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