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]

gold patch committed: Unify some target code


I committed this patch to unify some of the target code which is
currently replicated int the various do_finalize_sections functions.
This should not cause any functional changes.

Ian


2010-01-07  Ian Lance Taylor  <iant@google.com>

	* output.h (class Output_data): Add const version of
	output_section and do_output_section.
	(class Output_section_data): Add const version of
	do_output_section.
	(class Output_section): Likewise.
	* layout.cc (Layout::add_target_dynamic_tags): New function.
	* layout.h (class Layout): Update declarations.
	* arm.cc (Target_arm::do_finalize_sections): Use
	add_target_dynamic_tags.
	* i386.cc (Target_i386::do_finalize_sections): Likewise.
	* powerpc.cc (Target_powerpc::do_finalize_sections): Likewise.
	* sparc.cc (Target_sparc::do_finalize_sections): Likewise.
	* x86_64.cc (Target_x86_64::do_finalize_sections): Likewise.


Index: arm.cc
===================================================================
RCS file: /cvs/src/src/gold/arm.cc,v
retrieving revision 1.47
diff -p -u -r1.47 arm.cc
--- arm.cc	7 Jan 2010 18:38:43 -0000	1.47
+++ arm.cc	7 Jan 2010 20:40:18 -0000
@@ -4868,39 +4868,11 @@ Target_arm<big_endian>::do_finalize_sect
     this->set_may_use_blx(true);
  
   // Fill in some more dynamic tags.
-  Output_data_dynamic* const odyn = layout->dynamic_data();
-  if (odyn != NULL)
-    {
-      if (this->got_plt_ != NULL
-	  && this->got_plt_->output_section() != NULL)
-	odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_);
-
-      if (this->plt_ != NULL
-	  && this->plt_->output_section() != NULL)
-	{
-	  const Output_data* od = this->plt_->rel_plt();
-	  odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
-	  odyn->add_section_address(elfcpp::DT_JMPREL, od);
-	  odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_REL);
-	}
-
-      if (this->rel_dyn_ != NULL
-	  && this->rel_dyn_->output_section() != NULL)
-	{
-	  const Output_data* od = this->rel_dyn_;
-	  odyn->add_section_address(elfcpp::DT_REL, od);
-	  odyn->add_section_size(elfcpp::DT_RELSZ, od);
-	  odyn->add_constant(elfcpp::DT_RELENT,
-			     elfcpp::Elf_sizes<32>::rel_size);
-	}
-
-      if (!parameters->options().shared())
-	{
-	  // The value of the DT_DEBUG tag is filled in by the dynamic
-	  // linker at run time, and used by the debugger.
-	  odyn->add_constant(elfcpp::DT_DEBUG, 0);
-	}
-    }
+  const Reloc_section* rel_plt = (this->plt_ == NULL
+				  ? NULL
+				  : this->plt_->rel_plt());
+  layout->add_target_dynamic_tags(true, this->got_plt_, rel_plt,
+				  this->rel_dyn_, true);
 
   // Emit any relocs we saved in an attempt to avoid generating COPY
   // relocs.
Index: i386.cc
===================================================================
RCS file: /cvs/src/src/gold/i386.cc,v
retrieving revision 1.109
diff -p -u -r1.109 i386.cc
--- i386.cc	30 Dec 2009 07:22:06 -0000	1.109
+++ i386.cc	7 Jan 2010 20:40:18 -0000
@@ -1565,40 +1565,11 @@ Target_i386::do_finalize_sections(
     const Input_objects*,
     Symbol_table* symtab)
 {
-  // Fill in some more dynamic tags.
-  Output_data_dynamic* const odyn = layout->dynamic_data();
-  if (odyn != NULL)
-    {
-      if (this->got_plt_ != NULL
-	  && this->got_plt_->output_section() != NULL)
-	odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_);
-
-      if (this->plt_ != NULL
-	  && this->plt_->output_section() != NULL)
-	{
-	  const Output_data* od = this->plt_->rel_plt();
-	  odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
-	  odyn->add_section_address(elfcpp::DT_JMPREL, od);
-	  odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_REL);
-	}
-
-      if (this->rel_dyn_ != NULL
-	  && this->rel_dyn_->output_section() != NULL)
-	{
-	  const Output_data* od = this->rel_dyn_;
-	  odyn->add_section_address(elfcpp::DT_REL, od);
-	  odyn->add_section_size(elfcpp::DT_RELSZ, od);
-	  odyn->add_constant(elfcpp::DT_RELENT,
-			     elfcpp::Elf_sizes<32>::rel_size);
-	}
-
-      if (!parameters->options().shared())
-	{
-	  // The value of the DT_DEBUG tag is filled in by the dynamic
-	  // linker at run time, and used by the debugger.
-	  odyn->add_constant(elfcpp::DT_DEBUG, 0);
-	}
-    }
+  const Reloc_section* rel_plt = (this->plt_ == NULL
+				  ? NULL
+				  : this->plt_->rel_plt());
+  layout->add_target_dynamic_tags(true, this->got_plt_, rel_plt,
+				  this->rel_dyn_, true);
 
   // Emit any relocs we saved in an attempt to avoid generating COPY
   // relocs.
Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.159
diff -p -u -r1.159 layout.cc
--- layout.cc	7 Jan 2010 18:16:24 -0000	1.159
+++ layout.cc	7 Jan 2010 20:40:19 -0000
@@ -3206,6 +3206,83 @@ Layout::create_interp(const Target* targ
     }
 }
 
