OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [binutils-2.20.1/] [gold/] [reloc.h] - Blame information for rev 476

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 205 julius
// reloc.h -- relocate input files for gold   -*- C++ -*-
2
 
3
// Copyright 2006, 2007, 2008, 2009 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;
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
  // 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,
68
              Layout* layout, Relobj* object, Task_token* symtab_lock,
69
              Task_token* blocker)
70
    : options_(options), symtab_(symtab), layout_(layout), object_(object),
71
      symtab_lock_(symtab_lock), blocker_(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
  const General_options& options_;
90
  Symbol_table* symtab_;
91
  Layout* layout_;
92
  Relobj* object_;
93
  Task_token* symtab_lock_;
94
  Task_token* blocker_;
95
};
96
 
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
 
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,
145
              Layout* layout, Relobj* object, Read_relocs_data* rd,
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)
149
  { }
150
 
151
  // The standard Task methods.
152
 
153
  Task_token*
154
  is_runnable();
155
 
156
  void
157
  locks(Task_locker*);
158
 
159
  void
160
  run(Workqueue*);
161
 
162
  std::string
163
  get_name() const;
164
 
165
 private:
166
  const General_options& options_;
167
  Symbol_table* symtab_;
168
  Layout* layout_;
169
  Relobj* object_;
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
 
177
class Relocate_task : public Task
178
{
179
 public:
180
  Relocate_task(const General_options& options, const Symbol_table* symtab,
181
                const Layout* layout, Relobj* object, Output_file* of,
182
                Task_token* input_sections_blocker,
183
                Task_token* output_sections_blocker, Task_token* final_blocker)
184
    : options_(options), symtab_(symtab), layout_(layout), object_(object),
185
      of_(of), input_sections_blocker_(input_sections_blocker),
186
      output_sections_blocker_(output_sections_blocker),
187
      final_blocker_(final_blocker)
188
  { }
189
 
190
  // The standard Task methods.
191
 
192
  Task_token*
193
  is_runnable();
194
 
195
  void
196
  locks(Task_locker*);
197
 
198
  void
199
  run(Workqueue*);
200
 
201
  std::string
202
  get_name() const;
203
 
204
 private:
205
  const General_options& options_;
206
  const Symbol_table* symtab_;
207
  const Layout* layout_;
208
  Relobj* object_;
209
  Output_file* of_;
210
  Task_token* input_sections_blocker_;
211
  Task_token* output_sections_blocker_;
212
  Task_token* final_blocker_;
213
};
214
 
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,
238
    // Like RELOC_ADJUST_FOR_SECTION_RELA but the addend should not be
239
    // adjusted.
240
    RELOC_ADJUST_FOR_SECTION_0,
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
 
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
323
  rel(unsigned char* view,
324
      typename elfcpp::Swap<valsize, big_endian>::Valtype value)
325
  {
326
    typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
327
    Valtype* wv = reinterpret_cast<Valtype*>(view);
328
    Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
329
    elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value);
330
  }
331
 
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
 
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
 
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
380
  pcrel(unsigned char* view,
381
        typename elfcpp::Swap<valsize, big_endian>::Valtype value,
382
        typename elfcpp::Elf_types<size>::Elf_Addr address)
383
  {
384
    typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
385
    Valtype* wv = reinterpret_cast<Valtype*>(view);
386
    Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
387
    elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value - address);
388
  }
389
 
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
 
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
 
437
  typedef Relocate_functions<size, big_endian> This;
438
 
439
public:
440
  // Do a simple 8-bit REL relocation with the addend in the section
441
  // contents.
442
  static inline void
443
  rel8(unsigned char* view, unsigned char value)
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); }
451
 
452
  // Do an 8-bit RELA relocation with the addend in the relocation.
453
  static inline void
454
  rela8(unsigned char* view, unsigned char value, unsigned char addend)
455
  { This::template rela<8>(view, value, addend); }
456
 
457
  static inline void
458
  rela8(unsigned char* view,
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
 
464
  // Do a simple 8-bit PC relative relocation with the addend in the
465
  // section contents.
466
  static inline void
467
  pcrel8(unsigned char* view, unsigned char value,
468
         typename elfcpp::Elf_types<size>::Elf_Addr address)
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); }
477
 
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
 
493
  // Do a simple 16-bit REL relocation with the addend in the section
494
  // contents.
495
  static inline void
496
  rel16(unsigned char* view, elfcpp::Elf_Half value)
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); }
504
 
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
 
517
  // Do a simple 16-bit PC relative REL relocation with the addend in
518
  // the section contents.
519
  static inline void
520
  pcrel16(unsigned char* view, elfcpp::Elf_Half value,
521
          typename elfcpp::Elf_types<size>::Elf_Addr address)
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); }
530
 
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
 
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)
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); }
558
 
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
 
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)
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); }
584
 
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
 
601
  // Do a simple 64-bit REL relocation with the addend in the section
602
  // contents.
603
  static inline void
604
  rel64(unsigned char* view, elfcpp::Elf_Xword value)
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); }
612
 
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
 
626
  // Do a simple 64-bit PC relative REL relocation with the addend in
627
  // the section contents.
628
  static inline void
629
  pcrel64(unsigned char* view, elfcpp::Elf_Xword value,
630
          typename elfcpp::Elf_types<size>::Elf_Addr address)
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); }
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); }
655
};
656
 
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()
666
    : prelocs_(NULL), len_(0), pos_(0), reloc_size_(0)
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
675
  initialize(Object* object, unsigned int reloc_shndx,
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:
694
  // The contents of the input object's reloc section.
695
  const unsigned char* prelocs_;
696
  // The length of the reloc section.
697
  section_size_type len_;
698
  // Our current position in the reloc section.
699
  section_size_type pos_;
700
  // The size of the relocs in the section.
701
  int reloc_size_;
702
};
703
 
704
} // End namespace gold.
705
 
706
#endif // !defined(GOLD_RELOC_H)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.