From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23402 invoked by alias); 20 Mar 2013 00:26:21 -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 23385 invoked by uid 89); 20 Mar 2013 00:26:13 -0000 X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from mail-pb0-f53.google.com (HELO mail-pb0-f53.google.com) (209.85.160.53) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 20 Mar 2013 00:26:11 +0000 Received: by mail-pb0-f53.google.com with SMTP id un1so860430pbc.12 for ; Tue, 19 Mar 2013 17:26:09 -0700 (PDT) X-Received: by 10.66.138.40 with SMTP id qn8mr6094544pab.165.1363739169534; Tue, 19 Mar 2013 17:26:09 -0700 (PDT) Received: from bubble.grove.modra.org ([101.166.26.37]) by mx.google.com with ESMTPS id ti8sm26046395pbc.12.2013.03.19.17.26.07 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Mar 2013 17:26:08 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id C477AEA2CD2; Wed, 20 Mar 2013 10:56:03 +1030 (CST) Date: Wed, 20 Mar 2013 00:26:00 -0000 From: Alan Modra To: Ian Lance Taylor Cc: Binutils Subject: Re: [GOLD] --as-needed change wrt undefined weak symbols Message-ID: <20130320002603.GJ18331@bubble.grove.modra.org> Mail-Followup-To: Ian Lance Taylor , Binutils References: <20130115022340.GO3244@bubble.grove.modra.org> <20130115052328.GQ3244@bubble.grove.modra.org> <20130318024130.GA18331@bubble.grove.modra.org> <20130318075417.GB18331@bubble.grove.modra.org> <20130318081614.GC18331@bubble.grove.modra.org> <20130319023425.GG18331@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.5.21 (2010-09-15) X-SW-Source: 2013-03/txt/msg00213.txt.bz2 On Tue, Mar 19, 2013 at 01:41:31PM -0700, Ian Lance Taylor wrote: > On Mon, Mar 18, 2013 at 7:34 PM, Alan Modra wrote: > > On Mon, Mar 18, 2013 at 08:15:55AM -0700, Ian Lance Taylor wrote: > >> We can build a > >> temporary vector of symbols with version != NULL for which that > >> condition is not true, and then walk that vector in the second loop. > >> There won't be many entries in it. > > > > Well, OK, but I wonder whether it is really worth doing? Sometimes > > having two small loops is much better than having one large one. > > Yes, but there are executables here with tens of thousands of dynamic > symbols, none of which are weak. > > > * symtab.h (Symbol::override_version): Make public. > > * symtab.cc (Symbol_table::set_dynsym_indexes): Don't set object > > is_needed by weak references. Clear version for symbols defined > > in as-needed objects that are not needed. > > This is OK. When compiling with a different gcc and options (previously I used -fno-inline), I hit ...symtab.cc:2426: undefined reference to `gold::Symbol::override_version(char const*)' So I'm committing this slightly different patch. * symtab.h (Symbol::clear_version): New function. * symtab.cc (Symbol_table::set_dynsym_indexes): Don't set object is_needed by weak references. Clear version for symbols defined in as-needed objects that are not needed. Index: gold/symtab.h =================================================================== RCS file: /cvs/src/src/gold/symtab.h,v retrieving revision 1.129 diff -u -p -r1.129 symtab.h --- gold/symtab.h 10 Mar 2013 23:08:18 -0000 1.129 +++ gold/symtab.h 19 Mar 2013 22:33:39 -0000 @@ -121,6 +121,10 @@ class Symbol version() const { return this->version_; } + void + clear_version() + { this->version_ = NULL; } + // Return whether this version is the default for this symbol name // (eg, "foo@@V2" is a default version; "foo@V1" is not). Only // meaningful for versioned symbols. Index: gold/symtab.cc =================================================================== RCS file: /cvs/src/src/gold/symtab.cc,v retrieving revision 1.169 diff -u -p -r1.169 symtab.cc --- gold/symtab.cc 10 Mar 2013 23:08:18 -0000 1.169 +++ gold/symtab.cc 19 Mar 2013 22:33:40 -0000 @@ -2368,6 +2368,8 @@ Symbol_table::set_dynsym_indexes(unsigne Stringpool* dynpool, Versions* versions) { + std::vector as_needed_sym; + for (Symbol_table_type::iterator p = this->table_.begin(); p != this->table_.end(); ++p) @@ -2387,18 +2389,43 @@ Symbol_table::set_dynsym_indexes(unsigne syms->push_back(sym); dynpool->add(sym->name(), false, NULL); - // Record any version information. - if (sym->version() != NULL) - versions->record_version(this, dynpool, sym); - // If the symbol is defined in a dynamic object and is - // referenced in a regular object, then mark the dynamic - // object as needed. This is used to implement --as-needed. - if (sym->is_from_dynobj() && sym->in_reg()) + // referenced strongly in a regular object, then mark the + // dynamic object as needed. This is used to implement + // --as-needed. + if (sym->is_from_dynobj() + && sym->in_reg() + && !sym->is_undef_binding_weak()) sym->object()->set_is_needed(); + + // Record any version information, except those from + // as-needed libraries not seen to be needed. Note that the + // is_needed state for such libraries can change in this loop. + if (sym->version() != NULL) + { + if (!sym->is_from_dynobj() + || !sym->object()->as_needed() + || sym->object()->is_needed()) + versions->record_version(this, dynpool, sym); + else + as_needed_sym.push_back(sym); + } } } + // Process version information for symbols from as-needed libraries. + for (std::vector::iterator p = as_needed_sym.begin(); + p != as_needed_sym.end(); + ++p) + { + Symbol* sym = *p; + + if (sym->object()->is_needed()) + versions->record_version(this, dynpool, sym); + else + sym->clear_version(); + } + // Finish up the versions. In some cases this may add new dynamic // symbols. index = versions->finalize(this, index, syms); -- Alan Modra Australia Development Lab, IBM