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