forked from Imagelibrary/binutils-gdb
2010-04-09 Doug Kwan <dougkwan@google.com>
* layout.cc (Layout::choose_output_section): Handle script section types. (Layout::make_output_section_for_script): Add section type parameter. Handle script section types. * layout.h (Layout::make_output_section_for_script): Add section type parameter. * output.cc (Output_section::Output_section): Initialize data member is_noload_. (Output_section::do_reset_address_and_file_offset): Do not set address to 0 if section is a NOLOAD section. * output.h (Output_section::is_noload): New method. (Output_section::set_is_noload): Ditto. (Output_section::is_noload_): New data member. * script-c.h (Script_section_type): New enum type. (struct Parser_output_section_header): Add new file section_type. * script-sections.cc (Sections_element::output_section_name): Add parameter for returning script section type. (Output_section_definition::output_section_name): Ditto. (Output_section_definition::section_type)P; New method. (Output_section_definiton::script_section_type_name): Ditto. (Output_section_definition::script_section_type_): New data member. (Output_section_definition::Output_section_definition): Initialize data member Output_section_definition::script_section_type_. (Output_section_definition::create_sections): Pass script section type to Layout::make_output_section_for_script. (Output_section_definition::output_section_name): Return script section type to caller. (Output_section_definition::set_section_address): Do not advance dot value and load address if section type is NOLOAD. Set address of NOLOAD sections regardless of section flags. (Output_section_definition::print): Print section type if it is not SCRIPT_SECTION_TYPE_NONE. (Output_section_definition::section_type): New method. (Output_section_definition::script_section_type_name): Ditto. (Script_sections::output_section_name): Add new parameter PSECTION_TYPE for returning script section type. Pass it to section elements. Handle discard sections. (Sort_output_sections::operator()): Handle NOLOAD sections. * script-sections.h (Script_sections::Section_type): New enum type. (Script_sections::output_section_name): Add a new parameter for returning script section type. * script.cc (script_keyword_parsecodes): Add keywords COPY, DSECT, INFO and NOLOAD. * yyscript.y (union): Add new field SECTION_TYPE. (COPY, DSECT, INFO, NOLOAD): New tokens. (opt_address_and_section_type): Change type to output_section_header. (section_type): New non-terminal (section_header): Handle section type. (opt_address_and_section_type): Return section type value.
This commit is contained in:
@@ -502,13 +502,27 @@ Layout::choose_output_section(const Relobj* relobj, const char* name,
|
||||
Script_sections* ss = this->script_options_->script_sections();
|
||||
const char* file_name = relobj == NULL ? NULL : relobj->name().c_str();
|
||||
Output_section** output_section_slot;
|
||||
name = ss->output_section_name(file_name, name, &output_section_slot);
|
||||
Script_sections::Section_type script_section_type;
|
||||
name = ss->output_section_name(file_name, name, &output_section_slot,
|
||||
&script_section_type);
|
||||
if (name == NULL)
|
||||
{
|
||||
// The SECTIONS clause says to discard this input section.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// We can only handle script section types ST_NONE and ST_NOLOAD.
|
||||
switch (script_section_type)
|
||||
{
|
||||
case Script_sections::ST_NONE:
|
||||
break;
|
||||
case Script_sections::ST_NOLOAD:
|
||||
flags &= elfcpp::SHF_ALLOC;
|
||||
break;
|
||||
default:
|
||||
gold_unreachable();
|
||||
}
|
||||
|
||||
// If this is an orphan section--one not mentioned in the linker
|
||||
// script--then OUTPUT_SECTION_SLOT will be NULL, and we do the
|
||||
// default processing below.
|
||||
@@ -533,6 +547,25 @@ Layout::choose_output_section(const Relobj* relobj, const char* name,
|
||||
is_dynamic_linker_section, is_relro,
|
||||
is_last_relro, is_first_non_relro);
|
||||
os->set_found_in_sections_clause();
|
||||
|
||||
// Special handling for NOLOAD sections.
|
||||
if (script_section_type == Script_sections::ST_NOLOAD)
|
||||
{
|
||||
os->set_is_noload();
|
||||
|
||||
// The constructor of Output_section sets addresses of non-ALLOC
|
||||
// sections to 0 by default. We don't want that for NOLOAD
|
||||
// sections even if they have no SHF_ALLOC flag.
|
||||
if ((os->flags() & elfcpp::SHF_ALLOC) == 0
|
||||
&& os->is_address_valid())
|
||||
{
|
||||
gold_assert(os->address() == 0
|
||||
&& !os->is_offset_valid()
|
||||
&& !os->is_data_size_valid());
|
||||
os->reset_address_and_file_offset();
|
||||
}
|
||||
}
|
||||
|
||||
*output_section_slot = os;
|
||||
return os;
|
||||
}
|
||||
@@ -1157,13 +1190,20 @@ Layout::attach_allocated_section_to_segment(Output_section* os)
|
||||
// Make an output section for a script.
|
||||
|
||||
Output_section*
|
||||
Layout::make_output_section_for_script(const char* name)
|
||||
Layout::make_output_section_for_script(
|
||||
const char* name,
|
||||
Script_sections::Section_type section_type)
|
||||
{
|
||||
name = this->namepool_.add(name, false, NULL);
|
||||
elfcpp::Elf_Xword sh_flags = elfcpp::SHF_ALLOC;
|
||||
if (section_type == Script_sections::ST_NOLOAD)
|
||||
sh_flags = 0;
|
||||
Output_section* os = this->make_output_section(name, elfcpp::SHT_PROGBITS,
|
||||
elfcpp::SHF_ALLOC, false,
|
||||
sh_flags, false,
|
||||
false, false, false, false);
|
||||
os->set_found_in_sections_clause();
|
||||
if (section_type == Script_sections::ST_NOLOAD)
|
||||
os->set_is_noload();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user