Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* PowerPC-specific support for 32-bit ELF |
051d5130 | 2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
3a71aa26 | 3 | 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Ian Lance Taylor, Cygnus Support. |
5 | ||
ae9a127f | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
ae9a127f NC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 10 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 11 | (at your option) any later version. |
252b5132 | 12 | |
ae9a127f NC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
252b5132 | 17 | |
ae9a127f | 18 | You should have received a copy of the GNU General Public License |
fc0bffd6 | 19 | along with this program; if not, write to the |
3e110533 | 20 | Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
53e09e0a | 21 | Boston, MA 02110-1301, USA. */ |
252b5132 | 22 | |
cd123cb7 | 23 | |
252b5132 RH |
24 | /* This file is based on a preliminary PowerPC ELF ABI. The |
25 | information may not match the final PowerPC ELF ABI. It includes | |
26 | suggestions from the in-progress Embedded PowerPC ABI, and that | |
27 | information may also not match. */ | |
28 | ||
3db64b00 | 29 | #include "sysdep.h" |
183e98be | 30 | #include <stdarg.h> |
252b5132 | 31 | #include "bfd.h" |
252b5132 RH |
32 | #include "bfdlink.h" |
33 | #include "libbfd.h" | |
34 | #include "elf-bfd.h" | |
35 | #include "elf/ppc.h" | |
7619e7c7 | 36 | #include "elf32-ppc.h" |
9d8504b1 | 37 | #include "elf-vxworks.h" |
252b5132 | 38 | |
f0fe0e16 | 39 | /* RELA relocations are used here. */ |
252b5132 | 40 | |
252b5132 | 41 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
55fd94b0 | 42 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
7619e7c7 | 43 | static bfd_reloc_status_type ppc_elf_unhandled_reloc |
55fd94b0 | 44 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
252b5132 | 45 | |
70bccea4 AM |
46 | /* Branch prediction bit for branch taken relocs. */ |
47 | #define BRANCH_PREDICT_BIT 0x200000 | |
48 | /* Mask to set RA in memory instructions. */ | |
49 | #define RA_REGISTER_MASK 0x001f0000 | |
50 | /* Value to shift register by to insert RA. */ | |
51 | #define RA_REGISTER_SHIFT 16 | |
252b5132 RH |
52 | |
53 | /* The name of the dynamic interpreter. This is put in the .interp | |
54 | section. */ | |
252b5132 RH |
55 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
56 | ||
d7128ce4 | 57 | /* For old-style PLT. */ |
252b5132 RH |
58 | /* The number of single-slot PLT entries (the rest use two slots). */ |
59 | #define PLT_NUM_SINGLE_ENTRIES 8192 | |
60 | ||
d7128ce4 | 61 | /* For new-style .glink and .plt. */ |
a6aa5195 | 62 | #define GLINK_PLTRESOLVE 16*4 |
d7128ce4 AM |
63 | #define GLINK_ENTRY_SIZE 4*4 |
64 | ||
9d8504b1 PB |
65 | /* VxWorks uses its own plt layout, filled in by the static linker. */ |
66 | ||
67 | /* The standard VxWorks PLT entry. */ | |
68 | #define VXWORKS_PLT_ENTRY_SIZE 32 | |
69 | static const bfd_vma ppc_elf_vxworks_plt_entry | |
70 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
71 | { | |
72 | 0x3d800000, /* lis r12,0 */ | |
73 | 0x818c0000, /* lwz r12,0(r12) */ | |
74 | 0x7d8903a6, /* mtctr r12 */ | |
75 | 0x4e800420, /* bctr */ | |
76 | 0x39600000, /* li r11,0 */ | |
77 | 0x48000000, /* b 14 <.PLT0resolve+0x4> */ | |
78 | 0x60000000, /* nop */ | |
79 | 0x60000000, /* nop */ | |
80 | }; | |
81 | static const bfd_vma ppc_elf_vxworks_pic_plt_entry | |
82 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
83 | { | |
84 | 0x3d9e0000, /* addis r12,r30,0 */ | |
85 | 0x818c0000, /* lwz r12,0(r12) */ | |
86 | 0x7d8903a6, /* mtctr r12 */ | |
87 | 0x4e800420, /* bctr */ | |
88 | 0x39600000, /* li r11,0 */ | |
89 | 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */ | |
90 | 0x60000000, /* nop */ | |
91 | 0x60000000, /* nop */ | |
92 | }; | |
93 | ||
94 | /* The initial VxWorks PLT entry. */ | |
95 | #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32 | |
96 | static const bfd_vma ppc_elf_vxworks_plt0_entry | |
97 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
98 | { | |
99 | 0x3d800000, /* lis r12,0 */ | |
100 | 0x398c0000, /* addi r12,r12,0 */ | |
101 | 0x800c0008, /* lwz r0,8(r12) */ | |
102 | 0x7c0903a6, /* mtctr r0 */ | |
103 | 0x818c0004, /* lwz r12,4(r12) */ | |
104 | 0x4e800420, /* bctr */ | |
105 | 0x60000000, /* nop */ | |
106 | 0x60000000, /* nop */ | |
107 | }; | |
108 | static const bfd_vma ppc_elf_vxworks_pic_plt0_entry | |
109 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
110 | { | |
111 | 0x819e0008, /* lwz r12,8(r30) */ | |
112 | 0x7d8903a6, /* mtctr r12 */ | |
113 | 0x819e0004, /* lwz r12,4(r30) */ | |
114 | 0x4e800420, /* bctr */ | |
115 | 0x60000000, /* nop */ | |
116 | 0x60000000, /* nop */ | |
117 | 0x60000000, /* nop */ | |
118 | 0x60000000, /* nop */ | |
119 | }; | |
120 | ||
121 | /* For executables, we have some additional relocations in | |
122 | .rela.plt.unloaded, for the kernel loader. */ | |
123 | ||
124 | /* The number of non-JMP_SLOT relocations per PLT0 slot. */ | |
125 | #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3 | |
126 | /* The number of relocations in the PLTResolve slot. */ | |
127 | #define VXWORKS_PLTRESOLVE_RELOCS 2 | |
128 | /* The number of relocations in the PLTResolve slot when when creating | |
129 | a shared library. */ | |
130 | #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0 | |
131 | ||
d7128ce4 | 132 | /* Some instructions. */ |
d7128ce4 | 133 | #define ADDIS_11_11 0x3d6b0000 |
a6aa5195 AM |
134 | #define ADDIS_11_30 0x3d7e0000 |
135 | #define ADDIS_12_12 0x3d8c0000 | |
d7128ce4 | 136 | #define ADDI_11_11 0x396b0000 |
d7128ce4 AM |
137 | #define ADD_0_11_11 0x7c0b5a14 |
138 | #define ADD_11_0_11 0x7d605a14 | |
a6aa5195 AM |
139 | #define B 0x48000000 |
140 | #define BCL_20_31 0x429f0005 | |
d7128ce4 | 141 | #define BCTR 0x4e800420 |
7e8aeb9a AM |
142 | #define LIS_11 0x3d600000 |
143 | #define LIS_12 0x3d800000 | |
a6aa5195 AM |
144 | #define LWZU_0_12 0x840c0000 |
145 | #define LWZ_0_12 0x800c0000 | |
146 | #define LWZ_11_11 0x816b0000 | |
147 | #define LWZ_11_30 0x817e0000 | |
148 | #define LWZ_12_12 0x818c0000 | |
149 | #define MFLR_0 0x7c0802a6 | |
150 | #define MFLR_12 0x7d8802a6 | |
151 | #define MTCTR_0 0x7c0903a6 | |
152 | #define MTCTR_11 0x7d6903a6 | |
153 | #define MTLR_0 0x7c0803a6 | |
154 | #define NOP 0x60000000 | |
155 | #define SUB_11_11_12 0x7d6c5850 | |
7619e7c7 AM |
156 | |
157 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
158 | #define TP_OFFSET 0x7000 | |
159 | #define DTP_OFFSET 0x8000 | |
e87d4038 AM |
160 | |
161 | /* The value of a defined global symbol. */ | |
162 | #define SYM_VAL(SYM) \ | |
163 | ((SYM)->root.u.def.section->output_section->vma \ | |
164 | + (SYM)->root.u.def.section->output_offset \ | |
165 | + (SYM)->root.u.def.value) | |
7fce784e | 166 | \f |
e47cd125 | 167 | static reloc_howto_type *ppc_elf_howto_table[R_PPC_max]; |
252b5132 | 168 | |
8da6118f | 169 | static reloc_howto_type ppc_elf_howto_raw[] = { |
252b5132 RH |
170 | /* This reloc does nothing. */ |
171 | HOWTO (R_PPC_NONE, /* type */ | |
172 | 0, /* rightshift */ | |
173 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
174 | 32, /* bitsize */ | |
b34976b6 | 175 | FALSE, /* pc_relative */ |
252b5132 RH |
176 | 0, /* bitpos */ |
177 | complain_overflow_bitfield, /* complain_on_overflow */ | |
178 | bfd_elf_generic_reloc, /* special_function */ | |
179 | "R_PPC_NONE", /* name */ | |
b34976b6 | 180 | FALSE, /* partial_inplace */ |
252b5132 RH |
181 | 0, /* src_mask */ |
182 | 0, /* dst_mask */ | |
b34976b6 | 183 | FALSE), /* pcrel_offset */ |
252b5132 RH |
184 | |
185 | /* A standard 32 bit relocation. */ | |
186 | HOWTO (R_PPC_ADDR32, /* type */ | |
187 | 0, /* rightshift */ | |
188 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
189 | 32, /* bitsize */ | |
b34976b6 | 190 | FALSE, /* pc_relative */ |
252b5132 RH |
191 | 0, /* bitpos */ |
192 | complain_overflow_bitfield, /* complain_on_overflow */ | |
193 | bfd_elf_generic_reloc, /* special_function */ | |
194 | "R_PPC_ADDR32", /* name */ | |
b34976b6 | 195 | FALSE, /* partial_inplace */ |
252b5132 RH |
196 | 0, /* src_mask */ |
197 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 198 | FALSE), /* pcrel_offset */ |
252b5132 RH |
199 | |
200 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
201 | FIXME: we don't check that, we just clear them. */ | |
202 | HOWTO (R_PPC_ADDR24, /* type */ | |
203 | 0, /* rightshift */ | |
204 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
205 | 26, /* bitsize */ | |
b34976b6 | 206 | FALSE, /* pc_relative */ |
252b5132 RH |
207 | 0, /* bitpos */ |
208 | complain_overflow_bitfield, /* complain_on_overflow */ | |
209 | bfd_elf_generic_reloc, /* special_function */ | |
210 | "R_PPC_ADDR24", /* name */ | |
b34976b6 | 211 | FALSE, /* partial_inplace */ |
252b5132 RH |
212 | 0, /* src_mask */ |
213 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 214 | FALSE), /* pcrel_offset */ |
252b5132 RH |
215 | |
216 | /* A standard 16 bit relocation. */ | |
217 | HOWTO (R_PPC_ADDR16, /* type */ | |
218 | 0, /* rightshift */ | |
219 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
220 | 16, /* bitsize */ | |
b34976b6 | 221 | FALSE, /* pc_relative */ |
252b5132 RH |
222 | 0, /* bitpos */ |
223 | complain_overflow_bitfield, /* complain_on_overflow */ | |
224 | bfd_elf_generic_reloc, /* special_function */ | |
225 | "R_PPC_ADDR16", /* name */ | |
b34976b6 | 226 | FALSE, /* partial_inplace */ |
252b5132 RH |
227 | 0, /* src_mask */ |
228 | 0xffff, /* dst_mask */ | |
b34976b6 | 229 | FALSE), /* pcrel_offset */ |
252b5132 RH |
230 | |
231 | /* A 16 bit relocation without overflow. */ | |
232 | HOWTO (R_PPC_ADDR16_LO, /* type */ | |
233 | 0, /* rightshift */ | |
234 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
235 | 16, /* bitsize */ | |
b34976b6 | 236 | FALSE, /* pc_relative */ |
252b5132 RH |
237 | 0, /* bitpos */ |
238 | complain_overflow_dont,/* complain_on_overflow */ | |
239 | bfd_elf_generic_reloc, /* special_function */ | |
240 | "R_PPC_ADDR16_LO", /* name */ | |
b34976b6 | 241 | FALSE, /* partial_inplace */ |
252b5132 RH |
242 | 0, /* src_mask */ |
243 | 0xffff, /* dst_mask */ | |
b34976b6 | 244 | FALSE), /* pcrel_offset */ |
252b5132 RH |
245 | |
246 | /* The high order 16 bits of an address. */ | |
247 | HOWTO (R_PPC_ADDR16_HI, /* type */ | |
248 | 16, /* rightshift */ | |
249 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
250 | 16, /* bitsize */ | |
b34976b6 | 251 | FALSE, /* pc_relative */ |
252b5132 RH |
252 | 0, /* bitpos */ |
253 | complain_overflow_dont, /* complain_on_overflow */ | |
254 | bfd_elf_generic_reloc, /* special_function */ | |
255 | "R_PPC_ADDR16_HI", /* name */ | |
b34976b6 | 256 | FALSE, /* partial_inplace */ |
252b5132 RH |
257 | 0, /* src_mask */ |
258 | 0xffff, /* dst_mask */ | |
b34976b6 | 259 | FALSE), /* pcrel_offset */ |
252b5132 RH |
260 | |
261 | /* The high order 16 bits of an address, plus 1 if the contents of | |
8da6118f | 262 | the low 16 bits, treated as a signed number, is negative. */ |
252b5132 RH |
263 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
264 | 16, /* rightshift */ | |
265 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
266 | 16, /* bitsize */ | |
b34976b6 | 267 | FALSE, /* pc_relative */ |
252b5132 RH |
268 | 0, /* bitpos */ |
269 | complain_overflow_dont, /* complain_on_overflow */ | |
270 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
271 | "R_PPC_ADDR16_HA", /* name */ | |
b34976b6 | 272 | FALSE, /* partial_inplace */ |
252b5132 RH |
273 | 0, /* src_mask */ |
274 | 0xffff, /* dst_mask */ | |
b34976b6 | 275 | FALSE), /* pcrel_offset */ |
252b5132 RH |
276 | |
277 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
278 | FIXME: we don't check that, we just clear them. */ | |
279 | HOWTO (R_PPC_ADDR14, /* type */ | |
280 | 0, /* rightshift */ | |
281 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
282 | 16, /* bitsize */ | |
b34976b6 | 283 | FALSE, /* pc_relative */ |
252b5132 RH |
284 | 0, /* bitpos */ |
285 | complain_overflow_bitfield, /* complain_on_overflow */ | |
286 | bfd_elf_generic_reloc, /* special_function */ | |
287 | "R_PPC_ADDR14", /* name */ | |
b34976b6 | 288 | FALSE, /* partial_inplace */ |
252b5132 RH |
289 | 0, /* src_mask */ |
290 | 0xfffc, /* dst_mask */ | |
b34976b6 | 291 | FALSE), /* pcrel_offset */ |
252b5132 RH |
292 | |
293 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
294 | indicate that the branch is expected to be taken. The lower two | |
8da6118f | 295 | bits must be zero. */ |
252b5132 RH |
296 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
297 | 0, /* rightshift */ | |
298 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
299 | 16, /* bitsize */ | |
b34976b6 | 300 | FALSE, /* pc_relative */ |
252b5132 RH |
301 | 0, /* bitpos */ |
302 | complain_overflow_bitfield, /* complain_on_overflow */ | |
303 | bfd_elf_generic_reloc, /* special_function */ | |
304 | "R_PPC_ADDR14_BRTAKEN",/* 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 not expected to be taken. The lower | |
312 | two bits must be zero. */ | |
313 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
314 | 0, /* rightshift */ | |
315 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
316 | 16, /* bitsize */ | |
b34976b6 | 317 | FALSE, /* pc_relative */ |
252b5132 RH |
318 | 0, /* bitpos */ |
319 | complain_overflow_bitfield, /* complain_on_overflow */ | |
320 | bfd_elf_generic_reloc, /* special_function */ | |
321 | "R_PPC_ADDR14_BRNTAKEN",/* name */ | |
b34976b6 | 322 | FALSE, /* partial_inplace */ |
252b5132 RH |
323 | 0, /* src_mask */ |
324 | 0xfffc, /* dst_mask */ | |
b34976b6 | 325 | FALSE), /* pcrel_offset */ |
252b5132 | 326 | |
8da6118f | 327 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
328 | HOWTO (R_PPC_REL24, /* type */ |
329 | 0, /* rightshift */ | |
330 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
331 | 26, /* bitsize */ | |
b34976b6 | 332 | TRUE, /* pc_relative */ |
252b5132 RH |
333 | 0, /* bitpos */ |
334 | complain_overflow_signed, /* complain_on_overflow */ | |
335 | bfd_elf_generic_reloc, /* special_function */ | |
336 | "R_PPC_REL24", /* name */ | |
b34976b6 | 337 | FALSE, /* partial_inplace */ |
252b5132 RH |
338 | 0, /* src_mask */ |
339 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 340 | TRUE), /* pcrel_offset */ |
252b5132 | 341 | |
8da6118f | 342 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
343 | HOWTO (R_PPC_REL14, /* type */ |
344 | 0, /* rightshift */ | |
345 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
346 | 16, /* bitsize */ | |
b34976b6 | 347 | TRUE, /* pc_relative */ |
252b5132 RH |
348 | 0, /* bitpos */ |
349 | complain_overflow_signed, /* complain_on_overflow */ | |
350 | bfd_elf_generic_reloc, /* special_function */ | |
351 | "R_PPC_REL14", /* name */ | |
b34976b6 | 352 | FALSE, /* partial_inplace */ |
252b5132 RH |
353 | 0, /* src_mask */ |
354 | 0xfffc, /* dst_mask */ | |
b34976b6 | 355 | TRUE), /* pcrel_offset */ |
252b5132 | 356 | |
8da6118f | 357 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
358 | the branch is expected to be taken. The lower two bits must be |
359 | zero. */ | |
360 | HOWTO (R_PPC_REL14_BRTAKEN, /* 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_BRTAKEN", /* 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 not expected to be taken. The lower two bits must |
376 | be zero. */ | |
377 | HOWTO (R_PPC_REL14_BRNTAKEN, /* 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_BRNTAKEN",/* name */ | |
b34976b6 | 386 | FALSE, /* partial_inplace */ |
252b5132 RH |
387 | 0, /* src_mask */ |
388 | 0xfffc, /* dst_mask */ | |
b34976b6 | 389 | TRUE), /* pcrel_offset */ |
252b5132 RH |
390 | |
391 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
392 | symbol. */ | |
393 | HOWTO (R_PPC_GOT16, /* type */ | |
394 | 0, /* rightshift */ | |
395 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
396 | 16, /* bitsize */ | |
b34976b6 | 397 | FALSE, /* pc_relative */ |
252b5132 RH |
398 | 0, /* bitpos */ |
399 | complain_overflow_signed, /* complain_on_overflow */ | |
400 | bfd_elf_generic_reloc, /* special_function */ | |
401 | "R_PPC_GOT16", /* name */ | |
b34976b6 | 402 | FALSE, /* partial_inplace */ |
252b5132 RH |
403 | 0, /* src_mask */ |
404 | 0xffff, /* dst_mask */ | |
b34976b6 | 405 | FALSE), /* pcrel_offset */ |
252b5132 RH |
406 | |
407 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
408 | the symbol. */ | |
409 | HOWTO (R_PPC_GOT16_LO, /* type */ | |
410 | 0, /* rightshift */ | |
411 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
412 | 16, /* bitsize */ | |
b34976b6 | 413 | FALSE, /* pc_relative */ |
252b5132 RH |
414 | 0, /* bitpos */ |
415 | complain_overflow_dont, /* complain_on_overflow */ | |
416 | bfd_elf_generic_reloc, /* special_function */ | |
417 | "R_PPC_GOT16_LO", /* name */ | |
b34976b6 | 418 | FALSE, /* partial_inplace */ |
252b5132 RH |
419 | 0, /* src_mask */ |
420 | 0xffff, /* dst_mask */ | |
b34976b6 | 421 | FALSE), /* pcrel_offset */ |
252b5132 RH |
422 | |
423 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
424 | the symbol. */ | |
425 | HOWTO (R_PPC_GOT16_HI, /* type */ | |
426 | 16, /* rightshift */ | |
427 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
428 | 16, /* bitsize */ | |
b34976b6 | 429 | FALSE, /* pc_relative */ |
252b5132 RH |
430 | 0, /* bitpos */ |
431 | complain_overflow_bitfield, /* complain_on_overflow */ | |
432 | bfd_elf_generic_reloc, /* special_function */ | |
433 | "R_PPC_GOT16_HI", /* name */ | |
b34976b6 | 434 | FALSE, /* partial_inplace */ |
252b5132 RH |
435 | 0, /* src_mask */ |
436 | 0xffff, /* dst_mask */ | |
b34976b6 | 437 | FALSE), /* pcrel_offset */ |
252b5132 RH |
438 | |
439 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
440 | the symbol. */ | |
441 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
442 | 16, /* rightshift */ | |
443 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
444 | 16, /* bitsize */ | |
b34976b6 | 445 | FALSE, /* pc_relative */ |
252b5132 RH |
446 | 0, /* bitpos */ |
447 | complain_overflow_bitfield, /* complain_on_overflow */ | |
448 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
449 | "R_PPC_GOT16_HA", /* name */ | |
b34976b6 | 450 | FALSE, /* partial_inplace */ |
252b5132 RH |
451 | 0, /* src_mask */ |
452 | 0xffff, /* dst_mask */ | |
b34976b6 | 453 | FALSE), /* pcrel_offset */ |
252b5132 RH |
454 | |
455 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
456 | entry for the symbol. */ | |
457 | HOWTO (R_PPC_PLTREL24, /* type */ | |
458 | 0, /* rightshift */ | |
459 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
460 | 26, /* bitsize */ | |
b34976b6 | 461 | TRUE, /* pc_relative */ |
252b5132 RH |
462 | 0, /* bitpos */ |
463 | complain_overflow_signed, /* complain_on_overflow */ | |
464 | bfd_elf_generic_reloc, /* special_function */ | |
465 | "R_PPC_PLTREL24", /* name */ | |
b34976b6 | 466 | FALSE, /* partial_inplace */ |
252b5132 RH |
467 | 0, /* src_mask */ |
468 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 469 | TRUE), /* pcrel_offset */ |
252b5132 RH |
470 | |
471 | /* This is used only by the dynamic linker. The symbol should exist | |
472 | both in the object being run and in some shared library. The | |
473 | dynamic linker copies the data addressed by the symbol from the | |
474 | shared library into the object, because the object being | |
475 | run has to have the data at some particular address. */ | |
476 | HOWTO (R_PPC_COPY, /* type */ | |
477 | 0, /* rightshift */ | |
478 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
479 | 32, /* bitsize */ | |
b34976b6 | 480 | FALSE, /* pc_relative */ |
252b5132 RH |
481 | 0, /* bitpos */ |
482 | complain_overflow_bitfield, /* complain_on_overflow */ | |
483 | bfd_elf_generic_reloc, /* special_function */ | |
484 | "R_PPC_COPY", /* name */ | |
b34976b6 | 485 | FALSE, /* partial_inplace */ |
252b5132 RH |
486 | 0, /* src_mask */ |
487 | 0, /* dst_mask */ | |
b34976b6 | 488 | FALSE), /* pcrel_offset */ |
252b5132 RH |
489 | |
490 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
491 | entries. */ | |
492 | HOWTO (R_PPC_GLOB_DAT, /* type */ | |
493 | 0, /* rightshift */ | |
494 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
495 | 32, /* bitsize */ | |
b34976b6 | 496 | FALSE, /* pc_relative */ |
252b5132 RH |
497 | 0, /* bitpos */ |
498 | complain_overflow_bitfield, /* complain_on_overflow */ | |
499 | bfd_elf_generic_reloc, /* special_function */ | |
500 | "R_PPC_GLOB_DAT", /* name */ | |
b34976b6 | 501 | FALSE, /* partial_inplace */ |
252b5132 RH |
502 | 0, /* src_mask */ |
503 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 504 | FALSE), /* pcrel_offset */ |
252b5132 RH |
505 | |
506 | /* Marks a procedure linkage table entry for a symbol. */ | |
507 | HOWTO (R_PPC_JMP_SLOT, /* type */ | |
508 | 0, /* rightshift */ | |
509 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
510 | 32, /* bitsize */ | |
b34976b6 | 511 | FALSE, /* pc_relative */ |
252b5132 RH |
512 | 0, /* bitpos */ |
513 | complain_overflow_bitfield, /* complain_on_overflow */ | |
514 | bfd_elf_generic_reloc, /* special_function */ | |
515 | "R_PPC_JMP_SLOT", /* name */ | |
b34976b6 | 516 | FALSE, /* partial_inplace */ |
252b5132 RH |
517 | 0, /* src_mask */ |
518 | 0, /* dst_mask */ | |
b34976b6 | 519 | FALSE), /* pcrel_offset */ |
252b5132 RH |
520 | |
521 | /* Used only by the dynamic linker. When the object is run, this | |
522 | longword is set to the load address of the object, plus the | |
523 | addend. */ | |
524 | HOWTO (R_PPC_RELATIVE, /* type */ | |
525 | 0, /* rightshift */ | |
526 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
527 | 32, /* bitsize */ | |
b34976b6 | 528 | FALSE, /* pc_relative */ |
252b5132 RH |
529 | 0, /* bitpos */ |
530 | complain_overflow_bitfield, /* complain_on_overflow */ | |
531 | bfd_elf_generic_reloc, /* special_function */ | |
532 | "R_PPC_RELATIVE", /* name */ | |
b34976b6 | 533 | FALSE, /* partial_inplace */ |
252b5132 RH |
534 | 0, /* src_mask */ |
535 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 536 | FALSE), /* pcrel_offset */ |
252b5132 RH |
537 | |
538 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
539 | object rather than the final value. Normally used for | |
540 | _GLOBAL_OFFSET_TABLE_. */ | |
541 | HOWTO (R_PPC_LOCAL24PC, /* type */ | |
542 | 0, /* rightshift */ | |
543 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
544 | 26, /* bitsize */ | |
b34976b6 | 545 | TRUE, /* pc_relative */ |
252b5132 RH |
546 | 0, /* bitpos */ |
547 | complain_overflow_signed, /* complain_on_overflow */ | |
548 | bfd_elf_generic_reloc, /* special_function */ | |
549 | "R_PPC_LOCAL24PC", /* name */ | |
b34976b6 | 550 | FALSE, /* partial_inplace */ |
252b5132 RH |
551 | 0, /* src_mask */ |
552 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 553 | TRUE), /* pcrel_offset */ |
252b5132 RH |
554 | |
555 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
556 | HOWTO (R_PPC_UADDR32, /* type */ | |
557 | 0, /* rightshift */ | |
558 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
559 | 32, /* bitsize */ | |
b34976b6 | 560 | FALSE, /* pc_relative */ |
252b5132 RH |
561 | 0, /* bitpos */ |
562 | complain_overflow_bitfield, /* complain_on_overflow */ | |
563 | bfd_elf_generic_reloc, /* special_function */ | |
564 | "R_PPC_UADDR32", /* name */ | |
b34976b6 | 565 | FALSE, /* partial_inplace */ |
252b5132 RH |
566 | 0, /* src_mask */ |
567 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 568 | FALSE), /* pcrel_offset */ |
252b5132 RH |
569 | |
570 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
571 | HOWTO (R_PPC_UADDR16, /* type */ | |
572 | 0, /* rightshift */ | |
573 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
574 | 16, /* bitsize */ | |
b34976b6 | 575 | FALSE, /* pc_relative */ |
252b5132 RH |
576 | 0, /* bitpos */ |
577 | complain_overflow_bitfield, /* complain_on_overflow */ | |
578 | bfd_elf_generic_reloc, /* special_function */ | |
579 | "R_PPC_UADDR16", /* name */ | |
b34976b6 | 580 | FALSE, /* partial_inplace */ |
252b5132 RH |
581 | 0, /* src_mask */ |
582 | 0xffff, /* dst_mask */ | |
b34976b6 | 583 | FALSE), /* pcrel_offset */ |
252b5132 RH |
584 | |
585 | /* 32-bit PC relative */ | |
586 | HOWTO (R_PPC_REL32, /* type */ | |
587 | 0, /* rightshift */ | |
588 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
589 | 32, /* bitsize */ | |
b34976b6 | 590 | TRUE, /* pc_relative */ |
252b5132 RH |
591 | 0, /* bitpos */ |
592 | complain_overflow_bitfield, /* complain_on_overflow */ | |
593 | bfd_elf_generic_reloc, /* special_function */ | |
594 | "R_PPC_REL32", /* name */ | |
b34976b6 | 595 | FALSE, /* partial_inplace */ |
252b5132 RH |
596 | 0, /* src_mask */ |
597 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 598 | TRUE), /* pcrel_offset */ |
252b5132 RH |
599 | |
600 | /* 32-bit relocation to the symbol's procedure linkage table. | |
c3668558 | 601 | FIXME: not supported. */ |
252b5132 RH |
602 | HOWTO (R_PPC_PLT32, /* type */ |
603 | 0, /* rightshift */ | |
604 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
605 | 32, /* bitsize */ | |
b34976b6 | 606 | FALSE, /* pc_relative */ |
252b5132 RH |
607 | 0, /* bitpos */ |
608 | complain_overflow_bitfield, /* complain_on_overflow */ | |
609 | bfd_elf_generic_reloc, /* special_function */ | |
610 | "R_PPC_PLT32", /* name */ | |
b34976b6 | 611 | FALSE, /* partial_inplace */ |
252b5132 RH |
612 | 0, /* src_mask */ |
613 | 0, /* dst_mask */ | |
b34976b6 | 614 | FALSE), /* pcrel_offset */ |
252b5132 RH |
615 | |
616 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
c3668558 | 617 | FIXME: not supported. */ |
252b5132 RH |
618 | HOWTO (R_PPC_PLTREL32, /* type */ |
619 | 0, /* rightshift */ | |
620 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
621 | 32, /* bitsize */ | |
b34976b6 | 622 | TRUE, /* pc_relative */ |
252b5132 RH |
623 | 0, /* bitpos */ |
624 | complain_overflow_bitfield, /* complain_on_overflow */ | |
625 | bfd_elf_generic_reloc, /* special_function */ | |
626 | "R_PPC_PLTREL32", /* name */ | |
b34976b6 | 627 | FALSE, /* partial_inplace */ |
252b5132 RH |
628 | 0, /* src_mask */ |
629 | 0, /* dst_mask */ | |
b34976b6 | 630 | TRUE), /* pcrel_offset */ |
252b5132 RH |
631 | |
632 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
633 | the symbol. */ | |
634 | HOWTO (R_PPC_PLT16_LO, /* type */ | |
635 | 0, /* rightshift */ | |
636 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
637 | 16, /* bitsize */ | |
b34976b6 | 638 | FALSE, /* pc_relative */ |
252b5132 RH |
639 | 0, /* bitpos */ |
640 | complain_overflow_dont, /* complain_on_overflow */ | |
641 | bfd_elf_generic_reloc, /* special_function */ | |
642 | "R_PPC_PLT16_LO", /* name */ | |
b34976b6 | 643 | FALSE, /* partial_inplace */ |
252b5132 RH |
644 | 0, /* src_mask */ |
645 | 0xffff, /* dst_mask */ | |
b34976b6 | 646 | FALSE), /* pcrel_offset */ |
252b5132 RH |
647 | |
648 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
649 | the symbol. */ | |
650 | HOWTO (R_PPC_PLT16_HI, /* type */ | |
651 | 16, /* rightshift */ | |
652 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
653 | 16, /* bitsize */ | |
b34976b6 | 654 | FALSE, /* pc_relative */ |
252b5132 RH |
655 | 0, /* bitpos */ |
656 | complain_overflow_bitfield, /* complain_on_overflow */ | |
657 | bfd_elf_generic_reloc, /* special_function */ | |
658 | "R_PPC_PLT16_HI", /* name */ | |
b34976b6 | 659 | FALSE, /* partial_inplace */ |
252b5132 RH |
660 | 0, /* src_mask */ |
661 | 0xffff, /* dst_mask */ | |
b34976b6 | 662 | FALSE), /* pcrel_offset */ |
252b5132 RH |
663 | |
664 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
665 | the symbol. */ | |
666 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
667 | 16, /* rightshift */ | |
668 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
669 | 16, /* bitsize */ | |
b34976b6 | 670 | FALSE, /* pc_relative */ |
252b5132 RH |
671 | 0, /* bitpos */ |
672 | complain_overflow_bitfield, /* complain_on_overflow */ | |
673 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
674 | "R_PPC_PLT16_HA", /* name */ | |
b34976b6 | 675 | FALSE, /* partial_inplace */ |
252b5132 RH |
676 | 0, /* src_mask */ |
677 | 0xffff, /* dst_mask */ | |
b34976b6 | 678 | FALSE), /* pcrel_offset */ |
252b5132 RH |
679 | |
680 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with | |
681 | small data items. */ | |
682 | HOWTO (R_PPC_SDAREL16, /* type */ | |
683 | 0, /* rightshift */ | |
684 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
685 | 16, /* bitsize */ | |
b34976b6 | 686 | FALSE, /* pc_relative */ |
252b5132 RH |
687 | 0, /* bitpos */ |
688 | complain_overflow_signed, /* complain_on_overflow */ | |
689 | bfd_elf_generic_reloc, /* special_function */ | |
690 | "R_PPC_SDAREL16", /* name */ | |
b34976b6 | 691 | FALSE, /* partial_inplace */ |
252b5132 RH |
692 | 0, /* src_mask */ |
693 | 0xffff, /* dst_mask */ | |
b34976b6 | 694 | FALSE), /* pcrel_offset */ |
252b5132 | 695 | |
c061c2d8 | 696 | /* 16-bit section relative relocation. */ |
252b5132 RH |
697 | HOWTO (R_PPC_SECTOFF, /* type */ |
698 | 0, /* rightshift */ | |
c061c2d8 AM |
699 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
700 | 16, /* bitsize */ | |
b34976b6 | 701 | FALSE, /* pc_relative */ |
252b5132 RH |
702 | 0, /* bitpos */ |
703 | complain_overflow_bitfield, /* complain_on_overflow */ | |
704 | bfd_elf_generic_reloc, /* special_function */ | |
705 | "R_PPC_SECTOFF", /* name */ | |
b34976b6 | 706 | FALSE, /* partial_inplace */ |
252b5132 | 707 | 0, /* src_mask */ |
c061c2d8 | 708 | 0xffff, /* dst_mask */ |
b34976b6 | 709 | FALSE), /* pcrel_offset */ |
252b5132 | 710 | |
c3668558 | 711 | /* 16-bit lower half section relative relocation. */ |
252b5132 RH |
712 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
713 | 0, /* rightshift */ | |
714 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
715 | 16, /* bitsize */ | |
b34976b6 | 716 | FALSE, /* pc_relative */ |
252b5132 RH |
717 | 0, /* bitpos */ |
718 | complain_overflow_dont, /* complain_on_overflow */ | |
719 | bfd_elf_generic_reloc, /* special_function */ | |
720 | "R_PPC_SECTOFF_LO", /* name */ | |
b34976b6 | 721 | FALSE, /* partial_inplace */ |
252b5132 RH |
722 | 0, /* src_mask */ |
723 | 0xffff, /* dst_mask */ | |
b34976b6 | 724 | FALSE), /* pcrel_offset */ |
252b5132 | 725 | |
c3668558 | 726 | /* 16-bit upper half section relative relocation. */ |
252b5132 RH |
727 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
728 | 16, /* rightshift */ | |
729 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
730 | 16, /* bitsize */ | |
b34976b6 | 731 | FALSE, /* pc_relative */ |
252b5132 RH |
732 | 0, /* bitpos */ |
733 | complain_overflow_bitfield, /* complain_on_overflow */ | |
734 | bfd_elf_generic_reloc, /* special_function */ | |
735 | "R_PPC_SECTOFF_HI", /* name */ | |
b34976b6 | 736 | FALSE, /* partial_inplace */ |
252b5132 RH |
737 | 0, /* src_mask */ |
738 | 0xffff, /* dst_mask */ | |
b34976b6 | 739 | FALSE), /* pcrel_offset */ |
252b5132 | 740 | |
c3668558 | 741 | /* 16-bit upper half adjusted section relative relocation. */ |
252b5132 RH |
742 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
743 | 16, /* rightshift */ | |
744 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
745 | 16, /* bitsize */ | |
b34976b6 | 746 | FALSE, /* pc_relative */ |
252b5132 RH |
747 | 0, /* bitpos */ |
748 | complain_overflow_bitfield, /* complain_on_overflow */ | |
749 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
750 | "R_PPC_SECTOFF_HA", /* name */ | |
b34976b6 | 751 | FALSE, /* partial_inplace */ |
252b5132 RH |
752 | 0, /* src_mask */ |
753 | 0xffff, /* dst_mask */ | |
b34976b6 | 754 | FALSE), /* pcrel_offset */ |
252b5132 | 755 | |
727fc41e | 756 | /* Marker relocs for TLS. */ |
7619e7c7 | 757 | HOWTO (R_PPC_TLS, |
252b5132 RH |
758 | 0, /* rightshift */ |
759 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
760 | 32, /* bitsize */ | |
b34976b6 | 761 | FALSE, /* pc_relative */ |
252b5132 | 762 | 0, /* bitpos */ |
7619e7c7 | 763 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 | 764 | bfd_elf_generic_reloc, /* special_function */ |
7619e7c7 AM |
765 | "R_PPC_TLS", /* name */ |
766 | FALSE, /* partial_inplace */ | |
767 | 0, /* src_mask */ | |
768 | 0, /* dst_mask */ | |
769 | FALSE), /* pcrel_offset */ | |
770 | ||
727fc41e AM |
771 | HOWTO (R_PPC_TLSGD, |
772 | 0, /* rightshift */ | |
773 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
774 | 32, /* bitsize */ | |
775 | FALSE, /* pc_relative */ | |
776 | 0, /* bitpos */ | |
777 | complain_overflow_dont, /* complain_on_overflow */ | |
778 | bfd_elf_generic_reloc, /* special_function */ | |
779 | "R_PPC_TLSGD", /* name */ | |
780 | FALSE, /* partial_inplace */ | |
781 | 0, /* src_mask */ | |
782 | 0, /* dst_mask */ | |
783 | FALSE), /* pcrel_offset */ | |
784 | ||
785 | HOWTO (R_PPC_TLSLD, | |
786 | 0, /* rightshift */ | |
787 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
788 | 32, /* bitsize */ | |
789 | FALSE, /* pc_relative */ | |
790 | 0, /* bitpos */ | |
791 | complain_overflow_dont, /* complain_on_overflow */ | |
792 | bfd_elf_generic_reloc, /* special_function */ | |
793 | "R_PPC_TLSLD", /* name */ | |
794 | FALSE, /* partial_inplace */ | |
795 | 0, /* src_mask */ | |
796 | 0, /* dst_mask */ | |
797 | FALSE), /* pcrel_offset */ | |
798 | ||
7619e7c7 AM |
799 | /* Computes the load module index of the load module that contains the |
800 | definition of its TLS sym. */ | |
801 | HOWTO (R_PPC_DTPMOD32, | |
802 | 0, /* rightshift */ | |
803 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
804 | 32, /* bitsize */ | |
805 | FALSE, /* pc_relative */ | |
806 | 0, /* bitpos */ | |
807 | complain_overflow_dont, /* complain_on_overflow */ | |
808 | ppc_elf_unhandled_reloc, /* special_function */ | |
809 | "R_PPC_DTPMOD32", /* name */ | |
b34976b6 | 810 | FALSE, /* partial_inplace */ |
252b5132 RH |
811 | 0, /* src_mask */ |
812 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 813 | FALSE), /* pcrel_offset */ |
252b5132 | 814 | |
7619e7c7 AM |
815 | /* Computes a dtv-relative displacement, the difference between the value |
816 | of sym+add and the base address of the thread-local storage block that | |
817 | contains the definition of sym, minus 0x8000. */ | |
818 | HOWTO (R_PPC_DTPREL32, | |
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_DTPREL32", /* name */ | |
827 | FALSE, /* partial_inplace */ | |
828 | 0, /* src_mask */ | |
829 | 0xffffffff, /* dst_mask */ | |
830 | FALSE), /* pcrel_offset */ | |
831 | ||
832 | /* A 16 bit dtprel reloc. */ | |
833 | HOWTO (R_PPC_DTPREL16, | |
252b5132 RH |
834 | 0, /* rightshift */ |
835 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
836 | 16, /* bitsize */ | |
b34976b6 | 837 | FALSE, /* pc_relative */ |
252b5132 | 838 | 0, /* bitpos */ |
7619e7c7 AM |
839 | complain_overflow_signed, /* complain_on_overflow */ |
840 | ppc_elf_unhandled_reloc, /* special_function */ | |
841 | "R_PPC_DTPREL16", /* name */ | |
b34976b6 | 842 | FALSE, /* partial_inplace */ |
252b5132 RH |
843 | 0, /* src_mask */ |
844 | 0xffff, /* dst_mask */ | |
b34976b6 | 845 | FALSE), /* pcrel_offset */ |
252b5132 | 846 | |
7619e7c7 AM |
847 | /* Like DTPREL16, but no overflow. */ |
848 | HOWTO (R_PPC_DTPREL16_LO, | |
252b5132 RH |
849 | 0, /* rightshift */ |
850 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
851 | 16, /* bitsize */ | |
b34976b6 | 852 | FALSE, /* pc_relative */ |
252b5132 | 853 | 0, /* bitpos */ |
7619e7c7 AM |
854 | complain_overflow_dont, /* complain_on_overflow */ |
855 | ppc_elf_unhandled_reloc, /* special_function */ | |
856 | "R_PPC_DTPREL16_LO", /* name */ | |
b34976b6 | 857 | FALSE, /* partial_inplace */ |
252b5132 RH |
858 | 0, /* src_mask */ |
859 | 0xffff, /* dst_mask */ | |
b34976b6 | 860 | FALSE), /* pcrel_offset */ |
252b5132 | 861 | |
7619e7c7 AM |
862 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ |
863 | HOWTO (R_PPC_DTPREL16_HI, | |
252b5132 RH |
864 | 16, /* rightshift */ |
865 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
866 | 16, /* bitsize */ | |
b34976b6 | 867 | FALSE, /* pc_relative */ |
252b5132 RH |
868 | 0, /* bitpos */ |
869 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
870 | ppc_elf_unhandled_reloc, /* special_function */ |
871 | "R_PPC_DTPREL16_HI", /* name */ | |
b34976b6 | 872 | FALSE, /* partial_inplace */ |
252b5132 RH |
873 | 0, /* src_mask */ |
874 | 0xffff, /* dst_mask */ | |
b34976b6 | 875 | FALSE), /* pcrel_offset */ |
252b5132 | 876 | |
7619e7c7 AM |
877 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ |
878 | HOWTO (R_PPC_DTPREL16_HA, | |
252b5132 RH |
879 | 16, /* rightshift */ |
880 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
881 | 16, /* bitsize */ | |
b34976b6 | 882 | FALSE, /* pc_relative */ |
252b5132 RH |
883 | 0, /* bitpos */ |
884 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
885 | ppc_elf_unhandled_reloc, /* special_function */ |
886 | "R_PPC_DTPREL16_HA", /* name */ | |
b34976b6 | 887 | FALSE, /* partial_inplace */ |
252b5132 RH |
888 | 0, /* src_mask */ |
889 | 0xffff, /* dst_mask */ | |
b34976b6 | 890 | FALSE), /* pcrel_offset */ |
252b5132 | 891 | |
7619e7c7 AM |
892 | /* Computes a tp-relative displacement, the difference between the value of |
893 | sym+add and the value of the thread pointer (r13). */ | |
894 | HOWTO (R_PPC_TPREL32, | |
895 | 0, /* rightshift */ | |
896 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
897 | 32, /* bitsize */ | |
898 | FALSE, /* pc_relative */ | |
899 | 0, /* bitpos */ | |
900 | complain_overflow_dont, /* complain_on_overflow */ | |
901 | ppc_elf_unhandled_reloc, /* special_function */ | |
902 | "R_PPC_TPREL32", /* name */ | |
903 | FALSE, /* partial_inplace */ | |
904 | 0, /* src_mask */ | |
905 | 0xffffffff, /* dst_mask */ | |
906 | FALSE), /* pcrel_offset */ | |
907 | ||
908 | /* A 16 bit tprel reloc. */ | |
909 | HOWTO (R_PPC_TPREL16, | |
252b5132 RH |
910 | 0, /* rightshift */ |
911 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
912 | 16, /* bitsize */ | |
b34976b6 | 913 | FALSE, /* pc_relative */ |
252b5132 | 914 | 0, /* bitpos */ |
7619e7c7 AM |
915 | complain_overflow_signed, /* complain_on_overflow */ |
916 | ppc_elf_unhandled_reloc, /* special_function */ | |
917 | "R_PPC_TPREL16", /* name */ | |
b34976b6 | 918 | FALSE, /* partial_inplace */ |
252b5132 RH |
919 | 0, /* src_mask */ |
920 | 0xffff, /* dst_mask */ | |
b34976b6 | 921 | FALSE), /* pcrel_offset */ |
252b5132 | 922 | |
7619e7c7 AM |
923 | /* Like TPREL16, but no overflow. */ |
924 | HOWTO (R_PPC_TPREL16_LO, | |
252b5132 RH |
925 | 0, /* rightshift */ |
926 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
927 | 16, /* bitsize */ | |
b34976b6 | 928 | FALSE, /* pc_relative */ |
252b5132 | 929 | 0, /* bitpos */ |
7619e7c7 AM |
930 | complain_overflow_dont, /* complain_on_overflow */ |
931 | ppc_elf_unhandled_reloc, /* special_function */ | |
932 | "R_PPC_TPREL16_LO", /* name */ | |
b34976b6 | 933 | FALSE, /* partial_inplace */ |
252b5132 RH |
934 | 0, /* src_mask */ |
935 | 0xffff, /* dst_mask */ | |
b34976b6 | 936 | FALSE), /* pcrel_offset */ |
252b5132 | 937 | |
7619e7c7 AM |
938 | /* Like TPREL16_LO, but next higher group of 16 bits. */ |
939 | HOWTO (R_PPC_TPREL16_HI, | |
940 | 16, /* rightshift */ | |
941 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
942 | 16, /* bitsize */ | |
943 | FALSE, /* pc_relative */ | |
944 | 0, /* bitpos */ | |
945 | complain_overflow_dont, /* complain_on_overflow */ | |
946 | ppc_elf_unhandled_reloc, /* special_function */ | |
947 | "R_PPC_TPREL16_HI", /* name */ | |
948 | FALSE, /* partial_inplace */ | |
949 | 0, /* src_mask */ | |
950 | 0xffff, /* dst_mask */ | |
951 | FALSE), /* pcrel_offset */ | |
952 | ||
953 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
954 | HOWTO (R_PPC_TPREL16_HA, | |
955 | 16, /* rightshift */ | |
956 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
957 | 16, /* bitsize */ | |
958 | FALSE, /* pc_relative */ | |
959 | 0, /* bitpos */ | |
960 | complain_overflow_dont, /* complain_on_overflow */ | |
961 | ppc_elf_unhandled_reloc, /* special_function */ | |
962 | "R_PPC_TPREL16_HA", /* name */ | |
963 | FALSE, /* partial_inplace */ | |
964 | 0, /* src_mask */ | |
965 | 0xffff, /* dst_mask */ | |
966 | FALSE), /* pcrel_offset */ | |
967 | ||
968 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
969 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
970 | to the first entry. */ | |
971 | HOWTO (R_PPC_GOT_TLSGD16, | |
252b5132 RH |
972 | 0, /* rightshift */ |
973 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
974 | 16, /* bitsize */ | |
b34976b6 | 975 | FALSE, /* pc_relative */ |
252b5132 RH |
976 | 0, /* bitpos */ |
977 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
978 | ppc_elf_unhandled_reloc, /* special_function */ |
979 | "R_PPC_GOT_TLSGD16", /* name */ | |
b34976b6 | 980 | FALSE, /* partial_inplace */ |
252b5132 RH |
981 | 0, /* src_mask */ |
982 | 0xffff, /* dst_mask */ | |
b34976b6 | 983 | FALSE), /* pcrel_offset */ |
252b5132 | 984 | |
7619e7c7 AM |
985 | /* Like GOT_TLSGD16, but no overflow. */ |
986 | HOWTO (R_PPC_GOT_TLSGD16_LO, | |
252b5132 | 987 | 0, /* rightshift */ |
7619e7c7 | 988 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 989 | 16, /* bitsize */ |
b34976b6 | 990 | FALSE, /* pc_relative */ |
252b5132 | 991 | 0, /* bitpos */ |
7619e7c7 AM |
992 | complain_overflow_dont, /* complain_on_overflow */ |
993 | ppc_elf_unhandled_reloc, /* special_function */ | |
994 | "R_PPC_GOT_TLSGD16_LO", /* name */ | |
b34976b6 | 995 | FALSE, /* partial_inplace */ |
252b5132 RH |
996 | 0, /* src_mask */ |
997 | 0xffff, /* dst_mask */ | |
b34976b6 | 998 | FALSE), /* pcrel_offset */ |
252b5132 | 999 | |
7619e7c7 AM |
1000 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1001 | HOWTO (R_PPC_GOT_TLSGD16_HI, | |
1002 | 16, /* rightshift */ | |
1003 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1004 | 16, /* bitsize */ | |
1005 | FALSE, /* pc_relative */ | |
1006 | 0, /* bitpos */ | |
1007 | complain_overflow_dont, /* complain_on_overflow */ | |
1008 | ppc_elf_unhandled_reloc, /* special_function */ | |
1009 | "R_PPC_GOT_TLSGD16_HI", /* name */ | |
1010 | FALSE, /* partial_inplace */ | |
1011 | 0, /* src_mask */ | |
1012 | 0xffff, /* dst_mask */ | |
1013 | FALSE), /* pcrel_offset */ | |
252b5132 | 1014 | |
7619e7c7 AM |
1015 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1016 | HOWTO (R_PPC_GOT_TLSGD16_HA, | |
1017 | 16, /* rightshift */ | |
1018 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1019 | 16, /* bitsize */ | |
1020 | FALSE, /* pc_relative */ | |
1021 | 0, /* bitpos */ | |
1022 | complain_overflow_dont, /* complain_on_overflow */ | |
1023 | ppc_elf_unhandled_reloc, /* special_function */ | |
1024 | "R_PPC_GOT_TLSGD16_HA", /* name */ | |
1025 | FALSE, /* partial_inplace */ | |
1026 | 0, /* src_mask */ | |
1027 | 0xffff, /* dst_mask */ | |
1028 | FALSE), /* pcrel_offset */ | |
1029 | ||
1030 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1031 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1032 | first entry. */ | |
1033 | HOWTO (R_PPC_GOT_TLSLD16, | |
252b5132 RH |
1034 | 0, /* rightshift */ |
1035 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1036 | 16, /* bitsize */ | |
7619e7c7 | 1037 | FALSE, /* pc_relative */ |
252b5132 RH |
1038 | 0, /* bitpos */ |
1039 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1040 | ppc_elf_unhandled_reloc, /* special_function */ |
1041 | "R_PPC_GOT_TLSLD16", /* name */ | |
b34976b6 | 1042 | FALSE, /* partial_inplace */ |
252b5132 RH |
1043 | 0, /* src_mask */ |
1044 | 0xffff, /* dst_mask */ | |
b34976b6 | 1045 | FALSE), /* pcrel_offset */ |
252b5132 | 1046 | |
7619e7c7 AM |
1047 | /* Like GOT_TLSLD16, but no overflow. */ |
1048 | HOWTO (R_PPC_GOT_TLSLD16_LO, | |
252b5132 | 1049 | 0, /* rightshift */ |
7619e7c7 AM |
1050 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1051 | 16, /* bitsize */ | |
b34976b6 | 1052 | FALSE, /* pc_relative */ |
252b5132 RH |
1053 | 0, /* bitpos */ |
1054 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1055 | ppc_elf_unhandled_reloc, /* special_function */ |
1056 | "R_PPC_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1057 | FALSE, /* partial_inplace */ |
252b5132 | 1058 | 0, /* src_mask */ |
7619e7c7 | 1059 | 0xffff, /* dst_mask */ |
b34976b6 | 1060 | FALSE), /* pcrel_offset */ |
252b5132 | 1061 | |
7619e7c7 AM |
1062 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1063 | HOWTO (R_PPC_GOT_TLSLD16_HI, | |
1064 | 16, /* rightshift */ | |
1065 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1066 | 16, /* bitsize */ | |
b34976b6 | 1067 | FALSE, /* pc_relative */ |
252b5132 RH |
1068 | 0, /* bitpos */ |
1069 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1070 | ppc_elf_unhandled_reloc, /* special_function */ |
1071 | "R_PPC_GOT_TLSLD16_HI", /* name */ | |
b34976b6 | 1072 | FALSE, /* partial_inplace */ |
252b5132 | 1073 | 0, /* src_mask */ |
7619e7c7 | 1074 | 0xffff, /* dst_mask */ |
b34976b6 | 1075 | FALSE), /* pcrel_offset */ |
252b5132 | 1076 | |
7619e7c7 AM |
1077 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1078 | HOWTO (R_PPC_GOT_TLSLD16_HA, | |
1079 | 16, /* rightshift */ | |
1080 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1081 | 16, /* bitsize */ | |
1082 | FALSE, /* pc_relative */ | |
1083 | 0, /* bitpos */ | |
1084 | complain_overflow_dont, /* complain_on_overflow */ | |
1085 | ppc_elf_unhandled_reloc, /* special_function */ | |
1086 | "R_PPC_GOT_TLSLD16_HA", /* name */ | |
1087 | FALSE, /* partial_inplace */ | |
1088 | 0, /* src_mask */ | |
1089 | 0xffff, /* dst_mask */ | |
1090 | FALSE), /* pcrel_offset */ | |
1091 | ||
1092 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes | |
1093 | the offset to the entry. */ | |
1094 | HOWTO (R_PPC_GOT_DTPREL16, | |
252b5132 RH |
1095 | 0, /* rightshift */ |
1096 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1097 | 16, /* bitsize */ | |
b34976b6 | 1098 | FALSE, /* pc_relative */ |
252b5132 RH |
1099 | 0, /* bitpos */ |
1100 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1101 | ppc_elf_unhandled_reloc, /* special_function */ |
1102 | "R_PPC_GOT_DTPREL16", /* name */ | |
b34976b6 | 1103 | FALSE, /* partial_inplace */ |
252b5132 RH |
1104 | 0, /* src_mask */ |
1105 | 0xffff, /* dst_mask */ | |
b34976b6 | 1106 | FALSE), /* pcrel_offset */ |
252b5132 | 1107 | |
7619e7c7 AM |
1108 | /* Like GOT_DTPREL16, but no overflow. */ |
1109 | HOWTO (R_PPC_GOT_DTPREL16_LO, | |
1110 | 0, /* rightshift */ | |
1111 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1112 | 16, /* bitsize */ | |
1113 | FALSE, /* pc_relative */ | |
1114 | 0, /* bitpos */ | |
1115 | complain_overflow_dont, /* complain_on_overflow */ | |
1116 | ppc_elf_unhandled_reloc, /* special_function */ | |
1117 | "R_PPC_GOT_DTPREL16_LO", /* name */ | |
1118 | FALSE, /* partial_inplace */ | |
1119 | 0, /* src_mask */ | |
1120 | 0xffff, /* dst_mask */ | |
1121 | FALSE), /* pcrel_offset */ | |
252b5132 | 1122 | |
7619e7c7 AM |
1123 | /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */ |
1124 | HOWTO (R_PPC_GOT_DTPREL16_HI, | |
1125 | 16, /* rightshift */ | |
1126 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1127 | 16, /* bitsize */ | |
1128 | FALSE, /* pc_relative */ | |
1129 | 0, /* bitpos */ | |
1130 | complain_overflow_dont, /* complain_on_overflow */ | |
1131 | ppc_elf_unhandled_reloc, /* special_function */ | |
1132 | "R_PPC_GOT_DTPREL16_HI", /* name */ | |
1133 | FALSE, /* partial_inplace */ | |
1134 | 0, /* src_mask */ | |
1135 | 0xffff, /* dst_mask */ | |
1136 | FALSE), /* pcrel_offset */ | |
252b5132 | 1137 | |
7619e7c7 AM |
1138 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1139 | HOWTO (R_PPC_GOT_DTPREL16_HA, | |
1140 | 16, /* rightshift */ | |
1141 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1142 | 16, /* bitsize */ | |
1143 | FALSE, /* pc_relative */ | |
1144 | 0, /* bitpos */ | |
1145 | complain_overflow_dont, /* complain_on_overflow */ | |
1146 | ppc_elf_unhandled_reloc, /* special_function */ | |
1147 | "R_PPC_GOT_DTPREL16_HA", /* name */ | |
1148 | FALSE, /* partial_inplace */ | |
1149 | 0, /* src_mask */ | |
1150 | 0xffff, /* dst_mask */ | |
1151 | FALSE), /* pcrel_offset */ | |
c3668558 | 1152 | |
7619e7c7 AM |
1153 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the |
1154 | offset to the entry. */ | |
1155 | HOWTO (R_PPC_GOT_TPREL16, | |
1156 | 0, /* rightshift */ | |
1157 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1158 | 16, /* bitsize */ | |
1159 | FALSE, /* pc_relative */ | |
1160 | 0, /* bitpos */ | |
1161 | complain_overflow_signed, /* complain_on_overflow */ | |
1162 | ppc_elf_unhandled_reloc, /* special_function */ | |
1163 | "R_PPC_GOT_TPREL16", /* name */ | |
1164 | FALSE, /* partial_inplace */ | |
1165 | 0, /* src_mask */ | |
1166 | 0xffff, /* dst_mask */ | |
1167 | FALSE), /* pcrel_offset */ | |
1168 | ||
1169 | /* Like GOT_TPREL16, but no overflow. */ | |
1170 | HOWTO (R_PPC_GOT_TPREL16_LO, | |
1171 | 0, /* rightshift */ | |
1172 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1173 | 16, /* bitsize */ | |
1174 | FALSE, /* pc_relative */ | |
1175 | 0, /* bitpos */ | |
1176 | complain_overflow_dont, /* complain_on_overflow */ | |
1177 | ppc_elf_unhandled_reloc, /* special_function */ | |
1178 | "R_PPC_GOT_TPREL16_LO", /* name */ | |
1179 | FALSE, /* partial_inplace */ | |
1180 | 0, /* src_mask */ | |
1181 | 0xffff, /* dst_mask */ | |
1182 | FALSE), /* pcrel_offset */ | |
1183 | ||
1184 | /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */ | |
1185 | HOWTO (R_PPC_GOT_TPREL16_HI, | |
1186 | 16, /* rightshift */ | |
1187 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1188 | 16, /* bitsize */ | |
1189 | FALSE, /* pc_relative */ | |
1190 | 0, /* bitpos */ | |
1191 | complain_overflow_dont, /* complain_on_overflow */ | |
1192 | ppc_elf_unhandled_reloc, /* special_function */ | |
1193 | "R_PPC_GOT_TPREL16_HI", /* name */ | |
1194 | FALSE, /* partial_inplace */ | |
1195 | 0, /* src_mask */ | |
1196 | 0xffff, /* dst_mask */ | |
1197 | FALSE), /* pcrel_offset */ | |
1198 | ||
1199 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ | |
1200 | HOWTO (R_PPC_GOT_TPREL16_HA, | |
1201 | 16, /* rightshift */ | |
1202 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1203 | 16, /* bitsize */ | |
1204 | FALSE, /* pc_relative */ | |
1205 | 0, /* bitpos */ | |
1206 | complain_overflow_dont, /* complain_on_overflow */ | |
1207 | ppc_elf_unhandled_reloc, /* special_function */ | |
1208 | "R_PPC_GOT_TPREL16_HA", /* name */ | |
1209 | FALSE, /* partial_inplace */ | |
1210 | 0, /* src_mask */ | |
1211 | 0xffff, /* dst_mask */ | |
1212 | FALSE), /* pcrel_offset */ | |
1213 | ||
1214 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
1215 | in the SVR4 ELF ABI. */ | |
1216 | ||
1217 | /* 32 bit value resulting from the addend minus the symbol. */ | |
1218 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
1219 | 0, /* rightshift */ | |
1220 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1221 | 32, /* bitsize */ | |
1222 | FALSE, /* pc_relative */ | |
1223 | 0, /* bitpos */ | |
1224 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1225 | bfd_elf_generic_reloc, /* special_function */ | |
1226 | "R_PPC_EMB_NADDR32", /* name */ | |
1227 | FALSE, /* partial_inplace */ | |
1228 | 0, /* src_mask */ | |
1229 | 0xffffffff, /* dst_mask */ | |
1230 | FALSE), /* pcrel_offset */ | |
1231 | ||
1232 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1233 | HOWTO (R_PPC_EMB_NADDR16, /* type */ | |
1234 | 0, /* rightshift */ | |
1235 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1236 | 16, /* bitsize */ | |
1237 | FALSE, /* pc_relative */ | |
1238 | 0, /* bitpos */ | |
1239 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1240 | bfd_elf_generic_reloc, /* special_function */ | |
1241 | "R_PPC_EMB_NADDR16", /* name */ | |
1242 | FALSE, /* partial_inplace */ | |
1243 | 0, /* src_mask */ | |
1244 | 0xffff, /* dst_mask */ | |
1245 | FALSE), /* pcrel_offset */ | |
1246 | ||
1247 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1248 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
1249 | 0, /* rightshift */ | |
1250 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1251 | 16, /* bitsize */ | |
1252 | FALSE, /* pc_relative */ | |
1253 | 0, /* bitpos */ | |
1254 | complain_overflow_dont,/* complain_on_overflow */ | |
1255 | bfd_elf_generic_reloc, /* special_function */ | |
1256 | "R_PPC_EMB_ADDR16_LO", /* name */ | |
1257 | FALSE, /* partial_inplace */ | |
1258 | 0, /* src_mask */ | |
1259 | 0xffff, /* dst_mask */ | |
1260 | FALSE), /* pcrel_offset */ | |
1261 | ||
1262 | /* The high order 16 bits of the addend minus the symbol. */ | |
1263 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
1264 | 16, /* rightshift */ | |
1265 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1266 | 16, /* bitsize */ | |
1267 | FALSE, /* pc_relative */ | |
1268 | 0, /* bitpos */ | |
1269 | complain_overflow_dont, /* complain_on_overflow */ | |
1270 | bfd_elf_generic_reloc, /* special_function */ | |
1271 | "R_PPC_EMB_NADDR16_HI", /* name */ | |
1272 | FALSE, /* partial_inplace */ | |
1273 | 0, /* src_mask */ | |
1274 | 0xffff, /* dst_mask */ | |
1275 | FALSE), /* pcrel_offset */ | |
1276 | ||
1277 | /* The high order 16 bits of the result of the addend minus the address, | |
1278 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
1279 | is negative. */ | |
1280 | HOWTO (R_PPC_EMB_NADDR16_HA, /* 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 */ | |
25dbc73a AM |
1287 | ppc_elf_addr16_ha_reloc, /* special_function */ |
1288 | "R_PPC_EMB_NADDR16_HA", /* name */ | |
1289 | FALSE, /* partial_inplace */ | |
1290 | 0, /* src_mask */ | |
1291 | 0xffff, /* dst_mask */ | |
1292 | FALSE), /* pcrel_offset */ | |
1293 | ||
1294 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1295 | address in the .sdata section, and returning the offset from | |
1296 | _SDA_BASE_ for that relocation. */ | |
1297 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
1298 | 0, /* rightshift */ | |
1299 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1300 | 16, /* bitsize */ | |
1301 | FALSE, /* pc_relative */ | |
1302 | 0, /* bitpos */ | |
1303 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1304 | bfd_elf_generic_reloc, /* special_function */ | |
1305 | "R_PPC_EMB_SDAI16", /* 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 .sdata2 section, and returning the offset from | |
1313 | _SDA2_BASE_ for that relocation. */ | |
1314 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
1315 | 0, /* rightshift */ | |
1316 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1317 | 16, /* bitsize */ | |
1318 | FALSE, /* pc_relative */ | |
1319 | 0, /* bitpos */ | |
1320 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1321 | bfd_elf_generic_reloc, /* special_function */ | |
1322 | "R_PPC_EMB_SDA2I16", /* name */ | |
1323 | FALSE, /* partial_inplace */ | |
1324 | 0, /* src_mask */ | |
1325 | 0xffff, /* dst_mask */ | |
1326 | FALSE), /* pcrel_offset */ | |
1327 | ||
1328 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
1329 | small data items. */ | |
1330 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
1331 | 0, /* rightshift */ | |
1332 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1333 | 16, /* bitsize */ | |
1334 | FALSE, /* pc_relative */ | |
1335 | 0, /* bitpos */ | |
1336 | complain_overflow_signed, /* complain_on_overflow */ | |
1337 | bfd_elf_generic_reloc, /* special_function */ | |
1338 | "R_PPC_EMB_SDA2REL", /* name */ | |
1339 | FALSE, /* partial_inplace */ | |
1340 | 0, /* src_mask */ | |
1341 | 0xffff, /* dst_mask */ | |
1342 | FALSE), /* pcrel_offset */ | |
1343 | ||
1344 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
1345 | signed offset from the appropriate base, and filling in the register | |
1346 | field with the appropriate register (0, 2, or 13). */ | |
1347 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
1348 | 0, /* rightshift */ | |
1349 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1350 | 16, /* bitsize */ | |
1351 | FALSE, /* pc_relative */ | |
1352 | 0, /* bitpos */ | |
1353 | complain_overflow_signed, /* complain_on_overflow */ | |
1354 | bfd_elf_generic_reloc, /* special_function */ | |
1355 | "R_PPC_EMB_SDA21", /* name */ | |
1356 | FALSE, /* partial_inplace */ | |
1357 | 0, /* src_mask */ | |
1358 | 0xffff, /* dst_mask */ | |
1359 | FALSE), /* pcrel_offset */ | |
1360 | ||
1361 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
1362 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
1363 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
1364 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
1365 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
1366 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
1367 | ||
1368 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
1369 | in the 16 bit signed offset from the appropriate base, and filling in the | |
1370 | register field with the appropriate register (0, 2, or 13). */ | |
1371 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
1372 | 0, /* rightshift */ | |
1373 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1374 | 16, /* bitsize */ | |
1375 | TRUE, /* pc_relative */ | |
1376 | 0, /* bitpos */ | |
1377 | complain_overflow_signed, /* complain_on_overflow */ | |
1378 | bfd_elf_generic_reloc, /* special_function */ | |
1379 | "R_PPC_EMB_RELSDA", /* name */ | |
1380 | FALSE, /* partial_inplace */ | |
1381 | 0, /* src_mask */ | |
1382 | 0xffff, /* dst_mask */ | |
1383 | FALSE), /* pcrel_offset */ | |
1384 | ||
e054468f AM |
1385 | HOWTO (R_PPC_IRELATIVE, /* type */ |
1386 | 0, /* rightshift */ | |
1387 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1388 | 32, /* bitsize */ | |
1389 | FALSE, /* pc_relative */ | |
1390 | 0, /* bitpos */ | |
1391 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1392 | bfd_elf_generic_reloc, /* special_function */ | |
1393 | "R_PPC_IRELATIVE", /* name */ | |
1394 | FALSE, /* partial_inplace */ | |
1395 | 0, /* src_mask */ | |
1396 | 0xffffffff, /* dst_mask */ | |
1397 | FALSE), /* pcrel_offset */ | |
1398 | ||
d7128ce4 AM |
1399 | /* A 16 bit relative relocation. */ |
1400 | HOWTO (R_PPC_REL16, /* type */ | |
1401 | 0, /* rightshift */ | |
1402 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1403 | 16, /* bitsize */ | |
1404 | TRUE, /* pc_relative */ | |
1405 | 0, /* bitpos */ | |
1406 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1407 | bfd_elf_generic_reloc, /* special_function */ | |
1408 | "R_PPC_REL16", /* name */ | |
1409 | FALSE, /* partial_inplace */ | |
1410 | 0, /* src_mask */ | |
1411 | 0xffff, /* dst_mask */ | |
1412 | TRUE), /* pcrel_offset */ | |
1413 | ||
1414 | /* A 16 bit relative relocation without overflow. */ | |
1415 | HOWTO (R_PPC_REL16_LO, /* type */ | |
1416 | 0, /* rightshift */ | |
1417 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1418 | 16, /* bitsize */ | |
1419 | TRUE, /* pc_relative */ | |
1420 | 0, /* bitpos */ | |
1421 | complain_overflow_dont,/* complain_on_overflow */ | |
1422 | bfd_elf_generic_reloc, /* special_function */ | |
1423 | "R_PPC_REL16_LO", /* name */ | |
1424 | FALSE, /* partial_inplace */ | |
1425 | 0, /* src_mask */ | |
1426 | 0xffff, /* dst_mask */ | |
1427 | TRUE), /* pcrel_offset */ | |
1428 | ||
1429 | /* The high order 16 bits of a relative address. */ | |
1430 | HOWTO (R_PPC_REL16_HI, /* type */ | |
1431 | 16, /* rightshift */ | |
1432 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1433 | 16, /* bitsize */ | |
1434 | TRUE, /* pc_relative */ | |
1435 | 0, /* bitpos */ | |
1436 | complain_overflow_dont, /* complain_on_overflow */ | |
1437 | bfd_elf_generic_reloc, /* special_function */ | |
1438 | "R_PPC_REL16_HI", /* name */ | |
1439 | FALSE, /* partial_inplace */ | |
1440 | 0, /* src_mask */ | |
1441 | 0xffff, /* dst_mask */ | |
1442 | TRUE), /* pcrel_offset */ | |
1443 | ||
1444 | /* The high order 16 bits of a relative address, plus 1 if the contents of | |
1445 | the low 16 bits, treated as a signed number, is negative. */ | |
1446 | HOWTO (R_PPC_REL16_HA, /* type */ | |
1447 | 16, /* rightshift */ | |
1448 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1449 | 16, /* bitsize */ | |
1450 | TRUE, /* pc_relative */ | |
1451 | 0, /* bitpos */ | |
1452 | complain_overflow_dont, /* complain_on_overflow */ | |
1453 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1454 | "R_PPC_REL16_HA", /* name */ | |
1455 | FALSE, /* partial_inplace */ | |
1456 | 0, /* src_mask */ | |
1457 | 0xffff, /* dst_mask */ | |
1458 | TRUE), /* pcrel_offset */ | |
1459 | ||
25dbc73a AM |
1460 | /* GNU extension to record C++ vtable hierarchy. */ |
1461 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ | |
1462 | 0, /* rightshift */ | |
1463 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1464 | 0, /* bitsize */ | |
1465 | FALSE, /* pc_relative */ | |
1466 | 0, /* bitpos */ | |
1467 | complain_overflow_dont, /* complain_on_overflow */ | |
1468 | NULL, /* special_function */ | |
1469 | "R_PPC_GNU_VTINHERIT", /* name */ | |
1470 | FALSE, /* partial_inplace */ | |
1471 | 0, /* src_mask */ | |
1472 | 0, /* dst_mask */ | |
1473 | FALSE), /* pcrel_offset */ | |
1474 | ||
1475 | /* GNU extension to record C++ vtable member usage. */ | |
1476 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ | |
1477 | 0, /* rightshift */ | |
1478 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1479 | 0, /* bitsize */ | |
1480 | FALSE, /* pc_relative */ | |
1481 | 0, /* bitpos */ | |
1482 | complain_overflow_dont, /* complain_on_overflow */ | |
1483 | NULL, /* special_function */ | |
1484 | "R_PPC_GNU_VTENTRY", /* name */ | |
7619e7c7 AM |
1485 | FALSE, /* partial_inplace */ |
1486 | 0, /* src_mask */ | |
25dbc73a | 1487 | 0, /* dst_mask */ |
7619e7c7 AM |
1488 | FALSE), /* pcrel_offset */ |
1489 | ||
25dbc73a AM |
1490 | /* Phony reloc to handle AIX style TOC entries. */ |
1491 | HOWTO (R_PPC_TOC16, /* type */ | |
7619e7c7 AM |
1492 | 0, /* rightshift */ |
1493 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1494 | 16, /* bitsize */ | |
1495 | FALSE, /* pc_relative */ | |
1496 | 0, /* bitpos */ | |
25dbc73a | 1497 | complain_overflow_signed, /* complain_on_overflow */ |
7619e7c7 | 1498 | bfd_elf_generic_reloc, /* special_function */ |
25dbc73a | 1499 | "R_PPC_TOC16", /* name */ |
7619e7c7 AM |
1500 | FALSE, /* partial_inplace */ |
1501 | 0, /* src_mask */ | |
1502 | 0xffff, /* dst_mask */ | |
1503 | FALSE), /* pcrel_offset */ | |
25dbc73a AM |
1504 | }; |
1505 | \f | |
1506 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
1507 | ||
1508 | static void | |
1509 | ppc_elf_howto_init (void) | |
1510 | { | |
1511 | unsigned int i, type; | |
1512 | ||
1513 | for (i = 0; | |
1514 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1515 | i++) | |
1516 | { | |
1517 | type = ppc_elf_howto_raw[i].type; | |
1518 | if (type >= (sizeof (ppc_elf_howto_table) | |
1519 | / sizeof (ppc_elf_howto_table[0]))) | |
1520 | abort (); | |
1521 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; | |
1522 | } | |
1523 | } | |
1524 | ||
1525 | static reloc_howto_type * | |
1526 | ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1527 | bfd_reloc_code_real_type code) | |
1528 | { | |
1529 | enum elf_ppc_reloc_type r; | |
1530 | ||
1531 | /* Initialize howto table if not already done. */ | |
1532 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1533 | ppc_elf_howto_init (); | |
1534 | ||
1535 | switch (code) | |
1536 | { | |
1537 | default: | |
1538 | return NULL; | |
1539 | ||
1540 | case BFD_RELOC_NONE: r = R_PPC_NONE; break; | |
1541 | case BFD_RELOC_32: r = R_PPC_ADDR32; break; | |
1542 | case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break; | |
1543 | case BFD_RELOC_16: r = R_PPC_ADDR16; break; | |
1544 | case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break; | |
1545 | case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break; | |
1546 | case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break; | |
1547 | case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break; | |
1548 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break; | |
1549 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break; | |
1550 | case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break; | |
1551 | case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break; | |
1552 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break; | |
1553 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break; | |
1554 | case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break; | |
1555 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break; | |
1556 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break; | |
1557 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break; | |
1558 | case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break; | |
1559 | case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break; | |
1560 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break; | |
1561 | case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break; | |
1562 | case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break; | |
1563 | case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break; | |
1564 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break; | |
1565 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break; | |
1566 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break; | |
1567 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break; | |
1568 | case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break; | |
1569 | case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break; | |
1570 | case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break; | |
1571 | case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break; | |
1572 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break; | |
1573 | case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break; | |
1574 | case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break; | |
1575 | case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break; | |
727fc41e AM |
1576 | case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break; |
1577 | case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break; | |
25dbc73a AM |
1578 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break; |
1579 | case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break; | |
1580 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break; | |
1581 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break; | |
1582 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break; | |
1583 | case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break; | |
1584 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break; | |
1585 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break; | |
1586 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break; | |
1587 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break; | |
1588 | case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break; | |
1589 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break; | |
1590 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break; | |
1591 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break; | |
1592 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break; | |
1593 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break; | |
1594 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break; | |
1595 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break; | |
1596 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break; | |
1597 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break; | |
1598 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break; | |
1599 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break; | |
1600 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break; | |
1601 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break; | |
1602 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break; | |
1603 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break; | |
1604 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break; | |
1605 | case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break; | |
1606 | case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break; | |
1607 | case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break; | |
1608 | case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break; | |
1609 | case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break; | |
1610 | case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break; | |
1611 | case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break; | |
1612 | case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break; | |
1613 | case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break; | |
1614 | case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break; | |
1615 | case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break; | |
1616 | case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break; | |
1617 | case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break; | |
1618 | case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break; | |
1619 | case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break; | |
1620 | case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break; | |
d7128ce4 AM |
1621 | case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break; |
1622 | case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break; | |
1623 | case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break; | |
1624 | case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break; | |
25dbc73a AM |
1625 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break; |
1626 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break; | |
1627 | } | |
1628 | ||
1629 | return ppc_elf_howto_table[r]; | |
1630 | }; | |
1631 | ||
157090f7 AM |
1632 | static reloc_howto_type * |
1633 | ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1634 | const char *r_name) | |
1635 | { | |
1636 | unsigned int i; | |
1637 | ||
1638 | for (i = 0; | |
1639 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1640 | i++) | |
1641 | if (ppc_elf_howto_raw[i].name != NULL | |
1642 | && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0) | |
1643 | return &ppc_elf_howto_raw[i]; | |
1644 | ||
1645 | return NULL; | |
1646 | } | |
1647 | ||
25dbc73a AM |
1648 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
1649 | ||
1650 | static void | |
1651 | ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, | |
1652 | arelent *cache_ptr, | |
1653 | Elf_Internal_Rela *dst) | |
1654 | { | |
1655 | /* Initialize howto table if not already done. */ | |
1656 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1657 | ppc_elf_howto_init (); | |
1658 | ||
1659 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); | |
1660 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; | |
375de94a AM |
1661 | |
1662 | /* Just because the above assert didn't trigger doesn't mean that | |
1663 | ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */ | |
1664 | if (!cache_ptr->howto) | |
1665 | { | |
1666 | (*_bfd_error_handler) (_("%B: invalid relocation type %d"), | |
1667 | abfd, ELF32_R_TYPE (dst->r_info)); | |
1668 | bfd_set_error (bfd_error_bad_value); | |
1669 | ||
1670 | cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE]; | |
1671 | } | |
25dbc73a AM |
1672 | } |
1673 | ||
d7128ce4 | 1674 | /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */ |
25dbc73a AM |
1675 | |
1676 | static bfd_reloc_status_type | |
1677 | ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED, | |
1678 | arelent *reloc_entry, | |
1679 | asymbol *symbol, | |
1680 | void *data ATTRIBUTE_UNUSED, | |
1681 | asection *input_section, | |
1682 | bfd *output_bfd, | |
1683 | char **error_message ATTRIBUTE_UNUSED) | |
1684 | { | |
1685 | bfd_vma relocation; | |
1686 | ||
1687 | if (output_bfd != NULL) | |
1688 | { | |
1689 | reloc_entry->address += input_section->output_offset; | |
1690 | return bfd_reloc_ok; | |
1691 | } | |
1692 | ||
1693 | if (reloc_entry->address > bfd_get_section_limit (abfd, input_section)) | |
1694 | return bfd_reloc_outofrange; | |
1695 | ||
1696 | if (bfd_is_com_section (symbol->section)) | |
1697 | relocation = 0; | |
1698 | else | |
1699 | relocation = symbol->value; | |
1700 | ||
1701 | relocation += symbol->section->output_section->vma; | |
1702 | relocation += symbol->section->output_offset; | |
1703 | relocation += reloc_entry->addend; | |
d7128ce4 AM |
1704 | if (reloc_entry->howto->pc_relative) |
1705 | relocation -= reloc_entry->address; | |
25dbc73a AM |
1706 | |
1707 | reloc_entry->addend += (relocation & 0x8000) << 1; | |
1708 | ||
1709 | return bfd_reloc_continue; | |
1710 | } | |
1711 | ||
1712 | static bfd_reloc_status_type | |
1713 | ppc_elf_unhandled_reloc (bfd *abfd, | |
1714 | arelent *reloc_entry, | |
1715 | asymbol *symbol, | |
1716 | void *data, | |
1717 | asection *input_section, | |
1718 | bfd *output_bfd, | |
1719 | char **error_message) | |
1720 | { | |
1721 | /* If this is a relocatable link (output_bfd test tells us), just | |
1722 | call the generic function. Any adjustment will be done at final | |
1723 | link time. */ | |
1724 | if (output_bfd != NULL) | |
1725 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
1726 | input_section, output_bfd, error_message); | |
1727 | ||
1728 | if (error_message != NULL) | |
1729 | { | |
1730 | static char buf[60]; | |
1731 | sprintf (buf, _("generic linker can't handle %s"), | |
1732 | reloc_entry->howto->name); | |
1733 | *error_message = buf; | |
1734 | } | |
1735 | return bfd_reloc_dangerous; | |
1736 | } | |
1737 | \f | |
1738 | /* Sections created by the linker. */ | |
1739 | ||
1740 | typedef struct elf_linker_section | |
1741 | { | |
c9a2f333 | 1742 | /* Pointer to the bfd section. */ |
25dbc73a | 1743 | asection *section; |
c9a2f333 AM |
1744 | /* Section name. */ |
1745 | const char *name; | |
1746 | /* Associated bss section name. */ | |
1747 | const char *bss_name; | |
1748 | /* Associated symbol name. */ | |
1749 | const char *sym_name; | |
046183de AM |
1750 | /* Associated symbol. */ |
1751 | struct elf_link_hash_entry *sym; | |
25dbc73a AM |
1752 | } elf_linker_section_t; |
1753 | ||
1754 | /* Linked list of allocated pointer entries. This hangs off of the | |
1755 | symbol lists, and provides allows us to return different pointers, | |
1756 | based on different addend's. */ | |
1757 | ||
1758 | typedef struct elf_linker_section_pointers | |
1759 | { | |
1760 | /* next allocated pointer for this symbol */ | |
1761 | struct elf_linker_section_pointers *next; | |
1762 | /* offset of pointer from beginning of section */ | |
1763 | bfd_vma offset; | |
1764 | /* addend used */ | |
1765 | bfd_vma addend; | |
1766 | /* which linker section this is */ | |
1767 | elf_linker_section_t *lsect; | |
25dbc73a AM |
1768 | } elf_linker_section_pointers_t; |
1769 | ||
1770 | struct ppc_elf_obj_tdata | |
1771 | { | |
1772 | struct elf_obj_tdata elf; | |
1773 | ||
1774 | /* A mapping from local symbols to offsets into the various linker | |
1775 | sections added. This is index by the symbol index. */ | |
1776 | elf_linker_section_pointers_t **linker_section_pointers; | |
016687f8 AM |
1777 | |
1778 | /* Flags used to auto-detect plt type. */ | |
1779 | unsigned int makes_plt_call : 1; | |
1780 | unsigned int has_rel16 : 1; | |
25dbc73a AM |
1781 | }; |
1782 | ||
1783 | #define ppc_elf_tdata(bfd) \ | |
1784 | ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any) | |
7619e7c7 | 1785 | |
25dbc73a AM |
1786 | #define elf_local_ptr_offsets(bfd) \ |
1787 | (ppc_elf_tdata (bfd)->linker_section_pointers) | |
7619e7c7 | 1788 | |
0c8d6e5c AM |
1789 | #define is_ppc_elf(bfd) \ |
1790 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
1791 | && elf_object_id (bfd) == PPC32_ELF_TDATA) | |
1792 | ||
25dbc73a | 1793 | /* Override the generic function because we store some extras. */ |
7619e7c7 | 1794 | |
25dbc73a AM |
1795 | static bfd_boolean |
1796 | ppc_elf_mkobject (bfd *abfd) | |
1797 | { | |
0ffa91dd NC |
1798 | return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata), |
1799 | PPC32_ELF_TDATA); | |
25dbc73a | 1800 | } |
7619e7c7 | 1801 | |
25dbc73a AM |
1802 | /* Fix bad default arch selected for a 32 bit input bfd when the |
1803 | default is 64 bit. */ | |
7619e7c7 | 1804 | |
25dbc73a AM |
1805 | static bfd_boolean |
1806 | ppc_elf_object_p (bfd *abfd) | |
1807 | { | |
1808 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64) | |
1809 | { | |
1810 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
7619e7c7 | 1811 | |
25dbc73a AM |
1812 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) |
1813 | { | |
1814 | /* Relies on arch after 64 bit default being 32 bit default. */ | |
1815 | abfd->arch_info = abfd->arch_info->next; | |
1816 | BFD_ASSERT (abfd->arch_info->bits_per_word == 32); | |
1817 | } | |
1818 | } | |
1819 | return TRUE; | |
1820 | } | |
7619e7c7 | 1821 | |
25dbc73a | 1822 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
7619e7c7 | 1823 | |
25dbc73a AM |
1824 | static bfd_boolean |
1825 | ppc_elf_set_private_flags (bfd *abfd, flagword flags) | |
1826 | { | |
1827 | BFD_ASSERT (!elf_flags_init (abfd) | |
1828 | || elf_elfheader (abfd)->e_flags == flags); | |
7619e7c7 | 1829 | |
25dbc73a AM |
1830 | elf_elfheader (abfd)->e_flags = flags; |
1831 | elf_flags_init (abfd) = TRUE; | |
1832 | return TRUE; | |
1833 | } | |
1834 | ||
25dbc73a | 1835 | /* Support for core dump NOTE sections. */ |
deaaf2f3 | 1836 | |
b34976b6 | 1837 | static bfd_boolean |
25dbc73a | 1838 | ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
252b5132 | 1839 | { |
25dbc73a AM |
1840 | int offset; |
1841 | unsigned int size; | |
252b5132 | 1842 | |
25dbc73a AM |
1843 | switch (note->descsz) |
1844 | { | |
1845 | default: | |
1846 | return FALSE; | |
252b5132 | 1847 | |
25dbc73a AM |
1848 | case 268: /* Linux/PPC. */ |
1849 | /* pr_cursig */ | |
1850 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
deaaf2f3 | 1851 | |
25dbc73a AM |
1852 | /* pr_pid */ |
1853 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
9abc968f | 1854 | |
25dbc73a AM |
1855 | /* pr_reg */ |
1856 | offset = 72; | |
1857 | size = 192; | |
deaaf2f3 | 1858 | |
25dbc73a AM |
1859 | break; |
1860 | } | |
deaaf2f3 | 1861 | |
25dbc73a AM |
1862 | /* Make a ".reg/999" section. */ |
1863 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1864 | size, note->descpos + offset); | |
1865 | } | |
252b5132 | 1866 | |
25dbc73a AM |
1867 | static bfd_boolean |
1868 | ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
1869 | { | |
1870 | switch (note->descsz) | |
deaaf2f3 | 1871 | { |
25dbc73a AM |
1872 | default: |
1873 | return FALSE; | |
deaaf2f3 | 1874 | |
25dbc73a AM |
1875 | case 128: /* Linux/PPC elf_prpsinfo. */ |
1876 | elf_tdata (abfd)->core_program | |
1877 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); | |
1878 | elf_tdata (abfd)->core_command | |
1879 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); | |
1880 | } | |
9abc968f | 1881 | |
25dbc73a AM |
1882 | /* Note that for some reason, a spurious space is tacked |
1883 | onto the end of the args in some (at least one anyway) | |
1884 | implementations, so strip it off if it exists. */ | |
70bccea4 | 1885 | |
25dbc73a AM |
1886 | { |
1887 | char *command = elf_tdata (abfd)->core_command; | |
1888 | int n = strlen (command); | |
70bccea4 | 1889 | |
25dbc73a AM |
1890 | if (0 < n && command[n - 1] == ' ') |
1891 | command[n - 1] = '\0'; | |
1892 | } | |
deaaf2f3 | 1893 | |
25dbc73a AM |
1894 | return TRUE; |
1895 | } | |
deaaf2f3 | 1896 | |
183e98be AM |
1897 | static char * |
1898 | ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...) | |
1899 | { | |
1900 | switch (note_type) | |
1901 | { | |
1902 | default: | |
1903 | return NULL; | |
1904 | ||
1905 | case NT_PRPSINFO: | |
1906 | { | |
1907 | char data[128]; | |
1908 | va_list ap; | |
1909 | ||
1910 | va_start (ap, note_type); | |
1911 | memset (data, 0, 32); | |
1912 | strncpy (data + 32, va_arg (ap, const char *), 16); | |
1913 | strncpy (data + 48, va_arg (ap, const char *), 80); | |
1914 | va_end (ap); | |
1915 | return elfcore_write_note (abfd, buf, bufsiz, | |
1916 | "CORE", note_type, data, sizeof (data)); | |
1917 | } | |
1918 | ||
1919 | case NT_PRSTATUS: | |
1920 | { | |
1921 | char data[268]; | |
1922 | va_list ap; | |
1923 | long pid; | |
1924 | int cursig; | |
1925 | const void *greg; | |
1926 | ||
1927 | va_start (ap, note_type); | |
1928 | memset (data, 0, 72); | |
1929 | pid = va_arg (ap, long); | |
1930 | bfd_put_32 (abfd, pid, data + 24); | |
1931 | cursig = va_arg (ap, int); | |
1932 | bfd_put_16 (abfd, cursig, data + 12); | |
1933 | greg = va_arg (ap, const void *); | |
1934 | memcpy (data + 72, greg, 192); | |
1935 | memset (data + 264, 0, 4); | |
1936 | va_end (ap); | |
1937 | return elfcore_write_note (abfd, buf, bufsiz, | |
1938 | "CORE", note_type, data, sizeof (data)); | |
1939 | } | |
1940 | } | |
1941 | } | |
1942 | ||
25dbc73a AM |
1943 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
1944 | or (bfd_vma) -1 if it should not be included. */ | |
deaaf2f3 | 1945 | |
25dbc73a AM |
1946 | static bfd_vma |
1947 | ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, | |
1948 | const asection *plt ATTRIBUTE_UNUSED, | |
1949 | const arelent *rel) | |
1950 | { | |
1951 | return rel->address; | |
1952 | } | |
deaaf2f3 | 1953 | |
25dbc73a | 1954 | /* Handle a PowerPC specific section when reading an object file. This |
6dc132d9 L |
1955 | is called when bfd_section_from_shdr finds a section with an unknown |
1956 | type. */ | |
deaaf2f3 | 1957 | |
25dbc73a | 1958 | static bfd_boolean |
6dc132d9 L |
1959 | ppc_elf_section_from_shdr (bfd *abfd, |
1960 | Elf_Internal_Shdr *hdr, | |
1961 | const char *name, | |
1962 | int shindex) | |
25dbc73a AM |
1963 | { |
1964 | asection *newsect; | |
1965 | flagword flags; | |
d1c6de6f | 1966 | |
6dc132d9 | 1967 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
25dbc73a | 1968 | return FALSE; |
deaaf2f3 | 1969 | |
25dbc73a AM |
1970 | newsect = hdr->bfd_section; |
1971 | flags = bfd_get_section_flags (abfd, newsect); | |
1972 | if (hdr->sh_flags & SHF_EXCLUDE) | |
1973 | flags |= SEC_EXCLUDE; | |
9abc968f | 1974 | |
25dbc73a AM |
1975 | if (hdr->sh_type == SHT_ORDERED) |
1976 | flags |= SEC_SORT_ENTRIES; | |
d1c6de6f | 1977 | |
25dbc73a AM |
1978 | bfd_set_section_flags (abfd, newsect, flags); |
1979 | return TRUE; | |
1980 | } | |
1981 | ||
1982 | /* Set up any other section flags and such that may be necessary. */ | |
1983 | ||
1984 | static bfd_boolean | |
1985 | ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, | |
1986 | Elf_Internal_Shdr *shdr, | |
1987 | asection *asect) | |
1988 | { | |
d30e8e7c | 1989 | if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE) |
25dbc73a AM |
1990 | shdr->sh_flags |= SHF_EXCLUDE; |
1991 | ||
1992 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) | |
1993 | shdr->sh_type = SHT_ORDERED; | |
1994 | ||
1995 | return TRUE; | |
1996 | } | |
1997 | ||
1998 | /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we | |
1999 | need to bump up the number of section headers. */ | |
2000 | ||
2001 | static int | |
a6b96beb AM |
2002 | ppc_elf_additional_program_headers (bfd *abfd, |
2003 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
25dbc73a AM |
2004 | { |
2005 | asection *s; | |
2006 | int ret = 0; | |
d1c6de6f | 2007 | |
25dbc73a AM |
2008 | s = bfd_get_section_by_name (abfd, ".sbss2"); |
2009 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2010 | ++ret; | |
d1c6de6f | 2011 | |
25dbc73a AM |
2012 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); |
2013 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2014 | ++ret; | |
deaaf2f3 | 2015 | |
25dbc73a AM |
2016 | return ret; |
2017 | } | |
deaaf2f3 | 2018 | |
25dbc73a AM |
2019 | /* Add extra PPC sections -- Note, for now, make .sbss2 and |
2020 | .PPC.EMB.sbss0 a normal section, and not a bss section so | |
2021 | that the linker doesn't crater when trying to make more than | |
2022 | 2 sections. */ | |
e656e369 | 2023 | |
b35d266b | 2024 | static const struct bfd_elf_special_section ppc_elf_special_sections[] = |
7f4d3958 | 2025 | { |
0112cd26 NC |
2026 | { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR }, |
2027 | { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2028 | { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2029 | { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2030 | { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2031 | { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC }, | |
2032 | { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 }, | |
2033 | { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2034 | { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2035 | { NULL, 0, 0, 0, 0 } | |
7f4d3958 L |
2036 | }; |
2037 | ||
551b43fd AM |
2038 | /* This is what we want for new plt/got. */ |
2039 | static struct bfd_elf_special_section ppc_alt_plt = | |
0112cd26 | 2040 | { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC }; |
551b43fd AM |
2041 | |
2042 | static const struct bfd_elf_special_section * | |
2043 | ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) | |
7f4d3958 | 2044 | { |
b35d266b | 2045 | const struct bfd_elf_special_section *ssect; |
551b43fd AM |
2046 | |
2047 | /* See if this is one of the special sections. */ | |
2048 | if (sec->name == NULL) | |
2049 | return NULL; | |
2050 | ||
2051 | ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections, | |
2052 | sec->use_rela_p); | |
2053 | if (ssect != NULL) | |
2054 | { | |
2055 | if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0) | |
2056 | ssect = &ppc_alt_plt; | |
2057 | return ssect; | |
2058 | } | |
2059 | ||
2060 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
2061 | } | |
25dbc73a AM |
2062 | \f |
2063 | /* Very simple linked list structure for recording apuinfo values. */ | |
2064 | typedef struct apuinfo_list | |
2065 | { | |
2066 | struct apuinfo_list *next; | |
2067 | unsigned long value; | |
2068 | } | |
2069 | apuinfo_list; | |
e656e369 | 2070 | |
25dbc73a | 2071 | static apuinfo_list *head; |
deaaf2f3 | 2072 | |
deaaf2f3 | 2073 | |
25dbc73a AM |
2074 | static void |
2075 | apuinfo_list_init (void) | |
2076 | { | |
2077 | head = NULL; | |
2078 | } | |
9abc968f | 2079 | |
25dbc73a AM |
2080 | static void |
2081 | apuinfo_list_add (unsigned long value) | |
2082 | { | |
2083 | apuinfo_list *entry = head; | |
deaaf2f3 | 2084 | |
25dbc73a AM |
2085 | while (entry != NULL) |
2086 | { | |
2087 | if (entry->value == value) | |
2088 | return; | |
2089 | entry = entry->next; | |
2090 | } | |
b4a38de6 | 2091 | |
25dbc73a AM |
2092 | entry = bfd_malloc (sizeof (* entry)); |
2093 | if (entry == NULL) | |
2094 | return; | |
e656e369 | 2095 | |
25dbc73a AM |
2096 | entry->value = value; |
2097 | entry->next = head; | |
2098 | head = entry; | |
2099 | } | |
9abc968f | 2100 | |
25dbc73a AM |
2101 | static unsigned |
2102 | apuinfo_list_length (void) | |
2103 | { | |
2104 | apuinfo_list *entry; | |
2105 | unsigned long count; | |
9abc968f | 2106 | |
25dbc73a AM |
2107 | for (entry = head, count = 0; |
2108 | entry; | |
2109 | entry = entry->next) | |
2110 | ++ count; | |
e656e369 | 2111 | |
25dbc73a AM |
2112 | return count; |
2113 | } | |
eea6121a | 2114 | |
25dbc73a AM |
2115 | static inline unsigned long |
2116 | apuinfo_list_element (unsigned long number) | |
2117 | { | |
2118 | apuinfo_list * entry; | |
e656e369 | 2119 | |
25dbc73a AM |
2120 | for (entry = head; |
2121 | entry && number --; | |
2122 | entry = entry->next) | |
2123 | ; | |
252b5132 | 2124 | |
25dbc73a AM |
2125 | return entry ? entry->value : 0; |
2126 | } | |
2127 | ||
2128 | static void | |
2129 | apuinfo_list_finish (void) | |
2130 | { | |
2131 | apuinfo_list *entry; | |
2132 | ||
2133 | for (entry = head; entry;) | |
252b5132 | 2134 | { |
25dbc73a AM |
2135 | apuinfo_list *next = entry->next; |
2136 | free (entry); | |
2137 | entry = next; | |
2138 | } | |
9abc968f | 2139 | |
25dbc73a AM |
2140 | head = NULL; |
2141 | } | |
9abc968f | 2142 | |
25dbc73a AM |
2143 | #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo" |
2144 | #define APUINFO_LABEL "APUinfo" | |
9abc968f | 2145 | |
25dbc73a AM |
2146 | /* Scan the input BFDs and create a linked list of |
2147 | the APUinfo values that will need to be emitted. */ | |
9abc968f | 2148 | |
25dbc73a AM |
2149 | static void |
2150 | ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info) | |
2151 | { | |
2152 | bfd *ibfd; | |
2153 | asection *asec; | |
2154 | char *buffer; | |
2155 | unsigned num_input_sections; | |
2156 | bfd_size_type output_section_size; | |
2157 | unsigned i; | |
2158 | unsigned num_entries; | |
2159 | unsigned long offset; | |
2160 | unsigned long length; | |
2161 | const char *error_message = NULL; | |
9abc968f | 2162 | |
25dbc73a AM |
2163 | if (link_info == NULL) |
2164 | return; | |
9abc968f | 2165 | |
25dbc73a AM |
2166 | /* Scan the input bfds, looking for apuinfo sections. */ |
2167 | num_input_sections = 0; | |
2168 | output_section_size = 0; | |
252b5132 | 2169 | |
25dbc73a | 2170 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) |
252b5132 | 2171 | { |
25dbc73a AM |
2172 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
2173 | if (asec) | |
252b5132 | 2174 | { |
25dbc73a AM |
2175 | ++ num_input_sections; |
2176 | output_section_size += asec->size; | |
252b5132 | 2177 | } |
252b5132 RH |
2178 | } |
2179 | ||
25dbc73a AM |
2180 | /* We need at least one input sections |
2181 | in order to make merging worthwhile. */ | |
2182 | if (num_input_sections < 1) | |
2183 | return; | |
deaaf2f3 | 2184 | |
25dbc73a AM |
2185 | /* Just make sure that the output section exists as well. */ |
2186 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
2187 | if (asec == NULL) | |
2188 | return; | |
252b5132 | 2189 | |
25dbc73a AM |
2190 | /* Allocate a buffer for the contents of the input sections. */ |
2191 | buffer = bfd_malloc (output_section_size); | |
2192 | if (buffer == NULL) | |
2193 | return; | |
252b5132 | 2194 | |
25dbc73a AM |
2195 | offset = 0; |
2196 | apuinfo_list_init (); | |
252b5132 | 2197 | |
25dbc73a AM |
2198 | /* Read in the input sections contents. */ |
2199 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) | |
252b5132 | 2200 | { |
25dbc73a AM |
2201 | unsigned long datum; |
2202 | char *ptr; | |
252b5132 | 2203 | |
25dbc73a AM |
2204 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
2205 | if (asec == NULL) | |
2206 | continue; | |
252b5132 | 2207 | |
25dbc73a AM |
2208 | length = asec->size; |
2209 | if (length < 24) | |
2210 | { | |
2211 | error_message = _("corrupt or empty %s section in %B"); | |
2212 | goto fail; | |
2213 | } | |
252b5132 | 2214 | |
25dbc73a AM |
2215 | if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0 |
2216 | || (bfd_bread (buffer + offset, length, ibfd) != length)) | |
2217 | { | |
2218 | error_message = _("unable to read in %s section from %B"); | |
2219 | goto fail; | |
2220 | } | |
252b5132 | 2221 | |
25dbc73a AM |
2222 | /* Process the contents of the section. */ |
2223 | ptr = buffer + offset; | |
2224 | error_message = _("corrupt %s section in %B"); | |
252b5132 | 2225 | |
25dbc73a AM |
2226 | /* Verify the contents of the header. Note - we have to |
2227 | extract the values this way in order to allow for a | |
2228 | host whose endian-ness is different from the target. */ | |
2229 | datum = bfd_get_32 (ibfd, ptr); | |
2230 | if (datum != sizeof APUINFO_LABEL) | |
2231 | goto fail; | |
252b5132 | 2232 | |
25dbc73a AM |
2233 | datum = bfd_get_32 (ibfd, ptr + 8); |
2234 | if (datum != 0x2) | |
2235 | goto fail; | |
252b5132 | 2236 | |
25dbc73a AM |
2237 | if (strcmp (ptr + 12, APUINFO_LABEL) != 0) |
2238 | goto fail; | |
252b5132 | 2239 | |
25dbc73a AM |
2240 | /* Get the number of bytes used for apuinfo entries. */ |
2241 | datum = bfd_get_32 (ibfd, ptr + 4); | |
2242 | if (datum + 20 != length) | |
2243 | goto fail; | |
2244 | ||
2245 | /* Make sure that we do not run off the end of the section. */ | |
2246 | if (offset + length > output_section_size) | |
2247 | goto fail; | |
2248 | ||
2249 | /* Scan the apuinfo section, building a list of apuinfo numbers. */ | |
2250 | for (i = 0; i < datum; i += 4) | |
2251 | apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i)); | |
2252 | ||
2253 | /* Update the offset. */ | |
2254 | offset += length; | |
252b5132 RH |
2255 | } |
2256 | ||
25dbc73a | 2257 | error_message = NULL; |
252b5132 | 2258 | |
25dbc73a AM |
2259 | /* Compute the size of the output section. */ |
2260 | num_entries = apuinfo_list_length (); | |
2261 | output_section_size = 20 + num_entries * 4; | |
252b5132 | 2262 | |
25dbc73a AM |
2263 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); |
2264 | ||
2265 | if (! bfd_set_section_size (abfd, asec, output_section_size)) | |
2266 | ibfd = abfd, | |
2267 | error_message = _("warning: unable to set size of %s section in %B"); | |
2268 | ||
2269 | fail: | |
2270 | free (buffer); | |
2271 | ||
2272 | if (error_message) | |
2273 | (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME); | |
2274 | } | |
252b5132 | 2275 | |
25dbc73a AM |
2276 | /* Prevent the output section from accumulating the input sections' |
2277 | contents. We have already stored this in our linked list structure. */ | |
252b5132 | 2278 | |
25dbc73a AM |
2279 | static bfd_boolean |
2280 | ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED, | |
c7b8f16e | 2281 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED, |
25dbc73a AM |
2282 | asection *asec, |
2283 | bfd_byte *contents ATTRIBUTE_UNUSED) | |
2284 | { | |
2285 | return (apuinfo_list_length () | |
2286 | && strcmp (asec->name, APUINFO_SECTION_NAME) == 0); | |
252b5132 RH |
2287 | } |
2288 | ||
25dbc73a AM |
2289 | /* Finally we can generate the output section. */ |
2290 | ||
2291 | static void | |
2292 | ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) | |
7619e7c7 | 2293 | { |
25dbc73a AM |
2294 | bfd_byte *buffer; |
2295 | asection *asec; | |
2296 | unsigned i; | |
2297 | unsigned num_entries; | |
2298 | bfd_size_type length; | |
7619e7c7 | 2299 | |
25dbc73a AM |
2300 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); |
2301 | if (asec == NULL) | |
2302 | return; | |
2303 | ||
2304 | if (apuinfo_list_length () == 0) | |
2305 | return; | |
2306 | ||
2307 | length = asec->size; | |
2308 | if (length < 20) | |
2309 | return; | |
2310 | ||
2311 | buffer = bfd_malloc (length); | |
2312 | if (buffer == NULL) | |
7619e7c7 | 2313 | { |
25dbc73a AM |
2314 | (*_bfd_error_handler) |
2315 | (_("failed to allocate space for new APUinfo section.")); | |
2316 | return; | |
7619e7c7 | 2317 | } |
7619e7c7 | 2318 | |
25dbc73a AM |
2319 | /* Create the apuinfo header. */ |
2320 | num_entries = apuinfo_list_length (); | |
2321 | bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer); | |
2322 | bfd_put_32 (abfd, num_entries * 4, buffer + 4); | |
2323 | bfd_put_32 (abfd, 0x2, buffer + 8); | |
2324 | strcpy ((char *) buffer + 12, APUINFO_LABEL); | |
feee612b | 2325 | |
25dbc73a AM |
2326 | length = 20; |
2327 | for (i = 0; i < num_entries; i++) | |
feee612b | 2328 | { |
25dbc73a AM |
2329 | bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length); |
2330 | length += 4; | |
feee612b | 2331 | } |
feee612b | 2332 | |
25dbc73a AM |
2333 | if (length != asec->size) |
2334 | (*_bfd_error_handler) (_("failed to compute new APUinfo section.")); | |
252b5132 | 2335 | |
25dbc73a AM |
2336 | if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length)) |
2337 | (*_bfd_error_handler) (_("failed to install new APUinfo section.")); | |
252b5132 | 2338 | |
25dbc73a AM |
2339 | free (buffer); |
2340 | ||
2341 | apuinfo_list_finish (); | |
252b5132 | 2342 | } |
25dbc73a | 2343 | \f |
7382d32a | 2344 | static bfd_boolean |
c6dd29ce | 2345 | is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off) |
7382d32a | 2346 | { |
c6dd29ce | 2347 | bfd_byte buf[GLINK_ENTRY_SIZE]; |
7382d32a | 2348 | |
c6dd29ce | 2349 | if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE)) |
7382d32a AM |
2350 | return FALSE; |
2351 | ||
c6dd29ce AM |
2352 | return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11 |
2353 | && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11 | |
2354 | && bfd_get_32 (abfd, buf + 8) == MTCTR_11 | |
2355 | && bfd_get_32 (abfd, buf + 12) == BCTR); | |
7382d32a AM |
2356 | } |
2357 | ||
468392fb AM |
2358 | static bfd_boolean |
2359 | section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr) | |
2360 | { | |
2361 | bfd_vma vma = *(bfd_vma *) ptr; | |
2362 | return ((section->flags & SEC_ALLOC) != 0 | |
2363 | && section->vma <= vma | |
2364 | && vma < section->vma + section->size); | |
2365 | } | |
2366 | ||
2367 | static long | |
2368 | ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms, | |
2369 | long dynsymcount, asymbol **dynsyms, | |
2370 | asymbol **ret) | |
2371 | { | |
2372 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); | |
2373 | asection *plt, *relplt, *dynamic, *glink; | |
2374 | bfd_vma glink_vma = 0; | |
2375 | bfd_vma resolv_vma = 0; | |
2376 | bfd_vma stub_vma; | |
2377 | asymbol *s; | |
2378 | arelent *p; | |
2379 | long count, i; | |
2380 | size_t size; | |
2381 | char *names; | |
2382 | bfd_byte buf[4]; | |
2383 | ||
2384 | *ret = NULL; | |
2385 | ||
2386 | if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0) | |
2387 | return 0; | |
2388 | ||
2389 | if (dynsymcount <= 0) | |
2390 | return 0; | |
2391 | ||
2392 | relplt = bfd_get_section_by_name (abfd, ".rela.plt"); | |
2393 | if (relplt == NULL) | |
2394 | return 0; | |
2395 | ||
2396 | plt = bfd_get_section_by_name (abfd, ".plt"); | |
2397 | if (plt == NULL) | |
2398 | return 0; | |
2399 | ||
2400 | /* Call common code to handle old-style executable PLTs. */ | |
2401 | if (elf_section_flags (plt) & SHF_EXECINSTR) | |
2402 | return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms, | |
2403 | dynsymcount, dynsyms, ret); | |
2404 | ||
2405 | /* If this object was prelinked, the prelinker stored the address | |
2406 | of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */ | |
2407 | dynamic = bfd_get_section_by_name (abfd, ".dynamic"); | |
2408 | if (dynamic != NULL) | |
2409 | { | |
2410 | bfd_byte *dynbuf, *extdyn, *extdynend; | |
2411 | size_t extdynsize; | |
2412 | void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *); | |
2413 | ||
2414 | if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf)) | |
2415 | return -1; | |
2416 | ||
2417 | extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; | |
2418 | swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in; | |
2419 | ||
2420 | extdyn = dynbuf; | |
2421 | extdynend = extdyn + dynamic->size; | |
2422 | for (; extdyn < extdynend; extdyn += extdynsize) | |
2423 | { | |
2424 | Elf_Internal_Dyn dyn; | |
2425 | (*swap_dyn_in) (abfd, extdyn, &dyn); | |
2426 | ||
2427 | if (dyn.d_tag == DT_NULL) | |
2428 | break; | |
2429 | ||
2430 | if (dyn.d_tag == DT_PPC_GOT) | |
2431 | { | |
2432 | unsigned int g_o_t = dyn.d_un.d_val; | |
2433 | asection *got = bfd_get_section_by_name (abfd, ".got"); | |
2434 | if (got != NULL | |
2435 | && bfd_get_section_contents (abfd, got, buf, | |
2436 | g_o_t - got->vma + 4, 4)) | |
2437 | glink_vma = bfd_get_32 (abfd, buf); | |
2438 | break; | |
2439 | } | |
2440 | } | |
2441 | free (dynbuf); | |
2442 | } | |
2443 | ||
2444 | /* Otherwise we read the first plt entry. */ | |
2445 | if (glink_vma == 0) | |
2446 | { | |
2447 | if (bfd_get_section_contents (abfd, plt, buf, 0, 4)) | |
2448 | glink_vma = bfd_get_32 (abfd, buf); | |
2449 | } | |
2450 | ||
2451 | if (glink_vma == 0) | |
2452 | return 0; | |
2453 | ||
2454 | /* The .glink section usually does not survive the final | |
2455 | link; search for the section (usually .text) where the | |
2456 | glink stubs now reside. */ | |
2457 | glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma); | |
2458 | if (glink == NULL) | |
2459 | return 0; | |
2460 | ||
2461 | /* Determine glink PLT resolver by reading the relative branch | |
2462 | from the first glink stub. */ | |
2463 | if (bfd_get_section_contents (abfd, glink, buf, | |
2464 | glink_vma - glink->vma, 4)) | |
2465 | { | |
2466 | unsigned int insn = bfd_get_32 (abfd, buf); | |
2467 | ||
2468 | /* The first glink stub may either branch to the resolver ... */ | |
2469 | insn ^= B; | |
2470 | if ((insn & ~0x3fffffc) == 0) | |
2471 | resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000; | |
2472 | ||
2473 | /* ... or fall through a bunch of NOPs. */ | |
2474 | else if ((insn ^ B ^ NOP) == 0) | |
2475 | for (i = 4; | |
2476 | bfd_get_section_contents (abfd, glink, buf, | |
2477 | glink_vma - glink->vma + i, 4); | |
2478 | i += 4) | |
2479 | if (bfd_get_32 (abfd, buf) != NOP) | |
2480 | { | |
2481 | resolv_vma = glink_vma + i; | |
2482 | break; | |
2483 | } | |
2484 | } | |
2485 | ||
7382d32a AM |
2486 | count = relplt->size / sizeof (Elf32_External_Rela); |
2487 | stub_vma = glink_vma - (bfd_vma) count * 16; | |
2488 | /* If the stubs are those for -shared/-pie then we might have | |
2489 | multiple stubs for each plt entry. If that is the case then | |
2490 | there is no way to associate stubs with their plt entries short | |
2491 | of figuring out the GOT pointer value used in the stub. */ | |
c6dd29ce AM |
2492 | if (!is_nonpic_glink_stub (abfd, glink, |
2493 | glink_vma - GLINK_ENTRY_SIZE - glink->vma)) | |
7382d32a AM |
2494 | return 0; |
2495 | ||
468392fb AM |
2496 | slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; |
2497 | if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE)) | |
2498 | return -1; | |
2499 | ||
468392fb AM |
2500 | size = count * sizeof (asymbol); |
2501 | p = relplt->relocation; | |
2502 | for (i = 0; i < count; i++, p++) | |
e054468f AM |
2503 | { |
2504 | size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt"); | |
2505 | if (p->addend != 0) | |
2506 | size += sizeof ("+0x") - 1 + 8; | |
2507 | } | |
468392fb AM |
2508 | |
2509 | size += sizeof (asymbol) + sizeof ("__glink"); | |
2510 | ||
2511 | if (resolv_vma) | |
2512 | size += sizeof (asymbol) + sizeof ("__glink_PLTresolve"); | |
2513 | ||
2514 | s = *ret = bfd_malloc (size); | |
2515 | if (s == NULL) | |
2516 | return -1; | |
2517 | ||
2518 | names = (char *) (s + count + 1 + (resolv_vma != 0)); | |
2519 | p = relplt->relocation; | |
2520 | for (i = 0; i < count; i++, p++) | |
2521 | { | |
2522 | size_t len; | |
2523 | ||
2524 | *s = **p->sym_ptr_ptr; | |
2525 | /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since | |
2526 | we are defining a symbol, ensure one of them is set. */ | |
2527 | if ((s->flags & BSF_LOCAL) == 0) | |
2528 | s->flags |= BSF_GLOBAL; | |
6ba2a415 | 2529 | s->flags |= BSF_SYNTHETIC; |
468392fb AM |
2530 | s->section = glink; |
2531 | s->value = stub_vma - glink->vma; | |
2532 | s->name = names; | |
2533 | s->udata.p = NULL; | |
2534 | len = strlen ((*p->sym_ptr_ptr)->name); | |
2535 | memcpy (names, (*p->sym_ptr_ptr)->name, len); | |
2536 | names += len; | |
e054468f AM |
2537 | if (p->addend != 0) |
2538 | { | |
2539 | memcpy (names, "+0x", sizeof ("+0x") - 1); | |
2540 | names += sizeof ("+0x") - 1; | |
2541 | bfd_sprintf_vma (abfd, names, p->addend); | |
2542 | names += strlen (names); | |
2543 | } | |
468392fb AM |
2544 | memcpy (names, "@plt", sizeof ("@plt")); |
2545 | names += sizeof ("@plt"); | |
2546 | ++s; | |
2547 | stub_vma += 16; | |
2548 | } | |
2549 | ||
2550 | /* Add a symbol at the start of the glink branch table. */ | |
86a4952b | 2551 | memset (s, 0, sizeof *s); |
468392fb | 2552 | s->the_bfd = abfd; |
6ba2a415 | 2553 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
2554 | s->section = glink; |
2555 | s->value = glink_vma - glink->vma; | |
2556 | s->name = names; | |
2557 | memcpy (names, "__glink", sizeof ("__glink")); | |
2558 | names += sizeof ("__glink"); | |
2559 | s++; | |
2560 | count++; | |
2561 | ||
2562 | if (resolv_vma) | |
2563 | { | |
2564 | /* Add a symbol for the glink PLT resolver. */ | |
86a4952b | 2565 | memset (s, 0, sizeof *s); |
468392fb | 2566 | s->the_bfd = abfd; |
6ba2a415 | 2567 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
2568 | s->section = glink; |
2569 | s->value = resolv_vma - glink->vma; | |
2570 | s->name = names; | |
2571 | memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve")); | |
2572 | names += sizeof ("__glink_PLTresolve"); | |
2573 | s++; | |
2574 | count++; | |
2575 | } | |
2576 | ||
2577 | return count; | |
2578 | } | |
2579 | \f | |
25dbc73a AM |
2580 | /* The following functions are specific to the ELF linker, while |
2581 | functions above are used generally. They appear in this file more | |
2582 | or less in the order in which they are called. eg. | |
2583 | ppc_elf_check_relocs is called early in the link process, | |
2584 | ppc_elf_finish_dynamic_sections is one of the last functions | |
2585 | called. */ | |
252b5132 | 2586 | |
25dbc73a AM |
2587 | /* The PPC linker needs to keep track of the number of relocs that it |
2588 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2589 | This is so that it can later discard them if they are found to be | |
2590 | unnecessary. We store the information in a field extending the | |
2591 | regular ELF linker hash table. */ | |
ae9a127f | 2592 | |
25dbc73a | 2593 | struct ppc_elf_dyn_relocs |
252b5132 | 2594 | { |
25dbc73a | 2595 | struct ppc_elf_dyn_relocs *next; |
252b5132 | 2596 | |
25dbc73a AM |
2597 | /* The input section of the reloc. */ |
2598 | asection *sec; | |
252b5132 | 2599 | |
25dbc73a AM |
2600 | /* Total number of relocs copied for the input section. */ |
2601 | bfd_size_type count; | |
252b5132 | 2602 | |
25dbc73a AM |
2603 | /* Number of pc-relative relocs copied for the input section. */ |
2604 | bfd_size_type pc_count; | |
2605 | }; | |
252b5132 | 2606 | |
a6aa5195 | 2607 | /* Track PLT entries needed for a given symbol. We might need more |
a877a2b6 | 2608 | than one glink entry per symbol when generating a pic binary. */ |
a6aa5195 AM |
2609 | struct plt_entry |
2610 | { | |
2611 | struct plt_entry *next; | |
2612 | ||
2613 | /* -fPIC uses multiple GOT sections, one per file, called ".got2". | |
2614 | This field stores the offset into .got2 used to initialise the | |
a877a2b6 AM |
2615 | GOT pointer reg. It will always be at least 32768. (Current |
2616 | gcc always uses an offset of 32768, but ld -r will pack .got2 | |
2617 | sections together resulting in larger offsets). */ | |
a6aa5195 AM |
2618 | bfd_vma addend; |
2619 | ||
2620 | /* The .got2 section. */ | |
2621 | asection *sec; | |
2622 | ||
2623 | /* PLT refcount or offset. */ | |
2624 | union | |
2625 | { | |
2626 | bfd_signed_vma refcount; | |
2627 | bfd_vma offset; | |
2628 | } plt; | |
2629 | ||
2630 | /* .glink stub offset. */ | |
2631 | bfd_vma glink_offset; | |
2632 | }; | |
2633 | ||
1d483afe | 2634 | /* Of those relocs that might be copied as dynamic relocs, this function |
25dbc73a AM |
2635 | selects those that must be copied when linking a shared library, |
2636 | even when the symbol is local. */ | |
252b5132 | 2637 | |
1d483afe AM |
2638 | static int |
2639 | must_be_dyn_reloc (struct bfd_link_info *info, | |
2640 | enum elf_ppc_reloc_type r_type) | |
2641 | { | |
2642 | switch (r_type) | |
2643 | { | |
2644 | default: | |
2645 | return 1; | |
2646 | ||
2647 | case R_PPC_REL24: | |
2648 | case R_PPC_REL14: | |
2649 | case R_PPC_REL14_BRTAKEN: | |
2650 | case R_PPC_REL14_BRNTAKEN: | |
2651 | case R_PPC_REL32: | |
2652 | return 0; | |
2653 | ||
2654 | case R_PPC_TPREL32: | |
2655 | case R_PPC_TPREL16: | |
2656 | case R_PPC_TPREL16_LO: | |
2657 | case R_PPC_TPREL16_HI: | |
2658 | case R_PPC_TPREL16_HA: | |
2659 | return !info->executable; | |
2660 | } | |
2661 | } | |
252b5132 | 2662 | |
25dbc73a AM |
2663 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2664 | copying dynamic variables from a shared lib into an app's dynbss | |
2665 | section, and instead use a dynamic relocation to point into the | |
2666 | shared lib. */ | |
2667 | #define ELIMINATE_COPY_RELOCS 1 | |
252b5132 | 2668 | |
25dbc73a | 2669 | /* PPC ELF linker hash entry. */ |
252b5132 | 2670 | |
25dbc73a AM |
2671 | struct ppc_elf_link_hash_entry |
2672 | { | |
2673 | struct elf_link_hash_entry elf; | |
252b5132 | 2674 | |
25dbc73a AM |
2675 | /* If this symbol is used in the linker created sections, the processor |
2676 | specific backend uses this field to map the field into the offset | |
2677 | from the beginning of the section. */ | |
2678 | elf_linker_section_pointers_t *linker_section_pointer; | |
252b5132 | 2679 | |
25dbc73a AM |
2680 | /* Track dynamic relocs copied for this symbol. */ |
2681 | struct ppc_elf_dyn_relocs *dyn_relocs; | |
252b5132 | 2682 | |
25dbc73a AM |
2683 | /* Contexts in which symbol is used in the GOT (or TOC). |
2684 | TLS_GD .. TLS_TLS bits are or'd into the mask as the | |
2685 | corresponding relocs are encountered during check_relocs. | |
2686 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2687 | indicate the corresponding GOT entry type is not needed. */ | |
2688 | #define TLS_GD 1 /* GD reloc. */ | |
2689 | #define TLS_LD 2 /* LD reloc. */ | |
2690 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2691 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2692 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2693 | #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */ | |
e054468f | 2694 | #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */ |
25dbc73a | 2695 | char tls_mask; |
4dc4a9a5 DJ |
2696 | |
2697 | /* Nonzero if we have seen a small data relocation referring to this | |
2698 | symbol. */ | |
2699 | unsigned char has_sda_refs; | |
25dbc73a | 2700 | }; |
252b5132 | 2701 | |
25dbc73a AM |
2702 | #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent)) |
2703 | ||
2704 | /* PPC ELF linker hash table. */ | |
2705 | ||
2706 | struct ppc_elf_link_hash_table | |
2707 | { | |
2708 | struct elf_link_hash_table elf; | |
2709 | ||
2710 | /* Short-cuts to get to dynamic linker sections. */ | |
2711 | asection *got; | |
2712 | asection *relgot; | |
d7128ce4 | 2713 | asection *glink; |
25dbc73a AM |
2714 | asection *plt; |
2715 | asection *relplt; | |
e054468f AM |
2716 | asection *iplt; |
2717 | asection *reliplt; | |
25dbc73a AM |
2718 | asection *dynbss; |
2719 | asection *relbss; | |
2720 | asection *dynsbss; | |
2721 | asection *relsbss; | |
c9a2f333 | 2722 | elf_linker_section_t sdata[2]; |
25dbc73a AM |
2723 | asection *sbss; |
2724 | ||
016687f8 AM |
2725 | /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */ |
2726 | asection *srelplt2; | |
2727 | ||
2728 | /* The .got.plt section (VxWorks only)*/ | |
2729 | asection *sgotplt; | |
2730 | ||
1d483afe | 2731 | /* Shortcut to __tls_get_addr. */ |
25dbc73a | 2732 | struct elf_link_hash_entry *tls_get_addr; |
252b5132 | 2733 | |
016687f8 AM |
2734 | /* The bfd that forced an old-style PLT. */ |
2735 | bfd *old_bfd; | |
2736 | ||
25dbc73a AM |
2737 | /* TLS local dynamic got entry handling. */ |
2738 | union { | |
2739 | bfd_signed_vma refcount; | |
2740 | bfd_vma offset; | |
2741 | } tlsld_got; | |
252b5132 | 2742 | |
c6dd29ce | 2743 | /* Offset of branch table to PltResolve function in glink. */ |
d7128ce4 AM |
2744 | bfd_vma glink_pltresolve; |
2745 | ||
3b36f7e6 AM |
2746 | /* Size of reserved GOT entries. */ |
2747 | unsigned int got_header_size; | |
2748 | /* Non-zero if allocating the header left a gap. */ | |
2749 | unsigned int got_gap; | |
2750 | ||
4a3dc543 RS |
2751 | /* The type of PLT we have chosen to use. */ |
2752 | enum ppc_elf_plt_type plt_type; | |
2753 | ||
0ba07910 AM |
2754 | /* Set if we should emit symbols for stubs. */ |
2755 | unsigned int emit_stub_syms:1; | |
2756 | ||
9d8504b1 | 2757 | /* True if the target system is VxWorks. */ |
016687f8 | 2758 | unsigned int is_vxworks:1; |
9d8504b1 PB |
2759 | |
2760 | /* The size of PLT entries. */ | |
2761 | int plt_entry_size; | |
2762 | /* The distance between adjacent PLT slots. */ | |
2763 | int plt_slot_size; | |
2764 | /* The size of the first PLT entry. */ | |
2765 | int plt_initial_entry_size; | |
016687f8 | 2766 | |
87d72d41 AM |
2767 | /* Small local sym cache. */ |
2768 | struct sym_cache sym_cache; | |
25dbc73a | 2769 | }; |
252b5132 | 2770 | |
25dbc73a | 2771 | /* Get the PPC ELF linker hash table from a link_info structure. */ |
252b5132 | 2772 | |
25dbc73a AM |
2773 | #define ppc_elf_hash_table(p) \ |
2774 | ((struct ppc_elf_link_hash_table *) (p)->hash) | |
252b5132 | 2775 | |
25dbc73a | 2776 | /* Create an entry in a PPC ELF linker hash table. */ |
252b5132 | 2777 | |
25dbc73a AM |
2778 | static struct bfd_hash_entry * |
2779 | ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry, | |
2780 | struct bfd_hash_table *table, | |
2781 | const char *string) | |
252b5132 | 2782 | { |
25dbc73a AM |
2783 | /* Allocate the structure if it has not already been allocated by a |
2784 | subclass. */ | |
2785 | if (entry == NULL) | |
2786 | { | |
2787 | entry = bfd_hash_allocate (table, | |
2788 | sizeof (struct ppc_elf_link_hash_entry)); | |
2789 | if (entry == NULL) | |
2790 | return entry; | |
2791 | } | |
252b5132 | 2792 | |
25dbc73a AM |
2793 | /* Call the allocation method of the superclass. */ |
2794 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2795 | if (entry != NULL) | |
2796 | { | |
2797 | ppc_elf_hash_entry (entry)->linker_section_pointer = NULL; | |
2798 | ppc_elf_hash_entry (entry)->dyn_relocs = NULL; | |
2799 | ppc_elf_hash_entry (entry)->tls_mask = 0; | |
2800 | } | |
252b5132 | 2801 | |
25dbc73a | 2802 | return entry; |
252b5132 | 2803 | } |
3dab13f6 | 2804 | |
25dbc73a | 2805 | /* Create a PPC ELF linker hash table. */ |
3dab13f6 | 2806 | |
25dbc73a AM |
2807 | static struct bfd_link_hash_table * |
2808 | ppc_elf_link_hash_table_create (bfd *abfd) | |
3dab13f6 | 2809 | { |
25dbc73a | 2810 | struct ppc_elf_link_hash_table *ret; |
3dab13f6 | 2811 | |
25dbc73a AM |
2812 | ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table)); |
2813 | if (ret == NULL) | |
2814 | return NULL; | |
3dab13f6 | 2815 | |
66eb6687 AM |
2816 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, |
2817 | ppc_elf_link_hash_newfunc, | |
2818 | sizeof (struct ppc_elf_link_hash_entry))) | |
3dab13f6 | 2819 | { |
25dbc73a AM |
2820 | free (ret); |
2821 | return NULL; | |
2822 | } | |
58111eb7 | 2823 | |
a6aa5195 AM |
2824 | ret->elf.init_plt_refcount.refcount = 0; |
2825 | ret->elf.init_plt_refcount.glist = NULL; | |
2826 | ret->elf.init_plt_offset.offset = 0; | |
2827 | ret->elf.init_plt_offset.glist = NULL; | |
2828 | ||
c9a2f333 AM |
2829 | ret->sdata[0].name = ".sdata"; |
2830 | ret->sdata[0].sym_name = "_SDA_BASE_"; | |
2831 | ret->sdata[0].bss_name = ".sbss"; | |
2832 | ||
2833 | ret->sdata[1].name = ".sdata2"; | |
2834 | ret->sdata[1].sym_name = "_SDA2_BASE_"; | |
2835 | ret->sdata[1].bss_name = ".sbss2"; | |
2836 | ||
9d8504b1 PB |
2837 | ret->plt_entry_size = 12; |
2838 | ret->plt_slot_size = 8; | |
2839 | ret->plt_initial_entry_size = 72; | |
9d8504b1 | 2840 | |
25dbc73a AM |
2841 | return &ret->elf.root; |
2842 | } | |
3dab13f6 | 2843 | |
9d8504b1 | 2844 | /* Create .got and the related sections. */ |
3dab13f6 | 2845 | |
25dbc73a AM |
2846 | static bfd_boolean |
2847 | ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info) | |
2848 | { | |
2849 | struct ppc_elf_link_hash_table *htab; | |
2850 | asection *s; | |
2851 | flagword flags; | |
3dab13f6 | 2852 | |
25dbc73a AM |
2853 | if (!_bfd_elf_create_got_section (abfd, info)) |
2854 | return FALSE; | |
3dab13f6 | 2855 | |
25dbc73a AM |
2856 | htab = ppc_elf_hash_table (info); |
2857 | htab->got = s = bfd_get_section_by_name (abfd, ".got"); | |
2858 | if (s == NULL) | |
2859 | abort (); | |
3dab13f6 | 2860 | |
9d8504b1 PB |
2861 | if (htab->is_vxworks) |
2862 | { | |
2863 | htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt"); | |
2864 | if (!htab->sgotplt) | |
2865 | abort (); | |
2866 | } | |
2867 | else | |
2868 | { | |
2869 | /* The powerpc .got has a blrl instruction in it. Mark it | |
2870 | executable. */ | |
2871 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | |
2872 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2873 | if (!bfd_set_section_flags (abfd, s, flags)) | |
2874 | return FALSE; | |
2875 | } | |
3dab13f6 | 2876 | |
64e77c6d L |
2877 | htab->relgot = bfd_get_section_by_name (abfd, ".rela.got"); |
2878 | if (!htab->relgot) | |
2879 | abort (); | |
3dab13f6 | 2880 | |
25dbc73a AM |
2881 | return TRUE; |
2882 | } | |
3dab13f6 | 2883 | |
e054468f AM |
2884 | static bfd_boolean |
2885 | ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info) | |
2886 | { | |
2887 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
2888 | asection *s; | |
2889 | flagword flags; | |
2890 | ||
2891 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | |
2892 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2893 | s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags); | |
2894 | htab->glink = s; | |
2895 | if (s == NULL | |
2896 | || !bfd_set_section_alignment (abfd, s, 4)) | |
2897 | return FALSE; | |
2898 | ||
2899 | flags = SEC_ALLOC | SEC_LINKER_CREATED; | |
2900 | s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags); | |
2901 | htab->iplt = s; | |
2902 | if (s == NULL | |
2903 | || !bfd_set_section_alignment (abfd, s, 4)) | |
2904 | return FALSE; | |
2905 | ||
2906 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | |
2907 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2908 | s = bfd_make_section_with_flags (abfd, ".rela.iplt", flags); | |
2909 | htab->reliplt = s; | |
2910 | if (s == NULL | |
2911 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
2912 | return FALSE; | |
2913 | return TRUE; | |
2914 | } | |
2915 | ||
25dbc73a AM |
2916 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
2917 | to output sections (just like _bfd_elf_create_dynamic_sections has | |
2918 | to create .dynbss and .rela.bss). */ | |
3dab13f6 | 2919 | |
25dbc73a AM |
2920 | static bfd_boolean |
2921 | ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |
2922 | { | |
2923 | struct ppc_elf_link_hash_table *htab; | |
2924 | asection *s; | |
2925 | flagword flags; | |
3dab13f6 | 2926 | |
25dbc73a | 2927 | htab = ppc_elf_hash_table (info); |
3dab13f6 | 2928 | |
25dbc73a AM |
2929 | if (htab->got == NULL |
2930 | && !ppc_elf_create_got (abfd, info)) | |
3dab13f6 AM |
2931 | return FALSE; |
2932 | ||
25dbc73a AM |
2933 | if (!_bfd_elf_create_dynamic_sections (abfd, info)) |
2934 | return FALSE; | |
3dab13f6 | 2935 | |
e054468f AM |
2936 | if (htab->glink == NULL |
2937 | && !ppc_elf_create_glink (abfd, info)) | |
d7128ce4 | 2938 | return FALSE; |
3dab13f6 | 2939 | |
25dbc73a | 2940 | htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss"); |
3b36f7e6 AM |
2941 | s = bfd_make_section_with_flags (abfd, ".dynsbss", |
2942 | SEC_ALLOC | SEC_LINKER_CREATED); | |
2943 | htab->dynsbss = s; | |
3496cb2a | 2944 | if (s == NULL) |
25dbc73a | 2945 | return FALSE; |
3dab13f6 | 2946 | |
25dbc73a AM |
2947 | if (! info->shared) |
2948 | { | |
2949 | htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss"); | |
e054468f AM |
2950 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS |
2951 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
d7128ce4 | 2952 | s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags); |
3b36f7e6 | 2953 | htab->relsbss = s; |
25dbc73a | 2954 | if (s == NULL |
25dbc73a AM |
2955 | || ! bfd_set_section_alignment (abfd, s, 2)) |
2956 | return FALSE; | |
2957 | } | |
3dab13f6 | 2958 | |
711de32c RS |
2959 | if (htab->is_vxworks |
2960 | && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2)) | |
2961 | return FALSE; | |
9d8504b1 | 2962 | |
25dbc73a AM |
2963 | htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt"); |
2964 | htab->plt = s = bfd_get_section_by_name (abfd, ".plt"); | |
2965 | if (s == NULL) | |
2966 | abort (); | |
3dab13f6 | 2967 | |
3b36f7e6 | 2968 | flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED; |
4a3dc543 RS |
2969 | if (htab->plt_type == PLT_VXWORKS) |
2970 | /* The VxWorks PLT is a loaded section with contents. */ | |
2971 | flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY; | |
25dbc73a AM |
2972 | return bfd_set_section_flags (abfd, s, flags); |
2973 | } | |
3dab13f6 | 2974 | |
25dbc73a | 2975 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
58111eb7 | 2976 | |
25dbc73a | 2977 | static void |
fcfa13d2 | 2978 | ppc_elf_copy_indirect_symbol (struct bfd_link_info *info, |
25dbc73a AM |
2979 | struct elf_link_hash_entry *dir, |
2980 | struct elf_link_hash_entry *ind) | |
2981 | { | |
2982 | struct ppc_elf_link_hash_entry *edir, *eind; | |
3dab13f6 | 2983 | |
25dbc73a AM |
2984 | edir = (struct ppc_elf_link_hash_entry *) dir; |
2985 | eind = (struct ppc_elf_link_hash_entry *) ind; | |
3dab13f6 | 2986 | |
25dbc73a AM |
2987 | if (eind->dyn_relocs != NULL) |
2988 | { | |
2989 | if (edir->dyn_relocs != NULL) | |
3dab13f6 | 2990 | { |
25dbc73a AM |
2991 | struct ppc_elf_dyn_relocs **pp; |
2992 | struct ppc_elf_dyn_relocs *p; | |
3dab13f6 | 2993 | |
fcfa13d2 | 2994 | /* Add reloc counts against the indirect sym to the direct sym |
25dbc73a AM |
2995 | list. Merge any entries against the same section. */ |
2996 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3dab13f6 | 2997 | { |
25dbc73a AM |
2998 | struct ppc_elf_dyn_relocs *q; |
2999 | ||
3000 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3001 | if (q->sec == p->sec) | |
3002 | { | |
3003 | q->pc_count += p->pc_count; | |
3004 | q->count += p->count; | |
3005 | *pp = p->next; | |
3006 | break; | |
3007 | } | |
3008 | if (q == NULL) | |
3009 | pp = &p->next; | |
3dab13f6 | 3010 | } |
25dbc73a | 3011 | *pp = edir->dyn_relocs; |
3dab13f6 | 3012 | } |
25dbc73a AM |
3013 | |
3014 | edir->dyn_relocs = eind->dyn_relocs; | |
3015 | eind->dyn_relocs = NULL; | |
3dab13f6 | 3016 | } |
3dab13f6 | 3017 | |
25dbc73a | 3018 | edir->tls_mask |= eind->tls_mask; |
4dc4a9a5 | 3019 | edir->has_sda_refs |= eind->has_sda_refs; |
3dab13f6 | 3020 | |
a6aa5195 AM |
3021 | /* If called to transfer flags for a weakdef during processing |
3022 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |
3023 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3024 | if (!(ELIMINATE_COPY_RELOCS | |
3025 | && eind->elf.root.type != bfd_link_hash_indirect | |
3026 | && edir->elf.dynamic_adjusted)) | |
3027 | edir->elf.non_got_ref |= eind->elf.non_got_ref; | |
3028 | ||
3029 | edir->elf.ref_dynamic |= eind->elf.ref_dynamic; | |
3030 | edir->elf.ref_regular |= eind->elf.ref_regular; | |
3031 | edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak; | |
3032 | edir->elf.needs_plt |= eind->elf.needs_plt; | |
0eb4a168 | 3033 | edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed; |
a6aa5195 AM |
3034 | |
3035 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3036 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3037 | return; | |
3038 | ||
3039 | /* Copy over the GOT refcount entries that we may have already seen to | |
3040 | the symbol which just became indirect. */ | |
fcfa13d2 AM |
3041 | edir->elf.got.refcount += eind->elf.got.refcount; |
3042 | eind->elf.got.refcount = 0; | |
a6aa5195 AM |
3043 | |
3044 | /* And plt entries. */ | |
3045 | if (eind->elf.plt.plist != NULL) | |
3046 | { | |
3047 | if (edir->elf.plt.plist != NULL) | |
3048 | { | |
3049 | struct plt_entry **entp; | |
3050 | struct plt_entry *ent; | |
3051 | ||
3052 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3053 | { | |
3054 | struct plt_entry *dent; | |
3055 | ||
3056 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3057 | if (dent->sec == ent->sec && dent->addend == ent->addend) | |
3058 | { | |
3059 | dent->plt.refcount += ent->plt.refcount; | |
3060 | *entp = ent->next; | |
3061 | break; | |
3062 | } | |
3063 | if (dent == NULL) | |
3064 | entp = &ent->next; | |
3065 | } | |
3066 | *entp = edir->elf.plt.plist; | |
3067 | } | |
3068 | ||
3069 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3070 | eind->elf.plt.plist = NULL; | |
3071 | } | |
3072 | ||
fcfa13d2 | 3073 | if (eind->elf.dynindx != -1) |
25dbc73a | 3074 | { |
fcfa13d2 AM |
3075 | if (edir->elf.dynindx != -1) |
3076 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
3077 | edir->elf.dynstr_index); | |
a6aa5195 AM |
3078 | edir->elf.dynindx = eind->elf.dynindx; |
3079 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3080 | eind->elf.dynindx = -1; | |
3081 | eind->elf.dynstr_index = 0; | |
25dbc73a | 3082 | } |
25dbc73a | 3083 | } |
3dab13f6 | 3084 | |
25dbc73a AM |
3085 | /* Hook called by the linker routine which adds symbols from an object |
3086 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
58111eb7 | 3087 | |
25dbc73a AM |
3088 | static bfd_boolean |
3089 | ppc_elf_add_symbol_hook (bfd *abfd, | |
3090 | struct bfd_link_info *info, | |
3091 | Elf_Internal_Sym *sym, | |
3092 | const char **namep ATTRIBUTE_UNUSED, | |
3093 | flagword *flagsp ATTRIBUTE_UNUSED, | |
3094 | asection **secp, | |
3095 | bfd_vma *valp) | |
3096 | { | |
3097 | if (sym->st_shndx == SHN_COMMON | |
3098 | && !info->relocatable | |
0c8d6e5c AM |
3099 | && is_ppc_elf (info->output_bfd) |
3100 | && sym->st_size <= elf_gp_size (abfd)) | |
25dbc73a AM |
3101 | { |
3102 | /* Common symbols less than or equal to -G nn bytes are automatically | |
3103 | put into .sbss. */ | |
3104 | struct ppc_elf_link_hash_table *htab; | |
3dab13f6 | 3105 | |
25dbc73a AM |
3106 | htab = ppc_elf_hash_table (info); |
3107 | if (htab->sbss == NULL) | |
3108 | { | |
644285ef | 3109 | flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED; |
3dab13f6 | 3110 | |
644285ef AM |
3111 | if (!htab->elf.dynobj) |
3112 | htab->elf.dynobj = abfd; | |
3113 | ||
3496cb2a L |
3114 | htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
3115 | ".sbss", | |
3116 | flags); | |
3117 | if (htab->sbss == NULL) | |
25dbc73a | 3118 | return FALSE; |
3dab13f6 | 3119 | } |
3dab13f6 | 3120 | |
25dbc73a AM |
3121 | *secp = htab->sbss; |
3122 | *valp = sym->st_size; | |
3123 | } | |
3dab13f6 | 3124 | |
e054468f AM |
3125 | if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
3126 | elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE; | |
3127 | ||
25dbc73a | 3128 | return TRUE; |
3dab13f6 AM |
3129 | } |
3130 | \f | |
046183de AM |
3131 | static bfd_boolean |
3132 | create_sdata_sym (struct ppc_elf_link_hash_table *htab, | |
3133 | elf_linker_section_t *lsect) | |
3134 | { | |
3135 | lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name, | |
3136 | TRUE, FALSE, TRUE); | |
3137 | if (lsect->sym == NULL) | |
3138 | return FALSE; | |
3139 | if (lsect->sym->root.type == bfd_link_hash_new) | |
3140 | lsect->sym->non_elf = 0; | |
3141 | lsect->sym->ref_regular = 1; | |
3142 | return TRUE; | |
3143 | } | |
3144 | ||
c9a2f333 | 3145 | /* Create a special linker section. */ |
25dbc73a | 3146 | |
c9a2f333 | 3147 | static bfd_boolean |
55fd94b0 AM |
3148 | ppc_elf_create_linker_section (bfd *abfd, |
3149 | struct bfd_link_info *info, | |
c9a2f333 AM |
3150 | flagword flags, |
3151 | elf_linker_section_t *lsect) | |
252b5132 | 3152 | { |
58111eb7 | 3153 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); |
c9a2f333 | 3154 | asection *s; |
58111eb7 | 3155 | |
c9a2f333 AM |
3156 | flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
3157 | | SEC_LINKER_CREATED); | |
58111eb7 AM |
3158 | |
3159 | /* Record the first bfd that needs the special sections. */ | |
3160 | if (!htab->elf.dynobj) | |
3161 | htab->elf.dynobj = abfd; | |
3162 | ||
3496cb2a L |
3163 | s = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
3164 | lsect->name, | |
3165 | flags); | |
76750a2f | 3166 | if (s == NULL |
76750a2f | 3167 | || !bfd_set_section_alignment (htab->elf.dynobj, s, 2)) |
c9a2f333 | 3168 | return FALSE; |
76750a2f | 3169 | lsect->section = s; |
58111eb7 | 3170 | |
046183de | 3171 | return create_sdata_sym (htab, lsect); |
252b5132 | 3172 | } |
252b5132 | 3173 | |
25dbc73a AM |
3174 | /* Find a linker generated pointer with a given addend and type. */ |
3175 | ||
3176 | static elf_linker_section_pointers_t * | |
3177 | elf_find_pointer_linker_section | |
3178 | (elf_linker_section_pointers_t *linker_pointers, | |
3179 | bfd_vma addend, | |
3180 | elf_linker_section_t *lsect) | |
252b5132 | 3181 | { |
25dbc73a AM |
3182 | for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next) |
3183 | if (lsect == linker_pointers->lsect && addend == linker_pointers->addend) | |
3184 | return linker_pointers; | |
252b5132 | 3185 | |
25dbc73a AM |
3186 | return NULL; |
3187 | } | |
3188 | ||
3189 | /* Allocate a pointer to live in a linker created section. */ | |
3190 | ||
3191 | static bfd_boolean | |
3192 | elf_create_pointer_linker_section (bfd *abfd, | |
25dbc73a AM |
3193 | elf_linker_section_t *lsect, |
3194 | struct elf_link_hash_entry *h, | |
3195 | const Elf_Internal_Rela *rel) | |
3196 | { | |
3197 | elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL; | |
3198 | elf_linker_section_pointers_t *linker_section_ptr; | |
3199 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
3200 | bfd_size_type amt; | |
3201 | ||
3202 | BFD_ASSERT (lsect != NULL); | |
3203 | ||
3204 | /* Is this a global symbol? */ | |
3205 | if (h != NULL) | |
3206 | { | |
3207 | struct ppc_elf_link_hash_entry *eh; | |
3208 | ||
3209 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3210 | eh = (struct ppc_elf_link_hash_entry *) h; | |
3211 | if (elf_find_pointer_linker_section (eh->linker_section_pointer, | |
3212 | rel->r_addend, | |
3213 | lsect)) | |
3214 | return TRUE; | |
3215 | ||
3216 | ptr_linker_section_ptr = &eh->linker_section_pointer; | |
25dbc73a AM |
3217 | } |
3218 | else | |
3219 | { | |
0c8d6e5c | 3220 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 3221 | |
25dbc73a AM |
3222 | /* Allocation of a pointer to a local symbol. */ |
3223 | elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); | |
3224 | ||
3225 | /* Allocate a table to hold the local symbols if first time. */ | |
3226 | if (!ptr) | |
3227 | { | |
0ffa91dd | 3228 | unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info; |
25dbc73a AM |
3229 | |
3230 | amt = num_symbols; | |
3231 | amt *= sizeof (elf_linker_section_pointers_t *); | |
3232 | ptr = bfd_zalloc (abfd, amt); | |
3233 | ||
3234 | if (!ptr) | |
3235 | return FALSE; | |
3236 | ||
3237 | elf_local_ptr_offsets (abfd) = ptr; | |
3238 | } | |
3239 | ||
3240 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3241 | if (elf_find_pointer_linker_section (ptr[r_symndx], | |
3242 | rel->r_addend, | |
3243 | lsect)) | |
3244 | return TRUE; | |
252b5132 | 3245 | |
25dbc73a | 3246 | ptr_linker_section_ptr = &ptr[r_symndx]; |
25dbc73a | 3247 | } |
41fcb14e | 3248 | |
25dbc73a AM |
3249 | /* Allocate space for a pointer in the linker section, and allocate |
3250 | a new pointer record from internal memory. */ | |
3251 | BFD_ASSERT (ptr_linker_section_ptr != NULL); | |
3252 | amt = sizeof (elf_linker_section_pointers_t); | |
3253 | linker_section_ptr = bfd_alloc (abfd, amt); | |
41fcb14e | 3254 | |
25dbc73a | 3255 | if (!linker_section_ptr) |
7619e7c7 | 3256 | return FALSE; |
41fcb14e | 3257 | |
25dbc73a AM |
3258 | linker_section_ptr->next = *ptr_linker_section_ptr; |
3259 | linker_section_ptr->addend = rel->r_addend; | |
3260 | linker_section_ptr->lsect = lsect; | |
25dbc73a | 3261 | *ptr_linker_section_ptr = linker_section_ptr; |
41fcb14e | 3262 | |
25dbc73a AM |
3263 | linker_section_ptr->offset = lsect->section->size; |
3264 | lsect->section->size += 4; | |
7619e7c7 | 3265 | |
25dbc73a AM |
3266 | #ifdef DEBUG |
3267 | fprintf (stderr, | |
3268 | "Create pointer in linker section %s, offset = %ld, section size = %ld\n", | |
3269 | lsect->name, (long) linker_section_ptr->offset, | |
3270 | (long) lsect->section->size); | |
3271 | #endif | |
7619e7c7 AM |
3272 | |
3273 | return TRUE; | |
41fcb14e AM |
3274 | } |
3275 | ||
e054468f | 3276 | static struct plt_entry ** |
25dbc73a AM |
3277 | update_local_sym_info (bfd *abfd, |
3278 | Elf_Internal_Shdr *symtab_hdr, | |
3279 | unsigned long r_symndx, | |
3280 | int tls_type) | |
252b5132 | 3281 | { |
25dbc73a | 3282 | bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd); |
e054468f | 3283 | struct plt_entry **local_plt; |
25dbc73a | 3284 | char *local_got_tls_masks; |
252b5132 | 3285 | |
25dbc73a | 3286 | if (local_got_refcounts == NULL) |
252b5132 | 3287 | { |
25dbc73a AM |
3288 | bfd_size_type size = symtab_hdr->sh_info; |
3289 | ||
e054468f AM |
3290 | size *= (sizeof (*local_got_refcounts) |
3291 | + sizeof (*local_plt) | |
3292 | + sizeof (*local_got_tls_masks)); | |
25dbc73a AM |
3293 | local_got_refcounts = bfd_zalloc (abfd, size); |
3294 | if (local_got_refcounts == NULL) | |
e054468f | 3295 | return NULL; |
25dbc73a | 3296 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 3297 | } |
41fcb14e | 3298 | |
e054468f AM |
3299 | local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info); |
3300 | local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
25dbc73a | 3301 | local_got_tls_masks[r_symndx] |= tls_type; |
e054468f AM |
3302 | if (tls_type != PLT_IFUNC) |
3303 | local_got_refcounts[r_symndx] += 1; | |
3304 | return local_plt + r_symndx; | |
25dbc73a | 3305 | } |
41fcb14e | 3306 | |
a6aa5195 | 3307 | static bfd_boolean |
3ec01793 | 3308 | update_plt_info (bfd *abfd, struct plt_entry **plist, |
a6aa5195 AM |
3309 | asection *sec, bfd_vma addend) |
3310 | { | |
3311 | struct plt_entry *ent; | |
3312 | ||
3ec01793 | 3313 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3314 | if (ent->sec == sec && ent->addend == addend) |
3315 | break; | |
3316 | if (ent == NULL) | |
3317 | { | |
3318 | bfd_size_type amt = sizeof (*ent); | |
3319 | ent = bfd_alloc (abfd, amt); | |
3320 | if (ent == NULL) | |
3321 | return FALSE; | |
3ec01793 | 3322 | ent->next = *plist; |
a6aa5195 AM |
3323 | ent->sec = sec; |
3324 | ent->addend = addend; | |
3325 | ent->plt.refcount = 0; | |
3ec01793 | 3326 | *plist = ent; |
a6aa5195 AM |
3327 | } |
3328 | ent->plt.refcount += 1; | |
3329 | return TRUE; | |
3330 | } | |
3331 | ||
3332 | static struct plt_entry * | |
3ec01793 | 3333 | find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend) |
a6aa5195 AM |
3334 | { |
3335 | struct plt_entry *ent; | |
3336 | ||
3337 | if (addend < 32768) | |
3338 | sec = NULL; | |
3ec01793 | 3339 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3340 | if (ent->sec == sec && ent->addend == addend) |
3341 | break; | |
3342 | return ent; | |
3343 | } | |
3344 | ||
e054468f AM |
3345 | static bfd_boolean |
3346 | is_branch_reloc (enum elf_ppc_reloc_type r_type) | |
3347 | { | |
3348 | return (r_type == R_PPC_PLTREL24 | |
3349 | || r_type == R_PPC_LOCAL24PC | |
3350 | || r_type == R_PPC_REL24 | |
3351 | || r_type == R_PPC_REL14 | |
3352 | || r_type == R_PPC_REL14_BRTAKEN | |
3353 | || r_type == R_PPC_REL14_BRNTAKEN | |
3354 | || r_type == R_PPC_ADDR24 | |
3355 | || r_type == R_PPC_ADDR14 | |
3356 | || r_type == R_PPC_ADDR14_BRTAKEN | |
3357 | || r_type == R_PPC_ADDR14_BRNTAKEN); | |
3358 | } | |
3359 | ||
25dbc73a AM |
3360 | static void |
3361 | bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type) | |
3362 | { | |
3363 | (*_bfd_error_handler) | |
3364 | (_("%B: relocation %s cannot be used when making a shared object"), | |
3365 | abfd, | |
3366 | ppc_elf_howto_table[r_type]->name); | |
3367 | bfd_set_error (bfd_error_bad_value); | |
252b5132 RH |
3368 | } |
3369 | ||
25dbc73a AM |
3370 | /* Look through the relocs for a section during the first phase, and |
3371 | allocate space in the global offset table or procedure linkage | |
3372 | table. */ | |
252b5132 | 3373 | |
b34976b6 | 3374 | static bfd_boolean |
25dbc73a AM |
3375 | ppc_elf_check_relocs (bfd *abfd, |
3376 | struct bfd_link_info *info, | |
3377 | asection *sec, | |
3378 | const Elf_Internal_Rela *relocs) | |
252b5132 | 3379 | { |
7619e7c7 | 3380 | struct ppc_elf_link_hash_table *htab; |
25dbc73a AM |
3381 | Elf_Internal_Shdr *symtab_hdr; |
3382 | struct elf_link_hash_entry **sym_hashes; | |
3383 | const Elf_Internal_Rela *rel; | |
3384 | const Elf_Internal_Rela *rel_end; | |
a6aa5195 | 3385 | asection *got2, *sreloc; |
727fc41e | 3386 | struct elf_link_hash_entry *tga; |
25dbc73a AM |
3387 | |
3388 | if (info->relocatable) | |
3389 | return TRUE; | |
252b5132 | 3390 | |
c87b5a93 AM |
3391 | /* Don't do anything special with non-loaded, non-alloced sections. |
3392 | In particular, any relocs in such sections should not affect GOT | |
3393 | and PLT reference counting (ie. we don't allow them to create GOT | |
3394 | or PLT entries), there's no possibility or desire to optimize TLS | |
3395 | relocs, and there's not much point in propagating relocs to shared | |
3396 | libs that the dynamic linker won't relocate. */ | |
3397 | if ((sec->flags & SEC_ALLOC) == 0) | |
3398 | return TRUE; | |
3399 | ||
252b5132 | 3400 | #ifdef DEBUG |
25dbc73a AM |
3401 | _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B", |
3402 | sec, abfd); | |
252b5132 RH |
3403 | #endif |
3404 | ||
0c8d6e5c | 3405 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 3406 | |
25dbc73a AM |
3407 | /* Initialize howto table if not already done. */ |
3408 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
3409 | ppc_elf_howto_init (); | |
3410 | ||
7619e7c7 | 3411 | htab = ppc_elf_hash_table (info); |
25f23106 AM |
3412 | if (htab->glink == NULL) |
3413 | { | |
3414 | if (htab->elf.dynobj == NULL) | |
3415 | htab->elf.dynobj = abfd; | |
3416 | if (!ppc_elf_create_glink (htab->elf.dynobj, info)) | |
3417 | return FALSE; | |
3418 | } | |
727fc41e AM |
3419 | tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
3420 | FALSE, FALSE, TRUE); | |
0ffa91dd | 3421 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a | 3422 | sym_hashes = elf_sym_hashes (abfd); |
a6aa5195 | 3423 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
3424 | sreloc = NULL; |
3425 | ||
3426 | rel_end = relocs + sec->reloc_count; | |
3427 | for (rel = relocs; rel < rel_end; rel++) | |
3428 | { | |
3429 | unsigned long r_symndx; | |
3430 | enum elf_ppc_reloc_type r_type; | |
3431 | struct elf_link_hash_entry *h; | |
727fc41e | 3432 | int tls_type; |
e054468f | 3433 | struct plt_entry **ifunc; |
25dbc73a AM |
3434 | |
3435 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3436 | if (r_symndx < symtab_hdr->sh_info) | |
3437 | h = NULL; | |
3438 | else | |
973a3492 L |
3439 | { |
3440 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3441 | while (h->root.type == bfd_link_hash_indirect | |
3442 | || h->root.type == bfd_link_hash_warning) | |
3443 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3444 | } | |
25dbc73a AM |
3445 | |
3446 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. | |
3447 | This shows up in particular in an R_PPC_ADDR32 in the eabi | |
3448 | startup code. */ | |
3b36f7e6 AM |
3449 | if (h != NULL |
3450 | && htab->got == NULL | |
3451 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
252b5132 | 3452 | { |
3b36f7e6 AM |
3453 | if (htab->elf.dynobj == NULL) |
3454 | htab->elf.dynobj = abfd; | |
3455 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
3456 | return FALSE; | |
3457 | BFD_ASSERT (h == htab->elf.hgot); | |
25dbc73a | 3458 | } |
252b5132 | 3459 | |
727fc41e | 3460 | tls_type = 0; |
e054468f | 3461 | ifunc = NULL; |
de972ffa | 3462 | r_type = ELF32_R_TYPE (rel->r_info); |
25f23106 | 3463 | if (!htab->is_vxworks) |
e054468f | 3464 | { |
e054468f AM |
3465 | if (h != NULL) |
3466 | { | |
3467 | if (h->type == STT_GNU_IFUNC) | |
de972ffa | 3468 | ifunc = &h->plt.plist; |
e054468f AM |
3469 | } |
3470 | else | |
3471 | { | |
3472 | Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache, | |
3473 | abfd, r_symndx); | |
3474 | if (isym == NULL) | |
3475 | return FALSE; | |
3476 | ||
de972ffa AM |
3477 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC |
3478 | && (!info->shared | |
3479 | || is_branch_reloc (r_type))) | |
e054468f | 3480 | { |
de972ffa AM |
3481 | bfd_vma addend; |
3482 | ||
e054468f AM |
3483 | ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx, |
3484 | PLT_IFUNC); | |
3485 | if (ifunc == NULL) | |
3486 | return FALSE; | |
de972ffa AM |
3487 | |
3488 | /* STT_GNU_IFUNC symbols must have a PLT entry; | |
3489 | In a non-pie executable even when there are | |
3490 | no plt calls. */ | |
3491 | addend = 0; | |
3492 | if (r_type == R_PPC_PLTREL24) | |
3493 | { | |
3494 | ppc_elf_tdata (abfd)->makes_plt_call = 1; | |
a877a2b6 AM |
3495 | if (info->shared) |
3496 | addend = rel->r_addend; | |
de972ffa AM |
3497 | } |
3498 | if (!update_plt_info (abfd, ifunc, | |
3499 | addend < 32768 ? NULL : got2, addend)) | |
3500 | return FALSE; | |
e054468f AM |
3501 | } |
3502 | } | |
25f23106 AM |
3503 | } |
3504 | ||
de972ffa AM |
3505 | if (!htab->is_vxworks |
3506 | && is_branch_reloc (r_type) | |
3507 | && h != NULL | |
3508 | && h == tga) | |
25f23106 | 3509 | { |
de972ffa AM |
3510 | if (rel != relocs |
3511 | && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD | |
3512 | || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD)) | |
3513 | /* We have a new-style __tls_get_addr call with a marker | |
3514 | reloc. */ | |
3515 | ; | |
3516 | else | |
3517 | /* Mark this section as having an old-style call. */ | |
3518 | sec->has_tls_get_addr_call = 1; | |
e054468f | 3519 | } |
727fc41e | 3520 | |
25dbc73a AM |
3521 | switch (r_type) |
3522 | { | |
727fc41e AM |
3523 | case R_PPC_TLSGD: |
3524 | case R_PPC_TLSLD: | |
3525 | /* These special tls relocs tie a call to __tls_get_addr with | |
3526 | its parameter symbol. */ | |
3527 | break; | |
3528 | ||
25dbc73a AM |
3529 | case R_PPC_GOT_TLSLD16: |
3530 | case R_PPC_GOT_TLSLD16_LO: | |
3531 | case R_PPC_GOT_TLSLD16_HI: | |
3532 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
3533 | tls_type = TLS_TLS | TLS_LD; |
3534 | goto dogottls; | |
252b5132 | 3535 | |
25dbc73a AM |
3536 | case R_PPC_GOT_TLSGD16: |
3537 | case R_PPC_GOT_TLSGD16_LO: | |
3538 | case R_PPC_GOT_TLSGD16_HI: | |
3539 | case R_PPC_GOT_TLSGD16_HA: | |
3540 | tls_type = TLS_TLS | TLS_GD; | |
3541 | goto dogottls; | |
3542 | ||
3543 | case R_PPC_GOT_TPREL16: | |
3544 | case R_PPC_GOT_TPREL16_LO: | |
3545 | case R_PPC_GOT_TPREL16_HI: | |
3546 | case R_PPC_GOT_TPREL16_HA: | |
1d483afe | 3547 | if (!info->executable) |
25dbc73a AM |
3548 | info->flags |= DF_STATIC_TLS; |
3549 | tls_type = TLS_TLS | TLS_TPREL; | |
3550 | goto dogottls; | |
3551 | ||
3552 | case R_PPC_GOT_DTPREL16: | |
3553 | case R_PPC_GOT_DTPREL16_LO: | |
3554 | case R_PPC_GOT_DTPREL16_HI: | |
3555 | case R_PPC_GOT_DTPREL16_HA: | |
3556 | tls_type = TLS_TLS | TLS_DTPREL; | |
3557 | dogottls: | |
3558 | sec->has_tls_reloc = 1; | |
3559 | /* Fall thru */ | |
252b5132 | 3560 | |
25dbc73a AM |
3561 | /* GOT16 relocations */ |
3562 | case R_PPC_GOT16: | |
3563 | case R_PPC_GOT16_LO: | |
3564 | case R_PPC_GOT16_HI: | |
3565 | case R_PPC_GOT16_HA: | |
3566 | /* This symbol requires a global offset table entry. */ | |
3567 | if (htab->got == NULL) | |
3568 | { | |
3569 | if (htab->elf.dynobj == NULL) | |
3570 | htab->elf.dynobj = abfd; | |
3571 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
3572 | return FALSE; | |
3573 | } | |
3574 | if (h != NULL) | |
3575 | { | |
3576 | h->got.refcount += 1; | |
3577 | ppc_elf_hash_entry (h)->tls_mask |= tls_type; | |
3578 | } | |
3579 | else | |
3580 | /* This is a global offset table entry for a local symbol. */ | |
3581 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)) | |
3582 | return FALSE; | |
91e21fb7 AM |
3583 | |
3584 | /* We may also need a plt entry if the symbol turns out to be | |
3585 | an ifunc. */ | |
3586 | if (h != NULL && !info->shared) | |
3587 | { | |
3588 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) | |
3589 | return FALSE; | |
3590 | } | |
25dbc73a | 3591 | break; |
252b5132 | 3592 | |
25dbc73a AM |
3593 | /* Indirect .sdata relocation. */ |
3594 | case R_PPC_EMB_SDAI16: | |
3595 | if (info->shared) | |
3596 | { | |
3597 | bad_shared_reloc (abfd, r_type); | |
3598 | return FALSE; | |
3599 | } | |
c9a2f333 AM |
3600 | if (htab->sdata[0].section == NULL |
3601 | && !ppc_elf_create_linker_section (abfd, info, 0, | |
3602 | &htab->sdata[0])) | |
3603 | return FALSE; | |
76750a2f AM |
3604 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0], |
3605 | h, rel)) | |
25dbc73a | 3606 | return FALSE; |
046183de AM |
3607 | if (h != NULL) |
3608 | { | |
3609 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3610 | h->non_got_ref = TRUE; | |
3611 | } | |
25dbc73a | 3612 | break; |
252b5132 | 3613 | |
25dbc73a AM |
3614 | /* Indirect .sdata2 relocation. */ |
3615 | case R_PPC_EMB_SDA2I16: | |
3616 | if (info->shared) | |
3617 | { | |
3618 | bad_shared_reloc (abfd, r_type); | |
3619 | return FALSE; | |
3620 | } | |
c9a2f333 AM |
3621 | if (htab->sdata[1].section == NULL |
3622 | && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY, | |
3623 | &htab->sdata[1])) | |
3624 | return FALSE; | |
76750a2f AM |
3625 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1], |
3626 | h, rel)) | |
25dbc73a | 3627 | return FALSE; |
046183de AM |
3628 | if (h != NULL) |
3629 | { | |
3630 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3631 | h->non_got_ref = TRUE; | |
3632 | } | |
25dbc73a | 3633 | break; |
252b5132 | 3634 | |
25dbc73a | 3635 | case R_PPC_SDAREL16: |
046183de AM |
3636 | if (info->shared) |
3637 | { | |
3638 | bad_shared_reloc (abfd, r_type); | |
3639 | return FALSE; | |
3640 | } | |
3641 | if (htab->sdata[0].sym == NULL | |
3642 | && !create_sdata_sym (htab, &htab->sdata[0])) | |
3643 | return FALSE; | |
3644 | if (h != NULL) | |
3645 | { | |
3646 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3647 | h->non_got_ref = TRUE; | |
3648 | } | |
3649 | break; | |
3650 | ||
25dbc73a | 3651 | case R_PPC_EMB_SDA2REL: |
046183de AM |
3652 | if (info->shared) |
3653 | { | |
3654 | bad_shared_reloc (abfd, r_type); | |
3655 | return FALSE; | |
3656 | } | |
3657 | if (htab->sdata[1].sym == NULL | |
3658 | && !create_sdata_sym (htab, &htab->sdata[1])) | |
3659 | return FALSE; | |
3660 | if (h != NULL) | |
3661 | { | |
3662 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3663 | h->non_got_ref = TRUE; | |
3664 | } | |
3665 | break; | |
3666 | ||
25dbc73a AM |
3667 | case R_PPC_EMB_SDA21: |
3668 | case R_PPC_EMB_RELSDA: | |
046183de AM |
3669 | if (info->shared) |
3670 | { | |
3671 | bad_shared_reloc (abfd, r_type); | |
3672 | return FALSE; | |
3673 | } | |
3674 | if (htab->sdata[0].sym == NULL | |
3675 | && !create_sdata_sym (htab, &htab->sdata[0])) | |
3676 | return FALSE; | |
3677 | if (htab->sdata[1].sym == NULL | |
3678 | && !create_sdata_sym (htab, &htab->sdata[1])) | |
3679 | return FALSE; | |
3680 | if (h != NULL) | |
3681 | { | |
3682 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3683 | h->non_got_ref = TRUE; | |
3684 | } | |
3685 | break; | |
3686 | ||
25dbc73a AM |
3687 | case R_PPC_EMB_NADDR32: |
3688 | case R_PPC_EMB_NADDR16: | |
3689 | case R_PPC_EMB_NADDR16_LO: | |
3690 | case R_PPC_EMB_NADDR16_HI: | |
3691 | case R_PPC_EMB_NADDR16_HA: | |
3692 | if (info->shared) | |
3693 | { | |
3694 | bad_shared_reloc (abfd, r_type); | |
3695 | return FALSE; | |
3696 | } | |
4dc4a9a5 | 3697 | if (h != NULL) |
046183de | 3698 | h->non_got_ref = TRUE; |
25dbc73a | 3699 | break; |
252b5132 | 3700 | |
25dbc73a | 3701 | case R_PPC_PLTREL24: |
de972ffa | 3702 | if (h == NULL) |
6d78d0b9 AM |
3703 | break; |
3704 | /* Fall through */ | |
3705 | case R_PPC_PLT32: | |
25dbc73a AM |
3706 | case R_PPC_PLTREL32: |
3707 | case R_PPC_PLT16_LO: | |
3708 | case R_PPC_PLT16_HI: | |
3709 | case R_PPC_PLT16_HA: | |
3710 | #ifdef DEBUG | |
3711 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
3712 | #endif | |
3713 | /* This symbol requires a procedure linkage table entry. We | |
3714 | actually build the entry in finish_dynamic_symbol, | |
3715 | because this might be a case of linking PIC code without | |
3716 | linking in any dynamic objects, in which case we don't | |
3717 | need to generate a procedure linkage table after all. */ | |
7619e7c7 | 3718 | |
25dbc73a AM |
3719 | if (h == NULL) |
3720 | { | |
3721 | /* It does not make sense to have a procedure linkage | |
3722 | table entry for a local symbol. */ | |
3723 | (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against " | |
3724 | "local symbol"), | |
3725 | abfd, | |
3726 | sec, | |
3727 | (long) rel->r_offset, | |
3728 | ppc_elf_howto_table[r_type]->name); | |
3729 | bfd_set_error (bfd_error_bad_value); | |
3730 | return FALSE; | |
3731 | } | |
a6aa5195 AM |
3732 | else |
3733 | { | |
016687f8 | 3734 | bfd_vma addend = 0; |
ee05f2fe | 3735 | |
016687f8 AM |
3736 | if (r_type == R_PPC_PLTREL24) |
3737 | { | |
3738 | ppc_elf_tdata (abfd)->makes_plt_call = 1; | |
a877a2b6 AM |
3739 | if (info->shared) |
3740 | addend = rel->r_addend; | |
016687f8 | 3741 | } |
a6aa5195 | 3742 | h->needs_plt = 1; |
3ec01793 AM |
3743 | if (!update_plt_info (abfd, &h->plt.plist, |
3744 | addend < 32768 ? NULL : got2, addend)) | |
a6aa5195 AM |
3745 | return FALSE; |
3746 | } | |
25dbc73a | 3747 | break; |
ee05f2fe | 3748 | |
25dbc73a AM |
3749 | /* The following relocations don't need to propagate the |
3750 | relocation if linking a shared object since they are | |
3751 | section relative. */ | |
3752 | case R_PPC_SECTOFF: | |
3753 | case R_PPC_SECTOFF_LO: | |
3754 | case R_PPC_SECTOFF_HI: | |
3755 | case R_PPC_SECTOFF_HA: | |
3756 | case R_PPC_DTPREL16: | |
3757 | case R_PPC_DTPREL16_LO: | |
3758 | case R_PPC_DTPREL16_HI: | |
3759 | case R_PPC_DTPREL16_HA: | |
3760 | case R_PPC_TOC16: | |
3761 | break; | |
252b5132 | 3762 | |
d7128ce4 AM |
3763 | case R_PPC_REL16: |
3764 | case R_PPC_REL16_LO: | |
3765 | case R_PPC_REL16_HI: | |
3766 | case R_PPC_REL16_HA: | |
016687f8 | 3767 | ppc_elf_tdata (abfd)->has_rel16 = 1; |
d7128ce4 AM |
3768 | break; |
3769 | ||
a6aa5195 | 3770 | /* These are just markers. */ |
25dbc73a AM |
3771 | case R_PPC_TLS: |
3772 | case R_PPC_EMB_MRKREF: | |
3773 | case R_PPC_NONE: | |
3774 | case R_PPC_max: | |
ceaf50a2 AM |
3775 | case R_PPC_RELAX32: |
3776 | case R_PPC_RELAX32PC: | |
3777 | case R_PPC_RELAX32_PLT: | |
3778 | case R_PPC_RELAX32PC_PLT: | |
25dbc73a | 3779 | break; |
252b5132 | 3780 | |
25dbc73a AM |
3781 | /* These should only appear in dynamic objects. */ |
3782 | case R_PPC_COPY: | |
3783 | case R_PPC_GLOB_DAT: | |
3784 | case R_PPC_JMP_SLOT: | |
3785 | case R_PPC_RELATIVE: | |
e054468f | 3786 | case R_PPC_IRELATIVE: |
25dbc73a | 3787 | break; |
252b5132 | 3788 | |
25dbc73a AM |
3789 | /* These aren't handled yet. We'll report an error later. */ |
3790 | case R_PPC_ADDR30: | |
3791 | case R_PPC_EMB_RELSEC16: | |
3792 | case R_PPC_EMB_RELST_LO: | |
3793 | case R_PPC_EMB_RELST_HI: | |
3794 | case R_PPC_EMB_RELST_HA: | |
3795 | case R_PPC_EMB_BIT_FLD: | |
3796 | break; | |
252b5132 | 3797 | |
25dbc73a AM |
3798 | /* This refers only to functions defined in the shared library. */ |
3799 | case R_PPC_LOCAL24PC: | |
727fc41e | 3800 | if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET) |
016687f8 AM |
3801 | { |
3802 | htab->plt_type = PLT_OLD; | |
3803 | htab->old_bfd = abfd; | |
3804 | } | |
25dbc73a | 3805 | break; |
252b5132 | 3806 | |
25dbc73a AM |
3807 | /* This relocation describes the C++ object vtable hierarchy. |
3808 | Reconstruct it for later use during GC. */ | |
3809 | case R_PPC_GNU_VTINHERIT: | |
3810 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
3811 | return FALSE; | |
3812 | break; | |
252b5132 | 3813 | |
25dbc73a AM |
3814 | /* This relocation describes which C++ vtable entries are actually |
3815 | used. Record for later use during GC. */ | |
3816 | case R_PPC_GNU_VTENTRY: | |
d17e0c6e JB |
3817 | BFD_ASSERT (h != NULL); |
3818 | if (h != NULL | |
3819 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
25dbc73a AM |
3820 | return FALSE; |
3821 | break; | |
252b5132 | 3822 | |
25dbc73a AM |
3823 | /* We shouldn't really be seeing these. */ |
3824 | case R_PPC_TPREL32: | |
1d483afe AM |
3825 | case R_PPC_TPREL16: |
3826 | case R_PPC_TPREL16_LO: | |
3827 | case R_PPC_TPREL16_HI: | |
3828 | case R_PPC_TPREL16_HA: | |
3829 | if (!info->executable) | |
25dbc73a AM |
3830 | info->flags |= DF_STATIC_TLS; |
3831 | goto dodyn; | |
252b5132 | 3832 | |
25dbc73a AM |
3833 | /* Nor these. */ |
3834 | case R_PPC_DTPMOD32: | |
3835 | case R_PPC_DTPREL32: | |
3836 | goto dodyn; | |
252b5132 | 3837 | |
9edfd1af AM |
3838 | case R_PPC_REL32: |
3839 | if (h == NULL | |
3840 | && got2 != NULL | |
3841 | && (sec->flags & SEC_CODE) != 0 | |
a877a2b6 | 3842 | && info->shared |
4a3dc543 | 3843 | && htab->plt_type == PLT_UNSET) |
9edfd1af AM |
3844 | { |
3845 | /* Old -fPIC gcc code has .long LCTOC1-LCFx just before | |
3846 | the start of a function, which assembles to a REL32 | |
3847 | reference to .got2. If we detect one of these, then | |
3848 | force the old PLT layout because the linker cannot | |
3849 | reliably deduce the GOT pointer value needed for | |
3850 | PLT call stubs. */ | |
3851 | asection *s; | |
87d72d41 | 3852 | Elf_Internal_Sym *isym; |
9edfd1af | 3853 | |
87d72d41 AM |
3854 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3855 | abfd, r_symndx); | |
3856 | if (isym == NULL) | |
3857 | return FALSE; | |
3858 | ||
3859 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
9edfd1af | 3860 | if (s == got2) |
016687f8 AM |
3861 | { |
3862 | htab->plt_type = PLT_OLD; | |
3863 | htab->old_bfd = abfd; | |
3864 | } | |
9edfd1af | 3865 | } |
7123df0e | 3866 | if (h == NULL || h == htab->elf.hgot) |
fd38b44c | 3867 | break; |
625af618 AM |
3868 | /* fall through */ |
3869 | ||
3870 | case R_PPC_ADDR32: | |
3871 | case R_PPC_ADDR16: | |
3872 | case R_PPC_ADDR16_LO: | |
3873 | case R_PPC_ADDR16_HI: | |
3874 | case R_PPC_ADDR16_HA: | |
3875 | case R_PPC_UADDR32: | |
3876 | case R_PPC_UADDR16: | |
3877 | if (h != NULL && !info->shared) | |
3878 | { | |
3879 | /* We may need a plt entry if the symbol turns out to be | |
3880 | a function defined in a dynamic object. */ | |
3ec01793 | 3881 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
625af618 AM |
3882 | return FALSE; |
3883 | ||
3884 | /* We may need a copy reloc too. */ | |
3885 | h->non_got_ref = 1; | |
3886 | h->pointer_equality_needed = 1; | |
3887 | } | |
3888 | goto dodyn; | |
9edfd1af | 3889 | |
25dbc73a AM |
3890 | case R_PPC_REL24: |
3891 | case R_PPC_REL14: | |
3892 | case R_PPC_REL14_BRTAKEN: | |
3893 | case R_PPC_REL14_BRNTAKEN: | |
d7128ce4 | 3894 | if (h == NULL) |
25dbc73a | 3895 | break; |
7123df0e | 3896 | if (h == htab->elf.hgot) |
d7128ce4 | 3897 | { |
7123df0e | 3898 | if (htab->plt_type == PLT_UNSET) |
016687f8 AM |
3899 | { |
3900 | htab->plt_type = PLT_OLD; | |
3901 | htab->old_bfd = abfd; | |
3902 | } | |
d7128ce4 AM |
3903 | break; |
3904 | } | |
25dbc73a | 3905 | /* fall through */ |
ee05f2fe | 3906 | |
25dbc73a | 3907 | case R_PPC_ADDR24: |
25dbc73a AM |
3908 | case R_PPC_ADDR14: |
3909 | case R_PPC_ADDR14_BRTAKEN: | |
3910 | case R_PPC_ADDR14_BRNTAKEN: | |
25dbc73a AM |
3911 | if (h != NULL && !info->shared) |
3912 | { | |
3913 | /* We may need a plt entry if the symbol turns out to be | |
3914 | a function defined in a dynamic object. */ | |
e054468f | 3915 | h->needs_plt = 1; |
de972ffa | 3916 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
a6aa5195 | 3917 | return FALSE; |
625af618 | 3918 | break; |
25dbc73a | 3919 | } |
7619e7c7 | 3920 | |
25dbc73a AM |
3921 | dodyn: |
3922 | /* If we are creating a shared library, and this is a reloc | |
3923 | against a global symbol, or a non PC relative reloc | |
3924 | against a local symbol, then we need to copy the reloc | |
3925 | into the shared library. However, if we are linking with | |
3926 | -Bsymbolic, we do not need to copy a reloc against a | |
3927 | global symbol which is defined in an object we are | |
3928 | including in the link (i.e., DEF_REGULAR is set). At | |
3929 | this point we have not seen all the input files, so it is | |
3930 | possible that DEF_REGULAR is not set now but will be set | |
3931 | later (it is never cleared). In case of a weak definition, | |
3932 | DEF_REGULAR may be cleared later by a strong definition in | |
3933 | a shared library. We account for that possibility below by | |
3934 | storing information in the dyn_relocs field of the hash | |
3935 | table entry. A similar situation occurs when creating | |
3936 | shared libraries and symbol visibility changes render the | |
3937 | symbol local. | |
7619e7c7 | 3938 | |
25dbc73a AM |
3939 | If on the other hand, we are creating an executable, we |
3940 | may need to keep relocations for symbols satisfied by a | |
3941 | dynamic library if we manage to avoid copy relocs for the | |
3942 | symbol. */ | |
3943 | if ((info->shared | |
1d483afe | 3944 | && (must_be_dyn_reloc (info, r_type) |
25dbc73a AM |
3945 | || (h != NULL |
3946 | && (! info->symbolic | |
3947 | || h->root.type == bfd_link_hash_defweak | |
3948 | || !h->def_regular)))) | |
3949 | || (ELIMINATE_COPY_RELOCS | |
3950 | && !info->shared | |
25dbc73a AM |
3951 | && h != NULL |
3952 | && (h->root.type == bfd_link_hash_defweak | |
de972ffa | 3953 | || !h->def_regular))) |
25dbc73a AM |
3954 | { |
3955 | struct ppc_elf_dyn_relocs *p; | |
3956 | struct ppc_elf_dyn_relocs **head; | |
7619e7c7 | 3957 | |
25dbc73a AM |
3958 | #ifdef DEBUG |
3959 | fprintf (stderr, | |
3960 | "ppc_elf_check_relocs needs to " | |
3961 | "create relocation for %s\n", | |
3962 | (h && h->root.root.string | |
3963 | ? h->root.root.string : "<unknown>")); | |
3964 | #endif | |
3965 | if (sreloc == NULL) | |
3966 | { | |
c9a2f333 AM |
3967 | if (htab->elf.dynobj == NULL) |
3968 | htab->elf.dynobj = abfd; | |
83bac4b0 NC |
3969 | |
3970 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
3971 | (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE); | |
3972 | ||
25dbc73a | 3973 | if (sreloc == NULL) |
83bac4b0 | 3974 | return FALSE; |
25dbc73a | 3975 | } |
7619e7c7 | 3976 | |
25dbc73a AM |
3977 | /* If this is a global symbol, we count the number of |
3978 | relocations we need for this symbol. */ | |
3979 | if (h != NULL) | |
3980 | { | |
3981 | head = &ppc_elf_hash_entry (h)->dyn_relocs; | |
3982 | } | |
3983 | else | |
3984 | { | |
3985 | /* Track dynamic relocs needed for local syms too. | |
3986 | We really need local syms available to do this | |
3987 | easily. Oh well. */ | |
25dbc73a | 3988 | asection *s; |
6edfbbad | 3989 | void *vpp; |
87d72d41 | 3990 | Elf_Internal_Sym *isym; |
6edfbbad | 3991 | |
87d72d41 AM |
3992 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3993 | abfd, r_symndx); | |
3994 | if (isym == NULL) | |
25dbc73a | 3995 | return FALSE; |
7fce784e | 3996 | |
87d72d41 AM |
3997 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
3998 | if (s == NULL) | |
3999 | s = sec; | |
4000 | ||
6edfbbad DJ |
4001 | vpp = &elf_section_data (s)->local_dynrel; |
4002 | head = (struct ppc_elf_dyn_relocs **) vpp; | |
25dbc73a | 4003 | } |
7fce784e | 4004 | |
25dbc73a AM |
4005 | p = *head; |
4006 | if (p == NULL || p->sec != sec) | |
4007 | { | |
4008 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); | |
4009 | if (p == NULL) | |
4010 | return FALSE; | |
4011 | p->next = *head; | |
4012 | *head = p; | |
4013 | p->sec = sec; | |
4014 | p->count = 0; | |
4015 | p->pc_count = 0; | |
4016 | } | |
4017 | ||
4018 | p->count += 1; | |
1d483afe | 4019 | if (!must_be_dyn_reloc (info, r_type)) |
25dbc73a | 4020 | p->pc_count += 1; |
7619e7c7 | 4021 | } |
25dbc73a AM |
4022 | |
4023 | break; | |
7619e7c7 AM |
4024 | } |
4025 | } | |
ee05f2fe | 4026 | |
25dbc73a AM |
4027 | return TRUE; |
4028 | } | |
4029 | \f | |
34c8bcba JM |
4030 | |
4031 | /* Merge object attributes from IBFD into OBFD. Raise an error if | |
4032 | there are conflicting attributes. */ | |
4033 | static bfd_boolean | |
4034 | ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd) | |
4035 | { | |
c6e65352 DJ |
4036 | obj_attribute *in_attr, *in_attrs; |
4037 | obj_attribute *out_attr, *out_attrs; | |
34c8bcba JM |
4038 | |
4039 | if (!elf_known_obj_attributes_proc (obfd)[0].i) | |
4040 | { | |
4041 | /* This is the first object. Copy the attributes. */ | |
4042 | _bfd_elf_copy_obj_attributes (ibfd, obfd); | |
4043 | ||
4044 | /* Use the Tag_null value to indicate the attributes have been | |
4045 | initialized. */ | |
4046 | elf_known_obj_attributes_proc (obfd)[0].i = 1; | |
4047 | ||
4048 | return TRUE; | |
4049 | } | |
4050 | ||
c6e65352 DJ |
4051 | in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU]; |
4052 | out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU]; | |
4053 | ||
34c8bcba JM |
4054 | /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge |
4055 | non-conflicting ones. */ | |
c6e65352 DJ |
4056 | in_attr = &in_attrs[Tag_GNU_Power_ABI_FP]; |
4057 | out_attr = &out_attrs[Tag_GNU_Power_ABI_FP]; | |
4058 | if (in_attr->i != out_attr->i) | |
34c8bcba | 4059 | { |
c6e65352 DJ |
4060 | out_attr->type = 1; |
4061 | if (out_attr->i == 0) | |
4062 | out_attr->i = in_attr->i; | |
4063 | else if (in_attr->i == 0) | |
34c8bcba | 4064 | ; |
c6e65352 | 4065 | else if (out_attr->i == 1 && in_attr->i == 2) |
34c8bcba JM |
4066 | _bfd_error_handler |
4067 | (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd); | |
3c7b9897 AM |
4068 | else if (out_attr->i == 1 && in_attr->i == 3) |
4069 | _bfd_error_handler | |
4070 | (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"), | |
4071 | obfd, ibfd); | |
4072 | else if (out_attr->i == 3 && in_attr->i == 1) | |
4073 | _bfd_error_handler | |
4074 | (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"), | |
4075 | ibfd, obfd); | |
4076 | else if (out_attr->i == 3 && in_attr->i == 2) | |
4077 | _bfd_error_handler | |
4078 | (_("Warning: %B uses soft float, %B uses single-precision hard float"), | |
4079 | ibfd, obfd); | |
4080 | else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3)) | |
34c8bcba JM |
4081 | _bfd_error_handler |
4082 | (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd); | |
3c7b9897 | 4083 | else if (in_attr->i > 3) |
34c8bcba JM |
4084 | _bfd_error_handler |
4085 | (_("Warning: %B uses unknown floating point ABI %d"), ibfd, | |
c6e65352 | 4086 | in_attr->i); |
34c8bcba JM |
4087 | else |
4088 | _bfd_error_handler | |
4089 | (_("Warning: %B uses unknown floating point ABI %d"), obfd, | |
c6e65352 DJ |
4090 | out_attr->i); |
4091 | } | |
4092 | ||
4093 | /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and | |
4094 | merge non-conflicting ones. */ | |
4095 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector]; | |
4096 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector]; | |
4097 | if (in_attr->i != out_attr->i) | |
4098 | { | |
4099 | const char *in_abi = NULL, *out_abi = NULL; | |
4100 | ||
4101 | switch (in_attr->i) | |
4102 | { | |
4103 | case 1: in_abi = "generic"; break; | |
4104 | case 2: in_abi = "AltiVec"; break; | |
4105 | case 3: in_abi = "SPE"; break; | |
4106 | } | |
4107 | ||
4108 | switch (out_attr->i) | |
4109 | { | |
4110 | case 1: out_abi = "generic"; break; | |
4111 | case 2: out_abi = "AltiVec"; break; | |
4112 | case 3: out_abi = "SPE"; break; | |
4113 | } | |
4114 | ||
4115 | out_attr->type = 1; | |
4116 | if (out_attr->i == 0) | |
4117 | out_attr->i = in_attr->i; | |
4118 | else if (in_attr->i == 0) | |
4119 | ; | |
4120 | /* For now, allow generic to transition to AltiVec or SPE | |
4121 | without a warning. If GCC marked files with their stack | |
4122 | alignment and used don't-care markings for files which are | |
4123 | not affected by the vector ABI, we could warn about this | |
4124 | case too. */ | |
4125 | else if (out_attr->i == 1) | |
4126 | out_attr->i = in_attr->i; | |
4127 | else if (in_attr->i == 1) | |
4128 | ; | |
4129 | else if (in_abi == NULL) | |
4130 | _bfd_error_handler | |
4131 | (_("Warning: %B uses unknown vector ABI %d"), ibfd, | |
4132 | in_attr->i); | |
4133 | else if (out_abi == NULL) | |
4134 | _bfd_error_handler | |
4135 | (_("Warning: %B uses unknown vector ABI %d"), obfd, | |
4136 | in_attr->i); | |
4137 | else | |
4138 | _bfd_error_handler | |
4139 | (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""), | |
4140 | ibfd, obfd, in_abi, out_abi); | |
34c8bcba JM |
4141 | } |
4142 | ||
f82e0623 NF |
4143 | /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes |
4144 | and merge non-conflicting ones. */ | |
4145 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4146 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4147 | if (in_attr->i != out_attr->i) | |
4148 | { | |
4149 | out_attr->type = 1; | |
4150 | if (out_attr->i == 0) | |
4151 | out_attr->i = in_attr->i; | |
4152 | else if (in_attr->i == 0) | |
4153 | ; | |
4154 | else if (out_attr->i == 1 && in_attr->i == 2) | |
4155 | _bfd_error_handler | |
4156 | (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd); | |
4157 | else if (out_attr->i == 2 && in_attr->i == 1) | |
4158 | _bfd_error_handler | |
4159 | (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd); | |
4160 | else if (in_attr->i > 2) | |
4161 | _bfd_error_handler | |
4162 | (_("Warning: %B uses unknown small structure return convention %d"), ibfd, | |
4163 | in_attr->i); | |
4164 | else | |
4165 | _bfd_error_handler | |
4166 | (_("Warning: %B uses unknown small structure return convention %d"), obfd, | |
4167 | out_attr->i); | |
4168 | } | |
4169 | ||
34c8bcba JM |
4170 | /* Merge Tag_compatibility attributes and any common GNU ones. */ |
4171 | _bfd_elf_merge_object_attributes (ibfd, obfd); | |
4172 | ||
4173 | return TRUE; | |
4174 | } | |
4175 | ||
8853c3d3 AM |
4176 | /* Merge backend specific data from an object file to the output |
4177 | object file when linking. */ | |
4178 | ||
4179 | static bfd_boolean | |
4180 | ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) | |
4181 | { | |
4182 | flagword old_flags; | |
4183 | flagword new_flags; | |
4184 | bfd_boolean error; | |
4185 | ||
0c8d6e5c | 4186 | if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd)) |
8853c3d3 AM |
4187 | return TRUE; |
4188 | ||
4189 | /* Check if we have the same endianess. */ | |
4190 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) | |
4191 | return FALSE; | |
4192 | ||
34c8bcba JM |
4193 | if (!ppc_elf_merge_obj_attributes (ibfd, obfd)) |
4194 | return FALSE; | |
4195 | ||
8853c3d3 AM |
4196 | new_flags = elf_elfheader (ibfd)->e_flags; |
4197 | old_flags = elf_elfheader (obfd)->e_flags; | |
4198 | if (!elf_flags_init (obfd)) | |
4199 | { | |
4200 | /* First call, no flags set. */ | |
4201 | elf_flags_init (obfd) = TRUE; | |
4202 | elf_elfheader (obfd)->e_flags = new_flags; | |
4203 | } | |
4204 | ||
4205 | /* Compatible flags are ok. */ | |
4206 | else if (new_flags == old_flags) | |
4207 | ; | |
4208 | ||
4209 | /* Incompatible flags. */ | |
4210 | else | |
4211 | { | |
4212 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib | |
4213 | to be linked with either. */ | |
4214 | error = FALSE; | |
4215 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 | |
4216 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
4217 | { | |
4218 | error = TRUE; | |
4219 | (*_bfd_error_handler) | |
4220 | (_("%B: compiled with -mrelocatable and linked with " | |
4221 | "modules compiled normally"), ibfd); | |
4222 | } | |
4223 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
4224 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
4225 | { | |
4226 | error = TRUE; | |
4227 | (*_bfd_error_handler) | |
4228 | (_("%B: compiled normally and linked with " | |
4229 | "modules compiled with -mrelocatable"), ibfd); | |
4230 | } | |
4231 | ||
4232 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
4233 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
4234 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
4235 | ||
4236 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
4237 | but each input file is either -mrelocatable or -mrelocatable-lib. */ | |
4238 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) | |
4239 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
4240 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
4241 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
4242 | ||
4243 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if | |
4244 | any module uses it. */ | |
4245 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); | |
4246 | ||
4247 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4248 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4249 | ||
4250 | /* Warn about any other mismatches. */ | |
4251 | if (new_flags != old_flags) | |
4252 | { | |
4253 | error = TRUE; | |
4254 | (*_bfd_error_handler) | |
4255 | (_("%B: uses different e_flags (0x%lx) fields " | |
4256 | "than previous modules (0x%lx)"), | |
4257 | ibfd, (long) new_flags, (long) old_flags); | |
4258 | } | |
4259 | ||
4260 | if (error) | |
4261 | { | |
4262 | bfd_set_error (bfd_error_bad_value); | |
4263 | return FALSE; | |
4264 | } | |
4265 | } | |
4266 | ||
4267 | return TRUE; | |
4268 | } | |
4269 | \f | |
d7128ce4 AM |
4270 | /* Choose which PLT scheme to use, and set .plt flags appropriately. |
4271 | Returns -1 on error, 0 for old PLT, 1 for new PLT. */ | |
4272 | int | |
4273 | ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED, | |
4274 | struct bfd_link_info *info, | |
016687f8 | 4275 | enum ppc_elf_plt_type plt_style, |
0ba07910 | 4276 | int emit_stub_syms) |
d7128ce4 AM |
4277 | { |
4278 | struct ppc_elf_link_hash_table *htab; | |
9d8504b1 | 4279 | flagword flags; |
d7128ce4 AM |
4280 | |
4281 | htab = ppc_elf_hash_table (info); | |
4a3dc543 RS |
4282 | |
4283 | if (htab->plt_type == PLT_UNSET) | |
016687f8 AM |
4284 | { |
4285 | if (plt_style == PLT_OLD) | |
4286 | htab->plt_type = PLT_OLD; | |
4287 | else | |
4288 | { | |
4289 | bfd *ibfd; | |
4290 | enum ppc_elf_plt_type plt_type = plt_style; | |
4291 | ||
4292 | /* Look through the reloc flags left by ppc_elf_check_relocs. | |
4293 | Use the old style bss plt if a file makes plt calls | |
4294 | without using the new relocs, and if ld isn't given | |
4295 | --secure-plt and we never see REL16 relocs. */ | |
4296 | if (plt_type == PLT_UNSET) | |
4297 | plt_type = PLT_OLD; | |
60b31e8d | 4298 | for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next) |
0c8d6e5c | 4299 | if (is_ppc_elf (ibfd)) |
016687f8 AM |
4300 | { |
4301 | if (ppc_elf_tdata (ibfd)->has_rel16) | |
4302 | plt_type = PLT_NEW; | |
4303 | else if (ppc_elf_tdata (ibfd)->makes_plt_call) | |
4304 | { | |
4305 | plt_type = PLT_OLD; | |
4306 | htab->old_bfd = ibfd; | |
4307 | break; | |
4308 | } | |
4309 | } | |
4310 | htab->plt_type = plt_type; | |
4311 | } | |
4312 | } | |
4313 | if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW) | |
4314 | info->callbacks->info (_("Using bss-plt due to %B"), htab->old_bfd); | |
d7128ce4 | 4315 | |
0ba07910 AM |
4316 | htab->emit_stub_syms = emit_stub_syms; |
4317 | ||
4a3dc543 | 4318 | BFD_ASSERT (htab->plt_type != PLT_VXWORKS); |
9d8504b1 | 4319 | |
4a3dc543 | 4320 | if (htab->plt_type == PLT_NEW) |
9d8504b1 PB |
4321 | { |
4322 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
4323 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
86b9da88 AM |
4324 | |
4325 | /* The new PLT is a loaded section. */ | |
4326 | if (htab->plt != NULL | |
4327 | && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags)) | |
4328 | return -1; | |
4329 | ||
4330 | /* The new GOT is not executable. */ | |
4331 | if (htab->got != NULL | |
4332 | && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags)) | |
4333 | return -1; | |
d7128ce4 AM |
4334 | } |
4335 | else | |
4336 | { | |
4337 | /* Stop an unused .glink section from affecting .text alignment. */ | |
86b9da88 AM |
4338 | if (htab->glink != NULL |
4339 | && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0)) | |
4340 | return -1; | |
d7128ce4 | 4341 | } |
4a3dc543 | 4342 | return htab->plt_type == PLT_NEW; |
d7128ce4 AM |
4343 | } |
4344 | \f | |
25dbc73a AM |
4345 | /* Return the section that should be marked against GC for a given |
4346 | relocation. */ | |
586119b3 | 4347 | |
25dbc73a AM |
4348 | static asection * |
4349 | ppc_elf_gc_mark_hook (asection *sec, | |
07adf181 | 4350 | struct bfd_link_info *info, |
25dbc73a AM |
4351 | Elf_Internal_Rela *rel, |
4352 | struct elf_link_hash_entry *h, | |
4353 | Elf_Internal_Sym *sym) | |
4354 | { | |
4355 | if (h != NULL) | |
07adf181 AM |
4356 | switch (ELF32_R_TYPE (rel->r_info)) |
4357 | { | |
4358 | case R_PPC_GNU_VTINHERIT: | |
4359 | case R_PPC_GNU_VTENTRY: | |
4360 | return NULL; | |
4361 | } | |
4362 | ||
4363 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
25dbc73a | 4364 | } |
a876ecf9 | 4365 | |
25dbc73a AM |
4366 | /* Update the got, plt and dynamic reloc reference counts for the |
4367 | section being removed. */ | |
4368 | ||
4369 | static bfd_boolean | |
4370 | ppc_elf_gc_sweep_hook (bfd *abfd, | |
4371 | struct bfd_link_info *info, | |
4372 | asection *sec, | |
4373 | const Elf_Internal_Rela *relocs) | |
4374 | { | |
4375 | struct ppc_elf_link_hash_table *htab; | |
4376 | Elf_Internal_Shdr *symtab_hdr; | |
4377 | struct elf_link_hash_entry **sym_hashes; | |
4378 | bfd_signed_vma *local_got_refcounts; | |
4379 | const Elf_Internal_Rela *rel, *relend; | |
a6aa5195 | 4380 | asection *got2; |
25dbc73a | 4381 | |
7dda2462 TG |
4382 | if (info->relocatable) |
4383 | return TRUE; | |
4384 | ||
c87b5a93 AM |
4385 | if ((sec->flags & SEC_ALLOC) == 0) |
4386 | return TRUE; | |
4387 | ||
25dbc73a AM |
4388 | elf_section_data (sec)->local_dynrel = NULL; |
4389 | ||
4390 | htab = ppc_elf_hash_table (info); | |
0ffa91dd | 4391 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a AM |
4392 | sym_hashes = elf_sym_hashes (abfd); |
4393 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
a6aa5195 | 4394 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
4395 | |
4396 | relend = relocs + sec->reloc_count; | |
4397 | for (rel = relocs; rel < relend; rel++) | |
4398 | { | |
4399 | unsigned long r_symndx; | |
4400 | enum elf_ppc_reloc_type r_type; | |
4401 | struct elf_link_hash_entry *h = NULL; | |
4402 | ||
4403 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4404 | if (r_symndx >= symtab_hdr->sh_info) | |
a876ecf9 | 4405 | { |
25dbc73a AM |
4406 | struct ppc_elf_dyn_relocs **pp, *p; |
4407 | struct ppc_elf_link_hash_entry *eh; | |
4408 | ||
4409 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4410 | while (h->root.type == bfd_link_hash_indirect | |
4411 | || h->root.type == bfd_link_hash_warning) | |
4412 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4413 | eh = (struct ppc_elf_link_hash_entry *) h; | |
4414 | ||
4415 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4416 | if (p->sec == sec) | |
4417 | { | |
4418 | /* Everything must go for SEC. */ | |
4419 | *pp = p->next; | |
4420 | break; | |
4421 | } | |
a876ecf9 | 4422 | } |
ee05f2fe | 4423 | |
25dbc73a | 4424 | r_type = ELF32_R_TYPE (rel->r_info); |
de972ffa AM |
4425 | if (!htab->is_vxworks |
4426 | && h == NULL | |
4427 | && local_got_refcounts != NULL | |
4428 | && (!info->shared | |
4429 | || is_branch_reloc (r_type))) | |
e054468f | 4430 | { |
de972ffa AM |
4431 | struct plt_entry **local_plt = (struct plt_entry **) |
4432 | (local_got_refcounts + symtab_hdr->sh_info); | |
4433 | char *local_got_tls_masks = (char *) | |
4434 | (local_plt + symtab_hdr->sh_info); | |
4435 | if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0) | |
e054468f | 4436 | { |
de972ffa | 4437 | struct plt_entry **ifunc = local_plt + r_symndx; |
a877a2b6 AM |
4438 | bfd_vma addend = 0; |
4439 | struct plt_entry *ent; | |
4440 | ||
4441 | if (r_type == R_PPC_PLTREL24 && info->shared) | |
4442 | addend = rel->r_addend; | |
4443 | ent = find_plt_ent (ifunc, got2, addend); | |
e054468f AM |
4444 | if (ent->plt.refcount > 0) |
4445 | ent->plt.refcount -= 1; | |
4446 | continue; | |
4447 | } | |
4448 | } | |
4449 | ||
25dbc73a | 4450 | switch (r_type) |
ee05f2fe | 4451 | { |
25dbc73a AM |
4452 | case R_PPC_GOT_TLSLD16: |
4453 | case R_PPC_GOT_TLSLD16_LO: | |
4454 | case R_PPC_GOT_TLSLD16_HI: | |
4455 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
4456 | case R_PPC_GOT_TLSGD16: |
4457 | case R_PPC_GOT_TLSGD16_LO: | |
4458 | case R_PPC_GOT_TLSGD16_HI: | |
4459 | case R_PPC_GOT_TLSGD16_HA: | |
4460 | case R_PPC_GOT_TPREL16: | |
4461 | case R_PPC_GOT_TPREL16_LO: | |
4462 | case R_PPC_GOT_TPREL16_HI: | |
4463 | case R_PPC_GOT_TPREL16_HA: | |
4464 | case R_PPC_GOT_DTPREL16: | |
4465 | case R_PPC_GOT_DTPREL16_LO: | |
4466 | case R_PPC_GOT_DTPREL16_HI: | |
4467 | case R_PPC_GOT_DTPREL16_HA: | |
4468 | case R_PPC_GOT16: | |
4469 | case R_PPC_GOT16_LO: | |
4470 | case R_PPC_GOT16_HI: | |
4471 | case R_PPC_GOT16_HA: | |
4472 | if (h != NULL) | |
ee05f2fe | 4473 | { |
25dbc73a AM |
4474 | if (h->got.refcount > 0) |
4475 | h->got.refcount--; | |
91e21fb7 AM |
4476 | if (!info->shared) |
4477 | { | |
4478 | struct plt_entry *ent; | |
4479 | ||
4480 | ent = find_plt_ent (&h->plt.plist, NULL, 0); | |
4481 | if (ent->plt.refcount > 0) | |
4482 | ent->plt.refcount -= 1; | |
4483 | } | |
ee05f2fe | 4484 | } |
25dbc73a AM |
4485 | else if (local_got_refcounts != NULL) |
4486 | { | |
4487 | if (local_got_refcounts[r_symndx] > 0) | |
4488 | local_got_refcounts[r_symndx]--; | |
4489 | } | |
4490 | break; | |
ee05f2fe | 4491 | |
25dbc73a AM |
4492 | case R_PPC_REL24: |
4493 | case R_PPC_REL14: | |
4494 | case R_PPC_REL14_BRTAKEN: | |
4495 | case R_PPC_REL14_BRNTAKEN: | |
4496 | case R_PPC_REL32: | |
3b36f7e6 | 4497 | if (h == NULL || h == htab->elf.hgot) |
25dbc73a AM |
4498 | break; |
4499 | /* Fall thru */ | |
ee05f2fe | 4500 | |
25dbc73a AM |
4501 | case R_PPC_ADDR32: |
4502 | case R_PPC_ADDR24: | |
4503 | case R_PPC_ADDR16: | |
4504 | case R_PPC_ADDR16_LO: | |
4505 | case R_PPC_ADDR16_HI: | |
4506 | case R_PPC_ADDR16_HA: | |
4507 | case R_PPC_ADDR14: | |
4508 | case R_PPC_ADDR14_BRTAKEN: | |
4509 | case R_PPC_ADDR14_BRNTAKEN: | |
4510 | case R_PPC_UADDR32: | |
4511 | case R_PPC_UADDR16: | |
87538722 AM |
4512 | if (info->shared) |
4513 | break; | |
4514 | ||
25dbc73a AM |
4515 | case R_PPC_PLT32: |
4516 | case R_PPC_PLTREL24: | |
87538722 | 4517 | case R_PPC_PLTREL32: |
25dbc73a AM |
4518 | case R_PPC_PLT16_LO: |
4519 | case R_PPC_PLT16_HI: | |
4520 | case R_PPC_PLT16_HA: | |
4521 | if (h != NULL) | |
4522 | { | |
a877a2b6 AM |
4523 | bfd_vma addend = 0; |
4524 | struct plt_entry *ent; | |
4525 | ||
4526 | if (r_type == R_PPC_PLTREL24 && info->shared) | |
4527 | addend = rel->r_addend; | |
4528 | ent = find_plt_ent (&h->plt.plist, got2, addend); | |
a6aa5195 AM |
4529 | if (ent->plt.refcount > 0) |
4530 | ent->plt.refcount -= 1; | |
25dbc73a AM |
4531 | } |
4532 | break; | |
ee05f2fe | 4533 | |
25dbc73a AM |
4534 | default: |
4535 | break; | |
4536 | } | |
7fce784e | 4537 | } |
7fce784e AS |
4538 | return TRUE; |
4539 | } | |
25dbc73a | 4540 | \f |
3a71aa26 AM |
4541 | /* Set plt output section type, htab->tls_get_addr, and call the |
4542 | generic ELF tls_setup function. */ | |
7fce784e | 4543 | |
25dbc73a AM |
4544 | asection * |
4545 | ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) | |
7fce784e | 4546 | { |
25dbc73a | 4547 | struct ppc_elf_link_hash_table *htab; |
7fce784e | 4548 | |
25dbc73a | 4549 | htab = ppc_elf_hash_table (info); |
4a3dc543 | 4550 | if (htab->plt_type == PLT_NEW |
d7128ce4 AM |
4551 | && htab->plt != NULL |
4552 | && htab->plt->output_section != NULL) | |
4553 | { | |
4554 | elf_section_type (htab->plt->output_section) = SHT_PROGBITS; | |
4555 | elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE; | |
4556 | } | |
4557 | ||
25dbc73a AM |
4558 | htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
4559 | FALSE, FALSE, TRUE); | |
25dbc73a | 4560 | return _bfd_elf_tls_setup (obfd, info); |
7fce784e AS |
4561 | } |
4562 | ||
3a71aa26 AM |
4563 | /* Return TRUE iff REL is a branch reloc with a global symbol matching |
4564 | HASH. */ | |
4565 | ||
4566 | static bfd_boolean | |
4567 | branch_reloc_hash_match (const bfd *ibfd, | |
4568 | const Elf_Internal_Rela *rel, | |
4569 | const struct elf_link_hash_entry *hash) | |
4570 | { | |
4571 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); | |
4572 | enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info); | |
4573 | unsigned int r_symndx = ELF32_R_SYM (rel->r_info); | |
4574 | ||
e054468f | 4575 | if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type)) |
3a71aa26 AM |
4576 | { |
4577 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
4578 | struct elf_link_hash_entry *h; | |
4579 | ||
4580 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4581 | while (h->root.type == bfd_link_hash_indirect | |
4582 | || h->root.type == bfd_link_hash_warning) | |
4583 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4584 | if (h == hash) | |
4585 | return TRUE; | |
4586 | } | |
4587 | return FALSE; | |
4588 | } | |
4589 | ||
25dbc73a AM |
4590 | /* Run through all the TLS relocs looking for optimization |
4591 | opportunities. */ | |
252b5132 | 4592 | |
25dbc73a AM |
4593 | bfd_boolean |
4594 | ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, | |
4595 | struct bfd_link_info *info) | |
252b5132 | 4596 | { |
7fce784e | 4597 | bfd *ibfd; |
25dbc73a AM |
4598 | asection *sec; |
4599 | struct ppc_elf_link_hash_table *htab; | |
b7fcf6f6 | 4600 | int pass; |
252b5132 | 4601 | |
1d483afe | 4602 | if (info->relocatable || !info->executable) |
25dbc73a | 4603 | return TRUE; |
252b5132 | 4604 | |
7619e7c7 | 4605 | htab = ppc_elf_hash_table (info); |
b7fcf6f6 AM |
4606 | /* Make two passes through the relocs. First time check that tls |
4607 | relocs involved in setting up a tls_get_addr call are indeed | |
4608 | followed by such a call. If they are not, exclude them from | |
4609 | the optimizations done on the second pass. */ | |
4610 | for (pass = 0; pass < 2; ++pass) | |
4611 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
4612 | { | |
4613 | Elf_Internal_Sym *locsyms = NULL; | |
0ffa91dd | 4614 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); |
7619e7c7 | 4615 | |
b7fcf6f6 AM |
4616 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
4617 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
4618 | { | |
4619 | Elf_Internal_Rela *relstart, *rel, *relend; | |
252b5132 | 4620 | |
b7fcf6f6 AM |
4621 | /* Read the relocations. */ |
4622 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, | |
4623 | info->keep_memory); | |
4624 | if (relstart == NULL) | |
4625 | return FALSE; | |
7619e7c7 | 4626 | |
b7fcf6f6 AM |
4627 | relend = relstart + sec->reloc_count; |
4628 | for (rel = relstart; rel < relend; rel++) | |
4629 | { | |
4630 | enum elf_ppc_reloc_type r_type; | |
4631 | unsigned long r_symndx; | |
4632 | struct elf_link_hash_entry *h = NULL; | |
4633 | char *tls_mask; | |
4634 | char tls_set, tls_clear; | |
4635 | bfd_boolean is_local; | |
4636 | int expecting_tls_get_addr; | |
4637 | bfd_signed_vma *got_count; | |
4638 | ||
4639 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4640 | if (r_symndx >= symtab_hdr->sh_info) | |
4641 | { | |
4642 | struct elf_link_hash_entry **sym_hashes; | |
7fce784e | 4643 | |
b7fcf6f6 AM |
4644 | sym_hashes = elf_sym_hashes (ibfd); |
4645 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4646 | while (h->root.type == bfd_link_hash_indirect | |
4647 | || h->root.type == bfd_link_hash_warning) | |
4648 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4649 | } | |
7619e7c7 | 4650 | |
b7fcf6f6 AM |
4651 | expecting_tls_get_addr = 0; |
4652 | is_local = FALSE; | |
4653 | if (h == NULL | |
4654 | || !h->def_dynamic) | |
4655 | is_local = TRUE; | |
7619e7c7 | 4656 | |
b7fcf6f6 AM |
4657 | r_type = ELF32_R_TYPE (rel->r_info); |
4658 | switch (r_type) | |
4659 | { | |
4660 | case R_PPC_GOT_TLSLD16: | |
4661 | case R_PPC_GOT_TLSLD16_LO: | |
4662 | expecting_tls_get_addr = 1; | |
4663 | /* Fall thru */ | |
4664 | ||
4665 | case R_PPC_GOT_TLSLD16_HI: | |
4666 | case R_PPC_GOT_TLSLD16_HA: | |
4667 | /* These relocs should never be against a symbol | |
4668 | defined in a shared lib. Leave them alone if | |
4669 | that turns out to be the case. */ | |
4670 | if (!is_local) | |
4671 | continue; | |
4672 | ||
4673 | /* LD -> LE */ | |
4674 | tls_set = 0; | |
4675 | tls_clear = TLS_LD; | |
4676 | break; | |
4677 | ||
4678 | case R_PPC_GOT_TLSGD16: | |
4679 | case R_PPC_GOT_TLSGD16_LO: | |
4680 | expecting_tls_get_addr = 1; | |
4681 | /* Fall thru */ | |
4682 | ||
4683 | case R_PPC_GOT_TLSGD16_HI: | |
4684 | case R_PPC_GOT_TLSGD16_HA: | |
4685 | if (is_local) | |
4686 | /* GD -> LE */ | |
4687 | tls_set = 0; | |
4688 | else | |
4689 | /* GD -> IE */ | |
4690 | tls_set = TLS_TLS | TLS_TPRELGD; | |
4691 | tls_clear = TLS_GD; | |
4692 | break; | |
4693 | ||
4694 | case R_PPC_GOT_TPREL16: | |
4695 | case R_PPC_GOT_TPREL16_LO: | |
4696 | case R_PPC_GOT_TPREL16_HI: | |
4697 | case R_PPC_GOT_TPREL16_HA: | |
4698 | if (is_local) | |
4699 | { | |
4700 | /* IE -> LE */ | |
4701 | tls_set = 0; | |
4702 | tls_clear = TLS_TPREL; | |
4703 | break; | |
4704 | } | |
4705 | else | |
4706 | continue; | |
4707 | ||
4708 | default: | |
25dbc73a | 4709 | continue; |
b7fcf6f6 | 4710 | } |
25dbc73a | 4711 | |
b7fcf6f6 AM |
4712 | if (pass == 0) |
4713 | { | |
727fc41e AM |
4714 | if (!expecting_tls_get_addr |
4715 | || !sec->has_tls_get_addr_call) | |
b7fcf6f6 | 4716 | continue; |
25dbc73a | 4717 | |
3a71aa26 AM |
4718 | if (rel + 1 < relend |
4719 | && branch_reloc_hash_match (ibfd, rel + 1, | |
4720 | htab->tls_get_addr)) | |
4721 | continue; | |
25dbc73a | 4722 | |
b7fcf6f6 AM |
4723 | /* Uh oh, we didn't find the expected call. We |
4724 | could just mark this symbol to exclude it | |
4725 | from tls optimization but it's safer to skip | |
4726 | the entire section. */ | |
4727 | sec->has_tls_reloc = 0; | |
4728 | break; | |
4729 | } | |
25dbc73a | 4730 | |
b7fcf6f6 AM |
4731 | if (h != NULL) |
4732 | { | |
4733 | tls_mask = &ppc_elf_hash_entry (h)->tls_mask; | |
4734 | got_count = &h->got.refcount; | |
4735 | } | |
4736 | else | |
4737 | { | |
4738 | Elf_Internal_Sym *sym; | |
4739 | bfd_signed_vma *lgot_refs; | |
e054468f | 4740 | struct plt_entry **local_plt; |
b7fcf6f6 | 4741 | char *lgot_masks; |
25dbc73a | 4742 | |
b7fcf6f6 AM |
4743 | if (locsyms == NULL) |
4744 | { | |
4745 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4746 | if (locsyms == NULL) | |
4747 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
4748 | symtab_hdr->sh_info, | |
4749 | 0, NULL, NULL, NULL); | |
4750 | if (locsyms == NULL) | |
4751 | { | |
4752 | if (elf_section_data (sec)->relocs != relstart) | |
4753 | free (relstart); | |
4754 | return FALSE; | |
4755 | } | |
4756 | } | |
4757 | sym = locsyms + r_symndx; | |
4758 | lgot_refs = elf_local_got_refcounts (ibfd); | |
4759 | if (lgot_refs == NULL) | |
4760 | abort (); | |
e054468f AM |
4761 | local_plt = (struct plt_entry **) |
4762 | (lgot_refs + symtab_hdr->sh_info); | |
4763 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
b7fcf6f6 AM |
4764 | tls_mask = &lgot_masks[r_symndx]; |
4765 | got_count = &lgot_refs[r_symndx]; | |
4766 | } | |
25dbc73a | 4767 | |
b7fcf6f6 AM |
4768 | if (tls_set == 0) |
4769 | { | |
4770 | /* We managed to get rid of a got entry. */ | |
4771 | if (*got_count > 0) | |
4772 | *got_count -= 1; | |
4773 | } | |
25dbc73a | 4774 | |
b7fcf6f6 AM |
4775 | if (expecting_tls_get_addr) |
4776 | { | |
4777 | struct plt_entry *ent; | |
25dbc73a | 4778 | |
3ec01793 AM |
4779 | ent = find_plt_ent (&htab->tls_get_addr->plt.plist, |
4780 | NULL, 0); | |
b7fcf6f6 AM |
4781 | if (ent != NULL && ent->plt.refcount > 0) |
4782 | ent->plt.refcount -= 1; | |
4783 | } | |
25dbc73a | 4784 | |
b7fcf6f6 AM |
4785 | *tls_mask |= tls_set; |
4786 | *tls_mask &= ~tls_clear; | |
4787 | } | |
25dbc73a | 4788 | |
b7fcf6f6 AM |
4789 | if (elf_section_data (sec)->relocs != relstart) |
4790 | free (relstart); | |
4791 | } | |
4792 | ||
4793 | if (locsyms != NULL | |
4794 | && (symtab_hdr->contents != (unsigned char *) locsyms)) | |
4795 | { | |
4796 | if (!info->keep_memory) | |
4797 | free (locsyms); | |
4798 | else | |
4799 | symtab_hdr->contents = (unsigned char *) locsyms; | |
4800 | } | |
4801 | } | |
25dbc73a AM |
4802 | return TRUE; |
4803 | } | |
4804 | \f | |
625af618 AM |
4805 | /* Return true if we have dynamic relocs that apply to read-only sections. */ |
4806 | ||
4807 | static bfd_boolean | |
4808 | readonly_dynrelocs (struct elf_link_hash_entry *h) | |
4809 | { | |
4810 | struct ppc_elf_dyn_relocs *p; | |
4811 | ||
4812 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) | |
4813 | { | |
4814 | asection *s = p->sec->output_section; | |
4815 | ||
4816 | if (s != NULL | |
4817 | && ((s->flags & (SEC_READONLY | SEC_ALLOC)) | |
4818 | == (SEC_READONLY | SEC_ALLOC))) | |
4819 | return TRUE; | |
4820 | } | |
4821 | return FALSE; | |
4822 | } | |
4823 | ||
25dbc73a AM |
4824 | /* Adjust a symbol defined by a dynamic object and referenced by a |
4825 | regular object. The current definition is in some section of the | |
4826 | dynamic object, but we're not including those sections. We have to | |
4827 | change the definition to something the rest of the link can | |
4828 | understand. */ | |
7fce784e | 4829 | |
25dbc73a AM |
4830 | static bfd_boolean |
4831 | ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, | |
4832 | struct elf_link_hash_entry *h) | |
4833 | { | |
4834 | struct ppc_elf_link_hash_table *htab; | |
4835 | asection *s; | |
7fce784e | 4836 | |
25dbc73a AM |
4837 | #ifdef DEBUG |
4838 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", | |
4839 | h->root.root.string); | |
4840 | #endif | |
252b5132 | 4841 | |
25dbc73a AM |
4842 | /* Make sure we know what is going on here. */ |
4843 | htab = ppc_elf_hash_table (info); | |
4844 | BFD_ASSERT (htab->elf.dynobj != NULL | |
4845 | && (h->needs_plt | |
91e21fb7 | 4846 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
4847 | || h->u.weakdef != NULL |
4848 | || (h->def_dynamic | |
4849 | && h->ref_regular | |
4850 | && !h->def_regular))); | |
252b5132 | 4851 | |
25dbc73a AM |
4852 | /* Deal with function syms. */ |
4853 | if (h->type == STT_FUNC | |
e054468f | 4854 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
4855 | || h->needs_plt) |
4856 | { | |
4857 | /* Clear procedure linkage table information for any symbol that | |
4858 | won't need a .plt entry. */ | |
a6aa5195 AM |
4859 | struct plt_entry *ent; |
4860 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4861 | if (ent->plt.refcount > 0) | |
4862 | break; | |
4863 | if (ent == NULL | |
e054468f AM |
4864 | || (h->type != STT_GNU_IFUNC |
4865 | && (SYMBOL_CALLS_LOCAL (info, h) | |
4866 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4867 | && h->root.type == bfd_link_hash_undefweak)))) | |
252b5132 | 4868 | { |
25dbc73a | 4869 | /* A PLT entry is not required/allowed when: |
252b5132 | 4870 | |
25dbc73a AM |
4871 | 1. We are not using ld.so; because then the PLT entry |
4872 | can't be set up, so we can't use one. In this case, | |
4873 | ppc_elf_adjust_dynamic_symbol won't even be called. | |
252b5132 | 4874 | |
25dbc73a AM |
4875 | 2. GC has rendered the entry unused. |
4876 | ||
4877 | 3. We know for certain that a call to this symbol | |
4878 | will go to this object, or will remain undefined. */ | |
a6aa5195 | 4879 | h->plt.plist = NULL; |
25dbc73a AM |
4880 | h->needs_plt = 0; |
4881 | } | |
625af618 AM |
4882 | else |
4883 | { | |
25f23106 AM |
4884 | /* After adjust_dynamic_symbol, non_got_ref set in the |
4885 | non-shared case means that we have allocated space in | |
4886 | .dynbss for the symbol and thus dyn_relocs for this | |
4887 | symbol should be discarded. | |
625af618 AM |
4888 | If we get here we know we are making a PLT entry for this |
4889 | symbol, and in an executable we'd normally resolve | |
4890 | relocations against this symbol to the PLT entry. Allow | |
4891 | dynamic relocs if the reference is weak, and the dynamic | |
4892 | relocs will not cause text relocation. */ | |
4893 | if (!h->ref_regular_nonweak | |
4894 | && h->non_got_ref | |
25f23106 | 4895 | && h->type != STT_GNU_IFUNC |
625af618 AM |
4896 | && !htab->is_vxworks |
4897 | && !ppc_elf_hash_entry (h)->has_sda_refs | |
4898 | && !readonly_dynrelocs (h)) | |
4899 | h->non_got_ref = 0; | |
4900 | } | |
25dbc73a | 4901 | return TRUE; |
252b5132 | 4902 | } |
25dbc73a | 4903 | else |
a6aa5195 | 4904 | h->plt.plist = NULL; |
252b5132 | 4905 | |
25dbc73a AM |
4906 | /* If this is a weak symbol, and there is a real definition, the |
4907 | processor independent code will have arranged for us to see the | |
4908 | real definition first, and we can just use the same value. */ | |
4909 | if (h->u.weakdef != NULL) | |
252b5132 | 4910 | { |
25dbc73a AM |
4911 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
4912 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
4913 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
4914 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
4915 | if (ELIMINATE_COPY_RELOCS) | |
4916 | h->non_got_ref = h->u.weakdef->non_got_ref; | |
4917 | return TRUE; | |
4918 | } | |
dc810e39 | 4919 | |
25dbc73a AM |
4920 | /* This is a reference to a symbol defined by a dynamic object which |
4921 | is not a function. */ | |
252b5132 | 4922 | |
25dbc73a AM |
4923 | /* If we are creating a shared library, we must presume that the |
4924 | only references to the symbol are via the global offset table. | |
4925 | For such cases we need not do anything here; the relocations will | |
4926 | be handled correctly by relocate_section. */ | |
4927 | if (info->shared) | |
4928 | return TRUE; | |
252b5132 | 4929 | |
25dbc73a AM |
4930 | /* If there are no references to this symbol that do not use the |
4931 | GOT, we don't need to generate a copy reloc. */ | |
4932 | if (!h->non_got_ref) | |
4933 | return TRUE; | |
4934 | ||
cfd2c773 NS |
4935 | /* If we didn't find any dynamic relocs in read-only sections, then |
4936 | we'll be keeping the dynamic relocs and avoiding the copy reloc. | |
4937 | We can't do this if there are any small data relocations. This | |
4938 | doesn't work on VxWorks, where we can not have dynamic | |
4939 | relocations (other than copy and jump slot relocations) in an | |
4940 | executable. */ | |
4dc4a9a5 | 4941 | if (ELIMINATE_COPY_RELOCS |
cfd2c773 | 4942 | && !ppc_elf_hash_entry (h)->has_sda_refs |
625af618 AM |
4943 | && !htab->is_vxworks |
4944 | && !h->def_regular | |
4945 | && !readonly_dynrelocs (h)) | |
25dbc73a | 4946 | { |
625af618 AM |
4947 | h->non_got_ref = 0; |
4948 | return TRUE; | |
252b5132 RH |
4949 | } |
4950 | ||
909272ee AM |
4951 | if (h->size == 0) |
4952 | { | |
4953 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
4954 | h->root.root.string); | |
4955 | return TRUE; | |
4956 | } | |
4957 | ||
25dbc73a AM |
4958 | /* We must allocate the symbol in our .dynbss section, which will |
4959 | become part of the .bss section of the executable. There will be | |
4960 | an entry for this symbol in the .dynsym section. The dynamic | |
4961 | object will contain position independent code, so all references | |
4962 | from the dynamic object to this symbol will go through the global | |
4963 | offset table. The dynamic linker will use the .dynsym entry to | |
4964 | determine the address it must put in the global offset table, so | |
4965 | both the dynamic object and the regular object will refer to the | |
4966 | same memory location for the variable. | |
4967 | ||
4dc4a9a5 DJ |
4968 | Of course, if the symbol is referenced using SDAREL relocs, we |
4969 | must instead allocate it in .sbss. */ | |
25dbc73a | 4970 | |
4dc4a9a5 | 4971 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
4972 | s = htab->dynsbss; |
4973 | else | |
4974 | s = htab->dynbss; | |
4975 | BFD_ASSERT (s != NULL); | |
4976 | ||
4977 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
4978 | copy the initial value out of the dynamic object and into the | |
4979 | runtime process image. We need to remember the offset into the | |
4980 | .rela.bss section we are going to use. */ | |
4981 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
4982 | { | |
4983 | asection *srel; | |
4984 | ||
4dc4a9a5 | 4985 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
4986 | srel = htab->relsbss; |
4987 | else | |
4988 | srel = htab->relbss; | |
4989 | BFD_ASSERT (srel != NULL); | |
4990 | srel->size += sizeof (Elf32_External_Rela); | |
4991 | h->needs_copy = 1; | |
4992 | } | |
7619e7c7 | 4993 | |
027297b7 | 4994 | return _bfd_elf_adjust_dynamic_copy (h, s); |
25dbc73a AM |
4995 | } |
4996 | \f | |
ac39eb42 AM |
4997 | /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is |
4998 | xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0, | |
4999 | specifying the addend on the plt relocation. For -fpic code, the sym | |
5000 | is xxxxxxxx.plt_pic32.<callee>, and for -fPIC | |
5001 | xxxxxxxx.got2.plt_pic32.<callee>. */ | |
0ba07910 AM |
5002 | |
5003 | static bfd_boolean | |
5004 | add_stub_sym (struct plt_entry *ent, | |
5005 | struct elf_link_hash_entry *h, | |
ac39eb42 | 5006 | struct bfd_link_info *info) |
0ba07910 AM |
5007 | { |
5008 | struct elf_link_hash_entry *sh; | |
5009 | size_t len1, len2, len3; | |
5010 | char *name; | |
ac39eb42 AM |
5011 | const char *stub; |
5012 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
5013 | ||
a877a2b6 | 5014 | if (info->shared) |
ac39eb42 AM |
5015 | stub = ".plt_pic32."; |
5016 | else | |
5017 | stub = ".plt_call32."; | |
0ba07910 AM |
5018 | |
5019 | len1 = strlen (h->root.root.string); | |
ac39eb42 | 5020 | len2 = strlen (stub); |
0ba07910 AM |
5021 | len3 = 0; |
5022 | if (ent->sec) | |
5023 | len3 = strlen (ent->sec->name); | |
ac39eb42 | 5024 | name = bfd_malloc (len1 + len2 + len3 + 9); |
0ba07910 AM |
5025 | if (name == NULL) |
5026 | return FALSE; | |
5027 | sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff); | |
5028 | if (ent->sec) | |
5029 | memcpy (name + 8, ent->sec->name, len3); | |
ac39eb42 AM |
5030 | memcpy (name + 8 + len3, stub, len2); |
5031 | memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1); | |
0ba07910 AM |
5032 | sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE); |
5033 | if (sh == NULL) | |
5034 | return FALSE; | |
5035 | if (sh->root.type == bfd_link_hash_new) | |
5036 | { | |
5037 | sh->root.type = bfd_link_hash_defined; | |
5038 | sh->root.u.def.section = htab->glink; | |
5039 | sh->root.u.def.value = ent->glink_offset; | |
5040 | sh->ref_regular = 1; | |
5041 | sh->def_regular = 1; | |
5042 | sh->ref_regular_nonweak = 1; | |
5043 | sh->forced_local = 1; | |
5044 | sh->non_elf = 0; | |
5045 | } | |
5046 | return TRUE; | |
5047 | } | |
5048 | ||
3b36f7e6 AM |
5049 | /* Allocate NEED contiguous space in .got, and return the offset. |
5050 | Handles allocation of the got header when crossing 32k. */ | |
5051 | ||
5052 | static bfd_vma | |
5053 | allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need) | |
5054 | { | |
5055 | bfd_vma where; | |
4a3dc543 | 5056 | unsigned int max_before_header; |
3b36f7e6 | 5057 | |
4a3dc543 | 5058 | if (htab->plt_type == PLT_VXWORKS) |
9d8504b1 PB |
5059 | { |
5060 | where = htab->got->size; | |
5061 | htab->got->size += need; | |
5062 | } | |
3b36f7e6 AM |
5063 | else |
5064 | { | |
4a3dc543 RS |
5065 | max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764; |
5066 | if (need <= htab->got_gap) | |
3b36f7e6 | 5067 | { |
4a3dc543 RS |
5068 | where = max_before_header - htab->got_gap; |
5069 | htab->got_gap -= need; | |
5070 | } | |
5071 | else | |
5072 | { | |
5073 | if (htab->got->size + need > max_before_header | |
5074 | && htab->got->size <= max_before_header) | |
5075 | { | |
5076 | htab->got_gap = max_before_header - htab->got->size; | |
5077 | htab->got->size = max_before_header + htab->got_header_size; | |
5078 | } | |
5079 | where = htab->got->size; | |
5080 | htab->got->size += need; | |
3b36f7e6 | 5081 | } |
3b36f7e6 AM |
5082 | } |
5083 | return where; | |
5084 | } | |
5085 | ||
25dbc73a | 5086 | /* Allocate space in associated reloc sections for dynamic relocs. */ |
252b5132 | 5087 | |
b34976b6 | 5088 | static bfd_boolean |
25dbc73a | 5089 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
252b5132 | 5090 | { |
25dbc73a AM |
5091 | struct bfd_link_info *info = inf; |
5092 | struct ppc_elf_link_hash_entry *eh; | |
7619e7c7 | 5093 | struct ppc_elf_link_hash_table *htab; |
25dbc73a | 5094 | struct ppc_elf_dyn_relocs *p; |
252b5132 | 5095 | |
25dbc73a | 5096 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5097 | return TRUE; |
252b5132 | 5098 | |
25dbc73a AM |
5099 | if (h->root.type == bfd_link_hash_warning) |
5100 | /* When warning symbols are created, they **replace** the "real" | |
5101 | entry in the hash table, thus we never get to see the real | |
5102 | symbol in a hash traversal. So look at it now. */ | |
5103 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
e47cd125 | 5104 | |
7619e7c7 | 5105 | htab = ppc_elf_hash_table (info); |
e054468f AM |
5106 | if (htab->elf.dynamic_sections_created |
5107 | || h->type == STT_GNU_IFUNC) | |
252b5132 | 5108 | { |
a6aa5195 AM |
5109 | struct plt_entry *ent; |
5110 | bfd_boolean doneone = FALSE; | |
28e99bb6 | 5111 | bfd_vma plt_offset = 0, glink_offset = 0; |
e054468f | 5112 | bfd_boolean dyn; |
28e99bb6 | 5113 | |
a6aa5195 AM |
5114 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
5115 | if (ent->plt.refcount > 0) | |
5116 | { | |
5117 | /* Make sure this symbol is output as a dynamic symbol. */ | |
5118 | if (h->dynindx == -1 | |
e054468f AM |
5119 | && !h->forced_local |
5120 | && !h->def_regular | |
5121 | && htab->elf.dynamic_sections_created) | |
a6aa5195 AM |
5122 | { |
5123 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5124 | return FALSE; | |
5125 | } | |
252b5132 | 5126 | |
e054468f | 5127 | dyn = htab->elf.dynamic_sections_created; |
a6aa5195 | 5128 | if (info->shared |
e054468f AM |
5129 | || h->type == STT_GNU_IFUNC |
5130 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
a6aa5195 AM |
5131 | { |
5132 | asection *s = htab->plt; | |
25f23106 | 5133 | if (!dyn || h->dynindx == -1) |
e054468f | 5134 | s = htab->iplt; |
7619e7c7 | 5135 | |
25f23106 | 5136 | if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1) |
a6aa5195 | 5137 | { |
a6aa5195 | 5138 | if (!doneone) |
28e99bb6 AM |
5139 | { |
5140 | plt_offset = s->size; | |
5141 | s->size += 4; | |
5142 | } | |
5143 | ent->plt.offset = plt_offset; | |
d7128ce4 | 5144 | |
a6aa5195 | 5145 | s = htab->glink; |
a877a2b6 | 5146 | if (!doneone || info->shared) |
28e99bb6 AM |
5147 | { |
5148 | glink_offset = s->size; | |
5149 | s->size += GLINK_ENTRY_SIZE; | |
5150 | } | |
5151 | if (!doneone | |
5152 | && !info->shared | |
625af618 | 5153 | && h->def_dynamic |
a6aa5195 AM |
5154 | && !h->def_regular) |
5155 | { | |
5156 | h->root.u.def.section = s; | |
28e99bb6 | 5157 | h->root.u.def.value = glink_offset; |
a6aa5195 | 5158 | } |
28e99bb6 | 5159 | ent->glink_offset = glink_offset; |
0ba07910 AM |
5160 | |
5161 | if (htab->emit_stub_syms | |
ac39eb42 | 5162 | && !add_stub_sym (ent, h, info)) |
0ba07910 | 5163 | return FALSE; |
a6aa5195 AM |
5164 | } |
5165 | else | |
5166 | { | |
a6aa5195 AM |
5167 | if (!doneone) |
5168 | { | |
28e99bb6 AM |
5169 | /* If this is the first .plt entry, make room |
5170 | for the special first entry. */ | |
5171 | if (s->size == 0) | |
9d8504b1 | 5172 | s->size += htab->plt_initial_entry_size; |
28e99bb6 AM |
5173 | |
5174 | /* The PowerPC PLT is actually composed of two | |
5175 | parts, the first part is 2 words (for a load | |
5176 | and a jump), and then there is a remaining | |
5177 | word available at the end. */ | |
9d8504b1 PB |
5178 | plt_offset = (htab->plt_initial_entry_size |
5179 | + (htab->plt_slot_size | |
5180 | * ((s->size | |
5181 | - htab->plt_initial_entry_size) | |
5182 | / htab->plt_entry_size))); | |
28e99bb6 AM |
5183 | |
5184 | /* If this symbol is not defined in a regular | |
5185 | file, and we are not generating a shared | |
de972ffa AM |
5186 | library, then set the symbol to this location |
5187 | in the .plt. This is to avoid text | |
5188 | relocations, and is required to make | |
28e99bb6 AM |
5189 | function pointers compare as equal between |
5190 | the normal executable and the shared library. */ | |
5191 | if (! info->shared | |
625af618 | 5192 | && h->def_dynamic |
28e99bb6 AM |
5193 | && !h->def_regular) |
5194 | { | |
5195 | h->root.u.def.section = s; | |
5196 | h->root.u.def.value = plt_offset; | |
5197 | } | |
5198 | ||
9d8504b1 PB |
5199 | /* Make room for this entry. */ |
5200 | s->size += htab->plt_entry_size; | |
5201 | /* After the 8192nd entry, room for two entries | |
5202 | is allocated. */ | |
4a3dc543 | 5203 | if (htab->plt_type == PLT_OLD |
9d8504b1 PB |
5204 | && (s->size - htab->plt_initial_entry_size) |
5205 | / htab->plt_entry_size | |
5206 | > PLT_NUM_SINGLE_ENTRIES) | |
5207 | s->size += htab->plt_entry_size; | |
a6aa5195 | 5208 | } |
28e99bb6 | 5209 | ent->plt.offset = plt_offset; |
a6aa5195 | 5210 | } |
25dbc73a | 5211 | |
a6aa5195 AM |
5212 | /* We also need to make an entry in the .rela.plt section. */ |
5213 | if (!doneone) | |
5214 | { | |
25f23106 AM |
5215 | if (!htab->elf.dynamic_sections_created |
5216 | || h->dynindx == -1) | |
e054468f AM |
5217 | htab->reliplt->size += sizeof (Elf32_External_Rela); |
5218 | else | |
9d8504b1 | 5219 | { |
e054468f AM |
5220 | htab->relplt->size += sizeof (Elf32_External_Rela); |
5221 | ||
5222 | if (htab->plt_type == PLT_VXWORKS) | |
9d8504b1 | 5223 | { |
e054468f AM |
5224 | /* Allocate space for the unloaded relocations. */ |
5225 | if (!info->shared | |
5226 | && htab->elf.dynamic_sections_created) | |
9d8504b1 | 5227 | { |
e054468f AM |
5228 | if (ent->plt.offset |
5229 | == (bfd_vma) htab->plt_initial_entry_size) | |
5230 | { | |
5231 | htab->srelplt2->size | |
5232 | += (sizeof (Elf32_External_Rela) | |
5233 | * VXWORKS_PLTRESOLVE_RELOCS); | |
5234 | } | |
5235 | ||
9d8504b1 | 5236 | htab->srelplt2->size |
e054468f AM |
5237 | += (sizeof (Elf32_External_Rela) |
5238 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS); | |
9d8504b1 PB |
5239 | } |
5240 | ||
e054468f AM |
5241 | /* Every PLT entry has an associated GOT entry in |
5242 | .got.plt. */ | |
5243 | htab->sgotplt->size += 4; | |
9d8504b1 | 5244 | } |
9d8504b1 | 5245 | } |
a6aa5195 AM |
5246 | doneone = TRUE; |
5247 | } | |
5248 | } | |
5249 | else | |
5250 | ent->plt.offset = (bfd_vma) -1; | |
a6aa5195 | 5251 | } |
2ce859a1 AM |
5252 | else |
5253 | ent->plt.offset = (bfd_vma) -1; | |
5254 | ||
5255 | if (!doneone) | |
5256 | { | |
5257 | h->plt.plist = NULL; | |
5258 | h->needs_plt = 0; | |
5259 | } | |
25dbc73a AM |
5260 | } |
5261 | else | |
5262 | { | |
a6aa5195 | 5263 | h->plt.plist = NULL; |
25dbc73a AM |
5264 | h->needs_plt = 0; |
5265 | } | |
5266 | ||
5267 | eh = (struct ppc_elf_link_hash_entry *) h; | |
5268 | if (eh->elf.got.refcount > 0) | |
5269 | { | |
d6e14abc AM |
5270 | bfd_boolean dyn; |
5271 | unsigned int need; | |
5272 | ||
25dbc73a AM |
5273 | /* Make sure this symbol is output as a dynamic symbol. */ |
5274 | if (eh->elf.dynindx == -1 | |
b099ab9f | 5275 | && !eh->elf.forced_local |
25f23106 | 5276 | && eh->elf.type != STT_GNU_IFUNC |
b099ab9f | 5277 | && htab->elf.dynamic_sections_created) |
25dbc73a AM |
5278 | { |
5279 | if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf)) | |
b34976b6 | 5280 | return FALSE; |
25dbc73a | 5281 | } |
252b5132 | 5282 | |
d6e14abc AM |
5283 | need = 0; |
5284 | if ((eh->tls_mask & TLS_TLS) != 0) | |
25dbc73a | 5285 | { |
d6e14abc | 5286 | if ((eh->tls_mask & TLS_LD) != 0) |
252b5132 | 5287 | { |
d6e14abc AM |
5288 | if (!eh->elf.def_dynamic) |
5289 | /* We'll just use htab->tlsld_got.offset. This should | |
5290 | always be the case. It's a little odd if we have | |
5291 | a local dynamic reloc against a non-local symbol. */ | |
5292 | htab->tlsld_got.refcount += 1; | |
5293 | else | |
3b36f7e6 | 5294 | need += 8; |
252b5132 | 5295 | } |
d6e14abc AM |
5296 | if ((eh->tls_mask & TLS_GD) != 0) |
5297 | need += 8; | |
5298 | if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
5299 | need += 4; | |
5300 | if ((eh->tls_mask & TLS_DTPREL) != 0) | |
3b36f7e6 | 5301 | need += 4; |
d6e14abc AM |
5302 | } |
5303 | else | |
5304 | need += 4; | |
5305 | if (need == 0) | |
5306 | eh->elf.got.offset = (bfd_vma) -1; | |
5307 | else | |
5308 | { | |
3b36f7e6 | 5309 | eh->elf.got.offset = allocate_got (htab, need); |
25dbc73a AM |
5310 | dyn = htab->elf.dynamic_sections_created; |
5311 | if ((info->shared | |
5312 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf)) | |
5313 | && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT | |
5314 | || eh->elf.root.type != bfd_link_hash_undefweak)) | |
252b5132 | 5315 | { |
91e21fb7 | 5316 | asection *rsec = htab->relgot; |
3b36f7e6 AM |
5317 | /* All the entries we allocated need relocs. |
5318 | Except LD only needs one. */ | |
d6e14abc AM |
5319 | if ((eh->tls_mask & TLS_LD) != 0 |
5320 | && eh->elf.def_dynamic) | |
3b36f7e6 | 5321 | need -= 4; |
25f23106 | 5322 | rsec->size += need * (sizeof (Elf32_External_Rela) / 4); |
252b5132 | 5323 | } |
25dbc73a AM |
5324 | } |
5325 | } | |
5326 | else | |
5327 | eh->elf.got.offset = (bfd_vma) -1; | |
252b5132 | 5328 | |
b099ab9f | 5329 | if (eh->dyn_relocs == NULL |
de972ffa | 5330 | || !htab->elf.dynamic_sections_created) |
25dbc73a | 5331 | return TRUE; |
252b5132 | 5332 | |
25dbc73a AM |
5333 | /* In the shared -Bsymbolic case, discard space allocated for |
5334 | dynamic pc-relative relocs against symbols which turn out to be | |
5335 | defined in regular objects. For the normal shared case, discard | |
5336 | space for relocs that have become local due to symbol visibility | |
5337 | changes. */ | |
5338 | ||
5339 | if (info->shared) | |
5340 | { | |
5341 | /* Relocs that use pc_count are those that appear on a call insn, | |
1d483afe | 5342 | or certain REL relocs (see must_be_dyn_reloc) that can be |
25dbc73a AM |
5343 | generated via assembly. We want calls to protected symbols to |
5344 | resolve directly to the function rather than going via the plt. | |
5345 | If people want function pointer comparisons to work as expected | |
5346 | then they should avoid writing weird assembly. */ | |
5347 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
5348 | { | |
5349 | struct ppc_elf_dyn_relocs **pp; | |
5350 | ||
5351 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
252b5132 | 5352 | { |
25dbc73a AM |
5353 | p->count -= p->pc_count; |
5354 | p->pc_count = 0; | |
5355 | if (p->count == 0) | |
5356 | *pp = p->next; | |
5357 | else | |
5358 | pp = &p->next; | |
252b5132 | 5359 | } |
25dbc73a | 5360 | } |
252b5132 | 5361 | |
3348747a NS |
5362 | if (htab->is_vxworks) |
5363 | { | |
5364 | struct ppc_elf_dyn_relocs **pp; | |
5365 | ||
5366 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5367 | { | |
5368 | if (strcmp (p->sec->output_section->name, ".tls_vars") == 0) | |
5369 | *pp = p->next; | |
5370 | else | |
5371 | pp = &p->next; | |
5372 | } | |
5373 | } | |
5374 | ||
89200bf8 AM |
5375 | /* Discard relocs on undefined symbols that must be local. */ |
5376 | if (eh->dyn_relocs != NULL | |
5377 | && h->root.type == bfd_link_hash_undefined | |
5378 | && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
5379 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL)) | |
5380 | eh->dyn_relocs = NULL; | |
5381 | ||
25dbc73a AM |
5382 | /* Also discard relocs on undefined weak syms with non-default |
5383 | visibility. */ | |
cab87ef9 AM |
5384 | if (eh->dyn_relocs != NULL |
5385 | && h->root.type == bfd_link_hash_undefweak) | |
25dbc73a | 5386 | { |
dfbb6ac9 AM |
5387 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
5388 | eh->dyn_relocs = NULL; | |
5389 | ||
5390 | /* Make sure undefined weak symbols are output as a dynamic | |
5391 | symbol in PIEs. */ | |
5392 | else if (h->dynindx == -1 | |
e054468f AM |
5393 | && !h->forced_local |
5394 | && !h->def_regular) | |
dfbb6ac9 AM |
5395 | { |
5396 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5397 | return FALSE; | |
5398 | } | |
25dbc73a AM |
5399 | } |
5400 | } | |
5401 | else if (ELIMINATE_COPY_RELOCS) | |
5402 | { | |
5403 | /* For the non-shared case, discard space for relocs against | |
5404 | symbols which turn out to need copy relocs or are not | |
5405 | dynamic. */ | |
7619e7c7 | 5406 | |
25dbc73a | 5407 | if (!h->non_got_ref |
25dbc73a AM |
5408 | && !h->def_regular) |
5409 | { | |
5410 | /* Make sure this symbol is output as a dynamic symbol. | |
5411 | Undefined weak syms won't yet be marked as dynamic. */ | |
5412 | if (h->dynindx == -1 | |
25f23106 | 5413 | && !h->forced_local) |
25dbc73a AM |
5414 | { |
5415 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5416 | return FALSE; | |
5417 | } | |
7619e7c7 | 5418 | |
25dbc73a AM |
5419 | /* If that succeeded, we know we'll be keeping all the |
5420 | relocs. */ | |
5421 | if (h->dynindx != -1) | |
5422 | goto keep; | |
5423 | } | |
252b5132 | 5424 | |
25dbc73a | 5425 | eh->dyn_relocs = NULL; |
252b5132 | 5426 | |
25dbc73a AM |
5427 | keep: ; |
5428 | } | |
252b5132 | 5429 | |
25dbc73a AM |
5430 | /* Finally, allocate space. */ |
5431 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5432 | { | |
5433 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
25f23106 AM |
5434 | if (!htab->elf.dynamic_sections_created) |
5435 | sreloc = htab->reliplt; | |
25dbc73a AM |
5436 | sreloc->size += p->count * sizeof (Elf32_External_Rela); |
5437 | } | |
252b5132 | 5438 | |
25dbc73a AM |
5439 | return TRUE; |
5440 | } | |
7619e7c7 | 5441 | |
625af618 AM |
5442 | /* Set DF_TEXTREL if we find any dynamic relocs that apply to |
5443 | read-only sections. */ | |
7619e7c7 | 5444 | |
25dbc73a | 5445 | static bfd_boolean |
625af618 | 5446 | maybe_set_textrel (struct elf_link_hash_entry *h, void *info) |
25dbc73a | 5447 | { |
25dbc73a AM |
5448 | if (h->root.type == bfd_link_hash_indirect) |
5449 | return TRUE; | |
252b5132 | 5450 | |
25dbc73a AM |
5451 | if (h->root.type == bfd_link_hash_warning) |
5452 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 5453 | |
625af618 | 5454 | if (readonly_dynrelocs (h)) |
25dbc73a | 5455 | { |
625af618 | 5456 | ((struct bfd_link_info *) info)->flags |= DF_TEXTREL; |
ee05f2fe | 5457 | |
625af618 AM |
5458 | /* Not an error, just cut short the traversal. */ |
5459 | return FALSE; | |
25dbc73a AM |
5460 | } |
5461 | return TRUE; | |
5462 | } | |
5463 | ||
5464 | /* Set the sizes of the dynamic sections. */ | |
5465 | ||
5466 | static bfd_boolean | |
5467 | ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, | |
5468 | struct bfd_link_info *info) | |
5469 | { | |
5470 | struct ppc_elf_link_hash_table *htab; | |
5471 | asection *s; | |
5472 | bfd_boolean relocs; | |
5473 | bfd *ibfd; | |
7fce784e | 5474 | |
252b5132 | 5475 | #ifdef DEBUG |
25dbc73a | 5476 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); |
252b5132 | 5477 | #endif |
252b5132 | 5478 | |
25dbc73a AM |
5479 | htab = ppc_elf_hash_table (info); |
5480 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
252b5132 | 5481 | |
25dbc73a AM |
5482 | if (elf_hash_table (info)->dynamic_sections_created) |
5483 | { | |
5484 | /* Set the contents of the .interp section to the interpreter. */ | |
5485 | if (info->executable) | |
5486 | { | |
5487 | s = bfd_get_section_by_name (htab->elf.dynobj, ".interp"); | |
5488 | BFD_ASSERT (s != NULL); | |
5489 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5490 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
5491 | } | |
5492 | } | |
252b5132 | 5493 | |
4a3dc543 | 5494 | if (htab->plt_type == PLT_OLD) |
d7128ce4 | 5495 | htab->got_header_size = 16; |
4a3dc543 | 5496 | else if (htab->plt_type == PLT_NEW) |
d7128ce4 | 5497 | htab->got_header_size = 12; |
252b5132 | 5498 | |
25dbc73a AM |
5499 | /* Set up .got offsets for local syms, and space for local dynamic |
5500 | relocs. */ | |
5501 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
5502 | { | |
5503 | bfd_signed_vma *local_got; | |
5504 | bfd_signed_vma *end_local_got; | |
e054468f AM |
5505 | struct plt_entry **local_plt; |
5506 | struct plt_entry **end_local_plt; | |
25dbc73a AM |
5507 | char *lgot_masks; |
5508 | bfd_size_type locsymcount; | |
5509 | Elf_Internal_Shdr *symtab_hdr; | |
7fce784e | 5510 | |
0c8d6e5c | 5511 | if (!is_ppc_elf (ibfd)) |
25dbc73a | 5512 | continue; |
7fce784e | 5513 | |
25dbc73a AM |
5514 | for (s = ibfd->sections; s != NULL; s = s->next) |
5515 | { | |
5516 | struct ppc_elf_dyn_relocs *p; | |
252b5132 | 5517 | |
25dbc73a AM |
5518 | for (p = ((struct ppc_elf_dyn_relocs *) |
5519 | elf_section_data (s)->local_dynrel); | |
5520 | p != NULL; | |
5521 | p = p->next) | |
5522 | { | |
5523 | if (!bfd_is_abs_section (p->sec) | |
5524 | && bfd_is_abs_section (p->sec->output_section)) | |
5525 | { | |
5526 | /* Input section has been discarded, either because | |
5527 | it is a copy of a linkonce section or due to | |
5528 | linker script /DISCARD/, so we'll be discarding | |
5529 | the relocs too. */ | |
7fce784e | 5530 | } |
3348747a NS |
5531 | else if (htab->is_vxworks |
5532 | && strcmp (p->sec->output_section->name, | |
5533 | ".tls_vars") == 0) | |
5534 | { | |
5535 | /* Relocations in vxworks .tls_vars sections are | |
5536 | handled specially by the loader. */ | |
5537 | } | |
25dbc73a | 5538 | else if (p->count != 0) |
7fce784e | 5539 | { |
25f23106 AM |
5540 | asection *sreloc = elf_section_data (p->sec)->sreloc; |
5541 | if (!htab->elf.dynamic_sections_created) | |
5542 | sreloc = htab->reliplt; | |
5543 | sreloc->size += p->count * sizeof (Elf32_External_Rela); | |
25dbc73a AM |
5544 | if ((p->sec->output_section->flags |
5545 | & (SEC_READONLY | SEC_ALLOC)) | |
5546 | == (SEC_READONLY | SEC_ALLOC)) | |
5547 | info->flags |= DF_TEXTREL; | |
7fce784e | 5548 | } |
252b5132 | 5549 | } |
252b5132 | 5550 | } |
252b5132 | 5551 | |
25dbc73a AM |
5552 | local_got = elf_local_got_refcounts (ibfd); |
5553 | if (!local_got) | |
5554 | continue; | |
252b5132 | 5555 | |
0ffa91dd | 5556 | symtab_hdr = &elf_symtab_hdr (ibfd); |
25dbc73a AM |
5557 | locsymcount = symtab_hdr->sh_info; |
5558 | end_local_got = local_got + locsymcount; | |
e054468f AM |
5559 | local_plt = (struct plt_entry **) end_local_got; |
5560 | end_local_plt = local_plt + locsymcount; | |
5561 | lgot_masks = (char *) end_local_plt; | |
25dbc73a AM |
5562 | for (; local_got < end_local_got; ++local_got, ++lgot_masks) |
5563 | if (*local_got > 0) | |
5564 | { | |
d6e14abc AM |
5565 | unsigned int need = 0; |
5566 | if ((*lgot_masks & TLS_TLS) != 0) | |
25dbc73a | 5567 | { |
d6e14abc AM |
5568 | if ((*lgot_masks & TLS_GD) != 0) |
5569 | need += 8; | |
5570 | if ((*lgot_masks & TLS_LD) != 0) | |
5571 | htab->tlsld_got.refcount += 1; | |
5572 | if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
5573 | need += 4; | |
5574 | if ((*lgot_masks & TLS_DTPREL) != 0) | |
5575 | need += 4; | |
25dbc73a | 5576 | } |
d6e14abc AM |
5577 | else |
5578 | need += 4; | |
5579 | if (need == 0) | |
5580 | *local_got = (bfd_vma) -1; | |
25dbc73a AM |
5581 | else |
5582 | { | |
3b36f7e6 | 5583 | *local_got = allocate_got (htab, need); |
25dbc73a | 5584 | if (info->shared) |
3b36f7e6 AM |
5585 | htab->relgot->size += (need |
5586 | * (sizeof (Elf32_External_Rela) / 4)); | |
25dbc73a AM |
5587 | } |
5588 | } | |
5589 | else | |
5590 | *local_got = (bfd_vma) -1; | |
e054468f AM |
5591 | |
5592 | if (htab->is_vxworks) | |
5593 | continue; | |
5594 | ||
5595 | /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */ | |
5596 | for (; local_plt < end_local_plt; ++local_plt) | |
5597 | { | |
5598 | struct plt_entry *ent; | |
5599 | bfd_boolean doneone = FALSE; | |
5600 | bfd_vma plt_offset = 0, glink_offset = 0; | |
5601 | ||
5602 | for (ent = *local_plt; ent != NULL; ent = ent->next) | |
5603 | if (ent->plt.refcount > 0) | |
5604 | { | |
5605 | asection *s = htab->iplt; | |
5606 | ||
5607 | if (!doneone) | |
5608 | { | |
5609 | plt_offset = s->size; | |
5610 | s->size += 4; | |
5611 | } | |
5612 | ent->plt.offset = plt_offset; | |
5613 | ||
5614 | s = htab->glink; | |
a877a2b6 | 5615 | if (!doneone || info->shared) |
e054468f AM |
5616 | { |
5617 | glink_offset = s->size; | |
5618 | s->size += GLINK_ENTRY_SIZE; | |
5619 | } | |
5620 | ent->glink_offset = glink_offset; | |
5621 | ||
5622 | if (!doneone) | |
5623 | { | |
25f23106 | 5624 | htab->reliplt->size += sizeof (Elf32_External_Rela); |
e054468f AM |
5625 | doneone = TRUE; |
5626 | } | |
5627 | } | |
5628 | else | |
5629 | ent->plt.offset = (bfd_vma) -1; | |
5630 | } | |
25dbc73a | 5631 | } |
252b5132 | 5632 | |
b7fcf6f6 AM |
5633 | /* Allocate space for global sym dynamic relocs. */ |
5634 | elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info); | |
5635 | ||
3b36f7e6 AM |
5636 | if (htab->tlsld_got.refcount > 0) |
5637 | { | |
5638 | htab->tlsld_got.offset = allocate_got (htab, 8); | |
5639 | if (info->shared) | |
5640 | htab->relgot->size += sizeof (Elf32_External_Rela); | |
5641 | } | |
5642 | else | |
5643 | htab->tlsld_got.offset = (bfd_vma) -1; | |
5644 | ||
4a3dc543 | 5645 | if (htab->got != NULL && htab->plt_type != PLT_VXWORKS) |
3b36f7e6 AM |
5646 | { |
5647 | unsigned int g_o_t = 32768; | |
5648 | ||
4d962050 AM |
5649 | /* If we haven't allocated the header, do so now. When we get here, |
5650 | for old plt/got the got size will be 0 to 32764 (not allocated), | |
5651 | or 32780 to 65536 (header allocated). For new plt/got, the | |
5652 | corresponding ranges are 0 to 32768 and 32780 to 65536. */ | |
3b36f7e6 AM |
5653 | if (htab->got->size <= 32768) |
5654 | { | |
5655 | g_o_t = htab->got->size; | |
4a3dc543 | 5656 | if (htab->plt_type == PLT_OLD) |
4d962050 | 5657 | g_o_t += 4; |
3b36f7e6 AM |
5658 | htab->got->size += htab->got_header_size; |
5659 | } | |
3b36f7e6 AM |
5660 | |
5661 | htab->elf.hgot->root.u.def.value = g_o_t; | |
5662 | } | |
5663 | ||
e054468f AM |
5664 | if (htab->glink != NULL |
5665 | && htab->glink->size != 0 | |
5666 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
5667 | { |
5668 | htab->glink_pltresolve = htab->glink->size; | |
86b9da88 AM |
5669 | /* Space for the branch table. */ |
5670 | htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4; | |
5671 | /* Pad out to align the start of PLTresolve. */ | |
5672 | htab->glink->size += -htab->glink->size & 15; | |
d7128ce4 | 5673 | htab->glink->size += GLINK_PLTRESOLVE; |
0ba07910 AM |
5674 | |
5675 | if (htab->emit_stub_syms) | |
5676 | { | |
5677 | struct elf_link_hash_entry *sh; | |
5678 | sh = elf_link_hash_lookup (&htab->elf, "__glink", | |
5679 | TRUE, FALSE, FALSE); | |
5680 | if (sh == NULL) | |
5681 | return FALSE; | |
5682 | if (sh->root.type == bfd_link_hash_new) | |
5683 | { | |
5684 | sh->root.type = bfd_link_hash_defined; | |
5685 | sh->root.u.def.section = htab->glink; | |
5686 | sh->root.u.def.value = htab->glink_pltresolve; | |
5687 | sh->ref_regular = 1; | |
5688 | sh->def_regular = 1; | |
5689 | sh->ref_regular_nonweak = 1; | |
5690 | sh->forced_local = 1; | |
5691 | sh->non_elf = 0; | |
5692 | } | |
5693 | sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve", | |
5694 | TRUE, FALSE, FALSE); | |
5695 | if (sh == NULL) | |
5696 | return FALSE; | |
5697 | if (sh->root.type == bfd_link_hash_new) | |
5698 | { | |
5699 | sh->root.type = bfd_link_hash_defined; | |
5700 | sh->root.u.def.section = htab->glink; | |
5701 | sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE; | |
5702 | sh->ref_regular = 1; | |
5703 | sh->def_regular = 1; | |
5704 | sh->ref_regular_nonweak = 1; | |
5705 | sh->forced_local = 1; | |
5706 | sh->non_elf = 0; | |
5707 | } | |
5708 | } | |
d7128ce4 AM |
5709 | } |
5710 | ||
25dbc73a AM |
5711 | /* We've now determined the sizes of the various dynamic sections. |
5712 | Allocate memory for them. */ | |
5713 | relocs = FALSE; | |
5714 | for (s = htab->elf.dynobj->sections; s != NULL; s = s->next) | |
252b5132 | 5715 | { |
9d8504b1 PB |
5716 | bfd_boolean strip_section = TRUE; |
5717 | ||
25dbc73a AM |
5718 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
5719 | continue; | |
252b5132 | 5720 | |
25dbc73a | 5721 | if (s == htab->plt |
e054468f | 5722 | || s == htab->got) |
25dbc73a | 5723 | { |
9d8504b1 PB |
5724 | /* We'd like to strip these sections if they aren't needed, but if |
5725 | we've exported dynamic symbols from them we must leave them. | |
5726 | It's too late to tell BFD to get rid of the symbols. */ | |
e054468f | 5727 | if (htab->elf.hplt != NULL) |
9d8504b1 | 5728 | strip_section = FALSE; |
25dbc73a AM |
5729 | /* Strip this section if we don't need it; see the |
5730 | comment below. */ | |
5731 | } | |
e054468f AM |
5732 | else if (s == htab->iplt |
5733 | || s == htab->glink | |
5734 | || s == htab->sgotplt | |
5735 | || s == htab->sbss | |
5736 | || s == htab->dynbss | |
5737 | || s == htab->dynsbss | |
5738 | || s == htab->sdata[0].section | |
c9a2f333 | 5739 | || s == htab->sdata[1].section) |
25dbc73a | 5740 | { |
c9a2f333 | 5741 | /* Strip these too. */ |
25dbc73a | 5742 | } |
0112cd26 | 5743 | else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) |
25dbc73a | 5744 | { |
c456f082 | 5745 | if (s->size != 0) |
25dbc73a AM |
5746 | { |
5747 | /* Remember whether there are any relocation sections. */ | |
5748 | relocs = TRUE; | |
252b5132 | 5749 | |
25dbc73a AM |
5750 | /* We use the reloc_count field as a counter if we need |
5751 | to copy relocs into the output file. */ | |
5752 | s->reloc_count = 0; | |
252b5132 RH |
5753 | } |
5754 | } | |
25dbc73a AM |
5755 | else |
5756 | { | |
5757 | /* It's not one of our sections, so don't allocate space. */ | |
5758 | continue; | |
5759 | } | |
252b5132 | 5760 | |
9d8504b1 | 5761 | if (s->size == 0 && strip_section) |
25dbc73a | 5762 | { |
c456f082 AM |
5763 | /* If we don't need this section, strip it from the |
5764 | output file. This is mostly to handle .rela.bss and | |
5765 | .rela.plt. We must create both sections in | |
5766 | create_dynamic_sections, because they must be created | |
5767 | before the linker maps input sections to output | |
5768 | sections. The linker does that before | |
5769 | adjust_dynamic_symbol is called, and it is that | |
5770 | function which decides whether anything needs to go | |
5771 | into these sections. */ | |
8423293d | 5772 | s->flags |= SEC_EXCLUDE; |
25dbc73a AM |
5773 | continue; |
5774 | } | |
7fce784e | 5775 | |
d7128ce4 | 5776 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
644285ef AM |
5777 | continue; |
5778 | ||
25dbc73a AM |
5779 | /* Allocate memory for the section contents. */ |
5780 | s->contents = bfd_zalloc (htab->elf.dynobj, s->size); | |
5781 | if (s->contents == NULL) | |
5782 | return FALSE; | |
5783 | } | |
252b5132 | 5784 | |
25dbc73a | 5785 | if (htab->elf.dynamic_sections_created) |
7619e7c7 | 5786 | { |
25dbc73a AM |
5787 | /* Add some entries to the .dynamic section. We fill in the |
5788 | values later, in ppc_elf_finish_dynamic_sections, but we | |
5789 | must add the entries now so that we get the correct size for | |
5790 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5791 | dynamic linker and used by the debugger. */ | |
5792 | #define add_dynamic_entry(TAG, VAL) \ | |
5793 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |
252b5132 | 5794 | |
25dbc73a | 5795 | if (info->executable) |
7619e7c7 | 5796 | { |
25dbc73a AM |
5797 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
5798 | return FALSE; | |
7619e7c7 AM |
5799 | } |
5800 | ||
25dbc73a | 5801 | if (htab->plt != NULL && htab->plt->size != 0) |
7619e7c7 | 5802 | { |
25dbc73a AM |
5803 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
5804 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
5805 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5806 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
5807 | return FALSE; | |
5808 | } | |
7619e7c7 | 5809 | |
d7128ce4 AM |
5810 | if (htab->glink != NULL && htab->glink->size != 0) |
5811 | { | |
1fe44d79 | 5812 | if (!add_dynamic_entry (DT_PPC_GOT, 0)) |
d7128ce4 AM |
5813 | return FALSE; |
5814 | } | |
5815 | ||
25dbc73a AM |
5816 | if (relocs) |
5817 | { | |
5818 | if (!add_dynamic_entry (DT_RELA, 0) | |
5819 | || !add_dynamic_entry (DT_RELASZ, 0) | |
5820 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
5821 | return FALSE; | |
5822 | } | |
7619e7c7 | 5823 | |
25dbc73a AM |
5824 | /* If any dynamic relocs apply to a read-only section, then we |
5825 | need a DT_TEXTREL entry. */ | |
5826 | if ((info->flags & DF_TEXTREL) == 0) | |
625af618 | 5827 | elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel, |
25dbc73a | 5828 | info); |
7619e7c7 | 5829 | |
25dbc73a AM |
5830 | if ((info->flags & DF_TEXTREL) != 0) |
5831 | { | |
5832 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
5833 | return FALSE; | |
7619e7c7 | 5834 | } |
7a2b07ff NS |
5835 | if (htab->is_vxworks |
5836 | && !elf_vxworks_add_dynamic_entries (output_bfd, info)) | |
5837 | return FALSE; | |
5838 | } | |
25dbc73a AM |
5839 | #undef add_dynamic_entry |
5840 | ||
7619e7c7 AM |
5841 | return TRUE; |
5842 | } | |
0eb4a168 AM |
5843 | |
5844 | /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ | |
5845 | ||
5846 | static bfd_boolean | |
5847 | ppc_elf_hash_symbol (struct elf_link_hash_entry *h) | |
5848 | { | |
5849 | if (h->plt.plist != NULL | |
5850 | && !h->def_regular | |
5851 | && (!h->pointer_equality_needed | |
5852 | || !h->ref_regular_nonweak)) | |
5853 | return FALSE; | |
5854 | ||
5855 | return _bfd_elf_hash_symbol (h); | |
5856 | } | |
25dbc73a AM |
5857 | \f |
5858 | #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) | |
5859 | ||
5860 | static const int shared_stub_entry[] = | |
5861 | { | |
5862 | 0x7c0802a6, /* mflr 0 */ | |
5863 | 0x429f0005, /* bcl 20, 31, .Lxxx */ | |
5864 | 0x7d6802a6, /* mflr 11 */ | |
5865 | 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */ | |
5866 | 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */ | |
5867 | 0x7c0803a6, /* mtlr 0 */ | |
5868 | 0x7d6903a6, /* mtctr 11 */ | |
5869 | 0x4e800420, /* bctr */ | |
5870 | }; | |
5871 | ||
5872 | static const int stub_entry[] = | |
5873 | { | |
5874 | 0x3d600000, /* lis 11,xxx@ha */ | |
5875 | 0x396b0000, /* addi 11,11,xxx@l */ | |
5876 | 0x7d6903a6, /* mtctr 11 */ | |
5877 | 0x4e800420, /* bctr */ | |
5878 | }; | |
5879 | ||
5880 | static bfd_boolean | |
5881 | ppc_elf_relax_section (bfd *abfd, | |
5882 | asection *isec, | |
5883 | struct bfd_link_info *link_info, | |
5884 | bfd_boolean *again) | |
5885 | { | |
5886 | struct one_fixup | |
5887 | { | |
5888 | struct one_fixup *next; | |
5889 | asection *tsec; | |
5890 | bfd_vma toff; | |
5891 | bfd_vma trampoff; | |
5892 | }; | |
7619e7c7 | 5893 | |
25dbc73a AM |
5894 | Elf_Internal_Shdr *symtab_hdr; |
5895 | bfd_byte *contents = NULL; | |
5896 | Elf_Internal_Sym *isymbuf = NULL; | |
5897 | Elf_Internal_Rela *internal_relocs = NULL; | |
5898 | Elf_Internal_Rela *irel, *irelend; | |
5899 | struct one_fixup *fixups = NULL; | |
9bc4e62b | 5900 | unsigned changes = 0; |
d7128ce4 | 5901 | struct ppc_elf_link_hash_table *htab; |
25dbc73a | 5902 | bfd_size_type trampoff; |
a6aa5195 | 5903 | asection *got2; |
7619e7c7 | 5904 | |
25dbc73a | 5905 | *again = FALSE; |
7619e7c7 | 5906 | |
c87b5a93 | 5907 | /* Nothing to do if there are no relocations, and no need to do |
a8ad78a7 | 5908 | anything with non-alloc or non-code sections. */ |
c87b5a93 | 5909 | if ((isec->flags & SEC_ALLOC) == 0 |
a8ad78a7 | 5910 | || (isec->flags & SEC_CODE) == 0 |
c87b5a93 AM |
5911 | || (isec->flags & SEC_RELOC) == 0 |
5912 | || isec->reloc_count == 0) | |
25dbc73a | 5913 | return TRUE; |
7619e7c7 | 5914 | |
c8a1f254 NS |
5915 | /* We cannot represent the required PIC relocs in the output, so don't |
5916 | do anything. The linker doesn't support mixing -shared and -r | |
5917 | anyway. */ | |
5918 | if (link_info->relocatable && link_info->shared) | |
5919 | return TRUE; | |
5920 | ||
25dbc73a AM |
5921 | trampoff = (isec->size + 3) & (bfd_vma) -4; |
5922 | /* Space for a branch around any trampolines. */ | |
5923 | trampoff += 4; | |
7619e7c7 | 5924 | |
0ffa91dd | 5925 | symtab_hdr = &elf_symtab_hdr (abfd); |
7619e7c7 | 5926 | |
25dbc73a AM |
5927 | /* Get a copy of the native relocations. */ |
5928 | internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, | |
5929 | link_info->keep_memory); | |
5930 | if (internal_relocs == NULL) | |
5931 | goto error_return; | |
7619e7c7 | 5932 | |
d7128ce4 | 5933 | htab = ppc_elf_hash_table (link_info); |
a6aa5195 | 5934 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
7619e7c7 | 5935 | |
a6aa5195 | 5936 | irelend = internal_relocs + isec->reloc_count; |
25dbc73a | 5937 | for (irel = internal_relocs; irel < irelend; irel++) |
7619e7c7 | 5938 | { |
25dbc73a AM |
5939 | unsigned long r_type = ELF32_R_TYPE (irel->r_info); |
5940 | bfd_vma symaddr, reladdr, toff, roff; | |
5941 | asection *tsec; | |
5942 | struct one_fixup *f; | |
5943 | size_t insn_offset = 0; | |
5944 | bfd_vma max_branch_offset, val; | |
5945 | bfd_byte *hit_addr; | |
5946 | unsigned long t0; | |
de972ffa | 5947 | struct elf_link_hash_entry *h; |
a9585d22 | 5948 | struct plt_entry **plist; |
25dbc73a | 5949 | unsigned char sym_type; |
7619e7c7 | 5950 | |
25dbc73a AM |
5951 | switch (r_type) |
5952 | { | |
5953 | case R_PPC_REL24: | |
5954 | case R_PPC_LOCAL24PC: | |
5955 | case R_PPC_PLTREL24: | |
5956 | max_branch_offset = 1 << 25; | |
5957 | break; | |
7619e7c7 | 5958 | |
25dbc73a AM |
5959 | case R_PPC_REL14: |
5960 | case R_PPC_REL14_BRTAKEN: | |
5961 | case R_PPC_REL14_BRNTAKEN: | |
5962 | max_branch_offset = 1 << 15; | |
5963 | break; | |
7619e7c7 | 5964 | |
25dbc73a AM |
5965 | default: |
5966 | continue; | |
5967 | } | |
7619e7c7 | 5968 | |
25dbc73a | 5969 | /* Get the value of the symbol referred to by the reloc. */ |
de972ffa | 5970 | h = NULL; |
25dbc73a AM |
5971 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
5972 | { | |
5973 | /* A local symbol. */ | |
5974 | Elf_Internal_Sym *isym; | |
7fce784e | 5975 | |
25dbc73a AM |
5976 | /* Read this BFD's local symbols. */ |
5977 | if (isymbuf == NULL) | |
5978 | { | |
5979 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
5980 | if (isymbuf == NULL) | |
5981 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
5982 | symtab_hdr->sh_info, 0, | |
5983 | NULL, NULL, NULL); | |
5984 | if (isymbuf == 0) | |
5985 | goto error_return; | |
5986 | } | |
5987 | isym = isymbuf + ELF32_R_SYM (irel->r_info); | |
5988 | if (isym->st_shndx == SHN_UNDEF) | |
c8a1f254 | 5989 | tsec = bfd_und_section_ptr; |
25dbc73a AM |
5990 | else if (isym->st_shndx == SHN_ABS) |
5991 | tsec = bfd_abs_section_ptr; | |
5992 | else if (isym->st_shndx == SHN_COMMON) | |
5993 | tsec = bfd_com_section_ptr; | |
5994 | else | |
5995 | tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
7fce784e | 5996 | |
25dbc73a AM |
5997 | toff = isym->st_value; |
5998 | sym_type = ELF_ST_TYPE (isym->st_info); | |
5999 | } | |
6000 | else | |
6001 | { | |
6002 | /* Global symbol handling. */ | |
6003 | unsigned long indx; | |
7619e7c7 | 6004 | |
25dbc73a AM |
6005 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
6006 | h = elf_sym_hashes (abfd)[indx]; | |
7619e7c7 | 6007 | |
25dbc73a AM |
6008 | while (h->root.type == bfd_link_hash_indirect |
6009 | || h->root.type == bfd_link_hash_warning) | |
6010 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 6011 | |
a9585d22 AM |
6012 | if (h->root.type == bfd_link_hash_defined |
6013 | || h->root.type == bfd_link_hash_defweak) | |
25dbc73a AM |
6014 | { |
6015 | tsec = h->root.u.def.section; | |
6016 | toff = h->root.u.def.value; | |
6017 | } | |
c8a1f254 NS |
6018 | else if (h->root.type == bfd_link_hash_undefined |
6019 | || h->root.type == bfd_link_hash_undefweak) | |
6020 | { | |
6021 | tsec = bfd_und_section_ptr; | |
6022 | toff = 0; | |
6023 | } | |
25dbc73a AM |
6024 | else |
6025 | continue; | |
7619e7c7 | 6026 | |
25dbc73a AM |
6027 | sym_type = h->type; |
6028 | } | |
7619e7c7 | 6029 | |
a9585d22 AM |
6030 | /* The condition here under which we call find_plt_ent must |
6031 | match that in relocate_section. If we call find_plt_ent here | |
6032 | but not in relocate_section, or vice versa, then the branch | |
6033 | destination used here may be incorrect. */ | |
6034 | plist = NULL; | |
6035 | if (h != NULL) | |
de972ffa | 6036 | { |
a9585d22 AM |
6037 | /* We know is_branch_reloc (r_type) is true. */ |
6038 | if (h->type == STT_GNU_IFUNC | |
6039 | || r_type == R_PPC_PLTREL24) | |
de972ffa | 6040 | plist = &h->plt.plist; |
a9585d22 AM |
6041 | } |
6042 | else if (sym_type == STT_GNU_IFUNC | |
6043 | && elf_local_got_offsets (abfd) != NULL) | |
6044 | { | |
6045 | bfd_vma *local_got_offsets = elf_local_got_offsets (abfd); | |
6046 | struct plt_entry **local_plt = (struct plt_entry **) | |
6047 | (local_got_offsets + symtab_hdr->sh_info); | |
6048 | plist = local_plt + ELF32_R_SYM (irel->r_info); | |
6049 | } | |
6050 | if (plist != NULL) | |
6051 | { | |
6052 | bfd_vma addend = 0; | |
6053 | struct plt_entry *ent; | |
de972ffa | 6054 | |
a9585d22 AM |
6055 | if (r_type == R_PPC_PLTREL24 && link_info->shared) |
6056 | addend = irel->r_addend; | |
6057 | ent = find_plt_ent (plist, got2, addend); | |
6058 | if (ent != NULL) | |
6059 | { | |
6060 | if (htab->plt_type == PLT_NEW | |
6061 | || h == NULL | |
6062 | || !htab->elf.dynamic_sections_created | |
6063 | || h->dynindx == -1) | |
de972ffa | 6064 | { |
a9585d22 AM |
6065 | tsec = htab->glink; |
6066 | toff = ent->glink_offset; | |
6067 | } | |
6068 | else | |
6069 | { | |
6070 | tsec = htab->plt; | |
6071 | toff = ent->plt.offset; | |
de972ffa AM |
6072 | } |
6073 | } | |
6074 | } | |
6075 | ||
25dbc73a AM |
6076 | /* If the branch and target are in the same section, you have |
6077 | no hope of adding stubs. We'll error out later should the | |
6078 | branch overflow. */ | |
6079 | if (tsec == isec) | |
6080 | continue; | |
6081 | ||
6082 | /* There probably isn't any reason to handle symbols in | |
6083 | SEC_MERGE sections; SEC_MERGE doesn't seem a likely | |
6084 | attribute for a code section, and we are only looking at | |
6085 | branches. However, implement it correctly here as a | |
6086 | reference for other target relax_section functions. */ | |
6087 | if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE) | |
6088 | { | |
6089 | /* At this stage in linking, no SEC_MERGE symbol has been | |
6090 | adjusted, so all references to such symbols need to be | |
6091 | passed through _bfd_merged_section_offset. (Later, in | |
6092 | relocate_section, all SEC_MERGE symbols *except* for | |
6093 | section symbols have been adjusted.) | |
6094 | ||
6095 | gas may reduce relocations against symbols in SEC_MERGE | |
6096 | sections to a relocation against the section symbol when | |
6097 | the original addend was zero. When the reloc is against | |
6098 | a section symbol we should include the addend in the | |
6099 | offset passed to _bfd_merged_section_offset, since the | |
6100 | location of interest is the original symbol. On the | |
6101 | other hand, an access to "sym+addend" where "sym" is not | |
6102 | a section symbol should not include the addend; Such an | |
6103 | access is presumed to be an offset from "sym"; The | |
6104 | location of interest is just "sym". */ | |
6105 | if (sym_type == STT_SECTION) | |
6106 | toff += irel->r_addend; | |
7619e7c7 | 6107 | |
25dbc73a AM |
6108 | toff = _bfd_merged_section_offset (abfd, &tsec, |
6109 | elf_section_data (tsec)->sec_info, | |
6110 | toff); | |
7619e7c7 | 6111 | |
25dbc73a AM |
6112 | if (sym_type != STT_SECTION) |
6113 | toff += irel->r_addend; | |
6114 | } | |
a6aa5195 AM |
6115 | /* PLTREL24 addends are special. */ |
6116 | else if (r_type != R_PPC_PLTREL24) | |
25dbc73a | 6117 | toff += irel->r_addend; |
7619e7c7 | 6118 | |
7de713b9 AM |
6119 | /* Attempted -shared link of non-pic code loses. */ |
6120 | if (tsec->output_section == NULL) | |
6121 | continue; | |
6122 | ||
25dbc73a | 6123 | symaddr = tsec->output_section->vma + tsec->output_offset + toff; |
7619e7c7 | 6124 | |
25dbc73a AM |
6125 | roff = irel->r_offset; |
6126 | reladdr = isec->output_section->vma + isec->output_offset + roff; | |
7619e7c7 | 6127 | |
25dbc73a | 6128 | /* If the branch is in range, no need to do anything. */ |
c8a1f254 NS |
6129 | if (tsec != bfd_und_section_ptr |
6130 | && (!link_info->relocatable | |
6131 | /* A relocatable link may have sections moved during | |
6132 | final link, so do not presume they remain in range. */ | |
6133 | || tsec->output_section == isec->output_section) | |
6134 | && symaddr - reladdr + max_branch_offset < 2 * max_branch_offset) | |
25dbc73a | 6135 | continue; |
252b5132 | 6136 | |
25dbc73a AM |
6137 | /* Look for an existing fixup to this address. */ |
6138 | for (f = fixups; f ; f = f->next) | |
6139 | if (f->tsec == tsec && f->toff == toff) | |
6140 | break; | |
6141 | ||
6142 | if (f == NULL) | |
7619e7c7 | 6143 | { |
25dbc73a AM |
6144 | size_t size; |
6145 | unsigned long stub_rtype; | |
252b5132 | 6146 | |
25dbc73a AM |
6147 | val = trampoff - roff; |
6148 | if (val >= max_branch_offset) | |
6149 | /* Oh dear, we can't reach a trampoline. Don't try to add | |
6150 | one. We'll report an error later. */ | |
6151 | continue; | |
252b5132 | 6152 | |
25dbc73a AM |
6153 | if (link_info->shared) |
6154 | { | |
6155 | size = 4 * ARRAY_SIZE (shared_stub_entry); | |
6156 | insn_offset = 12; | |
6157 | stub_rtype = R_PPC_RELAX32PC; | |
6158 | } | |
6159 | else | |
6160 | { | |
6161 | size = 4 * ARRAY_SIZE (stub_entry); | |
6162 | insn_offset = 0; | |
6163 | stub_rtype = R_PPC_RELAX32; | |
6164 | } | |
dc810e39 | 6165 | |
25dbc73a AM |
6166 | if (R_PPC_RELAX32_PLT - R_PPC_RELAX32 |
6167 | != R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC) | |
6168 | abort (); | |
d7128ce4 AM |
6169 | if (tsec == htab->plt |
6170 | || tsec == htab->glink) | |
25dbc73a | 6171 | stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32; |
252b5132 | 6172 | |
25dbc73a AM |
6173 | /* Hijack the old relocation. Since we need two |
6174 | relocations for this use a "composite" reloc. */ | |
6175 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
6176 | stub_rtype); | |
6177 | irel->r_offset = trampoff + insn_offset; | |
e7d92e2e AM |
6178 | if (r_type == R_PPC_PLTREL24) |
6179 | irel->r_addend = 0; | |
252b5132 | 6180 | |
25dbc73a AM |
6181 | /* Record the fixup so we don't do it again this section. */ |
6182 | f = bfd_malloc (sizeof (*f)); | |
6183 | f->next = fixups; | |
6184 | f->tsec = tsec; | |
6185 | f->toff = toff; | |
6186 | f->trampoff = trampoff; | |
6187 | fixups = f; | |
252b5132 | 6188 | |
25dbc73a | 6189 | trampoff += size; |
9bc4e62b | 6190 | changes++; |
25dbc73a AM |
6191 | } |
6192 | else | |
6193 | { | |
6194 | val = f->trampoff - roff; | |
6195 | if (val >= max_branch_offset) | |
6196 | continue; | |
252b5132 | 6197 | |
25dbc73a AM |
6198 | /* Nop out the reloc, since we're finalizing things here. */ |
6199 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
6200 | } | |
252b5132 | 6201 | |
25dbc73a AM |
6202 | /* Get the section contents. */ |
6203 | if (contents == NULL) | |
6204 | { | |
6205 | /* Get cached copy if it exists. */ | |
6206 | if (elf_section_data (isec)->this_hdr.contents != NULL) | |
6207 | contents = elf_section_data (isec)->this_hdr.contents; | |
6208 | else | |
6209 | { | |
6210 | /* Go get them off disk. */ | |
6211 | if (!bfd_malloc_and_get_section (abfd, isec, &contents)) | |
6212 | goto error_return; | |
6213 | } | |
6214 | } | |
252b5132 | 6215 | |
25dbc73a AM |
6216 | /* Fix up the existing branch to hit the trampoline. */ |
6217 | hit_addr = contents + roff; | |
6218 | switch (r_type) | |
6219 | { | |
6220 | case R_PPC_REL24: | |
6221 | case R_PPC_LOCAL24PC: | |
6222 | case R_PPC_PLTREL24: | |
6223 | t0 = bfd_get_32 (abfd, hit_addr); | |
6224 | t0 &= ~0x3fffffc; | |
6225 | t0 |= val & 0x3fffffc; | |
6226 | bfd_put_32 (abfd, t0, hit_addr); | |
6227 | break; | |
252b5132 | 6228 | |
25dbc73a AM |
6229 | case R_PPC_REL14: |
6230 | case R_PPC_REL14_BRTAKEN: | |
6231 | case R_PPC_REL14_BRNTAKEN: | |
6232 | t0 = bfd_get_32 (abfd, hit_addr); | |
6233 | t0 &= ~0xfffc; | |
6234 | t0 |= val & 0xfffc; | |
6235 | bfd_put_32 (abfd, t0, hit_addr); | |
6236 | break; | |
6237 | } | |
6238 | } | |
252b5132 | 6239 | |
25dbc73a | 6240 | /* Write out the trampolines. */ |
25dbc73a AM |
6241 | if (fixups != NULL) |
6242 | { | |
6243 | const int *stub; | |
6244 | bfd_byte *dest; | |
6245 | bfd_vma val; | |
6246 | int i, size; | |
252b5132 | 6247 | |
25dbc73a AM |
6248 | do |
6249 | { | |
6250 | struct one_fixup *f = fixups; | |
6251 | fixups = fixups->next; | |
6252 | free (f); | |
6253 | } | |
6254 | while (fixups); | |
252b5132 | 6255 | |
515ef31d | 6256 | contents = bfd_realloc_or_free (contents, trampoff); |
25dbc73a AM |
6257 | if (contents == NULL) |
6258 | goto error_return; | |
252b5132 | 6259 | |
25dbc73a AM |
6260 | isec->size = (isec->size + 3) & (bfd_vma) -4; |
6261 | /* Branch around the trampolines. */ | |
e7d92e2e | 6262 | val = B + trampoff - isec->size; |
25dbc73a AM |
6263 | dest = contents + isec->size; |
6264 | isec->size = trampoff; | |
6265 | bfd_put_32 (abfd, val, dest); | |
6266 | dest += 4; | |
252b5132 | 6267 | |
25dbc73a AM |
6268 | if (link_info->shared) |
6269 | { | |
6270 | stub = shared_stub_entry; | |
6271 | size = ARRAY_SIZE (shared_stub_entry); | |
6272 | } | |
6273 | else | |
6274 | { | |
6275 | stub = stub_entry; | |
6276 | size = ARRAY_SIZE (stub_entry); | |
6277 | } | |
252b5132 | 6278 | |
25dbc73a AM |
6279 | i = 0; |
6280 | while (dest < contents + trampoff) | |
252b5132 | 6281 | { |
25dbc73a AM |
6282 | bfd_put_32 (abfd, stub[i], dest); |
6283 | i++; | |
6284 | if (i == size) | |
6285 | i = 0; | |
6286 | dest += 4; | |
252b5132 | 6287 | } |
25dbc73a | 6288 | BFD_ASSERT (i == 0); |
252b5132 RH |
6289 | } |
6290 | ||
25dbc73a AM |
6291 | if (isymbuf != NULL |
6292 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
252b5132 | 6293 | { |
25dbc73a AM |
6294 | if (! link_info->keep_memory) |
6295 | free (isymbuf); | |
252b5132 | 6296 | else |
25dbc73a AM |
6297 | { |
6298 | /* Cache the symbols for elf_link_input_bfd. */ | |
6299 | symtab_hdr->contents = (unsigned char *) isymbuf; | |
6300 | } | |
252b5132 RH |
6301 | } |
6302 | ||
25dbc73a AM |
6303 | if (contents != NULL |
6304 | && elf_section_data (isec)->this_hdr.contents != contents) | |
6305 | { | |
9bc4e62b | 6306 | if (!changes && !link_info->keep_memory) |
25dbc73a AM |
6307 | free (contents); |
6308 | else | |
6309 | { | |
6310 | /* Cache the section contents for elf_link_input_bfd. */ | |
6311 | elf_section_data (isec)->this_hdr.contents = contents; | |
6312 | } | |
6313 | } | |
252b5132 | 6314 | |
9bc4e62b | 6315 | if (changes != 0) |
25dbc73a | 6316 | { |
9bc4e62b NS |
6317 | /* Append sufficient NOP relocs so we can write out relocation |
6318 | information for the trampolines. */ | |
6319 | Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count) | |
6320 | * sizeof (*new_relocs)); | |
6321 | unsigned ix; | |
6322 | ||
6323 | if (!new_relocs) | |
6324 | goto error_return; | |
6325 | memcpy (new_relocs, internal_relocs, | |
6326 | isec->reloc_count * sizeof (*new_relocs)); | |
6327 | for (ix = changes; ix--;) | |
6328 | { | |
6329 | irel = new_relocs + ix + isec->reloc_count; | |
6330 | ||
6331 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
6332 | } | |
6333 | if (internal_relocs != elf_section_data (isec)->relocs) | |
25dbc73a | 6334 | free (internal_relocs); |
9bc4e62b NS |
6335 | elf_section_data (isec)->relocs = new_relocs; |
6336 | isec->reloc_count += changes; | |
6337 | elf_section_data (isec)->rel_hdr.sh_size | |
6338 | += changes * elf_section_data (isec)->rel_hdr.sh_entsize; | |
25dbc73a | 6339 | } |
9bc4e62b NS |
6340 | else if (elf_section_data (isec)->relocs != internal_relocs) |
6341 | free (internal_relocs); | |
252b5132 | 6342 | |
9bc4e62b | 6343 | *again = changes != 0; |
c8a1f254 NS |
6344 | if (!*again && link_info->relocatable) |
6345 | { | |
6346 | /* Convert the internal relax relocs to external form. */ | |
6347 | for (irel = internal_relocs; irel < irelend; irel++) | |
6348 | if (ELF32_R_TYPE (irel->r_info) == R_PPC_RELAX32) | |
6349 | { | |
6350 | unsigned long r_symndx = ELF32_R_SYM (irel->r_info); | |
6351 | ||
6352 | /* Rewrite the reloc and convert one of the trailing nop | |
6353 | relocs to describe this relocation. */ | |
6354 | BFD_ASSERT (ELF32_R_TYPE (irelend[-1].r_info) == R_PPC_NONE); | |
6355 | /* The relocs are at the bottom 2 bytes */ | |
6356 | irel[0].r_offset += 2; | |
6357 | memmove (irel + 1, irel, (irelend - irel - 1) * sizeof (*irel)); | |
6358 | irel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); | |
6359 | irel[1].r_offset += 4; | |
6360 | irel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); | |
6361 | irel++; | |
6362 | } | |
6363 | } | |
6364 | ||
b34976b6 | 6365 | return TRUE; |
25dbc73a AM |
6366 | |
6367 | error_return: | |
6368 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents) | |
6369 | free (isymbuf); | |
6370 | if (contents != NULL | |
6371 | && elf_section_data (isec)->this_hdr.contents != contents) | |
6372 | free (contents); | |
6373 | if (internal_relocs != NULL | |
6374 | && elf_section_data (isec)->relocs != internal_relocs) | |
6375 | free (internal_relocs); | |
6376 | return FALSE; | |
252b5132 | 6377 | } |
252b5132 | 6378 | \f |
8a696751 AM |
6379 | /* What to do when ld finds relocations against symbols defined in |
6380 | discarded sections. */ | |
6381 | ||
6382 | static unsigned int | |
6383 | ppc_elf_action_discarded (asection *sec) | |
6384 | { | |
6385 | if (strcmp (".fixup", sec->name) == 0) | |
6386 | return 0; | |
6387 | ||
6388 | if (strcmp (".got2", sec->name) == 0) | |
6389 | return 0; | |
6390 | ||
6391 | return _bfd_elf_default_action_discarded (sec); | |
6392 | } | |
c9a2f333 | 6393 | \f |
25dbc73a | 6394 | /* Fill in the address for a pointer generated in a linker section. */ |
252b5132 | 6395 | |
25dbc73a | 6396 | static bfd_vma |
76750a2f | 6397 | elf_finish_pointer_linker_section (bfd *input_bfd, |
25dbc73a AM |
6398 | elf_linker_section_t *lsect, |
6399 | struct elf_link_hash_entry *h, | |
6400 | bfd_vma relocation, | |
2bb04cf2 | 6401 | const Elf_Internal_Rela *rel) |
25dbc73a AM |
6402 | { |
6403 | elf_linker_section_pointers_t *linker_section_ptr; | |
252b5132 | 6404 | |
25dbc73a | 6405 | BFD_ASSERT (lsect != NULL); |
252b5132 | 6406 | |
25dbc73a | 6407 | if (h != NULL) |
252b5132 | 6408 | { |
25dbc73a AM |
6409 | /* Handle global symbol. */ |
6410 | struct ppc_elf_link_hash_entry *eh; | |
252b5132 | 6411 | |
25dbc73a | 6412 | eh = (struct ppc_elf_link_hash_entry *) h; |
76750a2f AM |
6413 | BFD_ASSERT (eh->elf.def_regular); |
6414 | linker_section_ptr = eh->linker_section_pointer; | |
25dbc73a AM |
6415 | } |
6416 | else | |
6417 | { | |
6418 | /* Handle local symbol. */ | |
6419 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
76750a2f | 6420 | |
0c8d6e5c | 6421 | BFD_ASSERT (is_ppc_elf (input_bfd)); |
25dbc73a | 6422 | BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); |
76750a2f AM |
6423 | linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx]; |
6424 | } | |
252b5132 | 6425 | |
76750a2f AM |
6426 | linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr, |
6427 | rel->r_addend, | |
6428 | lsect); | |
6429 | BFD_ASSERT (linker_section_ptr != NULL); | |
25dbc73a | 6430 | |
76750a2f AM |
6431 | /* Offset will always be a multiple of four, so use the bottom bit |
6432 | as a "written" flag. */ | |
6433 | if ((linker_section_ptr->offset & 1) == 0) | |
6434 | { | |
6435 | bfd_put_32 (lsect->section->owner, | |
6436 | relocation + linker_section_ptr->addend, | |
6437 | lsect->section->contents + linker_section_ptr->offset); | |
6438 | linker_section_ptr->offset += 1; | |
252b5132 RH |
6439 | } |
6440 | ||
25dbc73a | 6441 | relocation = (lsect->section->output_offset |
76750a2f | 6442 | + linker_section_ptr->offset - 1 |
c9a2f333 | 6443 | - 0x8000); |
252b5132 | 6444 | |
25dbc73a AM |
6445 | #ifdef DEBUG |
6446 | fprintf (stderr, | |
6447 | "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", | |
6448 | lsect->name, (long) relocation, (long) relocation); | |
6449 | #endif | |
252b5132 | 6450 | |
25dbc73a AM |
6451 | /* Subtract out the addend, because it will get added back in by the normal |
6452 | processing. */ | |
6453 | return relocation - linker_section_ptr->addend; | |
252b5132 | 6454 | } |
25dbc73a | 6455 | |
e054468f AM |
6456 | #define PPC_LO(v) ((v) & 0xffff) |
6457 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6458 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6459 | ||
6460 | static void | |
6461 | write_glink_stub (struct plt_entry *ent, asection *plt_sec, | |
6462 | struct bfd_link_info *info) | |
6463 | { | |
6464 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
6465 | bfd *output_bfd = info->output_bfd; | |
6466 | bfd_vma plt; | |
6467 | unsigned char *p; | |
6468 | ||
6469 | plt = ((ent->plt.offset & ~1) | |
6470 | + plt_sec->output_section->vma | |
6471 | + plt_sec->output_offset); | |
6472 | p = (unsigned char *) htab->glink->contents + ent->glink_offset; | |
6473 | ||
a877a2b6 | 6474 | if (info->shared) |
e054468f AM |
6475 | { |
6476 | bfd_vma got = 0; | |
6477 | ||
6478 | if (ent->addend >= 32768) | |
6479 | got = (ent->addend | |
6480 | + ent->sec->output_section->vma | |
6481 | + ent->sec->output_offset); | |
6482 | else if (htab->elf.hgot != NULL) | |
6483 | got = SYM_VAL (htab->elf.hgot); | |
6484 | ||
6485 | plt -= got; | |
6486 | ||
6487 | if (plt + 0x8000 < 0x10000) | |
6488 | { | |
6489 | bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p); | |
6490 | p += 4; | |
6491 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6492 | p += 4; | |
6493 | bfd_put_32 (output_bfd, BCTR, p); | |
6494 | p += 4; | |
6495 | bfd_put_32 (output_bfd, NOP, p); | |
6496 | p += 4; | |
6497 | } | |
6498 | else | |
6499 | { | |
6500 | bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p); | |
6501 | p += 4; | |
6502 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
6503 | p += 4; | |
6504 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6505 | p += 4; | |
6506 | bfd_put_32 (output_bfd, BCTR, p); | |
6507 | p += 4; | |
6508 | } | |
6509 | } | |
6510 | else | |
6511 | { | |
6512 | bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p); | |
6513 | p += 4; | |
6514 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
6515 | p += 4; | |
6516 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6517 | p += 4; | |
6518 | bfd_put_32 (output_bfd, BCTR, p); | |
6519 | p += 4; | |
6520 | } | |
6521 | } | |
6522 | ||
252b5132 RH |
6523 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
6524 | to handle the relocations for a section. | |
6525 | ||
6526 | The relocs are always passed as Rela structures; if the section | |
6527 | actually uses Rel structures, the r_addend field will always be | |
6528 | zero. | |
6529 | ||
6530 | This function is responsible for adjust the section contents as | |
6531 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 6532 | relocatable output file) adjusting the reloc addend as |
252b5132 RH |
6533 | necessary. |
6534 | ||
6535 | This function does not have to worry about setting the reloc | |
6536 | address or the reloc symbol index. | |
6537 | ||
6538 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
6539 | ||
6540 | LOCAL_SECTIONS is an array giving the section in the input file | |
6541 | corresponding to the st_shndx field of each local symbol. | |
6542 | ||
6543 | The global hash table entry for the global symbols can be found | |
6544 | via elf_sym_hashes (input_bfd). | |
6545 | ||
1049f94e | 6546 | When generating relocatable output, this function must handle |
252b5132 RH |
6547 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
6548 | going to be the section symbol corresponding to the output | |
6549 | section, which means that the addend must be adjusted | |
6550 | accordingly. */ | |
6551 | ||
b34976b6 | 6552 | static bfd_boolean |
55fd94b0 AM |
6553 | ppc_elf_relocate_section (bfd *output_bfd, |
6554 | struct bfd_link_info *info, | |
6555 | bfd *input_bfd, | |
6556 | asection *input_section, | |
6557 | bfd_byte *contents, | |
6558 | Elf_Internal_Rela *relocs, | |
6559 | Elf_Internal_Sym *local_syms, | |
6560 | asection **local_sections) | |
252b5132 | 6561 | { |
7619e7c7 AM |
6562 | Elf_Internal_Shdr *symtab_hdr; |
6563 | struct elf_link_hash_entry **sym_hashes; | |
6564 | struct ppc_elf_link_hash_table *htab; | |
6565 | Elf_Internal_Rela *rel; | |
6566 | Elf_Internal_Rela *relend; | |
6567 | Elf_Internal_Rela outrel; | |
6568 | bfd_byte *loc; | |
a6aa5195 | 6569 | asection *got2, *sreloc = NULL; |
252b5132 | 6570 | bfd_vma *local_got_offsets; |
b34976b6 | 6571 | bfd_boolean ret = TRUE; |
4fe5ca5b | 6572 | bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0); |
3348747a | 6573 | bfd_boolean is_vxworks_tls; |
b34976b6 | 6574 | |
252b5132 | 6575 | #ifdef DEBUG |
d003868e AM |
6576 | _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, " |
6577 | "%ld relocations%s", | |
6578 | input_bfd, input_section, | |
6579 | (long) input_section->reloc_count, | |
6580 | (info->relocatable) ? " (relocatable)" : ""); | |
252b5132 RH |
6581 | #endif |
6582 | ||
a6aa5195 AM |
6583 | got2 = bfd_get_section_by_name (input_bfd, ".got2"); |
6584 | ||
e47cd125 | 6585 | /* Initialize howto table if not already done. */ |
8da6118f | 6586 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
252b5132 RH |
6587 | ppc_elf_howto_init (); |
6588 | ||
7619e7c7 | 6589 | htab = ppc_elf_hash_table (info); |
252b5132 | 6590 | local_got_offsets = elf_local_got_offsets (input_bfd); |
0ffa91dd | 6591 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
7619e7c7 | 6592 | sym_hashes = elf_sym_hashes (input_bfd); |
3348747a NS |
6593 | /* We have to handle relocations in vxworks .tls_vars sections |
6594 | specially, because the dynamic loader is 'weird'. */ | |
6595 | is_vxworks_tls = (htab->is_vxworks && info->shared | |
6596 | && !strcmp (input_section->output_section->name, | |
6597 | ".tls_vars")); | |
7619e7c7 AM |
6598 | rel = relocs; |
6599 | relend = relocs + input_section->reloc_count; | |
252b5132 RH |
6600 | for (; rel < relend; rel++) |
6601 | { | |
7619e7c7 AM |
6602 | enum elf_ppc_reloc_type r_type; |
6603 | bfd_vma addend; | |
6604 | bfd_reloc_status_type r; | |
6605 | Elf_Internal_Sym *sym; | |
6606 | asection *sec; | |
6607 | struct elf_link_hash_entry *h; | |
6608 | const char *sym_name; | |
252b5132 RH |
6609 | reloc_howto_type *howto; |
6610 | unsigned long r_symndx; | |
6611 | bfd_vma relocation; | |
7619e7c7 | 6612 | bfd_vma branch_bit, insn, from; |
7619e7c7 AM |
6613 | bfd_boolean unresolved_reloc; |
6614 | bfd_boolean warned; | |
6615 | unsigned int tls_type, tls_mask, tls_gd; | |
e054468f | 6616 | struct plt_entry **ifunc; |
7619e7c7 | 6617 | |
55fd94b0 AM |
6618 | r_type = ELF32_R_TYPE (rel->r_info); |
6619 | sym = NULL; | |
6620 | sec = NULL; | |
6621 | h = NULL; | |
7619e7c7 AM |
6622 | unresolved_reloc = FALSE; |
6623 | warned = FALSE; | |
252b5132 | 6624 | r_symndx = ELF32_R_SYM (rel->r_info); |
560e09e9 | 6625 | |
252b5132 RH |
6626 | if (r_symndx < symtab_hdr->sh_info) |
6627 | { | |
6628 | sym = local_syms + r_symndx; | |
6629 | sec = local_sections[r_symndx]; | |
26c61ae5 | 6630 | sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec); |
252b5132 | 6631 | |
8517fae7 | 6632 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
252b5132 RH |
6633 | } |
6634 | else | |
6635 | { | |
b2a8e766 AM |
6636 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
6637 | r_symndx, symtab_hdr, sym_hashes, | |
6638 | h, sec, relocation, | |
6639 | unresolved_reloc, warned); | |
9abc968f | 6640 | |
252b5132 | 6641 | sym_name = h->root.root.string; |
7619e7c7 AM |
6642 | } |
6643 | ||
ab96bf03 AM |
6644 | if (sec != NULL && elf_discarded_section (sec)) |
6645 | { | |
6646 | /* For relocs against symbols from removed linkonce sections, | |
6647 | or sections discarded by a linker script, we just want the | |
6648 | section contents zeroed. Avoid any special processing. */ | |
6649 | howto = NULL; | |
6650 | if (r_type < R_PPC_max) | |
6651 | howto = ppc_elf_howto_table[r_type]; | |
6652 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); | |
6653 | rel->r_info = 0; | |
6654 | rel->r_addend = 0; | |
6655 | continue; | |
6656 | } | |
6657 | ||
6658 | if (info->relocatable) | |
6659 | { | |
6660 | if (got2 != NULL | |
6661 | && r_type == R_PPC_PLTREL24 | |
6662 | && rel->r_addend >= 32768) | |
6663 | { | |
6664 | /* R_PPC_PLTREL24 is rather special. If non-zero, the | |
6665 | addend specifies the GOT pointer offset within .got2. */ | |
6666 | rel->r_addend += got2->output_offset; | |
6667 | } | |
6668 | continue; | |
6669 | } | |
6670 | ||
7619e7c7 AM |
6671 | /* TLS optimizations. Replace instruction sequences and relocs |
6672 | based on information we collected in tls_optimize. We edit | |
6673 | RELOCS so that --emit-relocs will output something sensible | |
6674 | for the final instruction stream. */ | |
6675 | tls_mask = 0; | |
6676 | tls_gd = 0; | |
727fc41e AM |
6677 | if (h != NULL) |
6678 | tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask; | |
6679 | else if (local_got_offsets != NULL) | |
7619e7c7 | 6680 | { |
e054468f | 6681 | struct plt_entry **local_plt; |
727fc41e | 6682 | char *lgot_masks; |
e054468f AM |
6683 | local_plt |
6684 | = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info); | |
6685 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
727fc41e | 6686 | tls_mask = lgot_masks[r_symndx]; |
7619e7c7 AM |
6687 | } |
6688 | ||
6689 | /* Ensure reloc mapping code below stays sane. */ | |
6690 | if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3) | |
6691 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3) | |
6692 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3) | |
6693 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3) | |
6694 | || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3) | |
6695 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3) | |
6696 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3) | |
6697 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3)) | |
6698 | abort (); | |
6699 | switch (r_type) | |
6700 | { | |
6701 | default: | |
6702 | break; | |
6703 | ||
6704 | case R_PPC_GOT_TPREL16: | |
6705 | case R_PPC_GOT_TPREL16_LO: | |
e054468f | 6706 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
6707 | && (tls_mask & TLS_TPREL) == 0) |
6708 | { | |
6709 | bfd_vma insn; | |
4fe5ca5b | 6710 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset); |
7619e7c7 AM |
6711 | insn &= 31 << 21; |
6712 | insn |= 0x3c020000; /* addis 0,2,0 */ | |
4fe5ca5b | 6713 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset); |
7619e7c7 AM |
6714 | r_type = R_PPC_TPREL16_HA; |
6715 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6716 | } | |
6717 | break; | |
6718 | ||
6719 | case R_PPC_TLS: | |
e054468f | 6720 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
6721 | && (tls_mask & TLS_TPREL) == 0) |
6722 | { | |
6723 | bfd_vma insn, rtra; | |
6724 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
6725 | if ((insn & ((31 << 26) | (31 << 11))) | |
6726 | == ((31 << 26) | (2 << 11))) | |
6727 | rtra = insn & ((1 << 26) - (1 << 16)); | |
6728 | else if ((insn & ((31 << 26) | (31 << 16))) | |
6729 | == ((31 << 26) | (2 << 16))) | |
6730 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
6731 | else | |
6732 | abort (); | |
6733 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
6734 | /* add -> addi. */ | |
6735 | insn = 14 << 26; | |
6736 | else if ((insn & (31 << 1)) == 23 << 1 | |
6737 | && ((insn & (31 << 6)) < 14 << 6 | |
6738 | || ((insn & (31 << 6)) >= 16 << 6 | |
6739 | && (insn & (31 << 6)) < 24 << 6))) | |
6740 | /* load and store indexed -> dform. */ | |
6741 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
6742 | else if ((insn & (31 << 1)) == 21 << 1 | |
6743 | && (insn & (0x1a << 6)) == 0) | |
6744 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
6745 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
6746 | | ((insn >> 6) & 1)); | |
6747 | else if ((insn & (31 << 1)) == 21 << 1 | |
6748 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
6749 | /* lwax -> lwa. */ | |
6750 | insn = (58 << 26) | 2; | |
6751 | else | |
6752 | abort (); | |
6753 | insn |= rtra; | |
6754 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
6755 | r_type = R_PPC_TPREL16_LO; | |
6756 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4fe5ca5b | 6757 | |
7619e7c7 | 6758 | /* Was PPC_TLS which sits on insn boundary, now |
4fe5ca5b GM |
6759 | PPC_TPREL16_LO which is at low-order half-word. */ |
6760 | rel->r_offset += d_offset; | |
7619e7c7 AM |
6761 | } |
6762 | break; | |
6763 | ||
6764 | case R_PPC_GOT_TLSGD16_HI: | |
6765 | case R_PPC_GOT_TLSGD16_HA: | |
6766 | tls_gd = TLS_TPRELGD; | |
e054468f | 6767 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
7619e7c7 AM |
6768 | goto tls_gdld_hi; |
6769 | break; | |
6770 | ||
6771 | case R_PPC_GOT_TLSLD16_HI: | |
6772 | case R_PPC_GOT_TLSLD16_HA: | |
e054468f | 6773 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 AM |
6774 | { |
6775 | tls_gdld_hi: | |
6776 | if ((tls_mask & tls_gd) != 0) | |
6777 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
6778 | + R_PPC_GOT_TPREL16); | |
6779 | else | |
6780 | { | |
6781 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); | |
4fe5ca5b | 6782 | rel->r_offset -= d_offset; |
7619e7c7 AM |
6783 | r_type = R_PPC_NONE; |
6784 | } | |
6785 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6786 | } | |
6787 | break; | |
6788 | ||
6789 | case R_PPC_GOT_TLSGD16: | |
6790 | case R_PPC_GOT_TLSGD16_LO: | |
6791 | tls_gd = TLS_TPRELGD; | |
e054468f | 6792 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
b7fcf6f6 | 6793 | goto tls_ldgd_opt; |
7619e7c7 AM |
6794 | break; |
6795 | ||
6796 | case R_PPC_GOT_TLSLD16: | |
6797 | case R_PPC_GOT_TLSLD16_LO: | |
e054468f | 6798 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 | 6799 | { |
3a71aa26 | 6800 | unsigned int insn1, insn2; |
b7fcf6f6 | 6801 | bfd_vma offset; |
7619e7c7 | 6802 | |
b7fcf6f6 | 6803 | tls_ldgd_opt: |
727fc41e AM |
6804 | offset = (bfd_vma) -1; |
6805 | /* If not using the newer R_PPC_TLSGD/LD to mark | |
6806 | __tls_get_addr calls, we must trust that the call | |
6807 | stays with its arg setup insns, ie. that the next | |
6808 | reloc is the __tls_get_addr call associated with | |
6809 | the current reloc. Edit both insns. */ | |
6810 | if (input_section->has_tls_get_addr_call | |
6811 | && rel + 1 < relend | |
6812 | && branch_reloc_hash_match (input_bfd, rel + 1, | |
6813 | htab->tls_get_addr)) | |
6814 | offset = rel[1].r_offset; | |
b7fcf6f6 AM |
6815 | if ((tls_mask & tls_gd) != 0) |
6816 | { | |
6817 | /* IE */ | |
3a71aa26 AM |
6818 | insn1 = bfd_get_32 (output_bfd, |
6819 | contents + rel->r_offset - d_offset); | |
b7fcf6f6 AM |
6820 | insn1 &= (1 << 26) - 1; |
6821 | insn1 |= 32 << 26; /* lwz */ | |
727fc41e AM |
6822 | if (offset != (bfd_vma) -1) |
6823 | { | |
6824 | rel[1].r_info | |
6825 | = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info), | |
6826 | R_PPC_NONE); | |
6827 | insn2 = 0x7c631214; /* add 3,3,2 */ | |
6828 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
6829 | } | |
b7fcf6f6 AM |
6830 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) |
6831 | + R_PPC_GOT_TPREL16); | |
6832 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6833 | } | |
6834 | else | |
6835 | { | |
6836 | /* LE */ | |
6837 | insn1 = 0x3c620000; /* addis 3,2,0 */ | |
7619e7c7 AM |
6838 | if (tls_gd == 0) |
6839 | { | |
b7fcf6f6 | 6840 | /* Was an LD reloc. */ |
1d483afe AM |
6841 | for (r_symndx = 0; |
6842 | r_symndx < symtab_hdr->sh_info; | |
6843 | r_symndx++) | |
6844 | if (local_sections[r_symndx] == sec) | |
6845 | break; | |
6846 | if (r_symndx >= symtab_hdr->sh_info) | |
6847 | r_symndx = 0; | |
b7fcf6f6 | 6848 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
1d483afe AM |
6849 | if (r_symndx != 0) |
6850 | rel->r_addend -= (local_syms[r_symndx].st_value | |
6851 | + sec->output_offset | |
6852 | + sec->output_section->vma); | |
7619e7c7 | 6853 | } |
b7fcf6f6 AM |
6854 | r_type = R_PPC_TPREL16_HA; |
6855 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
727fc41e AM |
6856 | if (offset != (bfd_vma) -1) |
6857 | { | |
6858 | rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
6859 | rel[1].r_offset = offset + d_offset; | |
6860 | rel[1].r_addend = rel->r_addend; | |
6861 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
6862 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
6863 | } | |
b7fcf6f6 AM |
6864 | } |
6865 | bfd_put_32 (output_bfd, insn1, | |
6866 | contents + rel->r_offset - d_offset); | |
b7fcf6f6 AM |
6867 | if (tls_gd == 0) |
6868 | { | |
6869 | /* We changed the symbol on an LD reloc. Start over | |
6870 | in order to get h, sym, sec etc. right. */ | |
6871 | rel--; | |
6872 | continue; | |
7619e7c7 | 6873 | } |
252b5132 | 6874 | } |
7619e7c7 | 6875 | break; |
727fc41e AM |
6876 | |
6877 | case R_PPC_TLSGD: | |
e054468f | 6878 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
727fc41e AM |
6879 | { |
6880 | unsigned int insn2; | |
6881 | bfd_vma offset = rel->r_offset; | |
6882 | ||
6883 | if ((tls_mask & TLS_TPRELGD) != 0) | |
6884 | { | |
6885 | /* IE */ | |
6886 | r_type = R_PPC_NONE; | |
6887 | insn2 = 0x7c631214; /* add 3,3,2 */ | |
6888 | } | |
6889 | else | |
6890 | { | |
6891 | /* LE */ | |
6892 | r_type = R_PPC_TPREL16_LO; | |
6893 | rel->r_offset += d_offset; | |
6894 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
6895 | } | |
6896 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6897 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
6898 | /* Zap the reloc on the _tls_get_addr call too. */ | |
6899 | BFD_ASSERT (offset == rel[1].r_offset); | |
6900 | rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info), | |
6901 | R_PPC_NONE); | |
6902 | } | |
6903 | break; | |
6904 | ||
6905 | case R_PPC_TLSLD: | |
e054468f | 6906 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
727fc41e AM |
6907 | { |
6908 | unsigned int insn2; | |
6909 | ||
6910 | for (r_symndx = 0; | |
6911 | r_symndx < symtab_hdr->sh_info; | |
6912 | r_symndx++) | |
6913 | if (local_sections[r_symndx] == sec) | |
6914 | break; | |
6915 | if (r_symndx >= symtab_hdr->sh_info) | |
6916 | r_symndx = 0; | |
6917 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; | |
6918 | if (r_symndx != 0) | |
6919 | rel->r_addend -= (local_syms[r_symndx].st_value | |
6920 | + sec->output_offset | |
6921 | + sec->output_section->vma); | |
6922 | ||
6923 | rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
6924 | rel->r_offset += d_offset; | |
6925 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
6926 | bfd_put_32 (output_bfd, insn2, | |
6927 | contents + rel->r_offset - d_offset); | |
6928 | /* Zap the reloc on the _tls_get_addr call too. */ | |
6929 | BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset); | |
6930 | rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info), | |
6931 | R_PPC_NONE); | |
6932 | rel--; | |
6933 | continue; | |
6934 | } | |
6935 | break; | |
7619e7c7 AM |
6936 | } |
6937 | ||
6938 | /* Handle other relocations that tweak non-addend part of insn. */ | |
6939 | branch_bit = 0; | |
6940 | switch (r_type) | |
6941 | { | |
6942 | default: | |
6943 | break; | |
6944 | ||
6945 | /* Branch taken prediction relocations. */ | |
6946 | case R_PPC_ADDR14_BRTAKEN: | |
6947 | case R_PPC_REL14_BRTAKEN: | |
6948 | branch_bit = BRANCH_PREDICT_BIT; | |
6949 | /* Fall thru */ | |
6950 | ||
4cc11e76 | 6951 | /* Branch not taken prediction relocations. */ |
7619e7c7 AM |
6952 | case R_PPC_ADDR14_BRNTAKEN: |
6953 | case R_PPC_REL14_BRNTAKEN: | |
6954 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
6955 | insn &= ~BRANCH_PREDICT_BIT; | |
6956 | insn |= branch_bit; | |
6957 | ||
6958 | from = (rel->r_offset | |
6959 | + input_section->output_offset | |
6960 | + input_section->output_section->vma); | |
6961 | ||
6962 | /* Invert 'y' bit if not the default. */ | |
6963 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
6964 | insn ^= BRANCH_PREDICT_BIT; | |
6965 | ||
6966 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
6967 | break; | |
252b5132 RH |
6968 | } |
6969 | ||
e054468f | 6970 | ifunc = NULL; |
25f23106 | 6971 | if (!htab->is_vxworks) |
e054468f | 6972 | { |
de972ffa AM |
6973 | struct plt_entry *ent; |
6974 | ||
e054468f AM |
6975 | if (h != NULL) |
6976 | { | |
6977 | if (h->type == STT_GNU_IFUNC) | |
6978 | ifunc = &h->plt.plist; | |
6979 | } | |
de972ffa AM |
6980 | else if (local_got_offsets != NULL |
6981 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
e054468f | 6982 | { |
de972ffa | 6983 | struct plt_entry **local_plt; |
e054468f | 6984 | |
de972ffa AM |
6985 | local_plt = (struct plt_entry **) (local_got_offsets |
6986 | + symtab_hdr->sh_info); | |
6987 | ifunc = local_plt + r_symndx; | |
e054468f | 6988 | } |
e054468f | 6989 | |
de972ffa AM |
6990 | ent = NULL; |
6991 | if (ifunc != NULL | |
6992 | && (!info->shared | |
6993 | || is_branch_reloc (r_type))) | |
6994 | { | |
6995 | addend = 0; | |
a877a2b6 | 6996 | if (r_type == R_PPC_PLTREL24 && info->shared) |
de972ffa AM |
6997 | addend = rel->r_addend; |
6998 | ent = find_plt_ent (ifunc, got2, addend); | |
6999 | } | |
7000 | if (ent != NULL) | |
7001 | { | |
e054468f AM |
7002 | if (h == NULL && (ent->plt.offset & 1) == 0) |
7003 | { | |
7004 | Elf_Internal_Rela rela; | |
7005 | bfd_byte *loc; | |
7006 | ||
7007 | rela.r_offset = (htab->iplt->output_section->vma | |
7008 | + htab->iplt->output_offset | |
7009 | + ent->plt.offset); | |
7010 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7011 | rela.r_addend = relocation; | |
25f23106 AM |
7012 | loc = htab->reliplt->contents; |
7013 | loc += (htab->reliplt->reloc_count++ | |
7014 | * sizeof (Elf32_External_Rela)); | |
e054468f AM |
7015 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
7016 | ||
7017 | ent->plt.offset |= 1; | |
7018 | } | |
7019 | if (h == NULL && (ent->glink_offset & 1) == 0) | |
7020 | { | |
7021 | write_glink_stub (ent, htab->iplt, info); | |
7022 | ent->glink_offset |= 1; | |
7023 | } | |
7024 | ||
7025 | unresolved_reloc = FALSE; | |
7026 | if (htab->plt_type == PLT_NEW | |
7027 | || !htab->elf.dynamic_sections_created | |
7028 | || h == NULL) | |
7029 | relocation = (htab->glink->output_section->vma | |
7030 | + htab->glink->output_offset | |
7031 | + (ent->glink_offset & ~1)); | |
7032 | else | |
7033 | relocation = (htab->plt->output_section->vma | |
7034 | + htab->plt->output_offset | |
7035 | + ent->plt.offset); | |
7036 | } | |
7037 | } | |
7038 | ||
7619e7c7 AM |
7039 | addend = rel->r_addend; |
7040 | tls_type = 0; | |
7041 | howto = NULL; | |
55fd94b0 AM |
7042 | if (r_type < R_PPC_max) |
7043 | howto = ppc_elf_howto_table[r_type]; | |
7619e7c7 | 7044 | switch (r_type) |
252b5132 RH |
7045 | { |
7046 | default: | |
7619e7c7 | 7047 | (*_bfd_error_handler) |
d003868e AM |
7048 | (_("%B: unknown relocation type %d for symbol %s"), |
7049 | input_bfd, (int) r_type, sym_name); | |
252b5132 RH |
7050 | |
7051 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 7052 | ret = FALSE; |
252b5132 RH |
7053 | continue; |
7054 | ||
7619e7c7 AM |
7055 | case R_PPC_NONE: |
7056 | case R_PPC_TLS: | |
727fc41e AM |
7057 | case R_PPC_TLSGD: |
7058 | case R_PPC_TLSLD: | |
7619e7c7 AM |
7059 | case R_PPC_EMB_MRKREF: |
7060 | case R_PPC_GNU_VTINHERIT: | |
7061 | case R_PPC_GNU_VTENTRY: | |
7595d193 L |
7062 | continue; |
7063 | ||
7619e7c7 AM |
7064 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
7065 | address in the GOT as relocation value instead of the | |
7066 | symbol's value itself. Also, create a GOT entry for the | |
7067 | symbol and put the symbol value there. */ | |
7068 | case R_PPC_GOT_TLSGD16: | |
7069 | case R_PPC_GOT_TLSGD16_LO: | |
7070 | case R_PPC_GOT_TLSGD16_HI: | |
7071 | case R_PPC_GOT_TLSGD16_HA: | |
7072 | tls_type = TLS_TLS | TLS_GD; | |
7073 | goto dogot; | |
7074 | ||
7075 | case R_PPC_GOT_TLSLD16: | |
7076 | case R_PPC_GOT_TLSLD16_LO: | |
7077 | case R_PPC_GOT_TLSLD16_HI: | |
7078 | case R_PPC_GOT_TLSLD16_HA: | |
7079 | tls_type = TLS_TLS | TLS_LD; | |
7080 | goto dogot; | |
7081 | ||
7082 | case R_PPC_GOT_TPREL16: | |
7083 | case R_PPC_GOT_TPREL16_LO: | |
7084 | case R_PPC_GOT_TPREL16_HI: | |
7085 | case R_PPC_GOT_TPREL16_HA: | |
7086 | tls_type = TLS_TLS | TLS_TPREL; | |
7087 | goto dogot; | |
7088 | ||
7089 | case R_PPC_GOT_DTPREL16: | |
7090 | case R_PPC_GOT_DTPREL16_LO: | |
7091 | case R_PPC_GOT_DTPREL16_HI: | |
7092 | case R_PPC_GOT_DTPREL16_HA: | |
7093 | tls_type = TLS_TLS | TLS_DTPREL; | |
7094 | goto dogot; | |
7095 | ||
7096 | case R_PPC_GOT16: | |
7097 | case R_PPC_GOT16_LO: | |
7098 | case R_PPC_GOT16_HI: | |
7099 | case R_PPC_GOT16_HA: | |
727fc41e | 7100 | tls_mask = 0; |
7619e7c7 AM |
7101 | dogot: |
7102 | { | |
7103 | /* Relocation is to the entry for this symbol in the global | |
7104 | offset table. */ | |
7105 | bfd_vma off; | |
7106 | bfd_vma *offp; | |
7107 | unsigned long indx; | |
7108 | ||
7109 | if (htab->got == NULL) | |
7110 | abort (); | |
7111 | ||
7112 | indx = 0; | |
7113 | if (tls_type == (TLS_TLS | TLS_LD) | |
d881513a | 7114 | && (h == NULL |
f5385ebf | 7115 | || !h->def_dynamic)) |
7619e7c7 AM |
7116 | offp = &htab->tlsld_got.offset; |
7117 | else if (h != NULL) | |
7118 | { | |
7119 | bfd_boolean dyn; | |
7120 | dyn = htab->elf.dynamic_sections_created; | |
ee05f2fe | 7121 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
7619e7c7 AM |
7122 | || (info->shared |
7123 | && SYMBOL_REFERENCES_LOCAL (info, h))) | |
7124 | /* This is actually a static link, or it is a | |
7125 | -Bsymbolic link and the symbol is defined | |
7126 | locally, or the symbol was forced to be local | |
7127 | because of a version file. */ | |
7128 | ; | |
7129 | else | |
7130 | { | |
7131 | indx = h->dynindx; | |
7132 | unresolved_reloc = FALSE; | |
7133 | } | |
7134 | offp = &h->got.offset; | |
7135 | } | |
7136 | else | |
7137 | { | |
7138 | if (local_got_offsets == NULL) | |
7139 | abort (); | |
7140 | offp = &local_got_offsets[r_symndx]; | |
7141 | } | |
7142 | ||
7143 | /* The offset must always be a multiple of 4. We use the | |
7144 | least significant bit to record whether we have already | |
7145 | processed this entry. */ | |
7146 | off = *offp; | |
7147 | if ((off & 1) != 0) | |
7148 | off &= ~1; | |
7149 | else | |
7150 | { | |
70bccea4 AM |
7151 | unsigned int tls_m = (tls_mask |
7152 | & (TLS_LD | TLS_GD | TLS_DTPREL | |
7153 | | TLS_TPREL | TLS_TPRELGD)); | |
7154 | ||
7155 | if (offp == &htab->tlsld_got.offset) | |
7156 | tls_m = TLS_LD; | |
7157 | else if (h == NULL | |
f5385ebf | 7158 | || !h->def_dynamic) |
70bccea4 AM |
7159 | tls_m &= ~TLS_LD; |
7160 | ||
7161 | /* We might have multiple got entries for this sym. | |
7162 | Initialize them all. */ | |
7163 | do | |
7619e7c7 | 7164 | { |
70bccea4 AM |
7165 | int tls_ty = 0; |
7166 | ||
7167 | if ((tls_m & TLS_LD) != 0) | |
7619e7c7 | 7168 | { |
70bccea4 AM |
7169 | tls_ty = TLS_TLS | TLS_LD; |
7170 | tls_m &= ~TLS_LD; | |
7171 | } | |
7172 | else if ((tls_m & TLS_GD) != 0) | |
7173 | { | |
7174 | tls_ty = TLS_TLS | TLS_GD; | |
7175 | tls_m &= ~TLS_GD; | |
7176 | } | |
7177 | else if ((tls_m & TLS_DTPREL) != 0) | |
7178 | { | |
7179 | tls_ty = TLS_TLS | TLS_DTPREL; | |
7180 | tls_m &= ~TLS_DTPREL; | |
7181 | } | |
7182 | else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
7183 | { | |
7184 | tls_ty = TLS_TLS | TLS_TPREL; | |
7185 | tls_m = 0; | |
7619e7c7 | 7186 | } |
7619e7c7 | 7187 | |
70bccea4 | 7188 | /* Generate relocs for the dynamic linker. */ |
4e795f50 | 7189 | if ((info->shared || indx != 0) |
d6e14abc AM |
7190 | && (offp == &htab->tlsld_got.offset |
7191 | || h == NULL | |
4e795f50 AM |
7192 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7193 | || h->root.type != bfd_link_hash_undefweak)) | |
7619e7c7 | 7194 | { |
91e21fb7 AM |
7195 | asection *rsec = htab->relgot; |
7196 | ||
70bccea4 AM |
7197 | outrel.r_offset = (htab->got->output_section->vma |
7198 | + htab->got->output_offset | |
7199 | + off); | |
e515b051 | 7200 | outrel.r_addend = 0; |
70bccea4 AM |
7201 | if (tls_ty & (TLS_LD | TLS_GD)) |
7202 | { | |
7203 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32); | |
70bccea4 AM |
7204 | if (tls_ty == (TLS_TLS | TLS_GD)) |
7205 | { | |
25f23106 AM |
7206 | loc = rsec->contents; |
7207 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
7208 | * sizeof (Elf32_External_Rela)); |
7209 | bfd_elf32_swap_reloca_out (output_bfd, | |
7210 | &outrel, loc); | |
e515b051 | 7211 | outrel.r_offset += 4; |
70bccea4 AM |
7212 | outrel.r_info |
7213 | = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
70bccea4 AM |
7214 | } |
7215 | } | |
7216 | else if (tls_ty == (TLS_TLS | TLS_DTPREL)) | |
7217 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
7218 | else if (tls_ty == (TLS_TLS | TLS_TPREL)) | |
7219 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32); | |
25f23106 | 7220 | else if (indx != 0) |
70bccea4 | 7221 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT); |
25f23106 AM |
7222 | else if (ifunc != NULL) |
7223 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7224 | else | |
7225 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
d6e14abc | 7226 | if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD)) |
e515b051 AM |
7227 | { |
7228 | outrel.r_addend += relocation; | |
7229 | if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 7230 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 7231 | } |
25f23106 AM |
7232 | loc = rsec->contents; |
7233 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
7234 | * sizeof (Elf32_External_Rela)); |
7235 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
7619e7c7 AM |
7236 | } |
7237 | ||
70bccea4 AM |
7238 | /* Init the .got section contents if we're not |
7239 | emitting a reloc. */ | |
7240 | else | |
7619e7c7 | 7241 | { |
70bccea4 AM |
7242 | bfd_vma value = relocation; |
7243 | ||
7b609f53 AM |
7244 | if (tls_ty == (TLS_TLS | TLS_LD)) |
7245 | value = 1; | |
7246 | else if (tls_ty != 0) | |
70bccea4 | 7247 | { |
e1918d23 | 7248 | value -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 7249 | if (tls_ty == (TLS_TLS | TLS_TPREL)) |
70bccea4 | 7250 | value += DTP_OFFSET - TP_OFFSET; |
70bccea4 | 7251 | |
7b609f53 AM |
7252 | if (tls_ty == (TLS_TLS | TLS_GD)) |
7253 | { | |
7254 | bfd_put_32 (output_bfd, value, | |
7255 | htab->got->contents + off + 4); | |
7256 | value = 1; | |
7257 | } | |
70bccea4 | 7258 | } |
70bccea4 AM |
7259 | bfd_put_32 (output_bfd, value, |
7260 | htab->got->contents + off); | |
7619e7c7 | 7261 | } |
70bccea4 AM |
7262 | |
7263 | off += 4; | |
7264 | if (tls_ty & (TLS_LD | TLS_GD)) | |
7265 | off += 4; | |
7619e7c7 | 7266 | } |
70bccea4 AM |
7267 | while (tls_m != 0); |
7268 | ||
7269 | off = *offp; | |
7270 | *offp = off | 1; | |
7619e7c7 AM |
7271 | } |
7272 | ||
7273 | if (off >= (bfd_vma) -2) | |
7274 | abort (); | |
7275 | ||
70bccea4 AM |
7276 | if ((tls_type & TLS_TLS) != 0) |
7277 | { | |
7278 | if (tls_type != (TLS_TLS | TLS_LD)) | |
7279 | { | |
7280 | if ((tls_mask & TLS_LD) != 0 | |
7281 | && !(h == NULL | |
f5385ebf | 7282 | || !h->def_dynamic)) |
70bccea4 AM |
7283 | off += 8; |
7284 | if (tls_type != (TLS_TLS | TLS_GD)) | |
7285 | { | |
7286 | if ((tls_mask & TLS_GD) != 0) | |
7287 | off += 8; | |
7288 | if (tls_type != (TLS_TLS | TLS_DTPREL)) | |
7289 | { | |
7290 | if ((tls_mask & TLS_DTPREL) != 0) | |
7291 | off += 4; | |
7292 | } | |
7293 | } | |
7294 | } | |
7295 | } | |
7296 | ||
e87d4038 AM |
7297 | relocation = (htab->got->output_section->vma |
7298 | + htab->got->output_offset | |
7299 | + off | |
7300 | - SYM_VAL (htab->elf.hgot)); | |
7619e7c7 AM |
7301 | |
7302 | /* Addends on got relocations don't make much sense. | |
7303 | x+off@got is actually x@got+off, and since the got is | |
7304 | generated by a hash table traversal, the value in the | |
7305 | got at entry m+n bears little relation to the entry m. */ | |
7306 | if (addend != 0) | |
7307 | (*_bfd_error_handler) | |
d003868e AM |
7308 | (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"), |
7309 | input_bfd, | |
7310 | input_section, | |
7619e7c7 | 7311 | (long) rel->r_offset, |
7b609f53 | 7312 | howto->name, |
7619e7c7 AM |
7313 | sym_name); |
7314 | } | |
70bccea4 | 7315 | break; |
7619e7c7 | 7316 | |
252b5132 | 7317 | /* Relocations that need no special processing. */ |
7619e7c7 | 7318 | case R_PPC_LOCAL24PC: |
252b5132 RH |
7319 | /* It makes no sense to point a local relocation |
7320 | at a symbol not in this object. */ | |
7b609f53 | 7321 | if (unresolved_reloc) |
252b5132 | 7322 | { |
464e1740 ILT |
7323 | if (! (*info->callbacks->undefined_symbol) (info, |
7324 | h->root.root.string, | |
7325 | input_bfd, | |
7326 | input_section, | |
5cc7c785 | 7327 | rel->r_offset, |
b34976b6 AM |
7328 | TRUE)) |
7329 | return FALSE; | |
252b5132 RH |
7330 | continue; |
7331 | } | |
7332 | break; | |
7333 | ||
7619e7c7 AM |
7334 | case R_PPC_DTPREL16: |
7335 | case R_PPC_DTPREL16_LO: | |
7336 | case R_PPC_DTPREL16_HI: | |
7337 | case R_PPC_DTPREL16_HA: | |
e1918d23 | 7338 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
7339 | break; |
7340 | ||
70bccea4 AM |
7341 | /* Relocations that may need to be propagated if this is a shared |
7342 | object. */ | |
7619e7c7 AM |
7343 | case R_PPC_TPREL16: |
7344 | case R_PPC_TPREL16_LO: | |
7345 | case R_PPC_TPREL16_HI: | |
7346 | case R_PPC_TPREL16_HA: | |
e1918d23 | 7347 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
7348 | /* The TPREL16 relocs shouldn't really be used in shared |
7349 | libs as they will result in DT_TEXTREL being set, but | |
7350 | support them anyway. */ | |
7351 | goto dodyn; | |
7352 | ||
7353 | case R_PPC_TPREL32: | |
e1918d23 | 7354 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
7355 | goto dodyn; |
7356 | ||
7357 | case R_PPC_DTPREL32: | |
e1918d23 | 7358 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
7359 | goto dodyn; |
7360 | ||
e515b051 AM |
7361 | case R_PPC_DTPMOD32: |
7362 | relocation = 1; | |
7363 | addend = 0; | |
7364 | goto dodyn; | |
7365 | ||
d7128ce4 AM |
7366 | case R_PPC_REL16: |
7367 | case R_PPC_REL16_LO: | |
7368 | case R_PPC_REL16_HI: | |
7369 | case R_PPC_REL16_HA: | |
7370 | break; | |
7371 | ||
7619e7c7 | 7372 | case R_PPC_REL32: |
625af618 AM |
7373 | if (h == NULL || h == htab->elf.hgot) |
7374 | break; | |
7375 | /* fall through */ | |
7376 | ||
7377 | case R_PPC_ADDR32: | |
7378 | case R_PPC_ADDR16: | |
7379 | case R_PPC_ADDR16_LO: | |
7380 | case R_PPC_ADDR16_HI: | |
7381 | case R_PPC_ADDR16_HA: | |
7382 | case R_PPC_UADDR32: | |
7383 | case R_PPC_UADDR16: | |
7384 | goto dodyn; | |
7385 | ||
7386 | case R_PPC_REL24: | |
7619e7c7 AM |
7387 | case R_PPC_REL14: |
7388 | case R_PPC_REL14_BRTAKEN: | |
7389 | case R_PPC_REL14_BRNTAKEN: | |
252b5132 RH |
7390 | /* If these relocations are not to a named symbol, they can be |
7391 | handled right here, no need to bother the dynamic linker. */ | |
89200bf8 | 7392 | if (SYMBOL_CALLS_LOCAL (info, h) |
3b36f7e6 | 7393 | || h == htab->elf.hgot) |
252b5132 | 7394 | break; |
70bccea4 | 7395 | /* fall through */ |
252b5132 | 7396 | |
7619e7c7 | 7397 | case R_PPC_ADDR24: |
7619e7c7 AM |
7398 | case R_PPC_ADDR14: |
7399 | case R_PPC_ADDR14_BRTAKEN: | |
7400 | case R_PPC_ADDR14_BRNTAKEN: | |
625af618 AM |
7401 | if (h != NULL && !info->shared) |
7402 | break; | |
7403 | /* fall through */ | |
7404 | ||
7619e7c7 | 7405 | dodyn: |
3348747a NS |
7406 | if ((input_section->flags & SEC_ALLOC) == 0 |
7407 | || is_vxworks_tls) | |
c87b5a93 | 7408 | break; |
c87b5a93 | 7409 | |
ee05f2fe | 7410 | if ((info->shared |
89200bf8 AM |
7411 | && !(h != NULL |
7412 | && ((h->root.type == bfd_link_hash_undefined | |
7413 | && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
7414 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL)) | |
7415 | || (h->root.type == bfd_link_hash_undefweak | |
7416 | && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT))) | |
1d483afe | 7417 | && (must_be_dyn_reloc (info, r_type) |
f6c52c13 | 7418 | || !SYMBOL_CALLS_LOCAL (info, h))) |
ee05f2fe AM |
7419 | || (ELIMINATE_COPY_RELOCS |
7420 | && !info->shared | |
ee05f2fe AM |
7421 | && h != NULL |
7422 | && h->dynindx != -1 | |
f5385ebf | 7423 | && !h->non_got_ref |
de972ffa | 7424 | && !h->def_regular)) |
252b5132 | 7425 | { |
0bb2d96a | 7426 | int skip; |
252b5132 RH |
7427 | |
7428 | #ifdef DEBUG | |
55fd94b0 AM |
7429 | fprintf (stderr, "ppc_elf_relocate_section needs to " |
7430 | "create relocation for %s\n", | |
70bccea4 AM |
7431 | (h && h->root.root.string |
7432 | ? h->root.root.string : "<unknown>")); | |
252b5132 RH |
7433 | #endif |
7434 | ||
7435 | /* When generating a shared object, these relocations | |
70bccea4 AM |
7436 | are copied into the output file to be resolved at run |
7437 | time. */ | |
252b5132 RH |
7438 | if (sreloc == NULL) |
7439 | { | |
25f23106 AM |
7440 | sreloc = elf_section_data (input_section)->sreloc; |
7441 | if (!htab->elf.dynamic_sections_created) | |
7442 | sreloc = htab->reliplt; | |
83bac4b0 | 7443 | if (sreloc == NULL) |
b34976b6 | 7444 | return FALSE; |
252b5132 RH |
7445 | } |
7446 | ||
0bb2d96a | 7447 | skip = 0; |
c629eae0 JJ |
7448 | outrel.r_offset = |
7449 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
7450 | rel->r_offset); | |
0bb2d96a JJ |
7451 | if (outrel.r_offset == (bfd_vma) -1 |
7452 | || outrel.r_offset == (bfd_vma) -2) | |
7453 | skip = (int) outrel.r_offset; | |
252b5132 RH |
7454 | outrel.r_offset += (input_section->output_section->vma |
7455 | + input_section->output_offset); | |
7456 | ||
7457 | if (skip) | |
7458 | memset (&outrel, 0, sizeof outrel); | |
89200bf8 AM |
7459 | else if ((h != NULL |
7460 | && (h->root.type == bfd_link_hash_undefined | |
7461 | || h->root.type == bfd_link_hash_undefweak)) | |
7462 | || !SYMBOL_REFERENCES_LOCAL (info, h)) | |
252b5132 | 7463 | { |
7619e7c7 | 7464 | unresolved_reloc = FALSE; |
252b5132 RH |
7465 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
7466 | outrel.r_addend = rel->r_addend; | |
7467 | } | |
7468 | else | |
7469 | { | |
47388f4c AM |
7470 | outrel.r_addend = relocation + rel->r_addend; |
7471 | ||
25f23106 | 7472 | if (r_type != R_PPC_ADDR32) |
252b5132 | 7473 | { |
89200bf8 | 7474 | long indx = 0; |
252b5132 | 7475 | |
25f23106 AM |
7476 | if (ifunc != NULL) |
7477 | { | |
7478 | /* If we get here when building a static | |
7479 | executable, then the libc startup function | |
7480 | responsible for applying indirect function | |
7481 | relocations is going to complain about | |
7482 | the reloc type. | |
7483 | If we get here when building a dynamic | |
7484 | executable, it will be because we have | |
7485 | a text relocation. The dynamic loader | |
7486 | will set the text segment writable and | |
7487 | non-executable to apply text relocations. | |
7488 | So we'll segfault when trying to run the | |
7489 | indirection function to resolve the reloc. */ | |
7490 | (*_bfd_error_handler) | |
7491 | (_("%B(%A+0x%lx): relocation %s for indirect " | |
7492 | "function %s unsupported"), | |
7493 | input_bfd, | |
7494 | input_section, | |
7495 | (long) rel->r_offset, | |
7496 | howto->name, | |
7497 | sym_name); | |
7498 | ret = FALSE; | |
7499 | } | |
7500 | else if (r_symndx == 0 || bfd_is_abs_section (sec)) | |
89200bf8 | 7501 | ; |
252b5132 RH |
7502 | else if (sec == NULL || sec->owner == NULL) |
7503 | { | |
7504 | bfd_set_error (bfd_error_bad_value); | |
89200bf8 | 7505 | ret = FALSE; |
252b5132 RH |
7506 | } |
7507 | else | |
7508 | { | |
7509 | asection *osec; | |
7510 | ||
47388f4c AM |
7511 | /* We are turning this relocation into one |
7512 | against a section symbol. It would be | |
7513 | proper to subtract the symbol's value, | |
7514 | osec->vma, from the emitted reloc addend, | |
25f23106 AM |
7515 | but ld.so expects buggy relocs. |
7516 | FIXME: Why not always use a zero index? */ | |
252b5132 RH |
7517 | osec = sec->output_section; |
7518 | indx = elf_section_data (osec)->dynindx; | |
74541ad4 AM |
7519 | if (indx == 0) |
7520 | { | |
7521 | osec = htab->elf.text_index_section; | |
7522 | indx = elf_section_data (osec)->dynindx; | |
7523 | } | |
7524 | BFD_ASSERT (indx != 0); | |
252b5132 | 7525 | #ifdef DEBUG |
74541ad4 | 7526 | if (indx == 0) |
e460dd0d | 7527 | printf ("indx=%ld section=%s flags=%08x name=%s\n", |
55fd94b0 AM |
7528 | indx, osec->name, osec->flags, |
7529 | h->root.root.string); | |
252b5132 RH |
7530 | #endif |
7531 | } | |
7532 | ||
7533 | outrel.r_info = ELF32_R_INFO (indx, r_type); | |
252b5132 | 7534 | } |
25f23106 AM |
7535 | else if (ifunc != NULL) |
7536 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7537 | else | |
7538 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
252b5132 RH |
7539 | } |
7540 | ||
947216bf AM |
7541 | loc = sreloc->contents; |
7542 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
7543 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 | 7544 | |
2243deae | 7545 | if (skip == -1) |
252b5132 | 7546 | continue; |
2243deae L |
7547 | |
7548 | /* This reloc will be computed at runtime. We clear the memory | |
7549 | so that it contains predictable value. */ | |
7550 | if (! skip | |
7551 | && ((input_section->flags & SEC_ALLOC) != 0 | |
7552 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)) | |
7553 | { | |
7554 | relocation = howto->pc_relative ? outrel.r_offset : 0; | |
7555 | addend = 0; | |
7556 | break; | |
7557 | } | |
252b5132 | 7558 | } |
252b5132 RH |
7559 | break; |
7560 | ||
b4a38de6 AM |
7561 | case R_PPC_RELAX32PC_PLT: |
7562 | case R_PPC_RELAX32_PLT: | |
de972ffa AM |
7563 | if (h != NULL) |
7564 | { | |
7565 | struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2, | |
a877a2b6 | 7566 | info->shared ? addend : 0); |
de972ffa AM |
7567 | if (htab->plt_type == PLT_NEW) |
7568 | relocation = (htab->glink->output_section->vma | |
7569 | + htab->glink->output_offset | |
7570 | + ent->glink_offset); | |
7571 | else | |
7572 | relocation = (htab->plt->output_section->vma | |
7573 | + htab->plt->output_offset | |
7574 | + ent->plt.offset); | |
7575 | } | |
b4a38de6 AM |
7576 | if (r_type == R_PPC_RELAX32_PLT) |
7577 | goto relax32; | |
7578 | /* Fall thru */ | |
7579 | ||
f31a141e AM |
7580 | case R_PPC_RELAX32PC: |
7581 | relocation -= (input_section->output_section->vma | |
7582 | + input_section->output_offset | |
7583 | + rel->r_offset - 4); | |
7584 | /* Fall thru */ | |
b4a38de6 | 7585 | |
deaaf2f3 | 7586 | case R_PPC_RELAX32: |
b4a38de6 | 7587 | relax32: |
9abc968f AM |
7588 | { |
7589 | unsigned long t0; | |
7590 | unsigned long t1; | |
7591 | ||
7592 | t0 = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
7593 | t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4); | |
7594 | ||
7595 | /* We're clearing the bits for R_PPC_ADDR16_HA | |
7596 | and R_PPC_ADDR16_LO here. */ | |
7597 | t0 &= ~0xffff; | |
7598 | t1 &= ~0xffff; | |
7599 | ||
7600 | /* t0 is HA, t1 is LO */ | |
7601 | relocation += addend; | |
7602 | t0 |= ((relocation + 0x8000) >> 16) & 0xffff; | |
7603 | t1 |= relocation & 0xffff; | |
7604 | ||
7605 | bfd_put_32 (output_bfd, t0, contents + rel->r_offset); | |
7606 | bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4); | |
9bc4e62b NS |
7607 | |
7608 | /* Rewrite the reloc and convert one of the trailing nop | |
7609 | relocs to describe this relocation. */ | |
7610 | BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE); | |
7611 | /* The relocs are at the bottom 2 bytes */ | |
7612 | rel[0].r_offset += 2; | |
7613 | memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel)); | |
7614 | rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); | |
7615 | rel[1].r_offset += 4; | |
7616 | rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); | |
7617 | rel++; | |
9abc968f | 7618 | } |
8517fae7 | 7619 | continue; |
deaaf2f3 | 7620 | |
70bccea4 | 7621 | /* Indirect .sdata relocation. */ |
7619e7c7 | 7622 | case R_PPC_EMB_SDAI16: |
c9a2f333 | 7623 | BFD_ASSERT (htab->sdata[0].section != NULL); |
7619e7c7 | 7624 | relocation |
76750a2f AM |
7625 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0], |
7626 | h, relocation, rel); | |
252b5132 RH |
7627 | break; |
7628 | ||
70bccea4 | 7629 | /* Indirect .sdata2 relocation. */ |
7619e7c7 | 7630 | case R_PPC_EMB_SDA2I16: |
c9a2f333 | 7631 | BFD_ASSERT (htab->sdata[1].section != NULL); |
7619e7c7 | 7632 | relocation |
76750a2f AM |
7633 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1], |
7634 | h, relocation, rel); | |
252b5132 RH |
7635 | break; |
7636 | ||
70bccea4 AM |
7637 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
7638 | section, not the actual VMA. This is appropriate when generating | |
7639 | an embedded ELF object, for which the .got section acts like the | |
7640 | AIX .toc section. */ | |
7619e7c7 | 7641 | case R_PPC_TOC16: /* phony GOT16 relocations */ |
3b4f3a11 AM |
7642 | if (sec == NULL || sec->output_section == NULL) |
7643 | { | |
7644 | unresolved_reloc = TRUE; | |
7645 | break; | |
7646 | } | |
7647 | BFD_ASSERT (strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 | |
f12123c0 | 7648 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0); |
252b5132 | 7649 | |
3b4f3a11 | 7650 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; |
252b5132 RH |
7651 | break; |
7652 | ||
7619e7c7 | 7653 | case R_PPC_PLTREL24: |
e054468f | 7654 | if (h == NULL || ifunc != NULL) |
6d78d0b9 | 7655 | break; |
252b5132 | 7656 | /* Relocation is to the entry for this symbol in the |
70bccea4 | 7657 | procedure linkage table. */ |
a6aa5195 | 7658 | { |
a877a2b6 AM |
7659 | struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2, |
7660 | info->shared ? addend : 0); | |
a6aa5195 AM |
7661 | addend = 0; |
7662 | if (ent == NULL | |
7663 | || htab->plt == NULL) | |
7664 | { | |
7665 | /* We didn't make a PLT entry for this symbol. This | |
7666 | happens when statically linking PIC code, or when | |
7667 | using -Bsymbolic. */ | |
7668 | break; | |
7669 | } | |
252b5132 | 7670 | |
a6aa5195 | 7671 | unresolved_reloc = FALSE; |
4a3dc543 | 7672 | if (htab->plt_type == PLT_NEW) |
a6aa5195 AM |
7673 | relocation = (htab->glink->output_section->vma |
7674 | + htab->glink->output_offset | |
7675 | + ent->glink_offset); | |
7676 | else | |
7677 | relocation = (htab->plt->output_section->vma | |
7678 | + htab->plt->output_offset | |
7679 | + ent->plt.offset); | |
7680 | } | |
8da6118f | 7681 | break; |
252b5132 | 7682 | |
70bccea4 | 7683 | /* Relocate against _SDA_BASE_. */ |
7619e7c7 | 7684 | case R_PPC_SDAREL16: |
252b5132 RH |
7685 | { |
7686 | const char *name; | |
7687 | ||
3b4f3a11 AM |
7688 | if (sec == NULL || sec->output_section == NULL) |
7689 | { | |
7690 | unresolved_reloc = TRUE; | |
7691 | break; | |
7692 | } | |
7693 | ||
252b5132 | 7694 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 | 7695 | if (! ((CONST_STRNEQ (name, ".sdata") |
5f819128 | 7696 | && (name[6] == 0 || name[6] == '.')) |
0112cd26 | 7697 | || (CONST_STRNEQ (name, ".sbss") |
5f819128 | 7698 | && (name[5] == 0 || name[5] == '.')))) |
252b5132 | 7699 | { |
55fd94b0 | 7700 | (*_bfd_error_handler) |
d003868e | 7701 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 7702 | "in the wrong output section (%s)"), |
d003868e | 7703 | input_bfd, |
55fd94b0 AM |
7704 | sym_name, |
7705 | howto->name, | |
7706 | name); | |
252b5132 | 7707 | } |
e87d4038 | 7708 | addend -= SYM_VAL (htab->sdata[0].sym); |
252b5132 RH |
7709 | } |
7710 | break; | |
7711 | ||
70bccea4 | 7712 | /* Relocate against _SDA2_BASE_. */ |
7619e7c7 | 7713 | case R_PPC_EMB_SDA2REL: |
252b5132 RH |
7714 | { |
7715 | const char *name; | |
7716 | ||
3b4f3a11 AM |
7717 | if (sec == NULL || sec->output_section == NULL) |
7718 | { | |
7719 | unresolved_reloc = TRUE; | |
7720 | break; | |
7721 | } | |
7722 | ||
252b5132 | 7723 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 NC |
7724 | if (! (CONST_STRNEQ (name, ".sdata2") |
7725 | || CONST_STRNEQ (name, ".sbss2"))) | |
252b5132 | 7726 | { |
55fd94b0 | 7727 | (*_bfd_error_handler) |
d003868e | 7728 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 7729 | "in the wrong output section (%s)"), |
d003868e | 7730 | input_bfd, |
55fd94b0 AM |
7731 | sym_name, |
7732 | howto->name, | |
7733 | name); | |
c3668558 | 7734 | |
252b5132 | 7735 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 7736 | ret = FALSE; |
252b5132 RH |
7737 | continue; |
7738 | } | |
e87d4038 | 7739 | addend -= SYM_VAL (htab->sdata[1].sym); |
252b5132 RH |
7740 | } |
7741 | break; | |
7742 | ||
70bccea4 | 7743 | /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */ |
7619e7c7 AM |
7744 | case R_PPC_EMB_SDA21: |
7745 | case R_PPC_EMB_RELSDA: | |
252b5132 RH |
7746 | { |
7747 | const char *name; | |
7748 | int reg; | |
7749 | ||
3b4f3a11 AM |
7750 | if (sec == NULL || sec->output_section == NULL) |
7751 | { | |
7752 | unresolved_reloc = TRUE; | |
7753 | break; | |
7754 | } | |
7755 | ||
252b5132 | 7756 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 | 7757 | if (((CONST_STRNEQ (name, ".sdata") |
5f819128 | 7758 | && (name[6] == 0 || name[6] == '.')) |
0112cd26 | 7759 | || (CONST_STRNEQ (name, ".sbss") |
5f819128 | 7760 | && (name[5] == 0 || name[5] == '.')))) |
252b5132 RH |
7761 | { |
7762 | reg = 13; | |
e87d4038 | 7763 | addend -= SYM_VAL (htab->sdata[0].sym); |
252b5132 | 7764 | } |
0112cd26 NC |
7765 | else if (CONST_STRNEQ (name, ".sdata2") |
7766 | || CONST_STRNEQ (name, ".sbss2")) | |
252b5132 RH |
7767 | { |
7768 | reg = 2; | |
e87d4038 | 7769 | addend -= SYM_VAL (htab->sdata[1].sym); |
252b5132 | 7770 | } |
8da6118f KH |
7771 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 |
7772 | || strcmp (name, ".PPC.EMB.sbss0") == 0) | |
252b5132 RH |
7773 | { |
7774 | reg = 0; | |
7775 | } | |
252b5132 RH |
7776 | else |
7777 | { | |
55fd94b0 | 7778 | (*_bfd_error_handler) |
d003868e | 7779 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 7780 | "in the wrong output section (%s)"), |
d003868e | 7781 | input_bfd, |
55fd94b0 AM |
7782 | sym_name, |
7783 | howto->name, | |
7784 | name); | |
252b5132 RH |
7785 | |
7786 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 7787 | ret = FALSE; |
252b5132 RH |
7788 | continue; |
7789 | } | |
7790 | ||
7791 | if (r_type == R_PPC_EMB_SDA21) | |
7792 | { /* fill in register field */ | |
7619e7c7 | 7793 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
252b5132 | 7794 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); |
7619e7c7 | 7795 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
252b5132 RH |
7796 | } |
7797 | } | |
7798 | break; | |
7799 | ||
70bccea4 | 7800 | /* Relocate against the beginning of the section. */ |
7619e7c7 AM |
7801 | case R_PPC_SECTOFF: |
7802 | case R_PPC_SECTOFF_LO: | |
7803 | case R_PPC_SECTOFF_HI: | |
7804 | case R_PPC_SECTOFF_HA: | |
3b4f3a11 AM |
7805 | if (sec == NULL || sec->output_section == NULL) |
7806 | { | |
7807 | unresolved_reloc = TRUE; | |
7808 | break; | |
7809 | } | |
252b5132 | 7810 | addend -= sec->output_section->vma; |
252b5132 RH |
7811 | break; |
7812 | ||
70bccea4 | 7813 | /* Negative relocations. */ |
7619e7c7 AM |
7814 | case R_PPC_EMB_NADDR32: |
7815 | case R_PPC_EMB_NADDR16: | |
7816 | case R_PPC_EMB_NADDR16_LO: | |
7817 | case R_PPC_EMB_NADDR16_HI: | |
7818 | case R_PPC_EMB_NADDR16_HA: | |
8da6118f | 7819 | addend -= 2 * relocation; |
252b5132 RH |
7820 | break; |
7821 | ||
7619e7c7 AM |
7822 | case R_PPC_COPY: |
7823 | case R_PPC_GLOB_DAT: | |
7824 | case R_PPC_JMP_SLOT: | |
7825 | case R_PPC_RELATIVE: | |
e054468f | 7826 | case R_PPC_IRELATIVE: |
7619e7c7 AM |
7827 | case R_PPC_PLT32: |
7828 | case R_PPC_PLTREL32: | |
7829 | case R_PPC_PLT16_LO: | |
7830 | case R_PPC_PLT16_HI: | |
7831 | case R_PPC_PLT16_HA: | |
7832 | case R_PPC_ADDR30: | |
7833 | case R_PPC_EMB_RELSEC16: | |
7834 | case R_PPC_EMB_RELST_LO: | |
7835 | case R_PPC_EMB_RELST_HI: | |
7836 | case R_PPC_EMB_RELST_HA: | |
7837 | case R_PPC_EMB_BIT_FLD: | |
7838 | (*_bfd_error_handler) | |
d003868e AM |
7839 | (_("%B: relocation %s is not yet supported for symbol %s."), |
7840 | input_bfd, | |
7619e7c7 AM |
7841 | howto->name, |
7842 | sym_name); | |
252b5132 RH |
7843 | |
7844 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 7845 | ret = FALSE; |
252b5132 | 7846 | continue; |
7619e7c7 | 7847 | } |
252b5132 | 7848 | |
7619e7c7 AM |
7849 | /* Do any further special processing. */ |
7850 | switch (r_type) | |
7851 | { | |
7852 | default: | |
7853 | break; | |
7854 | ||
7855 | case R_PPC_ADDR16_HA: | |
d7128ce4 | 7856 | case R_PPC_REL16_HA: |
7619e7c7 AM |
7857 | case R_PPC_SECTOFF_HA: |
7858 | case R_PPC_TPREL16_HA: | |
7859 | case R_PPC_DTPREL16_HA: | |
7619e7c7 AM |
7860 | case R_PPC_EMB_NADDR16_HA: |
7861 | case R_PPC_EMB_RELST_HA: | |
7862 | /* It's just possible that this symbol is a weak symbol | |
7b609f53 | 7863 | that's not actually defined anywhere. In that case, |
7619e7c7 AM |
7864 | 'sec' would be NULL, and we should leave the symbol |
7865 | alone (it will be set to zero elsewhere in the link). */ | |
5c5f6e17 AM |
7866 | if (sec == NULL) |
7867 | break; | |
7868 | /* Fall thru */ | |
7869 | ||
7870 | case R_PPC_PLT16_HA: | |
7871 | case R_PPC_GOT16_HA: | |
7872 | case R_PPC_GOT_TLSGD16_HA: | |
7873 | case R_PPC_GOT_TLSLD16_HA: | |
7874 | case R_PPC_GOT_TPREL16_HA: | |
7875 | case R_PPC_GOT_DTPREL16_HA: | |
7876 | /* Add 0x10000 if sign bit in 0:15 is set. | |
7877 | Bits 0:15 are not used. */ | |
7878 | addend += 0x8000; | |
7619e7c7 | 7879 | break; |
252b5132 RH |
7880 | } |
7881 | ||
252b5132 | 7882 | #ifdef DEBUG |
55fd94b0 AM |
7883 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, " |
7884 | "offset = %ld, addend = %ld\n", | |
252b5132 | 7885 | howto->name, |
8da6118f | 7886 | (int) r_type, |
252b5132 RH |
7887 | sym_name, |
7888 | r_symndx, | |
7619e7c7 | 7889 | (long) rel->r_offset, |
8da6118f | 7890 | (long) addend); |
252b5132 RH |
7891 | #endif |
7892 | ||
7619e7c7 AM |
7893 | if (unresolved_reloc |
7894 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
f5385ebf | 7895 | && h->def_dynamic)) |
7619e7c7 AM |
7896 | { |
7897 | (*_bfd_error_handler) | |
d003868e AM |
7898 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
7899 | input_bfd, | |
7900 | input_section, | |
7619e7c7 | 7901 | (long) rel->r_offset, |
7b609f53 | 7902 | howto->name, |
7619e7c7 AM |
7903 | sym_name); |
7904 | ret = FALSE; | |
7905 | } | |
7906 | ||
252b5132 RH |
7907 | r = _bfd_final_link_relocate (howto, |
7908 | input_bfd, | |
7909 | input_section, | |
7910 | contents, | |
7619e7c7 | 7911 | rel->r_offset, |
252b5132 RH |
7912 | relocation, |
7913 | addend); | |
7914 | ||
7619e7c7 | 7915 | if (r != bfd_reloc_ok) |
252b5132 | 7916 | { |
7619e7c7 | 7917 | if (r == bfd_reloc_overflow) |
252b5132 | 7918 | { |
7619e7c7 AM |
7919 | if (warned) |
7920 | continue; | |
7921 | if (h != NULL | |
7922 | && h->root.type == bfd_link_hash_undefweak | |
dc1bc0c9 RH |
7923 | && howto->pc_relative) |
7924 | { | |
7925 | /* Assume this is a call protected by other code that | |
7926 | detect the symbol is undefined. If this is the case, | |
7927 | we can safely ignore the overflow. If not, the | |
7928 | program is hosed anyway, and a little warning isn't | |
7929 | going to help. */ | |
252b5132 | 7930 | |
dc1bc0c9 RH |
7931 | continue; |
7932 | } | |
252b5132 | 7933 | |
7619e7c7 | 7934 | if (! (*info->callbacks->reloc_overflow) (info, |
dfeffb9f | 7935 | (h ? &h->root : NULL), |
7619e7c7 AM |
7936 | sym_name, |
7937 | howto->name, | |
7938 | rel->r_addend, | |
7939 | input_bfd, | |
7940 | input_section, | |
7941 | rel->r_offset)) | |
7942 | return FALSE; | |
dc1bc0c9 RH |
7943 | } |
7944 | else | |
7945 | { | |
7619e7c7 | 7946 | (*_bfd_error_handler) |
d003868e AM |
7947 | (_("%B(%A+0x%lx): %s reloc against `%s': error %d"), |
7948 | input_bfd, input_section, | |
7b609f53 | 7949 | (long) rel->r_offset, howto->name, sym_name, (int) r); |
7619e7c7 | 7950 | ret = FALSE; |
252b5132 RH |
7951 | } |
7952 | } | |
7953 | } | |
7954 | ||
252b5132 RH |
7955 | #ifdef DEBUG |
7956 | fprintf (stderr, "\n"); | |
7957 | #endif | |
7958 | ||
7959 | return ret; | |
7960 | } | |
252b5132 | 7961 | \f |
25dbc73a AM |
7962 | /* Finish up dynamic symbol handling. We set the contents of various |
7963 | dynamic sections here. */ | |
c5fccbec | 7964 | |
b34976b6 | 7965 | static bfd_boolean |
25dbc73a AM |
7966 | ppc_elf_finish_dynamic_symbol (bfd *output_bfd, |
7967 | struct bfd_link_info *info, | |
7968 | struct elf_link_hash_entry *h, | |
7969 | Elf_Internal_Sym *sym) | |
e1a9cb8e | 7970 | { |
25dbc73a | 7971 | struct ppc_elf_link_hash_table *htab; |
a6aa5195 AM |
7972 | struct plt_entry *ent; |
7973 | bfd_boolean doneone; | |
e1a9cb8e | 7974 | |
25dbc73a AM |
7975 | #ifdef DEBUG |
7976 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", | |
7977 | h->root.root.string); | |
7978 | #endif | |
e1a9cb8e | 7979 | |
25dbc73a AM |
7980 | htab = ppc_elf_hash_table (info); |
7981 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
e1a9cb8e | 7982 | |
a6aa5195 AM |
7983 | doneone = FALSE; |
7984 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
7985 | if (ent->plt.offset != (bfd_vma) -1) | |
7986 | { | |
7987 | if (!doneone) | |
7988 | { | |
7989 | Elf_Internal_Rela rela; | |
7990 | bfd_byte *loc; | |
7991 | bfd_vma reloc_index; | |
e1a9cb8e | 7992 | |
e054468f | 7993 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
7994 | || !htab->elf.dynamic_sections_created |
7995 | || h->dynindx == -1) | |
9d8504b1 PB |
7996 | reloc_index = ent->plt.offset / 4; |
7997 | else | |
7998 | { | |
7999 | reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size) | |
8000 | / htab->plt_slot_size); | |
8001 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES | |
4a3dc543 | 8002 | && htab->plt_type == PLT_OLD) |
9d8504b1 PB |
8003 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; |
8004 | } | |
8005 | ||
a6aa5195 AM |
8006 | /* This symbol has an entry in the procedure linkage table. |
8007 | Set it up. */ | |
e054468f | 8008 | if (htab->plt_type == PLT_VXWORKS |
25f23106 AM |
8009 | && htab->elf.dynamic_sections_created |
8010 | && h->dynindx != -1) | |
a6aa5195 | 8011 | { |
9d8504b1 PB |
8012 | bfd_vma got_offset; |
8013 | const bfd_vma *plt_entry; | |
8014 | ||
8015 | /* The first three entries in .got.plt are reserved. */ | |
8016 | got_offset = (reloc_index + 3) * 4; | |
8017 | ||
8018 | /* Use the right PLT. */ | |
8019 | plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry | |
8020 | : ppc_elf_vxworks_plt_entry; | |
8021 | ||
8022 | /* Fill in the .plt on VxWorks. */ | |
8023 | if (info->shared) | |
8024 | { | |
9d8504b1 | 8025 | bfd_put_32 (output_bfd, |
e87d4038 | 8026 | plt_entry[0] | PPC_HA (got_offset), |
9d8504b1 PB |
8027 | htab->plt->contents + ent->plt.offset + 0); |
8028 | bfd_put_32 (output_bfd, | |
e87d4038 | 8029 | plt_entry[1] | PPC_LO (got_offset), |
9d8504b1 PB |
8030 | htab->plt->contents + ent->plt.offset + 4); |
8031 | } | |
8032 | else | |
8033 | { | |
e87d4038 | 8034 | bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot); |
9d8504b1 PB |
8035 | |
8036 | bfd_put_32 (output_bfd, | |
e87d4038 | 8037 | plt_entry[0] | PPC_HA (got_loc), |
9d8504b1 PB |
8038 | htab->plt->contents + ent->plt.offset + 0); |
8039 | bfd_put_32 (output_bfd, | |
e87d4038 | 8040 | plt_entry[1] | PPC_LO (got_loc), |
9d8504b1 PB |
8041 | htab->plt->contents + ent->plt.offset + 4); |
8042 | } | |
8043 | ||
8044 | bfd_put_32 (output_bfd, plt_entry[2], | |
8045 | htab->plt->contents + ent->plt.offset + 8); | |
8046 | bfd_put_32 (output_bfd, plt_entry[3], | |
8047 | htab->plt->contents + ent->plt.offset + 12); | |
8048 | ||
8049 | /* This instruction is an immediate load. The value loaded is | |
8050 | the byte offset of the R_PPC_JMP_SLOT relocation from the | |
8051 | start of the .rela.plt section. The value is stored in the | |
8052 | low-order 16 bits of the load instruction. */ | |
8053 | /* NOTE: It appears that this is now an index rather than a | |
8054 | prescaled offset. */ | |
8055 | bfd_put_32 (output_bfd, | |
8056 | plt_entry[4] | reloc_index, | |
8057 | htab->plt->contents + ent->plt.offset + 16); | |
8058 | /* This instruction is a PC-relative branch whose target is | |
8059 | the start of the PLT section. The address of this branch | |
8060 | instruction is 20 bytes beyond the start of this PLT entry. | |
8061 | The address is encoded in bits 6-29, inclusive. The value | |
8062 | stored is right-shifted by two bits, permitting a 26-bit | |
8063 | offset. */ | |
8064 | bfd_put_32 (output_bfd, | |
8065 | (plt_entry[5] | |
8066 | | (-(ent->plt.offset + 20) & 0x03fffffc)), | |
8067 | htab->plt->contents + ent->plt.offset + 20); | |
8068 | bfd_put_32 (output_bfd, plt_entry[6], | |
8069 | htab->plt->contents + ent->plt.offset + 24); | |
8070 | bfd_put_32 (output_bfd, plt_entry[7], | |
8071 | htab->plt->contents + ent->plt.offset + 28); | |
8072 | ||
8073 | /* Fill in the GOT entry corresponding to this PLT slot with | |
8074 | the address immediately after the the "bctr" instruction | |
8075 | in this PLT entry. */ | |
8076 | bfd_put_32 (output_bfd, (htab->plt->output_section->vma | |
8077 | + htab->plt->output_offset | |
8078 | + ent->plt.offset + 16), | |
8079 | htab->sgotplt->contents + got_offset); | |
8080 | ||
8081 | if (!info->shared) | |
8082 | { | |
8083 | /* Fill in a couple of entries in .rela.plt.unloaded. */ | |
8084 | loc = htab->srelplt2->contents | |
8085 | + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index | |
8086 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS) | |
8087 | * sizeof (Elf32_External_Rela)); | |
8088 | ||
8089 | /* Provide the @ha relocation for the first instruction. */ | |
8090 | rela.r_offset = (htab->plt->output_section->vma | |
8091 | + htab->plt->output_offset | |
8092 | + ent->plt.offset + 2); | |
636ce3f5 | 8093 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
8094 | R_PPC_ADDR16_HA); |
8095 | rela.r_addend = got_offset; | |
8096 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8097 | loc += sizeof (Elf32_External_Rela); | |
8098 | ||
8099 | /* Provide the @l relocation for the second instruction. */ | |
8100 | rela.r_offset = (htab->plt->output_section->vma | |
8101 | + htab->plt->output_offset | |
8102 | + ent->plt.offset + 6); | |
636ce3f5 | 8103 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
8104 | R_PPC_ADDR16_LO); |
8105 | rela.r_addend = got_offset; | |
8106 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8107 | loc += sizeof (Elf32_External_Rela); | |
8108 | ||
8109 | /* Provide a relocation for the GOT entry corresponding to this | |
8110 | PLT slot. Point it at the middle of the .plt entry. */ | |
8111 | rela.r_offset = (htab->sgotplt->output_section->vma | |
8112 | + htab->sgotplt->output_offset | |
8113 | + got_offset); | |
7325306f | 8114 | rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, |
9d8504b1 PB |
8115 | R_PPC_ADDR32); |
8116 | rela.r_addend = ent->plt.offset + 16; | |
8117 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8118 | } | |
8119 | ||
8120 | /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT. | |
8121 | In particular, the offset for the relocation is not the | |
8122 | address of the PLT entry for this function, as specified | |
8123 | by the ABI. Instead, the offset is set to the address of | |
8124 | the GOT slot for this function. See EABI 4.4.4.1. */ | |
8125 | rela.r_offset = (htab->sgotplt->output_section->vma | |
8126 | + htab->sgotplt->output_offset | |
8127 | + got_offset); | |
8128 | ||
a6aa5195 AM |
8129 | } |
8130 | else | |
8131 | { | |
e054468f | 8132 | asection *splt = htab->plt; |
25f23106 AM |
8133 | if (!htab->elf.dynamic_sections_created |
8134 | || h->dynindx == -1) | |
e054468f AM |
8135 | splt = htab->iplt; |
8136 | ||
8137 | rela.r_offset = (splt->output_section->vma | |
8138 | + splt->output_offset | |
9d8504b1 | 8139 | + ent->plt.offset); |
e054468f | 8140 | if (htab->plt_type == PLT_OLD |
25f23106 AM |
8141 | || !htab->elf.dynamic_sections_created |
8142 | || h->dynindx == -1) | |
9d8504b1 PB |
8143 | { |
8144 | /* We don't need to fill in the .plt. The ppc dynamic | |
8145 | linker will fill it in. */ | |
8146 | } | |
8147 | else | |
8148 | { | |
8149 | bfd_vma val = (htab->glink_pltresolve + ent->plt.offset | |
8150 | + htab->glink->output_section->vma | |
8151 | + htab->glink->output_offset); | |
8152 | bfd_put_32 (output_bfd, val, | |
e054468f | 8153 | splt->contents + ent->plt.offset); |
9d8504b1 | 8154 | } |
a6aa5195 | 8155 | } |
e1a9cb8e | 8156 | |
a6aa5195 | 8157 | /* Fill in the entry in the .rela.plt section. */ |
a6aa5195 | 8158 | rela.r_addend = 0; |
e054468f AM |
8159 | if (!htab->elf.dynamic_sections_created |
8160 | || h->dynindx == -1) | |
8161 | { | |
8162 | BFD_ASSERT (h->type == STT_GNU_IFUNC | |
8163 | && h->def_regular | |
8164 | && (h->root.type == bfd_link_hash_defined | |
8165 | || h->root.type == bfd_link_hash_defweak)); | |
8166 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
8167 | rela.r_addend = SYM_VAL (h); | |
8168 | } | |
8169 | else | |
8170 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); | |
e1a9cb8e | 8171 | |
25f23106 AM |
8172 | if (!htab->elf.dynamic_sections_created |
8173 | || h->dynindx == -1) | |
8174 | loc = (htab->reliplt->contents | |
8175 | + (htab->reliplt->reloc_count++ | |
8176 | * sizeof (Elf32_External_Rela))); | |
e054468f | 8177 | else |
25f23106 AM |
8178 | loc = (htab->relplt->contents |
8179 | + reloc_index * sizeof (Elf32_External_Rela)); | |
a6aa5195 | 8180 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
e1a9cb8e | 8181 | |
a6aa5195 AM |
8182 | if (!h->def_regular) |
8183 | { | |
0eb4a168 AM |
8184 | /* Mark the symbol as undefined, rather than as |
8185 | defined in the .plt section. Leave the value if | |
8186 | there were any relocations where pointer equality | |
8187 | matters (this is a clue for the dynamic linker, to | |
8188 | make function pointer comparisons work between an | |
8189 | application and shared library), otherwise set it | |
8190 | to zero. */ | |
a6aa5195 | 8191 | sym->st_shndx = SHN_UNDEF; |
0eb4a168 | 8192 | if (!h->pointer_equality_needed) |
a6aa5195 | 8193 | sym->st_value = 0; |
0eb4a168 AM |
8194 | else if (!h->ref_regular_nonweak) |
8195 | { | |
625af618 AM |
8196 | /* This breaks function pointer comparisons, but |
8197 | that is better than breaking tests for a NULL | |
0eb4a168 | 8198 | function pointer. */ |
0eb4a168 AM |
8199 | sym->st_value = 0; |
8200 | } | |
a6aa5195 | 8201 | } |
de972ffa AM |
8202 | else if (h->type == STT_GNU_IFUNC |
8203 | && !info->shared) | |
8204 | { | |
8205 | /* Set the value of ifunc symbols in a non-pie | |
8206 | executable to the glink entry. This is to avoid | |
8207 | text relocations. We can't do this for ifunc in | |
8208 | allocate_dynrelocs, as we do for normal dynamic | |
8209 | function symbols with plt entries, because we need | |
8210 | to keep the original value around for the ifunc | |
8211 | relocation. */ | |
8212 | sym->st_shndx = (_bfd_elf_section_from_bfd_section | |
8213 | (output_bfd, htab->glink->output_section)); | |
8214 | sym->st_value = (ent->glink_offset + | |
8215 | htab->glink->output_offset | |
8216 | + htab->glink->output_section->vma); | |
8217 | } | |
a6aa5195 AM |
8218 | doneone = TRUE; |
8219 | } | |
e1a9cb8e | 8220 | |
e054468f | 8221 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
8222 | || !htab->elf.dynamic_sections_created |
8223 | || h->dynindx == -1) | |
a6aa5195 | 8224 | { |
e054468f | 8225 | asection *splt = htab->plt; |
25f23106 AM |
8226 | if (!htab->elf.dynamic_sections_created |
8227 | || h->dynindx == -1) | |
e054468f | 8228 | splt = htab->iplt; |
e1a9cb8e | 8229 | |
e054468f | 8230 | write_glink_stub (ent, splt, info); |
e1a9cb8e | 8231 | |
a877a2b6 | 8232 | if (!info->shared) |
e054468f AM |
8233 | /* We only need one non-PIC glink stub. */ |
8234 | break; | |
a6aa5195 AM |
8235 | } |
8236 | else | |
8237 | break; | |
8238 | } | |
e1a9cb8e | 8239 | |
25dbc73a AM |
8240 | if (h->needs_copy) |
8241 | { | |
8242 | asection *s; | |
8243 | Elf_Internal_Rela rela; | |
8244 | bfd_byte *loc; | |
e1a9cb8e | 8245 | |
25dbc73a | 8246 | /* This symbols needs a copy reloc. Set it up. */ |
e1a9cb8e | 8247 | |
25dbc73a AM |
8248 | #ifdef DEBUG |
8249 | fprintf (stderr, ", copy"); | |
8250 | #endif | |
e1a9cb8e | 8251 | |
25dbc73a | 8252 | BFD_ASSERT (h->dynindx != -1); |
86bbe32f | 8253 | |
4dc4a9a5 | 8254 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
8255 | s = htab->relsbss; |
8256 | else | |
8257 | s = htab->relbss; | |
8258 | BFD_ASSERT (s != NULL); | |
e1a9cb8e | 8259 | |
e87d4038 | 8260 | rela.r_offset = SYM_VAL (h); |
25dbc73a AM |
8261 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); |
8262 | rela.r_addend = 0; | |
8263 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); | |
8264 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8265 | } | |
e1a9cb8e | 8266 | |
25dbc73a AM |
8267 | #ifdef DEBUG |
8268 | fprintf (stderr, "\n"); | |
8269 | #endif | |
e1a9cb8e | 8270 | |
25dbc73a | 8271 | /* Mark some specially defined symbols as absolute. */ |
9d8504b1 PB |
8272 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
8273 | || (!htab->is_vxworks | |
8274 | && (h == htab->elf.hgot | |
8275 | || strcmp (h->root.root.string, | |
8276 | "_PROCEDURE_LINKAGE_TABLE_") == 0))) | |
25dbc73a | 8277 | sym->st_shndx = SHN_ABS; |
e1a9cb8e | 8278 | |
25dbc73a AM |
8279 | return TRUE; |
8280 | } | |
8281 | \f | |
8282 | static enum elf_reloc_type_class | |
8283 | ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela) | |
e1a9cb8e | 8284 | { |
25dbc73a AM |
8285 | switch (ELF32_R_TYPE (rela->r_info)) |
8286 | { | |
8287 | case R_PPC_RELATIVE: | |
8288 | return reloc_class_relative; | |
8289 | case R_PPC_REL24: | |
8290 | case R_PPC_ADDR24: | |
8291 | case R_PPC_JMP_SLOT: | |
8292 | return reloc_class_plt; | |
8293 | case R_PPC_COPY: | |
8294 | return reloc_class_copy; | |
8295 | default: | |
8296 | return reloc_class_normal; | |
8297 | } | |
e1a9cb8e | 8298 | } |
25dbc73a AM |
8299 | \f |
8300 | /* Finish up the dynamic sections. */ | |
e1a9cb8e | 8301 | |
25dbc73a AM |
8302 | static bfd_boolean |
8303 | ppc_elf_finish_dynamic_sections (bfd *output_bfd, | |
8304 | struct bfd_link_info *info) | |
e1a9cb8e | 8305 | { |
25dbc73a | 8306 | asection *sdyn; |
9d8504b1 | 8307 | asection *splt; |
25dbc73a | 8308 | struct ppc_elf_link_hash_table *htab; |
1fe44d79 | 8309 | bfd_vma got; |
e87d4038 AM |
8310 | bfd *dynobj; |
8311 | bfd_boolean ret = TRUE; | |
e1a9cb8e | 8312 | |
25dbc73a AM |
8313 | #ifdef DEBUG |
8314 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
8315 | #endif | |
6b0817e5 | 8316 | |
25dbc73a | 8317 | htab = ppc_elf_hash_table (info); |
9d8504b1 PB |
8318 | dynobj = elf_hash_table (info)->dynobj; |
8319 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
8320 | if (htab->is_vxworks) | |
8321 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
8322 | else | |
8323 | splt = NULL; | |
e1a9cb8e | 8324 | |
1fe44d79 AM |
8325 | got = 0; |
8326 | if (htab->elf.hgot != NULL) | |
e87d4038 | 8327 | got = SYM_VAL (htab->elf.hgot); |
1fe44d79 | 8328 | |
25dbc73a | 8329 | if (htab->elf.dynamic_sections_created) |
e1a9cb8e | 8330 | { |
25dbc73a | 8331 | Elf32_External_Dyn *dyncon, *dynconend; |
e1a9cb8e | 8332 | |
25dbc73a | 8333 | BFD_ASSERT (htab->plt != NULL && sdyn != NULL); |
86bbe32f | 8334 | |
25dbc73a AM |
8335 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
8336 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); | |
8337 | for (; dyncon < dynconend; dyncon++) | |
8338 | { | |
8339 | Elf_Internal_Dyn dyn; | |
8340 | asection *s; | |
e1a9cb8e | 8341 | |
9d8504b1 | 8342 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
86bbe32f | 8343 | |
25dbc73a AM |
8344 | switch (dyn.d_tag) |
8345 | { | |
8346 | case DT_PLTGOT: | |
9d8504b1 PB |
8347 | if (htab->is_vxworks) |
8348 | s = htab->sgotplt; | |
8349 | else | |
8350 | s = htab->plt; | |
25dbc73a AM |
8351 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
8352 | break; | |
86bbe32f | 8353 | |
25dbc73a AM |
8354 | case DT_PLTRELSZ: |
8355 | dyn.d_un.d_val = htab->relplt->size; | |
8356 | break; | |
e1a9cb8e | 8357 | |
25dbc73a AM |
8358 | case DT_JMPREL: |
8359 | s = htab->relplt; | |
8360 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
8361 | break; | |
2f89ff8d | 8362 | |
1fe44d79 AM |
8363 | case DT_PPC_GOT: |
8364 | dyn.d_un.d_ptr = got; | |
d7128ce4 AM |
8365 | break; |
8366 | ||
9d8504b1 PB |
8367 | case DT_RELASZ: |
8368 | if (htab->is_vxworks) | |
8369 | { | |
8370 | if (htab->relplt) | |
8371 | dyn.d_un.d_ptr -= htab->relplt->size; | |
8372 | break; | |
8373 | } | |
8374 | continue; | |
8375 | ||
25dbc73a | 8376 | default: |
7a2b07ff NS |
8377 | if (htab->is_vxworks |
8378 | && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) | |
8379 | break; | |
25dbc73a AM |
8380 | continue; |
8381 | } | |
4c45e5c9 | 8382 | |
25dbc73a AM |
8383 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
8384 | } | |
8385 | } | |
4c45e5c9 | 8386 | |
3b36f7e6 | 8387 | if (htab->got != NULL) |
25dbc73a | 8388 | { |
e79f5955 AM |
8389 | if (htab->elf.hgot->root.u.def.section == htab->got |
8390 | || htab->elf.hgot->root.u.def.section == htab->sgotplt) | |
e87d4038 | 8391 | { |
e79f5955 | 8392 | unsigned char *p = htab->elf.hgot->root.u.def.section->contents; |
2f89ff8d | 8393 | |
e87d4038 AM |
8394 | p += htab->elf.hgot->root.u.def.value; |
8395 | if (htab->plt_type == PLT_OLD) | |
e79f5955 AM |
8396 | { |
8397 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 | |
8398 | so that a function can easily find the address of | |
8399 | _GLOBAL_OFFSET_TABLE_. */ | |
8400 | BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4 | |
8401 | < htab->elf.hgot->root.u.def.section->size); | |
8402 | bfd_put_32 (output_bfd, 0x4e800021, p - 4); | |
8403 | } | |
3b36f7e6 | 8404 | |
e87d4038 | 8405 | if (sdyn != NULL) |
e79f5955 AM |
8406 | { |
8407 | bfd_vma val = sdyn->output_section->vma + sdyn->output_offset; | |
8408 | BFD_ASSERT (htab->elf.hgot->root.u.def.value | |
8409 | < htab->elf.hgot->root.u.def.section->size); | |
8410 | bfd_put_32 (output_bfd, val, p); | |
8411 | } | |
e87d4038 AM |
8412 | } |
8413 | else | |
8414 | { | |
8415 | (*_bfd_error_handler) (_("%s not defined in linker created %s"), | |
8416 | htab->elf.hgot->root.root.string, | |
e79f5955 AM |
8417 | (htab->sgotplt != NULL |
8418 | ? htab->sgotplt->name : htab->got->name)); | |
e87d4038 AM |
8419 | bfd_set_error (bfd_error_bad_value); |
8420 | ret = FALSE; | |
8421 | } | |
25dbc73a AM |
8422 | |
8423 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4; | |
8424 | } | |
8425 | ||
9d8504b1 PB |
8426 | /* Fill in the first entry in the VxWorks procedure linkage table. */ |
8427 | if (splt && splt->size > 0) | |
8428 | { | |
8429 | /* Use the right PLT. */ | |
8430 | static const bfd_vma *plt_entry = NULL; | |
8431 | plt_entry = info->shared ? | |
8432 | ppc_elf_vxworks_pic_plt0_entry : ppc_elf_vxworks_plt0_entry; | |
8433 | ||
8434 | if (!info->shared) | |
8435 | { | |
e87d4038 | 8436 | bfd_vma got_value = SYM_VAL (htab->elf.hgot); |
9d8504b1 | 8437 | |
e87d4038 | 8438 | bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value), |
9d8504b1 | 8439 | splt->contents + 0); |
e87d4038 | 8440 | bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value), |
9d8504b1 PB |
8441 | splt->contents + 4); |
8442 | } | |
8443 | else | |
8444 | { | |
8445 | bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0); | |
8446 | bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4); | |
8447 | } | |
8448 | bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8); | |
8449 | bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12); | |
8450 | bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16); | |
8451 | bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20); | |
8452 | bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24); | |
8453 | bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28); | |
8454 | ||
8455 | if (! info->shared) | |
8456 | { | |
8457 | Elf_Internal_Rela rela; | |
8458 | bfd_byte *loc; | |
8459 | ||
8460 | loc = htab->srelplt2->contents; | |
8461 | ||
8462 | /* Output the @ha relocation for the first instruction. */ | |
8463 | rela.r_offset = (htab->plt->output_section->vma | |
8464 | + htab->plt->output_offset | |
8465 | + 2); | |
636ce3f5 | 8466 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
8467 | rela.r_addend = 0; |
8468 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8469 | loc += sizeof (Elf32_External_Rela); | |
8470 | ||
8471 | /* Output the @l relocation for the second instruction. */ | |
8472 | rela.r_offset = (htab->plt->output_section->vma | |
8473 | + htab->plt->output_offset | |
8474 | + 6); | |
636ce3f5 | 8475 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
8476 | rela.r_addend = 0; |
8477 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8478 | loc += sizeof (Elf32_External_Rela); | |
8479 | ||
8480 | /* Fix up the remaining relocations. They may have the wrong | |
8481 | symbol index for _G_O_T_ or _P_L_T_ depending on the order | |
8482 | in which symbols were output. */ | |
8483 | while (loc < htab->srelplt2->contents + htab->srelplt2->size) | |
8484 | { | |
8485 | Elf_Internal_Rela rel; | |
8486 | ||
8487 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 8488 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
8489 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8490 | loc += sizeof (Elf32_External_Rela); | |
8491 | ||
8492 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 8493 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
8494 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8495 | loc += sizeof (Elf32_External_Rela); | |
8496 | ||
8497 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
7325306f | 8498 | rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32); |
9d8504b1 PB |
8499 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8500 | loc += sizeof (Elf32_External_Rela); | |
8501 | } | |
8502 | } | |
8503 | } | |
8504 | ||
e054468f AM |
8505 | if (htab->glink != NULL |
8506 | && htab->glink->contents != NULL | |
8507 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
8508 | { |
8509 | unsigned char *p; | |
8510 | unsigned char *endp; | |
a6aa5195 | 8511 | bfd_vma res0; |
d7128ce4 | 8512 | unsigned int i; |
a6aa5195 AM |
8513 | |
8514 | /* | |
8515 | * PIC glink code is the following: | |
8516 | * | |
8517 | * # ith PLT code stub. | |
8518 | * addis 11,30,(plt+(i-1)*4-got)@ha | |
8519 | * lwz 11,(plt+(i-1)*4-got)@l(11) | |
8520 | * mtctr 11 | |
8521 | * bctr | |
8522 | * | |
8523 | * # A table of branches, one for each plt entry. | |
176a0d42 | 8524 | * # The idea is that the plt call stub loads ctr and r11 with these |
a6aa5195 AM |
8525 | * # addresses, so (r11 - res_0) gives the plt index * 4. |
8526 | * res_0: b PLTresolve | |
8527 | * res_1: b PLTresolve | |
8528 | * . | |
8529 | * # Some number of entries towards the end can be nops | |
8530 | * res_n_m3: nop | |
8531 | * res_n_m2: nop | |
8532 | * res_n_m1: | |
8533 | * | |
8534 | * PLTresolve: | |
8535 | * addis 11,11,(1f-res_0)@ha | |
8536 | * mflr 0 | |
8537 | * bcl 20,31,1f | |
8538 | * 1: addi 11,11,(1b-res_0)@l | |
8539 | * mflr 12 | |
8540 | * mtlr 0 | |
8541 | * sub 11,11,12 # r11 = index * 4 | |
8542 | * addis 12,12,(got+4-1b)@ha | |
8543 | * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve | |
8544 | * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address | |
8545 | * mtctr 0 | |
8546 | * add 0,11,11 | |
8547 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
8548 | * bctr | |
8549 | */ | |
8550 | static const unsigned int pic_plt_resolve[] = | |
8551 | { | |
8552 | ADDIS_11_11, | |
8553 | MFLR_0, | |
8554 | BCL_20_31, | |
8555 | ADDI_11_11, | |
8556 | MFLR_12, | |
8557 | MTLR_0, | |
8558 | SUB_11_11_12, | |
8559 | ADDIS_12_12, | |
8560 | LWZ_0_12, | |
8561 | LWZ_12_12, | |
8562 | MTCTR_0, | |
8563 | ADD_0_11_11, | |
8564 | ADD_11_0_11, | |
8565 | BCTR, | |
8566 | NOP, | |
8567 | NOP | |
8568 | }; | |
8569 | ||
176a0d42 AM |
8570 | /* |
8571 | * Non-PIC glink code is a little simpler. | |
8572 | * | |
8573 | * # ith PLT code stub. | |
8574 | * lis 11,(plt+(i-1)*4)@ha | |
8575 | * lwz 11,(plt+(i-1)*4)@l(11) | |
8576 | * mtctr 11 | |
8577 | * bctr | |
8578 | * | |
8579 | * The branch table is the same, then comes | |
8580 | * | |
8581 | * PLTresolve: | |
8582 | * lis 12,(got+4)@ha | |
8583 | * addis 11,11,(-res_0)@ha | |
8584 | * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve | |
8585 | * addi 11,11,(-res_0)@l # r11 = index * 4 | |
8586 | * mtctr 0 | |
8587 | * add 0,11,11 | |
8588 | * lwz 12,(got+8)@l(12) # got[2] contains the map address | |
8589 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
8590 | * bctr | |
8591 | */ | |
d7128ce4 AM |
8592 | static const unsigned int plt_resolve[] = |
8593 | { | |
a6aa5195 AM |
8594 | LIS_12, |
8595 | ADDIS_11_11, | |
8596 | LWZ_0_12, | |
8597 | ADDI_11_11, | |
d7128ce4 | 8598 | MTCTR_0, |
7e8aeb9a | 8599 | ADD_0_11_11, |
a6aa5195 | 8600 | LWZ_12_12, |
7e8aeb9a | 8601 | ADD_11_0_11, |
d7128ce4 AM |
8602 | BCTR, |
8603 | NOP, | |
8604 | NOP, | |
a6aa5195 AM |
8605 | NOP, |
8606 | NOP, | |
8607 | NOP, | |
8608 | NOP, | |
d7128ce4 AM |
8609 | NOP |
8610 | }; | |
8611 | ||
a6aa5195 AM |
8612 | if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4) |
8613 | abort (); | |
8614 | if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4) | |
7e8aeb9a AM |
8615 | abort (); |
8616 | ||
a6aa5195 | 8617 | /* Build the branch table, one for each plt entry (less one), |
86b9da88 | 8618 | and perhaps some padding. */ |
a6aa5195 AM |
8619 | p = htab->glink->contents; |
8620 | p += htab->glink_pltresolve; | |
86b9da88 AM |
8621 | endp = htab->glink->contents; |
8622 | endp += htab->glink->size - GLINK_PLTRESOLVE; | |
8623 | while (p < endp - 8 * 4) | |
8624 | { | |
8625 | bfd_put_32 (output_bfd, B + endp - p, p); | |
8626 | p += 4; | |
8627 | } | |
8628 | while (p < endp) | |
8629 | { | |
8630 | bfd_put_32 (output_bfd, NOP, p); | |
8631 | p += 4; | |
8632 | } | |
8633 | ||
7e8aeb9a | 8634 | res0 = (htab->glink_pltresolve |
86b9da88 AM |
8635 | + htab->glink->output_section->vma |
8636 | + htab->glink->output_offset); | |
8637 | ||
8638 | /* Last comes the PLTresolve stub. */ | |
a877a2b6 | 8639 | if (info->shared) |
7e8aeb9a | 8640 | { |
a6aa5195 | 8641 | bfd_vma bcl; |
d7128ce4 | 8642 | |
a6aa5195 | 8643 | for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++) |
7e8aeb9a | 8644 | { |
a6aa5195 | 8645 | bfd_put_32 (output_bfd, pic_plt_resolve[i], p); |
7e8aeb9a AM |
8646 | p += 4; |
8647 | } | |
a6aa5195 AM |
8648 | p -= 4 * ARRAY_SIZE (pic_plt_resolve); |
8649 | ||
8650 | bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4 | |
8651 | + htab->glink->output_section->vma | |
8652 | + htab->glink->output_offset); | |
8653 | ||
8654 | bfd_put_32 (output_bfd, | |
8655 | ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4); | |
8656 | bfd_put_32 (output_bfd, | |
8657 | ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4); | |
8658 | bfd_put_32 (output_bfd, | |
8659 | ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4); | |
8660 | if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl)) | |
8661 | { | |
8662 | bfd_put_32 (output_bfd, | |
8663 | LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
8664 | bfd_put_32 (output_bfd, | |
8665 | LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4); | |
8666 | } | |
8667 | else | |
8668 | { | |
8669 | bfd_put_32 (output_bfd, | |
8670 | LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
8671 | bfd_put_32 (output_bfd, | |
8672 | LWZ_12_12 + 4, p + 9*4); | |
8673 | } | |
7e8aeb9a AM |
8674 | } |
8675 | else | |
d7128ce4 | 8676 | { |
a6aa5195 | 8677 | for (i = 0; i < ARRAY_SIZE (plt_resolve); i++) |
7e8aeb9a AM |
8678 | { |
8679 | bfd_put_32 (output_bfd, plt_resolve[i], p); | |
8680 | p += 4; | |
8681 | } | |
a6aa5195 AM |
8682 | p -= 4 * ARRAY_SIZE (plt_resolve); |
8683 | ||
8684 | bfd_put_32 (output_bfd, | |
8685 | LIS_12 + PPC_HA (got + 4), p + 0*4); | |
8686 | bfd_put_32 (output_bfd, | |
8687 | ADDIS_11_11 + PPC_HA (-res0), p + 1*4); | |
8688 | bfd_put_32 (output_bfd, | |
8689 | ADDI_11_11 + PPC_LO (-res0), p + 3*4); | |
8690 | if (PPC_HA (got + 4) == PPC_HA (got + 8)) | |
8691 | { | |
8692 | bfd_put_32 (output_bfd, | |
8693 | LWZ_0_12 + PPC_LO (got + 4), p + 2*4); | |
8694 | bfd_put_32 (output_bfd, | |
8695 | LWZ_12_12 + PPC_LO (got + 8), p + 6*4); | |
8696 | } | |
8697 | else | |
8698 | { | |
8699 | bfd_put_32 (output_bfd, | |
8700 | LWZU_0_12 + PPC_LO (got + 4), p + 2*4); | |
8701 | bfd_put_32 (output_bfd, | |
8702 | LWZ_12_12 + 4, p + 6*4); | |
8703 | } | |
d7128ce4 | 8704 | } |
d7128ce4 AM |
8705 | } |
8706 | ||
e87d4038 | 8707 | return ret; |
25dbc73a | 8708 | } |
e1a9cb8e | 8709 | \f |
252b5132 RH |
8710 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
8711 | #define TARGET_LITTLE_NAME "elf32-powerpcle" | |
8712 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec | |
8713 | #define TARGET_BIG_NAME "elf32-powerpc" | |
8714 | #define ELF_ARCH bfd_arch_powerpc | |
8715 | #define ELF_MACHINE_CODE EM_PPC | |
d0facd1b NC |
8716 | #ifdef __QNXTARGET__ |
8717 | #define ELF_MAXPAGESIZE 0x1000 | |
8718 | #else | |
252b5132 | 8719 | #define ELF_MAXPAGESIZE 0x10000 |
d0facd1b | 8720 | #endif |
b1342370 | 8721 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 8722 | #define ELF_COMMONPAGESIZE 0x1000 |
252b5132 RH |
8723 | #define elf_info_to_howto ppc_elf_info_to_howto |
8724 | ||
8725 | #ifdef EM_CYGNUS_POWERPC | |
8726 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
8727 | #endif | |
8728 | ||
8729 | #ifdef EM_PPC_OLD | |
8730 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
8731 | #endif | |
8732 | ||
8733 | #define elf_backend_plt_not_loaded 1 | |
252b5132 | 8734 | #define elf_backend_can_gc_sections 1 |
51b64d56 | 8735 | #define elf_backend_can_refcount 1 |
b491616a | 8736 | #define elf_backend_rela_normal 1 |
252b5132 | 8737 | |
43c40ab2 | 8738 | #define bfd_elf32_mkobject ppc_elf_mkobject |
252b5132 | 8739 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
70bccea4 | 8740 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section |
252b5132 | 8741 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup |
157090f7 | 8742 | #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup |
252b5132 | 8743 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags |
70bccea4 | 8744 | #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create |
468392fb | 8745 | #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab |
252b5132 | 8746 | |
feee612b | 8747 | #define elf_backend_object_p ppc_elf_object_p |
252b5132 RH |
8748 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
8749 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook | |
8750 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr | |
8751 | #define elf_backend_relocate_section ppc_elf_relocate_section | |
8752 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections | |
8753 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
7fce784e | 8754 | #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol |
252b5132 RH |
8755 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol |
8756 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook | |
8757 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
0eb4a168 | 8758 | #define elf_backend_hash_symbol ppc_elf_hash_symbol |
252b5132 RH |
8759 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol |
8760 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
8761 | #define elf_backend_fake_sections ppc_elf_fake_sections | |
8762 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers | |
c5fccbec DJ |
8763 | #define elf_backend_grok_prstatus ppc_elf_grok_prstatus |
8764 | #define elf_backend_grok_psinfo ppc_elf_grok_psinfo | |
183e98be | 8765 | #define elf_backend_write_core_note ppc_elf_write_core_note |
29c2fb7c | 8766 | #define elf_backend_reloc_type_class ppc_elf_reloc_type_class |
70bccea4 AM |
8767 | #define elf_backend_begin_write_processing ppc_elf_begin_write_processing |
8768 | #define elf_backend_final_write_processing ppc_elf_final_write_processing | |
8769 | #define elf_backend_write_section ppc_elf_write_section | |
551b43fd | 8770 | #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr |
4c45e5c9 | 8771 | #define elf_backend_plt_sym_val ppc_elf_plt_sym_val |
8a696751 | 8772 | #define elf_backend_action_discarded ppc_elf_action_discarded |
74541ad4 | 8773 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
e054468f | 8774 | #define elf_backend_post_process_headers _bfd_elf_set_osabi |
252b5132 RH |
8775 | |
8776 | #include "elf32-target.h" | |
9d8504b1 PB |
8777 | |
8778 | /* VxWorks Target */ | |
8779 | ||
8780 | #undef TARGET_LITTLE_SYM | |
8781 | #undef TARGET_LITTLE_NAME | |
8782 | ||
8783 | #undef TARGET_BIG_SYM | |
8784 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec | |
8785 | #undef TARGET_BIG_NAME | |
8786 | #define TARGET_BIG_NAME "elf32-powerpc-vxworks" | |
8787 | ||
d5e3d971 PB |
8788 | /* VxWorks uses the elf default section flags for .plt. */ |
8789 | static const struct bfd_elf_special_section * | |
8790 | ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) | |
9d8504b1 | 8791 | { |
d5e3d971 PB |
8792 | if (sec->name == NULL) |
8793 | return NULL; | |
8794 | ||
8795 | if (strcmp (sec->name, ".plt") == 0) | |
8796 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
8797 | ||
8798 | return ppc_elf_get_sec_type_attr (abfd, sec); | |
8799 | } | |
9d8504b1 PB |
8800 | |
8801 | /* Like ppc_elf_link_hash_table_create, but overrides | |
8802 | appropriately for VxWorks. */ | |
8803 | static struct bfd_link_hash_table * | |
8804 | ppc_elf_vxworks_link_hash_table_create (bfd *abfd) | |
8805 | { | |
8806 | struct bfd_link_hash_table *ret; | |
8807 | ||
8808 | ret = ppc_elf_link_hash_table_create (abfd); | |
8809 | if (ret) | |
8810 | { | |
8811 | struct ppc_elf_link_hash_table *htab | |
8812 | = (struct ppc_elf_link_hash_table *)ret; | |
8813 | htab->is_vxworks = 1; | |
4a3dc543 | 8814 | htab->plt_type = PLT_VXWORKS; |
9d8504b1 PB |
8815 | htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE; |
8816 | htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE; | |
8817 | htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE; | |
8818 | } | |
8819 | return ret; | |
8820 | } | |
8821 | ||
8822 | /* Tweak magic VxWorks symbols as they are loaded. */ | |
8823 | static bfd_boolean | |
8824 | ppc_elf_vxworks_add_symbol_hook (bfd *abfd, | |
8825 | struct bfd_link_info *info, | |
8826 | Elf_Internal_Sym *sym, | |
8827 | const char **namep ATTRIBUTE_UNUSED, | |
8828 | flagword *flagsp ATTRIBUTE_UNUSED, | |
8829 | asection **secp, | |
8830 | bfd_vma *valp) | |
8831 | { | |
8832 | if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, | |
8833 | valp)) | |
8834 | return FALSE; | |
8835 | ||
8836 | return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp); | |
8837 | } | |
8838 | ||
9d8504b1 PB |
8839 | static void |
8840 | ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
8841 | { | |
8842 | ppc_elf_final_write_processing(abfd, linker); | |
8843 | elf_vxworks_final_write_processing(abfd, linker); | |
8844 | } | |
8845 | ||
8846 | /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so | |
8847 | define it. */ | |
8848 | #undef elf_backend_want_plt_sym | |
8849 | #define elf_backend_want_plt_sym 1 | |
8850 | #undef elf_backend_want_got_plt | |
8851 | #define elf_backend_want_got_plt 1 | |
8852 | #undef elf_backend_got_symbol_offset | |
8853 | #define elf_backend_got_symbol_offset 0 | |
8854 | #undef elf_backend_plt_not_loaded | |
8855 | #define elf_backend_plt_not_loaded 0 | |
8856 | #undef elf_backend_plt_readonly | |
8857 | #define elf_backend_plt_readonly 1 | |
8858 | #undef elf_backend_got_header_size | |
8859 | #define elf_backend_got_header_size 12 | |
8860 | ||
468392fb AM |
8861 | #undef bfd_elf32_get_synthetic_symtab |
8862 | ||
9d8504b1 PB |
8863 | #undef bfd_elf32_bfd_link_hash_table_create |
8864 | #define bfd_elf32_bfd_link_hash_table_create \ | |
8865 | ppc_elf_vxworks_link_hash_table_create | |
9d8504b1 PB |
8866 | #undef elf_backend_add_symbol_hook |
8867 | #define elf_backend_add_symbol_hook \ | |
8868 | ppc_elf_vxworks_add_symbol_hook | |
8869 | #undef elf_backend_link_output_symbol_hook | |
8870 | #define elf_backend_link_output_symbol_hook \ | |
9c72ff84 | 8871 | elf_vxworks_link_output_symbol_hook |
9d8504b1 PB |
8872 | #undef elf_backend_final_write_processing |
8873 | #define elf_backend_final_write_processing \ | |
8874 | ppc_elf_vxworks_final_write_processing | |
d5e3d971 PB |
8875 | #undef elf_backend_get_sec_type_attr |
8876 | #define elf_backend_get_sec_type_attr \ | |
8877 | ppc_elf_vxworks_get_sec_type_attr | |
9d8504b1 PB |
8878 | #undef elf_backend_emit_relocs |
8879 | #define elf_backend_emit_relocs \ | |
8880 | elf_vxworks_emit_relocs | |
8881 | ||
8882 | #undef elf32_bed | |
8883 | #define elf32_bed ppc_elf_vxworks_bed | |
e054468f | 8884 | #undef elf_backend_post_process_headers |
9d8504b1 PB |
8885 | |
8886 | #include "elf32-target.h" |