* peXXigen.c: Updates for PE/COFF V8.0, and clarification
[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
75f65a3e
ILT
16#include <cassert>
17
14bfc3f5
ILT
18#include "elfcpp.h"
19
bae7f79e
ILT
20namespace gold
21{
22
92e059d8 23class General_options;
14bfc3f5 24class Object;
61ba1cf9 25template<int size, bool big_endian>
f6ce93d6 26class Sized_relobj;
92e059d8
ILT
27template<int size, bool big_endian>
28struct Relocate_info;
f6ce93d6
ILT
29class Symbol;
30template<int size>
31class Sized_symbol;
32class Symbol_table;
14bfc3f5
ILT
33
34// The abstract class for target specific handling.
35
bae7f79e
ILT
36class Target
37{
38 public:
14bfc3f5
ILT
39 virtual ~Target()
40 { }
41
42 // Return the bit size that this target implements. This should
43 // return 32 or 64.
44 int
45 get_size() const
75f65a3e 46 { return this->pti_->size; }
14bfc3f5
ILT
47
48 // Return whether this target is big-endian.
49 bool
50 is_big_endian() const
75f65a3e 51 { return this->pti_->is_big_endian; }
14bfc3f5 52
61ba1cf9
ILT
53 // Machine code to store in e_machine field of ELF header.
54 elfcpp::EM
55 machine_code() const
56 { return this->pti_->machine_code; }
57
14bfc3f5
ILT
58 // Whether this target has a specific make_symbol function.
59 bool
60 has_make_symbol() const
75f65a3e 61 { return this->pti_->has_make_symbol; }
14bfc3f5
ILT
62
63 // Whether this target has a specific resolve function.
64 bool
65 has_resolve() const
75f65a3e
ILT
66 { return this->pti_->has_resolve; }
67
68 // Return the default address to use for the text segment.
69 uint64_t
70 text_segment_address() const
71 { return this->pti_->text_segment_address; }
72
73 // Return the ABI specified page size.
74 uint64_t
75 abi_pagesize() const
76 { return this->pti_->abi_pagesize; }
77
78 // Return the common page size used on actual systems.
79 uint64_t
80 common_pagesize() const
81 { return this->pti_->common_pagesize; }
14bfc3f5 82
14bfc3f5 83 protected:
75f65a3e
ILT
84 // This struct holds the constant information for a child class. We
85 // use a struct to avoid the overhead of virtual function calls for
86 // simple information.
87 struct Target_info
88 {
89 // Address size (32 or 64).
90 int size;
91 // Whether the target is big endian.
92 bool is_big_endian;
61ba1cf9
ILT
93 // The code to store in the e_machine field of the ELF header.
94 elfcpp::EM machine_code;
75f65a3e
ILT
95 // Whether this target has a specific make_symbol function.
96 bool has_make_symbol;
97 // Whether this target has a specific resolve function.
98 bool has_resolve;
99 // The default text segment address.
100 uint64_t text_segment_address;
101 // The ABI specified page size.
102 uint64_t abi_pagesize;
103 // The common page size used by actual implementations.
104 uint64_t common_pagesize;
105 };
106
107 Target(const Target_info* pti)
108 : pti_(pti)
14bfc3f5
ILT
109 { }
110
111 private:
112 Target(const Target&);
113 Target& operator=(const Target&);
114
75f65a3e
ILT
115 // The target information.
116 const Target_info* pti_;
bae7f79e
ILT
117};
118
14bfc3f5
ILT
119// The abstract class for a specific size and endianness of target.
120// Each actual target implementation class should derive from an
121// instantiation of Sized_target.
122
123template<int size, bool big_endian>
124class Sized_target : public Target
125{
126 public:
127 // Make a new symbol table entry for the target. This should be
128 // overridden by a target which needs additional information in the
129 // symbol table. This will only be called if has_make_symbol()
130 // returns true.
131 virtual Sized_symbol<size>*
132 make_symbol()
133 { abort(); }
134
135 // Resolve a symbol for the target. This should be overridden by a
136 // target which needs to take special action. TO is the
137 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
92e059d8 138 // This will only be called if has_resolve() returns true.
14bfc3f5
ILT
139 virtual void
140 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*)
141 { abort(); }
142
92e059d8
ILT
143 // Scan the relocs for a section, and record any information
144 // required for the symbol. OPTIONS is the command line options.
145 // SYMTAB is the symbol table. OBJECT is the object in which the
146 // section appears. SH_TYPE is the type of the relocation section,
147 // SHT_REL or SHT_RELA. PRELOCS points to the relocation data.
148 // RELOC_COUNT is the number of relocs. LOCAL_SYMBOL_COUNT is the
149 // number of local symbols. PLOCAL_SYMBOLS points to the local
150 // symbol data from OBJECT. GLOBAL_SYMBOLS is the array of pointers
151 // to the global symbol table from OBJECT.
61ba1cf9 152 virtual void
92e059d8
ILT
153 scan_relocs(const General_options& options,
154 Symbol_table* symtab,
ead1e424 155 Layout* layout,
f6ce93d6 156 Sized_relobj<size, big_endian>* object,
92e059d8
ILT
157 unsigned int sh_type,
158 const unsigned char* prelocs,
159 size_t reloc_count,
160 size_t local_symbol_count,
161 const unsigned char* plocal_symbols,
162 Symbol** global_symbols) = 0;
163
164 // Relocate section data. SH_TYPE is the type of the relocation
165 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
166 // information. RELOC_COUNT is the number of relocs. VIEW is a
167 // view into the output file holding the section contents,
168 // VIEW_ADDRESS is the virtual address of the view, and VIEW_SIZE is
169 // the size of the view.
170 virtual void
171 relocate_section(const Relocate_info<size, big_endian>*,
172 unsigned int sh_type,
173 const unsigned char* prelocs,
174 size_t reloc_count,
175 unsigned char* view,
176 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
177 off_t view_size) = 0;
61ba1cf9 178
14bfc3f5 179 protected:
75f65a3e
ILT
180 Sized_target(const Target::Target_info* pti)
181 : Target(pti)
182 {
183 assert(pti->size == size);
184 assert(pti->is_big_endian ? big_endian : !big_endian);
185 }
14bfc3f5 186};
bae7f79e
ILT
187
188} // End namespace gold.
189
190#endif // !defined(GOLD_TARGET_H)
This page took 0.038539 seconds and 4 git commands to generate.