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