]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/layout.h
* mapfile.cc: New file.
[thirdparty/binutils-gdb.git] / gold / layout.h
1 // layout.h -- lay out output file sections for gold -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008 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
23 #ifndef GOLD_LAYOUT_H
24 #define GOLD_LAYOUT_H
25
26 #include <cstring>
27 #include <list>
28 #include <string>
29 #include <utility>
30 #include <vector>
31
32 #include "script.h"
33 #include "workqueue.h"
34 #include "object.h"
35 #include "dynobj.h"
36 #include "stringpool.h"
37
38 namespace gold
39 {
40
41 class General_options;
42 class Input_objects;
43 class Mapfile;
44 class Symbol_table;
45 class Output_section_data;
46 class Output_section;
47 class Output_section_headers;
48 class Output_segment;
49 class Output_data;
50 class Output_data_dynamic;
51 class Output_symtab_xindex;
52 class Eh_frame;
53 class Target;
54
55 // This task function handles mapping the input sections to output
56 // sections and laying them out in memory.
57
58 class Layout_task_runner : public Task_function_runner
59 {
60 public:
61 // OPTIONS is the command line options, INPUT_OBJECTS is the list of
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,
67 Target* target,
68 Layout* layout,
69 Mapfile* mapfile)
70 : options_(options), input_objects_(input_objects), symtab_(symtab),
71 target_(target), layout_(layout), mapfile_(mapfile)
72 { }
73
74 // Run the operation.
75 void
76 run(Workqueue*, const Task*);
77
78 private:
79 Layout_task_runner(const Layout_task_runner&);
80 Layout_task_runner& operator=(const Layout_task_runner&);
81
82 const General_options& options_;
83 const Input_objects* input_objects_;
84 Symbol_table* symtab_;
85 Target* target_;
86 Layout* layout_;
87 Mapfile* mapfile_;
88 };
89
90 // This class handles the details of laying out input sections.
91
92 class Layout
93 {
94 public:
95 Layout(const General_options& options, Script_options*);
96
97 // Given an input section SHNDX, named NAME, with data in SHDR, from
98 // the object file OBJECT, return the output section where this
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.
104 template<int size, bool big_endian>
105 Output_section*
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
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,
131 elfcpp::Elf_Word flags,
132 std::vector<unsigned int>* shndxes);
133
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);
154
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
162 // Add an Output_section_data to the layout. This is used for
163 // special sections like the GOT section.
164 Output_section*
165 add_output_section_data(const char* name, elfcpp::Elf_Word type,
166 elfcpp::Elf_Xword flags,
167 Output_section_data*);
168
169 // Create dynamic sections if necessary.
170 void
171 create_initial_dynamic_sections(Symbol_table*);
172
173 // Define __start and __stop symbols for output sections.
174 void
175 define_section_symbols(Symbol_table*);
176
177 // Create sections for linker scripts.
178 void
179 create_script_sections()
180 { this->script_options_->create_script_sections(this); }
181
182 // Define symbols from any linker script.
183 void
184 define_script_symbols(Symbol_table* symtab)
185 { this->script_options_->add_symbols_to_table(symtab); }
186
187 // Define symbols for group signatures.
188 void
189 define_group_signatures(Symbol_table*);
190
191 // Return the Stringpool used for symbol names.
192 const Stringpool*
193 sympool() const
194 { return &this->sympool_; }
195
196 // Return the Stringpool used for dynamic symbol names and dynamic
197 // tags.
198 const Stringpool*
199 dynpool() const
200 { return &this->dynpool_; }
201
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
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
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
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
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;
243
244 // Finalize the layout after all the input sections have been added.
245 off_t
246 finalize(const Input_objects*, Symbol_table*, Target*, const Task*);
247
248 // Return whether any sections require postprocessing.
249 bool
250 any_postprocessing_sections() const
251 { return this->any_postprocessing_sections_; }
252
253 // Return the size of the output file.
254 off_t
255 output_file_size() const
256 { return this->output_file_size_; }
257
258 // Return the TLS segment. This will return NULL if there isn't
259 // one.
260 Output_segment*
261 tls_segment() const
262 { return this->tls_segment_; }
263
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
285 // Write out the output sections.
286 void
287 write_output_sections(Output_file* of) const;
288
289 // Write out data not associated with an input file or the symbol
290 // table.
291 void
292 write_data(const Symbol_table*, Output_file*) const;
293
294 // Write out output sections which can not be written until all the
295 // input sections are complete.
296 void
297 write_sections_after_input_sections(Output_file* of);
298
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
309 // Return the number of segments we expect to produce.
310 size_t
311 expected_segment_count() const;
312
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
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_; }
331
332 // Compute and write out the build ID if needed.
333 void
334 write_build_id(Output_file*) const;
335
336 // Rewrite output file in binary format.
337 void
338 write_binary(Output_file* in) const;
339
340 // Print output sections to the map file.
341 void
342 print_to_mapfile(Mapfile*) const;
343
344 // Dump statistical information to stderr.
345 void
346 print_stats() const;
347
348 // A list of segments.
349
350 typedef std::vector<Output_segment*> Segment_list;
351
352 // A list of sections.
353
354 typedef std::vector<Output_section*> Section_list;
355
356 // The list of information to write out which is not attached to
357 // either a section or a segment.
358 typedef std::vector<Output_data*> Data_list;
359
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
365 // Make a section for a linker script to hold data.
366 Output_section*
367 make_output_section_for_script(const char* name);
368
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
382 // Attach sections to segments.
383 void
384 attach_sections_to_segments();
385
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;
396 int tolen;
397 };
398 static const Linkonce_mapping linkonce_mapping[];
399 static const int linkonce_mapping_count;
400
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
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
425 // Create a .note section for gold.
426 void
427 create_gold_note();
428
429 // Record whether the stack must be executable.
430 void
431 create_executable_stack_info(const Target*);
432
433 // Create a build ID note if needed.
434 void
435 create_build_id();
436
437 // Find the first read-only PT_LOAD segment, creating one if
438 // necessary.
439 Output_segment*
440 find_first_load_seg();
441
442 // Count the local symbols in the regular symbol table and the dynamic
443 // symbol table, and build the respective string pools.
444 void
445 count_local_symbols(const Task*, const Input_objects*);
446
447 // Create the output sections for the symbol table.
448 void
449 create_symtab_sections(const Input_objects*, Symbol_table*,
450 unsigned int, off_t*);
451
452 // Create the .shstrtab section.
453 Output_section*
454 create_shstrtab();
455
456 // Create the section header table.
457 void
458 create_shdrs(const Output_section* shstrtab_section, off_t*);
459
460 // Create the dynamic symbol table.
461 void
462 create_dynamic_symtab(const Input_objects*, Symbol_table*,
463 Output_section** pdynstr,
464 unsigned int* plocal_dynamic_count,
465 std::vector<Symbol*>* pdynamic_symbols,
466 Versions* versions);
467
468 // Assign offsets to each local portion of the dynamic symbol table.
469 void
470 assign_local_dynsym_offsets(const Input_objects*);
471
472 // Finish the .dynamic section and PT_DYNAMIC segment.
473 void
474 finish_dynamic_section(const Input_objects*, const Symbol_table*);
475
476 // Create the .interp section and PT_INTERP segment.
477 void
478 create_interp(const Target* target);
479
480 // Create the version sections.
481 void
482 create_version_sections(const Versions*,
483 const Symbol_table*,
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,
491 const Symbol_table*,
492 unsigned int local_symcount,
493 const std::vector<Symbol*>& dynamic_symbols,
494 const Output_section* dynstr);
495
496 // Return whether to include this section in the link.
497 template<int size, bool big_endian>
498 bool
499 include_section(Sized_relobj<size, big_endian>* object, const char* name,
500 const elfcpp::Shdr<size, big_endian>&);
501
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
508 // Return the output section name to use for a linkonce section
509 // name. PLEN is as for output_section_name.
510 static const char*
511 linkonce_output_name(const char* name, size_t* plen);
512
513 // Return the number of allocated output sections.
514 size_t
515 allocated_output_section_count() const;
516
517 // Return the output section for NAME, TYPE and FLAGS.
518 Output_section*
519 get_output_section(const char* name, Stringpool::Key name_key,
520 elfcpp::Elf_Word type, elfcpp::Elf_Xword flags);
521
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,
526 bool is_input_section);
527
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
533 // Attach a section to a segment.
534 void
535 attach_section_to_segment(Output_section*);
536
537 // Attach an allocated section to a segment.
538 void
539 attach_allocated_section_to_segment(Output_section*);
540
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
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
550 // Set the final file offsets of all the sections not associated
551 // with a segment. We set section offsets in three passes: the
552 // first handles all allocated sections, the second sections that
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).
556 enum Section_offset_pass
557 {
558 BEFORE_INPUT_SECTIONS_PASS,
559 POSTPROCESSING_SECTIONS_PASS,
560 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
561 };
562 off_t
563 set_section_offsets(off_t, Section_offset_pass pass);
564
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);
569
570 // Set the section addresses when using a script.
571 Output_segment*
572 set_section_addresses_from_script(Symbol_table*);
573
574 // Return whether SEG1 comes before SEG2 in the output file.
575 static bool
576 segment_precedes(const Output_segment* seg1, const Output_segment* seg2);
577
578 // A mapping used for group signatures.
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;
592
593 // Mapping from input section name/type/flags to output section. We
594 // use canonicalized strings here.
595
596 typedef std::pair<Stringpool::Key,
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
616 // A reference to the options on the command line.
617 const General_options& options_;
618 // Information set by scripts or by command line options.
619 Script_options* script_options_;
620 // The output section names.
621 Stringpool namepool_;
622 // The output symbol names.
623 Stringpool sympool_;
624 // The dynamic strings, if needed.
625 Stringpool dynpool_;
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_;
632 // The list of output sections.
633 Section_list section_list_;
634 // The list of output sections which are not attached to any output
635 // segment.
636 Section_list unattached_section_list_;
637 // Whether we have attached the sections to the segments.
638 bool sections_are_attached_;
639 // The list of unattached Output_data objects which require special
640 // handling because they are not Output_sections.
641 Data_list special_output_list_;
642 // The section headers.
643 Output_section_headers* section_headers_;
644 // A pointer to the PT_TLS segment if there is one.
645 Output_segment* tls_segment_;
646 // A pointer to the PT_GNU_RELRO segment if there is one.
647 Output_segment* relro_segment_;
648 // The SHT_SYMTAB output section.
649 Output_section* symtab_section_;
650 // The SHT_SYMTAB_SHNDX for the regular symbol table if there is one.
651 Output_symtab_xindex* symtab_xindex_;
652 // The SHT_DYNSYM output section if there is one.
653 Output_section* dynsym_section_;
654 // The SHT_SYMTAB_SHNDX for the dynamic symbol table if there is one.
655 Output_symtab_xindex* dynsym_xindex_;
656 // The SHT_DYNAMIC output section if there is one.
657 Output_section* dynamic_section_;
658 // The dynamic data which goes into dynamic_section_.
659 Output_data_dynamic* dynamic_data_;
660 // The exception frame output section if there is one.
661 Output_section* eh_frame_section_;
662 // The exception frame data for eh_frame_section_.
663 Eh_frame* eh_frame_data_;
664 // Whether we have added eh_frame_data_ to the .eh_frame section.
665 bool added_eh_frame_data_;
666 // The exception frame header output section if there is one.
667 Output_section* eh_frame_hdr_section_;
668 // The space for the build ID checksum if there is one.
669 Output_section_data* build_id_note_;
670 // A list of group sections and their signatures.
671 Group_signatures group_signatures_;
672 // The size of the output file.
673 off_t output_file_size_;
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_;
683 // Whether we have seen an object file that uses the static TLS model.
684 bool has_static_tls_;
685 // Whether any sections require postprocessing.
686 bool any_postprocessing_sections_;
687 };
688
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
694 class 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
707 Task_token*
708 is_runnable();
709
710 void
711 locks(Task_locker*);
712
713 void
714 run(Workqueue*);
715
716 std::string
717 get_name() const
718 { return "Write_sections_task"; }
719
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
729 // This task handles writing out data which is not part of a section
730 // or segment.
731
732 class Write_data_task : public Task
733 {
734 public:
735 Write_data_task(const Layout* layout, const Symbol_table* symtab,
736 Output_file* of, Task_token* final_blocker)
737 : layout_(layout), symtab_(symtab), of_(of), final_blocker_(final_blocker)
738 { }
739
740 // The standard Task methods.
741
742 Task_token*
743 is_runnable();
744
745 void
746 locks(Task_locker*);
747
748 void
749 run(Workqueue*);
750
751 std::string
752 get_name() const
753 { return "Write_data_task"; }
754
755 private:
756 const Layout* layout_;
757 const Symbol_table* symtab_;
758 Output_file* of_;
759 Task_token* final_blocker_;
760 };
761
762 // This task handles writing out the global symbols.
763
764 class Write_symbols_task : public Task
765 {
766 public:
767 Write_symbols_task(const Layout* layout, const Symbol_table* symtab,
768 const Input_objects* input_objects,
769 const Stringpool* sympool, const Stringpool* dynpool,
770 Output_file* of, Task_token* final_blocker)
771 : layout_(layout), symtab_(symtab), input_objects_(input_objects),
772 sympool_(sympool), dynpool_(dynpool), of_(of),
773 final_blocker_(final_blocker)
774 { }
775
776 // The standard Task methods.
777
778 Task_token*
779 is_runnable();
780
781 void
782 locks(Task_locker*);
783
784 void
785 run(Workqueue*);
786
787 std::string
788 get_name() const
789 { return "Write_symbols_task"; }
790
791 private:
792 const Layout* layout_;
793 const Symbol_table* symtab_;
794 const Input_objects* input_objects_;
795 const Stringpool* sympool_;
796 const Stringpool* dynpool_;
797 Output_file* of_;
798 Task_token* final_blocker_;
799 };
800
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
806 class Write_after_input_sections_task : public Task
807 {
808 public:
809 Write_after_input_sections_task(Layout* layout, Output_file* of,
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
819 Task_token*
820 is_runnable();
821
822 void
823 locks(Task_locker*);
824
825 void
826 run(Workqueue*);
827
828 std::string
829 get_name() const
830 { return "Write_after_input_sections_task"; }
831
832 private:
833 Layout* layout_;
834 Output_file* of_;
835 Task_token* input_sections_blocker_;
836 Task_token* final_blocker_;
837 };
838
839 // This task function handles closing the file.
840
841 class Close_task_runner : public Task_function_runner
842 {
843 public:
844 Close_task_runner(const General_options* options, const Layout* layout,
845 Output_file* of)
846 : options_(options), layout_(layout), of_(of)
847 { }
848
849 // Run the operation.
850 void
851 run(Workqueue*, const Task*);
852
853 private:
854 const General_options* options_;
855 const Layout* layout_;
856 Output_file* of_;
857 };
858
859 // A small helper function to align an address.
860
861 inline uint64_t
862 align_address(uint64_t address, uint64_t addralign)
863 {
864 if (addralign != 0)
865 address = (address + addralign - 1) &~ (addralign - 1);
866 return address;
867 }
868
869 } // End namespace gold.
870
871 #endif // !defined(GOLD_LAYOUT_H)