From 0fb9425bc84087eb2b2f9e57f89843aaea85ca70 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Wed, 21 Jul 2021 20:27:25 -0700 Subject: [PATCH] [build] Automatically set `USE_BINARYBUILDER_CSL=0` when local CSL is new (#41645) We ship our own compiler support libraries to ensure a minimum level of support for BB-built libraries, however certain distros provide very bleeding-edge compilers. This can be a problem if we download an _older_ `libstdc++.so` and forcibly link against that when launching Julia, as when Julia itself is built with the local `g++`, it may use symbols that don't exist in the BB-sourced `libstdc++.so`. To address this, we default to not using BB-sourced CSLs if the `libstdc++.so` that the native compiler would use contains a symbol that our BB-sourced CSLs do not have. We use the monotonically-climbing `GLIBCXX_3.4.XX` version symbols for this purpose; encoding the "next" version number within `deps/csl.mk`, and triggering the BB-avoidance if that version exists within the system-provided `libstdc++.so`. (cherry picked from commit 27c0291f7fbecd811a3f9eb62b1159cff6b61e2a) --- Make.inc | 5 ++- deps/csl.mk | 40 ++++++++++++++++++- .../CompilerSupportLibraries_jll/Project.toml | 6 ++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Make.inc b/Make.inc index 438ab7fa02815c..4719a3d49b039d 100644 --- a/Make.inc +++ b/Make.inc @@ -1196,7 +1196,10 @@ BB_TRIPLET := $(subst $(SPACE),-,$(filter-out cxx%,$(filter-out libgfortran%,$(s LIBGFORTRAN_VERSION := $(subst libgfortran,,$(filter libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN)))) # This is the set of projects that BinaryBuilder dependencies are hooked up for. -BB_PROJECTS := OPENBLAS LLVM SUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP CSL +# Note: we explicitly _do not_ define `CSL` here, since it requires some more +# advanced techniques to decide whether it should be installed from a BB source +# or not. See `deps/csl.mk` for more detail. +BB_PROJECTS := OPENBLAS LLVM SUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP define SET_BB_DEFAULT # First, check to see if BB is disabled on a global setting ifeq ($$(USE_BINARYBUILDER),0) diff --git a/deps/csl.mk b/deps/csl.mk index 75e970f6882d3a..4dc497b80cbea0 100644 --- a/deps/csl.mk +++ b/deps/csl.mk @@ -1,5 +1,3 @@ -ifeq ($(USE_BINARYBUILDER_CSL),0) - # Interrogate the fortran compiler (which is always GCC based) on where it is keeping its libraries STD_LIB_PATH := $(shell LANG=C $(FC) -print-search-dirs | grep '^programs: =' | sed -e "s/^programs: =//") STD_LIB_PATH += :$(shell LANG=C $(FC) -print-search-dirs | grep '^libraries: =' | sed -e "s/^libraries: =//") @@ -12,6 +10,44 @@ define pathsearch $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(2))))) endef +# CSL bundles lots of system compiler libraries, and while it is quite bleeding-edge +# as compared to what most distros ship, if someone tries to build an older branch, +# the version of CSL that ships with that branch may become relatively old. This is +# not a problem for code that is built in BB, but when we build Julia with the system +# compiler, that compiler uses the version of `libstdc++` that it is bundled with, +# and we can get linker errors when trying to run that `julia` executable with the +# `libstdc++` that comes from the (now old) BB-built CSL. +# +# To fix this, we take note when the system `libstdc++.so` is newer than whatever we +# would get from CSL (by searching for a `GLIBCXX_3.4.X` symbol that does not exist +# in our CSL, but would in a newer one), and default to `USE_BINARYBUILDER_CSL=0` in +# this case. +CSL_NEXT_GLIBCXX_VERSION=GLIBCXX_3\.4\.30|GLIBCXX_3\.5\.|GLIBCXX_4\. + +# First, check to see if BB is disabled on a global setting +ifeq ($(USE_BINARYBUILDER),0) +USE_BINARYBUILDER_CSL ?= 0 +else +# If it's not, check to see if it's disabled by a USE_SYSTEM_xxx flag +ifeq ($(USE_SYSTEM_CSL),1) +USE_BINARYBUILDER_CSL ?= 0 +else +# If it's not, see if we should disable it due to `libstdc++` being newer: +LIBSTDCXX_PATH := $(eval $(call pathsearch,libstdc++,$(STD_LIB_PATH))) +ifneq (,$(and $(LIBSTDCXX_PATH),$(shell objdump -p $(LIBSTDCXX_PATH) | grep $(CSL_NEXT_GLIBCXX_VERSION)))) +# Found `libstdc++`, grepped it for strings and found a `GLIBCXX` symbol +# that is newer that whatever we have in CSL. Default to not using BB. +USE_BINARYBUILDER_CSL ?= 0 +else +# Either we didn't find `libstdc++` (e.g. we're using `clang`), or we +# found it and couldn't find the new symbol in it (it's older than what +# BB provides, so let's use BB instead) +USE_BINARYBUILDER_CSL ?= 1 +endif +endif +endif + +ifeq ($(USE_BINARYBUILDER_CSL),0) define copy_csl install-csl: | $$(build_shlibdir) $$(build_shlibdir)/$(1) $$(build_shlibdir)/$(1): | $$(build_shlibdir) diff --git a/stdlib/CompilerSupportLibraries_jll/Project.toml b/stdlib/CompilerSupportLibraries_jll/Project.toml index b4b4fddfac9d06..b76517c828d0ef 100644 --- a/stdlib/CompilerSupportLibraries_jll/Project.toml +++ b/stdlib/CompilerSupportLibraries_jll/Project.toml @@ -1,6 +1,10 @@ name = "CompilerSupportLibraries_jll" uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "0.3.6+1" + +# NOTE: When updating this, also make sure to update the value +# `CSL_NEXT_GLIBCXX_VERSION` in `deps/csl.mk`, to properly disable +# automatic usage of BB-built CSLs on extremely up-to-date systems! +version = "0.5.0+0" [deps] Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"