]>
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, |
264a1fe0 | 3 | 2004, 2005 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 | |
10 | the Free Software Foundation; either version 2 of the License, or | |
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 RH |
22 | |
23 | /* This file is based on a preliminary PowerPC ELF ABI. The | |
24 | information may not match the final PowerPC ELF ABI. It includes | |
25 | suggestions from the in-progress Embedded PowerPC ABI, and that | |
26 | information may also not match. */ | |
27 | ||
28 | #include "bfd.h" | |
29 | #include "sysdep.h" | |
30 | #include "bfdlink.h" | |
31 | #include "libbfd.h" | |
32 | #include "elf-bfd.h" | |
33 | #include "elf/ppc.h" | |
7619e7c7 | 34 | #include "elf32-ppc.h" |
252b5132 | 35 | |
f0fe0e16 | 36 | /* RELA relocations are used here. */ |
252b5132 | 37 | |
252b5132 | 38 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
55fd94b0 | 39 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
7619e7c7 | 40 | static bfd_reloc_status_type ppc_elf_unhandled_reloc |
55fd94b0 | 41 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
252b5132 | 42 | |
70bccea4 AM |
43 | /* Branch prediction bit for branch taken relocs. */ |
44 | #define BRANCH_PREDICT_BIT 0x200000 | |
45 | /* Mask to set RA in memory instructions. */ | |
46 | #define RA_REGISTER_MASK 0x001f0000 | |
47 | /* Value to shift register by to insert RA. */ | |
48 | #define RA_REGISTER_SHIFT 16 | |
252b5132 RH |
49 | |
50 | /* The name of the dynamic interpreter. This is put in the .interp | |
51 | section. */ | |
252b5132 RH |
52 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
53 | ||
d7128ce4 | 54 | /* For old-style PLT. */ |
252b5132 RH |
55 | /* The size in bytes of an entry in the procedure linkage table. */ |
56 | #define PLT_ENTRY_SIZE 12 | |
57 | /* The initial size of the plt reserved for the dynamic linker. */ | |
58 | #define PLT_INITIAL_ENTRY_SIZE 72 | |
59 | /* The size of the gap between entries in the PLT. */ | |
60 | #define PLT_SLOT_SIZE 8 | |
61 | /* The number of single-slot PLT entries (the rest use two slots). */ | |
62 | #define PLT_NUM_SINGLE_ENTRIES 8192 | |
63 | ||
d7128ce4 AM |
64 | /* For new-style .glink and .plt. */ |
65 | #define GLINK_PLTRESOLVE 12*4 | |
66 | #define GLINK_ENTRY_SIZE 4*4 | |
67 | ||
68 | /* Some instructions. */ | |
7619e7c7 | 69 | #define NOP 0x60000000 |
86b9da88 | 70 | #define B 0x48000000 |
d7128ce4 AM |
71 | #define ADDIS_11_11 0x3d6b0000 |
72 | #define ADDI_11_11 0x396b0000 | |
73 | #define SUB_11_11_30 0x7d7e5850 | |
74 | #define ADD_0_11_11 0x7c0b5a14 | |
75 | #define ADD_11_0_11 0x7d605a14 | |
76 | #define LWZ_0_4_30 0x801e0004 | |
77 | #define MTCTR_0 0x7c0903a6 | |
78 | #define LWZ_12_8_30 0x819e0008 | |
79 | #define BCTR 0x4e800420 | |
80 | #define ADDIS_11_30 0x3d7e0000 | |
86b9da88 AM |
81 | #define LWZ_11_X_11 0x816b0000 |
82 | #define LWZ_11_X_30 0x817e0000 | |
83 | #define MTCTR_11 0x7d6903a6 | |
7619e7c7 AM |
84 | |
85 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
86 | #define TP_OFFSET 0x7000 | |
87 | #define DTP_OFFSET 0x8000 | |
7fce784e | 88 | \f |
e47cd125 | 89 | static reloc_howto_type *ppc_elf_howto_table[R_PPC_max]; |
252b5132 | 90 | |
8da6118f | 91 | static reloc_howto_type ppc_elf_howto_raw[] = { |
252b5132 RH |
92 | /* This reloc does nothing. */ |
93 | HOWTO (R_PPC_NONE, /* type */ | |
94 | 0, /* rightshift */ | |
95 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
96 | 32, /* bitsize */ | |
b34976b6 | 97 | FALSE, /* pc_relative */ |
252b5132 RH |
98 | 0, /* bitpos */ |
99 | complain_overflow_bitfield, /* complain_on_overflow */ | |
100 | bfd_elf_generic_reloc, /* special_function */ | |
101 | "R_PPC_NONE", /* name */ | |
b34976b6 | 102 | FALSE, /* partial_inplace */ |
252b5132 RH |
103 | 0, /* src_mask */ |
104 | 0, /* dst_mask */ | |
b34976b6 | 105 | FALSE), /* pcrel_offset */ |
252b5132 RH |
106 | |
107 | /* A standard 32 bit relocation. */ | |
108 | HOWTO (R_PPC_ADDR32, /* type */ | |
109 | 0, /* rightshift */ | |
110 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
111 | 32, /* bitsize */ | |
b34976b6 | 112 | FALSE, /* pc_relative */ |
252b5132 RH |
113 | 0, /* bitpos */ |
114 | complain_overflow_bitfield, /* complain_on_overflow */ | |
115 | bfd_elf_generic_reloc, /* special_function */ | |
116 | "R_PPC_ADDR32", /* name */ | |
b34976b6 | 117 | FALSE, /* partial_inplace */ |
252b5132 RH |
118 | 0, /* src_mask */ |
119 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 120 | FALSE), /* pcrel_offset */ |
252b5132 RH |
121 | |
122 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
123 | FIXME: we don't check that, we just clear them. */ | |
124 | HOWTO (R_PPC_ADDR24, /* type */ | |
125 | 0, /* rightshift */ | |
126 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
127 | 26, /* bitsize */ | |
b34976b6 | 128 | FALSE, /* pc_relative */ |
252b5132 RH |
129 | 0, /* bitpos */ |
130 | complain_overflow_bitfield, /* complain_on_overflow */ | |
131 | bfd_elf_generic_reloc, /* special_function */ | |
132 | "R_PPC_ADDR24", /* name */ | |
b34976b6 | 133 | FALSE, /* partial_inplace */ |
252b5132 RH |
134 | 0, /* src_mask */ |
135 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 136 | FALSE), /* pcrel_offset */ |
252b5132 RH |
137 | |
138 | /* A standard 16 bit relocation. */ | |
139 | HOWTO (R_PPC_ADDR16, /* type */ | |
140 | 0, /* rightshift */ | |
141 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
142 | 16, /* bitsize */ | |
b34976b6 | 143 | FALSE, /* pc_relative */ |
252b5132 RH |
144 | 0, /* bitpos */ |
145 | complain_overflow_bitfield, /* complain_on_overflow */ | |
146 | bfd_elf_generic_reloc, /* special_function */ | |
147 | "R_PPC_ADDR16", /* name */ | |
b34976b6 | 148 | FALSE, /* partial_inplace */ |
252b5132 RH |
149 | 0, /* src_mask */ |
150 | 0xffff, /* dst_mask */ | |
b34976b6 | 151 | FALSE), /* pcrel_offset */ |
252b5132 RH |
152 | |
153 | /* A 16 bit relocation without overflow. */ | |
154 | HOWTO (R_PPC_ADDR16_LO, /* type */ | |
155 | 0, /* rightshift */ | |
156 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
157 | 16, /* bitsize */ | |
b34976b6 | 158 | FALSE, /* pc_relative */ |
252b5132 RH |
159 | 0, /* bitpos */ |
160 | complain_overflow_dont,/* complain_on_overflow */ | |
161 | bfd_elf_generic_reloc, /* special_function */ | |
162 | "R_PPC_ADDR16_LO", /* name */ | |
b34976b6 | 163 | FALSE, /* partial_inplace */ |
252b5132 RH |
164 | 0, /* src_mask */ |
165 | 0xffff, /* dst_mask */ | |
b34976b6 | 166 | FALSE), /* pcrel_offset */ |
252b5132 RH |
167 | |
168 | /* The high order 16 bits of an address. */ | |
169 | HOWTO (R_PPC_ADDR16_HI, /* type */ | |
170 | 16, /* rightshift */ | |
171 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
172 | 16, /* bitsize */ | |
b34976b6 | 173 | FALSE, /* pc_relative */ |
252b5132 RH |
174 | 0, /* bitpos */ |
175 | complain_overflow_dont, /* complain_on_overflow */ | |
176 | bfd_elf_generic_reloc, /* special_function */ | |
177 | "R_PPC_ADDR16_HI", /* name */ | |
b34976b6 | 178 | FALSE, /* partial_inplace */ |
252b5132 RH |
179 | 0, /* src_mask */ |
180 | 0xffff, /* dst_mask */ | |
b34976b6 | 181 | FALSE), /* pcrel_offset */ |
252b5132 RH |
182 | |
183 | /* The high order 16 bits of an address, plus 1 if the contents of | |
8da6118f | 184 | the low 16 bits, treated as a signed number, is negative. */ |
252b5132 RH |
185 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
186 | 16, /* rightshift */ | |
187 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
188 | 16, /* bitsize */ | |
b34976b6 | 189 | FALSE, /* pc_relative */ |
252b5132 RH |
190 | 0, /* bitpos */ |
191 | complain_overflow_dont, /* complain_on_overflow */ | |
192 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
193 | "R_PPC_ADDR16_HA", /* name */ | |
b34976b6 | 194 | FALSE, /* partial_inplace */ |
252b5132 RH |
195 | 0, /* src_mask */ |
196 | 0xffff, /* dst_mask */ | |
b34976b6 | 197 | FALSE), /* pcrel_offset */ |
252b5132 RH |
198 | |
199 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
200 | FIXME: we don't check that, we just clear them. */ | |
201 | HOWTO (R_PPC_ADDR14, /* type */ | |
202 | 0, /* rightshift */ | |
203 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
204 | 16, /* bitsize */ | |
b34976b6 | 205 | FALSE, /* pc_relative */ |
252b5132 RH |
206 | 0, /* bitpos */ |
207 | complain_overflow_bitfield, /* complain_on_overflow */ | |
208 | bfd_elf_generic_reloc, /* special_function */ | |
209 | "R_PPC_ADDR14", /* name */ | |
b34976b6 | 210 | FALSE, /* partial_inplace */ |
252b5132 RH |
211 | 0, /* src_mask */ |
212 | 0xfffc, /* dst_mask */ | |
b34976b6 | 213 | FALSE), /* pcrel_offset */ |
252b5132 RH |
214 | |
215 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
216 | indicate that the branch is expected to be taken. The lower two | |
8da6118f | 217 | bits must be zero. */ |
252b5132 RH |
218 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
219 | 0, /* rightshift */ | |
220 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
221 | 16, /* bitsize */ | |
b34976b6 | 222 | FALSE, /* pc_relative */ |
252b5132 RH |
223 | 0, /* bitpos */ |
224 | complain_overflow_bitfield, /* complain_on_overflow */ | |
225 | bfd_elf_generic_reloc, /* special_function */ | |
226 | "R_PPC_ADDR14_BRTAKEN",/* name */ | |
b34976b6 | 227 | FALSE, /* partial_inplace */ |
252b5132 RH |
228 | 0, /* src_mask */ |
229 | 0xfffc, /* dst_mask */ | |
b34976b6 | 230 | FALSE), /* pcrel_offset */ |
252b5132 RH |
231 | |
232 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
233 | indicate that the branch is not expected to be taken. The lower | |
234 | two bits must be zero. */ | |
235 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
236 | 0, /* rightshift */ | |
237 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
238 | 16, /* bitsize */ | |
b34976b6 | 239 | FALSE, /* pc_relative */ |
252b5132 RH |
240 | 0, /* bitpos */ |
241 | complain_overflow_bitfield, /* complain_on_overflow */ | |
242 | bfd_elf_generic_reloc, /* special_function */ | |
243 | "R_PPC_ADDR14_BRNTAKEN",/* name */ | |
b34976b6 | 244 | FALSE, /* partial_inplace */ |
252b5132 RH |
245 | 0, /* src_mask */ |
246 | 0xfffc, /* dst_mask */ | |
b34976b6 | 247 | FALSE), /* pcrel_offset */ |
252b5132 | 248 | |
8da6118f | 249 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
250 | HOWTO (R_PPC_REL24, /* type */ |
251 | 0, /* rightshift */ | |
252 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
253 | 26, /* bitsize */ | |
b34976b6 | 254 | TRUE, /* pc_relative */ |
252b5132 RH |
255 | 0, /* bitpos */ |
256 | complain_overflow_signed, /* complain_on_overflow */ | |
257 | bfd_elf_generic_reloc, /* special_function */ | |
258 | "R_PPC_REL24", /* name */ | |
b34976b6 | 259 | FALSE, /* partial_inplace */ |
252b5132 RH |
260 | 0, /* src_mask */ |
261 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 262 | TRUE), /* pcrel_offset */ |
252b5132 | 263 | |
8da6118f | 264 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
265 | HOWTO (R_PPC_REL14, /* type */ |
266 | 0, /* rightshift */ | |
267 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
268 | 16, /* bitsize */ | |
b34976b6 | 269 | TRUE, /* pc_relative */ |
252b5132 RH |
270 | 0, /* bitpos */ |
271 | complain_overflow_signed, /* complain_on_overflow */ | |
272 | bfd_elf_generic_reloc, /* special_function */ | |
273 | "R_PPC_REL14", /* name */ | |
b34976b6 | 274 | FALSE, /* partial_inplace */ |
252b5132 RH |
275 | 0, /* src_mask */ |
276 | 0xfffc, /* dst_mask */ | |
b34976b6 | 277 | TRUE), /* pcrel_offset */ |
252b5132 | 278 | |
8da6118f | 279 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
280 | the branch is expected to be taken. The lower two bits must be |
281 | zero. */ | |
282 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ | |
283 | 0, /* rightshift */ | |
284 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
285 | 16, /* bitsize */ | |
b34976b6 | 286 | TRUE, /* pc_relative */ |
252b5132 RH |
287 | 0, /* bitpos */ |
288 | complain_overflow_signed, /* complain_on_overflow */ | |
289 | bfd_elf_generic_reloc, /* special_function */ | |
290 | "R_PPC_REL14_BRTAKEN", /* name */ | |
b34976b6 | 291 | FALSE, /* partial_inplace */ |
252b5132 RH |
292 | 0, /* src_mask */ |
293 | 0xfffc, /* dst_mask */ | |
b34976b6 | 294 | TRUE), /* pcrel_offset */ |
252b5132 | 295 | |
8da6118f | 296 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
297 | the branch is not expected to be taken. The lower two bits must |
298 | be zero. */ | |
299 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ | |
300 | 0, /* rightshift */ | |
301 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
302 | 16, /* bitsize */ | |
b34976b6 | 303 | TRUE, /* pc_relative */ |
252b5132 RH |
304 | 0, /* bitpos */ |
305 | complain_overflow_signed, /* complain_on_overflow */ | |
306 | bfd_elf_generic_reloc, /* special_function */ | |
307 | "R_PPC_REL14_BRNTAKEN",/* name */ | |
b34976b6 | 308 | FALSE, /* partial_inplace */ |
252b5132 RH |
309 | 0, /* src_mask */ |
310 | 0xfffc, /* dst_mask */ | |
b34976b6 | 311 | TRUE), /* pcrel_offset */ |
252b5132 RH |
312 | |
313 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
314 | symbol. */ | |
315 | HOWTO (R_PPC_GOT16, /* type */ | |
316 | 0, /* rightshift */ | |
317 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
318 | 16, /* bitsize */ | |
b34976b6 | 319 | FALSE, /* pc_relative */ |
252b5132 RH |
320 | 0, /* bitpos */ |
321 | complain_overflow_signed, /* complain_on_overflow */ | |
322 | bfd_elf_generic_reloc, /* special_function */ | |
323 | "R_PPC_GOT16", /* name */ | |
b34976b6 | 324 | FALSE, /* partial_inplace */ |
252b5132 RH |
325 | 0, /* src_mask */ |
326 | 0xffff, /* dst_mask */ | |
b34976b6 | 327 | FALSE), /* pcrel_offset */ |
252b5132 RH |
328 | |
329 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
330 | the symbol. */ | |
331 | HOWTO (R_PPC_GOT16_LO, /* type */ | |
332 | 0, /* rightshift */ | |
333 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
334 | 16, /* bitsize */ | |
b34976b6 | 335 | FALSE, /* pc_relative */ |
252b5132 RH |
336 | 0, /* bitpos */ |
337 | complain_overflow_dont, /* complain_on_overflow */ | |
338 | bfd_elf_generic_reloc, /* special_function */ | |
339 | "R_PPC_GOT16_LO", /* name */ | |
b34976b6 | 340 | FALSE, /* partial_inplace */ |
252b5132 RH |
341 | 0, /* src_mask */ |
342 | 0xffff, /* dst_mask */ | |
b34976b6 | 343 | FALSE), /* pcrel_offset */ |
252b5132 RH |
344 | |
345 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
346 | the symbol. */ | |
347 | HOWTO (R_PPC_GOT16_HI, /* type */ | |
348 | 16, /* rightshift */ | |
349 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
350 | 16, /* bitsize */ | |
b34976b6 | 351 | FALSE, /* pc_relative */ |
252b5132 RH |
352 | 0, /* bitpos */ |
353 | complain_overflow_bitfield, /* complain_on_overflow */ | |
354 | bfd_elf_generic_reloc, /* special_function */ | |
355 | "R_PPC_GOT16_HI", /* name */ | |
b34976b6 | 356 | FALSE, /* partial_inplace */ |
252b5132 RH |
357 | 0, /* src_mask */ |
358 | 0xffff, /* dst_mask */ | |
b34976b6 | 359 | FALSE), /* pcrel_offset */ |
252b5132 RH |
360 | |
361 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
362 | the symbol. */ | |
363 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
364 | 16, /* rightshift */ | |
365 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
366 | 16, /* bitsize */ | |
b34976b6 | 367 | FALSE, /* pc_relative */ |
252b5132 RH |
368 | 0, /* bitpos */ |
369 | complain_overflow_bitfield, /* complain_on_overflow */ | |
370 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
371 | "R_PPC_GOT16_HA", /* name */ | |
b34976b6 | 372 | FALSE, /* partial_inplace */ |
252b5132 RH |
373 | 0, /* src_mask */ |
374 | 0xffff, /* dst_mask */ | |
b34976b6 | 375 | FALSE), /* pcrel_offset */ |
252b5132 RH |
376 | |
377 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
378 | entry for the symbol. */ | |
379 | HOWTO (R_PPC_PLTREL24, /* type */ | |
380 | 0, /* rightshift */ | |
381 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
382 | 26, /* bitsize */ | |
b34976b6 | 383 | TRUE, /* pc_relative */ |
252b5132 RH |
384 | 0, /* bitpos */ |
385 | complain_overflow_signed, /* complain_on_overflow */ | |
386 | bfd_elf_generic_reloc, /* special_function */ | |
387 | "R_PPC_PLTREL24", /* name */ | |
b34976b6 | 388 | FALSE, /* partial_inplace */ |
252b5132 RH |
389 | 0, /* src_mask */ |
390 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 391 | TRUE), /* pcrel_offset */ |
252b5132 RH |
392 | |
393 | /* This is used only by the dynamic linker. The symbol should exist | |
394 | both in the object being run and in some shared library. The | |
395 | dynamic linker copies the data addressed by the symbol from the | |
396 | shared library into the object, because the object being | |
397 | run has to have the data at some particular address. */ | |
398 | HOWTO (R_PPC_COPY, /* type */ | |
399 | 0, /* rightshift */ | |
400 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
401 | 32, /* bitsize */ | |
b34976b6 | 402 | FALSE, /* pc_relative */ |
252b5132 RH |
403 | 0, /* bitpos */ |
404 | complain_overflow_bitfield, /* complain_on_overflow */ | |
405 | bfd_elf_generic_reloc, /* special_function */ | |
406 | "R_PPC_COPY", /* name */ | |
b34976b6 | 407 | FALSE, /* partial_inplace */ |
252b5132 RH |
408 | 0, /* src_mask */ |
409 | 0, /* dst_mask */ | |
b34976b6 | 410 | FALSE), /* pcrel_offset */ |
252b5132 RH |
411 | |
412 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
413 | entries. */ | |
414 | HOWTO (R_PPC_GLOB_DAT, /* type */ | |
415 | 0, /* rightshift */ | |
416 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
417 | 32, /* bitsize */ | |
b34976b6 | 418 | FALSE, /* pc_relative */ |
252b5132 RH |
419 | 0, /* bitpos */ |
420 | complain_overflow_bitfield, /* complain_on_overflow */ | |
421 | bfd_elf_generic_reloc, /* special_function */ | |
422 | "R_PPC_GLOB_DAT", /* name */ | |
b34976b6 | 423 | FALSE, /* partial_inplace */ |
252b5132 RH |
424 | 0, /* src_mask */ |
425 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 426 | FALSE), /* pcrel_offset */ |
252b5132 RH |
427 | |
428 | /* Marks a procedure linkage table entry for a symbol. */ | |
429 | HOWTO (R_PPC_JMP_SLOT, /* type */ | |
430 | 0, /* rightshift */ | |
431 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
432 | 32, /* bitsize */ | |
b34976b6 | 433 | FALSE, /* pc_relative */ |
252b5132 RH |
434 | 0, /* bitpos */ |
435 | complain_overflow_bitfield, /* complain_on_overflow */ | |
436 | bfd_elf_generic_reloc, /* special_function */ | |
437 | "R_PPC_JMP_SLOT", /* name */ | |
b34976b6 | 438 | FALSE, /* partial_inplace */ |
252b5132 RH |
439 | 0, /* src_mask */ |
440 | 0, /* dst_mask */ | |
b34976b6 | 441 | FALSE), /* pcrel_offset */ |
252b5132 RH |
442 | |
443 | /* Used only by the dynamic linker. When the object is run, this | |
444 | longword is set to the load address of the object, plus the | |
445 | addend. */ | |
446 | HOWTO (R_PPC_RELATIVE, /* type */ | |
447 | 0, /* rightshift */ | |
448 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
449 | 32, /* bitsize */ | |
b34976b6 | 450 | FALSE, /* pc_relative */ |
252b5132 RH |
451 | 0, /* bitpos */ |
452 | complain_overflow_bitfield, /* complain_on_overflow */ | |
453 | bfd_elf_generic_reloc, /* special_function */ | |
454 | "R_PPC_RELATIVE", /* name */ | |
b34976b6 | 455 | FALSE, /* partial_inplace */ |
252b5132 RH |
456 | 0, /* src_mask */ |
457 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 458 | FALSE), /* pcrel_offset */ |
252b5132 RH |
459 | |
460 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
461 | object rather than the final value. Normally used for | |
462 | _GLOBAL_OFFSET_TABLE_. */ | |
463 | HOWTO (R_PPC_LOCAL24PC, /* type */ | |
464 | 0, /* rightshift */ | |
465 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
466 | 26, /* bitsize */ | |
b34976b6 | 467 | TRUE, /* pc_relative */ |
252b5132 RH |
468 | 0, /* bitpos */ |
469 | complain_overflow_signed, /* complain_on_overflow */ | |
470 | bfd_elf_generic_reloc, /* special_function */ | |
471 | "R_PPC_LOCAL24PC", /* name */ | |
b34976b6 | 472 | FALSE, /* partial_inplace */ |
252b5132 RH |
473 | 0, /* src_mask */ |
474 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 475 | TRUE), /* pcrel_offset */ |
252b5132 RH |
476 | |
477 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
478 | HOWTO (R_PPC_UADDR32, /* type */ | |
479 | 0, /* rightshift */ | |
480 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
481 | 32, /* bitsize */ | |
b34976b6 | 482 | FALSE, /* pc_relative */ |
252b5132 RH |
483 | 0, /* bitpos */ |
484 | complain_overflow_bitfield, /* complain_on_overflow */ | |
485 | bfd_elf_generic_reloc, /* special_function */ | |
486 | "R_PPC_UADDR32", /* name */ | |
b34976b6 | 487 | FALSE, /* partial_inplace */ |
252b5132 RH |
488 | 0, /* src_mask */ |
489 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 490 | FALSE), /* pcrel_offset */ |
252b5132 RH |
491 | |
492 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
493 | HOWTO (R_PPC_UADDR16, /* type */ | |
494 | 0, /* rightshift */ | |
495 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
496 | 16, /* bitsize */ | |
b34976b6 | 497 | FALSE, /* pc_relative */ |
252b5132 RH |
498 | 0, /* bitpos */ |
499 | complain_overflow_bitfield, /* complain_on_overflow */ | |
500 | bfd_elf_generic_reloc, /* special_function */ | |
501 | "R_PPC_UADDR16", /* name */ | |
b34976b6 | 502 | FALSE, /* partial_inplace */ |
252b5132 RH |
503 | 0, /* src_mask */ |
504 | 0xffff, /* dst_mask */ | |
b34976b6 | 505 | FALSE), /* pcrel_offset */ |
252b5132 RH |
506 | |
507 | /* 32-bit PC relative */ | |
508 | HOWTO (R_PPC_REL32, /* type */ | |
509 | 0, /* rightshift */ | |
510 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
511 | 32, /* bitsize */ | |
b34976b6 | 512 | TRUE, /* pc_relative */ |
252b5132 RH |
513 | 0, /* bitpos */ |
514 | complain_overflow_bitfield, /* complain_on_overflow */ | |
515 | bfd_elf_generic_reloc, /* special_function */ | |
516 | "R_PPC_REL32", /* name */ | |
b34976b6 | 517 | FALSE, /* partial_inplace */ |
252b5132 RH |
518 | 0, /* src_mask */ |
519 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 520 | TRUE), /* pcrel_offset */ |
252b5132 RH |
521 | |
522 | /* 32-bit relocation to the symbol's procedure linkage table. | |
c3668558 | 523 | FIXME: not supported. */ |
252b5132 RH |
524 | HOWTO (R_PPC_PLT32, /* type */ |
525 | 0, /* rightshift */ | |
526 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
527 | 32, /* bitsize */ | |
b34976b6 | 528 | FALSE, /* pc_relative */ |
252b5132 RH |
529 | 0, /* bitpos */ |
530 | complain_overflow_bitfield, /* complain_on_overflow */ | |
531 | bfd_elf_generic_reloc, /* special_function */ | |
532 | "R_PPC_PLT32", /* name */ | |
b34976b6 | 533 | FALSE, /* partial_inplace */ |
252b5132 RH |
534 | 0, /* src_mask */ |
535 | 0, /* dst_mask */ | |
b34976b6 | 536 | FALSE), /* pcrel_offset */ |
252b5132 RH |
537 | |
538 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
c3668558 | 539 | FIXME: not supported. */ |
252b5132 RH |
540 | HOWTO (R_PPC_PLTREL32, /* type */ |
541 | 0, /* rightshift */ | |
542 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
543 | 32, /* bitsize */ | |
b34976b6 | 544 | TRUE, /* pc_relative */ |
252b5132 RH |
545 | 0, /* bitpos */ |
546 | complain_overflow_bitfield, /* complain_on_overflow */ | |
547 | bfd_elf_generic_reloc, /* special_function */ | |
548 | "R_PPC_PLTREL32", /* name */ | |
b34976b6 | 549 | FALSE, /* partial_inplace */ |
252b5132 RH |
550 | 0, /* src_mask */ |
551 | 0, /* dst_mask */ | |
b34976b6 | 552 | TRUE), /* pcrel_offset */ |
252b5132 RH |
553 | |
554 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
555 | the symbol. */ | |
556 | HOWTO (R_PPC_PLT16_LO, /* type */ | |
557 | 0, /* rightshift */ | |
558 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
559 | 16, /* bitsize */ | |
b34976b6 | 560 | FALSE, /* pc_relative */ |
252b5132 RH |
561 | 0, /* bitpos */ |
562 | complain_overflow_dont, /* complain_on_overflow */ | |
563 | bfd_elf_generic_reloc, /* special_function */ | |
564 | "R_PPC_PLT16_LO", /* name */ | |
b34976b6 | 565 | FALSE, /* partial_inplace */ |
252b5132 RH |
566 | 0, /* src_mask */ |
567 | 0xffff, /* dst_mask */ | |
b34976b6 | 568 | FALSE), /* pcrel_offset */ |
252b5132 RH |
569 | |
570 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
571 | the symbol. */ | |
572 | HOWTO (R_PPC_PLT16_HI, /* type */ | |
573 | 16, /* rightshift */ | |
574 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
575 | 16, /* bitsize */ | |
b34976b6 | 576 | FALSE, /* pc_relative */ |
252b5132 RH |
577 | 0, /* bitpos */ |
578 | complain_overflow_bitfield, /* complain_on_overflow */ | |
579 | bfd_elf_generic_reloc, /* special_function */ | |
580 | "R_PPC_PLT16_HI", /* name */ | |
b34976b6 | 581 | FALSE, /* partial_inplace */ |
252b5132 RH |
582 | 0, /* src_mask */ |
583 | 0xffff, /* dst_mask */ | |
b34976b6 | 584 | FALSE), /* pcrel_offset */ |
252b5132 RH |
585 | |
586 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
587 | the symbol. */ | |
588 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
589 | 16, /* rightshift */ | |
590 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
591 | 16, /* bitsize */ | |
b34976b6 | 592 | FALSE, /* pc_relative */ |
252b5132 RH |
593 | 0, /* bitpos */ |
594 | complain_overflow_bitfield, /* complain_on_overflow */ | |
595 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
596 | "R_PPC_PLT16_HA", /* name */ | |
b34976b6 | 597 | FALSE, /* partial_inplace */ |
252b5132 RH |
598 | 0, /* src_mask */ |
599 | 0xffff, /* dst_mask */ | |
b34976b6 | 600 | FALSE), /* pcrel_offset */ |
252b5132 RH |
601 | |
602 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with | |
603 | small data items. */ | |
604 | HOWTO (R_PPC_SDAREL16, /* type */ | |
605 | 0, /* rightshift */ | |
606 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
607 | 16, /* bitsize */ | |
b34976b6 | 608 | FALSE, /* pc_relative */ |
252b5132 RH |
609 | 0, /* bitpos */ |
610 | complain_overflow_signed, /* complain_on_overflow */ | |
611 | bfd_elf_generic_reloc, /* special_function */ | |
612 | "R_PPC_SDAREL16", /* name */ | |
b34976b6 | 613 | FALSE, /* partial_inplace */ |
252b5132 RH |
614 | 0, /* src_mask */ |
615 | 0xffff, /* dst_mask */ | |
b34976b6 | 616 | FALSE), /* pcrel_offset */ |
252b5132 | 617 | |
c061c2d8 | 618 | /* 16-bit section relative relocation. */ |
252b5132 RH |
619 | HOWTO (R_PPC_SECTOFF, /* type */ |
620 | 0, /* rightshift */ | |
c061c2d8 AM |
621 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
622 | 16, /* bitsize */ | |
b34976b6 | 623 | FALSE, /* pc_relative */ |
252b5132 RH |
624 | 0, /* bitpos */ |
625 | complain_overflow_bitfield, /* complain_on_overflow */ | |
626 | bfd_elf_generic_reloc, /* special_function */ | |
627 | "R_PPC_SECTOFF", /* name */ | |
b34976b6 | 628 | FALSE, /* partial_inplace */ |
252b5132 | 629 | 0, /* src_mask */ |
c061c2d8 | 630 | 0xffff, /* dst_mask */ |
b34976b6 | 631 | FALSE), /* pcrel_offset */ |
252b5132 | 632 | |
c3668558 | 633 | /* 16-bit lower half section relative relocation. */ |
252b5132 RH |
634 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
635 | 0, /* rightshift */ | |
636 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
637 | 16, /* bitsize */ | |
b34976b6 | 638 | FALSE, /* pc_relative */ |
252b5132 RH |
639 | 0, /* bitpos */ |
640 | complain_overflow_dont, /* complain_on_overflow */ | |
641 | bfd_elf_generic_reloc, /* special_function */ | |
642 | "R_PPC_SECTOFF_LO", /* name */ | |
b34976b6 | 643 | FALSE, /* partial_inplace */ |
252b5132 RH |
644 | 0, /* src_mask */ |
645 | 0xffff, /* dst_mask */ | |
b34976b6 | 646 | FALSE), /* pcrel_offset */ |
252b5132 | 647 | |
c3668558 | 648 | /* 16-bit upper half section relative relocation. */ |
252b5132 RH |
649 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
650 | 16, /* rightshift */ | |
651 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
652 | 16, /* bitsize */ | |
b34976b6 | 653 | FALSE, /* pc_relative */ |
252b5132 RH |
654 | 0, /* bitpos */ |
655 | complain_overflow_bitfield, /* complain_on_overflow */ | |
656 | bfd_elf_generic_reloc, /* special_function */ | |
657 | "R_PPC_SECTOFF_HI", /* name */ | |
b34976b6 | 658 | FALSE, /* partial_inplace */ |
252b5132 RH |
659 | 0, /* src_mask */ |
660 | 0xffff, /* dst_mask */ | |
b34976b6 | 661 | FALSE), /* pcrel_offset */ |
252b5132 | 662 | |
c3668558 | 663 | /* 16-bit upper half adjusted section relative relocation. */ |
252b5132 RH |
664 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
665 | 16, /* rightshift */ | |
666 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
667 | 16, /* bitsize */ | |
b34976b6 | 668 | FALSE, /* pc_relative */ |
252b5132 RH |
669 | 0, /* bitpos */ |
670 | complain_overflow_bitfield, /* complain_on_overflow */ | |
671 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
672 | "R_PPC_SECTOFF_HA", /* name */ | |
b34976b6 | 673 | FALSE, /* partial_inplace */ |
252b5132 RH |
674 | 0, /* src_mask */ |
675 | 0xffff, /* dst_mask */ | |
b34976b6 | 676 | FALSE), /* pcrel_offset */ |
252b5132 | 677 | |
7619e7c7 AM |
678 | /* Marker reloc for TLS. */ |
679 | HOWTO (R_PPC_TLS, | |
252b5132 RH |
680 | 0, /* rightshift */ |
681 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
682 | 32, /* bitsize */ | |
b34976b6 | 683 | FALSE, /* pc_relative */ |
252b5132 | 684 | 0, /* bitpos */ |
7619e7c7 | 685 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 | 686 | bfd_elf_generic_reloc, /* special_function */ |
7619e7c7 AM |
687 | "R_PPC_TLS", /* name */ |
688 | FALSE, /* partial_inplace */ | |
689 | 0, /* src_mask */ | |
690 | 0, /* dst_mask */ | |
691 | FALSE), /* pcrel_offset */ | |
692 | ||
693 | /* Computes the load module index of the load module that contains the | |
694 | definition of its TLS sym. */ | |
695 | HOWTO (R_PPC_DTPMOD32, | |
696 | 0, /* rightshift */ | |
697 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
698 | 32, /* bitsize */ | |
699 | FALSE, /* pc_relative */ | |
700 | 0, /* bitpos */ | |
701 | complain_overflow_dont, /* complain_on_overflow */ | |
702 | ppc_elf_unhandled_reloc, /* special_function */ | |
703 | "R_PPC_DTPMOD32", /* name */ | |
b34976b6 | 704 | FALSE, /* partial_inplace */ |
252b5132 RH |
705 | 0, /* src_mask */ |
706 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 707 | FALSE), /* pcrel_offset */ |
252b5132 | 708 | |
7619e7c7 AM |
709 | /* Computes a dtv-relative displacement, the difference between the value |
710 | of sym+add and the base address of the thread-local storage block that | |
711 | contains the definition of sym, minus 0x8000. */ | |
712 | HOWTO (R_PPC_DTPREL32, | |
713 | 0, /* rightshift */ | |
714 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
715 | 32, /* bitsize */ | |
716 | FALSE, /* pc_relative */ | |
717 | 0, /* bitpos */ | |
718 | complain_overflow_dont, /* complain_on_overflow */ | |
719 | ppc_elf_unhandled_reloc, /* special_function */ | |
720 | "R_PPC_DTPREL32", /* name */ | |
721 | FALSE, /* partial_inplace */ | |
722 | 0, /* src_mask */ | |
723 | 0xffffffff, /* dst_mask */ | |
724 | FALSE), /* pcrel_offset */ | |
725 | ||
726 | /* A 16 bit dtprel reloc. */ | |
727 | HOWTO (R_PPC_DTPREL16, | |
252b5132 RH |
728 | 0, /* rightshift */ |
729 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
730 | 16, /* bitsize */ | |
b34976b6 | 731 | FALSE, /* pc_relative */ |
252b5132 | 732 | 0, /* bitpos */ |
7619e7c7 AM |
733 | complain_overflow_signed, /* complain_on_overflow */ |
734 | ppc_elf_unhandled_reloc, /* special_function */ | |
735 | "R_PPC_DTPREL16", /* name */ | |
b34976b6 | 736 | FALSE, /* partial_inplace */ |
252b5132 RH |
737 | 0, /* src_mask */ |
738 | 0xffff, /* dst_mask */ | |
b34976b6 | 739 | FALSE), /* pcrel_offset */ |
252b5132 | 740 | |
7619e7c7 AM |
741 | /* Like DTPREL16, but no overflow. */ |
742 | HOWTO (R_PPC_DTPREL16_LO, | |
252b5132 RH |
743 | 0, /* rightshift */ |
744 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
745 | 16, /* bitsize */ | |
b34976b6 | 746 | FALSE, /* pc_relative */ |
252b5132 | 747 | 0, /* bitpos */ |
7619e7c7 AM |
748 | complain_overflow_dont, /* complain_on_overflow */ |
749 | ppc_elf_unhandled_reloc, /* special_function */ | |
750 | "R_PPC_DTPREL16_LO", /* name */ | |
b34976b6 | 751 | FALSE, /* partial_inplace */ |
252b5132 RH |
752 | 0, /* src_mask */ |
753 | 0xffff, /* dst_mask */ | |
b34976b6 | 754 | FALSE), /* pcrel_offset */ |
252b5132 | 755 | |
7619e7c7 AM |
756 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ |
757 | HOWTO (R_PPC_DTPREL16_HI, | |
252b5132 RH |
758 | 16, /* rightshift */ |
759 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
760 | 16, /* bitsize */ | |
b34976b6 | 761 | FALSE, /* pc_relative */ |
252b5132 RH |
762 | 0, /* bitpos */ |
763 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
764 | ppc_elf_unhandled_reloc, /* special_function */ |
765 | "R_PPC_DTPREL16_HI", /* name */ | |
b34976b6 | 766 | FALSE, /* partial_inplace */ |
252b5132 RH |
767 | 0, /* src_mask */ |
768 | 0xffff, /* dst_mask */ | |
b34976b6 | 769 | FALSE), /* pcrel_offset */ |
252b5132 | 770 | |
7619e7c7 AM |
771 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ |
772 | HOWTO (R_PPC_DTPREL16_HA, | |
252b5132 RH |
773 | 16, /* rightshift */ |
774 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
775 | 16, /* bitsize */ | |
b34976b6 | 776 | FALSE, /* pc_relative */ |
252b5132 RH |
777 | 0, /* bitpos */ |
778 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
779 | ppc_elf_unhandled_reloc, /* special_function */ |
780 | "R_PPC_DTPREL16_HA", /* name */ | |
b34976b6 | 781 | FALSE, /* partial_inplace */ |
252b5132 RH |
782 | 0, /* src_mask */ |
783 | 0xffff, /* dst_mask */ | |
b34976b6 | 784 | FALSE), /* pcrel_offset */ |
252b5132 | 785 | |
7619e7c7 AM |
786 | /* Computes a tp-relative displacement, the difference between the value of |
787 | sym+add and the value of the thread pointer (r13). */ | |
788 | HOWTO (R_PPC_TPREL32, | |
789 | 0, /* rightshift */ | |
790 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
791 | 32, /* bitsize */ | |
792 | FALSE, /* pc_relative */ | |
793 | 0, /* bitpos */ | |
794 | complain_overflow_dont, /* complain_on_overflow */ | |
795 | ppc_elf_unhandled_reloc, /* special_function */ | |
796 | "R_PPC_TPREL32", /* name */ | |
797 | FALSE, /* partial_inplace */ | |
798 | 0, /* src_mask */ | |
799 | 0xffffffff, /* dst_mask */ | |
800 | FALSE), /* pcrel_offset */ | |
801 | ||
802 | /* A 16 bit tprel reloc. */ | |
803 | HOWTO (R_PPC_TPREL16, | |
252b5132 RH |
804 | 0, /* rightshift */ |
805 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
806 | 16, /* bitsize */ | |
b34976b6 | 807 | FALSE, /* pc_relative */ |
252b5132 | 808 | 0, /* bitpos */ |
7619e7c7 AM |
809 | complain_overflow_signed, /* complain_on_overflow */ |
810 | ppc_elf_unhandled_reloc, /* special_function */ | |
811 | "R_PPC_TPREL16", /* name */ | |
b34976b6 | 812 | FALSE, /* partial_inplace */ |
252b5132 RH |
813 | 0, /* src_mask */ |
814 | 0xffff, /* dst_mask */ | |
b34976b6 | 815 | FALSE), /* pcrel_offset */ |
252b5132 | 816 | |
7619e7c7 AM |
817 | /* Like TPREL16, but no overflow. */ |
818 | HOWTO (R_PPC_TPREL16_LO, | |
252b5132 RH |
819 | 0, /* rightshift */ |
820 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
821 | 16, /* bitsize */ | |
b34976b6 | 822 | FALSE, /* pc_relative */ |
252b5132 | 823 | 0, /* bitpos */ |
7619e7c7 AM |
824 | complain_overflow_dont, /* complain_on_overflow */ |
825 | ppc_elf_unhandled_reloc, /* special_function */ | |
826 | "R_PPC_TPREL16_LO", /* name */ | |
b34976b6 | 827 | FALSE, /* partial_inplace */ |
252b5132 RH |
828 | 0, /* src_mask */ |
829 | 0xffff, /* dst_mask */ | |
b34976b6 | 830 | FALSE), /* pcrel_offset */ |
252b5132 | 831 | |
7619e7c7 AM |
832 | /* Like TPREL16_LO, but next higher group of 16 bits. */ |
833 | HOWTO (R_PPC_TPREL16_HI, | |
834 | 16, /* rightshift */ | |
835 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
836 | 16, /* bitsize */ | |
837 | FALSE, /* pc_relative */ | |
838 | 0, /* bitpos */ | |
839 | complain_overflow_dont, /* complain_on_overflow */ | |
840 | ppc_elf_unhandled_reloc, /* special_function */ | |
841 | "R_PPC_TPREL16_HI", /* name */ | |
842 | FALSE, /* partial_inplace */ | |
843 | 0, /* src_mask */ | |
844 | 0xffff, /* dst_mask */ | |
845 | FALSE), /* pcrel_offset */ | |
846 | ||
847 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
848 | HOWTO (R_PPC_TPREL16_HA, | |
849 | 16, /* rightshift */ | |
850 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
851 | 16, /* bitsize */ | |
852 | FALSE, /* pc_relative */ | |
853 | 0, /* bitpos */ | |
854 | complain_overflow_dont, /* complain_on_overflow */ | |
855 | ppc_elf_unhandled_reloc, /* special_function */ | |
856 | "R_PPC_TPREL16_HA", /* name */ | |
857 | FALSE, /* partial_inplace */ | |
858 | 0, /* src_mask */ | |
859 | 0xffff, /* dst_mask */ | |
860 | FALSE), /* pcrel_offset */ | |
861 | ||
862 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
863 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
864 | to the first entry. */ | |
865 | HOWTO (R_PPC_GOT_TLSGD16, | |
252b5132 RH |
866 | 0, /* rightshift */ |
867 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
868 | 16, /* bitsize */ | |
b34976b6 | 869 | FALSE, /* pc_relative */ |
252b5132 RH |
870 | 0, /* bitpos */ |
871 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
872 | ppc_elf_unhandled_reloc, /* special_function */ |
873 | "R_PPC_GOT_TLSGD16", /* name */ | |
b34976b6 | 874 | FALSE, /* partial_inplace */ |
252b5132 RH |
875 | 0, /* src_mask */ |
876 | 0xffff, /* dst_mask */ | |
b34976b6 | 877 | FALSE), /* pcrel_offset */ |
252b5132 | 878 | |
7619e7c7 AM |
879 | /* Like GOT_TLSGD16, but no overflow. */ |
880 | HOWTO (R_PPC_GOT_TLSGD16_LO, | |
252b5132 | 881 | 0, /* rightshift */ |
7619e7c7 | 882 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 883 | 16, /* bitsize */ |
b34976b6 | 884 | FALSE, /* pc_relative */ |
252b5132 | 885 | 0, /* bitpos */ |
7619e7c7 AM |
886 | complain_overflow_dont, /* complain_on_overflow */ |
887 | ppc_elf_unhandled_reloc, /* special_function */ | |
888 | "R_PPC_GOT_TLSGD16_LO", /* name */ | |
b34976b6 | 889 | FALSE, /* partial_inplace */ |
252b5132 RH |
890 | 0, /* src_mask */ |
891 | 0xffff, /* dst_mask */ | |
b34976b6 | 892 | FALSE), /* pcrel_offset */ |
252b5132 | 893 | |
7619e7c7 AM |
894 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
895 | HOWTO (R_PPC_GOT_TLSGD16_HI, | |
896 | 16, /* rightshift */ | |
897 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
898 | 16, /* bitsize */ | |
899 | FALSE, /* pc_relative */ | |
900 | 0, /* bitpos */ | |
901 | complain_overflow_dont, /* complain_on_overflow */ | |
902 | ppc_elf_unhandled_reloc, /* special_function */ | |
903 | "R_PPC_GOT_TLSGD16_HI", /* name */ | |
904 | FALSE, /* partial_inplace */ | |
905 | 0, /* src_mask */ | |
906 | 0xffff, /* dst_mask */ | |
907 | FALSE), /* pcrel_offset */ | |
252b5132 | 908 | |
7619e7c7 AM |
909 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
910 | HOWTO (R_PPC_GOT_TLSGD16_HA, | |
911 | 16, /* rightshift */ | |
912 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
913 | 16, /* bitsize */ | |
914 | FALSE, /* pc_relative */ | |
915 | 0, /* bitpos */ | |
916 | complain_overflow_dont, /* complain_on_overflow */ | |
917 | ppc_elf_unhandled_reloc, /* special_function */ | |
918 | "R_PPC_GOT_TLSGD16_HA", /* name */ | |
919 | FALSE, /* partial_inplace */ | |
920 | 0, /* src_mask */ | |
921 | 0xffff, /* dst_mask */ | |
922 | FALSE), /* pcrel_offset */ | |
923 | ||
924 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
925 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
926 | first entry. */ | |
927 | HOWTO (R_PPC_GOT_TLSLD16, | |
252b5132 RH |
928 | 0, /* rightshift */ |
929 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
930 | 16, /* bitsize */ | |
7619e7c7 | 931 | FALSE, /* pc_relative */ |
252b5132 RH |
932 | 0, /* bitpos */ |
933 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
934 | ppc_elf_unhandled_reloc, /* special_function */ |
935 | "R_PPC_GOT_TLSLD16", /* name */ | |
b34976b6 | 936 | FALSE, /* partial_inplace */ |
252b5132 RH |
937 | 0, /* src_mask */ |
938 | 0xffff, /* dst_mask */ | |
b34976b6 | 939 | FALSE), /* pcrel_offset */ |
252b5132 | 940 | |
7619e7c7 AM |
941 | /* Like GOT_TLSLD16, but no overflow. */ |
942 | HOWTO (R_PPC_GOT_TLSLD16_LO, | |
252b5132 | 943 | 0, /* rightshift */ |
7619e7c7 AM |
944 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
945 | 16, /* bitsize */ | |
b34976b6 | 946 | FALSE, /* pc_relative */ |
252b5132 RH |
947 | 0, /* bitpos */ |
948 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
949 | ppc_elf_unhandled_reloc, /* special_function */ |
950 | "R_PPC_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 951 | FALSE, /* partial_inplace */ |
252b5132 | 952 | 0, /* src_mask */ |
7619e7c7 | 953 | 0xffff, /* dst_mask */ |
b34976b6 | 954 | FALSE), /* pcrel_offset */ |
252b5132 | 955 | |
7619e7c7 AM |
956 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
957 | HOWTO (R_PPC_GOT_TLSLD16_HI, | |
958 | 16, /* rightshift */ | |
959 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
960 | 16, /* bitsize */ | |
b34976b6 | 961 | FALSE, /* pc_relative */ |
252b5132 RH |
962 | 0, /* bitpos */ |
963 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
964 | ppc_elf_unhandled_reloc, /* special_function */ |
965 | "R_PPC_GOT_TLSLD16_HI", /* name */ | |
b34976b6 | 966 | FALSE, /* partial_inplace */ |
252b5132 | 967 | 0, /* src_mask */ |
7619e7c7 | 968 | 0xffff, /* dst_mask */ |
b34976b6 | 969 | FALSE), /* pcrel_offset */ |
252b5132 | 970 | |
7619e7c7 AM |
971 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
972 | HOWTO (R_PPC_GOT_TLSLD16_HA, | |
973 | 16, /* rightshift */ | |
974 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
975 | 16, /* bitsize */ | |
976 | FALSE, /* pc_relative */ | |
977 | 0, /* bitpos */ | |
978 | complain_overflow_dont, /* complain_on_overflow */ | |
979 | ppc_elf_unhandled_reloc, /* special_function */ | |
980 | "R_PPC_GOT_TLSLD16_HA", /* name */ | |
981 | FALSE, /* partial_inplace */ | |
982 | 0, /* src_mask */ | |
983 | 0xffff, /* dst_mask */ | |
984 | FALSE), /* pcrel_offset */ | |
985 | ||
986 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes | |
987 | the offset to the entry. */ | |
988 | HOWTO (R_PPC_GOT_DTPREL16, | |
252b5132 RH |
989 | 0, /* rightshift */ |
990 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
991 | 16, /* bitsize */ | |
b34976b6 | 992 | FALSE, /* pc_relative */ |
252b5132 RH |
993 | 0, /* bitpos */ |
994 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
995 | ppc_elf_unhandled_reloc, /* special_function */ |
996 | "R_PPC_GOT_DTPREL16", /* name */ | |
b34976b6 | 997 | FALSE, /* partial_inplace */ |
252b5132 RH |
998 | 0, /* src_mask */ |
999 | 0xffff, /* dst_mask */ | |
b34976b6 | 1000 | FALSE), /* pcrel_offset */ |
252b5132 | 1001 | |
7619e7c7 AM |
1002 | /* Like GOT_DTPREL16, but no overflow. */ |
1003 | HOWTO (R_PPC_GOT_DTPREL16_LO, | |
1004 | 0, /* rightshift */ | |
1005 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1006 | 16, /* bitsize */ | |
1007 | FALSE, /* pc_relative */ | |
1008 | 0, /* bitpos */ | |
1009 | complain_overflow_dont, /* complain_on_overflow */ | |
1010 | ppc_elf_unhandled_reloc, /* special_function */ | |
1011 | "R_PPC_GOT_DTPREL16_LO", /* name */ | |
1012 | FALSE, /* partial_inplace */ | |
1013 | 0, /* src_mask */ | |
1014 | 0xffff, /* dst_mask */ | |
1015 | FALSE), /* pcrel_offset */ | |
252b5132 | 1016 | |
7619e7c7 AM |
1017 | /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */ |
1018 | HOWTO (R_PPC_GOT_DTPREL16_HI, | |
1019 | 16, /* rightshift */ | |
1020 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1021 | 16, /* bitsize */ | |
1022 | FALSE, /* pc_relative */ | |
1023 | 0, /* bitpos */ | |
1024 | complain_overflow_dont, /* complain_on_overflow */ | |
1025 | ppc_elf_unhandled_reloc, /* special_function */ | |
1026 | "R_PPC_GOT_DTPREL16_HI", /* name */ | |
1027 | FALSE, /* partial_inplace */ | |
1028 | 0, /* src_mask */ | |
1029 | 0xffff, /* dst_mask */ | |
1030 | FALSE), /* pcrel_offset */ | |
252b5132 | 1031 | |
7619e7c7 AM |
1032 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1033 | HOWTO (R_PPC_GOT_DTPREL16_HA, | |
1034 | 16, /* rightshift */ | |
1035 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1036 | 16, /* bitsize */ | |
1037 | FALSE, /* pc_relative */ | |
1038 | 0, /* bitpos */ | |
1039 | complain_overflow_dont, /* complain_on_overflow */ | |
1040 | ppc_elf_unhandled_reloc, /* special_function */ | |
1041 | "R_PPC_GOT_DTPREL16_HA", /* name */ | |
1042 | FALSE, /* partial_inplace */ | |
1043 | 0, /* src_mask */ | |
1044 | 0xffff, /* dst_mask */ | |
1045 | FALSE), /* pcrel_offset */ | |
c3668558 | 1046 | |
7619e7c7 AM |
1047 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the |
1048 | offset to the entry. */ | |
1049 | HOWTO (R_PPC_GOT_TPREL16, | |
1050 | 0, /* rightshift */ | |
1051 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1052 | 16, /* bitsize */ | |
1053 | FALSE, /* pc_relative */ | |
1054 | 0, /* bitpos */ | |
1055 | complain_overflow_signed, /* complain_on_overflow */ | |
1056 | ppc_elf_unhandled_reloc, /* special_function */ | |
1057 | "R_PPC_GOT_TPREL16", /* name */ | |
1058 | FALSE, /* partial_inplace */ | |
1059 | 0, /* src_mask */ | |
1060 | 0xffff, /* dst_mask */ | |
1061 | FALSE), /* pcrel_offset */ | |
1062 | ||
1063 | /* Like GOT_TPREL16, but no overflow. */ | |
1064 | HOWTO (R_PPC_GOT_TPREL16_LO, | |
1065 | 0, /* rightshift */ | |
1066 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1067 | 16, /* bitsize */ | |
1068 | FALSE, /* pc_relative */ | |
1069 | 0, /* bitpos */ | |
1070 | complain_overflow_dont, /* complain_on_overflow */ | |
1071 | ppc_elf_unhandled_reloc, /* special_function */ | |
1072 | "R_PPC_GOT_TPREL16_LO", /* name */ | |
1073 | FALSE, /* partial_inplace */ | |
1074 | 0, /* src_mask */ | |
1075 | 0xffff, /* dst_mask */ | |
1076 | FALSE), /* pcrel_offset */ | |
1077 | ||
1078 | /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */ | |
1079 | HOWTO (R_PPC_GOT_TPREL16_HI, | |
1080 | 16, /* rightshift */ | |
1081 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1082 | 16, /* bitsize */ | |
1083 | FALSE, /* pc_relative */ | |
1084 | 0, /* bitpos */ | |
1085 | complain_overflow_dont, /* complain_on_overflow */ | |
1086 | ppc_elf_unhandled_reloc, /* special_function */ | |
1087 | "R_PPC_GOT_TPREL16_HI", /* name */ | |
1088 | FALSE, /* partial_inplace */ | |
1089 | 0, /* src_mask */ | |
1090 | 0xffff, /* dst_mask */ | |
1091 | FALSE), /* pcrel_offset */ | |
1092 | ||
1093 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ | |
1094 | HOWTO (R_PPC_GOT_TPREL16_HA, | |
1095 | 16, /* rightshift */ | |
1096 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1097 | 16, /* bitsize */ | |
1098 | FALSE, /* pc_relative */ | |
1099 | 0, /* bitpos */ | |
1100 | complain_overflow_dont, /* complain_on_overflow */ | |
1101 | ppc_elf_unhandled_reloc, /* special_function */ | |
1102 | "R_PPC_GOT_TPREL16_HA", /* name */ | |
1103 | FALSE, /* partial_inplace */ | |
1104 | 0, /* src_mask */ | |
1105 | 0xffff, /* dst_mask */ | |
1106 | FALSE), /* pcrel_offset */ | |
1107 | ||
1108 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
1109 | in the SVR4 ELF ABI. */ | |
1110 | ||
1111 | /* 32 bit value resulting from the addend minus the symbol. */ | |
1112 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
1113 | 0, /* rightshift */ | |
1114 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1115 | 32, /* bitsize */ | |
1116 | FALSE, /* pc_relative */ | |
1117 | 0, /* bitpos */ | |
1118 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1119 | bfd_elf_generic_reloc, /* special_function */ | |
1120 | "R_PPC_EMB_NADDR32", /* name */ | |
1121 | FALSE, /* partial_inplace */ | |
1122 | 0, /* src_mask */ | |
1123 | 0xffffffff, /* dst_mask */ | |
1124 | FALSE), /* pcrel_offset */ | |
1125 | ||
1126 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1127 | HOWTO (R_PPC_EMB_NADDR16, /* type */ | |
1128 | 0, /* rightshift */ | |
1129 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1130 | 16, /* bitsize */ | |
1131 | FALSE, /* pc_relative */ | |
1132 | 0, /* bitpos */ | |
1133 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1134 | bfd_elf_generic_reloc, /* special_function */ | |
1135 | "R_PPC_EMB_NADDR16", /* name */ | |
1136 | FALSE, /* partial_inplace */ | |
1137 | 0, /* src_mask */ | |
1138 | 0xffff, /* dst_mask */ | |
1139 | FALSE), /* pcrel_offset */ | |
1140 | ||
1141 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1142 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
1143 | 0, /* rightshift */ | |
1144 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1145 | 16, /* bitsize */ | |
1146 | FALSE, /* pc_relative */ | |
1147 | 0, /* bitpos */ | |
1148 | complain_overflow_dont,/* complain_on_overflow */ | |
1149 | bfd_elf_generic_reloc, /* special_function */ | |
1150 | "R_PPC_EMB_ADDR16_LO", /* name */ | |
1151 | FALSE, /* partial_inplace */ | |
1152 | 0, /* src_mask */ | |
1153 | 0xffff, /* dst_mask */ | |
1154 | FALSE), /* pcrel_offset */ | |
1155 | ||
1156 | /* The high order 16 bits of the addend minus the symbol. */ | |
1157 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
1158 | 16, /* rightshift */ | |
1159 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1160 | 16, /* bitsize */ | |
1161 | FALSE, /* pc_relative */ | |
1162 | 0, /* bitpos */ | |
1163 | complain_overflow_dont, /* complain_on_overflow */ | |
1164 | bfd_elf_generic_reloc, /* special_function */ | |
1165 | "R_PPC_EMB_NADDR16_HI", /* name */ | |
1166 | FALSE, /* partial_inplace */ | |
1167 | 0, /* src_mask */ | |
1168 | 0xffff, /* dst_mask */ | |
1169 | FALSE), /* pcrel_offset */ | |
1170 | ||
1171 | /* The high order 16 bits of the result of the addend minus the address, | |
1172 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
1173 | is negative. */ | |
1174 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ | |
1175 | 16, /* rightshift */ | |
1176 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1177 | 16, /* bitsize */ | |
1178 | FALSE, /* pc_relative */ | |
1179 | 0, /* bitpos */ | |
1180 | complain_overflow_dont, /* complain_on_overflow */ | |
25dbc73a AM |
1181 | ppc_elf_addr16_ha_reloc, /* special_function */ |
1182 | "R_PPC_EMB_NADDR16_HA", /* name */ | |
1183 | FALSE, /* partial_inplace */ | |
1184 | 0, /* src_mask */ | |
1185 | 0xffff, /* dst_mask */ | |
1186 | FALSE), /* pcrel_offset */ | |
1187 | ||
1188 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1189 | address in the .sdata section, and returning the offset from | |
1190 | _SDA_BASE_ for that relocation. */ | |
1191 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
1192 | 0, /* rightshift */ | |
1193 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1194 | 16, /* bitsize */ | |
1195 | FALSE, /* pc_relative */ | |
1196 | 0, /* bitpos */ | |
1197 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1198 | bfd_elf_generic_reloc, /* special_function */ | |
1199 | "R_PPC_EMB_SDAI16", /* name */ | |
1200 | FALSE, /* partial_inplace */ | |
1201 | 0, /* src_mask */ | |
1202 | 0xffff, /* dst_mask */ | |
1203 | FALSE), /* pcrel_offset */ | |
1204 | ||
1205 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1206 | address in the .sdata2 section, and returning the offset from | |
1207 | _SDA2_BASE_ for that relocation. */ | |
1208 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
1209 | 0, /* rightshift */ | |
1210 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1211 | 16, /* bitsize */ | |
1212 | FALSE, /* pc_relative */ | |
1213 | 0, /* bitpos */ | |
1214 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1215 | bfd_elf_generic_reloc, /* special_function */ | |
1216 | "R_PPC_EMB_SDA2I16", /* name */ | |
1217 | FALSE, /* partial_inplace */ | |
1218 | 0, /* src_mask */ | |
1219 | 0xffff, /* dst_mask */ | |
1220 | FALSE), /* pcrel_offset */ | |
1221 | ||
1222 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
1223 | small data items. */ | |
1224 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
1225 | 0, /* rightshift */ | |
1226 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1227 | 16, /* bitsize */ | |
1228 | FALSE, /* pc_relative */ | |
1229 | 0, /* bitpos */ | |
1230 | complain_overflow_signed, /* complain_on_overflow */ | |
1231 | bfd_elf_generic_reloc, /* special_function */ | |
1232 | "R_PPC_EMB_SDA2REL", /* name */ | |
1233 | FALSE, /* partial_inplace */ | |
1234 | 0, /* src_mask */ | |
1235 | 0xffff, /* dst_mask */ | |
1236 | FALSE), /* pcrel_offset */ | |
1237 | ||
1238 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
1239 | signed offset from the appropriate base, and filling in the register | |
1240 | field with the appropriate register (0, 2, or 13). */ | |
1241 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
1242 | 0, /* rightshift */ | |
1243 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1244 | 16, /* bitsize */ | |
1245 | FALSE, /* pc_relative */ | |
1246 | 0, /* bitpos */ | |
1247 | complain_overflow_signed, /* complain_on_overflow */ | |
1248 | bfd_elf_generic_reloc, /* special_function */ | |
1249 | "R_PPC_EMB_SDA21", /* name */ | |
1250 | FALSE, /* partial_inplace */ | |
1251 | 0, /* src_mask */ | |
1252 | 0xffff, /* dst_mask */ | |
1253 | FALSE), /* pcrel_offset */ | |
1254 | ||
1255 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
1256 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
1257 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
1258 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
1259 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
1260 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
1261 | ||
1262 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
1263 | in the 16 bit signed offset from the appropriate base, and filling in the | |
1264 | register field with the appropriate register (0, 2, or 13). */ | |
1265 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
1266 | 0, /* rightshift */ | |
1267 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1268 | 16, /* bitsize */ | |
1269 | TRUE, /* pc_relative */ | |
1270 | 0, /* bitpos */ | |
1271 | complain_overflow_signed, /* complain_on_overflow */ | |
1272 | bfd_elf_generic_reloc, /* special_function */ | |
1273 | "R_PPC_EMB_RELSDA", /* name */ | |
1274 | FALSE, /* partial_inplace */ | |
1275 | 0, /* src_mask */ | |
1276 | 0xffff, /* dst_mask */ | |
1277 | FALSE), /* pcrel_offset */ | |
1278 | ||
d7128ce4 AM |
1279 | /* A 16 bit relative relocation. */ |
1280 | HOWTO (R_PPC_REL16, /* type */ | |
1281 | 0, /* rightshift */ | |
1282 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1283 | 16, /* bitsize */ | |
1284 | TRUE, /* pc_relative */ | |
1285 | 0, /* bitpos */ | |
1286 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1287 | bfd_elf_generic_reloc, /* special_function */ | |
1288 | "R_PPC_REL16", /* name */ | |
1289 | FALSE, /* partial_inplace */ | |
1290 | 0, /* src_mask */ | |
1291 | 0xffff, /* dst_mask */ | |
1292 | TRUE), /* pcrel_offset */ | |
1293 | ||
1294 | /* A 16 bit relative relocation without overflow. */ | |
1295 | HOWTO (R_PPC_REL16_LO, /* type */ | |
1296 | 0, /* rightshift */ | |
1297 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1298 | 16, /* bitsize */ | |
1299 | TRUE, /* pc_relative */ | |
1300 | 0, /* bitpos */ | |
1301 | complain_overflow_dont,/* complain_on_overflow */ | |
1302 | bfd_elf_generic_reloc, /* special_function */ | |
1303 | "R_PPC_REL16_LO", /* name */ | |
1304 | FALSE, /* partial_inplace */ | |
1305 | 0, /* src_mask */ | |
1306 | 0xffff, /* dst_mask */ | |
1307 | TRUE), /* pcrel_offset */ | |
1308 | ||
1309 | /* The high order 16 bits of a relative address. */ | |
1310 | HOWTO (R_PPC_REL16_HI, /* type */ | |
1311 | 16, /* rightshift */ | |
1312 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1313 | 16, /* bitsize */ | |
1314 | TRUE, /* pc_relative */ | |
1315 | 0, /* bitpos */ | |
1316 | complain_overflow_dont, /* complain_on_overflow */ | |
1317 | bfd_elf_generic_reloc, /* special_function */ | |
1318 | "R_PPC_REL16_HI", /* name */ | |
1319 | FALSE, /* partial_inplace */ | |
1320 | 0, /* src_mask */ | |
1321 | 0xffff, /* dst_mask */ | |
1322 | TRUE), /* pcrel_offset */ | |
1323 | ||
1324 | /* The high order 16 bits of a relative address, plus 1 if the contents of | |
1325 | the low 16 bits, treated as a signed number, is negative. */ | |
1326 | HOWTO (R_PPC_REL16_HA, /* type */ | |
1327 | 16, /* rightshift */ | |
1328 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1329 | 16, /* bitsize */ | |
1330 | TRUE, /* pc_relative */ | |
1331 | 0, /* bitpos */ | |
1332 | complain_overflow_dont, /* complain_on_overflow */ | |
1333 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1334 | "R_PPC_REL16_HA", /* name */ | |
1335 | FALSE, /* partial_inplace */ | |
1336 | 0, /* src_mask */ | |
1337 | 0xffff, /* dst_mask */ | |
1338 | TRUE), /* pcrel_offset */ | |
1339 | ||
25dbc73a AM |
1340 | /* GNU extension to record C++ vtable hierarchy. */ |
1341 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ | |
1342 | 0, /* rightshift */ | |
1343 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1344 | 0, /* bitsize */ | |
1345 | FALSE, /* pc_relative */ | |
1346 | 0, /* bitpos */ | |
1347 | complain_overflow_dont, /* complain_on_overflow */ | |
1348 | NULL, /* special_function */ | |
1349 | "R_PPC_GNU_VTINHERIT", /* name */ | |
1350 | FALSE, /* partial_inplace */ | |
1351 | 0, /* src_mask */ | |
1352 | 0, /* dst_mask */ | |
1353 | FALSE), /* pcrel_offset */ | |
1354 | ||
1355 | /* GNU extension to record C++ vtable member usage. */ | |
1356 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ | |
1357 | 0, /* rightshift */ | |
1358 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1359 | 0, /* bitsize */ | |
1360 | FALSE, /* pc_relative */ | |
1361 | 0, /* bitpos */ | |
1362 | complain_overflow_dont, /* complain_on_overflow */ | |
1363 | NULL, /* special_function */ | |
1364 | "R_PPC_GNU_VTENTRY", /* name */ | |
7619e7c7 AM |
1365 | FALSE, /* partial_inplace */ |
1366 | 0, /* src_mask */ | |
25dbc73a | 1367 | 0, /* dst_mask */ |
7619e7c7 AM |
1368 | FALSE), /* pcrel_offset */ |
1369 | ||
25dbc73a AM |
1370 | /* Phony reloc to handle AIX style TOC entries. */ |
1371 | HOWTO (R_PPC_TOC16, /* type */ | |
7619e7c7 AM |
1372 | 0, /* rightshift */ |
1373 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1374 | 16, /* bitsize */ | |
1375 | FALSE, /* pc_relative */ | |
1376 | 0, /* bitpos */ | |
25dbc73a | 1377 | complain_overflow_signed, /* complain_on_overflow */ |
7619e7c7 | 1378 | bfd_elf_generic_reloc, /* special_function */ |
25dbc73a | 1379 | "R_PPC_TOC16", /* name */ |
7619e7c7 AM |
1380 | FALSE, /* partial_inplace */ |
1381 | 0, /* src_mask */ | |
1382 | 0xffff, /* dst_mask */ | |
1383 | FALSE), /* pcrel_offset */ | |
25dbc73a AM |
1384 | }; |
1385 | \f | |
1386 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
1387 | ||
1388 | static void | |
1389 | ppc_elf_howto_init (void) | |
1390 | { | |
1391 | unsigned int i, type; | |
1392 | ||
1393 | for (i = 0; | |
1394 | i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); | |
1395 | i++) | |
1396 | { | |
1397 | type = ppc_elf_howto_raw[i].type; | |
1398 | if (type >= (sizeof (ppc_elf_howto_table) | |
1399 | / sizeof (ppc_elf_howto_table[0]))) | |
1400 | abort (); | |
1401 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; | |
1402 | } | |
1403 | } | |
1404 | ||
1405 | static reloc_howto_type * | |
1406 | ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1407 | bfd_reloc_code_real_type code) | |
1408 | { | |
1409 | enum elf_ppc_reloc_type r; | |
1410 | ||
1411 | /* Initialize howto table if not already done. */ | |
1412 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1413 | ppc_elf_howto_init (); | |
1414 | ||
1415 | switch (code) | |
1416 | { | |
1417 | default: | |
1418 | return NULL; | |
1419 | ||
1420 | case BFD_RELOC_NONE: r = R_PPC_NONE; break; | |
1421 | case BFD_RELOC_32: r = R_PPC_ADDR32; break; | |
1422 | case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break; | |
1423 | case BFD_RELOC_16: r = R_PPC_ADDR16; break; | |
1424 | case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break; | |
1425 | case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break; | |
1426 | case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break; | |
1427 | case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break; | |
1428 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break; | |
1429 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break; | |
1430 | case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break; | |
1431 | case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break; | |
1432 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break; | |
1433 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break; | |
1434 | case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break; | |
1435 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break; | |
1436 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break; | |
1437 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break; | |
1438 | case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break; | |
1439 | case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break; | |
1440 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break; | |
1441 | case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break; | |
1442 | case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break; | |
1443 | case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break; | |
1444 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break; | |
1445 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break; | |
1446 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break; | |
1447 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break; | |
1448 | case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break; | |
1449 | case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break; | |
1450 | case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break; | |
1451 | case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break; | |
1452 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break; | |
1453 | case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break; | |
1454 | case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break; | |
1455 | case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break; | |
1456 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break; | |
1457 | case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break; | |
1458 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break; | |
1459 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break; | |
1460 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break; | |
1461 | case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break; | |
1462 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break; | |
1463 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break; | |
1464 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break; | |
1465 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break; | |
1466 | case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break; | |
1467 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break; | |
1468 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break; | |
1469 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break; | |
1470 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break; | |
1471 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break; | |
1472 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break; | |
1473 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break; | |
1474 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break; | |
1475 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break; | |
1476 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break; | |
1477 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break; | |
1478 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break; | |
1479 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break; | |
1480 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break; | |
1481 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break; | |
1482 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break; | |
1483 | case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break; | |
1484 | case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break; | |
1485 | case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break; | |
1486 | case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break; | |
1487 | case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break; | |
1488 | case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break; | |
1489 | case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break; | |
1490 | case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break; | |
1491 | case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break; | |
1492 | case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break; | |
1493 | case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break; | |
1494 | case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break; | |
1495 | case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break; | |
1496 | case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break; | |
1497 | case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break; | |
1498 | case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break; | |
d7128ce4 AM |
1499 | case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break; |
1500 | case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break; | |
1501 | case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break; | |
1502 | case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break; | |
25dbc73a AM |
1503 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break; |
1504 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break; | |
1505 | } | |
1506 | ||
1507 | return ppc_elf_howto_table[r]; | |
1508 | }; | |
1509 | ||
1510 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
1511 | ||
1512 | static void | |
1513 | ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, | |
1514 | arelent *cache_ptr, | |
1515 | Elf_Internal_Rela *dst) | |
1516 | { | |
1517 | /* Initialize howto table if not already done. */ | |
1518 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
1519 | ppc_elf_howto_init (); | |
1520 | ||
1521 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); | |
1522 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; | |
1523 | } | |
1524 | ||
d7128ce4 | 1525 | /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */ |
25dbc73a AM |
1526 | |
1527 | static bfd_reloc_status_type | |
1528 | ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED, | |
1529 | arelent *reloc_entry, | |
1530 | asymbol *symbol, | |
1531 | void *data ATTRIBUTE_UNUSED, | |
1532 | asection *input_section, | |
1533 | bfd *output_bfd, | |
1534 | char **error_message ATTRIBUTE_UNUSED) | |
1535 | { | |
1536 | bfd_vma relocation; | |
1537 | ||
1538 | if (output_bfd != NULL) | |
1539 | { | |
1540 | reloc_entry->address += input_section->output_offset; | |
1541 | return bfd_reloc_ok; | |
1542 | } | |
1543 | ||
1544 | if (reloc_entry->address > bfd_get_section_limit (abfd, input_section)) | |
1545 | return bfd_reloc_outofrange; | |
1546 | ||
1547 | if (bfd_is_com_section (symbol->section)) | |
1548 | relocation = 0; | |
1549 | else | |
1550 | relocation = symbol->value; | |
1551 | ||
1552 | relocation += symbol->section->output_section->vma; | |
1553 | relocation += symbol->section->output_offset; | |
1554 | relocation += reloc_entry->addend; | |
d7128ce4 AM |
1555 | if (reloc_entry->howto->pc_relative) |
1556 | relocation -= reloc_entry->address; | |
25dbc73a AM |
1557 | |
1558 | reloc_entry->addend += (relocation & 0x8000) << 1; | |
1559 | ||
1560 | return bfd_reloc_continue; | |
1561 | } | |
1562 | ||
1563 | static bfd_reloc_status_type | |
1564 | ppc_elf_unhandled_reloc (bfd *abfd, | |
1565 | arelent *reloc_entry, | |
1566 | asymbol *symbol, | |
1567 | void *data, | |
1568 | asection *input_section, | |
1569 | bfd *output_bfd, | |
1570 | char **error_message) | |
1571 | { | |
1572 | /* If this is a relocatable link (output_bfd test tells us), just | |
1573 | call the generic function. Any adjustment will be done at final | |
1574 | link time. */ | |
1575 | if (output_bfd != NULL) | |
1576 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
1577 | input_section, output_bfd, error_message); | |
1578 | ||
1579 | if (error_message != NULL) | |
1580 | { | |
1581 | static char buf[60]; | |
1582 | sprintf (buf, _("generic linker can't handle %s"), | |
1583 | reloc_entry->howto->name); | |
1584 | *error_message = buf; | |
1585 | } | |
1586 | return bfd_reloc_dangerous; | |
1587 | } | |
1588 | \f | |
1589 | /* Sections created by the linker. */ | |
1590 | ||
1591 | typedef struct elf_linker_section | |
1592 | { | |
c9a2f333 | 1593 | /* Pointer to the bfd section. */ |
25dbc73a | 1594 | asection *section; |
c9a2f333 AM |
1595 | /* Section name. */ |
1596 | const char *name; | |
1597 | /* Associated bss section name. */ | |
1598 | const char *bss_name; | |
1599 | /* Associated symbol name. */ | |
1600 | const char *sym_name; | |
1601 | /* Value of symbol. */ | |
1602 | bfd_vma sym_val; | |
25dbc73a AM |
1603 | } elf_linker_section_t; |
1604 | ||
1605 | /* Linked list of allocated pointer entries. This hangs off of the | |
1606 | symbol lists, and provides allows us to return different pointers, | |
1607 | based on different addend's. */ | |
1608 | ||
1609 | typedef struct elf_linker_section_pointers | |
1610 | { | |
1611 | /* next allocated pointer for this symbol */ | |
1612 | struct elf_linker_section_pointers *next; | |
1613 | /* offset of pointer from beginning of section */ | |
1614 | bfd_vma offset; | |
1615 | /* addend used */ | |
1616 | bfd_vma addend; | |
1617 | /* which linker section this is */ | |
1618 | elf_linker_section_t *lsect; | |
25dbc73a AM |
1619 | } elf_linker_section_pointers_t; |
1620 | ||
1621 | struct ppc_elf_obj_tdata | |
1622 | { | |
1623 | struct elf_obj_tdata elf; | |
1624 | ||
1625 | /* A mapping from local symbols to offsets into the various linker | |
1626 | sections added. This is index by the symbol index. */ | |
1627 | elf_linker_section_pointers_t **linker_section_pointers; | |
1628 | }; | |
1629 | ||
1630 | #define ppc_elf_tdata(bfd) \ | |
1631 | ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any) | |
7619e7c7 | 1632 | |
25dbc73a AM |
1633 | #define elf_local_ptr_offsets(bfd) \ |
1634 | (ppc_elf_tdata (bfd)->linker_section_pointers) | |
7619e7c7 | 1635 | |
25dbc73a | 1636 | /* Override the generic function because we store some extras. */ |
7619e7c7 | 1637 | |
25dbc73a AM |
1638 | static bfd_boolean |
1639 | ppc_elf_mkobject (bfd *abfd) | |
1640 | { | |
1641 | bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata); | |
1642 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
1643 | if (abfd->tdata.any == NULL) | |
1644 | return FALSE; | |
1645 | return TRUE; | |
1646 | } | |
7619e7c7 | 1647 | |
25dbc73a AM |
1648 | /* Fix bad default arch selected for a 32 bit input bfd when the |
1649 | default is 64 bit. */ | |
7619e7c7 | 1650 | |
25dbc73a AM |
1651 | static bfd_boolean |
1652 | ppc_elf_object_p (bfd *abfd) | |
1653 | { | |
1654 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64) | |
1655 | { | |
1656 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
7619e7c7 | 1657 | |
25dbc73a AM |
1658 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) |
1659 | { | |
1660 | /* Relies on arch after 64 bit default being 32 bit default. */ | |
1661 | abfd->arch_info = abfd->arch_info->next; | |
1662 | BFD_ASSERT (abfd->arch_info->bits_per_word == 32); | |
1663 | } | |
1664 | } | |
1665 | return TRUE; | |
1666 | } | |
7619e7c7 | 1667 | |
25dbc73a | 1668 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
7619e7c7 | 1669 | |
25dbc73a AM |
1670 | static bfd_boolean |
1671 | ppc_elf_set_private_flags (bfd *abfd, flagword flags) | |
1672 | { | |
1673 | BFD_ASSERT (!elf_flags_init (abfd) | |
1674 | || elf_elfheader (abfd)->e_flags == flags); | |
7619e7c7 | 1675 | |
25dbc73a AM |
1676 | elf_elfheader (abfd)->e_flags = flags; |
1677 | elf_flags_init (abfd) = TRUE; | |
1678 | return TRUE; | |
1679 | } | |
1680 | ||
25dbc73a | 1681 | /* Support for core dump NOTE sections. */ |
deaaf2f3 | 1682 | |
b34976b6 | 1683 | static bfd_boolean |
25dbc73a | 1684 | ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
252b5132 | 1685 | { |
25dbc73a AM |
1686 | int offset; |
1687 | unsigned int size; | |
252b5132 | 1688 | |
25dbc73a AM |
1689 | switch (note->descsz) |
1690 | { | |
1691 | default: | |
1692 | return FALSE; | |
252b5132 | 1693 | |
25dbc73a AM |
1694 | case 268: /* Linux/PPC. */ |
1695 | /* pr_cursig */ | |
1696 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
deaaf2f3 | 1697 | |
25dbc73a AM |
1698 | /* pr_pid */ |
1699 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
9abc968f | 1700 | |
25dbc73a AM |
1701 | /* pr_reg */ |
1702 | offset = 72; | |
1703 | size = 192; | |
deaaf2f3 | 1704 | |
25dbc73a AM |
1705 | break; |
1706 | } | |
deaaf2f3 | 1707 | |
25dbc73a AM |
1708 | /* Make a ".reg/999" section. */ |
1709 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1710 | size, note->descpos + offset); | |
1711 | } | |
252b5132 | 1712 | |
25dbc73a AM |
1713 | static bfd_boolean |
1714 | ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
1715 | { | |
1716 | switch (note->descsz) | |
deaaf2f3 | 1717 | { |
25dbc73a AM |
1718 | default: |
1719 | return FALSE; | |
deaaf2f3 | 1720 | |
25dbc73a AM |
1721 | case 128: /* Linux/PPC elf_prpsinfo. */ |
1722 | elf_tdata (abfd)->core_program | |
1723 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); | |
1724 | elf_tdata (abfd)->core_command | |
1725 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); | |
1726 | } | |
9abc968f | 1727 | |
25dbc73a AM |
1728 | /* Note that for some reason, a spurious space is tacked |
1729 | onto the end of the args in some (at least one anyway) | |
1730 | implementations, so strip it off if it exists. */ | |
70bccea4 | 1731 | |
25dbc73a AM |
1732 | { |
1733 | char *command = elf_tdata (abfd)->core_command; | |
1734 | int n = strlen (command); | |
70bccea4 | 1735 | |
25dbc73a AM |
1736 | if (0 < n && command[n - 1] == ' ') |
1737 | command[n - 1] = '\0'; | |
1738 | } | |
deaaf2f3 | 1739 | |
25dbc73a AM |
1740 | return TRUE; |
1741 | } | |
deaaf2f3 | 1742 | |
25dbc73a AM |
1743 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
1744 | or (bfd_vma) -1 if it should not be included. */ | |
deaaf2f3 | 1745 | |
25dbc73a AM |
1746 | static bfd_vma |
1747 | ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, | |
1748 | const asection *plt ATTRIBUTE_UNUSED, | |
1749 | const arelent *rel) | |
1750 | { | |
1751 | return rel->address; | |
1752 | } | |
deaaf2f3 | 1753 | |
25dbc73a | 1754 | /* Handle a PowerPC specific section when reading an object file. This |
6dc132d9 L |
1755 | is called when bfd_section_from_shdr finds a section with an unknown |
1756 | type. */ | |
deaaf2f3 | 1757 | |
25dbc73a | 1758 | static bfd_boolean |
6dc132d9 L |
1759 | ppc_elf_section_from_shdr (bfd *abfd, |
1760 | Elf_Internal_Shdr *hdr, | |
1761 | const char *name, | |
1762 | int shindex) | |
25dbc73a AM |
1763 | { |
1764 | asection *newsect; | |
1765 | flagword flags; | |
d1c6de6f | 1766 | |
6dc132d9 | 1767 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
25dbc73a | 1768 | return FALSE; |
deaaf2f3 | 1769 | |
25dbc73a AM |
1770 | newsect = hdr->bfd_section; |
1771 | flags = bfd_get_section_flags (abfd, newsect); | |
1772 | if (hdr->sh_flags & SHF_EXCLUDE) | |
1773 | flags |= SEC_EXCLUDE; | |
9abc968f | 1774 | |
25dbc73a AM |
1775 | if (hdr->sh_type == SHT_ORDERED) |
1776 | flags |= SEC_SORT_ENTRIES; | |
d1c6de6f | 1777 | |
25dbc73a AM |
1778 | bfd_set_section_flags (abfd, newsect, flags); |
1779 | return TRUE; | |
1780 | } | |
1781 | ||
1782 | /* Set up any other section flags and such that may be necessary. */ | |
1783 | ||
1784 | static bfd_boolean | |
1785 | ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, | |
1786 | Elf_Internal_Shdr *shdr, | |
1787 | asection *asect) | |
1788 | { | |
1789 | if ((asect->flags & SEC_EXCLUDE) != 0) | |
1790 | shdr->sh_flags |= SHF_EXCLUDE; | |
1791 | ||
1792 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) | |
1793 | shdr->sh_type = SHT_ORDERED; | |
1794 | ||
1795 | return TRUE; | |
1796 | } | |
1797 | ||
1798 | /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we | |
1799 | need to bump up the number of section headers. */ | |
1800 | ||
1801 | static int | |
1802 | ppc_elf_additional_program_headers (bfd *abfd) | |
1803 | { | |
1804 | asection *s; | |
1805 | int ret = 0; | |
d1c6de6f | 1806 | |
25dbc73a AM |
1807 | s = bfd_get_section_by_name (abfd, ".sbss2"); |
1808 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
1809 | ++ret; | |
d1c6de6f | 1810 | |
25dbc73a AM |
1811 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); |
1812 | if (s != NULL && (s->flags & SEC_ALLOC) != 0) | |
1813 | ++ret; | |
deaaf2f3 | 1814 | |
25dbc73a AM |
1815 | return ret; |
1816 | } | |
deaaf2f3 | 1817 | |
25dbc73a AM |
1818 | /* Add extra PPC sections -- Note, for now, make .sbss2 and |
1819 | .PPC.EMB.sbss0 a normal section, and not a bss section so | |
1820 | that the linker doesn't crater when trying to make more than | |
1821 | 2 sections. */ | |
e656e369 | 1822 | |
7f4d3958 L |
1823 | static struct bfd_elf_special_section const |
1824 | ppc_special_sections_p[] = | |
1825 | { | |
1826 | { ".plt", 4, 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR }, | |
1827 | { NULL, 0, 0, 0, 0 } | |
1828 | }; | |
1829 | ||
1830 | static struct bfd_elf_special_section const | |
1831 | ppc_special_sections_s[] = | |
25dbc73a | 1832 | { |
25dbc73a AM |
1833 | { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
1834 | { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
1835 | { ".sdata2", 7, -2, SHT_PROGBITS, SHF_ALLOC }, | |
1836 | { ".sbss2", 6, -2, SHT_PROGBITS, SHF_ALLOC }, | |
7f4d3958 L |
1837 | { NULL, 0, 0, 0, 0 } |
1838 | }; | |
1839 | ||
1840 | static struct bfd_elf_special_section const | |
1841 | ppc_special_sections_t[] = | |
1842 | { | |
1843 | { ".tags", 5, 0, SHT_ORDERED, SHF_ALLOC }, | |
1844 | { NULL, 0, 0, 0, 0 } | |
1845 | }; | |
1846 | ||
1847 | static struct bfd_elf_special_section const | |
1848 | ppc_special_sections_other[]= | |
1849 | { | |
25dbc73a AM |
1850 | { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE, 0 }, |
1851 | { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS, SHF_ALLOC }, | |
1852 | { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS, SHF_ALLOC }, | |
7f4d3958 L |
1853 | { NULL, 0, 0, 0, 0 } |
1854 | }; | |
1855 | ||
1856 | static struct bfd_elf_special_section const * | |
1857 | ppc_elf_special_sections[27]= | |
1858 | { | |
1859 | NULL, /* 'a' */ | |
1860 | NULL, /* 'b' */ | |
1861 | NULL, /* 'c' */ | |
1862 | NULL, /* 'd' */ | |
1863 | NULL, /* 'e' */ | |
1864 | NULL, /* 'f' */ | |
1865 | NULL, /* 'g' */ | |
1866 | NULL, /* 'h' */ | |
1867 | NULL, /* 'i' */ | |
1868 | NULL, /* 'j' */ | |
1869 | NULL, /* 'k' */ | |
1870 | NULL, /* 'l' */ | |
1871 | NULL, /* 'm' */ | |
1872 | NULL, /* 'n' */ | |
1873 | NULL, /* 'o' */ | |
1874 | ppc_special_sections_p, /* 'p' */ | |
1875 | NULL, /* 'q' */ | |
1876 | NULL, /* 'r' */ | |
1877 | ppc_special_sections_s, /* 's' */ | |
1878 | ppc_special_sections_t, /* 's' */ | |
1879 | NULL, /* 'u' */ | |
1880 | NULL, /* 'v' */ | |
1881 | NULL, /* 'w' */ | |
1882 | NULL, /* 'x' */ | |
1883 | NULL, /* 'y' */ | |
1884 | NULL, /* 'z' */ | |
1885 | ppc_special_sections_other, /* other */ | |
25dbc73a AM |
1886 | }; |
1887 | \f | |
1888 | /* Very simple linked list structure for recording apuinfo values. */ | |
1889 | typedef struct apuinfo_list | |
1890 | { | |
1891 | struct apuinfo_list *next; | |
1892 | unsigned long value; | |
1893 | } | |
1894 | apuinfo_list; | |
e656e369 | 1895 | |
25dbc73a | 1896 | static apuinfo_list *head; |
deaaf2f3 | 1897 | |
deaaf2f3 | 1898 | |
25dbc73a AM |
1899 | static void |
1900 | apuinfo_list_init (void) | |
1901 | { | |
1902 | head = NULL; | |
1903 | } | |
9abc968f | 1904 | |
25dbc73a AM |
1905 | static void |
1906 | apuinfo_list_add (unsigned long value) | |
1907 | { | |
1908 | apuinfo_list *entry = head; | |
deaaf2f3 | 1909 | |
25dbc73a AM |
1910 | while (entry != NULL) |
1911 | { | |
1912 | if (entry->value == value) | |
1913 | return; | |
1914 | entry = entry->next; | |
1915 | } | |
b4a38de6 | 1916 | |
25dbc73a AM |
1917 | entry = bfd_malloc (sizeof (* entry)); |
1918 | if (entry == NULL) | |
1919 | return; | |
e656e369 | 1920 | |
25dbc73a AM |
1921 | entry->value = value; |
1922 | entry->next = head; | |
1923 | head = entry; | |
1924 | } | |
9abc968f | 1925 | |
25dbc73a AM |
1926 | static unsigned |
1927 | apuinfo_list_length (void) | |
1928 | { | |
1929 | apuinfo_list *entry; | |
1930 | unsigned long count; | |
9abc968f | 1931 | |
25dbc73a AM |
1932 | for (entry = head, count = 0; |
1933 | entry; | |
1934 | entry = entry->next) | |
1935 | ++ count; | |
e656e369 | 1936 | |
25dbc73a AM |
1937 | return count; |
1938 | } | |
eea6121a | 1939 | |
25dbc73a AM |
1940 | static inline unsigned long |
1941 | apuinfo_list_element (unsigned long number) | |
1942 | { | |
1943 | apuinfo_list * entry; | |
e656e369 | 1944 | |
25dbc73a AM |
1945 | for (entry = head; |
1946 | entry && number --; | |
1947 | entry = entry->next) | |
1948 | ; | |
252b5132 | 1949 | |
25dbc73a AM |
1950 | return entry ? entry->value : 0; |
1951 | } | |
1952 | ||
1953 | static void | |
1954 | apuinfo_list_finish (void) | |
1955 | { | |
1956 | apuinfo_list *entry; | |
1957 | ||
1958 | for (entry = head; entry;) | |
252b5132 | 1959 | { |
25dbc73a AM |
1960 | apuinfo_list *next = entry->next; |
1961 | free (entry); | |
1962 | entry = next; | |
1963 | } | |
9abc968f | 1964 | |
25dbc73a AM |
1965 | head = NULL; |
1966 | } | |
9abc968f | 1967 | |
25dbc73a AM |
1968 | #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo" |
1969 | #define APUINFO_LABEL "APUinfo" | |
9abc968f | 1970 | |
25dbc73a AM |
1971 | /* Scan the input BFDs and create a linked list of |
1972 | the APUinfo values that will need to be emitted. */ | |
9abc968f | 1973 | |
25dbc73a AM |
1974 | static void |
1975 | ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info) | |
1976 | { | |
1977 | bfd *ibfd; | |
1978 | asection *asec; | |
1979 | char *buffer; | |
1980 | unsigned num_input_sections; | |
1981 | bfd_size_type output_section_size; | |
1982 | unsigned i; | |
1983 | unsigned num_entries; | |
1984 | unsigned long offset; | |
1985 | unsigned long length; | |
1986 | const char *error_message = NULL; | |
9abc968f | 1987 | |
25dbc73a AM |
1988 | if (link_info == NULL) |
1989 | return; | |
9abc968f | 1990 | |
25dbc73a AM |
1991 | /* Scan the input bfds, looking for apuinfo sections. */ |
1992 | num_input_sections = 0; | |
1993 | output_section_size = 0; | |
252b5132 | 1994 | |
25dbc73a | 1995 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) |
252b5132 | 1996 | { |
25dbc73a AM |
1997 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
1998 | if (asec) | |
252b5132 | 1999 | { |
25dbc73a AM |
2000 | ++ num_input_sections; |
2001 | output_section_size += asec->size; | |
252b5132 | 2002 | } |
252b5132 RH |
2003 | } |
2004 | ||
25dbc73a AM |
2005 | /* We need at least one input sections |
2006 | in order to make merging worthwhile. */ | |
2007 | if (num_input_sections < 1) | |
2008 | return; | |
deaaf2f3 | 2009 | |
25dbc73a AM |
2010 | /* Just make sure that the output section exists as well. */ |
2011 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
2012 | if (asec == NULL) | |
2013 | return; | |
252b5132 | 2014 | |
25dbc73a AM |
2015 | /* Allocate a buffer for the contents of the input sections. */ |
2016 | buffer = bfd_malloc (output_section_size); | |
2017 | if (buffer == NULL) | |
2018 | return; | |
252b5132 | 2019 | |
25dbc73a AM |
2020 | offset = 0; |
2021 | apuinfo_list_init (); | |
252b5132 | 2022 | |
25dbc73a AM |
2023 | /* Read in the input sections contents. */ |
2024 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) | |
252b5132 | 2025 | { |
25dbc73a AM |
2026 | unsigned long datum; |
2027 | char *ptr; | |
252b5132 | 2028 | |
25dbc73a AM |
2029 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
2030 | if (asec == NULL) | |
2031 | continue; | |
252b5132 | 2032 | |
25dbc73a AM |
2033 | length = asec->size; |
2034 | if (length < 24) | |
2035 | { | |
2036 | error_message = _("corrupt or empty %s section in %B"); | |
2037 | goto fail; | |
2038 | } | |
252b5132 | 2039 | |
25dbc73a AM |
2040 | if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0 |
2041 | || (bfd_bread (buffer + offset, length, ibfd) != length)) | |
2042 | { | |
2043 | error_message = _("unable to read in %s section from %B"); | |
2044 | goto fail; | |
2045 | } | |
252b5132 | 2046 | |
25dbc73a AM |
2047 | /* Process the contents of the section. */ |
2048 | ptr = buffer + offset; | |
2049 | error_message = _("corrupt %s section in %B"); | |
252b5132 | 2050 | |
25dbc73a AM |
2051 | /* Verify the contents of the header. Note - we have to |
2052 | extract the values this way in order to allow for a | |
2053 | host whose endian-ness is different from the target. */ | |
2054 | datum = bfd_get_32 (ibfd, ptr); | |
2055 | if (datum != sizeof APUINFO_LABEL) | |
2056 | goto fail; | |
252b5132 | 2057 | |
25dbc73a AM |
2058 | datum = bfd_get_32 (ibfd, ptr + 8); |
2059 | if (datum != 0x2) | |
2060 | goto fail; | |
252b5132 | 2061 | |
25dbc73a AM |
2062 | if (strcmp (ptr + 12, APUINFO_LABEL) != 0) |
2063 | goto fail; | |
252b5132 | 2064 | |
25dbc73a AM |
2065 | /* Get the number of bytes used for apuinfo entries. */ |
2066 | datum = bfd_get_32 (ibfd, ptr + 4); | |
2067 | if (datum + 20 != length) | |
2068 | goto fail; | |
2069 | ||
2070 | /* Make sure that we do not run off the end of the section. */ | |
2071 | if (offset + length > output_section_size) | |
2072 | goto fail; | |
2073 | ||
2074 | /* Scan the apuinfo section, building a list of apuinfo numbers. */ | |
2075 | for (i = 0; i < datum; i += 4) | |
2076 | apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i)); | |
2077 | ||
2078 | /* Update the offset. */ | |
2079 | offset += length; | |
252b5132 RH |
2080 | } |
2081 | ||
25dbc73a | 2082 | error_message = NULL; |
252b5132 | 2083 | |
25dbc73a AM |
2084 | /* Compute the size of the output section. */ |
2085 | num_entries = apuinfo_list_length (); | |
2086 | output_section_size = 20 + num_entries * 4; | |
252b5132 | 2087 | |
25dbc73a AM |
2088 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); |
2089 | ||
2090 | if (! bfd_set_section_size (abfd, asec, output_section_size)) | |
2091 | ibfd = abfd, | |
2092 | error_message = _("warning: unable to set size of %s section in %B"); | |
2093 | ||
2094 | fail: | |
2095 | free (buffer); | |
2096 | ||
2097 | if (error_message) | |
2098 | (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME); | |
2099 | } | |
252b5132 | 2100 | |
25dbc73a AM |
2101 | /* Prevent the output section from accumulating the input sections' |
2102 | contents. We have already stored this in our linked list structure. */ | |
252b5132 | 2103 | |
25dbc73a AM |
2104 | static bfd_boolean |
2105 | ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED, | |
2106 | asection *asec, | |
2107 | bfd_byte *contents ATTRIBUTE_UNUSED) | |
2108 | { | |
2109 | return (apuinfo_list_length () | |
2110 | && strcmp (asec->name, APUINFO_SECTION_NAME) == 0); | |
252b5132 RH |
2111 | } |
2112 | ||
25dbc73a AM |
2113 | /* Finally we can generate the output section. */ |
2114 | ||
2115 | static void | |
2116 | ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) | |
7619e7c7 | 2117 | { |
25dbc73a AM |
2118 | bfd_byte *buffer; |
2119 | asection *asec; | |
2120 | unsigned i; | |
2121 | unsigned num_entries; | |
2122 | bfd_size_type length; | |
7619e7c7 | 2123 | |
25dbc73a AM |
2124 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); |
2125 | if (asec == NULL) | |
2126 | return; | |
2127 | ||
2128 | if (apuinfo_list_length () == 0) | |
2129 | return; | |
2130 | ||
2131 | length = asec->size; | |
2132 | if (length < 20) | |
2133 | return; | |
2134 | ||
2135 | buffer = bfd_malloc (length); | |
2136 | if (buffer == NULL) | |
7619e7c7 | 2137 | { |
25dbc73a AM |
2138 | (*_bfd_error_handler) |
2139 | (_("failed to allocate space for new APUinfo section.")); | |
2140 | return; | |
7619e7c7 | 2141 | } |
7619e7c7 | 2142 | |
25dbc73a AM |
2143 | /* Create the apuinfo header. */ |
2144 | num_entries = apuinfo_list_length (); | |
2145 | bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer); | |
2146 | bfd_put_32 (abfd, num_entries * 4, buffer + 4); | |
2147 | bfd_put_32 (abfd, 0x2, buffer + 8); | |
2148 | strcpy ((char *) buffer + 12, APUINFO_LABEL); | |
feee612b | 2149 | |
25dbc73a AM |
2150 | length = 20; |
2151 | for (i = 0; i < num_entries; i++) | |
feee612b | 2152 | { |
25dbc73a AM |
2153 | bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length); |
2154 | length += 4; | |
feee612b | 2155 | } |
feee612b | 2156 | |
25dbc73a AM |
2157 | if (length != asec->size) |
2158 | (*_bfd_error_handler) (_("failed to compute new APUinfo section.")); | |
252b5132 | 2159 | |
25dbc73a AM |
2160 | if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length)) |
2161 | (*_bfd_error_handler) (_("failed to install new APUinfo section.")); | |
252b5132 | 2162 | |
25dbc73a AM |
2163 | free (buffer); |
2164 | ||
2165 | apuinfo_list_finish (); | |
252b5132 | 2166 | } |
25dbc73a AM |
2167 | \f |
2168 | /* The following functions are specific to the ELF linker, while | |
2169 | functions above are used generally. They appear in this file more | |
2170 | or less in the order in which they are called. eg. | |
2171 | ppc_elf_check_relocs is called early in the link process, | |
2172 | ppc_elf_finish_dynamic_sections is one of the last functions | |
2173 | called. */ | |
252b5132 | 2174 | |
25dbc73a AM |
2175 | /* The PPC linker needs to keep track of the number of relocs that it |
2176 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2177 | This is so that it can later discard them if they are found to be | |
2178 | unnecessary. We store the information in a field extending the | |
2179 | regular ELF linker hash table. */ | |
ae9a127f | 2180 | |
25dbc73a | 2181 | struct ppc_elf_dyn_relocs |
252b5132 | 2182 | { |
25dbc73a | 2183 | struct ppc_elf_dyn_relocs *next; |
252b5132 | 2184 | |
25dbc73a AM |
2185 | /* The input section of the reloc. */ |
2186 | asection *sec; | |
252b5132 | 2187 | |
25dbc73a AM |
2188 | /* Total number of relocs copied for the input section. */ |
2189 | bfd_size_type count; | |
252b5132 | 2190 | |
25dbc73a AM |
2191 | /* Number of pc-relative relocs copied for the input section. */ |
2192 | bfd_size_type pc_count; | |
2193 | }; | |
252b5132 | 2194 | |
25dbc73a AM |
2195 | /* Of those relocs that might be copied as dynamic relocs, this macro |
2196 | selects those that must be copied when linking a shared library, | |
2197 | even when the symbol is local. */ | |
252b5132 | 2198 | |
25dbc73a AM |
2199 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
2200 | ((RTYPE) != R_PPC_REL24 \ | |
2201 | && (RTYPE) != R_PPC_REL14 \ | |
2202 | && (RTYPE) != R_PPC_REL14_BRTAKEN \ | |
2203 | && (RTYPE) != R_PPC_REL14_BRNTAKEN \ | |
2204 | && (RTYPE) != R_PPC_REL32) | |
252b5132 | 2205 | |
25dbc73a AM |
2206 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2207 | copying dynamic variables from a shared lib into an app's dynbss | |
2208 | section, and instead use a dynamic relocation to point into the | |
2209 | shared lib. */ | |
2210 | #define ELIMINATE_COPY_RELOCS 1 | |
252b5132 | 2211 | |
25dbc73a | 2212 | /* PPC ELF linker hash entry. */ |
252b5132 | 2213 | |
25dbc73a AM |
2214 | struct ppc_elf_link_hash_entry |
2215 | { | |
2216 | struct elf_link_hash_entry elf; | |
252b5132 | 2217 | |
25dbc73a AM |
2218 | /* If this symbol is used in the linker created sections, the processor |
2219 | specific backend uses this field to map the field into the offset | |
2220 | from the beginning of the section. */ | |
2221 | elf_linker_section_pointers_t *linker_section_pointer; | |
252b5132 | 2222 | |
25dbc73a AM |
2223 | /* Track dynamic relocs copied for this symbol. */ |
2224 | struct ppc_elf_dyn_relocs *dyn_relocs; | |
252b5132 | 2225 | |
25dbc73a AM |
2226 | /* Contexts in which symbol is used in the GOT (or TOC). |
2227 | TLS_GD .. TLS_TLS bits are or'd into the mask as the | |
2228 | corresponding relocs are encountered during check_relocs. | |
2229 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2230 | indicate the corresponding GOT entry type is not needed. */ | |
2231 | #define TLS_GD 1 /* GD reloc. */ | |
2232 | #define TLS_LD 2 /* LD reloc. */ | |
2233 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2234 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2235 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2236 | #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */ | |
2237 | char tls_mask; | |
2238 | }; | |
252b5132 | 2239 | |
25dbc73a AM |
2240 | #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent)) |
2241 | ||
2242 | /* PPC ELF linker hash table. */ | |
2243 | ||
2244 | struct ppc_elf_link_hash_table | |
2245 | { | |
2246 | struct elf_link_hash_table elf; | |
2247 | ||
2248 | /* Short-cuts to get to dynamic linker sections. */ | |
2249 | asection *got; | |
2250 | asection *relgot; | |
d7128ce4 | 2251 | asection *glink; |
25dbc73a AM |
2252 | asection *plt; |
2253 | asection *relplt; | |
2254 | asection *dynbss; | |
2255 | asection *relbss; | |
2256 | asection *dynsbss; | |
2257 | asection *relsbss; | |
c9a2f333 | 2258 | elf_linker_section_t sdata[2]; |
25dbc73a AM |
2259 | asection *sbss; |
2260 | ||
2261 | /* Shortcut to .__tls_get_addr. */ | |
2262 | struct elf_link_hash_entry *tls_get_addr; | |
252b5132 | 2263 | |
25dbc73a AM |
2264 | /* TLS local dynamic got entry handling. */ |
2265 | union { | |
2266 | bfd_signed_vma refcount; | |
2267 | bfd_vma offset; | |
2268 | } tlsld_got; | |
252b5132 | 2269 | |
d7128ce4 AM |
2270 | /* Offset of PltResolve function in glink. */ |
2271 | bfd_vma glink_pltresolve; | |
2272 | ||
3b36f7e6 AM |
2273 | /* Size of reserved GOT entries. */ |
2274 | unsigned int got_header_size; | |
2275 | /* Non-zero if allocating the header left a gap. */ | |
2276 | unsigned int got_gap; | |
2277 | ||
d7128ce4 AM |
2278 | /* Whether to use new plt/got layout or not. */ |
2279 | unsigned int new_plt:1; | |
2280 | unsigned int old_plt:1; | |
2281 | ||
25dbc73a AM |
2282 | /* Small local sym to section mapping cache. */ |
2283 | struct sym_sec_cache sym_sec; | |
2284 | }; | |
252b5132 | 2285 | |
25dbc73a | 2286 | /* Get the PPC ELF linker hash table from a link_info structure. */ |
252b5132 | 2287 | |
25dbc73a AM |
2288 | #define ppc_elf_hash_table(p) \ |
2289 | ((struct ppc_elf_link_hash_table *) (p)->hash) | |
252b5132 | 2290 | |
25dbc73a | 2291 | /* Create an entry in a PPC ELF linker hash table. */ |
252b5132 | 2292 | |
25dbc73a AM |
2293 | static struct bfd_hash_entry * |
2294 | ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry, | |
2295 | struct bfd_hash_table *table, | |
2296 | const char *string) | |
252b5132 | 2297 | { |
25dbc73a AM |
2298 | /* Allocate the structure if it has not already been allocated by a |
2299 | subclass. */ | |
2300 | if (entry == NULL) | |
2301 | { | |
2302 | entry = bfd_hash_allocate (table, | |
2303 | sizeof (struct ppc_elf_link_hash_entry)); | |
2304 | if (entry == NULL) | |
2305 | return entry; | |
2306 | } | |
252b5132 | 2307 | |
25dbc73a AM |
2308 | /* Call the allocation method of the superclass. */ |
2309 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2310 | if (entry != NULL) | |
2311 | { | |
2312 | ppc_elf_hash_entry (entry)->linker_section_pointer = NULL; | |
2313 | ppc_elf_hash_entry (entry)->dyn_relocs = NULL; | |
2314 | ppc_elf_hash_entry (entry)->tls_mask = 0; | |
2315 | } | |
252b5132 | 2316 | |
25dbc73a | 2317 | return entry; |
252b5132 | 2318 | } |
3dab13f6 | 2319 | |
25dbc73a | 2320 | /* Create a PPC ELF linker hash table. */ |
3dab13f6 | 2321 | |
25dbc73a AM |
2322 | static struct bfd_link_hash_table * |
2323 | ppc_elf_link_hash_table_create (bfd *abfd) | |
3dab13f6 | 2324 | { |
25dbc73a | 2325 | struct ppc_elf_link_hash_table *ret; |
3dab13f6 | 2326 | |
25dbc73a AM |
2327 | ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table)); |
2328 | if (ret == NULL) | |
2329 | return NULL; | |
3dab13f6 | 2330 | |
25dbc73a AM |
2331 | if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, |
2332 | ppc_elf_link_hash_newfunc)) | |
3dab13f6 | 2333 | { |
25dbc73a AM |
2334 | free (ret); |
2335 | return NULL; | |
2336 | } | |
58111eb7 | 2337 | |
c9a2f333 AM |
2338 | ret->sdata[0].name = ".sdata"; |
2339 | ret->sdata[0].sym_name = "_SDA_BASE_"; | |
2340 | ret->sdata[0].bss_name = ".sbss"; | |
2341 | ||
2342 | ret->sdata[1].name = ".sdata2"; | |
2343 | ret->sdata[1].sym_name = "_SDA2_BASE_"; | |
2344 | ret->sdata[1].bss_name = ".sbss2"; | |
2345 | ||
25dbc73a AM |
2346 | return &ret->elf.root; |
2347 | } | |
3dab13f6 | 2348 | |
25dbc73a | 2349 | /* The powerpc .got has a blrl instruction in it. Mark it executable. */ |
3dab13f6 | 2350 | |
25dbc73a AM |
2351 | static bfd_boolean |
2352 | ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info) | |
2353 | { | |
2354 | struct ppc_elf_link_hash_table *htab; | |
2355 | asection *s; | |
2356 | flagword flags; | |
3dab13f6 | 2357 | |
25dbc73a AM |
2358 | if (!_bfd_elf_create_got_section (abfd, info)) |
2359 | return FALSE; | |
3dab13f6 | 2360 | |
25dbc73a AM |
2361 | htab = ppc_elf_hash_table (info); |
2362 | htab->got = s = bfd_get_section_by_name (abfd, ".got"); | |
2363 | if (s == NULL) | |
2364 | abort (); | |
3dab13f6 | 2365 | |
25dbc73a AM |
2366 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
2367 | | SEC_LINKER_CREATED); | |
2368 | if (!bfd_set_section_flags (abfd, s, flags)) | |
2369 | return FALSE; | |
3dab13f6 | 2370 | |
3b36f7e6 AM |
2371 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
2372 | | SEC_LINKER_CREATED | SEC_READONLY); | |
2373 | htab->relgot = bfd_make_section_with_flags (abfd, ".rela.got", flags); | |
25dbc73a | 2374 | if (!htab->relgot |
25dbc73a AM |
2375 | || ! bfd_set_section_alignment (abfd, htab->relgot, 2)) |
2376 | return FALSE; | |
3dab13f6 | 2377 | |
25dbc73a AM |
2378 | return TRUE; |
2379 | } | |
3dab13f6 | 2380 | |
25dbc73a AM |
2381 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
2382 | to output sections (just like _bfd_elf_create_dynamic_sections has | |
2383 | to create .dynbss and .rela.bss). */ | |
3dab13f6 | 2384 | |
25dbc73a AM |
2385 | static bfd_boolean |
2386 | ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) | |
2387 | { | |
2388 | struct ppc_elf_link_hash_table *htab; | |
2389 | asection *s; | |
2390 | flagword flags; | |
3dab13f6 | 2391 | |
25dbc73a | 2392 | htab = ppc_elf_hash_table (info); |
3dab13f6 | 2393 | |
25dbc73a AM |
2394 | if (htab->got == NULL |
2395 | && !ppc_elf_create_got (abfd, info)) | |
3dab13f6 AM |
2396 | return FALSE; |
2397 | ||
25dbc73a AM |
2398 | if (!_bfd_elf_create_dynamic_sections (abfd, info)) |
2399 | return FALSE; | |
3dab13f6 | 2400 | |
d7128ce4 AM |
2401 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS |
2402 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2403 | ||
2404 | s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags | SEC_CODE); | |
2405 | htab->glink = s; | |
2406 | if (s == NULL | |
2407 | || !bfd_set_section_alignment (abfd, s, 4)) | |
2408 | return FALSE; | |
3dab13f6 | 2409 | |
25dbc73a | 2410 | htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss"); |
3b36f7e6 AM |
2411 | s = bfd_make_section_with_flags (abfd, ".dynsbss", |
2412 | SEC_ALLOC | SEC_LINKER_CREATED); | |
2413 | htab->dynsbss = s; | |
3496cb2a | 2414 | if (s == NULL) |
25dbc73a | 2415 | return FALSE; |
3dab13f6 | 2416 | |
25dbc73a AM |
2417 | if (! info->shared) |
2418 | { | |
2419 | htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss"); | |
d7128ce4 | 2420 | s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags); |
3b36f7e6 | 2421 | htab->relsbss = s; |
25dbc73a | 2422 | if (s == NULL |
25dbc73a AM |
2423 | || ! bfd_set_section_alignment (abfd, s, 2)) |
2424 | return FALSE; | |
2425 | } | |
3dab13f6 | 2426 | |
25dbc73a AM |
2427 | htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt"); |
2428 | htab->plt = s = bfd_get_section_by_name (abfd, ".plt"); | |
2429 | if (s == NULL) | |
2430 | abort (); | |
3dab13f6 | 2431 | |
3b36f7e6 | 2432 | flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED; |
25dbc73a AM |
2433 | return bfd_set_section_flags (abfd, s, flags); |
2434 | } | |
3dab13f6 | 2435 | |
25dbc73a | 2436 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
58111eb7 | 2437 | |
25dbc73a AM |
2438 | static void |
2439 | ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed, | |
2440 | struct elf_link_hash_entry *dir, | |
2441 | struct elf_link_hash_entry *ind) | |
2442 | { | |
2443 | struct ppc_elf_link_hash_entry *edir, *eind; | |
3dab13f6 | 2444 | |
25dbc73a AM |
2445 | edir = (struct ppc_elf_link_hash_entry *) dir; |
2446 | eind = (struct ppc_elf_link_hash_entry *) ind; | |
3dab13f6 | 2447 | |
25dbc73a AM |
2448 | if (eind->dyn_relocs != NULL) |
2449 | { | |
2450 | if (edir->dyn_relocs != NULL) | |
3dab13f6 | 2451 | { |
25dbc73a AM |
2452 | struct ppc_elf_dyn_relocs **pp; |
2453 | struct ppc_elf_dyn_relocs *p; | |
3dab13f6 | 2454 | |
25dbc73a AM |
2455 | if (ind->root.type == bfd_link_hash_indirect) |
2456 | abort (); | |
2457 | ||
2458 | /* Add reloc counts against the weak sym to the strong sym | |
2459 | list. Merge any entries against the same section. */ | |
2460 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3dab13f6 | 2461 | { |
25dbc73a AM |
2462 | struct ppc_elf_dyn_relocs *q; |
2463 | ||
2464 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
2465 | if (q->sec == p->sec) | |
2466 | { | |
2467 | q->pc_count += p->pc_count; | |
2468 | q->count += p->count; | |
2469 | *pp = p->next; | |
2470 | break; | |
2471 | } | |
2472 | if (q == NULL) | |
2473 | pp = &p->next; | |
3dab13f6 | 2474 | } |
25dbc73a | 2475 | *pp = edir->dyn_relocs; |
3dab13f6 | 2476 | } |
25dbc73a AM |
2477 | |
2478 | edir->dyn_relocs = eind->dyn_relocs; | |
2479 | eind->dyn_relocs = NULL; | |
3dab13f6 | 2480 | } |
3dab13f6 | 2481 | |
25dbc73a | 2482 | edir->tls_mask |= eind->tls_mask; |
3dab13f6 | 2483 | |
25dbc73a AM |
2484 | if (ELIMINATE_COPY_RELOCS |
2485 | && ind->root.type != bfd_link_hash_indirect | |
2486 | && dir->dynamic_adjusted) | |
2487 | { | |
2488 | /* If called to transfer flags for a weakdef during processing | |
2489 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |
2490 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
2491 | dir->ref_dynamic |= ind->ref_dynamic; | |
2492 | dir->ref_regular |= ind->ref_regular; | |
2493 | dir->ref_regular_nonweak |= ind->ref_regular_nonweak; | |
2494 | dir->needs_plt |= ind->needs_plt; | |
2495 | } | |
2496 | else | |
2497 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); | |
2498 | } | |
3dab13f6 | 2499 | |
8853c3d3 AM |
2500 | /* Return 1 if target is one of ours. */ |
2501 | ||
2502 | static bfd_boolean | |
2503 | is_ppc_elf_target (const struct bfd_target *targ) | |
2504 | { | |
2505 | extern const bfd_target bfd_elf32_powerpc_vec; | |
2506 | extern const bfd_target bfd_elf32_powerpcle_vec; | |
2507 | ||
2508 | return targ == &bfd_elf32_powerpc_vec || targ == &bfd_elf32_powerpcle_vec; | |
2509 | } | |
2510 | ||
25dbc73a AM |
2511 | /* Hook called by the linker routine which adds symbols from an object |
2512 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
58111eb7 | 2513 | |
25dbc73a AM |
2514 | static bfd_boolean |
2515 | ppc_elf_add_symbol_hook (bfd *abfd, | |
2516 | struct bfd_link_info *info, | |
2517 | Elf_Internal_Sym *sym, | |
2518 | const char **namep ATTRIBUTE_UNUSED, | |
2519 | flagword *flagsp ATTRIBUTE_UNUSED, | |
2520 | asection **secp, | |
2521 | bfd_vma *valp) | |
2522 | { | |
2523 | if (sym->st_shndx == SHN_COMMON | |
2524 | && !info->relocatable | |
2525 | && sym->st_size <= elf_gp_size (abfd) | |
d2663f46 | 2526 | && is_ppc_elf_target (info->hash->creator)) |
25dbc73a AM |
2527 | { |
2528 | /* Common symbols less than or equal to -G nn bytes are automatically | |
2529 | put into .sbss. */ | |
2530 | struct ppc_elf_link_hash_table *htab; | |
3dab13f6 | 2531 | |
25dbc73a AM |
2532 | htab = ppc_elf_hash_table (info); |
2533 | if (htab->sbss == NULL) | |
2534 | { | |
644285ef | 2535 | flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED; |
3dab13f6 | 2536 | |
644285ef AM |
2537 | if (!htab->elf.dynobj) |
2538 | htab->elf.dynobj = abfd; | |
2539 | ||
3496cb2a L |
2540 | htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
2541 | ".sbss", | |
2542 | flags); | |
2543 | if (htab->sbss == NULL) | |
25dbc73a | 2544 | return FALSE; |
3dab13f6 | 2545 | } |
3dab13f6 | 2546 | |
25dbc73a AM |
2547 | *secp = htab->sbss; |
2548 | *valp = sym->st_size; | |
2549 | } | |
3dab13f6 | 2550 | |
25dbc73a | 2551 | return TRUE; |
3dab13f6 AM |
2552 | } |
2553 | \f | |
c9a2f333 | 2554 | /* Create a special linker section. */ |
25dbc73a | 2555 | |
c9a2f333 | 2556 | static bfd_boolean |
55fd94b0 AM |
2557 | ppc_elf_create_linker_section (bfd *abfd, |
2558 | struct bfd_link_info *info, | |
c9a2f333 AM |
2559 | flagword flags, |
2560 | elf_linker_section_t *lsect) | |
252b5132 | 2561 | { |
58111eb7 | 2562 | struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); |
c9a2f333 | 2563 | asection *s; |
58111eb7 | 2564 | |
c9a2f333 AM |
2565 | flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
2566 | | SEC_LINKER_CREATED); | |
58111eb7 AM |
2567 | |
2568 | /* Record the first bfd that needs the special sections. */ | |
2569 | if (!htab->elf.dynobj) | |
2570 | htab->elf.dynobj = abfd; | |
2571 | ||
3496cb2a L |
2572 | s = bfd_make_section_anyway_with_flags (htab->elf.dynobj, |
2573 | lsect->name, | |
2574 | flags); | |
76750a2f | 2575 | if (s == NULL |
76750a2f | 2576 | || !bfd_set_section_alignment (htab->elf.dynobj, s, 2)) |
c9a2f333 | 2577 | return FALSE; |
76750a2f | 2578 | lsect->section = s; |
58111eb7 | 2579 | |
c9a2f333 | 2580 | return TRUE; |
252b5132 | 2581 | } |
252b5132 | 2582 | |
25dbc73a AM |
2583 | /* Find a linker generated pointer with a given addend and type. */ |
2584 | ||
2585 | static elf_linker_section_pointers_t * | |
2586 | elf_find_pointer_linker_section | |
2587 | (elf_linker_section_pointers_t *linker_pointers, | |
2588 | bfd_vma addend, | |
2589 | elf_linker_section_t *lsect) | |
252b5132 | 2590 | { |
25dbc73a AM |
2591 | for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next) |
2592 | if (lsect == linker_pointers->lsect && addend == linker_pointers->addend) | |
2593 | return linker_pointers; | |
252b5132 | 2594 | |
25dbc73a AM |
2595 | return NULL; |
2596 | } | |
2597 | ||
2598 | /* Allocate a pointer to live in a linker created section. */ | |
2599 | ||
2600 | static bfd_boolean | |
2601 | elf_create_pointer_linker_section (bfd *abfd, | |
25dbc73a AM |
2602 | elf_linker_section_t *lsect, |
2603 | struct elf_link_hash_entry *h, | |
2604 | const Elf_Internal_Rela *rel) | |
2605 | { | |
2606 | elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL; | |
2607 | elf_linker_section_pointers_t *linker_section_ptr; | |
2608 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
2609 | bfd_size_type amt; | |
2610 | ||
2611 | BFD_ASSERT (lsect != NULL); | |
2612 | ||
2613 | /* Is this a global symbol? */ | |
2614 | if (h != NULL) | |
2615 | { | |
2616 | struct ppc_elf_link_hash_entry *eh; | |
2617 | ||
2618 | /* Has this symbol already been allocated? If so, our work is done. */ | |
2619 | eh = (struct ppc_elf_link_hash_entry *) h; | |
2620 | if (elf_find_pointer_linker_section (eh->linker_section_pointer, | |
2621 | rel->r_addend, | |
2622 | lsect)) | |
2623 | return TRUE; | |
2624 | ||
2625 | ptr_linker_section_ptr = &eh->linker_section_pointer; | |
25dbc73a AM |
2626 | } |
2627 | else | |
2628 | { | |
2629 | /* Allocation of a pointer to a local symbol. */ | |
2630 | elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); | |
2631 | ||
2632 | /* Allocate a table to hold the local symbols if first time. */ | |
2633 | if (!ptr) | |
2634 | { | |
2635 | unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info; | |
2636 | ||
2637 | amt = num_symbols; | |
2638 | amt *= sizeof (elf_linker_section_pointers_t *); | |
2639 | ptr = bfd_zalloc (abfd, amt); | |
2640 | ||
2641 | if (!ptr) | |
2642 | return FALSE; | |
2643 | ||
2644 | elf_local_ptr_offsets (abfd) = ptr; | |
2645 | } | |
2646 | ||
2647 | /* Has this symbol already been allocated? If so, our work is done. */ | |
2648 | if (elf_find_pointer_linker_section (ptr[r_symndx], | |
2649 | rel->r_addend, | |
2650 | lsect)) | |
2651 | return TRUE; | |
252b5132 | 2652 | |
25dbc73a | 2653 | ptr_linker_section_ptr = &ptr[r_symndx]; |
25dbc73a | 2654 | } |
41fcb14e | 2655 | |
25dbc73a AM |
2656 | /* Allocate space for a pointer in the linker section, and allocate |
2657 | a new pointer record from internal memory. */ | |
2658 | BFD_ASSERT (ptr_linker_section_ptr != NULL); | |
2659 | amt = sizeof (elf_linker_section_pointers_t); | |
2660 | linker_section_ptr = bfd_alloc (abfd, amt); | |
41fcb14e | 2661 | |
25dbc73a | 2662 | if (!linker_section_ptr) |
7619e7c7 | 2663 | return FALSE; |
41fcb14e | 2664 | |
25dbc73a AM |
2665 | linker_section_ptr->next = *ptr_linker_section_ptr; |
2666 | linker_section_ptr->addend = rel->r_addend; | |
2667 | linker_section_ptr->lsect = lsect; | |
25dbc73a | 2668 | *ptr_linker_section_ptr = linker_section_ptr; |
41fcb14e | 2669 | |
25dbc73a AM |
2670 | linker_section_ptr->offset = lsect->section->size; |
2671 | lsect->section->size += 4; | |
7619e7c7 | 2672 | |
25dbc73a AM |
2673 | #ifdef DEBUG |
2674 | fprintf (stderr, | |
2675 | "Create pointer in linker section %s, offset = %ld, section size = %ld\n", | |
2676 | lsect->name, (long) linker_section_ptr->offset, | |
2677 | (long) lsect->section->size); | |
2678 | #endif | |
7619e7c7 AM |
2679 | |
2680 | return TRUE; | |
41fcb14e AM |
2681 | } |
2682 | ||
b34976b6 | 2683 | static bfd_boolean |
25dbc73a AM |
2684 | update_local_sym_info (bfd *abfd, |
2685 | Elf_Internal_Shdr *symtab_hdr, | |
2686 | unsigned long r_symndx, | |
2687 | int tls_type) | |
252b5132 | 2688 | { |
25dbc73a AM |
2689 | bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd); |
2690 | char *local_got_tls_masks; | |
252b5132 | 2691 | |
25dbc73a | 2692 | if (local_got_refcounts == NULL) |
252b5132 | 2693 | { |
25dbc73a AM |
2694 | bfd_size_type size = symtab_hdr->sh_info; |
2695 | ||
2696 | size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks); | |
2697 | local_got_refcounts = bfd_zalloc (abfd, size); | |
2698 | if (local_got_refcounts == NULL) | |
b34976b6 | 2699 | return FALSE; |
25dbc73a | 2700 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 2701 | } |
41fcb14e | 2702 | |
25dbc73a AM |
2703 | local_got_refcounts[r_symndx] += 1; |
2704 | local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
2705 | local_got_tls_masks[r_symndx] |= tls_type; | |
2706 | return TRUE; | |
2707 | } | |
41fcb14e | 2708 | |
25dbc73a AM |
2709 | static void |
2710 | bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type) | |
2711 | { | |
2712 | (*_bfd_error_handler) | |
2713 | (_("%B: relocation %s cannot be used when making a shared object"), | |
2714 | abfd, | |
2715 | ppc_elf_howto_table[r_type]->name); | |
2716 | bfd_set_error (bfd_error_bad_value); | |
252b5132 RH |
2717 | } |
2718 | ||
25dbc73a AM |
2719 | /* Look through the relocs for a section during the first phase, and |
2720 | allocate space in the global offset table or procedure linkage | |
2721 | table. */ | |
252b5132 | 2722 | |
b34976b6 | 2723 | static bfd_boolean |
25dbc73a AM |
2724 | ppc_elf_check_relocs (bfd *abfd, |
2725 | struct bfd_link_info *info, | |
2726 | asection *sec, | |
2727 | const Elf_Internal_Rela *relocs) | |
252b5132 | 2728 | { |
7619e7c7 | 2729 | struct ppc_elf_link_hash_table *htab; |
25dbc73a AM |
2730 | Elf_Internal_Shdr *symtab_hdr; |
2731 | struct elf_link_hash_entry **sym_hashes; | |
2732 | const Elf_Internal_Rela *rel; | |
2733 | const Elf_Internal_Rela *rel_end; | |
2734 | asection *sreloc; | |
2735 | ||
2736 | if (info->relocatable) | |
2737 | return TRUE; | |
252b5132 | 2738 | |
c87b5a93 AM |
2739 | /* Don't do anything special with non-loaded, non-alloced sections. |
2740 | In particular, any relocs in such sections should not affect GOT | |
2741 | and PLT reference counting (ie. we don't allow them to create GOT | |
2742 | or PLT entries), there's no possibility or desire to optimize TLS | |
2743 | relocs, and there's not much point in propagating relocs to shared | |
2744 | libs that the dynamic linker won't relocate. */ | |
2745 | if ((sec->flags & SEC_ALLOC) == 0) | |
2746 | return TRUE; | |
2747 | ||
252b5132 | 2748 | #ifdef DEBUG |
25dbc73a AM |
2749 | _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B", |
2750 | sec, abfd); | |
252b5132 RH |
2751 | #endif |
2752 | ||
25dbc73a AM |
2753 | /* Initialize howto table if not already done. */ |
2754 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
2755 | ppc_elf_howto_init (); | |
2756 | ||
7619e7c7 | 2757 | htab = ppc_elf_hash_table (info); |
25dbc73a AM |
2758 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
2759 | sym_hashes = elf_sym_hashes (abfd); | |
2760 | sreloc = NULL; | |
2761 | ||
2762 | rel_end = relocs + sec->reloc_count; | |
2763 | for (rel = relocs; rel < rel_end; rel++) | |
2764 | { | |
2765 | unsigned long r_symndx; | |
2766 | enum elf_ppc_reloc_type r_type; | |
2767 | struct elf_link_hash_entry *h; | |
2768 | int tls_type = 0; | |
2769 | ||
2770 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2771 | if (r_symndx < symtab_hdr->sh_info) | |
2772 | h = NULL; | |
2773 | else | |
2774 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2775 | ||
2776 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. | |
2777 | This shows up in particular in an R_PPC_ADDR32 in the eabi | |
2778 | startup code. */ | |
3b36f7e6 AM |
2779 | if (h != NULL |
2780 | && htab->got == NULL | |
2781 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
252b5132 | 2782 | { |
3b36f7e6 AM |
2783 | if (htab->elf.dynobj == NULL) |
2784 | htab->elf.dynobj = abfd; | |
2785 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
2786 | return FALSE; | |
2787 | BFD_ASSERT (h == htab->elf.hgot); | |
25dbc73a | 2788 | } |
252b5132 | 2789 | |
25dbc73a AM |
2790 | r_type = ELF32_R_TYPE (rel->r_info); |
2791 | switch (r_type) | |
2792 | { | |
2793 | case R_PPC_GOT_TLSLD16: | |
2794 | case R_PPC_GOT_TLSLD16_LO: | |
2795 | case R_PPC_GOT_TLSLD16_HI: | |
2796 | case R_PPC_GOT_TLSLD16_HA: | |
2797 | htab->tlsld_got.refcount += 1; | |
2798 | tls_type = TLS_TLS | TLS_LD; | |
2799 | goto dogottls; | |
252b5132 | 2800 | |
25dbc73a AM |
2801 | case R_PPC_GOT_TLSGD16: |
2802 | case R_PPC_GOT_TLSGD16_LO: | |
2803 | case R_PPC_GOT_TLSGD16_HI: | |
2804 | case R_PPC_GOT_TLSGD16_HA: | |
2805 | tls_type = TLS_TLS | TLS_GD; | |
2806 | goto dogottls; | |
2807 | ||
2808 | case R_PPC_GOT_TPREL16: | |
2809 | case R_PPC_GOT_TPREL16_LO: | |
2810 | case R_PPC_GOT_TPREL16_HI: | |
2811 | case R_PPC_GOT_TPREL16_HA: | |
2812 | if (info->shared) | |
2813 | info->flags |= DF_STATIC_TLS; | |
2814 | tls_type = TLS_TLS | TLS_TPREL; | |
2815 | goto dogottls; | |
2816 | ||
2817 | case R_PPC_GOT_DTPREL16: | |
2818 | case R_PPC_GOT_DTPREL16_LO: | |
2819 | case R_PPC_GOT_DTPREL16_HI: | |
2820 | case R_PPC_GOT_DTPREL16_HA: | |
2821 | tls_type = TLS_TLS | TLS_DTPREL; | |
2822 | dogottls: | |
2823 | sec->has_tls_reloc = 1; | |
2824 | /* Fall thru */ | |
252b5132 | 2825 | |
25dbc73a AM |
2826 | /* GOT16 relocations */ |
2827 | case R_PPC_GOT16: | |
2828 | case R_PPC_GOT16_LO: | |
2829 | case R_PPC_GOT16_HI: | |
2830 | case R_PPC_GOT16_HA: | |
2831 | /* This symbol requires a global offset table entry. */ | |
2832 | if (htab->got == NULL) | |
2833 | { | |
2834 | if (htab->elf.dynobj == NULL) | |
2835 | htab->elf.dynobj = abfd; | |
2836 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
2837 | return FALSE; | |
2838 | } | |
2839 | if (h != NULL) | |
2840 | { | |
2841 | h->got.refcount += 1; | |
2842 | ppc_elf_hash_entry (h)->tls_mask |= tls_type; | |
2843 | } | |
2844 | else | |
2845 | /* This is a global offset table entry for a local symbol. */ | |
2846 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)) | |
2847 | return FALSE; | |
2848 | break; | |
252b5132 | 2849 | |
25dbc73a AM |
2850 | /* Indirect .sdata relocation. */ |
2851 | case R_PPC_EMB_SDAI16: | |
2852 | if (info->shared) | |
2853 | { | |
2854 | bad_shared_reloc (abfd, r_type); | |
2855 | return FALSE; | |
2856 | } | |
c9a2f333 AM |
2857 | if (htab->sdata[0].section == NULL |
2858 | && !ppc_elf_create_linker_section (abfd, info, 0, | |
2859 | &htab->sdata[0])) | |
2860 | return FALSE; | |
76750a2f AM |
2861 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0], |
2862 | h, rel)) | |
25dbc73a AM |
2863 | return FALSE; |
2864 | break; | |
252b5132 | 2865 | |
25dbc73a AM |
2866 | /* Indirect .sdata2 relocation. */ |
2867 | case R_PPC_EMB_SDA2I16: | |
2868 | if (info->shared) | |
2869 | { | |
2870 | bad_shared_reloc (abfd, r_type); | |
2871 | return FALSE; | |
2872 | } | |
c9a2f333 AM |
2873 | if (htab->sdata[1].section == NULL |
2874 | && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY, | |
2875 | &htab->sdata[1])) | |
2876 | return FALSE; | |
76750a2f AM |
2877 | if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1], |
2878 | h, rel)) | |
25dbc73a AM |
2879 | return FALSE; |
2880 | break; | |
252b5132 | 2881 | |
25dbc73a AM |
2882 | case R_PPC_SDAREL16: |
2883 | case R_PPC_EMB_SDA2REL: | |
2884 | case R_PPC_EMB_SDA21: | |
2885 | case R_PPC_EMB_RELSDA: | |
2886 | case R_PPC_EMB_NADDR32: | |
2887 | case R_PPC_EMB_NADDR16: | |
2888 | case R_PPC_EMB_NADDR16_LO: | |
2889 | case R_PPC_EMB_NADDR16_HI: | |
2890 | case R_PPC_EMB_NADDR16_HA: | |
2891 | if (info->shared) | |
2892 | { | |
2893 | bad_shared_reloc (abfd, r_type); | |
2894 | return FALSE; | |
2895 | } | |
2896 | break; | |
252b5132 | 2897 | |
25dbc73a AM |
2898 | case R_PPC_PLT32: |
2899 | case R_PPC_PLTREL24: | |
2900 | case R_PPC_PLTREL32: | |
2901 | case R_PPC_PLT16_LO: | |
2902 | case R_PPC_PLT16_HI: | |
2903 | case R_PPC_PLT16_HA: | |
2904 | #ifdef DEBUG | |
2905 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
2906 | #endif | |
2907 | /* This symbol requires a procedure linkage table entry. We | |
2908 | actually build the entry in finish_dynamic_symbol, | |
2909 | because this might be a case of linking PIC code without | |
2910 | linking in any dynamic objects, in which case we don't | |
2911 | need to generate a procedure linkage table after all. */ | |
7619e7c7 | 2912 | |
25dbc73a AM |
2913 | if (h == NULL) |
2914 | { | |
2915 | /* It does not make sense to have a procedure linkage | |
2916 | table entry for a local symbol. */ | |
2917 | (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against " | |
2918 | "local symbol"), | |
2919 | abfd, | |
2920 | sec, | |
2921 | (long) rel->r_offset, | |
2922 | ppc_elf_howto_table[r_type]->name); | |
2923 | bfd_set_error (bfd_error_bad_value); | |
2924 | return FALSE; | |
2925 | } | |
ee05f2fe | 2926 | |
25dbc73a AM |
2927 | h->needs_plt = 1; |
2928 | h->plt.refcount++; | |
2929 | break; | |
ee05f2fe | 2930 | |
25dbc73a AM |
2931 | /* The following relocations don't need to propagate the |
2932 | relocation if linking a shared object since they are | |
2933 | section relative. */ | |
2934 | case R_PPC_SECTOFF: | |
2935 | case R_PPC_SECTOFF_LO: | |
2936 | case R_PPC_SECTOFF_HI: | |
2937 | case R_PPC_SECTOFF_HA: | |
2938 | case R_PPC_DTPREL16: | |
2939 | case R_PPC_DTPREL16_LO: | |
2940 | case R_PPC_DTPREL16_HI: | |
2941 | case R_PPC_DTPREL16_HA: | |
2942 | case R_PPC_TOC16: | |
2943 | break; | |
252b5132 | 2944 | |
d7128ce4 AM |
2945 | case R_PPC_REL16: |
2946 | case R_PPC_REL16_LO: | |
2947 | case R_PPC_REL16_HI: | |
2948 | case R_PPC_REL16_HA: | |
2949 | htab->new_plt = 1; | |
2950 | break; | |
2951 | ||
25dbc73a AM |
2952 | /* This are just markers. */ |
2953 | case R_PPC_TLS: | |
2954 | case R_PPC_EMB_MRKREF: | |
2955 | case R_PPC_NONE: | |
2956 | case R_PPC_max: | |
2957 | break; | |
252b5132 | 2958 | |
25dbc73a AM |
2959 | /* These should only appear in dynamic objects. */ |
2960 | case R_PPC_COPY: | |
2961 | case R_PPC_GLOB_DAT: | |
2962 | case R_PPC_JMP_SLOT: | |
2963 | case R_PPC_RELATIVE: | |
2964 | break; | |
252b5132 | 2965 | |
25dbc73a AM |
2966 | /* These aren't handled yet. We'll report an error later. */ |
2967 | case R_PPC_ADDR30: | |
2968 | case R_PPC_EMB_RELSEC16: | |
2969 | case R_PPC_EMB_RELST_LO: | |
2970 | case R_PPC_EMB_RELST_HI: | |
2971 | case R_PPC_EMB_RELST_HA: | |
2972 | case R_PPC_EMB_BIT_FLD: | |
2973 | break; | |
252b5132 | 2974 | |
25dbc73a AM |
2975 | /* This refers only to functions defined in the shared library. */ |
2976 | case R_PPC_LOCAL24PC: | |
d7128ce4 AM |
2977 | if (h && h == htab->elf.hgot) |
2978 | htab->old_plt = 1; | |
25dbc73a | 2979 | break; |
252b5132 | 2980 | |
25dbc73a AM |
2981 | /* This relocation describes the C++ object vtable hierarchy. |
2982 | Reconstruct it for later use during GC. */ | |
2983 | case R_PPC_GNU_VTINHERIT: | |
2984 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
2985 | return FALSE; | |
2986 | break; | |
252b5132 | 2987 | |
25dbc73a AM |
2988 | /* This relocation describes which C++ vtable entries are actually |
2989 | used. Record for later use during GC. */ | |
2990 | case R_PPC_GNU_VTENTRY: | |
2991 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
2992 | return FALSE; | |
2993 | break; | |
252b5132 | 2994 | |
25dbc73a AM |
2995 | /* We shouldn't really be seeing these. */ |
2996 | case R_PPC_TPREL32: | |
2997 | if (info->shared) | |
2998 | info->flags |= DF_STATIC_TLS; | |
2999 | goto dodyn; | |
252b5132 | 3000 | |
25dbc73a AM |
3001 | /* Nor these. */ |
3002 | case R_PPC_DTPMOD32: | |
3003 | case R_PPC_DTPREL32: | |
3004 | goto dodyn; | |
252b5132 | 3005 | |
25dbc73a AM |
3006 | case R_PPC_TPREL16: |
3007 | case R_PPC_TPREL16_LO: | |
3008 | case R_PPC_TPREL16_HI: | |
3009 | case R_PPC_TPREL16_HA: | |
3010 | if (info->shared) | |
3011 | info->flags |= DF_STATIC_TLS; | |
3012 | goto dodyn; | |
ee05f2fe | 3013 | |
25dbc73a AM |
3014 | /* When creating a shared object, we must copy these |
3015 | relocs into the output file. We create a reloc | |
3016 | section in dynobj and make room for the reloc. */ | |
3017 | case R_PPC_REL24: | |
3018 | case R_PPC_REL14: | |
3019 | case R_PPC_REL14_BRTAKEN: | |
3020 | case R_PPC_REL14_BRNTAKEN: | |
3021 | case R_PPC_REL32: | |
d7128ce4 | 3022 | if (h == NULL) |
25dbc73a | 3023 | break; |
d7128ce4 AM |
3024 | if (h == htab->elf.hgot) |
3025 | { | |
3026 | htab->old_plt = 1; | |
3027 | break; | |
3028 | } | |
25dbc73a | 3029 | /* fall through */ |
ee05f2fe | 3030 | |
25dbc73a AM |
3031 | case R_PPC_ADDR32: |
3032 | case R_PPC_ADDR24: | |
3033 | case R_PPC_ADDR16: | |
3034 | case R_PPC_ADDR16_LO: | |
3035 | case R_PPC_ADDR16_HI: | |
3036 | case R_PPC_ADDR16_HA: | |
3037 | case R_PPC_ADDR14: | |
3038 | case R_PPC_ADDR14_BRTAKEN: | |
3039 | case R_PPC_ADDR14_BRNTAKEN: | |
3040 | case R_PPC_UADDR32: | |
3041 | case R_PPC_UADDR16: | |
3042 | if (h != NULL && !info->shared) | |
3043 | { | |
3044 | /* We may need a plt entry if the symbol turns out to be | |
3045 | a function defined in a dynamic object. */ | |
3046 | h->plt.refcount++; | |
7fce784e | 3047 | |
25dbc73a AM |
3048 | /* We may need a copy reloc too. */ |
3049 | h->non_got_ref = 1; | |
3050 | } | |
7619e7c7 | 3051 | |
25dbc73a AM |
3052 | dodyn: |
3053 | /* If we are creating a shared library, and this is a reloc | |
3054 | against a global symbol, or a non PC relative reloc | |
3055 | against a local symbol, then we need to copy the reloc | |
3056 | into the shared library. However, if we are linking with | |
3057 | -Bsymbolic, we do not need to copy a reloc against a | |
3058 | global symbol which is defined in an object we are | |
3059 | including in the link (i.e., DEF_REGULAR is set). At | |
3060 | this point we have not seen all the input files, so it is | |
3061 | possible that DEF_REGULAR is not set now but will be set | |
3062 | later (it is never cleared). In case of a weak definition, | |
3063 | DEF_REGULAR may be cleared later by a strong definition in | |
3064 | a shared library. We account for that possibility below by | |
3065 | storing information in the dyn_relocs field of the hash | |
3066 | table entry. A similar situation occurs when creating | |
3067 | shared libraries and symbol visibility changes render the | |
3068 | symbol local. | |
7619e7c7 | 3069 | |
25dbc73a AM |
3070 | If on the other hand, we are creating an executable, we |
3071 | may need to keep relocations for symbols satisfied by a | |
3072 | dynamic library if we manage to avoid copy relocs for the | |
3073 | symbol. */ | |
3074 | if ((info->shared | |
3075 | && (MUST_BE_DYN_RELOC (r_type) | |
3076 | || (h != NULL | |
3077 | && (! info->symbolic | |
3078 | || h->root.type == bfd_link_hash_defweak | |
3079 | || !h->def_regular)))) | |
3080 | || (ELIMINATE_COPY_RELOCS | |
3081 | && !info->shared | |
25dbc73a AM |
3082 | && h != NULL |
3083 | && (h->root.type == bfd_link_hash_defweak | |
3084 | || !h->def_regular))) | |
3085 | { | |
3086 | struct ppc_elf_dyn_relocs *p; | |
3087 | struct ppc_elf_dyn_relocs **head; | |
7619e7c7 | 3088 | |
25dbc73a AM |
3089 | #ifdef DEBUG |
3090 | fprintf (stderr, | |
3091 | "ppc_elf_check_relocs needs to " | |
3092 | "create relocation for %s\n", | |
3093 | (h && h->root.root.string | |
3094 | ? h->root.root.string : "<unknown>")); | |
3095 | #endif | |
3096 | if (sreloc == NULL) | |
3097 | { | |
3098 | const char *name; | |
7619e7c7 | 3099 | |
25dbc73a AM |
3100 | name = (bfd_elf_string_from_elf_section |
3101 | (abfd, | |
3102 | elf_elfheader (abfd)->e_shstrndx, | |
3103 | elf_section_data (sec)->rel_hdr.sh_name)); | |
3104 | if (name == NULL) | |
3105 | return FALSE; | |
7619e7c7 | 3106 | |
25dbc73a AM |
3107 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
3108 | && strcmp (bfd_get_section_name (abfd, sec), | |
3109 | name + 5) == 0); | |
7619e7c7 | 3110 | |
c9a2f333 AM |
3111 | if (htab->elf.dynobj == NULL) |
3112 | htab->elf.dynobj = abfd; | |
25dbc73a AM |
3113 | sreloc = bfd_get_section_by_name (htab->elf.dynobj, name); |
3114 | if (sreloc == NULL) | |
3115 | { | |
3116 | flagword flags; | |
7619e7c7 | 3117 | |
25dbc73a | 3118 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
c87b5a93 AM |
3119 | | SEC_IN_MEMORY | SEC_LINKER_CREATED |
3120 | | SEC_ALLOC | SEC_LOAD); | |
3496cb2a L |
3121 | sreloc = bfd_make_section_with_flags (htab->elf.dynobj, |
3122 | name, | |
3123 | flags); | |
25dbc73a | 3124 | if (sreloc == NULL |
25dbc73a AM |
3125 | || ! bfd_set_section_alignment (htab->elf.dynobj, |
3126 | sreloc, 2)) | |
3127 | return FALSE; | |
3128 | } | |
3129 | elf_section_data (sec)->sreloc = sreloc; | |
3130 | } | |
7619e7c7 | 3131 | |
25dbc73a AM |
3132 | /* If this is a global symbol, we count the number of |
3133 | relocations we need for this symbol. */ | |
3134 | if (h != NULL) | |
3135 | { | |
3136 | head = &ppc_elf_hash_entry (h)->dyn_relocs; | |
3137 | } | |
3138 | else | |
3139 | { | |
3140 | /* Track dynamic relocs needed for local syms too. | |
3141 | We really need local syms available to do this | |
3142 | easily. Oh well. */ | |
7619e7c7 | 3143 | |
25dbc73a AM |
3144 | asection *s; |
3145 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
3146 | sec, r_symndx); | |
3147 | if (s == NULL) | |
3148 | return FALSE; | |
7fce784e | 3149 | |
25dbc73a AM |
3150 | head = ((struct ppc_elf_dyn_relocs **) |
3151 | &elf_section_data (s)->local_dynrel); | |
3152 | } | |
7fce784e | 3153 | |
25dbc73a AM |
3154 | p = *head; |
3155 | if (p == NULL || p->sec != sec) | |
3156 | { | |
3157 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); | |
3158 | if (p == NULL) | |
3159 | return FALSE; | |
3160 | p->next = *head; | |
3161 | *head = p; | |
3162 | p->sec = sec; | |
3163 | p->count = 0; | |
3164 | p->pc_count = 0; | |
3165 | } | |
3166 | ||
3167 | p->count += 1; | |
3168 | if (!MUST_BE_DYN_RELOC (r_type)) | |
3169 | p->pc_count += 1; | |
7619e7c7 | 3170 | } |
25dbc73a AM |
3171 | |
3172 | break; | |
7619e7c7 AM |
3173 | } |
3174 | } | |
ee05f2fe | 3175 | |
25dbc73a AM |
3176 | return TRUE; |
3177 | } | |
3178 | \f | |
8853c3d3 AM |
3179 | /* Merge backend specific data from an object file to the output |
3180 | object file when linking. */ | |
3181 | ||
3182 | static bfd_boolean | |
3183 | ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) | |
3184 | { | |
3185 | flagword old_flags; | |
3186 | flagword new_flags; | |
3187 | bfd_boolean error; | |
3188 | ||
3189 | if (!is_ppc_elf_target (ibfd->xvec) | |
3190 | || !is_ppc_elf_target (obfd->xvec)) | |
3191 | return TRUE; | |
3192 | ||
3193 | /* Check if we have the same endianess. */ | |
3194 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) | |
3195 | return FALSE; | |
3196 | ||
3197 | new_flags = elf_elfheader (ibfd)->e_flags; | |
3198 | old_flags = elf_elfheader (obfd)->e_flags; | |
3199 | if (!elf_flags_init (obfd)) | |
3200 | { | |
3201 | /* First call, no flags set. */ | |
3202 | elf_flags_init (obfd) = TRUE; | |
3203 | elf_elfheader (obfd)->e_flags = new_flags; | |
3204 | } | |
3205 | ||
3206 | /* Compatible flags are ok. */ | |
3207 | else if (new_flags == old_flags) | |
3208 | ; | |
3209 | ||
3210 | /* Incompatible flags. */ | |
3211 | else | |
3212 | { | |
3213 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib | |
3214 | to be linked with either. */ | |
3215 | error = FALSE; | |
3216 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 | |
3217 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
3218 | { | |
3219 | error = TRUE; | |
3220 | (*_bfd_error_handler) | |
3221 | (_("%B: compiled with -mrelocatable and linked with " | |
3222 | "modules compiled normally"), ibfd); | |
3223 | } | |
3224 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
3225 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
3226 | { | |
3227 | error = TRUE; | |
3228 | (*_bfd_error_handler) | |
3229 | (_("%B: compiled normally and linked with " | |
3230 | "modules compiled with -mrelocatable"), ibfd); | |
3231 | } | |
3232 | ||
3233 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
3234 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
3235 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
3236 | ||
3237 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
3238 | but each input file is either -mrelocatable or -mrelocatable-lib. */ | |
3239 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) | |
3240 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
3241 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
3242 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
3243 | ||
3244 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if | |
3245 | any module uses it. */ | |
3246 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); | |
3247 | ||
3248 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
3249 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
3250 | ||
3251 | /* Warn about any other mismatches. */ | |
3252 | if (new_flags != old_flags) | |
3253 | { | |
3254 | error = TRUE; | |
3255 | (*_bfd_error_handler) | |
3256 | (_("%B: uses different e_flags (0x%lx) fields " | |
3257 | "than previous modules (0x%lx)"), | |
3258 | ibfd, (long) new_flags, (long) old_flags); | |
3259 | } | |
3260 | ||
3261 | if (error) | |
3262 | { | |
3263 | bfd_set_error (bfd_error_bad_value); | |
3264 | return FALSE; | |
3265 | } | |
3266 | } | |
3267 | ||
3268 | return TRUE; | |
3269 | } | |
3270 | \f | |
d7128ce4 AM |
3271 | /* Choose which PLT scheme to use, and set .plt flags appropriately. |
3272 | Returns -1 on error, 0 for old PLT, 1 for new PLT. */ | |
3273 | int | |
3274 | ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED, | |
3275 | struct bfd_link_info *info, | |
3276 | int force_old_plt) | |
3277 | { | |
3278 | struct ppc_elf_link_hash_table *htab; | |
3279 | ||
3280 | htab = ppc_elf_hash_table (info); | |
3281 | if (force_old_plt || !htab->new_plt) | |
3282 | htab->old_plt = 1; | |
3283 | ||
3284 | if (!htab->old_plt) | |
3285 | { | |
86b9da88 AM |
3286 | flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS |
3287 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3288 | ||
3289 | /* The new PLT is a loaded section. */ | |
3290 | if (htab->plt != NULL | |
3291 | && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags)) | |
3292 | return -1; | |
3293 | ||
3294 | /* The new GOT is not executable. */ | |
3295 | if (htab->got != NULL | |
3296 | && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags)) | |
3297 | return -1; | |
d7128ce4 AM |
3298 | } |
3299 | else | |
3300 | { | |
3301 | /* Stop an unused .glink section from affecting .text alignment. */ | |
86b9da88 AM |
3302 | if (htab->glink != NULL |
3303 | && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0)) | |
3304 | return -1; | |
d7128ce4 AM |
3305 | } |
3306 | return !htab->old_plt; | |
3307 | } | |
3308 | \f | |
25dbc73a AM |
3309 | /* Return the section that should be marked against GC for a given |
3310 | relocation. */ | |
586119b3 | 3311 | |
25dbc73a AM |
3312 | static asection * |
3313 | ppc_elf_gc_mark_hook (asection *sec, | |
3314 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
3315 | Elf_Internal_Rela *rel, | |
3316 | struct elf_link_hash_entry *h, | |
3317 | Elf_Internal_Sym *sym) | |
3318 | { | |
3319 | if (h != NULL) | |
ee05f2fe | 3320 | { |
25dbc73a | 3321 | switch (ELF32_R_TYPE (rel->r_info)) |
ee05f2fe | 3322 | { |
25dbc73a AM |
3323 | case R_PPC_GNU_VTINHERIT: |
3324 | case R_PPC_GNU_VTENTRY: | |
3325 | break; | |
ee05f2fe | 3326 | |
25dbc73a AM |
3327 | default: |
3328 | switch (h->root.type) | |
ee05f2fe | 3329 | { |
25dbc73a AM |
3330 | case bfd_link_hash_defined: |
3331 | case bfd_link_hash_defweak: | |
3332 | return h->root.u.def.section; | |
3333 | ||
3334 | case bfd_link_hash_common: | |
3335 | return h->root.u.c.p->section; | |
3336 | ||
3337 | default: | |
3338 | break; | |
ee05f2fe AM |
3339 | } |
3340 | } | |
25dbc73a AM |
3341 | } |
3342 | else | |
3343 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
4e795f50 | 3344 | |
25dbc73a AM |
3345 | return NULL; |
3346 | } | |
a876ecf9 | 3347 | |
25dbc73a AM |
3348 | /* Update the got, plt and dynamic reloc reference counts for the |
3349 | section being removed. */ | |
3350 | ||
3351 | static bfd_boolean | |
3352 | ppc_elf_gc_sweep_hook (bfd *abfd, | |
3353 | struct bfd_link_info *info, | |
3354 | asection *sec, | |
3355 | const Elf_Internal_Rela *relocs) | |
3356 | { | |
3357 | struct ppc_elf_link_hash_table *htab; | |
3358 | Elf_Internal_Shdr *symtab_hdr; | |
3359 | struct elf_link_hash_entry **sym_hashes; | |
3360 | bfd_signed_vma *local_got_refcounts; | |
3361 | const Elf_Internal_Rela *rel, *relend; | |
3362 | ||
c87b5a93 AM |
3363 | if ((sec->flags & SEC_ALLOC) == 0) |
3364 | return TRUE; | |
3365 | ||
25dbc73a AM |
3366 | elf_section_data (sec)->local_dynrel = NULL; |
3367 | ||
3368 | htab = ppc_elf_hash_table (info); | |
3369 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
3370 | sym_hashes = elf_sym_hashes (abfd); | |
3371 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
3372 | ||
3373 | relend = relocs + sec->reloc_count; | |
3374 | for (rel = relocs; rel < relend; rel++) | |
3375 | { | |
3376 | unsigned long r_symndx; | |
3377 | enum elf_ppc_reloc_type r_type; | |
3378 | struct elf_link_hash_entry *h = NULL; | |
3379 | ||
3380 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3381 | if (r_symndx >= symtab_hdr->sh_info) | |
a876ecf9 | 3382 | { |
25dbc73a AM |
3383 | struct ppc_elf_dyn_relocs **pp, *p; |
3384 | struct ppc_elf_link_hash_entry *eh; | |
3385 | ||
3386 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3387 | while (h->root.type == bfd_link_hash_indirect | |
3388 | || h->root.type == bfd_link_hash_warning) | |
3389 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3390 | eh = (struct ppc_elf_link_hash_entry *) h; | |
3391 | ||
3392 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
3393 | if (p->sec == sec) | |
3394 | { | |
3395 | /* Everything must go for SEC. */ | |
3396 | *pp = p->next; | |
3397 | break; | |
3398 | } | |
a876ecf9 | 3399 | } |
ee05f2fe | 3400 | |
25dbc73a AM |
3401 | r_type = ELF32_R_TYPE (rel->r_info); |
3402 | switch (r_type) | |
ee05f2fe | 3403 | { |
25dbc73a AM |
3404 | case R_PPC_GOT_TLSLD16: |
3405 | case R_PPC_GOT_TLSLD16_LO: | |
3406 | case R_PPC_GOT_TLSLD16_HI: | |
3407 | case R_PPC_GOT_TLSLD16_HA: | |
3408 | htab->tlsld_got.refcount -= 1; | |
3409 | /* Fall thru */ | |
3410 | ||
3411 | case R_PPC_GOT_TLSGD16: | |
3412 | case R_PPC_GOT_TLSGD16_LO: | |
3413 | case R_PPC_GOT_TLSGD16_HI: | |
3414 | case R_PPC_GOT_TLSGD16_HA: | |
3415 | case R_PPC_GOT_TPREL16: | |
3416 | case R_PPC_GOT_TPREL16_LO: | |
3417 | case R_PPC_GOT_TPREL16_HI: | |
3418 | case R_PPC_GOT_TPREL16_HA: | |
3419 | case R_PPC_GOT_DTPREL16: | |
3420 | case R_PPC_GOT_DTPREL16_LO: | |
3421 | case R_PPC_GOT_DTPREL16_HI: | |
3422 | case R_PPC_GOT_DTPREL16_HA: | |
3423 | case R_PPC_GOT16: | |
3424 | case R_PPC_GOT16_LO: | |
3425 | case R_PPC_GOT16_HI: | |
3426 | case R_PPC_GOT16_HA: | |
3427 | if (h != NULL) | |
ee05f2fe | 3428 | { |
25dbc73a AM |
3429 | if (h->got.refcount > 0) |
3430 | h->got.refcount--; | |
ee05f2fe | 3431 | } |
25dbc73a AM |
3432 | else if (local_got_refcounts != NULL) |
3433 | { | |
3434 | if (local_got_refcounts[r_symndx] > 0) | |
3435 | local_got_refcounts[r_symndx]--; | |
3436 | } | |
3437 | break; | |
ee05f2fe | 3438 | |
25dbc73a AM |
3439 | case R_PPC_REL24: |
3440 | case R_PPC_REL14: | |
3441 | case R_PPC_REL14_BRTAKEN: | |
3442 | case R_PPC_REL14_BRNTAKEN: | |
3443 | case R_PPC_REL32: | |
3b36f7e6 | 3444 | if (h == NULL || h == htab->elf.hgot) |
25dbc73a AM |
3445 | break; |
3446 | /* Fall thru */ | |
ee05f2fe | 3447 | |
25dbc73a AM |
3448 | case R_PPC_ADDR32: |
3449 | case R_PPC_ADDR24: | |
3450 | case R_PPC_ADDR16: | |
3451 | case R_PPC_ADDR16_LO: | |
3452 | case R_PPC_ADDR16_HI: | |
3453 | case R_PPC_ADDR16_HA: | |
3454 | case R_PPC_ADDR14: | |
3455 | case R_PPC_ADDR14_BRTAKEN: | |
3456 | case R_PPC_ADDR14_BRNTAKEN: | |
3457 | case R_PPC_UADDR32: | |
3458 | case R_PPC_UADDR16: | |
3459 | case R_PPC_PLT32: | |
3460 | case R_PPC_PLTREL24: | |
3461 | case R_PPC_PLT16_LO: | |
3462 | case R_PPC_PLT16_HI: | |
3463 | case R_PPC_PLT16_HA: | |
3464 | if (h != NULL) | |
3465 | { | |
3466 | if (h->plt.refcount > 0) | |
3467 | h->plt.refcount--; | |
3468 | } | |
3469 | break; | |
ee05f2fe | 3470 | |
25dbc73a AM |
3471 | default: |
3472 | break; | |
3473 | } | |
7fce784e | 3474 | } |
7fce784e AS |
3475 | return TRUE; |
3476 | } | |
25dbc73a AM |
3477 | \f |
3478 | /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ | |
7fce784e | 3479 | |
25dbc73a AM |
3480 | asection * |
3481 | ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) | |
7fce784e | 3482 | { |
25dbc73a | 3483 | struct ppc_elf_link_hash_table *htab; |
7fce784e | 3484 | |
25dbc73a | 3485 | htab = ppc_elf_hash_table (info); |
d7128ce4 AM |
3486 | if (!htab->old_plt |
3487 | && htab->plt != NULL | |
3488 | && htab->plt->output_section != NULL) | |
3489 | { | |
3490 | elf_section_type (htab->plt->output_section) = SHT_PROGBITS; | |
3491 | elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE; | |
3492 | } | |
3493 | ||
25dbc73a AM |
3494 | htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
3495 | FALSE, FALSE, TRUE); | |
25dbc73a | 3496 | return _bfd_elf_tls_setup (obfd, info); |
7fce784e AS |
3497 | } |
3498 | ||
25dbc73a AM |
3499 | /* Run through all the TLS relocs looking for optimization |
3500 | opportunities. */ | |
252b5132 | 3501 | |
25dbc73a AM |
3502 | bfd_boolean |
3503 | ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, | |
3504 | struct bfd_link_info *info) | |
252b5132 | 3505 | { |
7fce784e | 3506 | bfd *ibfd; |
25dbc73a AM |
3507 | asection *sec; |
3508 | struct ppc_elf_link_hash_table *htab; | |
252b5132 | 3509 | |
25dbc73a AM |
3510 | if (info->relocatable || info->shared) |
3511 | return TRUE; | |
252b5132 | 3512 | |
7619e7c7 | 3513 | htab = ppc_elf_hash_table (info); |
25dbc73a | 3514 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
252b5132 | 3515 | { |
25dbc73a AM |
3516 | Elf_Internal_Sym *locsyms = NULL; |
3517 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
7619e7c7 | 3518 | |
25dbc73a AM |
3519 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
3520 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
3521 | { | |
3522 | Elf_Internal_Rela *relstart, *rel, *relend; | |
3523 | int expecting_tls_get_addr; | |
252b5132 | 3524 | |
25dbc73a AM |
3525 | /* Read the relocations. */ |
3526 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, | |
3527 | info->keep_memory); | |
3528 | if (relstart == NULL) | |
3529 | return FALSE; | |
7619e7c7 | 3530 | |
25dbc73a AM |
3531 | expecting_tls_get_addr = 0; |
3532 | relend = relstart + sec->reloc_count; | |
3533 | for (rel = relstart; rel < relend; rel++) | |
3534 | { | |
3535 | enum elf_ppc_reloc_type r_type; | |
3536 | unsigned long r_symndx; | |
3537 | struct elf_link_hash_entry *h = NULL; | |
3538 | char *tls_mask; | |
3539 | char tls_set, tls_clear; | |
3540 | bfd_boolean is_local; | |
7fce784e | 3541 | |
25dbc73a AM |
3542 | r_symndx = ELF32_R_SYM (rel->r_info); |
3543 | if (r_symndx >= symtab_hdr->sh_info) | |
3544 | { | |
3545 | struct elf_link_hash_entry **sym_hashes; | |
7fce784e | 3546 | |
25dbc73a AM |
3547 | sym_hashes = elf_sym_hashes (ibfd); |
3548 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3549 | while (h->root.type == bfd_link_hash_indirect | |
3550 | || h->root.type == bfd_link_hash_warning) | |
3551 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3552 | } | |
7619e7c7 | 3553 | |
25dbc73a AM |
3554 | is_local = FALSE; |
3555 | if (h == NULL | |
3556 | || !h->def_dynamic) | |
3557 | is_local = TRUE; | |
7619e7c7 | 3558 | |
25dbc73a AM |
3559 | r_type = ELF32_R_TYPE (rel->r_info); |
3560 | switch (r_type) | |
7619e7c7 | 3561 | { |
25dbc73a AM |
3562 | case R_PPC_GOT_TLSLD16: |
3563 | case R_PPC_GOT_TLSLD16_LO: | |
3564 | case R_PPC_GOT_TLSLD16_HI: | |
3565 | case R_PPC_GOT_TLSLD16_HA: | |
3566 | /* These relocs should never be against a symbol | |
3567 | defined in a shared lib. Leave them alone if | |
3568 | that turns out to be the case. */ | |
3569 | expecting_tls_get_addr = 0; | |
3570 | htab->tlsld_got.refcount -= 1; | |
3571 | if (!is_local) | |
3572 | continue; | |
3573 | ||
3574 | /* LD -> LE */ | |
3575 | tls_set = 0; | |
3576 | tls_clear = TLS_LD; | |
3577 | expecting_tls_get_addr = 1; | |
3578 | break; | |
3579 | ||
3580 | case R_PPC_GOT_TLSGD16: | |
3581 | case R_PPC_GOT_TLSGD16_LO: | |
3582 | case R_PPC_GOT_TLSGD16_HI: | |
3583 | case R_PPC_GOT_TLSGD16_HA: | |
3584 | if (is_local) | |
3585 | /* GD -> LE */ | |
3586 | tls_set = 0; | |
3587 | else | |
3588 | /* GD -> IE */ | |
3589 | tls_set = TLS_TLS | TLS_TPRELGD; | |
3590 | tls_clear = TLS_GD; | |
3591 | expecting_tls_get_addr = 1; | |
3592 | break; | |
3593 | ||
3594 | case R_PPC_GOT_TPREL16: | |
3595 | case R_PPC_GOT_TPREL16_LO: | |
3596 | case R_PPC_GOT_TPREL16_HI: | |
3597 | case R_PPC_GOT_TPREL16_HA: | |
3598 | expecting_tls_get_addr = 0; | |
3599 | if (is_local) | |
3600 | { | |
3601 | /* IE -> LE */ | |
3602 | tls_set = 0; | |
3603 | tls_clear = TLS_TPREL; | |
3604 | break; | |
3605 | } | |
3606 | else | |
3607 | continue; | |
3608 | ||
3609 | case R_PPC_REL14: | |
3610 | case R_PPC_REL14_BRTAKEN: | |
3611 | case R_PPC_REL14_BRNTAKEN: | |
3612 | case R_PPC_REL24: | |
3613 | if (expecting_tls_get_addr | |
3614 | && h != NULL | |
3615 | && h == htab->tls_get_addr) | |
3616 | { | |
3617 | if (h->plt.refcount > 0) | |
3618 | h->plt.refcount -= 1; | |
3619 | } | |
3620 | expecting_tls_get_addr = 0; | |
3621 | continue; | |
3622 | ||
3623 | default: | |
3624 | expecting_tls_get_addr = 0; | |
3625 | continue; | |
7619e7c7 | 3626 | } |
25dbc73a AM |
3627 | |
3628 | if (h != NULL) | |
7619e7c7 | 3629 | { |
25dbc73a AM |
3630 | if (tls_set == 0) |
3631 | { | |
3632 | /* We managed to get rid of a got entry. */ | |
3633 | if (h->got.refcount > 0) | |
3634 | h->got.refcount -= 1; | |
3635 | } | |
3636 | tls_mask = &ppc_elf_hash_entry (h)->tls_mask; | |
3637 | } | |
3638 | else | |
3639 | { | |
3640 | Elf_Internal_Sym *sym; | |
3641 | bfd_signed_vma *lgot_refs; | |
3642 | char *lgot_masks; | |
3643 | ||
3644 | if (locsyms == NULL) | |
3645 | { | |
3646 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
3647 | if (locsyms == NULL) | |
3648 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
3649 | symtab_hdr->sh_info, | |
3650 | 0, NULL, NULL, NULL); | |
3651 | if (locsyms == NULL) | |
3652 | { | |
3653 | if (elf_section_data (sec)->relocs != relstart) | |
3654 | free (relstart); | |
3655 | return FALSE; | |
3656 | } | |
3657 | } | |
3658 | sym = locsyms + r_symndx; | |
3659 | lgot_refs = elf_local_got_refcounts (ibfd); | |
3660 | if (lgot_refs == NULL) | |
3661 | abort (); | |
3662 | if (tls_set == 0) | |
3663 | { | |
3664 | /* We managed to get rid of a got entry. */ | |
3665 | if (lgot_refs[r_symndx] > 0) | |
3666 | lgot_refs[r_symndx] -= 1; | |
3667 | } | |
3668 | lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info); | |
3669 | tls_mask = &lgot_masks[r_symndx]; | |
7619e7c7 | 3670 | } |
25dbc73a AM |
3671 | |
3672 | *tls_mask |= tls_set; | |
3673 | *tls_mask &= ~tls_clear; | |
7619e7c7 | 3674 | } |
25dbc73a AM |
3675 | |
3676 | if (elf_section_data (sec)->relocs != relstart) | |
3677 | free (relstart); | |
7619e7c7 | 3678 | } |
25dbc73a AM |
3679 | |
3680 | if (locsyms != NULL | |
3681 | && (symtab_hdr->contents != (unsigned char *) locsyms)) | |
3682 | { | |
3683 | if (!info->keep_memory) | |
3684 | free (locsyms); | |
3685 | else | |
3686 | symtab_hdr->contents = (unsigned char *) locsyms; | |
3687 | } | |
7fce784e | 3688 | } |
25dbc73a AM |
3689 | return TRUE; |
3690 | } | |
3691 | \f | |
3692 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
3693 | regular object. The current definition is in some section of the | |
3694 | dynamic object, but we're not including those sections. We have to | |
3695 | change the definition to something the rest of the link can | |
3696 | understand. */ | |
7fce784e | 3697 | |
25dbc73a AM |
3698 | static bfd_boolean |
3699 | ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, | |
3700 | struct elf_link_hash_entry *h) | |
3701 | { | |
3702 | struct ppc_elf_link_hash_table *htab; | |
3703 | asection *s; | |
3704 | unsigned int power_of_two; | |
7fce784e | 3705 | |
25dbc73a AM |
3706 | #ifdef DEBUG |
3707 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", | |
3708 | h->root.root.string); | |
3709 | #endif | |
252b5132 | 3710 | |
25dbc73a AM |
3711 | /* Make sure we know what is going on here. */ |
3712 | htab = ppc_elf_hash_table (info); | |
3713 | BFD_ASSERT (htab->elf.dynobj != NULL | |
3714 | && (h->needs_plt | |
3715 | || h->u.weakdef != NULL | |
3716 | || (h->def_dynamic | |
3717 | && h->ref_regular | |
3718 | && !h->def_regular))); | |
252b5132 | 3719 | |
25dbc73a AM |
3720 | /* Deal with function syms. */ |
3721 | if (h->type == STT_FUNC | |
3722 | || h->needs_plt) | |
3723 | { | |
3724 | /* Clear procedure linkage table information for any symbol that | |
3725 | won't need a .plt entry. */ | |
3726 | if (h->plt.refcount <= 0 | |
3727 | || SYMBOL_CALLS_LOCAL (info, h) | |
3728 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
3729 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 | 3730 | { |
25dbc73a | 3731 | /* A PLT entry is not required/allowed when: |
252b5132 | 3732 | |
25dbc73a AM |
3733 | 1. We are not using ld.so; because then the PLT entry |
3734 | can't be set up, so we can't use one. In this case, | |
3735 | ppc_elf_adjust_dynamic_symbol won't even be called. | |
252b5132 | 3736 | |
25dbc73a AM |
3737 | 2. GC has rendered the entry unused. |
3738 | ||
3739 | 3. We know for certain that a call to this symbol | |
3740 | will go to this object, or will remain undefined. */ | |
3741 | h->plt.offset = (bfd_vma) -1; | |
3742 | h->needs_plt = 0; | |
3743 | } | |
3744 | return TRUE; | |
252b5132 | 3745 | } |
25dbc73a AM |
3746 | else |
3747 | h->plt.offset = (bfd_vma) -1; | |
252b5132 | 3748 | |
25dbc73a AM |
3749 | /* If this is a weak symbol, and there is a real definition, the |
3750 | processor independent code will have arranged for us to see the | |
3751 | real definition first, and we can just use the same value. */ | |
3752 | if (h->u.weakdef != NULL) | |
252b5132 | 3753 | { |
25dbc73a AM |
3754 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
3755 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
3756 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
3757 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
3758 | if (ELIMINATE_COPY_RELOCS) | |
3759 | h->non_got_ref = h->u.weakdef->non_got_ref; | |
3760 | return TRUE; | |
3761 | } | |
dc810e39 | 3762 | |
25dbc73a AM |
3763 | /* This is a reference to a symbol defined by a dynamic object which |
3764 | is not a function. */ | |
252b5132 | 3765 | |
25dbc73a AM |
3766 | /* If we are creating a shared library, we must presume that the |
3767 | only references to the symbol are via the global offset table. | |
3768 | For such cases we need not do anything here; the relocations will | |
3769 | be handled correctly by relocate_section. */ | |
3770 | if (info->shared) | |
3771 | return TRUE; | |
252b5132 | 3772 | |
25dbc73a AM |
3773 | /* If there are no references to this symbol that do not use the |
3774 | GOT, we don't need to generate a copy reloc. */ | |
3775 | if (!h->non_got_ref) | |
3776 | return TRUE; | |
3777 | ||
3778 | if (ELIMINATE_COPY_RELOCS) | |
3779 | { | |
3780 | struct ppc_elf_dyn_relocs *p; | |
3781 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) | |
252b5132 | 3782 | { |
25dbc73a AM |
3783 | s = p->sec->output_section; |
3784 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
3785 | break; | |
252b5132 RH |
3786 | } |
3787 | ||
25dbc73a AM |
3788 | /* If we didn't find any dynamic relocs in read-only sections, then |
3789 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
3790 | if (p == NULL) | |
252b5132 | 3791 | { |
25dbc73a AM |
3792 | h->non_got_ref = 0; |
3793 | return TRUE; | |
252b5132 RH |
3794 | } |
3795 | } | |
3796 | ||
25dbc73a AM |
3797 | /* We must allocate the symbol in our .dynbss section, which will |
3798 | become part of the .bss section of the executable. There will be | |
3799 | an entry for this symbol in the .dynsym section. The dynamic | |
3800 | object will contain position independent code, so all references | |
3801 | from the dynamic object to this symbol will go through the global | |
3802 | offset table. The dynamic linker will use the .dynsym entry to | |
3803 | determine the address it must put in the global offset table, so | |
3804 | both the dynamic object and the regular object will refer to the | |
3805 | same memory location for the variable. | |
3806 | ||
3807 | Of course, if the symbol is sufficiently small, we must instead | |
3808 | allocate it in .sbss. FIXME: It would be better to do this if and | |
3809 | only if there were actually SDAREL relocs for that symbol. */ | |
3810 | ||
3811 | if (h->size <= elf_gp_size (htab->elf.dynobj)) | |
3812 | s = htab->dynsbss; | |
3813 | else | |
3814 | s = htab->dynbss; | |
3815 | BFD_ASSERT (s != NULL); | |
3816 | ||
3817 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
3818 | copy the initial value out of the dynamic object and into the | |
3819 | runtime process image. We need to remember the offset into the | |
3820 | .rela.bss section we are going to use. */ | |
3821 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
3822 | { | |
3823 | asection *srel; | |
3824 | ||
3825 | if (h->size <= elf_gp_size (htab->elf.dynobj)) | |
3826 | srel = htab->relsbss; | |
3827 | else | |
3828 | srel = htab->relbss; | |
3829 | BFD_ASSERT (srel != NULL); | |
3830 | srel->size += sizeof (Elf32_External_Rela); | |
3831 | h->needs_copy = 1; | |
3832 | } | |
7619e7c7 | 3833 | |
25dbc73a AM |
3834 | /* We need to figure out the alignment required for this symbol. I |
3835 | have no idea how ELF linkers handle this. */ | |
3836 | power_of_two = bfd_log2 (h->size); | |
3837 | if (power_of_two > 4) | |
3838 | power_of_two = 4; | |
7619e7c7 | 3839 | |
25dbc73a AM |
3840 | /* Apply the required alignment. */ |
3841 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); | |
3842 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
3843 | { | |
3844 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) | |
7619e7c7 | 3845 | return FALSE; |
7619e7c7 AM |
3846 | } |
3847 | ||
25dbc73a AM |
3848 | /* Define the symbol as being at this point in the section. */ |
3849 | h->root.u.def.section = s; | |
3850 | h->root.u.def.value = s->size; | |
7619e7c7 | 3851 | |
25dbc73a AM |
3852 | /* Increment the section size to make room for the symbol. */ |
3853 | s->size += h->size; | |
7619e7c7 | 3854 | |
25dbc73a AM |
3855 | return TRUE; |
3856 | } | |
3857 | \f | |
3b36f7e6 AM |
3858 | /* Allocate NEED contiguous space in .got, and return the offset. |
3859 | Handles allocation of the got header when crossing 32k. */ | |
3860 | ||
3861 | static bfd_vma | |
3862 | allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need) | |
3863 | { | |
3864 | bfd_vma where; | |
d7128ce4 AM |
3865 | unsigned int max_before_header = 32768; |
3866 | ||
3867 | if (htab->old_plt) | |
3868 | max_before_header = 32764; | |
3b36f7e6 AM |
3869 | |
3870 | if (need <= htab->got_gap) | |
3871 | { | |
3872 | where = max_before_header - htab->got_gap; | |
3873 | htab->got_gap -= need; | |
3874 | } | |
3875 | else | |
3876 | { | |
3877 | if (htab->got->size + need > max_before_header | |
3878 | && htab->got->size <= max_before_header) | |
3879 | { | |
3880 | htab->got_gap = max_before_header - htab->got->size; | |
3881 | htab->got->size = max_before_header + htab->got_header_size; | |
3882 | } | |
3883 | where = htab->got->size; | |
3884 | htab->got->size += need; | |
3885 | } | |
3886 | return where; | |
3887 | } | |
3888 | ||
25dbc73a | 3889 | /* Allocate space in associated reloc sections for dynamic relocs. */ |
252b5132 | 3890 | |
b34976b6 | 3891 | static bfd_boolean |
25dbc73a | 3892 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
252b5132 | 3893 | { |
25dbc73a AM |
3894 | struct bfd_link_info *info = inf; |
3895 | struct ppc_elf_link_hash_entry *eh; | |
7619e7c7 | 3896 | struct ppc_elf_link_hash_table *htab; |
25dbc73a | 3897 | struct ppc_elf_dyn_relocs *p; |
252b5132 | 3898 | |
25dbc73a | 3899 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 3900 | return TRUE; |
252b5132 | 3901 | |
25dbc73a AM |
3902 | if (h->root.type == bfd_link_hash_warning) |
3903 | /* When warning symbols are created, they **replace** the "real" | |
3904 | entry in the hash table, thus we never get to see the real | |
3905 | symbol in a hash traversal. So look at it now. */ | |
3906 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
e47cd125 | 3907 | |
7619e7c7 | 3908 | htab = ppc_elf_hash_table (info); |
25dbc73a AM |
3909 | if (htab->elf.dynamic_sections_created |
3910 | && h->plt.refcount > 0) | |
252b5132 | 3911 | { |
25dbc73a AM |
3912 | /* Make sure this symbol is output as a dynamic symbol. */ |
3913 | if (h->dynindx == -1 | |
3914 | && !h->forced_local) | |
252b5132 | 3915 | { |
25dbc73a AM |
3916 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
3917 | return FALSE; | |
252b5132 RH |
3918 | } |
3919 | ||
25dbc73a AM |
3920 | if (info->shared |
3921 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) | |
252b5132 | 3922 | { |
25dbc73a | 3923 | asection *s = htab->plt; |
7619e7c7 | 3924 | |
d7128ce4 | 3925 | if (!htab->old_plt) |
252b5132 | 3926 | { |
d7128ce4 AM |
3927 | h->plt.offset = s->size; |
3928 | s->size += 4; | |
3929 | ||
3930 | s = htab->glink; | |
3931 | if (!info->shared | |
3932 | && !h->def_regular) | |
3933 | { | |
3934 | h->root.u.def.section = s; | |
3935 | h->root.u.def.value = s->size; | |
3936 | } | |
3937 | s->size += GLINK_ENTRY_SIZE; | |
252b5132 | 3938 | } |
d7128ce4 AM |
3939 | else |
3940 | { | |
3941 | /* If this is the first .plt entry, make room for the | |
3942 | special first entry. */ | |
3943 | if (s->size == 0) | |
3944 | s->size += PLT_INITIAL_ENTRY_SIZE; | |
3945 | ||
3946 | /* The PowerPC PLT is actually composed of two parts, the | |
3947 | first part is 2 words (for a load and a jump), and then | |
3948 | there is a remaining word available at the end. */ | |
3949 | h->plt.offset = (PLT_INITIAL_ENTRY_SIZE | |
3950 | + (PLT_SLOT_SIZE | |
3951 | * ((s->size - PLT_INITIAL_ENTRY_SIZE) | |
3952 | / PLT_ENTRY_SIZE))); | |
3953 | ||
3954 | /* If this symbol is not defined in a regular file, and we | |
3955 | are not generating a shared library, then set the symbol | |
3956 | to this location in the .plt. This is required to make | |
3957 | function pointers compare as equal between the normal | |
3958 | executable and the shared library. */ | |
3959 | if (! info->shared | |
3960 | && !h->def_regular) | |
3961 | { | |
3962 | h->root.u.def.section = s; | |
3963 | h->root.u.def.value = h->plt.offset; | |
3964 | } | |
252b5132 | 3965 | |
d7128ce4 AM |
3966 | /* Make room for this entry. After the 8192nd entry, room |
3967 | for two entries is allocated. */ | |
3968 | s->size += PLT_ENTRY_SIZE; | |
3969 | if ((s->size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE | |
3970 | > PLT_NUM_SINGLE_ENTRIES) | |
3971 | s->size += PLT_ENTRY_SIZE; | |
3972 | } | |
25dbc73a AM |
3973 | |
3974 | /* We also need to make an entry in the .rela.plt section. */ | |
3975 | htab->relplt->size += sizeof (Elf32_External_Rela); | |
3976 | } | |
3977 | else | |
3978 | { | |
3979 | h->plt.offset = (bfd_vma) -1; | |
3980 | h->needs_plt = 0; | |
3981 | } | |
3982 | } | |
3983 | else | |
3984 | { | |
3985 | h->plt.offset = (bfd_vma) -1; | |
3986 | h->needs_plt = 0; | |
3987 | } | |
3988 | ||
3989 | eh = (struct ppc_elf_link_hash_entry *) h; | |
3990 | if (eh->elf.got.refcount > 0) | |
3991 | { | |
3992 | /* Make sure this symbol is output as a dynamic symbol. */ | |
3993 | if (eh->elf.dynindx == -1 | |
3994 | && !eh->elf.forced_local) | |
3995 | { | |
3996 | if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf)) | |
b34976b6 | 3997 | return FALSE; |
25dbc73a | 3998 | } |
252b5132 | 3999 | |
25dbc73a AM |
4000 | if (eh->tls_mask == (TLS_TLS | TLS_LD) |
4001 | && !eh->elf.def_dynamic) | |
4002 | /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */ | |
4003 | eh->elf.got.offset = (bfd_vma) -1; | |
4004 | else | |
4005 | { | |
4006 | bfd_boolean dyn; | |
3b36f7e6 | 4007 | unsigned int need = 0; |
25dbc73a | 4008 | if ((eh->tls_mask & TLS_TLS) != 0) |
252b5132 | 4009 | { |
25dbc73a | 4010 | if ((eh->tls_mask & TLS_LD) != 0) |
3b36f7e6 | 4011 | need += 8; |
25dbc73a | 4012 | if ((eh->tls_mask & TLS_GD) != 0) |
3b36f7e6 | 4013 | need += 8; |
25dbc73a | 4014 | if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0) |
3b36f7e6 | 4015 | need += 4; |
25dbc73a | 4016 | if ((eh->tls_mask & TLS_DTPREL) != 0) |
3b36f7e6 | 4017 | need += 4; |
252b5132 | 4018 | } |
25dbc73a | 4019 | else |
3b36f7e6 AM |
4020 | need += 4; |
4021 | eh->elf.got.offset = allocate_got (htab, need); | |
25dbc73a AM |
4022 | dyn = htab->elf.dynamic_sections_created; |
4023 | if ((info->shared | |
4024 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf)) | |
4025 | && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT | |
4026 | || eh->elf.root.type != bfd_link_hash_undefweak)) | |
252b5132 | 4027 | { |
3b36f7e6 AM |
4028 | /* All the entries we allocated need relocs. |
4029 | Except LD only needs one. */ | |
25dbc73a | 4030 | if ((eh->tls_mask & TLS_LD) != 0) |
3b36f7e6 AM |
4031 | need -= 4; |
4032 | htab->relgot->size += need * (sizeof (Elf32_External_Rela) / 4); | |
252b5132 | 4033 | } |
25dbc73a AM |
4034 | } |
4035 | } | |
4036 | else | |
4037 | eh->elf.got.offset = (bfd_vma) -1; | |
252b5132 | 4038 | |
25dbc73a AM |
4039 | if (eh->dyn_relocs == NULL) |
4040 | return TRUE; | |
252b5132 | 4041 | |
25dbc73a AM |
4042 | /* In the shared -Bsymbolic case, discard space allocated for |
4043 | dynamic pc-relative relocs against symbols which turn out to be | |
4044 | defined in regular objects. For the normal shared case, discard | |
4045 | space for relocs that have become local due to symbol visibility | |
4046 | changes. */ | |
4047 | ||
4048 | if (info->shared) | |
4049 | { | |
4050 | /* Relocs that use pc_count are those that appear on a call insn, | |
4051 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | |
4052 | generated via assembly. We want calls to protected symbols to | |
4053 | resolve directly to the function rather than going via the plt. | |
4054 | If people want function pointer comparisons to work as expected | |
4055 | then they should avoid writing weird assembly. */ | |
4056 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
4057 | { | |
4058 | struct ppc_elf_dyn_relocs **pp; | |
4059 | ||
4060 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
252b5132 | 4061 | { |
25dbc73a AM |
4062 | p->count -= p->pc_count; |
4063 | p->pc_count = 0; | |
4064 | if (p->count == 0) | |
4065 | *pp = p->next; | |
4066 | else | |
4067 | pp = &p->next; | |
252b5132 | 4068 | } |
25dbc73a | 4069 | } |
252b5132 | 4070 | |
25dbc73a AM |
4071 | /* Also discard relocs on undefined weak syms with non-default |
4072 | visibility. */ | |
4073 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4074 | && h->root.type == bfd_link_hash_undefweak) | |
4075 | eh->dyn_relocs = NULL; | |
7619e7c7 | 4076 | |
25dbc73a AM |
4077 | /* Make sure undefined weak symbols are output as a dynamic symbol |
4078 | in PIEs. */ | |
4079 | if (info->pie | |
4080 | && eh->dyn_relocs != NULL | |
4081 | && h->dynindx == -1 | |
4082 | && h->root.type == bfd_link_hash_undefweak | |
4083 | && !h->forced_local) | |
4084 | { | |
4085 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
4086 | return FALSE; | |
4087 | } | |
4088 | } | |
4089 | else if (ELIMINATE_COPY_RELOCS) | |
4090 | { | |
4091 | /* For the non-shared case, discard space for relocs against | |
4092 | symbols which turn out to need copy relocs or are not | |
4093 | dynamic. */ | |
7619e7c7 | 4094 | |
25dbc73a AM |
4095 | if (!h->non_got_ref |
4096 | && h->def_dynamic | |
4097 | && !h->def_regular) | |
4098 | { | |
4099 | /* Make sure this symbol is output as a dynamic symbol. | |
4100 | Undefined weak syms won't yet be marked as dynamic. */ | |
4101 | if (h->dynindx == -1 | |
4102 | && !h->forced_local) | |
4103 | { | |
4104 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
4105 | return FALSE; | |
4106 | } | |
7619e7c7 | 4107 | |
25dbc73a AM |
4108 | /* If that succeeded, we know we'll be keeping all the |
4109 | relocs. */ | |
4110 | if (h->dynindx != -1) | |
4111 | goto keep; | |
4112 | } | |
252b5132 | 4113 | |
25dbc73a | 4114 | eh->dyn_relocs = NULL; |
252b5132 | 4115 | |
25dbc73a AM |
4116 | keep: ; |
4117 | } | |
252b5132 | 4118 | |
25dbc73a AM |
4119 | /* Finally, allocate space. */ |
4120 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4121 | { | |
4122 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
4123 | sreloc->size += p->count * sizeof (Elf32_External_Rela); | |
4124 | } | |
252b5132 | 4125 | |
25dbc73a AM |
4126 | return TRUE; |
4127 | } | |
7619e7c7 | 4128 | |
25dbc73a | 4129 | /* Find any dynamic relocs that apply to read-only sections. */ |
7619e7c7 | 4130 | |
25dbc73a AM |
4131 | static bfd_boolean |
4132 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *info) | |
4133 | { | |
4134 | struct ppc_elf_dyn_relocs *p; | |
7619e7c7 | 4135 | |
25dbc73a AM |
4136 | if (h->root.type == bfd_link_hash_indirect) |
4137 | return TRUE; | |
252b5132 | 4138 | |
25dbc73a AM |
4139 | if (h->root.type == bfd_link_hash_warning) |
4140 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 4141 | |
25dbc73a AM |
4142 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) |
4143 | { | |
4144 | asection *s = p->sec->output_section; | |
ee05f2fe | 4145 | |
25dbc73a AM |
4146 | if (s != NULL |
4147 | && ((s->flags & (SEC_READONLY | SEC_ALLOC)) | |
4148 | == (SEC_READONLY | SEC_ALLOC))) | |
4149 | { | |
4150 | ((struct bfd_link_info *) info)->flags |= DF_TEXTREL; | |
ee05f2fe | 4151 | |
25dbc73a AM |
4152 | /* Not an error, just cut short the traversal. */ |
4153 | return FALSE; | |
4154 | } | |
4155 | } | |
4156 | return TRUE; | |
4157 | } | |
4158 | ||
4159 | /* Set the sizes of the dynamic sections. */ | |
4160 | ||
4161 | static bfd_boolean | |
4162 | ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, | |
4163 | struct bfd_link_info *info) | |
4164 | { | |
4165 | struct ppc_elf_link_hash_table *htab; | |
4166 | asection *s; | |
4167 | bfd_boolean relocs; | |
4168 | bfd *ibfd; | |
7fce784e | 4169 | |
252b5132 | 4170 | #ifdef DEBUG |
25dbc73a | 4171 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); |
252b5132 | 4172 | #endif |
252b5132 | 4173 | |
25dbc73a AM |
4174 | htab = ppc_elf_hash_table (info); |
4175 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
252b5132 | 4176 | |
25dbc73a AM |
4177 | if (elf_hash_table (info)->dynamic_sections_created) |
4178 | { | |
4179 | /* Set the contents of the .interp section to the interpreter. */ | |
4180 | if (info->executable) | |
4181 | { | |
4182 | s = bfd_get_section_by_name (htab->elf.dynobj, ".interp"); | |
4183 | BFD_ASSERT (s != NULL); | |
4184 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
4185 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
4186 | } | |
4187 | } | |
252b5132 | 4188 | |
d7128ce4 AM |
4189 | if (htab->old_plt) |
4190 | htab->got_header_size = 16; | |
4191 | else | |
4192 | htab->got_header_size = 12; | |
252b5132 | 4193 | |
25dbc73a AM |
4194 | /* Set up .got offsets for local syms, and space for local dynamic |
4195 | relocs. */ | |
4196 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
4197 | { | |
4198 | bfd_signed_vma *local_got; | |
4199 | bfd_signed_vma *end_local_got; | |
4200 | char *lgot_masks; | |
4201 | bfd_size_type locsymcount; | |
4202 | Elf_Internal_Shdr *symtab_hdr; | |
7fce784e | 4203 | |
d2663f46 | 4204 | if (!is_ppc_elf_target (ibfd->xvec)) |
25dbc73a | 4205 | continue; |
7fce784e | 4206 | |
25dbc73a AM |
4207 | for (s = ibfd->sections; s != NULL; s = s->next) |
4208 | { | |
4209 | struct ppc_elf_dyn_relocs *p; | |
252b5132 | 4210 | |
25dbc73a AM |
4211 | for (p = ((struct ppc_elf_dyn_relocs *) |
4212 | elf_section_data (s)->local_dynrel); | |
4213 | p != NULL; | |
4214 | p = p->next) | |
4215 | { | |
4216 | if (!bfd_is_abs_section (p->sec) | |
4217 | && bfd_is_abs_section (p->sec->output_section)) | |
4218 | { | |
4219 | /* Input section has been discarded, either because | |
4220 | it is a copy of a linkonce section or due to | |
4221 | linker script /DISCARD/, so we'll be discarding | |
4222 | the relocs too. */ | |
7fce784e | 4223 | } |
25dbc73a | 4224 | else if (p->count != 0) |
7fce784e | 4225 | { |
25dbc73a AM |
4226 | elf_section_data (p->sec)->sreloc->size |
4227 | += p->count * sizeof (Elf32_External_Rela); | |
4228 | if ((p->sec->output_section->flags | |
4229 | & (SEC_READONLY | SEC_ALLOC)) | |
4230 | == (SEC_READONLY | SEC_ALLOC)) | |
4231 | info->flags |= DF_TEXTREL; | |
7fce784e | 4232 | } |
252b5132 | 4233 | } |
252b5132 | 4234 | } |
252b5132 | 4235 | |
25dbc73a AM |
4236 | local_got = elf_local_got_refcounts (ibfd); |
4237 | if (!local_got) | |
4238 | continue; | |
252b5132 | 4239 | |
25dbc73a AM |
4240 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
4241 | locsymcount = symtab_hdr->sh_info; | |
4242 | end_local_got = local_got + locsymcount; | |
4243 | lgot_masks = (char *) end_local_got; | |
25dbc73a AM |
4244 | for (; local_got < end_local_got; ++local_got, ++lgot_masks) |
4245 | if (*local_got > 0) | |
4246 | { | |
4247 | if (*lgot_masks == (TLS_TLS | TLS_LD)) | |
4248 | { | |
4249 | /* If just an LD reloc, we'll just use | |
4250 | htab->tlsld_got.offset. */ | |
3b36f7e6 | 4251 | htab->tlsld_got.refcount += 1; |
25dbc73a AM |
4252 | *local_got = (bfd_vma) -1; |
4253 | } | |
4254 | else | |
4255 | { | |
3b36f7e6 | 4256 | unsigned int need = 0; |
25dbc73a AM |
4257 | if ((*lgot_masks & TLS_TLS) != 0) |
4258 | { | |
4259 | if ((*lgot_masks & TLS_GD) != 0) | |
3b36f7e6 | 4260 | need += 8; |
25dbc73a | 4261 | if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0) |
3b36f7e6 | 4262 | need += 4; |
25dbc73a | 4263 | if ((*lgot_masks & TLS_DTPREL) != 0) |
3b36f7e6 | 4264 | need += 4; |
25dbc73a AM |
4265 | } |
4266 | else | |
3b36f7e6 AM |
4267 | need += 4; |
4268 | *local_got = allocate_got (htab, need); | |
25dbc73a | 4269 | if (info->shared) |
3b36f7e6 AM |
4270 | htab->relgot->size += (need |
4271 | * (sizeof (Elf32_External_Rela) / 4)); | |
25dbc73a AM |
4272 | } |
4273 | } | |
4274 | else | |
4275 | *local_got = (bfd_vma) -1; | |
4276 | } | |
252b5132 | 4277 | |
3b36f7e6 AM |
4278 | if (htab->tlsld_got.refcount > 0) |
4279 | { | |
4280 | htab->tlsld_got.offset = allocate_got (htab, 8); | |
4281 | if (info->shared) | |
4282 | htab->relgot->size += sizeof (Elf32_External_Rela); | |
4283 | } | |
4284 | else | |
4285 | htab->tlsld_got.offset = (bfd_vma) -1; | |
4286 | ||
25dbc73a AM |
4287 | /* Allocate space for global sym dynamic relocs. */ |
4288 | elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info); | |
4289 | ||
3b36f7e6 AM |
4290 | if (htab->got != NULL) |
4291 | { | |
4292 | unsigned int g_o_t = 32768; | |
4293 | ||
4294 | /* If we haven't allocated the header, do so now. */ | |
4295 | if (htab->got->size <= 32768) | |
4296 | { | |
4297 | g_o_t = htab->got->size; | |
4298 | htab->got->size += htab->got_header_size; | |
4299 | } | |
d7128ce4 AM |
4300 | if (htab->old_plt) |
4301 | g_o_t += 4; | |
3b36f7e6 AM |
4302 | |
4303 | htab->elf.hgot->root.u.def.value = g_o_t; | |
4304 | } | |
4305 | ||
d7128ce4 AM |
4306 | if (htab->glink != NULL && htab->glink->size != 0) |
4307 | { | |
4308 | htab->glink_pltresolve = htab->glink->size; | |
86b9da88 AM |
4309 | /* Space for the branch table. */ |
4310 | htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4; | |
4311 | /* Pad out to align the start of PLTresolve. */ | |
4312 | htab->glink->size += -htab->glink->size & 15; | |
d7128ce4 AM |
4313 | htab->glink->size += GLINK_PLTRESOLVE; |
4314 | } | |
4315 | ||
25dbc73a AM |
4316 | /* We've now determined the sizes of the various dynamic sections. |
4317 | Allocate memory for them. */ | |
4318 | relocs = FALSE; | |
4319 | for (s = htab->elf.dynobj->sections; s != NULL; s = s->next) | |
252b5132 | 4320 | { |
25dbc73a AM |
4321 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
4322 | continue; | |
252b5132 | 4323 | |
25dbc73a | 4324 | if (s == htab->plt |
d7128ce4 | 4325 | || s == htab->glink |
644285ef AM |
4326 | || s == htab->got |
4327 | || s == htab->sbss) | |
25dbc73a AM |
4328 | { |
4329 | /* Strip this section if we don't need it; see the | |
4330 | comment below. */ | |
4331 | } | |
c9a2f333 AM |
4332 | else if (s == htab->sdata[0].section |
4333 | || s == htab->sdata[1].section) | |
25dbc73a | 4334 | { |
c9a2f333 | 4335 | /* Strip these too. */ |
25dbc73a AM |
4336 | } |
4337 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) | |
4338 | { | |
4339 | if (s->size == 0) | |
252b5132 | 4340 | { |
25dbc73a AM |
4341 | /* If we don't need this section, strip it from the |
4342 | output file. This is mostly to handle .rela.bss and | |
4343 | .rela.plt. We must create both sections in | |
4344 | create_dynamic_sections, because they must be created | |
4345 | before the linker maps input sections to output | |
4346 | sections. The linker does that before | |
4347 | adjust_dynamic_symbol is called, and it is that | |
4348 | function which decides whether anything needs to go | |
4349 | into these sections. */ | |
4350 | } | |
4351 | else | |
4352 | { | |
4353 | /* Remember whether there are any relocation sections. */ | |
4354 | relocs = TRUE; | |
252b5132 | 4355 | |
25dbc73a AM |
4356 | /* We use the reloc_count field as a counter if we need |
4357 | to copy relocs into the output file. */ | |
4358 | s->reloc_count = 0; | |
252b5132 RH |
4359 | } |
4360 | } | |
25dbc73a AM |
4361 | else |
4362 | { | |
4363 | /* It's not one of our sections, so don't allocate space. */ | |
4364 | continue; | |
4365 | } | |
252b5132 | 4366 | |
25dbc73a AM |
4367 | if (s->size == 0) |
4368 | { | |
8423293d | 4369 | s->flags |= SEC_EXCLUDE; |
25dbc73a AM |
4370 | continue; |
4371 | } | |
7fce784e | 4372 | |
d7128ce4 | 4373 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
644285ef AM |
4374 | continue; |
4375 | ||
25dbc73a AM |
4376 | /* Allocate memory for the section contents. */ |
4377 | s->contents = bfd_zalloc (htab->elf.dynobj, s->size); | |
4378 | if (s->contents == NULL) | |
4379 | return FALSE; | |
4380 | } | |
252b5132 | 4381 | |
25dbc73a | 4382 | if (htab->elf.dynamic_sections_created) |
7619e7c7 | 4383 | { |
25dbc73a AM |
4384 | /* Add some entries to the .dynamic section. We fill in the |
4385 | values later, in ppc_elf_finish_dynamic_sections, but we | |
4386 | must add the entries now so that we get the correct size for | |
4387 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
4388 | dynamic linker and used by the debugger. */ | |
4389 | #define add_dynamic_entry(TAG, VAL) \ | |
4390 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |
252b5132 | 4391 | |
25dbc73a | 4392 | if (info->executable) |
7619e7c7 | 4393 | { |
25dbc73a AM |
4394 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
4395 | return FALSE; | |
7619e7c7 AM |
4396 | } |
4397 | ||
25dbc73a | 4398 | if (htab->plt != NULL && htab->plt->size != 0) |
7619e7c7 | 4399 | { |
25dbc73a AM |
4400 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
4401 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
4402 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
4403 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
4404 | return FALSE; | |
4405 | } | |
7619e7c7 | 4406 | |
d7128ce4 AM |
4407 | if (htab->glink != NULL && htab->glink->size != 0) |
4408 | { | |
4409 | if (!add_dynamic_entry (DT_PPC_GLINK, 0)) | |
4410 | return FALSE; | |
4411 | } | |
4412 | ||
25dbc73a AM |
4413 | if (relocs) |
4414 | { | |
4415 | if (!add_dynamic_entry (DT_RELA, 0) | |
4416 | || !add_dynamic_entry (DT_RELASZ, 0) | |
4417 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
4418 | return FALSE; | |
4419 | } | |
7619e7c7 | 4420 | |
25dbc73a AM |
4421 | /* If any dynamic relocs apply to a read-only section, then we |
4422 | need a DT_TEXTREL entry. */ | |
4423 | if ((info->flags & DF_TEXTREL) == 0) | |
4424 | elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs, | |
4425 | info); | |
7619e7c7 | 4426 | |
25dbc73a AM |
4427 | if ((info->flags & DF_TEXTREL) != 0) |
4428 | { | |
4429 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
4430 | return FALSE; | |
7619e7c7 AM |
4431 | } |
4432 | } | |
25dbc73a AM |
4433 | #undef add_dynamic_entry |
4434 | ||
7619e7c7 AM |
4435 | return TRUE; |
4436 | } | |
25dbc73a AM |
4437 | \f |
4438 | #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) | |
4439 | ||
4440 | static const int shared_stub_entry[] = | |
4441 | { | |
4442 | 0x7c0802a6, /* mflr 0 */ | |
4443 | 0x429f0005, /* bcl 20, 31, .Lxxx */ | |
4444 | 0x7d6802a6, /* mflr 11 */ | |
4445 | 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */ | |
4446 | 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */ | |
4447 | 0x7c0803a6, /* mtlr 0 */ | |
4448 | 0x7d6903a6, /* mtctr 11 */ | |
4449 | 0x4e800420, /* bctr */ | |
4450 | }; | |
4451 | ||
4452 | static const int stub_entry[] = | |
4453 | { | |
4454 | 0x3d600000, /* lis 11,xxx@ha */ | |
4455 | 0x396b0000, /* addi 11,11,xxx@l */ | |
4456 | 0x7d6903a6, /* mtctr 11 */ | |
4457 | 0x4e800420, /* bctr */ | |
4458 | }; | |
4459 | ||
4460 | static bfd_boolean | |
4461 | ppc_elf_relax_section (bfd *abfd, | |
4462 | asection *isec, | |
4463 | struct bfd_link_info *link_info, | |
4464 | bfd_boolean *again) | |
4465 | { | |
4466 | struct one_fixup | |
4467 | { | |
4468 | struct one_fixup *next; | |
4469 | asection *tsec; | |
4470 | bfd_vma toff; | |
4471 | bfd_vma trampoff; | |
4472 | }; | |
7619e7c7 | 4473 | |
25dbc73a AM |
4474 | Elf_Internal_Shdr *symtab_hdr; |
4475 | bfd_byte *contents = NULL; | |
4476 | Elf_Internal_Sym *isymbuf = NULL; | |
4477 | Elf_Internal_Rela *internal_relocs = NULL; | |
4478 | Elf_Internal_Rela *irel, *irelend; | |
4479 | struct one_fixup *fixups = NULL; | |
4480 | bfd_boolean changed; | |
d7128ce4 | 4481 | struct ppc_elf_link_hash_table *htab; |
25dbc73a | 4482 | bfd_size_type trampoff; |
7619e7c7 | 4483 | |
25dbc73a | 4484 | *again = FALSE; |
7619e7c7 | 4485 | |
c87b5a93 AM |
4486 | /* Nothing to do if there are no relocations, and no need to do |
4487 | anything with non-alloc sections. */ | |
4488 | if ((isec->flags & SEC_ALLOC) == 0 | |
4489 | || (isec->flags & SEC_RELOC) == 0 | |
4490 | || isec->reloc_count == 0) | |
25dbc73a | 4491 | return TRUE; |
7619e7c7 | 4492 | |
25dbc73a AM |
4493 | trampoff = (isec->size + 3) & (bfd_vma) -4; |
4494 | /* Space for a branch around any trampolines. */ | |
4495 | trampoff += 4; | |
7619e7c7 | 4496 | |
25dbc73a | 4497 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
7619e7c7 | 4498 | |
25dbc73a AM |
4499 | /* Get a copy of the native relocations. */ |
4500 | internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, | |
4501 | link_info->keep_memory); | |
4502 | if (internal_relocs == NULL) | |
4503 | goto error_return; | |
7619e7c7 | 4504 | |
d7128ce4 | 4505 | htab = ppc_elf_hash_table (link_info); |
25dbc73a | 4506 | irelend = internal_relocs + isec->reloc_count; |
7619e7c7 | 4507 | |
25dbc73a | 4508 | for (irel = internal_relocs; irel < irelend; irel++) |
7619e7c7 | 4509 | { |
25dbc73a AM |
4510 | unsigned long r_type = ELF32_R_TYPE (irel->r_info); |
4511 | bfd_vma symaddr, reladdr, toff, roff; | |
4512 | asection *tsec; | |
4513 | struct one_fixup *f; | |
4514 | size_t insn_offset = 0; | |
4515 | bfd_vma max_branch_offset, val; | |
4516 | bfd_byte *hit_addr; | |
4517 | unsigned long t0; | |
4518 | unsigned char sym_type; | |
7619e7c7 | 4519 | |
25dbc73a AM |
4520 | switch (r_type) |
4521 | { | |
4522 | case R_PPC_REL24: | |
4523 | case R_PPC_LOCAL24PC: | |
4524 | case R_PPC_PLTREL24: | |
4525 | max_branch_offset = 1 << 25; | |
4526 | break; | |
7619e7c7 | 4527 | |
25dbc73a AM |
4528 | case R_PPC_REL14: |
4529 | case R_PPC_REL14_BRTAKEN: | |
4530 | case R_PPC_REL14_BRNTAKEN: | |
4531 | max_branch_offset = 1 << 15; | |
4532 | break; | |
7619e7c7 | 4533 | |
25dbc73a AM |
4534 | default: |
4535 | continue; | |
4536 | } | |
7619e7c7 | 4537 | |
25dbc73a AM |
4538 | /* Get the value of the symbol referred to by the reloc. */ |
4539 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) | |
4540 | { | |
4541 | /* A local symbol. */ | |
4542 | Elf_Internal_Sym *isym; | |
7fce784e | 4543 | |
25dbc73a AM |
4544 | /* Read this BFD's local symbols. */ |
4545 | if (isymbuf == NULL) | |
4546 | { | |
4547 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4548 | if (isymbuf == NULL) | |
4549 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
4550 | symtab_hdr->sh_info, 0, | |
4551 | NULL, NULL, NULL); | |
4552 | if (isymbuf == 0) | |
4553 | goto error_return; | |
4554 | } | |
4555 | isym = isymbuf + ELF32_R_SYM (irel->r_info); | |
4556 | if (isym->st_shndx == SHN_UNDEF) | |
4557 | continue; /* We can't do anything with undefined symbols. */ | |
4558 | else if (isym->st_shndx == SHN_ABS) | |
4559 | tsec = bfd_abs_section_ptr; | |
4560 | else if (isym->st_shndx == SHN_COMMON) | |
4561 | tsec = bfd_com_section_ptr; | |
4562 | else | |
4563 | tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
7fce784e | 4564 | |
25dbc73a AM |
4565 | toff = isym->st_value; |
4566 | sym_type = ELF_ST_TYPE (isym->st_info); | |
4567 | } | |
4568 | else | |
4569 | { | |
4570 | /* Global symbol handling. */ | |
4571 | unsigned long indx; | |
4572 | struct elf_link_hash_entry *h; | |
7619e7c7 | 4573 | |
25dbc73a AM |
4574 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
4575 | h = elf_sym_hashes (abfd)[indx]; | |
7619e7c7 | 4576 | |
25dbc73a AM |
4577 | while (h->root.type == bfd_link_hash_indirect |
4578 | || h->root.type == bfd_link_hash_warning) | |
4579 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7619e7c7 | 4580 | |
25dbc73a | 4581 | if (r_type == R_PPC_PLTREL24 |
d7128ce4 | 4582 | && htab->plt != NULL |
25dbc73a AM |
4583 | && h->plt.offset != (bfd_vma) -1) |
4584 | { | |
d7128ce4 AM |
4585 | if (!htab->old_plt) |
4586 | { | |
4587 | tsec = htab->glink; | |
4588 | toff = h->plt.offset * (GLINK_ENTRY_SIZE / 4); | |
4589 | } | |
4590 | else | |
4591 | { | |
4592 | tsec = htab->plt; | |
4593 | toff = h->plt.offset; | |
4594 | } | |
25dbc73a AM |
4595 | } |
4596 | else if (h->root.type == bfd_link_hash_defined | |
4597 | || h->root.type == bfd_link_hash_defweak) | |
4598 | { | |
4599 | tsec = h->root.u.def.section; | |
4600 | toff = h->root.u.def.value; | |
4601 | } | |
4602 | else | |
4603 | continue; | |
7619e7c7 | 4604 | |
25dbc73a AM |
4605 | sym_type = h->type; |
4606 | } | |
7619e7c7 | 4607 | |
25dbc73a AM |
4608 | /* If the branch and target are in the same section, you have |
4609 | no hope of adding stubs. We'll error out later should the | |
4610 | branch overflow. */ | |
4611 | if (tsec == isec) | |
4612 | continue; | |
4613 | ||
4614 | /* There probably isn't any reason to handle symbols in | |
4615 | SEC_MERGE sections; SEC_MERGE doesn't seem a likely | |
4616 | attribute for a code section, and we are only looking at | |
4617 | branches. However, implement it correctly here as a | |
4618 | reference for other target relax_section functions. */ | |
4619 | if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE) | |
4620 | { | |
4621 | /* At this stage in linking, no SEC_MERGE symbol has been | |
4622 | adjusted, so all references to such symbols need to be | |
4623 | passed through _bfd_merged_section_offset. (Later, in | |
4624 | relocate_section, all SEC_MERGE symbols *except* for | |
4625 | section symbols have been adjusted.) | |
4626 | ||
4627 | gas may reduce relocations against symbols in SEC_MERGE | |
4628 | sections to a relocation against the section symbol when | |
4629 | the original addend was zero. When the reloc is against | |
4630 | a section symbol we should include the addend in the | |
4631 | offset passed to _bfd_merged_section_offset, since the | |
4632 | location of interest is the original symbol. On the | |
4633 | other hand, an access to "sym+addend" where "sym" is not | |
4634 | a section symbol should not include the addend; Such an | |
4635 | access is presumed to be an offset from "sym"; The | |
4636 | location of interest is just "sym". */ | |
4637 | if (sym_type == STT_SECTION) | |
4638 | toff += irel->r_addend; | |
7619e7c7 | 4639 | |
25dbc73a AM |
4640 | toff = _bfd_merged_section_offset (abfd, &tsec, |
4641 | elf_section_data (tsec)->sec_info, | |
4642 | toff); | |
7619e7c7 | 4643 | |
25dbc73a AM |
4644 | if (sym_type != STT_SECTION) |
4645 | toff += irel->r_addend; | |
4646 | } | |
4647 | else | |
4648 | toff += irel->r_addend; | |
7619e7c7 | 4649 | |
25dbc73a | 4650 | symaddr = tsec->output_section->vma + tsec->output_offset + toff; |
7619e7c7 | 4651 | |
25dbc73a AM |
4652 | roff = irel->r_offset; |
4653 | reladdr = isec->output_section->vma + isec->output_offset + roff; | |
7619e7c7 | 4654 | |
25dbc73a AM |
4655 | /* If the branch is in range, no need to do anything. */ |
4656 | if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset) | |
4657 | continue; | |
252b5132 | 4658 | |
25dbc73a AM |
4659 | /* Look for an existing fixup to this address. */ |
4660 | for (f = fixups; f ; f = f->next) | |
4661 | if (f->tsec == tsec && f->toff == toff) | |
4662 | break; | |
4663 | ||
4664 | if (f == NULL) | |
7619e7c7 | 4665 | { |
25dbc73a AM |
4666 | size_t size; |
4667 | unsigned long stub_rtype; | |
252b5132 | 4668 | |
25dbc73a AM |
4669 | val = trampoff - roff; |
4670 | if (val >= max_branch_offset) | |
4671 | /* Oh dear, we can't reach a trampoline. Don't try to add | |
4672 | one. We'll report an error later. */ | |
4673 | continue; | |
252b5132 | 4674 | |
25dbc73a AM |
4675 | if (link_info->shared) |
4676 | { | |
4677 | size = 4 * ARRAY_SIZE (shared_stub_entry); | |
4678 | insn_offset = 12; | |
4679 | stub_rtype = R_PPC_RELAX32PC; | |
4680 | } | |
4681 | else | |
4682 | { | |
4683 | size = 4 * ARRAY_SIZE (stub_entry); | |
4684 | insn_offset = 0; | |
4685 | stub_rtype = R_PPC_RELAX32; | |
4686 | } | |
dc810e39 | 4687 | |
25dbc73a AM |
4688 | if (R_PPC_RELAX32_PLT - R_PPC_RELAX32 |
4689 | != R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC) | |
4690 | abort (); | |
d7128ce4 AM |
4691 | if (tsec == htab->plt |
4692 | || tsec == htab->glink) | |
25dbc73a | 4693 | stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32; |
252b5132 | 4694 | |
25dbc73a AM |
4695 | /* Hijack the old relocation. Since we need two |
4696 | relocations for this use a "composite" reloc. */ | |
4697 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
4698 | stub_rtype); | |
4699 | irel->r_offset = trampoff + insn_offset; | |
252b5132 | 4700 | |
25dbc73a AM |
4701 | /* Record the fixup so we don't do it again this section. */ |
4702 | f = bfd_malloc (sizeof (*f)); | |
4703 | f->next = fixups; | |
4704 | f->tsec = tsec; | |
4705 | f->toff = toff; | |
4706 | f->trampoff = trampoff; | |
4707 | fixups = f; | |
252b5132 | 4708 | |
25dbc73a AM |
4709 | trampoff += size; |
4710 | } | |
4711 | else | |
4712 | { | |
4713 | val = f->trampoff - roff; | |
4714 | if (val >= max_branch_offset) | |
4715 | continue; | |
252b5132 | 4716 | |
25dbc73a AM |
4717 | /* Nop out the reloc, since we're finalizing things here. */ |
4718 | irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); | |
4719 | } | |
252b5132 | 4720 | |
25dbc73a AM |
4721 | /* Get the section contents. */ |
4722 | if (contents == NULL) | |
4723 | { | |
4724 | /* Get cached copy if it exists. */ | |
4725 | if (elf_section_data (isec)->this_hdr.contents != NULL) | |
4726 | contents = elf_section_data (isec)->this_hdr.contents; | |
4727 | else | |
4728 | { | |
4729 | /* Go get them off disk. */ | |
4730 | if (!bfd_malloc_and_get_section (abfd, isec, &contents)) | |
4731 | goto error_return; | |
4732 | } | |
4733 | } | |
252b5132 | 4734 | |
25dbc73a AM |
4735 | /* Fix up the existing branch to hit the trampoline. */ |
4736 | hit_addr = contents + roff; | |
4737 | switch (r_type) | |
4738 | { | |
4739 | case R_PPC_REL24: | |
4740 | case R_PPC_LOCAL24PC: | |
4741 | case R_PPC_PLTREL24: | |
4742 | t0 = bfd_get_32 (abfd, hit_addr); | |
4743 | t0 &= ~0x3fffffc; | |
4744 | t0 |= val & 0x3fffffc; | |
4745 | bfd_put_32 (abfd, t0, hit_addr); | |
4746 | break; | |
252b5132 | 4747 | |
25dbc73a AM |
4748 | case R_PPC_REL14: |
4749 | case R_PPC_REL14_BRTAKEN: | |
4750 | case R_PPC_REL14_BRNTAKEN: | |
4751 | t0 = bfd_get_32 (abfd, hit_addr); | |
4752 | t0 &= ~0xfffc; | |
4753 | t0 |= val & 0xfffc; | |
4754 | bfd_put_32 (abfd, t0, hit_addr); | |
4755 | break; | |
4756 | } | |
4757 | } | |
252b5132 | 4758 | |
25dbc73a AM |
4759 | /* Write out the trampolines. */ |
4760 | changed = fixups != NULL; | |
4761 | if (fixups != NULL) | |
4762 | { | |
4763 | const int *stub; | |
4764 | bfd_byte *dest; | |
4765 | bfd_vma val; | |
4766 | int i, size; | |
252b5132 | 4767 | |
25dbc73a AM |
4768 | do |
4769 | { | |
4770 | struct one_fixup *f = fixups; | |
4771 | fixups = fixups->next; | |
4772 | free (f); | |
4773 | } | |
4774 | while (fixups); | |
252b5132 | 4775 | |
25dbc73a AM |
4776 | contents = bfd_realloc (contents, trampoff); |
4777 | if (contents == NULL) | |
4778 | goto error_return; | |
252b5132 | 4779 | |
25dbc73a AM |
4780 | isec->size = (isec->size + 3) & (bfd_vma) -4; |
4781 | /* Branch around the trampolines. */ | |
4782 | val = trampoff - isec->size + 0x48000000; | |
4783 | dest = contents + isec->size; | |
4784 | isec->size = trampoff; | |
4785 | bfd_put_32 (abfd, val, dest); | |
4786 | dest += 4; | |
252b5132 | 4787 | |
25dbc73a AM |
4788 | if (link_info->shared) |
4789 | { | |
4790 | stub = shared_stub_entry; | |
4791 | size = ARRAY_SIZE (shared_stub_entry); | |
4792 | } | |
4793 | else | |
4794 | { | |
4795 | stub = stub_entry; | |
4796 | size = ARRAY_SIZE (stub_entry); | |
4797 | } | |
252b5132 | 4798 | |
25dbc73a AM |
4799 | i = 0; |
4800 | while (dest < contents + trampoff) | |
252b5132 | 4801 | { |
25dbc73a AM |
4802 | bfd_put_32 (abfd, stub[i], dest); |
4803 | i++; | |
4804 | if (i == size) | |
4805 | i = 0; | |
4806 | dest += 4; | |
252b5132 | 4807 | } |
25dbc73a | 4808 | BFD_ASSERT (i == 0); |
252b5132 RH |
4809 | } |
4810 | ||
25dbc73a AM |
4811 | if (isymbuf != NULL |
4812 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
252b5132 | 4813 | { |
25dbc73a AM |
4814 | if (! link_info->keep_memory) |
4815 | free (isymbuf); | |
252b5132 | 4816 | else |
25dbc73a AM |
4817 | { |
4818 | /* Cache the symbols for elf_link_input_bfd. */ | |
4819 | symtab_hdr->contents = (unsigned char *) isymbuf; | |
4820 | } | |
252b5132 RH |
4821 | } |
4822 | ||
25dbc73a AM |
4823 | if (contents != NULL |
4824 | && elf_section_data (isec)->this_hdr.contents != contents) | |
4825 | { | |
4826 | if (!changed && !link_info->keep_memory) | |
4827 | free (contents); | |
4828 | else | |
4829 | { | |
4830 | /* Cache the section contents for elf_link_input_bfd. */ | |
4831 | elf_section_data (isec)->this_hdr.contents = contents; | |
4832 | } | |
4833 | } | |
252b5132 | 4834 | |
25dbc73a AM |
4835 | if (elf_section_data (isec)->relocs != internal_relocs) |
4836 | { | |
4837 | if (!changed) | |
4838 | free (internal_relocs); | |
4839 | else | |
4840 | elf_section_data (isec)->relocs = internal_relocs; | |
4841 | } | |
252b5132 | 4842 | |
25dbc73a | 4843 | *again = changed; |
b34976b6 | 4844 | return TRUE; |
25dbc73a AM |
4845 | |
4846 | error_return: | |
4847 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents) | |
4848 | free (isymbuf); | |
4849 | if (contents != NULL | |
4850 | && elf_section_data (isec)->this_hdr.contents != contents) | |
4851 | free (contents); | |
4852 | if (internal_relocs != NULL | |
4853 | && elf_section_data (isec)->relocs != internal_relocs) | |
4854 | free (internal_relocs); | |
4855 | return FALSE; | |
252b5132 | 4856 | } |
252b5132 | 4857 | \f |
f85f57ad AM |
4858 | /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms. They are |
4859 | set here rather than via PROVIDE in the default linker script, | |
4860 | because using PROVIDE inside an output section statement results in | |
4861 | unnecessary output sections. Using PROVIDE outside an output section | |
4862 | statement runs the risk of section alignment affecting where the | |
4863 | section starts. */ | |
c9a2f333 AM |
4864 | |
4865 | bfd_boolean | |
4866 | ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info) | |
4867 | { | |
4868 | struct ppc_elf_link_hash_table *htab; | |
4869 | unsigned i; | |
f85f57ad AM |
4870 | asection *s; |
4871 | bfd_vma val; | |
c9a2f333 AM |
4872 | |
4873 | htab = ppc_elf_hash_table (info); | |
4874 | ||
4875 | for (i = 0; i < 2; i++) | |
4876 | { | |
4877 | elf_linker_section_t *lsect = &htab->sdata[i]; | |
c9a2f333 AM |
4878 | |
4879 | s = lsect->section; | |
4880 | if (s != NULL) | |
4881 | s = s->output_section; | |
4882 | if (s == NULL) | |
4883 | s = bfd_get_section_by_name (obfd, lsect->name); | |
4884 | if (s == NULL) | |
4885 | s = bfd_get_section_by_name (obfd, lsect->bss_name); | |
4886 | ||
4887 | val = 0; | |
4888 | if (s != NULL) | |
4889 | val = s->vma + 32768; | |
4890 | lsect->sym_val = val; | |
4891 | ||
81e1b023 | 4892 | _bfd_elf_provide_symbol (info, lsect->sym_name, val); |
c9a2f333 | 4893 | } |
f85f57ad AM |
4894 | |
4895 | s = bfd_get_section_by_name (obfd, ".sbss"); | |
4896 | val = 0; | |
4897 | if (s != NULL) | |
4898 | val = s->vma; | |
81e1b023 L |
4899 | _bfd_elf_provide_symbol (info, "__sbss_start", val); |
4900 | _bfd_elf_provide_symbol (info, "___sbss_start", val); | |
f85f57ad AM |
4901 | if (s != NULL) |
4902 | val += s->size; | |
81e1b023 L |
4903 | _bfd_elf_provide_symbol (info, "__sbss_end", val); |
4904 | _bfd_elf_provide_symbol (info, "___sbss_end", val); | |
c9a2f333 AM |
4905 | return TRUE; |
4906 | } | |
4907 | \f | |
25dbc73a | 4908 | /* Fill in the address for a pointer generated in a linker section. */ |
252b5132 | 4909 | |
25dbc73a | 4910 | static bfd_vma |
76750a2f | 4911 | elf_finish_pointer_linker_section (bfd *input_bfd, |
25dbc73a AM |
4912 | elf_linker_section_t *lsect, |
4913 | struct elf_link_hash_entry *h, | |
4914 | bfd_vma relocation, | |
2bb04cf2 | 4915 | const Elf_Internal_Rela *rel) |
25dbc73a AM |
4916 | { |
4917 | elf_linker_section_pointers_t *linker_section_ptr; | |
252b5132 | 4918 | |
25dbc73a | 4919 | BFD_ASSERT (lsect != NULL); |
252b5132 | 4920 | |
25dbc73a | 4921 | if (h != NULL) |
252b5132 | 4922 | { |
25dbc73a AM |
4923 | /* Handle global symbol. */ |
4924 | struct ppc_elf_link_hash_entry *eh; | |
252b5132 | 4925 | |
25dbc73a | 4926 | eh = (struct ppc_elf_link_hash_entry *) h; |
76750a2f AM |
4927 | BFD_ASSERT (eh->elf.def_regular); |
4928 | linker_section_ptr = eh->linker_section_pointer; | |
25dbc73a AM |
4929 | } |
4930 | else | |
4931 | { | |
4932 | /* Handle local symbol. */ | |
4933 | unsigned long r_symndx = ELF32_R_SYM (rel->r_info); | |
76750a2f | 4934 | |
25dbc73a | 4935 | BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); |
76750a2f AM |
4936 | linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx]; |
4937 | } | |
252b5132 | 4938 | |
76750a2f AM |
4939 | linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr, |
4940 | rel->r_addend, | |
4941 | lsect); | |
4942 | BFD_ASSERT (linker_section_ptr != NULL); | |
25dbc73a | 4943 | |
76750a2f AM |
4944 | /* Offset will always be a multiple of four, so use the bottom bit |
4945 | as a "written" flag. */ | |
4946 | if ((linker_section_ptr->offset & 1) == 0) | |
4947 | { | |
4948 | bfd_put_32 (lsect->section->owner, | |
4949 | relocation + linker_section_ptr->addend, | |
4950 | lsect->section->contents + linker_section_ptr->offset); | |
4951 | linker_section_ptr->offset += 1; | |
252b5132 RH |
4952 | } |
4953 | ||
25dbc73a | 4954 | relocation = (lsect->section->output_offset |
76750a2f | 4955 | + linker_section_ptr->offset - 1 |
c9a2f333 | 4956 | - 0x8000); |
252b5132 | 4957 | |
25dbc73a AM |
4958 | #ifdef DEBUG |
4959 | fprintf (stderr, | |
4960 | "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", | |
4961 | lsect->name, (long) relocation, (long) relocation); | |
4962 | #endif | |
252b5132 | 4963 | |
25dbc73a AM |
4964 | /* Subtract out the addend, because it will get added back in by the normal |
4965 | processing. */ | |
4966 | return relocation - linker_section_ptr->addend; | |
252b5132 | 4967 | } |
25dbc73a | 4968 | |
252b5132 RH |
4969 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
4970 | to handle the relocations for a section. | |
4971 | ||
4972 | The relocs are always passed as Rela structures; if the section | |
4973 | actually uses Rel structures, the r_addend field will always be | |
4974 | zero. | |
4975 | ||
4976 | This function is responsible for adjust the section contents as | |
4977 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 4978 | relocatable output file) adjusting the reloc addend as |
252b5132 RH |
4979 | necessary. |
4980 | ||
4981 | This function does not have to worry about setting the reloc | |
4982 | address or the reloc symbol index. | |
4983 | ||
4984 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
4985 | ||
4986 | LOCAL_SECTIONS is an array giving the section in the input file | |
4987 | corresponding to the st_shndx field of each local symbol. | |
4988 | ||
4989 | The global hash table entry for the global symbols can be found | |
4990 | via elf_sym_hashes (input_bfd). | |
4991 | ||
1049f94e | 4992 | When generating relocatable output, this function must handle |
252b5132 RH |
4993 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
4994 | going to be the section symbol corresponding to the output | |
4995 | section, which means that the addend must be adjusted | |
4996 | accordingly. */ | |
4997 | ||
b34976b6 | 4998 | static bfd_boolean |
55fd94b0 AM |
4999 | ppc_elf_relocate_section (bfd *output_bfd, |
5000 | struct bfd_link_info *info, | |
5001 | bfd *input_bfd, | |
5002 | asection *input_section, | |
5003 | bfd_byte *contents, | |
5004 | Elf_Internal_Rela *relocs, | |
5005 | Elf_Internal_Sym *local_syms, | |
5006 | asection **local_sections) | |
252b5132 | 5007 | { |
7619e7c7 AM |
5008 | Elf_Internal_Shdr *symtab_hdr; |
5009 | struct elf_link_hash_entry **sym_hashes; | |
5010 | struct ppc_elf_link_hash_table *htab; | |
5011 | Elf_Internal_Rela *rel; | |
5012 | Elf_Internal_Rela *relend; | |
5013 | Elf_Internal_Rela outrel; | |
5014 | bfd_byte *loc; | |
b34976b6 | 5015 | asection *sreloc = NULL; |
252b5132 | 5016 | bfd_vma *local_got_offsets; |
b34976b6 | 5017 | bfd_boolean ret = TRUE; |
b34976b6 | 5018 | |
252b5132 | 5019 | #ifdef DEBUG |
d003868e AM |
5020 | _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, " |
5021 | "%ld relocations%s", | |
5022 | input_bfd, input_section, | |
5023 | (long) input_section->reloc_count, | |
5024 | (info->relocatable) ? " (relocatable)" : ""); | |
252b5132 RH |
5025 | #endif |
5026 | ||
1049f94e | 5027 | if (info->relocatable) |
b34976b6 | 5028 | return TRUE; |
b491616a | 5029 | |
e47cd125 | 5030 | /* Initialize howto table if not already done. */ |
8da6118f | 5031 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
252b5132 RH |
5032 | ppc_elf_howto_init (); |
5033 | ||
7619e7c7 | 5034 | htab = ppc_elf_hash_table (info); |
252b5132 | 5035 | local_got_offsets = elf_local_got_offsets (input_bfd); |
7619e7c7 AM |
5036 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
5037 | sym_hashes = elf_sym_hashes (input_bfd); | |
5038 | rel = relocs; | |
5039 | relend = relocs + input_section->reloc_count; | |
252b5132 RH |
5040 | for (; rel < relend; rel++) |
5041 | { | |
7619e7c7 AM |
5042 | enum elf_ppc_reloc_type r_type; |
5043 | bfd_vma addend; | |
5044 | bfd_reloc_status_type r; | |
5045 | Elf_Internal_Sym *sym; | |
5046 | asection *sec; | |
5047 | struct elf_link_hash_entry *h; | |
5048 | const char *sym_name; | |
252b5132 RH |
5049 | reloc_howto_type *howto; |
5050 | unsigned long r_symndx; | |
5051 | bfd_vma relocation; | |
7619e7c7 | 5052 | bfd_vma branch_bit, insn, from; |
7619e7c7 AM |
5053 | bfd_boolean unresolved_reloc; |
5054 | bfd_boolean warned; | |
5055 | unsigned int tls_type, tls_mask, tls_gd; | |
5056 | ||
55fd94b0 AM |
5057 | r_type = ELF32_R_TYPE (rel->r_info); |
5058 | sym = NULL; | |
5059 | sec = NULL; | |
5060 | h = NULL; | |
7619e7c7 AM |
5061 | unresolved_reloc = FALSE; |
5062 | warned = FALSE; | |
252b5132 | 5063 | r_symndx = ELF32_R_SYM (rel->r_info); |
560e09e9 | 5064 | |
252b5132 RH |
5065 | if (r_symndx < symtab_hdr->sh_info) |
5066 | { | |
5067 | sym = local_syms + r_symndx; | |
5068 | sec = local_sections[r_symndx]; | |
26c61ae5 | 5069 | sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec); |
252b5132 | 5070 | |
8517fae7 | 5071 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
252b5132 RH |
5072 | } |
5073 | else | |
5074 | { | |
b2a8e766 AM |
5075 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
5076 | r_symndx, symtab_hdr, sym_hashes, | |
5077 | h, sec, relocation, | |
5078 | unresolved_reloc, warned); | |
9abc968f | 5079 | |
252b5132 | 5080 | sym_name = h->root.root.string; |
7619e7c7 AM |
5081 | } |
5082 | ||
5083 | /* TLS optimizations. Replace instruction sequences and relocs | |
5084 | based on information we collected in tls_optimize. We edit | |
5085 | RELOCS so that --emit-relocs will output something sensible | |
5086 | for the final instruction stream. */ | |
5087 | tls_mask = 0; | |
5088 | tls_gd = 0; | |
5089 | if (IS_PPC_TLS_RELOC (r_type)) | |
5090 | { | |
5091 | if (h != NULL) | |
5092 | tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask; | |
5093 | else if (local_got_offsets != NULL) | |
5094 | { | |
5095 | char *lgot_masks; | |
5096 | lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info); | |
5097 | tls_mask = lgot_masks[r_symndx]; | |
5098 | } | |
5099 | } | |
5100 | ||
5101 | /* Ensure reloc mapping code below stays sane. */ | |
5102 | if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3) | |
5103 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3) | |
5104 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3) | |
5105 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3) | |
5106 | || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3) | |
5107 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3) | |
5108 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3) | |
5109 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3)) | |
5110 | abort (); | |
5111 | switch (r_type) | |
5112 | { | |
5113 | default: | |
5114 | break; | |
5115 | ||
5116 | case R_PPC_GOT_TPREL16: | |
5117 | case R_PPC_GOT_TPREL16_LO: | |
5118 | if (tls_mask != 0 | |
5119 | && (tls_mask & TLS_TPREL) == 0) | |
5120 | { | |
5121 | bfd_vma insn; | |
5122 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); | |
5123 | insn &= 31 << 21; | |
5124 | insn |= 0x3c020000; /* addis 0,2,0 */ | |
5125 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
5126 | r_type = R_PPC_TPREL16_HA; | |
5127 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
5128 | } | |
5129 | break; | |
5130 | ||
5131 | case R_PPC_TLS: | |
5132 | if (tls_mask != 0 | |
5133 | && (tls_mask & TLS_TPREL) == 0) | |
5134 | { | |
5135 | bfd_vma insn, rtra; | |
5136 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
5137 | if ((insn & ((31 << 26) | (31 << 11))) | |
5138 | == ((31 << 26) | (2 << 11))) | |
5139 | rtra = insn & ((1 << 26) - (1 << 16)); | |
5140 | else if ((insn & ((31 << 26) | (31 << 16))) | |
5141 | == ((31 << 26) | (2 << 16))) | |
5142 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
5143 | else | |
5144 | abort (); | |
5145 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
5146 | /* add -> addi. */ | |
5147 | insn = 14 << 26; | |
5148 | else if ((insn & (31 << 1)) == 23 << 1 | |
5149 | && ((insn & (31 << 6)) < 14 << 6 | |
5150 | || ((insn & (31 << 6)) >= 16 << 6 | |
5151 | && (insn & (31 << 6)) < 24 << 6))) | |
5152 | /* load and store indexed -> dform. */ | |
5153 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
5154 | else if ((insn & (31 << 1)) == 21 << 1 | |
5155 | && (insn & (0x1a << 6)) == 0) | |
5156 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
5157 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
5158 | | ((insn >> 6) & 1)); | |
5159 | else if ((insn & (31 << 1)) == 21 << 1 | |
5160 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
5161 | /* lwax -> lwa. */ | |
5162 | insn = (58 << 26) | 2; | |
5163 | else | |
5164 | abort (); | |
5165 | insn |= rtra; | |
5166 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
5167 | r_type = R_PPC_TPREL16_LO; | |
5168 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
5169 | /* Was PPC_TLS which sits on insn boundary, now | |
5170 | PPC_TPREL16_LO which is at insn+2. */ | |
5171 | rel->r_offset += 2; | |
5172 | } | |
5173 | break; | |
5174 | ||
5175 | case R_PPC_GOT_TLSGD16_HI: | |
5176 | case R_PPC_GOT_TLSGD16_HA: | |
5177 | tls_gd = TLS_TPRELGD; | |
5178 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
5179 | goto tls_gdld_hi; | |
5180 | break; | |
5181 | ||
5182 | case R_PPC_GOT_TLSLD16_HI: | |
5183 | case R_PPC_GOT_TLSLD16_HA: | |
5184 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
5185 | { | |
5186 | tls_gdld_hi: | |
5187 | if ((tls_mask & tls_gd) != 0) | |
5188 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
5189 | + R_PPC_GOT_TPREL16); | |
5190 | else | |
5191 | { | |
5192 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); | |
5193 | rel->r_offset -= 2; | |
5194 | r_type = R_PPC_NONE; | |
5195 | } | |
5196 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
5197 | } | |
5198 | break; | |
5199 | ||
5200 | case R_PPC_GOT_TLSGD16: | |
5201 | case R_PPC_GOT_TLSGD16_LO: | |
5202 | tls_gd = TLS_TPRELGD; | |
5203 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
5204 | goto tls_get_addr_check; | |
5205 | break; | |
5206 | ||
5207 | case R_PPC_GOT_TLSLD16: | |
5208 | case R_PPC_GOT_TLSLD16_LO: | |
5209 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
5210 | { | |
5211 | tls_get_addr_check: | |
5212 | if (rel + 1 < relend) | |
5213 | { | |
5214 | enum elf_ppc_reloc_type r_type2; | |
5215 | unsigned long r_symndx2; | |
5216 | struct elf_link_hash_entry *h2; | |
87d243f1 | 5217 | bfd_vma insn1, insn2; |
7619e7c7 AM |
5218 | bfd_vma offset; |
5219 | ||
5220 | /* The next instruction should be a call to | |
5221 | __tls_get_addr. Peek at the reloc to be sure. */ | |
55fd94b0 | 5222 | r_type2 = ELF32_R_TYPE (rel[1].r_info); |
7619e7c7 AM |
5223 | r_symndx2 = ELF32_R_SYM (rel[1].r_info); |
5224 | if (r_symndx2 < symtab_hdr->sh_info | |
5225 | || (r_type2 != R_PPC_REL14 | |
5226 | && r_type2 != R_PPC_REL14_BRTAKEN | |
5227 | && r_type2 != R_PPC_REL14_BRNTAKEN | |
5228 | && r_type2 != R_PPC_REL24 | |
5229 | && r_type2 != R_PPC_PLTREL24)) | |
5230 | break; | |
5231 | ||
5232 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
5233 | while (h2->root.type == bfd_link_hash_indirect | |
5234 | || h2->root.type == bfd_link_hash_warning) | |
5235 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
5236 | if (h2 == NULL || h2 != htab->tls_get_addr) | |
5237 | break; | |
5238 | ||
5239 | /* OK, it checks out. Replace the call. */ | |
5240 | offset = rel[1].r_offset; | |
5241 | insn1 = bfd_get_32 (output_bfd, | |
5242 | contents + rel->r_offset - 2); | |
7619e7c7 AM |
5243 | if ((tls_mask & tls_gd) != 0) |
5244 | { | |
5245 | /* IE */ | |
5246 | insn1 &= (1 << 26) - 1; | |
5247 | insn1 |= 32 << 26; /* lwz */ | |
5248 | insn2 = 0x7c631214; /* add 3,3,2 */ | |
5249 | rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE); | |
5250 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
5251 | + R_PPC_GOT_TPREL16); | |
5252 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
5253 | } | |
5254 | else | |
5255 | { | |
5256 | /* LE */ | |
5257 | insn1 = 0x3c620000; /* addis 3,2,0 */ | |
5258 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
5259 | if (tls_gd == 0) | |
5260 | { | |
5261 | /* Was an LD reloc. */ | |
5262 | r_symndx = 0; | |
e1918d23 AM |
5263 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
5264 | rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; | |
7619e7c7 AM |
5265 | } |
5266 | r_type = R_PPC_TPREL16_HA; | |
5267 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
5268 | rel[1].r_info = ELF32_R_INFO (r_symndx, | |
5269 | R_PPC_TPREL16_LO); | |
5270 | rel[1].r_offset += 2; | |
5271 | } | |
7619e7c7 AM |
5272 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); |
5273 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7619e7c7 AM |
5274 | if (tls_gd == 0) |
5275 | { | |
5276 | /* We changed the symbol on an LD reloc. Start over | |
70bccea4 | 5277 | in order to get h, sym, sec etc. right. */ |
7619e7c7 AM |
5278 | rel--; |
5279 | continue; | |
5280 | } | |
5281 | } | |
252b5132 | 5282 | } |
7619e7c7 AM |
5283 | break; |
5284 | } | |
5285 | ||
5286 | /* Handle other relocations that tweak non-addend part of insn. */ | |
5287 | branch_bit = 0; | |
5288 | switch (r_type) | |
5289 | { | |
5290 | default: | |
5291 | break; | |
5292 | ||
5293 | /* Branch taken prediction relocations. */ | |
5294 | case R_PPC_ADDR14_BRTAKEN: | |
5295 | case R_PPC_REL14_BRTAKEN: | |
5296 | branch_bit = BRANCH_PREDICT_BIT; | |
5297 | /* Fall thru */ | |
5298 | ||
4cc11e76 | 5299 | /* Branch not taken prediction relocations. */ |
7619e7c7 AM |
5300 | case R_PPC_ADDR14_BRNTAKEN: |
5301 | case R_PPC_REL14_BRNTAKEN: | |
5302 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
5303 | insn &= ~BRANCH_PREDICT_BIT; | |
5304 | insn |= branch_bit; | |
5305 | ||
5306 | from = (rel->r_offset | |
5307 | + input_section->output_offset | |
5308 | + input_section->output_section->vma); | |
5309 | ||
5310 | /* Invert 'y' bit if not the default. */ | |
5311 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
5312 | insn ^= BRANCH_PREDICT_BIT; | |
5313 | ||
5314 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
5315 | break; | |
252b5132 RH |
5316 | } |
5317 | ||
7619e7c7 AM |
5318 | addend = rel->r_addend; |
5319 | tls_type = 0; | |
5320 | howto = NULL; | |
55fd94b0 AM |
5321 | if (r_type < R_PPC_max) |
5322 | howto = ppc_elf_howto_table[r_type]; | |
7619e7c7 | 5323 | switch (r_type) |
252b5132 RH |
5324 | { |
5325 | default: | |
7619e7c7 | 5326 | (*_bfd_error_handler) |
d003868e AM |
5327 | (_("%B: unknown relocation type %d for symbol %s"), |
5328 | input_bfd, (int) r_type, sym_name); | |
252b5132 RH |
5329 | |
5330 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5331 | ret = FALSE; |
252b5132 RH |
5332 | continue; |
5333 | ||
7619e7c7 AM |
5334 | case R_PPC_NONE: |
5335 | case R_PPC_TLS: | |
5336 | case R_PPC_EMB_MRKREF: | |
5337 | case R_PPC_GNU_VTINHERIT: | |
5338 | case R_PPC_GNU_VTENTRY: | |
7595d193 L |
5339 | continue; |
5340 | ||
7619e7c7 AM |
5341 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
5342 | address in the GOT as relocation value instead of the | |
5343 | symbol's value itself. Also, create a GOT entry for the | |
5344 | symbol and put the symbol value there. */ | |
5345 | case R_PPC_GOT_TLSGD16: | |
5346 | case R_PPC_GOT_TLSGD16_LO: | |
5347 | case R_PPC_GOT_TLSGD16_HI: | |
5348 | case R_PPC_GOT_TLSGD16_HA: | |
5349 | tls_type = TLS_TLS | TLS_GD; | |
5350 | goto dogot; | |
5351 | ||
5352 | case R_PPC_GOT_TLSLD16: | |
5353 | case R_PPC_GOT_TLSLD16_LO: | |
5354 | case R_PPC_GOT_TLSLD16_HI: | |
5355 | case R_PPC_GOT_TLSLD16_HA: | |
5356 | tls_type = TLS_TLS | TLS_LD; | |
5357 | goto dogot; | |
5358 | ||
5359 | case R_PPC_GOT_TPREL16: | |
5360 | case R_PPC_GOT_TPREL16_LO: | |
5361 | case R_PPC_GOT_TPREL16_HI: | |
5362 | case R_PPC_GOT_TPREL16_HA: | |
5363 | tls_type = TLS_TLS | TLS_TPREL; | |
5364 | goto dogot; | |
5365 | ||
5366 | case R_PPC_GOT_DTPREL16: | |
5367 | case R_PPC_GOT_DTPREL16_LO: | |
5368 | case R_PPC_GOT_DTPREL16_HI: | |
5369 | case R_PPC_GOT_DTPREL16_HA: | |
5370 | tls_type = TLS_TLS | TLS_DTPREL; | |
5371 | goto dogot; | |
5372 | ||
5373 | case R_PPC_GOT16: | |
5374 | case R_PPC_GOT16_LO: | |
5375 | case R_PPC_GOT16_HI: | |
5376 | case R_PPC_GOT16_HA: | |
5377 | dogot: | |
5378 | { | |
5379 | /* Relocation is to the entry for this symbol in the global | |
5380 | offset table. */ | |
5381 | bfd_vma off; | |
5382 | bfd_vma *offp; | |
5383 | unsigned long indx; | |
5384 | ||
5385 | if (htab->got == NULL) | |
5386 | abort (); | |
5387 | ||
5388 | indx = 0; | |
5389 | if (tls_type == (TLS_TLS | TLS_LD) | |
d881513a | 5390 | && (h == NULL |
f5385ebf | 5391 | || !h->def_dynamic)) |
7619e7c7 AM |
5392 | offp = &htab->tlsld_got.offset; |
5393 | else if (h != NULL) | |
5394 | { | |
5395 | bfd_boolean dyn; | |
5396 | dyn = htab->elf.dynamic_sections_created; | |
ee05f2fe | 5397 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
7619e7c7 AM |
5398 | || (info->shared |
5399 | && SYMBOL_REFERENCES_LOCAL (info, h))) | |
5400 | /* This is actually a static link, or it is a | |
5401 | -Bsymbolic link and the symbol is defined | |
5402 | locally, or the symbol was forced to be local | |
5403 | because of a version file. */ | |
5404 | ; | |
5405 | else | |
5406 | { | |
5407 | indx = h->dynindx; | |
5408 | unresolved_reloc = FALSE; | |
5409 | } | |
5410 | offp = &h->got.offset; | |
5411 | } | |
5412 | else | |
5413 | { | |
5414 | if (local_got_offsets == NULL) | |
5415 | abort (); | |
5416 | offp = &local_got_offsets[r_symndx]; | |
5417 | } | |
5418 | ||
5419 | /* The offset must always be a multiple of 4. We use the | |
5420 | least significant bit to record whether we have already | |
5421 | processed this entry. */ | |
5422 | off = *offp; | |
5423 | if ((off & 1) != 0) | |
5424 | off &= ~1; | |
5425 | else | |
5426 | { | |
70bccea4 AM |
5427 | unsigned int tls_m = (tls_mask |
5428 | & (TLS_LD | TLS_GD | TLS_DTPREL | |
5429 | | TLS_TPREL | TLS_TPRELGD)); | |
5430 | ||
5431 | if (offp == &htab->tlsld_got.offset) | |
5432 | tls_m = TLS_LD; | |
5433 | else if (h == NULL | |
f5385ebf | 5434 | || !h->def_dynamic) |
70bccea4 AM |
5435 | tls_m &= ~TLS_LD; |
5436 | ||
5437 | /* We might have multiple got entries for this sym. | |
5438 | Initialize them all. */ | |
5439 | do | |
7619e7c7 | 5440 | { |
70bccea4 AM |
5441 | int tls_ty = 0; |
5442 | ||
5443 | if ((tls_m & TLS_LD) != 0) | |
7619e7c7 | 5444 | { |
70bccea4 AM |
5445 | tls_ty = TLS_TLS | TLS_LD; |
5446 | tls_m &= ~TLS_LD; | |
5447 | } | |
5448 | else if ((tls_m & TLS_GD) != 0) | |
5449 | { | |
5450 | tls_ty = TLS_TLS | TLS_GD; | |
5451 | tls_m &= ~TLS_GD; | |
5452 | } | |
5453 | else if ((tls_m & TLS_DTPREL) != 0) | |
5454 | { | |
5455 | tls_ty = TLS_TLS | TLS_DTPREL; | |
5456 | tls_m &= ~TLS_DTPREL; | |
5457 | } | |
5458 | else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
5459 | { | |
5460 | tls_ty = TLS_TLS | TLS_TPREL; | |
5461 | tls_m = 0; | |
7619e7c7 | 5462 | } |
7619e7c7 | 5463 | |
70bccea4 | 5464 | /* Generate relocs for the dynamic linker. */ |
4e795f50 AM |
5465 | if ((info->shared || indx != 0) |
5466 | && (h == NULL | |
5467 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5468 | || h->root.type != bfd_link_hash_undefweak)) | |
7619e7c7 | 5469 | { |
70bccea4 AM |
5470 | outrel.r_offset = (htab->got->output_section->vma |
5471 | + htab->got->output_offset | |
5472 | + off); | |
e515b051 | 5473 | outrel.r_addend = 0; |
70bccea4 AM |
5474 | if (tls_ty & (TLS_LD | TLS_GD)) |
5475 | { | |
5476 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32); | |
70bccea4 AM |
5477 | if (tls_ty == (TLS_TLS | TLS_GD)) |
5478 | { | |
5479 | loc = htab->relgot->contents; | |
5480 | loc += (htab->relgot->reloc_count++ | |
5481 | * sizeof (Elf32_External_Rela)); | |
5482 | bfd_elf32_swap_reloca_out (output_bfd, | |
5483 | &outrel, loc); | |
e515b051 | 5484 | outrel.r_offset += 4; |
70bccea4 AM |
5485 | outrel.r_info |
5486 | = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
70bccea4 AM |
5487 | } |
5488 | } | |
5489 | else if (tls_ty == (TLS_TLS | TLS_DTPREL)) | |
5490 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
5491 | else if (tls_ty == (TLS_TLS | TLS_TPREL)) | |
5492 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32); | |
5493 | else if (indx == 0) | |
5494 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE); | |
5495 | else | |
5496 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT); | |
70bccea4 | 5497 | if (indx == 0) |
e515b051 AM |
5498 | { |
5499 | outrel.r_addend += relocation; | |
5500 | if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 5501 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 5502 | } |
70bccea4 AM |
5503 | loc = htab->relgot->contents; |
5504 | loc += (htab->relgot->reloc_count++ | |
5505 | * sizeof (Elf32_External_Rela)); | |
5506 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
7619e7c7 AM |
5507 | } |
5508 | ||
70bccea4 AM |
5509 | /* Init the .got section contents if we're not |
5510 | emitting a reloc. */ | |
5511 | else | |
7619e7c7 | 5512 | { |
70bccea4 AM |
5513 | bfd_vma value = relocation; |
5514 | ||
7b609f53 AM |
5515 | if (tls_ty == (TLS_TLS | TLS_LD)) |
5516 | value = 1; | |
5517 | else if (tls_ty != 0) | |
70bccea4 | 5518 | { |
e1918d23 | 5519 | value -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 5520 | if (tls_ty == (TLS_TLS | TLS_TPREL)) |
70bccea4 | 5521 | value += DTP_OFFSET - TP_OFFSET; |
70bccea4 | 5522 | |
7b609f53 AM |
5523 | if (tls_ty == (TLS_TLS | TLS_GD)) |
5524 | { | |
5525 | bfd_put_32 (output_bfd, value, | |
5526 | htab->got->contents + off + 4); | |
5527 | value = 1; | |
5528 | } | |
70bccea4 | 5529 | } |
70bccea4 AM |
5530 | bfd_put_32 (output_bfd, value, |
5531 | htab->got->contents + off); | |
7619e7c7 | 5532 | } |
70bccea4 AM |
5533 | |
5534 | off += 4; | |
5535 | if (tls_ty & (TLS_LD | TLS_GD)) | |
5536 | off += 4; | |
7619e7c7 | 5537 | } |
70bccea4 AM |
5538 | while (tls_m != 0); |
5539 | ||
5540 | off = *offp; | |
5541 | *offp = off | 1; | |
7619e7c7 AM |
5542 | } |
5543 | ||
5544 | if (off >= (bfd_vma) -2) | |
5545 | abort (); | |
5546 | ||
70bccea4 AM |
5547 | if ((tls_type & TLS_TLS) != 0) |
5548 | { | |
5549 | if (tls_type != (TLS_TLS | TLS_LD)) | |
5550 | { | |
5551 | if ((tls_mask & TLS_LD) != 0 | |
5552 | && !(h == NULL | |
f5385ebf | 5553 | || !h->def_dynamic)) |
70bccea4 AM |
5554 | off += 8; |
5555 | if (tls_type != (TLS_TLS | TLS_GD)) | |
5556 | { | |
5557 | if ((tls_mask & TLS_GD) != 0) | |
5558 | off += 8; | |
5559 | if (tls_type != (TLS_TLS | TLS_DTPREL)) | |
5560 | { | |
5561 | if ((tls_mask & TLS_DTPREL) != 0) | |
5562 | off += 4; | |
5563 | } | |
5564 | } | |
5565 | } | |
5566 | } | |
5567 | ||
3b36f7e6 AM |
5568 | relocation = htab->got->output_offset + off; |
5569 | relocation -= htab->elf.hgot->root.u.def.value; | |
7619e7c7 AM |
5570 | |
5571 | /* Addends on got relocations don't make much sense. | |
5572 | x+off@got is actually x@got+off, and since the got is | |
5573 | generated by a hash table traversal, the value in the | |
5574 | got at entry m+n bears little relation to the entry m. */ | |
5575 | if (addend != 0) | |
5576 | (*_bfd_error_handler) | |
d003868e AM |
5577 | (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"), |
5578 | input_bfd, | |
5579 | input_section, | |
7619e7c7 | 5580 | (long) rel->r_offset, |
7b609f53 | 5581 | howto->name, |
7619e7c7 AM |
5582 | sym_name); |
5583 | } | |
70bccea4 | 5584 | break; |
7619e7c7 | 5585 | |
252b5132 | 5586 | /* Relocations that need no special processing. */ |
7619e7c7 | 5587 | case R_PPC_LOCAL24PC: |
252b5132 RH |
5588 | /* It makes no sense to point a local relocation |
5589 | at a symbol not in this object. */ | |
7b609f53 | 5590 | if (unresolved_reloc) |
252b5132 | 5591 | { |
464e1740 ILT |
5592 | if (! (*info->callbacks->undefined_symbol) (info, |
5593 | h->root.root.string, | |
5594 | input_bfd, | |
5595 | input_section, | |
5cc7c785 | 5596 | rel->r_offset, |
b34976b6 AM |
5597 | TRUE)) |
5598 | return FALSE; | |
252b5132 RH |
5599 | continue; |
5600 | } | |
5601 | break; | |
5602 | ||
7619e7c7 AM |
5603 | case R_PPC_DTPREL16: |
5604 | case R_PPC_DTPREL16_LO: | |
5605 | case R_PPC_DTPREL16_HI: | |
5606 | case R_PPC_DTPREL16_HA: | |
e1918d23 | 5607 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
5608 | break; |
5609 | ||
70bccea4 AM |
5610 | /* Relocations that may need to be propagated if this is a shared |
5611 | object. */ | |
7619e7c7 AM |
5612 | case R_PPC_TPREL16: |
5613 | case R_PPC_TPREL16_LO: | |
5614 | case R_PPC_TPREL16_HI: | |
5615 | case R_PPC_TPREL16_HA: | |
e1918d23 | 5616 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
5617 | /* The TPREL16 relocs shouldn't really be used in shared |
5618 | libs as they will result in DT_TEXTREL being set, but | |
5619 | support them anyway. */ | |
5620 | goto dodyn; | |
5621 | ||
5622 | case R_PPC_TPREL32: | |
e1918d23 | 5623 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
7619e7c7 AM |
5624 | goto dodyn; |
5625 | ||
5626 | case R_PPC_DTPREL32: | |
e1918d23 | 5627 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7619e7c7 AM |
5628 | goto dodyn; |
5629 | ||
e515b051 AM |
5630 | case R_PPC_DTPMOD32: |
5631 | relocation = 1; | |
5632 | addend = 0; | |
5633 | goto dodyn; | |
5634 | ||
d7128ce4 AM |
5635 | case R_PPC_REL16: |
5636 | case R_PPC_REL16_LO: | |
5637 | case R_PPC_REL16_HI: | |
5638 | case R_PPC_REL16_HA: | |
5639 | break; | |
5640 | ||
7619e7c7 AM |
5641 | case R_PPC_REL24: |
5642 | case R_PPC_REL32: | |
5643 | case R_PPC_REL14: | |
5644 | case R_PPC_REL14_BRTAKEN: | |
5645 | case R_PPC_REL14_BRNTAKEN: | |
252b5132 RH |
5646 | /* If these relocations are not to a named symbol, they can be |
5647 | handled right here, no need to bother the dynamic linker. */ | |
f6c52c13 | 5648 | if (SYMBOL_REFERENCES_LOCAL (info, h) |
3b36f7e6 | 5649 | || h == htab->elf.hgot) |
252b5132 | 5650 | break; |
70bccea4 | 5651 | /* fall through */ |
252b5132 | 5652 | |
70bccea4 AM |
5653 | /* Relocations that always need to be propagated if this is a shared |
5654 | object. */ | |
7619e7c7 AM |
5655 | case R_PPC_ADDR32: |
5656 | case R_PPC_ADDR24: | |
5657 | case R_PPC_ADDR16: | |
5658 | case R_PPC_ADDR16_LO: | |
5659 | case R_PPC_ADDR16_HI: | |
5660 | case R_PPC_ADDR16_HA: | |
5661 | case R_PPC_ADDR14: | |
5662 | case R_PPC_ADDR14_BRTAKEN: | |
5663 | case R_PPC_ADDR14_BRNTAKEN: | |
5664 | case R_PPC_UADDR32: | |
5665 | case R_PPC_UADDR16: | |
ee05f2fe AM |
5666 | /* r_symndx will be zero only for relocs against symbols |
5667 | from removed linkonce sections, or sections discarded by | |
5668 | a linker script. */ | |
7619e7c7 | 5669 | dodyn: |
ee05f2fe AM |
5670 | if (r_symndx == 0) |
5671 | break; | |
5672 | /* Fall thru. */ | |
5673 | ||
c87b5a93 AM |
5674 | if ((input_section->flags & SEC_ALLOC) == 0) |
5675 | break; | |
5676 | /* Fall thru. */ | |
5677 | ||
ee05f2fe | 5678 | if ((info->shared |
4e795f50 AM |
5679 | && (h == NULL |
5680 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5681 | || h->root.type != bfd_link_hash_undefweak) | |
ee05f2fe | 5682 | && (MUST_BE_DYN_RELOC (r_type) |
f6c52c13 | 5683 | || !SYMBOL_CALLS_LOCAL (info, h))) |
ee05f2fe AM |
5684 | || (ELIMINATE_COPY_RELOCS |
5685 | && !info->shared | |
ee05f2fe AM |
5686 | && h != NULL |
5687 | && h->dynindx != -1 | |
f5385ebf AM |
5688 | && !h->non_got_ref |
5689 | && h->def_dynamic | |
5690 | && !h->def_regular)) | |
252b5132 | 5691 | { |
0bb2d96a | 5692 | int skip; |
252b5132 RH |
5693 | |
5694 | #ifdef DEBUG | |
55fd94b0 AM |
5695 | fprintf (stderr, "ppc_elf_relocate_section needs to " |
5696 | "create relocation for %s\n", | |
70bccea4 AM |
5697 | (h && h->root.root.string |
5698 | ? h->root.root.string : "<unknown>")); | |
252b5132 RH |
5699 | #endif |
5700 | ||
5701 | /* When generating a shared object, these relocations | |
70bccea4 AM |
5702 | are copied into the output file to be resolved at run |
5703 | time. */ | |
252b5132 RH |
5704 | if (sreloc == NULL) |
5705 | { | |
5706 | const char *name; | |
5707 | ||
5708 | name = (bfd_elf_string_from_elf_section | |
5709 | (input_bfd, | |
5710 | elf_elfheader (input_bfd)->e_shstrndx, | |
5711 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
5712 | if (name == NULL) | |
b34976b6 | 5713 | return FALSE; |
252b5132 RH |
5714 | |
5715 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
5716 | && strcmp (bfd_get_section_name (input_bfd, | |
5717 | input_section), | |
5718 | name + 5) == 0); | |
5719 | ||
7619e7c7 | 5720 | sreloc = bfd_get_section_by_name (htab->elf.dynobj, name); |
252b5132 RH |
5721 | BFD_ASSERT (sreloc != NULL); |
5722 | } | |
5723 | ||
0bb2d96a | 5724 | skip = 0; |
252b5132 | 5725 | |
c629eae0 JJ |
5726 | outrel.r_offset = |
5727 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
5728 | rel->r_offset); | |
0bb2d96a JJ |
5729 | if (outrel.r_offset == (bfd_vma) -1 |
5730 | || outrel.r_offset == (bfd_vma) -2) | |
5731 | skip = (int) outrel.r_offset; | |
252b5132 RH |
5732 | outrel.r_offset += (input_section->output_section->vma |
5733 | + input_section->output_offset); | |
5734 | ||
5735 | if (skip) | |
5736 | memset (&outrel, 0, sizeof outrel); | |
f6c52c13 | 5737 | else if (!SYMBOL_REFERENCES_LOCAL (info, h)) |
252b5132 | 5738 | { |
7619e7c7 | 5739 | unresolved_reloc = FALSE; |
252b5132 RH |
5740 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
5741 | outrel.r_addend = rel->r_addend; | |
5742 | } | |
5743 | else | |
5744 | { | |
47388f4c AM |
5745 | outrel.r_addend = relocation + rel->r_addend; |
5746 | ||
252b5132 | 5747 | if (r_type == R_PPC_ADDR32) |
47388f4c | 5748 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); |
252b5132 RH |
5749 | else |
5750 | { | |
5751 | long indx; | |
5752 | ||
47388f4c | 5753 | if (bfd_is_abs_section (sec)) |
252b5132 RH |
5754 | indx = 0; |
5755 | else if (sec == NULL || sec->owner == NULL) | |
5756 | { | |
5757 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5758 | return FALSE; |
252b5132 RH |
5759 | } |
5760 | else | |
5761 | { | |
5762 | asection *osec; | |
5763 | ||
47388f4c AM |
5764 | /* We are turning this relocation into one |
5765 | against a section symbol. It would be | |
5766 | proper to subtract the symbol's value, | |
5767 | osec->vma, from the emitted reloc addend, | |
5768 | but ld.so expects buggy relocs. */ | |
252b5132 RH |
5769 | osec = sec->output_section; |
5770 | indx = elf_section_data (osec)->dynindx; | |
8da6118f | 5771 | BFD_ASSERT (indx > 0); |
252b5132 RH |
5772 | #ifdef DEBUG |
5773 | if (indx <= 0) | |
55fd94b0 AM |
5774 | printf ("indx=%d section=%s flags=%08x name=%s\n", |
5775 | indx, osec->name, osec->flags, | |
5776 | h->root.root.string); | |
252b5132 RH |
5777 | #endif |
5778 | } | |
5779 | ||
5780 | outrel.r_info = ELF32_R_INFO (indx, r_type); | |
252b5132 RH |
5781 | } |
5782 | } | |
5783 | ||
947216bf AM |
5784 | loc = sreloc->contents; |
5785 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
5786 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 | 5787 | |
2243deae | 5788 | if (skip == -1) |
252b5132 | 5789 | continue; |
2243deae L |
5790 | |
5791 | /* This reloc will be computed at runtime. We clear the memory | |
5792 | so that it contains predictable value. */ | |
5793 | if (! skip | |
5794 | && ((input_section->flags & SEC_ALLOC) != 0 | |
5795 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)) | |
5796 | { | |
5797 | relocation = howto->pc_relative ? outrel.r_offset : 0; | |
5798 | addend = 0; | |
5799 | break; | |
5800 | } | |
252b5132 | 5801 | } |
252b5132 RH |
5802 | break; |
5803 | ||
b4a38de6 AM |
5804 | case R_PPC_RELAX32PC_PLT: |
5805 | case R_PPC_RELAX32_PLT: | |
5806 | BFD_ASSERT (h != NULL | |
5807 | && h->plt.offset != (bfd_vma) -1 | |
5808 | && htab->plt != NULL); | |
5809 | ||
d7128ce4 AM |
5810 | if (!htab->old_plt) |
5811 | relocation = (htab->glink->output_section->vma | |
5812 | + htab->glink->output_offset | |
5813 | + h->plt.offset * (GLINK_ENTRY_SIZE / 4)); | |
5814 | else | |
5815 | relocation = (htab->plt->output_section->vma | |
5816 | + htab->plt->output_offset | |
5817 | + h->plt.offset); | |
b4a38de6 AM |
5818 | if (r_type == R_PPC_RELAX32_PLT) |
5819 | goto relax32; | |
5820 | /* Fall thru */ | |
5821 | ||
f31a141e AM |
5822 | case R_PPC_RELAX32PC: |
5823 | relocation -= (input_section->output_section->vma | |
5824 | + input_section->output_offset | |
5825 | + rel->r_offset - 4); | |
5826 | /* Fall thru */ | |
b4a38de6 | 5827 | |
deaaf2f3 | 5828 | case R_PPC_RELAX32: |
b4a38de6 | 5829 | relax32: |
9abc968f AM |
5830 | { |
5831 | unsigned long t0; | |
5832 | unsigned long t1; | |
5833 | ||
5834 | t0 = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
5835 | t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4); | |
5836 | ||
5837 | /* We're clearing the bits for R_PPC_ADDR16_HA | |
5838 | and R_PPC_ADDR16_LO here. */ | |
5839 | t0 &= ~0xffff; | |
5840 | t1 &= ~0xffff; | |
5841 | ||
5842 | /* t0 is HA, t1 is LO */ | |
5843 | relocation += addend; | |
5844 | t0 |= ((relocation + 0x8000) >> 16) & 0xffff; | |
5845 | t1 |= relocation & 0xffff; | |
5846 | ||
5847 | bfd_put_32 (output_bfd, t0, contents + rel->r_offset); | |
5848 | bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4); | |
5849 | } | |
8517fae7 | 5850 | continue; |
deaaf2f3 | 5851 | |
70bccea4 | 5852 | /* Indirect .sdata relocation. */ |
7619e7c7 | 5853 | case R_PPC_EMB_SDAI16: |
c9a2f333 | 5854 | BFD_ASSERT (htab->sdata[0].section != NULL); |
7619e7c7 | 5855 | relocation |
76750a2f AM |
5856 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0], |
5857 | h, relocation, rel); | |
252b5132 RH |
5858 | break; |
5859 | ||
70bccea4 | 5860 | /* Indirect .sdata2 relocation. */ |
7619e7c7 | 5861 | case R_PPC_EMB_SDA2I16: |
c9a2f333 | 5862 | BFD_ASSERT (htab->sdata[1].section != NULL); |
7619e7c7 | 5863 | relocation |
76750a2f AM |
5864 | = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1], |
5865 | h, relocation, rel); | |
252b5132 RH |
5866 | break; |
5867 | ||
70bccea4 AM |
5868 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
5869 | section, not the actual VMA. This is appropriate when generating | |
5870 | an embedded ELF object, for which the .got section acts like the | |
5871 | AIX .toc section. */ | |
7619e7c7 | 5872 | case R_PPC_TOC16: /* phony GOT16 relocations */ |
55fd94b0 | 5873 | BFD_ASSERT (sec != NULL); |
252b5132 RH |
5874 | BFD_ASSERT (bfd_is_und_section (sec) |
5875 | || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 | |
f12123c0 | 5876 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0); |
252b5132 | 5877 | |
70bccea4 | 5878 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; |
252b5132 RH |
5879 | break; |
5880 | ||
7619e7c7 | 5881 | case R_PPC_PLTREL24: |
252b5132 | 5882 | /* Relocation is to the entry for this symbol in the |
70bccea4 | 5883 | procedure linkage table. */ |
252b5132 RH |
5884 | BFD_ASSERT (h != NULL); |
5885 | ||
5886 | if (h->plt.offset == (bfd_vma) -1 | |
7619e7c7 | 5887 | || htab->plt == NULL) |
252b5132 RH |
5888 | { |
5889 | /* We didn't make a PLT entry for this symbol. This | |
70bccea4 AM |
5890 | happens when statically linking PIC code, or when |
5891 | using -Bsymbolic. */ | |
252b5132 RH |
5892 | break; |
5893 | } | |
5894 | ||
7619e7c7 | 5895 | unresolved_reloc = FALSE; |
d7128ce4 AM |
5896 | if (!htab->old_plt) |
5897 | relocation = (htab->glink->output_section->vma | |
5898 | + htab->glink->output_offset | |
5899 | + h->plt.offset * (GLINK_ENTRY_SIZE / 4)); | |
5900 | else | |
5901 | relocation = (htab->plt->output_section->vma | |
5902 | + htab->plt->output_offset | |
5903 | + h->plt.offset); | |
8da6118f | 5904 | break; |
252b5132 | 5905 | |
70bccea4 | 5906 | /* Relocate against _SDA_BASE_. */ |
7619e7c7 | 5907 | case R_PPC_SDAREL16: |
252b5132 RH |
5908 | { |
5909 | const char *name; | |
5910 | ||
55fd94b0 | 5911 | BFD_ASSERT (sec != NULL); |
252b5132 | 5912 | name = bfd_get_section_name (abfd, sec->output_section); |
5f819128 AM |
5913 | if (! ((strncmp (name, ".sdata", 6) == 0 |
5914 | && (name[6] == 0 || name[6] == '.')) | |
5915 | || (strncmp (name, ".sbss", 5) == 0 | |
5916 | && (name[5] == 0 || name[5] == '.')))) | |
252b5132 | 5917 | { |
55fd94b0 | 5918 | (*_bfd_error_handler) |
d003868e | 5919 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 5920 | "in the wrong output section (%s)"), |
d003868e | 5921 | input_bfd, |
55fd94b0 AM |
5922 | sym_name, |
5923 | howto->name, | |
5924 | name); | |
252b5132 | 5925 | } |
c9a2f333 | 5926 | addend -= htab->sdata[0].sym_val; |
252b5132 RH |
5927 | } |
5928 | break; | |
5929 | ||
70bccea4 | 5930 | /* Relocate against _SDA2_BASE_. */ |
7619e7c7 | 5931 | case R_PPC_EMB_SDA2REL: |
252b5132 RH |
5932 | { |
5933 | const char *name; | |
5934 | ||
55fd94b0 | 5935 | BFD_ASSERT (sec != NULL); |
252b5132 | 5936 | name = bfd_get_section_name (abfd, sec->output_section); |
5f819128 AM |
5937 | if (! (strncmp (name, ".sdata2", 7) == 0 |
5938 | || strncmp (name, ".sbss2", 6) == 0)) | |
252b5132 | 5939 | { |
55fd94b0 | 5940 | (*_bfd_error_handler) |
d003868e | 5941 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 5942 | "in the wrong output section (%s)"), |
d003868e | 5943 | input_bfd, |
55fd94b0 AM |
5944 | sym_name, |
5945 | howto->name, | |
5946 | name); | |
c3668558 | 5947 | |
252b5132 | 5948 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 5949 | ret = FALSE; |
252b5132 RH |
5950 | continue; |
5951 | } | |
c9a2f333 | 5952 | addend -= htab->sdata[1].sym_val; |
252b5132 RH |
5953 | } |
5954 | break; | |
5955 | ||
70bccea4 | 5956 | /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */ |
7619e7c7 AM |
5957 | case R_PPC_EMB_SDA21: |
5958 | case R_PPC_EMB_RELSDA: | |
252b5132 RH |
5959 | { |
5960 | const char *name; | |
5961 | int reg; | |
5962 | ||
55fd94b0 | 5963 | BFD_ASSERT (sec != NULL); |
252b5132 | 5964 | name = bfd_get_section_name (abfd, sec->output_section); |
b34976b6 | 5965 | if (((strncmp (name, ".sdata", 6) == 0 |
5f819128 AM |
5966 | && (name[6] == 0 || name[6] == '.')) |
5967 | || (strncmp (name, ".sbss", 5) == 0 | |
5968 | && (name[5] == 0 || name[5] == '.')))) | |
252b5132 RH |
5969 | { |
5970 | reg = 13; | |
c9a2f333 | 5971 | addend -= htab->sdata[0].sym_val; |
252b5132 RH |
5972 | } |
5973 | ||
5f819128 AM |
5974 | else if (strncmp (name, ".sdata2", 7) == 0 |
5975 | || strncmp (name, ".sbss2", 6) == 0) | |
252b5132 RH |
5976 | { |
5977 | reg = 2; | |
c9a2f333 | 5978 | addend -= htab->sdata[1].sym_val; |
252b5132 RH |
5979 | } |
5980 | ||
8da6118f KH |
5981 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 |
5982 | || strcmp (name, ".PPC.EMB.sbss0") == 0) | |
252b5132 RH |
5983 | { |
5984 | reg = 0; | |
5985 | } | |
5986 | ||
5987 | else | |
5988 | { | |
55fd94b0 | 5989 | (*_bfd_error_handler) |
d003868e | 5990 | (_("%B: the target (%s) of a %s relocation is " |
55fd94b0 | 5991 | "in the wrong output section (%s)"), |
d003868e | 5992 | input_bfd, |
55fd94b0 AM |
5993 | sym_name, |
5994 | howto->name, | |
5995 | name); | |
252b5132 RH |
5996 | |
5997 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5998 | ret = FALSE; |
252b5132 RH |
5999 | continue; |
6000 | } | |
6001 | ||
6002 | if (r_type == R_PPC_EMB_SDA21) | |
6003 | { /* fill in register field */ | |
7619e7c7 | 6004 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
252b5132 | 6005 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); |
7619e7c7 | 6006 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
252b5132 RH |
6007 | } |
6008 | } | |
6009 | break; | |
6010 | ||
70bccea4 | 6011 | /* Relocate against the beginning of the section. */ |
7619e7c7 AM |
6012 | case R_PPC_SECTOFF: |
6013 | case R_PPC_SECTOFF_LO: | |
6014 | case R_PPC_SECTOFF_HI: | |
6015 | case R_PPC_SECTOFF_HA: | |
55fd94b0 | 6016 | BFD_ASSERT (sec != NULL); |
252b5132 | 6017 | addend -= sec->output_section->vma; |
252b5132 RH |
6018 | break; |
6019 | ||
70bccea4 | 6020 | /* Negative relocations. */ |
7619e7c7 AM |
6021 | case R_PPC_EMB_NADDR32: |
6022 | case R_PPC_EMB_NADDR16: | |
6023 | case R_PPC_EMB_NADDR16_LO: | |
6024 | case R_PPC_EMB_NADDR16_HI: | |
6025 | case R_PPC_EMB_NADDR16_HA: | |
8da6118f | 6026 | addend -= 2 * relocation; |
252b5132 RH |
6027 | break; |
6028 | ||
7619e7c7 AM |
6029 | case R_PPC_COPY: |
6030 | case R_PPC_GLOB_DAT: | |
6031 | case R_PPC_JMP_SLOT: | |
6032 | case R_PPC_RELATIVE: | |
6033 | case R_PPC_PLT32: | |
6034 | case R_PPC_PLTREL32: | |
6035 | case R_PPC_PLT16_LO: | |
6036 | case R_PPC_PLT16_HI: | |
6037 | case R_PPC_PLT16_HA: | |
6038 | case R_PPC_ADDR30: | |
6039 | case R_PPC_EMB_RELSEC16: | |
6040 | case R_PPC_EMB_RELST_LO: | |
6041 | case R_PPC_EMB_RELST_HI: | |
6042 | case R_PPC_EMB_RELST_HA: | |
6043 | case R_PPC_EMB_BIT_FLD: | |
6044 | (*_bfd_error_handler) | |
d003868e AM |
6045 | (_("%B: relocation %s is not yet supported for symbol %s."), |
6046 | input_bfd, | |
7619e7c7 AM |
6047 | howto->name, |
6048 | sym_name); | |
252b5132 RH |
6049 | |
6050 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 6051 | ret = FALSE; |
252b5132 | 6052 | continue; |
7619e7c7 | 6053 | } |
252b5132 | 6054 | |
7619e7c7 AM |
6055 | /* Do any further special processing. */ |
6056 | switch (r_type) | |
6057 | { | |
6058 | default: | |
6059 | break; | |
6060 | ||
6061 | case R_PPC_ADDR16_HA: | |
d7128ce4 | 6062 | case R_PPC_REL16_HA: |
7619e7c7 AM |
6063 | case R_PPC_GOT16_HA: |
6064 | case R_PPC_PLT16_HA: | |
6065 | case R_PPC_SECTOFF_HA: | |
6066 | case R_PPC_TPREL16_HA: | |
6067 | case R_PPC_DTPREL16_HA: | |
6068 | case R_PPC_GOT_TLSGD16_HA: | |
6069 | case R_PPC_GOT_TLSLD16_HA: | |
6070 | case R_PPC_GOT_TPREL16_HA: | |
6071 | case R_PPC_GOT_DTPREL16_HA: | |
6072 | case R_PPC_EMB_NADDR16_HA: | |
6073 | case R_PPC_EMB_RELST_HA: | |
6074 | /* It's just possible that this symbol is a weak symbol | |
7b609f53 | 6075 | that's not actually defined anywhere. In that case, |
7619e7c7 AM |
6076 | 'sec' would be NULL, and we should leave the symbol |
6077 | alone (it will be set to zero elsewhere in the link). */ | |
6078 | if (sec != NULL) | |
e515b051 AM |
6079 | /* Add 0x10000 if sign bit in 0:15 is set. |
6080 | Bits 0:15 are not used. */ | |
6081 | addend += 0x8000; | |
7619e7c7 | 6082 | break; |
252b5132 RH |
6083 | } |
6084 | ||
252b5132 | 6085 | #ifdef DEBUG |
55fd94b0 AM |
6086 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, " |
6087 | "offset = %ld, addend = %ld\n", | |
252b5132 | 6088 | howto->name, |
8da6118f | 6089 | (int) r_type, |
252b5132 RH |
6090 | sym_name, |
6091 | r_symndx, | |
7619e7c7 | 6092 | (long) rel->r_offset, |
8da6118f | 6093 | (long) addend); |
252b5132 RH |
6094 | #endif |
6095 | ||
7619e7c7 AM |
6096 | if (unresolved_reloc |
6097 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
f5385ebf | 6098 | && h->def_dynamic)) |
7619e7c7 AM |
6099 | { |
6100 | (*_bfd_error_handler) | |
d003868e AM |
6101 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
6102 | input_bfd, | |
6103 | input_section, | |
7619e7c7 | 6104 | (long) rel->r_offset, |
7b609f53 | 6105 | howto->name, |
7619e7c7 AM |
6106 | sym_name); |
6107 | ret = FALSE; | |
6108 | } | |
6109 | ||
252b5132 RH |
6110 | r = _bfd_final_link_relocate (howto, |
6111 | input_bfd, | |
6112 | input_section, | |
6113 | contents, | |
7619e7c7 | 6114 | rel->r_offset, |
252b5132 RH |
6115 | relocation, |
6116 | addend); | |
6117 | ||
7619e7c7 | 6118 | if (r != bfd_reloc_ok) |
252b5132 | 6119 | { |
7619e7c7 | 6120 | if (r == bfd_reloc_overflow) |
252b5132 | 6121 | { |
7619e7c7 AM |
6122 | if (warned) |
6123 | continue; | |
6124 | if (h != NULL | |
6125 | && h->root.type == bfd_link_hash_undefweak | |
dc1bc0c9 RH |
6126 | && howto->pc_relative) |
6127 | { | |
6128 | /* Assume this is a call protected by other code that | |
6129 | detect the symbol is undefined. If this is the case, | |
6130 | we can safely ignore the overflow. If not, the | |
6131 | program is hosed anyway, and a little warning isn't | |
6132 | going to help. */ | |
252b5132 | 6133 | |
dc1bc0c9 RH |
6134 | continue; |
6135 | } | |
252b5132 | 6136 | |
7619e7c7 | 6137 | if (! (*info->callbacks->reloc_overflow) (info, |
dfeffb9f | 6138 | (h ? &h->root : NULL), |
7619e7c7 AM |
6139 | sym_name, |
6140 | howto->name, | |
6141 | rel->r_addend, | |
6142 | input_bfd, | |
6143 | input_section, | |
6144 | rel->r_offset)) | |
6145 | return FALSE; | |
dc1bc0c9 RH |
6146 | } |
6147 | else | |
6148 | { | |
7619e7c7 | 6149 | (*_bfd_error_handler) |
d003868e AM |
6150 | (_("%B(%A+0x%lx): %s reloc against `%s': error %d"), |
6151 | input_bfd, input_section, | |
7b609f53 | 6152 | (long) rel->r_offset, howto->name, sym_name, (int) r); |
7619e7c7 | 6153 | ret = FALSE; |
252b5132 RH |
6154 | } |
6155 | } | |
6156 | } | |
6157 | ||
252b5132 RH |
6158 | #ifdef DEBUG |
6159 | fprintf (stderr, "\n"); | |
6160 | #endif | |
6161 | ||
6162 | return ret; | |
6163 | } | |
252b5132 | 6164 | \f |
25dbc73a AM |
6165 | /* Finish up dynamic symbol handling. We set the contents of various |
6166 | dynamic sections here. */ | |
c5fccbec | 6167 | |
b34976b6 | 6168 | static bfd_boolean |
25dbc73a AM |
6169 | ppc_elf_finish_dynamic_symbol (bfd *output_bfd, |
6170 | struct bfd_link_info *info, | |
6171 | struct elf_link_hash_entry *h, | |
6172 | Elf_Internal_Sym *sym) | |
e1a9cb8e | 6173 | { |
25dbc73a | 6174 | struct ppc_elf_link_hash_table *htab; |
e1a9cb8e | 6175 | |
25dbc73a AM |
6176 | #ifdef DEBUG |
6177 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", | |
6178 | h->root.root.string); | |
6179 | #endif | |
e1a9cb8e | 6180 | |
25dbc73a AM |
6181 | htab = ppc_elf_hash_table (info); |
6182 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
e1a9cb8e | 6183 | |
25dbc73a | 6184 | if (h->plt.offset != (bfd_vma) -1) |
e1a9cb8e | 6185 | { |
25dbc73a AM |
6186 | Elf_Internal_Rela rela; |
6187 | bfd_byte *loc; | |
6188 | bfd_vma reloc_index; | |
e1a9cb8e | 6189 | |
25dbc73a AM |
6190 | #ifdef DEBUG |
6191 | fprintf (stderr, ", plt_offset = %d", h->plt.offset); | |
6192 | #endif | |
e1a9cb8e | 6193 | |
25dbc73a AM |
6194 | /* This symbol has an entry in the procedure linkage table. Set |
6195 | it up. */ | |
e1a9cb8e | 6196 | |
25dbc73a AM |
6197 | BFD_ASSERT (h->dynindx != -1); |
6198 | BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL); | |
e1a9cb8e | 6199 | |
d7128ce4 AM |
6200 | if (htab->old_plt) |
6201 | { | |
6202 | /* We don't need to fill in the .plt. The ppc dynamic linker | |
6203 | will fill it in. */ | |
6204 | } | |
6205 | else | |
6206 | { | |
6207 | bfd_vma val = (htab->glink_pltresolve | |
86b9da88 | 6208 | + h->plt.offset |
d7128ce4 AM |
6209 | + htab->glink->output_section->vma |
6210 | + htab->glink->output_offset); | |
6211 | bfd_put_32 (output_bfd, val, htab->plt->contents + h->plt.offset); | |
6212 | } | |
e1a9cb8e | 6213 | |
25dbc73a AM |
6214 | /* Fill in the entry in the .rela.plt section. */ |
6215 | rela.r_offset = (htab->plt->output_section->vma | |
6216 | + htab->plt->output_offset | |
6217 | + h->plt.offset); | |
6218 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); | |
6219 | rela.r_addend = 0; | |
e1a9cb8e | 6220 | |
d7128ce4 AM |
6221 | if (!htab->old_plt) |
6222 | reloc_index = h->plt.offset / 4; | |
6223 | else | |
6224 | { | |
6225 | reloc_index = ((h->plt.offset - PLT_INITIAL_ENTRY_SIZE) | |
6226 | / PLT_SLOT_SIZE); | |
6227 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES) | |
6228 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; | |
6229 | } | |
25dbc73a AM |
6230 | loc = (htab->relplt->contents |
6231 | + reloc_index * sizeof (Elf32_External_Rela)); | |
6232 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
e1a9cb8e | 6233 | |
25dbc73a AM |
6234 | if (!h->def_regular) |
6235 | { | |
6236 | /* Mark the symbol as undefined, rather than as defined in | |
6237 | the .plt section. Leave the value alone. */ | |
6238 | sym->st_shndx = SHN_UNDEF; | |
6239 | /* If the symbol is weak, we do need to clear the value. | |
6240 | Otherwise, the PLT entry would provide a definition for | |
6241 | the symbol even if the symbol wasn't defined anywhere, | |
6242 | and so the symbol would never be NULL. */ | |
6243 | if (!h->ref_regular_nonweak) | |
6244 | sym->st_value = 0; | |
6245 | } | |
e1a9cb8e NC |
6246 | } |
6247 | ||
25dbc73a AM |
6248 | if (h->needs_copy) |
6249 | { | |
6250 | asection *s; | |
6251 | Elf_Internal_Rela rela; | |
6252 | bfd_byte *loc; | |
e1a9cb8e | 6253 | |
25dbc73a | 6254 | /* This symbols needs a copy reloc. Set it up. */ |
e1a9cb8e | 6255 | |
25dbc73a AM |
6256 | #ifdef DEBUG |
6257 | fprintf (stderr, ", copy"); | |
6258 | #endif | |
e1a9cb8e | 6259 | |
25dbc73a | 6260 | BFD_ASSERT (h->dynindx != -1); |
86bbe32f | 6261 | |
25dbc73a AM |
6262 | if (h->size <= elf_gp_size (htab->elf.dynobj)) |
6263 | s = htab->relsbss; | |
6264 | else | |
6265 | s = htab->relbss; | |
6266 | BFD_ASSERT (s != NULL); | |
e1a9cb8e | 6267 | |
25dbc73a AM |
6268 | rela.r_offset = (h->root.u.def.value |
6269 | + h->root.u.def.section->output_section->vma | |
6270 | + h->root.u.def.section->output_offset); | |
6271 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); | |
6272 | rela.r_addend = 0; | |
6273 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); | |
6274 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
6275 | } | |
e1a9cb8e | 6276 | |
25dbc73a AM |
6277 | #ifdef DEBUG |
6278 | fprintf (stderr, "\n"); | |
6279 | #endif | |
e1a9cb8e | 6280 | |
25dbc73a | 6281 | /* Mark some specially defined symbols as absolute. */ |
3b36f7e6 AM |
6282 | if (h == htab->elf.hgot |
6283 | || strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
25dbc73a AM |
6284 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) |
6285 | sym->st_shndx = SHN_ABS; | |
e1a9cb8e | 6286 | |
25dbc73a AM |
6287 | return TRUE; |
6288 | } | |
6289 | \f | |
6290 | static enum elf_reloc_type_class | |
6291 | ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela) | |
e1a9cb8e | 6292 | { |
25dbc73a AM |
6293 | switch (ELF32_R_TYPE (rela->r_info)) |
6294 | { | |
6295 | case R_PPC_RELATIVE: | |
6296 | return reloc_class_relative; | |
6297 | case R_PPC_REL24: | |
6298 | case R_PPC_ADDR24: | |
6299 | case R_PPC_JMP_SLOT: | |
6300 | return reloc_class_plt; | |
6301 | case R_PPC_COPY: | |
6302 | return reloc_class_copy; | |
6303 | default: | |
6304 | return reloc_class_normal; | |
6305 | } | |
e1a9cb8e | 6306 | } |
25dbc73a AM |
6307 | \f |
6308 | /* Finish up the dynamic sections. */ | |
e1a9cb8e | 6309 | |
25dbc73a AM |
6310 | static bfd_boolean |
6311 | ppc_elf_finish_dynamic_sections (bfd *output_bfd, | |
6312 | struct bfd_link_info *info) | |
e1a9cb8e | 6313 | { |
25dbc73a AM |
6314 | asection *sdyn; |
6315 | struct ppc_elf_link_hash_table *htab; | |
e1a9cb8e | 6316 | |
25dbc73a AM |
6317 | #ifdef DEBUG |
6318 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
6319 | #endif | |
6b0817e5 | 6320 | |
25dbc73a AM |
6321 | htab = ppc_elf_hash_table (info); |
6322 | sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic"); | |
e1a9cb8e | 6323 | |
25dbc73a | 6324 | if (htab->elf.dynamic_sections_created) |
e1a9cb8e | 6325 | { |
25dbc73a | 6326 | Elf32_External_Dyn *dyncon, *dynconend; |
e1a9cb8e | 6327 | |
25dbc73a | 6328 | BFD_ASSERT (htab->plt != NULL && sdyn != NULL); |
86bbe32f | 6329 | |
25dbc73a AM |
6330 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
6331 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); | |
6332 | for (; dyncon < dynconend; dyncon++) | |
6333 | { | |
6334 | Elf_Internal_Dyn dyn; | |
6335 | asection *s; | |
e1a9cb8e | 6336 | |
25dbc73a | 6337 | bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn); |
86bbe32f | 6338 | |
25dbc73a AM |
6339 | switch (dyn.d_tag) |
6340 | { | |
6341 | case DT_PLTGOT: | |
6342 | s = htab->plt; | |
6343 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
6344 | break; | |
86bbe32f | 6345 | |
25dbc73a AM |
6346 | case DT_PLTRELSZ: |
6347 | dyn.d_un.d_val = htab->relplt->size; | |
6348 | break; | |
e1a9cb8e | 6349 | |
25dbc73a AM |
6350 | case DT_JMPREL: |
6351 | s = htab->relplt; | |
6352 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
6353 | break; | |
2f89ff8d | 6354 | |
d7128ce4 AM |
6355 | case DT_PPC_GLINK: |
6356 | s = htab->glink; | |
86b9da88 | 6357 | dyn.d_un.d_ptr = (s->size - GLINK_PLTRESOLVE |
d7128ce4 AM |
6358 | + s->output_section->vma + s->output_offset); |
6359 | break; | |
6360 | ||
25dbc73a AM |
6361 | default: |
6362 | continue; | |
6363 | } | |
4c45e5c9 | 6364 | |
25dbc73a AM |
6365 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
6366 | } | |
6367 | } | |
4c45e5c9 | 6368 | |
25dbc73a AM |
6369 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can |
6370 | easily find the address of the _GLOBAL_OFFSET_TABLE_. */ | |
3b36f7e6 | 6371 | if (htab->got != NULL) |
25dbc73a | 6372 | { |
3b36f7e6 AM |
6373 | unsigned char *p = htab->got->contents; |
6374 | bfd_vma val; | |
2f89ff8d | 6375 | |
3b36f7e6 | 6376 | p += elf_hash_table (info)->hgot->root.u.def.value; |
d7128ce4 AM |
6377 | if (htab->old_plt) |
6378 | bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, p - 4); | |
3b36f7e6 AM |
6379 | |
6380 | val = 0; | |
6381 | if (sdyn != NULL) | |
6382 | val = sdyn->output_section->vma + sdyn->output_offset; | |
6383 | bfd_put_32 (output_bfd, val, p); | |
25dbc73a AM |
6384 | |
6385 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4; | |
6386 | } | |
6387 | ||
d7128ce4 AM |
6388 | if (htab->glink != NULL && htab->glink->contents != NULL) |
6389 | { | |
6390 | unsigned char *p; | |
6391 | unsigned char *endp; | |
86b9da88 | 6392 | bfd_vma got, pltgot; |
d7128ce4 AM |
6393 | unsigned int i; |
6394 | static const unsigned int plt_resolve[] = | |
6395 | { | |
6396 | SUB_11_11_30, | |
6397 | ADD_0_11_11, | |
6398 | ADD_11_0_11, | |
6399 | LWZ_0_4_30, | |
6400 | MTCTR_0, | |
6401 | LWZ_12_8_30, | |
6402 | BCTR, | |
6403 | NOP, | |
6404 | NOP, | |
6405 | NOP | |
6406 | }; | |
6407 | ||
6408 | #define PPC_LO(v) ((v) & 0xffff) | |
6409 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6410 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6411 | ||
86b9da88 AM |
6412 | got = (htab->elf.hgot->root.u.def.value |
6413 | + htab->elf.hgot->root.u.def.section->output_section->vma | |
6414 | + htab->elf.hgot->root.u.def.section->output_offset); | |
6415 | ||
d7128ce4 AM |
6416 | pltgot = (htab->plt->output_section->vma |
6417 | + htab->plt->output_offset | |
86b9da88 | 6418 | - got); |
d7128ce4 | 6419 | |
86b9da88 | 6420 | /* Write the plt call stubs. */ |
d7128ce4 | 6421 | p = htab->glink->contents; |
86b9da88 AM |
6422 | endp = p + htab->glink_pltresolve; |
6423 | while (p < endp) | |
6424 | { | |
6425 | if (pltgot < 0x8000) | |
6426 | { | |
6427 | bfd_put_32 (output_bfd, LWZ_11_X_30 + pltgot, p); | |
6428 | p += 4; | |
6429 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6430 | p += 4; | |
6431 | bfd_put_32 (output_bfd, BCTR, p); | |
6432 | p += 4; | |
6433 | bfd_put_32 (output_bfd, NOP, p); | |
6434 | p += 4; | |
6435 | } | |
6436 | else | |
6437 | { | |
6438 | bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (pltgot), p); | |
6439 | p += 4; | |
6440 | bfd_put_32 (output_bfd, LWZ_11_X_11 + PPC_LO (pltgot), p); | |
6441 | p += 4; | |
6442 | bfd_put_32 (output_bfd, MTCTR_11, p); | |
6443 | p += 4; | |
6444 | bfd_put_32 (output_bfd, BCTR, p); | |
6445 | p += 4; | |
6446 | } | |
6447 | pltgot += 4; | |
6448 | } | |
6449 | ||
6450 | /* Now build the branch table, one for each plt entry (less one), | |
6451 | and perhaps some padding. */ | |
6452 | endp = htab->glink->contents; | |
6453 | endp += htab->glink->size - GLINK_PLTRESOLVE; | |
6454 | while (p < endp - 8 * 4) | |
6455 | { | |
6456 | bfd_put_32 (output_bfd, B + endp - p, p); | |
6457 | p += 4; | |
6458 | } | |
6459 | while (p < endp) | |
6460 | { | |
6461 | bfd_put_32 (output_bfd, NOP, p); | |
6462 | p += 4; | |
6463 | } | |
6464 | ||
6465 | got -= (htab->glink_pltresolve | |
6466 | + htab->glink->output_section->vma | |
6467 | + htab->glink->output_offset); | |
6468 | ||
6469 | /* Last comes the PLTresolve stub. */ | |
6470 | bfd_put_32 (output_bfd, ADDIS_11_11 + PPC_HA (got), p); | |
d7128ce4 | 6471 | p += 4; |
86b9da88 | 6472 | bfd_put_32 (output_bfd, ADDI_11_11 + PPC_LO (got), p); |
d7128ce4 AM |
6473 | p += 4; |
6474 | ||
6475 | for (i = 0; i < ARRAY_SIZE (plt_resolve); i++) | |
6476 | { | |
6477 | bfd_put_32 (output_bfd, plt_resolve[i], p); | |
6478 | p += 4; | |
6479 | } | |
6480 | if (ARRAY_SIZE (plt_resolve) + 2 != GLINK_PLTRESOLVE / 4) | |
6481 | abort (); | |
d7128ce4 AM |
6482 | } |
6483 | ||
25dbc73a AM |
6484 | return TRUE; |
6485 | } | |
e1a9cb8e | 6486 | \f |
252b5132 RH |
6487 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
6488 | #define TARGET_LITTLE_NAME "elf32-powerpcle" | |
6489 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec | |
6490 | #define TARGET_BIG_NAME "elf32-powerpc" | |
6491 | #define ELF_ARCH bfd_arch_powerpc | |
6492 | #define ELF_MACHINE_CODE EM_PPC | |
d0facd1b NC |
6493 | #ifdef __QNXTARGET__ |
6494 | #define ELF_MAXPAGESIZE 0x1000 | |
6495 | #else | |
252b5132 | 6496 | #define ELF_MAXPAGESIZE 0x10000 |
d0facd1b | 6497 | #endif |
b1342370 | 6498 | #define ELF_MINPAGESIZE 0x1000 |
252b5132 RH |
6499 | #define elf_info_to_howto ppc_elf_info_to_howto |
6500 | ||
6501 | #ifdef EM_CYGNUS_POWERPC | |
6502 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
6503 | #endif | |
6504 | ||
6505 | #ifdef EM_PPC_OLD | |
6506 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
6507 | #endif | |
6508 | ||
6509 | #define elf_backend_plt_not_loaded 1 | |
252b5132 | 6510 | #define elf_backend_can_gc_sections 1 |
51b64d56 | 6511 | #define elf_backend_can_refcount 1 |
b491616a | 6512 | #define elf_backend_rela_normal 1 |
252b5132 | 6513 | |
43c40ab2 | 6514 | #define bfd_elf32_mkobject ppc_elf_mkobject |
252b5132 | 6515 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
70bccea4 | 6516 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section |
252b5132 RH |
6517 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup |
6518 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags | |
70bccea4 | 6519 | #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create |
252b5132 | 6520 | |
feee612b | 6521 | #define elf_backend_object_p ppc_elf_object_p |
252b5132 RH |
6522 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
6523 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook | |
6524 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr | |
6525 | #define elf_backend_relocate_section ppc_elf_relocate_section | |
6526 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections | |
6527 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
7fce784e | 6528 | #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol |
252b5132 RH |
6529 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol |
6530 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook | |
6531 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
6532 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol | |
6533 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
6534 | #define elf_backend_fake_sections ppc_elf_fake_sections | |
6535 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers | |
c5fccbec DJ |
6536 | #define elf_backend_grok_prstatus ppc_elf_grok_prstatus |
6537 | #define elf_backend_grok_psinfo ppc_elf_grok_psinfo | |
29c2fb7c | 6538 | #define elf_backend_reloc_type_class ppc_elf_reloc_type_class |
70bccea4 AM |
6539 | #define elf_backend_begin_write_processing ppc_elf_begin_write_processing |
6540 | #define elf_backend_final_write_processing ppc_elf_final_write_processing | |
6541 | #define elf_backend_write_section ppc_elf_write_section | |
2f89ff8d | 6542 | #define elf_backend_special_sections ppc_elf_special_sections |
4c45e5c9 | 6543 | #define elf_backend_plt_sym_val ppc_elf_plt_sym_val |
252b5132 RH |
6544 | |
6545 | #include "elf32-target.h" |