[GOLD] Output_data_got tidy

Message ID YTBFcRFJfg3iR4QJ@squeak.grove.modra.org
State New
Headers show
Series
  • [GOLD] Output_data_got tidy
Related show

Commit Message

Alan Modra via Binutils Sept. 2, 2021, 3:30 a.m.
Some Output_data_got methods already have support for addends, but
were implemented as separate methods.  This removes unnecessary code
duplication by making the overloads without an addend inline calls of
the overload with addend.

Relobj::local_has_got_offset and others there get a similar treatment.
Comments are removed since it should be obvious without a comment, and
the existing comments are not precisely what the code does.  For
example, a local_has_got_offset call without an addend does not return
whether the local symbol has *a* GOT offset of type GOT_TYPE, it
returns whether there is a GOT entry of type GOT_TYPE for the symbol
with addend of zero.

	PR 28192
	* output.h (Output_data_got::add_local): Make overload without
	addend call overload with addend.
	(Output_data_got::add_local_with_rel): Likewise.
	(Output_data_got::add_local_pair_with_rel): Likewise.
	* output.cc (Output_data_got::add_local): Delete overload
	without addend.
	(Output_data_got::add_local_with_rel): Likewise.
	(Output_data_got::add_local_pair_with_rel): Likewise.
	* object.h (Relobj::local_has_got_offset): Move overload without
	addend later, and call version with addend rather than expanding
	that version.  Update comment.
	(Relobj::local_got_offset): Likewise.
	(Relobj::set_local_got_offset): Likewise.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/gold/object.h b/gold/object.h
index 2dbe4b3e1be..1d68f2a53a2 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -1216,48 +1216,42 @@  class Relobj : public Object
   local_plt_offset(unsigned int symndx) const
   { return this->do_local_plt_offset(symndx); }
 
-  // Return whether the local symbol SYMNDX has a GOT offset of type
-  // GOT_TYPE.
-  bool
-  local_has_got_offset(unsigned int symndx, unsigned int got_type) const
-  { return this->do_local_has_got_offset(symndx, got_type, 0); }
-
-  // Return whether the local symbol SYMNDX plus ADDEND has a GOT offset
-  // of type GOT_TYPE.
+  // Return whether there is a GOT entry of type GOT_TYPE for the
+  // local symbol SYMNDX with given ADDEND.
   bool
   local_has_got_offset(unsigned int symndx, unsigned int got_type,
 		       uint64_t addend) const
   { return this->do_local_has_got_offset(symndx, got_type, addend); }
 
-  // Return the GOT offset of type GOT_TYPE of the local symbol
-  // SYMNDX.  It is an error to call this if the symbol does not have
-  // a GOT offset of the specified type.
-  unsigned int
-  local_got_offset(unsigned int symndx, unsigned int got_type) const
-  { return this->do_local_got_offset(symndx, got_type, 0); }
+  bool
+  local_has_got_offset(unsigned int symndx, unsigned int got_type) const
+  { return this->local_has_got_offset(symndx, got_type, 0); }
 
-  // Return the GOT offset of type GOT_TYPE of the local symbol
-  // SYMNDX plus ADDEND.  It is an error to call this if the symbol
-  // does not have a GOT offset of the specified type.
+  // Return the GOT offset of the GOT entry with type GOT_TYPE for the
+  // local symbol SYMNDX with given ADDEND.  It is an error to call
+  // this function if the symbol does not have such a GOT entry.
   unsigned int
   local_got_offset(unsigned int symndx, unsigned int got_type,
-		       uint64_t addend) const
+		   uint64_t addend) const
   { return this->do_local_got_offset(symndx, got_type, addend); }
 
-  // Set the GOT offset with type GOT_TYPE of the local symbol SYMNDX
-  // to GOT_OFFSET.
-  void
-  set_local_got_offset(unsigned int symndx, unsigned int got_type,
-		       unsigned int got_offset)
-  { this->do_set_local_got_offset(symndx, got_type, got_offset, 0); }
+  unsigned int
+  local_got_offset(unsigned int symndx, unsigned int got_type) const
+  { return this->local_got_offset(symndx, got_type, 0); }
 
