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. | |
d37c89e5 | 5 | Largely rewritten by Alan Modra <amodra@bigpond.net.au> |
5bd4f169 | 6 | |
ae9a127f | 7 | This file is part of BFD, the Binary File Descriptor library. |
5bd4f169 | 8 | |
ae9a127f NC |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
5bd4f169 | 13 | |
ae9a127f NC |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
5bd4f169 | 18 | |
4ce794b7 AM |
19 | You should have received a copy of the GNU General Public License along |
20 | with this program; if not, write to the Free Software Foundation, Inc., | |
21 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
5bd4f169 | 22 | |
4ce794b7 AM |
23 | /* The 64-bit PowerPC ELF ABI may be found at |
24 | http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and | |
25 | http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */ | |
5bd4f169 AM |
26 | |
27 | #include "bfd.h" | |
28 | #include "sysdep.h" | |
29 | #include "bfdlink.h" | |
30 | #include "libbfd.h" | |
31 | #include "elf-bfd.h" | |
04c9666a | 32 | #include "elf/ppc64.h" |
5d1634d7 | 33 | #include "elf64-ppc.h" |
5bd4f169 | 34 | |
805fc799 | 35 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
4ce794b7 | 36 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 37 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
4ce794b7 | 38 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 39 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
4ce794b7 | 40 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 41 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
4ce794b7 | 42 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 43 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
4ce794b7 | 44 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 45 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
4ce794b7 | 46 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 47 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
4ce794b7 | 48 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 49 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
4ce794b7 | 50 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5bd4f169 AM |
51 | |
52 | ||
ad8e1ba5 AM |
53 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
54 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
55 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
56 | #define TARGET_BIG_NAME "elf64-powerpc" | |
57 | #define ELF_ARCH bfd_arch_powerpc | |
58 | #define ELF_MACHINE_CODE EM_PPC64 | |
59 | #define ELF_MAXPAGESIZE 0x10000 | |
60 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
61 | ||
62 | #define elf_backend_want_got_sym 0 | |
63 | #define elf_backend_want_plt_sym 0 | |
64 | #define elf_backend_plt_alignment 3 | |
65 | #define elf_backend_plt_not_loaded 1 | |
66 | #define elf_backend_got_symbol_offset 0 | |
67 | #define elf_backend_got_header_size 8 | |
ad8e1ba5 AM |
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 | |
d37c89e5 AM |
80 | #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus |
81 | #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo | |
ad8e1ba5 AM |
82 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
83 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
84 | #define elf_backend_check_relocs ppc64_elf_check_relocs | |
85 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
86 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
87 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
88 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol | |
89 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
90 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
91 | #define elf_backend_relocate_section ppc64_elf_relocate_section | |
92 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
93 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
94 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
2f89ff8d | 95 | #define elf_backend_special_sections ppc64_elf_special_sections |
ad8e1ba5 | 96 | |
5bd4f169 AM |
97 | /* The name of the dynamic interpreter. This is put in the .interp |
98 | section. */ | |
99 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
100 | ||
101 | /* The size in bytes of an entry in the procedure linkage table. */ | |
102 | #define PLT_ENTRY_SIZE 24 | |
103 | ||
104 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 105 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
106 | |
107 | /* TOC base pointers offset from start of TOC. */ | |
411e1bfb AM |
108 | #define TOC_BASE_OFF 0x8000 |
109 | ||
110 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
111 | #define TP_OFFSET 0x7000 | |
112 | #define DTP_OFFSET 0x8000 | |
5bd4f169 | 113 | |
ad8e1ba5 AM |
114 | /* .plt call stub instructions. The normal stub is like this, but |
115 | sometimes the .plt entry crosses a 64k boundary and we need to | |
116 | insert an addis to adjust r12. */ | |
117 | #define PLT_CALL_STUB_SIZE (7*4) | |
5d1634d7 AM |
118 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
119 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
120 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
121 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
122 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
123 | /* ld %r11,xxx+16@l(%r12) */ | |
124 | #define BCTR 0x4e800420 /* bctr */ | |
125 | ||
5d1634d7 | 126 | |
ad8e1ba5 AM |
127 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
128 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ | |
129 | ||
130 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
131 | ||
132 | /* glink call stub instructions. We enter with the index in R0, and the | |
133 | address of glink entry in CTR. From that, we can calculate PLT0. */ | |
134 | #define GLINK_CALL_STUB_SIZE (16*4) | |
135 | #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */ | |
136 | #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */ | |
137 | #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */ | |
138 | #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */ | |
139 | #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */ | |
140 | #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */ | |
141 | #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */ | |
142 | /* sub %r12,%r12,%r11 */ | |
143 | #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */ | |
144 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */ | |
145 | /* ld %r11,xxx@l(%r12) */ | |
146 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */ | |
147 | /* ld %r2,8(%r12) */ | |
148 | /* mtctr %r11 */ | |
149 | /* ld %r11,16(%r12) */ | |
150 | /* bctr */ | |
5d1634d7 AM |
151 | |
152 | /* Pad with this. */ | |
153 | #define NOP 0x60000000 | |
154 | ||
721956f4 AM |
155 | /* Some other nops. */ |
156 | #define CROR_151515 0x4def7b82 | |
157 | #define CROR_313131 0x4ffffb82 | |
158 | ||
cedb70c5 | 159 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
160 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
161 | #define B_DOT 0x48000000 /* b . */ | |
162 | ||
163 | /* After that, we need two instructions to load the index, followed by | |
164 | a branch. */ | |
165 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 166 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 167 | |
82bd7b59 AM |
168 | /* Instructions to save and restore floating point regs. */ |
169 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ | |
170 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
171 | #define BLR 0x4e800020 /* blr */ | |
172 | ||
41bd81ab AM |
173 | /* Since .opd is an array of descriptors and each entry will end up |
174 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
175 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 176 | relocate .opd without reloc entries. */ |
41bd81ab AM |
177 | #ifndef NO_OPD_RELOCS |
178 | #define NO_OPD_RELOCS 0 | |
179 | #endif | |
5bd4f169 | 180 | \f |
f5e87a1d | 181 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 182 | |
5bd4f169 | 183 | /* Relocation HOWTO's. */ |
04c9666a | 184 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
5bd4f169 AM |
185 | |
186 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
187 | /* This reloc does nothing. */ | |
188 | HOWTO (R_PPC64_NONE, /* type */ | |
189 | 0, /* rightshift */ | |
411e1bfb AM |
190 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
191 | 32, /* bitsize */ | |
b34976b6 | 192 | FALSE, /* pc_relative */ |
5bd4f169 | 193 | 0, /* bitpos */ |
f5e87a1d | 194 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
195 | bfd_elf_generic_reloc, /* special_function */ |
196 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 197 | FALSE, /* partial_inplace */ |
d006db6c | 198 | 0, /* src_mask */ |
5bd4f169 | 199 | 0, /* dst_mask */ |
b34976b6 | 200 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
201 | |
202 | /* A standard 32 bit relocation. */ | |
203 | HOWTO (R_PPC64_ADDR32, /* type */ | |
204 | 0, /* rightshift */ | |
205 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
206 | 32, /* bitsize */ | |
b34976b6 | 207 | FALSE, /* pc_relative */ |
5bd4f169 AM |
208 | 0, /* bitpos */ |
209 | complain_overflow_bitfield, /* complain_on_overflow */ | |
210 | bfd_elf_generic_reloc, /* special_function */ | |
211 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 212 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
213 | 0, /* src_mask */ |
214 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 215 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
216 | |
217 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
218 | FIXME: we don't check that, we just clear them. */ | |
219 | HOWTO (R_PPC64_ADDR24, /* type */ | |
220 | 0, /* rightshift */ | |
221 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
222 | 26, /* bitsize */ | |
b34976b6 | 223 | FALSE, /* pc_relative */ |
5bd4f169 AM |
224 | 0, /* bitpos */ |
225 | complain_overflow_bitfield, /* complain_on_overflow */ | |
226 | bfd_elf_generic_reloc, /* special_function */ | |
227 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 228 | FALSE, /* partial_inplace */ |
d006db6c | 229 | 0, /* src_mask */ |
f5e87a1d | 230 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 231 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
232 | |
233 | /* A standard 16 bit relocation. */ | |
234 | HOWTO (R_PPC64_ADDR16, /* type */ | |
235 | 0, /* rightshift */ | |
236 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
237 | 16, /* bitsize */ | |
b34976b6 | 238 | FALSE, /* pc_relative */ |
5bd4f169 AM |
239 | 0, /* bitpos */ |
240 | complain_overflow_bitfield, /* complain_on_overflow */ | |
241 | bfd_elf_generic_reloc, /* special_function */ | |
242 | "R_PPC64_ADDR16", /* name */ | |
b34976b6 | 243 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
244 | 0, /* src_mask */ |
245 | 0xffff, /* dst_mask */ | |
b34976b6 | 246 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
247 | |
248 | /* A 16 bit relocation without overflow. */ | |
249 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
250 | 0, /* rightshift */ | |
251 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
252 | 16, /* bitsize */ | |
b34976b6 | 253 | FALSE, /* pc_relative */ |
5bd4f169 AM |
254 | 0, /* bitpos */ |
255 | complain_overflow_dont,/* complain_on_overflow */ | |
256 | bfd_elf_generic_reloc, /* special_function */ | |
257 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 258 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
259 | 0, /* src_mask */ |
260 | 0xffff, /* dst_mask */ | |
b34976b6 | 261 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
262 | |
263 | /* Bits 16-31 of an address. */ | |
264 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
265 | 16, /* rightshift */ | |
266 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
267 | 16, /* bitsize */ | |
b34976b6 | 268 | FALSE, /* pc_relative */ |
5bd4f169 AM |
269 | 0, /* bitpos */ |
270 | complain_overflow_dont, /* complain_on_overflow */ | |
271 | bfd_elf_generic_reloc, /* special_function */ | |
272 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 273 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
274 | 0, /* src_mask */ |
275 | 0xffff, /* dst_mask */ | |
b34976b6 | 276 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
277 | |
278 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
279 | bits, treated as a signed number, is negative. */ | |
280 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
281 | 16, /* rightshift */ | |
282 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
283 | 16, /* bitsize */ | |
b34976b6 | 284 | FALSE, /* pc_relative */ |
5bd4f169 AM |
285 | 0, /* bitpos */ |
286 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 287 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 288 | "R_PPC64_ADDR16_HA", /* name */ |
b34976b6 | 289 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
290 | 0, /* src_mask */ |
291 | 0xffff, /* dst_mask */ | |
b34976b6 | 292 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
293 | |
294 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
295 | FIXME: we don't check that, we just clear them. */ | |
296 | HOWTO (R_PPC64_ADDR14, /* type */ | |
297 | 0, /* rightshift */ | |
298 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
299 | 16, /* bitsize */ | |
b34976b6 | 300 | FALSE, /* pc_relative */ |
5bd4f169 AM |
301 | 0, /* bitpos */ |
302 | complain_overflow_bitfield, /* complain_on_overflow */ | |
303 | bfd_elf_generic_reloc, /* special_function */ | |
304 | "R_PPC64_ADDR14", /* name */ | |
b34976b6 | 305 | FALSE, /* partial_inplace */ |
d006db6c | 306 | 0, /* src_mask */ |
f5e87a1d | 307 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 308 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
309 | |
310 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
311 | indicate that the branch is expected to be taken. The lower two | |
312 | bits must be zero. */ | |
313 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
314 | 0, /* rightshift */ | |
315 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
316 | 16, /* bitsize */ | |
b34976b6 | 317 | FALSE, /* pc_relative */ |
5bd4f169 AM |
318 | 0, /* bitpos */ |
319 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 320 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 321 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 322 | FALSE, /* partial_inplace */ |
d006db6c | 323 | 0, /* src_mask */ |
f5e87a1d | 324 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 325 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
326 | |
327 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
328 | indicate that the branch is not expected to be taken. The lower | |
329 | two bits must be zero. */ | |
330 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
331 | 0, /* rightshift */ | |
332 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
333 | 16, /* bitsize */ | |
b34976b6 | 334 | FALSE, /* pc_relative */ |
5bd4f169 AM |
335 | 0, /* bitpos */ |
336 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 337 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 338 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 339 | FALSE, /* partial_inplace */ |
d006db6c | 340 | 0, /* src_mask */ |
f5e87a1d | 341 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 342 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
343 | |
344 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
345 | HOWTO (R_PPC64_REL24, /* type */ | |
346 | 0, /* rightshift */ | |
347 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
348 | 26, /* bitsize */ | |
b34976b6 | 349 | TRUE, /* pc_relative */ |
5bd4f169 AM |
350 | 0, /* bitpos */ |
351 | complain_overflow_signed, /* complain_on_overflow */ | |
352 | bfd_elf_generic_reloc, /* special_function */ | |
353 | "R_PPC64_REL24", /* name */ | |
b34976b6 | 354 | FALSE, /* partial_inplace */ |
d006db6c | 355 | 0, /* src_mask */ |
f5e87a1d | 356 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 357 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
358 | |
359 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
360 | HOWTO (R_PPC64_REL14, /* type */ | |
361 | 0, /* rightshift */ | |
362 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
363 | 16, /* bitsize */ | |
b34976b6 | 364 | TRUE, /* pc_relative */ |
5bd4f169 AM |
365 | 0, /* bitpos */ |
366 | complain_overflow_signed, /* complain_on_overflow */ | |
367 | bfd_elf_generic_reloc, /* special_function */ | |
368 | "R_PPC64_REL14", /* name */ | |
b34976b6 | 369 | FALSE, /* partial_inplace */ |
d006db6c | 370 | 0, /* src_mask */ |
f5e87a1d | 371 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 372 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
373 | |
374 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
375 | the branch is expected to be taken. The lower two bits must be | |
376 | zero. */ | |
377 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
378 | 0, /* rightshift */ | |
379 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
380 | 16, /* bitsize */ | |
b34976b6 | 381 | TRUE, /* pc_relative */ |
5bd4f169 AM |
382 | 0, /* bitpos */ |
383 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 384 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 385 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 386 | FALSE, /* partial_inplace */ |
d006db6c | 387 | 0, /* src_mask */ |
f5e87a1d | 388 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 389 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
390 | |
391 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
392 | the branch is not expected to be taken. The lower two bits must | |
393 | be zero. */ | |
394 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
395 | 0, /* rightshift */ | |
396 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
397 | 16, /* bitsize */ | |
b34976b6 | 398 | TRUE, /* pc_relative */ |
5bd4f169 AM |
399 | 0, /* bitpos */ |
400 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 401 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 402 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 403 | FALSE, /* partial_inplace */ |
d006db6c | 404 | 0, /* src_mask */ |
f5e87a1d | 405 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 406 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
407 | |
408 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
409 | symbol. */ | |
410 | HOWTO (R_PPC64_GOT16, /* type */ | |
411 | 0, /* rightshift */ | |
412 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
413 | 16, /* bitsize */ | |
b34976b6 | 414 | FALSE, /* pc_relative */ |
5bd4f169 AM |
415 | 0, /* bitpos */ |
416 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 417 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 418 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 419 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
420 | 0, /* src_mask */ |
421 | 0xffff, /* dst_mask */ | |
b34976b6 | 422 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
423 | |
424 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
425 | the symbol. */ | |
426 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
427 | 0, /* rightshift */ | |
428 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
429 | 16, /* bitsize */ | |
b34976b6 | 430 | FALSE, /* pc_relative */ |
5bd4f169 AM |
431 | 0, /* bitpos */ |
432 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 433 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 434 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 435 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
436 | 0, /* src_mask */ |
437 | 0xffff, /* dst_mask */ | |
b34976b6 | 438 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
439 | |
440 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
441 | the symbol. */ | |
442 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
443 | 16, /* rightshift */ | |
444 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
445 | 16, /* bitsize */ | |
b34976b6 | 446 | FALSE, /* pc_relative */ |
5bd4f169 AM |
447 | 0, /* bitpos */ |
448 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 449 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 450 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 451 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
452 | 0, /* src_mask */ |
453 | 0xffff, /* dst_mask */ | |
b34976b6 | 454 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
455 | |
456 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
457 | the symbol. */ | |
458 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
459 | 16, /* rightshift */ | |
460 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
461 | 16, /* bitsize */ | |
b34976b6 | 462 | FALSE, /* pc_relative */ |
5bd4f169 AM |
463 | 0, /* bitpos */ |
464 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 465 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 466 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 467 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
468 | 0, /* src_mask */ |
469 | 0xffff, /* dst_mask */ | |
b34976b6 | 470 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
471 | |
472 | /* This is used only by the dynamic linker. The symbol should exist | |
473 | both in the object being run and in some shared library. The | |
474 | dynamic linker copies the data addressed by the symbol from the | |
475 | shared library into the object, because the object being | |
476 | run has to have the data at some particular address. */ | |
477 | HOWTO (R_PPC64_COPY, /* type */ | |
478 | 0, /* rightshift */ | |
f5e87a1d AM |
479 | 0, /* this one is variable size */ |
480 | 0, /* bitsize */ | |
b34976b6 | 481 | FALSE, /* pc_relative */ |
5bd4f169 | 482 | 0, /* bitpos */ |
f5e87a1d AM |
483 | complain_overflow_dont, /* complain_on_overflow */ |
484 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 485 | "R_PPC64_COPY", /* name */ |
b34976b6 | 486 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
487 | 0, /* src_mask */ |
488 | 0, /* dst_mask */ | |
b34976b6 | 489 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
490 | |
491 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
492 | entries. */ | |
493 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
494 | 0, /* rightshift */ | |
495 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
496 | 64, /* bitsize */ | |
b34976b6 | 497 | FALSE, /* pc_relative */ |
5bd4f169 AM |
498 | 0, /* bitpos */ |
499 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 500 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 501 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 502 | FALSE, /* partial_inplace */ |
5bd4f169 | 503 | 0, /* src_mask */ |
f5e87a1d | 504 | ONES (64), /* dst_mask */ |
b34976b6 | 505 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
506 | |
507 | /* Created by the link editor. Marks a procedure linkage table | |
508 | entry for a symbol. */ | |
509 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
510 | 0, /* rightshift */ | |
511 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
512 | 0, /* bitsize */ | |
b34976b6 | 513 | FALSE, /* pc_relative */ |
5bd4f169 AM |
514 | 0, /* bitpos */ |
515 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 516 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 517 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 518 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
519 | 0, /* src_mask */ |
520 | 0, /* dst_mask */ | |
b34976b6 | 521 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
522 | |
523 | /* Used only by the dynamic linker. When the object is run, this | |
524 | doubleword64 is set to the load address of the object, plus the | |
525 | addend. */ | |
526 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
527 | 0, /* rightshift */ | |
528 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
529 | 64, /* bitsize */ | |
b34976b6 | 530 | FALSE, /* pc_relative */ |
5bd4f169 AM |
531 | 0, /* bitpos */ |
532 | complain_overflow_dont, /* complain_on_overflow */ | |
533 | bfd_elf_generic_reloc, /* special_function */ | |
534 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 535 | FALSE, /* partial_inplace */ |
5bd4f169 | 536 | 0, /* src_mask */ |
f5e87a1d | 537 | ONES (64), /* dst_mask */ |
b34976b6 | 538 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
539 | |
540 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
541 | HOWTO (R_PPC64_UADDR32, /* type */ | |
542 | 0, /* rightshift */ | |
543 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
544 | 32, /* bitsize */ | |
b34976b6 | 545 | FALSE, /* pc_relative */ |
5bd4f169 AM |
546 | 0, /* bitpos */ |
547 | complain_overflow_bitfield, /* complain_on_overflow */ | |
548 | bfd_elf_generic_reloc, /* special_function */ | |
549 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 550 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
551 | 0, /* src_mask */ |
552 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 553 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
554 | |
555 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
556 | HOWTO (R_PPC64_UADDR16, /* type */ | |
557 | 0, /* rightshift */ | |
558 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
559 | 16, /* bitsize */ | |
b34976b6 | 560 | FALSE, /* pc_relative */ |
5bd4f169 AM |
561 | 0, /* bitpos */ |
562 | complain_overflow_bitfield, /* complain_on_overflow */ | |
563 | bfd_elf_generic_reloc, /* special_function */ | |
564 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 565 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
566 | 0, /* src_mask */ |
567 | 0xffff, /* dst_mask */ | |
b34976b6 | 568 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
569 | |
570 | /* 32-bit PC relative. */ | |
571 | HOWTO (R_PPC64_REL32, /* type */ | |
572 | 0, /* rightshift */ | |
573 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
574 | 32, /* bitsize */ | |
b34976b6 | 575 | TRUE, /* pc_relative */ |
5bd4f169 | 576 | 0, /* bitpos */ |
cedb70c5 | 577 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
578 | complain_overflow_signed, /* complain_on_overflow */ |
579 | bfd_elf_generic_reloc, /* special_function */ | |
580 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 581 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
582 | 0, /* src_mask */ |
583 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 584 | TRUE), /* pcrel_offset */ |
5bd4f169 | 585 | |
10ed1bba | 586 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
587 | HOWTO (R_PPC64_PLT32, /* type */ |
588 | 0, /* rightshift */ | |
589 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
590 | 32, /* bitsize */ | |
b34976b6 | 591 | FALSE, /* pc_relative */ |
5bd4f169 AM |
592 | 0, /* bitpos */ |
593 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 594 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 595 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 596 | FALSE, /* partial_inplace */ |
5bd4f169 | 597 | 0, /* src_mask */ |
f5e87a1d | 598 | 0xffffffff, /* dst_mask */ |
b34976b6 | 599 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
600 | |
601 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
602 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
603 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
604 | 0, /* rightshift */ | |
605 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
606 | 32, /* bitsize */ | |
b34976b6 | 607 | TRUE, /* pc_relative */ |
5bd4f169 AM |
608 | 0, /* bitpos */ |
609 | complain_overflow_signed, /* complain_on_overflow */ | |
610 | bfd_elf_generic_reloc, /* special_function */ | |
611 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 612 | FALSE, /* partial_inplace */ |
5bd4f169 | 613 | 0, /* src_mask */ |
f5e87a1d | 614 | 0xffffffff, /* dst_mask */ |
b34976b6 | 615 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
616 | |
617 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
618 | the symbol. */ | |
619 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
620 | 0, /* rightshift */ | |
621 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
622 | 16, /* bitsize */ | |
b34976b6 | 623 | FALSE, /* pc_relative */ |
5bd4f169 AM |
624 | 0, /* bitpos */ |
625 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 626 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 627 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 628 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
629 | 0, /* src_mask */ |
630 | 0xffff, /* dst_mask */ | |
b34976b6 | 631 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
632 | |
633 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
634 | the symbol. */ | |
635 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
636 | 16, /* rightshift */ | |
637 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
638 | 16, /* bitsize */ | |
b34976b6 | 639 | FALSE, /* pc_relative */ |
5bd4f169 AM |
640 | 0, /* bitpos */ |
641 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 642 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 643 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 644 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
645 | 0, /* src_mask */ |
646 | 0xffff, /* dst_mask */ | |
b34976b6 | 647 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
648 | |
649 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
650 | the symbol. */ | |
651 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
652 | 16, /* rightshift */ | |
653 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
654 | 16, /* bitsize */ | |
b34976b6 | 655 | FALSE, /* pc_relative */ |
5bd4f169 AM |
656 | 0, /* bitpos */ |
657 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 658 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 659 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 660 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
661 | 0, /* src_mask */ |
662 | 0xffff, /* dst_mask */ | |
b34976b6 | 663 | FALSE), /* pcrel_offset */ |
5bd4f169 | 664 | |
c061c2d8 | 665 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
666 | HOWTO (R_PPC64_SECTOFF, /* type */ |
667 | 0, /* rightshift */ | |
c061c2d8 AM |
668 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
669 | 16, /* bitsize */ | |
b34976b6 | 670 | FALSE, /* pc_relative */ |
5bd4f169 AM |
671 | 0, /* bitpos */ |
672 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 673 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 674 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 675 | FALSE, /* partial_inplace */ |
5bd4f169 | 676 | 0, /* src_mask */ |
c061c2d8 | 677 | 0xffff, /* dst_mask */ |
b34976b6 | 678 | FALSE), /* pcrel_offset */ |
5bd4f169 | 679 | |
c061c2d8 | 680 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
681 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
682 | 0, /* rightshift */ | |
683 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
684 | 16, /* bitsize */ | |
b34976b6 | 685 | FALSE, /* pc_relative */ |
5bd4f169 AM |
686 | 0, /* bitpos */ |
687 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 688 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 689 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 690 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
691 | 0, /* src_mask */ |
692 | 0xffff, /* dst_mask */ | |
b34976b6 | 693 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
694 | |
695 | /* 16-bit upper half section relative relocation. */ | |
696 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
697 | 16, /* rightshift */ | |
698 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
699 | 16, /* bitsize */ | |
b34976b6 | 700 | FALSE, /* pc_relative */ |
5bd4f169 AM |
701 | 0, /* bitpos */ |
702 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 703 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 704 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 705 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
706 | 0, /* src_mask */ |
707 | 0xffff, /* dst_mask */ | |
b34976b6 | 708 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
709 | |
710 | /* 16-bit upper half adjusted section relative relocation. */ | |
711 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
712 | 16, /* rightshift */ | |
713 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
714 | 16, /* bitsize */ | |
b34976b6 | 715 | FALSE, /* pc_relative */ |
5bd4f169 AM |
716 | 0, /* bitpos */ |
717 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 718 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 719 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 720 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
721 | 0, /* src_mask */ |
722 | 0xffff, /* dst_mask */ | |
b34976b6 | 723 | FALSE), /* pcrel_offset */ |
5bd4f169 | 724 | |
04c9666a AM |
725 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
726 | HOWTO (R_PPC64_REL30, /* type */ | |
5bd4f169 AM |
727 | 2, /* rightshift */ |
728 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
729 | 30, /* bitsize */ | |
b34976b6 | 730 | TRUE, /* pc_relative */ |
5bd4f169 AM |
731 | 0, /* bitpos */ |
732 | complain_overflow_dont, /* complain_on_overflow */ | |
733 | bfd_elf_generic_reloc, /* special_function */ | |
04c9666a | 734 | "R_PPC64_REL30", /* name */ |
b34976b6 | 735 | FALSE, /* partial_inplace */ |
d006db6c | 736 | 0, /* src_mask */ |
5bd4f169 | 737 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 738 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
739 | |
740 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
741 | ||
742 | /* A standard 64-bit relocation. */ | |
743 | HOWTO (R_PPC64_ADDR64, /* type */ | |
744 | 0, /* rightshift */ | |
745 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
746 | 64, /* bitsize */ | |
b34976b6 | 747 | FALSE, /* pc_relative */ |
5bd4f169 AM |
748 | 0, /* bitpos */ |
749 | complain_overflow_dont, /* complain_on_overflow */ | |
750 | bfd_elf_generic_reloc, /* special_function */ | |
751 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 752 | FALSE, /* partial_inplace */ |
5bd4f169 | 753 | 0, /* src_mask */ |
f5e87a1d | 754 | ONES (64), /* dst_mask */ |
b34976b6 | 755 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
756 | |
757 | /* The bits 32-47 of an address. */ | |
758 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
759 | 32, /* rightshift */ | |
760 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
761 | 16, /* bitsize */ | |
b34976b6 | 762 | FALSE, /* pc_relative */ |
5bd4f169 AM |
763 | 0, /* bitpos */ |
764 | complain_overflow_dont, /* complain_on_overflow */ | |
765 | bfd_elf_generic_reloc, /* special_function */ | |
766 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 767 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
768 | 0, /* src_mask */ |
769 | 0xffff, /* dst_mask */ | |
b34976b6 | 770 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
771 | |
772 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
773 | 16 bits, treated as a signed number, is negative. */ | |
774 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
775 | 32, /* rightshift */ | |
776 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
777 | 16, /* bitsize */ | |
b34976b6 | 778 | FALSE, /* pc_relative */ |
5bd4f169 AM |
779 | 0, /* bitpos */ |
780 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 781 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 782 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 783 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
784 | 0, /* src_mask */ |
785 | 0xffff, /* dst_mask */ | |
b34976b6 | 786 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
787 | |
788 | /* The bits 48-63 of an address. */ | |
789 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
790 | 48, /* rightshift */ | |
791 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
792 | 16, /* bitsize */ | |
b34976b6 | 793 | FALSE, /* pc_relative */ |
5bd4f169 AM |
794 | 0, /* bitpos */ |
795 | complain_overflow_dont, /* complain_on_overflow */ | |
796 | bfd_elf_generic_reloc, /* special_function */ | |
797 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
b34976b6 | 798 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
799 | 0, /* src_mask */ |
800 | 0xffff, /* dst_mask */ | |
b34976b6 | 801 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
802 | |
803 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
804 | 16 bits, treated as a signed number, is negative. */ | |
805 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
806 | 48, /* rightshift */ | |
807 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
808 | 16, /* bitsize */ | |
b34976b6 | 809 | FALSE, /* pc_relative */ |
5bd4f169 AM |
810 | 0, /* bitpos */ |
811 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 812 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 813 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
b34976b6 | 814 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
815 | 0, /* src_mask */ |
816 | 0xffff, /* dst_mask */ | |
b34976b6 | 817 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
818 | |
819 | /* Like ADDR64, but may be unaligned. */ | |
820 | HOWTO (R_PPC64_UADDR64, /* type */ | |
821 | 0, /* rightshift */ | |
822 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
823 | 64, /* bitsize */ | |
b34976b6 | 824 | FALSE, /* pc_relative */ |
5bd4f169 AM |
825 | 0, /* bitpos */ |
826 | complain_overflow_dont, /* complain_on_overflow */ | |
827 | bfd_elf_generic_reloc, /* special_function */ | |
828 | "R_PPC64_UADDR64", /* name */ | |
b34976b6 | 829 | FALSE, /* partial_inplace */ |
5bd4f169 | 830 | 0, /* src_mask */ |
f5e87a1d | 831 | ONES (64), /* dst_mask */ |
b34976b6 | 832 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
833 | |
834 | /* 64-bit relative relocation. */ | |
835 | HOWTO (R_PPC64_REL64, /* type */ | |
836 | 0, /* rightshift */ | |
837 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
838 | 64, /* bitsize */ | |
b34976b6 | 839 | TRUE, /* pc_relative */ |
5bd4f169 AM |
840 | 0, /* bitpos */ |
841 | complain_overflow_dont, /* complain_on_overflow */ | |
842 | bfd_elf_generic_reloc, /* special_function */ | |
843 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 844 | FALSE, /* partial_inplace */ |
5bd4f169 | 845 | 0, /* src_mask */ |
f5e87a1d | 846 | ONES (64), /* dst_mask */ |
b34976b6 | 847 | TRUE), /* pcrel_offset */ |
5bd4f169 | 848 | |
cedb70c5 | 849 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
850 | HOWTO (R_PPC64_PLT64, /* type */ |
851 | 0, /* rightshift */ | |
852 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
853 | 64, /* bitsize */ | |
b34976b6 | 854 | FALSE, /* pc_relative */ |
5bd4f169 AM |
855 | 0, /* bitpos */ |
856 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 857 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 858 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 859 | FALSE, /* partial_inplace */ |
5bd4f169 | 860 | 0, /* src_mask */ |
f5e87a1d | 861 | ONES (64), /* dst_mask */ |
b34976b6 | 862 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
863 | |
864 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
865 | table. */ | |
866 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
867 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
868 | 0, /* rightshift */ | |
869 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
870 | 64, /* bitsize */ | |
b34976b6 | 871 | TRUE, /* pc_relative */ |
5bd4f169 AM |
872 | 0, /* bitpos */ |
873 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 874 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 875 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 876 | FALSE, /* partial_inplace */ |
5bd4f169 | 877 | 0, /* src_mask */ |
f5e87a1d | 878 | ONES (64), /* dst_mask */ |
b34976b6 | 879 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
880 | |
881 | /* 16 bit TOC-relative relocation. */ | |
882 | ||
883 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
884 | HOWTO (R_PPC64_TOC16, /* type */ | |
885 | 0, /* rightshift */ | |
886 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
887 | 16, /* bitsize */ | |
b34976b6 | 888 | FALSE, /* pc_relative */ |
5bd4f169 AM |
889 | 0, /* bitpos */ |
890 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 891 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 892 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 893 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
894 | 0, /* src_mask */ |
895 | 0xffff, /* dst_mask */ | |
b34976b6 | 896 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
897 | |
898 | /* 16 bit TOC-relative relocation without overflow. */ | |
899 | ||
900 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
901 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
902 | 0, /* rightshift */ | |
903 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
904 | 16, /* bitsize */ | |
b34976b6 | 905 | FALSE, /* pc_relative */ |
5bd4f169 AM |
906 | 0, /* bitpos */ |
907 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 908 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 909 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 910 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
911 | 0, /* src_mask */ |
912 | 0xffff, /* dst_mask */ | |
b34976b6 | 913 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
914 | |
915 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
916 | ||
917 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
918 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
919 | 16, /* rightshift */ | |
920 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
921 | 16, /* bitsize */ | |
b34976b6 | 922 | FALSE, /* pc_relative */ |
5bd4f169 AM |
923 | 0, /* bitpos */ |
924 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 925 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 926 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 927 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
928 | 0, /* src_mask */ |
929 | 0xffff, /* dst_mask */ | |
b34976b6 | 930 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
931 | |
932 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
933 | contents of the low 16 bits, treated as a signed number, is | |
934 | negative. */ | |
935 | ||
936 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
937 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
938 | 16, /* rightshift */ | |
939 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
940 | 16, /* bitsize */ | |
b34976b6 | 941 | FALSE, /* pc_relative */ |
5bd4f169 AM |
942 | 0, /* bitpos */ |
943 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 944 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 945 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 946 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
947 | 0, /* src_mask */ |
948 | 0xffff, /* dst_mask */ | |
b34976b6 | 949 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
950 | |
951 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
952 | ||
953 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
954 | HOWTO (R_PPC64_TOC, /* type */ | |
955 | 0, /* rightshift */ | |
956 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
957 | 64, /* bitsize */ | |
b34976b6 | 958 | FALSE, /* pc_relative */ |
5bd4f169 AM |
959 | 0, /* bitpos */ |
960 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 961 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 962 | "R_PPC64_TOC", /* name */ |
b34976b6 | 963 | FALSE, /* partial_inplace */ |
5bd4f169 | 964 | 0, /* src_mask */ |
f5e87a1d | 965 | ONES (64), /* dst_mask */ |
b34976b6 | 966 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
967 | |
968 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
969 | value to relocate may (!) refer to a PLT entry which the link | |
970 | editor (a) may replace with the symbol value. If the link editor | |
971 | is unable to fully resolve the symbol, it may (b) create a PLT | |
972 | entry and store the address to the new PLT entry in the GOT. | |
973 | This permits lazy resolution of function symbols at run time. | |
974 | The link editor may also skip all of this and just (c) emit a | |
975 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
976 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
977 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
978 | 0, /* rightshift */ | |
979 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
980 | 16, /* bitsize */ | |
b34976b6 | 981 | FALSE, /* pc_relative */ |
5bd4f169 AM |
982 | 0, /* bitpos */ |
983 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 984 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb AM |
985 | "R_PPC64_PLTGOT16", /* name */ |
986 | FALSE, /* partial_inplace */ | |
987 | 0, /* src_mask */ | |
988 | 0xffff, /* dst_mask */ | |
989 | FALSE), /* pcrel_offset */ | |
990 | ||
991 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
992 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
993 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
994 | 0, /* rightshift */ | |
995 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
996 | 16, /* bitsize */ | |
997 | FALSE, /* pc_relative */ | |
998 | 0, /* bitpos */ | |
999 | complain_overflow_dont, /* complain_on_overflow */ | |
1000 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1001 | "R_PPC64_PLTGOT16_LO", /* name */ | |
1002 | FALSE, /* partial_inplace */ | |
1003 | 0, /* src_mask */ | |
1004 | 0xffff, /* dst_mask */ | |
1005 | FALSE), /* pcrel_offset */ | |
1006 | ||
1007 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
1008 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
1009 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
1010 | 16, /* rightshift */ | |
1011 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1012 | 16, /* bitsize */ | |
1013 | FALSE, /* pc_relative */ | |
1014 | 0, /* bitpos */ | |
1015 | complain_overflow_dont, /* complain_on_overflow */ | |
1016 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1017 | "R_PPC64_PLTGOT16_HI", /* name */ | |
1018 | FALSE, /* partial_inplace */ | |
1019 | 0, /* src_mask */ | |
1020 | 0xffff, /* dst_mask */ | |
1021 | FALSE), /* pcrel_offset */ | |
1022 | ||
1023 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
1024 | 1 if the contents of the low 16 bits, treated as a signed number, | |
1025 | is negative. */ | |
1026 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
1027 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
1028 | 16, /* rightshift */ | |
1029 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1030 | 16, /* bitsize */ | |
1031 | FALSE, /* pc_relative */ | |
1032 | 0, /* bitpos */ | |
1033 | complain_overflow_dont,/* complain_on_overflow */ | |
1034 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1035 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1036 | FALSE, /* partial_inplace */ | |
1037 | 0, /* src_mask */ | |
1038 | 0xffff, /* dst_mask */ | |
1039 | FALSE), /* pcrel_offset */ | |
1040 | ||
1041 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1042 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1043 | 0, /* rightshift */ | |
1044 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1045 | 16, /* bitsize */ | |
1046 | FALSE, /* pc_relative */ | |
1047 | 0, /* bitpos */ | |
1048 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1049 | bfd_elf_generic_reloc, /* special_function */ | |
1050 | "R_PPC64_ADDR16_DS", /* name */ | |
1051 | FALSE, /* partial_inplace */ | |
1052 | 0, /* src_mask */ | |
1053 | 0xfffc, /* dst_mask */ | |
1054 | FALSE), /* pcrel_offset */ | |
1055 | ||
1056 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1057 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1058 | 0, /* rightshift */ | |
1059 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1060 | 16, /* bitsize */ | |
1061 | FALSE, /* pc_relative */ | |
1062 | 0, /* bitpos */ | |
1063 | complain_overflow_dont,/* complain_on_overflow */ | |
1064 | bfd_elf_generic_reloc, /* special_function */ | |
1065 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1066 | FALSE, /* partial_inplace */ | |
1067 | 0, /* src_mask */ | |
1068 | 0xfffc, /* dst_mask */ | |
1069 | FALSE), /* pcrel_offset */ | |
1070 | ||
1071 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1072 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1073 | 0, /* rightshift */ | |
1074 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1075 | 16, /* bitsize */ | |
1076 | FALSE, /* pc_relative */ | |
1077 | 0, /* bitpos */ | |
1078 | complain_overflow_signed, /* complain_on_overflow */ | |
1079 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1080 | "R_PPC64_GOT16_DS", /* name */ | |
1081 | FALSE, /* partial_inplace */ | |
1082 | 0, /* src_mask */ | |
1083 | 0xfffc, /* dst_mask */ | |
1084 | FALSE), /* pcrel_offset */ | |
1085 | ||
1086 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1087 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1088 | 0, /* rightshift */ | |
1089 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1090 | 16, /* bitsize */ | |
1091 | FALSE, /* pc_relative */ | |
1092 | 0, /* bitpos */ | |
1093 | complain_overflow_dont, /* complain_on_overflow */ | |
1094 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1095 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1096 | FALSE, /* partial_inplace */ | |
1097 | 0, /* src_mask */ | |
1098 | 0xfffc, /* dst_mask */ | |
1099 | FALSE), /* pcrel_offset */ | |
1100 | ||
1101 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1102 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1103 | 0, /* rightshift */ | |
1104 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1105 | 16, /* bitsize */ | |
1106 | FALSE, /* pc_relative */ | |
1107 | 0, /* bitpos */ | |
1108 | complain_overflow_dont, /* complain_on_overflow */ | |
1109 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1110 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1111 | FALSE, /* partial_inplace */ | |
1112 | 0, /* src_mask */ | |
1113 | 0xfffc, /* dst_mask */ | |
1114 | FALSE), /* pcrel_offset */ | |
1115 | ||
1116 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1117 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1118 | 0, /* rightshift */ | |
1119 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1120 | 16, /* bitsize */ | |
1121 | FALSE, /* pc_relative */ | |
1122 | 0, /* bitpos */ | |
1123 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1124 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1125 | "R_PPC64_SECTOFF_DS", /* name */ | |
1126 | FALSE, /* partial_inplace */ | |
1127 | 0, /* src_mask */ | |
1128 | 0xfffc, /* dst_mask */ | |
1129 | FALSE), /* pcrel_offset */ | |
1130 | ||
1131 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1132 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1133 | 0, /* rightshift */ | |
1134 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1135 | 16, /* bitsize */ | |
1136 | FALSE, /* pc_relative */ | |
1137 | 0, /* bitpos */ | |
1138 | complain_overflow_dont, /* complain_on_overflow */ | |
1139 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1140 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1141 | FALSE, /* partial_inplace */ | |
1142 | 0, /* src_mask */ | |
1143 | 0xfffc, /* dst_mask */ | |
1144 | FALSE), /* pcrel_offset */ | |
1145 | ||
1146 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1147 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1148 | 0, /* rightshift */ | |
1149 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1150 | 16, /* bitsize */ | |
1151 | FALSE, /* pc_relative */ | |
1152 | 0, /* bitpos */ | |
1153 | complain_overflow_signed, /* complain_on_overflow */ | |
1154 | ppc64_elf_toc_reloc, /* special_function */ | |
1155 | "R_PPC64_TOC16_DS", /* name */ | |
1156 | FALSE, /* partial_inplace */ | |
1157 | 0, /* src_mask */ | |
1158 | 0xfffc, /* dst_mask */ | |
1159 | FALSE), /* pcrel_offset */ | |
1160 | ||
1161 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1162 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1163 | 0, /* rightshift */ | |
1164 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1165 | 16, /* bitsize */ | |
1166 | FALSE, /* pc_relative */ | |
1167 | 0, /* bitpos */ | |
1168 | complain_overflow_dont, /* complain_on_overflow */ | |
1169 | ppc64_elf_toc_reloc, /* special_function */ | |
1170 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1171 | FALSE, /* partial_inplace */ | |
1172 | 0, /* src_mask */ | |
1173 | 0xfffc, /* dst_mask */ | |
1174 | FALSE), /* pcrel_offset */ | |
1175 | ||
1176 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1177 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1178 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ | |
1179 | 0, /* rightshift */ | |
1180 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1181 | 16, /* bitsize */ | |
1182 | FALSE, /* pc_relative */ | |
1183 | 0, /* bitpos */ | |
1184 | complain_overflow_signed, /* complain_on_overflow */ | |
1185 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1186 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1187 | FALSE, /* partial_inplace */ | |
1188 | 0, /* src_mask */ | |
1189 | 0xfffc, /* dst_mask */ | |
1190 | FALSE), /* pcrel_offset */ | |
1191 | ||
1192 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1193 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1194 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1195 | 0, /* rightshift */ | |
1196 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1197 | 16, /* bitsize */ | |
1198 | FALSE, /* pc_relative */ | |
1199 | 0, /* bitpos */ | |
1200 | complain_overflow_dont, /* complain_on_overflow */ | |
1201 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1202 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1203 | FALSE, /* partial_inplace */ | |
1204 | 0, /* src_mask */ | |
1205 | 0xfffc, /* dst_mask */ | |
1206 | FALSE), /* pcrel_offset */ | |
1207 | ||
1208 | /* Marker reloc for TLS. */ | |
1209 | HOWTO (R_PPC64_TLS, | |
1210 | 0, /* rightshift */ | |
1211 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1212 | 32, /* bitsize */ | |
1213 | FALSE, /* pc_relative */ | |
1214 | 0, /* bitpos */ | |
1215 | complain_overflow_dont, /* complain_on_overflow */ | |
1216 | bfd_elf_generic_reloc, /* special_function */ | |
1217 | "R_PPC64_TLS", /* name */ | |
1218 | FALSE, /* partial_inplace */ | |
1219 | 0, /* src_mask */ | |
1220 | 0, /* dst_mask */ | |
1221 | FALSE), /* pcrel_offset */ | |
1222 | ||
1223 | /* Computes the load module index of the load module that contains the | |
1224 | definition of its TLS sym. */ | |
1225 | HOWTO (R_PPC64_DTPMOD64, | |
1226 | 0, /* rightshift */ | |
1227 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1228 | 64, /* bitsize */ | |
1229 | FALSE, /* pc_relative */ | |
1230 | 0, /* bitpos */ | |
1231 | complain_overflow_dont, /* complain_on_overflow */ | |
1232 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1233 | "R_PPC64_DTPMOD64", /* name */ | |
1234 | FALSE, /* partial_inplace */ | |
1235 | 0, /* src_mask */ | |
1236 | ONES (64), /* dst_mask */ | |
1237 | FALSE), /* pcrel_offset */ | |
1238 | ||
1239 | /* Computes a dtv-relative displacement, the difference between the value | |
1240 | of sym+add and the base address of the thread-local storage block that | |
1241 | contains the definition of sym, minus 0x8000. */ | |
1242 | HOWTO (R_PPC64_DTPREL64, | |
1243 | 0, /* rightshift */ | |
1244 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1245 | 64, /* bitsize */ | |
1246 | FALSE, /* pc_relative */ | |
1247 | 0, /* bitpos */ | |
1248 | complain_overflow_dont, /* complain_on_overflow */ | |
1249 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1250 | "R_PPC64_DTPREL64", /* name */ | |
1251 | FALSE, /* partial_inplace */ | |
1252 | 0, /* src_mask */ | |
1253 | ONES (64), /* dst_mask */ | |
1254 | FALSE), /* pcrel_offset */ | |
1255 | ||
1256 | /* A 16 bit dtprel reloc. */ | |
1257 | HOWTO (R_PPC64_DTPREL16, | |
1258 | 0, /* rightshift */ | |
1259 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1260 | 16, /* bitsize */ | |
1261 | FALSE, /* pc_relative */ | |
1262 | 0, /* bitpos */ | |
1263 | complain_overflow_signed, /* complain_on_overflow */ | |
1264 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1265 | "R_PPC64_DTPREL16", /* name */ | |
1266 | FALSE, /* partial_inplace */ | |
1267 | 0, /* src_mask */ | |
1268 | 0xffff, /* dst_mask */ | |
1269 | FALSE), /* pcrel_offset */ | |
1270 | ||
1271 | /* Like DTPREL16, but no overflow. */ | |
1272 | HOWTO (R_PPC64_DTPREL16_LO, | |
1273 | 0, /* rightshift */ | |
1274 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1275 | 16, /* bitsize */ | |
1276 | FALSE, /* pc_relative */ | |
1277 | 0, /* bitpos */ | |
1278 | complain_overflow_dont, /* complain_on_overflow */ | |
1279 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1280 | "R_PPC64_DTPREL16_LO", /* name */ | |
1281 | FALSE, /* partial_inplace */ | |
1282 | 0, /* src_mask */ | |
1283 | 0xffff, /* dst_mask */ | |
1284 | FALSE), /* pcrel_offset */ | |
1285 | ||
1286 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ | |
1287 | HOWTO (R_PPC64_DTPREL16_HI, | |
1288 | 16, /* rightshift */ | |
1289 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1290 | 16, /* bitsize */ | |
1291 | FALSE, /* pc_relative */ | |
1292 | 0, /* bitpos */ | |
1293 | complain_overflow_dont, /* complain_on_overflow */ | |
1294 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1295 | "R_PPC64_DTPREL16_HI", /* name */ | |
1296 | FALSE, /* partial_inplace */ | |
1297 | 0, /* src_mask */ | |
1298 | 0xffff, /* dst_mask */ | |
1299 | FALSE), /* pcrel_offset */ | |
1300 | ||
1301 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ | |
1302 | HOWTO (R_PPC64_DTPREL16_HA, | |
1303 | 16, /* rightshift */ | |
1304 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1305 | 16, /* bitsize */ | |
1306 | FALSE, /* pc_relative */ | |
1307 | 0, /* bitpos */ | |
1308 | complain_overflow_dont, /* complain_on_overflow */ | |
1309 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1310 | "R_PPC64_DTPREL16_HA", /* name */ | |
1311 | FALSE, /* partial_inplace */ | |
1312 | 0, /* src_mask */ | |
1313 | 0xffff, /* dst_mask */ | |
1314 | FALSE), /* pcrel_offset */ | |
1315 | ||
1316 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ | |
1317 | HOWTO (R_PPC64_DTPREL16_HIGHER, | |
1318 | 32, /* rightshift */ | |
1319 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1320 | 16, /* bitsize */ | |
1321 | FALSE, /* pc_relative */ | |
1322 | 0, /* bitpos */ | |
1323 | complain_overflow_dont, /* complain_on_overflow */ | |
1324 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1325 | "R_PPC64_DTPREL16_HIGHER", /* name */ | |
1326 | FALSE, /* partial_inplace */ | |
1327 | 0, /* src_mask */ | |
1328 | 0xffff, /* dst_mask */ | |
1329 | FALSE), /* pcrel_offset */ | |
1330 | ||
1331 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ | |
1332 | HOWTO (R_PPC64_DTPREL16_HIGHERA, | |
1333 | 32, /* rightshift */ | |
1334 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1335 | 16, /* bitsize */ | |
1336 | FALSE, /* pc_relative */ | |
1337 | 0, /* bitpos */ | |
1338 | complain_overflow_dont, /* complain_on_overflow */ | |
1339 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1340 | "R_PPC64_DTPREL16_HIGHERA", /* name */ | |
1341 | FALSE, /* partial_inplace */ | |
1342 | 0, /* src_mask */ | |
1343 | 0xffff, /* dst_mask */ | |
1344 | FALSE), /* pcrel_offset */ | |
1345 | ||
1346 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ | |
1347 | HOWTO (R_PPC64_DTPREL16_HIGHEST, | |
1348 | 48, /* rightshift */ | |
1349 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1350 | 16, /* bitsize */ | |
1351 | FALSE, /* pc_relative */ | |
1352 | 0, /* bitpos */ | |
1353 | complain_overflow_dont, /* complain_on_overflow */ | |
1354 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1355 | "R_PPC64_DTPREL16_HIGHEST", /* name */ | |
1356 | FALSE, /* partial_inplace */ | |
1357 | 0, /* src_mask */ | |
1358 | 0xffff, /* dst_mask */ | |
1359 | FALSE), /* pcrel_offset */ | |
1360 | ||
1361 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1362 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, | |
1363 | 48, /* rightshift */ | |
1364 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1365 | 16, /* bitsize */ | |
1366 | FALSE, /* pc_relative */ | |
1367 | 0, /* bitpos */ | |
1368 | complain_overflow_dont, /* complain_on_overflow */ | |
1369 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1370 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ | |
1371 | FALSE, /* partial_inplace */ | |
1372 | 0, /* src_mask */ | |
1373 | 0xffff, /* dst_mask */ | |
1374 | FALSE), /* pcrel_offset */ | |
1375 | ||
1376 | /* Like DTPREL16, but for insns with a DS field. */ | |
1377 | HOWTO (R_PPC64_DTPREL16_DS, | |
1378 | 0, /* rightshift */ | |
1379 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1380 | 16, /* bitsize */ | |
1381 | FALSE, /* pc_relative */ | |
1382 | 0, /* bitpos */ | |
1383 | complain_overflow_signed, /* complain_on_overflow */ | |
1384 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1385 | "R_PPC64_DTPREL16_DS", /* name */ | |
1386 | FALSE, /* partial_inplace */ | |
1387 | 0, /* src_mask */ | |
1388 | 0xfffc, /* dst_mask */ | |
1389 | FALSE), /* pcrel_offset */ | |
1390 | ||
1391 | /* Like DTPREL16_DS, but no overflow. */ | |
1392 | HOWTO (R_PPC64_DTPREL16_LO_DS, | |
1393 | 0, /* rightshift */ | |
1394 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1395 | 16, /* bitsize */ | |
1396 | FALSE, /* pc_relative */ | |
1397 | 0, /* bitpos */ | |
1398 | complain_overflow_dont, /* complain_on_overflow */ | |
1399 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1400 | "R_PPC64_DTPREL16_LO_DS", /* name */ | |
1401 | FALSE, /* partial_inplace */ | |
1402 | 0, /* src_mask */ | |
1403 | 0xfffc, /* dst_mask */ | |
1404 | FALSE), /* pcrel_offset */ | |
1405 | ||
1406 | /* Computes a tp-relative displacement, the difference between the value of | |
1407 | sym+add and the value of the thread pointer (r13). */ | |
1408 | HOWTO (R_PPC64_TPREL64, | |
1409 | 0, /* rightshift */ | |
1410 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1411 | 64, /* bitsize */ | |
1412 | FALSE, /* pc_relative */ | |
1413 | 0, /* bitpos */ | |
1414 | complain_overflow_dont, /* complain_on_overflow */ | |
1415 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1416 | "R_PPC64_TPREL64", /* name */ | |
1417 | FALSE, /* partial_inplace */ | |
1418 | 0, /* src_mask */ | |
1419 | ONES (64), /* dst_mask */ | |
1420 | FALSE), /* pcrel_offset */ | |
1421 | ||
1422 | /* A 16 bit tprel reloc. */ | |
1423 | HOWTO (R_PPC64_TPREL16, | |
1424 | 0, /* rightshift */ | |
1425 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1426 | 16, /* bitsize */ | |
1427 | FALSE, /* pc_relative */ | |
1428 | 0, /* bitpos */ | |
1429 | complain_overflow_signed, /* complain_on_overflow */ | |
1430 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1431 | "R_PPC64_TPREL16", /* name */ | |
1432 | FALSE, /* partial_inplace */ | |
1433 | 0, /* src_mask */ | |
1434 | 0xffff, /* dst_mask */ | |
1435 | FALSE), /* pcrel_offset */ | |
1436 | ||
1437 | /* Like TPREL16, but no overflow. */ | |
1438 | HOWTO (R_PPC64_TPREL16_LO, | |
1439 | 0, /* rightshift */ | |
1440 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1441 | 16, /* bitsize */ | |
1442 | FALSE, /* pc_relative */ | |
1443 | 0, /* bitpos */ | |
1444 | complain_overflow_dont, /* complain_on_overflow */ | |
1445 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1446 | "R_PPC64_TPREL16_LO", /* name */ | |
1447 | FALSE, /* partial_inplace */ | |
1448 | 0, /* src_mask */ | |
1449 | 0xffff, /* dst_mask */ | |
1450 | FALSE), /* pcrel_offset */ | |
1451 | ||
1452 | /* Like TPREL16_LO, but next higher group of 16 bits. */ | |
1453 | HOWTO (R_PPC64_TPREL16_HI, | |
1454 | 16, /* rightshift */ | |
1455 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1456 | 16, /* bitsize */ | |
1457 | FALSE, /* pc_relative */ | |
1458 | 0, /* bitpos */ | |
1459 | complain_overflow_dont, /* complain_on_overflow */ | |
1460 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1461 | "R_PPC64_TPREL16_HI", /* name */ | |
1462 | FALSE, /* partial_inplace */ | |
1463 | 0, /* src_mask */ | |
1464 | 0xffff, /* dst_mask */ | |
1465 | FALSE), /* pcrel_offset */ | |
1466 | ||
1467 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1468 | HOWTO (R_PPC64_TPREL16_HA, | |
1469 | 16, /* rightshift */ | |
1470 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1471 | 16, /* bitsize */ | |
1472 | FALSE, /* pc_relative */ | |
1473 | 0, /* bitpos */ | |
1474 | complain_overflow_dont, /* complain_on_overflow */ | |
1475 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1476 | "R_PPC64_TPREL16_HA", /* name */ | |
1477 | FALSE, /* partial_inplace */ | |
1478 | 0, /* src_mask */ | |
1479 | 0xffff, /* dst_mask */ | |
1480 | FALSE), /* pcrel_offset */ | |
1481 | ||
1482 | /* Like TPREL16_HI, but next higher group of 16 bits. */ | |
1483 | HOWTO (R_PPC64_TPREL16_HIGHER, | |
1484 | 32, /* rightshift */ | |
1485 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1486 | 16, /* bitsize */ | |
1487 | FALSE, /* pc_relative */ | |
1488 | 0, /* bitpos */ | |
1489 | complain_overflow_dont, /* complain_on_overflow */ | |
1490 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1491 | "R_PPC64_TPREL16_HIGHER", /* name */ | |
1492 | FALSE, /* partial_inplace */ | |
1493 | 0, /* src_mask */ | |
1494 | 0xffff, /* dst_mask */ | |
1495 | FALSE), /* pcrel_offset */ | |
1496 | ||
1497 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ | |
1498 | HOWTO (R_PPC64_TPREL16_HIGHERA, | |
1499 | 32, /* rightshift */ | |
1500 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1501 | 16, /* bitsize */ | |
1502 | FALSE, /* pc_relative */ | |
1503 | 0, /* bitpos */ | |
1504 | complain_overflow_dont, /* complain_on_overflow */ | |
1505 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1506 | "R_PPC64_TPREL16_HIGHERA", /* name */ | |
1507 | FALSE, /* partial_inplace */ | |
1508 | 0, /* src_mask */ | |
1509 | 0xffff, /* dst_mask */ | |
1510 | FALSE), /* pcrel_offset */ | |
1511 | ||
1512 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ | |
1513 | HOWTO (R_PPC64_TPREL16_HIGHEST, | |
1514 | 48, /* rightshift */ | |
1515 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1516 | 16, /* bitsize */ | |
1517 | FALSE, /* pc_relative */ | |
1518 | 0, /* bitpos */ | |
1519 | complain_overflow_dont, /* complain_on_overflow */ | |
1520 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1521 | "R_PPC64_TPREL16_HIGHEST", /* name */ | |
1522 | FALSE, /* partial_inplace */ | |
1523 | 0, /* src_mask */ | |
1524 | 0xffff, /* dst_mask */ | |
1525 | FALSE), /* pcrel_offset */ | |
1526 | ||
1527 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1528 | HOWTO (R_PPC64_TPREL16_HIGHESTA, | |
1529 | 48, /* rightshift */ | |
1530 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1531 | 16, /* bitsize */ | |
1532 | FALSE, /* pc_relative */ | |
1533 | 0, /* bitpos */ | |
1534 | complain_overflow_dont, /* complain_on_overflow */ | |
1535 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1536 | "R_PPC64_TPREL16_HIGHESTA", /* name */ | |
1537 | FALSE, /* partial_inplace */ | |
1538 | 0, /* src_mask */ | |
1539 | 0xffff, /* dst_mask */ | |
1540 | FALSE), /* pcrel_offset */ | |
1541 | ||
1542 | /* Like TPREL16, but for insns with a DS field. */ | |
1543 | HOWTO (R_PPC64_TPREL16_DS, | |
1544 | 0, /* rightshift */ | |
1545 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1546 | 16, /* bitsize */ | |
1547 | FALSE, /* pc_relative */ | |
1548 | 0, /* bitpos */ | |
1549 | complain_overflow_signed, /* complain_on_overflow */ | |
1550 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1551 | "R_PPC64_TPREL16_DS", /* name */ | |
1552 | FALSE, /* partial_inplace */ | |
1553 | 0, /* src_mask */ | |
1554 | 0xfffc, /* dst_mask */ | |
1555 | FALSE), /* pcrel_offset */ | |
1556 | ||
1557 | /* Like TPREL16_DS, but no overflow. */ | |
1558 | HOWTO (R_PPC64_TPREL16_LO_DS, | |
1559 | 0, /* rightshift */ | |
1560 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1561 | 16, /* bitsize */ | |
1562 | FALSE, /* pc_relative */ | |
1563 | 0, /* bitpos */ | |
1564 | complain_overflow_dont, /* complain_on_overflow */ | |
1565 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1566 | "R_PPC64_TPREL16_LO_DS", /* name */ | |
1567 | FALSE, /* partial_inplace */ | |
1568 | 0, /* src_mask */ | |
1569 | 0xfffc, /* dst_mask */ | |
1570 | FALSE), /* pcrel_offset */ | |
1571 | ||
1572 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1573 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1574 | to the first entry relative to the TOC base (r2). */ | |
1575 | HOWTO (R_PPC64_GOT_TLSGD16, | |
1576 | 0, /* rightshift */ | |
1577 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1578 | 16, /* bitsize */ | |
1579 | FALSE, /* pc_relative */ | |
1580 | 0, /* bitpos */ | |
1581 | complain_overflow_signed, /* complain_on_overflow */ | |
1582 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1583 | "R_PPC64_GOT_TLSGD16", /* name */ | |
b34976b6 | 1584 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1585 | 0, /* src_mask */ |
1586 | 0xffff, /* dst_mask */ | |
b34976b6 | 1587 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1588 | |
411e1bfb AM |
1589 | /* Like GOT_TLSGD16, but no overflow. */ |
1590 | HOWTO (R_PPC64_GOT_TLSGD16_LO, | |
5bd4f169 AM |
1591 | 0, /* rightshift */ |
1592 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1593 | 16, /* bitsize */ | |
b34976b6 | 1594 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1595 | 0, /* bitpos */ |
1596 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1597 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1598 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
b34976b6 | 1599 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1600 | 0, /* src_mask */ |
1601 | 0xffff, /* dst_mask */ | |
b34976b6 | 1602 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1603 | |
411e1bfb AM |
1604 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1605 | HOWTO (R_PPC64_GOT_TLSGD16_HI, | |
5bd4f169 AM |
1606 | 16, /* rightshift */ |
1607 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1608 | 16, /* bitsize */ | |
b34976b6 | 1609 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1610 | 0, /* bitpos */ |
1611 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1612 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1613 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
b34976b6 | 1614 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1615 | 0, /* src_mask */ |
1616 | 0xffff, /* dst_mask */ | |
b34976b6 | 1617 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1618 | |
411e1bfb AM |
1619 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1620 | HOWTO (R_PPC64_GOT_TLSGD16_HA, | |
5bd4f169 AM |
1621 | 16, /* rightshift */ |
1622 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1623 | 16, /* bitsize */ | |
b34976b6 | 1624 | FALSE, /* pc_relative */ |
5bd4f169 | 1625 | 0, /* bitpos */ |
411e1bfb | 1626 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1627 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1628 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
b34976b6 | 1629 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1630 | 0, /* src_mask */ |
1631 | 0xffff, /* dst_mask */ | |
b34976b6 | 1632 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1633 | |
411e1bfb AM |
1634 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
1635 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1636 | first entry relative to the TOC base (r2). */ | |
1637 | HOWTO (R_PPC64_GOT_TLSLD16, | |
5bd4f169 AM |
1638 | 0, /* rightshift */ |
1639 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1640 | 16, /* bitsize */ | |
b34976b6 | 1641 | FALSE, /* pc_relative */ |
5bd4f169 | 1642 | 0, /* bitpos */ |
411e1bfb AM |
1643 | complain_overflow_signed, /* complain_on_overflow */ |
1644 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1645 | "R_PPC64_GOT_TLSLD16", /* name */ | |
b34976b6 | 1646 | FALSE, /* partial_inplace */ |
d006db6c | 1647 | 0, /* src_mask */ |
411e1bfb | 1648 | 0xffff, /* dst_mask */ |
b34976b6 | 1649 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1650 | |
411e1bfb AM |
1651 | /* Like GOT_TLSLD16, but no overflow. */ |
1652 | HOWTO (R_PPC64_GOT_TLSLD16_LO, | |
5bd4f169 AM |
1653 | 0, /* rightshift */ |
1654 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1655 | 16, /* bitsize */ | |
b34976b6 | 1656 | FALSE, /* pc_relative */ |
5bd4f169 | 1657 | 0, /* bitpos */ |
411e1bfb AM |
1658 | complain_overflow_dont, /* complain_on_overflow */ |
1659 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1660 | "R_PPC64_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1661 | FALSE, /* partial_inplace */ |
d006db6c | 1662 | 0, /* src_mask */ |
411e1bfb | 1663 | 0xffff, /* dst_mask */ |
b34976b6 | 1664 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1665 | |
411e1bfb AM |
1666 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1667 | HOWTO (R_PPC64_GOT_TLSLD16_HI, | |
1668 | 16, /* rightshift */ | |
5bd4f169 AM |
1669 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1670 | 16, /* bitsize */ | |
b34976b6 | 1671 | FALSE, /* pc_relative */ |
5bd4f169 | 1672 | 0, /* bitpos */ |
411e1bfb | 1673 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1674 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1675 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
b34976b6 | 1676 | FALSE, /* partial_inplace */ |
d006db6c | 1677 | 0, /* src_mask */ |
411e1bfb | 1678 | 0xffff, /* dst_mask */ |
b34976b6 | 1679 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1680 | |
411e1bfb AM |
1681 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1682 | HOWTO (R_PPC64_GOT_TLSLD16_HA, | |
1683 | 16, /* rightshift */ | |
5bd4f169 AM |
1684 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1685 | 16, /* bitsize */ | |
b34976b6 | 1686 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1687 | 0, /* bitpos */ |
1688 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1689 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1690 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
b34976b6 | 1691 | FALSE, /* partial_inplace */ |
d006db6c | 1692 | 0, /* src_mask */ |
411e1bfb | 1693 | 0xffff, /* dst_mask */ |
b34976b6 | 1694 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1695 | |
411e1bfb AM |
1696 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
1697 | the offset to the entry relative to the TOC base (r2). */ | |
1698 | HOWTO (R_PPC64_GOT_DTPREL16_DS, | |
5bd4f169 AM |
1699 | 0, /* rightshift */ |
1700 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1701 | 16, /* bitsize */ | |
b34976b6 | 1702 | FALSE, /* pc_relative */ |
5bd4f169 | 1703 | 0, /* bitpos */ |
411e1bfb | 1704 | complain_overflow_signed, /* complain_on_overflow */ |
805fc799 | 1705 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1706 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
b34976b6 | 1707 | FALSE, /* partial_inplace */ |
d006db6c | 1708 | 0, /* src_mask */ |
5bd4f169 | 1709 | 0xfffc, /* dst_mask */ |
b34976b6 | 1710 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1711 | |
411e1bfb AM |
1712 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
1713 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, | |
5bd4f169 | 1714 | 0, /* rightshift */ |
c061c2d8 AM |
1715 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1716 | 16, /* bitsize */ | |
b34976b6 | 1717 | FALSE, /* pc_relative */ |
5bd4f169 | 1718 | 0, /* bitpos */ |
411e1bfb AM |
1719 | complain_overflow_dont, /* complain_on_overflow */ |
1720 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1721 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ | |
b34976b6 | 1722 | FALSE, /* partial_inplace */ |
d006db6c | 1723 | 0, /* src_mask */ |
c061c2d8 | 1724 | 0xfffc, /* dst_mask */ |
b34976b6 | 1725 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1726 | |
411e1bfb AM |
1727 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
1728 | HOWTO (R_PPC64_GOT_DTPREL16_HI, | |
1729 | 16, /* rightshift */ | |
5bd4f169 AM |
1730 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1731 | 16, /* bitsize */ | |
b34976b6 | 1732 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1733 | 0, /* bitpos */ |
1734 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1735 | ppc64_elf_unhandled_reloc, /* special_function */ |
1736 | "R_PPC64_GOT_DTPREL16_HI", /* name */ | |
b34976b6 | 1737 | FALSE, /* partial_inplace */ |
d006db6c | 1738 | 0, /* src_mask */ |
411e1bfb | 1739 | 0xffff, /* dst_mask */ |
b34976b6 | 1740 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1741 | |
411e1bfb AM |
1742 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1743 | HOWTO (R_PPC64_GOT_DTPREL16_HA, | |
1744 | 16, /* rightshift */ | |
1745 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1746 | 16, /* bitsize */ | |
1747 | FALSE, /* pc_relative */ | |
1748 | 0, /* bitpos */ | |
1749 | complain_overflow_dont, /* complain_on_overflow */ | |
1750 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1751 | "R_PPC64_GOT_DTPREL16_HA", /* name */ | |
1752 | FALSE, /* partial_inplace */ | |
1753 | 0, /* src_mask */ | |
1754 | 0xffff, /* dst_mask */ | |
1755 | FALSE), /* pcrel_offset */ | |
1756 | ||
1757 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the | |
1758 | offset to the entry relative to the TOC base (r2). */ | |
1759 | HOWTO (R_PPC64_GOT_TPREL16_DS, | |
5bd4f169 AM |
1760 | 0, /* rightshift */ |
1761 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1762 | 16, /* bitsize */ | |
b34976b6 | 1763 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1764 | 0, /* bitpos */ |
1765 | complain_overflow_signed, /* complain_on_overflow */ | |
411e1bfb AM |
1766 | ppc64_elf_unhandled_reloc, /* special_function */ |
1767 | "R_PPC64_GOT_TPREL16_DS", /* name */ | |
b34976b6 | 1768 | FALSE, /* partial_inplace */ |
d006db6c | 1769 | 0, /* src_mask */ |
ad8e1ba5 | 1770 | 0xfffc, /* dst_mask */ |
b34976b6 | 1771 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1772 | |
411e1bfb AM |
1773 | /* Like GOT_TPREL16_DS, but no overflow. */ |
1774 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, | |
5bd4f169 AM |
1775 | 0, /* rightshift */ |
1776 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1777 | 16, /* bitsize */ | |
b34976b6 | 1778 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1779 | 0, /* bitpos */ |
1780 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1781 | ppc64_elf_unhandled_reloc, /* special_function */ |
1782 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ | |
b34976b6 | 1783 | FALSE, /* partial_inplace */ |
d006db6c | 1784 | 0, /* src_mask */ |
ad8e1ba5 | 1785 | 0xfffc, /* dst_mask */ |
b34976b6 | 1786 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1787 | |
411e1bfb AM |
1788 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
1789 | HOWTO (R_PPC64_GOT_TPREL16_HI, | |
1790 | 16, /* rightshift */ | |
5bd4f169 AM |
1791 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1792 | 16, /* bitsize */ | |
b34976b6 | 1793 | FALSE, /* pc_relative */ |
5bd4f169 | 1794 | 0, /* bitpos */ |
411e1bfb | 1795 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1796 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1797 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
b34976b6 | 1798 | FALSE, /* partial_inplace */ |
d006db6c | 1799 | 0, /* src_mask */ |
411e1bfb | 1800 | 0xffff, /* dst_mask */ |
b34976b6 | 1801 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1802 | |
411e1bfb AM |
1803 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
1804 | HOWTO (R_PPC64_GOT_TPREL16_HA, | |
1805 | 16, /* rightshift */ | |
5bd4f169 AM |
1806 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1807 | 16, /* bitsize */ | |
b34976b6 | 1808 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1809 | 0, /* bitpos */ |
1810 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1811 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1812 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
b34976b6 | 1813 | FALSE, /* partial_inplace */ |
d006db6c | 1814 | 0, /* src_mask */ |
411e1bfb | 1815 | 0xffff, /* dst_mask */ |
b34976b6 | 1816 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1817 | |
1818 | /* GNU extension to record C++ vtable hierarchy. */ | |
1819 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1820 | 0, /* rightshift */ | |
1821 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1822 | 0, /* bitsize */ | |
b34976b6 | 1823 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1824 | 0, /* bitpos */ |
1825 | complain_overflow_dont, /* complain_on_overflow */ | |
1826 | NULL, /* special_function */ | |
1827 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1828 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1829 | 0, /* src_mask */ |
1830 | 0, /* dst_mask */ | |
b34976b6 | 1831 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1832 | |
1833 | /* GNU extension to record C++ vtable member usage. */ | |
1834 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1835 | 0, /* rightshift */ | |
1836 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1837 | 0, /* bitsize */ | |
b34976b6 | 1838 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1839 | 0, /* bitpos */ |
1840 | complain_overflow_dont, /* complain_on_overflow */ | |
1841 | NULL, /* special_function */ | |
1842 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1843 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1844 | 0, /* src_mask */ |
1845 | 0, /* dst_mask */ | |
b34976b6 | 1846 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1847 | }; |
1848 | ||
1849 | \f | |
1850 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1851 | be done. */ | |
1852 | ||
1853 | static void | |
4ce794b7 | 1854 | ppc_howto_init (void) |
5bd4f169 AM |
1855 | { |
1856 | unsigned int i, type; | |
1857 | ||
1858 | for (i = 0; | |
1859 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1860 | i++) | |
1861 | { | |
1862 | type = ppc64_elf_howto_raw[i].type; | |
1863 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1864 | / sizeof (ppc64_elf_howto_table[0]))); | |
1865 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1866 | } | |
1867 | } | |
1868 | ||
1869 | static reloc_howto_type * | |
4ce794b7 AM |
1870 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1871 | bfd_reloc_code_real_type code) | |
5bd4f169 | 1872 | { |
411e1bfb | 1873 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
5bd4f169 AM |
1874 | |
1875 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1876 | /* Initialize howto table if needed. */ | |
1877 | ppc_howto_init (); | |
1878 | ||
4ce794b7 | 1879 | switch (code) |
5bd4f169 AM |
1880 | { |
1881 | default: | |
4ce794b7 | 1882 | return NULL; |
5bd4f169 | 1883 | |
411e1bfb AM |
1884 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
1885 | break; | |
1886 | case BFD_RELOC_32: r = R_PPC64_ADDR32; | |
1887 | break; | |
1888 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; | |
1889 | break; | |
1890 | case BFD_RELOC_16: r = R_PPC64_ADDR16; | |
1891 | break; | |
1892 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; | |
1893 | break; | |
1894 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; | |
1895 | break; | |
1896 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; | |
5bd4f169 | 1897 | break; |
411e1bfb | 1898 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
5bd4f169 | 1899 | break; |
411e1bfb | 1900 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
5bd4f169 | 1901 | break; |
411e1bfb | 1902 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
5bd4f169 | 1903 | break; |
411e1bfb | 1904 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
5bd4f169 | 1905 | break; |
411e1bfb | 1906 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
5bd4f169 | 1907 | break; |
411e1bfb | 1908 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
5bd4f169 | 1909 | break; |
411e1bfb | 1910 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
5bd4f169 | 1911 | break; |
411e1bfb | 1912 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
5bd4f169 | 1913 | break; |
411e1bfb | 1914 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
5bd4f169 | 1915 | break; |
411e1bfb | 1916 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
5bd4f169 | 1917 | break; |
411e1bfb | 1918 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
5bd4f169 | 1919 | break; |
411e1bfb | 1920 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
5bd4f169 | 1921 | break; |
411e1bfb | 1922 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
5bd4f169 | 1923 | break; |
411e1bfb | 1924 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
5bd4f169 | 1925 | break; |
411e1bfb | 1926 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
5bd4f169 | 1927 | break; |
411e1bfb | 1928 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
5bd4f169 | 1929 | break; |
411e1bfb | 1930 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
5bd4f169 | 1931 | break; |
411e1bfb | 1932 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
5bd4f169 | 1933 | break; |
411e1bfb | 1934 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
5bd4f169 | 1935 | break; |
411e1bfb | 1936 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
5bd4f169 | 1937 | break; |
411e1bfb | 1938 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
5bd4f169 | 1939 | break; |
411e1bfb | 1940 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
5bd4f169 | 1941 | break; |
411e1bfb | 1942 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
5bd4f169 | 1943 | break; |
411e1bfb | 1944 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
5bd4f169 | 1945 | break; |
411e1bfb | 1946 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
5bd4f169 | 1947 | break; |
411e1bfb | 1948 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
5bd4f169 | 1949 | break; |
411e1bfb | 1950 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
5bd4f169 | 1951 | break; |
411e1bfb | 1952 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
5bd4f169 | 1953 | break; |
411e1bfb | 1954 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
5bd4f169 | 1955 | break; |
411e1bfb | 1956 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
5bd4f169 | 1957 | break; |
411e1bfb | 1958 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
5bd4f169 | 1959 | break; |
411e1bfb | 1960 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
5bd4f169 | 1961 | break; |
411e1bfb | 1962 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
5bd4f169 | 1963 | break; |
411e1bfb | 1964 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
5bd4f169 | 1965 | break; |
411e1bfb | 1966 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
5bd4f169 | 1967 | break; |
411e1bfb | 1968 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
5bd4f169 | 1969 | break; |
411e1bfb | 1970 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
5bd4f169 | 1971 | break; |
411e1bfb | 1972 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
5bd4f169 | 1973 | break; |
411e1bfb | 1974 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
5bd4f169 | 1975 | break; |
411e1bfb | 1976 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
5bd4f169 | 1977 | break; |
411e1bfb | 1978 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
5bd4f169 | 1979 | break; |
411e1bfb | 1980 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
5bd4f169 | 1981 | break; |
411e1bfb | 1982 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
5bd4f169 | 1983 | break; |
411e1bfb | 1984 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
5bd4f169 | 1985 | break; |
411e1bfb | 1986 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
5bd4f169 | 1987 | break; |
411e1bfb | 1988 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
5bd4f169 | 1989 | break; |
411e1bfb | 1990 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
5bd4f169 | 1991 | break; |
411e1bfb | 1992 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
5bd4f169 | 1993 | break; |
411e1bfb | 1994 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
5bd4f169 | 1995 | break; |
411e1bfb | 1996 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
5bd4f169 | 1997 | break; |
411e1bfb | 1998 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
5bd4f169 | 1999 | break; |
411e1bfb | 2000 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
5bd4f169 | 2001 | break; |
411e1bfb | 2002 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
5bd4f169 | 2003 | break; |
411e1bfb | 2004 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
5bd4f169 | 2005 | break; |
411e1bfb | 2006 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
5bd4f169 | 2007 | break; |
411e1bfb | 2008 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
5bd4f169 | 2009 | break; |
411e1bfb | 2010 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
5bd4f169 | 2011 | break; |
411e1bfb | 2012 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
5bd4f169 | 2013 | break; |
411e1bfb | 2014 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
5bd4f169 | 2015 | break; |
411e1bfb AM |
2016 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
2017 | break; | |
2018 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; | |
2019 | break; | |
2020 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; | |
2021 | break; | |
2022 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; | |
2023 | break; | |
2024 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; | |
2025 | break; | |
2026 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; | |
2027 | break; | |
2028 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; | |
2029 | break; | |
2030 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; | |
2031 | break; | |
2032 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; | |
2033 | break; | |
2034 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; | |
2035 | break; | |
2036 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; | |
2037 | break; | |
2038 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; | |
2039 | break; | |
2040 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; | |
2041 | break; | |
2042 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; | |
2043 | break; | |
2044 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; | |
2045 | break; | |
2046 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; | |
2047 | break; | |
2048 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; | |
2049 | break; | |
2050 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; | |
2051 | break; | |
2052 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; | |
2053 | break; | |
2054 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; | |
2055 | break; | |
2056 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; | |
2057 | break; | |
2058 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; | |
2059 | break; | |
2060 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; | |
2061 | break; | |
2062 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; | |
2063 | break; | |
2064 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; | |
2065 | break; | |
2066 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; | |
2067 | break; | |
2068 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; | |
2069 | break; | |
2070 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; | |
2071 | break; | |
2072 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; | |
2073 | break; | |
2074 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; | |
2075 | break; | |
2076 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; | |
2077 | break; | |
2078 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; | |
2079 | break; | |
2080 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; | |
2081 | break; | |
2082 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; | |
2083 | break; | |
2084 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; | |
5bd4f169 AM |
2085 | break; |
2086 | } | |
2087 | ||
4ce794b7 | 2088 | return ppc64_elf_howto_table[r]; |
5bd4f169 AM |
2089 | }; |
2090 | ||
2091 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
2092 | ||
2093 | static void | |
4ce794b7 AM |
2094 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
2095 | Elf_Internal_Rela *dst) | |
5bd4f169 | 2096 | { |
65f38f15 AM |
2097 | unsigned int type; |
2098 | ||
ef60b7ff | 2099 | /* Initialize howto table if needed. */ |
5bd4f169 | 2100 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
2101 | ppc_howto_init (); |
2102 | ||
65f38f15 AM |
2103 | type = ELF64_R_TYPE (dst->r_info); |
2104 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
2105 | / sizeof (ppc64_elf_howto_table[0]))); | |
2106 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
2107 | } |
2108 | ||
04c9666a | 2109 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
2110 | |
2111 | static bfd_reloc_status_type | |
4ce794b7 AM |
2112 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2113 | void *data, asection *input_section, | |
2114 | bfd *output_bfd, char **error_message) | |
5bd4f169 | 2115 | { |
805fc799 AM |
2116 | /* If this is a relocatable link (output_bfd test tells us), just |
2117 | call the generic function. Any adjustment will be done at final | |
2118 | link time. */ | |
2119 | if (output_bfd != NULL) | |
cedb70c5 | 2120 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2121 | input_section, output_bfd, error_message); |
2122 | ||
2123 | /* Adjust the addend for sign extension of the low 16 bits. | |
2124 | We won't actually be using the low 16 bits, so trashing them | |
2125 | doesn't matter. */ | |
2126 | reloc_entry->addend += 0x8000; | |
2127 | return bfd_reloc_continue; | |
2128 | } | |
5bd4f169 | 2129 | |
805fc799 | 2130 | static bfd_reloc_status_type |
4ce794b7 AM |
2131 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2132 | void *data, asection *input_section, | |
2133 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2134 | { |
2135 | long insn; | |
04c9666a | 2136 | enum elf_ppc64_reloc_type r_type; |
805fc799 AM |
2137 | bfd_size_type octets; |
2138 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 2139 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
2140 | |
2141 | /* If this is a relocatable link (output_bfd test tells us), just | |
2142 | call the generic function. Any adjustment will be done at final | |
2143 | link time. */ | |
5bd4f169 | 2144 | if (output_bfd != NULL) |
cedb70c5 | 2145 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2146 | input_section, output_bfd, error_message); |
2147 | ||
2148 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2149 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2150 | insn &= ~(0x01 << 21); | |
4ce794b7 | 2151 | r_type = reloc_entry->howto->type; |
805fc799 AM |
2152 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
2153 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 2154 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
2155 | |
2156 | if (is_power4) | |
5bd4f169 | 2157 | { |
805fc799 AM |
2158 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
2159 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
2160 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
2161 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
2162 | insn |= 0x02 << 21; | |
2163 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
2164 | insn |= 0x08 << 21; | |
2165 | else | |
2166 | return bfd_reloc_continue; | |
5bd4f169 | 2167 | } |
805fc799 AM |
2168 | else |
2169 | { | |
2170 | bfd_vma target = 0; | |
2171 | bfd_vma from; | |
5bd4f169 | 2172 | |
805fc799 AM |
2173 | if (!bfd_is_com_section (symbol->section)) |
2174 | target = symbol->value; | |
2175 | target += symbol->section->output_section->vma; | |
2176 | target += symbol->section->output_offset; | |
2177 | target += reloc_entry->addend; | |
5bd4f169 | 2178 | |
805fc799 AM |
2179 | from = (reloc_entry->address |
2180 | + input_section->output_offset | |
2181 | + input_section->output_section->vma); | |
5bd4f169 | 2182 | |
805fc799 AM |
2183 | /* Invert 'y' bit if not the default. */ |
2184 | if ((bfd_signed_vma) (target - from) < 0) | |
2185 | insn ^= 0x01 << 21; | |
2186 | } | |
4ce794b7 | 2187 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
805fc799 AM |
2188 | return bfd_reloc_continue; |
2189 | } | |
5bd4f169 | 2190 | |
805fc799 | 2191 | static bfd_reloc_status_type |
4ce794b7 AM |
2192 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2193 | void *data, asection *input_section, | |
2194 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2195 | { |
2196 | /* If this is a relocatable link (output_bfd test tells us), just | |
2197 | call the generic function. Any adjustment will be done at final | |
2198 | link time. */ | |
2199 | if (output_bfd != NULL) | |
cedb70c5 | 2200 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 2201 | input_section, output_bfd, error_message); |
5bd4f169 | 2202 | |
805fc799 AM |
2203 | /* Subtract the symbol section base address. */ |
2204 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
2205 | return bfd_reloc_continue; |
2206 | } | |
2207 | ||
805fc799 | 2208 | static bfd_reloc_status_type |
4ce794b7 AM |
2209 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2210 | void *data, asection *input_section, | |
2211 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2212 | { |
2213 | /* If this is a relocatable link (output_bfd test tells us), just | |
2214 | call the generic function. Any adjustment will be done at final | |
2215 | link time. */ | |
2216 | if (output_bfd != NULL) | |
cedb70c5 | 2217 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2218 | input_section, output_bfd, error_message); |
2219 | ||
2220 | /* Subtract the symbol section base address. */ | |
2221 | reloc_entry->addend -= symbol->section->output_section->vma; | |
2222 | ||
2223 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2224 | reloc_entry->addend += 0x8000; | |
2225 | return bfd_reloc_continue; | |
2226 | } | |
2227 | ||
2228 | static bfd_reloc_status_type | |
4ce794b7 AM |
2229 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2230 | void *data, asection *input_section, | |
2231 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2232 | { |
2233 | bfd_vma TOCstart; | |
2234 | ||
2235 | /* If this is a relocatable link (output_bfd test tells us), just | |
2236 | call the generic function. Any adjustment will be done at final | |
2237 | link time. */ | |
2238 | if (output_bfd != NULL) | |
cedb70c5 | 2239 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2240 | input_section, output_bfd, error_message); |
2241 | ||
2242 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2243 | if (TOCstart == 0) | |
2244 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2245 | ||
2246 | /* Subtract the TOC base address. */ | |
2247 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2248 | return bfd_reloc_continue; | |
2249 | } | |
2250 | ||
2251 | static bfd_reloc_status_type | |
4ce794b7 AM |
2252 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2253 | void *data, asection *input_section, | |
2254 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2255 | { |
2256 | bfd_vma TOCstart; | |
2257 | ||
2258 | /* If this is a relocatable link (output_bfd test tells us), just | |
2259 | call the generic function. Any adjustment will be done at final | |
2260 | link time. */ | |
2261 | if (output_bfd != NULL) | |
cedb70c5 | 2262 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2263 | input_section, output_bfd, error_message); |
2264 | ||
2265 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2266 | if (TOCstart == 0) | |
2267 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2268 | ||
2269 | /* Subtract the TOC base address. */ | |
2270 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2271 | ||
2272 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2273 | reloc_entry->addend += 0x8000; | |
2274 | return bfd_reloc_continue; | |
2275 | } | |
2276 | ||
2277 | static bfd_reloc_status_type | |
4ce794b7 AM |
2278 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2279 | void *data, asection *input_section, | |
2280 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2281 | { |
2282 | bfd_vma TOCstart; | |
2283 | bfd_size_type octets; | |
2284 | ||
2285 | /* If this is a relocatable link (output_bfd test tells us), just | |
2286 | call the generic function. Any adjustment will be done at final | |
2287 | link time. */ | |
2288 | if (output_bfd != NULL) | |
cedb70c5 | 2289 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2290 | input_section, output_bfd, error_message); |
2291 | ||
2292 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2293 | if (TOCstart == 0) | |
2294 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2295 | ||
2296 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2297 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
2298 | return bfd_reloc_ok; | |
2299 | } | |
2300 | ||
2301 | static bfd_reloc_status_type | |
4ce794b7 AM |
2302 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2303 | void *data, asection *input_section, | |
2304 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2305 | { |
2306 | /* If this is a relocatable link (output_bfd test tells us), just | |
2307 | call the generic function. Any adjustment will be done at final | |
2308 | link time. */ | |
2309 | if (output_bfd != NULL) | |
cedb70c5 | 2310 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2311 | input_section, output_bfd, error_message); |
2312 | ||
2313 | if (error_message != NULL) | |
2314 | { | |
2315 | static char buf[60]; | |
2316 | sprintf (buf, "generic linker can't handle %s", | |
2317 | reloc_entry->howto->name); | |
2318 | *error_message = buf; | |
2319 | } | |
2320 | return bfd_reloc_dangerous; | |
2321 | } | |
2322 | ||
e717da7e AM |
2323 | struct ppc64_elf_obj_tdata |
2324 | { | |
2325 | struct elf_obj_tdata elf; | |
2326 | ||
2327 | /* Shortcuts to dynamic linker sections. */ | |
2328 | asection *got; | |
2329 | asection *relgot; | |
2330 | ||
2331 | /* TLS local dynamic got entry handling. Suppose for multiple GOT | |
2332 | sections means we potentially need one of these for each input bfd. */ | |
2333 | union { | |
2334 | bfd_signed_vma refcount; | |
2335 | bfd_vma offset; | |
2336 | } tlsld_got; | |
2337 | }; | |
2338 | ||
2339 | #define ppc64_elf_tdata(bfd) \ | |
2340 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) | |
2341 | ||
2342 | #define ppc64_tlsld_got(bfd) \ | |
2343 | (&ppc64_elf_tdata (bfd)->tlsld_got) | |
2344 | ||
2345 | /* Override the generic function because we store some extras. */ | |
2346 | ||
2347 | static bfd_boolean | |
2348 | ppc64_elf_mkobject (bfd *abfd) | |
2349 | { | |
2350 | bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); | |
2351 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2352 | if (abfd->tdata.any == NULL) | |
2353 | return FALSE; | |
2354 | return TRUE; | |
2355 | } | |
2356 | ||
feee612b AM |
2357 | /* Fix bad default arch selected for a 64 bit input bfd when the |
2358 | default is 32 bit. */ | |
2359 | ||
b34976b6 | 2360 | static bfd_boolean |
4ce794b7 | 2361 | ppc64_elf_object_p (bfd *abfd) |
feee612b AM |
2362 | { |
2363 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
2364 | { | |
2365 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2366 | ||
2367 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
2368 | { | |
2369 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
2370 | abfd->arch_info = abfd->arch_info->next; | |
2371 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
2372 | } | |
2373 | } | |
b34976b6 | 2374 | return TRUE; |
feee612b AM |
2375 | } |
2376 | ||
d37c89e5 AM |
2377 | /* Support for core dump NOTE sections. */ |
2378 | ||
2379 | static bfd_boolean | |
2380 | ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
2381 | { | |
2382 | size_t offset, raw_size; | |
2383 | ||
2384 | if (note->descsz != 504) | |
2385 | return FALSE; | |
2386 | ||
2387 | /* pr_cursig */ | |
2388 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
2389 | ||
2390 | /* pr_pid */ | |
2391 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32); | |
2392 | ||
2393 | /* pr_reg */ | |
2394 | offset = 112; | |
2395 | raw_size = 384; | |
2396 | ||
2397 | /* Make a ".reg/999" section. */ | |
2398 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
2399 | raw_size, note->descpos + offset); | |
2400 | } | |
2401 | ||
2402 | static bfd_boolean | |
2403 | ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
2404 | { | |
2405 | if (note->descsz != 136) | |
2406 | return FALSE; | |
2407 | ||
2408 | elf_tdata (abfd)->core_program | |
2409 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |
2410 | elf_tdata (abfd)->core_command | |
2411 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |
2412 | ||
2413 | return TRUE; | |
2414 | } | |
2415 | ||
5bd4f169 AM |
2416 | /* Merge backend specific data from an object file to the output |
2417 | object file when linking. */ | |
2f6d9989 | 2418 | |
b34976b6 | 2419 | static bfd_boolean |
4ce794b7 | 2420 | ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
5bd4f169 | 2421 | { |
5bd4f169 AM |
2422 | /* Check if we have the same endianess. */ |
2423 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
87e226ce | 2424 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
5bd4f169 AM |
2425 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
2426 | { | |
2427 | const char *msg; | |
2428 | ||
2429 | if (bfd_big_endian (ibfd)) | |
4ce794b7 AM |
2430 | msg = _("%s: compiled for a big endian system " |
2431 | "and target is little endian"); | |
5bd4f169 | 2432 | else |
4ce794b7 AM |
2433 | msg = _("%s: compiled for a little endian system " |
2434 | "and target is big endian"); | |
5bd4f169 | 2435 | |
8f615d07 | 2436 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
5bd4f169 AM |
2437 | |
2438 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 2439 | return FALSE; |
5bd4f169 AM |
2440 | } |
2441 | ||
b34976b6 | 2442 | return TRUE; |
5bd4f169 | 2443 | } |
f0abc2a1 | 2444 | |
5d35169e AM |
2445 | /* Add extra PPC sections. */ |
2446 | ||
2447 | static struct bfd_elf_special_section const ppc64_elf_special_sections[]= | |
2448 | { | |
7dcb9820 AM |
2449 | { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
2450 | { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2451 | { ".plt", 4, 0, SHT_NOBITS, 0 }, | |
2452 | { ".toc", 4, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2453 | { ".toc1", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2454 | { ".tocbss", 7, 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2455 | { NULL, 0, 0, 0, 0 } | |
5d35169e AM |
2456 | }; |
2457 | ||
f0abc2a1 AM |
2458 | struct _ppc64_elf_section_data |
2459 | { | |
2460 | struct bfd_elf_section_data elf; | |
411e1bfb AM |
2461 | |
2462 | /* An array with one entry for each opd function descriptor. */ | |
f0abc2a1 AM |
2463 | union |
2464 | { | |
411e1bfb | 2465 | /* Points to the function code section for local opd entries. */ |
f0abc2a1 | 2466 | asection **func_sec; |
411e1bfb | 2467 | /* After editing .opd, adjust references to opd local syms. */ |
f0abc2a1 AM |
2468 | long *adjust; |
2469 | } opd; | |
411e1bfb AM |
2470 | |
2471 | /* An array for toc sections, indexed by offset/8. | |
2472 | Specifies the relocation symbol index used at a given toc offset. */ | |
2473 | unsigned *t_symndx; | |
f0abc2a1 AM |
2474 | }; |
2475 | ||
2476 | #define ppc64_elf_section_data(sec) \ | |
411e1bfb | 2477 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
f0abc2a1 AM |
2478 | |
2479 | static bfd_boolean | |
4ce794b7 | 2480 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
f0abc2a1 AM |
2481 | { |
2482 | struct _ppc64_elf_section_data *sdata; | |
2483 | bfd_size_type amt = sizeof (*sdata); | |
2484 | ||
4ce794b7 | 2485 | sdata = bfd_zalloc (abfd, amt); |
f0abc2a1 AM |
2486 | if (sdata == NULL) |
2487 | return FALSE; | |
4ce794b7 | 2488 | sec->used_by_bfd = sdata; |
f0abc2a1 AM |
2489 | |
2490 | return _bfd_elf_new_section_hook (abfd, sec); | |
2491 | } | |
5bd4f169 | 2492 | \f |
65f38f15 AM |
2493 | /* The following functions are specific to the ELF linker, while |
2494 | functions above are used generally. Those named ppc64_elf_* are | |
2495 | called by the main ELF linker code. They appear in this file more | |
2496 | or less in the order in which they are called. eg. | |
2497 | ppc64_elf_check_relocs is called early in the link process, | |
2498 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
2499 | called. |
2500 | ||
2501 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
2502 | functions have both a function code symbol and a function descriptor | |
2503 | symbol. A call to foo in a relocatable object file looks like: | |
2504 | ||
2505 | . .text | |
2506 | . x: | |
2507 | . bl .foo | |
2508 | . nop | |
2509 | ||
2510 | The function definition in another object file might be: | |
2511 | ||
2512 | . .section .opd | |
2513 | . foo: .quad .foo | |
2514 | . .quad .TOC.@tocbase | |
2515 | . .quad 0 | |
2516 | . | |
2517 | . .text | |
2518 | . .foo: blr | |
2519 | ||
2520 | When the linker resolves the call during a static link, the branch | |
2521 | unsurprisingly just goes to .foo and the .opd information is unused. | |
2522 | If the function definition is in a shared library, things are a little | |
2523 | different: The call goes via a plt call stub, the opd information gets | |
2524 | copied to the plt, and the linker patches the nop. | |
2525 | ||
2526 | . x: | |
2527 | . bl .foo_stub | |
2528 | . ld 2,40(1) | |
2529 | . | |
2530 | . | |
2531 | . .foo_stub: | |
2532 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
411e1bfb | 2533 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
e86ce104 AM |
2534 | . std 2,40(1) # this is the general idea |
2535 | . ld 11,0(12) | |
2536 | . ld 2,8(12) | |
2537 | . mtctr 11 | |
2538 | . ld 11,16(12) | |
2539 | . bctr | |
2540 | . | |
2541 | . .section .plt | |
2542 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
2543 | ||
2544 | The "reloc ()" notation is supposed to indicate that the linker emits | |
2545 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
2546 | copying. | |
2547 | ||
2548 | What are the difficulties here? Well, firstly, the relocations | |
2549 | examined by the linker in check_relocs are against the function code | |
2550 | sym .foo, while the dynamic relocation in the plt is emitted against | |
2551 | the function descriptor symbol, foo. Somewhere along the line, we need | |
2552 | to carefully copy dynamic link information from one symbol to the other. | |
2553 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
2554 | symbol as is normal for most other backends. We need foo dynamic | |
2555 | instead, at least for an application final link. However, when | |
2556 | creating a shared library containing foo, we need to have both symbols | |
2557 | dynamic so that references to .foo are satisfied during the early | |
2558 | stages of linking. Otherwise the linker might decide to pull in a | |
41bd81ab | 2559 | definition from some other object, eg. a static library. */ |
65f38f15 AM |
2560 | |
2561 | /* The linker needs to keep track of the number of relocs that it | |
2562 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2563 | This is so that it can later discard them if they are found to be | |
2564 | unnecessary. We store the information in a field extending the | |
2565 | regular ELF linker hash table. */ | |
2566 | ||
2567 | struct ppc_dyn_relocs | |
2568 | { | |
2569 | struct ppc_dyn_relocs *next; | |
2570 | ||
2571 | /* The input section of the reloc. */ | |
2572 | asection *sec; | |
2573 | ||
2574 | /* Total number of relocs copied for the input section. */ | |
2575 | bfd_size_type count; | |
2576 | ||
2577 | /* Number of pc-relative relocs copied for the input section. */ | |
2578 | bfd_size_type pc_count; | |
2579 | }; | |
2580 | ||
411e1bfb AM |
2581 | /* Track GOT entries needed for a given symbol. We might need more |
2582 | than one got entry per symbol. */ | |
2583 | struct got_entry | |
2584 | { | |
2585 | struct got_entry *next; | |
2586 | ||
e7b938ca | 2587 | /* The symbol addend that we'll be placing in the GOT. */ |
411e1bfb AM |
2588 | bfd_vma addend; |
2589 | ||
e717da7e AM |
2590 | /* Unlike other ELF targets, we use separate GOT entries for the same |
2591 | symbol referenced from different input files. This is to support | |
2592 | automatic multiple TOC/GOT sections, where the TOC base can vary | |
2593 | from one input file to another. | |
2594 | ||
2595 | Point to the BFD owning this GOT entry. */ | |
2596 | bfd *owner; | |
2597 | ||
2598 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, | |
2599 | TLS_TPREL or TLS_DTPREL for tls entries. */ | |
2600 | char tls_type; | |
2601 | ||
e7b938ca | 2602 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ |
411e1bfb AM |
2603 | union |
2604 | { | |
2605 | bfd_signed_vma refcount; | |
2606 | bfd_vma offset; | |
2607 | } got; | |
411e1bfb AM |
2608 | }; |
2609 | ||
2610 | /* The same for PLT. */ | |
2611 | struct plt_entry | |
2612 | { | |
2613 | struct plt_entry *next; | |
2614 | ||
2615 | bfd_vma addend; | |
2616 | ||
2617 | union | |
2618 | { | |
2619 | bfd_signed_vma refcount; | |
2620 | bfd_vma offset; | |
2621 | } plt; | |
2622 | }; | |
2623 | ||
65f38f15 | 2624 | /* Of those relocs that might be copied as dynamic relocs, this macro |
58ac9f71 AM |
2625 | selects those that must be copied when linking a shared library, |
2626 | even when the symbol is local. */ | |
65f38f15 | 2627 | |
411e1bfb | 2628 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
805fc799 AM |
2629 | ((RTYPE) != R_PPC64_REL32 \ |
2630 | && (RTYPE) != R_PPC64_REL64 \ | |
04c9666a | 2631 | && (RTYPE) != R_PPC64_REL30) |
65f38f15 | 2632 | |
f4656909 AM |
2633 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2634 | copying dynamic variables from a shared lib into an app's dynbss | |
2635 | section, and instead use a dynamic relocation to point into the | |
5d35169e AM |
2636 | shared lib. With code that gcc generates, it's vital that this be |
2637 | enabled; In the PowerPC64 ABI, the address of a function is actually | |
2638 | the address of a function descriptor, which resides in the .opd | |
2639 | section. gcc uses the descriptor directly rather than going via the | |
2640 | GOT as some other ABI's do, which means that initialized function | |
2641 | pointers must reference the descriptor. Thus, a function pointer | |
2642 | initialized to the address of a function in a shared library will | |
2643 | either require a copy reloc, or a dynamic reloc. Using a copy reloc | |
4cc11e76 | 2644 | redefines the function descriptor symbol to point to the copy. This |
5d35169e AM |
2645 | presents a problem as a plt entry for that function is also |
2646 | initialized from the function descriptor symbol and the copy reloc | |
2647 | may not be initialized first. */ | |
a23b6845 | 2648 | #define ELIMINATE_COPY_RELOCS 1 |
f4656909 | 2649 | |
721956f4 AM |
2650 | /* Section name for stubs is the associated section name plus this |
2651 | string. */ | |
2652 | #define STUB_SUFFIX ".stub" | |
2653 | ||
2654 | /* Linker stubs. | |
2655 | ppc_stub_long_branch: | |
2656 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
2657 | destination, but a 24 bit branch in a stub section will reach. | |
2658 | . b dest | |
2659 | ||
2660 | ppc_stub_plt_branch: | |
2661 | Similar to the above, but a 24 bit branch in the stub section won't | |
2662 | reach its destination. | |
87e226ce AM |
2663 | . addis %r12,%r2,xxx@toc@ha |
2664 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
2665 | . mtctr %r11 |
2666 | . bctr | |
2667 | ||
2668 | ppc_stub_plt_call: | |
2669 | Used to call a function in a shared library. | |
87e226ce | 2670 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 2671 | . std %r2,40(%r1) |
87e226ce AM |
2672 | . ld %r11,xxx+0@toc@l(%r12) |
2673 | . ld %r2,xxx+8@toc@l(%r12) | |
721956f4 | 2674 | . mtctr %r11 |
87e226ce | 2675 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 | 2676 | . bctr |
ad8e1ba5 AM |
2677 | |
2678 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional | |
2679 | code to adjust the value and save r2 to support multiple toc sections. | |
2680 | A ppc_stub_long_branch with an r2 offset looks like: | |
2681 | . std %r2,40(%r1) | |
2682 | . addis %r2,%r2,off@ha | |
2683 | . addi %r2,%r2,off@l | |
2684 | . b dest | |
2685 | ||
2686 | A ppc_stub_plt_branch with an r2 offset looks like: | |
2687 | . std %r2,40(%r1) | |
2688 | . addis %r12,%r2,xxx@toc@ha | |
2689 | . ld %r11,xxx@toc@l(%r12) | |
2690 | . addis %r2,%r2,off@ha | |
2691 | . addi %r2,%r2,off@l | |
2692 | . mtctr %r11 | |
2693 | . bctr | |
721956f4 AM |
2694 | */ |
2695 | ||
2696 | enum ppc_stub_type { | |
2697 | ppc_stub_none, | |
2698 | ppc_stub_long_branch, | |
ad8e1ba5 | 2699 | ppc_stub_long_branch_r2off, |
721956f4 | 2700 | ppc_stub_plt_branch, |
ad8e1ba5 | 2701 | ppc_stub_plt_branch_r2off, |
721956f4 AM |
2702 | ppc_stub_plt_call |
2703 | }; | |
2704 | ||
2705 | struct ppc_stub_hash_entry { | |
2706 | ||
2707 | /* Base hash table entry structure. */ | |
2708 | struct bfd_hash_entry root; | |
2709 | ||
ad8e1ba5 AM |
2710 | enum ppc_stub_type stub_type; |
2711 | ||
721956f4 AM |
2712 | /* The stub section. */ |
2713 | asection *stub_sec; | |
2714 | ||
2715 | /* Offset within stub_sec of the beginning of this stub. */ | |
2716 | bfd_vma stub_offset; | |
2717 | ||
2718 | /* Given the symbol's value and its section we can determine its final | |
2719 | value when building the stubs (so the stub knows where to jump. */ | |
2720 | bfd_vma target_value; | |
2721 | asection *target_section; | |
2722 | ||
721956f4 AM |
2723 | /* The symbol table entry, if any, that this was derived from. */ |
2724 | struct ppc_link_hash_entry *h; | |
2725 | ||
411e1bfb AM |
2726 | /* And the reloc addend that this was derived from. */ |
2727 | bfd_vma addend; | |
2728 | ||
721956f4 AM |
2729 | /* Where this stub is being called from, or, in the case of combined |
2730 | stub sections, the first input section in the group. */ | |
2731 | asection *id_sec; | |
2732 | }; | |
2733 | ||
2734 | struct ppc_branch_hash_entry { | |
2735 | ||
2736 | /* Base hash table entry structure. */ | |
2737 | struct bfd_hash_entry root; | |
2738 | ||
2739 | /* Offset within .branch_lt. */ | |
2740 | unsigned int offset; | |
2741 | ||
2742 | /* Generation marker. */ | |
2743 | unsigned int iter; | |
2744 | }; | |
65f38f15 AM |
2745 | |
2746 | struct ppc_link_hash_entry | |
2747 | { | |
2748 | struct elf_link_hash_entry elf; | |
2749 | ||
721956f4 AM |
2750 | /* A pointer to the most recently used stub hash entry against this |
2751 | symbol. */ | |
2752 | struct ppc_stub_hash_entry *stub_cache; | |
2753 | ||
65f38f15 AM |
2754 | /* Track dynamic relocs copied for this symbol. */ |
2755 | struct ppc_dyn_relocs *dyn_relocs; | |
e86ce104 | 2756 | |
721956f4 AM |
2757 | /* Link between function code and descriptor symbols. */ |
2758 | struct elf_link_hash_entry *oh; | |
2759 | ||
e86ce104 AM |
2760 | /* Flag function code and descriptor symbols. */ |
2761 | unsigned int is_func:1; | |
2762 | unsigned int is_func_descriptor:1; | |
1e2f5b6e | 2763 | unsigned int is_entry:1; |
411e1bfb AM |
2764 | |
2765 | /* Contexts in which symbol is used in the GOT (or TOC). | |
e7b938ca AM |
2766 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
2767 | corresponding relocs are encountered during check_relocs. | |
2768 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2769 | indicate the corresponding GOT entry type is not needed. | |
2770 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into | |
2771 | a TPREL one. We use a separate flag rather than setting TPREL | |
2772 | just for convenience in distinguishing the two cases. */ | |
2773 | #define TLS_GD 1 /* GD reloc. */ | |
2774 | #define TLS_LD 2 /* LD reloc. */ | |
2775 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2776 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2777 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2778 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ | |
2779 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ | |
2780 | char tls_mask; | |
65f38f15 AM |
2781 | }; |
2782 | ||
2783 | /* ppc64 ELF linker hash table. */ | |
2784 | ||
2785 | struct ppc_link_hash_table | |
2786 | { | |
2787 | struct elf_link_hash_table elf; | |
2788 | ||
721956f4 AM |
2789 | /* The stub hash table. */ |
2790 | struct bfd_hash_table stub_hash_table; | |
2791 | ||
2792 | /* Another hash table for plt_branch stubs. */ | |
2793 | struct bfd_hash_table branch_hash_table; | |
2794 | ||
2795 | /* Linker stub bfd. */ | |
2796 | bfd *stub_bfd; | |
2797 | ||
2798 | /* Linker call-backs. */ | |
4ce794b7 AM |
2799 | asection * (*add_stub_section) (const char *, asection *); |
2800 | void (*layout_sections_again) (void); | |
721956f4 AM |
2801 | |
2802 | /* Array to keep track of which stub sections have been created, and | |
2803 | information on stub grouping. */ | |
2804 | struct map_stub { | |
2805 | /* This is the section to which stubs in the group will be attached. */ | |
2806 | asection *link_sec; | |
2807 | /* The stub section. */ | |
2808 | asection *stub_sec; | |
ad8e1ba5 AM |
2809 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
2810 | bfd_vma toc_off; | |
721956f4 AM |
2811 | } *stub_group; |
2812 | ||
ad8e1ba5 AM |
2813 | /* Support for multiple toc sections. */ |
2814 | unsigned int no_multi_toc; | |
2815 | unsigned int multi_toc_needed; | |
2816 | ||
2817 | /* Temp used when calculating TOC pointers. */ | |
2818 | bfd_vma toc_curr; | |
2819 | ||
8f3bab57 AM |
2820 | /* Highest input section id. */ |
2821 | int top_id; | |
2822 | ||
734b6cf9 AM |
2823 | /* Highest output section index. */ |
2824 | int top_index; | |
2825 | ||
2826 | /* List of input sections for each output section. */ | |
2827 | asection **input_list; | |
721956f4 | 2828 | |
65f38f15 | 2829 | /* Short-cuts to get to dynamic linker sections. */ |
4ce794b7 | 2830 | asection *got; |
4ce794b7 AM |
2831 | asection *plt; |
2832 | asection *relplt; | |
2833 | asection *dynbss; | |
2834 | asection *relbss; | |
2835 | asection *glink; | |
82bd7b59 | 2836 | asection *sfpr; |
4ce794b7 AM |
2837 | asection *brlt; |
2838 | asection *relbrlt; | |
ec338859 | 2839 | |
411e1bfb AM |
2840 | /* Shortcut to .__tls_get_addr. */ |
2841 | struct elf_link_hash_entry *tls_get_addr; | |
2842 | ||
9b5ecbd0 AM |
2843 | /* Statistics. */ |
2844 | unsigned long stub_count[ppc_stub_plt_call]; | |
2845 | ||
ad8e1ba5 AM |
2846 | /* Set if we should emit symbols for stubs. */ |
2847 | unsigned int emit_stub_syms; | |
2848 | ||
5d1634d7 | 2849 | /* Set on error. */ |
721956f4 AM |
2850 | unsigned int stub_error; |
2851 | ||
2852 | /* Flag set when small branches are detected. Used to | |
2853 | select suitable defaults for the stub group size. */ | |
2854 | unsigned int has_14bit_branch; | |
2855 | ||
805fc799 AM |
2856 | /* Set if we detect a reference undefined weak symbol. */ |
2857 | unsigned int have_undefweak; | |
2858 | ||
721956f4 AM |
2859 | /* Incremented every time we size stubs. */ |
2860 | unsigned int stub_iteration; | |
5d1634d7 | 2861 | |
ec338859 AM |
2862 | /* Small local sym to section mapping cache. */ |
2863 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
2864 | }; |
2865 | ||
2866 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ | |
2867 | ||
2868 | #define ppc_hash_table(p) \ | |
2869 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
2870 | ||
721956f4 AM |
2871 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
2872 | ((struct ppc_stub_hash_entry *) \ | |
2873 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2874 | ||
2875 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
2876 | ((struct ppc_branch_hash_entry *) \ | |
2877 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2878 | ||
2879 | /* Create an entry in the stub hash table. */ | |
2880 | ||
2881 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2882 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2883 | struct bfd_hash_table *table, | |
2884 | const char *string) | |
721956f4 AM |
2885 | { |
2886 | /* Allocate the structure if it has not already been allocated by a | |
2887 | subclass. */ | |
2888 | if (entry == NULL) | |
2889 | { | |
2890 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
2891 | if (entry == NULL) | |
2892 | return entry; | |
2893 | } | |
2894 | ||
2895 | /* Call the allocation method of the superclass. */ | |
2896 | entry = bfd_hash_newfunc (entry, table, string); | |
2897 | if (entry != NULL) | |
2898 | { | |
2899 | struct ppc_stub_hash_entry *eh; | |
2900 | ||
2901 | /* Initialize the local fields. */ | |
2902 | eh = (struct ppc_stub_hash_entry *) entry; | |
ad8e1ba5 | 2903 | eh->stub_type = ppc_stub_none; |
721956f4 AM |
2904 | eh->stub_sec = NULL; |
2905 | eh->stub_offset = 0; | |
2906 | eh->target_value = 0; | |
2907 | eh->target_section = NULL; | |
721956f4 AM |
2908 | eh->h = NULL; |
2909 | eh->id_sec = NULL; | |
2910 | } | |
2911 | ||
2912 | return entry; | |
2913 | } | |
2914 | ||
2915 | /* Create an entry in the branch hash table. */ | |
2916 | ||
2917 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2918 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
2919 | struct bfd_hash_table *table, | |
2920 | const char *string) | |
721956f4 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_branch_hash_entry)); | |
2927 | if (entry == NULL) | |
2928 | return entry; | |
2929 | } | |
2930 | ||
2931 | /* Call the allocation method of the superclass. */ | |
2932 | entry = bfd_hash_newfunc (entry, table, string); | |
2933 | if (entry != NULL) | |
2934 | { | |
2935 | struct ppc_branch_hash_entry *eh; | |
2936 | ||
2937 | /* Initialize the local fields. */ | |
2938 | eh = (struct ppc_branch_hash_entry *) entry; | |
2939 | eh->offset = 0; | |
2940 | eh->iter = 0; | |
2941 | } | |
2942 | ||
2943 | return entry; | |
2944 | } | |
2945 | ||
65f38f15 AM |
2946 | /* Create an entry in a ppc64 ELF linker hash table. */ |
2947 | ||
2948 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2949 | link_hash_newfunc (struct bfd_hash_entry *entry, |
2950 | struct bfd_hash_table *table, | |
2951 | const char *string) | |
65f38f15 AM |
2952 | { |
2953 | /* Allocate the structure if it has not already been allocated by a | |
2954 | subclass. */ | |
2955 | if (entry == NULL) | |
2956 | { | |
2957 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
2958 | if (entry == NULL) | |
2959 | return entry; | |
2960 | } | |
2961 | ||
2962 | /* Call the allocation method of the superclass. */ | |
2963 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2964 | if (entry != NULL) | |
2965 | { | |
2966 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
2967 | ||
721956f4 | 2968 | eh->stub_cache = NULL; |
65f38f15 | 2969 | eh->dyn_relocs = NULL; |
721956f4 | 2970 | eh->oh = NULL; |
e86ce104 AM |
2971 | eh->is_func = 0; |
2972 | eh->is_func_descriptor = 0; | |
1e2f5b6e | 2973 | eh->is_entry = 0; |
e7b938ca | 2974 | eh->tls_mask = 0; |
65f38f15 AM |
2975 | } |
2976 | ||
2977 | return entry; | |
2978 | } | |
2979 | ||
2980 | /* Create a ppc64 ELF linker hash table. */ | |
2981 | ||
2982 | static struct bfd_link_hash_table * | |
4ce794b7 | 2983 | ppc64_elf_link_hash_table_create (bfd *abfd) |
65f38f15 AM |
2984 | { |
2985 | struct ppc_link_hash_table *htab; | |
2986 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
2987 | ||
4ce794b7 | 2988 | htab = bfd_zmalloc (amt); |
65f38f15 AM |
2989 | if (htab == NULL) |
2990 | return NULL; | |
2991 | ||
2992 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
2993 | { | |
e2d34d7d | 2994 | free (htab); |
65f38f15 AM |
2995 | return NULL; |
2996 | } | |
2997 | ||
721956f4 AM |
2998 | /* Init the stub hash table too. */ |
2999 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) | |
3000 | return NULL; | |
3001 | ||
3002 | /* And the branch hash table. */ | |
3003 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) | |
3004 | return NULL; | |
3005 | ||
3254fd24 AM |
3006 | /* Initializing two fields of the union is just cosmetic. We really |
3007 | only care about glist, but when compiled on a 32-bit host the | |
3008 | bfd_vma fields are larger. Setting the bfd_vma to zero makes | |
3009 | debugger inspection of these fields look nicer. */ | |
3010 | htab->elf.init_refcount.refcount = 0; | |
3011 | htab->elf.init_refcount.glist = NULL; | |
3012 | htab->elf.init_offset.offset = 0; | |
3013 | htab->elf.init_offset.glist = NULL; | |
3014 | ||
65f38f15 AM |
3015 | return &htab->elf.root; |
3016 | } | |
3017 | ||
721956f4 AM |
3018 | /* Free the derived linker hash table. */ |
3019 | ||
3020 | static void | |
4ce794b7 | 3021 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
721956f4 AM |
3022 | { |
3023 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
3024 | ||
3025 | bfd_hash_table_free (&ret->stub_hash_table); | |
3026 | bfd_hash_table_free (&ret->branch_hash_table); | |
3027 | _bfd_generic_link_hash_table_free (hash); | |
3028 | } | |
3029 | ||
e717da7e AM |
3030 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
3031 | ||
3032 | void | |
3033 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
3034 | { | |
3035 | struct ppc_link_hash_table *htab; | |
3036 | ||
3037 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; | |
3038 | ||
3039 | /* Always hook our dynamic sections into the first bfd, which is the | |
3040 | linker created stub bfd. This ensures that the GOT header is at | |
3041 | the start of the output TOC section. */ | |
3042 | htab = ppc_hash_table (info); | |
3043 | htab->stub_bfd = abfd; | |
3044 | htab->elf.dynobj = abfd; | |
3045 | } | |
3046 | ||
721956f4 AM |
3047 | /* Build a name for an entry in the stub hash table. */ |
3048 | ||
3049 | static char * | |
4ce794b7 AM |
3050 | ppc_stub_name (const asection *input_section, |
3051 | const asection *sym_sec, | |
3052 | const struct ppc_link_hash_entry *h, | |
3053 | const Elf_Internal_Rela *rel) | |
721956f4 AM |
3054 | { |
3055 | char *stub_name; | |
3056 | bfd_size_type len; | |
3057 | ||
3058 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
3059 | offsets from a sym as a branch target? In fact, we could | |
3060 | probably assume the addend is always zero. */ | |
3061 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
3062 | ||
3063 | if (h) | |
3064 | { | |
3065 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
3066 | stub_name = bfd_malloc (len); | |
3067 | if (stub_name != NULL) | |
3068 | { | |
97b639ba | 3069 | sprintf (stub_name, "%08x.%s+%x", |
721956f4 AM |
3070 | input_section->id & 0xffffffff, |
3071 | h->elf.root.root.string, | |
3072 | (int) rel->r_addend & 0xffffffff); | |
3073 | } | |
3074 | } | |
3075 | else | |
3076 | { | |
ad8e1ba5 | 3077 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
721956f4 AM |
3078 | stub_name = bfd_malloc (len); |
3079 | if (stub_name != NULL) | |
3080 | { | |
97b639ba | 3081 | sprintf (stub_name, "%08x.%x:%x+%x", |
721956f4 AM |
3082 | input_section->id & 0xffffffff, |
3083 | sym_sec->id & 0xffffffff, | |
3084 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
3085 | (int) rel->r_addend & 0xffffffff); | |
3086 | } | |
3087 | } | |
3088 | return stub_name; | |
3089 | } | |
3090 | ||
3091 | /* Look up an entry in the stub hash. Stub entries are cached because | |
3092 | creating the stub name takes a bit of time. */ | |
3093 | ||
3094 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3095 | ppc_get_stub_entry (const asection *input_section, |
3096 | const asection *sym_sec, | |
3097 | struct elf_link_hash_entry *hash, | |
3098 | const Elf_Internal_Rela *rel, | |
3099 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3100 | { |
3101 | struct ppc_stub_hash_entry *stub_entry; | |
3102 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; | |
3103 | const asection *id_sec; | |
3104 | ||
3105 | /* If this input section is part of a group of sections sharing one | |
3106 | stub section, then use the id of the first section in the group. | |
3107 | Stub names need to include a section id, as there may well be | |
3108 | more than one stub used to reach say, printf, and we need to | |
3109 | distinguish between them. */ | |
3110 | id_sec = htab->stub_group[input_section->id].link_sec; | |
3111 | ||
3112 | if (h != NULL && h->stub_cache != NULL | |
3113 | && h->stub_cache->h == h | |
3114 | && h->stub_cache->id_sec == id_sec) | |
3115 | { | |
3116 | stub_entry = h->stub_cache; | |
3117 | } | |
3118 | else | |
3119 | { | |
3120 | char *stub_name; | |
3121 | ||
3122 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
3123 | if (stub_name == NULL) | |
3124 | return NULL; | |
3125 | ||
3126 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 3127 | stub_name, FALSE, FALSE); |
721956f4 AM |
3128 | if (h != NULL) |
3129 | h->stub_cache = stub_entry; | |
3130 | ||
3131 | free (stub_name); | |
3132 | } | |
3133 | ||
3134 | return stub_entry; | |
3135 | } | |
3136 | ||
3137 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
3138 | stub entry are initialised. */ | |
3139 | ||
3140 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3141 | ppc_add_stub (const char *stub_name, |
3142 | asection *section, | |
3143 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3144 | { |
3145 | asection *link_sec; | |
3146 | asection *stub_sec; | |
3147 | struct ppc_stub_hash_entry *stub_entry; | |
3148 | ||
3149 | link_sec = htab->stub_group[section->id].link_sec; | |
3150 | stub_sec = htab->stub_group[section->id].stub_sec; | |
3151 | if (stub_sec == NULL) | |
3152 | { | |
3153 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
3154 | if (stub_sec == NULL) | |
3155 | { | |
d4c88bbb | 3156 | size_t namelen; |
721956f4 AM |
3157 | bfd_size_type len; |
3158 | char *s_name; | |
3159 | ||
d4c88bbb AM |
3160 | namelen = strlen (link_sec->name); |
3161 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
3162 | s_name = bfd_alloc (htab->stub_bfd, len); |
3163 | if (s_name == NULL) | |
3164 | return NULL; | |
3165 | ||
d4c88bbb AM |
3166 | memcpy (s_name, link_sec->name, namelen); |
3167 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
3168 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
3169 | if (stub_sec == NULL) | |
3170 | return NULL; | |
3171 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
3172 | } | |
3173 | htab->stub_group[section->id].stub_sec = stub_sec; | |
3174 | } | |
3175 | ||
3176 | /* Enter this entry into the linker stub hash table. */ | |
3177 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 3178 | TRUE, FALSE); |
721956f4 AM |
3179 | if (stub_entry == NULL) |
3180 | { | |
3181 | (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), | |
3182 | bfd_archive_filename (section->owner), | |
3183 | stub_name); | |
3184 | return NULL; | |
3185 | } | |
3186 | ||
3187 | stub_entry->stub_sec = stub_sec; | |
3188 | stub_entry->stub_offset = 0; | |
3189 | stub_entry->id_sec = link_sec; | |
3190 | return stub_entry; | |
3191 | } | |
3192 | ||
82bd7b59 AM |
3193 | /* Create sections for linker generated code. */ |
3194 | ||
b34976b6 | 3195 | static bfd_boolean |
4ce794b7 | 3196 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
82bd7b59 AM |
3197 | { |
3198 | struct ppc_link_hash_table *htab; | |
3199 | flagword flags; | |
3200 | ||
3201 | htab = ppc_hash_table (info); | |
3202 | ||
3203 | /* Create .sfpr for code to save and restore fp regs. */ | |
3204 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
3205 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
721956f4 | 3206 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
82bd7b59 AM |
3207 | if (htab->sfpr == NULL |
3208 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) | |
3209 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) | |
b34976b6 | 3210 | return FALSE; |
82bd7b59 | 3211 | |
721956f4 | 3212 | /* Create .glink for lazy dynamic linking support. */ |
4ce794b7 AM |
3213 | htab->glink = bfd_make_section_anyway (dynobj, ".glink"); |
3214 | if (htab->glink == NULL | |
3215 | || ! bfd_set_section_flags (dynobj, htab->glink, flags) | |
3216 | || ! bfd_set_section_alignment (dynobj, htab->glink, 2)) | |
b34976b6 | 3217 | return FALSE; |
82bd7b59 | 3218 | |
721956f4 AM |
3219 | /* Create .branch_lt for plt_branch stubs. */ |
3220 | flags = (SEC_ALLOC | SEC_LOAD | |
3221 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3222 | htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt"); |
3223 | if (htab->brlt == NULL | |
3224 | || ! bfd_set_section_flags (dynobj, htab->brlt, flags) | |
3225 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) | |
b34976b6 | 3226 | return FALSE; |
721956f4 AM |
3227 | |
3228 | if (info->shared) | |
3229 | { | |
3230 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
3231 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3232 | htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
3233 | if (!htab->relbrlt | |
3234 | || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags) | |
3235 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) | |
b34976b6 | 3236 | return FALSE; |
721956f4 | 3237 | } |
b34976b6 | 3238 | return TRUE; |
82bd7b59 AM |
3239 | } |
3240 | ||
e717da7e AM |
3241 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
3242 | not already done. */ | |
65f38f15 | 3243 | |
b34976b6 | 3244 | static bfd_boolean |
e717da7e | 3245 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
65f38f15 | 3246 | { |
e717da7e AM |
3247 | asection *got, *relgot; |
3248 | flagword flags; | |
3249 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
65f38f15 | 3250 | |
4ce794b7 | 3251 | if (!htab->got) |
e717da7e AM |
3252 | { |
3253 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) | |
3254 | return FALSE; | |
3255 | ||
3256 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); | |
3257 | if (!htab->got) | |
3258 | abort (); | |
3259 | } | |
3260 | ||
3261 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3262 | | SEC_LINKER_CREATED); | |
3263 | ||
3264 | got = bfd_make_section (abfd, ".got"); | |
3265 | if (!got | |
3266 | || !bfd_set_section_flags (abfd, got, flags) | |
3267 | || !bfd_set_section_alignment (abfd, got, 3)) | |
3268 | return FALSE; | |
65f38f15 | 3269 | |
e717da7e AM |
3270 | relgot = bfd_make_section (abfd, ".rela.got"); |
3271 | if (!relgot | |
3272 | || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY) | |
3273 | || ! bfd_set_section_alignment (abfd, relgot, 3)) | |
b34976b6 | 3274 | return FALSE; |
e717da7e AM |
3275 | |
3276 | ppc64_elf_tdata (abfd)->got = got; | |
3277 | ppc64_elf_tdata (abfd)->relgot = relgot; | |
b34976b6 | 3278 | return TRUE; |
65f38f15 | 3279 | } |
5bd4f169 | 3280 | |
82bd7b59 | 3281 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 3282 | |
b34976b6 | 3283 | static bfd_boolean |
4ce794b7 | 3284 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5bd4f169 | 3285 | { |
65f38f15 | 3286 | struct ppc_link_hash_table *htab; |
5bd4f169 | 3287 | |
65f38f15 | 3288 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 3289 | return FALSE; |
65f38f15 | 3290 | |
e717da7e AM |
3291 | htab = ppc_hash_table (info); |
3292 | if (!htab->got) | |
3293 | htab->got = bfd_get_section_by_name (dynobj, ".got"); | |
4ce794b7 AM |
3294 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
3295 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3296 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
65f38f15 | 3297 | if (!info->shared) |
4ce794b7 | 3298 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
65f38f15 | 3299 | |
e717da7e | 3300 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
4ce794b7 | 3301 | || (!info->shared && !htab->relbss)) |
65f38f15 AM |
3302 | abort (); |
3303 | ||
b34976b6 | 3304 | return TRUE; |
5bd4f169 AM |
3305 | } |
3306 | ||
65f38f15 AM |
3307 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
3308 | ||
3309 | static void | |
9c5bfbb7 AM |
3310 | ppc64_elf_copy_indirect_symbol |
3311 | (const struct elf_backend_data *bed ATTRIBUTE_UNUSED, | |
3312 | struct elf_link_hash_entry *dir, | |
3313 | struct elf_link_hash_entry *ind) | |
65f38f15 AM |
3314 | { |
3315 | struct ppc_link_hash_entry *edir, *eind; | |
81848ca0 | 3316 | flagword mask; |
65f38f15 AM |
3317 | |
3318 | edir = (struct ppc_link_hash_entry *) dir; | |
3319 | eind = (struct ppc_link_hash_entry *) ind; | |
3320 | ||
411e1bfb | 3321 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
bbd7ec4a | 3322 | if (eind->dyn_relocs != NULL) |
65f38f15 | 3323 | { |
bbd7ec4a AM |
3324 | if (edir->dyn_relocs != NULL) |
3325 | { | |
3326 | struct ppc_dyn_relocs **pp; | |
3327 | struct ppc_dyn_relocs *p; | |
3328 | ||
411e1bfb | 3329 | if (eind->elf.root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
3330 | abort (); |
3331 | ||
3332 | /* Add reloc counts against the weak sym to the strong sym | |
3333 | list. Merge any entries against the same section. */ | |
3334 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3335 | { | |
3336 | struct ppc_dyn_relocs *q; | |
3337 | ||
3338 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3339 | if (q->sec == p->sec) | |
3340 | { | |
3341 | q->pc_count += p->pc_count; | |
3342 | q->count += p->count; | |
3343 | *pp = p->next; | |
3344 | break; | |
3345 | } | |
3346 | if (q == NULL) | |
3347 | pp = &p->next; | |
3348 | } | |
3349 | *pp = edir->dyn_relocs; | |
3350 | } | |
3351 | ||
65f38f15 AM |
3352 | edir->dyn_relocs = eind->dyn_relocs; |
3353 | eind->dyn_relocs = NULL; | |
3354 | } | |
65f38f15 | 3355 | |
6349e628 AM |
3356 | edir->is_func |= eind->is_func; |
3357 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
3358 | edir->is_entry |= eind->is_entry; | |
58ac9f71 | 3359 | edir->tls_mask |= eind->tls_mask; |
6349e628 | 3360 | |
81848ca0 | 3361 | mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR |
3addb0a9 DJ |
3362 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF |
3363 | | ELF_LINK_HASH_NEEDS_PLT); | |
81848ca0 AM |
3364 | /* If called to transfer flags for a weakdef during processing |
3365 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. | |
3366 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3367 | if (ELIMINATE_COPY_RELOCS | |
3368 | && eind->elf.root.type != bfd_link_hash_indirect | |
3369 | && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) | |
3370 | mask &= ~ELF_LINK_NON_GOT_REF; | |
3371 | ||
3372 | edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask; | |
6349e628 AM |
3373 | |
3374 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3375 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3376 | return; | |
3377 | ||
81848ca0 AM |
3378 | /* Copy over got entries that we may have already seen to the |
3379 | symbol which just became indirect. */ | |
411e1bfb AM |
3380 | if (eind->elf.got.glist != NULL) |
3381 | { | |
3382 | if (edir->elf.got.glist != NULL) | |
3383 | { | |
3384 | struct got_entry **entp; | |
3385 | struct got_entry *ent; | |
3386 | ||
3387 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) | |
3388 | { | |
3389 | struct got_entry *dent; | |
3390 | ||
3391 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) | |
3392 | if (dent->addend == ent->addend | |
e717da7e | 3393 | && dent->owner == ent->owner |
411e1bfb AM |
3394 | && dent->tls_type == ent->tls_type) |
3395 | { | |
3396 | dent->got.refcount += ent->got.refcount; | |
3397 | *entp = ent->next; | |
3398 | break; | |
3399 | } | |
3400 | if (dent == NULL) | |
3401 | entp = &ent->next; | |
3402 | } | |
3403 | *entp = edir->elf.got.glist; | |
3404 | } | |
3405 | ||
3406 | edir->elf.got.glist = eind->elf.got.glist; | |
3407 | eind->elf.got.glist = NULL; | |
3408 | } | |
3409 | ||
3410 | /* And plt entries. */ | |
3411 | if (eind->elf.plt.plist != NULL) | |
3412 | { | |
3413 | if (edir->elf.plt.plist != NULL) | |
3414 | { | |
3415 | struct plt_entry **entp; | |
3416 | struct plt_entry *ent; | |
3417 | ||
3418 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3419 | { | |
3420 | struct plt_entry *dent; | |
3421 | ||
3422 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3423 | if (dent->addend == ent->addend) | |
3424 | { | |
3425 | dent->plt.refcount += ent->plt.refcount; | |
3426 | *entp = ent->next; | |
3427 | break; | |
3428 | } | |
3429 | if (dent == NULL) | |
3430 | entp = &ent->next; | |
3431 | } | |
3432 | *entp = edir->elf.plt.plist; | |
3433 | } | |
3434 | ||
3435 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3436 | eind->elf.plt.plist = NULL; | |
3437 | } | |
3438 | ||
411e1bfb AM |
3439 | if (edir->elf.dynindx == -1) |
3440 | { | |
3441 | edir->elf.dynindx = eind->elf.dynindx; | |
3442 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3443 | eind->elf.dynindx = -1; | |
3444 | eind->elf.dynstr_index = 0; | |
3445 | } | |
3446 | else | |
3447 | BFD_ASSERT (eind->elf.dynindx == -1); | |
3448 | } | |
3449 | ||
3450 | /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and | |
3451 | symbols undefined on the command-line. */ | |
3452 | ||
3453 | bfd_boolean | |
4ce794b7 | 3454 | ppc64_elf_mark_entry_syms (struct bfd_link_info *info) |
411e1bfb AM |
3455 | { |
3456 | struct ppc_link_hash_table *htab; | |
3457 | struct bfd_sym_chain *sym; | |
3458 | ||
3459 | htab = ppc_hash_table (info); | |
3460 | for (sym = info->gc_sym_list; sym; sym = sym->next) | |
3461 | { | |
3462 | struct elf_link_hash_entry *h; | |
3463 | ||
3464 | h = elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); | |
3465 | if (h != NULL) | |
3466 | ((struct ppc_link_hash_entry *) h)->is_entry = 1; | |
3467 | } | |
3468 | return TRUE; | |
3469 | } | |
3470 | ||
3471 | static bfd_boolean | |
4ce794b7 AM |
3472 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
3473 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) | |
411e1bfb AM |
3474 | { |
3475 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); | |
e7b938ca | 3476 | char *local_got_tls_masks; |
411e1bfb AM |
3477 | |
3478 | if (local_got_ents == NULL) | |
3479 | { | |
3480 | bfd_size_type size = symtab_hdr->sh_info; | |
3481 | ||
e7b938ca | 3482 | size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks); |
4ce794b7 | 3483 | local_got_ents = bfd_zalloc (abfd, size); |
411e1bfb AM |
3484 | if (local_got_ents == NULL) |
3485 | return FALSE; | |
3486 | elf_local_got_ents (abfd) = local_got_ents; | |
3487 | } | |
3488 | ||
3489 | if ((tls_type & TLS_EXPLICIT) == 0) | |
3490 | { | |
3491 | struct got_entry *ent; | |
3492 | ||
3493 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) | |
e717da7e AM |
3494 | if (ent->addend == r_addend |
3495 | && ent->owner == abfd | |
3496 | && ent->tls_type == tls_type) | |
411e1bfb AM |
3497 | break; |
3498 | if (ent == NULL) | |
3499 | { | |
3500 | bfd_size_type amt = sizeof (*ent); | |
4ce794b7 | 3501 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3502 | if (ent == NULL) |
3503 | return FALSE; | |
3504 | ent->next = local_got_ents[r_symndx]; | |
3505 | ent->addend = r_addend; | |
e717da7e | 3506 | ent->owner = abfd; |
411e1bfb AM |
3507 | ent->tls_type = tls_type; |
3508 | ent->got.refcount = 0; | |
3509 | local_got_ents[r_symndx] = ent; | |
3510 | } | |
3511 | ent->got.refcount += 1; | |
3512 | } | |
3513 | ||
e7b938ca AM |
3514 | local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
3515 | local_got_tls_masks[r_symndx] |= tls_type; | |
411e1bfb | 3516 | return TRUE; |
65f38f15 AM |
3517 | } |
3518 | ||
411e1bfb | 3519 | static bfd_boolean |
4ce794b7 | 3520 | update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend) |
1e2f5b6e | 3521 | { |
411e1bfb | 3522 | struct plt_entry *ent; |
1e2f5b6e | 3523 | |
411e1bfb AM |
3524 | for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next) |
3525 | if (ent->addend == addend) | |
3526 | break; | |
3527 | if (ent == NULL) | |
1e2f5b6e | 3528 | { |
411e1bfb | 3529 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3530 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3531 | if (ent == NULL) |
3532 | return FALSE; | |
3533 | ent->next = eh->elf.plt.plist; | |
3534 | ent->addend = addend; | |
3535 | ent->plt.refcount = 0; | |
3536 | eh->elf.plt.plist = ent; | |
1e2f5b6e | 3537 | } |
411e1bfb AM |
3538 | ent->plt.refcount += 1; |
3539 | eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3540 | eh->is_func = 1; | |
b34976b6 | 3541 | return TRUE; |
1e2f5b6e AM |
3542 | } |
3543 | ||
50bc7936 AM |
3544 | /* Find the function descriptor hash entry from the given function code |
3545 | hash entry FH. Link the entries via their OH fields. */ | |
3546 | static struct ppc_link_hash_entry * | |
3547 | get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) | |
3548 | { | |
3549 | struct ppc_link_hash_entry *fdh = (struct ppc_link_hash_entry *) fh->oh; | |
3550 | ||
3551 | if (fdh == NULL) | |
3552 | { | |
3553 | const char *fd_name = fh->elf.root.root.string + 1; | |
3554 | ||
3555 | fdh = (struct ppc_link_hash_entry *) | |
3556 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); | |
3557 | if (fdh != NULL) | |
3558 | { | |
3559 | fdh->is_func_descriptor = 1; | |
3560 | fdh->oh = &fh->elf; | |
3561 | fh->is_func = 1; | |
3562 | fh->oh = &fdh->elf; | |
3563 | } | |
3564 | } | |
3565 | ||
3566 | return fdh; | |
3567 | } | |
3568 | ||
5bd4f169 | 3569 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 3570 | calculate needed space in the global offset table, procedure |
5d1634d7 | 3571 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 3572 | |
b34976b6 | 3573 | static bfd_boolean |
4ce794b7 AM |
3574 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
3575 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 3576 | { |
65f38f15 | 3577 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3578 | Elf_Internal_Shdr *symtab_hdr; |
3579 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
3580 | const Elf_Internal_Rela *rel; | |
3581 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 3582 | asection *sreloc; |
1e2f5b6e | 3583 | asection **opd_sym_map; |
5bd4f169 | 3584 | |
1049f94e | 3585 | if (info->relocatable) |
b34976b6 | 3586 | return TRUE; |
5bd4f169 | 3587 | |
65f38f15 | 3588 | htab = ppc_hash_table (info); |
5bd4f169 | 3589 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
3590 | |
3591 | sym_hashes = elf_sym_hashes (abfd); | |
3592 | sym_hashes_end = (sym_hashes | |
1e2f5b6e AM |
3593 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
3594 | - symtab_hdr->sh_info); | |
5bd4f169 AM |
3595 | |
3596 | sreloc = NULL; | |
1e2f5b6e AM |
3597 | opd_sym_map = NULL; |
3598 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
3599 | { | |
3600 | /* Garbage collection needs some extra help with .opd sections. | |
3601 | We don't want to necessarily keep everything referenced by | |
3602 | relocs in .opd, as that would keep all functions. Instead, | |
3603 | if we reference an .opd symbol (a function descriptor), we | |
3604 | want to keep the function code symbol's section. This is | |
3605 | easy for global symbols, but for local syms we need to keep | |
3606 | information about the associated function section. Later, if | |
3607 | edit_opd deletes entries, we'll use this array to adjust | |
3608 | local syms in .opd. */ | |
3609 | union opd_info { | |
3610 | asection *func_section; | |
3611 | long entry_adjust; | |
3612 | }; | |
3613 | bfd_size_type amt; | |
3614 | ||
3615 | amt = sec->_raw_size * sizeof (union opd_info) / 24; | |
4ce794b7 | 3616 | opd_sym_map = bfd_zalloc (abfd, amt); |
1e2f5b6e | 3617 | if (opd_sym_map == NULL) |
b34976b6 | 3618 | return FALSE; |
f0abc2a1 | 3619 | ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map; |
1e2f5b6e | 3620 | } |
5bd4f169 | 3621 | |
82bd7b59 AM |
3622 | if (htab->sfpr == NULL |
3623 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 3624 | return FALSE; |
82bd7b59 | 3625 | |
5bd4f169 AM |
3626 | rel_end = relocs + sec->reloc_count; |
3627 | for (rel = relocs; rel < rel_end; rel++) | |
3628 | { | |
3629 | unsigned long r_symndx; | |
3630 | struct elf_link_hash_entry *h; | |
04c9666a | 3631 | enum elf_ppc64_reloc_type r_type; |
411e1bfb | 3632 | int tls_type = 0; |
5bd4f169 AM |
3633 | |
3634 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3635 | if (r_symndx < symtab_hdr->sh_info) | |
3636 | h = NULL; | |
3637 | else | |
3638 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3639 | ||
4ce794b7 | 3640 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 3641 | switch (r_type) |
5bd4f169 | 3642 | { |
411e1bfb AM |
3643 | case R_PPC64_GOT_TLSLD16: |
3644 | case R_PPC64_GOT_TLSLD16_LO: | |
3645 | case R_PPC64_GOT_TLSLD16_HI: | |
3646 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 3647 | ppc64_tlsld_got (abfd)->refcount += 1; |
951fd09b | 3648 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
3649 | goto dogottls; |
3650 | ||
3651 | case R_PPC64_GOT_TLSGD16: | |
3652 | case R_PPC64_GOT_TLSGD16_LO: | |
3653 | case R_PPC64_GOT_TLSGD16_HI: | |
3654 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 3655 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
3656 | goto dogottls; |
3657 | ||
3658 | case R_PPC64_GOT_TPREL16_DS: | |
3659 | case R_PPC64_GOT_TPREL16_LO_DS: | |
3660 | case R_PPC64_GOT_TPREL16_HI: | |
3661 | case R_PPC64_GOT_TPREL16_HA: | |
3662 | if (info->shared) | |
3663 | info->flags |= DF_STATIC_TLS; | |
3664 | tls_type = TLS_TLS | TLS_TPREL; | |
3665 | goto dogottls; | |
3666 | ||
3667 | case R_PPC64_GOT_DTPREL16_DS: | |
3668 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
3669 | case R_PPC64_GOT_DTPREL16_HI: | |
3670 | case R_PPC64_GOT_DTPREL16_HA: | |
3671 | tls_type = TLS_TLS | TLS_DTPREL; | |
3672 | dogottls: | |
3673 | sec->has_tls_reloc = 1; | |
3674 | /* Fall thru */ | |
3675 | ||
5bd4f169 | 3676 | case R_PPC64_GOT16: |
5bd4f169 | 3677 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
3678 | case R_PPC64_GOT16_HA: |
3679 | case R_PPC64_GOT16_HI: | |
3680 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 3681 | case R_PPC64_GOT16_LO_DS: |
65f38f15 | 3682 | /* This symbol requires a global offset table entry. */ |
ad8e1ba5 | 3683 | sec->has_gp_reloc = 1; |
e717da7e AM |
3684 | if (ppc64_elf_tdata (abfd)->got == NULL |
3685 | && !create_got_section (abfd, info)) | |
b34976b6 | 3686 | return FALSE; |
5bd4f169 AM |
3687 | |
3688 | if (h != NULL) | |
3689 | { | |
411e1bfb AM |
3690 | struct ppc_link_hash_entry *eh; |
3691 | struct got_entry *ent; | |
65f38f15 | 3692 | |
411e1bfb AM |
3693 | eh = (struct ppc_link_hash_entry *) h; |
3694 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) | |
3695 | if (ent->addend == rel->r_addend | |
e717da7e | 3696 | && ent->owner == abfd |
411e1bfb AM |
3697 | && ent->tls_type == tls_type) |
3698 | break; | |
3699 | if (ent == NULL) | |
5bd4f169 | 3700 | { |
411e1bfb | 3701 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3702 | ent = bfd_alloc (abfd, amt); |
411e1bfb | 3703 | if (ent == NULL) |
b34976b6 | 3704 | return FALSE; |
411e1bfb AM |
3705 | ent->next = eh->elf.got.glist; |
3706 | ent->addend = rel->r_addend; | |
e717da7e | 3707 | ent->owner = abfd; |
411e1bfb AM |
3708 | ent->tls_type = tls_type; |
3709 | ent->got.refcount = 0; | |
3710 | eh->elf.got.glist = ent; | |
5bd4f169 | 3711 | } |
411e1bfb | 3712 | ent->got.refcount += 1; |
e7b938ca | 3713 | eh->tls_mask |= tls_type; |
5bd4f169 | 3714 | } |
411e1bfb AM |
3715 | else |
3716 | /* This is a global offset table entry for a local symbol. */ | |
3717 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3718 | rel->r_addend, tls_type)) | |
3719 | return FALSE; | |
5bd4f169 AM |
3720 | break; |
3721 | ||
5bd4f169 | 3722 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
3723 | case R_PPC64_PLT16_HI: |
3724 | case R_PPC64_PLT16_LO: | |
3725 | case R_PPC64_PLT32: | |
3726 | case R_PPC64_PLT64: | |
5bd4f169 | 3727 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
3728 | actually build the entry in adjust_dynamic_symbol, |
3729 | because this might be a case of linking PIC code without | |
3730 | linking in any dynamic objects, in which case we don't | |
3731 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
3732 | if (h == NULL) |
3733 | { | |
3734 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 3735 | table entry for a local symbol. */ |
5bd4f169 | 3736 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3737 | return FALSE; |
5bd4f169 | 3738 | } |
411e1bfb AM |
3739 | else |
3740 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, | |
3741 | rel->r_addend)) | |
3742 | return FALSE; | |
5bd4f169 AM |
3743 | break; |
3744 | ||
3745 | /* The following relocations don't need to propagate the | |
3746 | relocation if linking a shared object since they are | |
3747 | section relative. */ | |
3748 | case R_PPC64_SECTOFF: | |
3749 | case R_PPC64_SECTOFF_LO: | |
3750 | case R_PPC64_SECTOFF_HI: | |
3751 | case R_PPC64_SECTOFF_HA: | |
3752 | case R_PPC64_SECTOFF_DS: | |
3753 | case R_PPC64_SECTOFF_LO_DS: | |
411e1bfb AM |
3754 | case R_PPC64_DTPREL16: |
3755 | case R_PPC64_DTPREL16_LO: | |
3756 | case R_PPC64_DTPREL16_HI: | |
3757 | case R_PPC64_DTPREL16_HA: | |
3758 | case R_PPC64_DTPREL16_DS: | |
3759 | case R_PPC64_DTPREL16_LO_DS: | |
3760 | case R_PPC64_DTPREL16_HIGHER: | |
3761 | case R_PPC64_DTPREL16_HIGHERA: | |
3762 | case R_PPC64_DTPREL16_HIGHEST: | |
3763 | case R_PPC64_DTPREL16_HIGHESTA: | |
5bd4f169 AM |
3764 | break; |
3765 | ||
ad8e1ba5 AM |
3766 | /* Nor do these. */ |
3767 | case R_PPC64_TOC16: | |
3768 | case R_PPC64_TOC16_LO: | |
3769 | case R_PPC64_TOC16_HI: | |
3770 | case R_PPC64_TOC16_HA: | |
3771 | case R_PPC64_TOC16_DS: | |
3772 | case R_PPC64_TOC16_LO_DS: | |
3773 | sec->has_gp_reloc = 1; | |
3774 | break; | |
3775 | ||
5bd4f169 AM |
3776 | /* This relocation describes the C++ object vtable hierarchy. |
3777 | Reconstruct it for later use during GC. */ | |
3778 | case R_PPC64_GNU_VTINHERIT: | |
3779 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
b34976b6 | 3780 | return FALSE; |
5bd4f169 AM |
3781 | break; |
3782 | ||
3783 | /* This relocation describes which C++ vtable entries are actually | |
3784 | used. Record for later use during GC. */ | |
3785 | case R_PPC64_GNU_VTENTRY: | |
3786 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 3787 | return FALSE; |
5bd4f169 AM |
3788 | break; |
3789 | ||
721956f4 AM |
3790 | case R_PPC64_REL14: |
3791 | case R_PPC64_REL14_BRTAKEN: | |
3792 | case R_PPC64_REL14_BRNTAKEN: | |
3793 | htab->has_14bit_branch = 1; | |
3794 | /* Fall through. */ | |
3795 | ||
5d1634d7 | 3796 | case R_PPC64_REL24: |
e86ce104 AM |
3797 | if (h != NULL |
3798 | && h->root.root.string[0] == '.' | |
3799 | && h->root.root.string[1] != 0) | |
5d1634d7 AM |
3800 | { |
3801 | /* We may need a .plt entry if the function this reloc | |
3802 | refers to is in a shared lib. */ | |
411e1bfb AM |
3803 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
3804 | rel->r_addend)) | |
3805 | return FALSE; | |
3806 | if (h == htab->tls_get_addr) | |
3807 | sec->has_tls_reloc = 1; | |
a48ebf4d AM |
3808 | else if ((strncmp (h->root.root.string, ".__tls_get_addr", 15) |
3809 | == 0) | |
3810 | && (h->root.root.string[15] == 0 | |
3811 | || h->root.root.string[15] == '@')) | |
411e1bfb AM |
3812 | { |
3813 | htab->tls_get_addr = h; | |
3814 | sec->has_tls_reloc = 1; | |
3815 | } | |
3816 | } | |
3817 | break; | |
3818 | ||
3819 | case R_PPC64_TPREL64: | |
3820 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | |
3821 | if (info->shared) | |
3822 | info->flags |= DF_STATIC_TLS; | |
3823 | goto dotlstoc; | |
3824 | ||
3825 | case R_PPC64_DTPMOD64: | |
3826 | if (rel + 1 < rel_end | |
3827 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
3828 | && rel[1].r_offset == rel->r_offset + 8) | |
951fd09b | 3829 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
411e1bfb | 3830 | else |
951fd09b | 3831 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
411e1bfb AM |
3832 | goto dotlstoc; |
3833 | ||
3834 | case R_PPC64_DTPREL64: | |
3835 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; | |
3836 | if (rel != relocs | |
3837 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) | |
3838 | && rel[-1].r_offset == rel->r_offset - 8) | |
3839 | /* This is the second reloc of a dtpmod, dtprel pair. | |
3840 | Don't mark with TLS_DTPREL. */ | |
3841 | goto dodyn; | |
3842 | ||
3843 | dotlstoc: | |
3844 | sec->has_tls_reloc = 1; | |
3845 | if (h != NULL) | |
3846 | { | |
3847 | struct ppc_link_hash_entry *eh; | |
3848 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 3849 | eh->tls_mask |= tls_type; |
411e1bfb AM |
3850 | } |
3851 | else | |
3852 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3853 | rel->r_addend, tls_type)) | |
3854 | return FALSE; | |
3855 | ||
3856 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) | |
3857 | { | |
e7b938ca | 3858 | /* One extra to simplify get_tls_mask. */ |
951fd09b | 3859 | bfd_size_type amt = sec->_raw_size * sizeof (unsigned) / 8 + 1; |
4ce794b7 | 3860 | ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt); |
411e1bfb AM |
3861 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
3862 | return FALSE; | |
3863 | } | |
3864 | BFD_ASSERT (rel->r_offset % 8 == 0); | |
3865 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx; | |
951fd09b AM |
3866 | |
3867 | /* Mark the second slot of a GD or LD entry. | |
3868 | -1 to indicate GD and -2 to indicate LD. */ | |
3869 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | |
3870 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1; | |
3871 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) | |
3872 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2; | |
411e1bfb AM |
3873 | goto dodyn; |
3874 | ||
3875 | case R_PPC64_TPREL16: | |
3876 | case R_PPC64_TPREL16_LO: | |
3877 | case R_PPC64_TPREL16_HI: | |
3878 | case R_PPC64_TPREL16_HA: | |
3879 | case R_PPC64_TPREL16_DS: | |
3880 | case R_PPC64_TPREL16_LO_DS: | |
3881 | case R_PPC64_TPREL16_HIGHER: | |
3882 | case R_PPC64_TPREL16_HIGHERA: | |
3883 | case R_PPC64_TPREL16_HIGHEST: | |
3884 | case R_PPC64_TPREL16_HIGHESTA: | |
3885 | if (info->shared) | |
3886 | { | |
3887 | info->flags |= DF_STATIC_TLS; | |
3888 | goto dodyn; | |
5d1634d7 AM |
3889 | } |
3890 | break; | |
3891 | ||
e86ce104 | 3892 | case R_PPC64_ADDR64: |
1e2f5b6e | 3893 | if (opd_sym_map != NULL |
e86ce104 AM |
3894 | && h != NULL |
3895 | && h->root.root.string[0] == '.' | |
3896 | && h->root.root.string[1] != 0) | |
50bc7936 | 3897 | get_fdh ((struct ppc_link_hash_entry *) h, htab); |
e86ce104 | 3898 | |
1e2f5b6e AM |
3899 | if (opd_sym_map != NULL |
3900 | && h == NULL | |
3901 | && rel + 1 < rel_end | |
4ce794b7 | 3902 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
1e2f5b6e AM |
3903 | { |
3904 | asection *s; | |
3905 | ||
3906 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, | |
3907 | r_symndx); | |
3908 | if (s == NULL) | |
b34976b6 | 3909 | return FALSE; |
1e2f5b6e AM |
3910 | else if (s != sec) |
3911 | opd_sym_map[rel->r_offset / 24] = s; | |
3912 | } | |
e86ce104 AM |
3913 | /* Fall through. */ |
3914 | ||
04c9666a | 3915 | case R_PPC64_REL30: |
5bd4f169 | 3916 | case R_PPC64_REL32: |
04c9666a | 3917 | case R_PPC64_REL64: |
65f38f15 AM |
3918 | case R_PPC64_ADDR14: |
3919 | case R_PPC64_ADDR14_BRNTAKEN: | |
3920 | case R_PPC64_ADDR14_BRTAKEN: | |
3921 | case R_PPC64_ADDR16: | |
3922 | case R_PPC64_ADDR16_DS: | |
3923 | case R_PPC64_ADDR16_HA: | |
3924 | case R_PPC64_ADDR16_HI: | |
3925 | case R_PPC64_ADDR16_HIGHER: | |
3926 | case R_PPC64_ADDR16_HIGHERA: | |
3927 | case R_PPC64_ADDR16_HIGHEST: | |
3928 | case R_PPC64_ADDR16_HIGHESTA: | |
3929 | case R_PPC64_ADDR16_LO: | |
3930 | case R_PPC64_ADDR16_LO_DS: | |
3931 | case R_PPC64_ADDR24: | |
65f38f15 | 3932 | case R_PPC64_ADDR32: |
65f38f15 AM |
3933 | case R_PPC64_UADDR16: |
3934 | case R_PPC64_UADDR32: | |
3935 | case R_PPC64_UADDR64: | |
5bd4f169 | 3936 | case R_PPC64_TOC: |
81848ca0 AM |
3937 | if (h != NULL && !info->shared) |
3938 | /* We may need a copy reloc. */ | |
3939 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
3940 | ||
41bd81ab | 3941 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 3942 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 3943 | break; |
e86ce104 | 3944 | |
f4656909 AM |
3945 | /* Don't propagate relocs that the dynamic linker won't relocate. */ |
3946 | if ((sec->flags & SEC_ALLOC) == 0) | |
3947 | break; | |
3948 | ||
65f38f15 AM |
3949 | /* If we are creating a shared library, and this is a reloc |
3950 | against a global symbol, or a non PC relative reloc | |
3951 | against a local symbol, then we need to copy the reloc | |
3952 | into the shared library. However, if we are linking with | |
3953 | -Bsymbolic, we do not need to copy a reloc against a | |
3954 | global symbol which is defined in an object we are | |
3955 | including in the link (i.e., DEF_REGULAR is set). At | |
3956 | this point we have not seen all the input files, so it is | |
3957 | possible that DEF_REGULAR is not set now but will be set | |
3958 | later (it is never cleared). In case of a weak definition, | |
3959 | DEF_REGULAR may be cleared later by a strong definition in | |
3960 | a shared library. We account for that possibility below by | |
f4656909 | 3961 | storing information in the dyn_relocs field of the hash |
65f38f15 AM |
3962 | table entry. A similar situation occurs when creating |
3963 | shared libraries and symbol visibility changes render the | |
3964 | symbol local. | |
3965 | ||
3966 | If on the other hand, we are creating an executable, we | |
3967 | may need to keep relocations for symbols satisfied by a | |
3968 | dynamic library if we manage to avoid copy relocs for the | |
3969 | symbol. */ | |
411e1bfb | 3970 | dodyn: |
65f38f15 | 3971 | if ((info->shared |
411e1bfb | 3972 | && (MUST_BE_DYN_RELOC (r_type) |
65f38f15 AM |
3973 | || (h != NULL |
3974 | && (! info->symbolic | |
3975 | || h->root.type == bfd_link_hash_defweak | |
3976 | || (h->elf_link_hash_flags | |
3977 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
f4656909 AM |
3978 | || (ELIMINATE_COPY_RELOCS |
3979 | && !info->shared | |
65f38f15 AM |
3980 | && h != NULL |
3981 | && (h->root.type == bfd_link_hash_defweak | |
3982 | || (h->elf_link_hash_flags | |
3983 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 3984 | { |
ec338859 AM |
3985 | struct ppc_dyn_relocs *p; |
3986 | struct ppc_dyn_relocs **head; | |
3987 | ||
65f38f15 AM |
3988 | /* We must copy these reloc types into the output file. |
3989 | Create a reloc section in dynobj and make room for | |
3990 | this reloc. */ | |
5bd4f169 AM |
3991 | if (sreloc == NULL) |
3992 | { | |
3993 | const char *name; | |
65f38f15 | 3994 | bfd *dynobj; |
5bd4f169 AM |
3995 | |
3996 | name = (bfd_elf_string_from_elf_section | |
3997 | (abfd, | |
3998 | elf_elfheader (abfd)->e_shstrndx, | |
3999 | elf_section_data (sec)->rel_hdr.sh_name)); | |
4000 | if (name == NULL) | |
b34976b6 | 4001 | return FALSE; |
5bd4f169 | 4002 | |
65f38f15 AM |
4003 | if (strncmp (name, ".rela", 5) != 0 |
4004 | || strcmp (bfd_get_section_name (abfd, sec), | |
4005 | name + 5) != 0) | |
4006 | { | |
4007 | (*_bfd_error_handler) | |
4008 | (_("%s: bad relocation section name `%s\'"), | |
4009 | bfd_archive_filename (abfd), name); | |
5d1634d7 | 4010 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
4011 | } |
4012 | ||
65f38f15 | 4013 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
4014 | sreloc = bfd_get_section_by_name (dynobj, name); |
4015 | if (sreloc == NULL) | |
4016 | { | |
4017 | flagword flags; | |
4018 | ||
4019 | sreloc = bfd_make_section (dynobj, name); | |
4020 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
4021 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4022 | if ((sec->flags & SEC_ALLOC) != 0) | |
4023 | flags |= SEC_ALLOC | SEC_LOAD; | |
4024 | if (sreloc == NULL | |
4025 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 4026 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
b34976b6 | 4027 | return FALSE; |
5bd4f169 | 4028 | } |
65f38f15 | 4029 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
4030 | } |
4031 | ||
65f38f15 AM |
4032 | /* If this is a global symbol, we count the number of |
4033 | relocations we need for this symbol. */ | |
4034 | if (h != NULL) | |
4035 | { | |
ec338859 | 4036 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
4037 | } |
4038 | else | |
4039 | { | |
ec338859 AM |
4040 | /* Track dynamic relocs needed for local syms too. |
4041 | We really need local syms available to do this | |
4042 | easily. Oh well. */ | |
4043 | ||
4044 | asection *s; | |
4045 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
4046 | sec, r_symndx); | |
4047 | if (s == NULL) | |
b34976b6 | 4048 | return FALSE; |
ec338859 AM |
4049 | |
4050 | head = ((struct ppc_dyn_relocs **) | |
4051 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 4052 | } |
ec338859 AM |
4053 | |
4054 | p = *head; | |
4055 | if (p == NULL || p->sec != sec) | |
4056 | { | |
4ce794b7 | 4057 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
ec338859 | 4058 | if (p == NULL) |
b34976b6 | 4059 | return FALSE; |
ec338859 AM |
4060 | p->next = *head; |
4061 | *head = p; | |
4062 | p->sec = sec; | |
4063 | p->count = 0; | |
4064 | p->pc_count = 0; | |
4065 | } | |
4066 | ||
4067 | p->count += 1; | |
411e1bfb | 4068 | if (!MUST_BE_DYN_RELOC (r_type)) |
ec338859 | 4069 | p->pc_count += 1; |
65f38f15 | 4070 | } |
5bd4f169 | 4071 | break; |
65f38f15 AM |
4072 | |
4073 | default: | |
96e0dda4 | 4074 | break; |
5bd4f169 AM |
4075 | } |
4076 | } | |
4077 | ||
b34976b6 | 4078 | return TRUE; |
5bd4f169 AM |
4079 | } |
4080 | ||
4081 | /* Return the section that should be marked against GC for a given | |
4082 | relocation. */ | |
4083 | ||
4084 | static asection * | |
4ce794b7 AM |
4085 | ppc64_elf_gc_mark_hook (asection *sec, |
4086 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
4087 | Elf_Internal_Rela *rel, | |
4088 | struct elf_link_hash_entry *h, | |
4089 | Elf_Internal_Sym *sym) | |
5bd4f169 | 4090 | { |
1e2f5b6e AM |
4091 | asection *rsec = NULL; |
4092 | ||
5bd4f169 AM |
4093 | if (h != NULL) |
4094 | { | |
04c9666a | 4095 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e | 4096 | struct ppc_link_hash_entry *fdh; |
a33d1f77 | 4097 | |
4ce794b7 | 4098 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 4099 | switch (r_type) |
5bd4f169 AM |
4100 | { |
4101 | case R_PPC64_GNU_VTINHERIT: | |
4102 | case R_PPC64_GNU_VTENTRY: | |
4103 | break; | |
4104 | ||
4105 | default: | |
4106 | switch (h->root.type) | |
4107 | { | |
4108 | case bfd_link_hash_defined: | |
4109 | case bfd_link_hash_defweak: | |
1e2f5b6e AM |
4110 | fdh = (struct ppc_link_hash_entry *) h; |
4111 | ||
4112 | /* Function descriptor syms cause the associated | |
4113 | function code sym section to be marked. */ | |
4114 | if (fdh->is_func_descriptor) | |
4115 | rsec = fdh->oh->root.u.def.section; | |
4116 | ||
4117 | /* Function entry syms return NULL if they are in .opd | |
4118 | and are not ._start (or others undefined on the ld | |
4119 | command line). Thus we avoid marking all function | |
b34976b6 | 4120 | sections, as all functions are referenced in .opd. */ |
1e2f5b6e AM |
4121 | else if ((fdh->oh != NULL |
4122 | && ((struct ppc_link_hash_entry *) fdh->oh)->is_entry) | |
f0abc2a1 | 4123 | || ppc64_elf_section_data (sec)->opd.func_sec == NULL) |
1e2f5b6e AM |
4124 | rsec = h->root.u.def.section; |
4125 | break; | |
5bd4f169 AM |
4126 | |
4127 | case bfd_link_hash_common: | |
1e2f5b6e AM |
4128 | rsec = h->root.u.c.p->section; |
4129 | break; | |
5bd4f169 AM |
4130 | |
4131 | default: | |
4132 | break; | |
4133 | } | |
4134 | } | |
4135 | } | |
4136 | else | |
4137 | { | |
1e2f5b6e AM |
4138 | asection **opd_sym_section; |
4139 | ||
4140 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
f0abc2a1 | 4141 | opd_sym_section = ppc64_elf_section_data (rsec)->opd.func_sec; |
1e2f5b6e AM |
4142 | if (opd_sym_section != NULL) |
4143 | rsec = opd_sym_section[sym->st_value / 24]; | |
f0abc2a1 | 4144 | else if (ppc64_elf_section_data (sec)->opd.func_sec != NULL) |
1e2f5b6e | 4145 | rsec = NULL; |
5bd4f169 AM |
4146 | } |
4147 | ||
1e2f5b6e | 4148 | return rsec; |
5bd4f169 AM |
4149 | } |
4150 | ||
65f38f15 AM |
4151 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
4152 | section being removed. */ | |
5bd4f169 | 4153 | |
b34976b6 | 4154 | static bfd_boolean |
4ce794b7 AM |
4155 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
4156 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 4157 | { |
411e1bfb | 4158 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
4159 | Elf_Internal_Shdr *symtab_hdr; |
4160 | struct elf_link_hash_entry **sym_hashes; | |
411e1bfb | 4161 | struct got_entry **local_got_ents; |
5bd4f169 | 4162 | const Elf_Internal_Rela *rel, *relend; |
5bd4f169 | 4163 | |
ec338859 AM |
4164 | elf_section_data (sec)->local_dynrel = NULL; |
4165 | ||
411e1bfb | 4166 | htab = ppc_hash_table (info); |
5bd4f169 AM |
4167 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4168 | sym_hashes = elf_sym_hashes (abfd); | |
411e1bfb | 4169 | local_got_ents = elf_local_got_ents (abfd); |
5bd4f169 AM |
4170 | |
4171 | relend = relocs + sec->reloc_count; | |
4172 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
4173 | { |
4174 | unsigned long r_symndx; | |
04c9666a | 4175 | enum elf_ppc64_reloc_type r_type; |
58ac9f71 | 4176 | struct elf_link_hash_entry *h = NULL; |
411e1bfb | 4177 | char tls_type = 0; |
5bd4f169 | 4178 | |
a33d1f77 | 4179 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 | 4180 | r_type = ELF64_R_TYPE (rel->r_info); |
58ac9f71 AM |
4181 | if (r_symndx >= symtab_hdr->sh_info) |
4182 | { | |
4183 | struct ppc_link_hash_entry *eh; | |
4184 | struct ppc_dyn_relocs **pp; | |
4185 | struct ppc_dyn_relocs *p; | |
4186 | ||
4187 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4188 | eh = (struct ppc_link_hash_entry *) h; | |
4189 | ||
4190 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4191 | if (p->sec == sec) | |
4192 | { | |
4193 | /* Everything must go for SEC. */ | |
4194 | *pp = p->next; | |
4195 | break; | |
4196 | } | |
4197 | } | |
4198 | ||
a33d1f77 AM |
4199 | switch (r_type) |
4200 | { | |
411e1bfb AM |
4201 | case R_PPC64_GOT_TLSLD16: |
4202 | case R_PPC64_GOT_TLSLD16_LO: | |
4203 | case R_PPC64_GOT_TLSLD16_HI: | |
4204 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 4205 | ppc64_tlsld_got (abfd)->refcount -= 1; |
951fd09b | 4206 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
4207 | goto dogot; |
4208 | ||
4209 | case R_PPC64_GOT_TLSGD16: | |
4210 | case R_PPC64_GOT_TLSGD16_LO: | |
4211 | case R_PPC64_GOT_TLSGD16_HI: | |
4212 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 4213 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
4214 | goto dogot; |
4215 | ||
4216 | case R_PPC64_GOT_TPREL16_DS: | |
4217 | case R_PPC64_GOT_TPREL16_LO_DS: | |
4218 | case R_PPC64_GOT_TPREL16_HI: | |
4219 | case R_PPC64_GOT_TPREL16_HA: | |
4220 | tls_type = TLS_TLS | TLS_TPREL; | |
4221 | goto dogot; | |
4222 | ||
4223 | case R_PPC64_GOT_DTPREL16_DS: | |
4224 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
4225 | case R_PPC64_GOT_DTPREL16_HI: | |
4226 | case R_PPC64_GOT_DTPREL16_HA: | |
4227 | tls_type = TLS_TLS | TLS_DTPREL; | |
4228 | goto dogot; | |
4229 | ||
a33d1f77 AM |
4230 | case R_PPC64_GOT16: |
4231 | case R_PPC64_GOT16_DS: | |
4232 | case R_PPC64_GOT16_HA: | |
4233 | case R_PPC64_GOT16_HI: | |
4234 | case R_PPC64_GOT16_LO: | |
4235 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb AM |
4236 | dogot: |
4237 | { | |
4238 | struct got_entry *ent; | |
4239 | ||
58ac9f71 AM |
4240 | if (h != NULL) |
4241 | ent = h->got.glist; | |
411e1bfb AM |
4242 | else |
4243 | ent = local_got_ents[r_symndx]; | |
4244 | ||
4245 | for (; ent != NULL; ent = ent->next) | |
4246 | if (ent->addend == rel->r_addend | |
e717da7e | 4247 | && ent->owner == abfd |
411e1bfb AM |
4248 | && ent->tls_type == tls_type) |
4249 | break; | |
4250 | if (ent == NULL) | |
4251 | abort (); | |
4252 | if (ent->got.refcount > 0) | |
4253 | ent->got.refcount -= 1; | |
4254 | } | |
a33d1f77 | 4255 | break; |
65f38f15 | 4256 | |
a33d1f77 AM |
4257 | case R_PPC64_PLT16_HA: |
4258 | case R_PPC64_PLT16_HI: | |
4259 | case R_PPC64_PLT16_LO: | |
4260 | case R_PPC64_PLT32: | |
4261 | case R_PPC64_PLT64: | |
721956f4 AM |
4262 | case R_PPC64_REL14: |
4263 | case R_PPC64_REL14_BRNTAKEN: | |
4264 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 | 4265 | case R_PPC64_REL24: |
58ac9f71 | 4266 | if (h != NULL) |
5d1634d7 | 4267 | { |
411e1bfb AM |
4268 | struct plt_entry *ent; |
4269 | ||
411e1bfb AM |
4270 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
4271 | if (ent->addend == rel->r_addend) | |
4272 | break; | |
4273 | if (ent == NULL) | |
4274 | abort (); | |
4275 | if (ent->plt.refcount > 0) | |
4276 | ent->plt.refcount -= 1; | |
5d1634d7 | 4277 | } |
e86ce104 | 4278 | break; |
5d1634d7 | 4279 | |
a33d1f77 AM |
4280 | default: |
4281 | break; | |
4282 | } | |
4283 | } | |
b34976b6 | 4284 | return TRUE; |
5bd4f169 AM |
4285 | } |
4286 | ||
e86ce104 AM |
4287 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
4288 | information on function code symbol entries to their corresponding | |
4289 | function descriptor symbol entries. */ | |
b34976b6 | 4290 | static bfd_boolean |
4ce794b7 | 4291 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 4292 | { |
e86ce104 | 4293 | struct bfd_link_info *info; |
65f38f15 | 4294 | struct ppc_link_hash_table *htab; |
411e1bfb | 4295 | struct plt_entry *ent; |
50bc7936 AM |
4296 | struct ppc_link_hash_entry *fh; |
4297 | struct ppc_link_hash_entry *fdh; | |
4298 | bfd_boolean force_local; | |
5bd4f169 | 4299 | |
50bc7936 AM |
4300 | fh = (struct ppc_link_hash_entry *) h; |
4301 | if (fh->elf.root.type == bfd_link_hash_indirect) | |
b34976b6 | 4302 | return TRUE; |
e86ce104 | 4303 | |
50bc7936 AM |
4304 | if (fh->elf.root.type == bfd_link_hash_warning) |
4305 | fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link; | |
e92d460e | 4306 | |
4ce794b7 | 4307 | info = inf; |
65f38f15 | 4308 | htab = ppc_hash_table (info); |
5bd4f169 | 4309 | |
e86ce104 AM |
4310 | /* If this is a function code symbol, transfer dynamic linking |
4311 | information to the function descriptor symbol. */ | |
50bc7936 | 4312 | if (!fh->is_func) |
b34976b6 | 4313 | return TRUE; |
e86ce104 | 4314 | |
50bc7936 AM |
4315 | if (fh->elf.root.type == bfd_link_hash_undefweak |
4316 | && (fh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR)) | |
b34976b6 | 4317 | htab->have_undefweak = TRUE; |
805fc799 | 4318 | |
50bc7936 | 4319 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
4320 | if (ent->plt.refcount > 0) |
4321 | break; | |
50bc7936 AM |
4322 | if (ent == NULL |
4323 | || fh->elf.root.root.string[0] != '.' | |
4324 | || fh->elf.root.root.string[1] == '\0') | |
4325 | return TRUE; | |
5bd4f169 | 4326 | |
50bc7936 AM |
4327 | /* Find the corresponding function descriptor symbol. Create it |
4328 | as undefined if necessary. */ | |
5bd4f169 | 4329 | |
50bc7936 AM |
4330 | fdh = get_fdh (fh, htab); |
4331 | if (fdh != NULL) | |
4332 | while (fdh->elf.root.type == bfd_link_hash_indirect | |
4333 | || fdh->elf.root.type == bfd_link_hash_warning) | |
4334 | fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link; | |
5bd4f169 | 4335 | |
50bc7936 AM |
4336 | if (fdh == NULL |
4337 | && info->shared | |
4338 | && (fh->elf.root.type == bfd_link_hash_undefined | |
4339 | || fh->elf.root.type == bfd_link_hash_undefweak)) | |
4340 | { | |
4341 | bfd *abfd; | |
4342 | asymbol *newsym; | |
4343 | struct bfd_link_hash_entry *bh; | |
4344 | ||
4345 | abfd = fh->elf.root.u.undef.abfd; | |
4346 | newsym = bfd_make_empty_symbol (abfd); | |
4347 | newsym->name = fh->elf.root.root.string + 1; | |
4348 | newsym->section = bfd_und_section_ptr; | |
4349 | newsym->value = 0; | |
4350 | newsym->flags = BSF_OBJECT; | |
4351 | if (fh->elf.root.type == bfd_link_hash_undefweak) | |
4352 | newsym->flags |= BSF_WEAK; | |
4353 | ||
4354 | bh = &fdh->elf.root; | |
4355 | if ( !(_bfd_generic_link_add_one_symbol | |
4356 | (info, abfd, newsym->name, newsym->flags, | |
4357 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) | |
648cca2c | 4358 | { |
50bc7936 | 4359 | return FALSE; |
648cca2c | 4360 | } |
50bc7936 AM |
4361 | fdh = (struct ppc_link_hash_entry *) bh; |
4362 | fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF; | |
4363 | fdh->elf.size = 24; | |
4364 | fdh->elf.type = STT_OBJECT; | |
4365 | } | |
648cca2c | 4366 | |
50bc7936 AM |
4367 | if (fdh != NULL |
4368 | && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 | |
4369 | && (info->shared | |
4370 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4371 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 | |
4372 | || (fdh->elf.root.type == bfd_link_hash_undefweak | |
4373 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) | |
4374 | { | |
4375 | if (fdh->elf.dynindx == -1) | |
4376 | if (! bfd_elf64_link_record_dynamic_symbol (info, &fdh->elf)) | |
4377 | return FALSE; | |
4378 | fdh->elf.elf_link_hash_flags | |
4379 | |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
4380 | | ELF_LINK_HASH_REF_DYNAMIC | |
4381 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
4382 | | ELF_LINK_NON_GOT_REF)); | |
4383 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) | |
e86ce104 | 4384 | { |
50bc7936 AM |
4385 | fdh->elf.plt.plist = fh->elf.plt.plist; |
4386 | fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
e86ce104 | 4387 | } |
50bc7936 AM |
4388 | fdh->is_func_descriptor = 1; |
4389 | fdh->oh = &fh->elf; | |
4390 | fh->oh = &fdh->elf; | |
e86ce104 AM |
4391 | } |
4392 | ||
50bc7936 AM |
4393 | /* Now that the info is on the function descriptor, clear the |
4394 | function code sym info. Any function code syms for which we | |
4395 | don't have a definition in a regular file, we force local. | |
4396 | This prevents a shared library from exporting syms that have | |
4397 | been imported from another library. Function code syms that | |
4398 | are really in the library we must leave global to prevent the | |
4399 | linker dragging in a definition from a static library. */ | |
4400 | force_local | |
4401 | = (info->shared | |
4402 | && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4403 | || fdh == NULL | |
4404 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4405 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)); | |
4406 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); | |
4407 | ||
b34976b6 | 4408 | return TRUE; |
e86ce104 | 4409 | } |
40b8271b | 4410 | |
82bd7b59 AM |
4411 | #define MIN_SAVE_FPR 14 |
4412 | #define MAX_SAVE_FPR 31 | |
4413 | ||
e86ce104 | 4414 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
4415 | this hook to a) provide some gcc support functions, and b) transfer |
4416 | dynamic linking information gathered so far on function code symbol | |
4417 | entries, to their corresponding function descriptor symbol entries. */ | |
b34976b6 | 4418 | static bfd_boolean |
4ce794b7 AM |
4419 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
4420 | struct bfd_link_info *info) | |
e86ce104 AM |
4421 | { |
4422 | struct ppc_link_hash_table *htab; | |
82bd7b59 AM |
4423 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
4424 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; | |
4425 | unsigned int i; | |
4426 | struct elf_link_hash_entry *h; | |
721956f4 | 4427 | bfd_byte *p; |
82bd7b59 | 4428 | char sym[10]; |
e86ce104 AM |
4429 | |
4430 | htab = ppc_hash_table (info); | |
82bd7b59 AM |
4431 | |
4432 | if (htab->sfpr == NULL) | |
4433 | /* We don't have any relocs. */ | |
b34976b6 | 4434 | return TRUE; |
82bd7b59 AM |
4435 | |
4436 | /* First provide any missing ._savef* and ._restf* functions. */ | |
4437 | memcpy (sym, "._savef14", 10); | |
4438 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4439 | { | |
4440 | sym[7] = i / 10 + '0'; | |
4441 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4442 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4443 | if (h != NULL |
772119ce | 4444 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4445 | { |
4446 | if (lowest_savef > i) | |
4447 | lowest_savef = i; | |
4448 | h->root.type = bfd_link_hash_defined; | |
4449 | h->root.u.def.section = htab->sfpr; | |
4450 | h->root.u.def.value = (i - lowest_savef) * 4; | |
4451 | h->type = STT_FUNC; | |
4452 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4453 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4454 | } |
4455 | } | |
4456 | ||
4457 | memcpy (sym, "._restf14", 10); | |
4458 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4459 | { | |
4460 | sym[7] = i / 10 + '0'; | |
4461 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4462 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4463 | if (h != NULL |
772119ce | 4464 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4465 | { |
4466 | if (lowest_restf > i) | |
4467 | lowest_restf = i; | |
4468 | h->root.type = bfd_link_hash_defined; | |
4469 | h->root.u.def.section = htab->sfpr; | |
4470 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 | |
4471 | + (i - lowest_restf) * 4); | |
4472 | h->type = STT_FUNC; | |
4473 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4474 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4475 | } |
4476 | } | |
4477 | ||
4ce794b7 | 4478 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
805fc799 | 4479 | |
82bd7b59 AM |
4480 | htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
4481 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); | |
4482 | ||
4483 | if (htab->sfpr->_raw_size == 0) | |
805fc799 AM |
4484 | { |
4485 | if (!htab->have_undefweak) | |
4486 | { | |
4487 | _bfd_strip_section_from_output (info, htab->sfpr); | |
b34976b6 | 4488 | return TRUE; |
805fc799 AM |
4489 | } |
4490 | ||
4491 | htab->sfpr->_raw_size = 4; | |
4492 | } | |
82bd7b59 | 4493 | |
4ce794b7 | 4494 | p = bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size); |
721956f4 | 4495 | if (p == NULL) |
b34976b6 | 4496 | return FALSE; |
721956f4 AM |
4497 | htab->sfpr->contents = p; |
4498 | ||
4499 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) | |
4500 | { | |
4501 | unsigned int fpr = i << 21; | |
4502 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4503 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); | |
4504 | p += 4; | |
4505 | } | |
4506 | if (lowest_savef <= MAX_SAVE_FPR) | |
4507 | { | |
82bd7b59 AM |
4508 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
4509 | p += 4; | |
721956f4 | 4510 | } |
82bd7b59 | 4511 | |
721956f4 AM |
4512 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
4513 | { | |
4514 | unsigned int fpr = i << 21; | |
4515 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4516 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); | |
82bd7b59 AM |
4517 | p += 4; |
4518 | } | |
721956f4 AM |
4519 | if (lowest_restf <= MAX_SAVE_FPR |
4520 | || htab->sfpr->_raw_size == 4) | |
4521 | { | |
4522 | bfd_put_32 (htab->elf.dynobj, BLR, p); | |
4523 | } | |
82bd7b59 | 4524 | |
b34976b6 | 4525 | return TRUE; |
e86ce104 AM |
4526 | } |
4527 | ||
4528 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
4529 | regular object. The current definition is in some section of the | |
4530 | dynamic object, but we're not including those sections. We have to | |
4531 | change the definition to something the rest of the link can | |
4532 | understand. */ | |
4533 | ||
b34976b6 | 4534 | static bfd_boolean |
4ce794b7 AM |
4535 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
4536 | struct elf_link_hash_entry *h) | |
e86ce104 AM |
4537 | { |
4538 | struct ppc_link_hash_table *htab; | |
e86ce104 AM |
4539 | asection *s; |
4540 | unsigned int power_of_two; | |
4541 | ||
4542 | htab = ppc_hash_table (info); | |
4543 | ||
4544 | /* Deal with function syms. */ | |
4545 | if (h->type == STT_FUNC | |
4546 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
4547 | { | |
4548 | /* Clear procedure linkage table information for any symbol that | |
4549 | won't need a .plt entry. */ | |
411e1bfb AM |
4550 | struct plt_entry *ent; |
4551 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4552 | if (ent->plt.refcount > 0) | |
4553 | break; | |
e86ce104 | 4554 | if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor |
411e1bfb | 4555 | || ent == NULL |
9c7a29a3 AM |
4556 | || SYMBOL_CALLS_LOCAL (info, h) |
4557 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4558 | && h->root.type == bfd_link_hash_undefweak)) | |
40b8271b | 4559 | { |
411e1bfb | 4560 | h->plt.plist = NULL; |
40b8271b | 4561 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
40b8271b | 4562 | } |
5bd4f169 | 4563 | } |
bbd7ec4a | 4564 | else |
411e1bfb | 4565 | h->plt.plist = NULL; |
5bd4f169 AM |
4566 | |
4567 | /* If this is a weak symbol, and there is a real definition, the | |
4568 | processor independent code will have arranged for us to see the | |
4569 | real definition first, and we can just use the same value. */ | |
4570 | if (h->weakdef != NULL) | |
4571 | { | |
4572 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
4573 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
4574 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
4575 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
a23b6845 AM |
4576 | if (ELIMINATE_COPY_RELOCS) |
4577 | h->elf_link_hash_flags | |
4578 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) | |
4579 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); | |
b34976b6 | 4580 | return TRUE; |
5bd4f169 AM |
4581 | } |
4582 | ||
5bd4f169 AM |
4583 | /* If we are creating a shared library, we must presume that the |
4584 | only references to the symbol are via the global offset table. | |
4585 | For such cases we need not do anything here; the relocations will | |
4586 | be handled correctly by relocate_section. */ | |
4587 | if (info->shared) | |
b34976b6 | 4588 | return TRUE; |
5bd4f169 | 4589 | |
65f38f15 AM |
4590 | /* If there are no references to this symbol that do not use the |
4591 | GOT, we don't need to generate a copy reloc. */ | |
4592 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 4593 | return TRUE; |
65f38f15 | 4594 | |
f4656909 | 4595 | if (ELIMINATE_COPY_RELOCS) |
65f38f15 | 4596 | { |
f4656909 AM |
4597 | struct ppc_link_hash_entry * eh; |
4598 | struct ppc_dyn_relocs *p; | |
65f38f15 | 4599 | |
f4656909 AM |
4600 | eh = (struct ppc_link_hash_entry *) h; |
4601 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4602 | { | |
4603 | s = p->sec->output_section; | |
4604 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
4605 | break; | |
4606 | } | |
4607 | ||
4608 | /* If we didn't find any dynamic relocs in read-only sections, then | |
4609 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
4610 | if (p == NULL) | |
4611 | { | |
4612 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
4613 | return TRUE; | |
4614 | } | |
65f38f15 AM |
4615 | } |
4616 | ||
5d35169e | 4617 | if (h->plt.plist != NULL) |
97b639ba AM |
4618 | { |
4619 | /* We should never get here, but unfortunately there are versions | |
4620 | of gcc out there that improperly (for this ABI) put initialized | |
4621 | function pointers, vtable refs and suchlike in read-only | |
4622 | sections. Allow them to proceed, but warn that this might | |
4623 | break at runtime. */ | |
4624 | (*_bfd_error_handler) | |
4625 | (_("copy reloc against `%s' requires lazy plt linking; " | |
4626 | "avoid setting LD_BIND_NOW=1 or upgrade gcc"), | |
4627 | h->root.root.string); | |
4628 | } | |
5d35169e AM |
4629 | |
4630 | /* This is a reference to a symbol defined by a dynamic object which | |
4631 | is not a function. */ | |
4632 | ||
5bd4f169 AM |
4633 | /* We must allocate the symbol in our .dynbss section, which will |
4634 | become part of the .bss section of the executable. There will be | |
4635 | an entry for this symbol in the .dynsym section. The dynamic | |
4636 | object will contain position independent code, so all references | |
4637 | from the dynamic object to this symbol will go through the global | |
4638 | offset table. The dynamic linker will use the .dynsym entry to | |
4639 | determine the address it must put in the global offset table, so | |
4640 | both the dynamic object and the regular object will refer to the | |
4641 | same memory location for the variable. */ | |
5bd4f169 | 4642 | |
04c9666a AM |
4643 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
4644 | to copy the initial value out of the dynamic object and into the | |
5bd4f169 AM |
4645 | runtime process image. We need to remember the offset into the |
4646 | .rela.bss section we are going to use. */ | |
4647 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
4648 | { | |
4ce794b7 | 4649 | htab->relbss->_raw_size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
4650 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
4651 | } | |
4652 | ||
4653 | /* We need to figure out the alignment required for this symbol. I | |
4654 | have no idea how ELF linkers handle this. */ | |
4655 | power_of_two = bfd_log2 (h->size); | |
4656 | if (power_of_two > 4) | |
4657 | power_of_two = 4; | |
4658 | ||
4659 | /* Apply the required alignment. */ | |
4ce794b7 | 4660 | s = htab->dynbss; |
65f38f15 AM |
4661 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); |
4662 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
5bd4f169 | 4663 | { |
65f38f15 | 4664 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 4665 | return FALSE; |
5bd4f169 AM |
4666 | } |
4667 | ||
4668 | /* Define the symbol as being at this point in the section. */ | |
4669 | h->root.u.def.section = s; | |
4670 | h->root.u.def.value = s->_raw_size; | |
4671 | ||
4672 | /* Increment the section size to make room for the symbol. */ | |
4673 | s->_raw_size += h->size; | |
4674 | ||
b34976b6 | 4675 | return TRUE; |
5bd4f169 AM |
4676 | } |
4677 | ||
e86ce104 AM |
4678 | /* If given a function descriptor symbol, hide both the function code |
4679 | sym and the descriptor. */ | |
4680 | static void | |
4ce794b7 AM |
4681 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
4682 | struct elf_link_hash_entry *h, | |
4683 | bfd_boolean force_local) | |
e86ce104 AM |
4684 | { |
4685 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); | |
4686 | ||
4687 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) | |
4688 | { | |
721956f4 | 4689 | struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh; |
e86ce104 | 4690 | |
721956f4 | 4691 | if (fh == NULL) |
d1329ca3 AM |
4692 | { |
4693 | const char *p, *q; | |
4694 | struct ppc_link_hash_table *htab; | |
4695 | char save; | |
4696 | ||
4697 | /* We aren't supposed to use alloca in BFD because on | |
4698 | systems which do not have alloca the version in libiberty | |
4699 | calls xmalloc, which might cause the program to crash | |
4700 | when it runs out of memory. This function doesn't have a | |
4701 | return status, so there's no way to gracefully return an | |
4702 | error. So cheat. We know that string[-1] can be safely | |
4703 | dereferenced; It's either a string in an ELF string | |
4704 | table, or allocated in an objalloc structure. */ | |
4705 | ||
4706 | p = h->root.root.string - 1; | |
4707 | save = *p; | |
4708 | *(char *) p = '.'; | |
4709 | htab = ppc_hash_table (info); | |
b34976b6 | 4710 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
4711 | *(char *) p = save; |
4712 | ||
4713 | /* Unfortunately, if it so happens that the string we were | |
4714 | looking for was allocated immediately before this string, | |
4715 | then we overwrote the string terminator. That's the only | |
4716 | reason the lookup should fail. */ | |
4717 | if (fh == NULL) | |
4718 | { | |
4719 | q = h->root.root.string + strlen (h->root.root.string); | |
4720 | while (q >= h->root.root.string && *q == *p) | |
4721 | --q, --p; | |
4722 | if (q < h->root.root.string && *p == '.') | |
b34976b6 | 4723 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
4724 | } |
4725 | if (fh != NULL) | |
4726 | { | |
4727 | ((struct ppc_link_hash_entry *) h)->oh = fh; | |
4728 | ((struct ppc_link_hash_entry *) fh)->oh = h; | |
4729 | } | |
4730 | } | |
e86ce104 AM |
4731 | if (fh != NULL) |
4732 | _bfd_elf_link_hash_hide_symbol (info, fh, force_local); | |
4733 | } | |
4734 | } | |
4735 | ||
411e1bfb | 4736 | static bfd_boolean |
4ce794b7 AM |
4737 | get_sym_h (struct elf_link_hash_entry **hp, Elf_Internal_Sym **symp, |
4738 | asection **symsecp, char **tls_maskp, Elf_Internal_Sym **locsymsp, | |
4739 | unsigned long r_symndx, bfd *ibfd) | |
411e1bfb AM |
4740 | { |
4741 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
4742 | ||
4743 | if (r_symndx >= symtab_hdr->sh_info) | |
4744 | { | |
4745 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
4746 | struct elf_link_hash_entry *h; | |
4747 | ||
4748 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4749 | while (h->root.type == bfd_link_hash_indirect | |
4750 | || h->root.type == bfd_link_hash_warning) | |
4751 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4752 | ||
4753 | if (hp != NULL) | |
4754 | *hp = h; | |
4755 | ||
4756 | if (symp != NULL) | |
4757 | *symp = NULL; | |
4758 | ||
4759 | if (symsecp != NULL) | |
4760 | { | |
4761 | asection *symsec = NULL; | |
4762 | if (h->root.type == bfd_link_hash_defined | |
4763 | || h->root.type == bfd_link_hash_defweak) | |
4764 | symsec = h->root.u.def.section; | |
4765 | *symsecp = symsec; | |
4766 | } | |
4767 | ||
e7b938ca | 4768 | if (tls_maskp != NULL) |
411e1bfb AM |
4769 | { |
4770 | struct ppc_link_hash_entry *eh; | |
4771 | ||
4772 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 4773 | *tls_maskp = &eh->tls_mask; |
411e1bfb AM |
4774 | } |
4775 | } | |
4776 | else | |
4777 | { | |
4778 | Elf_Internal_Sym *sym; | |
4779 | Elf_Internal_Sym *locsyms = *locsymsp; | |
4780 | ||
4781 | if (locsyms == NULL) | |
4782 | { | |
4783 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4784 | if (locsyms == NULL) | |
4785 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
4786 | symtab_hdr->sh_info, | |
4787 | 0, NULL, NULL, NULL); | |
4788 | if (locsyms == NULL) | |
4789 | return FALSE; | |
4790 | *locsymsp = locsyms; | |
4791 | } | |
4792 | sym = locsyms + r_symndx; | |
4793 | ||
4794 | if (hp != NULL) | |
4795 | *hp = NULL; | |
4796 | ||
4797 | if (symp != NULL) | |
4798 | *symp = sym; | |
4799 | ||
4800 | if (symsecp != NULL) | |
4801 | { | |
4802 | asection *symsec = NULL; | |
4803 | if ((sym->st_shndx != SHN_UNDEF | |
4804 | && sym->st_shndx < SHN_LORESERVE) | |
4805 | || sym->st_shndx > SHN_HIRESERVE) | |
4806 | symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); | |
4807 | *symsecp = symsec; | |
4808 | } | |
4809 | ||
e7b938ca | 4810 | if (tls_maskp != NULL) |
411e1bfb AM |
4811 | { |
4812 | struct got_entry **lgot_ents; | |
e7b938ca | 4813 | char *tls_mask; |
411e1bfb | 4814 | |
e7b938ca | 4815 | tls_mask = NULL; |
411e1bfb AM |
4816 | lgot_ents = elf_local_got_ents (ibfd); |
4817 | if (lgot_ents != NULL) | |
4818 | { | |
e7b938ca AM |
4819 | char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info); |
4820 | tls_mask = &lgot_masks[r_symndx]; | |
411e1bfb | 4821 | } |
e7b938ca | 4822 | *tls_maskp = tls_mask; |
411e1bfb AM |
4823 | } |
4824 | } | |
4825 | return TRUE; | |
4826 | } | |
4827 | ||
e7b938ca | 4828 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
951fd09b | 4829 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
ad8e1ba5 | 4830 | type suitable for optimization, and 1 otherwise. */ |
951fd09b AM |
4831 | |
4832 | static int | |
0d4792f7 AM |
4833 | get_tls_mask (char **tls_maskp, unsigned long *toc_symndx, |
4834 | Elf_Internal_Sym **locsymsp, | |
4ce794b7 | 4835 | const Elf_Internal_Rela *rel, bfd *ibfd) |
411e1bfb AM |
4836 | { |
4837 | unsigned long r_symndx; | |
0d4792f7 | 4838 | int next_r; |
411e1bfb AM |
4839 | struct elf_link_hash_entry *h; |
4840 | Elf_Internal_Sym *sym; | |
4841 | asection *sec; | |
4842 | bfd_vma off; | |
4843 | ||
4844 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 4845 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 4846 | return 0; |
411e1bfb | 4847 | |
e7b938ca | 4848 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
411e1bfb AM |
4849 | || sec == NULL |
4850 | || ppc64_elf_section_data (sec)->t_symndx == NULL) | |
951fd09b | 4851 | return 1; |
411e1bfb AM |
4852 | |
4853 | /* Look inside a TOC section too. */ | |
4854 | if (h != NULL) | |
4855 | { | |
4856 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
4857 | off = h->root.u.def.value; | |
4858 | } | |
4859 | else | |
4860 | off = sym->st_value; | |
4861 | off += rel->r_addend; | |
4862 | BFD_ASSERT (off % 8 == 0); | |
4863 | r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8]; | |
951fd09b | 4864 | next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1]; |
e7b938ca | 4865 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 4866 | return 0; |
0d4792f7 AM |
4867 | if (toc_symndx != NULL) |
4868 | *toc_symndx = r_symndx; | |
4869 | if ((h == NULL | |
4870 | || ((h->root.type == bfd_link_hash_defined | |
4871 | || h->root.type == bfd_link_hash_defweak) | |
4872 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
4873 | && (next_r == -1 || next_r == -2)) | |
4874 | return 1 - next_r; | |
951fd09b | 4875 | return 1; |
411e1bfb AM |
4876 | } |
4877 | ||
b34976b6 | 4878 | bfd_boolean |
4ce794b7 | 4879 | ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info) |
1e2f5b6e AM |
4880 | { |
4881 | bfd *ibfd; | |
1e2f5b6e | 4882 | |
411e1bfb | 4883 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1e2f5b6e AM |
4884 | { |
4885 | asection *sec; | |
4886 | Elf_Internal_Rela *relstart, *rel, *relend; | |
4887 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 4888 | Elf_Internal_Sym *local_syms; |
1e2f5b6e AM |
4889 | struct elf_link_hash_entry **sym_hashes; |
4890 | bfd_vma offset; | |
d6fe2dc1 | 4891 | bfd_size_type amt; |
1e2f5b6e | 4892 | long *adjust; |
b34976b6 | 4893 | bfd_boolean need_edit; |
1e2f5b6e AM |
4894 | |
4895 | sec = bfd_get_section_by_name (ibfd, ".opd"); | |
4896 | if (sec == NULL) | |
4897 | continue; | |
4898 | ||
d6fe2dc1 | 4899 | amt = sec->_raw_size * sizeof (long) / 24; |
f0abc2a1 | 4900 | adjust = ppc64_elf_section_data (sec)->opd.adjust; |
d6fe2dc1 AM |
4901 | if (adjust == NULL) |
4902 | { | |
4903 | /* Must be a ld -r link. ie. check_relocs hasn't been | |
4904 | called. */ | |
4ce794b7 | 4905 | adjust = bfd_zalloc (obfd, amt); |
f0abc2a1 | 4906 | ppc64_elf_section_data (sec)->opd.adjust = adjust; |
d6fe2dc1 | 4907 | } |
4ce794b7 | 4908 | memset (adjust, 0, amt); |
1e2f5b6e AM |
4909 | |
4910 | if (sec->output_section == bfd_abs_section_ptr) | |
4911 | continue; | |
4912 | ||
4913 | /* Look through the section relocs. */ | |
4914 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
4915 | continue; | |
4916 | ||
6cdc0ccc | 4917 | local_syms = NULL; |
1e2f5b6e AM |
4918 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
4919 | sym_hashes = elf_sym_hashes (ibfd); | |
4920 | ||
4921 | /* Read the relocations. */ | |
4ce794b7 | 4922 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 4923 | info->keep_memory); |
1e2f5b6e | 4924 | if (relstart == NULL) |
b34976b6 | 4925 | return FALSE; |
1e2f5b6e AM |
4926 | |
4927 | /* First run through the relocs to check they are sane, and to | |
4928 | determine whether we need to edit this opd section. */ | |
b34976b6 | 4929 | need_edit = FALSE; |
1e2f5b6e AM |
4930 | offset = 0; |
4931 | relend = relstart + sec->reloc_count; | |
50bc7936 | 4932 | for (rel = relstart; rel < relend; ) |
1e2f5b6e | 4933 | { |
04c9666a | 4934 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e AM |
4935 | unsigned long r_symndx; |
4936 | asection *sym_sec; | |
4937 | struct elf_link_hash_entry *h; | |
4938 | Elf_Internal_Sym *sym; | |
4939 | ||
4940 | /* .opd contains a regular array of 24 byte entries. We're | |
4941 | only interested in the reloc pointing to a function entry | |
4942 | point. */ | |
50bc7936 AM |
4943 | if (rel->r_offset != offset |
4944 | || rel + 1 >= relend | |
4945 | || (rel + 1)->r_offset != offset + 8) | |
1e2f5b6e AM |
4946 | { |
4947 | /* If someone messes with .opd alignment then after a | |
4948 | "ld -r" we might have padding in the middle of .opd. | |
4949 | Also, there's nothing to prevent someone putting | |
4950 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 4951 | optimization for them! */ |
1e2f5b6e AM |
4952 | (*_bfd_error_handler) |
4953 | (_("%s: .opd is not a regular array of opd entries"), | |
4954 | bfd_archive_filename (ibfd)); | |
b34976b6 | 4955 | need_edit = FALSE; |
1e2f5b6e AM |
4956 | break; |
4957 | } | |
4958 | ||
50bc7936 AM |
4959 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
4960 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) | |
4961 | { | |
4962 | (*_bfd_error_handler) | |
4963 | (_("%s: unexpected reloc type %u in .opd section"), | |
4964 | bfd_archive_filename (ibfd), r_type); | |
4965 | need_edit = FALSE; | |
4966 | break; | |
4967 | } | |
4968 | ||
1e2f5b6e | 4969 | r_symndx = ELF64_R_SYM (rel->r_info); |
411e1bfb AM |
4970 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
4971 | r_symndx, ibfd)) | |
50bc7936 | 4972 | goto error_ret; |
1e2f5b6e AM |
4973 | |
4974 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
4975 | { | |
411e1bfb AM |
4976 | const char *sym_name; |
4977 | if (h != NULL) | |
4978 | sym_name = h->root.root.string; | |
4979 | else | |
4980 | sym_name = bfd_elf_local_sym_name (ibfd, sym); | |
4981 | ||
1e2f5b6e AM |
4982 | (*_bfd_error_handler) |
4983 | (_("%s: undefined sym `%s' in .opd section"), | |
4984 | bfd_archive_filename (ibfd), | |
411e1bfb | 4985 | sym_name); |
b34976b6 | 4986 | need_edit = FALSE; |
1e2f5b6e AM |
4987 | break; |
4988 | } | |
4989 | ||
51020317 AM |
4990 | /* opd entries are always for functions defined in the |
4991 | current input bfd. If the symbol isn't defined in the | |
4992 | input bfd, then we won't be using the function in this | |
4993 | bfd; It must be defined in a linkonce section in another | |
4994 | bfd, or is weak. It's also possible that we are | |
4995 | discarding the function due to a linker script /DISCARD/, | |
4996 | which we test for via the output_section. */ | |
4997 | if (sym_sec->owner != ibfd | |
4998 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 4999 | need_edit = TRUE; |
1e2f5b6e AM |
5000 | |
5001 | offset += 24; | |
50bc7936 AM |
5002 | rel += 2; |
5003 | /* Allow for the possibility of a reloc on the third word. */ | |
5004 | if (rel < relend | |
5005 | && rel->r_offset == offset - 8) | |
5006 | rel += 1; | |
1e2f5b6e AM |
5007 | } |
5008 | ||
5009 | if (need_edit) | |
5010 | { | |
5011 | Elf_Internal_Rela *write_rel; | |
5012 | bfd_byte *rptr, *wptr; | |
b34976b6 | 5013 | bfd_boolean skip; |
1e2f5b6e AM |
5014 | |
5015 | /* This seems a waste of time as input .opd sections are all | |
5016 | zeros as generated by gcc, but I suppose there's no reason | |
5017 | this will always be so. We might start putting something in | |
5018 | the third word of .opd entries. */ | |
5019 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
5020 | { | |
5021 | bfd_byte *loc = bfd_alloc (ibfd, sec->_raw_size); | |
6cdc0ccc | 5022 | if (loc == NULL |
4ce794b7 | 5023 | || !bfd_get_section_contents (ibfd, sec, loc, 0, |
6cdc0ccc AM |
5024 | sec->_raw_size)) |
5025 | { | |
50bc7936 | 5026 | error_ret: |
6cdc0ccc AM |
5027 | if (local_syms != NULL |
5028 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5029 | free (local_syms); | |
6cdc0ccc AM |
5030 | if (elf_section_data (sec)->relocs != relstart) |
5031 | free (relstart); | |
b34976b6 | 5032 | return FALSE; |
6cdc0ccc | 5033 | } |
1e2f5b6e AM |
5034 | sec->contents = loc; |
5035 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
5036 | } | |
5037 | ||
5038 | elf_section_data (sec)->relocs = relstart; | |
5039 | ||
5040 | wptr = sec->contents; | |
5041 | rptr = sec->contents; | |
5042 | write_rel = relstart; | |
b34976b6 | 5043 | skip = FALSE; |
1e2f5b6e AM |
5044 | offset = 0; |
5045 | for (rel = relstart; rel < relend; rel++) | |
5046 | { | |
50bc7936 AM |
5047 | unsigned long r_symndx; |
5048 | asection *sym_sec; | |
5049 | struct elf_link_hash_entry *h; | |
5050 | Elf_Internal_Sym *sym; | |
5051 | ||
5052 | r_symndx = ELF64_R_SYM (rel->r_info); | |
5053 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
d37c89e5 | 5054 | r_symndx, ibfd)) |
50bc7936 AM |
5055 | goto error_ret; |
5056 | ||
1e2f5b6e AM |
5057 | if (rel->r_offset == offset) |
5058 | { | |
50bc7936 AM |
5059 | struct ppc_link_hash_entry *fdh = NULL; |
5060 | if (h != NULL) | |
5061 | fdh = get_fdh ((struct ppc_link_hash_entry *) h, | |
5062 | ppc_hash_table (info)); | |
1e2f5b6e | 5063 | |
51020317 AM |
5064 | skip = (sym_sec->owner != ibfd |
5065 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
5066 | if (skip) |
5067 | { | |
0be617ce | 5068 | if (h != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
5069 | { |
5070 | /* Arrange for the function descriptor sym | |
5071 | to be dropped. */ | |
d6fe2dc1 AM |
5072 | fdh->elf.root.u.def.value = 0; |
5073 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 AM |
5074 | } |
5075 | } | |
5076 | else | |
1e2f5b6e AM |
5077 | { |
5078 | /* We'll be keeping this opd entry. */ | |
5079 | ||
5080 | if (h != NULL) | |
5081 | { | |
5082 | /* Redefine the function descriptor symbol | |
5083 | to this location in the opd section. | |
5084 | We've checked above that opd relocs are | |
5085 | ordered. */ | |
d6fe2dc1 | 5086 | fdh->elf.root.u.def.value = wptr - sec->contents; |
1e2f5b6e AM |
5087 | } |
5088 | else | |
5089 | { | |
6cdc0ccc AM |
5090 | /* Local syms are a bit tricky. We could |
5091 | tweak them as they can be cached, but | |
5092 | we'd need to look through the local syms | |
5093 | for the function descriptor sym which we | |
5094 | don't have at the moment. So keep an | |
b34976b6 | 5095 | array of adjustments. */ |
7f6a7663 | 5096 | adjust[rel->r_offset / 24] = wptr - rptr; |
1e2f5b6e AM |
5097 | } |
5098 | ||
5099 | if (wptr != rptr) | |
5100 | memcpy (wptr, rptr, 24); | |
5101 | wptr += 24; | |
5102 | } | |
5103 | rptr += 24; | |
5104 | offset += 24; | |
5105 | } | |
5106 | ||
50bc7936 AM |
5107 | if (skip) |
5108 | { | |
5109 | BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info))); | |
5110 | if (info->shared) | |
5111 | { | |
5112 | /* We won't be needing dynamic relocs here. */ | |
5113 | struct ppc_dyn_relocs **pp; | |
5114 | struct ppc_dyn_relocs *p; | |
5115 | ||
5116 | if (h != NULL) | |
5117 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; | |
5118 | else if (sym_sec != NULL) | |
5119 | pp = ((struct ppc_dyn_relocs **) | |
5120 | &elf_section_data (sym_sec)->local_dynrel); | |
5121 | else | |
5122 | pp = ((struct ppc_dyn_relocs **) | |
5123 | &elf_section_data (sec)->local_dynrel); | |
5124 | while ((p = *pp) != NULL) | |
5125 | { | |
5126 | if (p->sec == sec) | |
5127 | { | |
5128 | p->count -= 1; | |
5129 | if (p->count == 0) | |
d37c89e5 | 5130 | *pp = p->next; |
50bc7936 AM |
5131 | break; |
5132 | } | |
5133 | pp = &p->next; | |
5134 | } | |
5135 | } | |
5136 | } | |
5137 | else | |
1e2f5b6e | 5138 | { |
50bc7936 AM |
5139 | /* We need to adjust any reloc offsets to point to the |
5140 | new opd entries. While we're at it, we may as well | |
5141 | remove redundant relocs. */ | |
1e2f5b6e AM |
5142 | rel->r_offset += wptr - rptr; |
5143 | if (write_rel != rel) | |
5144 | memcpy (write_rel, rel, sizeof (*rel)); | |
5145 | ++write_rel; | |
5146 | } | |
5147 | } | |
5148 | ||
5149 | sec->_cooked_size = wptr - sec->contents; | |
5150 | sec->reloc_count = write_rel - relstart; | |
cdcf6e38 AM |
5151 | /* Fudge the size too, as this is used later in |
5152 | elf_bfd_final_link if we are emitting relocs. */ | |
5153 | elf_section_data (sec)->rel_hdr.sh_size | |
5154 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; | |
5155 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); | |
1e2f5b6e | 5156 | } |
6cdc0ccc | 5157 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 5158 | free (relstart); |
6cdc0ccc | 5159 | |
411e1bfb AM |
5160 | if (local_syms != NULL |
5161 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5162 | { | |
5163 | if (!info->keep_memory) | |
5164 | free (local_syms); | |
5165 | else | |
5166 | symtab_hdr->contents = (unsigned char *) local_syms; | |
5167 | } | |
5168 | } | |
5169 | ||
5170 | return TRUE; | |
5171 | } | |
5172 | ||
e1918d23 | 5173 | /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ |
411e1bfb | 5174 | |
e1918d23 | 5175 | asection * |
4ce794b7 | 5176 | ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
411e1bfb | 5177 | { |
411e1bfb AM |
5178 | struct ppc_link_hash_table *htab; |
5179 | ||
411e1bfb | 5180 | htab = ppc_hash_table (info); |
a48ebf4d AM |
5181 | if (htab->tls_get_addr != NULL) |
5182 | { | |
5183 | struct elf_link_hash_entry *h = htab->tls_get_addr; | |
5184 | ||
5185 | while (h->root.type == bfd_link_hash_indirect | |
5186 | || h->root.type == bfd_link_hash_warning) | |
5187 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5188 | ||
5189 | htab->tls_get_addr = h; | |
5190 | } | |
5191 | ||
e1918d23 | 5192 | return _bfd_elf_tls_setup (obfd, info); |
951fd09b | 5193 | } |
411e1bfb | 5194 | |
951fd09b AM |
5195 | /* Run through all the TLS relocs looking for optimization |
5196 | opportunities. The linker has been hacked (see ppc64elf.em) to do | |
5197 | a preliminary section layout so that we know the TLS segment | |
5198 | offsets. We can't optimize earlier because some optimizations need | |
5199 | to know the tp offset, and we need to optimize before allocating | |
5200 | dynamic relocations. */ | |
5201 | ||
5202 | bfd_boolean | |
4ce794b7 | 5203 | ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) |
951fd09b AM |
5204 | { |
5205 | bfd *ibfd; | |
5206 | asection *sec; | |
5207 | struct ppc_link_hash_table *htab; | |
5208 | ||
1049f94e | 5209 | if (info->relocatable || info->shared) |
411e1bfb AM |
5210 | return TRUE; |
5211 | ||
951fd09b | 5212 | htab = ppc_hash_table (info); |
411e1bfb AM |
5213 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5214 | { | |
5215 | Elf_Internal_Sym *locsyms = NULL; | |
5216 | ||
5217 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
5218 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
5219 | { | |
5220 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5221 | int expecting_tls_get_addr; | |
5222 | ||
5223 | /* Read the relocations. */ | |
4ce794b7 | 5224 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5225 | info->keep_memory); |
411e1bfb AM |
5226 | if (relstart == NULL) |
5227 | return FALSE; | |
5228 | ||
5229 | expecting_tls_get_addr = 0; | |
5230 | relend = relstart + sec->reloc_count; | |
5231 | for (rel = relstart; rel < relend; rel++) | |
5232 | { | |
5233 | enum elf_ppc64_reloc_type r_type; | |
5234 | unsigned long r_symndx; | |
5235 | struct elf_link_hash_entry *h; | |
5236 | Elf_Internal_Sym *sym; | |
5237 | asection *sym_sec; | |
e7b938ca AM |
5238 | char *tls_mask; |
5239 | char tls_set, tls_clear, tls_type = 0; | |
411e1bfb | 5240 | bfd_vma value; |
951fd09b | 5241 | bfd_boolean ok_tprel, is_local; |
411e1bfb AM |
5242 | |
5243 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5244 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, |
411e1bfb AM |
5245 | r_symndx, ibfd)) |
5246 | { | |
5247 | err_free_rel: | |
5248 | if (elf_section_data (sec)->relocs != relstart) | |
5249 | free (relstart); | |
5250 | if (locsyms != NULL | |
5251 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5252 | != (unsigned char *) locsyms)) | |
5253 | free (locsyms); | |
5254 | return FALSE; | |
5255 | } | |
5256 | ||
5257 | if (h != NULL) | |
5258 | { | |
5259 | if (h->root.type != bfd_link_hash_defined | |
5260 | && h->root.type != bfd_link_hash_defweak) | |
5261 | continue; | |
5262 | value = h->root.u.def.value; | |
5263 | } | |
5264 | else | |
5265 | value = sym->st_value; | |
951fd09b | 5266 | |
411e1bfb | 5267 | ok_tprel = FALSE; |
951fd09b AM |
5268 | is_local = FALSE; |
5269 | if (h == NULL | |
5270 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5271 | { |
951fd09b | 5272 | is_local = TRUE; |
411e1bfb AM |
5273 | value += sym_sec->output_offset; |
5274 | value += sym_sec->output_section->vma; | |
e1918d23 | 5275 | value -= htab->elf.tls_sec->vma; |
411e1bfb AM |
5276 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) |
5277 | < (bfd_vma) 1 << 32); | |
5278 | } | |
5279 | ||
4ce794b7 | 5280 | r_type = ELF64_R_TYPE (rel->r_info); |
411e1bfb AM |
5281 | switch (r_type) |
5282 | { | |
5283 | case R_PPC64_GOT_TLSLD16: | |
5284 | case R_PPC64_GOT_TLSLD16_LO: | |
5285 | case R_PPC64_GOT_TLSLD16_HI: | |
5286 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b AM |
5287 | /* These relocs should never be against a symbol |
5288 | defined in a shared lib. Leave them alone if | |
5289 | that turns out to be the case. */ | |
e717da7e | 5290 | ppc64_tlsld_got (ibfd)->refcount -= 1; |
951fd09b AM |
5291 | if (!is_local) |
5292 | continue; | |
5293 | ||
951fd09b AM |
5294 | /* LD -> LE */ |
5295 | tls_set = 0; | |
5296 | tls_clear = TLS_LD; | |
e7b938ca | 5297 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
5298 | expecting_tls_get_addr = 1; |
5299 | break; | |
5300 | ||
5301 | case R_PPC64_GOT_TLSGD16: | |
5302 | case R_PPC64_GOT_TLSGD16_LO: | |
5303 | case R_PPC64_GOT_TLSGD16_HI: | |
5304 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 5305 | if (ok_tprel) |
411e1bfb AM |
5306 | /* GD -> LE */ |
5307 | tls_set = 0; | |
5308 | else | |
5309 | /* GD -> IE */ | |
951fd09b AM |
5310 | tls_set = TLS_TLS | TLS_TPRELGD; |
5311 | tls_clear = TLS_GD; | |
e7b938ca | 5312 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
5313 | expecting_tls_get_addr = 1; |
5314 | break; | |
5315 | ||
5316 | case R_PPC64_GOT_TPREL16_DS: | |
5317 | case R_PPC64_GOT_TPREL16_LO_DS: | |
5318 | case R_PPC64_GOT_TPREL16_HI: | |
5319 | case R_PPC64_GOT_TPREL16_HA: | |
5320 | expecting_tls_get_addr = 0; | |
5321 | if (ok_tprel) | |
5322 | { | |
5323 | /* IE -> LE */ | |
5324 | tls_set = 0; | |
5325 | tls_clear = TLS_TPREL; | |
e7b938ca | 5326 | tls_type = TLS_TLS | TLS_TPREL; |
411e1bfb AM |
5327 | break; |
5328 | } | |
5329 | else | |
5330 | continue; | |
5331 | ||
5332 | case R_PPC64_REL14: | |
5333 | case R_PPC64_REL14_BRTAKEN: | |
5334 | case R_PPC64_REL14_BRNTAKEN: | |
5335 | case R_PPC64_REL24: | |
5336 | if (h != NULL | |
5337 | && h == htab->tls_get_addr) | |
5338 | { | |
5339 | if (!expecting_tls_get_addr | |
5340 | && rel != relstart | |
5341 | && ((ELF64_R_TYPE (rel[-1].r_info) | |
5342 | == R_PPC64_TOC16) | |
5343 | || (ELF64_R_TYPE (rel[-1].r_info) | |
5344 | == R_PPC64_TOC16_LO))) | |
5345 | { | |
5346 | /* Check for toc tls entries. */ | |
5347 | char *toc_tls; | |
951fd09b | 5348 | int retval; |
411e1bfb | 5349 | |
0d4792f7 | 5350 | retval = get_tls_mask (&toc_tls, NULL, &locsyms, |
951fd09b AM |
5351 | rel - 1, ibfd); |
5352 | if (retval == 0) | |
411e1bfb AM |
5353 | goto err_free_rel; |
5354 | if (toc_tls != NULL) | |
951fd09b | 5355 | expecting_tls_get_addr = retval > 1; |
411e1bfb AM |
5356 | } |
5357 | ||
5358 | if (expecting_tls_get_addr) | |
5359 | { | |
5360 | struct plt_entry *ent; | |
5361 | for (ent = h->plt.plist; ent; ent = ent->next) | |
5362 | if (ent->addend == 0) | |
5363 | { | |
5364 | if (ent->plt.refcount > 0) | |
5365 | ent->plt.refcount -= 1; | |
5366 | break; | |
5367 | } | |
5368 | } | |
5369 | } | |
5370 | expecting_tls_get_addr = 0; | |
5371 | continue; | |
5372 | ||
5373 | case R_PPC64_TPREL64: | |
5374 | expecting_tls_get_addr = 0; | |
5375 | if (ok_tprel) | |
5376 | { | |
5377 | /* IE -> LE */ | |
5378 | tls_set = TLS_EXPLICIT; | |
5379 | tls_clear = TLS_TPREL; | |
5380 | break; | |
5381 | } | |
5382 | else | |
5383 | continue; | |
5384 | ||
5385 | case R_PPC64_DTPMOD64: | |
5386 | expecting_tls_get_addr = 0; | |
951fd09b AM |
5387 | if (rel + 1 < relend |
5388 | && (rel[1].r_info | |
5389 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) | |
5390 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 5391 | { |
951fd09b | 5392 | if (ok_tprel) |
411e1bfb | 5393 | /* GD -> LE */ |
951fd09b | 5394 | tls_set = TLS_EXPLICIT | TLS_GD; |
411e1bfb AM |
5395 | else |
5396 | /* GD -> IE */ | |
951fd09b AM |
5397 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; |
5398 | tls_clear = TLS_GD; | |
411e1bfb AM |
5399 | } |
5400 | else | |
5401 | { | |
951fd09b AM |
5402 | if (!is_local) |
5403 | continue; | |
5404 | ||
5405 | /* LD -> LE */ | |
5406 | tls_set = TLS_EXPLICIT; | |
5407 | tls_clear = TLS_LD; | |
411e1bfb AM |
5408 | } |
5409 | break; | |
5410 | ||
5411 | default: | |
5412 | expecting_tls_get_addr = 0; | |
5413 | continue; | |
5414 | } | |
5415 | ||
5416 | if ((tls_set & TLS_EXPLICIT) == 0) | |
5417 | { | |
5418 | struct got_entry *ent; | |
5419 | ||
5420 | /* Adjust got entry for this reloc. */ | |
5421 | if (h != NULL) | |
5422 | ent = h->got.glist; | |
5423 | else | |
5424 | ent = elf_local_got_ents (ibfd)[r_symndx]; | |
5425 | ||
5426 | for (; ent != NULL; ent = ent->next) | |
5427 | if (ent->addend == rel->r_addend | |
e717da7e | 5428 | && ent->owner == ibfd |
e7b938ca | 5429 | && ent->tls_type == tls_type) |
411e1bfb AM |
5430 | break; |
5431 | if (ent == NULL) | |
5432 | abort (); | |
5433 | ||
5434 | if (tls_set == 0) | |
5435 | { | |
5436 | /* We managed to get rid of a got entry. */ | |
5437 | if (ent->got.refcount > 0) | |
5438 | ent->got.refcount -= 1; | |
5439 | } | |
411e1bfb AM |
5440 | } |
5441 | else if (h != NULL) | |
5442 | { | |
5443 | struct ppc_link_hash_entry * eh; | |
5444 | struct ppc_dyn_relocs **pp; | |
5445 | struct ppc_dyn_relocs *p; | |
5446 | ||
5447 | /* Adjust dynamic relocs. */ | |
5448 | eh = (struct ppc_link_hash_entry *) h; | |
5449 | for (pp = &eh->dyn_relocs; | |
5450 | (p = *pp) != NULL; | |
5451 | pp = &p->next) | |
5452 | if (p->sec == sec) | |
5453 | { | |
5454 | /* If we got rid of a DTPMOD/DTPREL reloc | |
5455 | pair then we'll lose one or two dyn | |
5456 | relocs. */ | |
951fd09b | 5457 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
411e1bfb | 5458 | p->count -= 1; |
951fd09b | 5459 | p->count -= 1; |
411e1bfb AM |
5460 | if (p->count == 0) |
5461 | *pp = p->next; | |
5462 | break; | |
5463 | } | |
5464 | } | |
5465 | ||
e7b938ca AM |
5466 | *tls_mask |= tls_set; |
5467 | *tls_mask &= ~tls_clear; | |
411e1bfb AM |
5468 | } |
5469 | ||
5470 | if (elf_section_data (sec)->relocs != relstart) | |
5471 | free (relstart); | |
5472 | } | |
5473 | ||
5474 | if (locsyms != NULL | |
5475 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5476 | != (unsigned char *) locsyms)) | |
6cdc0ccc AM |
5477 | { |
5478 | if (!info->keep_memory) | |
411e1bfb | 5479 | free (locsyms); |
6cdc0ccc | 5480 | else |
411e1bfb | 5481 | elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; |
6cdc0ccc | 5482 | } |
1e2f5b6e | 5483 | } |
b34976b6 | 5484 | return TRUE; |
1e2f5b6e | 5485 | } |
b34976b6 | 5486 | |
65f38f15 AM |
5487 | /* This is the condition under which ppc64_elf_finish_dynamic_symbol |
5488 | will be called from elflink.h. If elflink.h doesn't call our | |
5489 | finish_dynamic_symbol routine, we'll need to do something about | |
5490 | initializing any .plt and .got entries in ppc64_elf_relocate_section. */ | |
f4656909 | 5491 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \ |
65f38f15 | 5492 | ((DYN) \ |
f4656909 | 5493 | && ((SHARED) \ |
65f38f15 AM |
5494 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ |
5495 | && ((H)->dynindx != -1 \ | |
5496 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
5bd4f169 | 5497 | |
65f38f15 AM |
5498 | /* Allocate space in .plt, .got and associated reloc sections for |
5499 | dynamic relocs. */ | |
5bd4f169 | 5500 | |
b34976b6 | 5501 | static bfd_boolean |
4ce794b7 | 5502 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 5503 | { |
65f38f15 AM |
5504 | struct bfd_link_info *info; |
5505 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 5506 | asection *s; |
65f38f15 AM |
5507 | struct ppc_link_hash_entry *eh; |
5508 | struct ppc_dyn_relocs *p; | |
411e1bfb | 5509 | struct got_entry *gent; |
5bd4f169 | 5510 | |
e92d460e | 5511 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5512 | return TRUE; |
5bd4f169 | 5513 | |
e92d460e AM |
5514 | if (h->root.type == bfd_link_hash_warning) |
5515 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5516 | ||
65f38f15 AM |
5517 | info = (struct bfd_link_info *) inf; |
5518 | htab = ppc_hash_table (info); | |
5bd4f169 | 5519 | |
65f38f15 | 5520 | if (htab->elf.dynamic_sections_created |
411e1bfb | 5521 | && h->dynindx != -1 |
9c7a29a3 | 5522 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) |
5bd4f169 | 5523 | { |
411e1bfb AM |
5524 | struct plt_entry *pent; |
5525 | bfd_boolean doneone = FALSE; | |
5526 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) | |
5527 | if (pent->plt.refcount > 0) | |
5528 | { | |
5529 | BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor); | |
5530 | ||
5531 | /* If this is the first .plt entry, make room for the special | |
5532 | first entry. */ | |
4ce794b7 | 5533 | s = htab->plt; |
411e1bfb AM |
5534 | if (s->_raw_size == 0) |
5535 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; | |
5536 | ||
5537 | pent->plt.offset = s->_raw_size; | |
5538 | ||
5539 | /* Make room for this entry. */ | |
5540 | s->_raw_size += PLT_ENTRY_SIZE; | |
5541 | ||
5542 | /* Make room for the .glink code. */ | |
4ce794b7 | 5543 | s = htab->glink; |
411e1bfb AM |
5544 | if (s->_raw_size == 0) |
5545 | s->_raw_size += GLINK_CALL_STUB_SIZE; | |
5546 | /* We need bigger stubs past index 32767. */ | |
5547 | if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4) | |
5548 | s->_raw_size += 4; | |
5549 | s->_raw_size += 2*4; | |
5550 | ||
5551 | /* We also need to make an entry in the .rela.plt section. */ | |
4ce794b7 | 5552 | s = htab->relplt; |
411e1bfb AM |
5553 | s->_raw_size += sizeof (Elf64_External_Rela); |
5554 | doneone = TRUE; | |
5555 | } | |
5556 | else | |
5557 | pent->plt.offset = (bfd_vma) -1; | |
5558 | if (!doneone) | |
65f38f15 | 5559 | { |
411e1bfb | 5560 | h->plt.plist = NULL; |
65f38f15 AM |
5561 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5562 | } | |
5563 | } | |
5564 | else | |
5565 | { | |
411e1bfb | 5566 | h->plt.plist = NULL; |
65f38f15 AM |
5567 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5568 | } | |
5569 | ||
951fd09b AM |
5570 | eh = (struct ppc_link_hash_entry *) h; |
5571 | /* Run through the TLS GD got entries first if we're changing them | |
5572 | to TPREL. */ | |
e7b938ca | 5573 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
951fd09b AM |
5574 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5575 | if (gent->got.refcount > 0 | |
5576 | && (gent->tls_type & TLS_GD) != 0) | |
5577 | { | |
5578 | /* This was a GD entry that has been converted to TPREL. If | |
5579 | there happens to be a TPREL entry we can use that one. */ | |
5580 | struct got_entry *ent; | |
5581 | for (ent = h->got.glist; ent != NULL; ent = ent->next) | |
5582 | if (ent->got.refcount > 0 | |
5583 | && (ent->tls_type & TLS_TPREL) != 0 | |
e717da7e AM |
5584 | && ent->addend == gent->addend |
5585 | && ent->owner == gent->owner) | |
951fd09b AM |
5586 | { |
5587 | gent->got.refcount = 0; | |
5588 | break; | |
5589 | } | |
5590 | ||
5591 | /* If not, then we'll be using our own TPREL entry. */ | |
5592 | if (gent->got.refcount != 0) | |
5593 | gent->tls_type = TLS_TLS | TLS_TPREL; | |
5594 | } | |
5595 | ||
411e1bfb AM |
5596 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5597 | if (gent->got.refcount > 0) | |
5598 | { | |
951fd09b AM |
5599 | bfd_boolean dyn; |
5600 | ||
411e1bfb | 5601 | /* Make sure this symbol is output as a dynamic symbol. |
951fd09b AM |
5602 | Undefined weak syms won't yet be marked as dynamic, |
5603 | nor will all TLS symbols. */ | |
411e1bfb AM |
5604 | if (h->dynindx == -1 |
5605 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5606 | { | |
5607 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
5608 | return FALSE; | |
5609 | } | |
65f38f15 | 5610 | |
d881513a AM |
5611 | if ((gent->tls_type & TLS_LD) != 0 |
5612 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5613 | { |
e717da7e | 5614 | gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; |
951fd09b | 5615 | continue; |
411e1bfb | 5616 | } |
951fd09b | 5617 | |
e717da7e | 5618 | s = ppc64_elf_tdata (gent->owner)->got; |
951fd09b | 5619 | gent->got.offset = s->_raw_size; |
d881513a AM |
5620 | s->_raw_size |
5621 | += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; | |
951fd09b | 5622 | dyn = htab->elf.dynamic_sections_created; |
4e795f50 AM |
5623 | if ((info->shared |
5624 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
5625 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5626 | || h->root.type != bfd_link_hash_undefweak)) | |
e717da7e | 5627 | ppc64_elf_tdata (gent->owner)->relgot->_raw_size |
e7b938ca | 5628 | += (gent->tls_type & eh->tls_mask & TLS_GD |
951fd09b AM |
5629 | ? 2 * sizeof (Elf64_External_Rela) |
5630 | : sizeof (Elf64_External_Rela)); | |
411e1bfb AM |
5631 | } |
5632 | else | |
5633 | gent->got.offset = (bfd_vma) -1; | |
65f38f15 | 5634 | |
65f38f15 | 5635 | if (eh->dyn_relocs == NULL) |
b34976b6 | 5636 | return TRUE; |
65f38f15 AM |
5637 | |
5638 | /* In the shared -Bsymbolic case, discard space allocated for | |
5639 | dynamic pc-relative relocs against symbols which turn out to be | |
5640 | defined in regular objects. For the normal shared case, discard | |
5641 | space for relocs that have become local due to symbol visibility | |
5642 | changes. */ | |
5643 | ||
5644 | if (info->shared) | |
5645 | { | |
9c7a29a3 AM |
5646 | /* Relocs that use pc_count are those that appear on a call insn, |
5647 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | |
5648 | generated via assembly. We want calls to protected symbols to | |
5649 | resolve directly to the function rather than going via the plt. | |
5650 | If people want function pointer comparisons to work as expected | |
5651 | then they should avoid writing weird assembly. */ | |
09695f56 | 5652 | if (SYMBOL_CALLS_LOCAL (info, h)) |
65f38f15 AM |
5653 | { |
5654 | struct ppc_dyn_relocs **pp; | |
5655 | ||
5656 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 5657 | { |
65f38f15 AM |
5658 | p->count -= p->pc_count; |
5659 | p->pc_count = 0; | |
5660 | if (p->count == 0) | |
5661 | *pp = p->next; | |
5662 | else | |
5663 | pp = &p->next; | |
5bd4f169 | 5664 | } |
65f38f15 | 5665 | } |
4e795f50 AM |
5666 | |
5667 | /* Also discard relocs on undefined weak syms with non-default | |
5668 | visibility. */ | |
5669 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
5670 | && h->root.type == bfd_link_hash_undefweak) | |
5671 | eh->dyn_relocs = NULL; | |
65f38f15 | 5672 | } |
f4656909 | 5673 | else if (ELIMINATE_COPY_RELOCS) |
65f38f15 AM |
5674 | { |
5675 | /* For the non-shared case, discard space for relocs against | |
5676 | symbols which turn out to need copy relocs or are not | |
5677 | dynamic. */ | |
5678 | ||
5679 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
5680 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
5681 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
65f38f15 AM |
5682 | { |
5683 | /* Make sure this symbol is output as a dynamic symbol. | |
5684 | Undefined weak syms won't yet be marked as dynamic. */ | |
5685 | if (h->dynindx == -1 | |
5686 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5687 | { | |
ec338859 | 5688 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
b34976b6 | 5689 | return FALSE; |
65f38f15 AM |
5690 | } |
5691 | ||
5692 | /* If that succeeded, we know we'll be keeping all the | |
5693 | relocs. */ | |
5694 | if (h->dynindx != -1) | |
5695 | goto keep; | |
5696 | } | |
5697 | ||
5698 | eh->dyn_relocs = NULL; | |
5699 | ||
ec338859 | 5700 | keep: ; |
65f38f15 AM |
5701 | } |
5702 | ||
5703 | /* Finally, allocate space. */ | |
5704 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5705 | { | |
5706 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
5707 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
5708 | } | |
5709 | ||
b34976b6 | 5710 | return TRUE; |
65f38f15 AM |
5711 | } |
5712 | ||
5713 | /* Find any dynamic relocs that apply to read-only sections. */ | |
5714 | ||
b34976b6 | 5715 | static bfd_boolean |
4ce794b7 | 5716 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
65f38f15 AM |
5717 | { |
5718 | struct ppc_link_hash_entry *eh; | |
5719 | struct ppc_dyn_relocs *p; | |
5720 | ||
e92d460e AM |
5721 | if (h->root.type == bfd_link_hash_warning) |
5722 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5723 | ||
65f38f15 AM |
5724 | eh = (struct ppc_link_hash_entry *) h; |
5725 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5726 | { | |
5727 | asection *s = p->sec->output_section; | |
5728 | ||
5729 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
5730 | { | |
4ce794b7 | 5731 | struct bfd_link_info *info = inf; |
65f38f15 AM |
5732 | |
5733 | info->flags |= DF_TEXTREL; | |
5734 | ||
5735 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 5736 | return FALSE; |
65f38f15 AM |
5737 | } |
5738 | } | |
b34976b6 | 5739 | return TRUE; |
65f38f15 AM |
5740 | } |
5741 | ||
5742 | /* Set the sizes of the dynamic sections. */ | |
5743 | ||
b34976b6 | 5744 | static bfd_boolean |
4ce794b7 AM |
5745 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
5746 | struct bfd_link_info *info) | |
65f38f15 AM |
5747 | { |
5748 | struct ppc_link_hash_table *htab; | |
5749 | bfd *dynobj; | |
5750 | asection *s; | |
b34976b6 | 5751 | bfd_boolean relocs; |
65f38f15 AM |
5752 | bfd *ibfd; |
5753 | ||
5754 | htab = ppc_hash_table (info); | |
5755 | dynobj = htab->elf.dynobj; | |
5756 | if (dynobj == NULL) | |
5757 | abort (); | |
5758 | ||
5759 | if (htab->elf.dynamic_sections_created) | |
5760 | { | |
5761 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 5762 | if (info->executable) |
65f38f15 AM |
5763 | { |
5764 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
5765 | if (s == NULL) | |
5766 | abort (); | |
5767 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5768 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
5769 | } | |
5770 | } | |
5771 | ||
5772 | /* Set up .got offsets for local syms, and space for local dynamic | |
5773 | relocs. */ | |
5774 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
5775 | { | |
411e1bfb AM |
5776 | struct got_entry **lgot_ents; |
5777 | struct got_entry **end_lgot_ents; | |
e7b938ca | 5778 | char *lgot_masks; |
65f38f15 AM |
5779 | bfd_size_type locsymcount; |
5780 | Elf_Internal_Shdr *symtab_hdr; | |
5781 | asection *srel; | |
5782 | ||
5783 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
5784 | continue; | |
5785 | ||
e717da7e AM |
5786 | if (ppc64_tlsld_got (ibfd)->refcount > 0) |
5787 | { | |
5788 | s = ppc64_elf_tdata (ibfd)->got; | |
5789 | ppc64_tlsld_got (ibfd)->offset = s->_raw_size; | |
5790 | s->_raw_size += 16; | |
5791 | if (info->shared) | |
5792 | { | |
5793 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
5794 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5795 | } | |
5796 | } | |
5797 | else | |
5798 | ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; | |
5799 | ||
65f38f15 AM |
5800 | for (s = ibfd->sections; s != NULL; s = s->next) |
5801 | { | |
ec338859 | 5802 | struct ppc_dyn_relocs *p; |
65f38f15 | 5803 | |
ec338859 AM |
5804 | for (p = *((struct ppc_dyn_relocs **) |
5805 | &elf_section_data (s)->local_dynrel); | |
5806 | p != NULL; | |
5807 | p = p->next) | |
65f38f15 | 5808 | { |
ec338859 AM |
5809 | if (!bfd_is_abs_section (p->sec) |
5810 | && bfd_is_abs_section (p->sec->output_section)) | |
5811 | { | |
5812 | /* Input section has been discarded, either because | |
5813 | it is a copy of a linkonce section or due to | |
5814 | linker script /DISCARD/, so we'll be discarding | |
5815 | the relocs too. */ | |
5816 | } | |
248866a8 | 5817 | else if (p->count != 0) |
ec338859 AM |
5818 | { |
5819 | srel = elf_section_data (p->sec)->sreloc; | |
5820 | srel->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
248866a8 AM |
5821 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
5822 | info->flags |= DF_TEXTREL; | |
ec338859 | 5823 | } |
65f38f15 AM |
5824 | } |
5825 | } | |
5826 | ||
411e1bfb AM |
5827 | lgot_ents = elf_local_got_ents (ibfd); |
5828 | if (!lgot_ents) | |
65f38f15 AM |
5829 | continue; |
5830 | ||
5831 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5832 | locsymcount = symtab_hdr->sh_info; | |
411e1bfb | 5833 | end_lgot_ents = lgot_ents + locsymcount; |
e7b938ca | 5834 | lgot_masks = (char *) end_lgot_ents; |
e717da7e AM |
5835 | s = ppc64_elf_tdata (ibfd)->got; |
5836 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
e7b938ca | 5837 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
65f38f15 | 5838 | { |
411e1bfb AM |
5839 | struct got_entry *ent; |
5840 | ||
5841 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) | |
5842 | if (ent->got.refcount > 0) | |
5843 | { | |
e7b938ca | 5844 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
411e1bfb | 5845 | { |
e717da7e | 5846 | if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) |
411e1bfb | 5847 | { |
e717da7e | 5848 | ppc64_tlsld_got (ibfd)->offset = s->_raw_size; |
411e1bfb AM |
5849 | s->_raw_size += 16; |
5850 | if (info->shared) | |
5851 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5852 | } | |
e717da7e | 5853 | ent->got.offset = ppc64_tlsld_got (ibfd)->offset; |
411e1bfb AM |
5854 | } |
5855 | else | |
5856 | { | |
5857 | ent->got.offset = s->_raw_size; | |
e7b938ca | 5858 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
411e1bfb AM |
5859 | { |
5860 | s->_raw_size += 16; | |
5861 | if (info->shared) | |
5862 | srel->_raw_size += 2 * sizeof (Elf64_External_Rela); | |
5863 | } | |
5864 | else | |
5865 | { | |
5866 | s->_raw_size += 8; | |
5867 | if (info->shared) | |
5868 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5869 | } | |
5870 | } | |
5871 | } | |
5872 | else | |
5873 | ent->got.offset = (bfd_vma) -1; | |
65f38f15 AM |
5874 | } |
5875 | } | |
5876 | ||
5877 | /* Allocate global sym .plt and .got entries, and space for global | |
5878 | sym dynamic relocs. */ | |
4ce794b7 | 5879 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
65f38f15 AM |
5880 | |
5881 | /* We now have determined the sizes of the various dynamic sections. | |
5882 | Allocate memory for them. */ | |
b34976b6 | 5883 | relocs = FALSE; |
65f38f15 AM |
5884 | for (s = dynobj->sections; s != NULL; s = s->next) |
5885 | { | |
5886 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
5887 | continue; | |
5888 | ||
411e1bfb AM |
5889 | /* Reset _cooked_size since prelim layout will set it wrongly, |
5890 | and a non-zero _cooked_size sticks. */ | |
5891 | s->_cooked_size = 0; | |
5892 | ||
4ce794b7 | 5893 | if (s == htab->brlt || s == htab->relbrlt) |
721956f4 AM |
5894 | /* These haven't been allocated yet; don't strip. */ |
5895 | continue; | |
e717da7e AM |
5896 | else if (s == htab->got |
5897 | || s == htab->plt | |
4ce794b7 | 5898 | || s == htab->glink) |
65f38f15 AM |
5899 | { |
5900 | /* Strip this section if we don't need it; see the | |
5901 | comment below. */ | |
5bd4f169 | 5902 | } |
65f38f15 | 5903 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 AM |
5904 | { |
5905 | if (s->_raw_size == 0) | |
5906 | { | |
5907 | /* If we don't need this section, strip it from the | |
5908 | output file. This is mostly to handle .rela.bss and | |
5909 | .rela.plt. We must create both sections in | |
5910 | create_dynamic_sections, because they must be created | |
5911 | before the linker maps input sections to output | |
5912 | sections. The linker does that before | |
5913 | adjust_dynamic_symbol is called, and it is that | |
5914 | function which decides whether anything needs to go | |
5915 | into these sections. */ | |
5bd4f169 AM |
5916 | } |
5917 | else | |
5918 | { | |
4ce794b7 | 5919 | if (s != htab->relplt) |
b34976b6 | 5920 | relocs = TRUE; |
5bd4f169 AM |
5921 | |
5922 | /* We use the reloc_count field as a counter if we need | |
5923 | to copy relocs into the output file. */ | |
5924 | s->reloc_count = 0; | |
5925 | } | |
5926 | } | |
65f38f15 | 5927 | else |
5bd4f169 AM |
5928 | { |
5929 | /* It's not one of our sections, so don't allocate space. */ | |
5930 | continue; | |
5931 | } | |
5932 | ||
65f38f15 | 5933 | if (s->_raw_size == 0) |
5bd4f169 AM |
5934 | { |
5935 | _bfd_strip_section_from_output (info, s); | |
5936 | continue; | |
5937 | } | |
5938 | ||
5f333394 AM |
5939 | /* .plt is in the bss section. We don't initialise it. */ |
5940 | if ((s->flags & SEC_LOAD) == 0) | |
5941 | continue; | |
5942 | ||
65f38f15 AM |
5943 | /* Allocate memory for the section contents. We use bfd_zalloc |
5944 | here in case unused entries are not reclaimed before the | |
5945 | section's contents are written out. This should not happen, | |
411e1bfb AM |
5946 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
5947 | sections instead of garbage. | |
5948 | We also rely on the section contents being zero when writing | |
5949 | the GOT. */ | |
4ce794b7 | 5950 | s->contents = bfd_zalloc (dynobj, s->_raw_size); |
65f38f15 | 5951 | if (s->contents == NULL) |
b34976b6 | 5952 | return FALSE; |
5bd4f169 AM |
5953 | } |
5954 | ||
e717da7e AM |
5955 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5956 | { | |
5957 | s = ppc64_elf_tdata (ibfd)->got; | |
5958 | if (s != NULL && s != htab->got) | |
5959 | { | |
5960 | s->_cooked_size = 0; | |
5961 | if (s->_raw_size == 0) | |
5962 | _bfd_strip_section_from_output (info, s); | |
5963 | else | |
5964 | { | |
5965 | s->contents = bfd_zalloc (ibfd, s->_raw_size); | |
5966 | if (s->contents == NULL) | |
5967 | return FALSE; | |
5968 | } | |
5969 | } | |
5970 | s = ppc64_elf_tdata (ibfd)->relgot; | |
5971 | if (s != NULL) | |
5972 | { | |
5973 | s->_cooked_size = 0; | |
5974 | if (s->_raw_size == 0) | |
5975 | _bfd_strip_section_from_output (info, s); | |
5976 | else | |
5977 | { | |
5978 | s->contents = bfd_zalloc (ibfd, s->_raw_size); | |
5979 | if (s->contents == NULL) | |
5980 | return FALSE; | |
5981 | relocs = TRUE; | |
5982 | s->reloc_count = 0; | |
5983 | } | |
5984 | } | |
5985 | } | |
5986 | ||
e86ce104 | 5987 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
5988 | { |
5989 | /* Add some entries to the .dynamic section. We fill in the | |
5990 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
5991 | must add the entries now so that we get the correct size for | |
5992 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5993 | dynamic linker and used by the debugger. */ | |
dc810e39 | 5994 | #define add_dynamic_entry(TAG, VAL) \ |
4ce794b7 | 5995 | bfd_elf64_add_dynamic_entry (info, (TAG), (VAL)) |
dc810e39 | 5996 | |
36af4a4e | 5997 | if (info->executable) |
5bd4f169 | 5998 | { |
dc810e39 | 5999 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 6000 | return FALSE; |
5bd4f169 AM |
6001 | } |
6002 | ||
4ce794b7 | 6003 | if (htab->plt != NULL && htab->plt->_raw_size != 0) |
5bd4f169 | 6004 | { |
dc810e39 AM |
6005 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
6006 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
6007 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
6008 | || !add_dynamic_entry (DT_JMPREL, 0) |
6009 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 6010 | return FALSE; |
5bd4f169 AM |
6011 | } |
6012 | ||
19397422 AM |
6013 | if (NO_OPD_RELOCS) |
6014 | { | |
6015 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
6016 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 6017 | return FALSE; |
19397422 AM |
6018 | } |
6019 | ||
5bd4f169 AM |
6020 | if (relocs) |
6021 | { | |
dc810e39 AM |
6022 | if (!add_dynamic_entry (DT_RELA, 0) |
6023 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6024 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 6025 | return FALSE; |
5bd4f169 | 6026 | |
65f38f15 AM |
6027 | /* If any dynamic relocs apply to a read-only section, |
6028 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 6029 | if ((info->flags & DF_TEXTREL) == 0) |
4ce794b7 | 6030 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
5bd4f169 | 6031 | |
65f38f15 | 6032 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 6033 | { |
65f38f15 | 6034 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 6035 | return FALSE; |
5bd4f169 | 6036 | } |
5bd4f169 | 6037 | } |
5bd4f169 | 6038 | } |
65f38f15 | 6039 | #undef add_dynamic_entry |
5bd4f169 | 6040 | |
b34976b6 | 6041 | return TRUE; |
5bd4f169 AM |
6042 | } |
6043 | ||
721956f4 | 6044 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 6045 | |
4ce794b7 AM |
6046 | static inline enum ppc_stub_type |
6047 | ppc_type_of_stub (asection *input_sec, | |
6048 | const Elf_Internal_Rela *rel, | |
6049 | struct ppc_link_hash_entry **hash, | |
6050 | bfd_vma destination) | |
5bd4f169 | 6051 | { |
721956f4 AM |
6052 | struct ppc_link_hash_entry *h = *hash; |
6053 | bfd_vma location; | |
6054 | bfd_vma branch_offset; | |
6055 | bfd_vma max_branch_offset; | |
4ce794b7 | 6056 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 | 6057 | |
721956f4 AM |
6058 | if (h != NULL) |
6059 | { | |
6060 | if (h->oh != NULL | |
721956f4 | 6061 | && h->oh->dynindx != -1) |
5bd4f169 | 6062 | { |
411e1bfb AM |
6063 | struct plt_entry *ent; |
6064 | for (ent = h->oh->plt.plist; ent != NULL; ent = ent->next) | |
6065 | if (ent->addend == rel->r_addend | |
6066 | && ent->plt.offset != (bfd_vma) -1) | |
6067 | { | |
6068 | *hash = (struct ppc_link_hash_entry *) h->oh; | |
6069 | return ppc_stub_plt_call; | |
6070 | } | |
5bd4f169 AM |
6071 | } |
6072 | ||
ee7de3e6 AM |
6073 | if (!(h->elf.root.type == bfd_link_hash_defined |
6074 | || h->elf.root.type == bfd_link_hash_defweak) | |
6075 | || h->elf.root.u.def.section->output_section == NULL) | |
721956f4 | 6076 | return ppc_stub_none; |
5d1634d7 | 6077 | } |
5d1634d7 | 6078 | |
721956f4 AM |
6079 | /* Determine where the call point is. */ |
6080 | location = (input_sec->output_offset | |
6081 | + input_sec->output_section->vma | |
6082 | + rel->r_offset); | |
5d1634d7 | 6083 | |
721956f4 AM |
6084 | branch_offset = destination - location; |
6085 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 6086 | |
721956f4 AM |
6087 | /* Determine if a long branch stub is needed. */ |
6088 | max_branch_offset = 1 << 25; | |
4ce794b7 | 6089 | if (r_type != R_PPC64_REL24) |
721956f4 | 6090 | max_branch_offset = 1 << 15; |
5d1634d7 | 6091 | |
721956f4 AM |
6092 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
6093 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
6094 | is needed later. */ | |
6095 | return ppc_stub_long_branch; | |
5d1634d7 | 6096 | |
721956f4 | 6097 | return ppc_stub_none; |
5d1634d7 AM |
6098 | } |
6099 | ||
6100 | /* Build a .plt call stub. */ | |
6101 | ||
4ce794b7 AM |
6102 | static inline bfd_byte * |
6103 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset) | |
5d1634d7 AM |
6104 | { |
6105 | #define PPC_LO(v) ((v) & 0xffff) | |
6106 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6107 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6108 | ||
5d1634d7 | 6109 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
ad8e1ba5 | 6110 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
5d1634d7 AM |
6111 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
6112 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6113 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6114 | offset += 8; |
6115 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
6116 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6117 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6118 | offset += 8; |
6119 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
6120 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
6121 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
6122 | return p; | |
6123 | } | |
6124 | ||
b34976b6 | 6125 | static bfd_boolean |
4ce794b7 | 6126 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
5d1634d7 | 6127 | { |
721956f4 AM |
6128 | struct ppc_stub_hash_entry *stub_entry; |
6129 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
6130 | struct bfd_link_info *info; |
6131 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
6132 | bfd_byte *loc; |
6133 | bfd_byte *p; | |
6134 | unsigned int indx; | |
411e1bfb | 6135 | struct plt_entry *ent; |
721956f4 AM |
6136 | bfd_vma off; |
6137 | int size; | |
5d1634d7 | 6138 | |
721956f4 AM |
6139 | /* Massage our args to the form they really have. */ |
6140 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6141 | info = in_arg; |
5d1634d7 | 6142 | |
5d1634d7 AM |
6143 | htab = ppc_hash_table (info); |
6144 | ||
721956f4 | 6145 | /* Make a note of the offset within the stubs for this entry. */ |
97b639ba AM |
6146 | stub_entry->stub_offset = stub_entry->stub_sec->_cooked_size; |
6147 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; | |
721956f4 | 6148 | |
4ce794b7 | 6149 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
721956f4 | 6150 | switch (stub_entry->stub_type) |
5d1634d7 | 6151 | { |
721956f4 | 6152 | case ppc_stub_long_branch: |
ad8e1ba5 | 6153 | case ppc_stub_long_branch_r2off: |
721956f4 AM |
6154 | /* Branches are relative. This is where we are going to. */ |
6155 | off = (stub_entry->target_value | |
6156 | + stub_entry->target_section->output_offset | |
6157 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 6158 | |
721956f4 AM |
6159 | /* And this is where we are coming from. */ |
6160 | off -= (stub_entry->stub_offset | |
97b639ba AM |
6161 | + stub_entry->stub_sec->output_offset |
6162 | + stub_entry->stub_sec->output_section->vma); | |
e86ce104 | 6163 | |
ad8e1ba5 AM |
6164 | if (stub_entry->stub_type != ppc_stub_long_branch_r2off) |
6165 | size = 4; | |
6166 | else | |
6167 | { | |
6168 | bfd_vma r2off; | |
6169 | ||
6170 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6171 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6172 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6173 | loc += 4; |
97b639ba | 6174 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6175 | loc += 4; |
97b639ba | 6176 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6177 | loc += 4; |
6178 | off -= 12; | |
6179 | size = 16; | |
6180 | } | |
97b639ba | 6181 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
ad8e1ba5 AM |
6182 | |
6183 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); | |
721956f4 | 6184 | break; |
e86ce104 | 6185 | |
721956f4 | 6186 | case ppc_stub_plt_branch: |
ad8e1ba5 | 6187 | case ppc_stub_plt_branch_r2off: |
721956f4 AM |
6188 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
6189 | stub_entry->root.string + 9, | |
b34976b6 | 6190 | FALSE, FALSE); |
721956f4 AM |
6191 | if (br_entry == NULL) |
6192 | { | |
6193 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), | |
6194 | stub_entry->root.string + 9); | |
b34976b6 AM |
6195 | htab->stub_error = TRUE; |
6196 | return FALSE; | |
721956f4 AM |
6197 | } |
6198 | ||
6199 | off = (stub_entry->target_value | |
6200 | + stub_entry->target_section->output_offset | |
6201 | + stub_entry->target_section->output_section->vma); | |
6202 | ||
4ce794b7 AM |
6203 | bfd_put_64 (htab->brlt->owner, off, |
6204 | htab->brlt->contents + br_entry->offset); | |
721956f4 AM |
6205 | |
6206 | if (info->shared) | |
6207 | { | |
6208 | /* Create a reloc for the branch lookup table entry. */ | |
6209 | Elf_Internal_Rela rela; | |
ad8e1ba5 | 6210 | bfd_byte *rl; |
5d1634d7 | 6211 | |
721956f4 | 6212 | rela.r_offset = (br_entry->offset |
4ce794b7 AM |
6213 | + htab->brlt->output_offset |
6214 | + htab->brlt->output_section->vma); | |
721956f4 AM |
6215 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
6216 | rela.r_addend = off; | |
6217 | ||
4ce794b7 AM |
6218 | rl = htab->relbrlt->contents; |
6219 | rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela); | |
6220 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); | |
721956f4 AM |
6221 | } |
6222 | ||
6223 | off = (br_entry->offset | |
4ce794b7 AM |
6224 | + htab->brlt->output_offset |
6225 | + htab->brlt->output_section->vma | |
6226 | - elf_gp (htab->brlt->output_section->owner) | |
ad8e1ba5 | 6227 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6228 | |
ad8e1ba5 | 6229 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
5d1634d7 AM |
6230 | { |
6231 | (*_bfd_error_handler) | |
e86ce104 | 6232 | (_("linkage table error against `%s'"), |
721956f4 | 6233 | stub_entry->root.string); |
5d1634d7 | 6234 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
6235 | htab->stub_error = TRUE; |
6236 | return FALSE; | |
5d1634d7 | 6237 | } |
41bd81ab | 6238 | |
721956f4 | 6239 | indx = off; |
ad8e1ba5 AM |
6240 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
6241 | { | |
97b639ba | 6242 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6243 | loc += 4; |
97b639ba | 6244 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 AM |
6245 | size = 16; |
6246 | } | |
6247 | else | |
6248 | { | |
6249 | bfd_vma r2off; | |
6250 | ||
6251 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6252 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6253 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6254 | loc += 4; |
97b639ba | 6255 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6256 | loc += 4; |
97b639ba | 6257 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 | 6258 | loc += 4; |
97b639ba | 6259 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6260 | loc += 4; |
97b639ba | 6261 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6262 | size = 28; |
6263 | } | |
6264 | loc += 4; | |
97b639ba | 6265 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
ad8e1ba5 | 6266 | loc += 4; |
97b639ba | 6267 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
721956f4 | 6268 | break; |
5d1634d7 | 6269 | |
721956f4 | 6270 | case ppc_stub_plt_call: |
c862ae31 AM |
6271 | /* Do the best we can for shared libraries built without |
6272 | exporting ".foo" for each "foo". This can happen when symbol | |
6273 | versioning scripts strip all bar a subset of symbols. */ | |
6274 | if (stub_entry->h->oh->root.type != bfd_link_hash_defined | |
6275 | && stub_entry->h->oh->root.type != bfd_link_hash_defweak) | |
6276 | { | |
6277 | /* Point the symbol at the stub. There may be multiple stubs, | |
6278 | we don't really care; The main thing is to make this sym | |
8f3bab57 AM |
6279 | defined somewhere. Maybe defining the symbol in the stub |
6280 | section is a silly idea. If we didn't do this, htab->top_id | |
6281 | could disappear. */ | |
c862ae31 AM |
6282 | stub_entry->h->oh->root.type = bfd_link_hash_defined; |
6283 | stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec; | |
6284 | stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset; | |
6285 | } | |
6286 | ||
721956f4 | 6287 | /* Now build the stub. */ |
411e1bfb AM |
6288 | off = (bfd_vma) -1; |
6289 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) | |
6290 | if (ent->addend == stub_entry->addend) | |
6291 | { | |
6292 | off = ent->plt.offset; | |
6293 | break; | |
6294 | } | |
721956f4 AM |
6295 | if (off >= (bfd_vma) -2) |
6296 | abort (); | |
6297 | ||
6298 | off &= ~ (bfd_vma) 1; | |
4ce794b7 AM |
6299 | off += (htab->plt->output_offset |
6300 | + htab->plt->output_section->vma | |
6301 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6302 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6303 | |
ad8e1ba5 | 6304 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
721956f4 AM |
6305 | { |
6306 | (*_bfd_error_handler) | |
6307 | (_("linkage table error against `%s'"), | |
6308 | stub_entry->h->elf.root.root.string); | |
6309 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 AM |
6310 | htab->stub_error = TRUE; |
6311 | return FALSE; | |
721956f4 AM |
6312 | } |
6313 | ||
97b639ba | 6314 | p = build_plt_stub (htab->stub_bfd, loc, off); |
721956f4 AM |
6315 | size = p - loc; |
6316 | break; | |
6317 | ||
6318 | default: | |
6319 | BFD_FAIL (); | |
b34976b6 | 6320 | return FALSE; |
721956f4 AM |
6321 | } |
6322 | ||
97b639ba AM |
6323 | stub_entry->stub_sec->_cooked_size += size; |
6324 | ||
6325 | if (htab->emit_stub_syms | |
6326 | && !(stub_entry->stub_type == ppc_stub_plt_call | |
6327 | && stub_entry->h->oh->root.type == bfd_link_hash_defined | |
6328 | && stub_entry->h->oh->root.u.def.section == stub_entry->stub_sec | |
6329 | && stub_entry->h->oh->root.u.def.value == stub_entry->stub_offset)) | |
6330 | { | |
6331 | struct elf_link_hash_entry *h; | |
6332 | h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string, | |
6333 | TRUE, FALSE, FALSE); | |
6334 | if (h == NULL) | |
6335 | return FALSE; | |
6336 | if (h->root.type == bfd_link_hash_new) | |
6337 | { | |
6338 | h->root.type = bfd_link_hash_defined; | |
6339 | h->root.u.def.section = stub_entry->stub_sec; | |
6340 | h->root.u.def.value = stub_entry->stub_offset; | |
6341 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
6342 | | ELF_LINK_HASH_DEF_REGULAR | |
6343 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
6344 | | ELF_LINK_FORCED_LOCAL); | |
6345 | } | |
6346 | } | |
6347 | ||
b34976b6 | 6348 | return TRUE; |
721956f4 AM |
6349 | } |
6350 | ||
6351 | /* As above, but don't actually build the stub. Just bump offset so | |
6352 | we know stub section sizes, and select plt_branch stubs where | |
6353 | long_branch stubs won't do. */ | |
6354 | ||
b34976b6 | 6355 | static bfd_boolean |
4ce794b7 | 6356 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
721956f4 AM |
6357 | { |
6358 | struct ppc_stub_hash_entry *stub_entry; | |
63bc6f6c | 6359 | struct bfd_link_info *info; |
721956f4 AM |
6360 | struct ppc_link_hash_table *htab; |
6361 | bfd_vma off; | |
6362 | int size; | |
6363 | ||
6364 | /* Massage our args to the form they really have. */ | |
6365 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
63bc6f6c AM |
6366 | info = in_arg; |
6367 | ||
6368 | htab = ppc_hash_table (info); | |
721956f4 AM |
6369 | |
6370 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
6371 | { | |
411e1bfb | 6372 | struct plt_entry *ent; |
58ac9f71 | 6373 | off = (bfd_vma) -1; |
411e1bfb AM |
6374 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
6375 | if (ent->addend == stub_entry->addend) | |
6376 | { | |
6377 | off = ent->plt.offset & ~(bfd_vma) 1; | |
6378 | break; | |
6379 | } | |
58ac9f71 | 6380 | if (off >= (bfd_vma) -2) |
411e1bfb | 6381 | abort (); |
4ce794b7 AM |
6382 | off += (htab->plt->output_offset |
6383 | + htab->plt->output_section->vma | |
6384 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6385 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6386 | |
ad8e1ba5 | 6387 | size = PLT_CALL_STUB_SIZE; |
4ce794b7 | 6388 | if (PPC_HA (off + 16) != PPC_HA (off)) |
721956f4 AM |
6389 | size += 4; |
6390 | } | |
6391 | else | |
6392 | { | |
ad8e1ba5 AM |
6393 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
6394 | variants. */ | |
721956f4 AM |
6395 | off = (stub_entry->target_value |
6396 | + stub_entry->target_section->output_offset | |
6397 | + stub_entry->target_section->output_section->vma); | |
6398 | off -= (stub_entry->stub_sec->_raw_size | |
6399 | + stub_entry->stub_sec->output_offset | |
6400 | + stub_entry->stub_sec->output_section->vma); | |
6401 | ||
ad8e1ba5 AM |
6402 | /* Reset the stub type from the plt variant in case we now |
6403 | can reach with a shorter stub. */ | |
6404 | if (stub_entry->stub_type >= ppc_stub_plt_branch) | |
6405 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; | |
6406 | ||
6407 | size = 4; | |
6408 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
6409 | { | |
6410 | off -= 12; | |
6411 | size = 16; | |
6412 | } | |
6413 | ||
6414 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ | |
721956f4 AM |
6415 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
6416 | { | |
6417 | struct ppc_branch_hash_entry *br_entry; | |
6418 | ||
6419 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
6420 | stub_entry->root.string + 9, | |
b34976b6 | 6421 | TRUE, FALSE); |
721956f4 AM |
6422 | if (br_entry == NULL) |
6423 | { | |
6424 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), | |
6425 | stub_entry->root.string + 9); | |
b34976b6 AM |
6426 | htab->stub_error = TRUE; |
6427 | return FALSE; | |
721956f4 AM |
6428 | } |
6429 | ||
6430 | if (br_entry->iter != htab->stub_iteration) | |
6431 | { | |
6432 | br_entry->iter = htab->stub_iteration; | |
4ce794b7 AM |
6433 | br_entry->offset = htab->brlt->_raw_size; |
6434 | htab->brlt->_raw_size += 8; | |
63bc6f6c AM |
6435 | |
6436 | if (info->shared) | |
6437 | htab->relbrlt->_raw_size += sizeof (Elf64_External_Rela); | |
721956f4 | 6438 | } |
ad8e1ba5 AM |
6439 | |
6440 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | |
721956f4 | 6441 | size = 16; |
ad8e1ba5 AM |
6442 | if (stub_entry->stub_type != ppc_stub_plt_branch) |
6443 | size = 28; | |
721956f4 AM |
6444 | } |
6445 | } | |
6446 | ||
6447 | stub_entry->stub_sec->_raw_size += size; | |
b34976b6 | 6448 | return TRUE; |
721956f4 AM |
6449 | } |
6450 | ||
6451 | /* Set up various things so that we can make a list of input sections | |
6452 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 6453 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
6454 | |
6455 | int | |
4ce794b7 | 6456 | ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
721956f4 AM |
6457 | { |
6458 | bfd *input_bfd; | |
734b6cf9 | 6459 | int top_id, top_index, id; |
721956f4 | 6460 | asection *section; |
734b6cf9 | 6461 | asection **input_list; |
721956f4 AM |
6462 | bfd_size_type amt; |
6463 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6464 | ||
4ce794b7 | 6465 | if (htab->brlt == NULL) |
721956f4 AM |
6466 | return 0; |
6467 | ||
1e2f5b6e | 6468 | /* Find the top input section id. */ |
3d6f9012 | 6469 | for (input_bfd = info->input_bfds, top_id = 3; |
721956f4 AM |
6470 | input_bfd != NULL; |
6471 | input_bfd = input_bfd->link_next) | |
6472 | { | |
721956f4 AM |
6473 | for (section = input_bfd->sections; |
6474 | section != NULL; | |
6475 | section = section->next) | |
6476 | { | |
6477 | if (top_id < section->id) | |
6478 | top_id = section->id; | |
6479 | } | |
6480 | } | |
721956f4 | 6481 | |
8f3bab57 | 6482 | htab->top_id = top_id; |
721956f4 | 6483 | amt = sizeof (struct map_stub) * (top_id + 1); |
4ce794b7 | 6484 | htab->stub_group = bfd_zmalloc (amt); |
721956f4 AM |
6485 | if (htab->stub_group == NULL) |
6486 | return -1; | |
6487 | ||
3d6f9012 AM |
6488 | /* Set toc_off for com, und, abs and ind sections. */ |
6489 | for (id = 0; id < 3; id++) | |
6490 | htab->stub_group[id].toc_off = TOC_BASE_OFF; | |
721956f4 | 6491 | |
3d6f9012 | 6492 | elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd); |
734b6cf9 AM |
6493 | |
6494 | /* We can't use output_bfd->section_count here to find the top output | |
6495 | section index as some sections may have been removed, and | |
6496 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
6497 | for (section = output_bfd->sections, top_index = 0; | |
6498 | section != NULL; | |
6499 | section = section->next) | |
6500 | { | |
6501 | if (top_index < section->index) | |
6502 | top_index = section->index; | |
6503 | } | |
6504 | ||
6505 | htab->top_index = top_index; | |
6506 | amt = sizeof (asection *) * (top_index + 1); | |
4ce794b7 | 6507 | input_list = bfd_zmalloc (amt); |
734b6cf9 AM |
6508 | htab->input_list = input_list; |
6509 | if (input_list == NULL) | |
6510 | return -1; | |
6511 | ||
721956f4 AM |
6512 | return 1; |
6513 | } | |
6514 | ||
e717da7e AM |
6515 | /* The linker repeatedly calls this function for each TOC input section |
6516 | and linker generated GOT section. Group input bfds such that the toc | |
6517 | within a group is less than 64k in size. Will break with cute linker | |
6518 | scripts that play games with dot in the output toc section. */ | |
ad8e1ba5 AM |
6519 | |
6520 | void | |
4ce794b7 | 6521 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
ad8e1ba5 AM |
6522 | { |
6523 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6524 | ||
6525 | if (!htab->no_multi_toc) | |
6526 | { | |
6527 | bfd_vma addr = isec->output_offset + isec->output_section->vma; | |
6528 | bfd_vma off = addr - htab->toc_curr; | |
6529 | if (off + isec->_raw_size > 0x10000) | |
6530 | { | |
6531 | htab->toc_curr = addr; | |
6532 | htab->multi_toc_needed = 1; | |
6533 | } | |
6534 | elf_gp (isec->owner) = (htab->toc_curr | |
6535 | - elf_gp (isec->output_section->owner) | |
6536 | + TOC_BASE_OFF); | |
6537 | } | |
6538 | } | |
6539 | ||
6540 | /* Called after the last call to the above function. */ | |
6541 | ||
6542 | void | |
4ce794b7 AM |
6543 | ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED, |
6544 | struct bfd_link_info *info) | |
ad8e1ba5 AM |
6545 | { |
6546 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
ad8e1ba5 AM |
6547 | |
6548 | /* toc_curr tracks the TOC offset used for code sections below in | |
6549 | ppc64_elf_next_input_section. Start off at 0x8000. */ | |
3d6f9012 | 6550 | htab->toc_curr = TOC_BASE_OFF; |
ad8e1ba5 AM |
6551 | } |
6552 | ||
9b5ecbd0 AM |
6553 | /* No toc references were found in ISEC. If the code in ISEC makes no |
6554 | calls, then there's no need to use toc adjusting stubs when branching | |
6555 | into ISEC. Actually, indirect calls from ISEC are OK as they will | |
6556 | load r2. */ | |
6557 | ||
6558 | static int | |
4ce794b7 | 6559 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
9b5ecbd0 AM |
6560 | { |
6561 | bfd_byte *contents; | |
6562 | bfd_size_type i; | |
6563 | int ret; | |
6564 | int branch_ok; | |
6565 | ||
772119ce AM |
6566 | /* We know none of our code bearing sections will need toc stubs. */ |
6567 | if ((isec->flags & SEC_LINKER_CREATED) != 0) | |
6568 | return 0; | |
6569 | ||
082c50f8 AM |
6570 | if (isec->_raw_size == 0) |
6571 | return 0; | |
6572 | ||
9b5ecbd0 AM |
6573 | /* Hack for linux kernel. .fixup contains branches, but only back to |
6574 | the function that hit an exception. */ | |
6575 | branch_ok = strcmp (isec->name, ".fixup") == 0; | |
6576 | ||
6577 | contents = elf_section_data (isec)->this_hdr.contents; | |
6578 | if (contents == NULL) | |
6579 | { | |
6580 | contents = bfd_malloc (isec->_raw_size); | |
6581 | if (contents == NULL) | |
6582 | return -1; | |
6583 | if (! bfd_get_section_contents (isec->owner, isec, contents, | |
e717da7e | 6584 | 0, isec->_raw_size)) |
9b5ecbd0 AM |
6585 | { |
6586 | free (contents); | |
6587 | return -1; | |
6588 | } | |
6589 | if (info->keep_memory) | |
6590 | elf_section_data (isec)->this_hdr.contents = contents; | |
6591 | } | |
6592 | ||
6593 | /* Code scan, because we don't necessarily have relocs on calls to | |
6594 | static functions. */ | |
6595 | ret = 0; | |
6596 | for (i = 0; i < isec->_raw_size; i += 4) | |
6597 | { | |
6598 | unsigned long insn = bfd_get_32 (isec->owner, contents + i); | |
6599 | /* Is this a branch? */ | |
772119ce | 6600 | if ((insn & (0x3f << 26)) == (18 << 26) |
9b5ecbd0 AM |
6601 | /* If branch and link, it's a function call. */ |
6602 | && ((insn & 1) != 0 | |
6603 | /* Sibling calls use a plain branch. I don't know a way | |
6604 | of deciding whether a branch is really a sibling call. */ | |
6605 | || !branch_ok)) | |
6606 | { | |
6607 | ret = 1; | |
6608 | break; | |
6609 | } | |
6610 | } | |
6611 | ||
6612 | if (elf_section_data (isec)->this_hdr.contents != contents) | |
6613 | free (contents); | |
6614 | return ret; | |
6615 | } | |
6616 | ||
721956f4 AM |
6617 | /* The linker repeatedly calls this function for each input section, |
6618 | in the order that input sections are linked into output sections. | |
6619 | Build lists of input sections to determine groupings between which | |
6620 | we may insert linker stubs. */ | |
6621 | ||
9b5ecbd0 | 6622 | bfd_boolean |
4ce794b7 | 6623 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
721956f4 AM |
6624 | { |
6625 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
9b5ecbd0 | 6626 | int ret; |
721956f4 | 6627 | |
734b6cf9 AM |
6628 | if ((isec->output_section->flags & SEC_CODE) != 0 |
6629 | && isec->output_section->index <= htab->top_index) | |
721956f4 | 6630 | { |
734b6cf9 | 6631 | asection **list = htab->input_list + isec->output_section->index; |
3d6f9012 | 6632 | /* Steal the link_sec pointer for our list. */ |
721956f4 | 6633 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3d6f9012 AM |
6634 | /* This happens to make the list in reverse order, |
6635 | which is what we want. */ | |
734b6cf9 AM |
6636 | PREV_SEC (isec) = *list; |
6637 | *list = isec; | |
721956f4 | 6638 | } |
ad8e1ba5 AM |
6639 | |
6640 | /* If a code section has a function that uses the TOC then we need | |
6641 | to use the right TOC (obviously). Also, make sure that .opd gets | |
ee87f2da AM |
6642 | the correct TOC value for R_PPC64_TOC relocs that don't have or |
6643 | can't find their function symbol (shouldn't ever happen now). */ | |
ad8e1ba5 | 6644 | if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0) |
9b5ecbd0 AM |
6645 | { |
6646 | if (elf_gp (isec->owner) != 0) | |
6647 | htab->toc_curr = elf_gp (isec->owner); | |
6648 | } | |
6649 | else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0) | |
6650 | return FALSE; | |
6651 | else | |
6652 | isec->has_gp_reloc = ret; | |
ad8e1ba5 AM |
6653 | |
6654 | /* Functions that don't use the TOC can belong in any TOC group. | |
6655 | Use the last TOC base. This happens to make _init and _fini | |
6656 | pasting work. */ | |
6657 | htab->stub_group[isec->id].toc_off = htab->toc_curr; | |
9b5ecbd0 | 6658 | return TRUE; |
721956f4 AM |
6659 | } |
6660 | ||
6661 | /* See whether we can group stub sections together. Grouping stub | |
6662 | sections may result in fewer stubs. More importantly, we need to | |
6663 | put all .init* and .fini* stubs at the beginning of the .init or | |
6664 | .fini output sections respectively, because glibc splits the | |
6665 | _init and _fini functions into multiple parts. Putting a stub in | |
6666 | the middle of a function is not a good idea. */ | |
6667 | ||
6668 | static void | |
4ce794b7 AM |
6669 | group_sections (struct ppc_link_hash_table *htab, |
6670 | bfd_size_type stub_group_size, | |
6671 | bfd_boolean stubs_always_before_branch) | |
721956f4 | 6672 | { |
734b6cf9 AM |
6673 | asection **list = htab->input_list + htab->top_index; |
6674 | do | |
721956f4 | 6675 | { |
734b6cf9 AM |
6676 | asection *tail = *list; |
6677 | while (tail != NULL) | |
721956f4 | 6678 | { |
734b6cf9 AM |
6679 | asection *curr; |
6680 | asection *prev; | |
6681 | bfd_size_type total; | |
6682 | bfd_boolean big_sec; | |
6683 | bfd_vma curr_toc; | |
6684 | ||
6685 | curr = tail; | |
6686 | if (tail->_cooked_size) | |
6687 | total = tail->_cooked_size; | |
6688 | else | |
6689 | total = tail->_raw_size; | |
6690 | big_sec = total >= stub_group_size; | |
6691 | curr_toc = htab->stub_group[tail->id].toc_off; | |
6692 | ||
6693 | while ((prev = PREV_SEC (curr)) != NULL | |
6694 | && ((total += curr->output_offset - prev->output_offset) | |
ad8e1ba5 AM |
6695 | < stub_group_size) |
6696 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
734b6cf9 AM |
6697 | curr = prev; |
6698 | ||
6699 | /* OK, the size from the start of CURR to the end is less | |
6700 | than stub_group_size and thus can be handled by one stub | |
6701 | section. (or the tail section is itself larger than | |
6702 | stub_group_size, in which case we may be toast.) We | |
6703 | should really be keeping track of the total size of stubs | |
6704 | added here, as stubs contribute to the final output | |
6705 | section size. That's a little tricky, and this way will | |
6706 | only break if stubs added make the total size more than | |
6707 | 2^25, ie. for the default stub_group_size, if stubs total | |
6708 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ | |
6709 | do | |
721956f4 AM |
6710 | { |
6711 | prev = PREV_SEC (tail); | |
734b6cf9 | 6712 | /* Set up this stub group. */ |
721956f4 AM |
6713 | htab->stub_group[tail->id].link_sec = curr; |
6714 | } | |
734b6cf9 AM |
6715 | while (tail != curr && (tail = prev) != NULL); |
6716 | ||
6717 | /* But wait, there's more! Input sections up to stub_group_size | |
6718 | bytes before the stub section can be handled by it too. | |
6719 | Don't do this if we have a really large section after the | |
6720 | stubs, as adding more stubs increases the chance that | |
6721 | branches may not reach into the stub section. */ | |
6722 | if (!stubs_always_before_branch && !big_sec) | |
6723 | { | |
6724 | total = 0; | |
6725 | while (prev != NULL | |
6726 | && ((total += tail->output_offset - prev->output_offset) | |
6727 | < stub_group_size) | |
6728 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
6729 | { | |
6730 | tail = prev; | |
6731 | prev = PREV_SEC (tail); | |
6732 | htab->stub_group[tail->id].link_sec = curr; | |
6733 | } | |
6734 | } | |
6735 | tail = prev; | |
721956f4 AM |
6736 | } |
6737 | } | |
734b6cf9 AM |
6738 | while (list-- != htab->input_list); |
6739 | free (htab->input_list); | |
721956f4 AM |
6740 | #undef PREV_SEC |
6741 | } | |
6742 | ||
721956f4 AM |
6743 | /* Determine and set the size of the stub section for a final link. |
6744 | ||
6745 | The basic idea here is to examine all the relocations looking for | |
6746 | PC-relative calls to a target that is unreachable with a "bl" | |
6747 | instruction. */ | |
6748 | ||
b34976b6 | 6749 | bfd_boolean |
4ce794b7 | 6750 | ppc64_elf_size_stubs (bfd *output_bfd, |
4ce794b7 AM |
6751 | struct bfd_link_info *info, |
6752 | bfd_signed_vma group_size, | |
6753 | asection *(*add_stub_section) (const char *, asection *), | |
6754 | void (*layout_sections_again) (void)) | |
721956f4 AM |
6755 | { |
6756 | bfd_size_type stub_group_size; | |
b34976b6 | 6757 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
6758 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
6759 | ||
6760 | /* Stash our params away. */ | |
721956f4 AM |
6761 | htab->add_stub_section = add_stub_section; |
6762 | htab->layout_sections_again = layout_sections_again; | |
6763 | stubs_always_before_branch = group_size < 0; | |
6764 | if (group_size < 0) | |
6765 | stub_group_size = -group_size; | |
6766 | else | |
6767 | stub_group_size = group_size; | |
6768 | if (stub_group_size == 1) | |
6769 | { | |
6770 | /* Default values. */ | |
58ac9f71 AM |
6771 | if (stubs_always_before_branch) |
6772 | { | |
6773 | stub_group_size = 0x1e00000; | |
6774 | if (htab->has_14bit_branch) | |
6775 | stub_group_size = 0x7800; | |
6776 | } | |
6777 | else | |
6778 | { | |
6779 | stub_group_size = 0x1c00000; | |
6780 | if (htab->has_14bit_branch) | |
6781 | stub_group_size = 0x7000; | |
6782 | } | |
721956f4 AM |
6783 | } |
6784 | ||
6785 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
6786 | ||
721956f4 AM |
6787 | while (1) |
6788 | { | |
6789 | bfd *input_bfd; | |
6790 | unsigned int bfd_indx; | |
6791 | asection *stub_sec; | |
b34976b6 | 6792 | bfd_boolean stub_changed; |
721956f4 AM |
6793 | |
6794 | htab->stub_iteration += 1; | |
b34976b6 | 6795 | stub_changed = FALSE; |
721956f4 AM |
6796 | |
6797 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
6798 | input_bfd != NULL; | |
6799 | input_bfd = input_bfd->link_next, bfd_indx++) | |
6800 | { | |
6801 | Elf_Internal_Shdr *symtab_hdr; | |
6802 | asection *section; | |
6cdc0ccc | 6803 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 AM |
6804 | |
6805 | /* We'll need the symbol table in a second. */ | |
6806 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
6807 | if (symtab_hdr->sh_info == 0) | |
6808 | continue; | |
6809 | ||
721956f4 AM |
6810 | /* Walk over each section attached to the input bfd. */ |
6811 | for (section = input_bfd->sections; | |
6812 | section != NULL; | |
6813 | section = section->next) | |
6814 | { | |
721956f4 | 6815 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
6816 | |
6817 | /* If there aren't any relocs, then there's nothing more | |
6818 | to do. */ | |
6819 | if ((section->flags & SEC_RELOC) == 0 | |
6820 | || section->reloc_count == 0) | |
6821 | continue; | |
6822 | ||
6823 | /* If this section is a link-once section that will be | |
6824 | discarded, then don't create any stubs. */ | |
6825 | if (section->output_section == NULL | |
6826 | || section->output_section->owner != output_bfd) | |
6827 | continue; | |
6828 | ||
1e2f5b6e AM |
6829 | /* Get the relocs. */ |
6830 | internal_relocs | |
4ce794b7 | 6831 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 6832 | info->keep_memory); |
721956f4 | 6833 | if (internal_relocs == NULL) |
1e2f5b6e | 6834 | goto error_ret_free_local; |
721956f4 AM |
6835 | |
6836 | /* Now examine each relocation. */ | |
6837 | irela = internal_relocs; | |
6838 | irelaend = irela + section->reloc_count; | |
6839 | for (; irela < irelaend; irela++) | |
6840 | { | |
4ce794b7 AM |
6841 | enum elf_ppc64_reloc_type r_type; |
6842 | unsigned int r_indx; | |
721956f4 AM |
6843 | enum ppc_stub_type stub_type; |
6844 | struct ppc_stub_hash_entry *stub_entry; | |
6845 | asection *sym_sec; | |
6846 | bfd_vma sym_value; | |
6847 | bfd_vma destination; | |
6848 | struct ppc_link_hash_entry *hash; | |
411e1bfb AM |
6849 | struct elf_link_hash_entry *h; |
6850 | Elf_Internal_Sym *sym; | |
721956f4 AM |
6851 | char *stub_name; |
6852 | const asection *id_sec; | |
6853 | ||
6854 | r_type = ELF64_R_TYPE (irela->r_info); | |
6855 | r_indx = ELF64_R_SYM (irela->r_info); | |
6856 | ||
4ce794b7 | 6857 | if (r_type >= R_PPC64_max) |
721956f4 AM |
6858 | { |
6859 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 6860 | goto error_ret_free_internal; |
721956f4 AM |
6861 | } |
6862 | ||
6863 | /* Only look for stubs on branch instructions. */ | |
4ce794b7 AM |
6864 | if (r_type != R_PPC64_REL24 |
6865 | && r_type != R_PPC64_REL14 | |
6866 | && r_type != R_PPC64_REL14_BRTAKEN | |
6867 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
721956f4 AM |
6868 | continue; |
6869 | ||
6870 | /* Now determine the call target, its name, value, | |
6871 | section. */ | |
721956f4 | 6872 | destination = 0; |
411e1bfb AM |
6873 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
6874 | r_indx, input_bfd)) | |
6875 | goto error_ret_free_internal; | |
6876 | hash = (struct ppc_link_hash_entry *) h; | |
6877 | ||
6878 | if (hash == NULL) | |
721956f4 AM |
6879 | { |
6880 | /* It's a local symbol. */ | |
411e1bfb | 6881 | sym_value = sym->st_value; |
721956f4 AM |
6882 | destination = (sym_value + irela->r_addend |
6883 | + sym_sec->output_offset | |
6884 | + sym_sec->output_section->vma); | |
6885 | } | |
6886 | else | |
6887 | { | |
6888 | /* It's an external symbol. */ | |
411e1bfb | 6889 | sym_value = 0; |
721956f4 AM |
6890 | if (hash->elf.root.type == bfd_link_hash_defined |
6891 | || hash->elf.root.type == bfd_link_hash_defweak) | |
6892 | { | |
721956f4 AM |
6893 | sym_value = hash->elf.root.u.def.value; |
6894 | if (sym_sec->output_section != NULL) | |
6895 | destination = (sym_value + irela->r_addend | |
6896 | + sym_sec->output_offset | |
6897 | + sym_sec->output_section->vma); | |
6898 | } | |
6899 | else if (hash->elf.root.type == bfd_link_hash_undefweak) | |
6900 | ; | |
6901 | else if (hash->elf.root.type == bfd_link_hash_undefined) | |
6902 | ; | |
6903 | else | |
6904 | { | |
6905 | bfd_set_error (bfd_error_bad_value); | |
6906 | goto error_ret_free_internal; | |
6907 | } | |
6908 | } | |
6909 | ||
6910 | /* Determine what (if any) linker stub is needed. */ | |
6911 | stub_type = ppc_type_of_stub (section, irela, &hash, | |
6912 | destination); | |
ad8e1ba5 AM |
6913 | |
6914 | if (stub_type != ppc_stub_plt_call) | |
6915 | { | |
6916 | /* Check whether we need a TOC adjusting stub. | |
6917 | Since the linker pastes together pieces from | |
6918 | different object files when creating the | |
6919 | _init and _fini functions, it may be that a | |
6920 | call to what looks like a local sym is in | |
6921 | fact a call needing a TOC adjustment. */ | |
6922 | if (sym_sec != NULL | |
6923 | && sym_sec->output_section != NULL | |
6924 | && (htab->stub_group[sym_sec->id].toc_off | |
9b5ecbd0 AM |
6925 | != htab->stub_group[section->id].toc_off) |
6926 | && sym_sec->has_gp_reloc | |
6927 | && section->has_gp_reloc) | |
ad8e1ba5 AM |
6928 | stub_type = ppc_stub_long_branch_r2off; |
6929 | } | |
6930 | ||
721956f4 AM |
6931 | if (stub_type == ppc_stub_none) |
6932 | continue; | |
6933 | ||
411e1bfb AM |
6934 | /* __tls_get_addr calls might be eliminated. */ |
6935 | if (stub_type != ppc_stub_plt_call | |
6936 | && hash != NULL | |
6937 | && &hash->elf == htab->tls_get_addr | |
6938 | && section->has_tls_reloc | |
6939 | && irela != internal_relocs) | |
6940 | { | |
6941 | /* Get tls info. */ | |
e7b938ca | 6942 | char *tls_mask; |
411e1bfb | 6943 | |
0d4792f7 | 6944 | if (!get_tls_mask (&tls_mask, NULL, &local_syms, |
411e1bfb AM |
6945 | irela - 1, input_bfd)) |
6946 | goto error_ret_free_internal; | |
e7b938ca | 6947 | if (*tls_mask != 0) |
411e1bfb AM |
6948 | continue; |
6949 | } | |
6950 | ||
721956f4 AM |
6951 | /* Support for grouping stub sections. */ |
6952 | id_sec = htab->stub_group[section->id].link_sec; | |
6953 | ||
6954 | /* Get the name of this stub. */ | |
6955 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
6956 | if (!stub_name) | |
6957 | goto error_ret_free_internal; | |
6958 | ||
6959 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 6960 | stub_name, FALSE, FALSE); |
721956f4 AM |
6961 | if (stub_entry != NULL) |
6962 | { | |
6963 | /* The proper stub has already been created. */ | |
6964 | free (stub_name); | |
6965 | continue; | |
6966 | } | |
6967 | ||
6968 | stub_entry = ppc_add_stub (stub_name, section, htab); | |
6969 | if (stub_entry == NULL) | |
6970 | { | |
6971 | free (stub_name); | |
6cdc0ccc AM |
6972 | error_ret_free_internal: |
6973 | if (elf_section_data (section)->relocs == NULL) | |
6974 | free (internal_relocs); | |
6975 | error_ret_free_local: | |
6976 | if (local_syms != NULL | |
6977 | && (symtab_hdr->contents | |
6978 | != (unsigned char *) local_syms)) | |
6979 | free (local_syms); | |
b34976b6 | 6980 | return FALSE; |
721956f4 AM |
6981 | } |
6982 | ||
ad8e1ba5 | 6983 | stub_entry->stub_type = stub_type; |
721956f4 AM |
6984 | stub_entry->target_value = sym_value; |
6985 | stub_entry->target_section = sym_sec; | |
721956f4 | 6986 | stub_entry->h = hash; |
411e1bfb | 6987 | stub_entry->addend = irela->r_addend; |
b34976b6 | 6988 | stub_changed = TRUE; |
721956f4 AM |
6989 | } |
6990 | ||
6991 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 6992 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 6993 | free (internal_relocs); |
721956f4 | 6994 | } |
6cdc0ccc AM |
6995 | |
6996 | if (local_syms != NULL | |
6997 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
6998 | { | |
6999 | if (!info->keep_memory) | |
7000 | free (local_syms); | |
7001 | else | |
7002 | symtab_hdr->contents = (unsigned char *) local_syms; | |
7003 | } | |
721956f4 AM |
7004 | } |
7005 | ||
7006 | if (!stub_changed) | |
7007 | break; | |
7008 | ||
7009 | /* OK, we've added some stubs. Find out the new size of the | |
7010 | stub sections. */ | |
7011 | for (stub_sec = htab->stub_bfd->sections; | |
7012 | stub_sec != NULL; | |
7013 | stub_sec = stub_sec->next) | |
e717da7e AM |
7014 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7015 | { | |
7016 | stub_sec->_raw_size = 0; | |
7017 | stub_sec->_cooked_size = 0; | |
7018 | } | |
4ce794b7 AM |
7019 | htab->brlt->_raw_size = 0; |
7020 | htab->brlt->_cooked_size = 0; | |
63bc6f6c AM |
7021 | if (info->shared) |
7022 | { | |
7023 | htab->relbrlt->_raw_size = 0; | |
7024 | htab->relbrlt->_cooked_size = 0; | |
7025 | } | |
721956f4 | 7026 | |
63bc6f6c | 7027 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info); |
721956f4 AM |
7028 | |
7029 | /* Ask the linker to do its stuff. */ | |
7030 | (*htab->layout_sections_again) (); | |
7031 | } | |
7032 | ||
afbe61cf AM |
7033 | /* It would be nice to strip .branch_lt from the output if the |
7034 | section is empty, but it's too late. If we strip sections here, | |
7035 | the dynamic symbol table is corrupted since the section symbol | |
7036 | for the stripped section isn't written. */ | |
721956f4 | 7037 | |
b34976b6 | 7038 | return TRUE; |
721956f4 AM |
7039 | } |
7040 | ||
7041 | /* Called after we have determined section placement. If sections | |
805fc799 | 7042 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 7043 | |
805fc799 | 7044 | bfd_vma |
4ce794b7 | 7045 | ppc64_elf_toc (bfd *obfd) |
721956f4 | 7046 | { |
805fc799 AM |
7047 | asection *s; |
7048 | bfd_vma TOCstart; | |
721956f4 | 7049 | |
805fc799 AM |
7050 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
7051 | order. The TOC starts where the first of these sections starts. */ | |
7052 | s = bfd_get_section_by_name (obfd, ".got"); | |
7053 | if (s == NULL) | |
7054 | s = bfd_get_section_by_name (obfd, ".toc"); | |
7055 | if (s == NULL) | |
7056 | s = bfd_get_section_by_name (obfd, ".tocbss"); | |
7057 | if (s == NULL) | |
7058 | s = bfd_get_section_by_name (obfd, ".plt"); | |
7059 | if (s == NULL) | |
7060 | { | |
7061 | /* This may happen for | |
7062 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
7063 | .toc directive | |
7064 | o bad linker script | |
7065 | o --gc-sections and empty TOC sections | |
7066 | ||
7067 | FIXME: Warn user? */ | |
7068 | ||
7069 | /* Look for a likely section. We probably won't even be | |
7070 | using TOCstart. */ | |
7071 | for (s = obfd->sections; s != NULL; s = s->next) | |
7072 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) | |
7073 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7074 | break; | |
721956f4 | 7075 | if (s == NULL) |
805fc799 AM |
7076 | for (s = obfd->sections; s != NULL; s = s->next) |
7077 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) | |
7078 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7079 | break; | |
721956f4 | 7080 | if (s == NULL) |
805fc799 AM |
7081 | for (s = obfd->sections; s != NULL; s = s->next) |
7082 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) | |
7083 | break; | |
721956f4 | 7084 | if (s == NULL) |
805fc799 AM |
7085 | for (s = obfd->sections; s != NULL; s = s->next) |
7086 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) | |
7087 | break; | |
7088 | } | |
721956f4 | 7089 | |
805fc799 AM |
7090 | TOCstart = 0; |
7091 | if (s != NULL) | |
7092 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 7093 | |
805fc799 | 7094 | return TOCstart; |
721956f4 AM |
7095 | } |
7096 | ||
7097 | /* Build all the stubs associated with the current output file. | |
7098 | The stubs are kept in a hash table attached to the main linker | |
7099 | hash table. This function is called via gldelf64ppc_finish. */ | |
7100 | ||
b34976b6 | 7101 | bfd_boolean |
4ce794b7 AM |
7102 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
7103 | struct bfd_link_info *info, | |
7104 | char **stats) | |
5d1634d7 AM |
7105 | { |
7106 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 7107 | asection *stub_sec; |
5d1634d7 | 7108 | bfd_byte *p; |
e717da7e | 7109 | int stub_sec_count = 0; |
5d1634d7 | 7110 | |
ad8e1ba5 | 7111 | htab->emit_stub_syms = emit_stub_syms; |
721956f4 AM |
7112 | for (stub_sec = htab->stub_bfd->sections; |
7113 | stub_sec != NULL; | |
7114 | stub_sec = stub_sec->next) | |
e717da7e AM |
7115 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7116 | { | |
7117 | bfd_size_type size; | |
721956f4 | 7118 | |
e717da7e AM |
7119 | /* Allocate memory to hold the linker stubs. */ |
7120 | size = stub_sec->_raw_size; | |
7121 | if (size != 0) | |
7122 | { | |
7123 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); | |
7124 | if (stub_sec->contents == NULL) | |
7125 | return FALSE; | |
7126 | } | |
7127 | stub_sec->_cooked_size = 0; | |
7128 | } | |
5d1634d7 | 7129 | |
4ce794b7 | 7130 | if (htab->plt != NULL) |
5d1634d7 | 7131 | { |
9f951329 | 7132 | unsigned int indx; |
ad8e1ba5 | 7133 | bfd_vma plt0; |
9f951329 | 7134 | |
721956f4 | 7135 | /* Build the .glink plt call stub. */ |
4ce794b7 AM |
7136 | plt0 = (htab->plt->output_section->vma |
7137 | + htab->plt->output_offset | |
7138 | - (htab->glink->output_section->vma | |
7139 | + htab->glink->output_offset | |
ad8e1ba5 AM |
7140 | + GLINK_CALL_STUB_SIZE)); |
7141 | if (plt0 + 0x80008000 > 0xffffffff) | |
721956f4 | 7142 | { |
ad8e1ba5 AM |
7143 | (*_bfd_error_handler) (_(".glink and .plt too far apart")); |
7144 | bfd_set_error (bfd_error_bad_value); | |
7145 | return FALSE; | |
721956f4 | 7146 | } |
721956f4 | 7147 | |
97b639ba AM |
7148 | if (htab->emit_stub_syms) |
7149 | { | |
7150 | struct elf_link_hash_entry *h; | |
7151 | h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE); | |
7152 | if (h == NULL) | |
7153 | return FALSE; | |
7154 | if (h->root.type == bfd_link_hash_new) | |
7155 | { | |
7156 | h->root.type = bfd_link_hash_defined; | |
7157 | h->root.u.def.section = htab->glink; | |
7158 | h->root.u.def.value = 0; | |
7159 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
7160 | | ELF_LINK_HASH_DEF_REGULAR | |
7161 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
7162 | | ELF_LINK_FORCED_LOCAL); | |
7163 | } | |
7164 | } | |
4ce794b7 AM |
7165 | p = htab->glink->contents; |
7166 | bfd_put_32 (htab->glink->owner, MFCTR_R12, p); | |
ad8e1ba5 | 7167 | p += 4; |
4ce794b7 | 7168 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p); |
ad8e1ba5 | 7169 | p += 4; |
4ce794b7 | 7170 | bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p); |
ad8e1ba5 | 7171 | p += 4; |
4ce794b7 | 7172 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7173 | p += 4; |
4ce794b7 | 7174 | bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p); |
ad8e1ba5 | 7175 | p += 4; |
4ce794b7 | 7176 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p); |
ad8e1ba5 | 7177 | p += 4; |
4ce794b7 | 7178 | bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p); |
ad8e1ba5 | 7179 | p += 4; |
4ce794b7 | 7180 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7181 | p += 4; |
4ce794b7 | 7182 | bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p); |
ad8e1ba5 | 7183 | p += 4; |
4ce794b7 | 7184 | bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p); |
ad8e1ba5 | 7185 | p += 4; |
4ce794b7 | 7186 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7187 | p += 4; |
4ce794b7 | 7188 | bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7189 | p += 4; |
4ce794b7 | 7190 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
ad8e1ba5 | 7191 | p += 4; |
4ce794b7 | 7192 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
ad8e1ba5 | 7193 | p += 4; |
4ce794b7 | 7194 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
ad8e1ba5 | 7195 | p += 4; |
4ce794b7 | 7196 | bfd_put_32 (htab->glink->owner, BCTR, p); |
ad8e1ba5 AM |
7197 | p += 4; |
7198 | ||
9f951329 AM |
7199 | /* Build the .glink lazy link call stubs. */ |
7200 | indx = 0; | |
4ce794b7 | 7201 | while (p < htab->glink->contents + htab->glink->_raw_size) |
9f951329 AM |
7202 | { |
7203 | if (indx < 0x8000) | |
7204 | { | |
4ce794b7 | 7205 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
9f951329 AM |
7206 | p += 4; |
7207 | } | |
7208 | else | |
7209 | { | |
4ce794b7 | 7210 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
9f951329 | 7211 | p += 4; |
4ce794b7 | 7212 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
9f951329 AM |
7213 | p += 4; |
7214 | } | |
4ce794b7 AM |
7215 | bfd_put_32 (htab->glink->owner, |
7216 | B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p); | |
a16d5acb | 7217 | indx++; |
9f951329 AM |
7218 | p += 4; |
7219 | } | |
4ce794b7 | 7220 | htab->glink->_cooked_size = p - htab->glink->contents; |
5d1634d7 | 7221 | } |
5d1634d7 | 7222 | |
4ce794b7 | 7223 | if (htab->brlt->_raw_size != 0) |
721956f4 | 7224 | { |
4ce794b7 AM |
7225 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
7226 | htab->brlt->_raw_size); | |
7227 | if (htab->brlt->contents == NULL) | |
b34976b6 | 7228 | return FALSE; |
721956f4 | 7229 | } |
63bc6f6c AM |
7230 | if (info->shared && htab->relbrlt->_raw_size != 0) |
7231 | { | |
7232 | htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner, | |
7233 | htab->relbrlt->_raw_size); | |
7234 | if (htab->relbrlt->contents == NULL) | |
7235 | return FALSE; | |
7236 | } | |
5d1634d7 | 7237 | |
721956f4 AM |
7238 | /* Build the stubs as directed by the stub hash table. */ |
7239 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 7240 | |
721956f4 AM |
7241 | for (stub_sec = htab->stub_bfd->sections; |
7242 | stub_sec != NULL; | |
7243 | stub_sec = stub_sec->next) | |
e717da7e AM |
7244 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7245 | { | |
7246 | stub_sec_count += 1; | |
7247 | if (stub_sec->_raw_size != stub_sec->_cooked_size) | |
7248 | break; | |
7249 | } | |
5d1634d7 | 7250 | |
721956f4 | 7251 | if (stub_sec != NULL |
4ce794b7 | 7252 | || htab->glink->_raw_size != htab->glink->_cooked_size) |
5d1634d7 | 7253 | { |
b34976b6 | 7254 | htab->stub_error = TRUE; |
721956f4 | 7255 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
5d1634d7 | 7256 | } |
721956f4 | 7257 | |
d2a300cf AM |
7258 | if (htab->stub_error) |
7259 | return FALSE; | |
7260 | ||
7261 | if (stats != NULL) | |
7262 | { | |
7263 | *stats = bfd_malloc (500); | |
7264 | if (*stats == NULL) | |
7265 | return FALSE; | |
7266 | ||
7267 | sprintf (*stats, _("linker stubs in %u groups\n" | |
7268 | " branch %lu\n" | |
7269 | " toc adjust %lu\n" | |
7270 | " long branch %lu\n" | |
7271 | " long toc adj %lu\n" | |
7272 | " plt call %lu"), | |
e717da7e | 7273 | stub_sec_count, |
4ce794b7 AM |
7274 | htab->stub_count[ppc_stub_long_branch - 1], |
7275 | htab->stub_count[ppc_stub_long_branch_r2off - 1], | |
7276 | htab->stub_count[ppc_stub_plt_branch - 1], | |
7277 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], | |
7278 | htab->stub_count[ppc_stub_plt_call - 1]); | |
d2a300cf AM |
7279 | } |
7280 | return TRUE; | |
5bd4f169 AM |
7281 | } |
7282 | ||
5bd4f169 AM |
7283 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
7284 | to handle the relocations for a section. | |
7285 | ||
7286 | The relocs are always passed as Rela structures; if the section | |
7287 | actually uses Rel structures, the r_addend field will always be | |
7288 | zero. | |
7289 | ||
7290 | This function is responsible for adjust the section contents as | |
7291 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 7292 | relocatable output file) adjusting the reloc addend as |
5bd4f169 AM |
7293 | necessary. |
7294 | ||
7295 | This function does not have to worry about setting the reloc | |
7296 | address or the reloc symbol index. | |
7297 | ||
7298 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
7299 | ||
7300 | LOCAL_SECTIONS is an array giving the section in the input file | |
7301 | corresponding to the st_shndx field of each local symbol. | |
7302 | ||
7303 | The global hash table entry for the global symbols can be found | |
7304 | via elf_sym_hashes (input_bfd). | |
7305 | ||
1049f94e | 7306 | When generating relocatable output, this function must handle |
5bd4f169 AM |
7307 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
7308 | going to be the section symbol corresponding to the output | |
7309 | section, which means that the addend must be adjusted | |
7310 | accordingly. */ | |
7311 | ||
b34976b6 | 7312 | static bfd_boolean |
4ce794b7 AM |
7313 | ppc64_elf_relocate_section (bfd *output_bfd, |
7314 | struct bfd_link_info *info, | |
7315 | bfd *input_bfd, | |
7316 | asection *input_section, | |
7317 | bfd_byte *contents, | |
7318 | Elf_Internal_Rela *relocs, | |
7319 | Elf_Internal_Sym *local_syms, | |
7320 | asection **local_sections) | |
5bd4f169 | 7321 | { |
65f38f15 | 7322 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
7323 | Elf_Internal_Shdr *symtab_hdr; |
7324 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
7325 | Elf_Internal_Rela *rel; |
7326 | Elf_Internal_Rela *relend; | |
411e1bfb AM |
7327 | Elf_Internal_Rela outrel; |
7328 | bfd_byte *loc; | |
411e1bfb | 7329 | struct got_entry **local_got_ents; |
5bd4f169 | 7330 | bfd_vma TOCstart; |
b34976b6 AM |
7331 | bfd_boolean ret = TRUE; |
7332 | bfd_boolean is_opd; | |
96e0dda4 | 7333 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 7334 | bfd_boolean is_power4 = FALSE; |
5bd4f169 | 7335 | |
1049f94e | 7336 | if (info->relocatable) |
b34976b6 | 7337 | return TRUE; |
b491616a | 7338 | |
65f38f15 | 7339 | /* Initialize howto table if needed. */ |
5bd4f169 | 7340 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
7341 | ppc_howto_init (); |
7342 | ||
65f38f15 | 7343 | htab = ppc_hash_table (info); |
411e1bfb | 7344 | local_got_ents = elf_local_got_ents (input_bfd); |
5bd4f169 | 7345 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
7346 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
7347 | sym_hashes = elf_sym_hashes (input_bfd); | |
f0abc2a1 | 7348 | is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL; |
65f38f15 | 7349 | |
5bd4f169 AM |
7350 | rel = relocs; |
7351 | relend = relocs + input_section->reloc_count; | |
7352 | for (; rel < relend; rel++) | |
7353 | { | |
04c9666a | 7354 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 AM |
7355 | bfd_vma addend; |
7356 | bfd_reloc_status_type r; | |
7357 | Elf_Internal_Sym *sym; | |
7358 | asection *sec; | |
7359 | struct elf_link_hash_entry *h; | |
721956f4 | 7360 | struct elf_link_hash_entry *fdh; |
5bd4f169 | 7361 | const char *sym_name; |
0d4792f7 | 7362 | unsigned long r_symndx, toc_symndx; |
951fd09b | 7363 | char tls_mask, tls_gd, tls_type; |
0d4792f7 | 7364 | char sym_type; |
5bd4f169 | 7365 | bfd_vma relocation; |
b34976b6 AM |
7366 | bfd_boolean unresolved_reloc; |
7367 | bfd_boolean warned; | |
50bc7936 | 7368 | unsigned long insn, mask; |
721956f4 AM |
7369 | struct ppc_stub_hash_entry *stub_entry; |
7370 | bfd_vma max_br_offset; | |
7371 | bfd_vma from; | |
5bd4f169 | 7372 | |
4ce794b7 | 7373 | r_type = ELF64_R_TYPE (rel->r_info); |
5bd4f169 | 7374 | r_symndx = ELF64_R_SYM (rel->r_info); |
ee87f2da AM |
7375 | |
7376 | /* For old style R_PPC64_TOC relocs with a zero symbol, use the | |
7377 | symbol of the previous ADDR64 reloc. The symbol gives us the | |
7378 | proper TOC base to use. */ | |
7379 | if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC) | |
7380 | && rel != relocs | |
7381 | && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64 | |
7382 | && is_opd) | |
7383 | r_symndx = ELF64_R_SYM (rel[-1].r_info); | |
7384 | ||
4ce794b7 AM |
7385 | sym = NULL; |
7386 | sec = NULL; | |
7387 | h = NULL; | |
7388 | sym_name = NULL; | |
b34976b6 AM |
7389 | unresolved_reloc = FALSE; |
7390 | warned = FALSE; | |
65f38f15 | 7391 | |
0b13192e | 7392 | if (r_symndx < symtab_hdr->sh_info) |
5bd4f169 AM |
7393 | { |
7394 | /* It's a local symbol. */ | |
7395 | sym = local_syms + r_symndx; | |
7396 | sec = local_sections[r_symndx]; | |
411e1bfb | 7397 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
0d4792f7 | 7398 | sym_type = ELF64_ST_TYPE (sym->st_info); |
8517fae7 | 7399 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
1e2f5b6e AM |
7400 | if (elf_section_data (sec) != NULL) |
7401 | { | |
7402 | long *opd_sym_adjust; | |
7403 | ||
f0abc2a1 | 7404 | opd_sym_adjust = ppc64_elf_section_data (sec)->opd.adjust; |
1e2f5b6e AM |
7405 | if (opd_sym_adjust != NULL && sym->st_value % 24 == 0) |
7406 | relocation += opd_sym_adjust[sym->st_value / 24]; | |
7407 | } | |
5bd4f169 AM |
7408 | } |
7409 | else | |
7410 | { | |
560e09e9 NC |
7411 | RELOC_FOR_GLOBAL_SYMBOL (h, sym_hashes, r_symndx, |
7412 | symtab_hdr, relocation, sec, | |
7413 | unresolved_reloc, info, | |
7414 | warned); | |
5bd4f169 | 7415 | sym_name = h->root.root.string; |
0d4792f7 | 7416 | sym_type = h->type; |
5bd4f169 AM |
7417 | } |
7418 | ||
951fd09b AM |
7419 | /* TLS optimizations. Replace instruction sequences and relocs |
7420 | based on information we collected in tls_optimize. We edit | |
7421 | RELOCS so that --emit-relocs will output something sensible | |
7422 | for the final instruction stream. */ | |
7423 | tls_mask = 0; | |
7424 | tls_gd = 0; | |
0d4792f7 | 7425 | toc_symndx = 0; |
d881513a | 7426 | if (IS_PPC64_TLS_RELOC (r_type)) |
411e1bfb AM |
7427 | { |
7428 | if (h != NULL) | |
e7b938ca | 7429 | tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask; |
411e1bfb AM |
7430 | else if (local_got_ents != NULL) |
7431 | { | |
e7b938ca AM |
7432 | char *lgot_masks; |
7433 | lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); | |
7434 | tls_mask = lgot_masks[r_symndx]; | |
411e1bfb | 7435 | } |
0d4792f7 AM |
7436 | if (tls_mask == 0 && r_type == R_PPC64_TLS) |
7437 | { | |
7438 | /* Check for toc tls entries. */ | |
7439 | char *toc_tls; | |
7440 | ||
7441 | if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms, | |
7442 | rel, input_bfd)) | |
7443 | return FALSE; | |
7444 | ||
7445 | if (toc_tls) | |
7446 | tls_mask = *toc_tls; | |
7447 | } | |
7448 | } | |
7449 | ||
7450 | /* Check that tls relocs are used with tls syms, and non-tls | |
7451 | relocs are used with non-tls syms. */ | |
7452 | if (r_symndx != 0 | |
7453 | && r_type != R_PPC64_NONE | |
7454 | && (h == NULL | |
7455 | || h->root.type == bfd_link_hash_defined | |
7456 | || h->root.type == bfd_link_hash_defweak) | |
7457 | && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
7458 | { | |
7459 | if (r_type == R_PPC64_TLS && tls_mask != 0) | |
7460 | /* R_PPC64_TLS is OK against a symbol in the TOC. */ | |
7461 | ; | |
7462 | else | |
7463 | (*_bfd_error_handler) | |
7464 | (sym_type == STT_TLS | |
7465 | ? _("%s(%s+0x%lx): %s used with TLS symbol %s") | |
7466 | : _("%s(%s+0x%lx): %s used with non-TLS symbol %s"), | |
7467 | bfd_archive_filename (input_bfd), | |
7468 | input_section->name, | |
7469 | (long) rel->r_offset, | |
7470 | ppc64_elf_howto_table[r_type]->name, | |
7471 | sym_name); | |
411e1bfb AM |
7472 | } |
7473 | ||
7474 | /* Ensure reloc mapping code below stays sane. */ | |
7475 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 | |
7476 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 | |
7477 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) | |
7478 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) | |
7479 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) | |
7480 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) | |
7481 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) | |
7482 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) | |
7483 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) | |
7484 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) | |
7485 | abort (); | |
0d4792f7 | 7486 | |
411e1bfb AM |
7487 | switch (r_type) |
7488 | { | |
7489 | default: | |
411e1bfb AM |
7490 | break; |
7491 | ||
7492 | case R_PPC64_TOC16: | |
7493 | case R_PPC64_TOC16_LO: | |
7494 | case R_PPC64_TOC16_DS: | |
7495 | case R_PPC64_TOC16_LO_DS: | |
411e1bfb AM |
7496 | { |
7497 | /* Check for toc tls entries. */ | |
7498 | char *toc_tls; | |
951fd09b | 7499 | int retval; |
411e1bfb | 7500 | |
0d4792f7 AM |
7501 | retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms, |
7502 | rel, input_bfd); | |
951fd09b | 7503 | if (retval == 0) |
411e1bfb AM |
7504 | return FALSE; |
7505 | ||
7506 | if (toc_tls) | |
7507 | { | |
951fd09b | 7508 | tls_mask = *toc_tls; |
411e1bfb AM |
7509 | if (r_type == R_PPC64_TOC16_DS |
7510 | || r_type == R_PPC64_TOC16_LO_DS) | |
81407a69 AM |
7511 | { |
7512 | if (tls_mask != 0 | |
7513 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) | |
7514 | goto toctprel; | |
7515 | } | |
411e1bfb | 7516 | else |
951fd09b AM |
7517 | { |
7518 | /* If we found a GD reloc pair, then we might be | |
7519 | doing a GD->IE transition. */ | |
7520 | if (retval == 2) | |
7521 | { | |
7522 | tls_gd = TLS_TPRELGD; | |
7523 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7524 | goto tls_get_addr_check; | |
7525 | } | |
7526 | else if (retval == 3) | |
7527 | { | |
7528 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7529 | goto tls_get_addr_check; | |
7530 | } | |
7531 | } | |
411e1bfb AM |
7532 | } |
7533 | } | |
7534 | break; | |
7535 | ||
7536 | case R_PPC64_GOT_TPREL16_DS: | |
7537 | case R_PPC64_GOT_TPREL16_LO_DS: | |
951fd09b AM |
7538 | if (tls_mask != 0 |
7539 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7540 | { |
81407a69 | 7541 | toctprel: |
411e1bfb AM |
7542 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); |
7543 | insn &= 31 << 21; | |
7544 | insn |= 0x3c0d0000; /* addis 0,13,0 */ | |
7545 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
7546 | r_type = R_PPC64_TPREL16_HA; | |
0d4792f7 AM |
7547 | if (toc_symndx != 0) |
7548 | { | |
7549 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
7550 | /* We changed the symbol. Start over in order to | |
7551 | get h, sym, sec etc. right. */ | |
7552 | rel--; | |
7553 | continue; | |
7554 | } | |
7555 | else | |
7556 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7557 | } |
7558 | break; | |
7559 | ||
7560 | case R_PPC64_TLS: | |
951fd09b AM |
7561 | if (tls_mask != 0 |
7562 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7563 | { |
50bc7936 | 7564 | bfd_vma rtra; |
411e1bfb | 7565 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
772119ce | 7566 | if ((insn & ((0x3f << 26) | (31 << 11))) |
411e1bfb AM |
7567 | == ((31 << 26) | (13 << 11))) |
7568 | rtra = insn & ((1 << 26) - (1 << 16)); | |
772119ce | 7569 | else if ((insn & ((0x3f << 26) | (31 << 16))) |
411e1bfb AM |
7570 | == ((31 << 26) | (13 << 16))) |
7571 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
7572 | else | |
7573 | abort (); | |
7574 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
7575 | /* add -> addi. */ | |
7576 | insn = 14 << 26; | |
7577 | else if ((insn & (31 << 1)) == 23 << 1 | |
7578 | && ((insn & (31 << 6)) < 14 << 6 | |
7579 | || ((insn & (31 << 6)) >= 16 << 6 | |
7580 | && (insn & (31 << 6)) < 24 << 6))) | |
7581 | /* load and store indexed -> dform. */ | |
7582 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
7583 | else if ((insn & (31 << 1)) == 21 << 1 | |
7584 | && (insn & (0x1a << 6)) == 0) | |
7585 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
7586 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
7587 | | ((insn >> 6) & 1)); | |
7588 | else if ((insn & (31 << 1)) == 21 << 1 | |
7589 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
7590 | /* lwax -> lwa. */ | |
7591 | insn = (58 << 26) | 2; | |
7592 | else | |
7593 | abort (); | |
7594 | insn |= rtra; | |
7595 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
411e1bfb AM |
7596 | /* Was PPC64_TLS which sits on insn boundary, now |
7597 | PPC64_TPREL16_LO which is at insn+2. */ | |
7598 | rel->r_offset += 2; | |
0d4792f7 AM |
7599 | r_type = R_PPC64_TPREL16_LO; |
7600 | if (toc_symndx != 0) | |
7601 | { | |
7602 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
7603 | /* We changed the symbol. Start over in order to | |
7604 | get h, sym, sec etc. right. */ | |
7605 | rel--; | |
7606 | continue; | |
7607 | } | |
7608 | else | |
7609 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7610 | } |
7611 | break; | |
7612 | ||
411e1bfb AM |
7613 | case R_PPC64_GOT_TLSGD16_HI: |
7614 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b AM |
7615 | tls_gd = TLS_TPRELGD; |
7616 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7617 | goto tls_gdld_hi; | |
7618 | break; | |
7619 | ||
411e1bfb AM |
7620 | case R_PPC64_GOT_TLSLD16_HI: |
7621 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 7622 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
411e1bfb | 7623 | { |
951fd09b AM |
7624 | tls_gdld_hi: |
7625 | if ((tls_mask & tls_gd) != 0) | |
7626 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7627 | + R_PPC64_GOT_TPREL16_DS); | |
7628 | else | |
411e1bfb | 7629 | { |
951fd09b AM |
7630 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
7631 | rel->r_offset -= 2; | |
7632 | r_type = R_PPC64_NONE; | |
411e1bfb | 7633 | } |
951fd09b | 7634 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb AM |
7635 | } |
7636 | break; | |
7637 | ||
951fd09b AM |
7638 | case R_PPC64_GOT_TLSGD16: |
7639 | case R_PPC64_GOT_TLSGD16_LO: | |
7640 | tls_gd = TLS_TPRELGD; | |
7641 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7642 | goto tls_get_addr_check; | |
7643 | break; | |
411e1bfb | 7644 | |
951fd09b AM |
7645 | case R_PPC64_GOT_TLSLD16: |
7646 | case R_PPC64_GOT_TLSLD16_LO: | |
7647 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7648 | { | |
7649 | tls_get_addr_check: | |
7650 | if (rel + 1 < relend) | |
411e1bfb | 7651 | { |
951fd09b AM |
7652 | enum elf_ppc64_reloc_type r_type2; |
7653 | unsigned long r_symndx2; | |
7654 | struct elf_link_hash_entry *h2; | |
7655 | bfd_vma insn1, insn2, insn3; | |
7656 | bfd_vma offset; | |
7657 | ||
7658 | /* The next instruction should be a call to | |
7659 | __tls_get_addr. Peek at the reloc to be sure. */ | |
4ce794b7 | 7660 | r_type2 = ELF64_R_TYPE (rel[1].r_info); |
951fd09b AM |
7661 | r_symndx2 = ELF64_R_SYM (rel[1].r_info); |
7662 | if (r_symndx2 < symtab_hdr->sh_info | |
7663 | || (r_type2 != R_PPC64_REL14 | |
7664 | && r_type2 != R_PPC64_REL14_BRTAKEN | |
7665 | && r_type2 != R_PPC64_REL14_BRNTAKEN | |
7666 | && r_type2 != R_PPC64_REL24)) | |
7667 | break; | |
7668 | ||
7669 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
7670 | while (h2->root.type == bfd_link_hash_indirect | |
7671 | || h2->root.type == bfd_link_hash_warning) | |
7672 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
7673 | if (h2 == NULL || h2 != htab->tls_get_addr) | |
7674 | break; | |
7675 | ||
7676 | /* OK, it checks out. Replace the call. */ | |
7677 | offset = rel[1].r_offset; | |
7678 | insn1 = bfd_get_32 (output_bfd, | |
7679 | contents + rel->r_offset - 2); | |
7680 | insn3 = bfd_get_32 (output_bfd, | |
7681 | contents + offset + 4); | |
7682 | if ((tls_mask & tls_gd) != 0) | |
411e1bfb | 7683 | { |
951fd09b AM |
7684 | /* IE */ |
7685 | insn1 &= (1 << 26) - (1 << 2); | |
7686 | insn1 |= 58 << 26; /* ld */ | |
7687 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
7688 | rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); | |
7689 | if ((tls_mask & TLS_EXPLICIT) == 0) | |
7690 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7691 | + R_PPC64_GOT_TPREL16_DS); | |
7692 | else | |
7693 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; | |
7694 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7695 | } |
7696 | else | |
951fd09b AM |
7697 | { |
7698 | /* LE */ | |
7699 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ | |
7700 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7701 | if (tls_gd == 0) | |
7702 | { | |
7703 | /* Was an LD reloc. */ | |
7704 | r_symndx = 0; | |
e1918d23 AM |
7705 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
7706 | rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; | |
951fd09b | 7707 | } |
0d4792f7 AM |
7708 | else if (toc_symndx != 0) |
7709 | r_symndx = toc_symndx; | |
951fd09b AM |
7710 | r_type = R_PPC64_TPREL16_HA; |
7711 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7712 | rel[1].r_info = ELF64_R_INFO (r_symndx, | |
7713 | R_PPC64_TPREL16_LO); | |
7714 | rel[1].r_offset += 2; | |
7715 | } | |
7716 | if (insn3 == NOP | |
7717 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
7718 | { | |
7719 | insn3 = insn2; | |
7720 | insn2 = NOP; | |
7721 | rel[1].r_offset += 4; | |
7722 | } | |
7723 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); | |
7724 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7725 | bfd_put_32 (output_bfd, insn3, contents + offset + 4); | |
0d4792f7 | 7726 | if (tls_gd == 0 || toc_symndx != 0) |
951fd09b | 7727 | { |
0d4792f7 AM |
7728 | /* We changed the symbol. Start over in order |
7729 | to get h, sym, sec etc. right. */ | |
951fd09b AM |
7730 | rel--; |
7731 | continue; | |
7732 | } | |
411e1bfb | 7733 | } |
411e1bfb | 7734 | } |
411e1bfb AM |
7735 | break; |
7736 | ||
7737 | case R_PPC64_DTPMOD64: | |
951fd09b AM |
7738 | if (rel + 1 < relend |
7739 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
7740 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 7741 | { |
951fd09b AM |
7742 | if ((tls_mask & TLS_GD) == 0) |
7743 | { | |
7744 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); | |
7745 | if ((tls_mask & TLS_TPRELGD) != 0) | |
7746 | r_type = R_PPC64_TPREL64; | |
7747 | else | |
7748 | { | |
4ce794b7 | 7749 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
951fd09b AM |
7750 | r_type = R_PPC64_NONE; |
7751 | } | |
7752 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7753 | } | |
7754 | } | |
7755 | else | |
7756 | { | |
7757 | if ((tls_mask & TLS_LD) == 0) | |
411e1bfb | 7758 | { |
4ce794b7 | 7759 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
411e1bfb | 7760 | r_type = R_PPC64_NONE; |
951fd09b | 7761 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb | 7762 | } |
411e1bfb AM |
7763 | } |
7764 | break; | |
7765 | ||
7766 | case R_PPC64_TPREL64: | |
951fd09b | 7767 | if ((tls_mask & TLS_TPREL) == 0) |
411e1bfb AM |
7768 | { |
7769 | r_type = R_PPC64_NONE; | |
7770 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7771 | } | |
7772 | break; | |
7773 | } | |
7774 | ||
7775 | /* Handle other relocations that tweak non-addend part of insn. */ | |
86c76c7b | 7776 | insn = 0; |
65f38f15 | 7777 | switch (r_type) |
5bd4f169 AM |
7778 | { |
7779 | default: | |
65f38f15 | 7780 | break; |
5bd4f169 | 7781 | |
65f38f15 AM |
7782 | /* Branch taken prediction relocations. */ |
7783 | case R_PPC64_ADDR14_BRTAKEN: | |
7784 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
7785 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
7786 | /* Fall thru. */ | |
65f38f15 | 7787 | |
86c76c7b | 7788 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
7789 | case R_PPC64_ADDR14_BRNTAKEN: |
7790 | case R_PPC64_REL14_BRNTAKEN: | |
411e1bfb AM |
7791 | insn |= bfd_get_32 (output_bfd, |
7792 | contents + rel->r_offset) & ~(0x01 << 21); | |
96e0dda4 AM |
7793 | if (is_power4) |
7794 | { | |
7795 | /* Set 'a' bit. This is 0b00010 in BO field for branch | |
7796 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
7797 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
7798 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
7799 | insn |= 0x02 << 21; | |
7800 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
7801 | insn |= 0x08 << 21; | |
7802 | else | |
7803 | break; | |
7804 | } | |
65f38f15 | 7805 | else |
96e0dda4 | 7806 | { |
411e1bfb | 7807 | from = (rel->r_offset |
805fc799 AM |
7808 | + input_section->output_offset |
7809 | + input_section->output_section->vma); | |
7810 | ||
96e0dda4 | 7811 | /* Invert 'y' bit if not the default. */ |
411e1bfb | 7812 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) |
96e0dda4 AM |
7813 | insn ^= 0x01 << 21; |
7814 | } | |
86c76c7b | 7815 | |
4ce794b7 | 7816 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
65f38f15 | 7817 | break; |
5bd4f169 | 7818 | |
65f38f15 | 7819 | case R_PPC64_REL24: |
ad8e1ba5 AM |
7820 | /* Calls to functions with a different TOC, such as calls to |
7821 | shared objects, need to alter the TOC pointer. This is | |
7822 | done using a linkage stub. A REL24 branching to these | |
7823 | linkage stubs needs to be followed by a nop, as the nop | |
7824 | will be replaced with an instruction to restore the TOC | |
7825 | base pointer. */ | |
7826 | if (((h != NULL | |
7827 | && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL | |
7828 | && fdh->plt.plist != NULL) | |
7829 | || ((fdh = h, sec) != NULL | |
7830 | && sec->output_section != NULL | |
7831 | && (htab->stub_group[sec->id].toc_off | |
7832 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 | 7833 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, |
ad8e1ba5 AM |
7834 | rel, htab)) != NULL |
7835 | && (stub_entry->stub_type == ppc_stub_plt_call | |
7836 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off | |
7837 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) | |
41bd81ab | 7838 | { |
b34976b6 | 7839 | bfd_boolean can_plt_call = 0; |
721956f4 | 7840 | |
411e1bfb | 7841 | if (rel->r_offset + 8 <= input_section->_cooked_size) |
41bd81ab | 7842 | { |
411e1bfb | 7843 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); |
721956f4 AM |
7844 | if (insn == NOP |
7845 | || insn == CROR_151515 || insn == CROR_313131) | |
41bd81ab | 7846 | { |
4ce794b7 | 7847 | bfd_put_32 (input_bfd, LD_R2_40R1, |
411e1bfb | 7848 | contents + rel->r_offset + 4); |
721956f4 | 7849 | can_plt_call = 1; |
41bd81ab | 7850 | } |
5bd4f169 | 7851 | } |
721956f4 AM |
7852 | |
7853 | if (!can_plt_call) | |
7854 | { | |
ad8e1ba5 AM |
7855 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7856 | { | |
7857 | /* If this is a plain branch rather than a branch | |
7858 | and link, don't require a nop. */ | |
7859 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
7860 | if ((insn & 1) == 0) | |
7861 | can_plt_call = 1; | |
7862 | } | |
6ab189d5 AM |
7863 | else if (h != NULL |
7864 | && strcmp (h->root.root.string, | |
7865 | ".__libc_start_main") == 0) | |
7866 | { | |
7867 | /* Allow crt1 branch to go via a toc adjusting stub. */ | |
7868 | can_plt_call = 1; | |
7869 | } | |
ad8e1ba5 AM |
7870 | else |
7871 | { | |
7872 | if (strcmp (input_section->output_section->name, | |
7873 | ".init") == 0 | |
7874 | || strcmp (input_section->output_section->name, | |
7875 | ".fini") == 0) | |
7876 | (*_bfd_error_handler) | |
7877 | (_("%s(%s+0x%lx): automatic multiple TOCs " | |
7878 | "not supported using your crt files; " | |
7879 | "recompile with -mminimal-toc or upgrade gcc"), | |
7880 | bfd_archive_filename (input_bfd), | |
7881 | input_section->name, | |
7882 | (long) rel->r_offset); | |
7883 | else | |
7884 | (*_bfd_error_handler) | |
7885 | (_("%s(%s+0x%lx): sibling call optimization to `%s' " | |
7886 | "does not allow automatic multiple TOCs; " | |
7887 | "recompile with -mminimal-toc or " | |
7888 | "-fno-optimize-sibling-calls, " | |
7889 | "or make `%s' extern"), | |
7890 | bfd_archive_filename (input_bfd), | |
7891 | input_section->name, | |
7892 | (long) rel->r_offset, | |
7893 | sym_name, | |
7894 | sym_name); | |
7895 | bfd_set_error (bfd_error_bad_value); | |
7896 | ret = FALSE; | |
7897 | } | |
721956f4 AM |
7898 | } |
7899 | ||
7900 | if (can_plt_call) | |
7901 | { | |
7902 | relocation = (stub_entry->stub_offset | |
7903 | + stub_entry->stub_sec->output_offset | |
7904 | + stub_entry->stub_sec->output_section->vma); | |
ad8e1ba5 AM |
7905 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7906 | unresolved_reloc = FALSE; | |
721956f4 | 7907 | } |
5bd4f169 | 7908 | } |
e86ce104 AM |
7909 | |
7910 | if (h != NULL | |
7911 | && h->root.type == bfd_link_hash_undefweak | |
721956f4 | 7912 | && relocation == 0 |
411e1bfb | 7913 | && rel->r_addend == 0) |
e86ce104 | 7914 | { |
721956f4 AM |
7915 | /* Tweak calls to undefined weak functions to point at a |
7916 | blr. We can thus call a weak function without first | |
7917 | checking whether the function is defined. We have a | |
7918 | blr at the end of .sfpr. */ | |
805fc799 | 7919 | BFD_ASSERT (htab->sfpr->_raw_size != 0); |
721956f4 AM |
7920 | relocation = (htab->sfpr->_raw_size - 4 |
7921 | + htab->sfpr->output_offset | |
7922 | + htab->sfpr->output_section->vma); | |
411e1bfb | 7923 | from = (rel->r_offset |
721956f4 AM |
7924 | + input_section->output_offset |
7925 | + input_section->output_section->vma); | |
805fc799 | 7926 | |
721956f4 AM |
7927 | /* But let's not be silly about it. If the blr isn't in |
7928 | reach, just go to the next instruction. */ | |
805fc799 AM |
7929 | if (relocation - from + (1 << 25) >= (1 << 26) |
7930 | || htab->sfpr->_raw_size == 0) | |
721956f4 | 7931 | relocation = from + 4; |
e86ce104 | 7932 | } |
65f38f15 AM |
7933 | break; |
7934 | } | |
5bd4f169 | 7935 | |
65f38f15 | 7936 | /* Set `addend'. */ |
411e1bfb AM |
7937 | tls_type = 0; |
7938 | addend = rel->r_addend; | |
65f38f15 AM |
7939 | switch (r_type) |
7940 | { | |
7941 | default: | |
7942 | (*_bfd_error_handler) | |
7943 | (_("%s: unknown relocation type %d for symbol %s"), | |
7944 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); | |
5bd4f169 | 7945 | |
65f38f15 | 7946 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 7947 | ret = FALSE; |
65f38f15 | 7948 | continue; |
5bd4f169 | 7949 | |
65f38f15 | 7950 | case R_PPC64_NONE: |
411e1bfb | 7951 | case R_PPC64_TLS: |
04c9666a AM |
7952 | case R_PPC64_GNU_VTINHERIT: |
7953 | case R_PPC64_GNU_VTENTRY: | |
65f38f15 | 7954 | continue; |
5bd4f169 AM |
7955 | |
7956 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
7957 | address in the GOT as relocation value instead of the | |
411e1bfb | 7958 | symbol's value itself. Also, create a GOT entry for the |
5bd4f169 | 7959 | symbol and put the symbol value there. */ |
411e1bfb AM |
7960 | case R_PPC64_GOT_TLSGD16: |
7961 | case R_PPC64_GOT_TLSGD16_LO: | |
7962 | case R_PPC64_GOT_TLSGD16_HI: | |
7963 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 7964 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
7965 | goto dogot; |
7966 | ||
7967 | case R_PPC64_GOT_TLSLD16: | |
7968 | case R_PPC64_GOT_TLSLD16_LO: | |
7969 | case R_PPC64_GOT_TLSLD16_HI: | |
7970 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 7971 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
7972 | goto dogot; |
7973 | ||
7974 | case R_PPC64_GOT_TPREL16_DS: | |
7975 | case R_PPC64_GOT_TPREL16_LO_DS: | |
7976 | case R_PPC64_GOT_TPREL16_HI: | |
7977 | case R_PPC64_GOT_TPREL16_HA: | |
7978 | tls_type = TLS_TLS | TLS_TPREL; | |
7979 | goto dogot; | |
7980 | ||
7981 | case R_PPC64_GOT_DTPREL16_DS: | |
7982 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
7983 | case R_PPC64_GOT_DTPREL16_HI: | |
7984 | case R_PPC64_GOT_DTPREL16_HA: | |
7985 | tls_type = TLS_TLS | TLS_DTPREL; | |
7986 | goto dogot; | |
7987 | ||
65f38f15 AM |
7988 | case R_PPC64_GOT16: |
7989 | case R_PPC64_GOT16_LO: | |
7990 | case R_PPC64_GOT16_HI: | |
7991 | case R_PPC64_GOT16_HA: | |
7992 | case R_PPC64_GOT16_DS: | |
7993 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb | 7994 | dogot: |
5bd4f169 AM |
7995 | { |
7996 | /* Relocation is to the entry for this symbol in the global | |
7997 | offset table. */ | |
e717da7e | 7998 | asection *got; |
d881513a | 7999 | bfd_vma *offp; |
5bd4f169 | 8000 | bfd_vma off; |
d881513a | 8001 | unsigned long indx = 0; |
65f38f15 | 8002 | |
d881513a AM |
8003 | if (tls_type == (TLS_TLS | TLS_LD) |
8004 | && (h == NULL | |
8005 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
e717da7e | 8006 | offp = &ppc64_tlsld_got (input_bfd)->offset; |
411e1bfb | 8007 | else |
5bd4f169 | 8008 | { |
d881513a | 8009 | struct got_entry *ent; |
5bd4f169 | 8010 | |
d881513a AM |
8011 | if (h != NULL) |
8012 | { | |
8013 | bfd_boolean dyn = htab->elf.dynamic_sections_created; | |
f4656909 | 8014 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
d881513a | 8015 | || (info->shared |
586119b3 | 8016 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
d881513a AM |
8017 | /* This is actually a static link, or it is a |
8018 | -Bsymbolic link and the symbol is defined | |
8019 | locally, or the symbol was forced to be local | |
8020 | because of a version file. */ | |
8021 | ; | |
8022 | else | |
8023 | { | |
8024 | indx = h->dynindx; | |
8025 | unresolved_reloc = FALSE; | |
8026 | } | |
8027 | ent = h->got.glist; | |
8028 | } | |
411e1bfb | 8029 | else |
5bd4f169 | 8030 | { |
d881513a AM |
8031 | if (local_got_ents == NULL) |
8032 | abort (); | |
8033 | ent = local_got_ents[r_symndx]; | |
5bd4f169 | 8034 | } |
d881513a AM |
8035 | |
8036 | for (; ent != NULL; ent = ent->next) | |
8037 | if (ent->addend == rel->r_addend | |
e717da7e | 8038 | && ent->owner == input_bfd |
d881513a AM |
8039 | && ent->tls_type == tls_type) |
8040 | break; | |
8041 | if (ent == NULL) | |
8042 | abort (); | |
8043 | offp = &ent->got.offset; | |
5bd4f169 | 8044 | } |
411e1bfb | 8045 | |
e717da7e AM |
8046 | got = ppc64_elf_tdata (input_bfd)->got; |
8047 | if (got == NULL) | |
8048 | abort (); | |
8049 | ||
411e1bfb AM |
8050 | /* The offset must always be a multiple of 8. We use the |
8051 | least significant bit to record whether we have already | |
8052 | processed this entry. */ | |
d881513a | 8053 | off = *offp; |
411e1bfb AM |
8054 | if ((off & 1) != 0) |
8055 | off &= ~1; | |
5bd4f169 AM |
8056 | else |
8057 | { | |
411e1bfb AM |
8058 | /* Generate relocs for the dynamic linker, except in |
8059 | the case of TLSLD where we'll use one entry per | |
8060 | module. */ | |
e717da7e AM |
8061 | asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; |
8062 | ||
d881513a | 8063 | *offp = off | 1; |
4e795f50 AM |
8064 | if ((info->shared || indx != 0) |
8065 | && (h == NULL | |
8066 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8067 | || h->root.type != bfd_link_hash_undefweak)) | |
5bd4f169 | 8068 | { |
e717da7e AM |
8069 | outrel.r_offset = (got->output_section->vma |
8070 | + got->output_offset | |
411e1bfb | 8071 | + off); |
81407a69 | 8072 | outrel.r_addend = rel->r_addend; |
d881513a | 8073 | if (tls_type & (TLS_LD | TLS_GD)) |
5bd4f169 | 8074 | { |
411e1bfb | 8075 | outrel.r_addend = 0; |
e515b051 | 8076 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
d881513a AM |
8077 | if (tls_type == (TLS_TLS | TLS_GD)) |
8078 | { | |
e717da7e AM |
8079 | loc = relgot->contents; |
8080 | loc += (relgot->reloc_count++ | |
d881513a AM |
8081 | * sizeof (Elf64_External_Rela)); |
8082 | bfd_elf64_swap_reloca_out (output_bfd, | |
8083 | &outrel, loc); | |
e515b051 | 8084 | outrel.r_offset += 8; |
81407a69 | 8085 | outrel.r_addend = rel->r_addend; |
d881513a AM |
8086 | outrel.r_info |
8087 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); | |
d881513a | 8088 | } |
411e1bfb | 8089 | } |
951fd09b | 8090 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
411e1bfb | 8091 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
951fd09b | 8092 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb AM |
8093 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
8094 | else if (indx == 0) | |
81407a69 AM |
8095 | { |
8096 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE); | |
8097 | ||
8098 | /* Write the .got section contents for the sake | |
8099 | of prelink. */ | |
e717da7e | 8100 | loc = got->contents + off; |
23fbd6fa JJ |
8101 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
8102 | loc); | |
81407a69 | 8103 | } |
411e1bfb AM |
8104 | else |
8105 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); | |
81407a69 AM |
8106 | |
8107 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) | |
e515b051 AM |
8108 | { |
8109 | outrel.r_addend += relocation; | |
8110 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 8111 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 8112 | } |
e717da7e AM |
8113 | loc = relgot->contents; |
8114 | loc += (relgot->reloc_count++ | |
411e1bfb AM |
8115 | * sizeof (Elf64_External_Rela)); |
8116 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
8117 | } | |
8118 | ||
ad8e1ba5 | 8119 | /* Init the .got section contents here if we're not |
81407a69 | 8120 | emitting a reloc. */ |
d881513a | 8121 | else |
411e1bfb | 8122 | { |
d881513a | 8123 | relocation += rel->r_addend; |
7b609f53 AM |
8124 | if (tls_type == (TLS_TLS | TLS_LD)) |
8125 | relocation = 1; | |
8126 | else if (tls_type != 0) | |
411e1bfb | 8127 | { |
e1918d23 | 8128 | relocation -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 8129 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 8130 | relocation += DTP_OFFSET - TP_OFFSET; |
5bd4f169 | 8131 | |
7b609f53 AM |
8132 | if (tls_type == (TLS_TLS | TLS_GD)) |
8133 | { | |
8134 | bfd_put_64 (output_bfd, relocation, | |
e717da7e | 8135 | got->contents + off + 8); |
7b609f53 AM |
8136 | relocation = 1; |
8137 | } | |
411e1bfb | 8138 | } |
7b609f53 | 8139 | |
411e1bfb | 8140 | bfd_put_64 (output_bfd, relocation, |
e717da7e | 8141 | got->contents + off); |
5bd4f169 AM |
8142 | } |
8143 | } | |
8144 | ||
65f38f15 AM |
8145 | if (off >= (bfd_vma) -2) |
8146 | abort (); | |
8147 | ||
e717da7e | 8148 | relocation = got->output_offset + off; |
65f38f15 | 8149 | |
5bd4f169 | 8150 | /* TOC base (r2) is TOC start plus 0x8000. */ |
e717da7e | 8151 | addend = -TOC_BASE_OFF; |
5bd4f169 | 8152 | } |
65f38f15 AM |
8153 | break; |
8154 | ||
8155 | case R_PPC64_PLT16_HA: | |
8156 | case R_PPC64_PLT16_HI: | |
8157 | case R_PPC64_PLT16_LO: | |
8158 | case R_PPC64_PLT32: | |
8159 | case R_PPC64_PLT64: | |
8160 | /* Relocation is to the entry for this symbol in the | |
8161 | procedure linkage table. */ | |
8162 | ||
8163 | /* Resolve a PLT reloc against a local symbol directly, | |
8164 | without using the procedure linkage table. */ | |
8165 | if (h == NULL) | |
8166 | break; | |
8167 | ||
411e1bfb AM |
8168 | /* It's possible that we didn't make a PLT entry for this |
8169 | symbol. This happens when statically linking PIC code, | |
8170 | or when using -Bsymbolic. Go find a match if there is a | |
8171 | PLT entry. */ | |
4ce794b7 | 8172 | if (htab->plt != NULL) |
65f38f15 | 8173 | { |
411e1bfb AM |
8174 | struct plt_entry *ent; |
8175 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8176 | if (ent->addend == rel->r_addend | |
8177 | && ent->plt.offset != (bfd_vma) -1) | |
8178 | { | |
4ce794b7 AM |
8179 | relocation = (htab->plt->output_section->vma |
8180 | + htab->plt->output_offset | |
411e1bfb AM |
8181 | + ent->plt.offset); |
8182 | unresolved_reloc = FALSE; | |
8183 | } | |
65f38f15 | 8184 | } |
65f38f15 | 8185 | break; |
5bd4f169 | 8186 | |
0b13192e AM |
8187 | case R_PPC64_TOC: |
8188 | /* Relocation value is TOC base. */ | |
8189 | relocation = TOCstart; | |
8190 | if (r_symndx == 0) | |
8191 | relocation += htab->stub_group[input_section->id].toc_off; | |
8517fae7 AM |
8192 | else if (unresolved_reloc) |
8193 | ; | |
8194 | else if (sec != NULL && sec->id <= htab->top_id) | |
0b13192e AM |
8195 | relocation += htab->stub_group[sec->id].toc_off; |
8196 | else | |
8197 | unresolved_reloc = TRUE; | |
8198 | goto dodyn2; | |
8199 | ||
5bd4f169 AM |
8200 | /* TOC16 relocs. We want the offset relative to the TOC base, |
8201 | which is the address of the start of the TOC plus 0x8000. | |
8202 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
8203 | in this order. */ | |
65f38f15 AM |
8204 | case R_PPC64_TOC16: |
8205 | case R_PPC64_TOC16_LO: | |
8206 | case R_PPC64_TOC16_HI: | |
8207 | case R_PPC64_TOC16_DS: | |
8208 | case R_PPC64_TOC16_LO_DS: | |
8209 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 8210 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
5bd4f169 AM |
8211 | break; |
8212 | ||
8213 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
8214 | case R_PPC64_SECTOFF: |
8215 | case R_PPC64_SECTOFF_LO: | |
8216 | case R_PPC64_SECTOFF_HI: | |
8217 | case R_PPC64_SECTOFF_DS: | |
8218 | case R_PPC64_SECTOFF_LO_DS: | |
8219 | case R_PPC64_SECTOFF_HA: | |
4ce794b7 | 8220 | if (sec != NULL) |
65f38f15 | 8221 | addend -= sec->output_section->vma; |
5bd4f169 AM |
8222 | break; |
8223 | ||
721956f4 AM |
8224 | case R_PPC64_REL14: |
8225 | case R_PPC64_REL14_BRNTAKEN: | |
8226 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
8227 | case R_PPC64_REL24: |
8228 | break; | |
8229 | ||
411e1bfb AM |
8230 | case R_PPC64_TPREL16: |
8231 | case R_PPC64_TPREL16_LO: | |
8232 | case R_PPC64_TPREL16_HI: | |
8233 | case R_PPC64_TPREL16_HA: | |
8234 | case R_PPC64_TPREL16_DS: | |
8235 | case R_PPC64_TPREL16_LO_DS: | |
8236 | case R_PPC64_TPREL16_HIGHER: | |
8237 | case R_PPC64_TPREL16_HIGHERA: | |
8238 | case R_PPC64_TPREL16_HIGHEST: | |
8239 | case R_PPC64_TPREL16_HIGHESTA: | |
e1918d23 | 8240 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8241 | if (info->shared) |
8242 | /* The TPREL16 relocs shouldn't really be used in shared | |
8243 | libs as they will result in DT_TEXTREL being set, but | |
8244 | support them anyway. */ | |
8245 | goto dodyn; | |
8246 | break; | |
8247 | ||
8248 | case R_PPC64_DTPREL16: | |
8249 | case R_PPC64_DTPREL16_LO: | |
8250 | case R_PPC64_DTPREL16_HI: | |
8251 | case R_PPC64_DTPREL16_HA: | |
8252 | case R_PPC64_DTPREL16_DS: | |
8253 | case R_PPC64_DTPREL16_LO_DS: | |
8254 | case R_PPC64_DTPREL16_HIGHER: | |
8255 | case R_PPC64_DTPREL16_HIGHERA: | |
8256 | case R_PPC64_DTPREL16_HIGHEST: | |
8257 | case R_PPC64_DTPREL16_HIGHESTA: | |
e1918d23 | 8258 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8259 | break; |
8260 | ||
e515b051 AM |
8261 | case R_PPC64_DTPMOD64: |
8262 | relocation = 1; | |
8263 | addend = 0; | |
8264 | goto dodyn; | |
8265 | ||
411e1bfb | 8266 | case R_PPC64_TPREL64: |
e1918d23 | 8267 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8268 | goto dodyn; |
8269 | ||
8270 | case R_PPC64_DTPREL64: | |
e1918d23 | 8271 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8272 | /* Fall thru */ |
8273 | ||
65f38f15 AM |
8274 | /* Relocations that may need to be propagated if this is a |
8275 | dynamic object. */ | |
04c9666a | 8276 | case R_PPC64_REL30: |
65f38f15 AM |
8277 | case R_PPC64_REL32: |
8278 | case R_PPC64_REL64: | |
8279 | case R_PPC64_ADDR14: | |
8280 | case R_PPC64_ADDR14_BRNTAKEN: | |
8281 | case R_PPC64_ADDR14_BRTAKEN: | |
8282 | case R_PPC64_ADDR16: | |
8283 | case R_PPC64_ADDR16_DS: | |
8284 | case R_PPC64_ADDR16_HA: | |
8285 | case R_PPC64_ADDR16_HI: | |
8286 | case R_PPC64_ADDR16_HIGHER: | |
8287 | case R_PPC64_ADDR16_HIGHERA: | |
8288 | case R_PPC64_ADDR16_HIGHEST: | |
8289 | case R_PPC64_ADDR16_HIGHESTA: | |
8290 | case R_PPC64_ADDR16_LO: | |
8291 | case R_PPC64_ADDR16_LO_DS: | |
8292 | case R_PPC64_ADDR24: | |
65f38f15 AM |
8293 | case R_PPC64_ADDR32: |
8294 | case R_PPC64_ADDR64: | |
8295 | case R_PPC64_UADDR16: | |
8296 | case R_PPC64_UADDR32: | |
8297 | case R_PPC64_UADDR64: | |
ec338859 AM |
8298 | /* r_symndx will be zero only for relocs against symbols |
8299 | from removed linkonce sections, or sections discarded by | |
8300 | a linker script. */ | |
411e1bfb | 8301 | dodyn: |
5d1634d7 AM |
8302 | if (r_symndx == 0) |
8303 | break; | |
8304 | /* Fall thru. */ | |
8305 | ||
0b13192e | 8306 | dodyn2: |
5d1634d7 | 8307 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
8308 | break; |
8309 | ||
41bd81ab AM |
8310 | if (NO_OPD_RELOCS && is_opd) |
8311 | break; | |
8312 | ||
65f38f15 | 8313 | if ((info->shared |
4e795f50 AM |
8314 | && (h == NULL |
8315 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8316 | || h->root.type != bfd_link_hash_undefweak) | |
411e1bfb | 8317 | && (MUST_BE_DYN_RELOC (r_type) |
f6c52c13 | 8318 | || !SYMBOL_CALLS_LOCAL (info, h))) |
f4656909 AM |
8319 | || (ELIMINATE_COPY_RELOCS |
8320 | && !info->shared | |
65f38f15 AM |
8321 | && h != NULL |
8322 | && h->dynindx != -1 | |
8323 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
8324 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
8325 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
65f38f15 AM |
8326 | { |
8327 | Elf_Internal_Rela outrel; | |
b34976b6 | 8328 | bfd_boolean skip, relocate; |
65f38f15 | 8329 | asection *sreloc; |
947216bf | 8330 | bfd_byte *loc; |
1cf1f670 | 8331 | bfd_vma out_off; |
65f38f15 AM |
8332 | |
8333 | /* When generating a dynamic object, these relocations | |
8334 | are copied into the output file to be resolved at run | |
8335 | time. */ | |
8336 | ||
b34976b6 AM |
8337 | skip = FALSE; |
8338 | relocate = FALSE; | |
65f38f15 | 8339 | |
1cf1f670 AM |
8340 | out_off = _bfd_elf_section_offset (output_bfd, info, |
8341 | input_section, rel->r_offset); | |
8342 | if (out_off == (bfd_vma) -1) | |
b34976b6 | 8343 | skip = TRUE; |
1cf1f670 | 8344 | else if (out_off == (bfd_vma) -2) |
b34976b6 | 8345 | skip = TRUE, relocate = TRUE; |
1cf1f670 AM |
8346 | out_off += (input_section->output_section->vma |
8347 | + input_section->output_offset); | |
8348 | outrel.r_offset = out_off; | |
411e1bfb | 8349 | outrel.r_addend = rel->r_addend; |
65f38f15 | 8350 | |
1cf1f670 AM |
8351 | /* Optimize unaligned reloc use. */ |
8352 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) | |
8353 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) | |
8354 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; | |
8355 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) | |
8356 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) | |
8357 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; | |
8358 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) | |
8359 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) | |
8360 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; | |
8361 | ||
65f38f15 | 8362 | if (skip) |
0bb2d96a | 8363 | memset (&outrel, 0, sizeof outrel); |
f6c52c13 | 8364 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
0b13192e AM |
8365 | && !is_opd |
8366 | && r_type != R_PPC64_TOC) | |
0bb2d96a | 8367 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
65f38f15 AM |
8368 | else |
8369 | { | |
41bd81ab AM |
8370 | /* This symbol is local, or marked to become local, |
8371 | or this is an opd section reloc which must point | |
8372 | at a local function. */ | |
65f38f15 | 8373 | outrel.r_addend += relocation; |
e86ce104 | 8374 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 8375 | { |
3fad3c7c | 8376 | if (is_opd && h != NULL) |
afbe61cf AM |
8377 | { |
8378 | /* Lie about opd entries. This case occurs | |
8379 | when building shared libraries and we | |
8380 | reference a function in another shared | |
3fad3c7c AM |
8381 | lib. The same thing happens for a weak |
8382 | definition in an application that's | |
8383 | overridden by a strong definition in a | |
8384 | shared lib. (I believe this is a generic | |
8385 | bug in binutils handling of weak syms.) | |
8386 | In these cases we won't use the opd | |
1e2f5b6e | 8387 | entry in this lib. */ |
b34976b6 | 8388 | unresolved_reloc = FALSE; |
afbe61cf | 8389 | } |
65f38f15 | 8390 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
81407a69 AM |
8391 | |
8392 | /* We need to relocate .opd contents for ld.so. | |
8393 | Prelink also wants simple and consistent rules | |
8394 | for relocs. This make all RELATIVE relocs have | |
8395 | *r_offset equal to r_addend. */ | |
8396 | relocate = TRUE; | |
65f38f15 AM |
8397 | } |
8398 | else | |
8399 | { | |
8400 | long indx = 0; | |
8401 | ||
41bd81ab | 8402 | if (bfd_is_abs_section (sec)) |
65f38f15 AM |
8403 | ; |
8404 | else if (sec == NULL || sec->owner == NULL) | |
8405 | { | |
8406 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8407 | return FALSE; |
65f38f15 AM |
8408 | } |
8409 | else | |
8410 | { | |
8411 | asection *osec; | |
8412 | ||
8413 | osec = sec->output_section; | |
8414 | indx = elf_section_data (osec)->dynindx; | |
8415 | ||
8416 | /* We are turning this relocation into one | |
8417 | against a section symbol, so subtract out | |
8418 | the output section's address but not the | |
8419 | offset of the input section in the output | |
8420 | section. */ | |
8421 | outrel.r_addend -= osec->vma; | |
8422 | } | |
8423 | ||
8424 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
8425 | } | |
8426 | } | |
8427 | ||
8428 | sreloc = elf_section_data (input_section)->sreloc; | |
8429 | if (sreloc == NULL) | |
8430 | abort (); | |
8431 | ||
947216bf AM |
8432 | loc = sreloc->contents; |
8433 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
8434 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
8435 | ||
8436 | /* If this reloc is against an external symbol, it will | |
8437 | be computed at runtime, so there's no need to do | |
81407a69 AM |
8438 | anything now. However, for the sake of prelink ensure |
8439 | that the section contents are a known value. */ | |
65f38f15 | 8440 | if (! relocate) |
81407a69 AM |
8441 | { |
8442 | unresolved_reloc = FALSE; | |
8443 | /* The value chosen here is quite arbitrary as ld.so | |
8444 | ignores section contents except for the special | |
8445 | case of .opd where the contents might be accessed | |
8446 | before relocation. Choose zero, as that won't | |
8447 | cause reloc overflow. */ | |
8448 | relocation = 0; | |
8449 | addend = 0; | |
8450 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs | |
8451 | to improve backward compatibility with older | |
8452 | versions of ld. */ | |
8453 | if (r_type == R_PPC64_ADDR64) | |
8454 | addend = outrel.r_addend; | |
8455 | /* Adjust pc_relative relocs to have zero in *r_offset. */ | |
4ce794b7 | 8456 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
000732f7 AM |
8457 | addend = (input_section->output_section->vma |
8458 | + input_section->output_offset | |
8459 | + rel->r_offset); | |
81407a69 | 8460 | } |
65f38f15 | 8461 | } |
5bd4f169 AM |
8462 | break; |
8463 | ||
65f38f15 AM |
8464 | case R_PPC64_COPY: |
8465 | case R_PPC64_GLOB_DAT: | |
8466 | case R_PPC64_JMP_SLOT: | |
8467 | case R_PPC64_RELATIVE: | |
8468 | /* We shouldn't ever see these dynamic relocs in relocatable | |
8469 | files. */ | |
ae9a127f | 8470 | /* Fall through. */ |
65f38f15 AM |
8471 | |
8472 | case R_PPC64_PLTGOT16: | |
8473 | case R_PPC64_PLTGOT16_DS: | |
8474 | case R_PPC64_PLTGOT16_HA: | |
8475 | case R_PPC64_PLTGOT16_HI: | |
8476 | case R_PPC64_PLTGOT16_LO: | |
8477 | case R_PPC64_PLTGOT16_LO_DS: | |
8478 | case R_PPC64_PLTREL32: | |
8479 | case R_PPC64_PLTREL64: | |
8480 | /* These ones haven't been implemented yet. */ | |
8481 | ||
8482 | (*_bfd_error_handler) | |
7b609f53 | 8483 | (_("%s: relocation %s is not supported for symbol %s."), |
65f38f15 | 8484 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8485 | ppc64_elf_howto_table[r_type]->name, sym_name); |
5bd4f169 AM |
8486 | |
8487 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 8488 | ret = FALSE; |
5bd4f169 | 8489 | continue; |
65f38f15 | 8490 | } |
5bd4f169 | 8491 | |
65f38f15 AM |
8492 | /* Do any further special processing. */ |
8493 | switch (r_type) | |
8494 | { | |
8495 | default: | |
8496 | break; | |
8497 | ||
8498 | case R_PPC64_ADDR16_HA: | |
8499 | case R_PPC64_ADDR16_HIGHERA: | |
8500 | case R_PPC64_ADDR16_HIGHESTA: | |
86bbe32f AM |
8501 | case R_PPC64_GOT16_HA: |
8502 | case R_PPC64_PLTGOT16_HA: | |
65f38f15 AM |
8503 | case R_PPC64_PLT16_HA: |
8504 | case R_PPC64_TOC16_HA: | |
8505 | case R_PPC64_SECTOFF_HA: | |
411e1bfb AM |
8506 | case R_PPC64_TPREL16_HA: |
8507 | case R_PPC64_DTPREL16_HA: | |
8508 | case R_PPC64_GOT_TLSGD16_HA: | |
8509 | case R_PPC64_GOT_TLSLD16_HA: | |
8510 | case R_PPC64_GOT_TPREL16_HA: | |
8511 | case R_PPC64_GOT_DTPREL16_HA: | |
8512 | case R_PPC64_TPREL16_HIGHER: | |
8513 | case R_PPC64_TPREL16_HIGHERA: | |
8514 | case R_PPC64_TPREL16_HIGHEST: | |
8515 | case R_PPC64_TPREL16_HIGHESTA: | |
8516 | case R_PPC64_DTPREL16_HIGHER: | |
8517 | case R_PPC64_DTPREL16_HIGHERA: | |
8518 | case R_PPC64_DTPREL16_HIGHEST: | |
8519 | case R_PPC64_DTPREL16_HIGHESTA: | |
65f38f15 AM |
8520 | /* It's just possible that this symbol is a weak symbol |
8521 | that's not actually defined anywhere. In that case, | |
8522 | 'sec' would be NULL, and we should leave the symbol | |
8523 | alone (it will be set to zero elsewhere in the link). */ | |
8524 | if (sec != NULL) | |
e515b051 AM |
8525 | /* Add 0x10000 if sign bit in 0:15 is set. |
8526 | Bits 0:15 are not used. */ | |
8527 | addend += 0x8000; | |
65f38f15 AM |
8528 | break; |
8529 | ||
8530 | case R_PPC64_ADDR16_DS: | |
8531 | case R_PPC64_ADDR16_LO_DS: | |
8532 | case R_PPC64_GOT16_DS: | |
8533 | case R_PPC64_GOT16_LO_DS: | |
8534 | case R_PPC64_PLT16_LO_DS: | |
8535 | case R_PPC64_SECTOFF_DS: | |
8536 | case R_PPC64_SECTOFF_LO_DS: | |
8537 | case R_PPC64_TOC16_DS: | |
8538 | case R_PPC64_TOC16_LO_DS: | |
8539 | case R_PPC64_PLTGOT16_DS: | |
8540 | case R_PPC64_PLTGOT16_LO_DS: | |
411e1bfb AM |
8541 | case R_PPC64_GOT_TPREL16_DS: |
8542 | case R_PPC64_GOT_TPREL16_LO_DS: | |
8543 | case R_PPC64_GOT_DTPREL16_DS: | |
8544 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
8545 | case R_PPC64_TPREL16_DS: | |
8546 | case R_PPC64_TPREL16_LO_DS: | |
8547 | case R_PPC64_DTPREL16_DS: | |
8548 | case R_PPC64_DTPREL16_LO_DS: | |
adadcc0c AM |
8549 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
8550 | mask = 3; | |
8551 | /* If this reloc is against an lq insn, then the value must be | |
8552 | a multiple of 16. This is somewhat of a hack, but the | |
8553 | "correct" way to do this by defining _DQ forms of all the | |
8554 | _DS relocs bloats all reloc switches in this file. It | |
8555 | doesn't seem to make much sense to use any of these relocs | |
8556 | in data, so testing the insn should be safe. */ | |
494dac0c | 8557 | if ((insn & (0x3f << 26)) == (56u << 26)) |
adadcc0c AM |
8558 | mask = 15; |
8559 | if (((relocation + addend) & mask) != 0) | |
65f38f15 AM |
8560 | { |
8561 | (*_bfd_error_handler) | |
adadcc0c | 8562 | (_("%s: error: relocation %s not a multiple of %d"), |
65f38f15 | 8563 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8564 | ppc64_elf_howto_table[r_type]->name, |
adadcc0c | 8565 | mask + 1); |
65f38f15 | 8566 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 8567 | ret = FALSE; |
65f38f15 AM |
8568 | continue; |
8569 | } | |
8570 | break; | |
721956f4 AM |
8571 | |
8572 | case R_PPC64_REL14: | |
8573 | case R_PPC64_REL14_BRNTAKEN: | |
8574 | case R_PPC64_REL14_BRTAKEN: | |
8575 | max_br_offset = 1 << 15; | |
8576 | goto branch_check; | |
8577 | ||
8578 | case R_PPC64_REL24: | |
8579 | max_br_offset = 1 << 25; | |
8580 | ||
8581 | branch_check: | |
ad8e1ba5 AM |
8582 | /* If the branch is out of reach or the TOC register needs |
8583 | adjusting, then redirect the call to the local stub for | |
8584 | this function. */ | |
411e1bfb | 8585 | from = (rel->r_offset |
721956f4 AM |
8586 | + input_section->output_offset |
8587 | + input_section->output_section->vma); | |
ad8e1ba5 AM |
8588 | if ((relocation + addend - from + max_br_offset >= 2 * max_br_offset |
8589 | || (sec != NULL | |
8590 | && sec->output_section != NULL | |
8f3bab57 | 8591 | && sec->id <= htab->top_id |
ad8e1ba5 AM |
8592 | && (htab->stub_group[sec->id].toc_off |
8593 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 AM |
8594 | && (stub_entry = ppc_get_stub_entry (input_section, sec, h, |
8595 | rel, htab)) != NULL) | |
8596 | { | |
8597 | /* Munge up the value and addend so that we call the stub | |
8598 | rather than the procedure directly. */ | |
8599 | relocation = (stub_entry->stub_offset | |
8600 | + stub_entry->stub_sec->output_offset | |
8601 | + stub_entry->stub_sec->output_section->vma); | |
8602 | addend = 0; | |
8603 | } | |
8604 | break; | |
5bd4f169 AM |
8605 | } |
8606 | ||
239e1f3a AM |
8607 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
8608 | because such sections are not SEC_ALLOC and thus ld.so will | |
8609 | not process them. */ | |
65f38f15 | 8610 | if (unresolved_reloc |
239e1f3a | 8611 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
65f38f15 | 8612 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
9c07fe7c AM |
8613 | { |
8614 | (*_bfd_error_handler) | |
7b609f53 | 8615 | (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), |
9c07fe7c AM |
8616 | bfd_archive_filename (input_bfd), |
8617 | bfd_get_section_name (input_bfd, input_section), | |
8618 | (long) rel->r_offset, | |
7b609f53 | 8619 | ppc64_elf_howto_table[(int) r_type]->name, |
9c07fe7c | 8620 | h->root.root.string); |
b34976b6 | 8621 | ret = FALSE; |
9c07fe7c | 8622 | } |
5bd4f169 | 8623 | |
65f38f15 | 8624 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
8625 | input_bfd, |
8626 | input_section, | |
8627 | contents, | |
411e1bfb | 8628 | rel->r_offset, |
5bd4f169 AM |
8629 | relocation, |
8630 | addend); | |
8631 | ||
ef60b7ff | 8632 | if (r != bfd_reloc_ok) |
5bd4f169 | 8633 | { |
cd27b276 AM |
8634 | if (sym_name == NULL) |
8635 | sym_name = "(null)"; | |
8636 | if (r == bfd_reloc_overflow) | |
5bd4f169 | 8637 | { |
cd27b276 AM |
8638 | if (warned) |
8639 | continue; | |
8640 | if (h != NULL | |
8641 | && h->root.type == bfd_link_hash_undefweak | |
4ce794b7 | 8642 | && ppc64_elf_howto_table[r_type]->pc_relative) |
5bd4f169 AM |
8643 | { |
8644 | /* Assume this is a call protected by other code that | |
8645 | detects the symbol is undefined. If this is the case, | |
8646 | we can safely ignore the overflow. If not, the | |
8647 | program is hosed anyway, and a little warning isn't | |
8648 | going to help. */ | |
8649 | ||
8650 | continue; | |
8651 | } | |
8652 | ||
ef60b7ff | 8653 | if (!((*info->callbacks->reloc_overflow) |
4ce794b7 | 8654 | (info, sym_name, ppc64_elf_howto_table[r_type]->name, |
411e1bfb | 8655 | rel->r_addend, input_bfd, input_section, rel->r_offset))) |
b34976b6 | 8656 | return FALSE; |
ef60b7ff AM |
8657 | } |
8658 | else | |
8659 | { | |
8660 | (*_bfd_error_handler) | |
7b609f53 | 8661 | (_("%s(%s+0x%lx): %s reloc against `%s': error %d"), |
ef60b7ff AM |
8662 | bfd_archive_filename (input_bfd), |
8663 | bfd_get_section_name (input_bfd, input_section), | |
7b609f53 | 8664 | (long) rel->r_offset, |
4ce794b7 | 8665 | ppc64_elf_howto_table[r_type]->name, |
7b609f53 AM |
8666 | sym_name, |
8667 | (int) r); | |
b34976b6 | 8668 | ret = FALSE; |
ef60b7ff | 8669 | } |
5bd4f169 | 8670 | } |
5bd4f169 AM |
8671 | } |
8672 | ||
5bd4f169 AM |
8673 | return ret; |
8674 | } | |
8675 | ||
8676 | /* Finish up dynamic symbol handling. We set the contents of various | |
8677 | dynamic sections here. */ | |
8678 | ||
b34976b6 | 8679 | static bfd_boolean |
4ce794b7 AM |
8680 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
8681 | struct bfd_link_info *info, | |
8682 | struct elf_link_hash_entry *h, | |
8683 | Elf_Internal_Sym *sym) | |
5bd4f169 | 8684 | { |
65f38f15 | 8685 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
8686 | bfd *dynobj; |
8687 | ||
65f38f15 AM |
8688 | htab = ppc_hash_table (info); |
8689 | dynobj = htab->elf.dynobj; | |
5bd4f169 | 8690 | |
411e1bfb | 8691 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
5bd4f169 | 8692 | { |
411e1bfb | 8693 | struct plt_entry *ent; |
65f38f15 | 8694 | Elf_Internal_Rela rela; |
947216bf | 8695 | bfd_byte *loc; |
5bd4f169 | 8696 | |
411e1bfb AM |
8697 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
8698 | if (ent->plt.offset != (bfd_vma) -1) | |
8699 | { | |
8700 | /* This symbol has an entry in the procedure linkage | |
8701 | table. Set it up. */ | |
5bd4f169 | 8702 | |
4ce794b7 AM |
8703 | if (htab->plt == NULL |
8704 | || htab->relplt == NULL | |
8705 | || htab->glink == NULL) | |
411e1bfb | 8706 | abort (); |
5bd4f169 | 8707 | |
411e1bfb AM |
8708 | /* Create a JMP_SLOT reloc to inform the dynamic linker to |
8709 | fill in the PLT entry. */ | |
4ce794b7 AM |
8710 | rela.r_offset = (htab->plt->output_section->vma |
8711 | + htab->plt->output_offset | |
411e1bfb AM |
8712 | + ent->plt.offset); |
8713 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); | |
8714 | rela.r_addend = ent->addend; | |
5bd4f169 | 8715 | |
4ce794b7 | 8716 | loc = htab->relplt->contents; |
411e1bfb AM |
8717 | loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE |
8718 | * sizeof (Elf64_External_Rela)); | |
8719 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
8720 | } | |
5bd4f169 AM |
8721 | } |
8722 | ||
8723 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
8724 | { | |
5bd4f169 | 8725 | Elf_Internal_Rela rela; |
947216bf | 8726 | bfd_byte *loc; |
5bd4f169 | 8727 | |
65f38f15 | 8728 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 8729 | |
65f38f15 AM |
8730 | if (h->dynindx == -1 |
8731 | || (h->root.type != bfd_link_hash_defined | |
8732 | && h->root.type != bfd_link_hash_defweak) | |
4ce794b7 | 8733 | || htab->relbss == NULL) |
65f38f15 | 8734 | abort (); |
5bd4f169 AM |
8735 | |
8736 | rela.r_offset = (h->root.u.def.value | |
8737 | + h->root.u.def.section->output_section->vma | |
8738 | + h->root.u.def.section->output_offset); | |
8739 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
8740 | rela.r_addend = 0; | |
4ce794b7 AM |
8741 | loc = htab->relbss->contents; |
8742 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 8743 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
8744 | } |
8745 | ||
5bd4f169 AM |
8746 | /* Mark some specially defined symbols as absolute. */ |
8747 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
8748 | sym->st_shndx = SHN_ABS; | |
8749 | ||
b34976b6 | 8750 | return TRUE; |
5bd4f169 AM |
8751 | } |
8752 | ||
65f38f15 AM |
8753 | /* Used to decide how to sort relocs in an optimal manner for the |
8754 | dynamic linker, before writing them out. */ | |
8755 | ||
8756 | static enum elf_reloc_type_class | |
4ce794b7 | 8757 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
65f38f15 | 8758 | { |
04c9666a | 8759 | enum elf_ppc64_reloc_type r_type; |
a33d1f77 | 8760 | |
4ce794b7 | 8761 | r_type = ELF64_R_TYPE (rela->r_info); |
a33d1f77 | 8762 | switch (r_type) |
65f38f15 AM |
8763 | { |
8764 | case R_PPC64_RELATIVE: | |
8765 | return reloc_class_relative; | |
8766 | case R_PPC64_JMP_SLOT: | |
8767 | return reloc_class_plt; | |
8768 | case R_PPC64_COPY: | |
8769 | return reloc_class_copy; | |
8770 | default: | |
8771 | return reloc_class_normal; | |
8772 | } | |
8773 | } | |
8774 | ||
5bd4f169 AM |
8775 | /* Finish up the dynamic sections. */ |
8776 | ||
b34976b6 | 8777 | static bfd_boolean |
4ce794b7 AM |
8778 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
8779 | struct bfd_link_info *info) | |
5bd4f169 | 8780 | { |
65f38f15 AM |
8781 | struct ppc_link_hash_table *htab; |
8782 | bfd *dynobj; | |
5bd4f169 | 8783 | asection *sdyn; |
5bd4f169 | 8784 | |
65f38f15 AM |
8785 | htab = ppc_hash_table (info); |
8786 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
8787 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
8788 | ||
65f38f15 | 8789 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 8790 | { |
5bd4f169 AM |
8791 | Elf64_External_Dyn *dyncon, *dynconend; |
8792 | ||
4ce794b7 | 8793 | if (sdyn == NULL || htab->got == NULL) |
65f38f15 | 8794 | abort (); |
5bd4f169 AM |
8795 | |
8796 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
8797 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
8798 | for (; dyncon < dynconend; dyncon++) | |
8799 | { | |
8800 | Elf_Internal_Dyn dyn; | |
19397422 | 8801 | asection *s; |
5bd4f169 AM |
8802 | |
8803 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
8804 | ||
8805 | switch (dyn.d_tag) | |
8806 | { | |
65f38f15 AM |
8807 | default: |
8808 | continue; | |
5bd4f169 | 8809 | |
5d1634d7 | 8810 | case DT_PPC64_GLINK: |
4ce794b7 | 8811 | s = htab->glink; |
6348e046 | 8812 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
ad8e1ba5 AM |
8813 | /* We stupidly defined DT_PPC64_GLINK to be the start |
8814 | of glink rather than the first entry point, which is | |
8815 | what ld.so needs, and now have a bigger stub to | |
8816 | support automatic multiple TOCs. */ | |
8817 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; | |
5d1634d7 AM |
8818 | break; |
8819 | ||
19397422 AM |
8820 | case DT_PPC64_OPD: |
8821 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8822 | if (s == NULL) |
8823 | continue; | |
8824 | dyn.d_un.d_ptr = s->vma; | |
19397422 AM |
8825 | break; |
8826 | ||
8827 | case DT_PPC64_OPDSZ: | |
8828 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8829 | if (s == NULL) |
8830 | continue; | |
8831 | dyn.d_un.d_val = s->_raw_size; | |
19397422 AM |
8832 | break; |
8833 | ||
65f38f15 | 8834 | case DT_PLTGOT: |
4ce794b7 | 8835 | s = htab->plt; |
6348e046 | 8836 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 AM |
8837 | break; |
8838 | ||
8839 | case DT_JMPREL: | |
4ce794b7 | 8840 | s = htab->relplt; |
6348e046 | 8841 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 | 8842 | break; |
5bd4f169 | 8843 | |
65f38f15 | 8844 | case DT_PLTRELSZ: |
4ce794b7 | 8845 | dyn.d_un.d_val = htab->relplt->_raw_size; |
5d1634d7 AM |
8846 | break; |
8847 | ||
8848 | case DT_RELASZ: | |
8849 | /* Don't count procedure linkage table relocs in the | |
8850 | overall reloc count. */ | |
4ce794b7 | 8851 | s = htab->relplt; |
6348e046 AM |
8852 | if (s == NULL) |
8853 | continue; | |
8854 | dyn.d_un.d_val -= s->_raw_size; | |
8855 | break; | |
8856 | ||
8857 | case DT_RELA: | |
8858 | /* We may not be using the standard ELF linker script. | |
8859 | If .rela.plt is the first .rela section, we adjust | |
8860 | DT_RELA to not include it. */ | |
4ce794b7 | 8861 | s = htab->relplt; |
6348e046 AM |
8862 | if (s == NULL) |
8863 | continue; | |
8864 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
8865 | continue; | |
8866 | dyn.d_un.d_ptr += s->_raw_size; | |
65f38f15 | 8867 | break; |
5bd4f169 | 8868 | } |
5bd4f169 | 8869 | |
65f38f15 | 8870 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 8871 | } |
5bd4f169 AM |
8872 | } |
8873 | ||
4ce794b7 | 8874 | if (htab->got != NULL && htab->got->_raw_size != 0) |
5d1634d7 AM |
8875 | { |
8876 | /* Fill in the first entry in the global offset table. | |
8877 | We use it to hold the link-time TOCbase. */ | |
8878 | bfd_put_64 (output_bfd, | |
60ee0d4a | 8879 | elf_gp (output_bfd) + TOC_BASE_OFF, |
4ce794b7 | 8880 | htab->got->contents); |
5d1634d7 AM |
8881 | |
8882 | /* Set .got entry size. */ | |
4ce794b7 | 8883 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
5d1634d7 AM |
8884 | } |
8885 | ||
4ce794b7 | 8886 | if (htab->plt != NULL && htab->plt->_raw_size != 0) |
5d1634d7 AM |
8887 | { |
8888 | /* Set .plt entry size. */ | |
4ce794b7 | 8889 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
5d1634d7 AM |
8890 | = PLT_ENTRY_SIZE; |
8891 | } | |
8892 | ||
e717da7e AM |
8893 | /* We need to handle writing out multiple GOT sections ourselves, |
8894 | since we didn't add them to DYNOBJ. */ | |
8895 | while ((dynobj = dynobj->link_next) != NULL) | |
8896 | { | |
8897 | asection *s; | |
8898 | s = ppc64_elf_tdata (dynobj)->got; | |
8899 | if (s != NULL | |
8900 | && s->_raw_size != 0 | |
8901 | && s->output_section != bfd_abs_section_ptr | |
8902 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8903 | s->contents, s->output_offset, | |
8904 | s->_raw_size)) | |
8905 | return FALSE; | |
8906 | s = ppc64_elf_tdata (dynobj)->relgot; | |
8907 | if (s != NULL | |
8908 | && s->_raw_size != 0 | |
8909 | && s->output_section != bfd_abs_section_ptr | |
8910 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8911 | s->contents, s->output_offset, | |
8912 | s->_raw_size)) | |
8913 | return FALSE; | |
8914 | } | |
f6c52c13 | 8915 | |
b34976b6 | 8916 | return TRUE; |
5bd4f169 AM |
8917 | } |
8918 | ||
5bd4f169 | 8919 | #include "elf64-target.h" |