+// Add dynamic tags for the PLT and the dynamic relocs.  This is
+// called by the target-specific code.  This does nothing if not doing
+// a dynamic link.
+
+// USE_REL is true for REL relocs rather than RELA relocs.
+
+// If PLT_GOT is not NULL, then DT_PLTGOT points to it.
+
+// If PLT_REL is not NULL, it is used for DT_PLTRELSZ, and DT_JMPREL,
+// and we also set DT_PLTREL.
+
+// If DYN_REL is not NULL, it is used for DT_REL/DT_RELA,
+// DT_RELSZ/DT_RELASZ, DT_RELENT/DT_RELAENT.
+
+// If ADD_DEBUG is true, we add a DT_DEBUG entry when generating an
+// executable.
+
+void
+Layout::add_target_dynamic_tags(bool use_rel, const Output_data* plt_got,
+				const Output_data* plt_rel,
+				const Output_data* dyn_rel, bool add_debug)
+{
+  Output_data_dynamic* odyn = this->dynamic_data_;
+  if (odyn == NULL)
+    return;
+
+  if (plt_got != NULL && plt_got->output_section() != NULL)
+    odyn->add_section_address(elfcpp::DT_PLTGOT, plt_got);
+
+  if (plt_rel != NULL && plt_rel->output_section() != NULL)
+    {
+      odyn->add_section_size(elfcpp::DT_PLTRELSZ, plt_rel);
+      odyn->add_section_address(elfcpp::DT_JMPREL, plt_rel);
+      odyn->add_constant(elfcpp::DT_PLTREL,
+			 use_rel ? elfcpp::DT_REL : elfcpp::DT_RELA);
+    }
+
+  if (dyn_rel != NULL && dyn_rel->output_section() != NULL)
+    {
+      odyn->add_section_address(use_rel ? elfcpp::DT_REL : elfcpp::DT_RELA,
+				dyn_rel);
+      odyn->add_section_size(use_rel ? elfcpp::DT_RELSZ : elfcpp::DT_RELASZ,
+			     dyn_rel);
+      const int size = parameters->target().get_size();
+      elfcpp::DT rel_tag;
+      int rel_size;
+      if (use_rel)
+	{
+	  rel_tag = elfcpp::DT_RELENT;
+	  if (size == 32)
+	    rel_size = Reloc_types<elfcpp::SHT_REL, 32, false>::reloc_size;
+	  else if (size == 64)
+	    rel_size = Reloc_types<elfcpp::SHT_REL, 64, false>::reloc_size;
+	  else
+	    gold_unreachable();
+	}
+      else
+	{
+	  rel_tag = elfcpp::DT_RELAENT;
+	  if (size == 32)
+	    rel_size = Reloc_types<elfcpp::SHT_RELA, 32, false>::reloc_size;
+	  else if (size == 64)
+	    rel_size = Reloc_types<elfcpp::SHT_RELA, 64, false>::reloc_size;
+	  else
+	    gold_unreachable();
+	}
+      odyn->add_constant(rel_tag, rel_size);
+    }
+
+  if (add_debug && !parameters->options().shared())
+    {
+      // The value of the DT_DEBUG tag is filled in by the dynamic
+      // linker at run time, and used by the debugger.
+      odyn->add_constant(elfcpp::DT_DEBUG, 0);
+    }
+}
+
 // Finish the .dynamic section and PT_DYNAMIC segment.
 
 void
Index: layout.h
===================================================================
RCS file: /cvs/src/src/gold/layout.h,v
retrieving revision 1.76
diff -p -u -r1.76 layout.h
--- layout.h	31 Dec 2009 03:48:46 -0000	1.76
+++ layout.h	7 Jan 2010 20:40:19 -0000
@@ -556,6 +556,13 @@ class Layout
   incremental_inputs()
   { return this->incremental_inputs_; }
 
