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