2010-08-03 Ian Lance Taylor <iant@google.com>

PR 11805
	* layout.h (enum Output_section_order): Define.
	(class Layout): Update declarations.
	* layout.cc (Layout::get_output_section): Add order parameter.
	Remove is_interp, is_dynamic_linker_section, is_last_relro, and
	is_first_non_relro parameters.  Change all callers.
	(Layout::choose_output_section): Likewise.
	(Layout::add_output_section_data): Likewise.
	(Layout::make_output_section): Likewise.  Set order.
	(Layout::default_section_order): New function.
	(Layout::layout_eh_frame): Call add_output_section_to_nonload.
	* output.cc (Output_section::Output_section): Initialize order_.
	Don't initialize deleted fields.
	(Output_segment::Output_segment): Don't initialize deleted
	fields.
	(Output_segment::add_output_section_to_load): New function
	replacing add_output_section.  Change all callers to call this or
	add_output_section_to_nonload.
	(Output_segment::add_output_section_to_nonload): New function.
	(Output_segment::remove_output_section): Rewrite.
	(Output_segment::add_initial_output_data): Likewise.
	(Output_segment::has_any_data_sections): Likewise.
	(Output_segment::is_first_section_relro): Likewise.
	(Output_segment::maximum_alignment): Likewise.
	(Output_segment::has_dynamic_reloc): New function replacing
	dynamic_reloc_count.  Change all callers.
	(Output_segment::has_dynamic_reloc_list): New function replacing
	dynamic_reloc_count_list.  Change all callers.
	(Output_segment::set_section_addresses): Rewrite.
	(Output_segment::set_offset): Rewrite.
	(Output_segment::find_first_and_last_list): Remove.
	(Output_segment::set_tls_offsets): Rewrite.
	(Output_segment::first_section_load_address): Likewise.
	(Output_segment::output_section_count): Likewise.
	(Output_segment::section_with_lowest_load_address): Likewise.
	(Output_segment::write_section_headers): Likewise.
	(Output_segment::print_sections_to_map): Likewise.
	* output.h (class Output_data): Remove dynamic_reloc_count_
	field.  Add has_dynamic_reloc_ field.  Make bools into bitfields.
	(Output_data::add_dynamic_reloc): Rewrite.
	(Output_data::has_dynamic_reloc): New function.
	(Output_data::dynamic_reloc_count): Remove.
	(class Output_section): Add order_ field.  Remvoe is_relro_local_,
	is_last_relro_, is_first_non_relro_, is_interp_,
	is_dynamic_linker_section_ fields.  Add order and set_order
	functions.  Remove is_relro_local, set_is_relro_local,
	is_last_relro, set_is_last_relro, is_first_non_relro,
	set_is_first_non_relro functions, is_interp, set_is_interp,
	is_dynamic_linker_section, and set_is_dynamic_linker_section
	functions.
	(class Output_segment): Change Output_data_list from std::list to
	std:;vector.  Add output_lists_ field.  Remove output_data_ and
	output_bss_ fields.  Update declarations.
This commit is contained in:
Ian Lance Taylor
2010-08-03 14:07:13 +00:00
parent e4d9f07834
commit 22f0da72ea
13 changed files with 655 additions and 718 deletions

View File

