]> Git Repo - binutils.git/blame - gold/target.h
*** empty log message ***
[binutils.git] / gold / target.h
CommitLineData
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 <[email protected]>.
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 36#include "elfcpp.h"
cd72c291 37#include "parameters.h"
14bfc3f5 38
bae7f79e
ILT
39namespace gold
40{
41
92e059d8 42class General_options;
14bfc3f5 43class Object;
61ba1cf9 44template<int size, bool big_endian>
f6ce93d6 45class Sized_relobj;
6a74a719 46class Relocatable_relocs;
92e059d8 47template<int size, bool big_endian>
730cdc88 48class Relocate_info;
f6ce93d6
ILT
49class Symbol;
50template<int size>
51class Sized_symbol;
52class Symbol_table;
730cdc88 53class Output_section;
14bfc3f5
ILT
54
55// The abstract class for target specific handling.
56
bae7f79e
ILT
57class Target
58{
59 public:
14bfc3f5
ILT
60 virtual ~Target()
61 { }
62
63 // Return the bit size that this target implements. This should
64 // return 32 or 64.
65 int
66 get_size() const
75f65a3e 67 { return this->pti_->size; }
14bfc3f5
ILT
68
69 // Return whether this target is big-endian.
70 bool
71 is_big_endian() const
75f65a3e 72 { return this->pti_->is_big_endian; }
14bfc3f5 73
61ba1cf9
ILT
74 // Machine code to store in e_machine field of ELF header.
75 elfcpp::EM
76 machine_code() const
77 { return this->pti_->machine_code; }
78
14bfc3f5
ILT
79 // Whether this target has a specific make_symbol function.
80 bool
81 has_make_symbol() const
75f65a3e 82 { return this->pti_->has_make_symbol; }
14bfc3f5
ILT
83
84 // Whether this target has a specific resolve function.
85 bool
86 has_resolve() const
75f65a3e
ILT
87 { return this->pti_->has_resolve; }
88
c51e6221
ILT
89 // Whether this target has a specific code fill function.
90 bool
91 has_code_fill() const
92 { return this->pti_->has_code_fill; }
93
dbe717ef
ILT
94 // Return the default name of the dynamic linker.
95 const char*
96 dynamic_linker() const
97 { return this->pti_->dynamic_linker; }
98
75f65a3e
ILT
99 // Return the default address to use for the text segment.
100 uint64_t
0c5e9c22
ILT
101 default_text_segment_address() const
102 { return this->pti_->default_text_segment_address; }
75f65a3e
ILT
103
104 // Return the ABI specified page size.
105 uint64_t
106 abi_pagesize() const
cd72c291
ILT
107 {
108 if (parameters->max_page_size() > 0)
109 return parameters->max_page_size();
110 else
111 return this->pti_->abi_pagesize;
112 }
75f65a3e
ILT
113
114 // Return the common page size used on actual systems.
115 uint64_t
116 common_pagesize() const
cd72c291
ILT
117 {
118 if (parameters->common_page_size() > 0)
119 return std::min(parameters->common_page_size(),
120 this->abi_pagesize());
121 else
122 return std::min(this->pti_->common_pagesize,
123 this->abi_pagesize());
124 }
14bfc3f5 125
35cdfc9a
ILT
126 // If we see some object files with .note.GNU-stack sections, and
127 // some objects files without them, this returns whether we should
128 // consider the object files without them to imply that the stack
129 // should be executable.
130 bool
131 is_default_stack_executable() const
132 { return this->pti_->is_default_stack_executable; }
133
5a6f7e2d
ILT
134 // This is called to tell the target to complete any sections it is
135 // handling. After this all sections must have their final size.
136 void
7e1edb90
ILT
137 finalize_sections(Layout* layout)
138 { return this->do_finalize_sections(layout); }
5a6f7e2d 139
ab5c9e90
ILT
140 // Return the value to use for a global symbol which needs a special
141 // value in the dynamic symbol table. This will only be called if
142 // the backend first calls symbol->set_needs_dynsym_value().
143 uint64_t
144 dynsym_value(const Symbol* sym) const
145 { return this->do_dynsym_value(sym); }
146
c51e6221
ILT
147 // Return a string to use to fill out a code section. This is
148 // basically one or more NOPS which must fill out the specified
149 // length in bytes.
150 std::string
fe8718a4 151 code_fill(section_size_type length)
c51e6221
ILT
152 { return this->do_code_fill(length); }
153
9a2d6984
ILT
154 // Return whether SYM is known to be defined by the ABI. This is
155 // used to avoid inappropriate warnings about undefined symbols.
156 bool
157 is_defined_by_abi(Symbol* sym) const
158 { return this->do_is_defined_by_abi(sym); }
159
14bfc3f5 160 protected:
75f65a3e
ILT
161 // This struct holds the constant information for a child class. We
162 // use a struct to avoid the overhead of virtual function calls for
163 // simple information.
164 struct Target_info
165 {
166 // Address size (32 or 64).
167 int size;
168 // Whether the target is big endian.
169 bool is_big_endian;
61ba1cf9
ILT
170 // The code to store in the e_machine field of the ELF header.
171 elfcpp::EM machine_code;
75f65a3e
ILT
172 // Whether this target has a specific make_symbol function.
173 bool has_make_symbol;
174 // Whether this target has a specific resolve function.
175 bool has_resolve;
c51e6221
ILT
176 // Whether this target has a specific code fill function.
177 bool has_code_fill;
35cdfc9a
ILT
178 // Whether an object file with no .note.GNU-stack sections implies
179 // that the stack should be executable.
180 bool is_default_stack_executable;
dbe717ef
ILT
181 // The default dynamic linker name.
182 const char* dynamic_linker;
75f65a3e 183 // The default text segment address.
0c5e9c22 184 uint64_t default_text_segment_address;
75f65a3e
ILT
185 // The ABI specified page size.
186 uint64_t abi_pagesize;
187 // The common page size used by actual implementations.
188 uint64_t common_pagesize;
189 };
190
191 Target(const Target_info* pti)
192 : pti_(pti)
14bfc3f5
ILT
193 { }
194
5a6f7e2d
ILT
195 // Virtual function which may be implemented by the child class.
196 virtual void
7e1edb90 197 do_finalize_sections(Layout*)
5a6f7e2d
ILT
198 { }
199
ab5c9e90
ILT
200 // Virtual function which may be implemented by the child class.
201 virtual uint64_t
202 do_dynsym_value(const Symbol*) const
203 { gold_unreachable(); }
204
c51e6221
ILT
205 // Virtual function which must be implemented by the child class if
206 // needed.
207 virtual std::string
fe8718a4 208 do_code_fill(section_size_type)
c51e6221
ILT
209 { gold_unreachable(); }
210
9a2d6984
ILT
211 // Virtual function which may be implemented by the child class.
212 virtual bool
213 do_is_defined_by_abi(Symbol*) const
214 { return false; }
215
14bfc3f5
ILT
216 private:
217 Target(const Target&);
218 Target& operator=(const Target&);
219
75f65a3e
ILT
220 // The target information.
221 const Target_info* pti_;
bae7f79e
ILT
222};
223
14bfc3f5
ILT
224// The abstract class for a specific size and endianness of target.
225// Each actual target implementation class should derive from an
226// instantiation of Sized_target.
227
228template<int size, bool big_endian>
229class Sized_target : public Target
230{
231 public:
232 // Make a new symbol table entry for the target. This should be
233 // overridden by a target which needs additional information in the
234 // symbol table. This will only be called if has_make_symbol()
235 // returns true.
236 virtual Sized_symbol<size>*
14b31740 237 make_symbol() const
a3ad94ed 238 { gold_unreachable(); }
14bfc3f5
ILT
239
240 // Resolve a symbol for the target. This should be overridden by a
241 // target which needs to take special action. TO is the
242 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
14b31740
ILT
243 // VERSION is the version of SYM. This will only be called if
244 // has_resolve() returns true.
14bfc3f5 245 virtual void
14b31740
ILT
246 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*,
247 const char*)
a3ad94ed 248 { gold_unreachable(); }
14bfc3f5 249
92e059d8
ILT
250 // Scan the relocs for a section, and record any information
251 // required for the symbol. OPTIONS is the command line options.
252 // SYMTAB is the symbol table. OBJECT is the object in which the
a3ad94ed
ILT
253 // section appears. DATA_SHNDX is the section index that these
254 // relocs apply to. SH_TYPE is the type of the relocation section,
92e059d8
ILT
255 // SHT_REL or SHT_RELA. PRELOCS points to the relocation data.
256 // RELOC_COUNT is the number of relocs. LOCAL_SYMBOL_COUNT is the
730cdc88
ILT
257 // number of local symbols. OUTPUT_SECTION is the output section.
258 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
259 // sections are not mapped as usual. PLOCAL_SYMBOLS points to the
260 // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
261 // pointers to the global symbol table from OBJECT.
61ba1cf9 262 virtual void
92e059d8
ILT
263 scan_relocs(const General_options& options,
264 Symbol_table* symtab,
ead1e424 265 Layout* layout,
f6ce93d6 266 Sized_relobj<size, big_endian>* object,
a3ad94ed 267 unsigned int data_shndx,
92e059d8
ILT
268 unsigned int sh_type,
269 const unsigned char* prelocs,
270 size_t reloc_count,
730cdc88
ILT
271 Output_section* output_section,
272 bool needs_special_offset_handling,
92e059d8 273 size_t local_symbol_count,
730cdc88 274 const unsigned char* plocal_symbols) = 0;
92e059d8
ILT
275
276 // Relocate section data. SH_TYPE is the type of the relocation
277 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
730cdc88
ILT
278 // information. RELOC_COUNT is the number of relocs.
279 // OUTPUT_SECTION is the output section.
280 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
281 // to correspond to the output section. VIEW is a view into the
282 // output file holding the section contents, VIEW_ADDRESS is the
283 // virtual address of the view, and VIEW_SIZE is the size of the
284 // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
285 // parameters refer to the complete output section data, not just
286 // the input section data.
92e059d8
ILT
287 virtual void
288 relocate_section(const Relocate_info<size, big_endian>*,
289 unsigned int sh_type,
290 const unsigned char* prelocs,
291 size_t reloc_count,
730cdc88
ILT
292 Output_section* output_section,
293 bool needs_special_offset_handling,
92e059d8
ILT
294 unsigned char* view,
295 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
fe8718a4 296 section_size_type view_size) = 0;
61ba1cf9 297
6a74a719
ILT
298 // Scan the relocs during a relocatable link. The parameters are
299 // like scan_relocs, with an additional Relocatable_relocs
300 // parameter, used to record the disposition of the relocs.
301 virtual void
302 scan_relocatable_relocs(const General_options& options,
303 Symbol_table* symtab,
304 Layout* layout,
305 Sized_relobj<size, big_endian>* object,
306 unsigned int data_shndx,
307 unsigned int sh_type,
308 const unsigned char* prelocs,
309 size_t reloc_count,
310 Output_section* output_section,
311 bool needs_special_offset_handling,
312 size_t local_symbol_count,
313 const unsigned char* plocal_symbols,
314 Relocatable_relocs*) = 0;
315
316 // Relocate a section during a relocatable link. The parameters are
317 // like relocate_section, with additional parameters for the view of
318 // the output reloc section.
319 virtual void
320 relocate_for_relocatable(const Relocate_info<size, big_endian>*,
321 unsigned int sh_type,
322 const unsigned char* prelocs,
323 size_t reloc_count,
324 Output_section* output_section,
325 off_t offset_in_output_section,
326 const Relocatable_relocs*,
327 unsigned char* view,
328 typename elfcpp::Elf_types<size>::Elf_Addr
329 view_address,
330 section_size_type view_size,
331 unsigned char* reloc_view,
332 section_size_type reloc_view_size) = 0;
333
14bfc3f5 334 protected:
75f65a3e
ILT
335 Sized_target(const Target::Target_info* pti)
336 : Target(pti)
337 {
a3ad94ed
ILT
338 gold_assert(pti->size == size);
339 gold_assert(pti->is_big_endian ? big_endian : !big_endian);
75f65a3e 340 }
14bfc3f5 341};
bae7f79e
ILT
342
343} // End namespace gold.
344
345#endif // !defined(GOLD_TARGET_H)
This page took 0.220807 seconds and 4 git commands to generate.