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