1 // target-reloc.h -- target specific relocation support -*- C++ -*-
3 #ifndef GOLD_TARGET_RELOC_H
4 #define GOLD_TARGET_RELOC_H
9 #include "reloc-types.h"
14 // This function implements the generic part of reloc scanning. This
15 // is an inline function which takes a class whose operator()
16 // implements the machine specific part of scanning. We do it this
17 // way to avoidmaking a function call for each relocation, and to
18 // avoid repeating the generic code for each target.
20 template<int size
, bool big_endian
, typename Target_type
, int sh_type
,
24 const General_options
& options
,
28 Sized_relobj
<size
, big_endian
>* object
,
29 const unsigned char* prelocs
,
32 const unsigned char* plocal_syms
,
35 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
36 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
37 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
40 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
42 Reltype
reloc(prelocs
);
44 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
45 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
46 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
48 if (r_sym
< local_count
)
50 assert(plocal_syms
!= NULL
);
51 typename
elfcpp::Sym
<size
, big_endian
> lsym(plocal_syms
53 const unsigned int shndx
= lsym
.get_st_shndx();
54 if (shndx
< elfcpp::SHN_LORESERVE
55 && shndx
!= elfcpp::SHN_UNDEF
56 && !object
->is_section_included(lsym
.get_st_shndx()))
58 // RELOC is a relocation against a local symbol in a
59 // section we are discarding. We can ignore this
60 // relocation. It will eventually become a reloc
61 // against the value zero.
63 // FIXME: We should issue a warning if this is an
64 // allocated section; is this the best place to do it?
66 // FIXME: The old GNU linker would in some cases look
67 // for the linkonce section which caused this section to
68 // be discarded, and, if the other section was the same
69 // size, change the reloc to refer to the other section.
70 // That seems risky and weird to me, and I don't know of
71 // any case where it is actually required.
76 scan
.local(options
, symtab
, layout
, target
, object
, reloc
, r_type
,
81 Symbol
* gsym
= global_syms
[r_sym
- local_count
];
83 if (gsym
->is_forwarder())
84 gsym
= symtab
->resolve_forwards(gsym
);
86 scan
.global(options
, symtab
, layout
, target
, object
, reloc
, r_type
,
92 // This function implements the generic part of relocation processing.
93 // This is an inline function which take a class whose operator()
94 // implements the machine specific part of relocation. We do it this
95 // way to avoid making a function call for each relocation, and to
96 // avoid repeating the generic relocation handling code for each
99 // SIZE is the ELF size: 32 or 64. BIG_ENDIAN is the endianness of
100 // the data. SH_TYPE is the section type: SHT_REL or SHT_RELA.
101 // RELOCATE implements operator() to do a relocation.
103 // PRELOCS points to the relocation data. RELOC_COUNT is the number
104 // of relocs. VIEW is the section data, VIEW_ADDRESS is its memory
105 // address, and VIEW_SIZE is the size.
107 template<int size
, bool big_endian
, typename Target_type
, int sh_type
,
111 const Relocate_info
<size
, big_endian
>* relinfo
,
113 const unsigned char* prelocs
,
116 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
119 typedef typename Reloc_types
<sh_type
, size
, big_endian
>::Reloc Reltype
;
120 const int reloc_size
= Reloc_types
<sh_type
, size
, big_endian
>::reloc_size
;
123 unsigned int local_count
= relinfo
->local_symbol_count
;
124 const typename Sized_relobj
<size
, big_endian
>::Local_values
* local_values
=
125 relinfo
->local_values
;
126 const Symbol
* const * global_syms
= relinfo
->symbols
;
128 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
130 Reltype
reloc(prelocs
);
132 off_t offset
= reloc
.get_r_offset();
134 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
135 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
136 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
138 const Sized_symbol
<size
>* sym
;
139 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
141 if (r_sym
< local_count
)
144 value
= (*local_values
)[r_sym
];
148 const Symbol
* gsym
= global_syms
[r_sym
- local_count
];
149 assert(gsym
!= NULL
);
150 if (gsym
->is_forwarder())
151 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
153 sym
= static_cast<const Sized_symbol
<size
>*>(gsym
);
154 value
= sym
->value();
157 if (!relocate
.relocate(relinfo
, target
, i
, reloc
, r_type
, sym
, value
,
158 view
+ offset
, view_address
+ offset
, view_size
))
161 if (offset
< 0 || offset
>= view_size
)
163 fprintf(stderr
, _("%s: %s: reloc has bad offset %zu\n"),
164 program_name
, relinfo
->location(i
, offset
).c_str(),
165 static_cast<size_t>(offset
));
170 && sym
->is_undefined()
171 && sym
->binding() != elfcpp::STB_WEAK
)
173 fprintf(stderr
, _("%s: %s: undefined reference to '%s'\n"),
174 program_name
, relinfo
->location(i
, offset
).c_str(),
179 if (sym
!= NULL
&& sym
->has_warning())
180 relinfo
->symtab
->issue_warning(sym
, relinfo
->location(i
, offset
));
184 } // End namespace gold.
186 #endif // !defined(GOLD_TARGET_RELOC_H)
This page took 0.037872 seconds and 4 git commands to generate.