]>
Commit | Line | Data |
---|---|---|
61ba1cf9 ILT |
1 | // reloc.h -- relocate input files for gold -*- C++ -*- |
2 | ||
93ceb764 | 3 | // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | // Written by Ian Lance Taylor <[email protected]>. |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
61ba1cf9 ILT |
23 | #ifndef GOLD_RELOC_H |
24 | #define GOLD_RELOC_H | |
25 | ||
17a1d0a9 | 26 | #include <vector> |
3d857b98 | 27 | #ifdef HAVE_BYTESWAP_H |
92e059d8 | 28 | #include <byteswap.h> |
3d857b98 | 29 | #endif |
92e059d8 | 30 | |
4c50553d | 31 | #include "elfcpp.h" |
61ba1cf9 ILT |
32 | #include "workqueue.h" |
33 | ||
34 | namespace gold | |
35 | { | |
36 | ||
a3ad94ed | 37 | class General_options; |
b696e6d4 | 38 | class Object; |
f6ce93d6 | 39 | class Relobj; |
92e059d8 | 40 | class Read_relocs_data; |
a3ad94ed | 41 | class Symbol; |
ead1e424 | 42 | class Layout; |
6a74a719 | 43 | class Output_data; |
4f4c5f80 | 44 | class Output_section; |
92e059d8 | 45 | |
5a6f7e2d ILT |
46 | template<int size> |
47 | class Sized_symbol; | |
48 | ||
b8e6aad9 ILT |
49 | template<int size, bool big_endian> |
50 | class Sized_relobj; | |
51 | ||
52 | template<int size> | |
53 | class Symbol_value; | |
54 | ||
5a6f7e2d ILT |
55 | template<int sh_type, bool dynamic, int size, bool big_endian> |
56 | class Output_data_reloc; | |
57 | ||
92e059d8 ILT |
58 | // A class to read the relocations for an object file, and then queue |
59 | // up a task to see if they require any GOT/PLT/COPY relocations in | |
60 | // the symbol table. | |
61 | ||
62 | class Read_relocs : public Task | |
63 | { | |
64 | public: | |
93ceb764 ILT |
65 | // THIS_BLOCKER and NEXT_BLOCKER are passed along to a Scan_relocs |
66 | // or Gc_process_relocs task, so that they run in a deterministic | |
67 | // order. | |
ad0f2072 | 68 | Read_relocs(Symbol_table* symtab, Layout* layout, Relobj* object, |
93ceb764 | 69 | Task_token* this_blocker, Task_token* next_blocker) |
ad0f2072 | 70 | : symtab_(symtab), layout_(layout), object_(object), |
93ceb764 | 71 | this_blocker_(this_blocker), next_blocker_(next_blocker) |
92e059d8 ILT |
72 | { } |
73 | ||
74 | // The standard Task methods. | |
75 | ||
17a1d0a9 ILT |
76 | Task_token* |
77 | is_runnable(); | |
92e059d8 | 78 | |
17a1d0a9 ILT |
79 | void |
80 | locks(Task_locker*); | |
92e059d8 ILT |
81 | |
82 | void | |
83 | run(Workqueue*); | |
84 | ||
c7912668 ILT |
85 | std::string |
86 | get_name() const; | |
87 | ||
92e059d8 | 88 | private: |
92e059d8 | 89 | Symbol_table* symtab_; |
ead1e424 | 90 | Layout* layout_; |
f6ce93d6 | 91 | Relobj* object_; |
93ceb764 ILT |
92 | Task_token* this_blocker_; |
93 | Task_token* next_blocker_; | |
92e059d8 ILT |
94 | }; |
95 | ||
6d03d481 ST |
96 | // Process the relocs to figure out which sections are garbage. |
97 | // Very similar to scan relocs. | |
98 | ||
99 | class Gc_process_relocs : public Task | |
100 | { | |
101 | public: | |
93ceb764 ILT |
102 | // THIS_BLOCKER prevents this task from running until the previous |
103 | // one is finished. NEXT_BLOCKER prevents the next task from | |
104 | // running. | |
ad0f2072 | 105 | Gc_process_relocs(Symbol_table* symtab, Layout* layout, Relobj* object, |
93ceb764 ILT |
106 | Read_relocs_data* rd, Task_token* this_blocker, |
107 | Task_token* next_blocker) | |
ad0f2072 | 108 | : symtab_(symtab), layout_(layout), object_(object), rd_(rd), |
93ceb764 | 109 | this_blocker_(this_blocker), next_blocker_(next_blocker) |
6d03d481 ST |
110 | { } |
111 | ||
93ceb764 ILT |
112 | ~Gc_process_relocs(); |
113 | ||
6d03d481 ST |
114 | // The standard Task methods. |
115 | ||
116 | Task_token* | |
117 | is_runnable(); | |
118 | ||
119 | void | |
120 | locks(Task_locker*); | |
121 | ||
122 | void | |
123 | run(Workqueue*); | |
124 | ||
125 | std::string | |
126 | get_name() const; | |
127 | ||
128 | private: | |
6d03d481 ST |
129 | Symbol_table* symtab_; |
130 | Layout* layout_; | |
131 | Relobj* object_; | |
132 | Read_relocs_data* rd_; | |
93ceb764 ILT |
133 | Task_token* this_blocker_; |
134 | Task_token* next_blocker_; | |
6d03d481 ST |
135 | }; |
136 | ||
92e059d8 ILT |
137 | // Scan the relocations for an object to see if they require any |
138 | // GOT/PLT/COPY relocations. | |
139 | ||
140 | class Scan_relocs : public Task | |
141 | { | |
142 | public: | |
93ceb764 ILT |
143 | // THIS_BLOCKER prevents this task from running until the previous |
144 | // one is finished. NEXT_BLOCKER prevents the next task from | |
145 | // running. | |
ad0f2072 | 146 | Scan_relocs(Symbol_table* symtab, Layout* layout, Relobj* object, |
93ceb764 ILT |
147 | Read_relocs_data* rd, Task_token* this_blocker, |
148 | Task_token* next_blocker) | |
ad0f2072 | 149 | : symtab_(symtab), layout_(layout), object_(object), rd_(rd), |
93ceb764 | 150 | this_blocker_(this_blocker), next_blocker_(next_blocker) |
92e059d8 ILT |
151 | { } |
152 | ||
93ceb764 ILT |
153 | ~Scan_relocs(); |
154 | ||
92e059d8 ILT |
155 | // The standard Task methods. |
156 | ||
17a1d0a9 ILT |
157 | Task_token* |
158 | is_runnable(); | |
92e059d8 | 159 | |
17a1d0a9 ILT |
160 | void |
161 | locks(Task_locker*); | |
92e059d8 ILT |
162 | |
163 | void | |
164 | run(Workqueue*); | |
165 | ||
c7912668 ILT |
166 | std::string |
167 | get_name() const; | |
168 | ||
92e059d8 | 169 | private: |
92e059d8 | 170 | Symbol_table* symtab_; |
ead1e424 | 171 | Layout* layout_; |
f6ce93d6 | 172 | Relobj* object_; |
92e059d8 | 173 | Read_relocs_data* rd_; |
93ceb764 ILT |
174 | Task_token* this_blocker_; |
175 | Task_token* next_blocker_; | |
92e059d8 ILT |
176 | }; |
177 | ||
178 | // A class to perform all the relocations for an object file. | |
179 | ||
61ba1cf9 ILT |
180 | class Relocate_task : public Task |
181 | { | |
182 | public: | |
ad0f2072 ILT |
183 | Relocate_task(const Symbol_table* symtab, const Layout* layout, |
184 | Relobj* object, Output_file* of, | |
730cdc88 ILT |
185 | Task_token* input_sections_blocker, |
186 | Task_token* output_sections_blocker, Task_token* final_blocker) | |
ad0f2072 ILT |
187 | : symtab_(symtab), layout_(layout), object_(object), of_(of), |
188 | input_sections_blocker_(input_sections_blocker), | |
730cdc88 ILT |
189 | output_sections_blocker_(output_sections_blocker), |
190 | final_blocker_(final_blocker) | |
61ba1cf9 ILT |
191 | { } |
192 | ||
193 | // The standard Task methods. | |
194 | ||
17a1d0a9 ILT |
195 | Task_token* |
196 | is_runnable(); | |
61ba1cf9 | 197 | |
17a1d0a9 ILT |
198 | void |
199 | locks(Task_locker*); | |
61ba1cf9 ILT |
200 | |
201 | void | |
202 | run(Workqueue*); | |
203 | ||
c7912668 ILT |
204 | std::string |
205 | get_name() const; | |
206 | ||
61ba1cf9 | 207 | private: |
61ba1cf9 | 208 | const Symbol_table* symtab_; |
92e059d8 | 209 | const Layout* layout_; |
f6ce93d6 | 210 | Relobj* object_; |
61ba1cf9 | 211 | Output_file* of_; |
730cdc88 ILT |
212 | Task_token* input_sections_blocker_; |
213 | Task_token* output_sections_blocker_; | |
61ba1cf9 ILT |
214 | Task_token* final_blocker_; |
215 | }; | |
216 | ||
6a74a719 ILT |
217 | // During a relocatable link, this class records how relocations |
218 | // should be handled for a single input reloc section. An instance of | |
219 | // this class is created while scanning relocs, and it is used while | |
220 | // processing relocs. | |
221 | ||
222 | class Relocatable_relocs | |
223 | { | |
224 | public: | |
225 | // We use a vector of unsigned char to indicate how the input relocs | |
226 | // should be handled. Each element is one of the following values. | |
227 | // We create this vector when we initially scan the relocations. | |
228 | enum Reloc_strategy | |
229 | { | |
230 | // Copy the input reloc. Don't modify it other than updating the | |
231 | // r_offset field and the r_sym part of the r_info field. | |
232 | RELOC_COPY, | |
233 | // Copy the input reloc which is against an STT_SECTION symbol. | |
234 | // Update the r_offset and r_sym part of the r_info field. Adjust | |
235 | // the addend by subtracting the value of the old local symbol and | |
236 | // adding the value of the new local symbol. The addend is in the | |
237 | // SHT_RELA reloc and the contents of the data section do not need | |
238 | // to be changed. | |
239 | RELOC_ADJUST_FOR_SECTION_RELA, | |
7019cd25 ILT |
240 | // Like RELOC_ADJUST_FOR_SECTION_RELA but the addend should not be |
241 | // adjusted. | |
242 | RELOC_ADJUST_FOR_SECTION_0, | |
6a74a719 ILT |
243 | // Like RELOC_ADJUST_FOR_SECTION_RELA but the contents of the |
244 | // section need to be changed. The number indicates the number of | |
245 | // bytes in the addend in the section contents. | |
246 | RELOC_ADJUST_FOR_SECTION_1, | |
247 | RELOC_ADJUST_FOR_SECTION_2, | |
248 | RELOC_ADJUST_FOR_SECTION_4, | |
249 | RELOC_ADJUST_FOR_SECTION_8, | |
250 | // Discard the input reloc--process it completely when relocating | |
251 | // the data section contents. | |
252 | RELOC_DISCARD, | |
253 | // An input reloc which is not discarded, but which requires | |
254 | // target specific processing in order to update it. | |
255 | RELOC_SPECIAL | |
256 | }; | |
257 | ||
258 | Relocatable_relocs() | |
259 | : reloc_strategies_(), output_reloc_count_(0), posd_(NULL) | |
260 | { } | |
261 | ||
262 | // Record the number of relocs. | |
263 | void | |
264 | set_reloc_count(size_t reloc_count) | |
265 | { this->reloc_strategies_.reserve(reloc_count); } | |
266 | ||
267 | // Record what to do for the next reloc. | |
268 | void | |
2ea97941 | 269 | set_next_reloc_strategy(Reloc_strategy strategy) |
6a74a719 | 270 | { |
2ea97941 ILT |
271 | this->reloc_strategies_.push_back(static_cast<unsigned char>(strategy)); |
272 | if (strategy != RELOC_DISCARD) | |
6a74a719 ILT |
273 | ++this->output_reloc_count_; |
274 | } | |
275 | ||
276 | // Record the Output_data associated with this reloc section. | |
277 | void | |
278 | set_output_data(Output_data* posd) | |
279 | { | |
280 | gold_assert(this->posd_ == NULL); | |
281 | this->posd_ = posd; | |
282 | } | |
283 | ||
284 | // Return the Output_data associated with this reloc section. | |
285 | Output_data* | |
286 | output_data() const | |
287 | { return this->posd_; } | |
288 | ||
289 | // Return what to do for reloc I. | |
290 | Reloc_strategy | |
291 | strategy(unsigned int i) const | |
292 | { | |
293 | gold_assert(i < this->reloc_strategies_.size()); | |
294 | return static_cast<Reloc_strategy>(this->reloc_strategies_[i]); | |
295 | } | |
296 | ||
297 | // Return the number of relocations to create in the output file. | |
298 | size_t | |
299 | output_reloc_count() const | |
300 | { return this->output_reloc_count_; } | |
301 | ||
302 | private: | |
303 | typedef std::vector<unsigned char> Reloc_strategies; | |
304 | ||
305 | // The strategies for the input reloc. There is one entry in this | |
306 | // vector for each relocation in the input section. | |
307 | Reloc_strategies reloc_strategies_; | |
308 | // The number of relocations to be created in the output file. | |
309 | size_t output_reloc_count_; | |
310 | // The output data structure associated with this relocation. | |
311 | Output_data* posd_; | |
312 | }; | |
313 | ||
92e059d8 ILT |
314 | // Standard relocation routines which are used on many targets. Here |
315 | // SIZE and BIG_ENDIAN refer to the target, not the relocation type. | |
316 | ||
317 | template<int size, bool big_endian> | |
318 | class Relocate_functions | |
319 | { | |
320 | private: | |
321 | // Do a simple relocation with the addend in the section contents. | |
322 | // VALSIZE is the size of the value. | |
323 | template<int valsize> | |
324 | static inline void | |
f6ce93d6 ILT |
325 | rel(unsigned char* view, |
326 | typename elfcpp::Swap<valsize, big_endian>::Valtype value) | |
92e059d8 | 327 | { |
f6ce93d6 | 328 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; |
92e059d8 | 329 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
f6ce93d6 ILT |
330 | Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv); |
331 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value); | |
92e059d8 ILT |
332 | } |
333 | ||
b8e6aad9 ILT |
334 | // Do a simple relocation using a Symbol_value with the addend in |
335 | // the section contents. VALSIZE is the size of the value to | |
336 | // relocate. | |
337 | template<int valsize> | |
338 | static inline void | |
339 | rel(unsigned char* view, | |
340 | const Sized_relobj<size, big_endian>* object, | |
341 | const Symbol_value<size>* psymval) | |
342 | { | |
343 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
344 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
345 | Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
346 | x = psymval->value(object, x); | |
347 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x); | |
348 | } | |
349 | ||
d830e0e0 ILT |
350 | // Do a simple relocation with the addend in the relocation. |
351 | // VALSIZE is the size of the value. | |
352 | template<int valsize> | |
353 | static inline void | |
354 | rela(unsigned char* view, | |
355 | typename elfcpp::Swap<valsize, big_endian>::Valtype value, | |
356 | typename elfcpp::Swap<valsize, big_endian>::Valtype addend) | |
357 | { | |
358 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
359 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
360 | elfcpp::Swap<valsize, big_endian>::writeval(wv, value + addend); | |
361 | } | |
362 | ||
363 | // Do a simple relocation using a symbol value with the addend in | |
364 | // the relocation. VALSIZE is the size of the value. | |
365 | template<int valsize> | |
366 | static inline void | |
367 | rela(unsigned char* view, | |
368 | const Sized_relobj<size, big_endian>* object, | |
369 | const Symbol_value<size>* psymval, | |
370 | typename elfcpp::Swap<valsize, big_endian>::Valtype addend) | |
371 | { | |
372 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
373 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
374 | Valtype x = psymval->value(object, addend); | |
375 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x); | |
376 | } | |
377 | ||
92e059d8 ILT |
378 | // Do a simple PC relative relocation with the addend in the section |
379 | // contents. VALSIZE is the size of the value. | |
380 | template<int valsize> | |
381 | static inline void | |
f6ce93d6 ILT |
382 | pcrel(unsigned char* view, |
383 | typename elfcpp::Swap<valsize, big_endian>::Valtype value, | |
92e059d8 ILT |
384 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
385 | { | |
f6ce93d6 | 386 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; |
92e059d8 | 387 | Valtype* wv = reinterpret_cast<Valtype*>(view); |
f6ce93d6 ILT |
388 | Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv); |
389 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value - address); | |
92e059d8 ILT |
390 | } |
391 | ||
b8e6aad9 ILT |
392 | // Do a simple PC relative relocation with a Symbol_value with the |
393 | // addend in the section contents. VALSIZE is the size of the | |
394 | // value. | |
395 | template<int valsize> | |
396 | static inline void | |
397 | pcrel(unsigned char* view, | |
398 | const Sized_relobj<size, big_endian>* object, | |
399 | const Symbol_value<size>* psymval, | |
400 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
401 | { | |
402 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
403 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
404 | Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv); | |
405 | x = psymval->value(object, x); | |
406 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x - address); | |
407 | } | |
408 | ||
d830e0e0 ILT |
409 | // Do a simple PC relative relocation with the addend in the |
410 | // relocation. VALSIZE is the size of the value. | |
411 | template<int valsize> | |
412 | static inline void | |
413 | pcrela(unsigned char* view, | |
414 | typename elfcpp::Swap<valsize, big_endian>::Valtype value, | |
415 | typename elfcpp::Swap<valsize, big_endian>::Valtype addend, | |
416 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
417 | { | |
418 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
419 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
420 | elfcpp::Swap<valsize, big_endian>::writeval(wv, value + addend - address); | |
421 | } | |
422 | ||
423 | // Do a simple PC relative relocation with a Symbol_value with the | |
424 | // addend in the relocation. VALSIZE is the size of the value. | |
425 | template<int valsize> | |
426 | static inline void | |
427 | pcrela(unsigned char* view, | |
428 | const Sized_relobj<size, big_endian>* object, | |
429 | const Symbol_value<size>* psymval, | |
430 | typename elfcpp::Swap<valsize, big_endian>::Valtype addend, | |
431 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
432 | { | |
433 | typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype; | |
434 | Valtype* wv = reinterpret_cast<Valtype*>(view); | |
435 | Valtype x = psymval->value(object, addend); | |
436 | elfcpp::Swap<valsize, big_endian>::writeval(wv, x - address); | |
437 | } | |
438 | ||
92e059d8 ILT |
439 | typedef Relocate_functions<size, big_endian> This; |
440 | ||
441 | public: | |
b8e6aad9 ILT |
442 | // Do a simple 8-bit REL relocation with the addend in the section |
443 | // contents. | |
92e059d8 ILT |
444 | static inline void |
445 | rel8(unsigned char* view, unsigned char value) | |
b8e6aad9 ILT |
446 | { This::template rel<8>(view, value); } |
447 | ||
448 | static inline void | |
449 | rel8(unsigned char* view, | |
450 | const Sized_relobj<size, big_endian>* object, | |
451 | const Symbol_value<size>* psymval) | |
452 | { This::template rel<8>(view, object, psymval); } | |
92e059d8 | 453 | |
d830e0e0 ILT |
454 | // Do an 8-bit RELA relocation with the addend in the relocation. |
455 | static inline void | |
5b3463d9 | 456 | rela8(unsigned char* view, unsigned char value, unsigned char addend) |
d830e0e0 ILT |
457 | { This::template rela<8>(view, value, addend); } |
458 | ||
459 | static inline void | |
5b3463d9 | 460 | rela8(unsigned char* view, |
d830e0e0 ILT |
461 | const Sized_relobj<size, big_endian>* object, |
462 | const Symbol_value<size>* psymval, | |
463 | unsigned char addend) | |
464 | { This::template rela<8>(view, object, psymval, addend); } | |
465 | ||
92e059d8 | 466 | // Do a simple 8-bit PC relative relocation with the addend in the |
b8e6aad9 | 467 | // section contents. |
92e059d8 ILT |
468 | static inline void |
469 | pcrel8(unsigned char* view, unsigned char value, | |
470 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
b8e6aad9 ILT |
471 | { This::template pcrel<8>(view, value, address); } |
472 | ||
473 | static inline void | |
474 | pcrel8(unsigned char* view, | |
475 | const Sized_relobj<size, big_endian>* object, | |
476 | const Symbol_value<size>* psymval, | |
477 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
478 | { This::template pcrel<8>(view, object, psymval, address); } | |
92e059d8 | 479 | |
d830e0e0 ILT |
480 | // Do a simple 8-bit PC relative RELA relocation with the addend in |
481 | // the reloc. | |
482 | static inline void | |
483 | pcrela8(unsigned char* view, unsigned char value, unsigned char addend, | |
484 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
485 | { This::template pcrela<8>(view, value, addend, address); } | |
486 | ||
487 | static inline void | |
488 | pcrela8(unsigned char* view, | |
489 | const Sized_relobj<size, big_endian>* object, | |
490 | const Symbol_value<size>* psymval, | |
491 | unsigned char addend, | |
492 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
493 | { This::template pcrela<8>(view, object, psymval, addend, address); } | |
494 | ||
b8e6aad9 ILT |
495 | // Do a simple 16-bit REL relocation with the addend in the section |
496 | // contents. | |
92e059d8 ILT |
497 | static inline void |
498 | rel16(unsigned char* view, elfcpp::Elf_Half value) | |
b8e6aad9 ILT |
499 | { This::template rel<16>(view, value); } |
500 | ||
501 | static inline void | |
502 | rel16(unsigned char* view, | |
503 | const Sized_relobj<size, big_endian>* object, | |
504 | const Symbol_value<size>* psymval) | |
505 | { This::template rel<16>(view, object, psymval); } | |
92e059d8 | 506 | |
d830e0e0 ILT |
507 | // Do an 16-bit RELA relocation with the addend in the relocation. |
508 | static inline void | |
509 | rela16(unsigned char* view, elfcpp::Elf_Half value, elfcpp::Elf_Half addend) | |
510 | { This::template rela<16>(view, value, addend); } | |
511 | ||
512 | static inline void | |
513 | rela16(unsigned char* view, | |
514 | const Sized_relobj<size, big_endian>* object, | |
515 | const Symbol_value<size>* psymval, | |
516 | elfcpp::Elf_Half addend) | |
517 | { This::template rela<16>(view, object, psymval, addend); } | |
518 | ||
d830e0e0 | 519 | // Do a simple 16-bit PC relative REL relocation with the addend in |
b8e6aad9 | 520 | // the section contents. |
92e059d8 | 521 | static inline void |
d830e0e0 | 522 | pcrel16(unsigned char* view, elfcpp::Elf_Half value, |
92e059d8 | 523 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
b8e6aad9 ILT |
524 | { This::template pcrel<16>(view, value, address); } |
525 | ||
526 | static inline void | |
527 | pcrel16(unsigned char* view, | |
528 | const Sized_relobj<size, big_endian>* object, | |
529 | const Symbol_value<size>* psymval, | |
530 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
531 | { This::template pcrel<16>(view, object, psymval, address); } | |
92e059d8 | 532 | |
d830e0e0 ILT |
533 | // Do a simple 16-bit PC relative RELA relocation with the addend in |
534 | // the reloc. | |
535 | static inline void | |
536 | pcrela16(unsigned char* view, elfcpp::Elf_Half value, | |
537 | elfcpp::Elf_Half addend, | |
538 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
539 | { This::template pcrela<16>(view, value, addend, address); } | |
540 | ||
541 | static inline void | |
542 | pcrela16(unsigned char* view, | |
543 | const Sized_relobj<size, big_endian>* object, | |
544 | const Symbol_value<size>* psymval, | |
545 | elfcpp::Elf_Half addend, | |
546 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
547 | { This::template pcrela<16>(view, object, psymval, addend, address); } | |
548 | ||
92e059d8 ILT |
549 | // Do a simple 32-bit REL relocation with the addend in the section |
550 | // contents. | |
551 | static inline void | |
552 | rel32(unsigned char* view, elfcpp::Elf_Word value) | |
b8e6aad9 ILT |
553 | { This::template rel<32>(view, value); } |
554 | ||
555 | static inline void | |
556 | rel32(unsigned char* view, | |
557 | const Sized_relobj<size, big_endian>* object, | |
558 | const Symbol_value<size>* psymval) | |
559 | { This::template rel<32>(view, object, psymval); } | |
92e059d8 | 560 | |
d830e0e0 ILT |
561 | // Do an 32-bit RELA relocation with the addend in the relocation. |
562 | static inline void | |
563 | rela32(unsigned char* view, elfcpp::Elf_Word value, elfcpp::Elf_Word addend) | |
564 | { This::template rela<32>(view, value, addend); } | |
565 | ||
566 | static inline void | |
567 | rela32(unsigned char* view, | |
568 | const Sized_relobj<size, big_endian>* object, | |
569 | const Symbol_value<size>* psymval, | |
570 | elfcpp::Elf_Word addend) | |
571 | { This::template rela<32>(view, object, psymval, addend); } | |
572 | ||
92e059d8 ILT |
573 | // Do a simple 32-bit PC relative REL relocation with the addend in |
574 | // the section contents. | |
575 | static inline void | |
576 | pcrel32(unsigned char* view, elfcpp::Elf_Word value, | |
577 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
b8e6aad9 ILT |
578 | { This::template pcrel<32>(view, value, address); } |
579 | ||
580 | static inline void | |
581 | pcrel32(unsigned char* view, | |
582 | const Sized_relobj<size, big_endian>* object, | |
583 | const Symbol_value<size>* psymval, | |
584 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
585 | { This::template pcrel<32>(view, object, psymval, address); } | |
92e059d8 | 586 | |
d830e0e0 ILT |
587 | // Do a simple 32-bit PC relative RELA relocation with the addend in |
588 | // the relocation. | |
589 | static inline void | |
590 | pcrela32(unsigned char* view, elfcpp::Elf_Word value, | |
591 | elfcpp::Elf_Word addend, | |
592 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
593 | { This::template pcrela<32>(view, value, addend, address); } | |
594 | ||
595 | static inline void | |
596 | pcrela32(unsigned char* view, | |
597 | const Sized_relobj<size, big_endian>* object, | |
598 | const Symbol_value<size>* psymval, | |
599 | elfcpp::Elf_Word addend, | |
600 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
601 | { This::template pcrela<32>(view, object, psymval, addend, address); } | |
602 | ||
92e059d8 ILT |
603 | // Do a simple 64-bit REL relocation with the addend in the section |
604 | // contents. | |
605 | static inline void | |
f6ce93d6 | 606 | rel64(unsigned char* view, elfcpp::Elf_Xword value) |
b8e6aad9 ILT |
607 | { This::template rel<64>(view, value); } |
608 | ||
609 | static inline void | |
610 | rel64(unsigned char* view, | |
611 | const Sized_relobj<size, big_endian>* object, | |
612 | const Symbol_value<size>* psymval) | |
613 | { This::template rel<64>(view, object, psymval); } | |
92e059d8 | 614 | |
d830e0e0 ILT |
615 | // Do a 64-bit RELA relocation with the addend in the relocation. |
616 | static inline void | |
617 | rela64(unsigned char* view, elfcpp::Elf_Xword value, | |
618 | elfcpp::Elf_Xword addend) | |
619 | { This::template rela<64>(view, value, addend); } | |
620 | ||
621 | static inline void | |
622 | rela64(unsigned char* view, | |
623 | const Sized_relobj<size, big_endian>* object, | |
624 | const Symbol_value<size>* psymval, | |
625 | elfcpp::Elf_Xword addend) | |
626 | { This::template rela<64>(view, object, psymval, addend); } | |
627 | ||
92e059d8 ILT |
628 | // Do a simple 64-bit PC relative REL relocation with the addend in |
629 | // the section contents. | |
630 | static inline void | |
f6ce93d6 | 631 | pcrel64(unsigned char* view, elfcpp::Elf_Xword value, |
92e059d8 | 632 | typename elfcpp::Elf_types<size>::Elf_Addr address) |
b8e6aad9 ILT |
633 | { This::template pcrel<64>(view, value, address); } |
634 | ||
635 | static inline void | |
636 | pcrel64(unsigned char* view, | |
637 | const Sized_relobj<size, big_endian>* object, | |
638 | const Symbol_value<size>* psymval, | |
639 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
640 | { This::template pcrel<64>(view, object, psymval, address); } | |
d830e0e0 ILT |
641 | |
642 | // Do a simple 64-bit PC relative RELA relocation with the addend in | |
643 | // the relocation. | |
644 | static inline void | |
645 | pcrela64(unsigned char* view, elfcpp::Elf_Xword value, | |
646 | elfcpp::Elf_Xword addend, | |
647 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
648 | { This::template pcrela<64>(view, value, addend, address); } | |
649 | ||
650 | static inline void | |
651 | pcrela64(unsigned char* view, | |
652 | const Sized_relobj<size, big_endian>* object, | |
653 | const Symbol_value<size>* psymval, | |
654 | elfcpp::Elf_Xword addend, | |
655 | typename elfcpp::Elf_types<size>::Elf_Addr address) | |
656 | { This::template pcrela<64>(view, object, psymval, addend, address); } | |
5a6f7e2d ILT |
657 | }; |
658 | ||
730cdc88 ILT |
659 | // Track relocations while reading a section. This lets you ask for |
660 | // the relocation at a certain offset, and see how relocs occur | |
661 | // between points of interest. | |
662 | ||
663 | template<int size, bool big_endian> | |
664 | class Track_relocs | |
665 | { | |
666 | public: | |
667 | Track_relocs() | |
b696e6d4 | 668 | : prelocs_(NULL), len_(0), pos_(0), reloc_size_(0) |
730cdc88 ILT |
669 | { } |
670 | ||
671 | // Initialize the Track_relocs object. OBJECT is the object holding | |
672 | // the reloc section, RELOC_SHNDX is the section index of the reloc | |
673 | // section, and RELOC_TYPE is the type of the reloc section | |
674 | // (elfcpp::SHT_REL or elfcpp::SHT_RELA). This returns false if | |
675 | // something went wrong. | |
676 | bool | |
b696e6d4 | 677 | initialize(Object* object, unsigned int reloc_shndx, |
730cdc88 ILT |
678 | unsigned int reloc_type); |
679 | ||
680 | // Return the offset in the data section to which the next reloc | |
681 | // applies. THis returns -1 if there is no next reloc. | |
682 | off_t | |
683 | next_offset() const; | |
684 | ||
685 | // Return the symbol index of the next reloc. This returns -1U if | |
686 | // there is no next reloc. | |
687 | unsigned int | |
688 | next_symndx() const; | |
689 | ||
690 | // Advance to OFFSET within the data section, and return the number | |
691 | // of relocs which would be skipped. | |
692 | int | |
693 | advance(off_t offset); | |
694 | ||
695 | private: | |
b696e6d4 | 696 | // The contents of the input object's reloc section. |
730cdc88 ILT |
697 | const unsigned char* prelocs_; |
698 | // The length of the reloc section. | |
8383303e | 699 | section_size_type len_; |
730cdc88 | 700 | // Our current position in the reloc section. |
8383303e | 701 | section_size_type pos_; |
730cdc88 ILT |
702 | // The size of the relocs in the section. |
703 | int reloc_size_; | |
704 | }; | |
705 | ||
61ba1cf9 ILT |
706 | } // End namespace gold. |
707 | ||
708 | #endif // !defined(GOLD_RELOC_H) |