1 // layout.h -- lay out output file sections for gold -*- C++ -*-
12 #include "workqueue.h"
14 #include "stringpool.h"
22 // This Task handles mapping the input sections to output sections and
23 // laying them out in memory.
25 class Layout_task
: public Task
28 // OPTIONS is the command line options, INPUT_OBJECTS is the list of
29 // input objects, THIS_BLOCKER is a token which blocks this task
30 // from executing until all the input symbols have been read.
31 Layout_task(const General_options
& options
, const Object_list
* input_objects
,
32 Task_token
* this_blocker
)
33 : options_(options
), input_objects_(input_objects
),
34 this_blocker_(this_blocker
)
39 // The standard Task methods.
42 is_runnable(Workqueue
*);
51 Layout_task(const Layout_task
&);
52 Layout_task
& operator=(const Layout_task
&);
54 const General_options
& options_
;
55 const Object_list
* input_objects_
;
56 Task_token
* this_blocker_
;
59 // This class handles the details of laying out input sections.
64 Layout(const General_options
& options
)
65 : options_(options
), namepool_(), signatures_(),
66 section_name_map_(), segment_list_()
69 // Given an input section named NAME with data in SHDR from the
70 // object file OBJECT, return the output section where this input
71 // section should go. Set *OFFSET to the offset within the output
73 template<int size
, bool big_endian
>
75 layout(Object
*object
, const char* name
,
76 const elfcpp::Shdr
<size
, big_endian
>& shdr
, off_t
* offset
);
78 // Return whether a section is a .gnu.linkonce section, given the
81 is_linkonce(const char* name
)
82 { return strncmp(name
, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; }
84 // Record the signature of a comdat section, and return whether to
85 // include it in the link. The GROUP parameter is true for a
86 // section group signature, false for a signature derived from a
87 // .gnu.linkonce section.
89 add_comdat(const char*, bool group
);
92 Layout(const Layout
&);
93 Layout
& operator=(const Layout
&);
95 // Mapping from .gnu.linkonce section names to output section names.
96 struct Linkonce_mapping
102 static const Linkonce_mapping linkonce_mapping
[];
103 static const int linkonce_mapping_count
;
105 // Return whether to include this section in the link.
106 template<int size
, bool big_endian
>
108 include_section(Object
* object
, const char* name
,
109 const elfcpp::Shdr
<size
, big_endian
>&);
111 // Return the output section name to use for a linkonce section
114 linkonce_output_name(const char* name
);
116 // Create a new Output_section.
118 make_output_section(const char* name
, elfcpp::Elf_Word type
,
119 elfcpp::Elf_Xword flags
);
121 // Return whether SEG1 comes before SEG2 in the output file.
123 Layout::segment_precedes(const Output_segment
* seg1
,
124 const Output_segment
* seg2
);
126 // Map from section flags to segment flags.
127 static elfcpp::Elf_Word
128 section_flags_to_segment(elfcpp::Elf_Xword flags
);
130 // A mapping used for group signatures.
131 typedef Unordered_map
<std::string
, bool> Signatures
;
133 // Mapping from input section name/type/flags to output section. We
134 // use canonicalized strings here.
136 typedef std::pair
<const char*,
137 std::pair
<elfcpp::Elf_Word
, elfcpp::Elf_Xword
> > Key
;
142 operator()(const Key
& k
) const;
145 typedef Unordered_map
<Key
, Output_section
*, Hash_key
> Section_name_map
;
147 // A comparison class for segments.
149 struct Compare_segments
152 operator()(const Output_segment
* seg1
, const Output_segment
* seg2
)
153 { return Layout::segment_precedes(seg1
, seg2
); }
156 // The list of segments.
158 typedef std::list
<Output_segment
*> Segment_list
;
160 // The list of sections not attached to a segment.
162 typedef std::list
<Output_section
*> Section_list
;
164 // A reference to the options on the command line.
165 const General_options
& options_
;
166 // The output section names.
167 Stringpool namepool_
;
168 // The list of group sections and linkonce sections which we have seen.
169 Signatures signatures_
;
170 // The mapping from input section name/type/flags to output sections.
171 Section_name_map section_name_map_
;
172 // The list of output segments.
173 Segment_list segment_list_
;
174 // The list of output sections which are not attached to any output
176 Section_list section_list_
;
179 } // End namespace gold.
181 #endif // !defined(GOLD_LAYOUT_H)