2005-03-20 H.J. Lu <hongjiu.lu@intel.com>
[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 /* Merge backend specific data from an object file to the output
1598 object file when linking. */
1599
1600 static bfd_boolean
1601 ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
1602 {
1603 flagword old_flags;
1604 flagword new_flags;
1605 bfd_boolean error;
1606
1607 /* Check if we have the same endianess. */
1608 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
1609 return FALSE;
1610
1611 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1612 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1613 return TRUE;
1614
1615 new_flags = elf_elfheader (ibfd)->e_flags;
1616 old_flags = elf_elfheader (obfd)->e_flags;
1617 if (!elf_flags_init (obfd))
1618 {
1619 /* First call, no flags set. */
1620 elf_flags_init (obfd) = TRUE;
1621 elf_elfheader (obfd)->e_flags = new_flags;
1622 }
1623
1624 /* Compatible flags are ok. */
1625 else if (new_flags == old_flags)
1626 ;
1627
1628 /* Incompatible flags. */
1629 else
1630 {
1631 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
1632 to be linked with either. */
1633 error = FALSE;
1634 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1635 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1636 {
1637 error = TRUE;
1638 (*_bfd_error_handler)
1639 (_("%B: compiled with -mrelocatable and linked with "
1640 "modules compiled normally"), ibfd);
1641 }
1642 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1643 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1644 {
1645 error = TRUE;
1646 (*_bfd_error_handler)
1647 (_("%B: compiled normally and linked with "
1648 "modules compiled with -mrelocatable"), ibfd);
1649 }
1650
1651 /* The output is -mrelocatable-lib iff both the input files are. */
1652 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
1653 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1654
1655 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1656 but each input file is either -mrelocatable or -mrelocatable-lib. */
1657 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
1658 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
1659 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
1660 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
1661
1662 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
1663 any module uses it. */
1664 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1665
1666 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1667 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1668
1669 /* Warn about any other mismatches. */
1670 if (new_flags != old_flags)
1671 {
1672 error = TRUE;
1673 (*_bfd_error_handler)
1674 (_("%B: uses different e_flags (0x%lx) fields "
1675 "than previous modules (0x%lx)"),
1676 ibfd, (long) new_flags, (long) old_flags);
1677 }
1678
1679 if (error)
1680 {
1681 bfd_set_error (bfd_error_bad_value);
1682 return FALSE;
1683 }
1684 }
1685
1686 return TRUE;
1687 }
1688
1689 /* Support for core dump NOTE sections. */
1690
1691 static bfd_boolean
1692 ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1693 {
1694 int offset;
1695 unsigned int size;
1696
1697 switch (note->descsz)
1698 {
1699 default:
1700 return FALSE;
1701
1702 case 268: /* Linux/PPC. */
1703 /* pr_cursig */
1704 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1705
1706 /* pr_pid */
1707 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1708
1709 /* pr_reg */
1710 offset = 72;
1711 size = 192;
1712
1713 break;
1714 }
1715
1716 /* Make a ".reg/999" section. */
1717 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1718 size, note->descpos + offset);
1719 }
1720
1721 static bfd_boolean
1722 ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1723 {
1724 switch (note->descsz)
1725 {
1726 default:
1727 return FALSE;
1728
1729 case 128: /* Linux/PPC elf_prpsinfo. */
1730 elf_tdata (abfd)->core_program
1731 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
1732 elf_tdata (abfd)->core_command
1733 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
1734 }
1735
1736 /* Note that for some reason, a spurious space is tacked
1737 onto the end of the args in some (at least one anyway)
1738 implementations, so strip it off if it exists. */
1739
1740 {
1741 char *command = elf_tdata (abfd)->core_command;
1742 int n = strlen (command);
1743
1744 if (0 < n && command[n - 1] == ' ')
1745 command[n - 1] = '\0';
1746 }
1747
1748 return TRUE;
1749 }
1750
1751 /* Return address for Ith PLT stub in section PLT, for relocation REL
1752 or (bfd_vma) -1 if it should not be included. */
1753
1754 static bfd_vma
1755 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
1756 const asection *plt ATTRIBUTE_UNUSED,
1757 const arelent *rel)
1758 {
1759 return rel->address;
1760 }
1761
1762 /* Handle a PowerPC specific section when reading an object file. This
1763 is called when bfd_section_from_shdr finds a section with an unknown
1764 type. */
1765
1766 static bfd_boolean
1767 ppc_elf_section_from_shdr (bfd *abfd,
1768 Elf_Internal_Shdr *hdr,
1769 const char *name,
1770 int shindex)
1771 {
1772 asection *newsect;
1773 flagword flags;
1774
1775 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1776 return FALSE;
1777
1778 newsect = hdr->bfd_section;
1779 flags = bfd_get_section_flags (abfd, newsect);
1780 if (hdr->sh_flags & SHF_EXCLUDE)
1781 flags |= SEC_EXCLUDE;
1782
1783 if (hdr->sh_type == SHT_ORDERED)
1784 flags |= SEC_SORT_ENTRIES;
1785
1786 bfd_set_section_flags (abfd, newsect, flags);
1787 return TRUE;
1788 }
1789
1790 /* Set up any other section flags and such that may be necessary. */
1791
1792 static bfd_boolean
1793 ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
1794 Elf_Internal_Shdr *shdr,
1795 asection *asect)
1796 {
1797 if ((asect->flags & SEC_EXCLUDE) != 0)
1798 shdr->sh_flags |= SHF_EXCLUDE;
1799
1800 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1801 shdr->sh_type = SHT_ORDERED;
1802
1803 return TRUE;
1804 }
1805
1806 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1807 need to bump up the number of section headers. */
1808
1809 static int
1810 ppc_elf_additional_program_headers (bfd *abfd)
1811 {
1812 asection *s;
1813 int ret = 0;
1814
1815 s = bfd_get_section_by_name (abfd, ".sbss2");
1816 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
1817 ++ret;
1818
1819 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
1820 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
1821 ++ret;
1822
1823 return ret;
1824 }
1825
1826 /* Add extra PPC sections -- Note, for now, make .sbss2 and
1827 .PPC.EMB.sbss0 a normal section, and not a bss section so
1828 that the linker doesn't crater when trying to make more than
1829 2 sections. */
1830
1831 static struct bfd_elf_special_section const ppc_elf_special_sections[]=
1832 {
1833 { ".tags", 5, 0, SHT_ORDERED, SHF_ALLOC },
1834 { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
1835 { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
1836 { ".sdata2", 7, -2, SHT_PROGBITS, SHF_ALLOC },
1837 { ".sbss2", 6, -2, SHT_PROGBITS, SHF_ALLOC },
1838 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE, 0 },
1839 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS, SHF_ALLOC },
1840 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS, SHF_ALLOC },
1841 { ".plt", 4, 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
1842 { NULL, 0, 0, 0, 0 }
1843 };
1844 \f
1845 /* Very simple linked list structure for recording apuinfo values. */
1846 typedef struct apuinfo_list
1847 {
1848 struct apuinfo_list *next;
1849 unsigned long value;
1850 }
1851 apuinfo_list;
1852
1853 static apuinfo_list *head;
1854
1855
1856 static void
1857 apuinfo_list_init (void)
1858 {
1859 head = NULL;
1860 }
1861
1862 static void
1863 apuinfo_list_add (unsigned long value)
1864 {
1865 apuinfo_list *entry = head;
1866
1867 while (entry != NULL)
1868 {
1869 if (entry->value == value)
1870 return;
1871 entry = entry->next;
1872 }
1873
1874 entry = bfd_malloc (sizeof (* entry));
1875 if (entry == NULL)
1876 return;
1877
1878 entry->value = value;
1879 entry->next = head;
1880 head = entry;
1881 }
1882
1883 static unsigned
1884 apuinfo_list_length (void)
1885 {
1886 apuinfo_list *entry;
1887 unsigned long count;
1888
1889 for (entry = head, count = 0;
1890 entry;
1891 entry = entry->next)
1892 ++ count;
1893
1894 return count;
1895 }
1896
1897 static inline unsigned long
1898 apuinfo_list_element (unsigned long number)
1899 {
1900 apuinfo_list * entry;
1901
1902 for (entry = head;
1903 entry && number --;
1904 entry = entry->next)
1905 ;
1906
1907 return entry ? entry->value : 0;
1908 }
1909
1910 static void
1911 apuinfo_list_finish (void)
1912 {
1913 apuinfo_list *entry;
1914
1915 for (entry = head; entry;)
1916 {
1917 apuinfo_list *next = entry->next;
1918 free (entry);
1919 entry = next;
1920 }
1921
1922 head = NULL;
1923 }
1924
1925 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
1926 #define APUINFO_LABEL "APUinfo"
1927
1928 /* Scan the input BFDs and create a linked list of
1929 the APUinfo values that will need to be emitted. */
1930
1931 static void
1932 ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
1933 {
1934 bfd *ibfd;
1935 asection *asec;
1936 char *buffer;
1937 unsigned num_input_sections;
1938 bfd_size_type output_section_size;
1939 unsigned i;
1940 unsigned num_entries;
1941 unsigned long offset;
1942 unsigned long length;
1943 const char *error_message = NULL;
1944
1945 if (link_info == NULL)
1946 return;
1947
1948 /* Scan the input bfds, looking for apuinfo sections. */
1949 num_input_sections = 0;
1950 output_section_size = 0;
1951
1952 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
1953 {
1954 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
1955 if (asec)
1956 {
1957 ++ num_input_sections;
1958 output_section_size += asec->size;
1959 }
1960 }
1961
1962 /* We need at least one input sections
1963 in order to make merging worthwhile. */
1964 if (num_input_sections < 1)
1965 return;
1966
1967 /* Just make sure that the output section exists as well. */
1968 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
1969 if (asec == NULL)
1970 return;
1971
1972 /* Allocate a buffer for the contents of the input sections. */
1973 buffer = bfd_malloc (output_section_size);
1974 if (buffer == NULL)
1975 return;
1976
1977 offset = 0;
1978 apuinfo_list_init ();
1979
1980 /* Read in the input sections contents. */
1981 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
1982 {
1983 unsigned long datum;
1984 char *ptr;
1985
1986 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
1987 if (asec == NULL)
1988 continue;
1989
1990 length = asec->size;
1991 if (length < 24)
1992 {
1993 error_message = _("corrupt or empty %s section in %B");
1994 goto fail;
1995 }
1996
1997 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
1998 || (bfd_bread (buffer + offset, length, ibfd) != length))
1999 {
2000 error_message = _("unable to read in %s section from %B");
2001 goto fail;
2002 }
2003
2004 /* Process the contents of the section. */
2005 ptr = buffer + offset;
2006 error_message = _("corrupt %s section in %B");
2007
2008 /* Verify the contents of the header. Note - we have to
2009 extract the values this way in order to allow for a
2010 host whose endian-ness is different from the target. */
2011 datum = bfd_get_32 (ibfd, ptr);
2012 if (datum != sizeof APUINFO_LABEL)
2013 goto fail;
2014
2015 datum = bfd_get_32 (ibfd, ptr + 8);
2016 if (datum != 0x2)
2017 goto fail;
2018
2019 if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
2020 goto fail;
2021
2022 /* Get the number of bytes used for apuinfo entries. */
2023 datum = bfd_get_32 (ibfd, ptr + 4);
2024 if (datum + 20 != length)
2025 goto fail;
2026
2027 /* Make sure that we do not run off the end of the section. */
2028 if (offset + length > output_section_size)
2029 goto fail;
2030
2031 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2032 for (i = 0; i < datum; i += 4)
2033 apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i));
2034
2035 /* Update the offset. */
2036 offset += length;
2037 }
2038
2039 error_message = NULL;
2040
2041 /* Compute the size of the output section. */
2042 num_entries = apuinfo_list_length ();
2043 output_section_size = 20 + num_entries * 4;
2044
2045 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2046
2047 if (! bfd_set_section_size (abfd, asec, output_section_size))
2048 ibfd = abfd,
2049 error_message = _("warning: unable to set size of %s section in %B");
2050
2051 fail:
2052 free (buffer);
2053
2054 if (error_message)
2055 (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
2056 }
2057
2058 /* Prevent the output section from accumulating the input sections'
2059 contents. We have already stored this in our linked list structure. */
2060
2061 static bfd_boolean
2062 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
2063 asection *asec,
2064 bfd_byte *contents ATTRIBUTE_UNUSED)
2065 {
2066 return (apuinfo_list_length ()
2067 && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
2068 }
2069
2070 /* Finally we can generate the output section. */
2071
2072 static void
2073 ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
2074 {
2075 bfd_byte *buffer;
2076 asection *asec;
2077 unsigned i;
2078 unsigned num_entries;
2079 bfd_size_type length;
2080
2081 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2082 if (asec == NULL)
2083 return;
2084
2085 if (apuinfo_list_length () == 0)
2086 return;
2087
2088 length = asec->size;
2089 if (length < 20)
2090 return;
2091
2092 buffer = bfd_malloc (length);
2093 if (buffer == NULL)
2094 {
2095 (*_bfd_error_handler)
2096 (_("failed to allocate space for new APUinfo section."));
2097 return;
2098 }
2099
2100 /* Create the apuinfo header. */
2101 num_entries = apuinfo_list_length ();
2102 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
2103 bfd_put_32 (abfd, num_entries * 4, buffer + 4);
2104 bfd_put_32 (abfd, 0x2, buffer + 8);
2105 strcpy ((char *) buffer + 12, APUINFO_LABEL);
2106
2107 length = 20;
2108 for (i = 0; i < num_entries; i++)
2109 {
2110 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
2111 length += 4;
2112 }
2113
2114 if (length != asec->size)
2115 (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
2116
2117 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
2118 (*_bfd_error_handler) (_("failed to install new APUinfo section."));
2119
2120 free (buffer);
2121
2122 apuinfo_list_finish ();
2123 }
2124 \f
2125 /* The following functions are specific to the ELF linker, while
2126 functions above are used generally. They appear in this file more
2127 or less in the order in which they are called. eg.
2128 ppc_elf_check_relocs is called early in the link process,
2129 ppc_elf_finish_dynamic_sections is one of the last functions
2130 called. */
2131
2132 /* The PPC linker needs to keep track of the number of relocs that it
2133 decides to copy as dynamic relocs in check_relocs for each symbol.
2134 This is so that it can later discard them if they are found to be
2135 unnecessary. We store the information in a field extending the
2136 regular ELF linker hash table. */
2137
2138 struct ppc_elf_dyn_relocs
2139 {
2140 struct ppc_elf_dyn_relocs *next;
2141
2142 /* The input section of the reloc. */
2143 asection *sec;
2144
2145 /* Total number of relocs copied for the input section. */
2146 bfd_size_type count;
2147
2148 /* Number of pc-relative relocs copied for the input section. */
2149 bfd_size_type pc_count;
2150 };
2151
2152 /* Of those relocs that might be copied as dynamic relocs, this macro
2153 selects those that must be copied when linking a shared library,
2154 even when the symbol is local. */
2155
2156 #define MUST_BE_DYN_RELOC(RTYPE) \
2157 ((RTYPE) != R_PPC_REL24 \
2158 && (RTYPE) != R_PPC_REL14 \
2159 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2160 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2161 && (RTYPE) != R_PPC_REL32)
2162
2163 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2164 copying dynamic variables from a shared lib into an app's dynbss
2165 section, and instead use a dynamic relocation to point into the
2166 shared lib. */
2167 #define ELIMINATE_COPY_RELOCS 1
2168
2169 /* PPC ELF linker hash entry. */
2170
2171 struct ppc_elf_link_hash_entry
2172 {
2173 struct elf_link_hash_entry elf;
2174
2175 /* If this symbol is used in the linker created sections, the processor
2176 specific backend uses this field to map the field into the offset
2177 from the beginning of the section. */
2178 elf_linker_section_pointers_t *linker_section_pointer;
2179
2180 /* Track dynamic relocs copied for this symbol. */
2181 struct ppc_elf_dyn_relocs *dyn_relocs;
2182
2183 /* Contexts in which symbol is used in the GOT (or TOC).
2184 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2185 corresponding relocs are encountered during check_relocs.
2186 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2187 indicate the corresponding GOT entry type is not needed. */
2188 #define TLS_GD 1 /* GD reloc. */
2189 #define TLS_LD 2 /* LD reloc. */
2190 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2191 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2192 #define TLS_TLS 16 /* Any TLS reloc. */
2193 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2194 char tls_mask;
2195 };
2196
2197 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2198
2199 /* PPC ELF linker hash table. */
2200
2201 struct ppc_elf_link_hash_table
2202 {
2203 struct elf_link_hash_table elf;
2204
2205 /* Short-cuts to get to dynamic linker sections. */
2206 asection *got;
2207 asection *relgot;
2208 asection *plt;
2209 asection *relplt;
2210 asection *dynbss;
2211 asection *relbss;
2212 asection *dynsbss;
2213 asection *relsbss;
2214 elf_linker_section_t *sdata;
2215 elf_linker_section_t *sdata2;
2216 asection *sbss;
2217
2218 /* Shortcut to .__tls_get_addr. */
2219 struct elf_link_hash_entry *tls_get_addr;
2220
2221 /* TLS local dynamic got entry handling. */
2222 union {
2223 bfd_signed_vma refcount;
2224 bfd_vma offset;
2225 } tlsld_got;
2226
2227 /* Small local sym to section mapping cache. */
2228 struct sym_sec_cache sym_sec;
2229 };
2230
2231 /* Get the PPC ELF linker hash table from a link_info structure. */
2232
2233 #define ppc_elf_hash_table(p) \
2234 ((struct ppc_elf_link_hash_table *) (p)->hash)
2235
2236 /* Create an entry in a PPC ELF linker hash table. */
2237
2238 static struct bfd_hash_entry *
2239 ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2240 struct bfd_hash_table *table,
2241 const char *string)
2242 {
2243 /* Allocate the structure if it has not already been allocated by a
2244 subclass. */
2245 if (entry == NULL)
2246 {
2247 entry = bfd_hash_allocate (table,
2248 sizeof (struct ppc_elf_link_hash_entry));
2249 if (entry == NULL)
2250 return entry;
2251 }
2252
2253 /* Call the allocation method of the superclass. */
2254 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2255 if (entry != NULL)
2256 {
2257 ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
2258 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
2259 ppc_elf_hash_entry (entry)->tls_mask = 0;
2260 }
2261
2262 return entry;
2263 }
2264
2265 /* Create a PPC ELF linker hash table. */
2266
2267 static struct bfd_link_hash_table *
2268 ppc_elf_link_hash_table_create (bfd *abfd)
2269 {
2270 struct ppc_elf_link_hash_table *ret;
2271
2272 ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
2273 if (ret == NULL)
2274 return NULL;
2275
2276 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
2277 ppc_elf_link_hash_newfunc))
2278 {
2279 free (ret);
2280 return NULL;
2281 }
2282
2283 return &ret->elf.root;
2284 }
2285
2286 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2287
2288 static bfd_boolean
2289 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
2290 {
2291 struct ppc_elf_link_hash_table *htab;
2292 asection *s;
2293 flagword flags;
2294
2295 if (!_bfd_elf_create_got_section (abfd, info))
2296 return FALSE;
2297
2298 htab = ppc_elf_hash_table (info);
2299 htab->got = s = bfd_get_section_by_name (abfd, ".got");
2300 if (s == NULL)
2301 abort ();
2302
2303 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2304 | SEC_LINKER_CREATED);
2305 if (!bfd_set_section_flags (abfd, s, flags))
2306 return FALSE;
2307
2308 htab->relgot = bfd_make_section (abfd, ".rela.got");
2309 if (!htab->relgot
2310 || ! bfd_set_section_flags (abfd, htab->relgot,
2311 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2312 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2313 | SEC_READONLY))
2314 || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
2315 return FALSE;
2316
2317 return TRUE;
2318 }
2319
2320 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2321 to output sections (just like _bfd_elf_create_dynamic_sections has
2322 to create .dynbss and .rela.bss). */
2323
2324 static bfd_boolean
2325 ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2326 {
2327 struct ppc_elf_link_hash_table *htab;
2328 asection *s;
2329 flagword flags;
2330
2331 htab = ppc_elf_hash_table (info);
2332
2333 if (htab->got == NULL
2334 && !ppc_elf_create_got (abfd, info))
2335 return FALSE;
2336
2337 if (!_bfd_elf_create_dynamic_sections (abfd, info))
2338 return FALSE;
2339
2340 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2341 | SEC_LINKER_CREATED);
2342
2343 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
2344 htab->dynsbss = s = bfd_make_section (abfd, ".dynsbss");
2345 if (s == NULL
2346 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
2347 return FALSE;
2348
2349 if (! info->shared)
2350 {
2351 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
2352 htab->relsbss = s = bfd_make_section (abfd, ".rela.sbss");
2353 if (s == NULL
2354 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2355 || ! bfd_set_section_alignment (abfd, s, 2))
2356 return FALSE;
2357 }
2358
2359 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2360 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2361 if (s == NULL)
2362 abort ();
2363
2364 flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED;
2365 return bfd_set_section_flags (abfd, s, flags);
2366 }
2367
2368 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2369
2370 static void
2371 ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
2372 struct elf_link_hash_entry *dir,
2373 struct elf_link_hash_entry *ind)
2374 {
2375 struct ppc_elf_link_hash_entry *edir, *eind;
2376
2377 edir = (struct ppc_elf_link_hash_entry *) dir;
2378 eind = (struct ppc_elf_link_hash_entry *) ind;
2379
2380 if (eind->dyn_relocs != NULL)
2381 {
2382 if (edir->dyn_relocs != NULL)
2383 {
2384 struct ppc_elf_dyn_relocs **pp;
2385 struct ppc_elf_dyn_relocs *p;
2386
2387 if (ind->root.type == bfd_link_hash_indirect)
2388 abort ();
2389
2390 /* Add reloc counts against the weak sym to the strong sym
2391 list. Merge any entries against the same section. */
2392 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2393 {
2394 struct ppc_elf_dyn_relocs *q;
2395
2396 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2397 if (q->sec == p->sec)
2398 {
2399 q->pc_count += p->pc_count;
2400 q->count += p->count;
2401 *pp = p->next;
2402 break;
2403 }
2404 if (q == NULL)
2405 pp = &p->next;
2406 }
2407 *pp = edir->dyn_relocs;
2408 }
2409
2410 edir->dyn_relocs = eind->dyn_relocs;
2411 eind->dyn_relocs = NULL;
2412 }
2413
2414 edir->tls_mask |= eind->tls_mask;
2415
2416 if (ELIMINATE_COPY_RELOCS
2417 && ind->root.type != bfd_link_hash_indirect
2418 && dir->dynamic_adjusted)
2419 {
2420 /* If called to transfer flags for a weakdef during processing
2421 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
2422 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
2423 dir->ref_dynamic |= ind->ref_dynamic;
2424 dir->ref_regular |= ind->ref_regular;
2425 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
2426 dir->needs_plt |= ind->needs_plt;
2427 }
2428 else
2429 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
2430 }
2431
2432 /* Hook called by the linker routine which adds symbols from an object
2433 file. We use it to put .comm items in .sbss, and not .bss. */
2434
2435 static bfd_boolean
2436 ppc_elf_add_symbol_hook (bfd *abfd,
2437 struct bfd_link_info *info,
2438 Elf_Internal_Sym *sym,
2439 const char **namep ATTRIBUTE_UNUSED,
2440 flagword *flagsp ATTRIBUTE_UNUSED,
2441 asection **secp,
2442 bfd_vma *valp)
2443 {
2444 if (sym->st_shndx == SHN_COMMON
2445 && !info->relocatable
2446 && sym->st_size <= elf_gp_size (abfd)
2447 && (info->hash->creator == abfd->xvec
2448 || info->hash->creator == abfd->xvec->alternative_target))
2449 {
2450 /* Common symbols less than or equal to -G nn bytes are automatically
2451 put into .sbss. */
2452 struct ppc_elf_link_hash_table *htab;
2453
2454 htab = ppc_elf_hash_table (info);
2455 if (htab->sbss == NULL)
2456 {
2457 flagword flags = SEC_IS_COMMON;
2458
2459 htab->sbss = bfd_make_section_anyway (abfd, ".sbss");
2460 if (htab->sbss == NULL
2461 || ! bfd_set_section_flags (abfd, htab->sbss, flags))
2462 return FALSE;
2463 }
2464
2465 *secp = htab->sbss;
2466 *valp = sym->st_size;
2467 }
2468
2469 return TRUE;
2470 }
2471 \f
2472 /* Enumeration to specify the special section. */
2473 enum elf_linker_section_enum
2474 {
2475 LINKER_SECTION_SDATA,
2476 LINKER_SECTION_SDATA2
2477 };
2478
2479 /* Create a special linker section */
2480 static elf_linker_section_t *
2481 ppc_elf_create_linker_section (bfd *abfd,
2482 struct bfd_link_info *info,
2483 enum elf_linker_section_enum which)
2484 {
2485 elf_linker_section_t *lsect;
2486 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
2487 asection *s, *sym_sec;
2488 bfd_size_type amt;
2489 flagword flags;
2490 const char *name;
2491 const char *rel_name;
2492 const char *sym_name;
2493 bfd_vma sym_offset;
2494
2495 /* The linker creates these sections so it has somewhere to attach
2496 their respective symbols. Startup code (crt1.o) uses these symbols
2497 to initialize a register pointing to the section. If the output
2498 sections corresponding to these input sections were empty it would
2499 be OK to set the symbol to 0 (or any random number), because the
2500 associated register should never be used.
2501 FIXME: Setting a symbol this way is silly. The symbols ought to
2502 be set the same way other backends set gp. */
2503 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2504 | SEC_LINKER_CREATED);
2505 sym_offset = 32768;
2506
2507 switch (which)
2508 {
2509 default:
2510 abort ();
2511 return NULL;
2512
2513 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
2514 name = ".sdata";
2515 rel_name = ".rela.sdata";
2516 sym_name = "_SDA_BASE_";
2517 break;
2518
2519 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
2520 name = ".sdata2";
2521 rel_name = ".rela.sdata2";
2522 sym_name = "_SDA2_BASE_";
2523 flags |= SEC_READONLY;
2524 break;
2525 }
2526
2527 /* Record the first bfd that needs the special sections. */
2528 if (!htab->elf.dynobj)
2529 htab->elf.dynobj = abfd;
2530
2531 amt = sizeof (elf_linker_section_t);
2532 lsect = bfd_zalloc (htab->elf.dynobj, amt);
2533
2534 lsect->sym_offset = sym_offset;
2535
2536 /* See if the sections already exist. */
2537 sym_sec = s = bfd_get_section_by_name (htab->elf.dynobj, name);
2538 if (s == NULL || (s->flags & flags) != flags)
2539 {
2540 s = bfd_make_section_anyway (htab->elf.dynobj, name);
2541 if (s == NULL
2542 || !bfd_set_section_flags (htab->elf.dynobj, s, flags))
2543 return NULL;
2544 if (sym_sec == NULL)
2545 sym_sec = s;
2546 }
2547 lsect->section = s;
2548
2549 if (bfd_get_section_alignment (htab->elf.dynobj, s) < 2
2550 && !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
2551 return NULL;
2552
2553 s->size = align_power (s->size, 2);
2554
2555 #ifdef DEBUG
2556 fprintf (stderr, "Creating section %s, current size = %ld\n",
2557 name, (long) s->size);
2558 #endif
2559
2560 if (sym_name)
2561 {
2562 struct elf_link_hash_entry *h;
2563 struct bfd_link_hash_entry *bh;
2564
2565 #ifdef DEBUG
2566 fprintf (stderr, "Adding %s to section %s\n", sym_name, name);
2567 #endif
2568 bh = bfd_link_hash_lookup (info->hash, sym_name,
2569 FALSE, FALSE, FALSE);
2570
2571 if ((bh == NULL || bh->type == bfd_link_hash_undefined)
2572 && !(_bfd_generic_link_add_one_symbol
2573 (info, abfd, sym_name, BSF_GLOBAL, sym_sec, sym_offset, NULL,
2574 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
2575 return NULL;
2576 h = (struct elf_link_hash_entry *) bh;
2577
2578 h->type = STT_OBJECT;
2579 lsect->sym_hash = h;
2580
2581 if (info->shared
2582 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2583 return NULL;
2584 }
2585
2586 if (info->shared)
2587 {
2588 s = bfd_make_section_anyway (htab->elf.dynobj, rel_name);
2589 lsect->rel_section = s;
2590 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2591 | SEC_LINKER_CREATED | SEC_READONLY);
2592 if (s == NULL
2593 || ! bfd_set_section_flags (htab->elf.dynobj, s, flags)
2594 || ! bfd_set_section_alignment (htab->elf.dynobj, s, 2))
2595 return NULL;
2596 }
2597
2598 return lsect;
2599 }
2600
2601 /* Find a linker generated pointer with a given addend and type. */
2602
2603 static elf_linker_section_pointers_t *
2604 elf_find_pointer_linker_section
2605 (elf_linker_section_pointers_t *linker_pointers,
2606 bfd_vma addend,
2607 elf_linker_section_t *lsect)
2608 {
2609 for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
2610 if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
2611 return linker_pointers;
2612
2613 return NULL;
2614 }
2615
2616 /* Allocate a pointer to live in a linker created section. */
2617
2618 static bfd_boolean
2619 elf_create_pointer_linker_section (bfd *abfd,
2620 struct bfd_link_info *info,
2621 elf_linker_section_t *lsect,
2622 struct elf_link_hash_entry *h,
2623 const Elf_Internal_Rela *rel)
2624 {
2625 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
2626 elf_linker_section_pointers_t *linker_section_ptr;
2627 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
2628 bfd_size_type amt;
2629
2630 BFD_ASSERT (lsect != NULL);
2631
2632 /* Is this a global symbol? */
2633 if (h != NULL)
2634 {
2635 struct ppc_elf_link_hash_entry *eh;
2636
2637 /* Has this symbol already been allocated? If so, our work is done. */
2638 eh = (struct ppc_elf_link_hash_entry *) h;
2639 if (elf_find_pointer_linker_section (eh->linker_section_pointer,
2640 rel->r_addend,
2641 lsect))
2642 return TRUE;
2643
2644 ptr_linker_section_ptr = &eh->linker_section_pointer;
2645 /* Make sure this symbol is output as a dynamic symbol. */
2646 if (h->dynindx == -1)
2647 {
2648 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2649 return FALSE;
2650 }
2651
2652 if (lsect->rel_section)
2653 lsect->rel_section->size += sizeof (Elf32_External_Rela);
2654 }
2655 else
2656 {
2657 /* Allocation of a pointer to a local symbol. */
2658 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
2659
2660 /* Allocate a table to hold the local symbols if first time. */
2661 if (!ptr)
2662 {
2663 unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info;
2664
2665 amt = num_symbols;
2666 amt *= sizeof (elf_linker_section_pointers_t *);
2667 ptr = bfd_zalloc (abfd, amt);
2668
2669 if (!ptr)
2670 return FALSE;
2671
2672 elf_local_ptr_offsets (abfd) = ptr;
2673 }
2674
2675 /* Has this symbol already been allocated? If so, our work is done. */
2676 if (elf_find_pointer_linker_section (ptr[r_symndx],
2677 rel->r_addend,
2678 lsect))
2679 return TRUE;
2680
2681 ptr_linker_section_ptr = &ptr[r_symndx];
2682
2683 if (info->shared)
2684 {
2685 /* If we are generating a shared object, we need to
2686 output a R_<xxx>_RELATIVE reloc so that the
2687 dynamic linker can adjust this GOT entry. */
2688 BFD_ASSERT (lsect->rel_section != NULL);
2689 lsect->rel_section->size += sizeof (Elf32_External_Rela);
2690 }
2691 }
2692
2693 /* Allocate space for a pointer in the linker section, and allocate
2694 a new pointer record from internal memory. */
2695 BFD_ASSERT (ptr_linker_section_ptr != NULL);
2696 amt = sizeof (elf_linker_section_pointers_t);
2697 linker_section_ptr = bfd_alloc (abfd, amt);
2698
2699 if (!linker_section_ptr)
2700 return FALSE;
2701
2702 linker_section_ptr->next = *ptr_linker_section_ptr;
2703 linker_section_ptr->addend = rel->r_addend;
2704 linker_section_ptr->lsect = lsect;
2705 linker_section_ptr->written_address_p = FALSE;
2706 *ptr_linker_section_ptr = linker_section_ptr;
2707
2708 linker_section_ptr->offset = lsect->section->size;
2709 lsect->section->size += 4;
2710
2711 #ifdef DEBUG
2712 fprintf (stderr,
2713 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2714 lsect->name, (long) linker_section_ptr->offset,
2715 (long) lsect->section->size);
2716 #endif
2717
2718 return TRUE;
2719 }
2720
2721 static bfd_boolean
2722 update_local_sym_info (bfd *abfd,
2723 Elf_Internal_Shdr *symtab_hdr,
2724 unsigned long r_symndx,
2725 int tls_type)
2726 {
2727 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
2728 char *local_got_tls_masks;
2729
2730 if (local_got_refcounts == NULL)
2731 {
2732 bfd_size_type size = symtab_hdr->sh_info;
2733
2734 size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
2735 local_got_refcounts = bfd_zalloc (abfd, size);
2736 if (local_got_refcounts == NULL)
2737 return FALSE;
2738 elf_local_got_refcounts (abfd) = local_got_refcounts;
2739 }
2740
2741 local_got_refcounts[r_symndx] += 1;
2742 local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
2743 local_got_tls_masks[r_symndx] |= tls_type;
2744 return TRUE;
2745 }
2746
2747 static void
2748 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
2749 {
2750 (*_bfd_error_handler)
2751 (_("%B: relocation %s cannot be used when making a shared object"),
2752 abfd,
2753 ppc_elf_howto_table[r_type]->name);
2754 bfd_set_error (bfd_error_bad_value);
2755 }
2756
2757 /* Look through the relocs for a section during the first phase, and
2758 allocate space in the global offset table or procedure linkage
2759 table. */
2760
2761 static bfd_boolean
2762 ppc_elf_check_relocs (bfd *abfd,
2763 struct bfd_link_info *info,
2764 asection *sec,
2765 const Elf_Internal_Rela *relocs)
2766 {
2767 struct ppc_elf_link_hash_table *htab;
2768 Elf_Internal_Shdr *symtab_hdr;
2769 struct elf_link_hash_entry **sym_hashes;
2770 const Elf_Internal_Rela *rel;
2771 const Elf_Internal_Rela *rel_end;
2772 asection *sreloc;
2773
2774 if (info->relocatable)
2775 return TRUE;
2776
2777 #ifdef DEBUG
2778 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
2779 sec, abfd);
2780 #endif
2781
2782 /* Initialize howto table if not already done. */
2783 if (!ppc_elf_howto_table[R_PPC_ADDR32])
2784 ppc_elf_howto_init ();
2785
2786 /* Create the linker generated sections all the time so that the
2787 special symbols are created. */
2788 htab = ppc_elf_hash_table (info);
2789 if (htab->sdata == NULL)
2790 {
2791 htab->sdata = ppc_elf_create_linker_section (abfd, info,
2792 LINKER_SECTION_SDATA);
2793 if (htab->sdata == NULL)
2794 return FALSE;
2795 }
2796
2797 if (htab->sdata2 == NULL)
2798 {
2799 htab->sdata2 = ppc_elf_create_linker_section (abfd, info,
2800 LINKER_SECTION_SDATA2);
2801 if (htab->sdata2 == NULL)
2802 return FALSE;
2803 }
2804
2805 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2806 sym_hashes = elf_sym_hashes (abfd);
2807 sreloc = NULL;
2808
2809 rel_end = relocs + sec->reloc_count;
2810 for (rel = relocs; rel < rel_end; rel++)
2811 {
2812 unsigned long r_symndx;
2813 enum elf_ppc_reloc_type r_type;
2814 struct elf_link_hash_entry *h;
2815 int tls_type = 0;
2816
2817 r_symndx = ELF32_R_SYM (rel->r_info);
2818 if (r_symndx < symtab_hdr->sh_info)
2819 h = NULL;
2820 else
2821 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2822
2823 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2824 This shows up in particular in an R_PPC_ADDR32 in the eabi
2825 startup code. */
2826 if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2827 {
2828 if (htab->got == NULL)
2829 {
2830 if (htab->elf.dynobj == NULL)
2831 htab->elf.dynobj = abfd;
2832 if (!ppc_elf_create_got (htab->elf.dynobj, info))
2833 return FALSE;
2834 }
2835 }
2836
2837 r_type = ELF32_R_TYPE (rel->r_info);
2838 switch (r_type)
2839 {
2840 case R_PPC_GOT_TLSLD16:
2841 case R_PPC_GOT_TLSLD16_LO:
2842 case R_PPC_GOT_TLSLD16_HI:
2843 case R_PPC_GOT_TLSLD16_HA:
2844 htab->tlsld_got.refcount += 1;
2845 tls_type = TLS_TLS | TLS_LD;
2846 goto dogottls;
2847
2848 case R_PPC_GOT_TLSGD16:
2849 case R_PPC_GOT_TLSGD16_LO:
2850 case R_PPC_GOT_TLSGD16_HI:
2851 case R_PPC_GOT_TLSGD16_HA:
2852 tls_type = TLS_TLS | TLS_GD;
2853 goto dogottls;
2854
2855 case R_PPC_GOT_TPREL16:
2856 case R_PPC_GOT_TPREL16_LO:
2857 case R_PPC_GOT_TPREL16_HI:
2858 case R_PPC_GOT_TPREL16_HA:
2859 if (info->shared)
2860 info->flags |= DF_STATIC_TLS;
2861 tls_type = TLS_TLS | TLS_TPREL;
2862 goto dogottls;
2863
2864 case R_PPC_GOT_DTPREL16:
2865 case R_PPC_GOT_DTPREL16_LO:
2866 case R_PPC_GOT_DTPREL16_HI:
2867 case R_PPC_GOT_DTPREL16_HA:
2868 tls_type = TLS_TLS | TLS_DTPREL;
2869 dogottls:
2870 sec->has_tls_reloc = 1;
2871 /* Fall thru */
2872
2873 /* GOT16 relocations */
2874 case R_PPC_GOT16:
2875 case R_PPC_GOT16_LO:
2876 case R_PPC_GOT16_HI:
2877 case R_PPC_GOT16_HA:
2878 /* This symbol requires a global offset table entry. */
2879 if (htab->got == NULL)
2880 {
2881 if (htab->elf.dynobj == NULL)
2882 htab->elf.dynobj = abfd;
2883 if (!ppc_elf_create_got (htab->elf.dynobj, info))
2884 return FALSE;
2885 }
2886 if (h != NULL)
2887 {
2888 h->got.refcount += 1;
2889 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
2890 }
2891 else
2892 /* This is a global offset table entry for a local symbol. */
2893 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
2894 return FALSE;
2895 break;
2896
2897 /* Indirect .sdata relocation. */
2898 case R_PPC_EMB_SDAI16:
2899 if (info->shared)
2900 {
2901 bad_shared_reloc (abfd, r_type);
2902 return FALSE;
2903 }
2904 if (!elf_create_pointer_linker_section (abfd, info,
2905 htab->sdata, h, rel))
2906 return FALSE;
2907 break;
2908
2909 /* Indirect .sdata2 relocation. */
2910 case R_PPC_EMB_SDA2I16:
2911 if (info->shared)
2912 {
2913 bad_shared_reloc (abfd, r_type);
2914 return FALSE;
2915 }
2916 if (!elf_create_pointer_linker_section (abfd, info,
2917 htab->sdata2, h, rel))
2918 return FALSE;
2919 break;
2920
2921 case R_PPC_SDAREL16:
2922 case R_PPC_EMB_SDA2REL:
2923 case R_PPC_EMB_SDA21:
2924 case R_PPC_EMB_RELSDA:
2925 case R_PPC_EMB_NADDR32:
2926 case R_PPC_EMB_NADDR16:
2927 case R_PPC_EMB_NADDR16_LO:
2928 case R_PPC_EMB_NADDR16_HI:
2929 case R_PPC_EMB_NADDR16_HA:
2930 if (info->shared)
2931 {
2932 bad_shared_reloc (abfd, r_type);
2933 return FALSE;
2934 }
2935 break;
2936
2937 case R_PPC_PLT32:
2938 case R_PPC_PLTREL24:
2939 case R_PPC_PLTREL32:
2940 case R_PPC_PLT16_LO:
2941 case R_PPC_PLT16_HI:
2942 case R_PPC_PLT16_HA:
2943 #ifdef DEBUG
2944 fprintf (stderr, "Reloc requires a PLT entry\n");
2945 #endif
2946 /* This symbol requires a procedure linkage table entry. We
2947 actually build the entry in finish_dynamic_symbol,
2948 because this might be a case of linking PIC code without
2949 linking in any dynamic objects, in which case we don't
2950 need to generate a procedure linkage table after all. */
2951
2952 if (h == NULL)
2953 {
2954 /* It does not make sense to have a procedure linkage
2955 table entry for a local symbol. */
2956 (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against "
2957 "local symbol"),
2958 abfd,
2959 sec,
2960 (long) rel->r_offset,
2961 ppc_elf_howto_table[r_type]->name);
2962 bfd_set_error (bfd_error_bad_value);
2963 return FALSE;
2964 }
2965
2966 h->needs_plt = 1;
2967 h->plt.refcount++;
2968 break;
2969
2970 /* The following relocations don't need to propagate the
2971 relocation if linking a shared object since they are
2972 section relative. */
2973 case R_PPC_SECTOFF:
2974 case R_PPC_SECTOFF_LO:
2975 case R_PPC_SECTOFF_HI:
2976 case R_PPC_SECTOFF_HA:
2977 case R_PPC_DTPREL16:
2978 case R_PPC_DTPREL16_LO:
2979 case R_PPC_DTPREL16_HI:
2980 case R_PPC_DTPREL16_HA:
2981 case R_PPC_TOC16:
2982 break;
2983
2984 /* This are just markers. */
2985 case R_PPC_TLS:
2986 case R_PPC_EMB_MRKREF:
2987 case R_PPC_NONE:
2988 case R_PPC_max:
2989 break;
2990
2991 /* These should only appear in dynamic objects. */
2992 case R_PPC_COPY:
2993 case R_PPC_GLOB_DAT:
2994 case R_PPC_JMP_SLOT:
2995 case R_PPC_RELATIVE:
2996 break;
2997
2998 /* These aren't handled yet. We'll report an error later. */
2999 case R_PPC_ADDR30:
3000 case R_PPC_EMB_RELSEC16:
3001 case R_PPC_EMB_RELST_LO:
3002 case R_PPC_EMB_RELST_HI:
3003 case R_PPC_EMB_RELST_HA:
3004 case R_PPC_EMB_BIT_FLD:
3005 break;
3006
3007 /* This refers only to functions defined in the shared library. */
3008 case R_PPC_LOCAL24PC:
3009 break;
3010
3011 /* This relocation describes the C++ object vtable hierarchy.
3012 Reconstruct it for later use during GC. */
3013 case R_PPC_GNU_VTINHERIT:
3014 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3015 return FALSE;
3016 break;
3017
3018 /* This relocation describes which C++ vtable entries are actually
3019 used. Record for later use during GC. */
3020 case R_PPC_GNU_VTENTRY:
3021 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3022 return FALSE;
3023 break;
3024
3025 /* We shouldn't really be seeing these. */
3026 case R_PPC_TPREL32:
3027 if (info->shared)
3028 info->flags |= DF_STATIC_TLS;
3029 goto dodyn;
3030
3031 /* Nor these. */
3032 case R_PPC_DTPMOD32:
3033 case R_PPC_DTPREL32:
3034 goto dodyn;
3035
3036 case R_PPC_TPREL16:
3037 case R_PPC_TPREL16_LO:
3038 case R_PPC_TPREL16_HI:
3039 case R_PPC_TPREL16_HA:
3040 if (info->shared)
3041 info->flags |= DF_STATIC_TLS;
3042 goto dodyn;
3043
3044 /* When creating a shared object, we must copy these
3045 relocs into the output file. We create a reloc
3046 section in dynobj and make room for the reloc. */
3047 case R_PPC_REL24:
3048 case R_PPC_REL14:
3049 case R_PPC_REL14_BRTAKEN:
3050 case R_PPC_REL14_BRNTAKEN:
3051 case R_PPC_REL32:
3052 if (h == NULL
3053 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3054 break;
3055 /* fall through */
3056
3057 case R_PPC_ADDR32:
3058 case R_PPC_ADDR24:
3059 case R_PPC_ADDR16:
3060 case R_PPC_ADDR16_LO:
3061 case R_PPC_ADDR16_HI:
3062 case R_PPC_ADDR16_HA:
3063 case R_PPC_ADDR14:
3064 case R_PPC_ADDR14_BRTAKEN:
3065 case R_PPC_ADDR14_BRNTAKEN:
3066 case R_PPC_UADDR32:
3067 case R_PPC_UADDR16:
3068 if (h != NULL && !info->shared)
3069 {
3070 /* We may need a plt entry if the symbol turns out to be
3071 a function defined in a dynamic object. */
3072 h->plt.refcount++;
3073
3074 /* We may need a copy reloc too. */
3075 h->non_got_ref = 1;
3076 }
3077
3078 dodyn:
3079 /* If we are creating a shared library, and this is a reloc
3080 against a global symbol, or a non PC relative reloc
3081 against a local symbol, then we need to copy the reloc
3082 into the shared library. However, if we are linking with
3083 -Bsymbolic, we do not need to copy a reloc against a
3084 global symbol which is defined in an object we are
3085 including in the link (i.e., DEF_REGULAR is set). At
3086 this point we have not seen all the input files, so it is
3087 possible that DEF_REGULAR is not set now but will be set
3088 later (it is never cleared). In case of a weak definition,
3089 DEF_REGULAR may be cleared later by a strong definition in
3090 a shared library. We account for that possibility below by
3091 storing information in the dyn_relocs field of the hash
3092 table entry. A similar situation occurs when creating
3093 shared libraries and symbol visibility changes render the
3094 symbol local.
3095
3096 If on the other hand, we are creating an executable, we
3097 may need to keep relocations for symbols satisfied by a
3098 dynamic library if we manage to avoid copy relocs for the
3099 symbol. */
3100 if ((info->shared
3101 && (MUST_BE_DYN_RELOC (r_type)
3102 || (h != NULL
3103 && (! info->symbolic
3104 || h->root.type == bfd_link_hash_defweak
3105 || !h->def_regular))))
3106 || (ELIMINATE_COPY_RELOCS
3107 && !info->shared
3108 && (sec->flags & SEC_ALLOC) != 0
3109 && h != NULL
3110 && (h->root.type == bfd_link_hash_defweak
3111 || !h->def_regular)))
3112 {
3113 struct ppc_elf_dyn_relocs *p;
3114 struct ppc_elf_dyn_relocs **head;
3115
3116 #ifdef DEBUG
3117 fprintf (stderr,
3118 "ppc_elf_check_relocs needs to "
3119 "create relocation for %s\n",
3120 (h && h->root.root.string
3121 ? h->root.root.string : "<unknown>"));
3122 #endif
3123 if (sreloc == NULL)
3124 {
3125 const char *name;
3126
3127 name = (bfd_elf_string_from_elf_section
3128 (abfd,
3129 elf_elfheader (abfd)->e_shstrndx,
3130 elf_section_data (sec)->rel_hdr.sh_name));
3131 if (name == NULL)
3132 return FALSE;
3133
3134 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3135 && strcmp (bfd_get_section_name (abfd, sec),
3136 name + 5) == 0);
3137
3138 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
3139 if (sreloc == NULL)
3140 {
3141 flagword flags;
3142
3143 sreloc = bfd_make_section (htab->elf.dynobj, name);
3144 flags = (SEC_HAS_CONTENTS | SEC_READONLY
3145 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3146 if ((sec->flags & SEC_ALLOC) != 0)
3147 flags |= SEC_ALLOC | SEC_LOAD;
3148 if (sreloc == NULL
3149 || ! bfd_set_section_flags (htab->elf.dynobj,
3150 sreloc, flags)
3151 || ! bfd_set_section_alignment (htab->elf.dynobj,
3152 sreloc, 2))
3153 return FALSE;
3154 }
3155 elf_section_data (sec)->sreloc = sreloc;
3156 }
3157
3158 /* If this is a global symbol, we count the number of
3159 relocations we need for this symbol. */
3160 if (h != NULL)
3161 {
3162 head = &ppc_elf_hash_entry (h)->dyn_relocs;
3163 }
3164 else
3165 {
3166 /* Track dynamic relocs needed for local syms too.
3167 We really need local syms available to do this
3168 easily. Oh well. */
3169
3170 asection *s;
3171 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
3172 sec, r_symndx);
3173 if (s == NULL)
3174 return FALSE;
3175
3176 head = ((struct ppc_elf_dyn_relocs **)
3177 &elf_section_data (s)->local_dynrel);
3178 }
3179
3180 p = *head;
3181 if (p == NULL || p->sec != sec)
3182 {
3183 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
3184 if (p == NULL)
3185 return FALSE;
3186 p->next = *head;
3187 *head = p;
3188 p->sec = sec;
3189 p->count = 0;
3190 p->pc_count = 0;
3191 }
3192
3193 p->count += 1;
3194 if (!MUST_BE_DYN_RELOC (r_type))
3195 p->pc_count += 1;
3196 }
3197
3198 break;
3199 }
3200 }
3201
3202 return TRUE;
3203 }
3204 \f
3205 /* Return the section that should be marked against GC for a given
3206 relocation. */
3207
3208 static asection *
3209 ppc_elf_gc_mark_hook (asection *sec,
3210 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3211 Elf_Internal_Rela *rel,
3212 struct elf_link_hash_entry *h,
3213 Elf_Internal_Sym *sym)
3214 {
3215 if (h != NULL)
3216 {
3217 switch (ELF32_R_TYPE (rel->r_info))
3218 {
3219 case R_PPC_GNU_VTINHERIT:
3220 case R_PPC_GNU_VTENTRY:
3221 break;
3222
3223 default:
3224 switch (h->root.type)
3225 {
3226 case bfd_link_hash_defined:
3227 case bfd_link_hash_defweak:
3228 return h->root.u.def.section;
3229
3230 case bfd_link_hash_common:
3231 return h->root.u.c.p->section;
3232
3233 default:
3234 break;
3235 }
3236 }
3237 }
3238 else
3239 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
3240
3241 return NULL;
3242 }
3243
3244 /* Update the got, plt and dynamic reloc reference counts for the
3245 section being removed. */
3246
3247 static bfd_boolean
3248 ppc_elf_gc_sweep_hook (bfd *abfd,
3249 struct bfd_link_info *info,
3250 asection *sec,
3251 const Elf_Internal_Rela *relocs)
3252 {
3253 struct ppc_elf_link_hash_table *htab;
3254 Elf_Internal_Shdr *symtab_hdr;
3255 struct elf_link_hash_entry **sym_hashes;
3256 bfd_signed_vma *local_got_refcounts;
3257 const Elf_Internal_Rela *rel, *relend;
3258
3259 elf_section_data (sec)->local_dynrel = NULL;
3260
3261 htab = ppc_elf_hash_table (info);
3262 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3263 sym_hashes = elf_sym_hashes (abfd);
3264 local_got_refcounts = elf_local_got_refcounts (abfd);
3265
3266 relend = relocs + sec->reloc_count;
3267 for (rel = relocs; rel < relend; rel++)
3268 {
3269 unsigned long r_symndx;
3270 enum elf_ppc_reloc_type r_type;
3271 struct elf_link_hash_entry *h = NULL;
3272
3273 r_symndx = ELF32_R_SYM (rel->r_info);
3274 if (r_symndx >= symtab_hdr->sh_info)
3275 {
3276 struct ppc_elf_dyn_relocs **pp, *p;
3277 struct ppc_elf_link_hash_entry *eh;
3278
3279 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3280 while (h->root.type == bfd_link_hash_indirect
3281 || h->root.type == bfd_link_hash_warning)
3282 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3283 eh = (struct ppc_elf_link_hash_entry *) h;
3284
3285 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3286 if (p->sec == sec)
3287 {
3288 /* Everything must go for SEC. */
3289 *pp = p->next;
3290 break;
3291 }
3292 }
3293
3294 r_type = ELF32_R_TYPE (rel->r_info);
3295 switch (r_type)
3296 {
3297 case R_PPC_GOT_TLSLD16:
3298 case R_PPC_GOT_TLSLD16_LO:
3299 case R_PPC_GOT_TLSLD16_HI:
3300 case R_PPC_GOT_TLSLD16_HA:
3301 htab->tlsld_got.refcount -= 1;
3302 /* Fall thru */
3303
3304 case R_PPC_GOT_TLSGD16:
3305 case R_PPC_GOT_TLSGD16_LO:
3306 case R_PPC_GOT_TLSGD16_HI:
3307 case R_PPC_GOT_TLSGD16_HA:
3308 case R_PPC_GOT_TPREL16:
3309 case R_PPC_GOT_TPREL16_LO:
3310 case R_PPC_GOT_TPREL16_HI:
3311 case R_PPC_GOT_TPREL16_HA:
3312 case R_PPC_GOT_DTPREL16:
3313 case R_PPC_GOT_DTPREL16_LO:
3314 case R_PPC_GOT_DTPREL16_HI:
3315 case R_PPC_GOT_DTPREL16_HA:
3316 case R_PPC_GOT16:
3317 case R_PPC_GOT16_LO:
3318 case R_PPC_GOT16_HI:
3319 case R_PPC_GOT16_HA:
3320 if (h != NULL)
3321 {
3322 if (h->got.refcount > 0)
3323 h->got.refcount--;
3324 }
3325 else if (local_got_refcounts != NULL)
3326 {
3327 if (local_got_refcounts[r_symndx] > 0)
3328 local_got_refcounts[r_symndx]--;
3329 }
3330 break;
3331
3332 case R_PPC_REL24:
3333 case R_PPC_REL14:
3334 case R_PPC_REL14_BRTAKEN:
3335 case R_PPC_REL14_BRNTAKEN:
3336 case R_PPC_REL32:
3337 if (h == NULL
3338 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3339 break;
3340 /* Fall thru */
3341
3342 case R_PPC_ADDR32:
3343 case R_PPC_ADDR24:
3344 case R_PPC_ADDR16:
3345 case R_PPC_ADDR16_LO:
3346 case R_PPC_ADDR16_HI:
3347 case R_PPC_ADDR16_HA:
3348 case R_PPC_ADDR14:
3349 case R_PPC_ADDR14_BRTAKEN:
3350 case R_PPC_ADDR14_BRNTAKEN:
3351 case R_PPC_UADDR32:
3352 case R_PPC_UADDR16:
3353 case R_PPC_PLT32:
3354 case R_PPC_PLTREL24:
3355 case R_PPC_PLT16_LO:
3356 case R_PPC_PLT16_HI:
3357 case R_PPC_PLT16_HA:
3358 if (h != NULL)
3359 {
3360 if (h->plt.refcount > 0)
3361 h->plt.refcount--;
3362 }
3363 break;
3364
3365 default:
3366 break;
3367 }
3368 }
3369 return TRUE;
3370 }
3371 \f
3372 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
3373
3374 asection *
3375 ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
3376 {
3377 struct ppc_elf_link_hash_table *htab;
3378
3379 htab = ppc_elf_hash_table (info);
3380 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3381 FALSE, FALSE, TRUE);
3382
3383 return _bfd_elf_tls_setup (obfd, info);
3384 }
3385
3386 /* Run through all the TLS relocs looking for optimization
3387 opportunities. */
3388
3389 bfd_boolean
3390 ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
3391 struct bfd_link_info *info)
3392 {
3393 bfd *ibfd;
3394 asection *sec;
3395 struct ppc_elf_link_hash_table *htab;
3396
3397 if (info->relocatable || info->shared)
3398 return TRUE;
3399
3400 htab = ppc_elf_hash_table (info);
3401 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3402 {
3403 Elf_Internal_Sym *locsyms = NULL;
3404 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3405
3406 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
3407 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
3408 {
3409 Elf_Internal_Rela *relstart, *rel, *relend;
3410 int expecting_tls_get_addr;
3411
3412 /* Read the relocations. */
3413 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
3414 info->keep_memory);
3415 if (relstart == NULL)
3416 return FALSE;
3417
3418 expecting_tls_get_addr = 0;
3419 relend = relstart + sec->reloc_count;
3420 for (rel = relstart; rel < relend; rel++)
3421 {
3422 enum elf_ppc_reloc_type r_type;
3423 unsigned long r_symndx;
3424 struct elf_link_hash_entry *h = NULL;
3425 char *tls_mask;
3426 char tls_set, tls_clear;
3427 bfd_boolean is_local;
3428
3429 r_symndx = ELF32_R_SYM (rel->r_info);
3430 if (r_symndx >= symtab_hdr->sh_info)
3431 {
3432 struct elf_link_hash_entry **sym_hashes;
3433
3434 sym_hashes = elf_sym_hashes (ibfd);
3435 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3436 while (h->root.type == bfd_link_hash_indirect
3437 || h->root.type == bfd_link_hash_warning)
3438 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3439 }
3440
3441 is_local = FALSE;
3442 if (h == NULL
3443 || !h->def_dynamic)
3444 is_local = TRUE;
3445
3446 r_type = ELF32_R_TYPE (rel->r_info);
3447 switch (r_type)
3448 {
3449 case R_PPC_GOT_TLSLD16:
3450 case R_PPC_GOT_TLSLD16_LO:
3451 case R_PPC_GOT_TLSLD16_HI:
3452 case R_PPC_GOT_TLSLD16_HA:
3453 /* These relocs should never be against a symbol
3454 defined in a shared lib. Leave them alone if
3455 that turns out to be the case. */
3456 expecting_tls_get_addr = 0;
3457 htab->tlsld_got.refcount -= 1;
3458 if (!is_local)
3459 continue;
3460
3461 /* LD -> LE */
3462 tls_set = 0;
3463 tls_clear = TLS_LD;
3464 expecting_tls_get_addr = 1;
3465 break;
3466
3467 case R_PPC_GOT_TLSGD16:
3468 case R_PPC_GOT_TLSGD16_LO:
3469 case R_PPC_GOT_TLSGD16_HI:
3470 case R_PPC_GOT_TLSGD16_HA:
3471 if (is_local)
3472 /* GD -> LE */
3473 tls_set = 0;
3474 else
3475 /* GD -> IE */
3476 tls_set = TLS_TLS | TLS_TPRELGD;
3477 tls_clear = TLS_GD;
3478 expecting_tls_get_addr = 1;
3479 break;
3480
3481 case R_PPC_GOT_TPREL16:
3482 case R_PPC_GOT_TPREL16_LO:
3483 case R_PPC_GOT_TPREL16_HI:
3484 case R_PPC_GOT_TPREL16_HA:
3485 expecting_tls_get_addr = 0;
3486 if (is_local)
3487 {
3488 /* IE -> LE */
3489 tls_set = 0;
3490 tls_clear = TLS_TPREL;
3491 break;
3492 }
3493 else
3494 continue;
3495
3496 case R_PPC_REL14:
3497 case R_PPC_REL14_BRTAKEN:
3498 case R_PPC_REL14_BRNTAKEN:
3499 case R_PPC_REL24:
3500 if (expecting_tls_get_addr
3501 && h != NULL
3502 && h == htab->tls_get_addr)
3503 {
3504 if (h->plt.refcount > 0)
3505 h->plt.refcount -= 1;
3506 }
3507 expecting_tls_get_addr = 0;
3508 continue;
3509
3510 default:
3511 expecting_tls_get_addr = 0;
3512 continue;
3513 }
3514
3515 if (h != NULL)
3516 {
3517 if (tls_set == 0)
3518 {
3519 /* We managed to get rid of a got entry. */
3520 if (h->got.refcount > 0)
3521 h->got.refcount -= 1;
3522 }
3523 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
3524 }
3525 else
3526 {
3527 Elf_Internal_Sym *sym;
3528 bfd_signed_vma *lgot_refs;
3529 char *lgot_masks;
3530
3531 if (locsyms == NULL)
3532 {
3533 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
3534 if (locsyms == NULL)
3535 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
3536 symtab_hdr->sh_info,
3537 0, NULL, NULL, NULL);
3538 if (locsyms == NULL)
3539 {
3540 if (elf_section_data (sec)->relocs != relstart)
3541 free (relstart);
3542 return FALSE;
3543 }
3544 }
3545 sym = locsyms + r_symndx;
3546 lgot_refs = elf_local_got_refcounts (ibfd);
3547 if (lgot_refs == NULL)
3548 abort ();
3549 if (tls_set == 0)
3550 {
3551 /* We managed to get rid of a got entry. */
3552 if (lgot_refs[r_symndx] > 0)
3553 lgot_refs[r_symndx] -= 1;
3554 }
3555 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
3556 tls_mask = &lgot_masks[r_symndx];
3557 }
3558
3559 *tls_mask |= tls_set;
3560 *tls_mask &= ~tls_clear;
3561 }
3562
3563 if (elf_section_data (sec)->relocs != relstart)
3564 free (relstart);
3565 }
3566
3567 if (locsyms != NULL
3568 && (symtab_hdr->contents != (unsigned char *) locsyms))
3569 {
3570 if (!info->keep_memory)
3571 free (locsyms);
3572 else
3573 symtab_hdr->contents = (unsigned char *) locsyms;
3574 }
3575 }
3576 return TRUE;
3577 }
3578 \f
3579 /* Adjust a symbol defined by a dynamic object and referenced by a
3580 regular object. The current definition is in some section of the
3581 dynamic object, but we're not including those sections. We have to
3582 change the definition to something the rest of the link can
3583 understand. */
3584
3585 static bfd_boolean
3586 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3587 struct elf_link_hash_entry *h)
3588 {
3589 struct ppc_elf_link_hash_table *htab;
3590 asection *s;
3591 unsigned int power_of_two;
3592
3593 #ifdef DEBUG
3594 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
3595 h->root.root.string);
3596 #endif
3597
3598 /* Make sure we know what is going on here. */
3599 htab = ppc_elf_hash_table (info);
3600 BFD_ASSERT (htab->elf.dynobj != NULL
3601 && (h->needs_plt
3602 || h->u.weakdef != NULL
3603 || (h->def_dynamic
3604 && h->ref_regular
3605 && !h->def_regular)));
3606
3607 /* Deal with function syms. */
3608 if (h->type == STT_FUNC
3609 || h->needs_plt)
3610 {
3611 /* Clear procedure linkage table information for any symbol that
3612 won't need a .plt entry. */
3613 if (h->plt.refcount <= 0
3614 || SYMBOL_CALLS_LOCAL (info, h)
3615 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3616 && h->root.type == bfd_link_hash_undefweak))
3617 {
3618 /* A PLT entry is not required/allowed when:
3619
3620 1. We are not using ld.so; because then the PLT entry
3621 can't be set up, so we can't use one. In this case,
3622 ppc_elf_adjust_dynamic_symbol won't even be called.
3623
3624 2. GC has rendered the entry unused.
3625
3626 3. We know for certain that a call to this symbol
3627 will go to this object, or will remain undefined. */
3628 h->plt.offset = (bfd_vma) -1;
3629 h->needs_plt = 0;
3630 }
3631 return TRUE;
3632 }
3633 else
3634 h->plt.offset = (bfd_vma) -1;
3635
3636 /* If this is a weak symbol, and there is a real definition, the
3637 processor independent code will have arranged for us to see the
3638 real definition first, and we can just use the same value. */
3639 if (h->u.weakdef != NULL)
3640 {
3641 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3642 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3643 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3644 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3645 if (ELIMINATE_COPY_RELOCS)
3646 h->non_got_ref = h->u.weakdef->non_got_ref;
3647 return TRUE;
3648 }
3649
3650 /* This is a reference to a symbol defined by a dynamic object which
3651 is not a function. */
3652
3653 /* If we are creating a shared library, we must presume that the
3654 only references to the symbol are via the global offset table.
3655 For such cases we need not do anything here; the relocations will
3656 be handled correctly by relocate_section. */
3657 if (info->shared)
3658 return TRUE;
3659
3660 /* If there are no references to this symbol that do not use the
3661 GOT, we don't need to generate a copy reloc. */
3662 if (!h->non_got_ref)
3663 return TRUE;
3664
3665 if (ELIMINATE_COPY_RELOCS)
3666 {
3667 struct ppc_elf_dyn_relocs *p;
3668 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
3669 {
3670 s = p->sec->output_section;
3671 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3672 break;
3673 }
3674
3675 /* If we didn't find any dynamic relocs in read-only sections, then
3676 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3677 if (p == NULL)
3678 {
3679 h->non_got_ref = 0;
3680 return TRUE;
3681 }
3682 }
3683
3684 /* We must allocate the symbol in our .dynbss section, which will
3685 become part of the .bss section of the executable. There will be
3686 an entry for this symbol in the .dynsym section. The dynamic
3687 object will contain position independent code, so all references
3688 from the dynamic object to this symbol will go through the global
3689 offset table. The dynamic linker will use the .dynsym entry to
3690 determine the address it must put in the global offset table, so
3691 both the dynamic object and the regular object will refer to the
3692 same memory location for the variable.
3693
3694 Of course, if the symbol is sufficiently small, we must instead
3695 allocate it in .sbss. FIXME: It would be better to do this if and
3696 only if there were actually SDAREL relocs for that symbol. */
3697
3698 if (h->size <= elf_gp_size (htab->elf.dynobj))
3699 s = htab->dynsbss;
3700 else
3701 s = htab->dynbss;
3702 BFD_ASSERT (s != NULL);
3703
3704 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3705 copy the initial value out of the dynamic object and into the
3706 runtime process image. We need to remember the offset into the
3707 .rela.bss section we are going to use. */
3708 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3709 {
3710 asection *srel;
3711
3712 if (h->size <= elf_gp_size (htab->elf.dynobj))
3713 srel = htab->relsbss;
3714 else
3715 srel = htab->relbss;
3716 BFD_ASSERT (srel != NULL);
3717 srel->size += sizeof (Elf32_External_Rela);
3718 h->needs_copy = 1;
3719 }
3720
3721 /* We need to figure out the alignment required for this symbol. I
3722 have no idea how ELF linkers handle this. */
3723 power_of_two = bfd_log2 (h->size);
3724 if (power_of_two > 4)
3725 power_of_two = 4;
3726
3727 /* Apply the required alignment. */
3728 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
3729 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3730 {
3731 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3732 return FALSE;
3733 }
3734
3735 /* Define the symbol as being at this point in the section. */
3736 h->root.u.def.section = s;
3737 h->root.u.def.value = s->size;
3738
3739 /* Increment the section size to make room for the symbol. */
3740 s->size += h->size;
3741
3742 return TRUE;
3743 }
3744 \f
3745 /* Allocate space in associated reloc sections for dynamic relocs. */
3746
3747 static bfd_boolean
3748 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3749 {
3750 struct bfd_link_info *info = inf;
3751 struct ppc_elf_link_hash_entry *eh;
3752 struct ppc_elf_link_hash_table *htab;
3753 struct ppc_elf_dyn_relocs *p;
3754
3755 if (h->root.type == bfd_link_hash_indirect)
3756 return TRUE;
3757
3758 if (h->root.type == bfd_link_hash_warning)
3759 /* When warning symbols are created, they **replace** the "real"
3760 entry in the hash table, thus we never get to see the real
3761 symbol in a hash traversal. So look at it now. */
3762 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3763
3764 htab = ppc_elf_hash_table (info);
3765 if (htab->elf.dynamic_sections_created
3766 && h->plt.refcount > 0)
3767 {
3768 /* Make sure this symbol is output as a dynamic symbol. */
3769 if (h->dynindx == -1
3770 && !h->forced_local)
3771 {
3772 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3773 return FALSE;
3774 }
3775
3776 if (info->shared
3777 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3778 {
3779 asection *s = htab->plt;
3780
3781 /* If this is the first .plt entry, make room for the special
3782 first entry. */
3783 if (s->size == 0)
3784 s->size += PLT_INITIAL_ENTRY_SIZE;
3785
3786 /* The PowerPC PLT is actually composed of two parts, the
3787 first part is 2 words (for a load and a jump), and then
3788 there is a remaining word available at the end. */
3789 h->plt.offset = (PLT_INITIAL_ENTRY_SIZE
3790 + (PLT_SLOT_SIZE
3791 * ((s->size - PLT_INITIAL_ENTRY_SIZE)
3792 / PLT_ENTRY_SIZE)));
3793
3794 /* If this symbol is not defined in a regular file, and we
3795 are not generating a shared library, then set the symbol
3796 to this location in the .plt. This is required to make
3797 function pointers compare as equal between the normal
3798 executable and the shared library. */
3799 if (! info->shared
3800 && !h->def_regular)
3801 {
3802 h->root.u.def.section = s;
3803 h->root.u.def.value = h->plt.offset;
3804 }
3805
3806 /* Make room for this entry. After the 8192nd entry, room
3807 for two entries is allocated. */
3808 s->size += PLT_ENTRY_SIZE;
3809 if ((s->size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
3810 > PLT_NUM_SINGLE_ENTRIES)
3811 s->size += PLT_ENTRY_SIZE;
3812
3813 /* We also need to make an entry in the .rela.plt section. */
3814 htab->relplt->size += sizeof (Elf32_External_Rela);
3815 }
3816 else
3817 {
3818 h->plt.offset = (bfd_vma) -1;
3819 h->needs_plt = 0;
3820 }
3821 }
3822 else
3823 {
3824 h->plt.offset = (bfd_vma) -1;
3825 h->needs_plt = 0;
3826 }
3827
3828 eh = (struct ppc_elf_link_hash_entry *) h;
3829 if (eh->elf.got.refcount > 0)
3830 {
3831 /* Make sure this symbol is output as a dynamic symbol. */
3832 if (eh->elf.dynindx == -1
3833 && !eh->elf.forced_local)
3834 {
3835 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
3836 return FALSE;
3837 }
3838
3839 if (eh->tls_mask == (TLS_TLS | TLS_LD)
3840 && !eh->elf.def_dynamic)
3841 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3842 eh->elf.got.offset = (bfd_vma) -1;
3843 else
3844 {
3845 bfd_boolean dyn;
3846 eh->elf.got.offset = htab->got->size;
3847 if ((eh->tls_mask & TLS_TLS) != 0)
3848 {
3849 if ((eh->tls_mask & TLS_LD) != 0)
3850 htab->got->size += 8;
3851 if ((eh->tls_mask & TLS_GD) != 0)
3852 htab->got->size += 8;
3853 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
3854 htab->got->size += 4;
3855 if ((eh->tls_mask & TLS_DTPREL) != 0)
3856 htab->got->size += 4;
3857 }
3858 else
3859 htab->got->size += 4;
3860 dyn = htab->elf.dynamic_sections_created;
3861 if ((info->shared
3862 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
3863 && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
3864 || eh->elf.root.type != bfd_link_hash_undefweak))
3865 {
3866 /* All the entries we allocated need relocs. */
3867 htab->relgot->size
3868 += ((htab->got->size - eh->elf.got.offset) / 4
3869 * sizeof (Elf32_External_Rela));
3870 /* Except LD only needs one. */
3871 if ((eh->tls_mask & TLS_LD) != 0)
3872 htab->relgot->size -= sizeof (Elf32_External_Rela);
3873 }
3874 }
3875 }
3876 else
3877 eh->elf.got.offset = (bfd_vma) -1;
3878
3879 if (eh->dyn_relocs == NULL)
3880 return TRUE;
3881
3882 /* In the shared -Bsymbolic case, discard space allocated for
3883 dynamic pc-relative relocs against symbols which turn out to be
3884 defined in regular objects. For the normal shared case, discard
3885 space for relocs that have become local due to symbol visibility
3886 changes. */
3887
3888 if (info->shared)
3889 {
3890 /* Relocs that use pc_count are those that appear on a call insn,
3891 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3892 generated via assembly. We want calls to protected symbols to
3893 resolve directly to the function rather than going via the plt.
3894 If people want function pointer comparisons to work as expected
3895 then they should avoid writing weird assembly. */
3896 if (SYMBOL_CALLS_LOCAL (info, h))
3897 {
3898 struct ppc_elf_dyn_relocs **pp;
3899
3900 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3901 {
3902 p->count -= p->pc_count;
3903 p->pc_count = 0;
3904 if (p->count == 0)
3905 *pp = p->next;
3906 else
3907 pp = &p->next;
3908 }
3909 }
3910
3911 /* Also discard relocs on undefined weak syms with non-default
3912 visibility. */
3913 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3914 && h->root.type == bfd_link_hash_undefweak)
3915 eh->dyn_relocs = NULL;
3916
3917 /* Make sure undefined weak symbols are output as a dynamic symbol
3918 in PIEs. */
3919 if (info->pie
3920 && eh->dyn_relocs != NULL
3921 && h->dynindx == -1
3922 && h->root.type == bfd_link_hash_undefweak
3923 && !h->forced_local)
3924 {
3925 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3926 return FALSE;
3927 }
3928 }
3929 else if (ELIMINATE_COPY_RELOCS)
3930 {
3931 /* For the non-shared case, discard space for relocs against
3932 symbols which turn out to need copy relocs or are not
3933 dynamic. */
3934
3935 if (!h->non_got_ref
3936 && h->def_dynamic
3937 && !h->def_regular)
3938 {
3939 /* Make sure this symbol is output as a dynamic symbol.
3940 Undefined weak syms won't yet be marked as dynamic. */
3941 if (h->dynindx == -1
3942 && !h->forced_local)
3943 {
3944 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3945 return FALSE;
3946 }
3947
3948 /* If that succeeded, we know we'll be keeping all the
3949 relocs. */
3950 if (h->dynindx != -1)
3951 goto keep;
3952 }
3953
3954 eh->dyn_relocs = NULL;
3955
3956 keep: ;
3957 }
3958
3959 /* Finally, allocate space. */
3960 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3961 {
3962 asection *sreloc = elf_section_data (p->sec)->sreloc;
3963 sreloc->size += p->count * sizeof (Elf32_External_Rela);
3964 }
3965
3966 return TRUE;
3967 }
3968
3969 /* Find any dynamic relocs that apply to read-only sections. */
3970
3971 static bfd_boolean
3972 readonly_dynrelocs (struct elf_link_hash_entry *h, void *info)
3973 {
3974 struct ppc_elf_dyn_relocs *p;
3975
3976 if (h->root.type == bfd_link_hash_indirect)
3977 return TRUE;
3978
3979 if (h->root.type == bfd_link_hash_warning)
3980 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3981
3982 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
3983 {
3984 asection *s = p->sec->output_section;
3985
3986 if (s != NULL
3987 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
3988 == (SEC_READONLY | SEC_ALLOC)))
3989 {
3990 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
3991
3992 /* Not an error, just cut short the traversal. */
3993 return FALSE;
3994 }
3995 }
3996 return TRUE;
3997 }
3998
3999 /* Set the sizes of the dynamic sections. */
4000
4001 static bfd_boolean
4002 ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4003 struct bfd_link_info *info)
4004 {
4005 struct ppc_elf_link_hash_table *htab;
4006 asection *s;
4007 bfd_boolean relocs;
4008 bfd *ibfd;
4009
4010 #ifdef DEBUG
4011 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
4012 #endif
4013
4014 htab = ppc_elf_hash_table (info);
4015 BFD_ASSERT (htab->elf.dynobj != NULL);
4016
4017 if (elf_hash_table (info)->dynamic_sections_created)
4018 {
4019 /* Set the contents of the .interp section to the interpreter. */
4020 if (info->executable)
4021 {
4022 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
4023 BFD_ASSERT (s != NULL);
4024 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4025 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4026 }
4027 }
4028
4029 if (htab->tlsld_got.refcount > 0)
4030 {
4031 htab->tlsld_got.offset = htab->got->size;
4032 htab->got->size += 8;
4033 if (info->shared)
4034 htab->relgot->size += sizeof (Elf32_External_Rela);
4035 }
4036 else
4037 htab->tlsld_got.offset = (bfd_vma) -1;
4038
4039 /* Set up .got offsets for local syms, and space for local dynamic
4040 relocs. */
4041 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4042 {
4043 bfd_signed_vma *local_got;
4044 bfd_signed_vma *end_local_got;
4045 char *lgot_masks;
4046 bfd_size_type locsymcount;
4047 Elf_Internal_Shdr *symtab_hdr;
4048 asection *srel;
4049
4050 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4051 continue;
4052
4053 for (s = ibfd->sections; s != NULL; s = s->next)
4054 {
4055 struct ppc_elf_dyn_relocs *p;
4056
4057 for (p = ((struct ppc_elf_dyn_relocs *)
4058 elf_section_data (s)->local_dynrel);
4059 p != NULL;
4060 p = p->next)
4061 {
4062 if (!bfd_is_abs_section (p->sec)
4063 && bfd_is_abs_section (p->sec->output_section))
4064 {
4065 /* Input section has been discarded, either because
4066 it is a copy of a linkonce section or due to
4067 linker script /DISCARD/, so we'll be discarding
4068 the relocs too. */
4069 }
4070 else if (p->count != 0)
4071 {
4072 elf_section_data (p->sec)->sreloc->size
4073 += p->count * sizeof (Elf32_External_Rela);
4074 if ((p->sec->output_section->flags
4075 & (SEC_READONLY | SEC_ALLOC))
4076 == (SEC_READONLY | SEC_ALLOC))
4077 info->flags |= DF_TEXTREL;
4078 }
4079 }
4080 }
4081
4082 local_got = elf_local_got_refcounts (ibfd);
4083 if (!local_got)
4084 continue;
4085
4086 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4087 locsymcount = symtab_hdr->sh_info;
4088 end_local_got = local_got + locsymcount;
4089 lgot_masks = (char *) end_local_got;
4090 s = htab->got;
4091 srel = htab->relgot;
4092 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
4093 if (*local_got > 0)
4094 {
4095 if (*lgot_masks == (TLS_TLS | TLS_LD))
4096 {
4097 /* If just an LD reloc, we'll just use
4098 htab->tlsld_got.offset. */
4099 if (htab->tlsld_got.offset == (bfd_vma) -1)
4100 {
4101 htab->tlsld_got.offset = s->size;
4102 s->size += 8;
4103 if (info->shared)
4104 srel->size += sizeof (Elf32_External_Rela);
4105 }
4106 *local_got = (bfd_vma) -1;
4107 }
4108 else
4109 {
4110 *local_got = s->size;
4111 if ((*lgot_masks & TLS_TLS) != 0)
4112 {
4113 if ((*lgot_masks & TLS_GD) != 0)
4114 s->size += 8;
4115 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
4116 s->size += 4;
4117 if ((*lgot_masks & TLS_DTPREL) != 0)
4118 s->size += 4;
4119 }
4120 else
4121 s->size += 4;
4122 if (info->shared)
4123 srel->size += ((s->size - *local_got) / 4
4124 * sizeof (Elf32_External_Rela));
4125 }
4126 }
4127 else
4128 *local_got = (bfd_vma) -1;
4129 }
4130
4131 /* Allocate space for global sym dynamic relocs. */
4132 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
4133
4134 /* We've now determined the sizes of the various dynamic sections.
4135 Allocate memory for them. */
4136 relocs = FALSE;
4137 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
4138 {
4139 if ((s->flags & SEC_LINKER_CREATED) == 0)
4140 continue;
4141
4142 if (s == htab->plt
4143 || s == htab->got)
4144 {
4145 /* Strip this section if we don't need it; see the
4146 comment below. */
4147 }
4148 else if ((htab->sdata != NULL && s == htab->sdata->section)
4149 || (htab->sdata2 != NULL && s == htab->sdata2->section))
4150 {
4151 if (s->size == 0)
4152 /* Don't strip these sections. We need them because they
4153 define _SDA_BASE_ and _SDA2_BASE_. crt1.o makes a
4154 reference to _SDA_BASE_ to set up r13. */
4155 continue;
4156 }
4157 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4158 {
4159 if (s->size == 0)
4160 {
4161 /* If we don't need this section, strip it from the
4162 output file. This is mostly to handle .rela.bss and
4163 .rela.plt. We must create both sections in
4164 create_dynamic_sections, because they must be created
4165 before the linker maps input sections to output
4166 sections. The linker does that before
4167 adjust_dynamic_symbol is called, and it is that
4168 function which decides whether anything needs to go
4169 into these sections. */
4170 }
4171 else
4172 {
4173 /* Remember whether there are any relocation sections. */
4174 relocs = TRUE;
4175
4176 /* We use the reloc_count field as a counter if we need
4177 to copy relocs into the output file. */
4178 s->reloc_count = 0;
4179 }
4180 }
4181 else
4182 {
4183 /* It's not one of our sections, so don't allocate space. */
4184 continue;
4185 }
4186
4187 if (s->size == 0)
4188 {
4189 _bfd_strip_section_from_output (info, s);
4190 continue;
4191 }
4192
4193 /* Allocate memory for the section contents. */
4194 s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
4195 if (s->contents == NULL)
4196 return FALSE;
4197 }
4198
4199 if (htab->elf.dynamic_sections_created)
4200 {
4201 /* Add some entries to the .dynamic section. We fill in the
4202 values later, in ppc_elf_finish_dynamic_sections, but we
4203 must add the entries now so that we get the correct size for
4204 the .dynamic section. The DT_DEBUG entry is filled in by the
4205 dynamic linker and used by the debugger. */
4206 #define add_dynamic_entry(TAG, VAL) \
4207 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4208
4209 if (info->executable)
4210 {
4211 if (!add_dynamic_entry (DT_DEBUG, 0))
4212 return FALSE;
4213 }
4214
4215 if (htab->plt != NULL && htab->plt->size != 0)
4216 {
4217 if (!add_dynamic_entry (DT_PLTGOT, 0)
4218 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4219 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4220 || !add_dynamic_entry (DT_JMPREL, 0))
4221 return FALSE;
4222 }
4223
4224 if (relocs)
4225 {
4226 if (!add_dynamic_entry (DT_RELA, 0)
4227 || !add_dynamic_entry (DT_RELASZ, 0)
4228 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
4229 return FALSE;
4230 }
4231
4232 /* If any dynamic relocs apply to a read-only section, then we
4233 need a DT_TEXTREL entry. */
4234 if ((info->flags & DF_TEXTREL) == 0)
4235 elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
4236 info);
4237
4238 if ((info->flags & DF_TEXTREL) != 0)
4239 {
4240 if (!add_dynamic_entry (DT_TEXTREL, 0))
4241 return FALSE;
4242 }
4243 }
4244 #undef add_dynamic_entry
4245
4246 return TRUE;
4247 }
4248 \f
4249 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
4250
4251 static const int shared_stub_entry[] =
4252 {
4253 0x7c0802a6, /* mflr 0 */
4254 0x429f0005, /* bcl 20, 31, .Lxxx */
4255 0x7d6802a6, /* mflr 11 */
4256 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
4257 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
4258 0x7c0803a6, /* mtlr 0 */
4259 0x7d6903a6, /* mtctr 11 */
4260 0x4e800420, /* bctr */
4261 };
4262
4263 static const int stub_entry[] =
4264 {
4265 0x3d600000, /* lis 11,xxx@ha */
4266 0x396b0000, /* addi 11,11,xxx@l */
4267 0x7d6903a6, /* mtctr 11 */
4268 0x4e800420, /* bctr */
4269 };
4270
4271 static bfd_boolean
4272 ppc_elf_relax_section (bfd *abfd,
4273 asection *isec,
4274 struct bfd_link_info *link_info,
4275 bfd_boolean *again)
4276 {
4277 struct one_fixup
4278 {
4279 struct one_fixup *next;
4280 asection *tsec;
4281 bfd_vma toff;
4282 bfd_vma trampoff;
4283 };
4284
4285 Elf_Internal_Shdr *symtab_hdr;
4286 bfd_byte *contents = NULL;
4287 Elf_Internal_Sym *isymbuf = NULL;
4288 Elf_Internal_Rela *internal_relocs = NULL;
4289 Elf_Internal_Rela *irel, *irelend;
4290 struct one_fixup *fixups = NULL;
4291 bfd_boolean changed;
4292 struct ppc_elf_link_hash_table *ppc_info;
4293 bfd_size_type trampoff;
4294
4295 *again = FALSE;
4296
4297 /* Nothing to do if there are no relocations. */
4298 if ((isec->flags & SEC_RELOC) == 0 || isec->reloc_count == 0)
4299 return TRUE;
4300
4301 trampoff = (isec->size + 3) & (bfd_vma) -4;
4302 /* Space for a branch around any trampolines. */
4303 trampoff += 4;
4304
4305 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4306
4307 /* Get a copy of the native relocations. */
4308 internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
4309 link_info->keep_memory);
4310 if (internal_relocs == NULL)
4311 goto error_return;
4312
4313 ppc_info = ppc_elf_hash_table (link_info);
4314 irelend = internal_relocs + isec->reloc_count;
4315
4316 for (irel = internal_relocs; irel < irelend; irel++)
4317 {
4318 unsigned long r_type = ELF32_R_TYPE (irel->r_info);
4319 bfd_vma symaddr, reladdr, toff, roff;
4320 asection *tsec;
4321 struct one_fixup *f;
4322 size_t insn_offset = 0;
4323 bfd_vma max_branch_offset, val;
4324 bfd_byte *hit_addr;
4325 unsigned long t0;
4326 unsigned char sym_type;
4327
4328 switch (r_type)
4329 {
4330 case R_PPC_REL24:
4331 case R_PPC_LOCAL24PC:
4332 case R_PPC_PLTREL24:
4333 max_branch_offset = 1 << 25;
4334 break;
4335
4336 case R_PPC_REL14:
4337 case R_PPC_REL14_BRTAKEN:
4338 case R_PPC_REL14_BRNTAKEN:
4339 max_branch_offset = 1 << 15;
4340 break;
4341
4342 default:
4343 continue;
4344 }
4345
4346 /* Get the value of the symbol referred to by the reloc. */
4347 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4348 {
4349 /* A local symbol. */
4350 Elf_Internal_Sym *isym;
4351
4352 /* Read this BFD's local symbols. */
4353 if (isymbuf == NULL)
4354 {
4355 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4356 if (isymbuf == NULL)
4357 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4358 symtab_hdr->sh_info, 0,
4359 NULL, NULL, NULL);
4360 if (isymbuf == 0)
4361 goto error_return;
4362 }
4363 isym = isymbuf + ELF32_R_SYM (irel->r_info);
4364 if (isym->st_shndx == SHN_UNDEF)
4365 continue; /* We can't do anything with undefined symbols. */
4366 else if (isym->st_shndx == SHN_ABS)
4367 tsec = bfd_abs_section_ptr;
4368 else if (isym->st_shndx == SHN_COMMON)
4369 tsec = bfd_com_section_ptr;
4370 else
4371 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4372
4373 toff = isym->st_value;
4374 sym_type = ELF_ST_TYPE (isym->st_info);
4375 }
4376 else
4377 {
4378 /* Global symbol handling. */
4379 unsigned long indx;
4380 struct elf_link_hash_entry *h;
4381
4382 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4383 h = elf_sym_hashes (abfd)[indx];
4384
4385 while (h->root.type == bfd_link_hash_indirect
4386 || h->root.type == bfd_link_hash_warning)
4387 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4388
4389 if (r_type == R_PPC_PLTREL24
4390 && ppc_info->plt != NULL
4391 && h->plt.offset != (bfd_vma) -1)
4392 {
4393 tsec = ppc_info->plt;
4394 toff = h->plt.offset;
4395 }
4396 else if (h->root.type == bfd_link_hash_defined
4397 || h->root.type == bfd_link_hash_defweak)
4398 {
4399 tsec = h->root.u.def.section;
4400 toff = h->root.u.def.value;
4401 }
4402 else
4403 continue;
4404
4405 sym_type = h->type;
4406 }
4407
4408 /* If the branch and target are in the same section, you have
4409 no hope of adding stubs. We'll error out later should the
4410 branch overflow. */
4411 if (tsec == isec)
4412 continue;
4413
4414 /* There probably isn't any reason to handle symbols in
4415 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
4416 attribute for a code section, and we are only looking at
4417 branches. However, implement it correctly here as a
4418 reference for other target relax_section functions. */
4419 if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
4420 {
4421 /* At this stage in linking, no SEC_MERGE symbol has been
4422 adjusted, so all references to such symbols need to be
4423 passed through _bfd_merged_section_offset. (Later, in
4424 relocate_section, all SEC_MERGE symbols *except* for
4425 section symbols have been adjusted.)
4426
4427 gas may reduce relocations against symbols in SEC_MERGE
4428 sections to a relocation against the section symbol when
4429 the original addend was zero. When the reloc is against
4430 a section symbol we should include the addend in the
4431 offset passed to _bfd_merged_section_offset, since the
4432 location of interest is the original symbol. On the
4433 other hand, an access to "sym+addend" where "sym" is not
4434 a section symbol should not include the addend; Such an
4435 access is presumed to be an offset from "sym"; The
4436 location of interest is just "sym". */
4437 if (sym_type == STT_SECTION)
4438 toff += irel->r_addend;
4439
4440 toff = _bfd_merged_section_offset (abfd, &tsec,
4441 elf_section_data (tsec)->sec_info,
4442 toff);
4443
4444 if (sym_type != STT_SECTION)
4445 toff += irel->r_addend;
4446 }
4447 else
4448 toff += irel->r_addend;
4449
4450 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
4451
4452 roff = irel->r_offset;
4453 reladdr = isec->output_section->vma + isec->output_offset + roff;
4454
4455 /* If the branch is in range, no need to do anything. */
4456 if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
4457 continue;
4458
4459 /* Look for an existing fixup to this address. */
4460 for (f = fixups; f ; f = f->next)
4461 if (f->tsec == tsec && f->toff == toff)
4462 break;
4463
4464 if (f == NULL)
4465 {
4466 size_t size;
4467 unsigned long stub_rtype;
4468
4469 val = trampoff - roff;
4470 if (val >= max_branch_offset)
4471 /* Oh dear, we can't reach a trampoline. Don't try to add
4472 one. We'll report an error later. */
4473 continue;
4474
4475 if (link_info->shared)
4476 {
4477 size = 4 * ARRAY_SIZE (shared_stub_entry);
4478 insn_offset = 12;
4479 stub_rtype = R_PPC_RELAX32PC;
4480 }
4481 else
4482 {
4483 size = 4 * ARRAY_SIZE (stub_entry);
4484 insn_offset = 0;
4485 stub_rtype = R_PPC_RELAX32;
4486 }
4487
4488 if (R_PPC_RELAX32_PLT - R_PPC_RELAX32
4489 != R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC)
4490 abort ();
4491 if (tsec == ppc_info->plt)
4492 stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32;
4493
4494 /* Hijack the old relocation. Since we need two
4495 relocations for this use a "composite" reloc. */
4496 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4497 stub_rtype);
4498 irel->r_offset = trampoff + insn_offset;
4499
4500 /* Record the fixup so we don't do it again this section. */
4501 f = bfd_malloc (sizeof (*f));
4502 f->next = fixups;
4503 f->tsec = tsec;
4504 f->toff = toff;
4505 f->trampoff = trampoff;
4506 fixups = f;
4507
4508 trampoff += size;
4509 }
4510 else
4511 {
4512 val = f->trampoff - roff;
4513 if (val >= max_branch_offset)
4514 continue;
4515
4516 /* Nop out the reloc, since we're finalizing things here. */
4517 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
4518 }
4519
4520 /* Get the section contents. */
4521 if (contents == NULL)
4522 {
4523 /* Get cached copy if it exists. */
4524 if (elf_section_data (isec)->this_hdr.contents != NULL)
4525 contents = elf_section_data (isec)->this_hdr.contents;
4526 else
4527 {
4528 /* Go get them off disk. */
4529 if (!bfd_malloc_and_get_section (abfd, isec, &contents))
4530 goto error_return;
4531 }
4532 }
4533
4534 /* Fix up the existing branch to hit the trampoline. */
4535 hit_addr = contents + roff;
4536 switch (r_type)
4537 {
4538 case R_PPC_REL24:
4539 case R_PPC_LOCAL24PC:
4540 case R_PPC_PLTREL24:
4541 t0 = bfd_get_32 (abfd, hit_addr);
4542 t0 &= ~0x3fffffc;
4543 t0 |= val & 0x3fffffc;
4544 bfd_put_32 (abfd, t0, hit_addr);
4545 break;
4546
4547 case R_PPC_REL14:
4548 case R_PPC_REL14_BRTAKEN:
4549 case R_PPC_REL14_BRNTAKEN:
4550 t0 = bfd_get_32 (abfd, hit_addr);
4551 t0 &= ~0xfffc;
4552 t0 |= val & 0xfffc;
4553 bfd_put_32 (abfd, t0, hit_addr);
4554 break;
4555 }
4556 }
4557
4558 /* Write out the trampolines. */
4559 changed = fixups != NULL;
4560 if (fixups != NULL)
4561 {
4562 const int *stub;
4563 bfd_byte *dest;
4564 bfd_vma val;
4565 int i, size;
4566
4567 do
4568 {
4569 struct one_fixup *f = fixups;
4570 fixups = fixups->next;
4571 free (f);
4572 }
4573 while (fixups);
4574
4575 contents = bfd_realloc (contents, trampoff);
4576 if (contents == NULL)
4577 goto error_return;
4578
4579 isec->size = (isec->size + 3) & (bfd_vma) -4;
4580 /* Branch around the trampolines. */
4581 val = trampoff - isec->size + 0x48000000;
4582 dest = contents + isec->size;
4583 isec->size = trampoff;
4584 bfd_put_32 (abfd, val, dest);
4585 dest += 4;
4586
4587 if (link_info->shared)
4588 {
4589 stub = shared_stub_entry;
4590 size = ARRAY_SIZE (shared_stub_entry);
4591 }
4592 else
4593 {
4594 stub = stub_entry;
4595 size = ARRAY_SIZE (stub_entry);
4596 }
4597
4598 i = 0;
4599 while (dest < contents + trampoff)
4600 {
4601 bfd_put_32 (abfd, stub[i], dest);
4602 i++;
4603 if (i == size)
4604 i = 0;
4605 dest += 4;
4606 }
4607 BFD_ASSERT (i == 0);
4608 }
4609
4610 if (isymbuf != NULL
4611 && symtab_hdr->contents != (unsigned char *) isymbuf)
4612 {
4613 if (! link_info->keep_memory)
4614 free (isymbuf);
4615 else
4616 {
4617 /* Cache the symbols for elf_link_input_bfd. */
4618 symtab_hdr->contents = (unsigned char *) isymbuf;
4619 }
4620 }
4621
4622 if (contents != NULL
4623 && elf_section_data (isec)->this_hdr.contents != contents)
4624 {
4625 if (!changed && !link_info->keep_memory)
4626 free (contents);
4627 else
4628 {
4629 /* Cache the section contents for elf_link_input_bfd. */
4630 elf_section_data (isec)->this_hdr.contents = contents;
4631 }
4632 }
4633
4634 if (elf_section_data (isec)->relocs != internal_relocs)
4635 {
4636 if (!changed)
4637 free (internal_relocs);
4638 else
4639 elf_section_data (isec)->relocs = internal_relocs;
4640 }
4641
4642 *again = changed;
4643 return TRUE;
4644
4645 error_return:
4646 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
4647 free (isymbuf);
4648 if (contents != NULL
4649 && elf_section_data (isec)->this_hdr.contents != contents)
4650 free (contents);
4651 if (internal_relocs != NULL
4652 && elf_section_data (isec)->relocs != internal_relocs)
4653 free (internal_relocs);
4654 return FALSE;
4655 }
4656 \f
4657 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
4658
4659 /* Fill in the address for a pointer generated in a linker section. */
4660
4661 static bfd_vma
4662 elf_finish_pointer_linker_section (bfd *output_bfd,
4663 bfd *input_bfd,
4664 struct bfd_link_info *info,
4665 elf_linker_section_t *lsect,
4666 struct elf_link_hash_entry *h,
4667 bfd_vma relocation,
4668 const Elf_Internal_Rela *rel,
4669 int relative_reloc)
4670 {
4671 elf_linker_section_pointers_t *linker_section_ptr;
4672
4673 BFD_ASSERT (lsect != NULL);
4674
4675 if (h != NULL)
4676 {
4677 /* Handle global symbol. */
4678 struct ppc_elf_link_hash_entry *eh;
4679
4680 eh = (struct ppc_elf_link_hash_entry *) h;
4681 linker_section_ptr
4682 = elf_find_pointer_linker_section (eh->linker_section_pointer,
4683 rel->r_addend,
4684 lsect);
4685
4686 BFD_ASSERT (linker_section_ptr != NULL);
4687
4688 if (! elf_hash_table (info)->dynamic_sections_created
4689 || (info->shared
4690 && info->symbolic
4691 && h->def_regular))
4692 {
4693 /* This is actually a static link, or it is a
4694 -Bsymbolic link and the symbol is defined
4695 locally. We must initialize this entry in the
4696 global section.
4697
4698 When doing a dynamic link, we create a .rela.<xxx>
4699 relocation entry to initialize the value. This
4700 is done in the finish_dynamic_symbol routine. */
4701 if (!linker_section_ptr->written_address_p)
4702 {
4703 linker_section_ptr->written_address_p = TRUE;
4704 bfd_put_ptr (output_bfd,
4705 relocation + linker_section_ptr->addend,
4706 (lsect->section->contents
4707 + linker_section_ptr->offset));
4708 }
4709 }
4710 }
4711 else
4712 {
4713 /* Handle local symbol. */
4714 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
4715 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
4716 BFD_ASSERT (elf_local_ptr_offsets (input_bfd)[r_symndx] != NULL);
4717 linker_section_ptr = (elf_find_pointer_linker_section
4718 (elf_local_ptr_offsets (input_bfd)[r_symndx],
4719 rel->r_addend,
4720 lsect));
4721
4722 BFD_ASSERT (linker_section_ptr != NULL);
4723
4724 /* Write out pointer if it hasn't been rewritten out before. */
4725 if (!linker_section_ptr->written_address_p)
4726 {
4727 linker_section_ptr->written_address_p = TRUE;
4728 bfd_put_ptr (output_bfd, relocation + linker_section_ptr->addend,
4729 lsect->section->contents + linker_section_ptr->offset);
4730
4731 if (info->shared)
4732 {
4733 /* We need to generate a relative reloc for the dynamic
4734 linker. */
4735
4736 asection *srel = lsect->rel_section;
4737 Elf_Internal_Rela outrel[MAX_INT_RELS_PER_EXT_REL];
4738 bfd_byte *erel;
4739 const struct elf_backend_data *bed;
4740 unsigned int i;
4741
4742 BFD_ASSERT (srel != NULL);
4743
4744 bed = get_elf_backend_data (output_bfd);
4745 for (i = 0; i < bed->s->int_rels_per_ext_rel; i++)
4746 {
4747 outrel[i].r_offset = (lsect->section->output_section->vma
4748 + lsect->section->output_offset
4749 + linker_section_ptr->offset);
4750 outrel[i].r_info = 0;
4751 outrel[i].r_addend = 0;
4752 }
4753 outrel[0].r_info = ELF32_R_INFO (0, relative_reloc);
4754 erel = lsect->section->contents;
4755 erel += (elf_section_data (lsect->section)->rel_count++
4756 * sizeof (Elf32_External_Rela));
4757 bfd_elf32_swap_reloca_out (output_bfd, outrel, erel);
4758 }
4759 }
4760 }
4761
4762 relocation = (lsect->section->output_offset
4763 + linker_section_ptr->offset
4764 - lsect->sym_offset);
4765
4766 #ifdef DEBUG
4767 fprintf (stderr,
4768 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
4769 lsect->name, (long) relocation, (long) relocation);
4770 #endif
4771
4772 /* Subtract out the addend, because it will get added back in by the normal
4773 processing. */
4774 return relocation - linker_section_ptr->addend;
4775 }
4776
4777 /* The RELOCATE_SECTION function is called by the ELF backend linker
4778 to handle the relocations for a section.
4779
4780 The relocs are always passed as Rela structures; if the section
4781 actually uses Rel structures, the r_addend field will always be
4782 zero.
4783
4784 This function is responsible for adjust the section contents as
4785 necessary, and (if using Rela relocs and generating a
4786 relocatable output file) adjusting the reloc addend as
4787 necessary.
4788
4789 This function does not have to worry about setting the reloc
4790 address or the reloc symbol index.
4791
4792 LOCAL_SYMS is a pointer to the swapped in local symbols.
4793
4794 LOCAL_SECTIONS is an array giving the section in the input file
4795 corresponding to the st_shndx field of each local symbol.
4796
4797 The global hash table entry for the global symbols can be found
4798 via elf_sym_hashes (input_bfd).
4799
4800 When generating relocatable output, this function must handle
4801 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4802 going to be the section symbol corresponding to the output
4803 section, which means that the addend must be adjusted
4804 accordingly. */
4805
4806 static bfd_boolean
4807 ppc_elf_relocate_section (bfd *output_bfd,
4808 struct bfd_link_info *info,
4809 bfd *input_bfd,
4810 asection *input_section,
4811 bfd_byte *contents,
4812 Elf_Internal_Rela *relocs,
4813 Elf_Internal_Sym *local_syms,
4814 asection **local_sections)
4815 {
4816 Elf_Internal_Shdr *symtab_hdr;
4817 struct elf_link_hash_entry **sym_hashes;
4818 struct ppc_elf_link_hash_table *htab;
4819 Elf_Internal_Rela *rel;
4820 Elf_Internal_Rela *relend;
4821 Elf_Internal_Rela outrel;
4822 bfd_byte *loc;
4823 asection *sreloc = NULL;
4824 bfd_vma *local_got_offsets;
4825 bfd_boolean ret = TRUE;
4826
4827 #ifdef DEBUG
4828 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
4829 "%ld relocations%s",
4830 input_bfd, input_section,
4831 (long) input_section->reloc_count,
4832 (info->relocatable) ? " (relocatable)" : "");
4833 #endif
4834
4835 if (info->relocatable)
4836 return TRUE;
4837
4838 /* Initialize howto table if not already done. */
4839 if (!ppc_elf_howto_table[R_PPC_ADDR32])
4840 ppc_elf_howto_init ();
4841
4842 htab = ppc_elf_hash_table (info);
4843 local_got_offsets = elf_local_got_offsets (input_bfd);
4844 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4845 sym_hashes = elf_sym_hashes (input_bfd);
4846 rel = relocs;
4847 relend = relocs + input_section->reloc_count;
4848 for (; rel < relend; rel++)
4849 {
4850 enum elf_ppc_reloc_type r_type;
4851 bfd_vma addend;
4852 bfd_reloc_status_type r;
4853 Elf_Internal_Sym *sym;
4854 asection *sec;
4855 struct elf_link_hash_entry *h;
4856 const char *sym_name;
4857 reloc_howto_type *howto;
4858 unsigned long r_symndx;
4859 bfd_vma relocation;
4860 bfd_vma branch_bit, insn, from;
4861 bfd_boolean unresolved_reloc;
4862 bfd_boolean warned;
4863 unsigned int tls_type, tls_mask, tls_gd;
4864
4865 r_type = ELF32_R_TYPE (rel->r_info);
4866 sym = NULL;
4867 sec = NULL;
4868 h = NULL;
4869 unresolved_reloc = FALSE;
4870 warned = FALSE;
4871 r_symndx = ELF32_R_SYM (rel->r_info);
4872
4873 if (r_symndx < symtab_hdr->sh_info)
4874 {
4875 sym = local_syms + r_symndx;
4876 sec = local_sections[r_symndx];
4877 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym);
4878
4879 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4880 }
4881 else
4882 {
4883 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4884 r_symndx, symtab_hdr, sym_hashes,
4885 h, sec, relocation,
4886 unresolved_reloc, warned);
4887
4888 sym_name = h->root.root.string;
4889 }
4890
4891 /* TLS optimizations. Replace instruction sequences and relocs
4892 based on information we collected in tls_optimize. We edit
4893 RELOCS so that --emit-relocs will output something sensible
4894 for the final instruction stream. */
4895 tls_mask = 0;
4896 tls_gd = 0;
4897 if (IS_PPC_TLS_RELOC (r_type))
4898 {
4899 if (h != NULL)
4900 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
4901 else if (local_got_offsets != NULL)
4902 {
4903 char *lgot_masks;
4904 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
4905 tls_mask = lgot_masks[r_symndx];
4906 }
4907 }
4908
4909 /* Ensure reloc mapping code below stays sane. */
4910 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
4911 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
4912 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
4913 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
4914 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
4915 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
4916 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
4917 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
4918 abort ();
4919 switch (r_type)
4920 {
4921 default:
4922 break;
4923
4924 case R_PPC_GOT_TPREL16:
4925 case R_PPC_GOT_TPREL16_LO:
4926 if (tls_mask != 0
4927 && (tls_mask & TLS_TPREL) == 0)
4928 {
4929 bfd_vma insn;
4930 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
4931 insn &= 31 << 21;
4932 insn |= 0x3c020000; /* addis 0,2,0 */
4933 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
4934 r_type = R_PPC_TPREL16_HA;
4935 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4936 }
4937 break;
4938
4939 case R_PPC_TLS:
4940 if (tls_mask != 0
4941 && (tls_mask & TLS_TPREL) == 0)
4942 {
4943 bfd_vma insn, rtra;
4944 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
4945 if ((insn & ((31 << 26) | (31 << 11)))
4946 == ((31 << 26) | (2 << 11)))
4947 rtra = insn & ((1 << 26) - (1 << 16));
4948 else if ((insn & ((31 << 26) | (31 << 16)))
4949 == ((31 << 26) | (2 << 16)))
4950 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
4951 else
4952 abort ();
4953 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
4954 /* add -> addi. */
4955 insn = 14 << 26;
4956 else if ((insn & (31 << 1)) == 23 << 1
4957 && ((insn & (31 << 6)) < 14 << 6
4958 || ((insn & (31 << 6)) >= 16 << 6
4959 && (insn & (31 << 6)) < 24 << 6)))
4960 /* load and store indexed -> dform. */
4961 insn = (32 | ((insn >> 6) & 31)) << 26;
4962 else if ((insn & (31 << 1)) == 21 << 1
4963 && (insn & (0x1a << 6)) == 0)
4964 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4965 insn = (((58 | ((insn >> 6) & 4)) << 26)
4966 | ((insn >> 6) & 1));
4967 else if ((insn & (31 << 1)) == 21 << 1
4968 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
4969 /* lwax -> lwa. */
4970 insn = (58 << 26) | 2;
4971 else
4972 abort ();
4973 insn |= rtra;
4974 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
4975 r_type = R_PPC_TPREL16_LO;
4976 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4977 /* Was PPC_TLS which sits on insn boundary, now
4978 PPC_TPREL16_LO which is at insn+2. */
4979 rel->r_offset += 2;
4980 }
4981 break;
4982
4983 case R_PPC_GOT_TLSGD16_HI:
4984 case R_PPC_GOT_TLSGD16_HA:
4985 tls_gd = TLS_TPRELGD;
4986 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
4987 goto tls_gdld_hi;
4988 break;
4989
4990 case R_PPC_GOT_TLSLD16_HI:
4991 case R_PPC_GOT_TLSLD16_HA:
4992 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
4993 {
4994 tls_gdld_hi:
4995 if ((tls_mask & tls_gd) != 0)
4996 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
4997 + R_PPC_GOT_TPREL16);
4998 else
4999 {
5000 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
5001 rel->r_offset -= 2;
5002 r_type = R_PPC_NONE;
5003 }
5004 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5005 }
5006 break;
5007
5008 case R_PPC_GOT_TLSGD16:
5009 case R_PPC_GOT_TLSGD16_LO:
5010 tls_gd = TLS_TPRELGD;
5011 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5012 goto tls_get_addr_check;
5013 break;
5014
5015 case R_PPC_GOT_TLSLD16:
5016 case R_PPC_GOT_TLSLD16_LO:
5017 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
5018 {
5019 tls_get_addr_check:
5020 if (rel + 1 < relend)
5021 {
5022 enum elf_ppc_reloc_type r_type2;
5023 unsigned long r_symndx2;
5024 struct elf_link_hash_entry *h2;
5025 bfd_vma insn1, insn2;
5026 bfd_vma offset;
5027
5028 /* The next instruction should be a call to
5029 __tls_get_addr. Peek at the reloc to be sure. */
5030 r_type2 = ELF32_R_TYPE (rel[1].r_info);
5031 r_symndx2 = ELF32_R_SYM (rel[1].r_info);
5032 if (r_symndx2 < symtab_hdr->sh_info
5033 || (r_type2 != R_PPC_REL14
5034 && r_type2 != R_PPC_REL14_BRTAKEN
5035 && r_type2 != R_PPC_REL14_BRNTAKEN
5036 && r_type2 != R_PPC_REL24
5037 && r_type2 != R_PPC_PLTREL24))
5038 break;
5039
5040 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
5041 while (h2->root.type == bfd_link_hash_indirect
5042 || h2->root.type == bfd_link_hash_warning)
5043 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
5044 if (h2 == NULL || h2 != htab->tls_get_addr)
5045 break;
5046
5047 /* OK, it checks out. Replace the call. */
5048 offset = rel[1].r_offset;
5049 insn1 = bfd_get_32 (output_bfd,
5050 contents + rel->r_offset - 2);
5051 if ((tls_mask & tls_gd) != 0)
5052 {
5053 /* IE */
5054 insn1 &= (1 << 26) - 1;
5055 insn1 |= 32 << 26; /* lwz */
5056 insn2 = 0x7c631214; /* add 3,3,2 */
5057 rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
5058 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
5059 + R_PPC_GOT_TPREL16);
5060 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5061 }
5062 else
5063 {
5064 /* LE */
5065 insn1 = 0x3c620000; /* addis 3,2,0 */
5066 insn2 = 0x38630000; /* addi 3,3,0 */
5067 if (tls_gd == 0)
5068 {
5069 /* Was an LD reloc. */
5070 r_symndx = 0;
5071 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
5072 rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
5073 }
5074 r_type = R_PPC_TPREL16_HA;
5075 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5076 rel[1].r_info = ELF32_R_INFO (r_symndx,
5077 R_PPC_TPREL16_LO);
5078 rel[1].r_offset += 2;
5079 }
5080 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
5081 bfd_put_32 (output_bfd, insn2, contents + offset);
5082 if (tls_gd == 0)
5083 {
5084 /* We changed the symbol on an LD reloc. Start over
5085 in order to get h, sym, sec etc. right. */
5086 rel--;
5087 continue;
5088 }
5089 }
5090 }
5091 break;
5092 }
5093
5094 /* Handle other relocations that tweak non-addend part of insn. */
5095 branch_bit = 0;
5096 switch (r_type)
5097 {
5098 default:
5099 break;
5100
5101 /* Branch taken prediction relocations. */
5102 case R_PPC_ADDR14_BRTAKEN:
5103 case R_PPC_REL14_BRTAKEN:
5104 branch_bit = BRANCH_PREDICT_BIT;
5105 /* Fall thru */
5106
5107 /* Branch not taken prediction relocations. */
5108 case R_PPC_ADDR14_BRNTAKEN:
5109 case R_PPC_REL14_BRNTAKEN:
5110 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5111 insn &= ~BRANCH_PREDICT_BIT;
5112 insn |= branch_bit;
5113
5114 from = (rel->r_offset
5115 + input_section->output_offset
5116 + input_section->output_section->vma);
5117
5118 /* Invert 'y' bit if not the default. */
5119 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
5120 insn ^= BRANCH_PREDICT_BIT;
5121
5122 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5123 break;
5124 }
5125
5126 addend = rel->r_addend;
5127 tls_type = 0;
5128 howto = NULL;
5129 if (r_type < R_PPC_max)
5130 howto = ppc_elf_howto_table[r_type];
5131 switch (r_type)
5132 {
5133 default:
5134 (*_bfd_error_handler)
5135 (_("%B: unknown relocation type %d for symbol %s"),
5136 input_bfd, (int) r_type, sym_name);
5137
5138 bfd_set_error (bfd_error_bad_value);
5139 ret = FALSE;
5140 continue;
5141
5142 case R_PPC_NONE:
5143 case R_PPC_TLS:
5144 case R_PPC_EMB_MRKREF:
5145 case R_PPC_GNU_VTINHERIT:
5146 case R_PPC_GNU_VTENTRY:
5147 continue;
5148
5149 /* GOT16 relocations. Like an ADDR16 using the symbol's
5150 address in the GOT as relocation value instead of the
5151 symbol's value itself. Also, create a GOT entry for the
5152 symbol and put the symbol value there. */
5153 case R_PPC_GOT_TLSGD16:
5154 case R_PPC_GOT_TLSGD16_LO:
5155 case R_PPC_GOT_TLSGD16_HI:
5156 case R_PPC_GOT_TLSGD16_HA:
5157 tls_type = TLS_TLS | TLS_GD;
5158 goto dogot;
5159
5160 case R_PPC_GOT_TLSLD16:
5161 case R_PPC_GOT_TLSLD16_LO:
5162 case R_PPC_GOT_TLSLD16_HI:
5163 case R_PPC_GOT_TLSLD16_HA:
5164 tls_type = TLS_TLS | TLS_LD;
5165 goto dogot;
5166
5167 case R_PPC_GOT_TPREL16:
5168 case R_PPC_GOT_TPREL16_LO:
5169 case R_PPC_GOT_TPREL16_HI:
5170 case R_PPC_GOT_TPREL16_HA:
5171 tls_type = TLS_TLS | TLS_TPREL;
5172 goto dogot;
5173
5174 case R_PPC_GOT_DTPREL16:
5175 case R_PPC_GOT_DTPREL16_LO:
5176 case R_PPC_GOT_DTPREL16_HI:
5177 case R_PPC_GOT_DTPREL16_HA:
5178 tls_type = TLS_TLS | TLS_DTPREL;
5179 goto dogot;
5180
5181 case R_PPC_GOT16:
5182 case R_PPC_GOT16_LO:
5183 case R_PPC_GOT16_HI:
5184 case R_PPC_GOT16_HA:
5185 dogot:
5186 {
5187 /* Relocation is to the entry for this symbol in the global
5188 offset table. */
5189 bfd_vma off;
5190 bfd_vma *offp;
5191 unsigned long indx;
5192
5193 if (htab->got == NULL)
5194 abort ();
5195
5196 indx = 0;
5197 if (tls_type == (TLS_TLS | TLS_LD)
5198 && (h == NULL
5199 || !h->def_dynamic))
5200 offp = &htab->tlsld_got.offset;
5201 else if (h != NULL)
5202 {
5203 bfd_boolean dyn;
5204 dyn = htab->elf.dynamic_sections_created;
5205 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5206 || (info->shared
5207 && SYMBOL_REFERENCES_LOCAL (info, h)))
5208 /* This is actually a static link, or it is a
5209 -Bsymbolic link and the symbol is defined
5210 locally, or the symbol was forced to be local
5211 because of a version file. */
5212 ;
5213 else
5214 {
5215 indx = h->dynindx;
5216 unresolved_reloc = FALSE;
5217 }
5218 offp = &h->got.offset;
5219 }
5220 else
5221 {
5222 if (local_got_offsets == NULL)
5223 abort ();
5224 offp = &local_got_offsets[r_symndx];
5225 }
5226
5227 /* The offset must always be a multiple of 4. We use the
5228 least significant bit to record whether we have already
5229 processed this entry. */
5230 off = *offp;
5231 if ((off & 1) != 0)
5232 off &= ~1;
5233 else
5234 {
5235 unsigned int tls_m = (tls_mask
5236 & (TLS_LD | TLS_GD | TLS_DTPREL
5237 | TLS_TPREL | TLS_TPRELGD));
5238
5239 if (offp == &htab->tlsld_got.offset)
5240 tls_m = TLS_LD;
5241 else if (h == NULL
5242 || !h->def_dynamic)
5243 tls_m &= ~TLS_LD;
5244
5245 /* We might have multiple got entries for this sym.
5246 Initialize them all. */
5247 do
5248 {
5249 int tls_ty = 0;
5250
5251 if ((tls_m & TLS_LD) != 0)
5252 {
5253 tls_ty = TLS_TLS | TLS_LD;
5254 tls_m &= ~TLS_LD;
5255 }
5256 else if ((tls_m & TLS_GD) != 0)
5257 {
5258 tls_ty = TLS_TLS | TLS_GD;
5259 tls_m &= ~TLS_GD;
5260 }
5261 else if ((tls_m & TLS_DTPREL) != 0)
5262 {
5263 tls_ty = TLS_TLS | TLS_DTPREL;
5264 tls_m &= ~TLS_DTPREL;
5265 }
5266 else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
5267 {
5268 tls_ty = TLS_TLS | TLS_TPREL;
5269 tls_m = 0;
5270 }
5271
5272 /* Generate relocs for the dynamic linker. */
5273 if ((info->shared || indx != 0)
5274 && (h == NULL
5275 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5276 || h->root.type != bfd_link_hash_undefweak))
5277 {
5278 outrel.r_offset = (htab->got->output_section->vma
5279 + htab->got->output_offset
5280 + off);
5281 outrel.r_addend = 0;
5282 if (tls_ty & (TLS_LD | TLS_GD))
5283 {
5284 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
5285 if (tls_ty == (TLS_TLS | TLS_GD))
5286 {
5287 loc = htab->relgot->contents;
5288 loc += (htab->relgot->reloc_count++
5289 * sizeof (Elf32_External_Rela));
5290 bfd_elf32_swap_reloca_out (output_bfd,
5291 &outrel, loc);
5292 outrel.r_offset += 4;
5293 outrel.r_info
5294 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5295 }
5296 }
5297 else if (tls_ty == (TLS_TLS | TLS_DTPREL))
5298 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5299 else if (tls_ty == (TLS_TLS | TLS_TPREL))
5300 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
5301 else if (indx == 0)
5302 outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
5303 else
5304 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
5305 if (indx == 0)
5306 {
5307 outrel.r_addend += relocation;
5308 if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
5309 outrel.r_addend -= htab->elf.tls_sec->vma;
5310 }
5311 loc = htab->relgot->contents;
5312 loc += (htab->relgot->reloc_count++
5313 * sizeof (Elf32_External_Rela));
5314 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5315 }
5316
5317 /* Init the .got section contents if we're not
5318 emitting a reloc. */
5319 else
5320 {
5321 bfd_vma value = relocation;
5322
5323 if (tls_ty == (TLS_TLS | TLS_LD))
5324 value = 1;
5325 else if (tls_ty != 0)
5326 {
5327 value -= htab->elf.tls_sec->vma + DTP_OFFSET;
5328 if (tls_ty == (TLS_TLS | TLS_TPREL))
5329 value += DTP_OFFSET - TP_OFFSET;
5330
5331 if (tls_ty == (TLS_TLS | TLS_GD))
5332 {
5333 bfd_put_32 (output_bfd, value,
5334 htab->got->contents + off + 4);
5335 value = 1;
5336 }
5337 }
5338 bfd_put_32 (output_bfd, value,
5339 htab->got->contents + off);
5340 }
5341
5342 off += 4;
5343 if (tls_ty & (TLS_LD | TLS_GD))
5344 off += 4;
5345 }
5346 while (tls_m != 0);
5347
5348 off = *offp;
5349 *offp = off | 1;
5350 }
5351
5352 if (off >= (bfd_vma) -2)
5353 abort ();
5354
5355 if ((tls_type & TLS_TLS) != 0)
5356 {
5357 if (tls_type != (TLS_TLS | TLS_LD))
5358 {
5359 if ((tls_mask & TLS_LD) != 0
5360 && !(h == NULL
5361 || !h->def_dynamic))
5362 off += 8;
5363 if (tls_type != (TLS_TLS | TLS_GD))
5364 {
5365 if ((tls_mask & TLS_GD) != 0)
5366 off += 8;
5367 if (tls_type != (TLS_TLS | TLS_DTPREL))
5368 {
5369 if ((tls_mask & TLS_DTPREL) != 0)
5370 off += 4;
5371 }
5372 }
5373 }
5374 }
5375
5376 relocation = htab->got->output_offset + off - 4;
5377
5378 /* Addends on got relocations don't make much sense.
5379 x+off@got is actually x@got+off, and since the got is
5380 generated by a hash table traversal, the value in the
5381 got at entry m+n bears little relation to the entry m. */
5382 if (addend != 0)
5383 (*_bfd_error_handler)
5384 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
5385 input_bfd,
5386 input_section,
5387 (long) rel->r_offset,
5388 howto->name,
5389 sym_name);
5390 }
5391 break;
5392
5393 /* Relocations that need no special processing. */
5394 case R_PPC_LOCAL24PC:
5395 /* It makes no sense to point a local relocation
5396 at a symbol not in this object. */
5397 if (unresolved_reloc)
5398 {
5399 if (! (*info->callbacks->undefined_symbol) (info,
5400 h->root.root.string,
5401 input_bfd,
5402 input_section,
5403 rel->r_offset,
5404 TRUE))
5405 return FALSE;
5406 continue;
5407 }
5408 break;
5409
5410 case R_PPC_DTPREL16:
5411 case R_PPC_DTPREL16_LO:
5412 case R_PPC_DTPREL16_HI:
5413 case R_PPC_DTPREL16_HA:
5414 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5415 break;
5416
5417 /* Relocations that may need to be propagated if this is a shared
5418 object. */
5419 case R_PPC_TPREL16:
5420 case R_PPC_TPREL16_LO:
5421 case R_PPC_TPREL16_HI:
5422 case R_PPC_TPREL16_HA:
5423 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5424 /* The TPREL16 relocs shouldn't really be used in shared
5425 libs as they will result in DT_TEXTREL being set, but
5426 support them anyway. */
5427 goto dodyn;
5428
5429 case R_PPC_TPREL32:
5430 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5431 goto dodyn;
5432
5433 case R_PPC_DTPREL32:
5434 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5435 goto dodyn;
5436
5437 case R_PPC_DTPMOD32:
5438 relocation = 1;
5439 addend = 0;
5440 goto dodyn;
5441
5442 case R_PPC_REL24:
5443 case R_PPC_REL32:
5444 case R_PPC_REL14:
5445 case R_PPC_REL14_BRTAKEN:
5446 case R_PPC_REL14_BRNTAKEN:
5447 /* If these relocations are not to a named symbol, they can be
5448 handled right here, no need to bother the dynamic linker. */
5449 if (SYMBOL_REFERENCES_LOCAL (info, h)
5450 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
5451 break;
5452 /* fall through */
5453
5454 /* Relocations that always need to be propagated if this is a shared
5455 object. */
5456 case R_PPC_ADDR32:
5457 case R_PPC_ADDR24:
5458 case R_PPC_ADDR16:
5459 case R_PPC_ADDR16_LO:
5460 case R_PPC_ADDR16_HI:
5461 case R_PPC_ADDR16_HA:
5462 case R_PPC_ADDR14:
5463 case R_PPC_ADDR14_BRTAKEN:
5464 case R_PPC_ADDR14_BRNTAKEN:
5465 case R_PPC_UADDR32:
5466 case R_PPC_UADDR16:
5467 /* r_symndx will be zero only for relocs against symbols
5468 from removed linkonce sections, or sections discarded by
5469 a linker script. */
5470 dodyn:
5471 if (r_symndx == 0)
5472 break;
5473 /* Fall thru. */
5474
5475 if ((info->shared
5476 && (h == NULL
5477 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5478 || h->root.type != bfd_link_hash_undefweak)
5479 && (MUST_BE_DYN_RELOC (r_type)
5480 || !SYMBOL_CALLS_LOCAL (info, h)))
5481 || (ELIMINATE_COPY_RELOCS
5482 && !info->shared
5483 && (input_section->flags & SEC_ALLOC) != 0
5484 && h != NULL
5485 && h->dynindx != -1
5486 && !h->non_got_ref
5487 && h->def_dynamic
5488 && !h->def_regular))
5489 {
5490 int skip;
5491
5492 #ifdef DEBUG
5493 fprintf (stderr, "ppc_elf_relocate_section needs to "
5494 "create relocation for %s\n",
5495 (h && h->root.root.string
5496 ? h->root.root.string : "<unknown>"));
5497 #endif
5498
5499 /* When generating a shared object, these relocations
5500 are copied into the output file to be resolved at run
5501 time. */
5502 if (sreloc == NULL)
5503 {
5504 const char *name;
5505
5506 name = (bfd_elf_string_from_elf_section
5507 (input_bfd,
5508 elf_elfheader (input_bfd)->e_shstrndx,
5509 elf_section_data (input_section)->rel_hdr.sh_name));
5510 if (name == NULL)
5511 return FALSE;
5512
5513 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5514 && strcmp (bfd_get_section_name (input_bfd,
5515 input_section),
5516 name + 5) == 0);
5517
5518 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
5519 BFD_ASSERT (sreloc != NULL);
5520 }
5521
5522 skip = 0;
5523
5524 outrel.r_offset =
5525 _bfd_elf_section_offset (output_bfd, info, input_section,
5526 rel->r_offset);
5527 if (outrel.r_offset == (bfd_vma) -1
5528 || outrel.r_offset == (bfd_vma) -2)
5529 skip = (int) outrel.r_offset;
5530 outrel.r_offset += (input_section->output_section->vma
5531 + input_section->output_offset);
5532
5533 if (skip)
5534 memset (&outrel, 0, sizeof outrel);
5535 else if (!SYMBOL_REFERENCES_LOCAL (info, h))
5536 {
5537 unresolved_reloc = FALSE;
5538 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
5539 outrel.r_addend = rel->r_addend;
5540 }
5541 else
5542 {
5543 outrel.r_addend = relocation + rel->r_addend;
5544
5545 if (r_type == R_PPC_ADDR32)
5546 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
5547 else
5548 {
5549 long indx;
5550
5551 if (bfd_is_abs_section (sec))
5552 indx = 0;
5553 else if (sec == NULL || sec->owner == NULL)
5554 {
5555 bfd_set_error (bfd_error_bad_value);
5556 return FALSE;
5557 }
5558 else
5559 {
5560 asection *osec;
5561
5562 /* We are turning this relocation into one
5563 against a section symbol. It would be
5564 proper to subtract the symbol's value,
5565 osec->vma, from the emitted reloc addend,
5566 but ld.so expects buggy relocs. */
5567 osec = sec->output_section;
5568 indx = elf_section_data (osec)->dynindx;
5569 BFD_ASSERT (indx > 0);
5570 #ifdef DEBUG
5571 if (indx <= 0)
5572 printf ("indx=%d section=%s flags=%08x name=%s\n",
5573 indx, osec->name, osec->flags,
5574 h->root.root.string);
5575 #endif
5576 }
5577
5578 outrel.r_info = ELF32_R_INFO (indx, r_type);
5579 }
5580 }
5581
5582 loc = sreloc->contents;
5583 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5584 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5585
5586 if (skip == -1)
5587 continue;
5588
5589 /* This reloc will be computed at runtime. We clear the memory
5590 so that it contains predictable value. */
5591 if (! skip
5592 && ((input_section->flags & SEC_ALLOC) != 0
5593 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
5594 {
5595 relocation = howto->pc_relative ? outrel.r_offset : 0;
5596 addend = 0;
5597 break;
5598 }
5599 }
5600 break;
5601
5602 case R_PPC_RELAX32PC_PLT:
5603 case R_PPC_RELAX32_PLT:
5604 BFD_ASSERT (h != NULL
5605 && h->plt.offset != (bfd_vma) -1
5606 && htab->plt != NULL);
5607
5608 relocation = (htab->plt->output_section->vma
5609 + htab->plt->output_offset
5610 + h->plt.offset);
5611 if (r_type == R_PPC_RELAX32_PLT)
5612 goto relax32;
5613 /* Fall thru */
5614
5615 case R_PPC_RELAX32PC:
5616 relocation -= (input_section->output_section->vma
5617 + input_section->output_offset
5618 + rel->r_offset - 4);
5619 /* Fall thru */
5620
5621 case R_PPC_RELAX32:
5622 relax32:
5623 {
5624 unsigned long t0;
5625 unsigned long t1;
5626
5627 t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
5628 t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
5629
5630 /* We're clearing the bits for R_PPC_ADDR16_HA
5631 and R_PPC_ADDR16_LO here. */
5632 t0 &= ~0xffff;
5633 t1 &= ~0xffff;
5634
5635 /* t0 is HA, t1 is LO */
5636 relocation += addend;
5637 t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
5638 t1 |= relocation & 0xffff;
5639
5640 bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
5641 bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
5642 }
5643 continue;
5644
5645 /* Indirect .sdata relocation. */
5646 case R_PPC_EMB_SDAI16:
5647 BFD_ASSERT (htab->sdata != NULL);
5648 relocation
5649 = elf_finish_pointer_linker_section (output_bfd, input_bfd, info,
5650 htab->sdata, h, relocation,
5651 rel, R_PPC_RELATIVE);
5652 break;
5653
5654 /* Indirect .sdata2 relocation. */
5655 case R_PPC_EMB_SDA2I16:
5656 BFD_ASSERT (htab->sdata2 != NULL);
5657 relocation
5658 = elf_finish_pointer_linker_section (output_bfd, input_bfd, info,
5659 htab->sdata2, h, relocation,
5660 rel, R_PPC_RELATIVE);
5661 break;
5662
5663 /* Handle the TOC16 reloc. We want to use the offset within the .got
5664 section, not the actual VMA. This is appropriate when generating
5665 an embedded ELF object, for which the .got section acts like the
5666 AIX .toc section. */
5667 case R_PPC_TOC16: /* phony GOT16 relocations */
5668 BFD_ASSERT (sec != NULL);
5669 BFD_ASSERT (bfd_is_und_section (sec)
5670 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
5671 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
5672
5673 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
5674 break;
5675
5676 case R_PPC_PLTREL24:
5677 /* Relocation is to the entry for this symbol in the
5678 procedure linkage table. */
5679 BFD_ASSERT (h != NULL);
5680
5681 if (h->plt.offset == (bfd_vma) -1
5682 || htab->plt == NULL)
5683 {
5684 /* We didn't make a PLT entry for this symbol. This
5685 happens when statically linking PIC code, or when
5686 using -Bsymbolic. */
5687 break;
5688 }
5689
5690 unresolved_reloc = FALSE;
5691 relocation = (htab->plt->output_section->vma
5692 + htab->plt->output_offset
5693 + h->plt.offset);
5694 break;
5695
5696 /* Relocate against _SDA_BASE_. */
5697 case R_PPC_SDAREL16:
5698 {
5699 const char *name;
5700 const struct elf_link_hash_entry *sh;
5701
5702 BFD_ASSERT (sec != NULL);
5703 name = bfd_get_section_name (abfd, sec->output_section);
5704 if (! ((strncmp (name, ".sdata", 6) == 0
5705 && (name[6] == 0 || name[6] == '.'))
5706 || (strncmp (name, ".sbss", 5) == 0
5707 && (name[5] == 0 || name[5] == '.'))))
5708 {
5709 (*_bfd_error_handler)
5710 (_("%B: the target (%s) of a %s relocation is "
5711 "in the wrong output section (%s)"),
5712 input_bfd,
5713 sym_name,
5714 howto->name,
5715 name);
5716 }
5717 sh = htab->sdata->sym_hash;
5718 addend -= (sh->root.u.def.value
5719 + sh->root.u.def.section->output_section->vma
5720 + sh->root.u.def.section->output_offset);
5721 }
5722 break;
5723
5724 /* Relocate against _SDA2_BASE_. */
5725 case R_PPC_EMB_SDA2REL:
5726 {
5727 const char *name;
5728 const struct elf_link_hash_entry *sh;
5729
5730 BFD_ASSERT (sec != NULL);
5731 name = bfd_get_section_name (abfd, sec->output_section);
5732 if (! (strncmp (name, ".sdata2", 7) == 0
5733 || strncmp (name, ".sbss2", 6) == 0))
5734 {
5735 (*_bfd_error_handler)
5736 (_("%B: the target (%s) of a %s relocation is "
5737 "in the wrong output section (%s)"),
5738 input_bfd,
5739 sym_name,
5740 howto->name,
5741 name);
5742
5743 bfd_set_error (bfd_error_bad_value);
5744 ret = FALSE;
5745 continue;
5746 }
5747 sh = htab->sdata2->sym_hash;
5748 addend -= (sh->root.u.def.value
5749 + sh->root.u.def.section->output_section->vma
5750 + sh->root.u.def.section->output_offset);
5751 }
5752 break;
5753
5754 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5755 case R_PPC_EMB_SDA21:
5756 case R_PPC_EMB_RELSDA:
5757 {
5758 const char *name;
5759 const struct elf_link_hash_entry *sh;
5760 int reg;
5761
5762 BFD_ASSERT (sec != NULL);
5763 name = bfd_get_section_name (abfd, sec->output_section);
5764 if (((strncmp (name, ".sdata", 6) == 0
5765 && (name[6] == 0 || name[6] == '.'))
5766 || (strncmp (name, ".sbss", 5) == 0
5767 && (name[5] == 0 || name[5] == '.'))))
5768 {
5769 reg = 13;
5770 sh = htab->sdata->sym_hash;
5771 addend -= (sh->root.u.def.value
5772 + sh->root.u.def.section->output_section->vma
5773 + sh->root.u.def.section->output_offset);
5774 }
5775
5776 else if (strncmp (name, ".sdata2", 7) == 0
5777 || strncmp (name, ".sbss2", 6) == 0)
5778 {
5779 reg = 2;
5780 sh = htab->sdata2->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 (strcmp (name, ".PPC.EMB.sdata0") == 0
5787 || strcmp (name, ".PPC.EMB.sbss0") == 0)
5788 {
5789 reg = 0;
5790 }
5791
5792 else
5793 {
5794 (*_bfd_error_handler)
5795 (_("%B: the target (%s) of a %s relocation is "
5796 "in the wrong output section (%s)"),
5797 input_bfd,
5798 sym_name,
5799 howto->name,
5800 name);
5801
5802 bfd_set_error (bfd_error_bad_value);
5803 ret = FALSE;
5804 continue;
5805 }
5806
5807 if (r_type == R_PPC_EMB_SDA21)
5808 { /* fill in register field */
5809 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5810 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
5811 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5812 }
5813 }
5814 break;
5815
5816 /* Relocate against the beginning of the section. */
5817 case R_PPC_SECTOFF:
5818 case R_PPC_SECTOFF_LO:
5819 case R_PPC_SECTOFF_HI:
5820 case R_PPC_SECTOFF_HA:
5821 BFD_ASSERT (sec != NULL);
5822 addend -= sec->output_section->vma;
5823 break;
5824
5825 /* Negative relocations. */
5826 case R_PPC_EMB_NADDR32:
5827 case R_PPC_EMB_NADDR16:
5828 case R_PPC_EMB_NADDR16_LO:
5829 case R_PPC_EMB_NADDR16_HI:
5830 case R_PPC_EMB_NADDR16_HA:
5831 addend -= 2 * relocation;
5832 break;
5833
5834 case R_PPC_COPY:
5835 case R_PPC_GLOB_DAT:
5836 case R_PPC_JMP_SLOT:
5837 case R_PPC_RELATIVE:
5838 case R_PPC_PLT32:
5839 case R_PPC_PLTREL32:
5840 case R_PPC_PLT16_LO:
5841 case R_PPC_PLT16_HI:
5842 case R_PPC_PLT16_HA:
5843 case R_PPC_ADDR30:
5844 case R_PPC_EMB_RELSEC16:
5845 case R_PPC_EMB_RELST_LO:
5846 case R_PPC_EMB_RELST_HI:
5847 case R_PPC_EMB_RELST_HA:
5848 case R_PPC_EMB_BIT_FLD:
5849 (*_bfd_error_handler)
5850 (_("%B: relocation %s is not yet supported for symbol %s."),
5851 input_bfd,
5852 howto->name,
5853 sym_name);
5854
5855 bfd_set_error (bfd_error_invalid_operation);
5856 ret = FALSE;
5857 continue;
5858 }
5859
5860 /* Do any further special processing. */
5861 switch (r_type)
5862 {
5863 default:
5864 break;
5865
5866 case R_PPC_ADDR16_HA:
5867 case R_PPC_GOT16_HA:
5868 case R_PPC_PLT16_HA:
5869 case R_PPC_SECTOFF_HA:
5870 case R_PPC_TPREL16_HA:
5871 case R_PPC_DTPREL16_HA:
5872 case R_PPC_GOT_TLSGD16_HA:
5873 case R_PPC_GOT_TLSLD16_HA:
5874 case R_PPC_GOT_TPREL16_HA:
5875 case R_PPC_GOT_DTPREL16_HA:
5876 case R_PPC_EMB_NADDR16_HA:
5877 case R_PPC_EMB_RELST_HA:
5878 /* It's just possible that this symbol is a weak symbol
5879 that's not actually defined anywhere. In that case,
5880 'sec' would be NULL, and we should leave the symbol
5881 alone (it will be set to zero elsewhere in the link). */
5882 if (sec != NULL)
5883 /* Add 0x10000 if sign bit in 0:15 is set.
5884 Bits 0:15 are not used. */
5885 addend += 0x8000;
5886 break;
5887 }
5888
5889 #ifdef DEBUG
5890 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5891 "offset = %ld, addend = %ld\n",
5892 howto->name,
5893 (int) r_type,
5894 sym_name,
5895 r_symndx,
5896 (long) rel->r_offset,
5897 (long) addend);
5898 #endif
5899
5900 if (unresolved_reloc
5901 && !((input_section->flags & SEC_DEBUGGING) != 0
5902 && h->def_dynamic))
5903 {
5904 (*_bfd_error_handler)
5905 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5906 input_bfd,
5907 input_section,
5908 (long) rel->r_offset,
5909 howto->name,
5910 sym_name);
5911 ret = FALSE;
5912 }
5913
5914 r = _bfd_final_link_relocate (howto,
5915 input_bfd,
5916 input_section,
5917 contents,
5918 rel->r_offset,
5919 relocation,
5920 addend);
5921
5922 if (r != bfd_reloc_ok)
5923 {
5924 if (sym_name == NULL)
5925 sym_name = "(null)";
5926 if (r == bfd_reloc_overflow)
5927 {
5928 if (warned)
5929 continue;
5930 if (h != NULL
5931 && h->root.type == bfd_link_hash_undefweak
5932 && howto->pc_relative)
5933 {
5934 /* Assume this is a call protected by other code that
5935 detect the symbol is undefined. If this is the case,
5936 we can safely ignore the overflow. If not, the
5937 program is hosed anyway, and a little warning isn't
5938 going to help. */
5939
5940 continue;
5941 }
5942
5943 if (! (*info->callbacks->reloc_overflow) (info,
5944 (h ? &h->root : NULL),
5945 sym_name,
5946 howto->name,
5947 rel->r_addend,
5948 input_bfd,
5949 input_section,
5950 rel->r_offset))
5951 return FALSE;
5952 }
5953 else
5954 {
5955 (*_bfd_error_handler)
5956 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
5957 input_bfd, input_section,
5958 (long) rel->r_offset, howto->name, sym_name, (int) r);
5959 ret = FALSE;
5960 }
5961 }
5962 }
5963
5964 #ifdef DEBUG
5965 fprintf (stderr, "\n");
5966 #endif
5967
5968 return ret;
5969 }
5970 \f
5971 /* Finish up dynamic symbol handling. We set the contents of various
5972 dynamic sections here. */
5973
5974 static bfd_boolean
5975 ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
5976 struct bfd_link_info *info,
5977 struct elf_link_hash_entry *h,
5978 Elf_Internal_Sym *sym)
5979 {
5980 struct ppc_elf_link_hash_table *htab;
5981
5982 #ifdef DEBUG
5983 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
5984 h->root.root.string);
5985 #endif
5986
5987 htab = ppc_elf_hash_table (info);
5988 BFD_ASSERT (htab->elf.dynobj != NULL);
5989
5990 if (h->plt.offset != (bfd_vma) -1)
5991 {
5992 Elf_Internal_Rela rela;
5993 bfd_byte *loc;
5994 bfd_vma reloc_index;
5995
5996 #ifdef DEBUG
5997 fprintf (stderr, ", plt_offset = %d", h->plt.offset);
5998 #endif
5999
6000 /* This symbol has an entry in the procedure linkage table. Set
6001 it up. */
6002
6003 BFD_ASSERT (h->dynindx != -1);
6004 BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL);
6005
6006 /* We don't need to fill in the .plt. The ppc dynamic linker
6007 will fill it in. */
6008
6009 /* Fill in the entry in the .rela.plt section. */
6010 rela.r_offset = (htab->plt->output_section->vma
6011 + htab->plt->output_offset
6012 + h->plt.offset);
6013 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
6014 rela.r_addend = 0;
6015
6016 reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE;
6017 if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
6018 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
6019 loc = (htab->relplt->contents
6020 + reloc_index * sizeof (Elf32_External_Rela));
6021 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6022
6023 if (!h->def_regular)
6024 {
6025 /* Mark the symbol as undefined, rather than as defined in
6026 the .plt section. Leave the value alone. */
6027 sym->st_shndx = SHN_UNDEF;
6028 /* If the symbol is weak, we do need to clear the value.
6029 Otherwise, the PLT entry would provide a definition for
6030 the symbol even if the symbol wasn't defined anywhere,
6031 and so the symbol would never be NULL. */
6032 if (!h->ref_regular_nonweak)
6033 sym->st_value = 0;
6034 }
6035 }
6036
6037 if (h->needs_copy)
6038 {
6039 asection *s;
6040 Elf_Internal_Rela rela;
6041 bfd_byte *loc;
6042
6043 /* This symbols needs a copy reloc. Set it up. */
6044
6045 #ifdef DEBUG
6046 fprintf (stderr, ", copy");
6047 #endif
6048
6049 BFD_ASSERT (h->dynindx != -1);
6050
6051 if (h->size <= elf_gp_size (htab->elf.dynobj))
6052 s = htab->relsbss;
6053 else
6054 s = htab->relbss;
6055 BFD_ASSERT (s != NULL);
6056
6057 rela.r_offset = (h->root.u.def.value
6058 + h->root.u.def.section->output_section->vma
6059 + h->root.u.def.section->output_offset);
6060 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
6061 rela.r_addend = 0;
6062 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
6063 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6064 }
6065
6066 #ifdef DEBUG
6067 fprintf (stderr, "\n");
6068 #endif
6069
6070 /* Mark some specially defined symbols as absolute. */
6071 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
6072 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
6073 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
6074 sym->st_shndx = SHN_ABS;
6075
6076 return TRUE;
6077 }
6078 \f
6079 static enum elf_reloc_type_class
6080 ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
6081 {
6082 switch (ELF32_R_TYPE (rela->r_info))
6083 {
6084 case R_PPC_RELATIVE:
6085 return reloc_class_relative;
6086 case R_PPC_REL24:
6087 case R_PPC_ADDR24:
6088 case R_PPC_JMP_SLOT:
6089 return reloc_class_plt;
6090 case R_PPC_COPY:
6091 return reloc_class_copy;
6092 default:
6093 return reloc_class_normal;
6094 }
6095 }
6096 \f
6097 /* Finish up the dynamic sections. */
6098
6099 static bfd_boolean
6100 ppc_elf_finish_dynamic_sections (bfd *output_bfd,
6101 struct bfd_link_info *info)
6102 {
6103 asection *sdyn;
6104 struct ppc_elf_link_hash_table *htab;
6105
6106 #ifdef DEBUG
6107 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
6108 #endif
6109
6110 htab = ppc_elf_hash_table (info);
6111 sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic");
6112
6113 if (htab->elf.dynamic_sections_created)
6114 {
6115 Elf32_External_Dyn *dyncon, *dynconend;
6116
6117 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
6118
6119 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6120 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6121 for (; dyncon < dynconend; dyncon++)
6122 {
6123 Elf_Internal_Dyn dyn;
6124 asection *s;
6125
6126 bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn);
6127
6128 switch (dyn.d_tag)
6129 {
6130 case DT_PLTGOT:
6131 s = htab->plt;
6132 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6133 break;
6134
6135 case DT_PLTRELSZ:
6136 dyn.d_un.d_val = htab->relplt->size;
6137 break;
6138
6139 case DT_JMPREL:
6140 s = htab->relplt;
6141 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6142 break;
6143
6144 default:
6145 continue;
6146 }
6147
6148 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6149 }
6150 }
6151
6152 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
6153 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
6154 if (htab->got)
6155 {
6156 unsigned char *contents = htab->got->contents;
6157 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
6158
6159 if (sdyn == NULL)
6160 bfd_put_32 (output_bfd, 0, contents + 4);
6161 else
6162 bfd_put_32 (output_bfd,
6163 sdyn->output_section->vma + sdyn->output_offset,
6164 contents + 4);
6165
6166 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
6167 }
6168
6169 return TRUE;
6170 }
6171 \f
6172 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6173 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6174 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6175 #define TARGET_BIG_NAME "elf32-powerpc"
6176 #define ELF_ARCH bfd_arch_powerpc
6177 #define ELF_MACHINE_CODE EM_PPC
6178 #ifdef __QNXTARGET__
6179 #define ELF_MAXPAGESIZE 0x1000
6180 #else
6181 #define ELF_MAXPAGESIZE 0x10000
6182 #endif
6183 #define ELF_MINPAGESIZE 0x1000
6184 #define elf_info_to_howto ppc_elf_info_to_howto
6185
6186 #ifdef EM_CYGNUS_POWERPC
6187 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6188 #endif
6189
6190 #ifdef EM_PPC_OLD
6191 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6192 #endif
6193
6194 #define elf_backend_plt_not_loaded 1
6195 #define elf_backend_got_symbol_offset 4
6196 #define elf_backend_can_gc_sections 1
6197 #define elf_backend_can_refcount 1
6198 #define elf_backend_got_header_size 12
6199 #define elf_backend_rela_normal 1
6200
6201 #define bfd_elf32_mkobject ppc_elf_mkobject
6202 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6203 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6204 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6205 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6206 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6207
6208 #define elf_backend_object_p ppc_elf_object_p
6209 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6210 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6211 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6212 #define elf_backend_relocate_section ppc_elf_relocate_section
6213 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6214 #define elf_backend_check_relocs ppc_elf_check_relocs
6215 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6216 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6217 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6218 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6219 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6220 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6221 #define elf_backend_fake_sections ppc_elf_fake_sections
6222 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6223 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6224 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6225 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6226 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6227 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6228 #define elf_backend_write_section ppc_elf_write_section
6229 #define elf_backend_special_sections ppc_elf_special_sections
6230 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
6231
6232 #include "elf32-target.h"
This page took 0.162215 seconds and 4 git commands to generate.