-  // Set the GOT offset with type GOT_TYPE of the local symbol SYMNDX
-  // plus ADDEND to GOT_OFFSET.
+  // Set the GOT offset for a GOT entry with type GOT_TYPE for the
+  // local symbol SYMNDX with ADDEND to GOT_OFFSET.  Create such an
+  // entry if none exists.
   void
   set_local_got_offset(unsigned int symndx, unsigned int got_type,
 		       unsigned int got_offset, uint64_t addend)
   { this->do_set_local_got_offset(symndx, got_type, got_offset, addend); }
 
+  void
+  set_local_got_offset(unsigned int symndx, unsigned int got_type,
+		       unsigned int got_offset)
+  { this->set_local_got_offset(symndx, got_type, got_offset, 0); }
+
   // Return whether the local symbol SYMNDX is a TLS symbol.
   bool
   local_is_tls(unsigned int symndx) const
diff --git a/gold/output.cc b/gold/output.cc
index afdba06753e..75f54f02f23 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -1531,26 +1531,6 @@  Output_data_got<got_size, big_endian>::add_global_pair_with_rel(
 				got_offset + got_size / 8, 0);
 }
 
-// Add an entry for a local symbol to the GOT.  This returns true if
-// this is a new GOT entry, false if the symbol already has a GOT
-// entry.
-
-template<int got_size, bool big_endian>
-bool
-Output_data_got<got_size, big_endian>::add_local(
-    Relobj* object,
-    unsigned int symndx,
-    unsigned int got_type)
-{
-  if (object->local_has_got_offset(symndx, got_type))
-    return false;
-
-  unsigned int got_offset = this->add_got_entry(Got_entry(object, symndx,
-							  false));
-  object->set_local_got_offset(symndx, got_type, got_offset);
-  return true;
-}
-
 // Add an entry for a local symbol plus ADDEND to the GOT.  This returns
 // true if this is a new GOT entry, false if the symbol already has a GOT
 // entry.
@@ -1590,26 +1570,6 @@  Output_data_got<got_size, big_endian>::add_local_plt(
   return true;
 }
 
-// Add an entry for a local symbol to the GOT, and add a dynamic
-// relocation of type R_TYPE for the GOT entry.
-
-template<int got_size, bool big_endian>
-void
-Output_data_got<got_size, big_endian>::add_local_with_rel(
-    Relobj* object,
-    unsigned int symndx,
-    unsigned int got_type,
-    Output_data_reloc_generic* rel_dyn,
-    unsigned int r_type)
-{
-  if (object->local_has_got_offset(symndx, got_type))
-    return;
-
-  unsigned int got_offset = this->add_got_entry(Got_entry());
-  object->set_local_got_offset(symndx, got_type, got_offset);
-  rel_dyn->add_local_generic(object, symndx, r_type, this, got_offset, 0);
-}
-
 // Add an entry for a local symbol plus ADDEND to the GOT, and add a dynamic
 // relocation of type R_TYPE for the GOT entry.
 
@@ -1631,32 +1591,6 @@  Output_data_got<got_size, big_endian>::add_local_with_rel(
                              addend);
 }
 
-// Add a pair of entries for a local symbol to the GOT, and add
-// a dynamic relocation of type R_TYPE using the section symbol of
-// the output section to which input section SHNDX maps, on the first.
-// The first got entry will have a value of zero, the second the
-// value of the local symbol.
-template<int got_size, bool big_endian>
-void
-Output_data_got<got_size, big_endian>::add_local_pair_with_rel(
-    Relobj* object,
-    unsigned int symndx,
-    unsigned int shndx,
-    unsigned int got_type,
-    Output_data_reloc_generic* rel_dyn,
-    unsigned int r_type)
-{
-  if (object->local_has_got_offset(symndx, got_type))
-    return;
-
-  unsigned int got_offset =
-      this->add_got_entry_pair(Got_entry(),
-			       Got_entry(object, symndx, false));
-  object->set_local_got_offset(symndx, got_type, got_offset);
-  Output_section* os = object->output_section(shndx);
-  rel_dyn->add_output_section_generic(os, r_type, this, got_offset, 0);
-}
-
 // Add a pair of entries for a local symbol plus ADDEND to the GOT, and add
 // a dynamic relocation of type R_TYPE using the section symbol of
 // the output section to which input section SHNDX maps, on the first.
