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_dynamic
;
55 class Output_symtab_xindex
;
56 class Output_reduced_debug_abbrev_section
;
57 class Output_reduced_debug_info_section
;
61 // This task function handles mapping the input sections to output
62 // sections and laying them out in memory.
64 class Layout_task_runner
: public Task_function_runner
67 // OPTIONS is the command line options, INPUT_OBJECTS is the list of
68 // input objects, SYMTAB is the symbol table, LAYOUT is the layout
70 Layout_task_runner(const General_options
& options
,
71 const Input_objects
* input_objects
,
76 : options_(options
), input_objects_(input_objects
), symtab_(symtab
),
77 target_(target
), layout_(layout
), mapfile_(mapfile
)
82 run(Workqueue
*, const Task
*);
85 Layout_task_runner(const Layout_task_runner
&);
86 Layout_task_runner
& operator=(const Layout_task_runner
&);
88 const General_options
& options_
;
89 const Input_objects
* input_objects_
;
90 Symbol_table
* symtab_
;
96 // This class holds information about the comdat group or
97 // .gnu.linkonce section that will be kept for a given signature.
102 // For a comdat group, we build a mapping from the name of each
103 // section in the group to the section index and the size in object.
104 // When we discard a group in some other object file, we use this
105 // map to figure out which kept section the discarded section is
106 // associated with. We then use that mapping when processing relocs
107 // against discarded sections.
108 struct Comdat_section_info
110 // The section index.
115 Comdat_section_info(unsigned int a_shndx
, uint64_t a_size
)
116 : shndx(a_shndx
), size(a_size
)
120 // Most comdat groups have only one or two sections, so we use a
121 // std::map rather than an Unordered_map to optimize for that case
122 // without paying too heavily for groups with more sections.
123 typedef std::map
<std::string
, Comdat_section_info
> Comdat_group
;
127 : object_(NULL
), shndx_(0), is_comdat_(false), is_group_name_(false)
128 { this->u_
.linkonce_size
= 0; }
130 // We need to support copies for the signature map in the Layout
131 // object, but we should never copy an object after it has been
132 // marked as a comdat section.
133 Kept_section(const Kept_section
& k
)
134 : object_(k
.object_
), shndx_(k
.shndx_
), is_comdat_(false),
135 is_group_name_(k
.is_group_name_
)
137 gold_assert(!k
.is_comdat_
);
138 this->u_
.linkonce_size
= 0;
143 if (this->is_comdat_
)
144 delete this->u_
.group_sections
;
147 // The object where this section lives.
150 { return this->object_
; }
154 set_object(Relobj
* object
)
156 gold_assert(this->object_
== NULL
);
157 this->object_
= object
;
160 // The section index.
163 { return this->shndx_
; }
165 // Set the section index.
167 set_shndx(unsigned int shndx
)
169 gold_assert(this->shndx_
== 0);
170 this->shndx_
= shndx
;
173 // Whether this is a comdat group.
176 { return this->is_comdat_
; }
178 // Set that this is a comdat group.
182 gold_assert(!this->is_comdat_
);
183 this->is_comdat_
= true;
184 this->u_
.group_sections
= new Comdat_group();
187 // Whether this is associated with the name of a group or section
188 // rather than the symbol name derived from a linkonce section.
190 is_group_name() const
191 { return this->is_group_name_
; }
193 // Note that this represents a comdat group rather than a single
197 { this->is_group_name_
= true; }
199 // Add a section to the group list.
201 add_comdat_section(const std::string
& name
, unsigned int shndx
,
204 gold_assert(this->is_comdat_
);
205 Comdat_section_info
sinfo(shndx
, size
);
206 this->u_
.group_sections
->insert(std::make_pair(name
, sinfo
));
209 // Look for a section name in the group list, and return whether it
210 // was found. If found, returns the section index and size.
212 find_comdat_section(const std::string
& name
, unsigned int *pshndx
,
213 uint64_t *psize
) const
215 gold_assert(this->is_comdat_
);
216 Comdat_group::const_iterator p
= this->u_
.group_sections
->find(name
);
217 if (p
== this->u_
.group_sections
->end())
219 *pshndx
= p
->second
.shndx
;
220 *psize
= p
->second
.size
;
224 // If there is only one section in the group list, return true, and
225 // return the section index and size.
227 find_single_comdat_section(unsigned int *pshndx
, uint64_t *psize
) const
229 gold_assert(this->is_comdat_
);
230 if (this->u_
.group_sections
->size() != 1)
232 Comdat_group::const_iterator p
= this->u_
.group_sections
->begin();
233 *pshndx
= p
->second
.shndx
;
234 *psize
= p
->second
.size
;
238 // Return the size of a linkonce section.
240 linkonce_size() const
242 gold_assert(!this->is_comdat_
);
243 return this->u_
.linkonce_size
;
246 // Set the size of a linkonce section.
248 set_linkonce_size(uint64_t size
)
250 gold_assert(!this->is_comdat_
);
251 this->u_
.linkonce_size
= size
;
256 Kept_section
& operator=(const Kept_section
&);
258 // The object containing the comdat group or .gnu.linkonce section.
260 // Index of the group section for comdats and the section itself for
263 // True if this is for a comdat group rather than a .gnu.linkonce
266 // The Kept_sections are values of a mapping, that maps names to
267 // them. This field is true if this struct is associated with the
268 // name of a comdat or .gnu.linkonce, false if it is associated with
269 // the name of a symbol obtained from the .gnu.linkonce.* name
270 // through some heuristics.
274 // If the is_comdat_ field is true, this holds a map from names of
275 // the sections in the group to section indexes in object_ and to
277 Comdat_group
* group_sections
;
278 // If the is_comdat_ field is false, this holds the size of the
280 uint64_t linkonce_size
;
284 // This class handles the details of laying out input sections.
289 Layout(int number_of_input_files
, Script_options
*);
293 delete this->relaxation_debug_check_
;
294 delete this->segment_states_
;
297 // Given an input section SHNDX, named NAME, with data in SHDR, from
298 // the object file OBJECT, return the output section where this
299 // input section should go. RELOC_SHNDX is the index of a
300 // relocation section which applies to this section, or 0 if none,
301 // or -1U if more than one. RELOC_TYPE is the type of the
302 // relocation section if there is one. Set *OFFSET to the offset
303 // within the output section.
304 template<int size
, bool big_endian
>
306 layout(Sized_relobj
<size
, big_endian
> *object
, unsigned int shndx
,
307 const char* name
, const elfcpp::Shdr
<size
, big_endian
>& shdr
,
308 unsigned int reloc_shndx
, unsigned int reloc_type
, off_t
* offset
);
310 // Layout an input reloc section when doing a relocatable link. The
311 // section is RELOC_SHNDX in OBJECT, with data in SHDR.
312 // DATA_SECTION is the reloc section to which it refers. RR is the
313 // relocatable information.
314 template<int size
, bool big_endian
>
316 layout_reloc(Sized_relobj
<size
, big_endian
>* object
,
317 unsigned int reloc_shndx
,
318 const elfcpp::Shdr
<size
, big_endian
>& shdr
,
319 Output_section
* data_section
,
320 Relocatable_relocs
* rr
);
322 // Layout a group section when doing a relocatable link.
323 template<int size
, bool big_endian
>
325 layout_group(Symbol_table
* symtab
,
326 Sized_relobj
<size
, big_endian
>* object
,
327 unsigned int group_shndx
,
328 const char* group_section_name
,
329 const char* signature
,
330 const elfcpp::Shdr
<size
, big_endian
>& shdr
,
331 elfcpp::Elf_Word flags
,
332 std::vector
<unsigned int>* shndxes
);
334 // Like layout, only for exception frame sections. OBJECT is an
335 // object file. SYMBOLS is the contents of the symbol table
336 // section, with size SYMBOLS_SIZE. SYMBOL_NAMES is the contents of
337 // the symbol name section, with size SYMBOL_NAMES_SIZE. SHNDX is a
338 // .eh_frame section in OBJECT. SHDR is the section header.
339 // RELOC_SHNDX is the index of a relocation section which applies to
340 // this section, or 0 if none, or -1U if more than one. RELOC_TYPE
341 // is the type of the relocation section if there is one. This
342 // returns the output section, and sets *OFFSET to the offset.
343 template<int size
, bool big_endian
>
345 layout_eh_frame(Sized_relobj
<size
, big_endian
>* object
,
346 const unsigned char* symbols
,
348 const unsigned char* symbol_names
,
349 off_t symbol_names_size
,
351 const elfcpp::Shdr
<size
, big_endian
>& shdr
,
352 unsigned int reloc_shndx
, unsigned int reloc_type
,
355 // Handle a GNU stack note. This is called once per input object
356 // file. SEEN_GNU_STACK is true if the object file has a
357 // .note.GNU-stack section. GNU_STACK_FLAGS is the section flags
358 // from that section if there was one.
360 layout_gnu_stack(bool seen_gnu_stack
, uint64_t gnu_stack_flags
);
362 // Add an Output_section_data to the layout. This is used for
363 // special sections like the GOT section. IS_DYNAMIC_LINKER_SECTION
364 // is true for sections which are used by the dynamic linker, such
365 // as dynamic reloc sections. IS_RELRO is true for relro sections.
366 // IS_LAST_RELRO is true for the last relro section.
367 // IS_FIRST_NON_RELRO is true for the first section after the relro
370 add_output_section_data(const char* name
, elfcpp::Elf_Word type
,
371 elfcpp::Elf_Xword flags
,
372 Output_section_data
*, bool is_dynamic_linker_section
,
373 bool is_relro
, bool is_last_relro
,
374 bool is_first_non_relro
);
376 // Increase the size of the relro segment by this much.
378 increase_relro(unsigned int s
)
379 { this->increase_relro_
+= s
; }
381 // Create dynamic sections if necessary.
383 create_initial_dynamic_sections(Symbol_table
*);
385 // Define __start and __stop symbols for output sections.
387 define_section_symbols(Symbol_table
*);
389 // Create automatic note sections.
393 // Create sections for linker scripts.
395 create_script_sections()
396 { this->script_options_
->create_script_sections(this); }
398 // Define symbols from any linker script.
400 define_script_symbols(Symbol_table
* symtab
)
401 { this->script_options_
->add_symbols_to_table(symtab
); }
403 // Define symbols for group signatures.
405 define_group_signatures(Symbol_table
*);
407 // Return the Stringpool used for symbol names.
410 { return &this->sympool_
; }
412 // Return the Stringpool used for dynamic symbol names and dynamic
416 { return &this->dynpool_
; }
418 // Return the symtab_xindex section used to hold large section
419 // indexes for the normal symbol table.
420 Output_symtab_xindex
*
421 symtab_xindex() const
422 { return this->symtab_xindex_
; }
424 // Return the dynsym_xindex section used to hold large section
425 // indexes for the dynamic symbol table.
426 Output_symtab_xindex
*
427 dynsym_xindex() const
428 { return this->dynsym_xindex_
; }
430 // Return whether a section is a .gnu.linkonce section, given the
433 is_linkonce(const char* name
)
434 { return strncmp(name
, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; }
436 // Whether we have added an input section.
438 have_added_input_section() const
439 { return this->have_added_input_section_
; }
441 // Return true if a section is a debugging section.
443 is_debug_info_section(const char* name
)
445 // Debugging sections can only be recognized by name.
446 return (strncmp(name
, ".debug", sizeof(".debug") - 1) == 0
447 || strncmp(name
, ".gnu.linkonce.wi.",
448 sizeof(".gnu.linkonce.wi.") - 1) == 0
449 || strncmp(name
, ".line", sizeof(".line") - 1) == 0
450 || strncmp(name
, ".stab", sizeof(".stab") - 1) == 0);
453 // Check if a comdat group or .gnu.linkonce section with the given
454 // NAME is selected for the link. If there is already a section,
455 // *KEPT_SECTION is set to point to the signature and the function
456 // returns false. Otherwise, OBJECT, SHNDX,IS_COMDAT, and
457 // IS_GROUP_NAME are recorded for this NAME in the layout object,
458 // *KEPT_SECTION is set to the internal copy and the function return
461 find_or_add_kept_section(const std::string
& name
, Relobj
* object
,
462 unsigned int shndx
, bool is_comdat
,
463 bool is_group_name
, Kept_section
** kept_section
);
465 // Finalize the layout after all the input sections have been added.
467 finalize(const Input_objects
*, Symbol_table
*, Target
*, const Task
*);
469 // Return whether any sections require postprocessing.
471 any_postprocessing_sections() const
472 { return this->any_postprocessing_sections_
; }
474 // Return the size of the output file.
476 output_file_size() const
477 { return this->output_file_size_
; }
479 // Return the TLS segment. This will return NULL if there isn't
483 { return this->tls_segment_
; }
485 // Return the normal symbol table.
487 symtab_section() const
489 gold_assert(this->symtab_section_
!= NULL
);
490 return this->symtab_section_
;
493 // Return the dynamic symbol table.
495 dynsym_section() const
497 gold_assert(this->dynsym_section_
!= NULL
);
498 return this->dynsym_section_
;
501 // Return the dynamic tags.
504 { return this->dynamic_data_
; }
506 // Write out the output sections.
508 write_output_sections(Output_file
* of
) const;
510 // Write out data not associated with an input file or the symbol
513 write_data(const Symbol_table
*, Output_file
*) const;
515 // Write out output sections which can not be written until all the
516 // input sections are complete.
518 write_sections_after_input_sections(Output_file
* of
);
520 // Return an output section named NAME, or NULL if there is none.
522 find_output_section(const char* name
) const;
524 // Return an output segment of type TYPE, with segment flags SET set
525 // and segment flags CLEAR clear. Return NULL if there is none.
527 find_output_segment(elfcpp::PT type
, elfcpp::Elf_Word set
,
528 elfcpp::Elf_Word clear
) const;
530 // Return the number of segments we expect to produce.
532 expected_segment_count() const;
534 // Set a flag to indicate that an object file uses the static TLS model.
537 { this->has_static_tls_
= true; }
539 // Return true if any object file uses the static TLS model.
541 has_static_tls() const
542 { return this->has_static_tls_
; }
544 // Return the options which may be set by a linker script.
547 { return this->script_options_
; }
549 const Script_options
*
550 script_options() const
551 { return this->script_options_
; }
553 // Return the object managing inputs in incremental build. NULL in
554 // non-incremental builds.
557 { return this->incremental_inputs_
; }
559 // Compute and write out the build ID if needed.
561 write_build_id(Output_file
*) const;
563 // Rewrite output file in binary format.
565 write_binary(Output_file
* in
) const;
567 // Print output sections to the map file.
569 print_to_mapfile(Mapfile
*) const;
571 // Dump statistical information to stderr.
575 // A list of segments.
577 typedef std::vector
<Output_segment
*> Segment_list
;
579 // A list of sections.
581 typedef std::vector
<Output_section
*> Section_list
;
583 // The list of information to write out which is not attached to
584 // either a section or a segment.
585 typedef std::vector
<Output_data
*> Data_list
;
587 // Store the allocated sections into the section list. This is used
588 // by the linker script code.
590 get_allocated_sections(Section_list
*) const;
592 // Make a section for a linker script to hold data.
594 make_output_section_for_script(const char* name
);
596 // Make a segment. This is used by the linker script code.
598 make_output_segment(elfcpp::Elf_Word type
, elfcpp::Elf_Word flags
);
600 // Return the number of segments.
602 segment_count() const
603 { return this->segment_list_
.size(); }
605 // Map from section flags to segment flags.
606 static elfcpp::Elf_Word
607 section_flags_to_segment(elfcpp::Elf_Xword flags
);
609 // Attach sections to segments.
611 attach_sections_to_segments();
613 // For relaxation clean up, we need to know output section data created
614 // from a linker script.
616 new_output_section_data_from_script(Output_section_data
* posd
)
618 if (this->record_output_section_data_from_script_
)
619 this->script_output_section_data_list_
.push_back(posd
);
622 // Return section list.
625 { return this->section_list_
; }
628 Layout(const Layout
&);
629 Layout
& operator=(const Layout
&);
631 // Mapping from input section names to output section names.
632 struct Section_name_mapping
639 static const Section_name_mapping section_name_mapping
[];
640 static const int section_name_mapping_count
;
642 // During a relocatable link, a list of group sections and
644 struct Group_signature
646 // The group section.
647 Output_section
* section
;
649 const char* signature
;
652 : section(NULL
), signature(NULL
)
655 Group_signature(Output_section
* sectiona
, const char* signaturea
)
656 : section(sectiona
), signature(signaturea
)
659 typedef std::vector
<Group_signature
> Group_signatures
;
661 // Create a note section, filling in the header.
663 create_note(const char* name
, int note_type
, const char *section_name
,
664 size_t descsz
, bool allocate
, size_t* trailing_padding
);
666 // Create a note section for gold version.
670 // Record whether the stack must be executable.
672 create_executable_stack_info();
674 // Create a build ID note if needed.
678 // Link .stab and .stabstr sections.
680 link_stabs_sections();
682 // Create .gnu_incremental_inputs and .gnu_incremental_strtab sections needed
683 // for the next run of incremental linking to check what has changed.
685 create_incremental_info_sections();
687 // Find the first read-only PT_LOAD segment, creating one if
690 find_first_load_seg();
692 // Count the local symbols in the regular symbol table and the dynamic
693 // symbol table, and build the respective string pools.
695 count_local_symbols(const Task
*, const Input_objects
*);
697 // Create the output sections for the symbol table.
699 create_symtab_sections(const Input_objects
*, Symbol_table
*,
700 unsigned int, off_t
*);
702 // Create the .shstrtab section.
706 // Create the section header table.
708 create_shdrs(const Output_section
* shstrtab_section
, off_t
*);
710 // Create the dynamic symbol table.
712 create_dynamic_symtab(const Input_objects
*, Symbol_table
*,
713 Output_section
** pdynstr
,
714 unsigned int* plocal_dynamic_count
,
715 std::vector
<Symbol
*>* pdynamic_symbols
,
718 // Assign offsets to each local portion of the dynamic symbol table.
720 assign_local_dynsym_offsets(const Input_objects
*);
722 // Finish the .dynamic section and PT_DYNAMIC segment.
724 finish_dynamic_section(const Input_objects
*, const Symbol_table
*);
726 // Set the size of the _DYNAMIC symbol.
728 set_dynamic_symbol_size(const Symbol_table
*);
730 // Create the .interp section and PT_INTERP segment.
732 create_interp(const Target
* target
);
734 // Create the version sections.
736 create_version_sections(const Versions
*,
738 unsigned int local_symcount
,
739 const std::vector
<Symbol
*>& dynamic_symbols
,
740 const Output_section
* dynstr
);
742 template<int size
, bool big_endian
>
744 sized_create_version_sections(const Versions
* versions
,
746 unsigned int local_symcount
,
747 const std::vector
<Symbol
*>& dynamic_symbols
,
748 const Output_section
* dynstr
);
750 // Return whether to include this section in the link.
751 template<int size
, bool big_endian
>
753 include_section(Sized_relobj
<size
, big_endian
>* object
, const char* name
,
754 const elfcpp::Shdr
<size
, big_endian
>&);
756 // Return the output section name to use given an input section
757 // name. Set *PLEN to the length of the name. *PLEN must be
758 // initialized to the length of NAME.
760 output_section_name(const char* name
, size_t* plen
);
762 // Return the number of allocated output sections.
764 allocated_output_section_count() const;
766 // Return the output section for NAME, TYPE and FLAGS.
768 get_output_section(const char* name
, Stringpool::Key name_key
,
769 elfcpp::Elf_Word type
, elfcpp::Elf_Xword flags
,
770 bool is_interp
, bool is_dynamic_linker_section
,
771 bool is_relro
, bool is_last_relro
,
772 bool is_first_non_relro
);
774 // Choose the output section for NAME in RELOBJ.
776 choose_output_section(const Relobj
* relobj
, const char* name
,
777 elfcpp::Elf_Word type
, elfcpp::Elf_Xword flags
,
778 bool is_input_section
, bool is_interp
,
779 bool is_dynamic_linker_section
, bool is_relro
,
780 bool is_last_relro
, bool is_first_non_relro
);
782 // Create a new Output_section.
784 make_output_section(const char* name
, elfcpp::Elf_Word type
,
785 elfcpp::Elf_Xword flags
, bool is_interp
,
786 bool is_dynamic_linker_section
, bool is_relro
,
787 bool is_last_relro
, bool is_first_non_relro
);
789 // Attach a section to a segment.
791 attach_section_to_segment(Output_section
*);
793 // Attach an allocated section to a segment.
795 attach_allocated_section_to_segment(Output_section
*);
797 // Set the final file offsets of all the segments.
799 set_segment_offsets(const Target
*, Output_segment
*, unsigned int* pshndx
);
801 // Set the file offsets of the sections when doing a relocatable
804 set_relocatable_section_offsets(Output_data
*, unsigned int* pshndx
);
806 // Set the final file offsets of all the sections not associated
807 // with a segment. We set section offsets in three passes: the
808 // first handles all allocated sections, the second sections that
809 // require postprocessing, and the last the late-bound STRTAB
810 // sections (probably only shstrtab, which is the one we care about
811 // because it holds section names).
812 enum Section_offset_pass
814 BEFORE_INPUT_SECTIONS_PASS
,
815 POSTPROCESSING_SECTIONS_PASS
,
816 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
819 set_section_offsets(off_t
, Section_offset_pass pass
);
821 // Set the final section indexes of all the sections not associated
822 // with a segment. Returns the next unused index.
824 set_section_indexes(unsigned int pshndx
);
826 // Set the section addresses when using a script.
828 set_section_addresses_from_script(Symbol_table
*);
830 // Find appropriate places or orphan sections in a script.
832 place_orphan_sections_in_script();
834 // Return whether SEG1 comes before SEG2 in the output file.
836 segment_precedes(const Output_segment
* seg1
, const Output_segment
* seg2
);
838 // Use to save and restore segments during relaxation.
839 typedef Unordered_map
<const Output_segment
*, const Output_segment
*>
842 // Save states of current output segments.
844 save_segments(Segment_states
*);
846 // Restore output segment states.
848 restore_segments(const Segment_states
*);
850 // Clean up after relaxation so that it is possible to lay out the
851 // sections and segments again.
853 clean_up_after_relaxation();
855 // Doing preparation work for relaxation. This is factored out to make
856 // Layout::finalized a bit smaller and easier to read.
858 prepare_for_relaxation();
860 // Main body of the relaxation loop, which lays out the section.
862 relaxation_loop_body(int, Target
*, Symbol_table
*, Output_segment
**,
863 Output_segment
*, Output_segment_headers
*,
864 Output_file_header
*, unsigned int*);
866 // A mapping used for kept comdats/.gnu.linkonce group signatures.
867 typedef Unordered_map
<std::string
, Kept_section
> Signatures
;
869 // Mapping from input section name/type/flags to output section. We
870 // use canonicalized strings here.
872 typedef std::pair
<Stringpool::Key
,
873 std::pair
<elfcpp::Elf_Word
, elfcpp::Elf_Xword
> > Key
;
878 operator()(const Key
& k
) const;
881 typedef Unordered_map
<Key
, Output_section
*, Hash_key
> Section_name_map
;
883 // A comparison class for segments.
885 struct Compare_segments
888 operator()(const Output_segment
* seg1
, const Output_segment
* seg2
)
889 { return Layout::segment_precedes(seg1
, seg2
); }
892 typedef std::vector
<Output_section_data
*> Output_section_data_list
;
894 // Debug checker class.
895 class Relaxation_debug_check
898 Relaxation_debug_check()
902 // Check that sections and special data are in reset states.
904 check_output_data_for_reset_values(const Layout::Section_list
&,
905 const Layout::Data_list
&);
907 // Record information of a section list.
909 read_sections(const Layout::Section_list
&);
911 // Verify a section list with recorded information.
913 verify_sections(const Layout::Section_list
&);
916 // Information we care about a section.
919 // Output section described by this.
920 Output_section
* output_section
;
929 // Section information.
930 std::vector
<Section_info
> section_infos_
;
933 // The number of input files, for sizing tables.
934 int number_of_input_files_
;
935 // Information set by scripts or by command line options.
936 Script_options
* script_options_
;
937 // The output section names.
938 Stringpool namepool_
;
939 // The output symbol names.
941 // The dynamic strings, if needed.
943 // The list of group sections and linkonce sections which we have seen.
944 Signatures signatures_
;
945 // The mapping from input section name/type/flags to output sections.
946 Section_name_map section_name_map_
;
947 // The list of output segments.
948 Segment_list segment_list_
;
949 // The list of output sections.
950 Section_list section_list_
;
951 // The list of output sections which are not attached to any output
953 Section_list unattached_section_list_
;
954 // The list of unattached Output_data objects which require special
955 // handling because they are not Output_sections.
956 Data_list special_output_list_
;
957 // The section headers.
958 Output_section_headers
* section_headers_
;
959 // A pointer to the PT_TLS segment if there is one.
960 Output_segment
* tls_segment_
;
961 // A pointer to the PT_GNU_RELRO segment if there is one.
962 Output_segment
* relro_segment_
;
963 // A backend may increase the size of the PT_GNU_RELRO segment if
964 // there is one. This is the amount to increase it by.
965 unsigned int increase_relro_
;
966 // The SHT_SYMTAB output section.
967 Output_section
* symtab_section_
;
968 // The SHT_SYMTAB_SHNDX for the regular symbol table if there is one.
969 Output_symtab_xindex
* symtab_xindex_
;
970 // The SHT_DYNSYM output section if there is one.
971 Output_section
* dynsym_section_
;
972 // The SHT_SYMTAB_SHNDX for the dynamic symbol table if there is one.
973 Output_symtab_xindex
* dynsym_xindex_
;
974 // The SHT_DYNAMIC output section if there is one.
975 Output_section
* dynamic_section_
;
976 // The _DYNAMIC symbol if there is one.
977 Symbol
* dynamic_symbol_
;
978 // The dynamic data which goes into dynamic_section_.
979 Output_data_dynamic
* dynamic_data_
;
980 // The exception frame output section if there is one.
981 Output_section
* eh_frame_section_
;
982 // The exception frame data for eh_frame_section_.
983 Eh_frame
* eh_frame_data_
;
984 // Whether we have added eh_frame_data_ to the .eh_frame section.
985 bool added_eh_frame_data_
;
986 // The exception frame header output section if there is one.
987 Output_section
* eh_frame_hdr_section_
;
988 // The space for the build ID checksum if there is one.
989 Output_section_data
* build_id_note_
;
990 // The output section containing dwarf abbreviations
991 Output_reduced_debug_abbrev_section
* debug_abbrev_
;
992 // The output section containing the dwarf debug info tree
993 Output_reduced_debug_info_section
* debug_info_
;
994 // A list of group sections and their signatures.
995 Group_signatures group_signatures_
;
996 // The size of the output file.
997 off_t output_file_size_
;
998 // Whether we have added an input section to an output section.
999 bool have_added_input_section_
;
1000 // Whether we have attached the sections to the segments.
1001 bool sections_are_attached_
;
1002 // Whether we have seen an object file marked to require an
1003 // executable stack.
1004 bool input_requires_executable_stack_
;
1005 // Whether we have seen at least one object file with an executable
1007 bool input_with_gnu_stack_note_
;
1008 // Whether we have seen at least one object file without an
1009 // executable stack marker.
1010 bool input_without_gnu_stack_note_
;
1011 // Whether we have seen an object file that uses the static TLS model.
1012 bool has_static_tls_
;
1013 // Whether any sections require postprocessing.
1014 bool any_postprocessing_sections_
;
1015 // Whether we have resized the signatures_ hash table.
1016 bool resized_signatures_
;
1017 // Whether we have created a .stab*str output section.
1018 bool have_stabstr_section_
;
1019 // In incremental build, holds information check the inputs and build the
1020 // .gnu_incremental_inputs section.
1021 Incremental_inputs
* incremental_inputs_
;
1022 // Whether we record output section data created in script
1023 bool record_output_section_data_from_script_
;
1024 // List of output data that needs to be removed at relexation clean up.
1025 Output_section_data_list script_output_section_data_list_
;
1026 // Structure to save segment states before entering the relaxation loop.
1027 Segment_states
* segment_states_
;
1028 // A relaxation debug checker. We only create one when in debugging mode.
1029 Relaxation_debug_check
* relaxation_debug_check_
;
1032 // This task handles writing out data in output sections which is not
1033 // part of an input section, or which requires special handling. When
1034 // this is done, it unblocks both output_sections_blocker and
1037 class Write_sections_task
: public Task
1040 Write_sections_task(const Layout
* layout
, Output_file
* of
,
1041 Task_token
* output_sections_blocker
,
1042 Task_token
* final_blocker
)
1043 : layout_(layout
), of_(of
),
1044 output_sections_blocker_(output_sections_blocker
),
1045 final_blocker_(final_blocker
)
1048 // The standard Task methods.
1054 locks(Task_locker
*);
1061 { return "Write_sections_task"; }
1064 class Write_sections_locker
;
1066 const Layout
* layout_
;
1068 Task_token
* output_sections_blocker_
;
1069 Task_token
* final_blocker_
;
1072 // This task handles writing out data which is not part of a section
1075 class Write_data_task
: public Task
1078 Write_data_task(const Layout
* layout
, const Symbol_table
* symtab
,
1079 Output_file
* of
, Task_token
* final_blocker
)
1080 : layout_(layout
), symtab_(symtab
), of_(of
), final_blocker_(final_blocker
)
1083 // The standard Task methods.
1089 locks(Task_locker
*);
1096 { return "Write_data_task"; }
1099 const Layout
* layout_
;
1100 const Symbol_table
* symtab_
;
1102 Task_token
* final_blocker_
;
1105 // This task handles writing out the global symbols.
1107 class Write_symbols_task
: public Task
1110 Write_symbols_task(const Layout
* layout
, const Symbol_table
* symtab
,
1111 const Input_objects
* input_objects
,
1112 const Stringpool
* sympool
, const Stringpool
* dynpool
,
1113 Output_file
* of
, Task_token
* final_blocker
)
1114 : layout_(layout
), symtab_(symtab
), input_objects_(input_objects
),
1115 sympool_(sympool
), dynpool_(dynpool
), of_(of
),
1116 final_blocker_(final_blocker
)
1119 // The standard Task methods.
1125 locks(Task_locker
*);
1132 { return "Write_symbols_task"; }
1135 const Layout
* layout_
;
1136 const Symbol_table
* symtab_
;
1137 const Input_objects
* input_objects_
;
1138 const Stringpool
* sympool_
;
1139 const Stringpool
* dynpool_
;
1141 Task_token
* final_blocker_
;
1144 // This task handles writing out data in output sections which can't
1145 // be written out until all the input sections have been handled.
1146 // This is for sections whose contents is based on the contents of
1147 // other output sections.
1149 class Write_after_input_sections_task
: public Task
1152 Write_after_input_sections_task(Layout
* layout
, Output_file
* of
,
1153 Task_token
* input_sections_blocker
,
1154 Task_token
* final_blocker
)
1155 : layout_(layout
), of_(of
),
1156 input_sections_blocker_(input_sections_blocker
),
1157 final_blocker_(final_blocker
)
1160 // The standard Task methods.
1166 locks(Task_locker
*);
1173 { return "Write_after_input_sections_task"; }
1178 Task_token
* input_sections_blocker_
;
1179 Task_token
* final_blocker_
;
1182 // This task function handles closing the file.
1184 class Close_task_runner
: public Task_function_runner
1187 Close_task_runner(const General_options
* options
, const Layout
* layout
,
1189 : options_(options
), layout_(layout
), of_(of
)
1192 // Run the operation.
1194 run(Workqueue
*, const Task
*);
1197 const General_options
* options_
;
1198 const Layout
* layout_
;
1202 // A small helper function to align an address.
1205 align_address(uint64_t address
, uint64_t addralign
)
1208 address
= (address
+ addralign
- 1) &~ (addralign
- 1);
1212 } // End namespace gold.
1214 #endif // !defined(GOLD_LAYOUT_H)