Add section_size_type and section_offset_type, use them to replace a
[binutils-gdb.git] / gold / ehframe.cc
index 1c7b7141aba7d3884064047436fcb741804fb659..b77148b43989a39c40f50449b42ba6ae4ce1c551 100644 (file)
@@ -88,10 +88,10 @@ Eh_frame_hdr::Eh_frame_hdr(Output_section* eh_frame_section,
 {
 }
 
-// Set the final address and size of the exception frame header.
+// Set the size of the exception frame header.
 
 void
-Eh_frame_hdr::do_set_address(uint64_t, off_t)
+Eh_frame_hdr::set_final_data_size()
 {
   unsigned int data_size = eh_frame_hdr_size + 4;
   if (!this->any_unrecognized_eh_frame_sections_)
@@ -234,8 +234,11 @@ Eh_frame_hdr::do_sized_write(Output_file* of)
 
 template<int size, bool big_endian>
 typename elfcpp::Elf_types<size>::Elf_Addr
-Eh_frame_hdr::get_fde_pc(const unsigned char* eh_frame_contents,
-                        off_t fde_offset, unsigned char fde_encoding)
+Eh_frame_hdr::get_fde_pc(
+    typename elfcpp::Elf_types<size>::Elf_Addr eh_frame_address,
+    const unsigned char* eh_frame_contents,
+    section_offset_type fde_offset,
+    unsigned char fde_encoding)
 {
   // The FDE starts with a 4 byte length and a 4 byte offset to the
   // CIE.  The PC follows.
@@ -274,6 +277,22 @@ Eh_frame_hdr::get_fde_pc(const unsigned char* eh_frame_contents,
       break;
 
     default:
+      // All other cases were rejected in Eh_frame::read_cie.
+      gold_unreachable();
+    }
+
+  switch (fde_encoding & 0xf0)
+    {
+    case 0:
+      break;
+
+    case elfcpp::DW_EH_PE_pcrel:
+      pc += eh_frame_address + fde_offset + 8;
+      break;
+
+    default:
+      // If other cases arise, then we have to handle them, or we have
+      // to reject them by returning false in Eh_frame::read_cie.
       gold_unreachable();
     }
 
@@ -304,7 +323,8 @@ Eh_frame_hdr::get_fde_addresses(Output_file* of,
        ++p)
     {
       typename elfcpp::Elf_types<size>::Elf_Addr fde_pc;
-      fde_pc = this->get_fde_pc<size, big_endian>(eh_frame_contents,
+      fde_pc = this->get_fde_pc<size, big_endian>(eh_frame_address,
+                                                 eh_frame_contents,
                                                  p->first, p->second);
       fde_addresses->push_back(fde_pc, eh_frame_address + p->first);
     }
@@ -319,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();
 
@@ -363,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();
@@ -393,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();
 
@@ -492,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);
@@ -556,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;
@@ -644,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,
@@ -742,6 +765,8 @@ Eh_frame::read_cie(Sized_relobj<size, big_endian>* object,
            case elfcpp::DW_EH_PE_udata8:
              break;
            default:
+             // We don't expect to see any other cases here, and
+             // we're not prepared to handle them.
              return false;
            }
          ++p;
@@ -896,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,
@@ -976,9 +1001,10 @@ Eh_frame::fde_count() const
 // Set the final data size.
 
 void
-Eh_frame::do_set_address(uint64_t, off_t start_file_offset)
+Eh_frame::set_final_data_size()
 {
-  off_t output_offset = 0;
+  off_t start_file_offset = this->offset();
+  section_offset_type output_offset = 0;
 
   for (Unmergeable_cie_offsets::iterator p =
         this->unmergeable_cie_offsets_.begin();
@@ -1009,7 +1035,8 @@ Eh_frame::do_set_address(uint64_t, off_t start_file_offset)
 
 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);
 }
@@ -1073,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();
@@ -1091,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);
@@ -1105,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);
@@ -1119,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);
@@ -1133,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);