From patchwork Mon Jan 4 22:38:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 41637 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 954503890434; Mon, 4 Jan 2021 22:39:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 954503890434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609799971; bh=W07//tLvI6qDA4R3JOstmTtUusdKfNJfsl2Ppd2x3nw=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=mrIjQQcWG5PjblPoPzMm7xruHS+5PUsK17K/jo8cjN6BHCWflVmgycDElrzLL+dnh bNMgYKGpNGrSIOP0qBB+BVh1LkeNgEjp+K3ftIO4SV/4Dhu12rmdmVuq7r3Qpqv32x Uv8kJrTsi1MEcTQRFwaMb4vnDS7vBjaLqTqosepg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 03B703861838 for ; Mon, 4 Jan 2021 22:39:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 03B703861838 Received: by mail-oi1-x232.google.com with SMTP id d189so33891083oig.11 for ; Mon, 04 Jan 2021 14:39:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W07//tLvI6qDA4R3JOstmTtUusdKfNJfsl2Ppd2x3nw=; b=q6B4RNaFt0OaFA5mF41CRNMV/P7QnqmSJIHkQ81mfDao8URGHS4MggmC2Qkm1k5kZH LD0Vhz8dYJiAFw8nrMCcp6UUh7eQMw3OPsKgP+CriDpmOBxnwdB3PyGwkdebAbD23LJZ X0U6gTLScF9GDVptB38HAn9F4Zi0YO/LVR3VJnHpqAKwSZOlV2oWl05EuVuV4fS14svv mHqTW20MiSUjUohCjbfyPMOnNnBHXO/bSEoTzvqzPX/+MiFst3RscaMgDExPms8ntQoE Q4m9RJY1g+pQRb91Hfez4wixPpaGJ4knc8J+Uo5jsxTag+pqnehQ7/GDaK/m8wqVt8yZ fJcA== X-Gm-Message-State: AOAM531GVQtH1P6igjVYN8zuTNbk5X3ZOcKD5gpdaGWxrvNm0rfvsvyq HOWRKzRfgbOWq9XIS9S+KANkBgcC5dpCpXn+WMOTBBRtSdk= X-Google-Smtp-Source: ABdhPJy7RxeDdYtBTRi4idTfbMSymkic7vom+0Hm4PZbsM7167ZQYXCDyX7EC3EgkD2FIxRix5L0tT4Tbz5DUTCyIuI= X-Received: by 2002:aca:f5d3:: with SMTP id t202mr775247oih.25.1609799968406; Mon, 04 Jan 2021 14:39:28 -0800 (PST) MIME-Version: 1.0 References: <20201228141102.2562718-1-hjl.tools@gmail.com> <0d676184-2aee-6580-7281-dbbafbe671c4@redhat.com> <4058143e-9b84-f8f5-1361-420a5b3aa808@redhat.com> In-Reply-To: Date: Mon, 4 Jan 2021 14:38:52 -0800 Message-ID: Subject: [PATCH] ifuncmain6pie: Remove the circular IFUNC dependency [BZ #20019] To: "Carlos O'Donell" X-Spam-Status: No, score=-3036.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: GNU C Library Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On Mon, Jan 4, 2021 at 1:20 PM Carlos O'Donell wrote: > ... > > > > [hjl@gnu-cfl-2 build-x86_64-linux]$ ./elf/ifuncmain6pie --direct > > ./elf/ifuncmain6pie: IFUNC symbol 'foo' referenced in > > '/export/build/gnu/tools-build/glibc/build-x86_64-linux/elf/ifuncmod6.so' > > is defined in the executable and creates an unsatisfiable circular > > dependency. > > [hjl@gnu-cfl-2 build-x86_64-linux]$ > > > > The message is correct. Should we update the testcase to avoid it? > > Yes, but it is still possible to support this with lazy binding? > > Should ifuncmain6pie be explicitly compiled with -Wl,-z,lazy to > bypass selection from the toolchain? The problem is non-JUMP_SLOT relocations. Here is a patch to remove them. OK for master? Thanks. From fe3bd3b8d7e6401dc96e2aa59f341d41d1cb4723 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 4 Jan 2021 14:25:39 -0800 Subject: [PATCH] ifuncmain6pie: Remove the circular IFUNC dependency [BZ #20019] On x86, ifuncmain6pie failed with: [hjl@gnu-cfl-2 build-i686-linux]$ ./elf/ifuncmain6pie --direct ./elf/ifuncmain6pie: IFUNC symbol 'foo' referenced in '/export/build/gnu/tools-build/glibc-32bit/build-i686-linux/elf/ifuncmod6.so' is defined in the executable and creates an unsatisfiable circular dependency. [hjl@gnu-cfl-2 build-i686-linux]$ readelf -rW elf/ifuncmod6.so | grep foo 00003ff4 00000706 R_386_GLOB_DAT 0000400c foo_ptr 00003ff8 00000406 R_386_GLOB_DAT 00000000 foo 0000400c 00000401 R_386_32 00000000 foo [hjl@gnu-cfl-2 build-i686-linux]$ Remove non-JUMP_SLOT relocations against foo in ifuncmod6.so, which trigger the circular IFUNC dependency, and build ifuncmain6pie with -Wl,-z,lazy. --- elf/Makefile | 2 ++ elf/ifuncmain6pie.c | 14 +++----------- elf/ifuncmod6.c | 8 ++++---- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 543800f4be..c41d11693b 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1403,6 +1403,8 @@ CFLAGS-ifuncmain7pie.c += $(pie-ccflag) CFLAGS-ifuncmain9pie.c += $(pie-ccflag) CFLAGS-tst-ifunc-textrel.c += $(pic-ccflag) +LDFLAGS-ifuncmain6pie = -Wl,-z,lazy + $(objpfx)ifuncmain1pie: $(objpfx)ifuncmod1.so $(objpfx)ifuncmain1staticpie: $(objpfx)ifuncdep1pic.o $(objpfx)ifuncmain1vispie: $(objpfx)ifuncmod1.so diff --git a/elf/ifuncmain6pie.c b/elf/ifuncmain6pie.c index 04faeb86ef..4a01906836 100644 --- a/elf/ifuncmain6pie.c +++ b/elf/ifuncmain6pie.c @@ -9,7 +9,6 @@ #include "ifunc-sel.h" typedef int (*foo_p) (void); -extern foo_p foo_ptr; static int one (void) @@ -28,20 +27,17 @@ foo_ifunc (void) } extern int foo (void); -extern foo_p get_foo (void); +extern int call_foo (void); extern foo_p get_foo_p (void); -foo_p my_foo_ptr = foo; +foo_p foo_ptr = foo; int main (void) { foo_p p; - p = get_foo (); - if (p != foo) - abort (); - if ((*p) () != -30) + if (call_foo () != -30) abort (); p = get_foo_p (); @@ -52,12 +48,8 @@ main (void) if (foo_ptr != foo) abort (); - if (my_foo_ptr != foo) - abort (); if ((*foo_ptr) () != -30) abort (); - if ((*my_foo_ptr) () != -30) - abort (); if (foo () != -30) abort (); diff --git a/elf/ifuncmod6.c b/elf/ifuncmod6.c index 2e16c1d06d..2f6d0715e6 100644 --- a/elf/ifuncmod6.c +++ b/elf/ifuncmod6.c @@ -4,7 +4,7 @@ extern int foo (void); typedef int (*foo_p) (void); -foo_p foo_ptr = foo; +extern foo_p foo_ptr; foo_p get_foo_p (void) @@ -12,8 +12,8 @@ get_foo_p (void) return foo_ptr; } -foo_p -get_foo (void) +int +call_foo (void) { - return foo; + return foo (); } -- 2.29.2