This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [GOLD] mapping input to output sections


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 <amodra@gmail.com> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]