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