From 7201884e0127c43cb6e1d6a2239134637fdc046e Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Wed, 10 May 2017 20:26:34 -0700 Subject: [PATCH] Workaround for FreeBSD linking to outdated system libs 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 7d83d9908f25ffe4f8a9ae0499bc17dfb7b6b005) --- Make.inc | 30 ++++++++++++++++++++++++++++++ deps/libgit2.mk | 3 +++ deps/llvm.mk | 8 ++++++++ deps/mbedtls.mk | 3 +++ deps/tools/common.mk | 7 +++++++ 5 files changed, 51 insertions(+) diff --git a/Make.inc b/Make.inc index 3293ebada9605..c7bc3f5302b6d 100644 --- a/Make.inc +++ b/Make.inc @@ -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 diff --git a/deps/libgit2.mk b/deps/libgit2.mk index afdc13d46e36a..3555212cfbb63 100644 --- a/deps/libgit2.mk +++ b/deps/libgit2.mk @@ -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) diff --git a/deps/llvm.mk b/deps/llvm.mk index b4925a2687871..5ee7805d2015c 100644 --- a/deps/llvm.mk +++ b/deps/llvm.mk @@ -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 diff --git a/deps/mbedtls.mk b/deps/mbedtls.mk index 4199c947779ab..4ac9a033b3352 100644 --- a/deps/mbedtls.mk +++ b/deps/mbedtls.mk @@ -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) diff --git a/deps/tools/common.mk b/deps/tools/common.mk index 42c7bb162e245..b2e0e42b0dc05 100644 --- a/deps/tools/common.mk +++ b/deps/tools/common.mk @@ -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)