Commit | Line | Data |
---|---|---|
5bd4f169 | 1 | /* PowerPC64-specific support for 64-bit ELF. |
5d1634d7 | 2 | Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
5bd4f169 AM |
3 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
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" | |
5d1634d7 | 31 | #include "elf64-ppc.h" |
5bd4f169 | 32 | |
5bd4f169 AM |
33 | static void ppc_howto_init |
34 | PARAMS ((void)); | |
35 | static reloc_howto_type *ppc64_elf_reloc_type_lookup | |
36 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
37 | static void ppc64_elf_info_to_howto | |
947216bf | 38 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)); |
805fc799 AM |
39 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
40 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
41 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc | |
42 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
43 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc | |
44 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
45 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc | |
46 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
47 | static bfd_reloc_status_type ppc64_elf_toc_reloc | |
48 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
49 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc | |
50 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
51 | static bfd_reloc_status_type ppc64_elf_toc64_reloc | |
52 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
53 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc | |
5bd4f169 | 54 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); |
b34976b6 | 55 | static bfd_boolean ppc64_elf_object_p |
feee612b | 56 | PARAMS ((bfd *)); |
b34976b6 | 57 | static bfd_boolean ppc64_elf_merge_private_bfd_data |
5bd4f169 | 58 | PARAMS ((bfd *, bfd *)); |
5bd4f169 AM |
59 | |
60 | ||
5bd4f169 AM |
61 | /* The name of the dynamic interpreter. This is put in the .interp |
62 | section. */ | |
63 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
64 | ||
65 | /* The size in bytes of an entry in the procedure linkage table. */ | |
66 | #define PLT_ENTRY_SIZE 24 | |
67 | ||
68 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 69 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
70 | |
71 | /* TOC base pointers offset from start of TOC. */ | |
72 | #define TOC_BASE_OFF (0x8000) | |
73 | ||
5d1634d7 AM |
74 | /* .plt call stub instructions. */ |
75 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ | |
76 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
77 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
78 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
79 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
80 | /* ld %r11,xxx+16@l(%r12) */ | |
81 | #define BCTR 0x4e800420 /* bctr */ | |
82 | ||
83 | /* The normal stub is this size. */ | |
84 | #define PLT_CALL_STUB_SIZE (7*4) | |
85 | ||
86 | /* But sometimes the .plt entry crosses a 64k boundary, and we need | |
87 | to adjust the high word with this insn. */ | |
88 | #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */ | |
5bd4f169 | 89 | |
5d1634d7 AM |
90 | /* The .glink fixup call stub is the same as the .plt call stub, but |
91 | the first instruction restores r2, and the std is omitted. */ | |
92 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
93 | ||
94 | /* Always allow this much space. */ | |
95 | #define GLINK_CALL_STUB_SIZE (8*4) | |
96 | ||
97 | /* Pad with this. */ | |
98 | #define NOP 0x60000000 | |
99 | ||
721956f4 AM |
100 | /* Some other nops. */ |
101 | #define CROR_151515 0x4def7b82 | |
102 | #define CROR_313131 0x4ffffb82 | |
103 | ||
cedb70c5 | 104 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
105 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
106 | #define B_DOT 0x48000000 /* b . */ | |
107 | ||
108 | /* After that, we need two instructions to load the index, followed by | |
109 | a branch. */ | |
110 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 111 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 112 | |
82bd7b59 AM |
113 | /* Instructions to save and restore floating point regs. */ |
114 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ | |
115 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
116 | #define BLR 0x4e800020 /* blr */ | |
117 | ||
41bd81ab AM |
118 | /* Since .opd is an array of descriptors and each entry will end up |
119 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
120 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 121 | relocate .opd without reloc entries. */ |
41bd81ab AM |
122 | #ifndef NO_OPD_RELOCS |
123 | #define NO_OPD_RELOCS 0 | |
124 | #endif | |
5bd4f169 | 125 | \f |
f5e87a1d | 126 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 127 | |
5bd4f169 AM |
128 | /* Relocation HOWTO's. */ |
129 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max]; | |
130 | ||
131 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
132 | /* This reloc does nothing. */ | |
133 | HOWTO (R_PPC64_NONE, /* type */ | |
134 | 0, /* rightshift */ | |
f5e87a1d AM |
135 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
136 | 8, /* bitsize */ | |
b34976b6 | 137 | FALSE, /* pc_relative */ |
5bd4f169 | 138 | 0, /* bitpos */ |
f5e87a1d | 139 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
140 | bfd_elf_generic_reloc, /* special_function */ |
141 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 142 | FALSE, /* partial_inplace */ |
d006db6c | 143 | 0, /* src_mask */ |
5bd4f169 | 144 | 0, /* dst_mask */ |
b34976b6 | 145 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
146 | |
147 | /* A standard 32 bit relocation. */ | |
148 | HOWTO (R_PPC64_ADDR32, /* type */ | |
149 | 0, /* rightshift */ | |
150 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
151 | 32, /* bitsize */ | |
b34976b6 | 152 | FALSE, /* pc_relative */ |
5bd4f169 AM |
153 | 0, /* bitpos */ |
154 | complain_overflow_bitfield, /* complain_on_overflow */ | |
155 | bfd_elf_generic_reloc, /* special_function */ | |
156 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 157 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
158 | 0, /* src_mask */ |
159 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 160 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
161 | |
162 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
163 | FIXME: we don't check that, we just clear them. */ | |
164 | HOWTO (R_PPC64_ADDR24, /* type */ | |
165 | 0, /* rightshift */ | |
166 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
167 | 26, /* bitsize */ | |
b34976b6 | 168 | FALSE, /* pc_relative */ |
5bd4f169 AM |
169 | 0, /* bitpos */ |
170 | complain_overflow_bitfield, /* complain_on_overflow */ | |
171 | bfd_elf_generic_reloc, /* special_function */ | |
172 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 173 | FALSE, /* partial_inplace */ |
d006db6c | 174 | 0, /* src_mask */ |
f5e87a1d | 175 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 176 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
177 | |
178 | /* A standard 16 bit relocation. */ | |
179 | HOWTO (R_PPC64_ADDR16, /* type */ | |
180 | 0, /* rightshift */ | |
181 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
182 | 16, /* bitsize */ | |
b34976b6 | 183 | FALSE, /* pc_relative */ |
5bd4f169 AM |
184 | 0, /* bitpos */ |
185 | complain_overflow_bitfield, /* complain_on_overflow */ | |
186 | bfd_elf_generic_reloc, /* special_function */ | |
187 | "R_PPC64_ADDR16", /* name */ | |
b34976b6 | 188 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
189 | 0, /* src_mask */ |
190 | 0xffff, /* dst_mask */ | |
b34976b6 | 191 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
192 | |
193 | /* A 16 bit relocation without overflow. */ | |
194 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
195 | 0, /* rightshift */ | |
196 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
197 | 16, /* bitsize */ | |
b34976b6 | 198 | FALSE, /* pc_relative */ |
5bd4f169 AM |
199 | 0, /* bitpos */ |
200 | complain_overflow_dont,/* complain_on_overflow */ | |
201 | bfd_elf_generic_reloc, /* special_function */ | |
202 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 203 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
204 | 0, /* src_mask */ |
205 | 0xffff, /* dst_mask */ | |
b34976b6 | 206 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
207 | |
208 | /* Bits 16-31 of an address. */ | |
209 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
210 | 16, /* rightshift */ | |
211 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
212 | 16, /* bitsize */ | |
b34976b6 | 213 | FALSE, /* pc_relative */ |
5bd4f169 AM |
214 | 0, /* bitpos */ |
215 | complain_overflow_dont, /* complain_on_overflow */ | |
216 | bfd_elf_generic_reloc, /* special_function */ | |
217 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 218 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
219 | 0, /* src_mask */ |
220 | 0xffff, /* dst_mask */ | |
b34976b6 | 221 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
222 | |
223 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
224 | bits, treated as a signed number, is negative. */ | |
225 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
226 | 16, /* rightshift */ | |
227 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
228 | 16, /* bitsize */ | |
b34976b6 | 229 | FALSE, /* pc_relative */ |
5bd4f169 AM |
230 | 0, /* bitpos */ |
231 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 232 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 233 | "R_PPC64_ADDR16_HA", /* name */ |
b34976b6 | 234 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
235 | 0, /* src_mask */ |
236 | 0xffff, /* dst_mask */ | |
b34976b6 | 237 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
238 | |
239 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
240 | FIXME: we don't check that, we just clear them. */ | |
241 | HOWTO (R_PPC64_ADDR14, /* type */ | |
242 | 0, /* rightshift */ | |
243 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
244 | 16, /* bitsize */ | |
b34976b6 | 245 | FALSE, /* pc_relative */ |
5bd4f169 AM |
246 | 0, /* bitpos */ |
247 | complain_overflow_bitfield, /* complain_on_overflow */ | |
248 | bfd_elf_generic_reloc, /* special_function */ | |
249 | "R_PPC64_ADDR14", /* name */ | |
b34976b6 | 250 | FALSE, /* partial_inplace */ |
d006db6c | 251 | 0, /* src_mask */ |
f5e87a1d | 252 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 253 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
254 | |
255 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
256 | indicate that the branch is expected to be taken. The lower two | |
257 | bits must be zero. */ | |
258 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
259 | 0, /* rightshift */ | |
260 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
261 | 16, /* bitsize */ | |
b34976b6 | 262 | FALSE, /* pc_relative */ |
5bd4f169 AM |
263 | 0, /* bitpos */ |
264 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 265 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 266 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 267 | FALSE, /* partial_inplace */ |
d006db6c | 268 | 0, /* src_mask */ |
f5e87a1d | 269 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 270 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
271 | |
272 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
273 | indicate that the branch is not expected to be taken. The lower | |
274 | two bits must be zero. */ | |
275 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
276 | 0, /* rightshift */ | |
277 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
278 | 16, /* bitsize */ | |
b34976b6 | 279 | FALSE, /* pc_relative */ |
5bd4f169 AM |
280 | 0, /* bitpos */ |
281 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 282 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 283 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 284 | FALSE, /* partial_inplace */ |
d006db6c | 285 | 0, /* src_mask */ |
f5e87a1d | 286 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 287 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
288 | |
289 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
290 | HOWTO (R_PPC64_REL24, /* type */ | |
291 | 0, /* rightshift */ | |
292 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
293 | 26, /* bitsize */ | |
b34976b6 | 294 | TRUE, /* pc_relative */ |
5bd4f169 AM |
295 | 0, /* bitpos */ |
296 | complain_overflow_signed, /* complain_on_overflow */ | |
297 | bfd_elf_generic_reloc, /* special_function */ | |
298 | "R_PPC64_REL24", /* name */ | |
b34976b6 | 299 | FALSE, /* partial_inplace */ |
d006db6c | 300 | 0, /* src_mask */ |
f5e87a1d | 301 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 302 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
303 | |
304 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
305 | HOWTO (R_PPC64_REL14, /* type */ | |
306 | 0, /* rightshift */ | |
307 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
308 | 16, /* bitsize */ | |
b34976b6 | 309 | TRUE, /* pc_relative */ |
5bd4f169 AM |
310 | 0, /* bitpos */ |
311 | complain_overflow_signed, /* complain_on_overflow */ | |
312 | bfd_elf_generic_reloc, /* special_function */ | |
313 | "R_PPC64_REL14", /* name */ | |
b34976b6 | 314 | FALSE, /* partial_inplace */ |
d006db6c | 315 | 0, /* src_mask */ |
f5e87a1d | 316 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 317 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
318 | |
319 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
320 | the branch is expected to be taken. The lower two bits must be | |
321 | zero. */ | |
322 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
323 | 0, /* rightshift */ | |
324 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
325 | 16, /* bitsize */ | |
b34976b6 | 326 | TRUE, /* pc_relative */ |
5bd4f169 AM |
327 | 0, /* bitpos */ |
328 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 329 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 330 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 331 | FALSE, /* partial_inplace */ |
d006db6c | 332 | 0, /* src_mask */ |
f5e87a1d | 333 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 334 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
335 | |
336 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
337 | the branch is not expected to be taken. The lower two bits must | |
338 | be zero. */ | |
339 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
340 | 0, /* rightshift */ | |
341 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
342 | 16, /* bitsize */ | |
b34976b6 | 343 | TRUE, /* pc_relative */ |
5bd4f169 AM |
344 | 0, /* bitpos */ |
345 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 346 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 347 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 348 | FALSE, /* partial_inplace */ |
d006db6c | 349 | 0, /* src_mask */ |
f5e87a1d | 350 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 351 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
352 | |
353 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
354 | symbol. */ | |
355 | HOWTO (R_PPC64_GOT16, /* type */ | |
356 | 0, /* rightshift */ | |
357 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
358 | 16, /* bitsize */ | |
b34976b6 | 359 | FALSE, /* pc_relative */ |
5bd4f169 AM |
360 | 0, /* bitpos */ |
361 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 362 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 363 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 364 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
365 | 0, /* src_mask */ |
366 | 0xffff, /* dst_mask */ | |
b34976b6 | 367 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
368 | |
369 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
370 | the symbol. */ | |
371 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
372 | 0, /* rightshift */ | |
373 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
374 | 16, /* bitsize */ | |
b34976b6 | 375 | FALSE, /* pc_relative */ |
5bd4f169 AM |
376 | 0, /* bitpos */ |
377 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 378 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 379 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 380 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
381 | 0, /* src_mask */ |
382 | 0xffff, /* dst_mask */ | |
b34976b6 | 383 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
384 | |
385 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
386 | the symbol. */ | |
387 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
388 | 16, /* rightshift */ | |
389 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
390 | 16, /* bitsize */ | |
b34976b6 | 391 | FALSE, /* pc_relative */ |
5bd4f169 AM |
392 | 0, /* bitpos */ |
393 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 394 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 395 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 396 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
397 | 0, /* src_mask */ |
398 | 0xffff, /* dst_mask */ | |
b34976b6 | 399 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
400 | |
401 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
402 | the symbol. */ | |
403 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
404 | 16, /* rightshift */ | |
405 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
406 | 16, /* bitsize */ | |
b34976b6 | 407 | FALSE, /* pc_relative */ |
5bd4f169 AM |
408 | 0, /* bitpos */ |
409 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 410 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 411 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 412 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
413 | 0, /* src_mask */ |
414 | 0xffff, /* dst_mask */ | |
b34976b6 | 415 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
416 | |
417 | /* This is used only by the dynamic linker. The symbol should exist | |
418 | both in the object being run and in some shared library. The | |
419 | dynamic linker copies the data addressed by the symbol from the | |
420 | shared library into the object, because the object being | |
421 | run has to have the data at some particular address. */ | |
422 | HOWTO (R_PPC64_COPY, /* type */ | |
423 | 0, /* rightshift */ | |
f5e87a1d AM |
424 | 0, /* this one is variable size */ |
425 | 0, /* bitsize */ | |
b34976b6 | 426 | FALSE, /* pc_relative */ |
5bd4f169 | 427 | 0, /* bitpos */ |
f5e87a1d AM |
428 | complain_overflow_dont, /* complain_on_overflow */ |
429 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 430 | "R_PPC64_COPY", /* name */ |
b34976b6 | 431 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
432 | 0, /* src_mask */ |
433 | 0, /* dst_mask */ | |
b34976b6 | 434 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
435 | |
436 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
437 | entries. */ | |
438 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
439 | 0, /* rightshift */ | |
440 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
441 | 64, /* bitsize */ | |
b34976b6 | 442 | FALSE, /* pc_relative */ |
5bd4f169 AM |
443 | 0, /* bitpos */ |
444 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 445 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 446 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 447 | FALSE, /* partial_inplace */ |
5bd4f169 | 448 | 0, /* src_mask */ |
f5e87a1d | 449 | ONES (64), /* dst_mask */ |
b34976b6 | 450 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
451 | |
452 | /* Created by the link editor. Marks a procedure linkage table | |
453 | entry for a symbol. */ | |
454 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
455 | 0, /* rightshift */ | |
456 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
457 | 0, /* bitsize */ | |
b34976b6 | 458 | FALSE, /* pc_relative */ |
5bd4f169 AM |
459 | 0, /* bitpos */ |
460 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 461 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 462 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 463 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
464 | 0, /* src_mask */ |
465 | 0, /* dst_mask */ | |
b34976b6 | 466 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
467 | |
468 | /* Used only by the dynamic linker. When the object is run, this | |
469 | doubleword64 is set to the load address of the object, plus the | |
470 | addend. */ | |
471 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
472 | 0, /* rightshift */ | |
473 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
474 | 64, /* bitsize */ | |
b34976b6 | 475 | FALSE, /* pc_relative */ |
5bd4f169 AM |
476 | 0, /* bitpos */ |
477 | complain_overflow_dont, /* complain_on_overflow */ | |
478 | bfd_elf_generic_reloc, /* special_function */ | |
479 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 480 | FALSE, /* partial_inplace */ |
5bd4f169 | 481 | 0, /* src_mask */ |
f5e87a1d | 482 | ONES (64), /* dst_mask */ |
b34976b6 | 483 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
484 | |
485 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
486 | HOWTO (R_PPC64_UADDR32, /* type */ | |
487 | 0, /* rightshift */ | |
488 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
489 | 32, /* bitsize */ | |
b34976b6 | 490 | FALSE, /* pc_relative */ |
5bd4f169 AM |
491 | 0, /* bitpos */ |
492 | complain_overflow_bitfield, /* complain_on_overflow */ | |
493 | bfd_elf_generic_reloc, /* special_function */ | |
494 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 495 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
496 | 0, /* src_mask */ |
497 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 498 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
499 | |
500 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
501 | HOWTO (R_PPC64_UADDR16, /* type */ | |
502 | 0, /* rightshift */ | |
503 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
504 | 16, /* bitsize */ | |
b34976b6 | 505 | FALSE, /* pc_relative */ |
5bd4f169 AM |
506 | 0, /* bitpos */ |
507 | complain_overflow_bitfield, /* complain_on_overflow */ | |
508 | bfd_elf_generic_reloc, /* special_function */ | |
509 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 510 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
511 | 0, /* src_mask */ |
512 | 0xffff, /* dst_mask */ | |
b34976b6 | 513 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
514 | |
515 | /* 32-bit PC relative. */ | |
516 | HOWTO (R_PPC64_REL32, /* type */ | |
517 | 0, /* rightshift */ | |
518 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
519 | 32, /* bitsize */ | |
b34976b6 | 520 | TRUE, /* pc_relative */ |
5bd4f169 | 521 | 0, /* bitpos */ |
cedb70c5 | 522 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
523 | complain_overflow_signed, /* complain_on_overflow */ |
524 | bfd_elf_generic_reloc, /* special_function */ | |
525 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 526 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
527 | 0, /* src_mask */ |
528 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 529 | TRUE), /* pcrel_offset */ |
5bd4f169 | 530 | |
10ed1bba | 531 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
532 | HOWTO (R_PPC64_PLT32, /* type */ |
533 | 0, /* rightshift */ | |
534 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
535 | 32, /* bitsize */ | |
b34976b6 | 536 | FALSE, /* pc_relative */ |
5bd4f169 AM |
537 | 0, /* bitpos */ |
538 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 539 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 540 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 541 | FALSE, /* partial_inplace */ |
5bd4f169 | 542 | 0, /* src_mask */ |
f5e87a1d | 543 | 0xffffffff, /* dst_mask */ |
b34976b6 | 544 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
545 | |
546 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
547 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
548 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
549 | 0, /* rightshift */ | |
550 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
551 | 32, /* bitsize */ | |
b34976b6 | 552 | TRUE, /* pc_relative */ |
5bd4f169 AM |
553 | 0, /* bitpos */ |
554 | complain_overflow_signed, /* complain_on_overflow */ | |
555 | bfd_elf_generic_reloc, /* special_function */ | |
556 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 557 | FALSE, /* partial_inplace */ |
5bd4f169 | 558 | 0, /* src_mask */ |
f5e87a1d | 559 | 0xffffffff, /* dst_mask */ |
b34976b6 | 560 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
561 | |
562 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
563 | the symbol. */ | |
564 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
565 | 0, /* rightshift */ | |
566 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
567 | 16, /* bitsize */ | |
b34976b6 | 568 | FALSE, /* pc_relative */ |
5bd4f169 AM |
569 | 0, /* bitpos */ |
570 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 571 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 572 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 573 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
574 | 0, /* src_mask */ |
575 | 0xffff, /* dst_mask */ | |
b34976b6 | 576 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
577 | |
578 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
579 | the symbol. */ | |
580 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
581 | 16, /* rightshift */ | |
582 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
583 | 16, /* bitsize */ | |
b34976b6 | 584 | FALSE, /* pc_relative */ |
5bd4f169 AM |
585 | 0, /* bitpos */ |
586 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 587 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 588 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 589 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
590 | 0, /* src_mask */ |
591 | 0xffff, /* dst_mask */ | |
b34976b6 | 592 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
593 | |
594 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
595 | the symbol. */ | |
596 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
597 | 16, /* rightshift */ | |
598 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
599 | 16, /* bitsize */ | |
b34976b6 | 600 | FALSE, /* pc_relative */ |
5bd4f169 AM |
601 | 0, /* bitpos */ |
602 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 603 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 604 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 605 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
606 | 0, /* src_mask */ |
607 | 0xffff, /* dst_mask */ | |
b34976b6 | 608 | FALSE), /* pcrel_offset */ |
5bd4f169 | 609 | |
c061c2d8 | 610 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
611 | HOWTO (R_PPC64_SECTOFF, /* type */ |
612 | 0, /* rightshift */ | |
c061c2d8 AM |
613 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
614 | 16, /* bitsize */ | |
b34976b6 | 615 | FALSE, /* pc_relative */ |
5bd4f169 AM |
616 | 0, /* bitpos */ |
617 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 618 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 619 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 620 | FALSE, /* partial_inplace */ |
5bd4f169 | 621 | 0, /* src_mask */ |
c061c2d8 | 622 | 0xffff, /* dst_mask */ |
b34976b6 | 623 | FALSE), /* pcrel_offset */ |
5bd4f169 | 624 | |
c061c2d8 | 625 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
626 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
627 | 0, /* rightshift */ | |
628 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
629 | 16, /* bitsize */ | |
b34976b6 | 630 | FALSE, /* pc_relative */ |
5bd4f169 AM |
631 | 0, /* bitpos */ |
632 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 633 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 634 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 635 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
636 | 0, /* src_mask */ |
637 | 0xffff, /* dst_mask */ | |
b34976b6 | 638 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
639 | |
640 | /* 16-bit upper half section relative relocation. */ | |
641 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
642 | 16, /* rightshift */ | |
643 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
644 | 16, /* bitsize */ | |
b34976b6 | 645 | FALSE, /* pc_relative */ |
5bd4f169 AM |
646 | 0, /* bitpos */ |
647 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 648 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 649 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 650 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
651 | 0, /* src_mask */ |
652 | 0xffff, /* dst_mask */ | |
b34976b6 | 653 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
654 | |
655 | /* 16-bit upper half adjusted section relative relocation. */ | |
656 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
657 | 16, /* rightshift */ | |
658 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
659 | 16, /* bitsize */ | |
b34976b6 | 660 | FALSE, /* pc_relative */ |
5bd4f169 AM |
661 | 0, /* bitpos */ |
662 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 663 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 664 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 665 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
666 | 0, /* src_mask */ |
667 | 0xffff, /* dst_mask */ | |
b34976b6 | 668 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
669 | |
670 | /* Like R_PPC64_REL24 without touching the two least significant | |
805fc799 | 671 | bits. Should have been named R_PPC64_REL30! */ |
5bd4f169 AM |
672 | HOWTO (R_PPC64_ADDR30, /* type */ |
673 | 2, /* rightshift */ | |
674 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
675 | 30, /* bitsize */ | |
b34976b6 | 676 | TRUE, /* pc_relative */ |
5bd4f169 AM |
677 | 0, /* bitpos */ |
678 | complain_overflow_dont, /* complain_on_overflow */ | |
679 | bfd_elf_generic_reloc, /* special_function */ | |
680 | "R_PPC64_ADDR30", /* name */ | |
b34976b6 | 681 | FALSE, /* partial_inplace */ |
d006db6c | 682 | 0, /* src_mask */ |
5bd4f169 | 683 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 684 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
685 | |
686 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
687 | ||
688 | /* A standard 64-bit relocation. */ | |
689 | HOWTO (R_PPC64_ADDR64, /* type */ | |
690 | 0, /* rightshift */ | |
691 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
692 | 64, /* bitsize */ | |
b34976b6 | 693 | FALSE, /* pc_relative */ |
5bd4f169 AM |
694 | 0, /* bitpos */ |
695 | complain_overflow_dont, /* complain_on_overflow */ | |
696 | bfd_elf_generic_reloc, /* special_function */ | |
697 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 698 | FALSE, /* partial_inplace */ |
5bd4f169 | 699 | 0, /* src_mask */ |
f5e87a1d | 700 | ONES (64), /* dst_mask */ |
b34976b6 | 701 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
702 | |
703 | /* The bits 32-47 of an address. */ | |
704 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
705 | 32, /* rightshift */ | |
706 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
707 | 16, /* bitsize */ | |
b34976b6 | 708 | FALSE, /* pc_relative */ |
5bd4f169 AM |
709 | 0, /* bitpos */ |
710 | complain_overflow_dont, /* complain_on_overflow */ | |
711 | bfd_elf_generic_reloc, /* special_function */ | |
712 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 713 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
714 | 0, /* src_mask */ |
715 | 0xffff, /* dst_mask */ | |
b34976b6 | 716 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
717 | |
718 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
719 | 16 bits, treated as a signed number, is negative. */ | |
720 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
721 | 32, /* rightshift */ | |
722 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
723 | 16, /* bitsize */ | |
b34976b6 | 724 | FALSE, /* pc_relative */ |
5bd4f169 AM |
725 | 0, /* bitpos */ |
726 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 727 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 728 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 729 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
730 | 0, /* src_mask */ |
731 | 0xffff, /* dst_mask */ | |
b34976b6 | 732 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
733 | |
734 | /* The bits 48-63 of an address. */ | |
735 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
736 | 48, /* rightshift */ | |
737 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
738 | 16, /* bitsize */ | |
b34976b6 | 739 | FALSE, /* pc_relative */ |
5bd4f169 AM |
740 | 0, /* bitpos */ |
741 | complain_overflow_dont, /* complain_on_overflow */ | |
742 | bfd_elf_generic_reloc, /* special_function */ | |
743 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
b34976b6 | 744 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
745 | 0, /* src_mask */ |
746 | 0xffff, /* dst_mask */ | |
b34976b6 | 747 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
748 | |
749 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
750 | 16 bits, treated as a signed number, is negative. */ | |
751 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
752 | 48, /* rightshift */ | |
753 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
754 | 16, /* bitsize */ | |
b34976b6 | 755 | FALSE, /* pc_relative */ |
5bd4f169 AM |
756 | 0, /* bitpos */ |
757 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 758 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 759 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
b34976b6 | 760 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
761 | 0, /* src_mask */ |
762 | 0xffff, /* dst_mask */ | |
b34976b6 | 763 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
764 | |
765 | /* Like ADDR64, but may be unaligned. */ | |
766 | HOWTO (R_PPC64_UADDR64, /* type */ | |
767 | 0, /* rightshift */ | |
768 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
769 | 64, /* bitsize */ | |
b34976b6 | 770 | FALSE, /* pc_relative */ |
5bd4f169 AM |
771 | 0, /* bitpos */ |
772 | complain_overflow_dont, /* complain_on_overflow */ | |
773 | bfd_elf_generic_reloc, /* special_function */ | |
774 | "R_PPC64_UADDR64", /* name */ | |
b34976b6 | 775 | FALSE, /* partial_inplace */ |
5bd4f169 | 776 | 0, /* src_mask */ |
f5e87a1d | 777 | ONES (64), /* dst_mask */ |
b34976b6 | 778 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
779 | |
780 | /* 64-bit relative relocation. */ | |
781 | HOWTO (R_PPC64_REL64, /* type */ | |
782 | 0, /* rightshift */ | |
783 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
784 | 64, /* bitsize */ | |
b34976b6 | 785 | TRUE, /* pc_relative */ |
5bd4f169 AM |
786 | 0, /* bitpos */ |
787 | complain_overflow_dont, /* complain_on_overflow */ | |
788 | bfd_elf_generic_reloc, /* special_function */ | |
789 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 790 | FALSE, /* partial_inplace */ |
5bd4f169 | 791 | 0, /* src_mask */ |
f5e87a1d | 792 | ONES (64), /* dst_mask */ |
b34976b6 | 793 | TRUE), /* pcrel_offset */ |
5bd4f169 | 794 | |
cedb70c5 | 795 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
796 | HOWTO (R_PPC64_PLT64, /* type */ |
797 | 0, /* rightshift */ | |
798 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
799 | 64, /* bitsize */ | |
b34976b6 | 800 | FALSE, /* pc_relative */ |
5bd4f169 AM |
801 | 0, /* bitpos */ |
802 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 803 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 804 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 805 | FALSE, /* partial_inplace */ |
5bd4f169 | 806 | 0, /* src_mask */ |
f5e87a1d | 807 | ONES (64), /* dst_mask */ |
b34976b6 | 808 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
809 | |
810 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
811 | table. */ | |
812 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
813 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
814 | 0, /* rightshift */ | |
815 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
816 | 64, /* bitsize */ | |
b34976b6 | 817 | TRUE, /* pc_relative */ |
5bd4f169 AM |
818 | 0, /* bitpos */ |
819 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 820 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 821 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 822 | FALSE, /* partial_inplace */ |
5bd4f169 | 823 | 0, /* src_mask */ |
f5e87a1d | 824 | ONES (64), /* dst_mask */ |
b34976b6 | 825 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
826 | |
827 | /* 16 bit TOC-relative relocation. */ | |
828 | ||
829 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
830 | HOWTO (R_PPC64_TOC16, /* type */ | |
831 | 0, /* rightshift */ | |
832 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
833 | 16, /* bitsize */ | |
b34976b6 | 834 | FALSE, /* pc_relative */ |
5bd4f169 AM |
835 | 0, /* bitpos */ |
836 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 837 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 838 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 839 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
840 | 0, /* src_mask */ |
841 | 0xffff, /* dst_mask */ | |
b34976b6 | 842 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
843 | |
844 | /* 16 bit TOC-relative relocation without overflow. */ | |
845 | ||
846 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
847 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
848 | 0, /* rightshift */ | |
849 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
850 | 16, /* bitsize */ | |
b34976b6 | 851 | FALSE, /* pc_relative */ |
5bd4f169 AM |
852 | 0, /* bitpos */ |
853 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 854 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 855 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 856 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
857 | 0, /* src_mask */ |
858 | 0xffff, /* dst_mask */ | |
b34976b6 | 859 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
860 | |
861 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
862 | ||
863 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
864 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
865 | 16, /* rightshift */ | |
866 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
867 | 16, /* bitsize */ | |
b34976b6 | 868 | FALSE, /* pc_relative */ |
5bd4f169 AM |
869 | 0, /* bitpos */ |
870 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 871 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 872 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 873 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
874 | 0, /* src_mask */ |
875 | 0xffff, /* dst_mask */ | |
b34976b6 | 876 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
877 | |
878 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
879 | contents of the low 16 bits, treated as a signed number, is | |
880 | negative. */ | |
881 | ||
882 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
883 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
884 | 16, /* rightshift */ | |
885 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
886 | 16, /* bitsize */ | |
b34976b6 | 887 | FALSE, /* pc_relative */ |
5bd4f169 AM |
888 | 0, /* bitpos */ |
889 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 890 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 891 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 892 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
893 | 0, /* src_mask */ |
894 | 0xffff, /* dst_mask */ | |
b34976b6 | 895 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
896 | |
897 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
898 | ||
899 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
900 | HOWTO (R_PPC64_TOC, /* type */ | |
901 | 0, /* rightshift */ | |
902 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
903 | 64, /* bitsize */ | |
b34976b6 | 904 | FALSE, /* pc_relative */ |
5bd4f169 AM |
905 | 0, /* bitpos */ |
906 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 907 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 908 | "R_PPC64_TOC", /* name */ |
b34976b6 | 909 | FALSE, /* partial_inplace */ |
5bd4f169 | 910 | 0, /* src_mask */ |
f5e87a1d | 911 | ONES (64), /* dst_mask */ |
b34976b6 | 912 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
913 | |
914 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
915 | value to relocate may (!) refer to a PLT entry which the link | |
916 | editor (a) may replace with the symbol value. If the link editor | |
917 | is unable to fully resolve the symbol, it may (b) create a PLT | |
918 | entry and store the address to the new PLT entry in the GOT. | |
919 | This permits lazy resolution of function symbols at run time. | |
920 | The link editor may also skip all of this and just (c) emit a | |
921 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
922 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
923 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
924 | 0, /* rightshift */ | |
925 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
926 | 16, /* bitsize */ | |
b34976b6 | 927 | FALSE, /* pc_relative */ |
5bd4f169 AM |
928 | 0, /* bitpos */ |
929 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 930 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 931 | "R_PPC64_PLTGOT16", /* name */ |
b34976b6 | 932 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
933 | 0, /* src_mask */ |
934 | 0xffff, /* dst_mask */ | |
b34976b6 | 935 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
936 | |
937 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
938 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
939 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
940 | 0, /* rightshift */ | |
941 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
942 | 16, /* bitsize */ | |
b34976b6 | 943 | FALSE, /* pc_relative */ |
5bd4f169 AM |
944 | 0, /* bitpos */ |
945 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 946 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 947 | "R_PPC64_PLTGOT16_LO", /* name */ |
b34976b6 | 948 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
949 | 0, /* src_mask */ |
950 | 0xffff, /* dst_mask */ | |
b34976b6 | 951 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
952 | |
953 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
954 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
955 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
956 | 16, /* rightshift */ | |
957 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
958 | 16, /* bitsize */ | |
b34976b6 | 959 | FALSE, /* pc_relative */ |
5bd4f169 AM |
960 | 0, /* bitpos */ |
961 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 962 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 963 | "R_PPC64_PLTGOT16_HI", /* name */ |
b34976b6 | 964 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
965 | 0, /* src_mask */ |
966 | 0xffff, /* dst_mask */ | |
b34976b6 | 967 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
968 | |
969 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
970 | 1 if the contents of the low 16 bits, treated as a signed number, | |
971 | is negative. */ | |
972 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
973 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
974 | 16, /* rightshift */ | |
975 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
976 | 16, /* bitsize */ | |
b34976b6 | 977 | FALSE, /* pc_relative */ |
5bd4f169 AM |
978 | 0, /* bitpos */ |
979 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 980 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 981 | "R_PPC64_PLTGOT16_HA", /* name */ |
b34976b6 | 982 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
983 | 0, /* src_mask */ |
984 | 0xffff, /* dst_mask */ | |
b34976b6 | 985 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
986 | |
987 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
988 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
989 | 0, /* rightshift */ | |
990 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
991 | 16, /* bitsize */ | |
b34976b6 | 992 | FALSE, /* pc_relative */ |
5bd4f169 AM |
993 | 0, /* bitpos */ |
994 | complain_overflow_bitfield, /* complain_on_overflow */ | |
995 | bfd_elf_generic_reloc, /* special_function */ | |
996 | "R_PPC64_ADDR16_DS", /* name */ | |
b34976b6 | 997 | FALSE, /* partial_inplace */ |
d006db6c | 998 | 0, /* src_mask */ |
5bd4f169 | 999 | 0xfffc, /* dst_mask */ |
b34976b6 | 1000 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1001 | |
1002 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1003 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1004 | 0, /* rightshift */ | |
1005 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1006 | 16, /* bitsize */ | |
b34976b6 | 1007 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1008 | 0, /* bitpos */ |
1009 | complain_overflow_dont,/* complain_on_overflow */ | |
1010 | bfd_elf_generic_reloc, /* special_function */ | |
1011 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
b34976b6 | 1012 | FALSE, /* partial_inplace */ |
d006db6c | 1013 | 0, /* src_mask */ |
5bd4f169 | 1014 | 0xfffc, /* dst_mask */ |
b34976b6 | 1015 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1016 | |
1017 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1018 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1019 | 0, /* rightshift */ | |
1020 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1021 | 16, /* bitsize */ | |
b34976b6 | 1022 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1023 | 0, /* bitpos */ |
1024 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 1025 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 1026 | "R_PPC64_GOT16_DS", /* name */ |
b34976b6 | 1027 | FALSE, /* partial_inplace */ |
d006db6c | 1028 | 0, /* src_mask */ |
5bd4f169 | 1029 | 0xfffc, /* dst_mask */ |
b34976b6 | 1030 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1031 | |
1032 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1033 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1034 | 0, /* rightshift */ | |
1035 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1036 | 16, /* bitsize */ | |
b34976b6 | 1037 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1038 | 0, /* bitpos */ |
1039 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1040 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 1041 | "R_PPC64_GOT16_LO_DS", /* name */ |
b34976b6 | 1042 | FALSE, /* partial_inplace */ |
d006db6c | 1043 | 0, /* src_mask */ |
5bd4f169 | 1044 | 0xfffc, /* dst_mask */ |
b34976b6 | 1045 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1046 | |
1047 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1048 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1049 | 0, /* rightshift */ | |
1050 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1051 | 16, /* bitsize */ | |
b34976b6 | 1052 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1053 | 0, /* bitpos */ |
1054 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1055 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 1056 | "R_PPC64_PLT16_LO_DS", /* name */ |
b34976b6 | 1057 | FALSE, /* partial_inplace */ |
d006db6c | 1058 | 0, /* src_mask */ |
5bd4f169 | 1059 | 0xfffc, /* dst_mask */ |
b34976b6 | 1060 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1061 | |
1062 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
5bd4f169 AM |
1063 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ |
1064 | 0, /* rightshift */ | |
c061c2d8 AM |
1065 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1066 | 16, /* bitsize */ | |
b34976b6 | 1067 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1068 | 0, /* bitpos */ |
1069 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 1070 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 1071 | "R_PPC64_SECTOFF_DS", /* name */ |
b34976b6 | 1072 | FALSE, /* partial_inplace */ |
d006db6c | 1073 | 0, /* src_mask */ |
c061c2d8 | 1074 | 0xfffc, /* dst_mask */ |
b34976b6 | 1075 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1076 | |
1077 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1078 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1079 | 0, /* rightshift */ | |
1080 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1081 | 16, /* bitsize */ | |
b34976b6 | 1082 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1083 | 0, /* bitpos */ |
1084 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1085 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 1086 | "R_PPC64_SECTOFF_LO_DS",/* name */ |
b34976b6 | 1087 | FALSE, /* partial_inplace */ |
d006db6c | 1088 | 0, /* src_mask */ |
5bd4f169 | 1089 | 0xfffc, /* dst_mask */ |
b34976b6 | 1090 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1091 | |
1092 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1093 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1094 | 0, /* rightshift */ | |
1095 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1096 | 16, /* bitsize */ | |
b34976b6 | 1097 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1098 | 0, /* bitpos */ |
1099 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 1100 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 1101 | "R_PPC64_TOC16_DS", /* name */ |
b34976b6 | 1102 | FALSE, /* partial_inplace */ |
d006db6c | 1103 | 0, /* src_mask */ |
5bd4f169 | 1104 | 0xfffc, /* dst_mask */ |
b34976b6 | 1105 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1106 | |
1107 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1108 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1109 | 0, /* rightshift */ | |
1110 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1111 | 16, /* bitsize */ | |
b34976b6 | 1112 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1113 | 0, /* bitpos */ |
1114 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1115 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 1116 | "R_PPC64_TOC16_LO_DS", /* name */ |
b34976b6 | 1117 | FALSE, /* partial_inplace */ |
d006db6c | 1118 | 0, /* src_mask */ |
5bd4f169 | 1119 | 0xfffc, /* dst_mask */ |
b34976b6 | 1120 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1121 | |
1122 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1123 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1124 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ | |
1125 | 0, /* rightshift */ | |
1126 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1127 | 16, /* bitsize */ | |
b34976b6 | 1128 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1129 | 0, /* bitpos */ |
1130 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 1131 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 1132 | "R_PPC64_PLTGOT16_DS", /* name */ |
b34976b6 | 1133 | FALSE, /* partial_inplace */ |
d006db6c | 1134 | 0, /* src_mask */ |
5bd4f169 | 1135 | 0xfffc, /* dst_mask */ |
b34976b6 | 1136 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1137 | |
1138 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1139 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1140 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1141 | 0, /* rightshift */ | |
1142 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1143 | 16, /* bitsize */ | |
b34976b6 | 1144 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1145 | 0, /* bitpos */ |
1146 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1147 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 1148 | "R_PPC64_PLTGOT16_LO_DS",/* name */ |
b34976b6 | 1149 | FALSE, /* partial_inplace */ |
d006db6c | 1150 | 0, /* src_mask */ |
5bd4f169 | 1151 | 0xfffc, /* dst_mask */ |
b34976b6 | 1152 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1153 | |
1154 | /* GNU extension to record C++ vtable hierarchy. */ | |
1155 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1156 | 0, /* rightshift */ | |
1157 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1158 | 0, /* bitsize */ | |
b34976b6 | 1159 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1160 | 0, /* bitpos */ |
1161 | complain_overflow_dont, /* complain_on_overflow */ | |
1162 | NULL, /* special_function */ | |
1163 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1164 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1165 | 0, /* src_mask */ |
1166 | 0, /* dst_mask */ | |
b34976b6 | 1167 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1168 | |
1169 | /* GNU extension to record C++ vtable member usage. */ | |
1170 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1171 | 0, /* rightshift */ | |
1172 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1173 | 0, /* bitsize */ | |
b34976b6 | 1174 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1175 | 0, /* bitpos */ |
1176 | complain_overflow_dont, /* complain_on_overflow */ | |
1177 | NULL, /* special_function */ | |
1178 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1179 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1180 | 0, /* src_mask */ |
1181 | 0, /* dst_mask */ | |
b34976b6 | 1182 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1183 | }; |
1184 | ||
1185 | \f | |
1186 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1187 | be done. */ | |
1188 | ||
1189 | static void | |
1190 | ppc_howto_init () | |
1191 | { | |
1192 | unsigned int i, type; | |
1193 | ||
1194 | for (i = 0; | |
1195 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1196 | i++) | |
1197 | { | |
1198 | type = ppc64_elf_howto_raw[i].type; | |
1199 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1200 | / sizeof (ppc64_elf_howto_table[0]))); | |
1201 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1202 | } | |
1203 | } | |
1204 | ||
1205 | static reloc_howto_type * | |
1206 | ppc64_elf_reloc_type_lookup (abfd, code) | |
1207 | bfd *abfd ATTRIBUTE_UNUSED; | |
1208 | bfd_reloc_code_real_type code; | |
1209 | { | |
1210 | enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE; | |
1211 | ||
1212 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1213 | /* Initialize howto table if needed. */ | |
1214 | ppc_howto_init (); | |
1215 | ||
1216 | switch ((int) code) | |
1217 | { | |
1218 | default: | |
1219 | return (reloc_howto_type *) NULL; | |
1220 | ||
1221 | case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE; | |
1222 | break; | |
1223 | case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32; | |
1224 | break; | |
1225 | case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24; | |
1226 | break; | |
1227 | case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16; | |
1228 | break; | |
1229 | case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO; | |
1230 | break; | |
1231 | case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI; | |
1232 | break; | |
1233 | case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA; | |
1234 | break; | |
1235 | case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14; | |
1236 | break; | |
1237 | case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN; | |
1238 | break; | |
1239 | case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN; | |
1240 | break; | |
1241 | case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24; | |
1242 | break; | |
1243 | case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14; | |
1244 | break; | |
1245 | case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN; | |
1246 | break; | |
1247 | case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN; | |
1248 | break; | |
1249 | case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16; | |
1250 | break; | |
1251 | case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO; | |
1252 | break; | |
1253 | case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI; | |
1254 | break; | |
1255 | case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA; | |
1256 | break; | |
1257 | case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY; | |
1258 | break; | |
1259 | case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT; | |
1260 | break; | |
1261 | case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32; | |
1262 | break; | |
1263 | case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32; | |
1264 | break; | |
1265 | case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32; | |
1266 | break; | |
1267 | case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO; | |
1268 | break; | |
1269 | case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI; | |
1270 | break; | |
1271 | case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA; | |
1272 | break; | |
c061c2d8 | 1273 | case BFD_RELOC_16_BASEREL: ppc_reloc = R_PPC64_SECTOFF; |
5bd4f169 AM |
1274 | break; |
1275 | case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO; | |
1276 | break; | |
1277 | case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI; | |
1278 | break; | |
1279 | case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA; | |
1280 | break; | |
10ed1bba | 1281 | case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64; |
5bd4f169 AM |
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; | |
947216bf | 1354 | Elf_Internal_Rela *dst; |
5bd4f169 | 1355 | { |
65f38f15 AM |
1356 | unsigned int type; |
1357 | ||
ef60b7ff | 1358 | /* Initialize howto table if needed. */ |
5bd4f169 | 1359 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
1360 | ppc_howto_init (); |
1361 | ||
65f38f15 AM |
1362 | type = ELF64_R_TYPE (dst->r_info); |
1363 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1364 | / sizeof (ppc64_elf_howto_table[0]))); | |
1365 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
1366 | } |
1367 | ||
65f38f15 | 1368 | /* Handle the R_PPC_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
1369 | |
1370 | static bfd_reloc_status_type | |
805fc799 AM |
1371 | ppc64_elf_ha_reloc (abfd, reloc_entry, symbol, data, |
1372 | input_section, output_bfd, error_message) | |
1373 | bfd *abfd; | |
5bd4f169 AM |
1374 | arelent *reloc_entry; |
1375 | asymbol *symbol; | |
805fc799 | 1376 | PTR data; |
5bd4f169 AM |
1377 | asection *input_section; |
1378 | bfd *output_bfd; | |
805fc799 | 1379 | char **error_message; |
5bd4f169 | 1380 | { |
805fc799 AM |
1381 | /* If this is a relocatable link (output_bfd test tells us), just |
1382 | call the generic function. Any adjustment will be done at final | |
1383 | link time. */ | |
1384 | if (output_bfd != NULL) | |
cedb70c5 | 1385 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
1386 | input_section, output_bfd, error_message); |
1387 | ||
1388 | /* Adjust the addend for sign extension of the low 16 bits. | |
1389 | We won't actually be using the low 16 bits, so trashing them | |
1390 | doesn't matter. */ | |
1391 | reloc_entry->addend += 0x8000; | |
1392 | return bfd_reloc_continue; | |
1393 | } | |
5bd4f169 | 1394 | |
805fc799 AM |
1395 | static bfd_reloc_status_type |
1396 | ppc64_elf_brtaken_reloc (abfd, reloc_entry, symbol, data, | |
1397 | input_section, output_bfd, error_message) | |
1398 | bfd *abfd; | |
1399 | arelent *reloc_entry; | |
1400 | asymbol *symbol; | |
1401 | PTR data; | |
1402 | asection *input_section; | |
1403 | bfd *output_bfd; | |
1404 | char **error_message; | |
1405 | { | |
1406 | long insn; | |
1407 | enum elf_ppc_reloc_type r_type; | |
1408 | bfd_size_type octets; | |
1409 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 1410 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
1411 | |
1412 | /* If this is a relocatable link (output_bfd test tells us), just | |
1413 | call the generic function. Any adjustment will be done at final | |
1414 | link time. */ | |
5bd4f169 | 1415 | if (output_bfd != NULL) |
cedb70c5 | 1416 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
1417 | input_section, output_bfd, error_message); |
1418 | ||
1419 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
1420 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
1421 | insn &= ~(0x01 << 21); | |
1422 | r_type = (enum elf_ppc_reloc_type) reloc_entry->howto->type; | |
1423 | if (r_type == R_PPC64_ADDR14_BRTAKEN | |
1424 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 1425 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
1426 | |
1427 | if (is_power4) | |
5bd4f169 | 1428 | { |
805fc799 AM |
1429 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
1430 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
1431 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
1432 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
1433 | insn |= 0x02 << 21; | |
1434 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
1435 | insn |= 0x08 << 21; | |
1436 | else | |
1437 | return bfd_reloc_continue; | |
5bd4f169 | 1438 | } |
805fc799 AM |
1439 | else |
1440 | { | |
1441 | bfd_vma target = 0; | |
1442 | bfd_vma from; | |
5bd4f169 | 1443 | |
805fc799 AM |
1444 | if (!bfd_is_com_section (symbol->section)) |
1445 | target = symbol->value; | |
1446 | target += symbol->section->output_section->vma; | |
1447 | target += symbol->section->output_offset; | |
1448 | target += reloc_entry->addend; | |
5bd4f169 | 1449 | |
805fc799 AM |
1450 | from = (reloc_entry->address |
1451 | + input_section->output_offset | |
1452 | + input_section->output_section->vma); | |
5bd4f169 | 1453 | |
805fc799 AM |
1454 | /* Invert 'y' bit if not the default. */ |
1455 | if ((bfd_signed_vma) (target - from) < 0) | |
1456 | insn ^= 0x01 << 21; | |
1457 | } | |
1458 | bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + octets); | |
1459 | return bfd_reloc_continue; | |
1460 | } | |
5bd4f169 | 1461 | |
805fc799 AM |
1462 | static bfd_reloc_status_type |
1463 | ppc64_elf_sectoff_reloc (abfd, reloc_entry, symbol, data, | |
1464 | input_section, output_bfd, error_message) | |
1465 | bfd *abfd; | |
1466 | arelent *reloc_entry; | |
1467 | asymbol *symbol; | |
1468 | PTR data; | |
1469 | asection *input_section; | |
1470 | bfd *output_bfd; | |
1471 | char **error_message; | |
1472 | { | |
1473 | /* If this is a relocatable link (output_bfd test tells us), just | |
1474 | call the generic function. Any adjustment will be done at final | |
1475 | link time. */ | |
1476 | if (output_bfd != NULL) | |
cedb70c5 | 1477 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 1478 | input_section, output_bfd, error_message); |
5bd4f169 | 1479 | |
805fc799 AM |
1480 | /* Subtract the symbol section base address. */ |
1481 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
1482 | return bfd_reloc_continue; |
1483 | } | |
1484 | ||
805fc799 AM |
1485 | static bfd_reloc_status_type |
1486 | ppc64_elf_sectoff_ha_reloc (abfd, reloc_entry, symbol, data, | |
1487 | input_section, output_bfd, error_message) | |
1488 | bfd *abfd; | |
1489 | arelent *reloc_entry; | |
1490 | asymbol *symbol; | |
1491 | PTR data; | |
1492 | asection *input_section; | |
1493 | bfd *output_bfd; | |
1494 | char **error_message; | |
1495 | { | |
1496 | /* If this is a relocatable link (output_bfd test tells us), just | |
1497 | call the generic function. Any adjustment will be done at final | |
1498 | link time. */ | |
1499 | if (output_bfd != NULL) | |
cedb70c5 | 1500 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
1501 | input_section, output_bfd, error_message); |
1502 | ||
1503 | /* Subtract the symbol section base address. */ | |
1504 | reloc_entry->addend -= symbol->section->output_section->vma; | |
1505 | ||
1506 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
1507 | reloc_entry->addend += 0x8000; | |
1508 | return bfd_reloc_continue; | |
1509 | } | |
1510 | ||
1511 | static bfd_reloc_status_type | |
1512 | ppc64_elf_toc_reloc (abfd, reloc_entry, symbol, data, | |
1513 | input_section, output_bfd, error_message) | |
1514 | bfd *abfd; | |
1515 | arelent *reloc_entry; | |
1516 | asymbol *symbol; | |
1517 | PTR data; | |
1518 | asection *input_section; | |
1519 | bfd *output_bfd; | |
1520 | char **error_message; | |
1521 | { | |
1522 | bfd_vma TOCstart; | |
1523 | ||
1524 | /* If this is a relocatable link (output_bfd test tells us), just | |
1525 | call the generic function. Any adjustment will be done at final | |
1526 | link time. */ | |
1527 | if (output_bfd != NULL) | |
cedb70c5 | 1528 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
1529 | input_section, output_bfd, error_message); |
1530 | ||
1531 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
1532 | if (TOCstart == 0) | |
1533 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
1534 | ||
1535 | /* Subtract the TOC base address. */ | |
1536 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
1537 | return bfd_reloc_continue; | |
1538 | } | |
1539 | ||
1540 | static bfd_reloc_status_type | |
1541 | ppc64_elf_toc_ha_reloc (abfd, reloc_entry, symbol, data, | |
1542 | input_section, output_bfd, error_message) | |
1543 | bfd *abfd; | |
1544 | arelent *reloc_entry; | |
1545 | asymbol *symbol; | |
1546 | PTR data; | |
1547 | asection *input_section; | |
1548 | bfd *output_bfd; | |
1549 | char **error_message; | |
1550 | { | |
1551 | bfd_vma TOCstart; | |
1552 | ||
1553 | /* If this is a relocatable link (output_bfd test tells us), just | |
1554 | call the generic function. Any adjustment will be done at final | |
1555 | link time. */ | |
1556 | if (output_bfd != NULL) | |
cedb70c5 | 1557 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
1558 | input_section, output_bfd, error_message); |
1559 | ||
1560 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
1561 | if (TOCstart == 0) | |
1562 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
1563 | ||
1564 | /* Subtract the TOC base address. */ | |
1565 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
1566 | ||
1567 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
1568 | reloc_entry->addend += 0x8000; | |
1569 | return bfd_reloc_continue; | |
1570 | } | |
1571 | ||
1572 | static bfd_reloc_status_type | |
1573 | ppc64_elf_toc64_reloc (abfd, reloc_entry, symbol, data, | |
1574 | input_section, output_bfd, error_message) | |
1575 | bfd *abfd; | |
1576 | arelent *reloc_entry; | |
1577 | asymbol *symbol; | |
1578 | PTR data; | |
1579 | asection *input_section; | |
1580 | bfd *output_bfd; | |
1581 | char **error_message; | |
1582 | { | |
1583 | bfd_vma TOCstart; | |
1584 | bfd_size_type octets; | |
1585 | ||
1586 | /* If this is a relocatable link (output_bfd test tells us), just | |
1587 | call the generic function. Any adjustment will be done at final | |
1588 | link time. */ | |
1589 | if (output_bfd != NULL) | |
cedb70c5 | 1590 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
1591 | input_section, output_bfd, error_message); |
1592 | ||
1593 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
1594 | if (TOCstart == 0) | |
1595 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
1596 | ||
1597 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
1598 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
1599 | return bfd_reloc_ok; | |
1600 | } | |
1601 | ||
1602 | static bfd_reloc_status_type | |
1603 | ppc64_elf_unhandled_reloc (abfd, reloc_entry, symbol, data, | |
1604 | input_section, output_bfd, error_message) | |
1605 | bfd *abfd; | |
1606 | arelent *reloc_entry; | |
1607 | asymbol *symbol; | |
1608 | PTR data; | |
1609 | asection *input_section; | |
1610 | bfd *output_bfd; | |
1611 | char **error_message; | |
1612 | { | |
1613 | /* If this is a relocatable link (output_bfd test tells us), just | |
1614 | call the generic function. Any adjustment will be done at final | |
1615 | link time. */ | |
1616 | if (output_bfd != NULL) | |
cedb70c5 | 1617 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
1618 | input_section, output_bfd, error_message); |
1619 | ||
1620 | if (error_message != NULL) | |
1621 | { | |
1622 | static char buf[60]; | |
1623 | sprintf (buf, "generic linker can't handle %s", | |
1624 | reloc_entry->howto->name); | |
1625 | *error_message = buf; | |
1626 | } | |
1627 | return bfd_reloc_dangerous; | |
1628 | } | |
1629 | ||
feee612b AM |
1630 | /* Fix bad default arch selected for a 64 bit input bfd when the |
1631 | default is 32 bit. */ | |
1632 | ||
b34976b6 | 1633 | static bfd_boolean |
feee612b AM |
1634 | ppc64_elf_object_p (abfd) |
1635 | bfd *abfd; | |
1636 | { | |
1637 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
1638 | { | |
1639 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
1640 | ||
1641 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
1642 | { | |
1643 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
1644 | abfd->arch_info = abfd->arch_info->next; | |
1645 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
1646 | } | |
1647 | } | |
b34976b6 | 1648 | return TRUE; |
feee612b AM |
1649 | } |
1650 | ||
5bd4f169 AM |
1651 | /* Merge backend specific data from an object file to the output |
1652 | object file when linking. */ | |
2f6d9989 | 1653 | |
b34976b6 | 1654 | static bfd_boolean |
5bd4f169 AM |
1655 | ppc64_elf_merge_private_bfd_data (ibfd, obfd) |
1656 | bfd *ibfd; | |
1657 | bfd *obfd; | |
1658 | { | |
5bd4f169 AM |
1659 | /* Check if we have the same endianess. */ |
1660 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
87e226ce | 1661 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
5bd4f169 AM |
1662 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
1663 | { | |
1664 | const char *msg; | |
1665 | ||
1666 | if (bfd_big_endian (ibfd)) | |
1667 | msg = _("%s: compiled for a big endian system and target is little endian"); | |
1668 | else | |
1669 | msg = _("%s: compiled for a little endian system and target is big endian"); | |
1670 | ||
8f615d07 | 1671 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
5bd4f169 AM |
1672 | |
1673 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 1674 | return FALSE; |
5bd4f169 AM |
1675 | } |
1676 | ||
b34976b6 | 1677 | return TRUE; |
5bd4f169 AM |
1678 | } |
1679 | \f | |
65f38f15 AM |
1680 | /* The following functions are specific to the ELF linker, while |
1681 | functions above are used generally. Those named ppc64_elf_* are | |
1682 | called by the main ELF linker code. They appear in this file more | |
1683 | or less in the order in which they are called. eg. | |
1684 | ppc64_elf_check_relocs is called early in the link process, | |
1685 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
1686 | called. |
1687 | ||
1688 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
1689 | functions have both a function code symbol and a function descriptor | |
1690 | symbol. A call to foo in a relocatable object file looks like: | |
1691 | ||
1692 | . .text | |
1693 | . x: | |
1694 | . bl .foo | |
1695 | . nop | |
1696 | ||
1697 | The function definition in another object file might be: | |
1698 | ||
1699 | . .section .opd | |
1700 | . foo: .quad .foo | |
1701 | . .quad .TOC.@tocbase | |
1702 | . .quad 0 | |
1703 | . | |
1704 | . .text | |
1705 | . .foo: blr | |
1706 | ||
1707 | When the linker resolves the call during a static link, the branch | |
1708 | unsurprisingly just goes to .foo and the .opd information is unused. | |
1709 | If the function definition is in a shared library, things are a little | |
1710 | different: The call goes via a plt call stub, the opd information gets | |
1711 | copied to the plt, and the linker patches the nop. | |
1712 | ||
1713 | . x: | |
1714 | . bl .foo_stub | |
1715 | . ld 2,40(1) | |
1716 | . | |
1717 | . | |
1718 | . .foo_stub: | |
1719 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
1720 | . addi 12,12,Lfoo@toc@l # is slightly optimised, but | |
1721 | . std 2,40(1) # this is the general idea | |
1722 | . ld 11,0(12) | |
1723 | . ld 2,8(12) | |
1724 | . mtctr 11 | |
1725 | . ld 11,16(12) | |
1726 | . bctr | |
1727 | . | |
1728 | . .section .plt | |
1729 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
1730 | ||
1731 | The "reloc ()" notation is supposed to indicate that the linker emits | |
1732 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
1733 | copying. | |
1734 | ||
1735 | What are the difficulties here? Well, firstly, the relocations | |
1736 | examined by the linker in check_relocs are against the function code | |
1737 | sym .foo, while the dynamic relocation in the plt is emitted against | |
1738 | the function descriptor symbol, foo. Somewhere along the line, we need | |
1739 | to carefully copy dynamic link information from one symbol to the other. | |
1740 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
1741 | symbol as is normal for most other backends. We need foo dynamic | |
1742 | instead, at least for an application final link. However, when | |
1743 | creating a shared library containing foo, we need to have both symbols | |
1744 | dynamic so that references to .foo are satisfied during the early | |
1745 | stages of linking. Otherwise the linker might decide to pull in a | |
41bd81ab | 1746 | definition from some other object, eg. a static library. */ |
65f38f15 AM |
1747 | |
1748 | /* The linker needs to keep track of the number of relocs that it | |
1749 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
1750 | This is so that it can later discard them if they are found to be | |
1751 | unnecessary. We store the information in a field extending the | |
1752 | regular ELF linker hash table. */ | |
1753 | ||
1754 | struct ppc_dyn_relocs | |
1755 | { | |
1756 | struct ppc_dyn_relocs *next; | |
1757 | ||
1758 | /* The input section of the reloc. */ | |
1759 | asection *sec; | |
1760 | ||
1761 | /* Total number of relocs copied for the input section. */ | |
1762 | bfd_size_type count; | |
1763 | ||
1764 | /* Number of pc-relative relocs copied for the input section. */ | |
1765 | bfd_size_type pc_count; | |
1766 | }; | |
1767 | ||
1768 | /* Of those relocs that might be copied as dynamic relocs, this macro | |
1769 | selects between relative and absolute types. */ | |
1770 | ||
1771 | #define IS_ABSOLUTE_RELOC(RTYPE) \ | |
805fc799 AM |
1772 | ((RTYPE) != R_PPC64_REL32 \ |
1773 | && (RTYPE) != R_PPC64_REL64 \ | |
1774 | && (RTYPE) != R_PPC64_ADDR30) | |
65f38f15 | 1775 | |
721956f4 AM |
1776 | /* Section name for stubs is the associated section name plus this |
1777 | string. */ | |
1778 | #define STUB_SUFFIX ".stub" | |
1779 | ||
1780 | /* Linker stubs. | |
1781 | ppc_stub_long_branch: | |
1782 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
1783 | destination, but a 24 bit branch in a stub section will reach. | |
1784 | . b dest | |
1785 | ||
1786 | ppc_stub_plt_branch: | |
1787 | Similar to the above, but a 24 bit branch in the stub section won't | |
1788 | reach its destination. | |
87e226ce AM |
1789 | . addis %r12,%r2,xxx@toc@ha |
1790 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
1791 | . mtctr %r11 |
1792 | . bctr | |
1793 | ||
1794 | ppc_stub_plt_call: | |
1795 | Used to call a function in a shared library. | |
87e226ce | 1796 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 1797 | . std %r2,40(%r1) |
87e226ce AM |
1798 | . ld %r11,xxx+0@toc@l(%r12) |
1799 | . ld %r2,xxx+8@toc@l(%r12) | |
721956f4 | 1800 | . mtctr %r11 |
87e226ce | 1801 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 AM |
1802 | . bctr |
1803 | */ | |
1804 | ||
1805 | enum ppc_stub_type { | |
1806 | ppc_stub_none, | |
1807 | ppc_stub_long_branch, | |
1808 | ppc_stub_plt_branch, | |
1809 | ppc_stub_plt_call | |
1810 | }; | |
1811 | ||
1812 | struct ppc_stub_hash_entry { | |
1813 | ||
1814 | /* Base hash table entry structure. */ | |
1815 | struct bfd_hash_entry root; | |
1816 | ||
1817 | /* The stub section. */ | |
1818 | asection *stub_sec; | |
1819 | ||
1820 | /* Offset within stub_sec of the beginning of this stub. */ | |
1821 | bfd_vma stub_offset; | |
1822 | ||
1823 | /* Given the symbol's value and its section we can determine its final | |
1824 | value when building the stubs (so the stub knows where to jump. */ | |
1825 | bfd_vma target_value; | |
1826 | asection *target_section; | |
1827 | ||
1828 | enum ppc_stub_type stub_type; | |
1829 | ||
1830 | /* The symbol table entry, if any, that this was derived from. */ | |
1831 | struct ppc_link_hash_entry *h; | |
1832 | ||
1833 | /* Where this stub is being called from, or, in the case of combined | |
1834 | stub sections, the first input section in the group. */ | |
1835 | asection *id_sec; | |
1836 | }; | |
1837 | ||
1838 | struct ppc_branch_hash_entry { | |
1839 | ||
1840 | /* Base hash table entry structure. */ | |
1841 | struct bfd_hash_entry root; | |
1842 | ||
1843 | /* Offset within .branch_lt. */ | |
1844 | unsigned int offset; | |
1845 | ||
1846 | /* Generation marker. */ | |
1847 | unsigned int iter; | |
1848 | }; | |
65f38f15 AM |
1849 | |
1850 | struct ppc_link_hash_entry | |
1851 | { | |
1852 | struct elf_link_hash_entry elf; | |
1853 | ||
721956f4 AM |
1854 | /* A pointer to the most recently used stub hash entry against this |
1855 | symbol. */ | |
1856 | struct ppc_stub_hash_entry *stub_cache; | |
1857 | ||
65f38f15 AM |
1858 | /* Track dynamic relocs copied for this symbol. */ |
1859 | struct ppc_dyn_relocs *dyn_relocs; | |
e86ce104 | 1860 | |
721956f4 AM |
1861 | /* Link between function code and descriptor symbols. */ |
1862 | struct elf_link_hash_entry *oh; | |
1863 | ||
e86ce104 AM |
1864 | /* Flag function code and descriptor symbols. */ |
1865 | unsigned int is_func:1; | |
1866 | unsigned int is_func_descriptor:1; | |
1e2f5b6e | 1867 | unsigned int is_entry:1; |
65f38f15 AM |
1868 | }; |
1869 | ||
1870 | /* ppc64 ELF linker hash table. */ | |
1871 | ||
1872 | struct ppc_link_hash_table | |
1873 | { | |
1874 | struct elf_link_hash_table elf; | |
1875 | ||
721956f4 AM |
1876 | /* The stub hash table. */ |
1877 | struct bfd_hash_table stub_hash_table; | |
1878 | ||
1879 | /* Another hash table for plt_branch stubs. */ | |
1880 | struct bfd_hash_table branch_hash_table; | |
1881 | ||
1882 | /* Linker stub bfd. */ | |
1883 | bfd *stub_bfd; | |
1884 | ||
1885 | /* Linker call-backs. */ | |
1886 | asection * (*add_stub_section) PARAMS ((const char *, asection *)); | |
1887 | void (*layout_sections_again) PARAMS ((void)); | |
1888 | ||
1889 | /* Array to keep track of which stub sections have been created, and | |
1890 | information on stub grouping. */ | |
1891 | struct map_stub { | |
1892 | /* This is the section to which stubs in the group will be attached. */ | |
1893 | asection *link_sec; | |
1894 | /* The stub section. */ | |
1895 | asection *stub_sec; | |
1896 | } *stub_group; | |
1897 | ||
1898 | /* Assorted information used by ppc64_elf_size_stubs. */ | |
721956f4 AM |
1899 | int top_index; |
1900 | asection **input_list; | |
721956f4 | 1901 | |
65f38f15 AM |
1902 | /* Short-cuts to get to dynamic linker sections. */ |
1903 | asection *sgot; | |
1904 | asection *srelgot; | |
1905 | asection *splt; | |
1906 | asection *srelplt; | |
1907 | asection *sdynbss; | |
1908 | asection *srelbss; | |
1909 | asection *sglink; | |
82bd7b59 | 1910 | asection *sfpr; |
721956f4 AM |
1911 | asection *sbrlt; |
1912 | asection *srelbrlt; | |
ec338859 | 1913 | |
5d1634d7 | 1914 | /* Set on error. */ |
721956f4 AM |
1915 | unsigned int stub_error; |
1916 | ||
1917 | /* Flag set when small branches are detected. Used to | |
1918 | select suitable defaults for the stub group size. */ | |
1919 | unsigned int has_14bit_branch; | |
1920 | ||
805fc799 AM |
1921 | /* Set if we detect a reference undefined weak symbol. */ |
1922 | unsigned int have_undefweak; | |
1923 | ||
721956f4 AM |
1924 | /* Incremented every time we size stubs. */ |
1925 | unsigned int stub_iteration; | |
5d1634d7 | 1926 | |
ec338859 AM |
1927 | /* Small local sym to section mapping cache. */ |
1928 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
1929 | }; |
1930 | ||
721956f4 AM |
1931 | static struct bfd_hash_entry *stub_hash_newfunc |
1932 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
1933 | static struct bfd_hash_entry *branch_hash_newfunc | |
1934 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
1935 | static struct bfd_hash_entry *link_hash_newfunc | |
1936 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
1937 | static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create | |
1938 | PARAMS ((bfd *)); | |
1939 | static void ppc64_elf_link_hash_table_free | |
1940 | PARAMS ((struct bfd_link_hash_table *)); | |
1941 | static char *ppc_stub_name | |
1942 | PARAMS ((const asection *, const asection *, | |
1943 | const struct ppc_link_hash_entry *, const Elf_Internal_Rela *)); | |
1944 | static struct ppc_stub_hash_entry *ppc_get_stub_entry | |
1945 | PARAMS ((const asection *, const asection *, struct elf_link_hash_entry *, | |
1946 | const Elf_Internal_Rela *, struct ppc_link_hash_table *)); | |
1947 | static struct ppc_stub_hash_entry *ppc_add_stub | |
1948 | PARAMS ((const char *, asection *, struct ppc_link_hash_table *)); | |
b34976b6 | 1949 | static bfd_boolean create_linkage_sections |
721956f4 | 1950 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 | 1951 | static bfd_boolean create_got_section |
721956f4 | 1952 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 | 1953 | static bfd_boolean ppc64_elf_create_dynamic_sections |
721956f4 AM |
1954 | PARAMS ((bfd *, struct bfd_link_info *)); |
1955 | static void ppc64_elf_copy_indirect_symbol | |
b48fa14c AM |
1956 | PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *, |
1957 | struct elf_link_hash_entry *)); | |
b34976b6 | 1958 | static bfd_boolean ppc64_elf_check_relocs |
721956f4 AM |
1959 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
1960 | const Elf_Internal_Rela *)); | |
1961 | static asection * ppc64_elf_gc_mark_hook | |
1e2f5b6e AM |
1962 | PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
1963 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | |
b34976b6 | 1964 | static bfd_boolean ppc64_elf_gc_sweep_hook |
1e2f5b6e AM |
1965 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
1966 | const Elf_Internal_Rela *)); | |
b34976b6 | 1967 | static bfd_boolean func_desc_adjust |
721956f4 | 1968 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
b34976b6 | 1969 | static bfd_boolean ppc64_elf_func_desc_adjust |
721956f4 | 1970 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 | 1971 | static bfd_boolean ppc64_elf_adjust_dynamic_symbol |
721956f4 AM |
1972 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); |
1973 | static void ppc64_elf_hide_symbol | |
b34976b6 AM |
1974 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean)); |
1975 | static bfd_boolean allocate_dynrelocs | |
721956f4 | 1976 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
b34976b6 | 1977 | static bfd_boolean readonly_dynrelocs |
721956f4 AM |
1978 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
1979 | static enum elf_reloc_type_class ppc64_elf_reloc_type_class | |
1980 | PARAMS ((const Elf_Internal_Rela *)); | |
b34976b6 | 1981 | static bfd_boolean ppc64_elf_size_dynamic_sections |
721956f4 AM |
1982 | PARAMS ((bfd *, struct bfd_link_info *)); |
1983 | static INLINE enum ppc_stub_type ppc_type_of_stub | |
1984 | PARAMS ((asection *, const Elf_Internal_Rela *, | |
1985 | struct ppc_link_hash_entry **, bfd_vma)); | |
1986 | static bfd_byte *build_plt_stub | |
1987 | PARAMS ((bfd *, bfd_byte *, int, int)); | |
b34976b6 | 1988 | static bfd_boolean ppc_build_one_stub |
721956f4 | 1989 | PARAMS ((struct bfd_hash_entry *, PTR)); |
b34976b6 | 1990 | static bfd_boolean ppc_size_one_stub |
721956f4 AM |
1991 | PARAMS ((struct bfd_hash_entry *, PTR)); |
1992 | static void group_sections | |
b34976b6 AM |
1993 | PARAMS ((struct ppc_link_hash_table *, bfd_size_type, bfd_boolean)); |
1994 | static bfd_boolean ppc64_elf_relocate_section | |
721956f4 AM |
1995 | PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *, |
1996 | Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, | |
1997 | asection **)); | |
b34976b6 | 1998 | static bfd_boolean ppc64_elf_finish_dynamic_symbol |
721956f4 AM |
1999 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, |
2000 | Elf_Internal_Sym *)); | |
b34976b6 | 2001 | static bfd_boolean ppc64_elf_finish_dynamic_sections |
721956f4 AM |
2002 | PARAMS ((bfd *, struct bfd_link_info *)); |
2003 | ||
65f38f15 AM |
2004 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ |
2005 | ||
2006 | #define ppc_hash_table(p) \ | |
2007 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
2008 | ||
721956f4 AM |
2009 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
2010 | ((struct ppc_stub_hash_entry *) \ | |
2011 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2012 | ||
2013 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
2014 | ((struct ppc_branch_hash_entry *) \ | |
2015 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2016 | ||
2017 | /* Create an entry in the stub hash table. */ | |
2018 | ||
2019 | static struct bfd_hash_entry * | |
2020 | stub_hash_newfunc (entry, table, string) | |
2021 | struct bfd_hash_entry *entry; | |
2022 | struct bfd_hash_table *table; | |
2023 | const char *string; | |
2024 | { | |
2025 | /* Allocate the structure if it has not already been allocated by a | |
2026 | subclass. */ | |
2027 | if (entry == NULL) | |
2028 | { | |
2029 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
2030 | if (entry == NULL) | |
2031 | return entry; | |
2032 | } | |
2033 | ||
2034 | /* Call the allocation method of the superclass. */ | |
2035 | entry = bfd_hash_newfunc (entry, table, string); | |
2036 | if (entry != NULL) | |
2037 | { | |
2038 | struct ppc_stub_hash_entry *eh; | |
2039 | ||
2040 | /* Initialize the local fields. */ | |
2041 | eh = (struct ppc_stub_hash_entry *) entry; | |
2042 | eh->stub_sec = NULL; | |
2043 | eh->stub_offset = 0; | |
2044 | eh->target_value = 0; | |
2045 | eh->target_section = NULL; | |
2046 | eh->stub_type = ppc_stub_none; | |
2047 | eh->h = NULL; | |
2048 | eh->id_sec = NULL; | |
2049 | } | |
2050 | ||
2051 | return entry; | |
2052 | } | |
2053 | ||
2054 | /* Create an entry in the branch hash table. */ | |
2055 | ||
2056 | static struct bfd_hash_entry * | |
2057 | branch_hash_newfunc (entry, table, string) | |
2058 | struct bfd_hash_entry *entry; | |
2059 | struct bfd_hash_table *table; | |
2060 | const char *string; | |
2061 | { | |
2062 | /* Allocate the structure if it has not already been allocated by a | |
2063 | subclass. */ | |
2064 | if (entry == NULL) | |
2065 | { | |
2066 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); | |
2067 | if (entry == NULL) | |
2068 | return entry; | |
2069 | } | |
2070 | ||
2071 | /* Call the allocation method of the superclass. */ | |
2072 | entry = bfd_hash_newfunc (entry, table, string); | |
2073 | if (entry != NULL) | |
2074 | { | |
2075 | struct ppc_branch_hash_entry *eh; | |
2076 | ||
2077 | /* Initialize the local fields. */ | |
2078 | eh = (struct ppc_branch_hash_entry *) entry; | |
2079 | eh->offset = 0; | |
2080 | eh->iter = 0; | |
2081 | } | |
2082 | ||
2083 | return entry; | |
2084 | } | |
2085 | ||
65f38f15 AM |
2086 | /* Create an entry in a ppc64 ELF linker hash table. */ |
2087 | ||
2088 | static struct bfd_hash_entry * | |
2089 | link_hash_newfunc (entry, table, string) | |
2090 | struct bfd_hash_entry *entry; | |
2091 | struct bfd_hash_table *table; | |
2092 | const char *string; | |
2093 | { | |
2094 | /* Allocate the structure if it has not already been allocated by a | |
2095 | subclass. */ | |
2096 | if (entry == NULL) | |
2097 | { | |
2098 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
2099 | if (entry == NULL) | |
2100 | return entry; | |
2101 | } | |
2102 | ||
2103 | /* Call the allocation method of the superclass. */ | |
2104 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2105 | if (entry != NULL) | |
2106 | { | |
2107 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
2108 | ||
721956f4 | 2109 | eh->stub_cache = NULL; |
65f38f15 | 2110 | eh->dyn_relocs = NULL; |
721956f4 | 2111 | eh->oh = NULL; |
e86ce104 AM |
2112 | eh->is_func = 0; |
2113 | eh->is_func_descriptor = 0; | |
1e2f5b6e | 2114 | eh->is_entry = 0; |
65f38f15 AM |
2115 | } |
2116 | ||
2117 | return entry; | |
2118 | } | |
2119 | ||
2120 | /* Create a ppc64 ELF linker hash table. */ | |
2121 | ||
2122 | static struct bfd_link_hash_table * | |
2123 | ppc64_elf_link_hash_table_create (abfd) | |
2124 | bfd *abfd; | |
2125 | { | |
2126 | struct ppc_link_hash_table *htab; | |
2127 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
2128 | ||
e2d34d7d | 2129 | htab = (struct ppc_link_hash_table *) bfd_malloc (amt); |
65f38f15 AM |
2130 | if (htab == NULL) |
2131 | return NULL; | |
2132 | ||
2133 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
2134 | { | |
e2d34d7d | 2135 | free (htab); |
65f38f15 AM |
2136 | return NULL; |
2137 | } | |
2138 | ||
721956f4 AM |
2139 | /* Init the stub hash table too. */ |
2140 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) | |
2141 | return NULL; | |
2142 | ||
2143 | /* And the branch hash table. */ | |
2144 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) | |
2145 | return NULL; | |
2146 | ||
2147 | htab->stub_bfd = NULL; | |
2148 | htab->add_stub_section = NULL; | |
2149 | htab->layout_sections_again = NULL; | |
2150 | htab->stub_group = NULL; | |
65f38f15 AM |
2151 | htab->sgot = NULL; |
2152 | htab->srelgot = NULL; | |
2153 | htab->splt = NULL; | |
2154 | htab->srelplt = NULL; | |
2155 | htab->sdynbss = NULL; | |
2156 | htab->srelbss = NULL; | |
2157 | htab->sglink = NULL; | |
82bd7b59 | 2158 | htab->sfpr = NULL; |
721956f4 AM |
2159 | htab->sbrlt = NULL; |
2160 | htab->srelbrlt = NULL; | |
2161 | htab->stub_error = 0; | |
2162 | htab->has_14bit_branch = 0; | |
805fc799 | 2163 | htab->have_undefweak = 0; |
721956f4 | 2164 | htab->stub_iteration = 0; |
ec338859 | 2165 | htab->sym_sec.abfd = NULL; |
65f38f15 AM |
2166 | |
2167 | return &htab->elf.root; | |
2168 | } | |
2169 | ||
721956f4 AM |
2170 | /* Free the derived linker hash table. */ |
2171 | ||
2172 | static void | |
2173 | ppc64_elf_link_hash_table_free (hash) | |
2174 | struct bfd_link_hash_table *hash; | |
2175 | { | |
2176 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
2177 | ||
2178 | bfd_hash_table_free (&ret->stub_hash_table); | |
2179 | bfd_hash_table_free (&ret->branch_hash_table); | |
2180 | _bfd_generic_link_hash_table_free (hash); | |
2181 | } | |
2182 | ||
2183 | /* Build a name for an entry in the stub hash table. */ | |
2184 | ||
2185 | static char * | |
2186 | ppc_stub_name (input_section, sym_sec, h, rel) | |
2187 | const asection *input_section; | |
2188 | const asection *sym_sec; | |
2189 | const struct ppc_link_hash_entry *h; | |
2190 | const Elf_Internal_Rela *rel; | |
2191 | { | |
2192 | char *stub_name; | |
2193 | bfd_size_type len; | |
2194 | ||
2195 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
2196 | offsets from a sym as a branch target? In fact, we could | |
2197 | probably assume the addend is always zero. */ | |
2198 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
2199 | ||
2200 | if (h) | |
2201 | { | |
2202 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
2203 | stub_name = bfd_malloc (len); | |
2204 | if (stub_name != NULL) | |
2205 | { | |
2206 | sprintf (stub_name, "%08x_%s+%x", | |
2207 | input_section->id & 0xffffffff, | |
2208 | h->elf.root.root.string, | |
2209 | (int) rel->r_addend & 0xffffffff); | |
2210 | } | |
2211 | } | |
2212 | else | |
2213 | { | |
2214 | len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1; | |
2215 | stub_name = bfd_malloc (len); | |
2216 | if (stub_name != NULL) | |
2217 | { | |
2218 | sprintf (stub_name, "%08x_%x:%x+%x", | |
2219 | input_section->id & 0xffffffff, | |
2220 | sym_sec->id & 0xffffffff, | |
2221 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
2222 | (int) rel->r_addend & 0xffffffff); | |
2223 | } | |
2224 | } | |
2225 | return stub_name; | |
2226 | } | |
2227 | ||
2228 | /* Look up an entry in the stub hash. Stub entries are cached because | |
2229 | creating the stub name takes a bit of time. */ | |
2230 | ||
2231 | static struct ppc_stub_hash_entry * | |
2232 | ppc_get_stub_entry (input_section, sym_sec, hash, rel, htab) | |
2233 | const asection *input_section; | |
2234 | const asection *sym_sec; | |
2235 | struct elf_link_hash_entry *hash; | |
2236 | const Elf_Internal_Rela *rel; | |
2237 | struct ppc_link_hash_table *htab; | |
2238 | { | |
2239 | struct ppc_stub_hash_entry *stub_entry; | |
2240 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; | |
2241 | const asection *id_sec; | |
2242 | ||
2243 | /* If this input section is part of a group of sections sharing one | |
2244 | stub section, then use the id of the first section in the group. | |
2245 | Stub names need to include a section id, as there may well be | |
2246 | more than one stub used to reach say, printf, and we need to | |
2247 | distinguish between them. */ | |
2248 | id_sec = htab->stub_group[input_section->id].link_sec; | |
2249 | ||
2250 | if (h != NULL && h->stub_cache != NULL | |
2251 | && h->stub_cache->h == h | |
2252 | && h->stub_cache->id_sec == id_sec) | |
2253 | { | |
2254 | stub_entry = h->stub_cache; | |
2255 | } | |
2256 | else | |
2257 | { | |
2258 | char *stub_name; | |
2259 | ||
2260 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
2261 | if (stub_name == NULL) | |
2262 | return NULL; | |
2263 | ||
2264 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 2265 | stub_name, FALSE, FALSE); |
721956f4 AM |
2266 | if (h != NULL) |
2267 | h->stub_cache = stub_entry; | |
2268 | ||
2269 | free (stub_name); | |
2270 | } | |
2271 | ||
2272 | return stub_entry; | |
2273 | } | |
2274 | ||
2275 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
2276 | stub entry are initialised. */ | |
2277 | ||
2278 | static struct ppc_stub_hash_entry * | |
2279 | ppc_add_stub (stub_name, section, htab) | |
2280 | const char *stub_name; | |
2281 | asection *section; | |
2282 | struct ppc_link_hash_table *htab; | |
2283 | { | |
2284 | asection *link_sec; | |
2285 | asection *stub_sec; | |
2286 | struct ppc_stub_hash_entry *stub_entry; | |
2287 | ||
2288 | link_sec = htab->stub_group[section->id].link_sec; | |
2289 | stub_sec = htab->stub_group[section->id].stub_sec; | |
2290 | if (stub_sec == NULL) | |
2291 | { | |
2292 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
2293 | if (stub_sec == NULL) | |
2294 | { | |
d4c88bbb | 2295 | size_t namelen; |
721956f4 AM |
2296 | bfd_size_type len; |
2297 | char *s_name; | |
2298 | ||
d4c88bbb AM |
2299 | namelen = strlen (link_sec->name); |
2300 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
2301 | s_name = bfd_alloc (htab->stub_bfd, len); |
2302 | if (s_name == NULL) | |
2303 | return NULL; | |
2304 | ||
d4c88bbb AM |
2305 | memcpy (s_name, link_sec->name, namelen); |
2306 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
2307 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
2308 | if (stub_sec == NULL) | |
2309 | return NULL; | |
2310 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
2311 | } | |
2312 | htab->stub_group[section->id].stub_sec = stub_sec; | |
2313 | } | |
2314 | ||
2315 | /* Enter this entry into the linker stub hash table. */ | |
2316 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 2317 | TRUE, FALSE); |
721956f4 AM |
2318 | if (stub_entry == NULL) |
2319 | { | |
2320 | (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), | |
2321 | bfd_archive_filename (section->owner), | |
2322 | stub_name); | |
2323 | return NULL; | |
2324 | } | |
2325 | ||
2326 | stub_entry->stub_sec = stub_sec; | |
2327 | stub_entry->stub_offset = 0; | |
2328 | stub_entry->id_sec = link_sec; | |
2329 | return stub_entry; | |
2330 | } | |
2331 | ||
82bd7b59 AM |
2332 | /* Create sections for linker generated code. */ |
2333 | ||
b34976b6 | 2334 | static bfd_boolean |
82bd7b59 AM |
2335 | create_linkage_sections (dynobj, info) |
2336 | bfd *dynobj; | |
2337 | struct bfd_link_info *info; | |
2338 | { | |
2339 | struct ppc_link_hash_table *htab; | |
2340 | flagword flags; | |
2341 | ||
2342 | htab = ppc_hash_table (info); | |
2343 | ||
2344 | /* Create .sfpr for code to save and restore fp regs. */ | |
2345 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
2346 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
721956f4 | 2347 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
82bd7b59 AM |
2348 | if (htab->sfpr == NULL |
2349 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) | |
2350 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) | |
b34976b6 | 2351 | return FALSE; |
82bd7b59 | 2352 | |
721956f4 AM |
2353 | /* Create .glink for lazy dynamic linking support. */ |
2354 | htab->sglink = bfd_make_section_anyway (dynobj, ".glink"); | |
82bd7b59 AM |
2355 | if (htab->sglink == NULL |
2356 | || ! bfd_set_section_flags (dynobj, htab->sglink, flags) | |
2357 | || ! bfd_set_section_alignment (dynobj, htab->sglink, 2)) | |
b34976b6 | 2358 | return FALSE; |
82bd7b59 | 2359 | |
721956f4 AM |
2360 | /* Create .branch_lt for plt_branch stubs. */ |
2361 | flags = (SEC_ALLOC | SEC_LOAD | |
2362 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2363 | htab->sbrlt = bfd_make_section_anyway (dynobj, ".branch_lt"); | |
2364 | if (htab->sbrlt == NULL | |
2365 | || ! bfd_set_section_flags (dynobj, htab->sbrlt, flags) | |
2366 | || ! bfd_set_section_alignment (dynobj, htab->sbrlt, 3)) | |
b34976b6 | 2367 | return FALSE; |
721956f4 AM |
2368 | |
2369 | if (info->shared) | |
2370 | { | |
2371 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
2372 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
1e2f5b6e | 2373 | htab->srelbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
721956f4 AM |
2374 | if (!htab->srelbrlt |
2375 | || ! bfd_set_section_flags (dynobj, htab->srelbrlt, flags) | |
2376 | || ! bfd_set_section_alignment (dynobj, htab->srelbrlt, 3)) | |
b34976b6 | 2377 | return FALSE; |
721956f4 | 2378 | } |
b34976b6 | 2379 | return TRUE; |
82bd7b59 AM |
2380 | } |
2381 | ||
65f38f15 AM |
2382 | /* Create .got and .rela.got sections in DYNOBJ, and set up |
2383 | shortcuts to them in our hash table. */ | |
2384 | ||
b34976b6 | 2385 | static bfd_boolean |
65f38f15 AM |
2386 | create_got_section (dynobj, info) |
2387 | bfd *dynobj; | |
2388 | struct bfd_link_info *info; | |
2389 | { | |
2390 | struct ppc_link_hash_table *htab; | |
2391 | ||
2392 | if (! _bfd_elf_create_got_section (dynobj, info)) | |
b34976b6 | 2393 | return FALSE; |
65f38f15 AM |
2394 | |
2395 | htab = ppc_hash_table (info); | |
2396 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); | |
2397 | if (!htab->sgot) | |
2398 | abort (); | |
2399 | ||
2400 | htab->srelgot = bfd_make_section (dynobj, ".rela.got"); | |
2401 | if (!htab->srelgot | |
2402 | || ! bfd_set_section_flags (dynobj, htab->srelgot, | |
2403 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
2404 | | SEC_IN_MEMORY | SEC_LINKER_CREATED | |
2405 | | SEC_READONLY)) | |
2406 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3)) | |
b34976b6 AM |
2407 | return FALSE; |
2408 | return TRUE; | |
65f38f15 | 2409 | } |
5bd4f169 | 2410 | |
82bd7b59 | 2411 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 2412 | |
b34976b6 | 2413 | static bfd_boolean |
65f38f15 AM |
2414 | ppc64_elf_create_dynamic_sections (dynobj, info) |
2415 | bfd *dynobj; | |
5bd4f169 AM |
2416 | struct bfd_link_info *info; |
2417 | { | |
65f38f15 | 2418 | struct ppc_link_hash_table *htab; |
5bd4f169 | 2419 | |
65f38f15 AM |
2420 | htab = ppc_hash_table (info); |
2421 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
b34976b6 | 2422 | return FALSE; |
5bd4f169 | 2423 | |
65f38f15 | 2424 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 2425 | return FALSE; |
65f38f15 AM |
2426 | |
2427 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
2428 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
2429 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
2430 | if (!info->shared) | |
2431 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
2432 | ||
2433 | if (!htab->splt || !htab->srelplt || !htab->sdynbss | |
2434 | || (!info->shared && !htab->srelbss)) | |
2435 | abort (); | |
2436 | ||
b34976b6 | 2437 | return TRUE; |
5bd4f169 AM |
2438 | } |
2439 | ||
65f38f15 AM |
2440 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
2441 | ||
2442 | static void | |
b48fa14c AM |
2443 | ppc64_elf_copy_indirect_symbol (bed, dir, ind) |
2444 | struct elf_backend_data *bed; | |
65f38f15 AM |
2445 | struct elf_link_hash_entry *dir, *ind; |
2446 | { | |
2447 | struct ppc_link_hash_entry *edir, *eind; | |
2448 | ||
2449 | edir = (struct ppc_link_hash_entry *) dir; | |
2450 | eind = (struct ppc_link_hash_entry *) ind; | |
2451 | ||
bbd7ec4a | 2452 | if (eind->dyn_relocs != NULL) |
65f38f15 | 2453 | { |
bbd7ec4a AM |
2454 | if (edir->dyn_relocs != NULL) |
2455 | { | |
2456 | struct ppc_dyn_relocs **pp; | |
2457 | struct ppc_dyn_relocs *p; | |
2458 | ||
1e370bd2 | 2459 | if (ind->root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
2460 | abort (); |
2461 | ||
2462 | /* Add reloc counts against the weak sym to the strong sym | |
2463 | list. Merge any entries against the same section. */ | |
2464 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
2465 | { | |
2466 | struct ppc_dyn_relocs *q; | |
2467 | ||
2468 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
2469 | if (q->sec == p->sec) | |
2470 | { | |
2471 | q->pc_count += p->pc_count; | |
2472 | q->count += p->count; | |
2473 | *pp = p->next; | |
2474 | break; | |
2475 | } | |
2476 | if (q == NULL) | |
2477 | pp = &p->next; | |
2478 | } | |
2479 | *pp = edir->dyn_relocs; | |
2480 | } | |
2481 | ||
65f38f15 AM |
2482 | edir->dyn_relocs = eind->dyn_relocs; |
2483 | eind->dyn_relocs = NULL; | |
2484 | } | |
65f38f15 | 2485 | |
d1329ca3 AM |
2486 | edir->is_func |= eind->is_func; |
2487 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
1e2f5b6e | 2488 | edir->is_entry |= eind->is_entry; |
e86ce104 | 2489 | |
b48fa14c | 2490 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); |
65f38f15 AM |
2491 | } |
2492 | ||
1e2f5b6e AM |
2493 | /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and |
2494 | symbols undefined on the command-line. */ | |
2495 | ||
b34976b6 | 2496 | bfd_boolean |
1e2f5b6e AM |
2497 | ppc64_elf_mark_entry_syms (info) |
2498 | struct bfd_link_info *info; | |
2499 | { | |
2500 | struct ppc_link_hash_table *htab; | |
2501 | struct bfd_sym_chain *sym; | |
2502 | ||
2503 | htab = ppc_hash_table (info); | |
2504 | for (sym = info->gc_sym_list; sym; sym = sym->next) | |
2505 | { | |
2506 | struct elf_link_hash_entry *h; | |
2507 | ||
b34976b6 | 2508 | h = elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); |
1e2f5b6e AM |
2509 | if (h != NULL) |
2510 | ((struct ppc_link_hash_entry *) h)->is_entry = 1; | |
2511 | } | |
b34976b6 | 2512 | return TRUE; |
1e2f5b6e AM |
2513 | } |
2514 | ||
5bd4f169 | 2515 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 2516 | calculate needed space in the global offset table, procedure |
5d1634d7 | 2517 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 2518 | |
b34976b6 | 2519 | static bfd_boolean |
5bd4f169 AM |
2520 | ppc64_elf_check_relocs (abfd, info, sec, relocs) |
2521 | bfd *abfd; | |
2522 | struct bfd_link_info *info; | |
2523 | asection *sec; | |
2524 | const Elf_Internal_Rela *relocs; | |
2525 | { | |
65f38f15 | 2526 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
2527 | Elf_Internal_Shdr *symtab_hdr; |
2528 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
2529 | const Elf_Internal_Rela *rel; | |
2530 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 2531 | asection *sreloc; |
1e2f5b6e | 2532 | asection **opd_sym_map; |
5bd4f169 AM |
2533 | |
2534 | if (info->relocateable) | |
b34976b6 | 2535 | return TRUE; |
5bd4f169 | 2536 | |
65f38f15 | 2537 | htab = ppc_hash_table (info); |
5bd4f169 | 2538 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
2539 | |
2540 | sym_hashes = elf_sym_hashes (abfd); | |
2541 | sym_hashes_end = (sym_hashes | |
1e2f5b6e AM |
2542 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
2543 | - symtab_hdr->sh_info); | |
5bd4f169 AM |
2544 | |
2545 | sreloc = NULL; | |
1e2f5b6e AM |
2546 | opd_sym_map = NULL; |
2547 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
2548 | { | |
2549 | /* Garbage collection needs some extra help with .opd sections. | |
2550 | We don't want to necessarily keep everything referenced by | |
2551 | relocs in .opd, as that would keep all functions. Instead, | |
2552 | if we reference an .opd symbol (a function descriptor), we | |
2553 | want to keep the function code symbol's section. This is | |
2554 | easy for global symbols, but for local syms we need to keep | |
2555 | information about the associated function section. Later, if | |
2556 | edit_opd deletes entries, we'll use this array to adjust | |
2557 | local syms in .opd. */ | |
2558 | union opd_info { | |
2559 | asection *func_section; | |
2560 | long entry_adjust; | |
2561 | }; | |
2562 | bfd_size_type amt; | |
2563 | ||
2564 | amt = sec->_raw_size * sizeof (union opd_info) / 24; | |
2565 | opd_sym_map = (asection **) bfd_zalloc (abfd, amt); | |
2566 | if (opd_sym_map == NULL) | |
b34976b6 | 2567 | return FALSE; |
1e2f5b6e AM |
2568 | elf_section_data (sec)->tdata = opd_sym_map; |
2569 | } | |
5bd4f169 | 2570 | |
82bd7b59 AM |
2571 | if (htab->elf.dynobj == NULL) |
2572 | htab->elf.dynobj = abfd; | |
2573 | if (htab->sfpr == NULL | |
2574 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 2575 | return FALSE; |
82bd7b59 | 2576 | |
5bd4f169 AM |
2577 | rel_end = relocs + sec->reloc_count; |
2578 | for (rel = relocs; rel < rel_end; rel++) | |
2579 | { | |
2580 | unsigned long r_symndx; | |
2581 | struct elf_link_hash_entry *h; | |
a33d1f77 | 2582 | enum elf_ppc_reloc_type r_type; |
5bd4f169 AM |
2583 | |
2584 | r_symndx = ELF64_R_SYM (rel->r_info); | |
2585 | if (r_symndx < symtab_hdr->sh_info) | |
2586 | h = NULL; | |
2587 | else | |
2588 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2589 | ||
a33d1f77 AM |
2590 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); |
2591 | switch (r_type) | |
5bd4f169 AM |
2592 | { |
2593 | /* GOT16 relocations */ | |
2594 | case R_PPC64_GOT16: | |
5bd4f169 | 2595 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
2596 | case R_PPC64_GOT16_HA: |
2597 | case R_PPC64_GOT16_HI: | |
2598 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 2599 | case R_PPC64_GOT16_LO_DS: |
5bd4f169 | 2600 | |
65f38f15 | 2601 | /* This symbol requires a global offset table entry. */ |
82bd7b59 AM |
2602 | if (htab->sgot == NULL |
2603 | && !create_got_section (htab->elf.dynobj, info)) | |
b34976b6 | 2604 | return FALSE; |
5bd4f169 AM |
2605 | |
2606 | if (h != NULL) | |
2607 | { | |
65f38f15 | 2608 | h->got.refcount += 1; |
5bd4f169 AM |
2609 | } |
2610 | else | |
2611 | { | |
65f38f15 AM |
2612 | bfd_signed_vma *local_got_refcounts; |
2613 | ||
5bd4f169 | 2614 | /* This is a global offset table entry for a local symbol. */ |
65f38f15 | 2615 | local_got_refcounts = elf_local_got_refcounts (abfd); |
5bd4f169 AM |
2616 | if (local_got_refcounts == NULL) |
2617 | { | |
dc810e39 | 2618 | bfd_size_type size; |
5bd4f169 | 2619 | |
dc810e39 AM |
2620 | size = symtab_hdr->sh_info; |
2621 | size *= sizeof (bfd_signed_vma); | |
2622 | local_got_refcounts = ((bfd_signed_vma *) | |
65f38f15 | 2623 | bfd_zalloc (abfd, size)); |
5bd4f169 | 2624 | if (local_got_refcounts == NULL) |
b34976b6 | 2625 | return FALSE; |
5bd4f169 | 2626 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
5bd4f169 | 2627 | } |
65f38f15 | 2628 | local_got_refcounts[r_symndx] += 1; |
5bd4f169 AM |
2629 | } |
2630 | break; | |
2631 | ||
5bd4f169 | 2632 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
2633 | case R_PPC64_PLT16_HI: |
2634 | case R_PPC64_PLT16_LO: | |
2635 | case R_PPC64_PLT32: | |
2636 | case R_PPC64_PLT64: | |
5bd4f169 | 2637 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
2638 | actually build the entry in adjust_dynamic_symbol, |
2639 | because this might be a case of linking PIC code without | |
2640 | linking in any dynamic objects, in which case we don't | |
2641 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
2642 | if (h == NULL) |
2643 | { | |
2644 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 2645 | table entry for a local symbol. */ |
5bd4f169 | 2646 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 2647 | return FALSE; |
5bd4f169 AM |
2648 | } |
2649 | ||
65f38f15 AM |
2650 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
2651 | h->plt.refcount += 1; | |
e86ce104 | 2652 | ((struct ppc_link_hash_entry *) h)->is_func = 1; |
5bd4f169 AM |
2653 | break; |
2654 | ||
2655 | /* The following relocations don't need to propagate the | |
2656 | relocation if linking a shared object since they are | |
2657 | section relative. */ | |
2658 | case R_PPC64_SECTOFF: | |
2659 | case R_PPC64_SECTOFF_LO: | |
2660 | case R_PPC64_SECTOFF_HI: | |
2661 | case R_PPC64_SECTOFF_HA: | |
2662 | case R_PPC64_SECTOFF_DS: | |
2663 | case R_PPC64_SECTOFF_LO_DS: | |
2664 | case R_PPC64_TOC16: | |
2665 | case R_PPC64_TOC16_LO: | |
2666 | case R_PPC64_TOC16_HI: | |
2667 | case R_PPC64_TOC16_HA: | |
2668 | case R_PPC64_TOC16_DS: | |
2669 | case R_PPC64_TOC16_LO_DS: | |
2670 | break; | |
2671 | ||
2672 | /* This relocation describes the C++ object vtable hierarchy. | |
2673 | Reconstruct it for later use during GC. */ | |
2674 | case R_PPC64_GNU_VTINHERIT: | |
2675 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
b34976b6 | 2676 | return FALSE; |
5bd4f169 AM |
2677 | break; |
2678 | ||
2679 | /* This relocation describes which C++ vtable entries are actually | |
2680 | used. Record for later use during GC. */ | |
2681 | case R_PPC64_GNU_VTENTRY: | |
2682 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 2683 | return FALSE; |
5bd4f169 AM |
2684 | break; |
2685 | ||
721956f4 AM |
2686 | case R_PPC64_REL14: |
2687 | case R_PPC64_REL14_BRTAKEN: | |
2688 | case R_PPC64_REL14_BRNTAKEN: | |
2689 | htab->has_14bit_branch = 1; | |
2690 | /* Fall through. */ | |
2691 | ||
5d1634d7 | 2692 | case R_PPC64_REL24: |
e86ce104 AM |
2693 | if (h != NULL |
2694 | && h->root.root.string[0] == '.' | |
2695 | && h->root.root.string[1] != 0) | |
5d1634d7 AM |
2696 | { |
2697 | /* We may need a .plt entry if the function this reloc | |
2698 | refers to is in a shared lib. */ | |
2699 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
2700 | h->plt.refcount += 1; | |
e86ce104 | 2701 | ((struct ppc_link_hash_entry *) h)->is_func = 1; |
5d1634d7 AM |
2702 | } |
2703 | break; | |
2704 | ||
e86ce104 | 2705 | case R_PPC64_ADDR64: |
1e2f5b6e | 2706 | if (opd_sym_map != NULL |
e86ce104 AM |
2707 | && h != NULL |
2708 | && h->root.root.string[0] == '.' | |
2709 | && h->root.root.string[1] != 0) | |
2710 | { | |
2711 | struct elf_link_hash_entry *fdh; | |
2712 | ||
2713 | fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1, | |
b34976b6 | 2714 | FALSE, FALSE, FALSE); |
e86ce104 AM |
2715 | if (fdh != NULL) |
2716 | { | |
e86ce104 | 2717 | ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1; |
721956f4 | 2718 | ((struct ppc_link_hash_entry *) fdh)->oh = h; |
e86ce104 | 2719 | ((struct ppc_link_hash_entry *) h)->is_func = 1; |
721956f4 | 2720 | ((struct ppc_link_hash_entry *) h)->oh = fdh; |
e86ce104 AM |
2721 | } |
2722 | } | |
1e2f5b6e AM |
2723 | if (opd_sym_map != NULL |
2724 | && h == NULL | |
2725 | && rel + 1 < rel_end | |
2726 | && ((enum elf_ppc_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info) | |
2727 | == R_PPC64_TOC)) | |
2728 | { | |
2729 | asection *s; | |
2730 | ||
2731 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, | |
2732 | r_symndx); | |
2733 | if (s == NULL) | |
b34976b6 | 2734 | return FALSE; |
1e2f5b6e AM |
2735 | else if (s != sec) |
2736 | opd_sym_map[rel->r_offset / 24] = s; | |
2737 | } | |
e86ce104 AM |
2738 | /* Fall through. */ |
2739 | ||
5bd4f169 AM |
2740 | case R_PPC64_REL64: |
2741 | case R_PPC64_REL32: | |
65f38f15 AM |
2742 | case R_PPC64_ADDR14: |
2743 | case R_PPC64_ADDR14_BRNTAKEN: | |
2744 | case R_PPC64_ADDR14_BRTAKEN: | |
2745 | case R_PPC64_ADDR16: | |
2746 | case R_PPC64_ADDR16_DS: | |
2747 | case R_PPC64_ADDR16_HA: | |
2748 | case R_PPC64_ADDR16_HI: | |
2749 | case R_PPC64_ADDR16_HIGHER: | |
2750 | case R_PPC64_ADDR16_HIGHERA: | |
2751 | case R_PPC64_ADDR16_HIGHEST: | |
2752 | case R_PPC64_ADDR16_HIGHESTA: | |
2753 | case R_PPC64_ADDR16_LO: | |
2754 | case R_PPC64_ADDR16_LO_DS: | |
2755 | case R_PPC64_ADDR24: | |
2756 | case R_PPC64_ADDR30: | |
2757 | case R_PPC64_ADDR32: | |
65f38f15 AM |
2758 | case R_PPC64_UADDR16: |
2759 | case R_PPC64_UADDR32: | |
2760 | case R_PPC64_UADDR64: | |
5bd4f169 | 2761 | case R_PPC64_TOC: |
41bd81ab | 2762 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 2763 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 2764 | break; |
e86ce104 | 2765 | |
65f38f15 AM |
2766 | /* If we are creating a shared library, and this is a reloc |
2767 | against a global symbol, or a non PC relative reloc | |
2768 | against a local symbol, then we need to copy the reloc | |
2769 | into the shared library. However, if we are linking with | |
2770 | -Bsymbolic, we do not need to copy a reloc against a | |
2771 | global symbol which is defined in an object we are | |
2772 | including in the link (i.e., DEF_REGULAR is set). At | |
2773 | this point we have not seen all the input files, so it is | |
2774 | possible that DEF_REGULAR is not set now but will be set | |
2775 | later (it is never cleared). In case of a weak definition, | |
2776 | DEF_REGULAR may be cleared later by a strong definition in | |
2777 | a shared library. We account for that possibility below by | |
2778 | storing information in the relocs_copied field of the hash | |
2779 | table entry. A similar situation occurs when creating | |
2780 | shared libraries and symbol visibility changes render the | |
2781 | symbol local. | |
2782 | ||
2783 | If on the other hand, we are creating an executable, we | |
2784 | may need to keep relocations for symbols satisfied by a | |
2785 | dynamic library if we manage to avoid copy relocs for the | |
2786 | symbol. */ | |
2787 | if ((info->shared | |
2788 | && (sec->flags & SEC_ALLOC) != 0 | |
a33d1f77 | 2789 | && (IS_ABSOLUTE_RELOC (r_type) |
65f38f15 AM |
2790 | || (h != NULL |
2791 | && (! info->symbolic | |
2792 | || h->root.type == bfd_link_hash_defweak | |
2793 | || (h->elf_link_hash_flags | |
2794 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
2795 | || (!info->shared | |
2796 | && (sec->flags & SEC_ALLOC) != 0 | |
2797 | && h != NULL | |
2798 | && (h->root.type == bfd_link_hash_defweak | |
2799 | || (h->elf_link_hash_flags | |
2800 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 2801 | { |
ec338859 AM |
2802 | struct ppc_dyn_relocs *p; |
2803 | struct ppc_dyn_relocs **head; | |
2804 | ||
65f38f15 AM |
2805 | /* We must copy these reloc types into the output file. |
2806 | Create a reloc section in dynobj and make room for | |
2807 | this reloc. */ | |
5bd4f169 AM |
2808 | if (sreloc == NULL) |
2809 | { | |
2810 | const char *name; | |
65f38f15 | 2811 | bfd *dynobj; |
5bd4f169 AM |
2812 | |
2813 | name = (bfd_elf_string_from_elf_section | |
2814 | (abfd, | |
2815 | elf_elfheader (abfd)->e_shstrndx, | |
2816 | elf_section_data (sec)->rel_hdr.sh_name)); | |
2817 | if (name == NULL) | |
b34976b6 | 2818 | return FALSE; |
5bd4f169 | 2819 | |
65f38f15 AM |
2820 | if (strncmp (name, ".rela", 5) != 0 |
2821 | || strcmp (bfd_get_section_name (abfd, sec), | |
2822 | name + 5) != 0) | |
2823 | { | |
2824 | (*_bfd_error_handler) | |
2825 | (_("%s: bad relocation section name `%s\'"), | |
2826 | bfd_archive_filename (abfd), name); | |
5d1634d7 | 2827 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
2828 | } |
2829 | ||
65f38f15 | 2830 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
2831 | sreloc = bfd_get_section_by_name (dynobj, name); |
2832 | if (sreloc == NULL) | |
2833 | { | |
2834 | flagword flags; | |
2835 | ||
2836 | sreloc = bfd_make_section (dynobj, name); | |
2837 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
2838 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2839 | if ((sec->flags & SEC_ALLOC) != 0) | |
2840 | flags |= SEC_ALLOC | SEC_LOAD; | |
2841 | if (sreloc == NULL | |
2842 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 2843 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
b34976b6 | 2844 | return FALSE; |
5bd4f169 | 2845 | } |
65f38f15 | 2846 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
2847 | } |
2848 | ||
65f38f15 AM |
2849 | /* If this is a global symbol, we count the number of |
2850 | relocations we need for this symbol. */ | |
2851 | if (h != NULL) | |
2852 | { | |
ec338859 | 2853 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
2854 | } |
2855 | else | |
2856 | { | |
ec338859 AM |
2857 | /* Track dynamic relocs needed for local syms too. |
2858 | We really need local syms available to do this | |
2859 | easily. Oh well. */ | |
2860 | ||
2861 | asection *s; | |
2862 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
2863 | sec, r_symndx); | |
2864 | if (s == NULL) | |
b34976b6 | 2865 | return FALSE; |
ec338859 AM |
2866 | |
2867 | head = ((struct ppc_dyn_relocs **) | |
2868 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 2869 | } |
ec338859 AM |
2870 | |
2871 | p = *head; | |
2872 | if (p == NULL || p->sec != sec) | |
2873 | { | |
2874 | p = ((struct ppc_dyn_relocs *) | |
2875 | bfd_alloc (htab->elf.dynobj, | |
2876 | (bfd_size_type) sizeof *p)); | |
2877 | if (p == NULL) | |
b34976b6 | 2878 | return FALSE; |
ec338859 AM |
2879 | p->next = *head; |
2880 | *head = p; | |
2881 | p->sec = sec; | |
2882 | p->count = 0; | |
2883 | p->pc_count = 0; | |
2884 | } | |
2885 | ||
2886 | p->count += 1; | |
2887 | if (!IS_ABSOLUTE_RELOC (r_type)) | |
2888 | p->pc_count += 1; | |
65f38f15 | 2889 | } |
5bd4f169 | 2890 | break; |
65f38f15 AM |
2891 | |
2892 | default: | |
96e0dda4 | 2893 | break; |
5bd4f169 AM |
2894 | } |
2895 | } | |
2896 | ||
b34976b6 | 2897 | return TRUE; |
5bd4f169 AM |
2898 | } |
2899 | ||
2900 | /* Return the section that should be marked against GC for a given | |
2901 | relocation. */ | |
2902 | ||
2903 | static asection * | |
1e2f5b6e AM |
2904 | ppc64_elf_gc_mark_hook (sec, info, rel, h, sym) |
2905 | asection *sec; | |
5bd4f169 AM |
2906 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
2907 | Elf_Internal_Rela *rel; | |
2908 | struct elf_link_hash_entry *h; | |
2909 | Elf_Internal_Sym *sym; | |
2910 | { | |
1e2f5b6e AM |
2911 | asection *rsec = NULL; |
2912 | ||
5bd4f169 AM |
2913 | if (h != NULL) |
2914 | { | |
a33d1f77 | 2915 | enum elf_ppc_reloc_type r_type; |
1e2f5b6e | 2916 | struct ppc_link_hash_entry *fdh; |
a33d1f77 AM |
2917 | |
2918 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); | |
2919 | switch (r_type) | |
5bd4f169 AM |
2920 | { |
2921 | case R_PPC64_GNU_VTINHERIT: | |
2922 | case R_PPC64_GNU_VTENTRY: | |
2923 | break; | |
2924 | ||
2925 | default: | |
2926 | switch (h->root.type) | |
2927 | { | |
2928 | case bfd_link_hash_defined: | |
2929 | case bfd_link_hash_defweak: | |
1e2f5b6e AM |
2930 | fdh = (struct ppc_link_hash_entry *) h; |
2931 | ||
2932 | /* Function descriptor syms cause the associated | |
2933 | function code sym section to be marked. */ | |
2934 | if (fdh->is_func_descriptor) | |
2935 | rsec = fdh->oh->root.u.def.section; | |
2936 | ||
2937 | /* Function entry syms return NULL if they are in .opd | |
2938 | and are not ._start (or others undefined on the ld | |
2939 | command line). Thus we avoid marking all function | |
b34976b6 | 2940 | sections, as all functions are referenced in .opd. */ |
1e2f5b6e AM |
2941 | else if ((fdh->oh != NULL |
2942 | && ((struct ppc_link_hash_entry *) fdh->oh)->is_entry) | |
2943 | || elf_section_data (sec)->tdata == NULL) | |
2944 | rsec = h->root.u.def.section; | |
2945 | break; | |
5bd4f169 AM |
2946 | |
2947 | case bfd_link_hash_common: | |
1e2f5b6e AM |
2948 | rsec = h->root.u.c.p->section; |
2949 | break; | |
5bd4f169 AM |
2950 | |
2951 | default: | |
2952 | break; | |
2953 | } | |
2954 | } | |
2955 | } | |
2956 | else | |
2957 | { | |
1e2f5b6e AM |
2958 | asection **opd_sym_section; |
2959 | ||
2960 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
2961 | opd_sym_section = (asection **) elf_section_data (rsec)->tdata; | |
2962 | if (opd_sym_section != NULL) | |
2963 | rsec = opd_sym_section[sym->st_value / 24]; | |
2964 | else if (elf_section_data (sec)->tdata != NULL) | |
2965 | rsec = NULL; | |
5bd4f169 AM |
2966 | } |
2967 | ||
1e2f5b6e | 2968 | return rsec; |
5bd4f169 AM |
2969 | } |
2970 | ||
65f38f15 AM |
2971 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
2972 | section being removed. */ | |
5bd4f169 | 2973 | |
b34976b6 | 2974 | static bfd_boolean |
5bd4f169 AM |
2975 | ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs) |
2976 | bfd *abfd; | |
2977 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
2978 | asection *sec; | |
2979 | const Elf_Internal_Rela *relocs; | |
2980 | { | |
2981 | Elf_Internal_Shdr *symtab_hdr; | |
2982 | struct elf_link_hash_entry **sym_hashes; | |
2983 | bfd_signed_vma *local_got_refcounts; | |
2984 | const Elf_Internal_Rela *rel, *relend; | |
5bd4f169 | 2985 | |
ec338859 AM |
2986 | elf_section_data (sec)->local_dynrel = NULL; |
2987 | ||
5bd4f169 AM |
2988 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
2989 | sym_hashes = elf_sym_hashes (abfd); | |
2990 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
2991 | ||
2992 | relend = relocs + sec->reloc_count; | |
2993 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
2994 | { |
2995 | unsigned long r_symndx; | |
2996 | enum elf_ppc_reloc_type r_type; | |
2997 | struct elf_link_hash_entry *h; | |
5bd4f169 | 2998 | |
a33d1f77 AM |
2999 | r_symndx = ELF64_R_SYM (rel->r_info); |
3000 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); | |
3001 | switch (r_type) | |
3002 | { | |
3003 | case R_PPC64_GOT16: | |
3004 | case R_PPC64_GOT16_DS: | |
3005 | case R_PPC64_GOT16_HA: | |
3006 | case R_PPC64_GOT16_HI: | |
3007 | case R_PPC64_GOT16_LO: | |
3008 | case R_PPC64_GOT16_LO_DS: | |
3009 | if (r_symndx >= symtab_hdr->sh_info) | |
3010 | { | |
3011 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3012 | if (h->got.refcount > 0) | |
3013 | h->got.refcount--; | |
3014 | } | |
3015 | else | |
3016 | { | |
3017 | if (local_got_refcounts[r_symndx] > 0) | |
3018 | local_got_refcounts[r_symndx]--; | |
3019 | } | |
3020 | break; | |
65f38f15 | 3021 | |
a33d1f77 AM |
3022 | case R_PPC64_PLT16_HA: |
3023 | case R_PPC64_PLT16_HI: | |
3024 | case R_PPC64_PLT16_LO: | |
3025 | case R_PPC64_PLT32: | |
3026 | case R_PPC64_PLT64: | |
3027 | if (r_symndx >= symtab_hdr->sh_info) | |
3028 | { | |
3029 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3030 | if (h->plt.refcount > 0) | |
3031 | h->plt.refcount--; | |
3032 | } | |
3033 | break; | |
65f38f15 | 3034 | |
721956f4 AM |
3035 | case R_PPC64_REL14: |
3036 | case R_PPC64_REL14_BRNTAKEN: | |
3037 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
3038 | case R_PPC64_REL24: |
3039 | if (r_symndx >= symtab_hdr->sh_info) | |
3040 | { | |
3041 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3042 | if (h->plt.refcount > 0) | |
3043 | h->plt.refcount--; | |
3044 | } | |
e86ce104 | 3045 | break; |
5d1634d7 | 3046 | |
a33d1f77 AM |
3047 | case R_PPC64_REL32: |
3048 | case R_PPC64_REL64: | |
3049 | if (r_symndx >= symtab_hdr->sh_info) | |
3050 | { | |
3051 | struct ppc_link_hash_entry *eh; | |
3052 | struct ppc_dyn_relocs **pp; | |
3053 | struct ppc_dyn_relocs *p; | |
65f38f15 | 3054 | |
a33d1f77 AM |
3055 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
3056 | eh = (struct ppc_link_hash_entry *) h; | |
65f38f15 | 3057 | |
a33d1f77 AM |
3058 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
3059 | if (p->sec == sec) | |
3060 | { | |
3061 | p->pc_count -= 1; | |
3062 | p->count -= 1; | |
3063 | if (p->count == 0) | |
3064 | *pp = p->next; | |
3065 | break; | |
3066 | } | |
3067 | } | |
3068 | break; | |
65f38f15 | 3069 | |
a33d1f77 AM |
3070 | case R_PPC64_ADDR14: |
3071 | case R_PPC64_ADDR14_BRNTAKEN: | |
3072 | case R_PPC64_ADDR14_BRTAKEN: | |
3073 | case R_PPC64_ADDR16: | |
3074 | case R_PPC64_ADDR16_DS: | |
3075 | case R_PPC64_ADDR16_HA: | |
3076 | case R_PPC64_ADDR16_HI: | |
3077 | case R_PPC64_ADDR16_HIGHER: | |
3078 | case R_PPC64_ADDR16_HIGHERA: | |
3079 | case R_PPC64_ADDR16_HIGHEST: | |
3080 | case R_PPC64_ADDR16_HIGHESTA: | |
3081 | case R_PPC64_ADDR16_LO: | |
3082 | case R_PPC64_ADDR16_LO_DS: | |
3083 | case R_PPC64_ADDR24: | |
3084 | case R_PPC64_ADDR30: | |
3085 | case R_PPC64_ADDR32: | |
3086 | case R_PPC64_ADDR64: | |
3087 | case R_PPC64_UADDR16: | |
3088 | case R_PPC64_UADDR32: | |
3089 | case R_PPC64_UADDR64: | |
3090 | case R_PPC64_TOC: | |
3091 | if (r_symndx >= symtab_hdr->sh_info) | |
3092 | { | |
3093 | struct ppc_link_hash_entry *eh; | |
3094 | struct ppc_dyn_relocs **pp; | |
3095 | struct ppc_dyn_relocs *p; | |
65f38f15 | 3096 | |
a33d1f77 AM |
3097 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
3098 | eh = (struct ppc_link_hash_entry *) h; | |
3099 | ||
3100 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
3101 | if (p->sec == sec) | |
3102 | { | |
3103 | p->count -= 1; | |
3104 | if (p->count == 0) | |
3105 | *pp = p->next; | |
3106 | break; | |
3107 | } | |
3108 | } | |
3109 | break; | |
5bd4f169 | 3110 | |
a33d1f77 AM |
3111 | default: |
3112 | break; | |
3113 | } | |
3114 | } | |
b34976b6 | 3115 | return TRUE; |
5bd4f169 AM |
3116 | } |
3117 | ||
e86ce104 AM |
3118 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
3119 | information on function code symbol entries to their corresponding | |
3120 | function descriptor symbol entries. */ | |
b34976b6 | 3121 | static bfd_boolean |
e86ce104 | 3122 | func_desc_adjust (h, inf) |
5bd4f169 | 3123 | struct elf_link_hash_entry *h; |
e86ce104 | 3124 | PTR inf; |
5bd4f169 | 3125 | { |
e86ce104 | 3126 | struct bfd_link_info *info; |
65f38f15 | 3127 | struct ppc_link_hash_table *htab; |
5bd4f169 | 3128 | |
e92d460e | 3129 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 3130 | return TRUE; |
e86ce104 | 3131 | |
e92d460e AM |
3132 | if (h->root.type == bfd_link_hash_warning) |
3133 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3134 | ||
e86ce104 | 3135 | info = (struct bfd_link_info *) inf; |
65f38f15 | 3136 | htab = ppc_hash_table (info); |
5bd4f169 | 3137 | |
e86ce104 AM |
3138 | /* If this is a function code symbol, transfer dynamic linking |
3139 | information to the function descriptor symbol. */ | |
3140 | if (!((struct ppc_link_hash_entry *) h)->is_func) | |
b34976b6 | 3141 | return TRUE; |
e86ce104 | 3142 | |
805fc799 AM |
3143 | if (h->root.type == bfd_link_hash_undefweak |
3144 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR)) | |
b34976b6 | 3145 | htab->have_undefweak = TRUE; |
805fc799 | 3146 | |
e86ce104 AM |
3147 | if (h->plt.refcount > 0 |
3148 | && h->root.root.string[0] == '.' | |
3149 | && h->root.root.string[1] != '\0') | |
5bd4f169 | 3150 | { |
721956f4 | 3151 | struct elf_link_hash_entry *fdh = ((struct ppc_link_hash_entry *) h)->oh; |
b34976b6 | 3152 | bfd_boolean force_local; |
5bd4f169 | 3153 | |
648cca2c AM |
3154 | /* Find the corresponding function descriptor symbol. Create it |
3155 | as undefined if necessary. */ | |
5bd4f169 | 3156 | |
721956f4 AM |
3157 | if (fdh == NULL) |
3158 | fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1, | |
b34976b6 | 3159 | FALSE, FALSE, TRUE); |
5bd4f169 | 3160 | |
d926e03d AM |
3161 | if (fdh == NULL |
3162 | && info->shared | |
3163 | && (h->root.type == bfd_link_hash_undefined | |
3164 | || h->root.type == bfd_link_hash_undefweak)) | |
648cca2c AM |
3165 | { |
3166 | bfd *abfd; | |
3167 | asymbol *newsym; | |
14a793b2 | 3168 | struct bfd_link_hash_entry *bh; |
648cca2c | 3169 | |
d926e03d | 3170 | abfd = h->root.u.undef.abfd; |
648cca2c AM |
3171 | newsym = bfd_make_empty_symbol (abfd); |
3172 | newsym->name = h->root.root.string + 1; | |
3173 | newsym->section = bfd_und_section_ptr; | |
3174 | newsym->value = 0; | |
3175 | newsym->flags = BSF_OBJECT; | |
3176 | if (h->root.type == bfd_link_hash_undefweak) | |
3177 | newsym->flags |= BSF_WEAK; | |
3178 | ||
14a793b2 | 3179 | bh = &fdh->root; |
648cca2c AM |
3180 | if ( !(_bfd_generic_link_add_one_symbol |
3181 | (info, abfd, newsym->name, newsym->flags, | |
b34976b6 | 3182 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) |
648cca2c | 3183 | { |
b34976b6 | 3184 | return FALSE; |
648cca2c | 3185 | } |
14a793b2 | 3186 | fdh = (struct elf_link_hash_entry *) bh; |
d926e03d | 3187 | fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; |
648cca2c AM |
3188 | } |
3189 | ||
e86ce104 AM |
3190 | if (fdh != NULL |
3191 | && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 | |
3192 | && (info->shared | |
3193 | || (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
3194 | || (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)) | |
3195 | { | |
3196 | if (fdh->dynindx == -1) | |
3197 | if (! bfd_elf64_link_record_dynamic_symbol (info, fdh)) | |
b34976b6 | 3198 | return FALSE; |
e86ce104 AM |
3199 | fdh->elf_link_hash_flags |= (h->elf_link_hash_flags |
3200 | & (ELF_LINK_HASH_REF_REGULAR | |
3201 | | ELF_LINK_HASH_REF_DYNAMIC | |
3202 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
3203 | | ELF_LINK_NON_GOT_REF)); | |
e1fa50e7 AM |
3204 | if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
3205 | { | |
3206 | fdh->plt.refcount = h->plt.refcount; | |
3207 | fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3208 | } | |
e86ce104 | 3209 | ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1; |
721956f4 | 3210 | ((struct ppc_link_hash_entry *) fdh)->oh = h; |
721956f4 | 3211 | ((struct ppc_link_hash_entry *) h)->oh = fdh; |
e86ce104 AM |
3212 | } |
3213 | ||
3214 | /* Now that the info is on the function descriptor, clear the | |
3215 | function code sym info. Any function code syms for which we | |
3216 | don't have a definition in a regular file, we force local. | |
3217 | This prevents a shared library from exporting syms that have | |
3218 | been imported from another library. Function code syms that | |
3219 | are really in the library we must leave global to prevent the | |
e1fa50e7 | 3220 | linker dragging in a definition from a static library. */ |
ea1e4b0d AM |
3221 | force_local = (info->shared |
3222 | && ((h->elf_link_hash_flags | |
3223 | & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
3224 | || fdh == NULL | |
3225 | || (fdh->elf_link_hash_flags | |
3226 | & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
3227 | || (fdh->elf_link_hash_flags | |
3228 | & ELF_LINK_FORCED_LOCAL) != 0)); | |
e86ce104 AM |
3229 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
3230 | } | |
3231 | ||
b34976b6 | 3232 | return TRUE; |
e86ce104 | 3233 | } |
40b8271b | 3234 | |
82bd7b59 AM |
3235 | #define MIN_SAVE_FPR 14 |
3236 | #define MAX_SAVE_FPR 31 | |
3237 | ||
e86ce104 | 3238 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
3239 | this hook to a) provide some gcc support functions, and b) transfer |
3240 | dynamic linking information gathered so far on function code symbol | |
3241 | entries, to their corresponding function descriptor symbol entries. */ | |
b34976b6 | 3242 | static bfd_boolean |
e86ce104 AM |
3243 | ppc64_elf_func_desc_adjust (obfd, info) |
3244 | bfd *obfd ATTRIBUTE_UNUSED; | |
3245 | struct bfd_link_info *info; | |
3246 | { | |
3247 | struct ppc_link_hash_table *htab; | |
82bd7b59 AM |
3248 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
3249 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; | |
3250 | unsigned int i; | |
3251 | struct elf_link_hash_entry *h; | |
721956f4 | 3252 | bfd_byte *p; |
82bd7b59 | 3253 | char sym[10]; |
e86ce104 AM |
3254 | |
3255 | htab = ppc_hash_table (info); | |
82bd7b59 AM |
3256 | |
3257 | if (htab->sfpr == NULL) | |
3258 | /* We don't have any relocs. */ | |
b34976b6 | 3259 | return TRUE; |
82bd7b59 AM |
3260 | |
3261 | /* First provide any missing ._savef* and ._restf* functions. */ | |
3262 | memcpy (sym, "._savef14", 10); | |
3263 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
3264 | { | |
3265 | sym[7] = i / 10 + '0'; | |
3266 | sym[8] = i % 10 + '0'; | |
b34976b6 | 3267 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 AM |
3268 | if (h != NULL |
3269 | && h->root.type == bfd_link_hash_undefined) | |
3270 | { | |
3271 | if (lowest_savef > i) | |
3272 | lowest_savef = i; | |
3273 | h->root.type = bfd_link_hash_defined; | |
3274 | h->root.u.def.section = htab->sfpr; | |
3275 | h->root.u.def.value = (i - lowest_savef) * 4; | |
3276 | h->type = STT_FUNC; | |
3277 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
3278 | _bfd_elf_link_hash_hide_symbol (info, h, info->shared); | |
3279 | } | |
3280 | } | |
3281 | ||
3282 | memcpy (sym, "._restf14", 10); | |
3283 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
3284 | { | |
3285 | sym[7] = i / 10 + '0'; | |
3286 | sym[8] = i % 10 + '0'; | |
b34976b6 | 3287 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 AM |
3288 | if (h != NULL |
3289 | && h->root.type == bfd_link_hash_undefined) | |
3290 | { | |
3291 | if (lowest_restf > i) | |
3292 | lowest_restf = i; | |
3293 | h->root.type = bfd_link_hash_defined; | |
3294 | h->root.u.def.section = htab->sfpr; | |
3295 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 | |
3296 | + (i - lowest_restf) * 4); | |
3297 | h->type = STT_FUNC; | |
3298 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
3299 | _bfd_elf_link_hash_hide_symbol (info, h, info->shared); | |
3300 | } | |
3301 | } | |
3302 | ||
805fc799 AM |
3303 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info); |
3304 | ||
82bd7b59 AM |
3305 | htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
3306 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); | |
3307 | ||
3308 | if (htab->sfpr->_raw_size == 0) | |
805fc799 AM |
3309 | { |
3310 | if (!htab->have_undefweak) | |
3311 | { | |
3312 | _bfd_strip_section_from_output (info, htab->sfpr); | |
b34976b6 | 3313 | return TRUE; |
805fc799 AM |
3314 | } |
3315 | ||
3316 | htab->sfpr->_raw_size = 4; | |
3317 | } | |
82bd7b59 | 3318 | |
721956f4 AM |
3319 | p = (bfd_byte *) bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size); |
3320 | if (p == NULL) | |
b34976b6 | 3321 | return FALSE; |
721956f4 AM |
3322 | htab->sfpr->contents = p; |
3323 | ||
3324 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) | |
3325 | { | |
3326 | unsigned int fpr = i << 21; | |
3327 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
3328 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); | |
3329 | p += 4; | |
3330 | } | |
3331 | if (lowest_savef <= MAX_SAVE_FPR) | |
3332 | { | |
82bd7b59 AM |
3333 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
3334 | p += 4; | |
721956f4 | 3335 | } |
82bd7b59 | 3336 | |
721956f4 AM |
3337 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
3338 | { | |
3339 | unsigned int fpr = i << 21; | |
3340 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
3341 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); | |
82bd7b59 AM |
3342 | p += 4; |
3343 | } | |
721956f4 AM |
3344 | if (lowest_restf <= MAX_SAVE_FPR |
3345 | || htab->sfpr->_raw_size == 4) | |
3346 | { | |
3347 | bfd_put_32 (htab->elf.dynobj, BLR, p); | |
3348 | } | |
82bd7b59 | 3349 | |
b34976b6 | 3350 | return TRUE; |
e86ce104 AM |
3351 | } |
3352 | ||
3353 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
3354 | regular object. The current definition is in some section of the | |
3355 | dynamic object, but we're not including those sections. We have to | |
3356 | change the definition to something the rest of the link can | |
3357 | understand. */ | |
3358 | ||
b34976b6 | 3359 | static bfd_boolean |
e86ce104 AM |
3360 | ppc64_elf_adjust_dynamic_symbol (info, h) |
3361 | struct bfd_link_info *info; | |
3362 | struct elf_link_hash_entry *h; | |
3363 | { | |
3364 | struct ppc_link_hash_table *htab; | |
3365 | struct ppc_link_hash_entry * eh; | |
3366 | struct ppc_dyn_relocs *p; | |
3367 | asection *s; | |
3368 | unsigned int power_of_two; | |
3369 | ||
3370 | htab = ppc_hash_table (info); | |
3371 | ||
3372 | /* Deal with function syms. */ | |
3373 | if (h->type == STT_FUNC | |
3374 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
3375 | { | |
3376 | /* Clear procedure linkage table information for any symbol that | |
3377 | won't need a .plt entry. */ | |
3378 | if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor | |
3379 | || h->plt.refcount <= 0 | |
3380 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 | |
3381 | || (! info->shared | |
3382 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 | |
3383 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)) | |
40b8271b | 3384 | { |
40b8271b AM |
3385 | h->plt.offset = (bfd_vma) -1; |
3386 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
40b8271b | 3387 | } |
b34976b6 | 3388 | return TRUE; |
5bd4f169 | 3389 | } |
bbd7ec4a AM |
3390 | else |
3391 | h->plt.offset = (bfd_vma) -1; | |
5bd4f169 AM |
3392 | |
3393 | /* If this is a weak symbol, and there is a real definition, the | |
3394 | processor independent code will have arranged for us to see the | |
3395 | real definition first, and we can just use the same value. */ | |
3396 | if (h->weakdef != NULL) | |
3397 | { | |
3398 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
3399 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
3400 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
3401 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
b34976b6 | 3402 | return TRUE; |
5bd4f169 AM |
3403 | } |
3404 | ||
3405 | /* This is a reference to a symbol defined by a dynamic object which | |
3406 | is not a function. */ | |
3407 | ||
3408 | /* If we are creating a shared library, we must presume that the | |
3409 | only references to the symbol are via the global offset table. | |
3410 | For such cases we need not do anything here; the relocations will | |
3411 | be handled correctly by relocate_section. */ | |
3412 | if (info->shared) | |
b34976b6 | 3413 | return TRUE; |
5bd4f169 | 3414 | |
65f38f15 AM |
3415 | /* If there are no references to this symbol that do not use the |
3416 | GOT, we don't need to generate a copy reloc. */ | |
3417 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 3418 | return TRUE; |
65f38f15 AM |
3419 | |
3420 | eh = (struct ppc_link_hash_entry *) h; | |
3421 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
3422 | { | |
3423 | s = p->sec->output_section; | |
3424 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
3425 | break; | |
3426 | } | |
3427 | ||
3428 | /* If we didn't find any dynamic relocs in read-only sections, then | |
5d1634d7 | 3429 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
65f38f15 AM |
3430 | if (p == NULL) |
3431 | { | |
3432 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
b34976b6 | 3433 | return TRUE; |
65f38f15 AM |
3434 | } |
3435 | ||
5bd4f169 AM |
3436 | /* We must allocate the symbol in our .dynbss section, which will |
3437 | become part of the .bss section of the executable. There will be | |
3438 | an entry for this symbol in the .dynsym section. The dynamic | |
3439 | object will contain position independent code, so all references | |
3440 | from the dynamic object to this symbol will go through the global | |
3441 | offset table. The dynamic linker will use the .dynsym entry to | |
3442 | determine the address it must put in the global offset table, so | |
3443 | both the dynamic object and the regular object will refer to the | |
3444 | same memory location for the variable. */ | |
5bd4f169 AM |
3445 | |
3446 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
3447 | copy the initial value out of the dynamic object and into the | |
3448 | runtime process image. We need to remember the offset into the | |
3449 | .rela.bss section we are going to use. */ | |
3450 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
3451 | { | |
65f38f15 | 3452 | htab->srelbss->_raw_size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
3453 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
3454 | } | |
3455 | ||
3456 | /* We need to figure out the alignment required for this symbol. I | |
3457 | have no idea how ELF linkers handle this. */ | |
3458 | power_of_two = bfd_log2 (h->size); | |
3459 | if (power_of_two > 4) | |
3460 | power_of_two = 4; | |
3461 | ||
3462 | /* Apply the required alignment. */ | |
65f38f15 AM |
3463 | s = htab->sdynbss; |
3464 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); | |
3465 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
5bd4f169 | 3466 | { |
65f38f15 | 3467 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 3468 | return FALSE; |
5bd4f169 AM |
3469 | } |
3470 | ||
3471 | /* Define the symbol as being at this point in the section. */ | |
3472 | h->root.u.def.section = s; | |
3473 | h->root.u.def.value = s->_raw_size; | |
3474 | ||
3475 | /* Increment the section size to make room for the symbol. */ | |
3476 | s->_raw_size += h->size; | |
3477 | ||
b34976b6 | 3478 | return TRUE; |
5bd4f169 AM |
3479 | } |
3480 | ||
e86ce104 AM |
3481 | /* If given a function descriptor symbol, hide both the function code |
3482 | sym and the descriptor. */ | |
3483 | static void | |
3484 | ppc64_elf_hide_symbol (info, h, force_local) | |
3485 | struct bfd_link_info *info; | |
3486 | struct elf_link_hash_entry *h; | |
b34976b6 | 3487 | bfd_boolean force_local; |
e86ce104 AM |
3488 | { |
3489 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); | |
3490 | ||
3491 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) | |
3492 | { | |
721956f4 | 3493 | struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh; |
e86ce104 | 3494 | |
721956f4 | 3495 | if (fh == NULL) |
d1329ca3 AM |
3496 | { |
3497 | const char *p, *q; | |
3498 | struct ppc_link_hash_table *htab; | |
3499 | char save; | |
3500 | ||
3501 | /* We aren't supposed to use alloca in BFD because on | |
3502 | systems which do not have alloca the version in libiberty | |
3503 | calls xmalloc, which might cause the program to crash | |
3504 | when it runs out of memory. This function doesn't have a | |
3505 | return status, so there's no way to gracefully return an | |
3506 | error. So cheat. We know that string[-1] can be safely | |
3507 | dereferenced; It's either a string in an ELF string | |
3508 | table, or allocated in an objalloc structure. */ | |
3509 | ||
3510 | p = h->root.root.string - 1; | |
3511 | save = *p; | |
3512 | *(char *) p = '.'; | |
3513 | htab = ppc_hash_table (info); | |
b34976b6 | 3514 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
3515 | *(char *) p = save; |
3516 | ||
3517 | /* Unfortunately, if it so happens that the string we were | |
3518 | looking for was allocated immediately before this string, | |
3519 | then we overwrote the string terminator. That's the only | |
3520 | reason the lookup should fail. */ | |
3521 | if (fh == NULL) | |
3522 | { | |
3523 | q = h->root.root.string + strlen (h->root.root.string); | |
3524 | while (q >= h->root.root.string && *q == *p) | |
3525 | --q, --p; | |
3526 | if (q < h->root.root.string && *p == '.') | |
b34976b6 | 3527 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
3528 | } |
3529 | if (fh != NULL) | |
3530 | { | |
3531 | ((struct ppc_link_hash_entry *) h)->oh = fh; | |
3532 | ((struct ppc_link_hash_entry *) fh)->oh = h; | |
3533 | } | |
3534 | } | |
e86ce104 AM |
3535 | if (fh != NULL) |
3536 | _bfd_elf_link_hash_hide_symbol (info, fh, force_local); | |
3537 | } | |
3538 | } | |
3539 | ||
b34976b6 | 3540 | bfd_boolean |
d6fe2dc1 | 3541 | ppc64_elf_edit_opd (obfd, info) |
1e2f5b6e AM |
3542 | bfd *obfd; |
3543 | struct bfd_link_info *info; | |
3544 | { | |
3545 | bfd *ibfd; | |
3546 | unsigned int bfd_indx; | |
1e2f5b6e AM |
3547 | |
3548 | for (bfd_indx = 0, ibfd = info->input_bfds; | |
3549 | ibfd != NULL; | |
3550 | ibfd = ibfd->link_next, bfd_indx++) | |
3551 | { | |
3552 | asection *sec; | |
3553 | Elf_Internal_Rela *relstart, *rel, *relend; | |
3554 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 3555 | Elf_Internal_Sym *local_syms; |
1e2f5b6e AM |
3556 | struct elf_link_hash_entry **sym_hashes; |
3557 | bfd_vma offset; | |
d6fe2dc1 | 3558 | bfd_size_type amt; |
1e2f5b6e | 3559 | long *adjust; |
b34976b6 | 3560 | bfd_boolean need_edit; |
1e2f5b6e AM |
3561 | |
3562 | sec = bfd_get_section_by_name (ibfd, ".opd"); | |
3563 | if (sec == NULL) | |
3564 | continue; | |
3565 | ||
d6fe2dc1 | 3566 | amt = sec->_raw_size * sizeof (long) / 24; |
1e2f5b6e | 3567 | adjust = (long *) elf_section_data (sec)->tdata; |
d6fe2dc1 AM |
3568 | if (adjust == NULL) |
3569 | { | |
3570 | /* Must be a ld -r link. ie. check_relocs hasn't been | |
3571 | called. */ | |
3572 | adjust = (long *) bfd_zalloc (obfd, amt); | |
3573 | elf_section_data (sec)->tdata = adjust; | |
3574 | } | |
3575 | memset (adjust, 0, (size_t) amt); | |
1e2f5b6e AM |
3576 | |
3577 | if (sec->output_section == bfd_abs_section_ptr) | |
3578 | continue; | |
3579 | ||
3580 | /* Look through the section relocs. */ | |
3581 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
3582 | continue; | |
3583 | ||
6cdc0ccc | 3584 | local_syms = NULL; |
1e2f5b6e AM |
3585 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
3586 | sym_hashes = elf_sym_hashes (ibfd); | |
3587 | ||
3588 | /* Read the relocations. */ | |
3589 | relstart = _bfd_elf64_link_read_relocs (obfd, sec, (PTR) NULL, | |
3590 | (Elf_Internal_Rela *) NULL, | |
3591 | info->keep_memory); | |
3592 | if (relstart == NULL) | |
b34976b6 | 3593 | return FALSE; |
1e2f5b6e AM |
3594 | |
3595 | /* First run through the relocs to check they are sane, and to | |
3596 | determine whether we need to edit this opd section. */ | |
b34976b6 | 3597 | need_edit = FALSE; |
1e2f5b6e AM |
3598 | offset = 0; |
3599 | relend = relstart + sec->reloc_count; | |
3600 | for (rel = relstart; rel < relend; rel++) | |
3601 | { | |
3602 | enum elf_ppc_reloc_type r_type; | |
3603 | unsigned long r_symndx; | |
3604 | asection *sym_sec; | |
3605 | struct elf_link_hash_entry *h; | |
3606 | Elf_Internal_Sym *sym; | |
3607 | ||
3608 | /* .opd contains a regular array of 24 byte entries. We're | |
3609 | only interested in the reloc pointing to a function entry | |
3610 | point. */ | |
3611 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); | |
3612 | if (r_type == R_PPC64_TOC) | |
3613 | continue; | |
3614 | ||
3615 | if (r_type != R_PPC64_ADDR64) | |
3616 | { | |
3617 | (*_bfd_error_handler) | |
3618 | (_("%s: unexpected reloc type %u in .opd section"), | |
3619 | bfd_archive_filename (ibfd), r_type); | |
b34976b6 | 3620 | need_edit = FALSE; |
1e2f5b6e AM |
3621 | break; |
3622 | } | |
3623 | ||
3624 | if (rel + 1 >= relend) | |
3625 | continue; | |
3626 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info); | |
3627 | if (r_type != R_PPC64_TOC) | |
3628 | continue; | |
3629 | ||
3630 | if (rel->r_offset != offset) | |
3631 | { | |
3632 | /* If someone messes with .opd alignment then after a | |
3633 | "ld -r" we might have padding in the middle of .opd. | |
3634 | Also, there's nothing to prevent someone putting | |
3635 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 3636 | optimization for them! */ |
1e2f5b6e AM |
3637 | (*_bfd_error_handler) |
3638 | (_("%s: .opd is not a regular array of opd entries"), | |
3639 | bfd_archive_filename (ibfd)); | |
b34976b6 | 3640 | need_edit = FALSE; |
1e2f5b6e AM |
3641 | break; |
3642 | } | |
3643 | ||
3644 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3645 | sym_sec = NULL; | |
3646 | h = NULL; | |
3647 | sym = NULL; | |
3648 | if (r_symndx >= symtab_hdr->sh_info) | |
3649 | { | |
3650 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3651 | while (h->root.type == bfd_link_hash_indirect | |
3652 | || h->root.type == bfd_link_hash_warning) | |
3653 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3654 | if (h->root.type == bfd_link_hash_defined | |
3655 | || h->root.type == bfd_link_hash_defweak) | |
3656 | sym_sec = h->root.u.def.section; | |
3657 | } | |
3658 | else | |
3659 | { | |
6cdc0ccc AM |
3660 | if (local_syms == NULL) |
3661 | { | |
3662 | local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
3663 | if (local_syms == NULL) | |
3664 | local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
3665 | symtab_hdr->sh_info, 0, | |
3666 | NULL, NULL, NULL); | |
3667 | if (local_syms == NULL) | |
3668 | goto error_free_rel; | |
3669 | } | |
3670 | sym = local_syms + r_symndx; | |
1e2f5b6e AM |
3671 | if ((sym->st_shndx != SHN_UNDEF |
3672 | && sym->st_shndx < SHN_LORESERVE) | |
3673 | || sym->st_shndx > SHN_HIRESERVE) | |
3674 | sym_sec = bfd_section_from_elf_index (ibfd, sym->st_shndx); | |
3675 | } | |
3676 | ||
3677 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
3678 | { | |
3679 | (*_bfd_error_handler) | |
3680 | (_("%s: undefined sym `%s' in .opd section"), | |
3681 | bfd_archive_filename (ibfd), | |
3682 | h != NULL ? h->root.root.string : "<local symbol>"); | |
b34976b6 | 3683 | need_edit = FALSE; |
1e2f5b6e AM |
3684 | break; |
3685 | } | |
3686 | ||
51020317 AM |
3687 | /* opd entries are always for functions defined in the |
3688 | current input bfd. If the symbol isn't defined in the | |
3689 | input bfd, then we won't be using the function in this | |
3690 | bfd; It must be defined in a linkonce section in another | |
3691 | bfd, or is weak. It's also possible that we are | |
3692 | discarding the function due to a linker script /DISCARD/, | |
3693 | which we test for via the output_section. */ | |
3694 | if (sym_sec->owner != ibfd | |
3695 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 3696 | need_edit = TRUE; |
1e2f5b6e AM |
3697 | |
3698 | offset += 24; | |
3699 | } | |
3700 | ||
3701 | if (need_edit) | |
3702 | { | |
3703 | Elf_Internal_Rela *write_rel; | |
3704 | bfd_byte *rptr, *wptr; | |
b34976b6 | 3705 | bfd_boolean skip; |
1e2f5b6e AM |
3706 | |
3707 | /* This seems a waste of time as input .opd sections are all | |
3708 | zeros as generated by gcc, but I suppose there's no reason | |
3709 | this will always be so. We might start putting something in | |
3710 | the third word of .opd entries. */ | |
3711 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
3712 | { | |
3713 | bfd_byte *loc = bfd_alloc (ibfd, sec->_raw_size); | |
6cdc0ccc AM |
3714 | if (loc == NULL |
3715 | || !bfd_get_section_contents (ibfd, sec, loc, (bfd_vma) 0, | |
3716 | sec->_raw_size)) | |
3717 | { | |
3718 | if (local_syms != NULL | |
3719 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
3720 | free (local_syms); | |
3721 | error_free_rel: | |
3722 | if (elf_section_data (sec)->relocs != relstart) | |
3723 | free (relstart); | |
b34976b6 | 3724 | return FALSE; |
6cdc0ccc | 3725 | } |
1e2f5b6e AM |
3726 | sec->contents = loc; |
3727 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
3728 | } | |
3729 | ||
3730 | elf_section_data (sec)->relocs = relstart; | |
3731 | ||
3732 | wptr = sec->contents; | |
3733 | rptr = sec->contents; | |
3734 | write_rel = relstart; | |
b34976b6 | 3735 | skip = FALSE; |
1e2f5b6e AM |
3736 | offset = 0; |
3737 | for (rel = relstart; rel < relend; rel++) | |
3738 | { | |
3739 | if (rel->r_offset == offset) | |
3740 | { | |
3741 | unsigned long r_symndx; | |
3742 | asection *sym_sec; | |
3743 | struct elf_link_hash_entry *h; | |
3744 | Elf_Internal_Sym *sym; | |
3745 | ||
3746 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3747 | sym_sec = NULL; | |
3748 | h = NULL; | |
3749 | sym = NULL; | |
3750 | if (r_symndx >= symtab_hdr->sh_info) | |
3751 | { | |
3752 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3753 | while (h->root.type == bfd_link_hash_indirect | |
3754 | || h->root.type == bfd_link_hash_warning) | |
3755 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3756 | if (h->root.type == bfd_link_hash_defined | |
3757 | || h->root.type == bfd_link_hash_defweak) | |
3758 | sym_sec = h->root.u.def.section; | |
3759 | } | |
3760 | else | |
3761 | { | |
6cdc0ccc | 3762 | sym = local_syms + r_symndx; |
1e2f5b6e AM |
3763 | if ((sym->st_shndx != SHN_UNDEF |
3764 | && sym->st_shndx < SHN_LORESERVE) | |
3765 | || sym->st_shndx > SHN_HIRESERVE) | |
3766 | sym_sec = bfd_section_from_elf_index (ibfd, | |
3767 | sym->st_shndx); | |
3768 | } | |
3769 | ||
51020317 AM |
3770 | skip = (sym_sec->owner != ibfd |
3771 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
3772 | if (skip) |
3773 | { | |
0be617ce | 3774 | if (h != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
3775 | { |
3776 | /* Arrange for the function descriptor sym | |
3777 | to be dropped. */ | |
d6fe2dc1 | 3778 | struct ppc_link_hash_entry *fdh; |
a4aa0fb7 AM |
3779 | struct ppc_link_hash_entry *fh; |
3780 | ||
3781 | fh = (struct ppc_link_hash_entry *) h; | |
d6fe2dc1 AM |
3782 | fdh = (struct ppc_link_hash_entry *) fh->oh; |
3783 | if (fdh == NULL) | |
3784 | { | |
3785 | const char *fd_name; | |
3786 | struct ppc_link_hash_table *htab; | |
3787 | ||
3788 | fd_name = h->root.root.string + 1; | |
3789 | htab = ppc_hash_table (info); | |
3790 | fdh = (struct ppc_link_hash_entry *) | |
3791 | elf_link_hash_lookup (&htab->elf, fd_name, | |
b34976b6 | 3792 | FALSE, FALSE, FALSE); |
d6fe2dc1 AM |
3793 | fdh->is_func_descriptor = 1; |
3794 | fdh->oh = &fh->elf; | |
3795 | fh->is_func = 1; | |
3796 | fh->oh = &fdh->elf; | |
3797 | } | |
3798 | ||
3799 | fdh->elf.root.u.def.value = 0; | |
3800 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 AM |
3801 | } |
3802 | } | |
3803 | else | |
1e2f5b6e AM |
3804 | { |
3805 | /* We'll be keeping this opd entry. */ | |
3806 | ||
3807 | if (h != NULL) | |
3808 | { | |
3809 | /* Redefine the function descriptor symbol | |
3810 | to this location in the opd section. | |
3811 | We've checked above that opd relocs are | |
3812 | ordered. */ | |
d6fe2dc1 | 3813 | struct ppc_link_hash_entry *fdh; |
1e2f5b6e AM |
3814 | struct ppc_link_hash_entry *fh; |
3815 | ||
3816 | fh = (struct ppc_link_hash_entry *) h; | |
d6fe2dc1 AM |
3817 | fdh = (struct ppc_link_hash_entry *) fh->oh; |
3818 | if (fdh == NULL) | |
3819 | { | |
3820 | const char *fd_name; | |
3821 | struct ppc_link_hash_table *htab; | |
3822 | ||
3823 | fd_name = h->root.root.string + 1; | |
3824 | htab = ppc_hash_table (info); | |
3825 | fdh = (struct ppc_link_hash_entry *) | |
3826 | elf_link_hash_lookup (&htab->elf, fd_name, | |
b34976b6 | 3827 | FALSE, FALSE, FALSE); |
d6fe2dc1 AM |
3828 | fdh->is_func_descriptor = 1; |
3829 | fdh->oh = &fh->elf; | |
3830 | fh->is_func = 1; | |
3831 | fh->oh = &fdh->elf; | |
3832 | } | |
3833 | ||
3834 | fdh->elf.root.u.def.value = wptr - sec->contents; | |
1e2f5b6e AM |
3835 | } |
3836 | else | |
3837 | { | |
6cdc0ccc AM |
3838 | /* Local syms are a bit tricky. We could |
3839 | tweak them as they can be cached, but | |
3840 | we'd need to look through the local syms | |
3841 | for the function descriptor sym which we | |
3842 | don't have at the moment. So keep an | |
b34976b6 | 3843 | array of adjustments. */ |
7f6a7663 | 3844 | adjust[rel->r_offset / 24] = wptr - rptr; |
1e2f5b6e AM |
3845 | } |
3846 | ||
3847 | if (wptr != rptr) | |
3848 | memcpy (wptr, rptr, 24); | |
3849 | wptr += 24; | |
3850 | } | |
3851 | rptr += 24; | |
3852 | offset += 24; | |
3853 | } | |
3854 | ||
3855 | /* We need to adjust any reloc offsets to point to the | |
3856 | new opd entries. While we're at it, we may as well | |
3857 | remove redundant relocs. */ | |
3858 | if (!skip) | |
3859 | { | |
3860 | rel->r_offset += wptr - rptr; | |
3861 | if (write_rel != rel) | |
3862 | memcpy (write_rel, rel, sizeof (*rel)); | |
3863 | ++write_rel; | |
3864 | } | |
3865 | } | |
3866 | ||
3867 | sec->_cooked_size = wptr - sec->contents; | |
3868 | sec->reloc_count = write_rel - relstart; | |
cdcf6e38 AM |
3869 | /* Fudge the size too, as this is used later in |
3870 | elf_bfd_final_link if we are emitting relocs. */ | |
3871 | elf_section_data (sec)->rel_hdr.sh_size | |
3872 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; | |
3873 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); | |
1e2f5b6e | 3874 | } |
6cdc0ccc | 3875 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 3876 | free (relstart); |
6cdc0ccc AM |
3877 | |
3878 | if (local_syms != NULL | |
3879 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
3880 | { | |
3881 | if (!info->keep_memory) | |
3882 | free (local_syms); | |
3883 | else | |
3884 | symtab_hdr->contents = (unsigned char *) local_syms; | |
3885 | } | |
1e2f5b6e AM |
3886 | } |
3887 | ||
b34976b6 | 3888 | return TRUE; |
1e2f5b6e | 3889 | } |
b34976b6 | 3890 | |
65f38f15 AM |
3891 | /* This is the condition under which ppc64_elf_finish_dynamic_symbol |
3892 | will be called from elflink.h. If elflink.h doesn't call our | |
3893 | finish_dynamic_symbol routine, we'll need to do something about | |
3894 | initializing any .plt and .got entries in ppc64_elf_relocate_section. */ | |
3895 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ | |
3896 | ((DYN) \ | |
3897 | && ((INFO)->shared \ | |
3898 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ | |
3899 | && ((H)->dynindx != -1 \ | |
3900 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
5bd4f169 | 3901 | |
65f38f15 AM |
3902 | /* Allocate space in .plt, .got and associated reloc sections for |
3903 | dynamic relocs. */ | |
5bd4f169 | 3904 | |
b34976b6 | 3905 | static bfd_boolean |
65f38f15 AM |
3906 | allocate_dynrelocs (h, inf) |
3907 | struct elf_link_hash_entry *h; | |
3908 | PTR inf; | |
5bd4f169 | 3909 | { |
65f38f15 AM |
3910 | struct bfd_link_info *info; |
3911 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 3912 | asection *s; |
65f38f15 AM |
3913 | struct ppc_link_hash_entry *eh; |
3914 | struct ppc_dyn_relocs *p; | |
5bd4f169 | 3915 | |
e92d460e | 3916 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 3917 | return TRUE; |
5bd4f169 | 3918 | |
e92d460e AM |
3919 | if (h->root.type == bfd_link_hash_warning) |
3920 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3921 | ||
65f38f15 AM |
3922 | info = (struct bfd_link_info *) inf; |
3923 | htab = ppc_hash_table (info); | |
5bd4f169 | 3924 | |
65f38f15 | 3925 | if (htab->elf.dynamic_sections_created |
e86ce104 AM |
3926 | && h->plt.refcount > 0 |
3927 | && h->dynindx != -1) | |
5bd4f169 | 3928 | { |
e86ce104 | 3929 | BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor); |
5bd4f169 | 3930 | |
65f38f15 AM |
3931 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) |
3932 | { | |
65f38f15 AM |
3933 | /* If this is the first .plt entry, make room for the special |
3934 | first entry. */ | |
3935 | s = htab->splt; | |
5bd4f169 | 3936 | if (s->_raw_size == 0) |
65f38f15 AM |
3937 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; |
3938 | ||
3939 | h->plt.offset = s->_raw_size; | |
3940 | ||
3941 | /* Make room for this entry. */ | |
3942 | s->_raw_size += PLT_ENTRY_SIZE; | |
3943 | ||
721956f4 | 3944 | /* Make room for the .glink code. */ |
5d1634d7 AM |
3945 | s = htab->sglink; |
3946 | if (s->_raw_size == 0) | |
3947 | s->_raw_size += GLINK_CALL_STUB_SIZE; | |
3948 | /* We need bigger stubs past index 32767. */ | |
3949 | if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4) | |
3950 | s->_raw_size += 4; | |
3951 | s->_raw_size += 2*4; | |
65f38f15 AM |
3952 | |
3953 | /* We also need to make an entry in the .rela.plt section. */ | |
3954 | s = htab->srelplt; | |
3955 | s->_raw_size += sizeof (Elf64_External_Rela); | |
3956 | } | |
3957 | else | |
3958 | { | |
3959 | h->plt.offset = (bfd_vma) -1; | |
3960 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
3961 | } | |
3962 | } | |
3963 | else | |
3964 | { | |
3965 | h->plt.offset = (bfd_vma) -1; | |
3966 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
3967 | } | |
3968 | ||
3969 | if (h->got.refcount > 0) | |
3970 | { | |
b34976b6 | 3971 | bfd_boolean dyn; |
65f38f15 AM |
3972 | |
3973 | /* Make sure this symbol is output as a dynamic symbol. | |
3974 | Undefined weak syms won't yet be marked as dynamic. */ | |
3975 | if (h->dynindx == -1 | |
3976 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
3977 | { | |
3978 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
b34976b6 | 3979 | return FALSE; |
65f38f15 AM |
3980 | } |
3981 | ||
3982 | s = htab->sgot; | |
3983 | h->got.offset = s->_raw_size; | |
3984 | s->_raw_size += 8; | |
3985 | dyn = htab->elf.dynamic_sections_created; | |
3986 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) | |
3987 | htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); | |
3988 | } | |
3989 | else | |
3990 | h->got.offset = (bfd_vma) -1; | |
3991 | ||
3992 | eh = (struct ppc_link_hash_entry *) h; | |
3993 | if (eh->dyn_relocs == NULL) | |
b34976b6 | 3994 | return TRUE; |
65f38f15 AM |
3995 | |
3996 | /* In the shared -Bsymbolic case, discard space allocated for | |
3997 | dynamic pc-relative relocs against symbols which turn out to be | |
3998 | defined in regular objects. For the normal shared case, discard | |
3999 | space for relocs that have become local due to symbol visibility | |
4000 | changes. */ | |
4001 | ||
4002 | if (info->shared) | |
4003 | { | |
4004 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 | |
4005 | && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 | |
4006 | || info->symbolic)) | |
4007 | { | |
4008 | struct ppc_dyn_relocs **pp; | |
4009 | ||
4010 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 4011 | { |
65f38f15 AM |
4012 | p->count -= p->pc_count; |
4013 | p->pc_count = 0; | |
4014 | if (p->count == 0) | |
4015 | *pp = p->next; | |
4016 | else | |
4017 | pp = &p->next; | |
5bd4f169 | 4018 | } |
65f38f15 AM |
4019 | } |
4020 | } | |
4021 | else | |
4022 | { | |
4023 | /* For the non-shared case, discard space for relocs against | |
4024 | symbols which turn out to need copy relocs or are not | |
4025 | dynamic. */ | |
4026 | ||
4027 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
4028 | && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4029 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
4030 | || (htab->elf.dynamic_sections_created | |
4031 | && (h->root.type == bfd_link_hash_undefweak | |
4032 | || h->root.type == bfd_link_hash_undefined)))) | |
4033 | { | |
4034 | /* Make sure this symbol is output as a dynamic symbol. | |
4035 | Undefined weak syms won't yet be marked as dynamic. */ | |
4036 | if (h->dynindx == -1 | |
4037 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
4038 | { | |
ec338859 | 4039 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
b34976b6 | 4040 | return FALSE; |
65f38f15 AM |
4041 | } |
4042 | ||
4043 | /* If that succeeded, we know we'll be keeping all the | |
4044 | relocs. */ | |
4045 | if (h->dynindx != -1) | |
4046 | goto keep; | |
4047 | } | |
4048 | ||
4049 | eh->dyn_relocs = NULL; | |
4050 | ||
ec338859 | 4051 | keep: ; |
65f38f15 AM |
4052 | } |
4053 | ||
4054 | /* Finally, allocate space. */ | |
4055 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4056 | { | |
4057 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
4058 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
4059 | } | |
4060 | ||
b34976b6 | 4061 | return TRUE; |
65f38f15 AM |
4062 | } |
4063 | ||
4064 | /* Find any dynamic relocs that apply to read-only sections. */ | |
4065 | ||
b34976b6 | 4066 | static bfd_boolean |
65f38f15 AM |
4067 | readonly_dynrelocs (h, inf) |
4068 | struct elf_link_hash_entry *h; | |
4069 | PTR inf; | |
4070 | { | |
4071 | struct ppc_link_hash_entry *eh; | |
4072 | struct ppc_dyn_relocs *p; | |
4073 | ||
e92d460e AM |
4074 | if (h->root.type == bfd_link_hash_warning) |
4075 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4076 | ||
65f38f15 AM |
4077 | eh = (struct ppc_link_hash_entry *) h; |
4078 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4079 | { | |
4080 | asection *s = p->sec->output_section; | |
4081 | ||
4082 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
4083 | { | |
4084 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
4085 | ||
4086 | info->flags |= DF_TEXTREL; | |
4087 | ||
4088 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 4089 | return FALSE; |
65f38f15 AM |
4090 | } |
4091 | } | |
b34976b6 | 4092 | return TRUE; |
65f38f15 AM |
4093 | } |
4094 | ||
4095 | /* Set the sizes of the dynamic sections. */ | |
4096 | ||
b34976b6 | 4097 | static bfd_boolean |
65f38f15 AM |
4098 | ppc64_elf_size_dynamic_sections (output_bfd, info) |
4099 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
4100 | struct bfd_link_info *info; | |
4101 | { | |
4102 | struct ppc_link_hash_table *htab; | |
4103 | bfd *dynobj; | |
4104 | asection *s; | |
b34976b6 | 4105 | bfd_boolean relocs; |
65f38f15 AM |
4106 | bfd *ibfd; |
4107 | ||
4108 | htab = ppc_hash_table (info); | |
4109 | dynobj = htab->elf.dynobj; | |
4110 | if (dynobj == NULL) | |
4111 | abort (); | |
4112 | ||
4113 | if (htab->elf.dynamic_sections_created) | |
4114 | { | |
4115 | /* Set the contents of the .interp section to the interpreter. */ | |
4116 | if (! info->shared) | |
4117 | { | |
4118 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
4119 | if (s == NULL) | |
4120 | abort (); | |
4121 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
4122 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
4123 | } | |
4124 | } | |
4125 | ||
4126 | /* Set up .got offsets for local syms, and space for local dynamic | |
4127 | relocs. */ | |
4128 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
4129 | { | |
4130 | bfd_signed_vma *local_got; | |
4131 | bfd_signed_vma *end_local_got; | |
4132 | bfd_size_type locsymcount; | |
4133 | Elf_Internal_Shdr *symtab_hdr; | |
4134 | asection *srel; | |
4135 | ||
4136 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
4137 | continue; | |
4138 | ||
4139 | for (s = ibfd->sections; s != NULL; s = s->next) | |
4140 | { | |
ec338859 | 4141 | struct ppc_dyn_relocs *p; |
65f38f15 | 4142 | |
ec338859 AM |
4143 | for (p = *((struct ppc_dyn_relocs **) |
4144 | &elf_section_data (s)->local_dynrel); | |
4145 | p != NULL; | |
4146 | p = p->next) | |
65f38f15 | 4147 | { |
ec338859 AM |
4148 | if (!bfd_is_abs_section (p->sec) |
4149 | && bfd_is_abs_section (p->sec->output_section)) | |
4150 | { | |
4151 | /* Input section has been discarded, either because | |
4152 | it is a copy of a linkonce section or due to | |
4153 | linker script /DISCARD/, so we'll be discarding | |
4154 | the relocs too. */ | |
4155 | } | |
248866a8 | 4156 | else if (p->count != 0) |
ec338859 AM |
4157 | { |
4158 | srel = elf_section_data (p->sec)->sreloc; | |
4159 | srel->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
248866a8 AM |
4160 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
4161 | info->flags |= DF_TEXTREL; | |
ec338859 | 4162 | } |
65f38f15 AM |
4163 | } |
4164 | } | |
4165 | ||
4166 | local_got = elf_local_got_refcounts (ibfd); | |
4167 | if (!local_got) | |
4168 | continue; | |
4169 | ||
4170 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
4171 | locsymcount = symtab_hdr->sh_info; | |
4172 | end_local_got = local_got + locsymcount; | |
4173 | s = htab->sgot; | |
4174 | srel = htab->srelgot; | |
4175 | for (; local_got < end_local_got; ++local_got) | |
4176 | { | |
4177 | if (*local_got > 0) | |
5bd4f169 | 4178 | { |
65f38f15 AM |
4179 | *local_got = s->_raw_size; |
4180 | s->_raw_size += 8; | |
4181 | if (info->shared) | |
4182 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5bd4f169 | 4183 | } |
65f38f15 AM |
4184 | else |
4185 | *local_got = (bfd_vma) -1; | |
4186 | } | |
4187 | } | |
4188 | ||
4189 | /* Allocate global sym .plt and .got entries, and space for global | |
4190 | sym dynamic relocs. */ | |
4191 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); | |
4192 | ||
4193 | /* We now have determined the sizes of the various dynamic sections. | |
4194 | Allocate memory for them. */ | |
b34976b6 | 4195 | relocs = FALSE; |
65f38f15 AM |
4196 | for (s = dynobj->sections; s != NULL; s = s->next) |
4197 | { | |
4198 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
4199 | continue; | |
4200 | ||
721956f4 AM |
4201 | if (s == htab->sbrlt || s == htab->srelbrlt) |
4202 | /* These haven't been allocated yet; don't strip. */ | |
4203 | continue; | |
4204 | else if (s == htab->splt | |
4205 | || s == htab->sgot | |
4206 | || s == htab->sglink) | |
65f38f15 AM |
4207 | { |
4208 | /* Strip this section if we don't need it; see the | |
4209 | comment below. */ | |
5bd4f169 | 4210 | } |
65f38f15 | 4211 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 AM |
4212 | { |
4213 | if (s->_raw_size == 0) | |
4214 | { | |
4215 | /* If we don't need this section, strip it from the | |
4216 | output file. This is mostly to handle .rela.bss and | |
4217 | .rela.plt. We must create both sections in | |
4218 | create_dynamic_sections, because they must be created | |
4219 | before the linker maps input sections to output | |
4220 | sections. The linker does that before | |
4221 | adjust_dynamic_symbol is called, and it is that | |
4222 | function which decides whether anything needs to go | |
4223 | into these sections. */ | |
5bd4f169 AM |
4224 | } |
4225 | else | |
4226 | { | |
65f38f15 | 4227 | if (s != htab->srelplt) |
b34976b6 | 4228 | relocs = TRUE; |
5bd4f169 AM |
4229 | |
4230 | /* We use the reloc_count field as a counter if we need | |
4231 | to copy relocs into the output file. */ | |
4232 | s->reloc_count = 0; | |
4233 | } | |
4234 | } | |
65f38f15 | 4235 | else |
5bd4f169 AM |
4236 | { |
4237 | /* It's not one of our sections, so don't allocate space. */ | |
4238 | continue; | |
4239 | } | |
4240 | ||
65f38f15 | 4241 | if (s->_raw_size == 0) |
5bd4f169 AM |
4242 | { |
4243 | _bfd_strip_section_from_output (info, s); | |
4244 | continue; | |
4245 | } | |
4246 | ||
5f333394 AM |
4247 | /* .plt is in the bss section. We don't initialise it. */ |
4248 | if ((s->flags & SEC_LOAD) == 0) | |
4249 | continue; | |
4250 | ||
65f38f15 AM |
4251 | /* Allocate memory for the section contents. We use bfd_zalloc |
4252 | here in case unused entries are not reclaimed before the | |
4253 | section's contents are written out. This should not happen, | |
4254 | but this way if it does, we get a R_PPC64_NONE reloc instead | |
4255 | of garbage. */ | |
721956f4 | 4256 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); |
65f38f15 | 4257 | if (s->contents == NULL) |
b34976b6 | 4258 | return FALSE; |
5bd4f169 AM |
4259 | } |
4260 | ||
e86ce104 | 4261 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
4262 | { |
4263 | /* Add some entries to the .dynamic section. We fill in the | |
4264 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
4265 | must add the entries now so that we get the correct size for | |
4266 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
4267 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
4268 | #define add_dynamic_entry(TAG, VAL) \ |
4269 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
4270 | ||
4271 | if (!info->shared) | |
5bd4f169 | 4272 | { |
dc810e39 | 4273 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 4274 | return FALSE; |
5bd4f169 AM |
4275 | } |
4276 | ||
9c07fe7c | 4277 | if (htab->splt != NULL && htab->splt->_raw_size != 0) |
5bd4f169 | 4278 | { |
dc810e39 AM |
4279 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
4280 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
4281 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
4282 | || !add_dynamic_entry (DT_JMPREL, 0) |
4283 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 4284 | return FALSE; |
5bd4f169 AM |
4285 | } |
4286 | ||
19397422 AM |
4287 | if (NO_OPD_RELOCS) |
4288 | { | |
4289 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
4290 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 4291 | return FALSE; |
19397422 AM |
4292 | } |
4293 | ||
5bd4f169 AM |
4294 | if (relocs) |
4295 | { | |
dc810e39 AM |
4296 | if (!add_dynamic_entry (DT_RELA, 0) |
4297 | || !add_dynamic_entry (DT_RELASZ, 0) | |
4298 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 4299 | return FALSE; |
5bd4f169 | 4300 | |
65f38f15 AM |
4301 | /* If any dynamic relocs apply to a read-only section, |
4302 | then we need a DT_TEXTREL entry. */ | |
248866a8 AM |
4303 | if ((info->flags & DF_TEXTREL) == 0) |
4304 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, | |
4305 | (PTR) info); | |
5bd4f169 | 4306 | |
65f38f15 | 4307 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 4308 | { |
65f38f15 | 4309 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 4310 | return FALSE; |
5bd4f169 | 4311 | } |
5bd4f169 | 4312 | } |
5bd4f169 | 4313 | } |
65f38f15 | 4314 | #undef add_dynamic_entry |
5bd4f169 | 4315 | |
b34976b6 | 4316 | return TRUE; |
5bd4f169 AM |
4317 | } |
4318 | ||
721956f4 | 4319 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 4320 | |
721956f4 AM |
4321 | static INLINE enum ppc_stub_type |
4322 | ppc_type_of_stub (input_sec, rel, hash, destination) | |
4323 | asection *input_sec; | |
4324 | const Elf_Internal_Rela *rel; | |
4325 | struct ppc_link_hash_entry **hash; | |
4326 | bfd_vma destination; | |
5bd4f169 | 4327 | { |
721956f4 AM |
4328 | struct ppc_link_hash_entry *h = *hash; |
4329 | bfd_vma location; | |
4330 | bfd_vma branch_offset; | |
4331 | bfd_vma max_branch_offset; | |
4332 | unsigned int r_type; | |
5bd4f169 | 4333 | |
721956f4 AM |
4334 | if (h != NULL) |
4335 | { | |
4336 | if (h->oh != NULL | |
4337 | && h->oh->plt.offset != (bfd_vma) -1 | |
4338 | && h->oh->dynindx != -1) | |
5bd4f169 | 4339 | { |
721956f4 AM |
4340 | *hash = (struct ppc_link_hash_entry *) h->oh; |
4341 | return ppc_stub_plt_call; | |
5bd4f169 AM |
4342 | } |
4343 | ||
721956f4 AM |
4344 | if (h->elf.root.type == bfd_link_hash_undefweak |
4345 | || h->elf.root.type == bfd_link_hash_undefined) | |
4346 | return ppc_stub_none; | |
5d1634d7 | 4347 | } |
5d1634d7 | 4348 | |
721956f4 AM |
4349 | /* Determine where the call point is. */ |
4350 | location = (input_sec->output_offset | |
4351 | + input_sec->output_section->vma | |
4352 | + rel->r_offset); | |
5d1634d7 | 4353 | |
721956f4 AM |
4354 | branch_offset = destination - location; |
4355 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 4356 | |
721956f4 AM |
4357 | /* Determine if a long branch stub is needed. */ |
4358 | max_branch_offset = 1 << 25; | |
4359 | if (r_type != (unsigned int) R_PPC64_REL24) | |
4360 | max_branch_offset = 1 << 15; | |
5d1634d7 | 4361 | |
721956f4 AM |
4362 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
4363 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
4364 | is needed later. */ | |
4365 | return ppc_stub_long_branch; | |
5d1634d7 | 4366 | |
721956f4 | 4367 | return ppc_stub_none; |
5d1634d7 AM |
4368 | } |
4369 | ||
4370 | /* Build a .plt call stub. */ | |
4371 | ||
4372 | static bfd_byte * | |
4373 | build_plt_stub (obfd, p, offset, glink) | |
4374 | bfd *obfd; | |
4375 | bfd_byte *p; | |
4376 | int offset; | |
4377 | int glink; | |
4378 | { | |
4379 | #define PPC_LO(v) ((v) & 0xffff) | |
4380 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
4381 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
4382 | ||
4383 | if (glink) | |
4384 | bfd_put_32 (obfd, LD_R2_40R1, p), p += 4; | |
4385 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; | |
4386 | if (!glink) | |
4387 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; | |
4388 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
4389 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
4390 | bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4; | |
4391 | offset += 8; | |
4392 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
4393 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
4394 | bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4; | |
4395 | offset += 8; | |
4396 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
4397 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
4398 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
4399 | return p; | |
4400 | } | |
4401 | ||
b34976b6 | 4402 | static bfd_boolean |
721956f4 AM |
4403 | ppc_build_one_stub (gen_entry, in_arg) |
4404 | struct bfd_hash_entry *gen_entry; | |
4405 | PTR in_arg; | |
5d1634d7 | 4406 | { |
721956f4 AM |
4407 | struct ppc_stub_hash_entry *stub_entry; |
4408 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
4409 | struct bfd_link_info *info; |
4410 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
4411 | asection *stub_sec; |
4412 | bfd *stub_bfd; | |
4413 | bfd_byte *loc; | |
4414 | bfd_byte *p; | |
4415 | unsigned int indx; | |
4416 | bfd_vma off; | |
4417 | int size; | |
5d1634d7 | 4418 | |
721956f4 AM |
4419 | /* Massage our args to the form they really have. */ |
4420 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4421 | info = (struct bfd_link_info *) in_arg; | |
5d1634d7 | 4422 | |
5d1634d7 | 4423 | htab = ppc_hash_table (info); |
721956f4 | 4424 | stub_sec = stub_entry->stub_sec; |
5d1634d7 | 4425 | |
721956f4 AM |
4426 | /* Make a note of the offset within the stubs for this entry. */ |
4427 | stub_entry->stub_offset = stub_sec->_cooked_size; | |
4428 | loc = stub_sec->contents + stub_entry->stub_offset; | |
4429 | ||
4430 | stub_bfd = stub_sec->owner; | |
4431 | ||
4432 | switch (stub_entry->stub_type) | |
5d1634d7 | 4433 | { |
721956f4 AM |
4434 | case ppc_stub_long_branch: |
4435 | /* Branches are relative. This is where we are going to. */ | |
4436 | off = (stub_entry->target_value | |
4437 | + stub_entry->target_section->output_offset | |
4438 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 4439 | |
721956f4 AM |
4440 | /* And this is where we are coming from. */ |
4441 | off -= (stub_entry->stub_offset | |
4442 | + stub_sec->output_offset | |
4443 | + stub_sec->output_section->vma); | |
e86ce104 | 4444 | |
721956f4 | 4445 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); |
e86ce104 | 4446 | |
721956f4 AM |
4447 | bfd_put_32 (stub_bfd, (bfd_vma) B_DOT | (off & 0x3fffffc), loc); |
4448 | size = 4; | |
4449 | break; | |
e86ce104 | 4450 | |
721956f4 AM |
4451 | case ppc_stub_plt_branch: |
4452 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
4453 | stub_entry->root.string + 9, | |
b34976b6 | 4454 | FALSE, FALSE); |
721956f4 AM |
4455 | if (br_entry == NULL) |
4456 | { | |
4457 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), | |
4458 | stub_entry->root.string + 9); | |
b34976b6 AM |
4459 | htab->stub_error = TRUE; |
4460 | return FALSE; | |
721956f4 AM |
4461 | } |
4462 | ||
4463 | off = (stub_entry->target_value | |
4464 | + stub_entry->target_section->output_offset | |
4465 | + stub_entry->target_section->output_section->vma); | |
4466 | ||
4467 | bfd_put_64 (htab->sbrlt->owner, off, | |
4468 | htab->sbrlt->contents + br_entry->offset); | |
4469 | ||
4470 | if (info->shared) | |
4471 | { | |
4472 | /* Create a reloc for the branch lookup table entry. */ | |
4473 | Elf_Internal_Rela rela; | |
947216bf | 4474 | bfd_byte *loc; |
5d1634d7 | 4475 | |
721956f4 AM |
4476 | rela.r_offset = (br_entry->offset |
4477 | + htab->sbrlt->output_offset | |
4478 | + htab->sbrlt->output_section->vma); | |
4479 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
4480 | rela.r_addend = off; | |
4481 | ||
947216bf AM |
4482 | loc = htab->srelbrlt->contents; |
4483 | loc += htab->srelbrlt->reloc_count++ * sizeof (Elf64_External_Rela); | |
4484 | bfd_elf64_swap_reloca_out (htab->srelbrlt->owner, &rela, loc); | |
721956f4 AM |
4485 | } |
4486 | ||
4487 | off = (br_entry->offset | |
4488 | + htab->sbrlt->output_offset | |
4489 | + htab->sbrlt->output_section->vma | |
4490 | - elf_gp (htab->sbrlt->output_section->owner) | |
4491 | - TOC_BASE_OFF); | |
4492 | ||
4493 | if (off + 0x80000000 > 0xffffffff || (off & 7) != 0) | |
5d1634d7 AM |
4494 | { |
4495 | (*_bfd_error_handler) | |
e86ce104 | 4496 | (_("linkage table error against `%s'"), |
721956f4 | 4497 | stub_entry->root.string); |
5d1634d7 | 4498 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
4499 | htab->stub_error = TRUE; |
4500 | return FALSE; | |
5d1634d7 | 4501 | } |
41bd81ab | 4502 | |
721956f4 AM |
4503 | indx = off; |
4504 | bfd_put_32 (stub_bfd, (bfd_vma) ADDIS_R12_R2 | PPC_HA (indx), loc); | |
4505 | bfd_put_32 (stub_bfd, (bfd_vma) LD_R11_0R12 | PPC_LO (indx), loc + 4); | |
4506 | bfd_put_32 (stub_bfd, (bfd_vma) MTCTR_R11, loc + 8); | |
4507 | bfd_put_32 (stub_bfd, (bfd_vma) BCTR, loc + 12); | |
4508 | size = 16; | |
4509 | break; | |
5d1634d7 | 4510 | |
721956f4 | 4511 | case ppc_stub_plt_call: |
c862ae31 AM |
4512 | /* Do the best we can for shared libraries built without |
4513 | exporting ".foo" for each "foo". This can happen when symbol | |
4514 | versioning scripts strip all bar a subset of symbols. */ | |
4515 | if (stub_entry->h->oh->root.type != bfd_link_hash_defined | |
4516 | && stub_entry->h->oh->root.type != bfd_link_hash_defweak) | |
4517 | { | |
4518 | /* Point the symbol at the stub. There may be multiple stubs, | |
4519 | we don't really care; The main thing is to make this sym | |
4520 | defined somewhere. */ | |
4521 | stub_entry->h->oh->root.type = bfd_link_hash_defined; | |
4522 | stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec; | |
4523 | stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset; | |
4524 | } | |
4525 | ||
721956f4 AM |
4526 | /* Now build the stub. */ |
4527 | off = stub_entry->h->elf.plt.offset; | |
4528 | if (off >= (bfd_vma) -2) | |
4529 | abort (); | |
4530 | ||
4531 | off &= ~ (bfd_vma) 1; | |
4532 | off += (htab->splt->output_offset | |
4533 | + htab->splt->output_section->vma | |
4534 | - elf_gp (htab->splt->output_section->owner) | |
4535 | - TOC_BASE_OFF); | |
4536 | ||
4537 | if (off + 0x80000000 > 0xffffffff || (off & 7) != 0) | |
4538 | { | |
4539 | (*_bfd_error_handler) | |
4540 | (_("linkage table error against `%s'"), | |
4541 | stub_entry->h->elf.root.root.string); | |
4542 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 AM |
4543 | htab->stub_error = TRUE; |
4544 | return FALSE; | |
721956f4 AM |
4545 | } |
4546 | ||
4547 | p = build_plt_stub (stub_bfd, loc, (int) off, 0); | |
4548 | size = p - loc; | |
4549 | break; | |
4550 | ||
4551 | default: | |
4552 | BFD_FAIL (); | |
b34976b6 | 4553 | return FALSE; |
721956f4 AM |
4554 | } |
4555 | ||
4556 | stub_sec->_cooked_size += size; | |
b34976b6 | 4557 | return TRUE; |
721956f4 AM |
4558 | } |
4559 | ||
4560 | /* As above, but don't actually build the stub. Just bump offset so | |
4561 | we know stub section sizes, and select plt_branch stubs where | |
4562 | long_branch stubs won't do. */ | |
4563 | ||
b34976b6 | 4564 | static bfd_boolean |
721956f4 AM |
4565 | ppc_size_one_stub (gen_entry, in_arg) |
4566 | struct bfd_hash_entry *gen_entry; | |
4567 | PTR in_arg; | |
4568 | { | |
4569 | struct ppc_stub_hash_entry *stub_entry; | |
4570 | struct ppc_link_hash_table *htab; | |
4571 | bfd_vma off; | |
4572 | int size; | |
4573 | ||
4574 | /* Massage our args to the form they really have. */ | |
4575 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4576 | htab = (struct ppc_link_hash_table *) in_arg; | |
4577 | ||
4578 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
4579 | { | |
4580 | off = stub_entry->h->elf.plt.offset & ~(bfd_vma) 1; | |
4581 | off += (htab->splt->output_offset | |
4582 | + htab->splt->output_section->vma | |
4583 | - elf_gp (htab->splt->output_section->owner) | |
4584 | - TOC_BASE_OFF); | |
4585 | ||
4586 | size = 28; | |
4587 | if (PPC_HA ((int) off + 16) != PPC_HA ((int) off)) | |
4588 | size += 4; | |
4589 | } | |
4590 | else | |
4591 | { | |
4592 | /* ppc_stub_long_branch or ppc_stub_plt_branch. */ | |
4593 | stub_entry->stub_type = ppc_stub_long_branch; | |
4594 | size = 4; | |
4595 | ||
4596 | off = (stub_entry->target_value | |
4597 | + stub_entry->target_section->output_offset | |
4598 | + stub_entry->target_section->output_section->vma); | |
4599 | off -= (stub_entry->stub_sec->_raw_size | |
4600 | + stub_entry->stub_sec->output_offset | |
4601 | + stub_entry->stub_sec->output_section->vma); | |
4602 | ||
4603 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) | |
4604 | { | |
4605 | struct ppc_branch_hash_entry *br_entry; | |
4606 | ||
4607 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
4608 | stub_entry->root.string + 9, | |
b34976b6 | 4609 | TRUE, FALSE); |
721956f4 AM |
4610 | if (br_entry == NULL) |
4611 | { | |
4612 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), | |
4613 | stub_entry->root.string + 9); | |
b34976b6 AM |
4614 | htab->stub_error = TRUE; |
4615 | return FALSE; | |
721956f4 AM |
4616 | } |
4617 | ||
4618 | if (br_entry->iter != htab->stub_iteration) | |
4619 | { | |
4620 | br_entry->iter = htab->stub_iteration; | |
4621 | br_entry->offset = htab->sbrlt->_raw_size; | |
4622 | htab->sbrlt->_raw_size += 8; | |
4623 | } | |
4624 | stub_entry->stub_type = ppc_stub_plt_branch; | |
4625 | size = 16; | |
4626 | } | |
4627 | } | |
4628 | ||
4629 | stub_entry->stub_sec->_raw_size += size; | |
b34976b6 | 4630 | return TRUE; |
721956f4 AM |
4631 | } |
4632 | ||
4633 | /* Set up various things so that we can make a list of input sections | |
4634 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 4635 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
4636 | |
4637 | int | |
4638 | ppc64_elf_setup_section_lists (output_bfd, info) | |
4639 | bfd *output_bfd; | |
4640 | struct bfd_link_info *info; | |
4641 | { | |
4642 | bfd *input_bfd; | |
721956f4 AM |
4643 | int top_id, top_index; |
4644 | asection *section; | |
4645 | asection **input_list, **list; | |
4646 | bfd_size_type amt; | |
4647 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
4648 | ||
805fc799 AM |
4649 | if (htab->elf.root.creator->flavour != bfd_target_elf_flavour |
4650 | || htab->sbrlt == NULL) | |
721956f4 AM |
4651 | return 0; |
4652 | ||
1e2f5b6e AM |
4653 | /* Find the top input section id. */ |
4654 | for (input_bfd = info->input_bfds, top_id = 0; | |
721956f4 AM |
4655 | input_bfd != NULL; |
4656 | input_bfd = input_bfd->link_next) | |
4657 | { | |
721956f4 AM |
4658 | for (section = input_bfd->sections; |
4659 | section != NULL; | |
4660 | section = section->next) | |
4661 | { | |
4662 | if (top_id < section->id) | |
4663 | top_id = section->id; | |
4664 | } | |
4665 | } | |
721956f4 AM |
4666 | |
4667 | amt = sizeof (struct map_stub) * (top_id + 1); | |
4668 | htab->stub_group = (struct map_stub *) bfd_zmalloc (amt); | |
4669 | if (htab->stub_group == NULL) | |
4670 | return -1; | |
4671 | ||
4672 | /* We can't use output_bfd->section_count here to find the top output | |
4673 | section index as some sections may have been removed, and | |
4674 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
4675 | for (section = output_bfd->sections, top_index = 0; | |
4676 | section != NULL; | |
4677 | section = section->next) | |
4678 | { | |
4679 | if (top_index < section->index) | |
4680 | top_index = section->index; | |
4681 | } | |
4682 | ||
4683 | htab->top_index = top_index; | |
4684 | amt = sizeof (asection *) * (top_index + 1); | |
4685 | input_list = (asection **) bfd_malloc (amt); | |
4686 | htab->input_list = input_list; | |
4687 | if (input_list == NULL) | |
4688 | return -1; | |
4689 | ||
4690 | /* For sections we aren't interested in, mark their entries with a | |
4691 | value we can check later. */ | |
4692 | list = input_list + top_index; | |
4693 | do | |
4694 | *list = bfd_abs_section_ptr; | |
4695 | while (list-- != input_list); | |
4696 | ||
4697 | for (section = output_bfd->sections; | |
4698 | section != NULL; | |
4699 | section = section->next) | |
4700 | { | |
4701 | if ((section->flags & SEC_CODE) != 0) | |
4702 | input_list[section->index] = NULL; | |
4703 | } | |
4704 | ||
4705 | return 1; | |
4706 | } | |
4707 | ||
4708 | /* The linker repeatedly calls this function for each input section, | |
4709 | in the order that input sections are linked into output sections. | |
4710 | Build lists of input sections to determine groupings between which | |
4711 | we may insert linker stubs. */ | |
4712 | ||
4713 | void | |
805fc799 | 4714 | ppc64_elf_next_input_section (info, isec) |
721956f4 AM |
4715 | struct bfd_link_info *info; |
4716 | asection *isec; | |
4717 | { | |
4718 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
4719 | ||
805fc799 | 4720 | if (isec->output_section->index <= htab->top_index) |
721956f4 AM |
4721 | { |
4722 | asection **list = htab->input_list + isec->output_section->index; | |
4723 | if (*list != bfd_abs_section_ptr) | |
4724 | { | |
4725 | /* Steal the link_sec pointer for our list. */ | |
4726 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) | |
4727 | /* This happens to make the list in reverse order, | |
4728 | which is what we want. */ | |
4729 | PREV_SEC (isec) = *list; | |
4730 | *list = isec; | |
4731 | } | |
4732 | } | |
4733 | } | |
4734 | ||
4735 | /* See whether we can group stub sections together. Grouping stub | |
4736 | sections may result in fewer stubs. More importantly, we need to | |
4737 | put all .init* and .fini* stubs at the beginning of the .init or | |
4738 | .fini output sections respectively, because glibc splits the | |
4739 | _init and _fini functions into multiple parts. Putting a stub in | |
4740 | the middle of a function is not a good idea. */ | |
4741 | ||
4742 | static void | |
4743 | group_sections (htab, stub_group_size, stubs_always_before_branch) | |
4744 | struct ppc_link_hash_table *htab; | |
4745 | bfd_size_type stub_group_size; | |
b34976b6 | 4746 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
4747 | { |
4748 | asection **list = htab->input_list + htab->top_index; | |
4749 | do | |
4750 | { | |
4751 | asection *tail = *list; | |
4752 | if (tail == bfd_abs_section_ptr) | |
4753 | continue; | |
4754 | while (tail != NULL) | |
4755 | { | |
4756 | asection *curr; | |
4757 | asection *prev; | |
4758 | bfd_size_type total; | |
4759 | ||
4760 | curr = tail; | |
4761 | if (tail->_cooked_size) | |
4762 | total = tail->_cooked_size; | |
4763 | else | |
4764 | total = tail->_raw_size; | |
4765 | while ((prev = PREV_SEC (curr)) != NULL | |
4766 | && ((total += curr->output_offset - prev->output_offset) | |
4767 | < stub_group_size)) | |
4768 | curr = prev; | |
4769 | ||
4770 | /* OK, the size from the start of CURR to the end is less | |
4771 | than stub_group_size and thus can be handled by one stub | |
4772 | section. (or the tail section is itself larger than | |
4773 | stub_group_size, in which case we may be toast.) We | |
4774 | should really be keeping track of the total size of stubs | |
4775 | added here, as stubs contribute to the final output | |
4776 | section size. That's a little tricky, and this way will | |
4777 | only break if stubs added make the total size more than | |
4778 | 2^25, ie. for the default stub_group_size, if stubs total | |
4779 | more than 2834432 bytes, or over 100000 plt call stubs. */ | |
4780 | do | |
4781 | { | |
4782 | prev = PREV_SEC (tail); | |
4783 | /* Set up this stub group. */ | |
4784 | htab->stub_group[tail->id].link_sec = curr; | |
4785 | } | |
4786 | while (tail != curr && (tail = prev) != NULL); | |
4787 | ||
4788 | /* But wait, there's more! Input sections up to stub_group_size | |
4789 | bytes before the stub section can be handled by it too. */ | |
4790 | if (!stubs_always_before_branch) | |
4791 | { | |
4792 | total = 0; | |
4793 | while (prev != NULL | |
4794 | && ((total += tail->output_offset - prev->output_offset) | |
4795 | < stub_group_size)) | |
4796 | { | |
4797 | tail = prev; | |
4798 | prev = PREV_SEC (tail); | |
4799 | htab->stub_group[tail->id].link_sec = curr; | |
4800 | } | |
4801 | } | |
4802 | tail = prev; | |
4803 | } | |
4804 | } | |
4805 | while (list-- != htab->input_list); | |
4806 | free (htab->input_list); | |
4807 | #undef PREV_SEC | |
4808 | } | |
4809 | ||
721956f4 AM |
4810 | /* Determine and set the size of the stub section for a final link. |
4811 | ||
4812 | The basic idea here is to examine all the relocations looking for | |
4813 | PC-relative calls to a target that is unreachable with a "bl" | |
4814 | instruction. */ | |
4815 | ||
b34976b6 | 4816 | bfd_boolean |
721956f4 AM |
4817 | ppc64_elf_size_stubs (output_bfd, stub_bfd, info, group_size, |
4818 | add_stub_section, layout_sections_again) | |
4819 | bfd *output_bfd; | |
4820 | bfd *stub_bfd; | |
4821 | struct bfd_link_info *info; | |
4822 | bfd_signed_vma group_size; | |
4823 | asection * (*add_stub_section) PARAMS ((const char *, asection *)); | |
4824 | void (*layout_sections_again) PARAMS ((void)); | |
4825 | { | |
4826 | bfd_size_type stub_group_size; | |
b34976b6 | 4827 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
4828 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
4829 | ||
4830 | /* Stash our params away. */ | |
4831 | htab->stub_bfd = stub_bfd; | |
4832 | htab->add_stub_section = add_stub_section; | |
4833 | htab->layout_sections_again = layout_sections_again; | |
4834 | stubs_always_before_branch = group_size < 0; | |
4835 | if (group_size < 0) | |
4836 | stub_group_size = -group_size; | |
4837 | else | |
4838 | stub_group_size = group_size; | |
4839 | if (stub_group_size == 1) | |
4840 | { | |
4841 | /* Default values. */ | |
4842 | stub_group_size = 30720000; | |
4843 | if (htab->has_14bit_branch) | |
4844 | stub_group_size = 30000; | |
4845 | } | |
4846 | ||
4847 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
4848 | ||
721956f4 AM |
4849 | while (1) |
4850 | { | |
4851 | bfd *input_bfd; | |
4852 | unsigned int bfd_indx; | |
4853 | asection *stub_sec; | |
b34976b6 | 4854 | bfd_boolean stub_changed; |
721956f4 AM |
4855 | |
4856 | htab->stub_iteration += 1; | |
b34976b6 | 4857 | stub_changed = FALSE; |
721956f4 AM |
4858 | |
4859 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
4860 | input_bfd != NULL; | |
4861 | input_bfd = input_bfd->link_next, bfd_indx++) | |
4862 | { | |
4863 | Elf_Internal_Shdr *symtab_hdr; | |
4864 | asection *section; | |
6cdc0ccc | 4865 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 AM |
4866 | |
4867 | /* We'll need the symbol table in a second. */ | |
4868 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
4869 | if (symtab_hdr->sh_info == 0) | |
4870 | continue; | |
4871 | ||
721956f4 AM |
4872 | /* Walk over each section attached to the input bfd. */ |
4873 | for (section = input_bfd->sections; | |
4874 | section != NULL; | |
4875 | section = section->next) | |
4876 | { | |
721956f4 | 4877 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
4878 | |
4879 | /* If there aren't any relocs, then there's nothing more | |
4880 | to do. */ | |
4881 | if ((section->flags & SEC_RELOC) == 0 | |
4882 | || section->reloc_count == 0) | |
4883 | continue; | |
4884 | ||
4885 | /* If this section is a link-once section that will be | |
4886 | discarded, then don't create any stubs. */ | |
4887 | if (section->output_section == NULL | |
4888 | || section->output_section->owner != output_bfd) | |
4889 | continue; | |
4890 | ||
1e2f5b6e AM |
4891 | /* Get the relocs. */ |
4892 | internal_relocs | |
4893 | = _bfd_elf64_link_read_relocs (input_bfd, section, NULL, | |
4894 | (Elf_Internal_Rela *) NULL, | |
4895 | info->keep_memory); | |
721956f4 | 4896 | if (internal_relocs == NULL) |
1e2f5b6e | 4897 | goto error_ret_free_local; |
721956f4 AM |
4898 | |
4899 | /* Now examine each relocation. */ | |
4900 | irela = internal_relocs; | |
4901 | irelaend = irela + section->reloc_count; | |
4902 | for (; irela < irelaend; irela++) | |
4903 | { | |
4904 | unsigned int r_type, r_indx; | |
4905 | enum ppc_stub_type stub_type; | |
4906 | struct ppc_stub_hash_entry *stub_entry; | |
4907 | asection *sym_sec; | |
4908 | bfd_vma sym_value; | |
4909 | bfd_vma destination; | |
4910 | struct ppc_link_hash_entry *hash; | |
4911 | char *stub_name; | |
4912 | const asection *id_sec; | |
4913 | ||
4914 | r_type = ELF64_R_TYPE (irela->r_info); | |
4915 | r_indx = ELF64_R_SYM (irela->r_info); | |
4916 | ||
4917 | if (r_type >= (unsigned int) R_PPC_max) | |
4918 | { | |
4919 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 4920 | goto error_ret_free_internal; |
721956f4 AM |
4921 | } |
4922 | ||
4923 | /* Only look for stubs on branch instructions. */ | |
4924 | if (r_type != (unsigned int) R_PPC64_REL24 | |
4925 | && r_type != (unsigned int) R_PPC64_REL14 | |
4926 | && r_type != (unsigned int) R_PPC64_REL14_BRTAKEN | |
4927 | && r_type != (unsigned int) R_PPC64_REL14_BRNTAKEN) | |
4928 | continue; | |
4929 | ||
4930 | /* Now determine the call target, its name, value, | |
4931 | section. */ | |
4932 | sym_sec = NULL; | |
4933 | sym_value = 0; | |
4934 | destination = 0; | |
4935 | hash = NULL; | |
4936 | if (r_indx < symtab_hdr->sh_info) | |
4937 | { | |
4938 | /* It's a local symbol. */ | |
4939 | Elf_Internal_Sym *sym; | |
4940 | Elf_Internal_Shdr *hdr; | |
4941 | ||
6cdc0ccc AM |
4942 | if (local_syms == NULL) |
4943 | { | |
4944 | local_syms | |
4945 | = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4946 | if (local_syms == NULL) | |
4947 | local_syms | |
4948 | = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, | |
4949 | symtab_hdr->sh_info, 0, | |
4950 | NULL, NULL, NULL); | |
4951 | if (local_syms == NULL) | |
4952 | goto error_ret_free_internal; | |
4953 | } | |
721956f4 AM |
4954 | sym = local_syms + r_indx; |
4955 | hdr = elf_elfsections (input_bfd)[sym->st_shndx]; | |
4956 | sym_sec = hdr->bfd_section; | |
4957 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) | |
4958 | sym_value = sym->st_value; | |
4959 | destination = (sym_value + irela->r_addend | |
4960 | + sym_sec->output_offset | |
4961 | + sym_sec->output_section->vma); | |
4962 | } | |
4963 | else | |
4964 | { | |
4965 | /* It's an external symbol. */ | |
4966 | int e_indx; | |
4967 | ||
4968 | e_indx = r_indx - symtab_hdr->sh_info; | |
4969 | hash = ((struct ppc_link_hash_entry *) | |
4970 | elf_sym_hashes (input_bfd)[e_indx]); | |
4971 | ||
4972 | while (hash->elf.root.type == bfd_link_hash_indirect | |
4973 | || hash->elf.root.type == bfd_link_hash_warning) | |
4974 | hash = ((struct ppc_link_hash_entry *) | |
4975 | hash->elf.root.u.i.link); | |
4976 | ||
4977 | if (hash->elf.root.type == bfd_link_hash_defined | |
4978 | || hash->elf.root.type == bfd_link_hash_defweak) | |
4979 | { | |
4980 | sym_sec = hash->elf.root.u.def.section; | |
4981 | sym_value = hash->elf.root.u.def.value; | |
4982 | if (sym_sec->output_section != NULL) | |
4983 | destination = (sym_value + irela->r_addend | |
4984 | + sym_sec->output_offset | |
4985 | + sym_sec->output_section->vma); | |
4986 | } | |
4987 | else if (hash->elf.root.type == bfd_link_hash_undefweak) | |
4988 | ; | |
4989 | else if (hash->elf.root.type == bfd_link_hash_undefined) | |
4990 | ; | |
4991 | else | |
4992 | { | |
4993 | bfd_set_error (bfd_error_bad_value); | |
4994 | goto error_ret_free_internal; | |
4995 | } | |
4996 | } | |
4997 | ||
4998 | /* Determine what (if any) linker stub is needed. */ | |
4999 | stub_type = ppc_type_of_stub (section, irela, &hash, | |
5000 | destination); | |
5001 | if (stub_type == ppc_stub_none) | |
5002 | continue; | |
5003 | ||
5004 | /* Support for grouping stub sections. */ | |
5005 | id_sec = htab->stub_group[section->id].link_sec; | |
5006 | ||
5007 | /* Get the name of this stub. */ | |
5008 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
5009 | if (!stub_name) | |
5010 | goto error_ret_free_internal; | |
5011 | ||
5012 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 5013 | stub_name, FALSE, FALSE); |
721956f4 AM |
5014 | if (stub_entry != NULL) |
5015 | { | |
5016 | /* The proper stub has already been created. */ | |
5017 | free (stub_name); | |
5018 | continue; | |
5019 | } | |
5020 | ||
5021 | stub_entry = ppc_add_stub (stub_name, section, htab); | |
5022 | if (stub_entry == NULL) | |
5023 | { | |
5024 | free (stub_name); | |
6cdc0ccc AM |
5025 | error_ret_free_internal: |
5026 | if (elf_section_data (section)->relocs == NULL) | |
5027 | free (internal_relocs); | |
5028 | error_ret_free_local: | |
5029 | if (local_syms != NULL | |
5030 | && (symtab_hdr->contents | |
5031 | != (unsigned char *) local_syms)) | |
5032 | free (local_syms); | |
b34976b6 | 5033 | return FALSE; |
721956f4 AM |
5034 | } |
5035 | ||
5036 | stub_entry->target_value = sym_value; | |
5037 | stub_entry->target_section = sym_sec; | |
5038 | stub_entry->stub_type = stub_type; | |
5039 | stub_entry->h = hash; | |
b34976b6 | 5040 | stub_changed = TRUE; |
721956f4 AM |
5041 | } |
5042 | ||
5043 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 5044 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 5045 | free (internal_relocs); |
721956f4 | 5046 | } |
6cdc0ccc AM |
5047 | |
5048 | if (local_syms != NULL | |
5049 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5050 | { | |
5051 | if (!info->keep_memory) | |
5052 | free (local_syms); | |
5053 | else | |
5054 | symtab_hdr->contents = (unsigned char *) local_syms; | |
5055 | } | |
721956f4 AM |
5056 | } |
5057 | ||
5058 | if (!stub_changed) | |
5059 | break; | |
5060 | ||
5061 | /* OK, we've added some stubs. Find out the new size of the | |
5062 | stub sections. */ | |
5063 | for (stub_sec = htab->stub_bfd->sections; | |
5064 | stub_sec != NULL; | |
5065 | stub_sec = stub_sec->next) | |
5066 | { | |
5067 | stub_sec->_raw_size = 0; | |
5068 | stub_sec->_cooked_size = 0; | |
5069 | } | |
5070 | htab->sbrlt->_raw_size = 0; | |
5071 | htab->sbrlt->_cooked_size = 0; | |
5072 | ||
5073 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab); | |
5074 | ||
5075 | /* Ask the linker to do its stuff. */ | |
5076 | (*htab->layout_sections_again) (); | |
5077 | } | |
5078 | ||
afbe61cf AM |
5079 | /* It would be nice to strip .branch_lt from the output if the |
5080 | section is empty, but it's too late. If we strip sections here, | |
5081 | the dynamic symbol table is corrupted since the section symbol | |
5082 | for the stripped section isn't written. */ | |
721956f4 | 5083 | |
b34976b6 | 5084 | return TRUE; |
721956f4 AM |
5085 | } |
5086 | ||
5087 | /* Called after we have determined section placement. If sections | |
805fc799 | 5088 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 5089 | |
805fc799 AM |
5090 | bfd_vma |
5091 | ppc64_elf_toc (obfd) | |
5d1634d7 | 5092 | bfd *obfd; |
721956f4 | 5093 | { |
805fc799 AM |
5094 | asection *s; |
5095 | bfd_vma TOCstart; | |
721956f4 | 5096 | |
805fc799 AM |
5097 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
5098 | order. The TOC starts where the first of these sections starts. */ | |
5099 | s = bfd_get_section_by_name (obfd, ".got"); | |
5100 | if (s == NULL) | |
5101 | s = bfd_get_section_by_name (obfd, ".toc"); | |
5102 | if (s == NULL) | |
5103 | s = bfd_get_section_by_name (obfd, ".tocbss"); | |
5104 | if (s == NULL) | |
5105 | s = bfd_get_section_by_name (obfd, ".plt"); | |
5106 | if (s == NULL) | |
5107 | { | |
5108 | /* This may happen for | |
5109 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
5110 | .toc directive | |
5111 | o bad linker script | |
5112 | o --gc-sections and empty TOC sections | |
5113 | ||
5114 | FIXME: Warn user? */ | |
5115 | ||
5116 | /* Look for a likely section. We probably won't even be | |
5117 | using TOCstart. */ | |
5118 | for (s = obfd->sections; s != NULL; s = s->next) | |
5119 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) | |
5120 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
5121 | break; | |
721956f4 | 5122 | if (s == NULL) |
805fc799 AM |
5123 | for (s = obfd->sections; s != NULL; s = s->next) |
5124 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) | |
5125 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
5126 | break; | |
721956f4 | 5127 | if (s == NULL) |
805fc799 AM |
5128 | for (s = obfd->sections; s != NULL; s = s->next) |
5129 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) | |
5130 | break; | |
721956f4 | 5131 | if (s == NULL) |
805fc799 AM |
5132 | for (s = obfd->sections; s != NULL; s = s->next) |
5133 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) | |
5134 | break; | |
5135 | } | |
721956f4 | 5136 | |
805fc799 AM |
5137 | TOCstart = 0; |
5138 | if (s != NULL) | |
5139 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 5140 | |
805fc799 | 5141 | return TOCstart; |
721956f4 AM |
5142 | } |
5143 | ||
5144 | /* Build all the stubs associated with the current output file. | |
5145 | The stubs are kept in a hash table attached to the main linker | |
5146 | hash table. This function is called via gldelf64ppc_finish. */ | |
5147 | ||
b34976b6 | 5148 | bfd_boolean |
721956f4 AM |
5149 | ppc64_elf_build_stubs (info) |
5150 | struct bfd_link_info *info; | |
5d1634d7 AM |
5151 | { |
5152 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 5153 | asection *stub_sec; |
5d1634d7 AM |
5154 | bfd_vma plt_r2; |
5155 | bfd_byte *p; | |
5156 | ||
721956f4 AM |
5157 | for (stub_sec = htab->stub_bfd->sections; |
5158 | stub_sec != NULL; | |
5159 | stub_sec = stub_sec->next) | |
5160 | { | |
5161 | bfd_size_type size; | |
5162 | ||
5163 | /* Allocate memory to hold the linker stubs. */ | |
5164 | size = stub_sec->_raw_size; | |
5165 | if (size != 0) | |
5166 | { | |
5167 | stub_sec->contents = (bfd_byte *) bfd_zalloc (htab->stub_bfd, size); | |
5168 | if (stub_sec->contents == NULL) | |
b34976b6 | 5169 | return FALSE; |
721956f4 AM |
5170 | } |
5171 | stub_sec->_cooked_size = 0; | |
5172 | } | |
5d1634d7 | 5173 | |
721956f4 | 5174 | if (htab->splt != NULL) |
5d1634d7 | 5175 | { |
9f951329 AM |
5176 | unsigned int indx; |
5177 | ||
721956f4 AM |
5178 | /* Build the .glink plt call stub. */ |
5179 | plt_r2 = (htab->splt->output_offset | |
5180 | + htab->splt->output_section->vma | |
5181 | - elf_gp (htab->splt->output_section->owner) | |
5182 | - TOC_BASE_OFF); | |
5183 | p = htab->sglink->contents; | |
5184 | p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1); | |
9f951329 | 5185 | while (p < htab->sglink->contents + GLINK_CALL_STUB_SIZE) |
721956f4 AM |
5186 | { |
5187 | bfd_put_32 (htab->sglink->owner, NOP, p); | |
5188 | p += 4; | |
5189 | } | |
721956f4 | 5190 | |
9f951329 AM |
5191 | /* Build the .glink lazy link call stubs. */ |
5192 | indx = 0; | |
5193 | while (p < htab->sglink->contents + htab->sglink->_raw_size) | |
5194 | { | |
5195 | if (indx < 0x8000) | |
5196 | { | |
5197 | bfd_put_32 (htab->sglink->owner, LI_R0_0 | indx, p); | |
5198 | p += 4; | |
5199 | } | |
5200 | else | |
5201 | { | |
5202 | bfd_put_32 (htab->sglink->owner, LIS_R0_0 | PPC_HI (indx), p); | |
5203 | p += 4; | |
5204 | bfd_put_32 (htab->sglink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); | |
5205 | p += 4; | |
5206 | } | |
5207 | bfd_put_32 (htab->sglink->owner, | |
5208 | B_DOT | ((htab->sglink->contents - p) & 0x3fffffc), p); | |
a16d5acb | 5209 | indx++; |
9f951329 AM |
5210 | p += 4; |
5211 | } | |
5212 | htab->sglink->_cooked_size = p - htab->sglink->contents; | |
5d1634d7 | 5213 | } |
5d1634d7 | 5214 | |
721956f4 AM |
5215 | if (htab->sbrlt->_raw_size != 0) |
5216 | { | |
5217 | htab->sbrlt->contents = (bfd_byte *) bfd_zalloc (htab->sbrlt->owner, | |
5218 | htab->sbrlt->_raw_size); | |
5219 | if (htab->sbrlt->contents == NULL) | |
b34976b6 | 5220 | return FALSE; |
721956f4 | 5221 | } |
5d1634d7 | 5222 | |
721956f4 AM |
5223 | /* Build the stubs as directed by the stub hash table. */ |
5224 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 5225 | |
721956f4 AM |
5226 | for (stub_sec = htab->stub_bfd->sections; |
5227 | stub_sec != NULL; | |
5228 | stub_sec = stub_sec->next) | |
5229 | { | |
5230 | if (stub_sec->_raw_size != stub_sec->_cooked_size) | |
5231 | break; | |
5232 | } | |
5d1634d7 | 5233 | |
721956f4 | 5234 | if (stub_sec != NULL |
5d1634d7 AM |
5235 | || htab->sglink->_raw_size != htab->sglink->_cooked_size) |
5236 | { | |
b34976b6 | 5237 | htab->stub_error = TRUE; |
721956f4 | 5238 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
5d1634d7 | 5239 | } |
721956f4 AM |
5240 | |
5241 | return !htab->stub_error; | |
5bd4f169 AM |
5242 | } |
5243 | ||
5bd4f169 AM |
5244 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
5245 | to handle the relocations for a section. | |
5246 | ||
5247 | The relocs are always passed as Rela structures; if the section | |
5248 | actually uses Rel structures, the r_addend field will always be | |
5249 | zero. | |
5250 | ||
5251 | This function is responsible for adjust the section contents as | |
5252 | necessary, and (if using Rela relocs and generating a | |
5253 | relocateable output file) adjusting the reloc addend as | |
5254 | necessary. | |
5255 | ||
5256 | This function does not have to worry about setting the reloc | |
5257 | address or the reloc symbol index. | |
5258 | ||
5259 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
5260 | ||
5261 | LOCAL_SECTIONS is an array giving the section in the input file | |
5262 | corresponding to the st_shndx field of each local symbol. | |
5263 | ||
5264 | The global hash table entry for the global symbols can be found | |
5265 | via elf_sym_hashes (input_bfd). | |
5266 | ||
5267 | When generating relocateable output, this function must handle | |
5268 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is | |
5269 | going to be the section symbol corresponding to the output | |
5270 | section, which means that the addend must be adjusted | |
5271 | accordingly. */ | |
5272 | ||
b34976b6 | 5273 | static bfd_boolean |
5bd4f169 AM |
5274 | ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section, |
5275 | contents, relocs, local_syms, local_sections) | |
5276 | bfd *output_bfd; | |
5277 | struct bfd_link_info *info; | |
5278 | bfd *input_bfd; | |
5279 | asection *input_section; | |
5280 | bfd_byte *contents; | |
5281 | Elf_Internal_Rela *relocs; | |
5282 | Elf_Internal_Sym *local_syms; | |
5283 | asection **local_sections; | |
5284 | { | |
65f38f15 | 5285 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
5286 | Elf_Internal_Shdr *symtab_hdr; |
5287 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
5288 | Elf_Internal_Rela *rel; |
5289 | Elf_Internal_Rela *relend; | |
5bd4f169 AM |
5290 | bfd_vma *local_got_offsets; |
5291 | bfd_vma TOCstart; | |
b34976b6 AM |
5292 | bfd_boolean ret = TRUE; |
5293 | bfd_boolean is_opd; | |
96e0dda4 | 5294 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 5295 | bfd_boolean is_power4 = FALSE; |
5bd4f169 | 5296 | |
b491616a | 5297 | if (info->relocateable) |
b34976b6 | 5298 | return TRUE; |
b491616a | 5299 | |
65f38f15 | 5300 | /* Initialize howto table if needed. */ |
5bd4f169 | 5301 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
5302 | ppc_howto_init (); |
5303 | ||
65f38f15 | 5304 | htab = ppc_hash_table (info); |
5bd4f169 | 5305 | local_got_offsets = elf_local_got_offsets (input_bfd); |
5bd4f169 | 5306 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
5307 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
5308 | sym_hashes = elf_sym_hashes (input_bfd); | |
1e2f5b6e | 5309 | is_opd = elf_section_data (input_section)->tdata != NULL; |
65f38f15 | 5310 | |
5bd4f169 AM |
5311 | rel = relocs; |
5312 | relend = relocs + input_section->reloc_count; | |
5313 | for (; rel < relend; rel++) | |
5314 | { | |
5315 | enum elf_ppc_reloc_type r_type; | |
5316 | bfd_vma offset; | |
5317 | bfd_vma addend; | |
5318 | bfd_reloc_status_type r; | |
5319 | Elf_Internal_Sym *sym; | |
5320 | asection *sec; | |
5321 | struct elf_link_hash_entry *h; | |
721956f4 | 5322 | struct elf_link_hash_entry *fdh; |
5bd4f169 | 5323 | const char *sym_name; |
5bd4f169 AM |
5324 | unsigned long r_symndx; |
5325 | bfd_vma relocation; | |
b34976b6 AM |
5326 | bfd_boolean unresolved_reloc; |
5327 | bfd_boolean warned; | |
dc810e39 | 5328 | long insn; |
721956f4 AM |
5329 | struct ppc_stub_hash_entry *stub_entry; |
5330 | bfd_vma max_br_offset; | |
5331 | bfd_vma from; | |
5bd4f169 AM |
5332 | |
5333 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); | |
5bd4f169 | 5334 | r_symndx = ELF64_R_SYM (rel->r_info); |
65f38f15 AM |
5335 | offset = rel->r_offset; |
5336 | addend = rel->r_addend; | |
5337 | r = bfd_reloc_other; | |
5338 | sym = (Elf_Internal_Sym *) 0; | |
5339 | sec = (asection *) 0; | |
5340 | h = (struct elf_link_hash_entry *) 0; | |
5341 | sym_name = (const char *) 0; | |
b34976b6 AM |
5342 | unresolved_reloc = FALSE; |
5343 | warned = FALSE; | |
65f38f15 | 5344 | |
5bd4f169 AM |
5345 | if (r_type == R_PPC64_TOC) |
5346 | { | |
5347 | /* Relocation value is TOC base. Symbol is ignored. */ | |
5348 | relocation = TOCstart + TOC_BASE_OFF; | |
5349 | } | |
5350 | else if (r_symndx < symtab_hdr->sh_info) | |
5351 | { | |
5352 | /* It's a local symbol. */ | |
5353 | sym = local_syms + r_symndx; | |
5354 | sec = local_sections[r_symndx]; | |
5355 | sym_name = "<local symbol>"; | |
5356 | ||
f8df10f4 | 5357 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
f46c2da6 AM |
5358 | /* rel may have changed, update our copy of addend. */ |
5359 | addend = rel->r_addend; | |
1e2f5b6e AM |
5360 | |
5361 | if (elf_section_data (sec) != NULL) | |
5362 | { | |
5363 | long *opd_sym_adjust; | |
5364 | ||
5365 | opd_sym_adjust = (long *) elf_section_data (sec)->tdata; | |
5366 | if (opd_sym_adjust != NULL && sym->st_value % 24 == 0) | |
5367 | relocation += opd_sym_adjust[sym->st_value / 24]; | |
5368 | } | |
5bd4f169 AM |
5369 | } |
5370 | else | |
5371 | { | |
5372 | /* It's a global symbol. */ | |
5373 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5374 | while (h->root.type == bfd_link_hash_indirect | |
5375 | || h->root.type == bfd_link_hash_warning) | |
5376 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5377 | sym_name = h->root.root.string; | |
65f38f15 | 5378 | relocation = 0; |
5bd4f169 AM |
5379 | if (h->root.type == bfd_link_hash_defined |
5380 | || h->root.type == bfd_link_hash_defweak) | |
5381 | { | |
5382 | sec = h->root.u.def.section; | |
65f38f15 AM |
5383 | if (sec->output_section == NULL) |
5384 | /* Set a flag that will be cleared later if we find a | |
5385 | relocation value for this symbol. output_section | |
5386 | is typically NULL for symbols satisfied by a shared | |
5387 | library. */ | |
b34976b6 | 5388 | unresolved_reloc = TRUE; |
5bd4f169 AM |
5389 | else |
5390 | relocation = (h->root.u.def.value | |
5391 | + sec->output_section->vma | |
5392 | + sec->output_offset); | |
5393 | } | |
5394 | else if (h->root.type == bfd_link_hash_undefweak) | |
65f38f15 | 5395 | ; |
671bae9c | 5396 | else if (info->shared |
65f38f15 AM |
5397 | && (!info->symbolic || info->allow_shlib_undefined) |
5398 | && !info->no_undefined | |
5399 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
5400 | ; | |
5bd4f169 AM |
5401 | else |
5402 | { | |
5403 | if (! ((*info->callbacks->undefined_symbol) | |
5404 | (info, h->root.root.string, input_bfd, input_section, | |
65f38f15 AM |
5405 | offset, (!info->shared |
5406 | || info->no_undefined | |
5407 | || ELF_ST_VISIBILITY (h->other))))) | |
b34976b6 AM |
5408 | return FALSE; |
5409 | warned = TRUE; | |
5bd4f169 AM |
5410 | } |
5411 | } | |
5412 | ||
65f38f15 | 5413 | /* First handle relocations that tweak non-addend part of insn. */ |
86c76c7b | 5414 | insn = 0; |
65f38f15 | 5415 | switch (r_type) |
5bd4f169 AM |
5416 | { |
5417 | default: | |
65f38f15 | 5418 | break; |
5bd4f169 | 5419 | |
65f38f15 AM |
5420 | /* Branch taken prediction relocations. */ |
5421 | case R_PPC64_ADDR14_BRTAKEN: | |
5422 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
5423 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
5424 | /* Fall thru. */ | |
65f38f15 | 5425 | |
86c76c7b | 5426 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
5427 | case R_PPC64_ADDR14_BRNTAKEN: |
5428 | case R_PPC64_REL14_BRNTAKEN: | |
86c76c7b | 5429 | insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21); |
96e0dda4 AM |
5430 | if (is_power4) |
5431 | { | |
5432 | /* Set 'a' bit. This is 0b00010 in BO field for branch | |
5433 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
5434 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
5435 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
5436 | insn |= 0x02 << 21; | |
5437 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
5438 | insn |= 0x08 << 21; | |
5439 | else | |
5440 | break; | |
5441 | } | |
65f38f15 | 5442 | else |
96e0dda4 | 5443 | { |
805fc799 AM |
5444 | from = (offset |
5445 | + input_section->output_offset | |
5446 | + input_section->output_section->vma); | |
5447 | ||
96e0dda4 | 5448 | /* Invert 'y' bit if not the default. */ |
805fc799 | 5449 | if ((bfd_signed_vma) (relocation + addend - from) < 0) |
96e0dda4 AM |
5450 | insn ^= 0x01 << 21; |
5451 | } | |
86c76c7b | 5452 | |
65f38f15 AM |
5453 | bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset); |
5454 | break; | |
5bd4f169 | 5455 | |
65f38f15 | 5456 | case R_PPC64_REL24: |
721956f4 AM |
5457 | /* A REL24 branching to a linkage function is followed by a |
5458 | nop. We replace the nop with a ld in order to restore | |
5459 | the TOC base pointer. Only calls to shared objects need | |
5460 | to alter the TOC base. These are recognized by their | |
5461 | need for a PLT entry. */ | |
5bd4f169 | 5462 | if (h != NULL |
721956f4 AM |
5463 | && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL |
5464 | && fdh->plt.offset != (bfd_vma) -1 | |
5465 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, | |
5466 | rel, htab)) != NULL) | |
41bd81ab | 5467 | { |
b34976b6 | 5468 | bfd_boolean can_plt_call = 0; |
721956f4 | 5469 | |
41bd81ab AM |
5470 | if (offset + 8 <= input_section->_cooked_size) |
5471 | { | |
721956f4 AM |
5472 | insn = bfd_get_32 (input_bfd, contents + offset + 4); |
5473 | if (insn == NOP | |
5474 | || insn == CROR_151515 || insn == CROR_313131) | |
41bd81ab | 5475 | { |
721956f4 AM |
5476 | bfd_put_32 (input_bfd, (bfd_vma) LD_R2_40R1, |
5477 | contents + offset + 4); | |
5478 | can_plt_call = 1; | |
41bd81ab | 5479 | } |
5bd4f169 | 5480 | } |
721956f4 AM |
5481 | |
5482 | if (!can_plt_call) | |
5483 | { | |
5484 | /* If this is a plain branch rather than a branch | |
5485 | and link, don't require a nop. */ | |
5486 | insn = bfd_get_32 (input_bfd, contents + offset); | |
5487 | if ((insn & 1) == 0) | |
5488 | can_plt_call = 1; | |
5489 | } | |
5490 | ||
5491 | if (can_plt_call) | |
5492 | { | |
5493 | relocation = (stub_entry->stub_offset | |
5494 | + stub_entry->stub_sec->output_offset | |
5495 | + stub_entry->stub_sec->output_section->vma); | |
5496 | addend = 0; | |
b34976b6 | 5497 | unresolved_reloc = FALSE; |
721956f4 | 5498 | } |
5bd4f169 | 5499 | } |
e86ce104 AM |
5500 | |
5501 | if (h != NULL | |
5502 | && h->root.type == bfd_link_hash_undefweak | |
721956f4 AM |
5503 | && relocation == 0 |
5504 | && addend == 0) | |
e86ce104 | 5505 | { |
721956f4 AM |
5506 | /* Tweak calls to undefined weak functions to point at a |
5507 | blr. We can thus call a weak function without first | |
5508 | checking whether the function is defined. We have a | |
5509 | blr at the end of .sfpr. */ | |
805fc799 | 5510 | BFD_ASSERT (htab->sfpr->_raw_size != 0); |
721956f4 AM |
5511 | relocation = (htab->sfpr->_raw_size - 4 |
5512 | + htab->sfpr->output_offset | |
5513 | + htab->sfpr->output_section->vma); | |
5514 | from = (offset | |
5515 | + input_section->output_offset | |
5516 | + input_section->output_section->vma); | |
805fc799 | 5517 | |
721956f4 AM |
5518 | /* But let's not be silly about it. If the blr isn't in |
5519 | reach, just go to the next instruction. */ | |
805fc799 AM |
5520 | if (relocation - from + (1 << 25) >= (1 << 26) |
5521 | || htab->sfpr->_raw_size == 0) | |
721956f4 | 5522 | relocation = from + 4; |
e86ce104 | 5523 | } |
65f38f15 AM |
5524 | break; |
5525 | } | |
5bd4f169 | 5526 | |
65f38f15 AM |
5527 | /* Set `addend'. */ |
5528 | switch (r_type) | |
5529 | { | |
5530 | default: | |
5531 | (*_bfd_error_handler) | |
5532 | (_("%s: unknown relocation type %d for symbol %s"), | |
5533 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); | |
5bd4f169 | 5534 | |
65f38f15 | 5535 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 5536 | ret = FALSE; |
65f38f15 | 5537 | continue; |
5bd4f169 | 5538 | |
65f38f15 AM |
5539 | case R_PPC64_NONE: |
5540 | case R_PPC_GNU_VTINHERIT: | |
5541 | case R_PPC_GNU_VTENTRY: | |
5542 | continue; | |
5bd4f169 AM |
5543 | |
5544 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
5545 | address in the GOT as relocation value instead of the | |
5546 | symbols value itself. Also, create a GOT entry for the | |
5547 | symbol and put the symbol value there. */ | |
65f38f15 AM |
5548 | case R_PPC64_GOT16: |
5549 | case R_PPC64_GOT16_LO: | |
5550 | case R_PPC64_GOT16_HI: | |
5551 | case R_PPC64_GOT16_HA: | |
5552 | case R_PPC64_GOT16_DS: | |
5553 | case R_PPC64_GOT16_LO_DS: | |
5bd4f169 AM |
5554 | { |
5555 | /* Relocation is to the entry for this symbol in the global | |
5556 | offset table. */ | |
5557 | bfd_vma off; | |
65f38f15 AM |
5558 | |
5559 | if (htab->sgot == NULL) | |
5560 | abort (); | |
5bd4f169 AM |
5561 | |
5562 | if (h != NULL) | |
5563 | { | |
b34976b6 | 5564 | bfd_boolean dyn; |
5bd4f169 | 5565 | |
65f38f15 AM |
5566 | off = h->got.offset; |
5567 | dyn = htab->elf.dynamic_sections_created; | |
5568 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) | |
5bd4f169 | 5569 | || (info->shared |
65f38f15 AM |
5570 | && (info->symbolic |
5571 | || h->dynindx == -1 | |
5572 | || (h->elf_link_hash_flags | |
5573 | & ELF_LINK_FORCED_LOCAL)) | |
5bd4f169 AM |
5574 | && (h->elf_link_hash_flags |
5575 | & ELF_LINK_HASH_DEF_REGULAR))) | |
5576 | { | |
5577 | /* This is actually a static link, or it is a | |
5578 | -Bsymbolic link and the symbol is defined | |
65f38f15 AM |
5579 | locally, or the symbol was forced to be local |
5580 | because of a version file. We must initialize | |
5581 | this entry in the global offset table. Since the | |
5582 | offset must always be a multiple of 8, we use the | |
5583 | least significant bit to record whether we have | |
5bd4f169 AM |
5584 | initialized it already. |
5585 | ||
65f38f15 | 5586 | When doing a dynamic link, we create a .rel.got |
5bd4f169 AM |
5587 | relocation entry to initialize the value. This |
5588 | is done in the finish_dynamic_symbol routine. */ | |
5589 | if ((off & 1) != 0) | |
5590 | off &= ~1; | |
5591 | else | |
5592 | { | |
5593 | bfd_put_64 (output_bfd, relocation, | |
65f38f15 | 5594 | htab->sgot->contents + off); |
5bd4f169 AM |
5595 | h->got.offset |= 1; |
5596 | } | |
5597 | } | |
65f38f15 | 5598 | else |
b34976b6 | 5599 | unresolved_reloc = FALSE; |
5bd4f169 AM |
5600 | } |
5601 | else | |
5602 | { | |
65f38f15 AM |
5603 | if (local_got_offsets == NULL) |
5604 | abort (); | |
5bd4f169 AM |
5605 | |
5606 | off = local_got_offsets[r_symndx]; | |
5607 | ||
65f38f15 | 5608 | /* The offset must always be a multiple of 8. We use |
5bd4f169 AM |
5609 | the least significant bit to record whether we have |
5610 | already processed this entry. */ | |
5611 | if ((off & 1) != 0) | |
5612 | off &= ~1; | |
5613 | else | |
5614 | { | |
65f38f15 AM |
5615 | bfd_put_64 (output_bfd, relocation, |
5616 | htab->sgot->contents + off); | |
5bd4f169 AM |
5617 | |
5618 | if (info->shared) | |
5619 | { | |
5bd4f169 | 5620 | Elf_Internal_Rela outrel; |
947216bf | 5621 | bfd_byte *loc; |
5bd4f169 AM |
5622 | |
5623 | /* We need to generate a R_PPC64_RELATIVE reloc | |
5624 | for the dynamic linker. */ | |
65f38f15 AM |
5625 | outrel.r_offset = (htab->sgot->output_section->vma |
5626 | + htab->sgot->output_offset | |
5bd4f169 AM |
5627 | + off); |
5628 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
5629 | outrel.r_addend = relocation; | |
947216bf AM |
5630 | loc = htab->srelgot->contents; |
5631 | loc += (htab->srelgot->reloc_count++ | |
5632 | * sizeof (Elf64_External_Rela)); | |
65f38f15 | 5633 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
5bd4f169 AM |
5634 | } |
5635 | ||
5636 | local_got_offsets[r_symndx] |= 1; | |
5637 | } | |
5638 | } | |
5639 | ||
65f38f15 AM |
5640 | if (off >= (bfd_vma) -2) |
5641 | abort (); | |
5642 | ||
5643 | relocation = htab->sgot->output_offset + off; | |
5644 | ||
5bd4f169 AM |
5645 | /* TOC base (r2) is TOC start plus 0x8000. */ |
5646 | addend -= TOC_BASE_OFF; | |
5bd4f169 | 5647 | } |
65f38f15 AM |
5648 | break; |
5649 | ||
5650 | case R_PPC64_PLT16_HA: | |
5651 | case R_PPC64_PLT16_HI: | |
5652 | case R_PPC64_PLT16_LO: | |
5653 | case R_PPC64_PLT32: | |
5654 | case R_PPC64_PLT64: | |
5655 | /* Relocation is to the entry for this symbol in the | |
5656 | procedure linkage table. */ | |
5657 | ||
5658 | /* Resolve a PLT reloc against a local symbol directly, | |
5659 | without using the procedure linkage table. */ | |
5660 | if (h == NULL) | |
5661 | break; | |
5662 | ||
5663 | if (h->plt.offset == (bfd_vma) -1 | |
5664 | || htab->splt == NULL) | |
5665 | { | |
5666 | /* We didn't make a PLT entry for this symbol. This | |
5667 | happens when statically linking PIC code, or when | |
5668 | using -Bsymbolic. */ | |
5669 | break; | |
5670 | } | |
5671 | ||
5672 | relocation = (htab->splt->output_section->vma | |
5673 | + htab->splt->output_offset | |
5674 | + h->plt.offset); | |
b34976b6 | 5675 | unresolved_reloc = FALSE; |
65f38f15 | 5676 | break; |
5bd4f169 AM |
5677 | |
5678 | /* TOC16 relocs. We want the offset relative to the TOC base, | |
5679 | which is the address of the start of the TOC plus 0x8000. | |
5680 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
5681 | in this order. */ | |
65f38f15 AM |
5682 | case R_PPC64_TOC16: |
5683 | case R_PPC64_TOC16_LO: | |
5684 | case R_PPC64_TOC16_HI: | |
5685 | case R_PPC64_TOC16_DS: | |
5686 | case R_PPC64_TOC16_LO_DS: | |
5687 | case R_PPC64_TOC16_HA: | |
5bd4f169 | 5688 | addend -= TOCstart + TOC_BASE_OFF; |
5bd4f169 AM |
5689 | break; |
5690 | ||
5691 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
5692 | case R_PPC64_SECTOFF: |
5693 | case R_PPC64_SECTOFF_LO: | |
5694 | case R_PPC64_SECTOFF_HI: | |
5695 | case R_PPC64_SECTOFF_DS: | |
5696 | case R_PPC64_SECTOFF_LO_DS: | |
5697 | case R_PPC64_SECTOFF_HA: | |
5698 | if (sec != (asection *) 0) | |
5699 | addend -= sec->output_section->vma; | |
5bd4f169 AM |
5700 | break; |
5701 | ||
721956f4 AM |
5702 | case R_PPC64_REL14: |
5703 | case R_PPC64_REL14_BRNTAKEN: | |
5704 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
5705 | case R_PPC64_REL24: |
5706 | break; | |
5707 | ||
65f38f15 AM |
5708 | /* Relocations that may need to be propagated if this is a |
5709 | dynamic object. */ | |
65f38f15 AM |
5710 | case R_PPC64_REL32: |
5711 | case R_PPC64_REL64: | |
5712 | case R_PPC64_ADDR14: | |
5713 | case R_PPC64_ADDR14_BRNTAKEN: | |
5714 | case R_PPC64_ADDR14_BRTAKEN: | |
5715 | case R_PPC64_ADDR16: | |
5716 | case R_PPC64_ADDR16_DS: | |
5717 | case R_PPC64_ADDR16_HA: | |
5718 | case R_PPC64_ADDR16_HI: | |
5719 | case R_PPC64_ADDR16_HIGHER: | |
5720 | case R_PPC64_ADDR16_HIGHERA: | |
5721 | case R_PPC64_ADDR16_HIGHEST: | |
5722 | case R_PPC64_ADDR16_HIGHESTA: | |
5723 | case R_PPC64_ADDR16_LO: | |
5724 | case R_PPC64_ADDR16_LO_DS: | |
5725 | case R_PPC64_ADDR24: | |
5726 | case R_PPC64_ADDR30: | |
5727 | case R_PPC64_ADDR32: | |
5728 | case R_PPC64_ADDR64: | |
5729 | case R_PPC64_UADDR16: | |
5730 | case R_PPC64_UADDR32: | |
5731 | case R_PPC64_UADDR64: | |
ec338859 AM |
5732 | /* r_symndx will be zero only for relocs against symbols |
5733 | from removed linkonce sections, or sections discarded by | |
5734 | a linker script. */ | |
5d1634d7 AM |
5735 | if (r_symndx == 0) |
5736 | break; | |
5737 | /* Fall thru. */ | |
5738 | ||
5739 | case R_PPC64_TOC: | |
5740 | if ((input_section->flags & SEC_ALLOC) == 0) | |
ec338859 AM |
5741 | break; |
5742 | ||
41bd81ab AM |
5743 | if (NO_OPD_RELOCS && is_opd) |
5744 | break; | |
5745 | ||
65f38f15 | 5746 | if ((info->shared |
65f38f15 AM |
5747 | && (IS_ABSOLUTE_RELOC (r_type) |
5748 | || (h != NULL | |
5749 | && h->dynindx != -1 | |
5750 | && (! info->symbolic | |
5751 | || (h->elf_link_hash_flags | |
5752 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
5753 | || (!info->shared | |
65f38f15 AM |
5754 | && h != NULL |
5755 | && h->dynindx != -1 | |
5756 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
5757 | && (((h->elf_link_hash_flags | |
5758 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
5759 | && (h->elf_link_hash_flags | |
5760 | & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
5761 | || h->root.type == bfd_link_hash_undefweak | |
5762 | || h->root.type == bfd_link_hash_undefined))) | |
5763 | { | |
5764 | Elf_Internal_Rela outrel; | |
b34976b6 | 5765 | bfd_boolean skip, relocate; |
65f38f15 | 5766 | asection *sreloc; |
947216bf | 5767 | bfd_byte *loc; |
65f38f15 AM |
5768 | |
5769 | /* When generating a dynamic object, these relocations | |
5770 | are copied into the output file to be resolved at run | |
5771 | time. */ | |
5772 | ||
b34976b6 AM |
5773 | skip = FALSE; |
5774 | relocate = FALSE; | |
65f38f15 | 5775 | |
c629eae0 JJ |
5776 | outrel.r_offset = |
5777 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
5778 | rel->r_offset); | |
5779 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 5780 | skip = TRUE; |
0bb2d96a | 5781 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 5782 | skip = TRUE, relocate = TRUE; |
65f38f15 AM |
5783 | outrel.r_offset += (input_section->output_section->vma |
5784 | + input_section->output_offset); | |
5785 | outrel.r_addend = addend; | |
5786 | ||
5787 | if (skip) | |
0bb2d96a | 5788 | memset (&outrel, 0, sizeof outrel); |
65f38f15 AM |
5789 | else if (h != NULL |
5790 | && h->dynindx != -1 | |
41bd81ab | 5791 | && !is_opd |
65f38f15 AM |
5792 | && (!IS_ABSOLUTE_RELOC (r_type) |
5793 | || !info->shared | |
5794 | || !info->symbolic | |
5795 | || (h->elf_link_hash_flags | |
5796 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
0bb2d96a | 5797 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
65f38f15 AM |
5798 | else |
5799 | { | |
41bd81ab AM |
5800 | /* This symbol is local, or marked to become local, |
5801 | or this is an opd section reloc which must point | |
5802 | at a local function. */ | |
65f38f15 | 5803 | outrel.r_addend += relocation; |
b34976b6 | 5804 | relocate = TRUE; |
e86ce104 | 5805 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 5806 | { |
3fad3c7c | 5807 | if (is_opd && h != NULL) |
afbe61cf AM |
5808 | { |
5809 | /* Lie about opd entries. This case occurs | |
5810 | when building shared libraries and we | |
5811 | reference a function in another shared | |
3fad3c7c AM |
5812 | lib. The same thing happens for a weak |
5813 | definition in an application that's | |
5814 | overridden by a strong definition in a | |
5815 | shared lib. (I believe this is a generic | |
5816 | bug in binutils handling of weak syms.) | |
5817 | In these cases we won't use the opd | |
1e2f5b6e | 5818 | entry in this lib. */ |
b34976b6 | 5819 | unresolved_reloc = FALSE; |
afbe61cf | 5820 | } |
65f38f15 AM |
5821 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
5822 | } | |
5823 | else | |
5824 | { | |
5825 | long indx = 0; | |
5826 | ||
41bd81ab | 5827 | if (bfd_is_abs_section (sec)) |
65f38f15 AM |
5828 | ; |
5829 | else if (sec == NULL || sec->owner == NULL) | |
5830 | { | |
5831 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5832 | return FALSE; |
65f38f15 AM |
5833 | } |
5834 | else | |
5835 | { | |
5836 | asection *osec; | |
5837 | ||
5838 | osec = sec->output_section; | |
5839 | indx = elf_section_data (osec)->dynindx; | |
5840 | ||
5841 | /* We are turning this relocation into one | |
5842 | against a section symbol, so subtract out | |
5843 | the output section's address but not the | |
5844 | offset of the input section in the output | |
5845 | section. */ | |
5846 | outrel.r_addend -= osec->vma; | |
5847 | } | |
5848 | ||
5849 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
5850 | } | |
5851 | } | |
5852 | ||
5853 | sreloc = elf_section_data (input_section)->sreloc; | |
5854 | if (sreloc == NULL) | |
5855 | abort (); | |
5856 | ||
947216bf AM |
5857 | loc = sreloc->contents; |
5858 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
5859 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
5860 | ||
5861 | /* If this reloc is against an external symbol, it will | |
5862 | be computed at runtime, so there's no need to do | |
5863 | anything now. */ | |
5864 | if (! relocate) | |
5865 | continue; | |
5866 | } | |
5bd4f169 AM |
5867 | break; |
5868 | ||
65f38f15 AM |
5869 | case R_PPC64_COPY: |
5870 | case R_PPC64_GLOB_DAT: | |
5871 | case R_PPC64_JMP_SLOT: | |
5872 | case R_PPC64_RELATIVE: | |
5873 | /* We shouldn't ever see these dynamic relocs in relocatable | |
5874 | files. */ | |
5875 | /* Fall thru */ | |
5876 | ||
5877 | case R_PPC64_PLTGOT16: | |
5878 | case R_PPC64_PLTGOT16_DS: | |
5879 | case R_PPC64_PLTGOT16_HA: | |
5880 | case R_PPC64_PLTGOT16_HI: | |
5881 | case R_PPC64_PLTGOT16_LO: | |
5882 | case R_PPC64_PLTGOT16_LO_DS: | |
5883 | case R_PPC64_PLTREL32: | |
5884 | case R_PPC64_PLTREL64: | |
5885 | /* These ones haven't been implemented yet. */ | |
5886 | ||
5887 | (*_bfd_error_handler) | |
5888 | (_("%s: Relocation %s is not supported for symbol %s."), | |
5889 | bfd_archive_filename (input_bfd), | |
5890 | ppc64_elf_howto_table[(int) r_type]->name, sym_name); | |
5bd4f169 AM |
5891 | |
5892 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 5893 | ret = FALSE; |
5bd4f169 | 5894 | continue; |
65f38f15 | 5895 | } |
5bd4f169 | 5896 | |
65f38f15 AM |
5897 | /* Do any further special processing. */ |
5898 | switch (r_type) | |
5899 | { | |
5900 | default: | |
5901 | break; | |
5902 | ||
5903 | case R_PPC64_ADDR16_HA: | |
5904 | case R_PPC64_ADDR16_HIGHERA: | |
5905 | case R_PPC64_ADDR16_HIGHESTA: | |
5906 | case R_PPC64_PLT16_HA: | |
5907 | case R_PPC64_TOC16_HA: | |
5908 | case R_PPC64_SECTOFF_HA: | |
5909 | /* It's just possible that this symbol is a weak symbol | |
5910 | that's not actually defined anywhere. In that case, | |
5911 | 'sec' would be NULL, and we should leave the symbol | |
5912 | alone (it will be set to zero elsewhere in the link). */ | |
5913 | if (sec != NULL) | |
5914 | /* Add 0x10000 if sign bit in 0:15 is set. */ | |
5915 | addend += ((relocation + addend) & 0x8000) << 1; | |
5916 | break; | |
5917 | ||
5918 | case R_PPC64_ADDR16_DS: | |
5919 | case R_PPC64_ADDR16_LO_DS: | |
5920 | case R_PPC64_GOT16_DS: | |
5921 | case R_PPC64_GOT16_LO_DS: | |
5922 | case R_PPC64_PLT16_LO_DS: | |
5923 | case R_PPC64_SECTOFF_DS: | |
5924 | case R_PPC64_SECTOFF_LO_DS: | |
5925 | case R_PPC64_TOC16_DS: | |
5926 | case R_PPC64_TOC16_LO_DS: | |
5927 | case R_PPC64_PLTGOT16_DS: | |
5928 | case R_PPC64_PLTGOT16_LO_DS: | |
5929 | if (((relocation + addend) & 3) != 0) | |
5930 | { | |
5931 | (*_bfd_error_handler) | |
5932 | (_("%s: error: relocation %s not a multiple of 4"), | |
5933 | bfd_archive_filename (input_bfd), | |
5934 | ppc64_elf_howto_table[(int) r_type]->name); | |
5935 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5936 | ret = FALSE; |
65f38f15 AM |
5937 | continue; |
5938 | } | |
5939 | break; | |
721956f4 AM |
5940 | |
5941 | case R_PPC64_REL14: | |
5942 | case R_PPC64_REL14_BRNTAKEN: | |
5943 | case R_PPC64_REL14_BRTAKEN: | |
5944 | max_br_offset = 1 << 15; | |
5945 | goto branch_check; | |
5946 | ||
5947 | case R_PPC64_REL24: | |
5948 | max_br_offset = 1 << 25; | |
5949 | ||
5950 | branch_check: | |
5951 | /* If the branch is out of reach, then redirect the | |
5952 | call to the local stub for this function. */ | |
5953 | from = (offset | |
5954 | + input_section->output_offset | |
5955 | + input_section->output_section->vma); | |
5956 | if (relocation + addend - from + max_br_offset >= 2 * max_br_offset | |
5957 | && (stub_entry = ppc_get_stub_entry (input_section, sec, h, | |
5958 | rel, htab)) != NULL) | |
5959 | { | |
5960 | /* Munge up the value and addend so that we call the stub | |
5961 | rather than the procedure directly. */ | |
5962 | relocation = (stub_entry->stub_offset | |
5963 | + stub_entry->stub_sec->output_offset | |
5964 | + stub_entry->stub_sec->output_section->vma); | |
5965 | addend = 0; | |
5966 | } | |
5967 | break; | |
5bd4f169 AM |
5968 | } |
5969 | ||
239e1f3a AM |
5970 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
5971 | because such sections are not SEC_ALLOC and thus ld.so will | |
5972 | not process them. */ | |
65f38f15 | 5973 | if (unresolved_reloc |
239e1f3a | 5974 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
65f38f15 | 5975 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
9c07fe7c AM |
5976 | { |
5977 | (*_bfd_error_handler) | |
5978 | (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"), | |
5979 | bfd_archive_filename (input_bfd), | |
5980 | bfd_get_section_name (input_bfd, input_section), | |
5981 | (long) rel->r_offset, | |
5982 | h->root.root.string); | |
b34976b6 | 5983 | ret = FALSE; |
9c07fe7c | 5984 | } |
5bd4f169 | 5985 | |
65f38f15 | 5986 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
5987 | input_bfd, |
5988 | input_section, | |
5989 | contents, | |
5990 | offset, | |
5991 | relocation, | |
5992 | addend); | |
5993 | ||
ef60b7ff | 5994 | if (r != bfd_reloc_ok) |
5bd4f169 AM |
5995 | { |
5996 | const char *name; | |
5997 | ||
5998 | if (h != NULL) | |
5999 | { | |
6000 | if (h->root.type == bfd_link_hash_undefweak | |
65f38f15 | 6001 | && ppc64_elf_howto_table[(int) r_type]->pc_relative) |
5bd4f169 AM |
6002 | { |
6003 | /* Assume this is a call protected by other code that | |
6004 | detects the symbol is undefined. If this is the case, | |
6005 | we can safely ignore the overflow. If not, the | |
6006 | program is hosed anyway, and a little warning isn't | |
6007 | going to help. */ | |
6008 | ||
6009 | continue; | |
6010 | } | |
6011 | ||
6012 | name = h->root.root.string; | |
6013 | } | |
6014 | else | |
6015 | { | |
6016 | name = bfd_elf_string_from_elf_section (input_bfd, | |
6017 | symtab_hdr->sh_link, | |
6018 | sym->st_name); | |
6019 | if (name == NULL) | |
6020 | continue; | |
6021 | if (*name == '\0') | |
6022 | name = bfd_section_name (input_bfd, sec); | |
6023 | } | |
6024 | ||
ef60b7ff AM |
6025 | if (r == bfd_reloc_overflow) |
6026 | { | |
6027 | if (warned) | |
6028 | continue; | |
6029 | if (!((*info->callbacks->reloc_overflow) | |
6030 | (info, name, ppc64_elf_howto_table[(int) r_type]->name, | |
6031 | rel->r_addend, input_bfd, input_section, offset))) | |
b34976b6 | 6032 | return FALSE; |
ef60b7ff AM |
6033 | } |
6034 | else | |
6035 | { | |
6036 | (*_bfd_error_handler) | |
6037 | (_("%s(%s+0x%lx): reloc against `%s': error %d"), | |
6038 | bfd_archive_filename (input_bfd), | |
6039 | bfd_get_section_name (input_bfd, input_section), | |
6040 | (long) rel->r_offset, name, (int) r); | |
b34976b6 | 6041 | ret = FALSE; |
ef60b7ff | 6042 | } |
5bd4f169 | 6043 | } |
5bd4f169 AM |
6044 | } |
6045 | ||
5bd4f169 AM |
6046 | return ret; |
6047 | } | |
6048 | ||
6049 | /* Finish up dynamic symbol handling. We set the contents of various | |
6050 | dynamic sections here. */ | |
6051 | ||
b34976b6 | 6052 | static bfd_boolean |
5bd4f169 AM |
6053 | ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym) |
6054 | bfd *output_bfd; | |
6055 | struct bfd_link_info *info; | |
6056 | struct elf_link_hash_entry *h; | |
6057 | Elf_Internal_Sym *sym; | |
6058 | { | |
65f38f15 | 6059 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
6060 | bfd *dynobj; |
6061 | ||
65f38f15 AM |
6062 | htab = ppc_hash_table (info); |
6063 | dynobj = htab->elf.dynobj; | |
5bd4f169 | 6064 | |
41bd81ab AM |
6065 | if (h->plt.offset != (bfd_vma) -1 |
6066 | && ((struct ppc_link_hash_entry *) h)->is_func_descriptor) | |
5bd4f169 | 6067 | { |
65f38f15 | 6068 | Elf_Internal_Rela rela; |
947216bf | 6069 | bfd_byte *loc; |
5bd4f169 AM |
6070 | |
6071 | /* This symbol has an entry in the procedure linkage table. Set | |
3fad3c7c | 6072 | it up. */ |
5bd4f169 | 6073 | |
5d1634d7 | 6074 | if (htab->splt == NULL |
65f38f15 | 6075 | || htab->srelplt == NULL |
e86ce104 | 6076 | || htab->sglink == NULL) |
65f38f15 AM |
6077 | abort (); |
6078 | ||
65f38f15 AM |
6079 | /* Create a JMP_SLOT reloc to inform the dynamic linker to |
6080 | fill in the PLT entry. */ | |
5bd4f169 | 6081 | |
65f38f15 AM |
6082 | rela.r_offset = (htab->splt->output_section->vma |
6083 | + htab->splt->output_offset | |
6084 | + h->plt.offset); | |
e86ce104 | 6085 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); |
65f38f15 AM |
6086 | rela.r_addend = 0; |
6087 | ||
947216bf AM |
6088 | loc = htab->srelplt->contents; |
6089 | loc += ((h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE | |
6090 | * sizeof (Elf64_External_Rela)); | |
65f38f15 | 6091 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
6092 | } |
6093 | ||
6094 | if (h->got.offset != (bfd_vma) -1) | |
6095 | { | |
5bd4f169 | 6096 | Elf_Internal_Rela rela; |
947216bf | 6097 | bfd_byte *loc; |
5bd4f169 AM |
6098 | |
6099 | /* This symbol has an entry in the global offset table. Set it | |
3fad3c7c | 6100 | up. */ |
5bd4f169 | 6101 | |
65f38f15 AM |
6102 | if (htab->sgot == NULL || htab->srelgot == NULL) |
6103 | abort (); | |
5bd4f169 | 6104 | |
65f38f15 AM |
6105 | rela.r_offset = (htab->sgot->output_section->vma |
6106 | + htab->sgot->output_offset | |
dc810e39 | 6107 | + (h->got.offset &~ (bfd_vma) 1)); |
5bd4f169 | 6108 | |
65f38f15 AM |
6109 | /* If this is a static link, or it is a -Bsymbolic link and the |
6110 | symbol is defined locally or was forced to be local because | |
6111 | of a version file, we just want to emit a RELATIVE reloc. | |
6112 | The entry in the global offset table will already have been | |
6113 | initialized in the relocate_section function. */ | |
5bd4f169 | 6114 | if (info->shared |
65f38f15 AM |
6115 | && (info->symbolic |
6116 | || h->dynindx == -1 | |
6117 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) | |
5bd4f169 AM |
6118 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) |
6119 | { | |
65f38f15 | 6120 | BFD_ASSERT((h->got.offset & 1) != 0); |
5bd4f169 AM |
6121 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
6122 | rela.r_addend = (h->root.u.def.value | |
6123 | + h->root.u.def.section->output_section->vma | |
6124 | + h->root.u.def.section->output_offset); | |
6125 | } | |
6126 | else | |
6127 | { | |
6128 | BFD_ASSERT ((h->got.offset & 1) == 0); | |
65f38f15 AM |
6129 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
6130 | htab->sgot->contents + h->got.offset); | |
5bd4f169 AM |
6131 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT); |
6132 | rela.r_addend = 0; | |
6133 | } | |
6134 | ||
947216bf AM |
6135 | loc = htab->srelgot->contents; |
6136 | loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 6137 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
6138 | } |
6139 | ||
6140 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
6141 | { | |
5bd4f169 | 6142 | Elf_Internal_Rela rela; |
947216bf | 6143 | bfd_byte *loc; |
5bd4f169 | 6144 | |
65f38f15 | 6145 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 6146 | |
65f38f15 AM |
6147 | if (h->dynindx == -1 |
6148 | || (h->root.type != bfd_link_hash_defined | |
6149 | && h->root.type != bfd_link_hash_defweak) | |
6150 | || htab->srelbss == NULL) | |
6151 | abort (); | |
5bd4f169 AM |
6152 | |
6153 | rela.r_offset = (h->root.u.def.value | |
6154 | + h->root.u.def.section->output_section->vma | |
6155 | + h->root.u.def.section->output_offset); | |
6156 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
6157 | rela.r_addend = 0; | |
947216bf AM |
6158 | loc = htab->srelbss->contents; |
6159 | loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 6160 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
6161 | } |
6162 | ||
5bd4f169 AM |
6163 | /* Mark some specially defined symbols as absolute. */ |
6164 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
6165 | sym->st_shndx = SHN_ABS; | |
6166 | ||
b34976b6 | 6167 | return TRUE; |
5bd4f169 AM |
6168 | } |
6169 | ||
65f38f15 AM |
6170 | /* Used to decide how to sort relocs in an optimal manner for the |
6171 | dynamic linker, before writing them out. */ | |
6172 | ||
6173 | static enum elf_reloc_type_class | |
6174 | ppc64_elf_reloc_type_class (rela) | |
6175 | const Elf_Internal_Rela *rela; | |
6176 | { | |
a33d1f77 AM |
6177 | enum elf_ppc_reloc_type r_type; |
6178 | ||
6179 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info); | |
6180 | switch (r_type) | |
65f38f15 AM |
6181 | { |
6182 | case R_PPC64_RELATIVE: | |
6183 | return reloc_class_relative; | |
6184 | case R_PPC64_JMP_SLOT: | |
6185 | return reloc_class_plt; | |
6186 | case R_PPC64_COPY: | |
6187 | return reloc_class_copy; | |
6188 | default: | |
6189 | return reloc_class_normal; | |
6190 | } | |
6191 | } | |
6192 | ||
5bd4f169 AM |
6193 | /* Finish up the dynamic sections. */ |
6194 | ||
b34976b6 | 6195 | static bfd_boolean |
5bd4f169 AM |
6196 | ppc64_elf_finish_dynamic_sections (output_bfd, info) |
6197 | bfd *output_bfd; | |
6198 | struct bfd_link_info *info; | |
6199 | { | |
65f38f15 AM |
6200 | struct ppc_link_hash_table *htab; |
6201 | bfd *dynobj; | |
5bd4f169 | 6202 | asection *sdyn; |
5bd4f169 | 6203 | |
65f38f15 AM |
6204 | htab = ppc_hash_table (info); |
6205 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
6206 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
6207 | ||
65f38f15 | 6208 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 6209 | { |
5bd4f169 AM |
6210 | Elf64_External_Dyn *dyncon, *dynconend; |
6211 | ||
65f38f15 AM |
6212 | if (sdyn == NULL || htab->sgot == NULL) |
6213 | abort (); | |
5bd4f169 AM |
6214 | |
6215 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
6216 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
6217 | for (; dyncon < dynconend; dyncon++) | |
6218 | { | |
6219 | Elf_Internal_Dyn dyn; | |
19397422 | 6220 | asection *s; |
5bd4f169 AM |
6221 | |
6222 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
6223 | ||
6224 | switch (dyn.d_tag) | |
6225 | { | |
65f38f15 AM |
6226 | default: |
6227 | continue; | |
5bd4f169 | 6228 | |
5d1634d7 AM |
6229 | case DT_PPC64_GLINK: |
6230 | dyn.d_un.d_ptr = (htab->sglink->output_section->vma | |
6231 | + htab->sglink->output_offset); | |
6232 | break; | |
6233 | ||
19397422 AM |
6234 | case DT_PPC64_OPD: |
6235 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6236 | if (s != NULL) | |
6237 | dyn.d_un.d_ptr = s->vma; | |
6238 | break; | |
6239 | ||
6240 | case DT_PPC64_OPDSZ: | |
6241 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6242 | if (s != NULL) | |
6243 | dyn.d_un.d_val = s->_raw_size; | |
6244 | break; | |
6245 | ||
65f38f15 | 6246 | case DT_PLTGOT: |
5d1634d7 AM |
6247 | dyn.d_un.d_ptr = (htab->splt->output_section->vma |
6248 | + htab->splt->output_offset); | |
65f38f15 AM |
6249 | break; |
6250 | ||
6251 | case DT_JMPREL: | |
5d1634d7 AM |
6252 | dyn.d_un.d_ptr = (htab->srelplt->output_section->vma |
6253 | + htab->srelplt->output_offset); | |
65f38f15 | 6254 | break; |
5bd4f169 | 6255 | |
65f38f15 | 6256 | case DT_PLTRELSZ: |
5d1634d7 AM |
6257 | dyn.d_un.d_val = htab->srelplt->_raw_size; |
6258 | break; | |
6259 | ||
6260 | case DT_RELASZ: | |
6261 | /* Don't count procedure linkage table relocs in the | |
6262 | overall reloc count. */ | |
6263 | if (htab->srelplt != NULL) | |
6264 | dyn.d_un.d_val -= htab->srelplt->_raw_size; | |
65f38f15 | 6265 | break; |
5bd4f169 | 6266 | } |
5bd4f169 | 6267 | |
65f38f15 | 6268 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 6269 | } |
5bd4f169 AM |
6270 | } |
6271 | ||
5d1634d7 AM |
6272 | if (htab->sgot != NULL && htab->sgot->_raw_size != 0) |
6273 | { | |
6274 | /* Fill in the first entry in the global offset table. | |
6275 | We use it to hold the link-time TOCbase. */ | |
6276 | bfd_put_64 (output_bfd, | |
60ee0d4a | 6277 | elf_gp (output_bfd) + TOC_BASE_OFF, |
5d1634d7 AM |
6278 | htab->sgot->contents); |
6279 | ||
6280 | /* Set .got entry size. */ | |
6281 | elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8; | |
6282 | } | |
6283 | ||
6284 | if (htab->splt != NULL && htab->splt->_raw_size != 0) | |
6285 | { | |
6286 | /* Set .plt entry size. */ | |
6287 | elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize | |
6288 | = PLT_ENTRY_SIZE; | |
6289 | } | |
6290 | ||
b34976b6 | 6291 | return TRUE; |
5bd4f169 AM |
6292 | } |
6293 | ||
6294 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec | |
6295 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
6296 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
6297 | #define TARGET_BIG_NAME "elf64-powerpc" | |
6298 | #define ELF_ARCH bfd_arch_powerpc | |
6299 | #define ELF_MACHINE_CODE EM_PPC64 | |
6300 | #define ELF_MAXPAGESIZE 0x10000 | |
6301 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
6302 | ||
6303 | #ifdef EM_CYGNUS_POWERPC | |
6304 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
6305 | #endif | |
6306 | ||
6307 | #ifdef EM_PPC_OLD | |
6308 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
6309 | #endif | |
6310 | ||
6311 | #define elf_backend_want_got_sym 0 | |
6312 | #define elf_backend_want_plt_sym 0 | |
6313 | #define elf_backend_plt_alignment 3 | |
6314 | #define elf_backend_plt_not_loaded 1 | |
6315 | #define elf_backend_got_symbol_offset 0 | |
5d1634d7 AM |
6316 | #define elf_backend_got_header_size 8 |
6317 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE | |
5bd4f169 | 6318 | #define elf_backend_can_gc_sections 1 |
65f38f15 | 6319 | #define elf_backend_can_refcount 1 |
b491616a | 6320 | #define elf_backend_rela_normal 1 |
5bd4f169 | 6321 | |
65f38f15 | 6322 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
65f38f15 AM |
6323 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data |
6324 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create | |
721956f4 | 6325 | #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free |
65f38f15 | 6326 | |
feee612b | 6327 | #define elf_backend_object_p ppc64_elf_object_p |
65f38f15 AM |
6328 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
6329 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
6330 | #define elf_backend_check_relocs ppc64_elf_check_relocs | |
6331 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
6332 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
6333 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
e86ce104 AM |
6334 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol |
6335 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
65f38f15 | 6336 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections |
65f38f15 AM |
6337 | #define elf_backend_relocate_section ppc64_elf_relocate_section |
6338 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
6339 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
6340 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
5bd4f169 AM |
6341 | |
6342 | #include "elf64-target.h" |