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