]>
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, |
766bc656 | 3 | 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Ian Lance Taylor, Cygnus Support. |
5 | ||
ae9a127f | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
ae9a127f NC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 10 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 11 | (at your option) any later version. |
252b5132 | 12 | |
ae9a127f NC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
252b5132 | 17 | |
ae9a127f | 18 | You should have received a copy of the GNU General Public License |
fc0bffd6 | 19 | along with this program; if not, write to the |
3e110533 | 20 | Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
53e09e0a | 21 | Boston, MA 02110-1301, USA. */ |
252b5132 | 22 | |
cd123cb7 | 23 | |
252b5132 RH |
24 | /* This file is based on a preliminary PowerPC ELF ABI. The |
25 | information may not match the final PowerPC ELF ABI. It includes | |
26 | suggestions from the in-progress Embedded PowerPC ABI, and that | |
27 | information may also not match. */ | |
28 | ||
3db64b00 | 29 | #include "sysdep.h" |
183e98be | 30 | #include <stdarg.h> |
252b5132 | 31 | #include "bfd.h" |
252b5132 RH |
32 | #include "bfdlink.h" |
33 | #include "libbfd.h" | |
34 | #include "elf-bfd.h" | |
35 | #include "elf/ppc.h" | |
7619e7c7 | 36 | #include "elf32-ppc.h" |
9d8504b1 | 37 | #include "elf-vxworks.h" |
252b5132 | 38 | |
f0fe0e16 | 39 | /* RELA relocations are used here. */ |
252b5132 | 40 | |
252b5132 | 41 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
55fd94b0 | 42 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
7619e7c7 | 43 | static bfd_reloc_status_type ppc_elf_unhandled_reloc |
55fd94b0 | 44 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
252b5132 | 45 | |
70bccea4 AM |
46 | /* Branch prediction bit for branch taken relocs. */ |
47 | #define BRANCH_PREDICT_BIT 0x200000 | |
48 | /* Mask to set RA in memory instructions. */ | |
49 | #define RA_REGISTER_MASK 0x001f0000 | |
50 | /* Value to shift register by to insert RA. */ | |
51 | #define RA_REGISTER_SHIFT 16 | |
252b5132 RH |
52 | |
53 | /* The name of the dynamic interpreter. This is put in the .interp | |
54 | section. */ | |
252b5132 RH |
55 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
56 | ||
d7128ce4 | 57 | /* For old-style PLT. */ |
252b5132 RH |
58 | /* The number of single-slot PLT entries (the rest use two slots). */ |
59 | #define PLT_NUM_SINGLE_ENTRIES 8192 | |
60 | ||
d7128ce4 | 61 | /* For new-style .glink and .plt. */ |
a6aa5195 | 62 | #define GLINK_PLTRESOLVE 16*4 |
d7128ce4 | 63 | #define GLINK_ENTRY_SIZE 4*4 |
a7f2871e | 64 | #define TLS_GET_ADDR_GLINK_SIZE 12*4 |
d7128ce4 | 65 | |
9d8504b1 PB |
66 | /* VxWorks uses its own plt layout, filled in by the static linker. */ |
67 | ||
68 | /* The standard VxWorks PLT entry. */ | |
69 | #define VXWORKS_PLT_ENTRY_SIZE 32 | |
70 | static const bfd_vma ppc_elf_vxworks_plt_entry | |
71 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
72 | { | |
73 | 0x3d800000, /* lis r12,0 */ | |
74 | 0x818c0000, /* lwz r12,0(r12) */ | |
75 | 0x7d8903a6, /* mtctr r12 */ | |
76 | 0x4e800420, /* bctr */ | |
77 | 0x39600000, /* li r11,0 */ | |
78 | 0x48000000, /* b 14 <.PLT0resolve+0x4> */ | |
79 | 0x60000000, /* nop */ | |
80 | 0x60000000, /* nop */ | |
81 | }; | |
82 | static const bfd_vma ppc_elf_vxworks_pic_plt_entry | |
83 | [VXWORKS_PLT_ENTRY_SIZE / 4] = | |
84 | { | |
85 | 0x3d9e0000, /* addis r12,r30,0 */ | |
86 | 0x818c0000, /* lwz r12,0(r12) */ | |
87 | 0x7d8903a6, /* mtctr r12 */ | |
88 | 0x4e800420, /* bctr */ | |
89 | 0x39600000, /* li r11,0 */ | |
90 | 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */ | |
91 | 0x60000000, /* nop */ | |
92 | 0x60000000, /* nop */ | |
93 | }; | |
94 | ||
95 | /* The initial VxWorks PLT entry. */ | |
96 | #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32 | |
97 | static const bfd_vma ppc_elf_vxworks_plt0_entry | |
98 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
99 | { | |
100 | 0x3d800000, /* lis r12,0 */ | |
101 | 0x398c0000, /* addi r12,r12,0 */ | |
102 | 0x800c0008, /* lwz r0,8(r12) */ | |
103 | 0x7c0903a6, /* mtctr r0 */ | |
104 | 0x818c0004, /* lwz r12,4(r12) */ | |
105 | 0x4e800420, /* bctr */ | |
106 | 0x60000000, /* nop */ | |
107 | 0x60000000, /* nop */ | |
108 | }; | |
109 | static const bfd_vma ppc_elf_vxworks_pic_plt0_entry | |
110 | [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] = | |
111 | { | |
112 | 0x819e0008, /* lwz r12,8(r30) */ | |
113 | 0x7d8903a6, /* mtctr r12 */ | |
114 | 0x819e0004, /* lwz r12,4(r30) */ | |
115 | 0x4e800420, /* bctr */ | |
116 | 0x60000000, /* nop */ | |
117 | 0x60000000, /* nop */ | |
118 | 0x60000000, /* nop */ | |
119 | 0x60000000, /* nop */ | |
120 | }; | |
121 | ||
122 | /* For executables, we have some additional relocations in | |
123 | .rela.plt.unloaded, for the kernel loader. */ | |
124 | ||
125 | /* The number of non-JMP_SLOT relocations per PLT0 slot. */ | |
126 | #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3 | |
127 | /* The number of relocations in the PLTResolve slot. */ | |
128 | #define VXWORKS_PLTRESOLVE_RELOCS 2 | |
129 | /* The number of relocations in the PLTResolve slot when when creating | |
130 | a shared library. */ | |
131 | #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0 | |
132 | ||
d7128ce4 | 133 | /* Some instructions. */ |
d7128ce4 | 134 | #define ADDIS_11_11 0x3d6b0000 |
a6aa5195 AM |
135 | #define ADDIS_11_30 0x3d7e0000 |
136 | #define ADDIS_12_12 0x3d8c0000 | |
d7128ce4 | 137 | #define ADDI_11_11 0x396b0000 |
d7128ce4 | 138 | #define ADD_0_11_11 0x7c0b5a14 |
a7f2871e | 139 | #define ADD_3_12_2 0x7c6c1214 |
d7128ce4 | 140 | #define ADD_11_0_11 0x7d605a14 |
a6aa5195 AM |
141 | #define B 0x48000000 |
142 | #define BCL_20_31 0x429f0005 | |
d7128ce4 | 143 | #define BCTR 0x4e800420 |
a7f2871e AM |
144 | #define BEQLR 0x4d820020 |
145 | #define CMPWI_11_0 0x2c0b0000 | |
7e8aeb9a AM |
146 | #define LIS_11 0x3d600000 |
147 | #define LIS_12 0x3d800000 | |
a6aa5195 AM |
148 | #define LWZU_0_12 0x840c0000 |
149 | #define LWZ_0_12 0x800c0000 | |
a7f2871e | 150 | #define LWZ_11_3 0x81630000 |
a6aa5195 AM |
151 | #define LWZ_11_11 0x816b0000 |
152 | #define LWZ_11_30 0x817e0000 | |
a7f2871e | 153 | #define LWZ_12_3 0x81830000 |
a6aa5195 | 154 | #define LWZ_12_12 0x818c0000 |
a7f2871e AM |
155 | #define MR_0_3 0x7c601b78 |
156 | #define MR_3_0 0x7c030378 | |
a6aa5195 AM |
157 | #define MFLR_0 0x7c0802a6 |
158 | #define MFLR_12 0x7d8802a6 | |
159 | #define MTCTR_0 0x7c0903a6 | |
160 | #define MTCTR_11 0x7d6903a6 | |
161 | #define MTLR_0 0x7c0803a6 | |
162 | #define NOP 0x60000000 | |
163 | #define SUB_11_11_12 0x7d6c5850 | |
7619e7c7 AM |
164 | |
165 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
166 | #define TP_OFFSET 0x7000 | |
167 | #define DTP_OFFSET 0x8000 | |
e87d4038 AM |
168 | |
169 | /* The value of a defined global symbol. */ | |
170 | #define SYM_VAL(SYM) \ | |
171 | ((SYM)->root.u.def.section->output_section->vma \ | |
172 | + (SYM)->root.u.def.section->output_offset \ | |
173 | + (SYM)->root.u.def.value) | |
7fce784e | 174 | \f |
e47cd125 | 175 | static reloc_howto_type *ppc_elf_howto_table[R_PPC_max]; |
252b5132 | 176 | |
8da6118f | 177 | static reloc_howto_type ppc_elf_howto_raw[] = { |
252b5132 RH |
178 | /* This reloc does nothing. */ |
179 | HOWTO (R_PPC_NONE, /* type */ | |
180 | 0, /* rightshift */ | |
181 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
182 | 32, /* bitsize */ | |
b34976b6 | 183 | FALSE, /* pc_relative */ |
252b5132 RH |
184 | 0, /* bitpos */ |
185 | complain_overflow_bitfield, /* complain_on_overflow */ | |
186 | bfd_elf_generic_reloc, /* special_function */ | |
187 | "R_PPC_NONE", /* name */ | |
b34976b6 | 188 | FALSE, /* partial_inplace */ |
252b5132 RH |
189 | 0, /* src_mask */ |
190 | 0, /* dst_mask */ | |
b34976b6 | 191 | FALSE), /* pcrel_offset */ |
252b5132 RH |
192 | |
193 | /* A standard 32 bit relocation. */ | |
194 | HOWTO (R_PPC_ADDR32, /* type */ | |
195 | 0, /* rightshift */ | |
196 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
197 | 32, /* bitsize */ | |
b34976b6 | 198 | FALSE, /* pc_relative */ |
252b5132 RH |
199 | 0, /* bitpos */ |
200 | complain_overflow_bitfield, /* complain_on_overflow */ | |
201 | bfd_elf_generic_reloc, /* special_function */ | |
202 | "R_PPC_ADDR32", /* name */ | |
b34976b6 | 203 | FALSE, /* partial_inplace */ |
252b5132 RH |
204 | 0, /* src_mask */ |
205 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 206 | FALSE), /* pcrel_offset */ |
252b5132 RH |
207 | |
208 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
209 | FIXME: we don't check that, we just clear them. */ | |
210 | HOWTO (R_PPC_ADDR24, /* type */ | |
211 | 0, /* rightshift */ | |
212 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
213 | 26, /* bitsize */ | |
b34976b6 | 214 | FALSE, /* pc_relative */ |
252b5132 RH |
215 | 0, /* bitpos */ |
216 | complain_overflow_bitfield, /* complain_on_overflow */ | |
217 | bfd_elf_generic_reloc, /* special_function */ | |
218 | "R_PPC_ADDR24", /* name */ | |
b34976b6 | 219 | FALSE, /* partial_inplace */ |
252b5132 RH |
220 | 0, /* src_mask */ |
221 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 222 | FALSE), /* pcrel_offset */ |
252b5132 RH |
223 | |
224 | /* A standard 16 bit relocation. */ | |
225 | HOWTO (R_PPC_ADDR16, /* type */ | |
226 | 0, /* rightshift */ | |
227 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
228 | 16, /* bitsize */ | |
b34976b6 | 229 | FALSE, /* pc_relative */ |
252b5132 RH |
230 | 0, /* bitpos */ |
231 | complain_overflow_bitfield, /* complain_on_overflow */ | |
232 | bfd_elf_generic_reloc, /* special_function */ | |
233 | "R_PPC_ADDR16", /* name */ | |
b34976b6 | 234 | FALSE, /* partial_inplace */ |
252b5132 RH |
235 | 0, /* src_mask */ |
236 | 0xffff, /* dst_mask */ | |
b34976b6 | 237 | FALSE), /* pcrel_offset */ |
252b5132 RH |
238 | |
239 | /* A 16 bit relocation without overflow. */ | |
240 | HOWTO (R_PPC_ADDR16_LO, /* type */ | |
241 | 0, /* rightshift */ | |
242 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
243 | 16, /* bitsize */ | |
b34976b6 | 244 | FALSE, /* pc_relative */ |
252b5132 RH |
245 | 0, /* bitpos */ |
246 | complain_overflow_dont,/* complain_on_overflow */ | |
247 | bfd_elf_generic_reloc, /* special_function */ | |
248 | "R_PPC_ADDR16_LO", /* name */ | |
b34976b6 | 249 | FALSE, /* partial_inplace */ |
252b5132 RH |
250 | 0, /* src_mask */ |
251 | 0xffff, /* dst_mask */ | |
b34976b6 | 252 | FALSE), /* pcrel_offset */ |
252b5132 RH |
253 | |
254 | /* The high order 16 bits of an address. */ | |
255 | HOWTO (R_PPC_ADDR16_HI, /* type */ | |
256 | 16, /* rightshift */ | |
257 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
258 | 16, /* bitsize */ | |
b34976b6 | 259 | FALSE, /* pc_relative */ |
252b5132 RH |
260 | 0, /* bitpos */ |
261 | complain_overflow_dont, /* complain_on_overflow */ | |
262 | bfd_elf_generic_reloc, /* special_function */ | |
263 | "R_PPC_ADDR16_HI", /* name */ | |
b34976b6 | 264 | FALSE, /* partial_inplace */ |
252b5132 RH |
265 | 0, /* src_mask */ |
266 | 0xffff, /* dst_mask */ | |
b34976b6 | 267 | FALSE), /* pcrel_offset */ |
252b5132 RH |
268 | |
269 | /* The high order 16 bits of an address, plus 1 if the contents of | |
8da6118f | 270 | the low 16 bits, treated as a signed number, is negative. */ |
252b5132 RH |
271 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
272 | 16, /* rightshift */ | |
273 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
274 | 16, /* bitsize */ | |
b34976b6 | 275 | FALSE, /* pc_relative */ |
252b5132 RH |
276 | 0, /* bitpos */ |
277 | complain_overflow_dont, /* complain_on_overflow */ | |
278 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
279 | "R_PPC_ADDR16_HA", /* name */ | |
b34976b6 | 280 | FALSE, /* partial_inplace */ |
252b5132 RH |
281 | 0, /* src_mask */ |
282 | 0xffff, /* dst_mask */ | |
b34976b6 | 283 | FALSE), /* pcrel_offset */ |
252b5132 RH |
284 | |
285 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
286 | FIXME: we don't check that, we just clear them. */ | |
287 | HOWTO (R_PPC_ADDR14, /* type */ | |
288 | 0, /* rightshift */ | |
289 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
290 | 16, /* bitsize */ | |
b34976b6 | 291 | FALSE, /* pc_relative */ |
252b5132 RH |
292 | 0, /* bitpos */ |
293 | complain_overflow_bitfield, /* complain_on_overflow */ | |
294 | bfd_elf_generic_reloc, /* special_function */ | |
295 | "R_PPC_ADDR14", /* name */ | |
b34976b6 | 296 | FALSE, /* partial_inplace */ |
252b5132 RH |
297 | 0, /* src_mask */ |
298 | 0xfffc, /* dst_mask */ | |
b34976b6 | 299 | FALSE), /* pcrel_offset */ |
252b5132 RH |
300 | |
301 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
302 | indicate that the branch is expected to be taken. The lower two | |
8da6118f | 303 | bits must be zero. */ |
252b5132 RH |
304 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
305 | 0, /* rightshift */ | |
306 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
307 | 16, /* bitsize */ | |
b34976b6 | 308 | FALSE, /* pc_relative */ |
252b5132 RH |
309 | 0, /* bitpos */ |
310 | complain_overflow_bitfield, /* complain_on_overflow */ | |
311 | bfd_elf_generic_reloc, /* special_function */ | |
312 | "R_PPC_ADDR14_BRTAKEN",/* name */ | |
b34976b6 | 313 | FALSE, /* partial_inplace */ |
252b5132 RH |
314 | 0, /* src_mask */ |
315 | 0xfffc, /* dst_mask */ | |
b34976b6 | 316 | FALSE), /* pcrel_offset */ |
252b5132 RH |
317 | |
318 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
319 | indicate that the branch is not expected to be taken. The lower | |
320 | two bits must be zero. */ | |
321 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
322 | 0, /* rightshift */ | |
323 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
324 | 16, /* bitsize */ | |
b34976b6 | 325 | FALSE, /* pc_relative */ |
252b5132 RH |
326 | 0, /* bitpos */ |
327 | complain_overflow_bitfield, /* complain_on_overflow */ | |
328 | bfd_elf_generic_reloc, /* special_function */ | |
329 | "R_PPC_ADDR14_BRNTAKEN",/* name */ | |
b34976b6 | 330 | FALSE, /* partial_inplace */ |
252b5132 RH |
331 | 0, /* src_mask */ |
332 | 0xfffc, /* dst_mask */ | |
b34976b6 | 333 | FALSE), /* pcrel_offset */ |
252b5132 | 334 | |
8da6118f | 335 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
336 | HOWTO (R_PPC_REL24, /* type */ |
337 | 0, /* rightshift */ | |
338 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
339 | 26, /* bitsize */ | |
b34976b6 | 340 | TRUE, /* pc_relative */ |
252b5132 RH |
341 | 0, /* bitpos */ |
342 | complain_overflow_signed, /* complain_on_overflow */ | |
343 | bfd_elf_generic_reloc, /* special_function */ | |
344 | "R_PPC_REL24", /* name */ | |
b34976b6 | 345 | FALSE, /* partial_inplace */ |
252b5132 RH |
346 | 0, /* src_mask */ |
347 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 348 | TRUE), /* pcrel_offset */ |
252b5132 | 349 | |
8da6118f | 350 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
351 | HOWTO (R_PPC_REL14, /* type */ |
352 | 0, /* rightshift */ | |
353 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
354 | 16, /* bitsize */ | |
b34976b6 | 355 | TRUE, /* pc_relative */ |
252b5132 RH |
356 | 0, /* bitpos */ |
357 | complain_overflow_signed, /* complain_on_overflow */ | |
358 | bfd_elf_generic_reloc, /* special_function */ | |
359 | "R_PPC_REL14", /* name */ | |
b34976b6 | 360 | FALSE, /* partial_inplace */ |
252b5132 RH |
361 | 0, /* src_mask */ |
362 | 0xfffc, /* dst_mask */ | |
b34976b6 | 363 | TRUE), /* pcrel_offset */ |
252b5132 | 364 | |
8da6118f | 365 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
366 | the branch is expected to be taken. The lower two bits must be |
367 | zero. */ | |
368 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ | |
369 | 0, /* rightshift */ | |
370 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
371 | 16, /* bitsize */ | |
b34976b6 | 372 | TRUE, /* pc_relative */ |
252b5132 RH |
373 | 0, /* bitpos */ |
374 | complain_overflow_signed, /* complain_on_overflow */ | |
375 | bfd_elf_generic_reloc, /* special_function */ | |
376 | "R_PPC_REL14_BRTAKEN", /* name */ | |
b34976b6 | 377 | FALSE, /* partial_inplace */ |
252b5132 RH |
378 | 0, /* src_mask */ |
379 | 0xfffc, /* dst_mask */ | |
b34976b6 | 380 | TRUE), /* pcrel_offset */ |
252b5132 | 381 | |
8da6118f | 382 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
383 | the branch is not expected to be taken. The lower two bits must |
384 | be zero. */ | |
385 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ | |
386 | 0, /* rightshift */ | |
387 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
388 | 16, /* bitsize */ | |
b34976b6 | 389 | TRUE, /* pc_relative */ |
252b5132 RH |
390 | 0, /* bitpos */ |
391 | complain_overflow_signed, /* complain_on_overflow */ | |
392 | bfd_elf_generic_reloc, /* special_function */ | |
393 | "R_PPC_REL14_BRNTAKEN",/* name */ | |
b34976b6 | 394 | FALSE, /* partial_inplace */ |
252b5132 RH |
395 | 0, /* src_mask */ |
396 | 0xfffc, /* dst_mask */ | |
b34976b6 | 397 | TRUE), /* pcrel_offset */ |
252b5132 RH |
398 | |
399 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
400 | symbol. */ | |
401 | HOWTO (R_PPC_GOT16, /* type */ | |
402 | 0, /* rightshift */ | |
403 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
404 | 16, /* bitsize */ | |
b34976b6 | 405 | FALSE, /* pc_relative */ |
252b5132 RH |
406 | 0, /* bitpos */ |
407 | complain_overflow_signed, /* complain_on_overflow */ | |
408 | bfd_elf_generic_reloc, /* special_function */ | |
409 | "R_PPC_GOT16", /* name */ | |
b34976b6 | 410 | FALSE, /* partial_inplace */ |
252b5132 RH |
411 | 0, /* src_mask */ |
412 | 0xffff, /* dst_mask */ | |
b34976b6 | 413 | FALSE), /* pcrel_offset */ |
252b5132 RH |
414 | |
415 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
416 | the symbol. */ | |
417 | HOWTO (R_PPC_GOT16_LO, /* type */ | |
418 | 0, /* rightshift */ | |
419 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
420 | 16, /* bitsize */ | |
b34976b6 | 421 | FALSE, /* pc_relative */ |
252b5132 RH |
422 | 0, /* bitpos */ |
423 | complain_overflow_dont, /* complain_on_overflow */ | |
424 | bfd_elf_generic_reloc, /* special_function */ | |
425 | "R_PPC_GOT16_LO", /* name */ | |
b34976b6 | 426 | FALSE, /* partial_inplace */ |
252b5132 RH |
427 | 0, /* src_mask */ |
428 | 0xffff, /* dst_mask */ | |
b34976b6 | 429 | FALSE), /* pcrel_offset */ |
252b5132 RH |
430 | |
431 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
432 | the symbol. */ | |
433 | HOWTO (R_PPC_GOT16_HI, /* type */ | |
434 | 16, /* rightshift */ | |
435 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
436 | 16, /* bitsize */ | |
b34976b6 | 437 | FALSE, /* pc_relative */ |
252b5132 RH |
438 | 0, /* bitpos */ |
439 | complain_overflow_bitfield, /* complain_on_overflow */ | |
440 | bfd_elf_generic_reloc, /* special_function */ | |
441 | "R_PPC_GOT16_HI", /* name */ | |
b34976b6 | 442 | FALSE, /* partial_inplace */ |
252b5132 RH |
443 | 0, /* src_mask */ |
444 | 0xffff, /* dst_mask */ | |
b34976b6 | 445 | FALSE), /* pcrel_offset */ |
252b5132 RH |
446 | |
447 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
448 | the symbol. */ | |
449 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
450 | 16, /* rightshift */ | |
451 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
452 | 16, /* bitsize */ | |
b34976b6 | 453 | FALSE, /* pc_relative */ |
252b5132 RH |
454 | 0, /* bitpos */ |
455 | complain_overflow_bitfield, /* complain_on_overflow */ | |
456 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
457 | "R_PPC_GOT16_HA", /* name */ | |
b34976b6 | 458 | FALSE, /* partial_inplace */ |
252b5132 RH |
459 | 0, /* src_mask */ |
460 | 0xffff, /* dst_mask */ | |
b34976b6 | 461 | FALSE), /* pcrel_offset */ |
252b5132 RH |
462 | |
463 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
464 | entry for the symbol. */ | |
465 | HOWTO (R_PPC_PLTREL24, /* type */ | |
466 | 0, /* rightshift */ | |
467 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
468 | 26, /* bitsize */ | |
b34976b6 | 469 | TRUE, /* pc_relative */ |
252b5132 RH |
470 | 0, /* bitpos */ |
471 | complain_overflow_signed, /* complain_on_overflow */ | |
472 | bfd_elf_generic_reloc, /* special_function */ | |
473 | "R_PPC_PLTREL24", /* name */ | |
b34976b6 | 474 | FALSE, /* partial_inplace */ |
252b5132 RH |
475 | 0, /* src_mask */ |
476 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 477 | TRUE), /* pcrel_offset */ |
252b5132 RH |
478 | |
479 | /* This is used only by the dynamic linker. The symbol should exist | |
480 | both in the object being run and in some shared library. The | |
481 | dynamic linker copies the data addressed by the symbol from the | |
482 | shared library into the object, because the object being | |
483 | run has to have the data at some particular address. */ | |
484 | HOWTO (R_PPC_COPY, /* type */ | |
485 | 0, /* rightshift */ | |
486 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
487 | 32, /* bitsize */ | |
b34976b6 | 488 | FALSE, /* pc_relative */ |
252b5132 RH |
489 | 0, /* bitpos */ |
490 | complain_overflow_bitfield, /* complain_on_overflow */ | |
491 | bfd_elf_generic_reloc, /* special_function */ | |
492 | "R_PPC_COPY", /* name */ | |
b34976b6 | 493 | FALSE, /* partial_inplace */ |
252b5132 RH |
494 | 0, /* src_mask */ |
495 | 0, /* dst_mask */ | |
b34976b6 | 496 | FALSE), /* pcrel_offset */ |
252b5132 RH |
497 | |
498 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
499 | entries. */ | |
500 | HOWTO (R_PPC_GLOB_DAT, /* type */ | |
501 | 0, /* rightshift */ | |
502 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
503 | 32, /* bitsize */ | |
b34976b6 | 504 | FALSE, /* pc_relative */ |
252b5132 RH |
505 | 0, /* bitpos */ |
506 | complain_overflow_bitfield, /* complain_on_overflow */ | |
507 | bfd_elf_generic_reloc, /* special_function */ | |
508 | "R_PPC_GLOB_DAT", /* name */ | |
b34976b6 | 509 | FALSE, /* partial_inplace */ |
252b5132 RH |
510 | 0, /* src_mask */ |
511 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 512 | FALSE), /* pcrel_offset */ |
252b5132 RH |
513 | |
514 | /* Marks a procedure linkage table entry for a symbol. */ | |
515 | HOWTO (R_PPC_JMP_SLOT, /* type */ | |
516 | 0, /* rightshift */ | |
517 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
518 | 32, /* bitsize */ | |
b34976b6 | 519 | FALSE, /* pc_relative */ |
252b5132 RH |
520 | 0, /* bitpos */ |
521 | complain_overflow_bitfield, /* complain_on_overflow */ | |
522 | bfd_elf_generic_reloc, /* special_function */ | |
523 | "R_PPC_JMP_SLOT", /* name */ | |
b34976b6 | 524 | FALSE, /* partial_inplace */ |
252b5132 RH |
525 | 0, /* src_mask */ |
526 | 0, /* dst_mask */ | |
b34976b6 | 527 | FALSE), /* pcrel_offset */ |
252b5132 RH |
528 | |
529 | /* Used only by the dynamic linker. When the object is run, this | |
530 | longword is set to the load address of the object, plus the | |
531 | addend. */ | |
532 | HOWTO (R_PPC_RELATIVE, /* type */ | |
533 | 0, /* rightshift */ | |
534 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
535 | 32, /* bitsize */ | |
b34976b6 | 536 | FALSE, /* pc_relative */ |
252b5132 RH |
537 | 0, /* bitpos */ |
538 | complain_overflow_bitfield, /* complain_on_overflow */ | |
539 | bfd_elf_generic_reloc, /* special_function */ | |
540 | "R_PPC_RELATIVE", /* name */ | |
b34976b6 | 541 | FALSE, /* partial_inplace */ |
252b5132 RH |
542 | 0, /* src_mask */ |
543 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 544 | FALSE), /* pcrel_offset */ |
252b5132 RH |
545 | |
546 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
547 | object rather than the final value. Normally used for | |
548 | _GLOBAL_OFFSET_TABLE_. */ | |
549 | HOWTO (R_PPC_LOCAL24PC, /* type */ | |
550 | 0, /* rightshift */ | |
551 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
552 | 26, /* bitsize */ | |
b34976b6 | 553 | TRUE, /* pc_relative */ |
252b5132 RH |
554 | 0, /* bitpos */ |
555 | complain_overflow_signed, /* complain_on_overflow */ | |
556 | bfd_elf_generic_reloc, /* special_function */ | |
557 | "R_PPC_LOCAL24PC", /* name */ | |
b34976b6 | 558 | FALSE, /* partial_inplace */ |
252b5132 RH |
559 | 0, /* src_mask */ |
560 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 561 | TRUE), /* pcrel_offset */ |
252b5132 RH |
562 | |
563 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
564 | HOWTO (R_PPC_UADDR32, /* type */ | |
565 | 0, /* rightshift */ | |
566 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
567 | 32, /* bitsize */ | |
b34976b6 | 568 | FALSE, /* pc_relative */ |
252b5132 RH |
569 | 0, /* bitpos */ |
570 | complain_overflow_bitfield, /* complain_on_overflow */ | |
571 | bfd_elf_generic_reloc, /* special_function */ | |
572 | "R_PPC_UADDR32", /* name */ | |
b34976b6 | 573 | FALSE, /* partial_inplace */ |
252b5132 RH |
574 | 0, /* src_mask */ |
575 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 576 | FALSE), /* pcrel_offset */ |
252b5132 RH |
577 | |
578 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
579 | HOWTO (R_PPC_UADDR16, /* type */ | |
580 | 0, /* rightshift */ | |
581 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
582 | 16, /* bitsize */ | |
b34976b6 | 583 | FALSE, /* pc_relative */ |
252b5132 RH |
584 | 0, /* bitpos */ |
585 | complain_overflow_bitfield, /* complain_on_overflow */ | |
586 | bfd_elf_generic_reloc, /* special_function */ | |
587 | "R_PPC_UADDR16", /* name */ | |
b34976b6 | 588 | FALSE, /* partial_inplace */ |
252b5132 RH |
589 | 0, /* src_mask */ |
590 | 0xffff, /* dst_mask */ | |
b34976b6 | 591 | FALSE), /* pcrel_offset */ |
252b5132 RH |
592 | |
593 | /* 32-bit PC relative */ | |
594 | HOWTO (R_PPC_REL32, /* type */ | |
595 | 0, /* rightshift */ | |
596 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
597 | 32, /* bitsize */ | |
b34976b6 | 598 | TRUE, /* pc_relative */ |
252b5132 RH |
599 | 0, /* bitpos */ |
600 | complain_overflow_bitfield, /* complain_on_overflow */ | |
601 | bfd_elf_generic_reloc, /* special_function */ | |
602 | "R_PPC_REL32", /* name */ | |
b34976b6 | 603 | FALSE, /* partial_inplace */ |
252b5132 RH |
604 | 0, /* src_mask */ |
605 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 606 | TRUE), /* pcrel_offset */ |
252b5132 RH |
607 | |
608 | /* 32-bit relocation to the symbol's procedure linkage table. | |
c3668558 | 609 | FIXME: not supported. */ |
252b5132 RH |
610 | HOWTO (R_PPC_PLT32, /* type */ |
611 | 0, /* rightshift */ | |
612 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
613 | 32, /* bitsize */ | |
b34976b6 | 614 | FALSE, /* pc_relative */ |
252b5132 RH |
615 | 0, /* bitpos */ |
616 | complain_overflow_bitfield, /* complain_on_overflow */ | |
617 | bfd_elf_generic_reloc, /* special_function */ | |
618 | "R_PPC_PLT32", /* name */ | |
b34976b6 | 619 | FALSE, /* partial_inplace */ |
252b5132 RH |
620 | 0, /* src_mask */ |
621 | 0, /* dst_mask */ | |
b34976b6 | 622 | FALSE), /* pcrel_offset */ |
252b5132 RH |
623 | |
624 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
c3668558 | 625 | FIXME: not supported. */ |
252b5132 RH |
626 | HOWTO (R_PPC_PLTREL32, /* type */ |
627 | 0, /* rightshift */ | |
628 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
629 | 32, /* bitsize */ | |
b34976b6 | 630 | TRUE, /* pc_relative */ |
252b5132 RH |
631 | 0, /* bitpos */ |
632 | complain_overflow_bitfield, /* complain_on_overflow */ | |
633 | bfd_elf_generic_reloc, /* special_function */ | |
634 | "R_PPC_PLTREL32", /* name */ | |
b34976b6 | 635 | FALSE, /* partial_inplace */ |
252b5132 RH |
636 | 0, /* src_mask */ |
637 | 0, /* dst_mask */ | |
b34976b6 | 638 | TRUE), /* pcrel_offset */ |
252b5132 RH |
639 | |
640 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
641 | the symbol. */ | |
642 | HOWTO (R_PPC_PLT16_LO, /* type */ | |
643 | 0, /* rightshift */ | |
644 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
645 | 16, /* bitsize */ | |
b34976b6 | 646 | FALSE, /* pc_relative */ |
252b5132 RH |
647 | 0, /* bitpos */ |
648 | complain_overflow_dont, /* complain_on_overflow */ | |
649 | bfd_elf_generic_reloc, /* special_function */ | |
650 | "R_PPC_PLT16_LO", /* name */ | |
b34976b6 | 651 | FALSE, /* partial_inplace */ |
252b5132 RH |
652 | 0, /* src_mask */ |
653 | 0xffff, /* dst_mask */ | |
b34976b6 | 654 | FALSE), /* pcrel_offset */ |
252b5132 RH |
655 | |
656 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
657 | the symbol. */ | |
658 | HOWTO (R_PPC_PLT16_HI, /* type */ | |
659 | 16, /* rightshift */ | |
660 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
661 | 16, /* bitsize */ | |
b34976b6 | 662 | FALSE, /* pc_relative */ |
252b5132 RH |
663 | 0, /* bitpos */ |
664 | complain_overflow_bitfield, /* complain_on_overflow */ | |
665 | bfd_elf_generic_reloc, /* special_function */ | |
666 | "R_PPC_PLT16_HI", /* name */ | |
b34976b6 | 667 | FALSE, /* partial_inplace */ |
252b5132 RH |
668 | 0, /* src_mask */ |
669 | 0xffff, /* dst_mask */ | |
b34976b6 | 670 | FALSE), /* pcrel_offset */ |
252b5132 RH |
671 | |
672 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
673 | the symbol. */ | |
674 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
675 | 16, /* rightshift */ | |
676 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
677 | 16, /* bitsize */ | |
b34976b6 | 678 | FALSE, /* pc_relative */ |
252b5132 RH |
679 | 0, /* bitpos */ |
680 | complain_overflow_bitfield, /* complain_on_overflow */ | |
681 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
682 | "R_PPC_PLT16_HA", /* name */ | |
b34976b6 | 683 | FALSE, /* partial_inplace */ |
252b5132 RH |
684 | 0, /* src_mask */ |
685 | 0xffff, /* dst_mask */ | |
b34976b6 | 686 | FALSE), /* pcrel_offset */ |
252b5132 RH |
687 | |
688 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with | |
689 | small data items. */ | |
690 | HOWTO (R_PPC_SDAREL16, /* type */ | |
691 | 0, /* rightshift */ | |
692 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
693 | 16, /* bitsize */ | |
b34976b6 | 694 | FALSE, /* pc_relative */ |
252b5132 RH |
695 | 0, /* bitpos */ |
696 | complain_overflow_signed, /* complain_on_overflow */ | |
697 | bfd_elf_generic_reloc, /* special_function */ | |
698 | "R_PPC_SDAREL16", /* name */ | |
b34976b6 | 699 | FALSE, /* partial_inplace */ |
252b5132 RH |
700 | 0, /* src_mask */ |
701 | 0xffff, /* dst_mask */ | |
b34976b6 | 702 | FALSE), /* pcrel_offset */ |
252b5132 | 703 | |
c061c2d8 | 704 | /* 16-bit section relative relocation. */ |
252b5132 RH |
705 | HOWTO (R_PPC_SECTOFF, /* type */ |
706 | 0, /* rightshift */ | |
c061c2d8 AM |
707 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
708 | 16, /* bitsize */ | |
b34976b6 | 709 | FALSE, /* pc_relative */ |
252b5132 RH |
710 | 0, /* bitpos */ |
711 | complain_overflow_bitfield, /* complain_on_overflow */ | |
712 | bfd_elf_generic_reloc, /* special_function */ | |
713 | "R_PPC_SECTOFF", /* name */ | |
b34976b6 | 714 | FALSE, /* partial_inplace */ |
252b5132 | 715 | 0, /* src_mask */ |
c061c2d8 | 716 | 0xffff, /* dst_mask */ |
b34976b6 | 717 | FALSE), /* pcrel_offset */ |
252b5132 | 718 | |
c3668558 | 719 | /* 16-bit lower half section relative relocation. */ |
252b5132 RH |
720 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
721 | 0, /* rightshift */ | |
722 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
723 | 16, /* bitsize */ | |
b34976b6 | 724 | FALSE, /* pc_relative */ |
252b5132 RH |
725 | 0, /* bitpos */ |
726 | complain_overflow_dont, /* complain_on_overflow */ | |
727 | bfd_elf_generic_reloc, /* special_function */ | |
728 | "R_PPC_SECTOFF_LO", /* name */ | |
b34976b6 | 729 | FALSE, /* partial_inplace */ |
252b5132 RH |
730 | 0, /* src_mask */ |
731 | 0xffff, /* dst_mask */ | |
b34976b6 | 732 | FALSE), /* pcrel_offset */ |
252b5132 | 733 | |
c3668558 | 734 | /* 16-bit upper half section relative relocation. */ |
252b5132 RH |
735 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
736 | 16, /* rightshift */ | |
737 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
738 | 16, /* bitsize */ | |
b34976b6 | 739 | FALSE, /* pc_relative */ |
252b5132 RH |
740 | 0, /* bitpos */ |
741 | complain_overflow_bitfield, /* complain_on_overflow */ | |
742 | bfd_elf_generic_reloc, /* special_function */ | |
743 | "R_PPC_SECTOFF_HI", /* name */ | |
b34976b6 | 744 | FALSE, /* partial_inplace */ |
252b5132 RH |
745 | 0, /* src_mask */ |
746 | 0xffff, /* dst_mask */ | |
b34976b6 | 747 | FALSE), /* pcrel_offset */ |
252b5132 | 748 | |
c3668558 | 749 | /* 16-bit upper half adjusted section relative relocation. */ |
252b5132 RH |
750 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
751 | 16, /* rightshift */ | |
752 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
753 | 16, /* bitsize */ | |
b34976b6 | 754 | FALSE, /* pc_relative */ |
252b5132 RH |
755 | 0, /* bitpos */ |
756 | complain_overflow_bitfield, /* complain_on_overflow */ | |
757 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
758 | "R_PPC_SECTOFF_HA", /* name */ | |
b34976b6 | 759 | FALSE, /* partial_inplace */ |
252b5132 RH |
760 | 0, /* src_mask */ |
761 | 0xffff, /* dst_mask */ | |
b34976b6 | 762 | FALSE), /* pcrel_offset */ |
252b5132 | 763 | |
727fc41e | 764 | /* Marker relocs for TLS. */ |
7619e7c7 | 765 | HOWTO (R_PPC_TLS, |
252b5132 RH |
766 | 0, /* rightshift */ |
767 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
768 | 32, /* bitsize */ | |
b34976b6 | 769 | FALSE, /* pc_relative */ |
252b5132 | 770 | 0, /* bitpos */ |
7619e7c7 | 771 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 | 772 | bfd_elf_generic_reloc, /* special_function */ |
7619e7c7 AM |
773 | "R_PPC_TLS", /* name */ |
774 | FALSE, /* partial_inplace */ | |
775 | 0, /* src_mask */ | |
776 | 0, /* dst_mask */ | |
777 | FALSE), /* pcrel_offset */ | |
778 | ||
727fc41e AM |
779 | HOWTO (R_PPC_TLSGD, |
780 | 0, /* rightshift */ | |
781 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
782 | 32, /* bitsize */ | |
783 | FALSE, /* pc_relative */ | |
784 | 0, /* bitpos */ | |
785 | complain_overflow_dont, /* complain_on_overflow */ | |
786 | bfd_elf_generic_reloc, /* special_function */ | |
787 | "R_PPC_TLSGD", /* name */ | |
788 | FALSE, /* partial_inplace */ | |
789 | 0, /* src_mask */ | |
790 | 0, /* dst_mask */ | |
791 | FALSE), /* pcrel_offset */ | |
792 | ||
793 | HOWTO (R_PPC_TLSLD, | |
794 | 0, /* rightshift */ | |
795 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
796 | 32, /* bitsize */ | |
797 | FALSE, /* pc_relative */ | |
798 | 0, /* bitpos */ | |
799 | complain_overflow_dont, /* complain_on_overflow */ | |
800 | bfd_elf_generic_reloc, /* special_function */ | |
801 | "R_PPC_TLSLD", /* name */ | |
802 | FALSE, /* partial_inplace */ | |
803 | 0, /* src_mask */ | |
804 | 0, /* dst_mask */ | |
805 | FALSE), /* pcrel_offset */ | |
806 | ||
7619e7c7 AM |
807 | /* Computes the load module index of the load module that contains the |
808 | definition of its TLS sym. */ | |
809 | HOWTO (R_PPC_DTPMOD32, | |
810 | 0, /* rightshift */ | |
811 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
812 | 32, /* bitsize */ | |
813 | FALSE, /* pc_relative */ | |
814 | 0, /* bitpos */ | |
815 | complain_overflow_dont, /* complain_on_overflow */ | |
816 | ppc_elf_unhandled_reloc, /* special_function */ | |
817 | "R_PPC_DTPMOD32", /* name */ | |
b34976b6 | 818 | FALSE, /* partial_inplace */ |
252b5132 RH |
819 | 0, /* src_mask */ |
820 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 821 | FALSE), /* pcrel_offset */ |
252b5132 | 822 | |
7619e7c7 AM |
823 | /* Computes a dtv-relative displacement, the difference between the value |
824 | of sym+add and the base address of the thread-local storage block that | |
825 | contains the definition of sym, minus 0x8000. */ | |
826 | HOWTO (R_PPC_DTPREL32, | |
827 | 0, /* rightshift */ | |
828 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
829 | 32, /* bitsize */ | |
830 | FALSE, /* pc_relative */ | |
831 | 0, /* bitpos */ | |
832 | complain_overflow_dont, /* complain_on_overflow */ | |
833 | ppc_elf_unhandled_reloc, /* special_function */ | |
834 | "R_PPC_DTPREL32", /* name */ | |
835 | FALSE, /* partial_inplace */ | |
836 | 0, /* src_mask */ | |
837 | 0xffffffff, /* dst_mask */ | |
838 | FALSE), /* pcrel_offset */ | |
839 | ||
840 | /* A 16 bit dtprel reloc. */ | |
841 | HOWTO (R_PPC_DTPREL16, | |
252b5132 RH |
842 | 0, /* rightshift */ |
843 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
844 | 16, /* bitsize */ | |
b34976b6 | 845 | FALSE, /* pc_relative */ |
252b5132 | 846 | 0, /* bitpos */ |
7619e7c7 AM |
847 | complain_overflow_signed, /* complain_on_overflow */ |
848 | ppc_elf_unhandled_reloc, /* special_function */ | |
849 | "R_PPC_DTPREL16", /* name */ | |
b34976b6 | 850 | FALSE, /* partial_inplace */ |
252b5132 RH |
851 | 0, /* src_mask */ |
852 | 0xffff, /* dst_mask */ | |
b34976b6 | 853 | FALSE), /* pcrel_offset */ |
252b5132 | 854 | |
7619e7c7 AM |
855 | /* Like DTPREL16, but no overflow. */ |
856 | HOWTO (R_PPC_DTPREL16_LO, | |
252b5132 RH |
857 | 0, /* rightshift */ |
858 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
859 | 16, /* bitsize */ | |
b34976b6 | 860 | FALSE, /* pc_relative */ |
252b5132 | 861 | 0, /* bitpos */ |
7619e7c7 AM |
862 | complain_overflow_dont, /* complain_on_overflow */ |
863 | ppc_elf_unhandled_reloc, /* special_function */ | |
864 | "R_PPC_DTPREL16_LO", /* name */ | |
b34976b6 | 865 | FALSE, /* partial_inplace */ |
252b5132 RH |
866 | 0, /* src_mask */ |
867 | 0xffff, /* dst_mask */ | |
b34976b6 | 868 | FALSE), /* pcrel_offset */ |
252b5132 | 869 | |
7619e7c7 AM |
870 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ |
871 | HOWTO (R_PPC_DTPREL16_HI, | |
252b5132 RH |
872 | 16, /* rightshift */ |
873 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
874 | 16, /* bitsize */ | |
b34976b6 | 875 | FALSE, /* pc_relative */ |
252b5132 RH |
876 | 0, /* bitpos */ |
877 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
878 | ppc_elf_unhandled_reloc, /* special_function */ |
879 | "R_PPC_DTPREL16_HI", /* name */ | |
b34976b6 | 880 | FALSE, /* partial_inplace */ |
252b5132 RH |
881 | 0, /* src_mask */ |
882 | 0xffff, /* dst_mask */ | |
b34976b6 | 883 | FALSE), /* pcrel_offset */ |
252b5132 | 884 | |
7619e7c7 AM |
885 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ |
886 | HOWTO (R_PPC_DTPREL16_HA, | |
252b5132 RH |
887 | 16, /* rightshift */ |
888 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
889 | 16, /* bitsize */ | |
b34976b6 | 890 | FALSE, /* pc_relative */ |
252b5132 RH |
891 | 0, /* bitpos */ |
892 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
893 | ppc_elf_unhandled_reloc, /* special_function */ |
894 | "R_PPC_DTPREL16_HA", /* name */ | |
b34976b6 | 895 | FALSE, /* partial_inplace */ |
252b5132 RH |
896 | 0, /* src_mask */ |
897 | 0xffff, /* dst_mask */ | |
b34976b6 | 898 | FALSE), /* pcrel_offset */ |
252b5132 | 899 | |
7619e7c7 AM |
900 | /* Computes a tp-relative displacement, the difference between the value of |
901 | sym+add and the value of the thread pointer (r13). */ | |
902 | HOWTO (R_PPC_TPREL32, | |
903 | 0, /* rightshift */ | |
904 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
905 | 32, /* bitsize */ | |
906 | FALSE, /* pc_relative */ | |
907 | 0, /* bitpos */ | |
908 | complain_overflow_dont, /* complain_on_overflow */ | |
909 | ppc_elf_unhandled_reloc, /* special_function */ | |
910 | "R_PPC_TPREL32", /* name */ | |
911 | FALSE, /* partial_inplace */ | |
912 | 0, /* src_mask */ | |
913 | 0xffffffff, /* dst_mask */ | |
914 | FALSE), /* pcrel_offset */ | |
915 | ||
916 | /* A 16 bit tprel reloc. */ | |
917 | HOWTO (R_PPC_TPREL16, | |
252b5132 RH |
918 | 0, /* rightshift */ |
919 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
920 | 16, /* bitsize */ | |
b34976b6 | 921 | FALSE, /* pc_relative */ |
252b5132 | 922 | 0, /* bitpos */ |
7619e7c7 AM |
923 | complain_overflow_signed, /* complain_on_overflow */ |
924 | ppc_elf_unhandled_reloc, /* special_function */ | |
925 | "R_PPC_TPREL16", /* name */ | |
b34976b6 | 926 | FALSE, /* partial_inplace */ |
252b5132 RH |
927 | 0, /* src_mask */ |
928 | 0xffff, /* dst_mask */ | |
b34976b6 | 929 | FALSE), /* pcrel_offset */ |
252b5132 | 930 | |
7619e7c7 AM |
931 | /* Like TPREL16, but no overflow. */ |
932 | HOWTO (R_PPC_TPREL16_LO, | |
252b5132 RH |
933 | 0, /* rightshift */ |
934 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
935 | 16, /* bitsize */ | |
b34976b6 | 936 | FALSE, /* pc_relative */ |
252b5132 | 937 | 0, /* bitpos */ |
7619e7c7 AM |
938 | complain_overflow_dont, /* complain_on_overflow */ |
939 | ppc_elf_unhandled_reloc, /* special_function */ | |
940 | "R_PPC_TPREL16_LO", /* name */ | |
b34976b6 | 941 | FALSE, /* partial_inplace */ |
252b5132 RH |
942 | 0, /* src_mask */ |
943 | 0xffff, /* dst_mask */ | |
b34976b6 | 944 | FALSE), /* pcrel_offset */ |
252b5132 | 945 | |
7619e7c7 AM |
946 | /* Like TPREL16_LO, but next higher group of 16 bits. */ |
947 | HOWTO (R_PPC_TPREL16_HI, | |
948 | 16, /* rightshift */ | |
949 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
950 | 16, /* bitsize */ | |
951 | FALSE, /* pc_relative */ | |
952 | 0, /* bitpos */ | |
953 | complain_overflow_dont, /* complain_on_overflow */ | |
954 | ppc_elf_unhandled_reloc, /* special_function */ | |
955 | "R_PPC_TPREL16_HI", /* name */ | |
956 | FALSE, /* partial_inplace */ | |
957 | 0, /* src_mask */ | |
958 | 0xffff, /* dst_mask */ | |
959 | FALSE), /* pcrel_offset */ | |
960 | ||
961 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
962 | HOWTO (R_PPC_TPREL16_HA, | |
963 | 16, /* rightshift */ | |
964 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
965 | 16, /* bitsize */ | |
966 | FALSE, /* pc_relative */ | |
967 | 0, /* bitpos */ | |
968 | complain_overflow_dont, /* complain_on_overflow */ | |
969 | ppc_elf_unhandled_reloc, /* special_function */ | |
970 | "R_PPC_TPREL16_HA", /* name */ | |
971 | FALSE, /* partial_inplace */ | |
972 | 0, /* src_mask */ | |
973 | 0xffff, /* dst_mask */ | |
974 | FALSE), /* pcrel_offset */ | |
975 | ||
976 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
977 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
978 | to the first entry. */ | |
979 | HOWTO (R_PPC_GOT_TLSGD16, | |
252b5132 RH |
980 | 0, /* rightshift */ |
981 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
982 | 16, /* bitsize */ | |
b34976b6 | 983 | FALSE, /* pc_relative */ |
252b5132 RH |
984 | 0, /* bitpos */ |
985 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
986 | ppc_elf_unhandled_reloc, /* special_function */ |
987 | "R_PPC_GOT_TLSGD16", /* name */ | |
b34976b6 | 988 | FALSE, /* partial_inplace */ |
252b5132 RH |
989 | 0, /* src_mask */ |
990 | 0xffff, /* dst_mask */ | |
b34976b6 | 991 | FALSE), /* pcrel_offset */ |
252b5132 | 992 | |
7619e7c7 AM |
993 | /* Like GOT_TLSGD16, but no overflow. */ |
994 | HOWTO (R_PPC_GOT_TLSGD16_LO, | |
252b5132 | 995 | 0, /* rightshift */ |
7619e7c7 | 996 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 997 | 16, /* bitsize */ |
b34976b6 | 998 | FALSE, /* pc_relative */ |
252b5132 | 999 | 0, /* bitpos */ |
7619e7c7 AM |
1000 | complain_overflow_dont, /* complain_on_overflow */ |
1001 | ppc_elf_unhandled_reloc, /* special_function */ | |
1002 | "R_PPC_GOT_TLSGD16_LO", /* name */ | |
b34976b6 | 1003 | FALSE, /* partial_inplace */ |
252b5132 RH |
1004 | 0, /* src_mask */ |
1005 | 0xffff, /* dst_mask */ | |
b34976b6 | 1006 | FALSE), /* pcrel_offset */ |
252b5132 | 1007 | |
7619e7c7 AM |
1008 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1009 | HOWTO (R_PPC_GOT_TLSGD16_HI, | |
1010 | 16, /* rightshift */ | |
1011 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1012 | 16, /* bitsize */ | |
1013 | FALSE, /* pc_relative */ | |
1014 | 0, /* bitpos */ | |
1015 | complain_overflow_dont, /* complain_on_overflow */ | |
1016 | ppc_elf_unhandled_reloc, /* special_function */ | |
1017 | "R_PPC_GOT_TLSGD16_HI", /* name */ | |
1018 | FALSE, /* partial_inplace */ | |
1019 | 0, /* src_mask */ | |
1020 | 0xffff, /* dst_mask */ | |
1021 | FALSE), /* pcrel_offset */ | |
252b5132 | 1022 | |
7619e7c7 AM |
1023 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1024 | HOWTO (R_PPC_GOT_TLSGD16_HA, | |
1025 | 16, /* rightshift */ | |
1026 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1027 | 16, /* bitsize */ | |
1028 | FALSE, /* pc_relative */ | |
1029 | 0, /* bitpos */ | |
1030 | complain_overflow_dont, /* complain_on_overflow */ | |
1031 | ppc_elf_unhandled_reloc, /* special_function */ | |
1032 | "R_PPC_GOT_TLSGD16_HA", /* name */ | |
1033 | FALSE, /* partial_inplace */ | |
1034 | 0, /* src_mask */ | |
1035 | 0xffff, /* dst_mask */ | |
1036 | FALSE), /* pcrel_offset */ | |
1037 | ||
1038 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1039 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1040 | first entry. */ | |
1041 | HOWTO (R_PPC_GOT_TLSLD16, | |
252b5132 RH |
1042 | 0, /* rightshift */ |
1043 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1044 | 16, /* bitsize */ | |
7619e7c7 | 1045 | FALSE, /* pc_relative */ |
252b5132 RH |
1046 | 0, /* bitpos */ |
1047 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1048 | ppc_elf_unhandled_reloc, /* special_function */ |
1049 | "R_PPC_GOT_TLSLD16", /* name */ | |
b34976b6 | 1050 | FALSE, /* partial_inplace */ |
252b5132 RH |
1051 | 0, /* src_mask */ |
1052 | 0xffff, /* dst_mask */ | |
b34976b6 | 1053 | FALSE), /* pcrel_offset */ |
252b5132 | 1054 | |
7619e7c7 AM |
1055 | /* Like GOT_TLSLD16, but no overflow. */ |
1056 | HOWTO (R_PPC_GOT_TLSLD16_LO, | |
252b5132 | 1057 | 0, /* rightshift */ |
7619e7c7 AM |
1058 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1059 | 16, /* bitsize */ | |
b34976b6 | 1060 | FALSE, /* pc_relative */ |
252b5132 RH |
1061 | 0, /* bitpos */ |
1062 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1063 | ppc_elf_unhandled_reloc, /* special_function */ |
1064 | "R_PPC_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1065 | FALSE, /* partial_inplace */ |
252b5132 | 1066 | 0, /* src_mask */ |
7619e7c7 | 1067 | 0xffff, /* dst_mask */ |
b34976b6 | 1068 | FALSE), /* pcrel_offset */ |
252b5132 | 1069 | |
7619e7c7 AM |
1070 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1071 | HOWTO (R_PPC_GOT_TLSLD16_HI, | |
1072 | 16, /* rightshift */ | |
1073 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1074 | 16, /* bitsize */ | |
b34976b6 | 1075 | FALSE, /* pc_relative */ |
252b5132 RH |
1076 | 0, /* bitpos */ |
1077 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1078 | ppc_elf_unhandled_reloc, /* special_function */ |
1079 | "R_PPC_GOT_TLSLD16_HI", /* name */ | |
b34976b6 | 1080 | FALSE, /* partial_inplace */ |
252b5132 | 1081 | 0, /* src_mask */ |
7619e7c7 | 1082 | 0xffff, /* dst_mask */ |
b34976b6 | 1083 | FALSE), /* pcrel_offset */ |
252b5132 | 1084 | |
7619e7c7 AM |
1085 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1086 | HOWTO (R_PPC_GOT_TLSLD16_HA, | |
1087 | 16, /* rightshift */ | |
1088 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1089 | 16, /* bitsize */ | |
1090 | FALSE, /* pc_relative */ | |
1091 | 0, /* bitpos */ | |
1092 | complain_overflow_dont, /* complain_on_overflow */ | |
1093 | ppc_elf_unhandled_reloc, /* special_function */ | |
1094 | "R_PPC_GOT_TLSLD16_HA", /* name */ | |
1095 | FALSE, /* partial_inplace */ | |
1096 | 0, /* src_mask */ | |
1097 | 0xffff, /* dst_mask */ | |
1098 | FALSE), /* pcrel_offset */ | |
1099 | ||
1100 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes | |
1101 | the offset to the entry. */ | |
1102 | HOWTO (R_PPC_GOT_DTPREL16, | |
252b5132 RH |
1103 | 0, /* rightshift */ |
1104 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1105 | 16, /* bitsize */ | |
b34976b6 | 1106 | FALSE, /* pc_relative */ |
252b5132 RH |
1107 | 0, /* bitpos */ |
1108 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1109 | ppc_elf_unhandled_reloc, /* special_function */ |
1110 | "R_PPC_GOT_DTPREL16", /* name */ | |
b34976b6 | 1111 | FALSE, /* partial_inplace */ |
252b5132 RH |
1112 | 0, /* src_mask */ |
1113 | 0xffff, /* dst_mask */ | |
b34976b6 | 1114 | FALSE), /* pcrel_offset */ |
252b5132 | 1115 | |
7619e7c7 AM |
1116 | /* Like GOT_DTPREL16, but no overflow. */ |
1117 | HOWTO (R_PPC_GOT_DTPREL16_LO, | |
1118 | 0, /* rightshift */ | |
1119 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1120 | 16, /* bitsize */ | |
1121 | FALSE, /* pc_relative */ | |
1122 | 0, /* bitpos */ | |
1123 | complain_overflow_dont, /* complain_on_overflow */ | |
1124 | ppc_elf_unhandled_reloc, /* special_function */ | |
1125 | "R_PPC_GOT_DTPREL16_LO", /* name */ | |
1126 | FALSE, /* partial_inplace */ | |
1127 | 0, /* src_mask */ | |
1128 | 0xffff, /* dst_mask */ | |
1129 | FALSE), /* pcrel_offset */ | |
252b5132 | 1130 | |
7619e7c7 AM |
1131 | /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */ |
1132 | HOWTO (R_PPC_GOT_DTPREL16_HI, | |
1133 | 16, /* rightshift */ | |
1134 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1135 | 16, /* bitsize */ | |
1136 | FALSE, /* pc_relative */ | |
1137 | 0, /* bitpos */ | |
1138 | complain_overflow_dont, /* complain_on_overflow */ | |
1139 | ppc_elf_unhandled_reloc, /* special_function */ | |
1140 | "R_PPC_GOT_DTPREL16_HI", /* name */ | |
1141 | FALSE, /* partial_inplace */ | |
1142 | 0, /* src_mask */ | |
1143 | 0xffff, /* dst_mask */ | |
1144 | FALSE), /* pcrel_offset */ | |
252b5132 | 1145 | |
7619e7c7 AM |
1146 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1147 | HOWTO (R_PPC_GOT_DTPREL16_HA, | |
1148 | 16, /* rightshift */ | |
1149 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1150 | 16, /* bitsize */ | |
1151 | FALSE, /* pc_relative */ | |
1152 | 0, /* bitpos */ | |
1153 | complain_overflow_dont, /* complain_on_overflow */ | |
1154 | ppc_elf_unhandled_reloc, /* special_function */ | |
1155 | "R_PPC_GOT_DTPREL16_HA", /* name */ | |
1156 | FALSE, /* partial_inplace */ | |
1157 | 0, /* src_mask */ | |
1158 | 0xffff, /* dst_mask */ | |
1159 | FALSE), /* pcrel_offset */ | |
c3668558 | 1160 | |
7619e7c7 AM |
1161 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the |
1162 | offset to the entry. */ | |
1163 | HOWTO (R_PPC_GOT_TPREL16, | |
1164 | 0, /* rightshift */ | |
1165 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1166 | 16, /* bitsize */ | |
1167 | FALSE, /* pc_relative */ | |
1168 | 0, /* bitpos */ | |
1169 | complain_overflow_signed, /* complain_on_overflow */ | |
1170 | ppc_elf_unhandled_reloc, /* special_function */ | |
1171 | "R_PPC_GOT_TPREL16", /* name */ | |
1172 | FALSE, /* partial_inplace */ | |
1173 | 0, /* src_mask */ | |
1174 | 0xffff, /* dst_mask */ | |
1175 | FALSE), /* pcrel_offset */ | |
1176 | ||
1177 | /* Like GOT_TPREL16, but no overflow. */ | |
1178 | HOWTO (R_PPC_GOT_TPREL16_LO, | |
1179 | 0, /* rightshift */ | |
1180 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1181 | 16, /* bitsize */ | |
1182 | FALSE, /* pc_relative */ | |
1183 | 0, /* bitpos */ | |
1184 | complain_overflow_dont, /* complain_on_overflow */ | |
1185 | ppc_elf_unhandled_reloc, /* special_function */ | |
1186 | "R_PPC_GOT_TPREL16_LO", /* name */ | |
1187 | FALSE, /* partial_inplace */ | |
1188 | 0, /* src_mask */ | |
1189 | 0xffff, /* dst_mask */ | |
1190 | FALSE), /* pcrel_offset */ | |
1191 | ||
1192 | /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */ | |
1193 | HOWTO (R_PPC_GOT_TPREL16_HI, | |
1194 | 16, /* rightshift */ | |
1195 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1196 | 16, /* bitsize */ | |
1197 | FALSE, /* pc_relative */ | |
1198 | 0, /* bitpos */ | |
1199 | complain_overflow_dont, /* complain_on_overflow */ | |
1200 | ppc_elf_unhandled_reloc, /* special_function */ | |
1201 | "R_PPC_GOT_TPREL16_HI", /* name */ | |
1202 | FALSE, /* partial_inplace */ | |
1203 | 0, /* src_mask */ | |
1204 | 0xffff, /* dst_mask */ | |
1205 | FALSE), /* pcrel_offset */ | |
1206 | ||
1207 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ | |
1208 | HOWTO (R_PPC_GOT_TPREL16_HA, | |
1209 | 16, /* rightshift */ | |
1210 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1211 | 16, /* bitsize */ | |
1212 | FALSE, /* pc_relative */ | |
1213 | 0, /* bitpos */ | |
1214 | complain_overflow_dont, /* complain_on_overflow */ | |
1215 | ppc_elf_unhandled_reloc, /* special_function */ | |
1216 | "R_PPC_GOT_TPREL16_HA", /* name */ | |
1217 | FALSE, /* partial_inplace */ | |
1218 | 0, /* src_mask */ | |
1219 | 0xffff, /* dst_mask */ | |
1220 | FALSE), /* pcrel_offset */ | |
1221 | ||
1222 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
1223 | in the SVR4 ELF ABI. */ | |
1224 | ||
1225 | /* 32 bit value resulting from the addend minus the symbol. */ | |
1226 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
1227 | 0, /* rightshift */ | |
1228 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1229 | 32, /* bitsize */ | |
1230 | FALSE, /* pc_relative */ | |
1231 | 0, /* bitpos */ | |
1232 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1233 | bfd_elf_generic_reloc, /* special_function */ | |
1234 | "R_PPC_EMB_NADDR32", /* name */ | |
1235 | FALSE, /* partial_inplace */ | |
1236 | 0, /* src_mask */ | |
1237 | 0xffffffff, /* dst_mask */ | |
1238 | FALSE), /* pcrel_offset */ | |
1239 | ||
1240 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1241 | HOWTO (R_PPC_EMB_NADDR16, /* type */ | |
1242 | 0, /* rightshift */ | |
1243 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1244 | 16, /* bitsize */ | |
1245 | FALSE, /* pc_relative */ | |
1246 | 0, /* bitpos */ | |
1247 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1248 | bfd_elf_generic_reloc, /* special_function */ | |
1249 | "R_PPC_EMB_NADDR16", /* name */ | |
1250 | FALSE, /* partial_inplace */ | |
1251 | 0, /* src_mask */ | |
1252 | 0xffff, /* dst_mask */ | |
1253 | FALSE), /* pcrel_offset */ | |
1254 | ||
1255 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1256 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
1257 | 0, /* rightshift */ | |
1258 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1259 | 16, /* bitsize */ | |
1260 | FALSE, /* pc_relative */ | |
1261 | 0, /* bitpos */ | |
1262 | complain_overflow_dont,/* complain_on_overflow */ | |
1263 | bfd_elf_generic_reloc, /* special_function */ | |
1264 | "R_PPC_EMB_ADDR16_LO", /* name */ | |
1265 | FALSE, /* partial_inplace */ | |
1266 | 0, /* src_mask */ | |
1267 | 0xffff, /* dst_mask */ | |
1268 | FALSE), /* pcrel_offset */ | |
1269 | ||
1270 | /* The high order 16 bits of the addend minus the symbol. */ | |
1271 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
1272 | 16, /* rightshift */ | |
1273 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1274 | 16, /* bitsize */ | |
1275 | FALSE, /* pc_relative */ | |
1276 | 0, /* bitpos */ | |
1277 | complain_overflow_dont, /* complain_on_overflow */ | |
1278 | bfd_elf_generic_reloc, /* special_function */ | |
1279 | "R_PPC_EMB_NADDR16_HI", /* name */ | |
1280 | FALSE, /* partial_inplace */ | |
1281 | 0, /* src_mask */ | |
1282 | 0xffff, /* dst_mask */ | |
1283 | FALSE), /* pcrel_offset */ | |
1284 | ||
1285 | /* The high order 16 bits of the result of the addend minus the address, | |
1286 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
1287 | is negative. */ | |
1288 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ | |
1289 | 16, /* rightshift */ | |
1290 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1291 | 16, /* bitsize */ | |
1292 | FALSE, /* pc_relative */ | |
1293 | 0, /* bitpos */ | |
1294 | complain_overflow_dont, /* complain_on_overflow */ | |
25dbc73a AM |
1295 | ppc_elf_addr16_ha_reloc, /* special_function */ |
1296 | "R_PPC_EMB_NADDR16_HA", /* name */ | |
1297 | FALSE, /* partial_inplace */ | |
1298 | 0, /* src_mask */ | |
1299 | 0xffff, /* dst_mask */ | |
1300 | FALSE), /* pcrel_offset */ | |
1301 | ||
1302 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1303 | address in the .sdata section, and returning the offset from | |
1304 | _SDA_BASE_ for that relocation. */ | |
1305 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
1306 | 0, /* rightshift */ | |
1307 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1308 | 16, /* bitsize */ | |
1309 | FALSE, /* pc_relative */ | |
1310 | 0, /* bitpos */ | |
bd6c6e2b | 1311 | complain_overflow_signed, /* complain_on_overflow */ |
25dbc73a AM |
1312 | bfd_elf_generic_reloc, /* special_function */ |
1313 | "R_PPC_EMB_SDAI16", /* name */ | |
1314 | FALSE, /* partial_inplace */ | |
1315 | 0, /* src_mask */ | |
1316 | 0xffff, /* dst_mask */ | |
1317 | FALSE), /* pcrel_offset */ | |
1318 | ||
1319 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1320 | address in the .sdata2 section, and returning the offset from | |
1321 | _SDA2_BASE_ for that relocation. */ | |
1322 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
1323 | 0, /* rightshift */ | |
1324 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1325 | 16, /* bitsize */ | |
1326 | FALSE, /* pc_relative */ | |
1327 | 0, /* bitpos */ | |
bd6c6e2b | 1328 | complain_overflow_signed, /* complain_on_overflow */ |
25dbc73a AM |
1329 | bfd_elf_generic_reloc, /* special_function */ |
1330 | "R_PPC_EMB_SDA2I16", /* name */ | |
1331 | FALSE, /* partial_inplace */ | |
1332 | 0, /* src_mask */ | |
1333 | 0xffff, /* dst_mask */ | |
1334 | FALSE), /* pcrel_offset */ | |
1335 | ||
1336 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
1337 | small data items. */ | |
1338 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
1339 | 0, /* rightshift */ | |
1340 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1341 | 16, /* bitsize */ | |
1342 | FALSE, /* pc_relative */ | |
1343 | 0, /* bitpos */ | |
1344 | complain_overflow_signed, /* complain_on_overflow */ | |
1345 | bfd_elf_generic_reloc, /* special_function */ | |
1346 | "R_PPC_EMB_SDA2REL", /* name */ | |
1347 | FALSE, /* partial_inplace */ | |
1348 | 0, /* src_mask */ | |
1349 | 0xffff, /* dst_mask */ | |
1350 | FALSE), /* pcrel_offset */ | |
1351 | ||
1352 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
1353 | signed offset from the appropriate base, and filling in the register | |
1354 | field with the appropriate register (0, 2, or 13). */ | |
1355 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
1356 | 0, /* rightshift */ | |
1357 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1358 | 16, /* bitsize */ | |
1359 | FALSE, /* pc_relative */ | |
1360 | 0, /* bitpos */ | |
1361 | complain_overflow_signed, /* complain_on_overflow */ | |
1362 | bfd_elf_generic_reloc, /* special_function */ | |
1363 | "R_PPC_EMB_SDA21", /* name */ | |
1364 | FALSE, /* partial_inplace */ | |
1365 | 0, /* src_mask */ | |
1366 | 0xffff, /* dst_mask */ | |
1367 | FALSE), /* pcrel_offset */ | |
1368 | ||
1369 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
1370 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
1371 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
1372 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
1373 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
1374 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
1375 | ||
1376 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
1377 | in the 16 bit signed offset from the appropriate base, and filling in the | |
1378 | register field with the appropriate register (0, 2, or 13). */ | |
1379 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
1380 | 0, /* rightshift */ | |
1381 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1382 | 16, /* bitsize */ | |
ddfd6795 | 1383 | FALSE, /* pc_relative */ |
25dbc73a AM |
1384 | 0, /* bitpos */ |
1385 | complain_overflow_signed, /* complain_on_overflow */ | |
1386 | bfd_elf_generic_reloc, /* special_function */ | |
1387 | "R_PPC_EMB_RELSDA", /* name */ | |
1388 | FALSE, /* partial_inplace */ | |
1389 | 0, /* src_mask */ | |
1390 | 0xffff, /* dst_mask */ | |
1391 | FALSE), /* pcrel_offset */ | |
1392 | ||
e054468f AM |
1393 | HOWTO (R_PPC_IRELATIVE, /* type */ |
1394 | 0, /* rightshift */ | |
1395 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1396 | 32, /* bitsize */ | |
1397 | FALSE, /* pc_relative */ | |
1398 | 0, /* bitpos */ | |
1399 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1400 | bfd_elf_generic_reloc, /* special_function */ | |
1401 | "R_PPC_IRELATIVE", /* name */ | |
1402 | FALSE, /* partial_inplace */ | |
1403 | 0, /* src_mask */ | |
1404 | 0xffffffff, /* dst_mask */ | |
1405 | FALSE), /* pcrel_offset */ | |
1406 | ||
d7128ce4 AM |
1407 | /* A 16 bit relative relocation. */ |
1408 | HOWTO (R_PPC_REL16, /* type */ | |
1409 | 0, /* rightshift */ | |
1410 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1411 | 16, /* bitsize */ | |
1412 | TRUE, /* pc_relative */ | |
1413 | 0, /* bitpos */ | |
1414 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1415 | bfd_elf_generic_reloc, /* special_function */ | |
1416 | "R_PPC_REL16", /* name */ | |
1417 | FALSE, /* partial_inplace */ | |
1418 | 0, /* src_mask */ | |
1419 | 0xffff, /* dst_mask */ | |
1420 | TRUE), /* pcrel_offset */ | |
1421 | ||
1422 | /* A 16 bit relative relocation without overflow. */ | |
1423 | HOWTO (R_PPC_REL16_LO, /* type */ | |
1424 | 0, /* rightshift */ | |
1425 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1426 | 16, /* bitsize */ | |
1427 | TRUE, /* pc_relative */ | |
1428 | 0, /* bitpos */ | |
1429 | complain_overflow_dont,/* complain_on_overflow */ | |
1430 | bfd_elf_generic_reloc, /* special_function */ | |
1431 | "R_PPC_REL16_LO", /* name */ | |
1432 | FALSE, /* partial_inplace */ | |
1433 | 0, /* src_mask */ | |
1434 | 0xffff, /* dst_mask */ | |
1435 | TRUE), /* pcrel_offset */ | |
1436 | ||
1437 | /* The high order 16 bits of a relative address. */ | |
1438 | HOWTO (R_PPC_REL16_HI, /* type */ | |
1439 | 16, /* rightshift */ | |
1440 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1441 | 16, /* bitsize */ | |
1442 | TRUE, /* pc_relative */ | |
1443 | 0, /* bitpos */ | |
1444 | complain_overflow_dont, /* complain_on_overflow */ | |
1445 | bfd_elf_generic_reloc, /* special_function */ | |
1446 | "R_PPC_REL16_HI", /* name */ | |
1447 | FALSE, /* partial_inplace */ | |
1448 | 0, /* src_mask */ | |
1449 | 0xffff, /* dst_mask */ | |
1450 | TRUE), /* pcrel_offset */ | |
1451 | ||
1452 | /* The high order 16 bits of a relative address, plus 1 if the contents of | |
1453 | the low 16 bits, treated as a signed number, is negative. */ | |
1454 | HOWTO (R_PPC_REL16_HA, /* type */ | |
1455 | 16, /* rightshift */ | |
1456 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1457 | 16, /* bitsize */ | |
1458 | TRUE, /* pc_relative */ | |
1459 | 0, /* bitpos */ | |
1460 | complain_overflow_dont, /* complain_on_overflow */ | |
1461 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1462 | "R_PPC_REL16_HA", /* name */ | |
1463 | FALSE, /* partial_inplace */ | |
1464 | 0, /* src_mask */ | |
1465 | 0xffff, /* dst_mask */ | |
1466 | TRUE), /* pcrel_offset */ | |
1467 | ||
25dbc73a AM |
1468 | /* GNU extension to record C++ vtable hierarchy. */ |
1469 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ | |
1470 | 0, /* rightshift */ | |
1471 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1472 | 0, /* bitsize */ | |
1473 | FALSE, /* pc_relative */ | |
1474 | 0, /* bitpos */ | |
1475 | complain_overflow_dont, /* complain_on_overflow */ | |
1476 | NULL, /* special_function */ | |
1477 | "R_PPC_GNU_VTINHERIT", /* name */ | |
1478 | FALSE, /* partial_inplace */ | |
1479 | 0, /* src_mask */ | |
1480 | 0, /* dst_mask */ | |
1481 | FALSE), /* pcrel_offset */ | |
1482 | ||
1483 | /* GNU extension to record C++ vtable member usage. */ | |
1484 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ | |
1485 | 0, /* rightshift */ | |
1486 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1487 | 0, /* bitsize */ | |
1488 | FALSE, /* pc_relative */ | |
1489 | 0, /* bitpos */ | |
1490 | complain_overflow_dont, /* complain_on_overflow */ | |
1491 | NULL, /* special_function */ | |
1492 | "R_PPC_GNU_VTENTRY", /* name */ | |
7619e7c7 AM |
1493 | FALSE, /* partial_inplace */ |
1494 | 0, /* src_mask */ | |
25dbc73a | 1495 | 0, /* dst_mask */ |
7619e7c7 AM |
1496 | FALSE), /* pcrel_offset */ |
1497 | ||
25dbc73a AM |
1498 | /* Phony reloc to handle AIX style TOC entries. */ |
1499 | HOWTO (R_PPC_TOC16, /* type */ | |
7619e7c7 AM |
1500 | 0, /* rightshift */ |
1501 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1502 | 16, /* bitsize */ | |
1503 | FALSE, /* pc_relative */ | |
1504 | 0, /* bitpos */ | |
25dbc73a | 1505 | complain_overflow_signed, /* complain_on_overflow */ |
7619e7c7 | 1506 | bfd_elf_generic_reloc, /* special_function */ |
25dbc73a | 1507 | "R_PPC_TOC16", /* name */ |
7619e7c7 AM |
1508 | FALSE, /* partial_inplace */ |
1509 | 0, /* src_mask */ | |
1510 | 0xffff, /* dst_mask */ | |
1511 | FALSE), /* pcrel_offset */ | |
25dbc73a AM |
1512 | }; |
1513 | \f | |
1514 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
1515 | ||
1516 | static void | |
1517 | ppc_elf_howto_init (void) | |
1518 | { | |
1519 | unsigned int i, type; | |
1520 | ||
1521 | for (i = 0; | |
1522 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1523 | i++) | |
1524 | { | |
1525 | type = ppc_elf_howto_raw[i].type; | |
1526 | if (type >= (sizeof (ppc_elf_howto_table) | |
1527 | / sizeof (ppc_elf_howto_table[0]))) | |
1528 | abort (); | |
1529 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; | |
1530 | } | |
1531 | } | |
1532 | ||
1533 | static reloc_howto_type * | |
1534 | ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1535 | bfd_reloc_code_real_type code) | |
1536 | { | |
1537 | enum elf_ppc_reloc_type r; | |
1538 | ||
1539 | /* Initialize howto table if not already done. */ | |
1540 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1541 | ppc_elf_howto_init (); | |
1542 | ||
1543 | switch (code) | |
1544 | { | |
1545 | default: | |
1546 | return NULL; | |
1547 | ||
1548 | case BFD_RELOC_NONE: r = R_PPC_NONE; break; | |
1549 | case BFD_RELOC_32: r = R_PPC_ADDR32; break; | |
1550 | case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break; | |
1551 | case BFD_RELOC_16: r = R_PPC_ADDR16; break; | |
1552 | case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break; | |
1553 | case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break; | |
1554 | case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break; | |
1555 | case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break; | |
1556 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break; | |
1557 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break; | |
1558 | case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break; | |
1559 | case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break; | |
1560 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break; | |
1561 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break; | |
1562 | case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break; | |
1563 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break; | |
1564 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break; | |
1565 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break; | |
1566 | case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break; | |
1567 | case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break; | |
1568 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break; | |
1569 | case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break; | |
1570 | case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break; | |
1571 | case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break; | |
1572 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break; | |
1573 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break; | |
1574 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break; | |
1575 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break; | |
1576 | case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break; | |
1577 | case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break; | |
1578 | case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break; | |
1579 | case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break; | |
1580 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break; | |
1581 | case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break; | |
1582 | case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break; | |
1583 | case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break; | |
727fc41e AM |
1584 | case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break; |
1585 | case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break; | |
25dbc73a AM |
1586 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break; |
1587 | case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break; | |
1588 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break; | |
1589 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break; | |
1590 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break; | |
1591 | case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break; | |
1592 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break; | |
1593 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break; | |
1594 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break; | |
1595 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break; | |
1596 | case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break; | |
1597 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break; | |
1598 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break; | |
1599 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break; | |
1600 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break; | |
1601 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break; | |
1602 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break; | |
1603 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break; | |
1604 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break; | |
1605 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break; | |
1606 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break; | |
1607 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break; | |
1608 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break; | |
1609 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break; | |
1610 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break; | |
1611 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break; | |
1612 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break; | |
1613 | case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break; | |
1614 | case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break; | |
1615 | case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break; | |
1616 | case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break; | |
1617 | case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break; | |
1618 | case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break; | |
1619 | case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break; | |
1620 | case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break; | |
1621 | case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break; | |
1622 | case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break; | |
1623 | case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break; | |
1624 | case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break; | |
1625 | case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break; | |
1626 | case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break; | |
1627 | case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break; | |
1628 | case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break; | |
d7128ce4 AM |
1629 | case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break; |
1630 | case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break; | |
1631 | case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break; | |
1632 | case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break; | |
25dbc73a AM |
1633 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break; |
1634 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break; | |
1635 | } | |
1636 | ||
1637 | return ppc_elf_howto_table[r]; | |
1638 | }; | |
1639 | ||
157090f7 AM |
1640 | static reloc_howto_type * |
1641 | ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1642 | const char *r_name) | |
1643 | { | |
1644 | unsigned int i; | |
1645 | ||
1646 | for (i = 0; | |
1647 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1648 | i++) | |
1649 | if (ppc_elf_howto_raw[i].name != NULL | |
1650 | && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0) | |
1651 | return &ppc_elf_howto_raw[i]; | |
1652 | ||
1653 | return NULL; | |
1654 | } | |
1655 | ||
25dbc73a AM |
1656 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
1657 | ||
1658 | static void | |
1659 | ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, | |
1660 | arelent *cache_ptr, | |
1661 | Elf_Internal_Rela *dst) | |
1662 | { | |
1663 | /* Initialize howto table if not already done. */ | |
1664 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1665 | ppc_elf_howto_init (); | |
1666 | ||
1667 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); | |
1668 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; | |
375de94a AM |
1669 | |
1670 | /* Just because the above assert didn't trigger doesn't mean that | |
1671 | ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */ | |
1672 | if (!cache_ptr->howto) | |
1673 | { | |
1674 | (*_bfd_error_handler) (_("%B: invalid relocation type %d"), | |
1675 | abfd, ELF32_R_TYPE (dst->r_info)); | |
1676 | bfd_set_error (bfd_error_bad_value); | |
1677 | ||
1678 | cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE]; | |
1679 | } | |
25dbc73a AM |
1680 | } |
1681 | ||
d7128ce4 | 1682 | /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */ |
25dbc73a AM |
1683 | |
1684 | static bfd_reloc_status_type | |
1685 | ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED, | |
1686 | arelent *reloc_entry, | |
1687 | asymbol *symbol, | |
1688 | void *data ATTRIBUTE_UNUSED, | |
1689 | asection *input_section, | |
1690 | bfd *output_bfd, | |
1691 | char **error_message ATTRIBUTE_UNUSED) | |
1692 | { | |
1693 | bfd_vma relocation; | |
1694 | ||
1695 | if (output_bfd != NULL) | |
1696 | { | |
1697 | reloc_entry->address += input_section->output_offset; | |
1698 | return bfd_reloc_ok; | |
1699 | } | |
1700 | ||
1701 | if (reloc_entry->address > bfd_get_section_limit (abfd, input_section)) | |
1702 | return bfd_reloc_outofrange; | |
1703 | ||
1704 | if (bfd_is_com_section (symbol->section)) | |
1705 | relocation = 0; | |
1706 | else | |
1707 | relocation = symbol->value; | |
1708 | ||
1709 | relocation += symbol->section->output_section->vma; | |
1710 | relocation += symbol->section->output_offset; | |
1711 | relocation += reloc_entry->addend; | |
d7128ce4 AM |
1712 | if (reloc_entry->howto->pc_relative) |
1713 | relocation -= reloc_entry->address; | |
25dbc73a AM |
1714 | |
1715 | reloc_entry->addend += (relocation & 0x8000) << 1; | |
1716 | ||
1717 | return bfd_reloc_continue; | |
1718 | } | |
1719 | ||
1720 | static bfd_reloc_status_type | |
1721 | ppc_elf_unhandled_reloc (bfd *abfd, | |
1722 | arelent *reloc_entry, | |
1723 | asymbol *symbol, | |
1724 | void *data, | |
1725 | asection *input_section, | |
1726 | bfd *output_bfd, | |
1727 | char **error_message) | |
1728 | { | |
1729 | /* If this is a relocatable link (output_bfd test tells us), just | |
1730 | call the generic function. Any adjustment will be done at final | |
1731 | link time. */ | |
1732 | if (output_bfd != NULL) | |
1733 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
1734 | input_section, output_bfd, error_message); | |
1735 | ||
1736 | if (error_message != NULL) | |
1737 | { | |
1738 | static char buf[60]; | |
1739 | sprintf (buf, _("generic linker can't handle %s"), | |
1740 | reloc_entry->howto->name); | |
1741 | *error_message = buf; | |
1742 | } | |
1743 | return bfd_reloc_dangerous; | |
1744 | } | |
1745 | \f | |
1746 | /* Sections created by the linker. */ | |
1747 | ||
1748 | typedef struct elf_linker_section | |
1749 | { | |
c9a2f333 | 1750 | /* Pointer to the bfd section. */ |
25dbc73a | 1751 | asection *section; |
c9a2f333 AM |
1752 | /* Section name. */ |
1753 | const char *name; | |
1754 | /* Associated bss section name. */ | |
1755 | const char *bss_name; | |
1756 | /* Associated symbol name. */ | |
1757 | const char *sym_name; | |
046183de AM |
1758 | /* Associated symbol. */ |
1759 | struct elf_link_hash_entry *sym; | |
25dbc73a AM |
1760 | } elf_linker_section_t; |
1761 | ||
1762 | /* Linked list of allocated pointer entries. This hangs off of the | |
1763 | symbol lists, and provides allows us to return different pointers, | |
1764 | based on different addend's. */ | |
1765 | ||
1766 | typedef struct elf_linker_section_pointers | |
1767 | { | |
1768 | /* next allocated pointer for this symbol */ | |
1769 | struct elf_linker_section_pointers *next; | |
1770 | /* offset of pointer from beginning of section */ | |
1771 | bfd_vma offset; | |
1772 | /* addend used */ | |
1773 | bfd_vma addend; | |
1774 | /* which linker section this is */ | |
1775 | elf_linker_section_t *lsect; | |
25dbc73a AM |
1776 | } elf_linker_section_pointers_t; |
1777 | ||
1778 | struct ppc_elf_obj_tdata | |
1779 | { | |
1780 | struct elf_obj_tdata elf; | |
1781 | ||
1782 | /* A mapping from local symbols to offsets into the various linker | |
1783 | sections added. This is index by the symbol index. */ | |
1784 | elf_linker_section_pointers_t **linker_section_pointers; | |
016687f8 AM |
1785 | |
1786 | /* Flags used to auto-detect plt type. */ | |
1787 | unsigned int makes_plt_call : 1; | |
1788 | unsigned int has_rel16 : 1; | |
25dbc73a AM |
1789 | }; |
1790 | ||
1791 | #define ppc_elf_tdata(bfd) \ | |
1792 | ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any) | |
7619e7c7 | 1793 | |
25dbc73a AM |
1794 | #define elf_local_ptr_offsets(bfd) \ |
1795 | (ppc_elf_tdata (bfd)->linker_section_pointers) | |
7619e7c7 | 1796 | |
0c8d6e5c AM |
1797 | #define is_ppc_elf(bfd) \ |
1798 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
4dfe6ac6 | 1799 | && elf_object_id (bfd) == PPC32_ELF_DATA) |
0c8d6e5c | 1800 | |
25dbc73a | 1801 | /* Override the generic function because we store some extras. */ |
7619e7c7 | 1802 | |
25dbc73a AM |
1803 | static bfd_boolean |
1804 | ppc_elf_mkobject (bfd *abfd) | |
1805 | { | |
0ffa91dd | 1806 | return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata), |
4dfe6ac6 | 1807 | PPC32_ELF_DATA); |
25dbc73a | 1808 | } |
7619e7c7 | 1809 | |
25dbc73a AM |
1810 | /* Fix bad default arch selected for a 32 bit input bfd when the |
1811 | default is 64 bit. */ | |
7619e7c7 | 1812 | |
25dbc73a AM |
1813 | static bfd_boolean |
1814 | ppc_elf_object_p (bfd *abfd) | |
1815 | { | |
1816 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64) | |
1817 | { | |
1818 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
7619e7c7 | 1819 | |
25dbc73a AM |
1820 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) |
1821 | { | |
1822 | /* Relies on arch after 64 bit default being 32 bit default. */ | |
1823 | abfd->arch_info = abfd->arch_info->next; | |
1824 | BFD_ASSERT (abfd->arch_info->bits_per_word == 32); | |
1825 | } | |
1826 | } | |
1827 | return TRUE; | |
1828 | } | |
7619e7c7 | 1829 | |
25dbc73a | 1830 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
7619e7c7 | 1831 | |
25dbc73a AM |
1832 | static bfd_boolean |
1833 | ppc_elf_set_private_flags (bfd *abfd, flagword flags) | |
1834 | { | |
1835 | BFD_ASSERT (!elf_flags_init (abfd) | |
1836 | || elf_elfheader (abfd)->e_flags == flags); | |
7619e7c7 | 1837 | |
25dbc73a AM |
1838 | elf_elfheader (abfd)->e_flags = flags; |
1839 | elf_flags_init (abfd) = TRUE; | |
1840 | return TRUE; | |
1841 | } | |
1842 | ||
25dbc73a | 1843 | /* Support for core dump NOTE sections. */ |
deaaf2f3 | 1844 | |
b34976b6 | 1845 | static bfd_boolean |
25dbc73a | 1846 | ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
252b5132 | 1847 | { |
25dbc73a AM |
1848 | int offset; |
1849 | unsigned int size; | |
252b5132 | 1850 | |
25dbc73a AM |
1851 | switch (note->descsz) |
1852 | { | |
1853 | default: | |
1854 | return FALSE; | |
252b5132 | 1855 | |
25dbc73a AM |
1856 | case 268: /* Linux/PPC. */ |
1857 | /* pr_cursig */ | |
1858 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
deaaf2f3 | 1859 | |
25dbc73a AM |
1860 | /* pr_pid */ |
1861 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
9abc968f | 1862 | |
25dbc73a AM |
1863 | /* pr_reg */ |
1864 | offset = 72; | |
1865 | size = 192; | |
deaaf2f3 | 1866 | |
25dbc73a AM |
1867 | break; |
1868 | } | |
deaaf2f3 | 1869 | |
25dbc73a AM |
1870 | /* Make a ".reg/999" section. */ |
1871 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1872 | size, note->descpos + offset); | |
1873 | } | |
252b5132 | 1874 | |
25dbc73a AM |
1875 | static bfd_boolean |
1876 | ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
1877 | { | |
1878 | switch (note->descsz) | |
deaaf2f3 | 1879 | { |
25dbc73a AM |
1880 | default: |
1881 | return FALSE; | |
deaaf2f3 | 1882 | |
25dbc73a AM |
1883 | case 128: /* Linux/PPC elf_prpsinfo. */ |
1884 | elf_tdata (abfd)->core_program | |
1885 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); | |
1886 | elf_tdata (abfd)->core_command | |
1887 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); | |
1888 | } | |
9abc968f | 1889 | |
25dbc73a AM |
1890 | /* Note that for some reason, a spurious space is tacked |
1891 | onto the end of the args in some (at least one anyway) | |
1892 | implementations, so strip it off if it exists. */ | |
70bccea4 | 1893 | |
25dbc73a AM |
1894 | { |
1895 | char *command = elf_tdata (abfd)->core_command; | |
1896 | int n = strlen (command); | |
70bccea4 | 1897 | |
25dbc73a AM |
1898 | if (0 < n && command[n - 1] == ' ') |
1899 | command[n - 1] = '\0'; | |
1900 | } | |
deaaf2f3 | 1901 | |
25dbc73a AM |
1902 | return TRUE; |
1903 | } | |
deaaf2f3 | 1904 | |
183e98be AM |
1905 | static char * |
1906 | ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...) | |
1907 | { | |
1908 | switch (note_type) | |
1909 | { | |
1910 | default: | |
1911 | return NULL; | |
1912 | ||
1913 | case NT_PRPSINFO: | |
1914 | { | |
1915 | char data[128]; | |
1916 | va_list ap; | |
1917 | ||
1918 | va_start (ap, note_type); | |
1919 | memset (data, 0, 32); | |
1920 | strncpy (data + 32, va_arg (ap, const char *), 16); | |
1921 | strncpy (data + 48, va_arg (ap, const char *), 80); | |
1922 | va_end (ap); | |
1923 | return elfcore_write_note (abfd, buf, bufsiz, | |
1924 | "CORE", note_type, data, sizeof (data)); | |
1925 | } | |
1926 | ||
1927 | case NT_PRSTATUS: | |
1928 | { | |
1929 | char data[268]; | |
1930 | va_list ap; | |
1931 | long pid; | |
1932 | int cursig; | |
1933 | const void *greg; | |
1934 | ||
1935 | va_start (ap, note_type); | |
1936 | memset (data, 0, 72); | |
1937 | pid = va_arg (ap, long); | |
1938 | bfd_put_32 (abfd, pid, data + 24); | |
1939 | cursig = va_arg (ap, int); | |
1940 | bfd_put_16 (abfd, cursig, data + 12); | |
1941 | greg = va_arg (ap, const void *); | |
1942 | memcpy (data + 72, greg, 192); | |
1943 | memset (data + 264, 0, 4); | |
1944 | va_end (ap); | |
1945 | return elfcore_write_note (abfd, buf, bufsiz, | |
1946 | "CORE", note_type, data, sizeof (data)); | |
1947 | } | |
1948 | } | |
1949 | } | |
1950 | ||
25dbc73a AM |
1951 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
1952 | or (bfd_vma) -1 if it should not be included. */ | |
deaaf2f3 | 1953 | |
25dbc73a AM |
1954 | static bfd_vma |
1955 | ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, | |
1956 | const asection *plt ATTRIBUTE_UNUSED, | |
1957 | const arelent *rel) | |
1958 | { | |
1959 | return rel->address; | |
1960 | } | |
deaaf2f3 | 1961 | |
25dbc73a | 1962 | /* Handle a PowerPC specific section when reading an object file. This |
6dc132d9 L |
1963 | is called when bfd_section_from_shdr finds a section with an unknown |
1964 | type. */ | |
deaaf2f3 | 1965 | |
25dbc73a | 1966 | static bfd_boolean |
6dc132d9 L |
1967 | ppc_elf_section_from_shdr (bfd *abfd, |
1968 | Elf_Internal_Shdr *hdr, | |
1969 | const char *name, | |
1970 | int shindex) | |
25dbc73a AM |
1971 | { |
1972 | asection *newsect; | |
1973 | flagword flags; | |
d1c6de6f | 1974 | |
6dc132d9 | 1975 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
25dbc73a | 1976 | return FALSE; |
deaaf2f3 | 1977 | |
25dbc73a AM |
1978 | newsect = hdr->bfd_section; |
1979 | flags = bfd_get_section_flags (abfd, newsect); | |
1980 | if (hdr->sh_flags & SHF_EXCLUDE) | |
1981 | flags |= SEC_EXCLUDE; | |
9abc968f | 1982 | |
25dbc73a AM |
1983 | if (hdr->sh_type == SHT_ORDERED) |
1984 | flags |= SEC_SORT_ENTRIES; | |
d1c6de6f | 1985 | |
25dbc73a AM |
1986 | bfd_set_section_flags (abfd, newsect, flags); |
1987 | return TRUE; | |
1988 | } | |
1989 | ||
1990 | /* Set up any other section flags and such that may be necessary. */ | |
1991 | ||
1992 | static bfd_boolean | |
1993 | ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, | |
1994 | Elf_Internal_Shdr *shdr, | |
1995 | asection *asect) | |
1996 | { | |
d30e8e7c | 1997 | if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE) |
25dbc73a AM |
1998 | shdr->sh_flags |= SHF_EXCLUDE; |
1999 | ||
2000 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) | |
2001 | shdr->sh_type = SHT_ORDERED; | |
2002 | ||
2003 | return TRUE; | |
2004 | } | |
2005 | ||
2006 | /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we | |
2007 | need to bump up the number of section headers. */ | |
2008 | ||
2009 | static int | |
a6b96beb AM |
2010 | ppc_elf_additional_program_headers (bfd *abfd, |
2011 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
25dbc73a AM |
2012 | { |
2013 | asection *s; | |
2014 | int ret = 0; | |
d1c6de6f | 2015 | |
25dbc73a AM |
2016 | s = bfd_get_section_by_name (abfd, ".sbss2"); |
2017 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2018 | ++ret; | |
d1c6de6f | 2019 | |
25dbc73a AM |
2020 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); |
2021 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
2022 | ++ret; | |
deaaf2f3 | 2023 | |
25dbc73a AM |
2024 | return ret; |
2025 | } | |
deaaf2f3 | 2026 | |
25dbc73a AM |
2027 | /* Add extra PPC sections -- Note, for now, make .sbss2 and |
2028 | .PPC.EMB.sbss0 a normal section, and not a bss section so | |
2029 | that the linker doesn't crater when trying to make more than | |
2030 | 2 sections. */ | |
e656e369 | 2031 | |
b35d266b | 2032 | static const struct bfd_elf_special_section ppc_elf_special_sections[] = |
7f4d3958 | 2033 | { |
0112cd26 NC |
2034 | { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR }, |
2035 | { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2036 | { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2037 | { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2038 | { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC }, | |
2039 | { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC }, | |
2040 | { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 }, | |
2041 | { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2042 | { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC }, | |
2043 | { NULL, 0, 0, 0, 0 } | |
7f4d3958 L |
2044 | }; |
2045 | ||
551b43fd AM |
2046 | /* This is what we want for new plt/got. */ |
2047 | static struct bfd_elf_special_section ppc_alt_plt = | |
0112cd26 | 2048 | { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC }; |
551b43fd AM |
2049 | |
2050 | static const struct bfd_elf_special_section * | |
2051 | ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) | |
7f4d3958 | 2052 | { |
b35d266b | 2053 | const struct bfd_elf_special_section *ssect; |
551b43fd AM |
2054 | |
2055 | /* See if this is one of the special sections. */ | |
2056 | if (sec->name == NULL) | |
2057 | return NULL; | |
2058 | ||
2059 | ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections, | |
2060 | sec->use_rela_p); | |
2061 | if (ssect != NULL) | |
2062 | { | |
2063 | if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0) | |
2064 | ssect = &ppc_alt_plt; | |
2065 | return ssect; | |
2066 | } | |
2067 | ||
2068 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
2069 | } | |
25dbc73a AM |
2070 | \f |
2071 | /* Very simple linked list structure for recording apuinfo values. */ | |
2072 | typedef struct apuinfo_list | |
2073 | { | |
2074 | struct apuinfo_list *next; | |
2075 | unsigned long value; | |
2076 | } | |
2077 | apuinfo_list; | |
e656e369 | 2078 | |
25dbc73a | 2079 | static apuinfo_list *head; |
f2faa800 | 2080 | static bfd_boolean apuinfo_set; |
deaaf2f3 | 2081 | |
25dbc73a AM |
2082 | static void |
2083 | apuinfo_list_init (void) | |
2084 | { | |
2085 | head = NULL; | |
f2faa800 | 2086 | apuinfo_set = FALSE; |
25dbc73a | 2087 | } |
9abc968f | 2088 | |
25dbc73a AM |
2089 | static void |
2090 | apuinfo_list_add (unsigned long value) | |
2091 | { | |
2092 | apuinfo_list *entry = head; | |
deaaf2f3 | 2093 | |
25dbc73a AM |
2094 | while (entry != NULL) |
2095 | { | |
2096 | if (entry->value == value) | |
2097 | return; | |
2098 | entry = entry->next; | |
2099 | } | |
b4a38de6 | 2100 | |
25dbc73a AM |
2101 | entry = bfd_malloc (sizeof (* entry)); |
2102 | if (entry == NULL) | |
2103 | return; | |
e656e369 | 2104 | |
25dbc73a AM |
2105 | entry->value = value; |
2106 | entry->next = head; | |
2107 | head = entry; | |
2108 | } | |
9abc968f | 2109 | |
25dbc73a AM |
2110 | static unsigned |
2111 | apuinfo_list_length (void) | |
2112 | { | |
2113 | apuinfo_list *entry; | |
2114 | unsigned long count; | |
9abc968f | 2115 | |
25dbc73a AM |
2116 | for (entry = head, count = 0; |
2117 | entry; | |
2118 | entry = entry->next) | |
2119 | ++ count; | |
e656e369 | 2120 | |
25dbc73a AM |
2121 | return count; |
2122 | } | |
eea6121a | 2123 | |
25dbc73a AM |
2124 | static inline unsigned long |
2125 | apuinfo_list_element (unsigned long number) | |
2126 | { | |
2127 | apuinfo_list * entry; | |
e656e369 | 2128 | |
25dbc73a AM |
2129 | for (entry = head; |
2130 | entry && number --; | |
2131 | entry = entry->next) | |
2132 | ; | |
252b5132 | 2133 | |
25dbc73a AM |
2134 | return entry ? entry->value : 0; |
2135 | } | |
2136 | ||
2137 | static void | |
2138 | apuinfo_list_finish (void) | |
2139 | { | |
2140 | apuinfo_list *entry; | |
2141 | ||
2142 | for (entry = head; entry;) | |
252b5132 | 2143 | { |
25dbc73a AM |
2144 | apuinfo_list *next = entry->next; |
2145 | free (entry); | |
2146 | entry = next; | |
2147 | } | |
9abc968f | 2148 | |
25dbc73a AM |
2149 | head = NULL; |
2150 | } | |
9abc968f | 2151 | |
25dbc73a AM |
2152 | #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo" |
2153 | #define APUINFO_LABEL "APUinfo" | |
9abc968f | 2154 | |
25dbc73a AM |
2155 | /* Scan the input BFDs and create a linked list of |
2156 | the APUinfo values that will need to be emitted. */ | |
9abc968f | 2157 | |
25dbc73a AM |
2158 | static void |
2159 | ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info) | |
2160 | { | |
2161 | bfd *ibfd; | |
2162 | asection *asec; | |
deddc40b NS |
2163 | char *buffer = NULL; |
2164 | bfd_size_type largest_input_size = 0; | |
25dbc73a | 2165 | unsigned i; |
25dbc73a AM |
2166 | unsigned long length; |
2167 | const char *error_message = NULL; | |
9abc968f | 2168 | |
25dbc73a AM |
2169 | if (link_info == NULL) |
2170 | return; | |
9abc968f | 2171 | |
25dbc73a | 2172 | apuinfo_list_init (); |
252b5132 | 2173 | |
25dbc73a AM |
2174 | /* Read in the input sections contents. */ |
2175 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) | |
252b5132 | 2176 | { |
25dbc73a | 2177 | unsigned long datum; |
252b5132 | 2178 | |
25dbc73a AM |
2179 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
2180 | if (asec == NULL) | |
2181 | continue; | |
252b5132 | 2182 | |
deddc40b | 2183 | error_message = _("corrupt %s section in %B"); |
25dbc73a | 2184 | length = asec->size; |
deddc40b NS |
2185 | if (length < 20) |
2186 | goto fail; | |
2187 | ||
f2faa800 | 2188 | apuinfo_set = TRUE; |
deddc40b | 2189 | if (largest_input_size < asec->size) |
25dbc73a | 2190 | { |
deddc40b NS |
2191 | if (buffer) |
2192 | free (buffer); | |
2193 | largest_input_size = asec->size; | |
2194 | buffer = bfd_malloc (largest_input_size); | |
2195 | if (!buffer) | |
2196 | return; | |
25dbc73a | 2197 | } |
deddc40b | 2198 | |
25dbc73a | 2199 | if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0 |
deddc40b | 2200 | || (bfd_bread (buffer, length, ibfd) != length)) |
25dbc73a AM |
2201 | { |
2202 | error_message = _("unable to read in %s section from %B"); | |
2203 | goto fail; | |
2204 | } | |
252b5132 | 2205 | |
25dbc73a AM |
2206 | /* Verify the contents of the header. Note - we have to |
2207 | extract the values this way in order to allow for a | |
2208 | host whose endian-ness is different from the target. */ | |
deddc40b | 2209 | datum = bfd_get_32 (ibfd, buffer); |
25dbc73a AM |
2210 | if (datum != sizeof APUINFO_LABEL) |
2211 | goto fail; | |
252b5132 | 2212 | |
deddc40b | 2213 | datum = bfd_get_32 (ibfd, buffer + 8); |
25dbc73a AM |
2214 | if (datum != 0x2) |
2215 | goto fail; | |
252b5132 | 2216 | |
deddc40b | 2217 | if (strcmp (buffer + 12, APUINFO_LABEL) != 0) |
25dbc73a | 2218 | goto fail; |
252b5132 | 2219 | |
25dbc73a | 2220 | /* Get the number of bytes used for apuinfo entries. */ |
deddc40b | 2221 | datum = bfd_get_32 (ibfd, buffer + 4); |
25dbc73a AM |
2222 | if (datum + 20 != length) |
2223 | goto fail; | |
2224 | ||
25dbc73a AM |
2225 | /* Scan the apuinfo section, building a list of apuinfo numbers. */ |
2226 | for (i = 0; i < datum; i += 4) | |
deddc40b | 2227 | apuinfo_list_add (bfd_get_32 (ibfd, buffer + 20 + i)); |
252b5132 RH |
2228 | } |
2229 | ||
25dbc73a | 2230 | error_message = NULL; |
252b5132 | 2231 | |
f2faa800 | 2232 | if (apuinfo_set) |
deddc40b | 2233 | { |
f2faa800 NS |
2234 | /* Compute the size of the output section. */ |
2235 | unsigned num_entries = apuinfo_list_length (); | |
2236 | ||
deddc40b NS |
2237 | /* Set the output section size, if it exists. */ |
2238 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
f2faa800 | 2239 | |
deddc40b NS |
2240 | if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4)) |
2241 | { | |
2242 | ibfd = abfd; | |
2243 | error_message = _("warning: unable to set size of %s section in %B"); | |
2244 | } | |
2245 | } | |
25dbc73a AM |
2246 | |
2247 | fail: | |
deddc40b NS |
2248 | if (buffer) |
2249 | free (buffer); | |
25dbc73a AM |
2250 | |
2251 | if (error_message) | |
2252 | (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME); | |
2253 | } | |
252b5132 | 2254 | |
25dbc73a AM |
2255 | /* Prevent the output section from accumulating the input sections' |
2256 | contents. We have already stored this in our linked list structure. */ | |
252b5132 | 2257 | |
25dbc73a AM |
2258 | static bfd_boolean |
2259 | ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED, | |
c7b8f16e | 2260 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED, |
25dbc73a AM |
2261 | asection *asec, |
2262 | bfd_byte *contents ATTRIBUTE_UNUSED) | |
2263 | { | |
f2faa800 | 2264 | return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0; |
252b5132 RH |
2265 | } |
2266 | ||
25dbc73a AM |
2267 | /* Finally we can generate the output section. */ |
2268 | ||
2269 | static void | |
2270 | ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) | |
7619e7c7 | 2271 | { |
25dbc73a AM |
2272 | bfd_byte *buffer; |
2273 | asection *asec; | |
2274 | unsigned i; | |
2275 | unsigned num_entries; | |
2276 | bfd_size_type length; | |
7619e7c7 | 2277 | |
25dbc73a AM |
2278 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); |
2279 | if (asec == NULL) | |
2280 | return; | |
2281 | ||
f2faa800 | 2282 | if (!apuinfo_set) |
25dbc73a AM |
2283 | return; |
2284 | ||
2285 | length = asec->size; | |
2286 | if (length < 20) | |
2287 | return; | |
2288 | ||
2289 | buffer = bfd_malloc (length); | |
2290 | if (buffer == NULL) | |
7619e7c7 | 2291 | { |
25dbc73a AM |
2292 | (*_bfd_error_handler) |
2293 | (_("failed to allocate space for new APUinfo section.")); | |
2294 | return; | |
7619e7c7 | 2295 | } |
7619e7c7 | 2296 | |
25dbc73a AM |
2297 | /* Create the apuinfo header. */ |
2298 | num_entries = apuinfo_list_length (); | |
2299 | bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer); | |
2300 | bfd_put_32 (abfd, num_entries * 4, buffer + 4); | |
2301 | bfd_put_32 (abfd, 0x2, buffer + 8); | |
2302 | strcpy ((char *) buffer + 12, APUINFO_LABEL); | |
feee612b | 2303 | |
25dbc73a AM |
2304 | length = 20; |
2305 | for (i = 0; i < num_entries; i++) | |
feee612b | 2306 | { |
25dbc73a AM |
2307 | bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length); |
2308 | length += 4; | |
feee612b | 2309 | } |
feee612b | 2310 | |
25dbc73a AM |
2311 | if (length != asec->size) |
2312 | (*_bfd_error_handler) (_("failed to compute new APUinfo section.")); | |
252b5132 | 2313 | |
25dbc73a AM |
2314 | if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length)) |
2315 | (*_bfd_error_handler) (_("failed to install new APUinfo section.")); | |
252b5132 | 2316 | |
25dbc73a AM |
2317 | free (buffer); |
2318 | ||
2319 | apuinfo_list_finish (); | |
252b5132 | 2320 | } |
25dbc73a | 2321 | \f |
7382d32a | 2322 | static bfd_boolean |
c6dd29ce | 2323 | is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off) |
7382d32a | 2324 | { |
c6dd29ce | 2325 | bfd_byte buf[GLINK_ENTRY_SIZE]; |
7382d32a | 2326 | |
c6dd29ce | 2327 | if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE)) |
7382d32a AM |
2328 | return FALSE; |
2329 | ||
c6dd29ce AM |
2330 | return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11 |
2331 | && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11 | |
2332 | && bfd_get_32 (abfd, buf + 8) == MTCTR_11 | |
2333 | && bfd_get_32 (abfd, buf + 12) == BCTR); | |
7382d32a AM |
2334 | } |
2335 | ||
468392fb AM |
2336 | static bfd_boolean |
2337 | section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr) | |
2338 | { | |
2339 | bfd_vma vma = *(bfd_vma *) ptr; | |
2340 | return ((section->flags & SEC_ALLOC) != 0 | |
2341 | && section->vma <= vma | |
2342 | && vma < section->vma + section->size); | |
2343 | } | |
2344 | ||
2345 | static long | |
2346 | ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms, | |
2347 | long dynsymcount, asymbol **dynsyms, | |
2348 | asymbol **ret) | |
2349 | { | |
2350 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); | |
2351 | asection *plt, *relplt, *dynamic, *glink; | |
2352 | bfd_vma glink_vma = 0; | |
2353 | bfd_vma resolv_vma = 0; | |
2354 | bfd_vma stub_vma; | |
2355 | asymbol *s; | |
2356 | arelent *p; | |
2357 | long count, i; | |
2358 | size_t size; | |
2359 | char *names; | |
2360 | bfd_byte buf[4]; | |
2361 | ||
2362 | *ret = NULL; | |
2363 | ||
2364 | if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0) | |
2365 | return 0; | |
2366 | ||
2367 | if (dynsymcount <= 0) | |
2368 | return 0; | |
2369 | ||
2370 | relplt = bfd_get_section_by_name (abfd, ".rela.plt"); | |
2371 | if (relplt == NULL) | |
2372 | return 0; | |
2373 | ||
2374 | plt = bfd_get_section_by_name (abfd, ".plt"); | |
2375 | if (plt == NULL) | |
2376 | return 0; | |
2377 | ||
2378 | /* Call common code to handle old-style executable PLTs. */ | |
2379 | if (elf_section_flags (plt) & SHF_EXECINSTR) | |
2380 | return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms, | |
2381 | dynsymcount, dynsyms, ret); | |
2382 | ||
2383 | /* If this object was prelinked, the prelinker stored the address | |
2384 | of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */ | |
2385 | dynamic = bfd_get_section_by_name (abfd, ".dynamic"); | |
2386 | if (dynamic != NULL) | |
2387 | { | |
2388 | bfd_byte *dynbuf, *extdyn, *extdynend; | |
2389 | size_t extdynsize; | |
2390 | void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *); | |
2391 | ||
2392 | if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf)) | |
2393 | return -1; | |
2394 | ||
2395 | extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; | |
2396 | swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in; | |
2397 | ||
2398 | extdyn = dynbuf; | |
2399 | extdynend = extdyn + dynamic->size; | |
2400 | for (; extdyn < extdynend; extdyn += extdynsize) | |
2401 | { | |
2402 | Elf_Internal_Dyn dyn; | |
2403 | (*swap_dyn_in) (abfd, extdyn, &dyn); | |
2404 | ||
2405 | if (dyn.d_tag == DT_NULL) | |
2406 | break; | |
2407 | ||
2408 | if (dyn.d_tag == DT_PPC_GOT) | |
2409 | { | |
2410 | unsigned int g_o_t = dyn.d_un.d_val; | |
2411 | asection *got = bfd_get_section_by_name (abfd, ".got"); | |
2412 | if (got != NULL | |
2413 | && bfd_get_section_contents (abfd, got, buf, | |
2414 | g_o_t - got->vma + 4, 4)) | |
2415 | glink_vma = bfd_get_32 (abfd, buf); | |
2416 | break; | |
2417 | } | |
2418 | } | |
2419 | free (dynbuf); | |
2420 | } | |
2421 | ||
2422 | /* Otherwise we read the first plt entry. */ | |
2423 | if (glink_vma == 0) | |
2424 | { | |
2425 | if (bfd_get_section_contents (abfd, plt, buf, 0, 4)) | |
2426 | glink_vma = bfd_get_32 (abfd, buf); | |
2427 | } | |
2428 | ||
2429 | if (glink_vma == 0) | |
2430 | return 0; | |
2431 | ||
2432 | /* The .glink section usually does not survive the final | |
2433 | link; search for the section (usually .text) where the | |
2434 | glink stubs now reside. */ | |
2435 | glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma); | |
2436 | if (glink == NULL) | |
2437 | return 0; | |
2438 | ||
2439 | /* Determine glink PLT resolver by reading the relative branch | |
2440 | from the first glink stub. */ | |
2441 | if (bfd_get_section_contents (abfd, glink, buf, | |
2442 | glink_vma - glink->vma, 4)) | |
2443 | { | |
2444 | unsigned int insn = bfd_get_32 (abfd, buf); | |
2445 | ||
2446 | /* The first glink stub may either branch to the resolver ... */ | |
2447 | insn ^= B; | |
2448 | if ((insn & ~0x3fffffc) == 0) | |
2449 | resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000; | |
2450 | ||
2451 | /* ... or fall through a bunch of NOPs. */ | |
2452 | else if ((insn ^ B ^ NOP) == 0) | |
2453 | for (i = 4; | |
2454 | bfd_get_section_contents (abfd, glink, buf, | |
2455 | glink_vma - glink->vma + i, 4); | |
2456 | i += 4) | |
2457 | if (bfd_get_32 (abfd, buf) != NOP) | |
2458 | { | |
2459 | resolv_vma = glink_vma + i; | |
2460 | break; | |
2461 | } | |
2462 | } | |
2463 | ||
7382d32a AM |
2464 | count = relplt->size / sizeof (Elf32_External_Rela); |
2465 | stub_vma = glink_vma - (bfd_vma) count * 16; | |
2466 | /* If the stubs are those for -shared/-pie then we might have | |
2467 | multiple stubs for each plt entry. If that is the case then | |
2468 | there is no way to associate stubs with their plt entries short | |
2469 | of figuring out the GOT pointer value used in the stub. */ | |
c6dd29ce AM |
2470 | if (!is_nonpic_glink_stub (abfd, glink, |
2471 | glink_vma - GLINK_ENTRY_SIZE - glink->vma)) | |
7382d32a AM |
2472 | return 0; |
2473 | ||
468392fb AM |
2474 | slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; |
2475 | if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE)) | |
2476 | return -1; | |
2477 | ||
468392fb AM |
2478 | size = count * sizeof (asymbol); |
2479 | p = relplt->relocation; | |
2480 | for (i = 0; i < count; i++, p++) | |
e054468f AM |
2481 | { |
2482 | size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt"); | |
2483 | if (p->addend != 0) | |
2484 | size += sizeof ("+0x") - 1 + 8; | |
2485 | } | |
468392fb AM |
2486 | |
2487 | size += sizeof (asymbol) + sizeof ("__glink"); | |
2488 | ||
2489 | if (resolv_vma) | |
2490 | size += sizeof (asymbol) + sizeof ("__glink_PLTresolve"); | |
2491 | ||
2492 | s = *ret = bfd_malloc (size); | |
2493 | if (s == NULL) | |
2494 | return -1; | |
2495 | ||
2496 | names = (char *) (s + count + 1 + (resolv_vma != 0)); | |
2497 | p = relplt->relocation; | |
2498 | for (i = 0; i < count; i++, p++) | |
2499 | { | |
2500 | size_t len; | |
2501 | ||
2502 | *s = **p->sym_ptr_ptr; | |
2503 | /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since | |
2504 | we are defining a symbol, ensure one of them is set. */ | |
2505 | if ((s->flags & BSF_LOCAL) == 0) | |
2506 | s->flags |= BSF_GLOBAL; | |
6ba2a415 | 2507 | s->flags |= BSF_SYNTHETIC; |
468392fb AM |
2508 | s->section = glink; |
2509 | s->value = stub_vma - glink->vma; | |
2510 | s->name = names; | |
2511 | s->udata.p = NULL; | |
2512 | len = strlen ((*p->sym_ptr_ptr)->name); | |
2513 | memcpy (names, (*p->sym_ptr_ptr)->name, len); | |
2514 | names += len; | |
e054468f AM |
2515 | if (p->addend != 0) |
2516 | { | |
2517 | memcpy (names, "+0x", sizeof ("+0x") - 1); | |
2518 | names += sizeof ("+0x") - 1; | |
2519 | bfd_sprintf_vma (abfd, names, p->addend); | |
2520 | names += strlen (names); | |
2521 | } | |
468392fb AM |
2522 | memcpy (names, "@plt", sizeof ("@plt")); |
2523 | names += sizeof ("@plt"); | |
2524 | ++s; | |
2525 | stub_vma += 16; | |
2526 | } | |
2527 | ||
2528 | /* Add a symbol at the start of the glink branch table. */ | |
86a4952b | 2529 | memset (s, 0, sizeof *s); |
468392fb | 2530 | s->the_bfd = abfd; |
6ba2a415 | 2531 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
2532 | s->section = glink; |
2533 | s->value = glink_vma - glink->vma; | |
2534 | s->name = names; | |
2535 | memcpy (names, "__glink", sizeof ("__glink")); | |
2536 | names += sizeof ("__glink"); | |
2537 | s++; | |
2538 | count++; | |
2539 | ||
2540 | if (resolv_vma) | |
2541 | { | |
2542 | /* Add a symbol for the glink PLT resolver. */ | |
86a4952b | 2543 | memset (s, 0, sizeof *s); |
468392fb | 2544 | s->the_bfd = abfd; |
6ba2a415 | 2545 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
2546 | s->section = glink; |
2547 | s->value = resolv_vma - glink->vma; | |
2548 | s->name = names; | |
2549 | memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve")); | |
2550 | names += sizeof ("__glink_PLTresolve"); | |
2551 | s++; | |
2552 | count++; | |
2553 | } | |
2554 | ||
2555 | return count; | |
2556 | } | |
2557 | \f | |
25dbc73a AM |
2558 | /* The following functions are specific to the ELF linker, while |
2559 | functions above are used generally. They appear in this file more | |
2560 | or less in the order in which they are called. eg. | |
2561 | ppc_elf_check_relocs is called early in the link process, | |
2562 | ppc_elf_finish_dynamic_sections is one of the last functions | |
2563 | called. */ | |
252b5132 | 2564 | |
25dbc73a AM |
2565 | /* The PPC linker needs to keep track of the number of relocs that it |
2566 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2567 | This is so that it can later discard them if they are found to be | |
2568 | unnecessary. We store the information in a field extending the | |
2569 | regular ELF linker hash table. */ | |
ae9a127f | 2570 | |
25dbc73a | 2571 | struct ppc_elf_dyn_relocs |
252b5132 | 2572 | { |
25dbc73a | 2573 | struct ppc_elf_dyn_relocs *next; |
252b5132 | 2574 | |
25dbc73a AM |
2575 | /* The input section of the reloc. */ |
2576 | asection *sec; | |
252b5132 | 2577 | |
25dbc73a AM |
2578 | /* Total number of relocs copied for the input section. */ |
2579 | bfd_size_type count; | |
252b5132 | 2580 | |
25dbc73a AM |
2581 | /* Number of pc-relative relocs copied for the input section. */ |
2582 | bfd_size_type pc_count; | |
2583 | }; | |
252b5132 | 2584 | |
a6aa5195 | 2585 | /* Track PLT entries needed for a given symbol. We might need more |
a877a2b6 | 2586 | than one glink entry per symbol when generating a pic binary. */ |
a6aa5195 AM |
2587 | struct plt_entry |
2588 | { | |
2589 | struct plt_entry *next; | |
2590 | ||
2591 | /* -fPIC uses multiple GOT sections, one per file, called ".got2". | |
2592 | This field stores the offset into .got2 used to initialise the | |
a877a2b6 AM |
2593 | GOT pointer reg. It will always be at least 32768. (Current |
2594 | gcc always uses an offset of 32768, but ld -r will pack .got2 | |
2595 | sections together resulting in larger offsets). */ | |
a6aa5195 AM |
2596 | bfd_vma addend; |
2597 | ||
2598 | /* The .got2 section. */ | |
2599 | asection *sec; | |
2600 | ||
2601 | /* PLT refcount or offset. */ | |
2602 | union | |
2603 | { | |
2604 | bfd_signed_vma refcount; | |
2605 | bfd_vma offset; | |
2606 | } plt; | |
2607 | ||
2608 | /* .glink stub offset. */ | |
2609 | bfd_vma glink_offset; | |
2610 | }; | |
2611 | ||
1d483afe | 2612 | /* Of those relocs that might be copied as dynamic relocs, this function |
25dbc73a AM |
2613 | selects those that must be copied when linking a shared library, |
2614 | even when the symbol is local. */ | |
252b5132 | 2615 | |
1d483afe AM |
2616 | static int |
2617 | must_be_dyn_reloc (struct bfd_link_info *info, | |
2618 | enum elf_ppc_reloc_type r_type) | |
2619 | { | |
2620 | switch (r_type) | |
2621 | { | |
2622 | default: | |
2623 | return 1; | |
2624 | ||
2625 | case R_PPC_REL24: | |
2626 | case R_PPC_REL14: | |
2627 | case R_PPC_REL14_BRTAKEN: | |
2628 | case R_PPC_REL14_BRNTAKEN: | |
2629 | case R_PPC_REL32: | |
2630 | return 0; | |
2631 | ||
2632 | case R_PPC_TPREL32: | |
2633 | case R_PPC_TPREL16: | |
2634 | case R_PPC_TPREL16_LO: | |
2635 | case R_PPC_TPREL16_HI: | |
2636 | case R_PPC_TPREL16_HA: | |
2637 | return !info->executable; | |
2638 | } | |
2639 | } | |
252b5132 | 2640 | |
25dbc73a AM |
2641 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2642 | copying dynamic variables from a shared lib into an app's dynbss | |
2643 | section, and instead use a dynamic relocation to point into the | |
2644 | shared lib. */ | |
2645 | #define ELIMINATE_COPY_RELOCS 1 | |
252b5132 | 2646 | |
25dbc73a | 2647 | /* PPC ELF linker hash entry. */ |
252b5132 | 2648 | |
25dbc73a AM |
2649 | struct ppc_elf_link_hash_entry |
2650 | { | |
2651 | struct elf_link_hash_entry elf; | |
252b5132 | 2652 | |
25dbc73a AM |
2653 | /* If this symbol is used in the linker created sections, the processor |
2654 | specific backend uses this field to map the field into the offset | |
2655 | from the beginning of the section. */ | |
2656 | elf_linker_section_pointers_t *linker_section_pointer; | |
252b5132 | 2657 | |
25dbc73a AM |
2658 | /* Track dynamic relocs copied for this symbol. */ |
2659 | struct ppc_elf_dyn_relocs *dyn_relocs; | |
252b5132 | 2660 | |
25dbc73a AM |
2661 | /* Contexts in which symbol is used in the GOT (or TOC). |
2662 | TLS_GD .. TLS_TLS bits are or'd into the mask as the | |
2663 | corresponding relocs are encountered during check_relocs. | |
2664 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2665 | indicate the corresponding GOT entry type is not needed. */ | |
2666 | #define TLS_GD 1 /* GD reloc. */ | |
2667 | #define TLS_LD 2 /* LD reloc. */ | |
2668 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2669 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2670 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2671 | #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */ | |
e054468f | 2672 | #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */ |
25dbc73a | 2673 | char tls_mask; |
4dc4a9a5 DJ |
2674 | |
2675 | /* Nonzero if we have seen a small data relocation referring to this | |
2676 | symbol. */ | |
2677 | unsigned char has_sda_refs; | |
25dbc73a | 2678 | }; |
252b5132 | 2679 | |
25dbc73a AM |
2680 | #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent)) |
2681 | ||
2682 | /* PPC ELF linker hash table. */ | |
2683 | ||
2684 | struct ppc_elf_link_hash_table | |
2685 | { | |
2686 | struct elf_link_hash_table elf; | |
2687 | ||
2688 | /* Short-cuts to get to dynamic linker sections. */ | |
2689 | asection *got; | |
2690 | asection *relgot; | |
d7128ce4 | 2691 | asection *glink; |
25dbc73a AM |
2692 | asection *plt; |
2693 | asection *relplt; | |
e054468f AM |
2694 | asection *iplt; |
2695 | asection *reliplt; | |
25dbc73a AM |
2696 | asection *dynbss; |
2697 | asection *relbss; | |
2698 | asection *dynsbss; | |
2699 | asection *relsbss; | |
c9a2f333 | 2700 | elf_linker_section_t sdata[2]; |
25dbc73a AM |
2701 | asection *sbss; |
2702 | ||
016687f8 AM |
2703 | /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */ |
2704 | asection *srelplt2; | |
2705 | ||
2706 | /* The .got.plt section (VxWorks only)*/ | |
2707 | asection *sgotplt; | |
2708 | ||
1d483afe | 2709 | /* Shortcut to __tls_get_addr. */ |
25dbc73a | 2710 | struct elf_link_hash_entry *tls_get_addr; |
252b5132 | 2711 | |
016687f8 AM |
2712 | /* The bfd that forced an old-style PLT. */ |
2713 | bfd *old_bfd; | |
2714 | ||
25dbc73a AM |
2715 | /* TLS local dynamic got entry handling. */ |
2716 | union { | |
2717 | bfd_signed_vma refcount; | |
2718 | bfd_vma offset; | |
2719 | } tlsld_got; | |
252b5132 | 2720 | |
c6dd29ce | 2721 | /* Offset of branch table to PltResolve function in glink. */ |
d7128ce4 AM |
2722 | bfd_vma glink_pltresolve; |
2723 | ||
3b36f7e6 AM |
2724 | /* Size of reserved GOT entries. */ |
2725 | unsigned int got_header_size; | |
2726 | /* Non-zero if allocating the header left a gap. */ | |
2727 | unsigned int got_gap; | |
2728 | ||
4a3dc543 RS |
2729 | /* The type of PLT we have chosen to use. */ |
2730 | enum ppc_elf_plt_type plt_type; | |
2731 | ||
0ba07910 AM |
2732 | /* Set if we should emit symbols for stubs. */ |
2733 | unsigned int emit_stub_syms:1; | |
2734 | ||
a7f2871e AM |
2735 | /* Set if __tls_get_addr optimization should not be done. */ |
2736 | unsigned int no_tls_get_addr_opt:1; | |
2737 | ||
9d8504b1 | 2738 | /* True if the target system is VxWorks. */ |
016687f8 | 2739 | unsigned int is_vxworks:1; |
9d8504b1 PB |
2740 | |
2741 | /* The size of PLT entries. */ | |
2742 | int plt_entry_size; | |
2743 | /* The distance between adjacent PLT slots. */ | |
2744 | int plt_slot_size; | |
2745 | /* The size of the first PLT entry. */ | |
2746 | int plt_initial_entry_size; | |
016687f8 | 2747 | |
87d72d41 AM |
2748 | /* Small local sym cache. */ |
2749 | struct sym_cache sym_cache; | |
25dbc73a | 2750 | }; |
252b5132 | 2751 | |
b0dddeec AM |
2752 | /* Rename some of the generic section flags to better document how they |
2753 | are used here. */ | |
2754 | ||
2755 | /* Nonzero if this section has TLS related relocations. */ | |
2756 | #define has_tls_reloc sec_flg0 | |
2757 | ||
2758 | /* Nonzero if this section has a call to __tls_get_addr. */ | |
2759 | #define has_tls_get_addr_call sec_flg1 | |
2760 | ||
25dbc73a | 2761 | /* Get the PPC ELF linker hash table from a link_info structure. */ |
252b5132 | 2762 | |
25dbc73a | 2763 | #define ppc_elf_hash_table(p) \ |
4dfe6ac6 NC |
2764 | (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ |
2765 | == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL) | |
252b5132 | 2766 | |
25dbc73a | 2767 | /* Create an entry in a PPC ELF linker hash table. */ |
252b5132 | 2768 | |
25dbc73a AM |
2769 | static struct bfd_hash_entry * |
2770 | ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry, | |
2771 | struct bfd_hash_table *table, | |
2772 | const char *string) | |
252b5132 | 2773 | { |
25dbc73a AM |
2774 | /* Allocate the structure if it has not already been allocated by a |
2775 | subclass. */ | |
2776 | if (entry == NULL) | |
2777 | { | |
2778 | entry = bfd_hash_allocate (table, | |
2779 | sizeof (struct ppc_elf_link_hash_entry)); | |
2780 | if (entry == NULL) | |
2781 | return entry; | |
2782 | } | |
252b5132 | 2783 | |
25dbc73a AM |
2784 | /* Call the allocation method of the superclass. */ |
2785 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2786 | if (entry != NULL) | |
2787 | { | |
2788 | ppc_elf_hash_entry (entry)->linker_section_pointer = NULL; | |
2789 | ppc_elf_hash_entry (entry)->dyn_relocs = NULL; | |
2790 | ppc_elf_hash_entry (entry)->tls_mask = 0; | |
2791 | } | |
252b5132 | 2792 | |
25dbc73a | 2793 | return entry; |
252b5132 | 2794 | } |
3dab13f6 | 2795 | |
25dbc73a | 2796 | /* Create a PPC ELF linker hash table. */ |
3dab13f6 | 2797 | |
25dbc73a AM |
2798 | static struct bfd_link_hash_table * |
2799 | ppc_elf_link_hash_table_create (bfd *abfd) | |
3dab13f6 | 2800 | { |
25dbc73a | 2801 | struct ppc_elf_link_hash_table *ret; |
3dab13f6 | 2802 | |
25dbc73a AM |
2803 | ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table)); |
2804 | if (ret == NULL) | |
2805 | return NULL; | |
3dab13f6 | 2806 | |
66eb6687 AM |
2807 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, |
2808 | ppc_elf_link_hash_newfunc, | |
4dfe6ac6 NC |
2809 | sizeof (struct ppc_elf_link_hash_entry), |
2810 | PPC32_ELF_DATA)) | |
3dab13f6 | 2811 | { |
25dbc73a AM |
2812 | free (ret); |
2813 | return NULL; | |
2814 | } | |
58111eb7 | 2815 | |
a6aa5195 AM |
2816 | ret->elf.init_plt_refcount.refcount = 0; |
2817 | ret->elf.init_plt_refcount.glist = NULL; | |
2818 | ret->elf.init_plt_offset.offset = 0; | |
2819 | ret->elf.init_plt_offset.glist = NULL; | |
2820 | ||
c9a2f333 AM |
2821 | ret->sdata[0].name = ".sdata"; |
2822 | ret->sdata[0].sym_name = "_SDA_BASE_"; | |
2823 | ret->sdata[0].bss_name = ".sbss"; | |
2824 | ||
2825 | ret->sdata[1].name = ".sdata2"; | |
2826 | ret->sdata[1].sym_name = "_SDA2_BASE_"; | |
2827 | ret->sdata[1].bss_name = ".sbss2"; | |
2828 | ||
9d8504b1 PB |
2829 | ret->plt_entry_size = 12; |
2830 | ret->plt_slot_size = 8; | |
2831 | ret->plt_initial_entry_size = 72; | |
9d8504b1 | 2832 | |
25dbc73a AM |
2833 | return &ret->elf.root; |
2834 | } | |
3dab13f6 | 2835 | |
9d8504b1 | 2836 | /* Create .got and the related sections. */ |
3dab13f6 | 2837 | |
25dbc73a AM |
2838 | static bfd_boolean |
2839 | ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info) | |
2840 | { | |
2841 | struct ppc_elf_link_hash_table *htab; | |
2842 | asection *s; | |
2843 | flagword flags; | |
3dab13f6 | 2844 | |
25dbc73a AM |
2845 | if (!_bfd_elf_create_got_section (abfd, info)) |
2846 | return FALSE; | |
3dab13f6 | 2847 | |
25dbc73a AM |
2848 | htab = ppc_elf_hash_table (info); |
2849 | htab->got = s = bfd_get_section_by_name (abfd, ".got"); | |
2850 | if (s == NULL) | |
2851 | abort (); | |
3dab13f6 | 2852 | |
9d8504b1 PB |
2853 | if (htab->is_vxworks) |
2854 | { | |
2855 | htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt"); | |
2856 | if (!htab->sgotplt) | |
2857 | abort (); | |
2858 | } | |
2859 | else | |
2860 | { | |
2861 | /* The powerpc .got has a blrl instruction in it. Mark it | |
2862 | executable. */ | |
2863 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | |
2864 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2865 | if (!bfd_set_section_flags (abfd, s, flags)) | |
2866 | return FALSE; | |
2867 | } | |
3dab13f6 | 2868 | |
64e77c6d L |
2869 | htab->relgot = bfd_get_section_by_name (abfd, ".rela.got"); |
2870 | if (!htab->relgot) | |
2871 | abort (); | |
3dab13f6 | 2872 | |
25dbc73a AM |
2873 | return TRUE; |
2874 | } | |
3dab13f6 | 2875 | |
e054468f AM |
2876 | static bfd_boolean |
2877 | ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info) | |
2878 | { | |
2879 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
2880 | asection *s; | |
2881 | flagword flags; | |
2882 | ||
2883 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | |
2884 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2885 | s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags); | |
2886 | htab->glink = s; | |
2887 | if (s == NULL | |
2888 | || !bfd_set_section_alignment (abfd, s, 4)) | |
2889 | return FALSE; | |
2890 | ||
2891 | flags = SEC_ALLOC | SEC_LINKER_CREATED; | |
2892 | s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags); | |
2893 | htab->iplt = s; | |
2894 | if (s == NULL | |
2895 | || !bfd_set_section_alignment (abfd, s, 4)) | |
2896 | return FALSE; | |
2897 | ||
2898 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | |
2899 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2900 | s = bfd_make_section_with_flags (abfd, ".rela.iplt", flags); | |
2901 | htab->reliplt = s; | |
2902 | if (s == NULL | |
2903 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
2904 | return FALSE; | |
2905 | return TRUE; | |
2906 | } | |
2907 | ||
25dbc73a AM |
2908 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
2909 | to output sections (just like _bfd_elf_create_dynamic_sections has | |
2910 | to create .dynbss and .rela.bss). */ | |
3dab13f6 | 2911 | |
25dbc73a AM |
2912 | static bfd_boolean |
2913 | ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |
2914 | { | |
2915 | struct ppc_elf_link_hash_table *htab; | |
2916 | asection *s; | |
2917 | flagword flags; | |
3dab13f6 | 2918 | |
25dbc73a | 2919 | htab = ppc_elf_hash_table (info); |
3dab13f6 | 2920 | |
25dbc73a AM |
2921 | if (htab->got == NULL |
2922 | && !ppc_elf_create_got (abfd, info)) | |
3dab13f6 AM |
2923 | return FALSE; |
2924 | ||
25dbc73a AM |
2925 | if (!_bfd_elf_create_dynamic_sections (abfd, info)) |
2926 | return FALSE; | |
3dab13f6 | 2927 | |
e054468f AM |
2928 | if (htab->glink == NULL |
2929 | && !ppc_elf_create_glink (abfd, info)) | |
d7128ce4 | 2930 | return FALSE; |
3dab13f6 | 2931 | |
25dbc73a | 2932 | htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss"); |
3b36f7e6 AM |
2933 | s = bfd_make_section_with_flags (abfd, ".dynsbss", |
2934 | SEC_ALLOC | SEC_LINKER_CREATED); | |
2935 | htab->dynsbss = s; | |
3496cb2a | 2936 | if (s == NULL) |
25dbc73a | 2937 | return FALSE; |
3dab13f6 | 2938 | |
25dbc73a AM |
2939 | if (! info->shared) |
2940 | { | |
2941 | htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss"); | |
e054468f AM |
2942 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS |
2943 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
d7128ce4 | 2944 | s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags); |
3b36f7e6 | 2945 | htab->relsbss = s; |
25dbc73a | 2946 | if (s == NULL |
25dbc73a AM |
2947 | || ! bfd_set_section_alignment (abfd, s, 2)) |
2948 | return FALSE; | |
2949 | } | |
3dab13f6 | 2950 | |
711de32c RS |
2951 | if (htab->is_vxworks |
2952 | && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2)) | |
2953 | return FALSE; | |
9d8504b1 | 2954 | |
25dbc73a AM |
2955 | htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt"); |
2956 | htab->plt = s = bfd_get_section_by_name (abfd, ".plt"); | |
2957 | if (s == NULL) | |
2958 | abort (); | |
3dab13f6 | 2959 | |
3b36f7e6 | 2960 | flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED; |
4a3dc543 RS |
2961 | if (htab->plt_type == PLT_VXWORKS) |
2962 | /* The VxWorks PLT is a loaded section with contents. */ | |
2963 | flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY; | |
25dbc73a AM |
2964 | return bfd_set_section_flags (abfd, s, flags); |
2965 | } | |
3dab13f6 | 2966 | |
25dbc73a | 2967 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
58111eb7 | 2968 | |
25dbc73a | 2969 | static void |
fcfa13d2 | 2970 | ppc_elf_copy_indirect_symbol (struct bfd_link_info *info, |
25dbc73a AM |
2971 | struct elf_link_hash_entry *dir, |
2972 | struct elf_link_hash_entry *ind) | |
2973 | { | |
2974 | struct ppc_elf_link_hash_entry *edir, *eind; | |
3dab13f6 | 2975 | |
25dbc73a AM |
2976 | edir = (struct ppc_elf_link_hash_entry *) dir; |
2977 | eind = (struct ppc_elf_link_hash_entry *) ind; | |
3dab13f6 | 2978 | |
25dbc73a AM |
2979 | if (eind->dyn_relocs != NULL) |
2980 | { | |
2981 | if (edir->dyn_relocs != NULL) | |
3dab13f6 | 2982 | { |
25dbc73a AM |
2983 | struct ppc_elf_dyn_relocs **pp; |
2984 | struct ppc_elf_dyn_relocs *p; | |
3dab13f6 | 2985 | |
fcfa13d2 | 2986 | /* Add reloc counts against the indirect sym to the direct sym |
25dbc73a AM |
2987 | list. Merge any entries against the same section. */ |
2988 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3dab13f6 | 2989 | { |
25dbc73a AM |
2990 | struct ppc_elf_dyn_relocs *q; |
2991 | ||
2992 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
2993 | if (q->sec == p->sec) | |
2994 | { | |
2995 | q->pc_count += p->pc_count; | |
2996 | q->count += p->count; | |
2997 | *pp = p->next; | |
2998 | break; | |
2999 | } | |
3000 | if (q == NULL) | |
3001 | pp = &p->next; | |
3dab13f6 | 3002 | } |
25dbc73a | 3003 | *pp = edir->dyn_relocs; |
3dab13f6 | 3004 | } |
25dbc73a AM |
3005 | |
3006 | edir->dyn_relocs = eind->dyn_relocs; | |
3007 | eind->dyn_relocs = NULL; | |
3dab13f6 | 3008 | } |
3dab13f6 | 3009 | |
25dbc73a | 3010 | edir->tls_mask |= eind->tls_mask; |
4dc4a9a5 | 3011 | edir->has_sda_refs |= eind->has_sda_refs; |
3dab13f6 | 3012 | |
a6aa5195 AM |
3013 | /* If called to transfer flags for a weakdef during processing |
3014 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |
3015 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3016 | if (!(ELIMINATE_COPY_RELOCS | |
3017 | && eind->elf.root.type != bfd_link_hash_indirect | |
3018 | && edir->elf.dynamic_adjusted)) | |
3019 | edir->elf.non_got_ref |= eind->elf.non_got_ref; | |
3020 | ||
3021 | edir->elf.ref_dynamic |= eind->elf.ref_dynamic; | |
3022 | edir->elf.ref_regular |= eind->elf.ref_regular; | |
3023 | edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak; | |
3024 | edir->elf.needs_plt |= eind->elf.needs_plt; | |
0eb4a168 | 3025 | edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed; |
a6aa5195 AM |
3026 | |
3027 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3028 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3029 | return; | |
3030 | ||
3031 | /* Copy over the GOT refcount entries that we may have already seen to | |
3032 | the symbol which just became indirect. */ | |
fcfa13d2 AM |
3033 | edir->elf.got.refcount += eind->elf.got.refcount; |
3034 | eind->elf.got.refcount = 0; | |
a6aa5195 AM |
3035 | |
3036 | /* And plt entries. */ | |
3037 | if (eind->elf.plt.plist != NULL) | |
3038 | { | |
3039 | if (edir->elf.plt.plist != NULL) | |
3040 | { | |
3041 | struct plt_entry **entp; | |
3042 | struct plt_entry *ent; | |
3043 | ||
3044 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3045 | { | |
3046 | struct plt_entry *dent; | |
3047 | ||
3048 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3049 | if (dent->sec == ent->sec && dent->addend == ent->addend) | |
3050 | { | |
3051 | dent->plt.refcount += ent->plt.refcount; | |
3052 | *entp = ent->next; | |
3053 | break; | |
3054 | } | |
3055 | if (dent == NULL) | |
3056 | entp = &ent->next; | |
3057 | } | |
3058 | *entp = edir->elf.plt.plist; | |
3059 | } | |
3060 | ||
3061 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3062 | eind->elf.plt.plist = NULL; | |
3063 | } | |
3064 | ||
fcfa13d2 | 3065 | if (eind->elf.dynindx != -1) |
25dbc73a | 3066 | { |
fcfa13d2 AM |
3067 | if (edir->elf.dynindx != -1) |
3068 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
3069 | edir->elf.dynstr_index); | |
a6aa5195 AM |
3070 | edir->elf.dynindx = eind->elf.dynindx; |
3071 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3072 | eind->elf.dynindx = -1; | |
3073 | eind->elf.dynstr_index = 0; | |
25dbc73a | 3074 | } |
25dbc73a | 3075 | } |
3dab13f6 | 3076 | |
25dbc73a AM |
3077 | /* Hook called by the linker routine which adds symbols from an object |
3078 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
58111eb7 | 3079 | |
25dbc73a AM |
3080 | static bfd_boolean |
3081 | ppc_elf_add_symbol_hook (bfd *abfd, | |
3082 | struct bfd_link_info *info, | |
3083 | Elf_Internal_Sym *sym, | |
3084 | const char **namep ATTRIBUTE_UNUSED, | |
3085 | flagword *flagsp ATTRIBUTE_UNUSED, | |
3086 | asection **secp, | |
3087 | bfd_vma *valp) | |
3088 | { | |
3089 | if (sym->st_shndx == SHN_COMMON | |
3090 | && !info->relocatable | |
0c8d6e5c AM |
3091 | && is_ppc_elf (info->output_bfd) |
3092 | && sym->st_size <= elf_gp_size (abfd)) | |
25dbc73a AM |
3093 | { |
3094 | /* Common symbols less than or equal to -G nn bytes are automatically | |
3095 | put into .sbss. */ | |
3096 | struct ppc_elf_link_hash_table *htab; | |
3dab13f6 | 3097 | |
25dbc73a AM |
3098 | htab = ppc_elf_hash_table (info); |
3099 | if (htab->sbss == NULL) | |
3100 | { | |
644285ef | 3101 | flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED; |
3dab13f6 | 3102 | |
644285ef AM |
3103 | if (!htab->elf.dynobj) |
3104 | htab->elf.dynobj = abfd; | |
3105 | ||
3496cb2a L |
3106 | htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
3107 | ".sbss", | |
3108 | flags); | |
3109 | if (htab->sbss == NULL) | |
25dbc73a | 3110 | return FALSE; |
3dab13f6 | 3111 | } |
3dab13f6 | 3112 | |
25dbc73a AM |
3113 | *secp = htab->sbss; |
3114 | *valp = sym->st_size; | |
3115 | } | |
3dab13f6 | 3116 | |
c16153ae L |
3117 | if ((abfd->flags & DYNAMIC) == 0 |
3118 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
e054468f AM |
3119 | elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE; |
3120 | ||
25dbc73a | 3121 | return TRUE; |
3dab13f6 AM |
3122 | } |
3123 | \f | |
046183de | 3124 | static bfd_boolean |
bd6c6e2b | 3125 | create_sdata_sym (struct bfd_link_info *info, elf_linker_section_t *lsect) |
046183de | 3126 | { |
bd6c6e2b AM |
3127 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); |
3128 | ||
046183de AM |
3129 | lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name, |
3130 | TRUE, FALSE, TRUE); | |
3131 | if (lsect->sym == NULL) | |
3132 | return FALSE; | |
3133 | if (lsect->sym->root.type == bfd_link_hash_new) | |
3134 | lsect->sym->non_elf = 0; | |
3135 | lsect->sym->ref_regular = 1; | |
bd6c6e2b | 3136 | _bfd_elf_link_hash_hide_symbol (info, lsect->sym, TRUE); |
046183de AM |
3137 | return TRUE; |
3138 | } | |
3139 | ||
c9a2f333 | 3140 | /* Create a special linker section. */ |
25dbc73a | 3141 | |
c9a2f333 | 3142 | static bfd_boolean |
55fd94b0 AM |
3143 | ppc_elf_create_linker_section (bfd *abfd, |
3144 | struct bfd_link_info *info, | |
c9a2f333 AM |
3145 | flagword flags, |
3146 | elf_linker_section_t *lsect) | |
252b5132 | 3147 | { |
58111eb7 | 3148 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); |
c9a2f333 | 3149 | asection *s; |
58111eb7 | 3150 | |
c9a2f333 AM |
3151 | flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
3152 | | SEC_LINKER_CREATED); | |
58111eb7 AM |
3153 | |
3154 | /* Record the first bfd that needs the special sections. */ | |
3155 | if (!htab->elf.dynobj) | |
3156 | htab->elf.dynobj = abfd; | |
3157 | ||
3496cb2a L |
3158 | s = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
3159 | lsect->name, | |
3160 | flags); | |
76750a2f | 3161 | if (s == NULL |
76750a2f | 3162 | || !bfd_set_section_alignment (htab->elf.dynobj, s, 2)) |
c9a2f333 | 3163 | return FALSE; |
76750a2f | 3164 | lsect->section = s; |
58111eb7 | 3165 | |
bd6c6e2b | 3166 | return create_sdata_sym (info, lsect); |
252b5132 | 3167 | } |
252b5132 | 3168 | |
25dbc73a AM |
3169 | /* Find a linker generated pointer with a given addend and type. */ |
3170 | ||
3171 | static elf_linker_section_pointers_t * | |
3172 | elf_find_pointer_linker_section | |
3173 | (elf_linker_section_pointers_t *linker_pointers, | |
3174 | bfd_vma addend, | |
3175 | elf_linker_section_t *lsect) | |
252b5132 | 3176 | { |
25dbc73a AM |
3177 | for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next) |
3178 | if (lsect == linker_pointers->lsect && addend == linker_pointers->addend) | |
3179 | return linker_pointers; | |
252b5132 | 3180 | |
25dbc73a AM |
3181 | return NULL; |
3182 | } | |
3183 | ||
3184 | /* Allocate a pointer to live in a linker created section. */ | |
3185 | ||
3186 | static bfd_boolean | |
3187 | elf_create_pointer_linker_section (bfd *abfd, | |
25dbc73a AM |
3188 | elf_linker_section_t *lsect, |
3189 | struct elf_link_hash_entry *h, | |
3190 | const Elf_Internal_Rela *rel) | |
3191 | { | |
3192 | elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL; | |
3193 | elf_linker_section_pointers_t *linker_section_ptr; | |
3194 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
3195 | bfd_size_type amt; | |
3196 | ||
3197 | BFD_ASSERT (lsect != NULL); | |
3198 | ||
3199 | /* Is this a global symbol? */ | |
3200 | if (h != NULL) | |
3201 | { | |
3202 | struct ppc_elf_link_hash_entry *eh; | |
3203 | ||
3204 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3205 | eh = (struct ppc_elf_link_hash_entry *) h; | |
3206 | if (elf_find_pointer_linker_section (eh->linker_section_pointer, | |
3207 | rel->r_addend, | |
3208 | lsect)) | |
3209 | return TRUE; | |
3210 | ||
3211 | ptr_linker_section_ptr = &eh->linker_section_pointer; | |
25dbc73a AM |
3212 | } |
3213 | else | |
3214 | { | |
0c8d6e5c | 3215 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 3216 | |
25dbc73a AM |
3217 | /* Allocation of a pointer to a local symbol. */ |
3218 | elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); | |
3219 | ||
3220 | /* Allocate a table to hold the local symbols if first time. */ | |
3221 | if (!ptr) | |
3222 | { | |
0ffa91dd | 3223 | unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info; |
25dbc73a AM |
3224 | |
3225 | amt = num_symbols; | |
3226 | amt *= sizeof (elf_linker_section_pointers_t *); | |
3227 | ptr = bfd_zalloc (abfd, amt); | |
3228 | ||
3229 | if (!ptr) | |
3230 | return FALSE; | |
3231 | ||
3232 | elf_local_ptr_offsets (abfd) = ptr; | |
3233 | } | |
3234 | ||
3235 | /* Has this symbol already been allocated? If so, our work is done. */ | |
3236 | if (elf_find_pointer_linker_section (ptr[r_symndx], | |
3237 | rel->r_addend, | |
3238 | lsect)) | |
3239 | return TRUE; | |
252b5132 | 3240 | |
25dbc73a | 3241 | ptr_linker_section_ptr = &ptr[r_symndx]; |
25dbc73a | 3242 | } |
41fcb14e | 3243 | |
25dbc73a AM |
3244 | /* Allocate space for a pointer in the linker section, and allocate |
3245 | a new pointer record from internal memory. */ | |
3246 | BFD_ASSERT (ptr_linker_section_ptr != NULL); | |
3247 | amt = sizeof (elf_linker_section_pointers_t); | |
3248 | linker_section_ptr = bfd_alloc (abfd, amt); | |
41fcb14e | 3249 | |
25dbc73a | 3250 | if (!linker_section_ptr) |
7619e7c7 | 3251 | return FALSE; |
41fcb14e | 3252 | |
25dbc73a AM |
3253 | linker_section_ptr->next = *ptr_linker_section_ptr; |
3254 | linker_section_ptr->addend = rel->r_addend; | |
3255 | linker_section_ptr->lsect = lsect; | |
25dbc73a | 3256 | *ptr_linker_section_ptr = linker_section_ptr; |
41fcb14e | 3257 | |
25dbc73a AM |
3258 | linker_section_ptr->offset = lsect->section->size; |
3259 | lsect->section->size += 4; | |
7619e7c7 | 3260 | |
25dbc73a AM |
3261 | #ifdef DEBUG |
3262 | fprintf (stderr, | |
3263 | "Create pointer in linker section %s, offset = %ld, section size = %ld\n", | |
3264 | lsect->name, (long) linker_section_ptr->offset, | |
3265 | (long) lsect->section->size); | |
3266 | #endif | |
7619e7c7 AM |
3267 | |
3268 | return TRUE; | |
41fcb14e AM |
3269 | } |
3270 | ||
e054468f | 3271 | static struct plt_entry ** |
25dbc73a AM |
3272 | update_local_sym_info (bfd *abfd, |
3273 | Elf_Internal_Shdr *symtab_hdr, | |
3274 | unsigned long r_symndx, | |
3275 | int tls_type) | |
252b5132 | 3276 | { |
25dbc73a | 3277 | bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd); |
e054468f | 3278 | struct plt_entry **local_plt; |
25dbc73a | 3279 | char *local_got_tls_masks; |
252b5132 | 3280 | |
25dbc73a | 3281 | if (local_got_refcounts == NULL) |
252b5132 | 3282 | { |
25dbc73a AM |
3283 | bfd_size_type size = symtab_hdr->sh_info; |
3284 | ||
e054468f AM |
3285 | size *= (sizeof (*local_got_refcounts) |
3286 | + sizeof (*local_plt) | |
3287 | + sizeof (*local_got_tls_masks)); | |
25dbc73a AM |
3288 | local_got_refcounts = bfd_zalloc (abfd, size); |
3289 | if (local_got_refcounts == NULL) | |
e054468f | 3290 | return NULL; |
25dbc73a | 3291 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 3292 | } |
41fcb14e | 3293 | |
e054468f AM |
3294 | local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info); |
3295 | local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
25dbc73a | 3296 | local_got_tls_masks[r_symndx] |= tls_type; |
e054468f AM |
3297 | if (tls_type != PLT_IFUNC) |
3298 | local_got_refcounts[r_symndx] += 1; | |
3299 | return local_plt + r_symndx; | |
25dbc73a | 3300 | } |
41fcb14e | 3301 | |
a6aa5195 | 3302 | static bfd_boolean |
3ec01793 | 3303 | update_plt_info (bfd *abfd, struct plt_entry **plist, |
a6aa5195 AM |
3304 | asection *sec, bfd_vma addend) |
3305 | { | |
3306 | struct plt_entry *ent; | |
3307 | ||
32af9f6e AM |
3308 | if (addend < 32768) |
3309 | sec = NULL; | |
3ec01793 | 3310 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3311 | if (ent->sec == sec && ent->addend == addend) |
3312 | break; | |
3313 | if (ent == NULL) | |
3314 | { | |
3315 | bfd_size_type amt = sizeof (*ent); | |
3316 | ent = bfd_alloc (abfd, amt); | |
3317 | if (ent == NULL) | |
3318 | return FALSE; | |
3ec01793 | 3319 | ent->next = *plist; |
a6aa5195 AM |
3320 | ent->sec = sec; |
3321 | ent->addend = addend; | |
3322 | ent->plt.refcount = 0; | |
3ec01793 | 3323 | *plist = ent; |
a6aa5195 AM |
3324 | } |
3325 | ent->plt.refcount += 1; | |
3326 | return TRUE; | |
3327 | } | |
3328 | ||
3329 | static struct plt_entry * | |
3ec01793 | 3330 | find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend) |
a6aa5195 AM |
3331 | { |
3332 | struct plt_entry *ent; | |
3333 | ||
3334 | if (addend < 32768) | |
3335 | sec = NULL; | |
3ec01793 | 3336 | for (ent = *plist; ent != NULL; ent = ent->next) |
a6aa5195 AM |
3337 | if (ent->sec == sec && ent->addend == addend) |
3338 | break; | |
3339 | return ent; | |
3340 | } | |
3341 | ||
e054468f AM |
3342 | static bfd_boolean |
3343 | is_branch_reloc (enum elf_ppc_reloc_type r_type) | |
3344 | { | |
3345 | return (r_type == R_PPC_PLTREL24 | |
3346 | || r_type == R_PPC_LOCAL24PC | |
3347 | || r_type == R_PPC_REL24 | |
3348 | || r_type == R_PPC_REL14 | |
3349 | || r_type == R_PPC_REL14_BRTAKEN | |
3350 | || r_type == R_PPC_REL14_BRNTAKEN | |
3351 | || r_type == R_PPC_ADDR24 | |
3352 | || r_type == R_PPC_ADDR14 | |
3353 | || r_type == R_PPC_ADDR14_BRTAKEN | |
3354 | || r_type == R_PPC_ADDR14_BRNTAKEN); | |
3355 | } | |
3356 | ||
25dbc73a AM |
3357 | static void |
3358 | bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type) | |
3359 | { | |
3360 | (*_bfd_error_handler) | |
3361 | (_("%B: relocation %s cannot be used when making a shared object"), | |
3362 | abfd, | |
3363 | ppc_elf_howto_table[r_type]->name); | |
3364 | bfd_set_error (bfd_error_bad_value); | |
252b5132 RH |
3365 | } |
3366 | ||
25dbc73a AM |
3367 | /* Look through the relocs for a section during the first phase, and |
3368 | allocate space in the global offset table or procedure linkage | |
3369 | table. */ | |
252b5132 | 3370 | |
b34976b6 | 3371 | static bfd_boolean |
25dbc73a AM |
3372 | ppc_elf_check_relocs (bfd *abfd, |
3373 | struct bfd_link_info *info, | |
3374 | asection *sec, | |
3375 | const Elf_Internal_Rela *relocs) | |
252b5132 | 3376 | { |
7619e7c7 | 3377 | struct ppc_elf_link_hash_table *htab; |
25dbc73a AM |
3378 | Elf_Internal_Shdr *symtab_hdr; |
3379 | struct elf_link_hash_entry **sym_hashes; | |
3380 | const Elf_Internal_Rela *rel; | |
3381 | const Elf_Internal_Rela *rel_end; | |
a6aa5195 | 3382 | asection *got2, *sreloc; |
727fc41e | 3383 | struct elf_link_hash_entry *tga; |
25dbc73a AM |
3384 | |
3385 | if (info->relocatable) | |
3386 | return TRUE; | |
252b5132 | 3387 | |
c87b5a93 AM |
3388 | /* Don't do anything special with non-loaded, non-alloced sections. |
3389 | In particular, any relocs in such sections should not affect GOT | |
3390 | and PLT reference counting (ie. we don't allow them to create GOT | |
3391 | or PLT entries), there's no possibility or desire to optimize TLS | |
3392 | relocs, and there's not much point in propagating relocs to shared | |
3393 | libs that the dynamic linker won't relocate. */ | |
3394 | if ((sec->flags & SEC_ALLOC) == 0) | |
3395 | return TRUE; | |
3396 | ||
252b5132 | 3397 | #ifdef DEBUG |
25dbc73a AM |
3398 | _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B", |
3399 | sec, abfd); | |
252b5132 RH |
3400 | #endif |
3401 | ||
0c8d6e5c | 3402 | BFD_ASSERT (is_ppc_elf (abfd)); |
0ffa91dd | 3403 | |
25dbc73a AM |
3404 | /* Initialize howto table if not already done. */ |
3405 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
3406 | ppc_elf_howto_init (); | |
3407 | ||
7619e7c7 | 3408 | htab = ppc_elf_hash_table (info); |
25f23106 AM |
3409 | if (htab->glink == NULL) |
3410 | { | |
3411 | if (htab->elf.dynobj == NULL) | |
3412 | htab->elf.dynobj = abfd; | |
3413 | if (!ppc_elf_create_glink (htab->elf.dynobj, info)) | |
3414 | return FALSE; | |
3415 | } | |
727fc41e AM |
3416 | tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
3417 | FALSE, FALSE, TRUE); | |
0ffa91dd | 3418 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a | 3419 | sym_hashes = elf_sym_hashes (abfd); |
a6aa5195 | 3420 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
3421 | sreloc = NULL; |
3422 | ||
3423 | rel_end = relocs + sec->reloc_count; | |
3424 | for (rel = relocs; rel < rel_end; rel++) | |
3425 | { | |
3426 | unsigned long r_symndx; | |
3427 | enum elf_ppc_reloc_type r_type; | |
3428 | struct elf_link_hash_entry *h; | |
727fc41e | 3429 | int tls_type; |
25dbc73a AM |
3430 | |
3431 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3432 | if (r_symndx < symtab_hdr->sh_info) | |
3433 | h = NULL; | |
3434 | else | |
973a3492 L |
3435 | { |
3436 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3437 | while (h->root.type == bfd_link_hash_indirect | |
3438 | || h->root.type == bfd_link_hash_warning) | |
3439 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3440 | } | |
25dbc73a AM |
3441 | |
3442 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. | |
3443 | This shows up in particular in an R_PPC_ADDR32 in the eabi | |
3444 | startup code. */ | |
3b36f7e6 AM |
3445 | if (h != NULL |
3446 | && htab->got == NULL | |
3447 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
252b5132 | 3448 | { |
3b36f7e6 AM |
3449 | if (htab->elf.dynobj == NULL) |
3450 | htab->elf.dynobj = abfd; | |
3451 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
3452 | return FALSE; | |
3453 | BFD_ASSERT (h == htab->elf.hgot); | |
25dbc73a | 3454 | } |
252b5132 | 3455 | |
727fc41e | 3456 | tls_type = 0; |
de972ffa | 3457 | r_type = ELF32_R_TYPE (rel->r_info); |
06a162cf | 3458 | if (h == NULL && !htab->is_vxworks) |
e054468f | 3459 | { |
06a162cf AM |
3460 | Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3461 | abfd, r_symndx); | |
3462 | if (isym == NULL) | |
3463 | return FALSE; | |
3464 | ||
3465 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC | |
3466 | && (!info->shared | |
3467 | || is_branch_reloc (r_type))) | |
e054468f | 3468 | { |
06a162cf AM |
3469 | struct plt_entry **ifunc; |
3470 | bfd_vma addend; | |
3471 | ||
3472 | ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3473 | PLT_IFUNC); | |
3474 | if (ifunc == NULL) | |
e054468f AM |
3475 | return FALSE; |
3476 | ||
06a162cf AM |
3477 | /* STT_GNU_IFUNC symbols must have a PLT entry; |
3478 | In a non-pie executable even when there are | |
3479 | no plt calls. */ | |
3480 | addend = 0; | |
3481 | if (r_type == R_PPC_PLTREL24) | |
e054468f | 3482 | { |
06a162cf AM |
3483 | ppc_elf_tdata (abfd)->makes_plt_call = 1; |
3484 | if (info->shared) | |
3485 | addend = rel->r_addend; | |
e054468f | 3486 | } |
06a162cf AM |
3487 | if (!update_plt_info (abfd, ifunc, got2, addend)) |
3488 | return FALSE; | |
e054468f | 3489 | } |
25f23106 AM |
3490 | } |
3491 | ||
de972ffa AM |
3492 | if (!htab->is_vxworks |
3493 | && is_branch_reloc (r_type) | |
3494 | && h != NULL | |
3495 | && h == tga) | |
25f23106 | 3496 | { |
de972ffa AM |
3497 | if (rel != relocs |
3498 | && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD | |
3499 | || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD)) | |
3500 | /* We have a new-style __tls_get_addr call with a marker | |
3501 | reloc. */ | |
3502 | ; | |
3503 | else | |
3504 | /* Mark this section as having an old-style call. */ | |
3505 | sec->has_tls_get_addr_call = 1; | |
e054468f | 3506 | } |
727fc41e | 3507 | |
25dbc73a AM |
3508 | switch (r_type) |
3509 | { | |
727fc41e AM |
3510 | case R_PPC_TLSGD: |
3511 | case R_PPC_TLSLD: | |
3512 | /* These special tls relocs tie a call to __tls_get_addr with | |
3513 | its parameter symbol. */ | |
3514 | break; | |
3515 | ||
25dbc73a AM |
3516 | case R_PPC_GOT_TLSLD16: |
3517 | case R_PPC_GOT_TLSLD16_LO: | |
3518 | case R_PPC_GOT_TLSLD16_HI: | |
3519 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
3520 | tls_type = TLS_TLS | TLS_LD; |
3521 | goto dogottls; | |
252b5132 | 3522 | |
25dbc73a AM |
3523 | case R_PPC_GOT_TLSGD16: |
3524 | case R_PPC_GOT_TLSGD16_LO: | |
3525 | case R_PPC_GOT_TLSGD16_HI: | |
3526 | case R_PPC_GOT_TLSGD16_HA: | |
3527 | tls_type = TLS_TLS | TLS_GD; | |
3528 | goto dogottls; | |
3529 | ||
3530 | case R_PPC_GOT_TPREL16: | |
3531 | case R_PPC_GOT_TPREL16_LO: | |
3532 | case R_PPC_GOT_TPREL16_HI: | |
3533 | case R_PPC_GOT_TPREL16_HA: | |
1d483afe | 3534 | if (!info->executable) |
25dbc73a AM |
3535 | info->flags |= DF_STATIC_TLS; |
3536 | tls_type = TLS_TLS | TLS_TPREL; | |
3537 | goto dogottls; | |
3538 | ||
3539 | case R_PPC_GOT_DTPREL16: | |
3540 | case R_PPC_GOT_DTPREL16_LO: | |
3541 | case R_PPC_GOT_DTPREL16_HI: | |
3542 | case R_PPC_GOT_DTPREL16_HA: | |
3543 | tls_type = TLS_TLS | TLS_DTPREL; | |
3544 | dogottls: | |
3545 | sec->has_tls_reloc = 1; | |
3546 | /* Fall thru */ | |
252b5132 | 3547 | |
25dbc73a AM |
3548 | /* GOT16 relocations */ |
3549 | case R_PPC_GOT16: | |
3550 | case R_PPC_GOT16_LO: | |
3551 | case R_PPC_GOT16_HI: | |
3552 | case R_PPC_GOT16_HA: | |
3553 | /* This symbol requires a global offset table entry. */ | |
3554 | if (htab->got == NULL) | |
3555 | { | |
3556 | if (htab->elf.dynobj == NULL) | |
3557 | htab->elf.dynobj = abfd; | |
3558 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
3559 | return FALSE; | |
3560 | } | |
3561 | if (h != NULL) | |
3562 | { | |
3563 | h->got.refcount += 1; | |
3564 | ppc_elf_hash_entry (h)->tls_mask |= tls_type; | |
3565 | } | |
3566 | else | |
3567 | /* This is a global offset table entry for a local symbol. */ | |
3568 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)) | |
3569 | return FALSE; | |
91e21fb7 AM |
3570 | |
3571 | /* We may also need a plt entry if the symbol turns out to be | |
3572 | an ifunc. */ | |
3573 | if (h != NULL && !info->shared) | |
3574 | { | |
3575 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) | |
3576 | return FALSE; | |
3577 | } | |
25dbc73a | 3578 | break; |
252b5132 | 3579 | |
25dbc73a AM |
3580 | /* Indirect .sdata relocation. */ |
3581 | case R_PPC_EMB_SDAI16: | |
3582 | if (info->shared) | |
3583 | { | |
3584 | bad_shared_reloc (abfd, r_type); | |
3585 | return FALSE; | |
3586 | } | |
c9a2f333 AM |
3587 | if (htab->sdata[0].section == NULL |
3588 | && !ppc_elf_create_linker_section (abfd, info, 0, | |
3589 | &htab->sdata[0])) | |
3590 | return FALSE; | |
76750a2f AM |
3591 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0], |
3592 | h, rel)) | |
25dbc73a | 3593 | return FALSE; |
046183de AM |
3594 | if (h != NULL) |
3595 | { | |
3596 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3597 | h->non_got_ref = TRUE; | |
3598 | } | |
25dbc73a | 3599 | break; |
252b5132 | 3600 | |
25dbc73a AM |
3601 | /* Indirect .sdata2 relocation. */ |
3602 | case R_PPC_EMB_SDA2I16: | |
3603 | if (info->shared) | |
3604 | { | |
3605 | bad_shared_reloc (abfd, r_type); | |
3606 | return FALSE; | |
3607 | } | |
c9a2f333 AM |
3608 | if (htab->sdata[1].section == NULL |
3609 | && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY, | |
3610 | &htab->sdata[1])) | |
3611 | return FALSE; | |
76750a2f AM |
3612 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1], |
3613 | h, rel)) | |
25dbc73a | 3614 | return FALSE; |
046183de AM |
3615 | if (h != NULL) |
3616 | { | |
3617 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3618 | h->non_got_ref = TRUE; | |
3619 | } | |
25dbc73a | 3620 | break; |
252b5132 | 3621 | |
25dbc73a | 3622 | case R_PPC_SDAREL16: |
046183de | 3623 | if (htab->sdata[0].sym == NULL |
bd6c6e2b | 3624 | && !create_sdata_sym (info, &htab->sdata[0])) |
046183de AM |
3625 | return FALSE; |
3626 | if (h != NULL) | |
3627 | { | |
3628 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3629 | h->non_got_ref = TRUE; | |
3630 | } | |
3631 | break; | |
3632 | ||
25dbc73a | 3633 | case R_PPC_EMB_SDA2REL: |
046183de AM |
3634 | if (info->shared) |
3635 | { | |
3636 | bad_shared_reloc (abfd, r_type); | |
3637 | return FALSE; | |
3638 | } | |
3639 | if (htab->sdata[1].sym == NULL | |
bd6c6e2b | 3640 | && !create_sdata_sym (info, &htab->sdata[1])) |
046183de AM |
3641 | return FALSE; |
3642 | if (h != NULL) | |
3643 | { | |
3644 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3645 | h->non_got_ref = TRUE; | |
3646 | } | |
3647 | break; | |
3648 | ||
25dbc73a AM |
3649 | case R_PPC_EMB_SDA21: |
3650 | case R_PPC_EMB_RELSDA: | |
046183de AM |
3651 | if (info->shared) |
3652 | { | |
3653 | bad_shared_reloc (abfd, r_type); | |
3654 | return FALSE; | |
3655 | } | |
3656 | if (htab->sdata[0].sym == NULL | |
bd6c6e2b | 3657 | && !create_sdata_sym (info, &htab->sdata[0])) |
046183de AM |
3658 | return FALSE; |
3659 | if (htab->sdata[1].sym == NULL | |
bd6c6e2b | 3660 | && !create_sdata_sym (info, &htab->sdata[1])) |
046183de AM |
3661 | return FALSE; |
3662 | if (h != NULL) | |
3663 | { | |
3664 | ppc_elf_hash_entry (h)->has_sda_refs = TRUE; | |
3665 | h->non_got_ref = TRUE; | |
3666 | } | |
3667 | break; | |
3668 | ||
25dbc73a AM |
3669 | case R_PPC_EMB_NADDR32: |
3670 | case R_PPC_EMB_NADDR16: | |
3671 | case R_PPC_EMB_NADDR16_LO: | |
3672 | case R_PPC_EMB_NADDR16_HI: | |
3673 | case R_PPC_EMB_NADDR16_HA: | |
3674 | if (info->shared) | |
3675 | { | |
3676 | bad_shared_reloc (abfd, r_type); | |
3677 | return FALSE; | |
3678 | } | |
4dc4a9a5 | 3679 | if (h != NULL) |
046183de | 3680 | h->non_got_ref = TRUE; |
25dbc73a | 3681 | break; |
252b5132 | 3682 | |
25dbc73a | 3683 | case R_PPC_PLTREL24: |
de972ffa | 3684 | if (h == NULL) |
6d78d0b9 AM |
3685 | break; |
3686 | /* Fall through */ | |
3687 | case R_PPC_PLT32: | |
25dbc73a AM |
3688 | case R_PPC_PLTREL32: |
3689 | case R_PPC_PLT16_LO: | |
3690 | case R_PPC_PLT16_HI: | |
3691 | case R_PPC_PLT16_HA: | |
3692 | #ifdef DEBUG | |
3693 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
3694 | #endif | |
3695 | /* This symbol requires a procedure linkage table entry. We | |
3696 | actually build the entry in finish_dynamic_symbol, | |
3697 | because this might be a case of linking PIC code without | |
3698 | linking in any dynamic objects, in which case we don't | |
3699 | need to generate a procedure linkage table after all. */ | |
7619e7c7 | 3700 | |
25dbc73a AM |
3701 | if (h == NULL) |
3702 | { | |
3703 | /* It does not make sense to have a procedure linkage | |
3704 | table entry for a local symbol. */ | |
3705 | (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against " | |
3706 | "local symbol"), | |
3707 | abfd, | |
3708 | sec, | |
3709 | (long) rel->r_offset, | |
3710 | ppc_elf_howto_table[r_type]->name); | |
3711 | bfd_set_error (bfd_error_bad_value); | |
3712 | return FALSE; | |
3713 | } | |
a6aa5195 AM |
3714 | else |
3715 | { | |
016687f8 | 3716 | bfd_vma addend = 0; |
ee05f2fe | 3717 | |
016687f8 AM |
3718 | if (r_type == R_PPC_PLTREL24) |
3719 | { | |
3720 | ppc_elf_tdata (abfd)->makes_plt_call = 1; | |
a877a2b6 AM |
3721 | if (info->shared) |
3722 | addend = rel->r_addend; | |
016687f8 | 3723 | } |
a6aa5195 | 3724 | h->needs_plt = 1; |
32af9f6e | 3725 | if (!update_plt_info (abfd, &h->plt.plist, got2, addend)) |
a6aa5195 AM |
3726 | return FALSE; |
3727 | } | |
25dbc73a | 3728 | break; |
ee05f2fe | 3729 | |
25dbc73a AM |
3730 | /* The following relocations don't need to propagate the |
3731 | relocation if linking a shared object since they are | |
3732 | section relative. */ | |
3733 | case R_PPC_SECTOFF: | |
3734 | case R_PPC_SECTOFF_LO: | |
3735 | case R_PPC_SECTOFF_HI: | |
3736 | case R_PPC_SECTOFF_HA: | |
3737 | case R_PPC_DTPREL16: | |
3738 | case R_PPC_DTPREL16_LO: | |
3739 | case R_PPC_DTPREL16_HI: | |
3740 | case R_PPC_DTPREL16_HA: | |
3741 | case R_PPC_TOC16: | |
3742 | break; | |
252b5132 | 3743 | |
d7128ce4 AM |
3744 | case R_PPC_REL16: |
3745 | case R_PPC_REL16_LO: | |
3746 | case R_PPC_REL16_HI: | |
3747 | case R_PPC_REL16_HA: | |
016687f8 | 3748 | ppc_elf_tdata (abfd)->has_rel16 = 1; |
d7128ce4 AM |
3749 | break; |
3750 | ||
a6aa5195 | 3751 | /* These are just markers. */ |
25dbc73a AM |
3752 | case R_PPC_TLS: |
3753 | case R_PPC_EMB_MRKREF: | |
3754 | case R_PPC_NONE: | |
3755 | case R_PPC_max: | |
32af9f6e AM |
3756 | case R_PPC_RELAX: |
3757 | case R_PPC_RELAX_PLT: | |
3758 | case R_PPC_RELAX_PLTREL24: | |
25dbc73a | 3759 | break; |
252b5132 | 3760 | |
25dbc73a AM |
3761 | /* These should only appear in dynamic objects. */ |
3762 | case R_PPC_COPY: | |
3763 | case R_PPC_GLOB_DAT: | |
3764 | case R_PPC_JMP_SLOT: | |
3765 | case R_PPC_RELATIVE: | |
e054468f | 3766 | case R_PPC_IRELATIVE: |
25dbc73a | 3767 | break; |
252b5132 | 3768 | |
25dbc73a AM |
3769 | /* These aren't handled yet. We'll report an error later. */ |
3770 | case R_PPC_ADDR30: | |
3771 | case R_PPC_EMB_RELSEC16: | |
3772 | case R_PPC_EMB_RELST_LO: | |
3773 | case R_PPC_EMB_RELST_HI: | |
3774 | case R_PPC_EMB_RELST_HA: | |
3775 | case R_PPC_EMB_BIT_FLD: | |
3776 | break; | |
252b5132 | 3777 | |
25dbc73a AM |
3778 | /* This refers only to functions defined in the shared library. */ |
3779 | case R_PPC_LOCAL24PC: | |
727fc41e | 3780 | if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET) |
016687f8 AM |
3781 | { |
3782 | htab->plt_type = PLT_OLD; | |
3783 | htab->old_bfd = abfd; | |
3784 | } | |
25dbc73a | 3785 | break; |
252b5132 | 3786 | |
25dbc73a AM |
3787 | /* This relocation describes the C++ object vtable hierarchy. |
3788 | Reconstruct it for later use during GC. */ | |
3789 | case R_PPC_GNU_VTINHERIT: | |
3790 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
3791 | return FALSE; | |
3792 | break; | |
252b5132 | 3793 | |
25dbc73a AM |
3794 | /* This relocation describes which C++ vtable entries are actually |
3795 | used. Record for later use during GC. */ | |
3796 | case R_PPC_GNU_VTENTRY: | |
d17e0c6e JB |
3797 | BFD_ASSERT (h != NULL); |
3798 | if (h != NULL | |
3799 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
25dbc73a AM |
3800 | return FALSE; |
3801 | break; | |
252b5132 | 3802 | |
25dbc73a AM |
3803 | /* We shouldn't really be seeing these. */ |
3804 | case R_PPC_TPREL32: | |
1d483afe AM |
3805 | case R_PPC_TPREL16: |
3806 | case R_PPC_TPREL16_LO: | |
3807 | case R_PPC_TPREL16_HI: | |
3808 | case R_PPC_TPREL16_HA: | |
3809 | if (!info->executable) | |
25dbc73a AM |
3810 | info->flags |= DF_STATIC_TLS; |
3811 | goto dodyn; | |
252b5132 | 3812 | |
25dbc73a AM |
3813 | /* Nor these. */ |
3814 | case R_PPC_DTPMOD32: | |
3815 | case R_PPC_DTPREL32: | |
3816 | goto dodyn; | |
252b5132 | 3817 | |
9edfd1af AM |
3818 | case R_PPC_REL32: |
3819 | if (h == NULL | |
3820 | && got2 != NULL | |
3821 | && (sec->flags & SEC_CODE) != 0 | |
a877a2b6 | 3822 | && info->shared |
4a3dc543 | 3823 | && htab->plt_type == PLT_UNSET) |
9edfd1af AM |
3824 | { |
3825 | /* Old -fPIC gcc code has .long LCTOC1-LCFx just before | |
3826 | the start of a function, which assembles to a REL32 | |
3827 | reference to .got2. If we detect one of these, then | |
3828 | force the old PLT layout because the linker cannot | |
3829 | reliably deduce the GOT pointer value needed for | |
3830 | PLT call stubs. */ | |
3831 | asection *s; | |
87d72d41 | 3832 | Elf_Internal_Sym *isym; |
9edfd1af | 3833 | |
87d72d41 AM |
3834 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3835 | abfd, r_symndx); | |
3836 | if (isym == NULL) | |
3837 | return FALSE; | |
3838 | ||
3839 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
9edfd1af | 3840 | if (s == got2) |
016687f8 AM |
3841 | { |
3842 | htab->plt_type = PLT_OLD; | |
3843 | htab->old_bfd = abfd; | |
3844 | } | |
9edfd1af | 3845 | } |
7123df0e | 3846 | if (h == NULL || h == htab->elf.hgot) |
fd38b44c | 3847 | break; |
625af618 AM |
3848 | /* fall through */ |
3849 | ||
3850 | case R_PPC_ADDR32: | |
3851 | case R_PPC_ADDR16: | |
3852 | case R_PPC_ADDR16_LO: | |
3853 | case R_PPC_ADDR16_HI: | |
3854 | case R_PPC_ADDR16_HA: | |
3855 | case R_PPC_UADDR32: | |
3856 | case R_PPC_UADDR16: | |
3857 | if (h != NULL && !info->shared) | |
3858 | { | |
3859 | /* We may need a plt entry if the symbol turns out to be | |
3860 | a function defined in a dynamic object. */ | |
3ec01793 | 3861 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
625af618 AM |
3862 | return FALSE; |
3863 | ||
3864 | /* We may need a copy reloc too. */ | |
3865 | h->non_got_ref = 1; | |
3866 | h->pointer_equality_needed = 1; | |
3867 | } | |
3868 | goto dodyn; | |
9edfd1af | 3869 | |
25dbc73a AM |
3870 | case R_PPC_REL24: |
3871 | case R_PPC_REL14: | |
3872 | case R_PPC_REL14_BRTAKEN: | |
3873 | case R_PPC_REL14_BRNTAKEN: | |
d7128ce4 | 3874 | if (h == NULL) |
25dbc73a | 3875 | break; |
7123df0e | 3876 | if (h == htab->elf.hgot) |
d7128ce4 | 3877 | { |
7123df0e | 3878 | if (htab->plt_type == PLT_UNSET) |
016687f8 AM |
3879 | { |
3880 | htab->plt_type = PLT_OLD; | |
3881 | htab->old_bfd = abfd; | |
3882 | } | |
d7128ce4 AM |
3883 | break; |
3884 | } | |
25dbc73a | 3885 | /* fall through */ |
ee05f2fe | 3886 | |
25dbc73a | 3887 | case R_PPC_ADDR24: |
25dbc73a AM |
3888 | case R_PPC_ADDR14: |
3889 | case R_PPC_ADDR14_BRTAKEN: | |
3890 | case R_PPC_ADDR14_BRNTAKEN: | |
25dbc73a AM |
3891 | if (h != NULL && !info->shared) |
3892 | { | |
3893 | /* We may need a plt entry if the symbol turns out to be | |
3894 | a function defined in a dynamic object. */ | |
e054468f | 3895 | h->needs_plt = 1; |
de972ffa | 3896 | if (!update_plt_info (abfd, &h->plt.plist, NULL, 0)) |
a6aa5195 | 3897 | return FALSE; |
625af618 | 3898 | break; |
25dbc73a | 3899 | } |
7619e7c7 | 3900 | |
25dbc73a AM |
3901 | dodyn: |
3902 | /* If we are creating a shared library, and this is a reloc | |
3903 | against a global symbol, or a non PC relative reloc | |
3904 | against a local symbol, then we need to copy the reloc | |
3905 | into the shared library. However, if we are linking with | |
3906 | -Bsymbolic, we do not need to copy a reloc against a | |
3907 | global symbol which is defined in an object we are | |
3908 | including in the link (i.e., DEF_REGULAR is set). At | |
3909 | this point we have not seen all the input files, so it is | |
3910 | possible that DEF_REGULAR is not set now but will be set | |
3911 | later (it is never cleared). In case of a weak definition, | |
3912 | DEF_REGULAR may be cleared later by a strong definition in | |
3913 | a shared library. We account for that possibility below by | |
3914 | storing information in the dyn_relocs field of the hash | |
3915 | table entry. A similar situation occurs when creating | |
3916 | shared libraries and symbol visibility changes render the | |
3917 | symbol local. | |
7619e7c7 | 3918 | |
25dbc73a AM |
3919 | If on the other hand, we are creating an executable, we |
3920 | may need to keep relocations for symbols satisfied by a | |
3921 | dynamic library if we manage to avoid copy relocs for the | |
3922 | symbol. */ | |
3923 | if ((info->shared | |
1d483afe | 3924 | && (must_be_dyn_reloc (info, r_type) |
25dbc73a AM |
3925 | || (h != NULL |
3926 | && (! info->symbolic | |
3927 | || h->root.type == bfd_link_hash_defweak | |
3928 | || !h->def_regular)))) | |
3929 | || (ELIMINATE_COPY_RELOCS | |
3930 | && !info->shared | |
25dbc73a AM |
3931 | && h != NULL |
3932 | && (h->root.type == bfd_link_hash_defweak | |
de972ffa | 3933 | || !h->def_regular))) |
25dbc73a AM |
3934 | { |
3935 | struct ppc_elf_dyn_relocs *p; | |
91d6fa6a | 3936 | struct ppc_elf_dyn_relocs **rel_head; |
7619e7c7 | 3937 | |
25dbc73a AM |
3938 | #ifdef DEBUG |
3939 | fprintf (stderr, | |
3940 | "ppc_elf_check_relocs needs to " | |
3941 | "create relocation for %s\n", | |
3942 | (h && h->root.root.string | |
3943 | ? h->root.root.string : "<unknown>")); | |
3944 | #endif | |
3945 | if (sreloc == NULL) | |
3946 | { | |
c9a2f333 AM |
3947 | if (htab->elf.dynobj == NULL) |
3948 | htab->elf.dynobj = abfd; | |
83bac4b0 NC |
3949 | |
3950 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
3951 | (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE); | |
3952 | ||
25dbc73a | 3953 | if (sreloc == NULL) |
83bac4b0 | 3954 | return FALSE; |
25dbc73a | 3955 | } |
7619e7c7 | 3956 | |
25dbc73a AM |
3957 | /* If this is a global symbol, we count the number of |
3958 | relocations we need for this symbol. */ | |
3959 | if (h != NULL) | |
3960 | { | |
91d6fa6a | 3961 | rel_head = &ppc_elf_hash_entry (h)->dyn_relocs; |
25dbc73a AM |
3962 | } |
3963 | else | |
3964 | { | |
3965 | /* Track dynamic relocs needed for local syms too. | |
3966 | We really need local syms available to do this | |
3967 | easily. Oh well. */ | |
25dbc73a | 3968 | asection *s; |
6edfbbad | 3969 | void *vpp; |
87d72d41 | 3970 | Elf_Internal_Sym *isym; |
6edfbbad | 3971 | |
87d72d41 AM |
3972 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
3973 | abfd, r_symndx); | |
3974 | if (isym == NULL) | |
25dbc73a | 3975 | return FALSE; |
7fce784e | 3976 | |
87d72d41 AM |
3977 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
3978 | if (s == NULL) | |
3979 | s = sec; | |
3980 | ||
6edfbbad | 3981 | vpp = &elf_section_data (s)->local_dynrel; |
91d6fa6a | 3982 | rel_head = (struct ppc_elf_dyn_relocs **) vpp; |
25dbc73a | 3983 | } |
7fce784e | 3984 | |
91d6fa6a | 3985 | p = *rel_head; |
25dbc73a AM |
3986 | if (p == NULL || p->sec != sec) |
3987 | { | |
3988 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); | |
3989 | if (p == NULL) | |
3990 | return FALSE; | |
91d6fa6a NC |
3991 | p->next = *rel_head; |
3992 | *rel_head = p; | |
25dbc73a AM |
3993 | p->sec = sec; |
3994 | p->count = 0; | |
3995 | p->pc_count = 0; | |
3996 | } | |
3997 | ||
3998 | p->count += 1; | |
1d483afe | 3999 | if (!must_be_dyn_reloc (info, r_type)) |
25dbc73a | 4000 | p->pc_count += 1; |
7619e7c7 | 4001 | } |
25dbc73a AM |
4002 | |
4003 | break; | |
7619e7c7 AM |
4004 | } |
4005 | } | |
ee05f2fe | 4006 | |
25dbc73a AM |
4007 | return TRUE; |
4008 | } | |
4009 | \f | |
34c8bcba JM |
4010 | |
4011 | /* Merge object attributes from IBFD into OBFD. Raise an error if | |
4012 | there are conflicting attributes. */ | |
4013 | static bfd_boolean | |
4014 | ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd) | |
4015 | { | |
c6e65352 DJ |
4016 | obj_attribute *in_attr, *in_attrs; |
4017 | obj_attribute *out_attr, *out_attrs; | |
34c8bcba JM |
4018 | |
4019 | if (!elf_known_obj_attributes_proc (obfd)[0].i) | |
4020 | { | |
4021 | /* This is the first object. Copy the attributes. */ | |
4022 | _bfd_elf_copy_obj_attributes (ibfd, obfd); | |
4023 | ||
4024 | /* Use the Tag_null value to indicate the attributes have been | |
4025 | initialized. */ | |
4026 | elf_known_obj_attributes_proc (obfd)[0].i = 1; | |
4027 | ||
4028 | return TRUE; | |
4029 | } | |
4030 | ||
c6e65352 DJ |
4031 | in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU]; |
4032 | out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU]; | |
4033 | ||
34c8bcba JM |
4034 | /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge |
4035 | non-conflicting ones. */ | |
c6e65352 DJ |
4036 | in_attr = &in_attrs[Tag_GNU_Power_ABI_FP]; |
4037 | out_attr = &out_attrs[Tag_GNU_Power_ABI_FP]; | |
4038 | if (in_attr->i != out_attr->i) | |
34c8bcba | 4039 | { |
c6e65352 DJ |
4040 | out_attr->type = 1; |
4041 | if (out_attr->i == 0) | |
4042 | out_attr->i = in_attr->i; | |
4043 | else if (in_attr->i == 0) | |
34c8bcba | 4044 | ; |
c6e65352 | 4045 | else if (out_attr->i == 1 && in_attr->i == 2) |
34c8bcba JM |
4046 | _bfd_error_handler |
4047 | (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd); | |
3c7b9897 AM |
4048 | else if (out_attr->i == 1 && in_attr->i == 3) |
4049 | _bfd_error_handler | |
4050 | (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"), | |
4051 | obfd, ibfd); | |
4052 | else if (out_attr->i == 3 && in_attr->i == 1) | |
4053 | _bfd_error_handler | |
4054 | (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"), | |
4055 | ibfd, obfd); | |
4056 | else if (out_attr->i == 3 && in_attr->i == 2) | |
4057 | _bfd_error_handler | |
4058 | (_("Warning: %B uses soft float, %B uses single-precision hard float"), | |
4059 | ibfd, obfd); | |
4060 | else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3)) | |
34c8bcba JM |
4061 | _bfd_error_handler |
4062 | (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd); | |
3c7b9897 | 4063 | else if (in_attr->i > 3) |
34c8bcba JM |
4064 | _bfd_error_handler |
4065 | (_("Warning: %B uses unknown floating point ABI %d"), ibfd, | |
c6e65352 | 4066 | in_attr->i); |
34c8bcba JM |
4067 | else |
4068 | _bfd_error_handler | |
4069 | (_("Warning: %B uses unknown floating point ABI %d"), obfd, | |
c6e65352 DJ |
4070 | out_attr->i); |
4071 | } | |
4072 | ||
4073 | /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and | |
4074 | merge non-conflicting ones. */ | |
4075 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector]; | |
4076 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector]; | |
4077 | if (in_attr->i != out_attr->i) | |
4078 | { | |
4079 | const char *in_abi = NULL, *out_abi = NULL; | |
4080 | ||
4081 | switch (in_attr->i) | |
4082 | { | |
4083 | case 1: in_abi = "generic"; break; | |
4084 | case 2: in_abi = "AltiVec"; break; | |
4085 | case 3: in_abi = "SPE"; break; | |
4086 | } | |
4087 | ||
4088 | switch (out_attr->i) | |
4089 | { | |
4090 | case 1: out_abi = "generic"; break; | |
4091 | case 2: out_abi = "AltiVec"; break; | |
4092 | case 3: out_abi = "SPE"; break; | |
4093 | } | |
4094 | ||
4095 | out_attr->type = 1; | |
4096 | if (out_attr->i == 0) | |
4097 | out_attr->i = in_attr->i; | |
4098 | else if (in_attr->i == 0) | |
4099 | ; | |
4100 | /* For now, allow generic to transition to AltiVec or SPE | |
4101 | without a warning. If GCC marked files with their stack | |
4102 | alignment and used don't-care markings for files which are | |
4103 | not affected by the vector ABI, we could warn about this | |
4104 | case too. */ | |
4105 | else if (out_attr->i == 1) | |
4106 | out_attr->i = in_attr->i; | |
4107 | else if (in_attr->i == 1) | |
4108 | ; | |
4109 | else if (in_abi == NULL) | |
4110 | _bfd_error_handler | |
4111 | (_("Warning: %B uses unknown vector ABI %d"), ibfd, | |
4112 | in_attr->i); | |
4113 | else if (out_abi == NULL) | |
4114 | _bfd_error_handler | |
4115 | (_("Warning: %B uses unknown vector ABI %d"), obfd, | |
4116 | in_attr->i); | |
4117 | else | |
4118 | _bfd_error_handler | |
4119 | (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""), | |
4120 | ibfd, obfd, in_abi, out_abi); | |
34c8bcba JM |
4121 | } |
4122 | ||
f82e0623 NF |
4123 | /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes |
4124 | and merge non-conflicting ones. */ | |
4125 | in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4126 | out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return]; | |
4127 | if (in_attr->i != out_attr->i) | |
4128 | { | |
4129 | out_attr->type = 1; | |
4130 | if (out_attr->i == 0) | |
4131 | out_attr->i = in_attr->i; | |
4132 | else if (in_attr->i == 0) | |
4133 | ; | |
4134 | else if (out_attr->i == 1 && in_attr->i == 2) | |
4135 | _bfd_error_handler | |
4136 | (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd); | |
4137 | else if (out_attr->i == 2 && in_attr->i == 1) | |
4138 | _bfd_error_handler | |
4139 | (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd); | |
4140 | else if (in_attr->i > 2) | |
4141 | _bfd_error_handler | |
4142 | (_("Warning: %B uses unknown small structure return convention %d"), ibfd, | |
4143 | in_attr->i); | |
4144 | else | |
4145 | _bfd_error_handler | |
4146 | (_("Warning: %B uses unknown small structure return convention %d"), obfd, | |
4147 | out_attr->i); | |
4148 | } | |
4149 | ||
34c8bcba JM |
4150 | /* Merge Tag_compatibility attributes and any common GNU ones. */ |
4151 | _bfd_elf_merge_object_attributes (ibfd, obfd); | |
4152 | ||
4153 | return TRUE; | |
4154 | } | |
4155 | ||
8853c3d3 AM |
4156 | /* Merge backend specific data from an object file to the output |
4157 | object file when linking. */ | |
4158 | ||
4159 | static bfd_boolean | |
4160 | ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) | |
4161 | { | |
4162 | flagword old_flags; | |
4163 | flagword new_flags; | |
4164 | bfd_boolean error; | |
4165 | ||
0c8d6e5c | 4166 | if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd)) |
8853c3d3 AM |
4167 | return TRUE; |
4168 | ||
4169 | /* Check if we have the same endianess. */ | |
4170 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) | |
4171 | return FALSE; | |
4172 | ||
34c8bcba JM |
4173 | if (!ppc_elf_merge_obj_attributes (ibfd, obfd)) |
4174 | return FALSE; | |
4175 | ||
8853c3d3 AM |
4176 | new_flags = elf_elfheader (ibfd)->e_flags; |
4177 | old_flags = elf_elfheader (obfd)->e_flags; | |
4178 | if (!elf_flags_init (obfd)) | |
4179 | { | |
4180 | /* First call, no flags set. */ | |
4181 | elf_flags_init (obfd) = TRUE; | |
4182 | elf_elfheader (obfd)->e_flags = new_flags; | |
4183 | } | |
4184 | ||
4185 | /* Compatible flags are ok. */ | |
4186 | else if (new_flags == old_flags) | |
4187 | ; | |
4188 | ||
4189 | /* Incompatible flags. */ | |
4190 | else | |
4191 | { | |
4192 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib | |
4193 | to be linked with either. */ | |
4194 | error = FALSE; | |
4195 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 | |
4196 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
4197 | { | |
4198 | error = TRUE; | |
4199 | (*_bfd_error_handler) | |
4200 | (_("%B: compiled with -mrelocatable and linked with " | |
4201 | "modules compiled normally"), ibfd); | |
4202 | } | |
4203 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
4204 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
4205 | { | |
4206 | error = TRUE; | |
4207 | (*_bfd_error_handler) | |
4208 | (_("%B: compiled normally and linked with " | |
4209 | "modules compiled with -mrelocatable"), ibfd); | |
4210 | } | |
4211 | ||
4212 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
4213 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
4214 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
4215 | ||
4216 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
4217 | but each input file is either -mrelocatable or -mrelocatable-lib. */ | |
4218 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) | |
4219 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
4220 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
4221 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
4222 | ||
4223 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if | |
4224 | any module uses it. */ | |
4225 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); | |
4226 | ||
4227 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4228 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
4229 | ||
4230 | /* Warn about any other mismatches. */ | |
4231 | if (new_flags != old_flags) | |
4232 | { | |
4233 | error = TRUE; | |
4234 | (*_bfd_error_handler) | |
4235 | (_("%B: uses different e_flags (0x%lx) fields " | |
4236 | "than previous modules (0x%lx)"), | |
4237 | ibfd, (long) new_flags, (long) old_flags); | |
4238 | } | |
4239 | ||
4240 | if (error) | |
4241 | { | |
4242 | bfd_set_error (bfd_error_bad_value); | |
4243 | return FALSE; | |
4244 | } | |
4245 | } | |
4246 | ||
4247 | return TRUE; | |
4248 | } | |
4249 | \f | |
d7128ce4 AM |
4250 | /* Choose which PLT scheme to use, and set .plt flags appropriately. |
4251 | Returns -1 on error, 0 for old PLT, 1 for new PLT. */ | |
4252 | int | |
4253 | ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED, | |
4254 | struct bfd_link_info *info, | |
016687f8 | 4255 | enum ppc_elf_plt_type plt_style, |
0ba07910 | 4256 | int emit_stub_syms) |
d7128ce4 AM |
4257 | { |
4258 | struct ppc_elf_link_hash_table *htab; | |
9d8504b1 | 4259 | flagword flags; |
d7128ce4 AM |
4260 | |
4261 | htab = ppc_elf_hash_table (info); | |
4a3dc543 | 4262 | |
a7f2871e AM |
4263 | htab->emit_stub_syms = emit_stub_syms; |
4264 | ||
4a3dc543 | 4265 | if (htab->plt_type == PLT_UNSET) |
016687f8 AM |
4266 | { |
4267 | if (plt_style == PLT_OLD) | |
4268 | htab->plt_type = PLT_OLD; | |
4269 | else | |
4270 | { | |
4271 | bfd *ibfd; | |
4272 | enum ppc_elf_plt_type plt_type = plt_style; | |
4273 | ||
4274 | /* Look through the reloc flags left by ppc_elf_check_relocs. | |
4275 | Use the old style bss plt if a file makes plt calls | |
4276 | without using the new relocs, and if ld isn't given | |
4277 | --secure-plt and we never see REL16 relocs. */ | |
4278 | if (plt_type == PLT_UNSET) | |
4279 | plt_type = PLT_OLD; | |
60b31e8d | 4280 | for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next) |
0c8d6e5c | 4281 | if (is_ppc_elf (ibfd)) |
016687f8 AM |
4282 | { |
4283 | if (ppc_elf_tdata (ibfd)->has_rel16) | |
4284 | plt_type = PLT_NEW; | |
4285 | else if (ppc_elf_tdata (ibfd)->makes_plt_call) | |
4286 | { | |
4287 | plt_type = PLT_OLD; | |
4288 | htab->old_bfd = ibfd; | |
4289 | break; | |
4290 | } | |
4291 | } | |
4292 | htab->plt_type = plt_type; | |
4293 | } | |
4294 | } | |
4295 | if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW) | |
4296 | info->callbacks->info (_("Using bss-plt due to %B"), htab->old_bfd); | |
d7128ce4 | 4297 | |
4a3dc543 | 4298 | BFD_ASSERT (htab->plt_type != PLT_VXWORKS); |
9d8504b1 | 4299 | |
4a3dc543 | 4300 | if (htab->plt_type == PLT_NEW) |
9d8504b1 PB |
4301 | { |
4302 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
4303 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
86b9da88 AM |
4304 | |
4305 | /* The new PLT is a loaded section. */ | |
4306 | if (htab->plt != NULL | |
4307 | && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags)) | |
4308 | return -1; | |
4309 | ||
4310 | /* The new GOT is not executable. */ | |
4311 | if (htab->got != NULL | |
4312 | && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags)) | |
4313 | return -1; | |
d7128ce4 AM |
4314 | } |
4315 | else | |
4316 | { | |
4317 | /* Stop an unused .glink section from affecting .text alignment. */ | |
86b9da88 AM |
4318 | if (htab->glink != NULL |
4319 | && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0)) | |
4320 | return -1; | |
d7128ce4 | 4321 | } |
4a3dc543 | 4322 | return htab->plt_type == PLT_NEW; |
d7128ce4 AM |
4323 | } |
4324 | \f | |
25dbc73a AM |
4325 | /* Return the section that should be marked against GC for a given |
4326 | relocation. */ | |
586119b3 | 4327 | |
25dbc73a AM |
4328 | static asection * |
4329 | ppc_elf_gc_mark_hook (asection *sec, | |
07adf181 | 4330 | struct bfd_link_info *info, |
25dbc73a AM |
4331 | Elf_Internal_Rela *rel, |
4332 | struct elf_link_hash_entry *h, | |
4333 | Elf_Internal_Sym *sym) | |
4334 | { | |
4335 | if (h != NULL) | |
07adf181 AM |
4336 | switch (ELF32_R_TYPE (rel->r_info)) |
4337 | { | |
4338 | case R_PPC_GNU_VTINHERIT: | |
4339 | case R_PPC_GNU_VTENTRY: | |
4340 | return NULL; | |
4341 | } | |
4342 | ||
4343 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
25dbc73a | 4344 | } |
a876ecf9 | 4345 | |
25dbc73a AM |
4346 | /* Update the got, plt and dynamic reloc reference counts for the |
4347 | section being removed. */ | |
4348 | ||
4349 | static bfd_boolean | |
4350 | ppc_elf_gc_sweep_hook (bfd *abfd, | |
4351 | struct bfd_link_info *info, | |
4352 | asection *sec, | |
4353 | const Elf_Internal_Rela *relocs) | |
4354 | { | |
4355 | struct ppc_elf_link_hash_table *htab; | |
4356 | Elf_Internal_Shdr *symtab_hdr; | |
4357 | struct elf_link_hash_entry **sym_hashes; | |
4358 | bfd_signed_vma *local_got_refcounts; | |
4359 | const Elf_Internal_Rela *rel, *relend; | |
a6aa5195 | 4360 | asection *got2; |
25dbc73a | 4361 | |
7dda2462 TG |
4362 | if (info->relocatable) |
4363 | return TRUE; | |
4364 | ||
c87b5a93 AM |
4365 | if ((sec->flags & SEC_ALLOC) == 0) |
4366 | return TRUE; | |
4367 | ||
25dbc73a AM |
4368 | elf_section_data (sec)->local_dynrel = NULL; |
4369 | ||
4370 | htab = ppc_elf_hash_table (info); | |
0ffa91dd | 4371 | symtab_hdr = &elf_symtab_hdr (abfd); |
25dbc73a AM |
4372 | sym_hashes = elf_sym_hashes (abfd); |
4373 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
a6aa5195 | 4374 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
25dbc73a AM |
4375 | |
4376 | relend = relocs + sec->reloc_count; | |
4377 | for (rel = relocs; rel < relend; rel++) | |
4378 | { | |
4379 | unsigned long r_symndx; | |
4380 | enum elf_ppc_reloc_type r_type; | |
4381 | struct elf_link_hash_entry *h = NULL; | |
4382 | ||
4383 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4384 | if (r_symndx >= symtab_hdr->sh_info) | |
a876ecf9 | 4385 | { |
25dbc73a AM |
4386 | struct ppc_elf_dyn_relocs **pp, *p; |
4387 | struct ppc_elf_link_hash_entry *eh; | |
4388 | ||
4389 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4390 | while (h->root.type == bfd_link_hash_indirect | |
4391 | || h->root.type == bfd_link_hash_warning) | |
4392 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4393 | eh = (struct ppc_elf_link_hash_entry *) h; | |
4394 | ||
4395 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4396 | if (p->sec == sec) | |
4397 | { | |
4398 | /* Everything must go for SEC. */ | |
4399 | *pp = p->next; | |
4400 | break; | |
4401 | } | |
a876ecf9 | 4402 | } |
ee05f2fe | 4403 | |
25dbc73a | 4404 | r_type = ELF32_R_TYPE (rel->r_info); |
de972ffa AM |
4405 | if (!htab->is_vxworks |
4406 | && h == NULL | |
4407 | && local_got_refcounts != NULL | |
4408 | && (!info->shared | |
4409 | || is_branch_reloc (r_type))) | |
e054468f | 4410 | { |
de972ffa AM |
4411 | struct plt_entry **local_plt = (struct plt_entry **) |
4412 | (local_got_refcounts + symtab_hdr->sh_info); | |
4413 | char *local_got_tls_masks = (char *) | |
4414 | (local_plt + symtab_hdr->sh_info); | |
4415 | if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0) | |
e054468f | 4416 | { |
de972ffa | 4417 | struct plt_entry **ifunc = local_plt + r_symndx; |
a877a2b6 AM |
4418 | bfd_vma addend = 0; |
4419 | struct plt_entry *ent; | |
4420 | ||
4421 | if (r_type == R_PPC_PLTREL24 && info->shared) | |
4422 | addend = rel->r_addend; | |
4423 | ent = find_plt_ent (ifunc, got2, addend); | |
e054468f AM |
4424 | if (ent->plt.refcount > 0) |
4425 | ent->plt.refcount -= 1; | |
4426 | continue; | |
4427 | } | |
4428 | } | |
4429 | ||
25dbc73a | 4430 | switch (r_type) |
ee05f2fe | 4431 | { |
25dbc73a AM |
4432 | case R_PPC_GOT_TLSLD16: |
4433 | case R_PPC_GOT_TLSLD16_LO: | |
4434 | case R_PPC_GOT_TLSLD16_HI: | |
4435 | case R_PPC_GOT_TLSLD16_HA: | |
25dbc73a AM |
4436 | case R_PPC_GOT_TLSGD16: |
4437 | case R_PPC_GOT_TLSGD16_LO: | |
4438 | case R_PPC_GOT_TLSGD16_HI: | |
4439 | case R_PPC_GOT_TLSGD16_HA: | |
4440 | case R_PPC_GOT_TPREL16: | |
4441 | case R_PPC_GOT_TPREL16_LO: | |
4442 | case R_PPC_GOT_TPREL16_HI: | |
4443 | case R_PPC_GOT_TPREL16_HA: | |
4444 | case R_PPC_GOT_DTPREL16: | |
4445 | case R_PPC_GOT_DTPREL16_LO: | |
4446 | case R_PPC_GOT_DTPREL16_HI: | |
4447 | case R_PPC_GOT_DTPREL16_HA: | |
4448 | case R_PPC_GOT16: | |
4449 | case R_PPC_GOT16_LO: | |
4450 | case R_PPC_GOT16_HI: | |
4451 | case R_PPC_GOT16_HA: | |
4452 | if (h != NULL) | |
ee05f2fe | 4453 | { |
25dbc73a AM |
4454 | if (h->got.refcount > 0) |
4455 | h->got.refcount--; | |
91e21fb7 AM |
4456 | if (!info->shared) |
4457 | { | |
4458 | struct plt_entry *ent; | |
4459 | ||
4460 | ent = find_plt_ent (&h->plt.plist, NULL, 0); | |
32af9f6e | 4461 | if (ent != NULL && ent->plt.refcount > 0) |
91e21fb7 AM |
4462 | ent->plt.refcount -= 1; |
4463 | } | |
ee05f2fe | 4464 | } |
25dbc73a AM |
4465 | else if (local_got_refcounts != NULL) |
4466 | { | |
4467 | if (local_got_refcounts[r_symndx] > 0) | |
4468 | local_got_refcounts[r_symndx]--; | |
4469 | } | |
4470 | break; | |
ee05f2fe | 4471 | |
25dbc73a AM |
4472 | case R_PPC_REL24: |
4473 | case R_PPC_REL14: | |
4474 | case R_PPC_REL14_BRTAKEN: | |
4475 | case R_PPC_REL14_BRNTAKEN: | |
4476 | case R_PPC_REL32: | |
3b36f7e6 | 4477 | if (h == NULL || h == htab->elf.hgot) |
25dbc73a AM |
4478 | break; |
4479 | /* Fall thru */ | |
ee05f2fe | 4480 | |
25dbc73a AM |
4481 | case R_PPC_ADDR32: |
4482 | case R_PPC_ADDR24: | |
4483 | case R_PPC_ADDR16: | |
4484 | case R_PPC_ADDR16_LO: | |
4485 | case R_PPC_ADDR16_HI: | |
4486 | case R_PPC_ADDR16_HA: | |
4487 | case R_PPC_ADDR14: | |
4488 | case R_PPC_ADDR14_BRTAKEN: | |
4489 | case R_PPC_ADDR14_BRNTAKEN: | |
4490 | case R_PPC_UADDR32: | |
4491 | case R_PPC_UADDR16: | |
87538722 AM |
4492 | if (info->shared) |
4493 | break; | |
4494 | ||
25dbc73a AM |
4495 | case R_PPC_PLT32: |
4496 | case R_PPC_PLTREL24: | |
87538722 | 4497 | case R_PPC_PLTREL32: |
25dbc73a AM |
4498 | case R_PPC_PLT16_LO: |
4499 | case R_PPC_PLT16_HI: | |
4500 | case R_PPC_PLT16_HA: | |
4501 | if (h != NULL) | |
4502 | { | |
a877a2b6 AM |
4503 | bfd_vma addend = 0; |
4504 | struct plt_entry *ent; | |
4505 | ||
4506 | if (r_type == R_PPC_PLTREL24 && info->shared) | |
4507 | addend = rel->r_addend; | |
4508 | ent = find_plt_ent (&h->plt.plist, got2, addend); | |
32af9f6e | 4509 | if (ent != NULL && ent->plt.refcount > 0) |
a6aa5195 | 4510 | ent->plt.refcount -= 1; |
25dbc73a AM |
4511 | } |
4512 | break; | |
ee05f2fe | 4513 | |
25dbc73a AM |
4514 | default: |
4515 | break; | |
4516 | } | |
7fce784e | 4517 | } |
7fce784e AS |
4518 | return TRUE; |
4519 | } | |
25dbc73a | 4520 | \f |
3a71aa26 AM |
4521 | /* Set plt output section type, htab->tls_get_addr, and call the |
4522 | generic ELF tls_setup function. */ | |
7fce784e | 4523 | |
25dbc73a | 4524 | asection * |
a7f2871e AM |
4525 | ppc_elf_tls_setup (bfd *obfd, |
4526 | struct bfd_link_info *info, | |
4527 | int no_tls_get_addr_opt) | |
7fce784e | 4528 | { |
25dbc73a | 4529 | struct ppc_elf_link_hash_table *htab; |
7fce784e | 4530 | |
25dbc73a | 4531 | htab = ppc_elf_hash_table (info); |
a7f2871e AM |
4532 | htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
4533 | FALSE, FALSE, TRUE); | |
4534 | if (!no_tls_get_addr_opt) | |
4535 | { | |
4536 | struct elf_link_hash_entry *opt, *tga; | |
4537 | opt = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt", | |
4538 | FALSE, FALSE, TRUE); | |
4539 | if (opt != NULL | |
4540 | && (opt->root.type == bfd_link_hash_defined | |
4541 | || opt->root.type == bfd_link_hash_defweak)) | |
4542 | { | |
4543 | /* If glibc supports an optimized __tls_get_addr call stub, | |
4544 | signalled by the presence of __tls_get_addr_opt, and we'll | |
4545 | be calling __tls_get_addr via a plt call stub, then | |
4546 | make __tls_get_addr point to __tls_get_addr_opt. */ | |
4547 | tga = htab->tls_get_addr; | |
4548 | if (htab->elf.dynamic_sections_created | |
4549 | && tga != NULL | |
4550 | && (tga->type == STT_FUNC | |
4551 | || tga->needs_plt) | |
4552 | && !(SYMBOL_CALLS_LOCAL (info, tga) | |
4553 | || (ELF_ST_VISIBILITY (tga->other) != STV_DEFAULT | |
4554 | && tga->root.type == bfd_link_hash_undefweak))) | |
4555 | { | |
4556 | struct plt_entry *ent; | |
32af9f6e AM |
4557 | for (ent = tga->plt.plist; ent != NULL; ent = ent->next) |
4558 | if (ent->plt.refcount > 0) | |
4559 | break; | |
4560 | if (ent != NULL) | |
a7f2871e AM |
4561 | { |
4562 | tga->root.type = bfd_link_hash_indirect; | |
4563 | tga->root.u.i.link = &opt->root; | |
4564 | ppc_elf_copy_indirect_symbol (info, opt, tga); | |
4565 | if (opt->dynindx != -1) | |
4566 | { | |
4567 | /* Use __tls_get_addr_opt in dynamic relocations. */ | |
4568 | opt->dynindx = -1; | |
4569 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
4570 | opt->dynstr_index); | |
4571 | if (!bfd_elf_link_record_dynamic_symbol (info, opt)) | |
4572 | return FALSE; | |
4573 | } | |
4574 | htab->tls_get_addr = opt; | |
4575 | } | |
4576 | } | |
4577 | } | |
4578 | else | |
4579 | no_tls_get_addr_opt = TRUE; | |
4580 | } | |
4581 | htab->no_tls_get_addr_opt = no_tls_get_addr_opt; | |
4a3dc543 | 4582 | if (htab->plt_type == PLT_NEW |
d7128ce4 AM |
4583 | && htab->plt != NULL |
4584 | && htab->plt->output_section != NULL) | |
4585 | { | |
4586 | elf_section_type (htab->plt->output_section) = SHT_PROGBITS; | |
4587 | elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE; | |
4588 | } | |
4589 | ||
25dbc73a | 4590 | return _bfd_elf_tls_setup (obfd, info); |
7fce784e AS |
4591 | } |
4592 | ||
3a71aa26 AM |
4593 | /* Return TRUE iff REL is a branch reloc with a global symbol matching |
4594 | HASH. */ | |
4595 | ||
4596 | static bfd_boolean | |
4597 | branch_reloc_hash_match (const bfd *ibfd, | |
4598 | const Elf_Internal_Rela *rel, | |
4599 | const struct elf_link_hash_entry *hash) | |
4600 | { | |
4601 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); | |
4602 | enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info); | |
4603 | unsigned int r_symndx = ELF32_R_SYM (rel->r_info); | |
4604 | ||
e054468f | 4605 | if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type)) |
3a71aa26 AM |
4606 | { |
4607 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
4608 | struct elf_link_hash_entry *h; | |
4609 | ||
4610 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4611 | while (h->root.type == bfd_link_hash_indirect | |
4612 | || h->root.type == bfd_link_hash_warning) | |
4613 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4614 | if (h == hash) | |
4615 | return TRUE; | |
4616 | } | |
4617 | return FALSE; | |
4618 | } | |
4619 | ||
25dbc73a AM |
4620 | /* Run through all the TLS relocs looking for optimization |
4621 | opportunities. */ | |
252b5132 | 4622 | |
25dbc73a AM |
4623 | bfd_boolean |
4624 | ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, | |
4625 | struct bfd_link_info *info) | |
252b5132 | 4626 | { |
7fce784e | 4627 | bfd *ibfd; |
25dbc73a AM |
4628 | asection *sec; |
4629 | struct ppc_elf_link_hash_table *htab; | |
b7fcf6f6 | 4630 | int pass; |
252b5132 | 4631 | |
1d483afe | 4632 | if (info->relocatable || !info->executable) |
25dbc73a | 4633 | return TRUE; |
252b5132 | 4634 | |
7619e7c7 | 4635 | htab = ppc_elf_hash_table (info); |
b7fcf6f6 AM |
4636 | /* Make two passes through the relocs. First time check that tls |
4637 | relocs involved in setting up a tls_get_addr call are indeed | |
4638 | followed by such a call. If they are not, exclude them from | |
4639 | the optimizations done on the second pass. */ | |
4640 | for (pass = 0; pass < 2; ++pass) | |
4641 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
4642 | { | |
4643 | Elf_Internal_Sym *locsyms = NULL; | |
0ffa91dd | 4644 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); |
32af9f6e | 4645 | asection *got2 = bfd_get_section_by_name (ibfd, ".got2"); |
7619e7c7 | 4646 | |
b7fcf6f6 AM |
4647 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
4648 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
4649 | { | |
4650 | Elf_Internal_Rela *relstart, *rel, *relend; | |
252b5132 | 4651 | |
b7fcf6f6 AM |
4652 | /* Read the relocations. */ |
4653 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, | |
4654 | info->keep_memory); | |
4655 | if (relstart == NULL) | |
4656 | return FALSE; | |
7619e7c7 | 4657 | |
b7fcf6f6 AM |
4658 | relend = relstart + sec->reloc_count; |
4659 | for (rel = relstart; rel < relend; rel++) | |
4660 | { | |
4661 | enum elf_ppc_reloc_type r_type; | |
4662 | unsigned long r_symndx; | |
4663 | struct elf_link_hash_entry *h = NULL; | |
4664 | char *tls_mask; | |
4665 | char tls_set, tls_clear; | |
4666 | bfd_boolean is_local; | |
4667 | int expecting_tls_get_addr; | |
4668 | bfd_signed_vma *got_count; | |
4669 | ||
4670 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4671 | if (r_symndx >= symtab_hdr->sh_info) | |
4672 | { | |
4673 | struct elf_link_hash_entry **sym_hashes; | |
7fce784e | 4674 | |
b7fcf6f6 AM |
4675 | sym_hashes = elf_sym_hashes (ibfd); |
4676 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4677 | while (h->root.type == bfd_link_hash_indirect | |
4678 | || h->root.type == bfd_link_hash_warning) | |
4679 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4680 | } | |
7619e7c7 | 4681 | |
b7fcf6f6 AM |
4682 | expecting_tls_get_addr = 0; |
4683 | is_local = FALSE; | |
4684 | if (h == NULL | |
4685 | || !h->def_dynamic) | |
4686 | is_local = TRUE; | |
7619e7c7 | 4687 | |
b7fcf6f6 AM |
4688 | r_type = ELF32_R_TYPE (rel->r_info); |
4689 | switch (r_type) | |
4690 | { | |
4691 | case R_PPC_GOT_TLSLD16: | |
4692 | case R_PPC_GOT_TLSLD16_LO: | |
4693 | expecting_tls_get_addr = 1; | |
4694 | /* Fall thru */ | |
4695 | ||
4696 | case R_PPC_GOT_TLSLD16_HI: | |
4697 | case R_PPC_GOT_TLSLD16_HA: | |
4698 | /* These relocs should never be against a symbol | |
4699 | defined in a shared lib. Leave them alone if | |
4700 | that turns out to be the case. */ | |
4701 | if (!is_local) | |
4702 | continue; | |
4703 | ||
4704 | /* LD -> LE */ | |
4705 | tls_set = 0; | |
4706 | tls_clear = TLS_LD; | |
4707 | break; | |
4708 | ||
4709 | case R_PPC_GOT_TLSGD16: | |
4710 | case R_PPC_GOT_TLSGD16_LO: | |
4711 | expecting_tls_get_addr = 1; | |
4712 | /* Fall thru */ | |
4713 | ||
4714 | case R_PPC_GOT_TLSGD16_HI: | |
4715 | case R_PPC_GOT_TLSGD16_HA: | |
4716 | if (is_local) | |
4717 | /* GD -> LE */ | |
4718 | tls_set = 0; | |
4719 | else | |
4720 | /* GD -> IE */ | |
4721 | tls_set = TLS_TLS | TLS_TPRELGD; | |
4722 | tls_clear = TLS_GD; | |
4723 | break; | |
4724 | ||
4725 | case R_PPC_GOT_TPREL16: | |
4726 | case R_PPC_GOT_TPREL16_LO: | |
4727 | case R_PPC_GOT_TPREL16_HI: | |
4728 | case R_PPC_GOT_TPREL16_HA: | |
4729 | if (is_local) | |
4730 | { | |
4731 | /* IE -> LE */ | |
4732 | tls_set = 0; | |
4733 | tls_clear = TLS_TPREL; | |
4734 | break; | |
4735 | } | |
4736 | else | |
4737 | continue; | |
4738 | ||
32af9f6e AM |
4739 | case R_PPC_TLSGD: |
4740 | case R_PPC_TLSLD: | |
4741 | expecting_tls_get_addr = 2; | |
4742 | tls_set = 0; | |
4743 | tls_clear = 0; | |
4744 | break; | |
4745 | ||
b7fcf6f6 | 4746 | default: |
25dbc73a | 4747 | continue; |
b7fcf6f6 | 4748 | } |
25dbc73a | 4749 | |
b7fcf6f6 AM |
4750 | if (pass == 0) |
4751 | { | |
727fc41e | 4752 | if (!expecting_tls_get_addr |
32af9f6e AM |
4753 | || (expecting_tls_get_addr == 1 |
4754 | && !sec->has_tls_get_addr_call)) | |
b7fcf6f6 | 4755 | continue; |
25dbc73a | 4756 | |
3a71aa26 AM |
4757 | if (rel + 1 < relend |
4758 | && branch_reloc_hash_match (ibfd, rel + 1, | |
4759 | htab->tls_get_addr)) | |
4760 | continue; | |
25dbc73a | 4761 | |
b7fcf6f6 AM |
4762 | /* Uh oh, we didn't find the expected call. We |
4763 | could just mark this symbol to exclude it | |
4764 | from tls optimization but it's safer to skip | |
4765 | the entire section. */ | |
4766 | sec->has_tls_reloc = 0; | |
4767 | break; | |
4768 | } | |
25dbc73a | 4769 | |
32af9f6e AM |
4770 | if (expecting_tls_get_addr) |
4771 | { | |
4772 | struct plt_entry *ent; | |
4773 | bfd_vma addend = 0; | |
4774 | ||
4775 | if (info->shared | |
4776 | && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24) | |
4777 | addend = rel[1].r_addend; | |
4778 | ent = find_plt_ent (&htab->tls_get_addr->plt.plist, | |
4779 | got2, addend); | |
4780 | if (ent != NULL && ent->plt.refcount > 0) | |
4781 | ent->plt.refcount -= 1; | |
4782 | ||
4783 | if (expecting_tls_get_addr == 2) | |
4784 | continue; | |
4785 | } | |
4786 | ||
b7fcf6f6 AM |
4787 | if (h != NULL) |
4788 | { | |
4789 | tls_mask = &ppc_elf_hash_entry (h)->tls_mask; | |
4790 | got_count = &h->got.refcount; | |
4791 | } | |
4792 | else | |
4793 | { | |
4794 | Elf_Internal_Sym *sym; | |
4795 | bfd_signed_vma *lgot_refs; | |
e054468f | 4796 | struct plt_entry **local_plt; |
b7fcf6f6 | 4797 | char *lgot_masks; |
25dbc73a | 4798 | |
b7fcf6f6 AM |
4799 | if (locsyms == NULL) |
4800 | { | |
4801 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4802 | if (locsyms == NULL) | |
4803 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
4804 | symtab_hdr->sh_info, | |
4805 | 0, NULL, NULL, NULL); | |
4806 | if (locsyms == NULL) | |
4807 | { | |
4808 | if (elf_section_data (sec)->relocs != relstart) | |
4809 | free (relstart); | |
4810 | return FALSE; | |
4811 | } | |
4812 | } | |
4813 | sym = locsyms + r_symndx; | |
4814 | lgot_refs = elf_local_got_refcounts (ibfd); | |
4815 | if (lgot_refs == NULL) | |
4816 | abort (); | |
e054468f AM |
4817 | local_plt = (struct plt_entry **) |
4818 | (lgot_refs + symtab_hdr->sh_info); | |
4819 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
b7fcf6f6 AM |
4820 | tls_mask = &lgot_masks[r_symndx]; |
4821 | got_count = &lgot_refs[r_symndx]; | |
4822 | } | |
25dbc73a | 4823 | |
b7fcf6f6 AM |
4824 | if (tls_set == 0) |
4825 | { | |
4826 | /* We managed to get rid of a got entry. */ | |
4827 | if (*got_count > 0) | |
4828 | *got_count -= 1; | |
4829 | } | |
25dbc73a | 4830 | |
b7fcf6f6 AM |
4831 | *tls_mask |= tls_set; |
4832 | *tls_mask &= ~tls_clear; | |
4833 | } | |
25dbc73a | 4834 | |
b7fcf6f6 AM |
4835 | if (elf_section_data (sec)->relocs != relstart) |
4836 | free (relstart); | |
4837 | } | |
4838 | ||
4839 | if (locsyms != NULL | |
4840 | && (symtab_hdr->contents != (unsigned char *) locsyms)) | |
4841 | { | |
4842 | if (!info->keep_memory) | |
4843 | free (locsyms); | |
4844 | else | |
4845 | symtab_hdr->contents = (unsigned char *) locsyms; | |
4846 | } | |
4847 | } | |
25dbc73a AM |
4848 | return TRUE; |
4849 | } | |
4850 | \f | |
625af618 AM |
4851 | /* Return true if we have dynamic relocs that apply to read-only sections. */ |
4852 | ||
4853 | static bfd_boolean | |
4854 | readonly_dynrelocs (struct elf_link_hash_entry *h) | |
4855 | { | |
4856 | struct ppc_elf_dyn_relocs *p; | |
4857 | ||
4858 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) | |
4859 | { | |
4860 | asection *s = p->sec->output_section; | |
4861 | ||
4862 | if (s != NULL | |
4863 | && ((s->flags & (SEC_READONLY | SEC_ALLOC)) | |
4864 | == (SEC_READONLY | SEC_ALLOC))) | |
4865 | return TRUE; | |
4866 | } | |
4867 | return FALSE; | |
4868 | } | |
4869 | ||
25dbc73a AM |
4870 | /* Adjust a symbol defined by a dynamic object and referenced by a |
4871 | regular object. The current definition is in some section of the | |
4872 | dynamic object, but we're not including those sections. We have to | |
4873 | change the definition to something the rest of the link can | |
4874 | understand. */ | |
7fce784e | 4875 | |
25dbc73a AM |
4876 | static bfd_boolean |
4877 | ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, | |
4878 | struct elf_link_hash_entry *h) | |
4879 | { | |
4880 | struct ppc_elf_link_hash_table *htab; | |
4881 | asection *s; | |
7fce784e | 4882 | |
25dbc73a AM |
4883 | #ifdef DEBUG |
4884 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", | |
4885 | h->root.root.string); | |
4886 | #endif | |
252b5132 | 4887 | |
25dbc73a AM |
4888 | /* Make sure we know what is going on here. */ |
4889 | htab = ppc_elf_hash_table (info); | |
4890 | BFD_ASSERT (htab->elf.dynobj != NULL | |
4891 | && (h->needs_plt | |
91e21fb7 | 4892 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
4893 | || h->u.weakdef != NULL |
4894 | || (h->def_dynamic | |
4895 | && h->ref_regular | |
4896 | && !h->def_regular))); | |
252b5132 | 4897 | |
25dbc73a AM |
4898 | /* Deal with function syms. */ |
4899 | if (h->type == STT_FUNC | |
e054468f | 4900 | || h->type == STT_GNU_IFUNC |
25dbc73a AM |
4901 | || h->needs_plt) |
4902 | { | |
4903 | /* Clear procedure linkage table information for any symbol that | |
4904 | won't need a .plt entry. */ | |
a6aa5195 AM |
4905 | struct plt_entry *ent; |
4906 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4907 | if (ent->plt.refcount > 0) | |
4908 | break; | |
4909 | if (ent == NULL | |
e054468f AM |
4910 | || (h->type != STT_GNU_IFUNC |
4911 | && (SYMBOL_CALLS_LOCAL (info, h) | |
4912 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4913 | && h->root.type == bfd_link_hash_undefweak)))) | |
252b5132 | 4914 | { |
25dbc73a | 4915 | /* A PLT entry is not required/allowed when: |
252b5132 | 4916 | |
25dbc73a AM |
4917 | 1. We are not using ld.so; because then the PLT entry |
4918 | can't be set up, so we can't use one. In this case, | |
4919 | ppc_elf_adjust_dynamic_symbol won't even be called. | |
252b5132 | 4920 | |
25dbc73a AM |
4921 | 2. GC has rendered the entry unused. |
4922 | ||
4923 | 3. We know for certain that a call to this symbol | |
4924 | will go to this object, or will remain undefined. */ | |
a6aa5195 | 4925 | h->plt.plist = NULL; |
25dbc73a AM |
4926 | h->needs_plt = 0; |
4927 | } | |
625af618 AM |
4928 | else |
4929 | { | |
25f23106 AM |
4930 | /* After adjust_dynamic_symbol, non_got_ref set in the |
4931 | non-shared case means that we have allocated space in | |
4932 | .dynbss for the symbol and thus dyn_relocs for this | |
4933 | symbol should be discarded. | |
625af618 AM |
4934 | If we get here we know we are making a PLT entry for this |
4935 | symbol, and in an executable we'd normally resolve | |
4936 | relocations against this symbol to the PLT entry. Allow | |
4937 | dynamic relocs if the reference is weak, and the dynamic | |
4938 | relocs will not cause text relocation. */ | |
4939 | if (!h->ref_regular_nonweak | |
4940 | && h->non_got_ref | |
25f23106 | 4941 | && h->type != STT_GNU_IFUNC |
625af618 AM |
4942 | && !htab->is_vxworks |
4943 | && !ppc_elf_hash_entry (h)->has_sda_refs | |
4944 | && !readonly_dynrelocs (h)) | |
4945 | h->non_got_ref = 0; | |
4946 | } | |
25dbc73a | 4947 | return TRUE; |
252b5132 | 4948 | } |
25dbc73a | 4949 | else |
a6aa5195 | 4950 | h->plt.plist = NULL; |
252b5132 | 4951 | |
25dbc73a AM |
4952 | /* If this is a weak symbol, and there is a real definition, the |
4953 | processor independent code will have arranged for us to see the | |
4954 | real definition first, and we can just use the same value. */ | |
4955 | if (h->u.weakdef != NULL) | |
252b5132 | 4956 | { |
25dbc73a AM |
4957 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
4958 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
4959 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
4960 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
4961 | if (ELIMINATE_COPY_RELOCS) | |
4962 | h->non_got_ref = h->u.weakdef->non_got_ref; | |
4963 | return TRUE; | |
4964 | } | |
dc810e39 | 4965 | |
25dbc73a AM |
4966 | /* This is a reference to a symbol defined by a dynamic object which |
4967 | is not a function. */ | |
252b5132 | 4968 | |
25dbc73a AM |
4969 | /* If we are creating a shared library, we must presume that the |
4970 | only references to the symbol are via the global offset table. | |
4971 | For such cases we need not do anything here; the relocations will | |
4972 | be handled correctly by relocate_section. */ | |
4973 | if (info->shared) | |
4974 | return TRUE; | |
252b5132 | 4975 | |
25dbc73a AM |
4976 | /* If there are no references to this symbol that do not use the |
4977 | GOT, we don't need to generate a copy reloc. */ | |
4978 | if (!h->non_got_ref) | |
4979 | return TRUE; | |
4980 | ||
cfd2c773 NS |
4981 | /* If we didn't find any dynamic relocs in read-only sections, then |
4982 | we'll be keeping the dynamic relocs and avoiding the copy reloc. | |
4983 | We can't do this if there are any small data relocations. This | |
4984 | doesn't work on VxWorks, where we can not have dynamic | |
4985 | relocations (other than copy and jump slot relocations) in an | |
4986 | executable. */ | |
4dc4a9a5 | 4987 | if (ELIMINATE_COPY_RELOCS |
cfd2c773 | 4988 | && !ppc_elf_hash_entry (h)->has_sda_refs |
625af618 AM |
4989 | && !htab->is_vxworks |
4990 | && !h->def_regular | |
4991 | && !readonly_dynrelocs (h)) | |
25dbc73a | 4992 | { |
625af618 AM |
4993 | h->non_got_ref = 0; |
4994 | return TRUE; | |
252b5132 RH |
4995 | } |
4996 | ||
909272ee AM |
4997 | if (h->size == 0) |
4998 | { | |
4999 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
5000 | h->root.root.string); | |
5001 | return TRUE; | |
5002 | } | |
5003 | ||
25dbc73a AM |
5004 | /* We must allocate the symbol in our .dynbss section, which will |
5005 | become part of the .bss section of the executable. There will be | |
5006 | an entry for this symbol in the .dynsym section. The dynamic | |
5007 | object will contain position independent code, so all references | |
5008 | from the dynamic object to this symbol will go through the global | |
5009 | offset table. The dynamic linker will use the .dynsym entry to | |
5010 | determine the address it must put in the global offset table, so | |
5011 | both the dynamic object and the regular object will refer to the | |
5012 | same memory location for the variable. | |
5013 | ||
4dc4a9a5 DJ |
5014 | Of course, if the symbol is referenced using SDAREL relocs, we |
5015 | must instead allocate it in .sbss. */ | |
25dbc73a | 5016 | |
4dc4a9a5 | 5017 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
5018 | s = htab->dynsbss; |
5019 | else | |
5020 | s = htab->dynbss; | |
5021 | BFD_ASSERT (s != NULL); | |
5022 | ||
5023 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
5024 | copy the initial value out of the dynamic object and into the | |
5025 | runtime process image. We need to remember the offset into the | |
5026 | .rela.bss section we are going to use. */ | |
5027 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
5028 | { | |
5029 | asection *srel; | |
5030 | ||
4dc4a9a5 | 5031 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
5032 | srel = htab->relsbss; |
5033 | else | |
5034 | srel = htab->relbss; | |
5035 | BFD_ASSERT (srel != NULL); | |
5036 | srel->size += sizeof (Elf32_External_Rela); | |
5037 | h->needs_copy = 1; | |
5038 | } | |
7619e7c7 | 5039 | |
027297b7 | 5040 | return _bfd_elf_adjust_dynamic_copy (h, s); |
25dbc73a AM |
5041 | } |
5042 | \f | |
ac39eb42 AM |
5043 | /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is |
5044 | xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0, | |
5045 | specifying the addend on the plt relocation. For -fpic code, the sym | |
5046 | is xxxxxxxx.plt_pic32.<callee>, and for -fPIC | |
5047 | xxxxxxxx.got2.plt_pic32.<callee>. */ | |
0ba07910 AM |
5048 | |
5049 | static bfd_boolean | |
5050 | add_stub_sym (struct plt_entry *ent, | |
5051 | struct elf_link_hash_entry *h, | |
ac39eb42 | 5052 | struct bfd_link_info *info) |
0ba07910 AM |
5053 | { |
5054 | struct elf_link_hash_entry *sh; | |
5055 | size_t len1, len2, len3; | |
5056 | char *name; | |
ac39eb42 AM |
5057 | const char *stub; |
5058 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
5059 | ||
a877a2b6 | 5060 | if (info->shared) |
ac39eb42 AM |
5061 | stub = ".plt_pic32."; |
5062 | else | |
5063 | stub = ".plt_call32."; | |
0ba07910 AM |
5064 | |
5065 | len1 = strlen (h->root.root.string); | |
ac39eb42 | 5066 | len2 = strlen (stub); |
0ba07910 AM |
5067 | len3 = 0; |
5068 | if (ent->sec) | |
5069 | len3 = strlen (ent->sec->name); | |
ac39eb42 | 5070 | name = bfd_malloc (len1 + len2 + len3 + 9); |
0ba07910 AM |
5071 | if (name == NULL) |
5072 | return FALSE; | |
5073 | sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff); | |
5074 | if (ent->sec) | |
5075 | memcpy (name + 8, ent->sec->name, len3); | |
ac39eb42 AM |
5076 | memcpy (name + 8 + len3, stub, len2); |
5077 | memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1); | |
0ba07910 AM |
5078 | sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE); |
5079 | if (sh == NULL) | |
5080 | return FALSE; | |
5081 | if (sh->root.type == bfd_link_hash_new) | |
5082 | { | |
5083 | sh->root.type = bfd_link_hash_defined; | |
5084 | sh->root.u.def.section = htab->glink; | |
5085 | sh->root.u.def.value = ent->glink_offset; | |
5086 | sh->ref_regular = 1; | |
5087 | sh->def_regular = 1; | |
5088 | sh->ref_regular_nonweak = 1; | |
5089 | sh->forced_local = 1; | |
5090 | sh->non_elf = 0; | |
5091 | } | |
5092 | return TRUE; | |
5093 | } | |
5094 | ||
3b36f7e6 AM |
5095 | /* Allocate NEED contiguous space in .got, and return the offset. |
5096 | Handles allocation of the got header when crossing 32k. */ | |
5097 | ||
5098 | static bfd_vma | |
5099 | allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need) | |
5100 | { | |
5101 | bfd_vma where; | |
4a3dc543 | 5102 | unsigned int max_before_header; |
3b36f7e6 | 5103 | |
4a3dc543 | 5104 | if (htab->plt_type == PLT_VXWORKS) |
9d8504b1 PB |
5105 | { |
5106 | where = htab->got->size; | |
5107 | htab->got->size += need; | |
5108 | } | |
3b36f7e6 AM |
5109 | else |
5110 | { | |
4a3dc543 RS |
5111 | max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764; |
5112 | if (need <= htab->got_gap) | |
3b36f7e6 | 5113 | { |
4a3dc543 RS |
5114 | where = max_before_header - htab->got_gap; |
5115 | htab->got_gap -= need; | |
5116 | } | |
5117 | else | |
5118 | { | |
5119 | if (htab->got->size + need > max_before_header | |
5120 | && htab->got->size <= max_before_header) | |
5121 | { | |
5122 | htab->got_gap = max_before_header - htab->got->size; | |
5123 | htab->got->size = max_before_header + htab->got_header_size; | |
5124 | } | |
5125 | where = htab->got->size; | |
5126 | htab->got->size += need; | |
3b36f7e6 | 5127 | } |
3b36f7e6 AM |
5128 | } |
5129 | return where; | |
5130 | } | |
5131 | ||
25dbc73a | 5132 | /* Allocate space in associated reloc sections for dynamic relocs. */ |
252b5132 | 5133 | |
b34976b6 | 5134 | static bfd_boolean |
25dbc73a | 5135 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
252b5132 | 5136 | { |
25dbc73a AM |
5137 | struct bfd_link_info *info = inf; |
5138 | struct ppc_elf_link_hash_entry *eh; | |
7619e7c7 | 5139 | struct ppc_elf_link_hash_table *htab; |
25dbc73a | 5140 | struct ppc_elf_dyn_relocs *p; |
252b5132 | 5141 | |
25dbc73a | 5142 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5143 | return TRUE; |
252b5132 | 5144 | |
25dbc73a AM |
5145 | if (h->root.type == bfd_link_hash_warning) |
5146 | /* When warning symbols are created, they **replace** the "real" | |
5147 | entry in the hash table, thus we never get to see the real | |
5148 | symbol in a hash traversal. So look at it now. */ | |
5149 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
e47cd125 | 5150 | |
7619e7c7 | 5151 | htab = ppc_elf_hash_table (info); |
e054468f AM |
5152 | if (htab->elf.dynamic_sections_created |
5153 | || h->type == STT_GNU_IFUNC) | |
252b5132 | 5154 | { |
a6aa5195 AM |
5155 | struct plt_entry *ent; |
5156 | bfd_boolean doneone = FALSE; | |
28e99bb6 | 5157 | bfd_vma plt_offset = 0, glink_offset = 0; |
e054468f | 5158 | bfd_boolean dyn; |
28e99bb6 | 5159 | |
a6aa5195 AM |
5160 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
5161 | if (ent->plt.refcount > 0) | |
5162 | { | |
5163 | /* Make sure this symbol is output as a dynamic symbol. */ | |
5164 | if (h->dynindx == -1 | |
e054468f AM |
5165 | && !h->forced_local |
5166 | && !h->def_regular | |
5167 | && htab->elf.dynamic_sections_created) | |
a6aa5195 AM |
5168 | { |
5169 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5170 | return FALSE; | |
5171 | } | |
252b5132 | 5172 | |
e054468f | 5173 | dyn = htab->elf.dynamic_sections_created; |
a6aa5195 | 5174 | if (info->shared |
e054468f AM |
5175 | || h->type == STT_GNU_IFUNC |
5176 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
a6aa5195 AM |
5177 | { |
5178 | asection *s = htab->plt; | |
25f23106 | 5179 | if (!dyn || h->dynindx == -1) |
e054468f | 5180 | s = htab->iplt; |
7619e7c7 | 5181 | |
25f23106 | 5182 | if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1) |
a6aa5195 | 5183 | { |
a6aa5195 | 5184 | if (!doneone) |
28e99bb6 AM |
5185 | { |
5186 | plt_offset = s->size; | |
5187 | s->size += 4; | |
5188 | } | |
5189 | ent->plt.offset = plt_offset; | |
d7128ce4 | 5190 | |
a6aa5195 | 5191 | s = htab->glink; |
a877a2b6 | 5192 | if (!doneone || info->shared) |
28e99bb6 AM |
5193 | { |
5194 | glink_offset = s->size; | |
5195 | s->size += GLINK_ENTRY_SIZE; | |
a7f2871e AM |
5196 | if (h == htab->tls_get_addr |
5197 | && !htab->no_tls_get_addr_opt) | |
5198 | s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE; | |
28e99bb6 AM |
5199 | } |
5200 | if (!doneone | |
5201 | && !info->shared | |
625af618 | 5202 | && h->def_dynamic |
a6aa5195 AM |
5203 | && !h->def_regular) |
5204 | { | |
5205 | h->root.u.def.section = s; | |
28e99bb6 | 5206 | h->root.u.def.value = glink_offset; |
a6aa5195 | 5207 | } |
28e99bb6 | 5208 | ent->glink_offset = glink_offset; |
0ba07910 AM |
5209 | |
5210 | if (htab->emit_stub_syms | |
ac39eb42 | 5211 | && !add_stub_sym (ent, h, info)) |
0ba07910 | 5212 | return FALSE; |
a6aa5195 AM |
5213 | } |
5214 | else | |
5215 | { | |
a6aa5195 AM |
5216 | if (!doneone) |
5217 | { | |
28e99bb6 AM |
5218 | /* If this is the first .plt entry, make room |
5219 | for the special first entry. */ | |
5220 | if (s->size == 0) | |
9d8504b1 | 5221 | s->size += htab->plt_initial_entry_size; |
28e99bb6 AM |
5222 | |
5223 | /* The PowerPC PLT is actually composed of two | |
5224 | parts, the first part is 2 words (for a load | |
5225 | and a jump), and then there is a remaining | |
5226 | word available at the end. */ | |
9d8504b1 PB |
5227 | plt_offset = (htab->plt_initial_entry_size |
5228 | + (htab->plt_slot_size | |
5229 | * ((s->size | |
5230 | - htab->plt_initial_entry_size) | |
5231 | / htab->plt_entry_size))); | |
28e99bb6 AM |
5232 | |
5233 | /* If this symbol is not defined in a regular | |
5234 | file, and we are not generating a shared | |
de972ffa AM |
5235 | library, then set the symbol to this location |
5236 | in the .plt. This is to avoid text | |
5237 | relocations, and is required to make | |
28e99bb6 AM |
5238 | function pointers compare as equal between |
5239 | the normal executable and the shared library. */ | |
5240 | if (! info->shared | |
625af618 | 5241 | && h->def_dynamic |
28e99bb6 AM |
5242 | && !h->def_regular) |
5243 | { | |
5244 | h->root.u.def.section = s; | |
5245 | h->root.u.def.value = plt_offset; | |
5246 | } | |
5247 | ||
9d8504b1 PB |
5248 | /* Make room for this entry. */ |
5249 | s->size += htab->plt_entry_size; | |
5250 | /* After the 8192nd entry, room for two entries | |
5251 | is allocated. */ | |
4a3dc543 | 5252 | if (htab->plt_type == PLT_OLD |
9d8504b1 PB |
5253 | && (s->size - htab->plt_initial_entry_size) |
5254 | / htab->plt_entry_size | |
5255 | > PLT_NUM_SINGLE_ENTRIES) | |
5256 | s->size += htab->plt_entry_size; | |
a6aa5195 | 5257 | } |
28e99bb6 | 5258 | ent->plt.offset = plt_offset; |
a6aa5195 | 5259 | } |
25dbc73a | 5260 | |
a6aa5195 AM |
5261 | /* We also need to make an entry in the .rela.plt section. */ |
5262 | if (!doneone) | |
5263 | { | |
25f23106 AM |
5264 | if (!htab->elf.dynamic_sections_created |
5265 | || h->dynindx == -1) | |
e054468f AM |
5266 | htab->reliplt->size += sizeof (Elf32_External_Rela); |
5267 | else | |
9d8504b1 | 5268 | { |
e054468f AM |
5269 | htab->relplt->size += sizeof (Elf32_External_Rela); |
5270 | ||
5271 | if (htab->plt_type == PLT_VXWORKS) | |
9d8504b1 | 5272 | { |
e054468f AM |
5273 | /* Allocate space for the unloaded relocations. */ |
5274 | if (!info->shared | |
5275 | && htab->elf.dynamic_sections_created) | |
9d8504b1 | 5276 | { |
e054468f AM |
5277 | if (ent->plt.offset |
5278 | == (bfd_vma) htab->plt_initial_entry_size) | |
5279 | { | |
5280 | htab->srelplt2->size | |
5281 | += (sizeof (Elf32_External_Rela) | |
5282 | * VXWORKS_PLTRESOLVE_RELOCS); | |
5283 | } | |
5284 | ||
9d8504b1 | 5285 | htab->srelplt2->size |
e054468f AM |
5286 | += (sizeof (Elf32_External_Rela) |
5287 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS); | |
9d8504b1 PB |
5288 | } |
5289 | ||
e054468f AM |
5290 | /* Every PLT entry has an associated GOT entry in |
5291 | .got.plt. */ | |
5292 | htab->sgotplt->size += 4; | |
9d8504b1 | 5293 | } |
9d8504b1 | 5294 | } |
a6aa5195 AM |
5295 | doneone = TRUE; |
5296 | } | |
5297 | } | |
5298 | else | |
5299 | ent->plt.offset = (bfd_vma) -1; | |
a6aa5195 | 5300 | } |
2ce859a1 AM |
5301 | else |
5302 | ent->plt.offset = (bfd_vma) -1; | |
5303 | ||
5304 | if (!doneone) | |
5305 | { | |
5306 | h->plt.plist = NULL; | |
5307 | h->needs_plt = 0; | |
5308 | } | |
25dbc73a AM |
5309 | } |
5310 | else | |
5311 | { | |
a6aa5195 | 5312 | h->plt.plist = NULL; |
25dbc73a AM |
5313 | h->needs_plt = 0; |
5314 | } | |
5315 | ||
5316 | eh = (struct ppc_elf_link_hash_entry *) h; | |
5317 | if (eh->elf.got.refcount > 0) | |
5318 | { | |
d6e14abc AM |
5319 | bfd_boolean dyn; |
5320 | unsigned int need; | |
5321 | ||
25dbc73a AM |
5322 | /* Make sure this symbol is output as a dynamic symbol. */ |
5323 | if (eh->elf.dynindx == -1 | |
b099ab9f | 5324 | && !eh->elf.forced_local |
25f23106 | 5325 | && eh->elf.type != STT_GNU_IFUNC |
b099ab9f | 5326 | && htab->elf.dynamic_sections_created) |
25dbc73a AM |
5327 | { |
5328 | if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf)) | |
b34976b6 | 5329 | return FALSE; |
25dbc73a | 5330 | } |
252b5132 | 5331 | |
d6e14abc AM |
5332 | need = 0; |
5333 | if ((eh->tls_mask & TLS_TLS) != 0) | |
25dbc73a | 5334 | { |
d6e14abc | 5335 | if ((eh->tls_mask & TLS_LD) != 0) |
252b5132 | 5336 | { |
d6e14abc AM |
5337 | if (!eh->elf.def_dynamic) |
5338 | /* We'll just use htab->tlsld_got.offset. This should | |
5339 | always be the case. It's a little odd if we have | |
5340 | a local dynamic reloc against a non-local symbol. */ | |
5341 | htab->tlsld_got.refcount += 1; | |
5342 | else | |
3b36f7e6 | 5343 | need += 8; |
252b5132 | 5344 | } |
d6e14abc AM |
5345 | if ((eh->tls_mask & TLS_GD) != 0) |
5346 | need += 8; | |
5347 | if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
5348 | need += 4; | |
5349 | if ((eh->tls_mask & TLS_DTPREL) != 0) | |
3b36f7e6 | 5350 | need += 4; |
d6e14abc AM |
5351 | } |
5352 | else | |
5353 | need += 4; | |
5354 | if (need == 0) | |
5355 | eh->elf.got.offset = (bfd_vma) -1; | |
5356 | else | |
5357 | { | |
3b36f7e6 | 5358 | eh->elf.got.offset = allocate_got (htab, need); |
25dbc73a AM |
5359 | dyn = htab->elf.dynamic_sections_created; |
5360 | if ((info->shared | |
5361 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf)) | |
5362 | && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT | |
5363 | || eh->elf.root.type != bfd_link_hash_undefweak)) | |
252b5132 | 5364 | { |
91e21fb7 | 5365 | asection *rsec = htab->relgot; |
3b36f7e6 AM |
5366 | /* All the entries we allocated need relocs. |
5367 | Except LD only needs one. */ | |
d6e14abc AM |
5368 | if ((eh->tls_mask & TLS_LD) != 0 |
5369 | && eh->elf.def_dynamic) | |
3b36f7e6 | 5370 | need -= 4; |
25f23106 | 5371 | rsec->size += need * (sizeof (Elf32_External_Rela) / 4); |
252b5132 | 5372 | } |
25dbc73a AM |
5373 | } |
5374 | } | |
5375 | else | |
5376 | eh->elf.got.offset = (bfd_vma) -1; | |
252b5132 | 5377 | |
b099ab9f | 5378 | if (eh->dyn_relocs == NULL |
de972ffa | 5379 | || !htab->elf.dynamic_sections_created) |
25dbc73a | 5380 | return TRUE; |
252b5132 | 5381 | |
25dbc73a AM |
5382 | /* In the shared -Bsymbolic case, discard space allocated for |
5383 | dynamic pc-relative relocs against symbols which turn out to be | |
5384 | defined in regular objects. For the normal shared case, discard | |
5385 | space for relocs that have become local due to symbol visibility | |
5386 | changes. */ | |
5387 | ||
5388 | if (info->shared) | |
5389 | { | |
5390 | /* Relocs that use pc_count are those that appear on a call insn, | |
1d483afe | 5391 | or certain REL relocs (see must_be_dyn_reloc) that can be |
25dbc73a AM |
5392 | generated via assembly. We want calls to protected symbols to |
5393 | resolve directly to the function rather than going via the plt. | |
5394 | If people want function pointer comparisons to work as expected | |
5395 | then they should avoid writing weird assembly. */ | |
5396 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
5397 | { | |
5398 | struct ppc_elf_dyn_relocs **pp; | |
5399 | ||
5400 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
252b5132 | 5401 | { |
25dbc73a AM |
5402 | p->count -= p->pc_count; |
5403 | p->pc_count = 0; | |
5404 | if (p->count == 0) | |
5405 | *pp = p->next; | |
5406 | else | |
5407 | pp = &p->next; | |
252b5132 | 5408 | } |
25dbc73a | 5409 | } |
252b5132 | 5410 | |
3348747a NS |
5411 | if (htab->is_vxworks) |
5412 | { | |
5413 | struct ppc_elf_dyn_relocs **pp; | |
5414 | ||
5415 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5416 | { | |
5417 | if (strcmp (p->sec->output_section->name, ".tls_vars") == 0) | |
5418 | *pp = p->next; | |
5419 | else | |
5420 | pp = &p->next; | |
5421 | } | |
5422 | } | |
5423 | ||
89200bf8 AM |
5424 | /* Discard relocs on undefined symbols that must be local. */ |
5425 | if (eh->dyn_relocs != NULL | |
5426 | && h->root.type == bfd_link_hash_undefined | |
5427 | && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
5428 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL)) | |
5429 | eh->dyn_relocs = NULL; | |
5430 | ||
25dbc73a AM |
5431 | /* Also discard relocs on undefined weak syms with non-default |
5432 | visibility. */ | |
cab87ef9 AM |
5433 | if (eh->dyn_relocs != NULL |
5434 | && h->root.type == bfd_link_hash_undefweak) | |
25dbc73a | 5435 | { |
dfbb6ac9 AM |
5436 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
5437 | eh->dyn_relocs = NULL; | |
5438 | ||
5439 | /* Make sure undefined weak symbols are output as a dynamic | |
5440 | symbol in PIEs. */ | |
5441 | else if (h->dynindx == -1 | |
e054468f AM |
5442 | && !h->forced_local |
5443 | && !h->def_regular) | |
dfbb6ac9 AM |
5444 | { |
5445 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5446 | return FALSE; | |
5447 | } | |
25dbc73a AM |
5448 | } |
5449 | } | |
5450 | else if (ELIMINATE_COPY_RELOCS) | |
5451 | { | |
5452 | /* For the non-shared case, discard space for relocs against | |
5453 | symbols which turn out to need copy relocs or are not | |
5454 | dynamic. */ | |
7619e7c7 | 5455 | |
25dbc73a | 5456 | if (!h->non_got_ref |
25dbc73a AM |
5457 | && !h->def_regular) |
5458 | { | |
5459 | /* Make sure this symbol is output as a dynamic symbol. | |
5460 | Undefined weak syms won't yet be marked as dynamic. */ | |
5461 | if (h->dynindx == -1 | |
25f23106 | 5462 | && !h->forced_local) |
25dbc73a AM |
5463 | { |
5464 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5465 | return FALSE; | |
5466 | } | |
7619e7c7 | 5467 | |
25dbc73a AM |
5468 | /* If that succeeded, we know we'll be keeping all the |
5469 | relocs. */ | |
5470 | if (h->dynindx != -1) | |
5471 | goto keep; | |
5472 | } | |
252b5132 | 5473 | |
25dbc73a | 5474 | eh->dyn_relocs = NULL; |
252b5132 | 5475 | |
25dbc73a AM |
5476 | keep: ; |
5477 | } | |
252b5132 | 5478 | |
25dbc73a AM |
5479 | /* Finally, allocate space. */ |
5480 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5481 | { | |
5482 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
25f23106 AM |
5483 | if (!htab->elf.dynamic_sections_created) |
5484 | sreloc = htab->reliplt; | |
25dbc73a AM |
5485 | sreloc->size += p->count * sizeof (Elf32_External_Rela); |
5486 | } | |
252b5132 | 5487 | |
25dbc73a AM |
5488 | return TRUE; |
5489 | } | |
7619e7c7 | 5490 | |
625af618 AM |
5491 | /* Set DF_TEXTREL if we find any dynamic relocs that apply to |
5492 | read-only sections. */ | |
7619e7c7 | 5493 | |
25dbc73a | 5494 | static bfd_boolean |
625af618 | 5495 | maybe_set_textrel (struct elf_link_hash_entry *h, void *info) |
25dbc73a | 5496 | { |
25dbc73a AM |
5497 | if (h->root.type == bfd_link_hash_indirect) |
5498 | return TRUE; | |
252b5132 | 5499 | |
25dbc73a AM |
5500 | if (h->root.type == bfd_link_hash_warning) |
5501 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 5502 | |
625af618 | 5503 | if (readonly_dynrelocs (h)) |
25dbc73a | 5504 | { |
625af618 | 5505 | ((struct bfd_link_info *) info)->flags |= DF_TEXTREL; |
ee05f2fe | 5506 | |
625af618 AM |
5507 | /* Not an error, just cut short the traversal. */ |
5508 | return FALSE; | |
25dbc73a AM |
5509 | } |
5510 | return TRUE; | |
5511 | } | |
5512 | ||
5513 | /* Set the sizes of the dynamic sections. */ | |
5514 | ||
5515 | static bfd_boolean | |
5516 | ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, | |
5517 | struct bfd_link_info *info) | |
5518 | { | |
5519 | struct ppc_elf_link_hash_table *htab; | |
5520 | asection *s; | |
5521 | bfd_boolean relocs; | |
5522 | bfd *ibfd; | |
7fce784e | 5523 | |
252b5132 | 5524 | #ifdef DEBUG |
25dbc73a | 5525 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); |
252b5132 | 5526 | #endif |
252b5132 | 5527 | |
25dbc73a AM |
5528 | htab = ppc_elf_hash_table (info); |
5529 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
252b5132 | 5530 | |
25dbc73a AM |
5531 | if (elf_hash_table (info)->dynamic_sections_created) |
5532 | { | |
5533 | /* Set the contents of the .interp section to the interpreter. */ | |
5534 | if (info->executable) | |
5535 | { | |
5536 | s = bfd_get_section_by_name (htab->elf.dynobj, ".interp"); | |
5537 | BFD_ASSERT (s != NULL); | |
5538 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5539 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
5540 | } | |
5541 | } | |
252b5132 | 5542 | |
4a3dc543 | 5543 | if (htab->plt_type == PLT_OLD) |
d7128ce4 | 5544 | htab->got_header_size = 16; |
4a3dc543 | 5545 | else if (htab->plt_type == PLT_NEW) |
d7128ce4 | 5546 | htab->got_header_size = 12; |
252b5132 | 5547 | |
25dbc73a AM |
5548 | /* Set up .got offsets for local syms, and space for local dynamic |
5549 | relocs. */ | |
5550 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
5551 | { | |
5552 | bfd_signed_vma *local_got; | |
5553 | bfd_signed_vma *end_local_got; | |
e054468f AM |
5554 | struct plt_entry **local_plt; |
5555 | struct plt_entry **end_local_plt; | |
25dbc73a AM |
5556 | char *lgot_masks; |
5557 | bfd_size_type locsymcount; | |
5558 | Elf_Internal_Shdr *symtab_hdr; | |
7fce784e | 5559 | |
0c8d6e5c | 5560 | if (!is_ppc_elf (ibfd)) |
25dbc73a | 5561 | continue; |
7fce784e | 5562 | |
25dbc73a AM |
5563 | for (s = ibfd->sections; s != NULL; s = s->next) |
5564 | { | |
5565 | struct ppc_elf_dyn_relocs *p; | |
252b5132 | 5566 | |
25dbc73a AM |
5567 | for (p = ((struct ppc_elf_dyn_relocs *) |
5568 | elf_section_data (s)->local_dynrel); | |
5569 | p != NULL; | |
5570 | p = p->next) | |
5571 | { | |
5572 | if (!bfd_is_abs_section (p->sec) | |
5573 | && bfd_is_abs_section (p->sec->output_section)) | |
5574 | { | |
5575 | /* Input section has been discarded, either because | |
5576 | it is a copy of a linkonce section or due to | |
5577 | linker script /DISCARD/, so we'll be discarding | |
5578 | the relocs too. */ | |
7fce784e | 5579 | } |
3348747a NS |
5580 | else if (htab->is_vxworks |
5581 | && strcmp (p->sec->output_section->name, | |
5582 | ".tls_vars") == 0) | |
5583 | { | |
5584 | /* Relocations in vxworks .tls_vars sections are | |
5585 | handled specially by the loader. */ | |
5586 | } | |
25dbc73a | 5587 | else if (p->count != 0) |
7fce784e | 5588 | { |
25f23106 AM |
5589 | asection *sreloc = elf_section_data (p->sec)->sreloc; |
5590 | if (!htab->elf.dynamic_sections_created) | |
5591 | sreloc = htab->reliplt; | |
5592 | sreloc->size += p->count * sizeof (Elf32_External_Rela); | |
25dbc73a AM |
5593 | if ((p->sec->output_section->flags |
5594 | & (SEC_READONLY | SEC_ALLOC)) | |
5595 | == (SEC_READONLY | SEC_ALLOC)) | |
5596 | info->flags |= DF_TEXTREL; | |
7fce784e | 5597 | } |
252b5132 | 5598 | } |
252b5132 | 5599 | } |
252b5132 | 5600 | |
25dbc73a AM |
5601 | local_got = elf_local_got_refcounts (ibfd); |
5602 | if (!local_got) | |
5603 | continue; | |
252b5132 | 5604 | |
0ffa91dd | 5605 | symtab_hdr = &elf_symtab_hdr (ibfd); |
25dbc73a AM |
5606 | locsymcount = symtab_hdr->sh_info; |
5607 | end_local_got = local_got + locsymcount; | |
e054468f AM |
5608 | local_plt = (struct plt_entry **) end_local_got; |
5609 | end_local_plt = local_plt + locsymcount; | |
5610 | lgot_masks = (char *) end_local_plt; | |
91d6fa6a | 5611 | |
25dbc73a AM |
5612 | for (; local_got < end_local_got; ++local_got, ++lgot_masks) |
5613 | if (*local_got > 0) | |
5614 | { | |
d6e14abc AM |
5615 | unsigned int need = 0; |
5616 | if ((*lgot_masks & TLS_TLS) != 0) | |
25dbc73a | 5617 | { |
d6e14abc AM |
5618 | if ((*lgot_masks & TLS_GD) != 0) |
5619 | need += 8; | |
5620 | if ((*lgot_masks & TLS_LD) != 0) | |
5621 | htab->tlsld_got.refcount += 1; | |
5622 | if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
5623 | need += 4; | |
5624 | if ((*lgot_masks & TLS_DTPREL) != 0) | |
5625 | need += 4; | |
25dbc73a | 5626 | } |
d6e14abc AM |
5627 | else |
5628 | need += 4; | |
5629 | if (need == 0) | |
5630 | *local_got = (bfd_vma) -1; | |
25dbc73a AM |
5631 | else |
5632 | { | |
3b36f7e6 | 5633 | *local_got = allocate_got (htab, need); |
25dbc73a | 5634 | if (info->shared) |
3b36f7e6 AM |
5635 | htab->relgot->size += (need |
5636 | * (sizeof (Elf32_External_Rela) / 4)); | |
25dbc73a AM |
5637 | } |
5638 | } | |
5639 | else | |
5640 | *local_got = (bfd_vma) -1; | |
e054468f AM |
5641 | |
5642 | if (htab->is_vxworks) | |
5643 | continue; | |
5644 | ||
5645 | /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */ | |
5646 | for (; local_plt < end_local_plt; ++local_plt) | |
5647 | { | |
5648 | struct plt_entry *ent; | |
5649 | bfd_boolean doneone = FALSE; | |
5650 | bfd_vma plt_offset = 0, glink_offset = 0; | |
5651 | ||
5652 | for (ent = *local_plt; ent != NULL; ent = ent->next) | |
5653 | if (ent->plt.refcount > 0) | |
5654 | { | |
91d6fa6a | 5655 | s = htab->iplt; |
e054468f AM |
5656 | |
5657 | if (!doneone) | |
5658 | { | |
5659 | plt_offset = s->size; | |
5660 | s->size += 4; | |
5661 | } | |
5662 | ent->plt.offset = plt_offset; | |
5663 | ||
5664 | s = htab->glink; | |
a877a2b6 | 5665 | if (!doneone || info->shared) |
e054468f AM |
5666 | { |
5667 | glink_offset = s->size; | |
5668 | s->size += GLINK_ENTRY_SIZE; | |
5669 | } | |
5670 | ent->glink_offset = glink_offset; | |
5671 | ||
5672 | if (!doneone) | |
5673 | { | |
25f23106 | 5674 | htab->reliplt->size += sizeof (Elf32_External_Rela); |
e054468f AM |
5675 | doneone = TRUE; |
5676 | } | |
5677 | } | |
5678 | else | |
5679 | ent->plt.offset = (bfd_vma) -1; | |
5680 | } | |
25dbc73a | 5681 | } |
252b5132 | 5682 | |
b7fcf6f6 AM |
5683 | /* Allocate space for global sym dynamic relocs. */ |
5684 | elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info); | |
5685 | ||
3b36f7e6 AM |
5686 | if (htab->tlsld_got.refcount > 0) |
5687 | { | |
5688 | htab->tlsld_got.offset = allocate_got (htab, 8); | |
5689 | if (info->shared) | |
5690 | htab->relgot->size += sizeof (Elf32_External_Rela); | |
5691 | } | |
5692 | else | |
5693 | htab->tlsld_got.offset = (bfd_vma) -1; | |
5694 | ||
4a3dc543 | 5695 | if (htab->got != NULL && htab->plt_type != PLT_VXWORKS) |
3b36f7e6 AM |
5696 | { |
5697 | unsigned int g_o_t = 32768; | |
5698 | ||
4d962050 AM |
5699 | /* If we haven't allocated the header, do so now. When we get here, |
5700 | for old plt/got the got size will be 0 to 32764 (not allocated), | |
5701 | or 32780 to 65536 (header allocated). For new plt/got, the | |
5702 | corresponding ranges are 0 to 32768 and 32780 to 65536. */ | |
3b36f7e6 AM |
5703 | if (htab->got->size <= 32768) |
5704 | { | |
5705 | g_o_t = htab->got->size; | |
4a3dc543 | 5706 | if (htab->plt_type == PLT_OLD) |
4d962050 | 5707 | g_o_t += 4; |
3b36f7e6 AM |
5708 | htab->got->size += htab->got_header_size; |
5709 | } | |
3b36f7e6 AM |
5710 | |
5711 | htab->elf.hgot->root.u.def.value = g_o_t; | |
5712 | } | |
bd6c6e2b AM |
5713 | if (info->shared) |
5714 | { | |
5715 | struct elf_link_hash_entry *sda = htab->sdata[0].sym; | |
5716 | if (sda != NULL | |
5717 | && !(sda->root.type == bfd_link_hash_defined | |
5718 | || sda->root.type == bfd_link_hash_defweak)) | |
5719 | { | |
5720 | sda->root.type = bfd_link_hash_defined; | |
5721 | sda->root.u.def.section = htab->elf.hgot->root.u.def.section; | |
5722 | sda->root.u.def.value = htab->elf.hgot->root.u.def.value; | |
5723 | } | |
5724 | } | |
3b36f7e6 | 5725 | |
e054468f AM |
5726 | if (htab->glink != NULL |
5727 | && htab->glink->size != 0 | |
5728 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
5729 | { |
5730 | htab->glink_pltresolve = htab->glink->size; | |
86b9da88 AM |
5731 | /* Space for the branch table. */ |
5732 | htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4; | |
5733 | /* Pad out to align the start of PLTresolve. */ | |
5734 | htab->glink->size += -htab->glink->size & 15; | |
d7128ce4 | 5735 | htab->glink->size += GLINK_PLTRESOLVE; |
0ba07910 AM |
5736 | |
5737 | if (htab->emit_stub_syms) | |
5738 | { | |
5739 | struct elf_link_hash_entry *sh; | |
5740 | sh = elf_link_hash_lookup (&htab->elf, "__glink", | |
5741 | TRUE, FALSE, FALSE); | |
5742 | if (sh == NULL) | |
5743 | return FALSE; | |
5744 | if (sh->root.type == bfd_link_hash_new) | |
5745 | { | |
5746 | sh->root.type = bfd_link_hash_defined; | |
5747 | sh->root.u.def.section = htab->glink; | |
5748 | sh->root.u.def.value = htab->glink_pltresolve; | |
5749 | sh->ref_regular = 1; | |
5750 | sh->def_regular = 1; | |
5751 | sh->ref_regular_nonweak = 1; | |
5752 | sh->forced_local = 1; | |
5753 | sh->non_elf = 0; | |
5754 | } | |
5755 | sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve", | |
5756 | TRUE, FALSE, FALSE); | |
5757 | if (sh == NULL) | |
5758 | return FALSE; | |
5759 | if (sh->root.type == bfd_link_hash_new) | |
5760 | { | |
5761 | sh->root.type = bfd_link_hash_defined; | |
5762 | sh->root.u.def.section = htab->glink; | |
5763 | sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE; | |
5764 | sh->ref_regular = 1; | |
5765 | sh->def_regular = 1; | |
5766 | sh->ref_regular_nonweak = 1; | |
5767 | sh->forced_local = 1; | |
5768 | sh->non_elf = 0; | |
5769 | } | |
5770 | } | |
d7128ce4 AM |
5771 | } |
5772 | ||
25dbc73a AM |
5773 | /* We've now determined the sizes of the various dynamic sections. |
5774 | Allocate memory for them. */ | |
5775 | relocs = FALSE; | |
5776 | for (s = htab->elf.dynobj->sections; s != NULL; s = s->next) | |
252b5132 | 5777 | { |
9d8504b1 PB |
5778 | bfd_boolean strip_section = TRUE; |
5779 | ||
25dbc73a AM |
5780 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
5781 | continue; | |
252b5132 | 5782 | |
25dbc73a | 5783 | if (s == htab->plt |
e054468f | 5784 | || s == htab->got) |
25dbc73a | 5785 | { |
9d8504b1 PB |
5786 | /* We'd like to strip these sections if they aren't needed, but if |
5787 | we've exported dynamic symbols from them we must leave them. | |
5788 | It's too late to tell BFD to get rid of the symbols. */ | |
e054468f | 5789 | if (htab->elf.hplt != NULL) |
9d8504b1 | 5790 | strip_section = FALSE; |
25dbc73a AM |
5791 | /* Strip this section if we don't need it; see the |
5792 | comment below. */ | |
5793 | } | |
e054468f AM |
5794 | else if (s == htab->iplt |
5795 | || s == htab->glink | |
5796 | || s == htab->sgotplt | |
5797 | || s == htab->sbss | |
5798 | || s == htab->dynbss | |
5799 | || s == htab->dynsbss | |
5800 | || s == htab->sdata[0].section | |
c9a2f333 | 5801 | || s == htab->sdata[1].section) |
25dbc73a | 5802 | { |
c9a2f333 | 5803 | /* Strip these too. */ |
25dbc73a | 5804 | } |
0112cd26 | 5805 | else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) |
25dbc73a | 5806 | { |
c456f082 | 5807 | if (s->size != 0) |
25dbc73a AM |
5808 | { |
5809 | /* Remember whether there are any relocation sections. */ | |
5810 | relocs = TRUE; | |
252b5132 | 5811 | |
25dbc73a AM |
5812 | /* We use the reloc_count field as a counter if we need |
5813 | to copy relocs into the output file. */ | |
5814 | s->reloc_count = 0; | |
252b5132 RH |
5815 | } |
5816 | } | |
25dbc73a AM |
5817 | else |
5818 | { | |
5819 | /* It's not one of our sections, so don't allocate space. */ | |
5820 | continue; | |
5821 | } | |
252b5132 | 5822 | |
9d8504b1 | 5823 | if (s->size == 0 && strip_section) |
25dbc73a | 5824 | { |
c456f082 AM |
5825 | /* If we don't need this section, strip it from the |
5826 | output file. This is mostly to handle .rela.bss and | |
5827 | .rela.plt. We must create both sections in | |
5828 | create_dynamic_sections, because they must be created | |
5829 | before the linker maps input sections to output | |
5830 | sections. The linker does that before | |
5831 | adjust_dynamic_symbol is called, and it is that | |
5832 | function which decides whether anything needs to go | |
5833 | into these sections. */ | |
8423293d | 5834 | s->flags |= SEC_EXCLUDE; |
25dbc73a AM |
5835 | continue; |
5836 | } | |
7fce784e | 5837 | |
d7128ce4 | 5838 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
644285ef AM |
5839 | continue; |
5840 | ||
25dbc73a AM |
5841 | /* Allocate memory for the section contents. */ |
5842 | s->contents = bfd_zalloc (htab->elf.dynobj, s->size); | |
5843 | if (s->contents == NULL) | |
5844 | return FALSE; | |
5845 | } | |
252b5132 | 5846 | |
25dbc73a | 5847 | if (htab->elf.dynamic_sections_created) |
7619e7c7 | 5848 | { |
25dbc73a AM |
5849 | /* Add some entries to the .dynamic section. We fill in the |
5850 | values later, in ppc_elf_finish_dynamic_sections, but we | |
5851 | must add the entries now so that we get the correct size for | |
5852 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5853 | dynamic linker and used by the debugger. */ | |
5854 | #define add_dynamic_entry(TAG, VAL) \ | |
5855 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |
252b5132 | 5856 | |
25dbc73a | 5857 | if (info->executable) |
7619e7c7 | 5858 | { |
25dbc73a AM |
5859 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
5860 | return FALSE; | |
7619e7c7 AM |
5861 | } |
5862 | ||
25dbc73a | 5863 | if (htab->plt != NULL && htab->plt->size != 0) |
7619e7c7 | 5864 | { |
25dbc73a AM |
5865 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
5866 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
5867 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5868 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
5869 | return FALSE; | |
5870 | } | |
7619e7c7 | 5871 | |
d7128ce4 AM |
5872 | if (htab->glink != NULL && htab->glink->size != 0) |
5873 | { | |
1fe44d79 | 5874 | if (!add_dynamic_entry (DT_PPC_GOT, 0)) |
d7128ce4 | 5875 | return FALSE; |
a7f2871e AM |
5876 | if (!htab->no_tls_get_addr_opt |
5877 | && htab->tls_get_addr != NULL | |
5878 | && htab->tls_get_addr->plt.plist != NULL | |
5879 | && !add_dynamic_entry (DT_PPC_TLSOPT, 0)) | |
5880 | return FALSE; | |
d7128ce4 AM |
5881 | } |
5882 | ||
25dbc73a AM |
5883 | if (relocs) |
5884 | { | |
5885 | if (!add_dynamic_entry (DT_RELA, 0) | |
5886 | || !add_dynamic_entry (DT_RELASZ, 0) | |
5887 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
5888 | return FALSE; | |
5889 | } | |
7619e7c7 | 5890 | |
25dbc73a AM |
5891 | /* If any dynamic relocs apply to a read-only section, then we |
5892 | need a DT_TEXTREL entry. */ | |
5893 | if ((info->flags & DF_TEXTREL) == 0) | |
625af618 | 5894 | elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel, |
25dbc73a | 5895 | info); |
7619e7c7 | 5896 | |
25dbc73a AM |
5897 | if ((info->flags & DF_TEXTREL) != 0) |
5898 | { | |
5899 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
5900 | return FALSE; | |
7619e7c7 | 5901 | } |
7a2b07ff NS |
5902 | if (htab->is_vxworks |
5903 | && !elf_vxworks_add_dynamic_entries (output_bfd, info)) | |
5904 | return FALSE; | |
5905 | } | |
25dbc73a AM |
5906 | #undef add_dynamic_entry |
5907 | ||
7619e7c7 AM |
5908 | return TRUE; |
5909 | } | |
0eb4a168 AM |
5910 | |
5911 | /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ | |
5912 | ||
5913 | static bfd_boolean | |
5914 | ppc_elf_hash_symbol (struct elf_link_hash_entry *h) | |
5915 | { | |
5916 | if (h->plt.plist != NULL | |
5917 | && !h->def_regular | |
5918 | && (!h->pointer_equality_needed | |
5919 | || !h->ref_regular_nonweak)) | |
5920 | return FALSE; | |
5921 | ||
5922 | return _bfd_elf_hash_symbol (h); | |
5923 | } | |
25dbc73a AM |
5924 | \f |
5925 | #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) | |
5926 | ||
01017ef8 NS |
5927 | /* Relaxation trampolines. r12 is available for clobbering (r11, is |
5928 | used for some functions that are allowed to break the ABI). */ | |
25dbc73a AM |
5929 | static const int shared_stub_entry[] = |
5930 | { | |
5931 | 0x7c0802a6, /* mflr 0 */ | |
5932 | 0x429f0005, /* bcl 20, 31, .Lxxx */ | |
01017ef8 NS |
5933 | 0x7d8802a6, /* mflr 12 */ |
5934 | 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */ | |
5935 | 0x398c0008, /* addi 12, 12, (xxx-.Lxxx)@l */ | |
25dbc73a | 5936 | 0x7c0803a6, /* mtlr 0 */ |
01017ef8 | 5937 | 0x7d8903a6, /* mtctr 12 */ |
25dbc73a AM |
5938 | 0x4e800420, /* bctr */ |
5939 | }; | |
5940 | ||
5941 | static const int stub_entry[] = | |
5942 | { | |
01017ef8 NS |
5943 | 0x3d800000, /* lis 12,xxx@ha */ |
5944 | 0x398c0000, /* addi 12,12,xxx@l */ | |
5945 | 0x7d8903a6, /* mtctr 12 */ | |
25dbc73a AM |
5946 | 0x4e800420, /* bctr */ |
5947 | }; | |
5948 | ||
5949 | static bfd_boolean | |
5950 | ppc_elf_relax_section (bfd *abfd, | |
5951 | asection *isec, | |
5952 | struct bfd_link_info *link_info, | |
5953 | bfd_boolean *again) | |
5954 | { | |
5955 | struct one_fixup | |
5956 | { | |
5957 | struct one_fixup *next; | |
5958 | asection *tsec; | |
01017ef8 NS |
5959 | /* Final link, can use the symbol offset. For a |
5960 | relocatable link we use the symbol's index. */ | |
25dbc73a AM |
5961 | bfd_vma toff; |
5962 | bfd_vma trampoff; | |
5963 | }; | |
7619e7c7 | 5964 | |
25dbc73a AM |
5965 | Elf_Internal_Shdr *symtab_hdr; |
5966 | bfd_byte *contents = NULL; | |
5967 | Elf_Internal_Sym *isymbuf = NULL; | |
5968 | Elf_Internal_Rela *internal_relocs = NULL; | |
5969 | Elf_Internal_Rela *irel, *irelend; | |
5970 | struct one_fixup *fixups = NULL; | |
9bc4e62b | 5971 | unsigned changes = 0; |
d7128ce4 | 5972 | struct ppc_elf_link_hash_table *htab; |
25dbc73a | 5973 | bfd_size_type trampoff; |
a6aa5195 | 5974 | asection *got2; |
7619e7c7 | 5975 | |
25dbc73a | 5976 | *again = FALSE; |
7619e7c7 | 5977 | |
c87b5a93 | 5978 | /* Nothing to do if there are no relocations, and no need to do |
a8ad78a7 | 5979 | anything with non-alloc or non-code sections. */ |
c87b5a93 | 5980 | if ((isec->flags & SEC_ALLOC) == 0 |
a8ad78a7 | 5981 | || (isec->flags & SEC_CODE) == 0 |
c87b5a93 AM |
5982 | || (isec->flags & SEC_RELOC) == 0 |
5983 | || isec->reloc_count == 0) | |
25dbc73a | 5984 | return TRUE; |
7619e7c7 | 5985 | |
c8a1f254 NS |
5986 | /* We cannot represent the required PIC relocs in the output, so don't |
5987 | do anything. The linker doesn't support mixing -shared and -r | |
5988 | anyway. */ | |
5989 | if (link_info->relocatable && link_info->shared) | |
5990 | return TRUE; | |
5991 | ||
25dbc73a AM |
5992 | trampoff = (isec->size + 3) & (bfd_vma) -4; |
5993 | /* Space for a branch around any trampolines. */ | |
5994 | trampoff += 4; | |
7619e7c7 | 5995 | |
0ffa91dd | 5996 | symtab_hdr = &elf_symtab_hdr (abfd); |
7619e7c7 | 5997 | |
25dbc73a AM |
5998 | /* Get a copy of the native relocations. */ |
5999 | internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, | |
6000 | link_info->keep_memory); | |
6001 | if (internal_relocs == NULL) | |
6002 | goto error_return; | |
7619e7c7 | 6003 | |
d7128ce4 | 6004 | htab = ppc_elf_hash_table (link_info); |
a6aa5195 | 6005 | got2 = bfd_get_section_by_name (abfd, ".got2"); |
7619e7c7 | 6006 | |
a6aa5195 | 6007 | irelend = internal_relocs + isec->reloc_count; |
25dbc73a | 6008 | for (irel = internal_relocs; irel < irelend; irel++) |
7619e7c7 | 6009 | { |
25dbc73a | 6010 | unsigned long r_type = ELF32_R_TYPE (irel->r_info); |
91d6fa6a | 6011 | bfd_vma toff, roff; |
25dbc73a AM |
6012 | asection *tsec; |
6013 | struct one_fixup *f; | |
6014 | size_t insn_offset = 0; | |
6015 | bfd_vma max_branch_offset, val; | |
6016 | bfd_byte *hit_addr; | |
6017 | unsigned long t0; | |
de972ffa | 6018 | struct elf_link_hash_entry *h; |
a9585d22 | 6019 | struct plt_entry **plist; |
25dbc73a | 6020 | unsigned char sym_type; |
7619e7c7 | 6021 | |
25dbc73a AM |
6022 | switch (r_type) |
6023 | { | |
6024 | case R_PPC_REL24: | |
6025 | case R_PPC_LOCAL24PC: | |
6026 | case R_PPC_PLTREL24: | |
6027 | max_branch_offset = 1 << 25; | |
6028 | break; | |
7619e7c7 | 6029 | |
25dbc73a AM |
6030 | case R_PPC_REL14: |
6031 | case R_PPC_REL14_BRTAKEN: | |
6032 | case R_PPC_REL14_BRNTAKEN: | |
6033 | max_branch_offset = 1 << 15; | |
6034 | break; | |
7619e7c7 | 6035 | |
25dbc73a AM |
6036 | default: |
6037 | continue; | |
6038 | } | |
7619e7c7 | 6039 | |
25dbc73a | 6040 | /* Get the value of the symbol referred to by the reloc. */ |
de972ffa | 6041 | h = NULL; |
25dbc73a AM |
6042 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
6043 | { | |
6044 | /* A local symbol. */ | |
6045 | Elf_Internal_Sym *isym; | |
7fce784e | 6046 | |
25dbc73a AM |
6047 | /* Read this BFD's local symbols. */ |
6048 | if (isymbuf == NULL) | |
6049 | { | |
6050 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
6051 | if (isymbuf == NULL) | |
6052 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
6053 | symtab_hdr->sh_info, 0, | |
6054 | NULL, NULL, NULL); | |
6055 | if (isymbuf == 0) | |
6056 | goto error_return; | |
6057 | } | |
6058 | isym = isymbuf + ELF32_R_SYM (irel->r_info); | |
6059 | if (isym->st_shndx == SHN_UNDEF) | |
c8a1f254 | 6060 | tsec = bfd_und_section_ptr; |
25dbc73a AM |
6061 | else if (isym->st_shndx == SHN_ABS) |
6062 | tsec = bfd_abs_section_ptr; | |
6063 | else if (isym->st_shndx == SHN_COMMON) | |
6064 | tsec = bfd_com_section_ptr; | |
6065 | else | |
6066 | tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
7fce784e | 6067 | |
25dbc73a AM |
6068 | toff = isym->st_value; |
6069 | sym_type = ELF_ST_TYPE (isym->st_info); | |
6070 | } | |
6071 | else | |
6072 | { | |
6073 | /* Global symbol handling. */ | |
6074 | unsigned long indx; | |
7619e7c7 | 6075 | |
25dbc73a AM |
6076 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
6077 | h = elf_sym_hashes (abfd)[indx]; | |
7619e7c7 | 6078 | |
25dbc73a AM |
6079 | while (h->root.type == bfd_link_hash_indirect |
6080 | || h->root.type == bfd_link_hash_warning) | |
6081 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 6082 | |
a9585d22 AM |
6083 | if (h->root.type == bfd_link_hash_defined |
6084 | || h->root.type == bfd_link_hash_defweak) | |
25dbc73a AM |
6085 | { |
6086 | tsec = h->root.u.def.section; | |
6087 | toff = h->root.u.def.value; | |
6088 | } | |
c8a1f254 NS |
6089 | else if (h->root.type == bfd_link_hash_undefined |
6090 | || h->root.type == bfd_link_hash_undefweak) | |
6091 | { | |
6092 | tsec = bfd_und_section_ptr; | |
01017ef8 | 6093 | toff = link_info->relocatable ? indx : 0; |
c8a1f254 | 6094 | } |
25dbc73a AM |
6095 | else |
6096 | continue; | |
7619e7c7 | 6097 | |
25dbc73a AM |
6098 | sym_type = h->type; |
6099 | } | |
7619e7c7 | 6100 | |
a9585d22 AM |
6101 | /* The condition here under which we call find_plt_ent must |
6102 | match that in relocate_section. If we call find_plt_ent here | |
6103 | but not in relocate_section, or vice versa, then the branch | |
6104 | destination used here may be incorrect. */ | |
6105 | plist = NULL; | |
6106 | if (h != NULL) | |
de972ffa | 6107 | { |
a9585d22 AM |
6108 | /* We know is_branch_reloc (r_type) is true. */ |
6109 | if (h->type == STT_GNU_IFUNC | |
6110 | || r_type == R_PPC_PLTREL24) | |
de972ffa | 6111 | plist = &h->plt.plist; |
a9585d22 AM |
6112 | } |
6113 | else if (sym_type == STT_GNU_IFUNC | |
6114 | && elf_local_got_offsets (abfd) != NULL) | |
6115 | { | |
6116 | bfd_vma *local_got_offsets = elf_local_got_offsets (abfd); | |
6117 | struct plt_entry **local_plt = (struct plt_entry **) | |
6118 | (local_got_offsets + symtab_hdr->sh_info); | |
6119 | plist = local_plt + ELF32_R_SYM (irel->r_info); | |
6120 | } | |
6121 | if (plist != NULL) | |
6122 | { | |
6123 | bfd_vma addend = 0; | |
6124 | struct plt_entry *ent; | |
de972ffa | 6125 | |
a9585d22 AM |
6126 | if (r_type == R_PPC_PLTREL24 && link_info->shared) |
6127 | addend = irel->r_addend; | |
6128 | ent = find_plt_ent (plist, got2, addend); | |
6129 | if (ent != NULL) | |
6130 | { | |
6131 | if (htab->plt_type == PLT_NEW | |
6132 | || h == NULL | |
6133 | || !htab->elf.dynamic_sections_created | |
6134 | || h->dynindx == -1) | |
de972ffa | 6135 | { |
a9585d22 AM |
6136 | tsec = htab->glink; |
6137 | toff = ent->glink_offset; | |
6138 | } | |
6139 | else | |
6140 | { | |
6141 | tsec = htab->plt; | |
6142 | toff = ent->plt.offset; | |
de972ffa AM |
6143 | } |
6144 | } | |
6145 | } | |
6146 | ||
25dbc73a AM |
6147 | /* If the branch and target are in the same section, you have |
6148 | no hope of adding stubs. We'll error out later should the | |
6149 | branch overflow. */ | |
6150 | if (tsec == isec) | |
6151 | continue; | |
6152 | ||
6153 | /* There probably isn't any reason to handle symbols in | |
6154 | SEC_MERGE sections; SEC_MERGE doesn't seem a likely | |
6155 | attribute for a code section, and we are only looking at | |
6156 | branches. However, implement it correctly here as a | |
6157 | reference for other target relax_section functions. */ | |
6158 | if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE) | |
6159 | { | |
6160 | /* At this stage in linking, no SEC_MERGE symbol has been | |
6161 | adjusted, so all references to such symbols need to be | |
6162 | passed through _bfd_merged_section_offset. (Later, in | |
6163 | relocate_section, all SEC_MERGE symbols *except* for | |
6164 | section symbols have been adjusted.) | |
6165 | ||
6166 | gas may reduce relocations against symbols in SEC_MERGE | |
6167 | sections to a relocation against the section symbol when | |
6168 | the original addend was zero. When the reloc is against | |
6169 | a section symbol we should include the addend in the | |
6170 | offset passed to _bfd_merged_section_offset, since the | |
6171 | location of interest is the original symbol. On the | |
6172 | other hand, an access to "sym+addend" where "sym" is not | |
6173 | a section symbol should not include the addend; Such an | |
6174 | access is presumed to be an offset from "sym"; The | |
6175 | location of interest is just "sym". */ | |
6176 | if (sym_type == STT_SECTION) | |
6177 | toff += irel->r_addend; | |
7619e7c7 | 6178 | |
25dbc73a AM |
6179 | toff = _bfd_merged_section_offset (abfd, &tsec, |
6180 | elf_section_data (tsec)->sec_info, | |
6181 | toff); | |
7619e7c7 | 6182 | |
25dbc73a AM |
6183 | if (sym_type != STT_SECTION) |
6184 | toff += irel->r_addend; | |
6185 | } | |
a6aa5195 AM |
6186 | /* PLTREL24 addends are special. */ |
6187 | else if (r_type != R_PPC_PLTREL24) | |
25dbc73a | 6188 | toff += irel->r_addend; |
7619e7c7 | 6189 | |
7de713b9 AM |
6190 | /* Attempted -shared link of non-pic code loses. */ |
6191 | if (tsec->output_section == NULL) | |
6192 | continue; | |
6193 | ||
25dbc73a | 6194 | roff = irel->r_offset; |
7619e7c7 | 6195 | |
25dbc73a | 6196 | /* If the branch is in range, no need to do anything. */ |
c8a1f254 NS |
6197 | if (tsec != bfd_und_section_ptr |
6198 | && (!link_info->relocatable | |
6199 | /* A relocatable link may have sections moved during | |
6200 | final link, so do not presume they remain in range. */ | |
01017ef8 NS |
6201 | || tsec->output_section == isec->output_section)) |
6202 | { | |
6203 | bfd_vma symaddr, reladdr; | |
6204 | ||
6205 | symaddr = tsec->output_section->vma + tsec->output_offset + toff; | |
6206 | reladdr = isec->output_section->vma + isec->output_offset + roff; | |
6207 | if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset) | |
6208 | continue; | |
6209 | } | |
252b5132 | 6210 | |
25dbc73a AM |
6211 | /* Look for an existing fixup to this address. */ |
6212 | for (f = fixups; f ; f = f->next) | |
6213 | if (f->tsec == tsec && f->toff == toff) | |
6214 | break; | |
6215 | ||
6216 | if (f == NULL) | |
7619e7c7 | 6217 | { |
25dbc73a AM |
6218 | size_t size; |
6219 | unsigned long stub_rtype; | |
252b5132 | 6220 | |
25dbc73a AM |
6221 | val = trampoff - roff; |
6222 | if (val >= max_branch_offset) | |
6223 | /* Oh dear, we can't reach a trampoline. Don't try to add | |
6224 | one. We'll report an error later. */ | |
6225 | continue; | |
252b5132 | 6226 | |
25dbc73a AM |
6227 | if (link_info->shared) |
6228 | { | |
6229 | size = 4 * ARRAY_SIZE (shared_stub_entry); | |
6230 | insn_offset = 12; | |
25dbc73a AM |
6231 | } |
6232 | else | |
6233 | { | |
6234 | size = 4 * ARRAY_SIZE (stub_entry); | |
6235 | insn_offset = 0; | |
25dbc73a | 6236 | } |
32af9f6e | 6237 | stub_rtype = R_PPC_RELAX; |
d7128ce4 AM |
6238 | if (tsec == htab->plt |
6239 | || tsec == htab->glink) | |
32af9f6e AM |
6240 | { |
6241 | stub_rtype = R_PPC_RELAX_PLT; | |
6242 | if (r_type == R_PPC_PLTREL24) | |
6243 | stub_rtype = R_PPC_RELAX_PLTREL24; | |
6244 | } | |
252b5132 | 6245 | |
25dbc73a AM |
6246 | /* Hijack the old relocation. Since we need two |
6247 | relocations for this use a "composite" reloc. */ | |
6248 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
6249 | stub_rtype); | |
6250 | irel->r_offset = trampoff + insn_offset; | |
32af9f6e AM |
6251 | if (r_type == R_PPC_PLTREL24 |
6252 | && stub_rtype != R_PPC_RELAX_PLTREL24) | |
e7d92e2e | 6253 | irel->r_addend = 0; |
252b5132 | 6254 | |
25dbc73a AM |
6255 | /* Record the fixup so we don't do it again this section. */ |
6256 | f = bfd_malloc (sizeof (*f)); | |
6257 | f->next = fixups; | |
6258 | f->tsec = tsec; | |
6259 | f->toff = toff; | |
6260 | f->trampoff = trampoff; | |
6261 | fixups = f; | |
252b5132 | 6262 | |
25dbc73a | 6263 | trampoff += size; |
9bc4e62b | 6264 | changes++; |
25dbc73a AM |
6265 | } |
6266 | else | |
6267 | { | |
6268 | val = f->trampoff - roff; | |
6269 | if (val >= max_branch_offset) | |
6270 | continue; | |
252b5132 | 6271 | |
25dbc73a AM |
6272 | /* Nop out the reloc, since we're finalizing things here. */ |
6273 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
6274 | } | |
252b5132 | 6275 | |
25dbc73a AM |
6276 | /* Get the section contents. */ |
6277 | if (contents == NULL) | |
6278 | { | |
6279 | /* Get cached copy if it exists. */ | |
6280 | if (elf_section_data (isec)->this_hdr.contents != NULL) | |
6281 | contents = elf_section_data (isec)->this_hdr.contents; | |
6282 | else | |
6283 | { | |
6284 | /* Go get them off disk. */ | |
6285 | if (!bfd_malloc_and_get_section (abfd, isec, &contents)) | |
6286 | goto error_return; | |
6287 | } | |
6288 | } | |
252b5132 | 6289 | |
25dbc73a AM |
6290 | /* Fix up the existing branch to hit the trampoline. */ |
6291 | hit_addr = contents + roff; | |
6292 | switch (r_type) | |
6293 | { | |
6294 | case R_PPC_REL24: | |
6295 | case R_PPC_LOCAL24PC: | |
6296 | case R_PPC_PLTREL24: | |
6297 | t0 = bfd_get_32 (abfd, hit_addr); | |
6298 | t0 &= ~0x3fffffc; | |
6299 | t0 |= val & 0x3fffffc; | |
6300 | bfd_put_32 (abfd, t0, hit_addr); | |
6301 | break; | |
252b5132 | 6302 | |
25dbc73a AM |
6303 | case R_PPC_REL14: |
6304 | case R_PPC_REL14_BRTAKEN: | |
6305 | case R_PPC_REL14_BRNTAKEN: | |
6306 | t0 = bfd_get_32 (abfd, hit_addr); | |
6307 | t0 &= ~0xfffc; | |
6308 | t0 |= val & 0xfffc; | |
6309 | bfd_put_32 (abfd, t0, hit_addr); | |
6310 | break; | |
6311 | } | |
6312 | } | |
252b5132 | 6313 | |
25dbc73a | 6314 | /* Write out the trampolines. */ |
25dbc73a AM |
6315 | if (fixups != NULL) |
6316 | { | |
6317 | const int *stub; | |
6318 | bfd_byte *dest; | |
6319 | bfd_vma val; | |
6320 | int i, size; | |
252b5132 | 6321 | |
25dbc73a AM |
6322 | do |
6323 | { | |
6324 | struct one_fixup *f = fixups; | |
6325 | fixups = fixups->next; | |
6326 | free (f); | |
6327 | } | |
6328 | while (fixups); | |
252b5132 | 6329 | |
515ef31d | 6330 | contents = bfd_realloc_or_free (contents, trampoff); |
25dbc73a AM |
6331 | if (contents == NULL) |
6332 | goto error_return; | |
252b5132 | 6333 | |
25dbc73a AM |
6334 | isec->size = (isec->size + 3) & (bfd_vma) -4; |
6335 | /* Branch around the trampolines. */ | |
e7d92e2e | 6336 | val = B + trampoff - isec->size; |
25dbc73a AM |
6337 | dest = contents + isec->size; |
6338 | isec->size = trampoff; | |
6339 | bfd_put_32 (abfd, val, dest); | |
6340 | dest += 4; | |
252b5132 | 6341 | |
25dbc73a AM |
6342 | if (link_info->shared) |
6343 | { | |
6344 | stub = shared_stub_entry; | |
6345 | size = ARRAY_SIZE (shared_stub_entry); | |
6346 | } | |
6347 | else | |
6348 | { | |
6349 | stub = stub_entry; | |
6350 | size = ARRAY_SIZE (stub_entry); | |
6351 | } | |
252b5132 | 6352 | |
25dbc73a AM |
6353 | i = 0; |
6354 | while (dest < contents + trampoff) | |
252b5132 | 6355 | { |
25dbc73a AM |
6356 | bfd_put_32 (abfd, stub[i], dest); |
6357 | i++; | |
6358 | if (i == size) | |
6359 | i = 0; | |
6360 | dest += 4; | |
252b5132 | 6361 | } |
25dbc73a | 6362 | BFD_ASSERT (i == 0); |
252b5132 RH |
6363 | } |
6364 | ||
25dbc73a AM |
6365 | if (isymbuf != NULL |
6366 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
252b5132 | 6367 | { |
25dbc73a AM |
6368 | if (! link_info->keep_memory) |
6369 | free (isymbuf); | |
252b5132 | 6370 | else |
25dbc73a AM |
6371 | { |
6372 | /* Cache the symbols for elf_link_input_bfd. */ | |
6373 | symtab_hdr->contents = (unsigned char *) isymbuf; | |
6374 | } | |
252b5132 RH |
6375 | } |
6376 | ||
25dbc73a AM |
6377 | if (contents != NULL |
6378 | && elf_section_data (isec)->this_hdr.contents != contents) | |
6379 | { | |
9bc4e62b | 6380 | if (!changes && !link_info->keep_memory) |
25dbc73a AM |
6381 | free (contents); |
6382 | else | |
6383 | { | |
6384 | /* Cache the section contents for elf_link_input_bfd. */ | |
6385 | elf_section_data (isec)->this_hdr.contents = contents; | |
6386 | } | |
6387 | } | |
252b5132 | 6388 | |
9bc4e62b | 6389 | if (changes != 0) |
25dbc73a | 6390 | { |
9bc4e62b NS |
6391 | /* Append sufficient NOP relocs so we can write out relocation |
6392 | information for the trampolines. */ | |
6393 | Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count) | |
6394 | * sizeof (*new_relocs)); | |
6395 | unsigned ix; | |
6396 | ||
6397 | if (!new_relocs) | |
6398 | goto error_return; | |
6399 | memcpy (new_relocs, internal_relocs, | |
6400 | isec->reloc_count * sizeof (*new_relocs)); | |
6401 | for (ix = changes; ix--;) | |
6402 | { | |
6403 | irel = new_relocs + ix + isec->reloc_count; | |
6404 | ||
6405 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
6406 | } | |
6407 | if (internal_relocs != elf_section_data (isec)->relocs) | |
25dbc73a | 6408 | free (internal_relocs); |
9bc4e62b NS |
6409 | elf_section_data (isec)->relocs = new_relocs; |
6410 | isec->reloc_count += changes; | |
6411 | elf_section_data (isec)->rel_hdr.sh_size | |
6412 | += changes * elf_section_data (isec)->rel_hdr.sh_entsize; | |
25dbc73a | 6413 | } |
9bc4e62b NS |
6414 | else if (elf_section_data (isec)->relocs != internal_relocs) |
6415 | free (internal_relocs); | |
252b5132 | 6416 | |
9bc4e62b | 6417 | *again = changes != 0; |
c8a1f254 NS |
6418 | if (!*again && link_info->relocatable) |
6419 | { | |
6420 | /* Convert the internal relax relocs to external form. */ | |
6421 | for (irel = internal_relocs; irel < irelend; irel++) | |
32af9f6e | 6422 | if (ELF32_R_TYPE (irel->r_info) == R_PPC_RELAX) |
c8a1f254 NS |
6423 | { |
6424 | unsigned long r_symndx = ELF32_R_SYM (irel->r_info); | |
6425 | ||
6426 | /* Rewrite the reloc and convert one of the trailing nop | |
6427 | relocs to describe this relocation. */ | |
6428 | BFD_ASSERT (ELF32_R_TYPE (irelend[-1].r_info) == R_PPC_NONE); | |
6429 | /* The relocs are at the bottom 2 bytes */ | |
6430 | irel[0].r_offset += 2; | |
6431 | memmove (irel + 1, irel, (irelend - irel - 1) * sizeof (*irel)); | |
6432 | irel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); | |
6433 | irel[1].r_offset += 4; | |
6434 | irel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); | |
6435 | irel++; | |
6436 | } | |
6437 | } | |
6438 | ||
b34976b6 | 6439 | return TRUE; |
25dbc73a AM |
6440 | |
6441 | error_return: | |
6442 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents) | |
6443 | free (isymbuf); | |
6444 | if (contents != NULL | |
6445 | && elf_section_data (isec)->this_hdr.contents != contents) | |
6446 | free (contents); | |
6447 | if (internal_relocs != NULL | |
6448 | && elf_section_data (isec)->relocs != internal_relocs) | |
6449 | free (internal_relocs); | |
6450 | return FALSE; | |
252b5132 | 6451 | } |
252b5132 | 6452 | \f |
8a696751 AM |
6453 | /* What to do when ld finds relocations against symbols defined in |
6454 | discarded sections. */ | |
6455 | ||
6456 | static unsigned int | |
6457 | ppc_elf_action_discarded (asection *sec) | |
6458 | { | |
6459 | if (strcmp (".fixup", sec->name) == 0) | |
6460 | return 0; | |
6461 | ||
6462 | if (strcmp (".got2", sec->name) == 0) | |
6463 | return 0; | |
6464 | ||
6465 | return _bfd_elf_default_action_discarded (sec); | |
6466 | } | |
c9a2f333 | 6467 | \f |
25dbc73a | 6468 | /* Fill in the address for a pointer generated in a linker section. */ |
252b5132 | 6469 | |
25dbc73a | 6470 | static bfd_vma |
76750a2f | 6471 | elf_finish_pointer_linker_section (bfd *input_bfd, |
25dbc73a AM |
6472 | elf_linker_section_t *lsect, |
6473 | struct elf_link_hash_entry *h, | |
6474 | bfd_vma relocation, | |
2bb04cf2 | 6475 | const Elf_Internal_Rela *rel) |
25dbc73a AM |
6476 | { |
6477 | elf_linker_section_pointers_t *linker_section_ptr; | |
252b5132 | 6478 | |
25dbc73a | 6479 | BFD_ASSERT (lsect != NULL); |
252b5132 | 6480 | |
25dbc73a | 6481 | if (h != NULL) |
252b5132 | 6482 | { |
25dbc73a AM |
6483 | /* Handle global symbol. */ |
6484 | struct ppc_elf_link_hash_entry *eh; | |
252b5132 | 6485 | |
25dbc73a | 6486 | eh = (struct ppc_elf_link_hash_entry *) h; |
76750a2f AM |
6487 | BFD_ASSERT (eh->elf.def_regular); |
6488 | linker_section_ptr = eh->linker_section_pointer; | |
25dbc73a AM |
6489 | } |
6490 | else | |
6491 | { | |
6492 | /* Handle local symbol. */ | |
6493 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
76750a2f | 6494 | |
0c8d6e5c | 6495 | BFD_ASSERT (is_ppc_elf (input_bfd)); |
25dbc73a | 6496 | BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); |
76750a2f AM |
6497 | linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx]; |
6498 | } | |
252b5132 | 6499 | |
76750a2f AM |
6500 | linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr, |
6501 | rel->r_addend, | |
6502 | lsect); | |
6503 | BFD_ASSERT (linker_section_ptr != NULL); | |
25dbc73a | 6504 | |
76750a2f AM |
6505 | /* Offset will always be a multiple of four, so use the bottom bit |
6506 | as a "written" flag. */ | |
6507 | if ((linker_section_ptr->offset & 1) == 0) | |
6508 | { | |
6509 | bfd_put_32 (lsect->section->owner, | |
6510 | relocation + linker_section_ptr->addend, | |
6511 | lsect->section->contents + linker_section_ptr->offset); | |
6512 | linker_section_ptr->offset += 1; | |
252b5132 RH |
6513 | } |
6514 | ||
bd6c6e2b AM |
6515 | relocation = (lsect->section->output_section->vma |
6516 | + lsect->section->output_offset | |
76750a2f | 6517 | + linker_section_ptr->offset - 1 |
bd6c6e2b | 6518 | - SYM_VAL (lsect->sym)); |
252b5132 | 6519 | |
25dbc73a AM |
6520 | #ifdef DEBUG |
6521 | fprintf (stderr, | |
6522 | "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", | |
6523 | lsect->name, (long) relocation, (long) relocation); | |
6524 | #endif | |
252b5132 | 6525 | |
bd6c6e2b | 6526 | return relocation; |
252b5132 | 6527 | } |
25dbc73a | 6528 | |
e054468f AM |
6529 | #define PPC_LO(v) ((v) & 0xffff) |
6530 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6531 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6532 | ||
6533 | static void | |
a7f2871e | 6534 | write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p, |
e054468f AM |
6535 | struct bfd_link_info *info) |
6536 | { | |
6537 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); | |
6538 | bfd *output_bfd = info->output_bfd; | |
6539 | bfd_vma plt; | |
e054468f AM |
6540 | |
6541 | plt = ((ent->plt.offset & ~1) | |
6542 | + plt_sec->output_section->vma | |
6543 | + plt_sec->output_offset); | |
e054468f | 6544 | |
a877a2b6 | 6545 | if (info->shared) |
e054468f AM |
6546 | { |
6547 | bfd_vma got = 0; | |
6548 | ||
6549 | if (ent->addend >= 32768) | |
6550 | got = (ent->addend | |
6551 | + ent->sec->output_section->vma | |
6552 | + ent->sec->output_offset); | |
6553 | else if (htab->elf.hgot != NULL) | |
6554 | got = SYM_VAL (htab->elf.hgot); | |
6555 | ||
6556 | plt -= got; | |
6557 | ||
6558 | if (plt + 0x8000 < 0x10000) | |
6559 | { | |
6560 | bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p); | |
6561 | p += 4; | |
6562 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6563 | p += 4; | |
6564 | bfd_put_32 (output_bfd, BCTR, p); | |
6565 | p += 4; | |
6566 | bfd_put_32 (output_bfd, NOP, p); | |
6567 | p += 4; | |
6568 | } | |
6569 | else | |
6570 | { | |
6571 | bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p); | |
6572 | p += 4; | |
6573 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
6574 | p += 4; | |
6575 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6576 | p += 4; | |
6577 | bfd_put_32 (output_bfd, BCTR, p); | |
6578 | p += 4; | |
6579 | } | |
6580 | } | |
6581 | else | |
6582 | { | |
6583 | bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p); | |
6584 | p += 4; | |
6585 | bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p); | |
6586 | p += 4; | |
6587 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6588 | p += 4; | |
6589 | bfd_put_32 (output_bfd, BCTR, p); | |
6590 | p += 4; | |
6591 | } | |
6592 | } | |
6593 | ||
bd6c6e2b AM |
6594 | /* Return true if symbol is defined statically. */ |
6595 | ||
6596 | static bfd_boolean | |
6597 | is_static_defined (struct elf_link_hash_entry *h) | |
6598 | { | |
6599 | return ((h->root.type == bfd_link_hash_defined | |
6600 | || h->root.type == bfd_link_hash_defweak) | |
6601 | && h->root.u.def.section != NULL | |
6602 | && h->root.u.def.section->output_section != NULL); | |
6603 | } | |
6604 | ||
2d0f3896 AM |
6605 | /* If INSN is an opcode that may be used with an @tls operand, return |
6606 | the transformed insn for TLS optimisation, otherwise return 0. If | |
6607 | REG is non-zero only match an insn with RB or RA equal to REG. */ | |
6608 | ||
6609 | unsigned int | |
6610 | _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg) | |
6611 | { | |
6612 | unsigned int rtra; | |
6613 | ||
6614 | if ((insn & (0x3f << 26)) != 31 << 26) | |
6615 | return 0; | |
6616 | ||
6617 | if (reg == 0 || ((insn >> 11) & 0x1f) == reg) | |
6618 | rtra = insn & ((1 << 26) - (1 << 16)); | |
6619 | else if (((insn >> 16) & 0x1f) == reg) | |
6620 | rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5); | |
6621 | else | |
6622 | return 0; | |
6623 | ||
6624 | if ((insn & (0x3ff << 1)) == 266 << 1) | |
6625 | /* add -> addi. */ | |
6626 | insn = 14 << 26; | |
6627 | else if ((insn & (0x1f << 1)) == 23 << 1 | |
6628 | && ((insn & (0x1f << 6)) < 14 << 6 | |
6629 | || ((insn & (0x1f << 6)) >= 16 << 6 | |
6630 | && (insn & (0x1f << 6)) < 24 << 6))) | |
6631 | /* load and store indexed -> dform. */ | |
6632 | insn = (32 | ((insn >> 6) & 0x1f)) << 26; | |
6633 | else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1) | |
6634 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
6635 | insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1); | |
6636 | else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1) | |
6637 | /* lwax -> lwa. */ | |
6638 | insn = (58 << 26) | 2; | |
6639 | else | |
6640 | return 0; | |
6641 | insn |= rtra; | |
6642 | return insn; | |
6643 | } | |
6644 | ||
766bc656 AM |
6645 | /* If INSN is an opcode that may be used with an @tprel operand, return |
6646 | the transformed insn for an undefined weak symbol, ie. with the | |
6647 | thread pointer REG operand removed. Otherwise return 0. */ | |
6648 | ||
6649 | unsigned int | |
6650 | _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg) | |
6651 | { | |
6652 | if ((insn & (0x1f << 16)) == reg << 16 | |
6653 | && ((insn & (0x3f << 26)) == 14u << 26 /* addi */ | |
6654 | || (insn & (0x3f << 26)) == 15u << 26 /* addis */ | |
6655 | || (insn & (0x3f << 26)) == 32u << 26 /* lwz */ | |
6656 | || (insn & (0x3f << 26)) == 34u << 26 /* lbz */ | |
6657 | || (insn & (0x3f << 26)) == 36u << 26 /* stw */ | |
6658 | || (insn & (0x3f << 26)) == 38u << 26 /* stb */ | |
6659 | || (insn & (0x3f << 26)) == 40u << 26 /* lhz */ | |
6660 | || (insn & (0x3f << 26)) == 42u << 26 /* lha */ | |
6661 | || (insn & (0x3f << 26)) == 44u << 26 /* sth */ | |
6662 | || (insn & (0x3f << 26)) == 46u << 26 /* lmw */ | |
6663 | || (insn & (0x3f << 26)) == 47u << 26 /* stmw */ | |
6664 | || (insn & (0x3f << 26)) == 48u << 26 /* lfs */ | |
6665 | || (insn & (0x3f << 26)) == 50u << 26 /* lfd */ | |
6666 | || (insn & (0x3f << 26)) == 52u << 26 /* stfs */ | |
6667 | || (insn & (0x3f << 26)) == 54u << 26 /* stfd */ | |
6668 | || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */ | |
6669 | && (insn & 3) != 1) | |
6670 | || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */ | |
6671 | && ((insn & 3) == 0 || (insn & 3) == 3)))) | |
6672 | { | |
6673 | insn &= ~(0x1f << 16); | |
6674 | } | |
6675 | else if ((insn & (0x1f << 21)) == reg << 21 | |
6676 | && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */ | |
6677 | || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */ | |
6678 | || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */)) | |
6679 | { | |
6680 | insn &= ~(0x1f << 21); | |
6681 | insn |= (insn & (0x1f << 16)) << 5; | |
6682 | if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */) | |
6683 | insn -= 2 >> 26; /* convert to ori,oris */ | |
6684 | } | |
6685 | else | |
6686 | insn = 0; | |
6687 | return insn; | |
6688 | } | |
6689 | ||
252b5132 RH |
6690 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
6691 | to handle the relocations for a section. | |
6692 | ||
6693 | The relocs are always passed as Rela structures; if the section | |
6694 | actually uses Rel structures, the r_addend field will always be | |
6695 | zero. | |
6696 | ||
6697 | This function is responsible for adjust the section contents as | |
6698 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 6699 | relocatable output file) adjusting the reloc addend as |
252b5132 RH |
6700 | necessary. |
6701 | ||
6702 | This function does not have to worry about setting the reloc | |
6703 | address or the reloc symbol index. | |
6704 | ||
6705 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
6706 | ||
6707 | LOCAL_SECTIONS is an array giving the section in the input file | |
6708 | corresponding to the st_shndx field of each local symbol. | |
6709 | ||
6710 | The global hash table entry for the global symbols can be found | |
6711 | via elf_sym_hashes (input_bfd). | |
6712 | ||
1049f94e | 6713 | When generating relocatable output, this function must handle |
252b5132 RH |
6714 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
6715 | going to be the section symbol corresponding to the output | |
6716 | section, which means that the addend must be adjusted | |
6717 | accordingly. */ | |
6718 | ||
b34976b6 | 6719 | static bfd_boolean |
55fd94b0 AM |
6720 | ppc_elf_relocate_section (bfd *output_bfd, |
6721 | struct bfd_link_info *info, | |
6722 | bfd *input_bfd, | |
6723 | asection *input_section, | |
6724 | bfd_byte *contents, | |
6725 | Elf_Internal_Rela *relocs, | |
6726 | Elf_Internal_Sym *local_syms, | |
6727 | asection **local_sections) | |
252b5132 | 6728 | { |
7619e7c7 AM |
6729 | Elf_Internal_Shdr *symtab_hdr; |
6730 | struct elf_link_hash_entry **sym_hashes; | |
6731 | struct ppc_elf_link_hash_table *htab; | |
6732 | Elf_Internal_Rela *rel; | |
6733 | Elf_Internal_Rela *relend; | |
6734 | Elf_Internal_Rela outrel; | |
a6aa5195 | 6735 | asection *got2, *sreloc = NULL; |
252b5132 | 6736 | bfd_vma *local_got_offsets; |
b34976b6 | 6737 | bfd_boolean ret = TRUE; |
4fe5ca5b | 6738 | bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0); |
3348747a | 6739 | bfd_boolean is_vxworks_tls; |
b34976b6 | 6740 | |
252b5132 | 6741 | #ifdef DEBUG |
d003868e AM |
6742 | _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, " |
6743 | "%ld relocations%s", | |
6744 | input_bfd, input_section, | |
6745 | (long) input_section->reloc_count, | |
6746 | (info->relocatable) ? " (relocatable)" : ""); | |
252b5132 RH |
6747 | #endif |
6748 | ||
a6aa5195 AM |
6749 | got2 = bfd_get_section_by_name (input_bfd, ".got2"); |
6750 | ||
e47cd125 | 6751 | /* Initialize howto table if not already done. */ |
8da6118f | 6752 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
252b5132 RH |
6753 | ppc_elf_howto_init (); |
6754 | ||
7619e7c7 | 6755 | htab = ppc_elf_hash_table (info); |
252b5132 | 6756 | local_got_offsets = elf_local_got_offsets (input_bfd); |
0ffa91dd | 6757 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
7619e7c7 | 6758 | sym_hashes = elf_sym_hashes (input_bfd); |
3348747a NS |
6759 | /* We have to handle relocations in vxworks .tls_vars sections |
6760 | specially, because the dynamic loader is 'weird'. */ | |
6761 | is_vxworks_tls = (htab->is_vxworks && info->shared | |
6762 | && !strcmp (input_section->output_section->name, | |
6763 | ".tls_vars")); | |
7619e7c7 AM |
6764 | rel = relocs; |
6765 | relend = relocs + input_section->reloc_count; | |
252b5132 RH |
6766 | for (; rel < relend; rel++) |
6767 | { | |
7619e7c7 AM |
6768 | enum elf_ppc_reloc_type r_type; |
6769 | bfd_vma addend; | |
6770 | bfd_reloc_status_type r; | |
6771 | Elf_Internal_Sym *sym; | |
6772 | asection *sec; | |
6773 | struct elf_link_hash_entry *h; | |
6774 | const char *sym_name; | |
252b5132 RH |
6775 | reloc_howto_type *howto; |
6776 | unsigned long r_symndx; | |
6777 | bfd_vma relocation; | |
91d6fa6a | 6778 | bfd_vma branch_bit, from; |
7619e7c7 AM |
6779 | bfd_boolean unresolved_reloc; |
6780 | bfd_boolean warned; | |
6781 | unsigned int tls_type, tls_mask, tls_gd; | |
e054468f | 6782 | struct plt_entry **ifunc; |
7619e7c7 | 6783 | |
55fd94b0 AM |
6784 | r_type = ELF32_R_TYPE (rel->r_info); |
6785 | sym = NULL; | |
6786 | sec = NULL; | |
6787 | h = NULL; | |
7619e7c7 AM |
6788 | unresolved_reloc = FALSE; |
6789 | warned = FALSE; | |
252b5132 | 6790 | r_symndx = ELF32_R_SYM (rel->r_info); |
560e09e9 | 6791 | |
252b5132 RH |
6792 | if (r_symndx < symtab_hdr->sh_info) |
6793 | { | |
6794 | sym = local_syms + r_symndx; | |
6795 | sec = local_sections[r_symndx]; | |
26c61ae5 | 6796 | sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec); |
252b5132 | 6797 | |
8517fae7 | 6798 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
252b5132 RH |
6799 | } |
6800 | else | |
6801 | { | |
b2a8e766 AM |
6802 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
6803 | r_symndx, symtab_hdr, sym_hashes, | |
6804 | h, sec, relocation, | |
6805 | unresolved_reloc, warned); | |
9abc968f | 6806 | |
252b5132 | 6807 | sym_name = h->root.root.string; |
7619e7c7 AM |
6808 | } |
6809 | ||
ab96bf03 AM |
6810 | if (sec != NULL && elf_discarded_section (sec)) |
6811 | { | |
6812 | /* For relocs against symbols from removed linkonce sections, | |
6813 | or sections discarded by a linker script, we just want the | |
6814 | section contents zeroed. Avoid any special processing. */ | |
6815 | howto = NULL; | |
6816 | if (r_type < R_PPC_max) | |
6817 | howto = ppc_elf_howto_table[r_type]; | |
6818 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); | |
6819 | rel->r_info = 0; | |
6820 | rel->r_addend = 0; | |
6821 | continue; | |
6822 | } | |
6823 | ||
6824 | if (info->relocatable) | |
6825 | { | |
6826 | if (got2 != NULL | |
6827 | && r_type == R_PPC_PLTREL24 | |
6828 | && rel->r_addend >= 32768) | |
6829 | { | |
6830 | /* R_PPC_PLTREL24 is rather special. If non-zero, the | |
6831 | addend specifies the GOT pointer offset within .got2. */ | |
6832 | rel->r_addend += got2->output_offset; | |
6833 | } | |
6834 | continue; | |
6835 | } | |
6836 | ||
7619e7c7 AM |
6837 | /* TLS optimizations. Replace instruction sequences and relocs |
6838 | based on information we collected in tls_optimize. We edit | |
6839 | RELOCS so that --emit-relocs will output something sensible | |
6840 | for the final instruction stream. */ | |
6841 | tls_mask = 0; | |
6842 | tls_gd = 0; | |
727fc41e AM |
6843 | if (h != NULL) |
6844 | tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask; | |
6845 | else if (local_got_offsets != NULL) | |
7619e7c7 | 6846 | { |
e054468f | 6847 | struct plt_entry **local_plt; |
727fc41e | 6848 | char *lgot_masks; |
e054468f AM |
6849 | local_plt |
6850 | = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info); | |
6851 | lgot_masks = (char *) (local_plt + symtab_hdr->sh_info); | |
727fc41e | 6852 | tls_mask = lgot_masks[r_symndx]; |
7619e7c7 AM |
6853 | } |
6854 | ||
6855 | /* Ensure reloc mapping code below stays sane. */ | |
6856 | if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3) | |
6857 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3) | |
6858 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3) | |
6859 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3) | |
6860 | || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3) | |
6861 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3) | |
6862 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3) | |
6863 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3)) | |
6864 | abort (); | |
6865 | switch (r_type) | |
6866 | { | |
6867 | default: | |
6868 | break; | |
6869 | ||
6870 | case R_PPC_GOT_TPREL16: | |
6871 | case R_PPC_GOT_TPREL16_LO: | |
e054468f | 6872 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
6873 | && (tls_mask & TLS_TPREL) == 0) |
6874 | { | |
6875 | bfd_vma insn; | |
91d6fa6a | 6876 | |
4fe5ca5b | 6877 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset); |
7619e7c7 AM |
6878 | insn &= 31 << 21; |
6879 | insn |= 0x3c020000; /* addis 0,2,0 */ | |
4fe5ca5b | 6880 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset); |
7619e7c7 AM |
6881 | r_type = R_PPC_TPREL16_HA; |
6882 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6883 | } | |
6884 | break; | |
6885 | ||
6886 | case R_PPC_TLS: | |
e054468f | 6887 | if ((tls_mask & TLS_TLS) != 0 |
7619e7c7 AM |
6888 | && (tls_mask & TLS_TPREL) == 0) |
6889 | { | |
2d0f3896 AM |
6890 | bfd_vma insn; |
6891 | ||
7619e7c7 | 6892 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
2d0f3896 AM |
6893 | insn = _bfd_elf_ppc_at_tls_transform (insn, 2); |
6894 | if (insn == 0) | |
7619e7c7 | 6895 | abort (); |
7619e7c7 AM |
6896 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
6897 | r_type = R_PPC_TPREL16_LO; | |
6898 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4fe5ca5b | 6899 | |
7619e7c7 | 6900 | /* Was PPC_TLS which sits on insn boundary, now |
4fe5ca5b GM |
6901 | PPC_TPREL16_LO which is at low-order half-word. */ |
6902 | rel->r_offset += d_offset; | |
7619e7c7 AM |
6903 | } |
6904 | break; | |
6905 | ||
6906 | case R_PPC_GOT_TLSGD16_HI: | |
6907 | case R_PPC_GOT_TLSGD16_HA: | |
6908 | tls_gd = TLS_TPRELGD; | |
e054468f | 6909 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
7619e7c7 AM |
6910 | goto tls_gdld_hi; |
6911 | break; | |
6912 | ||
6913 | case R_PPC_GOT_TLSLD16_HI: | |
6914 | case R_PPC_GOT_TLSLD16_HA: | |
e054468f | 6915 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 AM |
6916 | { |
6917 | tls_gdld_hi: | |
6918 | if ((tls_mask & tls_gd) != 0) | |
6919 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
6920 | + R_PPC_GOT_TPREL16); | |
6921 | else | |
6922 | { | |
6923 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); | |
4fe5ca5b | 6924 | rel->r_offset -= d_offset; |
7619e7c7 AM |
6925 | r_type = R_PPC_NONE; |
6926 | } | |
6927 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6928 | } | |
6929 | break; | |
6930 | ||
6931 | case R_PPC_GOT_TLSGD16: | |
6932 | case R_PPC_GOT_TLSGD16_LO: | |
6933 | tls_gd = TLS_TPRELGD; | |
e054468f | 6934 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
b7fcf6f6 | 6935 | goto tls_ldgd_opt; |
7619e7c7 AM |
6936 | break; |
6937 | ||
6938 | case R_PPC_GOT_TLSLD16: | |
6939 | case R_PPC_GOT_TLSLD16_LO: | |
e054468f | 6940 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
7619e7c7 | 6941 | { |
3a71aa26 | 6942 | unsigned int insn1, insn2; |
b7fcf6f6 | 6943 | bfd_vma offset; |
7619e7c7 | 6944 | |
b7fcf6f6 | 6945 | tls_ldgd_opt: |
727fc41e AM |
6946 | offset = (bfd_vma) -1; |
6947 | /* If not using the newer R_PPC_TLSGD/LD to mark | |
6948 | __tls_get_addr calls, we must trust that the call | |
6949 | stays with its arg setup insns, ie. that the next | |
6950 | reloc is the __tls_get_addr call associated with | |
6951 | the current reloc. Edit both insns. */ | |
6952 | if (input_section->has_tls_get_addr_call | |
6953 | && rel + 1 < relend | |
6954 | && branch_reloc_hash_match (input_bfd, rel + 1, | |
6955 | htab->tls_get_addr)) | |
6956 | offset = rel[1].r_offset; | |
b7fcf6f6 AM |
6957 | if ((tls_mask & tls_gd) != 0) |
6958 | { | |
6959 | /* IE */ | |
3a71aa26 AM |
6960 | insn1 = bfd_get_32 (output_bfd, |
6961 | contents + rel->r_offset - d_offset); | |
b7fcf6f6 AM |
6962 | insn1 &= (1 << 26) - 1; |
6963 | insn1 |= 32 << 26; /* lwz */ | |
727fc41e AM |
6964 | if (offset != (bfd_vma) -1) |
6965 | { | |
f58d5a2d | 6966 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e AM |
6967 | insn2 = 0x7c631214; /* add 3,3,2 */ |
6968 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
6969 | } | |
b7fcf6f6 AM |
6970 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) |
6971 | + R_PPC_GOT_TPREL16); | |
6972 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
6973 | } | |
6974 | else | |
6975 | { | |
6976 | /* LE */ | |
6977 | insn1 = 0x3c620000; /* addis 3,2,0 */ | |
7619e7c7 AM |
6978 | if (tls_gd == 0) |
6979 | { | |
b7fcf6f6 | 6980 | /* Was an LD reloc. */ |
1d483afe AM |
6981 | for (r_symndx = 0; |
6982 | r_symndx < symtab_hdr->sh_info; | |
6983 | r_symndx++) | |
6984 | if (local_sections[r_symndx] == sec) | |
6985 | break; | |
6986 | if (r_symndx >= symtab_hdr->sh_info) | |
6987 | r_symndx = 0; | |
b7fcf6f6 | 6988 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
1d483afe AM |
6989 | if (r_symndx != 0) |
6990 | rel->r_addend -= (local_syms[r_symndx].st_value | |
6991 | + sec->output_offset | |
6992 | + sec->output_section->vma); | |
7619e7c7 | 6993 | } |
b7fcf6f6 AM |
6994 | r_type = R_PPC_TPREL16_HA; |
6995 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
727fc41e AM |
6996 | if (offset != (bfd_vma) -1) |
6997 | { | |
6998 | rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
6999 | rel[1].r_offset = offset + d_offset; | |
7000 | rel[1].r_addend = rel->r_addend; | |
7001 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7002 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7003 | } | |
b7fcf6f6 AM |
7004 | } |
7005 | bfd_put_32 (output_bfd, insn1, | |
7006 | contents + rel->r_offset - d_offset); | |
b7fcf6f6 AM |
7007 | if (tls_gd == 0) |
7008 | { | |
7009 | /* We changed the symbol on an LD reloc. Start over | |
7010 | in order to get h, sym, sec etc. right. */ | |
7011 | rel--; | |
7012 | continue; | |
7619e7c7 | 7013 | } |
252b5132 | 7014 | } |
7619e7c7 | 7015 | break; |
727fc41e AM |
7016 | |
7017 | case R_PPC_TLSGD: | |
e054468f | 7018 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0) |
727fc41e AM |
7019 | { |
7020 | unsigned int insn2; | |
7021 | bfd_vma offset = rel->r_offset; | |
7022 | ||
7023 | if ((tls_mask & TLS_TPRELGD) != 0) | |
7024 | { | |
7025 | /* IE */ | |
7026 | r_type = R_PPC_NONE; | |
7027 | insn2 = 0x7c631214; /* add 3,3,2 */ | |
7028 | } | |
7029 | else | |
7030 | { | |
7031 | /* LE */ | |
7032 | r_type = R_PPC_TPREL16_LO; | |
7033 | rel->r_offset += d_offset; | |
7034 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7035 | } | |
7036 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
7037 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7038 | /* Zap the reloc on the _tls_get_addr call too. */ | |
7039 | BFD_ASSERT (offset == rel[1].r_offset); | |
f58d5a2d | 7040 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e AM |
7041 | } |
7042 | break; | |
7043 | ||
7044 | case R_PPC_TLSLD: | |
e054468f | 7045 | if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0) |
727fc41e AM |
7046 | { |
7047 | unsigned int insn2; | |
7048 | ||
7049 | for (r_symndx = 0; | |
7050 | r_symndx < symtab_hdr->sh_info; | |
7051 | r_symndx++) | |
7052 | if (local_sections[r_symndx] == sec) | |
7053 | break; | |
7054 | if (r_symndx >= symtab_hdr->sh_info) | |
7055 | r_symndx = 0; | |
7056 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; | |
7057 | if (r_symndx != 0) | |
7058 | rel->r_addend -= (local_syms[r_symndx].st_value | |
7059 | + sec->output_offset | |
7060 | + sec->output_section->vma); | |
7061 | ||
7062 | rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO); | |
7063 | rel->r_offset += d_offset; | |
7064 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7065 | bfd_put_32 (output_bfd, insn2, | |
7066 | contents + rel->r_offset - d_offset); | |
7067 | /* Zap the reloc on the _tls_get_addr call too. */ | |
7068 | BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset); | |
f58d5a2d | 7069 | rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); |
727fc41e AM |
7070 | rel--; |
7071 | continue; | |
7072 | } | |
7073 | break; | |
7619e7c7 AM |
7074 | } |
7075 | ||
7076 | /* Handle other relocations that tweak non-addend part of insn. */ | |
7077 | branch_bit = 0; | |
7078 | switch (r_type) | |
7079 | { | |
7080 | default: | |
7081 | break; | |
7082 | ||
7083 | /* Branch taken prediction relocations. */ | |
7084 | case R_PPC_ADDR14_BRTAKEN: | |
7085 | case R_PPC_REL14_BRTAKEN: | |
7086 | branch_bit = BRANCH_PREDICT_BIT; | |
7087 | /* Fall thru */ | |
7088 | ||
4cc11e76 | 7089 | /* Branch not taken prediction relocations. */ |
7619e7c7 AM |
7090 | case R_PPC_ADDR14_BRNTAKEN: |
7091 | case R_PPC_REL14_BRNTAKEN: | |
91d6fa6a NC |
7092 | { |
7093 | bfd_vma insn; | |
7619e7c7 | 7094 | |
91d6fa6a NC |
7095 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
7096 | insn &= ~BRANCH_PREDICT_BIT; | |
7097 | insn |= branch_bit; | |
7619e7c7 | 7098 | |
91d6fa6a NC |
7099 | from = (rel->r_offset |
7100 | + input_section->output_offset | |
7101 | + input_section->output_section->vma); | |
7619e7c7 | 7102 | |
91d6fa6a NC |
7103 | /* Invert 'y' bit if not the default. */ |
7104 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
7105 | insn ^= BRANCH_PREDICT_BIT; | |
7106 | ||
7107 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
7108 | break; | |
7109 | } | |
252b5132 RH |
7110 | } |
7111 | ||
e054468f | 7112 | ifunc = NULL; |
25f23106 | 7113 | if (!htab->is_vxworks) |
e054468f | 7114 | { |
de972ffa AM |
7115 | struct plt_entry *ent; |
7116 | ||
e054468f AM |
7117 | if (h != NULL) |
7118 | { | |
7119 | if (h->type == STT_GNU_IFUNC) | |
7120 | ifunc = &h->plt.plist; | |
7121 | } | |
de972ffa AM |
7122 | else if (local_got_offsets != NULL |
7123 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
e054468f | 7124 | { |
de972ffa | 7125 | struct plt_entry **local_plt; |
e054468f | 7126 | |
de972ffa AM |
7127 | local_plt = (struct plt_entry **) (local_got_offsets |
7128 | + symtab_hdr->sh_info); | |
7129 | ifunc = local_plt + r_symndx; | |
e054468f | 7130 | } |
e054468f | 7131 | |
de972ffa AM |
7132 | ent = NULL; |
7133 | if (ifunc != NULL | |
7134 | && (!info->shared | |
7135 | || is_branch_reloc (r_type))) | |
7136 | { | |
7137 | addend = 0; | |
a877a2b6 | 7138 | if (r_type == R_PPC_PLTREL24 && info->shared) |
de972ffa AM |
7139 | addend = rel->r_addend; |
7140 | ent = find_plt_ent (ifunc, got2, addend); | |
7141 | } | |
7142 | if (ent != NULL) | |
7143 | { | |
e054468f AM |
7144 | if (h == NULL && (ent->plt.offset & 1) == 0) |
7145 | { | |
7146 | Elf_Internal_Rela rela; | |
7147 | bfd_byte *loc; | |
7148 | ||
7149 | rela.r_offset = (htab->iplt->output_section->vma | |
7150 | + htab->iplt->output_offset | |
7151 | + ent->plt.offset); | |
7152 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7153 | rela.r_addend = relocation; | |
25f23106 AM |
7154 | loc = htab->reliplt->contents; |
7155 | loc += (htab->reliplt->reloc_count++ | |
7156 | * sizeof (Elf32_External_Rela)); | |
e054468f AM |
7157 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
7158 | ||
7159 | ent->plt.offset |= 1; | |
7160 | } | |
7161 | if (h == NULL && (ent->glink_offset & 1) == 0) | |
7162 | { | |
a7f2871e AM |
7163 | unsigned char *p = ((unsigned char *) htab->glink->contents |
7164 | + ent->glink_offset); | |
7165 | write_glink_stub (ent, htab->iplt, p, info); | |
e054468f AM |
7166 | ent->glink_offset |= 1; |
7167 | } | |
7168 | ||
7169 | unresolved_reloc = FALSE; | |
7170 | if (htab->plt_type == PLT_NEW | |
7171 | || !htab->elf.dynamic_sections_created | |
7172 | || h == NULL) | |
7173 | relocation = (htab->glink->output_section->vma | |
7174 | + htab->glink->output_offset | |
7175 | + (ent->glink_offset & ~1)); | |
7176 | else | |
7177 | relocation = (htab->plt->output_section->vma | |
7178 | + htab->plt->output_offset | |
7179 | + ent->plt.offset); | |
7180 | } | |
7181 | } | |
7182 | ||
7619e7c7 AM |
7183 | addend = rel->r_addend; |
7184 | tls_type = 0; | |
7185 | howto = NULL; | |
55fd94b0 AM |
7186 | if (r_type < R_PPC_max) |
7187 | howto = ppc_elf_howto_table[r_type]; | |
7619e7c7 | 7188 | switch (r_type) |
252b5132 RH |
7189 | { |
7190 | default: | |
7619e7c7 | 7191 | (*_bfd_error_handler) |
d003868e AM |
7192 | (_("%B: unknown relocation type %d for symbol %s"), |
7193 | input_bfd, (int) r_type, sym_name); | |
252b5132 RH |
7194 | |
7195 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 7196 | ret = FALSE; |
252b5132 RH |
7197 | continue; |
7198 | ||
7619e7c7 AM |
7199 | case R_PPC_NONE: |
7200 | case R_PPC_TLS: | |
727fc41e AM |
7201 | case R_PPC_TLSGD: |
7202 | case R_PPC_TLSLD: | |
7619e7c7 AM |
7203 | case R_PPC_EMB_MRKREF: |
7204 | case R_PPC_GNU_VTINHERIT: | |
7205 | case R_PPC_GNU_VTENTRY: | |
7595d193 L |
7206 | continue; |
7207 | ||
7619e7c7 AM |
7208 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
7209 | address in the GOT as relocation value instead of the | |
7210 | symbol's value itself. Also, create a GOT entry for the | |
7211 | symbol and put the symbol value there. */ | |
7212 | case R_PPC_GOT_TLSGD16: | |
7213 | case R_PPC_GOT_TLSGD16_LO: | |
7214 | case R_PPC_GOT_TLSGD16_HI: | |
7215 | case R_PPC_GOT_TLSGD16_HA: | |
7216 | tls_type = TLS_TLS | TLS_GD; | |
7217 | goto dogot; | |
7218 | ||
7219 | case R_PPC_GOT_TLSLD16: | |
7220 | case R_PPC_GOT_TLSLD16_LO: | |
7221 | case R_PPC_GOT_TLSLD16_HI: | |
7222 | case R_PPC_GOT_TLSLD16_HA: | |
7223 | tls_type = TLS_TLS | TLS_LD; | |
7224 | goto dogot; | |
7225 | ||
7226 | case R_PPC_GOT_TPREL16: | |
7227 | case R_PPC_GOT_TPREL16_LO: | |
7228 | case R_PPC_GOT_TPREL16_HI: | |
7229 | case R_PPC_GOT_TPREL16_HA: | |
7230 | tls_type = TLS_TLS | TLS_TPREL; | |
7231 | goto dogot; | |
7232 | ||
7233 | case R_PPC_GOT_DTPREL16: | |
7234 | case R_PPC_GOT_DTPREL16_LO: | |
7235 | case R_PPC_GOT_DTPREL16_HI: | |
7236 | case R_PPC_GOT_DTPREL16_HA: | |
7237 | tls_type = TLS_TLS | TLS_DTPREL; | |
7238 | goto dogot; | |
7239 | ||
7240 | case R_PPC_GOT16: | |
7241 | case R_PPC_GOT16_LO: | |
7242 | case R_PPC_GOT16_HI: | |
7243 | case R_PPC_GOT16_HA: | |
727fc41e | 7244 | tls_mask = 0; |
7619e7c7 AM |
7245 | dogot: |
7246 | { | |
7247 | /* Relocation is to the entry for this symbol in the global | |
7248 | offset table. */ | |
7249 | bfd_vma off; | |
7250 | bfd_vma *offp; | |
7251 | unsigned long indx; | |
7252 | ||
7253 | if (htab->got == NULL) | |
7254 | abort (); | |
7255 | ||
7256 | indx = 0; | |
7257 | if (tls_type == (TLS_TLS | TLS_LD) | |
d881513a | 7258 | && (h == NULL |
f5385ebf | 7259 | || !h->def_dynamic)) |
7619e7c7 AM |
7260 | offp = &htab->tlsld_got.offset; |
7261 | else if (h != NULL) | |
7262 | { | |
7263 | bfd_boolean dyn; | |
7264 | dyn = htab->elf.dynamic_sections_created; | |
ee05f2fe | 7265 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
7619e7c7 AM |
7266 | || (info->shared |
7267 | && SYMBOL_REFERENCES_LOCAL (info, h))) | |
7268 | /* This is actually a static link, or it is a | |
7269 | -Bsymbolic link and the symbol is defined | |
7270 | locally, or the symbol was forced to be local | |
7271 | because of a version file. */ | |
7272 | ; | |
7273 | else | |
7274 | { | |
7275 | indx = h->dynindx; | |
7276 | unresolved_reloc = FALSE; | |
7277 | } | |
7278 | offp = &h->got.offset; | |
7279 | } | |
7280 | else | |
7281 | { | |
7282 | if (local_got_offsets == NULL) | |
7283 | abort (); | |
7284 | offp = &local_got_offsets[r_symndx]; | |
7285 | } | |
7286 | ||
7287 | /* The offset must always be a multiple of 4. We use the | |
7288 | least significant bit to record whether we have already | |
7289 | processed this entry. */ | |
7290 | off = *offp; | |
7291 | if ((off & 1) != 0) | |
7292 | off &= ~1; | |
7293 | else | |
7294 | { | |
70bccea4 AM |
7295 | unsigned int tls_m = (tls_mask |
7296 | & (TLS_LD | TLS_GD | TLS_DTPREL | |
7297 | | TLS_TPREL | TLS_TPRELGD)); | |
7298 | ||
7299 | if (offp == &htab->tlsld_got.offset) | |
7300 | tls_m = TLS_LD; | |
7301 | else if (h == NULL | |
f5385ebf | 7302 | || !h->def_dynamic) |
70bccea4 AM |
7303 | tls_m &= ~TLS_LD; |
7304 | ||
7305 | /* We might have multiple got entries for this sym. | |
7306 | Initialize them all. */ | |
7307 | do | |
7619e7c7 | 7308 | { |
70bccea4 AM |
7309 | int tls_ty = 0; |
7310 | ||
7311 | if ((tls_m & TLS_LD) != 0) | |
7619e7c7 | 7312 | { |
70bccea4 AM |
7313 | tls_ty = TLS_TLS | TLS_LD; |
7314 | tls_m &= ~TLS_LD; | |
7315 | } | |
7316 | else if ((tls_m & TLS_GD) != 0) | |
7317 | { | |
7318 | tls_ty = TLS_TLS | TLS_GD; | |
7319 | tls_m &= ~TLS_GD; | |
7320 | } | |
7321 | else if ((tls_m & TLS_DTPREL) != 0) | |
7322 | { | |
7323 | tls_ty = TLS_TLS | TLS_DTPREL; | |
7324 | tls_m &= ~TLS_DTPREL; | |
7325 | } | |
7326 | else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
7327 | { | |
7328 | tls_ty = TLS_TLS | TLS_TPREL; | |
7329 | tls_m = 0; | |
7619e7c7 | 7330 | } |
7619e7c7 | 7331 | |
70bccea4 | 7332 | /* Generate relocs for the dynamic linker. */ |
4e795f50 | 7333 | if ((info->shared || indx != 0) |
d6e14abc AM |
7334 | && (offp == &htab->tlsld_got.offset |
7335 | || h == NULL | |
4e795f50 AM |
7336 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7337 | || h->root.type != bfd_link_hash_undefweak)) | |
7619e7c7 | 7338 | { |
91e21fb7 | 7339 | asection *rsec = htab->relgot; |
91d6fa6a | 7340 | bfd_byte * loc; |
91e21fb7 | 7341 | |
70bccea4 AM |
7342 | outrel.r_offset = (htab->got->output_section->vma |
7343 | + htab->got->output_offset | |
7344 | + off); | |
e515b051 | 7345 | outrel.r_addend = 0; |
70bccea4 AM |
7346 | if (tls_ty & (TLS_LD | TLS_GD)) |
7347 | { | |
7348 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32); | |
70bccea4 AM |
7349 | if (tls_ty == (TLS_TLS | TLS_GD)) |
7350 | { | |
25f23106 AM |
7351 | loc = rsec->contents; |
7352 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
7353 | * sizeof (Elf32_External_Rela)); |
7354 | bfd_elf32_swap_reloca_out (output_bfd, | |
7355 | &outrel, loc); | |
e515b051 | 7356 | outrel.r_offset += 4; |
70bccea4 AM |
7357 | outrel.r_info |
7358 | = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
70bccea4 AM |
7359 | } |
7360 | } | |
7361 | else if (tls_ty == (TLS_TLS | TLS_DTPREL)) | |
7362 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
7363 | else if (tls_ty == (TLS_TLS | TLS_TPREL)) | |
7364 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32); | |
25f23106 | 7365 | else if (indx != 0) |
70bccea4 | 7366 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT); |
25f23106 AM |
7367 | else if (ifunc != NULL) |
7368 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7369 | else | |
7370 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
d6e14abc | 7371 | if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD)) |
e515b051 AM |
7372 | { |
7373 | outrel.r_addend += relocation; | |
7374 | if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 7375 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 7376 | } |
25f23106 AM |
7377 | loc = rsec->contents; |
7378 | loc += (rsec->reloc_count++ | |
70bccea4 AM |
7379 | * sizeof (Elf32_External_Rela)); |
7380 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
7619e7c7 AM |
7381 | } |
7382 | ||
70bccea4 AM |
7383 | /* Init the .got section contents if we're not |
7384 | emitting a reloc. */ | |
7385 | else | |
7619e7c7 | 7386 | { |
70bccea4 AM |
7387 | bfd_vma value = relocation; |
7388 | ||
7b609f53 AM |
7389 | if (tls_ty == (TLS_TLS | TLS_LD)) |
7390 | value = 1; | |
7391 | else if (tls_ty != 0) | |
70bccea4 | 7392 | { |
e1918d23 | 7393 | value -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 7394 | if (tls_ty == (TLS_TLS | TLS_TPREL)) |
70bccea4 | 7395 | value += DTP_OFFSET - TP_OFFSET; |
70bccea4 | 7396 | |
7b609f53 AM |
7397 | if (tls_ty == (TLS_TLS | TLS_GD)) |
7398 | { | |
7399 | bfd_put_32 (output_bfd, value, | |
7400 | htab->got->contents + off + 4); | |
7401 | value = 1; | |
7402 | } | |
70bccea4 | 7403 | } |
70bccea4 AM |
7404 | bfd_put_32 (output_bfd, value, |
7405 | htab->got->contents + off); | |
7619e7c7 | 7406 | } |
70bccea4 AM |
7407 | |
7408 | off += 4; | |
7409 | if (tls_ty & (TLS_LD | TLS_GD)) | |
7410 | off += 4; | |
7619e7c7 | 7411 | } |
70bccea4 AM |
7412 | while (tls_m != 0); |
7413 | ||
7414 | off = *offp; | |
7415 | *offp = off | 1; | |
7619e7c7 AM |
7416 | } |
7417 | ||
7418 | if (off >= (bfd_vma) -2) | |
7419 | abort (); | |
7420 | ||
70bccea4 AM |
7421 | if ((tls_type & TLS_TLS) != 0) |
7422 | { | |
7423 | if (tls_type != (TLS_TLS | TLS_LD)) | |
7424 | { | |
7425 | if ((tls_mask & TLS_LD) != 0 | |
7426 | && !(h == NULL | |
f5385ebf | 7427 | || !h->def_dynamic)) |
70bccea4 AM |
7428 | off += 8; |
7429 | if (tls_type != (TLS_TLS | TLS_GD)) | |
7430 | { | |
7431 | if ((tls_mask & TLS_GD) != 0) | |
7432 | off += 8; | |
7433 | if (tls_type != (TLS_TLS | TLS_DTPREL)) | |
7434 | { | |
7435 | if ((tls_mask & TLS_DTPREL) != 0) | |
7436 | off += 4; | |
7437 | } | |
7438 | } | |
7439 | } | |
7440 | } | |
7441 | ||
e87d4038 AM |
7442 | relocation = (htab->got->output_section->vma |
7443 | + htab->got->output_offset | |
7444 | + off | |
7445 | - SYM_VAL (htab->elf.hgot)); | |
7619e7c7 AM |
7446 | |
7447 | /* Addends on got relocations don't make much sense. | |
7448 | x+off@got is actually x@got+off, and since the got is | |
7449 | generated by a hash table traversal, the value in the | |
7450 | got at entry m+n bears little relation to the entry m. */ | |
7451 | if (addend != 0) | |
7452 | (*_bfd_error_handler) | |
d003868e AM |
7453 | (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"), |
7454 | input_bfd, | |
7455 | input_section, | |
7619e7c7 | 7456 | (long) rel->r_offset, |
7b609f53 | 7457 | howto->name, |
7619e7c7 AM |
7458 | sym_name); |
7459 | } | |
70bccea4 | 7460 | break; |
7619e7c7 | 7461 | |
252b5132 | 7462 | /* Relocations that need no special processing. */ |
7619e7c7 | 7463 | case R_PPC_LOCAL24PC: |
252b5132 RH |
7464 | /* It makes no sense to point a local relocation |
7465 | at a symbol not in this object. */ | |
7b609f53 | 7466 | if (unresolved_reloc) |
252b5132 | 7467 | { |
464e1740 ILT |
7468 | if (! (*info->callbacks->undefined_symbol) (info, |
7469 | h->root.root.string, | |
7470 | input_bfd, | |
7471 | input_section, | |
5cc7c785 | 7472 | rel->r_offset, |
b34976b6 AM |
7473 | TRUE)) |
7474 | return FALSE; | |
252b5132 RH |
7475 | continue; |
7476 | } | |
7477 | break; | |
7478 | ||
7619e7c7 AM |
7479 | case R_PPC_DTPREL16: |
7480 | case R_PPC_DTPREL16_LO: | |
7481 | case R_PPC_DTPREL16_HI: | |
7482 | case R_PPC_DTPREL16_HA: | |
e1918d23 | 7483 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
7484 | break; |
7485 | ||
70bccea4 AM |
7486 | /* Relocations that may need to be propagated if this is a shared |
7487 | object. */ | |
7619e7c7 AM |
7488 | case R_PPC_TPREL16: |
7489 | case R_PPC_TPREL16_LO: | |
7490 | case R_PPC_TPREL16_HI: | |
7491 | case R_PPC_TPREL16_HA: | |
766bc656 AM |
7492 | if (h != NULL |
7493 | && h->root.type == bfd_link_hash_undefweak | |
7494 | && h->dynindx == -1) | |
7495 | { | |
7496 | /* Make this relocation against an undefined weak symbol | |
7497 | resolve to zero. This is really just a tweak, since | |
7498 | code using weak externs ought to check that they are | |
7499 | defined before using them. */ | |
7500 | bfd_byte *p = contents + rel->r_offset - d_offset; | |
7501 | unsigned int insn = bfd_get_32 (output_bfd, p); | |
7502 | insn = _bfd_elf_ppc_at_tprel_transform (insn, 2); | |
7503 | if (insn != 0) | |
7504 | bfd_put_32 (output_bfd, insn, p); | |
7505 | break; | |
7506 | } | |
e1918d23 | 7507 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
7508 | /* The TPREL16 relocs shouldn't really be used in shared |
7509 | libs as they will result in DT_TEXTREL being set, but | |
7510 | support them anyway. */ | |
7511 | goto dodyn; | |
7512 | ||
7513 | case R_PPC_TPREL32: | |
e1918d23 | 7514 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
7515 | goto dodyn; |
7516 | ||
7517 | case R_PPC_DTPREL32: | |
e1918d23 | 7518 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
7519 | goto dodyn; |
7520 | ||
e515b051 AM |
7521 | case R_PPC_DTPMOD32: |
7522 | relocation = 1; | |
7523 | addend = 0; | |
7524 | goto dodyn; | |
7525 | ||
d7128ce4 AM |
7526 | case R_PPC_REL16: |
7527 | case R_PPC_REL16_LO: | |
7528 | case R_PPC_REL16_HI: | |
7529 | case R_PPC_REL16_HA: | |
7530 | break; | |
7531 | ||
7619e7c7 | 7532 | case R_PPC_REL32: |
625af618 AM |
7533 | if (h == NULL || h == htab->elf.hgot) |
7534 | break; | |
7535 | /* fall through */ | |
7536 | ||
7537 | case R_PPC_ADDR32: | |
7538 | case R_PPC_ADDR16: | |
7539 | case R_PPC_ADDR16_LO: | |
7540 | case R_PPC_ADDR16_HI: | |
7541 | case R_PPC_ADDR16_HA: | |
7542 | case R_PPC_UADDR32: | |
7543 | case R_PPC_UADDR16: | |
7544 | goto dodyn; | |
7545 | ||
7546 | case R_PPC_REL24: | |
7619e7c7 AM |
7547 | case R_PPC_REL14: |
7548 | case R_PPC_REL14_BRTAKEN: | |
7549 | case R_PPC_REL14_BRNTAKEN: | |
252b5132 RH |
7550 | /* If these relocations are not to a named symbol, they can be |
7551 | handled right here, no need to bother the dynamic linker. */ | |
89200bf8 | 7552 | if (SYMBOL_CALLS_LOCAL (info, h) |
3b36f7e6 | 7553 | || h == htab->elf.hgot) |
252b5132 | 7554 | break; |
70bccea4 | 7555 | /* fall through */ |
252b5132 | 7556 | |
7619e7c7 | 7557 | case R_PPC_ADDR24: |
7619e7c7 AM |
7558 | case R_PPC_ADDR14: |
7559 | case R_PPC_ADDR14_BRTAKEN: | |
7560 | case R_PPC_ADDR14_BRNTAKEN: | |
625af618 AM |
7561 | if (h != NULL && !info->shared) |
7562 | break; | |
7563 | /* fall through */ | |
7564 | ||
7619e7c7 | 7565 | dodyn: |
3348747a NS |
7566 | if ((input_section->flags & SEC_ALLOC) == 0 |
7567 | || is_vxworks_tls) | |
c87b5a93 | 7568 | break; |
c87b5a93 | 7569 | |
ee05f2fe | 7570 | if ((info->shared |
89200bf8 AM |
7571 | && !(h != NULL |
7572 | && ((h->root.type == bfd_link_hash_undefined | |
7573 | && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
7574 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL)) | |
7575 | || (h->root.type == bfd_link_hash_undefweak | |
7576 | && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT))) | |
1d483afe | 7577 | && (must_be_dyn_reloc (info, r_type) |
f6c52c13 | 7578 | || !SYMBOL_CALLS_LOCAL (info, h))) |
ee05f2fe AM |
7579 | || (ELIMINATE_COPY_RELOCS |
7580 | && !info->shared | |
ee05f2fe AM |
7581 | && h != NULL |
7582 | && h->dynindx != -1 | |
f5385ebf | 7583 | && !h->non_got_ref |
de972ffa | 7584 | && !h->def_regular)) |
252b5132 | 7585 | { |
0bb2d96a | 7586 | int skip; |
91d6fa6a | 7587 | bfd_byte * loc; |
252b5132 | 7588 | #ifdef DEBUG |
55fd94b0 AM |
7589 | fprintf (stderr, "ppc_elf_relocate_section needs to " |
7590 | "create relocation for %s\n", | |
70bccea4 AM |
7591 | (h && h->root.root.string |
7592 | ? h->root.root.string : "<unknown>")); | |
252b5132 RH |
7593 | #endif |
7594 | ||
7595 | /* When generating a shared object, these relocations | |
70bccea4 AM |
7596 | are copied into the output file to be resolved at run |
7597 | time. */ | |
252b5132 RH |
7598 | if (sreloc == NULL) |
7599 | { | |
25f23106 AM |
7600 | sreloc = elf_section_data (input_section)->sreloc; |
7601 | if (!htab->elf.dynamic_sections_created) | |
7602 | sreloc = htab->reliplt; | |
83bac4b0 | 7603 | if (sreloc == NULL) |
b34976b6 | 7604 | return FALSE; |
252b5132 RH |
7605 | } |
7606 | ||
0bb2d96a | 7607 | skip = 0; |
c629eae0 JJ |
7608 | outrel.r_offset = |
7609 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
7610 | rel->r_offset); | |
0bb2d96a JJ |
7611 | if (outrel.r_offset == (bfd_vma) -1 |
7612 | || outrel.r_offset == (bfd_vma) -2) | |
7613 | skip = (int) outrel.r_offset; | |
252b5132 RH |
7614 | outrel.r_offset += (input_section->output_section->vma |
7615 | + input_section->output_offset); | |
7616 | ||
7617 | if (skip) | |
7618 | memset (&outrel, 0, sizeof outrel); | |
89200bf8 AM |
7619 | else if ((h != NULL |
7620 | && (h->root.type == bfd_link_hash_undefined | |
7621 | || h->root.type == bfd_link_hash_undefweak)) | |
7622 | || !SYMBOL_REFERENCES_LOCAL (info, h)) | |
252b5132 | 7623 | { |
7619e7c7 | 7624 | unresolved_reloc = FALSE; |
252b5132 RH |
7625 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
7626 | outrel.r_addend = rel->r_addend; | |
7627 | } | |
7628 | else | |
7629 | { | |
47388f4c AM |
7630 | outrel.r_addend = relocation + rel->r_addend; |
7631 | ||
25f23106 | 7632 | if (r_type != R_PPC_ADDR32) |
252b5132 | 7633 | { |
89200bf8 | 7634 | long indx = 0; |
252b5132 | 7635 | |
25f23106 AM |
7636 | if (ifunc != NULL) |
7637 | { | |
7638 | /* If we get here when building a static | |
7639 | executable, then the libc startup function | |
7640 | responsible for applying indirect function | |
7641 | relocations is going to complain about | |
7642 | the reloc type. | |
7643 | If we get here when building a dynamic | |
7644 | executable, it will be because we have | |
7645 | a text relocation. The dynamic loader | |
7646 | will set the text segment writable and | |
7647 | non-executable to apply text relocations. | |
7648 | So we'll segfault when trying to run the | |
7649 | indirection function to resolve the reloc. */ | |
7650 | (*_bfd_error_handler) | |
7651 | (_("%B(%A+0x%lx): relocation %s for indirect " | |
7652 | "function %s unsupported"), | |
7653 | input_bfd, | |
7654 | input_section, | |
7655 | (long) rel->r_offset, | |
7656 | howto->name, | |
7657 | sym_name); | |
7658 | ret = FALSE; | |
7659 | } | |
7660 | else if (r_symndx == 0 || bfd_is_abs_section (sec)) | |
89200bf8 | 7661 | ; |
252b5132 RH |
7662 | else if (sec == NULL || sec->owner == NULL) |
7663 | { | |
7664 | bfd_set_error (bfd_error_bad_value); | |
89200bf8 | 7665 | ret = FALSE; |
252b5132 RH |
7666 | } |
7667 | else | |
7668 | { | |
7669 | asection *osec; | |
7670 | ||
47388f4c AM |
7671 | /* We are turning this relocation into one |
7672 | against a section symbol. It would be | |
7673 | proper to subtract the symbol's value, | |
7674 | osec->vma, from the emitted reloc addend, | |
25f23106 AM |
7675 | but ld.so expects buggy relocs. |
7676 | FIXME: Why not always use a zero index? */ | |
252b5132 RH |
7677 | osec = sec->output_section; |
7678 | indx = elf_section_data (osec)->dynindx; | |
74541ad4 AM |
7679 | if (indx == 0) |
7680 | { | |
7681 | osec = htab->elf.text_index_section; | |
7682 | indx = elf_section_data (osec)->dynindx; | |
7683 | } | |
7684 | BFD_ASSERT (indx != 0); | |
252b5132 | 7685 | #ifdef DEBUG |
74541ad4 | 7686 | if (indx == 0) |
e460dd0d | 7687 | printf ("indx=%ld section=%s flags=%08x name=%s\n", |
55fd94b0 AM |
7688 | indx, osec->name, osec->flags, |
7689 | h->root.root.string); | |
252b5132 RH |
7690 | #endif |
7691 | } | |
7692 | ||
7693 | outrel.r_info = ELF32_R_INFO (indx, r_type); | |
252b5132 | 7694 | } |
25f23106 AM |
7695 | else if (ifunc != NULL) |
7696 | outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
7697 | else | |
7698 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); | |
252b5132 RH |
7699 | } |
7700 | ||
947216bf AM |
7701 | loc = sreloc->contents; |
7702 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
7703 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 | 7704 | |
2243deae | 7705 | if (skip == -1) |
252b5132 | 7706 | continue; |
2243deae L |
7707 | |
7708 | /* This reloc will be computed at runtime. We clear the memory | |
7709 | so that it contains predictable value. */ | |
7710 | if (! skip | |
7711 | && ((input_section->flags & SEC_ALLOC) != 0 | |
7712 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)) | |
7713 | { | |
7714 | relocation = howto->pc_relative ? outrel.r_offset : 0; | |
7715 | addend = 0; | |
7716 | break; | |
7717 | } | |
252b5132 | 7718 | } |
252b5132 RH |
7719 | break; |
7720 | ||
32af9f6e AM |
7721 | case R_PPC_RELAX_PLT: |
7722 | case R_PPC_RELAX_PLTREL24: | |
de972ffa AM |
7723 | if (h != NULL) |
7724 | { | |
32af9f6e AM |
7725 | struct plt_entry *ent; |
7726 | bfd_vma got2_addend = 0; | |
7727 | ||
7728 | if (r_type == R_PPC_RELAX_PLTREL24) | |
7729 | { | |
7730 | if (info->shared) | |
7731 | got2_addend = addend; | |
7732 | addend = 0; | |
7733 | } | |
7734 | ent = find_plt_ent (&h->plt.plist, got2, got2_addend); | |
de972ffa AM |
7735 | if (htab->plt_type == PLT_NEW) |
7736 | relocation = (htab->glink->output_section->vma | |
7737 | + htab->glink->output_offset | |
7738 | + ent->glink_offset); | |
7739 | else | |
7740 | relocation = (htab->plt->output_section->vma | |
7741 | + htab->plt->output_offset | |
7742 | + ent->plt.offset); | |
7743 | } | |
b4a38de6 AM |
7744 | /* Fall thru */ |
7745 | ||
32af9f6e AM |
7746 | case R_PPC_RELAX: |
7747 | if (info->shared) | |
7748 | relocation -= (input_section->output_section->vma | |
7749 | + input_section->output_offset | |
7750 | + rel->r_offset - 4); | |
b4a38de6 | 7751 | |
9abc968f AM |
7752 | { |
7753 | unsigned long t0; | |
7754 | unsigned long t1; | |
7755 | ||
7756 | t0 = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
7757 | t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4); | |
7758 | ||
7759 | /* We're clearing the bits for R_PPC_ADDR16_HA | |
7760 | and R_PPC_ADDR16_LO here. */ | |
7761 | t0 &= ~0xffff; | |
7762 | t1 &= ~0xffff; | |
7763 | ||
7764 | /* t0 is HA, t1 is LO */ | |
7765 | relocation += addend; | |
7766 | t0 |= ((relocation + 0x8000) >> 16) & 0xffff; | |
7767 | t1 |= relocation & 0xffff; | |
7768 | ||
7769 | bfd_put_32 (output_bfd, t0, contents + rel->r_offset); | |
7770 | bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4); | |
9bc4e62b NS |
7771 | |
7772 | /* Rewrite the reloc and convert one of the trailing nop | |
7773 | relocs to describe this relocation. */ | |
7774 | BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE); | |
7775 | /* The relocs are at the bottom 2 bytes */ | |
7776 | rel[0].r_offset += 2; | |
7777 | memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel)); | |
7778 | rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); | |
7779 | rel[1].r_offset += 4; | |
7780 | rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); | |
7781 | rel++; | |
9abc968f | 7782 | } |
8517fae7 | 7783 | continue; |
deaaf2f3 | 7784 | |
70bccea4 | 7785 | /* Indirect .sdata relocation. */ |
7619e7c7 | 7786 | case R_PPC_EMB_SDAI16: |
c9a2f333 | 7787 | BFD_ASSERT (htab->sdata[0].section != NULL); |
bd6c6e2b AM |
7788 | if (!is_static_defined (htab->sdata[0].sym)) |
7789 | { | |
7790 | unresolved_reloc = TRUE; | |
7791 | break; | |
7792 | } | |
7619e7c7 | 7793 | relocation |
76750a2f AM |
7794 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0], |
7795 | h, relocation, rel); | |
bd6c6e2b | 7796 | addend = 0; |
252b5132 RH |
7797 | break; |
7798 | ||
70bccea4 | 7799 | /* Indirect .sdata2 relocation. */ |
7619e7c7 | 7800 | case R_PPC_EMB_SDA2I16: |
c9a2f333 | 7801 | BFD_ASSERT (htab->sdata[1].section != NULL); |
bd6c6e2b AM |
7802 | if (!is_static_defined (htab->sdata[1].sym)) |
7803 | { | |
7804 | unresolved_reloc = TRUE; | |
7805 | break; | |
7806 | } | |
7619e7c7 | 7807 | relocation |
76750a2f AM |
7808 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1], |
7809 | h, relocation, rel); | |
bd6c6e2b | 7810 | addend = 0; |
252b5132 RH |
7811 | break; |
7812 | ||
70bccea4 AM |
7813 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
7814 | section, not the actual VMA. This is appropriate when generating | |
7815 | an embedded ELF object, for which the .got section acts like the | |
7816 | AIX .toc section. */ | |
7619e7c7 | 7817 | case R_PPC_TOC16: /* phony GOT16 relocations */ |
3b4f3a11 AM |
7818 | if (sec == NULL || sec->output_section == NULL) |
7819 | { | |
7820 | unresolved_reloc = TRUE; | |
7821 | break; | |
7822 | } | |
7823 | BFD_ASSERT (strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 | |
f12123c0 | 7824 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0); |
252b5132 | 7825 | |
3b4f3a11 | 7826 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; |
252b5132 RH |
7827 | break; |
7828 | ||
7619e7c7 | 7829 | case R_PPC_PLTREL24: |
e054468f | 7830 | if (h == NULL || ifunc != NULL) |
6d78d0b9 | 7831 | break; |
252b5132 | 7832 | /* Relocation is to the entry for this symbol in the |
70bccea4 | 7833 | procedure linkage table. */ |
a6aa5195 | 7834 | { |
a877a2b6 AM |
7835 | struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2, |
7836 | info->shared ? addend : 0); | |
a6aa5195 AM |
7837 | addend = 0; |
7838 | if (ent == NULL | |
7839 | || htab->plt == NULL) | |
7840 | { | |
7841 | /* We didn't make a PLT entry for this symbol. This | |
7842 | happens when statically linking PIC code, or when | |
7843 | using -Bsymbolic. */ | |
7844 | break; | |
7845 | } | |
252b5132 | 7846 | |
a6aa5195 | 7847 | unresolved_reloc = FALSE; |
4a3dc543 | 7848 | if (htab->plt_type == PLT_NEW) |
a6aa5195 AM |
7849 | relocation = (htab->glink->output_section->vma |
7850 | + htab->glink->output_offset | |
7851 | + ent->glink_offset); | |
7852 | else | |
7853 | relocation = (htab->plt->output_section->vma | |
7854 | + htab->plt->output_offset | |
7855 | + ent->plt.offset); | |
7856 | } | |
8da6118f | 7857 | break; |
252b5132 | 7858 | |
70bccea4 | 7859 | /* Relocate against _SDA_BASE_. */ |
7619e7c7 | 7860 | case R_PPC_SDAREL16: |
252b5132 RH |
7861 | { |
7862 | const char *name; | |
bd6c6e2b | 7863 | struct elf_link_hash_entry *sda = htab->sdata[0].sym; |
252b5132 | 7864 | |
bd6c6e2b AM |
7865 | if (sec == NULL |
7866 | || sec->output_section == NULL | |
7867 | || !is_static_defined (sda)) | |
3b4f3a11 AM |
7868 | { |
7869 | unresolved_reloc = TRUE; | |
7870 | break; | |
7871 | } | |
bd6c6e2b | 7872 | addend -= SYM_VAL (sda); |
3b4f3a11 | 7873 | |
252b5132 | 7874 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 | 7875 | if (! ((CONST_STRNEQ (name, ".sdata") |
5f819128 | 7876 | && (name[6] == 0 || name[6] == '.')) |
0112cd26 | 7877 | || (CONST_STRNEQ (name, ".sbss") |
5f819128 | 7878 | && (name[5] == 0 || name[5] == '.')))) |
252b5132 | 7879 | { |
55fd94b0 | 7880 | (*_bfd_error_handler) |
d003868e | 7881 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 7882 | "in the wrong output section (%s)"), |
d003868e | 7883 | input_bfd, |
55fd94b0 AM |
7884 | sym_name, |
7885 | howto->name, | |
7886 | name); | |
252b5132 | 7887 | } |
252b5132 RH |
7888 | } |
7889 | break; | |
7890 | ||
70bccea4 | 7891 | /* Relocate against _SDA2_BASE_. */ |
7619e7c7 | 7892 | case R_PPC_EMB_SDA2REL: |
252b5132 RH |
7893 | { |
7894 | const char *name; | |
bd6c6e2b | 7895 | struct elf_link_hash_entry *sda = htab->sdata[1].sym; |
252b5132 | 7896 | |
bd6c6e2b AM |
7897 | if (sec == NULL |
7898 | || sec->output_section == NULL | |
7899 | || !is_static_defined (sda)) | |
3b4f3a11 AM |
7900 | { |
7901 | unresolved_reloc = TRUE; | |
7902 | break; | |
7903 | } | |
bd6c6e2b | 7904 | addend -= SYM_VAL (sda); |
3b4f3a11 | 7905 | |
252b5132 | 7906 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 NC |
7907 | if (! (CONST_STRNEQ (name, ".sdata2") |
7908 | || CONST_STRNEQ (name, ".sbss2"))) | |
252b5132 | 7909 | { |
55fd94b0 | 7910 | (*_bfd_error_handler) |
d003868e | 7911 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 7912 | "in the wrong output section (%s)"), |
d003868e | 7913 | input_bfd, |
55fd94b0 AM |
7914 | sym_name, |
7915 | howto->name, | |
7916 | name); | |
252b5132 | 7917 | } |
252b5132 RH |
7918 | } |
7919 | break; | |
7920 | ||
70bccea4 | 7921 | /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */ |
7619e7c7 AM |
7922 | case R_PPC_EMB_SDA21: |
7923 | case R_PPC_EMB_RELSDA: | |
252b5132 RH |
7924 | { |
7925 | const char *name; | |
7926 | int reg; | |
bd6c6e2b | 7927 | struct elf_link_hash_entry *sda = NULL; |
252b5132 | 7928 | |
3b4f3a11 AM |
7929 | if (sec == NULL || sec->output_section == NULL) |
7930 | { | |
7931 | unresolved_reloc = TRUE; | |
7932 | break; | |
7933 | } | |
7934 | ||
252b5132 | 7935 | name = bfd_get_section_name (abfd, sec->output_section); |
0112cd26 | 7936 | if (((CONST_STRNEQ (name, ".sdata") |
5f819128 | 7937 | && (name[6] == 0 || name[6] == '.')) |
0112cd26 | 7938 | || (CONST_STRNEQ (name, ".sbss") |
5f819128 | 7939 | && (name[5] == 0 || name[5] == '.')))) |
252b5132 RH |
7940 | { |
7941 | reg = 13; | |
bd6c6e2b | 7942 | sda = htab->sdata[0].sym; |
252b5132 | 7943 | } |
0112cd26 NC |
7944 | else if (CONST_STRNEQ (name, ".sdata2") |
7945 | || CONST_STRNEQ (name, ".sbss2")) | |
252b5132 RH |
7946 | { |
7947 | reg = 2; | |
bd6c6e2b | 7948 | sda = htab->sdata[1].sym; |
252b5132 | 7949 | } |
8da6118f KH |
7950 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 |
7951 | || strcmp (name, ".PPC.EMB.sbss0") == 0) | |
252b5132 RH |
7952 | { |
7953 | reg = 0; | |
7954 | } | |
252b5132 RH |
7955 | else |
7956 | { | |
55fd94b0 | 7957 | (*_bfd_error_handler) |
d003868e | 7958 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 7959 | "in the wrong output section (%s)"), |
d003868e | 7960 | input_bfd, |
55fd94b0 AM |
7961 | sym_name, |
7962 | howto->name, | |
7963 | name); | |
252b5132 RH |
7964 | |
7965 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 7966 | ret = FALSE; |
252b5132 RH |
7967 | continue; |
7968 | } | |
7969 | ||
bd6c6e2b AM |
7970 | if (sda != NULL) |
7971 | { | |
7972 | if (!is_static_defined (sda)) | |
7973 | { | |
7974 | unresolved_reloc = TRUE; | |
7975 | break; | |
7976 | } | |
7977 | addend -= SYM_VAL (sda); | |
7978 | } | |
7979 | ||
252b5132 | 7980 | if (r_type == R_PPC_EMB_SDA21) |
91d6fa6a NC |
7981 | { |
7982 | bfd_vma insn; /* Fill in register field. */ | |
7983 | ||
7619e7c7 | 7984 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
252b5132 | 7985 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); |
7619e7c7 | 7986 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
252b5132 RH |
7987 | } |
7988 | } | |
7989 | break; | |
7990 | ||
70bccea4 | 7991 | /* Relocate against the beginning of the section. */ |
7619e7c7 AM |
7992 | case R_PPC_SECTOFF: |
7993 | case R_PPC_SECTOFF_LO: | |
7994 | case R_PPC_SECTOFF_HI: | |
7995 | case R_PPC_SECTOFF_HA: | |
3b4f3a11 AM |
7996 | if (sec == NULL || sec->output_section == NULL) |
7997 | { | |
7998 | unresolved_reloc = TRUE; | |
7999 | break; | |
8000 | } | |
252b5132 | 8001 | addend -= sec->output_section->vma; |
252b5132 RH |
8002 | break; |
8003 | ||
70bccea4 | 8004 | /* Negative relocations. */ |
7619e7c7 AM |
8005 | case R_PPC_EMB_NADDR32: |
8006 | case R_PPC_EMB_NADDR16: | |
8007 | case R_PPC_EMB_NADDR16_LO: | |
8008 | case R_PPC_EMB_NADDR16_HI: | |
8009 | case R_PPC_EMB_NADDR16_HA: | |
8da6118f | 8010 | addend -= 2 * relocation; |
252b5132 RH |
8011 | break; |
8012 | ||
7619e7c7 AM |
8013 | case R_PPC_COPY: |
8014 | case R_PPC_GLOB_DAT: | |
8015 | case R_PPC_JMP_SLOT: | |
8016 | case R_PPC_RELATIVE: | |
e054468f | 8017 | case R_PPC_IRELATIVE: |
7619e7c7 AM |
8018 | case R_PPC_PLT32: |
8019 | case R_PPC_PLTREL32: | |
8020 | case R_PPC_PLT16_LO: | |
8021 | case R_PPC_PLT16_HI: | |
8022 | case R_PPC_PLT16_HA: | |
8023 | case R_PPC_ADDR30: | |
8024 | case R_PPC_EMB_RELSEC16: | |
8025 | case R_PPC_EMB_RELST_LO: | |
8026 | case R_PPC_EMB_RELST_HI: | |
8027 | case R_PPC_EMB_RELST_HA: | |
8028 | case R_PPC_EMB_BIT_FLD: | |
8029 | (*_bfd_error_handler) | |
d003868e AM |
8030 | (_("%B: relocation %s is not yet supported for symbol %s."), |
8031 | input_bfd, | |
7619e7c7 AM |
8032 | howto->name, |
8033 | sym_name); | |
252b5132 RH |
8034 | |
8035 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 8036 | ret = FALSE; |
252b5132 | 8037 | continue; |
7619e7c7 | 8038 | } |
252b5132 | 8039 | |
7619e7c7 AM |
8040 | /* Do any further special processing. */ |
8041 | switch (r_type) | |
8042 | { | |
8043 | default: | |
8044 | break; | |
8045 | ||
8046 | case R_PPC_ADDR16_HA: | |
d7128ce4 | 8047 | case R_PPC_REL16_HA: |
7619e7c7 AM |
8048 | case R_PPC_SECTOFF_HA: |
8049 | case R_PPC_TPREL16_HA: | |
8050 | case R_PPC_DTPREL16_HA: | |
7619e7c7 AM |
8051 | case R_PPC_EMB_NADDR16_HA: |
8052 | case R_PPC_EMB_RELST_HA: | |
8053 | /* It's just possible that this symbol is a weak symbol | |
7b609f53 | 8054 | that's not actually defined anywhere. In that case, |
7619e7c7 AM |
8055 | 'sec' would be NULL, and we should leave the symbol |
8056 | alone (it will be set to zero elsewhere in the link). */ | |
5c5f6e17 AM |
8057 | if (sec == NULL) |
8058 | break; | |
8059 | /* Fall thru */ | |
8060 | ||
8061 | case R_PPC_PLT16_HA: | |
8062 | case R_PPC_GOT16_HA: | |
8063 | case R_PPC_GOT_TLSGD16_HA: | |
8064 | case R_PPC_GOT_TLSLD16_HA: | |
8065 | case R_PPC_GOT_TPREL16_HA: | |
8066 | case R_PPC_GOT_DTPREL16_HA: | |
8067 | /* Add 0x10000 if sign bit in 0:15 is set. | |
8068 | Bits 0:15 are not used. */ | |
8069 | addend += 0x8000; | |
7619e7c7 | 8070 | break; |
252b5132 RH |
8071 | } |
8072 | ||
252b5132 | 8073 | #ifdef DEBUG |
55fd94b0 AM |
8074 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, " |
8075 | "offset = %ld, addend = %ld\n", | |
252b5132 | 8076 | howto->name, |
8da6118f | 8077 | (int) r_type, |
252b5132 RH |
8078 | sym_name, |
8079 | r_symndx, | |
7619e7c7 | 8080 | (long) rel->r_offset, |
8da6118f | 8081 | (long) addend); |
252b5132 RH |
8082 | #endif |
8083 | ||
7619e7c7 AM |
8084 | if (unresolved_reloc |
8085 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
f5385ebf | 8086 | && h->def_dynamic)) |
7619e7c7 AM |
8087 | { |
8088 | (*_bfd_error_handler) | |
d003868e AM |
8089 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
8090 | input_bfd, | |
8091 | input_section, | |
7619e7c7 | 8092 | (long) rel->r_offset, |
7b609f53 | 8093 | howto->name, |
7619e7c7 AM |
8094 | sym_name); |
8095 | ret = FALSE; | |
8096 | } | |
8097 | ||
252b5132 RH |
8098 | r = _bfd_final_link_relocate (howto, |
8099 | input_bfd, | |
8100 | input_section, | |
8101 | contents, | |
7619e7c7 | 8102 | rel->r_offset, |
252b5132 RH |
8103 | relocation, |
8104 | addend); | |
8105 | ||
7619e7c7 | 8106 | if (r != bfd_reloc_ok) |
252b5132 | 8107 | { |
7619e7c7 | 8108 | if (r == bfd_reloc_overflow) |
252b5132 | 8109 | { |
7619e7c7 AM |
8110 | if (warned) |
8111 | continue; | |
8112 | if (h != NULL | |
8113 | && h->root.type == bfd_link_hash_undefweak | |
dc1bc0c9 RH |
8114 | && howto->pc_relative) |
8115 | { | |
8116 | /* Assume this is a call protected by other code that | |
8117 | detect the symbol is undefined. If this is the case, | |
8118 | we can safely ignore the overflow. If not, the | |
8119 | program is hosed anyway, and a little warning isn't | |
8120 | going to help. */ | |
252b5132 | 8121 | |
dc1bc0c9 RH |
8122 | continue; |
8123 | } | |
252b5132 | 8124 | |
7619e7c7 | 8125 | if (! (*info->callbacks->reloc_overflow) (info, |
dfeffb9f | 8126 | (h ? &h->root : NULL), |
7619e7c7 AM |
8127 | sym_name, |
8128 | howto->name, | |
8129 | rel->r_addend, | |
8130 | input_bfd, | |
8131 | input_section, | |
8132 | rel->r_offset)) | |
8133 | return FALSE; | |
dc1bc0c9 RH |
8134 | } |
8135 | else | |
8136 | { | |
7619e7c7 | 8137 | (*_bfd_error_handler) |
d003868e AM |
8138 | (_("%B(%A+0x%lx): %s reloc against `%s': error %d"), |
8139 | input_bfd, input_section, | |
7b609f53 | 8140 | (long) rel->r_offset, howto->name, sym_name, (int) r); |
7619e7c7 | 8141 | ret = FALSE; |
252b5132 RH |
8142 | } |
8143 | } | |
8144 | } | |
8145 | ||
252b5132 RH |
8146 | #ifdef DEBUG |
8147 | fprintf (stderr, "\n"); | |
8148 | #endif | |
8149 | ||
8150 | return ret; | |
8151 | } | |
252b5132 | 8152 | \f |
25dbc73a AM |
8153 | /* Finish up dynamic symbol handling. We set the contents of various |
8154 | dynamic sections here. */ | |
c5fccbec | 8155 | |
b34976b6 | 8156 | static bfd_boolean |
25dbc73a AM |
8157 | ppc_elf_finish_dynamic_symbol (bfd *output_bfd, |
8158 | struct bfd_link_info *info, | |
8159 | struct elf_link_hash_entry *h, | |
8160 | Elf_Internal_Sym *sym) | |
e1a9cb8e | 8161 | { |
25dbc73a | 8162 | struct ppc_elf_link_hash_table *htab; |
a6aa5195 AM |
8163 | struct plt_entry *ent; |
8164 | bfd_boolean doneone; | |
e1a9cb8e | 8165 | |
25dbc73a AM |
8166 | #ifdef DEBUG |
8167 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", | |
8168 | h->root.root.string); | |
8169 | #endif | |
e1a9cb8e | 8170 | |
25dbc73a AM |
8171 | htab = ppc_elf_hash_table (info); |
8172 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
e1a9cb8e | 8173 | |
a6aa5195 AM |
8174 | doneone = FALSE; |
8175 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8176 | if (ent->plt.offset != (bfd_vma) -1) | |
8177 | { | |
8178 | if (!doneone) | |
8179 | { | |
8180 | Elf_Internal_Rela rela; | |
8181 | bfd_byte *loc; | |
8182 | bfd_vma reloc_index; | |
e1a9cb8e | 8183 | |
e054468f | 8184 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
8185 | || !htab->elf.dynamic_sections_created |
8186 | || h->dynindx == -1) | |
9d8504b1 PB |
8187 | reloc_index = ent->plt.offset / 4; |
8188 | else | |
8189 | { | |
8190 | reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size) | |
8191 | / htab->plt_slot_size); | |
8192 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES | |
4a3dc543 | 8193 | && htab->plt_type == PLT_OLD) |
9d8504b1 PB |
8194 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; |
8195 | } | |
8196 | ||
a6aa5195 AM |
8197 | /* This symbol has an entry in the procedure linkage table. |
8198 | Set it up. */ | |
e054468f | 8199 | if (htab->plt_type == PLT_VXWORKS |
25f23106 AM |
8200 | && htab->elf.dynamic_sections_created |
8201 | && h->dynindx != -1) | |
a6aa5195 | 8202 | { |
9d8504b1 PB |
8203 | bfd_vma got_offset; |
8204 | const bfd_vma *plt_entry; | |
8205 | ||
8206 | /* The first three entries in .got.plt are reserved. */ | |
8207 | got_offset = (reloc_index + 3) * 4; | |
8208 | ||
8209 | /* Use the right PLT. */ | |
8210 | plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry | |
8211 | : ppc_elf_vxworks_plt_entry; | |
8212 | ||
8213 | /* Fill in the .plt on VxWorks. */ | |
8214 | if (info->shared) | |
8215 | { | |
9d8504b1 | 8216 | bfd_put_32 (output_bfd, |
e87d4038 | 8217 | plt_entry[0] | PPC_HA (got_offset), |
9d8504b1 PB |
8218 | htab->plt->contents + ent->plt.offset + 0); |
8219 | bfd_put_32 (output_bfd, | |
e87d4038 | 8220 | plt_entry[1] | PPC_LO (got_offset), |
9d8504b1 PB |
8221 | htab->plt->contents + ent->plt.offset + 4); |
8222 | } | |
8223 | else | |
8224 | { | |
e87d4038 | 8225 | bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot); |
9d8504b1 PB |
8226 | |
8227 | bfd_put_32 (output_bfd, | |
e87d4038 | 8228 | plt_entry[0] | PPC_HA (got_loc), |
9d8504b1 PB |
8229 | htab->plt->contents + ent->plt.offset + 0); |
8230 | bfd_put_32 (output_bfd, | |
e87d4038 | 8231 | plt_entry[1] | PPC_LO (got_loc), |
9d8504b1 PB |
8232 | htab->plt->contents + ent->plt.offset + 4); |
8233 | } | |
8234 | ||
8235 | bfd_put_32 (output_bfd, plt_entry[2], | |
8236 | htab->plt->contents + ent->plt.offset + 8); | |
8237 | bfd_put_32 (output_bfd, plt_entry[3], | |
8238 | htab->plt->contents + ent->plt.offset + 12); | |
8239 | ||
8240 | /* This instruction is an immediate load. The value loaded is | |
8241 | the byte offset of the R_PPC_JMP_SLOT relocation from the | |
8242 | start of the .rela.plt section. The value is stored in the | |
8243 | low-order 16 bits of the load instruction. */ | |
8244 | /* NOTE: It appears that this is now an index rather than a | |
8245 | prescaled offset. */ | |
8246 | bfd_put_32 (output_bfd, | |
8247 | plt_entry[4] | reloc_index, | |
8248 | htab->plt->contents + ent->plt.offset + 16); | |
8249 | /* This instruction is a PC-relative branch whose target is | |
8250 | the start of the PLT section. The address of this branch | |
8251 | instruction is 20 bytes beyond the start of this PLT entry. | |
8252 | The address is encoded in bits 6-29, inclusive. The value | |
8253 | stored is right-shifted by two bits, permitting a 26-bit | |
8254 | offset. */ | |
8255 | bfd_put_32 (output_bfd, | |
8256 | (plt_entry[5] | |
8257 | | (-(ent->plt.offset + 20) & 0x03fffffc)), | |
8258 | htab->plt->contents + ent->plt.offset + 20); | |
8259 | bfd_put_32 (output_bfd, plt_entry[6], | |
8260 | htab->plt->contents + ent->plt.offset + 24); | |
8261 | bfd_put_32 (output_bfd, plt_entry[7], | |
8262 | htab->plt->contents + ent->plt.offset + 28); | |
8263 | ||
8264 | /* Fill in the GOT entry corresponding to this PLT slot with | |
8265 | the address immediately after the the "bctr" instruction | |
8266 | in this PLT entry. */ | |
8267 | bfd_put_32 (output_bfd, (htab->plt->output_section->vma | |
8268 | + htab->plt->output_offset | |
8269 | + ent->plt.offset + 16), | |
8270 | htab->sgotplt->contents + got_offset); | |
8271 | ||
8272 | if (!info->shared) | |
8273 | { | |
8274 | /* Fill in a couple of entries in .rela.plt.unloaded. */ | |
8275 | loc = htab->srelplt2->contents | |
8276 | + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index | |
8277 | * VXWORKS_PLT_NON_JMP_SLOT_RELOCS) | |
8278 | * sizeof (Elf32_External_Rela)); | |
8279 | ||
8280 | /* Provide the @ha relocation for the first instruction. */ | |
8281 | rela.r_offset = (htab->plt->output_section->vma | |
8282 | + htab->plt->output_offset | |
8283 | + ent->plt.offset + 2); | |
636ce3f5 | 8284 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
8285 | R_PPC_ADDR16_HA); |
8286 | rela.r_addend = got_offset; | |
8287 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8288 | loc += sizeof (Elf32_External_Rela); | |
8289 | ||
8290 | /* Provide the @l relocation for the second instruction. */ | |
8291 | rela.r_offset = (htab->plt->output_section->vma | |
8292 | + htab->plt->output_offset | |
8293 | + ent->plt.offset + 6); | |
636ce3f5 | 8294 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, |
9d8504b1 PB |
8295 | R_PPC_ADDR16_LO); |
8296 | rela.r_addend = got_offset; | |
8297 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8298 | loc += sizeof (Elf32_External_Rela); | |
8299 | ||
8300 | /* Provide a relocation for the GOT entry corresponding to this | |
8301 | PLT slot. Point it at the middle of the .plt entry. */ | |
8302 | rela.r_offset = (htab->sgotplt->output_section->vma | |
8303 | + htab->sgotplt->output_offset | |
8304 | + got_offset); | |
7325306f | 8305 | rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, |
9d8504b1 PB |
8306 | R_PPC_ADDR32); |
8307 | rela.r_addend = ent->plt.offset + 16; | |
8308 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8309 | } | |
8310 | ||
8311 | /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT. | |
8312 | In particular, the offset for the relocation is not the | |
8313 | address of the PLT entry for this function, as specified | |
8314 | by the ABI. Instead, the offset is set to the address of | |
8315 | the GOT slot for this function. See EABI 4.4.4.1. */ | |
8316 | rela.r_offset = (htab->sgotplt->output_section->vma | |
8317 | + htab->sgotplt->output_offset | |
8318 | + got_offset); | |
8319 | ||
a6aa5195 AM |
8320 | } |
8321 | else | |
8322 | { | |
e054468f | 8323 | asection *splt = htab->plt; |
25f23106 AM |
8324 | if (!htab->elf.dynamic_sections_created |
8325 | || h->dynindx == -1) | |
e054468f AM |
8326 | splt = htab->iplt; |
8327 | ||
8328 | rela.r_offset = (splt->output_section->vma | |
8329 | + splt->output_offset | |
9d8504b1 | 8330 | + ent->plt.offset); |
e054468f | 8331 | if (htab->plt_type == PLT_OLD |
25f23106 AM |
8332 | || !htab->elf.dynamic_sections_created |
8333 | || h->dynindx == -1) | |
9d8504b1 PB |
8334 | { |
8335 | /* We don't need to fill in the .plt. The ppc dynamic | |
8336 | linker will fill it in. */ | |
8337 | } | |
8338 | else | |
8339 | { | |
8340 | bfd_vma val = (htab->glink_pltresolve + ent->plt.offset | |
8341 | + htab->glink->output_section->vma | |
8342 | + htab->glink->output_offset); | |
8343 | bfd_put_32 (output_bfd, val, | |
e054468f | 8344 | splt->contents + ent->plt.offset); |
9d8504b1 | 8345 | } |
a6aa5195 | 8346 | } |
e1a9cb8e | 8347 | |
a6aa5195 | 8348 | /* Fill in the entry in the .rela.plt section. */ |
a6aa5195 | 8349 | rela.r_addend = 0; |
e054468f AM |
8350 | if (!htab->elf.dynamic_sections_created |
8351 | || h->dynindx == -1) | |
8352 | { | |
8353 | BFD_ASSERT (h->type == STT_GNU_IFUNC | |
8354 | && h->def_regular | |
8355 | && (h->root.type == bfd_link_hash_defined | |
8356 | || h->root.type == bfd_link_hash_defweak)); | |
8357 | rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE); | |
8358 | rela.r_addend = SYM_VAL (h); | |
8359 | } | |
8360 | else | |
8361 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); | |
e1a9cb8e | 8362 | |
25f23106 AM |
8363 | if (!htab->elf.dynamic_sections_created |
8364 | || h->dynindx == -1) | |
8365 | loc = (htab->reliplt->contents | |
8366 | + (htab->reliplt->reloc_count++ | |
8367 | * sizeof (Elf32_External_Rela))); | |
e054468f | 8368 | else |
25f23106 AM |
8369 | loc = (htab->relplt->contents |
8370 | + reloc_index * sizeof (Elf32_External_Rela)); | |
a6aa5195 | 8371 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
e1a9cb8e | 8372 | |
a6aa5195 AM |
8373 | if (!h->def_regular) |
8374 | { | |
0eb4a168 AM |
8375 | /* Mark the symbol as undefined, rather than as |
8376 | defined in the .plt section. Leave the value if | |
8377 | there were any relocations where pointer equality | |
8378 | matters (this is a clue for the dynamic linker, to | |
8379 | make function pointer comparisons work between an | |
8380 | application and shared library), otherwise set it | |
8381 | to zero. */ | |
a6aa5195 | 8382 | sym->st_shndx = SHN_UNDEF; |
0eb4a168 | 8383 | if (!h->pointer_equality_needed) |
a6aa5195 | 8384 | sym->st_value = 0; |
0eb4a168 AM |
8385 | else if (!h->ref_regular_nonweak) |
8386 | { | |
625af618 AM |
8387 | /* This breaks function pointer comparisons, but |
8388 | that is better than breaking tests for a NULL | |
0eb4a168 | 8389 | function pointer. */ |
0eb4a168 AM |
8390 | sym->st_value = 0; |
8391 | } | |
a6aa5195 | 8392 | } |
de972ffa AM |
8393 | else if (h->type == STT_GNU_IFUNC |
8394 | && !info->shared) | |
8395 | { | |
8396 | /* Set the value of ifunc symbols in a non-pie | |
8397 | executable to the glink entry. This is to avoid | |
8398 | text relocations. We can't do this for ifunc in | |
8399 | allocate_dynrelocs, as we do for normal dynamic | |
8400 | function symbols with plt entries, because we need | |
8401 | to keep the original value around for the ifunc | |
8402 | relocation. */ | |
8403 | sym->st_shndx = (_bfd_elf_section_from_bfd_section | |
8404 | (output_bfd, htab->glink->output_section)); | |
8405 | sym->st_value = (ent->glink_offset + | |
8406 | htab->glink->output_offset | |
8407 | + htab->glink->output_section->vma); | |
8408 | } | |
a6aa5195 AM |
8409 | doneone = TRUE; |
8410 | } | |
e1a9cb8e | 8411 | |
e054468f | 8412 | if (htab->plt_type == PLT_NEW |
25f23106 AM |
8413 | || !htab->elf.dynamic_sections_created |
8414 | || h->dynindx == -1) | |
a6aa5195 | 8415 | { |
a7f2871e | 8416 | unsigned char *p; |
e054468f | 8417 | asection *splt = htab->plt; |
25f23106 AM |
8418 | if (!htab->elf.dynamic_sections_created |
8419 | || h->dynindx == -1) | |
e054468f | 8420 | splt = htab->iplt; |
e1a9cb8e | 8421 | |
a7f2871e AM |
8422 | p = (unsigned char *) htab->glink->contents + ent->glink_offset; |
8423 | ||
8424 | if (h == htab->tls_get_addr && !htab->no_tls_get_addr_opt) | |
8425 | { | |
8426 | bfd_put_32 (output_bfd, LWZ_11_3, p); | |
8427 | p += 4; | |
8428 | bfd_put_32 (output_bfd, LWZ_12_3 + 4, p); | |
8429 | p += 4; | |
8430 | bfd_put_32 (output_bfd, MR_0_3, p); | |
8431 | p += 4; | |
8432 | bfd_put_32 (output_bfd, CMPWI_11_0, p); | |
8433 | p += 4; | |
8434 | bfd_put_32 (output_bfd, ADD_3_12_2, p); | |
8435 | p += 4; | |
8436 | bfd_put_32 (output_bfd, BEQLR, p); | |
8437 | p += 4; | |
8438 | bfd_put_32 (output_bfd, MR_3_0, p); | |
8439 | p += 4; | |
8440 | bfd_put_32 (output_bfd, NOP, p); | |
8441 | p += 4; | |
8442 | } | |
8443 | ||
8444 | write_glink_stub (ent, splt, p, info); | |
e1a9cb8e | 8445 | |
a877a2b6 | 8446 | if (!info->shared) |
e054468f AM |
8447 | /* We only need one non-PIC glink stub. */ |
8448 | break; | |
a6aa5195 AM |
8449 | } |
8450 | else | |
8451 | break; | |
8452 | } | |
e1a9cb8e | 8453 | |
25dbc73a AM |
8454 | if (h->needs_copy) |
8455 | { | |
8456 | asection *s; | |
8457 | Elf_Internal_Rela rela; | |
8458 | bfd_byte *loc; | |
e1a9cb8e | 8459 | |
25dbc73a | 8460 | /* This symbols needs a copy reloc. Set it up. */ |
e1a9cb8e | 8461 | |
25dbc73a AM |
8462 | #ifdef DEBUG |
8463 | fprintf (stderr, ", copy"); | |
8464 | #endif | |
e1a9cb8e | 8465 | |
25dbc73a | 8466 | BFD_ASSERT (h->dynindx != -1); |
86bbe32f | 8467 | |
4dc4a9a5 | 8468 | if (ppc_elf_hash_entry (h)->has_sda_refs) |
25dbc73a AM |
8469 | s = htab->relsbss; |
8470 | else | |
8471 | s = htab->relbss; | |
8472 | BFD_ASSERT (s != NULL); | |
e1a9cb8e | 8473 | |
e87d4038 | 8474 | rela.r_offset = SYM_VAL (h); |
25dbc73a AM |
8475 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); |
8476 | rela.r_addend = 0; | |
8477 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); | |
8478 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8479 | } | |
e1a9cb8e | 8480 | |
25dbc73a AM |
8481 | #ifdef DEBUG |
8482 | fprintf (stderr, "\n"); | |
8483 | #endif | |
e1a9cb8e | 8484 | |
25dbc73a | 8485 | /* Mark some specially defined symbols as absolute. */ |
9d8504b1 PB |
8486 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
8487 | || (!htab->is_vxworks | |
8488 | && (h == htab->elf.hgot | |
8489 | || strcmp (h->root.root.string, | |
8490 | "_PROCEDURE_LINKAGE_TABLE_") == 0))) | |
25dbc73a | 8491 | sym->st_shndx = SHN_ABS; |
e1a9cb8e | 8492 | |
25dbc73a AM |
8493 | return TRUE; |
8494 | } | |
8495 | \f | |
8496 | static enum elf_reloc_type_class | |
8497 | ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela) | |
e1a9cb8e | 8498 | { |
25dbc73a AM |
8499 | switch (ELF32_R_TYPE (rela->r_info)) |
8500 | { | |
8501 | case R_PPC_RELATIVE: | |
8502 | return reloc_class_relative; | |
8503 | case R_PPC_REL24: | |
8504 | case R_PPC_ADDR24: | |
8505 | case R_PPC_JMP_SLOT: | |
8506 | return reloc_class_plt; | |
8507 | case R_PPC_COPY: | |
8508 | return reloc_class_copy; | |
8509 | default: | |
8510 | return reloc_class_normal; | |
8511 | } | |
e1a9cb8e | 8512 | } |
25dbc73a AM |
8513 | \f |
8514 | /* Finish up the dynamic sections. */ | |
e1a9cb8e | 8515 | |
25dbc73a AM |
8516 | static bfd_boolean |
8517 | ppc_elf_finish_dynamic_sections (bfd *output_bfd, | |
8518 | struct bfd_link_info *info) | |
e1a9cb8e | 8519 | { |
25dbc73a | 8520 | asection *sdyn; |
9d8504b1 | 8521 | asection *splt; |
25dbc73a | 8522 | struct ppc_elf_link_hash_table *htab; |
1fe44d79 | 8523 | bfd_vma got; |
e87d4038 AM |
8524 | bfd *dynobj; |
8525 | bfd_boolean ret = TRUE; | |
e1a9cb8e | 8526 | |
25dbc73a AM |
8527 | #ifdef DEBUG |
8528 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
8529 | #endif | |
6b0817e5 | 8530 | |
25dbc73a | 8531 | htab = ppc_elf_hash_table (info); |
9d8504b1 PB |
8532 | dynobj = elf_hash_table (info)->dynobj; |
8533 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
8534 | if (htab->is_vxworks) | |
8535 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
8536 | else | |
8537 | splt = NULL; | |
e1a9cb8e | 8538 | |
1fe44d79 AM |
8539 | got = 0; |
8540 | if (htab->elf.hgot != NULL) | |
e87d4038 | 8541 | got = SYM_VAL (htab->elf.hgot); |
1fe44d79 | 8542 | |
25dbc73a | 8543 | if (htab->elf.dynamic_sections_created) |
e1a9cb8e | 8544 | { |
25dbc73a | 8545 | Elf32_External_Dyn *dyncon, *dynconend; |
e1a9cb8e | 8546 | |
25dbc73a | 8547 | BFD_ASSERT (htab->plt != NULL && sdyn != NULL); |
86bbe32f | 8548 | |
25dbc73a AM |
8549 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
8550 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); | |
8551 | for (; dyncon < dynconend; dyncon++) | |
8552 | { | |
8553 | Elf_Internal_Dyn dyn; | |
8554 | asection *s; | |
e1a9cb8e | 8555 | |
9d8504b1 | 8556 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
86bbe32f | 8557 | |
25dbc73a AM |
8558 | switch (dyn.d_tag) |
8559 | { | |
8560 | case DT_PLTGOT: | |
9d8504b1 PB |
8561 | if (htab->is_vxworks) |
8562 | s = htab->sgotplt; | |
8563 | else | |
8564 | s = htab->plt; | |
25dbc73a AM |
8565 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
8566 | break; | |
86bbe32f | 8567 | |
25dbc73a AM |
8568 | case DT_PLTRELSZ: |
8569 | dyn.d_un.d_val = htab->relplt->size; | |
8570 | break; | |
e1a9cb8e | 8571 | |
25dbc73a AM |
8572 | case DT_JMPREL: |
8573 | s = htab->relplt; | |
8574 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
8575 | break; | |
2f89ff8d | 8576 | |
1fe44d79 AM |
8577 | case DT_PPC_GOT: |
8578 | dyn.d_un.d_ptr = got; | |
d7128ce4 AM |
8579 | break; |
8580 | ||
9d8504b1 PB |
8581 | case DT_RELASZ: |
8582 | if (htab->is_vxworks) | |
8583 | { | |
8584 | if (htab->relplt) | |
8585 | dyn.d_un.d_ptr -= htab->relplt->size; | |
8586 | break; | |
8587 | } | |
8588 | continue; | |
8589 | ||
25dbc73a | 8590 | default: |
7a2b07ff NS |
8591 | if (htab->is_vxworks |
8592 | && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) | |
8593 | break; | |
25dbc73a AM |
8594 | continue; |
8595 | } | |
4c45e5c9 | 8596 | |
25dbc73a AM |
8597 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
8598 | } | |
8599 | } | |
4c45e5c9 | 8600 | |
3b36f7e6 | 8601 | if (htab->got != NULL) |
25dbc73a | 8602 | { |
e79f5955 AM |
8603 | if (htab->elf.hgot->root.u.def.section == htab->got |
8604 | || htab->elf.hgot->root.u.def.section == htab->sgotplt) | |
e87d4038 | 8605 | { |
e79f5955 | 8606 | unsigned char *p = htab->elf.hgot->root.u.def.section->contents; |
2f89ff8d | 8607 | |
e87d4038 AM |
8608 | p += htab->elf.hgot->root.u.def.value; |
8609 | if (htab->plt_type == PLT_OLD) | |
e79f5955 AM |
8610 | { |
8611 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 | |
8612 | so that a function can easily find the address of | |
8613 | _GLOBAL_OFFSET_TABLE_. */ | |
8614 | BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4 | |
8615 | < htab->elf.hgot->root.u.def.section->size); | |
8616 | bfd_put_32 (output_bfd, 0x4e800021, p - 4); | |
8617 | } | |
3b36f7e6 | 8618 | |
e87d4038 | 8619 | if (sdyn != NULL) |
e79f5955 AM |
8620 | { |
8621 | bfd_vma val = sdyn->output_section->vma + sdyn->output_offset; | |
8622 | BFD_ASSERT (htab->elf.hgot->root.u.def.value | |
8623 | < htab->elf.hgot->root.u.def.section->size); | |
8624 | bfd_put_32 (output_bfd, val, p); | |
8625 | } | |
e87d4038 AM |
8626 | } |
8627 | else | |
8628 | { | |
8629 | (*_bfd_error_handler) (_("%s not defined in linker created %s"), | |
8630 | htab->elf.hgot->root.root.string, | |
e79f5955 AM |
8631 | (htab->sgotplt != NULL |
8632 | ? htab->sgotplt->name : htab->got->name)); | |
e87d4038 AM |
8633 | bfd_set_error (bfd_error_bad_value); |
8634 | ret = FALSE; | |
8635 | } | |
25dbc73a AM |
8636 | |
8637 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4; | |
8638 | } | |
8639 | ||
9d8504b1 PB |
8640 | /* Fill in the first entry in the VxWorks procedure linkage table. */ |
8641 | if (splt && splt->size > 0) | |
8642 | { | |
8643 | /* Use the right PLT. */ | |
8644 | static const bfd_vma *plt_entry = NULL; | |
8645 | plt_entry = info->shared ? | |
8646 | ppc_elf_vxworks_pic_plt0_entry : ppc_elf_vxworks_plt0_entry; | |
8647 | ||
8648 | if (!info->shared) | |
8649 | { | |
e87d4038 | 8650 | bfd_vma got_value = SYM_VAL (htab->elf.hgot); |
9d8504b1 | 8651 | |
e87d4038 | 8652 | bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value), |
9d8504b1 | 8653 | splt->contents + 0); |
e87d4038 | 8654 | bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value), |
9d8504b1 PB |
8655 | splt->contents + 4); |
8656 | } | |
8657 | else | |
8658 | { | |
8659 | bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0); | |
8660 | bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4); | |
8661 | } | |
8662 | bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8); | |
8663 | bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12); | |
8664 | bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16); | |
8665 | bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20); | |
8666 | bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24); | |
8667 | bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28); | |
8668 | ||
8669 | if (! info->shared) | |
8670 | { | |
8671 | Elf_Internal_Rela rela; | |
8672 | bfd_byte *loc; | |
8673 | ||
8674 | loc = htab->srelplt2->contents; | |
8675 | ||
8676 | /* Output the @ha relocation for the first instruction. */ | |
8677 | rela.r_offset = (htab->plt->output_section->vma | |
8678 | + htab->plt->output_offset | |
8679 | + 2); | |
636ce3f5 | 8680 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
8681 | rela.r_addend = 0; |
8682 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8683 | loc += sizeof (Elf32_External_Rela); | |
8684 | ||
8685 | /* Output the @l relocation for the second instruction. */ | |
8686 | rela.r_offset = (htab->plt->output_section->vma | |
8687 | + htab->plt->output_offset | |
8688 | + 6); | |
636ce3f5 | 8689 | rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
8690 | rela.r_addend = 0; |
8691 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
8692 | loc += sizeof (Elf32_External_Rela); | |
8693 | ||
8694 | /* Fix up the remaining relocations. They may have the wrong | |
8695 | symbol index for _G_O_T_ or _P_L_T_ depending on the order | |
8696 | in which symbols were output. */ | |
8697 | while (loc < htab->srelplt2->contents + htab->srelplt2->size) | |
8698 | { | |
8699 | Elf_Internal_Rela rel; | |
8700 | ||
8701 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 8702 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA); |
9d8504b1 PB |
8703 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8704 | loc += sizeof (Elf32_External_Rela); | |
8705 | ||
8706 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
636ce3f5 | 8707 | rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO); |
9d8504b1 PB |
8708 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8709 | loc += sizeof (Elf32_External_Rela); | |
8710 | ||
8711 | bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); | |
7325306f | 8712 | rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32); |
9d8504b1 PB |
8713 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
8714 | loc += sizeof (Elf32_External_Rela); | |
8715 | } | |
8716 | } | |
8717 | } | |
8718 | ||
e054468f AM |
8719 | if (htab->glink != NULL |
8720 | && htab->glink->contents != NULL | |
8721 | && htab->elf.dynamic_sections_created) | |
d7128ce4 AM |
8722 | { |
8723 | unsigned char *p; | |
8724 | unsigned char *endp; | |
a6aa5195 | 8725 | bfd_vma res0; |
d7128ce4 | 8726 | unsigned int i; |
a6aa5195 AM |
8727 | |
8728 | /* | |
8729 | * PIC glink code is the following: | |
8730 | * | |
8731 | * # ith PLT code stub. | |
8732 | * addis 11,30,(plt+(i-1)*4-got)@ha | |
8733 | * lwz 11,(plt+(i-1)*4-got)@l(11) | |
8734 | * mtctr 11 | |
8735 | * bctr | |
8736 | * | |
8737 | * # A table of branches, one for each plt entry. | |
176a0d42 | 8738 | * # The idea is that the plt call stub loads ctr and r11 with these |
a6aa5195 AM |
8739 | * # addresses, so (r11 - res_0) gives the plt index * 4. |
8740 | * res_0: b PLTresolve | |
8741 | * res_1: b PLTresolve | |
8742 | * . | |
8743 | * # Some number of entries towards the end can be nops | |
8744 | * res_n_m3: nop | |
8745 | * res_n_m2: nop | |
8746 | * res_n_m1: | |
8747 | * | |
8748 | * PLTresolve: | |
8749 | * addis 11,11,(1f-res_0)@ha | |
8750 | * mflr 0 | |
8751 | * bcl 20,31,1f | |
8752 | * 1: addi 11,11,(1b-res_0)@l | |
8753 | * mflr 12 | |
8754 | * mtlr 0 | |
8755 | * sub 11,11,12 # r11 = index * 4 | |
8756 | * addis 12,12,(got+4-1b)@ha | |
8757 | * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve | |
8758 | * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address | |
8759 | * mtctr 0 | |
8760 | * add 0,11,11 | |
8761 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
8762 | * bctr | |
8763 | */ | |
8764 | static const unsigned int pic_plt_resolve[] = | |
8765 | { | |
8766 | ADDIS_11_11, | |
8767 | MFLR_0, | |
8768 | BCL_20_31, | |
8769 | ADDI_11_11, | |
8770 | MFLR_12, | |
8771 | MTLR_0, | |
8772 | SUB_11_11_12, | |
8773 | ADDIS_12_12, | |
8774 | LWZ_0_12, | |
8775 | LWZ_12_12, | |
8776 | MTCTR_0, | |
8777 | ADD_0_11_11, | |
8778 | ADD_11_0_11, | |
8779 | BCTR, | |
8780 | NOP, | |
8781 | NOP | |
8782 | }; | |
8783 | ||
176a0d42 AM |
8784 | /* |
8785 | * Non-PIC glink code is a little simpler. | |
8786 | * | |
8787 | * # ith PLT code stub. | |
8788 | * lis 11,(plt+(i-1)*4)@ha | |
8789 | * lwz 11,(plt+(i-1)*4)@l(11) | |
8790 | * mtctr 11 | |
8791 | * bctr | |
8792 | * | |
8793 | * The branch table is the same, then comes | |
8794 | * | |
8795 | * PLTresolve: | |
8796 | * lis 12,(got+4)@ha | |
8797 | * addis 11,11,(-res_0)@ha | |
8798 | * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve | |
8799 | * addi 11,11,(-res_0)@l # r11 = index * 4 | |
8800 | * mtctr 0 | |
8801 | * add 0,11,11 | |
8802 | * lwz 12,(got+8)@l(12) # got[2] contains the map address | |
8803 | * add 11,0,11 # r11 = index * 12 = reloc offset. | |
8804 | * bctr | |
8805 | */ | |
d7128ce4 AM |
8806 | static const unsigned int plt_resolve[] = |
8807 | { | |
a6aa5195 AM |
8808 | LIS_12, |
8809 | ADDIS_11_11, | |
8810 | LWZ_0_12, | |
8811 | ADDI_11_11, | |
d7128ce4 | 8812 | MTCTR_0, |
7e8aeb9a | 8813 | ADD_0_11_11, |
a6aa5195 | 8814 | LWZ_12_12, |
7e8aeb9a | 8815 | ADD_11_0_11, |
d7128ce4 AM |
8816 | BCTR, |
8817 | NOP, | |
8818 | NOP, | |
a6aa5195 AM |
8819 | NOP, |
8820 | NOP, | |
8821 | NOP, | |
8822 | NOP, | |
d7128ce4 AM |
8823 | NOP |
8824 | }; | |
8825 | ||
a6aa5195 AM |
8826 | if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4) |
8827 | abort (); | |
8828 | if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4) | |
7e8aeb9a AM |
8829 | abort (); |
8830 | ||
a6aa5195 | 8831 | /* Build the branch table, one for each plt entry (less one), |
86b9da88 | 8832 | and perhaps some padding. */ |
a6aa5195 AM |
8833 | p = htab->glink->contents; |
8834 | p += htab->glink_pltresolve; | |
86b9da88 AM |
8835 | endp = htab->glink->contents; |
8836 | endp += htab->glink->size - GLINK_PLTRESOLVE; | |
8837 | while (p < endp - 8 * 4) | |
8838 | { | |
8839 | bfd_put_32 (output_bfd, B + endp - p, p); | |
8840 | p += 4; | |
8841 | } | |
8842 | while (p < endp) | |
8843 | { | |
8844 | bfd_put_32 (output_bfd, NOP, p); | |
8845 | p += 4; | |
8846 | } | |
8847 | ||
7e8aeb9a | 8848 | res0 = (htab->glink_pltresolve |
86b9da88 AM |
8849 | + htab->glink->output_section->vma |
8850 | + htab->glink->output_offset); | |
8851 | ||
8852 | /* Last comes the PLTresolve stub. */ | |
a877a2b6 | 8853 | if (info->shared) |
7e8aeb9a | 8854 | { |
a6aa5195 | 8855 | bfd_vma bcl; |
d7128ce4 | 8856 | |
a6aa5195 | 8857 | for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++) |
7e8aeb9a | 8858 | { |
a6aa5195 | 8859 | bfd_put_32 (output_bfd, pic_plt_resolve[i], p); |
7e8aeb9a AM |
8860 | p += 4; |
8861 | } | |
a6aa5195 AM |
8862 | p -= 4 * ARRAY_SIZE (pic_plt_resolve); |
8863 | ||
8864 | bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4 | |
8865 | + htab->glink->output_section->vma | |
8866 | + htab->glink->output_offset); | |
8867 | ||
8868 | bfd_put_32 (output_bfd, | |
8869 | ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4); | |
8870 | bfd_put_32 (output_bfd, | |
8871 | ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4); | |
8872 | bfd_put_32 (output_bfd, | |
8873 | ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4); | |
8874 | if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl)) | |
8875 | { | |
8876 | bfd_put_32 (output_bfd, | |
8877 | LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
8878 | bfd_put_32 (output_bfd, | |
8879 | LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4); | |
8880 | } | |
8881 | else | |
8882 | { | |
8883 | bfd_put_32 (output_bfd, | |
8884 | LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4); | |
8885 | bfd_put_32 (output_bfd, | |
8886 | LWZ_12_12 + 4, p + 9*4); | |
8887 | } | |
7e8aeb9a AM |
8888 | } |
8889 | else | |
d7128ce4 | 8890 | { |
a6aa5195 | 8891 | for (i = 0; i < ARRAY_SIZE (plt_resolve); i++) |
7e8aeb9a AM |
8892 | { |
8893 | bfd_put_32 (output_bfd, plt_resolve[i], p); | |
8894 | p += 4; | |
8895 | } | |
a6aa5195 AM |
8896 | p -= 4 * ARRAY_SIZE (plt_resolve); |
8897 | ||
8898 | bfd_put_32 (output_bfd, | |
8899 | LIS_12 + PPC_HA (got + 4), p + 0*4); | |
8900 | bfd_put_32 (output_bfd, | |
8901 | ADDIS_11_11 + PPC_HA (-res0), p + 1*4); | |
8902 | bfd_put_32 (output_bfd, | |
8903 | ADDI_11_11 + PPC_LO (-res0), p + 3*4); | |
8904 | if (PPC_HA (got + 4) == PPC_HA (got + 8)) | |
8905 | { | |
8906 | bfd_put_32 (output_bfd, | |
8907 | LWZ_0_12 + PPC_LO (got + 4), p + 2*4); | |
8908 | bfd_put_32 (output_bfd, | |
8909 | LWZ_12_12 + PPC_LO (got + 8), p + 6*4); | |
8910 | } | |
8911 | else | |
8912 | { | |
8913 | bfd_put_32 (output_bfd, | |
8914 | LWZU_0_12 + PPC_LO (got + 4), p + 2*4); | |
8915 | bfd_put_32 (output_bfd, | |
8916 | LWZ_12_12 + 4, p + 6*4); | |
8917 | } | |
d7128ce4 | 8918 | } |
d7128ce4 AM |
8919 | } |
8920 | ||
e87d4038 | 8921 | return ret; |
25dbc73a | 8922 | } |
e1a9cb8e | 8923 | \f |
252b5132 RH |
8924 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
8925 | #define TARGET_LITTLE_NAME "elf32-powerpcle" | |
8926 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec | |
8927 | #define TARGET_BIG_NAME "elf32-powerpc" | |
8928 | #define ELF_ARCH bfd_arch_powerpc | |
8929 | #define ELF_MACHINE_CODE EM_PPC | |
d0facd1b NC |
8930 | #ifdef __QNXTARGET__ |
8931 | #define ELF_MAXPAGESIZE 0x1000 | |
8932 | #else | |
252b5132 | 8933 | #define ELF_MAXPAGESIZE 0x10000 |
d0facd1b | 8934 | #endif |
b1342370 | 8935 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 8936 | #define ELF_COMMONPAGESIZE 0x1000 |
252b5132 RH |
8937 | #define elf_info_to_howto ppc_elf_info_to_howto |
8938 | ||
8939 | #ifdef EM_CYGNUS_POWERPC | |
8940 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
8941 | #endif | |
8942 | ||
8943 | #ifdef EM_PPC_OLD | |
8944 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
8945 | #endif | |
8946 | ||
8947 | #define elf_backend_plt_not_loaded 1 | |
252b5132 | 8948 | #define elf_backend_can_gc_sections 1 |
51b64d56 | 8949 | #define elf_backend_can_refcount 1 |
b491616a | 8950 | #define elf_backend_rela_normal 1 |
252b5132 | 8951 | |
43c40ab2 | 8952 | #define bfd_elf32_mkobject ppc_elf_mkobject |
252b5132 | 8953 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
70bccea4 | 8954 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section |
252b5132 | 8955 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup |
157090f7 | 8956 | #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup |
252b5132 | 8957 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags |
70bccea4 | 8958 | #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create |
468392fb | 8959 | #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab |
252b5132 | 8960 | |
feee612b | 8961 | #define elf_backend_object_p ppc_elf_object_p |
252b5132 RH |
8962 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
8963 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook | |
8964 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr | |
8965 | #define elf_backend_relocate_section ppc_elf_relocate_section | |
8966 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections | |
8967 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
7fce784e | 8968 | #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol |
252b5132 RH |
8969 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol |
8970 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook | |
8971 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
0eb4a168 | 8972 | #define elf_backend_hash_symbol ppc_elf_hash_symbol |
252b5132 RH |
8973 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol |
8974 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
8975 | #define elf_backend_fake_sections ppc_elf_fake_sections | |
8976 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers | |
c5fccbec DJ |
8977 | #define elf_backend_grok_prstatus ppc_elf_grok_prstatus |
8978 | #define elf_backend_grok_psinfo ppc_elf_grok_psinfo | |
183e98be | 8979 | #define elf_backend_write_core_note ppc_elf_write_core_note |
29c2fb7c | 8980 | #define elf_backend_reloc_type_class ppc_elf_reloc_type_class |
70bccea4 AM |
8981 | #define elf_backend_begin_write_processing ppc_elf_begin_write_processing |
8982 | #define elf_backend_final_write_processing ppc_elf_final_write_processing | |
8983 | #define elf_backend_write_section ppc_elf_write_section | |
551b43fd | 8984 | #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr |
4c45e5c9 | 8985 | #define elf_backend_plt_sym_val ppc_elf_plt_sym_val |
8a696751 | 8986 | #define elf_backend_action_discarded ppc_elf_action_discarded |
74541ad4 | 8987 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
e054468f | 8988 | #define elf_backend_post_process_headers _bfd_elf_set_osabi |
252b5132 RH |
8989 | |
8990 | #include "elf32-target.h" | |
9d8504b1 PB |
8991 | |
8992 | /* VxWorks Target */ | |
8993 | ||
8994 | #undef TARGET_LITTLE_SYM | |
8995 | #undef TARGET_LITTLE_NAME | |
8996 | ||
8997 | #undef TARGET_BIG_SYM | |
8998 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec | |
8999 | #undef TARGET_BIG_NAME | |
9000 | #define TARGET_BIG_NAME "elf32-powerpc-vxworks" | |
9001 | ||
d5e3d971 PB |
9002 | /* VxWorks uses the elf default section flags for .plt. */ |
9003 | static const struct bfd_elf_special_section * | |
9004 | ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) | |
9d8504b1 | 9005 | { |
d5e3d971 PB |
9006 | if (sec->name == NULL) |
9007 | return NULL; | |
9008 | ||
9009 | if (strcmp (sec->name, ".plt") == 0) | |
9010 | return _bfd_elf_get_sec_type_attr (abfd, sec); | |
9011 | ||
9012 | return ppc_elf_get_sec_type_attr (abfd, sec); | |
9013 | } | |
9d8504b1 PB |
9014 | |
9015 | /* Like ppc_elf_link_hash_table_create, but overrides | |
9016 | appropriately for VxWorks. */ | |
9017 | static struct bfd_link_hash_table * | |
9018 | ppc_elf_vxworks_link_hash_table_create (bfd *abfd) | |
9019 | { | |
9020 | struct bfd_link_hash_table *ret; | |
9021 | ||
9022 | ret = ppc_elf_link_hash_table_create (abfd); | |
9023 | if (ret) | |
9024 | { | |
9025 | struct ppc_elf_link_hash_table *htab | |
9026 | = (struct ppc_elf_link_hash_table *)ret; | |
9027 | htab->is_vxworks = 1; | |
4a3dc543 | 9028 | htab->plt_type = PLT_VXWORKS; |
9d8504b1 PB |
9029 | htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE; |
9030 | htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE; | |
9031 | htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE; | |
9032 | } | |
9033 | return ret; | |
9034 | } | |
9035 | ||
9036 | /* Tweak magic VxWorks symbols as they are loaded. */ | |
9037 | static bfd_boolean | |
9038 | ppc_elf_vxworks_add_symbol_hook (bfd *abfd, | |
9039 | struct bfd_link_info *info, | |
9040 | Elf_Internal_Sym *sym, | |
9041 | const char **namep ATTRIBUTE_UNUSED, | |
9042 | flagword *flagsp ATTRIBUTE_UNUSED, | |
9043 | asection **secp, | |
9044 | bfd_vma *valp) | |
9045 | { | |
9046 | if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, | |
9047 | valp)) | |
9048 | return FALSE; | |
9049 | ||
9050 | return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp); | |
9051 | } | |
9052 | ||
9d8504b1 PB |
9053 | static void |
9054 | ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
9055 | { | |
9056 | ppc_elf_final_write_processing(abfd, linker); | |
9057 | elf_vxworks_final_write_processing(abfd, linker); | |
9058 | } | |
9059 | ||
9060 | /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so | |
9061 | define it. */ | |
9062 | #undef elf_backend_want_plt_sym | |
9063 | #define elf_backend_want_plt_sym 1 | |
9064 | #undef elf_backend_want_got_plt | |
9065 | #define elf_backend_want_got_plt 1 | |
9066 | #undef elf_backend_got_symbol_offset | |
9067 | #define elf_backend_got_symbol_offset 0 | |
9068 | #undef elf_backend_plt_not_loaded | |
9069 | #define elf_backend_plt_not_loaded 0 | |
9070 | #undef elf_backend_plt_readonly | |
9071 | #define elf_backend_plt_readonly 1 | |
9072 | #undef elf_backend_got_header_size | |
9073 | #define elf_backend_got_header_size 12 | |
9074 | ||
468392fb AM |
9075 | #undef bfd_elf32_get_synthetic_symtab |
9076 | ||
9d8504b1 PB |
9077 | #undef bfd_elf32_bfd_link_hash_table_create |
9078 | #define bfd_elf32_bfd_link_hash_table_create \ | |
9079 | ppc_elf_vxworks_link_hash_table_create | |
9d8504b1 PB |
9080 | #undef elf_backend_add_symbol_hook |
9081 | #define elf_backend_add_symbol_hook \ | |
9082 | ppc_elf_vxworks_add_symbol_hook | |
9083 | #undef elf_backend_link_output_symbol_hook | |
9084 | #define elf_backend_link_output_symbol_hook \ | |
9c72ff84 | 9085 | elf_vxworks_link_output_symbol_hook |
9d8504b1 PB |
9086 | #undef elf_backend_final_write_processing |
9087 | #define elf_backend_final_write_processing \ | |
9088 | ppc_elf_vxworks_final_write_processing | |
d5e3d971 PB |
9089 | #undef elf_backend_get_sec_type_attr |
9090 | #define elf_backend_get_sec_type_attr \ | |
9091 | ppc_elf_vxworks_get_sec_type_attr | |
9d8504b1 PB |
9092 | #undef elf_backend_emit_relocs |
9093 | #define elf_backend_emit_relocs \ | |
9094 | elf_vxworks_emit_relocs | |
9095 | ||
9096 | #undef elf32_bed | |
9097 | #define elf32_bed ppc_elf_vxworks_bed | |
e054468f | 9098 | #undef elf_backend_post_process_headers |
9d8504b1 PB |
9099 | |
9100 | #include "elf32-target.h" |