Commit | Line | Data |
---|---|---|
a2fb1b05 ILT |
1 | // layout.h -- lay out output file sections for gold -*- C++ -*- |
2 | ||
e5756efb | 3 | // Copyright 2006, 2007, 2008 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 | ||
26 | #include <list> | |
27 | #include <string> | |
28 | #include <utility> | |
29 | #include <vector> | |
30 | ||
e5756efb | 31 | #include "script.h" |
a2fb1b05 ILT |
32 | #include "workqueue.h" |
33 | #include "object.h" | |
14b31740 | 34 | #include "dynobj.h" |
a2fb1b05 ILT |
35 | #include "stringpool.h" |
36 | ||
37 | namespace gold | |
38 | { | |
39 | ||
ead1e424 | 40 | class General_options; |
54dc6425 | 41 | class Input_objects; |
75f65a3e | 42 | class Symbol_table; |
ead1e424 | 43 | class Output_section_data; |
a2fb1b05 | 44 | class Output_section; |
75f65a3e | 45 | class Output_section_headers; |
a2fb1b05 | 46 | class Output_segment; |
54dc6425 | 47 | class Output_data; |
a3ad94ed | 48 | class Output_data_dynamic; |
d491d34e | 49 | class Output_symtab_xindex; |
730cdc88 | 50 | class Eh_frame; |
61ba1cf9 | 51 | class Target; |
a2fb1b05 | 52 | |
92e059d8 ILT |
53 | // This task function handles mapping the input sections to output |
54 | // sections and laying them out in memory. | |
a2fb1b05 | 55 | |
92e059d8 | 56 | class Layout_task_runner : public Task_function_runner |
a2fb1b05 ILT |
57 | { |
58 | public: | |
59 | // OPTIONS is the command line options, INPUT_OBJECTS is the list of | |
92e059d8 ILT |
60 | // input objects, SYMTAB is the symbol table, LAYOUT is the layout |
61 | // object. | |
62 | Layout_task_runner(const General_options& options, | |
63 | const Input_objects* input_objects, | |
64 | Symbol_table* symtab, | |
8851ecca | 65 | Target* target, |
92e059d8 | 66 | Layout* layout) |
75f65a3e | 67 | : options_(options), input_objects_(input_objects), symtab_(symtab), |
8851ecca | 68 | target_(target), layout_(layout) |
a2fb1b05 ILT |
69 | { } |
70 | ||
92e059d8 | 71 | // Run the operation. |
a2fb1b05 | 72 | void |
17a1d0a9 | 73 | run(Workqueue*, const Task*); |
a2fb1b05 ILT |
74 | |
75 | private: | |
92e059d8 ILT |
76 | Layout_task_runner(const Layout_task_runner&); |
77 | Layout_task_runner& operator=(const Layout_task_runner&); | |
a2fb1b05 ILT |
78 | |
79 | const General_options& options_; | |
54dc6425 | 80 | const Input_objects* input_objects_; |
75f65a3e | 81 | Symbol_table* symtab_; |
8851ecca | 82 | Target* target_; |
12e14209 | 83 | Layout* layout_; |
a2fb1b05 ILT |
84 | }; |
85 | ||
86 | // This class handles the details of laying out input sections. | |
87 | ||
88 | class Layout | |
89 | { | |
90 | public: | |
e5756efb | 91 | Layout(const General_options& options, Script_options*); |
54dc6425 | 92 | |
ead1e424 ILT |
93 | // Given an input section SHNDX, named NAME, with data in SHDR, from |
94 | // the object file OBJECT, return the output section where this | |
730cdc88 ILT |
95 | // input section should go. RELOC_SHNDX is the index of a |
96 | // relocation section which applies to this section, or 0 if none, | |
97 | // or -1U if more than one. RELOC_TYPE is the type of the | |
98 | // relocation section if there is one. Set *OFFSET to the offset | |
99 | // within the output section. | |
a2fb1b05 ILT |
100 | template<int size, bool big_endian> |
101 | Output_section* | |
730cdc88 ILT |
102 | layout(Sized_relobj<size, big_endian> *object, unsigned int shndx, |
103 | const char* name, const elfcpp::Shdr<size, big_endian>& shdr, | |
104 | unsigned int reloc_shndx, unsigned int reloc_type, off_t* offset); | |
105 | ||
6a74a719 ILT |
106 | // Layout an input reloc section when doing a relocatable link. The |
107 | // section is RELOC_SHNDX in OBJECT, with data in SHDR. | |
108 | // DATA_SECTION is the reloc section to which it refers. RR is the | |
109 | // relocatable information. | |
110 | template<int size, bool big_endian> | |
111 | Output_section* | |
112 | layout_reloc(Sized_relobj<size, big_endian>* object, | |
113 | unsigned int reloc_shndx, | |
114 | const elfcpp::Shdr<size, big_endian>& shdr, | |
115 | Output_section* data_section, | |
116 | Relocatable_relocs* rr); | |
117 | ||
118 | // Layout a group section when doing a relocatable link. | |
119 | template<int size, bool big_endian> | |
120 | void | |
121 | layout_group(Symbol_table* symtab, | |
122 | Sized_relobj<size, big_endian>* object, | |
123 | unsigned int group_shndx, | |
124 | const char* group_section_name, | |
125 | const char* signature, | |
126 | const elfcpp::Shdr<size, big_endian>& shdr, | |
127 | const elfcpp::Elf_Word* contents); | |
128 | ||
730cdc88 ILT |
129 | // Like layout, only for exception frame sections. OBJECT is an |
130 | // object file. SYMBOLS is the contents of the symbol table | |
131 | // section, with size SYMBOLS_SIZE. SYMBOL_NAMES is the contents of | |
132 | // the symbol name section, with size SYMBOL_NAMES_SIZE. SHNDX is a | |
133 | // .eh_frame section in OBJECT. SHDR is the section header. | |
134 | // RELOC_SHNDX is the index of a relocation section which applies to | |
135 | // this section, or 0 if none, or -1U if more than one. RELOC_TYPE | |
136 | // is the type of the relocation section if there is one. This | |
137 | // returns the output section, and sets *OFFSET to the offset. | |
138 | template<int size, bool big_endian> | |
139 | Output_section* | |
140 | layout_eh_frame(Sized_relobj<size, big_endian>* object, | |
141 | const unsigned char* symbols, | |
142 | off_t symbols_size, | |
143 | const unsigned char* symbol_names, | |
144 | off_t symbol_names_size, | |
145 | unsigned int shndx, | |
146 | const elfcpp::Shdr<size, big_endian>& shdr, | |
147 | unsigned int reloc_shndx, unsigned int reloc_type, | |
148 | off_t* offset); | |
a2fb1b05 | 149 | |
35cdfc9a ILT |
150 | // Handle a GNU stack note. This is called once per input object |
151 | // file. SEEN_GNU_STACK is true if the object file has a | |
152 | // .note.GNU-stack section. GNU_STACK_FLAGS is the section flags | |
153 | // from that section if there was one. | |
154 | void | |
155 | layout_gnu_stack(bool seen_gnu_stack, uint64_t gnu_stack_flags); | |
156 | ||
ead1e424 ILT |
157 | // Add an Output_section_data to the layout. This is used for |
158 | // special sections like the GOT section. | |
159 | void | |
160 | add_output_section_data(const char* name, elfcpp::Elf_Word type, | |
161 | elfcpp::Elf_Xword flags, | |
162 | Output_section_data*); | |
163 | ||
a3ad94ed ILT |
164 | // Create dynamic sections if necessary. |
165 | void | |
9b07f471 | 166 | create_initial_dynamic_sections(Symbol_table*); |
a3ad94ed | 167 | |
bfd58944 ILT |
168 | // Define __start and __stop symbols for output sections. |
169 | void | |
9b07f471 | 170 | define_section_symbols(Symbol_table*); |
bfd58944 | 171 | |
919ed24c ILT |
172 | // Create sections for linker scripts. |
173 | void | |
174 | create_script_sections() | |
175 | { this->script_options_->create_script_sections(this); } | |
176 | ||
e5756efb ILT |
177 | // Define symbols from any linker script. |
178 | void | |
9b07f471 ILT |
179 | define_script_symbols(Symbol_table* symtab) |
180 | { this->script_options_->add_symbols_to_table(symtab); } | |
e5756efb | 181 | |
755ab8af ILT |
182 | // Define symbols for group signatures. |
183 | void | |
184 | define_group_signatures(Symbol_table*); | |
185 | ||
61ba1cf9 ILT |
186 | // Return the Stringpool used for symbol names. |
187 | const Stringpool* | |
188 | sympool() const | |
189 | { return &this->sympool_; } | |
190 | ||
16649710 ILT |
191 | // Return the Stringpool used for dynamic symbol names and dynamic |
192 | // tags. | |
193 | const Stringpool* | |
194 | dynpool() const | |
195 | { return &this->dynpool_; } | |
196 | ||
d491d34e ILT |
197 | // Return the symtab_xindex section used to hold large section |
198 | // indexes for the normal symbol table. | |
199 | Output_symtab_xindex* | |
200 | symtab_xindex() const | |
201 | { return this->symtab_xindex_; } | |
202 | ||
203 | // Return the dynsym_xindex section used to hold large section | |
204 | // indexes for the dynamic symbol table. | |
205 | Output_symtab_xindex* | |
206 | dynsym_xindex() const | |
207 | { return this->dynsym_xindex_; } | |
208 | ||
a2fb1b05 ILT |
209 | // Return whether a section is a .gnu.linkonce section, given the |
210 | // section name. | |
211 | static inline bool | |
212 | is_linkonce(const char* name) | |
213 | { return strncmp(name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; } | |
214 | ||
215 | // Record the signature of a comdat section, and return whether to | |
216 | // include it in the link. The GROUP parameter is true for a | |
217 | // section group signature, false for a signature derived from a | |
218 | // .gnu.linkonce section. | |
219 | bool | |
220 | add_comdat(const char*, bool group); | |
221 | ||
54dc6425 | 222 | // Finalize the layout after all the input sections have been added. |
75f65a3e | 223 | off_t |
8851ecca | 224 | finalize(const Input_objects*, Symbol_table*, Target*, const Task*); |
17a1d0a9 ILT |
225 | |
226 | // Return whether any sections require postprocessing. | |
227 | bool | |
228 | any_postprocessing_sections() const | |
229 | { return this->any_postprocessing_sections_; } | |
54dc6425 | 230 | |
e44fcf3b ILT |
231 | // Return the size of the output file. |
232 | off_t | |
233 | output_file_size() const | |
234 | { return this->output_file_size_; } | |
235 | ||
16649710 ILT |
236 | // Return the TLS segment. This will return NULL if there isn't |
237 | // one. | |
92e059d8 ILT |
238 | Output_segment* |
239 | tls_segment() const | |
240 | { return this->tls_segment_; } | |
241 | ||
16649710 ILT |
242 | // Return the normal symbol table. |
243 | Output_section* | |
244 | symtab_section() const | |
245 | { | |
246 | gold_assert(this->symtab_section_ != NULL); | |
247 | return this->symtab_section_; | |
248 | } | |
249 | ||
250 | // Return the dynamic symbol table. | |
251 | Output_section* | |
252 | dynsym_section() const | |
253 | { | |
254 | gold_assert(this->dynsym_section_ != NULL); | |
255 | return this->dynsym_section_; | |
256 | } | |
257 | ||
258 | // Return the dynamic tags. | |
259 | Output_data_dynamic* | |
260 | dynamic_data() const | |
261 | { return this->dynamic_data_; } | |
262 | ||
730cdc88 ILT |
263 | // Write out the output sections. |
264 | void | |
265 | write_output_sections(Output_file* of) const; | |
266 | ||
61ba1cf9 ILT |
267 | // Write out data not associated with an input file or the symbol |
268 | // table. | |
269 | void | |
9025d29d | 270 | write_data(const Symbol_table*, Output_file*) const; |
61ba1cf9 | 271 | |
730cdc88 ILT |
272 | // Write out output sections which can not be written until all the |
273 | // input sections are complete. | |
274 | void | |
27bc2bce | 275 | write_sections_after_input_sections(Output_file* of); |
730cdc88 | 276 | |
ead1e424 ILT |
277 | // Return an output section named NAME, or NULL if there is none. |
278 | Output_section* | |
279 | find_output_section(const char* name) const; | |
280 | ||
281 | // Return an output segment of type TYPE, with segment flags SET set | |
282 | // and segment flags CLEAR clear. Return NULL if there is none. | |
283 | Output_segment* | |
284 | find_output_segment(elfcpp::PT type, elfcpp::Elf_Word set, | |
285 | elfcpp::Elf_Word clear) const; | |
286 | ||
3802b2dd ILT |
287 | // Return the number of segments we expect to produce. |
288 | size_t | |
289 | expected_segment_count() const; | |
290 | ||
535890bb ILT |
291 | // Set a flag to indicate that an object file uses the static TLS model. |
292 | void | |
293 | set_has_static_tls() | |
294 | { this->has_static_tls_ = true; } | |
295 | ||
296 | // Return true if any object file uses the static TLS model. | |
297 | bool | |
298 | has_static_tls() const | |
299 | { return this->has_static_tls_; } | |
300 | ||
e5756efb ILT |
301 | // Return the options which may be set by a linker script. |
302 | Script_options* | |
303 | script_options() | |
304 | { return this->script_options_; } | |
305 | ||
306 | const Script_options* | |
307 | script_options() const | |
308 | { return this->script_options_; } | |
d391083d | 309 | |
8ed814a9 ILT |
310 | // Compute and write out the build ID if needed. |
311 | void | |
312 | write_build_id(Output_file*) const; | |
313 | ||
516cb3d0 ILT |
314 | // Rewrite output file in binary format. |
315 | void | |
316 | write_binary(Output_file* in) const; | |
317 | ||
ad8f37d1 ILT |
318 | // Dump statistical information to stderr. |
319 | void | |
320 | print_stats() const; | |
321 | ||
a445fddf | 322 | // A list of segments. |
54dc6425 ILT |
323 | |
324 | typedef std::vector<Output_segment*> Segment_list; | |
325 | ||
a445fddf | 326 | // A list of sections. |
54dc6425 | 327 | |
a3ad94ed | 328 | typedef std::vector<Output_section*> Section_list; |
54dc6425 ILT |
329 | |
330 | // The list of information to write out which is not attached to | |
331 | // either a section or a segment. | |
a3ad94ed | 332 | typedef std::vector<Output_data*> Data_list; |
54dc6425 | 333 | |
a445fddf ILT |
334 | // Store the allocated sections into the section list. This is used |
335 | // by the linker script code. | |
336 | void | |
337 | get_allocated_sections(Section_list*) const; | |
338 | ||
919ed24c ILT |
339 | // Make a section for a linker script to hold data. |
340 | Output_section* | |
341 | make_output_section_for_script(const char* name); | |
342 | ||
a445fddf ILT |
343 | // Make a segment. This is used by the linker script code. |
344 | Output_segment* | |
345 | make_output_segment(elfcpp::Elf_Word type, elfcpp::Elf_Word flags); | |
346 | ||
347 | // Return the number of segments. | |
348 | size_t | |
349 | segment_count() const | |
350 | { return this->segment_list_.size(); } | |
351 | ||
352 | // Map from section flags to segment flags. | |
353 | static elfcpp::Elf_Word | |
354 | section_flags_to_segment(elfcpp::Elf_Xword flags); | |
355 | ||
154e0e9a ILT |
356 | // Attach sections to segments. |
357 | void | |
358 | attach_sections_to_segments(); | |
359 | ||
a2fb1b05 ILT |
360 | private: |
361 | Layout(const Layout&); | |
362 | Layout& operator=(const Layout&); | |
363 | ||
364 | // Mapping from .gnu.linkonce section names to output section names. | |
365 | struct Linkonce_mapping | |
366 | { | |
367 | const char* from; | |
368 | int fromlen; | |
369 | const char* to; | |
ead1e424 | 370 | int tolen; |
a2fb1b05 ILT |
371 | }; |
372 | static const Linkonce_mapping linkonce_mapping[]; | |
373 | static const int linkonce_mapping_count; | |
374 | ||
755ab8af ILT |
375 | // During a relocatable link, a list of group sections and |
376 | // signatures. | |
377 | struct Group_signature | |
378 | { | |
379 | // The group section. | |
380 | Output_section* section; | |
381 | // The signature. | |
382 | const char* signature; | |
383 | ||
384 | Group_signature() | |
385 | : section(NULL), signature(NULL) | |
386 | { } | |
387 | ||
388 | Group_signature(Output_section* sectiona, const char* signaturea) | |
389 | : section(sectiona), signature(signaturea) | |
390 | { } | |
391 | }; | |
392 | typedef std::vector<Group_signature> Group_signatures; | |
393 | ||
8ed814a9 ILT |
394 | // Create a .note section, filling in the header. |
395 | Output_section* | |
396 | create_note(const char* name, int note_type, size_t descsz, | |
397 | bool allocate, size_t* trailing_padding); | |
398 | ||
4f211c8b ILT |
399 | // Create a .note section for gold. |
400 | void | |
35cdfc9a ILT |
401 | create_gold_note(); |
402 | ||
403 | // Record whether the stack must be executable. | |
404 | void | |
405 | create_executable_stack_info(const Target*); | |
4f211c8b | 406 | |
8ed814a9 ILT |
407 | // Create a build ID note if needed. |
408 | void | |
409 | create_build_id(); | |
410 | ||
75f65a3e ILT |
411 | // Find the first read-only PT_LOAD segment, creating one if |
412 | // necessary. | |
413 | Output_segment* | |
414 | find_first_load_seg(); | |
415 | ||
7bf1f802 ILT |
416 | // Count the local symbols in the regular symbol table and the dynamic |
417 | // symbol table, and build the respective string pools. | |
418 | void | |
17a1d0a9 | 419 | count_local_symbols(const Task*, const Input_objects*); |
7bf1f802 | 420 | |
54dc6425 ILT |
421 | // Create the output sections for the symbol table. |
422 | void | |
d491d34e ILT |
423 | create_symtab_sections(const Input_objects*, Symbol_table*, |
424 | unsigned int, off_t*); | |
54dc6425 | 425 | |
75f65a3e ILT |
426 | // Create the .shstrtab section. |
427 | Output_section* | |
428 | create_shstrtab(); | |
429 | ||
430 | // Create the section header table. | |
27bc2bce | 431 | void |
d491d34e | 432 | create_shdrs(const Output_section* shstrtab_section, off_t*); |
54dc6425 | 433 | |
dbe717ef ILT |
434 | // Create the dynamic symbol table. |
435 | void | |
9b07f471 ILT |
436 | create_dynamic_symtab(const Input_objects*, Symbol_table*, |
437 | Output_section** pdynstr, | |
14b31740 ILT |
438 | unsigned int* plocal_dynamic_count, |
439 | std::vector<Symbol*>* pdynamic_symbols, | |
440 | Versions* versions); | |
dbe717ef | 441 | |
7bf1f802 ILT |
442 | // Assign offsets to each local portion of the dynamic symbol table. |
443 | void | |
444 | assign_local_dynsym_offsets(const Input_objects*); | |
445 | ||
a3ad94ed | 446 | // Finish the .dynamic section and PT_DYNAMIC segment. |
dbe717ef | 447 | void |
16649710 | 448 | finish_dynamic_section(const Input_objects*, const Symbol_table*); |
dbe717ef ILT |
449 | |
450 | // Create the .interp section and PT_INTERP segment. | |
451 | void | |
452 | create_interp(const Target* target); | |
453 | ||
14b31740 ILT |
454 | // Create the version sections. |
455 | void | |
9025d29d | 456 | create_version_sections(const Versions*, |
46fe1623 | 457 | const Symbol_table*, |
14b31740 ILT |
458 | unsigned int local_symcount, |
459 | const std::vector<Symbol*>& dynamic_symbols, | |
460 | const Output_section* dynstr); | |
461 | ||
462 | template<int size, bool big_endian> | |
463 | void | |
464 | sized_create_version_sections(const Versions* versions, | |
46fe1623 | 465 | const Symbol_table*, |
14b31740 ILT |
466 | unsigned int local_symcount, |
467 | const std::vector<Symbol*>& dynamic_symbols, | |
7d1a9ebb | 468 | const Output_section* dynstr); |
14b31740 | 469 | |
a2fb1b05 ILT |
470 | // Return whether to include this section in the link. |
471 | template<int size, bool big_endian> | |
472 | bool | |
730cdc88 | 473 | include_section(Sized_relobj<size, big_endian>* object, const char* name, |
a2fb1b05 ILT |
474 | const elfcpp::Shdr<size, big_endian>&); |
475 | ||
ead1e424 ILT |
476 | // Return the output section name to use given an input section |
477 | // name. Set *PLEN to the length of the name. *PLEN must be | |
478 | // initialized to the length of NAME. | |
479 | static const char* | |
480 | output_section_name(const char* name, size_t* plen); | |
481 | ||
a2fb1b05 | 482 | // Return the output section name to use for a linkonce section |
ead1e424 | 483 | // name. PLEN is as for output_section_name. |
a2fb1b05 | 484 | static const char* |
ead1e424 ILT |
485 | linkonce_output_name(const char* name, size_t* plen); |
486 | ||
d491d34e ILT |
487 | // Return the number of allocated output sections. |
488 | size_t | |
489 | allocated_output_section_count() const; | |
490 | ||
ead1e424 ILT |
491 | // Return the output section for NAME, TYPE and FLAGS. |
492 | Output_section* | |
f0641a0b ILT |
493 | get_output_section(const char* name, Stringpool::Key name_key, |
494 | elfcpp::Elf_Word type, elfcpp::Elf_Xword flags); | |
a2fb1b05 | 495 | |
a445fddf ILT |
496 | // Choose the output section for NAME in RELOBJ. |
497 | Output_section* | |
498 | choose_output_section(const Relobj* relobj, const char* name, | |
499 | elfcpp::Elf_Word type, elfcpp::Elf_Xword flags, | |
154e0e9a | 500 | bool is_input_section); |
a445fddf | 501 | |
a2fb1b05 ILT |
502 | // Create a new Output_section. |
503 | Output_section* | |
504 | make_output_section(const char* name, elfcpp::Elf_Word type, | |
505 | elfcpp::Elf_Xword flags); | |
506 | ||
4e2b1697 ILT |
507 | // Attach a section to a segment. |
508 | void | |
154e0e9a | 509 | attach_section_to_segment(Output_section*); |
4e2b1697 | 510 | |
154e0e9a | 511 | // Attach an allocated section to a segment. |
1650c4ff | 512 | void |
154e0e9a | 513 | attach_allocated_section_to_segment(Output_section*); |
1650c4ff | 514 | |
dbe717ef ILT |
515 | // Set the final file offsets of all the segments. |
516 | off_t | |
517 | set_segment_offsets(const Target*, Output_segment*, unsigned int* pshndx); | |
518 | ||
6a74a719 ILT |
519 | // Set the file offsets of the sections when doing a relocatable |
520 | // link. | |
521 | off_t | |
522 | set_relocatable_section_offsets(Output_data*, unsigned int* pshndx); | |
523 | ||
86887060 | 524 | // Set the final file offsets of all the sections not associated |
9a0910c3 ILT |
525 | // with a segment. We set section offsets in three passes: the |
526 | // first handles all allocated sections, the second sections that | |
17a1d0a9 ILT |
527 | // require postprocessing, and the last the late-bound STRTAB |
528 | // sections (probably only shstrtab, which is the one we care about | |
529 | // because it holds section names). | |
9a0910c3 ILT |
530 | enum Section_offset_pass |
531 | { | |
532 | BEFORE_INPUT_SECTIONS_PASS, | |
17a1d0a9 ILT |
533 | POSTPROCESSING_SECTIONS_PASS, |
534 | STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS | |
9a0910c3 | 535 | }; |
dbe717ef | 536 | off_t |
9a0910c3 ILT |
537 | set_section_offsets(off_t, Section_offset_pass pass); |
538 | ||
86887060 ILT |
539 | // Set the final section indexes of all the sections not associated |
540 | // with a segment. Returns the next unused index. | |
541 | unsigned int | |
542 | set_section_indexes(unsigned int pshndx); | |
dbe717ef | 543 | |
a445fddf ILT |
544 | // Set the section addresses when using a script. |
545 | Output_segment* | |
546 | set_section_addresses_from_script(Symbol_table*); | |
547 | ||
a2fb1b05 ILT |
548 | // Return whether SEG1 comes before SEG2 in the output file. |
549 | static bool | |
b3168e9d | 550 | segment_precedes(const Output_segment* seg1, const Output_segment* seg2); |
a2fb1b05 | 551 | |
a2fb1b05 ILT |
552 | // A mapping used for group signatures. |
553 | typedef Unordered_map<std::string, bool> Signatures; | |
554 | ||
555 | // Mapping from input section name/type/flags to output section. We | |
556 | // use canonicalized strings here. | |
557 | ||
f0641a0b | 558 | typedef std::pair<Stringpool::Key, |
a2fb1b05 ILT |
559 | std::pair<elfcpp::Elf_Word, elfcpp::Elf_Xword> > Key; |
560 | ||
561 | struct Hash_key | |
562 | { | |
563 | size_t | |
564 | operator()(const Key& k) const; | |
565 | }; | |
566 | ||
567 | typedef Unordered_map<Key, Output_section*, Hash_key> Section_name_map; | |
568 | ||
569 | // A comparison class for segments. | |
570 | ||
571 | struct Compare_segments | |
572 | { | |
573 | bool | |
574 | operator()(const Output_segment* seg1, const Output_segment* seg2) | |
575 | { return Layout::segment_precedes(seg1, seg2); } | |
576 | }; | |
577 | ||
a2fb1b05 ILT |
578 | // A reference to the options on the command line. |
579 | const General_options& options_; | |
e5756efb ILT |
580 | // Information set by scripts or by command line options. |
581 | Script_options* script_options_; | |
a2fb1b05 ILT |
582 | // The output section names. |
583 | Stringpool namepool_; | |
75f65a3e ILT |
584 | // The output symbol names. |
585 | Stringpool sympool_; | |
a3ad94ed ILT |
586 | // The dynamic strings, if needed. |
587 | Stringpool dynpool_; | |
a2fb1b05 ILT |
588 | // The list of group sections and linkonce sections which we have seen. |
589 | Signatures signatures_; | |
590 | // The mapping from input section name/type/flags to output sections. | |
591 | Section_name_map section_name_map_; | |
592 | // The list of output segments. | |
593 | Segment_list segment_list_; | |
a3ad94ed ILT |
594 | // The list of output sections. |
595 | Section_list section_list_; | |
a2fb1b05 ILT |
596 | // The list of output sections which are not attached to any output |
597 | // segment. | |
a3ad94ed | 598 | Section_list unattached_section_list_; |
154e0e9a ILT |
599 | // Whether we have attached the sections to the segments. |
600 | bool sections_are_attached_; | |
a3ad94ed ILT |
601 | // The list of unattached Output_data objects which require special |
602 | // handling because they are not Output_sections. | |
61ba1cf9 | 603 | Data_list special_output_list_; |
27bc2bce ILT |
604 | // The section headers. |
605 | Output_section_headers* section_headers_; | |
92e059d8 ILT |
606 | // A pointer to the PT_TLS segment if there is one. |
607 | Output_segment* tls_segment_; | |
a3ad94ed ILT |
608 | // The SHT_SYMTAB output section. |
609 | Output_section* symtab_section_; | |
d491d34e ILT |
610 | // The SHT_SYMTAB_SHNDX for the regular symbol table if there is one. |
611 | Output_symtab_xindex* symtab_xindex_; | |
a3ad94ed ILT |
612 | // The SHT_DYNSYM output section if there is one. |
613 | Output_section* dynsym_section_; | |
d491d34e ILT |
614 | // The SHT_SYMTAB_SHNDX for the dynamic symbol table if there is one. |
615 | Output_symtab_xindex* dynsym_xindex_; | |
a3ad94ed ILT |
616 | // The SHT_DYNAMIC output section if there is one. |
617 | Output_section* dynamic_section_; | |
16649710 ILT |
618 | // The dynamic data which goes into dynamic_section_. |
619 | Output_data_dynamic* dynamic_data_; | |
730cdc88 | 620 | // The exception frame output section if there is one. |
3151305a | 621 | Output_section* eh_frame_section_; |
730cdc88 ILT |
622 | // The exception frame data for eh_frame_section_. |
623 | Eh_frame* eh_frame_data_; | |
2c38906f ILT |
624 | // Whether we have added eh_frame_data_ to the .eh_frame section. |
625 | bool added_eh_frame_data_; | |
730cdc88 ILT |
626 | // The exception frame header output section if there is one. |
627 | Output_section* eh_frame_hdr_section_; | |
8ed814a9 ILT |
628 | // The space for the build ID checksum if there is one. |
629 | Output_section_data* build_id_note_; | |
755ab8af ILT |
630 | // A list of group sections and their signatures. |
631 | Group_signatures group_signatures_; | |
e44fcf3b ILT |
632 | // The size of the output file. |
633 | off_t output_file_size_; | |
35cdfc9a ILT |
634 | // Whether we have seen an object file marked to require an |
635 | // executable stack. | |
636 | bool input_requires_executable_stack_; | |
637 | // Whether we have seen at least one object file with an executable | |
638 | // stack marker. | |
639 | bool input_with_gnu_stack_note_; | |
640 | // Whether we have seen at least one object file without an | |
641 | // executable stack marker. | |
642 | bool input_without_gnu_stack_note_; | |
535890bb ILT |
643 | // Whether we have seen an object file that uses the static TLS model. |
644 | bool has_static_tls_; | |
17a1d0a9 ILT |
645 | // Whether any sections require postprocessing. |
646 | bool any_postprocessing_sections_; | |
61ba1cf9 ILT |
647 | }; |
648 | ||
730cdc88 ILT |
649 | // This task handles writing out data in output sections which is not |
650 | // part of an input section, or which requires special handling. When | |
651 | // this is done, it unblocks both output_sections_blocker and | |
652 | // final_blocker. | |
653 | ||
654 | class Write_sections_task : public Task | |
655 | { | |
656 | public: | |
657 | Write_sections_task(const Layout* layout, Output_file* of, | |
658 | Task_token* output_sections_blocker, | |
659 | Task_token* final_blocker) | |
660 | : layout_(layout), of_(of), | |
661 | output_sections_blocker_(output_sections_blocker), | |
662 | final_blocker_(final_blocker) | |
663 | { } | |
664 | ||
665 | // The standard Task methods. | |
666 | ||
17a1d0a9 ILT |
667 | Task_token* |
668 | is_runnable(); | |
730cdc88 | 669 | |
17a1d0a9 ILT |
670 | void |
671 | locks(Task_locker*); | |
730cdc88 ILT |
672 | |
673 | void | |
674 | run(Workqueue*); | |
675 | ||
c7912668 ILT |
676 | std::string |
677 | get_name() const | |
678 | { return "Write_sections_task"; } | |
679 | ||
730cdc88 ILT |
680 | private: |
681 | class Write_sections_locker; | |
682 | ||
683 | const Layout* layout_; | |
684 | Output_file* of_; | |
685 | Task_token* output_sections_blocker_; | |
686 | Task_token* final_blocker_; | |
687 | }; | |
688 | ||
61ba1cf9 ILT |
689 | // This task handles writing out data which is not part of a section |
690 | // or segment. | |
691 | ||
692 | class Write_data_task : public Task | |
693 | { | |
694 | public: | |
a3ad94ed | 695 | Write_data_task(const Layout* layout, const Symbol_table* symtab, |
9025d29d ILT |
696 | Output_file* of, Task_token* final_blocker) |
697 | : layout_(layout), symtab_(symtab), of_(of), final_blocker_(final_blocker) | |
61ba1cf9 ILT |
698 | { } |
699 | ||
700 | // The standard Task methods. | |
701 | ||
17a1d0a9 ILT |
702 | Task_token* |
703 | is_runnable(); | |
61ba1cf9 | 704 | |
17a1d0a9 ILT |
705 | void |
706 | locks(Task_locker*); | |
61ba1cf9 ILT |
707 | |
708 | void | |
709 | run(Workqueue*); | |
710 | ||
c7912668 ILT |
711 | std::string |
712 | get_name() const | |
713 | { return "Write_data_task"; } | |
714 | ||
61ba1cf9 ILT |
715 | private: |
716 | const Layout* layout_; | |
a3ad94ed | 717 | const Symbol_table* symtab_; |
61ba1cf9 ILT |
718 | Output_file* of_; |
719 | Task_token* final_blocker_; | |
720 | }; | |
721 | ||
722 | // This task handles writing out the global symbols. | |
723 | ||
724 | class Write_symbols_task : public Task | |
725 | { | |
726 | public: | |
d491d34e | 727 | Write_symbols_task(const Layout* layout, const Symbol_table* symtab, |
9a2d6984 | 728 | const Input_objects* input_objects, |
16649710 ILT |
729 | const Stringpool* sympool, const Stringpool* dynpool, |
730 | Output_file* of, Task_token* final_blocker) | |
d491d34e ILT |
731 | : layout_(layout), symtab_(symtab), input_objects_(input_objects), |
732 | sympool_(sympool), dynpool_(dynpool), of_(of), | |
733 | final_blocker_(final_blocker) | |
61ba1cf9 ILT |
734 | { } |
735 | ||
736 | // The standard Task methods. | |
737 | ||
17a1d0a9 ILT |
738 | Task_token* |
739 | is_runnable(); | |
61ba1cf9 | 740 | |
17a1d0a9 ILT |
741 | void |
742 | locks(Task_locker*); | |
61ba1cf9 ILT |
743 | |
744 | void | |
745 | run(Workqueue*); | |
746 | ||
c7912668 ILT |
747 | std::string |
748 | get_name() const | |
749 | { return "Write_symbols_task"; } | |
750 | ||
61ba1cf9 | 751 | private: |
d491d34e | 752 | const Layout* layout_; |
61ba1cf9 | 753 | const Symbol_table* symtab_; |
9a2d6984 | 754 | const Input_objects* input_objects_; |
61ba1cf9 | 755 | const Stringpool* sympool_; |
16649710 | 756 | const Stringpool* dynpool_; |
61ba1cf9 ILT |
757 | Output_file* of_; |
758 | Task_token* final_blocker_; | |
759 | }; | |
760 | ||
730cdc88 ILT |
761 | // This task handles writing out data in output sections which can't |
762 | // be written out until all the input sections have been handled. | |
763 | // This is for sections whose contents is based on the contents of | |
764 | // other output sections. | |
765 | ||
766 | class Write_after_input_sections_task : public Task | |
767 | { | |
768 | public: | |
27bc2bce | 769 | Write_after_input_sections_task(Layout* layout, Output_file* of, |
730cdc88 ILT |
770 | Task_token* input_sections_blocker, |
771 | Task_token* final_blocker) | |
772 | : layout_(layout), of_(of), | |
773 | input_sections_blocker_(input_sections_blocker), | |
774 | final_blocker_(final_blocker) | |
775 | { } | |
776 | ||
777 | // The standard Task methods. | |
778 | ||
17a1d0a9 ILT |
779 | Task_token* |
780 | is_runnable(); | |
730cdc88 | 781 | |
17a1d0a9 ILT |
782 | void |
783 | locks(Task_locker*); | |
730cdc88 ILT |
784 | |
785 | void | |
786 | run(Workqueue*); | |
787 | ||
c7912668 ILT |
788 | std::string |
789 | get_name() const | |
790 | { return "Write_after_input_sections_task"; } | |
791 | ||
730cdc88 | 792 | private: |
27bc2bce | 793 | Layout* layout_; |
730cdc88 ILT |
794 | Output_file* of_; |
795 | Task_token* input_sections_blocker_; | |
796 | Task_token* final_blocker_; | |
797 | }; | |
798 | ||
92e059d8 | 799 | // This task function handles closing the file. |
61ba1cf9 | 800 | |
92e059d8 | 801 | class Close_task_runner : public Task_function_runner |
61ba1cf9 ILT |
802 | { |
803 | public: | |
516cb3d0 ILT |
804 | Close_task_runner(const General_options* options, const Layout* layout, |
805 | Output_file* of) | |
806 | : options_(options), layout_(layout), of_(of) | |
61ba1cf9 ILT |
807 | { } |
808 | ||
92e059d8 | 809 | // Run the operation. |
61ba1cf9 | 810 | void |
17a1d0a9 | 811 | run(Workqueue*, const Task*); |
61ba1cf9 ILT |
812 | |
813 | private: | |
516cb3d0 ILT |
814 | const General_options* options_; |
815 | const Layout* layout_; | |
61ba1cf9 | 816 | Output_file* of_; |
a2fb1b05 ILT |
817 | }; |
818 | ||
ead1e424 ILT |
819 | // A small helper function to align an address. |
820 | ||
821 | inline uint64_t | |
822 | align_address(uint64_t address, uint64_t addralign) | |
823 | { | |
824 | if (addralign != 0) | |
825 | address = (address + addralign - 1) &~ (addralign - 1); | |
826 | return address; | |
827 | } | |
828 | ||
a2fb1b05 ILT |
829 | } // End namespace gold. |
830 | ||
831 | #endif // !defined(GOLD_LAYOUT_H) |