@@ -286,6 +286,107 @@ class Kept_section
} u_;
};
// The ordering for output sections. This controls how output
// sections are ordered within a PT_LOAD output segment.
enum Output_section_order
{
// Unspecified. Used for non-load segments. Also used for the file
// and segment headers.
ORDER_INVALID,
// The PT_INTERP section should come first, so that the dynamic
// linker can pick it up quickly.
ORDER_INTERP,
// Loadable read-only note sections come next so that the PT_NOTE
// segment is on the first page of the executable.
ORDER_RO_NOTE,
// Put read-only sections used by the dynamic linker early in the
// executable to minimize paging.
ORDER_DYNAMIC_LINKER,
// Put reloc sections used by the dynamic linker after other
// sections used by the dynamic linker; otherwise, objcopy and strip
// get confused.
ORDER_DYNAMIC_RELOCS,
// Put the PLT reloc section after the other dynamic relocs;
// otherwise, prelink gets foncused.
ORDER_DYNAMIC_PLT_RELOCS,
// The .init section.
ORDER_INIT,
// The PLT.
ORDER_PLT,
// The regular text sections.
ORDER_TEXT,
// The .fini section.
ORDER_FINI,
// The read-only sections.
ORDER_READONLY,
// The exception frame sections.
ORDER_EHFRAME,
// The TLS sections come first in the data section.
ORDER_TLS_DATA,
ORDER_TLS_BSS,
// Local RELRO (read-only after relocation) sections come before
// non-local RELRO sections. This data will be fully resolved by
// the prelinker.
ORDER_RELRO_LOCAL,
// Non-local RELRO sections are grouped together after local RELRO
// sections. All RELRO sections must be adjacent so that they can
// all be put into a PT_GNU_RELRO segment.
ORDER_RELRO,
// We permit marking exactly one output section as the last RELRO
// section. We do this so that the read-only GOT can be adjacent to
// the writable GOT.
ORDER_RELRO_LAST,
// Similarly, we permit marking exactly one output section as the
// first non-RELRO section.
ORDER_NON_RELRO_FIRST,
// The regular data sections come after the RELRO sections.
ORDER_DATA,
// Large data sections normally go in large data segments.
ORDER_LARGE_DATA,
// Group writable notes so that we can have a single PT_NOTE
// segment.
ORDER_RW_NOTE,
// The small data sections must be at the end of the data sections,
// so that they can be adjacent to the small BSS sections.
ORDER_SMALL_DATA,
// The BSS sections start here.
// The small BSS sections must be at the start of the BSS sections,
// so that they can be adjacent to the small data sections.
ORDER_SMALL_BSS,
// The regular BSS sections.
ORDER_BSS,
// The large BSS sections come after the other BSS sections.
ORDER_LARGE_BSS,
// Maximum value.
ORDER_MAX
};
// This class handles the details of laying out input sections.
class Layout
@@ -371,18 +472,14 @@ class Layout
layout_gnu_stack(bool seen_gnu_stack, uint64_t gnu_stack_flags);
// Add an Output_section_data to the layout. This is used for
// special sections like the GOT section. IS_DYNAMIC_LINKER_SECTION
// is true for sections which are used by the dynamic linker, such
// as dynamic reloc sections. IS_RELRO is true for relro sections.
// IS_LAST_RELRO is true for the last relro section.
// IS_FIRST_NON_RELRO is true for the first section after the relro
// sections.
// special sections like the GOT section. ORDER is where the
// section should wind up in the output segment. IS_RELRO is true
// for relro sections.
Output_section*
add_output_section_data(const char* name, elfcpp::Elf_Word type,
elfcpp::Elf_Xword flags,
Output_section_data*, bool is_dynamic_linker_section,
bool is_relro, bool is_last_relro,
bool is_first_non_relro);
Output_section_data*, Output_section_order order,
bool is_relro);
// Increase the size of the relro segment by this much.
void
@@ -788,29 +885,29 @@ class Layout
Output_section*
get_output_section(const char* name, Stringpool::Key name_key,
elfcpp::Elf_Word type, elfcpp::Elf_Xword flags,
bool is_interp, bool is_dynamic_linker_section,
bool is_relro, bool is_last_relro,
bool is_first_non_relro);
Output_section_order order, bool is_relro);
// Choose the output section for NAME in RELOBJ.
Output_section*
choose_output_section(const Relobj* relobj, const char* name,
elfcpp::Elf_Word type, elfcpp::Elf_Xword flags,
bool is_input_section, bool is_interp,
bool is_dynamic_linker_section, bool is_relro,
bool is_last_relro, bool is_first_non_relro);
bool is_input_section, Output_section_order order,
bool is_relro);
// Create a new Output_section.
Output_section*
make_output_section(const char* name, elfcpp::Elf_Word type,
elfcpp::Elf_Xword flags, bool is_interp,
bool is_dynamic_linker_section, bool is_relro,
bool is_last_relro, bool is_first_non_relro);
elfcpp::Elf_Xword flags, Output_section_order order,
bool is_relro);
// Attach a section to a segment.
void
attach_section_to_segment(Output_section*);
// Get section order.
Output_section_order
default_section_order(Output_section*, bool is_relro_local);
// Attach an allocated section to a segment.
void
attach_allocated_section_to_segment(Output_section*);