+  // For the target-specific code to add dynamic tags which are common
+  // to most targets.
+  void
+  add_target_dynamic_tags(bool use_rel, const Output_data* plt_got,
+			  const Output_data* plt_rel,
+			  const Output_data* dyn_rel, bool add_debug);
+
   // Compute and write out the build ID if needed.
   void
   write_build_id(Output_file*) const;
Index: output.h
===================================================================
RCS file: /cvs/src/src/gold/output.h,v
retrieving revision 1.94
diff -p -u -r1.94 output.h
--- output.h	6 Jan 2010 22:37:18 -0000	1.94
+++ output.h	7 Jan 2010 20:40:20 -0000
@@ -206,6 +206,10 @@ class Output_data
   output_section()
   { return this->do_output_section(); }
 
+  const Output_section*
+  output_section() const
+  { return this->do_output_section(); }
+
   // Return the output section index, if there is an output section.
   unsigned int
   out_shndx() const
@@ -358,6 +362,10 @@ class Output_data
   do_output_section()
   { return NULL; }
 
+  virtual const Output_section*
+  do_output_section() const
+  { return NULL; }
+
   // Return the output section index, if there is an output section.
   virtual unsigned int
   do_out_shndx() const
@@ -746,6 +754,10 @@ class Output_section_data : public Outpu
   do_output_section()
   { return this->output_section_; }
 
+  const Output_section*
+  do_output_section() const
+  { return this->output_section_; }
+
   // Return the section index of the output section.
   unsigned int
   do_out_shndx() const;
@@ -2641,6 +2653,10 @@ class Output_section : public Output_dat
   do_output_section()
   { return this; }
 
+  const Output_section*
+  do_output_section() const
+  { return this; }
+
   // Return the section index in the output file.
   unsigned int
   do_out_shndx() const
Index: powerpc.cc
===================================================================
RCS file: /cvs/src/src/gold/powerpc.cc,v
retrieving revision 1.26
diff -p -u -r1.26 powerpc.cc
--- powerpc.cc	30 Dec 2009 06:57:17 -0000	1.26
+++ powerpc.cc	7 Jan 2010 20:40:20 -0000
@@ -1552,37 +1552,11 @@ Target_powerpc<size, big_endian>::do_fin
     Symbol_table*)
 {
   // Fill in some more dynamic tags.
-  Output_data_dynamic* const odyn = layout->dynamic_data();
-  if (odyn != NULL)
-    {
-      if (this->plt_ != NULL
-	  && this->plt_->output_section() != NULL)
-	{
-	  const Output_data* od = this->plt_->rel_plt();
-	  odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
-	  odyn->add_section_address(elfcpp::DT_JMPREL, od);
-	  odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA);
-
-	  odyn->add_section_address(elfcpp::DT_PLTGOT, this->plt_);
-	}
-
-      if (this->rela_dyn_ != NULL
-	  && this->rela_dyn_->output_section() != NULL)
-	{
-	  const Output_data* od = this->rela_dyn_;
-	  odyn->add_section_address(elfcpp::DT_RELA, od);
-	  odyn->add_section_size(elfcpp::DT_RELASZ, od);
-	  odyn->add_constant(elfcpp::DT_RELAENT,
-			     elfcpp::Elf_sizes<size>::rela_size);
-	}
-
-      if (!parameters->options().shared())
-	{
-	  // The value of the DT_DEBUG tag is filled in by the dynamic
-	  // linker at run time, and used by the debugger.
-	  odyn->add_constant(elfcpp::DT_DEBUG, 0);
-	}
-    }
+  const Reloc_section* rel_plt = (this->plt_ == NULL
+				  ? NULL
+				  : this->plt_->rel_plt());
+  layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
+				  this->rela_dyn_, true);
 
   // Emit any relocs we saved in an attempt to avoid generating COPY
   // relocs.
