* gas/ppc/altivec_xcoff.s: Do not use .machine pseudo-ops as it overrides gas options.
[deliverable/binutils-gdb.git] / gold / reloc.h
CommitLineData
61ba1cf9
ILT
1// reloc.h -- relocate input files for gold -*- C++ -*-
2
6cb15b7f
ILT
3// Copyright 2006, 2007 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
61ba1cf9
ILT
23#ifndef GOLD_RELOC_H
24#define GOLD_RELOC_H
25
92e059d8
ILT
26#include <byteswap.h>
27
61ba1cf9
ILT
28#include "workqueue.h"
29
30namespace gold
31{
32
a3ad94ed 33class General_options;
f6ce93d6 34class Relobj;
92e059d8 35class Read_relocs_data;
a3ad94ed 36class Symbol;
ead1e424 37class Layout;
92e059d8 38
5a6f7e2d
ILT
39template<int size>
40class Sized_symbol;
41
b8e6aad9
ILT
42template<int size, bool big_endian>
43class Sized_relobj;
44
45template<int size>
46class Symbol_value;
47
5a6f7e2d
ILT
48template<int sh_type, bool dynamic, int size, bool big_endian>
49class Output_data_reloc;
50
92e059d8
ILT
51// A class to read the relocations for an object file, and then queue
52// up a task to see if they require any GOT/PLT/COPY relocations in
53// the symbol table.
54
55class Read_relocs : public Task
56{
57 public:
58 // SYMTAB_LOCK is used to lock the symbol table. BLOCKER should be
59 // unblocked when the Scan_relocs task completes.
60 Read_relocs(const General_options& options, Symbol_table* symtab,
f6ce93d6 61 Layout* layout, Relobj* object, Task_token* symtab_lock,
92e059d8 62 Task_token* blocker)
ead1e424 63 : options_(options), symtab_(symtab), layout_(layout), object_(object),
92e059d8
ILT
64 symtab_lock_(symtab_lock), blocker_(blocker)
65 { }
66
67 // The standard Task methods.
68
69 Is_runnable_type
70 is_runnable(Workqueue*);
71
72 Task_locker*
73 locks(Workqueue*);
74
75 void
76 run(Workqueue*);
77
78 private:
79 const General_options& options_;
80 Symbol_table* symtab_;
ead1e424 81 Layout* layout_;
f6ce93d6 82 Relobj* object_;
92e059d8
ILT
83 Task_token* symtab_lock_;
84 Task_token* blocker_;
85};
86
87// Scan the relocations for an object to see if they require any
88// GOT/PLT/COPY relocations.
89
90class Scan_relocs : public Task
91{
92 public:
93 // SYMTAB_LOCK is used to lock the symbol table. BLOCKER should be
94 // unblocked when the task completes.
95 Scan_relocs(const General_options& options, Symbol_table* symtab,
f6ce93d6 96 Layout* layout, Relobj* object, Read_relocs_data* rd,
ead1e424
ILT
97 Task_token* symtab_lock, Task_token* blocker)
98 : options_(options), symtab_(symtab), layout_(layout), object_(object),
99 rd_(rd), symtab_lock_(symtab_lock), blocker_(blocker)
92e059d8
ILT
100 { }
101
102 // The standard Task methods.
103
104 Is_runnable_type
105 is_runnable(Workqueue*);
106
107 Task_locker*
108 locks(Workqueue*);
109
110 void
111 run(Workqueue*);
112
113 private:
114 class Scan_relocs_locker;
115
116 const General_options& options_;
117 Symbol_table* symtab_;
ead1e424 118 Layout* layout_;
f6ce93d6 119 Relobj* object_;
92e059d8
ILT
120 Read_relocs_data* rd_;
121 Task_token* symtab_lock_;
122 Task_token* blocker_;
123};
124
125// A class to perform all the relocations for an object file.
126
61ba1cf9
ILT
127class Relocate_task : public Task
128{
129 public:
130 Relocate_task(const General_options& options, const Symbol_table* symtab,
f6ce93d6 131 const Layout* layout, Relobj* object, Output_file* of,
61ba1cf9 132 Task_token* final_blocker)
92e059d8 133 : options_(options), symtab_(symtab), layout_(layout), object_(object),
61ba1cf9
ILT
134 of_(of), final_blocker_(final_blocker)
135 { }
136
137 // The standard Task methods.
138
139 Is_runnable_type
140 is_runnable(Workqueue*);
141
142 Task_locker*
143 locks(Workqueue*);
144
145 void
146 run(Workqueue*);
147
148 private:
149 class Relocate_locker;
150
151 const General_options& options_;
152 const Symbol_table* symtab_;
92e059d8 153 const Layout* layout_;
f6ce93d6 154 Relobj* object_;
61ba1cf9
ILT
155 Output_file* of_;
156 Task_token* final_blocker_;
157};
158
92e059d8
ILT
159// Standard relocation routines which are used on many targets. Here
160// SIZE and BIG_ENDIAN refer to the target, not the relocation type.
161
162template<int size, bool big_endian>
163class Relocate_functions
164{
165private:
166 // Do a simple relocation with the addend in the section contents.
167 // VALSIZE is the size of the value.
168 template<int valsize>
169 static inline void
f6ce93d6
ILT
170 rel(unsigned char* view,
171 typename elfcpp::Swap<valsize, big_endian>::Valtype value)
92e059d8 172 {
f6ce93d6 173 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
92e059d8 174 Valtype* wv = reinterpret_cast<Valtype*>(view);
f6ce93d6
ILT
175 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
176 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value);
92e059d8
ILT
177 }
178
b8e6aad9
ILT
179 // Do a simple relocation using a Symbol_value with the addend in
180 // the section contents. VALSIZE is the size of the value to
181 // relocate.
182 template<int valsize>
183 static inline void
184 rel(unsigned char* view,
185 const Sized_relobj<size, big_endian>* object,
186 const Symbol_value<size>* psymval)
187 {
188 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
189 Valtype* wv = reinterpret_cast<Valtype*>(view);
190 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
191 x = psymval->value(object, x);
192 elfcpp::Swap<valsize, big_endian>::writeval(wv, x);
193 }
194
d830e0e0
ILT
195 // Do a simple relocation with the addend in the relocation.
196 // VALSIZE is the size of the value.
197 template<int valsize>
198 static inline void
199 rela(unsigned char* view,
200 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
201 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
202 {
203 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
204 Valtype* wv = reinterpret_cast<Valtype*>(view);
205 elfcpp::Swap<valsize, big_endian>::writeval(wv, value + addend);
206 }
207
208 // Do a simple relocation using a symbol value with the addend in
209 // the relocation. VALSIZE is the size of the value.
210 template<int valsize>
211 static inline void
212 rela(unsigned char* view,
213 const Sized_relobj<size, big_endian>* object,
214 const Symbol_value<size>* psymval,
215 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
216 {
217 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
218 Valtype* wv = reinterpret_cast<Valtype*>(view);
219 Valtype x = psymval->value(object, addend);
220 elfcpp::Swap<valsize, big_endian>::writeval(wv, x);
221 }
222
dfbba8f4
ILT
223 // Like rel(), but sign-extends the value to SIZE.
224 template<int valsize>
225 static inline void
226 signedrel(unsigned char* view,
227 const Sized_relobj<size, big_endian>* object,
228 const Symbol_value<size>* psymval)
229 {
230 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
231 typedef typename elfcpp::Swap<size, big_endian>::Valtype Sizetype;
232 Valtype* wv = reinterpret_cast<Valtype*>(view);
233 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
234 // Fancy formula to sign-extend x to size.
235 const Sizetype mask = 1U << (sizeof(valsize) * 8 - 1);
236 Sizetype sign_extended_x = x;
237 sign_extended_x = (sign_extended_x ^ mask) - mask;
238 x = psymval->value(object, sign_extended_x);
239 elfcpp::Swap<valsize, big_endian>::writeval(wv, x);
240 }
241
92e059d8
ILT
242 // Do a simple PC relative relocation with the addend in the section
243 // contents. VALSIZE is the size of the value.
244 template<int valsize>
245 static inline void
f6ce93d6
ILT
246 pcrel(unsigned char* view,
247 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
92e059d8
ILT
248 typename elfcpp::Elf_types<size>::Elf_Addr address)
249 {
f6ce93d6 250 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
92e059d8 251 Valtype* wv = reinterpret_cast<Valtype*>(view);
f6ce93d6
ILT
252 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
253 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value - address);
92e059d8
ILT
254 }
255
b8e6aad9
ILT
256 // Do a simple PC relative relocation with a Symbol_value with the
257 // addend in the section contents. VALSIZE is the size of the
258 // value.
259 template<int valsize>
260 static inline void
261 pcrel(unsigned char* view,
262 const Sized_relobj<size, big_endian>* object,
263 const Symbol_value<size>* psymval,
264 typename elfcpp::Elf_types<size>::Elf_Addr address)
265 {
266 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
267 Valtype* wv = reinterpret_cast<Valtype*>(view);
268 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
269 x = psymval->value(object, x);
270 elfcpp::Swap<valsize, big_endian>::writeval(wv, x - address);
271 }
272
d830e0e0
ILT
273 // Do a simple PC relative relocation with the addend in the
274 // relocation. VALSIZE is the size of the value.
275 template<int valsize>
276 static inline void
277 pcrela(unsigned char* view,
278 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
279 typename elfcpp::Swap<valsize, big_endian>::Valtype addend,
280 typename elfcpp::Elf_types<size>::Elf_Addr address)
281 {
282 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
283 Valtype* wv = reinterpret_cast<Valtype*>(view);
284 elfcpp::Swap<valsize, big_endian>::writeval(wv, value + addend - address);
285 }
286
287 // Do a simple PC relative relocation with a Symbol_value with the
288 // addend in the relocation. VALSIZE is the size of the value.
289 template<int valsize>
290 static inline void
291 pcrela(unsigned char* view,
292 const Sized_relobj<size, big_endian>* object,
293 const Symbol_value<size>* psymval,
294 typename elfcpp::Swap<valsize, big_endian>::Valtype addend,
295 typename elfcpp::Elf_types<size>::Elf_Addr address)
296 {
297 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
298 Valtype* wv = reinterpret_cast<Valtype*>(view);
299 Valtype x = psymval->value(object, addend);
300 elfcpp::Swap<valsize, big_endian>::writeval(wv, x - address);
301 }
302
92e059d8
ILT
303 typedef Relocate_functions<size, big_endian> This;
304
305public:
b8e6aad9
ILT
306 // Do a simple 8-bit REL relocation with the addend in the section
307 // contents.
92e059d8
ILT
308 static inline void
309 rel8(unsigned char* view, unsigned char value)
b8e6aad9
ILT
310 { This::template rel<8>(view, value); }
311
312 static inline void
313 rel8(unsigned char* view,
314 const Sized_relobj<size, big_endian>* object,
315 const Symbol_value<size>* psymval)
316 { This::template rel<8>(view, object, psymval); }
92e059d8 317
d830e0e0
ILT
318 // Do an 8-bit RELA relocation with the addend in the relocation.
319 static inline void
320 rel8a(unsigned char* view, unsigned char value, unsigned char addend)
321 { This::template rela<8>(view, value, addend); }
322
323 static inline void
324 rel8a(unsigned char* view,
325 const Sized_relobj<size, big_endian>* object,
326 const Symbol_value<size>* psymval,
327 unsigned char addend)
328 { This::template rela<8>(view, object, psymval, addend); }
329
dfbba8f4
ILT
330 // Do an 8-bit REL relocation, sign extending the addend to SIZE.
331 static inline void
332 rel8s(unsigned char* view,
333 const Sized_relobj<size, big_endian>* object,
334 const Symbol_value<size>* psymval)
335 { This::template signedrel<8>(view, object, psymval); }
336
92e059d8 337 // Do a simple 8-bit PC relative relocation with the addend in the
b8e6aad9 338 // section contents.
92e059d8
ILT
339 static inline void
340 pcrel8(unsigned char* view, unsigned char value,
341 typename elfcpp::Elf_types<size>::Elf_Addr address)
b8e6aad9
ILT
342 { This::template pcrel<8>(view, value, address); }
343
344 static inline void
345 pcrel8(unsigned char* view,
346 const Sized_relobj<size, big_endian>* object,
347 const Symbol_value<size>* psymval,
348 typename elfcpp::Elf_types<size>::Elf_Addr address)
349 { This::template pcrel<8>(view, object, psymval, address); }
92e059d8 350
d830e0e0
ILT
351 // Do a simple 8-bit PC relative RELA relocation with the addend in
352 // the reloc.
353 static inline void
354 pcrela8(unsigned char* view, unsigned char value, unsigned char addend,
355 typename elfcpp::Elf_types<size>::Elf_Addr address)
356 { This::template pcrela<8>(view, value, addend, address); }
357
358 static inline void
359 pcrela8(unsigned char* view,
360 const Sized_relobj<size, big_endian>* object,
361 const Symbol_value<size>* psymval,
362 unsigned char addend,
363 typename elfcpp::Elf_types<size>::Elf_Addr address)
364 { This::template pcrela<8>(view, object, psymval, addend, address); }
365
b8e6aad9
ILT
366 // Do a simple 16-bit REL relocation with the addend in the section
367 // contents.
92e059d8
ILT
368 static inline void
369 rel16(unsigned char* view, elfcpp::Elf_Half value)
b8e6aad9
ILT
370 { This::template rel<16>(view, value); }
371
372 static inline void
373 rel16(unsigned char* view,
374 const Sized_relobj<size, big_endian>* object,
375 const Symbol_value<size>* psymval)
376 { This::template rel<16>(view, object, psymval); }
92e059d8 377
d830e0e0
ILT
378 // Do an 16-bit RELA relocation with the addend in the relocation.
379 static inline void
380 rela16(unsigned char* view, elfcpp::Elf_Half value, elfcpp::Elf_Half addend)
381 { This::template rela<16>(view, value, addend); }
382
383 static inline void
384 rela16(unsigned char* view,
385 const Sized_relobj<size, big_endian>* object,
386 const Symbol_value<size>* psymval,
387 elfcpp::Elf_Half addend)
388 { This::template rela<16>(view, object, psymval, addend); }
389
dfbba8f4
ILT
390 // Do a 16-bit REL relocation, sign extending the addend to SIZE.
391 static inline void
392 rel16s(unsigned char* view,
393 const Sized_relobj<size, big_endian>* object,
394 const Symbol_value<size>* psymval)
395 { This::template signedrel<16>(view, object, psymval); }
396
d830e0e0 397 // Do a simple 16-bit PC relative REL relocation with the addend in
b8e6aad9 398 // the section contents.
92e059d8 399 static inline void
d830e0e0 400 pcrel16(unsigned char* view, elfcpp::Elf_Half value,
92e059d8 401 typename elfcpp::Elf_types<size>::Elf_Addr address)
b8e6aad9
ILT
402 { This::template pcrel<16>(view, value, address); }
403
404 static inline void
405 pcrel16(unsigned char* view,
406 const Sized_relobj<size, big_endian>* object,
407 const Symbol_value<size>* psymval,
408 typename elfcpp::Elf_types<size>::Elf_Addr address)
409 { This::template pcrel<16>(view, object, psymval, address); }
92e059d8 410
d830e0e0
ILT
411 // Do a simple 16-bit PC relative RELA relocation with the addend in
412 // the reloc.
413 static inline void
414 pcrela16(unsigned char* view, elfcpp::Elf_Half value,
415 elfcpp::Elf_Half addend,
416 typename elfcpp::Elf_types<size>::Elf_Addr address)
417 { This::template pcrela<16>(view, value, addend, address); }
418
419 static inline void
420 pcrela16(unsigned char* view,
421 const Sized_relobj<size, big_endian>* object,
422 const Symbol_value<size>* psymval,
423 elfcpp::Elf_Half addend,
424 typename elfcpp::Elf_types<size>::Elf_Addr address)
425 { This::template pcrela<16>(view, object, psymval, addend, address); }
426
92e059d8
ILT
427 // Do a simple 32-bit REL relocation with the addend in the section
428 // contents.
429 static inline void
430 rel32(unsigned char* view, elfcpp::Elf_Word value)
b8e6aad9
ILT
431 { This::template rel<32>(view, value); }
432
433 static inline void
434 rel32(unsigned char* view,
435 const Sized_relobj<size, big_endian>* object,
436 const Symbol_value<size>* psymval)
437 { This::template rel<32>(view, object, psymval); }
92e059d8 438
d830e0e0
ILT
439 // Do an 32-bit RELA relocation with the addend in the relocation.
440 static inline void
441 rela32(unsigned char* view, elfcpp::Elf_Word value, elfcpp::Elf_Word addend)
442 { This::template rela<32>(view, value, addend); }
443
444 static inline void
445 rela32(unsigned char* view,
446 const Sized_relobj<size, big_endian>* object,
447 const Symbol_value<size>* psymval,
448 elfcpp::Elf_Word addend)
449 { This::template rela<32>(view, object, psymval, addend); }
450
dfbba8f4
ILT
451 // Do a 32-bit REL relocation, sign extending the addend to SIZE.
452 static inline void
453 rel32s(unsigned char* view,
454 const Sized_relobj<size, big_endian>* object,
455 const Symbol_value<size>* psymval)
456 { This::template signedrel<32>(view, object, psymval); }
457
92e059d8
ILT
458 // Do a simple 32-bit PC relative REL relocation with the addend in
459 // the section contents.
460 static inline void
461 pcrel32(unsigned char* view, elfcpp::Elf_Word value,
462 typename elfcpp::Elf_types<size>::Elf_Addr address)
b8e6aad9
ILT
463 { This::template pcrel<32>(view, value, address); }
464
465 static inline void
466 pcrel32(unsigned char* view,
467 const Sized_relobj<size, big_endian>* object,
468 const Symbol_value<size>* psymval,
469 typename elfcpp::Elf_types<size>::Elf_Addr address)
470 { This::template pcrel<32>(view, object, psymval, address); }
92e059d8 471
d830e0e0
ILT
472 // Do a simple 32-bit PC relative RELA relocation with the addend in
473 // the relocation.
474 static inline void
475 pcrela32(unsigned char* view, elfcpp::Elf_Word value,
476 elfcpp::Elf_Word addend,
477 typename elfcpp::Elf_types<size>::Elf_Addr address)
478 { This::template pcrela<32>(view, value, addend, address); }
479
480 static inline void
481 pcrela32(unsigned char* view,
482 const Sized_relobj<size, big_endian>* object,
483 const Symbol_value<size>* psymval,
484 elfcpp::Elf_Word addend,
485 typename elfcpp::Elf_types<size>::Elf_Addr address)
486 { This::template pcrela<32>(view, object, psymval, addend, address); }
487
92e059d8
ILT
488 // Do a simple 64-bit REL relocation with the addend in the section
489 // contents.
490 static inline void
f6ce93d6 491 rel64(unsigned char* view, elfcpp::Elf_Xword value)
b8e6aad9
ILT
492 { This::template rel<64>(view, value); }
493
494 static inline void
495 rel64(unsigned char* view,
496 const Sized_relobj<size, big_endian>* object,
497 const Symbol_value<size>* psymval)
498 { This::template rel<64>(view, object, psymval); }
92e059d8 499
d830e0e0
ILT
500 // Do a 64-bit RELA relocation with the addend in the relocation.
501 static inline void
502 rela64(unsigned char* view, elfcpp::Elf_Xword value,
503 elfcpp::Elf_Xword addend)
504 { This::template rela<64>(view, value, addend); }
505
506 static inline void
507 rela64(unsigned char* view,
508 const Sized_relobj<size, big_endian>* object,
509 const Symbol_value<size>* psymval,
510 elfcpp::Elf_Xword addend)
511 { This::template rela<64>(view, object, psymval, addend); }
512
92e059d8
ILT
513 // Do a simple 64-bit PC relative REL relocation with the addend in
514 // the section contents.
515 static inline void
f6ce93d6 516 pcrel64(unsigned char* view, elfcpp::Elf_Xword value,
92e059d8 517 typename elfcpp::Elf_types<size>::Elf_Addr address)
b8e6aad9
ILT
518 { This::template pcrel<64>(view, value, address); }
519
520 static inline void
521 pcrel64(unsigned char* view,
522 const Sized_relobj<size, big_endian>* object,
523 const Symbol_value<size>* psymval,
524 typename elfcpp::Elf_types<size>::Elf_Addr address)
525 { This::template pcrel<64>(view, object, psymval, address); }
d830e0e0
ILT
526
527 // Do a simple 64-bit PC relative RELA relocation with the addend in
528 // the relocation.
529 static inline void
530 pcrela64(unsigned char* view, elfcpp::Elf_Xword value,
531 elfcpp::Elf_Xword addend,
532 typename elfcpp::Elf_types<size>::Elf_Addr address)
533 { This::template pcrela<64>(view, value, addend, address); }
534
535 static inline void
536 pcrela64(unsigned char* view,
537 const Sized_relobj<size, big_endian>* object,
538 const Symbol_value<size>* psymval,
539 elfcpp::Elf_Xword addend,
540 typename elfcpp::Elf_types<size>::Elf_Addr address)
541 { This::template pcrela<64>(view, object, psymval, addend, address); }
5a6f7e2d
ILT
542};
543
544// We try to avoid COPY relocations when possible. A COPY relocation
545// may be required when an executable refers to a variable defined in
546// a shared library. COPY relocations are problematic because they
547// tie the executable to the exact size of the variable in the shared
548// library. We can avoid them if all the references to the variable
549// are in a writeable section. In that case we can simply use dynamic
550// relocations. However, when scanning relocs, we don't know when we
551// see the relocation whether we will be forced to use a COPY
552// relocation or not. So we have to save the relocation during the
553// reloc scanning, and then emit it as a dynamic relocation if
554// necessary. This class implements that. It is used by the target
555// specific code.
556
557template<int size, bool big_endian>
558class Copy_relocs
559{
560 public:
561 Copy_relocs()
562 : entries_()
563 { }
a3ad94ed
ILT
564
565 // Return whether we need a COPY reloc for a reloc against GSYM,
566 // which is being applied to section SHNDX in OBJECT.
567 static bool
568 need_copy_reloc(const General_options*, Relobj* object, unsigned int shndx,
5a6f7e2d
ILT
569 Sized_symbol<size>* gsym);
570
571 // Save a Rel against SYM for possible emission later. SHNDX is the
572 // index of the section to which the reloc is being applied.
573 void
574 save(Symbol* sym, Relobj*, unsigned int shndx,
575 const elfcpp::Rel<size, big_endian>&);
576
577 // Save a Rela against SYM for possible emission later.
578 void
579 save(Symbol* sym, Relobj*, unsigned int shndx,
580 const elfcpp::Rela<size, big_endian>&);
581
582 // Return whether there are any relocs to emit. This also discards
583 // entries which need not be emitted.
584 bool
585 any_to_emit();
586
587 // Emit relocs for each symbol which did not get a COPY reloc (i.e.,
588 // is still defined in the dynamic object).
589 template<int sh_type>
590 void
591 emit(Output_data_reloc<sh_type, true, size, big_endian>*);
592
593 private:
594 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
595 typedef typename elfcpp::Elf_types<size>::Elf_Addr Addend;
596
597 // This POD class holds the entries we are saving.
598 class Copy_reloc_entry
599 {
600 public:
601 Copy_reloc_entry(Symbol* sym, unsigned int reloc_type,
602 Relobj* relobj, unsigned int shndx,
603 Address address, Addend addend)
604 : sym_(sym), reloc_type_(reloc_type), relobj_(relobj),
605 shndx_(shndx), address_(address), addend_(addend)
606 { }
607
608 // Return whether we should emit this reloc. If we should not
609 // emit, we clear it.
610 bool
611 should_emit();
612
613 // Emit this reloc.
614
615 void
616 emit(Output_data_reloc<elfcpp::SHT_REL, true, size, big_endian>*);
617
618 void
619 emit(Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian>*);
620
621 private:
622 Symbol* sym_;
623 unsigned int reloc_type_;
624 Relobj* relobj_;
625 unsigned int shndx_;
626 Address address_;
627 Addend addend_;
628 };
629
630 // A list of relocs to be saved.
631 typedef std::vector<Copy_reloc_entry> Copy_reloc_entries;
632
633 // The list of relocs we are saving.
634 Copy_reloc_entries entries_;
92e059d8
ILT
635};
636
61ba1cf9
ILT
637} // End namespace gold.
638
639#endif // !defined(GOLD_RELOC_H)
This page took 0.082428 seconds and 4 git commands to generate.