1 // target-reloc.h -- target specific relocation support -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #ifndef GOLD_TARGET_RELOC_H
24 #define GOLD_TARGET_RELOC_H
30 #include "reloc-types.h"
35 // This function implements the generic part of reloc scanning. The
36 // template parameter Scan must be a class type which provides two
37 // functions: local() and global(). Those functions implement the
38 // machine specific part of scanning. We do it this way to
39 // avoid making a function call for each relocation, and to avoid
40 // repeating the generic code for each target.
42 template<int size
, bool big_endian
, typename Target_type
, int sh_type
,
49 Sized_relobj_file
<size
, big_endian
>* object
,
50 unsigned int data_shndx
,
51 const unsigned char* prelocs
,
53 Output_section
* output_section
,
54 bool needs_special_offset_handling
,
56 const unsigned char* plocal_syms
)
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
;
63 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
65 Reltype
reloc(prelocs
);
67 if (needs_special_offset_handling
68 && !output_section
->is_input_address_mapped(object
, data_shndx
,
69 reloc
.get_r_offset()))
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
);
76 if (r_sym
< local_count
)
78 gold_assert(plocal_syms
!= NULL
);
79 typename
elfcpp::Sym
<size
, big_endian
> lsym(plocal_syms
81 unsigned int shndx
= lsym
.get_st_shndx();
83 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
85 && shndx
!= elfcpp::SHN_UNDEF
86 && !object
->is_section_included(shndx
)
87 && !symtab
->is_section_folded(object
, shndx
))
89 // RELOC is a relocation against a local symbol in a
90 // section we are discarding. We can ignore this
91 // relocation. It will eventually become a reloc
92 // against the value zero.
94 // FIXME: We should issue a warning if this is an
95 // allocated section; is this the best place to do it?
97 // FIXME: The old GNU linker would in some cases look
98 // for the linkonce section which caused this section to
99 // be discarded, and, if the other section was the same
100 // size, change the reloc to refer to the other section.
101 // That seems risky and weird to me, and I don't know of
102 // any case where it is actually required.
106 scan
.local(symtab
, layout
, target
, object
, data_shndx
,
107 output_section
, reloc
, r_type
, lsym
);
111 Symbol
* gsym
= object
->global_symbol(r_sym
);
112 gold_assert(gsym
!= NULL
);
113 if (gsym
->is_forwarder())
114 gsym
= symtab
->resolve_forwards(gsym
);
116 scan
.global(symtab
, layout
, target
, object
, data_shndx
,
117 output_section
, reloc
, r_type
, gsym
);
122 // Behavior for relocations to discarded comdat sections.
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.
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
136 inline Comdat_behavior
137 get_comdat_behavior(const char* name
)
139 if (Layout::is_debug_info_section(name
))
141 if (strcmp(name
, ".eh_frame") == 0
142 || strcmp(name
, ".gcc_except_table") == 0)
147 // Give an error for a symbol with non-default visibility which is not
151 visibility_error(const Symbol
* sym
)
154 switch (sym
->visibility())
156 case elfcpp::STV_INTERNAL
:
159 case elfcpp::STV_HIDDEN
:
162 case elfcpp::STV_PROTECTED
:
168 gold_error(_("%s symbol '%s' is not defined locally"),
172 // Return true if we are should issue an error saying that SYM is an
173 // undefined symbol. This is called if there is a relocation against
177 issue_undefined_symbol_error(const Symbol
* sym
)
179 // We only report global symbols.
183 // We only report undefined symbols.
184 if (!sym
->is_undefined() && !sym
->is_placeholder())
187 // We don't report weak symbols.
188 if (sym
->binding() == elfcpp::STB_WEAK
)
191 // We don't report symbols defined in discarded sections.
192 if (sym
->is_defined_in_discarded_section())
195 // If the target defines this symbol, don't report it here.
196 if (parameters
->target().is_defined_by_abi(sym
))
199 // See if we've been told to ignore whether this symbol is
201 const char* const u
= parameters
->options().unresolved_symbols();
204 if (strcmp(u
, "ignore-all") == 0)
206 if (strcmp(u
, "ignore-in-object-files") == 0 && !sym
->in_dyn())
208 if (strcmp(u
, "ignore-in-shared-libs") == 0 && !sym
->in_reg())
212 // When creating a shared library, only report unresolved symbols if
214 if (parameters
->options().shared() && !parameters
->options().defs())
217 // Otherwise issue a warning.
221 // This function implements the generic part of relocation processing.
222 // The template parameter Relocate must be a class type which provides
223 // a single function, relocate(), which implements the machine
224 // specific part of a relocation.
226 // SIZE is the ELF size: 32 or 64. BIG_ENDIAN is the endianness of
227 // the data. SH_TYPE is the section type: SHT_REL or SHT_RELA.
228 // RELOCATE implements operator() to do a relocation.
230 // PRELOCS points to the relocation data. RELOC_COUNT is the number
231 // of relocs. OUTPUT_SECTION is the output section.
232 // NEEDS_SPECIAL_OFFSET_HANDLING is true if input offsets need to be
233 // mapped to output offsets.
235 // VIEW is the section data, VIEW_ADDRESS is its memory address, and
236 // VIEW_SIZE is the size. These refer to the input section, unless
237 // NEEDS_SPECIAL_OFFSET_HANDLING is true, in which case they refer to
238 // the output section.
240 // RELOC_SYMBOL_CHANGES is used for -fsplit-stack support. If it is
241 // not NULL, it is a vector indexed by relocation index. If that
242 // entry is not NULL, it points to a global symbol which used as the
243 // symbol for the relocation, ignoring the symbol index in the
246 template<int size
, bool big_endian
, typename Target_type
, int sh_type
,
250 const Relocate_info
<size
, big_endian
>* relinfo
,
252 const unsigned char* prelocs
,
254 Output_section
* output_section
,
255 bool needs_special_offset_handling
,
257 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
258 section_size_type view_size
,
259 const Reloc_symbol_changes
* reloc_symbol_changes
)
261 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
262 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
265 Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
266 unsigned int local_count
= object
->local_symbol_count();
268 Comdat_behavior comdat_behavior
= CB_UNDETERMINED
;
270 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
272 Reltype
reloc(prelocs
);
274 section_offset_type offset
=
275 convert_to_section_size_type(reloc
.get_r_offset());
277 if (needs_special_offset_handling
)
279 offset
= output_section
->output_offset(relinfo
->object
,
286 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
287 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
288 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
290 const Sized_symbol
<size
>* sym
;
292 Symbol_value
<size
> symval
;
293 const Symbol_value
<size
> *psymval
;
294 bool is_defined_in_discarded_section
;
296 if (r_sym
< local_count
297 && (reloc_symbol_changes
== NULL
298 || (*reloc_symbol_changes
)[i
] == NULL
))
301 psymval
= object
->local_symbol(r_sym
);
303 // If the local symbol belongs to a section we are discarding,
304 // and that section is a debug section, try to find the
305 // corresponding kept section and map this symbol to its
306 // counterpart in the kept section. The symbol must not
307 // correspond to a section we are folding.
309 shndx
= psymval
->input_shndx(&is_ordinary
);
310 is_defined_in_discarded_section
=
312 && shndx
!= elfcpp::SHN_UNDEF
313 && !object
->is_section_included(shndx
)
314 && !relinfo
->symtab
->is_section_folded(object
, shndx
));
319 if (reloc_symbol_changes
!= NULL
320 && (*reloc_symbol_changes
)[i
] != NULL
)
321 gsym
= (*reloc_symbol_changes
)[i
];
324 gsym
= object
->global_symbol(r_sym
);
325 gold_assert(gsym
!= NULL
);
326 if (gsym
->is_forwarder())
327 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
330 sym
= static_cast<const Sized_symbol
<size
>*>(gsym
);
331 if (sym
->has_symtab_index() && sym
->symtab_index() != -1U)
332 symval
.set_output_symtab_index(sym
->symtab_index());
334 symval
.set_no_output_symtab_entry();
335 symval
.set_output_value(sym
->value());
336 if (gsym
->type() == elfcpp::STT_TLS
)
337 symval
.set_is_tls_symbol();
338 else if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
339 symval
.set_is_ifunc_symbol();
342 is_defined_in_discarded_section
=
343 (gsym
->is_defined_in_discarded_section()
344 && gsym
->is_undefined());
348 Symbol_value
<size
> symval2
;
349 if (is_defined_in_discarded_section
)
351 if (comdat_behavior
== CB_UNDETERMINED
)
353 std::string name
= object
->section_name(relinfo
->data_shndx
);
354 comdat_behavior
= get_comdat_behavior(name
.c_str());
356 if (comdat_behavior
== CB_PRETEND
)
358 // FIXME: This case does not work for global symbols.
359 // We have no place to store the original section index.
360 // Fortunately this does not matter for comdat sections,
361 // only for sections explicitly discarded by a linker
364 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
=
365 object
->map_to_kept_section(shndx
, &found
);
367 symval2
.set_output_value(value
+ psymval
->input_value());
369 symval2
.set_output_value(0);
373 if (comdat_behavior
== CB_WARNING
)
374 gold_warning_at_location(relinfo
, i
, offset
,
375 _("relocation refers to discarded "
377 symval2
.set_output_value(0);
379 symval2
.set_no_output_symtab_entry();
383 if (!relocate
.relocate(relinfo
, target
, output_section
, i
, reloc
,
384 r_type
, sym
, psymval
, view
+ offset
,
385 view_address
+ offset
, view_size
))
388 if (offset
< 0 || static_cast<section_size_type
>(offset
) >= view_size
)
390 gold_error_at_location(relinfo
, i
, offset
,
391 _("reloc has bad offset %zu"),
392 static_cast<size_t>(offset
));
396 if (issue_undefined_symbol_error(sym
))
397 gold_undefined_symbol_at_location(sym
, relinfo
, i
, offset
);
399 && sym
->visibility() != elfcpp::STV_DEFAULT
400 && (sym
->is_undefined() || sym
->is_from_dynobj()))
401 visibility_error(sym
);
403 if (sym
!= NULL
&& sym
->has_warning())
404 relinfo
->symtab
->issue_warning(sym
, relinfo
, i
, offset
);
408 // Apply an incremental relocation.
410 template<int size
, bool big_endian
, typename Target_type
,
413 apply_relocation(const Relocate_info
<size
, big_endian
>* relinfo
,
415 typename
elfcpp::Elf_types
<size
>::Elf_Addr r_offset
,
417 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
,
420 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
421 section_size_type view_size
)
423 // Construct the ELF relocation in a temporary buffer.
424 const int reloc_size
= elfcpp::Elf_sizes
<64>::rela_size
;
425 unsigned char relbuf
[reloc_size
];
426 elfcpp::Rela
<64, false> rel(relbuf
);
427 elfcpp::Rela_write
<64, false> orel(relbuf
);
428 orel
.put_r_offset(r_offset
);
429 orel
.put_r_info(elfcpp::elf_r_info
<64>(0, r_type
));
430 orel
.put_r_addend(r_addend
);
432 // Setup a Symbol_value for the global symbol.
433 const Sized_symbol
<64>* sym
= static_cast<const Sized_symbol
<64>*>(gsym
);
434 Symbol_value
<64> symval
;
435 gold_assert(sym
->has_symtab_index() && sym
->symtab_index() != -1U);
436 symval
.set_output_symtab_index(sym
->symtab_index());
437 symval
.set_output_value(sym
->value());
438 if (gsym
->type() == elfcpp::STT_TLS
)
439 symval
.set_is_tls_symbol();
440 else if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
441 symval
.set_is_ifunc_symbol();
444 relocate
.relocate(relinfo
, target
, NULL
, -1U, rel
, r_type
, sym
, &symval
,
445 view
+ r_offset
, address
+ r_offset
, view_size
);
448 // This class may be used as a typical class for the
449 // Scan_relocatable_reloc parameter to scan_relocatable_relocs. The
450 // template parameter Classify_reloc must be a class type which
451 // provides a function get_size_for_reloc which returns the number of
452 // bytes to which a reloc applies. This class is intended to capture
453 // the most typical target behaviour, while still permitting targets
454 // to define their own independent class for Scan_relocatable_reloc.
456 template<int sh_type
, typename Classify_reloc
>
457 class Default_scan_relocatable_relocs
460 // Return the strategy to use for a local symbol which is not a
461 // section symbol, given the relocation type.
462 inline Relocatable_relocs::Reloc_strategy
463 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
465 // We assume that relocation type 0 is NONE. Targets which are
466 // different must override.
467 if (r_type
== 0 && r_sym
== 0)
468 return Relocatable_relocs::RELOC_DISCARD
;
469 return Relocatable_relocs::RELOC_COPY
;
472 // Return the strategy to use for a local symbol which is a section
473 // symbol, given the relocation type.
474 inline Relocatable_relocs::Reloc_strategy
475 local_section_strategy(unsigned int r_type
, Relobj
* object
)
477 if (sh_type
== elfcpp::SHT_RELA
)
478 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
481 Classify_reloc classify
;
482 switch (classify
.get_size_for_reloc(r_type
, object
))
485 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
;
487 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1
;
489 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2
;
491 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4
;
493 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8
;
500 // Return the strategy to use for a global symbol, given the
501 // relocation type, the object, and the symbol index.
502 inline Relocatable_relocs::Reloc_strategy
503 global_strategy(unsigned int, Relobj
*, unsigned int)
504 { return Relocatable_relocs::RELOC_COPY
; }
507 // Scan relocs during a relocatable link. This is a default
508 // definition which should work for most targets.
509 // Scan_relocatable_reloc must name a class type which provides three
510 // functions which return a Relocatable_relocs::Reloc_strategy code:
511 // global_strategy, local_non_section_strategy, and
512 // local_section_strategy. Most targets should be able to use
513 // Default_scan_relocatable_relocs as this class.
515 template<int size
, bool big_endian
, int sh_type
,
516 typename Scan_relocatable_reloc
>
518 scan_relocatable_relocs(
521 Sized_relobj_file
<size
, big_endian
>* object
,
522 unsigned int data_shndx
,
523 const unsigned char* prelocs
,
525 Output_section
* output_section
,
526 bool needs_special_offset_handling
,
527 size_t local_symbol_count
,
528 const unsigned char* plocal_syms
,
529 Relocatable_relocs
* rr
)
531 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
532 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
533 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
534 Scan_relocatable_reloc scan
;
536 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
538 Reltype
reloc(prelocs
);
540 Relocatable_relocs::Reloc_strategy strategy
;
542 if (needs_special_offset_handling
543 && !output_section
->is_input_address_mapped(object
, data_shndx
,
544 reloc
.get_r_offset()))
545 strategy
= Relocatable_relocs::RELOC_DISCARD
;
548 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
=
550 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
551 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
553 if (r_sym
>= local_symbol_count
)
554 strategy
= scan
.global_strategy(r_type
, object
, r_sym
);
557 gold_assert(plocal_syms
!= NULL
);
558 typename
elfcpp::Sym
<size
, big_endian
> lsym(plocal_syms
560 unsigned int shndx
= lsym
.get_st_shndx();
562 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
564 && shndx
!= elfcpp::SHN_UNDEF
565 && !object
->is_section_included(shndx
))
567 // RELOC is a relocation against a local symbol
568 // defined in a section we are discarding. Discard
569 // the reloc. FIXME: Should we issue a warning?
570 strategy
= Relocatable_relocs::RELOC_DISCARD
;
572 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
573 strategy
= scan
.local_non_section_strategy(r_type
, object
,
577 strategy
= scan
.local_section_strategy(r_type
, object
);
578 if (strategy
!= Relocatable_relocs::RELOC_DISCARD
)
579 object
->output_section(shndx
)->set_needs_symtab_index();
582 if (strategy
== Relocatable_relocs::RELOC_COPY
)
583 object
->set_must_have_output_symtab_entry(r_sym
);
587 rr
->set_next_reloc_strategy(strategy
);
591 // Relocate relocs during a relocatable link. This is a default
592 // definition which should work for most targets.
594 template<int size
, bool big_endian
, int sh_type
>
596 relocate_for_relocatable(
597 const Relocate_info
<size
, big_endian
>* relinfo
,
598 const unsigned char* prelocs
,
600 Output_section
* output_section
,
601 typename
elfcpp::Elf_types
<size
>::Elf_Addr offset_in_output_section
,
602 const Relocatable_relocs
* rr
,
604 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
605 section_size_type view_size
,
606 unsigned char* reloc_view
,
607 section_size_type reloc_view_size
)
609 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
610 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
611 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc_write
613 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
614 const Address invalid_address
= static_cast<Address
>(0) - 1;
616 Sized_relobj_file
<size
, big_endian
>* const object
= relinfo
->object
;
617 const unsigned int local_count
= object
->local_symbol_count();
619 unsigned char* pwrite
= reloc_view
;
621 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
623 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
624 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
627 if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
629 // Target wants to handle this relocation.
630 Sized_target
<size
, big_endian
>* target
=
631 parameters
->sized_target
<size
, big_endian
>();
632 target
->relocate_special_relocatable(relinfo
, sh_type
, prelocs
,
634 offset_in_output_section
,
637 pwrite
+= reloc_size
;
640 Reltype
reloc(prelocs
);
641 Reltype_write
reloc_write(pwrite
);
643 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
644 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
645 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
647 // Get the new symbol index.
649 unsigned int new_symndx
;
650 if (r_sym
< local_count
)
654 case Relocatable_relocs::RELOC_COPY
:
659 new_symndx
= object
->symtab_index(r_sym
);
660 gold_assert(new_symndx
!= -1U);
664 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
665 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
:
666 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1
:
667 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2
:
668 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4
:
669 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8
:
671 // We are adjusting a section symbol. We need to find
672 // the symbol table index of the section symbol for
673 // the output section corresponding to input section
674 // in which this symbol is defined.
675 gold_assert(r_sym
< local_count
);
678 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
679 gold_assert(is_ordinary
);
680 Output_section
* os
= object
->output_section(shndx
);
681 gold_assert(os
!= NULL
);
682 gold_assert(os
->needs_symtab_index());
683 new_symndx
= os
->symtab_index();
693 const Symbol
* gsym
= object
->global_symbol(r_sym
);
694 gold_assert(gsym
!= NULL
);
695 if (gsym
->is_forwarder())
696 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
698 gold_assert(gsym
->has_symtab_index());
699 new_symndx
= gsym
->symtab_index();
702 // Get the new offset--the location in the output section where
703 // this relocation should be applied.
705 Address offset
= reloc
.get_r_offset();
707 if (offset_in_output_section
!= invalid_address
)
708 new_offset
= offset
+ offset_in_output_section
;
711 section_offset_type sot_offset
=
712 convert_types
<section_offset_type
, Address
>(offset
);
713 section_offset_type new_sot_offset
=
714 output_section
->output_offset(object
, relinfo
->data_shndx
,
716 gold_assert(new_sot_offset
!= -1);
717 new_offset
= new_sot_offset
;
720 // In an object file, r_offset is an offset within the section.
721 // In an executable or dynamic object, generated by
722 // --emit-relocs, r_offset is an absolute address.
723 if (!parameters
->options().relocatable())
725 new_offset
+= view_address
;
726 if (offset_in_output_section
!= invalid_address
)
727 new_offset
-= offset_in_output_section
;
730 reloc_write
.put_r_offset(new_offset
);
731 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(new_symndx
, r_type
));
733 // Handle the reloc addend based on the strategy.
735 if (strategy
== Relocatable_relocs::RELOC_COPY
)
737 if (sh_type
== elfcpp::SHT_RELA
)
738 Reloc_types
<sh_type
, size
, big_endian
>::
739 copy_reloc_addend(&reloc_write
,
744 // The relocation uses a section symbol in the input file.
745 // We are adjusting it to use a section symbol in the output
746 // file. The input section symbol refers to some address in
747 // the input section. We need the relocation in the output
748 // file to refer to that same address. This adjustment to
749 // the addend is the same calculation we use for a simple
750 // absolute relocation for the input section symbol.
752 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
754 unsigned char* padd
= view
+ offset
;
757 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
759 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
;
760 addend
= Reloc_types
<sh_type
, size
, big_endian
>::
761 get_reloc_addend(&reloc
);
762 addend
= psymval
->value(object
, addend
);
763 Reloc_types
<sh_type
, size
, big_endian
>::
764 set_reloc_addend(&reloc_write
, addend
);
768 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
:
771 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1
:
772 Relocate_functions
<size
, big_endian
>::rel8(padd
, object
,
776 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2
:
777 Relocate_functions
<size
, big_endian
>::rel16(padd
, object
,
781 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4
:
782 Relocate_functions
<size
, big_endian
>::rel32(padd
, object
,
786 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8
:
787 Relocate_functions
<size
, big_endian
>::rel64(padd
, object
,
796 pwrite
+= reloc_size
;
799 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
803 } // End namespace gold.
805 #endif // !defined(GOLD_TARGET_RELOC_H)