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]

[PATCH] gold: Remove ei_class from mips.cc.


This patch removes ei_class from mips.cc, and changes the way how to check for N64 ABI.
Depends on https://sourceware.org/ml/binutils/2016-03/msg00221.html.

Regards,
Vladimir.

ChangeLog -

    * elfcpp/mips.h (abi_64): Remove.
    * gold/mips.cc (Mips_relobj::Mips_relobj): Set is_n64_ by checking
    template parameter size.
    (Target_mips::is_output_n64): Change checking for N64 ABI.
    (Target_mips::ei_class_): Remove.
    (Target_mips::merge_processor_specific_flags): Remove ei_class
    argument, and remove comparing ei_class.
    (Target_mips::do_adjust_elf_header): Remove setting EI_CLASS field
    of the ELF header.
    (Target_mips::do_finalize_sections): Don't pass ei_class argument
    to merge_processor_specific_flags.
    (Target_mips::elf_mips_abi_name): Remove ei_class argument, and
    change checking for N64 ABI.
diff --git a/elfcpp/mips.h b/elfcpp/mips.h
index 4172850..10137ec 100644
--- a/elfcpp/mips.h
+++ b/elfcpp/mips.h
@@ -339,11 +339,6 @@ bool
 abi_n32(elfcpp::Elf_Word e_flags)
 { return (e_flags & elfcpp::EF_MIPS_ABI2) != 0; }
 
-// Whether the ABI is N64.
-bool
-abi_64(unsigned char ei_class)
-{ return ei_class == elfcpp::ELFCLASS64; }
-
 // Whether the file has microMIPS code.
 bool
 is_micromips(elfcpp::Elf_Word e_flags)
diff --git a/gold/mips.cc b/gold/mips.cc
index f905d83..070f30e 100644
--- a/gold/mips.cc
+++ b/gold/mips.cc
@@ -1537,7 +1537,7 @@ class Mips_relobj : public Sized_relobj_file<size, big_endian>
   {
     this->is_pic_ = (ehdr.get_e_flags() & elfcpp::EF_MIPS_PIC) != 0;
     this->is_n32_ = elfcpp::abi_n32(ehdr.get_e_flags());
-    this->is_n64_ = elfcpp::abi_64(ehdr.get_e_ident()[elfcpp::EI_CLASS]);
+    this->is_n64_ = size == 64;
   }
 
   ~Mips_relobj()
@@ -3197,8 +3197,8 @@ class Target_mips : public Sized_target<size, big_endian>
     : Sized_target<size, big_endian>(info), got_(NULL), gp_(NULL), plt_(NULL),
       got_plt_(NULL), rel_dyn_(NULL), copy_relocs_(),
       dyn_relocs_(), la25_stub_(NULL), mips_mach_extensions_(),
-      mips_stubs_(NULL), ei_class_(0), mach_(0), layout_(NULL),
-      got16_addends_(), entry_symbol_is_compressed_(false), insn32_(false)
+      mips_stubs_(NULL), mach_(0), layout_(NULL), got16_addends_(),
+      entry_symbol_is_compressed_(false), insn32_(false)
   {
     this->add_machine_extensions();
   }
@@ -3480,13 +3480,11 @@ class Target_mips : public Sized_target<size, big_endian>
     return elfcpp::abi_n32(this->processor_specific_flags());
   }
 
-  // Whether the output uses N64 ABI.  This is valid only after
-  // merge_processor_specific_flags() is called.
+  // Whether the output uses N64 ABI.
   bool
   is_output_n64() const
   {
-    gold_assert(this->are_processor_specific_flags_set());
-    return elfcpp::abi_64(this->ei_class_);
+    return size == 64;
   }
 
   // Whether the output uses NEWABI.  This is valid only after
@@ -3855,8 +3853,7 @@ class Target_mips : public Sized_target<size, big_endian>
 
   // Merge processor specific flags.
   void
-  merge_processor_specific_flags(const std::string&, elfcpp::Elf_Word,
-                                 unsigned char, bool);
+  merge_processor_specific_flags(const std::string&, elfcpp::Elf_Word, bool);
 
   // True if we are linking for CPUs that are faster if JAL is converted to BAL.
   static inline bool
@@ -3935,7 +3932,7 @@ class Target_mips : public Sized_target<size, big_endian>
   set_gp(Layout*, Symbol_table*);
 
   const char*
-  elf_mips_abi_name(elfcpp::Elf_Word e_flags, unsigned char ei_class);
+  elf_mips_abi_name(elfcpp::Elf_Word e_flags);
   const char*
   elf_mips_mach_name(elfcpp::Elf_Word e_flags);
 
@@ -4048,7 +4045,6 @@ class Target_mips : public Sized_target<size, big_endian>
   // .MIPS.stubs
   Mips_output_data_mips_stubs<size, big_endian>* mips_stubs_;
 
-  unsigned char ei_class_;
   unsigned int mach_;
   Layout* layout_;
 
