Remove unnecessary elfcpp_config.h file.
[deliverable/binutils-gdb.git] / gold / target.h
CommitLineData
14bfc3f5 1// target.h -- target support for gold -*- C++ -*-
bae7f79e
ILT
2
3// The abstract class Target is the interface for target specific
4// support. It defines abstract methods which each target must
5// implement. Typically there will be one target per processor, but
6// in some cases it may be necessary to have subclasses.
7
8// For speed and consistency we want to use inline functions to handle
9// relocation processing. So besides implementations of the abstract
10// methods, each target is expected to define a template
11// specialization of the relocation functions.
12
13#ifndef GOLD_TARGET_H
14#define GOLD_TARGET_H
15
14bfc3f5
ILT
16#include "elfcpp.h"
17
bae7f79e
ILT
18namespace gold
19{
20
92e059d8 21class General_options;
14bfc3f5 22class Object;
61ba1cf9 23template<int size, bool big_endian>
f6ce93d6 24class Sized_relobj;
92e059d8
ILT
25template<int size, bool big_endian>
26struct Relocate_info;
f6ce93d6
ILT
27class Symbol;
28template<int size>
29class Sized_symbol;
30class Symbol_table;
14bfc3f5
ILT
31
32// The abstract class for target specific handling.
33
bae7f79e
ILT
34class Target
35{
36 public:
14bfc3f5
ILT
37 virtual ~Target()
38 { }
39
40 // Return the bit size that this target implements. This should
41 // return 32 or 64.
42 int
43 get_size() const
75f65a3e 44 { return this->pti_->size; }
14bfc3f5
ILT
45
46 // Return whether this target is big-endian.
47 bool
48 is_big_endian() const
75f65a3e 49 { return this->pti_->is_big_endian; }
14bfc3f5 50
61ba1cf9
ILT
51 // Machine code to store in e_machine field of ELF header.
52 elfcpp::EM
53 machine_code() const
54 { return this->pti_->machine_code; }
55
14bfc3f5
ILT
56 // Whether this target has a specific make_symbol function.
57 bool
58 has_make_symbol() const
75f65a3e 59 { return this->pti_->has_make_symbol; }
14bfc3f5
ILT
60
61 // Whether this target has a specific resolve function.
62 bool
63 has_resolve() const
75f65a3e
ILT
64 { return this->pti_->has_resolve; }
65
c51e6221
ILT
66 // Whether this target has a specific code fill function.
67 bool
68 has_code_fill() const
69 { return this->pti_->has_code_fill; }
70
dbe717ef
ILT
71 // Return the default name of the dynamic linker.
72 const char*
73 dynamic_linker() const
74 { return this->pti_->dynamic_linker; }
75
75f65a3e
ILT
76 // Return the default address to use for the text segment.
77 uint64_t
78 text_segment_address() const
79 { return this->pti_->text_segment_address; }
80
81 // Return the ABI specified page size.
82 uint64_t
83 abi_pagesize() const
84 { return this->pti_->abi_pagesize; }
85
86 // Return the common page size used on actual systems.
87 uint64_t
88 common_pagesize() const
89 { return this->pti_->common_pagesize; }
14bfc3f5 90
5a6f7e2d
ILT
91 // This is called to tell the target to complete any sections it is
92 // handling. After this all sections must have their final size.
93 void
7e1edb90
ILT
94 finalize_sections(Layout* layout)
95 { return this->do_finalize_sections(layout); }
5a6f7e2d 96
c51e6221
ILT
97 // Return a string to use to fill out a code section. This is
98 // basically one or more NOPS which must fill out the specified
99 // length in bytes.
100 std::string
101 code_fill(off_t length)
102 { return this->do_code_fill(length); }
103
14bfc3f5 104 protected:
75f65a3e
ILT
105 // This struct holds the constant information for a child class. We
106 // use a struct to avoid the overhead of virtual function calls for
107 // simple information.
108 struct Target_info
109 {
110 // Address size (32 or 64).
111 int size;
112 // Whether the target is big endian.
113 bool is_big_endian;
61ba1cf9
ILT
114 // The code to store in the e_machine field of the ELF header.
115 elfcpp::EM machine_code;
75f65a3e
ILT
116 // Whether this target has a specific make_symbol function.
117 bool has_make_symbol;
118 // Whether this target has a specific resolve function.
119 bool has_resolve;
c51e6221
ILT
120 // Whether this target has a specific code fill function.
121 bool has_code_fill;
dbe717ef
ILT
122 // The default dynamic linker name.
123 const char* dynamic_linker;
75f65a3e
ILT
124 // The default text segment address.
125 uint64_t text_segment_address;
126 // The ABI specified page size.
127 uint64_t abi_pagesize;
128 // The common page size used by actual implementations.
129 uint64_t common_pagesize;
130 };
131
132 Target(const Target_info* pti)
133 : pti_(pti)
14bfc3f5
ILT
134 { }
135
5a6f7e2d
ILT
136 // Virtual function which may be implemented by the child class.
137 virtual void
7e1edb90 138 do_finalize_sections(Layout*)
5a6f7e2d
ILT
139 { }
140
c51e6221
ILT
141 // Virtual function which must be implemented by the child class if
142 // needed.
143 virtual std::string
144 do_code_fill(off_t)
145 { gold_unreachable(); }
146
14bfc3f5
ILT
147 private:
148 Target(const Target&);
149 Target& operator=(const Target&);
150
75f65a3e
ILT
151 // The target information.
152 const Target_info* pti_;
bae7f79e
ILT
153};
154
14bfc3f5
ILT
155// The abstract class for a specific size and endianness of target.
156// Each actual target implementation class should derive from an
157// instantiation of Sized_target.
158
159template<int size, bool big_endian>
160class Sized_target : public Target
161{
162 public:
163 // Make a new symbol table entry for the target. This should be
164 // overridden by a target which needs additional information in the
165 // symbol table. This will only be called if has_make_symbol()
166 // returns true.
167 virtual Sized_symbol<size>*
14b31740 168 make_symbol() const
a3ad94ed 169 { gold_unreachable(); }
14bfc3f5
ILT
170
171 // Resolve a symbol for the target. This should be overridden by a
172 // target which needs to take special action. TO is the
173 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
14b31740
ILT
174 // VERSION is the version of SYM. This will only be called if
175 // has_resolve() returns true.
14bfc3f5 176 virtual void
14b31740
ILT
177 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*,
178 const char*)
a3ad94ed 179 { gold_unreachable(); }
14bfc3f5 180
92e059d8
ILT
181 // Scan the relocs for a section, and record any information
182 // required for the symbol. OPTIONS is the command line options.
183 // SYMTAB is the symbol table. OBJECT is the object in which the
a3ad94ed
ILT
184 // section appears. DATA_SHNDX is the section index that these
185 // relocs apply to. SH_TYPE is the type of the relocation section,
92e059d8
ILT
186 // SHT_REL or SHT_RELA. PRELOCS points to the relocation data.
187 // RELOC_COUNT is the number of relocs. LOCAL_SYMBOL_COUNT is the
188 // number of local symbols. PLOCAL_SYMBOLS points to the local
189 // symbol data from OBJECT. GLOBAL_SYMBOLS is the array of pointers
190 // to the global symbol table from OBJECT.
61ba1cf9 191 virtual void
92e059d8
ILT
192 scan_relocs(const General_options& options,
193 Symbol_table* symtab,
ead1e424 194 Layout* layout,
f6ce93d6 195 Sized_relobj<size, big_endian>* object,
a3ad94ed 196 unsigned int data_shndx,
92e059d8
ILT
197 unsigned int sh_type,
198 const unsigned char* prelocs,
199 size_t reloc_count,
200 size_t local_symbol_count,
201 const unsigned char* plocal_symbols,
202 Symbol** global_symbols) = 0;
203
204 // Relocate section data. SH_TYPE is the type of the relocation
205 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
206 // information. RELOC_COUNT is the number of relocs. VIEW is a
207 // view into the output file holding the section contents,
208 // VIEW_ADDRESS is the virtual address of the view, and VIEW_SIZE is
209 // the size of the view.
210 virtual void
211 relocate_section(const Relocate_info<size, big_endian>*,
212 unsigned int sh_type,
213 const unsigned char* prelocs,
214 size_t reloc_count,
215 unsigned char* view,
216 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
217 off_t view_size) = 0;
61ba1cf9 218
14bfc3f5 219 protected:
75f65a3e
ILT
220 Sized_target(const Target::Target_info* pti)
221 : Target(pti)
222 {
a3ad94ed
ILT
223 gold_assert(pti->size == size);
224 gold_assert(pti->is_big_endian ? big_endian : !big_endian);
75f65a3e 225 }
14bfc3f5 226};
bae7f79e
ILT
227
228} // End namespace gold.
229
230#endif // !defined(GOLD_TARGET_H)
This page took 0.080843 seconds and 4 git commands to generate.