Fix bug in plugin section ordering infrastructure when layout is deferred.
Sriraman Tallam
tmsriram@google.com
Wed Sep 28 18:02:00 GMT 2011
Hi,
Currently, the plugin section ordering infrastructure does not do
the right thing when layout is deferred. This happens when garbage
collection or icf is done. The --section-ordering-file works fine
because it updates section order only after layout is done. This
patch fixes this problem by delaying the update of the section order
of input sections until layout has all the output sections.
Thanks,
-Sri.
* layout.h (section_order_map_): New member.
(get_section_order_map): New member function.
* output.cc (Output_section::add_input_section): Check for patterns
only when --section-ordering-file is specified.
* gold.cc (queue_middle_tasks): Delay updating order of sections till
output_sections have been formed.
* layout.cc (Layout_Layout): Initialize section_order_map_.
* plugin.cc (update_section_order): Store order in order_map. Do not
update the order.
-------------- next part --------------
Index: gold.cc
===================================================================
RCS file: /cvs/src/src/gold/gold.cc,v
retrieving revision 1.94
diff -u -u -p -r1.94 gold.cc
--- gold.cc 15 Jul 2011 21:43:08 -0000 1.94
+++ gold.cc 28 Sep 2011 17:57:43 -0000
@@ -556,6 +556,19 @@ queue_middle_tasks(const General_options
}
}
+ /* If plugins have specified a section order, re-arrange input sections
+ according to a specified section order. If --section-ordering-file is
+ also specified, do not do anything here. */
+ if (parameters->options().has_plugins()
+ && layout->is_section_ordering_specified()
+ && !parameters->options().section_ordering_file ())
+ {
+ for (Layout::Section_list::const_iterator p = layout->section_list().begin();
+ p != layout->section_list().end();
+ ++p)
+ (*p)->update_section_layout(layout->get_section_order_map ());
+ }
+
// Layout deferred objects due to plugins.
if (parameters->options().has_plugins())
{
Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.220
diff -u -u -p -r1.220 layout.cc
--- layout.cc 18 Sep 2011 15:06:28 -0000 1.220
+++ layout.cc 28 Sep 2011 17:57:44 -0000
@@ -410,6 +410,7 @@ Layout::Layout(int number_of_input_files
script_output_section_data_list_(),
segment_states_(NULL),
relaxation_debug_check_(NULL),
+ section_order_map_ (),
input_section_position_(),
input_section_glob_(),
incremental_base_(NULL),
Index: layout.h
===================================================================
RCS file: /cvs/src/src/gold/layout.h,v
retrieving revision 1.100
diff -u -u -p -r1.100 layout.h
--- layout.h 27 Aug 2011 01:28:17 -0000 1.100
+++ layout.h 28 Sep 2011 17:57:44 -0000
@@ -522,6 +522,10 @@ class Layout
const char* name, const elfcpp::Shdr<size, big_endian>& shdr,
unsigned int reloc_shndx, unsigned int reloc_type, off_t* offset);
+ std::map<Section_id, unsigned int> &
+ get_section_order_map()
+ { return this->section_order_map_; }
+
bool
is_section_ordering_specified()
{ return this->section_ordering_specified_; }
@@ -1322,6 +1326,9 @@ class Layout
Segment_states* segment_states_;
// A relaxation debug checker. We only create one when in debugging mode.
Relaxation_debug_check* relaxation_debug_check_;
+ // Plugins specify section_ordering using this map. This is set in
+ // update_section_order in plugin.cc
+ std::map<Section_id, unsigned int> section_order_map_;
// Hash a pattern to its position in the section ordering file.
Unordered_map<std::string, unsigned int> input_section_position_;
// Vector of glob only patterns in the section_ordering file.
Index: output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.159
diff -u -u -p -r1.159 output.cc
--- output.cc 10 Sep 2011 05:15:43 -0000 1.159
+++ output.cc 28 Sep 2011 17:57:44 -0000
@@ -2476,7 +2476,10 @@ Output_section::add_input_section(Layout
|| layout->is_section_ordering_specified())
{
Input_section isecn(object, shndx, input_section_size, addralign);
- if (layout->is_section_ordering_specified())
+ /* If section ordering is requested by specifying a ordering file,
+ using --section-ordering-file, match the section name with
+ a pattern. */
+ if (parameters->options().section_ordering_file ())
{
unsigned int section_order_index =
layout->find_section_order_index(std::string(secname));
Index: plugin.cc
===================================================================
RCS file: /cvs/src/src/gold/plugin.cc,v
retrieving revision 1.48
diff -u -u -p -r1.48 plugin.cc
--- plugin.cc 14 Jul 2011 00:55:18 -0000 1.48
+++ plugin.cc 28 Sep 2011 17:57:44 -0000
@@ -1588,8 +1588,14 @@ update_section_order(const struct ld_plu
if (section_list == NULL)
return LDPS_ERR;
- std::map<Section_id, unsigned int> order_map;
+ Layout* layout = parameters->options().plugins()->layout();
+ gold_assert (layout != NULL);
+ std::map<Section_id, unsigned int> &order_map
+ = layout->get_section_order_map ();
+
+ /* Store the mapping from Section_id to section position in layout's
+ order_map to consult after output sections are added. */
for (unsigned int i = 0; i < num_sections; ++i)
{
Object* obj = parameters->options().plugins()->get_elf_object(
@@ -1601,14 +1607,6 @@ update_section_order(const struct ld_plu
order_map[secn_id] = i + 1;
}
- Layout* layout = parameters->options().plugins()->layout();
- gold_assert (layout != NULL);
-
- for (Layout::Section_list::const_iterator p = layout->section_list().begin();
- p != layout->section_list().end();
- ++p)
- (*p)->update_section_layout(order_map);
-
return LDPS_OK;
}
cvs diff: Diffing po
cvs diff: Diffing testsuite
More information about the Binutils
mailing list