From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8350 invoked by alias); 5 Aug 2014 01:35:09 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 8332 invoked by uid 89); 5 Aug 2014 01:35:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f50.google.com Received: from mail-pa0-f50.google.com (HELO mail-pa0-f50.google.com) (209.85.220.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 05 Aug 2014 01:34:45 +0000 Received: by mail-pa0-f50.google.com with SMTP id et14so355812pad.37 for ; Mon, 04 Aug 2014 18:34:44 -0700 (PDT) X-Received: by 10.68.57.140 with SMTP id i12mr595742pbq.44.1407202484031; Mon, 04 Aug 2014 18:34:44 -0700 (PDT) Received: from bubble.grove.modra.org ([58.160.155.134]) by mx.google.com with ESMTPSA id tu10sm151221pbc.43.2014.08.04.18.34.42 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 18:34:43 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id C8157EA3744; Tue, 5 Aug 2014 11:04:38 +0930 (CST) Date: Tue, 05 Aug 2014 01:35:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: Re: Fix LTO vs. COFF archives Message-ID: <20140805013438.GE8921@bubble.grove.modra.org> Mail-Followup-To: binutils@sourceware.org References: <20140802050021.GJ23728@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140802050021.GJ23728@bubble.grove.modra.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2014-08/txt/msg00020.txt.bz2 On Sat, Aug 02, 2014 at 02:30:21PM +0930, Alan Modra wrote: > This patch needs some serious testing by mingw/cygwin people before Thanks to lrn1986 at gmail dot com for testing, now committed with this additional patch. It doesn't make sense to call add_archive_element without loading symbols from the object. Dave Korn flagged this a while ago with the comment he added.. * linker.c (generic_link_check_archive_element): Move handling of command link -u symbols with a common symbol def to the code handling non-common symbols so that archive element symbols are loaded. Use generic_link_add_object_symbols. diff --git a/bfd/linker.c b/bfd/linker.c index a31e473..1877e67 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -1120,29 +1120,21 @@ generic_link_check_archive_element (bfd *abfd, /* P is a symbol we are looking for. */ - if (! bfd_is_com_section (p->section)) + if (! bfd_is_com_section (p->section) + || (h->type == bfd_link_hash_undefined + && h->u.undef.abfd == NULL)) { - bfd_size_type symcount; - asymbol **symbols; - bfd *oldbfd = abfd; - - /* This object file defines this symbol, so pull it in. */ + /* P is not a common symbol, or an undefined reference was + created from outside BFD such as from a linker -u option. + This object file defines the symbol, so pull it in. */ + *pneeded = TRUE; if (!(*info->callbacks ->add_archive_element) (info, abfd, bfd_asymbol_name (p), &abfd)) return FALSE; /* Potentially, the add_archive_element hook may have set a substitute BFD for us. */ - if (abfd != oldbfd - && !bfd_generic_link_read_symbols (abfd)) - return FALSE; - symcount = _bfd_generic_link_get_symcount (abfd); - symbols = _bfd_generic_link_get_symbols (abfd); - if (! generic_link_add_symbol_list (abfd, info, symcount, - symbols, collect)) - return FALSE; - *pneeded = TRUE; - return TRUE; + return generic_link_add_object_symbols (abfd, info, collect); } /* P is a common symbol. */ @@ -1153,23 +1145,6 @@ generic_link_check_archive_element (bfd *abfd, bfd_vma size; unsigned int power; - symbfd = h->u.undef.abfd; - if (symbfd == NULL) - { - /* This symbol was created as undefined from outside - BFD. We assume that we should link in the object - file. This is for the -u option in the linker. */ - if (!(*info->callbacks - ->add_archive_element) (info, abfd, bfd_asymbol_name (p), - &abfd)) - return FALSE; - /* Potentially, the add_archive_element hook may have set a - substitute BFD for us. But no symbols are going to get - registered by anything we're returning to from here. */ - *pneeded = TRUE; - return TRUE; - } - /* Turn the symbol into a common symbol but do not link in the object file. This is how a.out works. Object formats that require different semantics must implement @@ -1177,6 +1152,7 @@ generic_link_check_archive_element (bfd *abfd, undefs list. We add the section to a common section attached to symbfd to ensure that it is in a BFD which will be linked in. */ + symbfd = h->u.undef.abfd; h->type = bfd_link_hash_common; h->u.c.p = (struct bfd_link_hash_common_entry *) bfd_hash_allocate (&info->hash->table, -- Alan Modra Australia Development Lab, IBM