1 // layout.h -- lay out output file sections for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
34 #include "workqueue.h"
37 #include "stringpool.h"
42 class General_options;
43 class Incremental_inputs;
47 class Output_section_data;
49 class Output_section_headers;
50 class Output_segment_headers;
51 class Output_file_header;
54 class Output_data_reloc_generic;
55 class Output_data_dynamic;
56 class Output_symtab_xindex;
57 class Output_reduced_debug_abbrev_section;
58 class Output_reduced_debug_info_section;
62 // This task function handles mapping the input sections to output
63 // sections and laying them out in memory.
65 class Layout_task_runner : public Task_function_runner
68 // OPTIONS is the command line options, INPUT_OBJECTS is the list of
69 // input objects, SYMTAB is the symbol table, LAYOUT is the layout
71 Layout_task_runner(const General_options& options,
72 const Input_objects* input_objects,
77 : options_(options), input_objects_(input_objects), symtab_(symtab),
78 target_(target), layout_(layout), mapfile_(mapfile)
83 run(Workqueue*, const Task*);
86 Layout_task_runner(const Layout_task_runner&);
87 Layout_task_runner& operator=(const Layout_task_runner&);
89 const General_options& options_;
90 const Input_objects* input_objects_;
91 Symbol_table* symtab_;
97 // This class holds information about the comdat group or
98 // .gnu.linkonce section that will be kept for a given signature.
103 // For a comdat group, we build a mapping from the name of each
104 // section in the group to the section index and the size in object.
105 // When we discard a group in some other object file, we use this
106 // map to figure out which kept section the discarded section is
107 // associated with. We then use that mapping when processing relocs
108 // against discarded sections.
109 struct Comdat_section_info
111 // The section index.
116 Comdat_section_info(unsigned int a_shndx, uint64_t a_size)
117 : shndx(a_shndx), size(a_size)
121 // Most comdat groups have only one or two sections, so we use a
122 // std::map rather than an Unordered_map to optimize for that case
123 // without paying too heavily for groups with more sections.
124 typedef std::map<std::string, Comdat_section_info> Comdat_group;
128 : object_(NULL), shndx_(0), is_comdat_(false), is_group_name_(false)
129 { this->u_.linkonce_size = 0; }
131 // We need to support copies for the signature map in the Layout
132 // object, but we should never copy an object after it has been
133 // marked as a comdat section.
134 Kept_section(const Kept_section& k)
135 : object_(k.object_), shndx_(k.shndx_), is_comdat_(false),
136 is_group_name_(k.is_group_name_)
138 gold_assert(!k.is_comdat_);
139 this->u_.linkonce_size = 0;
144 if (this->is_comdat_)
145 delete this->u_.group_sections;
148 // The object where this section lives.
151 { return this->object_; }
155 set_object(Relobj* object)
157 gold_assert(this->object_ == NULL);
158 this->object_ = object;
161 // The section index.
164 { return this->shndx_; }
166 // Set the section index.
168 set_shndx(unsigned int shndx)
170 gold_assert(this->shndx_ == 0);
171 this->shndx_ = shndx;
174 // Whether this is a comdat group.
177 { return this->is_comdat_; }
179 // Set that this is a comdat group.
183 gold_assert(!this->is_comdat_);
184 this->is_comdat_ = true;
185 this->u_.group_sections = new Comdat_group();
188 // Whether this is associated with the name of a group or section
189 // rather than the symbol name derived from a linkonce section.
191 is_group_name() const
192 { return this->is_group_name_; }
194 // Note that this represents a comdat group rather than a single
198 { this->is_group_name_ = true; }
200 // Add a section to the group list.
202 add_comdat_section(const std::string& name, unsigned int shndx,
205 gold_assert(this->is_comdat_);
206 Comdat_section_info sinfo(shndx, size);
207 this->u_.group_sections->insert(std::make_pair(name, sinfo));
210 // Look for a section name in the group list, and return whether it
211 // was found. If found, returns the section index and size.
213 find_comdat_section(const std::string& name, unsigned int *pshndx,
214 uint64_t *psize) const
216 gold_assert(this->is_comdat_);
217 Comdat_group::const_iterator p = this->u_.group_sections->find(name);
218 if (p == this->u_.group_sections->end())
220 *pshndx = p->second.shndx;
221 *psize = p->second.size;
225 // If there is only one section in the group list, return true, and
226 // return the section index and size.
228 find_single_comdat_section(unsigned int *pshndx, uint64_t *psize) const
230 gold_assert(this->is_comdat_);
231 if (this->u_.group_sections->size() != 1)
233 Comdat_group::const_iterator p = this->u_.group_sections->begin();
234 *pshndx = p->second.shndx;
235 *psize = p->second.size;
239 // Return the size of a linkonce section.
241 linkonce_size() const
243 gold_assert(!this->is_comdat_);
244 return this->u_.linkonce_size;
247 // Set the size of a linkonce section.
249 set_linkonce_size(uint64_t size)
251 gold_assert(!this->is_comdat_);
252 this->u_.linkonce_size = size;
257 Kept_section& operator=(const Kept_section&);
259 // The object containing the comdat group or .gnu.linkonce section.
261 // Index of the group section for comdats and the section itself for
264 // True if this is for a comdat group rather than a .gnu.linkonce
267 // The Kept_sections are values of a mapping, that maps names to
268 // them. This field is true if this struct is associated with the
269 // name of a comdat or .gnu.linkonce, false if it is associated with
270 // the name of a symbol obtained from the .gnu.linkonce.* name
271 // through some heuristics.
275 // If the is_comdat_ field is true, this holds a map from names of
276 // the sections in the group to section indexes in object_ and to
278 Comdat_group* group_sections;
279 // If the is_comdat_ field is false, this holds the size of the
281 uint64_t linkonce_size;
285 // This class handles the details of laying out input sections.
290 Layout(int number_of_input_files, Script_options*);
294 delete this->relaxation_debug_check_;
295 delete this->segment_states_;
298 // Given an input section SHNDX, named NAME, with data in SHDR, from
299 // the object file OBJECT, return the output section where this
300 // input section should go. RELOC_SHNDX is the index of a
301 // relocation section which applies to this section, or 0 if none,
302 // or -1U if more than one. RELOC_TYPE is the type of the
303 // relocation section if there is one. Set *OFFSET to the offset
304 // within the output section.
305 template<int size, bool big_endian>
307 layout(Sized_relobj<size, big_endian> *object, unsigned int shndx,
308 const char* name, const elfcpp::Shdr<size, big_endian>& shdr,
309 unsigned int reloc_shndx, unsigned int reloc_type, off_t* offset);
311 // Layout an input reloc section when doing a relocatable link. The
312 // section is RELOC_SHNDX in OBJECT, with data in SHDR.
313 // DATA_SECTION is the reloc section to which it refers. RR is the
314 // relocatable information.
315 template<int size, bool big_endian>
317 layout_reloc(Sized_relobj<size, big_endian>* object,
318 unsigned int reloc_shndx,
319 const elfcpp::Shdr<size, big_endian>& shdr,
320 Output_section* data_section,
321 Relocatable_relocs* rr);
323 // Layout a group section when doing a relocatable link.
324 template<int size, bool big_endian>
326 layout_group(Symbol_table* symtab,
327 Sized_relobj<size, big_endian>* object,
328 unsigned int group_shndx,
329 const char* group_section_name,
330 const char* signature,
331 const elfcpp::Shdr<size, big_endian>& shdr,
332 elfcpp::Elf_Word flags,
333 std::vector<unsigned int>* shndxes);
335 // Like layout, only for exception frame sections. OBJECT is an
336 // object file. SYMBOLS is the contents of the symbol table
337 // section, with size SYMBOLS_SIZE. SYMBOL_NAMES is the contents of
338 // the symbol name section, with size SYMBOL_NAMES_SIZE. SHNDX is a
339 // .eh_frame section in OBJECT. SHDR is the section header.
340 // RELOC_SHNDX is the index of a relocation section which applies to
341 // this section, or 0 if none, or -1U if more than one. RELOC_TYPE
342 // is the type of the relocation section if there is one. This
343 // returns the output section, and sets *OFFSET to the offset.
344 template<int size, bool big_endian>
346 layout_eh_frame(Sized_relobj<size, big_endian>* object,
347 const unsigned char* symbols,
349 const unsigned char* symbol_names,
350 off_t symbol_names_size,
352 const elfcpp::Shdr<size, big_endian>& shdr,
353 unsigned int reloc_shndx, unsigned int reloc_type,
356 // Handle a GNU stack note. This is called once per input object
357 // file. SEEN_GNU_STACK is true if the object file has a
358 // .note.GNU-stack section. GNU_STACK_FLAGS is the section flags
359 // from that section if there was one.
361 layout_gnu_stack(bool seen_gnu_stack, uint64_t gnu_stack_flags);
363 // Add an Output_section_data to the layout. This is used for
364 // special sections like the GOT section. IS_DYNAMIC_LINKER_SECTION
365 // is true for sections which are used by the dynamic linker, such
366 // as dynamic reloc sections. IS_RELRO is true for relro sections.
367 // IS_LAST_RELRO is true for the last relro section.
368 // IS_FIRST_NON_RELRO is true for the first section after the relro
371 add_output_section_data(const char* name, elfcpp::Elf_Word type,
372 elfcpp::Elf_Xword flags,
373 Output_section_data*, bool is_dynamic_linker_section,
374 bool is_relro, bool is_last_relro,
375 bool is_first_non_relro);
377 // Increase the size of the relro segment by this much.
379 increase_relro(unsigned int s)
380 { this->increase_relro_ += s; }
382 // Create dynamic sections if necessary.
384 create_initial_dynamic_sections(Symbol_table*);
386 // Define __start and __stop symbols for output sections.
388 define_section_symbols(Symbol_table*);
390 // Create automatic note sections.
394 // Create sections for linker scripts.
396 create_script_sections()
397 { this->script_options_->create_script_sections(this); }
399 // Define symbols from any linker script.
401 define_script_symbols(Symbol_table* symtab)
402 { this->script_options_->add_symbols_to_table(symtab); }
404 // Define symbols for group signatures.
406 define_group_signatures(Symbol_table*);
408 // Return the Stringpool used for symbol names.
411 { return &this->sympool_; }
413 // Return the Stringpool used for dynamic symbol names and dynamic
417 { return &this->dynpool_; }
419 // Return the symtab_xindex section used to hold large section
420 // indexes for the normal symbol table.
421 Output_symtab_xindex*
422 symtab_xindex() const
423 { return this->symtab_xindex_; }
425 // Return the dynsym_xindex section used to hold large section
426 // indexes for the dynamic symbol table.
427 Output_symtab_xindex*
428 dynsym_xindex() const
429 { return this->dynsym_xindex_; }
431 // Return whether a section is a .gnu.linkonce section, given the
434 is_linkonce(const char* name)
435 { return strncmp(name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; }
437 // Whether we have added an input section.
439 have_added_input_section() const
440 { return this->have_added_input_section_; }
442 // Return true if a section is a debugging section.
444 is_debug_info_section(const char* name)
446 // Debugging sections can only be recognized by name.
447 return (strncmp(name, ".debug", sizeof(".debug") - 1) == 0
448 || strncmp(name, ".gnu.linkonce.wi.",
449 sizeof(".gnu.linkonce.wi.") - 1) == 0
450 || strncmp(name, ".line", sizeof(".line") - 1) == 0
451 || strncmp(name, ".stab", sizeof(".stab") - 1) == 0);
454 // Check if a comdat group or .gnu.linkonce section with the given
455 // NAME is selected for the link. If there is already a section,
456 // *KEPT_SECTION is set to point to the signature and the function
457 // returns false. Otherwise, OBJECT, SHNDX,IS_COMDAT, and
458 // IS_GROUP_NAME are recorded for this NAME in the layout object,
459 // *KEPT_SECTION is set to the internal copy and the function return
462 find_or_add_kept_section(const std::string& name, Relobj* object,
463 unsigned int shndx, bool is_comdat,
464 bool is_group_name, Kept_section** kept_section);
466 // Finalize the layout after all the input sections have been added.
468 finalize(const Input_objects*, Symbol_table*, Target*, const Task*);
470 // Return whether any sections require postprocessing.
472 any_postprocessing_sections() const
473 { return this->any_postprocessing_sections_; }
475 // Return the size of the output file.
477 output_file_size() const
478 { return this->output_file_size_; }
480 // Return the TLS segment. This will return NULL if there isn't
484 { return this->tls_segment_; }
486 // Return the normal symbol table.
488 symtab_section() const
490 gold_assert(this->symtab_section_ != NULL);
491 return this->symtab_section_;
494 // Return the dynamic symbol table.
496 dynsym_section() const
498 gold_assert(this->dynsym_section_ != NULL);
499 return this->dynsym_section_;
502 // Return the dynamic tags.
505 { return this->dynamic_data_; }
507 // Write out the output sections.
509 write_output_sections(Output_file* of) const;
511 // Write out data not associated with an input file or the symbol
514 write_data(const Symbol_table*, Output_file*) const;
516 // Write out output sections which can not be written until all the
517 // input sections are complete.
519 write_sections_after_input_sections(Output_file* of);
521 // Return an output section named NAME, or NULL if there is none.
523 find_output_section(const char* name) const;
525 // Return an output segment of type TYPE, with segment flags SET set
526 // and segment flags CLEAR clear. Return NULL if there is none.
528 find_output_segment(elfcpp::PT type, elfcpp::Elf_Word set,
529 elfcpp::Elf_Word clear) const;
531 // Return the number of segments we expect to produce.
533 expected_segment_count() const;
535 // Set a flag to indicate that an object file uses the static TLS model.
538 { this->has_static_tls_ = true; }
540 // Return true if any object file uses the static TLS model.
542 has_static_tls() const
543 { return this->has_static_tls_; }
545 // Return the options which may be set by a linker script.
548 { return this->script_options_; }
550 const Script_options*
551 script_options() const
552 { return this->script_options_; }
554 // Return the object managing inputs in incremental build. NULL in
555 // non-incremental builds.
558 { return this->incremental_inputs_; }
560 // For the target-specific code to add dynamic tags which are common
563 add_target_dynamic_tags(bool use_rel, const Output_data* plt_got,
564 const Output_data* plt_rel,
565 const Output_data_reloc_generic* dyn_rel,
566 bool add_debug, bool dynrel_includes_plt);
568 // Compute and write out the build ID if needed.
570 write_build_id(Output_file*) const;
572 // Rewrite output file in binary format.
574 write_binary(Output_file* in) const;
576 // Print output sections to the map file.
578 print_to_mapfile(Mapfile*) const;
580 // Dump statistical information to stderr.
584 // A list of segments.
586 typedef std::vector<Output_segment*> Segment_list;
588 // A list of sections.
590 typedef std::vector<Output_section*> Section_list;
592 // The list of information to write out which is not attached to
593 // either a section or a segment.
594 typedef std::vector<Output_data*> Data_list;
596 // Store the allocated sections into the section list. This is used
597 // by the linker script code.
599 get_allocated_sections(Section_list*) const;
601 // Make a section for a linker script to hold data.
603 make_output_section_for_script(const char* name);
605 // Make a segment. This is used by the linker script code.
607 make_output_segment(elfcpp::Elf_Word type, elfcpp::Elf_Word flags);
609 // Return the number of segments.
611 segment_count() const
612 { return this->segment_list_.size(); }
614 // Map from section flags to segment flags.
615 static elfcpp::Elf_Word
616 section_flags_to_segment(elfcpp::Elf_Xword flags);
618 // Attach sections to segments.
620 attach_sections_to_segments();
622 // For relaxation clean up, we need to know output section data created
623 // from a linker script.
625 new_output_section_data_from_script(Output_section_data* posd)
627 if (this->record_output_section_data_from_script_)
628 this->script_output_section_data_list_.push_back(posd);
631 // Return section list.
634 { return this->section_list_; }
637 Layout(const Layout&);
638 Layout& operator=(const Layout&);
640 // Mapping from input section names to output section names.
641 struct Section_name_mapping
648 static const Section_name_mapping section_name_mapping[];
649 static const int section_name_mapping_count;
651 // During a relocatable link, a list of group sections and
653 struct Group_signature
655 // The group section.
656 Output_section* section;
658 const char* signature;
661 : section(NULL), signature(NULL)
664 Group_signature(Output_section* sectiona, const char* signaturea)
665 : section(sectiona), signature(signaturea)
668 typedef std::vector<Group_signature> Group_signatures;
670 // Create a note section, filling in the header.
672 create_note(const char* name, int note_type, const char *section_name,
673 size_t descsz, bool allocate, size_t* trailing_padding);
675 // Create a note section for gold version.
679 // Record whether the stack must be executable.
681 create_executable_stack_info();
683 // Create a build ID note if needed.
687 // Link .stab and .stabstr sections.
689 link_stabs_sections();
691 // Create .gnu_incremental_inputs and .gnu_incremental_strtab sections needed
692 // for the next run of incremental linking to check what has changed.
694 create_incremental_info_sections();
696 // Find the first read-only PT_LOAD segment, creating one if
699 find_first_load_seg();
701 // Count the local symbols in the regular symbol table and the dynamic
702 // symbol table, and build the respective string pools.
704 count_local_symbols(const Task*, const Input_objects*);
706 // Create the output sections for the symbol table.
708 create_symtab_sections(const Input_objects*, Symbol_table*,
709 unsigned int, off_t*);
711 // Create the .shstrtab section.
715 // Create the section header table.
717 create_shdrs(const Output_section* shstrtab_section, off_t*);
719 // Create the dynamic symbol table.
721 create_dynamic_symtab(const Input_objects*, Symbol_table*,
722 Output_section** pdynstr,
723 unsigned int* plocal_dynamic_count,
724 std::vector<Symbol*>* pdynamic_symbols,
727 // Assign offsets to each local portion of the dynamic symbol table.
729 assign_local_dynsym_offsets(const Input_objects*);
731 // Finish the .dynamic section and PT_DYNAMIC segment.
733 finish_dynamic_section(const Input_objects*, const Symbol_table*);
735 // Set the size of the _DYNAMIC symbol.
737 set_dynamic_symbol_size(const Symbol_table*);
739 // Create the .interp section and PT_INTERP segment.
741 create_interp(const Target* target);
743 // Create the version sections.
745 create_version_sections(const Versions*,
747 unsigned int local_symcount,
748 const std::vector<Symbol*>& dynamic_symbols,
749 const Output_section* dynstr);
751 template<int size, bool big_endian>
753 sized_create_version_sections(const Versions* versions,
755 unsigned int local_symcount,
756 const std::vector<Symbol*>& dynamic_symbols,
757 const Output_section* dynstr);
759 // Return whether to include this section in the link.
760 template<int size, bool big_endian>
762 include_section(Sized_relobj<size, big_endian>* object, const char* name,
763 const elfcpp::Shdr<size, big_endian>&);
765 // Return the output section name to use given an input section
766 // name. Set *PLEN to the length of the name. *PLEN must be
767 // initialized to the length of NAME.
769 output_section_name(const char* name, size_t* plen);
771 // Return the number of allocated output sections.
773 allocated_output_section_count() const;
775 // Return the output section for NAME, TYPE and FLAGS.
777 get_output_section(const char* name, Stringpool::Key name_key,
778 elfcpp::Elf_Word type, elfcpp::Elf_Xword flags,
779 bool is_interp, bool is_dynamic_linker_section,
780 bool is_relro, bool is_last_relro,
781 bool is_first_non_relro);
783 // Choose the output section for NAME in RELOBJ.
785 choose_output_section(const Relobj* relobj, const char* name,
786 elfcpp::Elf_Word type, elfcpp::Elf_Xword flags,
787 bool is_input_section, bool is_interp,
788 bool is_dynamic_linker_section, bool is_relro,
789 bool is_last_relro, bool is_first_non_relro);
791 // Create a new Output_section.
793 make_output_section(const char* name, elfcpp::Elf_Word type,
794 elfcpp::Elf_Xword flags, bool is_interp,
795 bool is_dynamic_linker_section, bool is_relro,
796 bool is_last_relro, bool is_first_non_relro);
798 // Attach a section to a segment.
800 attach_section_to_segment(Output_section*);
802 // Attach an allocated section to a segment.
804 attach_allocated_section_to_segment(Output_section*);
806 // Set the final file offsets of all the segments.
808 set_segment_offsets(const Target*, Output_segment*, unsigned int* pshndx);
810 // Set the file offsets of the sections when doing a relocatable
813 set_relocatable_section_offsets(Output_data*, unsigned int* pshndx);
815 // Set the final file offsets of all the sections not associated
816 // with a segment. We set section offsets in three passes: the
817 // first handles all allocated sections, the second sections that
818 // require postprocessing, and the last the late-bound STRTAB
819 // sections (probably only shstrtab, which is the one we care about
820 // because it holds section names).
821 enum Section_offset_pass
823 BEFORE_INPUT_SECTIONS_PASS,
824 POSTPROCESSING_SECTIONS_PASS,
825 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
828 set_section_offsets(off_t, Section_offset_pass pass);
830 // Set the final section indexes of all the sections not associated
831 // with a segment. Returns the next unused index.
833 set_section_indexes(unsigned int pshndx);
835 // Set the section addresses when using a script.
837 set_section_addresses_from_script(Symbol_table*);
839 // Find appropriate places or orphan sections in a script.
841 place_orphan_sections_in_script();
843 // Return whether SEG1 comes before SEG2 in the output file.
845 segment_precedes(const Output_segment* seg1, const Output_segment* seg2);
847 // Use to save and restore segments during relaxation.
848 typedef Unordered_map<const Output_segment*, const Output_segment*>
851 // Save states of current output segments.
853 save_segments(Segment_states*);
855 // Restore output segment states.
857 restore_segments(const Segment_states*);
859 // Clean up after relaxation so that it is possible to lay out the
860 // sections and segments again.
862 clean_up_after_relaxation();
864 // Doing preparation work for relaxation. This is factored out to make
865 // Layout::finalized a bit smaller and easier to read.
867 prepare_for_relaxation();
869 // Main body of the relaxation loop, which lays out the section.
871 relaxation_loop_body(int, Target*, Symbol_table*, Output_segment**,
872 Output_segment*, Output_segment_headers*,
873 Output_file_header*, unsigned int*);
875 // A mapping used for kept comdats/.gnu.linkonce group signatures.
876 typedef Unordered_map<std::string, Kept_section> Signatures;
878 // Mapping from input section name/type/flags to output section. We
879 // use canonicalized strings here.
881 typedef std::pair<Stringpool::Key,
882 std::pair<elfcpp::Elf_Word, elfcpp::Elf_Xword> > Key;
887 operator()(const Key& k) const;
890 typedef Unordered_map<Key, Output_section*, Hash_key> Section_name_map;
892 // A comparison class for segments.
894 struct Compare_segments
897 operator()(const Output_segment* seg1, const Output_segment* seg2)
898 { return Layout::segment_precedes(seg1, seg2); }
901 typedef std::vector<Output_section_data*> Output_section_data_list;
903 // Debug checker class.
904 class Relaxation_debug_check
907 Relaxation_debug_check()
911 // Check that sections and special data are in reset states.
913 check_output_data_for_reset_values(const Layout::Section_list&,
914 const Layout::Data_list&);
916 // Record information of a section list.
918 read_sections(const Layout::Section_list&);
920 // Verify a section list with recorded information.
922 verify_sections(const Layout::Section_list&);
925 // Information we care about a section.
928 // Output section described by this.
929 Output_section* output_section;
938 // Section information.
939 std::vector<Section_info> section_infos_;
942 // The number of input files, for sizing tables.
943 int number_of_input_files_;
944 // Information set by scripts or by command line options.
945 Script_options* script_options_;
946 // The output section names.
947 Stringpool namepool_;
948 // The output symbol names.
950 // The dynamic strings, if needed.
952 // The list of group sections and linkonce sections which we have seen.
953 Signatures signatures_;
954 // The mapping from input section name/type/flags to output sections.
955 Section_name_map section_name_map_;
956 // The list of output segments.
957 Segment_list segment_list_;
958 // The list of output sections.
959 Section_list section_list_;
960 // The list of output sections which are not attached to any output
962 Section_list unattached_section_list_;
963 // The list of unattached Output_data objects which require special
964 // handling because they are not Output_sections.
965 Data_list special_output_list_;
966 // The section headers.
967 Output_section_headers* section_headers_;
968 // A pointer to the PT_TLS segment if there is one.
969 Output_segment* tls_segment_;
970 // A pointer to the PT_GNU_RELRO segment if there is one.
971 Output_segment* relro_segment_;
972 // A backend may increase the size of the PT_GNU_RELRO segment if
973 // there is one. This is the amount to increase it by.
974 unsigned int increase_relro_;
975 // The SHT_SYMTAB output section.
976 Output_section* symtab_section_;
977 // The SHT_SYMTAB_SHNDX for the regular symbol table if there is one.
978 Output_symtab_xindex* symtab_xindex_;
979 // The SHT_DYNSYM output section if there is one.
980 Output_section* dynsym_section_;
981 // The SHT_SYMTAB_SHNDX for the dynamic symbol table if there is one.
982 Output_symtab_xindex* dynsym_xindex_;
983 // The SHT_DYNAMIC output section if there is one.
984 Output_section* dynamic_section_;
985 // The _DYNAMIC symbol if there is one.
986 Symbol* dynamic_symbol_;
987 // The dynamic data which goes into dynamic_section_.
988 Output_data_dynamic* dynamic_data_;
989 // The exception frame output section if there is one.
990 Output_section* eh_frame_section_;
991 // The exception frame data for eh_frame_section_.
992 Eh_frame* eh_frame_data_;
993 // Whether we have added eh_frame_data_ to the .eh_frame section.
994 bool added_eh_frame_data_;
995 // The exception frame header output section if there is one.
996 Output_section* eh_frame_hdr_section_;
997 // The space for the build ID checksum if there is one.
998 Output_section_data* build_id_note_;
999 // The output section containing dwarf abbreviations
1000 Output_reduced_debug_abbrev_section* debug_abbrev_;
1001 // The output section containing the dwarf debug info tree
1002 Output_reduced_debug_info_section* debug_info_;
1003 // A list of group sections and their signatures.
1004 Group_signatures group_signatures_;
1005 // The size of the output file.
1006 off_t output_file_size_;
1007 // Whether we have added an input section to an output section.
1008 bool have_added_input_section_;
1009 // Whether we have attached the sections to the segments.
1010 bool sections_are_attached_;
1011 // Whether we have seen an object file marked to require an
1012 // executable stack.
1013 bool input_requires_executable_stack_;
1014 // Whether we have seen at least one object file with an executable
1016 bool input_with_gnu_stack_note_;
1017 // Whether we have seen at least one object file without an
1018 // executable stack marker.
1019 bool input_without_gnu_stack_note_;
1020 // Whether we have seen an object file that uses the static TLS model.
1021 bool has_static_tls_;
1022 // Whether any sections require postprocessing.
1023 bool any_postprocessing_sections_;
1024 // Whether we have resized the signatures_ hash table.
1025 bool resized_signatures_;
1026 // Whether we have created a .stab*str output section.
1027 bool have_stabstr_section_;
1028 // In incremental build, holds information check the inputs and build the
1029 // .gnu_incremental_inputs section.
1030 Incremental_inputs* incremental_inputs_;
1031 // Whether we record output section data created in script
1032 bool record_output_section_data_from_script_;
1033 // List of output data that needs to be removed at relexation clean up.
1034 Output_section_data_list script_output_section_data_list_;
1035 // Structure to save segment states before entering the relaxation loop.
1036 Segment_states* segment_states_;
1037 // A relaxation debug checker. We only create one when in debugging mode.
1038 Relaxation_debug_check* relaxation_debug_check_;
1041 // This task handles writing out data in output sections which is not
1042 // part of an input section, or which requires special handling. When
1043 // this is done, it unblocks both output_sections_blocker and
1046 class Write_sections_task : public Task
1049 Write_sections_task(const Layout* layout, Output_file* of,
1050 Task_token* output_sections_blocker,
1051 Task_token* final_blocker)
1052 : layout_(layout), of_(of),
1053 output_sections_blocker_(output_sections_blocker),
1054 final_blocker_(final_blocker)
1057 // The standard Task methods.
1063 locks(Task_locker*);
1070 { return "Write_sections_task"; }
1073 class Write_sections_locker;
1075 const Layout* layout_;
1077 Task_token* output_sections_blocker_;
1078 Task_token* final_blocker_;
1081 // This task handles writing out data which is not part of a section
1084 class Write_data_task : public Task
1087 Write_data_task(const Layout* layout, const Symbol_table* symtab,
1088 Output_file* of, Task_token* final_blocker)
1089 : layout_(layout), symtab_(symtab), of_(of), final_blocker_(final_blocker)
1092 // The standard Task methods.
1098 locks(Task_locker*);
1105 { return "Write_data_task"; }
1108 const Layout* layout_;
1109 const Symbol_table* symtab_;
1111 Task_token* final_blocker_;
1114 // This task handles writing out the global symbols.
1116 class Write_symbols_task : public Task
1119 Write_symbols_task(const Layout* layout, const Symbol_table* symtab,
1120 const Input_objects* input_objects,
1121 const Stringpool* sympool, const Stringpool* dynpool,
1122 Output_file* of, Task_token* final_blocker)
1123 : layout_(layout), symtab_(symtab), input_objects_(input_objects),
1124 sympool_(sympool), dynpool_(dynpool), of_(of),
1125 final_blocker_(final_blocker)
1128 // The standard Task methods.
1134 locks(Task_locker*);
1141 { return "Write_symbols_task"; }
1144 const Layout* layout_;
1145 const Symbol_table* symtab_;
1146 const Input_objects* input_objects_;
1147 const Stringpool* sympool_;
1148 const Stringpool* dynpool_;
1150 Task_token* final_blocker_;
1153 // This task handles writing out data in output sections which can't
1154 // be written out until all the input sections have been handled.
1155 // This is for sections whose contents is based on the contents of
1156 // other output sections.
1158 class Write_after_input_sections_task : public Task
1161 Write_after_input_sections_task(Layout* layout, Output_file* of,
1162 Task_token* input_sections_blocker,
1163 Task_token* final_blocker)
1164 : layout_(layout), of_(of),
1165 input_sections_blocker_(input_sections_blocker),
1166 final_blocker_(final_blocker)
1169 // The standard Task methods.
1175 locks(Task_locker*);
1182 { return "Write_after_input_sections_task"; }
1187 Task_token* input_sections_blocker_;
1188 Task_token* final_blocker_;
1191 // This task function handles closing the file.
1193 class Close_task_runner : public Task_function_runner
1196 Close_task_runner(const General_options* options, const Layout* layout,
1198 : options_(options), layout_(layout), of_(of)
1201 // Run the operation.
1203 run(Workqueue*, const Task*);
1206 const General_options* options_;
1207 const Layout* layout_;
1211 // A small helper function to align an address.
1214 align_address(uint64_t address, uint64_t addralign)
1217 address = (address + addralign - 1) &~ (addralign - 1);
1221 } // End namespace gold.
1223 #endif // !defined(GOLD_LAYOUT_H)