]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/dynobj.h
1 // dynobj.h -- dynamic object support for gold -*- C++ -*-
13 // A dynamic object (ET_DYN). This is an abstract base class itself.
14 // The implementations is the template class Sized_dynobj.
16 class Dynobj
: public Object
19 Dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
= 0)
20 : Object(name
, input_file
, true, offset
), soname_()
23 // Return the name to use in a DT_NEEDED entry for this object.
27 // Create a standard ELF hash table, setting *PPHASH and *PHASHLEN.
28 // DYNSYMS is the global dynamic symbols. LOCAL_DYNSYM_COUNT is the
29 // number of local dynamic symbols, which is the index of the first
30 // dynamic gobal symbol.
32 create_elf_hash_table(const Target
*, const std::vector
<Symbol
*>& dynsyms
,
33 unsigned int local_dynsym_count
,
34 unsigned char** pphash
,
35 unsigned int* phashlen
);
37 // Create a GNU hash table, setting *PPHASH and *PHASHLEN. DYNSYMS
38 // is the global dynamic symbols. LOCAL_DYNSYM_COUNT is the number
39 // of local dynamic symbols, which is the index of the first dynamic
42 create_gnu_hash_table(const Target
*, const std::vector
<Symbol
*>& dynsyms
,
43 unsigned int local_dynsym_count
,
44 unsigned char** pphash
, unsigned int* phashlen
);
47 // Set the DT_SONAME string.
49 set_soname_string(const char* s
)
50 { this->soname_
.assign(s
); }
53 // Compute the ELF hash code for a string.
55 elf_hash(const char*);
57 // Compute the GNU hash code for a string.
59 gnu_hash(const char*);
61 // Compute the number of hash buckets to use.
63 compute_bucket_count(const std::vector
<uint32_t>& hashcodes
,
64 bool for_gnu_hash_table
);
66 // Sized version of create_elf_hash_table.
67 template<bool big_endian
>
69 sized_create_elf_hash_table(const std::vector
<uint32_t>& bucket
,
70 const std::vector
<uint32_t>& chain
,
72 unsigned int hashlen
);
74 // Sized version of create_gnu_hash_table.
75 template<int size
, bool big_endian
>
77 sized_create_gnu_hash_table(const std::vector
<Symbol
*>& hashed_dynsyms
,
78 const std::vector
<uint32_t>& dynsym_hashvals
,
79 unsigned int unhashed_dynsym_count
,
80 unsigned char** pphash
,
81 unsigned int* phashlen
);
83 // The DT_SONAME name, if any.
87 // A dynamic object, size and endian specific version.
89 template<int size
, bool big_endian
>
90 class Sized_dynobj
: public Dynobj
93 Sized_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
94 const typename
elfcpp::Ehdr
<size
, big_endian
>&);
96 // Set up the object file based on the ELF header.
98 setup(const typename
elfcpp::Ehdr
<size
, big_endian
>&);
102 do_read_symbols(Read_symbols_data
*);
104 // Lay out the input sections.
106 do_layout(const General_options
&, Symbol_table
*, Layout
*,
109 // Add the symbols to the symbol table.
111 do_add_symbols(Symbol_table
*, Read_symbols_data
*);
113 // Get the name of a section.
115 do_section_name(unsigned int shndx
)
116 { return this->elf_file_
.section_name(shndx
); }
118 // Return a view of the contents of a section. Set *PLEN to the
121 do_section_contents(unsigned int shndx
)
122 { return this->elf_file_
.section_contents(shndx
); }
124 // Return section flags.
126 do_section_flags(unsigned int shndx
)
127 { return this->elf_file_
.section_flags(shndx
); }
131 typedef Sized_dynobj
<size
, big_endian
> This
;
132 static const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
133 static const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
134 static const int dyn_size
= elfcpp::Elf_sizes
<size
>::dyn_size
;
135 typedef elfcpp::Shdr
<size
, big_endian
> Shdr
;
136 typedef elfcpp::Dyn
<size
, big_endian
> Dyn
;
138 // Find the dynamic symbol table and the version sections, given the
141 find_dynsym_sections(const unsigned char* pshdrs
,
142 unsigned int* pdynshm_shndx
,
143 unsigned int* pversym_shndx
,
144 unsigned int* pverdef_shndx
,
145 unsigned int* pverneed_shndx
,
146 unsigned int* pdynamic_shndx
);
148 // Read the dynamic symbol section SHNDX.
150 read_dynsym_section(const unsigned char* pshdrs
, unsigned int shndx
,
151 elfcpp::SHT type
, unsigned int link
,
152 File_view
** view
, off_t
* view_size
,
153 unsigned int* view_info
);
155 // Set the SONAME from the SHT_DYNAMIC section at DYNAMIC_SHNDX.
156 // The STRTAB parameters may have the relevant string table.
158 set_soname(const unsigned char* pshdrs
, unsigned int dynamic_shndx
,
159 unsigned int strtab_shndx
, const unsigned char* strtabu
,
162 // Mapping from version number to version name.
163 typedef std::vector
<const char*> Version_map
;
165 // Create the version map.
167 make_version_map(Read_symbols_data
* sd
, Version_map
*) const;
169 // Add an entry to the version map.
171 set_version_map(Version_map
*, unsigned int ndx
, const char* name
) const;
173 // General access to the ELF file.
174 elfcpp::Elf_file
<size
, big_endian
, Object
> elf_file_
;
177 } // End namespace gold.
179 #endif // !defined(GOLD_DYNOBJ_H)