From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by sourceware.org (Postfix) with ESMTPS id D69AE3858D35 for ; Fri, 31 Jul 2020 08:12:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D69AE3858D35 Received: by mail-pj1-x1044.google.com with SMTP id f9so7116079pju.4 for ; Fri, 31 Jul 2020 01:12:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0jj8C/Vmj2+SNkM7Iumhpce/QRzcI6KEqXqGN6SaK2I=; b=fb5wO7bCXd+I3y7v9/aYxX7c0PZSOsNUq/1B7Sh6CavBllcDH8TfunJ/dKcupAaz8D hjtfvZK0Unww3YJz0Sop7PfET+iUYUSy8naDmLwxu9QTGma08+dix0e7mfI7zvrYy0vM ZqllgxSxhNMqM27zFZ9P1IuCcqYWiqEsgthbL668zIAAfl5XlXe5OKiZq7Xyv1Tw4UUN QI3qYDUO5/bSRewFDwi4+2/teGBaNCLqxiN9MGK5IWKoB+vT35Dz52oMB5iMGyfAzF+f QTpjLzfAo4Cqz9AAb/O1Z+RMlhV6nJo9yYFVqoCrl83wgehbFPhprJOb9J1clmaGsNVF Klgw== X-Gm-Message-State: AOAM533sQLYKWC8Nbyt1z3qAPxhBMKnTBEUpQOVHg9e82mlxGld6XclR iRLTR137k4tKzw+9iCVxe+0= X-Google-Smtp-Source: ABdhPJxEYI7Ww5stAVuYkr5zHijwYCPHgilixjI9vIGBVmTQDn/Knjl5DVC2a/bXR2cMxwLKv7vAhw== X-Received: by 2002:a17:90a:f48d:: with SMTP id bx13mr1438421pjb.78.1596183148252; Fri, 31 Jul 2020 01:12:28 -0700 (PDT) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id v11sm8826713pgs.22.2020.07.31.01.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 01:12:25 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 790668800D; Fri, 31 Jul 2020 17:42:21 +0930 (ACST) Date: Fri, 31 Jul 2020 17:42:21 +0930 From: Alan Modra To: "H.J. Lu" , Nick Clifton Cc: Binutils Subject: Re: [PATCH] LTO: Ignore undefined symbols without relocation Message-ID: <20200731081221.GV9601@bubble.grove.modra.org> References: <20200729222258.3016925-1-hjl.tools@gmail.com> <20200730093214.GT9601@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-12.6 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: 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, 31 Jul 2020 08:12:31 -0000 On Thu, Jul 30, 2020 at 04:51:35AM -0700, H.J. Lu wrote: > On Thu, Jul 30, 2020 at 2:32 AM Alan Modra wrote: > > Surely this is just a gcc bug? We search libraries again after > > loading the LTO output, so one would expect that undefined symbols > > satisfied by an archive (or as-needed shared library) would lead to > > extra files being linked. > > > > I'd like to better understand just how this problem occurs though. As > > it is, I suspect there might be something else going on here, for > > example, ranlib being run without a plugin when building the archives. > > A testcase is on pr96385 branch at: > > https://gitlab.com/x86-gcc/gcc-bugs Thanks for that. Here are my observations about the link: gcc -O2 -g -o ar -Wl,--as-needed arparse.o arlex.o ar.o not-ranlib.o arsup.o rename.o binemul.o emul_vanilla.o bucomm.o version.o filemode.o libbfd-2.35-3.fc33.so libiberty.a -Wl,-R,. All of the above .o files are lto, leading to libbfd-2.35-3.fc33.so not being found needed when loading the IR objects. That's problem number one: We exclude IR references when deciding a shared library is needed. See PR15146. Thus none of the libbfd.so symbols are loaded before libiberty.a is scanned, and libbfd.so contains copies of libiberty.a functions. We ought to be using the libbfd.so copies rather than extracting them from the archive (an object is extracted even to satisfy IR symbols). After lto recompilation, libbfd.so is of course found to be needed and loaded. But that causes more problems. The lto recompilation didn't see symbol references from libbfd.so and variables like _xexit_cleanup are made local in the recompiled objects. Oops, two copies of them. Finally, those silly undefined symbols in the lto output debug files, combined with definitions in both libbfd.so and IR objects result in IR symbols being made dynamic. Nick, would you please check that this cures the Fedora build problem? The main fix here is to revert the PR15146 change to elf_link_add_object_symbols. PR 26314 * elflink.c (bfd_elf_link_record_dynamic_symbol): Don't allow IR symbols to become dynamic. (elf_link_add_object_symbols): Don't exclude IR symbols when deciding whether an as-needed shared library is needed. diff --git a/bfd/elflink.c b/bfd/elflink.c index ae5ff50ed6..0a7f5bb152 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -505,6 +505,16 @@ bfd_elf_link_record_dynamic_symbol (struct bfd_link_info *info, const char *name; size_t indx; + if (h->root.type == bfd_link_hash_defined + || h->root.type == bfd_link_hash_defweak) + { + /* An IR symbol should not be made dynamic. */ + if (h->root.u.def.section != NULL + && h->root.u.def.section->owner != NULL + && (h->root.u.def.section->owner->flags & BFD_PLUGIN) != 0) + return TRUE; + } + /* XXX: The ABI draft says the linker must turn hidden and internal symbols into STB_LOCAL symbols when producing the DSO. However, if ld.so honors st_other in the dynamic table, @@ -5199,15 +5209,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) break; } - /* Don't add DT_NEEDED for references from the dummy bfd nor - for unmatched symbol. */ if (!add_needed && matched && definition && ((dynsym - && h->ref_regular_nonweak - && (old_bfd == NULL - || (old_bfd->flags & BFD_PLUGIN) == 0)) + && h->ref_regular_nonweak) || (h->ref_dynamic_nonweak && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0 && !on_needed_list (elf_dt_name (abfd), -- Alan Modra Australia Development Lab, IBM