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