From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30221 invoked by alias); 18 Mar 2013 08:16:30 -0000 Received: (qmail 30197 invoked by uid 22791); 18 Mar 2013 08:16:26 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-pb0-f45.google.com (HELO mail-pb0-f45.google.com) (209.85.160.45) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 Mar 2013 08:16:20 +0000 Received: by mail-pb0-f45.google.com with SMTP id ro8so6209861pbb.18 for ; Mon, 18 Mar 2013 01:16:19 -0700 (PDT) X-Received: by 10.66.174.143 with SMTP id bs15mr9103206pac.17.1363594579666; Mon, 18 Mar 2013 01:16:19 -0700 (PDT) Received: from bubble.grove.modra.org ([101.166.26.37]) by mx.google.com with ESMTPS id wl14sm7356117pac.18.2013.03.18.01.16.17 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Mar 2013 01:16:18 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 7FE36EA2CD2; Mon, 18 Mar 2013 18:46:14 +1030 (CST) Date: Mon, 18 Mar 2013 08:16:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: Re: [GOLD] --as-needed change wrt undefined weak symbols Message-ID: <20130318081614.GC18331@bubble.grove.modra.org> Mail-Followup-To: binutils@sourceware.org References: <20130114035805.GF3244@bubble.grove.modra.org> <20130115022340.GO3244@bubble.grove.modra.org> <20130115052328.GQ3244@bubble.grove.modra.org> <20130318024130.GA18331@bubble.grove.modra.org> <20130318075417.GB18331@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130318075417.GB18331@bubble.grove.modra.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 X-SW-Source: 2013-03/txt/msg00205.txt.bz2 On Mon, Mar 18, 2013 at 06:24:17PM +1030, Alan Modra wrote: > On Mon, Mar 18, 2013 at 01:11:30PM +1030, Alan Modra wrote: > > http://sourceware.org/ml/binutils/2013-01/msg00188.html > > The corresponding gold change. Not quite so simple as just testing > whether the reference is strong before setting is_needed, since we > can't have symbol versions coming from a non-loaded shared lib. If > you do, ld.so segfaults. OK to apply? That was silly, we've just made a vector of dynamic symbols, so no need to traverse the whole symbol table. * 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. 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 18 Mar 2013 08:13:00 -0000 @@ -121,6 +121,10 @@ class Symbol version() const { return this->version_; } + // Override symbol version. + void + override_version(const char* version); + // 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. @@ -872,10 +876,6 @@ class Symbol void override_base_with_special(const Symbol* from); - // Override symbol version. - void - override_version(const char* version); - // Allocate a common symbol by giving it a location in the output // file. void 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 18 Mar 2013 08:13:01 -0000 @@ -2387,18 +2387,35 @@ 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. + for (std::vector::iterator p = syms->begin(); + p != syms->end(); + ++p) + { + Symbol* sym = *p; + + if (sym->version() != NULL) + { + if (!sym->is_from_dynobj() + || !sym->object()->as_needed() + || sym->object()->is_needed()) + versions->record_version(this, dynpool, sym); + else + sym->override_version(NULL); + } + } + // 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