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