From e231870b7bbbd2398cb7b2b972a6ce7dd13d89fa Mon Sep 17 00:00:00 2001 From: Iblis Lin Date: Tue, 11 Jul 2017 01:36:09 +0800 Subject: [PATCH] A simpler way to deal with libgcc_s on FreeBSD (#22656) Tweak the order of libgcc_s in DT_NEEDED on FreeBSD so that building on FreeBSD does not require `BUILD_CUSTOM_LIBCXX`. See also: #21788, #22352 Ref #22656 (cherry picked from commit d90c215f0b672dd1cd462d7a86c78d2043afba5e) --- Make.inc | 14 ++++++++++---- deps/llvm.mk | 7 ------- deps/tools/common.mk | 13 ++++--------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Make.inc b/Make.inc index c7bc3f5302b6d..3f2540dc207f9 100644 --- a/Make.inc +++ b/Make.inc @@ -544,9 +544,6 @@ LDFLAGS += -L$(build_libdir) -L$(GCCPATH) -Wl,-rpath,$(build_libdir) -Wl,-rpath, # 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 @@ -977,7 +974,16 @@ endif ifeq ($(OS), FreeBSD) JLDFLAGS := -Wl,-Bdynamic -OSLIBS += -lelf -lkvm -lrt -Wl,--export-dynamic -Wl,--version-script=$(JULIAHOME)/src/julia.expmap $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) +OSLIBS += -lelf -lkvm -lrt + +# Tweak order of libgcc_s in DT_NEEDED, +# make it loaded first to +# prevent from linking to outdated system libs. +# See #21788 +OSLIBS += -lgcc_s + +OSLIBS += -Wl,--export-dynamic -Wl,--version-script=$(JULIAHOME)/src/julia.expmap \ + $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) endif ifeq ($(OS), Darwin) diff --git a/deps/llvm.mk b/deps/llvm.mk index 8dfb1dc7a1203..72c88f5a4c1ee 100644 --- a/deps/llvm.mk +++ b/deps/llvm.mk @@ -142,13 +142,6 @@ 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_LDFLAGS += -Wl,-rpath,'\$$ORIGIN',-rpath,$(GCCPATH) -endif -endif - ifneq (,$(filter $(ARCH), powerpc64le ppc64le)) LLVM_CXXFLAGS += -mminimal-toc endif diff --git a/deps/tools/common.mk b/deps/tools/common.mk index c3830cf4d092a..e595ff9cc0c4b 100644 --- a/deps/tools/common.mk +++ b/deps/tools/common.mk @@ -1,5 +1,9 @@ ## Some shared configuration options ## +# NOTE: Do not make RPATH changes in CMAKE_COMMON on platforms other than FreeBSD, since +# it will make its way into the LLVM build flags, and LLVM is picky about RPATH (though +# apparently not on FreeBSD). Ref PR #22352 + CONFIGURE_COMMON := --prefix=$(abspath $(build_prefix)) --build=$(BUILD_MACHINE) --libdir=$(abspath $(build_libdir)) --bindir=$(abspath $(build_depsbindir)) $(CUSTOM_LD_LIBRARY_PATH) ifneq ($(XC_HOST),) CONFIGURE_COMMON += --host=$(XC_HOST) @@ -37,15 +41,6 @@ CMAKE_COMMON += -DCMAKE_RC_COMPILER="$$(which $(CROSS_COMPILE)windres)" endif endif -# NOTE: Do not make RPATH changes in CMAKE_COMMON on platforms other than FreeBSD, since -# it will make its way into the LLVM build flags, and LLVM is picky about RPATH (though -# apparently not on FreeBSD). Ref PR #22352 -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)