This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
gold patch committed: Fix handling of writable .eh_frame section
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Mon, 10 Jan 2011 14:00:49 -0800
- Subject: gold patch committed: Fix handling of writable .eh_frame section
In http://gcc.gnu.org/PR47248 there is a test case which fails when
using gold with -z relro. It fails because one of the input files has a
writable .eh_frame section (which it shouldn't, but that is another
story). A writable .eh_frame section is a relro section, and gold lays
it out accordingly. However, it was not marked as a relro section, and
this caused gold to miscompute the relro segment padding. This patch
fixes the problem. This patch fixes the problem. I also fixed a
possible lurking problem in the patch of 2010-10-17 in that
increase_relro was not reset in the case where set_section_addresses is
called a second time. Committed to mainline and to 2.21 branch.
Ian
2011-01-10 Ian Lance Taylor <iant@google.com>
* layout.cc (Layout::layout_eh_frame): Mark a writable .eh_frame
section as relro.
(Layout::set_segment_offsets): Reset increase_relro before calling
set_section_addresses a second time.
Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.189
diff -u -p -r1.189 layout.cc
--- layout.cc 9 Dec 2010 23:19:50 -0000 1.189
+++ layout.cc 10 Jan 2011 21:53:17 -0000
@@ -1,6 +1,6 @@
// layout.cc -- lay out output file sections for gold
-// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -912,6 +912,10 @@ Layout::layout_eh_frame(Sized_relobj<siz
{
os->update_flags_for_input_section(shdr.get_sh_flags());
+ // A writable .eh_frame section is a RELRO section.
+ if ((shdr.get_sh_flags() & elfcpp::SHF_WRITE) != 0)
+ os->set_is_relro();
+
// We found a .eh_frame section we are going to optimize, so now
// we can add the set of optimized sections to the output
// section. We need to postpone adding this until we've found a
@@ -2722,6 +2726,12 @@ Layout::set_segment_offsets(const Target
addr = align_address(addr, (*p)->maximum_alignment());
off = orig_off + ((addr - orig_addr) & (abi_pagesize - 1));
off = align_file_offset(off, addr, abi_pagesize);
+
+ increase_relro = this->increase_relro_;
+ if (this->script_options_->saw_sections_clause())
+ increase_relro = 0;
+ has_relro = false;
+
new_addr = (*p)->set_section_addresses(this, true, addr,
&increase_relro,
&has_relro,