// layout.h -- lay out output file sections for gold -*- C++ -*-
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
+// Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
class Output_reduced_debug_abbrev_section;
class Output_reduced_debug_info_section;
class Eh_frame;
+class Gdb_index;
class Target;
struct Timespec;
class Free_list
{
public:
+ struct Free_list_node
+ {
+ Free_list_node(off_t start, off_t end)
+ : start_(start), end_(end)
+ { }
+ off_t start_;
+ off_t end_;
+ };
+ typedef std::list<Free_list_node>::const_iterator Const_iterator;
+
Free_list()
- : list_(), last_remove_(list_.begin()), extend_(false), length_(0)
+ : list_(), last_remove_(list_.begin()), extend_(false), length_(0),
+ min_hole_(0)
{ }
+ // Initialize the free list for a section of length LEN.
+ // If EXTEND is true, free space may be allocated past the end.
void
init(off_t len, bool extend);
+ // Set the minimum hole size that is allowed when allocating
+ // from the free list.
+ void
+ set_min_hole_size(off_t min_hole)
+ { this->min_hole_ = min_hole; }
+
+ // Remove a chunk from the free list.
void
remove(off_t start, off_t end);
+ // Allocate a chunk of space from the free list of length LEN,
+ // with alignment ALIGN, and minimum offset MINOFF.
off_t
allocate(off_t len, uint64_t align, off_t minoff);
+ // Return an iterator for the beginning of the free list.
+ Const_iterator
+ begin() const
+ { return this->list_.begin(); }
+
+ // Return an iterator for the end of the free list.
+ Const_iterator
+ end() const
+ { return this->list_.end(); }
+
+ // Dump the free list (for debugging).
void
dump();
+ // Print usage statistics.
static void
print_stats();
private:
- struct Free_list_node
- {
- Free_list_node(off_t start, off_t end)
- : start_(start), end_(end)
- { }
- off_t start_;
- off_t end_;
- };
typedef std::list<Free_list_node>::iterator Iterator;
// The free list.
// The total length of the section, segment, or file.
off_t length_;
+ // The minimum hole size allowed. When allocating from the free list,
+ // we must not leave a hole smaller than this.
+ off_t min_hole_;
+
// Statistics:
// The total number of free lists used.
static unsigned int num_lists;
Layout_task_runner(const General_options& options,
const Input_objects* input_objects,
Symbol_table* symtab,
- Target* target,
+ Target* target,
Layout* layout,
Mapfile* mapfile)
: options_(options), input_objects_(input_objects), symtab_(symtab),
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_; }
+
+ void
+ set_section_ordering_specified()
+ { this->section_ordering_specified_ = true; }
+
// For incremental updates, allocate a block of memory from the
// free list. Find a block starting at or after MINOFF.
off_t
unsigned int
find_section_order_index(const std::string&);
+ // Read the sequence of input sections from the file specified with
+ // linker option --section-ordering-file.
void
read_layout_from_file();
size_t cie_length, const unsigned char* fde_data,
size_t fde_length);
+ // Scan a .debug_info or .debug_types section, and add summary
+ // information to the .gdb_index section.
+ template<int size, bool big_endian>
+ void
+ add_to_gdb_index(bool is_type_unit,
+ Sized_relobj<size, big_endian>* object,
+ const unsigned char* symbols,
+ off_t symbols_size,
+ unsigned int shndx,
+ unsigned int reloc_shndx,
+ unsigned int reloc_type);
+
// Handle a GNU stack note. This is called once per input object
// file. SEEN_GNU_STACK is true if the object file has a
// .note.GNU-stack section. GNU_STACK_FLAGS is the section flags
dynpool() const
{ return &this->dynpool_; }
+ // Return the .dynamic output section. This is only valid after the
+ // layout has been finalized.
+ Output_section*
+ dynamic_section() const
+ { return this->dynamic_section_; }
+
// Return the symtab_xindex section used to hold large section
// indexes for the normal symbol table.
Output_symtab_xindex*
{
// Debugging sections can only be recognized by name.
return (strncmp(name, ".debug", sizeof(".debug") - 1) == 0
- || strncmp(name, ".zdebug", sizeof(".zdebug") - 1) == 0
- || strncmp(name, ".gnu.linkonce.wi.",
- sizeof(".gnu.linkonce.wi.") - 1) == 0
- || strncmp(name, ".line", sizeof(".line") - 1) == 0
- || strncmp(name, ".stab", sizeof(".stab") - 1) == 0);
+ || strncmp(name, ".zdebug", sizeof(".zdebug") - 1) == 0
+ || strncmp(name, ".gnu.linkonce.wi.",
+ sizeof(".gnu.linkonce.wi.") - 1) == 0
+ || strncmp(name, ".line", sizeof(".line") - 1) == 0
+ || strncmp(name, ".stab", sizeof(".stab") - 1) == 0);
}
// Return true if RELOBJ is an input file whose base name matches
// *KEPT_SECTION is set to the internal copy and the function return
// false.
bool
- find_or_add_kept_section(const std::string& name, Relobj* object,
+ find_or_add_kept_section(const std::string& name, Relobj* object,
unsigned int shndx, bool is_comdat,
bool is_group_name, Kept_section** kept_section);
// Attach sections to segments.
void
- attach_sections_to_segments();
+ attach_sections_to_segments(const Target*);
// For relaxation clean up, we need to know output section data created
// from a linker script.
// Find the first read-only PT_LOAD segment, creating one if
// necessary.
Output_segment*
- find_first_load_seg();
+ find_first_load_seg(const Target*);
// Count the local symbols in the regular symbol table and the dynamic
// symbol table, and build the respective string pools.
// Attach a section to a segment.
void
- attach_section_to_segment(Output_section*);
+ attach_section_to_segment(const Target*, Output_section*);
// Get section order.
Output_section_order
// Attach an allocated section to a segment.
void
- attach_allocated_section_to_segment(Output_section*);
+ attach_allocated_section_to_segment(const Target*, Output_section*);
// Make the .eh_frame section.
Output_section*
bool
segment_precedes(const Output_segment* seg1, const Output_segment* seg2);
- // Use to save and restore segments during relaxation.
+ // Use to save and restore segments during relaxation.
typedef Unordered_map<const Output_segment*, const Output_segment*>
Segment_states;
Relaxation_debug_check()
: section_infos_()
{ }
-
+
// Check that sections and special data are in reset states.
void
check_output_data_for_reset_values(const Layout::Section_list&,
const Layout::Data_list&);
-
+
// Record information of a section list.
void
read_sections(const Layout::Section_list&);
// Verify a section list with recorded information.
void
verify_sections(const Layout::Section_list&);
-
+
private:
// Information we care about a section.
struct Section_info
bool added_eh_frame_data_;
// The exception frame header output section if there is one.
Output_section* eh_frame_hdr_section_;
+ // The data for the .gdb_index section.
+ Gdb_index* gdb_index_data_;
// The space for the build ID checksum if there is one.
Output_section_data* build_id_note_;
// The output section containing dwarf abbreviations
bool resized_signatures_;
// Whether we have created a .stab*str output section.
bool have_stabstr_section_;
+ // True if the input sections in the output sections should be sorted
+ // as specified in a section ordering file.
+ bool section_ordering_specified_;
// In incremental build, holds information check the inputs and build the
// .gnu_incremental_inputs section.
Incremental_inputs* incremental_inputs_;
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.