This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch][gold] Don't put rodata and text in the same segment.
Looking a bit more in the code I was curious why the optimization of
trying to keep the data contiguous on disk but not in memory could not
be applied in more cases. I also noticed that was_readonly was never
being set back to false. Is it because the code knows how the segments
are ordered? That is wrong in the presence of large segments, no?
Anyway, I tried to apply the optimization unconditionally and I could
not find a case that fails. Would you mind reviewing the attached
patch first? If you do know a case that would fail let me know and I
will add a testcase for it instead.
2010-09-03 Rafael Espindola <espindola@google.com>
* layout.cc (Layout::set_segment_offsets): Try harder to save disk
space.
Thanks,
--
Rafael Ãvila de EspÃndola
diff --git a/gold/layout.cc b/gold/layout.cc
index 5edba48..3d188a6 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -2562,7 +2562,6 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
const bool check_sections = parameters->options().check_sections();
Output_segment* last_load_segment = NULL;
- bool was_readonly = false;
for (Segment_list::iterator p = this->segment_list_.begin();
p != this->segment_list_.end();
++p)
@@ -2609,21 +2608,17 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
if (!are_addresses_set)
{
- // If the last segment was readonly, and this one is
- // not, then skip the address forward one page,
- // maintaining the same position within the page. This
- // lets us store both segments overlapping on a single
- // page in the file, but the loader will put them on
- // different pages in memory.
+ // Skip the address forward one page, maintaining the same
+ // position within the page. This lets us store both segments
+ // overlapping on a single page in the file, but the loader will
+ // put them on different pages in memory. We will revisit this
+ // decision once we know the size of the segment.
addr = align_address(addr, (*p)->maximum_alignment());
aligned_addr = addr;
- if (was_readonly && ((*p)->flags() & elfcpp::PF_W) != 0)
- {
- if ((addr & (abi_pagesize - 1)) != 0)
- addr = addr + abi_pagesize;
- }
+ if ((addr & (abi_pagesize - 1)) != 0)
+ addr = addr + abi_pagesize;
off = orig_off + ((addr - orig_addr) & (abi_pagesize - 1));
}
@@ -2681,9 +2676,6 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
addr = new_addr;
- if (((*p)->flags() & elfcpp::PF_W) == 0)
- was_readonly = true;
-
// Implement --check-sections. We know that the segments
// are sorted by LMA.
if (check_sections && last_load_segment != NULL)