]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* PowerPC-specific support for 32-bit ELF |
b491616a | 2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
7898deda | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Ian Lance Taylor, Cygnus Support. |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | /* This file is based on a preliminary PowerPC ELF ABI. The | |
23 | information may not match the final PowerPC ELF ABI. It includes | |
24 | suggestions from the in-progress Embedded PowerPC ABI, and that | |
25 | information may also not match. */ | |
26 | ||
27 | #include "bfd.h" | |
28 | #include "sysdep.h" | |
29 | #include "bfdlink.h" | |
30 | #include "libbfd.h" | |
31 | #include "elf-bfd.h" | |
32 | #include "elf/ppc.h" | |
33 | ||
f0fe0e16 | 34 | /* RELA relocations are used here. */ |
252b5132 | 35 | |
252b5132 RH |
36 | static reloc_howto_type *ppc_elf_reloc_type_lookup |
37 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
38 | static void ppc_elf_info_to_howto | |
947216bf | 39 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)); |
b34976b6 AM |
40 | static void ppc_elf_howto_init |
41 | PARAMS ((void)); | |
42 | static int ppc_elf_sort_rela | |
43 | PARAMS ((const PTR, const PTR)); | |
44 | static bfd_boolean ppc_elf_relax_section | |
45 | PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *)); | |
252b5132 RH |
46 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
47 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
b34976b6 AM |
48 | static bfd_boolean ppc_elf_object_p |
49 | PARAMS ((bfd *)); | |
50 | static bfd_boolean ppc_elf_set_private_flags | |
51 | PARAMS ((bfd *, flagword)); | |
52 | static bfd_boolean ppc_elf_merge_private_bfd_data | |
53 | PARAMS ((bfd *, bfd *)); | |
54 | static int ppc_elf_additional_program_headers | |
55 | PARAMS ((bfd *)); | |
56 | static bfd_boolean ppc_elf_modify_segment_map | |
57 | PARAMS ((bfd *)); | |
41fcb14e AM |
58 | static asection *ppc_elf_create_got |
59 | PARAMS ((bfd *, struct bfd_link_info *)); | |
b34976b6 | 60 | static bfd_boolean ppc_elf_create_dynamic_sections |
252b5132 | 61 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 AM |
62 | static bfd_boolean ppc_elf_section_from_shdr |
63 | PARAMS ((bfd *, Elf_Internal_Shdr *, const char *)); | |
64 | static bfd_boolean ppc_elf_fake_sections | |
947216bf | 65 | PARAMS ((bfd *, Elf_Internal_Shdr *, asection *)); |
252b5132 | 66 | static elf_linker_section_t *ppc_elf_create_linker_section |
b34976b6 | 67 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
252b5132 | 68 | enum elf_linker_section_enum)); |
b34976b6 AM |
69 | static bfd_boolean ppc_elf_check_relocs |
70 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
71 | const Elf_Internal_Rela *)); | |
72 | static asection * ppc_elf_gc_mark_hook | |
73 | PARAMS ((asection *sec, struct bfd_link_info *info, Elf_Internal_Rela *rel, | |
74 | struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)); | |
75 | static bfd_boolean ppc_elf_gc_sweep_hook | |
76 | PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec, | |
77 | const Elf_Internal_Rela *relocs)); | |
78 | static bfd_boolean ppc_elf_adjust_dynamic_symbol | |
79 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
80 | static bfd_boolean ppc_elf_size_dynamic_sections | |
81 | PARAMS ((bfd *, struct bfd_link_info *)); | |
82 | static bfd_boolean ppc_elf_relocate_section | |
83 | PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *, | |
84 | Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, | |
85 | asection **)); | |
86 | static bfd_boolean ppc_elf_add_symbol_hook | |
87 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, | |
88 | const char **, flagword *, asection **, bfd_vma *)); | |
89 | static bfd_boolean ppc_elf_finish_dynamic_symbol | |
90 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
91 | Elf_Internal_Sym *)); | |
92 | static bfd_boolean ppc_elf_finish_dynamic_sections | |
93 | PARAMS ((bfd *, struct bfd_link_info *)); | |
f51e552e AM |
94 | static enum elf_reloc_type_class ppc_elf_reloc_type_class |
95 | PARAMS ((const Elf_Internal_Rela *)); | |
b34976b6 | 96 | static bfd_boolean ppc_elf_grok_prstatus |
2e67030c | 97 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); |
b34976b6 | 98 | static bfd_boolean ppc_elf_grok_psinfo |
2e67030c | 99 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); |
252b5132 RH |
100 | |
101 | #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */ | |
102 | #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */ | |
103 | #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */ | |
104 | ||
105 | /* The name of the dynamic interpreter. This is put in the .interp | |
106 | section. */ | |
107 | ||
108 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
109 | ||
110 | /* The size in bytes of an entry in the procedure linkage table. */ | |
111 | #define PLT_ENTRY_SIZE 12 | |
112 | /* The initial size of the plt reserved for the dynamic linker. */ | |
113 | #define PLT_INITIAL_ENTRY_SIZE 72 | |
114 | /* The size of the gap between entries in the PLT. */ | |
115 | #define PLT_SLOT_SIZE 8 | |
116 | /* The number of single-slot PLT entries (the rest use two slots). */ | |
117 | #define PLT_NUM_SINGLE_ENTRIES 8192 | |
118 | ||
e1e0340b GK |
119 | /* Will references to this symbol always reference the symbol |
120 | in this object? */ | |
121 | #define SYMBOL_REFERENCES_LOCAL(INFO, H) \ | |
122 | ((! INFO->shared \ | |
123 | || INFO->symbolic \ | |
124 | || H->dynindx == -1 \ | |
125 | || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \ | |
126 | || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \ | |
127 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0) | |
128 | ||
129 | /* Will _calls_ to this symbol always call the version in this object? */ | |
130 | #define SYMBOL_CALLS_LOCAL(INFO, H) \ | |
131 | ((! INFO->shared \ | |
132 | || INFO->symbolic \ | |
133 | || H->dynindx == -1 \ | |
134 | || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \ | |
135 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0) | |
252b5132 | 136 | \f |
8da6118f | 137 | static reloc_howto_type *ppc_elf_howto_table[(int) R_PPC_max]; |
252b5132 | 138 | |
8da6118f | 139 | static reloc_howto_type ppc_elf_howto_raw[] = { |
252b5132 RH |
140 | /* This reloc does nothing. */ |
141 | HOWTO (R_PPC_NONE, /* type */ | |
142 | 0, /* rightshift */ | |
143 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
144 | 32, /* bitsize */ | |
b34976b6 | 145 | FALSE, /* pc_relative */ |
252b5132 RH |
146 | 0, /* bitpos */ |
147 | complain_overflow_bitfield, /* complain_on_overflow */ | |
148 | bfd_elf_generic_reloc, /* special_function */ | |
149 | "R_PPC_NONE", /* name */ | |
b34976b6 | 150 | FALSE, /* partial_inplace */ |
252b5132 RH |
151 | 0, /* src_mask */ |
152 | 0, /* dst_mask */ | |
b34976b6 | 153 | FALSE), /* pcrel_offset */ |
252b5132 RH |
154 | |
155 | /* A standard 32 bit relocation. */ | |
156 | HOWTO (R_PPC_ADDR32, /* type */ | |
157 | 0, /* rightshift */ | |
158 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
159 | 32, /* bitsize */ | |
b34976b6 | 160 | FALSE, /* pc_relative */ |
252b5132 RH |
161 | 0, /* bitpos */ |
162 | complain_overflow_bitfield, /* complain_on_overflow */ | |
163 | bfd_elf_generic_reloc, /* special_function */ | |
164 | "R_PPC_ADDR32", /* name */ | |
b34976b6 | 165 | FALSE, /* partial_inplace */ |
252b5132 RH |
166 | 0, /* src_mask */ |
167 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 168 | FALSE), /* pcrel_offset */ |
252b5132 RH |
169 | |
170 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
171 | FIXME: we don't check that, we just clear them. */ | |
172 | HOWTO (R_PPC_ADDR24, /* type */ | |
173 | 0, /* rightshift */ | |
174 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
175 | 26, /* bitsize */ | |
b34976b6 | 176 | FALSE, /* pc_relative */ |
252b5132 RH |
177 | 0, /* bitpos */ |
178 | complain_overflow_bitfield, /* complain_on_overflow */ | |
179 | bfd_elf_generic_reloc, /* special_function */ | |
180 | "R_PPC_ADDR24", /* name */ | |
b34976b6 | 181 | FALSE, /* partial_inplace */ |
252b5132 RH |
182 | 0, /* src_mask */ |
183 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 184 | FALSE), /* pcrel_offset */ |
252b5132 RH |
185 | |
186 | /* A standard 16 bit relocation. */ | |
187 | HOWTO (R_PPC_ADDR16, /* type */ | |
188 | 0, /* rightshift */ | |
189 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
190 | 16, /* bitsize */ | |
b34976b6 | 191 | FALSE, /* pc_relative */ |
252b5132 RH |
192 | 0, /* bitpos */ |
193 | complain_overflow_bitfield, /* complain_on_overflow */ | |
194 | bfd_elf_generic_reloc, /* special_function */ | |
195 | "R_PPC_ADDR16", /* name */ | |
b34976b6 | 196 | FALSE, /* partial_inplace */ |
252b5132 RH |
197 | 0, /* src_mask */ |
198 | 0xffff, /* dst_mask */ | |
b34976b6 | 199 | FALSE), /* pcrel_offset */ |
252b5132 RH |
200 | |
201 | /* A 16 bit relocation without overflow. */ | |
202 | HOWTO (R_PPC_ADDR16_LO, /* type */ | |
203 | 0, /* rightshift */ | |
204 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
205 | 16, /* bitsize */ | |
b34976b6 | 206 | FALSE, /* pc_relative */ |
252b5132 RH |
207 | 0, /* bitpos */ |
208 | complain_overflow_dont,/* complain_on_overflow */ | |
209 | bfd_elf_generic_reloc, /* special_function */ | |
210 | "R_PPC_ADDR16_LO", /* name */ | |
b34976b6 | 211 | FALSE, /* partial_inplace */ |
252b5132 RH |
212 | 0, /* src_mask */ |
213 | 0xffff, /* dst_mask */ | |
b34976b6 | 214 | FALSE), /* pcrel_offset */ |
252b5132 RH |
215 | |
216 | /* The high order 16 bits of an address. */ | |
217 | HOWTO (R_PPC_ADDR16_HI, /* type */ | |
218 | 16, /* rightshift */ | |
219 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
220 | 16, /* bitsize */ | |
b34976b6 | 221 | FALSE, /* pc_relative */ |
252b5132 RH |
222 | 0, /* bitpos */ |
223 | complain_overflow_dont, /* complain_on_overflow */ | |
224 | bfd_elf_generic_reloc, /* special_function */ | |
225 | "R_PPC_ADDR16_HI", /* name */ | |
b34976b6 | 226 | FALSE, /* partial_inplace */ |
252b5132 RH |
227 | 0, /* src_mask */ |
228 | 0xffff, /* dst_mask */ | |
b34976b6 | 229 | FALSE), /* pcrel_offset */ |
252b5132 RH |
230 | |
231 | /* The high order 16 bits of an address, plus 1 if the contents of | |
8da6118f | 232 | the low 16 bits, treated as a signed number, is negative. */ |
252b5132 RH |
233 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
234 | 16, /* rightshift */ | |
235 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
236 | 16, /* bitsize */ | |
b34976b6 | 237 | FALSE, /* pc_relative */ |
252b5132 RH |
238 | 0, /* bitpos */ |
239 | complain_overflow_dont, /* complain_on_overflow */ | |
240 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
241 | "R_PPC_ADDR16_HA", /* name */ | |
b34976b6 | 242 | FALSE, /* partial_inplace */ |
252b5132 RH |
243 | 0, /* src_mask */ |
244 | 0xffff, /* dst_mask */ | |
b34976b6 | 245 | FALSE), /* pcrel_offset */ |
252b5132 RH |
246 | |
247 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
248 | FIXME: we don't check that, we just clear them. */ | |
249 | HOWTO (R_PPC_ADDR14, /* type */ | |
250 | 0, /* rightshift */ | |
251 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
252 | 16, /* bitsize */ | |
b34976b6 | 253 | FALSE, /* pc_relative */ |
252b5132 RH |
254 | 0, /* bitpos */ |
255 | complain_overflow_bitfield, /* complain_on_overflow */ | |
256 | bfd_elf_generic_reloc, /* special_function */ | |
257 | "R_PPC_ADDR14", /* name */ | |
b34976b6 | 258 | FALSE, /* partial_inplace */ |
252b5132 RH |
259 | 0, /* src_mask */ |
260 | 0xfffc, /* dst_mask */ | |
b34976b6 | 261 | FALSE), /* pcrel_offset */ |
252b5132 RH |
262 | |
263 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
264 | indicate that the branch is expected to be taken. The lower two | |
8da6118f | 265 | bits must be zero. */ |
252b5132 RH |
266 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
267 | 0, /* rightshift */ | |
268 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
269 | 16, /* bitsize */ | |
b34976b6 | 270 | FALSE, /* pc_relative */ |
252b5132 RH |
271 | 0, /* bitpos */ |
272 | complain_overflow_bitfield, /* complain_on_overflow */ | |
273 | bfd_elf_generic_reloc, /* special_function */ | |
274 | "R_PPC_ADDR14_BRTAKEN",/* name */ | |
b34976b6 | 275 | FALSE, /* partial_inplace */ |
252b5132 RH |
276 | 0, /* src_mask */ |
277 | 0xfffc, /* dst_mask */ | |
b34976b6 | 278 | FALSE), /* pcrel_offset */ |
252b5132 RH |
279 | |
280 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
281 | indicate that the branch is not expected to be taken. The lower | |
282 | two bits must be zero. */ | |
283 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
284 | 0, /* rightshift */ | |
285 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
286 | 16, /* bitsize */ | |
b34976b6 | 287 | FALSE, /* pc_relative */ |
252b5132 RH |
288 | 0, /* bitpos */ |
289 | complain_overflow_bitfield, /* complain_on_overflow */ | |
290 | bfd_elf_generic_reloc, /* special_function */ | |
291 | "R_PPC_ADDR14_BRNTAKEN",/* name */ | |
b34976b6 | 292 | FALSE, /* partial_inplace */ |
252b5132 RH |
293 | 0, /* src_mask */ |
294 | 0xfffc, /* dst_mask */ | |
b34976b6 | 295 | FALSE), /* pcrel_offset */ |
252b5132 | 296 | |
8da6118f | 297 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
298 | HOWTO (R_PPC_REL24, /* type */ |
299 | 0, /* rightshift */ | |
300 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
301 | 26, /* bitsize */ | |
b34976b6 | 302 | TRUE, /* pc_relative */ |
252b5132 RH |
303 | 0, /* bitpos */ |
304 | complain_overflow_signed, /* complain_on_overflow */ | |
305 | bfd_elf_generic_reloc, /* special_function */ | |
306 | "R_PPC_REL24", /* name */ | |
b34976b6 | 307 | FALSE, /* partial_inplace */ |
252b5132 RH |
308 | 0, /* src_mask */ |
309 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 310 | TRUE), /* pcrel_offset */ |
252b5132 | 311 | |
8da6118f | 312 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
313 | HOWTO (R_PPC_REL14, /* type */ |
314 | 0, /* rightshift */ | |
315 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
316 | 16, /* bitsize */ | |
b34976b6 | 317 | TRUE, /* pc_relative */ |
252b5132 RH |
318 | 0, /* bitpos */ |
319 | complain_overflow_signed, /* complain_on_overflow */ | |
320 | bfd_elf_generic_reloc, /* special_function */ | |
321 | "R_PPC_REL14", /* name */ | |
b34976b6 | 322 | FALSE, /* partial_inplace */ |
252b5132 RH |
323 | 0, /* src_mask */ |
324 | 0xfffc, /* dst_mask */ | |
b34976b6 | 325 | TRUE), /* pcrel_offset */ |
252b5132 | 326 | |
8da6118f | 327 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
328 | the branch is expected to be taken. The lower two bits must be |
329 | zero. */ | |
330 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ | |
331 | 0, /* rightshift */ | |
332 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
333 | 16, /* bitsize */ | |
b34976b6 | 334 | TRUE, /* pc_relative */ |
252b5132 RH |
335 | 0, /* bitpos */ |
336 | complain_overflow_signed, /* complain_on_overflow */ | |
337 | bfd_elf_generic_reloc, /* special_function */ | |
338 | "R_PPC_REL14_BRTAKEN", /* name */ | |
b34976b6 | 339 | FALSE, /* partial_inplace */ |
252b5132 RH |
340 | 0, /* src_mask */ |
341 | 0xfffc, /* dst_mask */ | |
b34976b6 | 342 | TRUE), /* pcrel_offset */ |
252b5132 | 343 | |
8da6118f | 344 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
345 | the branch is not expected to be taken. The lower two bits must |
346 | be zero. */ | |
347 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ | |
348 | 0, /* rightshift */ | |
349 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
350 | 16, /* bitsize */ | |
b34976b6 | 351 | TRUE, /* pc_relative */ |
252b5132 RH |
352 | 0, /* bitpos */ |
353 | complain_overflow_signed, /* complain_on_overflow */ | |
354 | bfd_elf_generic_reloc, /* special_function */ | |
355 | "R_PPC_REL14_BRNTAKEN",/* name */ | |
b34976b6 | 356 | FALSE, /* partial_inplace */ |
252b5132 RH |
357 | 0, /* src_mask */ |
358 | 0xfffc, /* dst_mask */ | |
b34976b6 | 359 | TRUE), /* pcrel_offset */ |
252b5132 RH |
360 | |
361 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
362 | symbol. */ | |
363 | HOWTO (R_PPC_GOT16, /* type */ | |
364 | 0, /* rightshift */ | |
365 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
366 | 16, /* bitsize */ | |
b34976b6 | 367 | FALSE, /* pc_relative */ |
252b5132 RH |
368 | 0, /* bitpos */ |
369 | complain_overflow_signed, /* complain_on_overflow */ | |
370 | bfd_elf_generic_reloc, /* special_function */ | |
371 | "R_PPC_GOT16", /* name */ | |
b34976b6 | 372 | FALSE, /* partial_inplace */ |
252b5132 RH |
373 | 0, /* src_mask */ |
374 | 0xffff, /* dst_mask */ | |
b34976b6 | 375 | FALSE), /* pcrel_offset */ |
252b5132 RH |
376 | |
377 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
378 | the symbol. */ | |
379 | HOWTO (R_PPC_GOT16_LO, /* type */ | |
380 | 0, /* rightshift */ | |
381 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
382 | 16, /* bitsize */ | |
b34976b6 | 383 | FALSE, /* pc_relative */ |
252b5132 RH |
384 | 0, /* bitpos */ |
385 | complain_overflow_dont, /* complain_on_overflow */ | |
386 | bfd_elf_generic_reloc, /* special_function */ | |
387 | "R_PPC_GOT16_LO", /* name */ | |
b34976b6 | 388 | FALSE, /* partial_inplace */ |
252b5132 RH |
389 | 0, /* src_mask */ |
390 | 0xffff, /* dst_mask */ | |
b34976b6 | 391 | FALSE), /* pcrel_offset */ |
252b5132 RH |
392 | |
393 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
394 | the symbol. */ | |
395 | HOWTO (R_PPC_GOT16_HI, /* type */ | |
396 | 16, /* rightshift */ | |
397 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
398 | 16, /* bitsize */ | |
b34976b6 | 399 | FALSE, /* pc_relative */ |
252b5132 RH |
400 | 0, /* bitpos */ |
401 | complain_overflow_bitfield, /* complain_on_overflow */ | |
402 | bfd_elf_generic_reloc, /* special_function */ | |
403 | "R_PPC_GOT16_HI", /* name */ | |
b34976b6 | 404 | FALSE, /* partial_inplace */ |
252b5132 RH |
405 | 0, /* src_mask */ |
406 | 0xffff, /* dst_mask */ | |
b34976b6 | 407 | FALSE), /* pcrel_offset */ |
252b5132 RH |
408 | |
409 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
410 | the symbol. */ | |
411 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
412 | 16, /* rightshift */ | |
413 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
414 | 16, /* bitsize */ | |
b34976b6 | 415 | FALSE, /* pc_relative */ |
252b5132 RH |
416 | 0, /* bitpos */ |
417 | complain_overflow_bitfield, /* complain_on_overflow */ | |
418 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
419 | "R_PPC_GOT16_HA", /* name */ | |
b34976b6 | 420 | FALSE, /* partial_inplace */ |
252b5132 RH |
421 | 0, /* src_mask */ |
422 | 0xffff, /* dst_mask */ | |
b34976b6 | 423 | FALSE), /* pcrel_offset */ |
252b5132 RH |
424 | |
425 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
426 | entry for the symbol. */ | |
427 | HOWTO (R_PPC_PLTREL24, /* type */ | |
428 | 0, /* rightshift */ | |
429 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
430 | 26, /* bitsize */ | |
b34976b6 | 431 | TRUE, /* pc_relative */ |
252b5132 RH |
432 | 0, /* bitpos */ |
433 | complain_overflow_signed, /* complain_on_overflow */ | |
434 | bfd_elf_generic_reloc, /* special_function */ | |
435 | "R_PPC_PLTREL24", /* name */ | |
b34976b6 | 436 | FALSE, /* partial_inplace */ |
252b5132 RH |
437 | 0, /* src_mask */ |
438 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 439 | TRUE), /* pcrel_offset */ |
252b5132 RH |
440 | |
441 | /* This is used only by the dynamic linker. The symbol should exist | |
442 | both in the object being run and in some shared library. The | |
443 | dynamic linker copies the data addressed by the symbol from the | |
444 | shared library into the object, because the object being | |
445 | run has to have the data at some particular address. */ | |
446 | HOWTO (R_PPC_COPY, /* type */ | |
447 | 0, /* rightshift */ | |
448 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
449 | 32, /* bitsize */ | |
b34976b6 | 450 | FALSE, /* pc_relative */ |
252b5132 RH |
451 | 0, /* bitpos */ |
452 | complain_overflow_bitfield, /* complain_on_overflow */ | |
453 | bfd_elf_generic_reloc, /* special_function */ | |
454 | "R_PPC_COPY", /* name */ | |
b34976b6 | 455 | FALSE, /* partial_inplace */ |
252b5132 RH |
456 | 0, /* src_mask */ |
457 | 0, /* dst_mask */ | |
b34976b6 | 458 | FALSE), /* pcrel_offset */ |
252b5132 RH |
459 | |
460 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
461 | entries. */ | |
462 | HOWTO (R_PPC_GLOB_DAT, /* type */ | |
463 | 0, /* rightshift */ | |
464 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
465 | 32, /* bitsize */ | |
b34976b6 | 466 | FALSE, /* pc_relative */ |
252b5132 RH |
467 | 0, /* bitpos */ |
468 | complain_overflow_bitfield, /* complain_on_overflow */ | |
469 | bfd_elf_generic_reloc, /* special_function */ | |
470 | "R_PPC_GLOB_DAT", /* name */ | |
b34976b6 | 471 | FALSE, /* partial_inplace */ |
252b5132 RH |
472 | 0, /* src_mask */ |
473 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 474 | FALSE), /* pcrel_offset */ |
252b5132 RH |
475 | |
476 | /* Marks a procedure linkage table entry for a symbol. */ | |
477 | HOWTO (R_PPC_JMP_SLOT, /* type */ | |
478 | 0, /* rightshift */ | |
479 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
480 | 32, /* bitsize */ | |
b34976b6 | 481 | FALSE, /* pc_relative */ |
252b5132 RH |
482 | 0, /* bitpos */ |
483 | complain_overflow_bitfield, /* complain_on_overflow */ | |
484 | bfd_elf_generic_reloc, /* special_function */ | |
485 | "R_PPC_JMP_SLOT", /* name */ | |
b34976b6 | 486 | FALSE, /* partial_inplace */ |
252b5132 RH |
487 | 0, /* src_mask */ |
488 | 0, /* dst_mask */ | |
b34976b6 | 489 | FALSE), /* pcrel_offset */ |
252b5132 RH |
490 | |
491 | /* Used only by the dynamic linker. When the object is run, this | |
492 | longword is set to the load address of the object, plus the | |
493 | addend. */ | |
494 | HOWTO (R_PPC_RELATIVE, /* type */ | |
495 | 0, /* rightshift */ | |
496 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
497 | 32, /* bitsize */ | |
b34976b6 | 498 | FALSE, /* pc_relative */ |
252b5132 RH |
499 | 0, /* bitpos */ |
500 | complain_overflow_bitfield, /* complain_on_overflow */ | |
501 | bfd_elf_generic_reloc, /* special_function */ | |
502 | "R_PPC_RELATIVE", /* name */ | |
b34976b6 | 503 | FALSE, /* partial_inplace */ |
252b5132 RH |
504 | 0, /* src_mask */ |
505 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 506 | FALSE), /* pcrel_offset */ |
252b5132 RH |
507 | |
508 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
509 | object rather than the final value. Normally used for | |
510 | _GLOBAL_OFFSET_TABLE_. */ | |
511 | HOWTO (R_PPC_LOCAL24PC, /* type */ | |
512 | 0, /* rightshift */ | |
513 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
514 | 26, /* bitsize */ | |
b34976b6 | 515 | TRUE, /* pc_relative */ |
252b5132 RH |
516 | 0, /* bitpos */ |
517 | complain_overflow_signed, /* complain_on_overflow */ | |
518 | bfd_elf_generic_reloc, /* special_function */ | |
519 | "R_PPC_LOCAL24PC", /* name */ | |
b34976b6 | 520 | FALSE, /* partial_inplace */ |
252b5132 RH |
521 | 0, /* src_mask */ |
522 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 523 | TRUE), /* pcrel_offset */ |
252b5132 RH |
524 | |
525 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
526 | HOWTO (R_PPC_UADDR32, /* type */ | |
527 | 0, /* rightshift */ | |
528 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
529 | 32, /* bitsize */ | |
b34976b6 | 530 | FALSE, /* pc_relative */ |
252b5132 RH |
531 | 0, /* bitpos */ |
532 | complain_overflow_bitfield, /* complain_on_overflow */ | |
533 | bfd_elf_generic_reloc, /* special_function */ | |
534 | "R_PPC_UADDR32", /* name */ | |
b34976b6 | 535 | FALSE, /* partial_inplace */ |
252b5132 RH |
536 | 0, /* src_mask */ |
537 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 538 | FALSE), /* pcrel_offset */ |
252b5132 RH |
539 | |
540 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
541 | HOWTO (R_PPC_UADDR16, /* type */ | |
542 | 0, /* rightshift */ | |
543 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
544 | 16, /* bitsize */ | |
b34976b6 | 545 | FALSE, /* pc_relative */ |
252b5132 RH |
546 | 0, /* bitpos */ |
547 | complain_overflow_bitfield, /* complain_on_overflow */ | |
548 | bfd_elf_generic_reloc, /* special_function */ | |
549 | "R_PPC_UADDR16", /* name */ | |
b34976b6 | 550 | FALSE, /* partial_inplace */ |
252b5132 RH |
551 | 0, /* src_mask */ |
552 | 0xffff, /* dst_mask */ | |
b34976b6 | 553 | FALSE), /* pcrel_offset */ |
252b5132 RH |
554 | |
555 | /* 32-bit PC relative */ | |
556 | HOWTO (R_PPC_REL32, /* type */ | |
557 | 0, /* rightshift */ | |
558 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
559 | 32, /* bitsize */ | |
b34976b6 | 560 | TRUE, /* pc_relative */ |
252b5132 RH |
561 | 0, /* bitpos */ |
562 | complain_overflow_bitfield, /* complain_on_overflow */ | |
563 | bfd_elf_generic_reloc, /* special_function */ | |
564 | "R_PPC_REL32", /* name */ | |
b34976b6 | 565 | FALSE, /* partial_inplace */ |
252b5132 RH |
566 | 0, /* src_mask */ |
567 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 568 | TRUE), /* pcrel_offset */ |
252b5132 RH |
569 | |
570 | /* 32-bit relocation to the symbol's procedure linkage table. | |
c3668558 | 571 | FIXME: not supported. */ |
252b5132 RH |
572 | HOWTO (R_PPC_PLT32, /* type */ |
573 | 0, /* rightshift */ | |
574 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
575 | 32, /* bitsize */ | |
b34976b6 | 576 | FALSE, /* pc_relative */ |
252b5132 RH |
577 | 0, /* bitpos */ |
578 | complain_overflow_bitfield, /* complain_on_overflow */ | |
579 | bfd_elf_generic_reloc, /* special_function */ | |
580 | "R_PPC_PLT32", /* name */ | |
b34976b6 | 581 | FALSE, /* partial_inplace */ |
252b5132 RH |
582 | 0, /* src_mask */ |
583 | 0, /* dst_mask */ | |
b34976b6 | 584 | FALSE), /* pcrel_offset */ |
252b5132 RH |
585 | |
586 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
c3668558 | 587 | FIXME: not supported. */ |
252b5132 RH |
588 | HOWTO (R_PPC_PLTREL32, /* type */ |
589 | 0, /* rightshift */ | |
590 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
591 | 32, /* bitsize */ | |
b34976b6 | 592 | TRUE, /* pc_relative */ |
252b5132 RH |
593 | 0, /* bitpos */ |
594 | complain_overflow_bitfield, /* complain_on_overflow */ | |
595 | bfd_elf_generic_reloc, /* special_function */ | |
596 | "R_PPC_PLTREL32", /* name */ | |
b34976b6 | 597 | FALSE, /* partial_inplace */ |
252b5132 RH |
598 | 0, /* src_mask */ |
599 | 0, /* dst_mask */ | |
b34976b6 | 600 | TRUE), /* pcrel_offset */ |
252b5132 RH |
601 | |
602 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
603 | the symbol. */ | |
604 | HOWTO (R_PPC_PLT16_LO, /* type */ | |
605 | 0, /* rightshift */ | |
606 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
607 | 16, /* bitsize */ | |
b34976b6 | 608 | FALSE, /* pc_relative */ |
252b5132 RH |
609 | 0, /* bitpos */ |
610 | complain_overflow_dont, /* complain_on_overflow */ | |
611 | bfd_elf_generic_reloc, /* special_function */ | |
612 | "R_PPC_PLT16_LO", /* name */ | |
b34976b6 | 613 | FALSE, /* partial_inplace */ |
252b5132 RH |
614 | 0, /* src_mask */ |
615 | 0xffff, /* dst_mask */ | |
b34976b6 | 616 | FALSE), /* pcrel_offset */ |
252b5132 RH |
617 | |
618 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
619 | the symbol. */ | |
620 | HOWTO (R_PPC_PLT16_HI, /* type */ | |
621 | 16, /* rightshift */ | |
622 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
623 | 16, /* bitsize */ | |
b34976b6 | 624 | FALSE, /* pc_relative */ |
252b5132 RH |
625 | 0, /* bitpos */ |
626 | complain_overflow_bitfield, /* complain_on_overflow */ | |
627 | bfd_elf_generic_reloc, /* special_function */ | |
628 | "R_PPC_PLT16_HI", /* name */ | |
b34976b6 | 629 | FALSE, /* partial_inplace */ |
252b5132 RH |
630 | 0, /* src_mask */ |
631 | 0xffff, /* dst_mask */ | |
b34976b6 | 632 | FALSE), /* pcrel_offset */ |
252b5132 RH |
633 | |
634 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
635 | the symbol. */ | |
636 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
637 | 16, /* rightshift */ | |
638 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
639 | 16, /* bitsize */ | |
b34976b6 | 640 | FALSE, /* pc_relative */ |
252b5132 RH |
641 | 0, /* bitpos */ |
642 | complain_overflow_bitfield, /* complain_on_overflow */ | |
643 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
644 | "R_PPC_PLT16_HA", /* name */ | |
b34976b6 | 645 | FALSE, /* partial_inplace */ |
252b5132 RH |
646 | 0, /* src_mask */ |
647 | 0xffff, /* dst_mask */ | |
b34976b6 | 648 | FALSE), /* pcrel_offset */ |
252b5132 RH |
649 | |
650 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with | |
651 | small data items. */ | |
652 | HOWTO (R_PPC_SDAREL16, /* type */ | |
653 | 0, /* rightshift */ | |
654 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
655 | 16, /* bitsize */ | |
b34976b6 | 656 | FALSE, /* pc_relative */ |
252b5132 RH |
657 | 0, /* bitpos */ |
658 | complain_overflow_signed, /* complain_on_overflow */ | |
659 | bfd_elf_generic_reloc, /* special_function */ | |
660 | "R_PPC_SDAREL16", /* name */ | |
b34976b6 | 661 | FALSE, /* partial_inplace */ |
252b5132 RH |
662 | 0, /* src_mask */ |
663 | 0xffff, /* dst_mask */ | |
b34976b6 | 664 | FALSE), /* pcrel_offset */ |
252b5132 | 665 | |
c061c2d8 | 666 | /* 16-bit section relative relocation. */ |
252b5132 RH |
667 | HOWTO (R_PPC_SECTOFF, /* type */ |
668 | 0, /* rightshift */ | |
c061c2d8 AM |
669 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
670 | 16, /* bitsize */ | |
b34976b6 | 671 | FALSE, /* pc_relative */ |
252b5132 RH |
672 | 0, /* bitpos */ |
673 | complain_overflow_bitfield, /* complain_on_overflow */ | |
674 | bfd_elf_generic_reloc, /* special_function */ | |
675 | "R_PPC_SECTOFF", /* name */ | |
b34976b6 | 676 | FALSE, /* partial_inplace */ |
252b5132 | 677 | 0, /* src_mask */ |
c061c2d8 | 678 | 0xffff, /* dst_mask */ |
b34976b6 | 679 | FALSE), /* pcrel_offset */ |
252b5132 | 680 | |
c3668558 | 681 | /* 16-bit lower half section relative relocation. */ |
252b5132 RH |
682 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
683 | 0, /* rightshift */ | |
684 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
685 | 16, /* bitsize */ | |
b34976b6 | 686 | FALSE, /* pc_relative */ |
252b5132 RH |
687 | 0, /* bitpos */ |
688 | complain_overflow_dont, /* complain_on_overflow */ | |
689 | bfd_elf_generic_reloc, /* special_function */ | |
690 | "R_PPC_SECTOFF_LO", /* name */ | |
b34976b6 | 691 | FALSE, /* partial_inplace */ |
252b5132 RH |
692 | 0, /* src_mask */ |
693 | 0xffff, /* dst_mask */ | |
b34976b6 | 694 | FALSE), /* pcrel_offset */ |
252b5132 | 695 | |
c3668558 | 696 | /* 16-bit upper half section relative relocation. */ |
252b5132 RH |
697 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
698 | 16, /* rightshift */ | |
699 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
700 | 16, /* bitsize */ | |
b34976b6 | 701 | FALSE, /* pc_relative */ |
252b5132 RH |
702 | 0, /* bitpos */ |
703 | complain_overflow_bitfield, /* complain_on_overflow */ | |
704 | bfd_elf_generic_reloc, /* special_function */ | |
705 | "R_PPC_SECTOFF_HI", /* name */ | |
b34976b6 | 706 | FALSE, /* partial_inplace */ |
252b5132 RH |
707 | 0, /* src_mask */ |
708 | 0xffff, /* dst_mask */ | |
b34976b6 | 709 | FALSE), /* pcrel_offset */ |
252b5132 | 710 | |
c3668558 | 711 | /* 16-bit upper half adjusted section relative relocation. */ |
252b5132 RH |
712 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
713 | 16, /* rightshift */ | |
714 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
715 | 16, /* bitsize */ | |
b34976b6 | 716 | FALSE, /* pc_relative */ |
252b5132 RH |
717 | 0, /* bitpos */ |
718 | complain_overflow_bitfield, /* complain_on_overflow */ | |
719 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
720 | "R_PPC_SECTOFF_HA", /* name */ | |
b34976b6 | 721 | FALSE, /* partial_inplace */ |
252b5132 RH |
722 | 0, /* src_mask */ |
723 | 0xffff, /* dst_mask */ | |
b34976b6 | 724 | FALSE), /* pcrel_offset */ |
252b5132 RH |
725 | |
726 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
727 | in the SVR4 ELF ABI. */ | |
728 | ||
729 | /* 32 bit value resulting from the addend minus the symbol */ | |
730 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
731 | 0, /* rightshift */ | |
732 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
733 | 32, /* bitsize */ | |
b34976b6 | 734 | FALSE, /* pc_relative */ |
252b5132 RH |
735 | 0, /* bitpos */ |
736 | complain_overflow_bitfield, /* complain_on_overflow */ | |
737 | bfd_elf_generic_reloc, /* special_function */ | |
738 | "R_PPC_EMB_NADDR32", /* name */ | |
b34976b6 | 739 | FALSE, /* partial_inplace */ |
252b5132 RH |
740 | 0, /* src_mask */ |
741 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 742 | FALSE), /* pcrel_offset */ |
252b5132 RH |
743 | |
744 | /* 16 bit value resulting from the addend minus the symbol */ | |
745 | HOWTO (R_PPC_EMB_NADDR16, /* type */ | |
746 | 0, /* rightshift */ | |
747 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
748 | 16, /* bitsize */ | |
b34976b6 | 749 | FALSE, /* pc_relative */ |
252b5132 RH |
750 | 0, /* bitpos */ |
751 | complain_overflow_bitfield, /* complain_on_overflow */ | |
752 | bfd_elf_generic_reloc, /* special_function */ | |
753 | "R_PPC_EMB_NADDR16", /* name */ | |
b34976b6 | 754 | FALSE, /* partial_inplace */ |
252b5132 RH |
755 | 0, /* src_mask */ |
756 | 0xffff, /* dst_mask */ | |
b34976b6 | 757 | FALSE), /* pcrel_offset */ |
252b5132 RH |
758 | |
759 | /* 16 bit value resulting from the addend minus the symbol */ | |
760 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
761 | 0, /* rightshift */ | |
762 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
763 | 16, /* bitsize */ | |
b34976b6 | 764 | FALSE, /* pc_relative */ |
252b5132 RH |
765 | 0, /* bitpos */ |
766 | complain_overflow_dont,/* complain_on_overflow */ | |
767 | bfd_elf_generic_reloc, /* special_function */ | |
768 | "R_PPC_EMB_ADDR16_LO", /* name */ | |
b34976b6 | 769 | FALSE, /* partial_inplace */ |
252b5132 RH |
770 | 0, /* src_mask */ |
771 | 0xffff, /* dst_mask */ | |
b34976b6 | 772 | FALSE), /* pcrel_offset */ |
252b5132 RH |
773 | |
774 | /* The high order 16 bits of the addend minus the symbol */ | |
775 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
776 | 16, /* rightshift */ | |
777 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
778 | 16, /* bitsize */ | |
b34976b6 | 779 | FALSE, /* pc_relative */ |
252b5132 RH |
780 | 0, /* bitpos */ |
781 | complain_overflow_dont, /* complain_on_overflow */ | |
782 | bfd_elf_generic_reloc, /* special_function */ | |
783 | "R_PPC_EMB_NADDR16_HI", /* name */ | |
b34976b6 | 784 | FALSE, /* partial_inplace */ |
252b5132 RH |
785 | 0, /* src_mask */ |
786 | 0xffff, /* dst_mask */ | |
b34976b6 | 787 | FALSE), /* pcrel_offset */ |
252b5132 RH |
788 | |
789 | /* The high order 16 bits of the result of the addend minus the address, | |
790 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
791 | is negative. */ | |
792 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ | |
793 | 16, /* rightshift */ | |
794 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
795 | 16, /* bitsize */ | |
b34976b6 | 796 | FALSE, /* pc_relative */ |
252b5132 RH |
797 | 0, /* bitpos */ |
798 | complain_overflow_dont, /* complain_on_overflow */ | |
799 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
800 | "R_PPC_EMB_NADDR16_HA", /* name */ | |
b34976b6 | 801 | FALSE, /* partial_inplace */ |
252b5132 RH |
802 | 0, /* src_mask */ |
803 | 0xffff, /* dst_mask */ | |
b34976b6 | 804 | FALSE), /* pcrel_offset */ |
252b5132 RH |
805 | |
806 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
807 | address in the .sdata section, and returning the offset from | |
808 | _SDA_BASE_ for that relocation */ | |
809 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
810 | 0, /* rightshift */ | |
811 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
812 | 16, /* bitsize */ | |
b34976b6 | 813 | FALSE, /* pc_relative */ |
252b5132 RH |
814 | 0, /* bitpos */ |
815 | complain_overflow_bitfield, /* complain_on_overflow */ | |
816 | bfd_elf_generic_reloc, /* special_function */ | |
817 | "R_PPC_EMB_SDAI16", /* name */ | |
b34976b6 | 818 | FALSE, /* partial_inplace */ |
252b5132 RH |
819 | 0, /* src_mask */ |
820 | 0xffff, /* dst_mask */ | |
b34976b6 | 821 | FALSE), /* pcrel_offset */ |
252b5132 RH |
822 | |
823 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
824 | address in the .sdata2 section, and returning the offset from | |
825 | _SDA2_BASE_ for that relocation */ | |
826 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
827 | 0, /* rightshift */ | |
828 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
829 | 16, /* bitsize */ | |
b34976b6 | 830 | FALSE, /* pc_relative */ |
252b5132 RH |
831 | 0, /* bitpos */ |
832 | complain_overflow_bitfield, /* complain_on_overflow */ | |
833 | bfd_elf_generic_reloc, /* special_function */ | |
834 | "R_PPC_EMB_SDA2I16", /* name */ | |
b34976b6 | 835 | FALSE, /* partial_inplace */ |
252b5132 RH |
836 | 0, /* src_mask */ |
837 | 0xffff, /* dst_mask */ | |
b34976b6 | 838 | FALSE), /* pcrel_offset */ |
252b5132 RH |
839 | |
840 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
841 | small data items. */ | |
842 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
843 | 0, /* rightshift */ | |
844 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
845 | 16, /* bitsize */ | |
b34976b6 | 846 | FALSE, /* pc_relative */ |
252b5132 RH |
847 | 0, /* bitpos */ |
848 | complain_overflow_signed, /* complain_on_overflow */ | |
849 | bfd_elf_generic_reloc, /* special_function */ | |
850 | "R_PPC_EMB_SDA2REL", /* name */ | |
b34976b6 | 851 | FALSE, /* partial_inplace */ |
252b5132 RH |
852 | 0, /* src_mask */ |
853 | 0xffff, /* dst_mask */ | |
b34976b6 | 854 | FALSE), /* pcrel_offset */ |
252b5132 RH |
855 | |
856 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
857 | signed offset from the appropriate base, and filling in the register | |
858 | field with the appropriate register (0, 2, or 13). */ | |
859 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
860 | 0, /* rightshift */ | |
861 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
862 | 16, /* bitsize */ | |
b34976b6 | 863 | FALSE, /* pc_relative */ |
252b5132 RH |
864 | 0, /* bitpos */ |
865 | complain_overflow_signed, /* complain_on_overflow */ | |
866 | bfd_elf_generic_reloc, /* special_function */ | |
867 | "R_PPC_EMB_SDA21", /* name */ | |
b34976b6 | 868 | FALSE, /* partial_inplace */ |
252b5132 RH |
869 | 0, /* src_mask */ |
870 | 0xffff, /* dst_mask */ | |
b34976b6 | 871 | FALSE), /* pcrel_offset */ |
252b5132 RH |
872 | |
873 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
874 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
875 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
876 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
877 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
878 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
879 | ||
880 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
881 | in the 16 bit signed offset from the appropriate base, and filling in the | |
882 | register field with the appropriate register (0, 2, or 13). */ | |
883 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
884 | 0, /* rightshift */ | |
885 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
886 | 16, /* bitsize */ | |
b34976b6 | 887 | TRUE, /* pc_relative */ |
252b5132 RH |
888 | 0, /* bitpos */ |
889 | complain_overflow_signed, /* complain_on_overflow */ | |
890 | bfd_elf_generic_reloc, /* special_function */ | |
891 | "R_PPC_EMB_RELSDA", /* name */ | |
b34976b6 | 892 | FALSE, /* partial_inplace */ |
252b5132 RH |
893 | 0, /* src_mask */ |
894 | 0xffff, /* dst_mask */ | |
b34976b6 | 895 | FALSE), /* pcrel_offset */ |
252b5132 RH |
896 | |
897 | /* GNU extension to record C++ vtable hierarchy */ | |
898 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ | |
899 | 0, /* rightshift */ | |
900 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
901 | 0, /* bitsize */ | |
b34976b6 | 902 | FALSE, /* pc_relative */ |
252b5132 RH |
903 | 0, /* bitpos */ |
904 | complain_overflow_dont, /* complain_on_overflow */ | |
905 | NULL, /* special_function */ | |
906 | "R_PPC_GNU_VTINHERIT", /* name */ | |
b34976b6 | 907 | FALSE, /* partial_inplace */ |
252b5132 RH |
908 | 0, /* src_mask */ |
909 | 0, /* dst_mask */ | |
b34976b6 | 910 | FALSE), /* pcrel_offset */ |
252b5132 RH |
911 | |
912 | /* GNU extension to record C++ vtable member usage */ | |
913 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ | |
914 | 0, /* rightshift */ | |
915 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
916 | 0, /* bitsize */ | |
b34976b6 | 917 | FALSE, /* pc_relative */ |
252b5132 RH |
918 | 0, /* bitpos */ |
919 | complain_overflow_dont, /* complain_on_overflow */ | |
920 | NULL, /* special_function */ | |
921 | "R_PPC_GNU_VTENTRY", /* name */ | |
b34976b6 | 922 | FALSE, /* partial_inplace */ |
252b5132 RH |
923 | 0, /* src_mask */ |
924 | 0, /* dst_mask */ | |
b34976b6 | 925 | FALSE), /* pcrel_offset */ |
252b5132 RH |
926 | |
927 | /* Phony reloc to handle AIX style TOC entries */ | |
928 | HOWTO (R_PPC_TOC16, /* type */ | |
929 | 0, /* rightshift */ | |
930 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
931 | 16, /* bitsize */ | |
b34976b6 | 932 | FALSE, /* pc_relative */ |
252b5132 RH |
933 | 0, /* bitpos */ |
934 | complain_overflow_signed, /* complain_on_overflow */ | |
935 | bfd_elf_generic_reloc, /* special_function */ | |
936 | "R_PPC_TOC16", /* name */ | |
b34976b6 | 937 | FALSE, /* partial_inplace */ |
252b5132 RH |
938 | 0, /* src_mask */ |
939 | 0xffff, /* dst_mask */ | |
b34976b6 | 940 | FALSE), /* pcrel_offset */ |
252b5132 | 941 | }; |
252b5132 RH |
942 | \f |
943 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
944 | ||
945 | static void | |
946 | ppc_elf_howto_init () | |
947 | { | |
948 | unsigned int i, type; | |
949 | ||
950 | for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++) | |
951 | { | |
952 | type = ppc_elf_howto_raw[i].type; | |
c3668558 | 953 | BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0])); |
252b5132 RH |
954 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; |
955 | } | |
956 | } | |
252b5132 RH |
957 | \f |
958 | /* This function handles relaxing for the PPC with option --mpc860c0[=<n>]. | |
959 | ||
960 | The MPC860, revision C0 or earlier contains a bug in the die. | |
b34976b6 | 961 | If all of the following conditions are TRUE, the next instruction |
252b5132 RH |
962 | to be executed *may* be treated as a no-op. |
963 | 1/ A forward branch is executed. | |
964 | 2/ The branch is predicted as not taken. | |
965 | 3/ The branch is taken. | |
966 | 4/ The branch is located in the last 5 words of a page. | |
967 | (The EOP limit is 5 by default but may be specified as any value from 1-10.) | |
c3668558 | 968 | |
252b5132 RH |
969 | Our software solution is to detect these problematic branches in a |
970 | linker pass and modify them as follows: | |
971 | 1/ Unconditional branches - Since these are always predicted taken, | |
972 | there is no problem and no action is required. | |
973 | 2/ Conditional backward branches - No problem, no action required. | |
974 | 3/ Conditional forward branches - Ensure that the "inverse prediction | |
975 | bit" is set (ensure it is predicted taken). | |
976 | 4/ Conditional register branches - Ensure that the "y bit" is set | |
977 | (ensure it is predicted taken). | |
978 | */ | |
979 | ||
980 | /* Sort sections by address. */ | |
981 | ||
982 | static int | |
983 | ppc_elf_sort_rela (arg1, arg2) | |
a7b97311 AM |
984 | const PTR arg1; |
985 | const PTR arg2; | |
252b5132 RH |
986 | { |
987 | const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1; | |
988 | const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2; | |
989 | ||
c3668558 | 990 | /* Sort by offset. */ |
252b5132 RH |
991 | return ((*rela1)->r_offset - (*rela2)->r_offset); |
992 | } | |
993 | ||
b34976b6 | 994 | static bfd_boolean |
252b5132 | 995 | ppc_elf_relax_section (abfd, isec, link_info, again) |
8da6118f KH |
996 | bfd *abfd; |
997 | asection *isec; | |
998 | struct bfd_link_info *link_info; | |
b34976b6 | 999 | bfd_boolean *again; |
252b5132 RH |
1000 | { |
1001 | #define PAGESIZE 0x1000 | |
1002 | ||
1003 | bfd_byte *contents = NULL; | |
1004 | bfd_byte *free_contents = NULL; | |
1005 | Elf_Internal_Rela *internal_relocs = NULL; | |
1006 | Elf_Internal_Rela *free_relocs = NULL; | |
1007 | Elf_Internal_Rela **rela_comb = NULL; | |
1008 | int comb_curr, comb_count; | |
1009 | ||
c3668558 | 1010 | /* We never have to do this more than once per input section. */ |
b34976b6 | 1011 | *again = FALSE; |
252b5132 RH |
1012 | |
1013 | /* If needed, initialize this section's cooked size. */ | |
1014 | if (isec->_cooked_size == 0) | |
1015 | isec->_cooked_size = isec->_raw_size; | |
1016 | ||
1017 | /* We're only interested in text sections which overlap the | |
8da6118f | 1018 | troublesome area at the end of a page. */ |
252b5132 RH |
1019 | if (link_info->mpc860c0 && (isec->flags & SEC_CODE) && isec->_cooked_size) |
1020 | { | |
1021 | bfd_vma dot, end_page, end_section; | |
b34976b6 | 1022 | bfd_boolean section_modified; |
252b5132 | 1023 | |
c3668558 | 1024 | /* Get the section contents. */ |
252b5132 RH |
1025 | /* Get cached copy if it exists. */ |
1026 | if (elf_section_data (isec)->this_hdr.contents != NULL) | |
1027 | contents = elf_section_data (isec)->this_hdr.contents; | |
1028 | else | |
1029 | { | |
1030 | /* Go get them off disk. */ | |
1031 | contents = (bfd_byte *) bfd_malloc (isec->_raw_size); | |
1032 | if (contents == NULL) | |
8da6118f | 1033 | goto error_return; |
252b5132 RH |
1034 | free_contents = contents; |
1035 | ||
1036 | if (! bfd_get_section_contents (abfd, isec, contents, | |
1037 | (file_ptr) 0, isec->_raw_size)) | |
8da6118f | 1038 | goto error_return; |
252b5132 RH |
1039 | } |
1040 | ||
1041 | comb_curr = 0; | |
1042 | comb_count = 0; | |
1043 | if (isec->reloc_count) | |
8da6118f | 1044 | { |
252b5132 | 1045 | unsigned n; |
dc810e39 | 1046 | bfd_size_type amt; |
252b5132 RH |
1047 | |
1048 | /* Get a copy of the native relocations. */ | |
1049 | internal_relocs = _bfd_elf32_link_read_relocs ( | |
c3668558 | 1050 | abfd, isec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
252b5132 RH |
1051 | link_info->keep_memory); |
1052 | if (internal_relocs == NULL) | |
1053 | goto error_return; | |
1054 | if (! link_info->keep_memory) | |
1055 | free_relocs = internal_relocs; | |
c3668558 KH |
1056 | |
1057 | /* Setup a faster access method for the reloc info we need. */ | |
dc810e39 AM |
1058 | amt = isec->reloc_count; |
1059 | amt *= sizeof (Elf_Internal_Rela*); | |
1060 | rela_comb = (Elf_Internal_Rela**) bfd_malloc (amt); | |
252b5132 RH |
1061 | if (rela_comb == NULL) |
1062 | goto error_return; | |
8da6118f | 1063 | for (n = 0; n < isec->reloc_count; ++n) |
252b5132 RH |
1064 | { |
1065 | long r_type; | |
c3668558 | 1066 | |
252b5132 | 1067 | r_type = ELF32_R_TYPE (internal_relocs[n].r_info); |
8da6118f | 1068 | if (r_type < 0 || r_type >= (int) R_PPC_max) |
252b5132 | 1069 | goto error_return; |
c3668558 | 1070 | |
252b5132 RH |
1071 | /* Prologue constants are sometimes present in the ".text" |
1072 | sections and they can be identified by their associated relocation. | |
1073 | We don't want to process those words and some others which | |
1074 | can also be identified by their relocations. However, not all | |
1075 | conditional branches will have a relocation so we will | |
1076 | only ignore words that 1) have a reloc, and 2) the reloc | |
1077 | is not applicable to a conditional branch. | |
c3668558 | 1078 | The array rela_comb is built here for use in the EOP scan loop. */ |
252b5132 RH |
1079 | switch (r_type) |
1080 | { | |
1081 | case R_PPC_ADDR14_BRNTAKEN: /* absolute, predicted not taken */ | |
c3668558 | 1082 | case R_PPC_REL14: /* relative cond. br. */ |
252b5132 | 1083 | case R_PPC_REL14_BRNTAKEN: /* rel. cond. br., predicted not taken */ |
c3668558 | 1084 | /* We should check the instruction. */ |
252b5132 RH |
1085 | break; |
1086 | default: | |
c3668558 | 1087 | /* The word is not a conditional branch - ignore it. */ |
252b5132 RH |
1088 | rela_comb[comb_count++] = &internal_relocs[n]; |
1089 | break; | |
1090 | } | |
1091 | } | |
1092 | if (comb_count > 1) | |
8da6118f KH |
1093 | qsort (rela_comb, (size_t) comb_count, sizeof (int), ppc_elf_sort_rela); |
1094 | } | |
252b5132 | 1095 | |
c3668558 | 1096 | /* Enumerate each EOP region that overlaps this section. */ |
252b5132 RH |
1097 | end_section = isec->vma + isec->_cooked_size; |
1098 | dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1; | |
1099 | dot -= link_info->mpc860c0; | |
b34976b6 | 1100 | section_modified = FALSE; |
252b5132 | 1101 | if (dot < isec->vma) /* Increment the start position if this section */ |
c3668558 | 1102 | dot = isec->vma; /* begins in the middle of its first EOP region. */ |
252b5132 RH |
1103 | for (; |
1104 | dot < end_section; | |
1105 | dot += PAGESIZE, end_page += PAGESIZE) | |
1106 | { | |
1107 | ||
c3668558 | 1108 | /* Check each word in this EOP region. */ |
252b5132 RH |
1109 | for (; dot < end_page; dot += 4) |
1110 | { | |
1111 | bfd_vma isec_offset; | |
1112 | unsigned long insn; | |
b34976b6 | 1113 | bfd_boolean skip, modified; |
252b5132 RH |
1114 | |
1115 | /* Don't process this word if there is a relocation for it and | |
c3668558 | 1116 | the relocation indicates the word is not a conditional branch. */ |
b34976b6 | 1117 | skip = FALSE; |
252b5132 RH |
1118 | isec_offset = dot - isec->vma; |
1119 | for (; comb_curr<comb_count; ++comb_curr) | |
1120 | { | |
1121 | bfd_vma r_offset; | |
1122 | ||
1123 | r_offset = rela_comb[comb_curr]->r_offset; | |
1124 | if (r_offset >= isec_offset) | |
1125 | { | |
b34976b6 | 1126 | if (r_offset == isec_offset) skip = TRUE; |
252b5132 RH |
1127 | break; |
1128 | } | |
1129 | } | |
1130 | if (skip) continue; | |
1131 | ||
c3668558 | 1132 | /* Check the current word for a problematic conditional branch. */ |
252b5132 RH |
1133 | #define BO0(insn) ((insn) & 0x02000000) |
1134 | #define BO2(insn) ((insn) & 0x00800000) | |
1135 | #define BO4(insn) ((insn) & 0x00200000) | |
1136 | insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset); | |
b34976b6 | 1137 | modified = FALSE; |
252b5132 RH |
1138 | if ((insn & 0xFc000000) == 0x40000000) |
1139 | { | |
1140 | /* Instruction is BCx */ | |
1141 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) | |
1142 | { | |
1143 | bfd_vma target; | |
1144 | /* This branch is predicted as "normal". | |
c3668558 | 1145 | If this is a forward branch, it is problematic. */ |
252b5132 RH |
1146 | |
1147 | target = insn & 0x0000Fffc; /*extract*/ | |
1148 | target = (target ^ 0x8000) - 0x8000; /*sign extend*/ | |
1149 | if ((insn & 0x00000002) == 0) | |
1150 | target += dot; /*convert to abs*/ | |
1151 | if (target > dot) | |
1152 | { | |
1153 | insn |= 0x00200000; /* set the prediction bit */ | |
b34976b6 | 1154 | modified = TRUE; |
252b5132 RH |
1155 | } |
1156 | } | |
1157 | } | |
1158 | else if ((insn & 0xFc00Fffe) == 0x4c000420) | |
1159 | { | |
1160 | /* Instruction is BCCTRx */ | |
1161 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) | |
1162 | { | |
1163 | /* This branch is predicted as not-taken. | |
1164 | If this is a forward branch, it is problematic. | |
1165 | Since we can't tell statically if it will branch forward, | |
c3668558 | 1166 | always set the prediction bit. */ |
252b5132 | 1167 | insn |= 0x00200000; /* set the prediction bit */ |
b34976b6 | 1168 | modified = TRUE; |
252b5132 RH |
1169 | } |
1170 | } | |
1171 | else if ((insn & 0xFc00Fffe) == 0x4c000020) | |
1172 | { | |
1173 | /* Instruction is BCLRx */ | |
1174 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) | |
1175 | { | |
1176 | /* This branch is predicted as not-taken. | |
1177 | If this is a forward branch, it is problematic. | |
1178 | Since we can't tell statically if it will branch forward, | |
c3668558 | 1179 | always set the prediction bit. */ |
252b5132 | 1180 | insn |= 0x00200000; /* set the prediction bit */ |
b34976b6 | 1181 | modified = TRUE; |
252b5132 RH |
1182 | } |
1183 | } | |
1184 | #undef BO0 | |
1185 | #undef BO2 | |
1186 | #undef BO4 | |
1187 | if (modified) | |
1188 | { | |
dc810e39 | 1189 | bfd_put_32 (abfd, (bfd_vma) insn, contents + isec_offset); |
b34976b6 | 1190 | section_modified = TRUE; |
252b5132 RH |
1191 | } |
1192 | } | |
1193 | } | |
1194 | if (section_modified) | |
1195 | { | |
1196 | elf_section_data (isec)->this_hdr.contents = contents; | |
1197 | free_contents = NULL; | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | if (rela_comb != NULL) | |
1202 | { | |
1203 | free (rela_comb); | |
1204 | rela_comb = NULL; | |
1205 | } | |
1206 | ||
1207 | if (free_relocs != NULL) | |
1208 | { | |
1209 | free (free_relocs); | |
1210 | free_relocs = NULL; | |
1211 | } | |
1212 | ||
1213 | if (free_contents != NULL) | |
1214 | { | |
1215 | if (! link_info->keep_memory) | |
1216 | free (free_contents); | |
1217 | else | |
1218 | { | |
1219 | /* Cache the section contents for elf_link_input_bfd. */ | |
1220 | elf_section_data (isec)->this_hdr.contents = contents; | |
1221 | } | |
1222 | free_contents = NULL; | |
1223 | } | |
1224 | ||
b34976b6 | 1225 | return TRUE; |
252b5132 RH |
1226 | |
1227 | error_return: | |
1228 | if (rela_comb != NULL) | |
1229 | free (rela_comb); | |
1230 | if (free_relocs != NULL) | |
1231 | free (free_relocs); | |
1232 | if (free_contents != NULL) | |
1233 | free (free_contents); | |
b34976b6 | 1234 | return FALSE; |
252b5132 | 1235 | } |
252b5132 RH |
1236 | \f |
1237 | static reloc_howto_type * | |
1238 | ppc_elf_reloc_type_lookup (abfd, code) | |
5f771d47 | 1239 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1240 | bfd_reloc_code_real_type code; |
1241 | { | |
1242 | enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE; | |
1243 | ||
1244 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
8da6118f | 1245 | /* Initialize howto table if needed. */ |
252b5132 RH |
1246 | ppc_elf_howto_init (); |
1247 | ||
8da6118f | 1248 | switch ((int) code) |
252b5132 RH |
1249 | { |
1250 | default: | |
8da6118f | 1251 | return (reloc_howto_type *) NULL; |
252b5132 RH |
1252 | |
1253 | case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break; | |
1254 | case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break; | |
1255 | case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break; | |
1256 | case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break; | |
1257 | case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break; | |
1258 | case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break; | |
1259 | case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break; | |
1260 | case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break; | |
1261 | case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break; | |
1262 | case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break; | |
1263 | case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break; | |
1264 | case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break; | |
1265 | case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break; | |
1266 | case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break; | |
1267 | case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break; | |
1268 | case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break; | |
1269 | case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break; | |
1270 | case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break; | |
1271 | case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break; | |
1272 | case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break; | |
1273 | case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break; | |
1274 | case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break; | |
1275 | case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break; | |
1276 | case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break; | |
1277 | case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break; | |
1278 | case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break; | |
1279 | case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break; | |
1280 | case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break; | |
1281 | case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break; | |
c061c2d8 | 1282 | case BFD_RELOC_16_BASEREL: ppc_reloc = R_PPC_SECTOFF; break; |
252b5132 RH |
1283 | case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break; |
1284 | case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break; | |
1285 | case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break; | |
1286 | case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break; | |
1287 | case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break; | |
1288 | case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break; | |
1289 | case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break; | |
1290 | case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break; | |
1291 | case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break; | |
1292 | case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break; | |
1293 | case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break; | |
1294 | case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break; | |
1295 | case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break; | |
1296 | case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break; | |
1297 | case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break; | |
1298 | case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break; | |
1299 | case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break; | |
1300 | case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break; | |
1301 | case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break; | |
1302 | case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break; | |
1303 | case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break; | |
1304 | case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC_GNU_VTINHERIT; break; | |
1305 | case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC_GNU_VTENTRY; break; | |
1306 | } | |
1307 | ||
8da6118f | 1308 | return ppc_elf_howto_table[(int) ppc_reloc]; |
252b5132 RH |
1309 | }; |
1310 | ||
1311 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
1312 | ||
1313 | static void | |
1314 | ppc_elf_info_to_howto (abfd, cache_ptr, dst) | |
5f771d47 | 1315 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 1316 | arelent *cache_ptr; |
947216bf | 1317 | Elf_Internal_Rela *dst; |
252b5132 | 1318 | { |
8da6118f KH |
1319 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
1320 | /* Initialize howto table if needed. */ | |
252b5132 RH |
1321 | ppc_elf_howto_init (); |
1322 | ||
1323 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); | |
1324 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; | |
1325 | } | |
1326 | ||
1327 | /* Handle the R_PPC_ADDR16_HA reloc. */ | |
1328 | ||
1329 | static bfd_reloc_status_type | |
1330 | ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section, | |
1331 | output_bfd, error_message) | |
5f771d47 | 1332 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1333 | arelent *reloc_entry; |
1334 | asymbol *symbol; | |
5f771d47 | 1335 | PTR data ATTRIBUTE_UNUSED; |
252b5132 RH |
1336 | asection *input_section; |
1337 | bfd *output_bfd; | |
5f771d47 | 1338 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1339 | { |
1340 | bfd_vma relocation; | |
1341 | ||
1342 | if (output_bfd != NULL) | |
1343 | { | |
1344 | reloc_entry->address += input_section->output_offset; | |
1345 | return bfd_reloc_ok; | |
1346 | } | |
1347 | ||
1348 | if (reloc_entry->address > input_section->_cooked_size) | |
1349 | return bfd_reloc_outofrange; | |
1350 | ||
1351 | if (bfd_is_com_section (symbol->section)) | |
1352 | relocation = 0; | |
1353 | else | |
1354 | relocation = symbol->value; | |
1355 | ||
1356 | relocation += symbol->section->output_section->vma; | |
1357 | relocation += symbol->section->output_offset; | |
1358 | relocation += reloc_entry->addend; | |
1359 | ||
1360 | reloc_entry->addend += (relocation & 0x8000) << 1; | |
1361 | ||
1362 | return bfd_reloc_continue; | |
1363 | } | |
1364 | ||
feee612b AM |
1365 | /* Fix bad default arch selected for a 32 bit input bfd when the |
1366 | default is 64 bit. */ | |
1367 | ||
b34976b6 | 1368 | static bfd_boolean |
feee612b AM |
1369 | ppc_elf_object_p (abfd) |
1370 | bfd *abfd; | |
1371 | { | |
1372 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64) | |
1373 | { | |
1374 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
1375 | ||
1376 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) | |
1377 | { | |
1378 | /* Relies on arch after 64 bit default being 32 bit default. */ | |
1379 | abfd->arch_info = abfd->arch_info->next; | |
1380 | BFD_ASSERT (abfd->arch_info->bits_per_word == 32); | |
1381 | } | |
1382 | } | |
b34976b6 | 1383 | return TRUE; |
feee612b AM |
1384 | } |
1385 | ||
c3668558 | 1386 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
252b5132 | 1387 | |
b34976b6 | 1388 | static bfd_boolean |
252b5132 RH |
1389 | ppc_elf_set_private_flags (abfd, flags) |
1390 | bfd *abfd; | |
1391 | flagword flags; | |
1392 | { | |
1393 | BFD_ASSERT (!elf_flags_init (abfd) | |
1394 | || elf_elfheader (abfd)->e_flags == flags); | |
1395 | ||
1396 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 AM |
1397 | elf_flags_init (abfd) = TRUE; |
1398 | return TRUE; | |
252b5132 RH |
1399 | } |
1400 | ||
252b5132 RH |
1401 | /* Merge backend specific data from an object file to the output |
1402 | object file when linking */ | |
b34976b6 | 1403 | static bfd_boolean |
252b5132 RH |
1404 | ppc_elf_merge_private_bfd_data (ibfd, obfd) |
1405 | bfd *ibfd; | |
1406 | bfd *obfd; | |
1407 | { | |
1408 | flagword old_flags; | |
1409 | flagword new_flags; | |
b34976b6 | 1410 | bfd_boolean error; |
252b5132 RH |
1411 | |
1412 | /* Check if we have the same endianess */ | |
82e51918 | 1413 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 1414 | return FALSE; |
252b5132 RH |
1415 | |
1416 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
1417 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 1418 | return TRUE; |
252b5132 RH |
1419 | |
1420 | new_flags = elf_elfheader (ibfd)->e_flags; | |
1421 | old_flags = elf_elfheader (obfd)->e_flags; | |
1422 | if (!elf_flags_init (obfd)) /* First call, no flags set */ | |
1423 | { | |
b34976b6 | 1424 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
1425 | elf_elfheader (obfd)->e_flags = new_flags; |
1426 | } | |
1427 | ||
1428 | else if (new_flags == old_flags) /* Compatible flags are ok */ | |
1429 | ; | |
1430 | ||
1431 | else /* Incompatible flags */ | |
1432 | { | |
1433 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked | |
1434 | with either. */ | |
b34976b6 | 1435 | error = FALSE; |
252b5132 RH |
1436 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 |
1437 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
1438 | { | |
b34976b6 | 1439 | error = TRUE; |
252b5132 RH |
1440 | (*_bfd_error_handler) |
1441 | (_("%s: compiled with -mrelocatable and linked with modules compiled normally"), | |
8f615d07 | 1442 | bfd_archive_filename (ibfd)); |
252b5132 RH |
1443 | } |
1444 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
1445 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
1446 | { | |
b34976b6 | 1447 | error = TRUE; |
252b5132 RH |
1448 | (*_bfd_error_handler) |
1449 | (_("%s: compiled normally and linked with modules compiled with -mrelocatable"), | |
8f615d07 | 1450 | bfd_archive_filename (ibfd)); |
252b5132 RH |
1451 | } |
1452 | ||
1453 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
1454 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
1455 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
1456 | ||
1457 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
1458 | but each input file is either -mrelocatable or -mrelocatable-lib. */ | |
1459 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) | |
1460 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
1461 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
1462 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
1463 | ||
1464 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */ | |
1465 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); | |
1466 | ||
1467 | new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
1468 | old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
1469 | ||
1470 | /* Warn about any other mismatches */ | |
1471 | if (new_flags != old_flags) | |
1472 | { | |
b34976b6 | 1473 | error = TRUE; |
252b5132 RH |
1474 | (*_bfd_error_handler) |
1475 | (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"), | |
8f615d07 | 1476 | bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags); |
252b5132 RH |
1477 | } |
1478 | ||
1479 | if (error) | |
1480 | { | |
1481 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 1482 | return FALSE; |
252b5132 RH |
1483 | } |
1484 | } | |
1485 | ||
b34976b6 | 1486 | return TRUE; |
252b5132 | 1487 | } |
252b5132 RH |
1488 | \f |
1489 | /* Handle a PowerPC specific section when reading an object file. This | |
1490 | is called when elfcode.h finds a section with an unknown type. */ | |
1491 | ||
b34976b6 | 1492 | static bfd_boolean |
252b5132 RH |
1493 | ppc_elf_section_from_shdr (abfd, hdr, name) |
1494 | bfd *abfd; | |
947216bf | 1495 | Elf_Internal_Shdr *hdr; |
90937f86 | 1496 | const char *name; |
252b5132 RH |
1497 | { |
1498 | asection *newsect; | |
1499 | flagword flags; | |
1500 | ||
1501 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | |
b34976b6 | 1502 | return FALSE; |
252b5132 RH |
1503 | |
1504 | newsect = hdr->bfd_section; | |
1505 | flags = bfd_get_section_flags (abfd, newsect); | |
1506 | if (hdr->sh_flags & SHF_EXCLUDE) | |
1507 | flags |= SEC_EXCLUDE; | |
1508 | ||
1509 | if (hdr->sh_type == SHT_ORDERED) | |
1510 | flags |= SEC_SORT_ENTRIES; | |
1511 | ||
1512 | bfd_set_section_flags (abfd, newsect, flags); | |
b34976b6 | 1513 | return TRUE; |
252b5132 | 1514 | } |
252b5132 RH |
1515 | \f |
1516 | /* Set up any other section flags and such that may be necessary. */ | |
1517 | ||
b34976b6 | 1518 | static bfd_boolean |
252b5132 | 1519 | ppc_elf_fake_sections (abfd, shdr, asect) |
5f771d47 | 1520 | bfd *abfd ATTRIBUTE_UNUSED; |
947216bf | 1521 | Elf_Internal_Shdr *shdr; |
252b5132 RH |
1522 | asection *asect; |
1523 | { | |
1524 | if ((asect->flags & SEC_EXCLUDE) != 0) | |
1525 | shdr->sh_flags |= SHF_EXCLUDE; | |
1526 | ||
1527 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) | |
1528 | shdr->sh_type = SHT_ORDERED; | |
1529 | ||
b34976b6 | 1530 | return TRUE; |
252b5132 | 1531 | } |
252b5132 RH |
1532 | \f |
1533 | /* Create a special linker section */ | |
1534 | static elf_linker_section_t * | |
1535 | ppc_elf_create_linker_section (abfd, info, which) | |
1536 | bfd *abfd; | |
1537 | struct bfd_link_info *info; | |
1538 | enum elf_linker_section_enum which; | |
1539 | { | |
1540 | bfd *dynobj = elf_hash_table (info)->dynobj; | |
1541 | elf_linker_section_t *lsect; | |
1542 | ||
1543 | /* Record the first bfd section that needs the special section */ | |
1544 | if (!dynobj) | |
1545 | dynobj = elf_hash_table (info)->dynobj = abfd; | |
1546 | ||
1547 | /* If this is the first time, create the section */ | |
1548 | lsect = elf_linker_section (dynobj, which); | |
1549 | if (!lsect) | |
1550 | { | |
1551 | elf_linker_section_t defaults; | |
1552 | static elf_linker_section_t zero_section; | |
1553 | ||
1554 | defaults = zero_section; | |
1555 | defaults.which = which; | |
b34976b6 | 1556 | defaults.hole_written_p = FALSE; |
252b5132 RH |
1557 | defaults.alignment = 2; |
1558 | ||
1559 | /* Both of these sections are (technically) created by the user | |
1560 | putting data in them, so they shouldn't be marked | |
1561 | SEC_LINKER_CREATED. | |
1562 | ||
1563 | The linker creates them so it has somewhere to attach their | |
1564 | respective symbols. In fact, if they were empty it would | |
1565 | be OK to leave the symbol set to 0 (or any random number), because | |
1566 | the appropriate register should never be used. */ | |
1567 | defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
1568 | | SEC_IN_MEMORY); | |
1569 | ||
1570 | switch (which) | |
1571 | { | |
1572 | default: | |
1573 | (*_bfd_error_handler) (_("%s: Unknown special linker type %d"), | |
1574 | bfd_get_filename (abfd), | |
8da6118f | 1575 | (int) which); |
252b5132 RH |
1576 | |
1577 | bfd_set_error (bfd_error_bad_value); | |
8da6118f | 1578 | return (elf_linker_section_t *) 0; |
252b5132 RH |
1579 | |
1580 | case LINKER_SECTION_SDATA: /* .sdata/.sbss section */ | |
1581 | defaults.name = ".sdata"; | |
1582 | defaults.rel_name = ".rela.sdata"; | |
1583 | defaults.bss_name = ".sbss"; | |
1584 | defaults.sym_name = "_SDA_BASE_"; | |
1585 | defaults.sym_offset = 32768; | |
1586 | break; | |
1587 | ||
1588 | case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */ | |
1589 | defaults.name = ".sdata2"; | |
1590 | defaults.rel_name = ".rela.sdata2"; | |
1591 | defaults.bss_name = ".sbss2"; | |
1592 | defaults.sym_name = "_SDA2_BASE_"; | |
1593 | defaults.sym_offset = 32768; | |
1594 | defaults.flags |= SEC_READONLY; | |
1595 | break; | |
1596 | } | |
1597 | ||
1598 | lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults); | |
1599 | } | |
1600 | ||
1601 | return lsect; | |
1602 | } | |
252b5132 | 1603 | \f |
8da6118f KH |
1604 | /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we |
1605 | need to bump up the number of section headers. */ | |
252b5132 RH |
1606 | |
1607 | static int | |
1608 | ppc_elf_additional_program_headers (abfd) | |
1609 | bfd *abfd; | |
1610 | { | |
1611 | asection *s; | |
1612 | int ret; | |
1613 | ||
1614 | ret = 0; | |
1615 | ||
1616 | s = bfd_get_section_by_name (abfd, ".interp"); | |
1617 | if (s != NULL) | |
1618 | ++ret; | |
1619 | ||
1620 | s = bfd_get_section_by_name (abfd, ".sbss2"); | |
1621 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) | |
1622 | ++ret; | |
1623 | ||
1624 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); | |
1625 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) | |
1626 | ++ret; | |
1627 | ||
1628 | return ret; | |
1629 | } | |
1630 | ||
8da6118f | 1631 | /* Modify the segment map if needed. */ |
252b5132 | 1632 | |
b34976b6 | 1633 | static bfd_boolean |
252b5132 | 1634 | ppc_elf_modify_segment_map (abfd) |
5f771d47 | 1635 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 1636 | { |
b34976b6 | 1637 | return TRUE; |
252b5132 RH |
1638 | } |
1639 | \f | |
41fcb14e AM |
1640 | /* The powerpc .got has a blrl instruction in it. Mark it executable. */ |
1641 | ||
1642 | static asection * | |
1643 | ppc_elf_create_got (abfd, info) | |
1644 | bfd *abfd; | |
1645 | struct bfd_link_info *info; | |
1646 | { | |
1647 | register asection *s; | |
1648 | flagword flags; | |
1649 | ||
1650 | if (!_bfd_elf_create_got_section (abfd, info)) | |
1651 | return NULL; | |
1652 | ||
1653 | s = bfd_get_section_by_name (abfd, ".got"); | |
1654 | if (s == NULL) | |
1655 | abort (); | |
1656 | ||
1657 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
1658 | | SEC_LINKER_CREATED); | |
1659 | if (!bfd_set_section_flags (abfd, s, flags)) | |
1660 | return NULL; | |
1661 | return s; | |
1662 | } | |
1663 | ||
252b5132 RH |
1664 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
1665 | to output sections (just like _bfd_elf_create_dynamic_sections has | |
1666 | to create .dynbss and .rela.bss). */ | |
1667 | ||
b34976b6 | 1668 | static bfd_boolean |
252b5132 RH |
1669 | ppc_elf_create_dynamic_sections (abfd, info) |
1670 | bfd *abfd; | |
1671 | struct bfd_link_info *info; | |
1672 | { | |
1673 | register asection *s; | |
1674 | flagword flags; | |
1675 | ||
41fcb14e | 1676 | if (!ppc_elf_create_got (abfd, info)) |
b34976b6 | 1677 | return FALSE; |
41fcb14e | 1678 | |
8da6118f | 1679 | if (!_bfd_elf_create_dynamic_sections (abfd, info)) |
b34976b6 | 1680 | return FALSE; |
252b5132 RH |
1681 | |
1682 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
1683 | | SEC_LINKER_CREATED); | |
1684 | ||
1685 | s = bfd_make_section (abfd, ".dynsbss"); | |
1686 | if (s == NULL | |
1687 | || ! bfd_set_section_flags (abfd, s, SEC_ALLOC)) | |
b34976b6 | 1688 | return FALSE; |
252b5132 RH |
1689 | |
1690 | if (! info->shared) | |
1691 | { | |
1692 | s = bfd_make_section (abfd, ".rela.sbss"); | |
1693 | if (s == NULL | |
1694 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) | |
1695 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
b34976b6 | 1696 | return FALSE; |
252b5132 | 1697 | } |
41fcb14e AM |
1698 | |
1699 | s = bfd_get_section_by_name (abfd, ".plt"); | |
1700 | if (s == NULL) | |
1701 | abort (); | |
1702 | ||
1703 | flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED; | |
1704 | return bfd_set_section_flags (abfd, s, flags); | |
252b5132 RH |
1705 | } |
1706 | ||
1707 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
1708 | regular object. The current definition is in some section of the | |
1709 | dynamic object, but we're not including those sections. We have to | |
1710 | change the definition to something the rest of the link can | |
1711 | understand. */ | |
1712 | ||
b34976b6 | 1713 | static bfd_boolean |
252b5132 RH |
1714 | ppc_elf_adjust_dynamic_symbol (info, h) |
1715 | struct bfd_link_info *info; | |
1716 | struct elf_link_hash_entry *h; | |
1717 | { | |
1718 | bfd *dynobj = elf_hash_table (info)->dynobj; | |
1719 | asection *s; | |
1720 | unsigned int power_of_two; | |
1721 | bfd_vma plt_offset; | |
1722 | ||
1723 | #ifdef DEBUG | |
1724 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string); | |
1725 | #endif | |
1726 | ||
1727 | /* Make sure we know what is going on here. */ | |
1728 | BFD_ASSERT (dynobj != NULL | |
1729 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) | |
1730 | || h->weakdef != NULL | |
1731 | || ((h->elf_link_hash_flags | |
1732 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
1733 | && (h->elf_link_hash_flags | |
1734 | & ELF_LINK_HASH_REF_REGULAR) != 0 | |
1735 | && (h->elf_link_hash_flags | |
1736 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); | |
1737 | ||
252b5132 RH |
1738 | /* If this is a function, put it in the procedure linkage table. We |
1739 | will fill in the contents of the procedure linkage table later, | |
1740 | when we know the address of the .got section. */ | |
1741 | if (h->type == STT_FUNC | |
1742 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
1743 | { | |
1744 | if (! elf_hash_table (info)->dynamic_sections_created | |
e1e0340b | 1745 | || SYMBOL_CALLS_LOCAL (info, h) |
252b5132 RH |
1746 | || (info->shared && h->plt.refcount <= 0)) |
1747 | { | |
1748 | /* A PLT entry is not required/allowed when: | |
1749 | ||
1750 | 1. We are not using ld.so; because then the PLT entry | |
1751 | can't be set up, so we can't use one. | |
1752 | ||
e1e0340b GK |
1753 | 2. We know for certain that a call to this symbol |
1754 | will go to this object. | |
252b5132 RH |
1755 | |
1756 | 3. GC has rendered the entry unused. | |
1757 | Note, however, that in an executable all references to the | |
1758 | symbol go to the PLT, so we can't turn it off in that case. | |
1759 | ??? The correct thing to do here is to reference count | |
1760 | all uses of the symbol, not just those to the GOT or PLT. */ | |
1761 | h->plt.offset = (bfd_vma) -1; | |
1762 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
b34976b6 | 1763 | return TRUE; |
252b5132 RH |
1764 | } |
1765 | ||
1766 | /* Make sure this symbol is output as a dynamic symbol. */ | |
1767 | if (h->dynindx == -1) | |
1768 | { | |
1769 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
b34976b6 | 1770 | return FALSE; |
252b5132 RH |
1771 | } |
1772 | BFD_ASSERT (h->dynindx != -1); | |
1773 | ||
1774 | s = bfd_get_section_by_name (dynobj, ".plt"); | |
1775 | BFD_ASSERT (s != NULL); | |
1776 | ||
1777 | /* If this is the first .plt entry, make room for the special | |
1778 | first entry. */ | |
1779 | if (s->_raw_size == 0) | |
1780 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; | |
1781 | ||
1782 | /* The PowerPC PLT is actually composed of two parts, the first part | |
1783 | is 2 words (for a load and a jump), and then there is a remaining | |
1784 | word available at the end. */ | |
1785 | plt_offset = (PLT_INITIAL_ENTRY_SIZE | |
1786 | + (PLT_SLOT_SIZE | |
1787 | * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) | |
1788 | / PLT_ENTRY_SIZE))); | |
1789 | ||
1790 | /* If this symbol is not defined in a regular file, and we are | |
1791 | not generating a shared library, then set the symbol to this | |
1792 | location in the .plt. This is required to make function | |
1793 | pointers compare as equal between the normal executable and | |
1794 | the shared library. */ | |
1795 | if (! info->shared | |
1796 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
1797 | { | |
1798 | h->root.u.def.section = s; | |
1799 | h->root.u.def.value = plt_offset; | |
1800 | } | |
1801 | ||
1802 | h->plt.offset = plt_offset; | |
1803 | ||
1804 | /* Make room for this entry. After the 8192nd entry, room | |
1805 | for two entries is allocated. */ | |
1806 | if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE | |
1807 | >= PLT_NUM_SINGLE_ENTRIES) | |
1808 | s->_raw_size += 2 * PLT_ENTRY_SIZE; | |
1809 | else | |
1810 | s->_raw_size += PLT_ENTRY_SIZE; | |
1811 | ||
1812 | /* We also need to make an entry in the .rela.plt section. */ | |
1813 | s = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
1814 | BFD_ASSERT (s != NULL); | |
1815 | s->_raw_size += sizeof (Elf32_External_Rela); | |
1816 | ||
b34976b6 | 1817 | return TRUE; |
252b5132 | 1818 | } |
bbd7ec4a AM |
1819 | else |
1820 | h->plt.offset = (bfd_vma) -1; | |
252b5132 RH |
1821 | |
1822 | /* If this is a weak symbol, and there is a real definition, the | |
1823 | processor independent code will have arranged for us to see the | |
1824 | real definition first, and we can just use the same value. */ | |
1825 | if (h->weakdef != NULL) | |
1826 | { | |
1827 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
1828 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
1829 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
1830 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
b34976b6 | 1831 | return TRUE; |
252b5132 RH |
1832 | } |
1833 | ||
1834 | /* This is a reference to a symbol defined by a dynamic object which | |
1835 | is not a function. */ | |
1836 | ||
1837 | /* If we are creating a shared library, we must presume that the | |
1838 | only references to the symbol are via the global offset table. | |
1839 | For such cases we need not do anything here; the relocations will | |
1840 | be handled correctly by relocate_section. */ | |
1841 | if (info->shared) | |
b34976b6 | 1842 | return TRUE; |
252b5132 RH |
1843 | |
1844 | /* We must allocate the symbol in our .dynbss section, which will | |
1845 | become part of the .bss section of the executable. There will be | |
1846 | an entry for this symbol in the .dynsym section. The dynamic | |
1847 | object will contain position independent code, so all references | |
1848 | from the dynamic object to this symbol will go through the global | |
1849 | offset table. The dynamic linker will use the .dynsym entry to | |
1850 | determine the address it must put in the global offset table, so | |
1851 | both the dynamic object and the regular object will refer to the | |
1852 | same memory location for the variable. | |
1853 | ||
1854 | Of course, if the symbol is sufficiently small, we must instead | |
1855 | allocate it in .sbss. FIXME: It would be better to do this if and | |
1856 | only if there were actually SDAREL relocs for that symbol. */ | |
1857 | ||
1858 | if (h->size <= elf_gp_size (dynobj)) | |
1859 | s = bfd_get_section_by_name (dynobj, ".dynsbss"); | |
1860 | else | |
1861 | s = bfd_get_section_by_name (dynobj, ".dynbss"); | |
1862 | BFD_ASSERT (s != NULL); | |
1863 | ||
1864 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
1865 | copy the initial value out of the dynamic object and into the | |
1866 | runtime process image. We need to remember the offset into the | |
1867 | .rela.bss section we are going to use. */ | |
1868 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
1869 | { | |
1870 | asection *srel; | |
1871 | ||
1872 | if (h->size <= elf_gp_size (dynobj)) | |
1873 | srel = bfd_get_section_by_name (dynobj, ".rela.sbss"); | |
1874 | else | |
1875 | srel = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
1876 | BFD_ASSERT (srel != NULL); | |
1877 | srel->_raw_size += sizeof (Elf32_External_Rela); | |
1878 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; | |
1879 | } | |
1880 | ||
1881 | /* We need to figure out the alignment required for this symbol. I | |
1882 | have no idea how ELF linkers handle this. */ | |
1883 | power_of_two = bfd_log2 (h->size); | |
1884 | if (power_of_two > 4) | |
1885 | power_of_two = 4; | |
1886 | ||
1887 | /* Apply the required alignment. */ | |
1888 | s->_raw_size = BFD_ALIGN (s->_raw_size, | |
1889 | (bfd_size_type) (1 << power_of_two)); | |
1890 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) | |
1891 | { | |
1892 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 1893 | return FALSE; |
252b5132 RH |
1894 | } |
1895 | ||
1896 | /* Define the symbol as being at this point in the section. */ | |
1897 | h->root.u.def.section = s; | |
1898 | h->root.u.def.value = s->_raw_size; | |
1899 | ||
1900 | /* Increment the section size to make room for the symbol. */ | |
1901 | s->_raw_size += h->size; | |
1902 | ||
b34976b6 | 1903 | return TRUE; |
252b5132 | 1904 | } |
252b5132 RH |
1905 | \f |
1906 | /* Set the sizes of the dynamic sections. */ | |
1907 | ||
b34976b6 | 1908 | static bfd_boolean |
252b5132 | 1909 | ppc_elf_size_dynamic_sections (output_bfd, info) |
29c2fb7c | 1910 | bfd *output_bfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1911 | struct bfd_link_info *info; |
1912 | { | |
1913 | bfd *dynobj; | |
1914 | asection *s; | |
b34976b6 AM |
1915 | bfd_boolean plt; |
1916 | bfd_boolean relocs; | |
252b5132 RH |
1917 | |
1918 | #ifdef DEBUG | |
1919 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); | |
1920 | #endif | |
1921 | ||
1922 | dynobj = elf_hash_table (info)->dynobj; | |
1923 | BFD_ASSERT (dynobj != NULL); | |
1924 | ||
1925 | if (elf_hash_table (info)->dynamic_sections_created) | |
1926 | { | |
1927 | /* Set the contents of the .interp section to the interpreter. */ | |
1928 | if (! info->shared) | |
1929 | { | |
1930 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
1931 | BFD_ASSERT (s != NULL); | |
1932 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
1933 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
1934 | } | |
1935 | } | |
1936 | else | |
1937 | { | |
1938 | /* We may have created entries in the .rela.got, .rela.sdata, and | |
1939 | .rela.sdata2 sections. However, if we are not creating the | |
1940 | dynamic sections, we will not actually use these entries. Reset | |
1941 | the size of .rela.got, et al, which will cause it to get | |
1942 | stripped from the output file below. */ | |
1943 | static char *rela_sections[] = { ".rela.got", ".rela.sdata", | |
1944 | ".rela.sdata2", ".rela.sbss", | |
8da6118f | 1945 | (char *) 0 }; |
252b5132 RH |
1946 | char **p; |
1947 | ||
8da6118f | 1948 | for (p = rela_sections; *p != (char *) 0; p++) |
252b5132 RH |
1949 | { |
1950 | s = bfd_get_section_by_name (dynobj, *p); | |
1951 | if (s != NULL) | |
1952 | s->_raw_size = 0; | |
1953 | } | |
1954 | } | |
1955 | ||
1956 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
1957 | determined the sizes of the various dynamic sections. Allocate | |
1958 | memory for them. */ | |
b34976b6 AM |
1959 | plt = FALSE; |
1960 | relocs = FALSE; | |
252b5132 RH |
1961 | for (s = dynobj->sections; s != NULL; s = s->next) |
1962 | { | |
1963 | const char *name; | |
b34976b6 | 1964 | bfd_boolean strip; |
252b5132 RH |
1965 | |
1966 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
1967 | continue; | |
1968 | ||
1969 | /* It's OK to base decisions on the section name, because none | |
1970 | of the dynobj section names depend upon the input files. */ | |
1971 | name = bfd_get_section_name (dynobj, s); | |
1972 | ||
b34976b6 | 1973 | strip = FALSE; |
252b5132 RH |
1974 | |
1975 | if (strcmp (name, ".plt") == 0) | |
1976 | { | |
1977 | if (s->_raw_size == 0) | |
1978 | { | |
1979 | /* Strip this section if we don't need it; see the | |
1980 | comment below. */ | |
b34976b6 | 1981 | strip = TRUE; |
252b5132 RH |
1982 | } |
1983 | else | |
1984 | { | |
1985 | /* Remember whether there is a PLT. */ | |
b34976b6 | 1986 | plt = TRUE; |
252b5132 RH |
1987 | } |
1988 | } | |
1989 | else if (strncmp (name, ".rela", 5) == 0) | |
1990 | { | |
1991 | if (s->_raw_size == 0) | |
1992 | { | |
1993 | /* If we don't need this section, strip it from the | |
1994 | output file. This is mostly to handle .rela.bss and | |
1995 | .rela.plt. We must create both sections in | |
1996 | create_dynamic_sections, because they must be created | |
1997 | before the linker maps input sections to output | |
1998 | sections. The linker does that before | |
1999 | adjust_dynamic_symbol is called, and it is that | |
2000 | function which decides whether anything needs to go | |
2001 | into these sections. */ | |
b34976b6 | 2002 | strip = TRUE; |
252b5132 RH |
2003 | } |
2004 | else | |
2005 | { | |
c3668558 | 2006 | /* Remember whether there are any relocation sections. */ |
b34976b6 | 2007 | relocs = TRUE; |
252b5132 | 2008 | |
252b5132 RH |
2009 | /* We use the reloc_count field as a counter if we need |
2010 | to copy relocs into the output file. */ | |
2011 | s->reloc_count = 0; | |
2012 | } | |
2013 | } | |
2014 | else if (strcmp (name, ".got") != 0 | |
2015 | && strcmp (name, ".sdata") != 0 | |
2016 | && strcmp (name, ".sdata2") != 0) | |
2017 | { | |
2018 | /* It's not one of our sections, so don't allocate space. */ | |
2019 | continue; | |
2020 | } | |
2021 | ||
2022 | if (strip) | |
2023 | { | |
7f8d5fc9 | 2024 | _bfd_strip_section_from_output (info, s); |
252b5132 RH |
2025 | continue; |
2026 | } | |
2027 | ||
2028 | /* Allocate memory for the section contents. */ | |
2029 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); | |
2030 | if (s->contents == NULL && s->_raw_size != 0) | |
b34976b6 | 2031 | return FALSE; |
252b5132 RH |
2032 | } |
2033 | ||
2034 | if (elf_hash_table (info)->dynamic_sections_created) | |
2035 | { | |
2036 | /* Add some entries to the .dynamic section. We fill in the | |
2037 | values later, in ppc_elf_finish_dynamic_sections, but we | |
2038 | must add the entries now so that we get the correct size for | |
2039 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
2040 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
2041 | #define add_dynamic_entry(TAG, VAL) \ |
2042 | bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
2043 | ||
2044 | if (!info->shared) | |
252b5132 | 2045 | { |
dc810e39 | 2046 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 2047 | return FALSE; |
252b5132 RH |
2048 | } |
2049 | ||
2050 | if (plt) | |
2051 | { | |
dc810e39 AM |
2052 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
2053 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
2054 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
2055 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 2056 | return FALSE; |
252b5132 RH |
2057 | } |
2058 | ||
2059 | if (relocs) | |
2060 | { | |
dc810e39 AM |
2061 | if (!add_dynamic_entry (DT_RELA, 0) |
2062 | || !add_dynamic_entry (DT_RELASZ, 0) | |
2063 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
b34976b6 | 2064 | return FALSE; |
252b5132 RH |
2065 | } |
2066 | ||
29c2fb7c | 2067 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 2068 | { |
dc810e39 | 2069 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 2070 | return FALSE; |
d6cf2879 | 2071 | info->flags |= DF_TEXTREL; |
252b5132 RH |
2072 | } |
2073 | } | |
dc810e39 | 2074 | #undef add_dynamic_entry |
252b5132 | 2075 | |
b34976b6 | 2076 | return TRUE; |
252b5132 | 2077 | } |
252b5132 RH |
2078 | \f |
2079 | /* Look through the relocs for a section during the first phase, and | |
2080 | allocate space in the global offset table or procedure linkage | |
2081 | table. */ | |
2082 | ||
b34976b6 | 2083 | static bfd_boolean |
252b5132 RH |
2084 | ppc_elf_check_relocs (abfd, info, sec, relocs) |
2085 | bfd *abfd; | |
2086 | struct bfd_link_info *info; | |
2087 | asection *sec; | |
2088 | const Elf_Internal_Rela *relocs; | |
2089 | { | |
2090 | bfd *dynobj; | |
2091 | Elf_Internal_Shdr *symtab_hdr; | |
2092 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
2093 | const Elf_Internal_Rela *rel; | |
2094 | const Elf_Internal_Rela *rel_end; | |
2095 | bfd_signed_vma *local_got_refcounts; | |
2096 | elf_linker_section_t *sdata; | |
2097 | elf_linker_section_t *sdata2; | |
2098 | asection *sreloc; | |
2099 | asection *sgot = NULL; | |
2100 | asection *srelgot = NULL; | |
2101 | ||
2102 | if (info->relocateable) | |
b34976b6 | 2103 | return TRUE; |
252b5132 RH |
2104 | |
2105 | #ifdef DEBUG | |
2106 | fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n", | |
2107 | bfd_get_section_name (abfd, sec), | |
8f615d07 | 2108 | bfd_archive_filename (abfd)); |
252b5132 RH |
2109 | #endif |
2110 | ||
2111 | /* Create the linker generated sections all the time so that the | |
2112 | special symbols are created. */ | |
2113 | ||
2114 | if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL) | |
2115 | { | |
2116 | sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA); | |
2117 | if (!sdata) | |
b34976b6 | 2118 | return FALSE; |
252b5132 RH |
2119 | } |
2120 | ||
252b5132 RH |
2121 | if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL) |
2122 | { | |
2123 | sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2); | |
2124 | if (!sdata2) | |
b34976b6 | 2125 | return FALSE; |
252b5132 RH |
2126 | } |
2127 | ||
2128 | dynobj = elf_hash_table (info)->dynobj; | |
2129 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2130 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
2131 | ||
2132 | sym_hashes = elf_sym_hashes (abfd); | |
c3668558 | 2133 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym); |
252b5132 RH |
2134 | if (!elf_bad_symtab (abfd)) |
2135 | sym_hashes_end -= symtab_hdr->sh_info; | |
2136 | ||
2137 | sreloc = NULL; | |
2138 | ||
2139 | rel_end = relocs + sec->reloc_count; | |
2140 | for (rel = relocs; rel < rel_end; rel++) | |
2141 | { | |
2142 | unsigned long r_symndx; | |
2143 | struct elf_link_hash_entry *h; | |
2144 | ||
2145 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2146 | if (r_symndx < symtab_hdr->sh_info) | |
2147 | h = NULL; | |
2148 | else | |
2149 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2150 | ||
2151 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. | |
2152 | This shows up in particular in an R_PPC_ADDR32 in the eabi | |
2153 | startup code. */ | |
2154 | if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
2155 | { | |
2156 | if (sgot == NULL) | |
2157 | { | |
2158 | if (dynobj == NULL) | |
2159 | elf_hash_table (info)->dynobj = dynobj = abfd; | |
41fcb14e AM |
2160 | sgot = ppc_elf_create_got (dynobj, info); |
2161 | if (sgot == NULL) | |
b34976b6 | 2162 | return FALSE; |
252b5132 RH |
2163 | } |
2164 | } | |
2165 | ||
2166 | switch (ELF32_R_TYPE (rel->r_info)) | |
2167 | { | |
2168 | /* GOT16 relocations */ | |
2169 | case R_PPC_GOT16: | |
2170 | case R_PPC_GOT16_LO: | |
2171 | case R_PPC_GOT16_HI: | |
2172 | case R_PPC_GOT16_HA: | |
2173 | /* This symbol requires a global offset table entry. */ | |
2174 | ||
2175 | if (sgot == NULL) | |
2176 | { | |
2177 | if (dynobj == NULL) | |
2178 | elf_hash_table (info)->dynobj = dynobj = abfd; | |
41fcb14e AM |
2179 | sgot = ppc_elf_create_got (dynobj, info); |
2180 | if (sgot == NULL) | |
b34976b6 | 2181 | return FALSE; |
252b5132 RH |
2182 | } |
2183 | ||
2184 | if (srelgot == NULL | |
2185 | && (h != NULL || info->shared)) | |
2186 | { | |
2187 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
2188 | if (srelgot == NULL) | |
2189 | { | |
2190 | srelgot = bfd_make_section (dynobj, ".rela.got"); | |
2191 | if (srelgot == NULL | |
2192 | || ! bfd_set_section_flags (dynobj, srelgot, | |
2193 | (SEC_ALLOC | |
2194 | | SEC_LOAD | |
2195 | | SEC_HAS_CONTENTS | |
2196 | | SEC_IN_MEMORY | |
2197 | | SEC_LINKER_CREATED | |
2198 | | SEC_READONLY)) | |
2199 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | |
b34976b6 | 2200 | return FALSE; |
252b5132 RH |
2201 | } |
2202 | } | |
2203 | ||
2204 | if (h != NULL) | |
2205 | { | |
51b64d56 | 2206 | if (h->got.refcount == 0) |
252b5132 RH |
2207 | { |
2208 | /* Make sure this symbol is output as a dynamic symbol. */ | |
2209 | if (h->dynindx == -1) | |
2210 | if (!bfd_elf32_link_record_dynamic_symbol (info, h)) | |
b34976b6 | 2211 | return FALSE; |
252b5132 RH |
2212 | |
2213 | /* Allocate space in the .got. */ | |
2214 | sgot->_raw_size += 4; | |
2215 | /* Allocate relocation space. */ | |
2216 | srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
252b5132 | 2217 | } |
51b64d56 | 2218 | h->got.refcount++; |
252b5132 RH |
2219 | } |
2220 | else | |
2221 | { | |
2222 | /* This is a global offset table entry for a local symbol. */ | |
2223 | if (local_got_refcounts == NULL) | |
2224 | { | |
dc810e39 | 2225 | bfd_size_type size; |
252b5132 | 2226 | |
dc810e39 AM |
2227 | size = symtab_hdr->sh_info; |
2228 | size *= sizeof (bfd_signed_vma); | |
2229 | local_got_refcounts | |
51b64d56 | 2230 | = (bfd_signed_vma *) bfd_zalloc (abfd, size); |
252b5132 | 2231 | if (local_got_refcounts == NULL) |
b34976b6 | 2232 | return FALSE; |
252b5132 | 2233 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 2234 | } |
51b64d56 | 2235 | if (local_got_refcounts[r_symndx] == 0) |
252b5132 RH |
2236 | { |
2237 | sgot->_raw_size += 4; | |
2238 | ||
2239 | /* If we are generating a shared object, we need to | |
2240 | output a R_PPC_RELATIVE reloc so that the | |
2241 | dynamic linker can adjust this GOT entry. */ | |
2242 | if (info->shared) | |
2243 | srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
252b5132 | 2244 | } |
51b64d56 | 2245 | local_got_refcounts[r_symndx]++; |
252b5132 RH |
2246 | } |
2247 | break; | |
2248 | ||
2249 | /* Indirect .sdata relocation */ | |
2250 | case R_PPC_EMB_SDAI16: | |
2251 | if (info->shared) | |
2252 | { | |
2253 | ((*_bfd_error_handler) | |
2254 | (_("%s: relocation %s cannot be used when making a shared object"), | |
8f615d07 | 2255 | bfd_archive_filename (abfd), "R_PPC_EMB_SDAI16")); |
b34976b6 | 2256 | return FALSE; |
252b5132 RH |
2257 | } |
2258 | ||
2259 | if (srelgot == NULL && (h != NULL || info->shared)) | |
2260 | { | |
2261 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
2262 | if (srelgot == NULL) | |
2263 | { | |
2264 | srelgot = bfd_make_section (dynobj, ".rela.got"); | |
2265 | if (srelgot == NULL | |
2266 | || ! bfd_set_section_flags (dynobj, srelgot, | |
2267 | (SEC_ALLOC | |
2268 | | SEC_LOAD | |
2269 | | SEC_HAS_CONTENTS | |
2270 | | SEC_IN_MEMORY | |
2271 | | SEC_LINKER_CREATED | |
2272 | | SEC_READONLY)) | |
2273 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | |
b34976b6 | 2274 | return FALSE; |
252b5132 RH |
2275 | } |
2276 | } | |
2277 | ||
2278 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel)) | |
b34976b6 | 2279 | return FALSE; |
252b5132 RH |
2280 | |
2281 | break; | |
2282 | ||
2283 | /* Indirect .sdata2 relocation */ | |
2284 | case R_PPC_EMB_SDA2I16: | |
2285 | if (info->shared) | |
2286 | { | |
2287 | ((*_bfd_error_handler) | |
2288 | (_("%s: relocation %s cannot be used when making a shared object"), | |
8f615d07 | 2289 | bfd_archive_filename (abfd), "R_PPC_EMB_SDA2I16")); |
b34976b6 | 2290 | return FALSE; |
252b5132 RH |
2291 | } |
2292 | ||
2293 | if (srelgot == NULL && (h != NULL || info->shared)) | |
2294 | { | |
2295 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
2296 | if (srelgot == NULL) | |
2297 | { | |
2298 | srelgot = bfd_make_section (dynobj, ".rela.got"); | |
2299 | if (srelgot == NULL | |
2300 | || ! bfd_set_section_flags (dynobj, srelgot, | |
2301 | (SEC_ALLOC | |
2302 | | SEC_LOAD | |
2303 | | SEC_HAS_CONTENTS | |
2304 | | SEC_IN_MEMORY | |
2305 | | SEC_LINKER_CREATED | |
2306 | | SEC_READONLY)) | |
2307 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | |
b34976b6 | 2308 | return FALSE; |
252b5132 RH |
2309 | } |
2310 | } | |
2311 | ||
2312 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel)) | |
b34976b6 | 2313 | return FALSE; |
252b5132 RH |
2314 | |
2315 | break; | |
2316 | ||
2317 | case R_PPC_SDAREL16: | |
2318 | case R_PPC_EMB_SDA2REL: | |
2319 | case R_PPC_EMB_SDA21: | |
2320 | if (info->shared) | |
2321 | { | |
2322 | ((*_bfd_error_handler) | |
2323 | (_("%s: relocation %s cannot be used when making a shared object"), | |
8f615d07 | 2324 | bfd_archive_filename (abfd), |
8da6118f | 2325 | ppc_elf_howto_table[(int) ELF32_R_TYPE (rel->r_info)]->name)); |
b34976b6 | 2326 | return FALSE; |
252b5132 RH |
2327 | } |
2328 | break; | |
2329 | ||
2330 | case R_PPC_PLT32: | |
2331 | case R_PPC_PLTREL24: | |
2332 | case R_PPC_PLT16_LO: | |
2333 | case R_PPC_PLT16_HI: | |
2334 | case R_PPC_PLT16_HA: | |
2335 | #ifdef DEBUG | |
2336 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
2337 | #endif | |
2338 | /* This symbol requires a procedure linkage table entry. We | |
2339 | actually build the entry in adjust_dynamic_symbol, | |
2340 | because this might be a case of linking PIC code without | |
2341 | linking in any dynamic objects, in which case we don't | |
2342 | need to generate a procedure linkage table after all. */ | |
2343 | ||
2344 | if (h == NULL) | |
2345 | { | |
2346 | /* It does not make sense to have a procedure linkage | |
2347 | table entry for a local symbol. */ | |
2348 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 2349 | return FALSE; |
252b5132 RH |
2350 | } |
2351 | ||
2352 | /* Make sure this symbol is output as a dynamic symbol. */ | |
2353 | if (h->dynindx == -1) | |
2354 | { | |
2355 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
b34976b6 | 2356 | return FALSE; |
252b5132 | 2357 | } |
51b64d56 AM |
2358 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
2359 | h->plt.refcount++; | |
252b5132 RH |
2360 | break; |
2361 | ||
2362 | /* The following relocations don't need to propagate the | |
2363 | relocation if linking a shared object since they are | |
2364 | section relative. */ | |
2365 | case R_PPC_SECTOFF: | |
2366 | case R_PPC_SECTOFF_LO: | |
2367 | case R_PPC_SECTOFF_HI: | |
2368 | case R_PPC_SECTOFF_HA: | |
2369 | break; | |
2370 | ||
2371 | /* This refers only to functions defined in the shared library */ | |
2372 | case R_PPC_LOCAL24PC: | |
2373 | break; | |
2374 | ||
2375 | /* This relocation describes the C++ object vtable hierarchy. | |
2376 | Reconstruct it for later use during GC. */ | |
2377 | case R_PPC_GNU_VTINHERIT: | |
2378 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
b34976b6 | 2379 | return FALSE; |
252b5132 RH |
2380 | break; |
2381 | ||
2382 | /* This relocation describes which C++ vtable entries are actually | |
2383 | used. Record for later use during GC. */ | |
2384 | case R_PPC_GNU_VTENTRY: | |
2385 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 2386 | return FALSE; |
252b5132 RH |
2387 | break; |
2388 | ||
2389 | /* When creating a shared object, we must copy these | |
2390 | relocs into the output file. We create a reloc | |
2391 | section in dynobj and make room for the reloc. */ | |
2392 | case R_PPC_REL24: | |
2393 | case R_PPC_REL14: | |
2394 | case R_PPC_REL14_BRTAKEN: | |
2395 | case R_PPC_REL14_BRNTAKEN: | |
2396 | case R_PPC_REL32: | |
2397 | if (h == NULL | |
e1e0340b GK |
2398 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
2399 | || SYMBOL_REFERENCES_LOCAL (info, h)) | |
252b5132 RH |
2400 | break; |
2401 | /* fall through */ | |
2402 | ||
2403 | default: | |
2404 | if (info->shared) | |
2405 | { | |
2406 | #ifdef DEBUG | |
2407 | fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n", | |
2408 | (h && h->root.root.string) ? h->root.root.string : "<unknown>"); | |
2409 | #endif | |
2410 | if (sreloc == NULL) | |
2411 | { | |
2412 | const char *name; | |
2413 | ||
2414 | name = (bfd_elf_string_from_elf_section | |
2415 | (abfd, | |
2416 | elf_elfheader (abfd)->e_shstrndx, | |
2417 | elf_section_data (sec)->rel_hdr.sh_name)); | |
2418 | if (name == NULL) | |
b34976b6 | 2419 | return FALSE; |
252b5132 RH |
2420 | |
2421 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
2422 | && strcmp (bfd_get_section_name (abfd, sec), | |
2423 | name + 5) == 0); | |
2424 | ||
2425 | sreloc = bfd_get_section_by_name (dynobj, name); | |
2426 | if (sreloc == NULL) | |
2427 | { | |
2428 | flagword flags; | |
2429 | ||
2430 | sreloc = bfd_make_section (dynobj, name); | |
2431 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
2432 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2433 | if ((sec->flags & SEC_ALLOC) != 0) | |
2434 | flags |= SEC_ALLOC | SEC_LOAD; | |
2435 | if (sreloc == NULL | |
2436 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
2437 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) | |
b34976b6 | 2438 | return FALSE; |
252b5132 | 2439 | } |
29c2fb7c AJ |
2440 | if (sec->flags & SEC_READONLY) |
2441 | info->flags |= DF_TEXTREL; | |
252b5132 RH |
2442 | } |
2443 | ||
2444 | sreloc->_raw_size += sizeof (Elf32_External_Rela); | |
2445 | ||
2446 | /* FIXME: We should here do what the m68k and i386 | |
2447 | backends do: if the reloc is pc-relative, record it | |
2448 | in case it turns out that the reloc is unnecessary | |
2449 | because the symbol is forced local by versioning or | |
2450 | we are linking with -Bdynamic. Fortunately this | |
2451 | case is not frequent. */ | |
2452 | } | |
2453 | ||
2454 | break; | |
2455 | } | |
2456 | } | |
2457 | ||
b34976b6 | 2458 | return TRUE; |
252b5132 RH |
2459 | } |
2460 | ||
2461 | /* Return the section that should be marked against GC for a given | |
2462 | relocation. */ | |
2463 | ||
2464 | static asection * | |
1e2f5b6e AM |
2465 | ppc_elf_gc_mark_hook (sec, info, rel, h, sym) |
2466 | asection *sec; | |
5f771d47 | 2467 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
252b5132 RH |
2468 | Elf_Internal_Rela *rel; |
2469 | struct elf_link_hash_entry *h; | |
2470 | Elf_Internal_Sym *sym; | |
2471 | { | |
2472 | if (h != NULL) | |
2473 | { | |
2474 | switch (ELF32_R_TYPE (rel->r_info)) | |
2475 | { | |
2476 | case R_PPC_GNU_VTINHERIT: | |
2477 | case R_PPC_GNU_VTENTRY: | |
2478 | break; | |
2479 | ||
2480 | default: | |
2481 | switch (h->root.type) | |
2482 | { | |
2483 | case bfd_link_hash_defined: | |
2484 | case bfd_link_hash_defweak: | |
2485 | return h->root.u.def.section; | |
2486 | ||
2487 | case bfd_link_hash_common: | |
2488 | return h->root.u.c.p->section; | |
2489 | ||
2490 | default: | |
2491 | break; | |
2492 | } | |
2493 | } | |
2494 | } | |
2495 | else | |
1e2f5b6e | 2496 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
252b5132 RH |
2497 | |
2498 | return NULL; | |
2499 | } | |
2500 | ||
2501 | /* Update the got entry reference counts for the section being removed. */ | |
2502 | ||
b34976b6 | 2503 | static bfd_boolean |
252b5132 RH |
2504 | ppc_elf_gc_sweep_hook (abfd, info, sec, relocs) |
2505 | bfd *abfd; | |
5f771d47 | 2506 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
252b5132 RH |
2507 | asection *sec; |
2508 | const Elf_Internal_Rela *relocs; | |
2509 | { | |
2510 | Elf_Internal_Shdr *symtab_hdr; | |
2511 | struct elf_link_hash_entry **sym_hashes; | |
2512 | bfd_signed_vma *local_got_refcounts; | |
2513 | const Elf_Internal_Rela *rel, *relend; | |
2514 | unsigned long r_symndx; | |
2515 | struct elf_link_hash_entry *h; | |
2516 | ||
2517 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2518 | sym_hashes = elf_sym_hashes (abfd); | |
2519 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
2520 | ||
2521 | relend = relocs + sec->reloc_count; | |
2522 | for (rel = relocs; rel < relend; rel++) | |
2523 | switch (ELF32_R_TYPE (rel->r_info)) | |
2524 | { | |
2525 | case R_PPC_GOT16: | |
2526 | case R_PPC_GOT16_LO: | |
2527 | case R_PPC_GOT16_HI: | |
2528 | case R_PPC_GOT16_HA: | |
2529 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2530 | if (r_symndx >= symtab_hdr->sh_info) | |
2531 | { | |
2532 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2533 | if (h->got.refcount > 0) | |
2534 | h->got.refcount--; | |
2535 | } | |
dd5724d5 | 2536 | else if (local_got_refcounts != NULL) |
252b5132 RH |
2537 | { |
2538 | if (local_got_refcounts[r_symndx] > 0) | |
2539 | local_got_refcounts[r_symndx]--; | |
2540 | } | |
2541 | break; | |
2542 | ||
2543 | case R_PPC_PLT32: | |
2544 | case R_PPC_PLTREL24: | |
2545 | case R_PPC_PLT16_LO: | |
2546 | case R_PPC_PLT16_HI: | |
2547 | case R_PPC_PLT16_HA: | |
2548 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2549 | if (r_symndx >= symtab_hdr->sh_info) | |
2550 | { | |
2551 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2552 | if (h->plt.refcount > 0) | |
2553 | h->plt.refcount--; | |
2554 | } | |
2555 | break; | |
2556 | ||
2557 | default: | |
2558 | break; | |
2559 | } | |
2560 | ||
b34976b6 | 2561 | return TRUE; |
252b5132 RH |
2562 | } |
2563 | \f | |
2564 | /* Hook called by the linker routine which adds symbols from an object | |
2565 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
2566 | ||
b34976b6 | 2567 | static bfd_boolean |
252b5132 RH |
2568 | ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) |
2569 | bfd *abfd; | |
2570 | struct bfd_link_info *info; | |
2571 | const Elf_Internal_Sym *sym; | |
5f771d47 ILT |
2572 | const char **namep ATTRIBUTE_UNUSED; |
2573 | flagword *flagsp ATTRIBUTE_UNUSED; | |
252b5132 RH |
2574 | asection **secp; |
2575 | bfd_vma *valp; | |
2576 | { | |
2577 | if (sym->st_shndx == SHN_COMMON | |
2578 | && !info->relocateable | |
27242387 AM |
2579 | && sym->st_size <= elf_gp_size (abfd) |
2580 | && info->hash->creator->flavour == bfd_target_elf_flavour) | |
252b5132 RH |
2581 | { |
2582 | /* Common symbols less than or equal to -G nn bytes are automatically | |
2583 | put into .sdata. */ | |
2584 | elf_linker_section_t *sdata | |
2585 | = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA); | |
2586 | ||
2587 | if (!sdata->bss_section) | |
2588 | { | |
dc810e39 AM |
2589 | bfd_size_type amt; |
2590 | ||
252b5132 RH |
2591 | /* We don't go through bfd_make_section, because we don't |
2592 | want to attach this common section to DYNOBJ. The linker | |
2593 | will move the symbols to the appropriate output section | |
2594 | when it defines common symbols. */ | |
dc810e39 AM |
2595 | amt = sizeof (asection); |
2596 | sdata->bss_section = (asection *) bfd_zalloc (abfd, amt); | |
252b5132 | 2597 | if (sdata->bss_section == NULL) |
b34976b6 | 2598 | return FALSE; |
252b5132 RH |
2599 | sdata->bss_section->name = sdata->bss_name; |
2600 | sdata->bss_section->flags = SEC_IS_COMMON; | |
2601 | sdata->bss_section->output_section = sdata->bss_section; | |
dc810e39 AM |
2602 | amt = sizeof (asymbol); |
2603 | sdata->bss_section->symbol = (asymbol *) bfd_zalloc (abfd, amt); | |
2604 | amt = sizeof (asymbol *); | |
252b5132 | 2605 | sdata->bss_section->symbol_ptr_ptr = |
dc810e39 | 2606 | (asymbol **) bfd_zalloc (abfd, amt); |
252b5132 RH |
2607 | if (sdata->bss_section->symbol == NULL |
2608 | || sdata->bss_section->symbol_ptr_ptr == NULL) | |
b34976b6 | 2609 | return FALSE; |
252b5132 RH |
2610 | sdata->bss_section->symbol->name = sdata->bss_name; |
2611 | sdata->bss_section->symbol->flags = BSF_SECTION_SYM; | |
2612 | sdata->bss_section->symbol->section = sdata->bss_section; | |
2613 | *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol; | |
2614 | } | |
2615 | ||
2616 | *secp = sdata->bss_section; | |
2617 | *valp = sym->st_size; | |
2618 | } | |
2619 | ||
b34976b6 | 2620 | return TRUE; |
252b5132 | 2621 | } |
252b5132 RH |
2622 | \f |
2623 | /* Finish up dynamic symbol handling. We set the contents of various | |
2624 | dynamic sections here. */ | |
2625 | ||
b34976b6 | 2626 | static bfd_boolean |
252b5132 RH |
2627 | ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym) |
2628 | bfd *output_bfd; | |
2629 | struct bfd_link_info *info; | |
2630 | struct elf_link_hash_entry *h; | |
2631 | Elf_Internal_Sym *sym; | |
2632 | { | |
2633 | bfd *dynobj; | |
2634 | ||
2635 | #ifdef DEBUG | |
2636 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", | |
2637 | h->root.root.string); | |
2638 | #endif | |
2639 | ||
2640 | dynobj = elf_hash_table (info)->dynobj; | |
2641 | BFD_ASSERT (dynobj != NULL); | |
2642 | ||
2643 | if (h->plt.offset != (bfd_vma) -1) | |
2644 | { | |
2645 | asection *splt; | |
2646 | asection *srela; | |
2647 | Elf_Internal_Rela rela; | |
947216bf | 2648 | bfd_byte *loc; |
252b5132 RH |
2649 | bfd_vma reloc_index; |
2650 | ||
2651 | #ifdef DEBUG | |
2652 | fprintf (stderr, ", plt_offset = %d", h->plt.offset); | |
2653 | #endif | |
2654 | ||
2655 | /* This symbol has an entry in the procedure linkage table. Set | |
2656 | it up. */ | |
2657 | ||
2658 | BFD_ASSERT (h->dynindx != -1); | |
2659 | ||
2660 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
2661 | srela = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
2662 | BFD_ASSERT (splt != NULL && srela != NULL); | |
2663 | ||
2664 | /* We don't need to fill in the .plt. The ppc dynamic linker | |
2665 | will fill it in. */ | |
2666 | ||
2667 | /* Fill in the entry in the .rela.plt section. */ | |
2668 | rela.r_offset = (splt->output_section->vma | |
2669 | + splt->output_offset | |
2670 | + h->plt.offset); | |
2671 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); | |
2672 | rela.r_addend = 0; | |
2673 | ||
2674 | reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE; | |
2675 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES) | |
2676 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; | |
947216bf AM |
2677 | loc = srela->contents + reloc_index * sizeof (Elf32_External_Rela); |
2678 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
252b5132 RH |
2679 | |
2680 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
2681 | { | |
2682 | /* Mark the symbol as undefined, rather than as defined in | |
2683 | the .plt section. Leave the value alone. */ | |
2684 | sym->st_shndx = SHN_UNDEF; | |
a4b120e1 GK |
2685 | /* If the symbol is weak, we do need to clear the value. |
2686 | Otherwise, the PLT entry would provide a definition for | |
2687 | the symbol even if the symbol wasn't defined anywhere, | |
2688 | and so the symbol would never be NULL. */ | |
c3668558 | 2689 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK) |
a4b120e1 GK |
2690 | == 0) |
2691 | sym->st_value = 0; | |
252b5132 RH |
2692 | } |
2693 | } | |
2694 | ||
2695 | if (h->got.offset != (bfd_vma) -1) | |
2696 | { | |
2697 | asection *sgot; | |
2698 | asection *srela; | |
2699 | Elf_Internal_Rela rela; | |
947216bf | 2700 | bfd_byte *loc; |
252b5132 RH |
2701 | |
2702 | /* This symbol has an entry in the global offset table. Set it | |
2703 | up. */ | |
2704 | ||
2705 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
2706 | srela = bfd_get_section_by_name (dynobj, ".rela.got"); | |
2707 | BFD_ASSERT (sgot != NULL && srela != NULL); | |
2708 | ||
2709 | rela.r_offset = (sgot->output_section->vma | |
2710 | + sgot->output_offset | |
dc810e39 | 2711 | + (h->got.offset &~ (bfd_vma) 1)); |
252b5132 RH |
2712 | |
2713 | /* If this is a -Bsymbolic link, and the symbol is defined | |
2714 | locally, we just want to emit a RELATIVE reloc. The entry in | |
2715 | the global offset table will already have been initialized in | |
2716 | the relocate_section function. */ | |
2717 | if (info->shared | |
e1e0340b | 2718 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
252b5132 RH |
2719 | { |
2720 | rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
2721 | rela.r_addend = (h->root.u.def.value | |
2722 | + h->root.u.def.section->output_section->vma | |
2723 | + h->root.u.def.section->output_offset); | |
2724 | } | |
2725 | else | |
2726 | { | |
8da6118f | 2727 | BFD_ASSERT ((h->got.offset & 1) == 0); |
252b5132 RH |
2728 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT); |
2729 | rela.r_addend = 0; | |
2730 | } | |
2731 | ||
2243deae | 2732 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
947216bf AM |
2733 | loc = srela->contents; |
2734 | loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); | |
2735 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
252b5132 RH |
2736 | } |
2737 | ||
2738 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
2739 | { | |
2740 | asection *s; | |
2741 | Elf_Internal_Rela rela; | |
947216bf | 2742 | bfd_byte *loc; |
252b5132 RH |
2743 | |
2744 | /* This symbols needs a copy reloc. Set it up. */ | |
2745 | ||
2746 | #ifdef DEBUG | |
2747 | fprintf (stderr, ", copy"); | |
2748 | #endif | |
2749 | ||
2750 | BFD_ASSERT (h->dynindx != -1); | |
2751 | ||
2752 | if (h->size <= elf_gp_size (dynobj)) | |
2753 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
2754 | ".rela.sbss"); | |
2755 | else | |
2756 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
2757 | ".rela.bss"); | |
2758 | BFD_ASSERT (s != NULL); | |
2759 | ||
2760 | rela.r_offset = (h->root.u.def.value | |
2761 | + h->root.u.def.section->output_section->vma | |
2762 | + h->root.u.def.section->output_offset); | |
2763 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); | |
2764 | rela.r_addend = 0; | |
947216bf AM |
2765 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); |
2766 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
252b5132 RH |
2767 | } |
2768 | ||
2769 | #ifdef DEBUG | |
2770 | fprintf (stderr, "\n"); | |
2771 | #endif | |
2772 | ||
2773 | /* Mark some specially defined symbols as absolute. */ | |
2774 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
2775 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 | |
2776 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) | |
2777 | sym->st_shndx = SHN_ABS; | |
2778 | ||
b34976b6 | 2779 | return TRUE; |
252b5132 | 2780 | } |
252b5132 RH |
2781 | \f |
2782 | /* Finish up the dynamic sections. */ | |
2783 | ||
b34976b6 | 2784 | static bfd_boolean |
252b5132 RH |
2785 | ppc_elf_finish_dynamic_sections (output_bfd, info) |
2786 | bfd *output_bfd; | |
2787 | struct bfd_link_info *info; | |
2788 | { | |
2789 | asection *sdyn; | |
2790 | bfd *dynobj = elf_hash_table (info)->dynobj; | |
2791 | asection *sgot = bfd_get_section_by_name (dynobj, ".got"); | |
2792 | ||
2793 | #ifdef DEBUG | |
2794 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
2795 | #endif | |
2796 | ||
2797 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
2798 | ||
2799 | if (elf_hash_table (info)->dynamic_sections_created) | |
2800 | { | |
2801 | asection *splt; | |
2802 | Elf32_External_Dyn *dyncon, *dynconend; | |
2803 | ||
2804 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
2805 | BFD_ASSERT (splt != NULL && sdyn != NULL); | |
2806 | ||
2807 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
2808 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
2809 | for (; dyncon < dynconend; dyncon++) | |
2810 | { | |
2811 | Elf_Internal_Dyn dyn; | |
2812 | const char *name; | |
b34976b6 | 2813 | bfd_boolean size; |
252b5132 RH |
2814 | |
2815 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
2816 | ||
2817 | switch (dyn.d_tag) | |
2818 | { | |
b34976b6 AM |
2819 | case DT_PLTGOT: name = ".plt"; size = FALSE; break; |
2820 | case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break; | |
2821 | case DT_JMPREL: name = ".rela.plt"; size = FALSE; break; | |
2822 | default: name = NULL; size = FALSE; break; | |
252b5132 RH |
2823 | } |
2824 | ||
2825 | if (name != NULL) | |
2826 | { | |
2827 | asection *s; | |
2828 | ||
2829 | s = bfd_get_section_by_name (output_bfd, name); | |
2830 | if (s == NULL) | |
2831 | dyn.d_un.d_val = 0; | |
2832 | else | |
2833 | { | |
2834 | if (! size) | |
2835 | dyn.d_un.d_ptr = s->vma; | |
2836 | else | |
2837 | { | |
2838 | if (s->_cooked_size != 0) | |
2839 | dyn.d_un.d_val = s->_cooked_size; | |
2840 | else | |
2841 | dyn.d_un.d_val = s->_raw_size; | |
2842 | } | |
2843 | } | |
2844 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
2845 | } | |
2846 | } | |
2847 | } | |
2848 | ||
2849 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can | |
2850 | easily find the address of the _GLOBAL_OFFSET_TABLE_. */ | |
2851 | if (sgot) | |
2852 | { | |
2853 | unsigned char *contents = sgot->contents; | |
dc810e39 | 2854 | bfd_put_32 (output_bfd, (bfd_vma) 0x4e800021 /* blrl */, contents); |
252b5132 RH |
2855 | |
2856 | if (sdyn == NULL) | |
2857 | bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4); | |
2858 | else | |
2859 | bfd_put_32 (output_bfd, | |
2860 | sdyn->output_section->vma + sdyn->output_offset, | |
2861 | contents+4); | |
2862 | ||
2863 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; | |
2864 | } | |
2865 | ||
b34976b6 | 2866 | return TRUE; |
252b5132 | 2867 | } |
252b5132 RH |
2868 | \f |
2869 | /* The RELOCATE_SECTION function is called by the ELF backend linker | |
2870 | to handle the relocations for a section. | |
2871 | ||
2872 | The relocs are always passed as Rela structures; if the section | |
2873 | actually uses Rel structures, the r_addend field will always be | |
2874 | zero. | |
2875 | ||
2876 | This function is responsible for adjust the section contents as | |
2877 | necessary, and (if using Rela relocs and generating a | |
2878 | relocateable output file) adjusting the reloc addend as | |
2879 | necessary. | |
2880 | ||
2881 | This function does not have to worry about setting the reloc | |
2882 | address or the reloc symbol index. | |
2883 | ||
2884 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
2885 | ||
2886 | LOCAL_SECTIONS is an array giving the section in the input file | |
2887 | corresponding to the st_shndx field of each local symbol. | |
2888 | ||
2889 | The global hash table entry for the global symbols can be found | |
2890 | via elf_sym_hashes (input_bfd). | |
2891 | ||
2892 | When generating relocateable output, this function must handle | |
2893 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is | |
2894 | going to be the section symbol corresponding to the output | |
2895 | section, which means that the addend must be adjusted | |
2896 | accordingly. */ | |
2897 | ||
b34976b6 | 2898 | static bfd_boolean |
252b5132 RH |
2899 | ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section, |
2900 | contents, relocs, local_syms, local_sections) | |
2901 | bfd *output_bfd; | |
2902 | struct bfd_link_info *info; | |
2903 | bfd *input_bfd; | |
2904 | asection *input_section; | |
2905 | bfd_byte *contents; | |
2906 | Elf_Internal_Rela *relocs; | |
2907 | Elf_Internal_Sym *local_syms; | |
2908 | asection **local_sections; | |
2909 | { | |
b34976b6 | 2910 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
252b5132 | 2911 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); |
b34976b6 AM |
2912 | bfd *dynobj = elf_hash_table (info)->dynobj; |
2913 | elf_linker_section_t *sdata = NULL; | |
2914 | elf_linker_section_t *sdata2 = NULL; | |
2915 | Elf_Internal_Rela *rel = relocs; | |
2916 | Elf_Internal_Rela *relend = relocs + input_section->reloc_count; | |
2917 | asection *sreloc = NULL; | |
252b5132 RH |
2918 | asection *splt; |
2919 | asection *sgot; | |
2920 | bfd_vma *local_got_offsets; | |
b34976b6 | 2921 | bfd_boolean ret = TRUE; |
252b5132 RH |
2922 | long insn; |
2923 | ||
b34976b6 AM |
2924 | if (dynobj) |
2925 | { | |
2926 | sdata = elf_linker_section (dynobj, LINKER_SECTION_SDATA); | |
2927 | sdata2 = elf_linker_section (dynobj, LINKER_SECTION_SDATA2); | |
2928 | } | |
2929 | ||
252b5132 RH |
2930 | #ifdef DEBUG |
2931 | fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n", | |
8f615d07 | 2932 | bfd_archive_filename (input_bfd), |
252b5132 | 2933 | bfd_section_name(input_bfd, input_section), |
8da6118f | 2934 | (long) input_section->reloc_count, |
252b5132 RH |
2935 | (info->relocateable) ? " (relocatable)" : ""); |
2936 | #endif | |
2937 | ||
b491616a | 2938 | if (info->relocateable) |
b34976b6 | 2939 | return TRUE; |
b491616a | 2940 | |
8da6118f KH |
2941 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
2942 | /* Initialize howto table if needed. */ | |
252b5132 RH |
2943 | ppc_elf_howto_init (); |
2944 | ||
2945 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
2946 | ||
2947 | splt = sgot = NULL; | |
2948 | if (dynobj != NULL) | |
2949 | { | |
2950 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
2951 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
2952 | } | |
2953 | ||
2954 | for (; rel < relend; rel++) | |
2955 | { | |
2956 | enum elf_ppc_reloc_type r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info); | |
2957 | bfd_vma offset = rel->r_offset; | |
2958 | bfd_vma addend = rel->r_addend; | |
2959 | bfd_reloc_status_type r = bfd_reloc_other; | |
8da6118f KH |
2960 | Elf_Internal_Sym *sym = (Elf_Internal_Sym *) 0; |
2961 | asection *sec = (asection *) 0; | |
2962 | struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) 0; | |
2963 | const char *sym_name = (const char *) 0; | |
252b5132 RH |
2964 | reloc_howto_type *howto; |
2965 | unsigned long r_symndx; | |
2966 | bfd_vma relocation; | |
e1e0340b | 2967 | int will_become_local; |
252b5132 RH |
2968 | |
2969 | /* Unknown relocation handling */ | |
8da6118f KH |
2970 | if ((unsigned) r_type >= (unsigned) R_PPC_max |
2971 | || !ppc_elf_howto_table[(int) r_type]) | |
252b5132 RH |
2972 | { |
2973 | (*_bfd_error_handler) (_("%s: unknown relocation type %d"), | |
8f615d07 | 2974 | bfd_archive_filename (input_bfd), |
8da6118f | 2975 | (int) r_type); |
252b5132 RH |
2976 | |
2977 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 2978 | ret = FALSE; |
252b5132 RH |
2979 | continue; |
2980 | } | |
2981 | ||
8da6118f | 2982 | howto = ppc_elf_howto_table[(int) r_type]; |
252b5132 RH |
2983 | r_symndx = ELF32_R_SYM (rel->r_info); |
2984 | ||
252b5132 RH |
2985 | if (r_symndx < symtab_hdr->sh_info) |
2986 | { | |
2987 | sym = local_syms + r_symndx; | |
2988 | sec = local_sections[r_symndx]; | |
2989 | sym_name = "<local symbol>"; | |
2990 | ||
f8df10f4 JJ |
2991 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
2992 | addend = rel->r_addend; | |
e1e0340b GK |
2993 | /* Relocs to local symbols are always resolved. */ |
2994 | will_become_local = 1; | |
252b5132 RH |
2995 | } |
2996 | else | |
2997 | { | |
2998 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2999 | while (h->root.type == bfd_link_hash_indirect | |
3000 | || h->root.type == bfd_link_hash_warning) | |
3001 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3002 | sym_name = h->root.root.string; | |
e1e0340b GK |
3003 | |
3004 | /* Can this relocation be resolved immediately? */ | |
3005 | will_become_local = SYMBOL_REFERENCES_LOCAL (info, h); | |
3006 | ||
252b5132 RH |
3007 | if (h->root.type == bfd_link_hash_defined |
3008 | || h->root.type == bfd_link_hash_defweak) | |
3009 | { | |
3010 | sec = h->root.u.def.section; | |
e1e0340b GK |
3011 | if (((r_type == R_PPC_PLT32 |
3012 | || r_type == R_PPC_PLTREL24) | |
dd5724d5 | 3013 | && splt != NULL |
252b5132 RH |
3014 | && h->plt.offset != (bfd_vma) -1) |
3015 | || (r_type == R_PPC_LOCAL24PC | |
3016 | && sec->output_section == NULL) | |
3017 | || ((r_type == R_PPC_GOT16 | |
3018 | || r_type == R_PPC_GOT16_LO | |
3019 | || r_type == R_PPC_GOT16_HI | |
3020 | || r_type == R_PPC_GOT16_HA) | |
3021 | && elf_hash_table (info)->dynamic_sections_created | |
e1e0340b | 3022 | && (! info->shared || ! will_become_local)) |
252b5132 | 3023 | || (info->shared |
e1e0340b | 3024 | && ! will_become_local |
2d146250 ILT |
3025 | && ((input_section->flags & SEC_ALLOC) != 0 |
3026 | /* Testing SEC_DEBUGGING here may be wrong. | |
3027 | It's here to avoid a crash when | |
3028 | generating a shared library with DWARF | |
3029 | debugging information. */ | |
1319985e AM |
3030 | || ((input_section->flags & SEC_DEBUGGING) != 0 |
3031 | && (h->elf_link_hash_flags | |
3032 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) | |
252b5132 RH |
3033 | && (r_type == R_PPC_ADDR32 |
3034 | || r_type == R_PPC_ADDR24 | |
3035 | || r_type == R_PPC_ADDR16 | |
3036 | || r_type == R_PPC_ADDR16_LO | |
3037 | || r_type == R_PPC_ADDR16_HI | |
3038 | || r_type == R_PPC_ADDR16_HA | |
3039 | || r_type == R_PPC_ADDR14 | |
3040 | || r_type == R_PPC_ADDR14_BRTAKEN | |
3041 | || r_type == R_PPC_ADDR14_BRNTAKEN | |
252b5132 RH |
3042 | || r_type == R_PPC_COPY |
3043 | || r_type == R_PPC_GLOB_DAT | |
3044 | || r_type == R_PPC_JMP_SLOT | |
3045 | || r_type == R_PPC_UADDR32 | |
3046 | || r_type == R_PPC_UADDR16 | |
3047 | || r_type == R_PPC_SDAREL16 | |
3048 | || r_type == R_PPC_EMB_NADDR32 | |
3049 | || r_type == R_PPC_EMB_NADDR16 | |
3050 | || r_type == R_PPC_EMB_NADDR16_LO | |
3051 | || r_type == R_PPC_EMB_NADDR16_HI | |
3052 | || r_type == R_PPC_EMB_NADDR16_HA | |
3053 | || r_type == R_PPC_EMB_SDAI16 | |
3054 | || r_type == R_PPC_EMB_SDA2I16 | |
3055 | || r_type == R_PPC_EMB_SDA2REL | |
3056 | || r_type == R_PPC_EMB_SDA21 | |
3057 | || r_type == R_PPC_EMB_MRKREF | |
3058 | || r_type == R_PPC_EMB_BIT_FLD | |
3059 | || r_type == R_PPC_EMB_RELSDA | |
3060 | || ((r_type == R_PPC_REL24 | |
3061 | || r_type == R_PPC_REL32 | |
3062 | || r_type == R_PPC_REL14 | |
3063 | || r_type == R_PPC_REL14_BRTAKEN | |
3064 | || r_type == R_PPC_REL14_BRNTAKEN | |
3065 | || r_type == R_PPC_RELATIVE) | |
3066 | && strcmp (h->root.root.string, | |
3067 | "_GLOBAL_OFFSET_TABLE_") != 0)))) | |
3068 | { | |
3069 | /* In these cases, we don't need the relocation | |
3070 | value. We check specially because in some | |
3071 | obscure cases sec->output_section will be NULL. */ | |
3072 | relocation = 0; | |
3073 | } | |
2d146250 | 3074 | else if (sec->output_section == NULL) |
8da6118f | 3075 | { |
2d146250 ILT |
3076 | (*_bfd_error_handler) |
3077 | (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"), | |
8f615d07 | 3078 | bfd_archive_filename (input_bfd), h->root.root.string, |
2d146250 ILT |
3079 | bfd_get_section_name (input_bfd, input_section)); |
3080 | relocation = 0; | |
8da6118f | 3081 | } |
252b5132 RH |
3082 | else |
3083 | relocation = (h->root.u.def.value | |
3084 | + sec->output_section->vma | |
3085 | + sec->output_offset); | |
3086 | } | |
3087 | else if (h->root.type == bfd_link_hash_undefweak) | |
3088 | relocation = 0; | |
671bae9c NC |
3089 | else if (info->shared |
3090 | && (!info->symbolic || info->allow_shlib_undefined) | |
3091 | && !info->no_undefined | |
3a27a730 | 3092 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
252b5132 RH |
3093 | relocation = 0; |
3094 | else | |
3095 | { | |
c3668558 | 3096 | if (! (*info->callbacks->undefined_symbol) (info, |
464e1740 ILT |
3097 | h->root.root.string, |
3098 | input_bfd, | |
3099 | input_section, | |
5cc7c785 L |
3100 | rel->r_offset, |
3101 | (!info->shared | |
3a27a730 | 3102 | || info->no_undefined |
ba09750c | 3103 | || ELF_ST_VISIBILITY (h->other)))) |
b34976b6 | 3104 | return FALSE; |
464e1740 | 3105 | relocation = 0; |
252b5132 RH |
3106 | } |
3107 | } | |
3108 | ||
8da6118f | 3109 | switch ((int) r_type) |
252b5132 RH |
3110 | { |
3111 | default: | |
3112 | (*_bfd_error_handler) (_("%s: unknown relocation type %d for symbol %s"), | |
8f615d07 | 3113 | bfd_archive_filename (input_bfd), |
8da6118f | 3114 | (int) r_type, sym_name); |
252b5132 RH |
3115 | |
3116 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 3117 | ret = FALSE; |
252b5132 RH |
3118 | continue; |
3119 | ||
7595d193 L |
3120 | case (int) R_PPC_NONE: |
3121 | continue; | |
3122 | ||
252b5132 | 3123 | /* Relocations that need no special processing. */ |
8da6118f | 3124 | case (int) R_PPC_LOCAL24PC: |
252b5132 RH |
3125 | /* It makes no sense to point a local relocation |
3126 | at a symbol not in this object. */ | |
3127 | if (h != NULL | |
3128 | && (h->root.type == bfd_link_hash_defined | |
3129 | || h->root.type == bfd_link_hash_defweak) | |
3130 | && sec->output_section == NULL) | |
3131 | { | |
464e1740 ILT |
3132 | if (! (*info->callbacks->undefined_symbol) (info, |
3133 | h->root.root.string, | |
3134 | input_bfd, | |
3135 | input_section, | |
5cc7c785 | 3136 | rel->r_offset, |
b34976b6 AM |
3137 | TRUE)) |
3138 | return FALSE; | |
252b5132 RH |
3139 | continue; |
3140 | } | |
3141 | break; | |
3142 | ||
3143 | /* Relocations that may need to be propagated if this is a shared | |
3144 | object. */ | |
8da6118f KH |
3145 | case (int) R_PPC_REL24: |
3146 | case (int) R_PPC_REL32: | |
3147 | case (int) R_PPC_REL14: | |
252b5132 RH |
3148 | /* If these relocations are not to a named symbol, they can be |
3149 | handled right here, no need to bother the dynamic linker. */ | |
3150 | if (h == NULL | |
e1e0340b GK |
3151 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
3152 | || SYMBOL_REFERENCES_LOCAL (info, h)) | |
252b5132 RH |
3153 | break; |
3154 | /* fall through */ | |
3155 | ||
3156 | /* Relocations that always need to be propagated if this is a shared | |
3157 | object. */ | |
8da6118f KH |
3158 | case (int) R_PPC_ADDR32: |
3159 | case (int) R_PPC_ADDR24: | |
3160 | case (int) R_PPC_ADDR16: | |
3161 | case (int) R_PPC_ADDR16_LO: | |
3162 | case (int) R_PPC_ADDR16_HI: | |
3163 | case (int) R_PPC_ADDR16_HA: | |
3164 | case (int) R_PPC_ADDR14: | |
3165 | case (int) R_PPC_UADDR32: | |
3166 | case (int) R_PPC_UADDR16: | |
ec338859 | 3167 | if (info->shared && r_symndx != 0) |
252b5132 RH |
3168 | { |
3169 | Elf_Internal_Rela outrel; | |
947216bf | 3170 | bfd_byte *loc; |
0bb2d96a | 3171 | int skip; |
252b5132 RH |
3172 | |
3173 | #ifdef DEBUG | |
3174 | fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n", | |
3175 | (h && h->root.root.string) ? h->root.root.string : "<unknown>"); | |
3176 | #endif | |
3177 | ||
3178 | /* When generating a shared object, these relocations | |
3179 | are copied into the output file to be resolved at run | |
3180 | time. */ | |
3181 | ||
3182 | if (sreloc == NULL) | |
3183 | { | |
3184 | const char *name; | |
3185 | ||
3186 | name = (bfd_elf_string_from_elf_section | |
3187 | (input_bfd, | |
3188 | elf_elfheader (input_bfd)->e_shstrndx, | |
3189 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
3190 | if (name == NULL) | |
b34976b6 | 3191 | return FALSE; |
252b5132 RH |
3192 | |
3193 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
3194 | && strcmp (bfd_get_section_name (input_bfd, | |
3195 | input_section), | |
3196 | name + 5) == 0); | |
3197 | ||
3198 | sreloc = bfd_get_section_by_name (dynobj, name); | |
3199 | BFD_ASSERT (sreloc != NULL); | |
3200 | } | |
3201 | ||
0bb2d96a | 3202 | skip = 0; |
252b5132 | 3203 | |
c629eae0 JJ |
3204 | outrel.r_offset = |
3205 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
3206 | rel->r_offset); | |
0bb2d96a JJ |
3207 | if (outrel.r_offset == (bfd_vma) -1 |
3208 | || outrel.r_offset == (bfd_vma) -2) | |
3209 | skip = (int) outrel.r_offset; | |
252b5132 RH |
3210 | outrel.r_offset += (input_section->output_section->vma |
3211 | + input_section->output_offset); | |
3212 | ||
3213 | if (skip) | |
3214 | memset (&outrel, 0, sizeof outrel); | |
3215 | /* h->dynindx may be -1 if this symbol was marked to | |
3216 | become local. */ | |
e1e0340b | 3217 | else if (! will_become_local) |
252b5132 | 3218 | { |
252b5132 RH |
3219 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
3220 | outrel.r_addend = rel->r_addend; | |
3221 | } | |
3222 | else | |
3223 | { | |
3224 | if (r_type == R_PPC_ADDR32) | |
3225 | { | |
3226 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
3227 | outrel.r_addend = relocation + rel->r_addend; | |
3228 | } | |
3229 | else | |
3230 | { | |
3231 | long indx; | |
3232 | ||
3233 | if (h == NULL) | |
3234 | sec = local_sections[r_symndx]; | |
3235 | else | |
3236 | { | |
3237 | BFD_ASSERT (h->root.type == bfd_link_hash_defined | |
3238 | || (h->root.type | |
3239 | == bfd_link_hash_defweak)); | |
3240 | sec = h->root.u.def.section; | |
3241 | } | |
3242 | if (sec != NULL && bfd_is_abs_section (sec)) | |
3243 | indx = 0; | |
3244 | else if (sec == NULL || sec->owner == NULL) | |
3245 | { | |
3246 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 3247 | return FALSE; |
252b5132 RH |
3248 | } |
3249 | else | |
3250 | { | |
3251 | asection *osec; | |
3252 | ||
3253 | osec = sec->output_section; | |
3254 | indx = elf_section_data (osec)->dynindx; | |
8da6118f | 3255 | BFD_ASSERT (indx > 0); |
252b5132 RH |
3256 | #ifdef DEBUG |
3257 | if (indx <= 0) | |
3258 | { | |
c3668558 | 3259 | printf ("indx=%d section=%s flags=%08x name=%s\n", |
252b5132 RH |
3260 | indx, osec->name, osec->flags, |
3261 | h->root.root.string); | |
3262 | } | |
3263 | #endif | |
3264 | } | |
3265 | ||
3266 | outrel.r_info = ELF32_R_INFO (indx, r_type); | |
3267 | outrel.r_addend = relocation + rel->r_addend; | |
3268 | } | |
3269 | } | |
3270 | ||
947216bf AM |
3271 | loc = sreloc->contents; |
3272 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
3273 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 | 3274 | |
2243deae | 3275 | if (skip == -1) |
252b5132 | 3276 | continue; |
2243deae L |
3277 | |
3278 | /* This reloc will be computed at runtime. We clear the memory | |
3279 | so that it contains predictable value. */ | |
3280 | if (! skip | |
3281 | && ((input_section->flags & SEC_ALLOC) != 0 | |
3282 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)) | |
3283 | { | |
3284 | relocation = howto->pc_relative ? outrel.r_offset : 0; | |
3285 | addend = 0; | |
3286 | break; | |
3287 | } | |
252b5132 RH |
3288 | } |
3289 | ||
3290 | /* Arithmetic adjust relocations that aren't going into a | |
3291 | shared object. */ | |
3292 | if (r_type == R_PPC_ADDR16_HA | |
3293 | /* It's just possible that this symbol is a weak symbol | |
3294 | that's not actually defined anywhere. In that case, | |
3295 | 'sec' would be NULL, and we should leave the symbol | |
3296 | alone (it will be set to zero elsewhere in the link). */ | |
3297 | && sec != NULL) | |
3298 | { | |
3299 | addend += ((relocation + addend) & 0x8000) << 1; | |
3300 | } | |
3301 | break; | |
3302 | ||
3303 | /* branch taken prediction relocations */ | |
8da6118f KH |
3304 | case (int) R_PPC_ADDR14_BRTAKEN: |
3305 | case (int) R_PPC_REL14_BRTAKEN: | |
252b5132 RH |
3306 | insn = bfd_get_32 (output_bfd, contents + offset); |
3307 | if ((relocation - offset) & 0x8000) | |
3308 | insn &= ~BRANCH_PREDICT_BIT; | |
3309 | else | |
3310 | insn |= BRANCH_PREDICT_BIT; | |
dc810e39 | 3311 | bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset); |
252b5132 RH |
3312 | break; |
3313 | ||
3314 | /* branch not taken predicition relocations */ | |
8da6118f KH |
3315 | case (int) R_PPC_ADDR14_BRNTAKEN: |
3316 | case (int) R_PPC_REL14_BRNTAKEN: | |
252b5132 RH |
3317 | insn = bfd_get_32 (output_bfd, contents + offset); |
3318 | if ((relocation - offset) & 0x8000) | |
3319 | insn |= BRANCH_PREDICT_BIT; | |
3320 | else | |
3321 | insn &= ~BRANCH_PREDICT_BIT; | |
dc810e39 | 3322 | bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset); |
252b5132 RH |
3323 | break; |
3324 | ||
3325 | /* GOT16 relocations */ | |
8da6118f KH |
3326 | case (int) R_PPC_GOT16: |
3327 | case (int) R_PPC_GOT16_LO: | |
3328 | case (int) R_PPC_GOT16_HI: | |
3329 | case (int) R_PPC_GOT16_HA: | |
252b5132 RH |
3330 | /* Relocation is to the entry for this symbol in the global |
3331 | offset table. */ | |
3332 | BFD_ASSERT (sgot != NULL); | |
3333 | ||
3334 | if (h != NULL) | |
3335 | { | |
3336 | bfd_vma off; | |
3337 | ||
3338 | off = h->got.offset; | |
3339 | BFD_ASSERT (off != (bfd_vma) -1); | |
3340 | ||
3341 | if (! elf_hash_table (info)->dynamic_sections_created | |
3342 | || (info->shared | |
e1e0340b | 3343 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
252b5132 RH |
3344 | { |
3345 | /* This is actually a static link, or it is a | |
3346 | -Bsymbolic link and the symbol is defined | |
3347 | locally. We must initialize this entry in the | |
3348 | global offset table. Since the offset must | |
3349 | always be a multiple of 4, we use the least | |
3350 | significant bit to record whether we have | |
3351 | initialized it already. | |
3352 | ||
3353 | When doing a dynamic link, we create a .rela.got | |
3354 | relocation entry to initialize the value. This | |
3355 | is done in the finish_dynamic_symbol routine. */ | |
3356 | if ((off & 1) != 0) | |
3357 | off &= ~1; | |
3358 | else | |
3359 | { | |
3360 | bfd_put_32 (output_bfd, relocation, | |
3361 | sgot->contents + off); | |
3362 | h->got.offset |= 1; | |
3363 | } | |
3364 | } | |
3365 | ||
3366 | relocation = sgot->output_offset + off - 4; | |
3367 | } | |
3368 | else | |
3369 | { | |
3370 | bfd_vma off; | |
3371 | ||
3372 | BFD_ASSERT (local_got_offsets != NULL | |
3373 | && local_got_offsets[r_symndx] != (bfd_vma) -1); | |
3374 | ||
3375 | off = local_got_offsets[r_symndx]; | |
3376 | ||
3377 | /* The offset must always be a multiple of 4. We use | |
3378 | the least significant bit to record whether we have | |
3379 | already processed this entry. */ | |
3380 | if ((off & 1) != 0) | |
3381 | off &= ~1; | |
3382 | else | |
3383 | { | |
252b5132 RH |
3384 | |
3385 | if (info->shared) | |
3386 | { | |
3387 | asection *srelgot; | |
3388 | Elf_Internal_Rela outrel; | |
947216bf | 3389 | bfd_byte *loc; |
252b5132 RH |
3390 | |
3391 | /* We need to generate a R_PPC_RELATIVE reloc | |
3392 | for the dynamic linker. */ | |
3393 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
3394 | BFD_ASSERT (srelgot != NULL); | |
3395 | ||
3396 | outrel.r_offset = (sgot->output_section->vma | |
3397 | + sgot->output_offset | |
3398 | + off); | |
3399 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
3400 | outrel.r_addend = relocation; | |
947216bf AM |
3401 | loc = srelgot->contents; |
3402 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela); | |
3403 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
2243deae | 3404 | relocation = 0; |
252b5132 RH |
3405 | } |
3406 | ||
2243deae | 3407 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); |
252b5132 RH |
3408 | local_got_offsets[r_symndx] |= 1; |
3409 | } | |
3410 | ||
3411 | relocation = sgot->output_offset + off - 4; | |
3412 | } | |
3413 | break; | |
3414 | ||
3415 | /* Indirect .sdata relocation */ | |
8da6118f | 3416 | case (int) R_PPC_EMB_SDAI16: |
252b5132 RH |
3417 | BFD_ASSERT (sdata != NULL); |
3418 | relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info, | |
3419 | sdata, h, relocation, rel, | |
3420 | R_PPC_RELATIVE); | |
3421 | break; | |
3422 | ||
3423 | /* Indirect .sdata2 relocation */ | |
8da6118f | 3424 | case (int) R_PPC_EMB_SDA2I16: |
252b5132 RH |
3425 | BFD_ASSERT (sdata2 != NULL); |
3426 | relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info, | |
3427 | sdata2, h, relocation, rel, | |
3428 | R_PPC_RELATIVE); | |
3429 | break; | |
3430 | ||
3431 | /* Handle the TOC16 reloc. We want to use the offset within the .got | |
3432 | section, not the actual VMA. This is appropriate when generating | |
3433 | an embedded ELF object, for which the .got section acts like the | |
3434 | AIX .toc section. */ | |
8da6118f KH |
3435 | case (int) R_PPC_TOC16: /* phony GOT16 relocations */ |
3436 | BFD_ASSERT (sec != (asection *) 0); | |
252b5132 RH |
3437 | BFD_ASSERT (bfd_is_und_section (sec) |
3438 | || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 | |
3439 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0) | |
3440 | ||
3441 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; | |
3442 | break; | |
3443 | ||
8da6118f | 3444 | case (int) R_PPC_PLTREL24: |
252b5132 RH |
3445 | /* Relocation is to the entry for this symbol in the |
3446 | procedure linkage table. */ | |
3447 | BFD_ASSERT (h != NULL); | |
3448 | ||
3449 | if (h->plt.offset == (bfd_vma) -1 | |
3450 | || splt == NULL) | |
3451 | { | |
3452 | /* We didn't make a PLT entry for this symbol. This | |
3453 | happens when statically linking PIC code, or when | |
3454 | using -Bsymbolic. */ | |
3455 | break; | |
3456 | } | |
3457 | ||
3458 | relocation = (splt->output_section->vma | |
3459 | + splt->output_offset | |
3460 | + h->plt.offset); | |
8da6118f | 3461 | break; |
252b5132 RH |
3462 | |
3463 | /* relocate against _SDA_BASE_ */ | |
8da6118f | 3464 | case (int) R_PPC_SDAREL16: |
252b5132 RH |
3465 | { |
3466 | const char *name; | |
3467 | ||
8da6118f | 3468 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 | 3469 | name = bfd_get_section_name (abfd, sec->output_section); |
5f819128 AM |
3470 | if (! ((strncmp (name, ".sdata", 6) == 0 |
3471 | && (name[6] == 0 || name[6] == '.')) | |
3472 | || (strncmp (name, ".sbss", 5) == 0 | |
3473 | && (name[5] == 0 || name[5] == '.')))) | |
252b5132 RH |
3474 | { |
3475 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"), | |
8f615d07 | 3476 | bfd_archive_filename (input_bfd), |
252b5132 | 3477 | sym_name, |
8da6118f | 3478 | ppc_elf_howto_table[(int) r_type]->name, |
252b5132 RH |
3479 | name); |
3480 | } | |
3481 | addend -= (sdata->sym_hash->root.u.def.value | |
3482 | + sdata->sym_hash->root.u.def.section->output_section->vma | |
3483 | + sdata->sym_hash->root.u.def.section->output_offset); | |
3484 | } | |
3485 | break; | |
3486 | ||
252b5132 | 3487 | /* relocate against _SDA2_BASE_ */ |
8da6118f | 3488 | case (int) R_PPC_EMB_SDA2REL: |
252b5132 RH |
3489 | { |
3490 | const char *name; | |
3491 | ||
8da6118f | 3492 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 | 3493 | name = bfd_get_section_name (abfd, sec->output_section); |
5f819128 AM |
3494 | if (! (strncmp (name, ".sdata2", 7) == 0 |
3495 | || strncmp (name, ".sbss2", 6) == 0)) | |
252b5132 RH |
3496 | { |
3497 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"), | |
8f615d07 | 3498 | bfd_archive_filename (input_bfd), |
252b5132 | 3499 | sym_name, |
8da6118f | 3500 | ppc_elf_howto_table[(int) r_type]->name, |
252b5132 | 3501 | name); |
c3668558 | 3502 | |
252b5132 | 3503 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3504 | ret = FALSE; |
252b5132 RH |
3505 | continue; |
3506 | } | |
3507 | addend -= (sdata2->sym_hash->root.u.def.value | |
3508 | + sdata2->sym_hash->root.u.def.section->output_section->vma | |
3509 | + sdata2->sym_hash->root.u.def.section->output_offset); | |
3510 | } | |
3511 | break; | |
3512 | ||
252b5132 | 3513 | /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */ |
8da6118f KH |
3514 | case (int) R_PPC_EMB_SDA21: |
3515 | case (int) R_PPC_EMB_RELSDA: | |
252b5132 RH |
3516 | { |
3517 | const char *name; | |
3518 | int reg; | |
3519 | ||
8da6118f | 3520 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 | 3521 | name = bfd_get_section_name (abfd, sec->output_section); |
b34976b6 | 3522 | if (((strncmp (name, ".sdata", 6) == 0 |
5f819128 AM |
3523 | && (name[6] == 0 || name[6] == '.')) |
3524 | || (strncmp (name, ".sbss", 5) == 0 | |
3525 | && (name[5] == 0 || name[5] == '.')))) | |
252b5132 RH |
3526 | { |
3527 | reg = 13; | |
3528 | addend -= (sdata->sym_hash->root.u.def.value | |
3529 | + sdata->sym_hash->root.u.def.section->output_section->vma | |
3530 | + sdata->sym_hash->root.u.def.section->output_offset); | |
3531 | } | |
3532 | ||
5f819128 AM |
3533 | else if (strncmp (name, ".sdata2", 7) == 0 |
3534 | || strncmp (name, ".sbss2", 6) == 0) | |
252b5132 RH |
3535 | { |
3536 | reg = 2; | |
3537 | addend -= (sdata2->sym_hash->root.u.def.value | |
3538 | + sdata2->sym_hash->root.u.def.section->output_section->vma | |
3539 | + sdata2->sym_hash->root.u.def.section->output_offset); | |
3540 | } | |
3541 | ||
8da6118f KH |
3542 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 |
3543 | || strcmp (name, ".PPC.EMB.sbss0") == 0) | |
252b5132 RH |
3544 | { |
3545 | reg = 0; | |
3546 | } | |
3547 | ||
3548 | else | |
3549 | { | |
3550 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"), | |
8f615d07 | 3551 | bfd_archive_filename (input_bfd), |
252b5132 | 3552 | sym_name, |
8da6118f | 3553 | ppc_elf_howto_table[(int) r_type]->name, |
252b5132 RH |
3554 | name); |
3555 | ||
3556 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 3557 | ret = FALSE; |
252b5132 RH |
3558 | continue; |
3559 | } | |
3560 | ||
3561 | if (r_type == R_PPC_EMB_SDA21) | |
3562 | { /* fill in register field */ | |
3563 | insn = bfd_get_32 (output_bfd, contents + offset); | |
3564 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); | |
dc810e39 | 3565 | bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset); |
252b5132 RH |
3566 | } |
3567 | } | |
3568 | break; | |
3569 | ||
3570 | /* Relocate against the beginning of the section */ | |
8da6118f KH |
3571 | case (int) R_PPC_SECTOFF: |
3572 | case (int) R_PPC_SECTOFF_LO: | |
3573 | case (int) R_PPC_SECTOFF_HI: | |
3574 | BFD_ASSERT (sec != (asection *) 0); | |
252b5132 RH |
3575 | addend -= sec->output_section->vma; |
3576 | break; | |
3577 | ||
8da6118f KH |
3578 | case (int) R_PPC_SECTOFF_HA: |
3579 | BFD_ASSERT (sec != (asection *) 0); | |
252b5132 RH |
3580 | addend -= sec->output_section->vma; |
3581 | addend += ((relocation + addend) & 0x8000) << 1; | |
3582 | break; | |
3583 | ||
3584 | /* Negative relocations */ | |
8da6118f KH |
3585 | case (int) R_PPC_EMB_NADDR32: |
3586 | case (int) R_PPC_EMB_NADDR16: | |
3587 | case (int) R_PPC_EMB_NADDR16_LO: | |
3588 | case (int) R_PPC_EMB_NADDR16_HI: | |
3589 | addend -= 2 * relocation; | |
252b5132 RH |
3590 | break; |
3591 | ||
8da6118f KH |
3592 | case (int) R_PPC_EMB_NADDR16_HA: |
3593 | addend -= 2 * relocation; | |
252b5132 RH |
3594 | addend += ((relocation + addend) & 0x8000) << 1; |
3595 | break; | |
3596 | ||
3597 | /* NOP relocation that prevents garbage collecting linkers from omitting a | |
3598 | reference. */ | |
8da6118f | 3599 | case (int) R_PPC_EMB_MRKREF: |
252b5132 RH |
3600 | continue; |
3601 | ||
8da6118f KH |
3602 | case (int) R_PPC_COPY: |
3603 | case (int) R_PPC_GLOB_DAT: | |
3604 | case (int) R_PPC_JMP_SLOT: | |
3605 | case (int) R_PPC_RELATIVE: | |
3606 | case (int) R_PPC_PLT32: | |
3607 | case (int) R_PPC_PLTREL32: | |
3608 | case (int) R_PPC_PLT16_LO: | |
3609 | case (int) R_PPC_PLT16_HI: | |
3610 | case (int) R_PPC_PLT16_HA: | |
3611 | case (int) R_PPC_EMB_RELSEC16: | |
3612 | case (int) R_PPC_EMB_RELST_LO: | |
3613 | case (int) R_PPC_EMB_RELST_HI: | |
3614 | case (int) R_PPC_EMB_RELST_HA: | |
3615 | case (int) R_PPC_EMB_BIT_FLD: | |
252b5132 | 3616 | (*_bfd_error_handler) (_("%s: Relocation %s is not yet supported for symbol %s."), |
8f615d07 | 3617 | bfd_archive_filename (input_bfd), |
8da6118f | 3618 | ppc_elf_howto_table[(int) r_type]->name, |
252b5132 RH |
3619 | sym_name); |
3620 | ||
3621 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 3622 | ret = FALSE; |
252b5132 RH |
3623 | continue; |
3624 | ||
8da6118f KH |
3625 | case (int) R_PPC_GNU_VTINHERIT: |
3626 | case (int) R_PPC_GNU_VTENTRY: | |
252b5132 RH |
3627 | /* These are no-ops in the end. */ |
3628 | continue; | |
3629 | } | |
3630 | ||
252b5132 RH |
3631 | #ifdef DEBUG |
3632 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n", | |
3633 | howto->name, | |
8da6118f | 3634 | (int) r_type, |
252b5132 RH |
3635 | sym_name, |
3636 | r_symndx, | |
8da6118f KH |
3637 | (long) offset, |
3638 | (long) addend); | |
252b5132 RH |
3639 | #endif |
3640 | ||
3641 | r = _bfd_final_link_relocate (howto, | |
3642 | input_bfd, | |
3643 | input_section, | |
3644 | contents, | |
3645 | offset, | |
3646 | relocation, | |
3647 | addend); | |
3648 | ||
dc1bc0c9 RH |
3649 | if (r == bfd_reloc_ok) |
3650 | ; | |
3651 | else if (r == bfd_reloc_overflow) | |
252b5132 | 3652 | { |
dc1bc0c9 RH |
3653 | const char *name; |
3654 | ||
3655 | if (h != NULL) | |
252b5132 | 3656 | { |
dc1bc0c9 RH |
3657 | if (h->root.type == bfd_link_hash_undefweak |
3658 | && howto->pc_relative) | |
3659 | { | |
3660 | /* Assume this is a call protected by other code that | |
3661 | detect the symbol is undefined. If this is the case, | |
3662 | we can safely ignore the overflow. If not, the | |
3663 | program is hosed anyway, and a little warning isn't | |
3664 | going to help. */ | |
252b5132 | 3665 | |
dc1bc0c9 RH |
3666 | continue; |
3667 | } | |
252b5132 | 3668 | |
dc1bc0c9 RH |
3669 | name = h->root.root.string; |
3670 | } | |
3671 | else | |
3672 | { | |
3673 | name = bfd_elf_string_from_elf_section (input_bfd, | |
3674 | symtab_hdr->sh_link, | |
3675 | sym->st_name); | |
3676 | if (name == NULL) | |
3677 | continue; | |
3678 | if (*name == '\0') | |
3679 | name = bfd_section_name (input_bfd, sec); | |
252b5132 | 3680 | } |
dc1bc0c9 | 3681 | |
c3668558 | 3682 | if (! (*info->callbacks->reloc_overflow) (info, |
464e1740 ILT |
3683 | name, |
3684 | howto->name, | |
3685 | (bfd_vma) 0, | |
3686 | input_bfd, | |
3687 | input_section, | |
3688 | offset)) | |
b34976b6 | 3689 | return FALSE; |
252b5132 | 3690 | } |
dc1bc0c9 | 3691 | else |
b34976b6 | 3692 | ret = FALSE; |
252b5132 RH |
3693 | } |
3694 | ||
252b5132 RH |
3695 | #ifdef DEBUG |
3696 | fprintf (stderr, "\n"); | |
3697 | #endif | |
3698 | ||
3699 | return ret; | |
3700 | } | |
29c2fb7c AJ |
3701 | |
3702 | static enum elf_reloc_type_class | |
f51e552e AM |
3703 | ppc_elf_reloc_type_class (rela) |
3704 | const Elf_Internal_Rela *rela; | |
29c2fb7c | 3705 | { |
f51e552e | 3706 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
29c2fb7c AJ |
3707 | { |
3708 | case R_PPC_RELATIVE: | |
3709 | return reloc_class_relative; | |
3710 | case R_PPC_REL24: | |
3711 | case R_PPC_ADDR24: | |
3712 | case R_PPC_JMP_SLOT: | |
3713 | return reloc_class_plt; | |
3714 | case R_PPC_COPY: | |
3715 | return reloc_class_copy; | |
3716 | default: | |
3717 | return reloc_class_normal; | |
3718 | } | |
3719 | } | |
252b5132 | 3720 | \f |
c5fccbec | 3721 | /* Support for core dump NOTE sections */ |
b34976b6 | 3722 | static bfd_boolean |
c5fccbec DJ |
3723 | ppc_elf_grok_prstatus (abfd, note) |
3724 | bfd *abfd; | |
3725 | Elf_Internal_Note *note; | |
3726 | { | |
3727 | int offset; | |
dc810e39 | 3728 | unsigned int raw_size; |
c5fccbec DJ |
3729 | |
3730 | switch (note->descsz) | |
3731 | { | |
3732 | default: | |
b34976b6 | 3733 | return FALSE; |
c5fccbec DJ |
3734 | |
3735 | case 268: /* Linux/PPC */ | |
3736 | /* pr_cursig */ | |
3737 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
3738 | ||
3739 | /* pr_pid */ | |
3740 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
3741 | ||
3742 | /* pr_reg */ | |
3743 | offset = 72; | |
3744 | raw_size = 192; | |
3745 | ||
3746 | break; | |
3747 | } | |
3748 | ||
3749 | /* Make a ".reg/999" section. */ | |
3750 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
3751 | raw_size, note->descpos + offset); | |
3752 | } | |
3753 | ||
b34976b6 | 3754 | static bfd_boolean |
c5fccbec DJ |
3755 | ppc_elf_grok_psinfo (abfd, note) |
3756 | bfd *abfd; | |
3757 | Elf_Internal_Note *note; | |
3758 | { | |
3759 | switch (note->descsz) | |
3760 | { | |
3761 | default: | |
b34976b6 | 3762 | return FALSE; |
c5fccbec DJ |
3763 | |
3764 | case 128: /* Linux/PPC elf_prpsinfo */ | |
3765 | elf_tdata (abfd)->core_program | |
3766 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); | |
3767 | elf_tdata (abfd)->core_command | |
3768 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); | |
3769 | } | |
3770 | ||
3771 | /* Note that for some reason, a spurious space is tacked | |
3772 | onto the end of the args in some (at least one anyway) | |
3773 | implementations, so strip it off if it exists. */ | |
3774 | ||
3775 | { | |
3776 | char *command = elf_tdata (abfd)->core_command; | |
3777 | int n = strlen (command); | |
3778 | ||
3779 | if (0 < n && command[n - 1] == ' ') | |
3780 | command[n - 1] = '\0'; | |
3781 | } | |
3782 | ||
b34976b6 | 3783 | return TRUE; |
c5fccbec DJ |
3784 | } |
3785 | \f | |
252b5132 RH |
3786 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
3787 | #define TARGET_LITTLE_NAME "elf32-powerpcle" | |
3788 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec | |
3789 | #define TARGET_BIG_NAME "elf32-powerpc" | |
3790 | #define ELF_ARCH bfd_arch_powerpc | |
3791 | #define ELF_MACHINE_CODE EM_PPC | |
3792 | #define ELF_MAXPAGESIZE 0x10000 | |
3793 | #define elf_info_to_howto ppc_elf_info_to_howto | |
3794 | ||
3795 | #ifdef EM_CYGNUS_POWERPC | |
3796 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
3797 | #endif | |
3798 | ||
3799 | #ifdef EM_PPC_OLD | |
3800 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
3801 | #endif | |
3802 | ||
3803 | #define elf_backend_plt_not_loaded 1 | |
3804 | #define elf_backend_got_symbol_offset 4 | |
3805 | #define elf_backend_can_gc_sections 1 | |
51b64d56 | 3806 | #define elf_backend_can_refcount 1 |
252b5132 RH |
3807 | #define elf_backend_got_header_size 12 |
3808 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE | |
b491616a | 3809 | #define elf_backend_rela_normal 1 |
252b5132 | 3810 | |
252b5132 RH |
3811 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
3812 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section | |
3813 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup | |
3814 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags | |
3815 | #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link | |
3816 | ||
feee612b | 3817 | #define elf_backend_object_p ppc_elf_object_p |
252b5132 RH |
3818 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
3819 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook | |
3820 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr | |
3821 | #define elf_backend_relocate_section ppc_elf_relocate_section | |
3822 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections | |
3823 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
3824 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol | |
3825 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook | |
3826 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
3827 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol | |
3828 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
3829 | #define elf_backend_fake_sections ppc_elf_fake_sections | |
3830 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers | |
3831 | #define elf_backend_modify_segment_map ppc_elf_modify_segment_map | |
c5fccbec DJ |
3832 | #define elf_backend_grok_prstatus ppc_elf_grok_prstatus |
3833 | #define elf_backend_grok_psinfo ppc_elf_grok_psinfo | |
29c2fb7c | 3834 | #define elf_backend_reloc_type_class ppc_elf_reloc_type_class |
252b5132 RH |
3835 | |
3836 | #include "elf32-target.h" |