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
)
180 && (sym
->is_undefined() || sym
->is_placeholder())
181 && sym
->binding() != elfcpp::STB_WEAK
182 && !sym
->is_defined_in_discarded_section()
183 && !parameters
->target().is_defined_by_abi(sym
)
184 && (!parameters
->options().shared()
185 || parameters
->options().defs()));
188 // This function implements the generic part of relocation processing.
189 // The template parameter Relocate must be a class type which provides
190 // a single function, relocate(), which implements the machine
191 // specific part of a relocation.
193 // SIZE is the ELF size: 32 or 64. BIG_ENDIAN is the endianness of
194 // the data. SH_TYPE is the section type: SHT_REL or SHT_RELA.
195 // RELOCATE implements operator() to do a relocation.
197 // PRELOCS points to the relocation data. RELOC_COUNT is the number
198 // of relocs. OUTPUT_SECTION is the output section.
199 // NEEDS_SPECIAL_OFFSET_HANDLING is true if input offsets need to be
200 // mapped to output offsets.
202 // VIEW is the section data, VIEW_ADDRESS is its memory address, and
203 // VIEW_SIZE is the size. These refer to the input section, unless
204 // NEEDS_SPECIAL_OFFSET_HANDLING is true, in which case they refer to
205 // the output section.
207 // RELOC_SYMBOL_CHANGES is used for -fsplit-stack support. If it is
208 // not NULL, it is a vector indexed by relocation index. If that
209 // entry is not NULL, it points to a global symbol which used as the
210 // symbol for the relocation, ignoring the symbol index in the
213 template<int size
, bool big_endian
, typename Target_type
, int sh_type
,
217 const Relocate_info
<size
, big_endian
>* relinfo
,
219 const unsigned char* prelocs
,
221 Output_section
* output_section
,
222 bool needs_special_offset_handling
,
224 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
225 section_size_type view_size
,
226 const Reloc_symbol_changes
* reloc_symbol_changes
)
228 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
229 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
232 Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
233 unsigned int local_count
= object
->local_symbol_count();
235 Comdat_behavior comdat_behavior
= CB_UNDETERMINED
;
237 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
239 Reltype
reloc(prelocs
);
241 section_offset_type offset
=
242 convert_to_section_size_type(reloc
.get_r_offset());
244 if (needs_special_offset_handling
)
246 offset
= output_section
->output_offset(relinfo
->object
,
253 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
254 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
255 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
257 const Sized_symbol
<size
>* sym
;
259 Symbol_value
<size
> symval
;
260 const Symbol_value
<size
> *psymval
;
261 bool is_defined_in_discarded_section
;
263 if (r_sym
< local_count
264 && (reloc_symbol_changes
== NULL
265 || (*reloc_symbol_changes
)[i
] == NULL
))
268 psymval
= object
->local_symbol(r_sym
);
270 // If the local symbol belongs to a section we are discarding,
271 // and that section is a debug section, try to find the
272 // corresponding kept section and map this symbol to its
273 // counterpart in the kept section. The symbol must not
274 // correspond to a section we are folding.
276 shndx
= psymval
->input_shndx(&is_ordinary
);
277 is_defined_in_discarded_section
=
279 && shndx
!= elfcpp::SHN_UNDEF
280 && !object
->is_section_included(shndx
)
281 && !relinfo
->symtab
->is_section_folded(object
, shndx
));
286 if (reloc_symbol_changes
!= NULL
287 && (*reloc_symbol_changes
)[i
] != NULL
)
288 gsym
= (*reloc_symbol_changes
)[i
];
291 gsym
= object
->global_symbol(r_sym
);
292 gold_assert(gsym
!= NULL
);
293 if (gsym
->is_forwarder())
294 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
297 sym
= static_cast<const Sized_symbol
<size
>*>(gsym
);
298 if (sym
->has_symtab_index() && sym
->symtab_index() != -1U)
299 symval
.set_output_symtab_index(sym
->symtab_index());
301 symval
.set_no_output_symtab_entry();
302 symval
.set_output_value(sym
->value());
303 if (gsym
->type() == elfcpp::STT_TLS
)
304 symval
.set_is_tls_symbol();
305 else if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
306 symval
.set_is_ifunc_symbol();
309 is_defined_in_discarded_section
=
310 (gsym
->is_defined_in_discarded_section()
311 && gsym
->is_undefined());
315 Symbol_value
<size
> symval2
;
316 if (is_defined_in_discarded_section
)
318 if (comdat_behavior
== CB_UNDETERMINED
)
320 std::string name
= object
->section_name(relinfo
->data_shndx
);
321 comdat_behavior
= get_comdat_behavior(name
.c_str());
323 if (comdat_behavior
== CB_PRETEND
)
325 // FIXME: This case does not work for global symbols.
326 // We have no place to store the original section index.
327 // Fortunately this does not matter for comdat sections,
328 // only for sections explicitly discarded by a linker
331 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
=
332 object
->map_to_kept_section(shndx
, &found
);
334 symval2
.set_output_value(value
+ psymval
->input_value());
336 symval2
.set_output_value(0);
340 if (comdat_behavior
== CB_WARNING
)
341 gold_warning_at_location(relinfo
, i
, offset
,
342 _("relocation refers to discarded "
344 symval2
.set_output_value(0);
346 symval2
.set_no_output_symtab_entry();
350 if (!relocate
.relocate(relinfo
, target
, output_section
, i
, reloc
,
351 r_type
, sym
, psymval
, view
+ offset
,
352 view_address
+ offset
, view_size
))
355 if (offset
< 0 || static_cast<section_size_type
>(offset
) >= view_size
)
357 gold_error_at_location(relinfo
, i
, offset
,
358 _("reloc has bad offset %zu"),
359 static_cast<size_t>(offset
));
363 if (issue_undefined_symbol_error(sym
))
364 gold_undefined_symbol_at_location(sym
, relinfo
, i
, offset
);
366 && sym
->visibility() != elfcpp::STV_DEFAULT
367 && (sym
->is_undefined() || sym
->is_from_dynobj()))
368 visibility_error(sym
);
370 if (sym
!= NULL
&& sym
->has_warning())
371 relinfo
->symtab
->issue_warning(sym
, relinfo
, i
, offset
);
375 // Apply an incremental relocation.
377 template<int size
, bool big_endian
, typename Target_type
,
380 apply_relocation(const Relocate_info
<size
, big_endian
>* relinfo
,
382 typename
elfcpp::Elf_types
<size
>::Elf_Addr r_offset
,
384 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
,
387 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
388 section_size_type view_size
)
390 // Construct the ELF relocation in a temporary buffer.
391 const int reloc_size
= elfcpp::Elf_sizes
<64>::rela_size
;
392 unsigned char relbuf
[reloc_size
];
393 elfcpp::Rela
<64, false> rel(relbuf
);
394 elfcpp::Rela_write
<64, false> orel(relbuf
);
395 orel
.put_r_offset(r_offset
);
396 orel
.put_r_info(elfcpp::elf_r_info
<64>(0, r_type
));
397 orel
.put_r_addend(r_addend
);
399 // Setup a Symbol_value for the global symbol.
400 const Sized_symbol
<64>* sym
= static_cast<const Sized_symbol
<64>*>(gsym
);
401 Symbol_value
<64> symval
;
402 gold_assert(sym
->has_symtab_index() && sym
->symtab_index() != -1U);
403 symval
.set_output_symtab_index(sym
->symtab_index());
404 symval
.set_output_value(sym
->value());
405 if (gsym
->type() == elfcpp::STT_TLS
)
406 symval
.set_is_tls_symbol();
407 else if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
408 symval
.set_is_ifunc_symbol();
411 relocate
.relocate(relinfo
, target
, NULL
, -1U, rel
, r_type
, sym
, &symval
,
412 view
+ r_offset
, address
+ r_offset
, view_size
);
415 // This class may be used as a typical class for the
416 // Scan_relocatable_reloc parameter to scan_relocatable_relocs. The
417 // template parameter Classify_reloc must be a class type which
418 // provides a function get_size_for_reloc which returns the number of
419 // bytes to which a reloc applies. This class is intended to capture
420 // the most typical target behaviour, while still permitting targets
421 // to define their own independent class for Scan_relocatable_reloc.
423 template<int sh_type
, typename Classify_reloc
>
424 class Default_scan_relocatable_relocs
427 // Return the strategy to use for a local symbol which is not a
428 // section symbol, given the relocation type.
429 inline Relocatable_relocs::Reloc_strategy
430 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
432 // We assume that relocation type 0 is NONE. Targets which are
433 // different must override.
434 if (r_type
== 0 && r_sym
== 0)
435 return Relocatable_relocs::RELOC_DISCARD
;
436 return Relocatable_relocs::RELOC_COPY
;
439 // Return the strategy to use for a local symbol which is a section
440 // symbol, given the relocation type.
441 inline Relocatable_relocs::Reloc_strategy
442 local_section_strategy(unsigned int r_type
, Relobj
* object
)
444 if (sh_type
== elfcpp::SHT_RELA
)
445 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
448 Classify_reloc classify
;
449 switch (classify
.get_size_for_reloc(r_type
, object
))
452 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
;
454 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1
;
456 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2
;
458 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4
;
460 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8
;
467 // Return the strategy to use for a global symbol, given the
468 // relocation type, the object, and the symbol index.
469 inline Relocatable_relocs::Reloc_strategy
470 global_strategy(unsigned int, Relobj
*, unsigned int)
471 { return Relocatable_relocs::RELOC_COPY
; }
474 // Scan relocs during a relocatable link. This is a default
475 // definition which should work for most targets.
476 // Scan_relocatable_reloc must name a class type which provides three
477 // functions which return a Relocatable_relocs::Reloc_strategy code:
478 // global_strategy, local_non_section_strategy, and
479 // local_section_strategy. Most targets should be able to use
480 // Default_scan_relocatable_relocs as this class.
482 template<int size
, bool big_endian
, int sh_type
,
483 typename Scan_relocatable_reloc
>
485 scan_relocatable_relocs(
488 Sized_relobj_file
<size
, big_endian
>* object
,
489 unsigned int data_shndx
,
490 const unsigned char* prelocs
,
492 Output_section
* output_section
,
493 bool needs_special_offset_handling
,
494 size_t local_symbol_count
,
495 const unsigned char* plocal_syms
,
496 Relocatable_relocs
* rr
)
498 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
499 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
500 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
501 Scan_relocatable_reloc scan
;
503 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
505 Reltype
reloc(prelocs
);
507 Relocatable_relocs::Reloc_strategy strategy
;
509 if (needs_special_offset_handling
510 && !output_section
->is_input_address_mapped(object
, data_shndx
,
511 reloc
.get_r_offset()))
512 strategy
= Relocatable_relocs::RELOC_DISCARD
;
515 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
=
517 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
518 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
520 if (r_sym
>= local_symbol_count
)
521 strategy
= scan
.global_strategy(r_type
, object
, r_sym
);
524 gold_assert(plocal_syms
!= NULL
);
525 typename
elfcpp::Sym
<size
, big_endian
> lsym(plocal_syms
527 unsigned int shndx
= lsym
.get_st_shndx();
529 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
531 && shndx
!= elfcpp::SHN_UNDEF
532 && !object
->is_section_included(shndx
))
534 // RELOC is a relocation against a local symbol
535 // defined in a section we are discarding. Discard
536 // the reloc. FIXME: Should we issue a warning?
537 strategy
= Relocatable_relocs::RELOC_DISCARD
;
539 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
540 strategy
= scan
.local_non_section_strategy(r_type
, object
,
544 strategy
= scan
.local_section_strategy(r_type
, object
);
545 if (strategy
!= Relocatable_relocs::RELOC_DISCARD
)
546 object
->output_section(shndx
)->set_needs_symtab_index();
549 if (strategy
== Relocatable_relocs::RELOC_COPY
)
550 object
->set_must_have_output_symtab_entry(r_sym
);
554 rr
->set_next_reloc_strategy(strategy
);
558 // Relocate relocs during a relocatable link. This is a default
559 // definition which should work for most targets.
561 template<int size
, bool big_endian
, int sh_type
>
563 relocate_for_relocatable(
564 const Relocate_info
<size
, big_endian
>* relinfo
,
565 const unsigned char* prelocs
,
567 Output_section
* output_section
,
568 typename
elfcpp::Elf_types
<size
>::Elf_Addr offset_in_output_section
,
569 const Relocatable_relocs
* rr
,
571 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
572 section_size_type view_size
,
573 unsigned char* reloc_view
,
574 section_size_type reloc_view_size
)
576 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
577 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
578 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc_write
580 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
581 const Address invalid_address
= static_cast<Address
>(0) - 1;
583 Sized_relobj_file
<size
, big_endian
>* const object
= relinfo
->object
;
584 const unsigned int local_count
= object
->local_symbol_count();
586 unsigned char* pwrite
= reloc_view
;
588 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
590 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
591 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
594 if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
596 // Target wants to handle this relocation.
597 Sized_target
<size
, big_endian
>* target
=
598 parameters
->sized_target
<size
, big_endian
>();
599 target
->relocate_special_relocatable(relinfo
, sh_type
, prelocs
,
601 offset_in_output_section
,
604 pwrite
+= reloc_size
;
607 Reltype
reloc(prelocs
);
608 Reltype_write
reloc_write(pwrite
);
610 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
611 const unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
612 const unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
614 // Get the new symbol index.
616 unsigned int new_symndx
;
617 if (r_sym
< local_count
)
621 case Relocatable_relocs::RELOC_COPY
:
626 new_symndx
= object
->symtab_index(r_sym
);
627 gold_assert(new_symndx
!= -1U);
631 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
632 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
:
633 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1
:
634 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2
:
635 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4
:
636 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8
:
638 // We are adjusting a section symbol. We need to find
639 // the symbol table index of the section symbol for
640 // the output section corresponding to input section
641 // in which this symbol is defined.
642 gold_assert(r_sym
< local_count
);
645 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
646 gold_assert(is_ordinary
);
647 Output_section
* os
= object
->output_section(shndx
);
648 gold_assert(os
!= NULL
);
649 gold_assert(os
->needs_symtab_index());
650 new_symndx
= os
->symtab_index();
660 const Symbol
* gsym
= object
->global_symbol(r_sym
);
661 gold_assert(gsym
!= NULL
);
662 if (gsym
->is_forwarder())
663 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
665 gold_assert(gsym
->has_symtab_index());
666 new_symndx
= gsym
->symtab_index();
669 // Get the new offset--the location in the output section where
670 // this relocation should be applied.
672 Address offset
= reloc
.get_r_offset();
674 if (offset_in_output_section
!= invalid_address
)
675 new_offset
= offset
+ offset_in_output_section
;
678 section_offset_type sot_offset
=
679 convert_types
<section_offset_type
, Address
>(offset
);
680 section_offset_type new_sot_offset
=
681 output_section
->output_offset(object
, relinfo
->data_shndx
,
683 gold_assert(new_sot_offset
!= -1);
684 new_offset
= new_sot_offset
;
687 // In an object file, r_offset is an offset within the section.
688 // In an executable or dynamic object, generated by
689 // --emit-relocs, r_offset is an absolute address.
690 if (!parameters
->options().relocatable())
692 new_offset
+= view_address
;
693 if (offset_in_output_section
!= invalid_address
)
694 new_offset
-= offset_in_output_section
;
697 reloc_write
.put_r_offset(new_offset
);
698 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(new_symndx
, r_type
));
700 // Handle the reloc addend based on the strategy.
702 if (strategy
== Relocatable_relocs::RELOC_COPY
)
704 if (sh_type
== elfcpp::SHT_RELA
)
705 Reloc_types
<sh_type
, size
, big_endian
>::
706 copy_reloc_addend(&reloc_write
,
711 // The relocation uses a section symbol in the input file.
712 // We are adjusting it to use a section symbol in the output
713 // file. The input section symbol refers to some address in
714 // the input section. We need the relocation in the output
715 // file to refer to that same address. This adjustment to
716 // the addend is the same calculation we use for a simple
717 // absolute relocation for the input section symbol.
719 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
721 unsigned char* padd
= view
+ offset
;
724 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
726 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
;
727 addend
= Reloc_types
<sh_type
, size
, big_endian
>::
728 get_reloc_addend(&reloc
);
729 addend
= psymval
->value(object
, addend
);
730 Reloc_types
<sh_type
, size
, big_endian
>::
731 set_reloc_addend(&reloc_write
, addend
);
735 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0
:
738 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1
:
739 Relocate_functions
<size
, big_endian
>::rel8(padd
, object
,
743 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2
:
744 Relocate_functions
<size
, big_endian
>::rel16(padd
, object
,
748 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4
:
749 Relocate_functions
<size
, big_endian
>::rel32(padd
, object
,
753 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8
:
754 Relocate_functions
<size
, big_endian
>::rel64(padd
, object
,
763 pwrite
+= reloc_size
;
766 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
770 } // End namespace gold.
772 #endif // !defined(GOLD_TARGET_RELOC_H)