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