diff --git a/gold/output.h b/gold/output.h
index 9c44f6259a2..9c7bfd84dcc 100644
--- a/gold/output.h
+++ b/gold/output.h
@@ -2488,12 +2488,6 @@  class Output_data_got : public Output_data_got_base
 			   Output_data_reloc_generic* rel_dyn,
 			   unsigned int r_type_1, unsigned int r_type_2);
 
-  // Add an entry for a local symbol to the GOT.  This returns true if
-  // this is a new GOT entry, false if the symbol already has a GOT
-  // entry.
-  bool
-  add_local(Relobj* object, unsigned int sym_index, unsigned int got_type);
-
   // Add an entry for a local symbol plus ADDEND to the GOT.  This returns
   // true if this is a new GOT entry, false if the symbol already has a GOT
   // entry.
@@ -2501,6 +2495,10 @@  class Output_data_got : public Output_data_got_base
   add_local(Relobj* object, unsigned int sym_index, unsigned int got_type,
 	    uint64_t addend);
 
+  bool
+  add_local(Relobj* object, unsigned int sym_index, unsigned int got_type)
+  { return this->add_local(object, sym_index, got_type, 0); }
+
   // Like add_local, but use the PLT offset of the local symbol if it
   // has one.
   bool
@@ -2512,21 +2510,20 @@  class Output_data_got : public Output_data_got_base
   add_local_tls(Relobj* object, unsigned int sym_index, unsigned int got_type)
   { return add_local_plt(object, sym_index, got_type); }
 
-  // Add an entry for a local symbol to the GOT, and add a dynamic
+  // Add an entry for a local symbol plus ADDEND to the GOT, and add a dynamic
   // relocation of type R_TYPE for the GOT entry.
   void
   add_local_with_rel(Relobj* object, unsigned int sym_index,
 		     unsigned int got_type, Output_data_reloc_generic* rel_dyn,
-		     unsigned int r_type);
+		     unsigned int r_type, uint64_t addend);
 
-  // Add an entry for a local symbol plus ADDEND to the GOT, and add a dynamic
-  // relocation of type R_TYPE for the GOT entry.
   void
   add_local_with_rel(Relobj* object, unsigned int sym_index,
 		     unsigned int got_type, Output_data_reloc_generic* rel_dyn,
-		     unsigned int r_type, uint64_t addend);
+		     unsigned int r_type)
+  { this->add_local_with_rel(object, sym_index, got_type, rel_dyn, r_type, 0); }
 
-  // Add a pair of entries for a local symbol to the GOT, and add
+  // Add a pair of entries for a local symbol plus ADDEND to the GOT, and add
   // a dynamic relocation of type R_TYPE using the section symbol of
   // the output section to which input section SHNDX maps, on the first.
   // The first got entry will have a value of zero, the second the
@@ -2535,18 +2532,15 @@  class Output_data_got : public Output_data_got_base
   add_local_pair_with_rel(Relobj* object, unsigned int sym_index,
 			  unsigned int shndx, unsigned int got_type,
 			  Output_data_reloc_generic* rel_dyn,
-			  unsigned int r_type);
+			  unsigned int r_type, uint64_t addend);
 
-  // Add a pair of entries for a local symbol plus ADDEND to the GOT, and add
-  // a dynamic relocation of type R_TYPE using the section symbol of
-  // the output section to which input section SHNDX maps, on the first.
-  // The first got entry will have a value of zero, the second the
-  // value of the local symbol.
   void
   add_local_pair_with_rel(Relobj* object, unsigned int sym_index,
 			  unsigned int shndx, unsigned int got_type,
 			  Output_data_reloc_generic* rel_dyn,
-			  unsigned int r_type, uint64_t addend);
+			  unsigned int r_type)
+  { this->add_local_pair_with_rel(object, sym_index, shndx, got_type,
+				  rel_dyn, r_type, 0); }
 
   // Add a pair of entries for a local symbol to the GOT, and add
   // a dynamic relocation of type R_TYPE using STN_UNDEF on the first.