Make Elf_file::section_name() a const function, so that it can be used in
authorCary Coutant <ccoutant@google.com>
Wed, 2 Jul 2014 23:12:51 +0000 (16:12 -0700)
committerCary Coutant <ccoutant@google.com>
Tue, 2 Sep 2014 22:44:58 +0000 (15:44 -0700)
places where we have only a const Elf_file*.

elfcpp/
* elfcpp_file.h (Elf_file::shnum): New const function.
(Elf_file::shstrndx): New const function.
(Elf_file::large_shndx_offset): New const function.
(Elf_file::section_name): Add const attribute.
(Elf_file::section_header_offset): Likewise.

gold/
* dwp.cc (Sized_relobj_dwo::do_section_name): Add const attribute.
* dynobj.h (Sized_dynobj::do_section_name): Likewise.
* incremental.cc (Sized_relobj_incr::do_section_name): Likewise.
(Sized_incr_dynobj::do_section_name): Likewise.
* incremental.h (Sized_relobj_incr::do_section_name): Likewise.
(Sized_incr_dynobj::do_section_name): Likewise.
* object.h (Object::section_name): Likewise.
(Object::do_section_name): Likewise.
(Sized_relobj_file::do_section_name): Likewise.
* plugin.cc (Sized_pluginobj::do_section_name): Likewise.
* plugin.h (Sized_pluginobj::do_section_name): Likewise.

elfcpp/ChangeLog
elfcpp/elfcpp_file.h
gold/ChangeLog
gold/dwp.cc
gold/dynobj.h
gold/incremental.cc
gold/incremental.h
gold/object.h
gold/plugin.cc
gold/plugin.h

index eafa25238bb96b1ecfe10aca2b6c903a283868c3..b554287d672a034b5be2ecf3dbb74c415e741d9e 100644 (file)
@@ -1,3 +1,11 @@
+2014-09-02  Cary Coutant  <ccoutant@google.com>
+
+       * elfcpp_file.h (Elf_file::shnum): New const function.
+       (Elf_file::shstrndx): New const function.
+       (Elf_file::large_shndx_offset): New const function.
+       (Elf_file::section_name): Add const attribute.
+       (Elf_file::section_header_offset): Likewise.
+
 2014-08-08  Han Shen  <shenhan@google.com>
 
        * aarch64.h (withdrawn): Replaced with R_AARCH64_withdrawn.
index bcb0275413c60b25bff4311e8b6c0b2cba37e837..a8daf91ff0c2efd3f124b3217db6c7c1f109770c 100644 (file)
@@ -144,6 +144,15 @@ class Elf_file
     return this->shnum_;
   }
 
+  unsigned int
+  shnum() const
+  {
+    if (this->shnum_ == 0 && this->shoff_ != 0)
+      this->file_->error(_("ELF file has not been initialized yet"
+                          " (internal error)"));
+    return this->shnum_;
+  }
+
   // Return the section index of the section name string table.
   unsigned int
   shstrndx()
@@ -152,6 +161,18 @@ class Elf_file
     return this->shstrndx_;
   }
 
+  unsigned int
+  shstrndx() const
+  {
+    if (this->shstrndx_ == SHN_XINDEX && this->shoff_ != 0)
+      {
+       this->file_->error(_("ELF file has not been initialized yet"
+                            " (internal error)"));
+       return 0;
+      }
+    return this->shstrndx_;
+  }
+
   // Return the value to subtract from section indexes >=
   // SHN_LORESERVE.  See the comment in initialize_shnum.
   int
@@ -161,6 +182,15 @@ class Elf_file
     return this->large_shndx_offset_;
   }
 
+  int
+  large_shndx_offset() const
+  {
+    if (this->shstrndx_ == SHN_XINDEX && this->shoff_ != 0)
+      this->file_->error(_("ELF file has not been initialized yet"
+                          " (internal error)"));
+    return this->large_shndx_offset_;
+  }
+
   // Return the location of the header of section SHNDX.
   typename File::Location
   section_header(unsigned int shndx)
@@ -171,7 +201,7 @@ class Elf_file
 
   // Return the name of section SHNDX.
   std::string
-  section_name(unsigned int shndx);
+  section_name(unsigned int shndx) const;
 
   // Return the location of the contents of section SHNDX.
   typename File::Location
@@ -216,7 +246,7 @@ class Elf_file
 
   // Return the file offset of the header of section SHNDX.
   off_t
-  section_header_offset(unsigned int shndx);
+  section_header_offset(unsigned int shndx) const;
 
   // The file we are reading.
   File* file_;
@@ -465,7 +495,7 @@ Elf_file<size, big_endian, File>::find_section_by_type(unsigned int type)
 
 template<int size, bool big_endian, typename File>
 off_t
