This is the mail archive of the
mailing list for the binutils project.
[PATCH] PR gold/20462: Fix bogus layout on ARM with linker script using PHDRS clause
- From: Roland McGrath <mcgrathr at google dot com>
- To: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Thu, 11 Aug 2016 17:14:20 -0700
- Subject: [PATCH] PR gold/20462: Fix bogus layout on ARM with linker script using PHDRS clause
- Authentication-results: sourceware.org; auth=none
See https://sourceware.org/bugzilla/show_bug.cgi?id=20462 for the test
I'm not at all sure this fix is correct. It fixes both the minimal
test case I put in the bug, and my real case (which uses the same
linker script). It causes no regressions in 'make check-gold' in
a trunk build with --target=arm-eabi.
Here's what I figured out:
* On the first pass, the layout comes out just fine.
* ARM always tries relaxation (unless -r).
* In Target_arm::do_relax it calls Target_arm::fix_exidx_coverage and
decides that constituted some relaxation happening, so a second pass
always happens when there are any .ARM.exidx sections.
* In the second pass, Script_sections::expected_segment_count sees
this->segments_created_ and short-circuits, so it returns 0 instead
* Ergo, SIZEOF_HEADERS omits the phdrs in the second pass and
addresses go backwards, making everything unhappy.
Script_sections::expected_segment_count is the only thing that tests
this->segments_created_. It's not really clear to me if this ought
to be part of the state that Script_sections::release_segments (sole
caller Layout::clean_up_after_relaxation) resets, as my change here
does. An alternate fix would be to reverse the order of the first two
checks in Script_sections::expected_segment_count so that it always
returns this->phdrs_elements_->size() when this->saw_phdrs_clause().
(I haven't tried that on my test cases.)
If this is indeed a good fix, may I commit it to trunk and 2.27?
If not, is my other suggestion right or is there a different fix?
2016-08-11 Roland McGrath <email@example.com>
* script-sections.cc (Script_sections::release_segments):
diff --git a/gold/script-sections.cc b/gold/script-sections.cc
index 96c68de..bf25391 100644
@@ -4459,6 +4459,7 @@ Script_sections::release_segments()
+ this->segments_created_ = false;
// Print the SECTIONS clause to F for debugging.