* configure.ac: Update test for TLS descriptors: they are
[deliverable/binutils-gdb.git] / gold / target-reloc.h
CommitLineData
61ba1cf9
ILT
1// target-reloc.h -- target specific relocation support -*- C++ -*-
2
ebdbb458 3// Copyright 2006, 2007, 2008 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_TARGET_RELOC_H
24#define GOLD_TARGET_RELOC_H
25
26#include "elfcpp.h"
27#include "symtab.h"
6a74a719 28#include "reloc.h"
c06b7b0b 29#include "reloc-types.h"
61ba1cf9
ILT
30
31namespace gold
32{
33
6a74a719
ILT
34// This function implements the generic part of reloc scanning. The
35// template parameter Scan must be a class type which provides two
36// functions: local() and global(). Those functions implement the
37// machine specific part of scanning. We do it this way to
38// avoidmaking a function call for each relocation, and to avoid
39// repeating the generic code for each target.
92e059d8 40
ead1e424
ILT
41template<int size, bool big_endian, typename Target_type, int sh_type,
42 typename Scan>
92e059d8
ILT
43inline void
44scan_relocs(
45 const General_options& options,
46 Symbol_table* symtab,
ead1e424
ILT
47 Layout* layout,
48 Target_type* target,
f6ce93d6 49 Sized_relobj<size, big_endian>* object,
a3ad94ed 50 unsigned int data_shndx,
92e059d8
ILT
51 const unsigned char* prelocs,
52 size_t reloc_count,
730cdc88
ILT
53 Output_section* output_section,
54 bool needs_special_offset_handling,
92e059d8 55 size_t local_count,
730cdc88 56 const unsigned char* plocal_syms)
92e059d8
ILT
57{
58 typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
59 const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
60 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
61 Scan scan;
62
63 for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
64 {
65 Reltype reloc(prelocs);
66
730cdc88
ILT
67 if (needs_special_offset_handling
68 && !output_section->is_input_address_mapped(object, data_shndx,
69 reloc.get_r_offset()))
70 continue;
71
92e059d8
ILT
72 typename elfcpp::Elf_types<size>::Elf_WXword r_info = reloc.get_r_info();
73 unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
74 unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
75
76 if (r_sym < local_count)
77 {
a3ad94ed 78 gold_assert(plocal_syms != NULL);
92e059d8
ILT
79 typename elfcpp::Sym<size, big_endian> lsym(plocal_syms
80 + r_sym * sym_size);
d491d34e
ILT
81 unsigned int shndx = lsym.get_st_shndx();
82 bool is_ordinary;
83 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
84 if (is_ordinary
ead1e424 85 && shndx != elfcpp::SHN_UNDEF
d491d34e 86 && !object->is_section_included(shndx))
92e059d8
ILT
87 {
88 // RELOC is a relocation against a local symbol in a
89 // section we are discarding. We can ignore this
90 // relocation. It will eventually become a reloc
91 // against the value zero.
92 //
93 // FIXME: We should issue a warning if this is an
94 // allocated section; is this the best place to do it?
95 //
96 // FIXME: The old GNU linker would in some cases look
97 // for the linkonce section which caused this section to
98 // be discarded, and, if the other section was the same
99 // size, change the reloc to refer to the other section.
100 // That seems risky and weird to me, and I don't know of
101 // any case where it is actually required.
102
103 continue;
104 }
105
a3ad94ed 106 scan.local(options, symtab, layout, target, object, data_shndx,
07f397ab 107 output_section, reloc, r_type, lsym);
92e059d8
ILT
108 }
109 else
110 {
730cdc88 111 Symbol* gsym = object->global_symbol(r_sym);
a3ad94ed 112 gold_assert(gsym != NULL);
92e059d8
ILT
113 if (gsym->is_forwarder())
114 gsym = symtab->resolve_forwards(gsym);
115
a3ad94ed 116 scan.global(options, symtab, layout, target, object, data_shndx,
07f397ab 117 output_section, reloc, r_type, gsym);
92e059d8
ILT
118 }
119 }
120}
121
e94cf127
CC
122// Behavior for relocations to discarded comdat sections.
123
124enum Comdat_behavior
125{
126 CB_UNDETERMINED, // Not yet determined -- need to look at section name.
127 CB_PRETEND, // Attempt to map to the corresponding kept section.
128 CB_IGNORE, // Ignore the relocation.
129 CB_WARNING // Print a warning.
130};
131
132// Decide what the linker should do for relocations that refer to discarded
133// comdat sections. This decision is based on the name of the section being
134// relocated.
135
136inline Comdat_behavior
137get_comdat_behavior(const char* name)
138{
139 if (Layout::is_debug_info_section(name))
140 return CB_PRETEND;
141 if (strcmp(name, ".eh_frame") == 0
142 || strcmp(name, ".gcc_except_table") == 0)
143 return CB_IGNORE;
144 return CB_WARNING;
145}
146
92e059d8 147// This function implements the generic part of relocation processing.
6a74a719
ILT
148// The template parameter Relocate must be a class type which provides
149// a single function, relocate(), which implements the machine
150// specific part of a relocation.
61ba1cf9
ILT
151
152// SIZE is the ELF size: 32 or 64. BIG_ENDIAN is the endianness of
92e059d8
ILT
153// the data. SH_TYPE is the section type: SHT_REL or SHT_RELA.
154// RELOCATE implements operator() to do a relocation.
61ba1cf9 155
92e059d8 156// PRELOCS points to the relocation data. RELOC_COUNT is the number
730cdc88
ILT
157// of relocs. OUTPUT_SECTION is the output section.
158// NEEDS_SPECIAL_OFFSET_HANDLING is true if input offsets need to be
159// mapped to output offsets.
160
161// VIEW is the section data, VIEW_ADDRESS is its memory address, and
162// VIEW_SIZE is the size. These refer to the input section, unless
163// NEEDS_SPECIAL_OFFSET_HANDLING is true, in which case they refer to
164// the output section.
61ba1cf9 165
ead1e424
ILT
166template<int size, bool big_endian, typename Target_type, int sh_type,
167 typename Relocate>
61ba1cf9
ILT
168inline void
169relocate_section(
92e059d8 170 const Relocate_info<size, big_endian>* relinfo,
ead1e424 171 Target_type* target,
61ba1cf9
ILT
172 const unsigned char* prelocs,
173 size_t reloc_count,
730cdc88
ILT
174 Output_section* output_section,
175 bool needs_special_offset_handling,
61ba1cf9
ILT
176 unsigned char* view,
177 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
fe8718a4 178 section_size_type view_size)
61ba1cf9
ILT
179{
180 typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
181 const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
182 Relocate relocate;
183
730cdc88
ILT
184 Sized_relobj<size, big_endian>* object = relinfo->object;
185 unsigned int local_count = object->local_symbol_count();
92e059d8 186
e94cf127
CC
187 Comdat_behavior comdat_behavior = CB_UNDETERMINED;
188
61ba1cf9
ILT
189 for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
190 {
191 Reltype reloc(prelocs);
192
fe8718a4
ILT
193 section_offset_type offset =
194 convert_to_section_size_type(reloc.get_r_offset());
61ba1cf9 195
730cdc88
ILT
196 if (needs_special_offset_handling)
197 {
198 offset = output_section->output_offset(relinfo->object,
199 relinfo->data_shndx,
200 offset);
201 if (offset == -1)
202 continue;
203 }
204
61ba1cf9
ILT
205 typename elfcpp::Elf_types<size>::Elf_WXword r_info = reloc.get_r_info();
206 unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
207 unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
208
c06b7b0b 209 const Sized_symbol<size>* sym;
61ba1cf9 210
b8e6aad9
ILT
211 Symbol_value<size> symval;
212 const Symbol_value<size> *psymval;
61ba1cf9
ILT
213 if (r_sym < local_count)
214 {
215 sym = NULL;
730cdc88 216 psymval = object->local_symbol(r_sym);
e94cf127
CC
217
218 // If the local symbol belongs to a section we are discarding,
219 // and that section is a debug section, try to find the
220 // corresponding kept section and map this symbol to its
221 // counterpart in the kept section.
222 bool is_ordinary;
223 unsigned int shndx = psymval->input_shndx(&is_ordinary);
224 if (is_ordinary
225 && shndx != elfcpp::SHN_UNDEF
226 && !object->is_section_included(shndx))
227 {
228 if (comdat_behavior == CB_UNDETERMINED)
229 {
4418b2d5
CC
230 std::string name = object->section_name(relinfo->data_shndx);
231 comdat_behavior = get_comdat_behavior(name.c_str());
e94cf127
CC
232 }
233 if (comdat_behavior == CB_PRETEND)
234 {
235 bool found;
236 typename elfcpp::Elf_types<size>::Elf_Addr value =
237 object->map_to_kept_section(shndx, &found);
238 if (found)
239 symval.set_output_value(value + psymval->input_value());
240 else
241 symval.set_output_value(0);
242 }
243 else
244 {
245 if (comdat_behavior == CB_WARNING)
246 gold_warning_at_location(relinfo, i, offset,
247 _("Relocation refers to discarded "
248 "comdat section"));
249 symval.set_output_value(0);
250 }
251 symval.set_no_output_symtab_entry();
252 psymval = &symval;
253 }
61ba1cf9
ILT
254 }
255 else
256 {
730cdc88 257 const Symbol* gsym = object->global_symbol(r_sym);
a3ad94ed 258 gold_assert(gsym != NULL);
61ba1cf9 259 if (gsym->is_forwarder())
92e059d8 260 gsym = relinfo->symtab->resolve_forwards(gsym);
61ba1cf9 261
c06b7b0b 262 sym = static_cast<const Sized_symbol<size>*>(gsym);
b8e6aad9
ILT
263 if (sym->has_symtab_index())
264 symval.set_output_symtab_index(sym->symtab_index());
265 else
266 symval.set_no_output_symtab_entry();
267 symval.set_output_value(sym->value());
268 psymval = &symval;
ead1e424 269 }
61ba1cf9 270
b8e6aad9 271 if (!relocate.relocate(relinfo, target, i, reloc, r_type, sym, psymval,
ead1e424
ILT
272 view + offset, view_address + offset, view_size))
273 continue;
274
fe8718a4 275 if (offset < 0 || static_cast<section_size_type>(offset) >= view_size)
ead1e424 276 {
75f2446e
ILT
277 gold_error_at_location(relinfo, i, offset,
278 _("reloc has bad offset %zu"),
279 static_cast<size_t>(offset));
280 continue;
61ba1cf9
ILT
281 }
282
ead1e424
ILT
283 if (sym != NULL
284 && sym->is_undefined()
436ca963 285 && sym->binding() != elfcpp::STB_WEAK
9c2d0ef9 286 && !target->is_defined_by_abi(sym)
eb42429a
ILT
287 && (!parameters->options().shared() // -shared
288 || parameters->options().defs())) // -z defs
75f2446e 289 gold_undefined_symbol(sym, relinfo, i, offset);
f6ce93d6
ILT
290
291 if (sym != NULL && sym->has_warning())
75f2446e 292 relinfo->symtab->issue_warning(sym, relinfo, i, offset);
61ba1cf9
ILT
293 }
294}
295
6a74a719
ILT
296// This class may be used as a typical class for the
297// Scan_relocatable_reloc parameter to scan_relocatable_relocs. The
298// template parameter Classify_reloc must be a class type which
299// provides a function get_size_for_reloc which returns the number of
300// bytes to which a reloc applies. This class is intended to capture
301// the most typical target behaviour, while still permitting targets
302// to define their own independent class for Scan_relocatable_reloc.
303
304template<int sh_type, typename Classify_reloc>
305class Default_scan_relocatable_relocs
306{
307 public:
308 // Return the strategy to use for a local symbol which is not a
309 // section symbol, given the relocation type.
310 inline Relocatable_relocs::Reloc_strategy
c2508178
ILT
311 local_non_section_strategy(unsigned int r_type, Relobj*)
312 {
313 // We assume that relocation type 0 is NONE. Targets which are
314 // different must override.
315 if (r_type == 0)
316 return Relocatable_relocs::RELOC_DISCARD;
317 return Relocatable_relocs::RELOC_COPY;
318 }
6a74a719
ILT
319
320 // Return the strategy to use for a local symbol which is a section
321 // symbol, given the relocation type.
322 inline Relocatable_relocs::Reloc_strategy
323 local_section_strategy(unsigned int r_type, Relobj* object)
324 {
c2508178
ILT
325 // We assume that relocation type 0 is NONE. Targets which are
326 // different must override.
327 if (r_type == 0)
328 return Relocatable_relocs::RELOC_DISCARD;
6a74a719
ILT
329 if (sh_type == elfcpp::SHT_RELA)
330 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA;
331 else
332 {
333 Classify_reloc classify;
334 switch (classify.get_size_for_reloc(r_type, object))
335 {
336 case 0:
7019cd25 337 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0;
6a74a719
ILT
338 case 1:
339 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1;
340 case 2:
341 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2;
342 case 4:
343 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4;
344 case 8:
345 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8;
346 default:
347 gold_unreachable();
348 }
349 }
350 }
351
352 // Return the strategy to use for a global symbol, given the
353 // relocation type, the object, and the symbol index.
354 inline Relocatable_relocs::Reloc_strategy
c2508178
ILT
355 global_strategy(unsigned int r_type, Relobj*, unsigned int)
356 {
357 // We assume that relocation type 0 is NONE. Targets which are
358 // different must override.
359 if (r_type == 0)
360 return Relocatable_relocs::RELOC_DISCARD;
361 return Relocatable_relocs::RELOC_COPY;
362 }
6a74a719
ILT
363};
364
365// Scan relocs during a relocatable link. This is a default
366// definition which should work for most targets.
367// Scan_relocatable_reloc must name a class type which provides three
368// functions which return a Relocatable_relocs::Reloc_strategy code:
369// global_strategy, local_non_section_strategy, and
370// local_section_strategy. Most targets should be able to use
371// Default_scan_relocatable_relocs as this class.
372
7019cd25 373template<int size, bool big_endian, int sh_type,
6a74a719
ILT
374 typename Scan_relocatable_reloc>
375void
376scan_relocatable_relocs(
377 const General_options&,
378 Symbol_table*,
379 Layout*,
380 Sized_relobj<size, big_endian>* object,
381 unsigned int data_shndx,
382 const unsigned char* prelocs,
383 size_t reloc_count,
384 Output_section* output_section,
385 bool needs_special_offset_handling,
386 size_t local_symbol_count,
387 const unsigned char* plocal_syms,
388 Relocatable_relocs* rr)
389{
390 typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
391 const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
392 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
393 Scan_relocatable_reloc scan;
394
395 for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
396 {
397 Reltype reloc(prelocs);
398
399 Relocatable_relocs::Reloc_strategy strategy;
400
401 if (needs_special_offset_handling
402 && !output_section->is_input_address_mapped(object, data_shndx,
403 reloc.get_r_offset()))
404 strategy = Relocatable_relocs::RELOC_DISCARD;
405 else
406 {
407 typename elfcpp::Elf_types<size>::Elf_WXword r_info =
408 reloc.get_r_info();
409 const unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
410 const unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
411
412 if (r_sym >= local_symbol_count)
413 strategy = scan.global_strategy(r_type, object, r_sym);
414 else
415 {
416 gold_assert(plocal_syms != NULL);
417 typename elfcpp::Sym<size, big_endian> lsym(plocal_syms
418 + r_sym * sym_size);
d491d34e
ILT
419 unsigned int shndx = lsym.get_st_shndx();
420 bool is_ordinary;
421 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
422 if (is_ordinary
6a74a719 423 && shndx != elfcpp::SHN_UNDEF
d491d34e 424 && !object->is_section_included(shndx))
6a74a719
ILT
425 {
426 // RELOC is a relocation against a local symbol
427 // defined in a section we are discarding. Discard
428 // the reloc. FIXME: Should we issue a warning?
429 strategy = Relocatable_relocs::RELOC_DISCARD;
430 }
431 else if (lsym.get_st_type() != elfcpp::STT_SECTION)
432 strategy = scan.local_non_section_strategy(r_type, object);
433 else
434 {
435 strategy = scan.local_section_strategy(r_type, object);
436 if (strategy != Relocatable_relocs::RELOC_DISCARD)
ef9beddf 437 object->output_section(shndx)->set_needs_symtab_index();
6a74a719
ILT
438 }
439 }
440 }
441
442 rr->set_next_reloc_strategy(strategy);
443 }
444}
445
446// Relocate relocs during a relocatable link. This is a default
447// definition which should work for most targets.
448
7019cd25 449template<int size, bool big_endian, int sh_type>
6a74a719
ILT
450void
451relocate_for_relocatable(
452 const Relocate_info<size, big_endian>* relinfo,
453 const unsigned char* prelocs,
454 size_t reloc_count,
455 Output_section* output_section,
ef9beddf 456 typename elfcpp::Elf_types<size>::Elf_Addr offset_in_output_section,
6a74a719
ILT
457 const Relocatable_relocs* rr,
458 unsigned char* view,
6be6f3bd 459 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
6a74a719
ILT
460 section_size_type,
461 unsigned char* reloc_view,
462 section_size_type reloc_view_size)
463{
ef9beddf 464 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
6a74a719
ILT
465 typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
466 typedef typename Reloc_types<sh_type, size, big_endian>::Reloc_write
467 Reltype_write;
468 const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
eff45813 469 const Address invalid_address = static_cast<Address>(0) - 1;
6a74a719
ILT
470
471 Sized_relobj<size, big_endian>* const object = relinfo->object;
472 const unsigned int local_count = object->local_symbol_count();
473
474 unsigned char* pwrite = reloc_view;
475
476 for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
477 {
478 Relocatable_relocs::Reloc_strategy strategy = rr->strategy(i);
479 if (strategy == Relocatable_relocs::RELOC_DISCARD)
480 continue;
481
482 Reltype reloc(prelocs);
483 Reltype_write reloc_write(pwrite);
484
485 typename elfcpp::Elf_types<size>::Elf_WXword r_info = reloc.get_r_info();
486 const unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
487 const unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
488
489 // Get the new symbol index.
490
491 unsigned int new_symndx;
492 if (r_sym < local_count)
493 {
494 switch (strategy)
495 {
496 case Relocatable_relocs::RELOC_COPY:
497 new_symndx = object->symtab_index(r_sym);
498 gold_assert(new_symndx != -1U);
499 break;
500
501 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA:
7019cd25 502 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0:
6a74a719
ILT
503 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1:
504 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2:
505 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4:
506 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8:
507 {
508 // We are adjusting a section symbol. We need to find
509 // the symbol table index of the section symbol for
510 // the output section corresponding to input section
511 // in which this symbol is defined.
512 gold_assert(r_sym < local_count);
d491d34e
ILT
513 bool is_ordinary;
514 unsigned int shndx =
515 object->local_symbol_input_shndx(r_sym, &is_ordinary);
516 gold_assert(is_ordinary);
ef9beddf 517 Output_section* os = object->output_section(shndx);
6a74a719
ILT
518 gold_assert(os != NULL);
519 gold_assert(os->needs_symtab_index());
520 new_symndx = os->symtab_index();
521 }
522 break;
523
524 default:
525 gold_unreachable();
526 }
527 }
528 else
529 {
530 const Symbol* gsym = object->global_symbol(r_sym);
531 gold_assert(gsym != NULL);
532 if (gsym->is_forwarder())
533 gsym = relinfo->symtab->resolve_forwards(gsym);
534
535 gold_assert(gsym->has_symtab_index());
536 new_symndx = gsym->symtab_index();
537 }
538
539 // Get the new offset--the location in the output section where
540 // this relocation should be applied.
541
ef9beddf
ILT
542 Address offset = reloc.get_r_offset();
543 Address new_offset;
eff45813 544 if (offset_in_output_section != invalid_address)
6a74a719
ILT
545 new_offset = offset + offset_in_output_section;
546 else
547 {
ef9beddf
ILT
548 section_offset_type sot_offset =
549 convert_types<section_offset_type, Address>(offset);
550 section_offset_type new_sot_offset =
551 output_section->output_offset(object, relinfo->data_shndx,
552 sot_offset);
553 gold_assert(new_sot_offset != -1);
554 new_offset = new_sot_offset;
6a74a719
ILT
555 }
556
6be6f3bd
ILT
557 // In an object file, r_offset is an offset within the section.
558 // In an executable or dynamic object, generated by
559 // --emit-relocs, r_offset is an absolute address.
560 if (!parameters->options().relocatable())
e09ad04a
ILT
561 {
562 new_offset += view_address;
eff45813 563 if (offset_in_output_section != invalid_address)
e09ad04a
ILT
564 new_offset -= offset_in_output_section;
565 }
6be6f3bd 566
6a74a719
ILT
567 reloc_write.put_r_offset(new_offset);
568 reloc_write.put_r_info(elfcpp::elf_r_info<size>(new_symndx, r_type));
569
570 // Handle the reloc addend based on the strategy.
571
572 if (strategy == Relocatable_relocs::RELOC_COPY)
573 {
574 if (sh_type == elfcpp::SHT_RELA)
575 Reloc_types<sh_type, size, big_endian>::
576 copy_reloc_addend(&reloc_write,
577 &reloc);
578 }
579 else
580 {
581 // The relocation uses a section symbol in the input file.
582 // We are adjusting it to use a section symbol in the output
583 // file. The input section symbol refers to some address in
584 // the input section. We need the relocation in the output
585 // file to refer to that same address. This adjustment to
586 // the addend is the same calculation we use for a simple
587 // absolute relocation for the input section symbol.
588
589 const Symbol_value<size>* psymval = object->local_symbol(r_sym);
590
591 unsigned char* padd = view + offset;
592 switch (strategy)
593 {
594 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA:
595 {
596 typename elfcpp::Elf_types<size>::Elf_Swxword addend;
597 addend = Reloc_types<sh_type, size, big_endian>::
598 get_reloc_addend(&reloc);
599 addend = psymval->value(object, addend);
600 Reloc_types<sh_type, size, big_endian>::
601 set_reloc_addend(&reloc_write, addend);
602 }
603 break;
604
7019cd25
ILT
605 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0:
606 break;
607
6a74a719
ILT
608 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1:
609 Relocate_functions<size, big_endian>::rel8(padd, object,
610 psymval);
611 break;
612
613 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2:
614 Relocate_functions<size, big_endian>::rel16(padd, object,
615 psymval);
616 break;
617
618 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4:
619 Relocate_functions<size, big_endian>::rel32(padd, object,
620 psymval);
621 break;
622
623 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8:
624 Relocate_functions<size, big_endian>::rel64(padd, object,
625 psymval);
626 break;
627
628 default:
629 gold_unreachable();
630 }
631 }
632
633 pwrite += reloc_size;
634 }
635
636 gold_assert(static_cast<section_size_type>(pwrite - reloc_view)
637 == reloc_view_size);
638}
639
61ba1cf9
ILT
640} // End namespace gold.
641
642#endif // !defined(GOLD_TARGET_RELOC_H)
This page took 0.152851 seconds and 4 git commands to generate.