Commit | Line | Data |
---|---|---|
a2fb1b05 ILT |
1 | // layout.h -- lay out output file sections for gold -*- C++ -*- |
2 | ||
8a4c0b0d | 3 | // Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | // Written by Ian Lance Taylor <iant@google.com>. |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
a2fb1b05 ILT |
23 | #ifndef GOLD_LAYOUT_H |
24 | #define GOLD_LAYOUT_H | |
25 | ||
e94cf127 | 26 | #include <cstring> |
a2fb1b05 | 27 | #include <list> |
1ef4d87f | 28 | #include <map> |
a2fb1b05 ILT |
29 | #include <string> |
30 | #include <utility> | |
31 | #include <vector> | |
32 | ||
e5756efb | 33 | #include "script.h" |
a2fb1b05 ILT |
34 | #include "workqueue.h" |
35 | #include "object.h" | |
14b31740 | 36 | #include "dynobj.h" |
a2fb1b05 ILT |
37 | #include "stringpool.h" |
38 | ||
39 | namespace gold | |
40 | { | |
41 | ||
ead1e424 | 42 | class General_options; |
3ce2c28e | 43 | class Incremental_inputs; |
54dc6425 | 44 | class Input_objects; |
7d9e3d98 | 45 | class Mapfile; |
75f65a3e | 46 | class Symbol_table; |
ead1e424 | 47 | class Output_section_data; |
a2fb1b05 | 48 | class Output_section; |
75f65a3e | 49 | class Output_section_headers; |
20e6d0d6 DK |
50 | class Output_segment_headers; |
51 | class Output_file_header; | |
a2fb1b05 | 52 | class Output_segment; |
54dc6425 | 53 | class Output_data; |
3a44184e | 54 | class Output_data_reloc_generic; |
a3ad94ed | 55 | class Output_data_dynamic; |
d491d34e | 56 | class Output_symtab_xindex; |
62b01cb5 ILT |
57 | class Output_reduced_debug_abbrev_section; |
58 | class Output_reduced_debug_info_section; | |
730cdc88 | 59 | class Eh_frame; |
61ba1cf9 | 60 | class Target; |
a2fb1b05 | 61 | |
a2e47362 CC |
62 | // Return TRUE if SECNAME is the name of a compressed debug section. |
63 | extern bool | |
64 | is_compressed_debug_section(const char* secname); | |
65 | ||
92e059d8 ILT |
66 | // This task function handles mapping the input sections to output |
67 | // sections and laying them out in memory. | |
a2fb1b05 | 68 | |
92e059d8 | 69 | class Layout_task_runner : public Task_function_runner |
a2fb1b05 ILT |
70 | { |
71 | public: | |
72 | // OPTIONS is the command line options, INPUT_OBJECTS is the list of | |
92e059d8 ILT |
73 | // input objects, SYMTAB is the symbol table, LAYOUT is the layout |
74 | // object. | |
75 | Layout_task_runner(const General_options& options, | |
76 | const Input_objects* input_objects, | |
77 | Symbol_table* symtab, | |
8851ecca | 78 | Target* target, |
7d9e3d98 ILT |
79 | Layout* layout, |
80 | Mapfile* mapfile) | |
75f65a3e | 81 | : options_(options), input_objects_(input_objects), symtab_(symtab), |
7d9e3d98 | 82 | target_(target), layout_(layout), mapfile_(mapfile) |
a2fb1b05 ILT |
83 | { } |
84 | ||
92e059d8 | 85 | // Run the operation. |
a2fb1b05 | 86 | void |
17a1d0a9 | 87 | run(Workqueue*, const Task*); |
a2fb1b05 ILT |
88 | |
89 | private: | |
92e059d8 ILT |
90 | Layout_task_runner(const Layout_task_runner&); |
91 | Layout_task_runner& operator=(const Layout_task_runner&); | |
a2fb1b05 ILT |
92 | |
93 | const General_options& options_; | |
54dc6425 | 94 | const Input_objects* input_objects_; |
75f65a3e | 95 | Symbol_table* symtab_; |
8851ecca | 96 | Target* target_; |
12e14209 | 97 | Layout* layout_; |
7d9e3d98 | 98 | Mapfile* mapfile_; |
a2fb1b05 ILT |
99 | }; |
100 | ||
1ef4d87f ILT |
101 | // This class holds information about the comdat group or |
102 | // .gnu.linkonce section that will be kept for a given signature. | |
8a4c0b0d | 103 | |
1ef4d87f | 104 | class Kept_section |
8a4c0b0d | 105 | { |
1ef4d87f ILT |
106 | private: |
107 | // For a comdat group, we build a mapping from the name of each | |
108 | // section in the group to the section index and the size in object. | |
109 | // When we discard a group in some other object file, we use this | |
110 | // map to figure out which kept section the discarded section is | |
111 | // associated with. We then use that mapping when processing relocs | |
112 | // against discarded sections. | |
113 | struct Comdat_section_info | |
114 | { | |
115 | // The section index. | |
116 | unsigned int shndx; | |
117 | // The section size. | |
118 | uint64_t size; | |
119 | ||
120 | Comdat_section_info(unsigned int a_shndx, uint64_t a_size) | |
121 | : shndx(a_shndx), size(a_size) | |
122 | { } | |
123 | }; | |
124 | ||
125 | // Most comdat groups have only one or two sections, so we use a | |
126 | // std::map rather than an Unordered_map to optimize for that case | |
127 | // without paying too heavily for groups with more sections. | |
128 | typedef std::map<std::string, Comdat_section_info> Comdat_group; | |
129 | ||
130 | public: | |
8a4c0b0d | 131 | Kept_section() |
1ef4d87f ILT |
132 | : object_(NULL), shndx_(0), is_comdat_(false), is_group_name_(false) |
133 | { this->u_.linkonce_size = 0; } | |
134 | ||
135 | // We need to support copies for the signature map in the Layout | |
136 | // object, but we should never copy an object after it has been | |
137 | // marked as a comdat section. | |
138 | Kept_section(const Kept_section& k) | |
139 | : object_(k.object_), shndx_(k.shndx_), is_comdat_(false), | |
140 | is_group_name_(k.is_group_name_) | |
141 | { | |
142 | gold_assert(!k.is_comdat_); | |
143 | this->u_.linkonce_size = 0; | |
144 | } | |
145 | ||
146 | ~Kept_section() | |
147 | { | |
148 | if (this->is_comdat_) | |
149 | delete this->u_.group_sections; | |
150 | } | |
151 | ||
152 | // The object where this section lives. | |
153 | Relobj* | |
154 | object() const | |
155 | { return this->object_; } | |
8a4c0b0d | 156 | |
1ef4d87f ILT |
157 | // Set the object. |
158 | void | |
2ea97941 | 159 | set_object(Relobj* object) |
1ef4d87f ILT |
160 | { |
161 | gold_assert(this->object_ == NULL); | |
2ea97941 | 162 | this->object_ = object; |
1ef4d87f ILT |
163 | } |
164 | ||
165 | // The section index. | |
166 | unsigned int | |
167 | shndx() const | |
168 | { return this->shndx_; } | |
169 | ||
170 | // Set the section index. | |
171 | void | |
2ea97941 | 172 | set_shndx(unsigned int shndx) |
1ef4d87f ILT |
173 | { |
174 | gold_assert(this->shndx_ == 0); | |
2ea97941 | 175 | this->shndx_ = shndx; |
1ef4d87f ILT |
176 | } |
177 | ||
178 | // Whether this is a comdat group. | |
179 | bool | |
180 | is_comdat() const | |
181 | { return this->is_comdat_; } | |
182 | ||
183 | // Set that this is a comdat group. | |
184 | void | |
185 | set_is_comdat() | |
186 | { | |
187 | gold_assert(!this->is_comdat_); | |
188 | this->is_comdat_ = true; | |
189 | this->u_.group_sections = new Comdat_group(); | |
190 | } | |
8a4c0b0d | 191 | |
1ef4d87f ILT |
192 | // Whether this is associated with the name of a group or section |
193 | // rather than the symbol name derived from a linkonce section. | |
194 | bool | |
195 | is_group_name() const | |
196 | { return this->is_group_name_; } | |
197 | ||
198 | // Note that this represents a comdat group rather than a single | |
199 | // linkonce section. | |
200 | void | |
201 | set_is_group_name() | |
202 | { this->is_group_name_ = true; } | |
203 | ||
204 | // Add a section to the group list. | |
205 | void | |
2ea97941 | 206 | add_comdat_section(const std::string& name, unsigned int shndx, |
1ef4d87f ILT |
207 | uint64_t size) |
208 | { | |
209 | gold_assert(this->is_comdat_); | |
2ea97941 | 210 | Comdat_section_info sinfo(shndx, size); |
1ef4d87f ILT |
211 | this->u_.group_sections->insert(std::make_pair(name, sinfo)); |
212 | } | |
213 | ||
214 | // Look for a section name in the group list, and return whether it | |
215 | // was found. If found, returns the section index and size. | |
216 | bool | |
217 | find_comdat_section(const std::string& name, unsigned int *pshndx, | |
218 | uint64_t *psize) const | |
219 | { | |
220 | gold_assert(this->is_comdat_); | |
221 | Comdat_group::const_iterator p = this->u_.group_sections->find(name); | |
222 | if (p == this->u_.group_sections->end()) | |
223 | return false; | |
224 | *pshndx = p->second.shndx; | |
225 | *psize = p->second.size; | |
226 | return true; | |
227 | } | |
228 | ||
229 | // If there is only one section in the group list, return true, and | |
230 | // return the section index and size. | |
231 | bool | |
232 | find_single_comdat_section(unsigned int *pshndx, uint64_t *psize) const | |
233 | { | |
234 | gold_assert(this->is_comdat_); | |
235 | if (this->u_.group_sections->size() != 1) | |
236 | return false; | |
237 | Comdat_group::const_iterator p = this->u_.group_sections->begin(); | |
238 | *pshndx = p->second.shndx; | |
239 | *psize = p->second.size; | |
240 | return true; | |
241 | } | |
242 | ||
243 | // Return the size of a linkonce section. | |
244 | uint64_t | |
245 | linkonce_size() const | |
246 | { | |
247 | gold_assert(!this->is_comdat_); | |
248 | return this->u_.linkonce_size; | |
249 | } | |
250 | ||
251 | // Set the size of a linkonce section. | |
252 | void | |
253 | set_linkonce_size(uint64_t size) | |
254 | { | |
255 | gold_assert(!this->is_comdat_); | |
256 | this->u_.linkonce_size = size; | |
257 | } | |
258 | ||
259 | private: | |
260 | // No assignment. | |
261 | Kept_section& operator=(const Kept_section&); | |
262 | ||
263 | // The object containing the comdat group or .gnu.linkonce section. | |
264 | Relobj* object_; | |
265 | // Index of the group section for comdats and the section itself for | |
8a4c0b0d | 266 | // .gnu.linkonce. |
1ef4d87f ILT |
267 | unsigned int shndx_; |
268 | // True if this is for a comdat group rather than a .gnu.linkonce | |
269 | // section. | |
270 | bool is_comdat_; | |
8a4c0b0d ILT |
271 | // The Kept_sections are values of a mapping, that maps names to |
272 | // them. This field is true if this struct is associated with the | |
273 | // name of a comdat or .gnu.linkonce, false if it is associated with | |
274 | // the name of a symbol obtained from the .gnu.linkonce.* name | |
275 | // through some heuristics. | |
1ef4d87f ILT |
276 | bool is_group_name_; |
277 | union | |
278 | { | |
279 | // If the is_comdat_ field is true, this holds a map from names of | |
280 | // the sections in the group to section indexes in object_ and to | |
281 | // section sizes. | |
282 | Comdat_group* group_sections; | |
283 | // If the is_comdat_ field is false, this holds the size of the | |
284 | // single section. | |
285 | uint64_t linkonce_size; | |
286 | } u_; | |
8a4c0b0d ILT |
287 | }; |
288 | ||
a2fb1b05 ILT |
289 | // This class handles the details of laying out input sections. |
290 | ||
291 | class Layout | |
292 | { | |
293 | public: | |
e55bde5e | 294 | Layout(int number_of_input_files, Script_options*); |
54dc6425 | 295 | |
20e6d0d6 DK |
296 | ~Layout() |
297 | { | |
298 | delete this->relaxation_debug_check_; | |
299 | delete this->segment_states_; | |
300 | } | |
301 | ||
ead1e424 ILT |
302 | // Given an input section SHNDX, named NAME, with data in SHDR, from |
303 | // the object file OBJECT, return the output section where this | |
730cdc88 ILT |
304 | // input section should go. RELOC_SHNDX is the index of a |
305 | // relocation section which applies to this section, or 0 if none, | |
306 | // or -1U if more than one. RELOC_TYPE is the type of the | |
307 | // relocation section if there is one. Set *OFFSET to the offset | |
308 | // within the output section. | |
a2fb1b05 ILT |
309 | template<int size, bool big_endian> |
310 | Output_section* | |
730cdc88 ILT |
311 | layout(Sized_relobj<size, big_endian> *object, unsigned int shndx, |
312 | const char* name, const elfcpp::Shdr<size, big_endian>& shdr, | |
313 | unsigned int reloc_shndx, unsigned int reloc_type, off_t* offset); | |
314 | ||
6e9ba2ca ST |
315 | unsigned int |
316 | find_section_order_index(const std::string&); | |
317 | ||
318 | void | |
319 | read_layout_from_file(); | |
320 | ||
6a74a719 ILT |
321 | // Layout an input reloc section when doing a relocatable link. The |
322 | // section is RELOC_SHNDX in OBJECT, with data in SHDR. | |
323 | // DATA_SECTION is the reloc section to which it refers. RR is the | |
324 | // relocatable information. | |
325 | template<int size, bool big_endian> | |
326 | Output_section* | |
327 | layout_reloc(Sized_relobj<size, big_endian>* object, | |
328 | unsigned int reloc_shndx, | |
329 | const elfcpp::Shdr<size, big_endian>& shdr, | |
330 | Output_section* data_section, | |
331 | Relocatable_relocs* rr); | |
332 | ||
333 | // Layout a group section when doing a relocatable link. | |
334 | template<int size, bool big_endian> | |
335 | void | |
336 | layout_group(Symbol_table* symtab, | |
337 | Sized_relobj<size, big_endian>* object, | |
338 | unsigned int group_shndx, | |
339 | const char* group_section_name, | |
340 | const char* signature, | |
341 | const elfcpp::Shdr<size, big_endian>& shdr, | |
8825ac63 ILT |
342 | elfcpp::Elf_Word flags, |
343 | std::vector<unsigned int>* shndxes); | |
6a74a719 | 344 | |
730cdc88 ILT |
345 | // Like layout, only for exception frame sections. OBJECT is an |
346 | // object file. SYMBOLS is the contents of the symbol table | |
347 | // section, with size SYMBOLS_SIZE. SYMBOL_NAMES is the contents of | |
348 | // the symbol name section, with size SYMBOL_NAMES_SIZE. SHNDX is a | |
349 | // .eh_frame section in OBJECT. SHDR is the section header. | |
350 | // RELOC_SHNDX is the index of a relocation section which applies to | |
351 | // this section, or 0 if none, or -1U if more than one. RELOC_TYPE | |
352 | // is the type of the relocation section if there is one. This | |
353 | // returns the output section, and sets *OFFSET to the offset. | |
354 | template<int size, bool big_endian> | |
355 | Output_section* | |
356 | layout_eh_frame(Sized_relobj<size, big_endian>* object, | |
357 | const unsigned char* symbols, | |
358 | off_t symbols_size, | |
359 | const unsigned char* symbol_names, | |
360 | off_t symbol_names_size, | |
361 | unsigned int shndx, | |
362 | const elfcpp::Shdr<size, big_endian>& shdr, | |
363 | unsigned int reloc_shndx, unsigned int reloc_type, | |
364 | off_t* offset); | |
a2fb1b05 | 365 | |
35cdfc9a ILT |
366 | // Handle a GNU stack note. This is called once per input object |
367 | // file. SEEN_GNU_STACK is true if the object file has a | |
368 | // .note.GNU-stack section. GNU_STACK_FLAGS is the section flags | |
369 | // from that section if there was one. | |
370 | void | |
371 | layout_gnu_stack(bool seen_gnu_stack, uint64_t gnu_stack_flags); | |
372 | ||
ead1e424 | 373 | // Add an Output_section_data to the layout. This is used for |
f5c870d2 ILT |
374 | // special sections like the GOT section. IS_DYNAMIC_LINKER_SECTION |
375 | // is true for sections which are used by the dynamic linker, such | |
1a2dff53 ILT |
376 | // as dynamic reloc sections. IS_RELRO is true for relro sections. |
377 | // IS_LAST_RELRO is true for the last relro section. | |
378 | // IS_FIRST_NON_RELRO is true for the first section after the relro | |
379 | // sections. | |
9f1d377b | 380 | Output_section* |
ead1e424 ILT |
381 | add_output_section_data(const char* name, elfcpp::Elf_Word type, |
382 | elfcpp::Elf_Xword flags, | |
1a2dff53 ILT |
383 | Output_section_data*, bool is_dynamic_linker_section, |
384 | bool is_relro, bool is_last_relro, | |
385 | bool is_first_non_relro); | |
386 | ||
387 | // Increase the size of the relro segment by this much. | |
388 | void | |
389 | increase_relro(unsigned int s) | |
390 | { this->increase_relro_ += s; } | |
ead1e424 | 391 | |
a3ad94ed ILT |
392 | // Create dynamic sections if necessary. |
393 | void | |
9b07f471 | 394 | create_initial_dynamic_sections(Symbol_table*); |
a3ad94ed | 395 | |
bfd58944 ILT |
396 | // Define __start and __stop symbols for output sections. |
397 | void | |
9b07f471 | 398 | define_section_symbols(Symbol_table*); |
bfd58944 | 399 | |
9c547ec3 ILT |
400 | // Create automatic note sections. |
401 | void | |
402 | create_notes(); | |
403 | ||
919ed24c ILT |
404 | // Create sections for linker scripts. |
405 | void | |
406 | create_script_sections() | |
407 | { this->script_options_->create_script_sections(this); } | |
408 | ||
e5756efb ILT |
409 | // Define symbols from any linker script. |
410 | void | |
9b07f471 ILT |
411 | define_script_symbols(Symbol_table* symtab) |
412 | { this->script_options_->add_symbols_to_table(symtab); } | |
e5756efb | 413 | |
755ab8af ILT |
414 | // Define symbols for group signatures. |
415 | void | |
416 | define_group_signatures(Symbol_table*); | |
417 | ||
61ba1cf9 ILT |
418 | // Return the Stringpool used for symbol names. |
419 | const Stringpool* | |
420 | sympool() const | |
421 | { return &this->sympool_; } | |
422 | ||
16649710 ILT |
423 | // Return the Stringpool used for dynamic symbol names and dynamic |
424 | // tags. | |
425 | const Stringpool* | |
426 | dynpool() const | |
427 | { return &this->dynpool_; } | |
428 | ||
d491d34e ILT |
429 | // Return the symtab_xindex section used to hold large section |
430 | // indexes for the normal symbol table. | |
431 | Output_symtab_xindex* | |
432 | symtab_xindex() const | |
433 | { return this->symtab_xindex_; } | |
434 | ||
435 | // Return the dynsym_xindex section used to hold large section | |
436 | // indexes for the dynamic symbol table. | |
437 | Output_symtab_xindex* | |
438 | dynsym_xindex() const | |
439 | { return this->dynsym_xindex_; } | |
440 | ||
a2fb1b05 ILT |
441 | // Return whether a section is a .gnu.linkonce section, given the |
442 | // section name. | |
443 | static inline bool | |
444 | is_linkonce(const char* name) | |
445 | { return strncmp(name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; } | |
446 | ||
d7bb5745 ILT |
447 | // Whether we have added an input section. |
448 | bool | |
449 | have_added_input_section() const | |
450 | { return this->have_added_input_section_; } | |
451 | ||
e94cf127 CC |
452 | // Return true if a section is a debugging section. |
453 | static inline bool | |
454 | is_debug_info_section(const char* name) | |
455 | { | |
456 | // Debugging sections can only be recognized by name. | |
457 | return (strncmp(name, ".debug", sizeof(".debug") - 1) == 0 | |
a2e47362 | 458 | || strncmp(name, ".zdebug", sizeof(".zdebug") - 1) == 0 |
8a4c0b0d | 459 | || strncmp(name, ".gnu.linkonce.wi.", |
e94cf127 CC |
460 | sizeof(".gnu.linkonce.wi.") - 1) == 0 |
461 | || strncmp(name, ".line", sizeof(".line") - 1) == 0 | |
462 | || strncmp(name, ".stab", sizeof(".stab") - 1) == 0); | |
463 | } | |
464 | ||
8a4c0b0d ILT |
465 | // Check if a comdat group or .gnu.linkonce section with the given |
466 | // NAME is selected for the link. If there is already a section, | |
467 | // *KEPT_SECTION is set to point to the signature and the function | |
1ef4d87f ILT |
468 | // returns false. Otherwise, OBJECT, SHNDX,IS_COMDAT, and |
469 | // IS_GROUP_NAME are recorded for this NAME in the layout object, | |
470 | // *KEPT_SECTION is set to the internal copy and the function return | |
471 | // false. | |
a2fb1b05 | 472 | bool |
1ef4d87f ILT |
473 | find_or_add_kept_section(const std::string& name, Relobj* object, |
474 | unsigned int shndx, bool is_comdat, | |
475 | bool is_group_name, Kept_section** kept_section); | |
a2fb1b05 | 476 | |
54dc6425 | 477 | // Finalize the layout after all the input sections have been added. |
75f65a3e | 478 | off_t |
8851ecca | 479 | finalize(const Input_objects*, Symbol_table*, Target*, const Task*); |
17a1d0a9 ILT |
480 | |
481 | // Return whether any sections require postprocessing. | |
482 | bool | |
483 | any_postprocessing_sections() const | |
484 | { return this->any_postprocessing_sections_; } | |
54dc6425 | 485 | |
e44fcf3b ILT |
486 | // Return the size of the output file. |
487 | off_t | |
488 | output_file_size() const | |
489 | { return this->output_file_size_; } | |
490 | ||
16649710 ILT |
491 | // Return the TLS segment. This will return NULL if there isn't |
492 | // one. | |
92e059d8 ILT |
493 | Output_segment* |
494 | tls_segment() const | |
495 | { return this->tls_segment_; } | |
496 | ||
16649710 ILT |
497 | // Return the normal symbol table. |
498 | Output_section* | |
499 | symtab_section() const | |
500 | { | |
501 | gold_assert(this->symtab_section_ != NULL); | |
502 | return this->symtab_section_; | |
503 | } | |
504 | ||
505 | // Return the dynamic symbol table. | |
506 | Output_section* | |
507 | dynsym_section() const | |
508 | { | |
509 | gold_assert(this->dynsym_section_ != NULL); | |
510 | return this->dynsym_section_; | |
511 | } | |
512 | ||
513 | // Return the dynamic tags. | |
514 | Output_data_dynamic* | |
515 | dynamic_data() const | |
516 | { return this->dynamic_data_; } | |
517 | ||
730cdc88 ILT |
518 | // Write out the output sections. |
519 | void | |
520 | write_output_sections(Output_file* of) const; | |
521 | ||
61ba1cf9 ILT |
522 | // Write out data not associated with an input file or the symbol |
523 | // table. | |
524 | void | |
9025d29d | 525 | write_data(const Symbol_table*, Output_file*) const; |
61ba1cf9 | 526 | |
730cdc88 ILT |
527 | // Write out output sections which can not be written until all the |
528 | // input sections are complete. | |
529 | void | |
27bc2bce | 530 | write_sections_after_input_sections(Output_file* of); |
730cdc88 | 531 | |
ead1e424 ILT |
532 | // Return an output section named NAME, or NULL if there is none. |
533 | Output_section* | |
534 | find_output_section(const char* name) const; | |
535 | ||
536 | // Return an output segment of type TYPE, with segment flags SET set | |
537 | // and segment flags CLEAR clear. Return NULL if there is none. | |
538 | Output_segment* | |
539 | find_output_segment(elfcpp::PT type, elfcpp::Elf_Word set, | |
540 | elfcpp::Elf_Word clear) const; | |
541 | ||
3802b2dd ILT |
542 | // Return the number of segments we expect to produce. |
543 | size_t | |
544 | expected_segment_count() const; | |
545 | ||
535890bb ILT |
546 | // Set a flag to indicate that an object file uses the static TLS model. |
547 | void | |
548 | set_has_static_tls() | |
549 | { this->has_static_tls_ = true; } | |
550 | ||
551 | // Return true if any object file uses the static TLS model. | |
552 | bool | |
553 | has_static_tls() const | |
554 | { return this->has_static_tls_; } | |
555 | ||
e5756efb ILT |
556 | // Return the options which may be set by a linker script. |
557 | Script_options* | |
558 | script_options() | |
559 | { return this->script_options_; } | |
560 | ||
561 | const Script_options* | |
562 | script_options() const | |
563 | { return this->script_options_; } | |
d391083d | 564 | |
3ce2c28e ILT |
565 | // Return the object managing inputs in incremental build. NULL in |
566 | // non-incremental builds. | |
567 | Incremental_inputs* | |
568 | incremental_inputs() | |
569 | { return this->incremental_inputs_; } | |
570 | ||
ea715a34 ILT |
571 | // For the target-specific code to add dynamic tags which are common |
572 | // to most targets. | |
573 | void | |
574 | add_target_dynamic_tags(bool use_rel, const Output_data* plt_got, | |
575 | const Output_data* plt_rel, | |
3a44184e | 576 | const Output_data_reloc_generic* dyn_rel, |
612a8d3d | 577 | bool add_debug, bool dynrel_includes_plt); |
ea715a34 | 578 | |
8ed814a9 ILT |
579 | // Compute and write out the build ID if needed. |
580 | void | |
581 | write_build_id(Output_file*) const; | |
582 | ||
516cb3d0 ILT |
583 | // Rewrite output file in binary format. |
584 | void | |
585 | write_binary(Output_file* in) const; | |
586 | ||
7d9e3d98 ILT |
587 | // Print output sections to the map file. |
588 | void | |
589 | print_to_mapfile(Mapfile*) const; | |
590 | ||
ad8f37d1 ILT |
591 | // Dump statistical information to stderr. |
592 | void | |
593 | print_stats() const; | |
594 | ||
a445fddf | 595 | // A list of segments. |
54dc6425 ILT |
596 | |
597 | typedef std::vector<Output_segment*> Segment_list; | |
598 | ||
a445fddf | 599 | // A list of sections. |
54dc6425 | 600 | |
a3ad94ed | 601 | typedef std::vector<Output_section*> Section_list; |
54dc6425 ILT |
602 | |
603 | // The list of information to write out which is not attached to | |
604 | // either a section or a segment. | |
a3ad94ed | 605 | typedef std::vector<Output_data*> Data_list; |
54dc6425 | 606 | |
a445fddf ILT |
607 | // Store the allocated sections into the section list. This is used |
608 | // by the linker script code. | |
609 | void | |
610 | get_allocated_sections(Section_list*) const; | |
611 | ||
919ed24c ILT |
612 | // Make a section for a linker script to hold data. |
613 | Output_section* | |
1e5d2fb1 DK |
614 | make_output_section_for_script(const char* name, |
615 | Script_sections::Section_type section_type); | |
919ed24c | 616 | |
a445fddf ILT |
617 | // Make a segment. This is used by the linker script code. |
618 | Output_segment* | |
619 | make_output_segment(elfcpp::Elf_Word type, elfcpp::Elf_Word flags); | |
620 | ||
621 | // Return the number of segments. | |
622 | size_t | |
623 | segment_count() const | |
624 | { return this->segment_list_.size(); } | |
625 | ||
626 | // Map from section flags to segment flags. | |
627 | static elfcpp::Elf_Word | |
628 | section_flags_to_segment(elfcpp::Elf_Xword flags); | |
629 | ||
154e0e9a ILT |
630 | // Attach sections to segments. |
631 | void | |
632 | attach_sections_to_segments(); | |
633 | ||
20e6d0d6 DK |
634 | // For relaxation clean up, we need to know output section data created |
635 | // from a linker script. | |
636 | void | |
637 | new_output_section_data_from_script(Output_section_data* posd) | |
638 | { | |
639 | if (this->record_output_section_data_from_script_) | |
640 | this->script_output_section_data_list_.push_back(posd); | |
641 | } | |
642 | ||
c0a62865 DK |
643 | // Return section list. |
644 | const Section_list& | |
645 | section_list() const | |
646 | { return this->section_list_; } | |
647 | ||
a2fb1b05 ILT |
648 | private: |
649 | Layout(const Layout&); | |
650 | Layout& operator=(const Layout&); | |
651 | ||
dff16297 ILT |
652 | // Mapping from input section names to output section names. |
653 | struct Section_name_mapping | |
a2fb1b05 ILT |
654 | { |
655 | const char* from; | |
656 | int fromlen; | |
657 | const char* to; | |
ead1e424 | 658 | int tolen; |
a2fb1b05 | 659 | }; |
dff16297 ILT |
660 | static const Section_name_mapping section_name_mapping[]; |
661 | static const int section_name_mapping_count; | |
a2fb1b05 | 662 | |
755ab8af ILT |
663 | // During a relocatable link, a list of group sections and |
664 | // signatures. | |
665 | struct Group_signature | |
666 | { | |
667 | // The group section. | |
668 | Output_section* section; | |
669 | // The signature. | |
670 | const char* signature; | |
671 | ||
672 | Group_signature() | |
673 | : section(NULL), signature(NULL) | |
674 | { } | |
675 | ||
676 | Group_signature(Output_section* sectiona, const char* signaturea) | |
677 | : section(sectiona), signature(signaturea) | |
678 | { } | |
679 | }; | |
680 | typedef std::vector<Group_signature> Group_signatures; | |
681 | ||
ef4ab7a8 | 682 | // Create a note section, filling in the header. |
8ed814a9 | 683 | Output_section* |
ef4ab7a8 PP |
684 | create_note(const char* name, int note_type, const char *section_name, |
685 | size_t descsz, bool allocate, size_t* trailing_padding); | |
8ed814a9 | 686 | |
ef4ab7a8 | 687 | // Create a note section for gold version. |
4f211c8b | 688 | void |
35cdfc9a ILT |
689 | create_gold_note(); |
690 | ||
691 | // Record whether the stack must be executable. | |
692 | void | |
9c547ec3 | 693 | create_executable_stack_info(); |
4f211c8b | 694 | |
8ed814a9 ILT |
695 | // Create a build ID note if needed. |
696 | void | |
697 | create_build_id(); | |
698 | ||
1518dc8f ILT |
699 | // Link .stab and .stabstr sections. |
700 | void | |
701 | link_stabs_sections(); | |
702 | ||
3ce2c28e ILT |
703 | // Create .gnu_incremental_inputs and .gnu_incremental_strtab sections needed |
704 | // for the next run of incremental linking to check what has changed. | |
705 | void | |
706 | create_incremental_info_sections(); | |
707 | ||
75f65a3e ILT |
708 | // Find the first read-only PT_LOAD segment, creating one if |
709 | // necessary. | |
710 | Output_segment* | |
711 | find_first_load_seg(); | |
712 | ||
7bf1f802 ILT |
713 | // Count the local symbols in the regular symbol table and the dynamic |
714 | // symbol table, and build the respective string pools. | |
715 | void | |
17a1d0a9 | 716 | count_local_symbols(const Task*, const Input_objects*); |
7bf1f802 | 717 | |
54dc6425 ILT |
718 | // Create the output sections for the symbol table. |
719 | void | |
d491d34e ILT |
720 | create_symtab_sections(const Input_objects*, Symbol_table*, |
721 | unsigned int, off_t*); | |
54dc6425 | 722 | |
75f65a3e ILT |
723 | // Create the .shstrtab section. |
724 | Output_section* | |
725 | create_shstrtab(); | |
726 | ||
727 | // Create the section header table. | |
27bc2bce | 728 | void |
d491d34e | 729 | create_shdrs(const Output_section* shstrtab_section, off_t*); |
54dc6425 | 730 | |
dbe717ef ILT |
731 | // Create the dynamic symbol table. |
732 | void | |
9b07f471 ILT |
733 | create_dynamic_symtab(const Input_objects*, Symbol_table*, |
734 | Output_section** pdynstr, | |
14b31740 ILT |
735 | unsigned int* plocal_dynamic_count, |
736 | std::vector<Symbol*>* pdynamic_symbols, | |
737 | Versions* versions); | |
dbe717ef | 738 | |
7bf1f802 ILT |
739 | // Assign offsets to each local portion of the dynamic symbol table. |
740 | void | |
741 | assign_local_dynsym_offsets(const Input_objects*); | |
742 | ||
a3ad94ed | 743 | // Finish the .dynamic section and PT_DYNAMIC segment. |
dbe717ef | 744 | void |
16649710 | 745 | finish_dynamic_section(const Input_objects*, const Symbol_table*); |
dbe717ef | 746 | |
f0ba79e2 ILT |
747 | // Set the size of the _DYNAMIC symbol. |
748 | void | |
749 | set_dynamic_symbol_size(const Symbol_table*); | |
750 | ||
dbe717ef ILT |
751 | // Create the .interp section and PT_INTERP segment. |
752 | void | |
753 | create_interp(const Target* target); | |
754 | ||
14b31740 ILT |
755 | // Create the version sections. |
756 | void | |
9025d29d | 757 | create_version_sections(const Versions*, |
46fe1623 | 758 | const Symbol_table*, |
14b31740 ILT |
759 | unsigned int local_symcount, |
760 | const std::vector<Symbol*>& dynamic_symbols, | |
761 | const Output_section* dynstr); | |
762 | ||
763 | template<int size, bool big_endian> | |
764 | void | |
765 | sized_create_version_sections(const Versions* versions, | |
46fe1623 | 766 | const Symbol_table*, |
14b31740 ILT |
767 | unsigned int local_symcount, |
768 | const std::vector<Symbol*>& dynamic_symbols, | |
7d1a9ebb | 769 | const Output_section* dynstr); |
14b31740 | 770 | |
a2fb1b05 ILT |
771 | // Return whether to include this section in the link. |
772 | template<int size, bool big_endian> | |
773 | bool | |
730cdc88 | 774 | include_section(Sized_relobj<size, big_endian>* object, const char* name, |
a2fb1b05 ILT |
775 | const elfcpp::Shdr<size, big_endian>&); |
776 | ||
ead1e424 ILT |
777 | // Return the output section name to use given an input section |
778 | // name. Set *PLEN to the length of the name. *PLEN must be | |
779 | // initialized to the length of NAME. | |
780 | static const char* | |
781 | output_section_name(const char* name, size_t* plen); | |
782 | ||
d491d34e ILT |
783 | // Return the number of allocated output sections. |
784 | size_t | |
785 | allocated_output_section_count() const; | |
786 | ||
ead1e424 ILT |
787 | // Return the output section for NAME, TYPE and FLAGS. |
788 | Output_section* | |
f0641a0b | 789 | get_output_section(const char* name, Stringpool::Key name_key, |
f5c870d2 | 790 | elfcpp::Elf_Word type, elfcpp::Elf_Xword flags, |
1a2dff53 ILT |
791 | bool is_interp, bool is_dynamic_linker_section, |
792 | bool is_relro, bool is_last_relro, | |
793 | bool is_first_non_relro); | |
a2fb1b05 | 794 | |
a445fddf ILT |
795 | // Choose the output section for NAME in RELOBJ. |
796 | Output_section* | |
797 | choose_output_section(const Relobj* relobj, const char* name, | |
798 | elfcpp::Elf_Word type, elfcpp::Elf_Xword flags, | |
f5c870d2 | 799 | bool is_input_section, bool is_interp, |
1a2dff53 ILT |
800 | bool is_dynamic_linker_section, bool is_relro, |
801 | bool is_last_relro, bool is_first_non_relro); | |
a445fddf | 802 | |
a2fb1b05 ILT |
803 | // Create a new Output_section. |
804 | Output_section* | |
805 | make_output_section(const char* name, elfcpp::Elf_Word type, | |
f5c870d2 | 806 | elfcpp::Elf_Xword flags, bool is_interp, |
1a2dff53 ILT |
807 | bool is_dynamic_linker_section, bool is_relro, |
808 | bool is_last_relro, bool is_first_non_relro); | |
a2fb1b05 | 809 | |
4e2b1697 ILT |
810 | // Attach a section to a segment. |
811 | void | |
154e0e9a | 812 | attach_section_to_segment(Output_section*); |
4e2b1697 | 813 | |
154e0e9a | 814 | // Attach an allocated section to a segment. |
1650c4ff | 815 | void |
154e0e9a | 816 | attach_allocated_section_to_segment(Output_section*); |
1650c4ff | 817 | |
dbe717ef ILT |
818 | // Set the final file offsets of all the segments. |
819 | off_t | |
820 | set_segment_offsets(const Target*, Output_segment*, unsigned int* pshndx); | |
821 | ||
6a74a719 ILT |
822 | // Set the file offsets of the sections when doing a relocatable |
823 | // link. | |
824 | off_t | |
825 | set_relocatable_section_offsets(Output_data*, unsigned int* pshndx); | |
826 | ||
86887060 | 827 | // Set the final file offsets of all the sections not associated |
9a0910c3 ILT |
828 | // with a segment. We set section offsets in three passes: the |
829 | // first handles all allocated sections, the second sections that | |
17a1d0a9 ILT |
830 | // require postprocessing, and the last the late-bound STRTAB |
831 | // sections (probably only shstrtab, which is the one we care about | |
832 | // because it holds section names). | |
9a0910c3 ILT |
833 | enum Section_offset_pass |
834 | { | |
835 | BEFORE_INPUT_SECTIONS_PASS, | |
17a1d0a9 ILT |
836 | POSTPROCESSING_SECTIONS_PASS, |
837 | STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS | |
9a0910c3 | 838 | }; |
dbe717ef | 839 | off_t |
9a0910c3 ILT |
840 | set_section_offsets(off_t, Section_offset_pass pass); |
841 | ||
86887060 ILT |
842 | // Set the final section indexes of all the sections not associated |
843 | // with a segment. Returns the next unused index. | |
844 | unsigned int | |
845 | set_section_indexes(unsigned int pshndx); | |
dbe717ef | 846 | |
a445fddf ILT |
847 | // Set the section addresses when using a script. |
848 | Output_segment* | |
849 | set_section_addresses_from_script(Symbol_table*); | |
850 | ||
20e6d0d6 DK |
851 | // Find appropriate places or orphan sections in a script. |
852 | void | |
853 | place_orphan_sections_in_script(); | |
854 | ||
a2fb1b05 ILT |
855 | // Return whether SEG1 comes before SEG2 in the output file. |
856 | static bool | |
b3168e9d | 857 | segment_precedes(const Output_segment* seg1, const Output_segment* seg2); |
a2fb1b05 | 858 | |
20e6d0d6 DK |
859 | // Use to save and restore segments during relaxation. |
860 | typedef Unordered_map<const Output_segment*, const Output_segment*> | |
861 | Segment_states; | |
862 | ||
863 | // Save states of current output segments. | |
864 | void | |
865 | save_segments(Segment_states*); | |
866 | ||
867 | // Restore output segment states. | |
868 | void | |
869 | restore_segments(const Segment_states*); | |
870 | ||
871 | // Clean up after relaxation so that it is possible to lay out the | |
872 | // sections and segments again. | |
873 | void | |
874 | clean_up_after_relaxation(); | |
875 | ||
876 | // Doing preparation work for relaxation. This is factored out to make | |
877 | // Layout::finalized a bit smaller and easier to read. | |
878 | void | |
879 | prepare_for_relaxation(); | |
880 | ||
881 | // Main body of the relaxation loop, which lays out the section. | |
882 | off_t | |
883 | relaxation_loop_body(int, Target*, Symbol_table*, Output_segment**, | |
884 | Output_segment*, Output_segment_headers*, | |
885 | Output_file_header*, unsigned int*); | |
886 | ||
8a4c0b0d | 887 | // A mapping used for kept comdats/.gnu.linkonce group signatures. |
e94cf127 | 888 | typedef Unordered_map<std::string, Kept_section> Signatures; |
a2fb1b05 ILT |
889 | |
890 | // Mapping from input section name/type/flags to output section. We | |
891 | // use canonicalized strings here. | |
892 | ||
f0641a0b | 893 | typedef std::pair<Stringpool::Key, |
a2fb1b05 ILT |
894 | std::pair<elfcpp::Elf_Word, elfcpp::Elf_Xword> > Key; |
895 | ||
896 | struct Hash_key | |
897 | { | |
898 | size_t | |
899 | operator()(const Key& k) const; | |
900 | }; | |
901 | ||
902 | typedef Unordered_map<Key, Output_section*, Hash_key> Section_name_map; | |
903 | ||
904 | // A comparison class for segments. | |
905 | ||
906 | struct Compare_segments | |
907 | { | |
908 | bool | |
909 | operator()(const Output_segment* seg1, const Output_segment* seg2) | |
910 | { return Layout::segment_precedes(seg1, seg2); } | |
911 | }; | |
912 | ||
20e6d0d6 DK |
913 | typedef std::vector<Output_section_data*> Output_section_data_list; |
914 | ||
915 | // Debug checker class. | |
916 | class Relaxation_debug_check | |
917 | { | |
918 | public: | |
919 | Relaxation_debug_check() | |
920 | : section_infos_() | |
921 | { } | |
922 | ||
923 | // Check that sections and special data are in reset states. | |
924 | void | |
925 | check_output_data_for_reset_values(const Layout::Section_list&, | |
926 | const Layout::Data_list&); | |
927 | ||
928 | // Record information of a section list. | |
929 | void | |
930 | read_sections(const Layout::Section_list&); | |
931 | ||
932 | // Verify a section list with recorded information. | |
933 | void | |
934 | verify_sections(const Layout::Section_list&); | |
935 | ||
936 | private: | |
937 | // Information we care about a section. | |
938 | struct Section_info | |
939 | { | |
940 | // Output section described by this. | |
941 | Output_section* output_section; | |
942 | // Load address. | |
943 | uint64_t address; | |
944 | // Data size. | |
945 | off_t data_size; | |
946 | // File offset. | |
947 | off_t offset; | |
948 | }; | |
949 | ||
950 | // Section information. | |
951 | std::vector<Section_info> section_infos_; | |
952 | }; | |
953 | ||
e55bde5e ILT |
954 | // The number of input files, for sizing tables. |
955 | int number_of_input_files_; | |
e5756efb ILT |
956 | // Information set by scripts or by command line options. |
957 | Script_options* script_options_; | |
a2fb1b05 ILT |
958 | // The output section names. |
959 | Stringpool namepool_; | |
75f65a3e ILT |
960 | // The output symbol names. |
961 | Stringpool sympool_; | |
a3ad94ed ILT |
962 | // The dynamic strings, if needed. |
963 | Stringpool dynpool_; | |
a2fb1b05 ILT |
964 | // The list of group sections and linkonce sections which we have seen. |
965 | Signatures signatures_; | |
966 | // The mapping from input section name/type/flags to output sections. | |
967 | Section_name_map section_name_map_; | |
968 | // The list of output segments. | |
969 | Segment_list segment_list_; | |
a3ad94ed ILT |
970 | // The list of output sections. |
971 | Section_list section_list_; | |
a2fb1b05 ILT |
972 | // The list of output sections which are not attached to any output |
973 | // segment. | |
a3ad94ed ILT |
974 | Section_list unattached_section_list_; |
975 | // The list of unattached Output_data objects which require special | |
976 | // handling because they are not Output_sections. | |
61ba1cf9 | 977 | Data_list special_output_list_; |
27bc2bce ILT |
978 | // The section headers. |
979 | Output_section_headers* section_headers_; | |
92e059d8 ILT |
980 | // A pointer to the PT_TLS segment if there is one. |
981 | Output_segment* tls_segment_; | |
9f1d377b ILT |
982 | // A pointer to the PT_GNU_RELRO segment if there is one. |
983 | Output_segment* relro_segment_; | |
1a2dff53 ILT |
984 | // A backend may increase the size of the PT_GNU_RELRO segment if |
985 | // there is one. This is the amount to increase it by. | |
986 | unsigned int increase_relro_; | |
a3ad94ed ILT |
987 | // The SHT_SYMTAB output section. |
988 | Output_section* symtab_section_; | |
d491d34e ILT |
989 | // The SHT_SYMTAB_SHNDX for the regular symbol table if there is one. |
990 | Output_symtab_xindex* symtab_xindex_; | |
a3ad94ed ILT |
991 | // The SHT_DYNSYM output section if there is one. |
992 | Output_section* dynsym_section_; | |
d491d34e ILT |
993 | // The SHT_SYMTAB_SHNDX for the dynamic symbol table if there is one. |
994 | Output_symtab_xindex* dynsym_xindex_; | |
a3ad94ed ILT |
995 | // The SHT_DYNAMIC output section if there is one. |
996 | Output_section* dynamic_section_; | |
f0ba79e2 ILT |
997 | // The _DYNAMIC symbol if there is one. |
998 | Symbol* dynamic_symbol_; | |
16649710 ILT |
999 | // The dynamic data which goes into dynamic_section_. |
1000 | Output_data_dynamic* dynamic_data_; | |
730cdc88 | 1001 | // The exception frame output section if there is one. |
3151305a | 1002 | Output_section* eh_frame_section_; |
730cdc88 ILT |
1003 | // The exception frame data for eh_frame_section_. |
1004 | Eh_frame* eh_frame_data_; | |
2c38906f ILT |
1005 | // Whether we have added eh_frame_data_ to the .eh_frame section. |
1006 | bool added_eh_frame_data_; | |
730cdc88 ILT |
1007 | // The exception frame header output section if there is one. |
1008 | Output_section* eh_frame_hdr_section_; | |
8ed814a9 ILT |
1009 | // The space for the build ID checksum if there is one. |
1010 | Output_section_data* build_id_note_; | |
62b01cb5 ILT |
1011 | // The output section containing dwarf abbreviations |
1012 | Output_reduced_debug_abbrev_section* debug_abbrev_; | |
1013 | // The output section containing the dwarf debug info tree | |
1014 | Output_reduced_debug_info_section* debug_info_; | |
755ab8af ILT |
1015 | // A list of group sections and their signatures. |
1016 | Group_signatures group_signatures_; | |
e44fcf3b ILT |
1017 | // The size of the output file. |
1018 | off_t output_file_size_; | |
d7bb5745 ILT |
1019 | // Whether we have added an input section to an output section. |
1020 | bool have_added_input_section_; | |
e55bde5e ILT |
1021 | // Whether we have attached the sections to the segments. |
1022 | bool sections_are_attached_; | |
35cdfc9a ILT |
1023 | // Whether we have seen an object file marked to require an |
1024 | // executable stack. | |
1025 | bool input_requires_executable_stack_; | |
1026 | // Whether we have seen at least one object file with an executable | |
1027 | // stack marker. | |
1028 | bool input_with_gnu_stack_note_; | |
1029 | // Whether we have seen at least one object file without an | |
1030 | // executable stack marker. | |
1031 | bool input_without_gnu_stack_note_; | |
535890bb ILT |
1032 | // Whether we have seen an object file that uses the static TLS model. |
1033 | bool has_static_tls_; | |
17a1d0a9 ILT |
1034 | // Whether any sections require postprocessing. |
1035 | bool any_postprocessing_sections_; | |
e55bde5e ILT |
1036 | // Whether we have resized the signatures_ hash table. |
1037 | bool resized_signatures_; | |
1518dc8f ILT |
1038 | // Whether we have created a .stab*str output section. |
1039 | bool have_stabstr_section_; | |
3ce2c28e ILT |
1040 | // In incremental build, holds information check the inputs and build the |
1041 | // .gnu_incremental_inputs section. | |
1042 | Incremental_inputs* incremental_inputs_; | |
20e6d0d6 DK |
1043 | // Whether we record output section data created in script |
1044 | bool record_output_section_data_from_script_; | |
1045 | // List of output data that needs to be removed at relexation clean up. | |
1046 | Output_section_data_list script_output_section_data_list_; | |
1047 | // Structure to save segment states before entering the relaxation loop. | |
1048 | Segment_states* segment_states_; | |
1049 | // A relaxation debug checker. We only create one when in debugging mode. | |
1050 | Relaxation_debug_check* relaxation_debug_check_; | |
6e9ba2ca ST |
1051 | // Hash a pattern to its position in the section ordering file. |
1052 | Unordered_map<std::string, unsigned int> input_section_position_; | |
1053 | // Vector of glob only patterns in the section_ordering file. | |
1054 | std::vector<std::string> input_section_glob_; | |
61ba1cf9 ILT |
1055 | }; |
1056 | ||
730cdc88 ILT |
1057 | // This task handles writing out data in output sections which is not |
1058 | // part of an input section, or which requires special handling. When | |
1059 | // this is done, it unblocks both output_sections_blocker and | |
1060 | // final_blocker. | |
1061 | ||
1062 | class Write_sections_task : public Task | |
1063 | { | |
1064 | public: | |
1065 | Write_sections_task(const Layout* layout, Output_file* of, | |
1066 | Task_token* output_sections_blocker, | |
1067 | Task_token* final_blocker) | |
1068 | : layout_(layout), of_(of), | |
1069 | output_sections_blocker_(output_sections_blocker), | |
1070 | final_blocker_(final_blocker) | |
1071 | { } | |
1072 | ||
1073 | // The standard Task methods. | |
1074 | ||
17a1d0a9 ILT |
1075 | Task_token* |
1076 | is_runnable(); | |
730cdc88 | 1077 | |
17a1d0a9 ILT |
1078 | void |
1079 | locks(Task_locker*); | |
730cdc88 ILT |
1080 | |
1081 | void | |
1082 | run(Workqueue*); | |
1083 | ||
c7912668 ILT |
1084 | std::string |
1085 | get_name() const | |
1086 | { return "Write_sections_task"; } | |
1087 | ||
730cdc88 ILT |
1088 | private: |
1089 | class Write_sections_locker; | |
1090 | ||
1091 | const Layout* layout_; | |
1092 | Output_file* of_; | |
1093 | Task_token* output_sections_blocker_; | |
1094 | Task_token* final_blocker_; | |
1095 | }; | |
1096 | ||
61ba1cf9 ILT |
1097 | // This task handles writing out data which is not part of a section |
1098 | // or segment. | |
1099 | ||
1100 | class Write_data_task : public Task | |
1101 | { | |
1102 | public: | |
a3ad94ed | 1103 | Write_data_task(const Layout* layout, const Symbol_table* symtab, |
9025d29d ILT |
1104 | Output_file* of, Task_token* final_blocker) |
1105 | : layout_(layout), symtab_(symtab), of_(of), final_blocker_(final_blocker) | |
61ba1cf9 ILT |
1106 | { } |
1107 | ||
1108 | // The standard Task methods. | |
1109 | ||
17a1d0a9 ILT |
1110 | Task_token* |
1111 | is_runnable(); | |
61ba1cf9 | 1112 | |
17a1d0a9 ILT |
1113 | void |
1114 | locks(Task_locker*); | |
61ba1cf9 ILT |
1115 | |
1116 | void | |
1117 | run(Workqueue*); | |
1118 | ||
c7912668 ILT |
1119 | std::string |
1120 | get_name() const | |
1121 | { return "Write_data_task"; } | |
1122 | ||
61ba1cf9 ILT |
1123 | private: |
1124 | const Layout* layout_; | |
a3ad94ed | 1125 | const Symbol_table* symtab_; |
61ba1cf9 ILT |
1126 | Output_file* of_; |
1127 | Task_token* final_blocker_; | |
1128 | }; | |
1129 | ||
1130 | // This task handles writing out the global symbols. | |
1131 | ||
1132 | class Write_symbols_task : public Task | |
1133 | { | |
1134 | public: | |
d491d34e | 1135 | Write_symbols_task(const Layout* layout, const Symbol_table* symtab, |
9a2d6984 | 1136 | const Input_objects* input_objects, |
16649710 ILT |
1137 | const Stringpool* sympool, const Stringpool* dynpool, |
1138 | Output_file* of, Task_token* final_blocker) | |
d491d34e ILT |
1139 | : layout_(layout), symtab_(symtab), input_objects_(input_objects), |
1140 | sympool_(sympool), dynpool_(dynpool), of_(of), | |
1141 | final_blocker_(final_blocker) | |
61ba1cf9 ILT |
1142 | { } |
1143 | ||
1144 | // The standard Task methods. | |
1145 | ||
17a1d0a9 ILT |
1146 | Task_token* |
1147 | is_runnable(); | |
61ba1cf9 | 1148 | |
17a1d0a9 ILT |
1149 | void |
1150 | locks(Task_locker*); | |
61ba1cf9 ILT |
1151 | |
1152 | void | |
1153 | run(Workqueue*); | |
1154 | ||
c7912668 ILT |
1155 | std::string |
1156 | get_name() const | |
1157 | { return "Write_symbols_task"; } | |
1158 | ||
61ba1cf9 | 1159 | private: |
d491d34e | 1160 | const Layout* layout_; |
61ba1cf9 | 1161 | const Symbol_table* symtab_; |
9a2d6984 | 1162 | const Input_objects* input_objects_; |
61ba1cf9 | 1163 | const Stringpool* sympool_; |
16649710 | 1164 | const Stringpool* dynpool_; |
61ba1cf9 ILT |
1165 | Output_file* of_; |
1166 | Task_token* final_blocker_; | |
1167 | }; | |
1168 | ||
730cdc88 ILT |
1169 | // This task handles writing out data in output sections which can't |
1170 | // be written out until all the input sections have been handled. | |
1171 | // This is for sections whose contents is based on the contents of | |
1172 | // other output sections. | |
1173 | ||
1174 | class Write_after_input_sections_task : public Task | |
1175 | { | |
1176 | public: | |
27bc2bce | 1177 | Write_after_input_sections_task(Layout* layout, Output_file* of, |
730cdc88 ILT |
1178 | Task_token* input_sections_blocker, |
1179 | Task_token* final_blocker) | |
1180 | : layout_(layout), of_(of), | |
1181 | input_sections_blocker_(input_sections_blocker), | |
1182 | final_blocker_(final_blocker) | |
1183 | { } | |
1184 | ||
1185 | // The standard Task methods. | |
1186 | ||
17a1d0a9 ILT |
1187 | Task_token* |
1188 | is_runnable(); | |
730cdc88 | 1189 | |
17a1d0a9 ILT |
1190 | void |
1191 | locks(Task_locker*); | |
730cdc88 ILT |
1192 | |
1193 | void | |
1194 | run(Workqueue*); | |
1195 | ||
c7912668 ILT |
1196 | std::string |
1197 | get_name() const | |
1198 | { return "Write_after_input_sections_task"; } | |
1199 | ||
730cdc88 | 1200 | private: |
27bc2bce | 1201 | Layout* layout_; |
730cdc88 ILT |
1202 | Output_file* of_; |
1203 | Task_token* input_sections_blocker_; | |
1204 | Task_token* final_blocker_; | |
1205 | }; | |
1206 | ||
92e059d8 | 1207 | // This task function handles closing the file. |
61ba1cf9 | 1208 | |
92e059d8 | 1209 | class Close_task_runner : public Task_function_runner |
61ba1cf9 ILT |
1210 | { |
1211 | public: | |
516cb3d0 ILT |
1212 | Close_task_runner(const General_options* options, const Layout* layout, |
1213 | Output_file* of) | |
1214 | : options_(options), layout_(layout), of_(of) | |
61ba1cf9 ILT |
1215 | { } |
1216 | ||
92e059d8 | 1217 | // Run the operation. |
61ba1cf9 | 1218 | void |
17a1d0a9 | 1219 | run(Workqueue*, const Task*); |
61ba1cf9 ILT |
1220 | |
1221 | private: | |
516cb3d0 ILT |
1222 | const General_options* options_; |
1223 | const Layout* layout_; | |
61ba1cf9 | 1224 | Output_file* of_; |
a2fb1b05 ILT |
1225 | }; |
1226 | ||
ead1e424 ILT |
1227 | // A small helper function to align an address. |
1228 | ||
1229 | inline uint64_t | |
1230 | align_address(uint64_t address, uint64_t addralign) | |
1231 | { | |
1232 | if (addralign != 0) | |
1233 | address = (address + addralign - 1) &~ (addralign - 1); | |
1234 | return address; | |
1235 | } | |
1236 | ||
a2fb1b05 ILT |
1237 | } // End namespace gold. |
1238 | ||
1239 | #endif // !defined(GOLD_LAYOUT_H) |