Commit | Line | Data |
---|---|---|
61ba1cf9 ILT |
1 | // reloc.h -- relocate input files for gold -*- C++ -*- |
2 | ||
3 | #ifndef GOLD_RELOC_H | |
4 | #define GOLD_RELOC_H | |
5 | ||
92e059d8 ILT |
6 | #include <byteswap.h> |
7 | ||
61ba1cf9 ILT |
8 | #include "workqueue.h" |
9 | ||
10 | namespace gold | |
11 | { | |
12 | ||
a3ad94ed | 13 | class General_options; |
f6ce93d6 | 14 | class Relobj; |
92e059d8 ILT |
15 | class Read_relocs_data; |
16 | class Stringpool; | |
a3ad94ed | 17 | class Symbol; |
ead1e424 | 18 | class Layout; |
92e059d8 ILT |
19 | |
20 | // A class to read the relocations for an object file, and then queue | |
21 | // up a task to see if they require any GOT/PLT/COPY relocations in | |
22 | // the symbol table. | |
23 | ||
24 | class Read_relocs : public Task | |
25 | { | |
26 | public: | |
27 | // SYMTAB_LOCK is used to lock the symbol table. BLOCKER should be | |
28 | // unblocked when the Scan_relocs task completes. | |
29 | Read_relocs(const General_options& options, Symbol_table* symtab, | |
f6ce93d6 | 30 | Layout* layout, Relobj* object, Task_token* symtab_lock, |
92e059d8 | 31 | Task_token* blocker) |
ead1e424 | 32 | : options_(options), symtab_(symtab), layout_(layout), object_(object), |
92e059d8 ILT |
33 | symtab_lock_(symtab_lock), blocker_(blocker) |
34 | { } | |
35 | ||
36 | // The standard Task methods. | |
37 | ||
38 | Is_runnable_type | |
39 | is_runnable(Workqueue*); | |
40 | ||
41 | Task_locker* | |
42 | locks(Workqueue*); | |
43 | ||
44 | void | |
45 | run(Workqueue*); | |
46 | ||
47 | private: | |
48 | const General_options& options_; | |
49 | Symbol_table* symtab_; | |
ead1e424 | 50 | Layout* layout_; |
f6ce93d6 | 51 | Relobj* object_; |
92e059d8 ILT |
52 | Task_token* symtab_lock_; |
53 | Task_token* blocker_; | |
54 | }; | |
55 | ||
56 | // Scan the relocations for an object to see if they require any | |
57 | // GOT/PLT/COPY relocations. | |
58 | ||
59 | class Scan_relocs : public Task | |
60 | { | |
61 | public: | |
62 | // SYMTAB_LOCK is used to lock the symbol table. BLOCKER should be | |
63 | // unblocked when the task completes. | |
64 | Scan_relocs(const General_options& options, Symbol_table* symtab, | |
f6ce93d6 | 65 | Layout* layout, Relobj* object, Read_relocs_data* rd, |
ead1e424 ILT |
66 | Task_token* symtab_lock, Task_token* blocker) |
67 | : options_(options), symtab_(symtab), layout_(layout), object_(object), | |
68 | rd_(rd), symtab_lock_(symtab_lock), blocker_(blocker) | |
92e059d8 ILT |
69 | { } |
70 | ||
71 | // The standard Task methods. | |
72 | ||
73 | Is_runnable_type | |
74 | is_runnable(Workqueue*); | |
75 | ||
76 | Task_locker* | |
77 | locks(Workqueue*); | |
78 | ||
79 | void | |
80 | run(Workqueue*); | |
81 | ||
82 | private: | |
83 | class Scan_relocs_locker; | |
84 | ||
85 | const General_options& options_; | |
86 | Symbol_table* symtab_; | |
ead1e424 | 87 | Layout* layout_; |
f6ce93d6 | 88 | Relobj* object_; |
92e059d8 ILT |
89 | Read_relocs_data* rd_; |
90 | Task_token* symtab_lock_; | |
91 | Task_token* blocker_; | |
92 | }; | |
93 | ||
94 | // A class to perform all the relocations for an object file. | |
95 | ||
61ba1cf9 ILT |
96 | class Relocate_task : public Task |
97 | { | |
98 | public: | |
99 | Relocate_task(const General_options& options, const Symbol_table* symtab, | |
f6ce93d6 | 100 | const Layout* layout, Relobj* object, Output_file* of, |
61ba1cf9 | 101 | Task_token* final_blocker) |
92e059d8 | 102 | : options_(options), symtab_(symtab), layout_(layout), object_(object), |
61ba1cf9 ILT |
103 | of_(of), final_blocker_(final_blocker) |
104 | { } | |
105 | ||
106 | // The standard Task methods. | |
107 | ||
108 | Is_runnable_type | |
109 | is_runnable(Workqueue*); | |
110 | ||
111 | Task_locker* | |
112 | locks(Workqueue*); | |
113 | ||
114 | void | |
115 | run(Workqueue*); | |
116 | ||
117 | private: | |
118 | class Relocate_locker; | |
119 | ||
120 | const General_options& options_; | |
121 | const Symbol_table* symtab_; | |
92e059d8 | 122 | const Layout* layout_; |
f6ce93d6 | 123 | Relobj* object_; |
61ba1cf9 ILT |
124 | Output_file* of_; |
125 | Task_token* final_blocker_; | |
126 | }; | |
127 | ||
92e059d8 ILT |
128 | // Standard relocation routines which are used on many targets. Here |
129 | // SIZE and BIG_ENDIAN refer to the target, not the relocation type. | |
130 | ||
131 | template<int size, bool big_endian> | |
132 | class Relocate_functions | |
133 | { | |
134 | private: | |
135 | // Do a simple relocation with the addend in the section contents. | |
136 | // VALSIZE is the size of the value. | |
137 | template<int valsize> | |
138 | static inline void | |
f6ce93d6 ILT |
139 | rel(unsigned char* view, |
140 | typename elfcpp::Swap<valsize, big_endian>::Valtype value) | |
92e059d8 | 141 | { |
f6ce93d6 | 142 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; |
92e059d8 | 143 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
f6ce93d6 ILT |
144 | Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv); |
145 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value); | |
92e059d8 ILT |
146 | } |
147 | ||
148 | // Do a simple PC relative relocation with the addend in the section | |
149 | // contents. VALSIZE is the size of the value. | |
150 | template<int valsize> | |
151 | static inline void | |
f6ce93d6 ILT |
152 | pcrel(unsigned char* view, |
153 | typename elfcpp::Swap<valsize, big_endian>::Valtype value, | |
92e059d8 ILT |
154 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
155 | { | |
f6ce93d6 | 156 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; |
92e059d8 | 157 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
f6ce93d6 ILT |
158 | Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv); |
159 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value - address); | |
92e059d8 ILT |
160 | } |
161 | ||
162 | typedef Relocate_functions<size, big_endian> This; | |
163 | ||
164 | public: | |
165 | // Do a simple 8-bit REL relocation with the addend in the object | |
166 | // file data. | |
167 | static inline void | |
168 | rel8(unsigned char* view, unsigned char value) | |
169 | { | |
170 | This::template rel<8>(view, value); | |
171 | } | |
172 | ||
173 | // Do a simple 8-bit PC relative relocation with the addend in the | |
174 | // object file data. | |
175 | static inline void | |
176 | pcrel8(unsigned char* view, unsigned char value, | |
177 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
178 | { | |
179 | This::template pcrel<8>(view, value, address); | |
180 | } | |
181 | ||
182 | // Do a simple 16-bit REL relocation with the addend in the object | |
183 | // file data. | |
184 | static inline void | |
185 | rel16(unsigned char* view, elfcpp::Elf_Half value) | |
186 | { | |
187 | This::template rel<16>(view, value); | |
188 | } | |
189 | ||
190 | // Do a simple 32-bit PC relative REL relocation with the addend in | |
191 | // the object file data. | |
192 | static inline void | |
193 | pcrel16(unsigned char* view, elfcpp::Elf_Word value, | |
194 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
195 | { | |
196 | This::template pcrel<16>(view, value, address); | |
197 | } | |
198 | ||
199 | // Do a simple 32-bit REL relocation with the addend in the section | |
200 | // contents. | |
201 | static inline void | |
202 | rel32(unsigned char* view, elfcpp::Elf_Word value) | |
203 | { | |
204 | This::template rel<32>(view, value); | |
205 | } | |
206 | ||
207 | // Do a simple 32-bit PC relative REL relocation with the addend in | |
208 | // the section contents. | |
209 | static inline void | |
210 | pcrel32(unsigned char* view, elfcpp::Elf_Word value, | |
211 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
212 | { | |
213 | This::template pcrel<32>(view, value, address); | |
214 | } | |
215 | ||
216 | // Do a simple 64-bit REL relocation with the addend in the section | |
217 | // contents. | |
218 | static inline void | |
f6ce93d6 | 219 | rel64(unsigned char* view, elfcpp::Elf_Xword value) |
92e059d8 ILT |
220 | { |
221 | This::template rel<64>(view, value); | |
222 | } | |
223 | ||
224 | // Do a simple 64-bit PC relative REL relocation with the addend in | |
225 | // the section contents. | |
226 | static inline void | |
f6ce93d6 | 227 | pcrel64(unsigned char* view, elfcpp::Elf_Xword value, |
92e059d8 ILT |
228 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
229 | { | |
230 | This::template pcrel<64>(view, value, address); | |
231 | } | |
a3ad94ed ILT |
232 | |
233 | // Return whether we need a COPY reloc for a reloc against GSYM, | |
234 | // which is being applied to section SHNDX in OBJECT. | |
235 | static bool | |
236 | need_copy_reloc(const General_options*, Relobj* object, unsigned int shndx, | |
237 | Symbol* gsym); | |
92e059d8 ILT |
238 | }; |
239 | ||
61ba1cf9 ILT |
240 | } // End namespace gold. |
241 | ||
242 | #endif // !defined(GOLD_RELOC_H) |