This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gold patch committed: Update order if section flags change


When we add a second and subsequent input section to an output section,
it's possible for the output section's flags to change.  That can in
turn mean that the output section should be placed in a different
location in the output segment.  This was causing a relro assertion
error in a case where a section changed from read-only to read-write,
thus moving from the text segment to the data segment.  The ordering was
remaining ORDER_READONLY, putting it before the relro sections in the
data segment, which of course does not work.  This patch fixes the
problem.  Committed to mainline and 2.21 branch.

Ian


2011-05-06  Ian Lance Taylor  <iant@google.com>

	* layout.cc (Layout::layout): If the output section flags change,
	update the ordering.


Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.193
diff -u -p -r1.193 layout.cc
--- layout.cc	22 Apr 2011 22:39:55 -0000	1.193
+++ layout.cc	6 May 2011 14:53:55 -0000
@@ -944,8 +944,21 @@ Layout::layout(Sized_relobj<size, big_en
 
   // FIXME: Handle SHF_LINK_ORDER somewhere.
 
+  elfcpp::Elf_Xword orig_flags = os->flags();
+
   *off = os->add_input_section(this, object, shndx, name, shdr, reloc_shndx,
 			       this->script_options_->saw_sections_clause());
+
+  // If the flags changed, we may have to change the order.
+  if ((orig_flags & elfcpp::SHF_ALLOC) != 0)
+    {
+      orig_flags &= (elfcpp::SHF_WRITE | elfcpp::SHF_EXECINSTR);
+      elfcpp::Elf_Xword new_flags =
+	os->flags() & (elfcpp::SHF_WRITE | elfcpp::SHF_EXECINSTR);
+      if (orig_flags != new_flags)
+	os->set_order(this->default_section_order(os, false));
+    }
+
   this->have_added_input_section_ = true;
 
   return os;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]