Skip to content

Commit

Permalink
[build] Automatically set USE_BINARYBUILDER_CSL=0 when local CSL is…
Browse files Browse the repository at this point in the history
… 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 27c0291)
  • Loading branch information
staticfloat authored and KristofferC committed Aug 31, 2021
1 parent d8f269b commit 7767304
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 38 additions & 2 deletions deps/csl.mk
Original file line number Diff line number Diff line change
@@ -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: =//")
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions stdlib/CompilerSupportLibraries_jll/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name = "CompilerSupportLibraries_jll"
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"

# 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]
Expand Down

0 comments on commit 7767304

Please sign in to comment.