d8307d
commit a8ff215e56050a907189e713fd449bcafe99ff6b
d8307d
Author: Florian Weimer <fweimer@redhat.com>
d8307d
Date:   Fri Apr 26 07:16:30 2019 +0200
d8307d
d8307d
    Makeconfig: Move -Wl,-rpath-link options before library references
d8307d
    
d8307d
    Previously, the -Wl,-rpath-link options came after the libraries
d8307d
    injected using LDLIBS-* variables on the link editor command line for
d8307d
    main programs.  As a result, it could happen that installed libraries
d8307d
    that reference glibc libraries used the installed glibc from the system
d8307d
    directories, instead of the glibc from the build tree.  This can lead to
d8307d
    link failures if the wrong version of libpthread.so.0 is used, for
d8307d
    instance, due to differences in the internal GLIBC_PRIVATE interfaces,
d8307d
    as seen with memusagestat and -lgd after commit
d8307d
    f9b645b4b0a10c43753296ce3fa40053fa44606a ("memusagestat: use local glibc
d8307d
    when linking [BZ #18465]").
d8307d
    
d8307d
    The isolation is necessarily imperfect because these installed
d8307d
    libraries are linked against the installed glibc in the system
d8307d
    directories.  However, in most cases, the built glibc will be newer
d8307d
    than the installed glibc, and this link is permitted because of the
d8307d
    ABI backwards compatibility glibc provides.
d8307d
d8307d
diff --git a/Makeconfig b/Makeconfig
d8307d
index 1ad25fc5a7251aea..e315fb8a75ca5063 100644
d8307d
--- a/Makeconfig
d8307d
+++ b/Makeconfig
d8307d
@@ -428,8 +428,8 @@ ifndef +link-pie
d8307d
 	     $(link-extra-libs)
d8307d
 +link-pie-after-libc = $(+postctorS) $(+postinit)
d8307d
 define +link-pie
d8307d
-$(CC) $(+link-pie-before-libc) $(rtld-LDFLAGS) $(link-extra-flags) \
d8307d
-  $(link-libc) $(+link-pie-after-libc)
d8307d
+$(CC) $(link-libc-rpath-link) $(+link-pie-before-libc) $(rtld-LDFLAGS) \
d8307d
+  $(link-extra-flags) $(link-libc) $(+link-pie-after-libc)
d8307d
 $(call after-link,$@)
d8307d
 endef
d8307d
 define +link-pie-tests
d8307d
@@ -490,8 +490,8 @@ else  # not build-pie-default
d8307d
 	      $(link-extra-libs)
d8307d
 +link-after-libc = $(+postctor) $(+postinit)
d8307d
 define +link
d8307d
-$(CC) $(+link-before-libc) $(rtld-LDFLAGS) $(link-extra-flags) $(link-libc) \
d8307d
-  $(+link-after-libc)
d8307d
+$(CC) $(link-libc-rpath-link) $(+link-before-libc) $(rtld-LDFLAGS) \
d8307d
+  $(link-extra-flags) $(link-libc) $(+link-after-libc)
d8307d
 $(call after-link,$@)
d8307d
 endef
d8307d
 define +link-tests
d8307d
@@ -552,6 +552,15 @@ ifeq (yes,$(build-shared))
d8307d
 link-libc-rpath = -Wl,-rpath=$(rpath-link)
d8307d
 link-libc-rpath-link = -Wl,-rpath-link=$(rpath-link)
d8307d
 
d8307d
+# For programs which are not tests, $(link-libc-rpath-link) is added
d8307d
+# directly in $(+link), $(+link-pie) above, so that -Wl,-rpath-link
d8307d
+# comes before the expansion of LDLIBS-* and affects libraries added
d8307d
+# there.  For shared objects, -Wl,-rpath-link is added via
d8307d
+# $(build-shlib-helper) and $(build-module-helper) in Makerules (also
d8307d
+# before the expansion of LDLIBS-* variables).
d8307d
+
d8307d
+# Tests use -Wl,-rpath instead of -Wl,-rpath-link for
d8307d
+# build-hardcoded-path-in-tests.
d8307d
 ifeq (yes,$(build-hardcoded-path-in-tests))
d8307d
 link-libc-tests-rpath-link = $(link-libc-rpath)
d8307d
 else
d8307d
@@ -562,7 +571,7 @@ link-libc-before-gnulib = $(common-objpfx)libc.so$(libc.so-version) \
d8307d
 			  $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
d8307d
 			  $(as-needed) $(elf-objpfx)ld.so \
d8307d
 			  $(no-as-needed)
d8307d
-link-libc = $(link-libc-rpath-link) $(link-libc-before-gnulib) $(gnulib)
d8307d
+link-libc = $(link-libc-before-gnulib) $(gnulib)
d8307d
 
d8307d
 link-libc-tests-after-rpath-link = $(link-libc-before-gnulib) $(gnulib-tests)
d8307d
 link-libc-tests = $(link-libc-tests-rpath-link) \