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