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