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