From: Ian Lance Taylor Date: Wed, 7 Nov 2007 22:33:30 +0000 (+0000) Subject: From Craig Silverstein and Cary Coutant: fix assignment of section X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=868870607e2ef7584a22243d0be7bf1601dfba6d;p=binutils-gdb.git From Craig Silverstein and Cary Coutant: fix assignment of section indexes to sections which are not associated with segments. --- diff --git a/gold/layout.cc b/gold/layout.cc index d9593904f33..84e8722714c 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -637,7 +637,7 @@ Layout::finalize(const Input_objects* input_objects, Symbol_table* symtab) // 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); + off = this->set_section_offsets(off, true); // Create the symbol table sections. this->create_symtab_sections(input_objects, symtab, &off); @@ -647,7 +647,10 @@ Layout::finalize(const Input_objects* input_objects, Symbol_table* symtab) // Set the file offsets of all the non-data sections not associated with // segments. - off = this->set_section_offsets(off, &shndx, false); + off = this->set_section_offsets(off, false); + + // Now that all sections have been created, set the section indexes. + shndx = this->set_section_indexes(shndx); // Create the section table header. Output_section_headers* oshdrs = this->create_shdrs(&off); @@ -993,7 +996,6 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg, off_t Layout::set_section_offsets(off_t off, - unsigned int* pshndx, bool do_bits_sections) { for (Section_list::iterator p = this->unattached_section_list_.begin(); @@ -1004,8 +1006,6 @@ Layout::set_section_offsets(off_t off, || (*p)->type() == elfcpp::SHT_NOBITS); if (is_bits_section != do_bits_sections) continue; - (*p)->set_out_shndx(*pshndx); - ++*pshndx; if ((*p)->offset() != -1) continue; off = align_address(off, (*p)->addralign()); @@ -1015,6 +1015,22 @@ Layout::set_section_offsets(off_t off, return off; } +// Set the section indexes of all the sections not associated with a +// segment. + +unsigned int +Layout::set_section_indexes(unsigned int shndx) +{ + for (Section_list::iterator p = this->unattached_section_list_.begin(); + p != this->unattached_section_list_.end(); + ++p) + { + (*p)->set_out_shndx(shndx); + ++shndx; + } + return shndx; +} + // Create the symbol table sections. Here we also set the final // values of the symbols. At this point all the loadable sections are // fully laid out. diff --git a/gold/layout.h b/gold/layout.h index 6c7441e63be..5e9871e38c4 100644 --- a/gold/layout.h +++ b/gold/layout.h @@ -313,10 +313,15 @@ class Layout off_t set_segment_offsets(const Target*, Output_segment*, unsigned int* pshndx); - // Set the final file offsets and section indexes of all the - // sections not associated with a segment. + // Set the final file offsets of all the sections not associated + // with a segment. off_t - set_section_offsets(off_t, unsigned int *pshndx, bool do_bits_sections); + set_section_offsets(off_t, bool do_bits_sections); + + // Set the final section indexes of all the sections not associated + // with a segment. Returns the next unused index. + unsigned int + set_section_indexes(unsigned int pshndx); // Return whether SEG1 comes before SEG2 in the output file. static bool