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, |
25f53a85 AM |
3 | 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
4 | Free Software Foundation, Inc. | |
252b5132 RH |
5 | Written by Ian Lance Taylor, Cygnus Support. |
6 | ||
ae9a127f | 7 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 8 | |
ae9a127f NC |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 11 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 12 | (at your option) any later version. |
252b5132 | 13 | |
ae9a127f NC |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
252b5132 | 18 | |
ae9a127f | 19 | You should have received a copy of the GNU General Public License |
fc0bffd6 | 20 | along with this program; if not, write to the |
3e110533 | 21 | Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
53e09e0a | 22 | Boston, MA 02110-1301, USA. */ |
252b5132 | 23 | |
cd123cb7 | 24 | |
252b5132 RH |
25 | /* This file is based on a preliminary PowerPC ELF ABI. The |
26 | information may not match the final PowerPC ELF ABI. It includes | |
27 | suggestions from the in-progress Embedded PowerPC ABI, and that | |
28 | information may also not match. */ | |
29 | ||
3db64b00 | 30 | #include "sysdep.h" |
183e98be | 31 | #include <stdarg.h> |
252b5132 | 32 | #include "bfd.h" |
252b5132 RH |
33 | #include "bfdlink.h" |
34 | #include "libbfd.h" | |
35 | #include "elf-bfd.h" | |
36 | #include "elf/ppc.h" | |
7619e7c7 | 37 | #include "elf32-ppc.h" |
9d8504b1 | 38 | #include "elf-vxworks.h" |
6177242a | 39 | #include "dwarf2.h" |
252b5132 | 40 | |
f0fe0e16 | 41 | /* RELA relocations are used here. */ |
252b5132 | 42 | |
252b5132 | 43 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
55fd94b0 | 44 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
7619e7c7 | 45 | static bfd_reloc_status_type ppc_elf_unhandled_reloc |
55fd94b0 | 46 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
252b5132 | 47 | |
70bccea4 AM |
48 | /* Branch prediction bit for branch taken relocs. */ |
49 | #define BRANCH_PREDICT_BIT 0x200000 | |
50 | /* Mask to set RA in memory instructions. */ | |
51 | #define RA_REGISTER_MASK 0x001f0000 | |
52 | /* Value to shift register by to insert RA. */ | |
53 | #define RA_REGISTER_SHIFT 16 | |
252b5132 RH |
54 | |
55 | /* The name of the dynamic interpreter. This is put in the .interp | |
56 | section. */ | |
252b5132 RH |
57 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
58 | ||
d7128ce4 | 59 | /* For old-style PLT. */ |
252b5132 RH |
60 | /* The number of single-slot PLT entries (the rest use two slots). */ |
61 | #define PLT_NUM_SINGLE_ENTRIES 8192 | |
62 | ||
d7128ce4 | 63 | /* For new-style .glink and .plt. */ |
a6aa5195 | 64 | #define GLINK_PLTRESOLVE 16*4 |
d7128ce4 | 65 | #define GLINK_ENTRY_SIZE 4*4 |
a7f2871e | 66 | #define TLS_GET_ADDR_GLINK_SIZE 12*4 |
d7128ce4 | 67 | |
9d8504b1 PB |
68 | /* VxWorks uses its own plt layout, filled in by the static linker. */ |
69 | ||
70 | /* The standard VxWorks PLT entry. */ | |
71 | #define VXWORKS_PLT_ENTRY_SIZE 32 | |
72 | static const bfd_vma ppc_elf_vxworks_plt_entry | |
73 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
74 | { | |
75 | 0x3d800000, /* lis r12,0 */ | |
76 | 0x818c0000, /* lwz r12,0(r12) */ | |
77 | 0x7d8903a6, /* mtctr r12 */ | |
78 | 0x4e800420, /* bctr */ | |
79 | 0x39600000, /* li r11,0 */ | |
80 | 0x48000000, /* b 14 <.PLT0resolve+0x4> */ | |
81 | 0x60000000, /* nop */ | |
82 | 0x60000000, /* nop */ | |
83 | }; | |
84 | static const bfd_vma ppc_elf_vxworks_pic_plt_entry | |
85 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
86 | { | |
87 | 0x3d9e0000, /* addis r12,r30,0 */ | |
88 | 0x818c0000, /* lwz r12,0(r12) */ | |
89 | 0x7d8903a6, /* mtctr r12 */ | |
90 | 0x4e800420, /* bctr */ | |
91 | 0x39600000, /* li r11,0 */ | |
92 | 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */ | |
93 | 0x60000000, /* nop */ | |
94 | 0x60000000, /* nop */ | |
95 | }; | |
96 | ||
97 | /* The initial VxWorks PLT entry. */ | |
98 | #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32 | |
99 | static const bfd_vma ppc_elf_vxworks_plt0_entry | |
100 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
101 | { | |
102 | 0x3d800000, /* lis r12,0 */ | |
103 | 0x398c0000, /* addi r12,r12,0 */ | |
104 | 0x800c0008, /* lwz r0,8(r12) */ | |
105 | 0x7c0903a6, /* mtctr r0 */ | |
106 | 0x818c0004, /* lwz r12,4(r12) */ | |
107 | 0x4e800420, /* bctr */ | |
108 | 0x60000000, /* nop */ | |
109 | 0x60000000, /* nop */ | |
110 | }; | |
111 | static const bfd_vma ppc_elf_vxworks_pic_plt0_entry | |
112 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
113 | { | |
114 | 0x819e0008, /* lwz r12,8(r30) */ | |
115 | 0x7d8903a6, /* mtctr r12 */ | |
116 | 0x819e0004, /* lwz r12,4(r30) */ | |
117 | 0x4e800420, /* bctr */ | |
118 | 0x60000000, /* nop */ | |
119 | 0x60000000, /* nop */ | |
120 | 0x60000000, /* nop */ | |
121 | 0x60000000, /* nop */ | |
122 | }; | |
123 | ||
124 | /* For executables, we have some additional relocations in | |
125 | .rela.plt.unloaded, for the kernel loader. */ | |
126 | ||
127 | /* The number of non-JMP_SLOT relocations per PLT0 slot. */ | |
128 | #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3 | |
129 | /* The number of relocations in the PLTResolve slot. */ | |
130 | #define VXWORKS_PLTRESOLVE_RELOCS 2 | |
131 | /* The number of relocations in the PLTResolve slot when when creating | |
132 | a shared library. */ | |
133 | #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0 | |
134 | ||
d7128ce4 | 135 | /* Some instructions. */ |
d7128ce4 | 136 | #define ADDIS_11_11 0x3d6b0000 |
a6aa5195 AM |
137 | #define ADDIS_11_30 0x3d7e0000 |
138 | #define ADDIS_12_12 0x3d8c0000 | |
d7128ce4 | 139 | #define ADDI_11_11 0x396b0000 |
d7128ce4 | 140 | #define ADD_0_11_11 0x7c0b5a14 |
a7f2871e | 141 | #define ADD_3_12_2 0x7c6c1214 |
d7128ce4 | 142 | #define ADD_11_0_11 0x7d605a14 |
a6aa5195 AM |
143 | #define B 0x48000000 |
144 | #define BCL_20_31 0x429f0005 | |
d7128ce4 | 145 | #define BCTR 0x4e800420 |
a7f2871e AM |
146 | #define BEQLR 0x4d820020 |
147 | #define CMPWI_11_0 0x2c0b0000 | |
7e8aeb9a AM |
148 | #define LIS_11 0x3d600000 |
149 | #define LIS_12 0x3d800000 | |
a6aa5195 AM |
150 | #define LWZU_0_12 0x840c0000 |
151 | #define LWZ_0_12 0x800c0000 | |
a7f2871e | 152 | #define LWZ_11_3 0x81630000 |
a6aa5195 AM |
153 | #define LWZ_11_11 0x816b0000 |
154 | #define LWZ_11_30 0x817e0000 | |
a7f2871e | 155 | #define LWZ_12_3 0x81830000 |
a6aa5195 | 156 | #define LWZ_12_12 0x818c0000 |
a7f2871e AM |
157 | #define MR_0_3 0x7c601b78 |
158 | #define MR_3_0 0x7c030378 | |
a6aa5195 AM |
159 | #define MFLR_0 0x7c0802a6 |
160 | #define MFLR_12 0x7d8802a6 | |
161 | #define MTCTR_0 0x7c0903a6 | |
162 | #define MTCTR_11 0x7d6903a6 | |
163 | #define MTLR_0 0x7c0803a6 | |
164 | #define NOP 0x60000000 | |
165 | #define SUB_11_11_12 0x7d6c5850 | |
7619e7c7 AM |
166 | |
167 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
168 | #define TP_OFFSET 0x7000 | |
169 | #define DTP_OFFSET 0x8000 | |
e87d4038 AM |
170 | |
171 | /* The value of a defined global symbol. */ | |
172 | #define SYM_VAL(SYM) \ | |
173 | ((SYM)->root.u.def.section->output_section->vma \ | |
174 | + (SYM)->root.u.def.section->output_offset \ | |
175 | + (SYM)->root.u.def.value) | |
7fce784e | 176 | \f |
e47cd125 | 177 | static reloc_howto_type *ppc_elf_howto_table[R_PPC_max]; |
252b5132 | 178 | |
8da6118f | 179 | static reloc_howto_type ppc_elf_howto_raw[] = { |
252b5132 RH |
180 | /* This reloc does nothing. */ |
181 | HOWTO (R_PPC_NONE, /* type */ | |
182 | 0, /* rightshift */ | |
183 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
184 | 32, /* bitsize */ | |
b34976b6 | 185 | FALSE, /* pc_relative */ |
252b5132 RH |
186 | 0, /* bitpos */ |
187 | complain_overflow_bitfield, /* complain_on_overflow */ | |
188 | bfd_elf_generic_reloc, /* special_function */ | |
189 | "R_PPC_NONE", /* name */ | |
b34976b6 | 190 | FALSE, /* partial_inplace */ |
252b5132 RH |
191 | 0, /* src_mask */ |
192 | 0, /* dst_mask */ | |
b34976b6 | 193 | FALSE), /* pcrel_offset */ |
252b5132 RH |
194 | |
195 | /* A standard 32 bit relocation. */ | |
196 | HOWTO (R_PPC_ADDR32, /* type */ | |
197 | 0, /* rightshift */ | |
198 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
199 | 32, /* bitsize */ | |
b34976b6 | 200 | FALSE, /* pc_relative */ |
252b5132 RH |
201 | 0, /* bitpos */ |
202 | complain_overflow_bitfield, /* complain_on_overflow */ | |
203 | bfd_elf_generic_reloc, /* special_function */ | |
204 | "R_PPC_ADDR32", /* name */ | |
b34976b6 | 205 | FALSE, /* partial_inplace */ |
252b5132 RH |
206 | 0, /* src_mask */ |
207 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 208 | FALSE), /* pcrel_offset */ |
252b5132 RH |
209 | |
210 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
211 | FIXME: we don't check that, we just clear them. */ | |
212 | HOWTO (R_PPC_ADDR24, /* type */ | |
213 | 0, /* rightshift */ | |
214 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
215 | 26, /* bitsize */ | |
b34976b6 | 216 | FALSE, /* pc_relative */ |
252b5132 RH |
217 | 0, /* bitpos */ |
218 | complain_overflow_bitfield, /* complain_on_overflow */ | |
219 | bfd_elf_generic_reloc, /* special_function */ | |
220 | "R_PPC_ADDR24", /* name */ | |
b34976b6 | 221 | FALSE, /* partial_inplace */ |
252b5132 RH |
222 | 0, /* src_mask */ |
223 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 224 | FALSE), /* pcrel_offset */ |
252b5132 RH |
225 | |
226 | /* A standard 16 bit relocation. */ | |
227 | HOWTO (R_PPC_ADDR16, /* type */ | |
228 | 0, /* rightshift */ | |
229 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
230 | 16, /* bitsize */ | |
b34976b6 | 231 | FALSE, /* pc_relative */ |
252b5132 RH |
232 | 0, /* bitpos */ |
233 | complain_overflow_bitfield, /* complain_on_overflow */ | |
234 | bfd_elf_generic_reloc, /* special_function */ | |
235 | "R_PPC_ADDR16", /* name */ | |
b34976b6 | 236 | FALSE, /* partial_inplace */ |
252b5132 RH |
237 | 0, /* src_mask */ |
238 | 0xffff, /* dst_mask */ | |
b34976b6 | 239 | FALSE), /* pcrel_offset */ |
252b5132 RH |
240 | |
241 | /* A 16 bit relocation without overflow. */ | |
242 | HOWTO (R_PPC_ADDR16_LO, /* type */ | |
243 | 0, /* rightshift */ | |
244 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
245 | 16, /* bitsize */ | |
b34976b6 | 246 | FALSE, /* pc_relative */ |
252b5132 RH |
247 | 0, /* bitpos */ |
248 | complain_overflow_dont,/* complain_on_overflow */ | |
249 | bfd_elf_generic_reloc, /* special_function */ | |
250 | "R_PPC_ADDR16_LO", /* name */ | |
b34976b6 | 251 | FALSE, /* partial_inplace */ |
252b5132 RH |
252 | 0, /* src_mask */ |
253 | 0xffff, /* dst_mask */ | |
b34976b6 | 254 | FALSE), /* pcrel_offset */ |
252b5132 RH |
255 | |
256 | /* The high order 16 bits of an address. */ | |
257 | HOWTO (R_PPC_ADDR16_HI, /* type */ | |
258 | 16, /* rightshift */ | |
259 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
260 | 16, /* bitsize */ | |
b34976b6 | 261 | FALSE, /* pc_relative */ |
252b5132 RH |
262 | 0, /* bitpos */ |
263 | complain_overflow_dont, /* complain_on_overflow */ | |
264 | bfd_elf_generic_reloc, /* special_function */ | |
265 | "R_PPC_ADDR16_HI", /* name */ | |
b34976b6 | 266 | FALSE, /* partial_inplace */ |
252b5132 RH |
267 | 0, /* src_mask */ |
268 | 0xffff, /* dst_mask */ | |
b34976b6 | 269 | FALSE), /* pcrel_offset */ |
252b5132 RH |
270 | |
271 | /* The high order 16 bits of an address, plus 1 if the contents of | |
8da6118f | 272 | the low 16 bits, treated as a signed number, is negative. */ |
252b5132 RH |
273 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
274 | 16, /* rightshift */ | |
275 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
276 | 16, /* bitsize */ | |
b34976b6 | 277 | FALSE, /* pc_relative */ |
252b5132 RH |
278 | 0, /* bitpos */ |
279 | complain_overflow_dont, /* complain_on_overflow */ | |
280 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
281 | "R_PPC_ADDR16_HA", /* name */ | |
b34976b6 | 282 | FALSE, /* partial_inplace */ |
252b5132 RH |
283 | 0, /* src_mask */ |
284 | 0xffff, /* dst_mask */ | |
b34976b6 | 285 | FALSE), /* pcrel_offset */ |
252b5132 RH |
286 | |
287 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
288 | FIXME: we don't check that, we just clear them. */ | |
289 | HOWTO (R_PPC_ADDR14, /* type */ | |
290 | 0, /* rightshift */ | |
291 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
292 | 16, /* bitsize */ | |
b34976b6 | 293 | FALSE, /* pc_relative */ |
252b5132 RH |
294 | 0, /* bitpos */ |
295 | complain_overflow_bitfield, /* complain_on_overflow */ | |
296 | bfd_elf_generic_reloc, /* special_function */ | |
297 | "R_PPC_ADDR14", /* name */ | |
b34976b6 | 298 | FALSE, /* partial_inplace */ |
252b5132 RH |
299 | 0, /* src_mask */ |
300 | 0xfffc, /* dst_mask */ | |
b34976b6 | 301 | FALSE), /* pcrel_offset */ |
252b5132 RH |
302 | |
303 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
304 | indicate that the branch is expected to be taken. The lower two | |
8da6118f | 305 | bits must be zero. */ |
252b5132 RH |
306 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
307 | 0, /* rightshift */ | |
308 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
309 | 16, /* bitsize */ | |
b34976b6 | 310 | FALSE, /* pc_relative */ |
252b5132 RH |
311 | 0, /* bitpos */ |
312 | complain_overflow_bitfield, /* complain_on_overflow */ | |
313 | bfd_elf_generic_reloc, /* special_function */ | |
314 | "R_PPC_ADDR14_BRTAKEN",/* name */ | |
b34976b6 | 315 | FALSE, /* partial_inplace */ |
252b5132 RH |
316 | 0, /* src_mask */ |
317 | 0xfffc, /* dst_mask */ | |
b34976b6 | 318 | FALSE), /* pcrel_offset */ |
252b5132 RH |
319 | |
320 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
321 | indicate that the branch is not expected to be taken. The lower | |
322 | two bits must be zero. */ | |
323 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
324 | 0, /* rightshift */ | |
325 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
326 | 16, /* bitsize */ | |
b34976b6 | 327 | FALSE, /* pc_relative */ |
252b5132 RH |
328 | 0, /* bitpos */ |
329 | complain_overflow_bitfield, /* complain_on_overflow */ | |
330 | bfd_elf_generic_reloc, /* special_function */ | |
331 | "R_PPC_ADDR14_BRNTAKEN",/* name */ | |
b34976b6 | 332 | FALSE, /* partial_inplace */ |
252b5132 RH |
333 | 0, /* src_mask */ |
334 | 0xfffc, /* dst_mask */ | |
b34976b6 | 335 | FALSE), /* pcrel_offset */ |
252b5132 | 336 | |
8da6118f | 337 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
338 | HOWTO (R_PPC_REL24, /* type */ |
339 | 0, /* rightshift */ | |
340 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
341 | 26, /* bitsize */ | |
b34976b6 | 342 | TRUE, /* pc_relative */ |
252b5132 RH |
343 | 0, /* bitpos */ |
344 | complain_overflow_signed, /* complain_on_overflow */ | |
345 | bfd_elf_generic_reloc, /* special_function */ | |
346 | "R_PPC_REL24", /* name */ | |
b34976b6 | 347 | FALSE, /* partial_inplace */ |
252b5132 RH |
348 | 0, /* src_mask */ |
349 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 350 | TRUE), /* pcrel_offset */ |
252b5132 | 351 | |
8da6118f | 352 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
353 | HOWTO (R_PPC_REL14, /* type */ |
354 | 0, /* rightshift */ | |
355 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
356 | 16, /* bitsize */ | |
b34976b6 | 357 | TRUE, /* pc_relative */ |
252b5132 RH |
358 | 0, /* bitpos */ |
359 | complain_overflow_signed, /* complain_on_overflow */ | |
360 | bfd_elf_generic_reloc, /* special_function */ | |
361 | "R_PPC_REL14", /* name */ | |
b34976b6 | 362 | FALSE, /* partial_inplace */ |
252b5132 RH |
363 | 0, /* src_mask */ |
364 | 0xfffc, /* dst_mask */ | |
b34976b6 | 365 | TRUE), /* pcrel_offset */ |
252b5132 | 366 | |
8da6118f | 367 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
368 | the branch is expected to be taken. The lower two bits must be |
369 | zero. */ | |
370 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ | |
371 | 0, /* rightshift */ | |
372 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
373 | 16, /* bitsize */ | |
b34976b6 | 374 | TRUE, /* pc_relative */ |
252b5132 RH |
375 | 0, /* bitpos */ |
376 | complain_overflow_signed, /* complain_on_overflow */ | |
377 | bfd_elf_generic_reloc, /* special_function */ | |
378 | "R_PPC_REL14_BRTAKEN", /* name */ | |
b34976b6 | 379 | FALSE, /* partial_inplace */ |
252b5132 RH |
380 | 0, /* src_mask */ |
381 | 0xfffc, /* dst_mask */ | |
b34976b6 | 382 | TRUE), /* pcrel_offset */ |
252b5132 | 383 | |
8da6118f | 384 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
385 | the branch is not expected to be taken. The lower two bits must |
386 | be zero. */ | |
387 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ | |
388 | 0, /* rightshift */ | |
389 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
390 | 16, /* bitsize */ | |
b34976b6 | 391 | TRUE, /* pc_relative */ |
252b5132 RH |
392 | 0, /* bitpos */ |
393 | complain_overflow_signed, /* complain_on_overflow */ | |
394 | bfd_elf_generic_reloc, /* special_function */ | |
395 | "R_PPC_REL14_BRNTAKEN",/* name */ | |
b34976b6 | 396 | FALSE, /* partial_inplace */ |
252b5132 RH |
397 | 0, /* src_mask */ |
398 | 0xfffc, /* dst_mask */ | |
b34976b6 | 399 | TRUE), /* pcrel_offset */ |
252b5132 RH |
400 | |
401 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
402 | symbol. */ | |
403 | HOWTO (R_PPC_GOT16, /* type */ | |
404 | 0, /* rightshift */ | |
405 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
406 | 16, /* bitsize */ | |
b34976b6 | 407 | FALSE, /* pc_relative */ |
252b5132 RH |
408 | 0, /* bitpos */ |
409 | complain_overflow_signed, /* complain_on_overflow */ | |
410 | bfd_elf_generic_reloc, /* special_function */ | |
411 | "R_PPC_GOT16", /* name */ | |
b34976b6 | 412 | FALSE, /* partial_inplace */ |
252b5132 RH |
413 | 0, /* src_mask */ |
414 | 0xffff, /* dst_mask */ | |
b34976b6 | 415 | FALSE), /* pcrel_offset */ |
252b5132 RH |
416 | |
417 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
418 | the symbol. */ | |
419 | HOWTO (R_PPC_GOT16_LO, /* type */ | |
420 | 0, /* rightshift */ | |
421 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
422 | 16, /* bitsize */ | |
b34976b6 | 423 | FALSE, /* pc_relative */ |
252b5132 RH |
424 | 0, /* bitpos */ |
425 | complain_overflow_dont, /* complain_on_overflow */ | |
426 | bfd_elf_generic_reloc, /* special_function */ | |
427 | "R_PPC_GOT16_LO", /* name */ | |
b34976b6 | 428 | FALSE, /* partial_inplace */ |
252b5132 RH |
429 | 0, /* src_mask */ |
430 | 0xffff, /* dst_mask */ | |
b34976b6 | 431 | FALSE), /* pcrel_offset */ |
252b5132 RH |
432 | |
433 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
434 | the symbol. */ | |
435 | HOWTO (R_PPC_GOT16_HI, /* type */ | |
436 | 16, /* rightshift */ | |
437 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
438 | 16, /* bitsize */ | |
b34976b6 | 439 | FALSE, /* pc_relative */ |
252b5132 RH |
440 | 0, /* bitpos */ |
441 | complain_overflow_bitfield, /* complain_on_overflow */ | |
442 | bfd_elf_generic_reloc, /* special_function */ | |
443 | "R_PPC_GOT16_HI", /* name */ | |
b34976b6 | 444 | FALSE, /* partial_inplace */ |
252b5132 RH |
445 | 0, /* src_mask */ |
446 | 0xffff, /* dst_mask */ | |
b34976b6 | 447 | FALSE), /* pcrel_offset */ |
252b5132 RH |
448 | |
449 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
450 | the symbol. */ | |
451 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
452 | 16, /* rightshift */ | |
453 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
454 | 16, /* bitsize */ | |
b34976b6 | 455 | FALSE, /* pc_relative */ |
252b5132 RH |
456 | 0, /* bitpos */ |
457 | complain_overflow_bitfield, /* complain_on_overflow */ | |
458 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
459 | "R_PPC_GOT16_HA", /* name */ | |
b34976b6 | 460 | FALSE, /* partial_inplace */ |
252b5132 RH |
461 | 0, /* src_mask */ |
462 | 0xffff, /* dst_mask */ | |
b34976b6 | 463 | FALSE), /* pcrel_offset */ |
252b5132 RH |
464 | |
465 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
466 | entry for the symbol. */ | |
467 | HOWTO (R_PPC_PLTREL24, /* type */ | |
468 | 0, /* rightshift */ | |
469 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
470 | 26, /* bitsize */ | |
b34976b6 | 471 | TRUE, /* pc_relative */ |
252b5132 RH |
472 | 0, /* bitpos */ |
473 | complain_overflow_signed, /* complain_on_overflow */ | |
474 | bfd_elf_generic_reloc, /* special_function */ | |
475 | "R_PPC_PLTREL24", /* name */ | |
b34976b6 | 476 | FALSE, /* partial_inplace */ |
252b5132 RH |
477 | 0, /* src_mask */ |
478 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 479 | TRUE), /* pcrel_offset */ |
252b5132 RH |
480 | |
481 | /* This is used only by the dynamic linker. The symbol should exist | |
482 | both in the object being run and in some shared library. The | |
483 | dynamic linker copies the data addressed by the symbol from the | |
484 | shared library into the object, because the object being | |
485 | run has to have the data at some particular address. */ | |
486 | HOWTO (R_PPC_COPY, /* type */ | |
487 | 0, /* rightshift */ | |
488 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
489 | 32, /* bitsize */ | |
b34976b6 | 490 | FALSE, /* pc_relative */ |
252b5132 RH |
491 | 0, /* bitpos */ |
492 | complain_overflow_bitfield, /* complain_on_overflow */ | |
493 | bfd_elf_generic_reloc, /* special_function */ | |
494 | "R_PPC_COPY", /* name */ | |
b34976b6 | 495 | FALSE, /* partial_inplace */ |
252b5132 RH |
496 | 0, /* src_mask */ |
497 | 0, /* dst_mask */ | |
b34976b6 | 498 | FALSE), /* pcrel_offset */ |
252b5132 RH |
499 | |
500 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
501 | entries. */ | |
502 | HOWTO (R_PPC_GLOB_DAT, /* type */ | |
503 | 0, /* rightshift */ | |
504 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
505 | 32, /* bitsize */ | |
b34976b6 | 506 | FALSE, /* pc_relative */ |
252b5132 RH |
507 | 0, /* bitpos */ |
508 | complain_overflow_bitfield, /* complain_on_overflow */ | |
509 | bfd_elf_generic_reloc, /* special_function */ | |
510 | "R_PPC_GLOB_DAT", /* name */ | |
b34976b6 | 511 | FALSE, /* partial_inplace */ |
252b5132 RH |
512 | 0, /* src_mask */ |
513 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 514 | FALSE), /* pcrel_offset */ |
252b5132 RH |
515 | |
516 | /* Marks a procedure linkage table entry for a symbol. */ | |
517 | HOWTO (R_PPC_JMP_SLOT, /* type */ | |
518 | 0, /* rightshift */ | |
519 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
520 | 32, /* bitsize */ | |
b34976b6 | 521 | FALSE, /* pc_relative */ |
252b5132 RH |
522 | 0, /* bitpos */ |
523 | complain_overflow_bitfield, /* complain_on_overflow */ | |
524 | bfd_elf_generic_reloc, /* special_function */ | |
525 | "R_PPC_JMP_SLOT", /* name */ | |
b34976b6 | 526 | FALSE, /* partial_inplace */ |
252b5132 RH |
527 | 0, /* src_mask */ |
528 | 0, /* dst_mask */ | |
b34976b6 | 529 | FALSE), /* pcrel_offset */ |
252b5132 RH |
530 | |
531 | /* Used only by the dynamic linker. When the object is run, this | |
532 | longword is set to the load address of the object, plus the | |
533 | addend. */ | |
534 | HOWTO (R_PPC_RELATIVE, /* type */ | |
535 | 0, /* rightshift */ | |
536 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
537 | 32, /* bitsize */ | |
b34976b6 | 538 | FALSE, /* pc_relative */ |
252b5132 RH |
539 | 0, /* bitpos */ |
540 | complain_overflow_bitfield, /* complain_on_overflow */ | |
541 | bfd_elf_generic_reloc, /* special_function */ | |
542 | "R_PPC_RELATIVE", /* name */ | |
b34976b6 | 543 | FALSE, /* partial_inplace */ |
252b5132 RH |
544 | 0, /* src_mask */ |
545 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 546 | FALSE), /* pcrel_offset */ |
252b5132 RH |
547 | |
548 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
549 | object rather than the final value. Normally used for | |
550 | _GLOBAL_OFFSET_TABLE_. */ | |
551 | HOWTO (R_PPC_LOCAL24PC, /* type */ | |
552 | 0, /* rightshift */ | |
553 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
554 | 26, /* bitsize */ | |
b34976b6 | 555 | TRUE, /* pc_relative */ |
252b5132 RH |
556 | 0, /* bitpos */ |
557 | complain_overflow_signed, /* complain_on_overflow */ | |
558 | bfd_elf_generic_reloc, /* special_function */ | |
559 | "R_PPC_LOCAL24PC", /* name */ | |
b34976b6 | 560 | FALSE, /* partial_inplace */ |
252b5132 RH |
561 | 0, /* src_mask */ |
562 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 563 | TRUE), /* pcrel_offset */ |
252b5132 RH |
564 | |
565 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
566 | HOWTO (R_PPC_UADDR32, /* type */ | |
567 | 0, /* rightshift */ | |
568 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
569 | 32, /* bitsize */ | |
b34976b6 | 570 | FALSE, /* pc_relative */ |
252b5132 RH |
571 | 0, /* bitpos */ |
572 | complain_overflow_bitfield, /* complain_on_overflow */ | |
573 | bfd_elf_generic_reloc, /* special_function */ | |
574 | "R_PPC_UADDR32", /* name */ | |
b34976b6 | 575 | FALSE, /* partial_inplace */ |
252b5132 RH |
576 | 0, /* src_mask */ |
577 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 578 | FALSE), /* pcrel_offset */ |
252b5132 RH |
579 | |
580 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
581 | HOWTO (R_PPC_UADDR16, /* type */ | |
582 | 0, /* rightshift */ | |
583 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
584 | 16, /* bitsize */ | |
b34976b6 | 585 | FALSE, /* pc_relative */ |
252b5132 RH |
586 | 0, /* bitpos */ |
587 | complain_overflow_bitfield, /* complain_on_overflow */ | |
588 | bfd_elf_generic_reloc, /* special_function */ | |
589 | "R_PPC_UADDR16", /* name */ | |
b34976b6 | 590 | FALSE, /* partial_inplace */ |
252b5132 RH |
591 | 0, /* src_mask */ |
592 | 0xffff, /* dst_mask */ | |
b34976b6 | 593 | FALSE), /* pcrel_offset */ |
252b5132 RH |
594 | |
595 | /* 32-bit PC relative */ | |
596 | HOWTO (R_PPC_REL32, /* type */ | |
597 | 0, /* rightshift */ | |
598 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
599 | 32, /* bitsize */ | |
b34976b6 | 600 | TRUE, /* pc_relative */ |
252b5132 RH |
601 | 0, /* bitpos */ |
602 | complain_overflow_bitfield, /* complain_on_overflow */ | |
603 | bfd_elf_generic_reloc, /* special_function */ | |
604 | "R_PPC_REL32", /* name */ | |
b34976b6 | 605 | FALSE, /* partial_inplace */ |
252b5132 RH |
606 | 0, /* src_mask */ |
607 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 608 | TRUE), /* pcrel_offset */ |
252b5132 RH |
609 | |
610 | /* 32-bit relocation to the symbol's procedure linkage table. | |
c3668558 | 611 | FIXME: not supported. */ |
252b5132 RH |
612 | HOWTO (R_PPC_PLT32, /* type */ |
613 | 0, /* rightshift */ | |
614 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
615 | 32, /* bitsize */ | |
b34976b6 | 616 | FALSE, /* pc_relative */ |
252b5132 RH |
617 | 0, /* bitpos */ |
618 | complain_overflow_bitfield, /* complain_on_overflow */ | |
619 | bfd_elf_generic_reloc, /* special_function */ | |
620 | "R_PPC_PLT32", /* name */ | |
b34976b6 | 621 | FALSE, /* partial_inplace */ |
252b5132 RH |
622 | 0, /* src_mask */ |
623 | 0, /* dst_mask */ | |
b34976b6 | 624 | FALSE), /* pcrel_offset */ |
252b5132 RH |
625 | |
626 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
c3668558 | 627 | FIXME: not supported. */ |
252b5132 RH |
628 | HOWTO (R_PPC_PLTREL32, /* type */ |
629 | 0, /* rightshift */ | |
630 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
631 | 32, /* bitsize */ | |
b34976b6 | 632 | TRUE, /* pc_relative */ |
252b5132 RH |
633 | 0, /* bitpos */ |
634 | complain_overflow_bitfield, /* complain_on_overflow */ | |
635 | bfd_elf_generic_reloc, /* special_function */ | |
636 | "R_PPC_PLTREL32", /* name */ | |
b34976b6 | 637 | FALSE, /* partial_inplace */ |
252b5132 RH |
638 | 0, /* src_mask */ |
639 | 0, /* dst_mask */ | |
b34976b6 | 640 | TRUE), /* pcrel_offset */ |
252b5132 RH |
641 | |
642 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
643 | the symbol. */ | |
644 | HOWTO (R_PPC_PLT16_LO, /* type */ | |
645 | 0, /* rightshift */ | |
646 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
647 | 16, /* bitsize */ | |
b34976b6 | 648 | FALSE, /* pc_relative */ |
252b5132 RH |
649 | 0, /* bitpos */ |
650 | complain_overflow_dont, /* complain_on_overflow */ | |
651 | bfd_elf_generic_reloc, /* special_function */ | |
652 | "R_PPC_PLT16_LO", /* name */ | |
b34976b6 | 653 | FALSE, /* partial_inplace */ |
252b5132 RH |
654 | 0, /* src_mask */ |
655 | 0xffff, /* dst_mask */ | |
b34976b6 | 656 | FALSE), /* pcrel_offset */ |
252b5132 RH |
657 | |
658 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
659 | the symbol. */ | |
660 | HOWTO (R_PPC_PLT16_HI, /* type */ | |
661 | 16, /* rightshift */ | |
662 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
663 | 16, /* bitsize */ | |
b34976b6 | 664 | FALSE, /* pc_relative */ |
252b5132 RH |
665 | 0, /* bitpos */ |
666 | complain_overflow_bitfield, /* complain_on_overflow */ | |
667 | bfd_elf_generic_reloc, /* special_function */ | |
668 | "R_PPC_PLT16_HI", /* name */ | |
b34976b6 | 669 | FALSE, /* partial_inplace */ |
252b5132 RH |
670 | 0, /* src_mask */ |
671 | 0xffff, /* dst_mask */ | |
b34976b6 | 672 | FALSE), /* pcrel_offset */ |
252b5132 RH |
673 | |
674 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
675 | the symbol. */ | |
676 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
677 | 16, /* rightshift */ | |
678 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
679 | 16, /* bitsize */ | |
b34976b6 | 680 | FALSE, /* pc_relative */ |
252b5132 RH |
681 | 0, /* bitpos */ |
682 | complain_overflow_bitfield, /* complain_on_overflow */ | |
683 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
684 | "R_PPC_PLT16_HA", /* name */ | |
b34976b6 | 685 | FALSE, /* partial_inplace */ |
252b5132 RH |
686 | 0, /* src_mask */ |
687 | 0xffff, /* dst_mask */ | |
b34976b6 | 688 | FALSE), /* pcrel_offset */ |
252b5132 RH |
689 | |
690 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with | |
691 | small data items. */ | |
692 | HOWTO (R_PPC_SDAREL16, /* type */ | |
693 | 0, /* rightshift */ | |
694 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
695 | 16, /* bitsize */ | |
b34976b6 | 696 | FALSE, /* pc_relative */ |
252b5132 RH |
697 | 0, /* bitpos */ |
698 | complain_overflow_signed, /* complain_on_overflow */ | |
699 | bfd_elf_generic_reloc, /* special_function */ | |
700 | "R_PPC_SDAREL16", /* name */ | |
b34976b6 | 701 | FALSE, /* partial_inplace */ |
252b5132 RH |
702 | 0, /* src_mask */ |
703 | 0xffff, /* dst_mask */ | |
b34976b6 | 704 | FALSE), /* pcrel_offset */ |
252b5132 | 705 | |
c061c2d8 | 706 | /* 16-bit section relative relocation. */ |
252b5132 RH |
707 | HOWTO (R_PPC_SECTOFF, /* type */ |
708 | 0, /* rightshift */ | |
c061c2d8 AM |
709 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
710 | 16, /* bitsize */ | |
b34976b6 | 711 | FALSE, /* pc_relative */ |
252b5132 RH |
712 | 0, /* bitpos */ |
713 | complain_overflow_bitfield, /* complain_on_overflow */ | |
714 | bfd_elf_generic_reloc, /* special_function */ | |
715 | "R_PPC_SECTOFF", /* name */ | |
b34976b6 | 716 | FALSE, /* partial_inplace */ |
252b5132 | 717 | 0, /* src_mask */ |
c061c2d8 | 718 | 0xffff, /* dst_mask */ |
b34976b6 | 719 | FALSE), /* pcrel_offset */ |
252b5132 | 720 | |
c3668558 | 721 | /* 16-bit lower half section relative relocation. */ |
252b5132 RH |
722 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
723 | 0, /* rightshift */ | |
724 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
725 | 16, /* bitsize */ | |
b34976b6 | 726 | FALSE, /* pc_relative */ |
252b5132 RH |
727 | 0, /* bitpos */ |
728 | complain_overflow_dont, /* complain_on_overflow */ | |
729 | bfd_elf_generic_reloc, /* special_function */ | |
730 | "R_PPC_SECTOFF_LO", /* name */ | |
b34976b6 | 731 | FALSE, /* partial_inplace */ |
252b5132 RH |
732 | 0, /* src_mask */ |
733 | 0xffff, /* dst_mask */ | |
b34976b6 | 734 | FALSE), /* pcrel_offset */ |
252b5132 | 735 | |
c3668558 | 736 | /* 16-bit upper half section relative relocation. */ |
252b5132 RH |
737 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
738 | 16, /* rightshift */ | |
739 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
740 | 16, /* bitsize */ | |
b34976b6 | 741 | FALSE, /* pc_relative */ |
252b5132 RH |
742 | 0, /* bitpos */ |
743 | complain_overflow_bitfield, /* complain_on_overflow */ | |
744 | bfd_elf_generic_reloc, /* special_function */ | |
745 | "R_PPC_SECTOFF_HI", /* name */ | |
b34976b6 | 746 | FALSE, /* partial_inplace */ |
252b5132 RH |
747 | 0, /* src_mask */ |
748 | 0xffff, /* dst_mask */ | |
b34976b6 | 749 | FALSE), /* pcrel_offset */ |
252b5132 | 750 | |
c3668558 | 751 | /* 16-bit upper half adjusted section relative relocation. */ |
252b5132 RH |
752 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
753 | 16, /* rightshift */ | |
754 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
755 | 16, /* bitsize */ | |
b34976b6 | 756 | FALSE, /* pc_relative */ |
252b5132 RH |
757 | 0, /* bitpos */ |
758 | complain_overflow_bitfield, /* complain_on_overflow */ | |
759 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
760 | "R_PPC_SECTOFF_HA", /* name */ | |
b34976b6 | 761 | FALSE, /* partial_inplace */ |
252b5132 RH |
762 | 0, /* src_mask */ |
763 | 0xffff, /* dst_mask */ | |
b34976b6 | 764 | FALSE), /* pcrel_offset */ |
252b5132 | 765 | |
727fc41e | 766 | /* Marker relocs for TLS. */ |
7619e7c7 | 767 | HOWTO (R_PPC_TLS, |
252b5132 RH |
768 | 0, /* rightshift */ |
769 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
770 | 32, /* bitsize */ | |
b34976b6 | 771 | FALSE, /* pc_relative */ |
252b5132 | 772 | 0, /* bitpos */ |
7619e7c7 | 773 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 | 774 | bfd_elf_generic_reloc, /* special_function */ |
7619e7c7 AM |
775 | "R_PPC_TLS", /* name */ |
776 | FALSE, /* partial_inplace */ | |
777 | 0, /* src_mask */ | |
778 | 0, /* dst_mask */ | |
779 | FALSE), /* pcrel_offset */ | |
780 | ||
727fc41e AM |
781 | HOWTO (R_PPC_TLSGD, |
782 | 0, /* rightshift */ | |
783 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
784 | 32, /* bitsize */ | |
785 | FALSE, /* pc_relative */ | |
786 | 0, /* bitpos */ | |
787 | complain_overflow_dont, /* complain_on_overflow */ | |
788 | bfd_elf_generic_reloc, /* special_function */ | |
789 | "R_PPC_TLSGD", /* name */ | |
790 | FALSE, /* partial_inplace */ | |
791 | 0, /* src_mask */ | |
792 | 0, /* dst_mask */ | |
793 | FALSE), /* pcrel_offset */ | |
794 | ||
795 | HOWTO (R_PPC_TLSLD, | |
796 | 0, /* rightshift */ | |
797 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
798 | 32, /* bitsize */ | |
799 | FALSE, /* pc_relative */ | |
800 | 0, /* bitpos */ | |
801 | complain_overflow_dont, /* complain_on_overflow */ | |
802 | bfd_elf_generic_reloc, /* special_function */ | |
803 | "R_PPC_TLSLD", /* name */ | |
804 | FALSE, /* partial_inplace */ | |
805 | 0, /* src_mask */ | |
806 | 0, /* dst_mask */ | |
807 | FALSE), /* pcrel_offset */ | |
808 | ||
7619e7c7 AM |
809 | /* Computes the load module index of the load module that contains the |
810 | definition of its TLS sym. */ | |
811 | HOWTO (R_PPC_DTPMOD32, | |
812 | 0, /* rightshift */ | |
813 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
814 | 32, /* bitsize */ | |
815 | FALSE, /* pc_relative */ | |
816 | 0, /* bitpos */ | |
817 | complain_overflow_dont, /* complain_on_overflow */ | |
818 | ppc_elf_unhandled_reloc, /* special_function */ | |
819 | "R_PPC_DTPMOD32", /* name */ | |
b34976b6 | 820 | FALSE, /* partial_inplace */ |
252b5132 RH |
821 | 0, /* src_mask */ |
822 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 823 | FALSE), /* pcrel_offset */ |
252b5132 | 824 | |
7619e7c7 AM |
825 | /* Computes a dtv-relative displacement, the difference between the value |
826 | of sym+add and the base address of the thread-local storage block that | |
827 | contains the definition of sym, minus 0x8000. */ | |
828 | HOWTO (R_PPC_DTPREL32, | |
829 | 0, /* rightshift */ | |
830 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
831 | 32, /* bitsize */ | |
832 | FALSE, /* pc_relative */ | |
833 | 0, /* bitpos */ | |
834 | complain_overflow_dont, /* complain_on_overflow */ | |
835 | ppc_elf_unhandled_reloc, /* special_function */ | |
836 | "R_PPC_DTPREL32", /* name */ | |
837 | FALSE, /* partial_inplace */ | |
838 | 0, /* src_mask */ | |
839 | 0xffffffff, /* dst_mask */ | |
840 | FALSE), /* pcrel_offset */ | |
841 | ||
842 | /* A 16 bit dtprel reloc. */ | |
843 | HOWTO (R_PPC_DTPREL16, | |
252b5132 RH |
844 | 0, /* rightshift */ |
845 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
846 | 16, /* bitsize */ | |
b34976b6 | 847 | FALSE, /* pc_relative */ |
252b5132 | 848 | 0, /* bitpos */ |
7619e7c7 AM |
849 | complain_overflow_signed, /* complain_on_overflow */ |
850 | ppc_elf_unhandled_reloc, /* special_function */ | |
851 | "R_PPC_DTPREL16", /* name */ | |
b34976b6 | 852 | FALSE, /* partial_inplace */ |
252b5132 RH |
853 | 0, /* src_mask */ |
854 | 0xffff, /* dst_mask */ | |
b34976b6 | 855 | FALSE), /* pcrel_offset */ |
252b5132 | 856 | |
7619e7c7 AM |
857 | /* Like DTPREL16, but no overflow. */ |
858 | HOWTO (R_PPC_DTPREL16_LO, | |
252b5132 RH |
859 | 0, /* rightshift */ |
860 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
861 | 16, /* bitsize */ | |
b34976b6 | 862 | FALSE, /* pc_relative */ |
252b5132 | 863 | 0, /* bitpos */ |
7619e7c7 AM |
864 | complain_overflow_dont, /* complain_on_overflow */ |
865 | ppc_elf_unhandled_reloc, /* special_function */ | |
866 | "R_PPC_DTPREL16_LO", /* name */ | |
b34976b6 | 867 | FALSE, /* partial_inplace */ |
252b5132 RH |
868 | 0, /* src_mask */ |
869 | 0xffff, /* dst_mask */ | |
b34976b6 | 870 | FALSE), /* pcrel_offset */ |
252b5132 | 871 | |
7619e7c7 AM |
872 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ |
873 | HOWTO (R_PPC_DTPREL16_HI, | |
252b5132 RH |
874 | 16, /* rightshift */ |
875 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
876 | 16, /* bitsize */ | |
b34976b6 | 877 | FALSE, /* pc_relative */ |
252b5132 RH |
878 | 0, /* bitpos */ |
879 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
880 | ppc_elf_unhandled_reloc, /* special_function */ |
881 | "R_PPC_DTPREL16_HI", /* name */ | |
b34976b6 | 882 | FALSE, /* partial_inplace */ |
252b5132 RH |
883 | 0, /* src_mask */ |
884 | 0xffff, /* dst_mask */ | |
b34976b6 | 885 | FALSE), /* pcrel_offset */ |
252b5132 | 886 | |
7619e7c7 AM |
887 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ |
888 | HOWTO (R_PPC_DTPREL16_HA, | |
252b5132 RH |
889 | 16, /* rightshift */ |
890 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
891 | 16, /* bitsize */ | |
b34976b6 | 892 | FALSE, /* pc_relative */ |
252b5132 RH |
893 | 0, /* bitpos */ |
894 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
895 | ppc_elf_unhandled_reloc, /* special_function */ |
896 | "R_PPC_DTPREL16_HA", /* name */ | |
b34976b6 | 897 | FALSE, /* partial_inplace */ |
252b5132 RH |
898 | 0, /* src_mask */ |
899 | 0xffff, /* dst_mask */ | |
b34976b6 | 900 | FALSE), /* pcrel_offset */ |
252b5132 | 901 | |
7619e7c7 AM |
902 | /* Computes a tp-relative displacement, the difference between the value of |
903 | sym+add and the value of the thread pointer (r13). */ | |
904 | HOWTO (R_PPC_TPREL32, | |
905 | 0, /* rightshift */ | |
906 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
907 | 32, /* bitsize */ | |
908 | FALSE, /* pc_relative */ | |
909 | 0, /* bitpos */ | |
910 | complain_overflow_dont, /* complain_on_overflow */ | |
911 | ppc_elf_unhandled_reloc, /* special_function */ | |
912 | "R_PPC_TPREL32", /* name */ | |
913 | FALSE, /* partial_inplace */ | |
914 | 0, /* src_mask */ | |
915 | 0xffffffff, /* dst_mask */ | |
916 | FALSE), /* pcrel_offset */ | |
917 | ||
918 | /* A 16 bit tprel reloc. */ | |
919 | HOWTO (R_PPC_TPREL16, | |
252b5132 RH |
920 | 0, /* rightshift */ |
921 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
922 | 16, /* bitsize */ | |
b34976b6 | 923 | FALSE, /* pc_relative */ |
252b5132 | 924 | 0, /* bitpos */ |
7619e7c7 AM |
925 | complain_overflow_signed, /* complain_on_overflow */ |
926 | ppc_elf_unhandled_reloc, /* special_function */ | |
927 | "R_PPC_TPREL16", /* name */ | |
b34976b6 | 928 | FALSE, /* partial_inplace */ |
252b5132 RH |
929 | 0, /* src_mask */ |
930 | 0xffff, /* dst_mask */ | |
b34976b6 | 931 | FALSE), /* pcrel_offset */ |
252b5132 | 932 | |
7619e7c7 AM |
933 | /* Like TPREL16, but no overflow. */ |
934 | HOWTO (R_PPC_TPREL16_LO, | |
252b5132 RH |
935 | 0, /* rightshift */ |
936 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
937 | 16, /* bitsize */ | |
b34976b6 | 938 | FALSE, /* pc_relative */ |
252b5132 | 939 | 0, /* bitpos */ |
7619e7c7 AM |
940 | complain_overflow_dont, /* complain_on_overflow */ |
941 | ppc_elf_unhandled_reloc, /* special_function */ | |
942 | "R_PPC_TPREL16_LO", /* name */ | |
b34976b6 | 943 | FALSE, /* partial_inplace */ |
252b5132 RH |
944 | 0, /* src_mask */ |
945 | 0xffff, /* dst_mask */ | |
b34976b6 | 946 | FALSE), /* pcrel_offset */ |
252b5132 | 947 | |
7619e7c7 AM |
948 | /* Like TPREL16_LO, but next higher group of 16 bits. */ |
949 | HOWTO (R_PPC_TPREL16_HI, | |
950 | 16, /* rightshift */ | |
951 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
952 | 16, /* bitsize */ | |
953 | FALSE, /* pc_relative */ | |
954 | 0, /* bitpos */ | |
955 | complain_overflow_dont, /* complain_on_overflow */ | |
956 | ppc_elf_unhandled_reloc, /* special_function */ | |
957 | "R_PPC_TPREL16_HI", /* name */ | |
958 | FALSE, /* partial_inplace */ | |
959 | 0, /* src_mask */ | |
960 | 0xffff, /* dst_mask */ | |
961 | FALSE), /* pcrel_offset */ | |
962 | ||
963 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
964 | HOWTO (R_PPC_TPREL16_HA, | |
965 | 16, /* rightshift */ | |
966 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
967 | 16, /* bitsize */ | |
968 | FALSE, /* pc_relative */ | |
969 | 0, /* bitpos */ | |
970 | complain_overflow_dont, /* complain_on_overflow */ | |
971 | ppc_elf_unhandled_reloc, /* special_function */ | |
972 | "R_PPC_TPREL16_HA", /* name */ | |
973 | FALSE, /* partial_inplace */ | |
974 | 0, /* src_mask */ | |
975 | 0xffff, /* dst_mask */ | |
976 | FALSE), /* pcrel_offset */ | |
977 | ||
978 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
979 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
980 | to the first entry. */ | |
981 | HOWTO (R_PPC_GOT_TLSGD16, | |
252b5132 RH |
982 | 0, /* rightshift */ |
983 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
984 | 16, /* bitsize */ | |
b34976b6 | 985 | FALSE, /* pc_relative */ |
252b5132 RH |
986 | 0, /* bitpos */ |
987 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
988 | ppc_elf_unhandled_reloc, /* special_function */ |
989 | "R_PPC_GOT_TLSGD16", /* name */ | |
b34976b6 | 990 | FALSE, /* partial_inplace */ |
252b5132 RH |
991 | 0, /* src_mask */ |
992 | 0xffff, /* dst_mask */ | |
b34976b6 | 993 | FALSE), /* pcrel_offset */ |
252b5132 | 994 | |
7619e7c7 AM |
995 | /* Like GOT_TLSGD16, but no overflow. */ |
996 | HOWTO (R_PPC_GOT_TLSGD16_LO, | |
252b5132 | 997 | 0, /* rightshift */ |
7619e7c7 | 998 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 999 | 16, /* bitsize */ |
b34976b6 | 1000 | FALSE, /* pc_relative */ |
252b5132 | 1001 | 0, /* bitpos */ |
7619e7c7 AM |
1002 | complain_overflow_dont, /* complain_on_overflow */ |
1003 | ppc_elf_unhandled_reloc, /* special_function */ | |
1004 | "R_PPC_GOT_TLSGD16_LO", /* name */ | |
b34976b6 | 1005 | FALSE, /* partial_inplace */ |
252b5132 RH |
1006 | 0, /* src_mask */ |
1007 | 0xffff, /* dst_mask */ | |
b34976b6 | 1008 | FALSE), /* pcrel_offset */ |
252b5132 | 1009 | |
7619e7c7 AM |
1010 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1011 | HOWTO (R_PPC_GOT_TLSGD16_HI, | |
1012 | 16, /* rightshift */ | |
1013 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1014 | 16, /* bitsize */ | |
1015 | FALSE, /* pc_relative */ | |
1016 | 0, /* bitpos */ | |
1017 | complain_overflow_dont, /* complain_on_overflow */ | |
1018 | ppc_elf_unhandled_reloc, /* special_function */ | |
1019 | "R_PPC_GOT_TLSGD16_HI", /* name */ | |
1020 | FALSE, /* partial_inplace */ | |
1021 | 0, /* src_mask */ | |
1022 | 0xffff, /* dst_mask */ | |
1023 | FALSE), /* pcrel_offset */ | |
252b5132 | 1024 | |
7619e7c7 AM |
1025 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1026 | HOWTO (R_PPC_GOT_TLSGD16_HA, | |
1027 | 16, /* rightshift */ | |
1028 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1029 | 16, /* bitsize */ | |
1030 | FALSE, /* pc_relative */ | |
1031 | 0, /* bitpos */ | |
1032 | complain_overflow_dont, /* complain_on_overflow */ | |
1033 | ppc_elf_unhandled_reloc, /* special_function */ | |
1034 | "R_PPC_GOT_TLSGD16_HA", /* name */ | |
1035 | FALSE, /* partial_inplace */ | |
1036 | 0, /* src_mask */ | |
1037 | 0xffff, /* dst_mask */ | |
1038 | FALSE), /* pcrel_offset */ | |
1039 | ||
1040 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1041 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1042 | first entry. */ | |
1043 | HOWTO (R_PPC_GOT_TLSLD16, | |
252b5132 RH |
1044 | 0, /* rightshift */ |
1045 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1046 | 16, /* bitsize */ | |
7619e7c7 | 1047 | FALSE, /* pc_relative */ |
252b5132 RH |
1048 | 0, /* bitpos */ |
1049 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1050 | ppc_elf_unhandled_reloc, /* special_function */ |
1051 | "R_PPC_GOT_TLSLD16", /* name */ | |
b34976b6 | 1052 | FALSE, /* partial_inplace */ |
252b5132 RH |
1053 | 0, /* src_mask */ |
1054 | 0xffff, /* dst_mask */ | |
b34976b6 | 1055 | FALSE), /* pcrel_offset */ |
252b5132 | 1056 | |
7619e7c7 AM |
1057 | /* Like GOT_TLSLD16, but no overflow. */ |
1058 | HOWTO (R_PPC_GOT_TLSLD16_LO, | |
252b5132 | 1059 | 0, /* rightshift */ |
7619e7c7 AM |
1060 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1061 | 16, /* bitsize */ | |
b34976b6 | 1062 | FALSE, /* pc_relative */ |
252b5132 RH |
1063 | 0, /* bitpos */ |
1064 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1065 | ppc_elf_unhandled_reloc, /* special_function */ |
1066 | "R_PPC_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1067 | FALSE, /* partial_inplace */ |
252b5132 | 1068 | 0, /* src_mask */ |
7619e7c7 | 1069 | 0xffff, /* dst_mask */ |
b34976b6 | 1070 | FALSE), /* pcrel_offset */ |
252b5132 | 1071 | |
7619e7c7 AM |
1072 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1073 | HOWTO (R_PPC_GOT_TLSLD16_HI, | |
1074 | 16, /* rightshift */ | |
1075 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1076 | 16, /* bitsize */ | |
b34976b6 | 1077 | FALSE, /* pc_relative */ |
252b5132 RH |
1078 | 0, /* bitpos */ |
1079 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1080 | ppc_elf_unhandled_reloc, /* special_function */ |
1081 | "R_PPC_GOT_TLSLD16_HI", /* name */ | |
b34976b6 | 1082 | FALSE, /* partial_inplace */ |
252b5132 | 1083 | 0, /* src_mask */ |
7619e7c7 | 1084 | 0xffff, /* dst_mask */ |
b34976b6 | 1085 | FALSE), /* pcrel_offset */ |
252b5132 | 1086 | |
7619e7c7 AM |
1087 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1088 | HOWTO (R_PPC_GOT_TLSLD16_HA, | |
1089 | 16, /* rightshift */ | |
1090 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1091 | 16, /* bitsize */ | |
1092 | FALSE, /* pc_relative */ | |
1093 | 0, /* bitpos */ | |
1094 | complain_overflow_dont, /* complain_on_overflow */ | |
1095 | ppc_elf_unhandled_reloc, /* special_function */ | |
1096 | "R_PPC_GOT_TLSLD16_HA", /* name */ | |
1097 | FALSE, /* partial_inplace */ | |
1098 | 0, /* src_mask */ | |
1099 | 0xffff, /* dst_mask */ | |
1100 | FALSE), /* pcrel_offset */ | |
1101 | ||
1102 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes | |
1103 | the offset to the entry. */ | |
1104 | HOWTO (R_PPC_GOT_DTPREL16, | |
252b5132 RH |
1105 | 0, /* rightshift */ |
1106 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1107 | 16, /* bitsize */ | |
b34976b6 | 1108 | FALSE, /* pc_relative */ |
252b5132 RH |
1109 | 0, /* bitpos */ |
1110 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1111 | ppc_elf_unhandled_reloc, /* special_function */ |
1112 | "R_PPC_GOT_DTPREL16", /* name */ | |
b34976b6 | 1113 | FALSE, /* partial_inplace */ |
252b5132 RH |
1114 | 0, /* src_mask */ |
1115 | 0xffff, /* dst_mask */ | |
b34976b6 | 1116 | FALSE), /* pcrel_offset */ |
252b5132 | 1117 | |
7619e7c7 AM |
1118 | /* Like GOT_DTPREL16, but no overflow. */ |
1119 | HOWTO (R_PPC_GOT_DTPREL16_LO, | |
1120 | 0, /* rightshift */ | |
1121 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1122 | 16, /* bitsize */ | |
1123 | FALSE, /* pc_relative */ | |
1124 | 0, /* bitpos */ | |
1125 | complain_overflow_dont, /* complain_on_overflow */ | |
1126 | ppc_elf_unhandled_reloc, /* special_function */ | |
1127 | "R_PPC_GOT_DTPREL16_LO", /* name */ | |
1128 | FALSE, /* partial_inplace */ | |
1129 | 0, /* src_mask */ | |
1130 | 0xffff, /* dst_mask */ | |
1131 | FALSE), /* pcrel_offset */ | |
252b5132 | 1132 | |
7619e7c7 AM |
1133 | /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */ |
1134 | HOWTO (R_PPC_GOT_DTPREL16_HI, | |
1135 | 16, /* rightshift */ | |
1136 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1137 | 16, /* bitsize */ | |
1138 | FALSE, /* pc_relative */ | |
1139 | 0, /* bitpos */ | |
1140 | complain_overflow_dont, /* complain_on_overflow */ | |
1141 | ppc_elf_unhandled_reloc, /* special_function */ | |
1142 | "R_PPC_GOT_DTPREL16_HI", /* name */ | |
1143 | FALSE, /* partial_inplace */ | |
1144 | 0, /* src_mask */ | |
1145 | 0xffff, /* dst_mask */ | |
1146 | FALSE), /* pcrel_offset */ | |
252b5132 | 1147 | |
7619e7c7 AM |
1148 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1149 | HOWTO (R_PPC_GOT_DTPREL16_HA, | |
1150 | 16, /* rightshift */ | |
1151 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1152 | 16, /* bitsize */ | |
1153 | FALSE, /* pc_relative */ | |
1154 | 0, /* bitpos */ | |
1155 | complain_overflow_dont, /* complain_on_overflow */ | |
1156 | ppc_elf_unhandled_reloc, /* special_function */ | |
1157 | "R_PPC_GOT_DTPREL16_HA", /* name */ | |
1158 | FALSE, /* partial_inplace */ | |
1159 | 0, /* src_mask */ | |
1160 | 0xffff, /* dst_mask */ | |
1161 | FALSE), /* pcrel_offset */ | |
c3668558 | 1162 | |
7619e7c7 AM |
1163 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the |
1164 | offset to the entry. */ | |
1165 | HOWTO (R_PPC_GOT_TPREL16, | |
1166 | 0, /* rightshift */ | |
1167 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1168 | 16, /* bitsize */ | |
1169 | FALSE, /* pc_relative */ | |
1170 | 0, /* bitpos */ | |
1171 | complain_overflow_signed, /* complain_on_overflow */ | |
1172 | ppc_elf_unhandled_reloc, /* special_function */ | |
1173 | "R_PPC_GOT_TPREL16", /* name */ | |
1174 | FALSE, /* partial_inplace */ | |
1175 | 0, /* src_mask */ | |
1176 | 0xffff, /* dst_mask */ | |
1177 | FALSE), /* pcrel_offset */ | |
1178 | ||
1179 | /* Like GOT_TPREL16, but no overflow. */ | |
1180 | HOWTO (R_PPC_GOT_TPREL16_LO, | |
1181 | 0, /* rightshift */ | |
1182 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1183 | 16, /* bitsize */ | |
1184 | FALSE, /* pc_relative */ | |
1185 | 0, /* bitpos */ | |
1186 | complain_overflow_dont, /* complain_on_overflow */ | |
1187 | ppc_elf_unhandled_reloc, /* special_function */ | |
1188 | "R_PPC_GOT_TPREL16_LO", /* name */ | |
1189 | FALSE, /* partial_inplace */ | |
1190 | 0, /* src_mask */ | |
1191 | 0xffff, /* dst_mask */ | |
1192 | FALSE), /* pcrel_offset */ | |
1193 | ||
1194 | /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */ | |
1195 | HOWTO (R_PPC_GOT_TPREL16_HI, | |
1196 | 16, /* rightshift */ | |
1197 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1198 | 16, /* bitsize */ | |
1199 | FALSE, /* pc_relative */ | |
1200 | 0, /* bitpos */ | |
1201 | complain_overflow_dont, /* complain_on_overflow */ | |
1202 | ppc_elf_unhandled_reloc, /* special_function */ | |
1203 | "R_PPC_GOT_TPREL16_HI", /* name */ | |
1204 | FALSE, /* partial_inplace */ | |
1205 | 0, /* src_mask */ | |
1206 | 0xffff, /* dst_mask */ | |
1207 | FALSE), /* pcrel_offset */ | |
1208 | ||
1209 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ | |
1210 | HOWTO (R_PPC_GOT_TPREL16_HA, | |
1211 | 16, /* rightshift */ | |
1212 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1213 | 16, /* bitsize */ | |
1214 | FALSE, /* pc_relative */ | |
1215 | 0, /* bitpos */ | |
1216 | complain_overflow_dont, /* complain_on_overflow */ | |
1217 | ppc_elf_unhandled_reloc, /* special_function */ | |
1218 | "R_PPC_GOT_TPREL16_HA", /* name */ | |
1219 | FALSE, /* partial_inplace */ | |
1220 | 0, /* src_mask */ | |
1221 | 0xffff, /* dst_mask */ | |
1222 | FALSE), /* pcrel_offset */ | |
1223 | ||
1224 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
1225 | in the SVR4 ELF ABI. */ | |
1226 | ||
1227 | /* 32 bit value resulting from the addend minus the symbol. */ | |
1228 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
1229 | 0, /* rightshift */ | |
1230 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1231 | 32, /* bitsize */ | |
1232 | FALSE, /* pc_relative */ | |
1233 | 0, /* bitpos */ | |
1234 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1235 | bfd_elf_generic_reloc, /* special_function */ | |
1236 | "R_PPC_EMB_NADDR32", /* name */ | |
1237 | FALSE, /* partial_inplace */ | |
1238 | 0, /* src_mask */ | |
1239 | 0xffffffff, /* dst_mask */ | |
1240 | FALSE), /* pcrel_offset */ | |
1241 | ||
1242 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1243 | HOWTO (R_PPC_EMB_NADDR16, /* type */ | |
1244 | 0, /* rightshift */ | |
1245 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1246 | 16, /* bitsize */ | |
1247 | FALSE, /* pc_relative */ | |
1248 | 0, /* bitpos */ | |
1249 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1250 | bfd_elf_generic_reloc, /* special_function */ | |
1251 | "R_PPC_EMB_NADDR16", /* name */ | |
1252 | FALSE, /* partial_inplace */ | |
1253 | 0, /* src_mask */ | |
1254 | 0xffff, /* dst_mask */ | |
1255 | FALSE), /* pcrel_offset */ | |
1256 | ||
1257 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1258 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
1259 | 0, /* rightshift */ | |
1260 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1261 | 16, /* bitsize */ | |
1262 | FALSE, /* pc_relative */ | |
1263 | 0, /* bitpos */ | |
1264 | complain_overflow_dont,/* complain_on_overflow */ | |
1265 | bfd_elf_generic_reloc, /* special_function */ | |
1266 | "R_PPC_EMB_ADDR16_LO", /* name */ | |
1267 | FALSE, /* partial_inplace */ | |
1268 | 0, /* src_mask */ | |
1269 | 0xffff, /* dst_mask */ | |
1270 | FALSE), /* pcrel_offset */ | |
1271 | ||
1272 | /* The high order 16 bits of the addend minus the symbol. */ | |
1273 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
1274 | 16, /* rightshift */ | |
1275 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1276 | 16, /* bitsize */ | |
1277 | FALSE, /* pc_relative */ | |
1278 | 0, /* bitpos */ | |
1279 | complain_overflow_dont, /* complain_on_overflow */ | |
1280 | bfd_elf_generic_reloc, /* special_function */ | |
1281 | "R_PPC_EMB_NADDR16_HI", /* name */ | |
1282 | FALSE, /* partial_inplace */ | |
1283 | 0, /* src_mask */ | |
1284 | 0xffff, /* dst_mask */ | |
1285 | FALSE), /* pcrel_offset */ | |
1286 | ||
1287 | /* The high order 16 bits of the result of the addend minus the address, | |
1288 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
1289 | is negative. */ | |
1290 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ | |
1291 | 16, /* rightshift */ | |
1292 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1293 | 16, /* bitsize */ | |
1294 | FALSE, /* pc_relative */ | |
1295 | 0, /* bitpos */ | |
1296 | complain_overflow_dont, /* complain_on_overflow */ | |
25dbc73a AM |
1297 | ppc_elf_addr16_ha_reloc, /* special_function */ |
1298 | "R_PPC_EMB_NADDR16_HA", /* name */ | |
1299 | FALSE, /* partial_inplace */ | |
1300 | 0, /* src_mask */ | |
1301 | 0xffff, /* dst_mask */ | |
1302 | FALSE), /* pcrel_offset */ | |
1303 | ||
1304 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1305 | address in the .sdata section, and returning the offset from | |
1306 | _SDA_BASE_ for that relocation. */ | |
1307 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
1308 | 0, /* rightshift */ | |
1309 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1310 | 16, /* bitsize */ | |
1311 | FALSE, /* pc_relative */ | |
1312 | 0, /* bitpos */ | |
bd6c6e2b | 1313 | complain_overflow_signed, /* complain_on_overflow */ |
25dbc73a AM |
1314 | bfd_elf_generic_reloc, /* special_function */ |
1315 | "R_PPC_EMB_SDAI16", /* name */ | |
1316 | FALSE, /* partial_inplace */ | |
1317 | 0, /* src_mask */ | |
1318 | 0xffff, /* dst_mask */ | |
1319 | FALSE), /* pcrel_offset */ | |
1320 | ||
1321 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1322 | address in the .sdata2 section, and returning the offset from | |
1323 | _SDA2_BASE_ for that relocation. */ | |
1324 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
1325 | 0, /* rightshift */ | |
1326 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1327 | 16, /* bitsize */ | |
1328 | FALSE, /* pc_relative */ | |
1329 | 0, /* bitpos */ | |
bd6c6e2b | 1330 | complain_overflow_signed, /* complain_on_overflow */ |
25dbc73a AM |
1331 | bfd_elf_generic_reloc, /* special_function */ |
1332 | "R_PPC_EMB_SDA2I16", /* name */ | |
1333 | FALSE, /* partial_inplace */ | |
1334 | 0, /* src_mask */ | |
1335 | 0xffff, /* dst_mask */ | |
1336 | FALSE), /* pcrel_offset */ | |
1337 | ||
1338 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
1339 | small data items. */ | |
1340 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
1341 | 0, /* rightshift */ | |
1342 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1343 | 16, /* bitsize */ | |
1344 | FALSE, /* pc_relative */ | |
1345 | 0, /* bitpos */ | |
1346 | complain_overflow_signed, /* complain_on_overflow */ | |
1347 | bfd_elf_generic_reloc, /* special_function */ | |
1348 | "R_PPC_EMB_SDA2REL", /* name */ | |
1349 | FALSE, /* partial_inplace */ | |
1350 | 0, /* src_mask */ | |
1351 | 0xffff, /* dst_mask */ | |
1352 | FALSE), /* pcrel_offset */ | |
1353 | ||
1354 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
1355 | signed offset from the appropriate base, and filling in the register | |
1356 | field with the appropriate register (0, 2, or 13). */ | |
1357 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
1358 | 0, /* rightshift */ | |
1359 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1360 | 16, /* bitsize */ | |
1361 | FALSE, /* pc_relative */ | |
1362 | 0, /* bitpos */ | |
1363 | complain_overflow_signed, /* complain_on_overflow */ | |
1364 | bfd_elf_generic_reloc, /* special_function */ | |
1365 | "R_PPC_EMB_SDA21", /* name */ | |
1366 | FALSE, /* partial_inplace */ | |
1367 | 0, /* src_mask */ | |
1368 | 0xffff, /* dst_mask */ | |
1369 | FALSE), /* pcrel_offset */ | |
1370 | ||
1371 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
1372 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
1373 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
1374 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
1375 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
1376 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
1377 | ||
1378 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
1379 | in the 16 bit signed offset from the appropriate base, and filling in the | |
1380 | register field with the appropriate register (0, 2, or 13). */ | |
1381 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
1382 | 0, /* rightshift */ | |
1383 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1384 | 16, /* bitsize */ | |
ddfd6795 | 1385 | FALSE, /* pc_relative */ |
25dbc73a AM |
1386 | 0, /* bitpos */ |
1387 | complain_overflow_signed, /* complain_on_overflow */ | |
1388 | bfd_elf_generic_reloc, /* special_function */ | |
1389 | "R_PPC_EMB_RELSDA", /* name */ | |
1390 | FALSE, /* partial_inplace */ | |
1391 | 0, /* src_mask */ | |
1392 | 0xffff, /* dst_mask */ | |
1393 | FALSE), /* pcrel_offset */ | |
1394 | ||
e054468f AM |
1395 | HOWTO (R_PPC_IRELATIVE, /* type */ |
1396 | 0, /* rightshift */ | |
1397 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1398 | 32, /* bitsize */ | |
1399 | FALSE, /* pc_relative */ | |
1400 | 0, /* bitpos */ | |
1401 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1402 | bfd_elf_generic_reloc, /* special_function */ | |
1403 | "R_PPC_IRELATIVE", /* name */ | |
1404 | FALSE, /* partial_inplace */ | |
1405 | 0, /* src_mask */ | |
1406 | 0xffffffff, /* dst_mask */ | |
1407 | FALSE), /* pcrel_offset */ | |
1408 | ||
d7128ce4 AM |
1409 | /* A 16 bit relative relocation. */ |
1410 | HOWTO (R_PPC_REL16, /* type */ | |
1411 | 0, /* rightshift */ | |
1412 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1413 | 16, /* bitsize */ | |
1414 | TRUE, /* pc_relative */ | |
1415 | 0, /* bitpos */ | |
1416 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1417 | bfd_elf_generic_reloc, /* special_function */ | |
1418 | "R_PPC_REL16", /* name */ | |
1419 | FALSE, /* partial_inplace */ | |
1420 | 0, /* src_mask */ | |
1421 | 0xffff, /* dst_mask */ | |
1422 | TRUE), /* pcrel_offset */ | |
1423 | ||
1424 | /* A 16 bit relative relocation without overflow. */ | |
1425 | HOWTO (R_PPC_REL16_LO, /* type */ | |
1426 | 0, /* rightshift */ | |
1427 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1428 | 16, /* bitsize */ | |
1429 | TRUE, /* pc_relative */ | |
1430 | 0, /* bitpos */ | |
1431 | complain_overflow_dont,/* complain_on_overflow */ | |
1432 | bfd_elf_generic_reloc, /* special_function */ | |
1433 | "R_PPC_REL16_LO", /* name */ | |
1434 | FALSE, /* partial_inplace */ | |
1435 | 0, /* src_mask */ | |
1436 | 0xffff, /* dst_mask */ | |
1437 | TRUE), /* pcrel_offset */ | |
1438 | ||
1439 | /* The high order 16 bits of a relative address. */ | |
1440 | HOWTO (R_PPC_REL16_HI, /* type */ | |
1441 | 16, /* rightshift */ | |
1442 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1443 | 16, /* bitsize */ | |
1444 | TRUE, /* pc_relative */ | |
1445 | 0, /* bitpos */ | |
1446 | complain_overflow_dont, /* complain_on_overflow */ | |
1447 | bfd_elf_generic_reloc, /* special_function */ | |
1448 | "R_PPC_REL16_HI", /* name */ | |
1449 | FALSE, /* partial_inplace */ | |
1450 | 0, /* src_mask */ | |
1451 | 0xffff, /* dst_mask */ | |
1452 | TRUE), /* pcrel_offset */ | |
1453 | ||
1454 | /* The high order 16 bits of a relative address, plus 1 if the contents of | |
1455 | the low 16 bits, treated as a signed number, is negative. */ | |
1456 | HOWTO (R_PPC_REL16_HA, /* type */ | |
1457 | 16, /* rightshift */ | |
1458 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1459 | 16, /* bitsize */ | |
1460 | TRUE, /* pc_relative */ | |
1461 | 0, /* bitpos */ | |
1462 | complain_overflow_dont, /* complain_on_overflow */ | |
1463 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1464 | "R_PPC_REL16_HA", /* name */ | |
1465 | FALSE, /* partial_inplace */ | |
1466 | 0, /* src_mask */ | |
1467 | 0xffff, /* dst_mask */ | |
1468 | TRUE), /* pcrel_offset */ | |
1469 | ||
25dbc73a AM |
1470 | /* GNU extension to record C++ vtable hierarchy. */ |
1471 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ | |
1472 | 0, /* rightshift */ | |
1473 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1474 | 0, /* bitsize */ | |
1475 | FALSE, /* pc_relative */ | |
1476 | 0, /* bitpos */ | |
1477 | complain_overflow_dont, /* complain_on_overflow */ | |
1478 | NULL, /* special_function */ | |
1479 | "R_PPC_GNU_VTINHERIT", /* name */ | |
1480 | FALSE, /* partial_inplace */ | |
1481 | 0, /* src_mask */ | |
1482 | 0, /* dst_mask */ | |
1483 | FALSE), /* pcrel_offset */ | |
1484 | ||
1485 | /* GNU extension to record C++ vtable member usage. */ | |
1486 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ | |
1487 | 0, /* rightshift */ | |
1488 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1489 | 0, /* bitsize */ | |
1490 | FALSE, /* pc_relative */ | |
1491 | 0, /* bitpos */ | |
1492 | complain_overflow_dont, /* complain_on_overflow */ | |
1493 | NULL, /* special_function */ | |
1494 | "R_PPC_GNU_VTENTRY", /* name */ | |
7619e7c7 AM |
1495 | FALSE, /* partial_inplace */ |
1496 | 0, /* src_mask */ | |
25dbc73a | 1497 | 0, /* dst_mask */ |
7619e7c7 AM |
1498 | FALSE), /* pcrel_offset */ |
1499 | ||
25dbc73a AM |
1500 | /* Phony reloc to handle AIX style TOC entries. */ |
1501 | HOWTO (R_PPC_TOC16, /* type */ | |
7619e7c7 AM |
1502 | 0, /* rightshift */ |
1503 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1504 | 16, /* bitsize */ | |
1505 | FALSE, /* pc_relative */ | |
1506 | 0, /* bitpos */ | |
25dbc73a | 1507 | complain_overflow_signed, /* complain_on_overflow */ |
7619e7c7 | 1508 | bfd_elf_generic_reloc, /* special_function */ |
25dbc73a | 1509 | "R_PPC_TOC16", /* name */ |
7619e7c7 AM |
1510 | FALSE, /* partial_inplace */ |
1511 | 0, /* src_mask */ | |
1512 | 0xffff, /* dst_mask */ | |
1513 | FALSE), /* pcrel_offset */ | |
25dbc73a AM |
1514 | }; |
1515 | \f | |
1516 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
1517 | ||
1518 | static void | |
1519 | ppc_elf_howto_init (void) | |
1520 | { | |
1521 | unsigned int i, type; | |
1522 | ||
1523 | for (i = 0; | |
1524 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1525 | i++) | |
1526 | { | |
1527 | type = ppc_elf_howto_raw[i].type; | |
1528 | if (type >= (sizeof (ppc_elf_howto_table) | |
1529 | / sizeof (ppc_elf_howto_table[0]))) | |
1530 | abort (); | |
1531 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; | |
1532 | } | |
1533 | } | |
1534 | ||
1535 | static reloc_howto_type * | |
1536 | ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1537 | bfd_reloc_code_real_type code) | |
1538 | { | |
1539 | enum elf_ppc_reloc_type r; | |
1540 | ||
1541 | /* Initialize howto table if not already done. */ | |
1542 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1543 | ppc_elf_howto_init (); | |
1544 | ||
1545 | switch (code) | |
1546 | { | |
1547 | default: | |
1548 | return NULL; | |
1549 | ||
1550 | case BFD_RELOC_NONE: r = R_PPC_NONE; break; | |
1551 | case BFD_RELOC_32: r = R_PPC_ADDR32; break; | |
1552 | case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break; | |
1553 | case BFD_RELOC_16: r = R_PPC_ADDR16; break; | |
1554 | case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break; | |
1555 | case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break; | |
1556 | case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break; | |
1557 | case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break; | |
1558 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break; | |
1559 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break; | |
1560 | case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break; | |
1561 | case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break; | |
1562 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break; | |
1563 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break; | |
1564 | case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break; | |
1565 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break; | |
1566 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break; | |
1567 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break; | |
1568 | case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break; | |
1569 | case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break; | |
1570 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break; | |
1571 | case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break; | |
1572 | case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break; | |
1573 | case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break; | |
1574 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break; | |
1575 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break; | |
1576 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break; | |
1577 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break; | |
1578 | case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break; | |
1579 | case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break; | |
1580 | case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break; | |
1581 | case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break; | |
1582 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break; | |
1583 | case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break; | |
1584 | case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break; | |
1585 | case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break; | |
727fc41e AM |
1586 | case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break; |
1587 | case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break; | |
25dbc73a AM |
1588 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break; |
1589 | case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break; | |
1590 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break; | |
1591 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break; | |
1592 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break; | |
1593 | case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break; | |
1594 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break; | |
1595 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break; | |
1596 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break; | |
1597 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break; | |
1598 | case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break; | |
1599 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break; | |
1600 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break; | |
1601 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break; | |
1602 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break; | |
1603 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break; | |
1604 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break; | |
1605 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break; | |
1606 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break; | |
1607 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break; | |
1608 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break; | |
1609 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break; | |
1610 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break; | |
1611 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break; | |
1612 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break; | |
1613 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break; | |
1614 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break; | |
1615 | case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break; | |
1616 | case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break; | |
1617 | case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break; | |
1618 | case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break; | |
1619 | case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break; | |
1620 | case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break; | |
1621 | case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break; | |
1622 | case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break; | |
1623 | case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break; | |
1624 | case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break; | |
1625 | case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break; | |
1626 | case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break; | |
1627 | case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break; | |
1628 | case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break; | |
1629 | case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break; | |
1630 | case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break; | |
d7128ce4 AM |
1631 | case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break; |
1632 | case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break; | |
1633 | case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break; | |
1634 | case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break; | |
25dbc73a AM |
1635 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break; |
1636 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break; | |
1637 | } | |
1638 | ||
1639 | return ppc_elf_howto_table[r]; | |
1640 | }; | |
1641 | ||
157090f7 AM |
1642 | static reloc_howto_type * |
1643 | ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1644 | const char *r_name) | |
1645 | { | |
1646 | unsigned int i; | |
1647 | ||
1648 | for (i = 0; | |
1649 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1650 | i++) | |
1651 | if (ppc_elf_howto_raw[i].name != NULL | |
1652 | && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0) | |
1653 | return &ppc_elf_howto_raw[i]; | |
1654 | ||
1655 | return NULL; | |
1656 | } | |
1657 | ||
25dbc73a AM |
1658 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
1659 | ||
1660 | static void | |
1661 | ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, | |
1662 | arelent *cache_ptr, | |
1663 | Elf_Internal_Rela *dst) | |
1664 | { | |
1665 | /* Initialize howto table if not already done. */ | |
1666 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1667 | ppc_elf_howto_init (); | |
1668 | ||
1669 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); | |
1670 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; | |
375de94a AM |
1671 | |
1672 | /* Just because the above assert didn't trigger doesn't mean that | |
1673 | ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */ | |
1674 | if (!cache_ptr->howto) | |
1675 | { | |
1676 | (*_bfd_error_handler) (_("%B: invalid relocation type %d"), | |
1677 | abfd, ELF32_R_TYPE (dst->r_info)); | |
1678 | bfd_set_error (bfd_error_bad_value); | |
1679 | ||
1680 | cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE]; | |
1681 | } | |
25dbc73a AM |
1682 | } |
1683 | ||
d7128ce4 | 1684 | /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */ |
25dbc73a AM |
1685 | |
1686 | static bfd_reloc_status_type | |
1687 | ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED, | |
1688 | arelent *reloc_entry, | |
1689 | asymbol *symbol, | |
1690 | void *data ATTRIBUTE_UNUSED, | |
1691 | asection *input_section, | |
1692 | bfd *output_bfd, | |
1693 | char **error_message ATTRIBUTE_UNUSED) | |
1694 | { | |
1695 | bfd_vma relocation; | |
1696 | ||
1697 | if (output_bfd != NULL) | |
1698 | { | |
1699 | reloc_entry->address += input_section->output_offset; | |
1700 | return bfd_reloc_ok; | |
1701 | } | |
1702 | ||
1703 | if (reloc_entry->address > bfd_get_section_limit (abfd, input_section)) | |
1704 | return bfd_reloc_outofrange; | |
1705 | ||
1706 | if (bfd_is_com_section (symbol->section)) | |
1707 | relocation = 0; | |
1708 | else | |
1709 | relocation = symbol->value; | |
1710 | ||
1711 | relocation += symbol->section->output_section->vma; | |
1712 | relocation += symbol->section->output_offset; | |
1713 | relocation += reloc_entry->addend; | |
d7128ce4 AM |
1714 | if (reloc_entry->howto->pc_relative) |
1715 | relocation -= reloc_entry->address; | |
25dbc73a AM |
1716 | |
1717 | reloc_entry->addend += (relocation & 0x8000) << 1; | |
1718 | ||
1719 | return bfd_reloc_continue; | |
1720 | } | |
1721 | ||
1722 | static bfd_reloc_status_type | |
1723 | ppc_elf_unhandled_reloc (bfd *abfd, | |
1724 | arelent *reloc_entry, | |
1725 | asymbol *symbol, | |
1726 | void *data, | |
1727 | asection *input_section, | |
1728 | bfd *output_bfd, | |
1729 | char **error_message) | |
1730 | { | |
1731 | /* If this is a relocatable link (output_bfd test tells us), just | |
1732 | call the generic function. Any adjustment will be done at final | |
1733 | link time. */ | |
1734 | if (output_bfd != NULL) | |
1735 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
1736 | input_section, output_bfd, error_message); | |
1737 | ||
1738 | if (error_message != NULL) | |
1739 | { | |
1740 | static char buf[60]; | |
1741 | sprintf (buf, _("generic linker can't handle %s"), | |
1742 | reloc_entry->howto->name); | |
1743 | *error_message = buf; | |
1744 | } | |
1745 | return bfd_reloc_dangerous; | |
1746 | } | |
1747 | \f | |
1748 | /* Sections created by the linker. */ | |
1749 | ||
1750 | typedef struct elf_linker_section | |
1751 | { | |
c9a2f333 | 1752 | /* Pointer to the bfd section. */ |
25dbc73a | 1753 | asection *section; |
c9a2f333 AM |
1754 | /* Section name. */ |
1755 | const char *name; | |
1756 | /* Associated bss section name. */ | |
1757 | const char *bss_name; | |
1758 | /* Associated symbol name. */ | |
1759 | const char *sym_name; | |
046183de AM |
1760 | /* Associated symbol. */ |
1761 | struct elf_link_hash_entry *sym; | |
25dbc73a AM |
1762 | } elf_linker_section_t; |
1763 | ||
1764 | /* Linked list of allocated pointer entries. This hangs off of the | |
1765 | symbol lists, and provides allows us to return different pointers, | |
1766 | based on different addend's. */ | |
1767 | ||
1768 | typedef struct elf_linker_section_pointers | |
1769 | { | |
1770 | /* next allocated pointer for this symbol */ | |
1771 | struct elf_linker_section_pointers *next; | |
1772 | /* offset of pointer from beginning of section */ | |
1773 | bfd_vma offset; | |
1774 | /* addend used */ | |
1775 | bfd_vma addend; | |
1776 | /* which linker section this is */ | |
1777 | elf_linker_section_t *lsect; | |
25dbc73a AM |
1778 | } elf_linker_section_pointers_t; |
1779 | ||
1780 | struct ppc_elf_obj_tdata | |
1781 | { | |
1782 | struct elf_obj_tdata elf; | |
1783 | ||
1784 | /* A mapping from local symbols to offsets into the various linker | |
1785 | sections added. This is index by the symbol index. */ | |
1786 | elf_linker_section_pointers_t **linker_section_pointers; | |
016687f8 AM |
1787 | |
1788 | /* Flags used to auto-detect plt type. */ | |
1789 | unsigned int makes_plt_call : 1; | |
1790 | unsigned int has_rel16 : 1; | |
25dbc73a AM |
1791 | }; |
1792 | ||
1793 | #define ppc_elf_tdata(bfd) \ | |
1794 | ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any) | |
7619e7c7 | 1795 | |
25dbc73a AM |
1796 | #define elf_local_ptr_offsets(bfd) \ |
1797 | (ppc_elf_tdata (bfd)->linker_section_pointers) | |
7619e7c7 | 1798 | |
0c8d6e5c AM |
1799 | #define is_ppc_elf(bfd) \ |
1800 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
4dfe6ac6 | 1801 | && elf_object_id (bfd) == PPC32_ELF_DATA) |
0c8d6e5c | 1802 | |
25dbc73a | 1803 | /* Override the generic function because we store some extras. */ |
7619e7c7 | 1804 | |
25dbc73a AM |
1805 | static bfd_boolean |
1806 | ppc_elf_mkobject (bfd *abfd) | |
1807 | { | |
0ffa91dd | 1808 | return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata), |
4dfe6ac6 | 1809 | PPC32_ELF_DATA); |
25dbc73a | 1810 | } |
7619e7c7 | 1811 | |
25dbc73a AM |
1812 | /* Fix bad default arch selected for a 32 bit input bfd when the |
1813 | default is 64 bit. */ | |
7619e7c7 | 1814 | |
25dbc73a AM |
1815 | static bfd_boolean |
1816 | ppc_elf_object_p (bfd *abfd) | |
1817 | { | |
1818 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64) | |
1819 | { | |
1820 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
7619e7c7 | 1821 | |
25dbc73a AM |
1822 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) |
1823 | { | |
1824 | /* Relies on arch after 64 bit default being 32 bit default. */ | |
1825 | abfd->arch_info = abfd->arch_info->next; | |
1826 | BFD_ASSERT (abfd->arch_info->bits_per_word == 32); | |
1827 | } | |
1828 | } | |
1829 | return TRUE; | |
1830 | } | |
7619e7c7 | 1831 | |
25dbc73a | 1832 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
7619e7c7 | 1833 | |
25dbc73a AM |
1834 | static bfd_boolean |
1835 | ppc_elf_set_private_flags (bfd *abfd, flagword flags) | |
1836 | { | |
1837 | BFD_ASSERT (!elf_flags_init (abfd) | |
1838 | || elf_elfheader (abfd)->e_flags == flags); | |
7619e7c7 | 1839 | |
25dbc73a AM |
1840 | elf_elfheader (abfd)->e_flags = flags; |
1841 | elf_flags_init (abfd) = TRUE; | |
1842 | return TRUE; | |
1843 | } | |
1844 | ||
25dbc73a | 1845 | /* Support for core dump NOTE sections. */ |
deaaf2f3 | 1846 | |
b34976b6 | 1847 | static bfd_boolean |
25dbc73a | 1848 | ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
252b5132 | 1849 | { |
25dbc73a AM |
1850 | int offset; |
1851 | unsigned int size; | |
252b5132 | 1852 | |
25dbc73a AM |
1853 | switch (note->descsz) |
1854 | { | |
1855 | default: | |
1856 | return FALSE; | |
252b5132 | 1857 | |
25dbc73a AM |
1858 | case 268: /* Linux/PPC. */ |
1859 | /* pr_cursig */ | |
1860 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
deaaf2f3 | 1861 | |
25dbc73a | 1862 | /* pr_pid */ |
261b8d08 | 1863 | elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24); |
9abc968f | 1864 | |
25dbc73a AM |
1865 | /* pr_reg */ |
1866 | offset = 72; | |
1867 | size = 192; | |
deaaf2f3 | 1868 | |
25dbc73a AM |
1869 | break; |
1870 | } | |
deaaf2f3 | 1871 | |
25dbc73a AM |
1872 | /* Make a ".reg/999" section. */ |
1873 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1874 | size, note->descpos + offset); | |
1875 | } | |
252b5132 | 1876 | |
25dbc73a AM |
1877 | static bfd_boolean |
1878 | ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
1879 | { | |
1880 | switch (note->descsz) | |
deaaf2f3 | 1881 | { |
25dbc73a AM |
1882 | default: |
1883 | return FALSE; | |
deaaf2f3 | 1884 | |
25dbc73a | 1885 | case 128: /* Linux/PPC elf_prpsinfo. */ |
bc989cdc JK |
1886 | elf_tdata (abfd)->core_pid |
1887 | = bfd_get_32 (abfd, note->descdata + 16); | |
25dbc73a AM |
1888 | elf_tdata (abfd)->core_program |
1889 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); | |
1890 | elf_tdata (abfd)->core_command | |
1891 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); | |
1892 | } | |
9abc968f | 1893 | |
25dbc73a AM |
1894 | /* Note that for some reason, a spurious space is tacked |
1895 | onto the end of the args in some (at least one anyway) | |
1896 | implementations, so strip it off if it exists. */ | |
70bccea4 | 1897 | |
25dbc73a AM |
1898 | { |
1899 | char *command = elf_tdata (abfd)->core_command; | |
1900 | int n = strlen (command); | |
70bccea4 | 1901 | |
25dbc73a AM |
1902 | if (0 < n && command[n - 1] == ' ') |
1903 | command[n - 1] = '\0'; | |
1904 | } | |
deaaf2f3 | 1905 | |
25dbc73a AM |
1906 | return TRUE; |
1907 | } | |
deaaf2f3 | 1908 | |
183e98be AM |
1909 | static char * |
1910 | ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...) | |
1911 | { | |
1912 | switch (note_type) | |
1913 | { | |
1914 | default: | |
1915 | return NULL; | |
1916 | ||
1917 | case NT_PRPSINFO: | |
1918 | { | |
1919 | char data[128]; | |
1920 | va_list ap; | |
1921 | ||
1922 | va_start (ap, note_type); | |
1923 | memset (data, 0, 32); | |
1924 | strncpy (data + 32, va_arg (ap, const char *), 16); | |
1925 | strncpy (data + 48, va_arg (ap, const char *), 80); | |
1926 | va_end (ap); | |
1927 | return elfcore_write_note (abfd, buf, bufsiz, | |
1928 | "CORE", note_type, data, sizeof (data)); | |
1929 | } | |
1930 | ||
1931 | case NT_PRSTATUS: | |
1932 | { | |
1933 | char data[268]; | |
1934 | va_list ap; | |
1935 | long pid; | |
1936 | int cursig; | |
1937 | const void *greg; | |
1938 | ||
1939 | va_start (ap, note_type); | |
1940 | memset (data, 0, 72); | |
1941 | pid = va_arg (ap, long); | |
1942 | bfd_put_32 (abfd, pid, data + 24); | |
1943 | cursig = va_arg (ap, int); | |
1944 | bfd_put_16 (abfd, cursig, data + 12); | |
1945 | greg = va_arg (ap, const void *); | |
1946 | memcpy (data + 72, greg, 192); | |
1947 | memset (data + 264, 0, 4); | |
1948 | va_end (ap); | |
1949 | return elfcore_write_note (abfd, buf, bufsiz, | |
1950 | "CORE", note_type, data, sizeof (data)); | |
1951 | } | |
1952 | } | |
1953 | } | |
1954 | ||
25dbc73a AM |
1955 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
1956 | or (bfd_vma) -1 if it should not be included. */ | |
deaaf2f3 | 1957 | |
25dbc73a AM |
1958 | static bfd_vma |
1959 | ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, | |
1960 | const asection *plt ATTRIBUTE_UNUSED, | |
1961 | const arelent *rel) | |
1962 | { | |
1963 | return rel->address; | |
1964 | } | |
deaaf2f3 | 1965 | |
25dbc73a | 1966 | /* Handle a PowerPC specific section when reading an object file. This |
6dc132d9 L |
1967 | is called when bfd_section_from_shdr finds a section with an unknown |
1968 | type. */ | |
deaaf2f3 | 1969 | |
25dbc73a | 1970 | static bfd_boolean |
6dc132d9 L |
1971 | ppc_elf_section_from_shdr (bfd *abfd, |
1972 | Elf_Internal_Shdr *hdr, | |
1973 | const char *name, | |
1974 | int shindex) | |
25dbc73a AM |
1975 | { |
1976 | asection *newsect; | |
1977 | flagword flags; | |
d1c6de6f | 1978 | |
6dc132d9 | 1979 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
25dbc73a | 1980 | return FALSE; |
deaaf2f3 | 1981 | |
25dbc73a AM |
1982 | newsect = hdr->bfd_section; |
1983 | flags = bfd_get_section_flags (abfd, newsect); | |
1984 | if (hdr->sh_flags & SHF_EXCLUDE) | |
1985 | flags |= SEC_EXCLUDE; | |
9abc968f | 1986 | |
25dbc73a AM |
1987 | if (hdr->sh_type == SHT_ORDERED) |
1988 | flags |= SEC_SORT_ENTRIES; | |
d1c6de6f | 1989 | |
25dbc73a AM |
1990 | bfd_set_section_flags (abfd, newsect, flags); |
1991 | return TRUE; | |
1992 | } | |
1993 | ||
1994 | /* Set up any other section flags and such that may be necessary. */ | |
1995 | ||
1996 | static bfd_boolean | |
1997 | ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, | |
1998 | Elf_Internal_Shdr *shdr, | |
1999 | asection *asect) | |
2000 | { | |
25dbc73a AM |
2001 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) |
2002 | shdr->sh_type = SHT_ORDERED; | |
2003 | ||
2004 | return TRUE; | |
2005 | } | |
2006 | ||
2007 | /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we | |
2008 | need to bump up the number of section headers. */ | |
2009 | ||
2010 | static int | |
a6b96beb AM |
2011 | ppc_elf_additional_program_headers (bfd *abfd, |
2012 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
25dbc73a AM |
2013 | { |
2014 | asection *s; | |
2015 | int ret = 0; | |
d1c6de6f | 2016 | |
25dbc73a AM |
2017 | s = bfd_get_section_by_name (abfd, ".sbss2"); |
2018 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2019 | ++ret; | |
d1c6de6f | 2020 | |
25dbc73a AM |
2021 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); |
2022 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2023 | ++ret; | |
deaaf2f3 | 2024 | |
25dbc73a AM |
2025 | return ret; |
2026 | } | |
deaaf2f3 | 2027 | |
25dbc73a AM |
2028 | /* Add extra PPC sections -- Note, for now, make .sbss2 and |
2029 | .PPC.EMB.sbss0 a normal section, and not a bss section so | |
2030 | that the linker doesn't crater when trying to make more than | |
2031 | 2 sections. */ | |
e656e369 | 2032 | |
b35d266b | 2033 | static const struct bfd_elf_special_section ppc_elf_special_sections[] = |
7f4d3958 | 2034 | { |
0112cd26 NC |
2035 | { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR }, |
2036 | { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2037 | { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2038 | { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2039 | { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2040 | { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC }, | |
2041 | { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 }, | |
2042 | { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2043 | { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2044 | { NULL, 0, 0, 0, 0 } | |
7f4d3958 L |
2045 | }; |
2046 | ||
551b43fd AM |
2047 | /* This is what we want for new plt/got. */ |
2048 | static struct bfd_elf_special_section ppc_alt_plt = | |
0112cd26 | 2049 | { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC }; |
551b43fd AM |
2050 | |
2051 | static const struct bfd_elf_special_section * | |
2052 | ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) | |
7f4d3958 | 2053 | { |
b35d266b | 2054 | const struct bfd_elf_special_section *ssect; |
551b43fd AM |
2055 | |
2056 | /* See if this is one of the special sections. */ | |
2057 | if (sec->name == NULL) | |
2058 | return NULL; | |
2059 | ||
2060 | ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections, | |
2061 | sec->use_rela_p); | |
2062 | if (ssect != NULL) | |
2063 | { | |
2064 | if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0) | |
2065 | ssect = &ppc_alt_plt; | |
2066 | return ssect; | |
2067 | } | |
2068 | ||
2069 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
2070 | } | |
25dbc73a AM |
2071 | \f |
2072 | /* Very simple linked list structure for recording apuinfo values. */ | |
2073 | typedef struct apuinfo_list | |
2074 | { | |
2075 | struct apuinfo_list *next; | |
2076 | unsigned long value; | |
2077 | } | |
2078 | apuinfo_list; | |
e656e369 | 2079 | |
25dbc73a | 2080 | static apuinfo_list *head; |
f2faa800 | 2081 | static bfd_boolean apuinfo_set; |
deaaf2f3 | 2082 | |
25dbc73a AM |
2083 | static void |
2084 | apuinfo_list_init (void) | |
2085 | { | |
2086 | head = NULL; | |
f2faa800 | 2087 | apuinfo_set = FALSE; |
25dbc73a | 2088 | } |
9abc968f | 2089 | |
25dbc73a AM |
2090 | static void |
2091 | apuinfo_list_add (unsigned long value) | |
2092 | { | |
2093 | apuinfo_list *entry = head; | |
deaaf2f3 | 2094 | |
25dbc73a AM |
2095 | while (entry != NULL) |
2096 | { | |
2097 | if (entry->value == value) | |
2098 | return; | |
2099 | entry = entry->next; | |
2100 | } | |
b4a38de6 | 2101 | |
25dbc73a AM |
2102 | entry = bfd_malloc (sizeof (* entry)); |
2103 | if (entry == NULL) | |
2104 | return; | |
e656e369 | 2105 | |
25dbc73a AM |
2106 | entry->value = value; |
2107 | entry->next = head; | |
2108 | head = entry; | |
2109 | } | |
9abc968f | 2110 | |
25dbc73a AM |
2111 | static unsigned |
2112 | apuinfo_list_length (void) | |
2113 | { | |
2114 | apuinfo_list *entry; | |
2115 | unsigned long count; | |
9abc968f | 2116 | |
25dbc73a AM |
2117 | for (entry = head, count = 0; |
2118 | entry; | |
2119 | entry = entry->next) | |
2120 | ++ count; | |
e656e369 | 2121 | |
25dbc73a AM |
2122 | return count; |
2123 | } | |
eea6121a | 2124 | |
25dbc73a AM |
2125 | static inline unsigned long |
2126 | apuinfo_list_element (unsigned long number) | |
2127 | { | |
2128 | apuinfo_list * entry; | |
e656e369 | 2129 | |
25dbc73a AM |
2130 | for (entry = head; |
2131 | entry && number --; | |
2132 | entry = entry->next) | |
2133 | ; | |
252b5132 | 2134 | |
25dbc73a AM |
2135 | return entry ? entry->value : 0; |
2136 | } | |
2137 | ||
2138 | static void | |
2139 | apuinfo_list_finish (void) | |
2140 | { | |
2141 | apuinfo_list *entry; | |
2142 | ||
2143 | for (entry = head; entry;) | |
252b5132 | 2144 | { |
25dbc73a AM |
2145 | apuinfo_list *next = entry->next; |
2146 | free (entry); | |
2147 | entry = next; | |
2148 | } | |
9abc968f | 2149 | |
25dbc73a AM |
2150 | head = NULL; |
2151 | } | |
9abc968f | 2152 | |
25dbc73a AM |
2153 | #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo" |
2154 | #define APUINFO_LABEL "APUinfo" | |
9abc968f | 2155 | |
25dbc73a AM |
2156 | /* Scan the input BFDs and create a linked list of |
2157 | the APUinfo values that will need to be emitted. */ | |
9abc968f | 2158 | |
25dbc73a AM |
2159 | static void |
2160 | ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info) | |
2161 | { | |
2162 | bfd *ibfd; | |
2163 | asection *asec; | |
deddc40b NS |
2164 | char *buffer = NULL; |
2165 | bfd_size_type largest_input_size = 0; | |
25dbc73a | 2166 | unsigned i; |
25dbc73a AM |
2167 | unsigned long length; |
2168 | const char *error_message = NULL; | |
9abc968f | 2169 | |
25dbc73a AM |
2170 | if (link_info == NULL) |
2171 | return; | |
9abc968f | 2172 | |
25dbc73a | 2173 | apuinfo_list_init (); |
252b5132 | 2174 | |
25dbc73a AM |
2175 | /* Read in the input sections contents. */ |
2176 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) | |
252b5132 | 2177 | { |
25dbc73a | 2178 | unsigned long datum; |
252b5132 | 2179 | |
25dbc73a AM |
2180 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
2181 | if (asec == NULL) | |
2182 | continue; | |
252b5132 | 2183 | |
deddc40b | 2184 | error_message = _("corrupt %s section in %B"); |
25dbc73a | 2185 | length = asec->size; |
deddc40b NS |
2186 | if (length < 20) |
2187 | goto fail; | |
2188 | ||
f2faa800 | 2189 | apuinfo_set = TRUE; |
deddc40b | 2190 | if (largest_input_size < asec->size) |
25dbc73a | 2191 | { |
deddc40b NS |
2192 | if (buffer) |
2193 | free (buffer); | |
2194 | largest_input_size = asec->size; | |
2195 | buffer = bfd_malloc (largest_input_size); | |
2196 | if (!buffer) | |
2197 | return; | |
25dbc73a | 2198 | } |
5b914448 | 2199 | |
25dbc73a | 2200 | if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0 |
deddc40b | 2201 | || (bfd_bread (buffer, length, ibfd) != length)) |
25dbc73a AM |
2202 | { |
2203 | error_message = _("unable to read in %s section from %B"); | |
2204 | goto fail; | |
2205 | } | |
252b5132 | 2206 | |
25dbc73a AM |
2207 | /* Verify the contents of the header. Note - we have to |
2208 | extract the values this way in order to allow for a | |
2209 | host whose endian-ness is different from the target. */ | |
deddc40b | 2210 | datum = bfd_get_32 (ibfd, buffer); |
25dbc73a AM |
2211 | if (datum != sizeof APUINFO_LABEL) |
2212 | goto fail; | |
252b5132 | 2213 | |
deddc40b | 2214 | datum = bfd_get_32 (ibfd, buffer + 8); |
25dbc73a AM |
2215 | if (datum != 0x2) |
2216 | goto fail; | |
252b5132 | 2217 | |
deddc40b | 2218 | if (strcmp (buffer + 12, APUINFO_LABEL) != 0) |
25dbc73a | 2219 | goto fail; |
252b5132 | 2220 | |
25dbc73a | 2221 | /* Get the number of bytes used for apuinfo entries. */ |
deddc40b | 2222 | datum = bfd_get_32 (ibfd, buffer + 4); |
25dbc73a AM |
2223 | if (datum + 20 != length) |
2224 | goto fail; | |
2225 | ||
25dbc73a AM |
2226 | /* Scan the apuinfo section, building a list of apuinfo numbers. */ |
2227 | for (i = 0; i < datum; i += 4) | |
deddc40b | 2228 | apuinfo_list_add (bfd_get_32 (ibfd, buffer + 20 + i)); |
252b5132 RH |
2229 | } |
2230 | ||
25dbc73a | 2231 | error_message = NULL; |
252b5132 | 2232 | |
f2faa800 | 2233 | if (apuinfo_set) |
deddc40b | 2234 | { |
f2faa800 NS |
2235 | /* Compute the size of the output section. */ |
2236 | unsigned num_entries = apuinfo_list_length (); | |
5b914448 | 2237 | |
deddc40b NS |
2238 | /* Set the output section size, if it exists. */ |
2239 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
f2faa800 | 2240 | |
deddc40b NS |
2241 | if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4)) |
2242 | { | |
2243 | ibfd = abfd; | |
2244 | error_message = _("warning: unable to set size of %s section in %B"); | |
2245 | } | |
2246 | } | |
25dbc73a AM |
2247 | |
2248 | fail: | |
deddc40b NS |
2249 | if (buffer) |
2250 | free (buffer); | |
25dbc73a AM |
2251 | |
2252 | if (error_message) | |
2253 | (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME); | |
2254 | } | |
252b5132 | 2255 | |
25dbc73a AM |
2256 | /* Prevent the output section from accumulating the input sections' |
2257 | contents. We have already stored this in our linked list structure. */ | |
252b5132 | 2258 | |
25dbc73a AM |
2259 | static bfd_boolean |
2260 | ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED, | |
c7b8f16e | 2261 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED, |
25dbc73a AM |
2262 | asection *asec, |
2263 | bfd_byte *contents ATTRIBUTE_UNUSED) | |
2264 | { | |
f2faa800 | 2265 | return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0; |
252b5132 RH |
2266 | } |
2267 | ||
25dbc73a AM |
2268 | /* Finally we can generate the output section. */ |
2269 | ||
2270 | static void | |
2271 | ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) | |
7619e7c7 | 2272 | { |
25dbc73a AM |
2273 | bfd_byte *buffer; |
2274 | asection *asec; | |
2275 | unsigned i; | |
2276 | unsigned num_entries; | |
2277 | bfd_size_type length; | |
7619e7c7 | 2278 | |
25dbc73a AM |
2279 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); |
2280 | if (asec == NULL) | |
2281 | return; | |
2282 | ||
f2faa800 | 2283 | if (!apuinfo_set) |
25dbc73a AM |
2284 | return; |
2285 | ||
2286 | length = asec->size; | |
2287 | if (length < 20) | |
2288 | return; | |
2289 | ||
2290 | buffer = bfd_malloc (length); | |
2291 | if (buffer == NULL) | |
7619e7c7 | 2292 | { |
25dbc73a AM |
2293 | (*_bfd_error_handler) |
2294 | (_("failed to allocate space for new APUinfo section.")); | |
2295 | return; | |
7619e7c7 | 2296 | } |
7619e7c7 | 2297 | |
25dbc73a AM |
2298 | /* Create the apuinfo header. */ |
2299 | num_entries = apuinfo_list_length (); | |
2300 | bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer); | |
2301 | bfd_put_32 (abfd, num_entries * 4, buffer + 4); | |
2302 | bfd_put_32 (abfd, 0x2, buffer + 8); | |
2303 | strcpy ((char *) buffer + 12, APUINFO_LABEL); | |
feee612b | 2304 | |
25dbc73a AM |
2305 | length = 20; |
2306 | for (i = 0; i < num_entries; i++) | |
feee612b | 2307 | { |
25dbc73a AM |
2308 | bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length); |
2309 | length += 4; | |
feee612b | 2310 | } |
feee612b | 2311 | |
25dbc73a AM |
2312 | if (length != asec->size) |
2313 | (*_bfd_error_handler) (_("failed to compute new APUinfo section.")); | |
252b5132 | 2314 | |
25dbc73a AM |
2315 | if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length)) |
2316 | (*_bfd_error_handler) (_("failed to install new APUinfo section.")); | |
252b5132 | 2317 | |
25dbc73a AM |
2318 | free (buffer); |
2319 | ||
2320 | apuinfo_list_finish (); | |
252b5132 | 2321 | } |
25dbc73a | 2322 | \f |
7382d32a | 2323 | static bfd_boolean |
c6dd29ce | 2324 | is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off) |
7382d32a | 2325 | { |
c6dd29ce | 2326 | bfd_byte buf[GLINK_ENTRY_SIZE]; |
7382d32a | 2327 | |
c6dd29ce | 2328 | if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE)) |
7382d32a AM |
2329 | return FALSE; |
2330 | ||
c6dd29ce AM |
2331 | return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11 |
2332 | && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11 | |
2333 | && bfd_get_32 (abfd, buf + 8) == MTCTR_11 | |
2334 | && bfd_get_32 (abfd, buf + 12) == BCTR); | |
7382d32a AM |
2335 | } |
2336 | ||
468392fb AM |
2337 | static bfd_boolean |
2338 | section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr) | |
2339 | { | |
2340 | bfd_vma vma = *(bfd_vma *) ptr; | |
2341 | return ((section->flags & SEC_ALLOC) != 0 | |
2342 | && section->vma <= vma | |
2343 | && vma < section->vma + section->size); | |
2344 | } | |
2345 | ||
2346 | static long | |
2347 | ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms, | |
2348 | long dynsymcount, asymbol **dynsyms, | |
2349 | asymbol **ret) | |
2350 | { | |
2351 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); | |
2352 | asection *plt, *relplt, *dynamic, *glink; | |
2353 | bfd_vma glink_vma = 0; | |
2354 | bfd_vma resolv_vma = 0; | |
2355 | bfd_vma stub_vma; | |
2356 | asymbol *s; | |
2357 | arelent *p; | |
2358 | long count, i; | |
2359 | size_t size; | |
2360 | char *names; | |
2361 | bfd_byte buf[4]; | |
2362 | ||
2363 | *ret = NULL; | |
2364 | ||
2365 | if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0) | |
2366 | return 0; | |
2367 | ||
2368 | if (dynsymcount <= 0) | |
2369 | return 0; | |
2370 | ||
2371 | relplt = bfd_get_section_by_name (abfd, ".rela.plt"); | |
2372 | if (relplt == NULL) | |
2373 | return 0; | |
2374 | ||
2375 | plt = bfd_get_section_by_name (abfd, ".plt"); | |
2376 | if (plt == NULL) | |
2377 | return 0; | |
2378 | ||
2379 | /* Call common code to handle old-style executable PLTs. */ | |
2380 | if (elf_section_flags (plt) & SHF_EXECINSTR) | |
2381 | return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms, | |
2382 | dynsymcount, dynsyms, ret); | |
2383 | ||
2384 | /* If this object was prelinked, the prelinker stored the address | |
2385 | of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */ | |
2386 | dynamic = bfd_get_section_by_name (abfd, ".dynamic"); | |
2387 | if (dynamic != NULL) | |
2388 | { | |
2389 | bfd_byte *dynbuf, *extdyn, *extdynend; | |
2390 | size_t extdynsize; | |
2391 | void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *); | |
2392 | ||
2393 | if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf)) | |
2394 | return -1; | |
2395 | ||
2396 | extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; | |
2397 | swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in; | |
2398 | ||
2399 | extdyn = dynbuf; | |
2400 | extdynend = extdyn + dynamic->size; | |
2401 | for (; extdyn < extdynend; extdyn += extdynsize) | |
2402 | { | |
2403 | Elf_Internal_Dyn dyn; | |
2404 | (*swap_dyn_in) (abfd, extdyn, &dyn); | |
2405 | ||
2406 | if (dyn.d_tag == DT_NULL) | |
2407 | break; | |
2408 | ||
2409 | if (dyn.d_tag == DT_PPC_GOT) | |
2410 | { | |
2411 | unsigned int g_o_t = dyn.d_un.d_val; | |
2412 | asection *got = bfd_get_section_by_name (abfd, ".got"); | |
2413 | if (got != NULL | |
2414 | && bfd_get_section_contents (abfd, got, buf, | |
2415 | g_o_t - got->vma + 4, 4)) | |
2416 | glink_vma = bfd_get_32 (abfd, buf); | |
2417 | break; | |
2418 | } | |
2419 | } | |
2420 | free (dynbuf); | |
2421 | } | |
2422 | ||
2423 | /* Otherwise we read the first plt entry. */ | |
2424 | if (glink_vma == 0) | |
2425 | { | |
2426 | if (bfd_get_section_contents (abfd, plt, buf, 0, 4)) | |
2427 | glink_vma = bfd_get_32 (abfd, buf); | |
2428 | } | |
2429 | ||
2430 | if (glink_vma == 0) | |
2431 | return 0; | |
2432 | ||
2433 | /* The .glink section usually does not survive the final | |
2434 | link; search for the section (usually .text) where the | |
2435 | glink stubs now reside. */ | |
2436 | glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma); | |
2437 | if (glink == NULL) | |
2438 | return 0; | |
2439 | ||
2440 | /* Determine glink PLT resolver by reading the relative branch | |
2441 | from the first glink stub. */ | |
2442 | if (bfd_get_section_contents (abfd, glink, buf, | |
2443 | glink_vma - glink->vma, 4)) | |
2444 | { | |
2445 | unsigned int insn = bfd_get_32 (abfd, buf); | |
2446 | ||
2447 | /* The first glink stub may either branch to the resolver ... */ | |
2448 | insn ^= B; | |
2449 | if ((insn & ~0x3fffffc) == 0) | |
2450 | resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000; | |
2451 | ||
2452 | /* ... or fall through a bunch of NOPs. */ | |
2453 | else if ((insn ^ B ^ NOP) == 0) | |
2454 | for (i = 4; | |
2455 | bfd_get_section_contents (abfd, glink, buf, | |
2456 | glink_vma - glink->vma + i, 4); | |
2457 | i += 4) | |
2458 | if (bfd_get_32 (abfd, buf) != NOP) | |
2459 | { | |
2460 | resolv_vma = glink_vma + i; | |
2461 | break; | |
2462 | } | |
2463 | } | |
2464 | ||
7382d32a AM |
2465 | count = relplt->size / sizeof (Elf32_External_Rela); |
2466 | stub_vma = glink_vma - (bfd_vma) count * 16; | |
2467 | /* If the stubs are those for -shared/-pie then we might have | |
2468 | multiple stubs for each plt entry. If that is the case then | |
2469 | there is no way to associate stubs with their plt entries short | |
2470 | of figuring out the GOT pointer value used in the stub. */ | |
c6dd29ce AM |
2471 | if (!is_nonpic_glink_stub (abfd, glink, |
2472 | glink_vma - GLINK_ENTRY_SIZE - glink->vma)) | |
7382d32a AM |
2473 | return 0; |
2474 | ||
468392fb AM |
2475 | slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; |
2476 | if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE)) | |
2477 | return -1; | |
2478 | ||
468392fb AM |
2479 | size = count * sizeof (asymbol); |
2480 | p = relplt->relocation; | |
2481 | for (i = 0; i < count; i++, p++) | |
e054468f AM |
2482 | { |
2483 | size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt"); | |
2484 | if (p->addend != 0) | |
2485 | size += sizeof ("+0x") - 1 + 8; | |
2486 | } | |
468392fb AM |
2487 | |
2488 | size += sizeof (asymbol) + sizeof ("__glink"); | |
2489 | ||
2490 | if (resolv_vma) | |
2491 | size += sizeof (asymbol) + sizeof ("__glink_PLTresolve"); | |
2492 | ||
2493 | s = *ret = bfd_malloc (size); | |
2494 | if (s == NULL) | |
2495 | return -1; | |
2496 | ||
2497 | names = (char *) (s + count + 1 + (resolv_vma != 0)); | |
2498 | p = relplt->relocation; | |
2499 | for (i = 0; i < count; i++, p++) | |
2500 | { | |
2501 | size_t len; | |
2502 | ||
2503 | *s = **p->sym_ptr_ptr; | |
2504 | /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since | |
2505 | we are defining a symbol, ensure one of them is set. */ | |
2506 | if ((s->flags & BSF_LOCAL) == 0) | |
2507 | s->flags |= BSF_GLOBAL; | |
6ba2a415 | 2508 | s->flags |= BSF_SYNTHETIC; |
468392fb AM |
2509 | s->section = glink; |
2510 | s->value = stub_vma - glink->vma; | |
2511 | s->name = names; | |
2512 | s->udata.p = NULL; | |
2513 | len = strlen ((*p->sym_ptr_ptr)->name); | |
2514 | memcpy (names, (*p->sym_ptr_ptr)->name, len); | |
2515 | names += len; | |
e054468f AM |
2516 | if (p->addend != 0) |
2517 | { | |
2518 | memcpy (names, "+0x", sizeof ("+0x") - 1); | |
2519 | names += sizeof ("+0x") - 1; | |
2520 | bfd_sprintf_vma (abfd, names, p->addend); | |
2521 | names += strlen (names); | |
2522 | } | |
468392fb AM |
2523 | memcpy (names, "@plt", sizeof ("@plt")); |
2524 | names += sizeof ("@plt"); | |
2525 | ++s; | |
2526 | stub_vma += 16; | |
2527 | } | |
2528 | ||
2529 | /* Add a symbol at the start of the glink branch table. */ | |
86a4952b | 2530 | memset (s, 0, sizeof *s); |
468392fb | 2531 | s->the_bfd = abfd; |
6ba2a415 | 2532 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
2533 | s->section = glink; |
2534 | s->value = glink_vma - glink->vma; | |
2535 | s->name = names; | |
2536 | memcpy (names, "__glink", sizeof ("__glink")); | |
2537 | names += sizeof ("__glink"); | |
2538 | s++; | |
2539 | count++; | |
2540 | ||
2541 | if (resolv_vma) | |
2542 | { | |
2543 | /* Add a symbol for the glink PLT resolver. */ | |
86a4952b | 2544 | memset (s, 0, sizeof *s); |
468392fb | 2545 | s->the_bfd = abfd; |
6ba2a415 | 2546 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
2547 | s->section = glink; |
2548 | s->value = resolv_vma - glink->vma; | |
2549 | s->name = names; | |
2550 | memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve")); | |
2551 | names += sizeof ("__glink_PLTresolve"); | |
2552 | s++; | |
2553 | count++; | |
2554 | } | |
2555 | ||
2556 | return count; | |
2557 | } | |
2558 | \f | |
25dbc73a AM |
2559 | /* The following functions are specific to the ELF linker, while |
2560 | functions above are used generally. They appear in this file more | |
2561 | or less in the order in which they are called. eg. | |
2562 | ppc_elf_check_relocs is called early in the link process, | |
2563 | ppc_elf_finish_dynamic_sections is one of the last functions | |
2564 | called. */ | |
252b5132 | 2565 | |
a6aa5195 | 2566 | /* Track PLT entries needed for a given symbol. We might need more |
a877a2b6 | 2567 | than one glink entry per symbol when generating a pic binary. */ |
a6aa5195 AM |
2568 | struct plt_entry |
2569 | { | |
2570 | struct plt_entry *next; | |
2571 | ||
2572 | /* -fPIC uses multiple GOT sections, one per file, called ".got2". | |
2573 | This field stores the offset into .got2 used to initialise the | |
a877a2b6 AM |
2574 | GOT pointer reg. It will always be at least 32768. (Current |
2575 | gcc always uses an offset of 32768, but ld -r will pack .got2 | |
2576 | sections together resulting in larger offsets). */ | |
a6aa5195 AM |
2577 | bfd_vma addend; |
2578 | ||
2579 | /* The .got2 section. */ | |
2580 | asection *sec; | |
2581 | ||
2582 | /* PLT refcount or offset. */ | |
2583 | union | |
2584 | { | |
2585 | bfd_signed_vma refcount; | |
2586 | bfd_vma offset; | |
2587 | } plt; | |
2588 | ||
2589 | /* .glink stub offset. */ | |
2590 | bfd_vma glink_offset; | |
2591 | }; | |
2592 | ||
1d483afe | 2593 | /* Of those relocs that might be copied as dynamic relocs, this function |
25dbc73a AM |
2594 | selects those that must be copied when linking a shared library, |
2595 | even when the symbol is local. */ | |
252b5132 | 2596 | |
1d483afe AM |
2597 | static int |
2598 | must_be_dyn_reloc (struct bfd_link_info *info, | |
2599 | enum elf_ppc_reloc_type r_type) | |
2600 | { | |
2601 | switch (r_type) | |
2602 | { | |
2603 | default: | |
2604 | return 1; | |
2605 | ||
2606 | case R_PPC_REL24: | |
2607 | case R_PPC_REL14: | |
2608 | case R_PPC_REL14_BRTAKEN: | |
2609 | case R_PPC_REL14_BRNTAKEN: | |
2610 | case R_PPC_REL32: | |
2611 | return 0; | |
2612 | ||
2613 | case R_PPC_TPREL32: | |
2614 | case R_PPC_TPREL16: | |
2615 | case R_PPC_TPREL16_LO: | |
2616 | case R_PPC_TPREL16_HI: | |
2617 | case R_PPC_TPREL16_HA: | |
2618 | return !info->executable; | |
2619 | } | |
2620 | } | |
252b5132 | 2621 | |
25dbc73a AM |
2622 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2623 | copying dynamic variables from a shared lib into an app's dynbss | |
2624 | section, and instead use a dynamic relocation to point into the | |
2625 | shared lib. */ | |
2626 | #define ELIMINATE_COPY_RELOCS 1 | |
252b5132 | 2627 | |
25dbc73a | 2628 | /* PPC ELF linker hash entry. */ |
252b5132 | 2629 | |
25dbc73a AM |
2630 | struct ppc_elf_link_hash_entry |
2631 | { | |
2632 | struct elf_link_hash_entry elf; | |
252b5132 | 2633 | |
25dbc73a AM |
2634 | /* If this symbol is used in the linker created sections, the processor |
2635 | specific backend uses this field to map the field into the offset | |
2636 | from the beginning of the section. */ | |
2637 | elf_linker_section_pointers_t *linker_section_pointer; | |
252b5132 | 2638 | |
25dbc73a | 2639 | /* Track dynamic relocs copied for this symbol. */ |
6061a67d | 2640 | struct elf_dyn_relocs *dyn_relocs; |
252b5132 | 2641 | |
25dbc73a AM |
2642 | /* Contexts in which symbol is used in the GOT (or TOC). |
2643 | TLS_GD .. TLS_TLS bits are or'd into the mask as the | |
2644 | corresponding relocs are encountered during check_relocs. | |
2645 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2646 | indicate the corresponding GOT entry type is not needed. */ | |
2647 | #define TLS_GD 1 /* GD reloc. */ | |
2648 | #define TLS_LD 2 /* LD reloc. */ | |
2649 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2650 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2651 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2652 | #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */ | |
e054468f | 2653 | #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */ |
25dbc73a | 2654 | char tls_mask; |
4dc4a9a5 DJ |
2655 | |
2656 | /* Nonzero if we have seen a small data relocation referring to this | |
2657 | symbol. */ | |
2658 | unsigned char has_sda_refs; | |
25dbc73a | 2659 | }; |
252b5132 | 2660 | |
25dbc73a AM |
2661 | #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent)) |
2662 | ||
2663 | /* PPC ELF linker hash table. */ | |
2664 | ||
2665 | struct ppc_elf_link_hash_table | |
2666 | { | |
2667 | struct elf_link_hash_table elf; | |
2668 | ||
2669 | /* Short-cuts to get to dynamic linker sections. */ | |
2670 | asection *got; | |
2671 | asection *relgot; | |
d7128ce4 | 2672 | asection *glink; |
25dbc73a AM |
2673 | asection *plt; |
2674 | asection *relplt; | |
e054468f AM |
2675 | asection *iplt; |
2676 | asection *reliplt; | |
25dbc73a AM |
2677 | asection *dynbss; |
2678 | asection *relbss; | |
2679 | asection *dynsbss; | |
2680 | asection *relsbss; | |
c9a2f333 | 2681 | elf_linker_section_t sdata[2]; |
25dbc73a | 2682 | asection *sbss; |
6177242a | 2683 | asection *glink_eh_frame; |
25dbc73a | 2684 | |
016687f8 AM |
2685 | /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */ |
2686 | asection *srelplt2; | |
2687 | ||
2688 | /* The .got.plt section (VxWorks only)*/ | |
2689 | asection *sgotplt; | |
2690 | ||
1d483afe | 2691 | /* Shortcut to __tls_get_addr. */ |
25dbc73a | 2692 | struct elf_link_hash_entry *tls_get_addr; |
252b5132 | 2693 | |
016687f8 AM |
2694 | /* The bfd that forced an old-style PLT. */ |
2695 | bfd *old_bfd; | |
5b914448 | 2696 | |
25dbc73a AM |
2697 | /* TLS local dynamic got entry handling. */ |
2698 | union { | |
2699 | bfd_signed_vma refcount; | |
2700 | bfd_vma offset; | |
2701 | } tlsld_got; | |
252b5132 | 2702 | |
c6dd29ce | 2703 | /* Offset of branch table to PltResolve function in glink. */ |
d7128ce4 AM |
2704 | bfd_vma glink_pltresolve; |
2705 | ||
3b36f7e6 AM |
2706 | /* Size of reserved GOT entries. */ |
2707 | unsigned int got_header_size; | |
2708 | /* Non-zero if allocating the header left a gap. */ | |
2709 | unsigned int got_gap; | |
2710 | ||
4a3dc543 RS |
2711 | /* The type of PLT we have chosen to use. */ |
2712 | enum ppc_elf_plt_type plt_type; | |
2713 | ||
0ba07910 AM |
2714 | /* Set if we should emit symbols for stubs. */ |
2715 | unsigned int emit_stub_syms:1; | |
2716 | ||
a7f2871e AM |
2717 | /* Set if __tls_get_addr optimization should not be done. */ |
2718 | unsigned int no_tls_get_addr_opt:1; | |
2719 | ||
9d8504b1 | 2720 | /* True if the target system is VxWorks. */ |
016687f8 | 2721 | unsigned int is_vxworks:1; |
9d8504b1 PB |
2722 | |
2723 | /* The size of PLT entries. */ | |
2724 | int plt_entry_size; | |
2725 | /* The distance between adjacent PLT slots. */ | |
2726 | int plt_slot_size; | |
2727 | /* The size of the first PLT entry. */ | |
2728 | int plt_initial_entry_size; | |
016687f8 | 2729 | |
87d72d41 AM |
2730 | /* Small local sym cache. */ |
2731 | struct sym_cache sym_cache; | |
25dbc73a | 2732 | }; |
252b5132 | 2733 | |
b0dddeec AM |
2734 | /* Rename some of the generic section flags to better document how they |
2735 | are used here. */ | |
2736 | ||
2737 | /* Nonzero if this section has TLS related relocations. */ | |
2738 | #define has_tls_reloc sec_flg0 | |
2739 | ||
2740 | /* Nonzero if this section has a call to __tls_get_addr. */ | |
2741 | #define has_tls_get_addr_call sec_flg1 | |
2742 | ||
25dbc73a | 2743 | /* Get the PPC ELF linker hash table from a link_info structure. */ |
252b5132 | 2744 | |
25dbc73a | 2745 | #define ppc_elf_hash_table(p) \ |
4dfe6ac6 NC |
2746 | (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ |
2747 | == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL) | |
252b5132 | 2748 | |
25dbc73a | 2749 | /* Create an entry in a PPC ELF linker hash table. */ |
252b5132 | 2750 | |
25dbc73a AM |
2751 | static struct bfd_hash_entry * |
2752 | ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry, | |
2753 | struct bfd_hash_table *table, | |
2754 | const char *string) | |
252b5132 | 2755 | { |
25dbc73a AM |
2756 | /* Allocate the structure if it has not already been allocated by a |
2757 | subclass. */ | |
2758 | if (entry == NULL) | |
2759 | { | |
2760 | entry = bfd_hash_allocate (table, | |
2761 | sizeof (struct ppc_elf_link_hash_entry)); | |
2762 | if (entry == NULL) | |
2763 | return entry; | |
2764 | } | |
252b5132 | 2765 | |
25dbc73a AM |
2766 | /* Call the allocation method of the superclass. */ |
2767 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2768 | if (entry != NULL) | |
2769 | { | |
2770 | ppc_elf_hash_entry (entry)->linker_section_pointer = NULL; | |
2771 | ppc_elf_hash_entry (entry)->dyn_relocs = NULL; | |
2772 | ppc_elf_hash_entry (entry)->tls_mask = 0; | |
5240d94d | 2773 | ppc_elf_hash_entry (entry)->has_sda_refs = 0; |
25dbc73a | 2774 | } |
252b5132 | 2775 | |
25dbc73a | 2776 | return entry; |
252b5132 | 2777 | } |
3dab13f6 | 2778 | |
25dbc73a | 2779 | /* Create a PPC ELF linker hash table. */ |
3dab13f6 | 2780 | |
25dbc73a AM |
2781 | static struct bfd_link_hash_table * |
2782 | ppc_elf_link_hash_table_create (bfd *abfd) | |
3dab13f6 | 2783 | { |
25dbc73a | 2784 | struct ppc_elf_link_hash_table *ret; |
3dab13f6 | 2785 | |
25dbc73a AM |
2786 | ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table)); |
2787 | if (ret == NULL) | |
2788 | return NULL; | |
3dab13f6 | 2789 | |
66eb6687 AM |
2790 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, |
2791 | ppc_elf_link_hash_newfunc, | |
4dfe6ac6 NC |
2792 | sizeof (struct ppc_elf_link_hash_entry), |
2793 | PPC32_ELF_DATA)) | |
3dab13f6 | 2794 | { |
25dbc73a AM |
2795 | free (ret); |
2796 | return NULL; | |
2797 | } | |
58111eb7 | 2798 | |
a6aa5195 AM |
2799 | ret->elf.init_plt_refcount.refcount = 0; |
2800 | ret->elf.init_plt_refcount.glist = NULL; | |
2801 | ret->elf.init_plt_offset.offset = 0; | |
2802 | ret->elf.init_plt_offset.glist = NULL; | |
2803 | ||
c9a2f333 AM |
2804 | ret->sdata[0].name = ".sdata"; |
2805 | ret->sdata[0].sym_name = "_SDA_BASE_"; | |
2806 | ret->sdata[0].bss_name = ".sbss"; | |
2807 | ||
2808 | ret->sdata[1].name = ".sdata2"; | |
2809 | ret->sdata[1].sym_name = "_SDA2_BASE_"; | |
2810 | ret->sdata[1].bss_name = ".sbss2"; | |
2811 | ||
9d8504b1 PB |
2812 | ret->plt_entry_size = 12; |
2813 | ret->plt_slot_size = 8; | |
2814 | ret->plt_initial_entry_size = 72; | |
9d8504b1 | 2815 | |
25dbc73a AM |
2816 | return &ret->elf.root; |
2817 | } | |
3dab13f6 | 2818 | |
9d8504b1 | 2819 | /* Create .got and the related sections. */ |
3dab13f6 | 2820 | |
25dbc73a AM |
2821 | static bfd_boolean |
2822 | ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info) | |
2823 | { | |
2824 | struct ppc_elf_link_hash_table *htab; | |
2825 | asection *s; | |
2826 | flagword flags; | |
3dab13f6 | 2827 | |
25dbc73a AM |
2828 | if (!_bfd_elf_create_got_section (abfd, info)) |
2829 | return FALSE; | |
3dab13f6 | 2830 | |
25dbc73a AM |
2831 | htab = ppc_elf_hash_table (info); |
2832 | htab->got = s = bfd_get_section_by_name (abfd, ".got"); | |
2833 | if (s == NULL) | |
2834 | abort (); | |
3dab13f6 | 2835 | |
9d8504b1 PB |
2836 | if (htab->is_vxworks) |
2837 | { | |
2838 | htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt"); | |
2839 | if (!htab->sgotplt) | |
2840 | abort (); | |
2841 | } | |
2842 | else | |
2843 | { | |
2844 | /* The powerpc .got has a blrl instruction in it. Mark it | |
2845 | executable. */ | |
2846 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | |
2847 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2848 | if (!bfd_set_section_flags (abfd, s, flags)) | |
2849 | return FALSE; | |
2850 | } | |
3dab13f6 | 2851 | |
64e77c6d L |
2852 | htab->relgot = bfd_get_section_by_name (abfd, ".rela.got"); |
2853 | if (!htab->relgot) | |
2854 | abort (); | |
3dab13f6 | 2855 | |
25dbc73a AM |
2856 | return TRUE; |
2857 | } | |
3dab13f6 | 2858 | |
e054468f AM |
2859 | static bfd_boolean |
2860 | ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info) | |
2861 | { | |
2862 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
2863 | asection *s; | |
2864 | flagword flags; | |
2865 | ||
2866 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | |
2867 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2868 | s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags); | |
2869 | htab->glink = s; | |
2870 | if (s == NULL | |
2871 | || !bfd_set_section_alignment (abfd, s, 4)) | |
2872 | return FALSE; | |
2873 | ||
6177242a AM |
2874 | if (!info->no_ld_generated_unwind_info) |
2875 | { | |
2876 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | |
2877 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2878 | s = bfd_make_section_anyway_with_flags (abfd, ".eh_frame", flags); | |
2879 | htab->glink_eh_frame = s; | |
2880 | if (s == NULL | |
2881 | || !bfd_set_section_alignment (abfd, s, 2)) | |
2882 | return FALSE; | |
2883 | } | |
2884 | ||
e054468f AM |
2885 | flags = SEC_ALLOC | SEC_LINKER_CREATED; |
2886 | s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags); | |
2887 | htab->iplt = s; | |
2888 | if (s == NULL | |
2889 | || !bfd_set_section_alignment (abfd, s, 4)) | |
2890 | return FALSE; | |
2891 | ||
2892 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | |
2893 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2894 | s = bfd_make_section_with_flags (abfd, ".rela.iplt", flags); | |
2895 | htab->reliplt = s; | |
2896 | if (s == NULL | |
2897 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
2898 | return FALSE; | |
2899 | return TRUE; | |
2900 | } | |
2901 | ||
25dbc73a AM |
2902 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
2903 | to output sections (just like _bfd_elf_create_dynamic_sections has | |
2904 | to create .dynbss and .rela.bss). */ | |
3dab13f6 | 2905 | |
25dbc73a AM |
2906 | static bfd_boolean |
2907 | ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |
2908 | { | |
2909 | struct ppc_elf_link_hash_table *htab; | |
2910 | asection *s; | |
2911 | flagword flags; | |
3dab13f6 | 2912 | |
25dbc73a | 2913 | htab = ppc_elf_hash_table (info); |
3dab13f6 | 2914 | |
25dbc73a AM |
2915 | if (htab->got == NULL |
2916 | && !ppc_elf_create_got (abfd, info)) | |
3dab13f6 AM |
2917 | return FALSE; |
2918 | ||
25dbc73a AM |
2919 | if (!_bfd_elf_create_dynamic_sections (abfd, info)) |
2920 | return FALSE; | |
3dab13f6 | 2921 | |
e054468f AM |
2922 | if (htab->glink == NULL |
2923 | && !ppc_elf_create_glink (abfd, info)) | |
d7128ce4 | 2924 | return FALSE; |
3dab13f6 | 2925 | |
25dbc73a | 2926 | htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss"); |
3b36f7e6 AM |
2927 | s = bfd_make_section_with_flags (abfd, ".dynsbss", |
2928 | SEC_ALLOC | SEC_LINKER_CREATED); | |
2929 | htab->dynsbss = s; | |
3496cb2a | 2930 | if (s == NULL) |
25dbc73a | 2931 | return FALSE; |
3dab13f6 | 2932 | |
25dbc73a AM |
2933 | if (! info->shared) |
2934 | { | |
2935 | htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss"); | |
e054468f AM |
2936 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS |
2937 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
d7128ce4 | 2938 | s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags); |
3b36f7e6 | 2939 | htab->relsbss = s; |
25dbc73a | 2940 | if (s == NULL |
25dbc73a AM |
2941 | || ! bfd_set_section_alignment (abfd, s, 2)) |
2942 | return FALSE; | |
2943 | } | |
3dab13f6 | 2944 | |
711de32c RS |
2945 | if (htab->is_vxworks |
2946 | && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2)) | |
2947 | return FALSE; | |
9d8504b1 | 2948 | |
25dbc73a AM |
2949 | htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt"); |
2950 | htab->plt = s = bfd_get_section_by_name (abfd, ".plt"); | |
2951 | if (s == NULL) | |
2952 | abort (); | |
3dab13f6 | 2953 | |
3b36f7e6 | 2954 | flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED; |
4a3dc543 RS |
2955 | if (htab->plt_type == PLT_VXWORKS) |
2956 | /* The VxWorks PLT is a loaded section with contents. */ | |
2957 | flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY; | |
25dbc73a AM |
2958 | return bfd_set_section_flags (abfd, s, flags); |
2959 | } | |
3dab13f6 | 2960 | |
25dbc73a | 2961 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
58111eb7 | 2962 | |
25dbc73a | 2963 | static void |
fcfa13d2 | 2964 | ppc_elf_copy_indirect_symbol (struct bfd_link_info *info, |
25dbc73a AM |
2965 | struct elf_link_hash_entry *dir, |
2966 | struct elf_link_hash_entry *ind) | |
2967 | { | |
2968 | struct ppc_elf_link_hash_entry *edir, *eind; | |
3dab13f6 | 2969 | |
25dbc73a AM |
2970 | edir = (struct ppc_elf_link_hash_entry *) dir; |
2971 | eind = (struct ppc_elf_link_hash_entry *) ind; | |
3dab13f6 | 2972 | |
c79d6685 AM |
2973 | edir->tls_mask |= eind->tls_mask; |
2974 | edir->has_sda_refs |= eind->has_sda_refs; | |
2975 | ||
2976 | /* If called to transfer flags for a weakdef during processing | |
2977 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |
2978 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
2979 | if (!(ELIMINATE_COPY_RELOCS | |
2980 | && eind->elf.root.type != bfd_link_hash_indirect | |
2981 | && edir->elf.dynamic_adjusted)) | |
2982 | edir->elf.non_got_ref |= eind->elf.non_got_ref; | |
2983 | ||
2984 | edir->elf.ref_dynamic |= eind->elf.ref_dynamic; | |
2985 | edir->elf.ref_regular |= eind->elf.ref_regular; | |
2986 | edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak; | |
2987 | edir->elf.needs_plt |= eind->elf.needs_plt; | |
2988 | edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed; | |
2989 | ||
2990 | /* If we were called to copy over info for a weak sym, that's all. */ | |
2991 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
2992 | return; | |
2993 | ||
25dbc73a AM |
2994 | if (eind->dyn_relocs != NULL) |
2995 | { | |
2996 | if (edir->dyn_relocs != NULL) | |
3dab13f6 | 2997 | { |
6061a67d AM |
2998 | struct elf_dyn_relocs **pp; |
2999 | struct elf_dyn_relocs *p; | |
3dab13f6 | 3000 | |
fcfa13d2 | 3001 | /* Add reloc counts against the indirect sym to the direct sym |
25dbc73a AM |
3002 | list. Merge any entries against the same section. */ |
3003 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3dab13f6 | 3004 | { |
6061a67d | 3005 | struct elf_dyn_relocs *q; |
25dbc73a AM |
3006 | |
3007 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3008 | if (q->sec == p->sec) | |
3009 | { | |
3010 | q->pc_count += p->pc_count; | |
3011 | q->count += p->count; | |
3012 | *pp = p->next; | |
3013 | break; | |
3014 | } | |
3015 | if (q == NULL) | |
3016 | pp = &p->next; | |
3dab13f6 | 3017 | } |
25dbc73a | 3018 | *pp = edir->dyn_relocs; |
3dab13f6 | 3019 | } |
25dbc73a AM |
3020 | |
3021 | edir->dyn_relocs = eind->dyn_relocs; | |
3022 | eind->dyn_relocs = NULL; | |
3dab13f6 | 3023 | } |
3dab13f6 | 3024 | |
a6aa5195 AM |
3025 | /* Copy over the GOT refcount entries that we may have already seen to |
3026 | the symbol which just became indirect. */ | |
fcfa13d2 AM |
3027 | edir->elf.got.refcount += eind->elf.got.refcount; |
3028 | eind->elf.got.refcount = 0; | |
a6aa5195 AM |
3029 | |
3030 | /* And plt entries. */ | |
3031 | if (eind->elf.plt.plist != NULL) | |
3032 | { | |
3033 | if (edir->elf.plt.plist != NULL) | |
3034 | { | |
3035 | struct plt_entry **entp; | |
3036 | struct plt_entry *ent; | |
3037 | ||
3038 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3039 | { | |
3040 | struct plt_entry *dent; | |
3041 | ||
3042 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3043 | if (dent->sec == ent->sec && dent->addend == ent->addend) | |
3044 | { | |
3045 | dent->plt.refcount += ent->plt.refcount; | |
3046 | *entp = ent->next; | |
3047 | break; | |
3048 | } | |
3049 | if (dent == NULL) | |
3050 | entp = &ent->next; | |
3051 | } | |
3052 | *entp = edir->elf.plt.plist; | |
3053 | } | |
3054 | ||
3055 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3056 | eind->elf.plt.plist = NULL; | |
3057 | } | |
3058 | ||
fcfa13d2 | 3059 | if (eind->elf.dynindx != -1) |
25dbc73a | 3060 | { |
fcfa13d2 AM |
3061 | if (edir->elf.dynindx != -1) |
3062 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
3063 | edir->elf.dynstr_index); | |
a6aa5195 AM |
3064 | edir->elf.dynindx = eind->elf.dynindx; |
3065 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3066 | eind->elf.dynindx = -1; | |
3067 | eind->elf.dynstr_index = 0; | |
25dbc73a | 3068 | } |
25dbc73a | 3069 | } |
3dab13f6 | 3070 | |
25dbc73a AM |
3071 | /* Hook called by the linker routine which adds symbols from an object |
3072 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
58111eb7 | 3073 | |
25dbc73a AM |
3074 | static bfd_boolean |
3075 | ppc_elf_add_symbol_hook (bfd *abfd, | |
3076 | struct bfd_link_info *info, | |
3077 | Elf_Internal_Sym *sym, | |
3078 | const char **namep ATTRIBUTE_UNUSED, | |
3079 | flagword *flagsp ATTRIBUTE_UNUSED, | |
3080 | asection **secp, | |
3081 | bfd_vma *valp) | |
3082 | { | |
3083 | if (sym->st_shndx == SHN_COMMON | |
3084 | && !info->relocatable | |
0c8d6e5c AM |
3085 | && is_ppc_elf (info->output_bfd) |
3086 | && sym->st_size <= elf_gp_size (abfd)) | |
25dbc73a AM |
3087 | { |
3088 | /* Common symbols less than or equal to -G nn bytes are automatically | |
3089 | put into .sbss. */ | |
3090 | struct ppc_elf_link_hash_table *htab; | |
3dab13f6 | 3091 | |
25dbc73a AM |
3092 | htab = ppc_elf_hash_table (info); |
3093 | if (htab->sbss == NULL) | |
3094 | { | |
644285ef | 3095 | flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED; |
3dab13f6 | 3096 | |
644285ef AM |
3097 | if (!htab->elf.dynobj) |
3098 | htab->elf.dynobj = abfd; | |
3099 | ||
3496cb2a L |
3100 | htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
3101 | ".sbss", | |
3102 | flags); | |
3103 | if (htab->sbss == NULL) | |
25dbc73a | 3104 | return FALSE; |
3dab13f6 | 3105 | } |
3dab13f6 | 3106 | |
25dbc73a AM |
3107 | *secp = htab->sbss; |
3108 | *valp = sym->st_size; | |
3109 | } | |
3dab13f6 | 3110 | |
c16153ae | 3111 | if ((abfd->flags & DYNAMIC) == 0 |
f64b2e8d NC |
3112 | && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC |
3113 | || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) | |
3114 | elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; | |
e054468f | 3115 | |
25dbc73a | 3116 | return TRUE; |
3dab13f6 AM |
3117 | } |
3118 | \f | |
046183de | 3119 | static bfd_boolean |
bd6c6e2b | 3120 | create_sdata_sym (struct bfd_link_info *info, elf_linker_section_t *lsect) |
046183de | 3121 | { |
bd6c6e2b AM |
3122 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); |
3123 | ||
046183de AM |
3124 | lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name, |
3125 | TRUE, FALSE, TRUE); | |
3126 | if (lsect->sym == NULL) | |
3127 | return FALSE; | |
3128 | if (lsect->sym->root.type == bfd_link_hash_new) | |
3129 | lsect->sym->non_elf = 0; | |
3130 | lsect->sym->ref_regular = 1; | |
bd6c6e2b | 3131 | _bfd_elf_link_hash_hide_symbol (info, lsect->sym, TRUE); |
046183de AM |
3132 | return TRUE; |
3133 | } | |
3134 | ||
c9a2f333 | 3135 | /* Create a special linker section. */ |
25dbc73a | 3136 | |
c9a2f333 | 3137 | static bfd_boolean |
55fd94b0 AM |
3138 | ppc_elf_create_linker_section (bfd *abfd, |
3139 | struct bfd_link_info *info, | |
c9a2f333 AM |
3140 | flagword flags, |
3141 | elf_linker_section_t *lsect) | |
252b5132 | 3142 | { |
58111eb7 | 3143 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); |
c9a2f333 | 3144 | asection *s; |
58111eb7 | 3145 | |
c9a2f333 AM |
3146 | flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
3147 | | SEC_LINKER_CREATED); | |
58111eb7 AM |
3148 | |
3149 | /* Record the first bfd that needs the special sections. */ | |
3150 | if (!htab->elf.dynobj) | |
3151 | htab->elf.dynobj = abfd; | |
3152 | ||
3496cb2a L |
3153 | s = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
3154 | lsect->name, | |
3155 | flags); | |
76750a2f | 3156 | if (s == NULL |
76750a2f | 3157 | || !bfd_set_section_alignment (htab->elf.dynobj, s, 2)) |
c9a2f333 | 3158 | return FALSE; |
76750a2f | 3159 | lsect->section = s; |
58111eb7 | 3160 | |
bd6c6e2b | 3161 | return create_sdata_sym (info, lsect); |
252b5132 | 3162 | } |
252b5132 | 3163 | |
25dbc73a AM |
3164 | /* Find a linker generated pointer with a given addend and type. */ |
3165 | ||
3166 | static elf_linker_section_pointers_t * | |
3167 | elf_find_pointer_linker_section | |
3168 | (elf_linker_section_pointers_t *linker_pointers, | |
3169 | bfd_vma addend, | |
3170 | elf_linker_section_t *lsect) | |
252b5132 | 3171 | { |
25dbc73a AM |
3172 | for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next) |
3173 | if (lsect == linker_pointers->lsect && addend == linker_pointers->addend) | |
3174 | return linker_pointers; | |
252b5132 | 3175 | |
25dbc73a AM |
3176 | return NULL; |
3177 | } | |
3178 | ||
3179 | /* Allocate a pointer to live in a linker created section. */ | |
3180 | ||
3181 | static bfd_boolean | |
3182 | elf_create_pointer_linker_section (bfd *abfd, | |
25dbc73a AM |
3183 | elf_linker_section_t *lsect, |
3184 | struct elf_link_hash_entry *h, | |
3185 | const Elf_Internal_Rela *rel) | |
3186 | { | |
3187 | elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL; | |
3188 | elf_linker_section_pointers_t *linker_section_ptr; | |
3189 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
3190 | bfd_size_type amt; | |
3191 | ||
3192 | BFD_ASSERT (lsect != NULL); | |
3193 | ||
3194 | /* Is this a global symbol? */ | |
3195 | if (h != NULL) | |
3196 | { | |
3197 | struct ppc_elf_link_hash_entry *eh; | |
3198 | ||
3199 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3200 | eh = (struct ppc_elf_link_hash_entry *) h; | |
3201 | if (elf_find_pointer_linker_section (eh->linker_section_pointer, | |
3202 | rel->r_addend, | |
3203 | lsect)) | |
3204 | return TRUE; | |
3205 | ||
3206 | ptr_linker_section_ptr = &eh->linker_section_pointer; | |
25dbc73a AM |
3207 | } |
3208 | else | |
3209 | { | |
0c8d6e5c | 3210 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 3211 | |
25dbc73a AM |
3212 | /* Allocation of a pointer to a local symbol. */ |
3213 | elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); | |
3214 | ||
3215 | /* Allocate a table to hold the local symbols if first time. */ | |
3216 | if (!ptr) | |
3217 | { | |
0ffa91dd | 3218 | unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info; |
25dbc73a AM |
3219 | |
3220 | amt = num_symbols; | |
3221 | amt *= sizeof (elf_linker_section_pointers_t *); | |
3222 | ptr = bfd_zalloc (abfd, amt); | |
3223 | ||
3224 | if (!ptr) | |
3225 | return FALSE; | |
3226 | ||
3227 | elf_local_ptr_offsets (abfd) = ptr; | |
3228 | } | |
3229 | ||
3230 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3231 | if (elf_find_pointer_linker_section (ptr[r_symndx], | |
3232 | rel->r_addend, | |
3233 | lsect)) | |
3234 | return TRUE; | |
252b5132 | 3235 | |
25dbc73a | 3236 | ptr_linker_section_ptr = &ptr[r_symndx]; |
25dbc73a | 3237 | } |
41fcb14e | 3238 | |
25dbc73a AM |
3239 | /* Allocate space for a pointer in the linker section, and allocate |
3240 | a new pointer record from internal memory. */ | |
3241 | BFD_ASSERT (ptr_linker_section_ptr != NULL); | |
3242 | amt = sizeof (elf_linker_section_pointers_t); | |
3243 | linker_section_ptr = bfd_alloc (abfd, amt); | |
41fcb14e | 3244 | |
25dbc73a | 3245 | if (!linker_section_ptr) |
7619e7c7 | 3246 | return FALSE; |
41fcb14e | 3247 | |
25dbc73a AM |
3248 | linker_section_ptr->next = *ptr_linker_section_ptr; |
3249 | linker_section_ptr->addend = rel->r_addend; | |
3250 | linker_section_ptr->lsect = lsect; | |
25dbc73a | 3251 | *ptr_linker_section_ptr = linker_section_ptr; |
41fcb14e | 3252 | |
25dbc73a AM |
3253 | linker_section_ptr->offset = lsect->section->size; |
3254 | lsect->section->size += 4; | |
7619e7c7 | 3255 | |
25dbc73a AM |
3256 | #ifdef DEBUG |
3257 | fprintf (stderr, | |
3258 | "Create pointer in linker section %s, offset = %ld, section size = %ld\n", | |
3259 | lsect->name, (long) linker_section_ptr->offset, | |
3260 | (long) lsect->section->size); | |
3261 | #endif | |
7619e7c7 AM |
3262 | |
3263 | return TRUE; | |
41fcb14e AM |
3264 | } |
3265 | ||
e054468f | 3266 | static struct plt_entry ** |
25dbc73a AM |
3267 | update_local_sym_info (bfd *abfd, |
3268 | Elf_Internal_Shdr *symtab_hdr, | |
3269 | unsigned long r_symndx, | |
3270 | int tls_type) | |
252b5132 | 3271 | { |
25dbc73a | 3272 | bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd); |
e054468f | 3273 | struct plt_entry **local_plt; |
25dbc73a | 3274 | char *local_got_tls_masks; |
252b5132 | 3275 | |
25dbc73a | 3276 | if (local_got_refcounts == NULL) |
252b5132 | 3277 | { |
25dbc73a AM |
3278 | bfd_size_type size = symtab_hdr->sh_info; |
3279 | ||
e054468f AM |
3280 | size *= (sizeof (*local_got_refcounts) |
3281 | + sizeof (*local_plt) | |
3282 | + sizeof (*local_got_tls_masks)); | |
25dbc73a AM |
3283 | local_got_refcounts = bfd_zalloc (abfd, size); |
3284 | if (local_got_refcounts == NULL) | |
e054468f | 3285 | return NULL; |
25dbc73a | 3286 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 3287 | } |
41fcb14e | 3288 | |
e054468f AM |
3289 | local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info); |
3290 | local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
25dbc73a | 3291 | local_got_tls_masks[r_symndx] |= tls_type; |
e054468f AM |
3292 | if (tls_type != PLT_IFUNC) |
3293 | local_got_refcounts[r_symndx] += 1; | |
3294 | return local_plt + r_symndx; | |
25dbc73a | 3295 | } |
41fcb14e | 3296 | |
a6aa5195 | 3297 | static bfd_boolean |
3ec01793 | 3298 | update_plt_info (bfd *abfd, struct plt_entry **plist, |
a6aa5195 AM |
3299 | asection *sec, bfd_vma addend) |
3300 | { | |
3301 | struct plt_entry *ent; | |
3302 | ||
32af9f6e AM |
3303 | if (addend < 32768) |
3304 | sec = NULL; | |
3ec01793 | 3305 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3306 | if (ent->sec == sec && ent->addend == addend) |
3307 | break; | |
3308 | if (ent == NULL) | |
3309 | { | |
3310 | bfd_size_type amt = sizeof (*ent); | |
3311 | ent = bfd_alloc (abfd, amt); | |
3312 | if (ent == NULL) | |
3313 | return FALSE; | |
3ec01793 | 3314 | ent->next = *plist; |
a6aa5195 AM |
3315 | ent->sec = sec; |
3316 | ent->addend = addend; | |
3317 | ent->plt.refcount = 0; | |
3ec01793 | 3318 | *plist = ent; |
a6aa5195 AM |
3319 | } |
3320 | ent->plt.refcount += 1; | |
3321 | return TRUE; | |
3322 | } | |
3323 | ||
3324 | static struct plt_entry * | |
3ec01793 | 3325 | find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend) |
a6aa5195 AM |
3326 | { |
3327 | struct plt_entry *ent; | |
3328 | ||
3329 | if (addend < 32768) | |
3330 | sec = NULL; | |
3ec01793 | 3331 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3332 | if (ent->sec == sec && ent->addend == addend) |
3333 | break; | |
3334 | return ent; | |
3335 | } | |
3336 | ||
e054468f AM |
3337 | static bfd_boolean |
3338 | is_branch_reloc (enum elf_ppc_reloc_type r_type) | |
3339 | { | |
3340 | return (r_type == R_PPC_PLTREL24 | |
3341 | || r_type == R_PPC_LOCAL24PC | |
3342 | || r_type == R_PPC_REL24 | |
3343 | || r_type == R_PPC_REL14 | |
3344 | || r_type == R_PPC_REL14_BRTAKEN | |
3345 | || r_type == R_PPC_REL14_BRNTAKEN | |
3346 | || r_type == R_PPC_ADDR24 | |
3347 | || r_type == R_PPC_ADDR14 | |
3348 | || r_type == R_PPC_ADDR14_BRTAKEN | |
3349 | || r_type == R_PPC_ADDR14_BRNTAKEN); | |
3350 | } | |
3351 | ||
25dbc73a AM |
3352 | static void |
3353 | bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type) | |
3354 | { | |
3355 | (*_bfd_error_handler) | |
3356 | (_("%B: relocation %s cannot be used when making a shared object"), | |
3357 | abfd, | |
3358 | ppc_elf_howto_table[r_type]->name); | |
3359 | bfd_set_error (bfd_error_bad_value); | |
252b5132 RH |
3360 | } |
3361 | ||
25dbc73a AM |
3362 | /* Look through the relocs for a section during the first phase, and |
3363 | allocate space in the global offset table or procedure linkage | |
3364 | table. */ | |
252b5132 | 3365 | |
b34976b6 | 3366 | static bfd_boolean |
25dbc73a AM |
3367 | ppc_elf_check_relocs (bfd *abfd, |
3368 | struct bfd_link_info *info, | |
3369 | asection *sec, | |
3370 | const Elf_Internal_Rela *relocs) | |
252b5132 | 3371 | { |
7619e7c7 | 3372 | struct ppc_elf_link_hash_table *htab; |
25dbc73a AM |
3373 | Elf_Internal_Shdr *symtab_hdr; |
3374 | struct elf_link_hash_entry **sym_hashes; | |
3375 | const Elf_Internal_Rela *rel; | |
3376 | const Elf_Internal_Rela *rel_end; | |
a6aa5195 | 3377 | asection *got2, *sreloc; |
727fc41e | 3378 | struct elf_link_hash_entry *tga; |
25dbc73a AM |
3379 | |
3380 | if (info->relocatable) | |
3381 | return TRUE; | |
252b5132 | 3382 | |
c87b5a93 AM |
3383 | /* Don't do anything special with non-loaded, non-alloced sections. |
3384 | In particular, any relocs in such sections should not affect GOT | |
3385 | and PLT reference counting (ie. we don't allow them to create GOT | |
3386 | or PLT entries), there's no possibility or desire to optimize TLS | |
3387 | relocs, and there's not much point in propagating relocs to shared | |
3388 | libs that the dynamic linker won't relocate. */ | |
3389 | if ((sec->flags & SEC_ALLOC) == 0) | |
3390 | return TRUE; | |
3391 | ||
252b5132 | 3392 | #ifdef DEBUG |
25dbc73a AM |
3393 | _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B", |
3394 | sec, abfd); | |
252b5132 RH |
3395 | #endif |
3396 | ||
0c8d6e5c | 3397 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 3398 | |
25dbc73a AM |
3399 | /* Initialize howto table if not already done. */ |
3400 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
3401 | ppc_elf_howto_init (); | |
3402 | ||
7619e7c7 | 3403 | htab = ppc_elf_hash_table (info); |
25f23106 AM |
3404 | if (htab->glink == NULL) |
3405 | { | |
3406 | if (htab->elf.dynobj == NULL) | |
3407 | htab->elf.dynobj = abfd; | |
3408 | if (!ppc_elf_create_glink (htab->elf.dynobj, info)) | |
3409 | return FALSE; | |
3410 | } | |
727fc41e AM |
3411 | tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
3412 | FALSE, FALSE, TRUE); | |
0ffa91dd | 3413 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a | 3414 | sym_hashes = elf_sym_hashes (abfd); |
a6aa5195 | 3415 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
3416 | sreloc = NULL; |
3417 | ||
3418 | rel_end = relocs + sec->reloc_count; | |
3419 | for (rel = relocs; rel < rel_end; rel++) | |
3420 | { | |
3421 | unsigned long r_symndx; | |
3422 | enum elf_ppc_reloc_type r_type; | |
3423 | struct elf_link_hash_entry *h; | |
727fc41e | 3424 | int tls_type; |
25dbc73a AM |
3425 | |
3426 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3427 | if (r_symndx < symtab_hdr->sh_info) | |
3428 | h = NULL; | |
3429 | else | |
973a3492 L |
3430 | { |
3431 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3432 | while (h->root.type == bfd_link_hash_indirect | |
3433 | || h->root.type == bfd_link_hash_warning) | |
3434 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3435 | } | |
25dbc73a AM |
3436 | |
3437 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. | |
3438 | This shows up in particular in an R_PPC_ADDR32 in the eabi | |
3439 | startup code. */ | |
3b36f7e6 AM |
3440 | if (h != NULL |
3441 | && htab->got == NULL | |
3442 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
252b5132 | 3443 | { |
3b36f7e6 AM |
3444 | if (htab->elf.dynobj == NULL) |
3445 | htab->elf.dynobj = abfd; | |
3446 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
3447 | return FALSE; | |
3448 | BFD_ASSERT (h == htab->elf.hgot); | |
25dbc73a | 3449 | } |
252b5132 | 3450 | |
727fc41e | 3451 | tls_type = 0; |
de972ffa | 3452 | r_type = ELF32_R_TYPE (rel->r_info); |
06a162cf | 3453 | if (h == NULL && !htab->is_vxworks) |
e054468f | 3454 | { |
06a162cf AM |
3455 | Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3456 | abfd, r_symndx); | |
3457 | if (isym == NULL) | |
3458 | return FALSE; | |
3459 | ||
3460 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC | |
3461 | && (!info->shared | |
3462 | || is_branch_reloc (r_type))) | |
e054468f | 3463 | { |
06a162cf AM |
3464 | struct plt_entry **ifunc; |
3465 | bfd_vma addend; | |
3466 | ||
3467 | ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3468 | PLT_IFUNC); | |
3469 | if (ifunc == NULL) | |
e054468f AM |
3470 | return FALSE; |
3471 | ||
06a162cf AM |
3472 | /* STT_GNU_IFUNC symbols must have a PLT entry; |
3473 | In a non-pie executable even when there are | |
3474 | no plt calls. */ | |
3475 | addend = 0; | |
3476 | if (r_type == R_PPC_PLTREL24) | |
e054468f | 3477 | { |
06a162cf AM |
3478 | ppc_elf_tdata (abfd)->makes_plt_call = 1; |
3479 | if (info->shared) | |
3480 | addend = rel->r_addend; | |
e054468f | 3481 | } |
06a162cf AM |
3482 | if (!update_plt_info (abfd, ifunc, got2, addend)) |
3483 | return FALSE; | |
e054468f | 3484 | } |
25f23106 AM |
3485 | } |
3486 | ||
de972ffa AM |
3487 | if (!htab->is_vxworks |
3488 | && is_branch_reloc (r_type) | |
3489 | && h != NULL | |
3490 | && h == tga) | |
25f23106 | 3491 | { |
de972ffa AM |
3492 | if (rel != relocs |
3493 | && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD | |
3494 | || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD)) | |
3495 | /* We have a new-style __tls_get_addr call with a marker | |
3496 | reloc. */ | |
3497 | ; | |
3498 | else | |
3499 | /* Mark this section as having an old-style call. */ | |
3500 | sec->has_tls_get_addr_call = 1; | |
e054468f | 3501 | } |
727fc41e | 3502 | |
25dbc73a AM |
3503 | switch (r_type) |
3504 | { | |
727fc41e AM |
3505 | case R_PPC_TLSGD: |
3506 | case R_PPC_TLSLD: | |
3507 | /* These special tls relocs tie a call to __tls_get_addr with | |
3508 | its parameter symbol. */ | |
3509 | break; | |
3510 | ||
25dbc73a AM |
3511 | case R_PPC_GOT_TLSLD16: |
3512 | case R_PPC_GOT_TLSLD16_LO: | |
3513 | case R_PPC_GOT_TLSLD16_HI: | |
3514 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
3515 | tls_type = TLS_TLS | TLS_LD; |
3516 | goto dogottls; | |
252b5132 | 3517 | |
25dbc73a AM |
3518 | case R_PPC_GOT_TLSGD16: |
3519 | case R_PPC_GOT_TLSGD16_LO: | |
3520 | case R_PPC_GOT_TLSGD16_HI: | |
3521 | case R_PPC_GOT_TLSGD16_HA: | |
3522 | tls_type = TLS_TLS | TLS_GD; | |
3523 | goto dogottls; | |
3524 | ||
3525 | case R_PPC_GOT_TPREL16: | |
3526 | case R_PPC_GOT_TPREL16_LO: | |
3527 | case R_PPC_GOT_TPREL16_HI: | |
3528 | case R_PPC_GOT_TPREL16_HA: | |
1d483afe | 3529 | if (!info->executable) |
25dbc73a AM |
3530 | info->flags |= DF_STATIC_TLS; |
3531 | tls_type = TLS_TLS | TLS_TPREL; | |
3532 | goto dogottls; | |
3533 | ||
3534 | case R_PPC_GOT_DTPREL16: | |
3535 | case R_PPC_GOT_DTPREL16_LO: | |
3536 | case R_PPC_GOT_DTPREL16_HI: | |
3537 | case R_PPC_GOT_DTPREL16_HA: | |
3538 | tls_type = TLS_TLS | TLS_DTPREL; | |
3539 | dogottls: | |
3540 | sec->has_tls_reloc = 1; | |
3541 | /* Fall thru */ | |
252b5132 | 3542 | |
25dbc73a AM |
3543 | /* GOT16 relocations */ |
3544 | case R_PPC_GOT16: | |
3545 | case R_PPC_GOT16_LO: | |
3546 | case R_PPC_GOT16_HI: | |
3547 | case R_PPC_GOT16_HA: | |
3548 | /* This symbol requires a global offset table entry. */ | |
3549 | if (htab->got == NULL) | |
3550 | { | |
3551 | if (htab->elf.dynobj == NULL) | |
3552 | htab->elf.dynobj = abfd; | |
3553 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
3554 | return FALSE; | |
3555 | } | |
3556 | if (h != NULL) | |
3557 | { | |
3558 | h->got.refcount += 1; | |
3559 | ppc_elf_hash_entry (h)->tls_mask |= tls_type; | |
3560 | } | |
3561 | else | |
3562 | /* This is a global offset table entry for a local symbol. */ | |
3563 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)) | |
3564 | return FALSE; | |
91e21fb7 AM |
3565 | |
3566 | /* We may also need a plt entry if the symbol turns out to be | |
3567 | an ifunc. */ | |
3568 | if (h != NULL && !info->shared) | |
3569 | { | |
3570 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) | |
3571 | return FALSE; | |
3572 | } | |
25dbc73a | 3573 | break; |
252b5132 | 3574 | |
25dbc73a AM |
3575 | /* Indirect .sdata relocation. */ |
3576 | case R_PPC_EMB_SDAI16: | |
3577 | if (info->shared) | |
3578 | { | |
3579 | bad_shared_reloc (abfd, r_type); | |
3580 | return FALSE; | |
3581 | } | |
c9a2f333 AM |
3582 | if (htab->sdata[0].section == NULL |
3583 | && !ppc_elf_create_linker_section (abfd, info, 0, | |
3584 | &htab->sdata[0])) | |
3585 | return FALSE; | |
76750a2f AM |
3586 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0], |
3587 | h, rel)) | |
25dbc73a | 3588 | return FALSE; |
046183de AM |
3589 | if (h != NULL) |
3590 | { | |
3591 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3592 | h->non_got_ref = TRUE; | |
3593 | } | |
25dbc73a | 3594 | break; |
252b5132 | 3595 | |
25dbc73a AM |
3596 | /* Indirect .sdata2 relocation. */ |
3597 | case R_PPC_EMB_SDA2I16: | |
3598 | if (info->shared) | |
3599 | { | |
3600 | bad_shared_reloc (abfd, r_type); | |
3601 | return FALSE; | |
3602 | } | |
c9a2f333 AM |
3603 | if (htab->sdata[1].section == NULL |
3604 | && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY, | |
3605 | &htab->sdata[1])) | |
3606 | return FALSE; | |
76750a2f AM |
3607 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1], |
3608 | h, rel)) | |
25dbc73a | 3609 | return FALSE; |
046183de AM |
3610 | if (h != NULL) |
3611 | { | |
3612 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3613 | h->non_got_ref = TRUE; | |
3614 | } | |
25dbc73a | 3615 | break; |
252b5132 | 3616 | |
25dbc73a | 3617 | case R_PPC_SDAREL16: |
046183de | 3618 | if (htab->sdata[0].sym == NULL |
bd6c6e2b | 3619 | && !create_sdata_sym (info, &htab->sdata[0])) |
046183de AM |
3620 | return FALSE; |
3621 | if (h != NULL) | |
3622 | { | |
3623 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3624 | h->non_got_ref = TRUE; | |
3625 | } | |
3626 | break; | |
3627 | ||
25dbc73a | 3628 | case R_PPC_EMB_SDA2REL: |
046183de AM |
3629 | if (info->shared) |
3630 | { | |
3631 | bad_shared_reloc (abfd, r_type); | |
3632 | return FALSE; | |
3633 | } | |
3634 | if (htab->sdata[1].sym == NULL | |
bd6c6e2b | 3635 | && !create_sdata_sym (info, &htab->sdata[1])) |
046183de AM |
3636 | return FALSE; |
3637 | if (h != NULL) | |
3638 | { | |
3639 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3640 | h->non_got_ref = TRUE; | |
3641 | } | |
3642 | break; | |
3643 | ||
25dbc73a AM |
3644 | case R_PPC_EMB_SDA21: |
3645 | case R_PPC_EMB_RELSDA: | |
046183de AM |
3646 | if (info->shared) |
3647 | { | |
3648 | bad_shared_reloc (abfd, r_type); | |
3649 | return FALSE; | |
3650 | } | |
3651 | if (htab->sdata[0].sym == NULL | |
bd6c6e2b | 3652 | && !create_sdata_sym (info, &htab->sdata[0])) |
046183de AM |
3653 | return FALSE; |
3654 | if (htab->sdata[1].sym == NULL | |
bd6c6e2b | 3655 | && !create_sdata_sym (info, &htab->sdata[1])) |
046183de AM |
3656 | return FALSE; |
3657 | if (h != NULL) | |
3658 | { | |
3659 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3660 | h->non_got_ref = TRUE; | |
3661 | } | |
3662 | break; | |
3663 | ||
25dbc73a AM |
3664 | case R_PPC_EMB_NADDR32: |
3665 | case R_PPC_EMB_NADDR16: | |
3666 | case R_PPC_EMB_NADDR16_LO: | |
3667 | case R_PPC_EMB_NADDR16_HI: | |
3668 | case R_PPC_EMB_NADDR16_HA: | |
3669 | if (info->shared) | |
3670 | { | |
3671 | bad_shared_reloc (abfd, r_type); | |
3672 | return FALSE; | |
3673 | } | |
4dc4a9a5 | 3674 | if (h != NULL) |
046183de | 3675 | h->non_got_ref = TRUE; |
25dbc73a | 3676 | break; |
252b5132 | 3677 | |
25dbc73a | 3678 | case R_PPC_PLTREL24: |
de972ffa | 3679 | if (h == NULL) |
6d78d0b9 AM |
3680 | break; |
3681 | /* Fall through */ | |
3682 | case R_PPC_PLT32: | |
25dbc73a AM |
3683 | case R_PPC_PLTREL32: |
3684 | case R_PPC_PLT16_LO: | |
3685 | case R_PPC_PLT16_HI: | |
3686 | case R_PPC_PLT16_HA: | |
3687 | #ifdef DEBUG | |
3688 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
3689 | #endif | |
3690 | /* This symbol requires a procedure linkage table entry. We | |
3691 | actually build the entry in finish_dynamic_symbol, | |
3692 | because this might be a case of linking PIC code without | |
3693 | linking in any dynamic objects, in which case we don't | |
3694 | need to generate a procedure linkage table after all. */ | |
7619e7c7 | 3695 | |
25dbc73a AM |
3696 | if (h == NULL) |
3697 | { | |
3698 | /* It does not make sense to have a procedure linkage | |
3699 | table entry for a local symbol. */ | |
25f53a85 AM |
3700 | info->callbacks->einfo (_("%H: %s reloc against local symbol\n"), |
3701 | abfd, sec, rel->r_offset, | |
3702 | ppc_elf_howto_table[r_type]->name); | |
25dbc73a AM |
3703 | bfd_set_error (bfd_error_bad_value); |
3704 | return FALSE; | |
3705 | } | |
a6aa5195 AM |
3706 | else |
3707 | { | |
016687f8 | 3708 | bfd_vma addend = 0; |
ee05f2fe | 3709 | |
016687f8 AM |
3710 | if (r_type == R_PPC_PLTREL24) |
3711 | { | |
3712 | ppc_elf_tdata (abfd)->makes_plt_call = 1; | |
a877a2b6 AM |
3713 | if (info->shared) |
3714 | addend = rel->r_addend; | |
016687f8 | 3715 | } |
a6aa5195 | 3716 | h->needs_plt = 1; |
32af9f6e | 3717 | if (!update_plt_info (abfd, &h->plt.plist, got2, addend)) |
a6aa5195 AM |
3718 | return FALSE; |
3719 | } | |
25dbc73a | 3720 | break; |
ee05f2fe | 3721 | |
25dbc73a AM |
3722 | /* The following relocations don't need to propagate the |
3723 | relocation if linking a shared object since they are | |
3724 | section relative. */ | |
3725 | case R_PPC_SECTOFF: | |
3726 | case R_PPC_SECTOFF_LO: | |
3727 | case R_PPC_SECTOFF_HI: | |
3728 | case R_PPC_SECTOFF_HA: | |
3729 | case R_PPC_DTPREL16: | |
3730 | case R_PPC_DTPREL16_LO: | |
3731 | case R_PPC_DTPREL16_HI: | |
3732 | case R_PPC_DTPREL16_HA: | |
3733 | case R_PPC_TOC16: | |
3734 | break; | |
252b5132 | 3735 | |
d7128ce4 AM |
3736 | case R_PPC_REL16: |
3737 | case R_PPC_REL16_LO: | |
3738 | case R_PPC_REL16_HI: | |
3739 | case R_PPC_REL16_HA: | |
016687f8 | 3740 | ppc_elf_tdata (abfd)->has_rel16 = 1; |
d7128ce4 AM |
3741 | break; |
3742 | ||
a6aa5195 | 3743 | /* These are just markers. */ |
25dbc73a AM |
3744 | case R_PPC_TLS: |
3745 | case R_PPC_EMB_MRKREF: | |
3746 | case R_PPC_NONE: | |
3747 | case R_PPC_max: | |
32af9f6e AM |
3748 | case R_PPC_RELAX: |
3749 | case R_PPC_RELAX_PLT: | |
3750 | case R_PPC_RELAX_PLTREL24: | |
25dbc73a | 3751 | break; |
252b5132 | 3752 | |
25dbc73a AM |
3753 | /* These should only appear in dynamic objects. */ |
3754 | case R_PPC_COPY: | |
3755 | case R_PPC_GLOB_DAT: | |
3756 | case R_PPC_JMP_SLOT: | |
3757 | case R_PPC_RELATIVE: | |
e054468f | 3758 | case R_PPC_IRELATIVE: |
25dbc73a | 3759 | break; |
252b5132 | 3760 | |
25dbc73a AM |
3761 | /* These aren't handled yet. We'll report an error later. */ |
3762 | case R_PPC_ADDR30: | |
3763 | case R_PPC_EMB_RELSEC16: | |
3764 | case R_PPC_EMB_RELST_LO: | |
3765 | case R_PPC_EMB_RELST_HI: | |
3766 | case R_PPC_EMB_RELST_HA: | |
3767 | case R_PPC_EMB_BIT_FLD: | |
3768 | break; | |
252b5132 | 3769 | |
25dbc73a AM |
3770 | /* This refers only to functions defined in the shared library. */ |
3771 | case R_PPC_LOCAL24PC: | |
727fc41e | 3772 | if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET) |
016687f8 AM |
3773 | { |
3774 | htab->plt_type = PLT_OLD; | |
3775 | htab->old_bfd = abfd; | |
3776 | } | |
25dbc73a | 3777 | break; |
252b5132 | 3778 | |
25dbc73a AM |
3779 | /* This relocation describes the C++ object vtable hierarchy. |
3780 | Reconstruct it for later use during GC. */ | |
3781 | case R_PPC_GNU_VTINHERIT: | |
3782 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
3783 | return FALSE; | |
3784 | break; | |
252b5132 | 3785 | |
25dbc73a AM |
3786 | /* This relocation describes which C++ vtable entries are actually |
3787 | used. Record for later use during GC. */ | |
3788 | case R_PPC_GNU_VTENTRY: | |
d17e0c6e JB |
3789 | BFD_ASSERT (h != NULL); |
3790 | if (h != NULL | |
3791 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
25dbc73a AM |
3792 | return FALSE; |
3793 | break; | |
252b5132 | 3794 | |
25dbc73a AM |
3795 | /* We shouldn't really be seeing these. */ |
3796 | case R_PPC_TPREL32: | |
1d483afe AM |
3797 | case R_PPC_TPREL16: |
3798 | case R_PPC_TPREL16_LO: | |
3799 | case R_PPC_TPREL16_HI: | |
3800 | case R_PPC_TPREL16_HA: | |
3801 | if (!info->executable) | |
25dbc73a AM |
3802 | info->flags |= DF_STATIC_TLS; |
3803 | goto dodyn; | |
252b5132 | 3804 | |
25dbc73a AM |
3805 | /* Nor these. */ |
3806 | case R_PPC_DTPMOD32: | |
3807 | case R_PPC_DTPREL32: | |
3808 | goto dodyn; | |
252b5132 | 3809 | |
9edfd1af AM |
3810 | case R_PPC_REL32: |
3811 | if (h == NULL | |
3812 | && got2 != NULL | |
3813 | && (sec->flags & SEC_CODE) != 0 | |
a877a2b6 | 3814 | && info->shared |
4a3dc543 | 3815 | && htab->plt_type == PLT_UNSET) |
9edfd1af AM |
3816 | { |
3817 | /* Old -fPIC gcc code has .long LCTOC1-LCFx just before | |
3818 | the start of a function, which assembles to a REL32 | |
3819 | reference to .got2. If we detect one of these, then | |
3820 | force the old PLT layout because the linker cannot | |
3821 | reliably deduce the GOT pointer value needed for | |
3822 | PLT call stubs. */ | |
3823 | asection *s; | |
87d72d41 | 3824 | Elf_Internal_Sym *isym; |
9edfd1af | 3825 | |
87d72d41 AM |
3826 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3827 | abfd, r_symndx); | |
3828 | if (isym == NULL) | |
3829 | return FALSE; | |
3830 | ||
3831 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
9edfd1af | 3832 | if (s == got2) |
016687f8 AM |
3833 | { |
3834 | htab->plt_type = PLT_OLD; | |
3835 | htab->old_bfd = abfd; | |
3836 | } | |
9edfd1af | 3837 | } |
7123df0e | 3838 | if (h == NULL || h == htab->elf.hgot) |
fd38b44c | 3839 | break; |
625af618 AM |
3840 | /* fall through */ |
3841 | ||
3842 | case R_PPC_ADDR32: | |
3843 | case R_PPC_ADDR16: | |
3844 | case R_PPC_ADDR16_LO: | |
3845 | case R_PPC_ADDR16_HI: | |
3846 | case R_PPC_ADDR16_HA: | |
3847 | case R_PPC_UADDR32: | |
3848 | case R_PPC_UADDR16: | |
3849 | if (h != NULL && !info->shared) | |
3850 | { | |
3851 | /* We may need a plt entry if the symbol turns out to be | |
3852 | a function defined in a dynamic object. */ | |
3ec01793 | 3853 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
625af618 AM |
3854 | return FALSE; |
3855 | ||
3856 | /* We may need a copy reloc too. */ | |
3857 | h->non_got_ref = 1; | |
3858 | h->pointer_equality_needed = 1; | |
3859 | } | |
3860 | goto dodyn; | |
9edfd1af | 3861 | |
25dbc73a AM |
3862 | case R_PPC_REL24: |
3863 | case R_PPC_REL14: | |
3864 | case R_PPC_REL14_BRTAKEN: | |
3865 | case R_PPC_REL14_BRNTAKEN: | |
d7128ce4 | 3866 | if (h == NULL) |
25dbc73a | 3867 | break; |
7123df0e | 3868 | if (h == htab->elf.hgot) |
d7128ce4 | 3869 | { |
7123df0e | 3870 | if (htab->plt_type == PLT_UNSET) |
016687f8 AM |
3871 | { |
3872 | htab->plt_type = PLT_OLD; | |
3873 | htab->old_bfd = abfd; | |
3874 | } | |
d7128ce4 AM |
3875 | break; |
3876 | } | |
25dbc73a | 3877 | /* fall through */ |
ee05f2fe | 3878 | |
25dbc73a | 3879 | case R_PPC_ADDR24: |
25dbc73a AM |
3880 | case R_PPC_ADDR14: |
3881 | case R_PPC_ADDR14_BRTAKEN: | |
3882 | case R_PPC_ADDR14_BRNTAKEN: | |
25dbc73a AM |
3883 | if (h != NULL && !info->shared) |
3884 | { | |
3885 | /* We may need a plt entry if the symbol turns out to be | |
3886 | a function defined in a dynamic object. */ | |
e054468f | 3887 | h->needs_plt = 1; |
de972ffa | 3888 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
a6aa5195 | 3889 | return FALSE; |
625af618 | 3890 | break; |
25dbc73a | 3891 | } |
7619e7c7 | 3892 | |
25dbc73a AM |
3893 | dodyn: |
3894 | /* If we are creating a shared library, and this is a reloc | |
3895 | against a global symbol, or a non PC relative reloc | |
3896 | against a local symbol, then we need to copy the reloc | |
3897 | into the shared library. However, if we are linking with | |
3898 | -Bsymbolic, we do not need to copy a reloc against a | |
3899 | global symbol which is defined in an object we are | |
3900 | including in the link (i.e., DEF_REGULAR is set). At | |
3901 | this point we have not seen all the input files, so it is | |
3902 | possible that DEF_REGULAR is not set now but will be set | |
3903 | later (it is never cleared). In case of a weak definition, | |
3904 | DEF_REGULAR may be cleared later by a strong definition in | |
3905 | a shared library. We account for that possibility below by | |
3906 | storing information in the dyn_relocs field of the hash | |
3907 | table entry. A similar situation occurs when creating | |
3908 | shared libraries and symbol visibility changes render the | |
3909 | symbol local. | |
7619e7c7 | 3910 | |
25dbc73a AM |
3911 | If on the other hand, we are creating an executable, we |
3912 | may need to keep relocations for symbols satisfied by a | |
3913 | dynamic library if we manage to avoid copy relocs for the | |
3914 | symbol. */ | |
3915 | if ((info->shared | |
1d483afe | 3916 | && (must_be_dyn_reloc (info, r_type) |
25dbc73a AM |
3917 | || (h != NULL |
3918 | && (! info->symbolic | |
3919 | || h->root.type == bfd_link_hash_defweak | |
3920 | || !h->def_regular)))) | |
3921 | || (ELIMINATE_COPY_RELOCS | |
3922 | && !info->shared | |
25dbc73a AM |
3923 | && h != NULL |
3924 | && (h->root.type == bfd_link_hash_defweak | |
de972ffa | 3925 | || !h->def_regular))) |
25dbc73a | 3926 | { |
6061a67d AM |
3927 | struct elf_dyn_relocs *p; |
3928 | struct elf_dyn_relocs **rel_head; | |
7619e7c7 | 3929 | |
25dbc73a AM |
3930 | #ifdef DEBUG |
3931 | fprintf (stderr, | |
3932 | "ppc_elf_check_relocs needs to " | |
3933 | "create relocation for %s\n", | |
3934 | (h && h->root.root.string | |
3935 | ? h->root.root.string : "<unknown>")); | |
3936 | #endif | |
3937 | if (sreloc == NULL) | |
3938 | { | |
c9a2f333 AM |
3939 | if (htab->elf.dynobj == NULL) |
3940 | htab->elf.dynobj = abfd; | |
83bac4b0 NC |
3941 | |
3942 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
3943 | (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE); | |
3944 | ||
25dbc73a | 3945 | if (sreloc == NULL) |
83bac4b0 | 3946 | return FALSE; |
25dbc73a | 3947 | } |
7619e7c7 | 3948 | |
25dbc73a AM |
3949 | /* If this is a global symbol, we count the number of |
3950 | relocations we need for this symbol. */ | |
3951 | if (h != NULL) | |
3952 | { | |
91d6fa6a | 3953 | rel_head = &ppc_elf_hash_entry (h)->dyn_relocs; |
25dbc73a AM |
3954 | } |
3955 | else | |
3956 | { | |
3957 | /* Track dynamic relocs needed for local syms too. | |
3958 | We really need local syms available to do this | |
3959 | easily. Oh well. */ | |
25dbc73a | 3960 | asection *s; |
6edfbbad | 3961 | void *vpp; |
87d72d41 | 3962 | Elf_Internal_Sym *isym; |
6edfbbad | 3963 | |
87d72d41 AM |
3964 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3965 | abfd, r_symndx); | |
3966 | if (isym == NULL) | |
25dbc73a | 3967 | return FALSE; |
7fce784e | 3968 | |
87d72d41 AM |
3969 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
3970 | if (s == NULL) | |
3971 | s = sec; | |
3972 | ||
6edfbbad | 3973 | vpp = &elf_section_data (s)->local_dynrel; |
6061a67d | 3974 | rel_head = (struct elf_dyn_relocs **) vpp; |
25dbc73a | 3975 | } |
7fce784e | 3976 | |
91d6fa6a | 3977 | p = *rel_head; |
25dbc73a AM |
3978 | if (p == NULL || p->sec != sec) |
3979 | { | |
3980 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); | |
3981 | if (p == NULL) | |
3982 | return FALSE; | |
91d6fa6a NC |
3983 | p->next = *rel_head; |
3984 | *rel_head = p; | |
25dbc73a AM |
3985 | p->sec = sec; |
3986 | p->count = 0; | |
3987 | p->pc_count = 0; | |
3988 | } | |
3989 | ||
3990 | p->count += 1; | |
1d483afe | 3991 | if (!must_be_dyn_reloc (info, r_type)) |
25dbc73a | 3992 | p->pc_count += 1; |
7619e7c7 | 3993 | } |
25dbc73a AM |
3994 | |
3995 | break; | |
7619e7c7 AM |
3996 | } |
3997 | } | |
ee05f2fe | 3998 | |
25dbc73a AM |
3999 | return TRUE; |
4000 | } | |
4001 | \f | |
34c8bcba JM |
4002 | |
4003 | /* Merge object attributes from IBFD into OBFD. Raise an error if | |
4004 | there are conflicting attributes. */ | |
4005 | static bfd_boolean | |
4006 | ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd) | |
4007 | { | |
c6e65352 DJ |
4008 | obj_attribute *in_attr, *in_attrs; |
4009 | obj_attribute *out_attr, *out_attrs; | |
34c8bcba JM |
4010 | |
4011 | if (!elf_known_obj_attributes_proc (obfd)[0].i) | |
4012 | { | |
4013 | /* This is the first object. Copy the attributes. */ | |
4014 | _bfd_elf_copy_obj_attributes (ibfd, obfd); | |
4015 | ||
4016 | /* Use the Tag_null value to indicate the attributes have been | |
4017 | initialized. */ | |
4018 | elf_known_obj_attributes_proc (obfd)[0].i = 1; | |
4019 | ||
4020 | return TRUE; | |
4021 | } | |
4022 | ||
c6e65352 DJ |
4023 | in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU]; |
4024 | out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU]; | |
4025 | ||
34c8bcba JM |
4026 | /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge |
4027 | non-conflicting ones. */ | |
c6e65352 DJ |
4028 | in_attr = &in_attrs[Tag_GNU_Power_ABI_FP]; |
4029 | out_attr = &out_attrs[Tag_GNU_Power_ABI_FP]; | |
4030 | if (in_attr->i != out_attr->i) | |
34c8bcba | 4031 | { |
c6e65352 DJ |
4032 | out_attr->type = 1; |
4033 | if (out_attr->i == 0) | |
4034 | out_attr->i = in_attr->i; | |
4035 | else if (in_attr->i == 0) | |
34c8bcba | 4036 | ; |
c6e65352 | 4037 | else if (out_attr->i == 1 && in_attr->i == 2) |
34c8bcba JM |
4038 | _bfd_error_handler |
4039 | (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd); | |
3c7b9897 AM |
4040 | else if (out_attr->i == 1 && in_attr->i == 3) |
4041 | _bfd_error_handler | |
5b914448 | 4042 | (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"), |
3c7b9897 AM |
4043 | obfd, ibfd); |
4044 | else if (out_attr->i == 3 && in_attr->i == 1) | |
4045 | _bfd_error_handler | |
5b914448 | 4046 | (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"), |
3c7b9897 AM |
4047 | ibfd, obfd); |
4048 | else if (out_attr->i == 3 && in_attr->i == 2) | |
4049 | _bfd_error_handler | |
5b914448 | 4050 | (_("Warning: %B uses soft float, %B uses single-precision hard float"), |
3c7b9897 AM |
4051 | ibfd, obfd); |
4052 | else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3)) | |
34c8bcba JM |
4053 | _bfd_error_handler |
4054 | (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd); | |
3c7b9897 | 4055 | else if (in_attr->i > 3) |
34c8bcba JM |
4056 | _bfd_error_handler |
4057 | (_("Warning: %B uses unknown floating point ABI %d"), ibfd, | |
c6e65352 | 4058 | in_attr->i); |
34c8bcba JM |
4059 | else |
4060 | _bfd_error_handler | |
4061 | (_("Warning: %B uses unknown floating point ABI %d"), obfd, | |
c6e65352 DJ |
4062 | out_attr->i); |
4063 | } | |
4064 | ||
4065 | /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and | |
4066 | merge non-conflicting ones. */ | |
4067 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector]; | |
4068 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector]; | |
4069 | if (in_attr->i != out_attr->i) | |
4070 | { | |
4071 | const char *in_abi = NULL, *out_abi = NULL; | |
4072 | ||
4073 | switch (in_attr->i) | |
4074 | { | |
4075 | case 1: in_abi = "generic"; break; | |
4076 | case 2: in_abi = "AltiVec"; break; | |
4077 | case 3: in_abi = "SPE"; break; | |
4078 | } | |
4079 | ||
4080 | switch (out_attr->i) | |
4081 | { | |
4082 | case 1: out_abi = "generic"; break; | |
4083 | case 2: out_abi = "AltiVec"; break; | |
4084 | case 3: out_abi = "SPE"; break; | |
4085 | } | |
4086 | ||
4087 | out_attr->type = 1; | |
4088 | if (out_attr->i == 0) | |
4089 | out_attr->i = in_attr->i; | |
4090 | else if (in_attr->i == 0) | |
4091 | ; | |
4092 | /* For now, allow generic to transition to AltiVec or SPE | |
4093 | without a warning. If GCC marked files with their stack | |
4094 | alignment and used don't-care markings for files which are | |
4095 | not affected by the vector ABI, we could warn about this | |
4096 | case too. */ | |
4097 | else if (out_attr->i == 1) | |
4098 | out_attr->i = in_attr->i; | |
4099 | else if (in_attr->i == 1) | |
4100 | ; | |
4101 | else if (in_abi == NULL) | |
4102 | _bfd_error_handler | |
4103 | (_("Warning: %B uses unknown vector ABI %d"), ibfd, | |
4104 | in_attr->i); | |
4105 | else if (out_abi == NULL) | |
4106 | _bfd_error_handler | |
4107 | (_("Warning: %B uses unknown vector ABI %d"), obfd, | |
4108 | in_attr->i); | |
4109 | else | |
4110 | _bfd_error_handler | |
4111 | (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""), | |
4112 | ibfd, obfd, in_abi, out_abi); | |
34c8bcba JM |
4113 | } |
4114 | ||
f82e0623 NF |
4115 | /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes |
4116 | and merge non-conflicting ones. */ | |
4117 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4118 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4119 | if (in_attr->i != out_attr->i) | |
4120 | { | |
4121 | out_attr->type = 1; | |
4122 | if (out_attr->i == 0) | |
4123 | out_attr->i = in_attr->i; | |
4124 | else if (in_attr->i == 0) | |
4125 | ; | |
4126 | else if (out_attr->i == 1 && in_attr->i == 2) | |
4127 | _bfd_error_handler | |
4128 | (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd); | |
4129 | else if (out_attr->i == 2 && in_attr->i == 1) | |
4130 | _bfd_error_handler | |
4131 | (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd); | |
4132 | else if (in_attr->i > 2) | |
4133 | _bfd_error_handler | |
4134 | (_("Warning: %B uses unknown small structure return convention %d"), ibfd, | |
4135 | in_attr->i); | |
4136 | else | |
4137 | _bfd_error_handler | |
4138 | (_("Warning: %B uses unknown small structure return convention %d"), obfd, | |
4139 | out_attr->i); | |
4140 | } | |
4141 | ||
34c8bcba JM |
4142 | /* Merge Tag_compatibility attributes and any common GNU ones. */ |
4143 | _bfd_elf_merge_object_attributes (ibfd, obfd); | |
4144 | ||
4145 | return TRUE; | |
4146 | } | |
4147 | ||
8853c3d3 AM |
4148 | /* Merge backend specific data from an object file to the output |
4149 | object file when linking. */ | |
4150 | ||
4151 | static bfd_boolean | |
4152 | ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) | |
4153 | { | |
4154 | flagword old_flags; | |
4155 | flagword new_flags; | |
4156 | bfd_boolean error; | |
4157 | ||
0c8d6e5c | 4158 | if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd)) |
8853c3d3 AM |
4159 | return TRUE; |
4160 | ||
cc643b88 | 4161 | /* Check if we have the same endianness. */ |
8853c3d3 AM |
4162 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
4163 | return FALSE; | |
4164 | ||
34c8bcba JM |
4165 | if (!ppc_elf_merge_obj_attributes (ibfd, obfd)) |
4166 | return FALSE; | |
4167 | ||
8853c3d3 AM |
4168 | new_flags = elf_elfheader (ibfd)->e_flags; |
4169 | old_flags = elf_elfheader (obfd)->e_flags; | |
4170 | if (!elf_flags_init (obfd)) | |
4171 | { | |
4172 | /* First call, no flags set. */ | |
4173 | elf_flags_init (obfd) = TRUE; | |
4174 | elf_elfheader (obfd)->e_flags = new_flags; | |
4175 | } | |
4176 | ||
4177 | /* Compatible flags are ok. */ | |
4178 | else if (new_flags == old_flags) | |
4179 | ; | |
4180 | ||
4181 | /* Incompatible flags. */ | |
4182 | else | |
4183 | { | |
4184 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib | |
4185 | to be linked with either. */ | |
4186 | error = FALSE; | |
4187 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 | |
4188 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
4189 | { | |
4190 | error = TRUE; | |
4191 | (*_bfd_error_handler) | |
4192 | (_("%B: compiled with -mrelocatable and linked with " | |
4193 | "modules compiled normally"), ibfd); | |
4194 | } | |
4195 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
4196 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
4197 | { | |
4198 | error = TRUE; | |
4199 | (*_bfd_error_handler) | |
4200 | (_("%B: compiled normally and linked with " | |
4201 | "modules compiled with -mrelocatable"), ibfd); | |
4202 | } | |
4203 | ||
4204 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
4205 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
4206 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
4207 | ||
4208 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
4209 | but each input file is either -mrelocatable or -mrelocatable-lib. */ | |
4210 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) | |
4211 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
4212 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
4213 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
4214 | ||
4215 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if | |
4216 | any module uses it. */ | |
4217 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); | |
4218 | ||
4219 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4220 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4221 | ||
4222 | /* Warn about any other mismatches. */ | |
4223 | if (new_flags != old_flags) | |
4224 | { | |
4225 | error = TRUE; | |
4226 | (*_bfd_error_handler) | |
4227 | (_("%B: uses different e_flags (0x%lx) fields " | |
4228 | "than previous modules (0x%lx)"), | |
4229 | ibfd, (long) new_flags, (long) old_flags); | |
4230 | } | |
4231 | ||
4232 | if (error) | |
4233 | { | |
4234 | bfd_set_error (bfd_error_bad_value); | |
4235 | return FALSE; | |
4236 | } | |
4237 | } | |
4238 | ||
4239 | return TRUE; | |
4240 | } | |
4241 | \f | |
d7128ce4 AM |
4242 | /* Choose which PLT scheme to use, and set .plt flags appropriately. |
4243 | Returns -1 on error, 0 for old PLT, 1 for new PLT. */ | |
4244 | int | |
4245 | ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED, | |
4246 | struct bfd_link_info *info, | |
016687f8 | 4247 | enum ppc_elf_plt_type plt_style, |
0ba07910 | 4248 | int emit_stub_syms) |
d7128ce4 AM |
4249 | { |
4250 | struct ppc_elf_link_hash_table *htab; | |
9d8504b1 | 4251 | flagword flags; |
d7128ce4 AM |
4252 | |
4253 | htab = ppc_elf_hash_table (info); | |
4a3dc543 | 4254 | |
a7f2871e AM |
4255 | htab->emit_stub_syms = emit_stub_syms; |
4256 | ||
4a3dc543 | 4257 | if (htab->plt_type == PLT_UNSET) |
016687f8 AM |
4258 | { |
4259 | if (plt_style == PLT_OLD) | |
4260 | htab->plt_type = PLT_OLD; | |
4261 | else | |
4262 | { | |
4263 | bfd *ibfd; | |
4264 | enum ppc_elf_plt_type plt_type = plt_style; | |
4265 | ||
4266 | /* Look through the reloc flags left by ppc_elf_check_relocs. | |
4267 | Use the old style bss plt if a file makes plt calls | |
4268 | without using the new relocs, and if ld isn't given | |
4269 | --secure-plt and we never see REL16 relocs. */ | |
4270 | if (plt_type == PLT_UNSET) | |
4271 | plt_type = PLT_OLD; | |
60b31e8d | 4272 | for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next) |
0c8d6e5c | 4273 | if (is_ppc_elf (ibfd)) |
016687f8 AM |
4274 | { |
4275 | if (ppc_elf_tdata (ibfd)->has_rel16) | |
4276 | plt_type = PLT_NEW; | |
4277 | else if (ppc_elf_tdata (ibfd)->makes_plt_call) | |
4278 | { | |
4279 | plt_type = PLT_OLD; | |
4280 | htab->old_bfd = ibfd; | |
4281 | break; | |
4282 | } | |
4283 | } | |
4284 | htab->plt_type = plt_type; | |
4285 | } | |
4286 | } | |
4287 | if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW) | |
4288 | info->callbacks->info (_("Using bss-plt due to %B"), htab->old_bfd); | |
d7128ce4 | 4289 | |
4a3dc543 | 4290 | BFD_ASSERT (htab->plt_type != PLT_VXWORKS); |
9d8504b1 | 4291 | |
4a3dc543 | 4292 | if (htab->plt_type == PLT_NEW) |
9d8504b1 PB |
4293 | { |
4294 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
4295 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
86b9da88 AM |
4296 | |
4297 | /* The new PLT is a loaded section. */ | |
4298 | if (htab->plt != NULL | |
4299 | && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags)) | |
4300 | return -1; | |
4301 | ||
4302 | /* The new GOT is not executable. */ | |
4303 | if (htab->got != NULL | |
4304 | && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags)) | |
4305 | return -1; | |
d7128ce4 AM |
4306 | } |
4307 | else | |
4308 | { | |
4309 | /* Stop an unused .glink section from affecting .text alignment. */ | |
86b9da88 AM |
4310 | if (htab->glink != NULL |
4311 | && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0)) | |
4312 | return -1; | |
d7128ce4 | 4313 | } |
4a3dc543 | 4314 | return htab->plt_type == PLT_NEW; |
d7128ce4 AM |
4315 | } |
4316 | \f | |
25dbc73a AM |
4317 | /* Return the section that should be marked against GC for a given |
4318 | relocation. */ | |
586119b3 | 4319 | |
25dbc73a AM |
4320 | static asection * |
4321 | ppc_elf_gc_mark_hook (asection *sec, | |
07adf181 | 4322 | struct bfd_link_info *info, |
25dbc73a AM |
4323 | Elf_Internal_Rela *rel, |
4324 | struct elf_link_hash_entry *h, | |
4325 | Elf_Internal_Sym *sym) | |
4326 | { | |
4327 | if (h != NULL) | |
07adf181 AM |
4328 | switch (ELF32_R_TYPE (rel->r_info)) |
4329 | { | |
4330 | case R_PPC_GNU_VTINHERIT: | |
4331 | case R_PPC_GNU_VTENTRY: | |
4332 | return NULL; | |
4333 | } | |
4334 | ||
4335 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
25dbc73a | 4336 | } |
a876ecf9 | 4337 | |
25dbc73a AM |
4338 | /* Update the got, plt and dynamic reloc reference counts for the |
4339 | section being removed. */ | |
4340 | ||
4341 | static bfd_boolean | |
4342 | ppc_elf_gc_sweep_hook (bfd *abfd, | |
4343 | struct bfd_link_info *info, | |
4344 | asection *sec, | |
4345 | const Elf_Internal_Rela *relocs) | |
4346 | { | |
4347 | struct ppc_elf_link_hash_table *htab; | |
4348 | Elf_Internal_Shdr *symtab_hdr; | |
4349 | struct elf_link_hash_entry **sym_hashes; | |
4350 | bfd_signed_vma *local_got_refcounts; | |
4351 | const Elf_Internal_Rela *rel, *relend; | |
a6aa5195 | 4352 | asection *got2; |
25dbc73a | 4353 | |
7dda2462 TG |
4354 | if (info->relocatable) |
4355 | return TRUE; | |
4356 | ||
c87b5a93 AM |
4357 | if ((sec->flags & SEC_ALLOC) == 0) |
4358 | return TRUE; | |
4359 | ||
25dbc73a AM |
4360 | elf_section_data (sec)->local_dynrel = NULL; |
4361 | ||
4362 | htab = ppc_elf_hash_table (info); | |
0ffa91dd | 4363 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a AM |
4364 | sym_hashes = elf_sym_hashes (abfd); |
4365 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
a6aa5195 | 4366 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
4367 | |
4368 | relend = relocs + sec->reloc_count; | |
4369 | for (rel = relocs; rel < relend; rel++) | |
4370 | { | |
4371 | unsigned long r_symndx; | |
4372 | enum elf_ppc_reloc_type r_type; | |
4373 | struct elf_link_hash_entry *h = NULL; | |
4374 | ||
4375 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4376 | if (r_symndx >= symtab_hdr->sh_info) | |
a876ecf9 | 4377 | { |
6061a67d | 4378 | struct elf_dyn_relocs **pp, *p; |
25dbc73a AM |
4379 | struct ppc_elf_link_hash_entry *eh; |
4380 | ||
4381 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4382 | while (h->root.type == bfd_link_hash_indirect | |
4383 | || h->root.type == bfd_link_hash_warning) | |
4384 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4385 | eh = (struct ppc_elf_link_hash_entry *) h; | |
4386 | ||
4387 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4388 | if (p->sec == sec) | |
4389 | { | |
4390 | /* Everything must go for SEC. */ | |
4391 | *pp = p->next; | |
4392 | break; | |
4393 | } | |
a876ecf9 | 4394 | } |
ee05f2fe | 4395 | |
25dbc73a | 4396 | r_type = ELF32_R_TYPE (rel->r_info); |
de972ffa AM |
4397 | if (!htab->is_vxworks |
4398 | && h == NULL | |
4399 | && local_got_refcounts != NULL | |
4400 | && (!info->shared | |
4401 | || is_branch_reloc (r_type))) | |
e054468f | 4402 | { |
de972ffa AM |
4403 | struct plt_entry **local_plt = (struct plt_entry **) |
4404 | (local_got_refcounts + symtab_hdr->sh_info); | |
4405 | char *local_got_tls_masks = (char *) | |
4406 | (local_plt + symtab_hdr->sh_info); | |
4407 | if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0) | |
e054468f | 4408 | { |
de972ffa | 4409 | struct plt_entry **ifunc = local_plt + r_symndx; |
a877a2b6 AM |
4410 | bfd_vma addend = 0; |
4411 | struct plt_entry *ent; | |
4412 | ||
4413 | if (r_type == R_PPC_PLTREL24 && info->shared) | |
4414 | addend = rel->r_addend; | |
4415 | ent = find_plt_ent (ifunc, got2, addend); | |
e054468f AM |
4416 | if (ent->plt.refcount > 0) |
4417 | ent->plt.refcount -= 1; | |
4418 | continue; | |
4419 | } | |
4420 | } | |
4421 | ||
25dbc73a | 4422 | switch (r_type) |
ee05f2fe | 4423 | { |
25dbc73a AM |
4424 | case R_PPC_GOT_TLSLD16: |
4425 | case R_PPC_GOT_TLSLD16_LO: | |
4426 | case R_PPC_GOT_TLSLD16_HI: | |
4427 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
4428 | case R_PPC_GOT_TLSGD16: |
4429 | case R_PPC_GOT_TLSGD16_LO: | |
4430 | case R_PPC_GOT_TLSGD16_HI: | |
4431 | case R_PPC_GOT_TLSGD16_HA: | |
4432 | case R_PPC_GOT_TPREL16: | |
4433 | case R_PPC_GOT_TPREL16_LO: | |
4434 | case R_PPC_GOT_TPREL16_HI: | |
4435 | case R_PPC_GOT_TPREL16_HA: | |
4436 | case R_PPC_GOT_DTPREL16: | |
4437 | case R_PPC_GOT_DTPREL16_LO: | |
4438 | case R_PPC_GOT_DTPREL16_HI: | |
4439 | case R_PPC_GOT_DTPREL16_HA: | |
4440 | case R_PPC_GOT16: | |
4441 | case R_PPC_GOT16_LO: | |
4442 | case R_PPC_GOT16_HI: | |
4443 | case R_PPC_GOT16_HA: | |
4444 | if (h != NULL) | |
ee05f2fe | 4445 | { |
25dbc73a AM |
4446 | if (h->got.refcount > 0) |
4447 | h->got.refcount--; | |
91e21fb7 AM |
4448 | if (!info->shared) |
4449 | { | |
4450 | struct plt_entry *ent; | |
4451 | ||
4452 | ent = find_plt_ent (&h->plt.plist, NULL, 0); | |
32af9f6e | 4453 | if (ent != NULL && ent->plt.refcount > 0) |
91e21fb7 AM |
4454 | ent->plt.refcount -= 1; |
4455 | } | |
ee05f2fe | 4456 | } |
25dbc73a AM |
4457 | else if (local_got_refcounts != NULL) |
4458 | { | |
4459 | if (local_got_refcounts[r_symndx] > 0) | |
4460 | local_got_refcounts[r_symndx]--; | |
4461 | } | |
4462 | break; | |
ee05f2fe | 4463 | |
25dbc73a AM |
4464 | case R_PPC_REL24: |
4465 | case R_PPC_REL14: | |
4466 | case R_PPC_REL14_BRTAKEN: | |
4467 | case R_PPC_REL14_BRNTAKEN: | |
4468 | case R_PPC_REL32: | |
3b36f7e6 | 4469 | if (h == NULL || h == htab->elf.hgot) |
25dbc73a AM |
4470 | break; |
4471 | /* Fall thru */ | |
ee05f2fe | 4472 | |
25dbc73a AM |
4473 | case R_PPC_ADDR32: |
4474 | case R_PPC_ADDR24: | |
4475 | case R_PPC_ADDR16: | |
4476 | case R_PPC_ADDR16_LO: | |
4477 | case R_PPC_ADDR16_HI: | |
4478 | case R_PPC_ADDR16_HA: | |
4479 | case R_PPC_ADDR14: | |
4480 | case R_PPC_ADDR14_BRTAKEN: | |
4481 | case R_PPC_ADDR14_BRNTAKEN: | |
4482 | case R_PPC_UADDR32: | |
4483 | case R_PPC_UADDR16: | |
87538722 AM |
4484 | if (info->shared) |
4485 | break; | |
4486 | ||
25dbc73a AM |
4487 | case R_PPC_PLT32: |
4488 | case R_PPC_PLTREL24: | |
87538722 | 4489 | case R_PPC_PLTREL32: |
25dbc73a AM |
4490 | case R_PPC_PLT16_LO: |
4491 | case R_PPC_PLT16_HI: | |
4492 | case R_PPC_PLT16_HA: | |
4493 | if (h != NULL) | |
4494 | { | |
a877a2b6 AM |
4495 | bfd_vma addend = 0; |
4496 | struct plt_entry *ent; | |
4497 | ||
4498 | if (r_type == R_PPC_PLTREL24 && info->shared) | |
4499 | addend = rel->r_addend; | |
4500 | ent = find_plt_ent (&h->plt.plist, got2, addend); | |
32af9f6e | 4501 | if (ent != NULL && ent->plt.refcount > 0) |
a6aa5195 | 4502 | ent->plt.refcount -= 1; |
25dbc73a AM |
4503 | } |
4504 | break; | |
ee05f2fe | 4505 | |
25dbc73a AM |
4506 | default: |
4507 | break; | |
4508 | } | |
7fce784e | 4509 | } |
7fce784e AS |
4510 | return TRUE; |
4511 | } | |
25dbc73a | 4512 | \f |
3a71aa26 AM |
4513 | /* Set plt output section type, htab->tls_get_addr, and call the |
4514 | generic ELF tls_setup function. */ | |
7fce784e | 4515 | |
25dbc73a | 4516 | asection * |
a7f2871e AM |
4517 | ppc_elf_tls_setup (bfd *obfd, |
4518 | struct bfd_link_info *info, | |
4519 | int no_tls_get_addr_opt) | |
7fce784e | 4520 | { |
25dbc73a | 4521 | struct ppc_elf_link_hash_table *htab; |
7fce784e | 4522 | |
25dbc73a | 4523 | htab = ppc_elf_hash_table (info); |
a7f2871e AM |
4524 | htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
4525 | FALSE, FALSE, TRUE); | |
4526 | if (!no_tls_get_addr_opt) | |
4527 | { | |
4528 | struct elf_link_hash_entry *opt, *tga; | |
4529 | opt = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt", | |
4530 | FALSE, FALSE, TRUE); | |
4531 | if (opt != NULL | |
4532 | && (opt->root.type == bfd_link_hash_defined | |
4533 | || opt->root.type == bfd_link_hash_defweak)) | |
4534 | { | |
4535 | /* If glibc supports an optimized __tls_get_addr call stub, | |
4536 | signalled by the presence of __tls_get_addr_opt, and we'll | |
4537 | be calling __tls_get_addr via a plt call stub, then | |
4538 | make __tls_get_addr point to __tls_get_addr_opt. */ | |
4539 | tga = htab->tls_get_addr; | |
4540 | if (htab->elf.dynamic_sections_created | |
4541 | && tga != NULL | |
4542 | && (tga->type == STT_FUNC | |
4543 | || tga->needs_plt) | |
4544 | && !(SYMBOL_CALLS_LOCAL (info, tga) | |
4545 | || (ELF_ST_VISIBILITY (tga->other) != STV_DEFAULT | |
4546 | && tga->root.type == bfd_link_hash_undefweak))) | |
4547 | { | |
4548 | struct plt_entry *ent; | |
32af9f6e AM |
4549 | for (ent = tga->plt.plist; ent != NULL; ent = ent->next) |
4550 | if (ent->plt.refcount > 0) | |
4551 | break; | |
4552 | if (ent != NULL) | |
a7f2871e AM |
4553 | { |
4554 | tga->root.type = bfd_link_hash_indirect; | |
4555 | tga->root.u.i.link = &opt->root; | |
4556 | ppc_elf_copy_indirect_symbol (info, opt, tga); | |
4557 | if (opt->dynindx != -1) | |
4558 | { | |
4559 | /* Use __tls_get_addr_opt in dynamic relocations. */ | |
4560 | opt->dynindx = -1; | |
4561 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
4562 | opt->dynstr_index); | |
4563 | if (!bfd_elf_link_record_dynamic_symbol (info, opt)) | |
4564 | return FALSE; | |
4565 | } | |
4566 | htab->tls_get_addr = opt; | |
4567 | } | |
4568 | } | |
4569 | } | |
4570 | else | |
4571 | no_tls_get_addr_opt = TRUE; | |
4572 | } | |
4573 | htab->no_tls_get_addr_opt = no_tls_get_addr_opt; | |
4a3dc543 | 4574 | if (htab->plt_type == PLT_NEW |
d7128ce4 AM |
4575 | && htab->plt != NULL |
4576 | && htab->plt->output_section != NULL) | |
4577 | { | |
4578 | elf_section_type (htab->plt->output_section) = SHT_PROGBITS; | |
4579 | elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE; | |
4580 | } | |
4581 | ||
25dbc73a | 4582 | return _bfd_elf_tls_setup (obfd, info); |
7fce784e AS |
4583 | } |
4584 | ||
3a71aa26 AM |
4585 | /* Return TRUE iff REL is a branch reloc with a global symbol matching |
4586 | HASH. */ | |
4587 | ||
4588 | static bfd_boolean | |
4589 | branch_reloc_hash_match (const bfd *ibfd, | |
4590 | const Elf_Internal_Rela *rel, | |
4591 | const struct elf_link_hash_entry *hash) | |
4592 | { | |
4593 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); | |
4594 | enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info); | |
4595 | unsigned int r_symndx = ELF32_R_SYM (rel->r_info); | |
4596 | ||
e054468f | 4597 | if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type)) |
3a71aa26 AM |
4598 | { |
4599 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
4600 | struct elf_link_hash_entry *h; | |
4601 | ||
4602 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4603 | while (h->root.type == bfd_link_hash_indirect | |
4604 | || h->root.type == bfd_link_hash_warning) | |
4605 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4606 | if (h == hash) | |
4607 | return TRUE; | |
4608 | } | |
4609 | return FALSE; | |
4610 | } | |
4611 | ||
25dbc73a AM |
4612 | /* Run through all the TLS relocs looking for optimization |
4613 | opportunities. */ | |
252b5132 | 4614 | |
25dbc73a AM |
4615 | bfd_boolean |
4616 | ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, | |
4617 | struct bfd_link_info *info) | |
252b5132 | 4618 | { |
7fce784e | 4619 | bfd *ibfd; |
25dbc73a AM |
4620 | asection *sec; |
4621 | struct ppc_elf_link_hash_table *htab; | |
b7fcf6f6 | 4622 | int pass; |
252b5132 | 4623 | |
1d483afe | 4624 | if (info->relocatable || !info->executable) |
25dbc73a | 4625 | return TRUE; |
252b5132 | 4626 | |
7619e7c7 | 4627 | htab = ppc_elf_hash_table (info); |
663a1470 AM |
4628 | if (htab == NULL) |
4629 | return FALSE; | |
4630 | ||
b7fcf6f6 AM |
4631 | /* Make two passes through the relocs. First time check that tls |
4632 | relocs involved in setting up a tls_get_addr call are indeed | |
663a1470 AM |
4633 | followed by such a call. If they are not, don't do any tls |
4634 | optimization. On the second pass twiddle tls_mask flags to | |
4635 | notify relocate_section that optimization can be done, and | |
4636 | adjust got and plt refcounts. */ | |
b7fcf6f6 AM |
4637 | for (pass = 0; pass < 2; ++pass) |
4638 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
4639 | { | |
4640 | Elf_Internal_Sym *locsyms = NULL; | |
0ffa91dd | 4641 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); |
32af9f6e | 4642 | asection *got2 = bfd_get_section_by_name (ibfd, ".got2"); |
7619e7c7 | 4643 | |
b7fcf6f6 AM |
4644 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
4645 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
4646 | { | |
4647 | Elf_Internal_Rela *relstart, *rel, *relend; | |
663a1470 | 4648 | int expecting_tls_get_addr = 0; |
252b5132 | 4649 | |
b7fcf6f6 AM |
4650 | /* Read the relocations. */ |
4651 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, | |
4652 | info->keep_memory); | |
4653 | if (relstart == NULL) | |
4654 | return FALSE; | |
7619e7c7 | 4655 | |
b7fcf6f6 AM |
4656 | relend = relstart + sec->reloc_count; |
4657 | for (rel = relstart; rel < relend; rel++) | |
4658 | { | |
4659 | enum elf_ppc_reloc_type r_type; | |
4660 | unsigned long r_symndx; | |
4661 | struct elf_link_hash_entry *h = NULL; | |
4662 | char *tls_mask; | |
4663 | char tls_set, tls_clear; | |
4664 | bfd_boolean is_local; | |
b7fcf6f6 AM |
4665 | bfd_signed_vma *got_count; |
4666 | ||
4667 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4668 | if (r_symndx >= symtab_hdr->sh_info) | |
4669 | { | |
4670 | struct elf_link_hash_entry **sym_hashes; | |
7fce784e | 4671 | |
b7fcf6f6 AM |
4672 | sym_hashes = elf_sym_hashes (ibfd); |
4673 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4674 | while (h->root.type == bfd_link_hash_indirect | |
4675 | || h->root.type == bfd_link_hash_warning) | |
4676 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4677 | } | |
7619e7c7 | 4678 | |
b7fcf6f6 AM |
4679 | is_local = FALSE; |
4680 | if (h == NULL | |
4681 | || !h->def_dynamic) | |
4682 | is_local = TRUE; | |
7619e7c7 | 4683 | |
b7fcf6f6 | 4684 | r_type = ELF32_R_TYPE (rel->r_info); |
663a1470 AM |
4685 | /* If this section has old-style __tls_get_addr calls |
4686 | without marker relocs, then check that each | |
4687 | __tls_get_addr call reloc is preceded by a reloc | |
4688 | that conceivably belongs to the __tls_get_addr arg | |
4689 | setup insn. If we don't find matching arg setup | |
4690 | relocs, don't do any tls optimization. */ | |
4691 | if (pass == 0 | |
4692 | && sec->has_tls_get_addr_call | |
4693 | && h != NULL | |
4694 | && h == htab->tls_get_addr | |
4695 | && !expecting_tls_get_addr | |
4696 | && is_branch_reloc (r_type)) | |
4697 | { | |
25f53a85 | 4698 | info->callbacks->minfo ("%H __tls_get_addr lost arg, " |
663a1470 AM |
4699 | "TLS optimization disabled\n", |
4700 | ibfd, sec, rel->r_offset); | |
4701 | if (elf_section_data (sec)->relocs != relstart) | |
4702 | free (relstart); | |
4703 | return TRUE; | |
4704 | } | |
4705 | ||
4706 | expecting_tls_get_addr = 0; | |
b7fcf6f6 AM |
4707 | switch (r_type) |
4708 | { | |
4709 | case R_PPC_GOT_TLSLD16: | |
4710 | case R_PPC_GOT_TLSLD16_LO: | |
4711 | expecting_tls_get_addr = 1; | |
4712 | /* Fall thru */ | |
4713 | ||
4714 | case R_PPC_GOT_TLSLD16_HI: | |
4715 | case R_PPC_GOT_TLSLD16_HA: | |
4716 | /* These relocs should never be against a symbol | |
4717 | defined in a shared lib. Leave them alone if | |
4718 | that turns out to be the case. */ | |
4719 | if (!is_local) | |
4720 | continue; | |
4721 | ||
4722 | /* LD -> LE */ | |
4723 | tls_set = 0; | |
4724 | tls_clear = TLS_LD; | |
4725 | break; | |
4726 | ||
4727 | case R_PPC_GOT_TLSGD16: | |
4728 | case R_PPC_GOT_TLSGD16_LO: | |
4729 | expecting_tls_get_addr = 1; | |
4730 | /* Fall thru */ | |
4731 | ||
4732 | case R_PPC_GOT_TLSGD16_HI: | |
4733 | case R_PPC_GOT_TLSGD16_HA: | |
4734 | if (is_local) | |
4735 | /* GD -> LE */ | |
4736 | tls_set = 0; | |
4737 | else | |
4738 | /* GD -> IE */ | |
4739 | tls_set = TLS_TLS | TLS_TPRELGD; | |
4740 | tls_clear = TLS_GD; | |
4741 | break; | |
4742 | ||
4743 | case R_PPC_GOT_TPREL16: | |
4744 | case R_PPC_GOT_TPREL16_LO: | |
4745 | case R_PPC_GOT_TPREL16_HI: | |
4746 | case R_PPC_GOT_TPREL16_HA: | |
4747 | if (is_local) | |
4748 | { | |
4749 | /* IE -> LE */ | |
4750 | tls_set = 0; | |
4751 | tls_clear = TLS_TPREL; | |
4752 | break; | |
4753 | } | |
4754 | else | |
4755 | continue; | |
4756 | ||
32af9f6e AM |
4757 | case R_PPC_TLSGD: |
4758 | case R_PPC_TLSLD: | |
4759 | expecting_tls_get_addr = 2; | |
4760 | tls_set = 0; | |
4761 | tls_clear = 0; | |
4762 | break; | |
4763 | ||
b7fcf6f6 | 4764 | default: |
25dbc73a | 4765 | continue; |
b7fcf6f6 | 4766 | } |
25dbc73a | 4767 | |
b7fcf6f6 AM |
4768 | if (pass == 0) |
4769 | { | |
727fc41e | 4770 | if (!expecting_tls_get_addr |
32af9f6e AM |
4771 | || (expecting_tls_get_addr == 1 |
4772 | && !sec->has_tls_get_addr_call)) | |
b7fcf6f6 | 4773 | continue; |
25dbc73a | 4774 | |
3a71aa26 AM |
4775 | if (rel + 1 < relend |
4776 | && branch_reloc_hash_match (ibfd, rel + 1, | |
4777 | htab->tls_get_addr)) | |
4778 | continue; | |
25dbc73a | 4779 | |
b7fcf6f6 AM |
4780 | /* Uh oh, we didn't find the expected call. We |
4781 | could just mark this symbol to exclude it | |
4782 | from tls optimization but it's safer to skip | |
663a1470 | 4783 | the entire optimization. */ |
25f53a85 | 4784 | info->callbacks->minfo (_("%H arg lost __tls_get_addr, " |
663a1470 AM |
4785 | "TLS optimization disabled\n"), |
4786 | ibfd, sec, rel->r_offset); | |
4787 | if (elf_section_data (sec)->relocs != relstart) | |
4788 | free (relstart); | |
4789 | return TRUE; | |
b7fcf6f6 | 4790 | } |
25dbc73a | 4791 | |
32af9f6e AM |
4792 | if (expecting_tls_get_addr) |
4793 | { | |
4794 | struct plt_entry *ent; | |
4795 | bfd_vma addend = 0; | |
4796 | ||
4797 | if (info->shared | |
4798 | && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24) | |
4799 | addend = rel[1].r_addend; | |
4800 | ent = find_plt_ent (&htab->tls_get_addr->plt.plist, | |
4801 | got2, addend); | |
4802 | if (ent != NULL && ent->plt.refcount > 0) | |
4803 | ent->plt.refcount -= 1; | |
4804 | ||
4805 | if (expecting_tls_get_addr == 2) | |
4806 | continue; | |
4807 | } | |
4808 | ||
b7fcf6f6 AM |
4809 | if (h != NULL) |
4810 | { | |
4811 | tls_mask = &ppc_elf_hash_entry (h)->tls_mask; | |
4812 | got_count = &h->got.refcount; | |
4813 | } | |
4814 | else | |
4815 | { | |
b7fcf6f6 | 4816 | bfd_signed_vma *lgot_refs; |
e054468f | 4817 | struct plt_entry **local_plt; |
b7fcf6f6 | 4818 | char *lgot_masks; |
25dbc73a | 4819 | |
b7fcf6f6 AM |
4820 | if (locsyms == NULL) |
4821 | { | |
4822 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4823 | if (locsyms == NULL) | |
4824 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
4825 | symtab_hdr->sh_info, | |
4826 | 0, NULL, NULL, NULL); | |
4827 | if (locsyms == NULL) | |
4828 | { | |
4829 | if (elf_section_data (sec)->relocs != relstart) | |
4830 | free (relstart); | |
4831 | return FALSE; | |
4832 | } | |
4833 | } | |
b7fcf6f6 AM |
4834 | lgot_refs = elf_local_got_refcounts (ibfd); |
4835 | if (lgot_refs == NULL) | |
4836 | abort (); | |
e054468f AM |
4837 | local_plt = (struct plt_entry **) |
4838 | (lgot_refs + symtab_hdr->sh_info); | |
4839 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
b7fcf6f6 AM |
4840 | tls_mask = &lgot_masks[r_symndx]; |
4841 | got_count = &lgot_refs[r_symndx]; | |
4842 | } | |
25dbc73a | 4843 | |
b7fcf6f6 AM |
4844 | if (tls_set == 0) |
4845 | { | |
4846 | /* We managed to get rid of a got entry. */ | |
4847 | if (*got_count > 0) | |
4848 | *got_count -= 1; | |
4849 | } | |
25dbc73a | 4850 | |
b7fcf6f6 AM |
4851 | *tls_mask |= tls_set; |
4852 | *tls_mask &= ~tls_clear; | |
4853 | } | |
25dbc73a | 4854 | |
b7fcf6f6 AM |
4855 | if (elf_section_data (sec)->relocs != relstart) |
4856 | free (relstart); | |
4857 | } | |
4858 | ||
4859 | if (locsyms != NULL | |
4860 | && (symtab_hdr->contents != (unsigned char *) locsyms)) | |
4861 | { | |
4862 | if (!info->keep_memory) | |
4863 | free (locsyms); | |
4864 | else | |
4865 | symtab_hdr->contents = (unsigned char *) locsyms; | |
4866 | } | |
4867 | } | |
25dbc73a AM |
4868 | return TRUE; |
4869 | } | |
4870 | \f | |
625af618 AM |
4871 | /* Return true if we have dynamic relocs that apply to read-only sections. */ |
4872 | ||
4873 | static bfd_boolean | |
4874 | readonly_dynrelocs (struct elf_link_hash_entry *h) | |
4875 | { | |
6061a67d | 4876 | struct elf_dyn_relocs *p; |
625af618 AM |
4877 | |
4878 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) | |
4879 | { | |
4880 | asection *s = p->sec->output_section; | |
4881 | ||
4882 | if (s != NULL | |
4883 | && ((s->flags & (SEC_READONLY | SEC_ALLOC)) | |
4884 | == (SEC_READONLY | SEC_ALLOC))) | |
4885 | return TRUE; | |
4886 | } | |
4887 | return FALSE; | |
4888 | } | |
4889 | ||
25dbc73a AM |
4890 | /* Adjust a symbol defined by a dynamic object and referenced by a |
4891 | regular object. The current definition is in some section of the | |
4892 | dynamic object, but we're not including those sections. We have to | |
4893 | change the definition to something the rest of the link can | |
4894 | understand. */ | |
7fce784e | 4895 | |
25dbc73a AM |
4896 | static bfd_boolean |
4897 | ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, | |
4898 | struct elf_link_hash_entry *h) | |
4899 | { | |
4900 | struct ppc_elf_link_hash_table *htab; | |
4901 | asection *s; | |
7fce784e | 4902 | |
25dbc73a AM |
4903 | #ifdef DEBUG |
4904 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", | |
4905 | h->root.root.string); | |
4906 | #endif | |
252b5132 | 4907 | |
25dbc73a AM |
4908 | /* Make sure we know what is going on here. */ |
4909 | htab = ppc_elf_hash_table (info); | |
4910 | BFD_ASSERT (htab->elf.dynobj != NULL | |
4911 | && (h->needs_plt | |
91e21fb7 | 4912 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
4913 | || h->u.weakdef != NULL |
4914 | || (h->def_dynamic | |
4915 | && h->ref_regular | |
4916 | && !h->def_regular))); | |
252b5132 | 4917 | |
25dbc73a AM |
4918 | /* Deal with function syms. */ |
4919 | if (h->type == STT_FUNC | |
e054468f | 4920 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
4921 | || h->needs_plt) |
4922 | { | |
4923 | /* Clear procedure linkage table information for any symbol that | |
4924 | won't need a .plt entry. */ | |
a6aa5195 AM |
4925 | struct plt_entry *ent; |
4926 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4927 | if (ent->plt.refcount > 0) | |
4928 | break; | |
4929 | if (ent == NULL | |
e054468f AM |
4930 | || (h->type != STT_GNU_IFUNC |
4931 | && (SYMBOL_CALLS_LOCAL (info, h) | |
4932 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4933 | && h->root.type == bfd_link_hash_undefweak)))) | |
252b5132 | 4934 | { |
25dbc73a | 4935 | /* A PLT entry is not required/allowed when: |
252b5132 | 4936 | |
25dbc73a AM |
4937 | 1. We are not using ld.so; because then the PLT entry |
4938 | can't be set up, so we can't use one. In this case, | |
4939 | ppc_elf_adjust_dynamic_symbol won't even be called. | |
252b5132 | 4940 | |
25dbc73a AM |
4941 | 2. GC has rendered the entry unused. |
4942 | ||
4943 | 3. We know for certain that a call to this symbol | |
4944 | will go to this object, or will remain undefined. */ | |
a6aa5195 | 4945 | h->plt.plist = NULL; |
25dbc73a AM |
4946 | h->needs_plt = 0; |
4947 | } | |
625af618 AM |
4948 | else |
4949 | { | |
25f23106 AM |
4950 | /* After adjust_dynamic_symbol, non_got_ref set in the |
4951 | non-shared case means that we have allocated space in | |
4952 | .dynbss for the symbol and thus dyn_relocs for this | |
4953 | symbol should be discarded. | |
625af618 AM |
4954 | If we get here we know we are making a PLT entry for this |
4955 | symbol, and in an executable we'd normally resolve | |
4956 | relocations against this symbol to the PLT entry. Allow | |
4957 | dynamic relocs if the reference is weak, and the dynamic | |
4958 | relocs will not cause text relocation. */ | |
4959 | if (!h->ref_regular_nonweak | |
4960 | && h->non_got_ref | |
25f23106 | 4961 | && h->type != STT_GNU_IFUNC |
625af618 AM |
4962 | && !htab->is_vxworks |
4963 | && !ppc_elf_hash_entry (h)->has_sda_refs | |
4964 | && !readonly_dynrelocs (h)) | |
4965 | h->non_got_ref = 0; | |
4966 | } | |
25dbc73a | 4967 | return TRUE; |
252b5132 | 4968 | } |
25dbc73a | 4969 | else |
a6aa5195 | 4970 | h->plt.plist = NULL; |
252b5132 | 4971 | |
25dbc73a AM |
4972 | /* If this is a weak symbol, and there is a real definition, the |
4973 | processor independent code will have arranged for us to see the | |
4974 | real definition first, and we can just use the same value. */ | |
4975 | if (h->u.weakdef != NULL) | |
252b5132 | 4976 | { |
25dbc73a AM |
4977 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
4978 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
4979 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
4980 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
4981 | if (ELIMINATE_COPY_RELOCS) | |
4982 | h->non_got_ref = h->u.weakdef->non_got_ref; | |
4983 | return TRUE; | |
4984 | } | |
dc810e39 | 4985 | |
25dbc73a AM |
4986 | /* This is a reference to a symbol defined by a dynamic object which |
4987 | is not a function. */ | |
252b5132 | 4988 | |
25dbc73a AM |
4989 | /* If we are creating a shared library, we must presume that the |
4990 | only references to the symbol are via the global offset table. | |
4991 | For such cases we need not do anything here; the relocations will | |
4992 | be handled correctly by relocate_section. */ | |
4993 | if (info->shared) | |
4994 | return TRUE; | |
252b5132 | 4995 | |
25dbc73a AM |
4996 | /* If there are no references to this symbol that do not use the |
4997 | GOT, we don't need to generate a copy reloc. */ | |
4998 | if (!h->non_got_ref) | |
4999 | return TRUE; | |
5000 | ||
cfd2c773 NS |
5001 | /* If we didn't find any dynamic relocs in read-only sections, then |
5002 | we'll be keeping the dynamic relocs and avoiding the copy reloc. | |
5003 | We can't do this if there are any small data relocations. This | |
5004 | doesn't work on VxWorks, where we can not have dynamic | |
5005 | relocations (other than copy and jump slot relocations) in an | |
5006 | executable. */ | |
4dc4a9a5 | 5007 | if (ELIMINATE_COPY_RELOCS |
cfd2c773 | 5008 | && !ppc_elf_hash_entry (h)->has_sda_refs |
625af618 AM |
5009 | && !htab->is_vxworks |
5010 | && !h->def_regular | |
5011 | && !readonly_dynrelocs (h)) | |
25dbc73a | 5012 | { |
625af618 AM |
5013 | h->non_got_ref = 0; |
5014 | return TRUE; | |
252b5132 RH |
5015 | } |
5016 | ||
909272ee AM |
5017 | if (h->size == 0) |
5018 | { | |
25f53a85 AM |
5019 | info->callbacks->einfo (_("dynamic variable `%s' is zero size\n"), |
5020 | h->root.root.string); | |
909272ee AM |
5021 | return TRUE; |
5022 | } | |
5023 | ||
25dbc73a AM |
5024 | /* We must allocate the symbol in our .dynbss section, which will |
5025 | become part of the .bss section of the executable. There will be | |
5026 | an entry for this symbol in the .dynsym section. The dynamic | |
5027 | object will contain position independent code, so all references | |
5028 | from the dynamic object to this symbol will go through the global | |
5029 | offset table. The dynamic linker will use the .dynsym entry to | |
5030 | determine the address it must put in the global offset table, so | |
5031 | both the dynamic object and the regular object will refer to the | |
5032 | same memory location for the variable. | |
5033 | ||
4dc4a9a5 DJ |
5034 | Of course, if the symbol is referenced using SDAREL relocs, we |
5035 | must instead allocate it in .sbss. */ | |
25dbc73a | 5036 | |
4dc4a9a5 | 5037 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
5038 | s = htab->dynsbss; |
5039 | else | |
5040 | s = htab->dynbss; | |
5041 | BFD_ASSERT (s != NULL); | |
5042 | ||
5043 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
5044 | copy the initial value out of the dynamic object and into the | |
5045 | runtime process image. We need to remember the offset into the | |
5046 | .rela.bss section we are going to use. */ | |
5047 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
5048 | { | |
5049 | asection *srel; | |
5050 | ||
4dc4a9a5 | 5051 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
5052 | srel = htab->relsbss; |
5053 | else | |
5054 | srel = htab->relbss; | |
5055 | BFD_ASSERT (srel != NULL); | |
5056 | srel->size += sizeof (Elf32_External_Rela); | |
5057 | h->needs_copy = 1; | |
5058 | } | |
7619e7c7 | 5059 | |
027297b7 | 5060 | return _bfd_elf_adjust_dynamic_copy (h, s); |
25dbc73a AM |
5061 | } |
5062 | \f | |
ac39eb42 AM |
5063 | /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is |
5064 | xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0, | |
5065 | specifying the addend on the plt relocation. For -fpic code, the sym | |
5066 | is xxxxxxxx.plt_pic32.<callee>, and for -fPIC | |
5067 | xxxxxxxx.got2.plt_pic32.<callee>. */ | |
0ba07910 AM |
5068 | |
5069 | static bfd_boolean | |
5070 | add_stub_sym (struct plt_entry *ent, | |
5071 | struct elf_link_hash_entry *h, | |
ac39eb42 | 5072 | struct bfd_link_info *info) |
0ba07910 AM |
5073 | { |
5074 | struct elf_link_hash_entry *sh; | |
5075 | size_t len1, len2, len3; | |
5076 | char *name; | |
ac39eb42 AM |
5077 | const char *stub; |
5078 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
5079 | ||
a877a2b6 | 5080 | if (info->shared) |
ac39eb42 AM |
5081 | stub = ".plt_pic32."; |
5082 | else | |
5083 | stub = ".plt_call32."; | |
0ba07910 AM |
5084 | |
5085 | len1 = strlen (h->root.root.string); | |
ac39eb42 | 5086 | len2 = strlen (stub); |
0ba07910 AM |
5087 | len3 = 0; |
5088 | if (ent->sec) | |
5089 | len3 = strlen (ent->sec->name); | |
ac39eb42 | 5090 | name = bfd_malloc (len1 + len2 + len3 + 9); |
0ba07910 AM |
5091 | if (name == NULL) |
5092 | return FALSE; | |
5093 | sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff); | |
5094 | if (ent->sec) | |
5095 | memcpy (name + 8, ent->sec->name, len3); | |
ac39eb42 AM |
5096 | memcpy (name + 8 + len3, stub, len2); |
5097 | memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1); | |
0ba07910 AM |
5098 | sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE); |
5099 | if (sh == NULL) | |
5100 | return FALSE; | |
5101 | if (sh->root.type == bfd_link_hash_new) | |
5102 | { | |
5103 | sh->root.type = bfd_link_hash_defined; | |
5104 | sh->root.u.def.section = htab->glink; | |
5105 | sh->root.u.def.value = ent->glink_offset; | |
5106 | sh->ref_regular = 1; | |
5107 | sh->def_regular = 1; | |
5108 | sh->ref_regular_nonweak = 1; | |
5109 | sh->forced_local = 1; | |
5110 | sh->non_elf = 0; | |
5111 | } | |
5112 | return TRUE; | |
5113 | } | |
5114 | ||
3b36f7e6 AM |
5115 | /* Allocate NEED contiguous space in .got, and return the offset. |
5116 | Handles allocation of the got header when crossing 32k. */ | |
5117 | ||
5118 | static bfd_vma | |
5119 | allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need) | |
5120 | { | |
5121 | bfd_vma where; | |
4a3dc543 | 5122 | unsigned int max_before_header; |
3b36f7e6 | 5123 | |
4a3dc543 | 5124 | if (htab->plt_type == PLT_VXWORKS) |
9d8504b1 PB |
5125 | { |
5126 | where = htab->got->size; | |
5127 | htab->got->size += need; | |
5128 | } | |
3b36f7e6 AM |
5129 | else |
5130 | { | |
4a3dc543 RS |
5131 | max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764; |
5132 | if (need <= htab->got_gap) | |
3b36f7e6 | 5133 | { |
4a3dc543 RS |
5134 | where = max_before_header - htab->got_gap; |
5135 | htab->got_gap -= need; | |
5136 | } | |
5137 | else | |
5138 | { | |
5139 | if (htab->got->size + need > max_before_header | |
5140 | && htab->got->size <= max_before_header) | |
5141 | { | |
5142 | htab->got_gap = max_before_header - htab->got->size; | |
5143 | htab->got->size = max_before_header + htab->got_header_size; | |
5144 | } | |
5145 | where = htab->got->size; | |
5146 | htab->got->size += need; | |
3b36f7e6 | 5147 | } |
3b36f7e6 AM |
5148 | } |
5149 | return where; | |
5150 | } | |
5151 | ||
25dbc73a | 5152 | /* Allocate space in associated reloc sections for dynamic relocs. */ |
252b5132 | 5153 | |
b34976b6 | 5154 | static bfd_boolean |
25dbc73a | 5155 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
252b5132 | 5156 | { |
25dbc73a AM |
5157 | struct bfd_link_info *info = inf; |
5158 | struct ppc_elf_link_hash_entry *eh; | |
7619e7c7 | 5159 | struct ppc_elf_link_hash_table *htab; |
6061a67d | 5160 | struct elf_dyn_relocs *p; |
252b5132 | 5161 | |
25dbc73a | 5162 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5163 | return TRUE; |
252b5132 | 5164 | |
7619e7c7 | 5165 | htab = ppc_elf_hash_table (info); |
e054468f AM |
5166 | if (htab->elf.dynamic_sections_created |
5167 | || h->type == STT_GNU_IFUNC) | |
252b5132 | 5168 | { |
a6aa5195 AM |
5169 | struct plt_entry *ent; |
5170 | bfd_boolean doneone = FALSE; | |
28e99bb6 | 5171 | bfd_vma plt_offset = 0, glink_offset = 0; |
e054468f | 5172 | bfd_boolean dyn; |
28e99bb6 | 5173 | |
a6aa5195 AM |
5174 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
5175 | if (ent->plt.refcount > 0) | |
5176 | { | |
5177 | /* Make sure this symbol is output as a dynamic symbol. */ | |
5178 | if (h->dynindx == -1 | |
e054468f AM |
5179 | && !h->forced_local |
5180 | && !h->def_regular | |
5181 | && htab->elf.dynamic_sections_created) | |
a6aa5195 AM |
5182 | { |
5183 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5184 | return FALSE; | |
5185 | } | |
252b5132 | 5186 | |
e054468f | 5187 | dyn = htab->elf.dynamic_sections_created; |
a6aa5195 | 5188 | if (info->shared |
e054468f AM |
5189 | || h->type == STT_GNU_IFUNC |
5190 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
a6aa5195 AM |
5191 | { |
5192 | asection *s = htab->plt; | |
25f23106 | 5193 | if (!dyn || h->dynindx == -1) |
e054468f | 5194 | s = htab->iplt; |
7619e7c7 | 5195 | |
25f23106 | 5196 | if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1) |
a6aa5195 | 5197 | { |
a6aa5195 | 5198 | if (!doneone) |
28e99bb6 AM |
5199 | { |
5200 | plt_offset = s->size; | |
5201 | s->size += 4; | |
5202 | } | |
5203 | ent->plt.offset = plt_offset; | |
d7128ce4 | 5204 | |
a6aa5195 | 5205 | s = htab->glink; |
a877a2b6 | 5206 | if (!doneone || info->shared) |
28e99bb6 AM |
5207 | { |
5208 | glink_offset = s->size; | |
5209 | s->size += GLINK_ENTRY_SIZE; | |
a7f2871e AM |
5210 | if (h == htab->tls_get_addr |
5211 | && !htab->no_tls_get_addr_opt) | |
5212 | s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE; | |
28e99bb6 AM |
5213 | } |
5214 | if (!doneone | |
5215 | && !info->shared | |
625af618 | 5216 | && h->def_dynamic |
a6aa5195 AM |
5217 | && !h->def_regular) |
5218 | { | |
5219 | h->root.u.def.section = s; | |
28e99bb6 | 5220 | h->root.u.def.value = glink_offset; |
a6aa5195 | 5221 | } |
28e99bb6 | 5222 | ent->glink_offset = glink_offset; |
0ba07910 AM |
5223 | |
5224 | if (htab->emit_stub_syms | |
ac39eb42 | 5225 | && !add_stub_sym (ent, h, info)) |
0ba07910 | 5226 | return FALSE; |
a6aa5195 AM |
5227 | } |
5228 | else | |
5229 | { | |
a6aa5195 AM |
5230 | if (!doneone) |
5231 | { | |
28e99bb6 AM |
5232 | /* If this is the first .plt entry, make room |
5233 | for the special first entry. */ | |
5234 | if (s->size == 0) | |
9d8504b1 | 5235 | s->size += htab->plt_initial_entry_size; |
28e99bb6 AM |
5236 | |
5237 | /* The PowerPC PLT is actually composed of two | |
5238 | parts, the first part is 2 words (for a load | |
5239 | and a jump), and then there is a remaining | |
5240 | word available at the end. */ | |
9d8504b1 PB |
5241 | plt_offset = (htab->plt_initial_entry_size |
5242 | + (htab->plt_slot_size | |
5243 | * ((s->size | |
5244 | - htab->plt_initial_entry_size) | |
5245 | / htab->plt_entry_size))); | |
28e99bb6 AM |
5246 | |
5247 | /* If this symbol is not defined in a regular | |
5248 | file, and we are not generating a shared | |
5b914448 | 5249 | library, then set the symbol to this location |
de972ffa AM |
5250 | in the .plt. This is to avoid text |
5251 | relocations, and is required to make | |
28e99bb6 AM |
5252 | function pointers compare as equal between |
5253 | the normal executable and the shared library. */ | |
5254 | if (! info->shared | |
625af618 | 5255 | && h->def_dynamic |
28e99bb6 AM |
5256 | && !h->def_regular) |
5257 | { | |
5258 | h->root.u.def.section = s; | |
5259 | h->root.u.def.value = plt_offset; | |
5260 | } | |
5261 | ||
9d8504b1 PB |
5262 | /* Make room for this entry. */ |
5263 | s->size += htab->plt_entry_size; | |
5264 | /* After the 8192nd entry, room for two entries | |
5265 | is allocated. */ | |
4a3dc543 | 5266 | if (htab->plt_type == PLT_OLD |
9d8504b1 PB |
5267 | && (s->size - htab->plt_initial_entry_size) |
5268 | / htab->plt_entry_size | |
5269 | > PLT_NUM_SINGLE_ENTRIES) | |
5270 | s->size += htab->plt_entry_size; | |
a6aa5195 | 5271 | } |
28e99bb6 | 5272 | ent->plt.offset = plt_offset; |
a6aa5195 | 5273 | } |
25dbc73a | 5274 | |
a6aa5195 AM |
5275 | /* We also need to make an entry in the .rela.plt section. */ |
5276 | if (!doneone) | |
5277 | { | |
25f23106 AM |
5278 | if (!htab->elf.dynamic_sections_created |
5279 | || h->dynindx == -1) | |
e054468f AM |
5280 | htab->reliplt->size += sizeof (Elf32_External_Rela); |
5281 | else | |
9d8504b1 | 5282 | { |
e054468f AM |
5283 | htab->relplt->size += sizeof (Elf32_External_Rela); |
5284 | ||
5285 | if (htab->plt_type == PLT_VXWORKS) | |
9d8504b1 | 5286 | { |
e054468f AM |
5287 | /* Allocate space for the unloaded relocations. */ |
5288 | if (!info->shared | |
5289 | && htab->elf.dynamic_sections_created) | |
9d8504b1 | 5290 | { |
e054468f AM |
5291 | if (ent->plt.offset |
5292 | == (bfd_vma) htab->plt_initial_entry_size) | |
5293 | { | |
5294 | htab->srelplt2->size | |
5295 | += (sizeof (Elf32_External_Rela) | |
5296 | * VXWORKS_PLTRESOLVE_RELOCS); | |
5297 | } | |
5298 | ||
9d8504b1 | 5299 | htab->srelplt2->size |
e054468f AM |
5300 | += (sizeof (Elf32_External_Rela) |
5301 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS); | |
9d8504b1 PB |
5302 | } |
5303 | ||
e054468f AM |
5304 | /* Every PLT entry has an associated GOT entry in |
5305 | .got.plt. */ | |
5306 | htab->sgotplt->size += 4; | |
9d8504b1 | 5307 | } |
9d8504b1 | 5308 | } |
a6aa5195 AM |
5309 | doneone = TRUE; |
5310 | } | |
5311 | } | |
5312 | else | |
5313 | ent->plt.offset = (bfd_vma) -1; | |
a6aa5195 | 5314 | } |
2ce859a1 AM |
5315 | else |
5316 | ent->plt.offset = (bfd_vma) -1; | |
5317 | ||
5318 | if (!doneone) | |
5319 | { | |
5320 | h->plt.plist = NULL; | |
5321 | h->needs_plt = 0; | |
5322 | } | |
25dbc73a AM |
5323 | } |
5324 | else | |
5325 | { | |
a6aa5195 | 5326 | h->plt.plist = NULL; |
25dbc73a AM |
5327 | h->needs_plt = 0; |
5328 | } | |
5329 | ||
5330 | eh = (struct ppc_elf_link_hash_entry *) h; | |
5331 | if (eh->elf.got.refcount > 0) | |
5332 | { | |
d6e14abc AM |
5333 | bfd_boolean dyn; |
5334 | unsigned int need; | |
5335 | ||
25dbc73a AM |
5336 | /* Make sure this symbol is output as a dynamic symbol. */ |
5337 | if (eh->elf.dynindx == -1 | |
b099ab9f | 5338 | && !eh->elf.forced_local |
25f23106 | 5339 | && eh->elf.type != STT_GNU_IFUNC |
b099ab9f | 5340 | && htab->elf.dynamic_sections_created) |
25dbc73a AM |
5341 | { |
5342 | if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf)) | |
b34976b6 | 5343 | return FALSE; |
25dbc73a | 5344 | } |
252b5132 | 5345 | |
d6e14abc AM |
5346 | need = 0; |
5347 | if ((eh->tls_mask & TLS_TLS) != 0) | |
25dbc73a | 5348 | { |
d6e14abc | 5349 | if ((eh->tls_mask & TLS_LD) != 0) |
252b5132 | 5350 | { |
d6e14abc AM |
5351 | if (!eh->elf.def_dynamic) |
5352 | /* We'll just use htab->tlsld_got.offset. This should | |
5353 | always be the case. It's a little odd if we have | |
5354 | a local dynamic reloc against a non-local symbol. */ | |
5355 | htab->tlsld_got.refcount += 1; | |
5356 | else | |
3b36f7e6 | 5357 | need += 8; |
252b5132 | 5358 | } |
d6e14abc AM |
5359 | if ((eh->tls_mask & TLS_GD) != 0) |
5360 | need += 8; | |
5361 | if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
5362 | need += 4; | |
5363 | if ((eh->tls_mask & TLS_DTPREL) != 0) | |
3b36f7e6 | 5364 | need += 4; |
d6e14abc AM |
5365 | } |
5366 | else | |
5367 | need += 4; | |
5368 | if (need == 0) | |
5369 | eh->elf.got.offset = (bfd_vma) -1; | |
5370 | else | |
5371 | { | |
3b36f7e6 | 5372 | eh->elf.got.offset = allocate_got (htab, need); |
25dbc73a AM |
5373 | dyn = htab->elf.dynamic_sections_created; |
5374 | if ((info->shared | |
5375 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf)) | |
5376 | && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT | |
5377 | || eh->elf.root.type != bfd_link_hash_undefweak)) | |
252b5132 | 5378 | { |
91e21fb7 | 5379 | asection *rsec = htab->relgot; |
3b36f7e6 AM |
5380 | /* All the entries we allocated need relocs. |
5381 | Except LD only needs one. */ | |
d6e14abc AM |
5382 | if ((eh->tls_mask & TLS_LD) != 0 |
5383 | && eh->elf.def_dynamic) | |
3b36f7e6 | 5384 | need -= 4; |
25f23106 | 5385 | rsec->size += need * (sizeof (Elf32_External_Rela) / 4); |
252b5132 | 5386 | } |
25dbc73a AM |
5387 | } |
5388 | } | |
5389 | else | |
5390 | eh->elf.got.offset = (bfd_vma) -1; | |
252b5132 | 5391 | |
b099ab9f | 5392 | if (eh->dyn_relocs == NULL |
de972ffa | 5393 | || !htab->elf.dynamic_sections_created) |
25dbc73a | 5394 | return TRUE; |
252b5132 | 5395 | |
25dbc73a AM |
5396 | /* In the shared -Bsymbolic case, discard space allocated for |
5397 | dynamic pc-relative relocs against symbols which turn out to be | |
5398 | defined in regular objects. For the normal shared case, discard | |
5399 | space for relocs that have become local due to symbol visibility | |
5400 | changes. */ | |
5401 | ||
5402 | if (info->shared) | |
5403 | { | |
5404 | /* Relocs that use pc_count are those that appear on a call insn, | |
1d483afe | 5405 | or certain REL relocs (see must_be_dyn_reloc) that can be |
25dbc73a AM |
5406 | generated via assembly. We want calls to protected symbols to |
5407 | resolve directly to the function rather than going via the plt. | |
5408 | If people want function pointer comparisons to work as expected | |
5409 | then they should avoid writing weird assembly. */ | |
5410 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
5411 | { | |
6061a67d | 5412 | struct elf_dyn_relocs **pp; |
25dbc73a AM |
5413 | |
5414 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
252b5132 | 5415 | { |
25dbc73a AM |
5416 | p->count -= p->pc_count; |
5417 | p->pc_count = 0; | |
5418 | if (p->count == 0) | |
5419 | *pp = p->next; | |
5420 | else | |
5421 | pp = &p->next; | |
252b5132 | 5422 | } |
25dbc73a | 5423 | } |
252b5132 | 5424 | |
3348747a NS |
5425 | if (htab->is_vxworks) |
5426 | { | |
6061a67d | 5427 | struct elf_dyn_relocs **pp; |
3348747a NS |
5428 | |
5429 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5430 | { | |
5431 | if (strcmp (p->sec->output_section->name, ".tls_vars") == 0) | |
5432 | *pp = p->next; | |
5433 | else | |
5434 | pp = &p->next; | |
5435 | } | |
5436 | } | |
5437 | ||
89200bf8 AM |
5438 | /* Discard relocs on undefined symbols that must be local. */ |
5439 | if (eh->dyn_relocs != NULL | |
5440 | && h->root.type == bfd_link_hash_undefined | |
5441 | && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
5442 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL)) | |
5443 | eh->dyn_relocs = NULL; | |
5444 | ||
25dbc73a AM |
5445 | /* Also discard relocs on undefined weak syms with non-default |
5446 | visibility. */ | |
cab87ef9 AM |
5447 | if (eh->dyn_relocs != NULL |
5448 | && h->root.type == bfd_link_hash_undefweak) | |
25dbc73a | 5449 | { |
dfbb6ac9 AM |
5450 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
5451 | eh->dyn_relocs = NULL; | |
5452 | ||
5453 | /* Make sure undefined weak symbols are output as a dynamic | |
5454 | symbol in PIEs. */ | |
5455 | else if (h->dynindx == -1 | |
e054468f AM |
5456 | && !h->forced_local |
5457 | && !h->def_regular) | |
dfbb6ac9 AM |
5458 | { |
5459 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5460 | return FALSE; | |
5461 | } | |
25dbc73a AM |
5462 | } |
5463 | } | |
5464 | else if (ELIMINATE_COPY_RELOCS) | |
5465 | { | |
5466 | /* For the non-shared case, discard space for relocs against | |
5467 | symbols which turn out to need copy relocs or are not | |
5468 | dynamic. */ | |
7619e7c7 | 5469 | |
25dbc73a | 5470 | if (!h->non_got_ref |
25dbc73a AM |
5471 | && !h->def_regular) |
5472 | { | |
5473 | /* Make sure this symbol is output as a dynamic symbol. | |
5474 | Undefined weak syms won't yet be marked as dynamic. */ | |
5475 | if (h->dynindx == -1 | |
25f23106 | 5476 | && !h->forced_local) |
25dbc73a AM |
5477 | { |
5478 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5479 | return FALSE; | |
5480 | } | |
7619e7c7 | 5481 | |
25dbc73a AM |
5482 | /* If that succeeded, we know we'll be keeping all the |
5483 | relocs. */ | |
5484 | if (h->dynindx != -1) | |
5485 | goto keep; | |
5486 | } | |
252b5132 | 5487 | |
25dbc73a | 5488 | eh->dyn_relocs = NULL; |
252b5132 | 5489 | |
25dbc73a AM |
5490 | keep: ; |
5491 | } | |
252b5132 | 5492 | |
25dbc73a AM |
5493 | /* Finally, allocate space. */ |
5494 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5495 | { | |
5496 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
25f23106 AM |
5497 | if (!htab->elf.dynamic_sections_created) |
5498 | sreloc = htab->reliplt; | |
25dbc73a AM |
5499 | sreloc->size += p->count * sizeof (Elf32_External_Rela); |
5500 | } | |
252b5132 | 5501 | |
25dbc73a AM |
5502 | return TRUE; |
5503 | } | |
7619e7c7 | 5504 | |
625af618 AM |
5505 | /* Set DF_TEXTREL if we find any dynamic relocs that apply to |
5506 | read-only sections. */ | |
7619e7c7 | 5507 | |
25dbc73a | 5508 | static bfd_boolean |
625af618 | 5509 | maybe_set_textrel (struct elf_link_hash_entry *h, void *info) |
25dbc73a | 5510 | { |
25dbc73a AM |
5511 | if (h->root.type == bfd_link_hash_indirect) |
5512 | return TRUE; | |
252b5132 | 5513 | |
625af618 | 5514 | if (readonly_dynrelocs (h)) |
25dbc73a | 5515 | { |
625af618 | 5516 | ((struct bfd_link_info *) info)->flags |= DF_TEXTREL; |
ee05f2fe | 5517 | |
625af618 AM |
5518 | /* Not an error, just cut short the traversal. */ |
5519 | return FALSE; | |
25dbc73a AM |
5520 | } |
5521 | return TRUE; | |
5522 | } | |
5523 | ||
6177242a AM |
5524 | static const unsigned char glink_eh_frame_cie[] = |
5525 | { | |
5526 | 0, 0, 0, 16, /* length. */ | |
5527 | 0, 0, 0, 0, /* id. */ | |
5528 | 1, /* CIE version. */ | |
5529 | 'z', 'R', 0, /* Augmentation string. */ | |
5530 | 4, /* Code alignment. */ | |
5531 | 0x7c, /* Data alignment. */ | |
5532 | 65, /* RA reg. */ | |
5533 | 1, /* Augmentation size. */ | |
5534 | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */ | |
5535 | DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */ | |
5536 | }; | |
5537 | ||
25dbc73a AM |
5538 | /* Set the sizes of the dynamic sections. */ |
5539 | ||
5540 | static bfd_boolean | |
5541 | ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, | |
5542 | struct bfd_link_info *info) | |
5543 | { | |
5544 | struct ppc_elf_link_hash_table *htab; | |
5545 | asection *s; | |
5546 | bfd_boolean relocs; | |
5547 | bfd *ibfd; | |
7fce784e | 5548 | |
252b5132 | 5549 | #ifdef DEBUG |
25dbc73a | 5550 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); |
252b5132 | 5551 | #endif |
252b5132 | 5552 | |
25dbc73a AM |
5553 | htab = ppc_elf_hash_table (info); |
5554 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
252b5132 | 5555 | |
25dbc73a AM |
5556 | if (elf_hash_table (info)->dynamic_sections_created) |
5557 | { | |
5558 | /* Set the contents of the .interp section to the interpreter. */ | |
5559 | if (info->executable) | |
5560 | { | |
5561 | s = bfd_get_section_by_name (htab->elf.dynobj, ".interp"); | |
5562 | BFD_ASSERT (s != NULL); | |
5563 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5564 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
5565 | } | |
5566 | } | |
252b5132 | 5567 | |
4a3dc543 | 5568 | if (htab->plt_type == PLT_OLD) |
d7128ce4 | 5569 | htab->got_header_size = 16; |
4a3dc543 | 5570 | else if (htab->plt_type == PLT_NEW) |
d7128ce4 | 5571 | htab->got_header_size = 12; |
252b5132 | 5572 | |
25dbc73a AM |
5573 | /* Set up .got offsets for local syms, and space for local dynamic |
5574 | relocs. */ | |
5575 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
5576 | { | |
5577 | bfd_signed_vma *local_got; | |
5578 | bfd_signed_vma *end_local_got; | |
e054468f AM |
5579 | struct plt_entry **local_plt; |
5580 | struct plt_entry **end_local_plt; | |
25dbc73a AM |
5581 | char *lgot_masks; |
5582 | bfd_size_type locsymcount; | |
5583 | Elf_Internal_Shdr *symtab_hdr; | |
7fce784e | 5584 | |
0c8d6e5c | 5585 | if (!is_ppc_elf (ibfd)) |
25dbc73a | 5586 | continue; |
7fce784e | 5587 | |
25dbc73a AM |
5588 | for (s = ibfd->sections; s != NULL; s = s->next) |
5589 | { | |
6061a67d | 5590 | struct elf_dyn_relocs *p; |
252b5132 | 5591 | |
6061a67d | 5592 | for (p = ((struct elf_dyn_relocs *) |
25dbc73a AM |
5593 | elf_section_data (s)->local_dynrel); |
5594 | p != NULL; | |
5595 | p = p->next) | |
5596 | { | |
5597 | if (!bfd_is_abs_section (p->sec) | |
5598 | && bfd_is_abs_section (p->sec->output_section)) | |
5599 | { | |
5600 | /* Input section has been discarded, either because | |
5601 | it is a copy of a linkonce section or due to | |
5602 | linker script /DISCARD/, so we'll be discarding | |
5603 | the relocs too. */ | |
7fce784e | 5604 | } |
3348747a NS |
5605 | else if (htab->is_vxworks |
5606 | && strcmp (p->sec->output_section->name, | |
5607 | ".tls_vars") == 0) | |
5608 | { | |
5609 | /* Relocations in vxworks .tls_vars sections are | |
5610 | handled specially by the loader. */ | |
5611 | } | |
25dbc73a | 5612 | else if (p->count != 0) |
7fce784e | 5613 | { |
25f23106 AM |
5614 | asection *sreloc = elf_section_data (p->sec)->sreloc; |
5615 | if (!htab->elf.dynamic_sections_created) | |
5616 | sreloc = htab->reliplt; | |
5617 | sreloc->size += p->count * sizeof (Elf32_External_Rela); | |
25dbc73a AM |
5618 | if ((p->sec->output_section->flags |
5619 | & (SEC_READONLY | SEC_ALLOC)) | |
5620 | == (SEC_READONLY | SEC_ALLOC)) | |
5621 | info->flags |= DF_TEXTREL; | |
7fce784e | 5622 | } |
252b5132 | 5623 | } |
252b5132 | 5624 | } |
252b5132 | 5625 | |
25dbc73a AM |
5626 | local_got = elf_local_got_refcounts (ibfd); |
5627 | if (!local_got) | |
5628 | continue; | |
252b5132 | 5629 | |
0ffa91dd | 5630 | symtab_hdr = &elf_symtab_hdr (ibfd); |
25dbc73a AM |
5631 | locsymcount = symtab_hdr->sh_info; |
5632 | end_local_got = local_got + locsymcount; | |
e054468f AM |
5633 | local_plt = (struct plt_entry **) end_local_got; |
5634 | end_local_plt = local_plt + locsymcount; | |
5635 | lgot_masks = (char *) end_local_plt; | |
91d6fa6a | 5636 | |
25dbc73a AM |
5637 | for (; local_got < end_local_got; ++local_got, ++lgot_masks) |
5638 | if (*local_got > 0) | |
5639 | { | |
d6e14abc AM |
5640 | unsigned int need = 0; |
5641 | if ((*lgot_masks & TLS_TLS) != 0) | |
25dbc73a | 5642 | { |
d6e14abc AM |
5643 | if ((*lgot_masks & TLS_GD) != 0) |
5644 | need += 8; | |
5645 | if ((*lgot_masks & TLS_LD) != 0) | |
5646 | htab->tlsld_got.refcount += 1; | |
5647 | if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
5648 | need += 4; | |
5649 | if ((*lgot_masks & TLS_DTPREL) != 0) | |
5650 | need += 4; | |
25dbc73a | 5651 | } |
d6e14abc AM |
5652 | else |
5653 | need += 4; | |
5654 | if (need == 0) | |
5655 | *local_got = (bfd_vma) -1; | |
25dbc73a AM |
5656 | else |
5657 | { | |
3b36f7e6 | 5658 | *local_got = allocate_got (htab, need); |
25dbc73a | 5659 | if (info->shared) |
3b36f7e6 AM |
5660 | htab->relgot->size += (need |
5661 | * (sizeof (Elf32_External_Rela) / 4)); | |
25dbc73a AM |
5662 | } |
5663 | } | |
5664 | else | |
5665 | *local_got = (bfd_vma) -1; | |
e054468f AM |
5666 | |
5667 | if (htab->is_vxworks) | |
5668 | continue; | |
5669 | ||
5670 | /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */ | |
5671 | for (; local_plt < end_local_plt; ++local_plt) | |
5672 | { | |
5673 | struct plt_entry *ent; | |
5674 | bfd_boolean doneone = FALSE; | |
5675 | bfd_vma plt_offset = 0, glink_offset = 0; | |
5676 | ||
5677 | for (ent = *local_plt; ent != NULL; ent = ent->next) | |
5678 | if (ent->plt.refcount > 0) | |
5679 | { | |
91d6fa6a | 5680 | s = htab->iplt; |
e054468f AM |
5681 | |
5682 | if (!doneone) | |
5683 | { | |
5684 | plt_offset = s->size; | |
5685 | s->size += 4; | |
5686 | } | |
5687 | ent->plt.offset = plt_offset; | |
5688 | ||
5689 | s = htab->glink; | |
a877a2b6 | 5690 | if (!doneone || info->shared) |
e054468f AM |
5691 | { |
5692 | glink_offset = s->size; | |
5693 | s->size += GLINK_ENTRY_SIZE; | |
5694 | } | |
5695 | ent->glink_offset = glink_offset; | |
5696 | ||
5697 | if (!doneone) | |
5698 | { | |
25f23106 | 5699 | htab->reliplt->size += sizeof (Elf32_External_Rela); |
e054468f AM |
5700 | doneone = TRUE; |
5701 | } | |
5702 | } | |
5703 | else | |
5704 | ent->plt.offset = (bfd_vma) -1; | |
5705 | } | |
25dbc73a | 5706 | } |
252b5132 | 5707 | |
b7fcf6f6 AM |
5708 | /* Allocate space for global sym dynamic relocs. */ |
5709 | elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info); | |
5710 | ||
3b36f7e6 AM |
5711 | if (htab->tlsld_got.refcount > 0) |
5712 | { | |
5713 | htab->tlsld_got.offset = allocate_got (htab, 8); | |
5714 | if (info->shared) | |
5715 | htab->relgot->size += sizeof (Elf32_External_Rela); | |
5716 | } | |
5717 | else | |
5718 | htab->tlsld_got.offset = (bfd_vma) -1; | |
5719 | ||
4a3dc543 | 5720 | if (htab->got != NULL && htab->plt_type != PLT_VXWORKS) |
3b36f7e6 AM |
5721 | { |
5722 | unsigned int g_o_t = 32768; | |
5723 | ||
4d962050 AM |
5724 | /* If we haven't allocated the header, do so now. When we get here, |
5725 | for old plt/got the got size will be 0 to 32764 (not allocated), | |
5726 | or 32780 to 65536 (header allocated). For new plt/got, the | |
5727 | corresponding ranges are 0 to 32768 and 32780 to 65536. */ | |
3b36f7e6 AM |
5728 | if (htab->got->size <= 32768) |
5729 | { | |
5730 | g_o_t = htab->got->size; | |
4a3dc543 | 5731 | if (htab->plt_type == PLT_OLD) |
4d962050 | 5732 | g_o_t += 4; |
3b36f7e6 AM |
5733 | htab->got->size += htab->got_header_size; |
5734 | } | |
3b36f7e6 AM |
5735 | |
5736 | htab->elf.hgot->root.u.def.value = g_o_t; | |
5737 | } | |
bd6c6e2b AM |
5738 | if (info->shared) |
5739 | { | |
5740 | struct elf_link_hash_entry *sda = htab->sdata[0].sym; | |
5741 | if (sda != NULL | |
5742 | && !(sda->root.type == bfd_link_hash_defined | |
5743 | || sda->root.type == bfd_link_hash_defweak)) | |
5744 | { | |
5745 | sda->root.type = bfd_link_hash_defined; | |
5746 | sda->root.u.def.section = htab->elf.hgot->root.u.def.section; | |
5747 | sda->root.u.def.value = htab->elf.hgot->root.u.def.value; | |
5748 | } | |
5749 | } | |
3b36f7e6 | 5750 | |
e054468f AM |
5751 | if (htab->glink != NULL |
5752 | && htab->glink->size != 0 | |
5753 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
5754 | { |
5755 | htab->glink_pltresolve = htab->glink->size; | |
86b9da88 AM |
5756 | /* Space for the branch table. */ |
5757 | htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4; | |
5758 | /* Pad out to align the start of PLTresolve. */ | |
5759 | htab->glink->size += -htab->glink->size & 15; | |
d7128ce4 | 5760 | htab->glink->size += GLINK_PLTRESOLVE; |
0ba07910 AM |
5761 | |
5762 | if (htab->emit_stub_syms) | |
5763 | { | |
5764 | struct elf_link_hash_entry *sh; | |
5765 | sh = elf_link_hash_lookup (&htab->elf, "__glink", | |
5766 | TRUE, FALSE, FALSE); | |
5767 | if (sh == NULL) | |
5768 | return FALSE; | |
5769 | if (sh->root.type == bfd_link_hash_new) | |
5770 | { | |
5771 | sh->root.type = bfd_link_hash_defined; | |
5772 | sh->root.u.def.section = htab->glink; | |
5773 | sh->root.u.def.value = htab->glink_pltresolve; | |
5774 | sh->ref_regular = 1; | |
5775 | sh->def_regular = 1; | |
5776 | sh->ref_regular_nonweak = 1; | |
5777 | sh->forced_local = 1; | |
5778 | sh->non_elf = 0; | |
5779 | } | |
5780 | sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve", | |
5781 | TRUE, FALSE, FALSE); | |
5782 | if (sh == NULL) | |
5783 | return FALSE; | |
5784 | if (sh->root.type == bfd_link_hash_new) | |
5785 | { | |
5786 | sh->root.type = bfd_link_hash_defined; | |
5787 | sh->root.u.def.section = htab->glink; | |
5788 | sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE; | |
5789 | sh->ref_regular = 1; | |
5790 | sh->def_regular = 1; | |
5791 | sh->ref_regular_nonweak = 1; | |
5792 | sh->forced_local = 1; | |
5793 | sh->non_elf = 0; | |
5794 | } | |
5795 | } | |
d7128ce4 AM |
5796 | } |
5797 | ||
6177242a AM |
5798 | if (htab->glink != NULL |
5799 | && htab->glink->size != 0 | |
5800 | && htab->glink_eh_frame != NULL | |
5801 | && !bfd_is_abs_section (htab->glink_eh_frame->output_section)) | |
5802 | { | |
5803 | s = htab->glink_eh_frame; | |
5804 | s->size = sizeof (glink_eh_frame_cie) + 20; | |
5805 | if (info->shared) | |
5806 | { | |
5807 | s->size += 4; | |
5808 | if (htab->glink->size - GLINK_PLTRESOLVE + 8 >= 256) | |
5809 | s->size += 4; | |
5810 | } | |
5811 | } | |
5812 | ||
25dbc73a AM |
5813 | /* We've now determined the sizes of the various dynamic sections. |
5814 | Allocate memory for them. */ | |
5815 | relocs = FALSE; | |
5816 | for (s = htab->elf.dynobj->sections; s != NULL; s = s->next) | |
252b5132 | 5817 | { |
9d8504b1 PB |
5818 | bfd_boolean strip_section = TRUE; |
5819 | ||
25dbc73a AM |
5820 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
5821 | continue; | |
252b5132 | 5822 | |
25dbc73a | 5823 | if (s == htab->plt |
e054468f | 5824 | || s == htab->got) |
25dbc73a | 5825 | { |
9d8504b1 PB |
5826 | /* We'd like to strip these sections if they aren't needed, but if |
5827 | we've exported dynamic symbols from them we must leave them. | |
5828 | It's too late to tell BFD to get rid of the symbols. */ | |
e054468f | 5829 | if (htab->elf.hplt != NULL) |
9d8504b1 | 5830 | strip_section = FALSE; |
25dbc73a AM |
5831 | /* Strip this section if we don't need it; see the |
5832 | comment below. */ | |
5833 | } | |
e054468f AM |
5834 | else if (s == htab->iplt |
5835 | || s == htab->glink | |
6177242a | 5836 | || s == htab->glink_eh_frame |
e054468f AM |
5837 | || s == htab->sgotplt |
5838 | || s == htab->sbss | |
5839 | || s == htab->dynbss | |
5840 | || s == htab->dynsbss | |
5841 | || s == htab->sdata[0].section | |
c9a2f333 | 5842 | || s == htab->sdata[1].section) |
25dbc73a | 5843 | { |
c9a2f333 | 5844 | /* Strip these too. */ |
25dbc73a | 5845 | } |
0112cd26 | 5846 | else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) |
25dbc73a | 5847 | { |
c456f082 | 5848 | if (s->size != 0) |
25dbc73a AM |
5849 | { |
5850 | /* Remember whether there are any relocation sections. */ | |
5851 | relocs = TRUE; | |
252b5132 | 5852 | |
25dbc73a AM |
5853 | /* We use the reloc_count field as a counter if we need |
5854 | to copy relocs into the output file. */ | |
5855 | s->reloc_count = 0; | |
252b5132 RH |
5856 | } |
5857 | } | |
25dbc73a AM |
5858 | else |
5859 | { | |
5860 | /* It's not one of our sections, so don't allocate space. */ | |
5861 | continue; | |
5862 | } | |
252b5132 | 5863 | |
9d8504b1 | 5864 | if (s->size == 0 && strip_section) |
25dbc73a | 5865 | { |
c456f082 AM |
5866 | /* If we don't need this section, strip it from the |
5867 | output file. This is mostly to handle .rela.bss and | |
5868 | .rela.plt. We must create both sections in | |
5869 | create_dynamic_sections, because they must be created | |
5870 | before the linker maps input sections to output | |
5871 | sections. The linker does that before | |
5872 | adjust_dynamic_symbol is called, and it is that | |
5873 | function which decides whether anything needs to go | |
5874 | into these sections. */ | |
8423293d | 5875 | s->flags |= SEC_EXCLUDE; |
25dbc73a AM |
5876 | continue; |
5877 | } | |
7fce784e | 5878 | |
d7128ce4 | 5879 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
644285ef AM |
5880 | continue; |
5881 | ||
25dbc73a AM |
5882 | /* Allocate memory for the section contents. */ |
5883 | s->contents = bfd_zalloc (htab->elf.dynobj, s->size); | |
5884 | if (s->contents == NULL) | |
5885 | return FALSE; | |
5886 | } | |
252b5132 | 5887 | |
25dbc73a | 5888 | if (htab->elf.dynamic_sections_created) |
7619e7c7 | 5889 | { |
25dbc73a AM |
5890 | /* Add some entries to the .dynamic section. We fill in the |
5891 | values later, in ppc_elf_finish_dynamic_sections, but we | |
5892 | must add the entries now so that we get the correct size for | |
5893 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5894 | dynamic linker and used by the debugger. */ | |
5895 | #define add_dynamic_entry(TAG, VAL) \ | |
5896 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |
252b5132 | 5897 | |
25dbc73a | 5898 | if (info->executable) |
7619e7c7 | 5899 | { |
25dbc73a AM |
5900 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
5901 | return FALSE; | |
7619e7c7 AM |
5902 | } |
5903 | ||
25dbc73a | 5904 | if (htab->plt != NULL && htab->plt->size != 0) |
7619e7c7 | 5905 | { |
25dbc73a AM |
5906 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
5907 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
5908 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5909 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
5910 | return FALSE; | |
5911 | } | |
7619e7c7 | 5912 | |
d7128ce4 AM |
5913 | if (htab->glink != NULL && htab->glink->size != 0) |
5914 | { | |
1fe44d79 | 5915 | if (!add_dynamic_entry (DT_PPC_GOT, 0)) |
d7128ce4 | 5916 | return FALSE; |
a7f2871e AM |
5917 | if (!htab->no_tls_get_addr_opt |
5918 | && htab->tls_get_addr != NULL | |
5919 | && htab->tls_get_addr->plt.plist != NULL | |
5920 | && !add_dynamic_entry (DT_PPC_TLSOPT, 0)) | |
5921 | return FALSE; | |
d7128ce4 AM |
5922 | } |
5923 | ||
25dbc73a AM |
5924 | if (relocs) |
5925 | { | |
5926 | if (!add_dynamic_entry (DT_RELA, 0) | |
5927 | || !add_dynamic_entry (DT_RELASZ, 0) | |
5928 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
5929 | return FALSE; | |
5930 | } | |
7619e7c7 | 5931 | |
25dbc73a AM |
5932 | /* If any dynamic relocs apply to a read-only section, then we |
5933 | need a DT_TEXTREL entry. */ | |
5934 | if ((info->flags & DF_TEXTREL) == 0) | |
625af618 | 5935 | elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel, |
25dbc73a | 5936 | info); |
7619e7c7 | 5937 | |
25dbc73a AM |
5938 | if ((info->flags & DF_TEXTREL) != 0) |
5939 | { | |
5940 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
5941 | return FALSE; | |
7619e7c7 | 5942 | } |
7a2b07ff NS |
5943 | if (htab->is_vxworks |
5944 | && !elf_vxworks_add_dynamic_entries (output_bfd, info)) | |
5945 | return FALSE; | |
5946 | } | |
25dbc73a AM |
5947 | #undef add_dynamic_entry |
5948 | ||
7619e7c7 AM |
5949 | return TRUE; |
5950 | } | |
0eb4a168 AM |
5951 | |
5952 | /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ | |
5953 | ||
5954 | static bfd_boolean | |
5955 | ppc_elf_hash_symbol (struct elf_link_hash_entry *h) | |
5956 | { | |
5957 | if (h->plt.plist != NULL | |
5958 | && !h->def_regular | |
5959 | && (!h->pointer_equality_needed | |
5960 | || !h->ref_regular_nonweak)) | |
5961 | return FALSE; | |
5962 | ||
5963 | return _bfd_elf_hash_symbol (h); | |
5964 | } | |
25dbc73a AM |
5965 | \f |
5966 | #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) | |
5967 | ||
01017ef8 NS |
5968 | /* Relaxation trampolines. r12 is available for clobbering (r11, is |
5969 | used for some functions that are allowed to break the ABI). */ | |
25dbc73a AM |
5970 | static const int shared_stub_entry[] = |
5971 | { | |
5972 | 0x7c0802a6, /* mflr 0 */ | |
5973 | 0x429f0005, /* bcl 20, 31, .Lxxx */ | |
01017ef8 NS |
5974 | 0x7d8802a6, /* mflr 12 */ |
5975 | 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */ | |
5976 | 0x398c0008, /* addi 12, 12, (xxx-.Lxxx)@l */ | |
25dbc73a | 5977 | 0x7c0803a6, /* mtlr 0 */ |
01017ef8 | 5978 | 0x7d8903a6, /* mtctr 12 */ |
25dbc73a AM |
5979 | 0x4e800420, /* bctr */ |
5980 | }; | |
5981 | ||
5982 | static const int stub_entry[] = | |
5983 | { | |
01017ef8 NS |
5984 | 0x3d800000, /* lis 12,xxx@ha */ |
5985 | 0x398c0000, /* addi 12,12,xxx@l */ | |
5986 | 0x7d8903a6, /* mtctr 12 */ | |
25dbc73a AM |
5987 | 0x4e800420, /* bctr */ |
5988 | }; | |
5989 | ||
5990 | static bfd_boolean | |
5991 | ppc_elf_relax_section (bfd *abfd, | |
5992 | asection *isec, | |
5993 | struct bfd_link_info *link_info, | |
5994 | bfd_boolean *again) | |
5995 | { | |
5996 | struct one_fixup | |
5997 | { | |
5998 | struct one_fixup *next; | |
5999 | asection *tsec; | |
01017ef8 NS |
6000 | /* Final link, can use the symbol offset. For a |
6001 | relocatable link we use the symbol's index. */ | |
25dbc73a AM |
6002 | bfd_vma toff; |
6003 | bfd_vma trampoff; | |
6004 | }; | |
7619e7c7 | 6005 | |
25dbc73a AM |
6006 | Elf_Internal_Shdr *symtab_hdr; |
6007 | bfd_byte *contents = NULL; | |
6008 | Elf_Internal_Sym *isymbuf = NULL; | |
6009 | Elf_Internal_Rela *internal_relocs = NULL; | |
6010 | Elf_Internal_Rela *irel, *irelend; | |
6011 | struct one_fixup *fixups = NULL; | |
9bc4e62b | 6012 | unsigned changes = 0; |
d7128ce4 | 6013 | struct ppc_elf_link_hash_table *htab; |
25dbc73a | 6014 | bfd_size_type trampoff; |
a6aa5195 | 6015 | asection *got2; |
50248c89 | 6016 | bfd_boolean maybe_pasted; |
7619e7c7 | 6017 | |
25dbc73a | 6018 | *again = FALSE; |
7619e7c7 | 6019 | |
c87b5a93 | 6020 | /* Nothing to do if there are no relocations, and no need to do |
a8ad78a7 | 6021 | anything with non-alloc or non-code sections. */ |
c87b5a93 | 6022 | if ((isec->flags & SEC_ALLOC) == 0 |
a8ad78a7 | 6023 | || (isec->flags & SEC_CODE) == 0 |
c87b5a93 AM |
6024 | || (isec->flags & SEC_RELOC) == 0 |
6025 | || isec->reloc_count == 0) | |
25dbc73a | 6026 | return TRUE; |
7619e7c7 | 6027 | |
c8a1f254 NS |
6028 | /* We cannot represent the required PIC relocs in the output, so don't |
6029 | do anything. The linker doesn't support mixing -shared and -r | |
6030 | anyway. */ | |
6031 | if (link_info->relocatable && link_info->shared) | |
6032 | return TRUE; | |
5b914448 | 6033 | |
25dbc73a | 6034 | trampoff = (isec->size + 3) & (bfd_vma) -4; |
50248c89 AM |
6035 | maybe_pasted = (strcmp (isec->output_section->name, ".init") == 0 |
6036 | || strcmp (isec->output_section->name, ".fini") == 0); | |
25dbc73a | 6037 | /* Space for a branch around any trampolines. */ |
50248c89 AM |
6038 | if (maybe_pasted) |
6039 | trampoff += 4; | |
7619e7c7 | 6040 | |
0ffa91dd | 6041 | symtab_hdr = &elf_symtab_hdr (abfd); |
7619e7c7 | 6042 | |
25dbc73a AM |
6043 | /* Get a copy of the native relocations. */ |
6044 | internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, | |
6045 | link_info->keep_memory); | |
6046 | if (internal_relocs == NULL) | |
6047 | goto error_return; | |
7619e7c7 | 6048 | |
d7128ce4 | 6049 | htab = ppc_elf_hash_table (link_info); |
a6aa5195 | 6050 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
7619e7c7 | 6051 | |
a6aa5195 | 6052 | irelend = internal_relocs + isec->reloc_count; |
25dbc73a | 6053 | for (irel = internal_relocs; irel < irelend; irel++) |
7619e7c7 | 6054 | { |
25dbc73a | 6055 | unsigned long r_type = ELF32_R_TYPE (irel->r_info); |
91d6fa6a | 6056 | bfd_vma toff, roff; |
25dbc73a AM |
6057 | asection *tsec; |
6058 | struct one_fixup *f; | |
6059 | size_t insn_offset = 0; | |
6060 | bfd_vma max_branch_offset, val; | |
6061 | bfd_byte *hit_addr; | |
6062 | unsigned long t0; | |
de972ffa | 6063 | struct elf_link_hash_entry *h; |
a9585d22 | 6064 | struct plt_entry **plist; |
25dbc73a | 6065 | unsigned char sym_type; |
7619e7c7 | 6066 | |
25dbc73a AM |
6067 | switch (r_type) |
6068 | { | |
6069 | case R_PPC_REL24: | |
6070 | case R_PPC_LOCAL24PC: | |
6071 | case R_PPC_PLTREL24: | |
6072 | max_branch_offset = 1 << 25; | |
6073 | break; | |
7619e7c7 | 6074 | |
25dbc73a AM |
6075 | case R_PPC_REL14: |
6076 | case R_PPC_REL14_BRTAKEN: | |
6077 | case R_PPC_REL14_BRNTAKEN: | |
6078 | max_branch_offset = 1 << 15; | |
6079 | break; | |
7619e7c7 | 6080 | |
25dbc73a AM |
6081 | default: |
6082 | continue; | |
6083 | } | |
7619e7c7 | 6084 | |
25dbc73a | 6085 | /* Get the value of the symbol referred to by the reloc. */ |
de972ffa | 6086 | h = NULL; |
25dbc73a AM |
6087 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
6088 | { | |
6089 | /* A local symbol. */ | |
6090 | Elf_Internal_Sym *isym; | |
7fce784e | 6091 | |
25dbc73a AM |
6092 | /* Read this BFD's local symbols. */ |
6093 | if (isymbuf == NULL) | |
6094 | { | |
6095 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
6096 | if (isymbuf == NULL) | |
6097 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
6098 | symtab_hdr->sh_info, 0, | |
6099 | NULL, NULL, NULL); | |
6100 | if (isymbuf == 0) | |
6101 | goto error_return; | |
6102 | } | |
6103 | isym = isymbuf + ELF32_R_SYM (irel->r_info); | |
6104 | if (isym->st_shndx == SHN_UNDEF) | |
c8a1f254 | 6105 | tsec = bfd_und_section_ptr; |
25dbc73a AM |
6106 | else if (isym->st_shndx == SHN_ABS) |
6107 | tsec = bfd_abs_section_ptr; | |
6108 | else if (isym->st_shndx == SHN_COMMON) | |
6109 | tsec = bfd_com_section_ptr; | |
6110 | else | |
6111 | tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
7fce784e | 6112 | |
25dbc73a AM |
6113 | toff = isym->st_value; |
6114 | sym_type = ELF_ST_TYPE (isym->st_info); | |
6115 | } | |
6116 | else | |
6117 | { | |
6118 | /* Global symbol handling. */ | |
6119 | unsigned long indx; | |
7619e7c7 | 6120 | |
25dbc73a AM |
6121 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
6122 | h = elf_sym_hashes (abfd)[indx]; | |
7619e7c7 | 6123 | |
25dbc73a AM |
6124 | while (h->root.type == bfd_link_hash_indirect |
6125 | || h->root.type == bfd_link_hash_warning) | |
6126 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 6127 | |
a9585d22 AM |
6128 | if (h->root.type == bfd_link_hash_defined |
6129 | || h->root.type == bfd_link_hash_defweak) | |
25dbc73a AM |
6130 | { |
6131 | tsec = h->root.u.def.section; | |
6132 | toff = h->root.u.def.value; | |
6133 | } | |
c8a1f254 NS |
6134 | else if (h->root.type == bfd_link_hash_undefined |
6135 | || h->root.type == bfd_link_hash_undefweak) | |
6136 | { | |
6137 | tsec = bfd_und_section_ptr; | |
01017ef8 | 6138 | toff = link_info->relocatable ? indx : 0; |
c8a1f254 | 6139 | } |
25dbc73a AM |
6140 | else |
6141 | continue; | |
7619e7c7 | 6142 | |
25dbc73a AM |
6143 | sym_type = h->type; |
6144 | } | |
7619e7c7 | 6145 | |
a9585d22 AM |
6146 | /* The condition here under which we call find_plt_ent must |
6147 | match that in relocate_section. If we call find_plt_ent here | |
6148 | but not in relocate_section, or vice versa, then the branch | |
6149 | destination used here may be incorrect. */ | |
6150 | plist = NULL; | |
6151 | if (h != NULL) | |
de972ffa | 6152 | { |
a9585d22 AM |
6153 | /* We know is_branch_reloc (r_type) is true. */ |
6154 | if (h->type == STT_GNU_IFUNC | |
6155 | || r_type == R_PPC_PLTREL24) | |
de972ffa | 6156 | plist = &h->plt.plist; |
a9585d22 AM |
6157 | } |
6158 | else if (sym_type == STT_GNU_IFUNC | |
6159 | && elf_local_got_offsets (abfd) != NULL) | |
6160 | { | |
6161 | bfd_vma *local_got_offsets = elf_local_got_offsets (abfd); | |
6162 | struct plt_entry **local_plt = (struct plt_entry **) | |
6163 | (local_got_offsets + symtab_hdr->sh_info); | |
6164 | plist = local_plt + ELF32_R_SYM (irel->r_info); | |
6165 | } | |
6166 | if (plist != NULL) | |
6167 | { | |
6168 | bfd_vma addend = 0; | |
6169 | struct plt_entry *ent; | |
de972ffa | 6170 | |
a9585d22 AM |
6171 | if (r_type == R_PPC_PLTREL24 && link_info->shared) |
6172 | addend = irel->r_addend; | |
6173 | ent = find_plt_ent (plist, got2, addend); | |
6174 | if (ent != NULL) | |
6175 | { | |
6176 | if (htab->plt_type == PLT_NEW | |
6177 | || h == NULL | |
6178 | || !htab->elf.dynamic_sections_created | |
6179 | || h->dynindx == -1) | |
de972ffa | 6180 | { |
a9585d22 AM |
6181 | tsec = htab->glink; |
6182 | toff = ent->glink_offset; | |
6183 | } | |
6184 | else | |
6185 | { | |
6186 | tsec = htab->plt; | |
6187 | toff = ent->plt.offset; | |
de972ffa AM |
6188 | } |
6189 | } | |
6190 | } | |
6191 | ||
25dbc73a AM |
6192 | /* If the branch and target are in the same section, you have |
6193 | no hope of adding stubs. We'll error out later should the | |
6194 | branch overflow. */ | |
6195 | if (tsec == isec) | |
6196 | continue; | |
6197 | ||
6198 | /* There probably isn't any reason to handle symbols in | |
6199 | SEC_MERGE sections; SEC_MERGE doesn't seem a likely | |
6200 | attribute for a code section, and we are only looking at | |
6201 | branches. However, implement it correctly here as a | |
6202 | reference for other target relax_section functions. */ | |
6203 | if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE) | |
6204 | { | |
6205 | /* At this stage in linking, no SEC_MERGE symbol has been | |
6206 | adjusted, so all references to such symbols need to be | |
6207 | passed through _bfd_merged_section_offset. (Later, in | |
6208 | relocate_section, all SEC_MERGE symbols *except* for | |
6209 | section symbols have been adjusted.) | |
6210 | ||
6211 | gas may reduce relocations against symbols in SEC_MERGE | |
6212 | sections to a relocation against the section symbol when | |
6213 | the original addend was zero. When the reloc is against | |
6214 | a section symbol we should include the addend in the | |
6215 | offset passed to _bfd_merged_section_offset, since the | |
6216 | location of interest is the original symbol. On the | |
6217 | other hand, an access to "sym+addend" where "sym" is not | |
6218 | a section symbol should not include the addend; Such an | |
6219 | access is presumed to be an offset from "sym"; The | |
6220 | location of interest is just "sym". */ | |
6221 | if (sym_type == STT_SECTION) | |
6222 | toff += irel->r_addend; | |
7619e7c7 | 6223 | |
25dbc73a AM |
6224 | toff = _bfd_merged_section_offset (abfd, &tsec, |
6225 | elf_section_data (tsec)->sec_info, | |
6226 | toff); | |
7619e7c7 | 6227 | |
25dbc73a AM |
6228 | if (sym_type != STT_SECTION) |
6229 | toff += irel->r_addend; | |
6230 | } | |
a6aa5195 AM |
6231 | /* PLTREL24 addends are special. */ |
6232 | else if (r_type != R_PPC_PLTREL24) | |
25dbc73a | 6233 | toff += irel->r_addend; |
7619e7c7 | 6234 | |
7de713b9 AM |
6235 | /* Attempted -shared link of non-pic code loses. */ |
6236 | if (tsec->output_section == NULL) | |
6237 | continue; | |
6238 | ||
25dbc73a | 6239 | roff = irel->r_offset; |
7619e7c7 | 6240 | |
25dbc73a | 6241 | /* If the branch is in range, no need to do anything. */ |
c8a1f254 NS |
6242 | if (tsec != bfd_und_section_ptr |
6243 | && (!link_info->relocatable | |
6244 | /* A relocatable link may have sections moved during | |
6245 | final link, so do not presume they remain in range. */ | |
01017ef8 NS |
6246 | || tsec->output_section == isec->output_section)) |
6247 | { | |
6248 | bfd_vma symaddr, reladdr; | |
6249 | ||
6250 | symaddr = tsec->output_section->vma + tsec->output_offset + toff; | |
6251 | reladdr = isec->output_section->vma + isec->output_offset + roff; | |
6252 | if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset) | |
6253 | continue; | |
6254 | } | |
252b5132 | 6255 | |
25dbc73a AM |
6256 | /* Look for an existing fixup to this address. */ |
6257 | for (f = fixups; f ; f = f->next) | |
6258 | if (f->tsec == tsec && f->toff == toff) | |
6259 | break; | |
6260 | ||
6261 | if (f == NULL) | |
7619e7c7 | 6262 | { |
25dbc73a AM |
6263 | size_t size; |
6264 | unsigned long stub_rtype; | |
252b5132 | 6265 | |
25dbc73a AM |
6266 | val = trampoff - roff; |
6267 | if (val >= max_branch_offset) | |
6268 | /* Oh dear, we can't reach a trampoline. Don't try to add | |
6269 | one. We'll report an error later. */ | |
6270 | continue; | |
252b5132 | 6271 | |
25dbc73a AM |
6272 | if (link_info->shared) |
6273 | { | |
6274 | size = 4 * ARRAY_SIZE (shared_stub_entry); | |
6275 | insn_offset = 12; | |
25dbc73a AM |
6276 | } |
6277 | else | |
6278 | { | |
6279 | size = 4 * ARRAY_SIZE (stub_entry); | |
6280 | insn_offset = 0; | |
25dbc73a | 6281 | } |
32af9f6e | 6282 | stub_rtype = R_PPC_RELAX; |
d7128ce4 AM |
6283 | if (tsec == htab->plt |
6284 | || tsec == htab->glink) | |
32af9f6e AM |
6285 | { |
6286 | stub_rtype = R_PPC_RELAX_PLT; | |
6287 | if (r_type == R_PPC_PLTREL24) | |
6288 | stub_rtype = R_PPC_RELAX_PLTREL24; | |
6289 | } | |
252b5132 | 6290 | |
25dbc73a AM |
6291 | /* Hijack the old relocation. Since we need two |
6292 | relocations for this use a "composite" reloc. */ | |
6293 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
6294 | stub_rtype); | |
6295 | irel->r_offset = trampoff + insn_offset; | |
32af9f6e AM |
6296 | if (r_type == R_PPC_PLTREL24 |
6297 | && stub_rtype != R_PPC_RELAX_PLTREL24) | |
e7d92e2e | 6298 | irel->r_addend = 0; |
252b5132 | 6299 | |
25dbc73a AM |
6300 | /* Record the fixup so we don't do it again this section. */ |
6301 | f = bfd_malloc (sizeof (*f)); | |
6302 | f->next = fixups; | |
6303 | f->tsec = tsec; | |
6304 | f->toff = toff; | |
6305 | f->trampoff = trampoff; | |
6306 | fixups = f; | |
252b5132 | 6307 | |
25dbc73a | 6308 | trampoff += size; |
9bc4e62b | 6309 | changes++; |
25dbc73a AM |
6310 | } |
6311 | else | |
6312 | { | |
6313 | val = f->trampoff - roff; | |
6314 | if (val >= max_branch_offset) | |
6315 | continue; | |
252b5132 | 6316 | |
25dbc73a AM |
6317 | /* Nop out the reloc, since we're finalizing things here. */ |
6318 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
6319 | } | |
252b5132 | 6320 | |
25dbc73a AM |
6321 | /* Get the section contents. */ |
6322 | if (contents == NULL) | |
6323 | { | |
6324 | /* Get cached copy if it exists. */ | |
6325 | if (elf_section_data (isec)->this_hdr.contents != NULL) | |
6326 | contents = elf_section_data (isec)->this_hdr.contents; | |
6327 | else | |
6328 | { | |
6329 | /* Go get them off disk. */ | |
6330 | if (!bfd_malloc_and_get_section (abfd, isec, &contents)) | |
6331 | goto error_return; | |
6332 | } | |
6333 | } | |
252b5132 | 6334 | |
25dbc73a AM |
6335 | /* Fix up the existing branch to hit the trampoline. */ |
6336 | hit_addr = contents + roff; | |
6337 | switch (r_type) | |
6338 | { | |
6339 | case R_PPC_REL24: | |
6340 | case R_PPC_LOCAL24PC: | |
6341 | case R_PPC_PLTREL24: | |
6342 | t0 = bfd_get_32 (abfd, hit_addr); | |
6343 | t0 &= ~0x3fffffc; | |
6344 | t0 |= val & 0x3fffffc; | |
6345 | bfd_put_32 (abfd, t0, hit_addr); | |
6346 | break; | |
252b5132 | 6347 | |
25dbc73a AM |
6348 | case R_PPC_REL14: |
6349 | case R_PPC_REL14_BRTAKEN: | |
6350 | case R_PPC_REL14_BRNTAKEN: | |
6351 | t0 = bfd_get_32 (abfd, hit_addr); | |
6352 | t0 &= ~0xfffc; | |
6353 | t0 |= val & 0xfffc; | |
6354 | bfd_put_32 (abfd, t0, hit_addr); | |
6355 | break; | |
6356 | } | |
6357 | } | |
252b5132 | 6358 | |
25dbc73a | 6359 | /* Write out the trampolines. */ |
25dbc73a AM |
6360 | if (fixups != NULL) |
6361 | { | |
6362 | const int *stub; | |
6363 | bfd_byte *dest; | |
25dbc73a | 6364 | int i, size; |
252b5132 | 6365 | |
25dbc73a AM |
6366 | do |
6367 | { | |
6368 | struct one_fixup *f = fixups; | |
6369 | fixups = fixups->next; | |
6370 | free (f); | |
6371 | } | |
6372 | while (fixups); | |
252b5132 | 6373 | |
515ef31d | 6374 | contents = bfd_realloc_or_free (contents, trampoff); |
25dbc73a AM |
6375 | if (contents == NULL) |
6376 | goto error_return; | |
252b5132 | 6377 | |
25dbc73a | 6378 | isec->size = (isec->size + 3) & (bfd_vma) -4; |
25dbc73a | 6379 | dest = contents + isec->size; |
50248c89 AM |
6380 | /* Branch around the trampolines. */ |
6381 | if (maybe_pasted) | |
6382 | { | |
6383 | bfd_vma val = B + trampoff - isec->size; | |
6384 | bfd_put_32 (abfd, val, dest); | |
6385 | dest += 4; | |
6386 | } | |
25dbc73a | 6387 | isec->size = trampoff; |
252b5132 | 6388 | |
25dbc73a AM |
6389 | if (link_info->shared) |
6390 | { | |
6391 | stub = shared_stub_entry; | |
6392 | size = ARRAY_SIZE (shared_stub_entry); | |
6393 | } | |
6394 | else | |
6395 | { | |
6396 | stub = stub_entry; | |
6397 | size = ARRAY_SIZE (stub_entry); | |
6398 | } | |
252b5132 | 6399 | |
25dbc73a AM |
6400 | i = 0; |
6401 | while (dest < contents + trampoff) | |
252b5132 | 6402 | { |
25dbc73a AM |
6403 | bfd_put_32 (abfd, stub[i], dest); |
6404 | i++; | |
6405 | if (i == size) | |
6406 | i = 0; | |
6407 | dest += 4; | |
252b5132 | 6408 | } |
25dbc73a | 6409 | BFD_ASSERT (i == 0); |
252b5132 RH |
6410 | } |
6411 | ||
25dbc73a AM |
6412 | if (isymbuf != NULL |
6413 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
252b5132 | 6414 | { |
25dbc73a AM |
6415 | if (! link_info->keep_memory) |
6416 | free (isymbuf); | |
252b5132 | 6417 | else |
25dbc73a AM |
6418 | { |
6419 | /* Cache the symbols for elf_link_input_bfd. */ | |
6420 | symtab_hdr->contents = (unsigned char *) isymbuf; | |
6421 | } | |
252b5132 RH |
6422 | } |
6423 | ||
25dbc73a AM |
6424 | if (contents != NULL |
6425 | && elf_section_data (isec)->this_hdr.contents != contents) | |
6426 | { | |
9bc4e62b | 6427 | if (!changes && !link_info->keep_memory) |
25dbc73a AM |
6428 | free (contents); |
6429 | else | |
6430 | { | |
6431 | /* Cache the section contents for elf_link_input_bfd. */ | |
6432 | elf_section_data (isec)->this_hdr.contents = contents; | |
6433 | } | |
6434 | } | |
252b5132 | 6435 | |
9bc4e62b | 6436 | if (changes != 0) |
25dbc73a | 6437 | { |
9bc4e62b NS |
6438 | /* Append sufficient NOP relocs so we can write out relocation |
6439 | information for the trampolines. */ | |
d4730f92 | 6440 | Elf_Internal_Shdr *rel_hdr; |
9bc4e62b NS |
6441 | Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count) |
6442 | * sizeof (*new_relocs)); | |
6443 | unsigned ix; | |
5b914448 | 6444 | |
9bc4e62b NS |
6445 | if (!new_relocs) |
6446 | goto error_return; | |
6447 | memcpy (new_relocs, internal_relocs, | |
6448 | isec->reloc_count * sizeof (*new_relocs)); | |
6449 | for (ix = changes; ix--;) | |
6450 | { | |
6451 | irel = new_relocs + ix + isec->reloc_count; | |
6452 | ||
6453 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
6454 | } | |
6455 | if (internal_relocs != elf_section_data (isec)->relocs) | |
25dbc73a | 6456 | free (internal_relocs); |
9bc4e62b NS |
6457 | elf_section_data (isec)->relocs = new_relocs; |
6458 | isec->reloc_count += changes; | |
d4730f92 BS |
6459 | rel_hdr = _bfd_elf_single_rel_hdr (isec); |
6460 | rel_hdr->sh_size += changes * rel_hdr->sh_entsize; | |
25dbc73a | 6461 | } |
9bc4e62b NS |
6462 | else if (elf_section_data (isec)->relocs != internal_relocs) |
6463 | free (internal_relocs); | |
252b5132 | 6464 | |
9bc4e62b | 6465 | *again = changes != 0; |
c8a1f254 NS |
6466 | if (!*again && link_info->relocatable) |
6467 | { | |
6468 | /* Convert the internal relax relocs to external form. */ | |
6469 | for (irel = internal_relocs; irel < irelend; irel++) | |
32af9f6e | 6470 | if (ELF32_R_TYPE (irel->r_info) == R_PPC_RELAX) |
c8a1f254 NS |
6471 | { |
6472 | unsigned long r_symndx = ELF32_R_SYM (irel->r_info); | |
6473 | ||
6474 | /* Rewrite the reloc and convert one of the trailing nop | |
6475 | relocs to describe this relocation. */ | |
6476 | BFD_ASSERT (ELF32_R_TYPE (irelend[-1].r_info) == R_PPC_NONE); | |
6477 | /* The relocs are at the bottom 2 bytes */ | |
6478 | irel[0].r_offset += 2; | |
6479 | memmove (irel + 1, irel, (irelend - irel - 1) * sizeof (*irel)); | |
6480 | irel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); | |
6481 | irel[1].r_offset += 4; | |
6482 | irel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); | |
6483 | irel++; | |
6484 | } | |
6485 | } | |
5b914448 | 6486 | |
b34976b6 | 6487 | return TRUE; |
25dbc73a AM |
6488 | |
6489 | error_return: | |
6490 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents) | |
6491 | free (isymbuf); | |
6492 | if (contents != NULL | |
6493 | && elf_section_data (isec)->this_hdr.contents != contents) | |
6494 | free (contents); | |
6495 | if (internal_relocs != NULL | |
6496 | && elf_section_data (isec)->relocs != internal_relocs) | |
6497 | free (internal_relocs); | |
6498 | return FALSE; | |
252b5132 | 6499 | } |
252b5132 | 6500 | \f |
8a696751 AM |
6501 | /* What to do when ld finds relocations against symbols defined in |
6502 | discarded sections. */ | |
6503 | ||
6504 | static unsigned int | |
6505 | ppc_elf_action_discarded (asection *sec) | |
6506 | { | |
6507 | if (strcmp (".fixup", sec->name) == 0) | |
6508 | return 0; | |
6509 | ||
6510 | if (strcmp (".got2", sec->name) == 0) | |
6511 | return 0; | |
6512 | ||
6513 | return _bfd_elf_default_action_discarded (sec); | |
6514 | } | |
c9a2f333 | 6515 | \f |
25dbc73a | 6516 | /* Fill in the address for a pointer generated in a linker section. */ |
252b5132 | 6517 | |
25dbc73a | 6518 | static bfd_vma |
76750a2f | 6519 | elf_finish_pointer_linker_section (bfd *input_bfd, |
25dbc73a AM |
6520 | elf_linker_section_t *lsect, |
6521 | struct elf_link_hash_entry *h, | |
6522 | bfd_vma relocation, | |
2bb04cf2 | 6523 | const Elf_Internal_Rela *rel) |
25dbc73a AM |
6524 | { |
6525 | elf_linker_section_pointers_t *linker_section_ptr; | |
252b5132 | 6526 | |
25dbc73a | 6527 | BFD_ASSERT (lsect != NULL); |
252b5132 | 6528 | |
25dbc73a | 6529 | if (h != NULL) |
252b5132 | 6530 | { |
25dbc73a AM |
6531 | /* Handle global symbol. */ |
6532 | struct ppc_elf_link_hash_entry *eh; | |
252b5132 | 6533 | |
25dbc73a | 6534 | eh = (struct ppc_elf_link_hash_entry *) h; |
76750a2f AM |
6535 | BFD_ASSERT (eh->elf.def_regular); |
6536 | linker_section_ptr = eh->linker_section_pointer; | |
25dbc73a AM |
6537 | } |
6538 | else | |
6539 | { | |
6540 | /* Handle local symbol. */ | |
6541 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
76750a2f | 6542 | |
0c8d6e5c | 6543 | BFD_ASSERT (is_ppc_elf (input_bfd)); |
25dbc73a | 6544 | BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); |
76750a2f AM |
6545 | linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx]; |
6546 | } | |
252b5132 | 6547 | |
76750a2f AM |
6548 | linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr, |
6549 | rel->r_addend, | |
6550 | lsect); | |
6551 | BFD_ASSERT (linker_section_ptr != NULL); | |
25dbc73a | 6552 | |
76750a2f AM |
6553 | /* Offset will always be a multiple of four, so use the bottom bit |
6554 | as a "written" flag. */ | |
6555 | if ((linker_section_ptr->offset & 1) == 0) | |
6556 | { | |
6557 | bfd_put_32 (lsect->section->owner, | |
6558 | relocation + linker_section_ptr->addend, | |
6559 | lsect->section->contents + linker_section_ptr->offset); | |
6560 | linker_section_ptr->offset += 1; | |
252b5132 RH |
6561 | } |
6562 | ||
bd6c6e2b AM |
6563 | relocation = (lsect->section->output_section->vma |
6564 | + lsect->section->output_offset | |
76750a2f | 6565 | + linker_section_ptr->offset - 1 |
bd6c6e2b | 6566 | - SYM_VAL (lsect->sym)); |
252b5132 | 6567 | |
25dbc73a AM |
6568 | #ifdef DEBUG |
6569 | fprintf (stderr, | |
6570 | "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", | |
6571 | lsect->name, (long) relocation, (long) relocation); | |
6572 | #endif | |
252b5132 | 6573 | |
bd6c6e2b | 6574 | return relocation; |
252b5132 | 6575 | } |
25dbc73a | 6576 | |
e054468f AM |
6577 | #define PPC_LO(v) ((v) & 0xffff) |
6578 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6579 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6580 | ||
6581 | static void | |
a7f2871e | 6582 | write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p, |
e054468f AM |
6583 | struct bfd_link_info *info) |
6584 | { | |
6585 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
6586 | bfd *output_bfd = info->output_bfd; | |
6587 | bfd_vma plt; | |
e054468f AM |
6588 | |
6589 | plt = ((ent->plt.offset & ~1) | |
6590 | + plt_sec->output_section->vma | |
6591 | + plt_sec->output_offset); | |
e054468f | 6592 | |
a877a2b6 | 6593 | if (info->shared) |
e054468f AM |
6594 | { |
6595 | bfd_vma got = 0; | |
6596 | ||
6597 | if (ent->addend >= 32768) | |
6598 | got = (ent->addend | |
6599 | + ent->sec->output_section->vma | |
6600 | + ent->sec->output_offset); | |
6601 | else if (htab->elf.hgot != NULL) | |
6602 | got = SYM_VAL (htab->elf.hgot); | |
6603 | ||
6604 | plt -= got; | |
6605 | ||
6606 | if (plt + 0x8000 < 0x10000) | |
6607 | { | |
6608 | bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p); | |
6609 | p += 4; | |
6610 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6611 | p += 4; | |
6612 | bfd_put_32 (output_bfd, BCTR, p); | |
6613 | p += 4; | |
6614 | bfd_put_32 (output_bfd, NOP, p); | |
6615 | p += 4; | |
6616 | } | |
6617 | else | |
6618 | { | |
6619 | bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p); | |
6620 | p += 4; | |
6621 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
6622 | p += 4; | |
6623 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6624 | p += 4; | |
6625 | bfd_put_32 (output_bfd, BCTR, p); | |
6626 | p += 4; | |
6627 | } | |
6628 | } | |
6629 | else | |
6630 | { | |
6631 | bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p); | |
6632 | p += 4; | |
6633 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
6634 | p += 4; | |
6635 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6636 | p += 4; | |
6637 | bfd_put_32 (output_bfd, BCTR, p); | |
6638 | p += 4; | |
6639 | } | |
6640 | } | |
6641 | ||
bd6c6e2b AM |
6642 | /* Return true if symbol is defined statically. */ |
6643 | ||
6644 | static bfd_boolean | |
6645 | is_static_defined (struct elf_link_hash_entry *h) | |
6646 | { | |
6647 | return ((h->root.type == bfd_link_hash_defined | |
6648 | || h->root.type == bfd_link_hash_defweak) | |
6649 | && h->root.u.def.section != NULL | |
6650 | && h->root.u.def.section->output_section != NULL); | |
6651 | } | |
6652 | ||
2d0f3896 AM |
6653 | /* If INSN is an opcode that may be used with an @tls operand, return |
6654 | the transformed insn for TLS optimisation, otherwise return 0. If | |
6655 | REG is non-zero only match an insn with RB or RA equal to REG. */ | |
6656 | ||
6657 | unsigned int | |
6658 | _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg) | |
6659 | { | |
6660 | unsigned int rtra; | |
6661 | ||
6662 | if ((insn & (0x3f << 26)) != 31 << 26) | |
6663 | return 0; | |
6664 | ||
6665 | if (reg == 0 || ((insn >> 11) & 0x1f) == reg) | |
6666 | rtra = insn & ((1 << 26) - (1 << 16)); | |
6667 | else if (((insn >> 16) & 0x1f) == reg) | |
6668 | rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5); | |
6669 | else | |
6670 | return 0; | |
6671 | ||
6672 | if ((insn & (0x3ff << 1)) == 266 << 1) | |
6673 | /* add -> addi. */ | |
6674 | insn = 14 << 26; | |
6675 | else if ((insn & (0x1f << 1)) == 23 << 1 | |
6676 | && ((insn & (0x1f << 6)) < 14 << 6 | |
6677 | || ((insn & (0x1f << 6)) >= 16 << 6 | |
6678 | && (insn & (0x1f << 6)) < 24 << 6))) | |
6679 | /* load and store indexed -> dform. */ | |
6680 | insn = (32 | ((insn >> 6) & 0x1f)) << 26; | |
6681 | else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1) | |
6682 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
6683 | insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1); | |
6684 | else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1) | |
6685 | /* lwax -> lwa. */ | |
6686 | insn = (58 << 26) | 2; | |
6687 | else | |
6688 | return 0; | |
6689 | insn |= rtra; | |
6690 | return insn; | |
6691 | } | |
6692 | ||
766bc656 AM |
6693 | /* If INSN is an opcode that may be used with an @tprel operand, return |
6694 | the transformed insn for an undefined weak symbol, ie. with the | |
6695 | thread pointer REG operand removed. Otherwise return 0. */ | |
6696 | ||
6697 | unsigned int | |
6698 | _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg) | |
6699 | { | |
6700 | if ((insn & (0x1f << 16)) == reg << 16 | |
6701 | && ((insn & (0x3f << 26)) == 14u << 26 /* addi */ | |
6702 | || (insn & (0x3f << 26)) == 15u << 26 /* addis */ | |
6703 | || (insn & (0x3f << 26)) == 32u << 26 /* lwz */ | |
6704 | || (insn & (0x3f << 26)) == 34u << 26 /* lbz */ | |
6705 | || (insn & (0x3f << 26)) == 36u << 26 /* stw */ | |
6706 | || (insn & (0x3f << 26)) == 38u << 26 /* stb */ | |
6707 | || (insn & (0x3f << 26)) == 40u << 26 /* lhz */ | |
6708 | || (insn & (0x3f << 26)) == 42u << 26 /* lha */ | |
6709 | || (insn & (0x3f << 26)) == 44u << 26 /* sth */ | |
6710 | || (insn & (0x3f << 26)) == 46u << 26 /* lmw */ | |
6711 | || (insn & (0x3f << 26)) == 47u << 26 /* stmw */ | |
6712 | || (insn & (0x3f << 26)) == 48u << 26 /* lfs */ | |
6713 | || (insn & (0x3f << 26)) == 50u << 26 /* lfd */ | |
6714 | || (insn & (0x3f << 26)) == 52u << 26 /* stfs */ | |
6715 | || (insn & (0x3f << 26)) == 54u << 26 /* stfd */ | |
6716 | || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */ | |
6717 | && (insn & 3) != 1) | |
6718 | || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */ | |
6719 | && ((insn & 3) == 0 || (insn & 3) == 3)))) | |
6720 | { | |
6721 | insn &= ~(0x1f << 16); | |
6722 | } | |
6723 | else if ((insn & (0x1f << 21)) == reg << 21 | |
6724 | && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */ | |
6725 | || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */ | |
6726 | || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */)) | |
6727 | { | |
6728 | insn &= ~(0x1f << 21); | |
6729 | insn |= (insn & (0x1f << 16)) << 5; | |
6730 | if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */) | |
6731 | insn -= 2 >> 26; /* convert to ori,oris */ | |
6732 | } | |
6733 | else | |
6734 | insn = 0; | |
6735 | return insn; | |
6736 | } | |
6737 | ||
252b5132 RH |
6738 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
6739 | to handle the relocations for a section. | |
6740 | ||
6741 | The relocs are always passed as Rela structures; if the section | |
6742 | actually uses Rel structures, the r_addend field will always be | |
6743 | zero. | |
6744 | ||
6745 | This function is responsible for adjust the section contents as | |
6746 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 6747 | relocatable output file) adjusting the reloc addend as |
252b5132 RH |
6748 | necessary. |
6749 | ||
6750 | This function does not have to worry about setting the reloc | |
6751 | address or the reloc symbol index. | |
6752 | ||
6753 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
6754 | ||
6755 | LOCAL_SECTIONS is an array giving the section in the input file | |
6756 | corresponding to the st_shndx field of each local symbol. | |
6757 | ||
6758 | The global hash table entry for the global symbols can be found | |
6759 | via elf_sym_hashes (input_bfd). | |
6760 | ||
1049f94e | 6761 | When generating relocatable output, this function must handle |
252b5132 RH |
6762 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
6763 | going to be the section symbol corresponding to the output | |
6764 | section, which means that the addend must be adjusted | |
6765 | accordingly. */ | |
6766 | ||
b34976b6 | 6767 | static bfd_boolean |
55fd94b0 AM |
6768 | ppc_elf_relocate_section (bfd *output_bfd, |
6769 | struct bfd_link_info *info, | |
6770 | bfd *input_bfd, | |
6771 | asection *input_section, | |
6772 | bfd_byte *contents, | |
6773 | Elf_Internal_Rela *relocs, | |
6774 | Elf_Internal_Sym *local_syms, | |
6775 | asection **local_sections) | |
252b5132 | 6776 | { |
7619e7c7 AM |
6777 | Elf_Internal_Shdr *symtab_hdr; |
6778 | struct elf_link_hash_entry **sym_hashes; | |
6779 | struct ppc_elf_link_hash_table *htab; | |
6780 | Elf_Internal_Rela *rel; | |
6781 | Elf_Internal_Rela *relend; | |
6782 | Elf_Internal_Rela outrel; | |
a6aa5195 | 6783 | asection *got2, *sreloc = NULL; |
252b5132 | 6784 | bfd_vma *local_got_offsets; |
b34976b6 | 6785 | bfd_boolean ret = TRUE; |
4fe5ca5b | 6786 | bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0); |
3348747a | 6787 | bfd_boolean is_vxworks_tls; |
b34976b6 | 6788 | |
252b5132 | 6789 | #ifdef DEBUG |
d003868e AM |
6790 | _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, " |
6791 | "%ld relocations%s", | |
6792 | input_bfd, input_section, | |
6793 | (long) input_section->reloc_count, | |
6794 | (info->relocatable) ? " (relocatable)" : ""); | |
252b5132 RH |
6795 | #endif |
6796 | ||
a6aa5195 AM |
6797 | got2 = bfd_get_section_by_name (input_bfd, ".got2"); |
6798 | ||
e47cd125 | 6799 | /* Initialize howto table if not already done. */ |
8da6118f | 6800 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
252b5132 RH |
6801 | ppc_elf_howto_init (); |
6802 | ||
7619e7c7 | 6803 | htab = ppc_elf_hash_table (info); |
252b5132 | 6804 | local_got_offsets = elf_local_got_offsets (input_bfd); |
0ffa91dd | 6805 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
7619e7c7 | 6806 | sym_hashes = elf_sym_hashes (input_bfd); |
3348747a NS |
6807 | /* We have to handle relocations in vxworks .tls_vars sections |
6808 | specially, because the dynamic loader is 'weird'. */ | |
6809 | is_vxworks_tls = (htab->is_vxworks && info->shared | |
6810 | && !strcmp (input_section->output_section->name, | |
6811 | ".tls_vars")); | |
7619e7c7 AM |
6812 | rel = relocs; |
6813 | relend = relocs + input_section->reloc_count; | |
252b5132 RH |
6814 | for (; rel < relend; rel++) |
6815 | { | |
7619e7c7 AM |
6816 | enum elf_ppc_reloc_type r_type; |
6817 | bfd_vma addend; | |
6818 | bfd_reloc_status_type r; | |
6819 | Elf_Internal_Sym *sym; | |
6820 | asection *sec; | |
6821 | struct elf_link_hash_entry *h; | |
6822 | const char *sym_name; | |
252b5132 RH |
6823 | reloc_howto_type *howto; |
6824 | unsigned long r_symndx; | |
6825 | bfd_vma relocation; | |
91d6fa6a | 6826 | bfd_vma branch_bit, from; |
7619e7c7 AM |
6827 | bfd_boolean unresolved_reloc; |
6828 | bfd_boolean warned; | |
6829 | unsigned int tls_type, tls_mask, tls_gd; | |
e054468f | 6830 | struct plt_entry **ifunc; |
7619e7c7 | 6831 | |
55fd94b0 AM |
6832 | r_type = ELF32_R_TYPE (rel->r_info); |
6833 | sym = NULL; | |
6834 | sec = NULL; | |
6835 | h = NULL; | |
7619e7c7 AM |
6836 | unresolved_reloc = FALSE; |
6837 | warned = FALSE; | |
252b5132 | 6838 | r_symndx = ELF32_R_SYM (rel->r_info); |
560e09e9 | 6839 | |
252b5132 RH |
6840 | if (r_symndx < symtab_hdr->sh_info) |
6841 | { | |
6842 | sym = local_syms + r_symndx; | |
6843 | sec = local_sections[r_symndx]; | |
26c61ae5 | 6844 | sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec); |
252b5132 | 6845 | |
8517fae7 | 6846 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
252b5132 RH |
6847 | } |
6848 | else | |
6849 | { | |
b2a8e766 AM |
6850 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
6851 | r_symndx, symtab_hdr, sym_hashes, | |
6852 | h, sec, relocation, | |
6853 | unresolved_reloc, warned); | |
9abc968f | 6854 | |
252b5132 | 6855 | sym_name = h->root.root.string; |
7619e7c7 AM |
6856 | } |
6857 | ||
ab96bf03 AM |
6858 | if (sec != NULL && elf_discarded_section (sec)) |
6859 | { | |
6860 | /* For relocs against symbols from removed linkonce sections, | |
6861 | or sections discarded by a linker script, we just want the | |
6862 | section contents zeroed. Avoid any special processing. */ | |
6863 | howto = NULL; | |
6864 | if (r_type < R_PPC_max) | |
6865 | howto = ppc_elf_howto_table[r_type]; | |
e4067dbb DJ |
6866 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
6867 | rel, relend, howto, contents); | |
ab96bf03 AM |
6868 | } |
6869 | ||
6870 | if (info->relocatable) | |
6871 | { | |
6872 | if (got2 != NULL | |
6873 | && r_type == R_PPC_PLTREL24 | |
6874 | && rel->r_addend >= 32768) | |
6875 | { | |
6876 | /* R_PPC_PLTREL24 is rather special. If non-zero, the | |
6877 | addend specifies the GOT pointer offset within .got2. */ | |
6878 | rel->r_addend += got2->output_offset; | |
6879 | } | |
6880 | continue; | |
6881 | } | |
6882 | ||
7619e7c7 AM |
6883 | /* TLS optimizations. Replace instruction sequences and relocs |
6884 | based on information we collected in tls_optimize. We edit | |
6885 | RELOCS so that --emit-relocs will output something sensible | |
6886 | for the final instruction stream. */ | |
6887 | tls_mask = 0; | |
6888 | tls_gd = 0; | |
727fc41e AM |
6889 | if (h != NULL) |
6890 | tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask; | |
6891 | else if (local_got_offsets != NULL) | |
7619e7c7 | 6892 | { |
e054468f | 6893 | struct plt_entry **local_plt; |
727fc41e | 6894 | char *lgot_masks; |
e054468f AM |
6895 | local_plt |
6896 | = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info); | |
6897 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
727fc41e | 6898 | tls_mask = lgot_masks[r_symndx]; |
7619e7c7 AM |
6899 | } |
6900 | ||
6901 | /* Ensure reloc mapping code below stays sane. */ | |
6902 | if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3) | |
6903 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3) | |
6904 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3) | |
6905 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3) | |
6906 | || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3) | |
6907 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3) | |
6908 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3) | |
6909 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3)) | |
6910 | abort (); | |
6911 | switch (r_type) | |
6912 | { | |
6913 | default: | |
6914 | break; | |
6915 | ||
6916 | case R_PPC_GOT_TPREL16: | |
6917 | case R_PPC_GOT_TPREL16_LO: | |
e054468f | 6918 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
6919 | && (tls_mask & TLS_TPREL) == 0) |
6920 | { | |
6921 | bfd_vma insn; | |
91d6fa6a | 6922 | |
4fe5ca5b | 6923 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset); |
7619e7c7 AM |
6924 | insn &= 31 << 21; |
6925 | insn |= 0x3c020000; /* addis 0,2,0 */ | |
4fe5ca5b | 6926 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset); |
7619e7c7 AM |
6927 | r_type = R_PPC_TPREL16_HA; |
6928 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6929 | } | |
6930 | break; | |
6931 | ||
6932 | case R_PPC_TLS: | |
e054468f | 6933 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
6934 | && (tls_mask & TLS_TPREL) == 0) |
6935 | { | |
2d0f3896 AM |
6936 | bfd_vma insn; |
6937 | ||
7619e7c7 | 6938 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
2d0f3896 AM |
6939 | insn = _bfd_elf_ppc_at_tls_transform (insn, 2); |
6940 | if (insn == 0) | |
7619e7c7 | 6941 | abort (); |
7619e7c7 AM |
6942 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
6943 | r_type = R_PPC_TPREL16_LO; | |
6944 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4fe5ca5b | 6945 | |
7619e7c7 | 6946 | /* Was PPC_TLS which sits on insn boundary, now |
4fe5ca5b GM |
6947 | PPC_TPREL16_LO which is at low-order half-word. */ |
6948 | rel->r_offset += d_offset; | |
7619e7c7 AM |
6949 | } |
6950 | break; | |
6951 | ||
6952 | case R_PPC_GOT_TLSGD16_HI: | |
6953 | case R_PPC_GOT_TLSGD16_HA: | |
6954 | tls_gd = TLS_TPRELGD; | |
e054468f | 6955 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
7619e7c7 AM |
6956 | goto tls_gdld_hi; |
6957 | break; | |
6958 | ||
6959 | case R_PPC_GOT_TLSLD16_HI: | |
6960 | case R_PPC_GOT_TLSLD16_HA: | |
e054468f | 6961 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 AM |
6962 | { |
6963 | tls_gdld_hi: | |
6964 | if ((tls_mask & tls_gd) != 0) | |
6965 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
6966 | + R_PPC_GOT_TPREL16); | |
6967 | else | |
6968 | { | |
6969 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); | |
4fe5ca5b | 6970 | rel->r_offset -= d_offset; |
7619e7c7 AM |
6971 | r_type = R_PPC_NONE; |
6972 | } | |
6973 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6974 | } | |
6975 | break; | |
6976 | ||
6977 | case R_PPC_GOT_TLSGD16: | |
6978 | case R_PPC_GOT_TLSGD16_LO: | |
6979 | tls_gd = TLS_TPRELGD; | |
e054468f | 6980 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
b7fcf6f6 | 6981 | goto tls_ldgd_opt; |
7619e7c7 AM |
6982 | break; |
6983 | ||
6984 | case R_PPC_GOT_TLSLD16: | |
6985 | case R_PPC_GOT_TLSLD16_LO: | |
e054468f | 6986 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 | 6987 | { |
3a71aa26 | 6988 | unsigned int insn1, insn2; |
b7fcf6f6 | 6989 | bfd_vma offset; |
7619e7c7 | 6990 | |
b7fcf6f6 | 6991 | tls_ldgd_opt: |
727fc41e AM |
6992 | offset = (bfd_vma) -1; |
6993 | /* If not using the newer R_PPC_TLSGD/LD to mark | |
6994 | __tls_get_addr calls, we must trust that the call | |
6995 | stays with its arg setup insns, ie. that the next | |
6996 | reloc is the __tls_get_addr call associated with | |
6997 | the current reloc. Edit both insns. */ | |
6998 | if (input_section->has_tls_get_addr_call | |
6999 | && rel + 1 < relend | |
7000 | && branch_reloc_hash_match (input_bfd, rel + 1, | |
7001 | htab->tls_get_addr)) | |
7002 | offset = rel[1].r_offset; | |
b7fcf6f6 AM |
7003 | if ((tls_mask & tls_gd) != 0) |
7004 | { | |
7005 | /* IE */ | |
3a71aa26 AM |
7006 | insn1 = bfd_get_32 (output_bfd, |
7007 | contents + rel->r_offset - d_offset); | |
b7fcf6f6 AM |
7008 | insn1 &= (1 << 26) - 1; |
7009 | insn1 |= 32 << 26; /* lwz */ | |
727fc41e AM |
7010 | if (offset != (bfd_vma) -1) |
7011 | { | |
f58d5a2d | 7012 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e AM |
7013 | insn2 = 0x7c631214; /* add 3,3,2 */ |
7014 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7015 | } | |
b7fcf6f6 AM |
7016 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) |
7017 | + R_PPC_GOT_TPREL16); | |
7018 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
7019 | } | |
7020 | else | |
7021 | { | |
7022 | /* LE */ | |
7023 | insn1 = 0x3c620000; /* addis 3,2,0 */ | |
7619e7c7 AM |
7024 | if (tls_gd == 0) |
7025 | { | |
b7fcf6f6 | 7026 | /* Was an LD reloc. */ |
1d483afe AM |
7027 | for (r_symndx = 0; |
7028 | r_symndx < symtab_hdr->sh_info; | |
7029 | r_symndx++) | |
7030 | if (local_sections[r_symndx] == sec) | |
7031 | break; | |
7032 | if (r_symndx >= symtab_hdr->sh_info) | |
cf35638d | 7033 | r_symndx = STN_UNDEF; |
b7fcf6f6 | 7034 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
cf35638d | 7035 | if (r_symndx != STN_UNDEF) |
1d483afe AM |
7036 | rel->r_addend -= (local_syms[r_symndx].st_value |
7037 | + sec->output_offset | |
7038 | + sec->output_section->vma); | |
7619e7c7 | 7039 | } |
b7fcf6f6 AM |
7040 | r_type = R_PPC_TPREL16_HA; |
7041 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
727fc41e AM |
7042 | if (offset != (bfd_vma) -1) |
7043 | { | |
7044 | rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
7045 | rel[1].r_offset = offset + d_offset; | |
7046 | rel[1].r_addend = rel->r_addend; | |
7047 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7048 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7049 | } | |
b7fcf6f6 AM |
7050 | } |
7051 | bfd_put_32 (output_bfd, insn1, | |
7052 | contents + rel->r_offset - d_offset); | |
b7fcf6f6 AM |
7053 | if (tls_gd == 0) |
7054 | { | |
7055 | /* We changed the symbol on an LD reloc. Start over | |
7056 | in order to get h, sym, sec etc. right. */ | |
7057 | rel--; | |
7058 | continue; | |
7619e7c7 | 7059 | } |
252b5132 | 7060 | } |
7619e7c7 | 7061 | break; |
727fc41e AM |
7062 | |
7063 | case R_PPC_TLSGD: | |
e054468f | 7064 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
727fc41e AM |
7065 | { |
7066 | unsigned int insn2; | |
7067 | bfd_vma offset = rel->r_offset; | |
7068 | ||
7069 | if ((tls_mask & TLS_TPRELGD) != 0) | |
7070 | { | |
7071 | /* IE */ | |
7072 | r_type = R_PPC_NONE; | |
7073 | insn2 = 0x7c631214; /* add 3,3,2 */ | |
7074 | } | |
7075 | else | |
7076 | { | |
7077 | /* LE */ | |
7078 | r_type = R_PPC_TPREL16_LO; | |
7079 | rel->r_offset += d_offset; | |
7080 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7081 | } | |
7082 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
7083 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7084 | /* Zap the reloc on the _tls_get_addr call too. */ | |
7085 | BFD_ASSERT (offset == rel[1].r_offset); | |
f58d5a2d | 7086 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e AM |
7087 | } |
7088 | break; | |
7089 | ||
7090 | case R_PPC_TLSLD: | |
e054468f | 7091 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
727fc41e AM |
7092 | { |
7093 | unsigned int insn2; | |
7094 | ||
7095 | for (r_symndx = 0; | |
7096 | r_symndx < symtab_hdr->sh_info; | |
7097 | r_symndx++) | |
7098 | if (local_sections[r_symndx] == sec) | |
7099 | break; | |
7100 | if (r_symndx >= symtab_hdr->sh_info) | |
cf35638d | 7101 | r_symndx = STN_UNDEF; |
727fc41e | 7102 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
cf35638d | 7103 | if (r_symndx != STN_UNDEF) |
727fc41e AM |
7104 | rel->r_addend -= (local_syms[r_symndx].st_value |
7105 | + sec->output_offset | |
7106 | + sec->output_section->vma); | |
7107 | ||
7108 | rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
7109 | rel->r_offset += d_offset; | |
7110 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7111 | bfd_put_32 (output_bfd, insn2, | |
7112 | contents + rel->r_offset - d_offset); | |
7113 | /* Zap the reloc on the _tls_get_addr call too. */ | |
7114 | BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset); | |
f58d5a2d | 7115 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e AM |
7116 | rel--; |
7117 | continue; | |
7118 | } | |
7119 | break; | |
7619e7c7 AM |
7120 | } |
7121 | ||
7122 | /* Handle other relocations that tweak non-addend part of insn. */ | |
7123 | branch_bit = 0; | |
7124 | switch (r_type) | |
7125 | { | |
7126 | default: | |
7127 | break; | |
7128 | ||
7129 | /* Branch taken prediction relocations. */ | |
7130 | case R_PPC_ADDR14_BRTAKEN: | |
7131 | case R_PPC_REL14_BRTAKEN: | |
7132 | branch_bit = BRANCH_PREDICT_BIT; | |
7133 | /* Fall thru */ | |
7134 | ||
4cc11e76 | 7135 | /* Branch not taken prediction relocations. */ |
7619e7c7 AM |
7136 | case R_PPC_ADDR14_BRNTAKEN: |
7137 | case R_PPC_REL14_BRNTAKEN: | |
91d6fa6a NC |
7138 | { |
7139 | bfd_vma insn; | |
7619e7c7 | 7140 | |
91d6fa6a NC |
7141 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
7142 | insn &= ~BRANCH_PREDICT_BIT; | |
7143 | insn |= branch_bit; | |
7619e7c7 | 7144 | |
91d6fa6a NC |
7145 | from = (rel->r_offset |
7146 | + input_section->output_offset | |
7147 | + input_section->output_section->vma); | |
7619e7c7 | 7148 | |
91d6fa6a NC |
7149 | /* Invert 'y' bit if not the default. */ |
7150 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
7151 | insn ^= BRANCH_PREDICT_BIT; | |
7152 | ||
7153 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
7154 | break; | |
7155 | } | |
252b5132 RH |
7156 | } |
7157 | ||
e054468f | 7158 | ifunc = NULL; |
25f23106 | 7159 | if (!htab->is_vxworks) |
e054468f | 7160 | { |
de972ffa AM |
7161 | struct plt_entry *ent; |
7162 | ||
e054468f AM |
7163 | if (h != NULL) |
7164 | { | |
7165 | if (h->type == STT_GNU_IFUNC) | |
7166 | ifunc = &h->plt.plist; | |
7167 | } | |
de972ffa AM |
7168 | else if (local_got_offsets != NULL |
7169 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
e054468f | 7170 | { |
de972ffa | 7171 | struct plt_entry **local_plt; |
e054468f | 7172 | |
de972ffa AM |
7173 | local_plt = (struct plt_entry **) (local_got_offsets |
7174 | + symtab_hdr->sh_info); | |
7175 | ifunc = local_plt + r_symndx; | |
e054468f | 7176 | } |
e054468f | 7177 | |
de972ffa AM |
7178 | ent = NULL; |
7179 | if (ifunc != NULL | |
7180 | && (!info->shared | |
7181 | || is_branch_reloc (r_type))) | |
7182 | { | |
7183 | addend = 0; | |
a877a2b6 | 7184 | if (r_type == R_PPC_PLTREL24 && info->shared) |
de972ffa AM |
7185 | addend = rel->r_addend; |
7186 | ent = find_plt_ent (ifunc, got2, addend); | |
7187 | } | |
7188 | if (ent != NULL) | |
7189 | { | |
e054468f AM |
7190 | if (h == NULL && (ent->plt.offset & 1) == 0) |
7191 | { | |
7192 | Elf_Internal_Rela rela; | |
7193 | bfd_byte *loc; | |
7194 | ||
7195 | rela.r_offset = (htab->iplt->output_section->vma | |
7196 | + htab->iplt->output_offset | |
7197 | + ent->plt.offset); | |
7198 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7199 | rela.r_addend = relocation; | |
25f23106 AM |
7200 | loc = htab->reliplt->contents; |
7201 | loc += (htab->reliplt->reloc_count++ | |
7202 | * sizeof (Elf32_External_Rela)); | |
e054468f AM |
7203 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
7204 | ||
7205 | ent->plt.offset |= 1; | |
7206 | } | |
7207 | if (h == NULL && (ent->glink_offset & 1) == 0) | |
7208 | { | |
a7f2871e AM |
7209 | unsigned char *p = ((unsigned char *) htab->glink->contents |
7210 | + ent->glink_offset); | |
7211 | write_glink_stub (ent, htab->iplt, p, info); | |
e054468f AM |
7212 | ent->glink_offset |= 1; |
7213 | } | |
7214 | ||
7215 | unresolved_reloc = FALSE; | |
7216 | if (htab->plt_type == PLT_NEW | |
7217 | || !htab->elf.dynamic_sections_created | |
7218 | || h == NULL) | |
7219 | relocation = (htab->glink->output_section->vma | |
7220 | + htab->glink->output_offset | |
7221 | + (ent->glink_offset & ~1)); | |
7222 | else | |
7223 | relocation = (htab->plt->output_section->vma | |
7224 | + htab->plt->output_offset | |
7225 | + ent->plt.offset); | |
7226 | } | |
7227 | } | |
7228 | ||
7619e7c7 AM |
7229 | addend = rel->r_addend; |
7230 | tls_type = 0; | |
7231 | howto = NULL; | |
55fd94b0 AM |
7232 | if (r_type < R_PPC_max) |
7233 | howto = ppc_elf_howto_table[r_type]; | |
7619e7c7 | 7234 | switch (r_type) |
252b5132 RH |
7235 | { |
7236 | default: | |
25f53a85 AM |
7237 | info->callbacks->einfo |
7238 | (_("%B: unknown relocation type %d for symbol %s\n"), | |
d003868e | 7239 | input_bfd, (int) r_type, sym_name); |
252b5132 RH |
7240 | |
7241 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 7242 | ret = FALSE; |
252b5132 RH |
7243 | continue; |
7244 | ||
7619e7c7 AM |
7245 | case R_PPC_NONE: |
7246 | case R_PPC_TLS: | |
727fc41e AM |
7247 | case R_PPC_TLSGD: |
7248 | case R_PPC_TLSLD: | |
7619e7c7 AM |
7249 | case R_PPC_EMB_MRKREF: |
7250 | case R_PPC_GNU_VTINHERIT: | |
7251 | case R_PPC_GNU_VTENTRY: | |
7595d193 L |
7252 | continue; |
7253 | ||
7619e7c7 AM |
7254 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
7255 | address in the GOT as relocation value instead of the | |
7256 | symbol's value itself. Also, create a GOT entry for the | |
7257 | symbol and put the symbol value there. */ | |
7258 | case R_PPC_GOT_TLSGD16: | |
7259 | case R_PPC_GOT_TLSGD16_LO: | |
7260 | case R_PPC_GOT_TLSGD16_HI: | |
7261 | case R_PPC_GOT_TLSGD16_HA: | |
7262 | tls_type = TLS_TLS | TLS_GD; | |
7263 | goto dogot; | |
7264 | ||
7265 | case R_PPC_GOT_TLSLD16: | |
7266 | case R_PPC_GOT_TLSLD16_LO: | |
7267 | case R_PPC_GOT_TLSLD16_HI: | |
7268 | case R_PPC_GOT_TLSLD16_HA: | |
7269 | tls_type = TLS_TLS | TLS_LD; | |
7270 | goto dogot; | |
7271 | ||
7272 | case R_PPC_GOT_TPREL16: | |
7273 | case R_PPC_GOT_TPREL16_LO: | |
7274 | case R_PPC_GOT_TPREL16_HI: | |
7275 | case R_PPC_GOT_TPREL16_HA: | |
7276 | tls_type = TLS_TLS | TLS_TPREL; | |
7277 | goto dogot; | |
7278 | ||
7279 | case R_PPC_GOT_DTPREL16: | |
7280 | case R_PPC_GOT_DTPREL16_LO: | |
7281 | case R_PPC_GOT_DTPREL16_HI: | |
7282 | case R_PPC_GOT_DTPREL16_HA: | |
7283 | tls_type = TLS_TLS | TLS_DTPREL; | |
7284 | goto dogot; | |
7285 | ||
7286 | case R_PPC_GOT16: | |
7287 | case R_PPC_GOT16_LO: | |
7288 | case R_PPC_GOT16_HI: | |
7289 | case R_PPC_GOT16_HA: | |
727fc41e | 7290 | tls_mask = 0; |
7619e7c7 AM |
7291 | dogot: |
7292 | { | |
7293 | /* Relocation is to the entry for this symbol in the global | |
7294 | offset table. */ | |
7295 | bfd_vma off; | |
7296 | bfd_vma *offp; | |
7297 | unsigned long indx; | |
7298 | ||
7299 | if (htab->got == NULL) | |
7300 | abort (); | |
7301 | ||
7302 | indx = 0; | |
7303 | if (tls_type == (TLS_TLS | TLS_LD) | |
d881513a | 7304 | && (h == NULL |
f5385ebf | 7305 | || !h->def_dynamic)) |
7619e7c7 AM |
7306 | offp = &htab->tlsld_got.offset; |
7307 | else if (h != NULL) | |
7308 | { | |
7309 | bfd_boolean dyn; | |
7310 | dyn = htab->elf.dynamic_sections_created; | |
ee05f2fe | 7311 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
7619e7c7 AM |
7312 | || (info->shared |
7313 | && SYMBOL_REFERENCES_LOCAL (info, h))) | |
7314 | /* This is actually a static link, or it is a | |
7315 | -Bsymbolic link and the symbol is defined | |
7316 | locally, or the symbol was forced to be local | |
7317 | because of a version file. */ | |
7318 | ; | |
7319 | else | |
7320 | { | |
7321 | indx = h->dynindx; | |
7322 | unresolved_reloc = FALSE; | |
7323 | } | |
7324 | offp = &h->got.offset; | |
7325 | } | |
7326 | else | |
7327 | { | |
7328 | if (local_got_offsets == NULL) | |
7329 | abort (); | |
7330 | offp = &local_got_offsets[r_symndx]; | |
7331 | } | |
7332 | ||
7333 | /* The offset must always be a multiple of 4. We use the | |
7334 | least significant bit to record whether we have already | |
7335 | processed this entry. */ | |
7336 | off = *offp; | |
7337 | if ((off & 1) != 0) | |
7338 | off &= ~1; | |
7339 | else | |
7340 | { | |
70bccea4 AM |
7341 | unsigned int tls_m = (tls_mask |
7342 | & (TLS_LD | TLS_GD | TLS_DTPREL | |
7343 | | TLS_TPREL | TLS_TPRELGD)); | |
7344 | ||
7345 | if (offp == &htab->tlsld_got.offset) | |
7346 | tls_m = TLS_LD; | |
7347 | else if (h == NULL | |
f5385ebf | 7348 | || !h->def_dynamic) |
70bccea4 AM |
7349 | tls_m &= ~TLS_LD; |
7350 | ||
7351 | /* We might have multiple got entries for this sym. | |
7352 | Initialize them all. */ | |
7353 | do | |
7619e7c7 | 7354 | { |
70bccea4 AM |
7355 | int tls_ty = 0; |
7356 | ||
7357 | if ((tls_m & TLS_LD) != 0) | |
7619e7c7 | 7358 | { |
70bccea4 AM |
7359 | tls_ty = TLS_TLS | TLS_LD; |
7360 | tls_m &= ~TLS_LD; | |
7361 | } | |
7362 | else if ((tls_m & TLS_GD) != 0) | |
7363 | { | |
7364 | tls_ty = TLS_TLS | TLS_GD; | |
7365 | tls_m &= ~TLS_GD; | |
7366 | } | |
7367 | else if ((tls_m & TLS_DTPREL) != 0) | |
7368 | { | |
7369 | tls_ty = TLS_TLS | TLS_DTPREL; | |
7370 | tls_m &= ~TLS_DTPREL; | |
7371 | } | |
7372 | else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
7373 | { | |
7374 | tls_ty = TLS_TLS | TLS_TPREL; | |
7375 | tls_m = 0; | |
7619e7c7 | 7376 | } |
7619e7c7 | 7377 | |
70bccea4 | 7378 | /* Generate relocs for the dynamic linker. */ |
4e795f50 | 7379 | if ((info->shared || indx != 0) |
d6e14abc AM |
7380 | && (offp == &htab->tlsld_got.offset |
7381 | || h == NULL | |
4e795f50 AM |
7382 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7383 | || h->root.type != bfd_link_hash_undefweak)) | |
7619e7c7 | 7384 | { |
91e21fb7 | 7385 | asection *rsec = htab->relgot; |
91d6fa6a | 7386 | bfd_byte * loc; |
91e21fb7 | 7387 | |
70bccea4 AM |
7388 | outrel.r_offset = (htab->got->output_section->vma |
7389 | + htab->got->output_offset | |
7390 | + off); | |
e515b051 | 7391 | outrel.r_addend = 0; |
70bccea4 AM |
7392 | if (tls_ty & (TLS_LD | TLS_GD)) |
7393 | { | |
7394 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32); | |
70bccea4 AM |
7395 | if (tls_ty == (TLS_TLS | TLS_GD)) |
7396 | { | |
25f23106 AM |
7397 | loc = rsec->contents; |
7398 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
7399 | * sizeof (Elf32_External_Rela)); |
7400 | bfd_elf32_swap_reloca_out (output_bfd, | |
7401 | &outrel, loc); | |
e515b051 | 7402 | outrel.r_offset += 4; |
70bccea4 AM |
7403 | outrel.r_info |
7404 | = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
70bccea4 AM |
7405 | } |
7406 | } | |
7407 | else if (tls_ty == (TLS_TLS | TLS_DTPREL)) | |
7408 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
7409 | else if (tls_ty == (TLS_TLS | TLS_TPREL)) | |
7410 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32); | |
25f23106 | 7411 | else if (indx != 0) |
70bccea4 | 7412 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT); |
25f23106 AM |
7413 | else if (ifunc != NULL) |
7414 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7415 | else | |
7416 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
d6e14abc | 7417 | if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD)) |
e515b051 AM |
7418 | { |
7419 | outrel.r_addend += relocation; | |
7420 | if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 7421 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 7422 | } |
25f23106 AM |
7423 | loc = rsec->contents; |
7424 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
7425 | * sizeof (Elf32_External_Rela)); |
7426 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
7619e7c7 AM |
7427 | } |
7428 | ||
70bccea4 AM |
7429 | /* Init the .got section contents if we're not |
7430 | emitting a reloc. */ | |
7431 | else | |
7619e7c7 | 7432 | { |
70bccea4 AM |
7433 | bfd_vma value = relocation; |
7434 | ||
7b609f53 AM |
7435 | if (tls_ty == (TLS_TLS | TLS_LD)) |
7436 | value = 1; | |
7437 | else if (tls_ty != 0) | |
70bccea4 | 7438 | { |
e1918d23 | 7439 | value -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 7440 | if (tls_ty == (TLS_TLS | TLS_TPREL)) |
70bccea4 | 7441 | value += DTP_OFFSET - TP_OFFSET; |
70bccea4 | 7442 | |
7b609f53 AM |
7443 | if (tls_ty == (TLS_TLS | TLS_GD)) |
7444 | { | |
7445 | bfd_put_32 (output_bfd, value, | |
7446 | htab->got->contents + off + 4); | |
7447 | value = 1; | |
7448 | } | |
70bccea4 | 7449 | } |
70bccea4 AM |
7450 | bfd_put_32 (output_bfd, value, |
7451 | htab->got->contents + off); | |
7619e7c7 | 7452 | } |
70bccea4 AM |
7453 | |
7454 | off += 4; | |
7455 | if (tls_ty & (TLS_LD | TLS_GD)) | |
7456 | off += 4; | |
7619e7c7 | 7457 | } |
70bccea4 AM |
7458 | while (tls_m != 0); |
7459 | ||
7460 | off = *offp; | |
7461 | *offp = off | 1; | |
7619e7c7 AM |
7462 | } |
7463 | ||
7464 | if (off >= (bfd_vma) -2) | |
7465 | abort (); | |
7466 | ||
70bccea4 AM |
7467 | if ((tls_type & TLS_TLS) != 0) |
7468 | { | |
7469 | if (tls_type != (TLS_TLS | TLS_LD)) | |
7470 | { | |
7471 | if ((tls_mask & TLS_LD) != 0 | |
7472 | && !(h == NULL | |
f5385ebf | 7473 | || !h->def_dynamic)) |
70bccea4 AM |
7474 | off += 8; |
7475 | if (tls_type != (TLS_TLS | TLS_GD)) | |
7476 | { | |
7477 | if ((tls_mask & TLS_GD) != 0) | |
7478 | off += 8; | |
7479 | if (tls_type != (TLS_TLS | TLS_DTPREL)) | |
7480 | { | |
7481 | if ((tls_mask & TLS_DTPREL) != 0) | |
7482 | off += 4; | |
7483 | } | |
7484 | } | |
7485 | } | |
7486 | } | |
7487 | ||
e87d4038 AM |
7488 | relocation = (htab->got->output_section->vma |
7489 | + htab->got->output_offset | |
7490 | + off | |
7491 | - SYM_VAL (htab->elf.hgot)); | |
7619e7c7 AM |
7492 | |
7493 | /* Addends on got relocations don't make much sense. | |
7494 | x+off@got is actually x@got+off, and since the got is | |
7495 | generated by a hash table traversal, the value in the | |
7496 | got at entry m+n bears little relation to the entry m. */ | |
7497 | if (addend != 0) | |
25f53a85 AM |
7498 | info->callbacks->einfo |
7499 | (_("%H: non-zero addend on %s reloc against `%s'\n"), | |
7500 | input_bfd, input_section, rel->r_offset, | |
7b609f53 | 7501 | howto->name, |
7619e7c7 AM |
7502 | sym_name); |
7503 | } | |
70bccea4 | 7504 | break; |
7619e7c7 | 7505 | |
252b5132 | 7506 | /* Relocations that need no special processing. */ |
7619e7c7 | 7507 | case R_PPC_LOCAL24PC: |
252b5132 RH |
7508 | /* It makes no sense to point a local relocation |
7509 | at a symbol not in this object. */ | |
7b609f53 | 7510 | if (unresolved_reloc) |
252b5132 | 7511 | { |
464e1740 ILT |
7512 | if (! (*info->callbacks->undefined_symbol) (info, |
7513 | h->root.root.string, | |
7514 | input_bfd, | |
7515 | input_section, | |
5cc7c785 | 7516 | rel->r_offset, |
b34976b6 AM |
7517 | TRUE)) |
7518 | return FALSE; | |
252b5132 RH |
7519 | continue; |
7520 | } | |
7521 | break; | |
7522 | ||
7619e7c7 AM |
7523 | case R_PPC_DTPREL16: |
7524 | case R_PPC_DTPREL16_LO: | |
7525 | case R_PPC_DTPREL16_HI: | |
7526 | case R_PPC_DTPREL16_HA: | |
e1918d23 | 7527 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
7528 | break; |
7529 | ||
70bccea4 AM |
7530 | /* Relocations that may need to be propagated if this is a shared |
7531 | object. */ | |
7619e7c7 AM |
7532 | case R_PPC_TPREL16: |
7533 | case R_PPC_TPREL16_LO: | |
7534 | case R_PPC_TPREL16_HI: | |
7535 | case R_PPC_TPREL16_HA: | |
766bc656 AM |
7536 | if (h != NULL |
7537 | && h->root.type == bfd_link_hash_undefweak | |
7538 | && h->dynindx == -1) | |
7539 | { | |
7540 | /* Make this relocation against an undefined weak symbol | |
7541 | resolve to zero. This is really just a tweak, since | |
7542 | code using weak externs ought to check that they are | |
7543 | defined before using them. */ | |
7544 | bfd_byte *p = contents + rel->r_offset - d_offset; | |
7545 | unsigned int insn = bfd_get_32 (output_bfd, p); | |
7546 | insn = _bfd_elf_ppc_at_tprel_transform (insn, 2); | |
7547 | if (insn != 0) | |
7548 | bfd_put_32 (output_bfd, insn, p); | |
7549 | break; | |
7550 | } | |
e1918d23 | 7551 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
7552 | /* The TPREL16 relocs shouldn't really be used in shared |
7553 | libs as they will result in DT_TEXTREL being set, but | |
7554 | support them anyway. */ | |
7555 | goto dodyn; | |
7556 | ||
7557 | case R_PPC_TPREL32: | |
e1918d23 | 7558 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
7559 | goto dodyn; |
7560 | ||
7561 | case R_PPC_DTPREL32: | |
e1918d23 | 7562 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
7563 | goto dodyn; |
7564 | ||
e515b051 AM |
7565 | case R_PPC_DTPMOD32: |
7566 | relocation = 1; | |
7567 | addend = 0; | |
7568 | goto dodyn; | |
7569 | ||
d7128ce4 AM |
7570 | case R_PPC_REL16: |
7571 | case R_PPC_REL16_LO: | |
7572 | case R_PPC_REL16_HI: | |
7573 | case R_PPC_REL16_HA: | |
7574 | break; | |
7575 | ||
7619e7c7 | 7576 | case R_PPC_REL32: |
625af618 AM |
7577 | if (h == NULL || h == htab->elf.hgot) |
7578 | break; | |
7579 | /* fall through */ | |
7580 | ||
7581 | case R_PPC_ADDR32: | |
7582 | case R_PPC_ADDR16: | |
7583 | case R_PPC_ADDR16_LO: | |
7584 | case R_PPC_ADDR16_HI: | |
7585 | case R_PPC_ADDR16_HA: | |
7586 | case R_PPC_UADDR32: | |
7587 | case R_PPC_UADDR16: | |
7588 | goto dodyn; | |
7589 | ||
7590 | case R_PPC_REL24: | |
7619e7c7 AM |
7591 | case R_PPC_REL14: |
7592 | case R_PPC_REL14_BRTAKEN: | |
7593 | case R_PPC_REL14_BRNTAKEN: | |
252b5132 RH |
7594 | /* If these relocations are not to a named symbol, they can be |
7595 | handled right here, no need to bother the dynamic linker. */ | |
89200bf8 | 7596 | if (SYMBOL_CALLS_LOCAL (info, h) |
3b36f7e6 | 7597 | || h == htab->elf.hgot) |
252b5132 | 7598 | break; |
70bccea4 | 7599 | /* fall through */ |
252b5132 | 7600 | |
7619e7c7 | 7601 | case R_PPC_ADDR24: |
7619e7c7 AM |
7602 | case R_PPC_ADDR14: |
7603 | case R_PPC_ADDR14_BRTAKEN: | |
7604 | case R_PPC_ADDR14_BRNTAKEN: | |
625af618 AM |
7605 | if (h != NULL && !info->shared) |
7606 | break; | |
7607 | /* fall through */ | |
7608 | ||
7619e7c7 | 7609 | dodyn: |
3348747a NS |
7610 | if ((input_section->flags & SEC_ALLOC) == 0 |
7611 | || is_vxworks_tls) | |
c87b5a93 | 7612 | break; |
c87b5a93 | 7613 | |
ee05f2fe | 7614 | if ((info->shared |
89200bf8 AM |
7615 | && !(h != NULL |
7616 | && ((h->root.type == bfd_link_hash_undefined | |
7617 | && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
7618 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL)) | |
7619 | || (h->root.type == bfd_link_hash_undefweak | |
7620 | && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT))) | |
1d483afe | 7621 | && (must_be_dyn_reloc (info, r_type) |
f6c52c13 | 7622 | || !SYMBOL_CALLS_LOCAL (info, h))) |
ee05f2fe AM |
7623 | || (ELIMINATE_COPY_RELOCS |
7624 | && !info->shared | |
ee05f2fe AM |
7625 | && h != NULL |
7626 | && h->dynindx != -1 | |
f5385ebf | 7627 | && !h->non_got_ref |
de972ffa | 7628 | && !h->def_regular)) |
252b5132 | 7629 | { |
0bb2d96a | 7630 | int skip; |
91d6fa6a | 7631 | bfd_byte * loc; |
252b5132 | 7632 | #ifdef DEBUG |
55fd94b0 AM |
7633 | fprintf (stderr, "ppc_elf_relocate_section needs to " |
7634 | "create relocation for %s\n", | |
70bccea4 AM |
7635 | (h && h->root.root.string |
7636 | ? h->root.root.string : "<unknown>")); | |
252b5132 RH |
7637 | #endif |
7638 | ||
7639 | /* When generating a shared object, these relocations | |
70bccea4 AM |
7640 | are copied into the output file to be resolved at run |
7641 | time. */ | |
252b5132 RH |
7642 | if (sreloc == NULL) |
7643 | { | |
25f23106 AM |
7644 | sreloc = elf_section_data (input_section)->sreloc; |
7645 | if (!htab->elf.dynamic_sections_created) | |
7646 | sreloc = htab->reliplt; | |
83bac4b0 | 7647 | if (sreloc == NULL) |
b34976b6 | 7648 | return FALSE; |
252b5132 RH |
7649 | } |
7650 | ||
0bb2d96a | 7651 | skip = 0; |
5b914448 AM |
7652 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, info, |
7653 | input_section, | |
7654 | rel->r_offset); | |
0bb2d96a JJ |
7655 | if (outrel.r_offset == (bfd_vma) -1 |
7656 | || outrel.r_offset == (bfd_vma) -2) | |
7657 | skip = (int) outrel.r_offset; | |
252b5132 RH |
7658 | outrel.r_offset += (input_section->output_section->vma |
7659 | + input_section->output_offset); | |
7660 | ||
7661 | if (skip) | |
7662 | memset (&outrel, 0, sizeof outrel); | |
89200bf8 AM |
7663 | else if ((h != NULL |
7664 | && (h->root.type == bfd_link_hash_undefined | |
7665 | || h->root.type == bfd_link_hash_undefweak)) | |
7666 | || !SYMBOL_REFERENCES_LOCAL (info, h)) | |
252b5132 | 7667 | { |
7619e7c7 | 7668 | unresolved_reloc = FALSE; |
252b5132 RH |
7669 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
7670 | outrel.r_addend = rel->r_addend; | |
7671 | } | |
7672 | else | |
7673 | { | |
47388f4c AM |
7674 | outrel.r_addend = relocation + rel->r_addend; |
7675 | ||
25f23106 | 7676 | if (r_type != R_PPC_ADDR32) |
252b5132 | 7677 | { |
89200bf8 | 7678 | long indx = 0; |
252b5132 | 7679 | |
25f23106 AM |
7680 | if (ifunc != NULL) |
7681 | { | |
7682 | /* If we get here when building a static | |
7683 | executable, then the libc startup function | |
7684 | responsible for applying indirect function | |
7685 | relocations is going to complain about | |
7686 | the reloc type. | |
7687 | If we get here when building a dynamic | |
7688 | executable, it will be because we have | |
7689 | a text relocation. The dynamic loader | |
7690 | will set the text segment writable and | |
7691 | non-executable to apply text relocations. | |
7692 | So we'll segfault when trying to run the | |
7693 | indirection function to resolve the reloc. */ | |
25f53a85 AM |
7694 | info->callbacks->einfo |
7695 | (_("%H: relocation %s for indirect " | |
7696 | "function %s unsupported\n"), | |
7697 | input_bfd, input_section, rel->r_offset, | |
25f23106 AM |
7698 | howto->name, |
7699 | sym_name); | |
7700 | ret = FALSE; | |
7701 | } | |
cf35638d | 7702 | else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec)) |
89200bf8 | 7703 | ; |
252b5132 RH |
7704 | else if (sec == NULL || sec->owner == NULL) |
7705 | { | |
7706 | bfd_set_error (bfd_error_bad_value); | |
89200bf8 | 7707 | ret = FALSE; |
252b5132 RH |
7708 | } |
7709 | else | |
7710 | { | |
7711 | asection *osec; | |
7712 | ||
47388f4c AM |
7713 | /* We are turning this relocation into one |
7714 | against a section symbol. It would be | |
7715 | proper to subtract the symbol's value, | |
7716 | osec->vma, from the emitted reloc addend, | |
25f23106 AM |
7717 | but ld.so expects buggy relocs. |
7718 | FIXME: Why not always use a zero index? */ | |
252b5132 RH |
7719 | osec = sec->output_section; |
7720 | indx = elf_section_data (osec)->dynindx; | |
74541ad4 AM |
7721 | if (indx == 0) |
7722 | { | |
7723 | osec = htab->elf.text_index_section; | |
7724 | indx = elf_section_data (osec)->dynindx; | |
7725 | } | |
7726 | BFD_ASSERT (indx != 0); | |
252b5132 | 7727 | #ifdef DEBUG |
74541ad4 | 7728 | if (indx == 0) |
e460dd0d | 7729 | printf ("indx=%ld section=%s flags=%08x name=%s\n", |
55fd94b0 AM |
7730 | indx, osec->name, osec->flags, |
7731 | h->root.root.string); | |
252b5132 RH |
7732 | #endif |
7733 | } | |
7734 | ||
7735 | outrel.r_info = ELF32_R_INFO (indx, r_type); | |
252b5132 | 7736 | } |
25f23106 AM |
7737 | else if (ifunc != NULL) |
7738 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7739 | else | |
7740 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
252b5132 RH |
7741 | } |
7742 | ||
947216bf AM |
7743 | loc = sreloc->contents; |
7744 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
7745 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 | 7746 | |
2243deae | 7747 | if (skip == -1) |
252b5132 | 7748 | continue; |
2243deae L |
7749 | |
7750 | /* This reloc will be computed at runtime. We clear the memory | |
7751 | so that it contains predictable value. */ | |
7752 | if (! skip | |
7753 | && ((input_section->flags & SEC_ALLOC) != 0 | |
7754 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)) | |
7755 | { | |
7756 | relocation = howto->pc_relative ? outrel.r_offset : 0; | |
7757 | addend = 0; | |
7758 | break; | |
7759 | } | |
252b5132 | 7760 | } |
252b5132 RH |
7761 | break; |
7762 | ||
32af9f6e AM |
7763 | case R_PPC_RELAX_PLT: |
7764 | case R_PPC_RELAX_PLTREL24: | |
de972ffa AM |
7765 | if (h != NULL) |
7766 | { | |
32af9f6e AM |
7767 | struct plt_entry *ent; |
7768 | bfd_vma got2_addend = 0; | |
7769 | ||
7770 | if (r_type == R_PPC_RELAX_PLTREL24) | |
7771 | { | |
7772 | if (info->shared) | |
7773 | got2_addend = addend; | |
7774 | addend = 0; | |
7775 | } | |
7776 | ent = find_plt_ent (&h->plt.plist, got2, got2_addend); | |
de972ffa AM |
7777 | if (htab->plt_type == PLT_NEW) |
7778 | relocation = (htab->glink->output_section->vma | |
7779 | + htab->glink->output_offset | |
7780 | + ent->glink_offset); | |
7781 | else | |
7782 | relocation = (htab->plt->output_section->vma | |
7783 | + htab->plt->output_offset | |
7784 | + ent->plt.offset); | |
7785 | } | |
b4a38de6 AM |
7786 | /* Fall thru */ |
7787 | ||
32af9f6e AM |
7788 | case R_PPC_RELAX: |
7789 | if (info->shared) | |
7790 | relocation -= (input_section->output_section->vma | |
7791 | + input_section->output_offset | |
7792 | + rel->r_offset - 4); | |
b4a38de6 | 7793 | |
9abc968f AM |
7794 | { |
7795 | unsigned long t0; | |
7796 | unsigned long t1; | |
7797 | ||
7798 | t0 = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
7799 | t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4); | |
7800 | ||
7801 | /* We're clearing the bits for R_PPC_ADDR16_HA | |
7802 | and R_PPC_ADDR16_LO here. */ | |
7803 | t0 &= ~0xffff; | |
7804 | t1 &= ~0xffff; | |
7805 | ||
7806 | /* t0 is HA, t1 is LO */ | |
7807 | relocation += addend; | |
7808 | t0 |= ((relocation + 0x8000) >> 16) & 0xffff; | |
7809 | t1 |= relocation & 0xffff; | |
7810 | ||
7811 | bfd_put_32 (output_bfd, t0, contents + rel->r_offset); | |
7812 | bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4); | |
9bc4e62b NS |
7813 | |
7814 | /* Rewrite the reloc and convert one of the trailing nop | |
7815 | relocs to describe this relocation. */ | |
7816 | BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE); | |
7817 | /* The relocs are at the bottom 2 bytes */ | |
7818 | rel[0].r_offset += 2; | |
7819 | memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel)); | |
7820 | rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); | |
7821 | rel[1].r_offset += 4; | |
7822 | rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); | |
7823 | rel++; | |
9abc968f | 7824 | } |
8517fae7 | 7825 | continue; |
deaaf2f3 | 7826 | |
70bccea4 | 7827 | /* Indirect .sdata relocation. */ |
7619e7c7 | 7828 | case R_PPC_EMB_SDAI16: |
c9a2f333 | 7829 | BFD_ASSERT (htab->sdata[0].section != NULL); |
bd6c6e2b AM |
7830 | if (!is_static_defined (htab->sdata[0].sym)) |
7831 | { | |
7832 | unresolved_reloc = TRUE; | |
7833 | break; | |
7834 | } | |
7619e7c7 | 7835 | relocation |
76750a2f AM |
7836 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0], |
7837 | h, relocation, rel); | |
bd6c6e2b | 7838 | addend = 0; |
252b5132 RH |
7839 | break; |
7840 | ||
70bccea4 | 7841 | /* Indirect .sdata2 relocation. */ |
7619e7c7 | 7842 | case R_PPC_EMB_SDA2I16: |
c9a2f333 | 7843 | BFD_ASSERT (htab->sdata[1].section != NULL); |
bd6c6e2b AM |
7844 | if (!is_static_defined (htab->sdata[1].sym)) |
7845 | { | |
7846 | unresolved_reloc = TRUE; | |
7847 | break; | |
7848 | } | |
7619e7c7 | 7849 | relocation |
76750a2f AM |
7850 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1], |
7851 | h, relocation, rel); | |
bd6c6e2b | 7852 | addend = 0; |
252b5132 RH |
7853 | break; |
7854 | ||
70bccea4 AM |
7855 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
7856 | section, not the actual VMA. This is appropriate when generating | |
7857 | an embedded ELF object, for which the .got section acts like the | |
7858 | AIX .toc section. */ | |
7619e7c7 | 7859 | case R_PPC_TOC16: /* phony GOT16 relocations */ |
3b4f3a11 AM |
7860 | if (sec == NULL || sec->output_section == NULL) |
7861 | { | |
7862 | unresolved_reloc = TRUE; | |
7863 | break; | |
7864 | } | |
7865 | BFD_ASSERT (strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 | |
f12123c0 | 7866 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0); |
252b5132 | 7867 | |
3b4f3a11 | 7868 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; |
252b5132 RH |
7869 | break; |
7870 | ||
7619e7c7 | 7871 | case R_PPC_PLTREL24: |
e054468f | 7872 | if (h == NULL || ifunc != NULL) |
6d78d0b9 | 7873 | break; |
252b5132 | 7874 | /* Relocation is to the entry for this symbol in the |
70bccea4 | 7875 | procedure linkage table. */ |
a6aa5195 | 7876 | { |
a877a2b6 AM |
7877 | struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2, |
7878 | info->shared ? addend : 0); | |
a6aa5195 AM |
7879 | addend = 0; |
7880 | if (ent == NULL | |
7881 | || htab->plt == NULL) | |
7882 | { | |
7883 | /* We didn't make a PLT entry for this symbol. This | |
7884 | happens when statically linking PIC code, or when | |
7885 | using -Bsymbolic. */ | |
7886 | break; | |
7887 | } | |
252b5132 | 7888 | |
a6aa5195 | 7889 | unresolved_reloc = FALSE; |
4a3dc543 | 7890 | if (htab->plt_type == PLT_NEW) |
a6aa5195 AM |
7891 | relocation = (htab->glink->output_section->vma |
7892 | + htab->glink->output_offset | |
7893 | + ent->glink_offset); | |
7894 | else | |
7895 | relocation = (htab->plt->output_section->vma | |
7896 | + htab->plt->output_offset | |
7897 | + ent->plt.offset); | |
7898 | } | |
8da6118f | 7899 | break; |
252b5132 | 7900 | |
70bccea4 | 7901 | /* Relocate against _SDA_BASE_. */ |
7619e7c7 | 7902 | case R_PPC_SDAREL16: |
252b5132 RH |
7903 | { |
7904 | const char *name; | |
bd6c6e2b | 7905 | struct elf_link_hash_entry *sda = htab->sdata[0].sym; |
252b5132 | 7906 | |
bd6c6e2b AM |
7907 | if (sec == NULL |
7908 | || sec->output_section == NULL | |
7909 | || !is_static_defined (sda)) | |
3b4f3a11 AM |
7910 | { |
7911 | unresolved_reloc = TRUE; | |
7912 | break; | |
7913 | } | |
bd6c6e2b | 7914 | addend -= SYM_VAL (sda); |
3b4f3a11 | 7915 | |
252b5132 | 7916 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 | 7917 | if (! ((CONST_STRNEQ (name, ".sdata") |
5f819128 | 7918 | && (name[6] == 0 || name[6] == '.')) |
0112cd26 | 7919 | || (CONST_STRNEQ (name, ".sbss") |
5f819128 | 7920 | && (name[5] == 0 || name[5] == '.')))) |
252b5132 | 7921 | { |
25f53a85 | 7922 | info->callbacks->einfo |
d003868e | 7923 | (_("%B: the target (%s) of a %s relocation is " |
25f53a85 | 7924 | "in the wrong output section (%s)\n"), |
d003868e | 7925 | input_bfd, |
55fd94b0 AM |
7926 | sym_name, |
7927 | howto->name, | |
7928 | name); | |
252b5132 | 7929 | } |
252b5132 RH |
7930 | } |
7931 | break; | |
7932 | ||
70bccea4 | 7933 | /* Relocate against _SDA2_BASE_. */ |
7619e7c7 | 7934 | case R_PPC_EMB_SDA2REL: |
252b5132 RH |
7935 | { |
7936 | const char *name; | |
bd6c6e2b | 7937 | struct elf_link_hash_entry *sda = htab->sdata[1].sym; |
252b5132 | 7938 | |
bd6c6e2b AM |
7939 | if (sec == NULL |
7940 | || sec->output_section == NULL | |
7941 | || !is_static_defined (sda)) | |
3b4f3a11 AM |
7942 | { |
7943 | unresolved_reloc = TRUE; | |
7944 | break; | |
7945 | } | |
bd6c6e2b | 7946 | addend -= SYM_VAL (sda); |
3b4f3a11 | 7947 | |
252b5132 | 7948 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 NC |
7949 | if (! (CONST_STRNEQ (name, ".sdata2") |
7950 | || CONST_STRNEQ (name, ".sbss2"))) | |
252b5132 | 7951 | { |
25f53a85 | 7952 | info->callbacks->einfo |
d003868e | 7953 | (_("%B: the target (%s) of a %s relocation is " |
25f53a85 | 7954 | "in the wrong output section (%s)\n"), |
d003868e | 7955 | input_bfd, |
55fd94b0 AM |
7956 | sym_name, |
7957 | howto->name, | |
7958 | name); | |
252b5132 | 7959 | } |
252b5132 RH |
7960 | } |
7961 | break; | |
7962 | ||
70bccea4 | 7963 | /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */ |
7619e7c7 AM |
7964 | case R_PPC_EMB_SDA21: |
7965 | case R_PPC_EMB_RELSDA: | |
252b5132 RH |
7966 | { |
7967 | const char *name; | |
7968 | int reg; | |
bd6c6e2b | 7969 | struct elf_link_hash_entry *sda = NULL; |
252b5132 | 7970 | |
3b4f3a11 AM |
7971 | if (sec == NULL || sec->output_section == NULL) |
7972 | { | |
7973 | unresolved_reloc = TRUE; | |
7974 | break; | |
7975 | } | |
7976 | ||
252b5132 | 7977 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 | 7978 | if (((CONST_STRNEQ (name, ".sdata") |
5f819128 | 7979 | && (name[6] == 0 || name[6] == '.')) |
0112cd26 | 7980 | || (CONST_STRNEQ (name, ".sbss") |
5f819128 | 7981 | && (name[5] == 0 || name[5] == '.')))) |
252b5132 RH |
7982 | { |
7983 | reg = 13; | |
bd6c6e2b | 7984 | sda = htab->sdata[0].sym; |
252b5132 | 7985 | } |
0112cd26 NC |
7986 | else if (CONST_STRNEQ (name, ".sdata2") |
7987 | || CONST_STRNEQ (name, ".sbss2")) | |
252b5132 RH |
7988 | { |
7989 | reg = 2; | |
bd6c6e2b | 7990 | sda = htab->sdata[1].sym; |
252b5132 | 7991 | } |
8da6118f KH |
7992 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 |
7993 | || strcmp (name, ".PPC.EMB.sbss0") == 0) | |
252b5132 RH |
7994 | { |
7995 | reg = 0; | |
7996 | } | |
252b5132 RH |
7997 | else |
7998 | { | |
25f53a85 | 7999 | info->callbacks->einfo |
d003868e | 8000 | (_("%B: the target (%s) of a %s relocation is " |
25f53a85 | 8001 | "in the wrong output section (%s)\n"), |
d003868e | 8002 | input_bfd, |
55fd94b0 AM |
8003 | sym_name, |
8004 | howto->name, | |
8005 | name); | |
252b5132 RH |
8006 | |
8007 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8008 | ret = FALSE; |
252b5132 RH |
8009 | continue; |
8010 | } | |
8011 | ||
bd6c6e2b AM |
8012 | if (sda != NULL) |
8013 | { | |
8014 | if (!is_static_defined (sda)) | |
8015 | { | |
8016 | unresolved_reloc = TRUE; | |
8017 | break; | |
8018 | } | |
8019 | addend -= SYM_VAL (sda); | |
8020 | } | |
8021 | ||
252b5132 | 8022 | if (r_type == R_PPC_EMB_SDA21) |
91d6fa6a NC |
8023 | { |
8024 | bfd_vma insn; /* Fill in register field. */ | |
8025 | ||
7619e7c7 | 8026 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
252b5132 | 8027 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); |
7619e7c7 | 8028 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
252b5132 RH |
8029 | } |
8030 | } | |
8031 | break; | |
8032 | ||
70bccea4 | 8033 | /* Relocate against the beginning of the section. */ |
7619e7c7 AM |
8034 | case R_PPC_SECTOFF: |
8035 | case R_PPC_SECTOFF_LO: | |
8036 | case R_PPC_SECTOFF_HI: | |
8037 | case R_PPC_SECTOFF_HA: | |
3b4f3a11 AM |
8038 | if (sec == NULL || sec->output_section == NULL) |
8039 | { | |
8040 | unresolved_reloc = TRUE; | |
8041 | break; | |
8042 | } | |
252b5132 | 8043 | addend -= sec->output_section->vma; |
252b5132 RH |
8044 | break; |
8045 | ||
70bccea4 | 8046 | /* Negative relocations. */ |
7619e7c7 AM |
8047 | case R_PPC_EMB_NADDR32: |
8048 | case R_PPC_EMB_NADDR16: | |
8049 | case R_PPC_EMB_NADDR16_LO: | |
8050 | case R_PPC_EMB_NADDR16_HI: | |
8051 | case R_PPC_EMB_NADDR16_HA: | |
8da6118f | 8052 | addend -= 2 * relocation; |
252b5132 RH |
8053 | break; |
8054 | ||
7619e7c7 AM |
8055 | case R_PPC_COPY: |
8056 | case R_PPC_GLOB_DAT: | |
8057 | case R_PPC_JMP_SLOT: | |
8058 | case R_PPC_RELATIVE: | |
e054468f | 8059 | case R_PPC_IRELATIVE: |
7619e7c7 AM |
8060 | case R_PPC_PLT32: |
8061 | case R_PPC_PLTREL32: | |
8062 | case R_PPC_PLT16_LO: | |
8063 | case R_PPC_PLT16_HI: | |
8064 | case R_PPC_PLT16_HA: | |
8065 | case R_PPC_ADDR30: | |
8066 | case R_PPC_EMB_RELSEC16: | |
8067 | case R_PPC_EMB_RELST_LO: | |
8068 | case R_PPC_EMB_RELST_HI: | |
8069 | case R_PPC_EMB_RELST_HA: | |
8070 | case R_PPC_EMB_BIT_FLD: | |
25f53a85 AM |
8071 | info->callbacks->einfo |
8072 | (_("%B: relocation %s is not yet supported for symbol %s\n"), | |
d003868e | 8073 | input_bfd, |
7619e7c7 AM |
8074 | howto->name, |
8075 | sym_name); | |
252b5132 RH |
8076 | |
8077 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 8078 | ret = FALSE; |
252b5132 | 8079 | continue; |
7619e7c7 | 8080 | } |
252b5132 | 8081 | |
7619e7c7 AM |
8082 | /* Do any further special processing. */ |
8083 | switch (r_type) | |
8084 | { | |
8085 | default: | |
8086 | break; | |
8087 | ||
8088 | case R_PPC_ADDR16_HA: | |
d7128ce4 | 8089 | case R_PPC_REL16_HA: |
7619e7c7 AM |
8090 | case R_PPC_SECTOFF_HA: |
8091 | case R_PPC_TPREL16_HA: | |
8092 | case R_PPC_DTPREL16_HA: | |
7619e7c7 AM |
8093 | case R_PPC_EMB_NADDR16_HA: |
8094 | case R_PPC_EMB_RELST_HA: | |
8095 | /* It's just possible that this symbol is a weak symbol | |
7b609f53 | 8096 | that's not actually defined anywhere. In that case, |
7619e7c7 AM |
8097 | 'sec' would be NULL, and we should leave the symbol |
8098 | alone (it will be set to zero elsewhere in the link). */ | |
5c5f6e17 AM |
8099 | if (sec == NULL) |
8100 | break; | |
8101 | /* Fall thru */ | |
8102 | ||
8103 | case R_PPC_PLT16_HA: | |
8104 | case R_PPC_GOT16_HA: | |
8105 | case R_PPC_GOT_TLSGD16_HA: | |
8106 | case R_PPC_GOT_TLSLD16_HA: | |
8107 | case R_PPC_GOT_TPREL16_HA: | |
8108 | case R_PPC_GOT_DTPREL16_HA: | |
8109 | /* Add 0x10000 if sign bit in 0:15 is set. | |
8110 | Bits 0:15 are not used. */ | |
8111 | addend += 0x8000; | |
7619e7c7 | 8112 | break; |
252b5132 RH |
8113 | } |
8114 | ||
252b5132 | 8115 | #ifdef DEBUG |
55fd94b0 AM |
8116 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, " |
8117 | "offset = %ld, addend = %ld\n", | |
252b5132 | 8118 | howto->name, |
8da6118f | 8119 | (int) r_type, |
252b5132 RH |
8120 | sym_name, |
8121 | r_symndx, | |
7619e7c7 | 8122 | (long) rel->r_offset, |
8da6118f | 8123 | (long) addend); |
252b5132 RH |
8124 | #endif |
8125 | ||
7619e7c7 AM |
8126 | if (unresolved_reloc |
8127 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
f5385ebf | 8128 | && h->def_dynamic)) |
7619e7c7 | 8129 | { |
25f53a85 AM |
8130 | info->callbacks->einfo |
8131 | (_("%H: unresolvable %s relocation against symbol `%s'\n"), | |
8132 | input_bfd, input_section, rel->r_offset, | |
7b609f53 | 8133 | howto->name, |
7619e7c7 AM |
8134 | sym_name); |
8135 | ret = FALSE; | |
8136 | } | |
8137 | ||
252b5132 RH |
8138 | r = _bfd_final_link_relocate (howto, |
8139 | input_bfd, | |
8140 | input_section, | |
8141 | contents, | |
7619e7c7 | 8142 | rel->r_offset, |
252b5132 RH |
8143 | relocation, |
8144 | addend); | |
8145 | ||
7619e7c7 | 8146 | if (r != bfd_reloc_ok) |
252b5132 | 8147 | { |
7619e7c7 | 8148 | if (r == bfd_reloc_overflow) |
252b5132 | 8149 | { |
7619e7c7 AM |
8150 | if (warned) |
8151 | continue; | |
8152 | if (h != NULL | |
8153 | && h->root.type == bfd_link_hash_undefweak | |
dc1bc0c9 RH |
8154 | && howto->pc_relative) |
8155 | { | |
8156 | /* Assume this is a call protected by other code that | |
8157 | detect the symbol is undefined. If this is the case, | |
8158 | we can safely ignore the overflow. If not, the | |
8159 | program is hosed anyway, and a little warning isn't | |
8160 | going to help. */ | |
252b5132 | 8161 | |
dc1bc0c9 RH |
8162 | continue; |
8163 | } | |
252b5132 | 8164 | |
7619e7c7 | 8165 | if (! (*info->callbacks->reloc_overflow) (info, |
dfeffb9f | 8166 | (h ? &h->root : NULL), |
7619e7c7 AM |
8167 | sym_name, |
8168 | howto->name, | |
8169 | rel->r_addend, | |
8170 | input_bfd, | |
8171 | input_section, | |
8172 | rel->r_offset)) | |
8173 | return FALSE; | |
dc1bc0c9 RH |
8174 | } |
8175 | else | |
8176 | { | |
25f53a85 AM |
8177 | info->callbacks->einfo |
8178 | (_("%H: %s reloc against `%s': error %d\n"), | |
8179 | input_bfd, input_section, rel->r_offset, | |
8180 | howto->name, sym_name, (int) r); | |
7619e7c7 | 8181 | ret = FALSE; |
252b5132 RH |
8182 | } |
8183 | } | |
8184 | } | |
8185 | ||
252b5132 RH |
8186 | #ifdef DEBUG |
8187 | fprintf (stderr, "\n"); | |
8188 | #endif | |
8189 | ||
8190 | return ret; | |
8191 | } | |
252b5132 | 8192 | \f |
25dbc73a AM |
8193 | /* Finish up dynamic symbol handling. We set the contents of various |
8194 | dynamic sections here. */ | |
c5fccbec | 8195 | |
b34976b6 | 8196 | static bfd_boolean |
25dbc73a AM |
8197 | ppc_elf_finish_dynamic_symbol (bfd *output_bfd, |
8198 | struct bfd_link_info *info, | |
8199 | struct elf_link_hash_entry *h, | |
8200 | Elf_Internal_Sym *sym) | |
e1a9cb8e | 8201 | { |
25dbc73a | 8202 | struct ppc_elf_link_hash_table *htab; |
a6aa5195 AM |
8203 | struct plt_entry *ent; |
8204 | bfd_boolean doneone; | |
e1a9cb8e | 8205 | |
25dbc73a AM |
8206 | #ifdef DEBUG |
8207 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", | |
8208 | h->root.root.string); | |
8209 | #endif | |
e1a9cb8e | 8210 | |
25dbc73a AM |
8211 | htab = ppc_elf_hash_table (info); |
8212 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
e1a9cb8e | 8213 | |
a6aa5195 AM |
8214 | doneone = FALSE; |
8215 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8216 | if (ent->plt.offset != (bfd_vma) -1) | |
8217 | { | |
8218 | if (!doneone) | |
8219 | { | |
8220 | Elf_Internal_Rela rela; | |
8221 | bfd_byte *loc; | |
8222 | bfd_vma reloc_index; | |
e1a9cb8e | 8223 | |
e054468f | 8224 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
8225 | || !htab->elf.dynamic_sections_created |
8226 | || h->dynindx == -1) | |
9d8504b1 PB |
8227 | reloc_index = ent->plt.offset / 4; |
8228 | else | |
8229 | { | |
8230 | reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size) | |
8231 | / htab->plt_slot_size); | |
8232 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES | |
4a3dc543 | 8233 | && htab->plt_type == PLT_OLD) |
9d8504b1 PB |
8234 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; |
8235 | } | |
8236 | ||
a6aa5195 AM |
8237 | /* This symbol has an entry in the procedure linkage table. |
8238 | Set it up. */ | |
e054468f | 8239 | if (htab->plt_type == PLT_VXWORKS |
25f23106 AM |
8240 | && htab->elf.dynamic_sections_created |
8241 | && h->dynindx != -1) | |
a6aa5195 | 8242 | { |
9d8504b1 PB |
8243 | bfd_vma got_offset; |
8244 | const bfd_vma *plt_entry; | |
5b914448 | 8245 | |
9d8504b1 PB |
8246 | /* The first three entries in .got.plt are reserved. */ |
8247 | got_offset = (reloc_index + 3) * 4; | |
8248 | ||
8249 | /* Use the right PLT. */ | |
8250 | plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry | |
8251 | : ppc_elf_vxworks_plt_entry; | |
8252 | ||
8253 | /* Fill in the .plt on VxWorks. */ | |
8254 | if (info->shared) | |
8255 | { | |
9d8504b1 | 8256 | bfd_put_32 (output_bfd, |
e87d4038 | 8257 | plt_entry[0] | PPC_HA (got_offset), |
9d8504b1 PB |
8258 | htab->plt->contents + ent->plt.offset + 0); |
8259 | bfd_put_32 (output_bfd, | |
e87d4038 | 8260 | plt_entry[1] | PPC_LO (got_offset), |
9d8504b1 PB |
8261 | htab->plt->contents + ent->plt.offset + 4); |
8262 | } | |
8263 | else | |
8264 | { | |
e87d4038 | 8265 | bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot); |
9d8504b1 PB |
8266 | |
8267 | bfd_put_32 (output_bfd, | |
e87d4038 | 8268 | plt_entry[0] | PPC_HA (got_loc), |
9d8504b1 PB |
8269 | htab->plt->contents + ent->plt.offset + 0); |
8270 | bfd_put_32 (output_bfd, | |
e87d4038 | 8271 | plt_entry[1] | PPC_LO (got_loc), |
9d8504b1 PB |
8272 | htab->plt->contents + ent->plt.offset + 4); |
8273 | } | |
8274 | ||
8275 | bfd_put_32 (output_bfd, plt_entry[2], | |
8276 | htab->plt->contents + ent->plt.offset + 8); | |
8277 | bfd_put_32 (output_bfd, plt_entry[3], | |
8278 | htab->plt->contents + ent->plt.offset + 12); | |
8279 | ||
8280 | /* This instruction is an immediate load. The value loaded is | |
8281 | the byte offset of the R_PPC_JMP_SLOT relocation from the | |
8282 | start of the .rela.plt section. The value is stored in the | |
8283 | low-order 16 bits of the load instruction. */ | |
8284 | /* NOTE: It appears that this is now an index rather than a | |
8285 | prescaled offset. */ | |
5b914448 | 8286 | bfd_put_32 (output_bfd, |
9d8504b1 PB |
8287 | plt_entry[4] | reloc_index, |
8288 | htab->plt->contents + ent->plt.offset + 16); | |
8289 | /* This instruction is a PC-relative branch whose target is | |
8290 | the start of the PLT section. The address of this branch | |
8291 | instruction is 20 bytes beyond the start of this PLT entry. | |
8292 | The address is encoded in bits 6-29, inclusive. The value | |
8293 | stored is right-shifted by two bits, permitting a 26-bit | |
8294 | offset. */ | |
5b914448 AM |
8295 | bfd_put_32 (output_bfd, |
8296 | (plt_entry[5] | |
9d8504b1 PB |
8297 | | (-(ent->plt.offset + 20) & 0x03fffffc)), |
8298 | htab->plt->contents + ent->plt.offset + 20); | |
8299 | bfd_put_32 (output_bfd, plt_entry[6], | |
8300 | htab->plt->contents + ent->plt.offset + 24); | |
8301 | bfd_put_32 (output_bfd, plt_entry[7], | |
8302 | htab->plt->contents + ent->plt.offset + 28); | |
8303 | ||
8304 | /* Fill in the GOT entry corresponding to this PLT slot with | |
8305 | the address immediately after the the "bctr" instruction | |
8306 | in this PLT entry. */ | |
8307 | bfd_put_32 (output_bfd, (htab->plt->output_section->vma | |
8308 | + htab->plt->output_offset | |
8309 | + ent->plt.offset + 16), | |
8310 | htab->sgotplt->contents + got_offset); | |
8311 | ||
8312 | if (!info->shared) | |
8313 | { | |
8314 | /* Fill in a couple of entries in .rela.plt.unloaded. */ | |
8315 | loc = htab->srelplt2->contents | |
8316 | + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index | |
8317 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS) | |
8318 | * sizeof (Elf32_External_Rela)); | |
8319 | ||
8320 | /* Provide the @ha relocation for the first instruction. */ | |
8321 | rela.r_offset = (htab->plt->output_section->vma | |
8322 | + htab->plt->output_offset | |
8323 | + ent->plt.offset + 2); | |
636ce3f5 | 8324 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
8325 | R_PPC_ADDR16_HA); |
8326 | rela.r_addend = got_offset; | |
8327 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8328 | loc += sizeof (Elf32_External_Rela); | |
8329 | ||
8330 | /* Provide the @l relocation for the second instruction. */ | |
8331 | rela.r_offset = (htab->plt->output_section->vma | |
8332 | + htab->plt->output_offset | |
8333 | + ent->plt.offset + 6); | |
636ce3f5 | 8334 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
8335 | R_PPC_ADDR16_LO); |
8336 | rela.r_addend = got_offset; | |
8337 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8338 | loc += sizeof (Elf32_External_Rela); | |
8339 | ||
8340 | /* Provide a relocation for the GOT entry corresponding to this | |
8341 | PLT slot. Point it at the middle of the .plt entry. */ | |
8342 | rela.r_offset = (htab->sgotplt->output_section->vma | |
8343 | + htab->sgotplt->output_offset | |
8344 | + got_offset); | |
7325306f | 8345 | rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, |
9d8504b1 PB |
8346 | R_PPC_ADDR32); |
8347 | rela.r_addend = ent->plt.offset + 16; | |
8348 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8349 | } | |
8350 | ||
8351 | /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT. | |
8352 | In particular, the offset for the relocation is not the | |
8353 | address of the PLT entry for this function, as specified | |
8354 | by the ABI. Instead, the offset is set to the address of | |
8355 | the GOT slot for this function. See EABI 4.4.4.1. */ | |
8356 | rela.r_offset = (htab->sgotplt->output_section->vma | |
8357 | + htab->sgotplt->output_offset | |
8358 | + got_offset); | |
8359 | ||
a6aa5195 AM |
8360 | } |
8361 | else | |
8362 | { | |
e054468f | 8363 | asection *splt = htab->plt; |
25f23106 AM |
8364 | if (!htab->elf.dynamic_sections_created |
8365 | || h->dynindx == -1) | |
e054468f AM |
8366 | splt = htab->iplt; |
8367 | ||
8368 | rela.r_offset = (splt->output_section->vma | |
8369 | + splt->output_offset | |
9d8504b1 | 8370 | + ent->plt.offset); |
e054468f | 8371 | if (htab->plt_type == PLT_OLD |
25f23106 AM |
8372 | || !htab->elf.dynamic_sections_created |
8373 | || h->dynindx == -1) | |
9d8504b1 PB |
8374 | { |
8375 | /* We don't need to fill in the .plt. The ppc dynamic | |
8376 | linker will fill it in. */ | |
8377 | } | |
8378 | else | |
8379 | { | |
8380 | bfd_vma val = (htab->glink_pltresolve + ent->plt.offset | |
8381 | + htab->glink->output_section->vma | |
8382 | + htab->glink->output_offset); | |
8383 | bfd_put_32 (output_bfd, val, | |
e054468f | 8384 | splt->contents + ent->plt.offset); |
9d8504b1 | 8385 | } |
a6aa5195 | 8386 | } |
e1a9cb8e | 8387 | |
a6aa5195 | 8388 | /* Fill in the entry in the .rela.plt section. */ |
a6aa5195 | 8389 | rela.r_addend = 0; |
e054468f AM |
8390 | if (!htab->elf.dynamic_sections_created |
8391 | || h->dynindx == -1) | |
8392 | { | |
8393 | BFD_ASSERT (h->type == STT_GNU_IFUNC | |
8394 | && h->def_regular | |
8395 | && (h->root.type == bfd_link_hash_defined | |
8396 | || h->root.type == bfd_link_hash_defweak)); | |
8397 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
8398 | rela.r_addend = SYM_VAL (h); | |
8399 | } | |
8400 | else | |
8401 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); | |
e1a9cb8e | 8402 | |
25f23106 AM |
8403 | if (!htab->elf.dynamic_sections_created |
8404 | || h->dynindx == -1) | |
8405 | loc = (htab->reliplt->contents | |
8406 | + (htab->reliplt->reloc_count++ | |
8407 | * sizeof (Elf32_External_Rela))); | |
e054468f | 8408 | else |
25f23106 AM |
8409 | loc = (htab->relplt->contents |
8410 | + reloc_index * sizeof (Elf32_External_Rela)); | |
a6aa5195 | 8411 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
e1a9cb8e | 8412 | |
a6aa5195 AM |
8413 | if (!h->def_regular) |
8414 | { | |
0eb4a168 AM |
8415 | /* Mark the symbol as undefined, rather than as |
8416 | defined in the .plt section. Leave the value if | |
8417 | there were any relocations where pointer equality | |
8418 | matters (this is a clue for the dynamic linker, to | |
8419 | make function pointer comparisons work between an | |
8420 | application and shared library), otherwise set it | |
8421 | to zero. */ | |
a6aa5195 | 8422 | sym->st_shndx = SHN_UNDEF; |
0eb4a168 | 8423 | if (!h->pointer_equality_needed) |
a6aa5195 | 8424 | sym->st_value = 0; |
0eb4a168 AM |
8425 | else if (!h->ref_regular_nonweak) |
8426 | { | |
625af618 AM |
8427 | /* This breaks function pointer comparisons, but |
8428 | that is better than breaking tests for a NULL | |
0eb4a168 | 8429 | function pointer. */ |
0eb4a168 AM |
8430 | sym->st_value = 0; |
8431 | } | |
a6aa5195 | 8432 | } |
de972ffa AM |
8433 | else if (h->type == STT_GNU_IFUNC |
8434 | && !info->shared) | |
8435 | { | |
8436 | /* Set the value of ifunc symbols in a non-pie | |
8437 | executable to the glink entry. This is to avoid | |
8438 | text relocations. We can't do this for ifunc in | |
8439 | allocate_dynrelocs, as we do for normal dynamic | |
8440 | function symbols with plt entries, because we need | |
8441 | to keep the original value around for the ifunc | |
8442 | relocation. */ | |
8443 | sym->st_shndx = (_bfd_elf_section_from_bfd_section | |
8444 | (output_bfd, htab->glink->output_section)); | |
5b914448 AM |
8445 | sym->st_value = (ent->glink_offset |
8446 | + htab->glink->output_offset | |
de972ffa AM |
8447 | + htab->glink->output_section->vma); |
8448 | } | |
a6aa5195 AM |
8449 | doneone = TRUE; |
8450 | } | |
e1a9cb8e | 8451 | |
e054468f | 8452 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
8453 | || !htab->elf.dynamic_sections_created |
8454 | || h->dynindx == -1) | |
a6aa5195 | 8455 | { |
a7f2871e | 8456 | unsigned char *p; |
e054468f | 8457 | asection *splt = htab->plt; |
25f23106 AM |
8458 | if (!htab->elf.dynamic_sections_created |
8459 | || h->dynindx == -1) | |
e054468f | 8460 | splt = htab->iplt; |
e1a9cb8e | 8461 | |
a7f2871e AM |
8462 | p = (unsigned char *) htab->glink->contents + ent->glink_offset; |
8463 | ||
8464 | if (h == htab->tls_get_addr && !htab->no_tls_get_addr_opt) | |
8465 | { | |
8466 | bfd_put_32 (output_bfd, LWZ_11_3, p); | |
8467 | p += 4; | |
8468 | bfd_put_32 (output_bfd, LWZ_12_3 + 4, p); | |
8469 | p += 4; | |
8470 | bfd_put_32 (output_bfd, MR_0_3, p); | |
8471 | p += 4; | |
8472 | bfd_put_32 (output_bfd, CMPWI_11_0, p); | |
8473 | p += 4; | |
8474 | bfd_put_32 (output_bfd, ADD_3_12_2, p); | |
8475 | p += 4; | |
8476 | bfd_put_32 (output_bfd, BEQLR, p); | |
8477 | p += 4; | |
8478 | bfd_put_32 (output_bfd, MR_3_0, p); | |
8479 | p += 4; | |
8480 | bfd_put_32 (output_bfd, NOP, p); | |
8481 | p += 4; | |
8482 | } | |
8483 | ||
8484 | write_glink_stub (ent, splt, p, info); | |
e1a9cb8e | 8485 | |
a877a2b6 | 8486 | if (!info->shared) |
e054468f AM |
8487 | /* We only need one non-PIC glink stub. */ |
8488 | break; | |
a6aa5195 AM |
8489 | } |
8490 | else | |
8491 | break; | |
8492 | } | |
e1a9cb8e | 8493 | |
25dbc73a AM |
8494 | if (h->needs_copy) |
8495 | { | |
8496 | asection *s; | |
8497 | Elf_Internal_Rela rela; | |
8498 | bfd_byte *loc; | |
e1a9cb8e | 8499 | |
25dbc73a | 8500 | /* This symbols needs a copy reloc. Set it up. */ |
e1a9cb8e | 8501 | |
25dbc73a AM |
8502 | #ifdef DEBUG |
8503 | fprintf (stderr, ", copy"); | |
8504 | #endif | |
e1a9cb8e | 8505 | |
25dbc73a | 8506 | BFD_ASSERT (h->dynindx != -1); |
86bbe32f | 8507 | |
4dc4a9a5 | 8508 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
8509 | s = htab->relsbss; |
8510 | else | |
8511 | s = htab->relbss; | |
8512 | BFD_ASSERT (s != NULL); | |
e1a9cb8e | 8513 | |
e87d4038 | 8514 | rela.r_offset = SYM_VAL (h); |
25dbc73a AM |
8515 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); |
8516 | rela.r_addend = 0; | |
8517 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); | |
8518 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8519 | } | |
e1a9cb8e | 8520 | |
25dbc73a AM |
8521 | #ifdef DEBUG |
8522 | fprintf (stderr, "\n"); | |
8523 | #endif | |
e1a9cb8e | 8524 | |
25dbc73a | 8525 | /* Mark some specially defined symbols as absolute. */ |
9d8504b1 PB |
8526 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
8527 | || (!htab->is_vxworks | |
8528 | && (h == htab->elf.hgot | |
8529 | || strcmp (h->root.root.string, | |
8530 | "_PROCEDURE_LINKAGE_TABLE_") == 0))) | |
25dbc73a | 8531 | sym->st_shndx = SHN_ABS; |
e1a9cb8e | 8532 | |
25dbc73a AM |
8533 | return TRUE; |
8534 | } | |
8535 | \f | |
8536 | static enum elf_reloc_type_class | |
8537 | ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela) | |
e1a9cb8e | 8538 | { |
25dbc73a AM |
8539 | switch (ELF32_R_TYPE (rela->r_info)) |
8540 | { | |
8541 | case R_PPC_RELATIVE: | |
8542 | return reloc_class_relative; | |
8543 | case R_PPC_REL24: | |
8544 | case R_PPC_ADDR24: | |
8545 | case R_PPC_JMP_SLOT: | |
8546 | return reloc_class_plt; | |
8547 | case R_PPC_COPY: | |
8548 | return reloc_class_copy; | |
8549 | default: | |
8550 | return reloc_class_normal; | |
8551 | } | |
e1a9cb8e | 8552 | } |
25dbc73a AM |
8553 | \f |
8554 | /* Finish up the dynamic sections. */ | |
e1a9cb8e | 8555 | |
25dbc73a AM |
8556 | static bfd_boolean |
8557 | ppc_elf_finish_dynamic_sections (bfd *output_bfd, | |
8558 | struct bfd_link_info *info) | |
e1a9cb8e | 8559 | { |
25dbc73a | 8560 | asection *sdyn; |
9d8504b1 | 8561 | asection *splt; |
25dbc73a | 8562 | struct ppc_elf_link_hash_table *htab; |
1fe44d79 | 8563 | bfd_vma got; |
e87d4038 AM |
8564 | bfd *dynobj; |
8565 | bfd_boolean ret = TRUE; | |
e1a9cb8e | 8566 | |
25dbc73a AM |
8567 | #ifdef DEBUG |
8568 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
8569 | #endif | |
6b0817e5 | 8570 | |
25dbc73a | 8571 | htab = ppc_elf_hash_table (info); |
9d8504b1 PB |
8572 | dynobj = elf_hash_table (info)->dynobj; |
8573 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
8574 | if (htab->is_vxworks) | |
5b914448 | 8575 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
9d8504b1 PB |
8576 | else |
8577 | splt = NULL; | |
e1a9cb8e | 8578 | |
1fe44d79 AM |
8579 | got = 0; |
8580 | if (htab->elf.hgot != NULL) | |
e87d4038 | 8581 | got = SYM_VAL (htab->elf.hgot); |
1fe44d79 | 8582 | |
25dbc73a | 8583 | if (htab->elf.dynamic_sections_created) |
e1a9cb8e | 8584 | { |
25dbc73a | 8585 | Elf32_External_Dyn *dyncon, *dynconend; |
e1a9cb8e | 8586 | |
25dbc73a | 8587 | BFD_ASSERT (htab->plt != NULL && sdyn != NULL); |
86bbe32f | 8588 | |
25dbc73a AM |
8589 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
8590 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); | |
8591 | for (; dyncon < dynconend; dyncon++) | |
8592 | { | |
8593 | Elf_Internal_Dyn dyn; | |
8594 | asection *s; | |
e1a9cb8e | 8595 | |
9d8504b1 | 8596 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
86bbe32f | 8597 | |
25dbc73a AM |
8598 | switch (dyn.d_tag) |
8599 | { | |
8600 | case DT_PLTGOT: | |
9d8504b1 PB |
8601 | if (htab->is_vxworks) |
8602 | s = htab->sgotplt; | |
8603 | else | |
8604 | s = htab->plt; | |
25dbc73a AM |
8605 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
8606 | break; | |
86bbe32f | 8607 | |
25dbc73a AM |
8608 | case DT_PLTRELSZ: |
8609 | dyn.d_un.d_val = htab->relplt->size; | |
8610 | break; | |
e1a9cb8e | 8611 | |
25dbc73a AM |
8612 | case DT_JMPREL: |
8613 | s = htab->relplt; | |
8614 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
8615 | break; | |
2f89ff8d | 8616 | |
1fe44d79 AM |
8617 | case DT_PPC_GOT: |
8618 | dyn.d_un.d_ptr = got; | |
d7128ce4 AM |
8619 | break; |
8620 | ||
9d8504b1 PB |
8621 | case DT_RELASZ: |
8622 | if (htab->is_vxworks) | |
8623 | { | |
8624 | if (htab->relplt) | |
8625 | dyn.d_un.d_ptr -= htab->relplt->size; | |
8626 | break; | |
8627 | } | |
8628 | continue; | |
8629 | ||
25dbc73a | 8630 | default: |
7a2b07ff NS |
8631 | if (htab->is_vxworks |
8632 | && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) | |
8633 | break; | |
25dbc73a AM |
8634 | continue; |
8635 | } | |
4c45e5c9 | 8636 | |
25dbc73a AM |
8637 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
8638 | } | |
8639 | } | |
4c45e5c9 | 8640 | |
3b36f7e6 | 8641 | if (htab->got != NULL) |
25dbc73a | 8642 | { |
e79f5955 AM |
8643 | if (htab->elf.hgot->root.u.def.section == htab->got |
8644 | || htab->elf.hgot->root.u.def.section == htab->sgotplt) | |
e87d4038 | 8645 | { |
e79f5955 | 8646 | unsigned char *p = htab->elf.hgot->root.u.def.section->contents; |
2f89ff8d | 8647 | |
e87d4038 AM |
8648 | p += htab->elf.hgot->root.u.def.value; |
8649 | if (htab->plt_type == PLT_OLD) | |
e79f5955 AM |
8650 | { |
8651 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 | |
8652 | so that a function can easily find the address of | |
8653 | _GLOBAL_OFFSET_TABLE_. */ | |
8654 | BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4 | |
8655 | < htab->elf.hgot->root.u.def.section->size); | |
8656 | bfd_put_32 (output_bfd, 0x4e800021, p - 4); | |
8657 | } | |
3b36f7e6 | 8658 | |
e87d4038 | 8659 | if (sdyn != NULL) |
e79f5955 AM |
8660 | { |
8661 | bfd_vma val = sdyn->output_section->vma + sdyn->output_offset; | |
8662 | BFD_ASSERT (htab->elf.hgot->root.u.def.value | |
8663 | < htab->elf.hgot->root.u.def.section->size); | |
8664 | bfd_put_32 (output_bfd, val, p); | |
8665 | } | |
e87d4038 AM |
8666 | } |
8667 | else | |
8668 | { | |
25f53a85 AM |
8669 | info->callbacks->einfo (_("%s not defined in linker created %s\n"), |
8670 | htab->elf.hgot->root.root.string, | |
8671 | (htab->sgotplt != NULL | |
8672 | ? htab->sgotplt->name : htab->got->name)); | |
e87d4038 AM |
8673 | bfd_set_error (bfd_error_bad_value); |
8674 | ret = FALSE; | |
8675 | } | |
25dbc73a AM |
8676 | |
8677 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4; | |
8678 | } | |
8679 | ||
9d8504b1 PB |
8680 | /* Fill in the first entry in the VxWorks procedure linkage table. */ |
8681 | if (splt && splt->size > 0) | |
8682 | { | |
8683 | /* Use the right PLT. */ | |
5b914448 AM |
8684 | const bfd_vma *plt_entry = (info->shared |
8685 | ? ppc_elf_vxworks_pic_plt0_entry | |
8686 | : ppc_elf_vxworks_plt0_entry); | |
9d8504b1 PB |
8687 | |
8688 | if (!info->shared) | |
8689 | { | |
e87d4038 | 8690 | bfd_vma got_value = SYM_VAL (htab->elf.hgot); |
9d8504b1 | 8691 | |
e87d4038 | 8692 | bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value), |
9d8504b1 | 8693 | splt->contents + 0); |
e87d4038 | 8694 | bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value), |
9d8504b1 PB |
8695 | splt->contents + 4); |
8696 | } | |
8697 | else | |
8698 | { | |
8699 | bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0); | |
8700 | bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4); | |
8701 | } | |
8702 | bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8); | |
8703 | bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12); | |
8704 | bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16); | |
8705 | bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20); | |
8706 | bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24); | |
8707 | bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28); | |
8708 | ||
8709 | if (! info->shared) | |
8710 | { | |
8711 | Elf_Internal_Rela rela; | |
8712 | bfd_byte *loc; | |
8713 | ||
8714 | loc = htab->srelplt2->contents; | |
8715 | ||
8716 | /* Output the @ha relocation for the first instruction. */ | |
8717 | rela.r_offset = (htab->plt->output_section->vma | |
8718 | + htab->plt->output_offset | |
8719 | + 2); | |
636ce3f5 | 8720 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
8721 | rela.r_addend = 0; |
8722 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8723 | loc += sizeof (Elf32_External_Rela); | |
5b914448 | 8724 | |
9d8504b1 PB |
8725 | /* Output the @l relocation for the second instruction. */ |
8726 | rela.r_offset = (htab->plt->output_section->vma | |
8727 | + htab->plt->output_offset | |
8728 | + 6); | |
636ce3f5 | 8729 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
8730 | rela.r_addend = 0; |
8731 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8732 | loc += sizeof (Elf32_External_Rela); | |
8733 | ||
8734 | /* Fix up the remaining relocations. They may have the wrong | |
8735 | symbol index for _G_O_T_ or _P_L_T_ depending on the order | |
8736 | in which symbols were output. */ | |
8737 | while (loc < htab->srelplt2->contents + htab->srelplt2->size) | |
8738 | { | |
8739 | Elf_Internal_Rela rel; | |
8740 | ||
8741 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 8742 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
8743 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8744 | loc += sizeof (Elf32_External_Rela); | |
8745 | ||
8746 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 8747 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
8748 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8749 | loc += sizeof (Elf32_External_Rela); | |
8750 | ||
8751 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
7325306f | 8752 | rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32); |
9d8504b1 PB |
8753 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8754 | loc += sizeof (Elf32_External_Rela); | |
8755 | } | |
8756 | } | |
8757 | } | |
8758 | ||
e054468f AM |
8759 | if (htab->glink != NULL |
8760 | && htab->glink->contents != NULL | |
8761 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
8762 | { |
8763 | unsigned char *p; | |
8764 | unsigned char *endp; | |
a6aa5195 | 8765 | bfd_vma res0; |
d7128ce4 | 8766 | unsigned int i; |
a6aa5195 AM |
8767 | |
8768 | /* | |
8769 | * PIC glink code is the following: | |
8770 | * | |
8771 | * # ith PLT code stub. | |
8772 | * addis 11,30,(plt+(i-1)*4-got)@ha | |
8773 | * lwz 11,(plt+(i-1)*4-got)@l(11) | |
8774 | * mtctr 11 | |
8775 | * bctr | |
8776 | * | |
8777 | * # A table of branches, one for each plt entry. | |
176a0d42 | 8778 | * # The idea is that the plt call stub loads ctr and r11 with these |
a6aa5195 AM |
8779 | * # addresses, so (r11 - res_0) gives the plt index * 4. |
8780 | * res_0: b PLTresolve | |
8781 | * res_1: b PLTresolve | |
8782 | * . | |
8783 | * # Some number of entries towards the end can be nops | |
8784 | * res_n_m3: nop | |
8785 | * res_n_m2: nop | |
8786 | * res_n_m1: | |
8787 | * | |
8788 | * PLTresolve: | |
8789 | * addis 11,11,(1f-res_0)@ha | |
8790 | * mflr 0 | |
8791 | * bcl 20,31,1f | |
8792 | * 1: addi 11,11,(1b-res_0)@l | |
8793 | * mflr 12 | |
8794 | * mtlr 0 | |
8795 | * sub 11,11,12 # r11 = index * 4 | |
8796 | * addis 12,12,(got+4-1b)@ha | |
8797 | * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve | |
8798 | * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address | |
8799 | * mtctr 0 | |
8800 | * add 0,11,11 | |
8801 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
8802 | * bctr | |
8803 | */ | |
8804 | static const unsigned int pic_plt_resolve[] = | |
8805 | { | |
8806 | ADDIS_11_11, | |
8807 | MFLR_0, | |
8808 | BCL_20_31, | |
8809 | ADDI_11_11, | |
8810 | MFLR_12, | |
8811 | MTLR_0, | |
8812 | SUB_11_11_12, | |
8813 | ADDIS_12_12, | |
8814 | LWZ_0_12, | |
8815 | LWZ_12_12, | |
8816 | MTCTR_0, | |
8817 | ADD_0_11_11, | |
8818 | ADD_11_0_11, | |
8819 | BCTR, | |
8820 | NOP, | |
8821 | NOP | |
8822 | }; | |
8823 | ||
176a0d42 AM |
8824 | /* |
8825 | * Non-PIC glink code is a little simpler. | |
8826 | * | |
8827 | * # ith PLT code stub. | |
8828 | * lis 11,(plt+(i-1)*4)@ha | |
8829 | * lwz 11,(plt+(i-1)*4)@l(11) | |
8830 | * mtctr 11 | |
8831 | * bctr | |
8832 | * | |
8833 | * The branch table is the same, then comes | |
8834 | * | |
8835 | * PLTresolve: | |
8836 | * lis 12,(got+4)@ha | |
8837 | * addis 11,11,(-res_0)@ha | |
8838 | * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve | |
8839 | * addi 11,11,(-res_0)@l # r11 = index * 4 | |
8840 | * mtctr 0 | |
8841 | * add 0,11,11 | |
8842 | * lwz 12,(got+8)@l(12) # got[2] contains the map address | |
8843 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
8844 | * bctr | |
8845 | */ | |
d7128ce4 AM |
8846 | static const unsigned int plt_resolve[] = |
8847 | { | |
a6aa5195 AM |
8848 | LIS_12, |
8849 | ADDIS_11_11, | |
8850 | LWZ_0_12, | |
8851 | ADDI_11_11, | |
d7128ce4 | 8852 | MTCTR_0, |
7e8aeb9a | 8853 | ADD_0_11_11, |
a6aa5195 | 8854 | LWZ_12_12, |
7e8aeb9a | 8855 | ADD_11_0_11, |
d7128ce4 AM |
8856 | BCTR, |
8857 | NOP, | |
8858 | NOP, | |
a6aa5195 AM |
8859 | NOP, |
8860 | NOP, | |
8861 | NOP, | |
8862 | NOP, | |
d7128ce4 AM |
8863 | NOP |
8864 | }; | |
8865 | ||
a6aa5195 AM |
8866 | if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4) |
8867 | abort (); | |
8868 | if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4) | |
7e8aeb9a AM |
8869 | abort (); |
8870 | ||
a6aa5195 | 8871 | /* Build the branch table, one for each plt entry (less one), |
86b9da88 | 8872 | and perhaps some padding. */ |
a6aa5195 AM |
8873 | p = htab->glink->contents; |
8874 | p += htab->glink_pltresolve; | |
86b9da88 AM |
8875 | endp = htab->glink->contents; |
8876 | endp += htab->glink->size - GLINK_PLTRESOLVE; | |
8877 | while (p < endp - 8 * 4) | |
8878 | { | |
8879 | bfd_put_32 (output_bfd, B + endp - p, p); | |
8880 | p += 4; | |
8881 | } | |
8882 | while (p < endp) | |
8883 | { | |
8884 | bfd_put_32 (output_bfd, NOP, p); | |
8885 | p += 4; | |
8886 | } | |
8887 | ||
7e8aeb9a | 8888 | res0 = (htab->glink_pltresolve |
86b9da88 AM |
8889 | + htab->glink->output_section->vma |
8890 | + htab->glink->output_offset); | |
8891 | ||
8892 | /* Last comes the PLTresolve stub. */ | |
a877a2b6 | 8893 | if (info->shared) |
7e8aeb9a | 8894 | { |
a6aa5195 | 8895 | bfd_vma bcl; |
d7128ce4 | 8896 | |
a6aa5195 | 8897 | for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++) |
7e8aeb9a | 8898 | { |
a6aa5195 | 8899 | bfd_put_32 (output_bfd, pic_plt_resolve[i], p); |
7e8aeb9a AM |
8900 | p += 4; |
8901 | } | |
a6aa5195 AM |
8902 | p -= 4 * ARRAY_SIZE (pic_plt_resolve); |
8903 | ||
8904 | bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4 | |
8905 | + htab->glink->output_section->vma | |
8906 | + htab->glink->output_offset); | |
8907 | ||
8908 | bfd_put_32 (output_bfd, | |
8909 | ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4); | |
8910 | bfd_put_32 (output_bfd, | |
8911 | ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4); | |
8912 | bfd_put_32 (output_bfd, | |
8913 | ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4); | |
8914 | if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl)) | |
8915 | { | |
8916 | bfd_put_32 (output_bfd, | |
8917 | LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
8918 | bfd_put_32 (output_bfd, | |
8919 | LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4); | |
8920 | } | |
8921 | else | |
8922 | { | |
8923 | bfd_put_32 (output_bfd, | |
8924 | LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
8925 | bfd_put_32 (output_bfd, | |
8926 | LWZ_12_12 + 4, p + 9*4); | |
8927 | } | |
7e8aeb9a AM |
8928 | } |
8929 | else | |
d7128ce4 | 8930 | { |
a6aa5195 | 8931 | for (i = 0; i < ARRAY_SIZE (plt_resolve); i++) |
7e8aeb9a AM |
8932 | { |
8933 | bfd_put_32 (output_bfd, plt_resolve[i], p); | |
8934 | p += 4; | |
8935 | } | |
a6aa5195 AM |
8936 | p -= 4 * ARRAY_SIZE (plt_resolve); |
8937 | ||
8938 | bfd_put_32 (output_bfd, | |
8939 | LIS_12 + PPC_HA (got + 4), p + 0*4); | |
8940 | bfd_put_32 (output_bfd, | |
8941 | ADDIS_11_11 + PPC_HA (-res0), p + 1*4); | |
8942 | bfd_put_32 (output_bfd, | |
8943 | ADDI_11_11 + PPC_LO (-res0), p + 3*4); | |
8944 | if (PPC_HA (got + 4) == PPC_HA (got + 8)) | |
8945 | { | |
8946 | bfd_put_32 (output_bfd, | |
8947 | LWZ_0_12 + PPC_LO (got + 4), p + 2*4); | |
8948 | bfd_put_32 (output_bfd, | |
8949 | LWZ_12_12 + PPC_LO (got + 8), p + 6*4); | |
8950 | } | |
8951 | else | |
8952 | { | |
8953 | bfd_put_32 (output_bfd, | |
8954 | LWZU_0_12 + PPC_LO (got + 4), p + 2*4); | |
8955 | bfd_put_32 (output_bfd, | |
8956 | LWZ_12_12 + 4, p + 6*4); | |
8957 | } | |
d7128ce4 | 8958 | } |
d7128ce4 AM |
8959 | } |
8960 | ||
6177242a AM |
8961 | if (htab->glink_eh_frame != NULL |
8962 | && htab->glink_eh_frame->contents != NULL) | |
8963 | { | |
8964 | unsigned char *p = htab->glink_eh_frame->contents; | |
8965 | bfd_vma val; | |
8966 | ||
8967 | memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie)); | |
8968 | /* CIE length (rewrite in case little-endian). */ | |
8969 | bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p); | |
8970 | p += sizeof (glink_eh_frame_cie); | |
8971 | /* FDE length. */ | |
8972 | val = htab->glink_eh_frame->size - 4 - sizeof (glink_eh_frame_cie); | |
8973 | bfd_put_32 (htab->elf.dynobj, val, p); | |
8974 | p += 4; | |
8975 | /* CIE pointer. */ | |
8976 | val = p - htab->glink_eh_frame->contents; | |
8977 | bfd_put_32 (htab->elf.dynobj, val, p); | |
8978 | p += 4; | |
8979 | /* Offset to .glink. */ | |
8980 | val = (htab->glink->output_section->vma | |
8981 | + htab->glink->output_offset); | |
8982 | val -= (htab->glink_eh_frame->output_section->vma | |
8983 | + htab->glink_eh_frame->output_offset); | |
8984 | val -= p - htab->glink_eh_frame->contents; | |
8985 | bfd_put_32 (htab->elf.dynobj, val, p); | |
8986 | p += 4; | |
8987 | /* .glink size. */ | |
8988 | bfd_put_32 (htab->elf.dynobj, htab->glink->size, p); | |
8989 | p += 4; | |
8990 | /* Augmentation. */ | |
8991 | p += 1; | |
8992 | ||
8993 | if (info->shared | |
8994 | && htab->elf.dynamic_sections_created) | |
8995 | { | |
8996 | bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2; | |
8997 | if (adv < 64) | |
8998 | *p++ = DW_CFA_advance_loc + adv; | |
8999 | else if (adv < 256) | |
9000 | { | |
9001 | *p++ = DW_CFA_advance_loc1; | |
9002 | *p++ = adv; | |
9003 | } | |
9004 | else if (adv < 65536) | |
9005 | { | |
9006 | *p++ = DW_CFA_advance_loc2; | |
9007 | bfd_put_16 (htab->elf.dynobj, adv, p); | |
9008 | p += 2; | |
9009 | } | |
9010 | else | |
9011 | { | |
9012 | *p++ = DW_CFA_advance_loc4; | |
9013 | bfd_put_32 (htab->elf.dynobj, adv, p); | |
9014 | p += 4; | |
9015 | } | |
9016 | *p++ = DW_CFA_register; | |
9017 | *p++ = 65; | |
9018 | p++; | |
9019 | *p++ = DW_CFA_advance_loc + 4; | |
9020 | *p++ = DW_CFA_restore_extended; | |
9021 | *p++ = 65; | |
9022 | } | |
9023 | BFD_ASSERT ((bfd_vma) ((p + 3 - htab->glink_eh_frame->contents) & -4) | |
9024 | == htab->glink_eh_frame->size); | |
9025 | ||
9026 | if (htab->glink_eh_frame->sec_info_type == ELF_INFO_TYPE_EH_FRAME | |
9027 | && !_bfd_elf_write_section_eh_frame (output_bfd, info, | |
9028 | htab->glink_eh_frame, | |
9029 | htab->glink_eh_frame->contents)) | |
9030 | return FALSE; | |
9031 | } | |
9032 | ||
e87d4038 | 9033 | return ret; |
25dbc73a | 9034 | } |
e1a9cb8e | 9035 | \f |
252b5132 RH |
9036 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
9037 | #define TARGET_LITTLE_NAME "elf32-powerpcle" | |
9038 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec | |
9039 | #define TARGET_BIG_NAME "elf32-powerpc" | |
9040 | #define ELF_ARCH bfd_arch_powerpc | |
ae95ffa6 | 9041 | #define ELF_TARGET_ID PPC32_ELF_DATA |
252b5132 | 9042 | #define ELF_MACHINE_CODE EM_PPC |
d0facd1b NC |
9043 | #ifdef __QNXTARGET__ |
9044 | #define ELF_MAXPAGESIZE 0x1000 | |
9045 | #else | |
252b5132 | 9046 | #define ELF_MAXPAGESIZE 0x10000 |
d0facd1b | 9047 | #endif |
b1342370 | 9048 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 9049 | #define ELF_COMMONPAGESIZE 0x1000 |
252b5132 RH |
9050 | #define elf_info_to_howto ppc_elf_info_to_howto |
9051 | ||
9052 | #ifdef EM_CYGNUS_POWERPC | |
9053 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
9054 | #endif | |
9055 | ||
9056 | #ifdef EM_PPC_OLD | |
9057 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
9058 | #endif | |
9059 | ||
9060 | #define elf_backend_plt_not_loaded 1 | |
252b5132 | 9061 | #define elf_backend_can_gc_sections 1 |
51b64d56 | 9062 | #define elf_backend_can_refcount 1 |
b491616a | 9063 | #define elf_backend_rela_normal 1 |
252b5132 | 9064 | |
43c40ab2 | 9065 | #define bfd_elf32_mkobject ppc_elf_mkobject |
252b5132 | 9066 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
70bccea4 | 9067 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section |
252b5132 | 9068 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup |
157090f7 | 9069 | #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup |
252b5132 | 9070 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags |
70bccea4 | 9071 | #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create |
468392fb | 9072 | #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab |
252b5132 | 9073 | |
feee612b | 9074 | #define elf_backend_object_p ppc_elf_object_p |
252b5132 RH |
9075 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
9076 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook | |
9077 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr | |
9078 | #define elf_backend_relocate_section ppc_elf_relocate_section | |
9079 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections | |
9080 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
7fce784e | 9081 | #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol |
252b5132 RH |
9082 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol |
9083 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook | |
9084 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
0eb4a168 | 9085 | #define elf_backend_hash_symbol ppc_elf_hash_symbol |
252b5132 RH |
9086 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol |
9087 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
9088 | #define elf_backend_fake_sections ppc_elf_fake_sections | |
9089 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers | |
c5fccbec DJ |
9090 | #define elf_backend_grok_prstatus ppc_elf_grok_prstatus |
9091 | #define elf_backend_grok_psinfo ppc_elf_grok_psinfo | |
183e98be | 9092 | #define elf_backend_write_core_note ppc_elf_write_core_note |
29c2fb7c | 9093 | #define elf_backend_reloc_type_class ppc_elf_reloc_type_class |
70bccea4 AM |
9094 | #define elf_backend_begin_write_processing ppc_elf_begin_write_processing |
9095 | #define elf_backend_final_write_processing ppc_elf_final_write_processing | |
9096 | #define elf_backend_write_section ppc_elf_write_section | |
551b43fd | 9097 | #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr |
4c45e5c9 | 9098 | #define elf_backend_plt_sym_val ppc_elf_plt_sym_val |
8a696751 | 9099 | #define elf_backend_action_discarded ppc_elf_action_discarded |
74541ad4 | 9100 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
e054468f | 9101 | #define elf_backend_post_process_headers _bfd_elf_set_osabi |
252b5132 RH |
9102 | |
9103 | #include "elf32-target.h" | |
9d8504b1 PB |
9104 | |
9105 | /* VxWorks Target */ | |
9106 | ||
9107 | #undef TARGET_LITTLE_SYM | |
9108 | #undef TARGET_LITTLE_NAME | |
9109 | ||
9110 | #undef TARGET_BIG_SYM | |
9111 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec | |
9112 | #undef TARGET_BIG_NAME | |
9113 | #define TARGET_BIG_NAME "elf32-powerpc-vxworks" | |
9114 | ||
d5e3d971 PB |
9115 | /* VxWorks uses the elf default section flags for .plt. */ |
9116 | static const struct bfd_elf_special_section * | |
9117 | ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) | |
9d8504b1 | 9118 | { |
d5e3d971 PB |
9119 | if (sec->name == NULL) |
9120 | return NULL; | |
9121 | ||
9122 | if (strcmp (sec->name, ".plt") == 0) | |
9123 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
9124 | ||
9125 | return ppc_elf_get_sec_type_attr (abfd, sec); | |
9126 | } | |
9d8504b1 PB |
9127 | |
9128 | /* Like ppc_elf_link_hash_table_create, but overrides | |
9129 | appropriately for VxWorks. */ | |
9130 | static struct bfd_link_hash_table * | |
9131 | ppc_elf_vxworks_link_hash_table_create (bfd *abfd) | |
9132 | { | |
9133 | struct bfd_link_hash_table *ret; | |
9134 | ||
9135 | ret = ppc_elf_link_hash_table_create (abfd); | |
9136 | if (ret) | |
9137 | { | |
9138 | struct ppc_elf_link_hash_table *htab | |
9139 | = (struct ppc_elf_link_hash_table *)ret; | |
9140 | htab->is_vxworks = 1; | |
4a3dc543 | 9141 | htab->plt_type = PLT_VXWORKS; |
9d8504b1 PB |
9142 | htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE; |
9143 | htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE; | |
9144 | htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE; | |
9145 | } | |
9146 | return ret; | |
9147 | } | |
9148 | ||
9149 | /* Tweak magic VxWorks symbols as they are loaded. */ | |
9150 | static bfd_boolean | |
9151 | ppc_elf_vxworks_add_symbol_hook (bfd *abfd, | |
9152 | struct bfd_link_info *info, | |
9153 | Elf_Internal_Sym *sym, | |
9154 | const char **namep ATTRIBUTE_UNUSED, | |
9155 | flagword *flagsp ATTRIBUTE_UNUSED, | |
9156 | asection **secp, | |
9157 | bfd_vma *valp) | |
9158 | { | |
9159 | if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, | |
9160 | valp)) | |
9161 | return FALSE; | |
9162 | ||
9163 | return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp); | |
9164 | } | |
9165 | ||
9d8504b1 PB |
9166 | static void |
9167 | ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
9168 | { | |
9169 | ppc_elf_final_write_processing(abfd, linker); | |
9170 | elf_vxworks_final_write_processing(abfd, linker); | |
9171 | } | |
9172 | ||
9173 | /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so | |
9174 | define it. */ | |
9175 | #undef elf_backend_want_plt_sym | |
9176 | #define elf_backend_want_plt_sym 1 | |
9177 | #undef elf_backend_want_got_plt | |
9178 | #define elf_backend_want_got_plt 1 | |
9179 | #undef elf_backend_got_symbol_offset | |
9180 | #define elf_backend_got_symbol_offset 0 | |
9181 | #undef elf_backend_plt_not_loaded | |
9182 | #define elf_backend_plt_not_loaded 0 | |
9183 | #undef elf_backend_plt_readonly | |
9184 | #define elf_backend_plt_readonly 1 | |
9185 | #undef elf_backend_got_header_size | |
9186 | #define elf_backend_got_header_size 12 | |
9187 | ||
468392fb AM |
9188 | #undef bfd_elf32_get_synthetic_symtab |
9189 | ||
9d8504b1 PB |
9190 | #undef bfd_elf32_bfd_link_hash_table_create |
9191 | #define bfd_elf32_bfd_link_hash_table_create \ | |
9192 | ppc_elf_vxworks_link_hash_table_create | |
9d8504b1 PB |
9193 | #undef elf_backend_add_symbol_hook |
9194 | #define elf_backend_add_symbol_hook \ | |
9195 | ppc_elf_vxworks_add_symbol_hook | |
9196 | #undef elf_backend_link_output_symbol_hook | |
9197 | #define elf_backend_link_output_symbol_hook \ | |
9c72ff84 | 9198 | elf_vxworks_link_output_symbol_hook |
9d8504b1 PB |
9199 | #undef elf_backend_final_write_processing |
9200 | #define elf_backend_final_write_processing \ | |
9201 | ppc_elf_vxworks_final_write_processing | |
d5e3d971 PB |
9202 | #undef elf_backend_get_sec_type_attr |
9203 | #define elf_backend_get_sec_type_attr \ | |
9204 | ppc_elf_vxworks_get_sec_type_attr | |
9d8504b1 PB |
9205 | #undef elf_backend_emit_relocs |
9206 | #define elf_backend_emit_relocs \ | |
9207 | elf_vxworks_emit_relocs | |
9208 | ||
9209 | #undef elf32_bed | |
9210 | #define elf32_bed ppc_elf_vxworks_bed | |
e054468f | 9211 | #undef elf_backend_post_process_headers |
9d8504b1 PB |
9212 | |
9213 | #include "elf32-target.h" |