Commit | Line | Data |
---|---|---|
14bfc3f5 | 1 | // target.h -- target support for gold -*- C++ -*- |
bae7f79e | 2 | |
6cb15b7f ILT |
3 | // Copyright 2006, 2007 Free Software Foundation, Inc. |
4 | // Written by Ian Lance Taylor <iant@google.com>. | |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
bae7f79e ILT |
23 | // The abstract class Target is the interface for target specific |
24 | // support. It defines abstract methods which each target must | |
25 | // implement. Typically there will be one target per processor, but | |
26 | // in some cases it may be necessary to have subclasses. | |
27 | ||
28 | // For speed and consistency we want to use inline functions to handle | |
29 | // relocation processing. So besides implementations of the abstract | |
30 | // methods, each target is expected to define a template | |
31 | // specialization of the relocation functions. | |
32 | ||
33 | #ifndef GOLD_TARGET_H | |
34 | #define GOLD_TARGET_H | |
35 | ||
14bfc3f5 ILT |
36 | #include "elfcpp.h" |
37 | ||
bae7f79e ILT |
38 | namespace gold |
39 | { | |
40 | ||
92e059d8 | 41 | class General_options; |
14bfc3f5 | 42 | class Object; |
61ba1cf9 | 43 | template<int size, bool big_endian> |
f6ce93d6 | 44 | class Sized_relobj; |
92e059d8 | 45 | template<int size, bool big_endian> |
730cdc88 | 46 | class Relocate_info; |
f6ce93d6 ILT |
47 | class Symbol; |
48 | template<int size> | |
49 | class Sized_symbol; | |
50 | class Symbol_table; | |
730cdc88 | 51 | class Output_section; |
14bfc3f5 ILT |
52 | |
53 | // The abstract class for target specific handling. | |
54 | ||
bae7f79e ILT |
55 | class Target |
56 | { | |
57 | public: | |
14bfc3f5 ILT |
58 | virtual ~Target() |
59 | { } | |
60 | ||
61 | // Return the bit size that this target implements. This should | |
62 | // return 32 or 64. | |
63 | int | |
64 | get_size() const | |
75f65a3e | 65 | { return this->pti_->size; } |
14bfc3f5 ILT |
66 | |
67 | // Return whether this target is big-endian. | |
68 | bool | |
69 | is_big_endian() const | |
75f65a3e | 70 | { return this->pti_->is_big_endian; } |
14bfc3f5 | 71 | |
61ba1cf9 ILT |
72 | // Machine code to store in e_machine field of ELF header. |
73 | elfcpp::EM | |
74 | machine_code() const | |
75 | { return this->pti_->machine_code; } | |
76 | ||
14bfc3f5 ILT |
77 | // Whether this target has a specific make_symbol function. |
78 | bool | |
79 | has_make_symbol() const | |
75f65a3e | 80 | { return this->pti_->has_make_symbol; } |
14bfc3f5 ILT |
81 | |
82 | // Whether this target has a specific resolve function. | |
83 | bool | |
84 | has_resolve() const | |
75f65a3e ILT |
85 | { return this->pti_->has_resolve; } |
86 | ||
c51e6221 ILT |
87 | // Whether this target has a specific code fill function. |
88 | bool | |
89 | has_code_fill() const | |
90 | { return this->pti_->has_code_fill; } | |
91 | ||
dbe717ef ILT |
92 | // Return the default name of the dynamic linker. |
93 | const char* | |
94 | dynamic_linker() const | |
95 | { return this->pti_->dynamic_linker; } | |
96 | ||
75f65a3e ILT |
97 | // Return the default address to use for the text segment. |
98 | uint64_t | |
0c5e9c22 ILT |
99 | default_text_segment_address() const |
100 | { return this->pti_->default_text_segment_address; } | |
75f65a3e ILT |
101 | |
102 | // Return the ABI specified page size. | |
103 | uint64_t | |
104 | abi_pagesize() const | |
105 | { return this->pti_->abi_pagesize; } | |
106 | ||
107 | // Return the common page size used on actual systems. | |
108 | uint64_t | |
109 | common_pagesize() const | |
110 | { return this->pti_->common_pagesize; } | |
14bfc3f5 | 111 | |
35cdfc9a ILT |
112 | // If we see some object files with .note.GNU-stack sections, and |
113 | // some objects files without them, this returns whether we should | |
114 | // consider the object files without them to imply that the stack | |
115 | // should be executable. | |
116 | bool | |
117 | is_default_stack_executable() const | |
118 | { return this->pti_->is_default_stack_executable; } | |
119 | ||
5a6f7e2d ILT |
120 | // This is called to tell the target to complete any sections it is |
121 | // handling. After this all sections must have their final size. | |
122 | void | |
7e1edb90 ILT |
123 | finalize_sections(Layout* layout) |
124 | { return this->do_finalize_sections(layout); } | |
5a6f7e2d | 125 | |
ab5c9e90 ILT |
126 | // Return the value to use for a global symbol which needs a special |
127 | // value in the dynamic symbol table. This will only be called if | |
128 | // the backend first calls symbol->set_needs_dynsym_value(). | |
129 | uint64_t | |
130 | dynsym_value(const Symbol* sym) const | |
131 | { return this->do_dynsym_value(sym); } | |
132 | ||
c51e6221 ILT |
133 | // Return a string to use to fill out a code section. This is |
134 | // basically one or more NOPS which must fill out the specified | |
135 | // length in bytes. | |
136 | std::string | |
fe8718a4 | 137 | code_fill(section_size_type length) |
c51e6221 ILT |
138 | { return this->do_code_fill(length); } |
139 | ||
9a2d6984 ILT |
140 | // Return whether SYM is known to be defined by the ABI. This is |
141 | // used to avoid inappropriate warnings about undefined symbols. | |
142 | bool | |
143 | is_defined_by_abi(Symbol* sym) const | |
144 | { return this->do_is_defined_by_abi(sym); } | |
145 | ||
14bfc3f5 | 146 | protected: |
75f65a3e ILT |
147 | // This struct holds the constant information for a child class. We |
148 | // use a struct to avoid the overhead of virtual function calls for | |
149 | // simple information. | |
150 | struct Target_info | |
151 | { | |
152 | // Address size (32 or 64). | |
153 | int size; | |
154 | // Whether the target is big endian. | |
155 | bool is_big_endian; | |
61ba1cf9 ILT |
156 | // The code to store in the e_machine field of the ELF header. |
157 | elfcpp::EM machine_code; | |
75f65a3e ILT |
158 | // Whether this target has a specific make_symbol function. |
159 | bool has_make_symbol; | |
160 | // Whether this target has a specific resolve function. | |
161 | bool has_resolve; | |
c51e6221 ILT |
162 | // Whether this target has a specific code fill function. |
163 | bool has_code_fill; | |
35cdfc9a ILT |
164 | // Whether an object file with no .note.GNU-stack sections implies |
165 | // that the stack should be executable. | |
166 | bool is_default_stack_executable; | |
dbe717ef ILT |
167 | // The default dynamic linker name. |
168 | const char* dynamic_linker; | |
75f65a3e | 169 | // The default text segment address. |
0c5e9c22 | 170 | uint64_t default_text_segment_address; |
75f65a3e ILT |
171 | // The ABI specified page size. |
172 | uint64_t abi_pagesize; | |
173 | // The common page size used by actual implementations. | |
174 | uint64_t common_pagesize; | |
175 | }; | |
176 | ||
177 | Target(const Target_info* pti) | |
178 | : pti_(pti) | |
14bfc3f5 ILT |
179 | { } |
180 | ||
5a6f7e2d ILT |
181 | // Virtual function which may be implemented by the child class. |
182 | virtual void | |
7e1edb90 | 183 | do_finalize_sections(Layout*) |
5a6f7e2d ILT |
184 | { } |
185 | ||
ab5c9e90 ILT |
186 | // Virtual function which may be implemented by the child class. |
187 | virtual uint64_t | |
188 | do_dynsym_value(const Symbol*) const | |
189 | { gold_unreachable(); } | |
190 | ||
c51e6221 ILT |
191 | // Virtual function which must be implemented by the child class if |
192 | // needed. | |
193 | virtual std::string | |
fe8718a4 | 194 | do_code_fill(section_size_type) |
c51e6221 ILT |
195 | { gold_unreachable(); } |
196 | ||
9a2d6984 ILT |
197 | // Virtual function which may be implemented by the child class. |
198 | virtual bool | |
199 | do_is_defined_by_abi(Symbol*) const | |
200 | { return false; } | |
201 | ||
14bfc3f5 ILT |
202 | private: |
203 | Target(const Target&); | |
204 | Target& operator=(const Target&); | |
205 | ||
75f65a3e ILT |
206 | // The target information. |
207 | const Target_info* pti_; | |
bae7f79e ILT |
208 | }; |
209 | ||
14bfc3f5 ILT |
210 | // The abstract class for a specific size and endianness of target. |
211 | // Each actual target implementation class should derive from an | |
212 | // instantiation of Sized_target. | |
213 | ||
214 | template<int size, bool big_endian> | |
215 | class Sized_target : public Target | |
216 | { | |
217 | public: | |
218 | // Make a new symbol table entry for the target. This should be | |
219 | // overridden by a target which needs additional information in the | |
220 | // symbol table. This will only be called if has_make_symbol() | |
221 | // returns true. | |
222 | virtual Sized_symbol<size>* | |
14b31740 | 223 | make_symbol() const |
a3ad94ed | 224 | { gold_unreachable(); } |
14bfc3f5 ILT |
225 | |
226 | // Resolve a symbol for the target. This should be overridden by a | |
227 | // target which needs to take special action. TO is the | |
228 | // pre-existing symbol. SYM is the new symbol, seen in OBJECT. | |
14b31740 ILT |
229 | // VERSION is the version of SYM. This will only be called if |
230 | // has_resolve() returns true. | |
14bfc3f5 | 231 | virtual void |
14b31740 ILT |
232 | resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*, |
233 | const char*) | |
a3ad94ed | 234 | { gold_unreachable(); } |
14bfc3f5 | 235 | |
92e059d8 ILT |
236 | // Scan the relocs for a section, and record any information |
237 | // required for the symbol. OPTIONS is the command line options. | |
238 | // SYMTAB is the symbol table. OBJECT is the object in which the | |
a3ad94ed ILT |
239 | // section appears. DATA_SHNDX is the section index that these |
240 | // relocs apply to. SH_TYPE is the type of the relocation section, | |
92e059d8 ILT |
241 | // SHT_REL or SHT_RELA. PRELOCS points to the relocation data. |
242 | // RELOC_COUNT is the number of relocs. LOCAL_SYMBOL_COUNT is the | |
730cdc88 ILT |
243 | // number of local symbols. OUTPUT_SECTION is the output section. |
244 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output | |
245 | // sections are not mapped as usual. PLOCAL_SYMBOLS points to the | |
246 | // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of | |
247 | // pointers to the global symbol table from OBJECT. | |
61ba1cf9 | 248 | virtual void |
92e059d8 ILT |
249 | scan_relocs(const General_options& options, |
250 | Symbol_table* symtab, | |
ead1e424 | 251 | Layout* layout, |
f6ce93d6 | 252 | Sized_relobj<size, big_endian>* object, |
a3ad94ed | 253 | unsigned int data_shndx, |
92e059d8 ILT |
254 | unsigned int sh_type, |
255 | const unsigned char* prelocs, | |
256 | size_t reloc_count, | |
730cdc88 ILT |
257 | Output_section* output_section, |
258 | bool needs_special_offset_handling, | |
92e059d8 | 259 | size_t local_symbol_count, |
730cdc88 | 260 | const unsigned char* plocal_symbols) = 0; |
92e059d8 ILT |
261 | |
262 | // Relocate section data. SH_TYPE is the type of the relocation | |
263 | // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation | |
730cdc88 ILT |
264 | // information. RELOC_COUNT is the number of relocs. |
265 | // OUTPUT_SECTION is the output section. | |
266 | // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped | |
267 | // to correspond to the output section. VIEW is a view into the | |
268 | // output file holding the section contents, VIEW_ADDRESS is the | |
269 | // virtual address of the view, and VIEW_SIZE is the size of the | |
270 | // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx | |
271 | // parameters refer to the complete output section data, not just | |
272 | // the input section data. | |
92e059d8 ILT |
273 | virtual void |
274 | relocate_section(const Relocate_info<size, big_endian>*, | |
275 | unsigned int sh_type, | |
276 | const unsigned char* prelocs, | |
277 | size_t reloc_count, | |
730cdc88 ILT |
278 | Output_section* output_section, |
279 | bool needs_special_offset_handling, | |
92e059d8 ILT |
280 | unsigned char* view, |
281 | typename elfcpp::Elf_types<size>::Elf_Addr view_address, | |
fe8718a4 | 282 | section_size_type view_size) = 0; |
61ba1cf9 | 283 | |
14bfc3f5 | 284 | protected: |
75f65a3e ILT |
285 | Sized_target(const Target::Target_info* pti) |
286 | : Target(pti) | |
287 | { | |
a3ad94ed ILT |
288 | gold_assert(pti->size == size); |
289 | gold_assert(pti->is_big_endian ? big_endian : !big_endian); | |
75f65a3e | 290 | } |
14bfc3f5 | 291 | }; |
bae7f79e ILT |
292 | |
293 | } // End namespace gold. | |
294 | ||
295 | #endif // !defined(GOLD_TARGET_H) |