Cosmetic improvements for OSABI access.
authorCary Coutant <ccoutant@gmail.com>
Tue, 15 Dec 2020 22:37:22 +0000 (14:37 -0800)
committerCary Coutant <ccoutant@gmail.com>
Tue, 15 Dec 2020 22:37:22 +0000 (14:37 -0800)
Add accessor methods to elfcpp::Ehdr class for EI_OSABI and EI_ABIVERSION;
use those to simplify initialization of Osabi class and eliminate the need
to template the class.

elfcpp/
* elfcpp.h (class Ehdr): Add get_ei_osabi and get_ei_abiversion methods.

gold/
* dwp.cc (class Dwo_file): Use new Ehdr::get_ei_osabi and
get_ei_abiversion methods.
* incremental.cc (make_sized_incremental_binary): Likewise.
* object.cc (Sized_relobj_file::Sized_relobj_file): Likewise.
(make_elf_sized_object): Likewise.
* object.h (class Osabi): Make the class untemplated.

elfcpp/ChangeLog
elfcpp/elfcpp.h
gold/ChangeLog
gold/dwp.cc
gold/incremental.cc
gold/object.cc
gold/object.h

index 73432dad9b24c87ff16f8743e5fb20e0c6b770f1..0ae886e1780eb49fc6b3261be574e5772fdd08b3 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-15  Cary Coutant  <ccoutant@gmail.com>
+
+       * elfcpp.h (class Ehdr): Add get_ei_osabi and get_ei_abiversion methods.
+
 2020-12-15  Vivek Das Mohapatra  <vivek@collabora.com>
 
        * elfcpp.h (enum DT): New enum member DT_GNU_FLAGS_1.
index ee69d322e79a2bc5d384c6f715ba870e06e1eafa..428ecb8935009b44665f8f35bf8369f8df769c18 100644 (file)
@@ -1100,6 +1100,14 @@ class Ehdr
   get_e_ident() const
   { return this->p_->e_ident; }
 
+  unsigned char
+  get_ei_osabi() const
+  { return this->p_->e_ident[EI_OSABI]; }
+
+  unsigned char
+  get_ei_abiversion() const
+  { return this->p_->e_ident[EI_ABIVERSION]; }
+
   Elf_Half
   get_e_type() const
   { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
index 32decc69a43cca5a07ff061256a2360b4a5eada3..77b1f886c305f82cbb723b346b15434d497d03b0 100644 (file)
@@ -1,3 +1,12 @@
+2020-12-15  Cary Coutant  <ccoutant@gmail.com>
+
+       * dwp.cc (class Dwo_file): Use new Ehdr::get_ei_osabi and
+       get_ei_abiversion methods.
+       * incremental.cc (make_sized_incremental_binary): Likewise.
+       * object.cc (Sized_relobj_file::Sized_relobj_file): Likewise.
+       (make_elf_sized_object): Likewise.
+       * object.h (class Osabi): Make the class untemplated.
+
 2020-12-15  Vivek Das Mohapatra  <vivek@collabora.com>
 
        Implement -z unique / -z nounique options.
index 7c4eef090d482056d6b4ac379aeaf402cc6c4490..aae1fe212a2aa9ee0ac99d0a63b667d97207d490 100644 (file)
@@ -1107,8 +1107,8 @@ Dwo_file::sized_make_object(const unsigned char* p, Input_file* input_file,
   if (output_file != NULL)
     output_file->record_target_info(
        this->name_, ehdr.get_e_machine(), size, big_endian,
-       ehdr.get_e_ident()[elfcpp::EI_OSABI],
-       ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
+       ehdr.get_ei_osabi(),
+       ehdr.get_ei_abiversion());
   return obj;
 }
 
index 8d0df2d7bccc17d5efdf58ef78a53dfa5411c3d9..1f2ae5b87b3f2fab61e07d151e216bcdca4001f2 100644 (file)
@@ -856,8 +856,8 @@ make_sized_incremental_binary(Output_file* file,
 {
   Target* target = select_target(NULL, 0, // XXX
                                 ehdr.get_e_machine(), size, big_endian,
-                                ehdr.get_e_ident()[elfcpp::EI_OSABI],
-                                ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
+                                ehdr.get_ei_osabi(),
+                                ehdr.get_ei_abiversion());
   if (target == NULL)
     {
       explain_no_incremental(_("unsupported ELF machine number %d"),
index 072563b5a6a4d32b594284d5dbc5fbad5b90b24e..0edaf477db8c52aa3ba09776c6e8f16b03bc011d 100644 (file)
@@ -464,7 +464,8 @@ Sized_relobj_file<size, big_endian>::Sized_relobj_file(
     const elfcpp::Ehdr<size, big_endian>& ehdr)
   : Sized_relobj<size, big_endian>(name, input_file, offset),
     elf_file_(this, ehdr),
-    osabi_(ehdr),
+    osabi_(ehdr.get_ei_osabi()),
+    e_type_(ehdr.get_e_type()),
     symtab_shndx_(-1U),
     local_symbol_count_(0),
     output_local_symbol_count_(0),
@@ -482,7 +483,6 @@ Sized_relobj_file<size, big_endian>::Sized_relobj_file(
     deferred_layout_relocs_(),
     output_views_(NULL)
 {
-  this->e_type_ = ehdr.get_e_type();
 }
 
 template<int size, bool big_endian>
@@ -3387,8 +3387,8 @@ make_elf_sized_object(const std::string& name, Input_file* input_file,
 {
   Target* target = select_target(input_file, offset,
                                 ehdr.get_e_machine(), size, big_endian,
-                                ehdr.get_e_ident()[elfcpp::EI_OSABI],
-                                ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
+                                ehdr.get_ei_osabi(),
+                                ehdr.get_ei_abiversion());
   if (target == NULL)
     gold_fatal(_("%s: unsupported ELF machine number %d"),
               name.c_str(), ehdr.get_e_machine());
index 4afee993e8595fe36a1af2d0cdaded6ae075118d..1ab98ced4645e23ef8a2aba176d1ef7f40a2f9f3 100644 (file)
@@ -386,13 +386,11 @@ build_compressed_section_map(const unsigned char* pshdrs, unsigned int shnum,
 
 // Osabi represents the EI_OSABI field from the ELF header.
 
-template <int size, bool big_endian>
 class Osabi
 {
  public:
-  Osabi(const elfcpp::Ehdr<size, big_endian>& ehdr)
-    : ei_osabi_(static_cast<elfcpp::ELFOSABI>(
-                   ehdr.get_e_ident()[elfcpp::EI_OSABI]))
+  Osabi(unsigned char ei_osabi)
+    : ei_osabi_(static_cast<elfcpp::ELFOSABI>(ei_osabi))
   { }
 
   bool
@@ -2249,7 +2247,7 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
   { return this->e_type_; }
 
   // Return the EI_OSABI.
-  const Osabi<size, big_endian>&
+  const Osabi&
   osabi() const
   { return this->osabi_; }
 
@@ -2894,7 +2892,7 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
   // General access to the ELF file.
   elfcpp::Elf_file<size, big_endian, Object> elf_file_;
   // The EI_OSABI.
-  const Osabi<size, big_endian> osabi_;
+  const Osabi osabi_;
   // Type of ELF file (ET_REL or ET_EXEC).  ET_EXEC files are allowed
   // as input files only for the --just-symbols option.
   int e_type_;