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]

Mips target in gold - part 3


Hi all,

This is the third part of the patches that implement Mips target in gold. The attached files contain changes to target-independent code in gold:

1. start.patch
This patch allows a target to define start symbol. Mips start symbol is "__start" instead of "_start".

2. dynsym.patch
This patch allows a target to set dynamic symbol indexes. Mips ABI requires that the order of symbols in .got matches the order of dynamic symbols. The patch adds a call to a target hook at the beginning of the method Symbol_table::set_dynsym_indexes. Mips implementation of the method set_dynsym_indexes is almost identical to Symbol_table::set_dynsym_indexes, except that at the start of the method dynamic symbols are ordered based on their position in the .got.

3. nonvis.patch
This patch adds a method in the class Symbol that sets the non-visibility part of the st_other field. Mips uses st_other's non-visibility part to record different flags about the symbol (whether it has plt stub, whether it is mips16 etc.)

4. dynamic-tag.patch
This patch adds a new kind of Dynamic_entry, whose value is calculated by calling a target defined hook. Mips has several dynamic tags whose value is not known in the method do_finalize_sections, and the existing Dynamic_entries cannot handle the calculation. (for example DT_MIPS_SYMTABNO which is the number of entries in .dynsym section).

5. init-output-data.patch
This patch instantiates the template for Sized_symbol::init_output_data.

6. config.patch
This patch changes configure and Makefiles.

Regards,
Sasa
diff --git a/gold/parameters.cc b/gold/parameters.cc
index d69b62c..658f787 100644
--- a/gold/parameters.cc
+++ b/gold/parameters.cc
@@ -226,10 +226,7 @@ Parameters::entry() const
 {
   const char* ret = this->options().entry();
   if (ret == NULL)
-    {
-      // FIXME: Need to support target specific entry symbol.
-      ret = "_start";
-    }
+    ret = parameters->target().entry_symbol_name();
   return ret;
 }
 
diff --git a/gold/target.h b/gold/target.h
index 6523c04..23bef9d 100644
--- a/gold/target.h
+++ b/gold/target.h
@@ -449,6 +449,10 @@ class Target
   gc_mark_symbol(Symbol_table* symtab, Symbol* sym) const
   { this->do_gc_mark_symbol(symtab, sym); }
 
+  virtual const char*
+  entry_symbol_name() const
+  { return "_start"; }
+
  protected:
   // This struct holds the constant information for a child class.  We
   // use a struct to avoid the overhead of virtual function calls for
