Add section_size_type and section_offset_type, use them to replace a
authorIan Lance Taylor <iant@google.com>
Tue, 18 Dec 2007 00:48:04 +0000 (00:48 +0000)
committerIan Lance Taylor <iant@google.com>
Tue, 18 Dec 2007 00:48:04 +0000 (00:48 +0000)
lot of instances of off_t.

22 files changed:
gold/archive.cc
gold/archive.h
gold/dwarf_reader.cc
gold/dwarf_reader.h
gold/dynobj.cc
gold/dynobj.h
gold/ehframe.cc
gold/ehframe.h
gold/fileread.cc
gold/fileread.h
gold/gold.h
gold/merge.cc
gold/merge.h
gold/object.cc
gold/object.h
gold/output.cc
gold/output.h
gold/reloc.h
gold/stringpool.cc
gold/stringpool.h
gold/symtab.cc
gold/symtab.h

index b80dea5..53b5cd0 100644 (file)
@@ -84,7 +84,8 @@ Archive::setup(Task* task)
 
   // The first member of the archive should be the symbol table.
   std::string armap_name;
-  off_t armap_size = this->read_header(sarmag, &armap_name);
+  section_size_type armap_size =
+    convert_to_section_size_type(this->read_header(sarmag, &armap_name));
   off_t off = sarmag;
   if (armap_name.empty())
     {
@@ -115,7 +116,7 @@ Archive::setup(Task* task)
 // Read the archive symbol map.
 
 void
-Archive::read_armap(off_t start, off_t size)
+Archive::read_armap(off_t start, section_size_type size)
 {
   // Read in the entire armap.
   const unsigned char* p = this->get_view(start, size, false);
@@ -127,12 +128,13 @@ Archive::read_armap(off_t start, off_t size)
 
   // Note that the addition is in units of sizeof(elfcpp::Elf_Word).
   const char* pnames = reinterpret_cast<const char*>(pword + nsyms);
-  off_t names_size = reinterpret_cast<const char*>(p) + size - pnames;
+  section_size_type names_size =
+    reinterpret_cast<const char*>(p) + size - pnames;
   this->armap_names_.assign(pnames, names_size);
 
   this->armap_.resize(nsyms);
 
-  off_t name_offset = 0;
+  section_offset_type name_offset = 0;
   for (unsigned int i = 0; i < nsyms; ++i)
     {
       this->armap_[i].name_offset = name_offset;
@@ -141,7 +143,7 @@ Archive::read_armap(off_t start, off_t size)
       ++pword;
     }
 
-  if (reinterpret_cast<const unsigned char*>(pnames) - p > size)
+  if (static_cast<section_size_type>(name_offset) > names_size)
     gold_error(_("%s: bad archive symbol table names"),
               this->name().c_str());
 
index b135cd6..fb83ea6 100644 (file)
@@ -110,12 +110,12 @@ class Archive
 
   // Get a view into the underlying file.
   const unsigned char*
-  get_view(off_t start, off_t size, bool cache)
+  get_view(off_t start, section_size_type size, bool cache)
   { return this->input_file_->file().get_view(start, size, cache); }
 
   // Read the archive symbol map.
   void
-  read_armap(off_t start, off_t size);
+  read_armap(off_t start, section_size_type size);
 
   // Read an archive member header at OFF.  Return the size of the
   // member, and set *PNAME to the name.
index 1190066..bf03ca3 100644 (file)
@@ -127,9 +127,9 @@ Sized_dwarf_line_info<size, big_endian>::Sized_dwarf_line_info(Object* object,
   for (debug_shndx = 0; debug_shndx < object->shnum(); ++debug_shndx)
     if (object->section_name(debug_shndx) == ".debug_line")
       {
-        off_t buffer_size;
-        this->buffer_ = object->section_contents(
-            debug_shndx, &buffer_size, false);
+        section_size_type buffer_size;
+        this->buffer_ = object->section_contents(debug_shndx, &buffer_size,
+                                                false);
         this->buffer_end_ = this->buffer_ + buffer_size;
         break;
       }
index f522104..4d28518 100644 (file)
@@ -172,7 +172,7 @@ class Sized_dwarf_line_info : public Dwarf_line_info
 
   // This is used to figure out what section to apply a relocation to.
   const unsigned char* symtab_buffer_;
-  off_t symtab_buffer_size_;
+  section_size_type symtab_buffer_size_;
 
   // Holds the directories and files as we see them.  We have an array
   // of directory-lists, one for each .o file we're reading (usually
index f479352..7ebd758 100644 (file)
@@ -162,7 +162,7 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
     elfcpp::SHT type,
     unsigned int link,
     File_view** view,
-    off_t* view_size,
+    section_size_type* view_size,
     unsigned int* view_info)
 {
   if (shndx == -1U)
@@ -183,7 +183,7 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
 
   *view = this->get_lasting_view(shdr.get_sh_offset(), shdr.get_sh_size(),
                                 false);
-  *view_size = shdr.get_sh_size();
+  *view_size = convert_to_section_size_type(shdr.get_sh_size());
   *view_info = shdr.get_sh_info();
 }
 
@@ -313,7 +313,8 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
 
       sd->symbols = this->get_lasting_view(dynsymshdr.get_sh_offset(),
                                           dynsymshdr.get_sh_size(), false);
-      sd->symbols_size = dynsymshdr.get_sh_size();
+      sd->symbols_size =
+       convert_to_section_size_type(dynsymshdr.get_sh_size());
 
       // Get the symbol names.
       strtab_shndx = dynsymshdr.get_sh_link();
@@ -335,7 +336,8 @@ Sized_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
       sd->symbol_names = this->get_lasting_view(strtabshdr.get_sh_offset(),
                                                strtabshdr.get_sh_size(),
                                                true);
-      sd->symbol_names_size = strtabshdr.get_sh_size();
+      sd->symbol_names_size =
+       convert_to_section_size_type(strtabshdr.get_sh_size());
 
       // Get the version information.
 
@@ -444,10 +446,10 @@ Sized_dynobj<size, big_endian>::make_verdef_map(
     return;
 
   const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
-  off_t names_size = sd->symbol_names_size;
+  section_size_type names_size = sd->symbol_names_size;
 
   const unsigned char* pverdef = sd->verdef->data();
-  off_t verdef_size = sd->verdef_size;
+  section_size_type verdef_size = sd->verdef_size;
   const unsigned int count = sd->verdef_info;
 
   const unsigned char* p = pverdef;
@@ -519,10 +521,10 @@ Sized_dynobj<size, big_endian>::make_verneed_map(
     return;
 
   const char* names = reinterpret_cast<const char*>(sd->symbol_names->data());
-  off_t names_size = sd->symbol_names_size;
+  section_size_type names_size = sd->symbol_names_size;
 
   const unsigned char* pverneed = sd->verneed->data();
-  const off_t verneed_size = sd->verneed_size;
+  const section_size_type verneed_size = sd->verneed_size;
   const unsigned int count = sd->verneed_info;
 
   const unsigned char* p = pverneed;
@@ -621,7 +623,7 @@ Sized_dynobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
   const int sym_size = This::sym_size;
   const size_t symcount = sd->symbols_size / sym_size;
   gold_assert(sd->external_symbols_offset == 0);
-  if (static_cast<off_t>(symcount * sym_size) != sd->symbols_size)
+  if (symcount * sym_size != sd->symbols_size)
     {
       this->error(_("size of dynamic symbols is not multiple of symbol size"));
       return;
index 1fe37a4..cc6ec54 100644 (file)
@@ -229,7 +229,7 @@ class Sized_dynobj : public Dynobj
   void
   read_dynsym_section(const unsigned char* pshdrs, unsigned int shndx,
                      elfcpp::SHT type, unsigned int link,
-                     File_view** view, off_t* view_size,
+                     File_view** view, section_size_type* view_size,
                      unsigned int* view_info);
 
   // Read the dynamic tags.
index 328048b..b77148b 100644 (file)
@@ -237,7 +237,7 @@ typename elfcpp::Elf_types<size>::Elf_Addr
 Eh_frame_hdr::get_fde_pc(
     typename elfcpp::Elf_types<size>::Elf_Addr eh_frame_address,
     const unsigned char* eh_frame_contents,
-    off_t fde_offset,
+    section_offset_type fde_offset,
     unsigned char fde_encoding)
 {
   // The FDE starts with a 4 byte length and a 4 byte offset to the
@@ -339,9 +339,10 @@ Eh_frame_hdr::get_fde_addresses(Output_file* of,
 // CIE.  Record the FDE pc for EH_FRAME_HDR.  Return the new offset.
 
 template<int size, bool big_endian>
-off_t
-Fde::write(unsigned char* oview, off_t offset, off_t cie_offset,
-          unsigned char fde_encoding, Eh_frame_hdr* eh_frame_hdr)
+section_offset_type
+Fde::write(unsigned char* oview, section_offset_type offset,
+          section_offset_type cie_offset, unsigned char fde_encoding,
+          Eh_frame_hdr* eh_frame_hdr)
 {
   size_t length = this->contents_.length();
 
@@ -383,8 +384,9 @@ Cie::~Cie()
 
 // Set the output offset of a CIE.  Return the new output offset.
 
-off_t
-Cie::set_output_offset(off_t output_offset, unsigned int addralign,
+section_offset_type
+Cie::set_output_offset(section_offset_type output_offset,
+                      unsigned int addralign,
                       Merge_map* merge_map)
 {
   size_t length = this->contents_.length();
@@ -413,10 +415,11 @@ Cie::set_output_offset(off_t output_offset, unsigned int addralign,
 // recording.  Return the new offset.
 
 template<int size, bool big_endian>
-off_t
-Cie::write(unsigned char* oview, off_t offset, Eh_frame_hdr* eh_frame_hdr)
+section_offset_type
+Cie::write(unsigned char* oview, section_offset_type offset,
+          Eh_frame_hdr* eh_frame_hdr)
 {
-  off_t cie_offset = offset;
+  section_offset_type cie_offset = offset;
 
   size_t length = this->contents_.length();
 
@@ -512,15 +515,15 @@ bool
 Eh_frame::add_ehframe_input_section(
     Sized_relobj<size, big_endian>* object,
     const unsigned char* symbols,
-    off_t symbols_size,
+    section_size_type symbols_size,
     const unsigned char* symbol_names,
-    off_t symbol_names_size,
+    section_size_type symbol_names_size,
     unsigned int shndx,
     unsigned int reloc_shndx,
     unsigned int reloc_type)
 {
   // Get the section contents.
-  off_t contents_len;
+  section_size_type contents_len;
   const unsigned char* pcontents = object->section_contents(shndx,
                                                            &contents_len,
                                                            false);
@@ -576,14 +579,14 @@ bool
 Eh_frame::do_add_ehframe_input_section(
     Sized_relobj<size, big_endian>* object,
     const unsigned char* symbols,
-    off_t symbols_size,
+    section_size_type symbols_size,
     const unsigned char* symbol_names,
-    off_t symbol_names_size,
+    section_size_type symbol_names_size,
     unsigned int shndx,
     unsigned int reloc_shndx,
     unsigned int reloc_type,
     const unsigned char* pcontents,
-    off_t contents_len,
+    section_size_type contents_len,
     New_cies* new_cies)
 {
   typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
@@ -664,9 +667,9 @@ bool
 Eh_frame::read_cie(Sized_relobj<size, big_endian>* object,
                   unsigned int shndx,
                   const unsigned char* symbols,
-                  off_t symbols_size,
+                  section_size_type symbols_size,
                   const unsigned char* symbol_names,
-                  off_t symbol_names_size,
+                  section_size_type symbol_names_size,
                   const unsigned char* pcontents,
                   const unsigned char* pcie,
                   const unsigned char *pcieend,
@@ -918,7 +921,7 @@ bool
 Eh_frame::read_fde(Sized_relobj<size, big_endian>* object,
                   unsigned int shndx,
                   const unsigned char* symbols,
-                  off_t symbols_size,
+                  section_size_type symbols_size,
                   const unsigned char* pcontents,
                   unsigned int offset,
                   const unsigned char* pfde,
@@ -1001,7 +1004,7 @@ void
 Eh_frame::set_final_data_size()
 {
   off_t start_file_offset = this->offset();
-  off_t output_offset = 0;
+  section_offset_type output_offset = 0;
 
   for (Unmergeable_cie_offsets::iterator p =
         this->unmergeable_cie_offsets_.begin();
@@ -1032,7 +1035,8 @@ Eh_frame::set_final_data_size()
 
 bool
 Eh_frame::do_output_offset(const Relobj* object, unsigned int shndx,
-                          off_t offset, off_t* poutput) const
+                          section_offset_type offset,
+                          section_offset_type* poutput) const
 {
   return this->merge_map_.get_output_offset(object, shndx, offset, poutput);
 }
@@ -1096,7 +1100,7 @@ template<int size, bool big_endian>
 void
 Eh_frame::do_sized_write(unsigned char* oview)
 {
-  off_t o = 0;
+  section_offset_type o = 0;
   for (Unmergeable_cie_offsets::iterator p =
         this->unmergeable_cie_offsets_.begin();
        p != this->unmergeable_cie_offsets_.end();
@@ -1114,9 +1118,9 @@ bool
 Eh_frame::add_ehframe_input_section<32, false>(
     Sized_relobj<32, false>* object,
     const unsigned char* symbols,
-    off_t symbols_size,
+    section_size_type symbols_size,
     const unsigned char* symbol_names,
-    off_t symbol_names_size,
+    section_size_type symbol_names_size,
     unsigned int shndx,
     unsigned int reloc_shndx,
     unsigned int reloc_type);
@@ -1128,9 +1132,9 @@ bool
 Eh_frame::add_ehframe_input_section<32, true>(
     Sized_relobj<32, true>* object,
     const unsigned char* symbols,
-    off_t symbols_size,
+    section_size_type symbols_size,
     const unsigned char* symbol_names,
-    off_t symbol_names_size,
+    section_size_type symbol_names_size,
     unsigned int shndx,
     unsigned int reloc_shndx,
     unsigned int reloc_type);
@@ -1142,9 +1146,9 @@ bool
 Eh_frame::add_ehframe_input_section<64, false>(
     Sized_relobj<64, false>* object,
     const unsigned char* symbols,
-    off_t symbols_size,
+    section_size_type symbols_size,
     const unsigned char* symbol_names,
-    off_t symbol_names_size,
+    section_size_type symbol_names_size,
     unsigned int shndx,
     unsigned int reloc_shndx,
     unsigned int reloc_type);
@@ -1156,9 +1160,9 @@ bool
 Eh_frame::add_ehframe_input_section<64, true>(
     Sized_relobj<64, true>* object,
     const unsigned char* symbols,
-    off_t symbols_size,
+    section_size_type symbols_size,
     const unsigned char* symbol_names,
-    off_t symbol_names_size,
+    section_size_type symbol_names_size,
     unsigned int shndx,
     unsigned int reloc_shndx,
     unsigned int reloc_type);
index 5a733e7..ce4f6df 100644 (file)
@@ -57,7 +57,7 @@ class Eh_frame_hdr : public Output_section_data
 
   // Record an FDE.
   void
-  record_fde(off_t fde_offset, unsigned char fde_encoding)
+  record_fde(section_offset_type fde_offset, unsigned char fde_encoding)
   {
     if (!this->any_unrecognized_eh_frame_sections_)
       this->fde_offsets_.push_back(std::make_pair(fde_offset, fde_encoding));
@@ -79,7 +79,7 @@ class Eh_frame_hdr : public Output_section_data
 
   // The data we record for one FDE: the offset of the FDE within the
   // .eh_frame section, and the FDE encoding.
-  typedef std::pair<off_t, unsigned char> Fde_offset;
+  typedef std::pair<section_offset_type, unsigned char> Fde_offset;
 
   // The list of information we record for an FDE.
   typedef std::vector<Fde_offset> Fde_offsets;
@@ -133,7 +133,7 @@ class Eh_frame_hdr : public Output_section_data
   typename elfcpp::Elf_types<size>::Elf_Addr
   get_fde_pc(typename elfcpp::Elf_types<size>::Elf_Addr eh_frame_address,
             const unsigned char* eh_frame_contents,
-            off_t fde_offset, unsigned char fde_encoding);
+            section_offset_type fde_offset, unsigned char fde_encoding);
 
   // Convert Fde_offsets to Fde_addresses.
   template<int size, bool big_endian>
@@ -158,7 +158,7 @@ class Eh_frame_hdr : public Output_section_data
 class Fde
 {
  public:
-  Fde(Relobj* object, unsigned int shndx, off_t input_offset,
+  Fde(Relobj* object, unsigned int shndx, section_offset_type input_offset,
       const unsigned char* contents, size_t length)
     : object_(object), shndx_(shndx), input_offset_(input_offset),
       contents_(reinterpret_cast<const char*>(contents), length)
@@ -172,7 +172,7 @@ class Fde
 
   // Add a mapping for this FDE to MERGE_MAP.
   void
-  add_mapping(off_t output_offset, Merge_map* merge_map) const
+  add_mapping(section_offset_type output_offset, Merge_map* merge_map) const
   {
     merge_map->add_mapping(this->object_, this->shndx_,
                           this->input_offset_, this->length(),
@@ -183,9 +183,10 @@ class Fde
   // encoding, from the CIE.  Record the FDE in EH_FRAME_HDR.  Return
   // the new offset.
   template<int size, bool big_endian>
-  off_t
-  write(unsigned char* oview, off_t offset, off_t cie_offset,
-       unsigned char fde_encoding, Eh_frame_hdr* eh_frame_hdr);
+  section_offset_type
+  write(unsigned char* oview, section_offset_type offset,
+       section_offset_type cie_offset, unsigned char fde_encoding,
+       Eh_frame_hdr* eh_frame_hdr);
 
  private:
   // The object in which this FDE was seen.
@@ -193,7 +194,7 @@ class Fde
   // Input section index for this FDE.
   unsigned int shndx_;
   // Offset within the input section for this FDE.
-  off_t input_offset_;
+  section_offset_type input_offset_;
   // FDE data.
   std::string contents_;
 };
@@ -203,7 +204,7 @@ class Fde
 class Cie
 {
  public:
-  Cie(Relobj* object, unsigned int shndx, off_t input_offset,
+  Cie(Relobj* object, unsigned int shndx, section_offset_type input_offset,
       unsigned char fde_encoding, const char* personality_name,
       const unsigned char* contents, size_t length)
     : object_(object),
@@ -243,14 +244,16 @@ class Cie
   // followed by all its FDEs.  ADDRALIGN is the required address
   // alignment, typically 4 or 8.  This updates MERGE_MAP with the
   // mapping.  It returns the new output offset.
-  off_t
-  set_output_offset(off_t output_offset, unsigned int addralign, Merge_map*);
+  section_offset_type
+  set_output_offset(section_offset_type output_offset, unsigned int addralign,
+                   Merge_map*);
 
   // Write the CIE to OVIEW starting at OFFSET.  EH_FRAME_HDR is the
   // exception frame header for FDE recording.  Return the new offset.
   template<int size, bool big_endian>
-  off_t
-  write(unsigned char* oview, off_t offset, Eh_frame_hdr* eh_frame_hdr);
+  section_offset_type
+  write(unsigned char* oview, section_offset_type offset,
+       Eh_frame_hdr* eh_frame_hdr);
 
   friend bool operator<(const Cie&, const Cie&);
   friend bool operator==(const Cie&, const Cie&);
@@ -264,7 +267,7 @@ class Cie
   // Input section index for this CIE.
   unsigned int shndx_;
   // Offset within the input section for this CIE.
-  off_t input_offset_;
+  section_offset_type input_offset_;
   // The encoding of the FDE.  This is a DW_EH_PE code.
   unsigned char fde_encoding_;
   // The name of the personality routine.  This will be the name of a
@@ -303,9 +306,9 @@ class Eh_frame : public Output_section_data
   bool
   add_ehframe_input_section(Sized_relobj<size, big_endian>* object,
                            const unsigned char* symbols,
-                           off_t symbols_size,
+                           section_size_type symbols_size,
                            const unsigned char* symbol_names,
-                           off_t symbol_names_size,
+                           section_size_type symbol_names_size,
                            unsigned int shndx, unsigned int reloc_shndx,
                            unsigned int reloc_type);
 
@@ -319,8 +322,9 @@ class Eh_frame : public Output_section_data
 
   // Return the output address for an input address.
   bool
-  do_output_offset(const Relobj*, unsigned int shndx, off_t offset,
-                  off_t* poutput) const;
+  do_output_offset(const Relobj*, unsigned int shndx,
+                  section_offset_type offset,
+                  section_offset_type* poutput) const;
 
   // Write the data to the file.
   void
@@ -358,14 +362,14 @@ class Eh_frame : public Output_section_data
   bool
   do_add_ehframe_input_section(Sized_relobj<size, big_endian>* object,
                               const unsigned char* symbols,
-                              off_t symbols_size,
+                              section_size_type symbols_size,
                               const unsigned char* symbol_names,
-                              off_t symbol_names_size,
+                              section_size_type symbol_names_size,
                               unsigned int shndx,
                               unsigned int reloc_shndx,
                               unsigned int reloc_type,
                               const unsigned char* pcontents,
-                              off_t contents_len,
+                              section_size_type contents_len,
                               New_cies*);
 
   // Read a CIE.
@@ -374,9 +378,9 @@ class Eh_frame : public Output_section_data
   read_cie(Sized_relobj<size, big_endian>* object,
           unsigned int shndx,
           const unsigned char* symbols,
-          off_t symbols_size,
+          section_size_type symbols_size,
           const unsigned char* symbol_names,
-          off_t symbol_names_size,
+          section_size_type symbol_names_size,
           const unsigned char* pcontents,
           const unsigned char* pcie,
           const unsigned char *pcieend,
@@ -390,7 +394,7 @@ class Eh_frame : public Output_section_data
   read_fde(Sized_relobj<size, big_endian>* object,
           unsigned int shndx,
           const unsigned char* symbols,
-          off_t symbols_size,
+          section_size_type symbols_size,
           const unsigned char* pcontents,
           unsigned int offset,
           const unsigned char* pfde,
index 774179d..338a943 100644 (file)
@@ -191,7 +191,7 @@ File_read::is_locked() const
 // SIZE bytes.  Return a pointer to the View if found, NULL if not.
 
 inline File_read::View*
-File_read::find_view(off_t start, off_t size) const
+File_read::find_view(off_t start, section_size_type size) const
 {
   off_t page = File_read::page_offset(start);
   Views::const_iterator p = this->views_.find(page);
@@ -257,7 +257,7 @@ File_read::read(off_t start, off_t size, void* p) const
 // Find an existing view or make a new one.
 
 File_read::View*
-File_read::find_or_make_view(off_t start, off_t size, bool cache)
+File_read::find_or_make_view(off_t start, section_size_type size, bool cache)
 {
   gold_assert(!this->token_.is_writable());
   this->released_ = false;
@@ -326,14 +326,14 @@ File_read::find_or_make_view(off_t start, off_t size, bool cache)
 // Get a view into the file.
 
 const unsigned char*
-File_read::get_view(off_t start, off_t size, bool cache)
+File_read::get_view(off_t start, section_size_type size, bool cache)
 {
   File_read::View* pv = this->find_or_make_view(start, size, cache);
   return pv->data() + (start - pv->start());
 }
 
 File_view*
-File_read::get_lasting_view(off_t start, off_t size, bool cache)
+File_read::get_lasting_view(off_t start, section_size_type size, bool cache)
 {
   File_read::View* pv = this->find_or_make_view(start, size, cache);
   pv->lock();
index fd9b1ba..088a76b 100644 (file)
@@ -110,7 +110,7 @@ class File_read
   // to get_view, read, or get_lasting_view which retrieve the same
   // data.
   const unsigned char*
-  get_view(off_t start, off_t size, bool cache);
+  get_view(off_t start, section_size_type size, bool cache);
 
   // Read data from the file into the buffer P starting at file offset
   // START for SIZE bytes.
@@ -124,7 +124,7 @@ class File_read
   // error if we can not read enough data from the file.  The CACHE
   // parameter is as in get_view.
   File_view*
-  get_lasting_view(off_t start, off_t size, bool cache);
+  get_lasting_view(off_t start, section_size_type size, bool cache);
 
   // Dump statistical information to stderr.
   static void
@@ -151,8 +151,8 @@ class File_read
   class View
   {
    public:
-    View(off_t start, off_t size, const unsigned char* data, bool cache,
-         bool mapped)
+    View(off_t start, section_size_type size, const unsigned char* data,
+        bool cache, bool mapped)
       : start_(start), size_(size), data_(data), lock_count_(0),
        cache_(cache), mapped_(mapped)
     { }
@@ -163,7 +163,7 @@ class File_read
     start() const
     { return this->start_; }
 
-    off_t
+    section_size_type
     size() const
     { return this->size_; }
 
@@ -193,7 +193,7 @@ class File_read
     View& operator=(const View&);
 
     off_t start_;
-    off_t size_;
+    section_size_type size_;
     const unsigned char* data_;
     int lock_count_;
     bool cache_;
@@ -205,7 +205,7 @@ class File_read
 
   // Find a view into the file.
   View*
-  find_view(off_t start, off_t size) const;
+  find_view(off_t start, section_size_type size) const;
 
   // Read data from the file into a buffer.
   void
@@ -213,7 +213,7 @@ class File_read
 
   // Find or make a view into the file.
   View*
-  find_or_make_view(off_t start, off_t size, bool cache);
+  find_or_make_view(off_t start, section_size_type size, bool cache);
 
   // Clear the file views.
   void
index 32fcc43..8ea24d2 100644 (file)
@@ -161,10 +161,7 @@ class Select_size_endian { };
 
 #endif // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS)
 
-} // End namespace gold.
-
-namespace gold
-{
+// General declarations.
 
 class General_options;
 class Command_line;
@@ -180,6 +177,17 @@ class Output_file;
 template<int size, bool big_endian>
 struct Relocate_info;
 
+// Some basic types.  For these we use lower case initial letters.
+
+// For an offset in an input or output file, use off_t.  Note that
+// this will often be a 64-bit type even for a 32-bit build.
+
+// The size of a section if we are going to look at the contents.
+typedef size_t section_size_type;
+
+// An offset within a section when we are looking at the contents.
+typedef ptrdiff_t section_offset_type;
+
 // The name of the program as used in error messages.
 extern const char* program_name;
 
@@ -250,6 +258,22 @@ print_version(bool print_short);
 extern const char*
 get_version_string();
 
+// Convert numeric types without unnoticed loss of precision.
+template<typename To, typename From>
+inline To
+convert_types(const From from)
+{
+  To to = from;
+  gold_assert(to == from);
+  return to;
+}
+
+// A common case of convert_types<>: convert to section_size_type.
+template<typename From>
+inline section_size_type
+convert_to_section_size_type(const From from)
+{ return convert_types<section_size_type, From>(from); }
+
 // Queue up the first set of tasks.
 extern void
 queue_initial_tasks(const General_options&,
index 3eb7c3e..25aac76 100644 (file)
@@ -51,8 +51,8 @@ class Object_merge_map
   // output section.  An OUTPUT_OFFSET of -1 means that the bytes are
   // discarded.
   void
-  add_mapping(const Merge_map*, unsigned int shndx, off_t offset, off_t length,
-             off_t output_offset);
+  add_mapping(const Merge_map*, unsigned int shndx, section_offset_type offset,
+             section_size_type length, section_offset_type output_offset);
 
   // Get the output offset for an input address in MERGE_MAP.  The
   // input address is at offset OFFSET in section SHNDX.  This sets
@@ -60,8 +60,9 @@ class Object_merge_map
   // -1 if the bytes are not being copied to the output.  This returns
   // true if the mapping is known, false otherwise.
   bool
-  get_output_offset(const Merge_map*, unsigned int shndx, off_t offset,
-                   off_t *output_offset);
+  get_output_offset(const Merge_map*, unsigned int shndx,
+                   section_offset_type offset,
+                   section_offset_type *output_offset);
 
  private:
   // Map input section offsets to a length and an output section
@@ -70,11 +71,11 @@ class Object_merge_map
   struct Input_merge_entry
   {
     // The offset in the input section.
-    off_t input_offset;
+    section_offset_type input_offset;
     // The length.
-    off_t length;
+    section_size_type length;
     // The offset in the output section.
-    off_t output_offset;
+    section_offset_type output_offset;
   };
 
   // A less-than comparison routine for Input_merge_entry.
@@ -190,8 +191,9 @@ Object_merge_map::get_or_make_input_merge_map(const Merge_map* merge_map,
 
 void
 Object_merge_map::add_mapping(const Merge_map* merge_map, unsigned int shndx,
-                             off_t input_offset, off_t length,
-                             off_t output_offset)
+                             section_offset_type input_offset,
+                             section_size_type length,
+                             section_offset_type output_offset)
 {
   Input_merge_map* map = this->get_or_make_input_merge_map(merge_map, shndx);
 
@@ -200,18 +202,23 @@ Object_merge_map::add_mapping(const Merge_map* merge_map, unsigned int shndx,
     {
       Input_merge_entry& entry(map->entries.back());
 
+      // Use section_size_type to avoid signed/unsigned warnings.
+      section_size_type input_offset_u = input_offset;
+      section_size_type output_offset_u = output_offset;
+
       // If this entry is not in order, we need to sort the vector
       // before looking anything up.
-      if (input_offset < entry.input_offset + entry.length)
+      if (input_offset_u < entry.input_offset + entry.length)
        {
-         gold_assert(input_offset < entry.input_offset
-                     && input_offset + length <= entry.input_offset);
+         gold_assert(input_offset < entry.input_offset);
+         gold_assert(input_offset_u + length
+                     <= static_cast<section_size_type>(entry.input_offset));
          map->sorted = false;
        }
-      else if (entry.input_offset + entry.length == input_offset
+      else if (entry.input_offset + entry.length == input_offset_u
               && (output_offset == -1
                   ? entry.output_offset == -1
-                  : entry.output_offset + entry.length == output_offset))
+                  : entry.output_offset + entry.length == output_offset_u))
        {
          entry.length += length;
          return;
@@ -229,8 +236,9 @@ Object_merge_map::add_mapping(const Merge_map* merge_map, unsigned int shndx,
 
 bool
 Object_merge_map::get_output_offset(const Merge_map* merge_map,
-                                   unsigned int shndx, off_t input_offset,
-                                   off_t *output_offset)
+                                   unsigned int shndx,
+                                   section_offset_type input_offset,
+                                   section_offset_type *output_offset)
 {
   Input_merge_map* map = this->get_input_merge_map(shndx);
   if (map == NULL || map->merge_map != merge_map)
@@ -256,7 +264,8 @@ Object_merge_map::get_output_offset(const Merge_map* merge_map,
       gold_assert(p->input_offset <= input_offset);
     }
 
-  if (input_offset - p->input_offset >= p->length)
+  if (input_offset - p->input_offset
+      >= static_cast<section_offset_type>(p->length))
     return false;
 
   *output_offset = p->output_offset;
@@ -273,7 +282,8 @@ Object_merge_map::get_output_offset(const Merge_map* merge_map,
 
 void
 Merge_map::add_mapping(Relobj* object, unsigned int shndx,
-                      off_t offset, off_t length, off_t output_offset)
+                      section_offset_type offset, section_size_type length,
+                      section_offset_type output_offset)
 {
   Object_merge_map* object_merge_map = object->merge_map();
   if (object_merge_map == NULL)
@@ -292,7 +302,8 @@ Merge_map::add_mapping(Relobj* object, unsigned int shndx,
 
 bool
 Merge_map::get_output_offset(const Relobj* object, unsigned int shndx,
-                            off_t offset, off_t* output_offset) const
+                            section_offset_type offset,
+                            section_offset_type* output_offset) const
 {
   Object_merge_map* object_merge_map = object->merge_map();
   if (object_merge_map == NULL)
@@ -310,8 +321,8 @@ Merge_map::get_output_offset(const Relobj* object, unsigned int shndx,
 bool
 Output_merge_base::do_output_offset(const Relobj* object,
                                    unsigned int shndx,
-                                   off_t offset,
-                                   off_t* poutput) const
+                                   section_offset_type offset,
+                                   section_offset_type* poutput) const
 {
   return this->merge_map_.get_output_offset(object, shndx, offset, poutput);
 }
@@ -324,13 +335,14 @@ size_t
 Output_merge_data::Merge_data_hash::operator()(Merge_data_key k) const
 {
   const unsigned char* p = this->pomd_->constant(k);
-  uint64_t entsize = this->pomd_->entsize();
+  section_size_type entsize =
+    convert_to_section_size_type(this->pomd_->entsize());
 
   // Fowler/Noll/Vo (FNV) hash (type FNV-1a).
   if (sizeof(size_t) == 8)
     {
       size_t result = static_cast<size_t>(14695981039346656037ULL);
-      for (uint64_t i = 0; i < entsize; ++i)
+      for (section_size_type i = 0; i < entsize; ++i)
        {
          result &= (size_t) *p++;
          result *= 1099511628211ULL;
@@ -340,7 +352,7 @@ Output_merge_data::Merge_data_hash::operator()(Merge_data_key k) const
   else
     {
       size_t result = 2166136261UL;
-      for (uint64_t i = 0; i < entsize; ++i)
+      for (section_size_type i = 0; i < entsize; ++i)
        {
          result ^= (size_t) *p++;
          result *= 16777619UL;
@@ -365,8 +377,10 @@ Output_merge_data::Merge_data_eq::operator()(Merge_data_key k1,
 void
 Output_merge_data::add_constant(const unsigned char* p)
 {
-  uint64_t entsize = this->entsize();
-  uint64_t addsize = std::max(entsize, this->addralign());
+  section_size_type entsize = convert_to_section_size_type(this->entsize());
+  section_size_type addralign =
+    convert_to_section_size_type(this->addralign());
+  section_size_type addsize = std::max(entsize, addralign);
   if (this->len_ + addsize > this->alc_)
     {
       if (this->alc_ == 0)
@@ -392,15 +406,15 @@ Output_merge_data::add_constant(const unsigned char* p)
 bool
 Output_merge_data::do_add_input_section(Relobj* object, unsigned int shndx)
 {
-  off_t len;
+  section_size_type len;
   const unsigned char* p = object->section_contents(shndx, &len, false);
 
-  uint64_t entsize = this->entsize();
+  section_size_type entsize = convert_to_section_size_type(this->entsize());
 
   if (len % entsize != 0)
     return false;
 
-  for (off_t i = 0; i < len; i += entsize, p += entsize)
+  for (section_size_type i = 0; i < len; i += entsize, p += entsize)
     {
       // Add the constant to the section contents.  If we find that it
       // is already in the hash table, we will remove it again.
@@ -462,7 +476,7 @@ bool
 Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
                                                     unsigned int shndx)
 {
-  off_t len;
+  section_size_type len;
   const unsigned char* pdata = object->section_contents(shndx, &len, false);
 
   const Char_type* p = reinterpret_cast<const Char_type*>(pdata);
@@ -476,7 +490,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
     }
 
   // The index I is in bytes, not characters.
-  off_t i = 0;
+  section_size_type i = 0;
   while (i < len)
     {
       const Char_type* pl;
@@ -492,7 +506,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
 
       const Char_type* str = this->stringpool_.add_prefix(p, pl - p, NULL);
 
-      size_t bytelen_with_null = ((pl - p) + 1) * sizeof(Char_type);
+      section_size_type bytelen_with_null = ((pl - p) + 1) * sizeof(Char_type);
       this->merged_strings_.push_back(Merged_string(object, shndx, i, str,
                                                    bytelen_with_null));
 
@@ -507,7 +521,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
 // section, and return the final data size.
 
 template<typename Char_type>
-off_t
+section_size_type
 Output_merge_string<Char_type>::finalize_merged_data()
 {
   this->stringpool_.set_string_offsets();
index 529037c..a649321 100644 (file)
@@ -46,8 +46,9 @@ class Merge_map
   // output section.  An OUTPUT_OFFSET of -1 means that the bytes are
   // discarded.
   void
-  add_mapping(Relobj* object, unsigned int shndx, off_t offset, off_t length,
-             off_t output_offset);
+  add_mapping(Relobj* object, unsigned int shndx,
+             section_offset_type offset, section_size_type length,
+             section_offset_type output_offset);
 
   // Return the output offset for an input address.  The input address
   // is at offset OFFSET in section SHNDX in OBJECT.  This sets
@@ -55,8 +56,9 @@ class Merge_map
   // -1 if the bytes are not being copied to the output.  This returns
   // true if the mapping is known, false otherwise.
   bool
-  get_output_offset(const Relobj* object, unsigned int shndx, off_t offset,
-                   off_t *output_offset) const;
+  get_output_offset(const Relobj* object, unsigned int shndx,
+                   section_offset_type offset,
+                   section_offset_type *output_offset) const;
 };
 
 // A general class for SHF_MERGE data, to hold functions shared by
@@ -71,8 +73,9 @@ class Output_merge_base : public Output_section_data
 
   // Return the output offset for an input offset.
   bool
-  do_output_offset(const Relobj* object, unsigned int shndx, off_t offset,
-                  off_t* poutput) const;
+  do_output_offset(const Relobj* object, unsigned int shndx,
+                  section_offset_type offset,
+                  section_offset_type* poutput) const;
 
  protected:
   // Return the entry size.
@@ -83,8 +86,8 @@ class Output_merge_base : public Output_section_data
   // Add a mapping from an OFFSET in input section SHNDX in object
   // OBJECT to an OUTPUT_OFFSET in the output section.
   void
-  add_mapping(Relobj* object, unsigned int shndx, off_t offset,
-             off_t length, off_t output_offset)
+  add_mapping(Relobj* object, unsigned int shndx, section_offset_type offset,
+             section_size_type length, section_offset_type output_offset)
   {
     this->merge_map_.add_mapping(object, shndx, offset, length, output_offset);
   }
@@ -130,7 +133,7 @@ class Output_merge_data : public Output_merge_base
 
   // A key in the hash table.  This is an offset in the section
   // contents we are building.
-  typedef off_t Merge_data_key;
+  typedef section_offset_type Merge_data_key;
 
   // Compute the hash code.  To do this we need a pointer back to the
   // object holding the data.
@@ -180,7 +183,7 @@ class Output_merge_data : public Output_merge_base
   const unsigned char*
   constant(Merge_data_key k) const
   {
-    gold_assert(k >= 0 && k < this->len_);
+    gold_assert(k >= 0 && k < static_cast<section_offset_type>(this->len_));
     return this->p_ + k;
   }
 
@@ -191,9 +194,9 @@ class Output_merge_data : public Output_merge_base
   // The accumulated data.
   unsigned char* p_;
   // The length of the accumulated data.
-  off_t len_;
+  section_size_type len_;
   // The size of the allocated buffer.
-  size_t alc_;
+  section_size_type alc_;
   // The hash table.
   Merge_data_hashtable hashtable_;
 };
@@ -220,7 +223,7 @@ class Output_merge_string : public Output_merge_base
 
   // Do all the final processing after the input sections are read in.
   // Returns the final data size.
-  off_t
+  section_size_type
   finalize_merged_data();
 
   // Set the final data size.
@@ -237,7 +240,7 @@ class Output_merge_string : public Output_merge_base
 
   // Writes the stringpool to a buffer.
   void
-  stringpool_to_buffer(unsigned char* buffer, size_t buffer_size)
+  stringpool_to_buffer(unsigned char* buffer, section_size_type buffer_size)
   { this->stringpool_.write_to_buffer(buffer, buffer_size); }
 
   // Clears all the data in the stringpool, to save on memory.
@@ -255,14 +258,15 @@ class Output_merge_string : public Output_merge_base
     // The input section in the input object.
     unsigned int shndx;
     // The offset in the input section.
-    off_t offset;
+    section_offset_type offset;
     // The string itself, a pointer into a Stringpool.
     const Char_type* string;
     // The length of the string in bytes, including the null terminator.
     size_t length;
 
-    Merged_string(Relobj *objecta, unsigned int shndxa, off_t offseta,
-                 const Char_type* stringa, size_t lengtha)
+    Merged_string(Relobj *objecta, unsigned int shndxa,
+                 section_offset_type offseta, const Char_type* stringa,
+                 size_t lengtha)
       : object(objecta), shndx(shndxa), offset(offseta), string(stringa),
        length(lengtha)
     { }
index 9d62881..5216049 100644 (file)
@@ -75,11 +75,12 @@ Object::error(const char* format, ...) const
 // Return a view of the contents of a section.
 
 const unsigned char*
-Object::section_contents(unsigned int shndx, off_t* plen, bool cache)
+Object::section_contents(unsigned int shndx, section_size_type* plen,
+                        bool cache)
 {
   Location loc(this->do_section_contents(shndx));
-  *plen = loc.data_size;
-  return this->get_view(loc.file_offset, loc.data_size, cache);
+  *plen = convert_to_section_size_type(loc.data_size);
+  return this->get_view(loc.file_offset, *plen, cache);
 }
 
 // Read the section data into SD.  This is code common to Sized_relobj
@@ -106,7 +107,8 @@ Object::read_section_data(elfcpp::Elf_file<size, big_endian, Object>* elf_file,
     this->error(_("section name section has wrong type: %u"),
                static_cast<unsigned int>(shdrnames.get_sh_type()));
 
-  sd->section_names_size = shdrnames.get_sh_size();
+  sd->section_names_size =
+    convert_to_section_size_type(shdrnames.get_sh_size());
   sd->section_names = this->get_lasting_view(shdrnames.get_sh_offset(),
                                             sd->section_names_size, false);
 }
@@ -222,9 +224,10 @@ Sized_relobj<size, big_endian>::check_eh_frame_flags(
 
 template<int size, bool big_endian>
 bool
-Sized_relobj<size, big_endian>::find_eh_frame(const unsigned char* pshdrs,
-                                             const char* names,
-                                             off_t names_size) const
+Sized_relobj<size, big_endian>::find_eh_frame(
+    const unsigned char* pshdrs,
+    const char* names,
+    section_size_type names_size) const
 {
   const unsigned int shnum = this->shnum();
   const unsigned char* p = pshdrs + This::shdr_size;
@@ -293,14 +296,15 @@ Sized_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
   const unsigned int loccount = symtabshdr.get_sh_info();
   this->local_symbol_count_ = loccount;
   this->local_values_.resize(loccount);
-  off_t locsize = loccount * sym_size;
+  section_offset_type locsize = loccount * sym_size;
   off_t dataoff = symtabshdr.get_sh_offset();
-  off_t datasize = symtabshdr.get_sh_size();
+  section_size_type datasize =
+    convert_to_section_size_type(symtabshdr.get_sh_size());
   off_t extoff = dataoff + locsize;
-  off_t extsize = datasize - locsize;
+  section_size_type extsize = datasize - locsize;
 
   off_t readoff = this->has_eh_frame_ ? dataoff : extoff;
-  off_t readsize = this->has_eh_frame_ ? datasize : extsize;
+  section_size_type readsize = this->has_eh_frame_ ? datasize : extsize;
 
   File_view* fvsymtab = this->get_lasting_view(readoff, readsize, false);
 
@@ -327,7 +331,8 @@ Sized_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
   sd->symbols_size = readsize;
   sd->external_symbols_offset = this->has_eh_frame_ ? locsize : 0;
   sd->symbol_names = fvstrtab;
-  sd->symbol_names_size = strtabshdr.get_sh_size();
+  sd->symbol_names_size =
+    convert_to_section_size_type(strtabshdr.get_sh_size());
 }
 
 // Return the section index of symbol SYM.  Set *VALUE to its value in
@@ -340,7 +345,7 @@ unsigned int
 Sized_relobj<size, big_endian>::symbol_section_and_value(unsigned int sym,
                                                         Address* value)
 {
-  off_t symbols_size;
+  section_size_type symbols_size;
   const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
                                                        &symbols_size,
                                                        false);
@@ -403,7 +408,7 @@ Sized_relobj<size, big_endian>::include_section_group(
   elfcpp::Sym<size, big_endian> sym(psym);
 
   // Read the symbol table names.
-  off_t symnamelen;
+  section_size_type symnamelen;
   const unsigned char* psymnamesu;
   psymnamesu = this->section_contents(symshdr.get_sh_link(), &symnamelen,
                                      true);
@@ -703,8 +708,7 @@ Sized_relobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
   const int sym_size = This::sym_size;
   size_t symcount = ((sd->symbols_size - sd->external_symbols_offset)
                     / sym_size);
-  if (static_cast<off_t>(symcount * sym_size)
-      != sd->symbols_size - sd->external_symbols_offset)
+  if (symcount * sym_size != sd->symbols_size - sd->external_symbols_offset)
     {
       this->error(_("size of symbols is not multiple of symbol size"));
       return;
@@ -758,7 +762,7 @@ Sized_relobj<size, big_endian>::do_count_local_symbols(Stringpool* pool,
 
   // Read the symbol names.
   const unsigned int strtab_shndx = symtabshdr.get_sh_link();
-  off_t strtab_size;
+  section_size_type strtab_size;
   const unsigned char* pnamesu = this->section_contents(strtab_shndx,
                                                        &strtab_size,
                                                        true);
@@ -1018,7 +1022,7 @@ Sized_relobj<size, big_endian>::write_local_symbols(
 
   // Read the symbol names.
   const unsigned int strtab_shndx = symtabshdr.get_sh_link();
-  off_t strtab_size;
+  section_size_type strtab_size;
   const unsigned char* pnamesu = this->section_contents(strtab_shndx,
                                                        &strtab_size,
                                                        true);
@@ -1123,13 +1127,13 @@ Sized_relobj<size, big_endian>::get_symbol_location_info(
   if (this->symtab_shndx_ == 0)
     return false;
 
-  off_t symbols_size;
+  section_size_type symbols_size;
   const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
                                                        &symbols_size,
                                                        false);
 
   unsigned int symbol_names_shndx = this->section_link(this->symtab_shndx_);
-  off_t names_size;
+  section_size_type names_size;
   const unsigned char* symbol_names_u =
     this->section_contents(symbol_names_shndx, &names_size, false);
   const char* symbol_names = reinterpret_cast<const char*>(symbol_names_u);
@@ -1361,7 +1365,7 @@ namespace gold
 
 Object*
 make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
-               const unsigned char* p, off_t bytes)
+               const unsigned char* p, section_offset_type bytes)
 {
   if (bytes < elfcpp::EI_NIDENT)
     {
index a43ef0c..1ad9796 100644 (file)
@@ -54,31 +54,31 @@ struct Read_symbols_data
   // Section names.
   File_view* section_names;
   // Size of section name data in bytes.
-  off_t section_names_size;
+  section_size_type section_names_size;
   // Symbol data.
   File_view* symbols;
   // Size of symbol data in bytes.
-  off_t symbols_size;
+  section_size_type symbols_size;
   // Offset of external symbols within symbol data.  This structure
   // sometimes contains only external symbols, in which case this will
   // be zero.  Sometimes it contains all symbols.
-  off_t external_symbols_offset;
+  section_offset_type external_symbols_offset;
   // Symbol names.
   File_view* symbol_names;
   // Size of symbol name data in bytes.
-  off_t symbol_names_size;
+  section_size_type symbol_names_size;
 
   // Version information.  This is only used on dynamic objects.
   // Version symbol data (from SHT_GNU_versym section).
   File_view* versym;
-  off_t versym_size;
+  section_size_type versym_size;
   // Version definition data (from SHT_GNU_verdef section).
   File_view* verdef;
-  off_t verdef_size;
+  section_size_type verdef_size;
   unsigned int verdef_info;
   // Needed version data  (from SHT_GNU_verneed section).
   File_view* verneed;
-  off_t verneed_size;
+  section_size_type verneed_size;
   unsigned int verneed_info;
 };
 
@@ -204,7 +204,7 @@ class Object
   // Return a view of the contents of a section.  Set *PLEN to the
   // size.  CACHE is a hint as in File_read::get_view.
   const unsigned char*
-  section_contents(unsigned int shndx, off_t* plen, bool cache);
+  section_contents(unsigned int shndx, section_size_type* plen, bool cache);
 
   // Return the name of a section given a section index.  This is only
   // used for error messages.
@@ -272,7 +272,7 @@ class Object
 
   // Return a View.
   View
-  view(off_t file_offset, off_t data_size)
+  view(off_t file_offset, section_size_type data_size)
   { return View(this->get_view(file_offset, data_size, true)); }
 
   // Report an error.
@@ -285,7 +285,7 @@ class Object
     off_t file_offset;
     off_t data_size;
 
-    Location(off_t fo, off_t ds)
+    Location(off_t fo, section_size_type ds)
       : file_offset(fo), data_size(ds)
     { }
   };
@@ -344,7 +344,7 @@ class Object
 
   // Get a view into the underlying file.
   const unsigned char*
-  get_view(off_t start, off_t size, bool cache)
+  get_view(off_t start, section_size_type size, bool cache)
   {
     return this->input_file()->file().get_view(start + this->offset_, size,
                                               cache);
@@ -352,7 +352,7 @@ class Object
 
   // Get a lasting view into the underlying file.
   File_view*
-  get_lasting_view(off_t start, off_t size, bool cache)
+  get_lasting_view(off_t start, section_size_type size, bool cache)
   {
     return this->input_file()->file().get_lasting_view(start + this->offset_,
                                                       size, cache);
@@ -360,7 +360,7 @@ class Object
 
   // Read data from the underlying file.
   void
-  read(off_t start, off_t size, void* p) const
+  read(off_t start, section_size_type size, void* p) const
   { this->input_file()->file().read(start + this->offset_, size, p); }
 
   // Set the target.
@@ -504,11 +504,11 @@ class Relobj : public Object
   // and set *POFF to the offset within that section.  *POFF will be
   // set to -1 if the section requires special handling.
   inline Output_section*
-  output_section(unsigned int shndx, off_t* poff) const;
+  output_section(unsigned int shndx, section_offset_type* poff) const;
 
   // Set the offset of an input section within its output section.
   void
-  set_section_offset(unsigned int shndx, off_t off)
+  set_section_offset(unsigned int shndx, section_offset_type off)
   {
     gold_assert(shndx < this->map_to_output_.size());
     this->map_to_output_[shndx].offset = off;
@@ -546,7 +546,7 @@ class Relobj : public Object
     Output_section* output_section;
     // The offset within the output section.  This is -1 if the
     // section requires special handling.
-    off_t offset;
+    section_offset_type offset;
   };
 
   // Read the relocs--implemented by child class.
@@ -614,7 +614,7 @@ class Relobj : public Object
 
 // Implement Object::output_section inline for efficiency.
 inline Output_section*
-Relobj::output_section(unsigned int shndx, off_t* poff) const
+Relobj::output_section(unsigned int shndx, section_offset_type* poff) const
 {
   gold_assert(shndx < this->map_to_output_.size());
   const Map_to_output& mo(this->map_to_output_[shndx]);
@@ -1083,7 +1083,7 @@ class Sized_relobj : public Relobj
   // a GNU style exception frame section.
   bool
   find_eh_frame(const unsigned char* pshdrs, const char* names,
-               off_t names_size) const;
+               section_size_type names_size) const;
 
   // Whether to include a section group in the link.
   bool
@@ -1102,7 +1102,7 @@ class Sized_relobj : public Relobj
     unsigned char* view;
     typename elfcpp::Elf_types<size>::Elf_Addr address;
     off_t offset;
-    off_t view_size;
+    section_size_type view_size;
     bool is_input_output_view;
     bool is_postprocessing_view;
   };
@@ -1288,7 +1288,7 @@ struct Relocate_info
 extern Object*
 make_elf_object(const std::string& name, Input_file*,
                off_t offset, const unsigned char* p,
-               off_t bytes);
+               section_offset_type bytes);
 
 } // end namespace gold
 
index 922a9e5..5a8cae7 100644 (file)
@@ -673,7 +673,7 @@ Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::write_rel(
   Address address = this->address_;
   if (this->shndx_ != INVALID_CODE)
     {
-      off_t off;
+      section_offset_type off;
       Output_section* os = this->u2_.relobj->output_section(this->shndx_,
                                                            &off);
       gold_assert(os != NULL);
@@ -1085,7 +1085,7 @@ Output_data_got<size, big_endian>::add_local_tls_with_rel(
   this->entries_.push_back(Got_entry());
   unsigned int got_offset = this->last_got_offset();
   object->set_local_tls_got_offset(symndx, got_offset, need_pair);
-  off_t off;
+  section_offset_type off;
   Output_section* os = object->output_section(shndx, &off);
   rel_dyn->add_output_section(os, r_type, this, got_offset);
 
@@ -1113,7 +1113,7 @@ Output_data_got<size, big_endian>::add_local_tls_with_rela(
   this->entries_.push_back(Got_entry());
   unsigned int got_offset = this->last_got_offset();
   object->set_local_tls_got_offset(symndx, got_offset, need_pair);
-  off_t off;
+  section_offset_type off;
   Output_section* os = object->output_section(shndx, &off);
   rela_dyn->add_output_section(os, r_type, this, got_offset, 0);
 
@@ -1350,10 +1350,11 @@ Output_section::Input_section::finalize_data_size()
 // Try to turn an input offset into an output offset.
 
 bool
-Output_section::Input_section::output_offset(const Relobj* object,
-                                            unsigned int shndx,
-                                            off_t offset,
-                                            off_t *poutput) const
+Output_section::Input_section::output_offset(
+    const Relobj* object,
+    unsigned int shndx,
+    section_offset_type offset,
+    section_offset_type *poutput) const
 {
   if (!this->is_input_section())
     return this->u2_.posd->output_offset(object, shndx, offset, poutput);
@@ -1361,7 +1362,7 @@ Output_section::Input_section::output_offset(const Relobj* object,
     {
       if (this->shndx_ != shndx || this->u2_.object != object)
        return false;
-      off_t output_offset;
+      section_offset_type output_offset;
       Output_section* os = object->output_section(shndx, &output_offset);
       gold_assert(os != NULL);
       gold_assert(output_offset != -1);
@@ -1641,7 +1642,7 @@ Output_section::is_input_address_mapped(const Relobj* object,
        p != this->input_sections_.end();
        ++p)
     {
-      off_t output_offset;
+      section_offset_type output_offset;
       if (p->output_offset(object, shndx, offset, &output_offset))
        return output_offset != -1;
     }
@@ -1657,9 +1658,9 @@ Output_section::is_input_address_mapped(const Relobj* object,
 // start of the section.  This should only be called if SHNDX in
 // OBJECT has a special mapping.
 
-off_t
+section_offset_type
 Output_section::output_offset(const Relobj* object, unsigned int shndx,
-                             off_t offset) const
+                             section_offset_type offset) const
 {
   gold_assert(object->is_section_specially_mapped(shndx));
   // This can only be called meaningfully when layout is complete.
@@ -1669,7 +1670,7 @@ Output_section::output_offset(const Relobj* object, unsigned int shndx,
        p != this->input_sections_.end();
        ++p)
     {
-      off_t output_offset;
+      section_offset_type output_offset;
       if (p->output_offset(object, shndx, offset, &output_offset))
        return output_offset;
     }
@@ -1693,7 +1694,7 @@ Output_section::output_address(const Relobj* object, unsigned int shndx,
        ++p)
     {
       addr = align_address(addr, p->addralign());
-      off_t output_offset;
+      section_offset_type output_offset;
       if (p->output_offset(object, shndx, offset, &output_offset))
        {
          if (output_offset == -1)
index 172be49..76db946 100644 (file)
@@ -461,8 +461,9 @@ class Output_section_data : public Output_data
   // sets *POUTPUT to the output offset.  The value -1 indicates that
   // this input offset is being discarded.
   virtual bool
-  output_offset(const Relobj* object, unsigned int shndx, off_t offset,
-               off_t *poutput) const
+  output_offset(const Relobj* object, unsigned int shndx,
+               section_offset_type offset,
+               section_offset_type *poutput) const
   { return this->do_output_offset(object, shndx, offset, poutput); }
 
   // Write the contents to a buffer.  This is used for sections which
@@ -488,7 +489,8 @@ class Output_section_data : public Output_data
 
   // The child class may implement output_offset.
   virtual bool
-  do_output_offset(const Relobj*, unsigned int, off_t, off_t*) const
+  do_output_offset(const Relobj*, unsigned int, section_offset_type,
+                  section_offset_type*) const
   { return false; }
 
   // The child class may implement write_to_buffer.  Most child
@@ -1660,8 +1662,9 @@ class Output_section : public Output_data
 
   // Return the offset within the output section of OFFSET relative to
   // the start of input section SHNDX in object OBJECT.
-  off_t
-  output_offset(const Relobj* object, unsigned int shndx, off_t offset) const;
+  section_offset_type
+  output_offset(const Relobj* object, unsigned int shndx,
+               section_offset_type offset) const;
 
   // Return the output virtual address of OFFSET relative to the start
   // of input section SHNDX in object OBJECT.
@@ -1880,8 +1883,9 @@ class Output_section : public Output_data
     // this function returns true, it sets *POUTPUT to the output
     // offset.
     bool
-    output_offset(const Relobj* object, unsigned int shndx, off_t offset,
-                 off_t *poutput) const;
+    output_offset(const Relobj* object, unsigned int shndx,
+                 section_offset_type offset,
+                 section_offset_type *poutput) const;
 
     // Write out the data.  This does nothing for an input section.
     void
index c997030..39ffe4a 100644 (file)
@@ -651,9 +651,9 @@ class Track_relocs
   // The contents of the input object's reloc section.
   const unsigned char* prelocs_;
   // The length of the reloc section.
-  off_t len_;
+  section_size_type len_;
   // Our current position in the reloc section.
-  off_t pos_;
+  section_size_type pos_;
   // The size of the relocs in the section.
   int reloc_size_;
 };
index 7bf8365..3d8bfe6 100644 (file)
@@ -265,7 +265,7 @@ Stringpool_template<Stringpool_char>::add(const Stringpool_char* s, bool copy,
       // directly.
 
       const Key k = this->next_uncopied_key_;
-      const off_t ozero = 0;
+      const section_offset_type ozero = 0;
       std::pair<Hashkey, Hashval> element(Hashkey(s),
                                          std::make_pair(k, ozero));
 
@@ -320,7 +320,7 @@ Stringpool_template<Stringpool_char>::add_prefix(const Stringpool_char* s,
   // The contents of the string stay the same, so we don't need to
   // adjust hk.hash_code or hk.length.
 
-  const off_t ozero = 0;
+  const section_offset_type ozero = 0;
   std::pair<Hashkey, Hashval> element(hk, std::make_pair(k, ozero));
 
   typedef std::pair<typename String_set_type::iterator, bool> Insert_type;
@@ -412,7 +412,7 @@ Stringpool_template<Stringpool_char>::set_string_offsets()
   const size_t charsize = sizeof(Stringpool_char);
 
   // Offset 0 may be reserved for the empty string.
-  off_t offset = this->zero_null_ ? charsize : 0;
+  section_offset_type offset = this->zero_null_ ? charsize : 0;
 
   // Sorting to find suffixes can take over 25% of the total CPU time
   // used by the linker.  Since it's merely an optimization to reduce
@@ -479,7 +479,7 @@ Stringpool_template<Stringpool_char>::set_string_offsets()
 // exist.
 
 template<typename Stringpool_char>
-off_t
+section_offset_type
 Stringpool_template<Stringpool_char>::get_offset(const Stringpool_char* s)
   const
 {
@@ -494,13 +494,12 @@ Stringpool_template<Stringpool_char>::get_offset(const Stringpool_char* s)
 
 template<typename Stringpool_char>
 void
-Stringpool_template<Stringpool_char>::write_to_buffer(unsigned char* buffer,
-                                                      size_t bufsize)
+Stringpool_template<Stringpool_char>::write_to_buffer(
+    unsigned char* buffer,
+    section_size_type bufsize)
 {
   gold_assert(this->strtab_size_ != 0);
-   // Quiet the compiler in opt mode.
-  if (bufsize < static_cast<size_t>(this->strtab_size_))
-    gold_assert(bufsize >= static_cast<size_t>(this->strtab_size_));
+  gold_assert(bufsize >= this->strtab_size_);
   if (this->zero_null_)
     buffer[0] = '\0';
   for (typename String_set_type::const_iterator p = this->string_set_.begin();
@@ -508,7 +507,8 @@ Stringpool_template<Stringpool_char>::write_to_buffer(unsigned char* buffer,
        ++p)
     {
       const int len = (p->first.length + 1) * sizeof(Stringpool_char);
-      gold_assert(p->second.second + len <= this->strtab_size_);
+      gold_assert(static_cast<section_size_type>(p->second.second) + len
+                 <= this->strtab_size_);
       memcpy(buffer + p->second.second, p->first.string, len);
     }
 }
index 93e1ec8..0da7921 100644 (file)
@@ -127,17 +127,17 @@ class Stringpool_template
   // Get the offset of the string S in the string table.  This returns
   // the offset in bytes, not in units of Stringpool_char.  This may
   // only be called after set_string_offsets has been called.
-  off_t
+  section_offset_type
   get_offset(const Stringpool_char* s) const;
 
   // Get the offset of the string S in the string table.
-  off_t
+  section_offset_type
   get_offset(const std::basic_string<Stringpool_char>& s) const
   { return this->get_offset(s.c_str()); }
 
   // Get the size of the string table.  This returns the number of
   // bytes, not in units of Stringpool_char.
-  off_t
+  section_size_type
   get_strtab_size() const
   {
     gold_assert(this->strtab_size_ != 0);
@@ -153,7 +153,7 @@ class Stringpool_template
   // specified size.  buffer_size should be at least
   // get_strtab_size().
   void
-  write_to_buffer(unsigned char* buffer, size_t buffer_size);
+  write_to_buffer(unsigned char* buffer, section_size_type buffer_size);
 
   // Dump statistical information to stderr.
   void
@@ -247,7 +247,7 @@ class Stringpool_template
   // table offsets.  We only use the offsets if we turn this into an
   // string table section.
 
-  typedef std::pair<Key, off_t> Hashval;
+  typedef std::pair<Key, section_offset_type> Hashval;
 
   typedef Unordered_map<Hashkey, Hashval, Stringpool_hash,
                        Stringpool_eq> String_set_type;
@@ -270,7 +270,7 @@ class Stringpool_template
   // List of buffers.
   Stringdata_list strings_;
   // Size of string table.
-  off_t strtab_size_;
+  section_size_type strtab_size_;
   // Next Stringdata index.
   unsigned int next_index_;
   // Next key value for a string we don't copy.
index 7868c39..2cab980 100644 (file)
@@ -1497,7 +1497,7 @@ Symbol_table::sized_finalize(unsigned index, off_t off, Stringpool* pool)
            else
              {
                Relobj* relobj = static_cast<Relobj*>(symobj);
-               off_t secoff;
+               section_offset_type secoff;
                Output_section* os = relobj->output_section(shndx, &secoff);
 
                if (os == NULL)
@@ -1714,7 +1714,7 @@ Symbol_table::sized_write_globals(const Input_objects* input_objects,
                else
                  {
                    Relobj* relobj = static_cast<Relobj*>(symobj);
-                   off_t secoff;
+                   section_offset_type secoff;
                    Output_section* os = relobj->output_section(in_shndx,
                                                                &secoff);
                    gold_assert(os != NULL);
@@ -2026,7 +2026,7 @@ Warnings::note_warnings(Symbol_table* symtab, const Task* task)
          {
            Task_lock_obj<Object> tl(task, p->second.object);
            const unsigned char* c;
-           off_t len;
+           section_size_type len;
            c = p->second.object->section_contents(p->second.shndx, &len,
                                                   false);
            p->second.set_text(reinterpret_cast<const char*>(c), len);
index 244783e..9613f2e 100644 (file)
@@ -939,7 +939,7 @@ class Warnings
     }
 
     void
-    set_text(const char* t, off_t l)
+    set_text(const char* t, section_size_type l)
     { this->text.assign(t, l); }
   };