2011-11-09 Doug Kwan <dougkwan@google.com>
[deliverable/binutils-gdb.git] / gold / reloc.h
1 // reloc.h -- relocate input files for gold -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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
23 #ifndef GOLD_RELOC_H
24 #define GOLD_RELOC_H
25
26 #include <vector>
27 #ifdef HAVE_BYTESWAP_H
28 #include <byteswap.h>
29 #endif
30
31 #include "elfcpp.h"
32 #include "workqueue.h"
33
34 namespace gold
35 {
36
37 class General_options;
38 class Object;
39 class Relobj;
40 class Read_relocs_data;
41 class Symbol;
42 class Layout;
43 class Output_data;
44 class Output_section;
45
46 template<int size>
47 class Sized_symbol;
48
49 template<int size, bool big_endian>
50 class Sized_relobj_file;
51
52 template<int size>
53 class Symbol_value;
54
55 template<int sh_type, bool dynamic, int size, bool big_endian>
56 class Output_data_reloc;
57
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 // 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.
68 Read_relocs(Symbol_table* symtab, Layout* layout, Relobj* object,
69 Task_token* this_blocker, Task_token* next_blocker)
70 : symtab_(symtab), layout_(layout), object_(object),
71 this_blocker_(this_blocker), next_blocker_(next_blocker)
72 { }
73
74 // The standard Task methods.
75
76 Task_token*
77 is_runnable();
78
79 void
80 locks(Task_locker*);
81
82 void
83 run(Workqueue*);
84
85 std::string
86 get_name() const;
87
88 private:
89 Symbol_table* symtab_;
90 Layout* layout_;
91 Relobj* object_;
92 Task_token* this_blocker_;
93 Task_token* next_blocker_;
94 };
95
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:
102 // THIS_BLOCKER prevents this task from running until the previous
103 // one is finished. NEXT_BLOCKER prevents the next task from
104 // running.
105 Gc_process_relocs(Symbol_table* symtab, Layout* layout, Relobj* object,
106 Read_relocs_data* rd, Task_token* this_blocker,
107 Task_token* next_blocker)
108 : symtab_(symtab), layout_(layout), object_(object), rd_(rd),
109 this_blocker_(this_blocker), next_blocker_(next_blocker)
110 { }
111
112 ~Gc_process_relocs();
113
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:
129 Symbol_table* symtab_;
130 Layout* layout_;
131 Relobj* object_;
132 Read_relocs_data* rd_;
133 Task_token* this_blocker_;
134 Task_token* next_blocker_;
135 };
136
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:
143 // THIS_BLOCKER prevents this task from running until the previous
144 // one is finished. NEXT_BLOCKER prevents the next task from
145 // running.
146 Scan_relocs(Symbol_table* symtab, Layout* layout, Relobj* object,
147 Read_relocs_data* rd, Task_token* this_blocker,
148 Task_token* next_blocker)
149 : symtab_(symtab), layout_(layout), object_(object), rd_(rd),
150 this_blocker_(this_blocker), next_blocker_(next_blocker)
151 { }
152
153 ~Scan_relocs();
154
155 // The standard Task methods.
156
157 Task_token*
158 is_runnable();
159
160 void
161 locks(Task_locker*);
162
163 void
164 run(Workqueue*);
165
166 std::string
167 get_name() const;
168
169 private:
170 Symbol_table* symtab_;
171 Layout* layout_;
172 Relobj* object_;
173 Read_relocs_data* rd_;
174 Task_token* this_blocker_;
175 Task_token* next_blocker_;
176 };
177
178 // A class to perform all the relocations for an object file.
179
180 class Relocate_task : public Task
181 {
182 public:
183 Relocate_task(const Symbol_table* symtab, const Layout* layout,
184 Relobj* object, Output_file* of,
185 Task_token* input_sections_blocker,
186 Task_token* output_sections_blocker, Task_token* final_blocker)
187 : symtab_(symtab), layout_(layout), object_(object), of_(of),
188 input_sections_blocker_(input_sections_blocker),
189 output_sections_blocker_(output_sections_blocker),
190 final_blocker_(final_blocker)
191 { }
192
193 // The standard Task methods.
194
195 Task_token*
196 is_runnable();
197
198 void
199 locks(Task_locker*);
200
201 void
202 run(Workqueue*);
203
204 std::string
205 get_name() const;
206
207 private:
208 const Symbol_table* symtab_;
209 const Layout* layout_;
210 Relobj* object_;
211 Output_file* of_;
212 Task_token* input_sections_blocker_;
213 Task_token* output_sections_blocker_;
214 Task_token* final_blocker_;
215 };
216
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,
240 // Like RELOC_ADJUST_FOR_SECTION_RELA but the addend should not be
241 // adjusted.
242 RELOC_ADJUST_FOR_SECTION_0,
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 // Like RELOC_ADJUST_FOR_SECTION_4 but for unaligned relocs.
251 RELOC_ADJUST_FOR_SECTION_4_UNALIGNED,
252 // Discard the input reloc--process it completely when relocating
253 // the data section contents.
254 RELOC_DISCARD,
255 // An input reloc which is not discarded, but which requires
256 // target specific processing in order to update it.
257 RELOC_SPECIAL
258 };
259
260 Relocatable_relocs()
261 : reloc_strategies_(), output_reloc_count_(0), posd_(NULL)
262 { }
263
264 // Record the number of relocs.
265 void
266 set_reloc_count(size_t reloc_count)
267 { this->reloc_strategies_.reserve(reloc_count); }
268
269 // Record what to do for the next reloc.
270 void
271 set_next_reloc_strategy(Reloc_strategy strategy)
272 {
273 this->reloc_strategies_.push_back(static_cast<unsigned char>(strategy));
274 if (strategy != RELOC_DISCARD)
275 ++this->output_reloc_count_;
276 }
277
278 // Record the Output_data associated with this reloc section.
279 void
280 set_output_data(Output_data* posd)
281 {
282 gold_assert(this->posd_ == NULL);
283 this->posd_ = posd;
284 }
285
286 // Return the Output_data associated with this reloc section.
287 Output_data*
288 output_data() const
289 { return this->posd_; }
290
291 // Return what to do for reloc I.
292 Reloc_strategy
293 strategy(unsigned int i) const
294 {
295 gold_assert(i < this->reloc_strategies_.size());
296 return static_cast<Reloc_strategy>(this->reloc_strategies_[i]);
297 }
298
299 // Return the number of relocations to create in the output file.
300 size_t
301 output_reloc_count() const
302 { return this->output_reloc_count_; }
303
304 private:
305 typedef std::vector<unsigned char> Reloc_strategies;
306
307 // The strategies for the input reloc. There is one entry in this
308 // vector for each relocation in the input section.
309 Reloc_strategies reloc_strategies_;
310 // The number of relocations to be created in the output file.
311 size_t output_reloc_count_;
312 // The output data structure associated with this relocation.
313 Output_data* posd_;
314 };
315
316 // Standard relocation routines which are used on many targets. Here
317 // SIZE and BIG_ENDIAN refer to the target, not the relocation type.
318
319 template<int size, bool big_endian>
320 class Relocate_functions
321 {
322 private:
323 // Do a simple relocation with the addend in the section contents.
324 // VALSIZE is the size of the value.
325 template<int valsize>
326 static inline void
327 rel(unsigned char* view,
328 typename elfcpp::Swap<valsize, big_endian>::Valtype value)
329 {
330 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
331 Valtype* wv = reinterpret_cast<Valtype*>(view);
332 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
333 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value);
334 }
335
336 // Do a simple relocation using a Symbol_value with the addend in
337 // the section contents. VALSIZE is the size of the value to
338 // relocate.
339 template<int valsize>
340 static inline void
341 rel(unsigned char* view,
342 const Sized_relobj_file<size, big_endian>* object,
343 const Symbol_value<size>* psymval)
344 {
345 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
346 Valtype* wv = reinterpret_cast<Valtype*>(view);
347 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
348 x = psymval->value(object, x);
349 elfcpp::Swap<valsize, big_endian>::writeval(wv, x);
350 }
351
352 // Like the above but for relocs at unaligned addresses.
353 template<int valsize>
354 static inline void
355 rel_unaligned(unsigned char* view,
356 const Sized_relobj_file<size, big_endian>* object,
357 const Symbol_value<size>* psymval)
358 {
359 typedef typename elfcpp::Swap_unaligned<valsize, big_endian>::Valtype
360 Valtype;
361 Valtype x = elfcpp::Swap_unaligned<valsize, big_endian>::readval(view);
362 x = psymval->value(object, x);
363 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(view, x);
364 }
365
366 // Do a simple relocation with the addend in the relocation.
367 // VALSIZE is the size of the value.
368 template<int valsize>
369 static inline void
370 rela(unsigned char* view,
371 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
372 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
373 {
374 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
375 Valtype* wv = reinterpret_cast<Valtype*>(view);
376 elfcpp::Swap<valsize, big_endian>::writeval(wv, value + addend);
377 }
378
379 // Do a simple relocation using a symbol value with the addend in
380 // the relocation. VALSIZE is the size of the value.
381 template<int valsize>
382 static inline void
383 rela(unsigned char* view,
384 const Sized_relobj_file<size, big_endian>* object,
385 const Symbol_value<size>* psymval,
386 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
387 {
388 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
389 Valtype* wv = reinterpret_cast<Valtype*>(view);
390 Valtype x = psymval->value(object, addend);
391 elfcpp::Swap<valsize, big_endian>::writeval(wv, x);
392 }
393
394 // Do a simple PC relative relocation with the addend in the section
395 // contents. VALSIZE is the size of the value.
396 template<int valsize>
397 static inline void
398 pcrel(unsigned char* view,
399 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
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 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value - address);
406 }
407
408 // Do a simple PC relative relocation with a Symbol_value with the
409 // addend in the section contents. VALSIZE is the size of the
410 // value.
411 template<int valsize>
412 static inline void
413 pcrel(unsigned char* view,
414 const Sized_relobj_file<size, big_endian>* object,
415 const Symbol_value<size>* psymval,
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 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
421 x = psymval->value(object, x);
422 elfcpp::Swap<valsize, big_endian>::writeval(wv, x - address);
423 }
424
425 // Do a simple PC relative relocation with the addend in the
426 // relocation. VALSIZE is the size of the value.
427 template<int valsize>
428 static inline void
429 pcrela(unsigned char* view,
430 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
431 typename elfcpp::Swap<valsize, big_endian>::Valtype addend,
432 typename elfcpp::Elf_types<size>::Elf_Addr address)
433 {
434 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
435 Valtype* wv = reinterpret_cast<Valtype*>(view);
436 elfcpp::Swap<valsize, big_endian>::writeval(wv, value + addend - address);
437 }
438
439 // Do a simple PC relative relocation with a Symbol_value with the
440 // addend in the relocation. VALSIZE is the size of the value.
441 template<int valsize>
442 static inline void
443 pcrela(unsigned char* view,
444 const Sized_relobj_file<size, big_endian>* object,
445 const Symbol_value<size>* psymval,
446 typename elfcpp::Swap<valsize, big_endian>::Valtype addend,
447 typename elfcpp::Elf_types<size>::Elf_Addr address)
448 {
449 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
450 Valtype* wv = reinterpret_cast<Valtype*>(view);
451 Valtype x = psymval->value(object, addend);
452 elfcpp::Swap<valsize, big_endian>::writeval(wv, x - address);
453 }
454
455 typedef Relocate_functions<size, big_endian> This;
456
457 public:
458 // Do a simple 8-bit REL relocation with the addend in the section
459 // contents.
460 static inline void
461 rel8(unsigned char* view, unsigned char value)
462 { This::template rel<8>(view, value); }
463
464 static inline void
465 rel8(unsigned char* view,
466 const Sized_relobj_file<size, big_endian>* object,
467 const Symbol_value<size>* psymval)
468 { This::template rel<8>(view, object, psymval); }
469
470 // Do an 8-bit RELA relocation with the addend in the relocation.
471 static inline void
472 rela8(unsigned char* view, unsigned char value, unsigned char addend)
473 { This::template rela<8>(view, value, addend); }
474
475 static inline void
476 rela8(unsigned char* view,
477 const Sized_relobj_file<size, big_endian>* object,
478 const Symbol_value<size>* psymval,
479 unsigned char addend)
480 { This::template rela<8>(view, object, psymval, addend); }
481
482 // Do a simple 8-bit PC relative relocation with the addend in the
483 // section contents.
484 static inline void
485 pcrel8(unsigned char* view, unsigned char value,
486 typename elfcpp::Elf_types<size>::Elf_Addr address)
487 { This::template pcrel<8>(view, value, address); }
488
489 static inline void
490 pcrel8(unsigned char* view,
491 const Sized_relobj_file<size, big_endian>* object,
492 const Symbol_value<size>* psymval,
493 typename elfcpp::Elf_types<size>::Elf_Addr address)
494 { This::template pcrel<8>(view, object, psymval, address); }
495
496 // Do a simple 8-bit PC relative RELA relocation with the addend in
497 // the reloc.
498 static inline void
499 pcrela8(unsigned char* view, unsigned char value, unsigned char addend,
500 typename elfcpp::Elf_types<size>::Elf_Addr address)
501 { This::template pcrela<8>(view, value, addend, address); }
502
503 static inline void
504 pcrela8(unsigned char* view,
505 const Sized_relobj_file<size, big_endian>* object,
506 const Symbol_value<size>* psymval,
507 unsigned char addend,
508 typename elfcpp::Elf_types<size>::Elf_Addr address)
509 { This::template pcrela<8>(view, object, psymval, addend, address); }
510
511 // Do a simple 16-bit REL relocation with the addend in the section
512 // contents.
513 static inline void
514 rel16(unsigned char* view, elfcpp::Elf_Half value)
515 { This::template rel<16>(view, value); }
516
517 static inline void
518 rel16(unsigned char* view,
519 const Sized_relobj_file<size, big_endian>* object,
520 const Symbol_value<size>* psymval)
521 { This::template rel<16>(view, object, psymval); }
522
523 // Do an 16-bit RELA relocation with the addend in the relocation.
524 static inline void
525 rela16(unsigned char* view, elfcpp::Elf_Half value, elfcpp::Elf_Half addend)
526 { This::template rela<16>(view, value, addend); }
527
528 static inline void
529 rela16(unsigned char* view,
530 const Sized_relobj_file<size, big_endian>* object,
531 const Symbol_value<size>* psymval,
532 elfcpp::Elf_Half addend)
533 { This::template rela<16>(view, object, psymval, addend); }
534
535 // Do a simple 16-bit PC relative REL relocation with the addend in
536 // the section contents.
537 static inline void
538 pcrel16(unsigned char* view, elfcpp::Elf_Half value,
539 typename elfcpp::Elf_types<size>::Elf_Addr address)
540 { This::template pcrel<16>(view, value, address); }
541
542 static inline void
543 pcrel16(unsigned char* view,
544 const Sized_relobj_file<size, big_endian>* object,
545 const Symbol_value<size>* psymval,
546 typename elfcpp::Elf_types<size>::Elf_Addr address)
547 { This::template pcrel<16>(view, object, psymval, address); }
548
549 // Do a simple 16-bit PC relative RELA relocation with the addend in
550 // the reloc.
551 static inline void
552 pcrela16(unsigned char* view, elfcpp::Elf_Half value,
553 elfcpp::Elf_Half addend,
554 typename elfcpp::Elf_types<size>::Elf_Addr address)
555 { This::template pcrela<16>(view, value, addend, address); }
556
557 static inline void
558 pcrela16(unsigned char* view,
559 const Sized_relobj_file<size, big_endian>* object,
560 const Symbol_value<size>* psymval,
561 elfcpp::Elf_Half addend,
562 typename elfcpp::Elf_types<size>::Elf_Addr address)
563 { This::template pcrela<16>(view, object, psymval, addend, address); }
564
565 // Do a simple 32-bit REL relocation with the addend in the section
566 // contents.
567 static inline void
568 rel32(unsigned char* view, elfcpp::Elf_Word value)
569 { This::template rel<32>(view, value); }
570
571 static inline void
572 rel32(unsigned char* view,
573 const Sized_relobj_file<size, big_endian>* object,
574 const Symbol_value<size>* psymval)
575 { This::template rel<32>(view, object, psymval); }
576
577 // Like above but for relocs at unaligned addresses.
578 static inline void
579 rel32_unaligned(unsigned char* view,
580 const Sized_relobj_file<size, big_endian>* object,
581 const Symbol_value<size>* psymval)
582 { This::template rel_unaligned<32>(view, object, psymval); }
583
584 // Do an 32-bit RELA relocation with the addend in the relocation.
585 static inline void
586 rela32(unsigned char* view, elfcpp::Elf_Word value, elfcpp::Elf_Word addend)
587 { This::template rela<32>(view, value, addend); }
588
589 static inline void
590 rela32(unsigned char* view,
591 const Sized_relobj_file<size, big_endian>* object,
592 const Symbol_value<size>* psymval,
593 elfcpp::Elf_Word addend)
594 { This::template rela<32>(view, object, psymval, addend); }
595
596 // Do a simple 32-bit PC relative REL relocation with the addend in
597 // the section contents.
598 static inline void
599 pcrel32(unsigned char* view, elfcpp::Elf_Word value,
600 typename elfcpp::Elf_types<size>::Elf_Addr address)
601 { This::template pcrel<32>(view, value, address); }
602
603 static inline void
604 pcrel32(unsigned char* view,
605 const Sized_relobj_file<size, big_endian>* object,
606 const Symbol_value<size>* psymval,
607 typename elfcpp::Elf_types<size>::Elf_Addr address)
608 { This::template pcrel<32>(view, object, psymval, address); }
609
610 // Do a simple 32-bit PC relative RELA relocation with the addend in
611 // the relocation.
612 static inline void
613 pcrela32(unsigned char* view, elfcpp::Elf_Word value,
614 elfcpp::Elf_Word addend,
615 typename elfcpp::Elf_types<size>::Elf_Addr address)
616 { This::template pcrela<32>(view, value, addend, address); }
617
618 static inline void
619 pcrela32(unsigned char* view,
620 const Sized_relobj_file<size, big_endian>* object,
621 const Symbol_value<size>* psymval,
622 elfcpp::Elf_Word addend,
623 typename elfcpp::Elf_types<size>::Elf_Addr address)
624 { This::template pcrela<32>(view, object, psymval, addend, address); }
625
626 // Do a simple 64-bit REL relocation with the addend in the section
627 // contents.
628 static inline void
629 rel64(unsigned char* view, elfcpp::Elf_Xword value)
630 { This::template rel<64>(view, value); }
631
632 static inline void
633 rel64(unsigned char* view,
634 const Sized_relobj_file<size, big_endian>* object,
635 const Symbol_value<size>* psymval)
636 { This::template rel<64>(view, object, psymval); }
637
638 // Do a 64-bit RELA relocation with the addend in the relocation.
639 static inline void
640 rela64(unsigned char* view, elfcpp::Elf_Xword value,
641 elfcpp::Elf_Xword addend)
642 { This::template rela<64>(view, value, addend); }
643
644 static inline void
645 rela64(unsigned char* view,
646 const Sized_relobj_file<size, big_endian>* object,
647 const Symbol_value<size>* psymval,
648 elfcpp::Elf_Xword addend)
649 { This::template rela<64>(view, object, psymval, addend); }
650
651 // Do a simple 64-bit PC relative REL relocation with the addend in
652 // the section contents.
653 static inline void
654 pcrel64(unsigned char* view, elfcpp::Elf_Xword value,
655 typename elfcpp::Elf_types<size>::Elf_Addr address)
656 { This::template pcrel<64>(view, value, address); }
657
658 static inline void
659 pcrel64(unsigned char* view,
660 const Sized_relobj_file<size, big_endian>* object,
661 const Symbol_value<size>* psymval,
662 typename elfcpp::Elf_types<size>::Elf_Addr address)
663 { This::template pcrel<64>(view, object, psymval, address); }
664
665 // Do a simple 64-bit PC relative RELA relocation with the addend in
666 // the relocation.
667 static inline void
668 pcrela64(unsigned char* view, elfcpp::Elf_Xword value,
669 elfcpp::Elf_Xword addend,
670 typename elfcpp::Elf_types<size>::Elf_Addr address)
671 { This::template pcrela<64>(view, value, addend, address); }
672
673 static inline void
674 pcrela64(unsigned char* view,
675 const Sized_relobj_file<size, big_endian>* object,
676 const Symbol_value<size>* psymval,
677 elfcpp::Elf_Xword addend,
678 typename elfcpp::Elf_types<size>::Elf_Addr address)
679 { This::template pcrela<64>(view, object, psymval, addend, address); }
680 };
681
682 // Track relocations while reading a section. This lets you ask for
683 // the relocation at a certain offset, and see how relocs occur
684 // between points of interest.
685
686 template<int size, bool big_endian>
687 class Track_relocs
688 {
689 public:
690 Track_relocs()
691 : prelocs_(NULL), len_(0), pos_(0), reloc_size_(0)
692 { }
693
694 // Initialize the Track_relocs object. OBJECT is the object holding
695 // the reloc section, RELOC_SHNDX is the section index of the reloc
696 // section, and RELOC_TYPE is the type of the reloc section
697 // (elfcpp::SHT_REL or elfcpp::SHT_RELA). This returns false if
698 // something went wrong.
699 bool
700 initialize(Object* object, unsigned int reloc_shndx,
701 unsigned int reloc_type);
702
703 // Return the offset in the data section to which the next reloc
704 // applies. This returns -1 if there is no next reloc.
705 off_t
706 next_offset() const;
707
708 // Return the symbol index of the next reloc. This returns -1U if
709 // there is no next reloc.
710 unsigned int
711 next_symndx() const;
712
713 // Return the addend of the next reloc. This returns 0 if there is
714 // no next reloc.
715 uint64_t
716 next_addend() const;
717
718 // Advance to OFFSET within the data section, and return the number
719 // of relocs which would be skipped.
720 int
721 advance(off_t offset);
722
723 private:
724 // The contents of the input object's reloc section.
725 const unsigned char* prelocs_;
726 // The length of the reloc section.
727 section_size_type len_;
728 // Our current position in the reloc section.
729 section_size_type pos_;
730 // The size of the relocs in the section.
731 int reloc_size_;
732 };
733
734 } // End namespace gold.
735
736 #endif // !defined(GOLD_RELOC_H)
This page took 0.063692 seconds and 5 git commands to generate.