Skip to content

Commit

Permalink
Workaround for FreeBSD linking to outdated system libs
Browse files Browse the repository at this point in the history
FreeBSD's system libgcc_s declares its GCC version as 4.6, which is too
old to build Julia. Since gfortran doesn't come installed by default,
when it's installed it's done so through a GCC port, which includes its
own libgcc_s. Linking to libgfortran from the port and to the system's
libgcc_s causes versioning issues which wreck the build.

This commit works around this issue by determining the version of GCC
used for gfortran, then linking in the libgcc_s corresponding to that
version everywhere. It's a bit of a kludge, but it gets the job done.
With this change, all libraries which need to link to libgcc_s link to
the proper version.

Ref #21788
(cherry picked from commit 7d83d99)
  • Loading branch information
ararslan committed May 2, 2018
1 parent 30db725 commit 7201884
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,36 @@ ifeq (exists, $(shell [ -e $(BUILDROOT)/Make.user ] && echo exists ))
include $(BUILDROOT)/Make.user
endif

# A bit of a kludge to work around libraries linking to FreeBSD's outdated system libgcc_s
# Instead, let's link to the libgcc_s corresponding to the installation of gfortran
ifeq ($(OS),FreeBSD)
ifneq (,$(findstring gfortran,$(FC)))

# First let's figure out what version of GCC we're dealing with
_GCCMAJOR := $(shell $(FC) -dumpversion | cut -d'.' -f1)
_GCCMINOR := $(shell $(FC) -dumpversion | cut -d'.' -f2)

# The ports system uses major and minor for GCC < 5 (e.g. gcc49 for GCC 4.9), otherwise major only
ifeq ($(_GCCMAJOR),4)
_GCCVER := $(_GCCMAJOR)$(_GCCMINOR)
else
_GCCVER := $(_GCCMAJOR)
endif

# Allow the user to specify this in Make.user
GCCPATH ?= $(LOCALBASE)/lib/gcc$(_GCCVER)

LDFLAGS += -L$(build_libdir) -L$(GCCPATH) -Wl,-rpath,$(build_libdir) -Wl,-rpath,$(GCCPATH)

# This ensures we get the right RPATH even if we're missing FFLAGS somewhere
FC += -Wl,-rpath=$(GCCPATH)

# Build our own libc++ and libc++abi because otherwise /usr/lib/libc++.so and /lib/libcxxrt.so will
# be linked in when building LLVM, and those link to /lib/libgcc_s.so
BUILD_CUSTOM_LIBCXX ?= 1
endif # gfortran
endif # FreeBSD

ifneq ($(CC_BASE)$(CXX_BASE),$(shell echo $(CC) | cut -d' ' -f1)$(shell echo $(CXX) | cut -d' ' -f1))
$(error Forgot override directive on CC or CXX in Make.user? Cowardly refusing to build)
endif
Expand Down
3 changes: 3 additions & 0 deletions deps/libgit2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ LIBGIT2_OPTS += -DUSE_OPENSSL=OFF -DUSE_MBEDTLS=ON -DCMAKE_INSTALL_RPATH="\$$ORI
endif

ifeq ($(OS),FreeBSD)
# We're getting this from CMAKE_COMMON when GCCPATH is nonempty
ifeq ($(GCCPATH),)
LIBGIT2_OPTS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN"
endif
endif

# We need to bundle ca certs on linux now that we're using libgit2 with ssl
ifeq ($(OS),Linux)
Expand Down
8 changes: 8 additions & 0 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ LLVM_CMAKE += -DLLDB_DISABLE_PYTHON=ON
endif # LLDB_DISABLE_PYTHON
endif # BUILD_LLDB

# Part of the FreeBSD libgcc_s kludge
ifeq ($(OS),FreeBSD)
ifneq ($(GCCPATH),)
LLVM_CMAKE += -DCMAKE_INSTALL_RPATH="\$$ORIGIN:$(GCCPATH)"
LLVM_LDFLAGS += -Wl,-rpath,'\$$ORIGIN',-rpath,$(GCCPATH)
endif
endif

ifneq (,$(filter $(ARCH), powerpc64le ppc64le))
LLVM_CXXFLAGS += -mminimal-toc
endif
Expand Down
3 changes: 3 additions & 0 deletions deps/mbedtls.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ MBEDTLS_OPTS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN"
endif

ifeq ($(OS),FreeBSD)
# We're getting this from CMAKE_COMMON when GCCPATH is nonempty
ifeq ($(GCCPATH),)
MBEDTLS_OPTS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN"
endif
endif

$(SRCDIR)/srccache/$(MBEDTLS_SRC).tgz: | $(SRCDIR)/srccache
$(JLDOWNLOAD) $@ $(MBEDTLS_URL)
Expand Down
7 changes: 7 additions & 0 deletions deps/tools/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ CMAKE_COMMON += -DCMAKE_RC_COMPILER="$$(which $(CROSS_COMPILE)windres)"
endif
endif

# Part of the FreeBSD libgcc_s kludge
ifeq ($(OS),FreeBSD)
ifneq ($(GCCPATH),)
CMAKE_COMMON += -DCMAKE_INSTALL_RPATH="\$$ORIGIN:$(GCCPATH)"
endif
endif

# For now this is LLVM specific, but I expect it won't be in the future
ifeq ($(LLVM_USE_CMAKE),1)
ifeq ($(CMAKE_GENERATOR),Ninja)
Expand Down

0 comments on commit 7201884

Please sign in to comment.