aboutsummaryrefslogtreecommitdiff
path: root/gold/layout.cc
diff options
context:
space:
mode:
authorSriraman Tallam <tmsriram@google.com>2012-08-24 18:35:35 +0000
committerSriraman Tallam <tmsriram@google.com>2012-08-24 18:35:35 +0000
commit16164a6b00372ebc0360f6aa71337e5613278817 (patch)
tree503893149fa2b29775eafe985a0a537cf7433132 /gold/layout.cc
parent92a289b3800274d15d440cea98c0df067da4c2ec (diff)
downloadgdb-16164a6b00372ebc0360f6aa71337e5613278817.zip
gdb-16164a6b00372ebc0360f6aa71337e5613278817.tar.gz
gdb-16164a6b00372ebc0360f6aa71337e5613278817.tar.bz2
Patch adds support to allow plugins to map selected subset of sections to unique
segments. 2012-08-24 Sriraman Tallam <tmsriram@google.com> * gold.cc (queue_middle_tasks): Call layout again when unique segments for sections is desired. * layout.cc (Layout::Layout): Initialize new members. (Layout::get_output_section_flags): New function. (Layout::choose_output_section): Call get_output_section_flags. (Layout::layout): Make output section for mapping to a unique segment. (Layout::insert_section_segment_map): New function. (Layout::attach_allocated_section_to_segment): Make unique segment for output sections marked so. (Layout::segment_precedes): Check for unique segments when sorting. * layout.h (Layout::Unique_segment_info): New struct. (Layout::Section_segment_map): New typedef. (Layout::insert_section_segment_map): New function. (Layout::get_output_section_flags): New function. (Layout::is_unique_segment_for_sections_specified): New function. (Layout::set_unique_segment_for_sections_specified): New function. (Layout::unique_segment_for_sections_specified_): New member. (Layout::section_segment_map_): New member. * object.cc (Sized_relobj_file<size, big_endian>::do_layout): Rename is_gc_pass_one to is_pass_one. Rename is_gc_pass_two to is_pass_two. Rename is_gc_or_icf to is_two_pass. Check for which pass based on whether symbols data is present. Make it two pass when unique segments for sections is desired. * output.cc (Output_section::Output_section): Initialize new members. * output.h (Output_section::is_unique_segment): New function. (Output_section::set_is_unique_segment): New function. (Output_section::is_unique_segment_): New member. (Output_section::extra_segment_flags): New function. (Output_section::set_extra_segment_flags): New function. (Output_section::extra_segment_flags_): New member. (Output_section::segment_alignment): New function. (Output_section::set_segment_alignment): New function. (Output_section::segment_alignment_): New member. (Output_segment::Output_segment): Initialize is_unique_segment_. (Output_segment::is_unique_segment): New function. (Output_segment::set_is_unique_segment): New function. (Output_segment::is_unique_segment_): New member. * plugin.cc (allow_unique_segment_for_sections): New function. (unique_segment_for_sections): New function. (Plugin::load): Add new functions to transfer vector. * Makefile.am (plugin_final_layout.readelf.stdout): Add readelf output. * Makefile.in: Regenerate. * testsuite/plugin_final_layout.sh: Check if unique segment functionality works. * testsuite/plugin_section_order.c (onload): Check if new interfaces are available. (allow_unique_segment_for_sections): New global. (unique_segment_for_sections): New global. (claim_file_hook): Call allow_unique_segment_for_sections. (all_symbols_read_hook): Call unique_segment_for_sections. 2012-08-24 Sriraman Tallam <tmsriram@google.com> * plugin-api.h (ld_plugin_allow_unique_segment_for_sections): New interface. (ld_plugin_unique_segment_for_sections): New interface. (LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS): New enum val. (LDPT_UNIQUE_SEGMENT_FOR_SECTIONS): New enum val. (tv_allow_unique_segment_for_sections): New member. (tv_unique_segment_for_sections): New member.
Diffstat (limited to 'gold/layout.cc')
-rw-r--r--gold/layout.cc176
1 files changed, 123 insertions, 53 deletions
diff --git a/gold/layout.cc b/gold/layout.cc
index db6b6ac..cadac87 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -408,12 +408,14 @@ Layout::Layout(int number_of_input_files, Script_options* script_options)
resized_signatures_(false),
have_stabstr_section_(false),
section_ordering_specified_(false),
+ unique_segment_for_sections_specified_(false),
incremental_inputs_(NULL),
record_output_section_data_from_script_(false),
script_output_section_data_list_(),
segment_states_(NULL),
relaxation_debug_check_(NULL),
section_order_map_(),
+ section_segment_map_(),
input_section_position_(),
input_section_glob_(),
incremental_base_(NULL),
@@ -824,6 +826,27 @@ Layout::keep_input_section(const Relobj* relobj, const char* name)
return name != NULL && keep;
}
+// Clear the input section flags that should not be copied to the
+// output section.
+
+elfcpp::Elf_Xword
+Layout::get_output_section_flags(elfcpp::Elf_Xword input_section_flags)
+{
+ // Some flags in the input section should not be automatically
+ // copied to the output section.
+ input_section_flags &= ~ (elfcpp::SHF_INFO_LINK
+ | elfcpp::SHF_GROUP
+ | elfcpp::SHF_MERGE
+ | elfcpp::SHF_STRINGS);
+
+ // We only clear the SHF_LINK_ORDER flag in for
+ // a non-relocatable link.
+ if (!parameters->options().relocatable())
+ input_section_flags &= ~elfcpp::SHF_LINK_ORDER;
+
+ return input_section_flags;
+}
+
// Pick the output section to use for section NAME, in input file
// RELOBJ, with type TYPE and flags FLAGS. RELOBJ may be NULL for a
// linker created section. IS_INPUT_SECTION is true if we are
@@ -842,17 +865,7 @@ Layout::choose_output_section(const Relobj* relobj, const char* name,
// sections to segments.
gold_assert(!is_input_section || !this->sections_are_attached_);
- // Some flags in the input section should not be automatically
- // copied to the output section.
- flags &= ~ (elfcpp::SHF_INFO_LINK
- | elfcpp::SHF_GROUP
- | elfcpp::SHF_MERGE
- | elfcpp::SHF_STRINGS);
-
- // We only clear the SHF_LINK_ORDER flag in for
- // a non-relocatable link.
- if (!parameters->options().relocatable())
- flags &= ~elfcpp::SHF_LINK_ORDER;
+ flags = this->get_output_section_flags(flags);
if (this->script_options_->saw_sections_clause())
{
@@ -1054,9 +1067,37 @@ Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
}
else
{
- os = this->choose_output_section(object, name, sh_type,
- shdr.get_sh_flags(), true,
- ORDER_INVALID, false);
+ // Plugins can choose to place one or more subsets of sections in
+ // unique segments and this is done by mapping these section subsets
+ // to unique output sections. Check if this section needs to be
+ // remapped to a unique output section.
+ Section_segment_map::iterator it
+ = this->section_segment_map_.find(Const_section_id(object, shndx));
+ if (it == this->section_segment_map_.end())
+ {
+ os = this->choose_output_section(object, name, sh_type,
+ shdr.get_sh_flags(), true,
+ ORDER_INVALID, false);
+ }
+ else
+ {
+ // We know the name of the output section, directly call
+ // get_output_section here by-passing choose_output_section.
+ elfcpp::Elf_Xword flags
+ = this->get_output_section_flags(shdr.get_sh_flags());
+
+ const char* os_name = it->second->name;
+ Stringpool::Key name_key;
+ os_name = this->namepool_.add(os_name, true, &name_key);
+ os = this->get_output_section(os_name, name_key, sh_type, flags,
+ ORDER_INVALID, false);
+ if (!os->is_unique_segment())
+ {
+ os->set_is_unique_segment();
+ os->set_extra_segment_flags(it->second->flags);
+ os->set_segment_alignment(it->second->align);
+ }
+ }
if (os == NULL)
return NULL;
}
@@ -1116,6 +1157,15 @@ Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
return os;
}
+// Maps section SECN to SEGMENT s.
+void
+Layout::insert_section_segment_map(Const_section_id secn,
+ Unique_segment_info *s)
+{
+ gold_assert(this->unique_segment_for_sections_specified_);
+ this->section_segment_map_[secn] = s;
+}
+
// Handle a relocation section when doing a relocatable link.
template<int size, bool big_endian>
@@ -1718,6 +1768,10 @@ Layout::attach_allocated_section_to_segment(const Target* target,
elfcpp::Elf_Word seg_flags = Layout::section_flags_to_segment(flags);
+ // If this output section's segment has extra flags that need to be set,
+ // coming from a linker plugin, do that.
+ seg_flags |= os->extra_segment_flags();
+
// Check for --section-start.
uint64_t addr;
bool is_address_set = parameters->options().section_start(os->name(), &addr);
@@ -1730,45 +1784,51 @@ Layout::attach_allocated_section_to_segment(const Target* target,
// have to use a linker script.
Segment_list::const_iterator p;
- for (p = this->segment_list_.begin();
- p != this->segment_list_.end();
- ++p)
+ if (!os->is_unique_segment())
{
- if ((*p)->type() != elfcpp::PT_LOAD)
- continue;
- if (!parameters->options().omagic()
- && ((*p)->flags() & elfcpp::PF_W) != (seg_flags & elfcpp::PF_W))
- continue;
- if ((target->isolate_execinstr() || parameters->options().rosegment())
- && ((*p)->flags() & elfcpp::PF_X) != (seg_flags & elfcpp::PF_X))
- continue;
- // If -Tbss was specified, we need to separate the data and BSS
- // segments.
- if (parameters->options().user_set_Tbss())
- {
- if ((os->type() == elfcpp::SHT_NOBITS)
- == (*p)->has_any_data_sections())
- continue;
- }
- if (os->is_large_data_section() && !(*p)->is_large_data_segment())
- continue;
-
- if (is_address_set)
+ for (p = this->segment_list_.begin();
+ p != this->segment_list_.end();
+ ++p)
{
- if ((*p)->are_addresses_set())
- continue;
-
- (*p)->add_initial_output_data(os);
- (*p)->update_flags_for_output_section(seg_flags);
- (*p)->set_addresses(addr, addr);
- break;
- }
-
- (*p)->add_output_section_to_load(this, os, seg_flags);
- break;
- }
-
- if (p == this->segment_list_.end())
+ if ((*p)->type() != elfcpp::PT_LOAD)
+ continue;
+ if ((*p)->is_unique_segment())
+ continue;
+ if (!parameters->options().omagic()
+ && ((*p)->flags() & elfcpp::PF_W) != (seg_flags & elfcpp::PF_W))
+ continue;
+ if ((target->isolate_execinstr() || parameters->options().rosegment())
+ && ((*p)->flags() & elfcpp::PF_X) != (seg_flags & elfcpp::PF_X))
+ continue;
+ // If -Tbss was specified, we need to separate the data and BSS
+ // segments.
+ if (parameters->options().user_set_Tbss())
+ {
+ if ((os->type() == elfcpp::SHT_NOBITS)
+ == (*p)->has_any_data_sections())
+ continue;
+ }
+ if (os->is_large_data_section() && !(*p)->is_large_data_segment())
+ continue;
+
+ if (is_address_set)
+ {
+ if ((*p)->are_addresses_set())
+ continue;
+
+ (*p)->add_initial_output_data(os);
+ (*p)->update_flags_for_output_section(seg_flags);
+ (*p)->set_addresses(addr, addr);
+ break;
+ }
+
+ (*p)->add_output_section_to_load(this, os, seg_flags);
+ break;
+ }
+ }
+
+ if (p == this->segment_list_.end()
+ || os->is_unique_segment())
{
Output_segment* oseg = this->make_output_segment(elfcpp::PT_LOAD,
seg_flags);
@@ -1777,6 +1837,14 @@ Layout::attach_allocated_section_to_segment(const Target* target,
oseg->add_output_section_to_load(this, os, seg_flags);
if (is_address_set)
oseg->set_addresses(addr, addr);
+ // Check if segment should be marked unique. For segments marked
+ // unique by linker plugins, set the new alignment if specified.
+ if (os->is_unique_segment())
+ {
+ oseg->set_is_unique_segment();
+ if (os->segment_alignment() != 0)
+ oseg->set_minimum_p_align(os->segment_alignment());
+ }
}
// If we see a loadable SHT_NOTE section, we create a PT_NOTE
@@ -3121,9 +3189,11 @@ Layout::segment_precedes(const Output_segment* seg1,
// We shouldn't get here--we shouldn't create segments which we
// can't distinguish. Unless of course we are using a weird linker
- // script or overlapping --section-start options.
+ // script or overlapping --section-start options. We could also get
+ // here if plugins want unique segments for subsets of sections.
gold_assert(this->script_options_->saw_phdrs_clause()
- || parameters->options().any_section_start());
+ || parameters->options().any_section_start()
+ || this->is_unique_segment_for_sections_specified());
return false;
}