Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* PowerPC-specific support for 32-bit ELF |
2571583a | 2 | Copyright (C) 1994-2017 Free Software Foundation, Inc. |
252b5132 RH |
3 | Written by Ian Lance Taylor, Cygnus Support. |
4 | ||
ae9a127f | 5 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 6 | |
ae9a127f NC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 9 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 10 | (at your option) any later version. |
252b5132 | 11 | |
ae9a127f NC |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
252b5132 | 16 | |
ae9a127f | 17 | You should have received a copy of the GNU General Public License |
fc0bffd6 | 18 | along with this program; if not, write to the |
3e110533 | 19 | Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
53e09e0a | 20 | Boston, MA 02110-1301, USA. */ |
252b5132 | 21 | |
cd123cb7 | 22 | |
252b5132 RH |
23 | /* This file is based on a preliminary PowerPC ELF ABI. The |
24 | information may not match the final PowerPC ELF ABI. It includes | |
25 | suggestions from the in-progress Embedded PowerPC ABI, and that | |
26 | information may also not match. */ | |
27 | ||
3db64b00 | 28 | #include "sysdep.h" |
183e98be | 29 | #include <stdarg.h> |
252b5132 | 30 | #include "bfd.h" |
252b5132 RH |
31 | #include "bfdlink.h" |
32 | #include "libbfd.h" | |
33 | #include "elf-bfd.h" | |
34 | #include "elf/ppc.h" | |
7619e7c7 | 35 | #include "elf32-ppc.h" |
9d8504b1 | 36 | #include "elf-vxworks.h" |
6177242a | 37 | #include "dwarf2.h" |
08dc996f | 38 | #include "opcode/ppc.h" |
252b5132 | 39 | |
b9c361e0 JL |
40 | typedef enum split16_format_type |
41 | { | |
42 | split16a_type = 0, | |
43 | split16d_type | |
44 | } | |
45 | split16_format_type; | |
46 | ||
f0fe0e16 | 47 | /* RELA relocations are used here. */ |
252b5132 | 48 | |
252b5132 | 49 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
55fd94b0 | 50 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
7619e7c7 | 51 | static bfd_reloc_status_type ppc_elf_unhandled_reloc |
55fd94b0 | 52 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
252b5132 | 53 | |
70bccea4 AM |
54 | /* Branch prediction bit for branch taken relocs. */ |
55 | #define BRANCH_PREDICT_BIT 0x200000 | |
56 | /* Mask to set RA in memory instructions. */ | |
57 | #define RA_REGISTER_MASK 0x001f0000 | |
58 | /* Value to shift register by to insert RA. */ | |
59 | #define RA_REGISTER_SHIFT 16 | |
252b5132 RH |
60 | |
61 | /* The name of the dynamic interpreter. This is put in the .interp | |
62 | section. */ | |
252b5132 RH |
63 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
64 | ||
d7128ce4 | 65 | /* For old-style PLT. */ |
252b5132 RH |
66 | /* The number of single-slot PLT entries (the rest use two slots). */ |
67 | #define PLT_NUM_SINGLE_ENTRIES 8192 | |
68 | ||
d7128ce4 | 69 | /* For new-style .glink and .plt. */ |
a6aa5195 | 70 | #define GLINK_PLTRESOLVE 16*4 |
d7128ce4 | 71 | #define GLINK_ENTRY_SIZE 4*4 |
a7f2871e | 72 | #define TLS_GET_ADDR_GLINK_SIZE 12*4 |
d7128ce4 | 73 | |
9d8504b1 PB |
74 | /* VxWorks uses its own plt layout, filled in by the static linker. */ |
75 | ||
76 | /* The standard VxWorks PLT entry. */ | |
77 | #define VXWORKS_PLT_ENTRY_SIZE 32 | |
78 | static const bfd_vma ppc_elf_vxworks_plt_entry | |
79 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
80 | { | |
81 | 0x3d800000, /* lis r12,0 */ | |
82 | 0x818c0000, /* lwz r12,0(r12) */ | |
83 | 0x7d8903a6, /* mtctr r12 */ | |
84 | 0x4e800420, /* bctr */ | |
85 | 0x39600000, /* li r11,0 */ | |
86 | 0x48000000, /* b 14 <.PLT0resolve+0x4> */ | |
87 | 0x60000000, /* nop */ | |
88 | 0x60000000, /* nop */ | |
89 | }; | |
90 | static const bfd_vma ppc_elf_vxworks_pic_plt_entry | |
91 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
92 | { | |
93 | 0x3d9e0000, /* addis r12,r30,0 */ | |
94 | 0x818c0000, /* lwz r12,0(r12) */ | |
95 | 0x7d8903a6, /* mtctr r12 */ | |
96 | 0x4e800420, /* bctr */ | |
97 | 0x39600000, /* li r11,0 */ | |
98 | 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */ | |
99 | 0x60000000, /* nop */ | |
100 | 0x60000000, /* nop */ | |
101 | }; | |
102 | ||
103 | /* The initial VxWorks PLT entry. */ | |
104 | #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32 | |
105 | static const bfd_vma ppc_elf_vxworks_plt0_entry | |
106 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
107 | { | |
108 | 0x3d800000, /* lis r12,0 */ | |
109 | 0x398c0000, /* addi r12,r12,0 */ | |
110 | 0x800c0008, /* lwz r0,8(r12) */ | |
111 | 0x7c0903a6, /* mtctr r0 */ | |
112 | 0x818c0004, /* lwz r12,4(r12) */ | |
113 | 0x4e800420, /* bctr */ | |
114 | 0x60000000, /* nop */ | |
115 | 0x60000000, /* nop */ | |
116 | }; | |
117 | static const bfd_vma ppc_elf_vxworks_pic_plt0_entry | |
118 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
119 | { | |
120 | 0x819e0008, /* lwz r12,8(r30) */ | |
121 | 0x7d8903a6, /* mtctr r12 */ | |
122 | 0x819e0004, /* lwz r12,4(r30) */ | |
123 | 0x4e800420, /* bctr */ | |
124 | 0x60000000, /* nop */ | |
125 | 0x60000000, /* nop */ | |
126 | 0x60000000, /* nop */ | |
127 | 0x60000000, /* nop */ | |
128 | }; | |
129 | ||
130 | /* For executables, we have some additional relocations in | |
131 | .rela.plt.unloaded, for the kernel loader. */ | |
132 | ||
133 | /* The number of non-JMP_SLOT relocations per PLT0 slot. */ | |
134 | #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3 | |
135 | /* The number of relocations in the PLTResolve slot. */ | |
136 | #define VXWORKS_PLTRESOLVE_RELOCS 2 | |
de194d85 | 137 | /* The number of relocations in the PLTResolve slot when creating |
9d8504b1 PB |
138 | a shared library. */ |
139 | #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0 | |
140 | ||
d7128ce4 | 141 | /* Some instructions. */ |
d7128ce4 | 142 | #define ADDIS_11_11 0x3d6b0000 |
a6aa5195 AM |
143 | #define ADDIS_11_30 0x3d7e0000 |
144 | #define ADDIS_12_12 0x3d8c0000 | |
d7128ce4 | 145 | #define ADDI_11_11 0x396b0000 |
d7128ce4 | 146 | #define ADD_0_11_11 0x7c0b5a14 |
a7f2871e | 147 | #define ADD_3_12_2 0x7c6c1214 |
d7128ce4 | 148 | #define ADD_11_0_11 0x7d605a14 |
a6aa5195 | 149 | #define B 0x48000000 |
da3a2088 | 150 | #define BA 0x48000002 |
a6aa5195 | 151 | #define BCL_20_31 0x429f0005 |
d7128ce4 | 152 | #define BCTR 0x4e800420 |
a7f2871e AM |
153 | #define BEQLR 0x4d820020 |
154 | #define CMPWI_11_0 0x2c0b0000 | |
7e8aeb9a AM |
155 | #define LIS_11 0x3d600000 |
156 | #define LIS_12 0x3d800000 | |
a6aa5195 AM |
157 | #define LWZU_0_12 0x840c0000 |
158 | #define LWZ_0_12 0x800c0000 | |
a7f2871e | 159 | #define LWZ_11_3 0x81630000 |
a6aa5195 AM |
160 | #define LWZ_11_11 0x816b0000 |
161 | #define LWZ_11_30 0x817e0000 | |
a7f2871e | 162 | #define LWZ_12_3 0x81830000 |
a6aa5195 | 163 | #define LWZ_12_12 0x818c0000 |
a7f2871e AM |
164 | #define MR_0_3 0x7c601b78 |
165 | #define MR_3_0 0x7c030378 | |
a6aa5195 AM |
166 | #define MFLR_0 0x7c0802a6 |
167 | #define MFLR_12 0x7d8802a6 | |
168 | #define MTCTR_0 0x7c0903a6 | |
169 | #define MTCTR_11 0x7d6903a6 | |
170 | #define MTLR_0 0x7c0803a6 | |
171 | #define NOP 0x60000000 | |
172 | #define SUB_11_11_12 0x7d6c5850 | |
7619e7c7 AM |
173 | |
174 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
175 | #define TP_OFFSET 0x7000 | |
176 | #define DTP_OFFSET 0x8000 | |
e87d4038 AM |
177 | |
178 | /* The value of a defined global symbol. */ | |
179 | #define SYM_VAL(SYM) \ | |
180 | ((SYM)->root.u.def.section->output_section->vma \ | |
181 | + (SYM)->root.u.def.section->output_offset \ | |
182 | + (SYM)->root.u.def.value) | |
7fce784e | 183 | \f |
e47cd125 | 184 | static reloc_howto_type *ppc_elf_howto_table[R_PPC_max]; |
252b5132 | 185 | |
8da6118f | 186 | static reloc_howto_type ppc_elf_howto_raw[] = { |
252b5132 RH |
187 | /* This reloc does nothing. */ |
188 | HOWTO (R_PPC_NONE, /* type */ | |
189 | 0, /* rightshift */ | |
6346d5ca AM |
190 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
191 | 0, /* bitsize */ | |
b34976b6 | 192 | FALSE, /* pc_relative */ |
252b5132 | 193 | 0, /* bitpos */ |
86c95733 | 194 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 RH |
195 | bfd_elf_generic_reloc, /* special_function */ |
196 | "R_PPC_NONE", /* name */ | |
b34976b6 | 197 | FALSE, /* partial_inplace */ |
252b5132 RH |
198 | 0, /* src_mask */ |
199 | 0, /* dst_mask */ | |
b34976b6 | 200 | FALSE), /* pcrel_offset */ |
252b5132 RH |
201 | |
202 | /* A standard 32 bit relocation. */ | |
203 | HOWTO (R_PPC_ADDR32, /* type */ | |
204 | 0, /* rightshift */ | |
205 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
206 | 32, /* bitsize */ | |
b34976b6 | 207 | FALSE, /* pc_relative */ |
252b5132 | 208 | 0, /* bitpos */ |
86c95733 | 209 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 RH |
210 | bfd_elf_generic_reloc, /* special_function */ |
211 | "R_PPC_ADDR32", /* name */ | |
b34976b6 | 212 | FALSE, /* partial_inplace */ |
252b5132 RH |
213 | 0, /* src_mask */ |
214 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 215 | FALSE), /* pcrel_offset */ |
252b5132 RH |
216 | |
217 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
218 | FIXME: we don't check that, we just clear them. */ | |
219 | HOWTO (R_PPC_ADDR24, /* type */ | |
220 | 0, /* rightshift */ | |
221 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
222 | 26, /* bitsize */ | |
b34976b6 | 223 | FALSE, /* pc_relative */ |
252b5132 | 224 | 0, /* bitpos */ |
86c95733 | 225 | complain_overflow_signed, /* complain_on_overflow */ |
252b5132 RH |
226 | bfd_elf_generic_reloc, /* special_function */ |
227 | "R_PPC_ADDR24", /* name */ | |
b34976b6 | 228 | FALSE, /* partial_inplace */ |
252b5132 RH |
229 | 0, /* src_mask */ |
230 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 231 | FALSE), /* pcrel_offset */ |
252b5132 RH |
232 | |
233 | /* A standard 16 bit relocation. */ | |
234 | HOWTO (R_PPC_ADDR16, /* type */ | |
235 | 0, /* rightshift */ | |
236 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
237 | 16, /* bitsize */ | |
b34976b6 | 238 | FALSE, /* pc_relative */ |
252b5132 RH |
239 | 0, /* bitpos */ |
240 | complain_overflow_bitfield, /* complain_on_overflow */ | |
241 | bfd_elf_generic_reloc, /* special_function */ | |
242 | "R_PPC_ADDR16", /* name */ | |
b34976b6 | 243 | FALSE, /* partial_inplace */ |
252b5132 RH |
244 | 0, /* src_mask */ |
245 | 0xffff, /* dst_mask */ | |
b34976b6 | 246 | FALSE), /* pcrel_offset */ |
252b5132 RH |
247 | |
248 | /* A 16 bit relocation without overflow. */ | |
249 | HOWTO (R_PPC_ADDR16_LO, /* type */ | |
250 | 0, /* rightshift */ | |
251 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
252 | 16, /* bitsize */ | |
b34976b6 | 253 | FALSE, /* pc_relative */ |
252b5132 RH |
254 | 0, /* bitpos */ |
255 | complain_overflow_dont,/* complain_on_overflow */ | |
256 | bfd_elf_generic_reloc, /* special_function */ | |
257 | "R_PPC_ADDR16_LO", /* name */ | |
b34976b6 | 258 | FALSE, /* partial_inplace */ |
252b5132 RH |
259 | 0, /* src_mask */ |
260 | 0xffff, /* dst_mask */ | |
b34976b6 | 261 | FALSE), /* pcrel_offset */ |
252b5132 RH |
262 | |
263 | /* The high order 16 bits of an address. */ | |
264 | HOWTO (R_PPC_ADDR16_HI, /* type */ | |
265 | 16, /* rightshift */ | |
266 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
267 | 16, /* bitsize */ | |
b34976b6 | 268 | FALSE, /* pc_relative */ |
252b5132 RH |
269 | 0, /* bitpos */ |
270 | complain_overflow_dont, /* complain_on_overflow */ | |
271 | bfd_elf_generic_reloc, /* special_function */ | |
272 | "R_PPC_ADDR16_HI", /* name */ | |
b34976b6 | 273 | FALSE, /* partial_inplace */ |
252b5132 RH |
274 | 0, /* src_mask */ |
275 | 0xffff, /* dst_mask */ | |
b34976b6 | 276 | FALSE), /* pcrel_offset */ |
252b5132 RH |
277 | |
278 | /* The high order 16 bits of an address, plus 1 if the contents of | |
8da6118f | 279 | the low 16 bits, treated as a signed number, is negative. */ |
252b5132 RH |
280 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
281 | 16, /* rightshift */ | |
282 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
283 | 16, /* bitsize */ | |
b34976b6 | 284 | FALSE, /* pc_relative */ |
252b5132 RH |
285 | 0, /* bitpos */ |
286 | complain_overflow_dont, /* complain_on_overflow */ | |
287 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
288 | "R_PPC_ADDR16_HA", /* name */ | |
b34976b6 | 289 | FALSE, /* partial_inplace */ |
252b5132 RH |
290 | 0, /* src_mask */ |
291 | 0xffff, /* dst_mask */ | |
b34976b6 | 292 | FALSE), /* pcrel_offset */ |
252b5132 RH |
293 | |
294 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
295 | FIXME: we don't check that, we just clear them. */ | |
296 | HOWTO (R_PPC_ADDR14, /* type */ | |
297 | 0, /* rightshift */ | |
298 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
299 | 16, /* bitsize */ | |
b34976b6 | 300 | FALSE, /* pc_relative */ |
252b5132 | 301 | 0, /* bitpos */ |
86c95733 | 302 | complain_overflow_signed, /* complain_on_overflow */ |
252b5132 RH |
303 | bfd_elf_generic_reloc, /* special_function */ |
304 | "R_PPC_ADDR14", /* name */ | |
b34976b6 | 305 | FALSE, /* partial_inplace */ |
252b5132 RH |
306 | 0, /* src_mask */ |
307 | 0xfffc, /* dst_mask */ | |
b34976b6 | 308 | FALSE), /* pcrel_offset */ |
252b5132 RH |
309 | |
310 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
311 | indicate that the branch is expected to be taken. The lower two | |
8da6118f | 312 | bits must be zero. */ |
252b5132 RH |
313 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
314 | 0, /* rightshift */ | |
315 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
316 | 16, /* bitsize */ | |
b34976b6 | 317 | FALSE, /* pc_relative */ |
252b5132 | 318 | 0, /* bitpos */ |
86c95733 | 319 | complain_overflow_signed, /* complain_on_overflow */ |
252b5132 RH |
320 | bfd_elf_generic_reloc, /* special_function */ |
321 | "R_PPC_ADDR14_BRTAKEN",/* name */ | |
b34976b6 | 322 | FALSE, /* partial_inplace */ |
252b5132 RH |
323 | 0, /* src_mask */ |
324 | 0xfffc, /* dst_mask */ | |
b34976b6 | 325 | FALSE), /* pcrel_offset */ |
252b5132 RH |
326 | |
327 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
328 | indicate that the branch is not expected to be taken. The lower | |
329 | two bits must be zero. */ | |
330 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
331 | 0, /* rightshift */ | |
332 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
333 | 16, /* bitsize */ | |
b34976b6 | 334 | FALSE, /* pc_relative */ |
252b5132 | 335 | 0, /* bitpos */ |
86c95733 | 336 | complain_overflow_signed, /* complain_on_overflow */ |
252b5132 RH |
337 | bfd_elf_generic_reloc, /* special_function */ |
338 | "R_PPC_ADDR14_BRNTAKEN",/* name */ | |
b34976b6 | 339 | FALSE, /* partial_inplace */ |
252b5132 RH |
340 | 0, /* src_mask */ |
341 | 0xfffc, /* dst_mask */ | |
b34976b6 | 342 | FALSE), /* pcrel_offset */ |
252b5132 | 343 | |
8da6118f | 344 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
345 | HOWTO (R_PPC_REL24, /* type */ |
346 | 0, /* rightshift */ | |
347 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
348 | 26, /* bitsize */ | |
b34976b6 | 349 | TRUE, /* pc_relative */ |
252b5132 RH |
350 | 0, /* bitpos */ |
351 | complain_overflow_signed, /* complain_on_overflow */ | |
352 | bfd_elf_generic_reloc, /* special_function */ | |
353 | "R_PPC_REL24", /* name */ | |
b34976b6 | 354 | FALSE, /* partial_inplace */ |
252b5132 RH |
355 | 0, /* src_mask */ |
356 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 357 | TRUE), /* pcrel_offset */ |
252b5132 | 358 | |
8da6118f | 359 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
360 | HOWTO (R_PPC_REL14, /* type */ |
361 | 0, /* rightshift */ | |
362 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
363 | 16, /* bitsize */ | |
b34976b6 | 364 | TRUE, /* pc_relative */ |
252b5132 RH |
365 | 0, /* bitpos */ |
366 | complain_overflow_signed, /* complain_on_overflow */ | |
367 | bfd_elf_generic_reloc, /* special_function */ | |
368 | "R_PPC_REL14", /* name */ | |
b34976b6 | 369 | FALSE, /* partial_inplace */ |
252b5132 RH |
370 | 0, /* src_mask */ |
371 | 0xfffc, /* dst_mask */ | |
b34976b6 | 372 | TRUE), /* pcrel_offset */ |
252b5132 | 373 | |
8da6118f | 374 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
375 | the branch is expected to be taken. The lower two bits must be |
376 | zero. */ | |
377 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ | |
378 | 0, /* rightshift */ | |
379 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
380 | 16, /* bitsize */ | |
b34976b6 | 381 | TRUE, /* pc_relative */ |
252b5132 RH |
382 | 0, /* bitpos */ |
383 | complain_overflow_signed, /* complain_on_overflow */ | |
384 | bfd_elf_generic_reloc, /* special_function */ | |
385 | "R_PPC_REL14_BRTAKEN", /* name */ | |
b34976b6 | 386 | FALSE, /* partial_inplace */ |
252b5132 RH |
387 | 0, /* src_mask */ |
388 | 0xfffc, /* dst_mask */ | |
b34976b6 | 389 | TRUE), /* pcrel_offset */ |
252b5132 | 390 | |
8da6118f | 391 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
392 | the branch is not expected to be taken. The lower two bits must |
393 | be zero. */ | |
394 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ | |
395 | 0, /* rightshift */ | |
396 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
397 | 16, /* bitsize */ | |
b34976b6 | 398 | TRUE, /* pc_relative */ |
252b5132 RH |
399 | 0, /* bitpos */ |
400 | complain_overflow_signed, /* complain_on_overflow */ | |
401 | bfd_elf_generic_reloc, /* special_function */ | |
402 | "R_PPC_REL14_BRNTAKEN",/* name */ | |
b34976b6 | 403 | FALSE, /* partial_inplace */ |
252b5132 RH |
404 | 0, /* src_mask */ |
405 | 0xfffc, /* dst_mask */ | |
b34976b6 | 406 | TRUE), /* pcrel_offset */ |
252b5132 RH |
407 | |
408 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
409 | symbol. */ | |
410 | HOWTO (R_PPC_GOT16, /* type */ | |
411 | 0, /* rightshift */ | |
412 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
413 | 16, /* bitsize */ | |
b34976b6 | 414 | FALSE, /* pc_relative */ |
252b5132 RH |
415 | 0, /* bitpos */ |
416 | complain_overflow_signed, /* complain_on_overflow */ | |
3ce51288 | 417 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 418 | "R_PPC_GOT16", /* name */ |
b34976b6 | 419 | FALSE, /* partial_inplace */ |
252b5132 RH |
420 | 0, /* src_mask */ |
421 | 0xffff, /* dst_mask */ | |
b34976b6 | 422 | FALSE), /* pcrel_offset */ |
252b5132 RH |
423 | |
424 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
425 | the symbol. */ | |
426 | HOWTO (R_PPC_GOT16_LO, /* type */ | |
427 | 0, /* rightshift */ | |
428 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
429 | 16, /* bitsize */ | |
b34976b6 | 430 | FALSE, /* pc_relative */ |
252b5132 RH |
431 | 0, /* bitpos */ |
432 | complain_overflow_dont, /* complain_on_overflow */ | |
3ce51288 | 433 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 434 | "R_PPC_GOT16_LO", /* name */ |
b34976b6 | 435 | FALSE, /* partial_inplace */ |
252b5132 RH |
436 | 0, /* src_mask */ |
437 | 0xffff, /* dst_mask */ | |
b34976b6 | 438 | FALSE), /* pcrel_offset */ |
252b5132 RH |
439 | |
440 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
441 | the symbol. */ | |
442 | HOWTO (R_PPC_GOT16_HI, /* type */ | |
443 | 16, /* rightshift */ | |
444 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
445 | 16, /* bitsize */ | |
b34976b6 | 446 | FALSE, /* pc_relative */ |
252b5132 | 447 | 0, /* bitpos */ |
86c95733 | 448 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 449 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 450 | "R_PPC_GOT16_HI", /* name */ |
b34976b6 | 451 | FALSE, /* partial_inplace */ |
252b5132 RH |
452 | 0, /* src_mask */ |
453 | 0xffff, /* dst_mask */ | |
b34976b6 | 454 | FALSE), /* pcrel_offset */ |
252b5132 RH |
455 | |
456 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
457 | the symbol. */ | |
458 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
459 | 16, /* rightshift */ | |
460 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
461 | 16, /* bitsize */ | |
b34976b6 | 462 | FALSE, /* pc_relative */ |
252b5132 | 463 | 0, /* bitpos */ |
86c95733 | 464 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 465 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 466 | "R_PPC_GOT16_HA", /* name */ |
b34976b6 | 467 | FALSE, /* partial_inplace */ |
252b5132 RH |
468 | 0, /* src_mask */ |
469 | 0xffff, /* dst_mask */ | |
b34976b6 | 470 | FALSE), /* pcrel_offset */ |
252b5132 RH |
471 | |
472 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
473 | entry for the symbol. */ | |
474 | HOWTO (R_PPC_PLTREL24, /* type */ | |
475 | 0, /* rightshift */ | |
476 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
477 | 26, /* bitsize */ | |
b34976b6 | 478 | TRUE, /* pc_relative */ |
252b5132 | 479 | 0, /* bitpos */ |
3ce51288 AM |
480 | complain_overflow_signed, /* complain_on_overflow */ |
481 | ppc_elf_unhandled_reloc, /* special_function */ | |
252b5132 | 482 | "R_PPC_PLTREL24", /* name */ |
b34976b6 | 483 | FALSE, /* partial_inplace */ |
252b5132 RH |
484 | 0, /* src_mask */ |
485 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 486 | TRUE), /* pcrel_offset */ |
252b5132 RH |
487 | |
488 | /* This is used only by the dynamic linker. The symbol should exist | |
489 | both in the object being run and in some shared library. The | |
490 | dynamic linker copies the data addressed by the symbol from the | |
491 | shared library into the object, because the object being | |
492 | run has to have the data at some particular address. */ | |
493 | HOWTO (R_PPC_COPY, /* type */ | |
494 | 0, /* rightshift */ | |
495 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
496 | 32, /* bitsize */ | |
b34976b6 | 497 | FALSE, /* pc_relative */ |
252b5132 | 498 | 0, /* bitpos */ |
86c95733 | 499 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 500 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 501 | "R_PPC_COPY", /* name */ |
b34976b6 | 502 | FALSE, /* partial_inplace */ |
252b5132 RH |
503 | 0, /* src_mask */ |
504 | 0, /* dst_mask */ | |
b34976b6 | 505 | FALSE), /* pcrel_offset */ |
252b5132 RH |
506 | |
507 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
508 | entries. */ | |
509 | HOWTO (R_PPC_GLOB_DAT, /* type */ | |
510 | 0, /* rightshift */ | |
511 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
512 | 32, /* bitsize */ | |
b34976b6 | 513 | FALSE, /* pc_relative */ |
252b5132 | 514 | 0, /* bitpos */ |
86c95733 | 515 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 516 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 517 | "R_PPC_GLOB_DAT", /* name */ |
b34976b6 | 518 | FALSE, /* partial_inplace */ |
252b5132 RH |
519 | 0, /* src_mask */ |
520 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 521 | FALSE), /* pcrel_offset */ |
252b5132 RH |
522 | |
523 | /* Marks a procedure linkage table entry for a symbol. */ | |
524 | HOWTO (R_PPC_JMP_SLOT, /* type */ | |
525 | 0, /* rightshift */ | |
526 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
527 | 32, /* bitsize */ | |
b34976b6 | 528 | FALSE, /* pc_relative */ |
252b5132 | 529 | 0, /* bitpos */ |
86c95733 | 530 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 531 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 532 | "R_PPC_JMP_SLOT", /* name */ |
b34976b6 | 533 | FALSE, /* partial_inplace */ |
252b5132 RH |
534 | 0, /* src_mask */ |
535 | 0, /* dst_mask */ | |
b34976b6 | 536 | FALSE), /* pcrel_offset */ |
252b5132 RH |
537 | |
538 | /* Used only by the dynamic linker. When the object is run, this | |
539 | longword is set to the load address of the object, plus the | |
540 | addend. */ | |
541 | HOWTO (R_PPC_RELATIVE, /* type */ | |
542 | 0, /* rightshift */ | |
543 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
544 | 32, /* bitsize */ | |
b34976b6 | 545 | FALSE, /* pc_relative */ |
252b5132 | 546 | 0, /* bitpos */ |
86c95733 | 547 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 RH |
548 | bfd_elf_generic_reloc, /* special_function */ |
549 | "R_PPC_RELATIVE", /* name */ | |
b34976b6 | 550 | FALSE, /* partial_inplace */ |
252b5132 RH |
551 | 0, /* src_mask */ |
552 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 553 | FALSE), /* pcrel_offset */ |
252b5132 RH |
554 | |
555 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
556 | object rather than the final value. Normally used for | |
557 | _GLOBAL_OFFSET_TABLE_. */ | |
558 | HOWTO (R_PPC_LOCAL24PC, /* type */ | |
559 | 0, /* rightshift */ | |
560 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
561 | 26, /* bitsize */ | |
b34976b6 | 562 | TRUE, /* pc_relative */ |
252b5132 RH |
563 | 0, /* bitpos */ |
564 | complain_overflow_signed, /* complain_on_overflow */ | |
565 | bfd_elf_generic_reloc, /* special_function */ | |
566 | "R_PPC_LOCAL24PC", /* name */ | |
b34976b6 | 567 | FALSE, /* partial_inplace */ |
252b5132 RH |
568 | 0, /* src_mask */ |
569 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 570 | TRUE), /* pcrel_offset */ |
252b5132 RH |
571 | |
572 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
573 | HOWTO (R_PPC_UADDR32, /* type */ | |
574 | 0, /* rightshift */ | |
575 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
576 | 32, /* bitsize */ | |
b34976b6 | 577 | FALSE, /* pc_relative */ |
252b5132 | 578 | 0, /* bitpos */ |
86c95733 | 579 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 RH |
580 | bfd_elf_generic_reloc, /* special_function */ |
581 | "R_PPC_UADDR32", /* name */ | |
b34976b6 | 582 | FALSE, /* partial_inplace */ |
252b5132 RH |
583 | 0, /* src_mask */ |
584 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 585 | FALSE), /* pcrel_offset */ |
252b5132 RH |
586 | |
587 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
588 | HOWTO (R_PPC_UADDR16, /* type */ | |
589 | 0, /* rightshift */ | |
590 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
591 | 16, /* bitsize */ | |
b34976b6 | 592 | FALSE, /* pc_relative */ |
252b5132 RH |
593 | 0, /* bitpos */ |
594 | complain_overflow_bitfield, /* complain_on_overflow */ | |
595 | bfd_elf_generic_reloc, /* special_function */ | |
596 | "R_PPC_UADDR16", /* name */ | |
b34976b6 | 597 | FALSE, /* partial_inplace */ |
252b5132 RH |
598 | 0, /* src_mask */ |
599 | 0xffff, /* dst_mask */ | |
b34976b6 | 600 | FALSE), /* pcrel_offset */ |
252b5132 RH |
601 | |
602 | /* 32-bit PC relative */ | |
603 | HOWTO (R_PPC_REL32, /* type */ | |
604 | 0, /* rightshift */ | |
605 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
606 | 32, /* bitsize */ | |
b34976b6 | 607 | TRUE, /* pc_relative */ |
252b5132 | 608 | 0, /* bitpos */ |
86c95733 | 609 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 RH |
610 | bfd_elf_generic_reloc, /* special_function */ |
611 | "R_PPC_REL32", /* name */ | |
b34976b6 | 612 | FALSE, /* partial_inplace */ |
252b5132 RH |
613 | 0, /* src_mask */ |
614 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 615 | TRUE), /* pcrel_offset */ |
252b5132 RH |
616 | |
617 | /* 32-bit relocation to the symbol's procedure linkage table. | |
c3668558 | 618 | FIXME: not supported. */ |
252b5132 RH |
619 | HOWTO (R_PPC_PLT32, /* type */ |
620 | 0, /* rightshift */ | |
621 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
622 | 32, /* bitsize */ | |
b34976b6 | 623 | FALSE, /* pc_relative */ |
252b5132 | 624 | 0, /* bitpos */ |
86c95733 | 625 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 626 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 627 | "R_PPC_PLT32", /* name */ |
b34976b6 | 628 | FALSE, /* partial_inplace */ |
252b5132 RH |
629 | 0, /* src_mask */ |
630 | 0, /* dst_mask */ | |
b34976b6 | 631 | FALSE), /* pcrel_offset */ |
252b5132 RH |
632 | |
633 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
c3668558 | 634 | FIXME: not supported. */ |
252b5132 RH |
635 | HOWTO (R_PPC_PLTREL32, /* type */ |
636 | 0, /* rightshift */ | |
637 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
638 | 32, /* bitsize */ | |
b34976b6 | 639 | TRUE, /* pc_relative */ |
252b5132 | 640 | 0, /* bitpos */ |
86c95733 | 641 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 642 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 643 | "R_PPC_PLTREL32", /* name */ |
b34976b6 | 644 | FALSE, /* partial_inplace */ |
252b5132 RH |
645 | 0, /* src_mask */ |
646 | 0, /* dst_mask */ | |
b34976b6 | 647 | TRUE), /* pcrel_offset */ |
252b5132 RH |
648 | |
649 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
650 | the symbol. */ | |
651 | HOWTO (R_PPC_PLT16_LO, /* type */ | |
652 | 0, /* rightshift */ | |
653 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
654 | 16, /* bitsize */ | |
b34976b6 | 655 | FALSE, /* pc_relative */ |
252b5132 RH |
656 | 0, /* bitpos */ |
657 | complain_overflow_dont, /* complain_on_overflow */ | |
3ce51288 | 658 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 659 | "R_PPC_PLT16_LO", /* name */ |
b34976b6 | 660 | FALSE, /* partial_inplace */ |
252b5132 RH |
661 | 0, /* src_mask */ |
662 | 0xffff, /* dst_mask */ | |
b34976b6 | 663 | FALSE), /* pcrel_offset */ |
252b5132 RH |
664 | |
665 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
666 | the symbol. */ | |
667 | HOWTO (R_PPC_PLT16_HI, /* type */ | |
668 | 16, /* rightshift */ | |
669 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
670 | 16, /* bitsize */ | |
b34976b6 | 671 | FALSE, /* pc_relative */ |
252b5132 | 672 | 0, /* bitpos */ |
86c95733 | 673 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 674 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 675 | "R_PPC_PLT16_HI", /* name */ |
b34976b6 | 676 | FALSE, /* partial_inplace */ |
252b5132 RH |
677 | 0, /* src_mask */ |
678 | 0xffff, /* dst_mask */ | |
b34976b6 | 679 | FALSE), /* pcrel_offset */ |
252b5132 RH |
680 | |
681 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
682 | the symbol. */ | |
683 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
684 | 16, /* rightshift */ | |
685 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
686 | 16, /* bitsize */ | |
b34976b6 | 687 | FALSE, /* pc_relative */ |
252b5132 | 688 | 0, /* bitpos */ |
86c95733 | 689 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 690 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 691 | "R_PPC_PLT16_HA", /* name */ |
b34976b6 | 692 | FALSE, /* partial_inplace */ |
252b5132 RH |
693 | 0, /* src_mask */ |
694 | 0xffff, /* dst_mask */ | |
b34976b6 | 695 | FALSE), /* pcrel_offset */ |
252b5132 RH |
696 | |
697 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with | |
698 | small data items. */ | |
699 | HOWTO (R_PPC_SDAREL16, /* type */ | |
700 | 0, /* rightshift */ | |
701 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
702 | 16, /* bitsize */ | |
b34976b6 | 703 | FALSE, /* pc_relative */ |
252b5132 RH |
704 | 0, /* bitpos */ |
705 | complain_overflow_signed, /* complain_on_overflow */ | |
3ce51288 | 706 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 707 | "R_PPC_SDAREL16", /* name */ |
b34976b6 | 708 | FALSE, /* partial_inplace */ |
252b5132 RH |
709 | 0, /* src_mask */ |
710 | 0xffff, /* dst_mask */ | |
b34976b6 | 711 | FALSE), /* pcrel_offset */ |
252b5132 | 712 | |
c061c2d8 | 713 | /* 16-bit section relative relocation. */ |
252b5132 RH |
714 | HOWTO (R_PPC_SECTOFF, /* type */ |
715 | 0, /* rightshift */ | |
c061c2d8 AM |
716 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
717 | 16, /* bitsize */ | |
b34976b6 | 718 | FALSE, /* pc_relative */ |
252b5132 | 719 | 0, /* bitpos */ |
86c95733 | 720 | complain_overflow_signed, /* complain_on_overflow */ |
3ce51288 | 721 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 722 | "R_PPC_SECTOFF", /* name */ |
b34976b6 | 723 | FALSE, /* partial_inplace */ |
252b5132 | 724 | 0, /* src_mask */ |
c061c2d8 | 725 | 0xffff, /* dst_mask */ |
b34976b6 | 726 | FALSE), /* pcrel_offset */ |
252b5132 | 727 | |
c3668558 | 728 | /* 16-bit lower half section relative relocation. */ |
252b5132 RH |
729 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
730 | 0, /* rightshift */ | |
731 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
732 | 16, /* bitsize */ | |
b34976b6 | 733 | FALSE, /* pc_relative */ |
252b5132 RH |
734 | 0, /* bitpos */ |
735 | complain_overflow_dont, /* complain_on_overflow */ | |
3ce51288 | 736 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 737 | "R_PPC_SECTOFF_LO", /* name */ |
b34976b6 | 738 | FALSE, /* partial_inplace */ |
252b5132 RH |
739 | 0, /* src_mask */ |
740 | 0xffff, /* dst_mask */ | |
b34976b6 | 741 | FALSE), /* pcrel_offset */ |
252b5132 | 742 | |
c3668558 | 743 | /* 16-bit upper half section relative relocation. */ |
252b5132 RH |
744 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
745 | 16, /* rightshift */ | |
746 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
747 | 16, /* bitsize */ | |
b34976b6 | 748 | FALSE, /* pc_relative */ |
252b5132 | 749 | 0, /* bitpos */ |
86c95733 | 750 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 751 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 752 | "R_PPC_SECTOFF_HI", /* name */ |
b34976b6 | 753 | FALSE, /* partial_inplace */ |
252b5132 RH |
754 | 0, /* src_mask */ |
755 | 0xffff, /* dst_mask */ | |
b34976b6 | 756 | FALSE), /* pcrel_offset */ |
252b5132 | 757 | |
c3668558 | 758 | /* 16-bit upper half adjusted section relative relocation. */ |
252b5132 RH |
759 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
760 | 16, /* rightshift */ | |
761 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
762 | 16, /* bitsize */ | |
b34976b6 | 763 | FALSE, /* pc_relative */ |
252b5132 | 764 | 0, /* bitpos */ |
86c95733 | 765 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 766 | ppc_elf_unhandled_reloc, /* special_function */ |
252b5132 | 767 | "R_PPC_SECTOFF_HA", /* name */ |
b34976b6 | 768 | FALSE, /* partial_inplace */ |
252b5132 RH |
769 | 0, /* src_mask */ |
770 | 0xffff, /* dst_mask */ | |
b34976b6 | 771 | FALSE), /* pcrel_offset */ |
252b5132 | 772 | |
727fc41e | 773 | /* Marker relocs for TLS. */ |
7619e7c7 | 774 | HOWTO (R_PPC_TLS, |
252b5132 RH |
775 | 0, /* rightshift */ |
776 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
777 | 32, /* bitsize */ | |
b34976b6 | 778 | FALSE, /* pc_relative */ |
252b5132 | 779 | 0, /* bitpos */ |
7619e7c7 | 780 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 | 781 | bfd_elf_generic_reloc, /* special_function */ |
7619e7c7 AM |
782 | "R_PPC_TLS", /* name */ |
783 | FALSE, /* partial_inplace */ | |
784 | 0, /* src_mask */ | |
785 | 0, /* dst_mask */ | |
786 | FALSE), /* pcrel_offset */ | |
787 | ||
727fc41e AM |
788 | HOWTO (R_PPC_TLSGD, |
789 | 0, /* rightshift */ | |
790 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
791 | 32, /* bitsize */ | |
792 | FALSE, /* pc_relative */ | |
793 | 0, /* bitpos */ | |
794 | complain_overflow_dont, /* complain_on_overflow */ | |
795 | bfd_elf_generic_reloc, /* special_function */ | |
796 | "R_PPC_TLSGD", /* name */ | |
797 | FALSE, /* partial_inplace */ | |
798 | 0, /* src_mask */ | |
799 | 0, /* dst_mask */ | |
800 | FALSE), /* pcrel_offset */ | |
801 | ||
802 | HOWTO (R_PPC_TLSLD, | |
803 | 0, /* rightshift */ | |
804 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
805 | 32, /* bitsize */ | |
806 | FALSE, /* pc_relative */ | |
807 | 0, /* bitpos */ | |
808 | complain_overflow_dont, /* complain_on_overflow */ | |
809 | bfd_elf_generic_reloc, /* special_function */ | |
810 | "R_PPC_TLSLD", /* name */ | |
811 | FALSE, /* partial_inplace */ | |
812 | 0, /* src_mask */ | |
813 | 0, /* dst_mask */ | |
814 | FALSE), /* pcrel_offset */ | |
815 | ||
7619e7c7 AM |
816 | /* Computes the load module index of the load module that contains the |
817 | definition of its TLS sym. */ | |
818 | HOWTO (R_PPC_DTPMOD32, | |
819 | 0, /* rightshift */ | |
820 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
821 | 32, /* bitsize */ | |
822 | FALSE, /* pc_relative */ | |
823 | 0, /* bitpos */ | |
824 | complain_overflow_dont, /* complain_on_overflow */ | |
825 | ppc_elf_unhandled_reloc, /* special_function */ | |
826 | "R_PPC_DTPMOD32", /* name */ | |
b34976b6 | 827 | FALSE, /* partial_inplace */ |
252b5132 RH |
828 | 0, /* src_mask */ |
829 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 830 | FALSE), /* pcrel_offset */ |
252b5132 | 831 | |
7619e7c7 AM |
832 | /* Computes a dtv-relative displacement, the difference between the value |
833 | of sym+add and the base address of the thread-local storage block that | |
834 | contains the definition of sym, minus 0x8000. */ | |
835 | HOWTO (R_PPC_DTPREL32, | |
836 | 0, /* rightshift */ | |
837 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
838 | 32, /* bitsize */ | |
839 | FALSE, /* pc_relative */ | |
840 | 0, /* bitpos */ | |
841 | complain_overflow_dont, /* complain_on_overflow */ | |
842 | ppc_elf_unhandled_reloc, /* special_function */ | |
843 | "R_PPC_DTPREL32", /* name */ | |
844 | FALSE, /* partial_inplace */ | |
845 | 0, /* src_mask */ | |
846 | 0xffffffff, /* dst_mask */ | |
847 | FALSE), /* pcrel_offset */ | |
848 | ||
849 | /* A 16 bit dtprel reloc. */ | |
850 | HOWTO (R_PPC_DTPREL16, | |
252b5132 RH |
851 | 0, /* rightshift */ |
852 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
853 | 16, /* bitsize */ | |
b34976b6 | 854 | FALSE, /* pc_relative */ |
252b5132 | 855 | 0, /* bitpos */ |
7619e7c7 AM |
856 | complain_overflow_signed, /* complain_on_overflow */ |
857 | ppc_elf_unhandled_reloc, /* special_function */ | |
858 | "R_PPC_DTPREL16", /* name */ | |
b34976b6 | 859 | FALSE, /* partial_inplace */ |
252b5132 RH |
860 | 0, /* src_mask */ |
861 | 0xffff, /* dst_mask */ | |
b34976b6 | 862 | FALSE), /* pcrel_offset */ |
252b5132 | 863 | |
7619e7c7 AM |
864 | /* Like DTPREL16, but no overflow. */ |
865 | HOWTO (R_PPC_DTPREL16_LO, | |
252b5132 RH |
866 | 0, /* rightshift */ |
867 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
868 | 16, /* bitsize */ | |
b34976b6 | 869 | FALSE, /* pc_relative */ |
252b5132 | 870 | 0, /* bitpos */ |
7619e7c7 AM |
871 | complain_overflow_dont, /* complain_on_overflow */ |
872 | ppc_elf_unhandled_reloc, /* special_function */ | |
873 | "R_PPC_DTPREL16_LO", /* name */ | |
b34976b6 | 874 | FALSE, /* partial_inplace */ |
252b5132 RH |
875 | 0, /* src_mask */ |
876 | 0xffff, /* dst_mask */ | |
b34976b6 | 877 | FALSE), /* pcrel_offset */ |
252b5132 | 878 | |
7619e7c7 AM |
879 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ |
880 | HOWTO (R_PPC_DTPREL16_HI, | |
252b5132 RH |
881 | 16, /* rightshift */ |
882 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
883 | 16, /* bitsize */ | |
b34976b6 | 884 | FALSE, /* pc_relative */ |
252b5132 RH |
885 | 0, /* bitpos */ |
886 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
887 | ppc_elf_unhandled_reloc, /* special_function */ |
888 | "R_PPC_DTPREL16_HI", /* name */ | |
b34976b6 | 889 | FALSE, /* partial_inplace */ |
252b5132 RH |
890 | 0, /* src_mask */ |
891 | 0xffff, /* dst_mask */ | |
b34976b6 | 892 | FALSE), /* pcrel_offset */ |
252b5132 | 893 | |
7619e7c7 AM |
894 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ |
895 | HOWTO (R_PPC_DTPREL16_HA, | |
252b5132 RH |
896 | 16, /* rightshift */ |
897 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
898 | 16, /* bitsize */ | |
b34976b6 | 899 | FALSE, /* pc_relative */ |
252b5132 RH |
900 | 0, /* bitpos */ |
901 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
902 | ppc_elf_unhandled_reloc, /* special_function */ |
903 | "R_PPC_DTPREL16_HA", /* name */ | |
b34976b6 | 904 | FALSE, /* partial_inplace */ |
252b5132 RH |
905 | 0, /* src_mask */ |
906 | 0xffff, /* dst_mask */ | |
b34976b6 | 907 | FALSE), /* pcrel_offset */ |
252b5132 | 908 | |
7619e7c7 AM |
909 | /* Computes a tp-relative displacement, the difference between the value of |
910 | sym+add and the value of the thread pointer (r13). */ | |
911 | HOWTO (R_PPC_TPREL32, | |
912 | 0, /* rightshift */ | |
913 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
914 | 32, /* bitsize */ | |
915 | FALSE, /* pc_relative */ | |
916 | 0, /* bitpos */ | |
917 | complain_overflow_dont, /* complain_on_overflow */ | |
918 | ppc_elf_unhandled_reloc, /* special_function */ | |
919 | "R_PPC_TPREL32", /* name */ | |
920 | FALSE, /* partial_inplace */ | |
921 | 0, /* src_mask */ | |
922 | 0xffffffff, /* dst_mask */ | |
923 | FALSE), /* pcrel_offset */ | |
924 | ||
925 | /* A 16 bit tprel reloc. */ | |
926 | HOWTO (R_PPC_TPREL16, | |
252b5132 RH |
927 | 0, /* rightshift */ |
928 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
929 | 16, /* bitsize */ | |
b34976b6 | 930 | FALSE, /* pc_relative */ |
252b5132 | 931 | 0, /* bitpos */ |
7619e7c7 AM |
932 | complain_overflow_signed, /* complain_on_overflow */ |
933 | ppc_elf_unhandled_reloc, /* special_function */ | |
934 | "R_PPC_TPREL16", /* name */ | |
b34976b6 | 935 | FALSE, /* partial_inplace */ |
252b5132 RH |
936 | 0, /* src_mask */ |
937 | 0xffff, /* dst_mask */ | |
b34976b6 | 938 | FALSE), /* pcrel_offset */ |
252b5132 | 939 | |
7619e7c7 AM |
940 | /* Like TPREL16, but no overflow. */ |
941 | HOWTO (R_PPC_TPREL16_LO, | |
252b5132 RH |
942 | 0, /* rightshift */ |
943 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
944 | 16, /* bitsize */ | |
b34976b6 | 945 | FALSE, /* pc_relative */ |
252b5132 | 946 | 0, /* bitpos */ |
7619e7c7 AM |
947 | complain_overflow_dont, /* complain_on_overflow */ |
948 | ppc_elf_unhandled_reloc, /* special_function */ | |
949 | "R_PPC_TPREL16_LO", /* name */ | |
b34976b6 | 950 | FALSE, /* partial_inplace */ |
252b5132 RH |
951 | 0, /* src_mask */ |
952 | 0xffff, /* dst_mask */ | |
b34976b6 | 953 | FALSE), /* pcrel_offset */ |
252b5132 | 954 | |
7619e7c7 AM |
955 | /* Like TPREL16_LO, but next higher group of 16 bits. */ |
956 | HOWTO (R_PPC_TPREL16_HI, | |
957 | 16, /* rightshift */ | |
958 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
959 | 16, /* bitsize */ | |
960 | FALSE, /* pc_relative */ | |
961 | 0, /* bitpos */ | |
962 | complain_overflow_dont, /* complain_on_overflow */ | |
963 | ppc_elf_unhandled_reloc, /* special_function */ | |
964 | "R_PPC_TPREL16_HI", /* name */ | |
965 | FALSE, /* partial_inplace */ | |
966 | 0, /* src_mask */ | |
967 | 0xffff, /* dst_mask */ | |
968 | FALSE), /* pcrel_offset */ | |
969 | ||
970 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
971 | HOWTO (R_PPC_TPREL16_HA, | |
972 | 16, /* rightshift */ | |
973 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
974 | 16, /* bitsize */ | |
975 | FALSE, /* pc_relative */ | |
976 | 0, /* bitpos */ | |
977 | complain_overflow_dont, /* complain_on_overflow */ | |
978 | ppc_elf_unhandled_reloc, /* special_function */ | |
979 | "R_PPC_TPREL16_HA", /* name */ | |
980 | FALSE, /* partial_inplace */ | |
981 | 0, /* src_mask */ | |
982 | 0xffff, /* dst_mask */ | |
983 | FALSE), /* pcrel_offset */ | |
984 | ||
985 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
986 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
987 | to the first entry. */ | |
988 | HOWTO (R_PPC_GOT_TLSGD16, | |
252b5132 RH |
989 | 0, /* rightshift */ |
990 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
991 | 16, /* bitsize */ | |
b34976b6 | 992 | FALSE, /* pc_relative */ |
252b5132 RH |
993 | 0, /* bitpos */ |
994 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
995 | ppc_elf_unhandled_reloc, /* special_function */ |
996 | "R_PPC_GOT_TLSGD16", /* name */ | |
b34976b6 | 997 | FALSE, /* partial_inplace */ |
252b5132 RH |
998 | 0, /* src_mask */ |
999 | 0xffff, /* dst_mask */ | |
b34976b6 | 1000 | FALSE), /* pcrel_offset */ |
252b5132 | 1001 | |
7619e7c7 AM |
1002 | /* Like GOT_TLSGD16, but no overflow. */ |
1003 | HOWTO (R_PPC_GOT_TLSGD16_LO, | |
252b5132 | 1004 | 0, /* rightshift */ |
7619e7c7 | 1005 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 1006 | 16, /* bitsize */ |
b34976b6 | 1007 | FALSE, /* pc_relative */ |
252b5132 | 1008 | 0, /* bitpos */ |
7619e7c7 AM |
1009 | complain_overflow_dont, /* complain_on_overflow */ |
1010 | ppc_elf_unhandled_reloc, /* special_function */ | |
1011 | "R_PPC_GOT_TLSGD16_LO", /* name */ | |
b34976b6 | 1012 | FALSE, /* partial_inplace */ |
252b5132 RH |
1013 | 0, /* src_mask */ |
1014 | 0xffff, /* dst_mask */ | |
b34976b6 | 1015 | FALSE), /* pcrel_offset */ |
252b5132 | 1016 | |
7619e7c7 AM |
1017 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1018 | HOWTO (R_PPC_GOT_TLSGD16_HI, | |
1019 | 16, /* rightshift */ | |
1020 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1021 | 16, /* bitsize */ | |
1022 | FALSE, /* pc_relative */ | |
1023 | 0, /* bitpos */ | |
1024 | complain_overflow_dont, /* complain_on_overflow */ | |
1025 | ppc_elf_unhandled_reloc, /* special_function */ | |
1026 | "R_PPC_GOT_TLSGD16_HI", /* name */ | |
1027 | FALSE, /* partial_inplace */ | |
1028 | 0, /* src_mask */ | |
1029 | 0xffff, /* dst_mask */ | |
1030 | FALSE), /* pcrel_offset */ | |
252b5132 | 1031 | |
7619e7c7 AM |
1032 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1033 | HOWTO (R_PPC_GOT_TLSGD16_HA, | |
1034 | 16, /* rightshift */ | |
1035 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1036 | 16, /* bitsize */ | |
1037 | FALSE, /* pc_relative */ | |
1038 | 0, /* bitpos */ | |
1039 | complain_overflow_dont, /* complain_on_overflow */ | |
1040 | ppc_elf_unhandled_reloc, /* special_function */ | |
1041 | "R_PPC_GOT_TLSGD16_HA", /* name */ | |
1042 | FALSE, /* partial_inplace */ | |
1043 | 0, /* src_mask */ | |
1044 | 0xffff, /* dst_mask */ | |
1045 | FALSE), /* pcrel_offset */ | |
1046 | ||
1047 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1048 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1049 | first entry. */ | |
1050 | HOWTO (R_PPC_GOT_TLSLD16, | |
252b5132 RH |
1051 | 0, /* rightshift */ |
1052 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1053 | 16, /* bitsize */ | |
7619e7c7 | 1054 | FALSE, /* pc_relative */ |
252b5132 RH |
1055 | 0, /* bitpos */ |
1056 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1057 | ppc_elf_unhandled_reloc, /* special_function */ |
1058 | "R_PPC_GOT_TLSLD16", /* name */ | |
b34976b6 | 1059 | FALSE, /* partial_inplace */ |
252b5132 RH |
1060 | 0, /* src_mask */ |
1061 | 0xffff, /* dst_mask */ | |
b34976b6 | 1062 | FALSE), /* pcrel_offset */ |
252b5132 | 1063 | |
7619e7c7 AM |
1064 | /* Like GOT_TLSLD16, but no overflow. */ |
1065 | HOWTO (R_PPC_GOT_TLSLD16_LO, | |
252b5132 | 1066 | 0, /* rightshift */ |
7619e7c7 AM |
1067 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1068 | 16, /* bitsize */ | |
b34976b6 | 1069 | FALSE, /* pc_relative */ |
252b5132 RH |
1070 | 0, /* bitpos */ |
1071 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1072 | ppc_elf_unhandled_reloc, /* special_function */ |
1073 | "R_PPC_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1074 | FALSE, /* partial_inplace */ |
252b5132 | 1075 | 0, /* src_mask */ |
7619e7c7 | 1076 | 0xffff, /* dst_mask */ |
b34976b6 | 1077 | FALSE), /* pcrel_offset */ |
252b5132 | 1078 | |
7619e7c7 AM |
1079 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1080 | HOWTO (R_PPC_GOT_TLSLD16_HI, | |
1081 | 16, /* rightshift */ | |
1082 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1083 | 16, /* bitsize */ | |
b34976b6 | 1084 | FALSE, /* pc_relative */ |
252b5132 RH |
1085 | 0, /* bitpos */ |
1086 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1087 | ppc_elf_unhandled_reloc, /* special_function */ |
1088 | "R_PPC_GOT_TLSLD16_HI", /* name */ | |
b34976b6 | 1089 | FALSE, /* partial_inplace */ |
252b5132 | 1090 | 0, /* src_mask */ |
7619e7c7 | 1091 | 0xffff, /* dst_mask */ |
b34976b6 | 1092 | FALSE), /* pcrel_offset */ |
252b5132 | 1093 | |
7619e7c7 AM |
1094 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1095 | HOWTO (R_PPC_GOT_TLSLD16_HA, | |
1096 | 16, /* rightshift */ | |
1097 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1098 | 16, /* bitsize */ | |
1099 | FALSE, /* pc_relative */ | |
1100 | 0, /* bitpos */ | |
1101 | complain_overflow_dont, /* complain_on_overflow */ | |
1102 | ppc_elf_unhandled_reloc, /* special_function */ | |
1103 | "R_PPC_GOT_TLSLD16_HA", /* name */ | |
1104 | FALSE, /* partial_inplace */ | |
1105 | 0, /* src_mask */ | |
1106 | 0xffff, /* dst_mask */ | |
1107 | FALSE), /* pcrel_offset */ | |
1108 | ||
1109 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes | |
1110 | the offset to the entry. */ | |
1111 | HOWTO (R_PPC_GOT_DTPREL16, | |
252b5132 RH |
1112 | 0, /* rightshift */ |
1113 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1114 | 16, /* bitsize */ | |
b34976b6 | 1115 | FALSE, /* pc_relative */ |
252b5132 RH |
1116 | 0, /* bitpos */ |
1117 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1118 | ppc_elf_unhandled_reloc, /* special_function */ |
1119 | "R_PPC_GOT_DTPREL16", /* name */ | |
b34976b6 | 1120 | FALSE, /* partial_inplace */ |
252b5132 RH |
1121 | 0, /* src_mask */ |
1122 | 0xffff, /* dst_mask */ | |
b34976b6 | 1123 | FALSE), /* pcrel_offset */ |
252b5132 | 1124 | |
7619e7c7 AM |
1125 | /* Like GOT_DTPREL16, but no overflow. */ |
1126 | HOWTO (R_PPC_GOT_DTPREL16_LO, | |
1127 | 0, /* rightshift */ | |
1128 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1129 | 16, /* bitsize */ | |
1130 | FALSE, /* pc_relative */ | |
1131 | 0, /* bitpos */ | |
1132 | complain_overflow_dont, /* complain_on_overflow */ | |
1133 | ppc_elf_unhandled_reloc, /* special_function */ | |
1134 | "R_PPC_GOT_DTPREL16_LO", /* name */ | |
1135 | FALSE, /* partial_inplace */ | |
1136 | 0, /* src_mask */ | |
1137 | 0xffff, /* dst_mask */ | |
1138 | FALSE), /* pcrel_offset */ | |
252b5132 | 1139 | |
7619e7c7 AM |
1140 | /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */ |
1141 | HOWTO (R_PPC_GOT_DTPREL16_HI, | |
1142 | 16, /* rightshift */ | |
1143 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1144 | 16, /* bitsize */ | |
1145 | FALSE, /* pc_relative */ | |
1146 | 0, /* bitpos */ | |
1147 | complain_overflow_dont, /* complain_on_overflow */ | |
1148 | ppc_elf_unhandled_reloc, /* special_function */ | |
1149 | "R_PPC_GOT_DTPREL16_HI", /* name */ | |
1150 | FALSE, /* partial_inplace */ | |
1151 | 0, /* src_mask */ | |
1152 | 0xffff, /* dst_mask */ | |
1153 | FALSE), /* pcrel_offset */ | |
252b5132 | 1154 | |
7619e7c7 AM |
1155 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1156 | HOWTO (R_PPC_GOT_DTPREL16_HA, | |
1157 | 16, /* rightshift */ | |
1158 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1159 | 16, /* bitsize */ | |
1160 | FALSE, /* pc_relative */ | |
1161 | 0, /* bitpos */ | |
1162 | complain_overflow_dont, /* complain_on_overflow */ | |
1163 | ppc_elf_unhandled_reloc, /* special_function */ | |
1164 | "R_PPC_GOT_DTPREL16_HA", /* name */ | |
1165 | FALSE, /* partial_inplace */ | |
1166 | 0, /* src_mask */ | |
1167 | 0xffff, /* dst_mask */ | |
1168 | FALSE), /* pcrel_offset */ | |
c3668558 | 1169 | |
7619e7c7 AM |
1170 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the |
1171 | offset to the entry. */ | |
1172 | HOWTO (R_PPC_GOT_TPREL16, | |
1173 | 0, /* rightshift */ | |
1174 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1175 | 16, /* bitsize */ | |
1176 | FALSE, /* pc_relative */ | |
1177 | 0, /* bitpos */ | |
1178 | complain_overflow_signed, /* complain_on_overflow */ | |
1179 | ppc_elf_unhandled_reloc, /* special_function */ | |
1180 | "R_PPC_GOT_TPREL16", /* name */ | |
1181 | FALSE, /* partial_inplace */ | |
1182 | 0, /* src_mask */ | |
1183 | 0xffff, /* dst_mask */ | |
1184 | FALSE), /* pcrel_offset */ | |
1185 | ||
1186 | /* Like GOT_TPREL16, but no overflow. */ | |
1187 | HOWTO (R_PPC_GOT_TPREL16_LO, | |
1188 | 0, /* rightshift */ | |
1189 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1190 | 16, /* bitsize */ | |
1191 | FALSE, /* pc_relative */ | |
1192 | 0, /* bitpos */ | |
1193 | complain_overflow_dont, /* complain_on_overflow */ | |
1194 | ppc_elf_unhandled_reloc, /* special_function */ | |
1195 | "R_PPC_GOT_TPREL16_LO", /* name */ | |
1196 | FALSE, /* partial_inplace */ | |
1197 | 0, /* src_mask */ | |
1198 | 0xffff, /* dst_mask */ | |
1199 | FALSE), /* pcrel_offset */ | |
1200 | ||
1201 | /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */ | |
1202 | HOWTO (R_PPC_GOT_TPREL16_HI, | |
1203 | 16, /* rightshift */ | |
1204 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1205 | 16, /* bitsize */ | |
1206 | FALSE, /* pc_relative */ | |
1207 | 0, /* bitpos */ | |
1208 | complain_overflow_dont, /* complain_on_overflow */ | |
1209 | ppc_elf_unhandled_reloc, /* special_function */ | |
1210 | "R_PPC_GOT_TPREL16_HI", /* name */ | |
1211 | FALSE, /* partial_inplace */ | |
1212 | 0, /* src_mask */ | |
1213 | 0xffff, /* dst_mask */ | |
1214 | FALSE), /* pcrel_offset */ | |
1215 | ||
1216 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ | |
1217 | HOWTO (R_PPC_GOT_TPREL16_HA, | |
1218 | 16, /* rightshift */ | |
1219 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1220 | 16, /* bitsize */ | |
1221 | FALSE, /* pc_relative */ | |
1222 | 0, /* bitpos */ | |
1223 | complain_overflow_dont, /* complain_on_overflow */ | |
1224 | ppc_elf_unhandled_reloc, /* special_function */ | |
1225 | "R_PPC_GOT_TPREL16_HA", /* name */ | |
1226 | FALSE, /* partial_inplace */ | |
1227 | 0, /* src_mask */ | |
1228 | 0xffff, /* dst_mask */ | |
1229 | FALSE), /* pcrel_offset */ | |
1230 | ||
1231 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
1232 | in the SVR4 ELF ABI. */ | |
1233 | ||
1234 | /* 32 bit value resulting from the addend minus the symbol. */ | |
1235 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
1236 | 0, /* rightshift */ | |
1237 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1238 | 32, /* bitsize */ | |
1239 | FALSE, /* pc_relative */ | |
1240 | 0, /* bitpos */ | |
86c95733 | 1241 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 1242 | ppc_elf_unhandled_reloc, /* special_function */ |
7619e7c7 AM |
1243 | "R_PPC_EMB_NADDR32", /* name */ |
1244 | FALSE, /* partial_inplace */ | |
1245 | 0, /* src_mask */ | |
1246 | 0xffffffff, /* dst_mask */ | |
1247 | FALSE), /* pcrel_offset */ | |
1248 | ||
1249 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1250 | HOWTO (R_PPC_EMB_NADDR16, /* type */ | |
1251 | 0, /* rightshift */ | |
1252 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1253 | 16, /* bitsize */ | |
1254 | FALSE, /* pc_relative */ | |
1255 | 0, /* bitpos */ | |
86c95733 | 1256 | complain_overflow_signed, /* complain_on_overflow */ |
3ce51288 | 1257 | ppc_elf_unhandled_reloc, /* special_function */ |
7619e7c7 AM |
1258 | "R_PPC_EMB_NADDR16", /* name */ |
1259 | FALSE, /* partial_inplace */ | |
1260 | 0, /* src_mask */ | |
1261 | 0xffff, /* dst_mask */ | |
1262 | FALSE), /* pcrel_offset */ | |
1263 | ||
1264 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1265 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
1266 | 0, /* rightshift */ | |
1267 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1268 | 16, /* bitsize */ | |
1269 | FALSE, /* pc_relative */ | |
1270 | 0, /* bitpos */ | |
1271 | complain_overflow_dont,/* complain_on_overflow */ | |
3ce51288 | 1272 | ppc_elf_unhandled_reloc, /* special_function */ |
7619e7c7 AM |
1273 | "R_PPC_EMB_ADDR16_LO", /* name */ |
1274 | FALSE, /* partial_inplace */ | |
1275 | 0, /* src_mask */ | |
1276 | 0xffff, /* dst_mask */ | |
1277 | FALSE), /* pcrel_offset */ | |
1278 | ||
1279 | /* The high order 16 bits of the addend minus the symbol. */ | |
1280 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
1281 | 16, /* rightshift */ | |
1282 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1283 | 16, /* bitsize */ | |
1284 | FALSE, /* pc_relative */ | |
1285 | 0, /* bitpos */ | |
1286 | complain_overflow_dont, /* complain_on_overflow */ | |
3ce51288 | 1287 | ppc_elf_unhandled_reloc, /* special_function */ |
7619e7c7 AM |
1288 | "R_PPC_EMB_NADDR16_HI", /* name */ |
1289 | FALSE, /* partial_inplace */ | |
1290 | 0, /* src_mask */ | |
1291 | 0xffff, /* dst_mask */ | |
1292 | FALSE), /* pcrel_offset */ | |
1293 | ||
1294 | /* The high order 16 bits of the result of the addend minus the address, | |
1295 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
1296 | is negative. */ | |
1297 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ | |
1298 | 16, /* rightshift */ | |
1299 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1300 | 16, /* bitsize */ | |
1301 | FALSE, /* pc_relative */ | |
1302 | 0, /* bitpos */ | |
1303 | complain_overflow_dont, /* complain_on_overflow */ | |
3ce51288 | 1304 | ppc_elf_unhandled_reloc, /* special_function */ |
25dbc73a AM |
1305 | "R_PPC_EMB_NADDR16_HA", /* name */ |
1306 | FALSE, /* partial_inplace */ | |
1307 | 0, /* src_mask */ | |
1308 | 0xffff, /* dst_mask */ | |
1309 | FALSE), /* pcrel_offset */ | |
1310 | ||
1311 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1312 | address in the .sdata section, and returning the offset from | |
1313 | _SDA_BASE_ for that relocation. */ | |
1314 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
1315 | 0, /* rightshift */ | |
1316 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1317 | 16, /* bitsize */ | |
1318 | FALSE, /* pc_relative */ | |
1319 | 0, /* bitpos */ | |
bd6c6e2b | 1320 | complain_overflow_signed, /* complain_on_overflow */ |
3ce51288 | 1321 | ppc_elf_unhandled_reloc, /* special_function */ |
25dbc73a AM |
1322 | "R_PPC_EMB_SDAI16", /* name */ |
1323 | FALSE, /* partial_inplace */ | |
1324 | 0, /* src_mask */ | |
1325 | 0xffff, /* dst_mask */ | |
1326 | FALSE), /* pcrel_offset */ | |
1327 | ||
1328 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1329 | address in the .sdata2 section, and returning the offset from | |
1330 | _SDA2_BASE_ for that relocation. */ | |
1331 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
1332 | 0, /* rightshift */ | |
1333 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1334 | 16, /* bitsize */ | |
1335 | FALSE, /* pc_relative */ | |
1336 | 0, /* bitpos */ | |
bd6c6e2b | 1337 | complain_overflow_signed, /* complain_on_overflow */ |
3ce51288 | 1338 | ppc_elf_unhandled_reloc, /* special_function */ |
25dbc73a AM |
1339 | "R_PPC_EMB_SDA2I16", /* name */ |
1340 | FALSE, /* partial_inplace */ | |
1341 | 0, /* src_mask */ | |
1342 | 0xffff, /* dst_mask */ | |
1343 | FALSE), /* pcrel_offset */ | |
1344 | ||
1345 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
1346 | small data items. */ | |
1347 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
1348 | 0, /* rightshift */ | |
1349 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1350 | 16, /* bitsize */ | |
1351 | FALSE, /* pc_relative */ | |
1352 | 0, /* bitpos */ | |
1353 | complain_overflow_signed, /* complain_on_overflow */ | |
3ce51288 | 1354 | ppc_elf_unhandled_reloc, /* special_function */ |
25dbc73a AM |
1355 | "R_PPC_EMB_SDA2REL", /* name */ |
1356 | FALSE, /* partial_inplace */ | |
1357 | 0, /* src_mask */ | |
1358 | 0xffff, /* dst_mask */ | |
1359 | FALSE), /* pcrel_offset */ | |
1360 | ||
1361 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
1362 | signed offset from the appropriate base, and filling in the register | |
1363 | field with the appropriate register (0, 2, or 13). */ | |
1364 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
1365 | 0, /* rightshift */ | |
1366 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1367 | 16, /* bitsize */ | |
1368 | FALSE, /* pc_relative */ | |
1369 | 0, /* bitpos */ | |
1370 | complain_overflow_signed, /* complain_on_overflow */ | |
3ce51288 | 1371 | ppc_elf_unhandled_reloc, /* special_function */ |
25dbc73a AM |
1372 | "R_PPC_EMB_SDA21", /* name */ |
1373 | FALSE, /* partial_inplace */ | |
1374 | 0, /* src_mask */ | |
1375 | 0xffff, /* dst_mask */ | |
1376 | FALSE), /* pcrel_offset */ | |
1377 | ||
1378 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
1379 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
1380 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
1381 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
1382 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
1383 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
1384 | ||
1385 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
1386 | in the 16 bit signed offset from the appropriate base, and filling in the | |
1387 | register field with the appropriate register (0, 2, or 13). */ | |
1388 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
1389 | 0, /* rightshift */ | |
1390 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1391 | 16, /* bitsize */ | |
ddfd6795 | 1392 | FALSE, /* pc_relative */ |
25dbc73a AM |
1393 | 0, /* bitpos */ |
1394 | complain_overflow_signed, /* complain_on_overflow */ | |
3ce51288 | 1395 | ppc_elf_unhandled_reloc, /* special_function */ |
25dbc73a AM |
1396 | "R_PPC_EMB_RELSDA", /* name */ |
1397 | FALSE, /* partial_inplace */ | |
1398 | 0, /* src_mask */ | |
1399 | 0xffff, /* dst_mask */ | |
1400 | FALSE), /* pcrel_offset */ | |
1401 | ||
b9c361e0 JL |
1402 | /* A relative 8 bit branch. */ |
1403 | HOWTO (R_PPC_VLE_REL8, /* type */ | |
1404 | 1, /* rightshift */ | |
1405 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1406 | 8, /* bitsize */ | |
1407 | TRUE, /* pc_relative */ | |
1408 | 0, /* bitpos */ | |
1409 | complain_overflow_signed, /* complain_on_overflow */ | |
1410 | bfd_elf_generic_reloc, /* special_function */ | |
1411 | "R_PPC_VLE_REL8", /* name */ | |
1412 | FALSE, /* partial_inplace */ | |
1413 | 0, /* src_mask */ | |
1414 | 0xff, /* dst_mask */ | |
1415 | TRUE), /* pcrel_offset */ | |
68ffbac6 | 1416 | |
b9c361e0 JL |
1417 | /* A relative 15 bit branch. */ |
1418 | HOWTO (R_PPC_VLE_REL15, /* type */ | |
1419 | 1, /* rightshift */ | |
1420 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1421 | 15, /* bitsize */ | |
1422 | TRUE, /* pc_relative */ | |
1423 | 1, /* bitpos */ | |
1424 | complain_overflow_signed, /* complain_on_overflow */ | |
1425 | bfd_elf_generic_reloc, /* special_function */ | |
1426 | "R_PPC_VLE_REL15", /* name */ | |
1427 | FALSE, /* partial_inplace */ | |
1428 | 0, /* src_mask */ | |
dfdaec14 | 1429 | 0xfffe, /* dst_mask */ |
b9c361e0 JL |
1430 | TRUE), /* pcrel_offset */ |
1431 | ||
68ffbac6 | 1432 | /* A relative 24 bit branch. */ |
b9c361e0 JL |
1433 | HOWTO (R_PPC_VLE_REL24, /* type */ |
1434 | 1, /* rightshift */ | |
1435 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1436 | 24, /* bitsize */ | |
1437 | TRUE, /* pc_relative */ | |
1438 | 1, /* bitpos */ | |
1439 | complain_overflow_signed, /* complain_on_overflow */ | |
1440 | bfd_elf_generic_reloc, /* special_function */ | |
1441 | "R_PPC_VLE_REL24", /* name */ | |
1442 | FALSE, /* partial_inplace */ | |
1443 | 0, /* src_mask */ | |
1444 | 0x1fffffe, /* dst_mask */ | |
1445 | TRUE), /* pcrel_offset */ | |
1446 | ||
1447 | /* The 16 LSBS in split16a format. */ | |
1448 | HOWTO (R_PPC_VLE_LO16A, /* type */ | |
1449 | 0, /* rightshift */ | |
1450 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
86c95733 | 1451 | 16, /* bitsize */ |
bdaacd3a | 1452 | FALSE, /* pc_relative */ |
b9c361e0 | 1453 | 0, /* bitpos */ |
86c95733 | 1454 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 1455 | ppc_elf_unhandled_reloc, /* special_function */ |
b9c361e0 JL |
1456 | "R_PPC_VLE_LO16A", /* name */ |
1457 | FALSE, /* partial_inplace */ | |
1458 | 0, /* src_mask */ | |
08dc996f | 1459 | 0x1f07ff, /* dst_mask */ |
b9c361e0 JL |
1460 | FALSE), /* pcrel_offset */ |
1461 | ||
1462 | /* The 16 LSBS in split16d format. */ | |
1463 | HOWTO (R_PPC_VLE_LO16D, /* type */ | |
1464 | 0, /* rightshift */ | |
1465 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
86c95733 | 1466 | 16, /* bitsize */ |
b9c361e0 JL |
1467 | FALSE, /* pc_relative */ |
1468 | 0, /* bitpos */ | |
86c95733 | 1469 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 AM |
1470 | ppc_elf_unhandled_reloc, /* special_function */ |
1471 | "R_PPC_VLE_LO16D", /* name */ | |
b9c361e0 JL |
1472 | FALSE, /* partial_inplace */ |
1473 | 0, /* src_mask */ | |
5499c7c7 | 1474 | 0x3e007ff, /* dst_mask */ |
b9c361e0 JL |
1475 | FALSE), /* pcrel_offset */ |
1476 | ||
1477 | /* Bits 16-31 split16a format. */ | |
1478 | HOWTO (R_PPC_VLE_HI16A, /* type */ | |
86c95733 | 1479 | 16, /* rightshift */ |
b9c361e0 | 1480 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1481 | 16, /* bitsize */ |
b9c361e0 JL |
1482 | FALSE, /* pc_relative */ |
1483 | 0, /* bitpos */ | |
86c95733 | 1484 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 AM |
1485 | ppc_elf_unhandled_reloc, /* special_function */ |
1486 | "R_PPC_VLE_HI16A", /* name */ | |
b9c361e0 JL |
1487 | FALSE, /* partial_inplace */ |
1488 | 0, /* src_mask */ | |
08dc996f | 1489 | 0x1f07ff, /* dst_mask */ |
b9c361e0 JL |
1490 | FALSE), /* pcrel_offset */ |
1491 | ||
1492 | /* Bits 16-31 split16d format. */ | |
1493 | HOWTO (R_PPC_VLE_HI16D, /* type */ | |
86c95733 | 1494 | 16, /* rightshift */ |
b9c361e0 | 1495 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1496 | 16, /* bitsize */ |
b9c361e0 JL |
1497 | FALSE, /* pc_relative */ |
1498 | 0, /* bitpos */ | |
86c95733 | 1499 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 AM |
1500 | ppc_elf_unhandled_reloc, /* special_function */ |
1501 | "R_PPC_VLE_HI16D", /* name */ | |
b9c361e0 JL |
1502 | FALSE, /* partial_inplace */ |
1503 | 0, /* src_mask */ | |
5499c7c7 | 1504 | 0x3e007ff, /* dst_mask */ |
b9c361e0 JL |
1505 | FALSE), /* pcrel_offset */ |
1506 | ||
1507 | /* Bits 16-31 (High Adjusted) in split16a format. */ | |
1508 | HOWTO (R_PPC_VLE_HA16A, /* type */ | |
86c95733 | 1509 | 16, /* rightshift */ |
b9c361e0 | 1510 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1511 | 16, /* bitsize */ |
b9c361e0 JL |
1512 | FALSE, /* pc_relative */ |
1513 | 0, /* bitpos */ | |
86c95733 | 1514 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 AM |
1515 | ppc_elf_unhandled_reloc, /* special_function */ |
1516 | "R_PPC_VLE_HA16A", /* name */ | |
b9c361e0 JL |
1517 | FALSE, /* partial_inplace */ |
1518 | 0, /* src_mask */ | |
08dc996f | 1519 | 0x1f07ff, /* dst_mask */ |
b9c361e0 JL |
1520 | FALSE), /* pcrel_offset */ |
1521 | ||
1522 | /* Bits 16-31 (High Adjusted) in split16d format. */ | |
1523 | HOWTO (R_PPC_VLE_HA16D, /* type */ | |
86c95733 | 1524 | 16, /* rightshift */ |
b9c361e0 | 1525 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1526 | 16, /* bitsize */ |
b9c361e0 JL |
1527 | FALSE, /* pc_relative */ |
1528 | 0, /* bitpos */ | |
86c95733 | 1529 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 AM |
1530 | ppc_elf_unhandled_reloc, /* special_function */ |
1531 | "R_PPC_VLE_HA16D", /* name */ | |
b9c361e0 JL |
1532 | FALSE, /* partial_inplace */ |
1533 | 0, /* src_mask */ | |
5499c7c7 | 1534 | 0x3e007ff, /* dst_mask */ |
b9c361e0 JL |
1535 | FALSE), /* pcrel_offset */ |
1536 | ||
86c95733 AM |
1537 | /* This reloc is like R_PPC_EMB_SDA21 but only applies to e_add16i |
1538 | instructions. If the register base is 0 then the linker changes | |
1539 | the e_add16i to an e_li instruction. */ | |
1540 | HOWTO (R_PPC_VLE_SDA21, /* type */ | |
b9c361e0 JL |
1541 | 0, /* rightshift */ |
1542 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
86c95733 | 1543 | 16, /* bitsize */ |
b9c361e0 JL |
1544 | FALSE, /* pc_relative */ |
1545 | 0, /* bitpos */ | |
86c95733 | 1546 | complain_overflow_signed, /* complain_on_overflow */ |
3ce51288 AM |
1547 | ppc_elf_unhandled_reloc, /* special_function */ |
1548 | "R_PPC_VLE_SDA21", /* name */ | |
b9c361e0 JL |
1549 | FALSE, /* partial_inplace */ |
1550 | 0, /* src_mask */ | |
1551 | 0xffff, /* dst_mask */ | |
1552 | FALSE), /* pcrel_offset */ | |
1553 | ||
86c95733 | 1554 | /* Like R_PPC_VLE_SDA21 but ignore overflow. */ |
b9c361e0 JL |
1555 | HOWTO (R_PPC_VLE_SDA21_LO, /* type */ |
1556 | 0, /* rightshift */ | |
1557 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
86c95733 | 1558 | 16, /* bitsize */ |
b9c361e0 JL |
1559 | FALSE, /* pc_relative */ |
1560 | 0, /* bitpos */ | |
86c95733 | 1561 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 1562 | ppc_elf_unhandled_reloc, /* special_function */ |
b9c361e0 JL |
1563 | "R_PPC_VLE_SDA21_LO", /* name */ |
1564 | FALSE, /* partial_inplace */ | |
1565 | 0, /* src_mask */ | |
86c95733 | 1566 | 0xffff, /* dst_mask */ |
b9c361e0 JL |
1567 | FALSE), /* pcrel_offset */ |
1568 | ||
1569 | /* The 16 LSBS relative to _SDA_BASE_ in split16a format. */ | |
1570 | HOWTO (R_PPC_VLE_SDAREL_LO16A,/* type */ | |
1571 | 0, /* rightshift */ | |
1572 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
86c95733 | 1573 | 16, /* bitsize */ |
b9c361e0 JL |
1574 | FALSE, /* pc_relative */ |
1575 | 0, /* bitpos */ | |
3ce51288 AM |
1576 | complain_overflow_dont, /* complain_on_overflow */ |
1577 | ppc_elf_unhandled_reloc, /* special_function */ | |
1578 | "R_PPC_VLE_SDAREL_LO16A", /* name */ | |
b9c361e0 JL |
1579 | FALSE, /* partial_inplace */ |
1580 | 0, /* src_mask */ | |
08dc996f | 1581 | 0x1f07ff, /* dst_mask */ |
b9c361e0 JL |
1582 | FALSE), /* pcrel_offset */ |
1583 | ||
1584 | /* The 16 LSBS relative to _SDA_BASE_ in split16d format. */ | |
b9c361e0 JL |
1585 | HOWTO (R_PPC_VLE_SDAREL_LO16D, /* type */ |
1586 | 0, /* rightshift */ | |
1587 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
86c95733 | 1588 | 16, /* bitsize */ |
b9c361e0 JL |
1589 | FALSE, /* pc_relative */ |
1590 | 0, /* bitpos */ | |
3ce51288 AM |
1591 | complain_overflow_dont, /* complain_on_overflow */ |
1592 | ppc_elf_unhandled_reloc, /* special_function */ | |
1593 | "R_PPC_VLE_SDAREL_LO16D", /* name */ | |
b9c361e0 JL |
1594 | FALSE, /* partial_inplace */ |
1595 | 0, /* src_mask */ | |
5499c7c7 | 1596 | 0x3e007ff, /* dst_mask */ |
b9c361e0 JL |
1597 | FALSE), /* pcrel_offset */ |
1598 | ||
1599 | /* Bits 16-31 relative to _SDA_BASE_ in split16a format. */ | |
3ce51288 | 1600 | HOWTO (R_PPC_VLE_SDAREL_HI16A, /* type */ |
86c95733 | 1601 | 16, /* rightshift */ |
b9c361e0 | 1602 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1603 | 16, /* bitsize */ |
b9c361e0 JL |
1604 | FALSE, /* pc_relative */ |
1605 | 0, /* bitpos */ | |
3ce51288 AM |
1606 | complain_overflow_dont, /* complain_on_overflow */ |
1607 | ppc_elf_unhandled_reloc, /* special_function */ | |
1608 | "R_PPC_VLE_SDAREL_HI16A", /* name */ | |
b9c361e0 JL |
1609 | FALSE, /* partial_inplace */ |
1610 | 0, /* src_mask */ | |
08dc996f | 1611 | 0x1f07ff, /* dst_mask */ |
b9c361e0 JL |
1612 | FALSE), /* pcrel_offset */ |
1613 | ||
1614 | /* Bits 16-31 relative to _SDA_BASE_ in split16d format. */ | |
3ce51288 | 1615 | HOWTO (R_PPC_VLE_SDAREL_HI16D, /* type */ |
86c95733 | 1616 | 16, /* rightshift */ |
b9c361e0 | 1617 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1618 | 16, /* bitsize */ |
b9c361e0 JL |
1619 | FALSE, /* pc_relative */ |
1620 | 0, /* bitpos */ | |
3ce51288 AM |
1621 | complain_overflow_dont, /* complain_on_overflow */ |
1622 | ppc_elf_unhandled_reloc, /* special_function */ | |
1623 | "R_PPC_VLE_SDAREL_HI16D", /* name */ | |
b9c361e0 JL |
1624 | FALSE, /* partial_inplace */ |
1625 | 0, /* src_mask */ | |
5499c7c7 | 1626 | 0x3e007ff, /* dst_mask */ |
b9c361e0 JL |
1627 | FALSE), /* pcrel_offset */ |
1628 | ||
1629 | /* Bits 16-31 (HA) relative to _SDA_BASE split16a format. */ | |
3ce51288 | 1630 | HOWTO (R_PPC_VLE_SDAREL_HA16A, /* type */ |
86c95733 | 1631 | 16, /* rightshift */ |
b9c361e0 | 1632 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1633 | 16, /* bitsize */ |
b9c361e0 JL |
1634 | FALSE, /* pc_relative */ |
1635 | 0, /* bitpos */ | |
3ce51288 AM |
1636 | complain_overflow_dont, /* complain_on_overflow */ |
1637 | ppc_elf_unhandled_reloc, /* special_function */ | |
1638 | "R_PPC_VLE_SDAREL_HA16A", /* name */ | |
b9c361e0 JL |
1639 | FALSE, /* partial_inplace */ |
1640 | 0, /* src_mask */ | |
08dc996f | 1641 | 0x1f07ff, /* dst_mask */ |
b9c361e0 JL |
1642 | FALSE), /* pcrel_offset */ |
1643 | ||
1644 | /* Bits 16-31 (HA) relative to _SDA_BASE split16d format. */ | |
3ce51288 | 1645 | HOWTO (R_PPC_VLE_SDAREL_HA16D, /* type */ |
86c95733 | 1646 | 16, /* rightshift */ |
b9c361e0 | 1647 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
86c95733 | 1648 | 16, /* bitsize */ |
b9c361e0 JL |
1649 | FALSE, /* pc_relative */ |
1650 | 0, /* bitpos */ | |
3ce51288 AM |
1651 | complain_overflow_dont, /* complain_on_overflow */ |
1652 | ppc_elf_unhandled_reloc, /* special_function */ | |
1653 | "R_PPC_VLE_SDAREL_HA16D", /* name */ | |
b9c361e0 JL |
1654 | FALSE, /* partial_inplace */ |
1655 | 0, /* src_mask */ | |
5499c7c7 | 1656 | 0x3e007ff, /* dst_mask */ |
b9c361e0 JL |
1657 | FALSE), /* pcrel_offset */ |
1658 | ||
83eef883 AFB |
1659 | /* e_li split20 format. */ |
1660 | HOWTO (R_PPC_VLE_ADDR20, /* type */ | |
1661 | 16, /* rightshift */ | |
1662 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1663 | 20, /* bitsize */ | |
1664 | FALSE, /* pc_relative */ | |
1665 | 0, /* bitpos */ | |
1666 | complain_overflow_dont, /* complain_on_overflow */ | |
1667 | bfd_elf_generic_reloc, /* special_function */ | |
1668 | "R_PPC_VLE_ADDR20", /* name */ | |
1669 | FALSE, /* partial_inplace */ | |
1670 | 0, /* src_mask */ | |
1671 | 0x1f07ff, /* dst_mask */ | |
1672 | FALSE), /* pcrel_offset */ | |
1673 | ||
e054468f AM |
1674 | HOWTO (R_PPC_IRELATIVE, /* type */ |
1675 | 0, /* rightshift */ | |
1676 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1677 | 32, /* bitsize */ | |
1678 | FALSE, /* pc_relative */ | |
1679 | 0, /* bitpos */ | |
86c95733 | 1680 | complain_overflow_dont, /* complain_on_overflow */ |
3ce51288 | 1681 | ppc_elf_unhandled_reloc, /* special_function */ |
e054468f AM |
1682 | "R_PPC_IRELATIVE", /* name */ |
1683 | FALSE, /* partial_inplace */ | |
1684 | 0, /* src_mask */ | |
1685 | 0xffffffff, /* dst_mask */ | |
1686 | FALSE), /* pcrel_offset */ | |
1687 | ||
d7128ce4 AM |
1688 | /* A 16 bit relative relocation. */ |
1689 | HOWTO (R_PPC_REL16, /* type */ | |
1690 | 0, /* rightshift */ | |
1691 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1692 | 16, /* bitsize */ | |
1693 | TRUE, /* pc_relative */ | |
1694 | 0, /* bitpos */ | |
86c95733 | 1695 | complain_overflow_signed, /* complain_on_overflow */ |
d7128ce4 AM |
1696 | bfd_elf_generic_reloc, /* special_function */ |
1697 | "R_PPC_REL16", /* name */ | |
1698 | FALSE, /* partial_inplace */ | |
1699 | 0, /* src_mask */ | |
1700 | 0xffff, /* dst_mask */ | |
1701 | TRUE), /* pcrel_offset */ | |
1702 | ||
1703 | /* A 16 bit relative relocation without overflow. */ | |
1704 | HOWTO (R_PPC_REL16_LO, /* type */ | |
1705 | 0, /* rightshift */ | |
1706 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1707 | 16, /* bitsize */ | |
1708 | TRUE, /* pc_relative */ | |
1709 | 0, /* bitpos */ | |
1710 | complain_overflow_dont,/* complain_on_overflow */ | |
1711 | bfd_elf_generic_reloc, /* special_function */ | |
1712 | "R_PPC_REL16_LO", /* name */ | |
1713 | FALSE, /* partial_inplace */ | |
1714 | 0, /* src_mask */ | |
1715 | 0xffff, /* dst_mask */ | |
1716 | TRUE), /* pcrel_offset */ | |
1717 | ||
1718 | /* The high order 16 bits of a relative address. */ | |
1719 | HOWTO (R_PPC_REL16_HI, /* type */ | |
1720 | 16, /* rightshift */ | |
1721 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1722 | 16, /* bitsize */ | |
1723 | TRUE, /* pc_relative */ | |
1724 | 0, /* bitpos */ | |
1725 | complain_overflow_dont, /* complain_on_overflow */ | |
1726 | bfd_elf_generic_reloc, /* special_function */ | |
1727 | "R_PPC_REL16_HI", /* name */ | |
1728 | FALSE, /* partial_inplace */ | |
1729 | 0, /* src_mask */ | |
1730 | 0xffff, /* dst_mask */ | |
1731 | TRUE), /* pcrel_offset */ | |
1732 | ||
1733 | /* The high order 16 bits of a relative address, plus 1 if the contents of | |
1734 | the low 16 bits, treated as a signed number, is negative. */ | |
1735 | HOWTO (R_PPC_REL16_HA, /* type */ | |
1736 | 16, /* rightshift */ | |
1737 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1738 | 16, /* bitsize */ | |
1739 | TRUE, /* pc_relative */ | |
1740 | 0, /* bitpos */ | |
1741 | complain_overflow_dont, /* complain_on_overflow */ | |
1742 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1743 | "R_PPC_REL16_HA", /* name */ | |
1744 | FALSE, /* partial_inplace */ | |
1745 | 0, /* src_mask */ | |
1746 | 0xffff, /* dst_mask */ | |
1747 | TRUE), /* pcrel_offset */ | |
1748 | ||
a680de9a PB |
1749 | /* Like R_PPC_REL16_HA but for split field in addpcis. */ |
1750 | HOWTO (R_PPC_REL16DX_HA, /* type */ | |
1751 | 16, /* rightshift */ | |
1752 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1753 | 16, /* bitsize */ | |
1754 | TRUE, /* pc_relative */ | |
1755 | 0, /* bitpos */ | |
1756 | complain_overflow_signed, /* complain_on_overflow */ | |
1757 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1758 | "R_PPC_REL16DX_HA", /* name */ | |
1759 | FALSE, /* partial_inplace */ | |
1760 | 0, /* src_mask */ | |
1761 | 0x1fffc1, /* dst_mask */ | |
1762 | TRUE), /* pcrel_offset */ | |
1763 | ||
7ba71655 AM |
1764 | /* A split-field reloc for addpcis, non-relative (gas internal use only). */ |
1765 | HOWTO (R_PPC_16DX_HA, /* type */ | |
1766 | 16, /* rightshift */ | |
1767 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1768 | 16, /* bitsize */ | |
1769 | FALSE, /* pc_relative */ | |
1770 | 0, /* bitpos */ | |
1771 | complain_overflow_signed, /* complain_on_overflow */ | |
1772 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1773 | "R_PPC_16DX_HA", /* name */ | |
1774 | FALSE, /* partial_inplace */ | |
1775 | 0, /* src_mask */ | |
1776 | 0x1fffc1, /* dst_mask */ | |
1777 | FALSE), /* pcrel_offset */ | |
1778 | ||
25dbc73a AM |
1779 | /* GNU extension to record C++ vtable hierarchy. */ |
1780 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ | |
1781 | 0, /* rightshift */ | |
1782 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1783 | 0, /* bitsize */ | |
1784 | FALSE, /* pc_relative */ | |
1785 | 0, /* bitpos */ | |
1786 | complain_overflow_dont, /* complain_on_overflow */ | |
1787 | NULL, /* special_function */ | |
1788 | "R_PPC_GNU_VTINHERIT", /* name */ | |
1789 | FALSE, /* partial_inplace */ | |
1790 | 0, /* src_mask */ | |
1791 | 0, /* dst_mask */ | |
1792 | FALSE), /* pcrel_offset */ | |
1793 | ||
1794 | /* GNU extension to record C++ vtable member usage. */ | |
1795 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ | |
1796 | 0, /* rightshift */ | |
1797 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1798 | 0, /* bitsize */ | |
1799 | FALSE, /* pc_relative */ | |
1800 | 0, /* bitpos */ | |
1801 | complain_overflow_dont, /* complain_on_overflow */ | |
1802 | NULL, /* special_function */ | |
1803 | "R_PPC_GNU_VTENTRY", /* name */ | |
7619e7c7 AM |
1804 | FALSE, /* partial_inplace */ |
1805 | 0, /* src_mask */ | |
25dbc73a | 1806 | 0, /* dst_mask */ |
7619e7c7 AM |
1807 | FALSE), /* pcrel_offset */ |
1808 | ||
25dbc73a AM |
1809 | /* Phony reloc to handle AIX style TOC entries. */ |
1810 | HOWTO (R_PPC_TOC16, /* type */ | |
7619e7c7 AM |
1811 | 0, /* rightshift */ |
1812 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1813 | 16, /* bitsize */ | |
1814 | FALSE, /* pc_relative */ | |
1815 | 0, /* bitpos */ | |
25dbc73a | 1816 | complain_overflow_signed, /* complain_on_overflow */ |
3ce51288 | 1817 | ppc_elf_unhandled_reloc, /* special_function */ |
25dbc73a | 1818 | "R_PPC_TOC16", /* name */ |
7619e7c7 AM |
1819 | FALSE, /* partial_inplace */ |
1820 | 0, /* src_mask */ | |
1821 | 0xffff, /* dst_mask */ | |
1822 | FALSE), /* pcrel_offset */ | |
25dbc73a | 1823 | }; |
70a38d42 SDJ |
1824 | |
1825 | /* External 32-bit PPC structure for PRPSINFO. This structure is | |
1826 | ABI-defined, thus we choose to use char arrays here in order to | |
1827 | avoid dealing with different types in different architectures. | |
1828 | ||
1829 | The PPC 32-bit structure uses int for `pr_uid' and `pr_gid' while | |
1830 | most non-PPC architectures use `short int'. | |
1831 | ||
1832 | This structure will ultimately be written in the corefile's note | |
1833 | section, as the PRPSINFO. */ | |
1834 | ||
1835 | struct elf_external_ppc_linux_prpsinfo32 | |
1836 | { | |
1837 | char pr_state; /* Numeric process state. */ | |
1838 | char pr_sname; /* Char for pr_state. */ | |
1839 | char pr_zomb; /* Zombie. */ | |
1840 | char pr_nice; /* Nice val. */ | |
1841 | char pr_flag[4]; /* Flags. */ | |
1842 | char pr_uid[4]; | |
1843 | char pr_gid[4]; | |
1844 | char pr_pid[4]; | |
1845 | char pr_ppid[4]; | |
1846 | char pr_pgrp[4]; | |
1847 | char pr_sid[4]; | |
1848 | char pr_fname[16]; /* Filename of executable. */ | |
1849 | char pr_psargs[80]; /* Initial part of arg list. */ | |
1850 | }; | |
1851 | ||
aeb70569 AM |
1852 | /* Helper function to copy an elf_internal_linux_prpsinfo in host |
1853 | endian to an elf_external_ppc_linux_prpsinfo32 in target endian. */ | |
70a38d42 | 1854 | |
aeb70569 AM |
1855 | static inline void |
1856 | swap_ppc_linux_prpsinfo32_out (bfd *obfd, | |
1857 | const struct elf_internal_linux_prpsinfo *from, | |
1858 | struct elf_external_ppc_linux_prpsinfo32 *to) | |
1859 | { | |
1860 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
1861 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
1862 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
1863 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
1864 | bfd_put_32 (obfd, from->pr_flag, to->pr_flag); | |
1865 | bfd_put_32 (obfd, from->pr_uid, to->pr_uid); | |
1866 | bfd_put_32 (obfd, from->pr_gid, to->pr_gid); | |
1867 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
1868 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
1869 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
1870 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
1871 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); | |
1872 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
1873 | } | |
25dbc73a AM |
1874 | \f |
1875 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
1876 | ||
1877 | static void | |
1878 | ppc_elf_howto_init (void) | |
1879 | { | |
1880 | unsigned int i, type; | |
1881 | ||
1882 | for (i = 0; | |
1883 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1884 | i++) | |
1885 | { | |
1886 | type = ppc_elf_howto_raw[i].type; | |
1887 | if (type >= (sizeof (ppc_elf_howto_table) | |
1888 | / sizeof (ppc_elf_howto_table[0]))) | |
1889 | abort (); | |
1890 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; | |
1891 | } | |
1892 | } | |
1893 | ||
1894 | static reloc_howto_type * | |
1895 | ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1896 | bfd_reloc_code_real_type code) | |
1897 | { | |
1898 | enum elf_ppc_reloc_type r; | |
1899 | ||
1900 | /* Initialize howto table if not already done. */ | |
1901 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1902 | ppc_elf_howto_init (); | |
1903 | ||
1904 | switch (code) | |
1905 | { | |
1906 | default: | |
1907 | return NULL; | |
1908 | ||
1909 | case BFD_RELOC_NONE: r = R_PPC_NONE; break; | |
1910 | case BFD_RELOC_32: r = R_PPC_ADDR32; break; | |
1911 | case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break; | |
1fe532cf | 1912 | case BFD_RELOC_PPC64_ADDR16_DS: |
25dbc73a | 1913 | case BFD_RELOC_16: r = R_PPC_ADDR16; break; |
1fe532cf | 1914 | case BFD_RELOC_PPC64_ADDR16_LO_DS: |
25dbc73a AM |
1915 | case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break; |
1916 | case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break; | |
1917 | case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break; | |
1918 | case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break; | |
1919 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break; | |
1920 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break; | |
1921 | case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break; | |
1922 | case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break; | |
1923 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break; | |
1924 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break; | |
1fe532cf | 1925 | case BFD_RELOC_PPC64_GOT16_DS: |
25dbc73a | 1926 | case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break; |
1fe532cf | 1927 | case BFD_RELOC_PPC64_GOT16_LO_DS: |
25dbc73a AM |
1928 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break; |
1929 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break; | |
1930 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break; | |
1931 | case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break; | |
1932 | case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break; | |
1933 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break; | |
1934 | case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break; | |
1935 | case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break; | |
1936 | case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break; | |
1937 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break; | |
1fe532cf | 1938 | case BFD_RELOC_PPC64_PLT16_LO_DS: |
25dbc73a AM |
1939 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break; |
1940 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break; | |
1941 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break; | |
1942 | case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break; | |
1fe532cf | 1943 | case BFD_RELOC_PPC64_SECTOFF_DS: |
25dbc73a | 1944 | case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break; |
1fe532cf | 1945 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: |
25dbc73a AM |
1946 | case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break; |
1947 | case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break; | |
1948 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break; | |
1949 | case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break; | |
1fe532cf | 1950 | case BFD_RELOC_PPC64_TOC16_DS: |
25dbc73a AM |
1951 | case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break; |
1952 | case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break; | |
727fc41e AM |
1953 | case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break; |
1954 | case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break; | |
25dbc73a | 1955 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break; |
1fe532cf | 1956 | case BFD_RELOC_PPC64_TPREL16_DS: |
25dbc73a | 1957 | case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break; |
1fe532cf | 1958 | case BFD_RELOC_PPC64_TPREL16_LO_DS: |
25dbc73a AM |
1959 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break; |
1960 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break; | |
1961 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break; | |
1962 | case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break; | |
1fe532cf | 1963 | case BFD_RELOC_PPC64_DTPREL16_DS: |
25dbc73a | 1964 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break; |
1fe532cf | 1965 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: |
25dbc73a AM |
1966 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break; |
1967 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break; | |
1968 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break; | |
1969 | case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break; | |
1970 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break; | |
1971 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break; | |
1972 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break; | |
1973 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break; | |
1974 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break; | |
1975 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break; | |
1976 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break; | |
1977 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break; | |
1978 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break; | |
1979 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break; | |
1980 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break; | |
1981 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break; | |
1982 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break; | |
1983 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break; | |
1984 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break; | |
1985 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break; | |
1986 | case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break; | |
1987 | case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break; | |
1988 | case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break; | |
1989 | case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break; | |
1990 | case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break; | |
1991 | case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break; | |
1992 | case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break; | |
1993 | case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break; | |
1994 | case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break; | |
1995 | case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break; | |
1996 | case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break; | |
1997 | case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break; | |
1998 | case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break; | |
1999 | case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break; | |
2000 | case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break; | |
2001 | case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break; | |
b9c361e0 JL |
2002 | case BFD_RELOC_PPC_VLE_REL8: r = R_PPC_VLE_REL8; break; |
2003 | case BFD_RELOC_PPC_VLE_REL15: r = R_PPC_VLE_REL15; break; | |
2004 | case BFD_RELOC_PPC_VLE_REL24: r = R_PPC_VLE_REL24; break; | |
2005 | case BFD_RELOC_PPC_VLE_LO16A: r = R_PPC_VLE_LO16A; break; | |
2006 | case BFD_RELOC_PPC_VLE_LO16D: r = R_PPC_VLE_LO16D; break; | |
2007 | case BFD_RELOC_PPC_VLE_HI16A: r = R_PPC_VLE_HI16A; break; | |
2008 | case BFD_RELOC_PPC_VLE_HI16D: r = R_PPC_VLE_HI16D; break; | |
2009 | case BFD_RELOC_PPC_VLE_HA16A: r = R_PPC_VLE_HA16A; break; | |
2010 | case BFD_RELOC_PPC_VLE_HA16D: r = R_PPC_VLE_HA16D; break; | |
2011 | case BFD_RELOC_PPC_VLE_SDA21: r = R_PPC_VLE_SDA21; break; | |
2012 | case BFD_RELOC_PPC_VLE_SDA21_LO: r = R_PPC_VLE_SDA21_LO; break; | |
2013 | case BFD_RELOC_PPC_VLE_SDAREL_LO16A: | |
2014 | r = R_PPC_VLE_SDAREL_LO16A; | |
2015 | break; | |
2016 | case BFD_RELOC_PPC_VLE_SDAREL_LO16D: | |
2017 | r = R_PPC_VLE_SDAREL_LO16D; | |
2018 | break; | |
2019 | case BFD_RELOC_PPC_VLE_SDAREL_HI16A: | |
2020 | r = R_PPC_VLE_SDAREL_HI16A; | |
2021 | break; | |
2022 | case BFD_RELOC_PPC_VLE_SDAREL_HI16D: | |
2023 | r = R_PPC_VLE_SDAREL_HI16D; | |
2024 | break; | |
2025 | case BFD_RELOC_PPC_VLE_SDAREL_HA16A: | |
2026 | r = R_PPC_VLE_SDAREL_HA16A; | |
2027 | break; | |
2028 | case BFD_RELOC_PPC_VLE_SDAREL_HA16D: | |
2029 | r = R_PPC_VLE_SDAREL_HA16D; | |
2030 | break; | |
d7128ce4 AM |
2031 | case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break; |
2032 | case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break; | |
2033 | case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break; | |
2034 | case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break; | |
7ba71655 | 2035 | case BFD_RELOC_PPC_16DX_HA: r = R_PPC_16DX_HA; break; |
a680de9a | 2036 | case BFD_RELOC_PPC_REL16DX_HA: r = R_PPC_REL16DX_HA; break; |
25dbc73a AM |
2037 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break; |
2038 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break; | |
2039 | } | |
2040 | ||
2041 | return ppc_elf_howto_table[r]; | |
2042 | }; | |
2043 | ||
157090f7 AM |
2044 | static reloc_howto_type * |
2045 | ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
2046 | const char *r_name) | |
2047 | { | |
2048 | unsigned int i; | |
2049 | ||
2050 | for (i = 0; | |
2051 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
2052 | i++) | |
2053 | if (ppc_elf_howto_raw[i].name != NULL | |
2054 | && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0) | |
2055 | return &ppc_elf_howto_raw[i]; | |
2056 | ||
2057 | return NULL; | |
2058 | } | |
2059 | ||
25dbc73a AM |
2060 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
2061 | ||
2062 | static void | |
4aef7643 | 2063 | ppc_elf_info_to_howto (bfd *abfd, |
25dbc73a AM |
2064 | arelent *cache_ptr, |
2065 | Elf_Internal_Rela *dst) | |
2066 | { | |
cd21f5da NC |
2067 | unsigned int r_type; |
2068 | ||
25dbc73a AM |
2069 | /* Initialize howto table if not already done. */ |
2070 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
2071 | ppc_elf_howto_init (); | |
2072 | ||
cd21f5da NC |
2073 | r_type = ELF32_R_TYPE (dst->r_info); |
2074 | if (r_type >= R_PPC_max) | |
2075 | { | |
695344c0 | 2076 | /* xgettext:c-format */ |
4eca0228 AM |
2077 | _bfd_error_handler (_("%B: unrecognised PPC reloc number: %d"), |
2078 | abfd, r_type); | |
cd21f5da NC |
2079 | bfd_set_error (bfd_error_bad_value); |
2080 | r_type = R_PPC_NONE; | |
2081 | } | |
2082 | cache_ptr->howto = ppc_elf_howto_table[r_type]; | |
375de94a AM |
2083 | |
2084 | /* Just because the above assert didn't trigger doesn't mean that | |
2085 | ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */ | |
2086 | if (!cache_ptr->howto) | |
2087 | { | |
695344c0 | 2088 | /* xgettext:c-format */ |
4eca0228 AM |
2089 | _bfd_error_handler (_("%B: invalid relocation type %d"), |
2090 | abfd, r_type); | |
375de94a AM |
2091 | bfd_set_error (bfd_error_bad_value); |
2092 | ||
2093 | cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE]; | |
2094 | } | |
25dbc73a AM |
2095 | } |
2096 | ||
d7128ce4 | 2097 | /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */ |
25dbc73a AM |
2098 | |
2099 | static bfd_reloc_status_type | |
4aef7643 | 2100 | ppc_elf_addr16_ha_reloc (bfd *abfd, |
25dbc73a AM |
2101 | arelent *reloc_entry, |
2102 | asymbol *symbol, | |
4aef7643 | 2103 | void *data, |
25dbc73a AM |
2104 | asection *input_section, |
2105 | bfd *output_bfd, | |
2106 | char **error_message ATTRIBUTE_UNUSED) | |
2107 | { | |
a680de9a PB |
2108 | enum elf_ppc_reloc_type r_type; |
2109 | long insn; | |
2110 | bfd_size_type octets; | |
2111 | bfd_vma value; | |
25dbc73a AM |
2112 | |
2113 | if (output_bfd != NULL) | |
2114 | { | |
2115 | reloc_entry->address += input_section->output_offset; | |
2116 | return bfd_reloc_ok; | |
2117 | } | |
2118 | ||
a680de9a PB |
2119 | reloc_entry->addend += 0x8000; |
2120 | r_type = reloc_entry->howto->type; | |
2121 | if (r_type != R_PPC_REL16DX_HA) | |
2122 | return bfd_reloc_continue; | |
2123 | ||
2124 | value = 0; | |
2125 | if (!bfd_is_com_section (symbol->section)) | |
2126 | value = symbol->value; | |
2127 | value += (reloc_entry->addend | |
2128 | + symbol->section->output_offset | |
2129 | + symbol->section->output_section->vma); | |
2130 | value -= (reloc_entry->address | |
2131 | + input_section->output_offset | |
2132 | + input_section->output_section->vma); | |
2133 | value >>= 16; | |
2134 | ||
2135 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2136 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2137 | insn &= ~0x1fffc1; | |
2138 | insn |= (value & 0xffc1) | ((value & 0x3e) << 15); | |
2139 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); | |
2140 | return bfd_reloc_ok; | |
25dbc73a AM |
2141 | } |
2142 | ||
2143 | static bfd_reloc_status_type | |
2144 | ppc_elf_unhandled_reloc (bfd *abfd, | |
2145 | arelent *reloc_entry, | |
2146 | asymbol *symbol, | |
2147 | void *data, | |
2148 | asection *input_section, | |
2149 | bfd *output_bfd, | |
2150 | char **error_message) | |
2151 | { | |
2152 | /* If this is a relocatable link (output_bfd test tells us), just | |
2153 | call the generic function. Any adjustment will be done at final | |
2154 | link time. */ | |
2155 | if (output_bfd != NULL) | |
2156 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
2157 | input_section, output_bfd, error_message); | |
2158 | ||
2159 | if (error_message != NULL) | |
2160 | { | |
2161 | static char buf[60]; | |
2162 | sprintf (buf, _("generic linker can't handle %s"), | |
2163 | reloc_entry->howto->name); | |
2164 | *error_message = buf; | |
2165 | } | |
2166 | return bfd_reloc_dangerous; | |
2167 | } | |
2168 | \f | |
2169 | /* Sections created by the linker. */ | |
2170 | ||
2171 | typedef struct elf_linker_section | |
2172 | { | |
c9a2f333 | 2173 | /* Pointer to the bfd section. */ |
25dbc73a | 2174 | asection *section; |
c9a2f333 AM |
2175 | /* Section name. */ |
2176 | const char *name; | |
2177 | /* Associated bss section name. */ | |
2178 | const char *bss_name; | |
2179 | /* Associated symbol name. */ | |
2180 | const char *sym_name; | |
046183de AM |
2181 | /* Associated symbol. */ |
2182 | struct elf_link_hash_entry *sym; | |
25dbc73a AM |
2183 | } elf_linker_section_t; |
2184 | ||
2185 | /* Linked list of allocated pointer entries. This hangs off of the | |
2186 | symbol lists, and provides allows us to return different pointers, | |
2187 | based on different addend's. */ | |
2188 | ||
2189 | typedef struct elf_linker_section_pointers | |
2190 | { | |
2191 | /* next allocated pointer for this symbol */ | |
2192 | struct elf_linker_section_pointers *next; | |
2193 | /* offset of pointer from beginning of section */ | |
2194 | bfd_vma offset; | |
2195 | /* addend used */ | |
2196 | bfd_vma addend; | |
2197 | /* which linker section this is */ | |
2198 | elf_linker_section_t *lsect; | |
25dbc73a AM |
2199 | } elf_linker_section_pointers_t; |
2200 | ||
2201 | struct ppc_elf_obj_tdata | |
2202 | { | |
2203 | struct elf_obj_tdata elf; | |
2204 | ||
2205 | /* A mapping from local symbols to offsets into the various linker | |
2206 | sections added. This is index by the symbol index. */ | |
2207 | elf_linker_section_pointers_t **linker_section_pointers; | |
016687f8 AM |
2208 | |
2209 | /* Flags used to auto-detect plt type. */ | |
2210 | unsigned int makes_plt_call : 1; | |
2211 | unsigned int has_rel16 : 1; | |
25dbc73a AM |
2212 | }; |
2213 | ||
2214 | #define ppc_elf_tdata(bfd) \ | |
2215 | ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any) | |
7619e7c7 | 2216 | |
25dbc73a AM |
2217 | #define elf_local_ptr_offsets(bfd) \ |
2218 | (ppc_elf_tdata (bfd)->linker_section_pointers) | |
7619e7c7 | 2219 | |
0c8d6e5c AM |
2220 | #define is_ppc_elf(bfd) \ |
2221 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
4dfe6ac6 | 2222 | && elf_object_id (bfd) == PPC32_ELF_DATA) |
0c8d6e5c | 2223 | |
25dbc73a | 2224 | /* Override the generic function because we store some extras. */ |
7619e7c7 | 2225 | |
25dbc73a AM |
2226 | static bfd_boolean |
2227 | ppc_elf_mkobject (bfd *abfd) | |
2228 | { | |
0ffa91dd | 2229 | return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata), |
4dfe6ac6 | 2230 | PPC32_ELF_DATA); |
25dbc73a | 2231 | } |
7619e7c7 | 2232 | |
14b57c7c AM |
2233 | /* When defaulting arch/mach, decode apuinfo to find a better match. */ |
2234 | ||
2235 | bfd_boolean | |
2236 | _bfd_elf_ppc_set_arch (bfd *abfd) | |
2237 | { | |
2238 | unsigned long mach = 0; | |
2239 | asection *s; | |
2240 | unsigned char *contents; | |
2241 | ||
2242 | if (abfd->arch_info->bits_per_word == 32 | |
2243 | && bfd_big_endian (abfd)) | |
2244 | { | |
2245 | ||
2246 | for (s = abfd->sections; s != NULL; s = s->next) | |
2247 | if ((elf_section_data (s)->this_hdr.sh_flags & SHF_PPC_VLE) != 0) | |
2248 | break; | |
2249 | if (s != NULL) | |
2250 | mach = bfd_mach_ppc_vle; | |
2251 | } | |
2252 | ||
2253 | if (mach == 0) | |
2254 | { | |
2255 | s = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
2256 | if (s != NULL && bfd_malloc_and_get_section (abfd, s, &contents)) | |
2257 | { | |
2258 | unsigned int apuinfo_size = bfd_get_32 (abfd, contents + 4); | |
2259 | unsigned int i; | |
2260 | ||
2261 | for (i = 20; i < apuinfo_size + 20 && i + 4 <= s->size; i += 4) | |
2262 | { | |
2263 | unsigned int val = bfd_get_32 (abfd, contents + i); | |
2264 | switch (val >> 16) | |
2265 | { | |
2266 | case PPC_APUINFO_PMR: | |
2267 | case PPC_APUINFO_RFMCI: | |
2268 | if (mach == 0) | |
2269 | mach = bfd_mach_ppc_titan; | |
2270 | break; | |
2271 | ||
2272 | case PPC_APUINFO_ISEL: | |
2273 | case PPC_APUINFO_CACHELCK: | |
2274 | if (mach == bfd_mach_ppc_titan) | |
2275 | mach = bfd_mach_ppc_e500mc; | |
2276 | break; | |
2277 | ||
2278 | case PPC_APUINFO_SPE: | |
2279 | case PPC_APUINFO_EFS: | |
2280 | case PPC_APUINFO_BRLOCK: | |
2281 | if (mach != bfd_mach_ppc_vle) | |
2282 | mach = bfd_mach_ppc_e500; | |
8941017b | 2283 | break; |
14b57c7c AM |
2284 | |
2285 | case PPC_APUINFO_VLE: | |
2286 | mach = bfd_mach_ppc_vle; | |
2287 | break; | |
2288 | ||
2289 | default: | |
2290 | mach = -1ul; | |
2291 | } | |
2292 | } | |
2293 | free (contents); | |
2294 | } | |
2295 | } | |
2296 | ||
2297 | if (mach != 0 && mach != -1ul) | |
2298 | { | |
2299 | const bfd_arch_info_type *arch; | |
2300 | ||
2301 | for (arch = abfd->arch_info->next; arch; arch = arch->next) | |
2302 | if (arch->mach == mach) | |
2303 | { | |
2304 | abfd->arch_info = arch; | |
2305 | break; | |
2306 | } | |
2307 | } | |
2308 | return TRUE; | |
2309 | } | |
2310 | ||
25dbc73a | 2311 | /* Fix bad default arch selected for a 32 bit input bfd when the |
14b57c7c | 2312 | default is 64 bit. Also select arch based on apuinfo. */ |
7619e7c7 | 2313 | |
25dbc73a AM |
2314 | static bfd_boolean |
2315 | ppc_elf_object_p (bfd *abfd) | |
2316 | { | |
14b57c7c AM |
2317 | if (!abfd->arch_info->the_default) |
2318 | return TRUE; | |
2319 | ||
2320 | if (abfd->arch_info->bits_per_word == 64) | |
25dbc73a AM |
2321 | { |
2322 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
7619e7c7 | 2323 | |
25dbc73a AM |
2324 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) |
2325 | { | |
2326 | /* Relies on arch after 64 bit default being 32 bit default. */ | |
2327 | abfd->arch_info = abfd->arch_info->next; | |
2328 | BFD_ASSERT (abfd->arch_info->bits_per_word == 32); | |
2329 | } | |
2330 | } | |
14b57c7c | 2331 | return _bfd_elf_ppc_set_arch (abfd); |
25dbc73a | 2332 | } |
7619e7c7 | 2333 | |
25dbc73a | 2334 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
7619e7c7 | 2335 | |
25dbc73a AM |
2336 | static bfd_boolean |
2337 | ppc_elf_set_private_flags (bfd *abfd, flagword flags) | |
2338 | { | |
2339 | BFD_ASSERT (!elf_flags_init (abfd) | |
2340 | || elf_elfheader (abfd)->e_flags == flags); | |
7619e7c7 | 2341 | |
25dbc73a AM |
2342 | elf_elfheader (abfd)->e_flags = flags; |
2343 | elf_flags_init (abfd) = TRUE; | |
2344 | return TRUE; | |
2345 | } | |
2346 | ||
25dbc73a | 2347 | /* Support for core dump NOTE sections. */ |
deaaf2f3 | 2348 | |
b34976b6 | 2349 | static bfd_boolean |
25dbc73a | 2350 | ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
252b5132 | 2351 | { |
25dbc73a AM |
2352 | int offset; |
2353 | unsigned int size; | |
252b5132 | 2354 | |
25dbc73a AM |
2355 | switch (note->descsz) |
2356 | { | |
2357 | default: | |
2358 | return FALSE; | |
252b5132 | 2359 | |
25dbc73a AM |
2360 | case 268: /* Linux/PPC. */ |
2361 | /* pr_cursig */ | |
228e534f | 2362 | elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); |
deaaf2f3 | 2363 | |
25dbc73a | 2364 | /* pr_pid */ |
228e534f | 2365 | elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); |
9abc968f | 2366 | |
25dbc73a AM |
2367 | /* pr_reg */ |
2368 | offset = 72; | |
2369 | size = 192; | |
deaaf2f3 | 2370 | |
25dbc73a AM |
2371 | break; |
2372 | } | |
deaaf2f3 | 2373 | |
25dbc73a AM |
2374 | /* Make a ".reg/999" section. */ |
2375 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
2376 | size, note->descpos + offset); | |
2377 | } | |
252b5132 | 2378 | |
25dbc73a AM |
2379 | static bfd_boolean |
2380 | ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
2381 | { | |
2382 | switch (note->descsz) | |
deaaf2f3 | 2383 | { |
25dbc73a AM |
2384 | default: |
2385 | return FALSE; | |
deaaf2f3 | 2386 | |
25dbc73a | 2387 | case 128: /* Linux/PPC elf_prpsinfo. */ |
228e534f | 2388 | elf_tdata (abfd)->core->pid |
bc989cdc | 2389 | = bfd_get_32 (abfd, note->descdata + 16); |
228e534f | 2390 | elf_tdata (abfd)->core->program |
25dbc73a | 2391 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); |
228e534f | 2392 | elf_tdata (abfd)->core->command |
25dbc73a AM |
2393 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); |
2394 | } | |
9abc968f | 2395 | |
25dbc73a AM |
2396 | /* Note that for some reason, a spurious space is tacked |
2397 | onto the end of the args in some (at least one anyway) | |
2398 | implementations, so strip it off if it exists. */ | |
70bccea4 | 2399 | |
25dbc73a | 2400 | { |
228e534f | 2401 | char *command = elf_tdata (abfd)->core->command; |
25dbc73a | 2402 | int n = strlen (command); |
70bccea4 | 2403 | |
25dbc73a AM |
2404 | if (0 < n && command[n - 1] == ' ') |
2405 | command[n - 1] = '\0'; | |
2406 | } | |
deaaf2f3 | 2407 | |
25dbc73a AM |
2408 | return TRUE; |
2409 | } | |
deaaf2f3 | 2410 | |
70a38d42 | 2411 | char * |
aeb70569 AM |
2412 | elfcore_write_ppc_linux_prpsinfo32 |
2413 | (bfd *abfd, | |
2414 | char *buf, | |
2415 | int *bufsiz, | |
2416 | const struct elf_internal_linux_prpsinfo *prpsinfo) | |
70a38d42 SDJ |
2417 | { |
2418 | struct elf_external_ppc_linux_prpsinfo32 data; | |
2419 | ||
aeb70569 | 2420 | swap_ppc_linux_prpsinfo32_out (abfd, prpsinfo, &data); |
70a38d42 SDJ |
2421 | return elfcore_write_note (abfd, buf, bufsiz, |
2422 | "CORE", NT_PRPSINFO, &data, sizeof (data)); | |
2423 | } | |
2424 | ||
183e98be AM |
2425 | static char * |
2426 | ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...) | |
2427 | { | |
2428 | switch (note_type) | |
2429 | { | |
2430 | default: | |
2431 | return NULL; | |
2432 | ||
2433 | case NT_PRPSINFO: | |
2434 | { | |
2435 | char data[128]; | |
2436 | va_list ap; | |
2437 | ||
2438 | va_start (ap, note_type); | |
75cd47ed | 2439 | memset (data, 0, sizeof (data)); |
183e98be AM |
2440 | strncpy (data + 32, va_arg (ap, const char *), 16); |
2441 | strncpy (data + 48, va_arg (ap, const char *), 80); | |
2442 | va_end (ap); | |
2443 | return elfcore_write_note (abfd, buf, bufsiz, | |
2444 | "CORE", note_type, data, sizeof (data)); | |
2445 | } | |
2446 | ||
2447 | case NT_PRSTATUS: | |
2448 | { | |
2449 | char data[268]; | |
2450 | va_list ap; | |
2451 | long pid; | |
2452 | int cursig; | |
2453 | const void *greg; | |
2454 | ||
2455 | va_start (ap, note_type); | |
2456 | memset (data, 0, 72); | |
2457 | pid = va_arg (ap, long); | |
2458 | bfd_put_32 (abfd, pid, data + 24); | |
2459 | cursig = va_arg (ap, int); | |
2460 | bfd_put_16 (abfd, cursig, data + 12); | |
2461 | greg = va_arg (ap, const void *); | |
2462 | memcpy (data + 72, greg, 192); | |
2463 | memset (data + 264, 0, 4); | |
2464 | va_end (ap); | |
2465 | return elfcore_write_note (abfd, buf, bufsiz, | |
2466 | "CORE", note_type, data, sizeof (data)); | |
2467 | } | |
2468 | } | |
2469 | } | |
2470 | ||
b9c361e0 | 2471 | static flagword |
68ffbac6 | 2472 | ppc_elf_lookup_section_flags (char *flag_name) |
b9c361e0 JL |
2473 | { |
2474 | ||
2475 | if (!strcmp (flag_name, "SHF_PPC_VLE")) | |
2476 | return SHF_PPC_VLE; | |
2477 | ||
2478 | return 0; | |
2479 | } | |
2480 | ||
25dbc73a AM |
2481 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
2482 | or (bfd_vma) -1 if it should not be included. */ | |
deaaf2f3 | 2483 | |
25dbc73a AM |
2484 | static bfd_vma |
2485 | ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, | |
2486 | const asection *plt ATTRIBUTE_UNUSED, | |
2487 | const arelent *rel) | |
2488 | { | |
2489 | return rel->address; | |
2490 | } | |
deaaf2f3 | 2491 | |
25dbc73a | 2492 | /* Handle a PowerPC specific section when reading an object file. This |
6dc132d9 L |
2493 | is called when bfd_section_from_shdr finds a section with an unknown |
2494 | type. */ | |
deaaf2f3 | 2495 | |
25dbc73a | 2496 | static bfd_boolean |
6dc132d9 L |
2497 | ppc_elf_section_from_shdr (bfd *abfd, |
2498 | Elf_Internal_Shdr *hdr, | |
2499 | const char *name, | |
2500 | int shindex) | |
25dbc73a AM |
2501 | { |
2502 | asection *newsect; | |
2503 | flagword flags; | |
d1c6de6f | 2504 | |
6dc132d9 | 2505 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
25dbc73a | 2506 | return FALSE; |
deaaf2f3 | 2507 | |
25dbc73a AM |
2508 | newsect = hdr->bfd_section; |
2509 | flags = bfd_get_section_flags (abfd, newsect); | |
2510 | if (hdr->sh_flags & SHF_EXCLUDE) | |
2511 | flags |= SEC_EXCLUDE; | |
9abc968f | 2512 | |
25dbc73a AM |
2513 | if (hdr->sh_type == SHT_ORDERED) |
2514 | flags |= SEC_SORT_ENTRIES; | |
d1c6de6f | 2515 | |
25dbc73a AM |
2516 | bfd_set_section_flags (abfd, newsect, flags); |
2517 | return TRUE; | |
2518 | } | |
2519 | ||
2520 | /* Set up any other section flags and such that may be necessary. */ | |
2521 | ||
2522 | static bfd_boolean | |
2523 | ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, | |
2524 | Elf_Internal_Shdr *shdr, | |
2525 | asection *asect) | |
2526 | { | |
25dbc73a AM |
2527 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) |
2528 | shdr->sh_type = SHT_ORDERED; | |
2529 | ||
2530 | return TRUE; | |
2531 | } | |
2532 | ||
2533 | /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we | |
2534 | need to bump up the number of section headers. */ | |
2535 | ||
2536 | static int | |
a6b96beb AM |
2537 | ppc_elf_additional_program_headers (bfd *abfd, |
2538 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
25dbc73a AM |
2539 | { |
2540 | asection *s; | |
2541 | int ret = 0; | |
d1c6de6f | 2542 | |
25dbc73a AM |
2543 | s = bfd_get_section_by_name (abfd, ".sbss2"); |
2544 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2545 | ++ret; | |
d1c6de6f | 2546 | |
25dbc73a AM |
2547 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); |
2548 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2549 | ++ret; | |
deaaf2f3 | 2550 | |
25dbc73a AM |
2551 | return ret; |
2552 | } | |
deaaf2f3 | 2553 | |
68ffbac6 | 2554 | /* Modify the segment map for VLE executables. */ |
b9c361e0 JL |
2555 | |
2556 | bfd_boolean | |
2557 | ppc_elf_modify_segment_map (bfd *abfd, | |
2558 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
2559 | { | |
f7d69005 | 2560 | struct elf_segment_map *m; |
b9c361e0 JL |
2561 | |
2562 | /* At this point in the link, output sections have already been sorted by | |
2563 | LMA and assigned to segments. All that is left to do is to ensure | |
2564 | there is no mixing of VLE & non-VLE sections in a text segment. | |
2565 | If we find that case, we split the segment. | |
2566 | We maintain the original output section order. */ | |
2567 | ||
12bd6957 | 2568 | for (m = elf_seg_map (abfd); m != NULL; m = m->next) |
b9c361e0 | 2569 | { |
f7d69005 AM |
2570 | struct elf_segment_map *n; |
2571 | bfd_size_type amt; | |
2572 | unsigned int j, k; | |
2573 | unsigned int p_flags; | |
2574 | ||
2575 | if (m->p_type != PT_LOAD || m->count == 0) | |
b9c361e0 JL |
2576 | continue; |
2577 | ||
f7d69005 | 2578 | for (p_flags = PF_R, j = 0; j != m->count; ++j) |
b9c361e0 | 2579 | { |
f7d69005 AM |
2580 | if ((m->sections[j]->flags & SEC_READONLY) == 0) |
2581 | p_flags |= PF_W; | |
2582 | if ((m->sections[j]->flags & SEC_CODE) != 0) | |
2583 | { | |
2584 | p_flags |= PF_X; | |
2585 | if ((elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0) | |
2586 | p_flags |= PF_PPC_VLE; | |
2587 | break; | |
2588 | } | |
2589 | } | |
2590 | if (j != m->count) | |
2591 | while (++j != m->count) | |
2592 | { | |
2593 | unsigned int p_flags1 = PF_R; | |
94caa966 | 2594 | |
f7d69005 AM |
2595 | if ((m->sections[j]->flags & SEC_READONLY) == 0) |
2596 | p_flags1 |= PF_W; | |
2597 | if ((m->sections[j]->flags & SEC_CODE) != 0) | |
2598 | { | |
2599 | p_flags1 |= PF_X; | |
2600 | if ((elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0) | |
2601 | p_flags1 |= PF_PPC_VLE; | |
2602 | if (((p_flags1 ^ p_flags) & PF_PPC_VLE) != 0) | |
2603 | break; | |
2604 | } | |
2605 | p_flags |= p_flags1; | |
2606 | } | |
2607 | /* If we're splitting a segment which originally contained rw | |
2608 | sections then those sections might now only be in one of the | |
2609 | two parts. So always set p_flags if splitting, even if we | |
2610 | are being called for objcopy with p_flags_valid set. */ | |
2611 | if (j != m->count || !m->p_flags_valid) | |
2612 | { | |
2613 | m->p_flags_valid = 1; | |
2614 | m->p_flags = p_flags; | |
2615 | } | |
2616 | if (j == m->count) | |
b9c361e0 JL |
2617 | continue; |
2618 | ||
f7d69005 | 2619 | /* Sections 0..j-1 stay in this (current) segment, |
b9c361e0 JL |
2620 | the remainder are put in a new segment. |
2621 | The scan resumes with the new segment. */ | |
2622 | ||
b9c361e0 JL |
2623 | amt = sizeof (struct elf_segment_map); |
2624 | amt += (m->count - j - 1) * sizeof (asection *); | |
2625 | n = (struct elf_segment_map *) bfd_zalloc (abfd, amt); | |
2626 | if (n == NULL) | |
954b63d4 | 2627 | return FALSE; |
b9c361e0 JL |
2628 | |
2629 | n->p_type = PT_LOAD; | |
b9c361e0 JL |
2630 | n->count = m->count - j; |
2631 | for (k = 0; k < n->count; ++k) | |
f7d69005 AM |
2632 | n->sections[k] = m->sections[j + k]; |
2633 | m->count = j; | |
2634 | m->p_size_valid = 0; | |
b9c361e0 JL |
2635 | n->next = m->next; |
2636 | m->next = n; | |
b9c361e0 JL |
2637 | } |
2638 | ||
2639 | return TRUE; | |
2640 | } | |
2641 | ||
25dbc73a AM |
2642 | /* Add extra PPC sections -- Note, for now, make .sbss2 and |
2643 | .PPC.EMB.sbss0 a normal section, and not a bss section so | |
2644 | that the linker doesn't crater when trying to make more than | |
2645 | 2 sections. */ | |
e656e369 | 2646 | |
b35d266b | 2647 | static const struct bfd_elf_special_section ppc_elf_special_sections[] = |
7f4d3958 | 2648 | { |
14b57c7c AM |
2649 | { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR }, |
2650 | { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2651 | { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2652 | { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2653 | { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2654 | { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC }, | |
2655 | { STRING_COMMA_LEN (APUINFO_SECTION_NAME), 0, SHT_NOTE, 0 }, | |
2656 | { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2657 | { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2658 | { NULL, 0, 0, 0, 0 } | |
7f4d3958 L |
2659 | }; |
2660 | ||
551b43fd AM |
2661 | /* This is what we want for new plt/got. */ |
2662 | static struct bfd_elf_special_section ppc_alt_plt = | |
0112cd26 | 2663 | { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC }; |
551b43fd AM |
2664 | |
2665 | static const struct bfd_elf_special_section * | |
4aef7643 | 2666 | ppc_elf_get_sec_type_attr (bfd *abfd, asection *sec) |
7f4d3958 | 2667 | { |
b35d266b | 2668 | const struct bfd_elf_special_section *ssect; |
551b43fd AM |
2669 | |
2670 | /* See if this is one of the special sections. */ | |
2671 | if (sec->name == NULL) | |
2672 | return NULL; | |
2673 | ||
2674 | ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections, | |
2675 | sec->use_rela_p); | |
2676 | if (ssect != NULL) | |
2677 | { | |
2678 | if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0) | |
2679 | ssect = &ppc_alt_plt; | |
2680 | return ssect; | |
2681 | } | |
2682 | ||
2683 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
2684 | } | |
25dbc73a AM |
2685 | \f |
2686 | /* Very simple linked list structure for recording apuinfo values. */ | |
2687 | typedef struct apuinfo_list | |
2688 | { | |
2689 | struct apuinfo_list *next; | |
2690 | unsigned long value; | |
2691 | } | |
2692 | apuinfo_list; | |
e656e369 | 2693 | |
25dbc73a | 2694 | static apuinfo_list *head; |
f2faa800 | 2695 | static bfd_boolean apuinfo_set; |
deaaf2f3 | 2696 | |
25dbc73a AM |
2697 | static void |
2698 | apuinfo_list_init (void) | |
2699 | { | |
2700 | head = NULL; | |
f2faa800 | 2701 | apuinfo_set = FALSE; |
25dbc73a | 2702 | } |
9abc968f | 2703 | |
25dbc73a AM |
2704 | static void |
2705 | apuinfo_list_add (unsigned long value) | |
2706 | { | |
2707 | apuinfo_list *entry = head; | |
deaaf2f3 | 2708 | |
25dbc73a AM |
2709 | while (entry != NULL) |
2710 | { | |
2711 | if (entry->value == value) | |
2712 | return; | |
2713 | entry = entry->next; | |
2714 | } | |
b4a38de6 | 2715 | |
25dbc73a AM |
2716 | entry = bfd_malloc (sizeof (* entry)); |
2717 | if (entry == NULL) | |
2718 | return; | |
e656e369 | 2719 | |
25dbc73a AM |
2720 | entry->value = value; |
2721 | entry->next = head; | |
2722 | head = entry; | |
2723 | } | |
9abc968f | 2724 | |
25dbc73a AM |
2725 | static unsigned |
2726 | apuinfo_list_length (void) | |
2727 | { | |
2728 | apuinfo_list *entry; | |
2729 | unsigned long count; | |
9abc968f | 2730 | |
25dbc73a AM |
2731 | for (entry = head, count = 0; |
2732 | entry; | |
2733 | entry = entry->next) | |
2734 | ++ count; | |
e656e369 | 2735 | |
25dbc73a AM |
2736 | return count; |
2737 | } | |
eea6121a | 2738 | |
25dbc73a AM |
2739 | static inline unsigned long |
2740 | apuinfo_list_element (unsigned long number) | |
2741 | { | |
2742 | apuinfo_list * entry; | |
e656e369 | 2743 | |
25dbc73a AM |
2744 | for (entry = head; |
2745 | entry && number --; | |
2746 | entry = entry->next) | |
2747 | ; | |
252b5132 | 2748 | |
25dbc73a AM |
2749 | return entry ? entry->value : 0; |
2750 | } | |
2751 | ||
2752 | static void | |
2753 | apuinfo_list_finish (void) | |
2754 | { | |
2755 | apuinfo_list *entry; | |
2756 | ||
2757 | for (entry = head; entry;) | |
252b5132 | 2758 | { |
25dbc73a AM |
2759 | apuinfo_list *next = entry->next; |
2760 | free (entry); | |
2761 | entry = next; | |
2762 | } | |
9abc968f | 2763 | |
25dbc73a AM |
2764 | head = NULL; |
2765 | } | |
9abc968f | 2766 | |
25dbc73a AM |
2767 | /* Scan the input BFDs and create a linked list of |
2768 | the APUinfo values that will need to be emitted. */ | |
9abc968f | 2769 | |
25dbc73a AM |
2770 | static void |
2771 | ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info) | |
2772 | { | |
2773 | bfd *ibfd; | |
2774 | asection *asec; | |
deddc40b NS |
2775 | char *buffer = NULL; |
2776 | bfd_size_type largest_input_size = 0; | |
25dbc73a | 2777 | unsigned i; |
25dbc73a AM |
2778 | unsigned long length; |
2779 | const char *error_message = NULL; | |
9abc968f | 2780 | |
25dbc73a AM |
2781 | if (link_info == NULL) |
2782 | return; | |
9abc968f | 2783 | |
25dbc73a | 2784 | apuinfo_list_init (); |
252b5132 | 2785 | |
25dbc73a | 2786 | /* Read in the input sections contents. */ |
c72f2fb2 | 2787 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link.next) |
252b5132 | 2788 | { |
25dbc73a | 2789 | unsigned long datum; |
252b5132 | 2790 | |
25dbc73a AM |
2791 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
2792 | if (asec == NULL) | |
2793 | continue; | |
252b5132 | 2794 | |
695344c0 | 2795 | /* xgettext:c-format */ |
deddc40b | 2796 | error_message = _("corrupt %s section in %B"); |
25dbc73a | 2797 | length = asec->size; |
deddc40b NS |
2798 | if (length < 20) |
2799 | goto fail; | |
2800 | ||
f2faa800 | 2801 | apuinfo_set = TRUE; |
deddc40b | 2802 | if (largest_input_size < asec->size) |
25dbc73a | 2803 | { |
deddc40b NS |
2804 | if (buffer) |
2805 | free (buffer); | |
2806 | largest_input_size = asec->size; | |
2807 | buffer = bfd_malloc (largest_input_size); | |
2808 | if (!buffer) | |
2809 | return; | |
25dbc73a | 2810 | } |
5b914448 | 2811 | |
25dbc73a | 2812 | if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0 |
deddc40b | 2813 | || (bfd_bread (buffer, length, ibfd) != length)) |
25dbc73a | 2814 | { |
695344c0 | 2815 | /* xgettext:c-format */ |
25dbc73a AM |
2816 | error_message = _("unable to read in %s section from %B"); |
2817 | goto fail; | |
2818 | } | |
252b5132 | 2819 | |
25dbc73a AM |
2820 | /* Verify the contents of the header. Note - we have to |
2821 | extract the values this way in order to allow for a | |
2822 | host whose endian-ness is different from the target. */ | |
deddc40b | 2823 | datum = bfd_get_32 (ibfd, buffer); |
25dbc73a AM |
2824 | if (datum != sizeof APUINFO_LABEL) |
2825 | goto fail; | |
252b5132 | 2826 | |
deddc40b | 2827 | datum = bfd_get_32 (ibfd, buffer + 8); |
25dbc73a AM |
2828 | if (datum != 0x2) |
2829 | goto fail; | |
252b5132 | 2830 | |
deddc40b | 2831 | if (strcmp (buffer + 12, APUINFO_LABEL) != 0) |
25dbc73a | 2832 | goto fail; |
252b5132 | 2833 | |
25dbc73a | 2834 | /* Get the number of bytes used for apuinfo entries. */ |
deddc40b | 2835 | datum = bfd_get_32 (ibfd, buffer + 4); |
25dbc73a AM |
2836 | if (datum + 20 != length) |
2837 | goto fail; | |
2838 | ||
25dbc73a AM |
2839 | /* Scan the apuinfo section, building a list of apuinfo numbers. */ |
2840 | for (i = 0; i < datum; i += 4) | |
deddc40b | 2841 | apuinfo_list_add (bfd_get_32 (ibfd, buffer + 20 + i)); |
252b5132 RH |
2842 | } |
2843 | ||
25dbc73a | 2844 | error_message = NULL; |
252b5132 | 2845 | |
f2faa800 | 2846 | if (apuinfo_set) |
deddc40b | 2847 | { |
f2faa800 NS |
2848 | /* Compute the size of the output section. */ |
2849 | unsigned num_entries = apuinfo_list_length (); | |
5b914448 | 2850 | |
deddc40b NS |
2851 | /* Set the output section size, if it exists. */ |
2852 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
f2faa800 | 2853 | |
deddc40b NS |
2854 | if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4)) |
2855 | { | |
2856 | ibfd = abfd; | |
695344c0 | 2857 | /* xgettext:c-format */ |
deddc40b NS |
2858 | error_message = _("warning: unable to set size of %s section in %B"); |
2859 | } | |
2860 | } | |
25dbc73a AM |
2861 | |
2862 | fail: | |
deddc40b NS |
2863 | if (buffer) |
2864 | free (buffer); | |
25dbc73a AM |
2865 | |
2866 | if (error_message) | |
cd9af601 | 2867 | _bfd_error_handler (error_message, APUINFO_SECTION_NAME, ibfd); |
25dbc73a | 2868 | } |
252b5132 | 2869 | |
25dbc73a AM |
2870 | /* Prevent the output section from accumulating the input sections' |
2871 | contents. We have already stored this in our linked list structure. */ | |
252b5132 | 2872 | |
25dbc73a AM |
2873 | static bfd_boolean |
2874 | ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED, | |
c7b8f16e | 2875 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED, |
25dbc73a AM |
2876 | asection *asec, |
2877 | bfd_byte *contents ATTRIBUTE_UNUSED) | |
2878 | { | |
f2faa800 | 2879 | return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0; |
252b5132 RH |
2880 | } |
2881 | ||
25dbc73a AM |
2882 | /* Finally we can generate the output section. */ |
2883 | ||
2884 | static void | |
2885 | ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) | |
7619e7c7 | 2886 | { |
25dbc73a AM |
2887 | bfd_byte *buffer; |
2888 | asection *asec; | |
2889 | unsigned i; | |
2890 | unsigned num_entries; | |
2891 | bfd_size_type length; | |
7619e7c7 | 2892 | |
25dbc73a AM |
2893 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); |
2894 | if (asec == NULL) | |
2895 | return; | |
2896 | ||
f2faa800 | 2897 | if (!apuinfo_set) |
25dbc73a AM |
2898 | return; |
2899 | ||
2900 | length = asec->size; | |
2901 | if (length < 20) | |
2902 | return; | |
2903 | ||
2904 | buffer = bfd_malloc (length); | |
2905 | if (buffer == NULL) | |
7619e7c7 | 2906 | { |
4eca0228 | 2907 | _bfd_error_handler |
25dbc73a AM |
2908 | (_("failed to allocate space for new APUinfo section.")); |
2909 | return; | |
7619e7c7 | 2910 | } |
7619e7c7 | 2911 | |
25dbc73a AM |
2912 | /* Create the apuinfo header. */ |
2913 | num_entries = apuinfo_list_length (); | |
2914 | bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer); | |
2915 | bfd_put_32 (abfd, num_entries * 4, buffer + 4); | |
2916 | bfd_put_32 (abfd, 0x2, buffer + 8); | |
2917 | strcpy ((char *) buffer + 12, APUINFO_LABEL); | |
feee612b | 2918 | |
25dbc73a AM |
2919 | length = 20; |
2920 | for (i = 0; i < num_entries; i++) | |
feee612b | 2921 | { |
25dbc73a AM |
2922 | bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length); |
2923 | length += 4; | |
feee612b | 2924 | } |
feee612b | 2925 | |
25dbc73a | 2926 | if (length != asec->size) |
4eca0228 | 2927 | _bfd_error_handler (_("failed to compute new APUinfo section.")); |
252b5132 | 2928 | |
25dbc73a | 2929 | if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length)) |
4eca0228 | 2930 | _bfd_error_handler (_("failed to install new APUinfo section.")); |
252b5132 | 2931 | |
25dbc73a AM |
2932 | free (buffer); |
2933 | ||
2934 | apuinfo_list_finish (); | |
252b5132 | 2935 | } |
25dbc73a | 2936 | \f |
7382d32a | 2937 | static bfd_boolean |
c6dd29ce | 2938 | is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off) |
7382d32a | 2939 | { |
c6dd29ce | 2940 | bfd_byte buf[GLINK_ENTRY_SIZE]; |
7382d32a | 2941 | |
c6dd29ce | 2942 | if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE)) |
7382d32a AM |
2943 | return FALSE; |
2944 | ||
c6dd29ce AM |
2945 | return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11 |
2946 | && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11 | |
2947 | && bfd_get_32 (abfd, buf + 8) == MTCTR_11 | |
2948 | && bfd_get_32 (abfd, buf + 12) == BCTR); | |
7382d32a AM |
2949 | } |
2950 | ||
468392fb AM |
2951 | static bfd_boolean |
2952 | section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr) | |
2953 | { | |
2954 | bfd_vma vma = *(bfd_vma *) ptr; | |
2955 | return ((section->flags & SEC_ALLOC) != 0 | |
2956 | && section->vma <= vma | |
2957 | && vma < section->vma + section->size); | |
2958 | } | |
2959 | ||
2960 | static long | |
2961 | ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms, | |
2962 | long dynsymcount, asymbol **dynsyms, | |
2963 | asymbol **ret) | |
2964 | { | |
2965 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); | |
2966 | asection *plt, *relplt, *dynamic, *glink; | |
2967 | bfd_vma glink_vma = 0; | |
2968 | bfd_vma resolv_vma = 0; | |
2969 | bfd_vma stub_vma; | |
2970 | asymbol *s; | |
2971 | arelent *p; | |
2972 | long count, i; | |
2973 | size_t size; | |
2974 | char *names; | |
2975 | bfd_byte buf[4]; | |
2976 | ||
2977 | *ret = NULL; | |
2978 | ||
2979 | if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0) | |
2980 | return 0; | |
2981 | ||
2982 | if (dynsymcount <= 0) | |
2983 | return 0; | |
2984 | ||
2985 | relplt = bfd_get_section_by_name (abfd, ".rela.plt"); | |
2986 | if (relplt == NULL) | |
2987 | return 0; | |
2988 | ||
2989 | plt = bfd_get_section_by_name (abfd, ".plt"); | |
2990 | if (plt == NULL) | |
2991 | return 0; | |
2992 | ||
2993 | /* Call common code to handle old-style executable PLTs. */ | |
2994 | if (elf_section_flags (plt) & SHF_EXECINSTR) | |
2995 | return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms, | |
2996 | dynsymcount, dynsyms, ret); | |
2997 | ||
2998 | /* If this object was prelinked, the prelinker stored the address | |
2999 | of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */ | |
3000 | dynamic = bfd_get_section_by_name (abfd, ".dynamic"); | |
3001 | if (dynamic != NULL) | |
3002 | { | |
3003 | bfd_byte *dynbuf, *extdyn, *extdynend; | |
3004 | size_t extdynsize; | |
3005 | void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *); | |
3006 | ||
3007 | if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf)) | |
3008 | return -1; | |
3009 | ||
3010 | extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; | |
3011 | swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in; | |
3012 | ||
3013 | extdyn = dynbuf; | |
3014 | extdynend = extdyn + dynamic->size; | |
3015 | for (; extdyn < extdynend; extdyn += extdynsize) | |
3016 | { | |
3017 | Elf_Internal_Dyn dyn; | |
3018 | (*swap_dyn_in) (abfd, extdyn, &dyn); | |
3019 | ||
3020 | if (dyn.d_tag == DT_NULL) | |
3021 | break; | |
3022 | ||
3023 | if (dyn.d_tag == DT_PPC_GOT) | |
3024 | { | |
3025 | unsigned int g_o_t = dyn.d_un.d_val; | |
3026 | asection *got = bfd_get_section_by_name (abfd, ".got"); | |
3027 | if (got != NULL | |
3028 | && bfd_get_section_contents (abfd, got, buf, | |
3029 | g_o_t - got->vma + 4, 4)) | |
3030 | glink_vma = bfd_get_32 (abfd, buf); | |
3031 | break; | |
3032 | } | |
3033 | } | |
3034 | free (dynbuf); | |
3035 | } | |
3036 | ||
3037 | /* Otherwise we read the first plt entry. */ | |
3038 | if (glink_vma == 0) | |
3039 | { | |
3040 | if (bfd_get_section_contents (abfd, plt, buf, 0, 4)) | |
3041 | glink_vma = bfd_get_32 (abfd, buf); | |
3042 | } | |
3043 | ||
3044 | if (glink_vma == 0) | |
3045 | return 0; | |
3046 | ||
3047 | /* The .glink section usually does not survive the final | |
3048 | link; search for the section (usually .text) where the | |
3049 | glink stubs now reside. */ | |
3050 | glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma); | |
3051 | if (glink == NULL) | |
3052 | return 0; | |
3053 | ||
3054 | /* Determine glink PLT resolver by reading the relative branch | |
3055 | from the first glink stub. */ | |
3056 | if (bfd_get_section_contents (abfd, glink, buf, | |
3057 | glink_vma - glink->vma, 4)) | |
3058 | { | |
3059 | unsigned int insn = bfd_get_32 (abfd, buf); | |
3060 | ||
3061 | /* The first glink stub may either branch to the resolver ... */ | |
3062 | insn ^= B; | |
3063 | if ((insn & ~0x3fffffc) == 0) | |
3064 | resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000; | |
3065 | ||
3066 | /* ... or fall through a bunch of NOPs. */ | |
3067 | else if ((insn ^ B ^ NOP) == 0) | |
3068 | for (i = 4; | |
3069 | bfd_get_section_contents (abfd, glink, buf, | |
3070 | glink_vma - glink->vma + i, 4); | |
3071 | i += 4) | |
3072 | if (bfd_get_32 (abfd, buf) != NOP) | |
3073 | { | |
3074 | resolv_vma = glink_vma + i; | |
3075 | break; | |
3076 | } | |
3077 | } | |
3078 | ||
7382d32a | 3079 | count = relplt->size / sizeof (Elf32_External_Rela); |
7382d32a AM |
3080 | /* If the stubs are those for -shared/-pie then we might have |
3081 | multiple stubs for each plt entry. If that is the case then | |
3082 | there is no way to associate stubs with their plt entries short | |
3083 | of figuring out the GOT pointer value used in the stub. */ | |
c6dd29ce AM |
3084 | if (!is_nonpic_glink_stub (abfd, glink, |
3085 | glink_vma - GLINK_ENTRY_SIZE - glink->vma)) | |
7382d32a AM |
3086 | return 0; |
3087 | ||
468392fb AM |
3088 | slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; |
3089 | if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE)) | |
3090 | return -1; | |
3091 | ||
468392fb AM |
3092 | size = count * sizeof (asymbol); |
3093 | p = relplt->relocation; | |
3094 | for (i = 0; i < count; i++, p++) | |
e054468f AM |
3095 | { |
3096 | size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt"); | |
3097 | if (p->addend != 0) | |
3098 | size += sizeof ("+0x") - 1 + 8; | |
3099 | } | |
468392fb AM |
3100 | |
3101 | size += sizeof (asymbol) + sizeof ("__glink"); | |
3102 | ||
3103 | if (resolv_vma) | |
3104 | size += sizeof (asymbol) + sizeof ("__glink_PLTresolve"); | |
3105 | ||
3106 | s = *ret = bfd_malloc (size); | |
3107 | if (s == NULL) | |
3108 | return -1; | |
3109 | ||
1079403c | 3110 | stub_vma = glink_vma; |
468392fb | 3111 | names = (char *) (s + count + 1 + (resolv_vma != 0)); |
1079403c AM |
3112 | p = relplt->relocation + count - 1; |
3113 | for (i = 0; i < count; i++) | |
468392fb AM |
3114 | { |
3115 | size_t len; | |
3116 | ||
3117 | *s = **p->sym_ptr_ptr; | |
3118 | /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since | |
3119 | we are defining a symbol, ensure one of them is set. */ | |
3120 | if ((s->flags & BSF_LOCAL) == 0) | |
3121 | s->flags |= BSF_GLOBAL; | |
6ba2a415 | 3122 | s->flags |= BSF_SYNTHETIC; |
468392fb | 3123 | s->section = glink; |
1079403c AM |
3124 | stub_vma -= 16; |
3125 | if (strcmp ((*p->sym_ptr_ptr)->name, "__tls_get_addr_opt") == 0) | |
3126 | stub_vma -= 32; | |
468392fb AM |
3127 | s->value = stub_vma - glink->vma; |
3128 | s->name = names; | |
3129 | s->udata.p = NULL; | |
3130 | len = strlen ((*p->sym_ptr_ptr)->name); | |
3131 | memcpy (names, (*p->sym_ptr_ptr)->name, len); | |
3132 | names += len; | |
e054468f AM |
3133 | if (p->addend != 0) |
3134 | { | |
3135 | memcpy (names, "+0x", sizeof ("+0x") - 1); | |
3136 | names += sizeof ("+0x") - 1; | |
3137 | bfd_sprintf_vma (abfd, names, p->addend); | |
3138 | names += strlen (names); | |
3139 | } | |
468392fb AM |
3140 | memcpy (names, "@plt", sizeof ("@plt")); |
3141 | names += sizeof ("@plt"); | |
3142 | ++s; | |
1079403c | 3143 | --p; |
468392fb AM |
3144 | } |
3145 | ||
3146 | /* Add a symbol at the start of the glink branch table. */ | |
86a4952b | 3147 | memset (s, 0, sizeof *s); |
468392fb | 3148 | s->the_bfd = abfd; |
6ba2a415 | 3149 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
3150 | s->section = glink; |
3151 | s->value = glink_vma - glink->vma; | |
3152 | s->name = names; | |
3153 | memcpy (names, "__glink", sizeof ("__glink")); | |
3154 | names += sizeof ("__glink"); | |
3155 | s++; | |
3156 | count++; | |
3157 | ||
3158 | if (resolv_vma) | |
3159 | { | |
3160 | /* Add a symbol for the glink PLT resolver. */ | |
86a4952b | 3161 | memset (s, 0, sizeof *s); |
468392fb | 3162 | s->the_bfd = abfd; |
6ba2a415 | 3163 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
3164 | s->section = glink; |
3165 | s->value = resolv_vma - glink->vma; | |
3166 | s->name = names; | |
3167 | memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve")); | |
3168 | names += sizeof ("__glink_PLTresolve"); | |
3169 | s++; | |
3170 | count++; | |
3171 | } | |
3172 | ||
3173 | return count; | |
3174 | } | |
3175 | \f | |
25dbc73a AM |
3176 | /* The following functions are specific to the ELF linker, while |
3177 | functions above are used generally. They appear in this file more | |
3178 | or less in the order in which they are called. eg. | |
3179 | ppc_elf_check_relocs is called early in the link process, | |
3180 | ppc_elf_finish_dynamic_sections is one of the last functions | |
3181 | called. */ | |
252b5132 | 3182 | |
a6aa5195 | 3183 | /* Track PLT entries needed for a given symbol. We might need more |
a877a2b6 | 3184 | than one glink entry per symbol when generating a pic binary. */ |
a6aa5195 AM |
3185 | struct plt_entry |
3186 | { | |
3187 | struct plt_entry *next; | |
3188 | ||
3189 | /* -fPIC uses multiple GOT sections, one per file, called ".got2". | |
3190 | This field stores the offset into .got2 used to initialise the | |
a877a2b6 AM |
3191 | GOT pointer reg. It will always be at least 32768. (Current |
3192 | gcc always uses an offset of 32768, but ld -r will pack .got2 | |
3193 | sections together resulting in larger offsets). */ | |
a6aa5195 AM |
3194 | bfd_vma addend; |
3195 | ||
3196 | /* The .got2 section. */ | |
3197 | asection *sec; | |
3198 | ||
3199 | /* PLT refcount or offset. */ | |
3200 | union | |
3201 | { | |
3202 | bfd_signed_vma refcount; | |
3203 | bfd_vma offset; | |
3204 | } plt; | |
3205 | ||
3206 | /* .glink stub offset. */ | |
3207 | bfd_vma glink_offset; | |
3208 | }; | |
3209 | ||
7c8bbca5 AM |
3210 | /* Of those relocs that might be copied as dynamic relocs, this |
3211 | function selects those that must be copied when linking a shared | |
3212 | library or PIE, even when the symbol is local. */ | |
252b5132 | 3213 | |
1d483afe AM |
3214 | static int |
3215 | must_be_dyn_reloc (struct bfd_link_info *info, | |
3216 | enum elf_ppc_reloc_type r_type) | |
3217 | { | |
3218 | switch (r_type) | |
3219 | { | |
3220 | default: | |
7c8bbca5 AM |
3221 | /* Only relative relocs can be resolved when the object load |
3222 | address isn't fixed. DTPREL32 is excluded because the | |
3223 | dynamic linker needs to differentiate global dynamic from | |
3224 | local dynamic __tls_index pairs when PPC_OPT_TLS is set. */ | |
1d483afe AM |
3225 | return 1; |
3226 | ||
3227 | case R_PPC_REL24: | |
3228 | case R_PPC_REL14: | |
3229 | case R_PPC_REL14_BRTAKEN: | |
3230 | case R_PPC_REL14_BRNTAKEN: | |
3231 | case R_PPC_REL32: | |
3232 | return 0; | |
3233 | ||
3234 | case R_PPC_TPREL32: | |
3235 | case R_PPC_TPREL16: | |
3236 | case R_PPC_TPREL16_LO: | |
3237 | case R_PPC_TPREL16_HI: | |
3238 | case R_PPC_TPREL16_HA: | |
7c8bbca5 AM |
3239 | /* These relocations are relative but in a shared library the |
3240 | linker doesn't know the thread pointer base. */ | |
3241 | return bfd_link_dll (info); | |
1d483afe AM |
3242 | } |
3243 | } | |
252b5132 | 3244 | |
21d68fcd AM |
3245 | /* Whether an undefined weak symbol should resolve to its link-time |
3246 | value, even in PIC or PIE objects. */ | |
3247 | #define UNDEFWEAK_NO_DYNAMIC_RELOC(INFO, H) \ | |
3248 | ((H)->root.type == bfd_link_hash_undefweak \ | |
3249 | && (ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT \ | |
3250 | || (INFO)->dynamic_undefined_weak == 0)) | |
3251 | ||
25dbc73a AM |
3252 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
3253 | copying dynamic variables from a shared lib into an app's dynbss | |
3254 | section, and instead use a dynamic relocation to point into the | |
3255 | shared lib. */ | |
3256 | #define ELIMINATE_COPY_RELOCS 1 | |
252b5132 | 3257 | |
f95f8542 AM |
3258 | /* Used to track dynamic relocations for local symbols. */ |
3259 | struct ppc_dyn_relocs | |
3260 | { | |
3261 | struct ppc_dyn_relocs *next; | |
3262 | ||
3263 | /* The input section of the reloc. */ | |
3264 | asection *sec; | |
3265 | ||
3266 | /* Total number of relocs copied for the input section. */ | |
3267 | unsigned int count : 31; | |
3268 | ||
3269 | /* Whether this entry is for STT_GNU_IFUNC symbols. */ | |
3270 | unsigned int ifunc : 1; | |
3271 | }; | |
3272 | ||
25dbc73a | 3273 | /* PPC ELF linker hash entry. */ |
252b5132 | 3274 | |
25dbc73a AM |
3275 | struct ppc_elf_link_hash_entry |
3276 | { | |
3277 | struct elf_link_hash_entry elf; | |
252b5132 | 3278 | |
25dbc73a AM |
3279 | /* If this symbol is used in the linker created sections, the processor |
3280 | specific backend uses this field to map the field into the offset | |
3281 | from the beginning of the section. */ | |
3282 | elf_linker_section_pointers_t *linker_section_pointer; | |
252b5132 | 3283 | |
25dbc73a | 3284 | /* Track dynamic relocs copied for this symbol. */ |
6061a67d | 3285 | struct elf_dyn_relocs *dyn_relocs; |
252b5132 | 3286 | |
25dbc73a AM |
3287 | /* Contexts in which symbol is used in the GOT (or TOC). |
3288 | TLS_GD .. TLS_TLS bits are or'd into the mask as the | |
3289 | corresponding relocs are encountered during check_relocs. | |
3290 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
3291 | indicate the corresponding GOT entry type is not needed. */ | |
3292 | #define TLS_GD 1 /* GD reloc. */ | |
3293 | #define TLS_LD 2 /* LD reloc. */ | |
3294 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
3295 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
3296 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
3297 | #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */ | |
e054468f | 3298 | #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */ |
25dbc73a | 3299 | char tls_mask; |
4dc4a9a5 DJ |
3300 | |
3301 | /* Nonzero if we have seen a small data relocation referring to this | |
3302 | symbol. */ | |
d3e454b9 AM |
3303 | unsigned char has_sda_refs : 1; |
3304 | ||
3305 | /* Flag use of given relocations. */ | |
3306 | unsigned char has_addr16_ha : 1; | |
3307 | unsigned char has_addr16_lo : 1; | |
25dbc73a | 3308 | }; |
252b5132 | 3309 | |
25dbc73a AM |
3310 | #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent)) |
3311 | ||
3312 | /* PPC ELF linker hash table. */ | |
3313 | ||
3314 | struct ppc_elf_link_hash_table | |
3315 | { | |
3316 | struct elf_link_hash_table elf; | |
3317 | ||
5446cbdf AM |
3318 | /* Various options passed from the linker. */ |
3319 | struct ppc_elf_params *params; | |
3320 | ||
25dbc73a | 3321 | /* Short-cuts to get to dynamic linker sections. */ |
d7128ce4 | 3322 | asection *glink; |
25dbc73a AM |
3323 | asection *dynsbss; |
3324 | asection *relsbss; | |
c9a2f333 | 3325 | elf_linker_section_t sdata[2]; |
25dbc73a | 3326 | asection *sbss; |
6177242a | 3327 | asection *glink_eh_frame; |
25dbc73a | 3328 | |
016687f8 AM |
3329 | /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */ |
3330 | asection *srelplt2; | |
3331 | ||
1d483afe | 3332 | /* Shortcut to __tls_get_addr. */ |
25dbc73a | 3333 | struct elf_link_hash_entry *tls_get_addr; |
252b5132 | 3334 | |
016687f8 AM |
3335 | /* The bfd that forced an old-style PLT. */ |
3336 | bfd *old_bfd; | |
5b914448 | 3337 | |
25dbc73a AM |
3338 | /* TLS local dynamic got entry handling. */ |
3339 | union { | |
3340 | bfd_signed_vma refcount; | |
3341 | bfd_vma offset; | |
3342 | } tlsld_got; | |
252b5132 | 3343 | |
c6dd29ce | 3344 | /* Offset of branch table to PltResolve function in glink. */ |
d7128ce4 AM |
3345 | bfd_vma glink_pltresolve; |
3346 | ||
3b36f7e6 AM |
3347 | /* Size of reserved GOT entries. */ |
3348 | unsigned int got_header_size; | |
3349 | /* Non-zero if allocating the header left a gap. */ | |
3350 | unsigned int got_gap; | |
3351 | ||
4a3dc543 RS |
3352 | /* The type of PLT we have chosen to use. */ |
3353 | enum ppc_elf_plt_type plt_type; | |
3354 | ||
9d8504b1 | 3355 | /* True if the target system is VxWorks. */ |
016687f8 | 3356 | unsigned int is_vxworks:1; |
9d8504b1 | 3357 | |
82e66161 AM |
3358 | /* Whether there exist local gnu indirect function resolvers, |
3359 | referenced by dynamic relocations. */ | |
3360 | unsigned int local_ifunc_resolver:1; | |
3361 | unsigned int maybe_local_ifunc_resolver:1; | |
3362 | ||
9a23f96e AM |
3363 | /* Set if tls optimization is enabled. */ |
3364 | unsigned int do_tls_opt:1; | |
3365 | ||
9d8504b1 PB |
3366 | /* The size of PLT entries. */ |
3367 | int plt_entry_size; | |
3368 | /* The distance between adjacent PLT slots. */ | |
3369 | int plt_slot_size; | |
3370 | /* The size of the first PLT entry. */ | |
3371 | int plt_initial_entry_size; | |
016687f8 | 3372 | |
87d72d41 AM |
3373 | /* Small local sym cache. */ |
3374 | struct sym_cache sym_cache; | |
25dbc73a | 3375 | }; |
252b5132 | 3376 | |
94caa966 AM |
3377 | /* Rename some of the generic section flags to better document how they |
3378 | are used for ppc32. The flags are only valid for ppc32 elf objects. */ | |
3379 | ||
3380 | /* Nonzero if this section has TLS related relocations. */ | |
3381 | #define has_tls_reloc sec_flg0 | |
3382 | ||
3383 | /* Nonzero if this section has a call to __tls_get_addr. */ | |
3384 | #define has_tls_get_addr_call sec_flg1 | |
3385 | ||
25dbc73a | 3386 | /* Get the PPC ELF linker hash table from a link_info structure. */ |
252b5132 | 3387 | |
25dbc73a | 3388 | #define ppc_elf_hash_table(p) \ |
4dfe6ac6 NC |
3389 | (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ |
3390 | == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL) | |
252b5132 | 3391 | |
25dbc73a | 3392 | /* Create an entry in a PPC ELF linker hash table. */ |
252b5132 | 3393 | |
25dbc73a AM |
3394 | static struct bfd_hash_entry * |
3395 | ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry, | |
3396 | struct bfd_hash_table *table, | |
3397 | const char *string) | |
252b5132 | 3398 | { |
25dbc73a AM |
3399 | /* Allocate the structure if it has not already been allocated by a |
3400 | subclass. */ | |
3401 | if (entry == NULL) | |
3402 | { | |
3403 | entry = bfd_hash_allocate (table, | |
3404 | sizeof (struct ppc_elf_link_hash_entry)); | |
3405 | if (entry == NULL) | |
3406 | return entry; | |
3407 | } | |
252b5132 | 3408 | |
25dbc73a AM |
3409 | /* Call the allocation method of the superclass. */ |
3410 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
3411 | if (entry != NULL) | |
3412 | { | |
3413 | ppc_elf_hash_entry (entry)->linker_section_pointer = NULL; | |
3414 | ppc_elf_hash_entry (entry)->dyn_relocs = NULL; | |
3415 | ppc_elf_hash_entry (entry)->tls_mask = 0; | |
5240d94d | 3416 | ppc_elf_hash_entry (entry)->has_sda_refs = 0; |
25dbc73a | 3417 | } |
252b5132 | 3418 | |
25dbc73a | 3419 | return entry; |
252b5132 | 3420 | } |
3dab13f6 | 3421 | |
25dbc73a | 3422 | /* Create a PPC ELF linker hash table. */ |
3dab13f6 | 3423 | |
25dbc73a AM |
3424 | static struct bfd_link_hash_table * |
3425 | ppc_elf_link_hash_table_create (bfd *abfd) | |
3dab13f6 | 3426 | { |
25dbc73a | 3427 | struct ppc_elf_link_hash_table *ret; |
76e7a751 | 3428 | static struct ppc_elf_params default_params |
08dc996f | 3429 | = { PLT_OLD, 0, 1, 0, 0, 12, 0, 0, 0 }; |
3dab13f6 | 3430 | |
25dbc73a AM |
3431 | ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table)); |
3432 | if (ret == NULL) | |
3433 | return NULL; | |
3dab13f6 | 3434 | |
66eb6687 AM |
3435 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, |
3436 | ppc_elf_link_hash_newfunc, | |
4dfe6ac6 NC |
3437 | sizeof (struct ppc_elf_link_hash_entry), |
3438 | PPC32_ELF_DATA)) | |
3dab13f6 | 3439 | { |
25dbc73a AM |
3440 | free (ret); |
3441 | return NULL; | |
3442 | } | |
58111eb7 | 3443 | |
a6aa5195 AM |
3444 | ret->elf.init_plt_refcount.refcount = 0; |
3445 | ret->elf.init_plt_refcount.glist = NULL; | |
3446 | ret->elf.init_plt_offset.offset = 0; | |
3447 | ret->elf.init_plt_offset.glist = NULL; | |
3448 | ||
db434ba0 AM |
3449 | ret->params = &default_params; |
3450 | ||
c9a2f333 AM |
3451 | ret->sdata[0].name = ".sdata"; |
3452 | ret->sdata[0].sym_name = "_SDA_BASE_"; | |
3453 | ret->sdata[0].bss_name = ".sbss"; | |
3454 | ||
3455 | ret->sdata[1].name = ".sdata2"; | |
3456 | ret->sdata[1].sym_name = "_SDA2_BASE_"; | |
3457 | ret->sdata[1].bss_name = ".sbss2"; | |
3458 | ||
9d8504b1 PB |
3459 | ret->plt_entry_size = 12; |
3460 | ret->plt_slot_size = 8; | |
3461 | ret->plt_initial_entry_size = 72; | |
9d8504b1 | 3462 | |
25dbc73a AM |
3463 | return &ret->elf.root; |
3464 | } | |
3dab13f6 | 3465 | |
5446cbdf AM |
3466 | /* Hook linker params into hash table. */ |
3467 | ||
3468 | void | |
3469 | ppc_elf_link_params (struct bfd_link_info *info, struct ppc_elf_params *params) | |
3470 | { | |
3471 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
3472 | ||
3473 | if (htab) | |
3474 | htab->params = params; | |
76e7a751 | 3475 | params->pagesize_p2 = bfd_log2 (params->pagesize); |
5446cbdf AM |
3476 | } |
3477 | ||
9d8504b1 | 3478 | /* Create .got and the related sections. */ |
3dab13f6 | 3479 | |
25dbc73a AM |
3480 | static bfd_boolean |
3481 | ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info) | |
3482 | { | |
3483 | struct ppc_elf_link_hash_table *htab; | |
3dab13f6 | 3484 | |
25dbc73a AM |
3485 | if (!_bfd_elf_create_got_section (abfd, info)) |
3486 | return FALSE; | |
3dab13f6 | 3487 | |
25dbc73a | 3488 | htab = ppc_elf_hash_table (info); |
ce558b89 | 3489 | if (!htab->is_vxworks) |
9d8504b1 PB |
3490 | { |
3491 | /* The powerpc .got has a blrl instruction in it. Mark it | |
3492 | executable. */ | |
ce558b89 AM |
3493 | flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS |
3494 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3495 | if (!bfd_set_section_flags (abfd, htab->elf.sgot, flags)) | |
9d8504b1 PB |
3496 | return FALSE; |
3497 | } | |
3dab13f6 | 3498 | |
25dbc73a AM |
3499 | return TRUE; |
3500 | } | |
3dab13f6 | 3501 | |
93d1b056 AM |
3502 | /* Create a special linker section, used for R_PPC_EMB_SDAI16 and |
3503 | R_PPC_EMB_SDA2I16 pointers. These sections become part of .sdata | |
3504 | and .sdata2. Create _SDA_BASE_ and _SDA2_BASE too. */ | |
3505 | ||
3506 | static bfd_boolean | |
3507 | ppc_elf_create_linker_section (bfd *abfd, | |
3508 | struct bfd_link_info *info, | |
3509 | flagword flags, | |
3510 | elf_linker_section_t *lsect) | |
3511 | { | |
3512 | asection *s; | |
3513 | ||
3514 | flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3515 | | SEC_LINKER_CREATED); | |
3516 | ||
3517 | s = bfd_make_section_anyway_with_flags (abfd, lsect->name, flags); | |
3518 | if (s == NULL) | |
3519 | return FALSE; | |
3520 | lsect->section = s; | |
3521 | ||
3522 | /* Define the sym on the first section of this name. */ | |
3523 | s = bfd_get_section_by_name (abfd, lsect->name); | |
3524 | ||
3525 | lsect->sym = _bfd_elf_define_linkage_sym (abfd, info, s, lsect->sym_name); | |
3526 | if (lsect->sym == NULL) | |
3527 | return FALSE; | |
3528 | lsect->sym->root.u.def.value = 0x8000; | |
3529 | return TRUE; | |
3530 | } | |
3531 | ||
e054468f AM |
3532 | static bfd_boolean |
3533 | ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info) | |
3534 | { | |
3535 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
3536 | asection *s; | |
3537 | flagword flags; | |
3538 | ||
3539 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | |
3540 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3541 | s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags); | |
3542 | htab->glink = s; | |
3543 | if (s == NULL | |
5446cbdf AM |
3544 | || !bfd_set_section_alignment (abfd, s, |
3545 | htab->params->ppc476_workaround ? 6 : 4)) | |
e054468f AM |
3546 | return FALSE; |
3547 | ||
6177242a AM |
3548 | if (!info->no_ld_generated_unwind_info) |
3549 | { | |
3550 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | |
3551 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3552 | s = bfd_make_section_anyway_with_flags (abfd, ".eh_frame", flags); | |
3553 | htab->glink_eh_frame = s; | |
3554 | if (s == NULL | |
3555 | || !bfd_set_section_alignment (abfd, s, 2)) | |
3556 | return FALSE; | |
3557 | } | |
3558 | ||
e054468f AM |
3559 | flags = SEC_ALLOC | SEC_LINKER_CREATED; |
3560 | s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags); | |
ce558b89 | 3561 | htab->elf.iplt = s; |
e054468f AM |
3562 | if (s == NULL |
3563 | || !bfd_set_section_alignment (abfd, s, 4)) | |
3564 | return FALSE; | |
3565 | ||
3566 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | |
3567 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
14b2f831 | 3568 | s = bfd_make_section_anyway_with_flags (abfd, ".rela.iplt", flags); |
ce558b89 | 3569 | htab->elf.irelplt = s; |
e054468f AM |
3570 | if (s == NULL |
3571 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
3572 | return FALSE; | |
93d1b056 AM |
3573 | |
3574 | if (!ppc_elf_create_linker_section (abfd, info, 0, | |
3575 | &htab->sdata[0])) | |
3576 | return FALSE; | |
3577 | ||
3578 | if (!ppc_elf_create_linker_section (abfd, info, SEC_READONLY, | |
3579 | &htab->sdata[1])) | |
3580 | return FALSE; | |
3581 | ||
e054468f AM |
3582 | return TRUE; |
3583 | } | |
3584 | ||
25dbc73a AM |
3585 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
3586 | to output sections (just like _bfd_elf_create_dynamic_sections has | |
3587 | to create .dynbss and .rela.bss). */ | |
3dab13f6 | 3588 | |
25dbc73a AM |
3589 | static bfd_boolean |
3590 | ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |
3591 | { | |
3592 | struct ppc_elf_link_hash_table *htab; | |
3593 | asection *s; | |
3594 | flagword flags; | |
3dab13f6 | 3595 | |
25dbc73a | 3596 | htab = ppc_elf_hash_table (info); |
3dab13f6 | 3597 | |
ce558b89 | 3598 | if (htab->elf.sgot == NULL |
25dbc73a | 3599 | && !ppc_elf_create_got (abfd, info)) |
3dab13f6 AM |
3600 | return FALSE; |
3601 | ||
25dbc73a AM |
3602 | if (!_bfd_elf_create_dynamic_sections (abfd, info)) |
3603 | return FALSE; | |
3dab13f6 | 3604 | |
e054468f AM |
3605 | if (htab->glink == NULL |
3606 | && !ppc_elf_create_glink (abfd, info)) | |
d7128ce4 | 3607 | return FALSE; |
3dab13f6 | 3608 | |
14b2f831 AM |
3609 | s = bfd_make_section_anyway_with_flags (abfd, ".dynsbss", |
3610 | SEC_ALLOC | SEC_LINKER_CREATED); | |
3b36f7e6 | 3611 | htab->dynsbss = s; |
3496cb2a | 3612 | if (s == NULL) |
25dbc73a | 3613 | return FALSE; |
3dab13f6 | 3614 | |
0e1862bb | 3615 | if (! bfd_link_pic (info)) |
25dbc73a | 3616 | { |
e054468f AM |
3617 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS |
3618 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
14b2f831 | 3619 | s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss", flags); |
3b36f7e6 | 3620 | htab->relsbss = s; |
25dbc73a | 3621 | if (s == NULL |
25dbc73a AM |
3622 | || ! bfd_set_section_alignment (abfd, s, 2)) |
3623 | return FALSE; | |
3624 | } | |
3dab13f6 | 3625 | |
711de32c RS |
3626 | if (htab->is_vxworks |
3627 | && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2)) | |
3628 | return FALSE; | |
9d8504b1 | 3629 | |
ce558b89 | 3630 | s = htab->elf.splt; |
3b36f7e6 | 3631 | flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED; |
4a3dc543 RS |
3632 | if (htab->plt_type == PLT_VXWORKS) |
3633 | /* The VxWorks PLT is a loaded section with contents. */ | |
3634 | flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY; | |
25dbc73a AM |
3635 | return bfd_set_section_flags (abfd, s, flags); |
3636 | } | |
3dab13f6 | 3637 | |
25dbc73a | 3638 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
58111eb7 | 3639 | |
25dbc73a | 3640 | static void |
fcfa13d2 | 3641 | ppc_elf_copy_indirect_symbol (struct bfd_link_info *info, |
25dbc73a AM |
3642 | struct elf_link_hash_entry *dir, |
3643 | struct elf_link_hash_entry *ind) | |
3644 | { | |
3645 | struct ppc_elf_link_hash_entry *edir, *eind; | |
3dab13f6 | 3646 | |
25dbc73a AM |
3647 | edir = (struct ppc_elf_link_hash_entry *) dir; |
3648 | eind = (struct ppc_elf_link_hash_entry *) ind; | |
3dab13f6 | 3649 | |
c79d6685 AM |
3650 | edir->tls_mask |= eind->tls_mask; |
3651 | edir->has_sda_refs |= eind->has_sda_refs; | |
3652 | ||
3653 | /* If called to transfer flags for a weakdef during processing | |
3654 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |
3655 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3656 | if (!(ELIMINATE_COPY_RELOCS | |
3657 | && eind->elf.root.type != bfd_link_hash_indirect | |
3658 | && edir->elf.dynamic_adjusted)) | |
3659 | edir->elf.non_got_ref |= eind->elf.non_got_ref; | |
3660 | ||
e81830c5 AM |
3661 | if (edir->elf.versioned != versioned_hidden) |
3662 | edir->elf.ref_dynamic |= eind->elf.ref_dynamic; | |
c79d6685 AM |
3663 | edir->elf.ref_regular |= eind->elf.ref_regular; |
3664 | edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak; | |
3665 | edir->elf.needs_plt |= eind->elf.needs_plt; | |
3666 | edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed; | |
3667 | ||
25dbc73a AM |
3668 | if (eind->dyn_relocs != NULL) |
3669 | { | |
3670 | if (edir->dyn_relocs != NULL) | |
3dab13f6 | 3671 | { |
6061a67d AM |
3672 | struct elf_dyn_relocs **pp; |
3673 | struct elf_dyn_relocs *p; | |
3dab13f6 | 3674 | |
fcfa13d2 | 3675 | /* Add reloc counts against the indirect sym to the direct sym |
25dbc73a AM |
3676 | list. Merge any entries against the same section. */ |
3677 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3dab13f6 | 3678 | { |
6061a67d | 3679 | struct elf_dyn_relocs *q; |
25dbc73a AM |
3680 | |
3681 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3682 | if (q->sec == p->sec) | |
3683 | { | |
3684 | q->pc_count += p->pc_count; | |
3685 | q->count += p->count; | |
3686 | *pp = p->next; | |
3687 | break; | |
3688 | } | |
3689 | if (q == NULL) | |
3690 | pp = &p->next; | |
3dab13f6 | 3691 | } |
25dbc73a | 3692 | *pp = edir->dyn_relocs; |
3dab13f6 | 3693 | } |
25dbc73a AM |
3694 | |
3695 | edir->dyn_relocs = eind->dyn_relocs; | |
3696 | eind->dyn_relocs = NULL; | |
3dab13f6 | 3697 | } |
3dab13f6 | 3698 | |
68ba6d40 AM |
3699 | /* If we were called to copy over info for a weak sym, that's all. |
3700 | You might think dyn_relocs need not be copied over; After all, | |
3701 | both syms will be dynamic or both non-dynamic so we're just | |
68ffbac6 | 3702 | moving reloc accounting around. However, ELIMINATE_COPY_RELOCS |
68ba6d40 AM |
3703 | code in ppc_elf_adjust_dynamic_symbol needs to check for |
3704 | dyn_relocs in read-only sections, and it does so on what is the | |
3705 | DIR sym here. */ | |
3706 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3707 | return; | |
3708 | ||
a6aa5195 AM |
3709 | /* Copy over the GOT refcount entries that we may have already seen to |
3710 | the symbol which just became indirect. */ | |
fcfa13d2 AM |
3711 | edir->elf.got.refcount += eind->elf.got.refcount; |
3712 | eind->elf.got.refcount = 0; | |
a6aa5195 AM |
3713 | |
3714 | /* And plt entries. */ | |
3715 | if (eind->elf.plt.plist != NULL) | |
3716 | { | |
3717 | if (edir->elf.plt.plist != NULL) | |
3718 | { | |
3719 | struct plt_entry **entp; | |
3720 | struct plt_entry *ent; | |
3721 | ||
3722 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3723 | { | |
3724 | struct plt_entry *dent; | |
3725 | ||
3726 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3727 | if (dent->sec == ent->sec && dent->addend == ent->addend) | |
3728 | { | |
3729 | dent->plt.refcount += ent->plt.refcount; | |
3730 | *entp = ent->next; | |
3731 | break; | |
3732 | } | |
3733 | if (dent == NULL) | |
3734 | entp = &ent->next; | |
3735 | } | |
3736 | *entp = edir->elf.plt.plist; | |
3737 | } | |
3738 | ||
3739 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3740 | eind->elf.plt.plist = NULL; | |
3741 | } | |
3742 | ||
fcfa13d2 | 3743 | if (eind->elf.dynindx != -1) |
25dbc73a | 3744 | { |
fcfa13d2 AM |
3745 | if (edir->elf.dynindx != -1) |
3746 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
3747 | edir->elf.dynstr_index); | |
a6aa5195 AM |
3748 | edir->elf.dynindx = eind->elf.dynindx; |
3749 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3750 | eind->elf.dynindx = -1; | |
3751 | eind->elf.dynstr_index = 0; | |
25dbc73a | 3752 | } |
25dbc73a | 3753 | } |
3dab13f6 | 3754 | |
25dbc73a AM |
3755 | /* Hook called by the linker routine which adds symbols from an object |
3756 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
58111eb7 | 3757 | |
25dbc73a AM |
3758 | static bfd_boolean |
3759 | ppc_elf_add_symbol_hook (bfd *abfd, | |
3760 | struct bfd_link_info *info, | |
3761 | Elf_Internal_Sym *sym, | |
3762 | const char **namep ATTRIBUTE_UNUSED, | |
3763 | flagword *flagsp ATTRIBUTE_UNUSED, | |
3764 | asection **secp, | |
3765 | bfd_vma *valp) | |
3766 | { | |
3767 | if (sym->st_shndx == SHN_COMMON | |
0e1862bb | 3768 | && !bfd_link_relocatable (info) |
0c8d6e5c AM |
3769 | && is_ppc_elf (info->output_bfd) |
3770 | && sym->st_size <= elf_gp_size (abfd)) | |
25dbc73a AM |
3771 | { |
3772 | /* Common symbols less than or equal to -G nn bytes are automatically | |
3773 | put into .sbss. */ | |
3774 | struct ppc_elf_link_hash_table *htab; | |
3dab13f6 | 3775 | |
25dbc73a AM |
3776 | htab = ppc_elf_hash_table (info); |
3777 | if (htab->sbss == NULL) | |
3778 | { | |
644285ef | 3779 | flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED; |
3dab13f6 | 3780 | |
644285ef AM |
3781 | if (!htab->elf.dynobj) |
3782 | htab->elf.dynobj = abfd; | |
3783 | ||
3496cb2a L |
3784 | htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
3785 | ".sbss", | |
3786 | flags); | |
3787 | if (htab->sbss == NULL) | |
25dbc73a | 3788 | return FALSE; |
3dab13f6 | 3789 | } |
3dab13f6 | 3790 | |
25dbc73a AM |
3791 | *secp = htab->sbss; |
3792 | *valp = sym->st_size; | |
3793 | } | |
3dab13f6 | 3794 | |
a43942db | 3795 | if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC |
f1885d1e AM |
3796 | && (abfd->flags & DYNAMIC) == 0 |
3797 | && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour) | |
a43942db | 3798 | elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc; |
e054468f | 3799 | |
25dbc73a | 3800 | return TRUE; |
3dab13f6 AM |
3801 | } |
3802 | \f | |
25dbc73a AM |
3803 | /* Find a linker generated pointer with a given addend and type. */ |
3804 | ||
3805 | static elf_linker_section_pointers_t * | |
3806 | elf_find_pointer_linker_section | |
3807 | (elf_linker_section_pointers_t *linker_pointers, | |
3808 | bfd_vma addend, | |
3809 | elf_linker_section_t *lsect) | |
252b5132 | 3810 | { |
25dbc73a AM |
3811 | for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next) |
3812 | if (lsect == linker_pointers->lsect && addend == linker_pointers->addend) | |
3813 | return linker_pointers; | |
252b5132 | 3814 | |
25dbc73a AM |
3815 | return NULL; |
3816 | } | |
3817 | ||
3818 | /* Allocate a pointer to live in a linker created section. */ | |
3819 | ||
3820 | static bfd_boolean | |
93d1b056 AM |
3821 | elf_allocate_pointer_linker_section (bfd *abfd, |
3822 | elf_linker_section_t *lsect, | |
3823 | struct elf_link_hash_entry *h, | |
3824 | const Elf_Internal_Rela *rel) | |
25dbc73a AM |
3825 | { |
3826 | elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL; | |
3827 | elf_linker_section_pointers_t *linker_section_ptr; | |
3828 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
3829 | bfd_size_type amt; | |
3830 | ||
3831 | BFD_ASSERT (lsect != NULL); | |
3832 | ||
3833 | /* Is this a global symbol? */ | |
3834 | if (h != NULL) | |
3835 | { | |
3836 | struct ppc_elf_link_hash_entry *eh; | |
3837 | ||
3838 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3839 | eh = (struct ppc_elf_link_hash_entry *) h; | |
3840 | if (elf_find_pointer_linker_section (eh->linker_section_pointer, | |
3841 | rel->r_addend, | |
3842 | lsect)) | |
3843 | return TRUE; | |
3844 | ||
3845 | ptr_linker_section_ptr = &eh->linker_section_pointer; | |
25dbc73a AM |
3846 | } |
3847 | else | |
3848 | { | |
0c8d6e5c | 3849 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 3850 | |
25dbc73a AM |
3851 | /* Allocation of a pointer to a local symbol. */ |
3852 | elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); | |
3853 | ||
3854 | /* Allocate a table to hold the local symbols if first time. */ | |
3855 | if (!ptr) | |
3856 | { | |
0ffa91dd | 3857 | unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info; |
25dbc73a AM |
3858 | |
3859 | amt = num_symbols; | |
3860 | amt *= sizeof (elf_linker_section_pointers_t *); | |
3861 | ptr = bfd_zalloc (abfd, amt); | |
3862 | ||
3863 | if (!ptr) | |
3864 | return FALSE; | |
3865 | ||
3866 | elf_local_ptr_offsets (abfd) = ptr; | |
3867 | } | |
3868 | ||
3869 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3870 | if (elf_find_pointer_linker_section (ptr[r_symndx], | |
3871 | rel->r_addend, | |
3872 | lsect)) | |
3873 | return TRUE; | |
252b5132 | 3874 | |
25dbc73a | 3875 | ptr_linker_section_ptr = &ptr[r_symndx]; |
25dbc73a | 3876 | } |
41fcb14e | 3877 | |
25dbc73a AM |
3878 | /* Allocate space for a pointer in the linker section, and allocate |
3879 | a new pointer record from internal memory. */ | |
3880 | BFD_ASSERT (ptr_linker_section_ptr != NULL); | |
3881 | amt = sizeof (elf_linker_section_pointers_t); | |
3882 | linker_section_ptr = bfd_alloc (abfd, amt); | |
41fcb14e | 3883 | |
25dbc73a | 3884 | if (!linker_section_ptr) |
7619e7c7 | 3885 | return FALSE; |
41fcb14e | 3886 | |
25dbc73a AM |
3887 | linker_section_ptr->next = *ptr_linker_section_ptr; |
3888 | linker_section_ptr->addend = rel->r_addend; | |
3889 | linker_section_ptr->lsect = lsect; | |
25dbc73a | 3890 | *ptr_linker_section_ptr = linker_section_ptr; |
41fcb14e | 3891 | |
93d1b056 AM |
3892 | if (!bfd_set_section_alignment (lsect->section->owner, lsect->section, 2)) |
3893 | return FALSE; | |
25dbc73a AM |
3894 | linker_section_ptr->offset = lsect->section->size; |
3895 | lsect->section->size += 4; | |
7619e7c7 | 3896 | |
25dbc73a AM |
3897 | #ifdef DEBUG |
3898 | fprintf (stderr, | |
3899 | "Create pointer in linker section %s, offset = %ld, section size = %ld\n", | |
3900 | lsect->name, (long) linker_section_ptr->offset, | |
3901 | (long) lsect->section->size); | |
3902 | #endif | |
7619e7c7 AM |
3903 | |
3904 | return TRUE; | |
41fcb14e AM |
3905 | } |
3906 | ||
e054468f | 3907 | static struct plt_entry ** |
25dbc73a AM |
3908 | update_local_sym_info (bfd *abfd, |
3909 | Elf_Internal_Shdr *symtab_hdr, | |
3910 | unsigned long r_symndx, | |
3911 | int tls_type) | |
252b5132 | 3912 | { |
25dbc73a | 3913 | bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd); |
e054468f | 3914 | struct plt_entry **local_plt; |
25dbc73a | 3915 | char *local_got_tls_masks; |
252b5132 | 3916 | |
25dbc73a | 3917 | if (local_got_refcounts == NULL) |
252b5132 | 3918 | { |
25dbc73a AM |
3919 | bfd_size_type size = symtab_hdr->sh_info; |
3920 | ||
e054468f AM |
3921 | size *= (sizeof (*local_got_refcounts) |
3922 | + sizeof (*local_plt) | |
3923 | + sizeof (*local_got_tls_masks)); | |
25dbc73a AM |
3924 | local_got_refcounts = bfd_zalloc (abfd, size); |
3925 | if (local_got_refcounts == NULL) | |
e054468f | 3926 | return NULL; |
25dbc73a | 3927 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 3928 | } |
41fcb14e | 3929 | |
e054468f AM |
3930 | local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info); |
3931 | local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
25dbc73a | 3932 | local_got_tls_masks[r_symndx] |= tls_type; |
e054468f AM |
3933 | if (tls_type != PLT_IFUNC) |
3934 | local_got_refcounts[r_symndx] += 1; | |
3935 | return local_plt + r_symndx; | |
25dbc73a | 3936 | } |
41fcb14e | 3937 | |
a6aa5195 | 3938 | static bfd_boolean |
3ec01793 | 3939 | update_plt_info (bfd *abfd, struct plt_entry **plist, |
a6aa5195 AM |
3940 | asection *sec, bfd_vma addend) |
3941 | { | |
3942 | struct plt_entry *ent; | |
3943 | ||
32af9f6e AM |
3944 | if (addend < 32768) |
3945 | sec = NULL; | |
3ec01793 | 3946 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3947 | if (ent->sec == sec && ent->addend == addend) |
3948 | break; | |
3949 | if (ent == NULL) | |
3950 | { | |
3951 | bfd_size_type amt = sizeof (*ent); | |
3952 | ent = bfd_alloc (abfd, amt); | |
3953 | if (ent == NULL) | |
3954 | return FALSE; | |
3ec01793 | 3955 | ent->next = *plist; |
a6aa5195 AM |
3956 | ent->sec = sec; |
3957 | ent->addend = addend; | |
3958 | ent->plt.refcount = 0; | |
3ec01793 | 3959 | *plist = ent; |
a6aa5195 AM |
3960 | } |
3961 | ent->plt.refcount += 1; | |
3962 | return TRUE; | |
3963 | } | |
3964 | ||
3965 | static struct plt_entry * | |
3ec01793 | 3966 | find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend) |
a6aa5195 AM |
3967 | { |
3968 | struct plt_entry *ent; | |
3969 | ||
3970 | if (addend < 32768) | |
3971 | sec = NULL; | |
3ec01793 | 3972 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3973 | if (ent->sec == sec && ent->addend == addend) |
3974 | break; | |
3975 | return ent; | |
3976 | } | |
3977 | ||
e054468f AM |
3978 | static bfd_boolean |
3979 | is_branch_reloc (enum elf_ppc_reloc_type r_type) | |
3980 | { | |
3981 | return (r_type == R_PPC_PLTREL24 | |
3982 | || r_type == R_PPC_LOCAL24PC | |
3983 | || r_type == R_PPC_REL24 | |
3984 | || r_type == R_PPC_REL14 | |
3985 | || r_type == R_PPC_REL14_BRTAKEN | |
3986 | || r_type == R_PPC_REL14_BRNTAKEN | |
3987 | || r_type == R_PPC_ADDR24 | |
3988 | || r_type == R_PPC_ADDR14 | |
3989 | || r_type == R_PPC_ADDR14_BRTAKEN | |
dfdaec14 AJ |
3990 | || r_type == R_PPC_ADDR14_BRNTAKEN |
3991 | || r_type == R_PPC_VLE_REL24); | |
e054468f AM |
3992 | } |
3993 | ||
25dbc73a AM |
3994 | static void |
3995 | bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type) | |
3996 | { | |
4eca0228 | 3997 | _bfd_error_handler |
695344c0 | 3998 | /* xgettext:c-format */ |
25dbc73a AM |
3999 | (_("%B: relocation %s cannot be used when making a shared object"), |
4000 | abfd, | |
4001 | ppc_elf_howto_table[r_type]->name); | |
4002 | bfd_set_error (bfd_error_bad_value); | |
252b5132 RH |
4003 | } |
4004 | ||
25dbc73a AM |
4005 | /* Look through the relocs for a section during the first phase, and |
4006 | allocate space in the global offset table or procedure linkage | |
4007 | table. */ | |
252b5132 | 4008 | |
b34976b6 | 4009 | static bfd_boolean |
25dbc73a AM |
4010 | ppc_elf_check_relocs (bfd *abfd, |
4011 | struct bfd_link_info *info, | |
4012 | asection *sec, | |
4013 | const Elf_Internal_Rela *relocs) | |
252b5132 | 4014 | { |
7619e7c7 | 4015 | struct ppc_elf_link_hash_table *htab; |
25dbc73a AM |
4016 | Elf_Internal_Shdr *symtab_hdr; |
4017 | struct elf_link_hash_entry **sym_hashes; | |
4018 | const Elf_Internal_Rela *rel; | |
4019 | const Elf_Internal_Rela *rel_end; | |
a6aa5195 | 4020 | asection *got2, *sreloc; |
727fc41e | 4021 | struct elf_link_hash_entry *tga; |
25dbc73a | 4022 | |
0e1862bb | 4023 | if (bfd_link_relocatable (info)) |
25dbc73a | 4024 | return TRUE; |
252b5132 | 4025 | |
c87b5a93 AM |
4026 | /* Don't do anything special with non-loaded, non-alloced sections. |
4027 | In particular, any relocs in such sections should not affect GOT | |
4028 | and PLT reference counting (ie. we don't allow them to create GOT | |
4029 | or PLT entries), there's no possibility or desire to optimize TLS | |
4030 | relocs, and there's not much point in propagating relocs to shared | |
4031 | libs that the dynamic linker won't relocate. */ | |
4032 | if ((sec->flags & SEC_ALLOC) == 0) | |
4033 | return TRUE; | |
4034 | ||
252b5132 | 4035 | #ifdef DEBUG |
25dbc73a AM |
4036 | _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B", |
4037 | sec, abfd); | |
252b5132 RH |
4038 | #endif |
4039 | ||
0c8d6e5c | 4040 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 4041 | |
25dbc73a AM |
4042 | /* Initialize howto table if not already done. */ |
4043 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
4044 | ppc_elf_howto_init (); | |
4045 | ||
7619e7c7 | 4046 | htab = ppc_elf_hash_table (info); |
25f23106 AM |
4047 | if (htab->glink == NULL) |
4048 | { | |
4049 | if (htab->elf.dynobj == NULL) | |
4050 | htab->elf.dynobj = abfd; | |
4051 | if (!ppc_elf_create_glink (htab->elf.dynobj, info)) | |
4052 | return FALSE; | |
4053 | } | |
727fc41e AM |
4054 | tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
4055 | FALSE, FALSE, TRUE); | |
0ffa91dd | 4056 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a | 4057 | sym_hashes = elf_sym_hashes (abfd); |
a6aa5195 | 4058 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
4059 | sreloc = NULL; |
4060 | ||
4061 | rel_end = relocs + sec->reloc_count; | |
4062 | for (rel = relocs; rel < rel_end; rel++) | |
4063 | { | |
4064 | unsigned long r_symndx; | |
4065 | enum elf_ppc_reloc_type r_type; | |
4066 | struct elf_link_hash_entry *h; | |
727fc41e | 4067 | int tls_type; |
cbf95972 | 4068 | struct plt_entry **ifunc; |
25dbc73a AM |
4069 | |
4070 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4071 | if (r_symndx < symtab_hdr->sh_info) | |
4072 | h = NULL; | |
4073 | else | |
973a3492 L |
4074 | { |
4075 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4076 | while (h->root.type == bfd_link_hash_indirect | |
4077 | || h->root.type == bfd_link_hash_warning) | |
4078 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
81fbe831 AM |
4079 | |
4080 | /* PR15323, ref flags aren't set for references in the same | |
4081 | object. */ | |
bc4e12de | 4082 | h->root.non_ir_ref_regular = 1; |
973a3492 | 4083 | } |
25dbc73a AM |
4084 | |
4085 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. | |
4086 | This shows up in particular in an R_PPC_ADDR32 in the eabi | |
4087 | startup code. */ | |
3b36f7e6 | 4088 | if (h != NULL |
ce558b89 | 4089 | && htab->elf.sgot == NULL |
3b36f7e6 | 4090 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
252b5132 | 4091 | { |
3b36f7e6 AM |
4092 | if (htab->elf.dynobj == NULL) |
4093 | htab->elf.dynobj = abfd; | |
4094 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
4095 | return FALSE; | |
4096 | BFD_ASSERT (h == htab->elf.hgot); | |
25dbc73a | 4097 | } |
252b5132 | 4098 | |
727fc41e | 4099 | tls_type = 0; |
de972ffa | 4100 | r_type = ELF32_R_TYPE (rel->r_info); |
cbf95972 | 4101 | ifunc = NULL; |
06a162cf | 4102 | if (h == NULL && !htab->is_vxworks) |
e054468f | 4103 | { |
06a162cf AM |
4104 | Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
4105 | abfd, r_symndx); | |
4106 | if (isym == NULL) | |
4107 | return FALSE; | |
4108 | ||
0bed072f | 4109 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
e054468f | 4110 | { |
0bed072f | 4111 | /* Set PLT_IFUNC flag for this sym, no GOT entry yet. */ |
06a162cf AM |
4112 | ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx, |
4113 | PLT_IFUNC); | |
4114 | if (ifunc == NULL) | |
e054468f AM |
4115 | return FALSE; |
4116 | ||
06a162cf AM |
4117 | /* STT_GNU_IFUNC symbols must have a PLT entry; |
4118 | In a non-pie executable even when there are | |
4119 | no plt calls. */ | |
0e1862bb | 4120 | if (!bfd_link_pic (info) |
0bed072f | 4121 | || is_branch_reloc (r_type)) |
e054468f | 4122 | { |
0bed072f AM |
4123 | bfd_vma addend = 0; |
4124 | if (r_type == R_PPC_PLTREL24) | |
4125 | { | |
4126 | ppc_elf_tdata (abfd)->makes_plt_call = 1; | |
0e1862bb | 4127 | if (bfd_link_pic (info)) |
0bed072f AM |
4128 | addend = rel->r_addend; |
4129 | } | |
4130 | if (!update_plt_info (abfd, ifunc, got2, addend)) | |
4131 | return FALSE; | |
e054468f AM |
4132 | } |
4133 | } | |
25f23106 AM |
4134 | } |
4135 | ||
de972ffa AM |
4136 | if (!htab->is_vxworks |
4137 | && is_branch_reloc (r_type) | |
4138 | && h != NULL | |
4139 | && h == tga) | |
25f23106 | 4140 | { |
de972ffa AM |
4141 | if (rel != relocs |
4142 | && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD | |
4143 | || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD)) | |
4144 | /* We have a new-style __tls_get_addr call with a marker | |
4145 | reloc. */ | |
4146 | ; | |
4147 | else | |
4148 | /* Mark this section as having an old-style call. */ | |
4149 | sec->has_tls_get_addr_call = 1; | |
e054468f | 4150 | } |
727fc41e | 4151 | |
25dbc73a AM |
4152 | switch (r_type) |
4153 | { | |
727fc41e AM |
4154 | case R_PPC_TLSGD: |
4155 | case R_PPC_TLSLD: | |
4156 | /* These special tls relocs tie a call to __tls_get_addr with | |
4157 | its parameter symbol. */ | |
4158 | break; | |
4159 | ||
25dbc73a AM |
4160 | case R_PPC_GOT_TLSLD16: |
4161 | case R_PPC_GOT_TLSLD16_LO: | |
4162 | case R_PPC_GOT_TLSLD16_HI: | |
4163 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
4164 | tls_type = TLS_TLS | TLS_LD; |
4165 | goto dogottls; | |
252b5132 | 4166 | |
25dbc73a AM |
4167 | case R_PPC_GOT_TLSGD16: |
4168 | case R_PPC_GOT_TLSGD16_LO: | |
4169 | case R_PPC_GOT_TLSGD16_HI: | |
4170 | case R_PPC_GOT_TLSGD16_HA: | |
4171 | tls_type = TLS_TLS | TLS_GD; | |
4172 | goto dogottls; | |
4173 | ||
4174 | case R_PPC_GOT_TPREL16: | |
4175 | case R_PPC_GOT_TPREL16_LO: | |
4176 | case R_PPC_GOT_TPREL16_HI: | |
4177 | case R_PPC_GOT_TPREL16_HA: | |
7c8bbca5 | 4178 | if (bfd_link_dll (info)) |
25dbc73a AM |
4179 | info->flags |= DF_STATIC_TLS; |
4180 | tls_type = TLS_TLS | TLS_TPREL; | |
4181 | goto dogottls; | |
4182 | ||
4183 | case R_PPC_GOT_DTPREL16: | |
4184 | case R_PPC_GOT_DTPREL16_LO: | |
4185 | case R_PPC_GOT_DTPREL16_HI: | |
4186 | case R_PPC_GOT_DTPREL16_HA: | |
4187 | tls_type = TLS_TLS | TLS_DTPREL; | |
4188 | dogottls: | |
4189 | sec->has_tls_reloc = 1; | |
1a0670f3 | 4190 | /* Fall through. */ |
252b5132 | 4191 | |
25dbc73a AM |
4192 | /* GOT16 relocations */ |
4193 | case R_PPC_GOT16: | |
4194 | case R_PPC_GOT16_LO: | |
4195 | case R_PPC_GOT16_HI: | |
4196 | case R_PPC_GOT16_HA: | |
4197 | /* This symbol requires a global offset table entry. */ | |
ce558b89 | 4198 | if (htab->elf.sgot == NULL) |
25dbc73a AM |
4199 | { |
4200 | if (htab->elf.dynobj == NULL) | |
4201 | htab->elf.dynobj = abfd; | |
4202 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
4203 | return FALSE; | |
4204 | } | |
4205 | if (h != NULL) | |
4206 | { | |
4207 | h->got.refcount += 1; | |
4208 | ppc_elf_hash_entry (h)->tls_mask |= tls_type; | |
4209 | } | |
4210 | else | |
4211 | /* This is a global offset table entry for a local symbol. */ | |
4212 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)) | |
4213 | return FALSE; | |
91e21fb7 AM |
4214 | |
4215 | /* We may also need a plt entry if the symbol turns out to be | |
4216 | an ifunc. */ | |
0e1862bb | 4217 | if (h != NULL && !bfd_link_pic (info)) |
91e21fb7 AM |
4218 | { |
4219 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) | |
4220 | return FALSE; | |
4221 | } | |
25dbc73a | 4222 | break; |
252b5132 | 4223 | |
25dbc73a AM |
4224 | /* Indirect .sdata relocation. */ |
4225 | case R_PPC_EMB_SDAI16: | |
0e1862bb | 4226 | if (bfd_link_pic (info)) |
25dbc73a AM |
4227 | { |
4228 | bad_shared_reloc (abfd, r_type); | |
4229 | return FALSE; | |
4230 | } | |
93d1b056 AM |
4231 | htab->sdata[0].sym->ref_regular = 1; |
4232 | if (!elf_allocate_pointer_linker_section (abfd, &htab->sdata[0], | |
4233 | h, rel)) | |
25dbc73a | 4234 | return FALSE; |
046183de AM |
4235 | if (h != NULL) |
4236 | { | |
4237 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
4238 | h->non_got_ref = TRUE; | |
4239 | } | |
25dbc73a | 4240 | break; |
252b5132 | 4241 | |
25dbc73a AM |
4242 | /* Indirect .sdata2 relocation. */ |
4243 | case R_PPC_EMB_SDA2I16: | |
0e1862bb | 4244 | if (bfd_link_pic (info)) |
25dbc73a AM |
4245 | { |
4246 | bad_shared_reloc (abfd, r_type); | |
4247 | return FALSE; | |
4248 | } | |
93d1b056 AM |
4249 | htab->sdata[1].sym->ref_regular = 1; |
4250 | if (!elf_allocate_pointer_linker_section (abfd, &htab->sdata[1], | |
4251 | h, rel)) | |
25dbc73a | 4252 | return FALSE; |
046183de AM |
4253 | if (h != NULL) |
4254 | { | |
4255 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
4256 | h->non_got_ref = TRUE; | |
4257 | } | |
25dbc73a | 4258 | break; |
252b5132 | 4259 | |
93d1b056 AM |
4260 | case R_PPC_SDAREL16: |
4261 | htab->sdata[0].sym->ref_regular = 1; | |
1a0670f3 | 4262 | /* Fall through. */ |
93d1b056 | 4263 | |
b9c361e0 JL |
4264 | case R_PPC_VLE_SDAREL_LO16A: |
4265 | case R_PPC_VLE_SDAREL_LO16D: | |
4266 | case R_PPC_VLE_SDAREL_HI16A: | |
4267 | case R_PPC_VLE_SDAREL_HI16D: | |
4268 | case R_PPC_VLE_SDAREL_HA16A: | |
4269 | case R_PPC_VLE_SDAREL_HA16D: | |
046183de AM |
4270 | if (h != NULL) |
4271 | { | |
4272 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
4273 | h->non_got_ref = TRUE; | |
4274 | } | |
4275 | break; | |
4276 | ||
b9c361e0 JL |
4277 | case R_PPC_VLE_REL8: |
4278 | case R_PPC_VLE_REL15: | |
4279 | case R_PPC_VLE_REL24: | |
4280 | case R_PPC_VLE_LO16A: | |
4281 | case R_PPC_VLE_LO16D: | |
4282 | case R_PPC_VLE_HI16A: | |
4283 | case R_PPC_VLE_HI16D: | |
4284 | case R_PPC_VLE_HA16A: | |
4285 | case R_PPC_VLE_HA16D: | |
83eef883 | 4286 | case R_PPC_VLE_ADDR20: |
b9c361e0 JL |
4287 | break; |
4288 | ||
25dbc73a | 4289 | case R_PPC_EMB_SDA2REL: |
0e1862bb | 4290 | if (bfd_link_pic (info)) |
046183de AM |
4291 | { |
4292 | bad_shared_reloc (abfd, r_type); | |
4293 | return FALSE; | |
4294 | } | |
93d1b056 | 4295 | htab->sdata[1].sym->ref_regular = 1; |
046183de AM |
4296 | if (h != NULL) |
4297 | { | |
4298 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
4299 | h->non_got_ref = TRUE; | |
4300 | } | |
4301 | break; | |
4302 | ||
b9c361e0 JL |
4303 | case R_PPC_VLE_SDA21_LO: |
4304 | case R_PPC_VLE_SDA21: | |
25dbc73a AM |
4305 | case R_PPC_EMB_SDA21: |
4306 | case R_PPC_EMB_RELSDA: | |
0e1862bb | 4307 | if (bfd_link_pic (info)) |
046183de AM |
4308 | { |
4309 | bad_shared_reloc (abfd, r_type); | |
4310 | return FALSE; | |
4311 | } | |
046183de AM |
4312 | if (h != NULL) |
4313 | { | |
4314 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
4315 | h->non_got_ref = TRUE; | |
4316 | } | |
4317 | break; | |
4318 | ||
25dbc73a AM |
4319 | case R_PPC_EMB_NADDR32: |
4320 | case R_PPC_EMB_NADDR16: | |
4321 | case R_PPC_EMB_NADDR16_LO: | |
4322 | case R_PPC_EMB_NADDR16_HI: | |
4323 | case R_PPC_EMB_NADDR16_HA: | |
0e1862bb | 4324 | if (bfd_link_pic (info)) |
25dbc73a AM |
4325 | { |
4326 | bad_shared_reloc (abfd, r_type); | |
4327 | return FALSE; | |
4328 | } | |
4dc4a9a5 | 4329 | if (h != NULL) |
046183de | 4330 | h->non_got_ref = TRUE; |
25dbc73a | 4331 | break; |
252b5132 | 4332 | |
25dbc73a | 4333 | case R_PPC_PLTREL24: |
de972ffa | 4334 | if (h == NULL) |
6d78d0b9 AM |
4335 | break; |
4336 | /* Fall through */ | |
4337 | case R_PPC_PLT32: | |
25dbc73a AM |
4338 | case R_PPC_PLTREL32: |
4339 | case R_PPC_PLT16_LO: | |
4340 | case R_PPC_PLT16_HI: | |
4341 | case R_PPC_PLT16_HA: | |
4342 | #ifdef DEBUG | |
4343 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
4344 | #endif | |
cbf95972 | 4345 | /* This symbol requires a procedure linkage table entry. */ |
25dbc73a AM |
4346 | if (h == NULL) |
4347 | { | |
cbf95972 AM |
4348 | if (ifunc == NULL) |
4349 | { | |
4350 | /* It does not make sense to have a procedure linkage | |
4351 | table entry for a non-ifunc local symbol. */ | |
4352 | info->callbacks->einfo | |
695344c0 | 4353 | /* xgettext:c-format */ |
174d0a74 | 4354 | (_("%H: %s reloc against local symbol\n"), |
cbf95972 AM |
4355 | abfd, sec, rel->r_offset, |
4356 | ppc_elf_howto_table[r_type]->name); | |
4357 | bfd_set_error (bfd_error_bad_value); | |
4358 | return FALSE; | |
4359 | } | |
25dbc73a | 4360 | } |
a6aa5195 AM |
4361 | else |
4362 | { | |
016687f8 | 4363 | bfd_vma addend = 0; |
ee05f2fe | 4364 | |
016687f8 AM |
4365 | if (r_type == R_PPC_PLTREL24) |
4366 | { | |
4367 | ppc_elf_tdata (abfd)->makes_plt_call = 1; | |
0e1862bb | 4368 | if (bfd_link_pic (info)) |
a877a2b6 | 4369 | addend = rel->r_addend; |
016687f8 | 4370 | } |
a6aa5195 | 4371 | h->needs_plt = 1; |
32af9f6e | 4372 | if (!update_plt_info (abfd, &h->plt.plist, got2, addend)) |
a6aa5195 AM |
4373 | return FALSE; |
4374 | } | |
25dbc73a | 4375 | break; |
ee05f2fe | 4376 | |
25dbc73a AM |
4377 | /* The following relocations don't need to propagate the |
4378 | relocation if linking a shared object since they are | |
4379 | section relative. */ | |
4380 | case R_PPC_SECTOFF: | |
4381 | case R_PPC_SECTOFF_LO: | |
4382 | case R_PPC_SECTOFF_HI: | |
4383 | case R_PPC_SECTOFF_HA: | |
4384 | case R_PPC_DTPREL16: | |
4385 | case R_PPC_DTPREL16_LO: | |
4386 | case R_PPC_DTPREL16_HI: | |
4387 | case R_PPC_DTPREL16_HA: | |
4388 | case R_PPC_TOC16: | |
4389 | break; | |
252b5132 | 4390 | |
d7128ce4 AM |
4391 | case R_PPC_REL16: |
4392 | case R_PPC_REL16_LO: | |
4393 | case R_PPC_REL16_HI: | |
4394 | case R_PPC_REL16_HA: | |
a680de9a | 4395 | case R_PPC_REL16DX_HA: |
016687f8 | 4396 | ppc_elf_tdata (abfd)->has_rel16 = 1; |
d7128ce4 AM |
4397 | break; |
4398 | ||
a6aa5195 | 4399 | /* These are just markers. */ |
25dbc73a AM |
4400 | case R_PPC_TLS: |
4401 | case R_PPC_EMB_MRKREF: | |
4402 | case R_PPC_NONE: | |
4403 | case R_PPC_max: | |
32af9f6e AM |
4404 | case R_PPC_RELAX: |
4405 | case R_PPC_RELAX_PLT: | |
4406 | case R_PPC_RELAX_PLTREL24: | |
7ba71655 | 4407 | case R_PPC_16DX_HA: |
25dbc73a | 4408 | break; |
252b5132 | 4409 | |
25dbc73a AM |
4410 | /* These should only appear in dynamic objects. */ |
4411 | case R_PPC_COPY: | |
4412 | case R_PPC_GLOB_DAT: | |
4413 | case R_PPC_JMP_SLOT: | |
4414 | case R_PPC_RELATIVE: | |
e054468f | 4415 | case R_PPC_IRELATIVE: |
25dbc73a | 4416 | break; |
252b5132 | 4417 | |
25dbc73a AM |
4418 | /* These aren't handled yet. We'll report an error later. */ |
4419 | case R_PPC_ADDR30: | |
4420 | case R_PPC_EMB_RELSEC16: | |
4421 | case R_PPC_EMB_RELST_LO: | |
4422 | case R_PPC_EMB_RELST_HI: | |
4423 | case R_PPC_EMB_RELST_HA: | |
4424 | case R_PPC_EMB_BIT_FLD: | |
4425 | break; | |
252b5132 | 4426 | |
25dbc73a AM |
4427 | /* This refers only to functions defined in the shared library. */ |
4428 | case R_PPC_LOCAL24PC: | |
727fc41e | 4429 | if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET) |
016687f8 AM |
4430 | { |
4431 | htab->plt_type = PLT_OLD; | |
4432 | htab->old_bfd = abfd; | |
4433 | } | |
c7e17e05 AM |
4434 | if (h != NULL && h->type == STT_GNU_IFUNC) |
4435 | { | |
c7e17e05 AM |
4436 | h->needs_plt = 1; |
4437 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) | |
4438 | return FALSE; | |
4439 | } | |
25dbc73a | 4440 | break; |
252b5132 | 4441 | |
25dbc73a AM |
4442 | /* This relocation describes the C++ object vtable hierarchy. |
4443 | Reconstruct it for later use during GC. */ | |
4444 | case R_PPC_GNU_VTINHERIT: | |
4445 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
4446 | return FALSE; | |
4447 | break; | |
252b5132 | 4448 | |
25dbc73a AM |
4449 | /* This relocation describes which C++ vtable entries are actually |
4450 | used. Record for later use during GC. */ | |
4451 | case R_PPC_GNU_VTENTRY: | |
d17e0c6e JB |
4452 | BFD_ASSERT (h != NULL); |
4453 | if (h != NULL | |
4454 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
25dbc73a AM |
4455 | return FALSE; |
4456 | break; | |
252b5132 | 4457 | |
7c8bbca5 | 4458 | /* We shouldn't really be seeing TPREL32. */ |
25dbc73a | 4459 | case R_PPC_TPREL32: |
1d483afe AM |
4460 | case R_PPC_TPREL16: |
4461 | case R_PPC_TPREL16_LO: | |
4462 | case R_PPC_TPREL16_HI: | |
4463 | case R_PPC_TPREL16_HA: | |
7c8bbca5 | 4464 | if (bfd_link_dll (info)) |
25dbc73a AM |
4465 | info->flags |= DF_STATIC_TLS; |
4466 | goto dodyn; | |
252b5132 | 4467 | |
25dbc73a AM |
4468 | /* Nor these. */ |
4469 | case R_PPC_DTPMOD32: | |
4470 | case R_PPC_DTPREL32: | |
4471 | goto dodyn; | |
252b5132 | 4472 | |
9edfd1af AM |
4473 | case R_PPC_REL32: |
4474 | if (h == NULL | |
4475 | && got2 != NULL | |
4476 | && (sec->flags & SEC_CODE) != 0 | |
0e1862bb | 4477 | && bfd_link_pic (info) |
4a3dc543 | 4478 | && htab->plt_type == PLT_UNSET) |
9edfd1af AM |
4479 | { |
4480 | /* Old -fPIC gcc code has .long LCTOC1-LCFx just before | |
4481 | the start of a function, which assembles to a REL32 | |
4482 | reference to .got2. If we detect one of these, then | |
4483 | force the old PLT layout because the linker cannot | |
4484 | reliably deduce the GOT pointer value needed for | |
4485 | PLT call stubs. */ | |
4486 | asection *s; | |
87d72d41 | 4487 | Elf_Internal_Sym *isym; |
9edfd1af | 4488 | |
87d72d41 AM |
4489 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
4490 | abfd, r_symndx); | |
4491 | if (isym == NULL) | |
4492 | return FALSE; | |
4493 | ||
4494 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
9edfd1af | 4495 | if (s == got2) |
016687f8 AM |
4496 | { |
4497 | htab->plt_type = PLT_OLD; | |
4498 | htab->old_bfd = abfd; | |
4499 | } | |
9edfd1af | 4500 | } |
7123df0e | 4501 | if (h == NULL || h == htab->elf.hgot) |
fd38b44c | 4502 | break; |
625af618 AM |
4503 | /* fall through */ |
4504 | ||
4505 | case R_PPC_ADDR32: | |
4506 | case R_PPC_ADDR16: | |
4507 | case R_PPC_ADDR16_LO: | |
4508 | case R_PPC_ADDR16_HI: | |
4509 | case R_PPC_ADDR16_HA: | |
4510 | case R_PPC_UADDR32: | |
4511 | case R_PPC_UADDR16: | |
0e1862bb | 4512 | if (h != NULL && !bfd_link_pic (info)) |
625af618 AM |
4513 | { |
4514 | /* We may need a plt entry if the symbol turns out to be | |
4515 | a function defined in a dynamic object. */ | |
3ec01793 | 4516 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
625af618 AM |
4517 | return FALSE; |
4518 | ||
4519 | /* We may need a copy reloc too. */ | |
4520 | h->non_got_ref = 1; | |
4521 | h->pointer_equality_needed = 1; | |
d3e454b9 AM |
4522 | if (r_type == R_PPC_ADDR16_HA) |
4523 | ppc_elf_hash_entry (h)->has_addr16_ha = 1; | |
4524 | if (r_type == R_PPC_ADDR16_LO) | |
4525 | ppc_elf_hash_entry (h)->has_addr16_lo = 1; | |
625af618 AM |
4526 | } |
4527 | goto dodyn; | |
9edfd1af | 4528 | |
25dbc73a AM |
4529 | case R_PPC_REL24: |
4530 | case R_PPC_REL14: | |
4531 | case R_PPC_REL14_BRTAKEN: | |
4532 | case R_PPC_REL14_BRNTAKEN: | |
d7128ce4 | 4533 | if (h == NULL) |
25dbc73a | 4534 | break; |
7123df0e | 4535 | if (h == htab->elf.hgot) |
d7128ce4 | 4536 | { |
7123df0e | 4537 | if (htab->plt_type == PLT_UNSET) |
016687f8 AM |
4538 | { |
4539 | htab->plt_type = PLT_OLD; | |
4540 | htab->old_bfd = abfd; | |
4541 | } | |
d7128ce4 AM |
4542 | break; |
4543 | } | |
25dbc73a | 4544 | /* fall through */ |
ee05f2fe | 4545 | |
25dbc73a | 4546 | case R_PPC_ADDR24: |
25dbc73a AM |
4547 | case R_PPC_ADDR14: |
4548 | case R_PPC_ADDR14_BRTAKEN: | |
4549 | case R_PPC_ADDR14_BRNTAKEN: | |
0e1862bb | 4550 | if (h != NULL && !bfd_link_pic (info)) |
25dbc73a AM |
4551 | { |
4552 | /* We may need a plt entry if the symbol turns out to be | |
4553 | a function defined in a dynamic object. */ | |
e054468f | 4554 | h->needs_plt = 1; |
de972ffa | 4555 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
a6aa5195 | 4556 | return FALSE; |
625af618 | 4557 | break; |
25dbc73a | 4558 | } |
7619e7c7 | 4559 | |
25dbc73a AM |
4560 | dodyn: |
4561 | /* If we are creating a shared library, and this is a reloc | |
4562 | against a global symbol, or a non PC relative reloc | |
4563 | against a local symbol, then we need to copy the reloc | |
4564 | into the shared library. However, if we are linking with | |
4565 | -Bsymbolic, we do not need to copy a reloc against a | |
4566 | global symbol which is defined in an object we are | |
4567 | including in the link (i.e., DEF_REGULAR is set). At | |
4568 | this point we have not seen all the input files, so it is | |
4569 | possible that DEF_REGULAR is not set now but will be set | |
4570 | later (it is never cleared). In case of a weak definition, | |
4571 | DEF_REGULAR may be cleared later by a strong definition in | |
4572 | a shared library. We account for that possibility below by | |
4573 | storing information in the dyn_relocs field of the hash | |
4574 | table entry. A similar situation occurs when creating | |
4575 | shared libraries and symbol visibility changes render the | |
4576 | symbol local. | |
7619e7c7 | 4577 | |
25dbc73a AM |
4578 | If on the other hand, we are creating an executable, we |
4579 | may need to keep relocations for symbols satisfied by a | |
4580 | dynamic library if we manage to avoid copy relocs for the | |
4581 | symbol. */ | |
0e1862bb | 4582 | if ((bfd_link_pic (info) |
1d483afe | 4583 | && (must_be_dyn_reloc (info, r_type) |
25dbc73a | 4584 | || (h != NULL |
198f1157 | 4585 | && (!SYMBOLIC_BIND (info, h) |
25dbc73a AM |
4586 | || h->root.type == bfd_link_hash_defweak |
4587 | || !h->def_regular)))) | |
4588 | || (ELIMINATE_COPY_RELOCS | |
0e1862bb | 4589 | && !bfd_link_pic (info) |
25dbc73a AM |
4590 | && h != NULL |
4591 | && (h->root.type == bfd_link_hash_defweak | |
de972ffa | 4592 | || !h->def_regular))) |
25dbc73a | 4593 | { |
25dbc73a AM |
4594 | #ifdef DEBUG |
4595 | fprintf (stderr, | |
4596 | "ppc_elf_check_relocs needs to " | |
4597 | "create relocation for %s\n", | |
4598 | (h && h->root.root.string | |
4599 | ? h->root.root.string : "<unknown>")); | |
4600 | #endif | |
4601 | if (sreloc == NULL) | |
4602 | { | |
c9a2f333 AM |
4603 | if (htab->elf.dynobj == NULL) |
4604 | htab->elf.dynobj = abfd; | |
83bac4b0 NC |
4605 | |
4606 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
4607 | (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE); | |
4608 | ||
25dbc73a | 4609 | if (sreloc == NULL) |
83bac4b0 | 4610 | return FALSE; |
25dbc73a | 4611 | } |
7619e7c7 | 4612 | |
25dbc73a AM |
4613 | /* If this is a global symbol, we count the number of |
4614 | relocations we need for this symbol. */ | |
4615 | if (h != NULL) | |
4616 | { | |
f95f8542 AM |
4617 | struct elf_dyn_relocs *p; |
4618 | struct elf_dyn_relocs **rel_head; | |
4619 | ||
91d6fa6a | 4620 | rel_head = &ppc_elf_hash_entry (h)->dyn_relocs; |
f95f8542 AM |
4621 | p = *rel_head; |
4622 | if (p == NULL || p->sec != sec) | |
4623 | { | |
4624 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); | |
4625 | if (p == NULL) | |
4626 | return FALSE; | |
4627 | p->next = *rel_head; | |
4628 | *rel_head = p; | |
4629 | p->sec = sec; | |
4630 | p->count = 0; | |
4631 | p->pc_count = 0; | |
4632 | } | |
4633 | p->count += 1; | |
4634 | if (!must_be_dyn_reloc (info, r_type)) | |
4635 | p->pc_count += 1; | |
25dbc73a AM |
4636 | } |
4637 | else | |
4638 | { | |
4639 | /* Track dynamic relocs needed for local syms too. | |
4640 | We really need local syms available to do this | |
4641 | easily. Oh well. */ | |
f95f8542 AM |
4642 | struct ppc_dyn_relocs *p; |
4643 | struct ppc_dyn_relocs **rel_head; | |
4644 | bfd_boolean is_ifunc; | |
25dbc73a | 4645 | asection *s; |
6edfbbad | 4646 | void *vpp; |
87d72d41 | 4647 | Elf_Internal_Sym *isym; |
6edfbbad | 4648 | |
87d72d41 AM |
4649 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
4650 | abfd, r_symndx); | |
4651 | if (isym == NULL) | |
25dbc73a | 4652 | return FALSE; |
7fce784e | 4653 | |
87d72d41 AM |
4654 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
4655 | if (s == NULL) | |
4656 | s = sec; | |
4657 | ||
6edfbbad | 4658 | vpp = &elf_section_data (s)->local_dynrel; |
f95f8542 AM |
4659 | rel_head = (struct ppc_dyn_relocs **) vpp; |
4660 | is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC; | |
4661 | p = *rel_head; | |
4662 | if (p != NULL && p->sec == sec && p->ifunc != is_ifunc) | |
4663 | p = p->next; | |
4664 | if (p == NULL || p->sec != sec || p->ifunc != is_ifunc) | |
4665 | { | |
4666 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); | |
4667 | if (p == NULL) | |
4668 | return FALSE; | |
4669 | p->next = *rel_head; | |
4670 | *rel_head = p; | |
4671 | p->sec = sec; | |
4672 | p->ifunc = is_ifunc; | |
4673 | p->count = 0; | |
4674 | } | |
4675 | p->count += 1; | |
25dbc73a | 4676 | } |
7619e7c7 | 4677 | } |
25dbc73a AM |
4678 | |
4679 | break; | |
7619e7c7 AM |
4680 | } |
4681 | } | |
ee05f2fe | 4682 | |
25dbc73a AM |
4683 | return TRUE; |
4684 | } | |
4685 | \f | |
005d79fd AM |
4686 | /* Warn for conflicting Tag_GNU_Power_ABI_FP attributes between IBFD |
4687 | and OBFD, and merge non-conflicting ones. */ | |
4688 | void | |
50e03d47 | 4689 | _bfd_elf_ppc_merge_fp_attributes (bfd *ibfd, struct bfd_link_info *info) |
34c8bcba | 4690 | { |
50e03d47 | 4691 | bfd *obfd = info->output_bfd; |
c6e65352 DJ |
4692 | obj_attribute *in_attr, *in_attrs; |
4693 | obj_attribute *out_attr, *out_attrs; | |
34c8bcba | 4694 | |
c6e65352 DJ |
4695 | in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU]; |
4696 | out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU]; | |
4697 | ||
c6e65352 DJ |
4698 | in_attr = &in_attrs[Tag_GNU_Power_ABI_FP]; |
4699 | out_attr = &out_attrs[Tag_GNU_Power_ABI_FP]; | |
005d79fd | 4700 | |
c6e65352 | 4701 | if (in_attr->i != out_attr->i) |
34c8bcba | 4702 | { |
005d79fd AM |
4703 | int in_fp = in_attr->i & 3; |
4704 | int out_fp = out_attr->i & 3; | |
4705 | ||
4706 | if (in_fp == 0) | |
34c8bcba | 4707 | ; |
005d79fd AM |
4708 | else if (out_fp == 0) |
4709 | { | |
4710 | out_attr->type = 1; | |
4711 | out_attr->i ^= in_fp; | |
4712 | } | |
4713 | else if (out_fp != 2 && in_fp == 2) | |
34c8bcba | 4714 | _bfd_error_handler |
695344c0 | 4715 | /* xgettext:c-format */ |
34c8bcba | 4716 | (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd); |
005d79fd AM |
4717 | else if (out_fp == 2 && in_fp != 2) |
4718 | _bfd_error_handler | |
695344c0 | 4719 | /* xgettext:c-format */ |
005d79fd AM |
4720 | (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd); |
4721 | else if (out_fp == 1 && in_fp == 3) | |
3c7b9897 | 4722 | _bfd_error_handler |
695344c0 | 4723 | /* xgettext:c-format */ |
005d79fd AM |
4724 | (_("Warning: %B uses double-precision hard float, " |
4725 | "%B uses single-precision hard float"), obfd, ibfd); | |
4726 | else if (out_fp == 3 && in_fp == 1) | |
3c7b9897 | 4727 | _bfd_error_handler |
695344c0 | 4728 | /* xgettext:c-format */ |
005d79fd AM |
4729 | (_("Warning: %B uses double-precision hard float, " |
4730 | "%B uses single-precision hard float"), ibfd, obfd); | |
4731 | ||
4732 | in_fp = in_attr->i & 0xc; | |
4733 | out_fp = out_attr->i & 0xc; | |
4734 | if (in_fp == 0) | |
4735 | ; | |
4736 | else if (out_fp == 0) | |
4737 | { | |
4738 | out_attr->type = 1; | |
4739 | out_attr->i ^= in_fp; | |
4740 | } | |
4741 | else if (out_fp != 2 * 4 && in_fp == 2 * 4) | |
3c7b9897 | 4742 | _bfd_error_handler |
695344c0 | 4743 | /* xgettext:c-format */ |
005d79fd AM |
4744 | (_("Warning: %B uses 64-bit long double, " |
4745 | "%B uses 128-bit long double"), ibfd, obfd); | |
4746 | else if (in_fp != 2 * 4 && out_fp == 2 * 4) | |
34c8bcba | 4747 | _bfd_error_handler |
695344c0 | 4748 | /* xgettext:c-format */ |
005d79fd AM |
4749 | (_("Warning: %B uses 64-bit long double, " |
4750 | "%B uses 128-bit long double"), obfd, ibfd); | |
4751 | else if (out_fp == 1 * 4 && in_fp == 3 * 4) | |
34c8bcba | 4752 | _bfd_error_handler |
695344c0 | 4753 | /* xgettext:c-format */ |
005d79fd AM |
4754 | (_("Warning: %B uses IBM long double, " |
4755 | "%B uses IEEE long double"), ibfd, obfd); | |
4756 | else if (out_fp == 3 * 4 && in_fp == 1 * 4) | |
34c8bcba | 4757 | _bfd_error_handler |
695344c0 | 4758 | /* xgettext:c-format */ |
005d79fd AM |
4759 | (_("Warning: %B uses IBM long double, " |
4760 | "%B uses IEEE long double"), obfd, ibfd); | |
c6e65352 | 4761 | } |
005d79fd AM |
4762 | } |
4763 | ||
4764 | /* Merge object attributes from IBFD into OBFD. Warn if | |
4765 | there are conflicting attributes. */ | |
4766 | static bfd_boolean | |
50e03d47 | 4767 | ppc_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info) |
005d79fd | 4768 | { |
50e03d47 | 4769 | bfd *obfd; |
005d79fd AM |
4770 | obj_attribute *in_attr, *in_attrs; |
4771 | obj_attribute *out_attr, *out_attrs; | |
4772 | ||
50e03d47 | 4773 | _bfd_elf_ppc_merge_fp_attributes (ibfd, info); |
005d79fd | 4774 | |
50e03d47 | 4775 | obfd = info->output_bfd; |
005d79fd AM |
4776 | in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU]; |
4777 | out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU]; | |
c6e65352 DJ |
4778 | |
4779 | /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and | |
4780 | merge non-conflicting ones. */ | |
4781 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector]; | |
4782 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector]; | |
4783 | if (in_attr->i != out_attr->i) | |
4784 | { | |
005d79fd AM |
4785 | int in_vec = in_attr->i & 3; |
4786 | int out_vec = out_attr->i & 3; | |
c6e65352 | 4787 | |
005d79fd AM |
4788 | if (in_vec == 0) |
4789 | ; | |
4790 | else if (out_vec == 0) | |
c6e65352 | 4791 | { |
005d79fd AM |
4792 | out_attr->type = 1; |
4793 | out_attr->i = in_vec; | |
c6e65352 | 4794 | } |
c6e65352 DJ |
4795 | /* For now, allow generic to transition to AltiVec or SPE |
4796 | without a warning. If GCC marked files with their stack | |
4797 | alignment and used don't-care markings for files which are | |
4798 | not affected by the vector ABI, we could warn about this | |
4799 | case too. */ | |
005d79fd | 4800 | else if (in_vec == 1) |
c6e65352 | 4801 | ; |
005d79fd AM |
4802 | else if (out_vec == 1) |
4803 | { | |
4804 | out_attr->type = 1; | |
4805 | out_attr->i = in_vec; | |
4806 | } | |
4807 | else if (out_vec < in_vec) | |
c6e65352 | 4808 | _bfd_error_handler |
695344c0 | 4809 | /* xgettext:c-format */ |
005d79fd AM |
4810 | (_("Warning: %B uses AltiVec vector ABI, %B uses SPE vector ABI"), |
4811 | obfd, ibfd); | |
4812 | else if (out_vec > in_vec) | |
c6e65352 | 4813 | _bfd_error_handler |
695344c0 | 4814 | /* xgettext:c-format */ |
005d79fd AM |
4815 | (_("Warning: %B uses AltiVec vector ABI, %B uses SPE vector ABI"), |
4816 | ibfd, obfd); | |
34c8bcba JM |
4817 | } |
4818 | ||
f82e0623 NF |
4819 | /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes |
4820 | and merge non-conflicting ones. */ | |
4821 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4822 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4823 | if (in_attr->i != out_attr->i) | |
4824 | { | |
005d79fd AM |
4825 | int in_struct = in_attr->i & 3; |
4826 | int out_struct = out_attr->i & 3; | |
4827 | ||
4828 | if (in_struct == 0 || in_struct == 3) | |
f82e0623 | 4829 | ; |
005d79fd AM |
4830 | else if (out_struct == 0) |
4831 | { | |
4832 | out_attr->type = 1; | |
4833 | out_attr->i = in_struct; | |
4834 | } | |
4835 | else if (out_struct < in_struct) | |
4836 | _bfd_error_handler | |
695344c0 | 4837 | /* xgettext:c-format */ |
005d79fd AM |
4838 | (_("Warning: %B uses r3/r4 for small structure returns, " |
4839 | "%B uses memory"), obfd, ibfd); | |
4840 | else if (out_struct > in_struct) | |
4841 | _bfd_error_handler | |
695344c0 | 4842 | /* xgettext:c-format */ |
005d79fd AM |
4843 | (_("Warning: %B uses r3/r4 for small structure returns, " |
4844 | "%B uses memory"), ibfd, obfd); | |
f82e0623 NF |
4845 | } |
4846 | ||
34c8bcba | 4847 | /* Merge Tag_compatibility attributes and any common GNU ones. */ |
50e03d47 | 4848 | _bfd_elf_merge_object_attributes (ibfd, info); |
34c8bcba JM |
4849 | |
4850 | return TRUE; | |
4851 | } | |
4852 | ||
8853c3d3 AM |
4853 | /* Merge backend specific data from an object file to the output |
4854 | object file when linking. */ | |
4855 | ||
4856 | static bfd_boolean | |
50e03d47 | 4857 | ppc_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
8853c3d3 | 4858 | { |
50e03d47 | 4859 | bfd *obfd = info->output_bfd; |
8853c3d3 AM |
4860 | flagword old_flags; |
4861 | flagword new_flags; | |
4862 | bfd_boolean error; | |
4863 | ||
0c8d6e5c | 4864 | if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd)) |
8853c3d3 AM |
4865 | return TRUE; |
4866 | ||
cc643b88 | 4867 | /* Check if we have the same endianness. */ |
50e03d47 | 4868 | if (! _bfd_generic_verify_endian_match (ibfd, info)) |
8853c3d3 AM |
4869 | return FALSE; |
4870 | ||
50e03d47 | 4871 | if (!ppc_elf_merge_obj_attributes (ibfd, info)) |
34c8bcba JM |
4872 | return FALSE; |
4873 | ||
8853c3d3 AM |
4874 | new_flags = elf_elfheader (ibfd)->e_flags; |
4875 | old_flags = elf_elfheader (obfd)->e_flags; | |
4876 | if (!elf_flags_init (obfd)) | |
4877 | { | |
4878 | /* First call, no flags set. */ | |
4879 | elf_flags_init (obfd) = TRUE; | |
4880 | elf_elfheader (obfd)->e_flags = new_flags; | |
4881 | } | |
4882 | ||
4883 | /* Compatible flags are ok. */ | |
4884 | else if (new_flags == old_flags) | |
4885 | ; | |
4886 | ||
4887 | /* Incompatible flags. */ | |
4888 | else | |
4889 | { | |
4890 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib | |
4891 | to be linked with either. */ | |
4892 | error = FALSE; | |
4893 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 | |
4894 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
4895 | { | |
4896 | error = TRUE; | |
4eca0228 | 4897 | _bfd_error_handler |
8853c3d3 AM |
4898 | (_("%B: compiled with -mrelocatable and linked with " |
4899 | "modules compiled normally"), ibfd); | |
4900 | } | |
4901 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
4902 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
4903 | { | |
4904 | error = TRUE; | |
4eca0228 | 4905 | _bfd_error_handler |
8853c3d3 AM |
4906 | (_("%B: compiled normally and linked with " |
4907 | "modules compiled with -mrelocatable"), ibfd); | |
4908 | } | |
4909 | ||
4910 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
4911 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
4912 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
4913 | ||
4914 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
4915 | but each input file is either -mrelocatable or -mrelocatable-lib. */ | |
4916 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) | |
4917 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
4918 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
4919 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
4920 | ||
4921 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if | |
4922 | any module uses it. */ | |
4923 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); | |
4924 | ||
4925 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4926 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4927 | ||
4928 | /* Warn about any other mismatches. */ | |
4929 | if (new_flags != old_flags) | |
4930 | { | |
4931 | error = TRUE; | |
4eca0228 | 4932 | _bfd_error_handler |
695344c0 | 4933 | /* xgettext:c-format */ |
cd9af601 AM |
4934 | (_("%B: uses different e_flags (%#x) fields " |
4935 | "than previous modules (%#x)"), | |
4936 | ibfd, new_flags, old_flags); | |
8853c3d3 AM |
4937 | } |
4938 | ||
4939 | if (error) | |
4940 | { | |
4941 | bfd_set_error (bfd_error_bad_value); | |
4942 | return FALSE; | |
4943 | } | |
4944 | } | |
4945 | ||
4946 | return TRUE; | |
4947 | } | |
b9c361e0 JL |
4948 | |
4949 | static void | |
95f0d0d2 | 4950 | ppc_elf_vle_split16 (bfd *input_bfd, |
08dc996f AM |
4951 | asection *input_section, |
4952 | unsigned long offset, | |
95f0d0d2 | 4953 | bfd_byte *loc, |
86c95733 | 4954 | bfd_vma value, |
08dc996f AM |
4955 | split16_format_type split16_format, |
4956 | bfd_boolean fixup) | |
b9c361e0 | 4957 | { |
08dc996f | 4958 | unsigned int insn, opcode, top5; |
b9c361e0 | 4959 | |
95f0d0d2 | 4960 | insn = bfd_get_32 (input_bfd, loc); |
673cff9b | 4961 | opcode = insn & 0xfc00f800; |
08dc996f AM |
4962 | if (opcode == E_OR2I_INSN |
4963 | || opcode == E_AND2I_DOT_INSN | |
4964 | || opcode == E_OR2IS_INSN | |
4965 | || opcode == E_LIS_INSN | |
4966 | || opcode == E_AND2IS_DOT_INSN) | |
4967 | { | |
4968 | if (split16_format != split16a_type) | |
4969 | { | |
4970 | if (fixup) | |
4971 | split16_format = split16a_type; | |
4972 | else | |
4973 | _bfd_error_handler | |
4974 | /* xgettext:c-format */ | |
4975 | (_("%B(%A+0x%lx): expected 16A style relocation on 0x%08x insn"), | |
4976 | input_bfd, input_section, offset, opcode); | |
4977 | } | |
4978 | } | |
4979 | else if (opcode == E_ADD2I_DOT_INSN | |
4980 | || opcode == E_ADD2IS_INSN | |
4981 | || opcode == E_CMP16I_INSN | |
4982 | || opcode == E_MULL2I_INSN | |
4983 | || opcode == E_CMPL16I_INSN | |
4984 | || opcode == E_CMPH16I_INSN | |
4985 | || opcode == E_CMPHL16I_INSN) | |
4986 | { | |
4987 | if (split16_format != split16d_type) | |
4988 | { | |
4989 | if (fixup) | |
4990 | split16_format = split16d_type; | |
4991 | else | |
4992 | _bfd_error_handler | |
4993 | /* xgettext:c-format */ | |
4994 | (_("%B(%A+0x%lx): expected 16D style relocation on 0x%08x insn"), | |
4995 | input_bfd, input_section, offset, opcode); | |
4996 | } | |
4997 | } | |
86c95733 | 4998 | top5 = value & 0xf800; |
5499c7c7 AM |
4999 | top5 = top5 << (split16_format == split16a_type ? 5 : 10); |
5000 | insn &= (split16_format == split16a_type ? ~0x1f07ff : ~0x3e007ff); | |
b9c361e0 | 5001 | insn |= top5; |
86c95733 | 5002 | insn |= value & 0x7ff; |
95f0d0d2 | 5003 | bfd_put_32 (input_bfd, insn, loc); |
b9c361e0 | 5004 | } |
83eef883 AFB |
5005 | |
5006 | static void | |
5007 | ppc_elf_vle_split20 (bfd *output_bfd, bfd_byte *loc, bfd_vma value) | |
5008 | { | |
5009 | unsigned int insn; | |
5010 | ||
5011 | insn = bfd_get_32 (output_bfd, loc); | |
5012 | /* We have an li20 field, bits 17..20, 11..15, 21..31. */ | |
5013 | /* Top 4 bits of value to 17..20. */ | |
5014 | insn |= (value & 0xf0000) >> 5; | |
5015 | /* Next 5 bits of the value to 11..15. */ | |
5016 | insn |= (value & 0xf800) << 5; | |
5017 | /* And the final 11 bits of the value to bits 21 to 31. */ | |
5018 | insn |= value & 0x7ff; | |
5019 | bfd_put_32 (output_bfd, insn, loc); | |
5020 | } | |
5021 | ||
8853c3d3 | 5022 | \f |
d7128ce4 AM |
5023 | /* Choose which PLT scheme to use, and set .plt flags appropriately. |
5024 | Returns -1 on error, 0 for old PLT, 1 for new PLT. */ | |
5025 | int | |
5026 | ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED, | |
5446cbdf | 5027 | struct bfd_link_info *info) |
d7128ce4 AM |
5028 | { |
5029 | struct ppc_elf_link_hash_table *htab; | |
9d8504b1 | 5030 | flagword flags; |
d7128ce4 AM |
5031 | |
5032 | htab = ppc_elf_hash_table (info); | |
4a3dc543 RS |
5033 | |
5034 | if (htab->plt_type == PLT_UNSET) | |
016687f8 | 5035 | { |
b3874e1a AM |
5036 | struct elf_link_hash_entry *h; |
5037 | ||
5446cbdf | 5038 | if (htab->params->plt_style == PLT_OLD) |
016687f8 | 5039 | htab->plt_type = PLT_OLD; |
0e1862bb | 5040 | else if (bfd_link_pic (info) |
b3874e1a AM |
5041 | && htab->elf.dynamic_sections_created |
5042 | && (h = elf_link_hash_lookup (&htab->elf, "_mcount", | |
5043 | FALSE, FALSE, TRUE)) != NULL | |
5044 | && (h->type == STT_FUNC | |
5045 | || h->needs_plt) | |
5046 | && h->ref_regular | |
5047 | && !(SYMBOL_CALLS_LOCAL (info, h) | |
21d68fcd | 5048 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))) |
b3874e1a AM |
5049 | { |
5050 | /* Profiling of shared libs (and pies) is not supported with | |
5051 | secure plt, because ppc32 does profiling before a | |
5052 | function prologue and a secure plt pic call stubs needs | |
5053 | r30 to be set up. */ | |
5054 | htab->plt_type = PLT_OLD; | |
5055 | } | |
016687f8 AM |
5056 | else |
5057 | { | |
5058 | bfd *ibfd; | |
5446cbdf | 5059 | enum ppc_elf_plt_type plt_type = htab->params->plt_style; |
016687f8 AM |
5060 | |
5061 | /* Look through the reloc flags left by ppc_elf_check_relocs. | |
5062 | Use the old style bss plt if a file makes plt calls | |
5063 | without using the new relocs, and if ld isn't given | |
5064 | --secure-plt and we never see REL16 relocs. */ | |
5065 | if (plt_type == PLT_UNSET) | |
5066 | plt_type = PLT_OLD; | |
c72f2fb2 | 5067 | for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next) |
0c8d6e5c | 5068 | if (is_ppc_elf (ibfd)) |
016687f8 AM |
5069 | { |
5070 | if (ppc_elf_tdata (ibfd)->has_rel16) | |
5071 | plt_type = PLT_NEW; | |
5072 | else if (ppc_elf_tdata (ibfd)->makes_plt_call) | |
5073 | { | |
5074 | plt_type = PLT_OLD; | |
5075 | htab->old_bfd = ibfd; | |
5076 | break; | |
5077 | } | |
5078 | } | |
5079 | htab->plt_type = plt_type; | |
5080 | } | |
5081 | } | |
5446cbdf | 5082 | if (htab->plt_type == PLT_OLD && htab->params->plt_style == PLT_NEW) |
b3874e1a AM |
5083 | { |
5084 | if (htab->old_bfd != NULL) | |
5085 | info->callbacks->einfo (_("%P: bss-plt forced due to %B\n"), | |
5086 | htab->old_bfd); | |
5087 | else | |
5088 | info->callbacks->einfo (_("%P: bss-plt forced by profiling\n")); | |
5089 | } | |
d7128ce4 | 5090 | |
4a3dc543 | 5091 | BFD_ASSERT (htab->plt_type != PLT_VXWORKS); |
9d8504b1 | 5092 | |
4a3dc543 | 5093 | if (htab->plt_type == PLT_NEW) |
9d8504b1 PB |
5094 | { |
5095 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
5096 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
86b9da88 AM |
5097 | |
5098 | /* The new PLT is a loaded section. */ | |
ce558b89 AM |
5099 | if (htab->elf.splt != NULL |
5100 | && !bfd_set_section_flags (htab->elf.dynobj, htab->elf.splt, flags)) | |
86b9da88 AM |
5101 | return -1; |
5102 | ||
5103 | /* The new GOT is not executable. */ | |
ce558b89 AM |
5104 | if (htab->elf.sgot != NULL |
5105 | && !bfd_set_section_flags (htab->elf.dynobj, htab->elf.sgot, flags)) | |
86b9da88 | 5106 | return -1; |
d7128ce4 AM |
5107 | } |
5108 | else | |
5109 | { | |
5110 | /* Stop an unused .glink section from affecting .text alignment. */ | |
86b9da88 AM |
5111 | if (htab->glink != NULL |
5112 | && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0)) | |
5113 | return -1; | |
d7128ce4 | 5114 | } |
4a3dc543 | 5115 | return htab->plt_type == PLT_NEW; |
d7128ce4 AM |
5116 | } |
5117 | \f | |
25dbc73a AM |
5118 | /* Return the section that should be marked against GC for a given |
5119 | relocation. */ | |
586119b3 | 5120 | |
25dbc73a AM |
5121 | static asection * |
5122 | ppc_elf_gc_mark_hook (asection *sec, | |
07adf181 | 5123 | struct bfd_link_info *info, |
25dbc73a AM |
5124 | Elf_Internal_Rela *rel, |
5125 | struct elf_link_hash_entry *h, | |
5126 | Elf_Internal_Sym *sym) | |
5127 | { | |
5128 | if (h != NULL) | |
07adf181 AM |
5129 | switch (ELF32_R_TYPE (rel->r_info)) |
5130 | { | |
5131 | case R_PPC_GNU_VTINHERIT: | |
5132 | case R_PPC_GNU_VTENTRY: | |
5133 | return NULL; | |
5134 | } | |
5135 | ||
5136 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
25dbc73a | 5137 | } |
a876ecf9 | 5138 | |
25dbc73a AM |
5139 | /* Update the got, plt and dynamic reloc reference counts for the |
5140 | section being removed. */ | |
5141 | ||
5142 | static bfd_boolean | |
5143 | ppc_elf_gc_sweep_hook (bfd *abfd, | |
5144 | struct bfd_link_info *info, | |
5145 | asection *sec, | |
5146 | const Elf_Internal_Rela *relocs) | |
5147 | { | |
5148 | struct ppc_elf_link_hash_table *htab; | |
5149 | Elf_Internal_Shdr *symtab_hdr; | |
5150 | struct elf_link_hash_entry **sym_hashes; | |
5151 | bfd_signed_vma *local_got_refcounts; | |
5152 | const Elf_Internal_Rela *rel, *relend; | |
a6aa5195 | 5153 | asection *got2; |
25dbc73a | 5154 | |
0e1862bb | 5155 | if (bfd_link_relocatable (info)) |
7dda2462 TG |
5156 | return TRUE; |
5157 | ||
c87b5a93 AM |
5158 | if ((sec->flags & SEC_ALLOC) == 0) |
5159 | return TRUE; | |
5160 | ||
25dbc73a AM |
5161 | elf_section_data (sec)->local_dynrel = NULL; |
5162 | ||
5163 | htab = ppc_elf_hash_table (info); | |
0ffa91dd | 5164 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a AM |
5165 | sym_hashes = elf_sym_hashes (abfd); |
5166 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
a6aa5195 | 5167 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
5168 | |
5169 | relend = relocs + sec->reloc_count; | |
5170 | for (rel = relocs; rel < relend; rel++) | |
5171 | { | |
5172 | unsigned long r_symndx; | |
5173 | enum elf_ppc_reloc_type r_type; | |
5174 | struct elf_link_hash_entry *h = NULL; | |
5175 | ||
5176 | r_symndx = ELF32_R_SYM (rel->r_info); | |
5177 | if (r_symndx >= symtab_hdr->sh_info) | |
a876ecf9 | 5178 | { |
6061a67d | 5179 | struct elf_dyn_relocs **pp, *p; |
25dbc73a AM |
5180 | struct ppc_elf_link_hash_entry *eh; |
5181 | ||
5182 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5183 | while (h->root.type == bfd_link_hash_indirect | |
5184 | || h->root.type == bfd_link_hash_warning) | |
5185 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5186 | eh = (struct ppc_elf_link_hash_entry *) h; | |
5187 | ||
5188 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
5189 | if (p->sec == sec) | |
5190 | { | |
5191 | /* Everything must go for SEC. */ | |
5192 | *pp = p->next; | |
5193 | break; | |
5194 | } | |
a876ecf9 | 5195 | } |
ee05f2fe | 5196 | |
25dbc73a | 5197 | r_type = ELF32_R_TYPE (rel->r_info); |
de972ffa AM |
5198 | if (!htab->is_vxworks |
5199 | && h == NULL | |
5200 | && local_got_refcounts != NULL | |
0e1862bb | 5201 | && (!bfd_link_pic (info) |
de972ffa | 5202 | || is_branch_reloc (r_type))) |
e054468f | 5203 | { |
de972ffa AM |
5204 | struct plt_entry **local_plt = (struct plt_entry **) |
5205 | (local_got_refcounts + symtab_hdr->sh_info); | |
5206 | char *local_got_tls_masks = (char *) | |
5207 | (local_plt + symtab_hdr->sh_info); | |
5208 | if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0) | |
e054468f | 5209 | { |
de972ffa | 5210 | struct plt_entry **ifunc = local_plt + r_symndx; |
a877a2b6 AM |
5211 | bfd_vma addend = 0; |
5212 | struct plt_entry *ent; | |
5213 | ||
0e1862bb | 5214 | if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info)) |
a877a2b6 AM |
5215 | addend = rel->r_addend; |
5216 | ent = find_plt_ent (ifunc, got2, addend); | |
e054468f AM |
5217 | if (ent->plt.refcount > 0) |
5218 | ent->plt.refcount -= 1; | |
5219 | continue; | |
5220 | } | |
5221 | } | |
5222 | ||
25dbc73a | 5223 | switch (r_type) |
ee05f2fe | 5224 | { |
25dbc73a AM |
5225 | case R_PPC_GOT_TLSLD16: |
5226 | case R_PPC_GOT_TLSLD16_LO: | |
5227 | case R_PPC_GOT_TLSLD16_HI: | |
5228 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
5229 | case R_PPC_GOT_TLSGD16: |
5230 | case R_PPC_GOT_TLSGD16_LO: | |
5231 | case R_PPC_GOT_TLSGD16_HI: | |
5232 | case R_PPC_GOT_TLSGD16_HA: | |
5233 | case R_PPC_GOT_TPREL16: | |
5234 | case R_PPC_GOT_TPREL16_LO: | |
5235 | case R_PPC_GOT_TPREL16_HI: | |
5236 | case R_PPC_GOT_TPREL16_HA: | |
5237 | case R_PPC_GOT_DTPREL16: | |
5238 | case R_PPC_GOT_DTPREL16_LO: | |
5239 | case R_PPC_GOT_DTPREL16_HI: | |
5240 | case R_PPC_GOT_DTPREL16_HA: | |
5241 | case R_PPC_GOT16: | |
5242 | case R_PPC_GOT16_LO: | |
5243 | case R_PPC_GOT16_HI: | |
5244 | case R_PPC_GOT16_HA: | |
5245 | if (h != NULL) | |
ee05f2fe | 5246 | { |
25dbc73a AM |
5247 | if (h->got.refcount > 0) |
5248 | h->got.refcount--; | |
0e1862bb | 5249 | if (!bfd_link_pic (info)) |
91e21fb7 AM |
5250 | { |
5251 | struct plt_entry *ent; | |
5252 | ||
5253 | ent = find_plt_ent (&h->plt.plist, NULL, 0); | |
32af9f6e | 5254 | if (ent != NULL && ent->plt.refcount > 0) |
91e21fb7 AM |
5255 | ent->plt.refcount -= 1; |
5256 | } | |
ee05f2fe | 5257 | } |
25dbc73a AM |
5258 | else if (local_got_refcounts != NULL) |
5259 | { | |
5260 | if (local_got_refcounts[r_symndx] > 0) | |
5261 | local_got_refcounts[r_symndx]--; | |
5262 | } | |
5263 | break; | |
ee05f2fe | 5264 | |
25dbc73a AM |
5265 | case R_PPC_REL24: |
5266 | case R_PPC_REL14: | |
5267 | case R_PPC_REL14_BRTAKEN: | |
5268 | case R_PPC_REL14_BRNTAKEN: | |
5269 | case R_PPC_REL32: | |
3b36f7e6 | 5270 | if (h == NULL || h == htab->elf.hgot) |
25dbc73a | 5271 | break; |
1a0670f3 | 5272 | /* Fall through. */ |
ee05f2fe | 5273 | |
25dbc73a AM |
5274 | case R_PPC_ADDR32: |
5275 | case R_PPC_ADDR24: | |
5276 | case R_PPC_ADDR16: | |
5277 | case R_PPC_ADDR16_LO: | |
5278 | case R_PPC_ADDR16_HI: | |
5279 | case R_PPC_ADDR16_HA: | |
5280 | case R_PPC_ADDR14: | |
5281 | case R_PPC_ADDR14_BRTAKEN: | |
5282 | case R_PPC_ADDR14_BRNTAKEN: | |
5283 | case R_PPC_UADDR32: | |
5284 | case R_PPC_UADDR16: | |
0e1862bb | 5285 | if (bfd_link_pic (info)) |
87538722 | 5286 | break; |
1a0670f3 | 5287 | /* Fall through. */ |
87538722 | 5288 | |
25dbc73a AM |
5289 | case R_PPC_PLT32: |
5290 | case R_PPC_PLTREL24: | |
87538722 | 5291 | case R_PPC_PLTREL32: |
25dbc73a AM |
5292 | case R_PPC_PLT16_LO: |
5293 | case R_PPC_PLT16_HI: | |
5294 | case R_PPC_PLT16_HA: | |
5295 | if (h != NULL) | |
5296 | { | |
a877a2b6 AM |
5297 | bfd_vma addend = 0; |
5298 | struct plt_entry *ent; | |
5299 | ||
0e1862bb | 5300 | if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info)) |
a877a2b6 AM |
5301 | addend = rel->r_addend; |
5302 | ent = find_plt_ent (&h->plt.plist, got2, addend); | |
32af9f6e | 5303 | if (ent != NULL && ent->plt.refcount > 0) |
a6aa5195 | 5304 | ent->plt.refcount -= 1; |
25dbc73a AM |
5305 | } |
5306 | break; | |
ee05f2fe | 5307 | |
25dbc73a AM |
5308 | default: |
5309 | break; | |
5310 | } | |
7fce784e | 5311 | } |
7fce784e AS |
5312 | return TRUE; |
5313 | } | |
25dbc73a | 5314 | \f |
3a71aa26 AM |
5315 | /* Set plt output section type, htab->tls_get_addr, and call the |
5316 | generic ELF tls_setup function. */ | |
7fce784e | 5317 | |
25dbc73a | 5318 | asection * |
5446cbdf | 5319 | ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
7fce784e | 5320 | { |
25dbc73a | 5321 | struct ppc_elf_link_hash_table *htab; |
7fce784e | 5322 | |
25dbc73a | 5323 | htab = ppc_elf_hash_table (info); |
a7f2871e AM |
5324 | htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
5325 | FALSE, FALSE, TRUE); | |
f01f1741 AM |
5326 | if (htab->plt_type != PLT_NEW) |
5327 | htab->params->no_tls_get_addr_opt = TRUE; | |
5328 | ||
5446cbdf | 5329 | if (!htab->params->no_tls_get_addr_opt) |
a7f2871e AM |
5330 | { |
5331 | struct elf_link_hash_entry *opt, *tga; | |
5332 | opt = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt", | |
5333 | FALSE, FALSE, TRUE); | |
5334 | if (opt != NULL | |
5335 | && (opt->root.type == bfd_link_hash_defined | |
5336 | || opt->root.type == bfd_link_hash_defweak)) | |
5337 | { | |
5338 | /* If glibc supports an optimized __tls_get_addr call stub, | |
5339 | signalled by the presence of __tls_get_addr_opt, and we'll | |
5340 | be calling __tls_get_addr via a plt call stub, then | |
5341 | make __tls_get_addr point to __tls_get_addr_opt. */ | |
5342 | tga = htab->tls_get_addr; | |
5343 | if (htab->elf.dynamic_sections_created | |
5344 | && tga != NULL | |
5345 | && (tga->type == STT_FUNC | |
5346 | || tga->needs_plt) | |
5347 | && !(SYMBOL_CALLS_LOCAL (info, tga) | |
21d68fcd | 5348 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, tga))) |
a7f2871e AM |
5349 | { |
5350 | struct plt_entry *ent; | |
32af9f6e AM |
5351 | for (ent = tga->plt.plist; ent != NULL; ent = ent->next) |
5352 | if (ent->plt.refcount > 0) | |
5353 | break; | |
5354 | if (ent != NULL) | |
a7f2871e AM |
5355 | { |
5356 | tga->root.type = bfd_link_hash_indirect; | |
5357 | tga->root.u.i.link = &opt->root; | |
5358 | ppc_elf_copy_indirect_symbol (info, opt, tga); | |
b531344c | 5359 | opt->mark = 1; |
a7f2871e AM |
5360 | if (opt->dynindx != -1) |
5361 | { | |
5362 | /* Use __tls_get_addr_opt in dynamic relocations. */ | |
5363 | opt->dynindx = -1; | |
5364 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
5365 | opt->dynstr_index); | |
5366 | if (!bfd_elf_link_record_dynamic_symbol (info, opt)) | |
5367 | return FALSE; | |
5368 | } | |
5369 | htab->tls_get_addr = opt; | |
5370 | } | |
5371 | } | |
5372 | } | |
5373 | else | |
5446cbdf | 5374 | htab->params->no_tls_get_addr_opt = TRUE; |
a7f2871e | 5375 | } |
4a3dc543 | 5376 | if (htab->plt_type == PLT_NEW |
ce558b89 AM |
5377 | && htab->elf.splt != NULL |
5378 | && htab->elf.splt->output_section != NULL) | |
d7128ce4 | 5379 | { |
ce558b89 AM |
5380 | elf_section_type (htab->elf.splt->output_section) = SHT_PROGBITS; |
5381 | elf_section_flags (htab->elf.splt->output_section) = SHF_ALLOC + SHF_WRITE; | |
d7128ce4 AM |
5382 | } |
5383 | ||
25dbc73a | 5384 | return _bfd_elf_tls_setup (obfd, info); |
7fce784e AS |
5385 | } |
5386 | ||
3a71aa26 AM |
5387 | /* Return TRUE iff REL is a branch reloc with a global symbol matching |
5388 | HASH. */ | |
5389 | ||
5390 | static bfd_boolean | |
5391 | branch_reloc_hash_match (const bfd *ibfd, | |
5392 | const Elf_Internal_Rela *rel, | |
5393 | const struct elf_link_hash_entry *hash) | |
5394 | { | |
5395 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); | |
5396 | enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info); | |
5397 | unsigned int r_symndx = ELF32_R_SYM (rel->r_info); | |
5398 | ||
e054468f | 5399 | if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type)) |
3a71aa26 AM |
5400 | { |
5401 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
5402 | struct elf_link_hash_entry *h; | |
5403 | ||
5404 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5405 | while (h->root.type == bfd_link_hash_indirect | |
5406 | || h->root.type == bfd_link_hash_warning) | |
5407 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5408 | if (h == hash) | |
5409 | return TRUE; | |
5410 | } | |
5411 | return FALSE; | |
5412 | } | |
5413 | ||
25dbc73a AM |
5414 | /* Run through all the TLS relocs looking for optimization |
5415 | opportunities. */ | |
252b5132 | 5416 | |
25dbc73a AM |
5417 | bfd_boolean |
5418 | ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, | |
5419 | struct bfd_link_info *info) | |
252b5132 | 5420 | { |
7fce784e | 5421 | bfd *ibfd; |
25dbc73a AM |
5422 | asection *sec; |
5423 | struct ppc_elf_link_hash_table *htab; | |
b7fcf6f6 | 5424 | int pass; |
252b5132 | 5425 | |
3cbc1e5e | 5426 | if (!bfd_link_executable (info)) |
25dbc73a | 5427 | return TRUE; |
252b5132 | 5428 | |
7619e7c7 | 5429 | htab = ppc_elf_hash_table (info); |
663a1470 AM |
5430 | if (htab == NULL) |
5431 | return FALSE; | |
5432 | ||
b7fcf6f6 AM |
5433 | /* Make two passes through the relocs. First time check that tls |
5434 | relocs involved in setting up a tls_get_addr call are indeed | |
663a1470 AM |
5435 | followed by such a call. If they are not, don't do any tls |
5436 | optimization. On the second pass twiddle tls_mask flags to | |
5437 | notify relocate_section that optimization can be done, and | |
5438 | adjust got and plt refcounts. */ | |
b7fcf6f6 | 5439 | for (pass = 0; pass < 2; ++pass) |
c72f2fb2 | 5440 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
b7fcf6f6 AM |
5441 | { |
5442 | Elf_Internal_Sym *locsyms = NULL; | |
0ffa91dd | 5443 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); |
32af9f6e | 5444 | asection *got2 = bfd_get_section_by_name (ibfd, ".got2"); |
7619e7c7 | 5445 | |
b7fcf6f6 AM |
5446 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
5447 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
5448 | { | |
5449 | Elf_Internal_Rela *relstart, *rel, *relend; | |
663a1470 | 5450 | int expecting_tls_get_addr = 0; |
252b5132 | 5451 | |
b7fcf6f6 AM |
5452 | /* Read the relocations. */ |
5453 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, | |
5454 | info->keep_memory); | |
5455 | if (relstart == NULL) | |
5456 | return FALSE; | |
7619e7c7 | 5457 | |
b7fcf6f6 AM |
5458 | relend = relstart + sec->reloc_count; |
5459 | for (rel = relstart; rel < relend; rel++) | |
5460 | { | |
5461 | enum elf_ppc_reloc_type r_type; | |
5462 | unsigned long r_symndx; | |
5463 | struct elf_link_hash_entry *h = NULL; | |
5464 | char *tls_mask; | |
5465 | char tls_set, tls_clear; | |
5466 | bfd_boolean is_local; | |
b7fcf6f6 AM |
5467 | bfd_signed_vma *got_count; |
5468 | ||
5469 | r_symndx = ELF32_R_SYM (rel->r_info); | |
5470 | if (r_symndx >= symtab_hdr->sh_info) | |
5471 | { | |
5472 | struct elf_link_hash_entry **sym_hashes; | |
7fce784e | 5473 | |
b7fcf6f6 AM |
5474 | sym_hashes = elf_sym_hashes (ibfd); |
5475 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5476 | while (h->root.type == bfd_link_hash_indirect | |
5477 | || h->root.type == bfd_link_hash_warning) | |
5478 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5479 | } | |
7619e7c7 | 5480 | |
b7fcf6f6 AM |
5481 | is_local = FALSE; |
5482 | if (h == NULL | |
5483 | || !h->def_dynamic) | |
5484 | is_local = TRUE; | |
7619e7c7 | 5485 | |
b7fcf6f6 | 5486 | r_type = ELF32_R_TYPE (rel->r_info); |
663a1470 AM |
5487 | /* If this section has old-style __tls_get_addr calls |
5488 | without marker relocs, then check that each | |
5489 | __tls_get_addr call reloc is preceded by a reloc | |
5490 | that conceivably belongs to the __tls_get_addr arg | |
5491 | setup insn. If we don't find matching arg setup | |
5492 | relocs, don't do any tls optimization. */ | |
5493 | if (pass == 0 | |
5494 | && sec->has_tls_get_addr_call | |
5495 | && h != NULL | |
5496 | && h == htab->tls_get_addr | |
5497 | && !expecting_tls_get_addr | |
5498 | && is_branch_reloc (r_type)) | |
5499 | { | |
25f53a85 | 5500 | info->callbacks->minfo ("%H __tls_get_addr lost arg, " |
663a1470 AM |
5501 | "TLS optimization disabled\n", |
5502 | ibfd, sec, rel->r_offset); | |
5503 | if (elf_section_data (sec)->relocs != relstart) | |
5504 | free (relstart); | |
5505 | return TRUE; | |
5506 | } | |
5507 | ||
5508 | expecting_tls_get_addr = 0; | |
b7fcf6f6 AM |
5509 | switch (r_type) |
5510 | { | |
5511 | case R_PPC_GOT_TLSLD16: | |
5512 | case R_PPC_GOT_TLSLD16_LO: | |
5513 | expecting_tls_get_addr = 1; | |
1a0670f3 | 5514 | /* Fall through. */ |
b7fcf6f6 AM |
5515 | |
5516 | case R_PPC_GOT_TLSLD16_HI: | |
5517 | case R_PPC_GOT_TLSLD16_HA: | |
5518 | /* These relocs should never be against a symbol | |
5519 | defined in a shared lib. Leave them alone if | |
5520 | that turns out to be the case. */ | |
5521 | if (!is_local) | |
5522 | continue; | |
5523 | ||
5524 | /* LD -> LE */ | |
5525 | tls_set = 0; | |
5526 | tls_clear = TLS_LD; | |
5527 | break; | |
5528 | ||
5529 | case R_PPC_GOT_TLSGD16: | |
5530 | case R_PPC_GOT_TLSGD16_LO: | |
5531 | expecting_tls_get_addr = 1; | |
1a0670f3 | 5532 | /* Fall through. */ |
b7fcf6f6 AM |
5533 | |
5534 | case R_PPC_GOT_TLSGD16_HI: | |
5535 | case R_PPC_GOT_TLSGD16_HA: | |
5536 | if (is_local) | |
5537 | /* GD -> LE */ | |
5538 | tls_set = 0; | |
5539 | else | |
5540 | /* GD -> IE */ | |
5541 | tls_set = TLS_TLS | TLS_TPRELGD; | |
5542 | tls_clear = TLS_GD; | |
5543 | break; | |
5544 | ||
5545 | case R_PPC_GOT_TPREL16: | |
5546 | case R_PPC_GOT_TPREL16_LO: | |
5547 | case R_PPC_GOT_TPREL16_HI: | |
5548 | case R_PPC_GOT_TPREL16_HA: | |
5549 | if (is_local) | |
5550 | { | |
5551 | /* IE -> LE */ | |
5552 | tls_set = 0; | |
5553 | tls_clear = TLS_TPREL; | |
5554 | break; | |
5555 | } | |
5556 | else | |
5557 | continue; | |
5558 | ||
32af9f6e AM |
5559 | case R_PPC_TLSGD: |
5560 | case R_PPC_TLSLD: | |
5561 | expecting_tls_get_addr = 2; | |
5562 | tls_set = 0; | |
5563 | tls_clear = 0; | |
5564 | break; | |
5565 | ||
b7fcf6f6 | 5566 | default: |
25dbc73a | 5567 | continue; |
b7fcf6f6 | 5568 | } |
25dbc73a | 5569 | |
b7fcf6f6 AM |
5570 | if (pass == 0) |
5571 | { | |
727fc41e | 5572 | if (!expecting_tls_get_addr |
32af9f6e AM |
5573 | || (expecting_tls_get_addr == 1 |
5574 | && !sec->has_tls_get_addr_call)) | |
b7fcf6f6 | 5575 | continue; |
25dbc73a | 5576 | |
3a71aa26 AM |
5577 | if (rel + 1 < relend |
5578 | && branch_reloc_hash_match (ibfd, rel + 1, | |
5579 | htab->tls_get_addr)) | |
5580 | continue; | |
25dbc73a | 5581 | |
b7fcf6f6 AM |
5582 | /* Uh oh, we didn't find the expected call. We |
5583 | could just mark this symbol to exclude it | |
5584 | from tls optimization but it's safer to skip | |
663a1470 | 5585 | the entire optimization. */ |
25f53a85 | 5586 | info->callbacks->minfo (_("%H arg lost __tls_get_addr, " |
663a1470 AM |
5587 | "TLS optimization disabled\n"), |
5588 | ibfd, sec, rel->r_offset); | |
5589 | if (elf_section_data (sec)->relocs != relstart) | |
5590 | free (relstart); | |
5591 | return TRUE; | |
b7fcf6f6 | 5592 | } |
25dbc73a | 5593 | |
32af9f6e AM |
5594 | if (expecting_tls_get_addr) |
5595 | { | |
5596 | struct plt_entry *ent; | |
5597 | bfd_vma addend = 0; | |
5598 | ||
0e1862bb | 5599 | if (bfd_link_pic (info) |
32af9f6e AM |
5600 | && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24) |
5601 | addend = rel[1].r_addend; | |
5602 | ent = find_plt_ent (&htab->tls_get_addr->plt.plist, | |
5603 | got2, addend); | |
5604 | if (ent != NULL && ent->plt.refcount > 0) | |
5605 | ent->plt.refcount -= 1; | |
5606 | ||
5607 | if (expecting_tls_get_addr == 2) | |
5608 | continue; | |
5609 | } | |
5610 | ||
b7fcf6f6 AM |
5611 | if (h != NULL) |
5612 | { | |
5613 | tls_mask = &ppc_elf_hash_entry (h)->tls_mask; | |
5614 | got_count = &h->got.refcount; | |
5615 | } | |
5616 | else | |
5617 | { | |
b7fcf6f6 | 5618 | bfd_signed_vma *lgot_refs; |
e054468f | 5619 | struct plt_entry **local_plt; |
b7fcf6f6 | 5620 | char *lgot_masks; |
25dbc73a | 5621 | |
b7fcf6f6 AM |
5622 | if (locsyms == NULL) |
5623 | { | |
5624 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
5625 | if (locsyms == NULL) | |
5626 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
5627 | symtab_hdr->sh_info, | |
5628 | 0, NULL, NULL, NULL); | |
5629 | if (locsyms == NULL) | |
5630 | { | |
5631 | if (elf_section_data (sec)->relocs != relstart) | |
5632 | free (relstart); | |
5633 | return FALSE; | |
5634 | } | |
5635 | } | |
b7fcf6f6 AM |
5636 | lgot_refs = elf_local_got_refcounts (ibfd); |
5637 | if (lgot_refs == NULL) | |
5638 | abort (); | |
e054468f AM |
5639 | local_plt = (struct plt_entry **) |
5640 | (lgot_refs + symtab_hdr->sh_info); | |
5641 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
b7fcf6f6 AM |
5642 | tls_mask = &lgot_masks[r_symndx]; |
5643 | got_count = &lgot_refs[r_symndx]; | |
5644 | } | |
25dbc73a | 5645 | |
b7fcf6f6 AM |
5646 | if (tls_set == 0) |
5647 | { | |
5648 | /* We managed to get rid of a got entry. */ | |
5649 | if (*got_count > 0) | |
5650 | *got_count -= 1; | |
5651 | } | |
25dbc73a | 5652 | |
b7fcf6f6 AM |
5653 | *tls_mask |= tls_set; |
5654 | *tls_mask &= ~tls_clear; | |
5655 | } | |
25dbc73a | 5656 | |
b7fcf6f6 AM |
5657 | if (elf_section_data (sec)->relocs != relstart) |
5658 | free (relstart); | |
5659 | } | |
5660 | ||
5661 | if (locsyms != NULL | |
5662 | && (symtab_hdr->contents != (unsigned char *) locsyms)) | |
5663 | { | |
5664 | if (!info->keep_memory) | |
5665 | free (locsyms); | |
5666 | else | |
5667 | symtab_hdr->contents = (unsigned char *) locsyms; | |
5668 | } | |
5669 | } | |
9a23f96e | 5670 | htab->do_tls_opt = 1; |
25dbc73a AM |
5671 | return TRUE; |
5672 | } | |
5673 | \f | |
625af618 AM |
5674 | /* Return true if we have dynamic relocs that apply to read-only sections. */ |
5675 | ||
5676 | static bfd_boolean | |
0caf6c82 L |
5677 | readonly_dynrelocs (struct elf_link_hash_entry *h, |
5678 | struct bfd_link_info *info) | |
625af618 | 5679 | { |
6061a67d | 5680 | struct elf_dyn_relocs *p; |
625af618 AM |
5681 | |
5682 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) | |
5683 | { | |
5684 | asection *s = p->sec->output_section; | |
5685 | ||
5686 | if (s != NULL | |
5687 | && ((s->flags & (SEC_READONLY | SEC_ALLOC)) | |
5688 | == (SEC_READONLY | SEC_ALLOC))) | |
0caf6c82 L |
5689 | { |
5690 | if (info) | |
5691 | info->callbacks->minfo (_("%B: dynamic relocation in read-only section `%A'\n"), | |
5692 | p->sec->owner, p->sec); | |
5693 | ||
5694 | return TRUE; | |
5695 | } | |
625af618 AM |
5696 | } |
5697 | return FALSE; | |
5698 | } | |
5699 | ||
25dbc73a AM |
5700 | /* Adjust a symbol defined by a dynamic object and referenced by a |
5701 | regular object. The current definition is in some section of the | |
5702 | dynamic object, but we're not including those sections. We have to | |
5703 | change the definition to something the rest of the link can | |
5704 | understand. */ | |
7fce784e | 5705 | |
25dbc73a AM |
5706 | static bfd_boolean |
5707 | ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, | |
5708 | struct elf_link_hash_entry *h) | |
5709 | { | |
5710 | struct ppc_elf_link_hash_table *htab; | |
5711 | asection *s; | |
7fce784e | 5712 | |
25dbc73a AM |
5713 | #ifdef DEBUG |
5714 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", | |
5715 | h->root.root.string); | |
5716 | #endif | |
252b5132 | 5717 | |
25dbc73a AM |
5718 | /* Make sure we know what is going on here. */ |
5719 | htab = ppc_elf_hash_table (info); | |
5720 | BFD_ASSERT (htab->elf.dynobj != NULL | |
5721 | && (h->needs_plt | |
91e21fb7 | 5722 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
5723 | || h->u.weakdef != NULL |
5724 | || (h->def_dynamic | |
5725 | && h->ref_regular | |
5726 | && !h->def_regular))); | |
252b5132 | 5727 | |
25dbc73a AM |
5728 | /* Deal with function syms. */ |
5729 | if (h->type == STT_FUNC | |
e054468f | 5730 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
5731 | || h->needs_plt) |
5732 | { | |
5733 | /* Clear procedure linkage table information for any symbol that | |
5734 | won't need a .plt entry. */ | |
a6aa5195 AM |
5735 | struct plt_entry *ent; |
5736 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
5737 | if (ent->plt.refcount > 0) | |
5738 | break; | |
5739 | if (ent == NULL | |
e054468f AM |
5740 | || (h->type != STT_GNU_IFUNC |
5741 | && (SYMBOL_CALLS_LOCAL (info, h) | |
21d68fcd | 5742 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)))) |
252b5132 | 5743 | { |
25dbc73a | 5744 | /* A PLT entry is not required/allowed when: |
252b5132 | 5745 | |
25dbc73a AM |
5746 | 1. We are not using ld.so; because then the PLT entry |
5747 | can't be set up, so we can't use one. In this case, | |
5748 | ppc_elf_adjust_dynamic_symbol won't even be called. | |
252b5132 | 5749 | |
25dbc73a AM |
5750 | 2. GC has rendered the entry unused. |
5751 | ||
5752 | 3. We know for certain that a call to this symbol | |
5753 | will go to this object, or will remain undefined. */ | |
a6aa5195 | 5754 | h->plt.plist = NULL; |
25dbc73a | 5755 | h->needs_plt = 0; |
d1eca1e4 | 5756 | h->pointer_equality_needed = 0; |
25dbc73a | 5757 | } |
625af618 AM |
5758 | else |
5759 | { | |
d1eca1e4 AM |
5760 | /* Taking a function's address in a read/write section |
5761 | doesn't require us to define the function symbol in the | |
1009ef28 | 5762 | executable on a plt call stub. A dynamic reloc can |
f0158f44 AM |
5763 | be used instead, giving better runtime performance. |
5764 | (Calls via that function pointer don't need to bounce | |
5765 | through the plt call stub.) Similarly, use a dynamic | |
5766 | reloc for a weak reference when possible, allowing the | |
5767 | resolution of the symbol to be set at load time rather | |
5768 | than link time. */ | |
5769 | if ((h->pointer_equality_needed | |
5770 | || (!h->ref_regular_nonweak && h->non_got_ref)) | |
1009ef28 AM |
5771 | && !htab->is_vxworks |
5772 | && !ppc_elf_hash_entry (h)->has_sda_refs | |
0caf6c82 | 5773 | && !readonly_dynrelocs (h, NULL)) |
d1eca1e4 AM |
5774 | { |
5775 | h->pointer_equality_needed = 0; | |
f0158f44 AM |
5776 | /* After adjust_dynamic_symbol, non_got_ref set in the |
5777 | non-pic case means that dyn_relocs for this symbol | |
5778 | should be discarded. */ | |
d1eca1e4 AM |
5779 | h->non_got_ref = 0; |
5780 | } | |
625af618 | 5781 | } |
d3e454b9 | 5782 | h->protected_def = 0; |
25dbc73a | 5783 | return TRUE; |
252b5132 | 5784 | } |
25dbc73a | 5785 | else |
a6aa5195 | 5786 | h->plt.plist = NULL; |
252b5132 | 5787 | |
25dbc73a AM |
5788 | /* If this is a weak symbol, and there is a real definition, the |
5789 | processor independent code will have arranged for us to see the | |
5790 | real definition first, and we can just use the same value. */ | |
5791 | if (h->u.weakdef != NULL) | |
252b5132 | 5792 | { |
25dbc73a AM |
5793 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
5794 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
5795 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
5796 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
5797 | if (ELIMINATE_COPY_RELOCS) | |
5798 | h->non_got_ref = h->u.weakdef->non_got_ref; | |
5799 | return TRUE; | |
5800 | } | |
dc810e39 | 5801 | |
25dbc73a AM |
5802 | /* This is a reference to a symbol defined by a dynamic object which |
5803 | is not a function. */ | |
252b5132 | 5804 | |
25dbc73a AM |
5805 | /* If we are creating a shared library, we must presume that the |
5806 | only references to the symbol are via the global offset table. | |
5807 | For such cases we need not do anything here; the relocations will | |
5808 | be handled correctly by relocate_section. */ | |
0e1862bb | 5809 | if (bfd_link_pic (info)) |
d3e454b9 AM |
5810 | { |
5811 | h->protected_def = 0; | |
5812 | return TRUE; | |
5813 | } | |
252b5132 | 5814 | |
25dbc73a AM |
5815 | /* If there are no references to this symbol that do not use the |
5816 | GOT, we don't need to generate a copy reloc. */ | |
5817 | if (!h->non_got_ref) | |
d3e454b9 AM |
5818 | { |
5819 | h->protected_def = 0; | |
5820 | return TRUE; | |
5821 | } | |
5822 | ||
5823 | /* Protected variables do not work with .dynbss. The copy in | |
5824 | .dynbss won't be used by the shared library with the protected | |
5825 | definition for the variable. Editing to PIC, or text relocations | |
5826 | are preferable to an incorrect program. */ | |
5827 | if (h->protected_def) | |
5828 | { | |
5829 | if (ELIMINATE_COPY_RELOCS | |
5830 | && ppc_elf_hash_entry (h)->has_addr16_ha | |
5831 | && ppc_elf_hash_entry (h)->has_addr16_lo | |
5832 | && htab->params->pic_fixup == 0 | |
5833 | && info->disable_target_specific_optimizations <= 1) | |
5834 | htab->params->pic_fixup = 1; | |
5835 | h->non_got_ref = 0; | |
5836 | return TRUE; | |
5837 | } | |
25dbc73a | 5838 | |
a127494f AM |
5839 | /* If -z nocopyreloc was given, we won't generate them either. */ |
5840 | if (info->nocopyreloc) | |
5841 | { | |
5842 | h->non_got_ref = 0; | |
5843 | return TRUE; | |
5844 | } | |
5845 | ||
cfd2c773 NS |
5846 | /* If we didn't find any dynamic relocs in read-only sections, then |
5847 | we'll be keeping the dynamic relocs and avoiding the copy reloc. | |
5848 | We can't do this if there are any small data relocations. This | |
5849 | doesn't work on VxWorks, where we can not have dynamic | |
5850 | relocations (other than copy and jump slot relocations) in an | |
5851 | executable. */ | |
4dc4a9a5 | 5852 | if (ELIMINATE_COPY_RELOCS |
cfd2c773 | 5853 | && !ppc_elf_hash_entry (h)->has_sda_refs |
625af618 AM |
5854 | && !htab->is_vxworks |
5855 | && !h->def_regular | |
0caf6c82 | 5856 | && !readonly_dynrelocs (h, NULL)) |
25dbc73a | 5857 | { |
625af618 AM |
5858 | h->non_got_ref = 0; |
5859 | return TRUE; | |
252b5132 RH |
5860 | } |
5861 | ||
25dbc73a AM |
5862 | /* We must allocate the symbol in our .dynbss section, which will |
5863 | become part of the .bss section of the executable. There will be | |
5864 | an entry for this symbol in the .dynsym section. The dynamic | |
5865 | object will contain position independent code, so all references | |
5866 | from the dynamic object to this symbol will go through the global | |
5867 | offset table. The dynamic linker will use the .dynsym entry to | |
5868 | determine the address it must put in the global offset table, so | |
5869 | both the dynamic object and the regular object will refer to the | |
5870 | same memory location for the variable. | |
5871 | ||
4dc4a9a5 DJ |
5872 | Of course, if the symbol is referenced using SDAREL relocs, we |
5873 | must instead allocate it in .sbss. */ | |
25dbc73a | 5874 | |
4dc4a9a5 | 5875 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a | 5876 | s = htab->dynsbss; |
5474d94f AM |
5877 | else if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
5878 | s = htab->elf.sdynrelro; | |
25dbc73a | 5879 | else |
9d19e4fd | 5880 | s = htab->elf.sdynbss; |
25dbc73a AM |
5881 | BFD_ASSERT (s != NULL); |
5882 | ||
5883 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
5884 | copy the initial value out of the dynamic object and into the | |
5885 | runtime process image. We need to remember the offset into the | |
5886 | .rela.bss section we are going to use. */ | |
1d7e9d18 | 5887 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
25dbc73a AM |
5888 | { |
5889 | asection *srel; | |
5890 | ||
4dc4a9a5 | 5891 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a | 5892 | srel = htab->relsbss; |
5474d94f AM |
5893 | else if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
5894 | srel = htab->elf.sreldynrelro; | |
25dbc73a | 5895 | else |
9d19e4fd | 5896 | srel = htab->elf.srelbss; |
25dbc73a AM |
5897 | BFD_ASSERT (srel != NULL); |
5898 | srel->size += sizeof (Elf32_External_Rela); | |
5899 | h->needs_copy = 1; | |
5900 | } | |
7619e7c7 | 5901 | |
6cabe1ea | 5902 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
25dbc73a AM |
5903 | } |
5904 | \f | |
ac39eb42 AM |
5905 | /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is |
5906 | xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0, | |
5907 | specifying the addend on the plt relocation. For -fpic code, the sym | |
5908 | is xxxxxxxx.plt_pic32.<callee>, and for -fPIC | |
5909 | xxxxxxxx.got2.plt_pic32.<callee>. */ | |
0ba07910 AM |
5910 | |
5911 | static bfd_boolean | |
5912 | add_stub_sym (struct plt_entry *ent, | |
5913 | struct elf_link_hash_entry *h, | |
ac39eb42 | 5914 | struct bfd_link_info *info) |
0ba07910 AM |
5915 | { |
5916 | struct elf_link_hash_entry *sh; | |
5917 | size_t len1, len2, len3; | |
5918 | char *name; | |
ac39eb42 AM |
5919 | const char *stub; |
5920 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
5921 | ||
0e1862bb | 5922 | if (bfd_link_pic (info)) |
ac39eb42 AM |
5923 | stub = ".plt_pic32."; |
5924 | else | |
5925 | stub = ".plt_call32."; | |
0ba07910 AM |
5926 | |
5927 | len1 = strlen (h->root.root.string); | |
ac39eb42 | 5928 | len2 = strlen (stub); |
0ba07910 AM |
5929 | len3 = 0; |
5930 | if (ent->sec) | |
5931 | len3 = strlen (ent->sec->name); | |
ac39eb42 | 5932 | name = bfd_malloc (len1 + len2 + len3 + 9); |
0ba07910 AM |
5933 | if (name == NULL) |
5934 | return FALSE; | |
5935 | sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff); | |
5936 | if (ent->sec) | |
5937 | memcpy (name + 8, ent->sec->name, len3); | |
ac39eb42 AM |
5938 | memcpy (name + 8 + len3, stub, len2); |
5939 | memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1); | |
0ba07910 AM |
5940 | sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE); |
5941 | if (sh == NULL) | |
5942 | return FALSE; | |
5943 | if (sh->root.type == bfd_link_hash_new) | |
5944 | { | |
5945 | sh->root.type = bfd_link_hash_defined; | |
5946 | sh->root.u.def.section = htab->glink; | |
5947 | sh->root.u.def.value = ent->glink_offset; | |
5948 | sh->ref_regular = 1; | |
5949 | sh->def_regular = 1; | |
5950 | sh->ref_regular_nonweak = 1; | |
5951 | sh->forced_local = 1; | |
5952 | sh->non_elf = 0; | |
2ec55de3 | 5953 | sh->root.linker_def = 1; |
0ba07910 AM |
5954 | } |
5955 | return TRUE; | |
5956 | } | |
5957 | ||
3b36f7e6 AM |
5958 | /* Allocate NEED contiguous space in .got, and return the offset. |
5959 | Handles allocation of the got header when crossing 32k. */ | |
5960 | ||
5961 | static bfd_vma | |
5962 | allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need) | |
5963 | { | |
5964 | bfd_vma where; | |
4a3dc543 | 5965 | unsigned int max_before_header; |
3b36f7e6 | 5966 | |
4a3dc543 | 5967 | if (htab->plt_type == PLT_VXWORKS) |
9d8504b1 | 5968 | { |
ce558b89 AM |
5969 | where = htab->elf.sgot->size; |
5970 | htab->elf.sgot->size += need; | |
9d8504b1 | 5971 | } |
3b36f7e6 AM |
5972 | else |
5973 | { | |
4a3dc543 RS |
5974 | max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764; |
5975 | if (need <= htab->got_gap) | |
3b36f7e6 | 5976 | { |
4a3dc543 RS |
5977 | where = max_before_header - htab->got_gap; |
5978 | htab->got_gap -= need; | |
5979 | } | |
5980 | else | |
5981 | { | |
ce558b89 AM |
5982 | if (htab->elf.sgot->size + need > max_before_header |
5983 | && htab->elf.sgot->size <= max_before_header) | |
4a3dc543 | 5984 | { |
ce558b89 AM |
5985 | htab->got_gap = max_before_header - htab->elf.sgot->size; |
5986 | htab->elf.sgot->size = max_before_header + htab->got_header_size; | |
4a3dc543 | 5987 | } |
ce558b89 AM |
5988 | where = htab->elf.sgot->size; |
5989 | htab->elf.sgot->size += need; | |
3b36f7e6 | 5990 | } |
3b36f7e6 AM |
5991 | } |
5992 | return where; | |
5993 | } | |
5994 | ||
46434633 | 5995 | /* If H is undefined, make it dynamic if that makes sense. */ |
f0158f44 AM |
5996 | |
5997 | static bfd_boolean | |
46434633 AM |
5998 | ensure_undef_dynamic (struct bfd_link_info *info, |
5999 | struct elf_link_hash_entry *h) | |
f0158f44 AM |
6000 | { |
6001 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
6002 | ||
6003 | if (htab->dynamic_sections_created | |
46434633 AM |
6004 | && ((info->dynamic_undefined_weak != 0 |
6005 | && h->root.type == bfd_link_hash_undefweak) | |
6006 | || h->root.type == bfd_link_hash_undefined) | |
f0158f44 AM |
6007 | && h->dynindx == -1 |
6008 | && !h->forced_local | |
6009 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
6010 | return bfd_elf_link_record_dynamic_symbol (info, h); | |
6011 | return TRUE; | |
6012 | } | |
6013 | ||
25dbc73a | 6014 | /* Allocate space in associated reloc sections for dynamic relocs. */ |
252b5132 | 6015 | |
b34976b6 | 6016 | static bfd_boolean |
25dbc73a | 6017 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
252b5132 | 6018 | { |
25dbc73a AM |
6019 | struct bfd_link_info *info = inf; |
6020 | struct ppc_elf_link_hash_entry *eh; | |
7619e7c7 | 6021 | struct ppc_elf_link_hash_table *htab; |
6061a67d | 6022 | struct elf_dyn_relocs *p; |
f0158f44 | 6023 | bfd_boolean dyn; |
252b5132 | 6024 | |
25dbc73a | 6025 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 6026 | return TRUE; |
252b5132 | 6027 | |
7619e7c7 | 6028 | htab = ppc_elf_hash_table (info); |
25dbc73a | 6029 | eh = (struct ppc_elf_link_hash_entry *) h; |
d3e454b9 AM |
6030 | if (eh->elf.got.refcount > 0 |
6031 | || (ELIMINATE_COPY_RELOCS | |
6032 | && !eh->elf.def_regular | |
6033 | && eh->elf.protected_def | |
6034 | && eh->has_addr16_ha | |
6035 | && eh->has_addr16_lo | |
6036 | && htab->params->pic_fixup > 0)) | |
25dbc73a | 6037 | { |
d6e14abc AM |
6038 | unsigned int need; |
6039 | ||
46434633 AM |
6040 | /* Make sure this symbol is output as a dynamic symbol. */ |
6041 | if (!ensure_undef_dynamic (info, &eh->elf)) | |
f0158f44 | 6042 | return FALSE; |
252b5132 | 6043 | |
d6e14abc AM |
6044 | need = 0; |
6045 | if ((eh->tls_mask & TLS_TLS) != 0) | |
25dbc73a | 6046 | { |
d6e14abc | 6047 | if ((eh->tls_mask & TLS_LD) != 0) |
252b5132 | 6048 | { |
d6e14abc AM |
6049 | if (!eh->elf.def_dynamic) |
6050 | /* We'll just use htab->tlsld_got.offset. This should | |
6051 | always be the case. It's a little odd if we have | |
6052 | a local dynamic reloc against a non-local symbol. */ | |
6053 | htab->tlsld_got.refcount += 1; | |
6054 | else | |
3b36f7e6 | 6055 | need += 8; |
252b5132 | 6056 | } |
d6e14abc AM |
6057 | if ((eh->tls_mask & TLS_GD) != 0) |
6058 | need += 8; | |
6059 | if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
6060 | need += 4; | |
6061 | if ((eh->tls_mask & TLS_DTPREL) != 0) | |
3b36f7e6 | 6062 | need += 4; |
d6e14abc AM |
6063 | } |
6064 | else | |
6065 | need += 4; | |
6066 | if (need == 0) | |
6067 | eh->elf.got.offset = (bfd_vma) -1; | |
6068 | else | |
6069 | { | |
3b36f7e6 | 6070 | eh->elf.got.offset = allocate_got (htab, need); |
0e1862bb | 6071 | if ((bfd_link_pic (info) |
f0158f44 AM |
6072 | || (htab->elf.dynamic_sections_created |
6073 | && eh->elf.dynindx != -1 | |
6074 | && !SYMBOL_REFERENCES_LOCAL (info, &eh->elf))) | |
21d68fcd | 6075 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &eh->elf)) |
252b5132 | 6076 | { |
ce558b89 | 6077 | asection *rsec = htab->elf.srelgot; |
0bed072f AM |
6078 | |
6079 | if (eh->elf.type == STT_GNU_IFUNC) | |
ce558b89 | 6080 | rsec = htab->elf.irelplt; |
3b36f7e6 AM |
6081 | /* All the entries we allocated need relocs. |
6082 | Except LD only needs one. */ | |
d6e14abc AM |
6083 | if ((eh->tls_mask & TLS_LD) != 0 |
6084 | && eh->elf.def_dynamic) | |
3b36f7e6 | 6085 | need -= 4; |
25f23106 | 6086 | rsec->size += need * (sizeof (Elf32_External_Rela) / 4); |
252b5132 | 6087 | } |
25dbc73a AM |
6088 | } |
6089 | } | |
6090 | else | |
6091 | eh->elf.got.offset = (bfd_vma) -1; | |
252b5132 | 6092 | |
954b63d4 AM |
6093 | /* If no dynamic sections we can't have dynamic relocs, except for |
6094 | IFUNCs which are handled even in static executables. */ | |
f0158f44 AM |
6095 | if (!htab->elf.dynamic_sections_created |
6096 | && h->type != STT_GNU_IFUNC) | |
6097 | eh->dyn_relocs = NULL; | |
6098 | ||
6099 | if (eh->dyn_relocs == NULL) | |
6100 | ; | |
252b5132 | 6101 | |
25dbc73a AM |
6102 | /* In the shared -Bsymbolic case, discard space allocated for |
6103 | dynamic pc-relative relocs against symbols which turn out to be | |
6104 | defined in regular objects. For the normal shared case, discard | |
6105 | space for relocs that have become local due to symbol visibility | |
6106 | changes. */ | |
f0158f44 | 6107 | else if (bfd_link_pic (info)) |
25dbc73a | 6108 | { |
954b63d4 AM |
6109 | /* Discard relocs on undefined symbols that must be local. */ |
6110 | if (h->root.type == bfd_link_hash_undefined | |
6111 | && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
6112 | eh->dyn_relocs = NULL; | |
6113 | ||
6114 | /* Also discard relocs on undefined weak syms with non-default | |
6115 | visibility, or when dynamic_undefined_weak says so. */ | |
21d68fcd | 6116 | else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
954b63d4 AM |
6117 | eh->dyn_relocs = NULL; |
6118 | ||
25dbc73a | 6119 | /* Relocs that use pc_count are those that appear on a call insn, |
1d483afe | 6120 | or certain REL relocs (see must_be_dyn_reloc) that can be |
25dbc73a AM |
6121 | generated via assembly. We want calls to protected symbols to |
6122 | resolve directly to the function rather than going via the plt. | |
6123 | If people want function pointer comparisons to work as expected | |
6124 | then they should avoid writing weird assembly. */ | |
954b63d4 | 6125 | else if (SYMBOL_CALLS_LOCAL (info, h)) |
25dbc73a | 6126 | { |
6061a67d | 6127 | struct elf_dyn_relocs **pp; |
25dbc73a AM |
6128 | |
6129 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
252b5132 | 6130 | { |
25dbc73a AM |
6131 | p->count -= p->pc_count; |
6132 | p->pc_count = 0; | |
6133 | if (p->count == 0) | |
6134 | *pp = p->next; | |
6135 | else | |
6136 | pp = &p->next; | |
252b5132 | 6137 | } |
25dbc73a | 6138 | } |
252b5132 | 6139 | |
3348747a NS |
6140 | if (htab->is_vxworks) |
6141 | { | |
6061a67d | 6142 | struct elf_dyn_relocs **pp; |
3348747a NS |
6143 | |
6144 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
6145 | { | |
6146 | if (strcmp (p->sec->output_section->name, ".tls_vars") == 0) | |
6147 | *pp = p->next; | |
6148 | else | |
6149 | pp = &p->next; | |
6150 | } | |
6151 | } | |
6152 | ||
954b63d4 | 6153 | if (eh->dyn_relocs != NULL) |
25dbc73a | 6154 | { |
46434633 AM |
6155 | /* Make sure this symbol is output as a dynamic symbol. */ |
6156 | if (!ensure_undef_dynamic (info, h)) | |
f0158f44 | 6157 | return FALSE; |
25dbc73a AM |
6158 | } |
6159 | } | |
6160 | else if (ELIMINATE_COPY_RELOCS) | |
6161 | { | |
f0158f44 | 6162 | /* For the non-pic case, discard space for relocs against |
25dbc73a AM |
6163 | symbols which turn out to need copy relocs or are not |
6164 | dynamic. */ | |
25dbc73a | 6165 | if (!h->non_got_ref |
d3e454b9 AM |
6166 | && !h->def_regular |
6167 | && !(h->protected_def | |
6168 | && eh->has_addr16_ha | |
6169 | && eh->has_addr16_lo | |
6170 | && htab->params->pic_fixup > 0)) | |
25dbc73a | 6171 | { |
46434633 AM |
6172 | /* Make sure this symbol is output as a dynamic symbol. */ |
6173 | if (!ensure_undef_dynamic (info, h)) | |
f0158f44 | 6174 | return FALSE; |
7619e7c7 | 6175 | |
f0158f44 AM |
6176 | if (h->dynindx == -1) |
6177 | eh->dyn_relocs = NULL; | |
25dbc73a | 6178 | } |
f0158f44 AM |
6179 | else |
6180 | eh->dyn_relocs = NULL; | |
25dbc73a | 6181 | } |
252b5132 | 6182 | |
f0158f44 | 6183 | /* Allocate space. */ |
25dbc73a AM |
6184 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
6185 | { | |
6186 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
f95f8542 | 6187 | if (eh->elf.type == STT_GNU_IFUNC) |
ce558b89 | 6188 | sreloc = htab->elf.irelplt; |
25dbc73a AM |
6189 | sreloc->size += p->count * sizeof (Elf32_External_Rela); |
6190 | } | |
252b5132 | 6191 | |
f0158f44 AM |
6192 | /* Handle PLT relocs. Done last, after dynindx has settled. */ |
6193 | dyn = htab->elf.dynamic_sections_created && h->dynindx != -1; | |
6194 | if (dyn || h->type == STT_GNU_IFUNC) | |
6195 | { | |
6196 | struct plt_entry *ent; | |
6197 | bfd_boolean doneone = FALSE; | |
6198 | bfd_vma plt_offset = 0, glink_offset = 0; | |
6199 | ||
6200 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
6201 | if (ent->plt.refcount > 0) | |
6202 | { | |
6203 | asection *s = htab->elf.splt; | |
6204 | ||
6205 | if (!dyn) | |
6206 | s = htab->elf.iplt; | |
6207 | ||
6208 | if (htab->plt_type == PLT_NEW || !dyn) | |
6209 | { | |
6210 | if (!doneone) | |
6211 | { | |
6212 | plt_offset = s->size; | |
6213 | s->size += 4; | |
6214 | } | |
6215 | ent->plt.offset = plt_offset; | |
6216 | ||
6217 | s = htab->glink; | |
6218 | if (!doneone || bfd_link_pic (info)) | |
6219 | { | |
6220 | glink_offset = s->size; | |
6221 | s->size += GLINK_ENTRY_SIZE; | |
6222 | if (h == htab->tls_get_addr | |
6223 | && !htab->params->no_tls_get_addr_opt) | |
6224 | s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE; | |
6225 | } | |
6226 | if (!doneone | |
6227 | && !bfd_link_pic (info) | |
6228 | && h->def_dynamic | |
6229 | && !h->def_regular) | |
6230 | { | |
6231 | h->root.u.def.section = s; | |
6232 | h->root.u.def.value = glink_offset; | |
6233 | } | |
6234 | ent->glink_offset = glink_offset; | |
6235 | ||
6236 | if (htab->params->emit_stub_syms | |
6237 | && !add_stub_sym (ent, h, info)) | |
6238 | return FALSE; | |
6239 | } | |
6240 | else | |
6241 | { | |
6242 | if (!doneone) | |
6243 | { | |
6244 | /* If this is the first .plt entry, make room | |
6245 | for the special first entry. */ | |
6246 | if (s->size == 0) | |
6247 | s->size += htab->plt_initial_entry_size; | |
6248 | ||
6249 | /* The PowerPC PLT is actually composed of two | |
6250 | parts, the first part is 2 words (for a load | |
6251 | and a jump), and then there is a remaining | |
6252 | word available at the end. */ | |
6253 | plt_offset = (htab->plt_initial_entry_size | |
6254 | + (htab->plt_slot_size | |
6255 | * ((s->size | |
6256 | - htab->plt_initial_entry_size) | |
6257 | / htab->plt_entry_size))); | |
6258 | ||
6259 | /* If this symbol is not defined in a regular | |
6260 | file, and we are not generating a shared | |
6261 | library, then set the symbol to this location | |
6262 | in the .plt. This is to avoid text | |
6263 | relocations, and is required to make | |
6264 | function pointers compare as equal between | |
6265 | the normal executable and the shared library. */ | |
6266 | if (! bfd_link_pic (info) | |
6267 | && h->def_dynamic | |
6268 | && !h->def_regular) | |
6269 | { | |
6270 | h->root.u.def.section = s; | |
6271 | h->root.u.def.value = plt_offset; | |
6272 | } | |
6273 | ||
6274 | /* Make room for this entry. */ | |
6275 | s->size += htab->plt_entry_size; | |
6276 | /* After the 8192nd entry, room for two entries | |
6277 | is allocated. */ | |
6278 | if (htab->plt_type == PLT_OLD | |
6279 | && (s->size - htab->plt_initial_entry_size) | |
6280 | / htab->plt_entry_size | |
6281 | > PLT_NUM_SINGLE_ENTRIES) | |
6282 | s->size += htab->plt_entry_size; | |
6283 | } | |
6284 | ent->plt.offset = plt_offset; | |
6285 | } | |
6286 | ||
6287 | /* We also need to make an entry in the .rela.plt section. */ | |
6288 | if (!doneone) | |
6289 | { | |
6290 | if (!dyn) | |
6291 | htab->elf.irelplt->size += sizeof (Elf32_External_Rela); | |
6292 | else | |
6293 | { | |
6294 | htab->elf.srelplt->size += sizeof (Elf32_External_Rela); | |
6295 | ||
6296 | if (htab->plt_type == PLT_VXWORKS) | |
6297 | { | |
6298 | /* Allocate space for the unloaded relocations. */ | |
6299 | if (!bfd_link_pic (info) | |
6300 | && htab->elf.dynamic_sections_created) | |
6301 | { | |
6302 | if (ent->plt.offset | |
6303 | == (bfd_vma) htab->plt_initial_entry_size) | |
6304 | { | |
6305 | htab->srelplt2->size | |
6306 | += (sizeof (Elf32_External_Rela) | |
6307 | * VXWORKS_PLTRESOLVE_RELOCS); | |
6308 | } | |
6309 | ||
6310 | htab->srelplt2->size | |
6311 | += (sizeof (Elf32_External_Rela) | |
6312 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS); | |
6313 | } | |
6314 | ||
6315 | /* Every PLT entry has an associated GOT entry in | |
6316 | .got.plt. */ | |
6317 | htab->elf.sgotplt->size += 4; | |
6318 | } | |
6319 | } | |
6320 | doneone = TRUE; | |
6321 | } | |
6322 | } | |
6323 | else | |
6324 | ent->plt.offset = (bfd_vma) -1; | |
6325 | ||
6326 | if (!doneone) | |
6327 | { | |
6328 | h->plt.plist = NULL; | |
6329 | h->needs_plt = 0; | |
6330 | } | |
6331 | } | |
6332 | else | |
6333 | { | |
6334 | h->plt.plist = NULL; | |
6335 | h->needs_plt = 0; | |
6336 | } | |
6337 | ||
25dbc73a AM |
6338 | return TRUE; |
6339 | } | |
7619e7c7 | 6340 | |
625af618 AM |
6341 | /* Set DF_TEXTREL if we find any dynamic relocs that apply to |
6342 | read-only sections. */ | |
7619e7c7 | 6343 | |
25dbc73a | 6344 | static bfd_boolean |
0caf6c82 | 6345 | maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p) |
25dbc73a | 6346 | { |
0caf6c82 L |
6347 | struct bfd_link_info *info; |
6348 | ||
25dbc73a AM |
6349 | if (h->root.type == bfd_link_hash_indirect) |
6350 | return TRUE; | |
252b5132 | 6351 | |
0caf6c82 L |
6352 | info = (struct bfd_link_info *) info_p; |
6353 | if (readonly_dynrelocs (h, info)) | |
25dbc73a | 6354 | { |
0caf6c82 | 6355 | info->flags |= DF_TEXTREL; |
ee05f2fe | 6356 | |
625af618 AM |
6357 | /* Not an error, just cut short the traversal. */ |
6358 | return FALSE; | |
25dbc73a AM |
6359 | } |
6360 | return TRUE; | |
6361 | } | |
6362 | ||
6177242a AM |
6363 | static const unsigned char glink_eh_frame_cie[] = |
6364 | { | |
6365 | 0, 0, 0, 16, /* length. */ | |
6366 | 0, 0, 0, 0, /* id. */ | |
6367 | 1, /* CIE version. */ | |
6368 | 'z', 'R', 0, /* Augmentation string. */ | |
6369 | 4, /* Code alignment. */ | |
6370 | 0x7c, /* Data alignment. */ | |
6371 | 65, /* RA reg. */ | |
6372 | 1, /* Augmentation size. */ | |
6373 | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */ | |
6374 | DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */ | |
6375 | }; | |
6376 | ||
25dbc73a AM |
6377 | /* Set the sizes of the dynamic sections. */ |
6378 | ||
6379 | static bfd_boolean | |
93d1b056 | 6380 | ppc_elf_size_dynamic_sections (bfd *output_bfd, |
25dbc73a AM |
6381 | struct bfd_link_info *info) |
6382 | { | |
6383 | struct ppc_elf_link_hash_table *htab; | |
6384 | asection *s; | |
6385 | bfd_boolean relocs; | |
6386 | bfd *ibfd; | |
7fce784e | 6387 | |
252b5132 | 6388 | #ifdef DEBUG |
25dbc73a | 6389 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); |
252b5132 | 6390 | #endif |
252b5132 | 6391 | |
25dbc73a AM |
6392 | htab = ppc_elf_hash_table (info); |
6393 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
252b5132 | 6394 | |
25dbc73a AM |
6395 | if (elf_hash_table (info)->dynamic_sections_created) |
6396 | { | |
6397 | /* Set the contents of the .interp section to the interpreter. */ | |
9b8b325a | 6398 | if (bfd_link_executable (info) && !info->nointerp) |
25dbc73a | 6399 | { |
3d4d4302 | 6400 | s = bfd_get_linker_section (htab->elf.dynobj, ".interp"); |
25dbc73a AM |
6401 | BFD_ASSERT (s != NULL); |
6402 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
6403 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
6404 | } | |
6405 | } | |
252b5132 | 6406 | |
4a3dc543 | 6407 | if (htab->plt_type == PLT_OLD) |
d7128ce4 | 6408 | htab->got_header_size = 16; |
4a3dc543 | 6409 | else if (htab->plt_type == PLT_NEW) |
d7128ce4 | 6410 | htab->got_header_size = 12; |
252b5132 | 6411 | |
25dbc73a AM |
6412 | /* Set up .got offsets for local syms, and space for local dynamic |
6413 | relocs. */ | |
c72f2fb2 | 6414 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
25dbc73a AM |
6415 | { |
6416 | bfd_signed_vma *local_got; | |
6417 | bfd_signed_vma *end_local_got; | |
e054468f AM |
6418 | struct plt_entry **local_plt; |
6419 | struct plt_entry **end_local_plt; | |
25dbc73a AM |
6420 | char *lgot_masks; |
6421 | bfd_size_type locsymcount; | |
6422 | Elf_Internal_Shdr *symtab_hdr; | |
7fce784e | 6423 | |
0c8d6e5c | 6424 | if (!is_ppc_elf (ibfd)) |
25dbc73a | 6425 | continue; |
7fce784e | 6426 | |
25dbc73a AM |
6427 | for (s = ibfd->sections; s != NULL; s = s->next) |
6428 | { | |
f95f8542 | 6429 | struct ppc_dyn_relocs *p; |
252b5132 | 6430 | |
f95f8542 | 6431 | for (p = ((struct ppc_dyn_relocs *) |
25dbc73a AM |
6432 | elf_section_data (s)->local_dynrel); |
6433 | p != NULL; | |
6434 | p = p->next) | |
6435 | { | |
6436 | if (!bfd_is_abs_section (p->sec) | |
6437 | && bfd_is_abs_section (p->sec->output_section)) | |
6438 | { | |
6439 | /* Input section has been discarded, either because | |
6440 | it is a copy of a linkonce section or due to | |
6441 | linker script /DISCARD/, so we'll be discarding | |
6442 | the relocs too. */ | |
7fce784e | 6443 | } |
3348747a NS |
6444 | else if (htab->is_vxworks |
6445 | && strcmp (p->sec->output_section->name, | |
6446 | ".tls_vars") == 0) | |
6447 | { | |
6448 | /* Relocations in vxworks .tls_vars sections are | |
6449 | handled specially by the loader. */ | |
6450 | } | |
25dbc73a | 6451 | else if (p->count != 0) |
7fce784e | 6452 | { |
25f23106 | 6453 | asection *sreloc = elf_section_data (p->sec)->sreloc; |
f95f8542 | 6454 | if (p->ifunc) |
ce558b89 | 6455 | sreloc = htab->elf.irelplt; |
25f23106 | 6456 | sreloc->size += p->count * sizeof (Elf32_External_Rela); |
25dbc73a AM |
6457 | if ((p->sec->output_section->flags |
6458 | & (SEC_READONLY | SEC_ALLOC)) | |
6459 | == (SEC_READONLY | SEC_ALLOC)) | |
0caf6c82 L |
6460 | { |
6461 | info->flags |= DF_TEXTREL; | |
6462 | info->callbacks->minfo (_("%B: dynamic relocation in read-only section `%A'\n"), | |
6463 | p->sec->owner, p->sec); | |
6464 | } | |
7fce784e | 6465 | } |
252b5132 | 6466 | } |
252b5132 | 6467 | } |
252b5132 | 6468 | |
25dbc73a AM |
6469 | local_got = elf_local_got_refcounts (ibfd); |
6470 | if (!local_got) | |
6471 | continue; | |
252b5132 | 6472 | |
0ffa91dd | 6473 | symtab_hdr = &elf_symtab_hdr (ibfd); |
25dbc73a AM |
6474 | locsymcount = symtab_hdr->sh_info; |
6475 | end_local_got = local_got + locsymcount; | |
e054468f AM |
6476 | local_plt = (struct plt_entry **) end_local_got; |
6477 | end_local_plt = local_plt + locsymcount; | |
6478 | lgot_masks = (char *) end_local_plt; | |
91d6fa6a | 6479 | |
25dbc73a AM |
6480 | for (; local_got < end_local_got; ++local_got, ++lgot_masks) |
6481 | if (*local_got > 0) | |
6482 | { | |
d6e14abc AM |
6483 | unsigned int need = 0; |
6484 | if ((*lgot_masks & TLS_TLS) != 0) | |
25dbc73a | 6485 | { |
d6e14abc AM |
6486 | if ((*lgot_masks & TLS_GD) != 0) |
6487 | need += 8; | |
6488 | if ((*lgot_masks & TLS_LD) != 0) | |
6489 | htab->tlsld_got.refcount += 1; | |
6490 | if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
6491 | need += 4; | |
6492 | if ((*lgot_masks & TLS_DTPREL) != 0) | |
6493 | need += 4; | |
25dbc73a | 6494 | } |
d6e14abc AM |
6495 | else |
6496 | need += 4; | |
6497 | if (need == 0) | |
6498 | *local_got = (bfd_vma) -1; | |
25dbc73a AM |
6499 | else |
6500 | { | |
3b36f7e6 | 6501 | *local_got = allocate_got (htab, need); |
0e1862bb | 6502 | if (bfd_link_pic (info)) |
0bed072f | 6503 | { |
ce558b89 | 6504 | asection *srel = htab->elf.srelgot; |
0bed072f | 6505 | if ((*lgot_masks & PLT_IFUNC) != 0) |
ce558b89 | 6506 | srel = htab->elf.irelplt; |
0bed072f AM |
6507 | srel->size += need * (sizeof (Elf32_External_Rela) / 4); |
6508 | } | |
25dbc73a AM |
6509 | } |
6510 | } | |
6511 | else | |
6512 | *local_got = (bfd_vma) -1; | |
e054468f AM |
6513 | |
6514 | if (htab->is_vxworks) | |
6515 | continue; | |
6516 | ||
6517 | /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */ | |
6518 | for (; local_plt < end_local_plt; ++local_plt) | |
6519 | { | |
6520 | struct plt_entry *ent; | |
6521 | bfd_boolean doneone = FALSE; | |
6522 | bfd_vma plt_offset = 0, glink_offset = 0; | |
6523 | ||
6524 | for (ent = *local_plt; ent != NULL; ent = ent->next) | |
6525 | if (ent->plt.refcount > 0) | |
6526 | { | |
ce558b89 | 6527 | s = htab->elf.iplt; |
e054468f AM |
6528 | |
6529 | if (!doneone) | |
6530 | { | |
6531 | plt_offset = s->size; | |
6532 | s->size += 4; | |
6533 | } | |
6534 | ent->plt.offset = plt_offset; | |
6535 | ||
6536 | s = htab->glink; | |
0e1862bb | 6537 | if (!doneone || bfd_link_pic (info)) |
e054468f AM |
6538 | { |
6539 | glink_offset = s->size; | |
6540 | s->size += GLINK_ENTRY_SIZE; | |
6541 | } | |
6542 | ent->glink_offset = glink_offset; | |
6543 | ||
6544 | if (!doneone) | |
6545 | { | |
ce558b89 | 6546 | htab->elf.irelplt->size += sizeof (Elf32_External_Rela); |
e054468f AM |
6547 | doneone = TRUE; |
6548 | } | |
6549 | } | |
6550 | else | |
6551 | ent->plt.offset = (bfd_vma) -1; | |
6552 | } | |
25dbc73a | 6553 | } |
252b5132 | 6554 | |
b7fcf6f6 AM |
6555 | /* Allocate space for global sym dynamic relocs. */ |
6556 | elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info); | |
6557 | ||
3b36f7e6 AM |
6558 | if (htab->tlsld_got.refcount > 0) |
6559 | { | |
6560 | htab->tlsld_got.offset = allocate_got (htab, 8); | |
0e1862bb | 6561 | if (bfd_link_pic (info)) |
ce558b89 | 6562 | htab->elf.srelgot->size += sizeof (Elf32_External_Rela); |
3b36f7e6 AM |
6563 | } |
6564 | else | |
6565 | htab->tlsld_got.offset = (bfd_vma) -1; | |
6566 | ||
ce558b89 | 6567 | if (htab->elf.sgot != NULL && htab->plt_type != PLT_VXWORKS) |
3b36f7e6 AM |
6568 | { |
6569 | unsigned int g_o_t = 32768; | |
6570 | ||
4d962050 AM |
6571 | /* If we haven't allocated the header, do so now. When we get here, |
6572 | for old plt/got the got size will be 0 to 32764 (not allocated), | |
6573 | or 32780 to 65536 (header allocated). For new plt/got, the | |
6574 | corresponding ranges are 0 to 32768 and 32780 to 65536. */ | |
ce558b89 | 6575 | if (htab->elf.sgot->size <= 32768) |
3b36f7e6 | 6576 | { |
ce558b89 | 6577 | g_o_t = htab->elf.sgot->size; |
4a3dc543 | 6578 | if (htab->plt_type == PLT_OLD) |
4d962050 | 6579 | g_o_t += 4; |
ce558b89 | 6580 | htab->elf.sgot->size += htab->got_header_size; |
3b36f7e6 | 6581 | } |
3b36f7e6 AM |
6582 | |
6583 | htab->elf.hgot->root.u.def.value = g_o_t; | |
6584 | } | |
0e1862bb | 6585 | if (bfd_link_pic (info)) |
bd6c6e2b AM |
6586 | { |
6587 | struct elf_link_hash_entry *sda = htab->sdata[0].sym; | |
93d1b056 AM |
6588 | |
6589 | sda->root.u.def.section = htab->elf.hgot->root.u.def.section; | |
6590 | sda->root.u.def.value = htab->elf.hgot->root.u.def.value; | |
bd6c6e2b | 6591 | } |
15bfcc77 AM |
6592 | if (info->emitrelocations) |
6593 | { | |
6594 | struct elf_link_hash_entry *sda = htab->sdata[0].sym; | |
6595 | ||
6596 | if (sda != NULL && sda->ref_regular) | |
6597 | sda->root.u.def.section->flags |= SEC_KEEP; | |
6598 | sda = htab->sdata[1].sym; | |
6599 | if (sda != NULL && sda->ref_regular) | |
6600 | sda->root.u.def.section->flags |= SEC_KEEP; | |
6601 | } | |
3b36f7e6 | 6602 | |
e054468f AM |
6603 | if (htab->glink != NULL |
6604 | && htab->glink->size != 0 | |
6605 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
6606 | { |
6607 | htab->glink_pltresolve = htab->glink->size; | |
888a7fc3 AM |
6608 | /* Space for the branch table. ??? We don't need entries for |
6609 | non-dynamic symbols in this table. This case can arise with | |
6610 | static ifuncs or forced local ifuncs. */ | |
86b9da88 AM |
6611 | htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4; |
6612 | /* Pad out to align the start of PLTresolve. */ | |
5446cbdf AM |
6613 | htab->glink->size += -htab->glink->size & (htab->params->ppc476_workaround |
6614 | ? 63 : 15); | |
d7128ce4 | 6615 | htab->glink->size += GLINK_PLTRESOLVE; |
0ba07910 | 6616 | |
5446cbdf | 6617 | if (htab->params->emit_stub_syms) |
0ba07910 AM |
6618 | { |
6619 | struct elf_link_hash_entry *sh; | |
6620 | sh = elf_link_hash_lookup (&htab->elf, "__glink", | |
6621 | TRUE, FALSE, FALSE); | |
6622 | if (sh == NULL) | |
6623 | return FALSE; | |
6624 | if (sh->root.type == bfd_link_hash_new) | |
6625 | { | |
6626 | sh->root.type = bfd_link_hash_defined; | |
6627 | sh->root.u.def.section = htab->glink; | |
6628 | sh->root.u.def.value = htab->glink_pltresolve; | |
6629 | sh->ref_regular = 1; | |
6630 | sh->def_regular = 1; | |
6631 | sh->ref_regular_nonweak = 1; | |
6632 | sh->forced_local = 1; | |
6633 | sh->non_elf = 0; | |
2ec55de3 | 6634 | sh->root.linker_def = 1; |
0ba07910 AM |
6635 | } |
6636 | sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve", | |
6637 | TRUE, FALSE, FALSE); | |
6638 | if (sh == NULL) | |
6639 | return FALSE; | |
6640 | if (sh->root.type == bfd_link_hash_new) | |
6641 | { | |
6642 | sh->root.type = bfd_link_hash_defined; | |
6643 | sh->root.u.def.section = htab->glink; | |
6644 | sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE; | |
6645 | sh->ref_regular = 1; | |
6646 | sh->def_regular = 1; | |
6647 | sh->ref_regular_nonweak = 1; | |
6648 | sh->forced_local = 1; | |
6649 | sh->non_elf = 0; | |
2ec55de3 | 6650 | sh->root.linker_def = 1; |
0ba07910 AM |
6651 | } |
6652 | } | |
d7128ce4 AM |
6653 | } |
6654 | ||
6177242a AM |
6655 | if (htab->glink != NULL |
6656 | && htab->glink->size != 0 | |
6657 | && htab->glink_eh_frame != NULL | |
9a2a56cc AM |
6658 | && !bfd_is_abs_section (htab->glink_eh_frame->output_section) |
6659 | && _bfd_elf_eh_frame_present (info)) | |
6177242a AM |
6660 | { |
6661 | s = htab->glink_eh_frame; | |
6662 | s->size = sizeof (glink_eh_frame_cie) + 20; | |
0e1862bb | 6663 | if (bfd_link_pic (info)) |
6177242a AM |
6664 | { |
6665 | s->size += 4; | |
6666 | if (htab->glink->size - GLINK_PLTRESOLVE + 8 >= 256) | |
6667 | s->size += 4; | |
6668 | } | |
6669 | } | |
6670 | ||
25dbc73a AM |
6671 | /* We've now determined the sizes of the various dynamic sections. |
6672 | Allocate memory for them. */ | |
6673 | relocs = FALSE; | |
6674 | for (s = htab->elf.dynobj->sections; s != NULL; s = s->next) | |
252b5132 | 6675 | { |
9d8504b1 PB |
6676 | bfd_boolean strip_section = TRUE; |
6677 | ||
25dbc73a AM |
6678 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
6679 | continue; | |
252b5132 | 6680 | |
ce558b89 AM |
6681 | if (s == htab->elf.splt |
6682 | || s == htab->elf.sgot) | |
25dbc73a | 6683 | { |
9d8504b1 PB |
6684 | /* We'd like to strip these sections if they aren't needed, but if |
6685 | we've exported dynamic symbols from them we must leave them. | |
6686 | It's too late to tell BFD to get rid of the symbols. */ | |
e054468f | 6687 | if (htab->elf.hplt != NULL) |
9d8504b1 | 6688 | strip_section = FALSE; |
25dbc73a AM |
6689 | /* Strip this section if we don't need it; see the |
6690 | comment below. */ | |
6691 | } | |
ce558b89 | 6692 | else if (s == htab->elf.iplt |
e054468f | 6693 | || s == htab->glink |
6177242a | 6694 | || s == htab->glink_eh_frame |
ce558b89 | 6695 | || s == htab->elf.sgotplt |
e054468f | 6696 | || s == htab->sbss |
9d19e4fd | 6697 | || s == htab->elf.sdynbss |
5474d94f | 6698 | || s == htab->elf.sdynrelro |
15bfcc77 | 6699 | || s == htab->dynsbss) |
25dbc73a | 6700 | { |
c9a2f333 | 6701 | /* Strip these too. */ |
25dbc73a | 6702 | } |
15bfcc77 AM |
6703 | else if (s == htab->sdata[0].section |
6704 | || s == htab->sdata[1].section) | |
6705 | { | |
6706 | strip_section = (s->flags & SEC_KEEP) == 0; | |
6707 | } | |
a0f49396 NC |
6708 | else if (CONST_STRNEQ (bfd_get_section_name (htab->elf.dynobj, s), |
6709 | ".rela")) | |
25dbc73a | 6710 | { |
c456f082 | 6711 | if (s->size != 0) |
25dbc73a AM |
6712 | { |
6713 | /* Remember whether there are any relocation sections. */ | |
6714 | relocs = TRUE; | |
252b5132 | 6715 | |
25dbc73a AM |
6716 | /* We use the reloc_count field as a counter if we need |
6717 | to copy relocs into the output file. */ | |
6718 | s->reloc_count = 0; | |
252b5132 RH |
6719 | } |
6720 | } | |
25dbc73a AM |
6721 | else |
6722 | { | |
6723 | /* It's not one of our sections, so don't allocate space. */ | |
6724 | continue; | |
6725 | } | |
252b5132 | 6726 | |
9d8504b1 | 6727 | if (s->size == 0 && strip_section) |
25dbc73a | 6728 | { |
c456f082 AM |
6729 | /* If we don't need this section, strip it from the |
6730 | output file. This is mostly to handle .rela.bss and | |
6731 | .rela.plt. We must create both sections in | |
6732 | create_dynamic_sections, because they must be created | |
6733 | before the linker maps input sections to output | |
6734 | sections. The linker does that before | |
6735 | adjust_dynamic_symbol is called, and it is that | |
6736 | function which decides whether anything needs to go | |
6737 | into these sections. */ | |
8423293d | 6738 | s->flags |= SEC_EXCLUDE; |
25dbc73a AM |
6739 | continue; |
6740 | } | |
7fce784e | 6741 | |
d7128ce4 | 6742 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
644285ef AM |
6743 | continue; |
6744 | ||
25dbc73a AM |
6745 | /* Allocate memory for the section contents. */ |
6746 | s->contents = bfd_zalloc (htab->elf.dynobj, s->size); | |
6747 | if (s->contents == NULL) | |
6748 | return FALSE; | |
6749 | } | |
252b5132 | 6750 | |
25dbc73a | 6751 | if (htab->elf.dynamic_sections_created) |
7619e7c7 | 6752 | { |
25dbc73a AM |
6753 | /* Add some entries to the .dynamic section. We fill in the |
6754 | values later, in ppc_elf_finish_dynamic_sections, but we | |
6755 | must add the entries now so that we get the correct size for | |
6756 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
6757 | dynamic linker and used by the debugger. */ | |
6758 | #define add_dynamic_entry(TAG, VAL) \ | |
6759 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |
252b5132 | 6760 | |
0e1862bb | 6761 | if (bfd_link_executable (info)) |
7619e7c7 | 6762 | { |
25dbc73a AM |
6763 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
6764 | return FALSE; | |
7619e7c7 AM |
6765 | } |
6766 | ||
ce558b89 | 6767 | if (htab->elf.splt != NULL && htab->elf.splt->size != 0) |
7619e7c7 | 6768 | { |
25dbc73a AM |
6769 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
6770 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
6771 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
6772 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
6773 | return FALSE; | |
6774 | } | |
7619e7c7 | 6775 | |
c7e17e05 AM |
6776 | if (htab->plt_type == PLT_NEW |
6777 | && htab->glink != NULL | |
6778 | && htab->glink->size != 0) | |
d7128ce4 | 6779 | { |
1fe44d79 | 6780 | if (!add_dynamic_entry (DT_PPC_GOT, 0)) |
d7128ce4 | 6781 | return FALSE; |
5446cbdf | 6782 | if (!htab->params->no_tls_get_addr_opt |
a7f2871e AM |
6783 | && htab->tls_get_addr != NULL |
6784 | && htab->tls_get_addr->plt.plist != NULL | |
e8910a83 | 6785 | && !add_dynamic_entry (DT_PPC_OPT, PPC_OPT_TLS)) |
a7f2871e | 6786 | return FALSE; |
d7128ce4 AM |
6787 | } |
6788 | ||
25dbc73a AM |
6789 | if (relocs) |
6790 | { | |
6791 | if (!add_dynamic_entry (DT_RELA, 0) | |
6792 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6793 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
6794 | return FALSE; | |
6795 | } | |
7619e7c7 | 6796 | |
25dbc73a AM |
6797 | /* If any dynamic relocs apply to a read-only section, then we |
6798 | need a DT_TEXTREL entry. */ | |
6799 | if ((info->flags & DF_TEXTREL) == 0) | |
625af618 | 6800 | elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel, |
25dbc73a | 6801 | info); |
7619e7c7 | 6802 | |
25dbc73a AM |
6803 | if ((info->flags & DF_TEXTREL) != 0) |
6804 | { | |
6805 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
6806 | return FALSE; | |
7619e7c7 | 6807 | } |
7a2b07ff NS |
6808 | if (htab->is_vxworks |
6809 | && !elf_vxworks_add_dynamic_entries (output_bfd, info)) | |
6810 | return FALSE; | |
6811 | } | |
25dbc73a AM |
6812 | #undef add_dynamic_entry |
6813 | ||
7e01508c AM |
6814 | if (htab->glink_eh_frame != NULL |
6815 | && htab->glink_eh_frame->contents != NULL) | |
6816 | { | |
6817 | unsigned char *p = htab->glink_eh_frame->contents; | |
6818 | bfd_vma val; | |
6819 | ||
6820 | memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie)); | |
6821 | /* CIE length (rewrite in case little-endian). */ | |
6822 | bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p); | |
6823 | p += sizeof (glink_eh_frame_cie); | |
6824 | /* FDE length. */ | |
6825 | val = htab->glink_eh_frame->size - 4 - sizeof (glink_eh_frame_cie); | |
6826 | bfd_put_32 (htab->elf.dynobj, val, p); | |
6827 | p += 4; | |
6828 | /* CIE pointer. */ | |
6829 | val = p - htab->glink_eh_frame->contents; | |
6830 | bfd_put_32 (htab->elf.dynobj, val, p); | |
6831 | p += 4; | |
6832 | /* Offset to .glink. Set later. */ | |
6833 | p += 4; | |
6834 | /* .glink size. */ | |
6835 | bfd_put_32 (htab->elf.dynobj, htab->glink->size, p); | |
6836 | p += 4; | |
6837 | /* Augmentation. */ | |
6838 | p += 1; | |
6839 | ||
0e1862bb | 6840 | if (bfd_link_pic (info) |
7e01508c AM |
6841 | && htab->elf.dynamic_sections_created) |
6842 | { | |
6843 | bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2; | |
6844 | if (adv < 64) | |
6845 | *p++ = DW_CFA_advance_loc + adv; | |
6846 | else if (adv < 256) | |
6847 | { | |
6848 | *p++ = DW_CFA_advance_loc1; | |
6849 | *p++ = adv; | |
6850 | } | |
6851 | else if (adv < 65536) | |
6852 | { | |
6853 | *p++ = DW_CFA_advance_loc2; | |
6854 | bfd_put_16 (htab->elf.dynobj, adv, p); | |
6855 | p += 2; | |
6856 | } | |
6857 | else | |
6858 | { | |
6859 | *p++ = DW_CFA_advance_loc4; | |
6860 | bfd_put_32 (htab->elf.dynobj, adv, p); | |
6861 | p += 4; | |
6862 | } | |
6863 | *p++ = DW_CFA_register; | |
6864 | *p++ = 65; | |
6865 | p++; | |
6866 | *p++ = DW_CFA_advance_loc + 4; | |
6867 | *p++ = DW_CFA_restore_extended; | |
6868 | *p++ = 65; | |
6869 | } | |
6870 | BFD_ASSERT ((bfd_vma) ((p + 3 - htab->glink_eh_frame->contents) & -4) | |
6871 | == htab->glink_eh_frame->size); | |
6872 | } | |
6873 | ||
7619e7c7 AM |
6874 | return TRUE; |
6875 | } | |
0eb4a168 | 6876 | |
93d1b056 AM |
6877 | /* Arrange to have _SDA_BASE_ or _SDA2_BASE_ stripped from the output |
6878 | if it looks like nothing is using them. */ | |
6879 | ||
6880 | static void | |
6881 | maybe_strip_sdasym (bfd *output_bfd, elf_linker_section_t *lsect) | |
6882 | { | |
6883 | struct elf_link_hash_entry *sda = lsect->sym; | |
6884 | ||
6885 | if (sda != NULL && !sda->ref_regular && sda->dynindx == -1) | |
6886 | { | |
6887 | asection *s; | |
6888 | ||
6889 | s = bfd_get_section_by_name (output_bfd, lsect->name); | |
6890 | if (s == NULL || bfd_section_removed_from_list (output_bfd, s)) | |
6891 | { | |
6892 | s = bfd_get_section_by_name (output_bfd, lsect->bss_name); | |
6893 | if (s == NULL || bfd_section_removed_from_list (output_bfd, s)) | |
6894 | { | |
6895 | sda->def_regular = 0; | |
6896 | /* This is somewhat magic. See elf_link_output_extsym. */ | |
6897 | sda->ref_dynamic = 1; | |
6898 | sda->forced_local = 0; | |
6899 | } | |
6900 | } | |
6901 | } | |
6902 | } | |
6903 | ||
6904 | void | |
6905 | ppc_elf_maybe_strip_sdata_syms (struct bfd_link_info *info) | |
6906 | { | |
6907 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
6908 | ||
6909 | if (htab != NULL) | |
6910 | { | |
6911 | maybe_strip_sdasym (info->output_bfd, &htab->sdata[0]); | |
6912 | maybe_strip_sdasym (info->output_bfd, &htab->sdata[1]); | |
6913 | } | |
6914 | } | |
6915 | ||
6916 | ||
0eb4a168 AM |
6917 | /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ |
6918 | ||
6919 | static bfd_boolean | |
6920 | ppc_elf_hash_symbol (struct elf_link_hash_entry *h) | |
6921 | { | |
6922 | if (h->plt.plist != NULL | |
6923 | && !h->def_regular | |
6924 | && (!h->pointer_equality_needed | |
6925 | || !h->ref_regular_nonweak)) | |
6926 | return FALSE; | |
6927 | ||
6928 | return _bfd_elf_hash_symbol (h); | |
6929 | } | |
25dbc73a AM |
6930 | \f |
6931 | #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) | |
6932 | ||
01017ef8 NS |
6933 | /* Relaxation trampolines. r12 is available for clobbering (r11, is |
6934 | used for some functions that are allowed to break the ABI). */ | |
25dbc73a AM |
6935 | static const int shared_stub_entry[] = |
6936 | { | |
6937 | 0x7c0802a6, /* mflr 0 */ | |
6938 | 0x429f0005, /* bcl 20, 31, .Lxxx */ | |
01017ef8 NS |
6939 | 0x7d8802a6, /* mflr 12 */ |
6940 | 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */ | |
53291d1f | 6941 | 0x398c0000, /* addi 12, 12, (xxx-.Lxxx)@l */ |
25dbc73a | 6942 | 0x7c0803a6, /* mtlr 0 */ |
01017ef8 | 6943 | 0x7d8903a6, /* mtctr 12 */ |
25dbc73a AM |
6944 | 0x4e800420, /* bctr */ |
6945 | }; | |
6946 | ||
6947 | static const int stub_entry[] = | |
6948 | { | |
01017ef8 NS |
6949 | 0x3d800000, /* lis 12,xxx@ha */ |
6950 | 0x398c0000, /* addi 12,12,xxx@l */ | |
6951 | 0x7d8903a6, /* mtctr 12 */ | |
25dbc73a AM |
6952 | 0x4e800420, /* bctr */ |
6953 | }; | |
6954 | ||
5446cbdf AM |
6955 | struct ppc_elf_relax_info |
6956 | { | |
6957 | unsigned int workaround_size; | |
d3e454b9 | 6958 | unsigned int picfixup_size; |
5446cbdf AM |
6959 | }; |
6960 | ||
6961 | /* This function implements long branch trampolines, and the ppc476 | |
6962 | icache bug workaround. Any section needing trampolines or patch | |
6963 | space for the workaround has its size extended so that we can | |
53291d1f | 6964 | add trampolines at the end of the section. */ |
5446cbdf | 6965 | |
25dbc73a AM |
6966 | static bfd_boolean |
6967 | ppc_elf_relax_section (bfd *abfd, | |
6968 | asection *isec, | |
6969 | struct bfd_link_info *link_info, | |
6970 | bfd_boolean *again) | |
6971 | { | |
d3e454b9 | 6972 | struct one_branch_fixup |
25dbc73a | 6973 | { |
d3e454b9 | 6974 | struct one_branch_fixup *next; |
25dbc73a | 6975 | asection *tsec; |
01017ef8 NS |
6976 | /* Final link, can use the symbol offset. For a |
6977 | relocatable link we use the symbol's index. */ | |
25dbc73a AM |
6978 | bfd_vma toff; |
6979 | bfd_vma trampoff; | |
6980 | }; | |
7619e7c7 | 6981 | |
25dbc73a AM |
6982 | Elf_Internal_Shdr *symtab_hdr; |
6983 | bfd_byte *contents = NULL; | |
6984 | Elf_Internal_Sym *isymbuf = NULL; | |
6985 | Elf_Internal_Rela *internal_relocs = NULL; | |
5446cbdf | 6986 | Elf_Internal_Rela *irel, *irelend = NULL; |
d3e454b9 | 6987 | struct one_branch_fixup *branch_fixups = NULL; |
5446cbdf | 6988 | struct ppc_elf_relax_info *relax_info = NULL; |
9bc4e62b | 6989 | unsigned changes = 0; |
5446cbdf | 6990 | bfd_boolean workaround_change; |
d7128ce4 | 6991 | struct ppc_elf_link_hash_table *htab; |
d3e454b9 | 6992 | bfd_size_type trampbase, trampoff, newsize, picfixup_size; |
a6aa5195 | 6993 | asection *got2; |
50248c89 | 6994 | bfd_boolean maybe_pasted; |
7619e7c7 | 6995 | |
25dbc73a | 6996 | *again = FALSE; |
7619e7c7 | 6997 | |
5446cbdf | 6998 | /* No need to do anything with non-alloc or non-code sections. */ |
c87b5a93 | 6999 | if ((isec->flags & SEC_ALLOC) == 0 |
a8ad78a7 | 7000 | || (isec->flags & SEC_CODE) == 0 |
5446cbdf AM |
7001 | || (isec->flags & SEC_LINKER_CREATED) != 0 |
7002 | || isec->size < 4) | |
25dbc73a | 7003 | return TRUE; |
7619e7c7 | 7004 | |
c8a1f254 NS |
7005 | /* We cannot represent the required PIC relocs in the output, so don't |
7006 | do anything. The linker doesn't support mixing -shared and -r | |
7007 | anyway. */ | |
0e1862bb | 7008 | if (bfd_link_relocatable (link_info) && bfd_link_pic (link_info)) |
795bc6b3 | 7009 | return TRUE; |
5b914448 | 7010 | |
5446cbdf AM |
7011 | htab = ppc_elf_hash_table (link_info); |
7012 | if (htab == NULL) | |
7013 | return TRUE; | |
7014 | ||
7015 | isec->size = (isec->size + 3) & -4; | |
7016 | if (isec->rawsize == 0) | |
7017 | isec->rawsize = isec->size; | |
7018 | trampbase = isec->size; | |
7019 | ||
53291d1f AM |
7020 | BFD_ASSERT (isec->sec_info_type == SEC_INFO_TYPE_NONE |
7021 | || isec->sec_info_type == SEC_INFO_TYPE_TARGET); | |
7022 | isec->sec_info_type = SEC_INFO_TYPE_TARGET; | |
7023 | ||
d3e454b9 AM |
7024 | if (htab->params->ppc476_workaround |
7025 | || htab->params->pic_fixup > 0) | |
5446cbdf AM |
7026 | { |
7027 | if (elf_section_data (isec)->sec_info == NULL) | |
7028 | { | |
5446cbdf AM |
7029 | elf_section_data (isec)->sec_info |
7030 | = bfd_zalloc (abfd, sizeof (struct ppc_elf_relax_info)); | |
7031 | if (elf_section_data (isec)->sec_info == NULL) | |
7032 | return FALSE; | |
7033 | } | |
7034 | relax_info = elf_section_data (isec)->sec_info; | |
7035 | trampbase -= relax_info->workaround_size; | |
7036 | } | |
7037 | ||
50248c89 AM |
7038 | maybe_pasted = (strcmp (isec->output_section->name, ".init") == 0 |
7039 | || strcmp (isec->output_section->name, ".fini") == 0); | |
25dbc73a | 7040 | /* Space for a branch around any trampolines. */ |
5446cbdf AM |
7041 | trampoff = trampbase; |
7042 | if (maybe_pasted && trampbase == isec->rawsize) | |
50248c89 | 7043 | trampoff += 4; |
7619e7c7 | 7044 | |
0ffa91dd | 7045 | symtab_hdr = &elf_symtab_hdr (abfd); |
d3e454b9 AM |
7046 | picfixup_size = 0; |
7047 | if (htab->params->branch_trampolines | |
7048 | || htab->params->pic_fixup > 0) | |
7619e7c7 | 7049 | { |
5446cbdf AM |
7050 | /* Get a copy of the native relocations. */ |
7051 | if (isec->reloc_count != 0) | |
25dbc73a | 7052 | { |
5446cbdf AM |
7053 | internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, |
7054 | link_info->keep_memory); | |
7055 | if (internal_relocs == NULL) | |
7056 | goto error_return; | |
25dbc73a | 7057 | } |
7619e7c7 | 7058 | |
5446cbdf AM |
7059 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
7060 | ||
7061 | irelend = internal_relocs + isec->reloc_count; | |
7062 | for (irel = internal_relocs; irel < irelend; irel++) | |
25dbc73a | 7063 | { |
5446cbdf AM |
7064 | unsigned long r_type = ELF32_R_TYPE (irel->r_info); |
7065 | bfd_vma toff, roff; | |
7066 | asection *tsec; | |
d3e454b9 | 7067 | struct one_branch_fixup *f; |
5446cbdf | 7068 | size_t insn_offset = 0; |
d3e454b9 | 7069 | bfd_vma max_branch_offset = 0, val; |
5446cbdf AM |
7070 | bfd_byte *hit_addr; |
7071 | unsigned long t0; | |
7072 | struct elf_link_hash_entry *h; | |
7073 | struct plt_entry **plist; | |
7074 | unsigned char sym_type; | |
7075 | ||
7076 | switch (r_type) | |
7077 | { | |
7078 | case R_PPC_REL24: | |
7079 | case R_PPC_LOCAL24PC: | |
7080 | case R_PPC_PLTREL24: | |
7081 | max_branch_offset = 1 << 25; | |
7082 | break; | |
7083 | ||
7084 | case R_PPC_REL14: | |
7085 | case R_PPC_REL14_BRTAKEN: | |
7086 | case R_PPC_REL14_BRNTAKEN: | |
7087 | max_branch_offset = 1 << 15; | |
7088 | break; | |
7fce784e | 7089 | |
d3e454b9 AM |
7090 | case R_PPC_ADDR16_HA: |
7091 | if (htab->params->pic_fixup > 0) | |
7092 | break; | |
7093 | continue; | |
7094 | ||
5446cbdf AM |
7095 | default: |
7096 | continue; | |
7097 | } | |
7098 | ||
7099 | /* Get the value of the symbol referred to by the reloc. */ | |
7100 | h = NULL; | |
7101 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) | |
25dbc73a | 7102 | { |
5446cbdf AM |
7103 | /* A local symbol. */ |
7104 | Elf_Internal_Sym *isym; | |
7105 | ||
7106 | /* Read this BFD's local symbols. */ | |
25dbc73a | 7107 | if (isymbuf == NULL) |
5446cbdf AM |
7108 | { |
7109 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
7110 | if (isymbuf == NULL) | |
7111 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
7112 | symtab_hdr->sh_info, 0, | |
7113 | NULL, NULL, NULL); | |
7114 | if (isymbuf == 0) | |
7115 | goto error_return; | |
7116 | } | |
7117 | isym = isymbuf + ELF32_R_SYM (irel->r_info); | |
7118 | if (isym->st_shndx == SHN_UNDEF) | |
7119 | tsec = bfd_und_section_ptr; | |
7120 | else if (isym->st_shndx == SHN_ABS) | |
7121 | tsec = bfd_abs_section_ptr; | |
7122 | else if (isym->st_shndx == SHN_COMMON) | |
7123 | tsec = bfd_com_section_ptr; | |
7124 | else | |
7125 | tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
7126 | ||
7127 | toff = isym->st_value; | |
7128 | sym_type = ELF_ST_TYPE (isym->st_info); | |
25dbc73a | 7129 | } |
25dbc73a | 7130 | else |
5446cbdf AM |
7131 | { |
7132 | /* Global symbol handling. */ | |
7133 | unsigned long indx; | |
7fce784e | 7134 | |
5446cbdf AM |
7135 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
7136 | h = elf_sym_hashes (abfd)[indx]; | |
7619e7c7 | 7137 | |
5446cbdf AM |
7138 | while (h->root.type == bfd_link_hash_indirect |
7139 | || h->root.type == bfd_link_hash_warning) | |
7140 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 7141 | |
5446cbdf AM |
7142 | if (h->root.type == bfd_link_hash_defined |
7143 | || h->root.type == bfd_link_hash_defweak) | |
7144 | { | |
7145 | tsec = h->root.u.def.section; | |
7146 | toff = h->root.u.def.value; | |
7147 | } | |
7148 | else if (h->root.type == bfd_link_hash_undefined | |
7149 | || h->root.type == bfd_link_hash_undefweak) | |
7150 | { | |
7151 | tsec = bfd_und_section_ptr; | |
0e1862bb | 7152 | toff = bfd_link_relocatable (link_info) ? indx : 0; |
5446cbdf AM |
7153 | } |
7154 | else | |
7155 | continue; | |
7156 | ||
9f7552cf AM |
7157 | /* If this branch is to __tls_get_addr then we may later |
7158 | optimise away the call. We won't be needing a long- | |
7159 | branch stub in that case. */ | |
0e1862bb | 7160 | if (bfd_link_executable (link_info) |
9f7552cf AM |
7161 | && h == htab->tls_get_addr |
7162 | && irel != internal_relocs) | |
7163 | { | |
7164 | unsigned long t_symndx = ELF32_R_SYM (irel[-1].r_info); | |
7165 | unsigned long t_rtype = ELF32_R_TYPE (irel[-1].r_info); | |
7166 | unsigned int tls_mask = 0; | |
7167 | ||
7168 | /* The previous reloc should be one of R_PPC_TLSGD or | |
7169 | R_PPC_TLSLD, or for older object files, a reloc | |
7170 | on the __tls_get_addr arg setup insn. Get tls | |
7171 | mask bits from the symbol on that reloc. */ | |
7172 | if (t_symndx < symtab_hdr->sh_info) | |
7173 | { | |
7174 | bfd_vma *local_got_offsets = elf_local_got_offsets (abfd); | |
7175 | ||
7176 | if (local_got_offsets != NULL) | |
7177 | { | |
7178 | struct plt_entry **local_plt = (struct plt_entry **) | |
7179 | (local_got_offsets + symtab_hdr->sh_info); | |
7180 | char *lgot_masks = (char *) | |
7181 | (local_plt + symtab_hdr->sh_info); | |
7182 | tls_mask = lgot_masks[t_symndx]; | |
7183 | } | |
7184 | } | |
7185 | else | |
7186 | { | |
7187 | struct elf_link_hash_entry *th | |
7188 | = elf_sym_hashes (abfd)[t_symndx - symtab_hdr->sh_info]; | |
7189 | ||
7190 | while (th->root.type == bfd_link_hash_indirect | |
7191 | || th->root.type == bfd_link_hash_warning) | |
7192 | th = (struct elf_link_hash_entry *) th->root.u.i.link; | |
7193 | ||
7194 | tls_mask | |
7195 | = ((struct ppc_elf_link_hash_entry *) th)->tls_mask; | |
7196 | } | |
7197 | ||
7198 | /* The mask bits tell us if the call will be | |
7199 | optimised away. */ | |
7200 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0 | |
7201 | && (t_rtype == R_PPC_TLSGD | |
7202 | || t_rtype == R_PPC_GOT_TLSGD16 | |
7203 | || t_rtype == R_PPC_GOT_TLSGD16_LO)) | |
7204 | continue; | |
7205 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0 | |
7206 | && (t_rtype == R_PPC_TLSLD | |
7207 | || t_rtype == R_PPC_GOT_TLSLD16 | |
7208 | || t_rtype == R_PPC_GOT_TLSLD16_LO)) | |
7209 | continue; | |
7210 | } | |
7211 | ||
5446cbdf AM |
7212 | sym_type = h->type; |
7213 | } | |
7619e7c7 | 7214 | |
d3e454b9 AM |
7215 | if (r_type == R_PPC_ADDR16_HA) |
7216 | { | |
7217 | if (h != NULL | |
7218 | && !h->def_regular | |
7219 | && h->protected_def | |
7220 | && ppc_elf_hash_entry (h)->has_addr16_ha | |
7221 | && ppc_elf_hash_entry (h)->has_addr16_lo) | |
7222 | picfixup_size += 12; | |
7223 | continue; | |
7224 | } | |
7225 | ||
5446cbdf AM |
7226 | /* The condition here under which we call find_plt_ent must |
7227 | match that in relocate_section. If we call find_plt_ent here | |
7228 | but not in relocate_section, or vice versa, then the branch | |
7229 | destination used here may be incorrect. */ | |
7230 | plist = NULL; | |
7231 | if (h != NULL) | |
25dbc73a | 7232 | { |
5446cbdf AM |
7233 | /* We know is_branch_reloc (r_type) is true. */ |
7234 | if (h->type == STT_GNU_IFUNC | |
7235 | || r_type == R_PPC_PLTREL24) | |
7236 | plist = &h->plt.plist; | |
25dbc73a | 7237 | } |
5446cbdf AM |
7238 | else if (sym_type == STT_GNU_IFUNC |
7239 | && elf_local_got_offsets (abfd) != NULL) | |
c8a1f254 | 7240 | { |
5446cbdf AM |
7241 | bfd_vma *local_got_offsets = elf_local_got_offsets (abfd); |
7242 | struct plt_entry **local_plt = (struct plt_entry **) | |
7243 | (local_got_offsets + symtab_hdr->sh_info); | |
7244 | plist = local_plt + ELF32_R_SYM (irel->r_info); | |
c8a1f254 | 7245 | } |
5446cbdf | 7246 | if (plist != NULL) |
a9585d22 | 7247 | { |
5446cbdf AM |
7248 | bfd_vma addend = 0; |
7249 | struct plt_entry *ent; | |
7250 | ||
0e1862bb | 7251 | if (r_type == R_PPC_PLTREL24 && bfd_link_pic (link_info)) |
5446cbdf AM |
7252 | addend = irel->r_addend; |
7253 | ent = find_plt_ent (plist, got2, addend); | |
7254 | if (ent != NULL) | |
a9585d22 | 7255 | { |
5446cbdf AM |
7256 | if (htab->plt_type == PLT_NEW |
7257 | || h == NULL | |
7258 | || !htab->elf.dynamic_sections_created | |
7259 | || h->dynindx == -1) | |
7260 | { | |
7261 | tsec = htab->glink; | |
7262 | toff = ent->glink_offset; | |
7263 | } | |
7264 | else | |
7265 | { | |
ce558b89 | 7266 | tsec = htab->elf.splt; |
5446cbdf AM |
7267 | toff = ent->plt.offset; |
7268 | } | |
de972ffa AM |
7269 | } |
7270 | } | |
de972ffa | 7271 | |
5446cbdf AM |
7272 | /* If the branch and target are in the same section, you have |
7273 | no hope of adding stubs. We'll error out later should the | |
7274 | branch overflow. */ | |
7275 | if (tsec == isec) | |
7276 | continue; | |
25dbc73a | 7277 | |
5446cbdf AM |
7278 | /* There probably isn't any reason to handle symbols in |
7279 | SEC_MERGE sections; SEC_MERGE doesn't seem a likely | |
7280 | attribute for a code section, and we are only looking at | |
7281 | branches. However, implement it correctly here as a | |
7282 | reference for other target relax_section functions. */ | |
7283 | if (0 && tsec->sec_info_type == SEC_INFO_TYPE_MERGE) | |
7284 | { | |
7285 | /* At this stage in linking, no SEC_MERGE symbol has been | |
7286 | adjusted, so all references to such symbols need to be | |
7287 | passed through _bfd_merged_section_offset. (Later, in | |
7288 | relocate_section, all SEC_MERGE symbols *except* for | |
7289 | section symbols have been adjusted.) | |
7290 | ||
7291 | gas may reduce relocations against symbols in SEC_MERGE | |
7292 | sections to a relocation against the section symbol when | |
7293 | the original addend was zero. When the reloc is against | |
7294 | a section symbol we should include the addend in the | |
7295 | offset passed to _bfd_merged_section_offset, since the | |
7296 | location of interest is the original symbol. On the | |
7297 | other hand, an access to "sym+addend" where "sym" is not | |
7298 | a section symbol should not include the addend; Such an | |
7299 | access is presumed to be an offset from "sym"; The | |
7300 | location of interest is just "sym". */ | |
7301 | if (sym_type == STT_SECTION) | |
7302 | toff += irel->r_addend; | |
7303 | ||
7304 | toff | |
7305 | = _bfd_merged_section_offset (abfd, &tsec, | |
7306 | elf_section_data (tsec)->sec_info, | |
7307 | toff); | |
7308 | ||
7309 | if (sym_type != STT_SECTION) | |
7310 | toff += irel->r_addend; | |
7311 | } | |
7312 | /* PLTREL24 addends are special. */ | |
7313 | else if (r_type != R_PPC_PLTREL24) | |
25dbc73a | 7314 | toff += irel->r_addend; |
7619e7c7 | 7315 | |
5446cbdf | 7316 | /* Attempted -shared link of non-pic code loses. */ |
0e1862bb | 7317 | if ((!bfd_link_relocatable (link_info) |
5446cbdf AM |
7318 | && tsec == bfd_und_section_ptr) |
7319 | || tsec->output_section == NULL | |
7320 | || (tsec->owner != NULL | |
7321 | && (tsec->owner->flags & BFD_PLUGIN) != 0)) | |
7322 | continue; | |
7619e7c7 | 7323 | |
5446cbdf | 7324 | roff = irel->r_offset; |
7de713b9 | 7325 | |
5446cbdf AM |
7326 | /* If the branch is in range, no need to do anything. */ |
7327 | if (tsec != bfd_und_section_ptr | |
0e1862bb | 7328 | && (!bfd_link_relocatable (link_info) |
5446cbdf AM |
7329 | /* A relocatable link may have sections moved during |
7330 | final link, so do not presume they remain in range. */ | |
7331 | || tsec->output_section == isec->output_section)) | |
7332 | { | |
7333 | bfd_vma symaddr, reladdr; | |
7619e7c7 | 7334 | |
5446cbdf AM |
7335 | symaddr = tsec->output_section->vma + tsec->output_offset + toff; |
7336 | reladdr = isec->output_section->vma + isec->output_offset + roff; | |
7337 | if (symaddr - reladdr + max_branch_offset | |
7338 | < 2 * max_branch_offset) | |
7339 | continue; | |
7340 | } | |
01017ef8 | 7341 | |
5446cbdf | 7342 | /* Look for an existing fixup to this address. */ |
d3e454b9 | 7343 | for (f = branch_fixups; f ; f = f->next) |
5446cbdf AM |
7344 | if (f->tsec == tsec && f->toff == toff) |
7345 | break; | |
252b5132 | 7346 | |
5446cbdf AM |
7347 | if (f == NULL) |
7348 | { | |
7349 | size_t size; | |
7350 | unsigned long stub_rtype; | |
25dbc73a | 7351 | |
5446cbdf AM |
7352 | val = trampoff - roff; |
7353 | if (val >= max_branch_offset) | |
7354 | /* Oh dear, we can't reach a trampoline. Don't try to add | |
7355 | one. We'll report an error later. */ | |
7356 | continue; | |
252b5132 | 7357 | |
0e1862bb | 7358 | if (bfd_link_pic (link_info)) |
5446cbdf AM |
7359 | { |
7360 | size = 4 * ARRAY_SIZE (shared_stub_entry); | |
7361 | insn_offset = 12; | |
7362 | } | |
7363 | else | |
7364 | { | |
7365 | size = 4 * ARRAY_SIZE (stub_entry); | |
7366 | insn_offset = 0; | |
7367 | } | |
7368 | stub_rtype = R_PPC_RELAX; | |
ce558b89 | 7369 | if (tsec == htab->elf.splt |
5446cbdf AM |
7370 | || tsec == htab->glink) |
7371 | { | |
7372 | stub_rtype = R_PPC_RELAX_PLT; | |
7373 | if (r_type == R_PPC_PLTREL24) | |
7374 | stub_rtype = R_PPC_RELAX_PLTREL24; | |
7375 | } | |
252b5132 | 7376 | |
5446cbdf AM |
7377 | /* Hijack the old relocation. Since we need two |
7378 | relocations for this use a "composite" reloc. */ | |
7379 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
7380 | stub_rtype); | |
7381 | irel->r_offset = trampoff + insn_offset; | |
7382 | if (r_type == R_PPC_PLTREL24 | |
7383 | && stub_rtype != R_PPC_RELAX_PLTREL24) | |
7384 | irel->r_addend = 0; | |
7385 | ||
7386 | /* Record the fixup so we don't do it again this section. */ | |
7387 | f = bfd_malloc (sizeof (*f)); | |
d3e454b9 | 7388 | f->next = branch_fixups; |
5446cbdf AM |
7389 | f->tsec = tsec; |
7390 | f->toff = toff; | |
7391 | f->trampoff = trampoff; | |
d3e454b9 | 7392 | branch_fixups = f; |
5446cbdf AM |
7393 | |
7394 | trampoff += size; | |
7395 | changes++; | |
25dbc73a AM |
7396 | } |
7397 | else | |
7398 | { | |
5446cbdf AM |
7399 | val = f->trampoff - roff; |
7400 | if (val >= max_branch_offset) | |
7401 | continue; | |
252b5132 | 7402 | |
5446cbdf AM |
7403 | /* Nop out the reloc, since we're finalizing things here. */ |
7404 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
7405 | } | |
252b5132 | 7406 | |
5446cbdf AM |
7407 | /* Get the section contents. */ |
7408 | if (contents == NULL) | |
25dbc73a | 7409 | { |
5446cbdf AM |
7410 | /* Get cached copy if it exists. */ |
7411 | if (elf_section_data (isec)->this_hdr.contents != NULL) | |
7412 | contents = elf_section_data (isec)->this_hdr.contents; | |
25dbc73a | 7413 | /* Go get them off disk. */ |
5446cbdf | 7414 | else if (!bfd_malloc_and_get_section (abfd, isec, &contents)) |
25dbc73a AM |
7415 | goto error_return; |
7416 | } | |
252b5132 | 7417 | |
5446cbdf AM |
7418 | /* Fix up the existing branch to hit the trampoline. */ |
7419 | hit_addr = contents + roff; | |
7420 | switch (r_type) | |
7421 | { | |
7422 | case R_PPC_REL24: | |
7423 | case R_PPC_LOCAL24PC: | |
7424 | case R_PPC_PLTREL24: | |
7425 | t0 = bfd_get_32 (abfd, hit_addr); | |
7426 | t0 &= ~0x3fffffc; | |
7427 | t0 |= val & 0x3fffffc; | |
7428 | bfd_put_32 (abfd, t0, hit_addr); | |
7429 | break; | |
252b5132 | 7430 | |
5446cbdf AM |
7431 | case R_PPC_REL14: |
7432 | case R_PPC_REL14_BRTAKEN: | |
7433 | case R_PPC_REL14_BRNTAKEN: | |
7434 | t0 = bfd_get_32 (abfd, hit_addr); | |
7435 | t0 &= ~0xfffc; | |
7436 | t0 |= val & 0xfffc; | |
7437 | bfd_put_32 (abfd, t0, hit_addr); | |
7438 | break; | |
7439 | } | |
25dbc73a | 7440 | } |
252b5132 | 7441 | |
d3e454b9 | 7442 | while (branch_fixups != NULL) |
25dbc73a | 7443 | { |
d3e454b9 AM |
7444 | struct one_branch_fixup *f = branch_fixups; |
7445 | branch_fixups = branch_fixups->next; | |
25dbc73a AM |
7446 | free (f); |
7447 | } | |
5446cbdf | 7448 | } |
252b5132 | 7449 | |
5446cbdf AM |
7450 | workaround_change = FALSE; |
7451 | newsize = trampoff; | |
795bc6b3 | 7452 | if (htab->params->ppc476_workaround |
0e1862bb | 7453 | && (!bfd_link_relocatable (link_info) |
795bc6b3 | 7454 | || isec->output_section->alignment_power >= htab->params->pagesize_p2)) |
5446cbdf AM |
7455 | { |
7456 | bfd_vma addr, end_addr; | |
7457 | unsigned int crossings; | |
795bc6b3 | 7458 | bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2; |
5446cbdf AM |
7459 | |
7460 | addr = isec->output_section->vma + isec->output_offset; | |
6128f9cf | 7461 | end_addr = addr + trampoff; |
5446cbdf | 7462 | addr &= -pagesize; |
795bc6b3 | 7463 | crossings = ((end_addr & -pagesize) - addr) >> htab->params->pagesize_p2; |
5446cbdf AM |
7464 | if (crossings != 0) |
7465 | { | |
7466 | /* Keep space aligned, to ensure the patch code itself does | |
7467 | not cross a page. Don't decrease size calculated on a | |
7468 | previous pass as otherwise we might never settle on a layout. */ | |
1e269e9b | 7469 | newsize = 15 - ((end_addr - 1) & 15); |
5446cbdf AM |
7470 | newsize += crossings * 16; |
7471 | if (relax_info->workaround_size < newsize) | |
7472 | { | |
7473 | relax_info->workaround_size = newsize; | |
7474 | workaround_change = TRUE; | |
5446cbdf AM |
7475 | } |
7476 | /* Ensure relocate_section is called. */ | |
7477 | isec->flags |= SEC_RELOC; | |
7478 | } | |
7479 | newsize = trampoff + relax_info->workaround_size; | |
7480 | } | |
7481 | ||
d3e454b9 AM |
7482 | if (htab->params->pic_fixup > 0) |
7483 | { | |
7484 | picfixup_size -= relax_info->picfixup_size; | |
7485 | if (picfixup_size != 0) | |
7486 | relax_info->picfixup_size += picfixup_size; | |
7487 | newsize += relax_info->picfixup_size; | |
7488 | } | |
7489 | ||
7490 | if (changes != 0 || picfixup_size != 0 || workaround_change) | |
5446cbdf AM |
7491 | isec->size = newsize; |
7492 | ||
25dbc73a AM |
7493 | if (isymbuf != NULL |
7494 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
252b5132 | 7495 | { |
25dbc73a AM |
7496 | if (! link_info->keep_memory) |
7497 | free (isymbuf); | |
252b5132 | 7498 | else |
25dbc73a AM |
7499 | { |
7500 | /* Cache the symbols for elf_link_input_bfd. */ | |
7501 | symtab_hdr->contents = (unsigned char *) isymbuf; | |
7502 | } | |
252b5132 RH |
7503 | } |
7504 | ||
25dbc73a AM |
7505 | if (contents != NULL |
7506 | && elf_section_data (isec)->this_hdr.contents != contents) | |
7507 | { | |
53291d1f | 7508 | if (!changes && !link_info->keep_memory) |
25dbc73a AM |
7509 | free (contents); |
7510 | else | |
7511 | { | |
7512 | /* Cache the section contents for elf_link_input_bfd. */ | |
7513 | elf_section_data (isec)->this_hdr.contents = contents; | |
7514 | } | |
7515 | } | |
252b5132 | 7516 | |
d3e454b9 | 7517 | changes += picfixup_size; |
9bc4e62b | 7518 | if (changes != 0) |
25dbc73a | 7519 | { |
9bc4e62b NS |
7520 | /* Append sufficient NOP relocs so we can write out relocation |
7521 | information for the trampolines. */ | |
d4730f92 | 7522 | Elf_Internal_Shdr *rel_hdr; |
9bc4e62b NS |
7523 | Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count) |
7524 | * sizeof (*new_relocs)); | |
7525 | unsigned ix; | |
5b914448 | 7526 | |
9bc4e62b NS |
7527 | if (!new_relocs) |
7528 | goto error_return; | |
7529 | memcpy (new_relocs, internal_relocs, | |
7530 | isec->reloc_count * sizeof (*new_relocs)); | |
7531 | for (ix = changes; ix--;) | |
7532 | { | |
7533 | irel = new_relocs + ix + isec->reloc_count; | |
7534 | ||
7535 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
7536 | } | |
7537 | if (internal_relocs != elf_section_data (isec)->relocs) | |
25dbc73a | 7538 | free (internal_relocs); |
9bc4e62b NS |
7539 | elf_section_data (isec)->relocs = new_relocs; |
7540 | isec->reloc_count += changes; | |
d4730f92 BS |
7541 | rel_hdr = _bfd_elf_single_rel_hdr (isec); |
7542 | rel_hdr->sh_size += changes * rel_hdr->sh_entsize; | |
25dbc73a | 7543 | } |
5446cbdf AM |
7544 | else if (internal_relocs != NULL |
7545 | && elf_section_data (isec)->relocs != internal_relocs) | |
9bc4e62b | 7546 | free (internal_relocs); |
252b5132 | 7547 | |
5446cbdf | 7548 | *again = changes != 0 || workaround_change; |
b34976b6 | 7549 | return TRUE; |
25dbc73a AM |
7550 | |
7551 | error_return: | |
d3e454b9 | 7552 | while (branch_fixups != NULL) |
5446cbdf | 7553 | { |
d3e454b9 AM |
7554 | struct one_branch_fixup *f = branch_fixups; |
7555 | branch_fixups = branch_fixups->next; | |
5446cbdf AM |
7556 | free (f); |
7557 | } | |
25dbc73a AM |
7558 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents) |
7559 | free (isymbuf); | |
7560 | if (contents != NULL | |
7561 | && elf_section_data (isec)->this_hdr.contents != contents) | |
7562 | free (contents); | |
7563 | if (internal_relocs != NULL | |
7564 | && elf_section_data (isec)->relocs != internal_relocs) | |
7565 | free (internal_relocs); | |
7566 | return FALSE; | |
252b5132 | 7567 | } |
252b5132 | 7568 | \f |
8a696751 AM |
7569 | /* What to do when ld finds relocations against symbols defined in |
7570 | discarded sections. */ | |
7571 | ||
7572 | static unsigned int | |
7573 | ppc_elf_action_discarded (asection *sec) | |
7574 | { | |
7575 | if (strcmp (".fixup", sec->name) == 0) | |
7576 | return 0; | |
7577 | ||
7578 | if (strcmp (".got2", sec->name) == 0) | |
7579 | return 0; | |
7580 | ||
7581 | return _bfd_elf_default_action_discarded (sec); | |
7582 | } | |
c9a2f333 | 7583 | \f |
25dbc73a | 7584 | /* Fill in the address for a pointer generated in a linker section. */ |
252b5132 | 7585 | |
25dbc73a | 7586 | static bfd_vma |
76750a2f | 7587 | elf_finish_pointer_linker_section (bfd *input_bfd, |
25dbc73a AM |
7588 | elf_linker_section_t *lsect, |
7589 | struct elf_link_hash_entry *h, | |
7590 | bfd_vma relocation, | |
2bb04cf2 | 7591 | const Elf_Internal_Rela *rel) |
25dbc73a AM |
7592 | { |
7593 | elf_linker_section_pointers_t *linker_section_ptr; | |
252b5132 | 7594 | |
25dbc73a | 7595 | BFD_ASSERT (lsect != NULL); |
252b5132 | 7596 | |
25dbc73a | 7597 | if (h != NULL) |
252b5132 | 7598 | { |
25dbc73a AM |
7599 | /* Handle global symbol. */ |
7600 | struct ppc_elf_link_hash_entry *eh; | |
252b5132 | 7601 | |
25dbc73a | 7602 | eh = (struct ppc_elf_link_hash_entry *) h; |
76750a2f AM |
7603 | BFD_ASSERT (eh->elf.def_regular); |
7604 | linker_section_ptr = eh->linker_section_pointer; | |
25dbc73a AM |
7605 | } |
7606 | else | |
7607 | { | |
7608 | /* Handle local symbol. */ | |
7609 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
76750a2f | 7610 | |
0c8d6e5c | 7611 | BFD_ASSERT (is_ppc_elf (input_bfd)); |
25dbc73a | 7612 | BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); |
76750a2f AM |
7613 | linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx]; |
7614 | } | |
252b5132 | 7615 | |
76750a2f AM |
7616 | linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr, |
7617 | rel->r_addend, | |
7618 | lsect); | |
7619 | BFD_ASSERT (linker_section_ptr != NULL); | |
25dbc73a | 7620 | |
76750a2f AM |
7621 | /* Offset will always be a multiple of four, so use the bottom bit |
7622 | as a "written" flag. */ | |
7623 | if ((linker_section_ptr->offset & 1) == 0) | |
7624 | { | |
7625 | bfd_put_32 (lsect->section->owner, | |
7626 | relocation + linker_section_ptr->addend, | |
7627 | lsect->section->contents + linker_section_ptr->offset); | |
7628 | linker_section_ptr->offset += 1; | |
252b5132 RH |
7629 | } |
7630 | ||
bd6c6e2b AM |
7631 | relocation = (lsect->section->output_section->vma |
7632 | + lsect->section->output_offset | |
76750a2f | 7633 | + linker_section_ptr->offset - 1 |
bd6c6e2b | 7634 | - SYM_VAL (lsect->sym)); |
252b5132 | 7635 | |
25dbc73a AM |
7636 | #ifdef DEBUG |
7637 | fprintf (stderr, | |
7638 | "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", | |
7639 | lsect->name, (long) relocation, (long) relocation); | |
7640 | #endif | |
252b5132 | 7641 | |
bd6c6e2b | 7642 | return relocation; |
252b5132 | 7643 | } |
25dbc73a | 7644 | |
e054468f AM |
7645 | #define PPC_LO(v) ((v) & 0xffff) |
7646 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
7647 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
7648 | ||
7649 | static void | |
a7f2871e | 7650 | write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p, |
e054468f AM |
7651 | struct bfd_link_info *info) |
7652 | { | |
7653 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
7654 | bfd *output_bfd = info->output_bfd; | |
7655 | bfd_vma plt; | |
e054468f AM |
7656 | |
7657 | plt = ((ent->plt.offset & ~1) | |
7658 | + plt_sec->output_section->vma | |
7659 | + plt_sec->output_offset); | |
e054468f | 7660 | |
0e1862bb | 7661 | if (bfd_link_pic (info)) |
e054468f AM |
7662 | { |
7663 | bfd_vma got = 0; | |
7664 | ||
7665 | if (ent->addend >= 32768) | |
7666 | got = (ent->addend | |
7667 | + ent->sec->output_section->vma | |
7668 | + ent->sec->output_offset); | |
7669 | else if (htab->elf.hgot != NULL) | |
7670 | got = SYM_VAL (htab->elf.hgot); | |
7671 | ||
7672 | plt -= got; | |
7673 | ||
7674 | if (plt + 0x8000 < 0x10000) | |
7675 | { | |
7676 | bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p); | |
7677 | p += 4; | |
7678 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
7679 | p += 4; | |
7680 | bfd_put_32 (output_bfd, BCTR, p); | |
7681 | p += 4; | |
da3a2088 | 7682 | bfd_put_32 (output_bfd, htab->params->ppc476_workaround ? BA : NOP, p); |
e054468f AM |
7683 | p += 4; |
7684 | } | |
7685 | else | |
7686 | { | |
7687 | bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p); | |
7688 | p += 4; | |
7689 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
7690 | p += 4; | |
7691 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
7692 | p += 4; | |
7693 | bfd_put_32 (output_bfd, BCTR, p); | |
7694 | p += 4; | |
7695 | } | |
7696 | } | |
7697 | else | |
7698 | { | |
7699 | bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p); | |
7700 | p += 4; | |
7701 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
7702 | p += 4; | |
7703 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
7704 | p += 4; | |
7705 | bfd_put_32 (output_bfd, BCTR, p); | |
7706 | p += 4; | |
7707 | } | |
7708 | } | |
7709 | ||
bd6c6e2b AM |
7710 | /* Return true if symbol is defined statically. */ |
7711 | ||
7712 | static bfd_boolean | |
7713 | is_static_defined (struct elf_link_hash_entry *h) | |
7714 | { | |
7715 | return ((h->root.type == bfd_link_hash_defined | |
7716 | || h->root.type == bfd_link_hash_defweak) | |
7717 | && h->root.u.def.section != NULL | |
7718 | && h->root.u.def.section->output_section != NULL); | |
7719 | } | |
7720 | ||
2d0f3896 AM |
7721 | /* If INSN is an opcode that may be used with an @tls operand, return |
7722 | the transformed insn for TLS optimisation, otherwise return 0. If | |
7723 | REG is non-zero only match an insn with RB or RA equal to REG. */ | |
7724 | ||
7725 | unsigned int | |
7726 | _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg) | |
7727 | { | |
7728 | unsigned int rtra; | |
7729 | ||
7730 | if ((insn & (0x3f << 26)) != 31 << 26) | |
7731 | return 0; | |
7732 | ||
7733 | if (reg == 0 || ((insn >> 11) & 0x1f) == reg) | |
7734 | rtra = insn & ((1 << 26) - (1 << 16)); | |
7735 | else if (((insn >> 16) & 0x1f) == reg) | |
7736 | rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5); | |
7737 | else | |
7738 | return 0; | |
7739 | ||
7740 | if ((insn & (0x3ff << 1)) == 266 << 1) | |
7741 | /* add -> addi. */ | |
7742 | insn = 14 << 26; | |
7743 | else if ((insn & (0x1f << 1)) == 23 << 1 | |
7744 | && ((insn & (0x1f << 6)) < 14 << 6 | |
7745 | || ((insn & (0x1f << 6)) >= 16 << 6 | |
7746 | && (insn & (0x1f << 6)) < 24 << 6))) | |
7747 | /* load and store indexed -> dform. */ | |
7748 | insn = (32 | ((insn >> 6) & 0x1f)) << 26; | |
7749 | else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1) | |
7750 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
7751 | insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1); | |
7752 | else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1) | |
7753 | /* lwax -> lwa. */ | |
7754 | insn = (58 << 26) | 2; | |
7755 | else | |
7756 | return 0; | |
7757 | insn |= rtra; | |
7758 | return insn; | |
7759 | } | |
7760 | ||
766bc656 AM |
7761 | /* If INSN is an opcode that may be used with an @tprel operand, return |
7762 | the transformed insn for an undefined weak symbol, ie. with the | |
7763 | thread pointer REG operand removed. Otherwise return 0. */ | |
7764 | ||
7765 | unsigned int | |
7766 | _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg) | |
7767 | { | |
7768 | if ((insn & (0x1f << 16)) == reg << 16 | |
7769 | && ((insn & (0x3f << 26)) == 14u << 26 /* addi */ | |
7770 | || (insn & (0x3f << 26)) == 15u << 26 /* addis */ | |
7771 | || (insn & (0x3f << 26)) == 32u << 26 /* lwz */ | |
7772 | || (insn & (0x3f << 26)) == 34u << 26 /* lbz */ | |
7773 | || (insn & (0x3f << 26)) == 36u << 26 /* stw */ | |
7774 | || (insn & (0x3f << 26)) == 38u << 26 /* stb */ | |
7775 | || (insn & (0x3f << 26)) == 40u << 26 /* lhz */ | |
7776 | || (insn & (0x3f << 26)) == 42u << 26 /* lha */ | |
7777 | || (insn & (0x3f << 26)) == 44u << 26 /* sth */ | |
7778 | || (insn & (0x3f << 26)) == 46u << 26 /* lmw */ | |
7779 | || (insn & (0x3f << 26)) == 47u << 26 /* stmw */ | |
7780 | || (insn & (0x3f << 26)) == 48u << 26 /* lfs */ | |
7781 | || (insn & (0x3f << 26)) == 50u << 26 /* lfd */ | |
7782 | || (insn & (0x3f << 26)) == 52u << 26 /* stfs */ | |
7783 | || (insn & (0x3f << 26)) == 54u << 26 /* stfd */ | |
7784 | || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */ | |
7785 | && (insn & 3) != 1) | |
7786 | || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */ | |
7787 | && ((insn & 3) == 0 || (insn & 3) == 3)))) | |
7788 | { | |
7789 | insn &= ~(0x1f << 16); | |
7790 | } | |
7791 | else if ((insn & (0x1f << 21)) == reg << 21 | |
7792 | && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */ | |
7793 | || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */ | |
7794 | || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */)) | |
7795 | { | |
7796 | insn &= ~(0x1f << 21); | |
7797 | insn |= (insn & (0x1f << 16)) << 5; | |
7798 | if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */) | |
7799 | insn -= 2 >> 26; /* convert to ori,oris */ | |
7800 | } | |
7801 | else | |
7802 | insn = 0; | |
7803 | return insn; | |
7804 | } | |
7805 | ||
1fe532cf AM |
7806 | static bfd_boolean |
7807 | is_insn_ds_form (unsigned int insn) | |
7808 | { | |
7809 | return ((insn & (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */ | |
7810 | || (insn & (0x3f << 26)) == 62u << 26 /* std,stdu,stq */ | |
7811 | || (insn & (0x3f << 26)) == 57u << 26 /* lfdp */ | |
7812 | || (insn & (0x3f << 26)) == 61u << 26 /* stfdp */); | |
7813 | } | |
7814 | ||
7815 | static bfd_boolean | |
7816 | is_insn_dq_form (unsigned int insn) | |
7817 | { | |
a680de9a PB |
7818 | return ((insn & (0x3f << 26)) == 56u << 26 /* lq */ |
7819 | || ((insn & (0x3f << 26)) == (61u << 26) /* lxv, stxv */ | |
7820 | && (insn & 3) == 1)); | |
1fe532cf AM |
7821 | } |
7822 | ||
252b5132 RH |
7823 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
7824 | to handle the relocations for a section. | |
7825 | ||
7826 | The relocs are always passed as Rela structures; if the section | |
7827 | actually uses Rel structures, the r_addend field will always be | |
7828 | zero. | |
7829 | ||
7830 | This function is responsible for adjust the section contents as | |
7831 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 7832 | relocatable output file) adjusting the reloc addend as |
252b5132 RH |
7833 | necessary. |
7834 | ||
7835 | This function does not have to worry about setting the reloc | |
7836 | address or the reloc symbol index. | |
7837 | ||
7838 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
7839 | ||
7840 | LOCAL_SECTIONS is an array giving the section in the input file | |
7841 | corresponding to the st_shndx field of each local symbol. | |
7842 | ||
7843 | The global hash table entry for the global symbols can be found | |
7844 | via elf_sym_hashes (input_bfd). | |
7845 | ||
1049f94e | 7846 | When generating relocatable output, this function must handle |
252b5132 RH |
7847 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
7848 | going to be the section symbol corresponding to the output | |
7849 | section, which means that the addend must be adjusted | |
7850 | accordingly. */ | |
7851 | ||
b34976b6 | 7852 | static bfd_boolean |
55fd94b0 AM |
7853 | ppc_elf_relocate_section (bfd *output_bfd, |
7854 | struct bfd_link_info *info, | |
7855 | bfd *input_bfd, | |
7856 | asection *input_section, | |
7857 | bfd_byte *contents, | |
7858 | Elf_Internal_Rela *relocs, | |
7859 | Elf_Internal_Sym *local_syms, | |
7860 | asection **local_sections) | |
252b5132 | 7861 | { |
7619e7c7 AM |
7862 | Elf_Internal_Shdr *symtab_hdr; |
7863 | struct elf_link_hash_entry **sym_hashes; | |
7864 | struct ppc_elf_link_hash_table *htab; | |
7865 | Elf_Internal_Rela *rel; | |
c316a17c | 7866 | Elf_Internal_Rela *wrel; |
7619e7c7 AM |
7867 | Elf_Internal_Rela *relend; |
7868 | Elf_Internal_Rela outrel; | |
f95f8542 | 7869 | asection *got2; |
252b5132 | 7870 | bfd_vma *local_got_offsets; |
b34976b6 | 7871 | bfd_boolean ret = TRUE; |
95f0d0d2 | 7872 | bfd_vma d_offset = (bfd_big_endian (input_bfd) ? 2 : 0); |
3348747a | 7873 | bfd_boolean is_vxworks_tls; |
d3e454b9 AM |
7874 | unsigned int picfixup_size = 0; |
7875 | struct ppc_elf_relax_info *relax_info = NULL; | |
b34976b6 | 7876 | |
252b5132 | 7877 | #ifdef DEBUG |
d003868e AM |
7878 | _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, " |
7879 | "%ld relocations%s", | |
7880 | input_bfd, input_section, | |
7881 | (long) input_section->reloc_count, | |
0e1862bb | 7882 | (bfd_link_relocatable (info)) ? " (relocatable)" : ""); |
252b5132 RH |
7883 | #endif |
7884 | ||
a6aa5195 AM |
7885 | got2 = bfd_get_section_by_name (input_bfd, ".got2"); |
7886 | ||
e47cd125 | 7887 | /* Initialize howto table if not already done. */ |
8da6118f | 7888 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
252b5132 RH |
7889 | ppc_elf_howto_init (); |
7890 | ||
7619e7c7 | 7891 | htab = ppc_elf_hash_table (info); |
252b5132 | 7892 | local_got_offsets = elf_local_got_offsets (input_bfd); |
0ffa91dd | 7893 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
7619e7c7 | 7894 | sym_hashes = elf_sym_hashes (input_bfd); |
3348747a NS |
7895 | /* We have to handle relocations in vxworks .tls_vars sections |
7896 | specially, because the dynamic loader is 'weird'. */ | |
0e1862bb | 7897 | is_vxworks_tls = (htab->is_vxworks && bfd_link_pic (info) |
3348747a NS |
7898 | && !strcmp (input_section->output_section->name, |
7899 | ".tls_vars")); | |
d3e454b9 AM |
7900 | if (input_section->sec_info_type == SEC_INFO_TYPE_TARGET) |
7901 | relax_info = elf_section_data (input_section)->sec_info; | |
c316a17c | 7902 | rel = wrel = relocs; |
7619e7c7 | 7903 | relend = relocs + input_section->reloc_count; |
c316a17c | 7904 | for (; rel < relend; wrel++, rel++) |
252b5132 | 7905 | { |
7619e7c7 AM |
7906 | enum elf_ppc_reloc_type r_type; |
7907 | bfd_vma addend; | |
7908 | bfd_reloc_status_type r; | |
7909 | Elf_Internal_Sym *sym; | |
7910 | asection *sec; | |
7911 | struct elf_link_hash_entry *h; | |
7912 | const char *sym_name; | |
252b5132 RH |
7913 | reloc_howto_type *howto; |
7914 | unsigned long r_symndx; | |
7915 | bfd_vma relocation; | |
91d6fa6a | 7916 | bfd_vma branch_bit, from; |
7619e7c7 AM |
7917 | bfd_boolean unresolved_reloc; |
7918 | bfd_boolean warned; | |
7919 | unsigned int tls_type, tls_mask, tls_gd; | |
e054468f | 7920 | struct plt_entry **ifunc; |
86c95733 | 7921 | struct reloc_howto_struct alt_howto; |
7619e7c7 | 7922 | |
c316a17c | 7923 | again: |
55fd94b0 AM |
7924 | r_type = ELF32_R_TYPE (rel->r_info); |
7925 | sym = NULL; | |
7926 | sec = NULL; | |
7927 | h = NULL; | |
7619e7c7 AM |
7928 | unresolved_reloc = FALSE; |
7929 | warned = FALSE; | |
252b5132 | 7930 | r_symndx = ELF32_R_SYM (rel->r_info); |
560e09e9 | 7931 | |
252b5132 RH |
7932 | if (r_symndx < symtab_hdr->sh_info) |
7933 | { | |
7934 | sym = local_syms + r_symndx; | |
7935 | sec = local_sections[r_symndx]; | |
26c61ae5 | 7936 | sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec); |
252b5132 | 7937 | |
8517fae7 | 7938 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
252b5132 RH |
7939 | } |
7940 | else | |
7941 | { | |
62d887d4 L |
7942 | bfd_boolean ignored; |
7943 | ||
b2a8e766 AM |
7944 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
7945 | r_symndx, symtab_hdr, sym_hashes, | |
7946 | h, sec, relocation, | |
62d887d4 | 7947 | unresolved_reloc, warned, ignored); |
9abc968f | 7948 | |
252b5132 | 7949 | sym_name = h->root.root.string; |
7619e7c7 AM |
7950 | } |
7951 | ||
dbaa2011 | 7952 | if (sec != NULL && discarded_section (sec)) |
ab96bf03 AM |
7953 | { |
7954 | /* For relocs against symbols from removed linkonce sections, | |
7955 | or sections discarded by a linker script, we just want the | |
7956 | section contents zeroed. Avoid any special processing. */ | |
7957 | howto = NULL; | |
7958 | if (r_type < R_PPC_max) | |
7959 | howto = ppc_elf_howto_table[r_type]; | |
c316a17c AM |
7960 | |
7961 | _bfd_clear_contents (howto, input_bfd, input_section, | |
7962 | contents + rel->r_offset); | |
7963 | wrel->r_offset = rel->r_offset; | |
7964 | wrel->r_info = 0; | |
7965 | wrel->r_addend = 0; | |
7966 | ||
7967 | /* For ld -r, remove relocations in debug sections against | |
dcd2b8a0 | 7968 | symbols defined in discarded sections. Not done for |
c316a17c AM |
7969 | non-debug to preserve relocs in .eh_frame which the |
7970 | eh_frame editing code expects to be present. */ | |
7971 | if (bfd_link_relocatable (info) | |
7972 | && (input_section->flags & SEC_DEBUGGING)) | |
7973 | wrel--; | |
7974 | ||
7975 | continue; | |
ab96bf03 AM |
7976 | } |
7977 | ||
0e1862bb | 7978 | if (bfd_link_relocatable (info)) |
ab96bf03 AM |
7979 | { |
7980 | if (got2 != NULL | |
7981 | && r_type == R_PPC_PLTREL24 | |
f75e0e33 | 7982 | && rel->r_addend != 0) |
ab96bf03 AM |
7983 | { |
7984 | /* R_PPC_PLTREL24 is rather special. If non-zero, the | |
7985 | addend specifies the GOT pointer offset within .got2. */ | |
7986 | rel->r_addend += got2->output_offset; | |
7987 | } | |
53291d1f AM |
7988 | if (r_type != R_PPC_RELAX_PLT |
7989 | && r_type != R_PPC_RELAX_PLTREL24 | |
7990 | && r_type != R_PPC_RELAX) | |
c316a17c | 7991 | goto copy_reloc; |
ab96bf03 AM |
7992 | } |
7993 | ||
7619e7c7 AM |
7994 | /* TLS optimizations. Replace instruction sequences and relocs |
7995 | based on information we collected in tls_optimize. We edit | |
7996 | RELOCS so that --emit-relocs will output something sensible | |
7997 | for the final instruction stream. */ | |
7998 | tls_mask = 0; | |
7999 | tls_gd = 0; | |
727fc41e AM |
8000 | if (h != NULL) |
8001 | tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask; | |
8002 | else if (local_got_offsets != NULL) | |
7619e7c7 | 8003 | { |
e054468f | 8004 | struct plt_entry **local_plt; |
727fc41e | 8005 | char *lgot_masks; |
e054468f AM |
8006 | local_plt |
8007 | = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info); | |
8008 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
727fc41e | 8009 | tls_mask = lgot_masks[r_symndx]; |
7619e7c7 AM |
8010 | } |
8011 | ||
8012 | /* Ensure reloc mapping code below stays sane. */ | |
8013 | if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3) | |
8014 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3) | |
8015 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3) | |
8016 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3) | |
8017 | || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3) | |
8018 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3) | |
8019 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3) | |
8020 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3)) | |
8021 | abort (); | |
8022 | switch (r_type) | |
8023 | { | |
8024 | default: | |
8025 | break; | |
8026 | ||
8027 | case R_PPC_GOT_TPREL16: | |
8028 | case R_PPC_GOT_TPREL16_LO: | |
e054468f | 8029 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
8030 | && (tls_mask & TLS_TPREL) == 0) |
8031 | { | |
8032 | bfd_vma insn; | |
91d6fa6a | 8033 | |
95f0d0d2 | 8034 | insn = bfd_get_32 (input_bfd, |
c316a17c | 8035 | contents + rel->r_offset - d_offset); |
7619e7c7 AM |
8036 | insn &= 31 << 21; |
8037 | insn |= 0x3c020000; /* addis 0,2,0 */ | |
95f0d0d2 | 8038 | bfd_put_32 (input_bfd, insn, |
c316a17c | 8039 | contents + rel->r_offset - d_offset); |
7619e7c7 AM |
8040 | r_type = R_PPC_TPREL16_HA; |
8041 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
8042 | } | |
8043 | break; | |
8044 | ||
8045 | case R_PPC_TLS: | |
e054468f | 8046 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
8047 | && (tls_mask & TLS_TPREL) == 0) |
8048 | { | |
2d0f3896 AM |
8049 | bfd_vma insn; |
8050 | ||
95f0d0d2 | 8051 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); |
2d0f3896 AM |
8052 | insn = _bfd_elf_ppc_at_tls_transform (insn, 2); |
8053 | if (insn == 0) | |
7619e7c7 | 8054 | abort (); |
95f0d0d2 | 8055 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); |
7619e7c7 AM |
8056 | r_type = R_PPC_TPREL16_LO; |
8057 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4fe5ca5b | 8058 | |
7619e7c7 | 8059 | /* Was PPC_TLS which sits on insn boundary, now |
4fe5ca5b GM |
8060 | PPC_TPREL16_LO which is at low-order half-word. */ |
8061 | rel->r_offset += d_offset; | |
7619e7c7 AM |
8062 | } |
8063 | break; | |
8064 | ||
8065 | case R_PPC_GOT_TLSGD16_HI: | |
8066 | case R_PPC_GOT_TLSGD16_HA: | |
8067 | tls_gd = TLS_TPRELGD; | |
e054468f | 8068 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
7619e7c7 AM |
8069 | goto tls_gdld_hi; |
8070 | break; | |
8071 | ||
8072 | case R_PPC_GOT_TLSLD16_HI: | |
8073 | case R_PPC_GOT_TLSLD16_HA: | |
e054468f | 8074 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 AM |
8075 | { |
8076 | tls_gdld_hi: | |
8077 | if ((tls_mask & tls_gd) != 0) | |
8078 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
8079 | + R_PPC_GOT_TPREL16); | |
8080 | else | |
8081 | { | |
4fe5ca5b | 8082 | rel->r_offset -= d_offset; |
95f0d0d2 | 8083 | bfd_put_32 (input_bfd, NOP, contents + rel->r_offset); |
7619e7c7 AM |
8084 | r_type = R_PPC_NONE; |
8085 | } | |
8086 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
8087 | } | |
8088 | break; | |
8089 | ||
8090 | case R_PPC_GOT_TLSGD16: | |
8091 | case R_PPC_GOT_TLSGD16_LO: | |
8092 | tls_gd = TLS_TPRELGD; | |
e054468f | 8093 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
b7fcf6f6 | 8094 | goto tls_ldgd_opt; |
7619e7c7 AM |
8095 | break; |
8096 | ||
8097 | case R_PPC_GOT_TLSLD16: | |
8098 | case R_PPC_GOT_TLSLD16_LO: | |
e054468f | 8099 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 | 8100 | { |
3a71aa26 | 8101 | unsigned int insn1, insn2; |
b7fcf6f6 | 8102 | bfd_vma offset; |
7619e7c7 | 8103 | |
b7fcf6f6 | 8104 | tls_ldgd_opt: |
727fc41e AM |
8105 | offset = (bfd_vma) -1; |
8106 | /* If not using the newer R_PPC_TLSGD/LD to mark | |
8107 | __tls_get_addr calls, we must trust that the call | |
8108 | stays with its arg setup insns, ie. that the next | |
8109 | reloc is the __tls_get_addr call associated with | |
8110 | the current reloc. Edit both insns. */ | |
8111 | if (input_section->has_tls_get_addr_call | |
8112 | && rel + 1 < relend | |
8113 | && branch_reloc_hash_match (input_bfd, rel + 1, | |
8114 | htab->tls_get_addr)) | |
8115 | offset = rel[1].r_offset; | |
b86ac8e3 AM |
8116 | /* We read the low GOT_TLS insn because we need to keep |
8117 | the destination reg. It may be something other than | |
8118 | the usual r3, and moved to r3 before the call by | |
8119 | intervening code. */ | |
95f0d0d2 | 8120 | insn1 = bfd_get_32 (input_bfd, |
b86ac8e3 | 8121 | contents + rel->r_offset - d_offset); |
b7fcf6f6 AM |
8122 | if ((tls_mask & tls_gd) != 0) |
8123 | { | |
8124 | /* IE */ | |
b86ac8e3 | 8125 | insn1 &= (0x1f << 21) | (0x1f << 16); |
b7fcf6f6 | 8126 | insn1 |= 32 << 26; /* lwz */ |
727fc41e AM |
8127 | if (offset != (bfd_vma) -1) |
8128 | { | |
f58d5a2d | 8129 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e | 8130 | insn2 = 0x7c631214; /* add 3,3,2 */ |
95f0d0d2 | 8131 | bfd_put_32 (input_bfd, insn2, contents + offset); |
727fc41e | 8132 | } |
b7fcf6f6 AM |
8133 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) |
8134 | + R_PPC_GOT_TPREL16); | |
8135 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
8136 | } | |
8137 | else | |
8138 | { | |
8139 | /* LE */ | |
b86ac8e3 AM |
8140 | insn1 &= 0x1f << 21; |
8141 | insn1 |= 0x3c020000; /* addis r,2,0 */ | |
7619e7c7 AM |
8142 | if (tls_gd == 0) |
8143 | { | |
b7fcf6f6 | 8144 | /* Was an LD reloc. */ |
1d483afe AM |
8145 | for (r_symndx = 0; |
8146 | r_symndx < symtab_hdr->sh_info; | |
8147 | r_symndx++) | |
8148 | if (local_sections[r_symndx] == sec) | |
8149 | break; | |
8150 | if (r_symndx >= symtab_hdr->sh_info) | |
cf35638d | 8151 | r_symndx = STN_UNDEF; |
b7fcf6f6 | 8152 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
cf35638d | 8153 | if (r_symndx != STN_UNDEF) |
1d483afe AM |
8154 | rel->r_addend -= (local_syms[r_symndx].st_value |
8155 | + sec->output_offset | |
8156 | + sec->output_section->vma); | |
7619e7c7 | 8157 | } |
b7fcf6f6 AM |
8158 | r_type = R_PPC_TPREL16_HA; |
8159 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
727fc41e AM |
8160 | if (offset != (bfd_vma) -1) |
8161 | { | |
8162 | rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
8163 | rel[1].r_offset = offset + d_offset; | |
8164 | rel[1].r_addend = rel->r_addend; | |
8165 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
95f0d0d2 | 8166 | bfd_put_32 (input_bfd, insn2, contents + offset); |
727fc41e | 8167 | } |
b7fcf6f6 | 8168 | } |
95f0d0d2 | 8169 | bfd_put_32 (input_bfd, insn1, |
b7fcf6f6 | 8170 | contents + rel->r_offset - d_offset); |
b7fcf6f6 AM |
8171 | if (tls_gd == 0) |
8172 | { | |
8173 | /* We changed the symbol on an LD reloc. Start over | |
8174 | in order to get h, sym, sec etc. right. */ | |
c316a17c | 8175 | goto again; |
7619e7c7 | 8176 | } |
252b5132 | 8177 | } |
7619e7c7 | 8178 | break; |
727fc41e AM |
8179 | |
8180 | case R_PPC_TLSGD: | |
e054468f | 8181 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
727fc41e AM |
8182 | { |
8183 | unsigned int insn2; | |
8184 | bfd_vma offset = rel->r_offset; | |
8185 | ||
8186 | if ((tls_mask & TLS_TPRELGD) != 0) | |
8187 | { | |
8188 | /* IE */ | |
8189 | r_type = R_PPC_NONE; | |
8190 | insn2 = 0x7c631214; /* add 3,3,2 */ | |
8191 | } | |
8192 | else | |
8193 | { | |
8194 | /* LE */ | |
8195 | r_type = R_PPC_TPREL16_LO; | |
8196 | rel->r_offset += d_offset; | |
8197 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
8198 | } | |
8199 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
95f0d0d2 | 8200 | bfd_put_32 (input_bfd, insn2, contents + offset); |
727fc41e AM |
8201 | /* Zap the reloc on the _tls_get_addr call too. */ |
8202 | BFD_ASSERT (offset == rel[1].r_offset); | |
f58d5a2d | 8203 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e AM |
8204 | } |
8205 | break; | |
8206 | ||
8207 | case R_PPC_TLSLD: | |
e054468f | 8208 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
727fc41e AM |
8209 | { |
8210 | unsigned int insn2; | |
8211 | ||
8212 | for (r_symndx = 0; | |
8213 | r_symndx < symtab_hdr->sh_info; | |
8214 | r_symndx++) | |
8215 | if (local_sections[r_symndx] == sec) | |
8216 | break; | |
8217 | if (r_symndx >= symtab_hdr->sh_info) | |
cf35638d | 8218 | r_symndx = STN_UNDEF; |
727fc41e | 8219 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
cf35638d | 8220 | if (r_symndx != STN_UNDEF) |
727fc41e AM |
8221 | rel->r_addend -= (local_syms[r_symndx].st_value |
8222 | + sec->output_offset | |
8223 | + sec->output_section->vma); | |
8224 | ||
8225 | rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
8226 | rel->r_offset += d_offset; | |
8227 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
95f0d0d2 | 8228 | bfd_put_32 (input_bfd, insn2, |
727fc41e AM |
8229 | contents + rel->r_offset - d_offset); |
8230 | /* Zap the reloc on the _tls_get_addr call too. */ | |
8231 | BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset); | |
f58d5a2d | 8232 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
c316a17c | 8233 | goto again; |
727fc41e AM |
8234 | } |
8235 | break; | |
7619e7c7 AM |
8236 | } |
8237 | ||
8238 | /* Handle other relocations that tweak non-addend part of insn. */ | |
8239 | branch_bit = 0; | |
8240 | switch (r_type) | |
8241 | { | |
8242 | default: | |
8243 | break; | |
8244 | ||
8245 | /* Branch taken prediction relocations. */ | |
8246 | case R_PPC_ADDR14_BRTAKEN: | |
8247 | case R_PPC_REL14_BRTAKEN: | |
8248 | branch_bit = BRANCH_PREDICT_BIT; | |
1a0670f3 | 8249 | /* Fall through. */ |
7619e7c7 | 8250 | |
4cc11e76 | 8251 | /* Branch not taken prediction relocations. */ |
7619e7c7 AM |
8252 | case R_PPC_ADDR14_BRNTAKEN: |
8253 | case R_PPC_REL14_BRNTAKEN: | |
91d6fa6a NC |
8254 | { |
8255 | bfd_vma insn; | |
7619e7c7 | 8256 | |
95f0d0d2 | 8257 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); |
91d6fa6a NC |
8258 | insn &= ~BRANCH_PREDICT_BIT; |
8259 | insn |= branch_bit; | |
7619e7c7 | 8260 | |
91d6fa6a NC |
8261 | from = (rel->r_offset |
8262 | + input_section->output_offset | |
8263 | + input_section->output_section->vma); | |
7619e7c7 | 8264 | |
91d6fa6a NC |
8265 | /* Invert 'y' bit if not the default. */ |
8266 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
8267 | insn ^= BRANCH_PREDICT_BIT; | |
8268 | ||
95f0d0d2 | 8269 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); |
91d6fa6a NC |
8270 | break; |
8271 | } | |
252b5132 RH |
8272 | } |
8273 | ||
d3e454b9 AM |
8274 | if (ELIMINATE_COPY_RELOCS |
8275 | && h != NULL | |
8276 | && !h->def_regular | |
8277 | && h->protected_def | |
8278 | && ppc_elf_hash_entry (h)->has_addr16_ha | |
8279 | && ppc_elf_hash_entry (h)->has_addr16_lo | |
8280 | && htab->params->pic_fixup > 0) | |
8281 | { | |
8282 | /* Convert lis;addi or lis;load/store accessing a protected | |
8283 | variable defined in a shared library to PIC. */ | |
8284 | unsigned int insn; | |
8285 | ||
8286 | if (r_type == R_PPC_ADDR16_HA) | |
8287 | { | |
95f0d0d2 | 8288 | insn = bfd_get_32 (input_bfd, |
d3e454b9 AM |
8289 | contents + rel->r_offset - d_offset); |
8290 | if ((insn & (0x3f << 26)) == (15u << 26) | |
8291 | && (insn & (0x1f << 16)) == 0 /* lis */) | |
8292 | { | |
8293 | bfd_byte *p; | |
8294 | bfd_vma off; | |
8295 | bfd_vma got_addr; | |
8296 | ||
8297 | p = (contents + input_section->size | |
8298 | - relax_info->workaround_size | |
8299 | - relax_info->picfixup_size | |
8300 | + picfixup_size); | |
8301 | off = (p - contents) - (rel->r_offset - d_offset); | |
8302 | if (off > 0x1fffffc || (off & 3) != 0) | |
8303 | info->callbacks->einfo | |
174d0a74 | 8304 | (_("%H: fixup branch overflow\n"), |
d3e454b9 AM |
8305 | input_bfd, input_section, rel->r_offset); |
8306 | ||
95f0d0d2 | 8307 | bfd_put_32 (input_bfd, B | off, |
d3e454b9 | 8308 | contents + rel->r_offset - d_offset); |
ce558b89 AM |
8309 | got_addr = (htab->elf.sgot->output_section->vma |
8310 | + htab->elf.sgot->output_offset | |
d3e454b9 | 8311 | + (h->got.offset & ~1)); |
c316a17c AM |
8312 | wrel->r_offset = (p - contents) + d_offset; |
8313 | wrel->r_info = ELF32_R_INFO (0, R_PPC_ADDR16_HA); | |
8314 | wrel->r_addend = got_addr; | |
d3e454b9 | 8315 | insn &= ~0xffff; |
4aef7643 | 8316 | insn |= ((unsigned int) (got_addr + 0x8000) >> 16) & 0xffff; |
95f0d0d2 | 8317 | bfd_put_32 (input_bfd, insn, p); |
d3e454b9 AM |
8318 | |
8319 | /* Convert lis to lwz, loading address from GOT. */ | |
8320 | insn &= ~0xffff; | |
8321 | insn ^= (32u ^ 15u) << 26; | |
8322 | insn |= (insn & (0x1f << 21)) >> 5; | |
8323 | insn |= got_addr & 0xffff; | |
95f0d0d2 | 8324 | bfd_put_32 (input_bfd, insn, p + 4); |
d3e454b9 | 8325 | |
95f0d0d2 | 8326 | bfd_put_32 (input_bfd, B | ((-4 - off) & 0x3ffffff), p + 8); |
d3e454b9 AM |
8327 | picfixup_size += 12; |
8328 | ||
8329 | /* Use one of the spare relocs, so --emit-relocs | |
8330 | output is reasonable. */ | |
8331 | memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel)); | |
c316a17c AM |
8332 | wrel++, rel++; |
8333 | rel->r_offset = wrel[-1].r_offset + 4; | |
d3e454b9 | 8334 | rel->r_info = ELF32_R_INFO (0, R_PPC_ADDR16_LO); |
c316a17c | 8335 | rel->r_addend = wrel[-1].r_addend; |
d3e454b9 AM |
8336 | |
8337 | /* Continue on as if we had a got reloc, to output | |
8338 | dynamic reloc. */ | |
8339 | r_type = R_PPC_GOT16_LO; | |
8340 | } | |
8341 | else | |
2c4d9cbe | 8342 | _bfd_error_handler |
695344c0 | 8343 | /* xgettext:c-format */ |
e3fbc3da | 8344 | (_("%B(%A+%#Lx): error: %s with unexpected instruction %#x"), |
d3e454b9 AM |
8345 | input_bfd, input_section, rel->r_offset, |
8346 | "R_PPC_ADDR16_HA", insn); | |
8347 | } | |
8348 | else if (r_type == R_PPC_ADDR16_LO) | |
8349 | { | |
95f0d0d2 | 8350 | insn = bfd_get_32 (input_bfd, |
d3e454b9 AM |
8351 | contents + rel->r_offset - d_offset); |
8352 | if ((insn & (0x3f << 26)) == 14u << 26 /* addi */ | |
8353 | || (insn & (0x3f << 26)) == 32u << 26 /* lwz */ | |
8354 | || (insn & (0x3f << 26)) == 34u << 26 /* lbz */ | |
8355 | || (insn & (0x3f << 26)) == 36u << 26 /* stw */ | |
8356 | || (insn & (0x3f << 26)) == 38u << 26 /* stb */ | |
8357 | || (insn & (0x3f << 26)) == 40u << 26 /* lhz */ | |
8358 | || (insn & (0x3f << 26)) == 42u << 26 /* lha */ | |
8359 | || (insn & (0x3f << 26)) == 44u << 26 /* sth */ | |
8360 | || (insn & (0x3f << 26)) == 46u << 26 /* lmw */ | |
8361 | || (insn & (0x3f << 26)) == 47u << 26 /* stmw */ | |
8362 | || (insn & (0x3f << 26)) == 48u << 26 /* lfs */ | |
8363 | || (insn & (0x3f << 26)) == 50u << 26 /* lfd */ | |
8364 | || (insn & (0x3f << 26)) == 52u << 26 /* stfs */ | |
8365 | || (insn & (0x3f << 26)) == 54u << 26 /* stfd */ | |
8366 | || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */ | |
8367 | && (insn & 3) != 1) | |
8368 | || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */ | |
8369 | && ((insn & 3) == 0 || (insn & 3) == 3))) | |
8370 | { | |
8371 | /* Arrange to apply the reloc addend, if any. */ | |
8372 | relocation = 0; | |
8373 | unresolved_reloc = FALSE; | |
8374 | rel->r_info = ELF32_R_INFO (0, r_type); | |
8375 | } | |
8376 | else | |
2c4d9cbe | 8377 | _bfd_error_handler |
695344c0 | 8378 | /* xgettext:c-format */ |
e3fbc3da | 8379 | (_("%B(%A+%#Lx): error: %s with unexpected instruction %#x"), |
d3e454b9 AM |
8380 | input_bfd, input_section, rel->r_offset, |
8381 | "R_PPC_ADDR16_LO", insn); | |
8382 | } | |
8383 | } | |
8384 | ||
e054468f | 8385 | ifunc = NULL; |
25f23106 | 8386 | if (!htab->is_vxworks) |
e054468f | 8387 | { |
de972ffa AM |
8388 | struct plt_entry *ent; |
8389 | ||
e054468f AM |
8390 | if (h != NULL) |
8391 | { | |
8392 | if (h->type == STT_GNU_IFUNC) | |
8393 | ifunc = &h->plt.plist; | |
8394 | } | |
de972ffa AM |
8395 | else if (local_got_offsets != NULL |
8396 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
e054468f | 8397 | { |
de972ffa | 8398 | struct plt_entry **local_plt; |
e054468f | 8399 | |
de972ffa AM |
8400 | local_plt = (struct plt_entry **) (local_got_offsets |
8401 | + symtab_hdr->sh_info); | |
8402 | ifunc = local_plt + r_symndx; | |
e054468f | 8403 | } |
e054468f | 8404 | |
de972ffa AM |
8405 | ent = NULL; |
8406 | if (ifunc != NULL | |
0e1862bb | 8407 | && (!bfd_link_pic (info) |
de972ffa AM |
8408 | || is_branch_reloc (r_type))) |
8409 | { | |
8410 | addend = 0; | |
0e1862bb | 8411 | if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info)) |
de972ffa AM |
8412 | addend = rel->r_addend; |
8413 | ent = find_plt_ent (ifunc, got2, addend); | |
8414 | } | |
8415 | if (ent != NULL) | |
8416 | { | |
888a7fc3 AM |
8417 | if (bfd_link_pic (info) |
8418 | && ent->sec != got2 | |
8419 | && htab->plt_type != PLT_NEW | |
8420 | && (!htab->elf.dynamic_sections_created | |
8421 | || h == NULL | |
8422 | || h->dynindx == -1)) | |
8423 | { | |
8424 | /* Uh oh, we are going to create a pic glink stub | |
8425 | for an ifunc (here for h == NULL and later in | |
8426 | finish_dynamic_symbol for h != NULL), and | |
8427 | apparently are using code compiled with | |
8428 | -mbss-plt. The difficulty is that -mbss-plt code | |
8429 | gives no indication via a magic PLTREL24 addend | |
8430 | whether r30 is equal to _GLOBAL_OFFSET_TABLE_ or | |
8431 | is pointing into a .got2 section (and how far | |
8432 | into .got2). */ | |
8433 | info->callbacks->einfo | |
695344c0 | 8434 | /* xgettext:c-format */ |
174d0a74 | 8435 | (_("%X%H: unsupported bss-plt -fPIC ifunc %s\n"), |
888a7fc3 AM |
8436 | input_bfd, input_section, rel->r_offset, sym_name); |
8437 | } | |
e054468f AM |
8438 | if (h == NULL && (ent->plt.offset & 1) == 0) |
8439 | { | |
8440 | Elf_Internal_Rela rela; | |
8441 | bfd_byte *loc; | |
8442 | ||
ce558b89 AM |
8443 | rela.r_offset = (htab->elf.iplt->output_section->vma |
8444 | + htab->elf.iplt->output_offset | |
e054468f AM |
8445 | + ent->plt.offset); |
8446 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
8447 | rela.r_addend = relocation; | |
ce558b89 AM |
8448 | loc = htab->elf.irelplt->contents; |
8449 | loc += (htab->elf.irelplt->reloc_count++ | |
25f23106 | 8450 | * sizeof (Elf32_External_Rela)); |
e054468f | 8451 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
82e66161 | 8452 | htab->local_ifunc_resolver = 1; |
e054468f AM |
8453 | |
8454 | ent->plt.offset |= 1; | |
8455 | } | |
8456 | if (h == NULL && (ent->glink_offset & 1) == 0) | |
8457 | { | |
a7f2871e AM |
8458 | unsigned char *p = ((unsigned char *) htab->glink->contents |
8459 | + ent->glink_offset); | |
ce558b89 | 8460 | write_glink_stub (ent, htab->elf.iplt, p, info); |
e054468f AM |
8461 | ent->glink_offset |= 1; |
8462 | } | |
8463 | ||
8464 | unresolved_reloc = FALSE; | |
8465 | if (htab->plt_type == PLT_NEW | |
8466 | || !htab->elf.dynamic_sections_created | |
c7e17e05 AM |
8467 | || h == NULL |
8468 | || h->dynindx == -1) | |
e054468f AM |
8469 | relocation = (htab->glink->output_section->vma |
8470 | + htab->glink->output_offset | |
8471 | + (ent->glink_offset & ~1)); | |
8472 | else | |
ce558b89 AM |
8473 | relocation = (htab->elf.splt->output_section->vma |
8474 | + htab->elf.splt->output_offset | |
e054468f AM |
8475 | + ent->plt.offset); |
8476 | } | |
8477 | } | |
8478 | ||
7619e7c7 | 8479 | addend = rel->r_addend; |
7619e7c7 | 8480 | howto = NULL; |
55fd94b0 AM |
8481 | if (r_type < R_PPC_max) |
8482 | howto = ppc_elf_howto_table[r_type]; | |
9a23f96e AM |
8483 | |
8484 | switch (r_type) | |
8485 | { | |
8486 | default: | |
8487 | break; | |
8488 | ||
8489 | case R_PPC_TPREL16_HA: | |
8490 | if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000) | |
8491 | { | |
8492 | bfd_byte *p = contents + (rel->r_offset & ~3); | |
8493 | unsigned int insn = bfd_get_32 (input_bfd, p); | |
8494 | if ((insn & ((0x3f << 26) | 0x1f << 16)) | |
8495 | != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */) | |
8496 | /* xgettext:c-format */ | |
8497 | info->callbacks->minfo | |
8498 | (_("%H: warning: %s unexpected insn %#x.\n"), | |
8499 | input_bfd, input_section, rel->r_offset, howto->name, insn); | |
8500 | else | |
8501 | bfd_put_32 (input_bfd, NOP, p); | |
8502 | } | |
8503 | break; | |
8504 | ||
8505 | case R_PPC_TPREL16_LO: | |
8506 | if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000) | |
8507 | { | |
8508 | bfd_byte *p = contents + (rel->r_offset & ~3); | |
8509 | unsigned int insn = bfd_get_32 (input_bfd, p); | |
8510 | insn &= ~(0x1f << 16); | |
8511 | insn |= 2 << 16; | |
8512 | bfd_put_32 (input_bfd, insn, p); | |
8513 | } | |
8514 | break; | |
8515 | } | |
8516 | ||
8517 | tls_type = 0; | |
7619e7c7 | 8518 | switch (r_type) |
252b5132 RH |
8519 | { |
8520 | default: | |
25f53a85 | 8521 | info->callbacks->einfo |
695344c0 | 8522 | /* xgettext:c-format */ |
8de848d8 | 8523 | (_("%P: %B: unknown relocation type %d for symbol %s\n"), |
d003868e | 8524 | input_bfd, (int) r_type, sym_name); |
252b5132 RH |
8525 | |
8526 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8527 | ret = FALSE; |
c316a17c | 8528 | goto copy_reloc; |
252b5132 | 8529 | |
7619e7c7 AM |
8530 | case R_PPC_NONE: |
8531 | case R_PPC_TLS: | |
727fc41e AM |
8532 | case R_PPC_TLSGD: |
8533 | case R_PPC_TLSLD: | |
7619e7c7 AM |
8534 | case R_PPC_EMB_MRKREF: |
8535 | case R_PPC_GNU_VTINHERIT: | |
8536 | case R_PPC_GNU_VTENTRY: | |
c316a17c | 8537 | goto copy_reloc; |
7595d193 | 8538 | |
7619e7c7 AM |
8539 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
8540 | address in the GOT as relocation value instead of the | |
8541 | symbol's value itself. Also, create a GOT entry for the | |
8542 | symbol and put the symbol value there. */ | |
8543 | case R_PPC_GOT_TLSGD16: | |
8544 | case R_PPC_GOT_TLSGD16_LO: | |
8545 | case R_PPC_GOT_TLSGD16_HI: | |
8546 | case R_PPC_GOT_TLSGD16_HA: | |
8547 | tls_type = TLS_TLS | TLS_GD; | |
8548 | goto dogot; | |
8549 | ||
8550 | case R_PPC_GOT_TLSLD16: | |
8551 | case R_PPC_GOT_TLSLD16_LO: | |
8552 | case R_PPC_GOT_TLSLD16_HI: | |
8553 | case R_PPC_GOT_TLSLD16_HA: | |
8554 | tls_type = TLS_TLS | TLS_LD; | |
8555 | goto dogot; | |
8556 | ||
8557 | case R_PPC_GOT_TPREL16: | |
8558 | case R_PPC_GOT_TPREL16_LO: | |
8559 | case R_PPC_GOT_TPREL16_HI: | |
8560 | case R_PPC_GOT_TPREL16_HA: | |
8561 | tls_type = TLS_TLS | TLS_TPREL; | |
8562 | goto dogot; | |
8563 | ||
8564 | case R_PPC_GOT_DTPREL16: | |
8565 | case R_PPC_GOT_DTPREL16_LO: | |
8566 | case R_PPC_GOT_DTPREL16_HI: | |
8567 | case R_PPC_GOT_DTPREL16_HA: | |
8568 | tls_type = TLS_TLS | TLS_DTPREL; | |
8569 | goto dogot; | |
8570 | ||
8571 | case R_PPC_GOT16: | |
8572 | case R_PPC_GOT16_LO: | |
8573 | case R_PPC_GOT16_HI: | |
8574 | case R_PPC_GOT16_HA: | |
727fc41e | 8575 | tls_mask = 0; |
7619e7c7 AM |
8576 | dogot: |
8577 | { | |
8578 | /* Relocation is to the entry for this symbol in the global | |
8579 | offset table. */ | |
8580 | bfd_vma off; | |
8581 | bfd_vma *offp; | |
8582 | unsigned long indx; | |
8583 | ||
ce558b89 | 8584 | if (htab->elf.sgot == NULL) |
7619e7c7 AM |
8585 | abort (); |
8586 | ||
8587 | indx = 0; | |
8588 | if (tls_type == (TLS_TLS | TLS_LD) | |
d881513a | 8589 | && (h == NULL |
f5385ebf | 8590 | || !h->def_dynamic)) |
7619e7c7 AM |
8591 | offp = &htab->tlsld_got.offset; |
8592 | else if (h != NULL) | |
8593 | { | |
f0158f44 AM |
8594 | if (!htab->elf.dynamic_sections_created |
8595 | || h->dynindx == -1 | |
8596 | || SYMBOL_REFERENCES_LOCAL (info, h) | |
21d68fcd | 8597 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
7619e7c7 AM |
8598 | /* This is actually a static link, or it is a |
8599 | -Bsymbolic link and the symbol is defined | |
8600 | locally, or the symbol was forced to be local | |
8601 | because of a version file. */ | |
8602 | ; | |
8603 | else | |
8604 | { | |
8605 | indx = h->dynindx; | |
8606 | unresolved_reloc = FALSE; | |
8607 | } | |
8608 | offp = &h->got.offset; | |
8609 | } | |
8610 | else | |
8611 | { | |
8612 | if (local_got_offsets == NULL) | |
8613 | abort (); | |
8614 | offp = &local_got_offsets[r_symndx]; | |
8615 | } | |
8616 | ||
8617 | /* The offset must always be a multiple of 4. We use the | |
8618 | least significant bit to record whether we have already | |
8619 | processed this entry. */ | |
8620 | off = *offp; | |
8621 | if ((off & 1) != 0) | |
8622 | off &= ~1; | |
8623 | else | |
8624 | { | |
70bccea4 AM |
8625 | unsigned int tls_m = (tls_mask |
8626 | & (TLS_LD | TLS_GD | TLS_DTPREL | |
8627 | | TLS_TPREL | TLS_TPRELGD)); | |
8628 | ||
8629 | if (offp == &htab->tlsld_got.offset) | |
8630 | tls_m = TLS_LD; | |
8631 | else if (h == NULL | |
f5385ebf | 8632 | || !h->def_dynamic) |
70bccea4 AM |
8633 | tls_m &= ~TLS_LD; |
8634 | ||
8635 | /* We might have multiple got entries for this sym. | |
8636 | Initialize them all. */ | |
8637 | do | |
7619e7c7 | 8638 | { |
70bccea4 AM |
8639 | int tls_ty = 0; |
8640 | ||
8641 | if ((tls_m & TLS_LD) != 0) | |
7619e7c7 | 8642 | { |
70bccea4 AM |
8643 | tls_ty = TLS_TLS | TLS_LD; |
8644 | tls_m &= ~TLS_LD; | |
8645 | } | |
8646 | else if ((tls_m & TLS_GD) != 0) | |
8647 | { | |
8648 | tls_ty = TLS_TLS | TLS_GD; | |
8649 | tls_m &= ~TLS_GD; | |
8650 | } | |
8651 | else if ((tls_m & TLS_DTPREL) != 0) | |
8652 | { | |
8653 | tls_ty = TLS_TLS | TLS_DTPREL; | |
8654 | tls_m &= ~TLS_DTPREL; | |
8655 | } | |
8656 | else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
8657 | { | |
8658 | tls_ty = TLS_TLS | TLS_TPREL; | |
8659 | tls_m = 0; | |
7619e7c7 | 8660 | } |
7619e7c7 | 8661 | |
70bccea4 | 8662 | /* Generate relocs for the dynamic linker. */ |
f0158f44 AM |
8663 | if (indx != 0 |
8664 | || (bfd_link_pic (info) | |
8665 | && (h == NULL | |
21d68fcd | 8666 | || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h) |
f0158f44 | 8667 | || offp == &htab->tlsld_got.offset))) |
7619e7c7 | 8668 | { |
ce558b89 | 8669 | asection *rsec = htab->elf.srelgot; |
91d6fa6a | 8670 | bfd_byte * loc; |
91e21fb7 | 8671 | |
0bed072f | 8672 | if (ifunc != NULL) |
82e66161 AM |
8673 | { |
8674 | rsec = htab->elf.irelplt; | |
8675 | if (indx == 0) | |
8676 | htab->local_ifunc_resolver = 1; | |
8677 | else if (is_static_defined (h)) | |
8678 | htab->maybe_local_ifunc_resolver = 1; | |
8679 | } | |
ce558b89 AM |
8680 | outrel.r_offset = (htab->elf.sgot->output_section->vma |
8681 | + htab->elf.sgot->output_offset | |
70bccea4 | 8682 | + off); |
e515b051 | 8683 | outrel.r_addend = 0; |
70bccea4 AM |
8684 | if (tls_ty & (TLS_LD | TLS_GD)) |
8685 | { | |
8686 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32); | |
70bccea4 AM |
8687 | if (tls_ty == (TLS_TLS | TLS_GD)) |
8688 | { | |
25f23106 AM |
8689 | loc = rsec->contents; |
8690 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
8691 | * sizeof (Elf32_External_Rela)); |
8692 | bfd_elf32_swap_reloca_out (output_bfd, | |
8693 | &outrel, loc); | |
e515b051 | 8694 | outrel.r_offset += 4; |
70bccea4 AM |
8695 | outrel.r_info |
8696 | = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
70bccea4 AM |
8697 | } |
8698 | } | |
8699 | else if (tls_ty == (TLS_TLS | TLS_DTPREL)) | |
8700 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
8701 | else if (tls_ty == (TLS_TLS | TLS_TPREL)) | |
8702 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32); | |
25f23106 | 8703 | else if (indx != 0) |
70bccea4 | 8704 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT); |
25f23106 AM |
8705 | else if (ifunc != NULL) |
8706 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
8707 | else | |
8708 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
d6e14abc | 8709 | if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD)) |
e515b051 AM |
8710 | { |
8711 | outrel.r_addend += relocation; | |
8712 | if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
989f9879 AM |
8713 | { |
8714 | if (htab->elf.tls_sec == NULL) | |
8715 | outrel.r_addend = 0; | |
8716 | else | |
8717 | outrel.r_addend -= htab->elf.tls_sec->vma; | |
8718 | } | |
e515b051 | 8719 | } |
25f23106 AM |
8720 | loc = rsec->contents; |
8721 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
8722 | * sizeof (Elf32_External_Rela)); |
8723 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
7619e7c7 AM |
8724 | } |
8725 | ||
70bccea4 AM |
8726 | /* Init the .got section contents if we're not |
8727 | emitting a reloc. */ | |
8728 | else | |
7619e7c7 | 8729 | { |
70bccea4 AM |
8730 | bfd_vma value = relocation; |
8731 | ||
f0158f44 | 8732 | if (tls_ty != 0) |
70bccea4 | 8733 | { |
989f9879 AM |
8734 | if (htab->elf.tls_sec == NULL) |
8735 | value = 0; | |
8736 | else | |
8737 | { | |
f0158f44 AM |
8738 | if (tls_ty & TLS_LD) |
8739 | value = 0; | |
8740 | else | |
8741 | value -= htab->elf.tls_sec->vma + DTP_OFFSET; | |
676ee2b5 | 8742 | if (tls_ty & TLS_TPREL) |
989f9879 AM |
8743 | value += DTP_OFFSET - TP_OFFSET; |
8744 | } | |
70bccea4 | 8745 | |
f0158f44 | 8746 | if (tls_ty & (TLS_LD | TLS_GD)) |
7b609f53 | 8747 | { |
95f0d0d2 | 8748 | bfd_put_32 (input_bfd, value, |
ce558b89 | 8749 | htab->elf.sgot->contents + off + 4); |
676ee2b5 | 8750 | value = 1; |
7b609f53 | 8751 | } |
70bccea4 | 8752 | } |
95f0d0d2 | 8753 | bfd_put_32 (input_bfd, value, |
ce558b89 | 8754 | htab->elf.sgot->contents + off); |
7619e7c7 | 8755 | } |
70bccea4 AM |
8756 | |
8757 | off += 4; | |
8758 | if (tls_ty & (TLS_LD | TLS_GD)) | |
8759 | off += 4; | |
7619e7c7 | 8760 | } |
70bccea4 AM |
8761 | while (tls_m != 0); |
8762 | ||
8763 | off = *offp; | |
8764 | *offp = off | 1; | |
7619e7c7 AM |
8765 | } |
8766 | ||
8767 | if (off >= (bfd_vma) -2) | |
8768 | abort (); | |
8769 | ||
70bccea4 AM |
8770 | if ((tls_type & TLS_TLS) != 0) |
8771 | { | |
8772 | if (tls_type != (TLS_TLS | TLS_LD)) | |
8773 | { | |
8774 | if ((tls_mask & TLS_LD) != 0 | |
8775 | && !(h == NULL | |
f5385ebf | 8776 | || !h->def_dynamic)) |
70bccea4 AM |
8777 | off += 8; |
8778 | if (tls_type != (TLS_TLS | TLS_GD)) | |
8779 | { | |
8780 | if ((tls_mask & TLS_GD) != 0) | |
8781 | off += 8; | |
8782 | if (tls_type != (TLS_TLS | TLS_DTPREL)) | |
8783 | { | |
8784 | if ((tls_mask & TLS_DTPREL) != 0) | |
8785 | off += 4; | |
8786 | } | |
8787 | } | |
8788 | } | |
8789 | } | |
8790 | ||
d3e454b9 AM |
8791 | /* If here for a picfixup, we're done. */ |
8792 | if (r_type != ELF32_R_TYPE (rel->r_info)) | |
c316a17c | 8793 | goto copy_reloc; |
d3e454b9 | 8794 | |
ce558b89 AM |
8795 | relocation = (htab->elf.sgot->output_section->vma |
8796 | + htab->elf.sgot->output_offset | |
e87d4038 AM |
8797 | + off |
8798 | - SYM_VAL (htab->elf.hgot)); | |
7619e7c7 AM |
8799 | |
8800 | /* Addends on got relocations don't make much sense. | |
8801 | x+off@got is actually x@got+off, and since the got is | |
8802 | generated by a hash table traversal, the value in the | |
8803 | got at entry m+n bears little relation to the entry m. */ | |
8804 | if (addend != 0) | |
25f53a85 | 8805 | info->callbacks->einfo |
695344c0 | 8806 | /* xgettext:c-format */ |
174d0a74 | 8807 | (_("%H: non-zero addend on %s reloc against `%s'\n"), |
25f53a85 | 8808 | input_bfd, input_section, rel->r_offset, |
7b609f53 | 8809 | howto->name, |
7619e7c7 AM |
8810 | sym_name); |
8811 | } | |
86c95733 | 8812 | break; |
7619e7c7 | 8813 | |
86c95733 | 8814 | /* Relocations that need no special processing. */ |
7619e7c7 | 8815 | case R_PPC_LOCAL24PC: |
252b5132 RH |
8816 | /* It makes no sense to point a local relocation |
8817 | at a symbol not in this object. */ | |
7b609f53 | 8818 | if (unresolved_reloc) |
252b5132 | 8819 | { |
1a72702b AM |
8820 | (*info->callbacks->undefined_symbol) (info, |
8821 | h->root.root.string, | |
8822 | input_bfd, | |
8823 | input_section, | |
8824 | rel->r_offset, | |
8825 | TRUE); | |
c316a17c | 8826 | goto copy_reloc; |
252b5132 | 8827 | } |
888a7fc3 AM |
8828 | if (h != NULL && h->type == STT_GNU_IFUNC && bfd_link_pic (info)) |
8829 | { | |
8830 | /* @local on an ifunc does not really make sense since | |
8831 | the ifunc resolver can take you anywhere. More | |
8832 | seriously, calls to ifuncs must go through a plt call | |
8833 | stub, and for pic the plt call stubs uses r30 to | |
8834 | access the PLT. The problem is that a call that is | |
8835 | local won't have the +32k reloc addend trick marking | |
8836 | -fPIC code, so the linker won't know whether r30 is | |
8837 | _GLOBAL_OFFSET_TABLE_ or pointing into a .got2 section. */ | |
695344c0 | 8838 | /* xgettext:c-format */ |
174d0a74 | 8839 | info->callbacks->einfo (_("%X%H: @local call to ifunc %s\n"), |
888a7fc3 AM |
8840 | input_bfd, input_section, rel->r_offset, |
8841 | h->root.root.string); | |
8842 | } | |
252b5132 RH |
8843 | break; |
8844 | ||
7619e7c7 AM |
8845 | case R_PPC_DTPREL16: |
8846 | case R_PPC_DTPREL16_LO: | |
8847 | case R_PPC_DTPREL16_HI: | |
8848 | case R_PPC_DTPREL16_HA: | |
989f9879 AM |
8849 | if (htab->elf.tls_sec != NULL) |
8850 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; | |
7619e7c7 AM |
8851 | break; |
8852 | ||
70bccea4 AM |
8853 | /* Relocations that may need to be propagated if this is a shared |
8854 | object. */ | |
7619e7c7 AM |
8855 | case R_PPC_TPREL16: |
8856 | case R_PPC_TPREL16_LO: | |
8857 | case R_PPC_TPREL16_HI: | |
8858 | case R_PPC_TPREL16_HA: | |
766bc656 AM |
8859 | if (h != NULL |
8860 | && h->root.type == bfd_link_hash_undefweak | |
8861 | && h->dynindx == -1) | |
8862 | { | |
8863 | /* Make this relocation against an undefined weak symbol | |
8864 | resolve to zero. This is really just a tweak, since | |
8865 | code using weak externs ought to check that they are | |
8866 | defined before using them. */ | |
8867 | bfd_byte *p = contents + rel->r_offset - d_offset; | |
95f0d0d2 | 8868 | unsigned int insn = bfd_get_32 (input_bfd, p); |
766bc656 AM |
8869 | insn = _bfd_elf_ppc_at_tprel_transform (insn, 2); |
8870 | if (insn != 0) | |
95f0d0d2 | 8871 | bfd_put_32 (input_bfd, insn, p); |
766bc656 AM |
8872 | break; |
8873 | } | |
989f9879 AM |
8874 | if (htab->elf.tls_sec != NULL) |
8875 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; | |
7619e7c7 | 8876 | /* The TPREL16 relocs shouldn't really be used in shared |
7c8bbca5 AM |
8877 | libs or with non-local symbols as that will result in |
8878 | DT_TEXTREL being set, but support them anyway. */ | |
7619e7c7 AM |
8879 | goto dodyn; |
8880 | ||
8881 | case R_PPC_TPREL32: | |
989f9879 AM |
8882 | if (htab->elf.tls_sec != NULL) |
8883 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; | |
7619e7c7 AM |
8884 | goto dodyn; |
8885 | ||
8886 | case R_PPC_DTPREL32: | |
989f9879 AM |
8887 | if (htab->elf.tls_sec != NULL) |
8888 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; | |
7619e7c7 AM |
8889 | goto dodyn; |
8890 | ||
e515b051 AM |
8891 | case R_PPC_DTPMOD32: |
8892 | relocation = 1; | |
8893 | addend = 0; | |
8894 | goto dodyn; | |
8895 | ||
d7128ce4 AM |
8896 | case R_PPC_REL16: |
8897 | case R_PPC_REL16_LO: | |
8898 | case R_PPC_REL16_HI: | |
8899 | case R_PPC_REL16_HA: | |
a680de9a | 8900 | case R_PPC_REL16DX_HA: |
d7128ce4 AM |
8901 | break; |
8902 | ||
7619e7c7 | 8903 | case R_PPC_REL32: |
625af618 AM |
8904 | if (h == NULL || h == htab->elf.hgot) |
8905 | break; | |
8906 | /* fall through */ | |
8907 | ||
8908 | case R_PPC_ADDR32: | |
8909 | case R_PPC_ADDR16: | |
8910 | case R_PPC_ADDR16_LO: | |
8911 | case R_PPC_ADDR16_HI: | |
8912 | case R_PPC_ADDR16_HA: | |
8913 | case R_PPC_UADDR32: | |
8914 | case R_PPC_UADDR16: | |
8915 | goto dodyn; | |
8916 | ||
b9c361e0 JL |
8917 | case R_PPC_VLE_REL8: |
8918 | case R_PPC_VLE_REL15: | |
8919 | case R_PPC_VLE_REL24: | |
625af618 | 8920 | case R_PPC_REL24: |
7619e7c7 AM |
8921 | case R_PPC_REL14: |
8922 | case R_PPC_REL14_BRTAKEN: | |
8923 | case R_PPC_REL14_BRNTAKEN: | |
252b5132 RH |
8924 | /* If these relocations are not to a named symbol, they can be |
8925 | handled right here, no need to bother the dynamic linker. */ | |
89200bf8 | 8926 | if (SYMBOL_CALLS_LOCAL (info, h) |
3b36f7e6 | 8927 | || h == htab->elf.hgot) |
252b5132 | 8928 | break; |
70bccea4 | 8929 | /* fall through */ |
252b5132 | 8930 | |
7619e7c7 | 8931 | case R_PPC_ADDR24: |
7619e7c7 AM |
8932 | case R_PPC_ADDR14: |
8933 | case R_PPC_ADDR14_BRTAKEN: | |
8934 | case R_PPC_ADDR14_BRNTAKEN: | |
0e1862bb | 8935 | if (h != NULL && !bfd_link_pic (info)) |
625af618 AM |
8936 | break; |
8937 | /* fall through */ | |
8938 | ||
7619e7c7 | 8939 | dodyn: |
3348747a NS |
8940 | if ((input_section->flags & SEC_ALLOC) == 0 |
8941 | || is_vxworks_tls) | |
c87b5a93 | 8942 | break; |
c87b5a93 | 8943 | |
0e1862bb | 8944 | if ((bfd_link_pic (info) |
89200bf8 AM |
8945 | && !(h != NULL |
8946 | && ((h->root.type == bfd_link_hash_undefined | |
954b63d4 | 8947 | && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
21d68fcd | 8948 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))) |
1d483afe | 8949 | && (must_be_dyn_reloc (info, r_type) |
f6c52c13 | 8950 | || !SYMBOL_CALLS_LOCAL (info, h))) |
ee05f2fe | 8951 | || (ELIMINATE_COPY_RELOCS |
0e1862bb | 8952 | && !bfd_link_pic (info) |
ee05f2fe AM |
8953 | && h != NULL |
8954 | && h->dynindx != -1 | |
f5385ebf | 8955 | && !h->non_got_ref |
d3e454b9 AM |
8956 | && !h->def_regular |
8957 | && !(h->protected_def | |
8958 | && ppc_elf_hash_entry (h)->has_addr16_ha | |
8959 | && ppc_elf_hash_entry (h)->has_addr16_lo | |
8960 | && htab->params->pic_fixup > 0))) | |
252b5132 | 8961 | { |
0bb2d96a | 8962 | int skip; |
f95f8542 AM |
8963 | bfd_byte *loc; |
8964 | asection *sreloc; | |
82e66161 AM |
8965 | long indx = 0; |
8966 | ||
252b5132 | 8967 | #ifdef DEBUG |
55fd94b0 AM |
8968 | fprintf (stderr, "ppc_elf_relocate_section needs to " |
8969 | "create relocation for %s\n", | |
70bccea4 AM |
8970 | (h && h->root.root.string |
8971 | ? h->root.root.string : "<unknown>")); | |
252b5132 RH |
8972 | #endif |
8973 | ||
8974 | /* When generating a shared object, these relocations | |
70bccea4 AM |
8975 | are copied into the output file to be resolved at run |
8976 | time. */ | |
0bb2d96a | 8977 | skip = 0; |
5b914448 AM |
8978 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, info, |
8979 | input_section, | |
8980 | rel->r_offset); | |
0bb2d96a JJ |
8981 | if (outrel.r_offset == (bfd_vma) -1 |
8982 | || outrel.r_offset == (bfd_vma) -2) | |
8983 | skip = (int) outrel.r_offset; | |
252b5132 RH |
8984 | outrel.r_offset += (input_section->output_section->vma |
8985 | + input_section->output_offset); | |
8986 | ||
8987 | if (skip) | |
8988 | memset (&outrel, 0, sizeof outrel); | |
21d68fcd | 8989 | else if (!SYMBOL_REFERENCES_LOCAL (info, h)) |
252b5132 | 8990 | { |
82e66161 AM |
8991 | indx = h->dynindx; |
8992 | BFD_ASSERT (indx != -1); | |
7619e7c7 | 8993 | unresolved_reloc = FALSE; |
82e66161 | 8994 | outrel.r_info = ELF32_R_INFO (indx, r_type); |
252b5132 RH |
8995 | outrel.r_addend = rel->r_addend; |
8996 | } | |
8997 | else | |
8998 | { | |
47388f4c AM |
8999 | outrel.r_addend = relocation + rel->r_addend; |
9000 | ||
25f23106 | 9001 | if (r_type != R_PPC_ADDR32) |
252b5132 | 9002 | { |
25f23106 AM |
9003 | if (ifunc != NULL) |
9004 | { | |
9005 | /* If we get here when building a static | |
9006 | executable, then the libc startup function | |
9007 | responsible for applying indirect function | |
9008 | relocations is going to complain about | |
9009 | the reloc type. | |
9010 | If we get here when building a dynamic | |
9011 | executable, it will be because we have | |
9012 | a text relocation. The dynamic loader | |
9013 | will set the text segment writable and | |
9014 | non-executable to apply text relocations. | |
9015 | So we'll segfault when trying to run the | |
9016 | indirection function to resolve the reloc. */ | |
25f53a85 | 9017 | info->callbacks->einfo |
695344c0 | 9018 | /* xgettext:c-format */ |
174d0a74 | 9019 | (_("%H: relocation %s for indirect " |
25f53a85 AM |
9020 | "function %s unsupported\n"), |
9021 | input_bfd, input_section, rel->r_offset, | |
25f23106 AM |
9022 | howto->name, |
9023 | sym_name); | |
9024 | ret = FALSE; | |
9025 | } | |
cf35638d | 9026 | else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec)) |
89200bf8 | 9027 | ; |
252b5132 RH |
9028 | else if (sec == NULL || sec->owner == NULL) |
9029 | { | |
9030 | bfd_set_error (bfd_error_bad_value); | |
89200bf8 | 9031 | ret = FALSE; |
252b5132 RH |
9032 | } |
9033 | else | |
9034 | { | |
9035 | asection *osec; | |
9036 | ||
47388f4c AM |
9037 | /* We are turning this relocation into one |
9038 | against a section symbol. It would be | |
9039 | proper to subtract the symbol's value, | |
9040 | osec->vma, from the emitted reloc addend, | |
25f23106 AM |
9041 | but ld.so expects buggy relocs. |
9042 | FIXME: Why not always use a zero index? */ | |
252b5132 RH |
9043 | osec = sec->output_section; |
9044 | indx = elf_section_data (osec)->dynindx; | |
74541ad4 AM |
9045 | if (indx == 0) |
9046 | { | |
9047 | osec = htab->elf.text_index_section; | |
9048 | indx = elf_section_data (osec)->dynindx; | |
9049 | } | |
9050 | BFD_ASSERT (indx != 0); | |
252b5132 | 9051 | #ifdef DEBUG |
74541ad4 | 9052 | if (indx == 0) |
e460dd0d | 9053 | printf ("indx=%ld section=%s flags=%08x name=%s\n", |
55fd94b0 AM |
9054 | indx, osec->name, osec->flags, |
9055 | h->root.root.string); | |
252b5132 RH |
9056 | #endif |
9057 | } | |
9058 | ||
9059 | outrel.r_info = ELF32_R_INFO (indx, r_type); | |
252b5132 | 9060 | } |
25f23106 AM |
9061 | else if (ifunc != NULL) |
9062 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
9063 | else | |
9064 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
252b5132 RH |
9065 | } |
9066 | ||
82e66161 AM |
9067 | sreloc = elf_section_data (input_section)->sreloc; |
9068 | if (ifunc) | |
9069 | { | |
9070 | sreloc = htab->elf.irelplt; | |
9071 | if (indx == 0) | |
9072 | htab->local_ifunc_resolver = 1; | |
9073 | else if (is_static_defined (h)) | |
9074 | htab->maybe_local_ifunc_resolver = 1; | |
9075 | } | |
9076 | if (sreloc == NULL) | |
9077 | return FALSE; | |
9078 | ||
947216bf AM |
9079 | loc = sreloc->contents; |
9080 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
9081 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 | 9082 | |
2243deae | 9083 | if (skip == -1) |
c316a17c | 9084 | goto copy_reloc; |
2243deae | 9085 | |
f0158f44 AM |
9086 | /* This reloc will be computed at runtime. Clear the memory |
9087 | so that it contains a predictable value for prelink. */ | |
9088 | if (!skip) | |
2243deae L |
9089 | { |
9090 | relocation = howto->pc_relative ? outrel.r_offset : 0; | |
9091 | addend = 0; | |
9092 | break; | |
9093 | } | |
252b5132 | 9094 | } |
252b5132 RH |
9095 | break; |
9096 | ||
32af9f6e AM |
9097 | case R_PPC_RELAX_PLT: |
9098 | case R_PPC_RELAX_PLTREL24: | |
de972ffa AM |
9099 | if (h != NULL) |
9100 | { | |
32af9f6e AM |
9101 | struct plt_entry *ent; |
9102 | bfd_vma got2_addend = 0; | |
9103 | ||
9104 | if (r_type == R_PPC_RELAX_PLTREL24) | |
9105 | { | |
0e1862bb | 9106 | if (bfd_link_pic (info)) |
32af9f6e AM |
9107 | got2_addend = addend; |
9108 | addend = 0; | |
9109 | } | |
9110 | ent = find_plt_ent (&h->plt.plist, got2, got2_addend); | |
de972ffa AM |
9111 | if (htab->plt_type == PLT_NEW) |
9112 | relocation = (htab->glink->output_section->vma | |
9113 | + htab->glink->output_offset | |
9114 | + ent->glink_offset); | |
9115 | else | |
ce558b89 AM |
9116 | relocation = (htab->elf.splt->output_section->vma |
9117 | + htab->elf.splt->output_offset | |
de972ffa AM |
9118 | + ent->plt.offset); |
9119 | } | |
1a0670f3 | 9120 | /* Fall through. */ |
b4a38de6 | 9121 | |
32af9f6e | 9122 | case R_PPC_RELAX: |
9abc968f | 9123 | { |
53291d1f AM |
9124 | const int *stub; |
9125 | size_t size; | |
9126 | size_t insn_offset = rel->r_offset; | |
9127 | unsigned int insn; | |
9abc968f | 9128 | |
0e1862bb | 9129 | if (bfd_link_pic (info)) |
53291d1f AM |
9130 | { |
9131 | relocation -= (input_section->output_section->vma | |
9132 | + input_section->output_offset | |
9133 | + rel->r_offset - 4); | |
9134 | stub = shared_stub_entry; | |
95f0d0d2 AM |
9135 | bfd_put_32 (input_bfd, stub[0], contents + insn_offset - 12); |
9136 | bfd_put_32 (input_bfd, stub[1], contents + insn_offset - 8); | |
9137 | bfd_put_32 (input_bfd, stub[2], contents + insn_offset - 4); | |
53291d1f AM |
9138 | stub += 3; |
9139 | size = ARRAY_SIZE (shared_stub_entry) - 3; | |
9140 | } | |
9141 | else | |
9142 | { | |
9143 | stub = stub_entry; | |
9144 | size = ARRAY_SIZE (stub_entry); | |
9145 | } | |
9abc968f | 9146 | |
9abc968f | 9147 | relocation += addend; |
0e1862bb | 9148 | if (bfd_link_relocatable (info)) |
53291d1f AM |
9149 | relocation = 0; |
9150 | ||
9151 | /* First insn is HA, second is LO. */ | |
9152 | insn = *stub++; | |
9153 | insn |= ((relocation + 0x8000) >> 16) & 0xffff; | |
95f0d0d2 | 9154 | bfd_put_32 (input_bfd, insn, contents + insn_offset); |
53291d1f AM |
9155 | insn_offset += 4; |
9156 | ||
9157 | insn = *stub++; | |
9158 | insn |= relocation & 0xffff; | |
95f0d0d2 | 9159 | bfd_put_32 (input_bfd, insn, contents + insn_offset); |
53291d1f AM |
9160 | insn_offset += 4; |
9161 | size -= 2; | |
9162 | ||
9163 | while (size != 0) | |
9164 | { | |
9165 | insn = *stub++; | |
9166 | --size; | |
95f0d0d2 | 9167 | bfd_put_32 (input_bfd, insn, contents + insn_offset); |
53291d1f AM |
9168 | insn_offset += 4; |
9169 | } | |
9bc4e62b NS |
9170 | |
9171 | /* Rewrite the reloc and convert one of the trailing nop | |
9172 | relocs to describe this relocation. */ | |
9173 | BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE); | |
9174 | /* The relocs are at the bottom 2 bytes */ | |
c316a17c AM |
9175 | wrel->r_offset = rel->r_offset + d_offset; |
9176 | wrel->r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); | |
9177 | wrel->r_addend = rel->r_addend; | |
9178 | memmove (wrel + 1, wrel, (relend - wrel - 1) * sizeof (*wrel)); | |
9179 | wrel++, rel++; | |
9180 | wrel->r_offset += 4; | |
9181 | wrel->r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); | |
9abc968f | 9182 | } |
8517fae7 | 9183 | continue; |
deaaf2f3 | 9184 | |
70bccea4 | 9185 | /* Indirect .sdata relocation. */ |
7619e7c7 | 9186 | case R_PPC_EMB_SDAI16: |
c9a2f333 | 9187 | BFD_ASSERT (htab->sdata[0].section != NULL); |
bd6c6e2b AM |
9188 | if (!is_static_defined (htab->sdata[0].sym)) |
9189 | { | |
9190 | unresolved_reloc = TRUE; | |
9191 | break; | |
9192 | } | |
7619e7c7 | 9193 | relocation |
76750a2f AM |
9194 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0], |
9195 | h, relocation, rel); | |
bd6c6e2b | 9196 | addend = 0; |
252b5132 RH |
9197 | break; |
9198 | ||
70bccea4 | 9199 | /* Indirect .sdata2 relocation. */ |
7619e7c7 | 9200 | case R_PPC_EMB_SDA2I16: |
c9a2f333 | 9201 | BFD_ASSERT (htab->sdata[1].section != NULL); |
bd6c6e2b AM |
9202 | if (!is_static_defined (htab->sdata[1].sym)) |
9203 | { | |
9204 | unresolved_reloc = TRUE; | |
9205 | break; | |
9206 | } | |
7619e7c7 | 9207 | relocation |
76750a2f AM |
9208 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1], |
9209 | h, relocation, rel); | |
bd6c6e2b | 9210 | addend = 0; |
252b5132 RH |
9211 | break; |
9212 | ||
70bccea4 AM |
9213 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
9214 | section, not the actual VMA. This is appropriate when generating | |
9215 | an embedded ELF object, for which the .got section acts like the | |
9216 | AIX .toc section. */ | |
7619e7c7 | 9217 | case R_PPC_TOC16: /* phony GOT16 relocations */ |
3b4f3a11 AM |
9218 | if (sec == NULL || sec->output_section == NULL) |
9219 | { | |
9220 | unresolved_reloc = TRUE; | |
9221 | break; | |
9222 | } | |
a0f49396 NC |
9223 | BFD_ASSERT (strcmp (bfd_get_section_name (sec->owner, sec), |
9224 | ".got") == 0 | |
9225 | || strcmp (bfd_get_section_name (sec->owner, sec), | |
9226 | ".cgot") == 0); | |
252b5132 | 9227 | |
3b4f3a11 | 9228 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; |
252b5132 RH |
9229 | break; |
9230 | ||
7619e7c7 | 9231 | case R_PPC_PLTREL24: |
f75e0e33 AM |
9232 | if (h != NULL && ifunc == NULL) |
9233 | { | |
cbf95972 AM |
9234 | struct plt_entry *ent; |
9235 | ||
9236 | ent = find_plt_ent (&h->plt.plist, got2, | |
9237 | bfd_link_pic (info) ? addend : 0); | |
f75e0e33 | 9238 | if (ent == NULL |
ce558b89 | 9239 | || htab->elf.splt == NULL) |
f75e0e33 AM |
9240 | { |
9241 | /* We didn't make a PLT entry for this symbol. This | |
9242 | happens when statically linking PIC code, or when | |
9243 | using -Bsymbolic. */ | |
9244 | } | |
9245 | else | |
9246 | { | |
9247 | /* Relocation is to the entry for this symbol in the | |
9248 | procedure linkage table. */ | |
9249 | unresolved_reloc = FALSE; | |
9250 | if (htab->plt_type == PLT_NEW) | |
9251 | relocation = (htab->glink->output_section->vma | |
9252 | + htab->glink->output_offset | |
9253 | + ent->glink_offset); | |
9254 | else | |
ce558b89 AM |
9255 | relocation = (htab->elf.splt->output_section->vma |
9256 | + htab->elf.splt->output_offset | |
f75e0e33 AM |
9257 | + ent->plt.offset); |
9258 | } | |
9259 | } | |
252b5132 | 9260 | |
f75e0e33 AM |
9261 | /* R_PPC_PLTREL24 is rather special. If non-zero, the |
9262 | addend specifies the GOT pointer offset within .got2. | |
9263 | Don't apply it to the relocation field. */ | |
9264 | addend = 0; | |
8da6118f | 9265 | break; |
252b5132 | 9266 | |
70bccea4 | 9267 | /* Relocate against _SDA_BASE_. */ |
7619e7c7 | 9268 | case R_PPC_SDAREL16: |
252b5132 RH |
9269 | { |
9270 | const char *name; | |
bd6c6e2b | 9271 | struct elf_link_hash_entry *sda = htab->sdata[0].sym; |
252b5132 | 9272 | |
bd6c6e2b AM |
9273 | if (sec == NULL |
9274 | || sec->output_section == NULL | |
9275 | || !is_static_defined (sda)) | |
3b4f3a11 AM |
9276 | { |
9277 | unresolved_reloc = TRUE; | |
9278 | break; | |
9279 | } | |
bd6c6e2b | 9280 | addend -= SYM_VAL (sda); |
3b4f3a11 | 9281 | |
a0f49396 | 9282 | name = bfd_get_section_name (output_bfd, sec->output_section); |
93d1b056 AM |
9283 | if (!(strcmp (name, ".sdata") == 0 |
9284 | || strcmp (name, ".sbss") == 0)) | |
252b5132 | 9285 | { |
25f53a85 | 9286 | info->callbacks->einfo |
695344c0 | 9287 | /* xgettext:c-format */ |
8de848d8 | 9288 | (_("%P: %B: the target (%s) of a %s relocation is " |
25f53a85 | 9289 | "in the wrong output section (%s)\n"), |
d003868e | 9290 | input_bfd, |
55fd94b0 AM |
9291 | sym_name, |
9292 | howto->name, | |
9293 | name); | |
252b5132 | 9294 | } |
252b5132 RH |
9295 | } |
9296 | break; | |
9297 | ||
70bccea4 | 9298 | /* Relocate against _SDA2_BASE_. */ |
7619e7c7 | 9299 | case R_PPC_EMB_SDA2REL: |
252b5132 RH |
9300 | { |
9301 | const char *name; | |
bd6c6e2b | 9302 | struct elf_link_hash_entry *sda = htab->sdata[1].sym; |
252b5132 | 9303 | |
bd6c6e2b AM |
9304 | if (sec == NULL |
9305 | || sec->output_section == NULL | |
9306 | || !is_static_defined (sda)) | |
3b4f3a11 AM |
9307 | { |
9308 | unresolved_reloc = TRUE; | |
9309 | break; | |
9310 | } | |
bd6c6e2b | 9311 | addend -= SYM_VAL (sda); |
3b4f3a11 | 9312 | |
a0f49396 | 9313 | name = bfd_get_section_name (output_bfd, sec->output_section); |
93d1b056 AM |
9314 | if (!(strcmp (name, ".sdata2") == 0 |
9315 | || strcmp (name, ".sbss2") == 0)) | |
252b5132 | 9316 | { |
25f53a85 | 9317 | info->callbacks->einfo |
695344c0 | 9318 | /* xgettext:c-format */ |
8de848d8 | 9319 | (_("%P: %B: the target (%s) of a %s relocation is " |
25f53a85 | 9320 | "in the wrong output section (%s)\n"), |
d003868e | 9321 | input_bfd, |
55fd94b0 AM |
9322 | sym_name, |
9323 | howto->name, | |
9324 | name); | |
252b5132 | 9325 | } |
252b5132 RH |
9326 | } |
9327 | break; | |
9328 | ||
b9c361e0 | 9329 | case R_PPC_VLE_LO16A: |
86c95733 | 9330 | relocation = relocation + addend; |
08dc996f AM |
9331 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9332 | contents + rel->r_offset, relocation, | |
9333 | split16a_type, htab->params->vle_reloc_fixup); | |
c316a17c | 9334 | goto copy_reloc; |
b9c361e0 JL |
9335 | |
9336 | case R_PPC_VLE_LO16D: | |
86c95733 | 9337 | relocation = relocation + addend; |
08dc996f AM |
9338 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9339 | contents + rel->r_offset, relocation, | |
9340 | split16d_type, htab->params->vle_reloc_fixup); | |
c316a17c | 9341 | goto copy_reloc; |
b9c361e0 JL |
9342 | |
9343 | case R_PPC_VLE_HI16A: | |
86c95733 | 9344 | relocation = (relocation + addend) >> 16; |
08dc996f AM |
9345 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9346 | contents + rel->r_offset, relocation, | |
9347 | split16a_type, htab->params->vle_reloc_fixup); | |
c316a17c | 9348 | goto copy_reloc; |
b9c361e0 JL |
9349 | |
9350 | case R_PPC_VLE_HI16D: | |
86c95733 | 9351 | relocation = (relocation + addend) >> 16; |
08dc996f AM |
9352 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9353 | contents + rel->r_offset, relocation, | |
9354 | split16d_type, htab->params->vle_reloc_fixup); | |
c316a17c | 9355 | goto copy_reloc; |
b9c361e0 JL |
9356 | |
9357 | case R_PPC_VLE_HA16A: | |
86c95733 | 9358 | relocation = (relocation + addend + 0x8000) >> 16; |
08dc996f AM |
9359 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9360 | contents + rel->r_offset, relocation, | |
9361 | split16a_type, htab->params->vle_reloc_fixup); | |
c316a17c | 9362 | goto copy_reloc; |
b9c361e0 JL |
9363 | |
9364 | case R_PPC_VLE_HA16D: | |
86c95733 | 9365 | relocation = (relocation + addend + 0x8000) >> 16; |
08dc996f AM |
9366 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9367 | contents + rel->r_offset, relocation, | |
9368 | split16d_type, htab->params->vle_reloc_fixup); | |
c316a17c | 9369 | goto copy_reloc; |
b9c361e0 | 9370 | |
70bccea4 | 9371 | /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */ |
7619e7c7 | 9372 | case R_PPC_EMB_SDA21: |
b9c361e0 | 9373 | case R_PPC_VLE_SDA21: |
7619e7c7 | 9374 | case R_PPC_EMB_RELSDA: |
b9c361e0 | 9375 | case R_PPC_VLE_SDA21_LO: |
252b5132 RH |
9376 | { |
9377 | const char *name; | |
9378 | int reg; | |
86c95733 | 9379 | unsigned int insn; |
bd6c6e2b | 9380 | struct elf_link_hash_entry *sda = NULL; |
252b5132 | 9381 | |
3b4f3a11 AM |
9382 | if (sec == NULL || sec->output_section == NULL) |
9383 | { | |
9384 | unresolved_reloc = TRUE; | |
9385 | break; | |
9386 | } | |
9387 | ||
a0f49396 | 9388 | name = bfd_get_section_name (output_bfd, sec->output_section); |
93d1b056 AM |
9389 | if (strcmp (name, ".sdata") == 0 |
9390 | || strcmp (name, ".sbss") == 0) | |
252b5132 RH |
9391 | { |
9392 | reg = 13; | |
bd6c6e2b | 9393 | sda = htab->sdata[0].sym; |
252b5132 | 9394 | } |
93d1b056 AM |
9395 | else if (strcmp (name, ".sdata2") == 0 |
9396 | || strcmp (name, ".sbss2") == 0) | |
252b5132 RH |
9397 | { |
9398 | reg = 2; | |
bd6c6e2b | 9399 | sda = htab->sdata[1].sym; |
252b5132 | 9400 | } |
8da6118f KH |
9401 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 |
9402 | || strcmp (name, ".PPC.EMB.sbss0") == 0) | |
252b5132 RH |
9403 | { |
9404 | reg = 0; | |
9405 | } | |
252b5132 RH |
9406 | else |
9407 | { | |
25f53a85 | 9408 | info->callbacks->einfo |
695344c0 | 9409 | /* xgettext:c-format */ |
8de848d8 | 9410 | (_("%P: %B: the target (%s) of a %s relocation is " |
25f53a85 | 9411 | "in the wrong output section (%s)\n"), |
d003868e | 9412 | input_bfd, |
55fd94b0 AM |
9413 | sym_name, |
9414 | howto->name, | |
9415 | name); | |
252b5132 RH |
9416 | |
9417 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 9418 | ret = FALSE; |
c316a17c | 9419 | goto copy_reloc; |
252b5132 RH |
9420 | } |
9421 | ||
bd6c6e2b AM |
9422 | if (sda != NULL) |
9423 | { | |
9424 | if (!is_static_defined (sda)) | |
9425 | { | |
9426 | unresolved_reloc = TRUE; | |
9427 | break; | |
9428 | } | |
9429 | addend -= SYM_VAL (sda); | |
9430 | } | |
9431 | ||
95f0d0d2 | 9432 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); |
b9c361e0 JL |
9433 | if (reg == 0 |
9434 | && (r_type == R_PPC_VLE_SDA21 | |
9435 | || r_type == R_PPC_VLE_SDA21_LO)) | |
9436 | { | |
86c95733 AM |
9437 | relocation = relocation + addend; |
9438 | addend = 0; | |
9439 | ||
9440 | /* Force e_li insn, keeping RT from original insn. */ | |
9441 | insn &= 0x1f << 21; | |
9442 | insn |= 28u << 26; | |
9443 | ||
9444 | /* We have an li20 field, bits 17..20, 11..15, 21..31. */ | |
9445 | /* Top 4 bits of value to 17..20. */ | |
9446 | insn |= (relocation & 0xf0000) >> 5; | |
9447 | /* Next 5 bits of the value to 11..15. */ | |
9448 | insn |= (relocation & 0xf800) << 5; | |
9449 | /* And the final 11 bits of the value to bits 21 to 31. */ | |
9450 | insn |= relocation & 0x7ff; | |
9451 | ||
95f0d0d2 | 9452 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); |
c3301df1 AM |
9453 | |
9454 | if (r_type == R_PPC_VLE_SDA21 | |
9455 | && ((relocation + 0x80000) & 0xffffffff) > 0x100000) | |
9456 | goto overflow; | |
c316a17c | 9457 | goto copy_reloc; |
b9c361e0 JL |
9458 | } |
9459 | else if (r_type == R_PPC_EMB_SDA21 | |
9460 | || r_type == R_PPC_VLE_SDA21 | |
9461 | || r_type == R_PPC_VLE_SDA21_LO) | |
91d6fa6a | 9462 | { |
86c95733 | 9463 | /* Fill in register field. */ |
252b5132 | 9464 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); |
252b5132 | 9465 | } |
95f0d0d2 | 9466 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); |
252b5132 RH |
9467 | } |
9468 | break; | |
9469 | ||
b9c361e0 JL |
9470 | case R_PPC_VLE_SDAREL_LO16A: |
9471 | case R_PPC_VLE_SDAREL_LO16D: | |
9472 | case R_PPC_VLE_SDAREL_HI16A: | |
9473 | case R_PPC_VLE_SDAREL_HI16D: | |
9474 | case R_PPC_VLE_SDAREL_HA16A: | |
9475 | case R_PPC_VLE_SDAREL_HA16D: | |
9476 | { | |
9477 | bfd_vma value; | |
9478 | const char *name; | |
b9c361e0 JL |
9479 | struct elf_link_hash_entry *sda = NULL; |
9480 | ||
9481 | if (sec == NULL || sec->output_section == NULL) | |
9482 | { | |
9483 | unresolved_reloc = TRUE; | |
9484 | break; | |
9485 | } | |
9486 | ||
a0f49396 | 9487 | name = bfd_get_section_name (output_bfd, sec->output_section); |
93d1b056 AM |
9488 | if (strcmp (name, ".sdata") == 0 |
9489 | || strcmp (name, ".sbss") == 0) | |
5499c7c7 | 9490 | sda = htab->sdata[0].sym; |
93d1b056 AM |
9491 | else if (strcmp (name, ".sdata2") == 0 |
9492 | || strcmp (name, ".sbss2") == 0) | |
5499c7c7 | 9493 | sda = htab->sdata[1].sym; |
b9c361e0 JL |
9494 | else |
9495 | { | |
4eca0228 | 9496 | _bfd_error_handler |
695344c0 | 9497 | /* xgettext:c-format */ |
b9c361e0 JL |
9498 | (_("%B: the target (%s) of a %s relocation is " |
9499 | "in the wrong output section (%s)"), | |
9500 | input_bfd, | |
9501 | sym_name, | |
9502 | howto->name, | |
9503 | name); | |
9504 | ||
9505 | bfd_set_error (bfd_error_bad_value); | |
9506 | ret = FALSE; | |
c316a17c | 9507 | goto copy_reloc; |
b9c361e0 JL |
9508 | } |
9509 | ||
5499c7c7 | 9510 | if (sda == NULL || !is_static_defined (sda)) |
b9c361e0 | 9511 | { |
5499c7c7 AM |
9512 | unresolved_reloc = TRUE; |
9513 | break; | |
b9c361e0 | 9514 | } |
5499c7c7 | 9515 | value = relocation + addend - SYM_VAL (sda); |
86c95733 AM |
9516 | |
9517 | if (r_type == R_PPC_VLE_SDAREL_LO16A) | |
08dc996f AM |
9518 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9519 | contents + rel->r_offset, value, | |
9520 | split16a_type, | |
9521 | htab->params->vle_reloc_fixup); | |
86c95733 | 9522 | else if (r_type == R_PPC_VLE_SDAREL_LO16D) |
08dc996f AM |
9523 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9524 | contents + rel->r_offset, value, | |
9525 | split16d_type, | |
9526 | htab->params->vle_reloc_fixup); | |
86c95733 | 9527 | else if (r_type == R_PPC_VLE_SDAREL_HI16A) |
b9c361e0 | 9528 | { |
86c95733 | 9529 | value = value >> 16; |
08dc996f AM |
9530 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9531 | contents + rel->r_offset, value, | |
9532 | split16a_type, | |
9533 | htab->params->vle_reloc_fixup); | |
b9c361e0 | 9534 | } |
86c95733 | 9535 | else if (r_type == R_PPC_VLE_SDAREL_HI16D) |
b9c361e0 | 9536 | { |
86c95733 | 9537 | value = value >> 16; |
08dc996f AM |
9538 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9539 | contents + rel->r_offset, value, | |
9540 | split16d_type, | |
9541 | htab->params->vle_reloc_fixup); | |
b9c361e0 | 9542 | } |
86c95733 | 9543 | else if (r_type == R_PPC_VLE_SDAREL_HA16A) |
b9c361e0 | 9544 | { |
86c95733 | 9545 | value = (value + 0x8000) >> 16; |
08dc996f AM |
9546 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9547 | contents + rel->r_offset, value, | |
9548 | split16a_type, | |
9549 | htab->params->vle_reloc_fixup); | |
b9c361e0 | 9550 | } |
86c95733 | 9551 | else if (r_type == R_PPC_VLE_SDAREL_HA16D) |
b9c361e0 | 9552 | { |
86c95733 | 9553 | value = (value + 0x8000) >> 16; |
08dc996f AM |
9554 | ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset, |
9555 | contents + rel->r_offset, value, | |
9556 | split16d_type, | |
9557 | htab->params->vle_reloc_fixup); | |
b9c361e0 JL |
9558 | } |
9559 | } | |
c316a17c | 9560 | goto copy_reloc; |
b9c361e0 | 9561 | |
83eef883 AFB |
9562 | case R_PPC_VLE_ADDR20: |
9563 | ppc_elf_vle_split20 (output_bfd, contents + rel->r_offset, relocation); | |
9564 | continue; | |
9565 | ||
70bccea4 | 9566 | /* Relocate against the beginning of the section. */ |
7619e7c7 AM |
9567 | case R_PPC_SECTOFF: |
9568 | case R_PPC_SECTOFF_LO: | |
9569 | case R_PPC_SECTOFF_HI: | |
9570 | case R_PPC_SECTOFF_HA: | |
3b4f3a11 AM |
9571 | if (sec == NULL || sec->output_section == NULL) |
9572 | { | |
9573 | unresolved_reloc = TRUE; | |
9574 | break; | |
9575 | } | |
252b5132 | 9576 | addend -= sec->output_section->vma; |
252b5132 RH |
9577 | break; |
9578 | ||
70bccea4 | 9579 | /* Negative relocations. */ |
7619e7c7 AM |
9580 | case R_PPC_EMB_NADDR32: |
9581 | case R_PPC_EMB_NADDR16: | |
9582 | case R_PPC_EMB_NADDR16_LO: | |
9583 | case R_PPC_EMB_NADDR16_HI: | |
9584 | case R_PPC_EMB_NADDR16_HA: | |
8da6118f | 9585 | addend -= 2 * relocation; |
252b5132 RH |
9586 | break; |
9587 | ||
7619e7c7 AM |
9588 | case R_PPC_COPY: |
9589 | case R_PPC_GLOB_DAT: | |
9590 | case R_PPC_JMP_SLOT: | |
9591 | case R_PPC_RELATIVE: | |
e054468f | 9592 | case R_PPC_IRELATIVE: |
7619e7c7 AM |
9593 | case R_PPC_PLT32: |
9594 | case R_PPC_PLTREL32: | |
9595 | case R_PPC_PLT16_LO: | |
9596 | case R_PPC_PLT16_HI: | |
9597 | case R_PPC_PLT16_HA: | |
9598 | case R_PPC_ADDR30: | |
9599 | case R_PPC_EMB_RELSEC16: | |
9600 | case R_PPC_EMB_RELST_LO: | |
9601 | case R_PPC_EMB_RELST_HI: | |
9602 | case R_PPC_EMB_RELST_HA: | |
9603 | case R_PPC_EMB_BIT_FLD: | |
25f53a85 | 9604 | info->callbacks->einfo |
695344c0 | 9605 | /* xgettext:c-format */ |
8de848d8 | 9606 | (_("%P: %B: relocation %s is not yet supported for symbol %s\n"), |
d003868e | 9607 | input_bfd, |
7619e7c7 AM |
9608 | howto->name, |
9609 | sym_name); | |
252b5132 RH |
9610 | |
9611 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 9612 | ret = FALSE; |
c316a17c | 9613 | goto copy_reloc; |
7619e7c7 | 9614 | } |
252b5132 | 9615 | |
7619e7c7 AM |
9616 | /* Do any further special processing. */ |
9617 | switch (r_type) | |
9618 | { | |
9619 | default: | |
9620 | break; | |
9621 | ||
9622 | case R_PPC_ADDR16_HA: | |
d7128ce4 | 9623 | case R_PPC_REL16_HA: |
a680de9a | 9624 | case R_PPC_REL16DX_HA: |
7619e7c7 AM |
9625 | case R_PPC_SECTOFF_HA: |
9626 | case R_PPC_TPREL16_HA: | |
9627 | case R_PPC_DTPREL16_HA: | |
7619e7c7 AM |
9628 | case R_PPC_EMB_NADDR16_HA: |
9629 | case R_PPC_EMB_RELST_HA: | |
9630 | /* It's just possible that this symbol is a weak symbol | |
7b609f53 | 9631 | that's not actually defined anywhere. In that case, |
7619e7c7 AM |
9632 | 'sec' would be NULL, and we should leave the symbol |
9633 | alone (it will be set to zero elsewhere in the link). */ | |
5c5f6e17 AM |
9634 | if (sec == NULL) |
9635 | break; | |
1a0670f3 | 9636 | /* Fall through. */ |
5c5f6e17 AM |
9637 | |
9638 | case R_PPC_PLT16_HA: | |
9639 | case R_PPC_GOT16_HA: | |
9640 | case R_PPC_GOT_TLSGD16_HA: | |
9641 | case R_PPC_GOT_TLSLD16_HA: | |
9642 | case R_PPC_GOT_TPREL16_HA: | |
9643 | case R_PPC_GOT_DTPREL16_HA: | |
9644 | /* Add 0x10000 if sign bit in 0:15 is set. | |
9645 | Bits 0:15 are not used. */ | |
9646 | addend += 0x8000; | |
7619e7c7 | 9647 | break; |
1fe532cf AM |
9648 | |
9649 | case R_PPC_ADDR16: | |
9650 | case R_PPC_ADDR16_LO: | |
9651 | case R_PPC_GOT16: | |
9652 | case R_PPC_GOT16_LO: | |
9653 | case R_PPC_SDAREL16: | |
9654 | case R_PPC_SECTOFF: | |
9655 | case R_PPC_SECTOFF_LO: | |
9656 | case R_PPC_DTPREL16: | |
9657 | case R_PPC_DTPREL16_LO: | |
9658 | case R_PPC_TPREL16: | |
9659 | case R_PPC_TPREL16_LO: | |
9660 | case R_PPC_GOT_TLSGD16: | |
9661 | case R_PPC_GOT_TLSGD16_LO: | |
9662 | case R_PPC_GOT_TLSLD16: | |
9663 | case R_PPC_GOT_TLSLD16_LO: | |
9664 | case R_PPC_GOT_DTPREL16: | |
9665 | case R_PPC_GOT_DTPREL16_LO: | |
9666 | case R_PPC_GOT_TPREL16: | |
9667 | case R_PPC_GOT_TPREL16_LO: | |
9668 | { | |
9669 | /* The 32-bit ABI lacks proper relocations to deal with | |
9670 | certain 64-bit instructions. Prevent damage to bits | |
9671 | that make up part of the insn opcode. */ | |
9672 | unsigned int insn, mask, lobit; | |
9673 | ||
95f0d0d2 | 9674 | insn = bfd_get_32 (input_bfd, |
c316a17c | 9675 | contents + rel->r_offset - d_offset); |
1fe532cf AM |
9676 | mask = 0; |
9677 | if (is_insn_ds_form (insn)) | |
9678 | mask = 3; | |
9679 | else if (is_insn_dq_form (insn)) | |
9680 | mask = 15; | |
9681 | else | |
9682 | break; | |
a680de9a PB |
9683 | relocation += addend; |
9684 | addend = insn & mask; | |
9685 | lobit = mask & relocation; | |
1fe532cf AM |
9686 | if (lobit != 0) |
9687 | { | |
a680de9a | 9688 | relocation ^= lobit; |
1fe532cf | 9689 | info->callbacks->einfo |
695344c0 | 9690 | /* xgettext:c-format */ |
174d0a74 | 9691 | (_("%H: error: %s against `%s' not a multiple of %u\n"), |
1fe532cf AM |
9692 | input_bfd, input_section, rel->r_offset, |
9693 | howto->name, sym_name, mask + 1); | |
9694 | bfd_set_error (bfd_error_bad_value); | |
9695 | ret = FALSE; | |
9696 | } | |
1fe532cf AM |
9697 | } |
9698 | break; | |
252b5132 RH |
9699 | } |
9700 | ||
252b5132 | 9701 | #ifdef DEBUG |
55fd94b0 AM |
9702 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, " |
9703 | "offset = %ld, addend = %ld\n", | |
252b5132 | 9704 | howto->name, |
8da6118f | 9705 | (int) r_type, |
252b5132 RH |
9706 | sym_name, |
9707 | r_symndx, | |
7619e7c7 | 9708 | (long) rel->r_offset, |
8da6118f | 9709 | (long) addend); |
252b5132 RH |
9710 | #endif |
9711 | ||
7619e7c7 AM |
9712 | if (unresolved_reloc |
9713 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
1d5316ab AM |
9714 | && h->def_dynamic) |
9715 | && _bfd_elf_section_offset (output_bfd, info, input_section, | |
9716 | rel->r_offset) != (bfd_vma) -1) | |
7619e7c7 | 9717 | { |
25f53a85 | 9718 | info->callbacks->einfo |
695344c0 | 9719 | /* xgettext:c-format */ |
174d0a74 | 9720 | (_("%H: unresolvable %s relocation against symbol `%s'\n"), |
25f53a85 | 9721 | input_bfd, input_section, rel->r_offset, |
7b609f53 | 9722 | howto->name, |
7619e7c7 AM |
9723 | sym_name); |
9724 | ret = FALSE; | |
9725 | } | |
9726 | ||
86c95733 AM |
9727 | /* 16-bit fields in insns mostly have signed values, but a |
9728 | few insns have 16-bit unsigned values. Really, we should | |
9729 | have different reloc types. */ | |
9730 | if (howto->complain_on_overflow != complain_overflow_dont | |
9731 | && howto->dst_mask == 0xffff | |
9732 | && (input_section->flags & SEC_CODE) != 0) | |
9733 | { | |
9734 | enum complain_overflow complain = complain_overflow_signed; | |
9735 | ||
9736 | if ((elf_section_flags (input_section) & SHF_PPC_VLE) == 0) | |
9737 | { | |
9738 | unsigned int insn; | |
9739 | ||
9740 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); | |
a47622ac AM |
9741 | if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */) |
9742 | complain = complain_overflow_bitfield; | |
9743 | else if ((insn & (0x3f << 26)) == 28u << 26 /* andi */ | |
9744 | || (insn & (0x3f << 26)) == 24u << 26 /* ori */ | |
9745 | || (insn & (0x3f << 26)) == 26u << 26 /* xori */) | |
86c95733 AM |
9746 | complain = complain_overflow_unsigned; |
9747 | } | |
9748 | if (howto->complain_on_overflow != complain) | |
9749 | { | |
9750 | alt_howto = *howto; | |
9751 | alt_howto.complain_on_overflow = complain; | |
9752 | howto = &alt_howto; | |
9753 | } | |
9754 | } | |
9755 | ||
a680de9a PB |
9756 | if (r_type == R_PPC_REL16DX_HA) |
9757 | { | |
9758 | /* Split field reloc isn't handled by _bfd_final_link_relocate. */ | |
9759 | if (rel->r_offset + 4 > input_section->size) | |
9760 | r = bfd_reloc_outofrange; | |
9761 | else | |
9762 | { | |
9763 | unsigned int insn; | |
9764 | ||
9765 | relocation += addend; | |
9766 | relocation -= (rel->r_offset | |
9767 | + input_section->output_offset | |
9768 | + input_section->output_section->vma); | |
9769 | relocation >>= 16; | |
9770 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
9771 | insn &= ~0x1fffc1; | |
9772 | insn |= (relocation & 0xffc1) | ((relocation & 0x3e) << 15); | |
9773 | bfd_put_32 (input_bfd, insn, contents + rel->r_offset); | |
9774 | r = bfd_reloc_ok; | |
9775 | } | |
9776 | } | |
9777 | else | |
9778 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents, | |
9779 | rel->r_offset, relocation, addend); | |
252b5132 | 9780 | |
7619e7c7 | 9781 | if (r != bfd_reloc_ok) |
252b5132 | 9782 | { |
7619e7c7 | 9783 | if (r == bfd_reloc_overflow) |
252b5132 | 9784 | { |
c3301df1 | 9785 | overflow: |
8131c122 AM |
9786 | /* On code like "if (foo) foo();" don't report overflow |
9787 | on a branch to zero when foo is undefined. */ | |
9788 | if (!warned | |
9789 | && !(h != NULL | |
9790 | && (h->root.type == bfd_link_hash_undefweak | |
9791 | || h->root.type == bfd_link_hash_undefined) | |
9792 | && is_branch_reloc (r_type))) | |
1a72702b AM |
9793 | info->callbacks->reloc_overflow |
9794 | (info, (h ? &h->root : NULL), sym_name, howto->name, | |
9795 | rel->r_addend, input_bfd, input_section, rel->r_offset); | |
dc1bc0c9 RH |
9796 | } |
9797 | else | |
9798 | { | |
25f53a85 | 9799 | info->callbacks->einfo |
695344c0 | 9800 | /* xgettext:c-format */ |
174d0a74 | 9801 | (_("%H: %s reloc against `%s': error %d\n"), |
25f53a85 AM |
9802 | input_bfd, input_section, rel->r_offset, |
9803 | howto->name, sym_name, (int) r); | |
7619e7c7 | 9804 | ret = FALSE; |
252b5132 RH |
9805 | } |
9806 | } | |
c316a17c AM |
9807 | copy_reloc: |
9808 | if (wrel != rel) | |
9809 | *wrel = *rel; | |
9810 | } | |
9811 | ||
9812 | if (wrel != rel) | |
9813 | { | |
9814 | Elf_Internal_Shdr *rel_hdr; | |
9815 | size_t deleted = rel - wrel; | |
9816 | ||
9817 | rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section); | |
9818 | rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted; | |
9819 | if (rel_hdr->sh_size == 0) | |
9820 | { | |
9821 | /* It is too late to remove an empty reloc section. Leave | |
9822 | one NONE reloc. | |
9823 | ??? What is wrong with an empty section??? */ | |
9824 | rel_hdr->sh_size = rel_hdr->sh_entsize; | |
9825 | deleted -= 1; | |
9826 | wrel++; | |
9827 | } | |
9828 | relend = wrel; | |
9829 | rel_hdr = _bfd_elf_single_rel_hdr (input_section); | |
9830 | rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted; | |
9831 | input_section->reloc_count -= deleted; | |
252b5132 RH |
9832 | } |
9833 | ||
252b5132 RH |
9834 | #ifdef DEBUG |
9835 | fprintf (stderr, "\n"); | |
9836 | #endif | |
9837 | ||
53291d1f AM |
9838 | if (input_section->sec_info_type == SEC_INFO_TYPE_TARGET |
9839 | && input_section->size != input_section->rawsize | |
9840 | && (strcmp (input_section->output_section->name, ".init") == 0 | |
9841 | || strcmp (input_section->output_section->name, ".fini") == 0)) | |
9842 | { | |
9843 | /* Branch around the trampolines. */ | |
9844 | unsigned int insn = B + input_section->size - input_section->rawsize; | |
9845 | bfd_put_32 (input_bfd, insn, contents + input_section->rawsize); | |
9846 | } | |
9847 | ||
5446cbdf | 9848 | if (htab->params->ppc476_workaround |
795bc6b3 | 9849 | && input_section->sec_info_type == SEC_INFO_TYPE_TARGET |
0e1862bb | 9850 | && (!bfd_link_relocatable (info) |
795bc6b3 AM |
9851 | || (input_section->output_section->alignment_power |
9852 | >= htab->params->pagesize_p2))) | |
5446cbdf | 9853 | { |
5446cbdf | 9854 | bfd_vma start_addr, end_addr, addr; |
795bc6b3 | 9855 | bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2; |
5446cbdf | 9856 | |
5446cbdf | 9857 | if (relax_info->workaround_size != 0) |
40fd06d1 AM |
9858 | { |
9859 | bfd_byte *p; | |
9860 | unsigned int n; | |
9861 | bfd_byte fill[4]; | |
9862 | ||
9863 | bfd_put_32 (input_bfd, BA, fill); | |
9864 | p = contents + input_section->size - relax_info->workaround_size; | |
9865 | n = relax_info->workaround_size >> 2; | |
9866 | while (n--) | |
9867 | { | |
9868 | memcpy (p, fill, 4); | |
9869 | p += 4; | |
9870 | } | |
9871 | } | |
5446cbdf AM |
9872 | |
9873 | /* The idea is: Replace the last instruction on a page with a | |
9874 | branch to a patch area. Put the insn there followed by a | |
9875 | branch back to the next page. Complicated a little by | |
9876 | needing to handle moved conditional branches, and by not | |
9877 | wanting to touch data-in-text. */ | |
9878 | ||
9879 | start_addr = (input_section->output_section->vma | |
9880 | + input_section->output_offset); | |
9881 | end_addr = (start_addr + input_section->size | |
9882 | - relax_info->workaround_size); | |
9883 | for (addr = ((start_addr & -pagesize) + pagesize - 4); | |
9884 | addr < end_addr; | |
9885 | addr += pagesize) | |
9886 | { | |
9887 | bfd_vma offset = addr - start_addr; | |
9888 | Elf_Internal_Rela *lo, *hi; | |
9889 | bfd_boolean is_data; | |
9890 | bfd_vma patch_off, patch_addr; | |
9891 | unsigned int insn; | |
9892 | ||
9893 | /* Do we have a data reloc at this offset? If so, leave | |
9894 | the word alone. */ | |
9895 | is_data = FALSE; | |
9896 | lo = relocs; | |
668e22e5 AM |
9897 | hi = relend; |
9898 | rel = NULL; | |
5446cbdf AM |
9899 | while (lo < hi) |
9900 | { | |
9901 | rel = lo + (hi - lo) / 2; | |
9902 | if (rel->r_offset < offset) | |
9903 | lo = rel + 1; | |
668e22e5 | 9904 | else if (rel->r_offset > offset + 3) |
5446cbdf AM |
9905 | hi = rel; |
9906 | else | |
9907 | { | |
9908 | switch (ELF32_R_TYPE (rel->r_info)) | |
9909 | { | |
9910 | case R_PPC_ADDR32: | |
9911 | case R_PPC_UADDR32: | |
9912 | case R_PPC_REL32: | |
9913 | case R_PPC_ADDR30: | |
9914 | is_data = TRUE; | |
9915 | break; | |
9916 | default: | |
9917 | break; | |
9918 | } | |
9919 | break; | |
9920 | } | |
9921 | } | |
9922 | if (is_data) | |
9923 | continue; | |
9924 | ||
b4ab4364 AM |
9925 | /* Some instructions can be left alone too. Unconditional |
9926 | branches, except for bcctr with BO=0x14 (bctr, bctrl), | |
9927 | avoid the icache failure. | |
9928 | ||
9929 | The problem occurs due to prefetch across a page boundary | |
9930 | where stale instructions can be fetched from the next | |
9931 | page, and the mechanism for flushing these bad | |
9932 | instructions fails under certain circumstances. The | |
9933 | unconditional branches: | |
9934 | 1) Branch: b, bl, ba, bla, | |
9935 | 2) Branch Conditional: bc, bca, bcl, bcla, | |
9936 | 3) Branch Conditional to Link Register: bclr, bclrl, | |
9937 | where (2) and (3) have BO=0x14 making them unconditional, | |
9938 | prevent the bad prefetch because the prefetch itself is | |
9939 | affected by these instructions. This happens even if the | |
9940 | instruction is not executed. | |
9941 | ||
9942 | A bctr example: | |
9943 | . | |
9944 | . lis 9,new_page@ha | |
9945 | . addi 9,9,new_page@l | |
9946 | . mtctr 9 | |
9947 | . bctr | |
9948 | . nop | |
9949 | . nop | |
9950 | . new_page: | |
9951 | . | |
9952 | The bctr is not predicted taken due to ctr not being | |
9953 | ready, so prefetch continues on past the bctr into the | |
9954 | new page which might have stale instructions. If they | |
9955 | fail to be flushed, then they will be executed after the | |
9956 | bctr executes. Either of the following modifications | |
9957 | prevent the bad prefetch from happening in the first | |
9958 | place: | |
9959 | . | |
1b786873 L |
9960 | . lis 9,new_page@ha lis 9,new_page@ha |
9961 | . addi 9,9,new_page@l addi 9,9,new_page@l | |
9962 | . mtctr 9 mtctr 9 | |
9963 | . bctr bctr | |
b4ab4364 | 9964 | . nop b somewhere_else |
1b786873 L |
9965 | . b somewhere_else nop |
9966 | . new_page: new_page: | |
b4ab4364 | 9967 | . */ |
5446cbdf | 9968 | insn = bfd_get_32 (input_bfd, contents + offset); |
b4ab4364 AM |
9969 | if ((insn & (0x3f << 26)) == (18u << 26) /* b,bl,ba,bla */ |
9970 | || ((insn & (0x3f << 26)) == (16u << 26) /* bc,bcl,bca,bcla*/ | |
9971 | && (insn & (0x14 << 21)) == (0x14 << 21)) /* with BO=0x14 */ | |
5446cbdf | 9972 | || ((insn & (0x3f << 26)) == (19u << 26) |
b4ab4364 AM |
9973 | && (insn & (0x3ff << 1)) == (16u << 1) /* bclr,bclrl */ |
9974 | && (insn & (0x14 << 21)) == (0x14 << 21)))/* with BO=0x14 */ | |
5446cbdf AM |
9975 | continue; |
9976 | ||
9977 | patch_addr = (start_addr + input_section->size | |
9978 | - relax_info->workaround_size); | |
9979 | patch_addr = (patch_addr + 15) & -16; | |
9980 | patch_off = patch_addr - start_addr; | |
9981 | bfd_put_32 (input_bfd, B + patch_off - offset, contents + offset); | |
668e22e5 AM |
9982 | |
9983 | if (rel != NULL | |
9984 | && rel->r_offset >= offset | |
9985 | && rel->r_offset < offset + 4) | |
9986 | { | |
f8b44781 AM |
9987 | asection *sreloc; |
9988 | ||
668e22e5 AM |
9989 | /* If the insn we are patching had a reloc, adjust the |
9990 | reloc r_offset so that the reloc applies to the moved | |
9991 | location. This matters for -r and --emit-relocs. */ | |
9992 | if (rel + 1 != relend) | |
9993 | { | |
9994 | Elf_Internal_Rela tmp = *rel; | |
9995 | ||
9996 | /* Keep the relocs sorted by r_offset. */ | |
9997 | memmove (rel, rel + 1, (relend - (rel + 1)) * sizeof (*rel)); | |
9998 | relend[-1] = tmp; | |
9999 | } | |
10000 | relend[-1].r_offset += patch_off - offset; | |
f8b44781 AM |
10001 | |
10002 | /* Adjust REL16 addends too. */ | |
10003 | switch (ELF32_R_TYPE (relend[-1].r_info)) | |
10004 | { | |
10005 | case R_PPC_REL16: | |
10006 | case R_PPC_REL16_LO: | |
10007 | case R_PPC_REL16_HI: | |
10008 | case R_PPC_REL16_HA: | |
10009 | relend[-1].r_addend += patch_off - offset; | |
10010 | break; | |
10011 | default: | |
10012 | break; | |
10013 | } | |
10014 | ||
10015 | /* If we are building a PIE or shared library with | |
10016 | non-PIC objects, perhaps we had a dynamic reloc too? | |
10017 | If so, the dynamic reloc must move with the insn. */ | |
10018 | sreloc = elf_section_data (input_section)->sreloc; | |
10019 | if (sreloc != NULL) | |
10020 | { | |
1d5c94cb | 10021 | Elf32_External_Rela *slo, *shi, *srelend; |
f8b44781 AM |
10022 | bfd_vma soffset; |
10023 | ||
1d5c94cb AM |
10024 | slo = (Elf32_External_Rela *) sreloc->contents; |
10025 | shi = srelend = slo + sreloc->reloc_count; | |
f8b44781 AM |
10026 | soffset = (offset + input_section->output_section->vma |
10027 | + input_section->output_offset); | |
10028 | while (slo < shi) | |
10029 | { | |
1d5c94cb AM |
10030 | Elf32_External_Rela *srel = slo + (shi - slo) / 2; |
10031 | bfd_elf32_swap_reloca_in (output_bfd, (bfd_byte *) srel, | |
10032 | &outrel); | |
f8b44781 AM |
10033 | if (outrel.r_offset < soffset) |
10034 | slo = srel + 1; | |
10035 | else if (outrel.r_offset > soffset + 3) | |
10036 | shi = srel; | |
10037 | else | |
10038 | { | |
1d5c94cb | 10039 | if (srel + 1 != srelend) |
f8b44781 | 10040 | { |
1d5c94cb AM |
10041 | memmove (srel, srel + 1, |
10042 | (srelend - (srel + 1)) * sizeof (*srel)); | |
10043 | srel = srelend - 1; | |
f8b44781 AM |
10044 | } |
10045 | outrel.r_offset += patch_off - offset; | |
1d5c94cb AM |
10046 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, |
10047 | (bfd_byte *) srel); | |
f8b44781 AM |
10048 | break; |
10049 | } | |
10050 | } | |
10051 | } | |
668e22e5 AM |
10052 | } |
10053 | else | |
10054 | rel = NULL; | |
10055 | ||
5446cbdf AM |
10056 | if ((insn & (0x3f << 26)) == (16u << 26) /* bc */ |
10057 | && (insn & 2) == 0 /* relative */) | |
10058 | { | |
10059 | bfd_vma delta = ((insn & 0xfffc) ^ 0x8000) - 0x8000; | |
10060 | ||
10061 | delta += offset - patch_off; | |
0e1862bb | 10062 | if (bfd_link_relocatable (info) && rel != NULL) |
668e22e5 | 10063 | delta = 0; |
0e1862bb | 10064 | if (!bfd_link_relocatable (info) && rel != NULL) |
668e22e5 AM |
10065 | { |
10066 | enum elf_ppc_reloc_type r_type; | |
10067 | ||
10068 | r_type = ELF32_R_TYPE (relend[-1].r_info); | |
10069 | if (r_type == R_PPC_REL14_BRTAKEN) | |
10070 | insn |= BRANCH_PREDICT_BIT; | |
10071 | else if (r_type == R_PPC_REL14_BRNTAKEN) | |
10072 | insn &= ~BRANCH_PREDICT_BIT; | |
10073 | else | |
10074 | BFD_ASSERT (r_type == R_PPC_REL14); | |
10075 | ||
10076 | if ((r_type == R_PPC_REL14_BRTAKEN | |
10077 | || r_type == R_PPC_REL14_BRNTAKEN) | |
10078 | && delta + 0x8000 < 0x10000 | |
10079 | && (bfd_signed_vma) delta < 0) | |
10080 | insn ^= BRANCH_PREDICT_BIT; | |
10081 | } | |
5446cbdf AM |
10082 | if (delta + 0x8000 < 0x10000) |
10083 | { | |
10084 | bfd_put_32 (input_bfd, | |
10085 | (insn & ~0xfffc) | (delta & 0xfffc), | |
10086 | contents + patch_off); | |
10087 | patch_off += 4; | |
10088 | bfd_put_32 (input_bfd, | |
10089 | B | ((offset + 4 - patch_off) & 0x3fffffc), | |
10090 | contents + patch_off); | |
10091 | patch_off += 4; | |
10092 | } | |
10093 | else | |
10094 | { | |
668e22e5 AM |
10095 | if (rel != NULL) |
10096 | { | |
10097 | unsigned int r_sym = ELF32_R_SYM (relend[-1].r_info); | |
10098 | ||
10099 | relend[-1].r_offset += 8; | |
10100 | relend[-1].r_info = ELF32_R_INFO (r_sym, R_PPC_REL24); | |
10101 | } | |
5446cbdf AM |
10102 | bfd_put_32 (input_bfd, |
10103 | (insn & ~0xfffc) | 8, | |
10104 | contents + patch_off); | |
10105 | patch_off += 4; | |
10106 | bfd_put_32 (input_bfd, | |
10107 | B | ((offset + 4 - patch_off) & 0x3fffffc), | |
10108 | contents + patch_off); | |
10109 | patch_off += 4; | |
10110 | bfd_put_32 (input_bfd, | |
10111 | B | ((delta - 8) & 0x3fffffc), | |
10112 | contents + patch_off); | |
10113 | patch_off += 4; | |
10114 | } | |
10115 | } | |
10116 | else | |
10117 | { | |
10118 | bfd_put_32 (input_bfd, insn, contents + patch_off); | |
10119 | patch_off += 4; | |
10120 | bfd_put_32 (input_bfd, | |
10121 | B | ((offset + 4 - patch_off) & 0x3fffffc), | |
10122 | contents + patch_off); | |
10123 | patch_off += 4; | |
10124 | } | |
10125 | BFD_ASSERT (patch_off <= input_section->size); | |
10126 | relax_info->workaround_size = input_section->size - patch_off; | |
10127 | } | |
10128 | } | |
10129 | ||
252b5132 RH |
10130 | return ret; |
10131 | } | |
252b5132 | 10132 | \f |
25dbc73a AM |
10133 | /* Finish up dynamic symbol handling. We set the contents of various |
10134 | dynamic sections here. */ | |
c5fccbec | 10135 | |
b34976b6 | 10136 | static bfd_boolean |
25dbc73a AM |
10137 | ppc_elf_finish_dynamic_symbol (bfd *output_bfd, |
10138 | struct bfd_link_info *info, | |
10139 | struct elf_link_hash_entry *h, | |
10140 | Elf_Internal_Sym *sym) | |
e1a9cb8e | 10141 | { |
25dbc73a | 10142 | struct ppc_elf_link_hash_table *htab; |
a6aa5195 AM |
10143 | struct plt_entry *ent; |
10144 | bfd_boolean doneone; | |
e1a9cb8e | 10145 | |
25dbc73a AM |
10146 | #ifdef DEBUG |
10147 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", | |
10148 | h->root.root.string); | |
10149 | #endif | |
e1a9cb8e | 10150 | |
25dbc73a AM |
10151 | htab = ppc_elf_hash_table (info); |
10152 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
e1a9cb8e | 10153 | |
a6aa5195 AM |
10154 | doneone = FALSE; |
10155 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
10156 | if (ent->plt.offset != (bfd_vma) -1) | |
10157 | { | |
10158 | if (!doneone) | |
10159 | { | |
10160 | Elf_Internal_Rela rela; | |
10161 | bfd_byte *loc; | |
10162 | bfd_vma reloc_index; | |
e1a9cb8e | 10163 | |
e054468f | 10164 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
10165 | || !htab->elf.dynamic_sections_created |
10166 | || h->dynindx == -1) | |
9d8504b1 PB |
10167 | reloc_index = ent->plt.offset / 4; |
10168 | else | |
10169 | { | |
10170 | reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size) | |
10171 | / htab->plt_slot_size); | |
10172 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES | |
4a3dc543 | 10173 | && htab->plt_type == PLT_OLD) |
9d8504b1 PB |
10174 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; |
10175 | } | |
10176 | ||
a6aa5195 AM |
10177 | /* This symbol has an entry in the procedure linkage table. |
10178 | Set it up. */ | |
e054468f | 10179 | if (htab->plt_type == PLT_VXWORKS |
25f23106 AM |
10180 | && htab->elf.dynamic_sections_created |
10181 | && h->dynindx != -1) | |
a6aa5195 | 10182 | { |
9d8504b1 PB |
10183 | bfd_vma got_offset; |
10184 | const bfd_vma *plt_entry; | |
5b914448 | 10185 | |
9d8504b1 PB |
10186 | /* The first three entries in .got.plt are reserved. */ |
10187 | got_offset = (reloc_index + 3) * 4; | |
10188 | ||
10189 | /* Use the right PLT. */ | |
0e1862bb | 10190 | plt_entry = bfd_link_pic (info) ? ppc_elf_vxworks_pic_plt_entry |
9d8504b1 PB |
10191 | : ppc_elf_vxworks_plt_entry; |
10192 | ||
10193 | /* Fill in the .plt on VxWorks. */ | |
0e1862bb | 10194 | if (bfd_link_pic (info)) |
9d8504b1 | 10195 | { |
9d8504b1 | 10196 | bfd_put_32 (output_bfd, |
e87d4038 | 10197 | plt_entry[0] | PPC_HA (got_offset), |
ce558b89 | 10198 | htab->elf.splt->contents + ent->plt.offset + 0); |
9d8504b1 | 10199 | bfd_put_32 (output_bfd, |
e87d4038 | 10200 | plt_entry[1] | PPC_LO (got_offset), |
ce558b89 | 10201 | htab->elf.splt->contents + ent->plt.offset + 4); |
9d8504b1 PB |
10202 | } |
10203 | else | |
10204 | { | |
e87d4038 | 10205 | bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot); |
9d8504b1 PB |
10206 | |
10207 | bfd_put_32 (output_bfd, | |
e87d4038 | 10208 | plt_entry[0] | PPC_HA (got_loc), |
ce558b89 | 10209 | htab->elf.splt->contents + ent->plt.offset + 0); |
9d8504b1 | 10210 | bfd_put_32 (output_bfd, |
e87d4038 | 10211 | plt_entry[1] | PPC_LO (got_loc), |
ce558b89 | 10212 | htab->elf.splt->contents + ent->plt.offset + 4); |
9d8504b1 PB |
10213 | } |
10214 | ||
10215 | bfd_put_32 (output_bfd, plt_entry[2], | |
ce558b89 | 10216 | htab->elf.splt->contents + ent->plt.offset + 8); |
9d8504b1 | 10217 | bfd_put_32 (output_bfd, plt_entry[3], |
ce558b89 | 10218 | htab->elf.splt->contents + ent->plt.offset + 12); |
9d8504b1 PB |
10219 | |
10220 | /* This instruction is an immediate load. The value loaded is | |
10221 | the byte offset of the R_PPC_JMP_SLOT relocation from the | |
10222 | start of the .rela.plt section. The value is stored in the | |
10223 | low-order 16 bits of the load instruction. */ | |
10224 | /* NOTE: It appears that this is now an index rather than a | |
10225 | prescaled offset. */ | |
5b914448 | 10226 | bfd_put_32 (output_bfd, |
9d8504b1 | 10227 | plt_entry[4] | reloc_index, |
ce558b89 | 10228 | htab->elf.splt->contents + ent->plt.offset + 16); |
9d8504b1 PB |
10229 | /* This instruction is a PC-relative branch whose target is |
10230 | the start of the PLT section. The address of this branch | |
10231 | instruction is 20 bytes beyond the start of this PLT entry. | |
10232 | The address is encoded in bits 6-29, inclusive. The value | |
10233 | stored is right-shifted by two bits, permitting a 26-bit | |
10234 | offset. */ | |
5b914448 AM |
10235 | bfd_put_32 (output_bfd, |
10236 | (plt_entry[5] | |
9d8504b1 | 10237 | | (-(ent->plt.offset + 20) & 0x03fffffc)), |
ce558b89 | 10238 | htab->elf.splt->contents + ent->plt.offset + 20); |
9d8504b1 | 10239 | bfd_put_32 (output_bfd, plt_entry[6], |
ce558b89 | 10240 | htab->elf.splt->contents + ent->plt.offset + 24); |
9d8504b1 | 10241 | bfd_put_32 (output_bfd, plt_entry[7], |
ce558b89 | 10242 | htab->elf.splt->contents + ent->plt.offset + 28); |
9d8504b1 PB |
10243 | |
10244 | /* Fill in the GOT entry corresponding to this PLT slot with | |
a8685210 | 10245 | the address immediately after the "bctr" instruction |
9d8504b1 | 10246 | in this PLT entry. */ |
ce558b89 AM |
10247 | bfd_put_32 (output_bfd, (htab->elf.splt->output_section->vma |
10248 | + htab->elf.splt->output_offset | |
9d8504b1 | 10249 | + ent->plt.offset + 16), |
ce558b89 | 10250 | htab->elf.sgotplt->contents + got_offset); |
9d8504b1 | 10251 | |
0e1862bb | 10252 | if (!bfd_link_pic (info)) |
9d8504b1 PB |
10253 | { |
10254 | /* Fill in a couple of entries in .rela.plt.unloaded. */ | |
10255 | loc = htab->srelplt2->contents | |
10256 | + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index | |
10257 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS) | |
10258 | * sizeof (Elf32_External_Rela)); | |
10259 | ||
10260 | /* Provide the @ha relocation for the first instruction. */ | |
ce558b89 AM |
10261 | rela.r_offset = (htab->elf.splt->output_section->vma |
10262 | + htab->elf.splt->output_offset | |
9d8504b1 | 10263 | + ent->plt.offset + 2); |
636ce3f5 | 10264 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
10265 | R_PPC_ADDR16_HA); |
10266 | rela.r_addend = got_offset; | |
10267 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
10268 | loc += sizeof (Elf32_External_Rela); | |
10269 | ||
10270 | /* Provide the @l relocation for the second instruction. */ | |
ce558b89 AM |
10271 | rela.r_offset = (htab->elf.splt->output_section->vma |
10272 | + htab->elf.splt->output_offset | |
9d8504b1 | 10273 | + ent->plt.offset + 6); |
636ce3f5 | 10274 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
10275 | R_PPC_ADDR16_LO); |
10276 | rela.r_addend = got_offset; | |
10277 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
10278 | loc += sizeof (Elf32_External_Rela); | |
10279 | ||
10280 | /* Provide a relocation for the GOT entry corresponding to this | |
10281 | PLT slot. Point it at the middle of the .plt entry. */ | |
ce558b89 AM |
10282 | rela.r_offset = (htab->elf.sgotplt->output_section->vma |
10283 | + htab->elf.sgotplt->output_offset | |
9d8504b1 | 10284 | + got_offset); |
7325306f | 10285 | rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, |
9d8504b1 PB |
10286 | R_PPC_ADDR32); |
10287 | rela.r_addend = ent->plt.offset + 16; | |
10288 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
10289 | } | |
10290 | ||
10291 | /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT. | |
10292 | In particular, the offset for the relocation is not the | |
10293 | address of the PLT entry for this function, as specified | |
10294 | by the ABI. Instead, the offset is set to the address of | |
10295 | the GOT slot for this function. See EABI 4.4.4.1. */ | |
ce558b89 AM |
10296 | rela.r_offset = (htab->elf.sgotplt->output_section->vma |
10297 | + htab->elf.sgotplt->output_offset | |
9d8504b1 PB |
10298 | + got_offset); |
10299 | ||
a6aa5195 AM |
10300 | } |
10301 | else | |
10302 | { | |
ce558b89 | 10303 | asection *splt = htab->elf.splt; |
25f23106 AM |
10304 | if (!htab->elf.dynamic_sections_created |
10305 | || h->dynindx == -1) | |
ce558b89 | 10306 | splt = htab->elf.iplt; |
e054468f AM |
10307 | |
10308 | rela.r_offset = (splt->output_section->vma | |
10309 | + splt->output_offset | |
9d8504b1 | 10310 | + ent->plt.offset); |
e054468f | 10311 | if (htab->plt_type == PLT_OLD |
25f23106 AM |
10312 | || !htab->elf.dynamic_sections_created |
10313 | || h->dynindx == -1) | |
9d8504b1 PB |
10314 | { |
10315 | /* We don't need to fill in the .plt. The ppc dynamic | |
10316 | linker will fill it in. */ | |
10317 | } | |
10318 | else | |
10319 | { | |
10320 | bfd_vma val = (htab->glink_pltresolve + ent->plt.offset | |
10321 | + htab->glink->output_section->vma | |
10322 | + htab->glink->output_offset); | |
10323 | bfd_put_32 (output_bfd, val, | |
e054468f | 10324 | splt->contents + ent->plt.offset); |
9d8504b1 | 10325 | } |
a6aa5195 | 10326 | } |
e1a9cb8e | 10327 | |
a6aa5195 | 10328 | /* Fill in the entry in the .rela.plt section. */ |
a6aa5195 | 10329 | rela.r_addend = 0; |
e054468f AM |
10330 | if (!htab->elf.dynamic_sections_created |
10331 | || h->dynindx == -1) | |
10332 | { | |
10333 | BFD_ASSERT (h->type == STT_GNU_IFUNC | |
10334 | && h->def_regular | |
10335 | && (h->root.type == bfd_link_hash_defined | |
10336 | || h->root.type == bfd_link_hash_defweak)); | |
10337 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
10338 | rela.r_addend = SYM_VAL (h); | |
10339 | } | |
10340 | else | |
10341 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); | |
e1a9cb8e | 10342 | |
25f23106 AM |
10343 | if (!htab->elf.dynamic_sections_created |
10344 | || h->dynindx == -1) | |
82e66161 AM |
10345 | { |
10346 | loc = (htab->elf.irelplt->contents | |
10347 | + (htab->elf.irelplt->reloc_count++ | |
10348 | * sizeof (Elf32_External_Rela))); | |
10349 | htab->local_ifunc_resolver = 1; | |
10350 | } | |
e054468f | 10351 | else |
82e66161 AM |
10352 | { |
10353 | loc = (htab->elf.srelplt->contents | |
10354 | + reloc_index * sizeof (Elf32_External_Rela)); | |
10355 | if (h->type == STT_GNU_IFUNC && is_static_defined (h)) | |
10356 | htab->maybe_local_ifunc_resolver = 1; | |
10357 | } | |
a6aa5195 | 10358 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
e1a9cb8e | 10359 | |
a6aa5195 AM |
10360 | if (!h->def_regular) |
10361 | { | |
0eb4a168 AM |
10362 | /* Mark the symbol as undefined, rather than as |
10363 | defined in the .plt section. Leave the value if | |
10364 | there were any relocations where pointer equality | |
10365 | matters (this is a clue for the dynamic linker, to | |
10366 | make function pointer comparisons work between an | |
10367 | application and shared library), otherwise set it | |
10368 | to zero. */ | |
a6aa5195 | 10369 | sym->st_shndx = SHN_UNDEF; |
0eb4a168 | 10370 | if (!h->pointer_equality_needed) |
a6aa5195 | 10371 | sym->st_value = 0; |
0eb4a168 AM |
10372 | else if (!h->ref_regular_nonweak) |
10373 | { | |
625af618 AM |
10374 | /* This breaks function pointer comparisons, but |
10375 | that is better than breaking tests for a NULL | |
0eb4a168 | 10376 | function pointer. */ |
0eb4a168 AM |
10377 | sym->st_value = 0; |
10378 | } | |
a6aa5195 | 10379 | } |
de972ffa | 10380 | else if (h->type == STT_GNU_IFUNC |
0e1862bb | 10381 | && !bfd_link_pic (info)) |
de972ffa AM |
10382 | { |
10383 | /* Set the value of ifunc symbols in a non-pie | |
10384 | executable to the glink entry. This is to avoid | |
10385 | text relocations. We can't do this for ifunc in | |
10386 | allocate_dynrelocs, as we do for normal dynamic | |
10387 | function symbols with plt entries, because we need | |
10388 | to keep the original value around for the ifunc | |
10389 | relocation. */ | |
10390 | sym->st_shndx = (_bfd_elf_section_from_bfd_section | |
10391 | (output_bfd, htab->glink->output_section)); | |
5b914448 AM |
10392 | sym->st_value = (ent->glink_offset |
10393 | + htab->glink->output_offset | |
de972ffa AM |
10394 | + htab->glink->output_section->vma); |
10395 | } | |
a6aa5195 AM |
10396 | doneone = TRUE; |
10397 | } | |
e1a9cb8e | 10398 | |
e054468f | 10399 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
10400 | || !htab->elf.dynamic_sections_created |
10401 | || h->dynindx == -1) | |
a6aa5195 | 10402 | { |
a7f2871e | 10403 | unsigned char *p; |
ce558b89 | 10404 | asection *splt = htab->elf.splt; |
25f23106 AM |
10405 | if (!htab->elf.dynamic_sections_created |
10406 | || h->dynindx == -1) | |
ce558b89 | 10407 | splt = htab->elf.iplt; |
e1a9cb8e | 10408 | |
a7f2871e AM |
10409 | p = (unsigned char *) htab->glink->contents + ent->glink_offset; |
10410 | ||
5446cbdf | 10411 | if (h == htab->tls_get_addr && !htab->params->no_tls_get_addr_opt) |
a7f2871e AM |
10412 | { |
10413 | bfd_put_32 (output_bfd, LWZ_11_3, p); | |
10414 | p += 4; | |
10415 | bfd_put_32 (output_bfd, LWZ_12_3 + 4, p); | |
10416 | p += 4; | |
10417 | bfd_put_32 (output_bfd, MR_0_3, p); | |
10418 | p += 4; | |
10419 | bfd_put_32 (output_bfd, CMPWI_11_0, p); | |
10420 | p += 4; | |
10421 | bfd_put_32 (output_bfd, ADD_3_12_2, p); | |
10422 | p += 4; | |
10423 | bfd_put_32 (output_bfd, BEQLR, p); | |
10424 | p += 4; | |
10425 | bfd_put_32 (output_bfd, MR_3_0, p); | |
10426 | p += 4; | |
10427 | bfd_put_32 (output_bfd, NOP, p); | |
10428 | p += 4; | |
10429 | } | |
10430 | ||
10431 | write_glink_stub (ent, splt, p, info); | |
e1a9cb8e | 10432 | |
0e1862bb | 10433 | if (!bfd_link_pic (info)) |
e054468f AM |
10434 | /* We only need one non-PIC glink stub. */ |
10435 | break; | |
a6aa5195 AM |
10436 | } |
10437 | else | |
10438 | break; | |
10439 | } | |
e1a9cb8e | 10440 | |
25dbc73a AM |
10441 | if (h->needs_copy) |
10442 | { | |
10443 | asection *s; | |
10444 | Elf_Internal_Rela rela; | |
10445 | bfd_byte *loc; | |
e1a9cb8e | 10446 | |
25dbc73a | 10447 | /* This symbols needs a copy reloc. Set it up. */ |
e1a9cb8e | 10448 | |
25dbc73a AM |
10449 | #ifdef DEBUG |
10450 | fprintf (stderr, ", copy"); | |
10451 | #endif | |
e1a9cb8e | 10452 | |
25dbc73a | 10453 | BFD_ASSERT (h->dynindx != -1); |
86bbe32f | 10454 | |
4dc4a9a5 | 10455 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a | 10456 | s = htab->relsbss; |
afbf7e8e | 10457 | else if (h->root.u.def.section == htab->elf.sdynrelro) |
5474d94f | 10458 | s = htab->elf.sreldynrelro; |
25dbc73a | 10459 | else |
9d19e4fd | 10460 | s = htab->elf.srelbss; |
25dbc73a | 10461 | BFD_ASSERT (s != NULL); |
e1a9cb8e | 10462 | |
e87d4038 | 10463 | rela.r_offset = SYM_VAL (h); |
25dbc73a AM |
10464 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); |
10465 | rela.r_addend = 0; | |
10466 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); | |
10467 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
10468 | } | |
e1a9cb8e | 10469 | |
25dbc73a AM |
10470 | #ifdef DEBUG |
10471 | fprintf (stderr, "\n"); | |
10472 | #endif | |
e1a9cb8e | 10473 | |
25dbc73a AM |
10474 | return TRUE; |
10475 | } | |
10476 | \f | |
10477 | static enum elf_reloc_type_class | |
7e612e98 AM |
10478 | ppc_elf_reloc_type_class (const struct bfd_link_info *info, |
10479 | const asection *rel_sec, | |
10480 | const Elf_Internal_Rela *rela) | |
e1a9cb8e | 10481 | { |
7e612e98 AM |
10482 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); |
10483 | ||
ce558b89 | 10484 | if (rel_sec == htab->elf.irelplt) |
7e612e98 AM |
10485 | return reloc_class_ifunc; |
10486 | ||
25dbc73a AM |
10487 | switch (ELF32_R_TYPE (rela->r_info)) |
10488 | { | |
10489 | case R_PPC_RELATIVE: | |
10490 | return reloc_class_relative; | |
25dbc73a AM |
10491 | case R_PPC_JMP_SLOT: |
10492 | return reloc_class_plt; | |
10493 | case R_PPC_COPY: | |
10494 | return reloc_class_copy; | |
10495 | default: | |
10496 | return reloc_class_normal; | |
10497 | } | |
e1a9cb8e | 10498 | } |
25dbc73a AM |
10499 | \f |
10500 | /* Finish up the dynamic sections. */ | |
e1a9cb8e | 10501 | |
25dbc73a AM |
10502 | static bfd_boolean |
10503 | ppc_elf_finish_dynamic_sections (bfd *output_bfd, | |
10504 | struct bfd_link_info *info) | |
e1a9cb8e | 10505 | { |
25dbc73a AM |
10506 | asection *sdyn; |
10507 | struct ppc_elf_link_hash_table *htab; | |
1fe44d79 | 10508 | bfd_vma got; |
e87d4038 AM |
10509 | bfd *dynobj; |
10510 | bfd_boolean ret = TRUE; | |
e1a9cb8e | 10511 | |
25dbc73a AM |
10512 | #ifdef DEBUG |
10513 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
10514 | #endif | |
6b0817e5 | 10515 | |
25dbc73a | 10516 | htab = ppc_elf_hash_table (info); |
ce558b89 | 10517 | dynobj = htab->elf.dynobj; |
3d4d4302 | 10518 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
e1a9cb8e | 10519 | |
1fe44d79 AM |
10520 | got = 0; |
10521 | if (htab->elf.hgot != NULL) | |
e87d4038 | 10522 | got = SYM_VAL (htab->elf.hgot); |
1fe44d79 | 10523 | |
25dbc73a | 10524 | if (htab->elf.dynamic_sections_created) |
e1a9cb8e | 10525 | { |
25dbc73a | 10526 | Elf32_External_Dyn *dyncon, *dynconend; |
e1a9cb8e | 10527 | |
ce558b89 | 10528 | BFD_ASSERT (htab->elf.splt != NULL && sdyn != NULL); |
86bbe32f | 10529 | |
25dbc73a AM |
10530 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
10531 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); | |
10532 | for (; dyncon < dynconend; dyncon++) | |
10533 | { | |
10534 | Elf_Internal_Dyn dyn; | |
10535 | asection *s; | |
e1a9cb8e | 10536 | |
9d8504b1 | 10537 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
86bbe32f | 10538 | |
25dbc73a AM |
10539 | switch (dyn.d_tag) |
10540 | { | |
10541 | case DT_PLTGOT: | |
9d8504b1 | 10542 | if (htab->is_vxworks) |
ce558b89 | 10543 | s = htab->elf.sgotplt; |
9d8504b1 | 10544 | else |
ce558b89 | 10545 | s = htab->elf.splt; |
25dbc73a AM |
10546 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
10547 | break; | |
86bbe32f | 10548 | |
25dbc73a | 10549 | case DT_PLTRELSZ: |
ce558b89 | 10550 | dyn.d_un.d_val = htab->elf.srelplt->size; |
25dbc73a | 10551 | break; |
e1a9cb8e | 10552 | |
25dbc73a | 10553 | case DT_JMPREL: |
ce558b89 | 10554 | s = htab->elf.srelplt; |
25dbc73a AM |
10555 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
10556 | break; | |
2f89ff8d | 10557 | |
1fe44d79 AM |
10558 | case DT_PPC_GOT: |
10559 | dyn.d_un.d_ptr = got; | |
d7128ce4 AM |
10560 | break; |
10561 | ||
82e66161 AM |
10562 | case DT_TEXTREL: |
10563 | if (htab->local_ifunc_resolver) | |
10564 | info->callbacks->einfo | |
10565 | (_("%X%P: text relocations and GNU indirect " | |
10566 | "functions will result in a segfault at runtime\n")); | |
10567 | else if (htab->maybe_local_ifunc_resolver) | |
10568 | info->callbacks->einfo | |
10569 | (_("%P: warning: text relocations and GNU indirect " | |
10570 | "functions may result in a segfault at runtime\n")); | |
10571 | continue; | |
10572 | ||
25dbc73a | 10573 | default: |
7a2b07ff NS |
10574 | if (htab->is_vxworks |
10575 | && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) | |
10576 | break; | |
25dbc73a AM |
10577 | continue; |
10578 | } | |
4c45e5c9 | 10579 | |
25dbc73a AM |
10580 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
10581 | } | |
10582 | } | |
4c45e5c9 | 10583 | |
6528b6eb AM |
10584 | if (htab->elf.sgot != NULL |
10585 | && htab->elf.sgot->output_section != bfd_abs_section_ptr) | |
25dbc73a | 10586 | { |
ce558b89 AM |
10587 | if (htab->elf.hgot->root.u.def.section == htab->elf.sgot |
10588 | || htab->elf.hgot->root.u.def.section == htab->elf.sgotplt) | |
e87d4038 | 10589 | { |
e79f5955 | 10590 | unsigned char *p = htab->elf.hgot->root.u.def.section->contents; |
2f89ff8d | 10591 | |
e87d4038 AM |
10592 | p += htab->elf.hgot->root.u.def.value; |
10593 | if (htab->plt_type == PLT_OLD) | |
e79f5955 AM |
10594 | { |
10595 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 | |
10596 | so that a function can easily find the address of | |
10597 | _GLOBAL_OFFSET_TABLE_. */ | |
10598 | BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4 | |
10599 | < htab->elf.hgot->root.u.def.section->size); | |
10600 | bfd_put_32 (output_bfd, 0x4e800021, p - 4); | |
10601 | } | |
3b36f7e6 | 10602 | |
e87d4038 | 10603 | if (sdyn != NULL) |
e79f5955 AM |
10604 | { |
10605 | bfd_vma val = sdyn->output_section->vma + sdyn->output_offset; | |
10606 | BFD_ASSERT (htab->elf.hgot->root.u.def.value | |
10607 | < htab->elf.hgot->root.u.def.section->size); | |
10608 | bfd_put_32 (output_bfd, val, p); | |
10609 | } | |
e87d4038 AM |
10610 | } |
10611 | else | |
10612 | { | |
695344c0 | 10613 | /* xgettext:c-format */ |
8de848d8 | 10614 | info->callbacks->einfo (_("%P: %s not defined in linker created %s\n"), |
25f53a85 | 10615 | htab->elf.hgot->root.root.string, |
ce558b89 AM |
10616 | (htab->elf.sgotplt != NULL |
10617 | ? htab->elf.sgotplt->name | |
10618 | : htab->elf.sgot->name)); | |
e87d4038 AM |
10619 | bfd_set_error (bfd_error_bad_value); |
10620 | ret = FALSE; | |
10621 | } | |
25dbc73a | 10622 | |
ce558b89 | 10623 | elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4; |
25dbc73a AM |
10624 | } |
10625 | ||
9d8504b1 | 10626 | /* Fill in the first entry in the VxWorks procedure linkage table. */ |
6528b6eb AM |
10627 | if (htab->is_vxworks |
10628 | && htab->elf.splt != NULL | |
10629 | && htab->elf.splt->size != 0 | |
10630 | && htab->elf.splt->output_section != bfd_abs_section_ptr) | |
9d8504b1 | 10631 | { |
6528b6eb | 10632 | asection *splt = htab->elf.splt; |
9d8504b1 | 10633 | /* Use the right PLT. */ |
0e1862bb | 10634 | const bfd_vma *plt_entry = (bfd_link_pic (info) |
5b914448 AM |
10635 | ? ppc_elf_vxworks_pic_plt0_entry |
10636 | : ppc_elf_vxworks_plt0_entry); | |
9d8504b1 | 10637 | |
0e1862bb | 10638 | if (!bfd_link_pic (info)) |
9d8504b1 | 10639 | { |
e87d4038 | 10640 | bfd_vma got_value = SYM_VAL (htab->elf.hgot); |
9d8504b1 | 10641 | |
e87d4038 | 10642 | bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value), |
9d8504b1 | 10643 | splt->contents + 0); |
e87d4038 | 10644 | bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value), |
9d8504b1 PB |
10645 | splt->contents + 4); |
10646 | } | |
10647 | else | |
10648 | { | |
10649 | bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0); | |
10650 | bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4); | |
10651 | } | |
10652 | bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8); | |
10653 | bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12); | |
10654 | bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16); | |
10655 | bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20); | |
10656 | bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24); | |
10657 | bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28); | |
10658 | ||
0e1862bb | 10659 | if (! bfd_link_pic (info)) |
9d8504b1 PB |
10660 | { |
10661 | Elf_Internal_Rela rela; | |
10662 | bfd_byte *loc; | |
10663 | ||
10664 | loc = htab->srelplt2->contents; | |
10665 | ||
10666 | /* Output the @ha relocation for the first instruction. */ | |
ce558b89 AM |
10667 | rela.r_offset = (htab->elf.splt->output_section->vma |
10668 | + htab->elf.splt->output_offset | |
9d8504b1 | 10669 | + 2); |
636ce3f5 | 10670 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
10671 | rela.r_addend = 0; |
10672 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
10673 | loc += sizeof (Elf32_External_Rela); | |
5b914448 | 10674 | |
9d8504b1 | 10675 | /* Output the @l relocation for the second instruction. */ |
ce558b89 AM |
10676 | rela.r_offset = (htab->elf.splt->output_section->vma |
10677 | + htab->elf.splt->output_offset | |
9d8504b1 | 10678 | + 6); |
636ce3f5 | 10679 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
10680 | rela.r_addend = 0; |
10681 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
10682 | loc += sizeof (Elf32_External_Rela); | |
10683 | ||
10684 | /* Fix up the remaining relocations. They may have the wrong | |
10685 | symbol index for _G_O_T_ or _P_L_T_ depending on the order | |
10686 | in which symbols were output. */ | |
10687 | while (loc < htab->srelplt2->contents + htab->srelplt2->size) | |
10688 | { | |
10689 | Elf_Internal_Rela rel; | |
10690 | ||
10691 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 10692 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
10693 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
10694 | loc += sizeof (Elf32_External_Rela); | |
10695 | ||
10696 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 10697 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
10698 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
10699 | loc += sizeof (Elf32_External_Rela); | |
10700 | ||
10701 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
7325306f | 10702 | rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32); |
9d8504b1 PB |
10703 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
10704 | loc += sizeof (Elf32_External_Rela); | |
10705 | } | |
10706 | } | |
10707 | } | |
10708 | ||
e054468f AM |
10709 | if (htab->glink != NULL |
10710 | && htab->glink->contents != NULL | |
10711 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
10712 | { |
10713 | unsigned char *p; | |
10714 | unsigned char *endp; | |
a6aa5195 | 10715 | bfd_vma res0; |
d7128ce4 | 10716 | unsigned int i; |
a6aa5195 AM |
10717 | |
10718 | /* | |
10719 | * PIC glink code is the following: | |
10720 | * | |
10721 | * # ith PLT code stub. | |
10722 | * addis 11,30,(plt+(i-1)*4-got)@ha | |
10723 | * lwz 11,(plt+(i-1)*4-got)@l(11) | |
10724 | * mtctr 11 | |
10725 | * bctr | |
10726 | * | |
10727 | * # A table of branches, one for each plt entry. | |
176a0d42 | 10728 | * # The idea is that the plt call stub loads ctr and r11 with these |
a6aa5195 AM |
10729 | * # addresses, so (r11 - res_0) gives the plt index * 4. |
10730 | * res_0: b PLTresolve | |
10731 | * res_1: b PLTresolve | |
10732 | * . | |
10733 | * # Some number of entries towards the end can be nops | |
10734 | * res_n_m3: nop | |
10735 | * res_n_m2: nop | |
10736 | * res_n_m1: | |
10737 | * | |
10738 | * PLTresolve: | |
10739 | * addis 11,11,(1f-res_0)@ha | |
10740 | * mflr 0 | |
10741 | * bcl 20,31,1f | |
10742 | * 1: addi 11,11,(1b-res_0)@l | |
10743 | * mflr 12 | |
10744 | * mtlr 0 | |
10745 | * sub 11,11,12 # r11 = index * 4 | |
10746 | * addis 12,12,(got+4-1b)@ha | |
10747 | * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve | |
10748 | * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address | |
10749 | * mtctr 0 | |
10750 | * add 0,11,11 | |
10751 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
10752 | * bctr | |
10753 | */ | |
10754 | static const unsigned int pic_plt_resolve[] = | |
10755 | { | |
10756 | ADDIS_11_11, | |
10757 | MFLR_0, | |
10758 | BCL_20_31, | |
10759 | ADDI_11_11, | |
10760 | MFLR_12, | |
10761 | MTLR_0, | |
10762 | SUB_11_11_12, | |
10763 | ADDIS_12_12, | |
10764 | LWZ_0_12, | |
10765 | LWZ_12_12, | |
10766 | MTCTR_0, | |
10767 | ADD_0_11_11, | |
10768 | ADD_11_0_11, | |
10769 | BCTR, | |
10770 | NOP, | |
10771 | NOP | |
10772 | }; | |
10773 | ||
176a0d42 AM |
10774 | /* |
10775 | * Non-PIC glink code is a little simpler. | |
10776 | * | |
10777 | * # ith PLT code stub. | |
10778 | * lis 11,(plt+(i-1)*4)@ha | |
10779 | * lwz 11,(plt+(i-1)*4)@l(11) | |
10780 | * mtctr 11 | |
10781 | * bctr | |
10782 | * | |
10783 | * The branch table is the same, then comes | |
10784 | * | |
10785 | * PLTresolve: | |
10786 | * lis 12,(got+4)@ha | |
10787 | * addis 11,11,(-res_0)@ha | |
10788 | * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve | |
10789 | * addi 11,11,(-res_0)@l # r11 = index * 4 | |
10790 | * mtctr 0 | |
10791 | * add 0,11,11 | |
10792 | * lwz 12,(got+8)@l(12) # got[2] contains the map address | |
10793 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
10794 | * bctr | |
10795 | */ | |
d7128ce4 AM |
10796 | static const unsigned int plt_resolve[] = |
10797 | { | |
a6aa5195 AM |
10798 | LIS_12, |
10799 | ADDIS_11_11, | |
10800 | LWZ_0_12, | |
10801 | ADDI_11_11, | |
d7128ce4 | 10802 | MTCTR_0, |
7e8aeb9a | 10803 | ADD_0_11_11, |
a6aa5195 | 10804 | LWZ_12_12, |
7e8aeb9a | 10805 | ADD_11_0_11, |
d7128ce4 AM |
10806 | BCTR, |
10807 | NOP, | |
10808 | NOP, | |
a6aa5195 AM |
10809 | NOP, |
10810 | NOP, | |
10811 | NOP, | |
10812 | NOP, | |
d7128ce4 AM |
10813 | NOP |
10814 | }; | |
10815 | ||
a6aa5195 AM |
10816 | if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4) |
10817 | abort (); | |
10818 | if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4) | |
7e8aeb9a AM |
10819 | abort (); |
10820 | ||
a6aa5195 | 10821 | /* Build the branch table, one for each plt entry (less one), |
86b9da88 | 10822 | and perhaps some padding. */ |
a6aa5195 AM |
10823 | p = htab->glink->contents; |
10824 | p += htab->glink_pltresolve; | |
86b9da88 AM |
10825 | endp = htab->glink->contents; |
10826 | endp += htab->glink->size - GLINK_PLTRESOLVE; | |
da3a2088 | 10827 | while (p < endp - (htab->params->ppc476_workaround ? 0 : 8 * 4)) |
86b9da88 AM |
10828 | { |
10829 | bfd_put_32 (output_bfd, B + endp - p, p); | |
10830 | p += 4; | |
10831 | } | |
10832 | while (p < endp) | |
10833 | { | |
10834 | bfd_put_32 (output_bfd, NOP, p); | |
10835 | p += 4; | |
10836 | } | |
10837 | ||
7e8aeb9a | 10838 | res0 = (htab->glink_pltresolve |
86b9da88 AM |
10839 | + htab->glink->output_section->vma |
10840 | + htab->glink->output_offset); | |
10841 | ||
da3a2088 AM |
10842 | if (htab->params->ppc476_workaround) |
10843 | { | |
10844 | /* Ensure that a call stub at the end of a page doesn't | |
10845 | result in prefetch over the end of the page into the | |
10846 | glink branch table. */ | |
10847 | bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2; | |
10848 | bfd_vma page_addr; | |
10849 | bfd_vma glink_start = (htab->glink->output_section->vma | |
10850 | + htab->glink->output_offset); | |
10851 | ||
10852 | for (page_addr = res0 & -pagesize; | |
10853 | page_addr > glink_start; | |
10854 | page_addr -= pagesize) | |
10855 | { | |
10856 | /* We have a plt call stub that may need fixing. */ | |
10857 | bfd_byte *loc; | |
10858 | unsigned int insn; | |
10859 | ||
10860 | loc = htab->glink->contents + page_addr - 4 - glink_start; | |
10861 | insn = bfd_get_32 (output_bfd, loc); | |
10862 | if (insn == BCTR) | |
10863 | { | |
10864 | /* By alignment, we know that there must be at least | |
10865 | one other call stub before this one. */ | |
10866 | insn = bfd_get_32 (output_bfd, loc - 16); | |
10867 | if (insn == BCTR) | |
10868 | bfd_put_32 (output_bfd, B | (-16 & 0x3fffffc), loc); | |
10869 | else | |
10870 | bfd_put_32 (output_bfd, B | (-20 & 0x3fffffc), loc); | |
10871 | } | |
10872 | } | |
10873 | } | |
10874 | ||
86b9da88 | 10875 | /* Last comes the PLTresolve stub. */ |
0e1862bb | 10876 | if (bfd_link_pic (info)) |
7e8aeb9a | 10877 | { |
a6aa5195 | 10878 | bfd_vma bcl; |
d7128ce4 | 10879 | |
a6aa5195 | 10880 | for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++) |
7e8aeb9a | 10881 | { |
da3a2088 AM |
10882 | unsigned int insn = pic_plt_resolve[i]; |
10883 | ||
10884 | if (htab->params->ppc476_workaround && insn == NOP) | |
10885 | insn = BA + 0; | |
10886 | bfd_put_32 (output_bfd, insn, p); | |
7e8aeb9a AM |
10887 | p += 4; |
10888 | } | |
a6aa5195 AM |
10889 | p -= 4 * ARRAY_SIZE (pic_plt_resolve); |
10890 | ||
10891 | bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4 | |
10892 | + htab->glink->output_section->vma | |
10893 | + htab->glink->output_offset); | |
10894 | ||
10895 | bfd_put_32 (output_bfd, | |
10896 | ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4); | |
10897 | bfd_put_32 (output_bfd, | |
10898 | ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4); | |
10899 | bfd_put_32 (output_bfd, | |
10900 | ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4); | |
10901 | if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl)) | |
10902 | { | |
10903 | bfd_put_32 (output_bfd, | |
10904 | LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
10905 | bfd_put_32 (output_bfd, | |
10906 | LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4); | |
10907 | } | |
10908 | else | |
10909 | { | |
10910 | bfd_put_32 (output_bfd, | |
10911 | LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
10912 | bfd_put_32 (output_bfd, | |
10913 | LWZ_12_12 + 4, p + 9*4); | |
10914 | } | |
7e8aeb9a AM |
10915 | } |
10916 | else | |
d7128ce4 | 10917 | { |
a6aa5195 | 10918 | for (i = 0; i < ARRAY_SIZE (plt_resolve); i++) |
7e8aeb9a | 10919 | { |
da3a2088 AM |
10920 | unsigned int insn = plt_resolve[i]; |
10921 | ||
10922 | if (htab->params->ppc476_workaround && insn == NOP) | |
10923 | insn = BA + 0; | |
10924 | bfd_put_32 (output_bfd, insn, p); | |
7e8aeb9a AM |
10925 | p += 4; |
10926 | } | |
a6aa5195 AM |
10927 | p -= 4 * ARRAY_SIZE (plt_resolve); |
10928 | ||
10929 | bfd_put_32 (output_bfd, | |
10930 | LIS_12 + PPC_HA (got + 4), p + 0*4); | |
10931 | bfd_put_32 (output_bfd, | |
10932 | ADDIS_11_11 + PPC_HA (-res0), p + 1*4); | |
10933 | bfd_put_32 (output_bfd, | |
10934 | ADDI_11_11 + PPC_LO (-res0), p + 3*4); | |
10935 | if (PPC_HA (got + 4) == PPC_HA (got + 8)) | |
10936 | { | |
10937 | bfd_put_32 (output_bfd, | |
10938 | LWZ_0_12 + PPC_LO (got + 4), p + 2*4); | |
10939 | bfd_put_32 (output_bfd, | |
10940 | LWZ_12_12 + PPC_LO (got + 8), p + 6*4); | |
10941 | } | |
10942 | else | |
10943 | { | |
10944 | bfd_put_32 (output_bfd, | |
10945 | LWZU_0_12 + PPC_LO (got + 4), p + 2*4); | |
10946 | bfd_put_32 (output_bfd, | |
10947 | LWZ_12_12 + 4, p + 6*4); | |
10948 | } | |
d7128ce4 | 10949 | } |
d7128ce4 AM |
10950 | } |
10951 | ||
6177242a AM |
10952 | if (htab->glink_eh_frame != NULL |
10953 | && htab->glink_eh_frame->contents != NULL) | |
10954 | { | |
10955 | unsigned char *p = htab->glink_eh_frame->contents; | |
10956 | bfd_vma val; | |
10957 | ||
6177242a AM |
10958 | p += sizeof (glink_eh_frame_cie); |
10959 | /* FDE length. */ | |
6177242a AM |
10960 | p += 4; |
10961 | /* CIE pointer. */ | |
6177242a AM |
10962 | p += 4; |
10963 | /* Offset to .glink. */ | |
10964 | val = (htab->glink->output_section->vma | |
10965 | + htab->glink->output_offset); | |
10966 | val -= (htab->glink_eh_frame->output_section->vma | |
10967 | + htab->glink_eh_frame->output_offset); | |
10968 | val -= p - htab->glink_eh_frame->contents; | |
10969 | bfd_put_32 (htab->elf.dynobj, val, p); | |
6177242a | 10970 | |
dbaa2011 | 10971 | if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME |
6177242a AM |
10972 | && !_bfd_elf_write_section_eh_frame (output_bfd, info, |
10973 | htab->glink_eh_frame, | |
10974 | htab->glink_eh_frame->contents)) | |
10975 | return FALSE; | |
10976 | } | |
10977 | ||
e87d4038 | 10978 | return ret; |
25dbc73a | 10979 | } |
e1a9cb8e | 10980 | \f |
6d00b590 | 10981 | #define TARGET_LITTLE_SYM powerpc_elf32_le_vec |
252b5132 | 10982 | #define TARGET_LITTLE_NAME "elf32-powerpcle" |
6d00b590 | 10983 | #define TARGET_BIG_SYM powerpc_elf32_vec |
252b5132 RH |
10984 | #define TARGET_BIG_NAME "elf32-powerpc" |
10985 | #define ELF_ARCH bfd_arch_powerpc | |
ae95ffa6 | 10986 | #define ELF_TARGET_ID PPC32_ELF_DATA |
252b5132 | 10987 | #define ELF_MACHINE_CODE EM_PPC |
d0facd1b NC |
10988 | #ifdef __QNXTARGET__ |
10989 | #define ELF_MAXPAGESIZE 0x1000 | |
04c6a44c | 10990 | #define ELF_COMMONPAGESIZE 0x1000 |
d0facd1b | 10991 | #else |
252b5132 | 10992 | #define ELF_MAXPAGESIZE 0x10000 |
04c6a44c | 10993 | #define ELF_COMMONPAGESIZE 0x10000 |
d0facd1b | 10994 | #endif |
b1342370 | 10995 | #define ELF_MINPAGESIZE 0x1000 |
252b5132 RH |
10996 | #define elf_info_to_howto ppc_elf_info_to_howto |
10997 | ||
10998 | #ifdef EM_CYGNUS_POWERPC | |
10999 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
11000 | #endif | |
11001 | ||
11002 | #ifdef EM_PPC_OLD | |
11003 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
11004 | #endif | |
11005 | ||
11006 | #define elf_backend_plt_not_loaded 1 | |
5474d94f | 11007 | #define elf_backend_want_dynrelro 1 |
252b5132 | 11008 | #define elf_backend_can_gc_sections 1 |
51b64d56 | 11009 | #define elf_backend_can_refcount 1 |
b491616a | 11010 | #define elf_backend_rela_normal 1 |
53291d1f | 11011 | #define elf_backend_caches_rawsize 1 |
252b5132 | 11012 | |
43c40ab2 | 11013 | #define bfd_elf32_mkobject ppc_elf_mkobject |
252b5132 | 11014 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
70bccea4 | 11015 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section |
252b5132 | 11016 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup |
b9c361e0 | 11017 | #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup |
252b5132 | 11018 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags |
70bccea4 | 11019 | #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create |
468392fb | 11020 | #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab |
252b5132 | 11021 | |
feee612b | 11022 | #define elf_backend_object_p ppc_elf_object_p |
252b5132 RH |
11023 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
11024 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook | |
11025 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr | |
11026 | #define elf_backend_relocate_section ppc_elf_relocate_section | |
11027 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections | |
11028 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
7fce784e | 11029 | #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol |
252b5132 RH |
11030 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol |
11031 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook | |
11032 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
0eb4a168 | 11033 | #define elf_backend_hash_symbol ppc_elf_hash_symbol |
252b5132 RH |
11034 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol |
11035 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
11036 | #define elf_backend_fake_sections ppc_elf_fake_sections | |
11037 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers | |
954b63d4 | 11038 | #define elf_backend_modify_segment_map ppc_elf_modify_segment_map |
c5fccbec DJ |
11039 | #define elf_backend_grok_prstatus ppc_elf_grok_prstatus |
11040 | #define elf_backend_grok_psinfo ppc_elf_grok_psinfo | |
183e98be | 11041 | #define elf_backend_write_core_note ppc_elf_write_core_note |
29c2fb7c | 11042 | #define elf_backend_reloc_type_class ppc_elf_reloc_type_class |
70bccea4 AM |
11043 | #define elf_backend_begin_write_processing ppc_elf_begin_write_processing |
11044 | #define elf_backend_final_write_processing ppc_elf_final_write_processing | |
11045 | #define elf_backend_write_section ppc_elf_write_section | |
551b43fd | 11046 | #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr |
4c45e5c9 | 11047 | #define elf_backend_plt_sym_val ppc_elf_plt_sym_val |
8a696751 | 11048 | #define elf_backend_action_discarded ppc_elf_action_discarded |
74541ad4 | 11049 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
b9c361e0 | 11050 | #define elf_backend_lookup_section_flags_hook ppc_elf_lookup_section_flags |
252b5132 RH |
11051 | |
11052 | #include "elf32-target.h" | |
9d8504b1 | 11053 | |
7b8e7dad AM |
11054 | /* FreeBSD Target */ |
11055 | ||
11056 | #undef TARGET_LITTLE_SYM | |
11057 | #undef TARGET_LITTLE_NAME | |
11058 | ||
11059 | #undef TARGET_BIG_SYM | |
6d00b590 | 11060 | #define TARGET_BIG_SYM powerpc_elf32_fbsd_vec |
7b8e7dad AM |
11061 | #undef TARGET_BIG_NAME |
11062 | #define TARGET_BIG_NAME "elf32-powerpc-freebsd" | |
11063 | ||
11064 | #undef ELF_OSABI | |
11065 | #define ELF_OSABI ELFOSABI_FREEBSD | |
11066 | ||
11067 | #undef elf32_bed | |
11068 | #define elf32_bed elf32_powerpc_fbsd_bed | |
11069 | ||
11070 | #include "elf32-target.h" | |
11071 | ||
9d8504b1 PB |
11072 | /* VxWorks Target */ |
11073 | ||
11074 | #undef TARGET_LITTLE_SYM | |
11075 | #undef TARGET_LITTLE_NAME | |
11076 | ||
11077 | #undef TARGET_BIG_SYM | |
6d00b590 | 11078 | #define TARGET_BIG_SYM powerpc_elf32_vxworks_vec |
9d8504b1 PB |
11079 | #undef TARGET_BIG_NAME |
11080 | #define TARGET_BIG_NAME "elf32-powerpc-vxworks" | |
11081 | ||
7b8e7dad AM |
11082 | #undef ELF_OSABI |
11083 | ||
d5e3d971 PB |
11084 | /* VxWorks uses the elf default section flags for .plt. */ |
11085 | static const struct bfd_elf_special_section * | |
4aef7643 | 11086 | ppc_elf_vxworks_get_sec_type_attr (bfd *abfd, asection *sec) |
9d8504b1 | 11087 | { |
d5e3d971 PB |
11088 | if (sec->name == NULL) |
11089 | return NULL; | |
11090 | ||
11091 | if (strcmp (sec->name, ".plt") == 0) | |
11092 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
11093 | ||
11094 | return ppc_elf_get_sec_type_attr (abfd, sec); | |
11095 | } | |
9d8504b1 PB |
11096 | |
11097 | /* Like ppc_elf_link_hash_table_create, but overrides | |
11098 | appropriately for VxWorks. */ | |
11099 | static struct bfd_link_hash_table * | |
11100 | ppc_elf_vxworks_link_hash_table_create (bfd *abfd) | |
11101 | { | |
11102 | struct bfd_link_hash_table *ret; | |
11103 | ||
11104 | ret = ppc_elf_link_hash_table_create (abfd); | |
11105 | if (ret) | |
11106 | { | |
11107 | struct ppc_elf_link_hash_table *htab | |
954b63d4 | 11108 | = (struct ppc_elf_link_hash_table *)ret; |
9d8504b1 | 11109 | htab->is_vxworks = 1; |
4a3dc543 | 11110 | htab->plt_type = PLT_VXWORKS; |
9d8504b1 PB |
11111 | htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE; |
11112 | htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE; | |
11113 | htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE; | |
11114 | } | |
11115 | return ret; | |
11116 | } | |
11117 | ||
11118 | /* Tweak magic VxWorks symbols as they are loaded. */ | |
11119 | static bfd_boolean | |
11120 | ppc_elf_vxworks_add_symbol_hook (bfd *abfd, | |
11121 | struct bfd_link_info *info, | |
11122 | Elf_Internal_Sym *sym, | |
4aef7643 AM |
11123 | const char **namep, |
11124 | flagword *flagsp, | |
9d8504b1 PB |
11125 | asection **secp, |
11126 | bfd_vma *valp) | |
11127 | { | |
4aef7643 AM |
11128 | if (!elf_vxworks_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, |
11129 | valp)) | |
9d8504b1 PB |
11130 | return FALSE; |
11131 | ||
4aef7643 | 11132 | return ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp); |
9d8504b1 PB |
11133 | } |
11134 | ||
9d8504b1 PB |
11135 | static void |
11136 | ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
11137 | { | |
4aef7643 AM |
11138 | ppc_elf_final_write_processing (abfd, linker); |
11139 | elf_vxworks_final_write_processing (abfd, linker); | |
9d8504b1 PB |
11140 | } |
11141 | ||
11142 | /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so | |
11143 | define it. */ | |
11144 | #undef elf_backend_want_plt_sym | |
11145 | #define elf_backend_want_plt_sym 1 | |
11146 | #undef elf_backend_want_got_plt | |
11147 | #define elf_backend_want_got_plt 1 | |
11148 | #undef elf_backend_got_symbol_offset | |
11149 | #define elf_backend_got_symbol_offset 0 | |
11150 | #undef elf_backend_plt_not_loaded | |
11151 | #define elf_backend_plt_not_loaded 0 | |
11152 | #undef elf_backend_plt_readonly | |
11153 | #define elf_backend_plt_readonly 1 | |
11154 | #undef elf_backend_got_header_size | |
11155 | #define elf_backend_got_header_size 12 | |
64f52338 AM |
11156 | #undef elf_backend_dtrel_excludes_plt |
11157 | #define elf_backend_dtrel_excludes_plt 1 | |
9d8504b1 | 11158 | |
468392fb AM |
11159 | #undef bfd_elf32_get_synthetic_symtab |
11160 | ||
9d8504b1 PB |
11161 | #undef bfd_elf32_bfd_link_hash_table_create |
11162 | #define bfd_elf32_bfd_link_hash_table_create \ | |
11163 | ppc_elf_vxworks_link_hash_table_create | |
9d8504b1 PB |
11164 | #undef elf_backend_add_symbol_hook |
11165 | #define elf_backend_add_symbol_hook \ | |
11166 | ppc_elf_vxworks_add_symbol_hook | |
11167 | #undef elf_backend_link_output_symbol_hook | |
11168 | #define elf_backend_link_output_symbol_hook \ | |
9c72ff84 | 11169 | elf_vxworks_link_output_symbol_hook |
9d8504b1 PB |
11170 | #undef elf_backend_final_write_processing |
11171 | #define elf_backend_final_write_processing \ | |
11172 | ppc_elf_vxworks_final_write_processing | |
d5e3d971 PB |
11173 | #undef elf_backend_get_sec_type_attr |
11174 | #define elf_backend_get_sec_type_attr \ | |
11175 | ppc_elf_vxworks_get_sec_type_attr | |
9d8504b1 PB |
11176 | #undef elf_backend_emit_relocs |
11177 | #define elf_backend_emit_relocs \ | |
11178 | elf_vxworks_emit_relocs | |
11179 | ||
11180 | #undef elf32_bed | |
11181 | #define elf32_bed ppc_elf_vxworks_bed | |
e054468f | 11182 | #undef elf_backend_post_process_headers |
9d8504b1 PB |
11183 | |
11184 | #include "elf32-target.h" |