From patchwork Thu Apr 25 12:36:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1090735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-101612-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="yLkGvPAE"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44qc9w51hpz9s9T for ; Thu, 25 Apr 2019 22:36:20 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=OdNFjMltc4nInOSkKD1wkz529GXsQ oofMuh7XHDVrjWlTqQq52W7Qhq8IcHphsXFFgotj3u7snHUXEyQgDqSQ4HC7O1un HqosEY8vtDax6vxB9E6EYNBmqfPUDbw655+HerEruQ+wwNeky7wLPdR7nlfnlewe nGh/1gjfFN3fYU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=HpE/C4UlEGnb0g5jjfYLelkB930=; b=yLk GvPAElnoospEygZTza3tRCcO2ZaxbXyQJ95K304DPkKmQEJU3o2HqQUMLw3cNGW9 jNJpUo2suLwGC/RKlaVI+bfszDWQNpIpaoRJnkaJQx92CV86PfEMUzidgS9mPbb9 kerjCeRm6EFMg3sEcO949fbq9uc24sAbtBmXMp10= Received: (qmail 51254 invoked by alias); 25 Apr 2019 12:36:15 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 51243 invoked by uid 89); 25 Apr 2019 12:36:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] Makeconfig: Move -Wl, -rpath-link options before library references Date: Thu, 25 Apr 2019 14:36:10 +0200 Message-ID: <874l6mcldx.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Previously, the -Wl,-rpath-link options came after the libraries injected using LDLIBS-* variables on the link editor command line for main programs. As a result, it could happen that installed libraries that reference glibc libraries used the installed glibc from the system directories, instead of the glibc from the build tree. This can lead to link failures if the wrong version of libpthread.so.0 is used, for instance, due to differences in the internal GLIBC_PRIVATE interfaces, as seen with memusagestat and -lgd after commit f9b645b4b0a10c43753296ce3fa40053fa44606a ("memusagestat: use local glibc when linking [BZ #18465]"). The isolation is necessarily imperfect because these installed libraries are linked against the installed glibc in the system directories. However, in most cases, the built glibc will be newer than the installed glibc, and this link is permitted because of the ABI backwards compatibility glibc provides. (Note: This patch depends on "Makeconfig: Move $(CC) to +link command variables".) 2019-04-25 Florian Weimer Makeconfig: Move -Wl,-rpath-link options before library references. * Makeconfig (+link-pie, +link): Add $(link-libc-rpath-link). (link-libc): Remove $(link-libc-rpath-link). Reviewed-by: Carlos O'Donell diff --git a/Makeconfig b/Makeconfig index 92c9b59bb5..76a5d41242 100644 --- a/Makeconfig +++ b/Makeconfig @@ -428,8 +428,8 @@ ifndef +link-pie $(link-extra-libs) +link-pie-after-libc = $(+postctorS) $(+postinit) define +link-pie -$(CC) $(+link-pie-before-libc) $(rtld-LDFLAGS) $(link-extra-flags) \ - $(link-libc) $(+link-pie-after-libc) +$(CC) $(link-libc-rpath-link) $(+link-pie-before-libc) $(rtld-LDFLAGS) \ + $(link-extra-flags) $(link-libc) $(+link-pie-after-libc) $(call after-link,$@) endef define +link-pie-tests @@ -490,8 +490,8 @@ else # not build-pie-default $(link-extra-libs) +link-after-libc = $(+postctor) $(+postinit) define +link -$(CC) $(+link-before-libc) $(rtld-LDFLAGS) $(link-extra-flags) $(link-libc) \ - $(+link-after-libc) +$(CC) $(link-libc-rpath-link) $(+link-before-libc) $(rtld-LDFLAGS) \ + $(link-extra-flags) $(link-libc) $(+link-after-libc) $(call after-link,$@) endef define +link-tests @@ -552,6 +552,15 @@ ifeq (yes,$(build-shared)) link-libc-rpath = -Wl,-rpath=$(rpath-link) link-libc-rpath-link = -Wl,-rpath-link=$(rpath-link) +# For programs which are not tests, $(link-libc-rpath-link) is added +# directly in $(+link), $(+link-pie) above, so that -Wl,-rpath-link +# comes before the expansion of LDLIBS-* and affects libraries added +# there. For shared objects, -Wl,-rpath-link is added via +# $(build-shlib-helper) and $(build-module-helper) in Makerules (also +# before the expansion of LDLIBS-* variables). + +# Test use -Wl,-rpath instead of -Wl,-rpath-link for +# build-hardcoded-path-in-tests. ifeq (yes,$(build-hardcoded-path-in-tests)) link-libc-tests-rpath-link = $(link-libc-rpath) else @@ -562,7 +571,7 @@ link-libc-before-gnulib = $(common-objpfx)libc.so$(libc.so-version) \ $(common-objpfx)$(patsubst %,$(libtype.oS),c) \ $(as-needed) $(elf-objpfx)ld.so \ $(no-as-needed) -link-libc = $(link-libc-rpath-link) $(link-libc-before-gnulib) $(gnulib) +link-libc = $(link-libc-before-gnulib) $(gnulib) link-libc-tests-after-rpath-link = $(link-libc-before-gnulib) $(gnulib-tests) link-libc-tests = $(link-libc-tests-rpath-link) \