1 // object.h -- support for an object file for linking in 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.
30 #include "elfcpp_file.h"
37 class General_options;
44 class Output_symtab_xindex;
47 class Object_merge_map;
48 class Relocatable_relocs;
51 template<typename Stringpool_char>
52 class Stringpool_template;
54 // Data to pass from read_symbols() to add_symbols().
56 struct Read_symbols_data
59 File_view* section_headers;
61 File_view* section_names;
62 // Size of section name data in bytes.
63 section_size_type section_names_size;
66 // Size of symbol data in bytes.
67 section_size_type symbols_size;
68 // Offset of external symbols within symbol data. This structure
69 // sometimes contains only external symbols, in which case this will
70 // be zero. Sometimes it contains all symbols.
71 section_offset_type external_symbols_offset;
73 File_view* symbol_names;
74 // Size of symbol name data in bytes.
75 section_size_type symbol_names_size;
77 // Version information. This is only used on dynamic objects.
78 // Version symbol data (from SHT_GNU_versym section).
80 section_size_type versym_size;
81 // Version definition data (from SHT_GNU_verdef section).
83 section_size_type verdef_size;
84 unsigned int verdef_info;
85 // Needed version data (from SHT_GNU_verneed section).
87 section_size_type verneed_size;
88 unsigned int verneed_info;
91 // Information used to print error messages.
93 struct Symbol_location_info
95 std::string source_file;
96 std::string enclosing_symbol_name;
100 // Data about a single relocation section. This is read in
101 // read_relocs and processed in scan_relocs.
103 struct Section_relocs
105 // Index of reloc section.
106 unsigned int reloc_shndx;
107 // Index of section that relocs apply to.
108 unsigned int data_shndx;
109 // Contents of reloc section.
111 // Reloc section type.
112 unsigned int sh_type;
113 // Number of reloc entries.
116 Output_section* output_section;
117 // Whether this section has special handling for offsets.
118 bool needs_special_offset_handling;
119 // Whether the data section is allocated (has the SHF_ALLOC flag set).
120 bool is_data_section_allocated;
123 // Relocations in an object file. This is read in read_relocs and
124 // processed in scan_relocs.
126 struct Read_relocs_data
128 typedef std::vector<Section_relocs> Relocs_list;
131 // The local symbols.
132 File_view* local_symbols;
135 // The Xindex class manages section indexes for objects with more than
141 Xindex(int large_shndx_offset)
142 : large_shndx_offset_(large_shndx_offset), symtab_xindex_()
145 // Initialize the symtab_xindex_ array, given the object and the
146 // section index of the symbol table to use.
147 template<int size, bool big_endian>
149 initialize_symtab_xindex(Object*, unsigned int symtab_shndx);
151 // Read in the symtab_xindex_ array, given its section index.
152 // PSHDRS may optionally point to the section headers.
153 template<int size, bool big_endian>
155 read_symtab_xindex(Object*, unsigned int xindex_shndx,
156 const unsigned char* pshdrs);
158 // Symbol SYMNDX in OBJECT has a section of SHN_XINDEX; return the
159 // real section index.
161 sym_xindex_to_shndx(Object* object, unsigned int symndx);
164 // The type of the array giving the real section index for symbols
165 // whose st_shndx field holds SHN_XINDEX.
166 typedef std::vector<unsigned int> Symtab_xindex;
168 // Adjust a section index if necessary. This should only be called
169 // for ordinary section indexes.
171 adjust_shndx(unsigned int shndx)
173 if (shndx >= elfcpp::SHN_LORESERVE)
174 shndx += this->large_shndx_offset_;
178 // Adjust to apply to large section indexes.
179 int large_shndx_offset_;
180 // The data from the SHT_SYMTAB_SHNDX section.
181 Symtab_xindex symtab_xindex_;
184 // Object is an abstract base class which represents either a 32-bit
185 // or a 64-bit input object. This can be a regular object file
186 // (ET_REL) or a shared object (ET_DYN).
191 // NAME is the name of the object as we would report it to the user
192 // (e.g., libfoo.a(bar.o) if this is in an archive. INPUT_FILE is
193 // used to read the file. OFFSET is the offset within the input
194 // file--0 for a .o or .so file, something else for a .a file.
195 Object(const std::string& name, Input_file* input_file, bool is_dynamic,
197 : name_(name), input_file_(input_file), offset_(offset), shnum_(-1U),
198 is_dynamic_(is_dynamic), target_(NULL), xindex_(NULL), no_export_(false)
199 { input_file->file().add_object(); }
202 { this->input_file_->file().remove_object(); }
204 // Return the name of the object as we would report it to the tuser.
207 { return this->name_; }
209 // Get the offset into the file.
212 { return this->offset_; }
214 // Return whether this is a dynamic object.
217 { return this->is_dynamic_; }
219 // Returns NULL for Objects that are not plugin objects. This method
220 // is overridden in the Pluginobj class.
223 { return this->do_pluginobj(); }
225 // Return the target structure associated with this object.
228 { return this->target_; }
230 // Get the file. We pass on const-ness.
233 { return this->input_file_; }
237 { return this->input_file_; }
239 // Lock the underlying file.
242 { this->input_file()->file().lock(t); }
244 // Unlock the underlying file.
246 unlock(const Task* t)
247 { this->input_file()->file().unlock(t); }
249 // Return whether the underlying file is locked.
252 { return this->input_file()->file().is_locked(); }
254 // Return the token, so that the task can be queued.
257 { return this->input_file()->file().token(); }
259 // Release the underlying file.
262 { this->input_file_->file().release(); }
264 // Return whether we should just read symbols from this file.
267 { return this->input_file()->just_symbols(); }
269 // Return the sized target structure associated with this object.
270 // This is like the target method but it returns a pointer of
271 // appropriate checked type.
272 template<int size, bool big_endian>
273 Sized_target<size, big_endian>*
274 sized_target() const;
276 // Get the number of sections.
279 { return this->shnum_; }
281 // Return a view of the contents of a section. Set *PLEN to the
282 // size. CACHE is a hint as in File_read::get_view.
284 section_contents(unsigned int shndx, section_size_type* plen, bool cache);
286 // Adjust a symbol's section index as needed. SYMNDX is the index
287 // of the symbol and SHNDX is the symbol's section from
288 // get_st_shndx. This returns the section index. It sets
289 // *IS_ORDINARY to indicate whether this is a normal section index,
290 // rather than a special code between SHN_LORESERVE and
293 adjust_sym_shndx(unsigned int symndx, unsigned int shndx, bool* is_ordinary)
295 if (shndx < elfcpp::SHN_LORESERVE)
297 else if (shndx == elfcpp::SHN_XINDEX)
299 if (this->xindex_ == NULL)
300 this->xindex_ = this->do_initialize_xindex();
301 shndx = this->xindex_->sym_xindex_to_shndx(this, symndx);
305 *is_ordinary = false;
309 // Return the size of a section given a section index.
311 section_size(unsigned int shndx)
312 { return this->do_section_size(shndx); }
314 // Return the name of a section given a section index.
316 section_name(unsigned int shndx)
317 { return this->do_section_name(shndx); }
319 // Return the section flags given a section index.
321 section_flags(unsigned int shndx)
322 { return this->do_section_flags(shndx); }
324 // Return the section entsize given a section index.
326 section_entsize(unsigned int shndx)
327 { return this->do_section_entsize(shndx); }
329 // Return the section address given a section index.
331 section_address(unsigned int shndx)
332 { return this->do_section_address(shndx); }
334 // Return the section type given a section index.
336 section_type(unsigned int shndx)
337 { return this->do_section_type(shndx); }
339 // Return the section link field given a section index.
341 section_link(unsigned int shndx)
342 { return this->do_section_link(shndx); }
344 // Return the section info field given a section index.
346 section_info(unsigned int shndx)
347 { return this->do_section_info(shndx); }
349 // Return the required section alignment given a section index.
351 section_addralign(unsigned int shndx)
352 { return this->do_section_addralign(shndx); }
354 // Read the symbol information.
356 read_symbols(Read_symbols_data* sd)
357 { return this->do_read_symbols(sd); }
359 // Pass sections which should be included in the link to the Layout
360 // object, and record where the sections go in the output file.
362 layout(Symbol_table* symtab, Layout* layout, Read_symbols_data* sd)
363 { this->do_layout(symtab, layout, sd); }
365 // Add symbol information to the global symbol table.
367 add_symbols(Symbol_table* symtab, Read_symbols_data* sd, Layout *layout)
368 { this->do_add_symbols(symtab, sd, layout); }
370 // Functions and types for the elfcpp::Elf_file interface. This
371 // permit us to use Object as the File template parameter for
374 // The View class is returned by view. It must support a single
375 // method, data(). This is trivial, because get_view does what we
380 View(const unsigned char* p)
389 const unsigned char* p_;
394 view(off_t file_offset, section_size_type data_size)
395 { return View(this->get_view(file_offset, data_size, true, true)); }
399 error(const char* format, ...) const ATTRIBUTE_PRINTF_2;
401 // A location in the file.
407 Location(off_t fo, section_size_type ds)
408 : file_offset(fo), data_size(ds)
412 // Get a View given a Location.
413 View view(Location loc)
414 { return View(this->get_view(loc.file_offset, loc.data_size, true, true)); }
416 // Get a view into the underlying file.
418 get_view(off_t start, section_size_type size, bool aligned, bool cache)
420 return this->input_file()->file().get_view(this->offset_, start, size,
424 // Get a lasting view into the underlying file.
426 get_lasting_view(off_t start, section_size_type size, bool aligned,
429 return this->input_file()->file().get_lasting_view(this->offset_, start,
430 size, aligned, cache);
433 // Read data from the underlying file.
435 read(off_t start, section_size_type size, void* p)
436 { this->input_file()->file().read(start + this->offset_, size, p); }
438 // Read multiple data from the underlying file.
440 read_multiple(const File_read::Read_multiple& rm)
441 { this->input_file()->file().read_multiple(this->offset_, rm); }
443 // Stop caching views in the underlying file.
445 clear_view_cache_marks()
446 { this->input_file()->file().clear_view_cache_marks(); }
448 // Get the number of global symbols defined by this object, and the
449 // number of the symbols whose final definition came from this
452 get_global_symbol_counts(const Symbol_table* symtab, size_t* defined,
454 { this->do_get_global_symbol_counts(symtab, defined, used); }
458 set_target(Target* target)
459 { this->target_ = target; }
461 // Return whether this object was found in a system directory.
463 is_in_system_directory() const
464 { return this->input_file()->is_in_system_directory(); }
466 // Return whether we found this object by searching a directory.
469 { return this->input_file()->will_search_for(); }
473 { return this->no_export_; }
476 set_no_export(bool value)
477 { this->no_export_ = value; }
480 // Returns NULL for Objects that are not plugin objects. This method
481 // is overridden in the Pluginobj class.
486 // Read the symbols--implemented by child class.
488 do_read_symbols(Read_symbols_data*) = 0;
490 // Lay out sections--implemented by child class.
492 do_layout(Symbol_table*, Layout*, Read_symbols_data*) = 0;
494 // Add symbol information to the global symbol table--implemented by
497 do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*) = 0;
499 // Return the location of the contents of a section. Implemented by
502 do_section_contents(unsigned int shndx) = 0;
504 // Get the size of a section--implemented by child class.
506 do_section_size(unsigned int shndx) = 0;
508 // Get the name of a section--implemented by child class.
510 do_section_name(unsigned int shndx) = 0;
512 // Get section flags--implemented by child class.
514 do_section_flags(unsigned int shndx) = 0;
516 // Get section entsize--implemented by child class.
518 do_section_entsize(unsigned int shndx) = 0;
520 // Get section address--implemented by child class.
522 do_section_address(unsigned int shndx) = 0;
524 // Get section type--implemented by child class.
526 do_section_type(unsigned int shndx) = 0;
528 // Get section link field--implemented by child class.
530 do_section_link(unsigned int shndx) = 0;
532 // Get section info field--implemented by child class.
534 do_section_info(unsigned int shndx) = 0;
536 // Get section alignment--implemented by child class.
538 do_section_addralign(unsigned int shndx) = 0;
540 // Return the Xindex structure to use.
542 do_initialize_xindex() = 0;
544 // Implement get_global_symbol_counts--implemented by child class.
546 do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const = 0;
550 set_target(int machine, int size, bool big_endian, int osabi,
553 // Set the number of sections.
556 { this->shnum_ = shnum; }
558 // Functions used by both Sized_relobj and Sized_dynobj.
560 // Read the section data into a Read_symbols_data object.
561 template<int size, bool big_endian>
563 read_section_data(elfcpp::Elf_file<size, big_endian, Object>*,
566 // Let the child class initialize the xindex object directly.
568 set_xindex(Xindex* xindex)
570 gold_assert(this->xindex_ == NULL);
571 this->xindex_ = xindex;
574 // If NAME is the name of a special .gnu.warning section, arrange
575 // for the warning to be issued. SHNDX is the section index.
576 // Return whether it is a warning section.
578 handle_gnu_warning_section(const char* name, unsigned int shndx,
582 // This class may not be copied.
583 Object(const Object&);
584 Object& operator=(const Object&);
586 // Name of object as printed to user.
588 // For reading the file.
589 Input_file* input_file_;
590 // Offset within the file--0 for an object file, non-0 for an
593 // Number of input sections.
595 // Whether this is a dynamic object.
597 // Target functions--may be NULL if the target is not known.
599 // Many sections for objects with more than SHN_LORESERVE sections.
601 // True if exclude this object from automatic symbol export.
602 // This is used only for archive objects.
606 // Implement sized_target inline for efficiency. This approach breaks
607 // static type checking, but is made safe using asserts.
609 template<int size, bool big_endian>
610 inline Sized_target<size, big_endian>*
611 Object::sized_target() const
613 gold_assert(this->target_->get_size() == size);
614 gold_assert(this->target_->is_big_endian() ? big_endian : !big_endian);
615 return static_cast<Sized_target<size, big_endian>*>(this->target_);
618 // A regular object (ET_REL). This is an abstract base class itself.
619 // The implementation is the template class Sized_relobj.
621 class Relobj : public Object
624 Relobj(const std::string& name, Input_file* input_file, off_t offset = 0)
625 : Object(name, input_file, false, offset),
627 map_to_relocatable_relocs_(NULL),
628 object_merge_map_(NULL),
629 relocs_must_follow_section_writes_(false),
633 // During garbage collection, the Read_symbols_data pass for
634 // each object is stored as layout needs to be done after
638 { return this->sd_; }
640 // Decides which section names have to be included in the worklist
643 is_section_name_included(const char *name);
646 copy_symbols_data(Symbols_data* gc_sd, Read_symbols_data* sd,
647 unsigned int section_header_size);
650 set_symbols_data(Symbols_data* sd)
653 // During garbage collection, the Read_relocs pass for all objects
654 // is done before scanning the relocs. In that case, this->rd_ is
655 // used to store the information from Read_relocs for each object.
656 // This data is also used to compute the list of relevant sections.
659 { return this->rd_; }
662 set_relocs_data(Read_relocs_data* rd)
666 is_output_section_offset_invalid(unsigned int shndx) const = 0;
670 read_relocs(Read_relocs_data* rd)
671 { return this->do_read_relocs(rd); }
673 // Process the relocs, during garbage collection only.
675 gc_process_relocs(const General_options& options, Symbol_table* symtab,
676 Layout* layout, Read_relocs_data* rd)
677 { return this->do_gc_process_relocs(options, symtab, layout, rd); }
679 // Scan the relocs and adjust the symbol table.
681 scan_relocs(const General_options& options, Symbol_table* symtab,
682 Layout* layout, Read_relocs_data* rd)
683 { return this->do_scan_relocs(options, symtab, layout, rd); }
685 // The number of local symbols in the input symbol table.
687 local_symbol_count() const
688 { return this->do_local_symbol_count(); }
690 // Initial local symbol processing: count the number of local symbols
691 // in the output symbol table and dynamic symbol table; add local symbol
692 // names to *POOL and *DYNPOOL.
694 count_local_symbols(Stringpool_template<char>* pool,
695 Stringpool_template<char>* dynpool)
696 { return this->do_count_local_symbols(pool, dynpool); }
698 // Set the values of the local symbols, set the output symbol table
699 // indexes for the local variables, and set the offset where local
700 // symbol information will be stored. Returns the new local symbol index.
702 finalize_local_symbols(unsigned int index, off_t off, Symbol_table* symtab)
703 { return this->do_finalize_local_symbols(index, off, symtab); }
705 // Set the output dynamic symbol table indexes for the local variables.
707 set_local_dynsym_indexes(unsigned int index)
708 { return this->do_set_local_dynsym_indexes(index); }
710 // Set the offset where local dynamic symbol information will be stored.
712 set_local_dynsym_offset(off_t off)
713 { return this->do_set_local_dynsym_offset(off); }
715 // Relocate the input sections and write out the local symbols.
717 relocate(const General_options& options, const Symbol_table* symtab,
718 const Layout* layout, Output_file* of)
719 { return this->do_relocate(options, symtab, layout, of); }
721 // Return whether an input section is being included in the link.
723 is_section_included(unsigned int shndx) const
725 gold_assert(shndx < this->output_sections_.size());
726 return this->output_sections_[shndx] != NULL;
729 // Given a section index, return the corresponding Output_section.
730 // The return value will be NULL if the section is not included in
733 output_section(unsigned int shndx) const
735 gold_assert(shndx < this->output_sections_.size());
736 return this->output_sections_[shndx];
739 // Given a section index, return the offset in the Output_section.
740 // The return value will be -1U if the section is specially mapped,
741 // such as a merge section.
743 output_section_offset(unsigned int shndx) const
744 { return this->do_output_section_offset(shndx); }
746 // Set the offset of an input section within its output section.
748 set_section_offset(unsigned int shndx, uint64_t off)
749 { this->do_set_section_offset(shndx, off); }
751 // Return true if we need to wait for output sections to be written
752 // before we can apply relocations. This is true if the object has
753 // any relocations for sections which require special handling, such
754 // as the exception frame section.
756 relocs_must_follow_section_writes() const
757 { return this->relocs_must_follow_section_writes_; }
759 // Return the object merge map.
762 { return this->object_merge_map_; }
764 // Set the object merge map.
766 set_merge_map(Object_merge_map* object_merge_map)
768 gold_assert(this->object_merge_map_ == NULL);
769 this->object_merge_map_ = object_merge_map;
772 // Record the relocatable reloc info for an input reloc section.
774 set_relocatable_relocs(unsigned int reloc_shndx, Relocatable_relocs* rr)
776 gold_assert(reloc_shndx < this->shnum());
777 (*this->map_to_relocatable_relocs_)[reloc_shndx] = rr;
780 // Get the relocatable reloc info for an input reloc section.
782 relocatable_relocs(unsigned int reloc_shndx)
784 gold_assert(reloc_shndx < this->shnum());
785 return (*this->map_to_relocatable_relocs_)[reloc_shndx];
788 // Layout sections whose layout was deferred while waiting for
789 // input files from a plugin.
791 layout_deferred_sections(Layout* layout)
792 { this->do_layout_deferred_sections(layout); }
795 // The output section to be used for each input section, indexed by
796 // the input section number. The output section is NULL if the
797 // input section is to be discarded.
798 typedef std::vector<Output_section*> Output_sections;
800 // Read the relocs--implemented by child class.
802 do_read_relocs(Read_relocs_data*) = 0;
804 // Process the relocs--implemented by child class.
806 do_gc_process_relocs(const General_options&, Symbol_table*, Layout*,
807 Read_relocs_data*) = 0;
809 // Scan the relocs--implemented by child class.
811 do_scan_relocs(const General_options&, Symbol_table*, Layout*,
812 Read_relocs_data*) = 0;
814 // Return the number of local symbols--implemented by child class.
816 do_local_symbol_count() const = 0;
818 // Count local symbols--implemented by child class.
820 do_count_local_symbols(Stringpool_template<char>*,
821 Stringpool_template<char>*) = 0;
823 // Finalize the local symbols. Set the output symbol table indexes
824 // for the local variables, and set the offset where local symbol
825 // information will be stored.
827 do_finalize_local_symbols(unsigned int, off_t, Symbol_table*) = 0;
829 // Set the output dynamic symbol table indexes for the local variables.
831 do_set_local_dynsym_indexes(unsigned int) = 0;
833 // Set the offset where local dynamic symbol information will be stored.
835 do_set_local_dynsym_offset(off_t) = 0;
837 // Relocate the input sections and write out the local
838 // symbols--implemented by child class.
840 do_relocate(const General_options& options, const Symbol_table* symtab,
841 const Layout*, Output_file* of) = 0;
843 // Get the offset of a section--implemented by child class.
845 do_output_section_offset(unsigned int shndx) const = 0;
847 // Set the offset of a section--implemented by child class.
849 do_set_section_offset(unsigned int shndx, uint64_t off) = 0;
851 // Layout sections whose layout was deferred while waiting for
852 // input files from a plugin--implemented by child class.
854 do_layout_deferred_sections(Layout*) = 0;
856 // Return the vector mapping input sections to output sections.
859 { return this->output_sections_; }
861 const Output_sections&
862 output_sections() const
863 { return this->output_sections_; }
865 // Set the size of the relocatable relocs array.
867 size_relocatable_relocs()
869 this->map_to_relocatable_relocs_ =
870 new std::vector<Relocatable_relocs*>(this->shnum());
873 // Record that we must wait for the output sections to be written
874 // before applying relocations.
876 set_relocs_must_follow_section_writes()
877 { this->relocs_must_follow_section_writes_ = true; }
880 // Mapping from input sections to output section.
881 Output_sections output_sections_;
882 // Mapping from input section index to the information recorded for
883 // the relocations. This is only used for a relocatable link.
884 std::vector<Relocatable_relocs*>* map_to_relocatable_relocs_;
885 // Mappings for merge sections. This is managed by the code in the
887 Object_merge_map* object_merge_map_;
888 // Whether we need to wait for output sections to be written before
889 // we can apply relocations.
890 bool relocs_must_follow_section_writes_;
891 // Used to store the relocs data computed by the Read_relocs pass.
892 // Used during garbage collection of unused sections.
893 Read_relocs_data* rd_;
894 // Used to store the symbols data computed by the Read_symbols pass.
895 // Again used during garbage collection when laying out referenced
897 gold::Symbols_data *sd_;
900 // This class is used to handle relocations against a section symbol
901 // in an SHF_MERGE section. For such a symbol, we need to know the
902 // addend of the relocation before we can determine the final value.
903 // The addend gives us the location in the input section, and we can
904 // determine how it is mapped to the output section. For a
905 // non-section symbol, we apply the addend to the final value of the
906 // symbol; that is done in finalize_local_symbols, and does not use
910 class Merged_symbol_value
913 typedef typename elfcpp::Elf_types<size>::Elf_Addr Value;
915 // We use a hash table to map offsets in the input section to output
917 typedef Unordered_map<section_offset_type, Value> Output_addresses;
919 Merged_symbol_value(Value input_value, Value output_start_address)
920 : input_value_(input_value), output_start_address_(output_start_address),
924 // Initialize the hash table.
926 initialize_input_to_output_map(const Relobj*, unsigned int input_shndx);
928 // Release the hash table to save space.
930 free_input_to_output_map()
931 { this->output_addresses_.clear(); }
933 // Get the output value corresponding to an addend. The object and
934 // input section index are passed in because the caller will have
935 // them; otherwise we could store them here.
937 value(const Relobj* object, unsigned int input_shndx, Value addend) const
939 // This is a relocation against a section symbol. ADDEND is the
940 // offset in the section. The result should be the start of some
941 // merge area. If the object file wants something else, it should
942 // use a regular symbol rather than a section symbol.
943 // Unfortunately, PR 6658 shows a case in which the object file
944 // refers to the section symbol, but uses a negative ADDEND to
945 // compensate for a PC relative reloc. We can't handle the
946 // general case. However, we can handle the special case of a
947 // negative addend, by assuming that it refers to the start of the
948 // section. Of course, that means that we have to guess when
949 // ADDEND is negative. It is normal to see a 32-bit value here
950 // even when the template parameter size is 64, as 64-bit object
951 // file formats have 32-bit relocations. We know this is a merge
952 // section, so we know it has to fit into memory. So we assume
953 // that we won't see a value larger than a large 32-bit unsigned
954 // value. This will break objects with very very large merge
955 // sections; they probably break in other ways anyhow.
956 Value input_offset = this->input_value_;
957 if (addend < 0xffffff00)
959 input_offset += addend;
962 typename Output_addresses::const_iterator p =
963 this->output_addresses_.find(input_offset);
964 if (p != this->output_addresses_.end())
965 return p->second + addend;
967 return (this->value_from_output_section(object, input_shndx, input_offset)
972 // Get the output value for an input offset if we couldn't find it
973 // in the hash table.
975 value_from_output_section(const Relobj*, unsigned int input_shndx,
976 Value input_offset) const;
978 // The value of the section symbol in the input file. This is
979 // normally zero, but could in principle be something else.
981 // The start address of this merged section in the output file.
982 Value output_start_address_;
983 // A hash table which maps offsets in the input section to output
984 // addresses. This only maps specific offsets, not all offsets.
985 Output_addresses output_addresses_;
988 // This POD class is holds the value of a symbol. This is used for
989 // local symbols, and for all symbols during relocation processing.
990 // For special sections, such as SHF_MERGE sections, this calls a
991 // function to get the final symbol value.
997 typedef typename elfcpp::Elf_types<size>::Elf_Addr Value;
1000 : output_symtab_index_(0), output_dynsym_index_(-1U), input_shndx_(0),
1001 is_ordinary_shndx_(false), is_section_symbol_(false),
1002 is_tls_symbol_(false), has_output_value_(true)
1003 { this->u_.value = 0; }
1005 // Get the value of this symbol. OBJECT is the object in which this
1006 // symbol is defined, and ADDEND is an addend to add to the value.
1007 template<bool big_endian>
1009 value(const Sized_relobj<size, big_endian>* object, Value addend) const
1011 if (this->has_output_value_)
1012 return this->u_.value + addend;
1015 gold_assert(this->is_ordinary_shndx_);
1016 return this->u_.merged_symbol_value->value(object, this->input_shndx_,
1021 // Set the value of this symbol in the output symbol table.
1023 set_output_value(Value value)
1024 { this->u_.value = value; }
1026 // For a section symbol in a merged section, we need more
1029 set_merged_symbol_value(Merged_symbol_value<size>* msv)
1031 gold_assert(this->is_section_symbol_);
1032 this->has_output_value_ = false;
1033 this->u_.merged_symbol_value = msv;
1036 // Initialize the input to output map for a section symbol in a
1037 // merged section. We also initialize the value of a non-section
1038 // symbol in a merged section.
1040 initialize_input_to_output_map(const Relobj* object)
1042 if (!this->has_output_value_)
1044 gold_assert(this->is_section_symbol_ && this->is_ordinary_shndx_);
1045 Merged_symbol_value<size>* msv = this->u_.merged_symbol_value;
1046 msv->initialize_input_to_output_map(object, this->input_shndx_);
1050 // Free the input to output map for a section symbol in a merged
1053 free_input_to_output_map()
1055 if (!this->has_output_value_)
1056 this->u_.merged_symbol_value->free_input_to_output_map();
1059 // Set the value of the symbol from the input file. This is only
1060 // called by count_local_symbols, to communicate the value to
1061 // finalize_local_symbols.
1063 set_input_value(Value value)
1064 { this->u_.value = value; }
1066 // Return the input value. This is only called by
1067 // finalize_local_symbols and (in special cases) relocate_section.
1070 { return this->u_.value; }
1072 // Return whether this symbol should go into the output symbol
1075 needs_output_symtab_entry() const
1076 { return this->output_symtab_index_ != -1U; }
1078 // Return the index in the output symbol table.
1080 output_symtab_index() const
1082 gold_assert(this->output_symtab_index_ != 0);
1083 return this->output_symtab_index_;
1086 // Set the index in the output symbol table.
1088 set_output_symtab_index(unsigned int i)
1090 gold_assert(this->output_symtab_index_ == 0);
1091 this->output_symtab_index_ = i;
1094 // Record that this symbol should not go into the output symbol
1097 set_no_output_symtab_entry()
1099 gold_assert(this->output_symtab_index_ == 0);
1100 this->output_symtab_index_ = -1U;
1103 // Set the index in the output dynamic symbol table.
1105 set_needs_output_dynsym_entry()
1107 gold_assert(!this->is_section_symbol());
1108 this->output_dynsym_index_ = 0;
1111 // Return whether this symbol should go into the output symbol
1114 needs_output_dynsym_entry() const
1116 return this->output_dynsym_index_ != -1U;
1119 // Record that this symbol should go into the dynamic symbol table.
1121 set_output_dynsym_index(unsigned int i)
1123 gold_assert(this->output_dynsym_index_ == 0);
1124 this->output_dynsym_index_ = i;
1127 // Return the index in the output dynamic symbol table.
1129 output_dynsym_index() const
1131 gold_assert(this->output_dynsym_index_ != 0
1132 && this->output_dynsym_index_ != -1U);
1133 return this->output_dynsym_index_;
1136 // Set the index of the input section in the input file.
1138 set_input_shndx(unsigned int i, bool is_ordinary)
1140 this->input_shndx_ = i;
1141 // input_shndx_ field is a bitfield, so make sure that the value
1143 gold_assert(this->input_shndx_ == i);
1144 this->is_ordinary_shndx_ = is_ordinary;
1147 // Return the index of the input section in the input file.
1149 input_shndx(bool* is_ordinary) const
1151 *is_ordinary = this->is_ordinary_shndx_;
1152 return this->input_shndx_;
1155 // Whether this is a section symbol.
1157 is_section_symbol() const
1158 { return this->is_section_symbol_; }
1160 // Record that this is a section symbol.
1162 set_is_section_symbol()
1164 gold_assert(!this->needs_output_dynsym_entry());
1165 this->is_section_symbol_ = true;
1168 // Record that this is a TLS symbol.
1171 { this->is_tls_symbol_ = true; }
1173 // Return TRUE if this is a TLS symbol.
1175 is_tls_symbol() const
1176 { return this->is_tls_symbol_; }
1179 // The index of this local symbol in the output symbol table. This
1180 // will be -1 if the symbol should not go into the symbol table.
1181 unsigned int output_symtab_index_;
1182 // The index of this local symbol in the dynamic symbol table. This
1183 // will be -1 if the symbol should not go into the symbol table.
1184 unsigned int output_dynsym_index_;
1185 // The section index in the input file in which this symbol is
1187 unsigned int input_shndx_ : 28;
1188 // Whether the section index is an ordinary index, not a special
1190 bool is_ordinary_shndx_ : 1;
1191 // Whether this is a STT_SECTION symbol.
1192 bool is_section_symbol_ : 1;
1193 // Whether this is a STT_TLS symbol.
1194 bool is_tls_symbol_ : 1;
1195 // Whether this symbol has a value for the output file. This is
1196 // normally set to true during Layout::finalize, by
1197 // finalize_local_symbols. It will be false for a section symbol in
1198 // a merge section, as for such symbols we can not determine the
1199 // value to use in a relocation until we see the addend.
1200 bool has_output_value_ : 1;
1203 // This is used if has_output_value_ is true. Between
1204 // count_local_symbols and finalize_local_symbols, this is the
1205 // value in the input file. After finalize_local_symbols, it is
1206 // the value in the output file.
1208 // This is used if has_output_value_ is false. It points to the
1209 // information we need to get the value for a merge section.
1210 Merged_symbol_value<size>* merged_symbol_value;
1214 // A GOT offset list. A symbol may have more than one GOT offset
1215 // (e.g., when mixing modules compiled with two different TLS models),
1216 // but will usually have at most one. GOT_TYPE identifies the type of
1217 // GOT entry; its values are specific to each target.
1219 class Got_offset_list
1223 : got_type_(-1U), got_offset_(0), got_next_(NULL)
1226 Got_offset_list(unsigned int got_type, unsigned int got_offset)
1227 : got_type_(got_type), got_offset_(got_offset), got_next_(NULL)
1232 if (this->got_next_ != NULL)
1234 delete this->got_next_;
1235 this->got_next_ = NULL;
1239 // Initialize the fields to their default values.
1243 this->got_type_ = -1U;
1244 this->got_offset_ = 0;
1245 this->got_next_ = NULL;
1248 // Set the offset for the GOT entry of type GOT_TYPE.
1250 set_offset(unsigned int got_type, unsigned int got_offset)
1252 if (this->got_type_ == -1U)
1254 this->got_type_ = got_type;
1255 this->got_offset_ = got_offset;
1259 for (Got_offset_list* g = this; g != NULL; g = g->got_next_)
1261 if (g->got_type_ == got_type)
1263 g->got_offset_ = got_offset;
1267 Got_offset_list* g = new Got_offset_list(got_type, got_offset);
1268 g->got_next_ = this->got_next_;
1269 this->got_next_ = g;
1273 // Return the offset for a GOT entry of type GOT_TYPE.
1275 get_offset(unsigned int got_type) const
1277 for (const Got_offset_list* g = this; g != NULL; g = g->got_next_)
1279 if (g->got_type_ == got_type)
1280 return g->got_offset_;
1286 unsigned int got_type_;
1287 unsigned int got_offset_;
1288 Got_offset_list* got_next_;
1291 // A regular object file. This is size and endian specific.
1293 template<int size, bool big_endian>
1294 class Sized_relobj : public Relobj
1297 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
1298 typedef std::vector<Symbol*> Symbols;
1299 typedef std::vector<Symbol_value<size> > Local_values;
1301 static const Address invalid_address = static_cast<Address>(0) - 1;
1303 Sized_relobj(const std::string& name, Input_file* input_file, off_t offset,
1304 const typename elfcpp::Ehdr<size, big_endian>&);
1308 // Checks if the offset of input section SHNDX within its output
1309 // section is invalid.
1311 is_output_section_offset_invalid(unsigned int shndx) const
1312 { return this->get_output_section_offset(shndx) == invalid_address; }
1314 // Set up the object file based on the ELF header.
1316 setup(const typename elfcpp::Ehdr<size, big_endian>&);
1318 // Return the number of symbols. This is only valid after
1319 // Object::add_symbols has been called.
1321 symbol_count() const
1322 { return this->local_symbol_count_ + this->symbols_.size(); }
1324 // If SYM is the index of a global symbol in the object file's
1325 // symbol table, return the Symbol object. Otherwise, return NULL.
1327 global_symbol(unsigned int sym) const
1329 if (sym >= this->local_symbol_count_)
1331 gold_assert(sym - this->local_symbol_count_ < this->symbols_.size());
1332 return this->symbols_[sym - this->local_symbol_count_];
1337 // Return the section index of symbol SYM. Set *VALUE to its value
1338 // in the object file. Set *IS_ORDINARY if this is an ordinary
1339 // section index, not a special code between SHN_LORESERVE and
1340 // SHN_HIRESERVE. Note that for a symbol which is not defined in
1341 // this object file, this will set *VALUE to 0 and return SHN_UNDEF;
1342 // it will not return the final value of the symbol in the link.
1344 symbol_section_and_value(unsigned int sym, Address* value, bool* is_ordinary);
1346 // Return a pointer to the Symbol_value structure which holds the
1347 // value of a local symbol.
1348 const Symbol_value<size>*
1349 local_symbol(unsigned int sym) const
1351 gold_assert(sym < this->local_values_.size());
1352 return &this->local_values_[sym];
1355 // Return the index of local symbol SYM in the ordinary symbol
1356 // table. A value of -1U means that the symbol is not being output.
1358 symtab_index(unsigned int sym) const
1360 gold_assert(sym < this->local_values_.size());
1361 return this->local_values_[sym].output_symtab_index();
1364 // Return the index of local symbol SYM in the dynamic symbol
1365 // table. A value of -1U means that the symbol is not being output.
1367 dynsym_index(unsigned int sym) const
1369 gold_assert(sym < this->local_values_.size());
1370 return this->local_values_[sym].output_dynsym_index();
1373 // Return the input section index of local symbol SYM.
1375 local_symbol_input_shndx(unsigned int sym, bool* is_ordinary) const
1377 gold_assert(sym < this->local_values_.size());
1378 return this->local_values_[sym].input_shndx(is_ordinary);
1381 // Return the appropriate Sized_target structure.
1382 Sized_target<size, big_endian>*
1384 { return this->Object::sized_target<size, big_endian>(); }
1386 // Record that local symbol SYM needs a dynamic symbol entry.
1388 set_needs_output_dynsym_entry(unsigned int sym)
1390 gold_assert(sym < this->local_values_.size());
1391 this->local_values_[sym].set_needs_output_dynsym_entry();
1394 // Return whether the local symbol SYMNDX has a GOT offset.
1395 // For TLS symbols, the GOT entry will hold its tp-relative offset.
1397 local_has_got_offset(unsigned int symndx, unsigned int got_type) const
1399 Local_got_offsets::const_iterator p =
1400 this->local_got_offsets_.find(symndx);
1401 return (p != this->local_got_offsets_.end()
1402 && p->second->get_offset(got_type) != -1U);
1405 // Return the GOT offset of the local symbol SYMNDX.
1407 local_got_offset(unsigned int symndx, unsigned int got_type) const
1409 Local_got_offsets::const_iterator p =
1410 this->local_got_offsets_.find(symndx);
1411 gold_assert(p != this->local_got_offsets_.end());
1412 unsigned int off = p->second->get_offset(got_type);
1413 gold_assert(off != -1U);
1417 // Set the GOT offset of the local symbol SYMNDX to GOT_OFFSET.
1419 set_local_got_offset(unsigned int symndx, unsigned int got_type,
1420 unsigned int got_offset)
1422 Local_got_offsets::const_iterator p =
1423 this->local_got_offsets_.find(symndx);
1424 if (p != this->local_got_offsets_.end())
1425 p->second->set_offset(got_type, got_offset);
1428 Got_offset_list* g = new Got_offset_list(got_type, got_offset);
1429 std::pair<Local_got_offsets::iterator, bool> ins =
1430 this->local_got_offsets_.insert(std::make_pair(symndx, g));
1431 gold_assert(ins.second);
1435 // Get the offset of input section SHNDX within its output section.
1436 // This is -1 if the input section requires a special mapping, such
1437 // as a merge section. The output section can be found in the
1438 // output_sections_ field of the parent class Relobj.
1440 get_output_section_offset(unsigned int shndx) const
1442 gold_assert(shndx < this->section_offsets_.size());
1443 return this->section_offsets_[shndx];
1446 // Return the name of the symbol that spans the given offset in the
1447 // specified section in this object. This is used only for error
1448 // messages and is not particularly efficient.
1450 get_symbol_location_info(unsigned int shndx, off_t offset,
1451 Symbol_location_info* info);
1453 // Look for a kept section corresponding to the given discarded section,
1454 // and return its output address. This is used only for relocations in
1455 // debugging sections.
1457 map_to_kept_section(unsigned int shndx, bool* found) const;
1460 // Read the symbols.
1462 do_read_symbols(Read_symbols_data*);
1464 // Return the number of local symbols.
1466 do_local_symbol_count() const
1467 { return this->local_symbol_count_; }
1469 // Lay out the input sections.
1471 do_layout(Symbol_table*, Layout*, Read_symbols_data*);
1473 // Layout sections whose layout was deferred while waiting for
1474 // input files from a plugin.
1476 do_layout_deferred_sections(Layout*);
1478 // Add the symbols to the symbol table.
1480 do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
1484 do_read_relocs(Read_relocs_data*);
1486 // Process the relocs to find list of referenced sections. Used only
1487 // during garbage collection.
1489 do_gc_process_relocs(const General_options&, Symbol_table*, Layout*,
1492 // Scan the relocs and adjust the symbol table.
1494 do_scan_relocs(const General_options&, Symbol_table*, Layout*,
1497 // Count the local symbols.
1499 do_count_local_symbols(Stringpool_template<char>*,
1500 Stringpool_template<char>*);
1502 // Finalize the local symbols.
1504 do_finalize_local_symbols(unsigned int, off_t, Symbol_table*);
1506 // Set the offset where local dynamic symbol information will be stored.
1508 do_set_local_dynsym_indexes(unsigned int);
1510 // Set the offset where local dynamic symbol information will be stored.
1512 do_set_local_dynsym_offset(off_t);
1514 // Relocate the input sections and write out the local symbols.
1516 do_relocate(const General_options& options, const Symbol_table* symtab,
1517 const Layout*, Output_file* of);
1519 // Get the size of a section.
1521 do_section_size(unsigned int shndx)
1522 { return this->elf_file_.section_size(shndx); }
1524 // Get the name of a section.
1526 do_section_name(unsigned int shndx)
1527 { return this->elf_file_.section_name(shndx); }
1529 // Return the location of the contents of a section.
1531 do_section_contents(unsigned int shndx)
1532 { return this->elf_file_.section_contents(shndx); }
1534 // Return section flags.
1536 do_section_flags(unsigned int shndx);
1538 // Return section entsize.
1540 do_section_entsize(unsigned int shndx);
1542 // Return section address.
1544 do_section_address(unsigned int shndx)
1545 { return this->elf_file_.section_addr(shndx); }
1547 // Return section type.
1549 do_section_type(unsigned int shndx)
1550 { return this->elf_file_.section_type(shndx); }
1552 // Return the section link field.
1554 do_section_link(unsigned int shndx)
1555 { return this->elf_file_.section_link(shndx); }
1557 // Return the section info field.
1559 do_section_info(unsigned int shndx)
1560 { return this->elf_file_.section_info(shndx); }
1562 // Return the section alignment.
1564 do_section_addralign(unsigned int shndx)
1565 { return this->elf_file_.section_addralign(shndx); }
1567 // Return the Xindex structure to use.
1569 do_initialize_xindex();
1571 // Get symbol counts.
1573 do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const;
1575 // Get the offset of a section.
1577 do_output_section_offset(unsigned int shndx) const
1579 Address off = this->get_output_section_offset(shndx);
1580 if (off == invalid_address)
1585 // Set the offset of a section.
1587 do_set_section_offset(unsigned int shndx, uint64_t off)
1589 gold_assert(shndx < this->section_offsets_.size());
1590 this->section_offsets_[shndx] = convert_types<Address, uint64_t>(off);
1595 typedef Sized_relobj<size, big_endian> This;
1596 static const int ehdr_size = elfcpp::Elf_sizes<size>::ehdr_size;
1597 static const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
1598 static const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1599 typedef elfcpp::Shdr<size, big_endian> Shdr;
1601 // To keep track of discarded comdat sections, we need to map a member
1602 // section index to the object and section index of the corresponding
1604 struct Kept_comdat_section
1606 Kept_comdat_section(Relobj* a_object, unsigned int a_shndx)
1607 : object(a_object), shndx(a_shndx)
1612 typedef std::map<unsigned int, Kept_comdat_section>
1613 Kept_comdat_section_table;
1615 // Adjust a section index if necessary.
1617 adjust_shndx(unsigned int shndx)
1619 if (shndx >= elfcpp::SHN_LORESERVE)
1620 shndx += this->elf_file_.large_shndx_offset();
1624 // Find the SHT_SYMTAB section, given the section headers.
1626 find_symtab(const unsigned char* pshdrs);
1628 // Return whether SHDR has the right flags for a GNU style exception
1631 check_eh_frame_flags(const elfcpp::Shdr<size, big_endian>* shdr) const;
1633 // Return whether there is a section named .eh_frame which might be
1634 // a GNU style exception frame section.
1636 find_eh_frame(const unsigned char* pshdrs, const char* names,
1637 section_size_type names_size) const;
1639 // Whether to include a section group in the link.
1641 include_section_group(Symbol_table*, Layout*, unsigned int, const char*,
1642 const unsigned char*, const char *, section_size_type,
1643 std::vector<bool>*);
1645 // Whether to include a linkonce section in the link.
1647 include_linkonce_section(Layout*, unsigned int, const char*,
1648 const elfcpp::Shdr<size, big_endian>&);
1650 // Layout an input section.
1652 layout_section(Layout* layout, unsigned int shndx, const char* name,
1653 typename This::Shdr& shdr, unsigned int reloc_shndx,
1654 unsigned int reloc_type);
1656 // Views and sizes when relocating.
1659 unsigned char* view;
1660 typename elfcpp::Elf_types<size>::Elf_Addr address;
1662 section_size_type view_size;
1663 bool is_input_output_view;
1664 bool is_postprocessing_view;
1667 typedef std::vector<View_size> Views;
1669 // Write section data to the output file. Record the views and
1670 // sizes in VIEWS for use when relocating.
1672 write_sections(const unsigned char* pshdrs, Output_file*, Views*);
1674 // Relocate the sections in the output file.
1676 relocate_sections(const General_options& options, const Symbol_table*,
1677 const Layout*, const unsigned char* pshdrs, Views*);
1679 // Scan the input relocations for --emit-relocs.
1681 emit_relocs_scan(const General_options&, Symbol_table*, Layout*,
1682 const unsigned char* plocal_syms,
1683 const Read_relocs_data::Relocs_list::iterator&);
1685 // Scan the input relocations for --emit-relocs, templatized on the
1686 // type of the relocation section.
1687 template<int sh_type>
1689 emit_relocs_scan_reltype(const General_options&, Symbol_table*, Layout*,
1690 const unsigned char* plocal_syms,
1691 const Read_relocs_data::Relocs_list::iterator&,
1692 Relocatable_relocs*);
1694 // Emit the relocs for --emit-relocs.
1696 emit_relocs(const Relocate_info<size, big_endian>*, unsigned int,
1697 unsigned int sh_type, const unsigned char* prelocs,
1698 size_t reloc_count, Output_section*, Address output_offset,
1699 unsigned char* view, Address address,
1700 section_size_type view_size,
1701 unsigned char* reloc_view, section_size_type reloc_view_size);
1703 // Emit the relocs for --emit-relocs, templatized on the type of the
1704 // relocation section.
1705 template<int sh_type>
1707 emit_relocs_reltype(const Relocate_info<size, big_endian>*, unsigned int,
1708 const unsigned char* prelocs, size_t reloc_count,
1709 Output_section*, Address output_offset,
1710 unsigned char* view, Address address,
1711 section_size_type view_size,
1712 unsigned char* reloc_view,
1713 section_size_type reloc_view_size);
1715 // Initialize input to output maps for section symbols in merged
1718 initialize_input_to_output_maps();
1720 // Free the input to output maps for section symbols in merged
1723 free_input_to_output_maps();
1725 // Write out the local symbols.
1727 write_local_symbols(Output_file*,
1728 const Stringpool_template<char>*,
1729 const Stringpool_template<char>*,
1730 Output_symtab_xindex*,
1731 Output_symtab_xindex*);
1733 // Clear the local symbol information.
1735 clear_local_symbols()
1737 this->local_values_.clear();
1738 this->local_got_offsets_.clear();
1741 // Record a mapping from discarded section SHNDX to the corresponding
1744 set_kept_comdat_section(unsigned int shndx, Relobj* kept_object,
1745 unsigned int kept_shndx)
1747 Kept_comdat_section kept(kept_object, kept_shndx);
1748 this->kept_comdat_sections_.insert(std::make_pair(shndx, kept));
1751 // Find the kept section corresponding to the discarded section
1752 // SHNDX. Return true if found.
1754 get_kept_comdat_section(unsigned int shndx, Relobj** kept_object,
1755 unsigned int* kept_shndx) const
1757 typename Kept_comdat_section_table::const_iterator p =
1758 this->kept_comdat_sections_.find(shndx);
1759 if (p == this->kept_comdat_sections_.end())
1761 *kept_object = p->second.object;
1762 *kept_shndx = p->second.shndx;
1766 // The GOT offsets of local symbols. This map also stores GOT offsets
1767 // for tp-relative offsets for TLS symbols.
1768 typedef Unordered_map<unsigned int, Got_offset_list*> Local_got_offsets;
1770 // The TLS GOT offsets of local symbols. The map stores the offsets
1771 // for either a single GOT entry that holds the module index of a TLS
1772 // symbol, or a pair of GOT entries containing the module index and
1773 // dtv-relative offset.
1774 struct Tls_got_entry
1776 Tls_got_entry(int got_offset, bool have_pair)
1777 : got_offset_(got_offset),
1778 have_pair_(have_pair)
1783 typedef Unordered_map<unsigned int, Tls_got_entry> Local_tls_got_offsets;
1785 // Saved information for sections whose layout was deferred.
1786 struct Deferred_layout
1788 static const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
1789 Deferred_layout(unsigned int shndx, const char* name,
1790 const unsigned char* pshdr,
1791 unsigned int reloc_shndx, unsigned int reloc_type)
1792 : shndx_(shndx), name_(name), reloc_shndx_(reloc_shndx),
1793 reloc_type_(reloc_type)
1795 memcpy(this->shdr_data_, pshdr, shdr_size);
1797 unsigned int shndx_;
1799 unsigned int reloc_shndx_;
1800 unsigned int reloc_type_;
1801 unsigned char shdr_data_[shdr_size];
1804 // General access to the ELF file.
1805 elfcpp::Elf_file<size, big_endian, Object> elf_file_;
1806 // Index of SHT_SYMTAB section.
1807 unsigned int symtab_shndx_;
1808 // The number of local symbols.
1809 unsigned int local_symbol_count_;
1810 // The number of local symbols which go into the output file.
1811 unsigned int output_local_symbol_count_;
1812 // The number of local symbols which go into the output file's dynamic
1814 unsigned int output_local_dynsym_count_;
1815 // The entries in the symbol table for the external symbols.
1817 // Number of symbols defined in object file itself.
1818 size_t defined_count_;
1819 // File offset for local symbols.
1820 off_t local_symbol_offset_;
1821 // File offset for local dynamic symbols.
1822 off_t local_dynsym_offset_;
1823 // Values of local symbols.
1824 Local_values local_values_;
1825 // GOT offsets for local non-TLS symbols, and tp-relative offsets
1826 // for TLS symbols, indexed by symbol number.
1827 Local_got_offsets local_got_offsets_;
1828 // For each input section, the offset of the input section in its
1829 // output section. This is INVALID_ADDRESS if the input section requires a
1831 std::vector<Address> section_offsets_;
1832 // Table mapping discarded comdat sections to corresponding kept sections.
1833 Kept_comdat_section_table kept_comdat_sections_;
1834 // Whether this object has a GNU style .eh_frame section.
1836 // If this object has a GNU style .eh_frame section that is discarded in
1837 // output, record the index here. Otherwise it is -1U.
1838 unsigned int discarded_eh_frame_shndx_;
1839 // The list of sections whose layout was deferred.
1840 std::vector<Deferred_layout> deferred_layout_;
1843 // A class to manage the list of all objects.
1849 : relobj_list_(), dynobj_list_(), sonames_(), cref_(NULL)
1852 // The type of the list of input relocateable objects.
1853 typedef std::vector<Relobj*> Relobj_list;
1854 typedef Relobj_list::const_iterator Relobj_iterator;
1856 // The type of the list of input dynamic objects.
1857 typedef std::vector<Dynobj*> Dynobj_list;
1858 typedef Dynobj_list::const_iterator Dynobj_iterator;
1860 // Add an object to the list. Return true if all is well, or false
1861 // if this object should be ignored.
1863 add_object(Object*);
1865 // Start processing an archive.
1867 archive_start(Archive*);
1869 // Stop processing an archive.
1871 archive_stop(Archive*);
1873 // For each dynamic object, check whether we've seen all of its
1874 // explicit dependencies.
1876 check_dynamic_dependencies() const;
1878 // Return whether an object was found in the system library
1881 found_in_system_library_directory(const Object*) const;
1883 // Print symbol counts.
1885 print_symbol_counts(const Symbol_table*) const;
1887 // Iterate over all regular objects.
1890 relobj_begin() const
1891 { return this->relobj_list_.begin(); }
1895 { return this->relobj_list_.end(); }
1897 // Iterate over all dynamic objects.
1900 dynobj_begin() const
1901 { return this->dynobj_list_.begin(); }
1905 { return this->dynobj_list_.end(); }
1907 // Return whether we have seen any dynamic objects.
1910 { return !this->dynobj_list_.empty(); }
1912 // Return the number of input objects.
1914 number_of_input_objects() const
1915 { return this->relobj_list_.size() + this->dynobj_list_.size(); }
1918 Input_objects(const Input_objects&);
1919 Input_objects& operator=(const Input_objects&);
1921 // The list of ordinary objects included in the link.
1922 Relobj_list relobj_list_;
1923 // The list of dynamic objects included in the link.
1924 Dynobj_list dynobj_list_;
1925 // SONAMEs that we have seen.
1926 Unordered_set<std::string> sonames_;
1927 // Manage cross-references if requested.
1931 // Some of the information we pass to the relocation routines. We
1932 // group this together to avoid passing a dozen different arguments.
1934 template<int size, bool big_endian>
1935 struct Relocate_info
1937 // Command line options.
1938 const General_options* options;
1940 const Symbol_table* symtab;
1942 const Layout* layout;
1943 // Object being relocated.
1944 Sized_relobj<size, big_endian>* object;
1945 // Section index of relocation section.
1946 unsigned int reloc_shndx;
1947 // Section index of section being relocated.
1948 unsigned int data_shndx;
1950 // Return a string showing the location of a relocation. This is
1951 // only used for error messages.
1953 location(size_t relnum, off_t reloffset) const;
1956 // Return whether INPUT_FILE contains an ELF object start at file
1957 // offset OFFSET. This sets *START to point to a view of the start of
1958 // the file. It sets *READ_SIZE to the number of bytes in the view.
1961 is_elf_object(Input_file* input_file, off_t offset,
1962 const unsigned char** start, int *read_size);
1964 // Return an Object appropriate for the input file. P is BYTES long,
1965 // and holds the ELF header. If PUNCONFIGURED is not NULL, then if
1966 // this sees an object the linker is not configured to support, it
1967 // sets *PUNCONFIGURED to true and returns NULL without giving an
1971 make_elf_object(const std::string& name, Input_file*,
1972 off_t offset, const unsigned char* p,
1973 section_offset_type bytes, bool* punconfigured);
1975 } // end namespace gold
1977 #endif // !defined(GOLD_OBJECT_H)