@@ -8347,14 +8343,12 @@ Target_mips<size, big_endian>::mips_mach_extends(unsigned int base,
 template<int size, bool big_endian>
 void
 Target_mips<size, big_endian>::merge_processor_specific_flags(
-    const std::string& name, elfcpp::Elf_Word in_flags,
-    unsigned char in_ei_class, bool dyn_obj)
+    const std::string& name, elfcpp::Elf_Word in_flags, bool dyn_obj)
 {
   // If flags are not set yet, just copy them.
   if (!this->are_processor_specific_flags_set())
     {
       this->set_processor_specific_flags(in_flags);
-      this->ei_class_ = in_ei_class;
       this->mach_ = this->elf_mips_mach(in_flags);
       return;
     }
@@ -8436,19 +8430,16 @@ Target_mips<size, big_endian>::merge_processor_specific_flags(
   old_flags &= (~(elfcpp::EF_MIPS_ARCH | elfcpp::EF_MIPS_MACH
                 | elfcpp::EF_MIPS_32BITMODE));
 
-  // Compare ABIs.  The 64-bit ABI does not use EF_MIPS_ABI. But, it does set
-  // EI_CLASS differently from any 32-bit ABI.
-  if ((new_flags & elfcpp::EF_MIPS_ABI) != (old_flags & elfcpp::EF_MIPS_ABI)
-      || (in_ei_class != this->ei_class_))
+  // Compare ABIs.
+  if ((new_flags & elfcpp::EF_MIPS_ABI) != (old_flags & elfcpp::EF_MIPS_ABI))
     {
       // Only error if both are set (to different values).
-      if (((new_flags & elfcpp::EF_MIPS_ABI)
+      if ((new_flags & elfcpp::EF_MIPS_ABI)
            && (old_flags & elfcpp::EF_MIPS_ABI))
-          || (in_ei_class != this->ei_class_))
         gold_error(_("%s: ABI mismatch: linking %s module with "
                      "previous %s modules"), name.c_str(),
-                   this->elf_mips_abi_name(in_flags, in_ei_class),
-                   this->elf_mips_abi_name(merged_flags, this->ei_class_));
+                   this->elf_mips_abi_name(in_flags),
+                   this->elf_mips_abi_name(merged_flags));
 
       new_flags &= ~elfcpp::EF_MIPS_ABI;
       old_flags &= ~elfcpp::EF_MIPS_ABI;
@@ -8496,16 +8487,13 @@ Target_mips<size, big_endian>::do_adjust_elf_header(
 {
   gold_assert(len == elfcpp::Elf_sizes<size>::ehdr_size);
 
-  elfcpp::Ehdr<size, big_endian> ehdr(view);
-  unsigned char e_ident[elfcpp::EI_NIDENT];
-  memcpy(e_ident, ehdr.get_e_ident(), elfcpp::EI_NIDENT);
-
-  e_ident[elfcpp::EI_CLASS] = this->ei_class_;
+  if (!this->entry_symbol_is_compressed_)
+    return;
 
+  elfcpp::Ehdr<size, big_endian> ehdr(view);
   elfcpp::Ehdr_write<size, big_endian> oehdr(view);
-  oehdr.put_e_ident(e_ident);
-  if (this->entry_symbol_is_compressed_)
-    oehdr.put_e_entry(ehdr.get_e_entry() + 1);
+
+  oehdr.put_e_entry(ehdr.get_e_entry() + 1);
 }
 
 // do_make_elf_object to override the same function in the base class.
@@ -8620,7 +8608,6 @@ Target_mips<size, big_endian>::do_finalize_sections(Layout* layout,
 
           elfcpp::Ehdr<size, big_endian> ehdr(pehdr);
           elfcpp::Elf_Word in_flags = ehdr.get_e_flags();
-          unsigned char ei_class = ehdr.get_e_ident()[elfcpp::EI_CLASS];
           // If all input sections will be discarded, don't use this object
           // file for merging processor specific flags.
           bool should_merge_processor_specific_flags = false;
@@ -8634,7 +8621,7 @@ Target_mips<size, big_endian>::do_finalize_sections(Layout* layout,
 
           if (should_merge_processor_specific_flags)
             this->merge_processor_specific_flags(relobj->name(), in_flags,
-                                                 ei_class, false);
+                                                 false);
         }
     }
 
@@ -8652,10 +8639,8 @@ Target_mips<size, big_endian>::do_finalize_sections(Layout* layout,
 
       elfcpp::Ehdr<size, big_endian> ehdr(pehdr);
       elfcpp::Elf_Word in_flags = ehdr.get_e_flags();
-      unsigned char ei_class = ehdr.get_e_ident()[elfcpp::EI_CLASS];
 
-      this->merge_processor_specific_flags(dynobj->name(), in_flags, ei_class,
-                                           true);
+      this->merge_processor_specific_flags(dynobj->name(), in_flags, true);
     }
 
   // Merge .reginfo contents of input objects.
@@ -11233,15 +11218,14 @@ Target_mips<size, big_endian>::Scan::unsupported_reloc_global(
 // Return printable name for ABI.
 template<int size, bool big_endian>
 const char*
-Target_mips<size, big_endian>::elf_mips_abi_name(elfcpp::Elf_Word e_flags,
-                                                 unsigned char ei_class)
+Target_mips<size, big_endian>::elf_mips_abi_name(elfcpp::Elf_Word e_flags)
 {
   switch (e_flags & elfcpp::EF_MIPS_ABI)
     {
     case 0:
       if ((e_flags & elfcpp::EF_MIPS_ABI2) != 0)
         return "N32";
-      else if (elfcpp::abi_64(ei_class))
+      else if (size == 64)
         return "64";
       else
         return "none";

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