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