PR 11108
[external/binutils.git] / gold / target-reloc.h
1 // target-reloc.h -- target specific relocation support  -*- C++ -*-
2
3 // Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #ifndef GOLD_TARGET_RELOC_H
24 #define GOLD_TARGET_RELOC_H
25
26 #include "elfcpp.h"
27 #include "symtab.h"
28 #include "object.h"
29 #include "reloc.h"
30 #include "reloc-types.h"
31
32 namespace gold
33 {
34
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 // avoidmaking a function call for each relocation, and to avoid
40 // repeating the generic code for each target.
41
42 template<int size, bool big_endian, typename Target_type, int sh_type,
43          typename Scan>
44 inline void
45 scan_relocs(
46     Symbol_table* symtab,
47     Layout* layout,
48     Target_type* target,
49     Sized_relobj<size, big_endian>* object,
50     unsigned int data_shndx,
51     const unsigned char* prelocs,
52     size_t reloc_count,
53     Output_section* output_section,
54     bool needs_special_offset_handling,
55     size_t local_count,
56     const unsigned char* plocal_syms)
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
67       if (needs_special_offset_handling
68           && !output_section->is_input_address_mapped(object, data_shndx,
69                                                       reloc.get_r_offset()))
70         continue;
71
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         {
78           gold_assert(plocal_syms != NULL);
79           typename elfcpp::Sym<size, big_endian> lsym(plocal_syms
80                                                       + r_sym * sym_size);
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
85               && shndx != elfcpp::SHN_UNDEF
86               && !object->is_section_included(shndx))
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
106           scan.local(symtab, layout, target, object, data_shndx,
107                      output_section, reloc, r_type, lsym);
108         }
109       else
110         {
111           Symbol* gsym = object->global_symbol(r_sym);
112           gold_assert(gsym != NULL);
113           if (gsym->is_forwarder())
114             gsym = symtab->resolve_forwards(gsym);
115
116           scan.global(symtab, layout, target, object, data_shndx,
117                       output_section, reloc, r_type, gsym);
118         }
119     }
120 }
121
122 // Behavior for relocations to discarded comdat sections.
123
124 enum 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
136 inline Comdat_behavior
137 get_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
147 // This function implements the generic part of relocation processing.
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.
151
152 // SIZE is the ELF size: 32 or 64.  BIG_ENDIAN is the endianness of
153 // the data.  SH_TYPE is the section type: SHT_REL or SHT_RELA.
154 // RELOCATE implements operator() to do a relocation.
155
156 // PRELOCS points to the relocation data.  RELOC_COUNT is the number
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.
165
166 // RELOC_SYMBOL_CHANGES is used for -fsplit-stack support.  If it is
167 // not NULL, it is a vector indexed by relocation index.  If that
168 // entry is not NULL, it points to a global symbol which used as the
169 // symbol for the relocation, ignoring the symbol index in the
170 // relocation.
171
172 template<int size, bool big_endian, typename Target_type, int sh_type,
173          typename Relocate>
174 inline void
175 relocate_section(
176     const Relocate_info<size, big_endian>* relinfo,
177     Target_type* target,
178     const unsigned char* prelocs,
179     size_t reloc_count,
180     Output_section* output_section,
181     bool needs_special_offset_handling,
182     unsigned char* view,
183     typename elfcpp::Elf_types<size>::Elf_Addr view_address,
184     section_size_type view_size,
185     const Reloc_symbol_changes* reloc_symbol_changes)
186 {
187   typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
188   const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
189   Relocate relocate;
190
191   Sized_relobj<size, big_endian>* object = relinfo->object;
192   unsigned int local_count = object->local_symbol_count();
193
194   Comdat_behavior comdat_behavior = CB_UNDETERMINED;
195
196   for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
197     {
198       Reltype reloc(prelocs);
199
200       section_offset_type offset =
201         convert_to_section_size_type(reloc.get_r_offset());
202
203       if (needs_special_offset_handling)
204         {
205           offset = output_section->output_offset(relinfo->object,
206                                                  relinfo->data_shndx,
207                                                  offset);
208           if (offset == -1)
209             continue;
210         }
211
212       typename elfcpp::Elf_types<size>::Elf_WXword r_info = reloc.get_r_info();
213       unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
214       unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
215
216       const Sized_symbol<size>* sym;
217
218       Symbol_value<size> symval;
219       const Symbol_value<size> *psymval;
220       bool is_defined_in_discarded_section;
221       unsigned int shndx;
222       if (r_sym < local_count
223           && (reloc_symbol_changes == NULL
224               || (*reloc_symbol_changes)[i] == NULL))
225         {
226           sym = NULL;
227           psymval = object->local_symbol(r_sym);
228
229           // If the local symbol belongs to a section we are discarding,
230           // and that section is a debug section, try to find the
231           // corresponding kept section and map this symbol to its
232           // counterpart in the kept section.  The symbol must not 
233           // correspond to a section we are folding.
234           bool is_ordinary;
235           shndx = psymval->input_shndx(&is_ordinary);
236           is_defined_in_discarded_section =
237             (is_ordinary
238              && shndx != elfcpp::SHN_UNDEF
239              && !object->is_section_included(shndx)
240              && !relinfo->symtab->is_section_folded(object, shndx));
241         }
242       else
243         {
244           const Symbol* gsym;
245           if (reloc_symbol_changes != NULL
246               && (*reloc_symbol_changes)[i] != NULL)
247             gsym = (*reloc_symbol_changes)[i];
248           else
249             {
250               gsym = object->global_symbol(r_sym);
251               gold_assert(gsym != NULL);
252               if (gsym->is_forwarder())
253                 gsym = relinfo->symtab->resolve_forwards(gsym);
254             }
255
256           sym = static_cast<const Sized_symbol<size>*>(gsym);
257           if (sym->has_symtab_index())
258             symval.set_output_symtab_index(sym->symtab_index());
259           else
260             symval.set_no_output_symtab_entry();
261           symval.set_output_value(sym->value());
262           psymval = &symval;
263
264           is_defined_in_discarded_section =
265             (gsym->is_defined_in_discarded_section()
266              && gsym->is_undefined());
267           shndx = 0;
268         }
269
270       Symbol_value<size> symval2;
271       if (is_defined_in_discarded_section)
272         {
273           if (comdat_behavior == CB_UNDETERMINED)
274             {
275               std::string name = object->section_name(relinfo->data_shndx);
276               comdat_behavior = get_comdat_behavior(name.c_str());
277             }
278           if (comdat_behavior == CB_PRETEND)
279             {
280               // FIXME: This case does not work for global symbols.
281               // We have no place to store the original section index.
282               // Fortunately this does not matter for comdat sections,
283               // only for sections explicitly discarded by a linker
284               // script.
285               bool found;
286               typename elfcpp::Elf_types<size>::Elf_Addr value =
287                 object->map_to_kept_section(shndx, &found);
288               if (found)
289                 symval2.set_output_value(value + psymval->input_value());
290               else
291                 symval2.set_output_value(0);
292             }
293           else
294             {
295               if (comdat_behavior == CB_WARNING)
296                 gold_warning_at_location(relinfo, i, offset,
297                                          _("relocation refers to discarded "
298                                            "section"));
299               symval2.set_output_value(0);
300             }
301           symval2.set_no_output_symtab_entry();
302           psymval = &symval2;
303         }
304
305       if (!relocate.relocate(relinfo, target, output_section, i, reloc,
306                              r_type, sym, psymval, view + offset,
307                              view_address + offset, view_size))
308         continue;
309
310       if (offset < 0 || static_cast<section_size_type>(offset) >= view_size)
311         {
312           gold_error_at_location(relinfo, i, offset,
313                                  _("reloc has bad offset %zu"),
314                                  static_cast<size_t>(offset));
315           continue;
316         }
317
318       if (sym != NULL
319           && sym->is_undefined()
320           && sym->binding() != elfcpp::STB_WEAK
321           && !is_defined_in_discarded_section
322           && !target->is_defined_by_abi(sym)
323           && (!parameters->options().shared()       // -shared
324               || parameters->options().defs()))     // -z defs
325         gold_undefined_symbol_at_location(sym, relinfo, i, offset);
326
327       if (sym != NULL && sym->has_warning())
328         relinfo->symtab->issue_warning(sym, relinfo, i, offset);
329     }
330 }
331
332 // This class may be used as a typical class for the
333 // Scan_relocatable_reloc parameter to scan_relocatable_relocs.  The
334 // template parameter Classify_reloc must be a class type which
335 // provides a function get_size_for_reloc which returns the number of
336 // bytes to which a reloc applies.  This class is intended to capture
337 // the most typical target behaviour, while still permitting targets
338 // to define their own independent class for Scan_relocatable_reloc.
339
340 template<int sh_type, typename Classify_reloc>
341 class Default_scan_relocatable_relocs
342 {
343  public:
344   // Return the strategy to use for a local symbol which is not a
345   // section symbol, given the relocation type.
346   inline Relocatable_relocs::Reloc_strategy
347   local_non_section_strategy(unsigned int r_type, Relobj*, unsigned int r_sym)
348   {
349     // We assume that relocation type 0 is NONE.  Targets which are
350     // different must override.
351     if (r_type == 0 && r_sym == 0)
352       return Relocatable_relocs::RELOC_DISCARD;
353     return Relocatable_relocs::RELOC_COPY;
354   }
355
356   // Return the strategy to use for a local symbol which is a section
357   // symbol, given the relocation type.
358   inline Relocatable_relocs::Reloc_strategy
359   local_section_strategy(unsigned int r_type, Relobj* object)
360   {
361     if (sh_type == elfcpp::SHT_RELA)
362       return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA;
363     else
364       {
365         Classify_reloc classify;
366         switch (classify.get_size_for_reloc(r_type, object))
367           {
368           case 0:
369             return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0;
370           case 1:
371             return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1;
372           case 2:
373             return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2;
374           case 4:
375             return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4;
376           case 8:
377             return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8;
378           default:
379             gold_unreachable();
380           }
381       }
382   }
383
384   // Return the strategy to use for a global symbol, given the
385   // relocation type, the object, and the symbol index.
386   inline Relocatable_relocs::Reloc_strategy
387   global_strategy(unsigned int, Relobj*, unsigned int)
388   { return Relocatable_relocs::RELOC_COPY; }
389 };
390
391 // Scan relocs during a relocatable link.  This is a default
392 // definition which should work for most targets.
393 // Scan_relocatable_reloc must name a class type which provides three
394 // functions which return a Relocatable_relocs::Reloc_strategy code:
395 // global_strategy, local_non_section_strategy, and
396 // local_section_strategy.  Most targets should be able to use
397 // Default_scan_relocatable_relocs as this class.
398
399 template<int size, bool big_endian, int sh_type,
400          typename Scan_relocatable_reloc>
401 void
402 scan_relocatable_relocs(
403     Symbol_table*,
404     Layout*,
405     Sized_relobj<size, big_endian>* object,
406     unsigned int data_shndx,
407     const unsigned char* prelocs,
408     size_t reloc_count,
409     Output_section* output_section,
410     bool needs_special_offset_handling,
411     size_t local_symbol_count,
412     const unsigned char* plocal_syms,
413     Relocatable_relocs* rr)
414 {
415   typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
416   const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
417   const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
418   Scan_relocatable_reloc scan;
419
420   for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
421     {
422       Reltype reloc(prelocs);
423
424       Relocatable_relocs::Reloc_strategy strategy;
425
426       if (needs_special_offset_handling
427           && !output_section->is_input_address_mapped(object, data_shndx,
428                                                       reloc.get_r_offset()))
429         strategy = Relocatable_relocs::RELOC_DISCARD;
430       else
431         {
432           typename elfcpp::Elf_types<size>::Elf_WXword r_info =
433             reloc.get_r_info();
434           const unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
435           const unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
436
437           if (r_sym >= local_symbol_count)
438             strategy = scan.global_strategy(r_type, object, r_sym);
439           else
440             {
441               gold_assert(plocal_syms != NULL);
442               typename elfcpp::Sym<size, big_endian> lsym(plocal_syms
443                                                           + r_sym * sym_size);
444               unsigned int shndx = lsym.get_st_shndx();
445               bool is_ordinary;
446               shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
447               if (is_ordinary
448                   && shndx != elfcpp::SHN_UNDEF
449                   && !object->is_section_included(shndx))
450                 {
451                   // RELOC is a relocation against a local symbol
452                   // defined in a section we are discarding.  Discard
453                   // the reloc.  FIXME: Should we issue a warning?
454                   strategy = Relocatable_relocs::RELOC_DISCARD;
455                 }
456               else if (lsym.get_st_type() != elfcpp::STT_SECTION)
457                 strategy = scan.local_non_section_strategy(r_type, object,
458                                                            r_sym);
459               else
460                 {
461                   strategy = scan.local_section_strategy(r_type, object);
462                   if (strategy != Relocatable_relocs::RELOC_DISCARD)
463                     object->output_section(shndx)->set_needs_symtab_index();
464                 }
465             }
466         }
467
468       rr->set_next_reloc_strategy(strategy);
469     }
470 }
471
472 // Relocate relocs during a relocatable link.  This is a default
473 // definition which should work for most targets.
474
475 template<int size, bool big_endian, int sh_type>
476 void
477 relocate_for_relocatable(
478     const Relocate_info<size, big_endian>* relinfo,
479     const unsigned char* prelocs,
480     size_t reloc_count,
481     Output_section* output_section,
482     typename elfcpp::Elf_types<size>::Elf_Addr offset_in_output_section,
483     const Relocatable_relocs* rr,
484     unsigned char* view,
485     typename elfcpp::Elf_types<size>::Elf_Addr view_address,
486     section_size_type,
487     unsigned char* reloc_view,
488     section_size_type reloc_view_size)
489 {
490   typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
491   typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
492   typedef typename Reloc_types<sh_type, size, big_endian>::Reloc_write
493     Reltype_write;
494   const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
495   const Address invalid_address = static_cast<Address>(0) - 1;
496
497   Sized_relobj<size, big_endian>* const object = relinfo->object;
498   const unsigned int local_count = object->local_symbol_count();
499
500   unsigned char* pwrite = reloc_view;
501
502   for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
503     {
504       Relocatable_relocs::Reloc_strategy strategy = rr->strategy(i);
505       if (strategy == Relocatable_relocs::RELOC_DISCARD)
506         continue;
507
508       Reltype reloc(prelocs);
509       Reltype_write reloc_write(pwrite);
510
511       typename elfcpp::Elf_types<size>::Elf_WXword r_info = reloc.get_r_info();
512       const unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
513       const unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
514
515       // Get the new symbol index.
516
517       unsigned int new_symndx;
518       if (r_sym < local_count)
519         {
520           switch (strategy)
521             {
522             case Relocatable_relocs::RELOC_COPY:
523               if (r_sym == 0)
524                 new_symndx = 0;
525               else
526                 {
527                   new_symndx = object->symtab_index(r_sym);
528                   gold_assert(new_symndx != -1U);
529                 }
530               break;
531
532             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA:
533             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0:
534             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1:
535             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2:
536             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4:
537             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8:
538               {
539                 // We are adjusting a section symbol.  We need to find
540                 // the symbol table index of the section symbol for
541                 // the output section corresponding to input section
542                 // in which this symbol is defined.
543                 gold_assert(r_sym < local_count);
544                 bool is_ordinary;
545                 unsigned int shndx =
546                   object->local_symbol_input_shndx(r_sym, &is_ordinary);
547                 gold_assert(is_ordinary);
548                 Output_section* os = object->output_section(shndx);
549                 gold_assert(os != NULL);
550                 gold_assert(os->needs_symtab_index());
551                 new_symndx = os->symtab_index();
552               }
553               break;
554
555             default:
556               gold_unreachable();
557             }
558         }
559       else
560         {
561           const Symbol* gsym = object->global_symbol(r_sym);
562           gold_assert(gsym != NULL);
563           if (gsym->is_forwarder())
564             gsym = relinfo->symtab->resolve_forwards(gsym);
565
566           gold_assert(gsym->has_symtab_index());
567           new_symndx = gsym->symtab_index();
568         }
569
570       // Get the new offset--the location in the output section where
571       // this relocation should be applied.
572
573       Address offset = reloc.get_r_offset();
574       Address new_offset;
575       if (offset_in_output_section != invalid_address)
576         new_offset = offset + offset_in_output_section;
577       else
578         {
579           section_offset_type sot_offset =
580               convert_types<section_offset_type, Address>(offset);
581           section_offset_type new_sot_offset =
582               output_section->output_offset(object, relinfo->data_shndx,
583                                             sot_offset);
584           gold_assert(new_sot_offset != -1);
585           new_offset = new_sot_offset;
586         }
587
588       // In an object file, r_offset is an offset within the section.
589       // In an executable or dynamic object, generated by
590       // --emit-relocs, r_offset is an absolute address.
591       if (!parameters->options().relocatable())
592         {
593           new_offset += view_address;
594           if (offset_in_output_section != invalid_address)
595             new_offset -= offset_in_output_section;
596         }
597
598       reloc_write.put_r_offset(new_offset);
599       reloc_write.put_r_info(elfcpp::elf_r_info<size>(new_symndx, r_type));
600
601       // Handle the reloc addend based on the strategy.
602
603       if (strategy == Relocatable_relocs::RELOC_COPY)
604         {
605           if (sh_type == elfcpp::SHT_RELA)
606             Reloc_types<sh_type, size, big_endian>::
607               copy_reloc_addend(&reloc_write,
608                                 &reloc);
609         }
610       else
611         {
612           // The relocation uses a section symbol in the input file.
613           // We are adjusting it to use a section symbol in the output
614           // file.  The input section symbol refers to some address in
615           // the input section.  We need the relocation in the output
616           // file to refer to that same address.  This adjustment to
617           // the addend is the same calculation we use for a simple
618           // absolute relocation for the input section symbol.
619
620           const Symbol_value<size>* psymval = object->local_symbol(r_sym);
621
622           unsigned char* padd = view + offset;
623           switch (strategy)
624             {
625             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA:
626               {
627                 typename elfcpp::Elf_types<size>::Elf_Swxword addend;
628                 addend = Reloc_types<sh_type, size, big_endian>::
629                            get_reloc_addend(&reloc);
630                 addend = psymval->value(object, addend);
631                 Reloc_types<sh_type, size, big_endian>::
632                   set_reloc_addend(&reloc_write, addend);
633               }
634               break;
635
636             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0:
637               break;
638
639             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_1:
640               Relocate_functions<size, big_endian>::rel8(padd, object,
641                                                          psymval);
642               break;
643
644             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_2:
645               Relocate_functions<size, big_endian>::rel16(padd, object,
646                                                           psymval);
647               break;
648
649             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4:
650               Relocate_functions<size, big_endian>::rel32(padd, object,
651                                                           psymval);
652               break;
653
654             case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_8:
655               Relocate_functions<size, big_endian>::rel64(padd, object,
656                                                           psymval);
657               break;
658
659             default:
660               gold_unreachable();
661             }
662         }
663
664       pwrite += reloc_size;
665     }
666
667   gold_assert(static_cast<section_size_type>(pwrite - reloc_view)
668               == reloc_view_size);
669 }
670
671 } // End namespace gold.
672
673 #endif // !defined(GOLD_TARGET_RELOC_H)