From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6254 invoked by alias); 14 Aug 2012 00:54:56 -0000 Received: (qmail 6220 invoked by uid 22791); 14 Aug 2012 00:54:53 -0000 X-SWARE-Spam-Status: No, hits=-3.7 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-yw0-f41.google.com (HELO mail-yw0-f41.google.com) (209.85.213.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Aug 2012 00:54:38 +0000 Received: by yhr47 with SMTP id 47so4279706yhr.0 for ; Mon, 13 Aug 2012 17:54:38 -0700 (PDT) Received: by 10.50.88.165 with SMTP id bh5mr5657821igb.50.1344905677685; Mon, 13 Aug 2012 17:54:37 -0700 (PDT) Received: from bubble.grove.modra.org ([101.166.26.37]) by mx.google.com with ESMTPS id bo7sm17557526igb.2.2012.08.13.17.54.35 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 13 Aug 2012 17:54:36 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 72F7AEA0383; Tue, 14 Aug 2012 10:24:31 +0930 (CST) Date: Tue, 14 Aug 2012 02:20:00 -0000 From: Alan Modra To: Ian Lance Taylor Cc: binutils@sourceware.org Subject: Re: [GOLD] mapping input to output sections Message-ID: <20120814005431.GD3947@bubble.grove.modra.org> Mail-Followup-To: Ian Lance Taylor , binutils@sourceware.org References: <20120813142344.GC3947@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-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: 2012-08/txt/msg00242.txt.bz2 On Mon, Aug 13, 2012 at 09:11:03AM -0700, Ian Lance Taylor wrote: > On Mon, Aug 13, 2012 at 7:23 AM, Alan Modra wrote: > > Powerpc64 needs to map input .toc and .got sections to the output .got > > section, as the following accomplishes with GNU ld: > > .got : ALIGN(8) { *(.got .toc) } > > I gather gold is supposed to operate without a linker script. Is is > > reasonable to move section_name_mapping[], section_name_mapping_count, > > output_section_name() and match_file_name() from layout.cc to > > target.cc so output_section_name() can be overridden in class > > Target_powerpc? Or is there a better way to do this sort of trick? > > This is a case where I think I would prefer to see a more targeted > target hook. Suppose we have Layout::output_section_name call a > target hook first. If the hook returns non-NULL, > Layout::output_section can return that. Otherwise it can apply the > default. I suspected that might be the case, which is why I didn't even write a ChangeLog entry. Like this? * target.h (Target::output_section_name): New function. (Target::do_output_section_name): New function. * layout.cc (Layout::choose_output_section): Call the above. * powerpc.cc (Target_powerpc::do_output_section_name): New function. Index: gold/target.h =================================================================== RCS file: /cvs/src/src/gold/target.h,v retrieving revision 1.66 diff -u -p -r1.66 target.h --- gold/target.h 2 May 2012 21:37:23 -0000 1.66 +++ gold/target.h 14 Aug 2012 00:19:43 -0000 @@ -412,6 +412,15 @@ class Target define_standard_symbols(Symbol_table* symtab, Layout* layout) { this->do_define_standard_symbols(symtab, layout); } + // Return the output section name to use given an input section + // name, or NULL if no target specific name mapping is required. + // Set *PLEN to the length of the name if returning non-NULL. + const char* + output_section_name(const Relobj* relobj, + const char* name, + size_t* plen) const + { return this->do_output_section_name(relobj, name, plen); } + protected: // This struct holds the constant information for a child class. We // use a struct to avoid the overhead of virtual function calls for @@ -655,6 +664,11 @@ class Target do_define_standard_symbols(Symbol_table*, Layout*) { } + // This may be overridden by the child class. + virtual const char* + do_output_section_name(const Relobj*, const char*, size_t*) const + { return NULL; } + private: // The implementations of the four do_make_elf_object virtual functions are // almost identical except for their sizes and endianness. We use a template. Index: gold/layout.cc =================================================================== RCS file: /cvs/src/src/gold/layout.cc,v retrieving revision 1.232 diff -u -p -r1.232 layout.cc --- gold/layout.cc 7 Aug 2012 13:24:47 -0000 1.232 +++ gold/layout.cc 14 Aug 2012 00:19:42 -0000 @@ -939,7 +939,12 @@ Layout::choose_output_section(const Relo if (is_input_section && !this->script_options_->saw_sections_clause() && !parameters->options().relocatable()) - name = Layout::output_section_name(relobj, name, &len); + { + const char *orig_name = name; + name = parameters->target().output_section_name(relobj, name, &len); + if (name == NULL) + name = Layout::output_section_name(relobj, orig_name, &len); + } Stringpool::Key name_key; name = this->namepool_.add_with_length(name, len, true, &name_key); Index: gold/powerpc.cc =================================================================== RCS file: /cvs/src/src/gold/powerpc.cc,v retrieving revision 1.46 diff -u -p -r1.46 powerpc.cc --- gold/powerpc.cc 12 Aug 2012 03:07:32 -0000 1.46 +++ gold/powerpc.cc 14 Aug 2012 00:19:43 -0000 @@ -134,6 +125,19 @@ class Target_powerpc : public Sized_targ bool needs_special_offset_handling, size_t local_symbol_count, const unsigned char* plocal_symbols); + + // Map input .toc section to output .got section. + const char* + do_output_section_name(const Relobj*, const char* name, size_t* plen) const + { + if (size == 64 && strcmp (name, ".toc") == 0) + { + *plen = 4; + return ".got"; + } + return NULL; + } + // Finalize the sections. void do_finalize_sections(Layout*, const Input_objects*, Symbol_table*); -- Alan Modra Australia Development Lab, IBM