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