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