From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id E03F1385841B for ; Fri, 11 Feb 2022 23:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E03F1385841B Received: by mail-pl1-x62b.google.com with SMTP id x4so5850058plb.4 for ; Fri, 11 Feb 2022 15:19:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Wrx8gMlMbpLGBRoberimRYen8jvNn5ae0JAGCOXLk8=; b=syRxYzxxfsIo3syh+JfkZN/0weWT+fzQV/9uGHHO370NslAA0EYf6EQwmT8M81WHIM bMSwdR2mRsKs6lS6xidXv2M+6Ar+awq871Qjv5v91i+eZoVV4YGCqpdG9kAFlJ3wVSun QeDsyb5dhrBFddOb0fxpcwFKW0R8q1z62j9lWKa/k01U0c36XZQJFZecwCcGaAxhD/WD a7ODRxRG6UB/tiN32XA+JnHd9N6tMvPIOWkZDOQEw2bJBhmaFqaJixV98LjMTLRNqqT8 5/qIjNVvfdhBO3eOmt+BMpCt4KBqwmsqAaT+JRuMTrIdYMhzjk41rFsecks4pamA6VzG 4ruA== X-Gm-Message-State: AOAM532YRNC70oz00uWwc8TLs5BkuXCKi0qJJbV2rhK3RzdLkKl9tqsg 17DsajUbnVF1KLjlHIpvif24Iq32yt0= X-Google-Smtp-Source: ABdhPJzzDj+wUvXftxLRCCxpfuqPqO7K7AAn931EMN/9jZG6YPpmyOIPZcNKExPckJZMoL7Sk9k61Q== X-Received: by 2002:a17:90b:314c:: with SMTP id ip12mr2641740pjb.191.1644621568744; Fri, 11 Feb 2022 15:19:28 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id h6sm30238764pfk.110.2022.02.11.15.19.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 15:19:28 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 8BF1DC01CF for ; Fri, 11 Feb 2022 15:19:27 -0800 (PST) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] ld: Keep indirect symbol from IR if referenced from shared object Date: Fri, 11 Feb 2022 15:19:27 -0800 Message-Id: <20220211231927.2021394-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3029.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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 11 Feb 2022 23:19:31 -0000 Don't change indirect symbol defined in IR to undefined if it is referenced from shared object. bfd/ PR ld/28879 * elflink.c (_bfd_elf_merge_symbol): Don't change indirect symbol defined in IR to undefined if it is referenced from shared object. ld/ PR ld/28879 * testsuite/ld-plugin/lto.exp: Run PR ld/28879 tests. * testsuite/ld-plugin/pr28879a.cc: New file. * testsuite/ld-plugin/pr28879b.cc: Likewise. --- bfd/elflink.c | 5 ++--- ld/testsuite/ld-plugin/lto.exp | 26 ++++++++++++++++++++++++++ ld/testsuite/ld-plugin/pr28879a.cc | 7 +++++++ ld/testsuite/ld-plugin/pr28879b.cc | 8 ++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 ld/testsuite/ld-plugin/pr28879a.cc create mode 100644 ld/testsuite/ld-plugin/pr28879b.cc diff --git a/bfd/elflink.c b/bfd/elflink.c index 6fa18d92007..f8521426cad 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -1294,9 +1294,8 @@ _bfd_elf_merge_symbol (bfd *abfd, h->root.non_ir_ref_dynamic = true; hi->root.non_ir_ref_dynamic = true; } - - if ((oldbfd->flags & BFD_PLUGIN) != 0 - && hi->root.type == bfd_link_hash_indirect) + else if ((oldbfd->flags & BFD_PLUGIN) != 0 + && hi->root.type == bfd_link_hash_indirect) { /* Change indirect symbol from IR to undefined. */ hi->root.type = bfd_link_hash_undefined; diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index a70a84562b8..64b880265ee 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -471,6 +471,32 @@ set lto_link_elf_tests [list \ [list {pr27441c.so} \ {-shared -fPIC -Wl,--as-needed tmpdir/pr27441c.o tmpdir/pr27441b.so tmpdir/pr27441a.so} {-fPIC} \ {dummy.c} {{readelf {-dW} pr27441c.d}} {pr27441c.so}] \ + [list \ + "Build libpr28879a.so" \ + "-shared" \ + "-O0 -fpic" \ + {pr28879a.cc} \ + {} \ + "libpr28879a.so" \ + "c++" \ + ] \ + [list \ + "Build libpr28879b.so" \ + "-shared -Wl,--no-as-needed tmpdir/libpr28879a.so" \ + "-O2 -fpic" \ + {dummy.c} \ + {} \ + "libpr28879b.so" \ + ] \ + [list \ + "Build pr28879" \ + "-Wl,--no-as-needed tmpdir/libpr28879b.so -Wl,-rpath-link,." \ + "-O0 -flto -D_GLIBCXX_ASSERTIONS" \ + {pr28879b.cc} \ + {} \ + "pr28879" \ + "c++" \ + ] \ ] # PR 14918 checks that libgcc is not spuriously included in a shared link of diff --git a/ld/testsuite/ld-plugin/pr28879a.cc b/ld/testsuite/ld-plugin/pr28879a.cc new file mode 100644 index 00000000000..8307a42e2fb --- /dev/null +++ b/ld/testsuite/ld-plugin/pr28879a.cc @@ -0,0 +1,7 @@ +#include + +void +func (std::string *s) +{ + delete s; +} diff --git a/ld/testsuite/ld-plugin/pr28879b.cc b/ld/testsuite/ld-plugin/pr28879b.cc new file mode 100644 index 00000000000..02fc351366c --- /dev/null +++ b/ld/testsuite/ld-plugin/pr28879b.cc @@ -0,0 +1,8 @@ +#include + +int +main (void) +{ + std::string header; + return 0; +} -- 2.34.1