Skip to content

Commit 3b1c54d

Browse files
Consistently use RUNPATH in our libraries (#46464)
* Consistently use `RUNPATH` in our libraries When loading dependencies on Linux, we can either use `RPATH` or `RUNPATH` as a list of relative paths to search for libraries. The difference, for our purposes, mainly lies within how this interacts with `LD_LIBRARY_PATH`: `RPATH` is searched first, then `LD_LIBRARY_PATH`, then `RUNPATH`. So by using `RUNPATH` here, we are explicitly allowing ourselves to be overridden by `LD_LIBRARY_PATH`. This is fine, as long as we are consistent across our entire library line, however in the `v1.8.0` release, there was an inconsistency, reported in [0]. The inconsistency occured because of the following confluence of factors: - Ancient `ld` builds (such as the one used in our build environment) do not default to using `RUNPATH`, but instead use `RPATH`. - `patchelf`, when it rewrites the RPATH, will default to using `RUNPATH` instead. - We were only using `patchelf` on `libjulia-internal`, not on `libjulia-codegen`, which was newly added in `v1.8`. These three factors together caused us to ship a binary with `RUNPATH` in `libjulia-internal`, but `RPATH` in `libjulia-codegen`, which caused loading to fail in [0] due to first `libjulia-internal` being loaded, (which brought in the external `libstdc++`), then `libjulia-codegen` failed to load (because it found an incompatible `libstdc++`), causing the mysterious compiler error. This PR fixes this twofold; first, when building the libraries in the first place, we pass `--enable-new-dtags` to the linker to encourage it to use `runpath` when possible. This removes the possibility for a missing `patchelf` invocation to break things in this way. Second, we apply `patchelf` properly to `libjulia-codegen` as well. [0] #46409 * Update Make.inc Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com> Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
1 parent 8dde54d commit 3b1c54d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Make.inc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,9 @@ else
12231223
NO_WHOLE_ARCHIVE := -Wl,--no-whole-archive
12241224
endif
12251225

1226+
# Initialize these once, then add to them in OS-specific blocks
1227+
JLIBLDFLAGS :=
1228+
12261229
ifeq ($(OS), Linux)
12271230
OSLIBS += -Wl,--no-as-needed -ldl -lrt -lpthread -latomic -Wl,--export-dynamic,--as-needed,--no-whole-archive
12281231
# Detect if ifunc is supported
@@ -1236,14 +1239,14 @@ ifneq ($(SANITIZE),1)
12361239
JLDFLAGS += -Wl,-no-undefined
12371240
endif
12381241
ifeq (-Bsymbolic-functions, $(shell $(LD) --help | grep -o -e "-Bsymbolic-functions"))
1239-
JLIBLDFLAGS := -Wl,-Bsymbolic-functions
1240-
else
1241-
JLIBLDFLAGS :=
1242+
JLIBLDFLAGS += -Wl,-Bsymbolic-functions
12421243
endif
1244+
ifeq (--enable-new-dtags, $(shell $(LD) --help | grep -o -e "--enable-new-dtags"))
1245+
JLIBLDFLAGS += -Wl,--enable-new-dtags
1246+
endif
1247+
12431248
# Linker doesn't detect automatically that Julia doesn't need executable stack
12441249
JLIBLDFLAGS += -Wl,-z,noexecstack
1245-
else ifneq ($(OS), Darwin)
1246-
JLIBLDFLAGS :=
12471250
endif
12481251

12491252
ifeq ($(OS), FreeBSD)
@@ -1266,7 +1269,7 @@ OSLIBS += -framework CoreFoundation
12661269
WHOLE_ARCHIVE := -Xlinker -all_load
12671270
NO_WHOLE_ARCHIVE :=
12681271
HAVE_SSP := 1
1269-
JLIBLDFLAGS := -Wl,-compatibility_version,$(SOMAJOR) -Wl,-current_version,$(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)
1272+
JLIBLDFLAGS += -Wl,-compatibility_version,$(SOMAJOR) -Wl,-current_version,$(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)
12701273
endif
12711274

12721275
ifeq ($(OS), WINNT)

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,10 @@ endif
370370
ifneq (,$(findstring $(OS),Linux FreeBSD))
371371
ifeq ($(JULIA_BUILD_MODE),release)
372372
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-internal.$(SHLIB_EXT)
373+
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-codegen.$(SHLIB_EXT)
373374
else ifeq ($(JULIA_BUILD_MODE),debug)
374375
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-internal-debug.$(SHLIB_EXT)
376+
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-codegen-debug.$(SHLIB_EXT)
375377
endif
376378
endif
377379

0 commit comments

Comments
 (0)