diff --git a/gold/symtab.cc b/gold/symtab.cc
index 2e17529..ac6db1d 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -2369,12 +2369,29 @@ Symbol_table::set_dynsym_indexes(unsigned int index,
 				 Versions* versions)
 {
   std::vector<Symbol*> as_needed_sym;
+  std::vector<Symbol*> dyn_symbols;
 
   for (Symbol_table_type::iterator p = this->table_.begin();
        p != this->table_.end();
        ++p)
     {
       Symbol* sym = p->second;
+      if (!sym->should_add_dynsym_entry(this))
+        sym->set_dynsym_index(-1U);
+      else
+        dyn_symbols.push_back(sym);
+    }
+
+  // Allow a target to set dynsym indexes.
+  if (parameters->target().custom_set_dynsym_indexes())
+    return parameters->target().set_dynsym_indexes(&dyn_symbols, index, syms,
+                                                   dynpool, versions, this);
+
+  for (std::vector<Symbol *>::iterator p = dyn_symbols.begin();
+       p != dyn_symbols.end();
+       ++p)
+    {
+      Symbol* sym = *p;
 
       // Note that SYM may already have a dynamic symbol index, since
       // some symbols appear more than once in the symbol table, with
diff --git a/gold/target.h b/gold/target.h
index 23bef9d..91fc5a7 100644
--- a/gold/target.h
+++ b/gold/target.h
@@ -37,6 +37,7 @@
 #include "elfcpp.h"
 #include "options.h"
 #include "parameters.h"
+#include "stringpool.h"
 #include "debug.h"
 
 namespace gold
@@ -62,6 +63,7 @@ class Output_section;
 class Input_objects;
 class Task;
 struct Symbol_location;
+class Versions;
 
 // The abstract class for target specific handling.
 
@@ -453,6 +455,15 @@ class Target
   entry_symbol_name() const
   { return "_start"; }
 
+  virtual bool
+  custom_set_dynsym_indexes() const
+  { return false; }
+
+  virtual unsigned int
+  set_dynsym_indexes(std::vector<Symbol*>*, unsigned int, std::vector<Symbol*>*,
+                     Stringpool*, Versions*, Symbol_table*) const
+  { gold_unreachable(); }
+
  protected:
   // This struct holds the constant information for a child class.  We
   // use a struct to avoid the overhead of virtual function calls for
diff --git a/gold/symtab.h b/gold/symtab.h
index 689d99f..9c32242 100644
--- a/gold/symtab.h
+++ b/gold/symtab.h
@@ -259,6 +259,11 @@ class Symbol
   nonvis() const
   { return this->nonvis_; }
 
+  // Set the non-visibility part of the st_other field.
+  void
+  set_nonvis(unsigned int nonvis)
+  { this->nonvis_ = nonvis; }
+
   // Return whether this symbol is a forwarder.  This will never be
   // true of a symbol found in the hash table, but may be true of
   // symbol pointers attached to object files.
diff --git a/gold/output.cc b/gold/output.cc
index 75ce840..3053ce6 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -1797,6 +1797,10 @@ Output_data_dynamic::Dynamic_entry::write(
       val = pool->get_offset(this->u_.str);
       break;
 
+    case DYNAMIC_CUSTOM:
+      val = parameters->target().dynamic_tag_custom_value(this->tag_);
+      break;
+
     default:
       val = this->u_.od->address() + this->offset_;
       break;
diff --git a/gold/output.h b/gold/output.h
index 7722237..7bd3464 100644
--- a/gold/output.h
+++ b/gold/output.h
@@ -2574,6 +2574,11 @@ class Output_data_dynamic : public Output_section_data
   add_string(elfcpp::DT tag, const std::string& str)
   { this->add_string(tag, str.c_str()); }
 
+  // Add a new dynamic entry with custom value.
+  void
+  add_custom(elfcpp::DT tag)
+  { this->add_entry(Dynamic_entry(tag)); }
+
  protected:
   // Adjust the output section to set the entry size.
   void
@@ -2638,6 +2643,11 @@ class Output_data_dynamic : public Output_section_data
       : tag_(tag), offset_(DYNAMIC_STRING)
     { this->u_.str = str; }
 
+    // Create an entry with a custom value.
+    Dynamic_entry(elfcpp::DT tag)
+      : tag_(tag), offset_(DYNAMIC_CUSTOM)
+    { }
+
     // Return the tag of this entry.
     elfcpp::DT
     tag() const
@@ -2661,7 +2671,9 @@ class Output_data_dynamic : public Output_section_data
       // Symbol adress.
       DYNAMIC_SYMBOL = -3U,
       // String.
-      DYNAMIC_STRING = -4U
+      DYNAMIC_STRING = -4U,
+      // Custom value.
+      DYNAMIC_CUSTOM = -5U
       // Any other value indicates a section address plus OFFSET.
     };
 
diff --git a/gold/target.h b/gold/target.h
index 91fc5a7..aecfad7 100644
--- a/gold/target.h
+++ b/gold/target.h
@@ -464,6 +464,11 @@ class Target
                      Stringpool*, Versions*, Symbol_table*) const
   { gold_unreachable(); }
 
+  // Get the custom dynamic tag value.
+  virtual unsigned int
+  dynamic_tag_custom_value(elfcpp::DT) const
+  { gold_unreachable(); }
+
  protected:
   // This struct holds the constant information for a child class.  We
   // use a struct to avoid the overhead of virtual function calls for
diff --git a/gold/symtab.cc b/gold/symtab.cc
index ac6db1d..2d11a42 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -3639,6 +3639,32 @@ Symbol_table::define_with_copy_reloc<64>(
     elfcpp::Elf_types<64>::Elf_Addr value);
 #endif
 
+#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
+template
+void
+Sized_symbol<32>::init_output_data(const char* name, const char* version,
+				   Output_data* od, Value_type value,
+				   Size_type symsize, elfcpp::STT type,
+				   elfcpp::STB binding,
+				   elfcpp::STV visibility,
+				   unsigned char nonvis,
+				   bool offset_is_from_end,
+				   bool is_predefined);
+#endif
+
+#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
+template
+void
+Sized_symbol<64>::init_output_data(const char* name, const char* version,
+				   Output_data* od, Value_type value,
+				   Size_type symsize, elfcpp::STT type,
+				   elfcpp::STB binding,
+				   elfcpp::STV visibility,
+				   unsigned char nonvis,
+				   bool offset_is_from_end,
+				   bool is_predefined);
+#endif
+
 #ifdef HAVE_TARGET_32_LITTLE
 template
 void
diff --git a/gold/Makefile.am b/gold/Makefile.am
index 8e2fff1..12699d0 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -164,11 +164,12 @@ DEFFILES = arm-reloc.def
 EXTRA_DIST = yyscript.c yyscript.h
 
 TARGETSOURCES = \
-	i386.cc x86_64.cc sparc.cc powerpc.cc arm.cc arm-reloc-property.cc tilegx.cc
+	i386.cc x86_64.cc sparc.cc powerpc.cc arm.cc arm-reloc-property.cc tilegx.cc \
+	mips.cc
 
 ALL_TARGETOBJS = \
 	i386.$(OBJEXT) x86_64.$(OBJEXT) sparc.$(OBJEXT) powerpc.$(OBJEXT) \
-	arm.$(OBJEXT) arm-reloc-property.$(OBJEXT) tilegx.$(OBJEXT)
+	arm.$(OBJEXT) arm-reloc-property.$(OBJEXT) tilegx.$(OBJEXT) mips.$(OBJEXT)
 
 libgold_a_SOURCES = $(CCFILES) $(HFILES) $(YFILES) $(DEFFILES)
 libgold_a_LIBADD = $(LIBOBJS)
diff --git a/gold/Makefile.in b/gold/Makefile.in
index 09de14c..0a1ecbb 100644
--- a/gold/Makefile.in
+++ b/gold/Makefile.in
@@ -532,11 +532,12 @@ YFILES = \
 DEFFILES = arm-reloc.def
 EXTRA_DIST = yyscript.c yyscript.h
 TARGETSOURCES = \
-	i386.cc x86_64.cc sparc.cc powerpc.cc arm.cc arm-reloc-property.cc tilegx.cc
+	i386.cc x86_64.cc sparc.cc powerpc.cc arm.cc arm-reloc-property.cc tilegx.cc \
+	mips.cc
 
 ALL_TARGETOBJS = \
 	i386.$(OBJEXT) x86_64.$(OBJEXT) sparc.$(OBJEXT) powerpc.$(OBJEXT) \
-	arm.$(OBJEXT) arm-reloc-property.$(OBJEXT) tilegx.$(OBJEXT)
+	arm.$(OBJEXT) arm-reloc-property.$(OBJEXT) tilegx.$(OBJEXT) mips.$(OBJEXT)
 
 libgold_a_SOURCES = $(CCFILES) $(HFILES) $(YFILES) $(DEFFILES)
 libgold_a_LIBADD = $(LIBOBJS)
diff --git a/gold/configure.tgt b/gold/configure.tgt
index d61647e..8b816fc 100644
--- a/gold/configure.tgt
+++ b/gold/configure.tgt
@@ -144,6 +144,20 @@ arm*-*-*)
  targ_big_endian=false
  targ_extra_big_endian=true
  ;;
+mips*-*-*)
+ targ_obj=mips
+ targ_machine=EM_MIPS
+ targ_size=32
+ targ_big_endian=true
+ targ_extra_big_endian=false
+ ;;
+mips*el*-*-*|mips*le*-*-*)
+ targ_obj=mips
+ targ_machine=EM_MIPS_RS3_LE
+ targ_size=32
+ targ_big_endian=false
+ targ_extra_big_endian=true
+ ;;
 *)
   targ_obj=UNKNOWN
   ;;

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