From Cary Coutant: Set offsets of sections with data before finalizing
authorIan Lance Taylor <iant@google.com>
Sat, 27 Oct 2007 00:36:52 +0000 (00:36 +0000)
committerIan Lance Taylor <iant@google.com>
Sat, 27 Oct 2007 00:36:52 +0000 (00:36 +0000)
local symbols.

gold/layout.cc
gold/layout.h

index 22d3b59169d98eae0e8018f98afe2975c28d195a..488ca6de55c976f706c1f4bf812dbde701487034 100644 (file)
@@ -633,15 +633,20 @@ Layout::finalize(const Input_objects* input_objects, Symbol_table* symtab)
   // they contain.
   off_t off = this->set_segment_offsets(target, load_seg, &shndx);
 
+  // Set the file offsets of all the data sections not associated with
+  // segments. This makes sure that debug sections have their offsets
+  // before symbols are finalized.
+  off = this->set_section_offsets(off, &shndx, true);
+
   // Create the symbol table sections.
   this->create_symtab_sections(input_objects, symtab, &off);
 
   // Create the .shstrtab section.
   Output_section* shstrtab_section = this->create_shstrtab();
 
-  // Set the file offsets of all the sections not associated with
+  // Set the file offsets of all the non-data sections not associated with
   // segments.
-  off = this->set_section_offsets(off, &shndx);
+  off = this->set_section_offsets(off, &shndx, false);
 
   // Create the section table header.
   Output_section_headers* oshdrs = this->create_shdrs(&off);
@@ -986,12 +991,18 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
 // segment.
 
 off_t
-Layout::set_section_offsets(off_t off, unsigned int* pshndx)
+Layout::set_section_offsets(off_t off,
+                            unsigned int* pshndx,
+                            bool do_bits_sections)
 {
   for (Section_list::iterator p = this->unattached_section_list_.begin();
        p != this->unattached_section_list_.end();
        ++p)
     {
+      bool is_bits_section = ((*p)->type() == elfcpp::SHT_PROGBITS
+                              || (*p)->type() == elfcpp::SHT_NOBITS);
+      if (is_bits_section != do_bits_sections)
+        continue;
       (*p)->set_out_shndx(*pshndx);
       ++*pshndx;
       if ((*p)->offset() != -1)
index 19c8e09ee1000a021c81379a774720ed21b43cf8..6c7441e63be93f6cf2bc398f31e5e00ef4d1baaf 100644 (file)
@@ -316,7 +316,7 @@ class Layout
   // Set the final file offsets and section indexes of all the
   // sections not associated with a segment.
   off_t
-  set_section_offsets(off_t, unsigned int *pshndx);
+  set_section_offsets(off_t, unsigned int *pshndx, bool do_bits_sections);
 
   // Return whether SEG1 comes before SEG2 in the output file.
   static bool