Index: sparc.cc
===================================================================
RCS file: /cvs/src/src/gold/sparc.cc,v
retrieving revision 1.30
diff -p -u -r1.30 sparc.cc
--- sparc.cc	30 Dec 2009 06:57:17 -0000	1.30
+++ sparc.cc	7 Jan 2010 20:40:21 -0000
@@ -2331,37 +2331,11 @@ Target_sparc<size, big_endian>::do_final
     Symbol_table*)
 {
   // Fill in some more dynamic tags.
-  Output_data_dynamic* const odyn = layout->dynamic_data();
-  if (odyn != NULL)
-    {
-      if (this->plt_ != NULL
-	  && this->plt_->output_section() != NULL)
-	{
-	  const Output_data* od = this->plt_->rel_plt();
-	  odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
-	  odyn->add_section_address(elfcpp::DT_JMPREL, od);
-	  odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA);
-
-	  odyn->add_section_address(elfcpp::DT_PLTGOT, this->plt_);
-	}
-
-      if (this->rela_dyn_ != NULL
-	  && this->rela_dyn_->output_section() != NULL)
-	{
-	  const Output_data* od = this->rela_dyn_;
-	  odyn->add_section_address(elfcpp::DT_RELA, od);
-	  odyn->add_section_size(elfcpp::DT_RELASZ, od);
-	  odyn->add_constant(elfcpp::DT_RELAENT,
-			     elfcpp::Elf_sizes<size>::rela_size);
-	}
-
-      if (!parameters->options().shared())
-	{
-	  // The value of the DT_DEBUG tag is filled in by the dynamic
-	  // linker at run time, and used by the debugger.
-	  odyn->add_constant(elfcpp::DT_DEBUG, 0);
-	}
-    }
+  const Reloc_section* rel_plt = (this->plt_ == NULL
+				  ? NULL
+				  : this->plt_->rel_plt());
+  layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
+				  this->rela_dyn_, true);
 
   // Emit any relocs we saved in an attempt to avoid generating COPY
   // relocs.
Index: x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.102
diff -p -u -r1.102 x86_64.cc
--- x86_64.cc	30 Dec 2009 07:22:06 -0000	1.102
+++ x86_64.cc	7 Jan 2010 20:40:21 -0000
@@ -1655,48 +1655,27 @@ Target_x86_64::do_finalize_sections(
     const Input_objects*,
     Symbol_table* symtab)
 {
+  const Reloc_section* rel_plt = (this->plt_ == NULL
+				  ? NULL
+				  : this->plt_->rel_plt());
+  layout->add_target_dynamic_tags(false, this->got_plt_, rel_plt,
+				  this->rela_dyn_, true);
+				  
   // Fill in some more dynamic tags.
   Output_data_dynamic* const odyn = layout->dynamic_data();
   if (odyn != NULL)
     {
-      if (this->got_plt_ != NULL
-	  && this->got_plt_->output_section() != NULL)
-	odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_);
-
       if (this->plt_ != NULL
-	  && this->plt_->output_section() != NULL)
-	{
-	  const Output_data* od = this->plt_->rel_plt();
-	  odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
-	  odyn->add_section_address(elfcpp::DT_JMPREL, od);
-	  odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA);
-	  if (this->plt_->has_tlsdesc_entry())
-	    {
-              unsigned int plt_offset = this->plt_->get_tlsdesc_plt_offset();
-              unsigned int got_offset = this->plt_->get_tlsdesc_got_offset();
-              this->got_->finalize_data_size();
-              odyn->add_section_plus_offset(elfcpp::DT_TLSDESC_PLT,
-                                            this->plt_, plt_offset);
-              odyn->add_section_plus_offset(elfcpp::DT_TLSDESC_GOT,
-                                            this->got_, got_offset);
-	    }
-	}
-
-      if (this->rela_dyn_ != NULL
-	  && this->rela_dyn_->output_section() != NULL)
-	{
-	  const Output_data* od = this->rela_dyn_;
-	  odyn->add_section_address(elfcpp::DT_RELA, od);
-	  odyn->add_section_size(elfcpp::DT_RELASZ, od);
-	  odyn->add_constant(elfcpp::DT_RELAENT,
-			     elfcpp::Elf_sizes<64>::rela_size);
-	}
-
-      if (!parameters->options().shared())
+	  && this->plt_->output_section() != NULL
+	  && this->plt_->has_tlsdesc_entry())
 	{
-	  // The value of the DT_DEBUG tag is filled in by the dynamic
-	  // linker at run time, and used by the debugger.
-	  odyn->add_constant(elfcpp::DT_DEBUG, 0);
+	  unsigned int plt_offset = this->plt_->get_tlsdesc_plt_offset();
+	  unsigned int got_offset = this->plt_->get_tlsdesc_got_offset();
+	  this->got_->finalize_data_size();
+	  odyn->add_section_plus_offset(elfcpp::DT_TLSDESC_PLT,
+					this->plt_, plt_offset);
+	  odyn->add_section_plus_offset(elfcpp::DT_TLSDESC_GOT,
+					this->got_, got_offset);
 	}
     }
 

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