Commit | Line | Data |
---|---|---|
5bd4f169 | 1 | /* PowerPC64-specific support for 64-bit ELF. |
86bbe32f | 2 | Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
5bd4f169 AM |
3 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
4 | based on elf32-ppc.c by Ian Lance Taylor. | |
5 | ||
ae9a127f | 6 | This file is part of BFD, the Binary File Descriptor library. |
5bd4f169 | 7 | |
ae9a127f NC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
5bd4f169 | 12 | |
ae9a127f NC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
5bd4f169 | 17 | |
4ce794b7 AM |
18 | You should have received a copy of the GNU General Public License along |
19 | with this program; if not, write to the Free Software Foundation, Inc., | |
20 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
5bd4f169 | 21 | |
4ce794b7 AM |
22 | /* The 64-bit PowerPC ELF ABI may be found at |
23 | http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and | |
24 | http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */ | |
5bd4f169 AM |
25 | |
26 | #include "bfd.h" | |
27 | #include "sysdep.h" | |
28 | #include "bfdlink.h" | |
29 | #include "libbfd.h" | |
30 | #include "elf-bfd.h" | |
04c9666a | 31 | #include "elf/ppc64.h" |
5d1634d7 | 32 | #include "elf64-ppc.h" |
5bd4f169 | 33 | |
805fc799 | 34 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
4ce794b7 | 35 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 36 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
4ce794b7 | 37 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 38 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
4ce794b7 | 39 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 40 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
4ce794b7 | 41 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 42 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
4ce794b7 | 43 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 44 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
4ce794b7 | 45 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 46 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
4ce794b7 | 47 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 48 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
4ce794b7 | 49 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5bd4f169 AM |
50 | |
51 | ||
ad8e1ba5 AM |
52 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
53 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
54 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
55 | #define TARGET_BIG_NAME "elf64-powerpc" | |
56 | #define ELF_ARCH bfd_arch_powerpc | |
57 | #define ELF_MACHINE_CODE EM_PPC64 | |
58 | #define ELF_MAXPAGESIZE 0x10000 | |
59 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
60 | ||
61 | #define elf_backend_want_got_sym 0 | |
62 | #define elf_backend_want_plt_sym 0 | |
63 | #define elf_backend_plt_alignment 3 | |
64 | #define elf_backend_plt_not_loaded 1 | |
65 | #define elf_backend_got_symbol_offset 0 | |
66 | #define elf_backend_got_header_size 8 | |
67 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE | |
68 | #define elf_backend_can_gc_sections 1 | |
69 | #define elf_backend_can_refcount 1 | |
70 | #define elf_backend_rela_normal 1 | |
71 | ||
e717da7e | 72 | #define bfd_elf64_mkobject ppc64_elf_mkobject |
ad8e1ba5 AM |
73 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
74 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data | |
75 | #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook | |
76 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create | |
77 | #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free | |
78 | ||
79 | #define elf_backend_object_p ppc64_elf_object_p | |
80 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections | |
81 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
82 | #define elf_backend_check_relocs ppc64_elf_check_relocs | |
83 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
84 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
85 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
86 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol | |
87 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
88 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
89 | #define elf_backend_relocate_section ppc64_elf_relocate_section | |
90 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
91 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
92 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
2f89ff8d | 93 | #define elf_backend_special_sections ppc64_elf_special_sections |
ad8e1ba5 | 94 | |
5bd4f169 AM |
95 | /* The name of the dynamic interpreter. This is put in the .interp |
96 | section. */ | |
97 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
98 | ||
99 | /* The size in bytes of an entry in the procedure linkage table. */ | |
100 | #define PLT_ENTRY_SIZE 24 | |
101 | ||
102 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 103 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
104 | |
105 | /* TOC base pointers offset from start of TOC. */ | |
411e1bfb AM |
106 | #define TOC_BASE_OFF 0x8000 |
107 | ||
108 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
109 | #define TP_OFFSET 0x7000 | |
110 | #define DTP_OFFSET 0x8000 | |
5bd4f169 | 111 | |
ad8e1ba5 AM |
112 | /* .plt call stub instructions. The normal stub is like this, but |
113 | sometimes the .plt entry crosses a 64k boundary and we need to | |
114 | insert an addis to adjust r12. */ | |
115 | #define PLT_CALL_STUB_SIZE (7*4) | |
5d1634d7 AM |
116 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
117 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
118 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
119 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
120 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
121 | /* ld %r11,xxx+16@l(%r12) */ | |
122 | #define BCTR 0x4e800420 /* bctr */ | |
123 | ||
5d1634d7 | 124 | |
ad8e1ba5 AM |
125 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
126 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ | |
127 | ||
128 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
129 | ||
130 | /* glink call stub instructions. We enter with the index in R0, and the | |
131 | address of glink entry in CTR. From that, we can calculate PLT0. */ | |
132 | #define GLINK_CALL_STUB_SIZE (16*4) | |
133 | #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */ | |
134 | #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */ | |
135 | #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */ | |
136 | #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */ | |
137 | #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */ | |
138 | #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */ | |
139 | #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */ | |
140 | /* sub %r12,%r12,%r11 */ | |
141 | #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */ | |
142 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */ | |
143 | /* ld %r11,xxx@l(%r12) */ | |
144 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */ | |
145 | /* ld %r2,8(%r12) */ | |
146 | /* mtctr %r11 */ | |
147 | /* ld %r11,16(%r12) */ | |
148 | /* bctr */ | |
5d1634d7 AM |
149 | |
150 | /* Pad with this. */ | |
151 | #define NOP 0x60000000 | |
152 | ||
721956f4 AM |
153 | /* Some other nops. */ |
154 | #define CROR_151515 0x4def7b82 | |
155 | #define CROR_313131 0x4ffffb82 | |
156 | ||
cedb70c5 | 157 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
158 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
159 | #define B_DOT 0x48000000 /* b . */ | |
160 | ||
161 | /* After that, we need two instructions to load the index, followed by | |
162 | a branch. */ | |
163 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 164 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 165 | |
82bd7b59 AM |
166 | /* Instructions to save and restore floating point regs. */ |
167 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ | |
168 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
169 | #define BLR 0x4e800020 /* blr */ | |
170 | ||
41bd81ab AM |
171 | /* Since .opd is an array of descriptors and each entry will end up |
172 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
173 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 174 | relocate .opd without reloc entries. */ |
41bd81ab AM |
175 | #ifndef NO_OPD_RELOCS |
176 | #define NO_OPD_RELOCS 0 | |
177 | #endif | |
5bd4f169 | 178 | \f |
f5e87a1d | 179 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 180 | |
5bd4f169 | 181 | /* Relocation HOWTO's. */ |
04c9666a | 182 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
5bd4f169 AM |
183 | |
184 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
185 | /* This reloc does nothing. */ | |
186 | HOWTO (R_PPC64_NONE, /* type */ | |
187 | 0, /* rightshift */ | |
411e1bfb AM |
188 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
189 | 32, /* bitsize */ | |
b34976b6 | 190 | FALSE, /* pc_relative */ |
5bd4f169 | 191 | 0, /* bitpos */ |
f5e87a1d | 192 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
193 | bfd_elf_generic_reloc, /* special_function */ |
194 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 195 | FALSE, /* partial_inplace */ |
d006db6c | 196 | 0, /* src_mask */ |
5bd4f169 | 197 | 0, /* dst_mask */ |
b34976b6 | 198 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
199 | |
200 | /* A standard 32 bit relocation. */ | |
201 | HOWTO (R_PPC64_ADDR32, /* type */ | |
202 | 0, /* rightshift */ | |
203 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
204 | 32, /* bitsize */ | |
b34976b6 | 205 | FALSE, /* pc_relative */ |
5bd4f169 AM |
206 | 0, /* bitpos */ |
207 | complain_overflow_bitfield, /* complain_on_overflow */ | |
208 | bfd_elf_generic_reloc, /* special_function */ | |
209 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 210 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
211 | 0, /* src_mask */ |
212 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 213 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
214 | |
215 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
216 | FIXME: we don't check that, we just clear them. */ | |
217 | HOWTO (R_PPC64_ADDR24, /* type */ | |
218 | 0, /* rightshift */ | |
219 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
220 | 26, /* bitsize */ | |
b34976b6 | 221 | FALSE, /* pc_relative */ |
5bd4f169 AM |
222 | 0, /* bitpos */ |
223 | complain_overflow_bitfield, /* complain_on_overflow */ | |
224 | bfd_elf_generic_reloc, /* special_function */ | |
225 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 226 | FALSE, /* partial_inplace */ |
d006db6c | 227 | 0, /* src_mask */ |
f5e87a1d | 228 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 229 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
230 | |
231 | /* A standard 16 bit relocation. */ | |
232 | HOWTO (R_PPC64_ADDR16, /* type */ | |
233 | 0, /* rightshift */ | |
234 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
235 | 16, /* bitsize */ | |
b34976b6 | 236 | FALSE, /* pc_relative */ |
5bd4f169 AM |
237 | 0, /* bitpos */ |
238 | complain_overflow_bitfield, /* complain_on_overflow */ | |
239 | bfd_elf_generic_reloc, /* special_function */ | |
240 | "R_PPC64_ADDR16", /* name */ | |
b34976b6 | 241 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
242 | 0, /* src_mask */ |
243 | 0xffff, /* dst_mask */ | |
b34976b6 | 244 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
245 | |
246 | /* A 16 bit relocation without overflow. */ | |
247 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
248 | 0, /* rightshift */ | |
249 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
250 | 16, /* bitsize */ | |
b34976b6 | 251 | FALSE, /* pc_relative */ |
5bd4f169 AM |
252 | 0, /* bitpos */ |
253 | complain_overflow_dont,/* complain_on_overflow */ | |
254 | bfd_elf_generic_reloc, /* special_function */ | |
255 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 256 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
257 | 0, /* src_mask */ |
258 | 0xffff, /* dst_mask */ | |
b34976b6 | 259 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
260 | |
261 | /* Bits 16-31 of an address. */ | |
262 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
263 | 16, /* rightshift */ | |
264 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
265 | 16, /* bitsize */ | |
b34976b6 | 266 | FALSE, /* pc_relative */ |
5bd4f169 AM |
267 | 0, /* bitpos */ |
268 | complain_overflow_dont, /* complain_on_overflow */ | |
269 | bfd_elf_generic_reloc, /* special_function */ | |
270 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 271 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
272 | 0, /* src_mask */ |
273 | 0xffff, /* dst_mask */ | |
b34976b6 | 274 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
275 | |
276 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
277 | bits, treated as a signed number, is negative. */ | |
278 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
279 | 16, /* rightshift */ | |
280 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
281 | 16, /* bitsize */ | |
b34976b6 | 282 | FALSE, /* pc_relative */ |
5bd4f169 AM |
283 | 0, /* bitpos */ |
284 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 285 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 286 | "R_PPC64_ADDR16_HA", /* name */ |
b34976b6 | 287 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
288 | 0, /* src_mask */ |
289 | 0xffff, /* dst_mask */ | |
b34976b6 | 290 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
291 | |
292 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
293 | FIXME: we don't check that, we just clear them. */ | |
294 | HOWTO (R_PPC64_ADDR14, /* type */ | |
295 | 0, /* rightshift */ | |
296 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
297 | 16, /* bitsize */ | |
b34976b6 | 298 | FALSE, /* pc_relative */ |
5bd4f169 AM |
299 | 0, /* bitpos */ |
300 | complain_overflow_bitfield, /* complain_on_overflow */ | |
301 | bfd_elf_generic_reloc, /* special_function */ | |
302 | "R_PPC64_ADDR14", /* name */ | |
b34976b6 | 303 | FALSE, /* partial_inplace */ |
d006db6c | 304 | 0, /* src_mask */ |
f5e87a1d | 305 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 306 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
307 | |
308 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
309 | indicate that the branch is expected to be taken. The lower two | |
310 | bits must be zero. */ | |
311 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
312 | 0, /* rightshift */ | |
313 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
314 | 16, /* bitsize */ | |
b34976b6 | 315 | FALSE, /* pc_relative */ |
5bd4f169 AM |
316 | 0, /* bitpos */ |
317 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 318 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 319 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 320 | FALSE, /* partial_inplace */ |
d006db6c | 321 | 0, /* src_mask */ |
f5e87a1d | 322 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 323 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
324 | |
325 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
326 | indicate that the branch is not expected to be taken. The lower | |
327 | two bits must be zero. */ | |
328 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
329 | 0, /* rightshift */ | |
330 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
331 | 16, /* bitsize */ | |
b34976b6 | 332 | FALSE, /* pc_relative */ |
5bd4f169 AM |
333 | 0, /* bitpos */ |
334 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 335 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 336 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 337 | FALSE, /* partial_inplace */ |
d006db6c | 338 | 0, /* src_mask */ |
f5e87a1d | 339 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 340 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
341 | |
342 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
343 | HOWTO (R_PPC64_REL24, /* type */ | |
344 | 0, /* rightshift */ | |
345 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
346 | 26, /* bitsize */ | |
b34976b6 | 347 | TRUE, /* pc_relative */ |
5bd4f169 AM |
348 | 0, /* bitpos */ |
349 | complain_overflow_signed, /* complain_on_overflow */ | |
350 | bfd_elf_generic_reloc, /* special_function */ | |
351 | "R_PPC64_REL24", /* name */ | |
b34976b6 | 352 | FALSE, /* partial_inplace */ |
d006db6c | 353 | 0, /* src_mask */ |
f5e87a1d | 354 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 355 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
356 | |
357 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
358 | HOWTO (R_PPC64_REL14, /* type */ | |
359 | 0, /* rightshift */ | |
360 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
361 | 16, /* bitsize */ | |
b34976b6 | 362 | TRUE, /* pc_relative */ |
5bd4f169 AM |
363 | 0, /* bitpos */ |
364 | complain_overflow_signed, /* complain_on_overflow */ | |
365 | bfd_elf_generic_reloc, /* special_function */ | |
366 | "R_PPC64_REL14", /* name */ | |
b34976b6 | 367 | FALSE, /* partial_inplace */ |
d006db6c | 368 | 0, /* src_mask */ |
f5e87a1d | 369 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 370 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
371 | |
372 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
373 | the branch is expected to be taken. The lower two bits must be | |
374 | zero. */ | |
375 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
376 | 0, /* rightshift */ | |
377 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
378 | 16, /* bitsize */ | |
b34976b6 | 379 | TRUE, /* pc_relative */ |
5bd4f169 AM |
380 | 0, /* bitpos */ |
381 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 382 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 383 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 384 | FALSE, /* partial_inplace */ |
d006db6c | 385 | 0, /* src_mask */ |
f5e87a1d | 386 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 387 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
388 | |
389 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
390 | the branch is not expected to be taken. The lower two bits must | |
391 | be zero. */ | |
392 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
393 | 0, /* rightshift */ | |
394 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
395 | 16, /* bitsize */ | |
b34976b6 | 396 | TRUE, /* pc_relative */ |
5bd4f169 AM |
397 | 0, /* bitpos */ |
398 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 399 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 400 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 401 | FALSE, /* partial_inplace */ |
d006db6c | 402 | 0, /* src_mask */ |
f5e87a1d | 403 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 404 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
405 | |
406 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
407 | symbol. */ | |
408 | HOWTO (R_PPC64_GOT16, /* type */ | |
409 | 0, /* rightshift */ | |
410 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
411 | 16, /* bitsize */ | |
b34976b6 | 412 | FALSE, /* pc_relative */ |
5bd4f169 AM |
413 | 0, /* bitpos */ |
414 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 415 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 416 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 417 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
418 | 0, /* src_mask */ |
419 | 0xffff, /* dst_mask */ | |
b34976b6 | 420 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
421 | |
422 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
423 | the symbol. */ | |
424 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
425 | 0, /* rightshift */ | |
426 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
427 | 16, /* bitsize */ | |
b34976b6 | 428 | FALSE, /* pc_relative */ |
5bd4f169 AM |
429 | 0, /* bitpos */ |
430 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 431 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 432 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 433 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
434 | 0, /* src_mask */ |
435 | 0xffff, /* dst_mask */ | |
b34976b6 | 436 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
437 | |
438 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
439 | the symbol. */ | |
440 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
441 | 16, /* rightshift */ | |
442 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
443 | 16, /* bitsize */ | |
b34976b6 | 444 | FALSE, /* pc_relative */ |
5bd4f169 AM |
445 | 0, /* bitpos */ |
446 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 447 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 448 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 449 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
450 | 0, /* src_mask */ |
451 | 0xffff, /* dst_mask */ | |
b34976b6 | 452 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
453 | |
454 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
455 | the symbol. */ | |
456 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
457 | 16, /* rightshift */ | |
458 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
459 | 16, /* bitsize */ | |
b34976b6 | 460 | FALSE, /* pc_relative */ |
5bd4f169 AM |
461 | 0, /* bitpos */ |
462 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 463 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 464 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 465 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
466 | 0, /* src_mask */ |
467 | 0xffff, /* dst_mask */ | |
b34976b6 | 468 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
469 | |
470 | /* This is used only by the dynamic linker. The symbol should exist | |
471 | both in the object being run and in some shared library. The | |
472 | dynamic linker copies the data addressed by the symbol from the | |
473 | shared library into the object, because the object being | |
474 | run has to have the data at some particular address. */ | |
475 | HOWTO (R_PPC64_COPY, /* type */ | |
476 | 0, /* rightshift */ | |
f5e87a1d AM |
477 | 0, /* this one is variable size */ |
478 | 0, /* bitsize */ | |
b34976b6 | 479 | FALSE, /* pc_relative */ |
5bd4f169 | 480 | 0, /* bitpos */ |
f5e87a1d AM |
481 | complain_overflow_dont, /* complain_on_overflow */ |
482 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 483 | "R_PPC64_COPY", /* name */ |
b34976b6 | 484 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
485 | 0, /* src_mask */ |
486 | 0, /* dst_mask */ | |
b34976b6 | 487 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
488 | |
489 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
490 | entries. */ | |
491 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
492 | 0, /* rightshift */ | |
493 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
494 | 64, /* bitsize */ | |
b34976b6 | 495 | FALSE, /* pc_relative */ |
5bd4f169 AM |
496 | 0, /* bitpos */ |
497 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 498 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 499 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 500 | FALSE, /* partial_inplace */ |
5bd4f169 | 501 | 0, /* src_mask */ |
f5e87a1d | 502 | ONES (64), /* dst_mask */ |
b34976b6 | 503 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
504 | |
505 | /* Created by the link editor. Marks a procedure linkage table | |
506 | entry for a symbol. */ | |
507 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
508 | 0, /* rightshift */ | |
509 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
510 | 0, /* bitsize */ | |
b34976b6 | 511 | FALSE, /* pc_relative */ |
5bd4f169 AM |
512 | 0, /* bitpos */ |
513 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 514 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 515 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 516 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
517 | 0, /* src_mask */ |
518 | 0, /* dst_mask */ | |
b34976b6 | 519 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
520 | |
521 | /* Used only by the dynamic linker. When the object is run, this | |
522 | doubleword64 is set to the load address of the object, plus the | |
523 | addend. */ | |
524 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
525 | 0, /* rightshift */ | |
526 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
527 | 64, /* bitsize */ | |
b34976b6 | 528 | FALSE, /* pc_relative */ |
5bd4f169 AM |
529 | 0, /* bitpos */ |
530 | complain_overflow_dont, /* complain_on_overflow */ | |
531 | bfd_elf_generic_reloc, /* special_function */ | |
532 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 533 | FALSE, /* partial_inplace */ |
5bd4f169 | 534 | 0, /* src_mask */ |
f5e87a1d | 535 | ONES (64), /* dst_mask */ |
b34976b6 | 536 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
537 | |
538 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
539 | HOWTO (R_PPC64_UADDR32, /* type */ | |
540 | 0, /* rightshift */ | |
541 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
542 | 32, /* bitsize */ | |
b34976b6 | 543 | FALSE, /* pc_relative */ |
5bd4f169 AM |
544 | 0, /* bitpos */ |
545 | complain_overflow_bitfield, /* complain_on_overflow */ | |
546 | bfd_elf_generic_reloc, /* special_function */ | |
547 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 548 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
549 | 0, /* src_mask */ |
550 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 551 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
552 | |
553 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
554 | HOWTO (R_PPC64_UADDR16, /* type */ | |
555 | 0, /* rightshift */ | |
556 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
557 | 16, /* bitsize */ | |
b34976b6 | 558 | FALSE, /* pc_relative */ |
5bd4f169 AM |
559 | 0, /* bitpos */ |
560 | complain_overflow_bitfield, /* complain_on_overflow */ | |
561 | bfd_elf_generic_reloc, /* special_function */ | |
562 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 563 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
564 | 0, /* src_mask */ |
565 | 0xffff, /* dst_mask */ | |
b34976b6 | 566 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
567 | |
568 | /* 32-bit PC relative. */ | |
569 | HOWTO (R_PPC64_REL32, /* type */ | |
570 | 0, /* rightshift */ | |
571 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
572 | 32, /* bitsize */ | |
b34976b6 | 573 | TRUE, /* pc_relative */ |
5bd4f169 | 574 | 0, /* bitpos */ |
cedb70c5 | 575 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
576 | complain_overflow_signed, /* complain_on_overflow */ |
577 | bfd_elf_generic_reloc, /* special_function */ | |
578 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 579 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
580 | 0, /* src_mask */ |
581 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 582 | TRUE), /* pcrel_offset */ |
5bd4f169 | 583 | |
10ed1bba | 584 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
585 | HOWTO (R_PPC64_PLT32, /* type */ |
586 | 0, /* rightshift */ | |
587 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
588 | 32, /* bitsize */ | |
b34976b6 | 589 | FALSE, /* pc_relative */ |
5bd4f169 AM |
590 | 0, /* bitpos */ |
591 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 592 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 593 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 594 | FALSE, /* partial_inplace */ |
5bd4f169 | 595 | 0, /* src_mask */ |
f5e87a1d | 596 | 0xffffffff, /* dst_mask */ |
b34976b6 | 597 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
598 | |
599 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
600 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
601 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
602 | 0, /* rightshift */ | |
603 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
604 | 32, /* bitsize */ | |
b34976b6 | 605 | TRUE, /* pc_relative */ |
5bd4f169 AM |
606 | 0, /* bitpos */ |
607 | complain_overflow_signed, /* complain_on_overflow */ | |
608 | bfd_elf_generic_reloc, /* special_function */ | |
609 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 610 | FALSE, /* partial_inplace */ |
5bd4f169 | 611 | 0, /* src_mask */ |
f5e87a1d | 612 | 0xffffffff, /* dst_mask */ |
b34976b6 | 613 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
614 | |
615 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
616 | the symbol. */ | |
617 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
618 | 0, /* rightshift */ | |
619 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
620 | 16, /* bitsize */ | |
b34976b6 | 621 | FALSE, /* pc_relative */ |
5bd4f169 AM |
622 | 0, /* bitpos */ |
623 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 624 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 625 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 626 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
627 | 0, /* src_mask */ |
628 | 0xffff, /* dst_mask */ | |
b34976b6 | 629 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
630 | |
631 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
632 | the symbol. */ | |
633 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
634 | 16, /* rightshift */ | |
635 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
636 | 16, /* bitsize */ | |
b34976b6 | 637 | FALSE, /* pc_relative */ |
5bd4f169 AM |
638 | 0, /* bitpos */ |
639 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 640 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 641 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 642 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
643 | 0, /* src_mask */ |
644 | 0xffff, /* dst_mask */ | |
b34976b6 | 645 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
646 | |
647 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
648 | the symbol. */ | |
649 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
650 | 16, /* rightshift */ | |
651 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
652 | 16, /* bitsize */ | |
b34976b6 | 653 | FALSE, /* pc_relative */ |
5bd4f169 AM |
654 | 0, /* bitpos */ |
655 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 656 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 657 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 658 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
659 | 0, /* src_mask */ |
660 | 0xffff, /* dst_mask */ | |
b34976b6 | 661 | FALSE), /* pcrel_offset */ |
5bd4f169 | 662 | |
c061c2d8 | 663 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
664 | HOWTO (R_PPC64_SECTOFF, /* type */ |
665 | 0, /* rightshift */ | |
c061c2d8 AM |
666 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
667 | 16, /* bitsize */ | |
b34976b6 | 668 | FALSE, /* pc_relative */ |
5bd4f169 AM |
669 | 0, /* bitpos */ |
670 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 671 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 672 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 673 | FALSE, /* partial_inplace */ |
5bd4f169 | 674 | 0, /* src_mask */ |
c061c2d8 | 675 | 0xffff, /* dst_mask */ |
b34976b6 | 676 | FALSE), /* pcrel_offset */ |
5bd4f169 | 677 | |
c061c2d8 | 678 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
679 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
680 | 0, /* rightshift */ | |
681 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
682 | 16, /* bitsize */ | |
b34976b6 | 683 | FALSE, /* pc_relative */ |
5bd4f169 AM |
684 | 0, /* bitpos */ |
685 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 686 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 687 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 688 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
689 | 0, /* src_mask */ |
690 | 0xffff, /* dst_mask */ | |
b34976b6 | 691 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
692 | |
693 | /* 16-bit upper half section relative relocation. */ | |
694 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
695 | 16, /* rightshift */ | |
696 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
697 | 16, /* bitsize */ | |
b34976b6 | 698 | FALSE, /* pc_relative */ |
5bd4f169 AM |
699 | 0, /* bitpos */ |
700 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 701 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 702 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 703 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
704 | 0, /* src_mask */ |
705 | 0xffff, /* dst_mask */ | |
b34976b6 | 706 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
707 | |
708 | /* 16-bit upper half adjusted section relative relocation. */ | |
709 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
710 | 16, /* rightshift */ | |
711 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
712 | 16, /* bitsize */ | |
b34976b6 | 713 | FALSE, /* pc_relative */ |
5bd4f169 AM |
714 | 0, /* bitpos */ |
715 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 716 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 717 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 718 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
719 | 0, /* src_mask */ |
720 | 0xffff, /* dst_mask */ | |
b34976b6 | 721 | FALSE), /* pcrel_offset */ |
5bd4f169 | 722 | |
04c9666a AM |
723 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
724 | HOWTO (R_PPC64_REL30, /* type */ | |
5bd4f169 AM |
725 | 2, /* rightshift */ |
726 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
727 | 30, /* bitsize */ | |
b34976b6 | 728 | TRUE, /* pc_relative */ |
5bd4f169 AM |
729 | 0, /* bitpos */ |
730 | complain_overflow_dont, /* complain_on_overflow */ | |
731 | bfd_elf_generic_reloc, /* special_function */ | |
04c9666a | 732 | "R_PPC64_REL30", /* name */ |
b34976b6 | 733 | FALSE, /* partial_inplace */ |
d006db6c | 734 | 0, /* src_mask */ |
5bd4f169 | 735 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 736 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
737 | |
738 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
739 | ||
740 | /* A standard 64-bit relocation. */ | |
741 | HOWTO (R_PPC64_ADDR64, /* type */ | |
742 | 0, /* rightshift */ | |
743 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
744 | 64, /* bitsize */ | |
b34976b6 | 745 | FALSE, /* pc_relative */ |
5bd4f169 AM |
746 | 0, /* bitpos */ |
747 | complain_overflow_dont, /* complain_on_overflow */ | |
748 | bfd_elf_generic_reloc, /* special_function */ | |
749 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 750 | FALSE, /* partial_inplace */ |
5bd4f169 | 751 | 0, /* src_mask */ |
f5e87a1d | 752 | ONES (64), /* dst_mask */ |
b34976b6 | 753 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
754 | |
755 | /* The bits 32-47 of an address. */ | |
756 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
757 | 32, /* rightshift */ | |
758 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
759 | 16, /* bitsize */ | |
b34976b6 | 760 | FALSE, /* pc_relative */ |
5bd4f169 AM |
761 | 0, /* bitpos */ |
762 | complain_overflow_dont, /* complain_on_overflow */ | |
763 | bfd_elf_generic_reloc, /* special_function */ | |
764 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 765 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
766 | 0, /* src_mask */ |
767 | 0xffff, /* dst_mask */ | |
b34976b6 | 768 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
769 | |
770 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
771 | 16 bits, treated as a signed number, is negative. */ | |
772 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
773 | 32, /* rightshift */ | |
774 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
775 | 16, /* bitsize */ | |
b34976b6 | 776 | FALSE, /* pc_relative */ |
5bd4f169 AM |
777 | 0, /* bitpos */ |
778 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 779 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 780 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 781 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
782 | 0, /* src_mask */ |
783 | 0xffff, /* dst_mask */ | |
b34976b6 | 784 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
785 | |
786 | /* The bits 48-63 of an address. */ | |
787 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
788 | 48, /* rightshift */ | |
789 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
790 | 16, /* bitsize */ | |
b34976b6 | 791 | FALSE, /* pc_relative */ |
5bd4f169 AM |
792 | 0, /* bitpos */ |
793 | complain_overflow_dont, /* complain_on_overflow */ | |
794 | bfd_elf_generic_reloc, /* special_function */ | |
795 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
b34976b6 | 796 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
797 | 0, /* src_mask */ |
798 | 0xffff, /* dst_mask */ | |
b34976b6 | 799 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
800 | |
801 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
802 | 16 bits, treated as a signed number, is negative. */ | |
803 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
804 | 48, /* rightshift */ | |
805 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
806 | 16, /* bitsize */ | |
b34976b6 | 807 | FALSE, /* pc_relative */ |
5bd4f169 AM |
808 | 0, /* bitpos */ |
809 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 810 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 811 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
b34976b6 | 812 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
813 | 0, /* src_mask */ |
814 | 0xffff, /* dst_mask */ | |
b34976b6 | 815 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
816 | |
817 | /* Like ADDR64, but may be unaligned. */ | |
818 | HOWTO (R_PPC64_UADDR64, /* type */ | |
819 | 0, /* rightshift */ | |
820 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
821 | 64, /* bitsize */ | |
b34976b6 | 822 | FALSE, /* pc_relative */ |
5bd4f169 AM |
823 | 0, /* bitpos */ |
824 | complain_overflow_dont, /* complain_on_overflow */ | |
825 | bfd_elf_generic_reloc, /* special_function */ | |
826 | "R_PPC64_UADDR64", /* name */ | |
b34976b6 | 827 | FALSE, /* partial_inplace */ |
5bd4f169 | 828 | 0, /* src_mask */ |
f5e87a1d | 829 | ONES (64), /* dst_mask */ |
b34976b6 | 830 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
831 | |
832 | /* 64-bit relative relocation. */ | |
833 | HOWTO (R_PPC64_REL64, /* type */ | |
834 | 0, /* rightshift */ | |
835 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
836 | 64, /* bitsize */ | |
b34976b6 | 837 | TRUE, /* pc_relative */ |
5bd4f169 AM |
838 | 0, /* bitpos */ |
839 | complain_overflow_dont, /* complain_on_overflow */ | |
840 | bfd_elf_generic_reloc, /* special_function */ | |
841 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 842 | FALSE, /* partial_inplace */ |
5bd4f169 | 843 | 0, /* src_mask */ |
f5e87a1d | 844 | ONES (64), /* dst_mask */ |
b34976b6 | 845 | TRUE), /* pcrel_offset */ |
5bd4f169 | 846 | |
cedb70c5 | 847 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
848 | HOWTO (R_PPC64_PLT64, /* type */ |
849 | 0, /* rightshift */ | |
850 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
851 | 64, /* bitsize */ | |
b34976b6 | 852 | FALSE, /* pc_relative */ |
5bd4f169 AM |
853 | 0, /* bitpos */ |
854 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 855 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 856 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 857 | FALSE, /* partial_inplace */ |
5bd4f169 | 858 | 0, /* src_mask */ |
f5e87a1d | 859 | ONES (64), /* dst_mask */ |
b34976b6 | 860 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
861 | |
862 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
863 | table. */ | |
864 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
865 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
866 | 0, /* rightshift */ | |
867 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
868 | 64, /* bitsize */ | |
b34976b6 | 869 | TRUE, /* pc_relative */ |
5bd4f169 AM |
870 | 0, /* bitpos */ |
871 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 872 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 873 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 874 | FALSE, /* partial_inplace */ |
5bd4f169 | 875 | 0, /* src_mask */ |
f5e87a1d | 876 | ONES (64), /* dst_mask */ |
b34976b6 | 877 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
878 | |
879 | /* 16 bit TOC-relative relocation. */ | |
880 | ||
881 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
882 | HOWTO (R_PPC64_TOC16, /* type */ | |
883 | 0, /* rightshift */ | |
884 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
885 | 16, /* bitsize */ | |
b34976b6 | 886 | FALSE, /* pc_relative */ |
5bd4f169 AM |
887 | 0, /* bitpos */ |
888 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 889 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 890 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 891 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
892 | 0, /* src_mask */ |
893 | 0xffff, /* dst_mask */ | |
b34976b6 | 894 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
895 | |
896 | /* 16 bit TOC-relative relocation without overflow. */ | |
897 | ||
898 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
899 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
900 | 0, /* rightshift */ | |
901 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
902 | 16, /* bitsize */ | |
b34976b6 | 903 | FALSE, /* pc_relative */ |
5bd4f169 AM |
904 | 0, /* bitpos */ |
905 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 906 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 907 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 908 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
909 | 0, /* src_mask */ |
910 | 0xffff, /* dst_mask */ | |
b34976b6 | 911 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
912 | |
913 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
914 | ||
915 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
916 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
917 | 16, /* rightshift */ | |
918 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
919 | 16, /* bitsize */ | |
b34976b6 | 920 | FALSE, /* pc_relative */ |
5bd4f169 AM |
921 | 0, /* bitpos */ |
922 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 923 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 924 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 925 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
926 | 0, /* src_mask */ |
927 | 0xffff, /* dst_mask */ | |
b34976b6 | 928 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
929 | |
930 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
931 | contents of the low 16 bits, treated as a signed number, is | |
932 | negative. */ | |
933 | ||
934 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
935 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
936 | 16, /* rightshift */ | |
937 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
938 | 16, /* bitsize */ | |
b34976b6 | 939 | FALSE, /* pc_relative */ |
5bd4f169 AM |
940 | 0, /* bitpos */ |
941 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 942 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 943 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 944 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
945 | 0, /* src_mask */ |
946 | 0xffff, /* dst_mask */ | |
b34976b6 | 947 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
948 | |
949 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
950 | ||
951 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
952 | HOWTO (R_PPC64_TOC, /* type */ | |
953 | 0, /* rightshift */ | |
954 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
955 | 64, /* bitsize */ | |
b34976b6 | 956 | FALSE, /* pc_relative */ |
5bd4f169 AM |
957 | 0, /* bitpos */ |
958 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 959 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 960 | "R_PPC64_TOC", /* name */ |
b34976b6 | 961 | FALSE, /* partial_inplace */ |
5bd4f169 | 962 | 0, /* src_mask */ |
f5e87a1d | 963 | ONES (64), /* dst_mask */ |
b34976b6 | 964 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
965 | |
966 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
967 | value to relocate may (!) refer to a PLT entry which the link | |
968 | editor (a) may replace with the symbol value. If the link editor | |
969 | is unable to fully resolve the symbol, it may (b) create a PLT | |
970 | entry and store the address to the new PLT entry in the GOT. | |
971 | This permits lazy resolution of function symbols at run time. | |
972 | The link editor may also skip all of this and just (c) emit a | |
973 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
974 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
975 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
976 | 0, /* rightshift */ | |
977 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
978 | 16, /* bitsize */ | |
b34976b6 | 979 | FALSE, /* pc_relative */ |
5bd4f169 AM |
980 | 0, /* bitpos */ |
981 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 982 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb AM |
983 | "R_PPC64_PLTGOT16", /* name */ |
984 | FALSE, /* partial_inplace */ | |
985 | 0, /* src_mask */ | |
986 | 0xffff, /* dst_mask */ | |
987 | FALSE), /* pcrel_offset */ | |
988 | ||
989 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
990 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
991 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
992 | 0, /* rightshift */ | |
993 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
994 | 16, /* bitsize */ | |
995 | FALSE, /* pc_relative */ | |
996 | 0, /* bitpos */ | |
997 | complain_overflow_dont, /* complain_on_overflow */ | |
998 | ppc64_elf_unhandled_reloc, /* special_function */ | |
999 | "R_PPC64_PLTGOT16_LO", /* name */ | |
1000 | FALSE, /* partial_inplace */ | |
1001 | 0, /* src_mask */ | |
1002 | 0xffff, /* dst_mask */ | |
1003 | FALSE), /* pcrel_offset */ | |
1004 | ||
1005 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
1006 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
1007 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
1008 | 16, /* rightshift */ | |
1009 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1010 | 16, /* bitsize */ | |
1011 | FALSE, /* pc_relative */ | |
1012 | 0, /* bitpos */ | |
1013 | complain_overflow_dont, /* complain_on_overflow */ | |
1014 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1015 | "R_PPC64_PLTGOT16_HI", /* name */ | |
1016 | FALSE, /* partial_inplace */ | |
1017 | 0, /* src_mask */ | |
1018 | 0xffff, /* dst_mask */ | |
1019 | FALSE), /* pcrel_offset */ | |
1020 | ||
1021 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
1022 | 1 if the contents of the low 16 bits, treated as a signed number, | |
1023 | is negative. */ | |
1024 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
1025 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
1026 | 16, /* rightshift */ | |
1027 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1028 | 16, /* bitsize */ | |
1029 | FALSE, /* pc_relative */ | |
1030 | 0, /* bitpos */ | |
1031 | complain_overflow_dont,/* complain_on_overflow */ | |
1032 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1033 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1034 | FALSE, /* partial_inplace */ | |
1035 | 0, /* src_mask */ | |
1036 | 0xffff, /* dst_mask */ | |
1037 | FALSE), /* pcrel_offset */ | |
1038 | ||
1039 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1040 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1041 | 0, /* rightshift */ | |
1042 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1043 | 16, /* bitsize */ | |
1044 | FALSE, /* pc_relative */ | |
1045 | 0, /* bitpos */ | |
1046 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1047 | bfd_elf_generic_reloc, /* special_function */ | |
1048 | "R_PPC64_ADDR16_DS", /* name */ | |
1049 | FALSE, /* partial_inplace */ | |
1050 | 0, /* src_mask */ | |
1051 | 0xfffc, /* dst_mask */ | |
1052 | FALSE), /* pcrel_offset */ | |
1053 | ||
1054 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1055 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1056 | 0, /* rightshift */ | |
1057 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1058 | 16, /* bitsize */ | |
1059 | FALSE, /* pc_relative */ | |
1060 | 0, /* bitpos */ | |
1061 | complain_overflow_dont,/* complain_on_overflow */ | |
1062 | bfd_elf_generic_reloc, /* special_function */ | |
1063 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1064 | FALSE, /* partial_inplace */ | |
1065 | 0, /* src_mask */ | |
1066 | 0xfffc, /* dst_mask */ | |
1067 | FALSE), /* pcrel_offset */ | |
1068 | ||
1069 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1070 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1071 | 0, /* rightshift */ | |
1072 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1073 | 16, /* bitsize */ | |
1074 | FALSE, /* pc_relative */ | |
1075 | 0, /* bitpos */ | |
1076 | complain_overflow_signed, /* complain_on_overflow */ | |
1077 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1078 | "R_PPC64_GOT16_DS", /* name */ | |
1079 | FALSE, /* partial_inplace */ | |
1080 | 0, /* src_mask */ | |
1081 | 0xfffc, /* dst_mask */ | |
1082 | FALSE), /* pcrel_offset */ | |
1083 | ||
1084 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1085 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1086 | 0, /* rightshift */ | |
1087 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1088 | 16, /* bitsize */ | |
1089 | FALSE, /* pc_relative */ | |
1090 | 0, /* bitpos */ | |
1091 | complain_overflow_dont, /* complain_on_overflow */ | |
1092 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1093 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1094 | FALSE, /* partial_inplace */ | |
1095 | 0, /* src_mask */ | |
1096 | 0xfffc, /* dst_mask */ | |
1097 | FALSE), /* pcrel_offset */ | |
1098 | ||
1099 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1100 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1101 | 0, /* rightshift */ | |
1102 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1103 | 16, /* bitsize */ | |
1104 | FALSE, /* pc_relative */ | |
1105 | 0, /* bitpos */ | |
1106 | complain_overflow_dont, /* complain_on_overflow */ | |
1107 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1108 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1109 | FALSE, /* partial_inplace */ | |
1110 | 0, /* src_mask */ | |
1111 | 0xfffc, /* dst_mask */ | |
1112 | FALSE), /* pcrel_offset */ | |
1113 | ||
1114 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1115 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1116 | 0, /* rightshift */ | |
1117 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1118 | 16, /* bitsize */ | |
1119 | FALSE, /* pc_relative */ | |
1120 | 0, /* bitpos */ | |
1121 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1122 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1123 | "R_PPC64_SECTOFF_DS", /* name */ | |
1124 | FALSE, /* partial_inplace */ | |
1125 | 0, /* src_mask */ | |
1126 | 0xfffc, /* dst_mask */ | |
1127 | FALSE), /* pcrel_offset */ | |
1128 | ||
1129 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1130 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1131 | 0, /* rightshift */ | |
1132 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1133 | 16, /* bitsize */ | |
1134 | FALSE, /* pc_relative */ | |
1135 | 0, /* bitpos */ | |
1136 | complain_overflow_dont, /* complain_on_overflow */ | |
1137 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1138 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1139 | FALSE, /* partial_inplace */ | |
1140 | 0, /* src_mask */ | |
1141 | 0xfffc, /* dst_mask */ | |
1142 | FALSE), /* pcrel_offset */ | |
1143 | ||
1144 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1145 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1146 | 0, /* rightshift */ | |
1147 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1148 | 16, /* bitsize */ | |
1149 | FALSE, /* pc_relative */ | |
1150 | 0, /* bitpos */ | |
1151 | complain_overflow_signed, /* complain_on_overflow */ | |
1152 | ppc64_elf_toc_reloc, /* special_function */ | |
1153 | "R_PPC64_TOC16_DS", /* name */ | |
1154 | FALSE, /* partial_inplace */ | |
1155 | 0, /* src_mask */ | |
1156 | 0xfffc, /* dst_mask */ | |
1157 | FALSE), /* pcrel_offset */ | |
1158 | ||
1159 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1160 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1161 | 0, /* rightshift */ | |
1162 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1163 | 16, /* bitsize */ | |
1164 | FALSE, /* pc_relative */ | |
1165 | 0, /* bitpos */ | |
1166 | complain_overflow_dont, /* complain_on_overflow */ | |
1167 | ppc64_elf_toc_reloc, /* special_function */ | |
1168 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1169 | FALSE, /* partial_inplace */ | |
1170 | 0, /* src_mask */ | |
1171 | 0xfffc, /* dst_mask */ | |
1172 | FALSE), /* pcrel_offset */ | |
1173 | ||
1174 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1175 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1176 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ | |
1177 | 0, /* rightshift */ | |
1178 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1179 | 16, /* bitsize */ | |
1180 | FALSE, /* pc_relative */ | |
1181 | 0, /* bitpos */ | |
1182 | complain_overflow_signed, /* complain_on_overflow */ | |
1183 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1184 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1185 | FALSE, /* partial_inplace */ | |
1186 | 0, /* src_mask */ | |
1187 | 0xfffc, /* dst_mask */ | |
1188 | FALSE), /* pcrel_offset */ | |
1189 | ||
1190 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1191 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1192 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1193 | 0, /* rightshift */ | |
1194 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1195 | 16, /* bitsize */ | |
1196 | FALSE, /* pc_relative */ | |
1197 | 0, /* bitpos */ | |
1198 | complain_overflow_dont, /* complain_on_overflow */ | |
1199 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1200 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1201 | FALSE, /* partial_inplace */ | |
1202 | 0, /* src_mask */ | |
1203 | 0xfffc, /* dst_mask */ | |
1204 | FALSE), /* pcrel_offset */ | |
1205 | ||
1206 | /* Marker reloc for TLS. */ | |
1207 | HOWTO (R_PPC64_TLS, | |
1208 | 0, /* rightshift */ | |
1209 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1210 | 32, /* bitsize */ | |
1211 | FALSE, /* pc_relative */ | |
1212 | 0, /* bitpos */ | |
1213 | complain_overflow_dont, /* complain_on_overflow */ | |
1214 | bfd_elf_generic_reloc, /* special_function */ | |
1215 | "R_PPC64_TLS", /* name */ | |
1216 | FALSE, /* partial_inplace */ | |
1217 | 0, /* src_mask */ | |
1218 | 0, /* dst_mask */ | |
1219 | FALSE), /* pcrel_offset */ | |
1220 | ||
1221 | /* Computes the load module index of the load module that contains the | |
1222 | definition of its TLS sym. */ | |
1223 | HOWTO (R_PPC64_DTPMOD64, | |
1224 | 0, /* rightshift */ | |
1225 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1226 | 64, /* bitsize */ | |
1227 | FALSE, /* pc_relative */ | |
1228 | 0, /* bitpos */ | |
1229 | complain_overflow_dont, /* complain_on_overflow */ | |
1230 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1231 | "R_PPC64_DTPMOD64", /* name */ | |
1232 | FALSE, /* partial_inplace */ | |
1233 | 0, /* src_mask */ | |
1234 | ONES (64), /* dst_mask */ | |
1235 | FALSE), /* pcrel_offset */ | |
1236 | ||
1237 | /* Computes a dtv-relative displacement, the difference between the value | |
1238 | of sym+add and the base address of the thread-local storage block that | |
1239 | contains the definition of sym, minus 0x8000. */ | |
1240 | HOWTO (R_PPC64_DTPREL64, | |
1241 | 0, /* rightshift */ | |
1242 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1243 | 64, /* bitsize */ | |
1244 | FALSE, /* pc_relative */ | |
1245 | 0, /* bitpos */ | |
1246 | complain_overflow_dont, /* complain_on_overflow */ | |
1247 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1248 | "R_PPC64_DTPREL64", /* name */ | |
1249 | FALSE, /* partial_inplace */ | |
1250 | 0, /* src_mask */ | |
1251 | ONES (64), /* dst_mask */ | |
1252 | FALSE), /* pcrel_offset */ | |
1253 | ||
1254 | /* A 16 bit dtprel reloc. */ | |
1255 | HOWTO (R_PPC64_DTPREL16, | |
1256 | 0, /* rightshift */ | |
1257 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1258 | 16, /* bitsize */ | |
1259 | FALSE, /* pc_relative */ | |
1260 | 0, /* bitpos */ | |
1261 | complain_overflow_signed, /* complain_on_overflow */ | |
1262 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1263 | "R_PPC64_DTPREL16", /* name */ | |
1264 | FALSE, /* partial_inplace */ | |
1265 | 0, /* src_mask */ | |
1266 | 0xffff, /* dst_mask */ | |
1267 | FALSE), /* pcrel_offset */ | |
1268 | ||
1269 | /* Like DTPREL16, but no overflow. */ | |
1270 | HOWTO (R_PPC64_DTPREL16_LO, | |
1271 | 0, /* rightshift */ | |
1272 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1273 | 16, /* bitsize */ | |
1274 | FALSE, /* pc_relative */ | |
1275 | 0, /* bitpos */ | |
1276 | complain_overflow_dont, /* complain_on_overflow */ | |
1277 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1278 | "R_PPC64_DTPREL16_LO", /* name */ | |
1279 | FALSE, /* partial_inplace */ | |
1280 | 0, /* src_mask */ | |
1281 | 0xffff, /* dst_mask */ | |
1282 | FALSE), /* pcrel_offset */ | |
1283 | ||
1284 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ | |
1285 | HOWTO (R_PPC64_DTPREL16_HI, | |
1286 | 16, /* rightshift */ | |
1287 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1288 | 16, /* bitsize */ | |
1289 | FALSE, /* pc_relative */ | |
1290 | 0, /* bitpos */ | |
1291 | complain_overflow_dont, /* complain_on_overflow */ | |
1292 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1293 | "R_PPC64_DTPREL16_HI", /* name */ | |
1294 | FALSE, /* partial_inplace */ | |
1295 | 0, /* src_mask */ | |
1296 | 0xffff, /* dst_mask */ | |
1297 | FALSE), /* pcrel_offset */ | |
1298 | ||
1299 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ | |
1300 | HOWTO (R_PPC64_DTPREL16_HA, | |
1301 | 16, /* rightshift */ | |
1302 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1303 | 16, /* bitsize */ | |
1304 | FALSE, /* pc_relative */ | |
1305 | 0, /* bitpos */ | |
1306 | complain_overflow_dont, /* complain_on_overflow */ | |
1307 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1308 | "R_PPC64_DTPREL16_HA", /* name */ | |
1309 | FALSE, /* partial_inplace */ | |
1310 | 0, /* src_mask */ | |
1311 | 0xffff, /* dst_mask */ | |
1312 | FALSE), /* pcrel_offset */ | |
1313 | ||
1314 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ | |
1315 | HOWTO (R_PPC64_DTPREL16_HIGHER, | |
1316 | 32, /* rightshift */ | |
1317 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1318 | 16, /* bitsize */ | |
1319 | FALSE, /* pc_relative */ | |
1320 | 0, /* bitpos */ | |
1321 | complain_overflow_dont, /* complain_on_overflow */ | |
1322 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1323 | "R_PPC64_DTPREL16_HIGHER", /* name */ | |
1324 | FALSE, /* partial_inplace */ | |
1325 | 0, /* src_mask */ | |
1326 | 0xffff, /* dst_mask */ | |
1327 | FALSE), /* pcrel_offset */ | |
1328 | ||
1329 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ | |
1330 | HOWTO (R_PPC64_DTPREL16_HIGHERA, | |
1331 | 32, /* rightshift */ | |
1332 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1333 | 16, /* bitsize */ | |
1334 | FALSE, /* pc_relative */ | |
1335 | 0, /* bitpos */ | |
1336 | complain_overflow_dont, /* complain_on_overflow */ | |
1337 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1338 | "R_PPC64_DTPREL16_HIGHERA", /* name */ | |
1339 | FALSE, /* partial_inplace */ | |
1340 | 0, /* src_mask */ | |
1341 | 0xffff, /* dst_mask */ | |
1342 | FALSE), /* pcrel_offset */ | |
1343 | ||
1344 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ | |
1345 | HOWTO (R_PPC64_DTPREL16_HIGHEST, | |
1346 | 48, /* rightshift */ | |
1347 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1348 | 16, /* bitsize */ | |
1349 | FALSE, /* pc_relative */ | |
1350 | 0, /* bitpos */ | |
1351 | complain_overflow_dont, /* complain_on_overflow */ | |
1352 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1353 | "R_PPC64_DTPREL16_HIGHEST", /* name */ | |
1354 | FALSE, /* partial_inplace */ | |
1355 | 0, /* src_mask */ | |
1356 | 0xffff, /* dst_mask */ | |
1357 | FALSE), /* pcrel_offset */ | |
1358 | ||
1359 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1360 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, | |
1361 | 48, /* rightshift */ | |
1362 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1363 | 16, /* bitsize */ | |
1364 | FALSE, /* pc_relative */ | |
1365 | 0, /* bitpos */ | |
1366 | complain_overflow_dont, /* complain_on_overflow */ | |
1367 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1368 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ | |
1369 | FALSE, /* partial_inplace */ | |
1370 | 0, /* src_mask */ | |
1371 | 0xffff, /* dst_mask */ | |
1372 | FALSE), /* pcrel_offset */ | |
1373 | ||
1374 | /* Like DTPREL16, but for insns with a DS field. */ | |
1375 | HOWTO (R_PPC64_DTPREL16_DS, | |
1376 | 0, /* rightshift */ | |
1377 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1378 | 16, /* bitsize */ | |
1379 | FALSE, /* pc_relative */ | |
1380 | 0, /* bitpos */ | |
1381 | complain_overflow_signed, /* complain_on_overflow */ | |
1382 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1383 | "R_PPC64_DTPREL16_DS", /* name */ | |
1384 | FALSE, /* partial_inplace */ | |
1385 | 0, /* src_mask */ | |
1386 | 0xfffc, /* dst_mask */ | |
1387 | FALSE), /* pcrel_offset */ | |
1388 | ||
1389 | /* Like DTPREL16_DS, but no overflow. */ | |
1390 | HOWTO (R_PPC64_DTPREL16_LO_DS, | |
1391 | 0, /* rightshift */ | |
1392 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1393 | 16, /* bitsize */ | |
1394 | FALSE, /* pc_relative */ | |
1395 | 0, /* bitpos */ | |
1396 | complain_overflow_dont, /* complain_on_overflow */ | |
1397 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1398 | "R_PPC64_DTPREL16_LO_DS", /* name */ | |
1399 | FALSE, /* partial_inplace */ | |
1400 | 0, /* src_mask */ | |
1401 | 0xfffc, /* dst_mask */ | |
1402 | FALSE), /* pcrel_offset */ | |
1403 | ||
1404 | /* Computes a tp-relative displacement, the difference between the value of | |
1405 | sym+add and the value of the thread pointer (r13). */ | |
1406 | HOWTO (R_PPC64_TPREL64, | |
1407 | 0, /* rightshift */ | |
1408 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1409 | 64, /* bitsize */ | |
1410 | FALSE, /* pc_relative */ | |
1411 | 0, /* bitpos */ | |
1412 | complain_overflow_dont, /* complain_on_overflow */ | |
1413 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1414 | "R_PPC64_TPREL64", /* name */ | |
1415 | FALSE, /* partial_inplace */ | |
1416 | 0, /* src_mask */ | |
1417 | ONES (64), /* dst_mask */ | |
1418 | FALSE), /* pcrel_offset */ | |
1419 | ||
1420 | /* A 16 bit tprel reloc. */ | |
1421 | HOWTO (R_PPC64_TPREL16, | |
1422 | 0, /* rightshift */ | |
1423 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1424 | 16, /* bitsize */ | |
1425 | FALSE, /* pc_relative */ | |
1426 | 0, /* bitpos */ | |
1427 | complain_overflow_signed, /* complain_on_overflow */ | |
1428 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1429 | "R_PPC64_TPREL16", /* name */ | |
1430 | FALSE, /* partial_inplace */ | |
1431 | 0, /* src_mask */ | |
1432 | 0xffff, /* dst_mask */ | |
1433 | FALSE), /* pcrel_offset */ | |
1434 | ||
1435 | /* Like TPREL16, but no overflow. */ | |
1436 | HOWTO (R_PPC64_TPREL16_LO, | |
1437 | 0, /* rightshift */ | |
1438 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1439 | 16, /* bitsize */ | |
1440 | FALSE, /* pc_relative */ | |
1441 | 0, /* bitpos */ | |
1442 | complain_overflow_dont, /* complain_on_overflow */ | |
1443 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1444 | "R_PPC64_TPREL16_LO", /* name */ | |
1445 | FALSE, /* partial_inplace */ | |
1446 | 0, /* src_mask */ | |
1447 | 0xffff, /* dst_mask */ | |
1448 | FALSE), /* pcrel_offset */ | |
1449 | ||
1450 | /* Like TPREL16_LO, but next higher group of 16 bits. */ | |
1451 | HOWTO (R_PPC64_TPREL16_HI, | |
1452 | 16, /* rightshift */ | |
1453 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1454 | 16, /* bitsize */ | |
1455 | FALSE, /* pc_relative */ | |
1456 | 0, /* bitpos */ | |
1457 | complain_overflow_dont, /* complain_on_overflow */ | |
1458 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1459 | "R_PPC64_TPREL16_HI", /* name */ | |
1460 | FALSE, /* partial_inplace */ | |
1461 | 0, /* src_mask */ | |
1462 | 0xffff, /* dst_mask */ | |
1463 | FALSE), /* pcrel_offset */ | |
1464 | ||
1465 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1466 | HOWTO (R_PPC64_TPREL16_HA, | |
1467 | 16, /* rightshift */ | |
1468 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1469 | 16, /* bitsize */ | |
1470 | FALSE, /* pc_relative */ | |
1471 | 0, /* bitpos */ | |
1472 | complain_overflow_dont, /* complain_on_overflow */ | |
1473 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1474 | "R_PPC64_TPREL16_HA", /* name */ | |
1475 | FALSE, /* partial_inplace */ | |
1476 | 0, /* src_mask */ | |
1477 | 0xffff, /* dst_mask */ | |
1478 | FALSE), /* pcrel_offset */ | |
1479 | ||
1480 | /* Like TPREL16_HI, but next higher group of 16 bits. */ | |
1481 | HOWTO (R_PPC64_TPREL16_HIGHER, | |
1482 | 32, /* rightshift */ | |
1483 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1484 | 16, /* bitsize */ | |
1485 | FALSE, /* pc_relative */ | |
1486 | 0, /* bitpos */ | |
1487 | complain_overflow_dont, /* complain_on_overflow */ | |
1488 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1489 | "R_PPC64_TPREL16_HIGHER", /* name */ | |
1490 | FALSE, /* partial_inplace */ | |
1491 | 0, /* src_mask */ | |
1492 | 0xffff, /* dst_mask */ | |
1493 | FALSE), /* pcrel_offset */ | |
1494 | ||
1495 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ | |
1496 | HOWTO (R_PPC64_TPREL16_HIGHERA, | |
1497 | 32, /* rightshift */ | |
1498 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1499 | 16, /* bitsize */ | |
1500 | FALSE, /* pc_relative */ | |
1501 | 0, /* bitpos */ | |
1502 | complain_overflow_dont, /* complain_on_overflow */ | |
1503 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1504 | "R_PPC64_TPREL16_HIGHERA", /* name */ | |
1505 | FALSE, /* partial_inplace */ | |
1506 | 0, /* src_mask */ | |
1507 | 0xffff, /* dst_mask */ | |
1508 | FALSE), /* pcrel_offset */ | |
1509 | ||
1510 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ | |
1511 | HOWTO (R_PPC64_TPREL16_HIGHEST, | |
1512 | 48, /* rightshift */ | |
1513 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1514 | 16, /* bitsize */ | |
1515 | FALSE, /* pc_relative */ | |
1516 | 0, /* bitpos */ | |
1517 | complain_overflow_dont, /* complain_on_overflow */ | |
1518 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1519 | "R_PPC64_TPREL16_HIGHEST", /* name */ | |
1520 | FALSE, /* partial_inplace */ | |
1521 | 0, /* src_mask */ | |
1522 | 0xffff, /* dst_mask */ | |
1523 | FALSE), /* pcrel_offset */ | |
1524 | ||
1525 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1526 | HOWTO (R_PPC64_TPREL16_HIGHESTA, | |
1527 | 48, /* rightshift */ | |
1528 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1529 | 16, /* bitsize */ | |
1530 | FALSE, /* pc_relative */ | |
1531 | 0, /* bitpos */ | |
1532 | complain_overflow_dont, /* complain_on_overflow */ | |
1533 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1534 | "R_PPC64_TPREL16_HIGHESTA", /* name */ | |
1535 | FALSE, /* partial_inplace */ | |
1536 | 0, /* src_mask */ | |
1537 | 0xffff, /* dst_mask */ | |
1538 | FALSE), /* pcrel_offset */ | |
1539 | ||
1540 | /* Like TPREL16, but for insns with a DS field. */ | |
1541 | HOWTO (R_PPC64_TPREL16_DS, | |
1542 | 0, /* rightshift */ | |
1543 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1544 | 16, /* bitsize */ | |
1545 | FALSE, /* pc_relative */ | |
1546 | 0, /* bitpos */ | |
1547 | complain_overflow_signed, /* complain_on_overflow */ | |
1548 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1549 | "R_PPC64_TPREL16_DS", /* name */ | |
1550 | FALSE, /* partial_inplace */ | |
1551 | 0, /* src_mask */ | |
1552 | 0xfffc, /* dst_mask */ | |
1553 | FALSE), /* pcrel_offset */ | |
1554 | ||
1555 | /* Like TPREL16_DS, but no overflow. */ | |
1556 | HOWTO (R_PPC64_TPREL16_LO_DS, | |
1557 | 0, /* rightshift */ | |
1558 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1559 | 16, /* bitsize */ | |
1560 | FALSE, /* pc_relative */ | |
1561 | 0, /* bitpos */ | |
1562 | complain_overflow_dont, /* complain_on_overflow */ | |
1563 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1564 | "R_PPC64_TPREL16_LO_DS", /* name */ | |
1565 | FALSE, /* partial_inplace */ | |
1566 | 0, /* src_mask */ | |
1567 | 0xfffc, /* dst_mask */ | |
1568 | FALSE), /* pcrel_offset */ | |
1569 | ||
1570 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1571 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1572 | to the first entry relative to the TOC base (r2). */ | |
1573 | HOWTO (R_PPC64_GOT_TLSGD16, | |
1574 | 0, /* rightshift */ | |
1575 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1576 | 16, /* bitsize */ | |
1577 | FALSE, /* pc_relative */ | |
1578 | 0, /* bitpos */ | |
1579 | complain_overflow_signed, /* complain_on_overflow */ | |
1580 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1581 | "R_PPC64_GOT_TLSGD16", /* name */ | |
b34976b6 | 1582 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1583 | 0, /* src_mask */ |
1584 | 0xffff, /* dst_mask */ | |
b34976b6 | 1585 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1586 | |
411e1bfb AM |
1587 | /* Like GOT_TLSGD16, but no overflow. */ |
1588 | HOWTO (R_PPC64_GOT_TLSGD16_LO, | |
5bd4f169 AM |
1589 | 0, /* rightshift */ |
1590 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1591 | 16, /* bitsize */ | |
b34976b6 | 1592 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1593 | 0, /* bitpos */ |
1594 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1595 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1596 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
b34976b6 | 1597 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1598 | 0, /* src_mask */ |
1599 | 0xffff, /* dst_mask */ | |
b34976b6 | 1600 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1601 | |
411e1bfb AM |
1602 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1603 | HOWTO (R_PPC64_GOT_TLSGD16_HI, | |
5bd4f169 AM |
1604 | 16, /* rightshift */ |
1605 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1606 | 16, /* bitsize */ | |
b34976b6 | 1607 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1608 | 0, /* bitpos */ |
1609 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1610 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1611 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
b34976b6 | 1612 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1613 | 0, /* src_mask */ |
1614 | 0xffff, /* dst_mask */ | |
b34976b6 | 1615 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1616 | |
411e1bfb AM |
1617 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1618 | HOWTO (R_PPC64_GOT_TLSGD16_HA, | |
5bd4f169 AM |
1619 | 16, /* rightshift */ |
1620 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1621 | 16, /* bitsize */ | |
b34976b6 | 1622 | FALSE, /* pc_relative */ |
5bd4f169 | 1623 | 0, /* bitpos */ |
411e1bfb | 1624 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1625 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1626 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
b34976b6 | 1627 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1628 | 0, /* src_mask */ |
1629 | 0xffff, /* dst_mask */ | |
b34976b6 | 1630 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1631 | |
411e1bfb AM |
1632 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
1633 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1634 | first entry relative to the TOC base (r2). */ | |
1635 | HOWTO (R_PPC64_GOT_TLSLD16, | |
5bd4f169 AM |
1636 | 0, /* rightshift */ |
1637 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1638 | 16, /* bitsize */ | |
b34976b6 | 1639 | FALSE, /* pc_relative */ |
5bd4f169 | 1640 | 0, /* bitpos */ |
411e1bfb AM |
1641 | complain_overflow_signed, /* complain_on_overflow */ |
1642 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1643 | "R_PPC64_GOT_TLSLD16", /* name */ | |
b34976b6 | 1644 | FALSE, /* partial_inplace */ |
d006db6c | 1645 | 0, /* src_mask */ |
411e1bfb | 1646 | 0xffff, /* dst_mask */ |
b34976b6 | 1647 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1648 | |
411e1bfb AM |
1649 | /* Like GOT_TLSLD16, but no overflow. */ |
1650 | HOWTO (R_PPC64_GOT_TLSLD16_LO, | |
5bd4f169 AM |
1651 | 0, /* rightshift */ |
1652 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1653 | 16, /* bitsize */ | |
b34976b6 | 1654 | FALSE, /* pc_relative */ |
5bd4f169 | 1655 | 0, /* bitpos */ |
411e1bfb AM |
1656 | complain_overflow_dont, /* complain_on_overflow */ |
1657 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1658 | "R_PPC64_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1659 | FALSE, /* partial_inplace */ |
d006db6c | 1660 | 0, /* src_mask */ |
411e1bfb | 1661 | 0xffff, /* dst_mask */ |
b34976b6 | 1662 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1663 | |
411e1bfb AM |
1664 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1665 | HOWTO (R_PPC64_GOT_TLSLD16_HI, | |
1666 | 16, /* rightshift */ | |
5bd4f169 AM |
1667 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1668 | 16, /* bitsize */ | |
b34976b6 | 1669 | FALSE, /* pc_relative */ |
5bd4f169 | 1670 | 0, /* bitpos */ |
411e1bfb | 1671 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1672 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1673 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
b34976b6 | 1674 | FALSE, /* partial_inplace */ |
d006db6c | 1675 | 0, /* src_mask */ |
411e1bfb | 1676 | 0xffff, /* dst_mask */ |
b34976b6 | 1677 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1678 | |
411e1bfb AM |
1679 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1680 | HOWTO (R_PPC64_GOT_TLSLD16_HA, | |
1681 | 16, /* rightshift */ | |
5bd4f169 AM |
1682 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1683 | 16, /* bitsize */ | |
b34976b6 | 1684 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1685 | 0, /* bitpos */ |
1686 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1687 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1688 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
b34976b6 | 1689 | FALSE, /* partial_inplace */ |
d006db6c | 1690 | 0, /* src_mask */ |
411e1bfb | 1691 | 0xffff, /* dst_mask */ |
b34976b6 | 1692 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1693 | |
411e1bfb AM |
1694 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
1695 | the offset to the entry relative to the TOC base (r2). */ | |
1696 | HOWTO (R_PPC64_GOT_DTPREL16_DS, | |
5bd4f169 AM |
1697 | 0, /* rightshift */ |
1698 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1699 | 16, /* bitsize */ | |
b34976b6 | 1700 | FALSE, /* pc_relative */ |
5bd4f169 | 1701 | 0, /* bitpos */ |
411e1bfb | 1702 | complain_overflow_signed, /* complain_on_overflow */ |
805fc799 | 1703 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1704 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
b34976b6 | 1705 | FALSE, /* partial_inplace */ |
d006db6c | 1706 | 0, /* src_mask */ |
5bd4f169 | 1707 | 0xfffc, /* dst_mask */ |
b34976b6 | 1708 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1709 | |
411e1bfb AM |
1710 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
1711 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, | |
5bd4f169 | 1712 | 0, /* rightshift */ |
c061c2d8 AM |
1713 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1714 | 16, /* bitsize */ | |
b34976b6 | 1715 | FALSE, /* pc_relative */ |
5bd4f169 | 1716 | 0, /* bitpos */ |
411e1bfb AM |
1717 | complain_overflow_dont, /* complain_on_overflow */ |
1718 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1719 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ | |
b34976b6 | 1720 | FALSE, /* partial_inplace */ |
d006db6c | 1721 | 0, /* src_mask */ |
c061c2d8 | 1722 | 0xfffc, /* dst_mask */ |
b34976b6 | 1723 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1724 | |
411e1bfb AM |
1725 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
1726 | HOWTO (R_PPC64_GOT_DTPREL16_HI, | |
1727 | 16, /* rightshift */ | |
5bd4f169 AM |
1728 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1729 | 16, /* bitsize */ | |
b34976b6 | 1730 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1731 | 0, /* bitpos */ |
1732 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1733 | ppc64_elf_unhandled_reloc, /* special_function */ |
1734 | "R_PPC64_GOT_DTPREL16_HI", /* name */ | |
b34976b6 | 1735 | FALSE, /* partial_inplace */ |
d006db6c | 1736 | 0, /* src_mask */ |
411e1bfb | 1737 | 0xffff, /* dst_mask */ |
b34976b6 | 1738 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1739 | |
411e1bfb AM |
1740 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1741 | HOWTO (R_PPC64_GOT_DTPREL16_HA, | |
1742 | 16, /* rightshift */ | |
1743 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1744 | 16, /* bitsize */ | |
1745 | FALSE, /* pc_relative */ | |
1746 | 0, /* bitpos */ | |
1747 | complain_overflow_dont, /* complain_on_overflow */ | |
1748 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1749 | "R_PPC64_GOT_DTPREL16_HA", /* name */ | |
1750 | FALSE, /* partial_inplace */ | |
1751 | 0, /* src_mask */ | |
1752 | 0xffff, /* dst_mask */ | |
1753 | FALSE), /* pcrel_offset */ | |
1754 | ||
1755 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the | |
1756 | offset to the entry relative to the TOC base (r2). */ | |
1757 | HOWTO (R_PPC64_GOT_TPREL16_DS, | |
5bd4f169 AM |
1758 | 0, /* rightshift */ |
1759 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1760 | 16, /* bitsize */ | |
b34976b6 | 1761 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1762 | 0, /* bitpos */ |
1763 | complain_overflow_signed, /* complain_on_overflow */ | |
411e1bfb AM |
1764 | ppc64_elf_unhandled_reloc, /* special_function */ |
1765 | "R_PPC64_GOT_TPREL16_DS", /* name */ | |
b34976b6 | 1766 | FALSE, /* partial_inplace */ |
d006db6c | 1767 | 0, /* src_mask */ |
ad8e1ba5 | 1768 | 0xfffc, /* dst_mask */ |
b34976b6 | 1769 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1770 | |
411e1bfb AM |
1771 | /* Like GOT_TPREL16_DS, but no overflow. */ |
1772 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, | |
5bd4f169 AM |
1773 | 0, /* rightshift */ |
1774 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1775 | 16, /* bitsize */ | |
b34976b6 | 1776 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1777 | 0, /* bitpos */ |
1778 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1779 | ppc64_elf_unhandled_reloc, /* special_function */ |
1780 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ | |
b34976b6 | 1781 | FALSE, /* partial_inplace */ |
d006db6c | 1782 | 0, /* src_mask */ |
ad8e1ba5 | 1783 | 0xfffc, /* dst_mask */ |
b34976b6 | 1784 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1785 | |
411e1bfb AM |
1786 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
1787 | HOWTO (R_PPC64_GOT_TPREL16_HI, | |
1788 | 16, /* rightshift */ | |
5bd4f169 AM |
1789 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1790 | 16, /* bitsize */ | |
b34976b6 | 1791 | FALSE, /* pc_relative */ |
5bd4f169 | 1792 | 0, /* bitpos */ |
411e1bfb | 1793 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1794 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1795 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
b34976b6 | 1796 | FALSE, /* partial_inplace */ |
d006db6c | 1797 | 0, /* src_mask */ |
411e1bfb | 1798 | 0xffff, /* dst_mask */ |
b34976b6 | 1799 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1800 | |
411e1bfb AM |
1801 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
1802 | HOWTO (R_PPC64_GOT_TPREL16_HA, | |
1803 | 16, /* rightshift */ | |
5bd4f169 AM |
1804 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1805 | 16, /* bitsize */ | |
b34976b6 | 1806 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1807 | 0, /* bitpos */ |
1808 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1809 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1810 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
b34976b6 | 1811 | FALSE, /* partial_inplace */ |
d006db6c | 1812 | 0, /* src_mask */ |
411e1bfb | 1813 | 0xffff, /* dst_mask */ |
b34976b6 | 1814 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1815 | |
1816 | /* GNU extension to record C++ vtable hierarchy. */ | |
1817 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1818 | 0, /* rightshift */ | |
1819 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1820 | 0, /* bitsize */ | |
b34976b6 | 1821 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1822 | 0, /* bitpos */ |
1823 | complain_overflow_dont, /* complain_on_overflow */ | |
1824 | NULL, /* special_function */ | |
1825 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1826 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1827 | 0, /* src_mask */ |
1828 | 0, /* dst_mask */ | |
b34976b6 | 1829 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1830 | |
1831 | /* GNU extension to record C++ vtable member usage. */ | |
1832 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1833 | 0, /* rightshift */ | |
1834 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1835 | 0, /* bitsize */ | |
b34976b6 | 1836 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1837 | 0, /* bitpos */ |
1838 | complain_overflow_dont, /* complain_on_overflow */ | |
1839 | NULL, /* special_function */ | |
1840 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1841 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1842 | 0, /* src_mask */ |
1843 | 0, /* dst_mask */ | |
b34976b6 | 1844 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1845 | }; |
1846 | ||
1847 | \f | |
1848 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1849 | be done. */ | |
1850 | ||
1851 | static void | |
4ce794b7 | 1852 | ppc_howto_init (void) |
5bd4f169 AM |
1853 | { |
1854 | unsigned int i, type; | |
1855 | ||
1856 | for (i = 0; | |
1857 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1858 | i++) | |
1859 | { | |
1860 | type = ppc64_elf_howto_raw[i].type; | |
1861 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1862 | / sizeof (ppc64_elf_howto_table[0]))); | |
1863 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1864 | } | |
1865 | } | |
1866 | ||
1867 | static reloc_howto_type * | |
4ce794b7 AM |
1868 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1869 | bfd_reloc_code_real_type code) | |
5bd4f169 | 1870 | { |
411e1bfb | 1871 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
5bd4f169 AM |
1872 | |
1873 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1874 | /* Initialize howto table if needed. */ | |
1875 | ppc_howto_init (); | |
1876 | ||
4ce794b7 | 1877 | switch (code) |
5bd4f169 AM |
1878 | { |
1879 | default: | |
4ce794b7 | 1880 | return NULL; |
5bd4f169 | 1881 | |
411e1bfb AM |
1882 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
1883 | break; | |
1884 | case BFD_RELOC_32: r = R_PPC64_ADDR32; | |
1885 | break; | |
1886 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; | |
1887 | break; | |
1888 | case BFD_RELOC_16: r = R_PPC64_ADDR16; | |
1889 | break; | |
1890 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; | |
1891 | break; | |
1892 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; | |
1893 | break; | |
1894 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; | |
5bd4f169 | 1895 | break; |
411e1bfb | 1896 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
5bd4f169 | 1897 | break; |
411e1bfb | 1898 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
5bd4f169 | 1899 | break; |
411e1bfb | 1900 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
5bd4f169 | 1901 | break; |
411e1bfb | 1902 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
5bd4f169 | 1903 | break; |
411e1bfb | 1904 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
5bd4f169 | 1905 | break; |
411e1bfb | 1906 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
5bd4f169 | 1907 | break; |
411e1bfb | 1908 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
5bd4f169 | 1909 | break; |
411e1bfb | 1910 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
5bd4f169 | 1911 | break; |
411e1bfb | 1912 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
5bd4f169 | 1913 | break; |
411e1bfb | 1914 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
5bd4f169 | 1915 | break; |
411e1bfb | 1916 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
5bd4f169 | 1917 | break; |
411e1bfb | 1918 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
5bd4f169 | 1919 | break; |
411e1bfb | 1920 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
5bd4f169 | 1921 | break; |
411e1bfb | 1922 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
5bd4f169 | 1923 | break; |
411e1bfb | 1924 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
5bd4f169 | 1925 | break; |
411e1bfb | 1926 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
5bd4f169 | 1927 | break; |
411e1bfb | 1928 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
5bd4f169 | 1929 | break; |
411e1bfb | 1930 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
5bd4f169 | 1931 | break; |
411e1bfb | 1932 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
5bd4f169 | 1933 | break; |
411e1bfb | 1934 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
5bd4f169 | 1935 | break; |
411e1bfb | 1936 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
5bd4f169 | 1937 | break; |
411e1bfb | 1938 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
5bd4f169 | 1939 | break; |
411e1bfb | 1940 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
5bd4f169 | 1941 | break; |
411e1bfb | 1942 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
5bd4f169 | 1943 | break; |
411e1bfb | 1944 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
5bd4f169 | 1945 | break; |
411e1bfb | 1946 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
5bd4f169 | 1947 | break; |
411e1bfb | 1948 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
5bd4f169 | 1949 | break; |
411e1bfb | 1950 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
5bd4f169 | 1951 | break; |
411e1bfb | 1952 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
5bd4f169 | 1953 | break; |
411e1bfb | 1954 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
5bd4f169 | 1955 | break; |
411e1bfb | 1956 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
5bd4f169 | 1957 | break; |
411e1bfb | 1958 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
5bd4f169 | 1959 | break; |
411e1bfb | 1960 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
5bd4f169 | 1961 | break; |
411e1bfb | 1962 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
5bd4f169 | 1963 | break; |
411e1bfb | 1964 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
5bd4f169 | 1965 | break; |
411e1bfb | 1966 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
5bd4f169 | 1967 | break; |
411e1bfb | 1968 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
5bd4f169 | 1969 | break; |
411e1bfb | 1970 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
5bd4f169 | 1971 | break; |
411e1bfb | 1972 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
5bd4f169 | 1973 | break; |
411e1bfb | 1974 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
5bd4f169 | 1975 | break; |
411e1bfb | 1976 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
5bd4f169 | 1977 | break; |
411e1bfb | 1978 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
5bd4f169 | 1979 | break; |
411e1bfb | 1980 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
5bd4f169 | 1981 | break; |
411e1bfb | 1982 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
5bd4f169 | 1983 | break; |
411e1bfb | 1984 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
5bd4f169 | 1985 | break; |
411e1bfb | 1986 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
5bd4f169 | 1987 | break; |
411e1bfb | 1988 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
5bd4f169 | 1989 | break; |
411e1bfb | 1990 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
5bd4f169 | 1991 | break; |
411e1bfb | 1992 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
5bd4f169 | 1993 | break; |
411e1bfb | 1994 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
5bd4f169 | 1995 | break; |
411e1bfb | 1996 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
5bd4f169 | 1997 | break; |
411e1bfb | 1998 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
5bd4f169 | 1999 | break; |
411e1bfb | 2000 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
5bd4f169 | 2001 | break; |
411e1bfb | 2002 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
5bd4f169 | 2003 | break; |
411e1bfb | 2004 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
5bd4f169 | 2005 | break; |
411e1bfb | 2006 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
5bd4f169 | 2007 | break; |
411e1bfb | 2008 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
5bd4f169 | 2009 | break; |
411e1bfb | 2010 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
5bd4f169 | 2011 | break; |
411e1bfb | 2012 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
5bd4f169 | 2013 | break; |
411e1bfb AM |
2014 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
2015 | break; | |
2016 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; | |
2017 | break; | |
2018 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; | |
2019 | break; | |
2020 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; | |
2021 | break; | |
2022 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; | |
2023 | break; | |
2024 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; | |
2025 | break; | |
2026 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; | |
2027 | break; | |
2028 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; | |
2029 | break; | |
2030 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; | |
2031 | break; | |
2032 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; | |
2033 | break; | |
2034 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; | |
2035 | break; | |
2036 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; | |
2037 | break; | |
2038 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; | |
2039 | break; | |
2040 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; | |
2041 | break; | |
2042 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; | |
2043 | break; | |
2044 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; | |
2045 | break; | |
2046 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; | |
2047 | break; | |
2048 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; | |
2049 | break; | |
2050 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; | |
2051 | break; | |
2052 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; | |
2053 | break; | |
2054 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; | |
2055 | break; | |
2056 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; | |
2057 | break; | |
2058 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; | |
2059 | break; | |
2060 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; | |
2061 | break; | |
2062 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; | |
2063 | break; | |
2064 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; | |
2065 | break; | |
2066 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; | |
2067 | break; | |
2068 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; | |
2069 | break; | |
2070 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; | |
2071 | break; | |
2072 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; | |
2073 | break; | |
2074 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; | |
2075 | break; | |
2076 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; | |
2077 | break; | |
2078 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; | |
2079 | break; | |
2080 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; | |
2081 | break; | |
2082 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; | |
5bd4f169 AM |
2083 | break; |
2084 | } | |
2085 | ||
4ce794b7 | 2086 | return ppc64_elf_howto_table[r]; |
5bd4f169 AM |
2087 | }; |
2088 | ||
2089 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
2090 | ||
2091 | static void | |
4ce794b7 AM |
2092 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
2093 | Elf_Internal_Rela *dst) | |
5bd4f169 | 2094 | { |
65f38f15 AM |
2095 | unsigned int type; |
2096 | ||
ef60b7ff | 2097 | /* Initialize howto table if needed. */ |
5bd4f169 | 2098 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
2099 | ppc_howto_init (); |
2100 | ||
65f38f15 AM |
2101 | type = ELF64_R_TYPE (dst->r_info); |
2102 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
2103 | / sizeof (ppc64_elf_howto_table[0]))); | |
2104 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
2105 | } |
2106 | ||
04c9666a | 2107 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
2108 | |
2109 | static bfd_reloc_status_type | |
4ce794b7 AM |
2110 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2111 | void *data, asection *input_section, | |
2112 | bfd *output_bfd, char **error_message) | |
5bd4f169 | 2113 | { |
805fc799 AM |
2114 | /* If this is a relocatable link (output_bfd test tells us), just |
2115 | call the generic function. Any adjustment will be done at final | |
2116 | link time. */ | |
2117 | if (output_bfd != NULL) | |
cedb70c5 | 2118 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2119 | input_section, output_bfd, error_message); |
2120 | ||
2121 | /* Adjust the addend for sign extension of the low 16 bits. | |
2122 | We won't actually be using the low 16 bits, so trashing them | |
2123 | doesn't matter. */ | |
2124 | reloc_entry->addend += 0x8000; | |
2125 | return bfd_reloc_continue; | |
2126 | } | |
5bd4f169 | 2127 | |
805fc799 | 2128 | static bfd_reloc_status_type |
4ce794b7 AM |
2129 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2130 | void *data, asection *input_section, | |
2131 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2132 | { |
2133 | long insn; | |
04c9666a | 2134 | enum elf_ppc64_reloc_type r_type; |
805fc799 AM |
2135 | bfd_size_type octets; |
2136 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 2137 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
2138 | |
2139 | /* If this is a relocatable link (output_bfd test tells us), just | |
2140 | call the generic function. Any adjustment will be done at final | |
2141 | link time. */ | |
5bd4f169 | 2142 | if (output_bfd != NULL) |
cedb70c5 | 2143 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2144 | input_section, output_bfd, error_message); |
2145 | ||
2146 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2147 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2148 | insn &= ~(0x01 << 21); | |
4ce794b7 | 2149 | r_type = reloc_entry->howto->type; |
805fc799 AM |
2150 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
2151 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 2152 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
2153 | |
2154 | if (is_power4) | |
5bd4f169 | 2155 | { |
805fc799 AM |
2156 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
2157 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
2158 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
2159 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
2160 | insn |= 0x02 << 21; | |
2161 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
2162 | insn |= 0x08 << 21; | |
2163 | else | |
2164 | return bfd_reloc_continue; | |
5bd4f169 | 2165 | } |
805fc799 AM |
2166 | else |
2167 | { | |
2168 | bfd_vma target = 0; | |
2169 | bfd_vma from; | |
5bd4f169 | 2170 | |
805fc799 AM |
2171 | if (!bfd_is_com_section (symbol->section)) |
2172 | target = symbol->value; | |
2173 | target += symbol->section->output_section->vma; | |
2174 | target += symbol->section->output_offset; | |
2175 | target += reloc_entry->addend; | |
5bd4f169 | 2176 | |
805fc799 AM |
2177 | from = (reloc_entry->address |
2178 | + input_section->output_offset | |
2179 | + input_section->output_section->vma); | |
5bd4f169 | 2180 | |
805fc799 AM |
2181 | /* Invert 'y' bit if not the default. */ |
2182 | if ((bfd_signed_vma) (target - from) < 0) | |
2183 | insn ^= 0x01 << 21; | |
2184 | } | |
4ce794b7 | 2185 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
805fc799 AM |
2186 | return bfd_reloc_continue; |
2187 | } | |
5bd4f169 | 2188 | |
805fc799 | 2189 | static bfd_reloc_status_type |
4ce794b7 AM |
2190 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2191 | void *data, asection *input_section, | |
2192 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2193 | { |
2194 | /* If this is a relocatable link (output_bfd test tells us), just | |
2195 | call the generic function. Any adjustment will be done at final | |
2196 | link time. */ | |
2197 | if (output_bfd != NULL) | |
cedb70c5 | 2198 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 2199 | input_section, output_bfd, error_message); |
5bd4f169 | 2200 | |
805fc799 AM |
2201 | /* Subtract the symbol section base address. */ |
2202 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
2203 | return bfd_reloc_continue; |
2204 | } | |
2205 | ||
805fc799 | 2206 | static bfd_reloc_status_type |
4ce794b7 AM |
2207 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2208 | void *data, asection *input_section, | |
2209 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2210 | { |
2211 | /* If this is a relocatable link (output_bfd test tells us), just | |
2212 | call the generic function. Any adjustment will be done at final | |
2213 | link time. */ | |
2214 | if (output_bfd != NULL) | |
cedb70c5 | 2215 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2216 | input_section, output_bfd, error_message); |
2217 | ||
2218 | /* Subtract the symbol section base address. */ | |
2219 | reloc_entry->addend -= symbol->section->output_section->vma; | |
2220 | ||
2221 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2222 | reloc_entry->addend += 0x8000; | |
2223 | return bfd_reloc_continue; | |
2224 | } | |
2225 | ||
2226 | static bfd_reloc_status_type | |
4ce794b7 AM |
2227 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2228 | void *data, asection *input_section, | |
2229 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2230 | { |
2231 | bfd_vma TOCstart; | |
2232 | ||
2233 | /* If this is a relocatable link (output_bfd test tells us), just | |
2234 | call the generic function. Any adjustment will be done at final | |
2235 | link time. */ | |
2236 | if (output_bfd != NULL) | |
cedb70c5 | 2237 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2238 | input_section, output_bfd, error_message); |
2239 | ||
2240 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2241 | if (TOCstart == 0) | |
2242 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2243 | ||
2244 | /* Subtract the TOC base address. */ | |
2245 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2246 | return bfd_reloc_continue; | |
2247 | } | |
2248 | ||
2249 | static bfd_reloc_status_type | |
4ce794b7 AM |
2250 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2251 | void *data, asection *input_section, | |
2252 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2253 | { |
2254 | bfd_vma TOCstart; | |
2255 | ||
2256 | /* If this is a relocatable link (output_bfd test tells us), just | |
2257 | call the generic function. Any adjustment will be done at final | |
2258 | link time. */ | |
2259 | if (output_bfd != NULL) | |
cedb70c5 | 2260 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2261 | input_section, output_bfd, error_message); |
2262 | ||
2263 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2264 | if (TOCstart == 0) | |
2265 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2266 | ||
2267 | /* Subtract the TOC base address. */ | |
2268 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2269 | ||
2270 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2271 | reloc_entry->addend += 0x8000; | |
2272 | return bfd_reloc_continue; | |
2273 | } | |
2274 | ||
2275 | static bfd_reloc_status_type | |
4ce794b7 AM |
2276 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2277 | void *data, asection *input_section, | |
2278 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2279 | { |
2280 | bfd_vma TOCstart; | |
2281 | bfd_size_type octets; | |
2282 | ||
2283 | /* If this is a relocatable link (output_bfd test tells us), just | |
2284 | call the generic function. Any adjustment will be done at final | |
2285 | link time. */ | |
2286 | if (output_bfd != NULL) | |
cedb70c5 | 2287 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2288 | input_section, output_bfd, error_message); |
2289 | ||
2290 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2291 | if (TOCstart == 0) | |
2292 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2293 | ||
2294 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2295 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
2296 | return bfd_reloc_ok; | |
2297 | } | |
2298 | ||
2299 | static bfd_reloc_status_type | |
4ce794b7 AM |
2300 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2301 | void *data, asection *input_section, | |
2302 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2303 | { |
2304 | /* If this is a relocatable link (output_bfd test tells us), just | |
2305 | call the generic function. Any adjustment will be done at final | |
2306 | link time. */ | |
2307 | if (output_bfd != NULL) | |
cedb70c5 | 2308 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2309 | input_section, output_bfd, error_message); |
2310 | ||
2311 | if (error_message != NULL) | |
2312 | { | |
2313 | static char buf[60]; | |
2314 | sprintf (buf, "generic linker can't handle %s", | |
2315 | reloc_entry->howto->name); | |
2316 | *error_message = buf; | |
2317 | } | |
2318 | return bfd_reloc_dangerous; | |
2319 | } | |
2320 | ||
e717da7e AM |
2321 | struct ppc64_elf_obj_tdata |
2322 | { | |
2323 | struct elf_obj_tdata elf; | |
2324 | ||
2325 | /* Shortcuts to dynamic linker sections. */ | |
2326 | asection *got; | |
2327 | asection *relgot; | |
2328 | ||
2329 | /* TLS local dynamic got entry handling. Suppose for multiple GOT | |
2330 | sections means we potentially need one of these for each input bfd. */ | |
2331 | union { | |
2332 | bfd_signed_vma refcount; | |
2333 | bfd_vma offset; | |
2334 | } tlsld_got; | |
2335 | }; | |
2336 | ||
2337 | #define ppc64_elf_tdata(bfd) \ | |
2338 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) | |
2339 | ||
2340 | #define ppc64_tlsld_got(bfd) \ | |
2341 | (&ppc64_elf_tdata (bfd)->tlsld_got) | |
2342 | ||
2343 | /* Override the generic function because we store some extras. */ | |
2344 | ||
2345 | static bfd_boolean | |
2346 | ppc64_elf_mkobject (bfd *abfd) | |
2347 | { | |
2348 | bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); | |
2349 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2350 | if (abfd->tdata.any == NULL) | |
2351 | return FALSE; | |
2352 | return TRUE; | |
2353 | } | |
2354 | ||
feee612b AM |
2355 | /* Fix bad default arch selected for a 64 bit input bfd when the |
2356 | default is 32 bit. */ | |
2357 | ||
b34976b6 | 2358 | static bfd_boolean |
4ce794b7 | 2359 | ppc64_elf_object_p (bfd *abfd) |
feee612b AM |
2360 | { |
2361 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
2362 | { | |
2363 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2364 | ||
2365 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
2366 | { | |
2367 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
2368 | abfd->arch_info = abfd->arch_info->next; | |
2369 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
2370 | } | |
2371 | } | |
b34976b6 | 2372 | return TRUE; |
feee612b AM |
2373 | } |
2374 | ||
5bd4f169 AM |
2375 | /* Merge backend specific data from an object file to the output |
2376 | object file when linking. */ | |
2f6d9989 | 2377 | |
b34976b6 | 2378 | static bfd_boolean |
4ce794b7 | 2379 | ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
5bd4f169 | 2380 | { |
5bd4f169 AM |
2381 | /* Check if we have the same endianess. */ |
2382 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
87e226ce | 2383 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
5bd4f169 AM |
2384 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
2385 | { | |
2386 | const char *msg; | |
2387 | ||
2388 | if (bfd_big_endian (ibfd)) | |
4ce794b7 AM |
2389 | msg = _("%s: compiled for a big endian system " |
2390 | "and target is little endian"); | |
5bd4f169 | 2391 | else |
4ce794b7 AM |
2392 | msg = _("%s: compiled for a little endian system " |
2393 | "and target is big endian"); | |
5bd4f169 | 2394 | |
8f615d07 | 2395 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
5bd4f169 AM |
2396 | |
2397 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 2398 | return FALSE; |
5bd4f169 AM |
2399 | } |
2400 | ||
b34976b6 | 2401 | return TRUE; |
5bd4f169 | 2402 | } |
f0abc2a1 | 2403 | |
5d35169e AM |
2404 | /* Add extra PPC sections. */ |
2405 | ||
2406 | static struct bfd_elf_special_section const ppc64_elf_special_sections[]= | |
2407 | { | |
2408 | { ".sdata", 0, NULL, 0, | |
2409 | SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2410 | { ".sbss", 0, NULL, 0, | |
2411 | SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2412 | { ".plt", 0, NULL, 0, | |
2413 | SHT_NOBITS, 0 }, | |
2414 | { ".toc", 0, NULL, 0, | |
2415 | SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2416 | { ".toc1", 0, NULL, 0, | |
2417 | SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2418 | { ".tocbss", 0, NULL, 0, | |
2419 | SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2420 | { NULL, 0, NULL, 0, | |
2421 | 0, 0 } | |
2422 | }; | |
2423 | ||
f0abc2a1 AM |
2424 | struct _ppc64_elf_section_data |
2425 | { | |
2426 | struct bfd_elf_section_data elf; | |
411e1bfb AM |
2427 | |
2428 | /* An array with one entry for each opd function descriptor. */ | |
f0abc2a1 AM |
2429 | union |
2430 | { | |
411e1bfb | 2431 | /* Points to the function code section for local opd entries. */ |
f0abc2a1 | 2432 | asection **func_sec; |
411e1bfb | 2433 | /* After editing .opd, adjust references to opd local syms. */ |
f0abc2a1 AM |
2434 | long *adjust; |
2435 | } opd; | |
411e1bfb AM |
2436 | |
2437 | /* An array for toc sections, indexed by offset/8. | |
2438 | Specifies the relocation symbol index used at a given toc offset. */ | |
2439 | unsigned *t_symndx; | |
f0abc2a1 AM |
2440 | }; |
2441 | ||
2442 | #define ppc64_elf_section_data(sec) \ | |
411e1bfb | 2443 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
f0abc2a1 AM |
2444 | |
2445 | static bfd_boolean | |
4ce794b7 | 2446 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
f0abc2a1 AM |
2447 | { |
2448 | struct _ppc64_elf_section_data *sdata; | |
2449 | bfd_size_type amt = sizeof (*sdata); | |
2450 | ||
4ce794b7 | 2451 | sdata = bfd_zalloc (abfd, amt); |
f0abc2a1 AM |
2452 | if (sdata == NULL) |
2453 | return FALSE; | |
4ce794b7 | 2454 | sec->used_by_bfd = sdata; |
f0abc2a1 AM |
2455 | |
2456 | return _bfd_elf_new_section_hook (abfd, sec); | |
2457 | } | |
5bd4f169 | 2458 | \f |
65f38f15 AM |
2459 | /* The following functions are specific to the ELF linker, while |
2460 | functions above are used generally. Those named ppc64_elf_* are | |
2461 | called by the main ELF linker code. They appear in this file more | |
2462 | or less in the order in which they are called. eg. | |
2463 | ppc64_elf_check_relocs is called early in the link process, | |
2464 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
2465 | called. |
2466 | ||
2467 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
2468 | functions have both a function code symbol and a function descriptor | |
2469 | symbol. A call to foo in a relocatable object file looks like: | |
2470 | ||
2471 | . .text | |
2472 | . x: | |
2473 | . bl .foo | |
2474 | . nop | |
2475 | ||
2476 | The function definition in another object file might be: | |
2477 | ||
2478 | . .section .opd | |
2479 | . foo: .quad .foo | |
2480 | . .quad .TOC.@tocbase | |
2481 | . .quad 0 | |
2482 | . | |
2483 | . .text | |
2484 | . .foo: blr | |
2485 | ||
2486 | When the linker resolves the call during a static link, the branch | |
2487 | unsurprisingly just goes to .foo and the .opd information is unused. | |
2488 | If the function definition is in a shared library, things are a little | |
2489 | different: The call goes via a plt call stub, the opd information gets | |
2490 | copied to the plt, and the linker patches the nop. | |
2491 | ||
2492 | . x: | |
2493 | . bl .foo_stub | |
2494 | . ld 2,40(1) | |
2495 | . | |
2496 | . | |
2497 | . .foo_stub: | |
2498 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
411e1bfb | 2499 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
e86ce104 AM |
2500 | . std 2,40(1) # this is the general idea |
2501 | . ld 11,0(12) | |
2502 | . ld 2,8(12) | |
2503 | . mtctr 11 | |
2504 | . ld 11,16(12) | |
2505 | . bctr | |
2506 | . | |
2507 | . .section .plt | |
2508 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
2509 | ||
2510 | The "reloc ()" notation is supposed to indicate that the linker emits | |
2511 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
2512 | copying. | |
2513 | ||
2514 | What are the difficulties here? Well, firstly, the relocations | |
2515 | examined by the linker in check_relocs are against the function code | |
2516 | sym .foo, while the dynamic relocation in the plt is emitted against | |
2517 | the function descriptor symbol, foo. Somewhere along the line, we need | |
2518 | to carefully copy dynamic link information from one symbol to the other. | |
2519 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
2520 | symbol as is normal for most other backends. We need foo dynamic | |
2521 | instead, at least for an application final link. However, when | |
2522 | creating a shared library containing foo, we need to have both symbols | |
2523 | dynamic so that references to .foo are satisfied during the early | |
2524 | stages of linking. Otherwise the linker might decide to pull in a | |
41bd81ab | 2525 | definition from some other object, eg. a static library. */ |
65f38f15 AM |
2526 | |
2527 | /* The linker needs to keep track of the number of relocs that it | |
2528 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2529 | This is so that it can later discard them if they are found to be | |
2530 | unnecessary. We store the information in a field extending the | |
2531 | regular ELF linker hash table. */ | |
2532 | ||
2533 | struct ppc_dyn_relocs | |
2534 | { | |
2535 | struct ppc_dyn_relocs *next; | |
2536 | ||
2537 | /* The input section of the reloc. */ | |
2538 | asection *sec; | |
2539 | ||
2540 | /* Total number of relocs copied for the input section. */ | |
2541 | bfd_size_type count; | |
2542 | ||
2543 | /* Number of pc-relative relocs copied for the input section. */ | |
2544 | bfd_size_type pc_count; | |
2545 | }; | |
2546 | ||
411e1bfb AM |
2547 | /* Track GOT entries needed for a given symbol. We might need more |
2548 | than one got entry per symbol. */ | |
2549 | struct got_entry | |
2550 | { | |
2551 | struct got_entry *next; | |
2552 | ||
e7b938ca | 2553 | /* The symbol addend that we'll be placing in the GOT. */ |
411e1bfb AM |
2554 | bfd_vma addend; |
2555 | ||
e717da7e AM |
2556 | /* Unlike other ELF targets, we use separate GOT entries for the same |
2557 | symbol referenced from different input files. This is to support | |
2558 | automatic multiple TOC/GOT sections, where the TOC base can vary | |
2559 | from one input file to another. | |
2560 | ||
2561 | Point to the BFD owning this GOT entry. */ | |
2562 | bfd *owner; | |
2563 | ||
2564 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, | |
2565 | TLS_TPREL or TLS_DTPREL for tls entries. */ | |
2566 | char tls_type; | |
2567 | ||
e7b938ca | 2568 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ |
411e1bfb AM |
2569 | union |
2570 | { | |
2571 | bfd_signed_vma refcount; | |
2572 | bfd_vma offset; | |
2573 | } got; | |
411e1bfb AM |
2574 | }; |
2575 | ||
2576 | /* The same for PLT. */ | |
2577 | struct plt_entry | |
2578 | { | |
2579 | struct plt_entry *next; | |
2580 | ||
2581 | bfd_vma addend; | |
2582 | ||
2583 | union | |
2584 | { | |
2585 | bfd_signed_vma refcount; | |
2586 | bfd_vma offset; | |
2587 | } plt; | |
2588 | }; | |
2589 | ||
65f38f15 | 2590 | /* Of those relocs that might be copied as dynamic relocs, this macro |
58ac9f71 AM |
2591 | selects those that must be copied when linking a shared library, |
2592 | even when the symbol is local. */ | |
65f38f15 | 2593 | |
411e1bfb | 2594 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
805fc799 AM |
2595 | ((RTYPE) != R_PPC64_REL32 \ |
2596 | && (RTYPE) != R_PPC64_REL64 \ | |
04c9666a | 2597 | && (RTYPE) != R_PPC64_REL30) |
65f38f15 | 2598 | |
f4656909 AM |
2599 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2600 | copying dynamic variables from a shared lib into an app's dynbss | |
2601 | section, and instead use a dynamic relocation to point into the | |
5d35169e AM |
2602 | shared lib. With code that gcc generates, it's vital that this be |
2603 | enabled; In the PowerPC64 ABI, the address of a function is actually | |
2604 | the address of a function descriptor, which resides in the .opd | |
2605 | section. gcc uses the descriptor directly rather than going via the | |
2606 | GOT as some other ABI's do, which means that initialized function | |
2607 | pointers must reference the descriptor. Thus, a function pointer | |
2608 | initialized to the address of a function in a shared library will | |
2609 | either require a copy reloc, or a dynamic reloc. Using a copy reloc | |
2610 | redefines the function desctriptor symbol to point to the copy. This | |
2611 | presents a problem as a plt entry for that function is also | |
2612 | initialized from the function descriptor symbol and the copy reloc | |
2613 | may not be initialized first. */ | |
a23b6845 | 2614 | #define ELIMINATE_COPY_RELOCS 1 |
f4656909 | 2615 | |
721956f4 AM |
2616 | /* Section name for stubs is the associated section name plus this |
2617 | string. */ | |
2618 | #define STUB_SUFFIX ".stub" | |
2619 | ||
2620 | /* Linker stubs. | |
2621 | ppc_stub_long_branch: | |
2622 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
2623 | destination, but a 24 bit branch in a stub section will reach. | |
2624 | . b dest | |
2625 | ||
2626 | ppc_stub_plt_branch: | |
2627 | Similar to the above, but a 24 bit branch in the stub section won't | |
2628 | reach its destination. | |
87e226ce AM |
2629 | . addis %r12,%r2,xxx@toc@ha |
2630 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
2631 | . mtctr %r11 |
2632 | . bctr | |
2633 | ||
2634 | ppc_stub_plt_call: | |
2635 | Used to call a function in a shared library. | |
87e226ce | 2636 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 2637 | . std %r2,40(%r1) |
87e226ce AM |
2638 | . ld %r11,xxx+0@toc@l(%r12) |
2639 | . ld %r2,xxx+8@toc@l(%r12) | |
721956f4 | 2640 | . mtctr %r11 |
87e226ce | 2641 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 | 2642 | . bctr |
ad8e1ba5 AM |
2643 | |
2644 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional | |
2645 | code to adjust the value and save r2 to support multiple toc sections. | |
2646 | A ppc_stub_long_branch with an r2 offset looks like: | |
2647 | . std %r2,40(%r1) | |
2648 | . addis %r2,%r2,off@ha | |
2649 | . addi %r2,%r2,off@l | |
2650 | . b dest | |
2651 | ||
2652 | A ppc_stub_plt_branch with an r2 offset looks like: | |
2653 | . std %r2,40(%r1) | |
2654 | . addis %r12,%r2,xxx@toc@ha | |
2655 | . ld %r11,xxx@toc@l(%r12) | |
2656 | . addis %r2,%r2,off@ha | |
2657 | . addi %r2,%r2,off@l | |
2658 | . mtctr %r11 | |
2659 | . bctr | |
721956f4 AM |
2660 | */ |
2661 | ||
2662 | enum ppc_stub_type { | |
2663 | ppc_stub_none, | |
2664 | ppc_stub_long_branch, | |
ad8e1ba5 | 2665 | ppc_stub_long_branch_r2off, |
721956f4 | 2666 | ppc_stub_plt_branch, |
ad8e1ba5 | 2667 | ppc_stub_plt_branch_r2off, |
721956f4 AM |
2668 | ppc_stub_plt_call |
2669 | }; | |
2670 | ||
2671 | struct ppc_stub_hash_entry { | |
2672 | ||
2673 | /* Base hash table entry structure. */ | |
2674 | struct bfd_hash_entry root; | |
2675 | ||
ad8e1ba5 AM |
2676 | enum ppc_stub_type stub_type; |
2677 | ||
721956f4 AM |
2678 | /* The stub section. */ |
2679 | asection *stub_sec; | |
2680 | ||
2681 | /* Offset within stub_sec of the beginning of this stub. */ | |
2682 | bfd_vma stub_offset; | |
2683 | ||
2684 | /* Given the symbol's value and its section we can determine its final | |
2685 | value when building the stubs (so the stub knows where to jump. */ | |
2686 | bfd_vma target_value; | |
2687 | asection *target_section; | |
2688 | ||
721956f4 AM |
2689 | /* The symbol table entry, if any, that this was derived from. */ |
2690 | struct ppc_link_hash_entry *h; | |
2691 | ||
411e1bfb AM |
2692 | /* And the reloc addend that this was derived from. */ |
2693 | bfd_vma addend; | |
2694 | ||
721956f4 AM |
2695 | /* Where this stub is being called from, or, in the case of combined |
2696 | stub sections, the first input section in the group. */ | |
2697 | asection *id_sec; | |
2698 | }; | |
2699 | ||
2700 | struct ppc_branch_hash_entry { | |
2701 | ||
2702 | /* Base hash table entry structure. */ | |
2703 | struct bfd_hash_entry root; | |
2704 | ||
2705 | /* Offset within .branch_lt. */ | |
2706 | unsigned int offset; | |
2707 | ||
2708 | /* Generation marker. */ | |
2709 | unsigned int iter; | |
2710 | }; | |
65f38f15 AM |
2711 | |
2712 | struct ppc_link_hash_entry | |
2713 | { | |
2714 | struct elf_link_hash_entry elf; | |
2715 | ||
721956f4 AM |
2716 | /* A pointer to the most recently used stub hash entry against this |
2717 | symbol. */ | |
2718 | struct ppc_stub_hash_entry *stub_cache; | |
2719 | ||
65f38f15 AM |
2720 | /* Track dynamic relocs copied for this symbol. */ |
2721 | struct ppc_dyn_relocs *dyn_relocs; | |
e86ce104 | 2722 | |
721956f4 AM |
2723 | /* Link between function code and descriptor symbols. */ |
2724 | struct elf_link_hash_entry *oh; | |
2725 | ||
e86ce104 AM |
2726 | /* Flag function code and descriptor symbols. */ |
2727 | unsigned int is_func:1; | |
2728 | unsigned int is_func_descriptor:1; | |
1e2f5b6e | 2729 | unsigned int is_entry:1; |
411e1bfb AM |
2730 | |
2731 | /* Contexts in which symbol is used in the GOT (or TOC). | |
e7b938ca AM |
2732 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
2733 | corresponding relocs are encountered during check_relocs. | |
2734 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2735 | indicate the corresponding GOT entry type is not needed. | |
2736 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into | |
2737 | a TPREL one. We use a separate flag rather than setting TPREL | |
2738 | just for convenience in distinguishing the two cases. */ | |
2739 | #define TLS_GD 1 /* GD reloc. */ | |
2740 | #define TLS_LD 2 /* LD reloc. */ | |
2741 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2742 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2743 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2744 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ | |
2745 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ | |
2746 | char tls_mask; | |
65f38f15 AM |
2747 | }; |
2748 | ||
2749 | /* ppc64 ELF linker hash table. */ | |
2750 | ||
2751 | struct ppc_link_hash_table | |
2752 | { | |
2753 | struct elf_link_hash_table elf; | |
2754 | ||
721956f4 AM |
2755 | /* The stub hash table. */ |
2756 | struct bfd_hash_table stub_hash_table; | |
2757 | ||
2758 | /* Another hash table for plt_branch stubs. */ | |
2759 | struct bfd_hash_table branch_hash_table; | |
2760 | ||
2761 | /* Linker stub bfd. */ | |
2762 | bfd *stub_bfd; | |
2763 | ||
2764 | /* Linker call-backs. */ | |
4ce794b7 AM |
2765 | asection * (*add_stub_section) (const char *, asection *); |
2766 | void (*layout_sections_again) (void); | |
721956f4 AM |
2767 | |
2768 | /* Array to keep track of which stub sections have been created, and | |
2769 | information on stub grouping. */ | |
2770 | struct map_stub { | |
2771 | /* This is the section to which stubs in the group will be attached. */ | |
2772 | asection *link_sec; | |
2773 | /* The stub section. */ | |
2774 | asection *stub_sec; | |
ad8e1ba5 AM |
2775 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
2776 | bfd_vma toc_off; | |
721956f4 AM |
2777 | } *stub_group; |
2778 | ||
ad8e1ba5 AM |
2779 | /* Support for multiple toc sections. */ |
2780 | unsigned int no_multi_toc; | |
2781 | unsigned int multi_toc_needed; | |
2782 | ||
2783 | /* Temp used when calculating TOC pointers. */ | |
2784 | bfd_vma toc_curr; | |
2785 | ||
8f3bab57 AM |
2786 | /* Highest input section id. */ |
2787 | int top_id; | |
2788 | ||
734b6cf9 AM |
2789 | /* Highest output section index. */ |
2790 | int top_index; | |
2791 | ||
2792 | /* List of input sections for each output section. */ | |
2793 | asection **input_list; | |
721956f4 | 2794 | |
65f38f15 | 2795 | /* Short-cuts to get to dynamic linker sections. */ |
4ce794b7 | 2796 | asection *got; |
4ce794b7 AM |
2797 | asection *plt; |
2798 | asection *relplt; | |
2799 | asection *dynbss; | |
2800 | asection *relbss; | |
2801 | asection *glink; | |
82bd7b59 | 2802 | asection *sfpr; |
4ce794b7 AM |
2803 | asection *brlt; |
2804 | asection *relbrlt; | |
ec338859 | 2805 | |
411e1bfb AM |
2806 | /* Short-cut to first output tls section. */ |
2807 | asection *tls_sec; | |
2808 | ||
2809 | /* Shortcut to .__tls_get_addr. */ | |
2810 | struct elf_link_hash_entry *tls_get_addr; | |
2811 | ||
9b5ecbd0 AM |
2812 | /* Statistics. */ |
2813 | unsigned long stub_count[ppc_stub_plt_call]; | |
2814 | ||
ad8e1ba5 AM |
2815 | /* Set if we should emit symbols for stubs. */ |
2816 | unsigned int emit_stub_syms; | |
2817 | ||
5d1634d7 | 2818 | /* Set on error. */ |
721956f4 AM |
2819 | unsigned int stub_error; |
2820 | ||
2821 | /* Flag set when small branches are detected. Used to | |
2822 | select suitable defaults for the stub group size. */ | |
2823 | unsigned int has_14bit_branch; | |
2824 | ||
805fc799 AM |
2825 | /* Set if we detect a reference undefined weak symbol. */ |
2826 | unsigned int have_undefweak; | |
2827 | ||
721956f4 AM |
2828 | /* Incremented every time we size stubs. */ |
2829 | unsigned int stub_iteration; | |
5d1634d7 | 2830 | |
ec338859 AM |
2831 | /* Small local sym to section mapping cache. */ |
2832 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
2833 | }; |
2834 | ||
2835 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ | |
2836 | ||
2837 | #define ppc_hash_table(p) \ | |
2838 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
2839 | ||
721956f4 AM |
2840 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
2841 | ((struct ppc_stub_hash_entry *) \ | |
2842 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2843 | ||
2844 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
2845 | ((struct ppc_branch_hash_entry *) \ | |
2846 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2847 | ||
2848 | /* Create an entry in the stub hash table. */ | |
2849 | ||
2850 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2851 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2852 | struct bfd_hash_table *table, | |
2853 | const char *string) | |
721956f4 AM |
2854 | { |
2855 | /* Allocate the structure if it has not already been allocated by a | |
2856 | subclass. */ | |
2857 | if (entry == NULL) | |
2858 | { | |
2859 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
2860 | if (entry == NULL) | |
2861 | return entry; | |
2862 | } | |
2863 | ||
2864 | /* Call the allocation method of the superclass. */ | |
2865 | entry = bfd_hash_newfunc (entry, table, string); | |
2866 | if (entry != NULL) | |
2867 | { | |
2868 | struct ppc_stub_hash_entry *eh; | |
2869 | ||
2870 | /* Initialize the local fields. */ | |
2871 | eh = (struct ppc_stub_hash_entry *) entry; | |
ad8e1ba5 | 2872 | eh->stub_type = ppc_stub_none; |
721956f4 AM |
2873 | eh->stub_sec = NULL; |
2874 | eh->stub_offset = 0; | |
2875 | eh->target_value = 0; | |
2876 | eh->target_section = NULL; | |
721956f4 AM |
2877 | eh->h = NULL; |
2878 | eh->id_sec = NULL; | |
2879 | } | |
2880 | ||
2881 | return entry; | |
2882 | } | |
2883 | ||
2884 | /* Create an entry in the branch hash table. */ | |
2885 | ||
2886 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2887 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
2888 | struct bfd_hash_table *table, | |
2889 | const char *string) | |
721956f4 AM |
2890 | { |
2891 | /* Allocate the structure if it has not already been allocated by a | |
2892 | subclass. */ | |
2893 | if (entry == NULL) | |
2894 | { | |
2895 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); | |
2896 | if (entry == NULL) | |
2897 | return entry; | |
2898 | } | |
2899 | ||
2900 | /* Call the allocation method of the superclass. */ | |
2901 | entry = bfd_hash_newfunc (entry, table, string); | |
2902 | if (entry != NULL) | |
2903 | { | |
2904 | struct ppc_branch_hash_entry *eh; | |
2905 | ||
2906 | /* Initialize the local fields. */ | |
2907 | eh = (struct ppc_branch_hash_entry *) entry; | |
2908 | eh->offset = 0; | |
2909 | eh->iter = 0; | |
2910 | } | |
2911 | ||
2912 | return entry; | |
2913 | } | |
2914 | ||
65f38f15 AM |
2915 | /* Create an entry in a ppc64 ELF linker hash table. */ |
2916 | ||
2917 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2918 | link_hash_newfunc (struct bfd_hash_entry *entry, |
2919 | struct bfd_hash_table *table, | |
2920 | const char *string) | |
65f38f15 AM |
2921 | { |
2922 | /* Allocate the structure if it has not already been allocated by a | |
2923 | subclass. */ | |
2924 | if (entry == NULL) | |
2925 | { | |
2926 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
2927 | if (entry == NULL) | |
2928 | return entry; | |
2929 | } | |
2930 | ||
2931 | /* Call the allocation method of the superclass. */ | |
2932 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2933 | if (entry != NULL) | |
2934 | { | |
2935 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
2936 | ||
721956f4 | 2937 | eh->stub_cache = NULL; |
65f38f15 | 2938 | eh->dyn_relocs = NULL; |
721956f4 | 2939 | eh->oh = NULL; |
e86ce104 AM |
2940 | eh->is_func = 0; |
2941 | eh->is_func_descriptor = 0; | |
1e2f5b6e | 2942 | eh->is_entry = 0; |
e7b938ca | 2943 | eh->tls_mask = 0; |
65f38f15 AM |
2944 | } |
2945 | ||
2946 | return entry; | |
2947 | } | |
2948 | ||
2949 | /* Create a ppc64 ELF linker hash table. */ | |
2950 | ||
2951 | static struct bfd_link_hash_table * | |
4ce794b7 | 2952 | ppc64_elf_link_hash_table_create (bfd *abfd) |
65f38f15 AM |
2953 | { |
2954 | struct ppc_link_hash_table *htab; | |
2955 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
2956 | ||
4ce794b7 | 2957 | htab = bfd_zmalloc (amt); |
65f38f15 AM |
2958 | if (htab == NULL) |
2959 | return NULL; | |
2960 | ||
2961 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
2962 | { | |
e2d34d7d | 2963 | free (htab); |
65f38f15 AM |
2964 | return NULL; |
2965 | } | |
2966 | ||
721956f4 AM |
2967 | /* Init the stub hash table too. */ |
2968 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) | |
2969 | return NULL; | |
2970 | ||
2971 | /* And the branch hash table. */ | |
2972 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) | |
2973 | return NULL; | |
2974 | ||
3254fd24 AM |
2975 | /* Initializing two fields of the union is just cosmetic. We really |
2976 | only care about glist, but when compiled on a 32-bit host the | |
2977 | bfd_vma fields are larger. Setting the bfd_vma to zero makes | |
2978 | debugger inspection of these fields look nicer. */ | |
2979 | htab->elf.init_refcount.refcount = 0; | |
2980 | htab->elf.init_refcount.glist = NULL; | |
2981 | htab->elf.init_offset.offset = 0; | |
2982 | htab->elf.init_offset.glist = NULL; | |
2983 | ||
65f38f15 AM |
2984 | return &htab->elf.root; |
2985 | } | |
2986 | ||
721956f4 AM |
2987 | /* Free the derived linker hash table. */ |
2988 | ||
2989 | static void | |
4ce794b7 | 2990 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
721956f4 AM |
2991 | { |
2992 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
2993 | ||
2994 | bfd_hash_table_free (&ret->stub_hash_table); | |
2995 | bfd_hash_table_free (&ret->branch_hash_table); | |
2996 | _bfd_generic_link_hash_table_free (hash); | |
2997 | } | |
2998 | ||
e717da7e AM |
2999 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
3000 | ||
3001 | void | |
3002 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
3003 | { | |
3004 | struct ppc_link_hash_table *htab; | |
3005 | ||
3006 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; | |
3007 | ||
3008 | /* Always hook our dynamic sections into the first bfd, which is the | |
3009 | linker created stub bfd. This ensures that the GOT header is at | |
3010 | the start of the output TOC section. */ | |
3011 | htab = ppc_hash_table (info); | |
3012 | htab->stub_bfd = abfd; | |
3013 | htab->elf.dynobj = abfd; | |
3014 | } | |
3015 | ||
721956f4 AM |
3016 | /* Build a name for an entry in the stub hash table. */ |
3017 | ||
3018 | static char * | |
4ce794b7 AM |
3019 | ppc_stub_name (const asection *input_section, |
3020 | const asection *sym_sec, | |
3021 | const struct ppc_link_hash_entry *h, | |
3022 | const Elf_Internal_Rela *rel) | |
721956f4 AM |
3023 | { |
3024 | char *stub_name; | |
3025 | bfd_size_type len; | |
3026 | ||
3027 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
3028 | offsets from a sym as a branch target? In fact, we could | |
3029 | probably assume the addend is always zero. */ | |
3030 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
3031 | ||
3032 | if (h) | |
3033 | { | |
3034 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
3035 | stub_name = bfd_malloc (len); | |
3036 | if (stub_name != NULL) | |
3037 | { | |
97b639ba | 3038 | sprintf (stub_name, "%08x.%s+%x", |
721956f4 AM |
3039 | input_section->id & 0xffffffff, |
3040 | h->elf.root.root.string, | |
3041 | (int) rel->r_addend & 0xffffffff); | |
3042 | } | |
3043 | } | |
3044 | else | |
3045 | { | |
ad8e1ba5 | 3046 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
721956f4 AM |
3047 | stub_name = bfd_malloc (len); |
3048 | if (stub_name != NULL) | |
3049 | { | |
97b639ba | 3050 | sprintf (stub_name, "%08x.%x:%x+%x", |
721956f4 AM |
3051 | input_section->id & 0xffffffff, |
3052 | sym_sec->id & 0xffffffff, | |
3053 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
3054 | (int) rel->r_addend & 0xffffffff); | |
3055 | } | |
3056 | } | |
3057 | return stub_name; | |
3058 | } | |
3059 | ||
3060 | /* Look up an entry in the stub hash. Stub entries are cached because | |
3061 | creating the stub name takes a bit of time. */ | |
3062 | ||
3063 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3064 | ppc_get_stub_entry (const asection *input_section, |
3065 | const asection *sym_sec, | |
3066 | struct elf_link_hash_entry *hash, | |
3067 | const Elf_Internal_Rela *rel, | |
3068 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3069 | { |
3070 | struct ppc_stub_hash_entry *stub_entry; | |
3071 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; | |
3072 | const asection *id_sec; | |
3073 | ||
3074 | /* If this input section is part of a group of sections sharing one | |
3075 | stub section, then use the id of the first section in the group. | |
3076 | Stub names need to include a section id, as there may well be | |
3077 | more than one stub used to reach say, printf, and we need to | |
3078 | distinguish between them. */ | |
3079 | id_sec = htab->stub_group[input_section->id].link_sec; | |
3080 | ||
3081 | if (h != NULL && h->stub_cache != NULL | |
3082 | && h->stub_cache->h == h | |
3083 | && h->stub_cache->id_sec == id_sec) | |
3084 | { | |
3085 | stub_entry = h->stub_cache; | |
3086 | } | |
3087 | else | |
3088 | { | |
3089 | char *stub_name; | |
3090 | ||
3091 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
3092 | if (stub_name == NULL) | |
3093 | return NULL; | |
3094 | ||
3095 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 3096 | stub_name, FALSE, FALSE); |
721956f4 AM |
3097 | if (h != NULL) |
3098 | h->stub_cache = stub_entry; | |
3099 | ||
3100 | free (stub_name); | |
3101 | } | |
3102 | ||
3103 | return stub_entry; | |
3104 | } | |
3105 | ||
3106 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
3107 | stub entry are initialised. */ | |
3108 | ||
3109 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3110 | ppc_add_stub (const char *stub_name, |
3111 | asection *section, | |
3112 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3113 | { |
3114 | asection *link_sec; | |
3115 | asection *stub_sec; | |
3116 | struct ppc_stub_hash_entry *stub_entry; | |
3117 | ||
3118 | link_sec = htab->stub_group[section->id].link_sec; | |
3119 | stub_sec = htab->stub_group[section->id].stub_sec; | |
3120 | if (stub_sec == NULL) | |
3121 | { | |
3122 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
3123 | if (stub_sec == NULL) | |
3124 | { | |
d4c88bbb | 3125 | size_t namelen; |
721956f4 AM |
3126 | bfd_size_type len; |
3127 | char *s_name; | |
3128 | ||
d4c88bbb AM |
3129 | namelen = strlen (link_sec->name); |
3130 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
3131 | s_name = bfd_alloc (htab->stub_bfd, len); |
3132 | if (s_name == NULL) | |
3133 | return NULL; | |
3134 | ||
d4c88bbb AM |
3135 | memcpy (s_name, link_sec->name, namelen); |
3136 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
3137 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
3138 | if (stub_sec == NULL) | |
3139 | return NULL; | |
3140 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
3141 | } | |
3142 | htab->stub_group[section->id].stub_sec = stub_sec; | |
3143 | } | |
3144 | ||
3145 | /* Enter this entry into the linker stub hash table. */ | |
3146 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 3147 | TRUE, FALSE); |
721956f4 AM |
3148 | if (stub_entry == NULL) |
3149 | { | |
3150 | (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), | |
3151 | bfd_archive_filename (section->owner), | |
3152 | stub_name); | |
3153 | return NULL; | |
3154 | } | |
3155 | ||
3156 | stub_entry->stub_sec = stub_sec; | |
3157 | stub_entry->stub_offset = 0; | |
3158 | stub_entry->id_sec = link_sec; | |
3159 | return stub_entry; | |
3160 | } | |
3161 | ||
82bd7b59 AM |
3162 | /* Create sections for linker generated code. */ |
3163 | ||
b34976b6 | 3164 | static bfd_boolean |
4ce794b7 | 3165 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
82bd7b59 AM |
3166 | { |
3167 | struct ppc_link_hash_table *htab; | |
3168 | flagword flags; | |
3169 | ||
3170 | htab = ppc_hash_table (info); | |
3171 | ||
3172 | /* Create .sfpr for code to save and restore fp regs. */ | |
3173 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
3174 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
721956f4 | 3175 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
82bd7b59 AM |
3176 | if (htab->sfpr == NULL |
3177 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) | |
3178 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) | |
b34976b6 | 3179 | return FALSE; |
82bd7b59 | 3180 | |
721956f4 | 3181 | /* Create .glink for lazy dynamic linking support. */ |
4ce794b7 AM |
3182 | htab->glink = bfd_make_section_anyway (dynobj, ".glink"); |
3183 | if (htab->glink == NULL | |
3184 | || ! bfd_set_section_flags (dynobj, htab->glink, flags) | |
3185 | || ! bfd_set_section_alignment (dynobj, htab->glink, 2)) | |
b34976b6 | 3186 | return FALSE; |
82bd7b59 | 3187 | |
721956f4 AM |
3188 | /* Create .branch_lt for plt_branch stubs. */ |
3189 | flags = (SEC_ALLOC | SEC_LOAD | |
3190 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3191 | htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt"); |
3192 | if (htab->brlt == NULL | |
3193 | || ! bfd_set_section_flags (dynobj, htab->brlt, flags) | |
3194 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) | |
b34976b6 | 3195 | return FALSE; |
721956f4 AM |
3196 | |
3197 | if (info->shared) | |
3198 | { | |
3199 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
3200 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3201 | htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
3202 | if (!htab->relbrlt | |
3203 | || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags) | |
3204 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) | |
b34976b6 | 3205 | return FALSE; |
721956f4 | 3206 | } |
b34976b6 | 3207 | return TRUE; |
82bd7b59 AM |
3208 | } |
3209 | ||
e717da7e AM |
3210 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
3211 | not already done. */ | |
65f38f15 | 3212 | |
b34976b6 | 3213 | static bfd_boolean |
e717da7e | 3214 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
65f38f15 | 3215 | { |
e717da7e AM |
3216 | asection *got, *relgot; |
3217 | flagword flags; | |
3218 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
65f38f15 | 3219 | |
4ce794b7 | 3220 | if (!htab->got) |
e717da7e AM |
3221 | { |
3222 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) | |
3223 | return FALSE; | |
3224 | ||
3225 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); | |
3226 | if (!htab->got) | |
3227 | abort (); | |
3228 | } | |
3229 | ||
3230 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3231 | | SEC_LINKER_CREATED); | |
3232 | ||
3233 | got = bfd_make_section (abfd, ".got"); | |
3234 | if (!got | |
3235 | || !bfd_set_section_flags (abfd, got, flags) | |
3236 | || !bfd_set_section_alignment (abfd, got, 3)) | |
3237 | return FALSE; | |
65f38f15 | 3238 | |
e717da7e AM |
3239 | relgot = bfd_make_section (abfd, ".rela.got"); |
3240 | if (!relgot | |
3241 | || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY) | |
3242 | || ! bfd_set_section_alignment (abfd, relgot, 3)) | |
b34976b6 | 3243 | return FALSE; |
e717da7e AM |
3244 | |
3245 | ppc64_elf_tdata (abfd)->got = got; | |
3246 | ppc64_elf_tdata (abfd)->relgot = relgot; | |
b34976b6 | 3247 | return TRUE; |
65f38f15 | 3248 | } |
5bd4f169 | 3249 | |
82bd7b59 | 3250 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 3251 | |
b34976b6 | 3252 | static bfd_boolean |
4ce794b7 | 3253 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5bd4f169 | 3254 | { |
65f38f15 | 3255 | struct ppc_link_hash_table *htab; |
5bd4f169 | 3256 | |
65f38f15 | 3257 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 3258 | return FALSE; |
65f38f15 | 3259 | |
e717da7e AM |
3260 | htab = ppc_hash_table (info); |
3261 | if (!htab->got) | |
3262 | htab->got = bfd_get_section_by_name (dynobj, ".got"); | |
4ce794b7 AM |
3263 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
3264 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3265 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
65f38f15 | 3266 | if (!info->shared) |
4ce794b7 | 3267 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
65f38f15 | 3268 | |
e717da7e | 3269 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
4ce794b7 | 3270 | || (!info->shared && !htab->relbss)) |
65f38f15 AM |
3271 | abort (); |
3272 | ||
b34976b6 | 3273 | return TRUE; |
5bd4f169 AM |
3274 | } |
3275 | ||
65f38f15 AM |
3276 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
3277 | ||
3278 | static void | |
9c5bfbb7 AM |
3279 | ppc64_elf_copy_indirect_symbol |
3280 | (const struct elf_backend_data *bed ATTRIBUTE_UNUSED, | |
3281 | struct elf_link_hash_entry *dir, | |
3282 | struct elf_link_hash_entry *ind) | |
65f38f15 AM |
3283 | { |
3284 | struct ppc_link_hash_entry *edir, *eind; | |
81848ca0 | 3285 | flagword mask; |
65f38f15 AM |
3286 | |
3287 | edir = (struct ppc_link_hash_entry *) dir; | |
3288 | eind = (struct ppc_link_hash_entry *) ind; | |
3289 | ||
411e1bfb | 3290 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
bbd7ec4a | 3291 | if (eind->dyn_relocs != NULL) |
65f38f15 | 3292 | { |
bbd7ec4a AM |
3293 | if (edir->dyn_relocs != NULL) |
3294 | { | |
3295 | struct ppc_dyn_relocs **pp; | |
3296 | struct ppc_dyn_relocs *p; | |
3297 | ||
411e1bfb | 3298 | if (eind->elf.root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
3299 | abort (); |
3300 | ||
3301 | /* Add reloc counts against the weak sym to the strong sym | |
3302 | list. Merge any entries against the same section. */ | |
3303 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3304 | { | |
3305 | struct ppc_dyn_relocs *q; | |
3306 | ||
3307 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3308 | if (q->sec == p->sec) | |
3309 | { | |
3310 | q->pc_count += p->pc_count; | |
3311 | q->count += p->count; | |
3312 | *pp = p->next; | |
3313 | break; | |
3314 | } | |
3315 | if (q == NULL) | |
3316 | pp = &p->next; | |
3317 | } | |
3318 | *pp = edir->dyn_relocs; | |
3319 | } | |
3320 | ||
65f38f15 AM |
3321 | edir->dyn_relocs = eind->dyn_relocs; |
3322 | eind->dyn_relocs = NULL; | |
3323 | } | |
65f38f15 | 3324 | |
6349e628 AM |
3325 | edir->is_func |= eind->is_func; |
3326 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
3327 | edir->is_entry |= eind->is_entry; | |
58ac9f71 | 3328 | edir->tls_mask |= eind->tls_mask; |
6349e628 | 3329 | |
81848ca0 AM |
3330 | mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR |
3331 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF); | |
3332 | /* If called to transfer flags for a weakdef during processing | |
3333 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. | |
3334 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3335 | if (ELIMINATE_COPY_RELOCS | |
3336 | && eind->elf.root.type != bfd_link_hash_indirect | |
3337 | && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) | |
3338 | mask &= ~ELF_LINK_NON_GOT_REF; | |
3339 | ||
3340 | edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask; | |
6349e628 AM |
3341 | |
3342 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3343 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3344 | return; | |
3345 | ||
81848ca0 AM |
3346 | /* Copy over got entries that we may have already seen to the |
3347 | symbol which just became indirect. */ | |
411e1bfb AM |
3348 | if (eind->elf.got.glist != NULL) |
3349 | { | |
3350 | if (edir->elf.got.glist != NULL) | |
3351 | { | |
3352 | struct got_entry **entp; | |
3353 | struct got_entry *ent; | |
3354 | ||
3355 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) | |
3356 | { | |
3357 | struct got_entry *dent; | |
3358 | ||
3359 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) | |
3360 | if (dent->addend == ent->addend | |
e717da7e | 3361 | && dent->owner == ent->owner |
411e1bfb AM |
3362 | && dent->tls_type == ent->tls_type) |
3363 | { | |
3364 | dent->got.refcount += ent->got.refcount; | |
3365 | *entp = ent->next; | |
3366 | break; | |
3367 | } | |
3368 | if (dent == NULL) | |
3369 | entp = &ent->next; | |
3370 | } | |
3371 | *entp = edir->elf.got.glist; | |
3372 | } | |
3373 | ||
3374 | edir->elf.got.glist = eind->elf.got.glist; | |
3375 | eind->elf.got.glist = NULL; | |
3376 | } | |
3377 | ||
3378 | /* And plt entries. */ | |
3379 | if (eind->elf.plt.plist != NULL) | |
3380 | { | |
3381 | if (edir->elf.plt.plist != NULL) | |
3382 | { | |
3383 | struct plt_entry **entp; | |
3384 | struct plt_entry *ent; | |
3385 | ||
3386 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3387 | { | |
3388 | struct plt_entry *dent; | |
3389 | ||
3390 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3391 | if (dent->addend == ent->addend) | |
3392 | { | |
3393 | dent->plt.refcount += ent->plt.refcount; | |
3394 | *entp = ent->next; | |
3395 | break; | |
3396 | } | |
3397 | if (dent == NULL) | |
3398 | entp = &ent->next; | |
3399 | } | |
3400 | *entp = edir->elf.plt.plist; | |
3401 | } | |
3402 | ||
3403 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3404 | eind->elf.plt.plist = NULL; | |
3405 | } | |
3406 | ||
411e1bfb AM |
3407 | if (edir->elf.dynindx == -1) |
3408 | { | |
3409 | edir->elf.dynindx = eind->elf.dynindx; | |
3410 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3411 | eind->elf.dynindx = -1; | |
3412 | eind->elf.dynstr_index = 0; | |
3413 | } | |
3414 | else | |
3415 | BFD_ASSERT (eind->elf.dynindx == -1); | |
3416 | } | |
3417 | ||
3418 | /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and | |
3419 | symbols undefined on the command-line. */ | |
3420 | ||
3421 | bfd_boolean | |
4ce794b7 | 3422 | ppc64_elf_mark_entry_syms (struct bfd_link_info *info) |
411e1bfb AM |
3423 | { |
3424 | struct ppc_link_hash_table *htab; | |
3425 | struct bfd_sym_chain *sym; | |
3426 | ||
3427 | htab = ppc_hash_table (info); | |
3428 | for (sym = info->gc_sym_list; sym; sym = sym->next) | |
3429 | { | |
3430 | struct elf_link_hash_entry *h; | |
3431 | ||
3432 | h = elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); | |
3433 | if (h != NULL) | |
3434 | ((struct ppc_link_hash_entry *) h)->is_entry = 1; | |
3435 | } | |
3436 | return TRUE; | |
3437 | } | |
3438 | ||
3439 | static bfd_boolean | |
4ce794b7 AM |
3440 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
3441 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) | |
411e1bfb AM |
3442 | { |
3443 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); | |
e7b938ca | 3444 | char *local_got_tls_masks; |
411e1bfb AM |
3445 | |
3446 | if (local_got_ents == NULL) | |
3447 | { | |
3448 | bfd_size_type size = symtab_hdr->sh_info; | |
3449 | ||
e7b938ca | 3450 | size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks); |
4ce794b7 | 3451 | local_got_ents = bfd_zalloc (abfd, size); |
411e1bfb AM |
3452 | if (local_got_ents == NULL) |
3453 | return FALSE; | |
3454 | elf_local_got_ents (abfd) = local_got_ents; | |
3455 | } | |
3456 | ||
3457 | if ((tls_type & TLS_EXPLICIT) == 0) | |
3458 | { | |
3459 | struct got_entry *ent; | |
3460 | ||
3461 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) | |
e717da7e AM |
3462 | if (ent->addend == r_addend |
3463 | && ent->owner == abfd | |
3464 | && ent->tls_type == tls_type) | |
411e1bfb AM |
3465 | break; |
3466 | if (ent == NULL) | |
3467 | { | |
3468 | bfd_size_type amt = sizeof (*ent); | |
4ce794b7 | 3469 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3470 | if (ent == NULL) |
3471 | return FALSE; | |
3472 | ent->next = local_got_ents[r_symndx]; | |
3473 | ent->addend = r_addend; | |
e717da7e | 3474 | ent->owner = abfd; |
411e1bfb AM |
3475 | ent->tls_type = tls_type; |
3476 | ent->got.refcount = 0; | |
3477 | local_got_ents[r_symndx] = ent; | |
3478 | } | |
3479 | ent->got.refcount += 1; | |
3480 | } | |
3481 | ||
e7b938ca AM |
3482 | local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
3483 | local_got_tls_masks[r_symndx] |= tls_type; | |
411e1bfb | 3484 | return TRUE; |
65f38f15 AM |
3485 | } |
3486 | ||
411e1bfb | 3487 | static bfd_boolean |
4ce794b7 | 3488 | update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend) |
1e2f5b6e | 3489 | { |
411e1bfb | 3490 | struct plt_entry *ent; |
1e2f5b6e | 3491 | |
411e1bfb AM |
3492 | for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next) |
3493 | if (ent->addend == addend) | |
3494 | break; | |
3495 | if (ent == NULL) | |
1e2f5b6e | 3496 | { |
411e1bfb | 3497 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3498 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3499 | if (ent == NULL) |
3500 | return FALSE; | |
3501 | ent->next = eh->elf.plt.plist; | |
3502 | ent->addend = addend; | |
3503 | ent->plt.refcount = 0; | |
3504 | eh->elf.plt.plist = ent; | |
1e2f5b6e | 3505 | } |
411e1bfb AM |
3506 | ent->plt.refcount += 1; |
3507 | eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3508 | eh->is_func = 1; | |
b34976b6 | 3509 | return TRUE; |
1e2f5b6e AM |
3510 | } |
3511 | ||
50bc7936 AM |
3512 | /* Find the function descriptor hash entry from the given function code |
3513 | hash entry FH. Link the entries via their OH fields. */ | |
3514 | static struct ppc_link_hash_entry * | |
3515 | get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) | |
3516 | { | |
3517 | struct ppc_link_hash_entry *fdh = (struct ppc_link_hash_entry *) fh->oh; | |
3518 | ||
3519 | if (fdh == NULL) | |
3520 | { | |
3521 | const char *fd_name = fh->elf.root.root.string + 1; | |
3522 | ||
3523 | fdh = (struct ppc_link_hash_entry *) | |
3524 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); | |
3525 | if (fdh != NULL) | |
3526 | { | |
3527 | fdh->is_func_descriptor = 1; | |
3528 | fdh->oh = &fh->elf; | |
3529 | fh->is_func = 1; | |
3530 | fh->oh = &fdh->elf; | |
3531 | } | |
3532 | } | |
3533 | ||
3534 | return fdh; | |
3535 | } | |
3536 | ||
5bd4f169 | 3537 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 3538 | calculate needed space in the global offset table, procedure |
5d1634d7 | 3539 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 3540 | |
b34976b6 | 3541 | static bfd_boolean |
4ce794b7 AM |
3542 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
3543 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 3544 | { |
65f38f15 | 3545 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3546 | Elf_Internal_Shdr *symtab_hdr; |
3547 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
3548 | const Elf_Internal_Rela *rel; | |
3549 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 3550 | asection *sreloc; |
1e2f5b6e | 3551 | asection **opd_sym_map; |
5bd4f169 | 3552 | |
1049f94e | 3553 | if (info->relocatable) |
b34976b6 | 3554 | return TRUE; |
5bd4f169 | 3555 | |
65f38f15 | 3556 | htab = ppc_hash_table (info); |
5bd4f169 | 3557 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
3558 | |
3559 | sym_hashes = elf_sym_hashes (abfd); | |
3560 | sym_hashes_end = (sym_hashes | |
1e2f5b6e AM |
3561 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
3562 | - symtab_hdr->sh_info); | |
5bd4f169 AM |
3563 | |
3564 | sreloc = NULL; | |
1e2f5b6e AM |
3565 | opd_sym_map = NULL; |
3566 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
3567 | { | |
3568 | /* Garbage collection needs some extra help with .opd sections. | |
3569 | We don't want to necessarily keep everything referenced by | |
3570 | relocs in .opd, as that would keep all functions. Instead, | |
3571 | if we reference an .opd symbol (a function descriptor), we | |
3572 | want to keep the function code symbol's section. This is | |
3573 | easy for global symbols, but for local syms we need to keep | |
3574 | information about the associated function section. Later, if | |
3575 | edit_opd deletes entries, we'll use this array to adjust | |
3576 | local syms in .opd. */ | |
3577 | union opd_info { | |
3578 | asection *func_section; | |
3579 | long entry_adjust; | |
3580 | }; | |
3581 | bfd_size_type amt; | |
3582 | ||
3583 | amt = sec->_raw_size * sizeof (union opd_info) / 24; | |
4ce794b7 | 3584 | opd_sym_map = bfd_zalloc (abfd, amt); |
1e2f5b6e | 3585 | if (opd_sym_map == NULL) |
b34976b6 | 3586 | return FALSE; |
f0abc2a1 | 3587 | ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map; |
1e2f5b6e | 3588 | } |
5bd4f169 | 3589 | |
82bd7b59 AM |
3590 | if (htab->sfpr == NULL |
3591 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 3592 | return FALSE; |
82bd7b59 | 3593 | |
5bd4f169 AM |
3594 | rel_end = relocs + sec->reloc_count; |
3595 | for (rel = relocs; rel < rel_end; rel++) | |
3596 | { | |
3597 | unsigned long r_symndx; | |
3598 | struct elf_link_hash_entry *h; | |
04c9666a | 3599 | enum elf_ppc64_reloc_type r_type; |
411e1bfb | 3600 | int tls_type = 0; |
5bd4f169 AM |
3601 | |
3602 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3603 | if (r_symndx < symtab_hdr->sh_info) | |
3604 | h = NULL; | |
3605 | else | |
3606 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3607 | ||
4ce794b7 | 3608 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 3609 | switch (r_type) |
5bd4f169 | 3610 | { |
411e1bfb AM |
3611 | case R_PPC64_GOT_TLSLD16: |
3612 | case R_PPC64_GOT_TLSLD16_LO: | |
3613 | case R_PPC64_GOT_TLSLD16_HI: | |
3614 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 3615 | ppc64_tlsld_got (abfd)->refcount += 1; |
951fd09b | 3616 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
3617 | goto dogottls; |
3618 | ||
3619 | case R_PPC64_GOT_TLSGD16: | |
3620 | case R_PPC64_GOT_TLSGD16_LO: | |
3621 | case R_PPC64_GOT_TLSGD16_HI: | |
3622 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 3623 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
3624 | goto dogottls; |
3625 | ||
3626 | case R_PPC64_GOT_TPREL16_DS: | |
3627 | case R_PPC64_GOT_TPREL16_LO_DS: | |
3628 | case R_PPC64_GOT_TPREL16_HI: | |
3629 | case R_PPC64_GOT_TPREL16_HA: | |
3630 | if (info->shared) | |
3631 | info->flags |= DF_STATIC_TLS; | |
3632 | tls_type = TLS_TLS | TLS_TPREL; | |
3633 | goto dogottls; | |
3634 | ||
3635 | case R_PPC64_GOT_DTPREL16_DS: | |
3636 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
3637 | case R_PPC64_GOT_DTPREL16_HI: | |
3638 | case R_PPC64_GOT_DTPREL16_HA: | |
3639 | tls_type = TLS_TLS | TLS_DTPREL; | |
3640 | dogottls: | |
3641 | sec->has_tls_reloc = 1; | |
3642 | /* Fall thru */ | |
3643 | ||
5bd4f169 | 3644 | case R_PPC64_GOT16: |
5bd4f169 | 3645 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
3646 | case R_PPC64_GOT16_HA: |
3647 | case R_PPC64_GOT16_HI: | |
3648 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 3649 | case R_PPC64_GOT16_LO_DS: |
65f38f15 | 3650 | /* This symbol requires a global offset table entry. */ |
ad8e1ba5 | 3651 | sec->has_gp_reloc = 1; |
e717da7e AM |
3652 | if (ppc64_elf_tdata (abfd)->got == NULL |
3653 | && !create_got_section (abfd, info)) | |
b34976b6 | 3654 | return FALSE; |
5bd4f169 AM |
3655 | |
3656 | if (h != NULL) | |
3657 | { | |
411e1bfb AM |
3658 | struct ppc_link_hash_entry *eh; |
3659 | struct got_entry *ent; | |
65f38f15 | 3660 | |
411e1bfb AM |
3661 | eh = (struct ppc_link_hash_entry *) h; |
3662 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) | |
3663 | if (ent->addend == rel->r_addend | |
e717da7e | 3664 | && ent->owner == abfd |
411e1bfb AM |
3665 | && ent->tls_type == tls_type) |
3666 | break; | |
3667 | if (ent == NULL) | |
5bd4f169 | 3668 | { |
411e1bfb | 3669 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3670 | ent = bfd_alloc (abfd, amt); |
411e1bfb | 3671 | if (ent == NULL) |
b34976b6 | 3672 | return FALSE; |
411e1bfb AM |
3673 | ent->next = eh->elf.got.glist; |
3674 | ent->addend = rel->r_addend; | |
e717da7e | 3675 | ent->owner = abfd; |
411e1bfb AM |
3676 | ent->tls_type = tls_type; |
3677 | ent->got.refcount = 0; | |
3678 | eh->elf.got.glist = ent; | |
5bd4f169 | 3679 | } |
411e1bfb | 3680 | ent->got.refcount += 1; |
e7b938ca | 3681 | eh->tls_mask |= tls_type; |
5bd4f169 | 3682 | } |
411e1bfb AM |
3683 | else |
3684 | /* This is a global offset table entry for a local symbol. */ | |
3685 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3686 | rel->r_addend, tls_type)) | |
3687 | return FALSE; | |
5bd4f169 AM |
3688 | break; |
3689 | ||
5bd4f169 | 3690 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
3691 | case R_PPC64_PLT16_HI: |
3692 | case R_PPC64_PLT16_LO: | |
3693 | case R_PPC64_PLT32: | |
3694 | case R_PPC64_PLT64: | |
5bd4f169 | 3695 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
3696 | actually build the entry in adjust_dynamic_symbol, |
3697 | because this might be a case of linking PIC code without | |
3698 | linking in any dynamic objects, in which case we don't | |
3699 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
3700 | if (h == NULL) |
3701 | { | |
3702 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 3703 | table entry for a local symbol. */ |
5bd4f169 | 3704 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3705 | return FALSE; |
5bd4f169 | 3706 | } |
411e1bfb AM |
3707 | else |
3708 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, | |
3709 | rel->r_addend)) | |
3710 | return FALSE; | |
5bd4f169 AM |
3711 | break; |
3712 | ||
3713 | /* The following relocations don't need to propagate the | |
3714 | relocation if linking a shared object since they are | |
3715 | section relative. */ | |
3716 | case R_PPC64_SECTOFF: | |
3717 | case R_PPC64_SECTOFF_LO: | |
3718 | case R_PPC64_SECTOFF_HI: | |
3719 | case R_PPC64_SECTOFF_HA: | |
3720 | case R_PPC64_SECTOFF_DS: | |
3721 | case R_PPC64_SECTOFF_LO_DS: | |
411e1bfb AM |
3722 | case R_PPC64_DTPREL16: |
3723 | case R_PPC64_DTPREL16_LO: | |
3724 | case R_PPC64_DTPREL16_HI: | |
3725 | case R_PPC64_DTPREL16_HA: | |
3726 | case R_PPC64_DTPREL16_DS: | |
3727 | case R_PPC64_DTPREL16_LO_DS: | |
3728 | case R_PPC64_DTPREL16_HIGHER: | |
3729 | case R_PPC64_DTPREL16_HIGHERA: | |
3730 | case R_PPC64_DTPREL16_HIGHEST: | |
3731 | case R_PPC64_DTPREL16_HIGHESTA: | |
5bd4f169 AM |
3732 | break; |
3733 | ||
ad8e1ba5 AM |
3734 | /* Nor do these. */ |
3735 | case R_PPC64_TOC16: | |
3736 | case R_PPC64_TOC16_LO: | |
3737 | case R_PPC64_TOC16_HI: | |
3738 | case R_PPC64_TOC16_HA: | |
3739 | case R_PPC64_TOC16_DS: | |
3740 | case R_PPC64_TOC16_LO_DS: | |
3741 | sec->has_gp_reloc = 1; | |
3742 | break; | |
3743 | ||
5bd4f169 AM |
3744 | /* This relocation describes the C++ object vtable hierarchy. |
3745 | Reconstruct it for later use during GC. */ | |
3746 | case R_PPC64_GNU_VTINHERIT: | |
3747 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
b34976b6 | 3748 | return FALSE; |
5bd4f169 AM |
3749 | break; |
3750 | ||
3751 | /* This relocation describes which C++ vtable entries are actually | |
3752 | used. Record for later use during GC. */ | |
3753 | case R_PPC64_GNU_VTENTRY: | |
3754 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 3755 | return FALSE; |
5bd4f169 AM |
3756 | break; |
3757 | ||
721956f4 AM |
3758 | case R_PPC64_REL14: |
3759 | case R_PPC64_REL14_BRTAKEN: | |
3760 | case R_PPC64_REL14_BRNTAKEN: | |
3761 | htab->has_14bit_branch = 1; | |
3762 | /* Fall through. */ | |
3763 | ||
5d1634d7 | 3764 | case R_PPC64_REL24: |
e86ce104 AM |
3765 | if (h != NULL |
3766 | && h->root.root.string[0] == '.' | |
3767 | && h->root.root.string[1] != 0) | |
5d1634d7 AM |
3768 | { |
3769 | /* We may need a .plt entry if the function this reloc | |
3770 | refers to is in a shared lib. */ | |
411e1bfb AM |
3771 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
3772 | rel->r_addend)) | |
3773 | return FALSE; | |
3774 | if (h == htab->tls_get_addr) | |
3775 | sec->has_tls_reloc = 1; | |
a48ebf4d AM |
3776 | else if ((strncmp (h->root.root.string, ".__tls_get_addr", 15) |
3777 | == 0) | |
3778 | && (h->root.root.string[15] == 0 | |
3779 | || h->root.root.string[15] == '@')) | |
411e1bfb AM |
3780 | { |
3781 | htab->tls_get_addr = h; | |
3782 | sec->has_tls_reloc = 1; | |
3783 | } | |
3784 | } | |
3785 | break; | |
3786 | ||
3787 | case R_PPC64_TPREL64: | |
3788 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | |
3789 | if (info->shared) | |
3790 | info->flags |= DF_STATIC_TLS; | |
3791 | goto dotlstoc; | |
3792 | ||
3793 | case R_PPC64_DTPMOD64: | |
3794 | if (rel + 1 < rel_end | |
3795 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
3796 | && rel[1].r_offset == rel->r_offset + 8) | |
951fd09b | 3797 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
411e1bfb | 3798 | else |
951fd09b | 3799 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
411e1bfb AM |
3800 | goto dotlstoc; |
3801 | ||
3802 | case R_PPC64_DTPREL64: | |
3803 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; | |
3804 | if (rel != relocs | |
3805 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) | |
3806 | && rel[-1].r_offset == rel->r_offset - 8) | |
3807 | /* This is the second reloc of a dtpmod, dtprel pair. | |
3808 | Don't mark with TLS_DTPREL. */ | |
3809 | goto dodyn; | |
3810 | ||
3811 | dotlstoc: | |
3812 | sec->has_tls_reloc = 1; | |
3813 | if (h != NULL) | |
3814 | { | |
3815 | struct ppc_link_hash_entry *eh; | |
3816 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 3817 | eh->tls_mask |= tls_type; |
411e1bfb AM |
3818 | } |
3819 | else | |
3820 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3821 | rel->r_addend, tls_type)) | |
3822 | return FALSE; | |
3823 | ||
3824 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) | |
3825 | { | |
e7b938ca | 3826 | /* One extra to simplify get_tls_mask. */ |
951fd09b | 3827 | bfd_size_type amt = sec->_raw_size * sizeof (unsigned) / 8 + 1; |
4ce794b7 | 3828 | ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt); |
411e1bfb AM |
3829 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
3830 | return FALSE; | |
3831 | } | |
3832 | BFD_ASSERT (rel->r_offset % 8 == 0); | |
3833 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx; | |
951fd09b AM |
3834 | |
3835 | /* Mark the second slot of a GD or LD entry. | |
3836 | -1 to indicate GD and -2 to indicate LD. */ | |
3837 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | |
3838 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1; | |
3839 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) | |
3840 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2; | |
411e1bfb AM |
3841 | goto dodyn; |
3842 | ||
3843 | case R_PPC64_TPREL16: | |
3844 | case R_PPC64_TPREL16_LO: | |
3845 | case R_PPC64_TPREL16_HI: | |
3846 | case R_PPC64_TPREL16_HA: | |
3847 | case R_PPC64_TPREL16_DS: | |
3848 | case R_PPC64_TPREL16_LO_DS: | |
3849 | case R_PPC64_TPREL16_HIGHER: | |
3850 | case R_PPC64_TPREL16_HIGHERA: | |
3851 | case R_PPC64_TPREL16_HIGHEST: | |
3852 | case R_PPC64_TPREL16_HIGHESTA: | |
3853 | if (info->shared) | |
3854 | { | |
3855 | info->flags |= DF_STATIC_TLS; | |
3856 | goto dodyn; | |
5d1634d7 AM |
3857 | } |
3858 | break; | |
3859 | ||
e86ce104 | 3860 | case R_PPC64_ADDR64: |
1e2f5b6e | 3861 | if (opd_sym_map != NULL |
e86ce104 AM |
3862 | && h != NULL |
3863 | && h->root.root.string[0] == '.' | |
3864 | && h->root.root.string[1] != 0) | |
50bc7936 | 3865 | get_fdh ((struct ppc_link_hash_entry *) h, htab); |
e86ce104 | 3866 | |
1e2f5b6e AM |
3867 | if (opd_sym_map != NULL |
3868 | && h == NULL | |
3869 | && rel + 1 < rel_end | |
4ce794b7 | 3870 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
1e2f5b6e AM |
3871 | { |
3872 | asection *s; | |
3873 | ||
3874 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, | |
3875 | r_symndx); | |
3876 | if (s == NULL) | |
b34976b6 | 3877 | return FALSE; |
1e2f5b6e AM |
3878 | else if (s != sec) |
3879 | opd_sym_map[rel->r_offset / 24] = s; | |
3880 | } | |
e86ce104 AM |
3881 | /* Fall through. */ |
3882 | ||
04c9666a | 3883 | case R_PPC64_REL30: |
5bd4f169 | 3884 | case R_PPC64_REL32: |
04c9666a | 3885 | case R_PPC64_REL64: |
65f38f15 AM |
3886 | case R_PPC64_ADDR14: |
3887 | case R_PPC64_ADDR14_BRNTAKEN: | |
3888 | case R_PPC64_ADDR14_BRTAKEN: | |
3889 | case R_PPC64_ADDR16: | |
3890 | case R_PPC64_ADDR16_DS: | |
3891 | case R_PPC64_ADDR16_HA: | |
3892 | case R_PPC64_ADDR16_HI: | |
3893 | case R_PPC64_ADDR16_HIGHER: | |
3894 | case R_PPC64_ADDR16_HIGHERA: | |
3895 | case R_PPC64_ADDR16_HIGHEST: | |
3896 | case R_PPC64_ADDR16_HIGHESTA: | |
3897 | case R_PPC64_ADDR16_LO: | |
3898 | case R_PPC64_ADDR16_LO_DS: | |
3899 | case R_PPC64_ADDR24: | |
65f38f15 | 3900 | case R_PPC64_ADDR32: |
65f38f15 AM |
3901 | case R_PPC64_UADDR16: |
3902 | case R_PPC64_UADDR32: | |
3903 | case R_PPC64_UADDR64: | |
5bd4f169 | 3904 | case R_PPC64_TOC: |
81848ca0 AM |
3905 | if (h != NULL && !info->shared) |
3906 | /* We may need a copy reloc. */ | |
3907 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
3908 | ||
41bd81ab | 3909 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 3910 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 3911 | break; |
e86ce104 | 3912 | |
f4656909 AM |
3913 | /* Don't propagate relocs that the dynamic linker won't relocate. */ |
3914 | if ((sec->flags & SEC_ALLOC) == 0) | |
3915 | break; | |
3916 | ||
65f38f15 AM |
3917 | /* If we are creating a shared library, and this is a reloc |
3918 | against a global symbol, or a non PC relative reloc | |
3919 | against a local symbol, then we need to copy the reloc | |
3920 | into the shared library. However, if we are linking with | |
3921 | -Bsymbolic, we do not need to copy a reloc against a | |
3922 | global symbol which is defined in an object we are | |
3923 | including in the link (i.e., DEF_REGULAR is set). At | |
3924 | this point we have not seen all the input files, so it is | |
3925 | possible that DEF_REGULAR is not set now but will be set | |
3926 | later (it is never cleared). In case of a weak definition, | |
3927 | DEF_REGULAR may be cleared later by a strong definition in | |
3928 | a shared library. We account for that possibility below by | |
f4656909 | 3929 | storing information in the dyn_relocs field of the hash |
65f38f15 AM |
3930 | table entry. A similar situation occurs when creating |
3931 | shared libraries and symbol visibility changes render the | |
3932 | symbol local. | |
3933 | ||
3934 | If on the other hand, we are creating an executable, we | |
3935 | may need to keep relocations for symbols satisfied by a | |
3936 | dynamic library if we manage to avoid copy relocs for the | |
3937 | symbol. */ | |
411e1bfb | 3938 | dodyn: |
65f38f15 | 3939 | if ((info->shared |
411e1bfb | 3940 | && (MUST_BE_DYN_RELOC (r_type) |
65f38f15 AM |
3941 | || (h != NULL |
3942 | && (! info->symbolic | |
3943 | || h->root.type == bfd_link_hash_defweak | |
3944 | || (h->elf_link_hash_flags | |
3945 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
f4656909 AM |
3946 | || (ELIMINATE_COPY_RELOCS |
3947 | && !info->shared | |
65f38f15 AM |
3948 | && h != NULL |
3949 | && (h->root.type == bfd_link_hash_defweak | |
3950 | || (h->elf_link_hash_flags | |
3951 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 3952 | { |
ec338859 AM |
3953 | struct ppc_dyn_relocs *p; |
3954 | struct ppc_dyn_relocs **head; | |
3955 | ||
65f38f15 AM |
3956 | /* We must copy these reloc types into the output file. |
3957 | Create a reloc section in dynobj and make room for | |
3958 | this reloc. */ | |
5bd4f169 AM |
3959 | if (sreloc == NULL) |
3960 | { | |
3961 | const char *name; | |
65f38f15 | 3962 | bfd *dynobj; |
5bd4f169 AM |
3963 | |
3964 | name = (bfd_elf_string_from_elf_section | |
3965 | (abfd, | |
3966 | elf_elfheader (abfd)->e_shstrndx, | |
3967 | elf_section_data (sec)->rel_hdr.sh_name)); | |
3968 | if (name == NULL) | |
b34976b6 | 3969 | return FALSE; |
5bd4f169 | 3970 | |
65f38f15 AM |
3971 | if (strncmp (name, ".rela", 5) != 0 |
3972 | || strcmp (bfd_get_section_name (abfd, sec), | |
3973 | name + 5) != 0) | |
3974 | { | |
3975 | (*_bfd_error_handler) | |
3976 | (_("%s: bad relocation section name `%s\'"), | |
3977 | bfd_archive_filename (abfd), name); | |
5d1634d7 | 3978 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
3979 | } |
3980 | ||
65f38f15 | 3981 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
3982 | sreloc = bfd_get_section_by_name (dynobj, name); |
3983 | if (sreloc == NULL) | |
3984 | { | |
3985 | flagword flags; | |
3986 | ||
3987 | sreloc = bfd_make_section (dynobj, name); | |
3988 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
3989 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3990 | if ((sec->flags & SEC_ALLOC) != 0) | |
3991 | flags |= SEC_ALLOC | SEC_LOAD; | |
3992 | if (sreloc == NULL | |
3993 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 3994 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
b34976b6 | 3995 | return FALSE; |
5bd4f169 | 3996 | } |
65f38f15 | 3997 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
3998 | } |
3999 | ||
65f38f15 AM |
4000 | /* If this is a global symbol, we count the number of |
4001 | relocations we need for this symbol. */ | |
4002 | if (h != NULL) | |
4003 | { | |
ec338859 | 4004 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
4005 | } |
4006 | else | |
4007 | { | |
ec338859 AM |
4008 | /* Track dynamic relocs needed for local syms too. |
4009 | We really need local syms available to do this | |
4010 | easily. Oh well. */ | |
4011 | ||
4012 | asection *s; | |
4013 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
4014 | sec, r_symndx); | |
4015 | if (s == NULL) | |
b34976b6 | 4016 | return FALSE; |
ec338859 AM |
4017 | |
4018 | head = ((struct ppc_dyn_relocs **) | |
4019 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 4020 | } |
ec338859 AM |
4021 | |
4022 | p = *head; | |
4023 | if (p == NULL || p->sec != sec) | |
4024 | { | |
4ce794b7 | 4025 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
ec338859 | 4026 | if (p == NULL) |
b34976b6 | 4027 | return FALSE; |
ec338859 AM |
4028 | p->next = *head; |
4029 | *head = p; | |
4030 | p->sec = sec; | |
4031 | p->count = 0; | |
4032 | p->pc_count = 0; | |
4033 | } | |
4034 | ||
4035 | p->count += 1; | |
411e1bfb | 4036 | if (!MUST_BE_DYN_RELOC (r_type)) |
ec338859 | 4037 | p->pc_count += 1; |
65f38f15 | 4038 | } |
5bd4f169 | 4039 | break; |
65f38f15 AM |
4040 | |
4041 | default: | |
96e0dda4 | 4042 | break; |
5bd4f169 AM |
4043 | } |
4044 | } | |
4045 | ||
b34976b6 | 4046 | return TRUE; |
5bd4f169 AM |
4047 | } |
4048 | ||
4049 | /* Return the section that should be marked against GC for a given | |
4050 | relocation. */ | |
4051 | ||
4052 | static asection * | |
4ce794b7 AM |
4053 | ppc64_elf_gc_mark_hook (asection *sec, |
4054 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
4055 | Elf_Internal_Rela *rel, | |
4056 | struct elf_link_hash_entry *h, | |
4057 | Elf_Internal_Sym *sym) | |
5bd4f169 | 4058 | { |
1e2f5b6e AM |
4059 | asection *rsec = NULL; |
4060 | ||
5bd4f169 AM |
4061 | if (h != NULL) |
4062 | { | |
04c9666a | 4063 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e | 4064 | struct ppc_link_hash_entry *fdh; |
a33d1f77 | 4065 | |
4ce794b7 | 4066 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 4067 | switch (r_type) |
5bd4f169 AM |
4068 | { |
4069 | case R_PPC64_GNU_VTINHERIT: | |
4070 | case R_PPC64_GNU_VTENTRY: | |
4071 | break; | |
4072 | ||
4073 | default: | |
4074 | switch (h->root.type) | |
4075 | { | |
4076 | case bfd_link_hash_defined: | |
4077 | case bfd_link_hash_defweak: | |
1e2f5b6e AM |
4078 | fdh = (struct ppc_link_hash_entry *) h; |
4079 | ||
4080 | /* Function descriptor syms cause the associated | |
4081 | function code sym section to be marked. */ | |
4082 | if (fdh->is_func_descriptor) | |
4083 | rsec = fdh->oh->root.u.def.section; | |
4084 | ||
4085 | /* Function entry syms return NULL if they are in .opd | |
4086 | and are not ._start (or others undefined on the ld | |
4087 | command line). Thus we avoid marking all function | |
b34976b6 | 4088 | sections, as all functions are referenced in .opd. */ |
1e2f5b6e AM |
4089 | else if ((fdh->oh != NULL |
4090 | && ((struct ppc_link_hash_entry *) fdh->oh)->is_entry) | |
f0abc2a1 | 4091 | || ppc64_elf_section_data (sec)->opd.func_sec == NULL) |
1e2f5b6e AM |
4092 | rsec = h->root.u.def.section; |
4093 | break; | |
5bd4f169 AM |
4094 | |
4095 | case bfd_link_hash_common: | |
1e2f5b6e AM |
4096 | rsec = h->root.u.c.p->section; |
4097 | break; | |
5bd4f169 AM |
4098 | |
4099 | default: | |
4100 | break; | |
4101 | } | |
4102 | } | |
4103 | } | |
4104 | else | |
4105 | { | |
1e2f5b6e AM |
4106 | asection **opd_sym_section; |
4107 | ||
4108 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
f0abc2a1 | 4109 | opd_sym_section = ppc64_elf_section_data (rsec)->opd.func_sec; |
1e2f5b6e AM |
4110 | if (opd_sym_section != NULL) |
4111 | rsec = opd_sym_section[sym->st_value / 24]; | |
f0abc2a1 | 4112 | else if (ppc64_elf_section_data (sec)->opd.func_sec != NULL) |
1e2f5b6e | 4113 | rsec = NULL; |
5bd4f169 AM |
4114 | } |
4115 | ||
1e2f5b6e | 4116 | return rsec; |
5bd4f169 AM |
4117 | } |
4118 | ||
65f38f15 AM |
4119 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
4120 | section being removed. */ | |
5bd4f169 | 4121 | |
b34976b6 | 4122 | static bfd_boolean |
4ce794b7 AM |
4123 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
4124 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 4125 | { |
411e1bfb | 4126 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
4127 | Elf_Internal_Shdr *symtab_hdr; |
4128 | struct elf_link_hash_entry **sym_hashes; | |
411e1bfb | 4129 | struct got_entry **local_got_ents; |
5bd4f169 | 4130 | const Elf_Internal_Rela *rel, *relend; |
5bd4f169 | 4131 | |
ec338859 AM |
4132 | elf_section_data (sec)->local_dynrel = NULL; |
4133 | ||
411e1bfb | 4134 | htab = ppc_hash_table (info); |
5bd4f169 AM |
4135 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4136 | sym_hashes = elf_sym_hashes (abfd); | |
411e1bfb | 4137 | local_got_ents = elf_local_got_ents (abfd); |
5bd4f169 AM |
4138 | |
4139 | relend = relocs + sec->reloc_count; | |
4140 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
4141 | { |
4142 | unsigned long r_symndx; | |
04c9666a | 4143 | enum elf_ppc64_reloc_type r_type; |
58ac9f71 | 4144 | struct elf_link_hash_entry *h = NULL; |
411e1bfb | 4145 | char tls_type = 0; |
5bd4f169 | 4146 | |
a33d1f77 | 4147 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 | 4148 | r_type = ELF64_R_TYPE (rel->r_info); |
58ac9f71 AM |
4149 | if (r_symndx >= symtab_hdr->sh_info) |
4150 | { | |
4151 | struct ppc_link_hash_entry *eh; | |
4152 | struct ppc_dyn_relocs **pp; | |
4153 | struct ppc_dyn_relocs *p; | |
4154 | ||
4155 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4156 | eh = (struct ppc_link_hash_entry *) h; | |
4157 | ||
4158 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4159 | if (p->sec == sec) | |
4160 | { | |
4161 | /* Everything must go for SEC. */ | |
4162 | *pp = p->next; | |
4163 | break; | |
4164 | } | |
4165 | } | |
4166 | ||
a33d1f77 AM |
4167 | switch (r_type) |
4168 | { | |
411e1bfb AM |
4169 | case R_PPC64_GOT_TLSLD16: |
4170 | case R_PPC64_GOT_TLSLD16_LO: | |
4171 | case R_PPC64_GOT_TLSLD16_HI: | |
4172 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 4173 | ppc64_tlsld_got (abfd)->refcount -= 1; |
951fd09b | 4174 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
4175 | goto dogot; |
4176 | ||
4177 | case R_PPC64_GOT_TLSGD16: | |
4178 | case R_PPC64_GOT_TLSGD16_LO: | |
4179 | case R_PPC64_GOT_TLSGD16_HI: | |
4180 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 4181 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
4182 | goto dogot; |
4183 | ||
4184 | case R_PPC64_GOT_TPREL16_DS: | |
4185 | case R_PPC64_GOT_TPREL16_LO_DS: | |
4186 | case R_PPC64_GOT_TPREL16_HI: | |
4187 | case R_PPC64_GOT_TPREL16_HA: | |
4188 | tls_type = TLS_TLS | TLS_TPREL; | |
4189 | goto dogot; | |
4190 | ||
4191 | case R_PPC64_GOT_DTPREL16_DS: | |
4192 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
4193 | case R_PPC64_GOT_DTPREL16_HI: | |
4194 | case R_PPC64_GOT_DTPREL16_HA: | |
4195 | tls_type = TLS_TLS | TLS_DTPREL; | |
4196 | goto dogot; | |
4197 | ||
a33d1f77 AM |
4198 | case R_PPC64_GOT16: |
4199 | case R_PPC64_GOT16_DS: | |
4200 | case R_PPC64_GOT16_HA: | |
4201 | case R_PPC64_GOT16_HI: | |
4202 | case R_PPC64_GOT16_LO: | |
4203 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb AM |
4204 | dogot: |
4205 | { | |
4206 | struct got_entry *ent; | |
4207 | ||
58ac9f71 AM |
4208 | if (h != NULL) |
4209 | ent = h->got.glist; | |
411e1bfb AM |
4210 | else |
4211 | ent = local_got_ents[r_symndx]; | |
4212 | ||
4213 | for (; ent != NULL; ent = ent->next) | |
4214 | if (ent->addend == rel->r_addend | |
e717da7e | 4215 | && ent->owner == abfd |
411e1bfb AM |
4216 | && ent->tls_type == tls_type) |
4217 | break; | |
4218 | if (ent == NULL) | |
4219 | abort (); | |
4220 | if (ent->got.refcount > 0) | |
4221 | ent->got.refcount -= 1; | |
4222 | } | |
a33d1f77 | 4223 | break; |
65f38f15 | 4224 | |
a33d1f77 AM |
4225 | case R_PPC64_PLT16_HA: |
4226 | case R_PPC64_PLT16_HI: | |
4227 | case R_PPC64_PLT16_LO: | |
4228 | case R_PPC64_PLT32: | |
4229 | case R_PPC64_PLT64: | |
721956f4 AM |
4230 | case R_PPC64_REL14: |
4231 | case R_PPC64_REL14_BRNTAKEN: | |
4232 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 | 4233 | case R_PPC64_REL24: |
58ac9f71 | 4234 | if (h != NULL) |
5d1634d7 | 4235 | { |
411e1bfb AM |
4236 | struct plt_entry *ent; |
4237 | ||
411e1bfb AM |
4238 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
4239 | if (ent->addend == rel->r_addend) | |
4240 | break; | |
4241 | if (ent == NULL) | |
4242 | abort (); | |
4243 | if (ent->plt.refcount > 0) | |
4244 | ent->plt.refcount -= 1; | |
5d1634d7 | 4245 | } |
e86ce104 | 4246 | break; |
5d1634d7 | 4247 | |
a33d1f77 AM |
4248 | default: |
4249 | break; | |
4250 | } | |
4251 | } | |
b34976b6 | 4252 | return TRUE; |
5bd4f169 AM |
4253 | } |
4254 | ||
e86ce104 AM |
4255 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
4256 | information on function code symbol entries to their corresponding | |
4257 | function descriptor symbol entries. */ | |
b34976b6 | 4258 | static bfd_boolean |
4ce794b7 | 4259 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 4260 | { |
e86ce104 | 4261 | struct bfd_link_info *info; |
65f38f15 | 4262 | struct ppc_link_hash_table *htab; |
411e1bfb | 4263 | struct plt_entry *ent; |
50bc7936 AM |
4264 | struct ppc_link_hash_entry *fh; |
4265 | struct ppc_link_hash_entry *fdh; | |
4266 | bfd_boolean force_local; | |
5bd4f169 | 4267 | |
50bc7936 AM |
4268 | fh = (struct ppc_link_hash_entry *) h; |
4269 | if (fh->elf.root.type == bfd_link_hash_indirect) | |
b34976b6 | 4270 | return TRUE; |
e86ce104 | 4271 | |
50bc7936 AM |
4272 | if (fh->elf.root.type == bfd_link_hash_warning) |
4273 | fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link; | |
e92d460e | 4274 | |
4ce794b7 | 4275 | info = inf; |
65f38f15 | 4276 | htab = ppc_hash_table (info); |
5bd4f169 | 4277 | |
e86ce104 AM |
4278 | /* If this is a function code symbol, transfer dynamic linking |
4279 | information to the function descriptor symbol. */ | |
50bc7936 | 4280 | if (!fh->is_func) |
b34976b6 | 4281 | return TRUE; |
e86ce104 | 4282 | |
50bc7936 AM |
4283 | if (fh->elf.root.type == bfd_link_hash_undefweak |
4284 | && (fh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR)) | |
b34976b6 | 4285 | htab->have_undefweak = TRUE; |
805fc799 | 4286 | |
50bc7936 | 4287 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
4288 | if (ent->plt.refcount > 0) |
4289 | break; | |
50bc7936 AM |
4290 | if (ent == NULL |
4291 | || fh->elf.root.root.string[0] != '.' | |
4292 | || fh->elf.root.root.string[1] == '\0') | |
4293 | return TRUE; | |
5bd4f169 | 4294 | |
50bc7936 AM |
4295 | /* Find the corresponding function descriptor symbol. Create it |
4296 | as undefined if necessary. */ | |
5bd4f169 | 4297 | |
50bc7936 AM |
4298 | fdh = get_fdh (fh, htab); |
4299 | if (fdh != NULL) | |
4300 | while (fdh->elf.root.type == bfd_link_hash_indirect | |
4301 | || fdh->elf.root.type == bfd_link_hash_warning) | |
4302 | fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link; | |
5bd4f169 | 4303 | |
50bc7936 AM |
4304 | if (fdh == NULL |
4305 | && info->shared | |
4306 | && (fh->elf.root.type == bfd_link_hash_undefined | |
4307 | || fh->elf.root.type == bfd_link_hash_undefweak)) | |
4308 | { | |
4309 | bfd *abfd; | |
4310 | asymbol *newsym; | |
4311 | struct bfd_link_hash_entry *bh; | |
4312 | ||
4313 | abfd = fh->elf.root.u.undef.abfd; | |
4314 | newsym = bfd_make_empty_symbol (abfd); | |
4315 | newsym->name = fh->elf.root.root.string + 1; | |
4316 | newsym->section = bfd_und_section_ptr; | |
4317 | newsym->value = 0; | |
4318 | newsym->flags = BSF_OBJECT; | |
4319 | if (fh->elf.root.type == bfd_link_hash_undefweak) | |
4320 | newsym->flags |= BSF_WEAK; | |
4321 | ||
4322 | bh = &fdh->elf.root; | |
4323 | if ( !(_bfd_generic_link_add_one_symbol | |
4324 | (info, abfd, newsym->name, newsym->flags, | |
4325 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) | |
648cca2c | 4326 | { |
50bc7936 | 4327 | return FALSE; |
648cca2c | 4328 | } |
50bc7936 AM |
4329 | fdh = (struct ppc_link_hash_entry *) bh; |
4330 | fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF; | |
4331 | fdh->elf.size = 24; | |
4332 | fdh->elf.type = STT_OBJECT; | |
4333 | } | |
648cca2c | 4334 | |
50bc7936 AM |
4335 | if (fdh != NULL |
4336 | && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 | |
4337 | && (info->shared | |
4338 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4339 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 | |
4340 | || (fdh->elf.root.type == bfd_link_hash_undefweak | |
4341 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) | |
4342 | { | |
4343 | if (fdh->elf.dynindx == -1) | |
4344 | if (! bfd_elf64_link_record_dynamic_symbol (info, &fdh->elf)) | |
4345 | return FALSE; | |
4346 | fdh->elf.elf_link_hash_flags | |
4347 | |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
4348 | | ELF_LINK_HASH_REF_DYNAMIC | |
4349 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
4350 | | ELF_LINK_NON_GOT_REF)); | |
4351 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) | |
e86ce104 | 4352 | { |
50bc7936 AM |
4353 | fdh->elf.plt.plist = fh->elf.plt.plist; |
4354 | fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
e86ce104 | 4355 | } |
50bc7936 AM |
4356 | fdh->is_func_descriptor = 1; |
4357 | fdh->oh = &fh->elf; | |
4358 | fh->oh = &fdh->elf; | |
e86ce104 AM |
4359 | } |
4360 | ||
50bc7936 AM |
4361 | /* Now that the info is on the function descriptor, clear the |
4362 | function code sym info. Any function code syms for which we | |
4363 | don't have a definition in a regular file, we force local. | |
4364 | This prevents a shared library from exporting syms that have | |
4365 | been imported from another library. Function code syms that | |
4366 | are really in the library we must leave global to prevent the | |
4367 | linker dragging in a definition from a static library. */ | |
4368 | force_local | |
4369 | = (info->shared | |
4370 | && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4371 | || fdh == NULL | |
4372 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4373 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)); | |
4374 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); | |
4375 | ||
b34976b6 | 4376 | return TRUE; |
e86ce104 | 4377 | } |
40b8271b | 4378 | |
82bd7b59 AM |
4379 | #define MIN_SAVE_FPR 14 |
4380 | #define MAX_SAVE_FPR 31 | |
4381 | ||
e86ce104 | 4382 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
4383 | this hook to a) provide some gcc support functions, and b) transfer |
4384 | dynamic linking information gathered so far on function code symbol | |
4385 | entries, to their corresponding function descriptor symbol entries. */ | |
b34976b6 | 4386 | static bfd_boolean |
4ce794b7 AM |
4387 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
4388 | struct bfd_link_info *info) | |
e86ce104 AM |
4389 | { |
4390 | struct ppc_link_hash_table *htab; | |
82bd7b59 AM |
4391 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
4392 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; | |
4393 | unsigned int i; | |
4394 | struct elf_link_hash_entry *h; | |
721956f4 | 4395 | bfd_byte *p; |
82bd7b59 | 4396 | char sym[10]; |
e86ce104 AM |
4397 | |
4398 | htab = ppc_hash_table (info); | |
82bd7b59 AM |
4399 | |
4400 | if (htab->sfpr == NULL) | |
4401 | /* We don't have any relocs. */ | |
b34976b6 | 4402 | return TRUE; |
82bd7b59 AM |
4403 | |
4404 | /* First provide any missing ._savef* and ._restf* functions. */ | |
4405 | memcpy (sym, "._savef14", 10); | |
4406 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4407 | { | |
4408 | sym[7] = i / 10 + '0'; | |
4409 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4410 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4411 | if (h != NULL |
772119ce | 4412 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4413 | { |
4414 | if (lowest_savef > i) | |
4415 | lowest_savef = i; | |
4416 | h->root.type = bfd_link_hash_defined; | |
4417 | h->root.u.def.section = htab->sfpr; | |
4418 | h->root.u.def.value = (i - lowest_savef) * 4; | |
4419 | h->type = STT_FUNC; | |
4420 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4421 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4422 | } |
4423 | } | |
4424 | ||
4425 | memcpy (sym, "._restf14", 10); | |
4426 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4427 | { | |
4428 | sym[7] = i / 10 + '0'; | |
4429 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4430 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4431 | if (h != NULL |
772119ce | 4432 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4433 | { |
4434 | if (lowest_restf > i) | |
4435 | lowest_restf = i; | |
4436 | h->root.type = bfd_link_hash_defined; | |
4437 | h->root.u.def.section = htab->sfpr; | |
4438 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 | |
4439 | + (i - lowest_restf) * 4); | |
4440 | h->type = STT_FUNC; | |
4441 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4442 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4443 | } |
4444 | } | |
4445 | ||
4ce794b7 | 4446 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
805fc799 | 4447 | |
82bd7b59 AM |
4448 | htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
4449 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); | |
4450 | ||
4451 | if (htab->sfpr->_raw_size == 0) | |
805fc799 AM |
4452 | { |
4453 | if (!htab->have_undefweak) | |
4454 | { | |
4455 | _bfd_strip_section_from_output (info, htab->sfpr); | |
b34976b6 | 4456 | return TRUE; |
805fc799 AM |
4457 | } |
4458 | ||
4459 | htab->sfpr->_raw_size = 4; | |
4460 | } | |
82bd7b59 | 4461 | |
4ce794b7 | 4462 | p = bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size); |
721956f4 | 4463 | if (p == NULL) |
b34976b6 | 4464 | return FALSE; |
721956f4 AM |
4465 | htab->sfpr->contents = p; |
4466 | ||
4467 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) | |
4468 | { | |
4469 | unsigned int fpr = i << 21; | |
4470 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4471 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); | |
4472 | p += 4; | |
4473 | } | |
4474 | if (lowest_savef <= MAX_SAVE_FPR) | |
4475 | { | |
82bd7b59 AM |
4476 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
4477 | p += 4; | |
721956f4 | 4478 | } |
82bd7b59 | 4479 | |
721956f4 AM |
4480 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
4481 | { | |
4482 | unsigned int fpr = i << 21; | |
4483 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4484 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); | |
82bd7b59 AM |
4485 | p += 4; |
4486 | } | |
721956f4 AM |
4487 | if (lowest_restf <= MAX_SAVE_FPR |
4488 | || htab->sfpr->_raw_size == 4) | |
4489 | { | |
4490 | bfd_put_32 (htab->elf.dynobj, BLR, p); | |
4491 | } | |
82bd7b59 | 4492 | |
b34976b6 | 4493 | return TRUE; |
e86ce104 AM |
4494 | } |
4495 | ||
4496 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
4497 | regular object. The current definition is in some section of the | |
4498 | dynamic object, but we're not including those sections. We have to | |
4499 | change the definition to something the rest of the link can | |
4500 | understand. */ | |
4501 | ||
b34976b6 | 4502 | static bfd_boolean |
4ce794b7 AM |
4503 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
4504 | struct elf_link_hash_entry *h) | |
e86ce104 AM |
4505 | { |
4506 | struct ppc_link_hash_table *htab; | |
e86ce104 AM |
4507 | asection *s; |
4508 | unsigned int power_of_two; | |
4509 | ||
4510 | htab = ppc_hash_table (info); | |
4511 | ||
4512 | /* Deal with function syms. */ | |
4513 | if (h->type == STT_FUNC | |
4514 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
4515 | { | |
4516 | /* Clear procedure linkage table information for any symbol that | |
4517 | won't need a .plt entry. */ | |
411e1bfb AM |
4518 | struct plt_entry *ent; |
4519 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4520 | if (ent->plt.refcount > 0) | |
4521 | break; | |
e86ce104 | 4522 | if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor |
411e1bfb | 4523 | || ent == NULL |
9c7a29a3 AM |
4524 | || SYMBOL_CALLS_LOCAL (info, h) |
4525 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4526 | && h->root.type == bfd_link_hash_undefweak)) | |
40b8271b | 4527 | { |
411e1bfb | 4528 | h->plt.plist = NULL; |
40b8271b | 4529 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
40b8271b | 4530 | } |
5bd4f169 | 4531 | } |
bbd7ec4a | 4532 | else |
411e1bfb | 4533 | h->plt.plist = NULL; |
5bd4f169 AM |
4534 | |
4535 | /* If this is a weak symbol, and there is a real definition, the | |
4536 | processor independent code will have arranged for us to see the | |
4537 | real definition first, and we can just use the same value. */ | |
4538 | if (h->weakdef != NULL) | |
4539 | { | |
4540 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
4541 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
4542 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
4543 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
a23b6845 AM |
4544 | if (ELIMINATE_COPY_RELOCS) |
4545 | h->elf_link_hash_flags | |
4546 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) | |
4547 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); | |
b34976b6 | 4548 | return TRUE; |
5bd4f169 AM |
4549 | } |
4550 | ||
5bd4f169 AM |
4551 | /* If we are creating a shared library, we must presume that the |
4552 | only references to the symbol are via the global offset table. | |
4553 | For such cases we need not do anything here; the relocations will | |
4554 | be handled correctly by relocate_section. */ | |
4555 | if (info->shared) | |
b34976b6 | 4556 | return TRUE; |
5bd4f169 | 4557 | |
65f38f15 AM |
4558 | /* If there are no references to this symbol that do not use the |
4559 | GOT, we don't need to generate a copy reloc. */ | |
4560 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 4561 | return TRUE; |
65f38f15 | 4562 | |
f4656909 | 4563 | if (ELIMINATE_COPY_RELOCS) |
65f38f15 | 4564 | { |
f4656909 AM |
4565 | struct ppc_link_hash_entry * eh; |
4566 | struct ppc_dyn_relocs *p; | |
65f38f15 | 4567 | |
f4656909 AM |
4568 | eh = (struct ppc_link_hash_entry *) h; |
4569 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4570 | { | |
4571 | s = p->sec->output_section; | |
4572 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
4573 | break; | |
4574 | } | |
4575 | ||
4576 | /* If we didn't find any dynamic relocs in read-only sections, then | |
4577 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
4578 | if (p == NULL) | |
4579 | { | |
4580 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
4581 | return TRUE; | |
4582 | } | |
65f38f15 AM |
4583 | } |
4584 | ||
5d35169e | 4585 | if (h->plt.plist != NULL) |
97b639ba AM |
4586 | { |
4587 | /* We should never get here, but unfortunately there are versions | |
4588 | of gcc out there that improperly (for this ABI) put initialized | |
4589 | function pointers, vtable refs and suchlike in read-only | |
4590 | sections. Allow them to proceed, but warn that this might | |
4591 | break at runtime. */ | |
4592 | (*_bfd_error_handler) | |
4593 | (_("copy reloc against `%s' requires lazy plt linking; " | |
4594 | "avoid setting LD_BIND_NOW=1 or upgrade gcc"), | |
4595 | h->root.root.string); | |
4596 | } | |
5d35169e AM |
4597 | |
4598 | /* This is a reference to a symbol defined by a dynamic object which | |
4599 | is not a function. */ | |
4600 | ||
5bd4f169 AM |
4601 | /* We must allocate the symbol in our .dynbss section, which will |
4602 | become part of the .bss section of the executable. There will be | |
4603 | an entry for this symbol in the .dynsym section. The dynamic | |
4604 | object will contain position independent code, so all references | |
4605 | from the dynamic object to this symbol will go through the global | |
4606 | offset table. The dynamic linker will use the .dynsym entry to | |
4607 | determine the address it must put in the global offset table, so | |
4608 | both the dynamic object and the regular object will refer to the | |
4609 | same memory location for the variable. */ | |
5bd4f169 | 4610 | |
04c9666a AM |
4611 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
4612 | to copy the initial value out of the dynamic object and into the | |
5bd4f169 AM |
4613 | runtime process image. We need to remember the offset into the |
4614 | .rela.bss section we are going to use. */ | |
4615 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
4616 | { | |
4ce794b7 | 4617 | htab->relbss->_raw_size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
4618 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
4619 | } | |
4620 | ||
4621 | /* We need to figure out the alignment required for this symbol. I | |
4622 | have no idea how ELF linkers handle this. */ | |
4623 | power_of_two = bfd_log2 (h->size); | |
4624 | if (power_of_two > 4) | |
4625 | power_of_two = 4; | |
4626 | ||
4627 | /* Apply the required alignment. */ | |
4ce794b7 | 4628 | s = htab->dynbss; |
65f38f15 AM |
4629 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); |
4630 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
5bd4f169 | 4631 | { |
65f38f15 | 4632 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 4633 | return FALSE; |
5bd4f169 AM |
4634 | } |
4635 | ||
4636 | /* Define the symbol as being at this point in the section. */ | |
4637 | h->root.u.def.section = s; | |
4638 | h->root.u.def.value = s->_raw_size; | |
4639 | ||
4640 | /* Increment the section size to make room for the symbol. */ | |
4641 | s->_raw_size += h->size; | |
4642 | ||
b34976b6 | 4643 | return TRUE; |
5bd4f169 AM |
4644 | } |
4645 | ||
e86ce104 AM |
4646 | /* If given a function descriptor symbol, hide both the function code |
4647 | sym and the descriptor. */ | |
4648 | static void | |
4ce794b7 AM |
4649 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
4650 | struct elf_link_hash_entry *h, | |
4651 | bfd_boolean force_local) | |
e86ce104 AM |
4652 | { |
4653 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); | |
4654 | ||
4655 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) | |
4656 | { | |
721956f4 | 4657 | struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh; |
e86ce104 | 4658 | |
721956f4 | 4659 | if (fh == NULL) |
d1329ca3 AM |
4660 | { |
4661 | const char *p, *q; | |
4662 | struct ppc_link_hash_table *htab; | |
4663 | char save; | |
4664 | ||
4665 | /* We aren't supposed to use alloca in BFD because on | |
4666 | systems which do not have alloca the version in libiberty | |
4667 | calls xmalloc, which might cause the program to crash | |
4668 | when it runs out of memory. This function doesn't have a | |
4669 | return status, so there's no way to gracefully return an | |
4670 | error. So cheat. We know that string[-1] can be safely | |
4671 | dereferenced; It's either a string in an ELF string | |
4672 | table, or allocated in an objalloc structure. */ | |
4673 | ||
4674 | p = h->root.root.string - 1; | |
4675 | save = *p; | |
4676 | *(char *) p = '.'; | |
4677 | htab = ppc_hash_table (info); | |
b34976b6 | 4678 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
4679 | *(char *) p = save; |
4680 | ||
4681 | /* Unfortunately, if it so happens that the string we were | |
4682 | looking for was allocated immediately before this string, | |
4683 | then we overwrote the string terminator. That's the only | |
4684 | reason the lookup should fail. */ | |
4685 | if (fh == NULL) | |
4686 | { | |
4687 | q = h->root.root.string + strlen (h->root.root.string); | |
4688 | while (q >= h->root.root.string && *q == *p) | |
4689 | --q, --p; | |
4690 | if (q < h->root.root.string && *p == '.') | |
b34976b6 | 4691 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
4692 | } |
4693 | if (fh != NULL) | |
4694 | { | |
4695 | ((struct ppc_link_hash_entry *) h)->oh = fh; | |
4696 | ((struct ppc_link_hash_entry *) fh)->oh = h; | |
4697 | } | |
4698 | } | |
e86ce104 AM |
4699 | if (fh != NULL) |
4700 | _bfd_elf_link_hash_hide_symbol (info, fh, force_local); | |
4701 | } | |
4702 | } | |
4703 | ||
411e1bfb | 4704 | static bfd_boolean |
4ce794b7 AM |
4705 | get_sym_h (struct elf_link_hash_entry **hp, Elf_Internal_Sym **symp, |
4706 | asection **symsecp, char **tls_maskp, Elf_Internal_Sym **locsymsp, | |
4707 | unsigned long r_symndx, bfd *ibfd) | |
411e1bfb AM |
4708 | { |
4709 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
4710 | ||
4711 | if (r_symndx >= symtab_hdr->sh_info) | |
4712 | { | |
4713 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
4714 | struct elf_link_hash_entry *h; | |
4715 | ||
4716 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4717 | while (h->root.type == bfd_link_hash_indirect | |
4718 | || h->root.type == bfd_link_hash_warning) | |
4719 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4720 | ||
4721 | if (hp != NULL) | |
4722 | *hp = h; | |
4723 | ||
4724 | if (symp != NULL) | |
4725 | *symp = NULL; | |
4726 | ||
4727 | if (symsecp != NULL) | |
4728 | { | |
4729 | asection *symsec = NULL; | |
4730 | if (h->root.type == bfd_link_hash_defined | |
4731 | || h->root.type == bfd_link_hash_defweak) | |
4732 | symsec = h->root.u.def.section; | |
4733 | *symsecp = symsec; | |
4734 | } | |
4735 | ||
e7b938ca | 4736 | if (tls_maskp != NULL) |
411e1bfb AM |
4737 | { |
4738 | struct ppc_link_hash_entry *eh; | |
4739 | ||
4740 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 4741 | *tls_maskp = &eh->tls_mask; |
411e1bfb AM |
4742 | } |
4743 | } | |
4744 | else | |
4745 | { | |
4746 | Elf_Internal_Sym *sym; | |
4747 | Elf_Internal_Sym *locsyms = *locsymsp; | |
4748 | ||
4749 | if (locsyms == NULL) | |
4750 | { | |
4751 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4752 | if (locsyms == NULL) | |
4753 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
4754 | symtab_hdr->sh_info, | |
4755 | 0, NULL, NULL, NULL); | |
4756 | if (locsyms == NULL) | |
4757 | return FALSE; | |
4758 | *locsymsp = locsyms; | |
4759 | } | |
4760 | sym = locsyms + r_symndx; | |
4761 | ||
4762 | if (hp != NULL) | |
4763 | *hp = NULL; | |
4764 | ||
4765 | if (symp != NULL) | |
4766 | *symp = sym; | |
4767 | ||
4768 | if (symsecp != NULL) | |
4769 | { | |
4770 | asection *symsec = NULL; | |
4771 | if ((sym->st_shndx != SHN_UNDEF | |
4772 | && sym->st_shndx < SHN_LORESERVE) | |
4773 | || sym->st_shndx > SHN_HIRESERVE) | |
4774 | symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); | |
4775 | *symsecp = symsec; | |
4776 | } | |
4777 | ||
e7b938ca | 4778 | if (tls_maskp != NULL) |
411e1bfb AM |
4779 | { |
4780 | struct got_entry **lgot_ents; | |
e7b938ca | 4781 | char *tls_mask; |
411e1bfb | 4782 | |
e7b938ca | 4783 | tls_mask = NULL; |
411e1bfb AM |
4784 | lgot_ents = elf_local_got_ents (ibfd); |
4785 | if (lgot_ents != NULL) | |
4786 | { | |
e7b938ca AM |
4787 | char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info); |
4788 | tls_mask = &lgot_masks[r_symndx]; | |
411e1bfb | 4789 | } |
e7b938ca | 4790 | *tls_maskp = tls_mask; |
411e1bfb AM |
4791 | } |
4792 | } | |
4793 | return TRUE; | |
4794 | } | |
4795 | ||
e7b938ca | 4796 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
951fd09b | 4797 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
ad8e1ba5 | 4798 | type suitable for optimization, and 1 otherwise. */ |
951fd09b AM |
4799 | |
4800 | static int | |
4ce794b7 AM |
4801 | get_tls_mask (char **tls_maskp, Elf_Internal_Sym **locsymsp, |
4802 | const Elf_Internal_Rela *rel, bfd *ibfd) | |
411e1bfb AM |
4803 | { |
4804 | unsigned long r_symndx; | |
951fd09b | 4805 | unsigned int next_r; |
411e1bfb AM |
4806 | struct elf_link_hash_entry *h; |
4807 | Elf_Internal_Sym *sym; | |
4808 | asection *sec; | |
4809 | bfd_vma off; | |
4810 | ||
4811 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 4812 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 4813 | return 0; |
411e1bfb | 4814 | |
e7b938ca | 4815 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
411e1bfb AM |
4816 | || sec == NULL |
4817 | || ppc64_elf_section_data (sec)->t_symndx == NULL) | |
951fd09b | 4818 | return 1; |
411e1bfb AM |
4819 | |
4820 | /* Look inside a TOC section too. */ | |
4821 | if (h != NULL) | |
4822 | { | |
4823 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
4824 | off = h->root.u.def.value; | |
4825 | } | |
4826 | else | |
4827 | off = sym->st_value; | |
4828 | off += rel->r_addend; | |
4829 | BFD_ASSERT (off % 8 == 0); | |
4830 | r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8]; | |
951fd09b | 4831 | next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1]; |
e7b938ca | 4832 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b AM |
4833 | return 0; |
4834 | if (h == NULL | |
4835 | || h->root.type == bfd_link_hash_defined | |
4836 | || h->root.type == bfd_link_hash_defweak) | |
4837 | { | |
4838 | if (next_r == (unsigned) -1) | |
4839 | return 2; | |
4840 | if (next_r == (unsigned) -2 | |
4841 | && (h == NULL | |
4842 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
4843 | return 3; | |
4844 | } | |
4845 | return 1; | |
411e1bfb AM |
4846 | } |
4847 | ||
b34976b6 | 4848 | bfd_boolean |
4ce794b7 | 4849 | ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info) |
1e2f5b6e AM |
4850 | { |
4851 | bfd *ibfd; | |
1e2f5b6e | 4852 | |
411e1bfb | 4853 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1e2f5b6e AM |
4854 | { |
4855 | asection *sec; | |
4856 | Elf_Internal_Rela *relstart, *rel, *relend; | |
4857 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 4858 | Elf_Internal_Sym *local_syms; |
1e2f5b6e AM |
4859 | struct elf_link_hash_entry **sym_hashes; |
4860 | bfd_vma offset; | |
d6fe2dc1 | 4861 | bfd_size_type amt; |
1e2f5b6e | 4862 | long *adjust; |
b34976b6 | 4863 | bfd_boolean need_edit; |
1e2f5b6e AM |
4864 | |
4865 | sec = bfd_get_section_by_name (ibfd, ".opd"); | |
4866 | if (sec == NULL) | |
4867 | continue; | |
4868 | ||
d6fe2dc1 | 4869 | amt = sec->_raw_size * sizeof (long) / 24; |
f0abc2a1 | 4870 | adjust = ppc64_elf_section_data (sec)->opd.adjust; |
d6fe2dc1 AM |
4871 | if (adjust == NULL) |
4872 | { | |
4873 | /* Must be a ld -r link. ie. check_relocs hasn't been | |
4874 | called. */ | |
4ce794b7 | 4875 | adjust = bfd_zalloc (obfd, amt); |
f0abc2a1 | 4876 | ppc64_elf_section_data (sec)->opd.adjust = adjust; |
d6fe2dc1 | 4877 | } |
4ce794b7 | 4878 | memset (adjust, 0, amt); |
1e2f5b6e AM |
4879 | |
4880 | if (sec->output_section == bfd_abs_section_ptr) | |
4881 | continue; | |
4882 | ||
4883 | /* Look through the section relocs. */ | |
4884 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
4885 | continue; | |
4886 | ||
6cdc0ccc | 4887 | local_syms = NULL; |
1e2f5b6e AM |
4888 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
4889 | sym_hashes = elf_sym_hashes (ibfd); | |
4890 | ||
4891 | /* Read the relocations. */ | |
4ce794b7 | 4892 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 4893 | info->keep_memory); |
1e2f5b6e | 4894 | if (relstart == NULL) |
b34976b6 | 4895 | return FALSE; |
1e2f5b6e AM |
4896 | |
4897 | /* First run through the relocs to check they are sane, and to | |
4898 | determine whether we need to edit this opd section. */ | |
b34976b6 | 4899 | need_edit = FALSE; |
1e2f5b6e AM |
4900 | offset = 0; |
4901 | relend = relstart + sec->reloc_count; | |
50bc7936 | 4902 | for (rel = relstart; rel < relend; ) |
1e2f5b6e | 4903 | { |
04c9666a | 4904 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e AM |
4905 | unsigned long r_symndx; |
4906 | asection *sym_sec; | |
4907 | struct elf_link_hash_entry *h; | |
4908 | Elf_Internal_Sym *sym; | |
4909 | ||
4910 | /* .opd contains a regular array of 24 byte entries. We're | |
4911 | only interested in the reloc pointing to a function entry | |
4912 | point. */ | |
50bc7936 AM |
4913 | if (rel->r_offset != offset |
4914 | || rel + 1 >= relend | |
4915 | || (rel + 1)->r_offset != offset + 8) | |
1e2f5b6e AM |
4916 | { |
4917 | /* If someone messes with .opd alignment then after a | |
4918 | "ld -r" we might have padding in the middle of .opd. | |
4919 | Also, there's nothing to prevent someone putting | |
4920 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 4921 | optimization for them! */ |
1e2f5b6e AM |
4922 | (*_bfd_error_handler) |
4923 | (_("%s: .opd is not a regular array of opd entries"), | |
4924 | bfd_archive_filename (ibfd)); | |
b34976b6 | 4925 | need_edit = FALSE; |
1e2f5b6e AM |
4926 | break; |
4927 | } | |
4928 | ||
50bc7936 AM |
4929 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
4930 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) | |
4931 | { | |
4932 | (*_bfd_error_handler) | |
4933 | (_("%s: unexpected reloc type %u in .opd section"), | |
4934 | bfd_archive_filename (ibfd), r_type); | |
4935 | need_edit = FALSE; | |
4936 | break; | |
4937 | } | |
4938 | ||
1e2f5b6e | 4939 | r_symndx = ELF64_R_SYM (rel->r_info); |
411e1bfb AM |
4940 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
4941 | r_symndx, ibfd)) | |
50bc7936 | 4942 | goto error_ret; |
1e2f5b6e AM |
4943 | |
4944 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
4945 | { | |
411e1bfb AM |
4946 | const char *sym_name; |
4947 | if (h != NULL) | |
4948 | sym_name = h->root.root.string; | |
4949 | else | |
4950 | sym_name = bfd_elf_local_sym_name (ibfd, sym); | |
4951 | ||
1e2f5b6e AM |
4952 | (*_bfd_error_handler) |
4953 | (_("%s: undefined sym `%s' in .opd section"), | |
4954 | bfd_archive_filename (ibfd), | |
411e1bfb | 4955 | sym_name); |
b34976b6 | 4956 | need_edit = FALSE; |
1e2f5b6e AM |
4957 | break; |
4958 | } | |
4959 | ||
51020317 AM |
4960 | /* opd entries are always for functions defined in the |
4961 | current input bfd. If the symbol isn't defined in the | |
4962 | input bfd, then we won't be using the function in this | |
4963 | bfd; It must be defined in a linkonce section in another | |
4964 | bfd, or is weak. It's also possible that we are | |
4965 | discarding the function due to a linker script /DISCARD/, | |
4966 | which we test for via the output_section. */ | |
4967 | if (sym_sec->owner != ibfd | |
4968 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 4969 | need_edit = TRUE; |
1e2f5b6e AM |
4970 | |
4971 | offset += 24; | |
50bc7936 AM |
4972 | rel += 2; |
4973 | /* Allow for the possibility of a reloc on the third word. */ | |
4974 | if (rel < relend | |
4975 | && rel->r_offset == offset - 8) | |
4976 | rel += 1; | |
1e2f5b6e AM |
4977 | } |
4978 | ||
4979 | if (need_edit) | |
4980 | { | |
4981 | Elf_Internal_Rela *write_rel; | |
4982 | bfd_byte *rptr, *wptr; | |
b34976b6 | 4983 | bfd_boolean skip; |
1e2f5b6e AM |
4984 | |
4985 | /* This seems a waste of time as input .opd sections are all | |
4986 | zeros as generated by gcc, but I suppose there's no reason | |
4987 | this will always be so. We might start putting something in | |
4988 | the third word of .opd entries. */ | |
4989 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
4990 | { | |
4991 | bfd_byte *loc = bfd_alloc (ibfd, sec->_raw_size); | |
6cdc0ccc | 4992 | if (loc == NULL |
4ce794b7 | 4993 | || !bfd_get_section_contents (ibfd, sec, loc, 0, |
6cdc0ccc AM |
4994 | sec->_raw_size)) |
4995 | { | |
50bc7936 | 4996 | error_ret: |
6cdc0ccc AM |
4997 | if (local_syms != NULL |
4998 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
4999 | free (local_syms); | |
6cdc0ccc AM |
5000 | if (elf_section_data (sec)->relocs != relstart) |
5001 | free (relstart); | |
b34976b6 | 5002 | return FALSE; |
6cdc0ccc | 5003 | } |
1e2f5b6e AM |
5004 | sec->contents = loc; |
5005 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
5006 | } | |
5007 | ||
5008 | elf_section_data (sec)->relocs = relstart; | |
5009 | ||
5010 | wptr = sec->contents; | |
5011 | rptr = sec->contents; | |
5012 | write_rel = relstart; | |
b34976b6 | 5013 | skip = FALSE; |
1e2f5b6e AM |
5014 | offset = 0; |
5015 | for (rel = relstart; rel < relend; rel++) | |
5016 | { | |
50bc7936 AM |
5017 | unsigned long r_symndx; |
5018 | asection *sym_sec; | |
5019 | struct elf_link_hash_entry *h; | |
5020 | Elf_Internal_Sym *sym; | |
5021 | ||
5022 | r_symndx = ELF64_R_SYM (rel->r_info); | |
5023 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
5024 | r_symndx, ibfd)) | |
5025 | goto error_ret; | |
5026 | ||
1e2f5b6e AM |
5027 | if (rel->r_offset == offset) |
5028 | { | |
50bc7936 AM |
5029 | struct ppc_link_hash_entry *fdh = NULL; |
5030 | if (h != NULL) | |
5031 | fdh = get_fdh ((struct ppc_link_hash_entry *) h, | |
5032 | ppc_hash_table (info)); | |
1e2f5b6e | 5033 | |
51020317 AM |
5034 | skip = (sym_sec->owner != ibfd |
5035 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
5036 | if (skip) |
5037 | { | |
0be617ce | 5038 | if (h != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
5039 | { |
5040 | /* Arrange for the function descriptor sym | |
5041 | to be dropped. */ | |
d6fe2dc1 AM |
5042 | fdh->elf.root.u.def.value = 0; |
5043 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 AM |
5044 | } |
5045 | } | |
5046 | else | |
1e2f5b6e AM |
5047 | { |
5048 | /* We'll be keeping this opd entry. */ | |
5049 | ||
5050 | if (h != NULL) | |
5051 | { | |
5052 | /* Redefine the function descriptor symbol | |
5053 | to this location in the opd section. | |
5054 | We've checked above that opd relocs are | |
5055 | ordered. */ | |
d6fe2dc1 | 5056 | fdh->elf.root.u.def.value = wptr - sec->contents; |
1e2f5b6e AM |
5057 | } |
5058 | else | |
5059 | { | |
6cdc0ccc AM |
5060 | /* Local syms are a bit tricky. We could |
5061 | tweak them as they can be cached, but | |
5062 | we'd need to look through the local syms | |
5063 | for the function descriptor sym which we | |
5064 | don't have at the moment. So keep an | |
b34976b6 | 5065 | array of adjustments. */ |
7f6a7663 | 5066 | adjust[rel->r_offset / 24] = wptr - rptr; |
1e2f5b6e AM |
5067 | } |
5068 | ||
5069 | if (wptr != rptr) | |
5070 | memcpy (wptr, rptr, 24); | |
5071 | wptr += 24; | |
5072 | } | |
5073 | rptr += 24; | |
5074 | offset += 24; | |
5075 | } | |
5076 | ||
50bc7936 AM |
5077 | if (skip) |
5078 | { | |
5079 | BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info))); | |
5080 | if (info->shared) | |
5081 | { | |
5082 | /* We won't be needing dynamic relocs here. */ | |
5083 | struct ppc_dyn_relocs **pp; | |
5084 | struct ppc_dyn_relocs *p; | |
5085 | ||
5086 | if (h != NULL) | |
5087 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; | |
5088 | else if (sym_sec != NULL) | |
5089 | pp = ((struct ppc_dyn_relocs **) | |
5090 | &elf_section_data (sym_sec)->local_dynrel); | |
5091 | else | |
5092 | pp = ((struct ppc_dyn_relocs **) | |
5093 | &elf_section_data (sec)->local_dynrel); | |
5094 | while ((p = *pp) != NULL) | |
5095 | { | |
5096 | if (p->sec == sec) | |
5097 | { | |
5098 | p->count -= 1; | |
5099 | if (p->count == 0) | |
5100 | *pp = p->next; | |
5101 | break; | |
5102 | } | |
5103 | pp = &p->next; | |
5104 | } | |
5105 | } | |
5106 | } | |
5107 | else | |
1e2f5b6e | 5108 | { |
50bc7936 AM |
5109 | /* We need to adjust any reloc offsets to point to the |
5110 | new opd entries. While we're at it, we may as well | |
5111 | remove redundant relocs. */ | |
1e2f5b6e AM |
5112 | rel->r_offset += wptr - rptr; |
5113 | if (write_rel != rel) | |
5114 | memcpy (write_rel, rel, sizeof (*rel)); | |
5115 | ++write_rel; | |
5116 | } | |
5117 | } | |
5118 | ||
5119 | sec->_cooked_size = wptr - sec->contents; | |
5120 | sec->reloc_count = write_rel - relstart; | |
cdcf6e38 AM |
5121 | /* Fudge the size too, as this is used later in |
5122 | elf_bfd_final_link if we are emitting relocs. */ | |
5123 | elf_section_data (sec)->rel_hdr.sh_size | |
5124 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; | |
5125 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); | |
1e2f5b6e | 5126 | } |
6cdc0ccc | 5127 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 5128 | free (relstart); |
6cdc0ccc | 5129 | |
411e1bfb AM |
5130 | if (local_syms != NULL |
5131 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5132 | { | |
5133 | if (!info->keep_memory) | |
5134 | free (local_syms); | |
5135 | else | |
5136 | symtab_hdr->contents = (unsigned char *) local_syms; | |
5137 | } | |
5138 | } | |
5139 | ||
5140 | return TRUE; | |
5141 | } | |
5142 | ||
951fd09b | 5143 | /* Set htab->tls_sec. */ |
411e1bfb AM |
5144 | |
5145 | bfd_boolean | |
4ce794b7 | 5146 | ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
411e1bfb AM |
5147 | { |
5148 | asection *tls; | |
411e1bfb AM |
5149 | struct ppc_link_hash_table *htab; |
5150 | ||
411e1bfb AM |
5151 | for (tls = obfd->sections; tls != NULL; tls = tls->next) |
5152 | if ((tls->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) | |
5153 | == (SEC_THREAD_LOCAL | SEC_LOAD)) | |
5154 | break; | |
411e1bfb AM |
5155 | |
5156 | htab = ppc_hash_table (info); | |
5157 | htab->tls_sec = tls; | |
a48ebf4d AM |
5158 | |
5159 | if (htab->tls_get_addr != NULL) | |
5160 | { | |
5161 | struct elf_link_hash_entry *h = htab->tls_get_addr; | |
5162 | ||
5163 | while (h->root.type == bfd_link_hash_indirect | |
5164 | || h->root.type == bfd_link_hash_warning) | |
5165 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5166 | ||
5167 | htab->tls_get_addr = h; | |
5168 | } | |
5169 | ||
951fd09b AM |
5170 | return tls != NULL; |
5171 | } | |
411e1bfb | 5172 | |
951fd09b AM |
5173 | /* Run through all the TLS relocs looking for optimization |
5174 | opportunities. The linker has been hacked (see ppc64elf.em) to do | |
5175 | a preliminary section layout so that we know the TLS segment | |
5176 | offsets. We can't optimize earlier because some optimizations need | |
5177 | to know the tp offset, and we need to optimize before allocating | |
5178 | dynamic relocations. */ | |
5179 | ||
5180 | bfd_boolean | |
4ce794b7 | 5181 | ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) |
951fd09b AM |
5182 | { |
5183 | bfd *ibfd; | |
5184 | asection *sec; | |
5185 | struct ppc_link_hash_table *htab; | |
5186 | ||
1049f94e | 5187 | if (info->relocatable || info->shared) |
411e1bfb AM |
5188 | return TRUE; |
5189 | ||
951fd09b | 5190 | htab = ppc_hash_table (info); |
411e1bfb AM |
5191 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5192 | { | |
5193 | Elf_Internal_Sym *locsyms = NULL; | |
5194 | ||
5195 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
5196 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
5197 | { | |
5198 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5199 | int expecting_tls_get_addr; | |
5200 | ||
5201 | /* Read the relocations. */ | |
4ce794b7 | 5202 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5203 | info->keep_memory); |
411e1bfb AM |
5204 | if (relstart == NULL) |
5205 | return FALSE; | |
5206 | ||
5207 | expecting_tls_get_addr = 0; | |
5208 | relend = relstart + sec->reloc_count; | |
5209 | for (rel = relstart; rel < relend; rel++) | |
5210 | { | |
5211 | enum elf_ppc64_reloc_type r_type; | |
5212 | unsigned long r_symndx; | |
5213 | struct elf_link_hash_entry *h; | |
5214 | Elf_Internal_Sym *sym; | |
5215 | asection *sym_sec; | |
e7b938ca AM |
5216 | char *tls_mask; |
5217 | char tls_set, tls_clear, tls_type = 0; | |
411e1bfb | 5218 | bfd_vma value; |
951fd09b | 5219 | bfd_boolean ok_tprel, is_local; |
411e1bfb AM |
5220 | |
5221 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5222 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, |
411e1bfb AM |
5223 | r_symndx, ibfd)) |
5224 | { | |
5225 | err_free_rel: | |
5226 | if (elf_section_data (sec)->relocs != relstart) | |
5227 | free (relstart); | |
5228 | if (locsyms != NULL | |
5229 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5230 | != (unsigned char *) locsyms)) | |
5231 | free (locsyms); | |
5232 | return FALSE; | |
5233 | } | |
5234 | ||
5235 | if (h != NULL) | |
5236 | { | |
5237 | if (h->root.type != bfd_link_hash_defined | |
5238 | && h->root.type != bfd_link_hash_defweak) | |
5239 | continue; | |
5240 | value = h->root.u.def.value; | |
5241 | } | |
5242 | else | |
5243 | value = sym->st_value; | |
951fd09b | 5244 | |
411e1bfb | 5245 | ok_tprel = FALSE; |
951fd09b AM |
5246 | is_local = FALSE; |
5247 | if (h == NULL | |
5248 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5249 | { |
951fd09b | 5250 | is_local = TRUE; |
411e1bfb AM |
5251 | value += sym_sec->output_offset; |
5252 | value += sym_sec->output_section->vma; | |
5253 | value -= htab->tls_sec->vma; | |
5254 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) | |
5255 | < (bfd_vma) 1 << 32); | |
5256 | } | |
5257 | ||
4ce794b7 | 5258 | r_type = ELF64_R_TYPE (rel->r_info); |
411e1bfb AM |
5259 | switch (r_type) |
5260 | { | |
5261 | case R_PPC64_GOT_TLSLD16: | |
5262 | case R_PPC64_GOT_TLSLD16_LO: | |
5263 | case R_PPC64_GOT_TLSLD16_HI: | |
5264 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b AM |
5265 | /* These relocs should never be against a symbol |
5266 | defined in a shared lib. Leave them alone if | |
5267 | that turns out to be the case. */ | |
e717da7e | 5268 | ppc64_tlsld_got (ibfd)->refcount -= 1; |
951fd09b AM |
5269 | if (!is_local) |
5270 | continue; | |
5271 | ||
951fd09b AM |
5272 | /* LD -> LE */ |
5273 | tls_set = 0; | |
5274 | tls_clear = TLS_LD; | |
e7b938ca | 5275 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
5276 | expecting_tls_get_addr = 1; |
5277 | break; | |
5278 | ||
5279 | case R_PPC64_GOT_TLSGD16: | |
5280 | case R_PPC64_GOT_TLSGD16_LO: | |
5281 | case R_PPC64_GOT_TLSGD16_HI: | |
5282 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 5283 | if (ok_tprel) |
411e1bfb AM |
5284 | /* GD -> LE */ |
5285 | tls_set = 0; | |
5286 | else | |
5287 | /* GD -> IE */ | |
951fd09b AM |
5288 | tls_set = TLS_TLS | TLS_TPRELGD; |
5289 | tls_clear = TLS_GD; | |
e7b938ca | 5290 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
5291 | expecting_tls_get_addr = 1; |
5292 | break; | |
5293 | ||
5294 | case R_PPC64_GOT_TPREL16_DS: | |
5295 | case R_PPC64_GOT_TPREL16_LO_DS: | |
5296 | case R_PPC64_GOT_TPREL16_HI: | |
5297 | case R_PPC64_GOT_TPREL16_HA: | |
5298 | expecting_tls_get_addr = 0; | |
5299 | if (ok_tprel) | |
5300 | { | |
5301 | /* IE -> LE */ | |
5302 | tls_set = 0; | |
5303 | tls_clear = TLS_TPREL; | |
e7b938ca | 5304 | tls_type = TLS_TLS | TLS_TPREL; |
411e1bfb AM |
5305 | break; |
5306 | } | |
5307 | else | |
5308 | continue; | |
5309 | ||
5310 | case R_PPC64_REL14: | |
5311 | case R_PPC64_REL14_BRTAKEN: | |
5312 | case R_PPC64_REL14_BRNTAKEN: | |
5313 | case R_PPC64_REL24: | |
5314 | if (h != NULL | |
5315 | && h == htab->tls_get_addr) | |
5316 | { | |
5317 | if (!expecting_tls_get_addr | |
5318 | && rel != relstart | |
5319 | && ((ELF64_R_TYPE (rel[-1].r_info) | |
5320 | == R_PPC64_TOC16) | |
5321 | || (ELF64_R_TYPE (rel[-1].r_info) | |
5322 | == R_PPC64_TOC16_LO))) | |
5323 | { | |
5324 | /* Check for toc tls entries. */ | |
5325 | char *toc_tls; | |
951fd09b | 5326 | int retval; |
411e1bfb | 5327 | |
e7b938ca | 5328 | retval = get_tls_mask (&toc_tls, &locsyms, |
951fd09b AM |
5329 | rel - 1, ibfd); |
5330 | if (retval == 0) | |
411e1bfb AM |
5331 | goto err_free_rel; |
5332 | if (toc_tls != NULL) | |
951fd09b | 5333 | expecting_tls_get_addr = retval > 1; |
411e1bfb AM |
5334 | } |
5335 | ||
5336 | if (expecting_tls_get_addr) | |
5337 | { | |
5338 | struct plt_entry *ent; | |
5339 | for (ent = h->plt.plist; ent; ent = ent->next) | |
5340 | if (ent->addend == 0) | |
5341 | { | |
5342 | if (ent->plt.refcount > 0) | |
5343 | ent->plt.refcount -= 1; | |
5344 | break; | |
5345 | } | |
5346 | } | |
5347 | } | |
5348 | expecting_tls_get_addr = 0; | |
5349 | continue; | |
5350 | ||
5351 | case R_PPC64_TPREL64: | |
5352 | expecting_tls_get_addr = 0; | |
5353 | if (ok_tprel) | |
5354 | { | |
5355 | /* IE -> LE */ | |
5356 | tls_set = TLS_EXPLICIT; | |
5357 | tls_clear = TLS_TPREL; | |
5358 | break; | |
5359 | } | |
5360 | else | |
5361 | continue; | |
5362 | ||
5363 | case R_PPC64_DTPMOD64: | |
5364 | expecting_tls_get_addr = 0; | |
951fd09b AM |
5365 | if (rel + 1 < relend |
5366 | && (rel[1].r_info | |
5367 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) | |
5368 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 5369 | { |
951fd09b | 5370 | if (ok_tprel) |
411e1bfb | 5371 | /* GD -> LE */ |
951fd09b | 5372 | tls_set = TLS_EXPLICIT | TLS_GD; |
411e1bfb AM |
5373 | else |
5374 | /* GD -> IE */ | |
951fd09b AM |
5375 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; |
5376 | tls_clear = TLS_GD; | |
411e1bfb AM |
5377 | } |
5378 | else | |
5379 | { | |
951fd09b AM |
5380 | if (!is_local) |
5381 | continue; | |
5382 | ||
5383 | /* LD -> LE */ | |
5384 | tls_set = TLS_EXPLICIT; | |
5385 | tls_clear = TLS_LD; | |
411e1bfb AM |
5386 | } |
5387 | break; | |
5388 | ||
5389 | default: | |
5390 | expecting_tls_get_addr = 0; | |
5391 | continue; | |
5392 | } | |
5393 | ||
5394 | if ((tls_set & TLS_EXPLICIT) == 0) | |
5395 | { | |
5396 | struct got_entry *ent; | |
5397 | ||
5398 | /* Adjust got entry for this reloc. */ | |
5399 | if (h != NULL) | |
5400 | ent = h->got.glist; | |
5401 | else | |
5402 | ent = elf_local_got_ents (ibfd)[r_symndx]; | |
5403 | ||
5404 | for (; ent != NULL; ent = ent->next) | |
5405 | if (ent->addend == rel->r_addend | |
e717da7e | 5406 | && ent->owner == ibfd |
e7b938ca | 5407 | && ent->tls_type == tls_type) |
411e1bfb AM |
5408 | break; |
5409 | if (ent == NULL) | |
5410 | abort (); | |
5411 | ||
5412 | if (tls_set == 0) | |
5413 | { | |
5414 | /* We managed to get rid of a got entry. */ | |
5415 | if (ent->got.refcount > 0) | |
5416 | ent->got.refcount -= 1; | |
5417 | } | |
411e1bfb AM |
5418 | } |
5419 | else if (h != NULL) | |
5420 | { | |
5421 | struct ppc_link_hash_entry * eh; | |
5422 | struct ppc_dyn_relocs **pp; | |
5423 | struct ppc_dyn_relocs *p; | |
5424 | ||
5425 | /* Adjust dynamic relocs. */ | |
5426 | eh = (struct ppc_link_hash_entry *) h; | |
5427 | for (pp = &eh->dyn_relocs; | |
5428 | (p = *pp) != NULL; | |
5429 | pp = &p->next) | |
5430 | if (p->sec == sec) | |
5431 | { | |
5432 | /* If we got rid of a DTPMOD/DTPREL reloc | |
5433 | pair then we'll lose one or two dyn | |
5434 | relocs. */ | |
951fd09b | 5435 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
411e1bfb | 5436 | p->count -= 1; |
951fd09b | 5437 | p->count -= 1; |
411e1bfb AM |
5438 | if (p->count == 0) |
5439 | *pp = p->next; | |
5440 | break; | |
5441 | } | |
5442 | } | |
5443 | ||
e7b938ca AM |
5444 | *tls_mask |= tls_set; |
5445 | *tls_mask &= ~tls_clear; | |
411e1bfb AM |
5446 | } |
5447 | ||
5448 | if (elf_section_data (sec)->relocs != relstart) | |
5449 | free (relstart); | |
5450 | } | |
5451 | ||
5452 | if (locsyms != NULL | |
5453 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5454 | != (unsigned char *) locsyms)) | |
6cdc0ccc AM |
5455 | { |
5456 | if (!info->keep_memory) | |
411e1bfb | 5457 | free (locsyms); |
6cdc0ccc | 5458 | else |
411e1bfb | 5459 | elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; |
6cdc0ccc | 5460 | } |
1e2f5b6e | 5461 | } |
b34976b6 | 5462 | return TRUE; |
1e2f5b6e | 5463 | } |
b34976b6 | 5464 | |
65f38f15 AM |
5465 | /* This is the condition under which ppc64_elf_finish_dynamic_symbol |
5466 | will be called from elflink.h. If elflink.h doesn't call our | |
5467 | finish_dynamic_symbol routine, we'll need to do something about | |
5468 | initializing any .plt and .got entries in ppc64_elf_relocate_section. */ | |
f4656909 | 5469 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \ |
65f38f15 | 5470 | ((DYN) \ |
f4656909 | 5471 | && ((SHARED) \ |
65f38f15 AM |
5472 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ |
5473 | && ((H)->dynindx != -1 \ | |
5474 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
5bd4f169 | 5475 | |
65f38f15 AM |
5476 | /* Allocate space in .plt, .got and associated reloc sections for |
5477 | dynamic relocs. */ | |
5bd4f169 | 5478 | |
b34976b6 | 5479 | static bfd_boolean |
4ce794b7 | 5480 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 5481 | { |
65f38f15 AM |
5482 | struct bfd_link_info *info; |
5483 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 5484 | asection *s; |
65f38f15 AM |
5485 | struct ppc_link_hash_entry *eh; |
5486 | struct ppc_dyn_relocs *p; | |
411e1bfb | 5487 | struct got_entry *gent; |
5bd4f169 | 5488 | |
e92d460e | 5489 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5490 | return TRUE; |
5bd4f169 | 5491 | |
e92d460e AM |
5492 | if (h->root.type == bfd_link_hash_warning) |
5493 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5494 | ||
65f38f15 AM |
5495 | info = (struct bfd_link_info *) inf; |
5496 | htab = ppc_hash_table (info); | |
5bd4f169 | 5497 | |
65f38f15 | 5498 | if (htab->elf.dynamic_sections_created |
411e1bfb | 5499 | && h->dynindx != -1 |
9c7a29a3 | 5500 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) |
5bd4f169 | 5501 | { |
411e1bfb AM |
5502 | struct plt_entry *pent; |
5503 | bfd_boolean doneone = FALSE; | |
5504 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) | |
5505 | if (pent->plt.refcount > 0) | |
5506 | { | |
5507 | BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor); | |
5508 | ||
5509 | /* If this is the first .plt entry, make room for the special | |
5510 | first entry. */ | |
4ce794b7 | 5511 | s = htab->plt; |
411e1bfb AM |
5512 | if (s->_raw_size == 0) |
5513 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; | |
5514 | ||
5515 | pent->plt.offset = s->_raw_size; | |
5516 | ||
5517 | /* Make room for this entry. */ | |
5518 | s->_raw_size += PLT_ENTRY_SIZE; | |
5519 | ||
5520 | /* Make room for the .glink code. */ | |
4ce794b7 | 5521 | s = htab->glink; |
411e1bfb AM |
5522 | if (s->_raw_size == 0) |
5523 | s->_raw_size += GLINK_CALL_STUB_SIZE; | |
5524 | /* We need bigger stubs past index 32767. */ | |
5525 | if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4) | |
5526 | s->_raw_size += 4; | |
5527 | s->_raw_size += 2*4; | |
5528 | ||
5529 | /* We also need to make an entry in the .rela.plt section. */ | |
4ce794b7 | 5530 | s = htab->relplt; |
411e1bfb AM |
5531 | s->_raw_size += sizeof (Elf64_External_Rela); |
5532 | doneone = TRUE; | |
5533 | } | |
5534 | else | |
5535 | pent->plt.offset = (bfd_vma) -1; | |
5536 | if (!doneone) | |
65f38f15 | 5537 | { |
411e1bfb | 5538 | h->plt.plist = NULL; |
65f38f15 AM |
5539 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5540 | } | |
5541 | } | |
5542 | else | |
5543 | { | |
411e1bfb | 5544 | h->plt.plist = NULL; |
65f38f15 AM |
5545 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5546 | } | |
5547 | ||
951fd09b AM |
5548 | eh = (struct ppc_link_hash_entry *) h; |
5549 | /* Run through the TLS GD got entries first if we're changing them | |
5550 | to TPREL. */ | |
e7b938ca | 5551 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
951fd09b AM |
5552 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5553 | if (gent->got.refcount > 0 | |
5554 | && (gent->tls_type & TLS_GD) != 0) | |
5555 | { | |
5556 | /* This was a GD entry that has been converted to TPREL. If | |
5557 | there happens to be a TPREL entry we can use that one. */ | |
5558 | struct got_entry *ent; | |
5559 | for (ent = h->got.glist; ent != NULL; ent = ent->next) | |
5560 | if (ent->got.refcount > 0 | |
5561 | && (ent->tls_type & TLS_TPREL) != 0 | |
e717da7e AM |
5562 | && ent->addend == gent->addend |
5563 | && ent->owner == gent->owner) | |
951fd09b AM |
5564 | { |
5565 | gent->got.refcount = 0; | |
5566 | break; | |
5567 | } | |
5568 | ||
5569 | /* If not, then we'll be using our own TPREL entry. */ | |
5570 | if (gent->got.refcount != 0) | |
5571 | gent->tls_type = TLS_TLS | TLS_TPREL; | |
5572 | } | |
5573 | ||
411e1bfb AM |
5574 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5575 | if (gent->got.refcount > 0) | |
5576 | { | |
951fd09b AM |
5577 | bfd_boolean dyn; |
5578 | ||
411e1bfb | 5579 | /* Make sure this symbol is output as a dynamic symbol. |
951fd09b AM |
5580 | Undefined weak syms won't yet be marked as dynamic, |
5581 | nor will all TLS symbols. */ | |
411e1bfb AM |
5582 | if (h->dynindx == -1 |
5583 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5584 | { | |
5585 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
5586 | return FALSE; | |
5587 | } | |
65f38f15 | 5588 | |
d881513a AM |
5589 | if ((gent->tls_type & TLS_LD) != 0 |
5590 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5591 | { |
e717da7e | 5592 | gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; |
951fd09b | 5593 | continue; |
411e1bfb | 5594 | } |
951fd09b | 5595 | |
e717da7e | 5596 | s = ppc64_elf_tdata (gent->owner)->got; |
951fd09b | 5597 | gent->got.offset = s->_raw_size; |
d881513a AM |
5598 | s->_raw_size |
5599 | += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; | |
951fd09b | 5600 | dyn = htab->elf.dynamic_sections_created; |
4e795f50 AM |
5601 | if ((info->shared |
5602 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
5603 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5604 | || h->root.type != bfd_link_hash_undefweak)) | |
e717da7e | 5605 | ppc64_elf_tdata (gent->owner)->relgot->_raw_size |
e7b938ca | 5606 | += (gent->tls_type & eh->tls_mask & TLS_GD |
951fd09b AM |
5607 | ? 2 * sizeof (Elf64_External_Rela) |
5608 | : sizeof (Elf64_External_Rela)); | |
411e1bfb AM |
5609 | } |
5610 | else | |
5611 | gent->got.offset = (bfd_vma) -1; | |
65f38f15 | 5612 | |
65f38f15 | 5613 | if (eh->dyn_relocs == NULL) |
b34976b6 | 5614 | return TRUE; |
65f38f15 AM |
5615 | |
5616 | /* In the shared -Bsymbolic case, discard space allocated for | |
5617 | dynamic pc-relative relocs against symbols which turn out to be | |
5618 | defined in regular objects. For the normal shared case, discard | |
5619 | space for relocs that have become local due to symbol visibility | |
5620 | changes. */ | |
5621 | ||
5622 | if (info->shared) | |
5623 | { | |
9c7a29a3 AM |
5624 | /* Relocs that use pc_count are those that appear on a call insn, |
5625 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | |
5626 | generated via assembly. We want calls to protected symbols to | |
5627 | resolve directly to the function rather than going via the plt. | |
5628 | If people want function pointer comparisons to work as expected | |
5629 | then they should avoid writing weird assembly. */ | |
09695f56 | 5630 | if (SYMBOL_CALLS_LOCAL (info, h)) |
65f38f15 AM |
5631 | { |
5632 | struct ppc_dyn_relocs **pp; | |
5633 | ||
5634 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 5635 | { |
65f38f15 AM |
5636 | p->count -= p->pc_count; |
5637 | p->pc_count = 0; | |
5638 | if (p->count == 0) | |
5639 | *pp = p->next; | |
5640 | else | |
5641 | pp = &p->next; | |
5bd4f169 | 5642 | } |
65f38f15 | 5643 | } |
4e795f50 AM |
5644 | |
5645 | /* Also discard relocs on undefined weak syms with non-default | |
5646 | visibility. */ | |
5647 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
5648 | && h->root.type == bfd_link_hash_undefweak) | |
5649 | eh->dyn_relocs = NULL; | |
65f38f15 | 5650 | } |
f4656909 | 5651 | else if (ELIMINATE_COPY_RELOCS) |
65f38f15 AM |
5652 | { |
5653 | /* For the non-shared case, discard space for relocs against | |
5654 | symbols which turn out to need copy relocs or are not | |
5655 | dynamic. */ | |
5656 | ||
5657 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
5658 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
5659 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
65f38f15 AM |
5660 | { |
5661 | /* Make sure this symbol is output as a dynamic symbol. | |
5662 | Undefined weak syms won't yet be marked as dynamic. */ | |
5663 | if (h->dynindx == -1 | |
5664 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5665 | { | |
ec338859 | 5666 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
b34976b6 | 5667 | return FALSE; |
65f38f15 AM |
5668 | } |
5669 | ||
5670 | /* If that succeeded, we know we'll be keeping all the | |
5671 | relocs. */ | |
5672 | if (h->dynindx != -1) | |
5673 | goto keep; | |
5674 | } | |
5675 | ||
5676 | eh->dyn_relocs = NULL; | |
5677 | ||
ec338859 | 5678 | keep: ; |
65f38f15 AM |
5679 | } |
5680 | ||
5681 | /* Finally, allocate space. */ | |
5682 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5683 | { | |
5684 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
5685 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
5686 | } | |
5687 | ||
b34976b6 | 5688 | return TRUE; |
65f38f15 AM |
5689 | } |
5690 | ||
5691 | /* Find any dynamic relocs that apply to read-only sections. */ | |
5692 | ||
b34976b6 | 5693 | static bfd_boolean |
4ce794b7 | 5694 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
65f38f15 AM |
5695 | { |
5696 | struct ppc_link_hash_entry *eh; | |
5697 | struct ppc_dyn_relocs *p; | |
5698 | ||
e92d460e AM |
5699 | if (h->root.type == bfd_link_hash_warning) |
5700 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5701 | ||
65f38f15 AM |
5702 | eh = (struct ppc_link_hash_entry *) h; |
5703 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5704 | { | |
5705 | asection *s = p->sec->output_section; | |
5706 | ||
5707 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
5708 | { | |
4ce794b7 | 5709 | struct bfd_link_info *info = inf; |
65f38f15 AM |
5710 | |
5711 | info->flags |= DF_TEXTREL; | |
5712 | ||
5713 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 5714 | return FALSE; |
65f38f15 AM |
5715 | } |
5716 | } | |
b34976b6 | 5717 | return TRUE; |
65f38f15 AM |
5718 | } |
5719 | ||
5720 | /* Set the sizes of the dynamic sections. */ | |
5721 | ||
b34976b6 | 5722 | static bfd_boolean |
4ce794b7 AM |
5723 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
5724 | struct bfd_link_info *info) | |
65f38f15 AM |
5725 | { |
5726 | struct ppc_link_hash_table *htab; | |
5727 | bfd *dynobj; | |
5728 | asection *s; | |
b34976b6 | 5729 | bfd_boolean relocs; |
65f38f15 AM |
5730 | bfd *ibfd; |
5731 | ||
5732 | htab = ppc_hash_table (info); | |
5733 | dynobj = htab->elf.dynobj; | |
5734 | if (dynobj == NULL) | |
5735 | abort (); | |
5736 | ||
5737 | if (htab->elf.dynamic_sections_created) | |
5738 | { | |
5739 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 5740 | if (info->executable) |
65f38f15 AM |
5741 | { |
5742 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
5743 | if (s == NULL) | |
5744 | abort (); | |
5745 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5746 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
5747 | } | |
5748 | } | |
5749 | ||
5750 | /* Set up .got offsets for local syms, and space for local dynamic | |
5751 | relocs. */ | |
5752 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
5753 | { | |
411e1bfb AM |
5754 | struct got_entry **lgot_ents; |
5755 | struct got_entry **end_lgot_ents; | |
e7b938ca | 5756 | char *lgot_masks; |
65f38f15 AM |
5757 | bfd_size_type locsymcount; |
5758 | Elf_Internal_Shdr *symtab_hdr; | |
5759 | asection *srel; | |
5760 | ||
5761 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
5762 | continue; | |
5763 | ||
e717da7e AM |
5764 | if (ppc64_tlsld_got (ibfd)->refcount > 0) |
5765 | { | |
5766 | s = ppc64_elf_tdata (ibfd)->got; | |
5767 | ppc64_tlsld_got (ibfd)->offset = s->_raw_size; | |
5768 | s->_raw_size += 16; | |
5769 | if (info->shared) | |
5770 | { | |
5771 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
5772 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5773 | } | |
5774 | } | |
5775 | else | |
5776 | ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; | |
5777 | ||
65f38f15 AM |
5778 | for (s = ibfd->sections; s != NULL; s = s->next) |
5779 | { | |
ec338859 | 5780 | struct ppc_dyn_relocs *p; |
65f38f15 | 5781 | |
ec338859 AM |
5782 | for (p = *((struct ppc_dyn_relocs **) |
5783 | &elf_section_data (s)->local_dynrel); | |
5784 | p != NULL; | |
5785 | p = p->next) | |
65f38f15 | 5786 | { |
ec338859 AM |
5787 | if (!bfd_is_abs_section (p->sec) |
5788 | && bfd_is_abs_section (p->sec->output_section)) | |
5789 | { | |
5790 | /* Input section has been discarded, either because | |
5791 | it is a copy of a linkonce section or due to | |
5792 | linker script /DISCARD/, so we'll be discarding | |
5793 | the relocs too. */ | |
5794 | } | |
248866a8 | 5795 | else if (p->count != 0) |
ec338859 AM |
5796 | { |
5797 | srel = elf_section_data (p->sec)->sreloc; | |
5798 | srel->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
248866a8 AM |
5799 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
5800 | info->flags |= DF_TEXTREL; | |
ec338859 | 5801 | } |
65f38f15 AM |
5802 | } |
5803 | } | |
5804 | ||
411e1bfb AM |
5805 | lgot_ents = elf_local_got_ents (ibfd); |
5806 | if (!lgot_ents) | |
65f38f15 AM |
5807 | continue; |
5808 | ||
5809 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5810 | locsymcount = symtab_hdr->sh_info; | |
411e1bfb | 5811 | end_lgot_ents = lgot_ents + locsymcount; |
e7b938ca | 5812 | lgot_masks = (char *) end_lgot_ents; |
e717da7e AM |
5813 | s = ppc64_elf_tdata (ibfd)->got; |
5814 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
e7b938ca | 5815 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
65f38f15 | 5816 | { |
411e1bfb AM |
5817 | struct got_entry *ent; |
5818 | ||
5819 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) | |
5820 | if (ent->got.refcount > 0) | |
5821 | { | |
e7b938ca | 5822 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
411e1bfb | 5823 | { |
e717da7e | 5824 | if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) |
411e1bfb | 5825 | { |
e717da7e | 5826 | ppc64_tlsld_got (ibfd)->offset = s->_raw_size; |
411e1bfb AM |
5827 | s->_raw_size += 16; |
5828 | if (info->shared) | |
5829 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5830 | } | |
e717da7e | 5831 | ent->got.offset = ppc64_tlsld_got (ibfd)->offset; |
411e1bfb AM |
5832 | } |
5833 | else | |
5834 | { | |
5835 | ent->got.offset = s->_raw_size; | |
e7b938ca | 5836 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
411e1bfb AM |
5837 | { |
5838 | s->_raw_size += 16; | |
5839 | if (info->shared) | |
5840 | srel->_raw_size += 2 * sizeof (Elf64_External_Rela); | |
5841 | } | |
5842 | else | |
5843 | { | |
5844 | s->_raw_size += 8; | |
5845 | if (info->shared) | |
5846 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5847 | } | |
5848 | } | |
5849 | } | |
5850 | else | |
5851 | ent->got.offset = (bfd_vma) -1; | |
65f38f15 AM |
5852 | } |
5853 | } | |
5854 | ||
5855 | /* Allocate global sym .plt and .got entries, and space for global | |
5856 | sym dynamic relocs. */ | |
4ce794b7 | 5857 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
65f38f15 AM |
5858 | |
5859 | /* We now have determined the sizes of the various dynamic sections. | |
5860 | Allocate memory for them. */ | |
b34976b6 | 5861 | relocs = FALSE; |
65f38f15 AM |
5862 | for (s = dynobj->sections; s != NULL; s = s->next) |
5863 | { | |
5864 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
5865 | continue; | |
5866 | ||
411e1bfb AM |
5867 | /* Reset _cooked_size since prelim layout will set it wrongly, |
5868 | and a non-zero _cooked_size sticks. */ | |
5869 | s->_cooked_size = 0; | |
5870 | ||
4ce794b7 | 5871 | if (s == htab->brlt || s == htab->relbrlt) |
721956f4 AM |
5872 | /* These haven't been allocated yet; don't strip. */ |
5873 | continue; | |
e717da7e AM |
5874 | else if (s == htab->got |
5875 | || s == htab->plt | |
4ce794b7 | 5876 | || s == htab->glink) |
65f38f15 AM |
5877 | { |
5878 | /* Strip this section if we don't need it; see the | |
5879 | comment below. */ | |
5bd4f169 | 5880 | } |
65f38f15 | 5881 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 AM |
5882 | { |
5883 | if (s->_raw_size == 0) | |
5884 | { | |
5885 | /* If we don't need this section, strip it from the | |
5886 | output file. This is mostly to handle .rela.bss and | |
5887 | .rela.plt. We must create both sections in | |
5888 | create_dynamic_sections, because they must be created | |
5889 | before the linker maps input sections to output | |
5890 | sections. The linker does that before | |
5891 | adjust_dynamic_symbol is called, and it is that | |
5892 | function which decides whether anything needs to go | |
5893 | into these sections. */ | |
5bd4f169 AM |
5894 | } |
5895 | else | |
5896 | { | |
4ce794b7 | 5897 | if (s != htab->relplt) |
b34976b6 | 5898 | relocs = TRUE; |
5bd4f169 AM |
5899 | |
5900 | /* We use the reloc_count field as a counter if we need | |
5901 | to copy relocs into the output file. */ | |
5902 | s->reloc_count = 0; | |
5903 | } | |
5904 | } | |
65f38f15 | 5905 | else |
5bd4f169 AM |
5906 | { |
5907 | /* It's not one of our sections, so don't allocate space. */ | |
5908 | continue; | |
5909 | } | |
5910 | ||
65f38f15 | 5911 | if (s->_raw_size == 0) |
5bd4f169 AM |
5912 | { |
5913 | _bfd_strip_section_from_output (info, s); | |
5914 | continue; | |
5915 | } | |
5916 | ||
5f333394 AM |
5917 | /* .plt is in the bss section. We don't initialise it. */ |
5918 | if ((s->flags & SEC_LOAD) == 0) | |
5919 | continue; | |
5920 | ||
65f38f15 AM |
5921 | /* Allocate memory for the section contents. We use bfd_zalloc |
5922 | here in case unused entries are not reclaimed before the | |
5923 | section's contents are written out. This should not happen, | |
411e1bfb AM |
5924 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
5925 | sections instead of garbage. | |
5926 | We also rely on the section contents being zero when writing | |
5927 | the GOT. */ | |
4ce794b7 | 5928 | s->contents = bfd_zalloc (dynobj, s->_raw_size); |
65f38f15 | 5929 | if (s->contents == NULL) |
b34976b6 | 5930 | return FALSE; |
5bd4f169 AM |
5931 | } |
5932 | ||
e717da7e AM |
5933 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5934 | { | |
5935 | s = ppc64_elf_tdata (ibfd)->got; | |
5936 | if (s != NULL && s != htab->got) | |
5937 | { | |
5938 | s->_cooked_size = 0; | |
5939 | if (s->_raw_size == 0) | |
5940 | _bfd_strip_section_from_output (info, s); | |
5941 | else | |
5942 | { | |
5943 | s->contents = bfd_zalloc (ibfd, s->_raw_size); | |
5944 | if (s->contents == NULL) | |
5945 | return FALSE; | |
5946 | } | |
5947 | } | |
5948 | s = ppc64_elf_tdata (ibfd)->relgot; | |
5949 | if (s != NULL) | |
5950 | { | |
5951 | s->_cooked_size = 0; | |
5952 | if (s->_raw_size == 0) | |
5953 | _bfd_strip_section_from_output (info, s); | |
5954 | else | |
5955 | { | |
5956 | s->contents = bfd_zalloc (ibfd, s->_raw_size); | |
5957 | if (s->contents == NULL) | |
5958 | return FALSE; | |
5959 | relocs = TRUE; | |
5960 | s->reloc_count = 0; | |
5961 | } | |
5962 | } | |
5963 | } | |
5964 | ||
e86ce104 | 5965 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
5966 | { |
5967 | /* Add some entries to the .dynamic section. We fill in the | |
5968 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
5969 | must add the entries now so that we get the correct size for | |
5970 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5971 | dynamic linker and used by the debugger. */ | |
dc810e39 | 5972 | #define add_dynamic_entry(TAG, VAL) \ |
4ce794b7 | 5973 | bfd_elf64_add_dynamic_entry (info, (TAG), (VAL)) |
dc810e39 | 5974 | |
36af4a4e | 5975 | if (info->executable) |
5bd4f169 | 5976 | { |
dc810e39 | 5977 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 5978 | return FALSE; |
5bd4f169 AM |
5979 | } |
5980 | ||
4ce794b7 | 5981 | if (htab->plt != NULL && htab->plt->_raw_size != 0) |
5bd4f169 | 5982 | { |
dc810e39 AM |
5983 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
5984 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
5985 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
5986 | || !add_dynamic_entry (DT_JMPREL, 0) |
5987 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 5988 | return FALSE; |
5bd4f169 AM |
5989 | } |
5990 | ||
19397422 AM |
5991 | if (NO_OPD_RELOCS) |
5992 | { | |
5993 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
5994 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 5995 | return FALSE; |
19397422 AM |
5996 | } |
5997 | ||
5bd4f169 AM |
5998 | if (relocs) |
5999 | { | |
dc810e39 AM |
6000 | if (!add_dynamic_entry (DT_RELA, 0) |
6001 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6002 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 6003 | return FALSE; |
5bd4f169 | 6004 | |
65f38f15 AM |
6005 | /* If any dynamic relocs apply to a read-only section, |
6006 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 6007 | if ((info->flags & DF_TEXTREL) == 0) |
4ce794b7 | 6008 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
5bd4f169 | 6009 | |
65f38f15 | 6010 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 6011 | { |
65f38f15 | 6012 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 6013 | return FALSE; |
5bd4f169 | 6014 | } |
5bd4f169 | 6015 | } |
5bd4f169 | 6016 | } |
65f38f15 | 6017 | #undef add_dynamic_entry |
5bd4f169 | 6018 | |
b34976b6 | 6019 | return TRUE; |
5bd4f169 AM |
6020 | } |
6021 | ||
721956f4 | 6022 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 6023 | |
4ce794b7 AM |
6024 | static inline enum ppc_stub_type |
6025 | ppc_type_of_stub (asection *input_sec, | |
6026 | const Elf_Internal_Rela *rel, | |
6027 | struct ppc_link_hash_entry **hash, | |
6028 | bfd_vma destination) | |
5bd4f169 | 6029 | { |
721956f4 AM |
6030 | struct ppc_link_hash_entry *h = *hash; |
6031 | bfd_vma location; | |
6032 | bfd_vma branch_offset; | |
6033 | bfd_vma max_branch_offset; | |
4ce794b7 | 6034 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 | 6035 | |
721956f4 AM |
6036 | if (h != NULL) |
6037 | { | |
6038 | if (h->oh != NULL | |
721956f4 | 6039 | && h->oh->dynindx != -1) |
5bd4f169 | 6040 | { |
411e1bfb AM |
6041 | struct plt_entry *ent; |
6042 | for (ent = h->oh->plt.plist; ent != NULL; ent = ent->next) | |
6043 | if (ent->addend == rel->r_addend | |
6044 | && ent->plt.offset != (bfd_vma) -1) | |
6045 | { | |
6046 | *hash = (struct ppc_link_hash_entry *) h->oh; | |
6047 | return ppc_stub_plt_call; | |
6048 | } | |
5bd4f169 AM |
6049 | } |
6050 | ||
ad8e1ba5 AM |
6051 | if (h->elf.root.type != bfd_link_hash_defined |
6052 | && h->elf.root.type != bfd_link_hash_defweak) | |
721956f4 | 6053 | return ppc_stub_none; |
5d1634d7 | 6054 | } |
5d1634d7 | 6055 | |
721956f4 AM |
6056 | /* Determine where the call point is. */ |
6057 | location = (input_sec->output_offset | |
6058 | + input_sec->output_section->vma | |
6059 | + rel->r_offset); | |
5d1634d7 | 6060 | |
721956f4 AM |
6061 | branch_offset = destination - location; |
6062 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 6063 | |
721956f4 AM |
6064 | /* Determine if a long branch stub is needed. */ |
6065 | max_branch_offset = 1 << 25; | |
4ce794b7 | 6066 | if (r_type != R_PPC64_REL24) |
721956f4 | 6067 | max_branch_offset = 1 << 15; |
5d1634d7 | 6068 | |
721956f4 AM |
6069 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
6070 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
6071 | is needed later. */ | |
6072 | return ppc_stub_long_branch; | |
5d1634d7 | 6073 | |
721956f4 | 6074 | return ppc_stub_none; |
5d1634d7 AM |
6075 | } |
6076 | ||
6077 | /* Build a .plt call stub. */ | |
6078 | ||
4ce794b7 AM |
6079 | static inline bfd_byte * |
6080 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset) | |
5d1634d7 AM |
6081 | { |
6082 | #define PPC_LO(v) ((v) & 0xffff) | |
6083 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6084 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6085 | ||
5d1634d7 | 6086 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
ad8e1ba5 | 6087 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
5d1634d7 AM |
6088 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
6089 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6090 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6091 | offset += 8; |
6092 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
6093 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6094 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6095 | offset += 8; |
6096 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
6097 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
6098 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
6099 | return p; | |
6100 | } | |
6101 | ||
b34976b6 | 6102 | static bfd_boolean |
4ce794b7 | 6103 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
5d1634d7 | 6104 | { |
721956f4 AM |
6105 | struct ppc_stub_hash_entry *stub_entry; |
6106 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
6107 | struct bfd_link_info *info; |
6108 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
6109 | bfd_byte *loc; |
6110 | bfd_byte *p; | |
6111 | unsigned int indx; | |
411e1bfb | 6112 | struct plt_entry *ent; |
721956f4 AM |
6113 | bfd_vma off; |
6114 | int size; | |
5d1634d7 | 6115 | |
721956f4 AM |
6116 | /* Massage our args to the form they really have. */ |
6117 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6118 | info = in_arg; |
5d1634d7 | 6119 | |
5d1634d7 AM |
6120 | htab = ppc_hash_table (info); |
6121 | ||
721956f4 | 6122 | /* Make a note of the offset within the stubs for this entry. */ |
97b639ba AM |
6123 | stub_entry->stub_offset = stub_entry->stub_sec->_cooked_size; |
6124 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; | |
721956f4 | 6125 | |
4ce794b7 | 6126 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
721956f4 | 6127 | switch (stub_entry->stub_type) |
5d1634d7 | 6128 | { |
721956f4 | 6129 | case ppc_stub_long_branch: |
ad8e1ba5 | 6130 | case ppc_stub_long_branch_r2off: |
721956f4 AM |
6131 | /* Branches are relative. This is where we are going to. */ |
6132 | off = (stub_entry->target_value | |
6133 | + stub_entry->target_section->output_offset | |
6134 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 6135 | |
721956f4 AM |
6136 | /* And this is where we are coming from. */ |
6137 | off -= (stub_entry->stub_offset | |
97b639ba AM |
6138 | + stub_entry->stub_sec->output_offset |
6139 | + stub_entry->stub_sec->output_section->vma); | |
e86ce104 | 6140 | |
ad8e1ba5 AM |
6141 | if (stub_entry->stub_type != ppc_stub_long_branch_r2off) |
6142 | size = 4; | |
6143 | else | |
6144 | { | |
6145 | bfd_vma r2off; | |
6146 | ||
6147 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6148 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6149 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6150 | loc += 4; |
97b639ba | 6151 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6152 | loc += 4; |
97b639ba | 6153 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6154 | loc += 4; |
6155 | off -= 12; | |
6156 | size = 16; | |
6157 | } | |
97b639ba | 6158 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
ad8e1ba5 AM |
6159 | |
6160 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); | |
721956f4 | 6161 | break; |
e86ce104 | 6162 | |
721956f4 | 6163 | case ppc_stub_plt_branch: |
ad8e1ba5 | 6164 | case ppc_stub_plt_branch_r2off: |
721956f4 AM |
6165 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
6166 | stub_entry->root.string + 9, | |
b34976b6 | 6167 | FALSE, FALSE); |
721956f4 AM |
6168 | if (br_entry == NULL) |
6169 | { | |
6170 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), | |
6171 | stub_entry->root.string + 9); | |
b34976b6 AM |
6172 | htab->stub_error = TRUE; |
6173 | return FALSE; | |
721956f4 AM |
6174 | } |
6175 | ||
6176 | off = (stub_entry->target_value | |
6177 | + stub_entry->target_section->output_offset | |
6178 | + stub_entry->target_section->output_section->vma); | |
6179 | ||
4ce794b7 AM |
6180 | bfd_put_64 (htab->brlt->owner, off, |
6181 | htab->brlt->contents + br_entry->offset); | |
721956f4 AM |
6182 | |
6183 | if (info->shared) | |
6184 | { | |
6185 | /* Create a reloc for the branch lookup table entry. */ | |
6186 | Elf_Internal_Rela rela; | |
ad8e1ba5 | 6187 | bfd_byte *rl; |
5d1634d7 | 6188 | |
721956f4 | 6189 | rela.r_offset = (br_entry->offset |
4ce794b7 AM |
6190 | + htab->brlt->output_offset |
6191 | + htab->brlt->output_section->vma); | |
721956f4 AM |
6192 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
6193 | rela.r_addend = off; | |
6194 | ||
4ce794b7 AM |
6195 | rl = htab->relbrlt->contents; |
6196 | rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela); | |
6197 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); | |
721956f4 AM |
6198 | } |
6199 | ||
6200 | off = (br_entry->offset | |
4ce794b7 AM |
6201 | + htab->brlt->output_offset |
6202 | + htab->brlt->output_section->vma | |
6203 | - elf_gp (htab->brlt->output_section->owner) | |
ad8e1ba5 | 6204 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6205 | |
ad8e1ba5 | 6206 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
5d1634d7 AM |
6207 | { |
6208 | (*_bfd_error_handler) | |
e86ce104 | 6209 | (_("linkage table error against `%s'"), |
721956f4 | 6210 | stub_entry->root.string); |
5d1634d7 | 6211 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
6212 | htab->stub_error = TRUE; |
6213 | return FALSE; | |
5d1634d7 | 6214 | } |
41bd81ab | 6215 | |
721956f4 | 6216 | indx = off; |
ad8e1ba5 AM |
6217 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
6218 | { | |
97b639ba | 6219 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6220 | loc += 4; |
97b639ba | 6221 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 AM |
6222 | size = 16; |
6223 | } | |
6224 | else | |
6225 | { | |
6226 | bfd_vma r2off; | |
6227 | ||
6228 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6229 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6230 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6231 | loc += 4; |
97b639ba | 6232 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6233 | loc += 4; |
97b639ba | 6234 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 | 6235 | loc += 4; |
97b639ba | 6236 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6237 | loc += 4; |
97b639ba | 6238 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6239 | size = 28; |
6240 | } | |
6241 | loc += 4; | |
97b639ba | 6242 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
ad8e1ba5 | 6243 | loc += 4; |
97b639ba | 6244 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
721956f4 | 6245 | break; |
5d1634d7 | 6246 | |
721956f4 | 6247 | case ppc_stub_plt_call: |
c862ae31 AM |
6248 | /* Do the best we can for shared libraries built without |
6249 | exporting ".foo" for each "foo". This can happen when symbol | |
6250 | versioning scripts strip all bar a subset of symbols. */ | |
6251 | if (stub_entry->h->oh->root.type != bfd_link_hash_defined | |
6252 | && stub_entry->h->oh->root.type != bfd_link_hash_defweak) | |
6253 | { | |
6254 | /* Point the symbol at the stub. There may be multiple stubs, | |
6255 | we don't really care; The main thing is to make this sym | |
8f3bab57 AM |
6256 | defined somewhere. Maybe defining the symbol in the stub |
6257 | section is a silly idea. If we didn't do this, htab->top_id | |
6258 | could disappear. */ | |
c862ae31 AM |
6259 | stub_entry->h->oh->root.type = bfd_link_hash_defined; |
6260 | stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec; | |
6261 | stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset; | |
6262 | } | |
6263 | ||
721956f4 | 6264 | /* Now build the stub. */ |
411e1bfb AM |
6265 | off = (bfd_vma) -1; |
6266 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) | |
6267 | if (ent->addend == stub_entry->addend) | |
6268 | { | |
6269 | off = ent->plt.offset; | |
6270 | break; | |
6271 | } | |
721956f4 AM |
6272 | if (off >= (bfd_vma) -2) |
6273 | abort (); | |
6274 | ||
6275 | off &= ~ (bfd_vma) 1; | |
4ce794b7 AM |
6276 | off += (htab->plt->output_offset |
6277 | + htab->plt->output_section->vma | |
6278 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6279 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6280 | |
ad8e1ba5 | 6281 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
721956f4 AM |
6282 | { |
6283 | (*_bfd_error_handler) | |
6284 | (_("linkage table error against `%s'"), | |
6285 | stub_entry->h->elf.root.root.string); | |
6286 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 AM |
6287 | htab->stub_error = TRUE; |
6288 | return FALSE; | |
721956f4 AM |
6289 | } |
6290 | ||
97b639ba | 6291 | p = build_plt_stub (htab->stub_bfd, loc, off); |
721956f4 AM |
6292 | size = p - loc; |
6293 | break; | |
6294 | ||
6295 | default: | |
6296 | BFD_FAIL (); | |
b34976b6 | 6297 | return FALSE; |
721956f4 AM |
6298 | } |
6299 | ||
97b639ba AM |
6300 | stub_entry->stub_sec->_cooked_size += size; |
6301 | ||
6302 | if (htab->emit_stub_syms | |
6303 | && !(stub_entry->stub_type == ppc_stub_plt_call | |
6304 | && stub_entry->h->oh->root.type == bfd_link_hash_defined | |
6305 | && stub_entry->h->oh->root.u.def.section == stub_entry->stub_sec | |
6306 | && stub_entry->h->oh->root.u.def.value == stub_entry->stub_offset)) | |
6307 | { | |
6308 | struct elf_link_hash_entry *h; | |
6309 | h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string, | |
6310 | TRUE, FALSE, FALSE); | |
6311 | if (h == NULL) | |
6312 | return FALSE; | |
6313 | if (h->root.type == bfd_link_hash_new) | |
6314 | { | |
6315 | h->root.type = bfd_link_hash_defined; | |
6316 | h->root.u.def.section = stub_entry->stub_sec; | |
6317 | h->root.u.def.value = stub_entry->stub_offset; | |
6318 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
6319 | | ELF_LINK_HASH_DEF_REGULAR | |
6320 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
6321 | | ELF_LINK_FORCED_LOCAL); | |
6322 | } | |
6323 | } | |
6324 | ||
b34976b6 | 6325 | return TRUE; |
721956f4 AM |
6326 | } |
6327 | ||
6328 | /* As above, but don't actually build the stub. Just bump offset so | |
6329 | we know stub section sizes, and select plt_branch stubs where | |
6330 | long_branch stubs won't do. */ | |
6331 | ||
b34976b6 | 6332 | static bfd_boolean |
4ce794b7 | 6333 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
721956f4 AM |
6334 | { |
6335 | struct ppc_stub_hash_entry *stub_entry; | |
6336 | struct ppc_link_hash_table *htab; | |
6337 | bfd_vma off; | |
6338 | int size; | |
6339 | ||
6340 | /* Massage our args to the form they really have. */ | |
6341 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6342 | htab = in_arg; |
721956f4 AM |
6343 | |
6344 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
6345 | { | |
411e1bfb | 6346 | struct plt_entry *ent; |
58ac9f71 | 6347 | off = (bfd_vma) -1; |
411e1bfb AM |
6348 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
6349 | if (ent->addend == stub_entry->addend) | |
6350 | { | |
6351 | off = ent->plt.offset & ~(bfd_vma) 1; | |
6352 | break; | |
6353 | } | |
58ac9f71 | 6354 | if (off >= (bfd_vma) -2) |
411e1bfb | 6355 | abort (); |
4ce794b7 AM |
6356 | off += (htab->plt->output_offset |
6357 | + htab->plt->output_section->vma | |
6358 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6359 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6360 | |
ad8e1ba5 | 6361 | size = PLT_CALL_STUB_SIZE; |
4ce794b7 | 6362 | if (PPC_HA (off + 16) != PPC_HA (off)) |
721956f4 AM |
6363 | size += 4; |
6364 | } | |
6365 | else | |
6366 | { | |
ad8e1ba5 AM |
6367 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
6368 | variants. */ | |
721956f4 AM |
6369 | off = (stub_entry->target_value |
6370 | + stub_entry->target_section->output_offset | |
6371 | + stub_entry->target_section->output_section->vma); | |
6372 | off -= (stub_entry->stub_sec->_raw_size | |
6373 | + stub_entry->stub_sec->output_offset | |
6374 | + stub_entry->stub_sec->output_section->vma); | |
6375 | ||
ad8e1ba5 AM |
6376 | /* Reset the stub type from the plt variant in case we now |
6377 | can reach with a shorter stub. */ | |
6378 | if (stub_entry->stub_type >= ppc_stub_plt_branch) | |
6379 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; | |
6380 | ||
6381 | size = 4; | |
6382 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
6383 | { | |
6384 | off -= 12; | |
6385 | size = 16; | |
6386 | } | |
6387 | ||
6388 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ | |
721956f4 AM |
6389 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
6390 | { | |
6391 | struct ppc_branch_hash_entry *br_entry; | |
6392 | ||
6393 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
6394 | stub_entry->root.string + 9, | |
b34976b6 | 6395 | TRUE, FALSE); |
721956f4 AM |
6396 | if (br_entry == NULL) |
6397 | { | |
6398 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), | |
6399 | stub_entry->root.string + 9); | |
b34976b6 AM |
6400 | htab->stub_error = TRUE; |
6401 | return FALSE; | |
721956f4 AM |
6402 | } |
6403 | ||
6404 | if (br_entry->iter != htab->stub_iteration) | |
6405 | { | |
6406 | br_entry->iter = htab->stub_iteration; | |
4ce794b7 AM |
6407 | br_entry->offset = htab->brlt->_raw_size; |
6408 | htab->brlt->_raw_size += 8; | |
721956f4 | 6409 | } |
ad8e1ba5 AM |
6410 | |
6411 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | |
721956f4 | 6412 | size = 16; |
ad8e1ba5 AM |
6413 | if (stub_entry->stub_type != ppc_stub_plt_branch) |
6414 | size = 28; | |
721956f4 AM |
6415 | } |
6416 | } | |
6417 | ||
6418 | stub_entry->stub_sec->_raw_size += size; | |
b34976b6 | 6419 | return TRUE; |
721956f4 AM |
6420 | } |
6421 | ||
6422 | /* Set up various things so that we can make a list of input sections | |
6423 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 6424 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
6425 | |
6426 | int | |
4ce794b7 | 6427 | ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
721956f4 AM |
6428 | { |
6429 | bfd *input_bfd; | |
734b6cf9 | 6430 | int top_id, top_index, id; |
721956f4 | 6431 | asection *section; |
734b6cf9 | 6432 | asection **input_list; |
721956f4 AM |
6433 | bfd_size_type amt; |
6434 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6435 | ||
4ce794b7 | 6436 | if (htab->brlt == NULL) |
721956f4 AM |
6437 | return 0; |
6438 | ||
1e2f5b6e | 6439 | /* Find the top input section id. */ |
3d6f9012 | 6440 | for (input_bfd = info->input_bfds, top_id = 3; |
721956f4 AM |
6441 | input_bfd != NULL; |
6442 | input_bfd = input_bfd->link_next) | |
6443 | { | |
721956f4 AM |
6444 | for (section = input_bfd->sections; |
6445 | section != NULL; | |
6446 | section = section->next) | |
6447 | { | |
6448 | if (top_id < section->id) | |
6449 | top_id = section->id; | |
6450 | } | |
6451 | } | |
721956f4 | 6452 | |
8f3bab57 | 6453 | htab->top_id = top_id; |
721956f4 | 6454 | amt = sizeof (struct map_stub) * (top_id + 1); |
4ce794b7 | 6455 | htab->stub_group = bfd_zmalloc (amt); |
721956f4 AM |
6456 | if (htab->stub_group == NULL) |
6457 | return -1; | |
6458 | ||
3d6f9012 AM |
6459 | /* Set toc_off for com, und, abs and ind sections. */ |
6460 | for (id = 0; id < 3; id++) | |
6461 | htab->stub_group[id].toc_off = TOC_BASE_OFF; | |
721956f4 | 6462 | |
3d6f9012 | 6463 | elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd); |
734b6cf9 AM |
6464 | |
6465 | /* We can't use output_bfd->section_count here to find the top output | |
6466 | section index as some sections may have been removed, and | |
6467 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
6468 | for (section = output_bfd->sections, top_index = 0; | |
6469 | section != NULL; | |
6470 | section = section->next) | |
6471 | { | |
6472 | if (top_index < section->index) | |
6473 | top_index = section->index; | |
6474 | } | |
6475 | ||
6476 | htab->top_index = top_index; | |
6477 | amt = sizeof (asection *) * (top_index + 1); | |
4ce794b7 | 6478 | input_list = bfd_zmalloc (amt); |
734b6cf9 AM |
6479 | htab->input_list = input_list; |
6480 | if (input_list == NULL) | |
6481 | return -1; | |
6482 | ||
721956f4 AM |
6483 | return 1; |
6484 | } | |
6485 | ||
e717da7e AM |
6486 | /* The linker repeatedly calls this function for each TOC input section |
6487 | and linker generated GOT section. Group input bfds such that the toc | |
6488 | within a group is less than 64k in size. Will break with cute linker | |
6489 | scripts that play games with dot in the output toc section. */ | |
ad8e1ba5 AM |
6490 | |
6491 | void | |
4ce794b7 | 6492 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
ad8e1ba5 AM |
6493 | { |
6494 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6495 | ||
6496 | if (!htab->no_multi_toc) | |
6497 | { | |
6498 | bfd_vma addr = isec->output_offset + isec->output_section->vma; | |
6499 | bfd_vma off = addr - htab->toc_curr; | |
6500 | if (off + isec->_raw_size > 0x10000) | |
6501 | { | |
6502 | htab->toc_curr = addr; | |
6503 | htab->multi_toc_needed = 1; | |
6504 | } | |
6505 | elf_gp (isec->owner) = (htab->toc_curr | |
6506 | - elf_gp (isec->output_section->owner) | |
6507 | + TOC_BASE_OFF); | |
6508 | } | |
6509 | } | |
6510 | ||
6511 | /* Called after the last call to the above function. */ | |
6512 | ||
6513 | void | |
4ce794b7 AM |
6514 | ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED, |
6515 | struct bfd_link_info *info) | |
ad8e1ba5 AM |
6516 | { |
6517 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
ad8e1ba5 AM |
6518 | |
6519 | /* toc_curr tracks the TOC offset used for code sections below in | |
6520 | ppc64_elf_next_input_section. Start off at 0x8000. */ | |
3d6f9012 | 6521 | htab->toc_curr = TOC_BASE_OFF; |
ad8e1ba5 AM |
6522 | } |
6523 | ||
9b5ecbd0 AM |
6524 | /* No toc references were found in ISEC. If the code in ISEC makes no |
6525 | calls, then there's no need to use toc adjusting stubs when branching | |
6526 | into ISEC. Actually, indirect calls from ISEC are OK as they will | |
6527 | load r2. */ | |
6528 | ||
6529 | static int | |
4ce794b7 | 6530 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
9b5ecbd0 AM |
6531 | { |
6532 | bfd_byte *contents; | |
6533 | bfd_size_type i; | |
6534 | int ret; | |
6535 | int branch_ok; | |
6536 | ||
772119ce AM |
6537 | /* We know none of our code bearing sections will need toc stubs. */ |
6538 | if ((isec->flags & SEC_LINKER_CREATED) != 0) | |
6539 | return 0; | |
6540 | ||
9b5ecbd0 AM |
6541 | /* Hack for linux kernel. .fixup contains branches, but only back to |
6542 | the function that hit an exception. */ | |
6543 | branch_ok = strcmp (isec->name, ".fixup") == 0; | |
6544 | ||
6545 | contents = elf_section_data (isec)->this_hdr.contents; | |
6546 | if (contents == NULL) | |
6547 | { | |
6548 | contents = bfd_malloc (isec->_raw_size); | |
6549 | if (contents == NULL) | |
6550 | return -1; | |
6551 | if (! bfd_get_section_contents (isec->owner, isec, contents, | |
e717da7e | 6552 | 0, isec->_raw_size)) |
9b5ecbd0 AM |
6553 | { |
6554 | free (contents); | |
6555 | return -1; | |
6556 | } | |
6557 | if (info->keep_memory) | |
6558 | elf_section_data (isec)->this_hdr.contents = contents; | |
6559 | } | |
6560 | ||
6561 | /* Code scan, because we don't necessarily have relocs on calls to | |
6562 | static functions. */ | |
6563 | ret = 0; | |
6564 | for (i = 0; i < isec->_raw_size; i += 4) | |
6565 | { | |
6566 | unsigned long insn = bfd_get_32 (isec->owner, contents + i); | |
6567 | /* Is this a branch? */ | |
772119ce | 6568 | if ((insn & (0x3f << 26)) == (18 << 26) |
9b5ecbd0 AM |
6569 | /* If branch and link, it's a function call. */ |
6570 | && ((insn & 1) != 0 | |
6571 | /* Sibling calls use a plain branch. I don't know a way | |
6572 | of deciding whether a branch is really a sibling call. */ | |
6573 | || !branch_ok)) | |
6574 | { | |
6575 | ret = 1; | |
6576 | break; | |
6577 | } | |
6578 | } | |
6579 | ||
6580 | if (elf_section_data (isec)->this_hdr.contents != contents) | |
6581 | free (contents); | |
6582 | return ret; | |
6583 | } | |
6584 | ||
721956f4 AM |
6585 | /* The linker repeatedly calls this function for each input section, |
6586 | in the order that input sections are linked into output sections. | |
6587 | Build lists of input sections to determine groupings between which | |
6588 | we may insert linker stubs. */ | |
6589 | ||
9b5ecbd0 | 6590 | bfd_boolean |
4ce794b7 | 6591 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
721956f4 AM |
6592 | { |
6593 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
9b5ecbd0 | 6594 | int ret; |
721956f4 | 6595 | |
734b6cf9 AM |
6596 | if ((isec->output_section->flags & SEC_CODE) != 0 |
6597 | && isec->output_section->index <= htab->top_index) | |
721956f4 | 6598 | { |
734b6cf9 | 6599 | asection **list = htab->input_list + isec->output_section->index; |
3d6f9012 | 6600 | /* Steal the link_sec pointer for our list. */ |
721956f4 | 6601 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3d6f9012 AM |
6602 | /* This happens to make the list in reverse order, |
6603 | which is what we want. */ | |
734b6cf9 AM |
6604 | PREV_SEC (isec) = *list; |
6605 | *list = isec; | |
721956f4 | 6606 | } |
ad8e1ba5 AM |
6607 | |
6608 | /* If a code section has a function that uses the TOC then we need | |
6609 | to use the right TOC (obviously). Also, make sure that .opd gets | |
ee87f2da AM |
6610 | the correct TOC value for R_PPC64_TOC relocs that don't have or |
6611 | can't find their function symbol (shouldn't ever happen now). */ | |
ad8e1ba5 | 6612 | if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0) |
9b5ecbd0 AM |
6613 | { |
6614 | if (elf_gp (isec->owner) != 0) | |
6615 | htab->toc_curr = elf_gp (isec->owner); | |
6616 | } | |
6617 | else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0) | |
6618 | return FALSE; | |
6619 | else | |
6620 | isec->has_gp_reloc = ret; | |
ad8e1ba5 AM |
6621 | |
6622 | /* Functions that don't use the TOC can belong in any TOC group. | |
6623 | Use the last TOC base. This happens to make _init and _fini | |
6624 | pasting work. */ | |
6625 | htab->stub_group[isec->id].toc_off = htab->toc_curr; | |
9b5ecbd0 | 6626 | return TRUE; |
721956f4 AM |
6627 | } |
6628 | ||
6629 | /* See whether we can group stub sections together. Grouping stub | |
6630 | sections may result in fewer stubs. More importantly, we need to | |
6631 | put all .init* and .fini* stubs at the beginning of the .init or | |
6632 | .fini output sections respectively, because glibc splits the | |
6633 | _init and _fini functions into multiple parts. Putting a stub in | |
6634 | the middle of a function is not a good idea. */ | |
6635 | ||
6636 | static void | |
4ce794b7 AM |
6637 | group_sections (struct ppc_link_hash_table *htab, |
6638 | bfd_size_type stub_group_size, | |
6639 | bfd_boolean stubs_always_before_branch) | |
721956f4 | 6640 | { |
734b6cf9 AM |
6641 | asection **list = htab->input_list + htab->top_index; |
6642 | do | |
721956f4 | 6643 | { |
734b6cf9 AM |
6644 | asection *tail = *list; |
6645 | while (tail != NULL) | |
721956f4 | 6646 | { |
734b6cf9 AM |
6647 | asection *curr; |
6648 | asection *prev; | |
6649 | bfd_size_type total; | |
6650 | bfd_boolean big_sec; | |
6651 | bfd_vma curr_toc; | |
6652 | ||
6653 | curr = tail; | |
6654 | if (tail->_cooked_size) | |
6655 | total = tail->_cooked_size; | |
6656 | else | |
6657 | total = tail->_raw_size; | |
6658 | big_sec = total >= stub_group_size; | |
6659 | curr_toc = htab->stub_group[tail->id].toc_off; | |
6660 | ||
6661 | while ((prev = PREV_SEC (curr)) != NULL | |
6662 | && ((total += curr->output_offset - prev->output_offset) | |
ad8e1ba5 AM |
6663 | < stub_group_size) |
6664 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
734b6cf9 AM |
6665 | curr = prev; |
6666 | ||
6667 | /* OK, the size from the start of CURR to the end is less | |
6668 | than stub_group_size and thus can be handled by one stub | |
6669 | section. (or the tail section is itself larger than | |
6670 | stub_group_size, in which case we may be toast.) We | |
6671 | should really be keeping track of the total size of stubs | |
6672 | added here, as stubs contribute to the final output | |
6673 | section size. That's a little tricky, and this way will | |
6674 | only break if stubs added make the total size more than | |
6675 | 2^25, ie. for the default stub_group_size, if stubs total | |
6676 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ | |
6677 | do | |
721956f4 AM |
6678 | { |
6679 | prev = PREV_SEC (tail); | |
734b6cf9 | 6680 | /* Set up this stub group. */ |
721956f4 AM |
6681 | htab->stub_group[tail->id].link_sec = curr; |
6682 | } | |
734b6cf9 AM |
6683 | while (tail != curr && (tail = prev) != NULL); |
6684 | ||
6685 | /* But wait, there's more! Input sections up to stub_group_size | |
6686 | bytes before the stub section can be handled by it too. | |
6687 | Don't do this if we have a really large section after the | |
6688 | stubs, as adding more stubs increases the chance that | |
6689 | branches may not reach into the stub section. */ | |
6690 | if (!stubs_always_before_branch && !big_sec) | |
6691 | { | |
6692 | total = 0; | |
6693 | while (prev != NULL | |
6694 | && ((total += tail->output_offset - prev->output_offset) | |
6695 | < stub_group_size) | |
6696 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
6697 | { | |
6698 | tail = prev; | |
6699 | prev = PREV_SEC (tail); | |
6700 | htab->stub_group[tail->id].link_sec = curr; | |
6701 | } | |
6702 | } | |
6703 | tail = prev; | |
721956f4 AM |
6704 | } |
6705 | } | |
734b6cf9 AM |
6706 | while (list-- != htab->input_list); |
6707 | free (htab->input_list); | |
721956f4 AM |
6708 | #undef PREV_SEC |
6709 | } | |
6710 | ||
721956f4 AM |
6711 | /* Determine and set the size of the stub section for a final link. |
6712 | ||
6713 | The basic idea here is to examine all the relocations looking for | |
6714 | PC-relative calls to a target that is unreachable with a "bl" | |
6715 | instruction. */ | |
6716 | ||
b34976b6 | 6717 | bfd_boolean |
4ce794b7 | 6718 | ppc64_elf_size_stubs (bfd *output_bfd, |
4ce794b7 AM |
6719 | struct bfd_link_info *info, |
6720 | bfd_signed_vma group_size, | |
6721 | asection *(*add_stub_section) (const char *, asection *), | |
6722 | void (*layout_sections_again) (void)) | |
721956f4 AM |
6723 | { |
6724 | bfd_size_type stub_group_size; | |
b34976b6 | 6725 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
6726 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
6727 | ||
6728 | /* Stash our params away. */ | |
721956f4 AM |
6729 | htab->add_stub_section = add_stub_section; |
6730 | htab->layout_sections_again = layout_sections_again; | |
6731 | stubs_always_before_branch = group_size < 0; | |
6732 | if (group_size < 0) | |
6733 | stub_group_size = -group_size; | |
6734 | else | |
6735 | stub_group_size = group_size; | |
6736 | if (stub_group_size == 1) | |
6737 | { | |
6738 | /* Default values. */ | |
58ac9f71 AM |
6739 | if (stubs_always_before_branch) |
6740 | { | |
6741 | stub_group_size = 0x1e00000; | |
6742 | if (htab->has_14bit_branch) | |
6743 | stub_group_size = 0x7800; | |
6744 | } | |
6745 | else | |
6746 | { | |
6747 | stub_group_size = 0x1c00000; | |
6748 | if (htab->has_14bit_branch) | |
6749 | stub_group_size = 0x7000; | |
6750 | } | |
721956f4 AM |
6751 | } |
6752 | ||
6753 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
6754 | ||
721956f4 AM |
6755 | while (1) |
6756 | { | |
6757 | bfd *input_bfd; | |
6758 | unsigned int bfd_indx; | |
6759 | asection *stub_sec; | |
b34976b6 | 6760 | bfd_boolean stub_changed; |
721956f4 AM |
6761 | |
6762 | htab->stub_iteration += 1; | |
b34976b6 | 6763 | stub_changed = FALSE; |
721956f4 AM |
6764 | |
6765 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
6766 | input_bfd != NULL; | |
6767 | input_bfd = input_bfd->link_next, bfd_indx++) | |
6768 | { | |
6769 | Elf_Internal_Shdr *symtab_hdr; | |
6770 | asection *section; | |
6cdc0ccc | 6771 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 AM |
6772 | |
6773 | /* We'll need the symbol table in a second. */ | |
6774 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
6775 | if (symtab_hdr->sh_info == 0) | |
6776 | continue; | |
6777 | ||
721956f4 AM |
6778 | /* Walk over each section attached to the input bfd. */ |
6779 | for (section = input_bfd->sections; | |
6780 | section != NULL; | |
6781 | section = section->next) | |
6782 | { | |
721956f4 | 6783 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
6784 | |
6785 | /* If there aren't any relocs, then there's nothing more | |
6786 | to do. */ | |
6787 | if ((section->flags & SEC_RELOC) == 0 | |
6788 | || section->reloc_count == 0) | |
6789 | continue; | |
6790 | ||
6791 | /* If this section is a link-once section that will be | |
6792 | discarded, then don't create any stubs. */ | |
6793 | if (section->output_section == NULL | |
6794 | || section->output_section->owner != output_bfd) | |
6795 | continue; | |
6796 | ||
1e2f5b6e AM |
6797 | /* Get the relocs. */ |
6798 | internal_relocs | |
4ce794b7 | 6799 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 6800 | info->keep_memory); |
721956f4 | 6801 | if (internal_relocs == NULL) |
1e2f5b6e | 6802 | goto error_ret_free_local; |
721956f4 AM |
6803 | |
6804 | /* Now examine each relocation. */ | |
6805 | irela = internal_relocs; | |
6806 | irelaend = irela + section->reloc_count; | |
6807 | for (; irela < irelaend; irela++) | |
6808 | { | |
4ce794b7 AM |
6809 | enum elf_ppc64_reloc_type r_type; |
6810 | unsigned int r_indx; | |
721956f4 AM |
6811 | enum ppc_stub_type stub_type; |
6812 | struct ppc_stub_hash_entry *stub_entry; | |
6813 | asection *sym_sec; | |
6814 | bfd_vma sym_value; | |
6815 | bfd_vma destination; | |
6816 | struct ppc_link_hash_entry *hash; | |
411e1bfb AM |
6817 | struct elf_link_hash_entry *h; |
6818 | Elf_Internal_Sym *sym; | |
721956f4 AM |
6819 | char *stub_name; |
6820 | const asection *id_sec; | |
6821 | ||
6822 | r_type = ELF64_R_TYPE (irela->r_info); | |
6823 | r_indx = ELF64_R_SYM (irela->r_info); | |
6824 | ||
4ce794b7 | 6825 | if (r_type >= R_PPC64_max) |
721956f4 AM |
6826 | { |
6827 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 6828 | goto error_ret_free_internal; |
721956f4 AM |
6829 | } |
6830 | ||
6831 | /* Only look for stubs on branch instructions. */ | |
4ce794b7 AM |
6832 | if (r_type != R_PPC64_REL24 |
6833 | && r_type != R_PPC64_REL14 | |
6834 | && r_type != R_PPC64_REL14_BRTAKEN | |
6835 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
721956f4 AM |
6836 | continue; |
6837 | ||
6838 | /* Now determine the call target, its name, value, | |
6839 | section. */ | |
721956f4 | 6840 | destination = 0; |
411e1bfb AM |
6841 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
6842 | r_indx, input_bfd)) | |
6843 | goto error_ret_free_internal; | |
6844 | hash = (struct ppc_link_hash_entry *) h; | |
6845 | ||
6846 | if (hash == NULL) | |
721956f4 AM |
6847 | { |
6848 | /* It's a local symbol. */ | |
411e1bfb | 6849 | sym_value = sym->st_value; |
721956f4 AM |
6850 | destination = (sym_value + irela->r_addend |
6851 | + sym_sec->output_offset | |
6852 | + sym_sec->output_section->vma); | |
6853 | } | |
6854 | else | |
6855 | { | |
6856 | /* It's an external symbol. */ | |
411e1bfb | 6857 | sym_value = 0; |
721956f4 AM |
6858 | if (hash->elf.root.type == bfd_link_hash_defined |
6859 | || hash->elf.root.type == bfd_link_hash_defweak) | |
6860 | { | |
721956f4 AM |
6861 | sym_value = hash->elf.root.u.def.value; |
6862 | if (sym_sec->output_section != NULL) | |
6863 | destination = (sym_value + irela->r_addend | |
6864 | + sym_sec->output_offset | |
6865 | + sym_sec->output_section->vma); | |
6866 | } | |
6867 | else if (hash->elf.root.type == bfd_link_hash_undefweak) | |
6868 | ; | |
6869 | else if (hash->elf.root.type == bfd_link_hash_undefined) | |
6870 | ; | |
6871 | else | |
6872 | { | |
6873 | bfd_set_error (bfd_error_bad_value); | |
6874 | goto error_ret_free_internal; | |
6875 | } | |
6876 | } | |
6877 | ||
6878 | /* Determine what (if any) linker stub is needed. */ | |
6879 | stub_type = ppc_type_of_stub (section, irela, &hash, | |
6880 | destination); | |
ad8e1ba5 AM |
6881 | |
6882 | if (stub_type != ppc_stub_plt_call) | |
6883 | { | |
6884 | /* Check whether we need a TOC adjusting stub. | |
6885 | Since the linker pastes together pieces from | |
6886 | different object files when creating the | |
6887 | _init and _fini functions, it may be that a | |
6888 | call to what looks like a local sym is in | |
6889 | fact a call needing a TOC adjustment. */ | |
6890 | if (sym_sec != NULL | |
6891 | && sym_sec->output_section != NULL | |
6892 | && (htab->stub_group[sym_sec->id].toc_off | |
9b5ecbd0 AM |
6893 | != htab->stub_group[section->id].toc_off) |
6894 | && sym_sec->has_gp_reloc | |
6895 | && section->has_gp_reloc) | |
ad8e1ba5 AM |
6896 | stub_type = ppc_stub_long_branch_r2off; |
6897 | } | |
6898 | ||
721956f4 AM |
6899 | if (stub_type == ppc_stub_none) |
6900 | continue; | |
6901 | ||
411e1bfb AM |
6902 | /* __tls_get_addr calls might be eliminated. */ |
6903 | if (stub_type != ppc_stub_plt_call | |
6904 | && hash != NULL | |
6905 | && &hash->elf == htab->tls_get_addr | |
6906 | && section->has_tls_reloc | |
6907 | && irela != internal_relocs) | |
6908 | { | |
6909 | /* Get tls info. */ | |
e7b938ca | 6910 | char *tls_mask; |
411e1bfb | 6911 | |
e7b938ca | 6912 | if (!get_tls_mask (&tls_mask, &local_syms, |
411e1bfb AM |
6913 | irela - 1, input_bfd)) |
6914 | goto error_ret_free_internal; | |
e7b938ca | 6915 | if (*tls_mask != 0) |
411e1bfb AM |
6916 | continue; |
6917 | } | |
6918 | ||
721956f4 AM |
6919 | /* Support for grouping stub sections. */ |
6920 | id_sec = htab->stub_group[section->id].link_sec; | |
6921 | ||
6922 | /* Get the name of this stub. */ | |
6923 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
6924 | if (!stub_name) | |
6925 | goto error_ret_free_internal; | |
6926 | ||
6927 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 6928 | stub_name, FALSE, FALSE); |
721956f4 AM |
6929 | if (stub_entry != NULL) |
6930 | { | |
6931 | /* The proper stub has already been created. */ | |
6932 | free (stub_name); | |
6933 | continue; | |
6934 | } | |
6935 | ||
6936 | stub_entry = ppc_add_stub (stub_name, section, htab); | |
6937 | if (stub_entry == NULL) | |
6938 | { | |
6939 | free (stub_name); | |
6cdc0ccc AM |
6940 | error_ret_free_internal: |
6941 | if (elf_section_data (section)->relocs == NULL) | |
6942 | free (internal_relocs); | |
6943 | error_ret_free_local: | |
6944 | if (local_syms != NULL | |
6945 | && (symtab_hdr->contents | |
6946 | != (unsigned char *) local_syms)) | |
6947 | free (local_syms); | |
b34976b6 | 6948 | return FALSE; |
721956f4 AM |
6949 | } |
6950 | ||
ad8e1ba5 | 6951 | stub_entry->stub_type = stub_type; |
721956f4 AM |
6952 | stub_entry->target_value = sym_value; |
6953 | stub_entry->target_section = sym_sec; | |
721956f4 | 6954 | stub_entry->h = hash; |
411e1bfb | 6955 | stub_entry->addend = irela->r_addend; |
b34976b6 | 6956 | stub_changed = TRUE; |
721956f4 AM |
6957 | } |
6958 | ||
6959 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 6960 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 6961 | free (internal_relocs); |
721956f4 | 6962 | } |
6cdc0ccc AM |
6963 | |
6964 | if (local_syms != NULL | |
6965 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
6966 | { | |
6967 | if (!info->keep_memory) | |
6968 | free (local_syms); | |
6969 | else | |
6970 | symtab_hdr->contents = (unsigned char *) local_syms; | |
6971 | } | |
721956f4 AM |
6972 | } |
6973 | ||
6974 | if (!stub_changed) | |
6975 | break; | |
6976 | ||
6977 | /* OK, we've added some stubs. Find out the new size of the | |
6978 | stub sections. */ | |
6979 | for (stub_sec = htab->stub_bfd->sections; | |
6980 | stub_sec != NULL; | |
6981 | stub_sec = stub_sec->next) | |
e717da7e AM |
6982 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
6983 | { | |
6984 | stub_sec->_raw_size = 0; | |
6985 | stub_sec->_cooked_size = 0; | |
6986 | } | |
4ce794b7 AM |
6987 | htab->brlt->_raw_size = 0; |
6988 | htab->brlt->_cooked_size = 0; | |
721956f4 AM |
6989 | |
6990 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab); | |
6991 | ||
6992 | /* Ask the linker to do its stuff. */ | |
6993 | (*htab->layout_sections_again) (); | |
6994 | } | |
6995 | ||
afbe61cf AM |
6996 | /* It would be nice to strip .branch_lt from the output if the |
6997 | section is empty, but it's too late. If we strip sections here, | |
6998 | the dynamic symbol table is corrupted since the section symbol | |
6999 | for the stripped section isn't written. */ | |
721956f4 | 7000 | |
b34976b6 | 7001 | return TRUE; |
721956f4 AM |
7002 | } |
7003 | ||
7004 | /* Called after we have determined section placement. If sections | |
805fc799 | 7005 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 7006 | |
805fc799 | 7007 | bfd_vma |
4ce794b7 | 7008 | ppc64_elf_toc (bfd *obfd) |
721956f4 | 7009 | { |
805fc799 AM |
7010 | asection *s; |
7011 | bfd_vma TOCstart; | |
721956f4 | 7012 | |
805fc799 AM |
7013 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
7014 | order. The TOC starts where the first of these sections starts. */ | |
7015 | s = bfd_get_section_by_name (obfd, ".got"); | |
7016 | if (s == NULL) | |
7017 | s = bfd_get_section_by_name (obfd, ".toc"); | |
7018 | if (s == NULL) | |
7019 | s = bfd_get_section_by_name (obfd, ".tocbss"); | |
7020 | if (s == NULL) | |
7021 | s = bfd_get_section_by_name (obfd, ".plt"); | |
7022 | if (s == NULL) | |
7023 | { | |
7024 | /* This may happen for | |
7025 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
7026 | .toc directive | |
7027 | o bad linker script | |
7028 | o --gc-sections and empty TOC sections | |
7029 | ||
7030 | FIXME: Warn user? */ | |
7031 | ||
7032 | /* Look for a likely section. We probably won't even be | |
7033 | using TOCstart. */ | |
7034 | for (s = obfd->sections; s != NULL; s = s->next) | |
7035 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) | |
7036 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7037 | break; | |
721956f4 | 7038 | if (s == NULL) |
805fc799 AM |
7039 | for (s = obfd->sections; s != NULL; s = s->next) |
7040 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) | |
7041 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7042 | break; | |
721956f4 | 7043 | if (s == NULL) |
805fc799 AM |
7044 | for (s = obfd->sections; s != NULL; s = s->next) |
7045 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) | |
7046 | break; | |
721956f4 | 7047 | if (s == NULL) |
805fc799 AM |
7048 | for (s = obfd->sections; s != NULL; s = s->next) |
7049 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) | |
7050 | break; | |
7051 | } | |
721956f4 | 7052 | |
805fc799 AM |
7053 | TOCstart = 0; |
7054 | if (s != NULL) | |
7055 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 7056 | |
805fc799 | 7057 | return TOCstart; |
721956f4 AM |
7058 | } |
7059 | ||
7060 | /* Build all the stubs associated with the current output file. | |
7061 | The stubs are kept in a hash table attached to the main linker | |
7062 | hash table. This function is called via gldelf64ppc_finish. */ | |
7063 | ||
b34976b6 | 7064 | bfd_boolean |
4ce794b7 AM |
7065 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
7066 | struct bfd_link_info *info, | |
7067 | char **stats) | |
5d1634d7 AM |
7068 | { |
7069 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 7070 | asection *stub_sec; |
5d1634d7 | 7071 | bfd_byte *p; |
e717da7e | 7072 | int stub_sec_count = 0; |
5d1634d7 | 7073 | |
ad8e1ba5 | 7074 | htab->emit_stub_syms = emit_stub_syms; |
721956f4 AM |
7075 | for (stub_sec = htab->stub_bfd->sections; |
7076 | stub_sec != NULL; | |
7077 | stub_sec = stub_sec->next) | |
e717da7e AM |
7078 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7079 | { | |
7080 | bfd_size_type size; | |
721956f4 | 7081 | |
e717da7e AM |
7082 | /* Allocate memory to hold the linker stubs. */ |
7083 | size = stub_sec->_raw_size; | |
7084 | if (size != 0) | |
7085 | { | |
7086 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); | |
7087 | if (stub_sec->contents == NULL) | |
7088 | return FALSE; | |
7089 | } | |
7090 | stub_sec->_cooked_size = 0; | |
7091 | } | |
5d1634d7 | 7092 | |
4ce794b7 | 7093 | if (htab->plt != NULL) |
5d1634d7 | 7094 | { |
9f951329 | 7095 | unsigned int indx; |
ad8e1ba5 | 7096 | bfd_vma plt0; |
9f951329 | 7097 | |
721956f4 | 7098 | /* Build the .glink plt call stub. */ |
4ce794b7 AM |
7099 | plt0 = (htab->plt->output_section->vma |
7100 | + htab->plt->output_offset | |
7101 | - (htab->glink->output_section->vma | |
7102 | + htab->glink->output_offset | |
ad8e1ba5 AM |
7103 | + GLINK_CALL_STUB_SIZE)); |
7104 | if (plt0 + 0x80008000 > 0xffffffff) | |
721956f4 | 7105 | { |
ad8e1ba5 AM |
7106 | (*_bfd_error_handler) (_(".glink and .plt too far apart")); |
7107 | bfd_set_error (bfd_error_bad_value); | |
7108 | return FALSE; | |
721956f4 | 7109 | } |
721956f4 | 7110 | |
97b639ba AM |
7111 | if (htab->emit_stub_syms) |
7112 | { | |
7113 | struct elf_link_hash_entry *h; | |
7114 | h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE); | |
7115 | if (h == NULL) | |
7116 | return FALSE; | |
7117 | if (h->root.type == bfd_link_hash_new) | |
7118 | { | |
7119 | h->root.type = bfd_link_hash_defined; | |
7120 | h->root.u.def.section = htab->glink; | |
7121 | h->root.u.def.value = 0; | |
7122 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
7123 | | ELF_LINK_HASH_DEF_REGULAR | |
7124 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
7125 | | ELF_LINK_FORCED_LOCAL); | |
7126 | } | |
7127 | } | |
4ce794b7 AM |
7128 | p = htab->glink->contents; |
7129 | bfd_put_32 (htab->glink->owner, MFCTR_R12, p); | |
ad8e1ba5 | 7130 | p += 4; |
4ce794b7 | 7131 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p); |
ad8e1ba5 | 7132 | p += 4; |
4ce794b7 | 7133 | bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p); |
ad8e1ba5 | 7134 | p += 4; |
4ce794b7 | 7135 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7136 | p += 4; |
4ce794b7 | 7137 | bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p); |
ad8e1ba5 | 7138 | p += 4; |
4ce794b7 | 7139 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p); |
ad8e1ba5 | 7140 | p += 4; |
4ce794b7 | 7141 | bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p); |
ad8e1ba5 | 7142 | p += 4; |
4ce794b7 | 7143 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7144 | p += 4; |
4ce794b7 | 7145 | bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p); |
ad8e1ba5 | 7146 | p += 4; |
4ce794b7 | 7147 | bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p); |
ad8e1ba5 | 7148 | p += 4; |
4ce794b7 | 7149 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7150 | p += 4; |
4ce794b7 | 7151 | bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7152 | p += 4; |
4ce794b7 | 7153 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
ad8e1ba5 | 7154 | p += 4; |
4ce794b7 | 7155 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
ad8e1ba5 | 7156 | p += 4; |
4ce794b7 | 7157 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
ad8e1ba5 | 7158 | p += 4; |
4ce794b7 | 7159 | bfd_put_32 (htab->glink->owner, BCTR, p); |
ad8e1ba5 AM |
7160 | p += 4; |
7161 | ||
9f951329 AM |
7162 | /* Build the .glink lazy link call stubs. */ |
7163 | indx = 0; | |
4ce794b7 | 7164 | while (p < htab->glink->contents + htab->glink->_raw_size) |
9f951329 AM |
7165 | { |
7166 | if (indx < 0x8000) | |
7167 | { | |
4ce794b7 | 7168 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
9f951329 AM |
7169 | p += 4; |
7170 | } | |
7171 | else | |
7172 | { | |
4ce794b7 | 7173 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
9f951329 | 7174 | p += 4; |
4ce794b7 | 7175 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
9f951329 AM |
7176 | p += 4; |
7177 | } | |
4ce794b7 AM |
7178 | bfd_put_32 (htab->glink->owner, |
7179 | B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p); | |
a16d5acb | 7180 | indx++; |
9f951329 AM |
7181 | p += 4; |
7182 | } | |
4ce794b7 | 7183 | htab->glink->_cooked_size = p - htab->glink->contents; |
5d1634d7 | 7184 | } |
5d1634d7 | 7185 | |
4ce794b7 | 7186 | if (htab->brlt->_raw_size != 0) |
721956f4 | 7187 | { |
4ce794b7 AM |
7188 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
7189 | htab->brlt->_raw_size); | |
7190 | if (htab->brlt->contents == NULL) | |
b34976b6 | 7191 | return FALSE; |
721956f4 | 7192 | } |
5d1634d7 | 7193 | |
721956f4 AM |
7194 | /* Build the stubs as directed by the stub hash table. */ |
7195 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 7196 | |
721956f4 AM |
7197 | for (stub_sec = htab->stub_bfd->sections; |
7198 | stub_sec != NULL; | |
7199 | stub_sec = stub_sec->next) | |
e717da7e AM |
7200 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7201 | { | |
7202 | stub_sec_count += 1; | |
7203 | if (stub_sec->_raw_size != stub_sec->_cooked_size) | |
7204 | break; | |
7205 | } | |
5d1634d7 | 7206 | |
721956f4 | 7207 | if (stub_sec != NULL |
4ce794b7 | 7208 | || htab->glink->_raw_size != htab->glink->_cooked_size) |
5d1634d7 | 7209 | { |
b34976b6 | 7210 | htab->stub_error = TRUE; |
721956f4 | 7211 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
5d1634d7 | 7212 | } |
721956f4 | 7213 | |
d2a300cf AM |
7214 | if (htab->stub_error) |
7215 | return FALSE; | |
7216 | ||
7217 | if (stats != NULL) | |
7218 | { | |
7219 | *stats = bfd_malloc (500); | |
7220 | if (*stats == NULL) | |
7221 | return FALSE; | |
7222 | ||
7223 | sprintf (*stats, _("linker stubs in %u groups\n" | |
7224 | " branch %lu\n" | |
7225 | " toc adjust %lu\n" | |
7226 | " long branch %lu\n" | |
7227 | " long toc adj %lu\n" | |
7228 | " plt call %lu"), | |
e717da7e | 7229 | stub_sec_count, |
4ce794b7 AM |
7230 | htab->stub_count[ppc_stub_long_branch - 1], |
7231 | htab->stub_count[ppc_stub_long_branch_r2off - 1], | |
7232 | htab->stub_count[ppc_stub_plt_branch - 1], | |
7233 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], | |
7234 | htab->stub_count[ppc_stub_plt_call - 1]); | |
d2a300cf AM |
7235 | } |
7236 | return TRUE; | |
5bd4f169 AM |
7237 | } |
7238 | ||
5bd4f169 AM |
7239 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
7240 | to handle the relocations for a section. | |
7241 | ||
7242 | The relocs are always passed as Rela structures; if the section | |
7243 | actually uses Rel structures, the r_addend field will always be | |
7244 | zero. | |
7245 | ||
7246 | This function is responsible for adjust the section contents as | |
7247 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 7248 | relocatable output file) adjusting the reloc addend as |
5bd4f169 AM |
7249 | necessary. |
7250 | ||
7251 | This function does not have to worry about setting the reloc | |
7252 | address or the reloc symbol index. | |
7253 | ||
7254 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
7255 | ||
7256 | LOCAL_SECTIONS is an array giving the section in the input file | |
7257 | corresponding to the st_shndx field of each local symbol. | |
7258 | ||
7259 | The global hash table entry for the global symbols can be found | |
7260 | via elf_sym_hashes (input_bfd). | |
7261 | ||
1049f94e | 7262 | When generating relocatable output, this function must handle |
5bd4f169 AM |
7263 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
7264 | going to be the section symbol corresponding to the output | |
7265 | section, which means that the addend must be adjusted | |
7266 | accordingly. */ | |
7267 | ||
b34976b6 | 7268 | static bfd_boolean |
4ce794b7 AM |
7269 | ppc64_elf_relocate_section (bfd *output_bfd, |
7270 | struct bfd_link_info *info, | |
7271 | bfd *input_bfd, | |
7272 | asection *input_section, | |
7273 | bfd_byte *contents, | |
7274 | Elf_Internal_Rela *relocs, | |
7275 | Elf_Internal_Sym *local_syms, | |
7276 | asection **local_sections) | |
5bd4f169 | 7277 | { |
65f38f15 | 7278 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
7279 | Elf_Internal_Shdr *symtab_hdr; |
7280 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
7281 | Elf_Internal_Rela *rel; |
7282 | Elf_Internal_Rela *relend; | |
411e1bfb AM |
7283 | Elf_Internal_Rela outrel; |
7284 | bfd_byte *loc; | |
411e1bfb | 7285 | struct got_entry **local_got_ents; |
5bd4f169 | 7286 | bfd_vma TOCstart; |
b34976b6 AM |
7287 | bfd_boolean ret = TRUE; |
7288 | bfd_boolean is_opd; | |
96e0dda4 | 7289 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 7290 | bfd_boolean is_power4 = FALSE; |
5bd4f169 | 7291 | |
1049f94e | 7292 | if (info->relocatable) |
b34976b6 | 7293 | return TRUE; |
b491616a | 7294 | |
65f38f15 | 7295 | /* Initialize howto table if needed. */ |
5bd4f169 | 7296 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
7297 | ppc_howto_init (); |
7298 | ||
65f38f15 | 7299 | htab = ppc_hash_table (info); |
411e1bfb | 7300 | local_got_ents = elf_local_got_ents (input_bfd); |
5bd4f169 | 7301 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
7302 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
7303 | sym_hashes = elf_sym_hashes (input_bfd); | |
f0abc2a1 | 7304 | is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL; |
65f38f15 | 7305 | |
5bd4f169 AM |
7306 | rel = relocs; |
7307 | relend = relocs + input_section->reloc_count; | |
7308 | for (; rel < relend; rel++) | |
7309 | { | |
04c9666a | 7310 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 AM |
7311 | bfd_vma addend; |
7312 | bfd_reloc_status_type r; | |
7313 | Elf_Internal_Sym *sym; | |
7314 | asection *sec; | |
7315 | struct elf_link_hash_entry *h; | |
721956f4 | 7316 | struct elf_link_hash_entry *fdh; |
5bd4f169 | 7317 | const char *sym_name; |
5bd4f169 | 7318 | unsigned long r_symndx; |
951fd09b | 7319 | char tls_mask, tls_gd, tls_type; |
5bd4f169 | 7320 | bfd_vma relocation; |
b34976b6 AM |
7321 | bfd_boolean unresolved_reloc; |
7322 | bfd_boolean warned; | |
50bc7936 | 7323 | unsigned long insn, mask; |
721956f4 AM |
7324 | struct ppc_stub_hash_entry *stub_entry; |
7325 | bfd_vma max_br_offset; | |
7326 | bfd_vma from; | |
5bd4f169 | 7327 | |
4ce794b7 | 7328 | r_type = ELF64_R_TYPE (rel->r_info); |
5bd4f169 | 7329 | r_symndx = ELF64_R_SYM (rel->r_info); |
ee87f2da AM |
7330 | |
7331 | /* For old style R_PPC64_TOC relocs with a zero symbol, use the | |
7332 | symbol of the previous ADDR64 reloc. The symbol gives us the | |
7333 | proper TOC base to use. */ | |
7334 | if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC) | |
7335 | && rel != relocs | |
7336 | && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64 | |
7337 | && is_opd) | |
7338 | r_symndx = ELF64_R_SYM (rel[-1].r_info); | |
7339 | ||
4ce794b7 AM |
7340 | sym = NULL; |
7341 | sec = NULL; | |
7342 | h = NULL; | |
7343 | sym_name = NULL; | |
b34976b6 AM |
7344 | unresolved_reloc = FALSE; |
7345 | warned = FALSE; | |
65f38f15 | 7346 | |
0b13192e | 7347 | if (r_symndx < symtab_hdr->sh_info) |
5bd4f169 AM |
7348 | { |
7349 | /* It's a local symbol. */ | |
7350 | sym = local_syms + r_symndx; | |
7351 | sec = local_sections[r_symndx]; | |
411e1bfb | 7352 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
f8df10f4 | 7353 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
1e2f5b6e AM |
7354 | if (elf_section_data (sec) != NULL) |
7355 | { | |
7356 | long *opd_sym_adjust; | |
7357 | ||
f0abc2a1 | 7358 | opd_sym_adjust = ppc64_elf_section_data (sec)->opd.adjust; |
1e2f5b6e AM |
7359 | if (opd_sym_adjust != NULL && sym->st_value % 24 == 0) |
7360 | relocation += opd_sym_adjust[sym->st_value / 24]; | |
7361 | } | |
5bd4f169 AM |
7362 | } |
7363 | else | |
7364 | { | |
7365 | /* It's a global symbol. */ | |
7366 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
7367 | while (h->root.type == bfd_link_hash_indirect | |
7368 | || h->root.type == bfd_link_hash_warning) | |
7369 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7370 | sym_name = h->root.root.string; | |
65f38f15 | 7371 | relocation = 0; |
5bd4f169 AM |
7372 | if (h->root.type == bfd_link_hash_defined |
7373 | || h->root.type == bfd_link_hash_defweak) | |
7374 | { | |
7375 | sec = h->root.u.def.section; | |
65f38f15 AM |
7376 | if (sec->output_section == NULL) |
7377 | /* Set a flag that will be cleared later if we find a | |
7378 | relocation value for this symbol. output_section | |
7379 | is typically NULL for symbols satisfied by a shared | |
7380 | library. */ | |
b34976b6 | 7381 | unresolved_reloc = TRUE; |
5bd4f169 AM |
7382 | else |
7383 | relocation = (h->root.u.def.value | |
7384 | + sec->output_section->vma | |
7385 | + sec->output_offset); | |
7386 | } | |
7387 | else if (h->root.type == bfd_link_hash_undefweak) | |
65f38f15 | 7388 | ; |
9203ba99 | 7389 | else if (!info->executable |
65f38f15 AM |
7390 | && !info->no_undefined |
7391 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
7392 | ; | |
5bd4f169 AM |
7393 | else |
7394 | { | |
7395 | if (! ((*info->callbacks->undefined_symbol) | |
7396 | (info, h->root.root.string, input_bfd, input_section, | |
15f40dfc | 7397 | rel->r_offset, (info->executable |
411e1bfb AM |
7398 | || info->no_undefined |
7399 | || ELF_ST_VISIBILITY (h->other))))) | |
b34976b6 AM |
7400 | return FALSE; |
7401 | warned = TRUE; | |
5bd4f169 AM |
7402 | } |
7403 | } | |
7404 | ||
951fd09b AM |
7405 | /* TLS optimizations. Replace instruction sequences and relocs |
7406 | based on information we collected in tls_optimize. We edit | |
7407 | RELOCS so that --emit-relocs will output something sensible | |
7408 | for the final instruction stream. */ | |
7409 | tls_mask = 0; | |
7410 | tls_gd = 0; | |
d881513a | 7411 | if (IS_PPC64_TLS_RELOC (r_type)) |
411e1bfb AM |
7412 | { |
7413 | if (h != NULL) | |
e7b938ca | 7414 | tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask; |
411e1bfb AM |
7415 | else if (local_got_ents != NULL) |
7416 | { | |
e7b938ca AM |
7417 | char *lgot_masks; |
7418 | lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); | |
7419 | tls_mask = lgot_masks[r_symndx]; | |
411e1bfb AM |
7420 | } |
7421 | } | |
7422 | ||
7423 | /* Ensure reloc mapping code below stays sane. */ | |
7424 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 | |
7425 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 | |
7426 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) | |
7427 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) | |
7428 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) | |
7429 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) | |
7430 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) | |
7431 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) | |
7432 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) | |
7433 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) | |
7434 | abort (); | |
7435 | switch (r_type) | |
7436 | { | |
7437 | default: | |
411e1bfb AM |
7438 | break; |
7439 | ||
7440 | case R_PPC64_TOC16: | |
7441 | case R_PPC64_TOC16_LO: | |
7442 | case R_PPC64_TOC16_DS: | |
7443 | case R_PPC64_TOC16_LO_DS: | |
411e1bfb AM |
7444 | { |
7445 | /* Check for toc tls entries. */ | |
7446 | char *toc_tls; | |
951fd09b | 7447 | int retval; |
411e1bfb | 7448 | |
e7b938ca | 7449 | retval = get_tls_mask (&toc_tls, &local_syms, rel, input_bfd); |
951fd09b | 7450 | if (retval == 0) |
411e1bfb AM |
7451 | return FALSE; |
7452 | ||
7453 | if (toc_tls) | |
7454 | { | |
951fd09b | 7455 | tls_mask = *toc_tls; |
411e1bfb AM |
7456 | if (r_type == R_PPC64_TOC16_DS |
7457 | || r_type == R_PPC64_TOC16_LO_DS) | |
81407a69 AM |
7458 | { |
7459 | if (tls_mask != 0 | |
7460 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) | |
7461 | goto toctprel; | |
7462 | } | |
411e1bfb | 7463 | else |
951fd09b AM |
7464 | { |
7465 | /* If we found a GD reloc pair, then we might be | |
7466 | doing a GD->IE transition. */ | |
7467 | if (retval == 2) | |
7468 | { | |
7469 | tls_gd = TLS_TPRELGD; | |
7470 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7471 | goto tls_get_addr_check; | |
7472 | } | |
7473 | else if (retval == 3) | |
7474 | { | |
7475 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7476 | goto tls_get_addr_check; | |
7477 | } | |
7478 | } | |
411e1bfb AM |
7479 | } |
7480 | } | |
7481 | break; | |
7482 | ||
7483 | case R_PPC64_GOT_TPREL16_DS: | |
7484 | case R_PPC64_GOT_TPREL16_LO_DS: | |
951fd09b AM |
7485 | if (tls_mask != 0 |
7486 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7487 | { |
81407a69 | 7488 | toctprel: |
411e1bfb AM |
7489 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); |
7490 | insn &= 31 << 21; | |
7491 | insn |= 0x3c0d0000; /* addis 0,13,0 */ | |
7492 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
7493 | r_type = R_PPC64_TPREL16_HA; | |
7494 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7495 | } | |
7496 | break; | |
7497 | ||
7498 | case R_PPC64_TLS: | |
951fd09b | 7499 | if (tls_mask == 0) |
411e1bfb AM |
7500 | { |
7501 | /* Check for toc tls entries. */ | |
7502 | char *toc_tls; | |
7503 | ||
e7b938ca | 7504 | if (!get_tls_mask (&toc_tls, &local_syms, rel, input_bfd)) |
411e1bfb AM |
7505 | return FALSE; |
7506 | ||
7507 | if (toc_tls) | |
951fd09b | 7508 | tls_mask = *toc_tls; |
411e1bfb | 7509 | } |
951fd09b AM |
7510 | if (tls_mask != 0 |
7511 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7512 | { |
50bc7936 | 7513 | bfd_vma rtra; |
411e1bfb | 7514 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
772119ce | 7515 | if ((insn & ((0x3f << 26) | (31 << 11))) |
411e1bfb AM |
7516 | == ((31 << 26) | (13 << 11))) |
7517 | rtra = insn & ((1 << 26) - (1 << 16)); | |
772119ce | 7518 | else if ((insn & ((0x3f << 26) | (31 << 16))) |
411e1bfb AM |
7519 | == ((31 << 26) | (13 << 16))) |
7520 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
7521 | else | |
7522 | abort (); | |
7523 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
7524 | /* add -> addi. */ | |
7525 | insn = 14 << 26; | |
7526 | else if ((insn & (31 << 1)) == 23 << 1 | |
7527 | && ((insn & (31 << 6)) < 14 << 6 | |
7528 | || ((insn & (31 << 6)) >= 16 << 6 | |
7529 | && (insn & (31 << 6)) < 24 << 6))) | |
7530 | /* load and store indexed -> dform. */ | |
7531 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
7532 | else if ((insn & (31 << 1)) == 21 << 1 | |
7533 | && (insn & (0x1a << 6)) == 0) | |
7534 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
7535 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
7536 | | ((insn >> 6) & 1)); | |
7537 | else if ((insn & (31 << 1)) == 21 << 1 | |
7538 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
7539 | /* lwax -> lwa. */ | |
7540 | insn = (58 << 26) | 2; | |
7541 | else | |
7542 | abort (); | |
7543 | insn |= rtra; | |
7544 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
7545 | r_type = R_PPC64_TPREL16_LO; | |
7546 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7547 | /* Was PPC64_TLS which sits on insn boundary, now | |
7548 | PPC64_TPREL16_LO which is at insn+2. */ | |
7549 | rel->r_offset += 2; | |
7550 | } | |
7551 | break; | |
7552 | ||
411e1bfb AM |
7553 | case R_PPC64_GOT_TLSGD16_HI: |
7554 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b AM |
7555 | tls_gd = TLS_TPRELGD; |
7556 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7557 | goto tls_gdld_hi; | |
7558 | break; | |
7559 | ||
411e1bfb AM |
7560 | case R_PPC64_GOT_TLSLD16_HI: |
7561 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 7562 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
411e1bfb | 7563 | { |
951fd09b AM |
7564 | tls_gdld_hi: |
7565 | if ((tls_mask & tls_gd) != 0) | |
7566 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7567 | + R_PPC64_GOT_TPREL16_DS); | |
7568 | else | |
411e1bfb | 7569 | { |
951fd09b AM |
7570 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
7571 | rel->r_offset -= 2; | |
7572 | r_type = R_PPC64_NONE; | |
411e1bfb | 7573 | } |
951fd09b | 7574 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb AM |
7575 | } |
7576 | break; | |
7577 | ||
951fd09b AM |
7578 | case R_PPC64_GOT_TLSGD16: |
7579 | case R_PPC64_GOT_TLSGD16_LO: | |
7580 | tls_gd = TLS_TPRELGD; | |
7581 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7582 | goto tls_get_addr_check; | |
7583 | break; | |
411e1bfb | 7584 | |
951fd09b AM |
7585 | case R_PPC64_GOT_TLSLD16: |
7586 | case R_PPC64_GOT_TLSLD16_LO: | |
7587 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7588 | { | |
7589 | tls_get_addr_check: | |
7590 | if (rel + 1 < relend) | |
411e1bfb | 7591 | { |
951fd09b AM |
7592 | enum elf_ppc64_reloc_type r_type2; |
7593 | unsigned long r_symndx2; | |
7594 | struct elf_link_hash_entry *h2; | |
7595 | bfd_vma insn1, insn2, insn3; | |
7596 | bfd_vma offset; | |
7597 | ||
7598 | /* The next instruction should be a call to | |
7599 | __tls_get_addr. Peek at the reloc to be sure. */ | |
4ce794b7 | 7600 | r_type2 = ELF64_R_TYPE (rel[1].r_info); |
951fd09b AM |
7601 | r_symndx2 = ELF64_R_SYM (rel[1].r_info); |
7602 | if (r_symndx2 < symtab_hdr->sh_info | |
7603 | || (r_type2 != R_PPC64_REL14 | |
7604 | && r_type2 != R_PPC64_REL14_BRTAKEN | |
7605 | && r_type2 != R_PPC64_REL14_BRNTAKEN | |
7606 | && r_type2 != R_PPC64_REL24)) | |
7607 | break; | |
7608 | ||
7609 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
7610 | while (h2->root.type == bfd_link_hash_indirect | |
7611 | || h2->root.type == bfd_link_hash_warning) | |
7612 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
7613 | if (h2 == NULL || h2 != htab->tls_get_addr) | |
7614 | break; | |
7615 | ||
7616 | /* OK, it checks out. Replace the call. */ | |
7617 | offset = rel[1].r_offset; | |
7618 | insn1 = bfd_get_32 (output_bfd, | |
7619 | contents + rel->r_offset - 2); | |
7620 | insn3 = bfd_get_32 (output_bfd, | |
7621 | contents + offset + 4); | |
7622 | if ((tls_mask & tls_gd) != 0) | |
411e1bfb | 7623 | { |
951fd09b AM |
7624 | /* IE */ |
7625 | insn1 &= (1 << 26) - (1 << 2); | |
7626 | insn1 |= 58 << 26; /* ld */ | |
7627 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
7628 | rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); | |
7629 | if ((tls_mask & TLS_EXPLICIT) == 0) | |
7630 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7631 | + R_PPC64_GOT_TPREL16_DS); | |
7632 | else | |
7633 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; | |
7634 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7635 | } |
7636 | else | |
951fd09b AM |
7637 | { |
7638 | /* LE */ | |
7639 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ | |
7640 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7641 | if (tls_gd == 0) | |
7642 | { | |
7643 | /* Was an LD reloc. */ | |
7644 | r_symndx = 0; | |
7645 | rel->r_addend = htab->tls_sec->vma + DTP_OFFSET; | |
7646 | rel[1].r_addend = htab->tls_sec->vma + DTP_OFFSET; | |
7647 | } | |
7648 | r_type = R_PPC64_TPREL16_HA; | |
7649 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7650 | rel[1].r_info = ELF64_R_INFO (r_symndx, | |
7651 | R_PPC64_TPREL16_LO); | |
7652 | rel[1].r_offset += 2; | |
7653 | } | |
7654 | if (insn3 == NOP | |
7655 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
7656 | { | |
7657 | insn3 = insn2; | |
7658 | insn2 = NOP; | |
7659 | rel[1].r_offset += 4; | |
7660 | } | |
7661 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); | |
7662 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7663 | bfd_put_32 (output_bfd, insn3, contents + offset + 4); | |
7664 | if (tls_gd == 0) | |
7665 | { | |
7666 | /* We changed the symbol on an LD reloc. Start over | |
ad8e1ba5 | 7667 | in order to get h, sym, sec etc. right. */ |
951fd09b AM |
7668 | rel--; |
7669 | continue; | |
7670 | } | |
411e1bfb | 7671 | } |
411e1bfb | 7672 | } |
411e1bfb AM |
7673 | break; |
7674 | ||
7675 | case R_PPC64_DTPMOD64: | |
951fd09b AM |
7676 | if (rel + 1 < relend |
7677 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
7678 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 7679 | { |
951fd09b AM |
7680 | if ((tls_mask & TLS_GD) == 0) |
7681 | { | |
7682 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); | |
7683 | if ((tls_mask & TLS_TPRELGD) != 0) | |
7684 | r_type = R_PPC64_TPREL64; | |
7685 | else | |
7686 | { | |
4ce794b7 | 7687 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
951fd09b AM |
7688 | r_type = R_PPC64_NONE; |
7689 | } | |
7690 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7691 | } | |
7692 | } | |
7693 | else | |
7694 | { | |
7695 | if ((tls_mask & TLS_LD) == 0) | |
411e1bfb | 7696 | { |
4ce794b7 | 7697 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
411e1bfb | 7698 | r_type = R_PPC64_NONE; |
951fd09b | 7699 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb | 7700 | } |
411e1bfb AM |
7701 | } |
7702 | break; | |
7703 | ||
7704 | case R_PPC64_TPREL64: | |
951fd09b | 7705 | if ((tls_mask & TLS_TPREL) == 0) |
411e1bfb AM |
7706 | { |
7707 | r_type = R_PPC64_NONE; | |
7708 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7709 | } | |
7710 | break; | |
7711 | } | |
7712 | ||
7713 | /* Handle other relocations that tweak non-addend part of insn. */ | |
86c76c7b | 7714 | insn = 0; |
65f38f15 | 7715 | switch (r_type) |
5bd4f169 AM |
7716 | { |
7717 | default: | |
65f38f15 | 7718 | break; |
5bd4f169 | 7719 | |
65f38f15 AM |
7720 | /* Branch taken prediction relocations. */ |
7721 | case R_PPC64_ADDR14_BRTAKEN: | |
7722 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
7723 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
7724 | /* Fall thru. */ | |
65f38f15 | 7725 | |
86c76c7b | 7726 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
7727 | case R_PPC64_ADDR14_BRNTAKEN: |
7728 | case R_PPC64_REL14_BRNTAKEN: | |
411e1bfb AM |
7729 | insn |= bfd_get_32 (output_bfd, |
7730 | contents + rel->r_offset) & ~(0x01 << 21); | |
96e0dda4 AM |
7731 | if (is_power4) |
7732 | { | |
7733 | /* Set 'a' bit. This is 0b00010 in BO field for branch | |
7734 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
7735 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
7736 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
7737 | insn |= 0x02 << 21; | |
7738 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
7739 | insn |= 0x08 << 21; | |
7740 | else | |
7741 | break; | |
7742 | } | |
65f38f15 | 7743 | else |
96e0dda4 | 7744 | { |
411e1bfb | 7745 | from = (rel->r_offset |
805fc799 AM |
7746 | + input_section->output_offset |
7747 | + input_section->output_section->vma); | |
7748 | ||
96e0dda4 | 7749 | /* Invert 'y' bit if not the default. */ |
411e1bfb | 7750 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) |
96e0dda4 AM |
7751 | insn ^= 0x01 << 21; |
7752 | } | |
86c76c7b | 7753 | |
4ce794b7 | 7754 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
65f38f15 | 7755 | break; |
5bd4f169 | 7756 | |
65f38f15 | 7757 | case R_PPC64_REL24: |
ad8e1ba5 AM |
7758 | /* Calls to functions with a different TOC, such as calls to |
7759 | shared objects, need to alter the TOC pointer. This is | |
7760 | done using a linkage stub. A REL24 branching to these | |
7761 | linkage stubs needs to be followed by a nop, as the nop | |
7762 | will be replaced with an instruction to restore the TOC | |
7763 | base pointer. */ | |
7764 | if (((h != NULL | |
7765 | && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL | |
7766 | && fdh->plt.plist != NULL) | |
7767 | || ((fdh = h, sec) != NULL | |
7768 | && sec->output_section != NULL | |
7769 | && (htab->stub_group[sec->id].toc_off | |
7770 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 | 7771 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, |
ad8e1ba5 AM |
7772 | rel, htab)) != NULL |
7773 | && (stub_entry->stub_type == ppc_stub_plt_call | |
7774 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off | |
7775 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) | |
41bd81ab | 7776 | { |
b34976b6 | 7777 | bfd_boolean can_plt_call = 0; |
721956f4 | 7778 | |
411e1bfb | 7779 | if (rel->r_offset + 8 <= input_section->_cooked_size) |
41bd81ab | 7780 | { |
411e1bfb | 7781 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); |
721956f4 AM |
7782 | if (insn == NOP |
7783 | || insn == CROR_151515 || insn == CROR_313131) | |
41bd81ab | 7784 | { |
4ce794b7 | 7785 | bfd_put_32 (input_bfd, LD_R2_40R1, |
411e1bfb | 7786 | contents + rel->r_offset + 4); |
721956f4 | 7787 | can_plt_call = 1; |
41bd81ab | 7788 | } |
5bd4f169 | 7789 | } |
721956f4 AM |
7790 | |
7791 | if (!can_plt_call) | |
7792 | { | |
ad8e1ba5 AM |
7793 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7794 | { | |
7795 | /* If this is a plain branch rather than a branch | |
7796 | and link, don't require a nop. */ | |
7797 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
7798 | if ((insn & 1) == 0) | |
7799 | can_plt_call = 1; | |
7800 | } | |
6ab189d5 AM |
7801 | else if (h != NULL |
7802 | && strcmp (h->root.root.string, | |
7803 | ".__libc_start_main") == 0) | |
7804 | { | |
7805 | /* Allow crt1 branch to go via a toc adjusting stub. */ | |
7806 | can_plt_call = 1; | |
7807 | } | |
ad8e1ba5 AM |
7808 | else |
7809 | { | |
7810 | if (strcmp (input_section->output_section->name, | |
7811 | ".init") == 0 | |
7812 | || strcmp (input_section->output_section->name, | |
7813 | ".fini") == 0) | |
7814 | (*_bfd_error_handler) | |
7815 | (_("%s(%s+0x%lx): automatic multiple TOCs " | |
7816 | "not supported using your crt files; " | |
7817 | "recompile with -mminimal-toc or upgrade gcc"), | |
7818 | bfd_archive_filename (input_bfd), | |
7819 | input_section->name, | |
7820 | (long) rel->r_offset); | |
7821 | else | |
7822 | (*_bfd_error_handler) | |
7823 | (_("%s(%s+0x%lx): sibling call optimization to `%s' " | |
7824 | "does not allow automatic multiple TOCs; " | |
7825 | "recompile with -mminimal-toc or " | |
7826 | "-fno-optimize-sibling-calls, " | |
7827 | "or make `%s' extern"), | |
7828 | bfd_archive_filename (input_bfd), | |
7829 | input_section->name, | |
7830 | (long) rel->r_offset, | |
7831 | sym_name, | |
7832 | sym_name); | |
7833 | bfd_set_error (bfd_error_bad_value); | |
7834 | ret = FALSE; | |
7835 | } | |
721956f4 AM |
7836 | } |
7837 | ||
7838 | if (can_plt_call) | |
7839 | { | |
7840 | relocation = (stub_entry->stub_offset | |
7841 | + stub_entry->stub_sec->output_offset | |
7842 | + stub_entry->stub_sec->output_section->vma); | |
ad8e1ba5 AM |
7843 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7844 | unresolved_reloc = FALSE; | |
721956f4 | 7845 | } |
5bd4f169 | 7846 | } |
e86ce104 AM |
7847 | |
7848 | if (h != NULL | |
7849 | && h->root.type == bfd_link_hash_undefweak | |
721956f4 | 7850 | && relocation == 0 |
411e1bfb | 7851 | && rel->r_addend == 0) |
e86ce104 | 7852 | { |
721956f4 AM |
7853 | /* Tweak calls to undefined weak functions to point at a |
7854 | blr. We can thus call a weak function without first | |
7855 | checking whether the function is defined. We have a | |
7856 | blr at the end of .sfpr. */ | |
805fc799 | 7857 | BFD_ASSERT (htab->sfpr->_raw_size != 0); |
721956f4 AM |
7858 | relocation = (htab->sfpr->_raw_size - 4 |
7859 | + htab->sfpr->output_offset | |
7860 | + htab->sfpr->output_section->vma); | |
411e1bfb | 7861 | from = (rel->r_offset |
721956f4 AM |
7862 | + input_section->output_offset |
7863 | + input_section->output_section->vma); | |
805fc799 | 7864 | |
721956f4 AM |
7865 | /* But let's not be silly about it. If the blr isn't in |
7866 | reach, just go to the next instruction. */ | |
805fc799 AM |
7867 | if (relocation - from + (1 << 25) >= (1 << 26) |
7868 | || htab->sfpr->_raw_size == 0) | |
721956f4 | 7869 | relocation = from + 4; |
e86ce104 | 7870 | } |
65f38f15 AM |
7871 | break; |
7872 | } | |
5bd4f169 | 7873 | |
65f38f15 | 7874 | /* Set `addend'. */ |
411e1bfb AM |
7875 | tls_type = 0; |
7876 | addend = rel->r_addend; | |
65f38f15 AM |
7877 | switch (r_type) |
7878 | { | |
7879 | default: | |
7880 | (*_bfd_error_handler) | |
7881 | (_("%s: unknown relocation type %d for symbol %s"), | |
7882 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); | |
5bd4f169 | 7883 | |
65f38f15 | 7884 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 7885 | ret = FALSE; |
65f38f15 | 7886 | continue; |
5bd4f169 | 7887 | |
65f38f15 | 7888 | case R_PPC64_NONE: |
411e1bfb | 7889 | case R_PPC64_TLS: |
04c9666a AM |
7890 | case R_PPC64_GNU_VTINHERIT: |
7891 | case R_PPC64_GNU_VTENTRY: | |
65f38f15 | 7892 | continue; |
5bd4f169 AM |
7893 | |
7894 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
7895 | address in the GOT as relocation value instead of the | |
411e1bfb | 7896 | symbol's value itself. Also, create a GOT entry for the |
5bd4f169 | 7897 | symbol and put the symbol value there. */ |
411e1bfb AM |
7898 | case R_PPC64_GOT_TLSGD16: |
7899 | case R_PPC64_GOT_TLSGD16_LO: | |
7900 | case R_PPC64_GOT_TLSGD16_HI: | |
7901 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 7902 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
7903 | goto dogot; |
7904 | ||
7905 | case R_PPC64_GOT_TLSLD16: | |
7906 | case R_PPC64_GOT_TLSLD16_LO: | |
7907 | case R_PPC64_GOT_TLSLD16_HI: | |
7908 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 7909 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
7910 | goto dogot; |
7911 | ||
7912 | case R_PPC64_GOT_TPREL16_DS: | |
7913 | case R_PPC64_GOT_TPREL16_LO_DS: | |
7914 | case R_PPC64_GOT_TPREL16_HI: | |
7915 | case R_PPC64_GOT_TPREL16_HA: | |
7916 | tls_type = TLS_TLS | TLS_TPREL; | |
7917 | goto dogot; | |
7918 | ||
7919 | case R_PPC64_GOT_DTPREL16_DS: | |
7920 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
7921 | case R_PPC64_GOT_DTPREL16_HI: | |
7922 | case R_PPC64_GOT_DTPREL16_HA: | |
7923 | tls_type = TLS_TLS | TLS_DTPREL; | |
7924 | goto dogot; | |
7925 | ||
65f38f15 AM |
7926 | case R_PPC64_GOT16: |
7927 | case R_PPC64_GOT16_LO: | |
7928 | case R_PPC64_GOT16_HI: | |
7929 | case R_PPC64_GOT16_HA: | |
7930 | case R_PPC64_GOT16_DS: | |
7931 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb | 7932 | dogot: |
5bd4f169 AM |
7933 | { |
7934 | /* Relocation is to the entry for this symbol in the global | |
7935 | offset table. */ | |
e717da7e | 7936 | asection *got; |
d881513a | 7937 | bfd_vma *offp; |
5bd4f169 | 7938 | bfd_vma off; |
d881513a | 7939 | unsigned long indx = 0; |
65f38f15 | 7940 | |
d881513a AM |
7941 | if (tls_type == (TLS_TLS | TLS_LD) |
7942 | && (h == NULL | |
7943 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
e717da7e | 7944 | offp = &ppc64_tlsld_got (input_bfd)->offset; |
411e1bfb | 7945 | else |
5bd4f169 | 7946 | { |
d881513a | 7947 | struct got_entry *ent; |
5bd4f169 | 7948 | |
d881513a AM |
7949 | if (h != NULL) |
7950 | { | |
7951 | bfd_boolean dyn = htab->elf.dynamic_sections_created; | |
f4656909 | 7952 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
d881513a | 7953 | || (info->shared |
586119b3 | 7954 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
d881513a AM |
7955 | /* This is actually a static link, or it is a |
7956 | -Bsymbolic link and the symbol is defined | |
7957 | locally, or the symbol was forced to be local | |
7958 | because of a version file. */ | |
7959 | ; | |
7960 | else | |
7961 | { | |
7962 | indx = h->dynindx; | |
7963 | unresolved_reloc = FALSE; | |
7964 | } | |
7965 | ent = h->got.glist; | |
7966 | } | |
411e1bfb | 7967 | else |
5bd4f169 | 7968 | { |
d881513a AM |
7969 | if (local_got_ents == NULL) |
7970 | abort (); | |
7971 | ent = local_got_ents[r_symndx]; | |
5bd4f169 | 7972 | } |
d881513a AM |
7973 | |
7974 | for (; ent != NULL; ent = ent->next) | |
7975 | if (ent->addend == rel->r_addend | |
e717da7e | 7976 | && ent->owner == input_bfd |
d881513a AM |
7977 | && ent->tls_type == tls_type) |
7978 | break; | |
7979 | if (ent == NULL) | |
7980 | abort (); | |
7981 | offp = &ent->got.offset; | |
5bd4f169 | 7982 | } |
411e1bfb | 7983 | |
e717da7e AM |
7984 | got = ppc64_elf_tdata (input_bfd)->got; |
7985 | if (got == NULL) | |
7986 | abort (); | |
7987 | ||
411e1bfb AM |
7988 | /* The offset must always be a multiple of 8. We use the |
7989 | least significant bit to record whether we have already | |
7990 | processed this entry. */ | |
d881513a | 7991 | off = *offp; |
411e1bfb AM |
7992 | if ((off & 1) != 0) |
7993 | off &= ~1; | |
5bd4f169 AM |
7994 | else |
7995 | { | |
411e1bfb AM |
7996 | /* Generate relocs for the dynamic linker, except in |
7997 | the case of TLSLD where we'll use one entry per | |
7998 | module. */ | |
e717da7e AM |
7999 | asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; |
8000 | ||
d881513a | 8001 | *offp = off | 1; |
4e795f50 AM |
8002 | if ((info->shared || indx != 0) |
8003 | && (h == NULL | |
8004 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8005 | || h->root.type != bfd_link_hash_undefweak)) | |
5bd4f169 | 8006 | { |
e717da7e AM |
8007 | outrel.r_offset = (got->output_section->vma |
8008 | + got->output_offset | |
411e1bfb | 8009 | + off); |
81407a69 | 8010 | outrel.r_addend = rel->r_addend; |
d881513a | 8011 | if (tls_type & (TLS_LD | TLS_GD)) |
5bd4f169 | 8012 | { |
411e1bfb | 8013 | outrel.r_addend = 0; |
e515b051 | 8014 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
d881513a AM |
8015 | if (tls_type == (TLS_TLS | TLS_GD)) |
8016 | { | |
e717da7e AM |
8017 | loc = relgot->contents; |
8018 | loc += (relgot->reloc_count++ | |
d881513a AM |
8019 | * sizeof (Elf64_External_Rela)); |
8020 | bfd_elf64_swap_reloca_out (output_bfd, | |
8021 | &outrel, loc); | |
e515b051 | 8022 | outrel.r_offset += 8; |
81407a69 | 8023 | outrel.r_addend = rel->r_addend; |
d881513a AM |
8024 | outrel.r_info |
8025 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); | |
d881513a | 8026 | } |
411e1bfb | 8027 | } |
951fd09b | 8028 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
411e1bfb | 8029 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
951fd09b | 8030 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb AM |
8031 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
8032 | else if (indx == 0) | |
81407a69 AM |
8033 | { |
8034 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE); | |
8035 | ||
8036 | /* Write the .got section contents for the sake | |
8037 | of prelink. */ | |
e717da7e | 8038 | loc = got->contents + off; |
23fbd6fa JJ |
8039 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
8040 | loc); | |
81407a69 | 8041 | } |
411e1bfb AM |
8042 | else |
8043 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); | |
81407a69 AM |
8044 | |
8045 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) | |
e515b051 AM |
8046 | { |
8047 | outrel.r_addend += relocation; | |
8048 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
8049 | outrel.r_addend -= htab->tls_sec->vma; | |
8050 | } | |
e717da7e AM |
8051 | loc = relgot->contents; |
8052 | loc += (relgot->reloc_count++ | |
411e1bfb AM |
8053 | * sizeof (Elf64_External_Rela)); |
8054 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
8055 | } | |
8056 | ||
ad8e1ba5 | 8057 | /* Init the .got section contents here if we're not |
81407a69 | 8058 | emitting a reloc. */ |
d881513a | 8059 | else |
411e1bfb | 8060 | { |
d881513a | 8061 | relocation += rel->r_addend; |
7b609f53 AM |
8062 | if (tls_type == (TLS_TLS | TLS_LD)) |
8063 | relocation = 1; | |
8064 | else if (tls_type != 0) | |
411e1bfb AM |
8065 | { |
8066 | relocation -= htab->tls_sec->vma + DTP_OFFSET; | |
7b609f53 | 8067 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 8068 | relocation += DTP_OFFSET - TP_OFFSET; |
5bd4f169 | 8069 | |
7b609f53 AM |
8070 | if (tls_type == (TLS_TLS | TLS_GD)) |
8071 | { | |
8072 | bfd_put_64 (output_bfd, relocation, | |
e717da7e | 8073 | got->contents + off + 8); |
7b609f53 AM |
8074 | relocation = 1; |
8075 | } | |
411e1bfb | 8076 | } |
7b609f53 | 8077 | |
411e1bfb | 8078 | bfd_put_64 (output_bfd, relocation, |
e717da7e | 8079 | got->contents + off); |
5bd4f169 AM |
8080 | } |
8081 | } | |
8082 | ||
65f38f15 AM |
8083 | if (off >= (bfd_vma) -2) |
8084 | abort (); | |
8085 | ||
e717da7e | 8086 | relocation = got->output_offset + off; |
65f38f15 | 8087 | |
5bd4f169 | 8088 | /* TOC base (r2) is TOC start plus 0x8000. */ |
e717da7e | 8089 | addend = -TOC_BASE_OFF; |
5bd4f169 | 8090 | } |
65f38f15 AM |
8091 | break; |
8092 | ||
8093 | case R_PPC64_PLT16_HA: | |
8094 | case R_PPC64_PLT16_HI: | |
8095 | case R_PPC64_PLT16_LO: | |
8096 | case R_PPC64_PLT32: | |
8097 | case R_PPC64_PLT64: | |
8098 | /* Relocation is to the entry for this symbol in the | |
8099 | procedure linkage table. */ | |
8100 | ||
8101 | /* Resolve a PLT reloc against a local symbol directly, | |
8102 | without using the procedure linkage table. */ | |
8103 | if (h == NULL) | |
8104 | break; | |
8105 | ||
411e1bfb AM |
8106 | /* It's possible that we didn't make a PLT entry for this |
8107 | symbol. This happens when statically linking PIC code, | |
8108 | or when using -Bsymbolic. Go find a match if there is a | |
8109 | PLT entry. */ | |
4ce794b7 | 8110 | if (htab->plt != NULL) |
65f38f15 | 8111 | { |
411e1bfb AM |
8112 | struct plt_entry *ent; |
8113 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8114 | if (ent->addend == rel->r_addend | |
8115 | && ent->plt.offset != (bfd_vma) -1) | |
8116 | { | |
4ce794b7 AM |
8117 | relocation = (htab->plt->output_section->vma |
8118 | + htab->plt->output_offset | |
411e1bfb AM |
8119 | + ent->plt.offset); |
8120 | unresolved_reloc = FALSE; | |
8121 | } | |
65f38f15 | 8122 | } |
65f38f15 | 8123 | break; |
5bd4f169 | 8124 | |
0b13192e AM |
8125 | case R_PPC64_TOC: |
8126 | /* Relocation value is TOC base. */ | |
8127 | relocation = TOCstart; | |
8128 | if (r_symndx == 0) | |
8129 | relocation += htab->stub_group[input_section->id].toc_off; | |
8130 | else if (sec != NULL && !unresolved_reloc) | |
8131 | relocation += htab->stub_group[sec->id].toc_off; | |
8132 | else | |
8133 | unresolved_reloc = TRUE; | |
8134 | goto dodyn2; | |
8135 | ||
5bd4f169 AM |
8136 | /* TOC16 relocs. We want the offset relative to the TOC base, |
8137 | which is the address of the start of the TOC plus 0x8000. | |
8138 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
8139 | in this order. */ | |
65f38f15 AM |
8140 | case R_PPC64_TOC16: |
8141 | case R_PPC64_TOC16_LO: | |
8142 | case R_PPC64_TOC16_HI: | |
8143 | case R_PPC64_TOC16_DS: | |
8144 | case R_PPC64_TOC16_LO_DS: | |
8145 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 8146 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
5bd4f169 AM |
8147 | break; |
8148 | ||
8149 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
8150 | case R_PPC64_SECTOFF: |
8151 | case R_PPC64_SECTOFF_LO: | |
8152 | case R_PPC64_SECTOFF_HI: | |
8153 | case R_PPC64_SECTOFF_DS: | |
8154 | case R_PPC64_SECTOFF_LO_DS: | |
8155 | case R_PPC64_SECTOFF_HA: | |
4ce794b7 | 8156 | if (sec != NULL) |
65f38f15 | 8157 | addend -= sec->output_section->vma; |
5bd4f169 AM |
8158 | break; |
8159 | ||
721956f4 AM |
8160 | case R_PPC64_REL14: |
8161 | case R_PPC64_REL14_BRNTAKEN: | |
8162 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
8163 | case R_PPC64_REL24: |
8164 | break; | |
8165 | ||
411e1bfb AM |
8166 | case R_PPC64_TPREL16: |
8167 | case R_PPC64_TPREL16_LO: | |
8168 | case R_PPC64_TPREL16_HI: | |
8169 | case R_PPC64_TPREL16_HA: | |
8170 | case R_PPC64_TPREL16_DS: | |
8171 | case R_PPC64_TPREL16_LO_DS: | |
8172 | case R_PPC64_TPREL16_HIGHER: | |
8173 | case R_PPC64_TPREL16_HIGHERA: | |
8174 | case R_PPC64_TPREL16_HIGHEST: | |
8175 | case R_PPC64_TPREL16_HIGHESTA: | |
8176 | addend -= htab->tls_sec->vma + TP_OFFSET; | |
8177 | if (info->shared) | |
8178 | /* The TPREL16 relocs shouldn't really be used in shared | |
8179 | libs as they will result in DT_TEXTREL being set, but | |
8180 | support them anyway. */ | |
8181 | goto dodyn; | |
8182 | break; | |
8183 | ||
8184 | case R_PPC64_DTPREL16: | |
8185 | case R_PPC64_DTPREL16_LO: | |
8186 | case R_PPC64_DTPREL16_HI: | |
8187 | case R_PPC64_DTPREL16_HA: | |
8188 | case R_PPC64_DTPREL16_DS: | |
8189 | case R_PPC64_DTPREL16_LO_DS: | |
8190 | case R_PPC64_DTPREL16_HIGHER: | |
8191 | case R_PPC64_DTPREL16_HIGHERA: | |
8192 | case R_PPC64_DTPREL16_HIGHEST: | |
8193 | case R_PPC64_DTPREL16_HIGHESTA: | |
8194 | addend -= htab->tls_sec->vma + DTP_OFFSET; | |
8195 | break; | |
8196 | ||
e515b051 AM |
8197 | case R_PPC64_DTPMOD64: |
8198 | relocation = 1; | |
8199 | addend = 0; | |
8200 | goto dodyn; | |
8201 | ||
411e1bfb AM |
8202 | case R_PPC64_TPREL64: |
8203 | addend -= htab->tls_sec->vma + TP_OFFSET; | |
8204 | goto dodyn; | |
8205 | ||
8206 | case R_PPC64_DTPREL64: | |
8207 | addend -= htab->tls_sec->vma + DTP_OFFSET; | |
8208 | /* Fall thru */ | |
8209 | ||
65f38f15 AM |
8210 | /* Relocations that may need to be propagated if this is a |
8211 | dynamic object. */ | |
04c9666a | 8212 | case R_PPC64_REL30: |
65f38f15 AM |
8213 | case R_PPC64_REL32: |
8214 | case R_PPC64_REL64: | |
8215 | case R_PPC64_ADDR14: | |
8216 | case R_PPC64_ADDR14_BRNTAKEN: | |
8217 | case R_PPC64_ADDR14_BRTAKEN: | |
8218 | case R_PPC64_ADDR16: | |
8219 | case R_PPC64_ADDR16_DS: | |
8220 | case R_PPC64_ADDR16_HA: | |
8221 | case R_PPC64_ADDR16_HI: | |
8222 | case R_PPC64_ADDR16_HIGHER: | |
8223 | case R_PPC64_ADDR16_HIGHERA: | |
8224 | case R_PPC64_ADDR16_HIGHEST: | |
8225 | case R_PPC64_ADDR16_HIGHESTA: | |
8226 | case R_PPC64_ADDR16_LO: | |
8227 | case R_PPC64_ADDR16_LO_DS: | |
8228 | case R_PPC64_ADDR24: | |
65f38f15 AM |
8229 | case R_PPC64_ADDR32: |
8230 | case R_PPC64_ADDR64: | |
8231 | case R_PPC64_UADDR16: | |
8232 | case R_PPC64_UADDR32: | |
8233 | case R_PPC64_UADDR64: | |
ec338859 AM |
8234 | /* r_symndx will be zero only for relocs against symbols |
8235 | from removed linkonce sections, or sections discarded by | |
8236 | a linker script. */ | |
411e1bfb | 8237 | dodyn: |
5d1634d7 AM |
8238 | if (r_symndx == 0) |
8239 | break; | |
8240 | /* Fall thru. */ | |
8241 | ||
0b13192e | 8242 | dodyn2: |
5d1634d7 | 8243 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
8244 | break; |
8245 | ||
41bd81ab AM |
8246 | if (NO_OPD_RELOCS && is_opd) |
8247 | break; | |
8248 | ||
65f38f15 | 8249 | if ((info->shared |
4e795f50 AM |
8250 | && (h == NULL |
8251 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8252 | || h->root.type != bfd_link_hash_undefweak) | |
411e1bfb | 8253 | && (MUST_BE_DYN_RELOC (r_type) |
f6c52c13 | 8254 | || !SYMBOL_CALLS_LOCAL (info, h))) |
f4656909 AM |
8255 | || (ELIMINATE_COPY_RELOCS |
8256 | && !info->shared | |
65f38f15 AM |
8257 | && h != NULL |
8258 | && h->dynindx != -1 | |
8259 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
8260 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
8261 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
65f38f15 AM |
8262 | { |
8263 | Elf_Internal_Rela outrel; | |
b34976b6 | 8264 | bfd_boolean skip, relocate; |
65f38f15 | 8265 | asection *sreloc; |
947216bf | 8266 | bfd_byte *loc; |
1cf1f670 | 8267 | bfd_vma out_off; |
65f38f15 AM |
8268 | |
8269 | /* When generating a dynamic object, these relocations | |
8270 | are copied into the output file to be resolved at run | |
8271 | time. */ | |
8272 | ||
b34976b6 AM |
8273 | skip = FALSE; |
8274 | relocate = FALSE; | |
65f38f15 | 8275 | |
1cf1f670 AM |
8276 | out_off = _bfd_elf_section_offset (output_bfd, info, |
8277 | input_section, rel->r_offset); | |
8278 | if (out_off == (bfd_vma) -1) | |
b34976b6 | 8279 | skip = TRUE; |
1cf1f670 | 8280 | else if (out_off == (bfd_vma) -2) |
b34976b6 | 8281 | skip = TRUE, relocate = TRUE; |
1cf1f670 AM |
8282 | out_off += (input_section->output_section->vma |
8283 | + input_section->output_offset); | |
8284 | outrel.r_offset = out_off; | |
411e1bfb | 8285 | outrel.r_addend = rel->r_addend; |
65f38f15 | 8286 | |
1cf1f670 AM |
8287 | /* Optimize unaligned reloc use. */ |
8288 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) | |
8289 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) | |
8290 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; | |
8291 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) | |
8292 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) | |
8293 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; | |
8294 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) | |
8295 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) | |
8296 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; | |
8297 | ||
65f38f15 | 8298 | if (skip) |
0bb2d96a | 8299 | memset (&outrel, 0, sizeof outrel); |
f6c52c13 | 8300 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
0b13192e AM |
8301 | && !is_opd |
8302 | && r_type != R_PPC64_TOC) | |
0bb2d96a | 8303 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
65f38f15 AM |
8304 | else |
8305 | { | |
41bd81ab AM |
8306 | /* This symbol is local, or marked to become local, |
8307 | or this is an opd section reloc which must point | |
8308 | at a local function. */ | |
65f38f15 | 8309 | outrel.r_addend += relocation; |
e86ce104 | 8310 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 8311 | { |
3fad3c7c | 8312 | if (is_opd && h != NULL) |
afbe61cf AM |
8313 | { |
8314 | /* Lie about opd entries. This case occurs | |
8315 | when building shared libraries and we | |
8316 | reference a function in another shared | |
3fad3c7c AM |
8317 | lib. The same thing happens for a weak |
8318 | definition in an application that's | |
8319 | overridden by a strong definition in a | |
8320 | shared lib. (I believe this is a generic | |
8321 | bug in binutils handling of weak syms.) | |
8322 | In these cases we won't use the opd | |
1e2f5b6e | 8323 | entry in this lib. */ |
b34976b6 | 8324 | unresolved_reloc = FALSE; |
afbe61cf | 8325 | } |
65f38f15 | 8326 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
81407a69 AM |
8327 | |
8328 | /* We need to relocate .opd contents for ld.so. | |
8329 | Prelink also wants simple and consistent rules | |
8330 | for relocs. This make all RELATIVE relocs have | |
8331 | *r_offset equal to r_addend. */ | |
8332 | relocate = TRUE; | |
65f38f15 AM |
8333 | } |
8334 | else | |
8335 | { | |
8336 | long indx = 0; | |
8337 | ||
41bd81ab | 8338 | if (bfd_is_abs_section (sec)) |
65f38f15 AM |
8339 | ; |
8340 | else if (sec == NULL || sec->owner == NULL) | |
8341 | { | |
8342 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8343 | return FALSE; |
65f38f15 AM |
8344 | } |
8345 | else | |
8346 | { | |
8347 | asection *osec; | |
8348 | ||
8349 | osec = sec->output_section; | |
8350 | indx = elf_section_data (osec)->dynindx; | |
8351 | ||
8352 | /* We are turning this relocation into one | |
8353 | against a section symbol, so subtract out | |
8354 | the output section's address but not the | |
8355 | offset of the input section in the output | |
8356 | section. */ | |
8357 | outrel.r_addend -= osec->vma; | |
8358 | } | |
8359 | ||
8360 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
8361 | } | |
8362 | } | |
8363 | ||
8364 | sreloc = elf_section_data (input_section)->sreloc; | |
8365 | if (sreloc == NULL) | |
8366 | abort (); | |
8367 | ||
947216bf AM |
8368 | loc = sreloc->contents; |
8369 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
8370 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
8371 | ||
8372 | /* If this reloc is against an external symbol, it will | |
8373 | be computed at runtime, so there's no need to do | |
81407a69 AM |
8374 | anything now. However, for the sake of prelink ensure |
8375 | that the section contents are a known value. */ | |
65f38f15 | 8376 | if (! relocate) |
81407a69 AM |
8377 | { |
8378 | unresolved_reloc = FALSE; | |
8379 | /* The value chosen here is quite arbitrary as ld.so | |
8380 | ignores section contents except for the special | |
8381 | case of .opd where the contents might be accessed | |
8382 | before relocation. Choose zero, as that won't | |
8383 | cause reloc overflow. */ | |
8384 | relocation = 0; | |
8385 | addend = 0; | |
8386 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs | |
8387 | to improve backward compatibility with older | |
8388 | versions of ld. */ | |
8389 | if (r_type == R_PPC64_ADDR64) | |
8390 | addend = outrel.r_addend; | |
8391 | /* Adjust pc_relative relocs to have zero in *r_offset. */ | |
4ce794b7 | 8392 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
000732f7 AM |
8393 | addend = (input_section->output_section->vma |
8394 | + input_section->output_offset | |
8395 | + rel->r_offset); | |
81407a69 | 8396 | } |
65f38f15 | 8397 | } |
5bd4f169 AM |
8398 | break; |
8399 | ||
65f38f15 AM |
8400 | case R_PPC64_COPY: |
8401 | case R_PPC64_GLOB_DAT: | |
8402 | case R_PPC64_JMP_SLOT: | |
8403 | case R_PPC64_RELATIVE: | |
8404 | /* We shouldn't ever see these dynamic relocs in relocatable | |
8405 | files. */ | |
ae9a127f | 8406 | /* Fall through. */ |
65f38f15 AM |
8407 | |
8408 | case R_PPC64_PLTGOT16: | |
8409 | case R_PPC64_PLTGOT16_DS: | |
8410 | case R_PPC64_PLTGOT16_HA: | |
8411 | case R_PPC64_PLTGOT16_HI: | |
8412 | case R_PPC64_PLTGOT16_LO: | |
8413 | case R_PPC64_PLTGOT16_LO_DS: | |
8414 | case R_PPC64_PLTREL32: | |
8415 | case R_PPC64_PLTREL64: | |
8416 | /* These ones haven't been implemented yet. */ | |
8417 | ||
8418 | (*_bfd_error_handler) | |
7b609f53 | 8419 | (_("%s: relocation %s is not supported for symbol %s."), |
65f38f15 | 8420 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8421 | ppc64_elf_howto_table[r_type]->name, sym_name); |
5bd4f169 AM |
8422 | |
8423 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 8424 | ret = FALSE; |
5bd4f169 | 8425 | continue; |
65f38f15 | 8426 | } |
5bd4f169 | 8427 | |
65f38f15 AM |
8428 | /* Do any further special processing. */ |
8429 | switch (r_type) | |
8430 | { | |
8431 | default: | |
8432 | break; | |
8433 | ||
8434 | case R_PPC64_ADDR16_HA: | |
8435 | case R_PPC64_ADDR16_HIGHERA: | |
8436 | case R_PPC64_ADDR16_HIGHESTA: | |
86bbe32f AM |
8437 | case R_PPC64_GOT16_HA: |
8438 | case R_PPC64_PLTGOT16_HA: | |
65f38f15 AM |
8439 | case R_PPC64_PLT16_HA: |
8440 | case R_PPC64_TOC16_HA: | |
8441 | case R_PPC64_SECTOFF_HA: | |
411e1bfb AM |
8442 | case R_PPC64_TPREL16_HA: |
8443 | case R_PPC64_DTPREL16_HA: | |
8444 | case R_PPC64_GOT_TLSGD16_HA: | |
8445 | case R_PPC64_GOT_TLSLD16_HA: | |
8446 | case R_PPC64_GOT_TPREL16_HA: | |
8447 | case R_PPC64_GOT_DTPREL16_HA: | |
8448 | case R_PPC64_TPREL16_HIGHER: | |
8449 | case R_PPC64_TPREL16_HIGHERA: | |
8450 | case R_PPC64_TPREL16_HIGHEST: | |
8451 | case R_PPC64_TPREL16_HIGHESTA: | |
8452 | case R_PPC64_DTPREL16_HIGHER: | |
8453 | case R_PPC64_DTPREL16_HIGHERA: | |
8454 | case R_PPC64_DTPREL16_HIGHEST: | |
8455 | case R_PPC64_DTPREL16_HIGHESTA: | |
65f38f15 AM |
8456 | /* It's just possible that this symbol is a weak symbol |
8457 | that's not actually defined anywhere. In that case, | |
8458 | 'sec' would be NULL, and we should leave the symbol | |
8459 | alone (it will be set to zero elsewhere in the link). */ | |
8460 | if (sec != NULL) | |
e515b051 AM |
8461 | /* Add 0x10000 if sign bit in 0:15 is set. |
8462 | Bits 0:15 are not used. */ | |
8463 | addend += 0x8000; | |
65f38f15 AM |
8464 | break; |
8465 | ||
8466 | case R_PPC64_ADDR16_DS: | |
8467 | case R_PPC64_ADDR16_LO_DS: | |
8468 | case R_PPC64_GOT16_DS: | |
8469 | case R_PPC64_GOT16_LO_DS: | |
8470 | case R_PPC64_PLT16_LO_DS: | |
8471 | case R_PPC64_SECTOFF_DS: | |
8472 | case R_PPC64_SECTOFF_LO_DS: | |
8473 | case R_PPC64_TOC16_DS: | |
8474 | case R_PPC64_TOC16_LO_DS: | |
8475 | case R_PPC64_PLTGOT16_DS: | |
8476 | case R_PPC64_PLTGOT16_LO_DS: | |
411e1bfb AM |
8477 | case R_PPC64_GOT_TPREL16_DS: |
8478 | case R_PPC64_GOT_TPREL16_LO_DS: | |
8479 | case R_PPC64_GOT_DTPREL16_DS: | |
8480 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
8481 | case R_PPC64_TPREL16_DS: | |
8482 | case R_PPC64_TPREL16_LO_DS: | |
8483 | case R_PPC64_DTPREL16_DS: | |
8484 | case R_PPC64_DTPREL16_LO_DS: | |
adadcc0c AM |
8485 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
8486 | mask = 3; | |
8487 | /* If this reloc is against an lq insn, then the value must be | |
8488 | a multiple of 16. This is somewhat of a hack, but the | |
8489 | "correct" way to do this by defining _DQ forms of all the | |
8490 | _DS relocs bloats all reloc switches in this file. It | |
8491 | doesn't seem to make much sense to use any of these relocs | |
8492 | in data, so testing the insn should be safe. */ | |
494dac0c | 8493 | if ((insn & (0x3f << 26)) == (56u << 26)) |
adadcc0c AM |
8494 | mask = 15; |
8495 | if (((relocation + addend) & mask) != 0) | |
65f38f15 AM |
8496 | { |
8497 | (*_bfd_error_handler) | |
adadcc0c | 8498 | (_("%s: error: relocation %s not a multiple of %d"), |
65f38f15 | 8499 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8500 | ppc64_elf_howto_table[r_type]->name, |
adadcc0c | 8501 | mask + 1); |
65f38f15 | 8502 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 8503 | ret = FALSE; |
65f38f15 AM |
8504 | continue; |
8505 | } | |
8506 | break; | |
721956f4 AM |
8507 | |
8508 | case R_PPC64_REL14: | |
8509 | case R_PPC64_REL14_BRNTAKEN: | |
8510 | case R_PPC64_REL14_BRTAKEN: | |
8511 | max_br_offset = 1 << 15; | |
8512 | goto branch_check; | |
8513 | ||
8514 | case R_PPC64_REL24: | |
8515 | max_br_offset = 1 << 25; | |
8516 | ||
8517 | branch_check: | |
ad8e1ba5 AM |
8518 | /* If the branch is out of reach or the TOC register needs |
8519 | adjusting, then redirect the call to the local stub for | |
8520 | this function. */ | |
411e1bfb | 8521 | from = (rel->r_offset |
721956f4 AM |
8522 | + input_section->output_offset |
8523 | + input_section->output_section->vma); | |
ad8e1ba5 AM |
8524 | if ((relocation + addend - from + max_br_offset >= 2 * max_br_offset |
8525 | || (sec != NULL | |
8526 | && sec->output_section != NULL | |
8f3bab57 | 8527 | && sec->id <= htab->top_id |
ad8e1ba5 AM |
8528 | && (htab->stub_group[sec->id].toc_off |
8529 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 AM |
8530 | && (stub_entry = ppc_get_stub_entry (input_section, sec, h, |
8531 | rel, htab)) != NULL) | |
8532 | { | |
8533 | /* Munge up the value and addend so that we call the stub | |
8534 | rather than the procedure directly. */ | |
8535 | relocation = (stub_entry->stub_offset | |
8536 | + stub_entry->stub_sec->output_offset | |
8537 | + stub_entry->stub_sec->output_section->vma); | |
8538 | addend = 0; | |
8539 | } | |
8540 | break; | |
5bd4f169 AM |
8541 | } |
8542 | ||
239e1f3a AM |
8543 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
8544 | because such sections are not SEC_ALLOC and thus ld.so will | |
8545 | not process them. */ | |
65f38f15 | 8546 | if (unresolved_reloc |
239e1f3a | 8547 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
65f38f15 | 8548 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
9c07fe7c AM |
8549 | { |
8550 | (*_bfd_error_handler) | |
7b609f53 | 8551 | (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), |
9c07fe7c AM |
8552 | bfd_archive_filename (input_bfd), |
8553 | bfd_get_section_name (input_bfd, input_section), | |
8554 | (long) rel->r_offset, | |
7b609f53 | 8555 | ppc64_elf_howto_table[(int) r_type]->name, |
9c07fe7c | 8556 | h->root.root.string); |
b34976b6 | 8557 | ret = FALSE; |
9c07fe7c | 8558 | } |
5bd4f169 | 8559 | |
65f38f15 | 8560 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
8561 | input_bfd, |
8562 | input_section, | |
8563 | contents, | |
411e1bfb | 8564 | rel->r_offset, |
5bd4f169 AM |
8565 | relocation, |
8566 | addend); | |
8567 | ||
ef60b7ff | 8568 | if (r != bfd_reloc_ok) |
5bd4f169 | 8569 | { |
cd27b276 AM |
8570 | if (sym_name == NULL) |
8571 | sym_name = "(null)"; | |
8572 | if (r == bfd_reloc_overflow) | |
5bd4f169 | 8573 | { |
cd27b276 AM |
8574 | if (warned) |
8575 | continue; | |
8576 | if (h != NULL | |
8577 | && h->root.type == bfd_link_hash_undefweak | |
4ce794b7 | 8578 | && ppc64_elf_howto_table[r_type]->pc_relative) |
5bd4f169 AM |
8579 | { |
8580 | /* Assume this is a call protected by other code that | |
8581 | detects the symbol is undefined. If this is the case, | |
8582 | we can safely ignore the overflow. If not, the | |
8583 | program is hosed anyway, and a little warning isn't | |
8584 | going to help. */ | |
8585 | ||
8586 | continue; | |
8587 | } | |
8588 | ||
ef60b7ff | 8589 | if (!((*info->callbacks->reloc_overflow) |
4ce794b7 | 8590 | (info, sym_name, ppc64_elf_howto_table[r_type]->name, |
411e1bfb | 8591 | rel->r_addend, input_bfd, input_section, rel->r_offset))) |
b34976b6 | 8592 | return FALSE; |
ef60b7ff AM |
8593 | } |
8594 | else | |
8595 | { | |
8596 | (*_bfd_error_handler) | |
7b609f53 | 8597 | (_("%s(%s+0x%lx): %s reloc against `%s': error %d"), |
ef60b7ff AM |
8598 | bfd_archive_filename (input_bfd), |
8599 | bfd_get_section_name (input_bfd, input_section), | |
7b609f53 | 8600 | (long) rel->r_offset, |
4ce794b7 | 8601 | ppc64_elf_howto_table[r_type]->name, |
7b609f53 AM |
8602 | sym_name, |
8603 | (int) r); | |
b34976b6 | 8604 | ret = FALSE; |
ef60b7ff | 8605 | } |
5bd4f169 | 8606 | } |
5bd4f169 AM |
8607 | } |
8608 | ||
5bd4f169 AM |
8609 | return ret; |
8610 | } | |
8611 | ||
8612 | /* Finish up dynamic symbol handling. We set the contents of various | |
8613 | dynamic sections here. */ | |
8614 | ||
b34976b6 | 8615 | static bfd_boolean |
4ce794b7 AM |
8616 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
8617 | struct bfd_link_info *info, | |
8618 | struct elf_link_hash_entry *h, | |
8619 | Elf_Internal_Sym *sym) | |
5bd4f169 | 8620 | { |
65f38f15 | 8621 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
8622 | bfd *dynobj; |
8623 | ||
65f38f15 AM |
8624 | htab = ppc_hash_table (info); |
8625 | dynobj = htab->elf.dynobj; | |
5bd4f169 | 8626 | |
411e1bfb | 8627 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
5bd4f169 | 8628 | { |
411e1bfb | 8629 | struct plt_entry *ent; |
65f38f15 | 8630 | Elf_Internal_Rela rela; |
947216bf | 8631 | bfd_byte *loc; |
5bd4f169 | 8632 | |
411e1bfb AM |
8633 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
8634 | if (ent->plt.offset != (bfd_vma) -1) | |
8635 | { | |
8636 | /* This symbol has an entry in the procedure linkage | |
8637 | table. Set it up. */ | |
5bd4f169 | 8638 | |
4ce794b7 AM |
8639 | if (htab->plt == NULL |
8640 | || htab->relplt == NULL | |
8641 | || htab->glink == NULL) | |
411e1bfb | 8642 | abort (); |
5bd4f169 | 8643 | |
411e1bfb AM |
8644 | /* Create a JMP_SLOT reloc to inform the dynamic linker to |
8645 | fill in the PLT entry. */ | |
4ce794b7 AM |
8646 | rela.r_offset = (htab->plt->output_section->vma |
8647 | + htab->plt->output_offset | |
411e1bfb AM |
8648 | + ent->plt.offset); |
8649 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); | |
8650 | rela.r_addend = ent->addend; | |
5bd4f169 | 8651 | |
4ce794b7 | 8652 | loc = htab->relplt->contents; |
411e1bfb AM |
8653 | loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE |
8654 | * sizeof (Elf64_External_Rela)); | |
8655 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
8656 | } | |
5bd4f169 AM |
8657 | } |
8658 | ||
8659 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
8660 | { | |
5bd4f169 | 8661 | Elf_Internal_Rela rela; |
947216bf | 8662 | bfd_byte *loc; |
5bd4f169 | 8663 | |
65f38f15 | 8664 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 8665 | |
65f38f15 AM |
8666 | if (h->dynindx == -1 |
8667 | || (h->root.type != bfd_link_hash_defined | |
8668 | && h->root.type != bfd_link_hash_defweak) | |
4ce794b7 | 8669 | || htab->relbss == NULL) |
65f38f15 | 8670 | abort (); |
5bd4f169 AM |
8671 | |
8672 | rela.r_offset = (h->root.u.def.value | |
8673 | + h->root.u.def.section->output_section->vma | |
8674 | + h->root.u.def.section->output_offset); | |
8675 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
8676 | rela.r_addend = 0; | |
4ce794b7 AM |
8677 | loc = htab->relbss->contents; |
8678 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 8679 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
8680 | } |
8681 | ||
5bd4f169 AM |
8682 | /* Mark some specially defined symbols as absolute. */ |
8683 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
8684 | sym->st_shndx = SHN_ABS; | |
8685 | ||
b34976b6 | 8686 | return TRUE; |
5bd4f169 AM |
8687 | } |
8688 | ||
65f38f15 AM |
8689 | /* Used to decide how to sort relocs in an optimal manner for the |
8690 | dynamic linker, before writing them out. */ | |
8691 | ||
8692 | static enum elf_reloc_type_class | |
4ce794b7 | 8693 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
65f38f15 | 8694 | { |
04c9666a | 8695 | enum elf_ppc64_reloc_type r_type; |
a33d1f77 | 8696 | |
4ce794b7 | 8697 | r_type = ELF64_R_TYPE (rela->r_info); |
a33d1f77 | 8698 | switch (r_type) |
65f38f15 AM |
8699 | { |
8700 | case R_PPC64_RELATIVE: | |
8701 | return reloc_class_relative; | |
8702 | case R_PPC64_JMP_SLOT: | |
8703 | return reloc_class_plt; | |
8704 | case R_PPC64_COPY: | |
8705 | return reloc_class_copy; | |
8706 | default: | |
8707 | return reloc_class_normal; | |
8708 | } | |
8709 | } | |
8710 | ||
5bd4f169 AM |
8711 | /* Finish up the dynamic sections. */ |
8712 | ||
b34976b6 | 8713 | static bfd_boolean |
4ce794b7 AM |
8714 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
8715 | struct bfd_link_info *info) | |
5bd4f169 | 8716 | { |
65f38f15 AM |
8717 | struct ppc_link_hash_table *htab; |
8718 | bfd *dynobj; | |
5bd4f169 | 8719 | asection *sdyn; |
5bd4f169 | 8720 | |
65f38f15 AM |
8721 | htab = ppc_hash_table (info); |
8722 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
8723 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
8724 | ||
65f38f15 | 8725 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 8726 | { |
5bd4f169 AM |
8727 | Elf64_External_Dyn *dyncon, *dynconend; |
8728 | ||
4ce794b7 | 8729 | if (sdyn == NULL || htab->got == NULL) |
65f38f15 | 8730 | abort (); |
5bd4f169 AM |
8731 | |
8732 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
8733 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
8734 | for (; dyncon < dynconend; dyncon++) | |
8735 | { | |
8736 | Elf_Internal_Dyn dyn; | |
19397422 | 8737 | asection *s; |
5bd4f169 AM |
8738 | |
8739 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
8740 | ||
8741 | switch (dyn.d_tag) | |
8742 | { | |
65f38f15 AM |
8743 | default: |
8744 | continue; | |
5bd4f169 | 8745 | |
5d1634d7 | 8746 | case DT_PPC64_GLINK: |
4ce794b7 | 8747 | s = htab->glink; |
6348e046 | 8748 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
ad8e1ba5 AM |
8749 | /* We stupidly defined DT_PPC64_GLINK to be the start |
8750 | of glink rather than the first entry point, which is | |
8751 | what ld.so needs, and now have a bigger stub to | |
8752 | support automatic multiple TOCs. */ | |
8753 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; | |
5d1634d7 AM |
8754 | break; |
8755 | ||
19397422 AM |
8756 | case DT_PPC64_OPD: |
8757 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8758 | if (s == NULL) |
8759 | continue; | |
8760 | dyn.d_un.d_ptr = s->vma; | |
19397422 AM |
8761 | break; |
8762 | ||
8763 | case DT_PPC64_OPDSZ: | |
8764 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8765 | if (s == NULL) |
8766 | continue; | |
8767 | dyn.d_un.d_val = s->_raw_size; | |
19397422 AM |
8768 | break; |
8769 | ||
65f38f15 | 8770 | case DT_PLTGOT: |
4ce794b7 | 8771 | s = htab->plt; |
6348e046 | 8772 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 AM |
8773 | break; |
8774 | ||
8775 | case DT_JMPREL: | |
4ce794b7 | 8776 | s = htab->relplt; |
6348e046 | 8777 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 | 8778 | break; |
5bd4f169 | 8779 | |
65f38f15 | 8780 | case DT_PLTRELSZ: |
4ce794b7 | 8781 | dyn.d_un.d_val = htab->relplt->_raw_size; |
5d1634d7 AM |
8782 | break; |
8783 | ||
8784 | case DT_RELASZ: | |
8785 | /* Don't count procedure linkage table relocs in the | |
8786 | overall reloc count. */ | |
4ce794b7 | 8787 | s = htab->relplt; |
6348e046 AM |
8788 | if (s == NULL) |
8789 | continue; | |
8790 | dyn.d_un.d_val -= s->_raw_size; | |
8791 | break; | |
8792 | ||
8793 | case DT_RELA: | |
8794 | /* We may not be using the standard ELF linker script. | |
8795 | If .rela.plt is the first .rela section, we adjust | |
8796 | DT_RELA to not include it. */ | |
4ce794b7 | 8797 | s = htab->relplt; |
6348e046 AM |
8798 | if (s == NULL) |
8799 | continue; | |
8800 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
8801 | continue; | |
8802 | dyn.d_un.d_ptr += s->_raw_size; | |
65f38f15 | 8803 | break; |
5bd4f169 | 8804 | } |
5bd4f169 | 8805 | |
65f38f15 | 8806 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 8807 | } |
5bd4f169 AM |
8808 | } |
8809 | ||
4ce794b7 | 8810 | if (htab->got != NULL && htab->got->_raw_size != 0) |
5d1634d7 AM |
8811 | { |
8812 | /* Fill in the first entry in the global offset table. | |
8813 | We use it to hold the link-time TOCbase. */ | |
8814 | bfd_put_64 (output_bfd, | |
60ee0d4a | 8815 | elf_gp (output_bfd) + TOC_BASE_OFF, |
4ce794b7 | 8816 | htab->got->contents); |
5d1634d7 AM |
8817 | |
8818 | /* Set .got entry size. */ | |
4ce794b7 | 8819 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
5d1634d7 AM |
8820 | } |
8821 | ||
4ce794b7 | 8822 | if (htab->plt != NULL && htab->plt->_raw_size != 0) |
5d1634d7 AM |
8823 | { |
8824 | /* Set .plt entry size. */ | |
4ce794b7 | 8825 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
5d1634d7 AM |
8826 | = PLT_ENTRY_SIZE; |
8827 | } | |
8828 | ||
e717da7e AM |
8829 | /* We need to handle writing out multiple GOT sections ourselves, |
8830 | since we didn't add them to DYNOBJ. */ | |
8831 | while ((dynobj = dynobj->link_next) != NULL) | |
8832 | { | |
8833 | asection *s; | |
8834 | s = ppc64_elf_tdata (dynobj)->got; | |
8835 | if (s != NULL | |
8836 | && s->_raw_size != 0 | |
8837 | && s->output_section != bfd_abs_section_ptr | |
8838 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8839 | s->contents, s->output_offset, | |
8840 | s->_raw_size)) | |
8841 | return FALSE; | |
8842 | s = ppc64_elf_tdata (dynobj)->relgot; | |
8843 | if (s != NULL | |
8844 | && s->_raw_size != 0 | |
8845 | && s->output_section != bfd_abs_section_ptr | |
8846 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8847 | s->contents, s->output_offset, | |
8848 | s->_raw_size)) | |
8849 | return FALSE; | |
8850 | } | |
f6c52c13 | 8851 | |
b34976b6 | 8852 | return TRUE; |
5bd4f169 AM |
8853 | } |
8854 | ||
5bd4f169 | 8855 | #include "elf64-target.h" |