-Elf_file<size, big_endian, File>::section_header_offset(unsigned int shndx)
+Elf_file<size, big_endian, File>::section_header_offset(unsigned int shndx) const
 {
   if (shndx >= this->shnum())
     this->file_->error(_("section_header_offset: bad shndx %u >= %u"),
@@ -477,7 +507,7 @@ Elf_file<size, big_endian, File>::section_header_offset(unsigned int shndx)
 
 template<int size, bool big_endian, typename File>
 std::string
-Elf_file<size, big_endian, File>::section_name(unsigned int shndx)
+Elf_file<size, big_endian, File>::section_name(unsigned int shndx) const
 {
   File* const file = this->file_;
 
index 0fa15612b9a9f7c557f12aa239f6630f55ee571c..2c09a05efcf195a87216fd808770965884dc0ea7 100644 (file)
@@ -1,3 +1,17 @@
+2014-09-02  Cary Coutant  <ccoutant@google.com>
+
+       * dwp.cc (Sized_relobj_dwo::do_section_name): Add const attribute.
+       * dynobj.h (Sized_dynobj::do_section_name): Likewise.
+       * incremental.cc (Sized_relobj_incr::do_section_name): Likewise.
+       (Sized_incr_dynobj::do_section_name): Likewise.
+       * incremental.h (Sized_relobj_incr::do_section_name): Likewise.
+       (Sized_incr_dynobj::do_section_name): Likewise.
+       * object.h (Object::section_name): Likewise.
+       (Object::do_section_name): Likewise.
+       (Sized_relobj_file::do_section_name): Likewise.
+       * plugin.cc (Sized_pluginobj::do_section_name): Likewise.
+       * plugin.h (Sized_pluginobj::do_section_name): Likewise.
+
 2014-09-02  Cary Coutant  <ccoutant@google.com>
 
        PR gold/17005
index 359d4b745aba2970ae884f260f9156379f4e3e63..5401e0c6ee3e04a1c165a55abb367e75dcaa3017 100644 (file)
@@ -272,7 +272,7 @@ class Sized_relobj_dwo : public Sized_relobj<size, big_endian>
 
   // Get the name of a section.
   std::string
-  do_section_name(unsigned int shndx)
+  do_section_name(unsigned int shndx) const
   { return this->elf_file_.section_name(shndx); }
 
   // Get the size of a section.
index 03b8053400ae7ffac424196c344473a6d03ac5ce..c20ed2031243ec989c71b47629440237d5ffb2d8 100644 (file)
@@ -203,7 +203,7 @@ class Sized_dynobj : public Dynobj
 
   // Get the name of a section.
   std::string
-  do_section_name(unsigned int shndx)
+  do_section_name(unsigned int shndx) const
   { return this->elf_file_.section_name(shndx); }
 
   // Return a view of the contents of a section.  Set *PLEN to the
index 2345cf84e4ee28944dbc9d749ab1971b57276ac8..bbc055c559ae4b98e09f3abeee36fc0c6eae58cf 100644 (file)
@@ -2270,10 +2270,10 @@ Sized_relobj_incr<size, big_endian>::do_section_size(unsigned int)
 
 template<int size, bool big_endian>
 std::string
-Sized_relobj_incr<size, big_endian>::do_section_name(unsigned int shndx)
+Sized_relobj_incr<size, big_endian>::do_section_name(unsigned int shndx) const
 {
-  Output_sections& out_sections(this->output_sections());
-  Output_section* os = out_sections[shndx];
+  const Output_sections& out_sections(this->output_sections());
+  const Output_section* os = out_sections[shndx];
   if (os == NULL)
     return NULL;
   return os->name();
@@ -2858,7 +2858,7 @@ Sized_incr_dynobj<size, big_endian>::do_section_size(unsigned int)
 
 template<int size, bool big_endian>
 std::string
-Sized_incr_dynobj<size, big_endian>::do_section_name(unsigned int)
+Sized_incr_dynobj<size, big_endian>::do_section_name(unsigned int) const
 {
   gold_unreachable();
 }
index f84511dd012f523fe4894ef7056a6ce074c23fc5..5440c863f9f3fe903afd3c1825352c7393b7ba53 100644 (file)
@@ -1901,7 +1901,7 @@ class Sized_relobj_incr : public Sized_relobj<size, big_endian>
 
   // Get the name of a section.
   std::string
-  do_section_name(unsigned int shndx);
+  do_section_name(unsigned int shndx) const;
 
   // Return a view of the contents of a section.
   const unsigned char*
@@ -2112,7 +2112,7 @@ class Sized_incr_dynobj : public Dynobj
 
   // Get the name of a section.
   std::string
-  do_section_name(unsigned int shndx);
+  do_section_name(unsigned int shndx) const;
 
   // Return a view of the contents of a section.
   const unsigned char*
index 92cdbdd8d3ad96428da8e5e97b2965a12e8eaccc..754b1d26b89dd442e0e9a9d0e7f7feb9e82a7eaf 100644 (file)
@@ -507,7 +507,7 @@ class Object
 
   // Return the name of a section given a section index.
   std::string
-  section_name(unsigned int shndx)
+  section_name(unsigned int shndx) const
   { return this->do_section_name(shndx); }
 
   // Return the section flags given a section index.
@@ -822,7 +822,7 @@ class Object
 
   // Get the name of a section--implemented by child class.
   virtual std::string
-  do_section_name(unsigned int shndx) = 0;
+  do_section_name(unsigned int shndx) const = 0;
 
   // Get section flags--implemented by child class.
   virtual uint64_t
@@ -2315,7 +2315,7 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
 
   // Get the name of a section.
   std::string
-  do_section_name(unsigned int shndx)
+  do_section_name(unsigned int shndx) const
   { return this->elf_file_.section_name(shndx); }
 
   // Return the location of the contents of a section.
index 62807b81d250735449e551b3bd31ee5b49392dcb..65197322dd226da544ae3e174a6551e88cd7c627 100644 (file)
@@ -1209,7 +1209,7 @@ Sized_pluginobj<size, big_endian>::do_section_size(unsigned int)
 
 template<int size, bool big_endian>
 std::string
-Sized_pluginobj<size, big_endian>::do_section_name(unsigned int)
+Sized_pluginobj<size, big_endian>::do_section_name(unsigned int) const
 {
   gold_unreachable();
   return std::string();
index 320b02d72121ea8ae63feeb0196eeb45a555e4f3..9ef2812909284cc90b8894d8645647f71d524be0 100644 (file)
@@ -490,7 +490,7 @@ class Sized_pluginobj : public Pluginobj
 
   // Get the name of a section.
   std::string
-  do_section_name(unsigned int shndx);
+  do_section_name(unsigned int shndx) const;
 
   // Return a view of the contents of a section.
   const unsigned char*