From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 3DE3A3858015 for ; Mon, 14 Feb 2022 00:17:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3DE3A3858015 Received: by mail-pj1-x1036.google.com with SMTP id om7so12956094pjb.5 for ; Sun, 13 Feb 2022 16:17:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=RWy0oLhGDcLq4q5guKRXrPAYNUFuafv2rzyBnmfjwLw=; b=ahfoSaJkb8LgRtoZzC2fyGziQpc6vLlC72X9xC3G9IIYKxZ8IAbqTwC4fmjqHOB9Zx jaILeWJVmWoICMUleDkdxugaIqaGyiko5XUgFe/cxB4bz3grcxJ8/shGdYyLkP2urPph jgeF+ng+uRWcHMDM9yae1+XSuffrQWXdhhgM38OxdWoqhd5CfITz8bQ6+ytmGZ111NZx YG9NeUVKnnsvcw7u4dvgEUwk5Fd8HZnCiFVCwy91tCku9mcvH8vvovnfg6NOQ9uCctxq 1wCOm6VroFE2fjgTwcvxA44dAEYxi1BIcbWl+0tBby0DcdPEOvus9hhQ5kmNyKg/0Ggj fbJw== X-Gm-Message-State: AOAM533Eg9IuNjZ3DJeUs+VoTpCPREYnjZsjLvBYFqrou6pFwza98GJh ZX2e+jV/GVjEvKjRhTB8085LLUyN2YaMu1QuQ5gzF4Kv X-Google-Smtp-Source: ABdhPJxNoVw4q6FRTQDuq5aa6ljW1DHHUY67zquvhPql5cl6i8twfrydGttNsuHW/PowcHIWWTi9cfCrx9hYEx6Crws= X-Received: by 2002:a17:90b:3eca:: with SMTP id rm10mr4060507pjb.120.1644797831991; Sun, 13 Feb 2022 16:17:11 -0800 (PST) MIME-Version: 1.0 References: <20220211231927.2021394-1-hjl.tools@gmail.com> In-Reply-To: <20220211231927.2021394-1-hjl.tools@gmail.com> From: "H.J. Lu" Date: Sun, 13 Feb 2022 16:16:35 -0800 Message-ID: Subject: Re: [PATCH] ld: Keep indirect symbol from IR if referenced from shared object To: Binutils , Nick Clifton , Alan Modra Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3027.1 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: Mon, 14 Feb 2022 00:17:15 -0000 On Fri, Feb 11, 2022 at 3:19 PM H.J. Lu wrote: > > 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 > Hi Nick, Alan, Is this OK for master and 2.38 branch? Thanks. -- H.J.