diff --git a/gold/output.cc b/gold/output.cc index 5cc3629..9c0dfe6 100644 --- a/gold/output.cc +++ b/gold/output.cc @@ -4232,6 +4232,7 @@ Output_segment::set_section_addresses(const Target* target, uint64_t last_relro_pad = 0; off_t orig_off = *poff; + uint64_t orig_addr = addr; bool in_tls = false; @@ -4356,7 +4357,7 @@ Output_segment::set_section_addresses(const Target* target, *poff = align_address(*poff, segment_align); } - this->memsz_ = *poff - orig_off; + this->memsz_ = addr - orig_addr; // Ignore the file offset adjustments made by the BSS Output_data // objects. @@ -4415,6 +4416,8 @@ Output_segment::set_section_list_addresses(Layout* layout, bool reset, // free space in the file. This keeps track of the high-water mark. off_t maxoff = startoff; + off_t fileoff = startoff; + off_t off = startoff; for (Output_data_list::iterator p = pdl->begin(); p != pdl->end(); @@ -4501,7 +4504,10 @@ Output_segment::set_section_list_addresses(Layout* layout, bool reset, // The script may have inserted a skip forward, but it // better not have moved backward. if ((*p)->address() >= addr + (off - startoff)) - off += (*p)->address() - (addr + (off - startoff)); + { + fileoff += (*p)->address() - (addr + (off - startoff)); + off += (*p)->address() - (addr + (off - startoff)); + } else { if (!layout->script_options()->saw_sections_clause()) @@ -4525,7 +4531,7 @@ Output_segment::set_section_list_addresses(Layout* layout, bool reset, os->name(), previous_dot, dot); } } - (*p)->set_file_offset(off); + (*p)->set_file_offset(fileoff); (*p)->finalize_data_size(); } @@ -4544,6 +4550,11 @@ Output_segment::set_section_list_addresses(Layout* layout, bool reset, || !(*p)->is_section_type(elfcpp::SHT_NOBITS)) off += (*p)->data_size(); + if (!(*p)->is_section_type(elfcpp::SHT_NOBITS)) + { + fileoff = off; + } + if (off > maxoff) maxoff = off; @@ -4554,7 +4565,7 @@ Output_segment::set_section_list_addresses(Layout* layout, bool reset, } } - *poff = maxoff; + *poff = fileoff; return addr + (maxoff - startoff); }