From 7d83d9908f25ffe4f8a9ae0499bc17dfb7b6b005 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Wed, 10 May 2017 20:26:34 -0700 Subject: [PATCH 1/2] 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. --- 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 d40abf17adb86..dda36ba03c7bd 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 129fbe610fa17..e535c5d551713 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 5ac5ab438f51a..043c19483dfd2 100644 --- a/deps/llvm.mk +++ b/deps/llvm.mk @@ -135,6 +135,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 df491b256c124..93cc4e6560244 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) From 78305aad4a57d426ea282d604c71a4865b6f4e6e Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sat, 13 May 2017 14:02:35 -0700 Subject: [PATCH 2/2] Rearrange CMake RPATH specifications to be centrally defined --- deps/libgit2.mk | 9 +-------- deps/libssh2.mk | 8 -------- deps/llvm.mk | 1 - deps/mbedtls.mk | 11 ----------- deps/tools/common.mk | 6 +++++- 5 files changed, 6 insertions(+), 29 deletions(-) diff --git a/deps/libgit2.mk b/deps/libgit2.mk index e535c5d551713..11d5bcbee196b 100644 --- a/deps/libgit2.mk +++ b/deps/libgit2.mk @@ -37,14 +37,7 @@ LIBGIT2_OPTS += -DCURL_INCLUDE_DIRS=$(build_includedir) -DCURL_LIBRARIES="-L$(bu endif ifeq ($(OS),Linux) -LIBGIT2_OPTS += -DUSE_OPENSSL=OFF -DUSE_MBEDTLS=ON -DCMAKE_INSTALL_RPATH="\$$ORIGIN" -endif - -ifeq ($(OS),FreeBSD) -# We're getting this from CMAKE_COMMON when GCCPATH is nonempty -ifeq ($(GCCPATH),) -LIBGIT2_OPTS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN" -endif +LIBGIT2_OPTS += -DUSE_OPENSSL=OFF -DUSE_MBEDTLS=ON endif # We need to bundle ca certs on linux now that we're using libgit2 with ssl diff --git a/deps/libssh2.mk b/deps/libssh2.mk index 8bbe6dd310dac..ea77379988ac0 100644 --- a/deps/libssh2.mk +++ b/deps/libssh2.mk @@ -20,14 +20,6 @@ else LIBSSH2_OPTS += -DCRYPTO_BACKEND=mbedTLS -DENABLE_ZLIB_COMPRESSION=OFF endif -ifeq ($(OS),Linux) -LIBSSH2_OPTS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN" -endif - -ifeq ($(OS),FreeBSD) -LIBSSH2_OPTS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN" -endif - $(SRCDIR)/srccache/$(LIBSSH2_SRC_DIR)/libssh2-encryptedpem.patch-applied: $(SRCDIR)/srccache/$(LIBSSH2_SRC_DIR)/source-extracted cd $(SRCDIR)/srccache/$(LIBSSH2_SRC_DIR) && patch -p1 -f < $(SRCDIR)/patches/libssh2-encryptedpem.patch echo 1 > $@ diff --git a/deps/llvm.mk b/deps/llvm.mk index 043c19483dfd2..8a3738841eaac 100644 --- a/deps/llvm.mk +++ b/deps/llvm.mk @@ -138,7 +138,6 @@ 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 diff --git a/deps/mbedtls.mk b/deps/mbedtls.mk index 4ac9a033b3352..9ebc0c071dbdd 100644 --- a/deps/mbedtls.mk +++ b/deps/mbedtls.mk @@ -15,17 +15,6 @@ ifeq ($(BUILD_OS),WINNT) MBEDTLS_OPTS += -G"MSYS Makefiles" endif -ifeq ($(OS),Linux) -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 93cc4e6560244..130d62db80c95 100644 --- a/deps/tools/common.mk +++ b/deps/tools/common.mk @@ -37,12 +37,16 @@ CMAKE_COMMON += -DCMAKE_RC_COMPILER="$$(which $(CROSS_COMPILE)windres)" endif endif +ifneq (,$(findstring $(OS),Linux FreeBSD)) +INSTALL_RPATH := "\$$ORIGIN" # Part of the FreeBSD libgcc_s kludge ifeq ($(OS),FreeBSD) ifneq ($(GCCPATH),) -CMAKE_COMMON += -DCMAKE_INSTALL_RPATH="\$$ORIGIN:$(GCCPATH)" +INSTALL_RPATH := "\$$ORIGIN:$(GCCPATH)" endif endif +CMAKE_COMMON += -DCMAKE_INSTALL_RPATH=$(INSTALL_RPATH) +endif # Linux or FreeBSD # For now this is LLVM specific, but I expect it won't be in the future ifeq ($(LLVM_USE_CMAKE),1)