From patchwork Wed Nov 16 23:20:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 21321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp111140wrr; Wed, 16 Nov 2022 15:20:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf6danpBfGGQVR3MZBTpgGzMBgvz3EjvwZ54m1ejRnKzbxWW64rTbwomBFwkLxihyGkHqWQi X-Received: by 2002:a17:906:245a:b0:78d:857d:b4a8 with SMTP id a26-20020a170906245a00b0078d857db4a8mr31242ejb.495.1668640855393; Wed, 16 Nov 2022 15:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668640855; cv=none; d=google.com; s=arc-20160816; b=IC+OYkD8MlW7waC6KToUcbt0RPdxEE9v+7tvH3nM8+gRsc8cES0oof20aNIi0Bx2gK wvZEOVseAoIm/G0PMS4P+WG/IuLEdZdnIiFxZ5/lG3BTElDpopNnRa3ymj09Gm9fSa3m nCbElKHN+HqmM5i4kJDZmFGrmoBI9poaWIA9rxOS8AMjdgsWG7nil5hP5YXU+0Em3OF+ MCUlrudvcA2sYtuBBNgVFYqie8CZX+l+iFk5XoTh70bHGYrhSHV7CyyZWlEg7RkTrjtY sNr87vteXqmcBq68EpxMImKxdShEXi6DomdM1pPvsNY3umXVwXq5MpywhKXzzvTkvZAr xrXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=IzINdXFI0W2gvJSjBWh4vY2Wk5Be3H2BJrVY0zhSzKI=; b=tWEDWZucThif3TeiRKNH7VXKpasRI953o2wxFA171LjgTDEqz8rt+xbCd48L7WrJlg yYLKPPlx0w6om32lOukuK8t/b6BonAZmXIV44925RMM2oPV0y2vOYkpQHwasIk9b/4nL DEDLtZSuG2RbkCNtjZ4+t8G/F3XUVHPshX8LQxNXCpw449tZbuAt9O1T09qrPevh8The MH90/LtLj3pTauoPHCiXCKoKxXm/wc49a+zDvJ9CpjgWnVGmWViCsNA8lDjk5hO/7rVh gvawnmFPn/cSNnHH3RNOtmlD1SpZw1gq0KhE2x+vx32FCEY8eBAkACObUvnyWw677wvB J4AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=cqz5cGTe; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xh14-20020a170906da8e00b007986956bd8esi15464888ejb.472.2022.11.16.15.20.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 15:20:55 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=cqz5cGTe; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D7D4396E436 for ; Wed, 16 Nov 2022 23:20:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D7D4396E436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668640853; bh=IzINdXFI0W2gvJSjBWh4vY2Wk5Be3H2BJrVY0zhSzKI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cqz5cGTeH9M259JgThCxDhs3sSussUh/Mp0FUo7EZ1baJYqIOJGD3CE0fDJHM+kCe yJcutxizpmCCkG/OvptMulxgI78+b5O6p32BriGBt02mpEZOxybSxIOM+Vg53PRRt8 ZYfoX6ECcmWzSnzDt95Fui44CxDWZYKn4HoLt9r8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id E05923959CAD for ; Wed, 16 Nov 2022 23:20:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E05923959CAD Received: by mail-pl1-x629.google.com with SMTP id w23so11437252ply.12 for ; Wed, 16 Nov 2022 15:20:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IzINdXFI0W2gvJSjBWh4vY2Wk5Be3H2BJrVY0zhSzKI=; b=FTxzycosEa+suDPZVRD9FkKMKQbNSHkjYkulswVbiqEnoKeZleija/Ic+LzVSicA66 sf8GDgMVxiBxIwg2PqzXVOudbQjCHDeZME0HduOLMn+RTegXXTYK/pW77JSyr5ZnTfMc mIUWyURaJSCpDTdjgUPWTvyIbnUouoZrwJeGFQ+yr2vcyJSQGR7/J2TqaW803bnOKvMs ddhUDgSrC+k9zr/2gFtvBzeMLDToRmz9OaL+BGBpf7zc1dsUy++EDETzRdkQ6bp+n13u mRyt3W2R1xKK3Cu9Fw8FRl7NLsjK8WbzUjoL2JgYBIY+4ccvx2YjxzbjJKIM1f7ihKN9 MIcw== X-Gm-Message-State: ANoB5pm4h+/oxKSo9r2HLJvvEwj8ME9BrxA4nv/RPfuTMYOhXpKIrFPc +0UW7Ou4K5O8CrvKqWAusnWKMk0/BZE= X-Received: by 2002:a17:90b:30d4:b0:212:d6ed:cdf5 with SMTP id hi20-20020a17090b30d400b00212d6edcdf5mr5801405pjb.142.1668640842417; Wed, 16 Nov 2022 15:20:42 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.56.31.158]) by smtp.gmail.com with ESMTPSA id x13-20020a63f70d000000b0046f469a2661sm10160376pgh.27.2022.11.16.15.20.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 15:20:41 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id C4327C04E0 for ; Wed, 16 Nov 2022 15:20:39 -0800 (PST) To: binutils@sourceware.org Subject: [PATCH] ld: Always call elf_backend_output_arch_local_syms Date: Wed, 16 Nov 2022 15:20:39 -0800 Message-Id: <20221116232039.1793148-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Spam-Status: No, score=-3026.2 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749696753654806984?= X-GMAIL-MSGID: =?utf-8?q?1749696753654806984?= Always call elf_backend_output_arch_local_syms since only the backend knows if elf_backend_output_arch_local_syms is needed when all symbols are striped. elf_backend_output_arch_local_syms is defined only for x86, ARM and AARCH64. On x86, elf_backend_output_arch_local_syms must be called to handle local IFUNC symbols even if all symbols are striped. Update ARM and AARCH64 to skip elf_backend_output_arch_local_syms when symbols aren't needed. bfd/ PR ld/29797 * elf32-arm.c (elf32_arm_output_arch_local_syms): Skip if symbols aren't needed. * elfnn-aarch64.c (elfNN_aarch64_output_arch_local_syms): Likewise. * elflink.c (bfd_elf_final_link): Always call elf_backend_output_arch_local_syms if available. ld/ PR ld/29797 * testsuite/ld-elf/linux-x86.exp: Run PR ld/29797 test. * testsuite/ld-elf/pr29797.c: New file. --- bfd/elf32-arm.c | 5 +++++ bfd/elflink.c | 3 +-- bfd/elfnn-aarch64.c | 5 +++++ ld/testsuite/ld-elf/linux-x86.exp | 15 +++++++++++++++ ld/testsuite/ld-elf/pr29797.c | 21 +++++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr29797.c diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index ec18a8ab362..c7d73171e62 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -18110,6 +18110,11 @@ elf32_arm_output_arch_local_syms (bfd *output_bfd, bfd_size_type size; bfd *input_bfd; + if (info->strip == strip_all + && !info->emitrelocations + && !bfd_link_relocatable (info)) + return true; + htab = elf32_arm_hash_table (info); if (htab == NULL) return false; diff --git a/bfd/elflink.c b/bfd/elflink.c index 20cee4c76a4..81b34129463 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -12877,8 +12877,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) /* If backend needs to output some local symbols not present in the hash table, do it now. */ - if (bed->elf_backend_output_arch_local_syms - && (info->strip != strip_all || emit_relocs)) + if (bed->elf_backend_output_arch_local_syms) { if (! ((*bed->elf_backend_output_arch_local_syms) (abfd, info, &flinfo, elf_link_output_symstrtab))) diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 7b93672c0df..a9fefbd44a9 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -8476,6 +8476,11 @@ elfNN_aarch64_output_arch_local_syms (bfd *output_bfd, output_arch_syminfo osi; struct elf_aarch64_link_hash_table *htab; + if (info->strip == strip_all + && !info->emitrelocations + && !bfd_link_relocatable (info)) + return true; + htab = elf_aarch64_hash_table (info); osi.finfo = finfo; diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp index 06379057ff2..7822bd227f0 100644 --- a/ld/testsuite/ld-elf/linux-x86.exp +++ b/ld/testsuite/ld-elf/linux-x86.exp @@ -203,6 +203,21 @@ run_ld_link_exec_tests [list \ ] \ ] +# Run-time tests which require working ifunc attribute support. +if { [check_ifunc_attribute_available] } { + run_ld_link_exec_tests [list \ + [list \ + "Run pr29797" \ + "-s" \ + "" \ + { pr29797.c } \ + "pr29797" \ + "pass.out" \ + "-O0" \ + ] \ + ] +} + # Old gcc silently ignores __attribute__ ((aligned())) with too big alignment. proc compiler_honours_aligned { } { global CC_FOR_TARGET READELF srcdir subdir diff --git a/ld/testsuite/ld-elf/pr29797.c b/ld/testsuite/ld-elf/pr29797.c new file mode 100644 index 00000000000..9e3113fe98d --- /dev/null +++ b/ld/testsuite/ld-elf/pr29797.c @@ -0,0 +1,21 @@ +#include + +static int foo (int x) __attribute__ ((ifunc ("resolve_foo"))); + +static int foo_impl(int x) +{ + return x; +} + +static void *resolve_foo (void) +{ + return (void *) foo_impl; +} + +int +main () +{ + foo (0); + puts ("PASS"); + return 0; +}