Commit | Line | Data |
---|---|---|
5bd4f169 | 1 | /* PowerPC64-specific support for 64-bit ELF. |
b2a8e766 AM |
2 | Copyright 1999, 2000, 2001, 2002, 2003, 2004 |
3 | Free Software Foundation, Inc. | |
5bd4f169 AM |
4 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
5 | based on elf32-ppc.c by Ian Lance Taylor. | |
d37c89e5 | 6 | Largely rewritten by Alan Modra <amodra@bigpond.net.au> |
5bd4f169 | 7 | |
ae9a127f | 8 | This file is part of BFD, the Binary File Descriptor library. |
5bd4f169 | 9 | |
ae9a127f NC |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
5bd4f169 | 14 | |
ae9a127f NC |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
5bd4f169 | 19 | |
4ce794b7 AM |
20 | You should have received a copy of the GNU General Public License along |
21 | with this program; if not, write to the Free Software Foundation, Inc., | |
22 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
5bd4f169 | 23 | |
4ce794b7 AM |
24 | /* The 64-bit PowerPC ELF ABI may be found at |
25 | http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and | |
26 | http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */ | |
5bd4f169 AM |
27 | |
28 | #include "bfd.h" | |
29 | #include "sysdep.h" | |
30 | #include "bfdlink.h" | |
31 | #include "libbfd.h" | |
32 | #include "elf-bfd.h" | |
04c9666a | 33 | #include "elf/ppc64.h" |
5d1634d7 | 34 | #include "elf64-ppc.h" |
5bd4f169 | 35 | |
805fc799 | 36 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
4ce794b7 | 37 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 38 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
4ce794b7 | 39 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 40 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
4ce794b7 | 41 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 42 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
4ce794b7 | 43 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 44 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
4ce794b7 | 45 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 46 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
4ce794b7 | 47 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 48 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
4ce794b7 | 49 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 50 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
4ce794b7 | 51 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5bd4f169 AM |
52 | |
53 | ||
ad8e1ba5 AM |
54 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
55 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
56 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
57 | #define TARGET_BIG_NAME "elf64-powerpc" | |
58 | #define ELF_ARCH bfd_arch_powerpc | |
59 | #define ELF_MACHINE_CODE EM_PPC64 | |
60 | #define ELF_MAXPAGESIZE 0x10000 | |
61 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
62 | ||
63 | #define elf_backend_want_got_sym 0 | |
64 | #define elf_backend_want_plt_sym 0 | |
65 | #define elf_backend_plt_alignment 3 | |
66 | #define elf_backend_plt_not_loaded 1 | |
67 | #define elf_backend_got_symbol_offset 0 | |
68 | #define elf_backend_got_header_size 8 | |
ad8e1ba5 AM |
69 | #define elf_backend_can_gc_sections 1 |
70 | #define elf_backend_can_refcount 1 | |
71 | #define elf_backend_rela_normal 1 | |
72 | ||
e717da7e | 73 | #define bfd_elf64_mkobject ppc64_elf_mkobject |
ad8e1ba5 AM |
74 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
75 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data | |
76 | #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook | |
77 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create | |
78 | #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free | |
79 | ||
80 | #define elf_backend_object_p ppc64_elf_object_p | |
d37c89e5 AM |
81 | #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus |
82 | #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo | |
ad8e1ba5 AM |
83 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
84 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
555cd476 | 85 | #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook |
8387904d AM |
86 | #define elf_backend_check_directives ppc64_elf_check_directives |
87 | #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup | |
ad8e1ba5 AM |
88 | #define elf_backend_check_relocs ppc64_elf_check_relocs |
89 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
90 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
91 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
92 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol | |
93 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
94 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
95 | #define elf_backend_relocate_section ppc64_elf_relocate_section | |
96 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
97 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
98 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
754021d0 | 99 | #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook |
2f89ff8d | 100 | #define elf_backend_special_sections ppc64_elf_special_sections |
ad8e1ba5 | 101 | |
5bd4f169 AM |
102 | /* The name of the dynamic interpreter. This is put in the .interp |
103 | section. */ | |
104 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
105 | ||
106 | /* The size in bytes of an entry in the procedure linkage table. */ | |
107 | #define PLT_ENTRY_SIZE 24 | |
108 | ||
109 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 110 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
111 | |
112 | /* TOC base pointers offset from start of TOC. */ | |
411e1bfb AM |
113 | #define TOC_BASE_OFF 0x8000 |
114 | ||
115 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
116 | #define TP_OFFSET 0x7000 | |
117 | #define DTP_OFFSET 0x8000 | |
5bd4f169 | 118 | |
ad8e1ba5 AM |
119 | /* .plt call stub instructions. The normal stub is like this, but |
120 | sometimes the .plt entry crosses a 64k boundary and we need to | |
121 | insert an addis to adjust r12. */ | |
122 | #define PLT_CALL_STUB_SIZE (7*4) | |
5d1634d7 AM |
123 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
124 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
125 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
126 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
127 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
128 | /* ld %r11,xxx+16@l(%r12) */ | |
129 | #define BCTR 0x4e800420 /* bctr */ | |
130 | ||
5d1634d7 | 131 | |
ad8e1ba5 AM |
132 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
133 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ | |
134 | ||
135 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
136 | ||
137 | /* glink call stub instructions. We enter with the index in R0, and the | |
138 | address of glink entry in CTR. From that, we can calculate PLT0. */ | |
139 | #define GLINK_CALL_STUB_SIZE (16*4) | |
140 | #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */ | |
141 | #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */ | |
142 | #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */ | |
143 | #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */ | |
144 | #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */ | |
145 | #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */ | |
146 | #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */ | |
147 | /* sub %r12,%r12,%r11 */ | |
148 | #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */ | |
149 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */ | |
150 | /* ld %r11,xxx@l(%r12) */ | |
151 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */ | |
152 | /* ld %r2,8(%r12) */ | |
153 | /* mtctr %r11 */ | |
154 | /* ld %r11,16(%r12) */ | |
155 | /* bctr */ | |
5d1634d7 AM |
156 | |
157 | /* Pad with this. */ | |
158 | #define NOP 0x60000000 | |
159 | ||
721956f4 AM |
160 | /* Some other nops. */ |
161 | #define CROR_151515 0x4def7b82 | |
162 | #define CROR_313131 0x4ffffb82 | |
163 | ||
cedb70c5 | 164 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
165 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
166 | #define B_DOT 0x48000000 /* b . */ | |
167 | ||
168 | /* After that, we need two instructions to load the index, followed by | |
169 | a branch. */ | |
170 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 171 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 172 | |
82bd7b59 AM |
173 | /* Instructions to save and restore floating point regs. */ |
174 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ | |
175 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
176 | #define BLR 0x4e800020 /* blr */ | |
177 | ||
41bd81ab AM |
178 | /* Since .opd is an array of descriptors and each entry will end up |
179 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
180 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 181 | relocate .opd without reloc entries. */ |
41bd81ab AM |
182 | #ifndef NO_OPD_RELOCS |
183 | #define NO_OPD_RELOCS 0 | |
184 | #endif | |
5bd4f169 | 185 | \f |
f5e87a1d | 186 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 187 | |
5bd4f169 | 188 | /* Relocation HOWTO's. */ |
04c9666a | 189 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
5bd4f169 AM |
190 | |
191 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
192 | /* This reloc does nothing. */ | |
193 | HOWTO (R_PPC64_NONE, /* type */ | |
194 | 0, /* rightshift */ | |
411e1bfb AM |
195 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
196 | 32, /* bitsize */ | |
b34976b6 | 197 | FALSE, /* pc_relative */ |
5bd4f169 | 198 | 0, /* bitpos */ |
f5e87a1d | 199 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
200 | bfd_elf_generic_reloc, /* special_function */ |
201 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 202 | FALSE, /* partial_inplace */ |
d006db6c | 203 | 0, /* src_mask */ |
5bd4f169 | 204 | 0, /* dst_mask */ |
b34976b6 | 205 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
206 | |
207 | /* A standard 32 bit relocation. */ | |
208 | HOWTO (R_PPC64_ADDR32, /* type */ | |
209 | 0, /* rightshift */ | |
210 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
211 | 32, /* bitsize */ | |
b34976b6 | 212 | FALSE, /* pc_relative */ |
5bd4f169 AM |
213 | 0, /* bitpos */ |
214 | complain_overflow_bitfield, /* complain_on_overflow */ | |
215 | bfd_elf_generic_reloc, /* special_function */ | |
216 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 217 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
218 | 0, /* src_mask */ |
219 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 220 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
221 | |
222 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
223 | FIXME: we don't check that, we just clear them. */ | |
224 | HOWTO (R_PPC64_ADDR24, /* type */ | |
225 | 0, /* rightshift */ | |
226 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
227 | 26, /* bitsize */ | |
b34976b6 | 228 | FALSE, /* pc_relative */ |
5bd4f169 AM |
229 | 0, /* bitpos */ |
230 | complain_overflow_bitfield, /* complain_on_overflow */ | |
231 | bfd_elf_generic_reloc, /* special_function */ | |
232 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 233 | FALSE, /* partial_inplace */ |
d006db6c | 234 | 0, /* src_mask */ |
f5e87a1d | 235 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 236 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
237 | |
238 | /* A standard 16 bit relocation. */ | |
239 | HOWTO (R_PPC64_ADDR16, /* type */ | |
240 | 0, /* rightshift */ | |
241 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
242 | 16, /* bitsize */ | |
b34976b6 | 243 | FALSE, /* pc_relative */ |
5bd4f169 AM |
244 | 0, /* bitpos */ |
245 | complain_overflow_bitfield, /* complain_on_overflow */ | |
246 | bfd_elf_generic_reloc, /* special_function */ | |
247 | "R_PPC64_ADDR16", /* name */ | |
b34976b6 | 248 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
249 | 0, /* src_mask */ |
250 | 0xffff, /* dst_mask */ | |
b34976b6 | 251 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
252 | |
253 | /* A 16 bit relocation without overflow. */ | |
254 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
255 | 0, /* rightshift */ | |
256 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
257 | 16, /* bitsize */ | |
b34976b6 | 258 | FALSE, /* pc_relative */ |
5bd4f169 AM |
259 | 0, /* bitpos */ |
260 | complain_overflow_dont,/* complain_on_overflow */ | |
261 | bfd_elf_generic_reloc, /* special_function */ | |
262 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 263 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
264 | 0, /* src_mask */ |
265 | 0xffff, /* dst_mask */ | |
b34976b6 | 266 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
267 | |
268 | /* Bits 16-31 of an address. */ | |
269 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
270 | 16, /* rightshift */ | |
271 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
272 | 16, /* bitsize */ | |
b34976b6 | 273 | FALSE, /* pc_relative */ |
5bd4f169 AM |
274 | 0, /* bitpos */ |
275 | complain_overflow_dont, /* complain_on_overflow */ | |
276 | bfd_elf_generic_reloc, /* special_function */ | |
277 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 278 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
279 | 0, /* src_mask */ |
280 | 0xffff, /* dst_mask */ | |
b34976b6 | 281 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
282 | |
283 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
284 | bits, treated as a signed number, is negative. */ | |
285 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
286 | 16, /* rightshift */ | |
287 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
288 | 16, /* bitsize */ | |
b34976b6 | 289 | FALSE, /* pc_relative */ |
5bd4f169 AM |
290 | 0, /* bitpos */ |
291 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 292 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 293 | "R_PPC64_ADDR16_HA", /* name */ |
b34976b6 | 294 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
295 | 0, /* src_mask */ |
296 | 0xffff, /* dst_mask */ | |
b34976b6 | 297 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
298 | |
299 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
300 | FIXME: we don't check that, we just clear them. */ | |
301 | HOWTO (R_PPC64_ADDR14, /* type */ | |
302 | 0, /* rightshift */ | |
303 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
304 | 16, /* bitsize */ | |
b34976b6 | 305 | FALSE, /* pc_relative */ |
5bd4f169 AM |
306 | 0, /* bitpos */ |
307 | complain_overflow_bitfield, /* complain_on_overflow */ | |
308 | bfd_elf_generic_reloc, /* special_function */ | |
309 | "R_PPC64_ADDR14", /* name */ | |
b34976b6 | 310 | FALSE, /* partial_inplace */ |
d006db6c | 311 | 0, /* src_mask */ |
f5e87a1d | 312 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 313 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
314 | |
315 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
316 | indicate that the branch is expected to be taken. The lower two | |
317 | bits must be zero. */ | |
318 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
319 | 0, /* rightshift */ | |
320 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
321 | 16, /* bitsize */ | |
b34976b6 | 322 | FALSE, /* pc_relative */ |
5bd4f169 AM |
323 | 0, /* bitpos */ |
324 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 325 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 326 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 327 | FALSE, /* partial_inplace */ |
d006db6c | 328 | 0, /* src_mask */ |
f5e87a1d | 329 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 330 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
331 | |
332 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
333 | indicate that the branch is not expected to be taken. The lower | |
334 | two bits must be zero. */ | |
335 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
336 | 0, /* rightshift */ | |
337 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
338 | 16, /* bitsize */ | |
b34976b6 | 339 | FALSE, /* pc_relative */ |
5bd4f169 AM |
340 | 0, /* bitpos */ |
341 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 342 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 343 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 344 | FALSE, /* partial_inplace */ |
d006db6c | 345 | 0, /* src_mask */ |
f5e87a1d | 346 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 347 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
348 | |
349 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
350 | HOWTO (R_PPC64_REL24, /* type */ | |
351 | 0, /* rightshift */ | |
352 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
353 | 26, /* bitsize */ | |
b34976b6 | 354 | TRUE, /* pc_relative */ |
5bd4f169 AM |
355 | 0, /* bitpos */ |
356 | complain_overflow_signed, /* complain_on_overflow */ | |
357 | bfd_elf_generic_reloc, /* special_function */ | |
358 | "R_PPC64_REL24", /* name */ | |
b34976b6 | 359 | FALSE, /* partial_inplace */ |
d006db6c | 360 | 0, /* src_mask */ |
f5e87a1d | 361 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 362 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
363 | |
364 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
365 | HOWTO (R_PPC64_REL14, /* type */ | |
366 | 0, /* rightshift */ | |
367 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
368 | 16, /* bitsize */ | |
b34976b6 | 369 | TRUE, /* pc_relative */ |
5bd4f169 AM |
370 | 0, /* bitpos */ |
371 | complain_overflow_signed, /* complain_on_overflow */ | |
372 | bfd_elf_generic_reloc, /* special_function */ | |
373 | "R_PPC64_REL14", /* name */ | |
b34976b6 | 374 | FALSE, /* partial_inplace */ |
d006db6c | 375 | 0, /* src_mask */ |
f5e87a1d | 376 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 377 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
378 | |
379 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
380 | the branch is expected to be taken. The lower two bits must be | |
381 | zero. */ | |
382 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
383 | 0, /* rightshift */ | |
384 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
385 | 16, /* bitsize */ | |
b34976b6 | 386 | TRUE, /* pc_relative */ |
5bd4f169 AM |
387 | 0, /* bitpos */ |
388 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 389 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 390 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 391 | FALSE, /* partial_inplace */ |
d006db6c | 392 | 0, /* src_mask */ |
f5e87a1d | 393 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 394 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
395 | |
396 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
397 | the branch is not expected to be taken. The lower two bits must | |
398 | be zero. */ | |
399 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
400 | 0, /* rightshift */ | |
401 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
402 | 16, /* bitsize */ | |
b34976b6 | 403 | TRUE, /* pc_relative */ |
5bd4f169 AM |
404 | 0, /* bitpos */ |
405 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 406 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 407 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 408 | FALSE, /* partial_inplace */ |
d006db6c | 409 | 0, /* src_mask */ |
f5e87a1d | 410 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 411 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
412 | |
413 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
414 | symbol. */ | |
415 | HOWTO (R_PPC64_GOT16, /* type */ | |
416 | 0, /* rightshift */ | |
417 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
418 | 16, /* bitsize */ | |
b34976b6 | 419 | FALSE, /* pc_relative */ |
5bd4f169 AM |
420 | 0, /* bitpos */ |
421 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 422 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 423 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 424 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
425 | 0, /* src_mask */ |
426 | 0xffff, /* dst_mask */ | |
b34976b6 | 427 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
428 | |
429 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
430 | the symbol. */ | |
431 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
432 | 0, /* rightshift */ | |
433 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
434 | 16, /* bitsize */ | |
b34976b6 | 435 | FALSE, /* pc_relative */ |
5bd4f169 AM |
436 | 0, /* bitpos */ |
437 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 438 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 439 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 440 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
441 | 0, /* src_mask */ |
442 | 0xffff, /* dst_mask */ | |
b34976b6 | 443 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
444 | |
445 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
446 | the symbol. */ | |
447 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
448 | 16, /* rightshift */ | |
449 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
450 | 16, /* bitsize */ | |
b34976b6 | 451 | FALSE, /* pc_relative */ |
5bd4f169 AM |
452 | 0, /* bitpos */ |
453 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 454 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 455 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 456 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
457 | 0, /* src_mask */ |
458 | 0xffff, /* dst_mask */ | |
b34976b6 | 459 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
460 | |
461 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
462 | the symbol. */ | |
463 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
464 | 16, /* rightshift */ | |
465 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
466 | 16, /* bitsize */ | |
b34976b6 | 467 | FALSE, /* pc_relative */ |
5bd4f169 AM |
468 | 0, /* bitpos */ |
469 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 470 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 471 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 472 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
473 | 0, /* src_mask */ |
474 | 0xffff, /* dst_mask */ | |
b34976b6 | 475 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
476 | |
477 | /* This is used only by the dynamic linker. The symbol should exist | |
478 | both in the object being run and in some shared library. The | |
479 | dynamic linker copies the data addressed by the symbol from the | |
480 | shared library into the object, because the object being | |
481 | run has to have the data at some particular address. */ | |
482 | HOWTO (R_PPC64_COPY, /* type */ | |
483 | 0, /* rightshift */ | |
f5e87a1d AM |
484 | 0, /* this one is variable size */ |
485 | 0, /* bitsize */ | |
b34976b6 | 486 | FALSE, /* pc_relative */ |
5bd4f169 | 487 | 0, /* bitpos */ |
f5e87a1d AM |
488 | complain_overflow_dont, /* complain_on_overflow */ |
489 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 490 | "R_PPC64_COPY", /* name */ |
b34976b6 | 491 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
492 | 0, /* src_mask */ |
493 | 0, /* dst_mask */ | |
b34976b6 | 494 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
495 | |
496 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
497 | entries. */ | |
498 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
499 | 0, /* rightshift */ | |
500 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
501 | 64, /* bitsize */ | |
b34976b6 | 502 | FALSE, /* pc_relative */ |
5bd4f169 AM |
503 | 0, /* bitpos */ |
504 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 505 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 506 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 507 | FALSE, /* partial_inplace */ |
5bd4f169 | 508 | 0, /* src_mask */ |
f5e87a1d | 509 | ONES (64), /* dst_mask */ |
b34976b6 | 510 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
511 | |
512 | /* Created by the link editor. Marks a procedure linkage table | |
513 | entry for a symbol. */ | |
514 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
515 | 0, /* rightshift */ | |
516 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
517 | 0, /* bitsize */ | |
b34976b6 | 518 | FALSE, /* pc_relative */ |
5bd4f169 AM |
519 | 0, /* bitpos */ |
520 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 521 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 522 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 523 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
524 | 0, /* src_mask */ |
525 | 0, /* dst_mask */ | |
b34976b6 | 526 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
527 | |
528 | /* Used only by the dynamic linker. When the object is run, this | |
529 | doubleword64 is set to the load address of the object, plus the | |
530 | addend. */ | |
531 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
532 | 0, /* rightshift */ | |
533 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
534 | 64, /* bitsize */ | |
b34976b6 | 535 | FALSE, /* pc_relative */ |
5bd4f169 AM |
536 | 0, /* bitpos */ |
537 | complain_overflow_dont, /* complain_on_overflow */ | |
538 | bfd_elf_generic_reloc, /* special_function */ | |
539 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 540 | FALSE, /* partial_inplace */ |
5bd4f169 | 541 | 0, /* src_mask */ |
f5e87a1d | 542 | ONES (64), /* dst_mask */ |
b34976b6 | 543 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
544 | |
545 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
546 | HOWTO (R_PPC64_UADDR32, /* type */ | |
547 | 0, /* rightshift */ | |
548 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
549 | 32, /* bitsize */ | |
b34976b6 | 550 | FALSE, /* pc_relative */ |
5bd4f169 AM |
551 | 0, /* bitpos */ |
552 | complain_overflow_bitfield, /* complain_on_overflow */ | |
553 | bfd_elf_generic_reloc, /* special_function */ | |
554 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 555 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
556 | 0, /* src_mask */ |
557 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 558 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
559 | |
560 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
561 | HOWTO (R_PPC64_UADDR16, /* type */ | |
562 | 0, /* rightshift */ | |
563 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
564 | 16, /* bitsize */ | |
b34976b6 | 565 | FALSE, /* pc_relative */ |
5bd4f169 AM |
566 | 0, /* bitpos */ |
567 | complain_overflow_bitfield, /* complain_on_overflow */ | |
568 | bfd_elf_generic_reloc, /* special_function */ | |
569 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 570 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
571 | 0, /* src_mask */ |
572 | 0xffff, /* dst_mask */ | |
b34976b6 | 573 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
574 | |
575 | /* 32-bit PC relative. */ | |
576 | HOWTO (R_PPC64_REL32, /* type */ | |
577 | 0, /* rightshift */ | |
578 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
579 | 32, /* bitsize */ | |
b34976b6 | 580 | TRUE, /* pc_relative */ |
5bd4f169 | 581 | 0, /* bitpos */ |
cedb70c5 | 582 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
583 | complain_overflow_signed, /* complain_on_overflow */ |
584 | bfd_elf_generic_reloc, /* special_function */ | |
585 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 586 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
587 | 0, /* src_mask */ |
588 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 589 | TRUE), /* pcrel_offset */ |
5bd4f169 | 590 | |
10ed1bba | 591 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
592 | HOWTO (R_PPC64_PLT32, /* type */ |
593 | 0, /* rightshift */ | |
594 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
595 | 32, /* bitsize */ | |
b34976b6 | 596 | FALSE, /* pc_relative */ |
5bd4f169 AM |
597 | 0, /* bitpos */ |
598 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 599 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 600 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 601 | FALSE, /* partial_inplace */ |
5bd4f169 | 602 | 0, /* src_mask */ |
f5e87a1d | 603 | 0xffffffff, /* dst_mask */ |
b34976b6 | 604 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
605 | |
606 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
607 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
608 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
609 | 0, /* rightshift */ | |
610 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
611 | 32, /* bitsize */ | |
b34976b6 | 612 | TRUE, /* pc_relative */ |
5bd4f169 AM |
613 | 0, /* bitpos */ |
614 | complain_overflow_signed, /* complain_on_overflow */ | |
615 | bfd_elf_generic_reloc, /* special_function */ | |
616 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 617 | FALSE, /* partial_inplace */ |
5bd4f169 | 618 | 0, /* src_mask */ |
f5e87a1d | 619 | 0xffffffff, /* dst_mask */ |
b34976b6 | 620 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
621 | |
622 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
623 | the symbol. */ | |
624 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
625 | 0, /* rightshift */ | |
626 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
627 | 16, /* bitsize */ | |
b34976b6 | 628 | FALSE, /* pc_relative */ |
5bd4f169 AM |
629 | 0, /* bitpos */ |
630 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 631 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 632 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 633 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
634 | 0, /* src_mask */ |
635 | 0xffff, /* dst_mask */ | |
b34976b6 | 636 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
637 | |
638 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
639 | the symbol. */ | |
640 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
641 | 16, /* rightshift */ | |
642 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
643 | 16, /* bitsize */ | |
b34976b6 | 644 | FALSE, /* pc_relative */ |
5bd4f169 AM |
645 | 0, /* bitpos */ |
646 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 647 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 648 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 649 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
650 | 0, /* src_mask */ |
651 | 0xffff, /* dst_mask */ | |
b34976b6 | 652 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
653 | |
654 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
655 | the symbol. */ | |
656 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
657 | 16, /* rightshift */ | |
658 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
659 | 16, /* bitsize */ | |
b34976b6 | 660 | FALSE, /* pc_relative */ |
5bd4f169 AM |
661 | 0, /* bitpos */ |
662 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 663 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 664 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 665 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
666 | 0, /* src_mask */ |
667 | 0xffff, /* dst_mask */ | |
b34976b6 | 668 | FALSE), /* pcrel_offset */ |
5bd4f169 | 669 | |
c061c2d8 | 670 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
671 | HOWTO (R_PPC64_SECTOFF, /* type */ |
672 | 0, /* rightshift */ | |
c061c2d8 AM |
673 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
674 | 16, /* bitsize */ | |
b34976b6 | 675 | FALSE, /* pc_relative */ |
5bd4f169 AM |
676 | 0, /* bitpos */ |
677 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 678 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 679 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 680 | FALSE, /* partial_inplace */ |
5bd4f169 | 681 | 0, /* src_mask */ |
c061c2d8 | 682 | 0xffff, /* dst_mask */ |
b34976b6 | 683 | FALSE), /* pcrel_offset */ |
5bd4f169 | 684 | |
c061c2d8 | 685 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
686 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
687 | 0, /* rightshift */ | |
688 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
689 | 16, /* bitsize */ | |
b34976b6 | 690 | FALSE, /* pc_relative */ |
5bd4f169 AM |
691 | 0, /* bitpos */ |
692 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 693 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 694 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 695 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
696 | 0, /* src_mask */ |
697 | 0xffff, /* dst_mask */ | |
b34976b6 | 698 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
699 | |
700 | /* 16-bit upper half section relative relocation. */ | |
701 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
702 | 16, /* rightshift */ | |
703 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
704 | 16, /* bitsize */ | |
b34976b6 | 705 | FALSE, /* pc_relative */ |
5bd4f169 AM |
706 | 0, /* bitpos */ |
707 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 708 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 709 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 710 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
711 | 0, /* src_mask */ |
712 | 0xffff, /* dst_mask */ | |
b34976b6 | 713 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
714 | |
715 | /* 16-bit upper half adjusted section relative relocation. */ | |
716 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
717 | 16, /* rightshift */ | |
718 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
719 | 16, /* bitsize */ | |
b34976b6 | 720 | FALSE, /* pc_relative */ |
5bd4f169 AM |
721 | 0, /* bitpos */ |
722 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 723 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 724 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 725 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
726 | 0, /* src_mask */ |
727 | 0xffff, /* dst_mask */ | |
b34976b6 | 728 | FALSE), /* pcrel_offset */ |
5bd4f169 | 729 | |
04c9666a AM |
730 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
731 | HOWTO (R_PPC64_REL30, /* type */ | |
5bd4f169 AM |
732 | 2, /* rightshift */ |
733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
734 | 30, /* bitsize */ | |
b34976b6 | 735 | TRUE, /* pc_relative */ |
5bd4f169 AM |
736 | 0, /* bitpos */ |
737 | complain_overflow_dont, /* complain_on_overflow */ | |
738 | bfd_elf_generic_reloc, /* special_function */ | |
04c9666a | 739 | "R_PPC64_REL30", /* name */ |
b34976b6 | 740 | FALSE, /* partial_inplace */ |
d006db6c | 741 | 0, /* src_mask */ |
5bd4f169 | 742 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 743 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
744 | |
745 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
746 | ||
747 | /* A standard 64-bit relocation. */ | |
748 | HOWTO (R_PPC64_ADDR64, /* type */ | |
749 | 0, /* rightshift */ | |
750 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
751 | 64, /* bitsize */ | |
b34976b6 | 752 | FALSE, /* pc_relative */ |
5bd4f169 AM |
753 | 0, /* bitpos */ |
754 | complain_overflow_dont, /* complain_on_overflow */ | |
755 | bfd_elf_generic_reloc, /* special_function */ | |
756 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 757 | FALSE, /* partial_inplace */ |
5bd4f169 | 758 | 0, /* src_mask */ |
f5e87a1d | 759 | ONES (64), /* dst_mask */ |
b34976b6 | 760 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
761 | |
762 | /* The bits 32-47 of an address. */ | |
763 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
764 | 32, /* rightshift */ | |
765 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
766 | 16, /* bitsize */ | |
b34976b6 | 767 | FALSE, /* pc_relative */ |
5bd4f169 AM |
768 | 0, /* bitpos */ |
769 | complain_overflow_dont, /* complain_on_overflow */ | |
770 | bfd_elf_generic_reloc, /* special_function */ | |
771 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 772 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
773 | 0, /* src_mask */ |
774 | 0xffff, /* dst_mask */ | |
b34976b6 | 775 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
776 | |
777 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
778 | 16 bits, treated as a signed number, is negative. */ | |
779 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
780 | 32, /* rightshift */ | |
781 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
782 | 16, /* bitsize */ | |
b34976b6 | 783 | FALSE, /* pc_relative */ |
5bd4f169 AM |
784 | 0, /* bitpos */ |
785 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 786 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 787 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 788 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
789 | 0, /* src_mask */ |
790 | 0xffff, /* dst_mask */ | |
b34976b6 | 791 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
792 | |
793 | /* The bits 48-63 of an address. */ | |
794 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
795 | 48, /* rightshift */ | |
796 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
797 | 16, /* bitsize */ | |
b34976b6 | 798 | FALSE, /* pc_relative */ |
5bd4f169 AM |
799 | 0, /* bitpos */ |
800 | complain_overflow_dont, /* complain_on_overflow */ | |
801 | bfd_elf_generic_reloc, /* special_function */ | |
802 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
b34976b6 | 803 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
804 | 0, /* src_mask */ |
805 | 0xffff, /* dst_mask */ | |
b34976b6 | 806 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
807 | |
808 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
809 | 16 bits, treated as a signed number, is negative. */ | |
810 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
811 | 48, /* rightshift */ | |
812 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
813 | 16, /* bitsize */ | |
b34976b6 | 814 | FALSE, /* pc_relative */ |
5bd4f169 AM |
815 | 0, /* bitpos */ |
816 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 817 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 818 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
b34976b6 | 819 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
820 | 0, /* src_mask */ |
821 | 0xffff, /* dst_mask */ | |
b34976b6 | 822 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
823 | |
824 | /* Like ADDR64, but may be unaligned. */ | |
825 | HOWTO (R_PPC64_UADDR64, /* type */ | |
826 | 0, /* rightshift */ | |
827 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
828 | 64, /* bitsize */ | |
b34976b6 | 829 | FALSE, /* pc_relative */ |
5bd4f169 AM |
830 | 0, /* bitpos */ |
831 | complain_overflow_dont, /* complain_on_overflow */ | |
832 | bfd_elf_generic_reloc, /* special_function */ | |
833 | "R_PPC64_UADDR64", /* name */ | |
b34976b6 | 834 | FALSE, /* partial_inplace */ |
5bd4f169 | 835 | 0, /* src_mask */ |
f5e87a1d | 836 | ONES (64), /* dst_mask */ |
b34976b6 | 837 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
838 | |
839 | /* 64-bit relative relocation. */ | |
840 | HOWTO (R_PPC64_REL64, /* type */ | |
841 | 0, /* rightshift */ | |
842 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
843 | 64, /* bitsize */ | |
b34976b6 | 844 | TRUE, /* pc_relative */ |
5bd4f169 AM |
845 | 0, /* bitpos */ |
846 | complain_overflow_dont, /* complain_on_overflow */ | |
847 | bfd_elf_generic_reloc, /* special_function */ | |
848 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 849 | FALSE, /* partial_inplace */ |
5bd4f169 | 850 | 0, /* src_mask */ |
f5e87a1d | 851 | ONES (64), /* dst_mask */ |
b34976b6 | 852 | TRUE), /* pcrel_offset */ |
5bd4f169 | 853 | |
cedb70c5 | 854 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
855 | HOWTO (R_PPC64_PLT64, /* type */ |
856 | 0, /* rightshift */ | |
857 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
858 | 64, /* bitsize */ | |
b34976b6 | 859 | FALSE, /* pc_relative */ |
5bd4f169 AM |
860 | 0, /* bitpos */ |
861 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 862 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 863 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 864 | FALSE, /* partial_inplace */ |
5bd4f169 | 865 | 0, /* src_mask */ |
f5e87a1d | 866 | ONES (64), /* dst_mask */ |
b34976b6 | 867 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
868 | |
869 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
870 | table. */ | |
871 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
872 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
873 | 0, /* rightshift */ | |
874 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
875 | 64, /* bitsize */ | |
b34976b6 | 876 | TRUE, /* pc_relative */ |
5bd4f169 AM |
877 | 0, /* bitpos */ |
878 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 879 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 880 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 881 | FALSE, /* partial_inplace */ |
5bd4f169 | 882 | 0, /* src_mask */ |
f5e87a1d | 883 | ONES (64), /* dst_mask */ |
b34976b6 | 884 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
885 | |
886 | /* 16 bit TOC-relative relocation. */ | |
887 | ||
888 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
889 | HOWTO (R_PPC64_TOC16, /* type */ | |
890 | 0, /* rightshift */ | |
891 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
892 | 16, /* bitsize */ | |
b34976b6 | 893 | FALSE, /* pc_relative */ |
5bd4f169 AM |
894 | 0, /* bitpos */ |
895 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 896 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 897 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 898 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
899 | 0, /* src_mask */ |
900 | 0xffff, /* dst_mask */ | |
b34976b6 | 901 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
902 | |
903 | /* 16 bit TOC-relative relocation without overflow. */ | |
904 | ||
905 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
906 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
907 | 0, /* rightshift */ | |
908 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
909 | 16, /* bitsize */ | |
b34976b6 | 910 | FALSE, /* pc_relative */ |
5bd4f169 AM |
911 | 0, /* bitpos */ |
912 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 913 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 914 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 915 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
916 | 0, /* src_mask */ |
917 | 0xffff, /* dst_mask */ | |
b34976b6 | 918 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
919 | |
920 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
921 | ||
922 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
923 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
924 | 16, /* rightshift */ | |
925 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
926 | 16, /* bitsize */ | |
b34976b6 | 927 | FALSE, /* pc_relative */ |
5bd4f169 AM |
928 | 0, /* bitpos */ |
929 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 930 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 931 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 932 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
933 | 0, /* src_mask */ |
934 | 0xffff, /* dst_mask */ | |
b34976b6 | 935 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
936 | |
937 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
938 | contents of the low 16 bits, treated as a signed number, is | |
939 | negative. */ | |
940 | ||
941 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
942 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
943 | 16, /* rightshift */ | |
944 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
945 | 16, /* bitsize */ | |
b34976b6 | 946 | FALSE, /* pc_relative */ |
5bd4f169 AM |
947 | 0, /* bitpos */ |
948 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 949 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 950 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 951 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
952 | 0, /* src_mask */ |
953 | 0xffff, /* dst_mask */ | |
b34976b6 | 954 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
955 | |
956 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
957 | ||
958 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
959 | HOWTO (R_PPC64_TOC, /* type */ | |
960 | 0, /* rightshift */ | |
961 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
962 | 64, /* bitsize */ | |
b34976b6 | 963 | FALSE, /* pc_relative */ |
5bd4f169 AM |
964 | 0, /* bitpos */ |
965 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 966 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 967 | "R_PPC64_TOC", /* name */ |
b34976b6 | 968 | FALSE, /* partial_inplace */ |
5bd4f169 | 969 | 0, /* src_mask */ |
f5e87a1d | 970 | ONES (64), /* dst_mask */ |
b34976b6 | 971 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
972 | |
973 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
974 | value to relocate may (!) refer to a PLT entry which the link | |
975 | editor (a) may replace with the symbol value. If the link editor | |
976 | is unable to fully resolve the symbol, it may (b) create a PLT | |
977 | entry and store the address to the new PLT entry in the GOT. | |
978 | This permits lazy resolution of function symbols at run time. | |
979 | The link editor may also skip all of this and just (c) emit a | |
980 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
981 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
982 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
983 | 0, /* rightshift */ | |
984 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
985 | 16, /* bitsize */ | |
b34976b6 | 986 | FALSE, /* pc_relative */ |
5bd4f169 AM |
987 | 0, /* bitpos */ |
988 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 989 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb AM |
990 | "R_PPC64_PLTGOT16", /* name */ |
991 | FALSE, /* partial_inplace */ | |
992 | 0, /* src_mask */ | |
993 | 0xffff, /* dst_mask */ | |
994 | FALSE), /* pcrel_offset */ | |
995 | ||
996 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
997 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
998 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
999 | 0, /* rightshift */ | |
1000 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1001 | 16, /* bitsize */ | |
1002 | FALSE, /* pc_relative */ | |
1003 | 0, /* bitpos */ | |
1004 | complain_overflow_dont, /* complain_on_overflow */ | |
1005 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1006 | "R_PPC64_PLTGOT16_LO", /* name */ | |
1007 | FALSE, /* partial_inplace */ | |
1008 | 0, /* src_mask */ | |
1009 | 0xffff, /* dst_mask */ | |
1010 | FALSE), /* pcrel_offset */ | |
1011 | ||
1012 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
1013 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
1014 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
1015 | 16, /* rightshift */ | |
1016 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1017 | 16, /* bitsize */ | |
1018 | FALSE, /* pc_relative */ | |
1019 | 0, /* bitpos */ | |
1020 | complain_overflow_dont, /* complain_on_overflow */ | |
1021 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1022 | "R_PPC64_PLTGOT16_HI", /* name */ | |
1023 | FALSE, /* partial_inplace */ | |
1024 | 0, /* src_mask */ | |
1025 | 0xffff, /* dst_mask */ | |
1026 | FALSE), /* pcrel_offset */ | |
1027 | ||
1028 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
1029 | 1 if the contents of the low 16 bits, treated as a signed number, | |
1030 | is negative. */ | |
1031 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
1032 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
1033 | 16, /* rightshift */ | |
1034 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1035 | 16, /* bitsize */ | |
1036 | FALSE, /* pc_relative */ | |
1037 | 0, /* bitpos */ | |
1038 | complain_overflow_dont,/* complain_on_overflow */ | |
1039 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1040 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1041 | FALSE, /* partial_inplace */ | |
1042 | 0, /* src_mask */ | |
1043 | 0xffff, /* dst_mask */ | |
1044 | FALSE), /* pcrel_offset */ | |
1045 | ||
1046 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1047 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1048 | 0, /* rightshift */ | |
1049 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1050 | 16, /* bitsize */ | |
1051 | FALSE, /* pc_relative */ | |
1052 | 0, /* bitpos */ | |
1053 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1054 | bfd_elf_generic_reloc, /* special_function */ | |
1055 | "R_PPC64_ADDR16_DS", /* name */ | |
1056 | FALSE, /* partial_inplace */ | |
1057 | 0, /* src_mask */ | |
1058 | 0xfffc, /* dst_mask */ | |
1059 | FALSE), /* pcrel_offset */ | |
1060 | ||
1061 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1062 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1063 | 0, /* rightshift */ | |
1064 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1065 | 16, /* bitsize */ | |
1066 | FALSE, /* pc_relative */ | |
1067 | 0, /* bitpos */ | |
1068 | complain_overflow_dont,/* complain_on_overflow */ | |
1069 | bfd_elf_generic_reloc, /* special_function */ | |
1070 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1071 | FALSE, /* partial_inplace */ | |
1072 | 0, /* src_mask */ | |
1073 | 0xfffc, /* dst_mask */ | |
1074 | FALSE), /* pcrel_offset */ | |
1075 | ||
1076 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1077 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1078 | 0, /* rightshift */ | |
1079 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1080 | 16, /* bitsize */ | |
1081 | FALSE, /* pc_relative */ | |
1082 | 0, /* bitpos */ | |
1083 | complain_overflow_signed, /* complain_on_overflow */ | |
1084 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1085 | "R_PPC64_GOT16_DS", /* name */ | |
1086 | FALSE, /* partial_inplace */ | |
1087 | 0, /* src_mask */ | |
1088 | 0xfffc, /* dst_mask */ | |
1089 | FALSE), /* pcrel_offset */ | |
1090 | ||
1091 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1092 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1093 | 0, /* rightshift */ | |
1094 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1095 | 16, /* bitsize */ | |
1096 | FALSE, /* pc_relative */ | |
1097 | 0, /* bitpos */ | |
1098 | complain_overflow_dont, /* complain_on_overflow */ | |
1099 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1100 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1101 | FALSE, /* partial_inplace */ | |
1102 | 0, /* src_mask */ | |
1103 | 0xfffc, /* dst_mask */ | |
1104 | FALSE), /* pcrel_offset */ | |
1105 | ||
1106 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1107 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1108 | 0, /* rightshift */ | |
1109 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1110 | 16, /* bitsize */ | |
1111 | FALSE, /* pc_relative */ | |
1112 | 0, /* bitpos */ | |
1113 | complain_overflow_dont, /* complain_on_overflow */ | |
1114 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1115 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1116 | FALSE, /* partial_inplace */ | |
1117 | 0, /* src_mask */ | |
1118 | 0xfffc, /* dst_mask */ | |
1119 | FALSE), /* pcrel_offset */ | |
1120 | ||
1121 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1122 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1123 | 0, /* rightshift */ | |
1124 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1125 | 16, /* bitsize */ | |
1126 | FALSE, /* pc_relative */ | |
1127 | 0, /* bitpos */ | |
1128 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1129 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1130 | "R_PPC64_SECTOFF_DS", /* name */ | |
1131 | FALSE, /* partial_inplace */ | |
1132 | 0, /* src_mask */ | |
1133 | 0xfffc, /* dst_mask */ | |
1134 | FALSE), /* pcrel_offset */ | |
1135 | ||
1136 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1137 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1138 | 0, /* rightshift */ | |
1139 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1140 | 16, /* bitsize */ | |
1141 | FALSE, /* pc_relative */ | |
1142 | 0, /* bitpos */ | |
1143 | complain_overflow_dont, /* complain_on_overflow */ | |
1144 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1145 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1146 | FALSE, /* partial_inplace */ | |
1147 | 0, /* src_mask */ | |
1148 | 0xfffc, /* dst_mask */ | |
1149 | FALSE), /* pcrel_offset */ | |
1150 | ||
1151 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1152 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1153 | 0, /* rightshift */ | |
1154 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1155 | 16, /* bitsize */ | |
1156 | FALSE, /* pc_relative */ | |
1157 | 0, /* bitpos */ | |
1158 | complain_overflow_signed, /* complain_on_overflow */ | |
1159 | ppc64_elf_toc_reloc, /* special_function */ | |
1160 | "R_PPC64_TOC16_DS", /* name */ | |
1161 | FALSE, /* partial_inplace */ | |
1162 | 0, /* src_mask */ | |
1163 | 0xfffc, /* dst_mask */ | |
1164 | FALSE), /* pcrel_offset */ | |
1165 | ||
1166 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1167 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1168 | 0, /* rightshift */ | |
1169 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1170 | 16, /* bitsize */ | |
1171 | FALSE, /* pc_relative */ | |
1172 | 0, /* bitpos */ | |
1173 | complain_overflow_dont, /* complain_on_overflow */ | |
1174 | ppc64_elf_toc_reloc, /* special_function */ | |
1175 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1176 | FALSE, /* partial_inplace */ | |
1177 | 0, /* src_mask */ | |
1178 | 0xfffc, /* dst_mask */ | |
1179 | FALSE), /* pcrel_offset */ | |
1180 | ||
1181 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1182 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1183 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ | |
1184 | 0, /* rightshift */ | |
1185 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1186 | 16, /* bitsize */ | |
1187 | FALSE, /* pc_relative */ | |
1188 | 0, /* bitpos */ | |
1189 | complain_overflow_signed, /* complain_on_overflow */ | |
1190 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1191 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1192 | FALSE, /* partial_inplace */ | |
1193 | 0, /* src_mask */ | |
1194 | 0xfffc, /* dst_mask */ | |
1195 | FALSE), /* pcrel_offset */ | |
1196 | ||
1197 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1198 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1199 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1200 | 0, /* rightshift */ | |
1201 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1202 | 16, /* bitsize */ | |
1203 | FALSE, /* pc_relative */ | |
1204 | 0, /* bitpos */ | |
1205 | complain_overflow_dont, /* complain_on_overflow */ | |
1206 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1207 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1208 | FALSE, /* partial_inplace */ | |
1209 | 0, /* src_mask */ | |
1210 | 0xfffc, /* dst_mask */ | |
1211 | FALSE), /* pcrel_offset */ | |
1212 | ||
1213 | /* Marker reloc for TLS. */ | |
1214 | HOWTO (R_PPC64_TLS, | |
1215 | 0, /* rightshift */ | |
1216 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1217 | 32, /* bitsize */ | |
1218 | FALSE, /* pc_relative */ | |
1219 | 0, /* bitpos */ | |
1220 | complain_overflow_dont, /* complain_on_overflow */ | |
1221 | bfd_elf_generic_reloc, /* special_function */ | |
1222 | "R_PPC64_TLS", /* name */ | |
1223 | FALSE, /* partial_inplace */ | |
1224 | 0, /* src_mask */ | |
1225 | 0, /* dst_mask */ | |
1226 | FALSE), /* pcrel_offset */ | |
1227 | ||
1228 | /* Computes the load module index of the load module that contains the | |
1229 | definition of its TLS sym. */ | |
1230 | HOWTO (R_PPC64_DTPMOD64, | |
1231 | 0, /* rightshift */ | |
1232 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1233 | 64, /* bitsize */ | |
1234 | FALSE, /* pc_relative */ | |
1235 | 0, /* bitpos */ | |
1236 | complain_overflow_dont, /* complain_on_overflow */ | |
1237 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1238 | "R_PPC64_DTPMOD64", /* name */ | |
1239 | FALSE, /* partial_inplace */ | |
1240 | 0, /* src_mask */ | |
1241 | ONES (64), /* dst_mask */ | |
1242 | FALSE), /* pcrel_offset */ | |
1243 | ||
1244 | /* Computes a dtv-relative displacement, the difference between the value | |
1245 | of sym+add and the base address of the thread-local storage block that | |
1246 | contains the definition of sym, minus 0x8000. */ | |
1247 | HOWTO (R_PPC64_DTPREL64, | |
1248 | 0, /* rightshift */ | |
1249 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1250 | 64, /* bitsize */ | |
1251 | FALSE, /* pc_relative */ | |
1252 | 0, /* bitpos */ | |
1253 | complain_overflow_dont, /* complain_on_overflow */ | |
1254 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1255 | "R_PPC64_DTPREL64", /* name */ | |
1256 | FALSE, /* partial_inplace */ | |
1257 | 0, /* src_mask */ | |
1258 | ONES (64), /* dst_mask */ | |
1259 | FALSE), /* pcrel_offset */ | |
1260 | ||
1261 | /* A 16 bit dtprel reloc. */ | |
1262 | HOWTO (R_PPC64_DTPREL16, | |
1263 | 0, /* rightshift */ | |
1264 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1265 | 16, /* bitsize */ | |
1266 | FALSE, /* pc_relative */ | |
1267 | 0, /* bitpos */ | |
1268 | complain_overflow_signed, /* complain_on_overflow */ | |
1269 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1270 | "R_PPC64_DTPREL16", /* name */ | |
1271 | FALSE, /* partial_inplace */ | |
1272 | 0, /* src_mask */ | |
1273 | 0xffff, /* dst_mask */ | |
1274 | FALSE), /* pcrel_offset */ | |
1275 | ||
1276 | /* Like DTPREL16, but no overflow. */ | |
1277 | HOWTO (R_PPC64_DTPREL16_LO, | |
1278 | 0, /* rightshift */ | |
1279 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1280 | 16, /* bitsize */ | |
1281 | FALSE, /* pc_relative */ | |
1282 | 0, /* bitpos */ | |
1283 | complain_overflow_dont, /* complain_on_overflow */ | |
1284 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1285 | "R_PPC64_DTPREL16_LO", /* name */ | |
1286 | FALSE, /* partial_inplace */ | |
1287 | 0, /* src_mask */ | |
1288 | 0xffff, /* dst_mask */ | |
1289 | FALSE), /* pcrel_offset */ | |
1290 | ||
1291 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ | |
1292 | HOWTO (R_PPC64_DTPREL16_HI, | |
1293 | 16, /* rightshift */ | |
1294 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1295 | 16, /* bitsize */ | |
1296 | FALSE, /* pc_relative */ | |
1297 | 0, /* bitpos */ | |
1298 | complain_overflow_dont, /* complain_on_overflow */ | |
1299 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1300 | "R_PPC64_DTPREL16_HI", /* name */ | |
1301 | FALSE, /* partial_inplace */ | |
1302 | 0, /* src_mask */ | |
1303 | 0xffff, /* dst_mask */ | |
1304 | FALSE), /* pcrel_offset */ | |
1305 | ||
1306 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ | |
1307 | HOWTO (R_PPC64_DTPREL16_HA, | |
1308 | 16, /* rightshift */ | |
1309 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1310 | 16, /* bitsize */ | |
1311 | FALSE, /* pc_relative */ | |
1312 | 0, /* bitpos */ | |
1313 | complain_overflow_dont, /* complain_on_overflow */ | |
1314 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1315 | "R_PPC64_DTPREL16_HA", /* name */ | |
1316 | FALSE, /* partial_inplace */ | |
1317 | 0, /* src_mask */ | |
1318 | 0xffff, /* dst_mask */ | |
1319 | FALSE), /* pcrel_offset */ | |
1320 | ||
1321 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ | |
1322 | HOWTO (R_PPC64_DTPREL16_HIGHER, | |
1323 | 32, /* rightshift */ | |
1324 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1325 | 16, /* bitsize */ | |
1326 | FALSE, /* pc_relative */ | |
1327 | 0, /* bitpos */ | |
1328 | complain_overflow_dont, /* complain_on_overflow */ | |
1329 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1330 | "R_PPC64_DTPREL16_HIGHER", /* name */ | |
1331 | FALSE, /* partial_inplace */ | |
1332 | 0, /* src_mask */ | |
1333 | 0xffff, /* dst_mask */ | |
1334 | FALSE), /* pcrel_offset */ | |
1335 | ||
1336 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ | |
1337 | HOWTO (R_PPC64_DTPREL16_HIGHERA, | |
1338 | 32, /* rightshift */ | |
1339 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1340 | 16, /* bitsize */ | |
1341 | FALSE, /* pc_relative */ | |
1342 | 0, /* bitpos */ | |
1343 | complain_overflow_dont, /* complain_on_overflow */ | |
1344 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1345 | "R_PPC64_DTPREL16_HIGHERA", /* name */ | |
1346 | FALSE, /* partial_inplace */ | |
1347 | 0, /* src_mask */ | |
1348 | 0xffff, /* dst_mask */ | |
1349 | FALSE), /* pcrel_offset */ | |
1350 | ||
1351 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ | |
1352 | HOWTO (R_PPC64_DTPREL16_HIGHEST, | |
1353 | 48, /* rightshift */ | |
1354 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1355 | 16, /* bitsize */ | |
1356 | FALSE, /* pc_relative */ | |
1357 | 0, /* bitpos */ | |
1358 | complain_overflow_dont, /* complain_on_overflow */ | |
1359 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1360 | "R_PPC64_DTPREL16_HIGHEST", /* name */ | |
1361 | FALSE, /* partial_inplace */ | |
1362 | 0, /* src_mask */ | |
1363 | 0xffff, /* dst_mask */ | |
1364 | FALSE), /* pcrel_offset */ | |
1365 | ||
1366 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1367 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, | |
1368 | 48, /* rightshift */ | |
1369 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1370 | 16, /* bitsize */ | |
1371 | FALSE, /* pc_relative */ | |
1372 | 0, /* bitpos */ | |
1373 | complain_overflow_dont, /* complain_on_overflow */ | |
1374 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1375 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ | |
1376 | FALSE, /* partial_inplace */ | |
1377 | 0, /* src_mask */ | |
1378 | 0xffff, /* dst_mask */ | |
1379 | FALSE), /* pcrel_offset */ | |
1380 | ||
1381 | /* Like DTPREL16, but for insns with a DS field. */ | |
1382 | HOWTO (R_PPC64_DTPREL16_DS, | |
1383 | 0, /* rightshift */ | |
1384 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1385 | 16, /* bitsize */ | |
1386 | FALSE, /* pc_relative */ | |
1387 | 0, /* bitpos */ | |
1388 | complain_overflow_signed, /* complain_on_overflow */ | |
1389 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1390 | "R_PPC64_DTPREL16_DS", /* name */ | |
1391 | FALSE, /* partial_inplace */ | |
1392 | 0, /* src_mask */ | |
1393 | 0xfffc, /* dst_mask */ | |
1394 | FALSE), /* pcrel_offset */ | |
1395 | ||
1396 | /* Like DTPREL16_DS, but no overflow. */ | |
1397 | HOWTO (R_PPC64_DTPREL16_LO_DS, | |
1398 | 0, /* rightshift */ | |
1399 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1400 | 16, /* bitsize */ | |
1401 | FALSE, /* pc_relative */ | |
1402 | 0, /* bitpos */ | |
1403 | complain_overflow_dont, /* complain_on_overflow */ | |
1404 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1405 | "R_PPC64_DTPREL16_LO_DS", /* name */ | |
1406 | FALSE, /* partial_inplace */ | |
1407 | 0, /* src_mask */ | |
1408 | 0xfffc, /* dst_mask */ | |
1409 | FALSE), /* pcrel_offset */ | |
1410 | ||
1411 | /* Computes a tp-relative displacement, the difference between the value of | |
1412 | sym+add and the value of the thread pointer (r13). */ | |
1413 | HOWTO (R_PPC64_TPREL64, | |
1414 | 0, /* rightshift */ | |
1415 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1416 | 64, /* bitsize */ | |
1417 | FALSE, /* pc_relative */ | |
1418 | 0, /* bitpos */ | |
1419 | complain_overflow_dont, /* complain_on_overflow */ | |
1420 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1421 | "R_PPC64_TPREL64", /* name */ | |
1422 | FALSE, /* partial_inplace */ | |
1423 | 0, /* src_mask */ | |
1424 | ONES (64), /* dst_mask */ | |
1425 | FALSE), /* pcrel_offset */ | |
1426 | ||
1427 | /* A 16 bit tprel reloc. */ | |
1428 | HOWTO (R_PPC64_TPREL16, | |
1429 | 0, /* rightshift */ | |
1430 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1431 | 16, /* bitsize */ | |
1432 | FALSE, /* pc_relative */ | |
1433 | 0, /* bitpos */ | |
1434 | complain_overflow_signed, /* complain_on_overflow */ | |
1435 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1436 | "R_PPC64_TPREL16", /* name */ | |
1437 | FALSE, /* partial_inplace */ | |
1438 | 0, /* src_mask */ | |
1439 | 0xffff, /* dst_mask */ | |
1440 | FALSE), /* pcrel_offset */ | |
1441 | ||
1442 | /* Like TPREL16, but no overflow. */ | |
1443 | HOWTO (R_PPC64_TPREL16_LO, | |
1444 | 0, /* rightshift */ | |
1445 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1446 | 16, /* bitsize */ | |
1447 | FALSE, /* pc_relative */ | |
1448 | 0, /* bitpos */ | |
1449 | complain_overflow_dont, /* complain_on_overflow */ | |
1450 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1451 | "R_PPC64_TPREL16_LO", /* name */ | |
1452 | FALSE, /* partial_inplace */ | |
1453 | 0, /* src_mask */ | |
1454 | 0xffff, /* dst_mask */ | |
1455 | FALSE), /* pcrel_offset */ | |
1456 | ||
1457 | /* Like TPREL16_LO, but next higher group of 16 bits. */ | |
1458 | HOWTO (R_PPC64_TPREL16_HI, | |
1459 | 16, /* rightshift */ | |
1460 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1461 | 16, /* bitsize */ | |
1462 | FALSE, /* pc_relative */ | |
1463 | 0, /* bitpos */ | |
1464 | complain_overflow_dont, /* complain_on_overflow */ | |
1465 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1466 | "R_PPC64_TPREL16_HI", /* name */ | |
1467 | FALSE, /* partial_inplace */ | |
1468 | 0, /* src_mask */ | |
1469 | 0xffff, /* dst_mask */ | |
1470 | FALSE), /* pcrel_offset */ | |
1471 | ||
1472 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1473 | HOWTO (R_PPC64_TPREL16_HA, | |
1474 | 16, /* rightshift */ | |
1475 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1476 | 16, /* bitsize */ | |
1477 | FALSE, /* pc_relative */ | |
1478 | 0, /* bitpos */ | |
1479 | complain_overflow_dont, /* complain_on_overflow */ | |
1480 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1481 | "R_PPC64_TPREL16_HA", /* name */ | |
1482 | FALSE, /* partial_inplace */ | |
1483 | 0, /* src_mask */ | |
1484 | 0xffff, /* dst_mask */ | |
1485 | FALSE), /* pcrel_offset */ | |
1486 | ||
1487 | /* Like TPREL16_HI, but next higher group of 16 bits. */ | |
1488 | HOWTO (R_PPC64_TPREL16_HIGHER, | |
1489 | 32, /* rightshift */ | |
1490 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1491 | 16, /* bitsize */ | |
1492 | FALSE, /* pc_relative */ | |
1493 | 0, /* bitpos */ | |
1494 | complain_overflow_dont, /* complain_on_overflow */ | |
1495 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1496 | "R_PPC64_TPREL16_HIGHER", /* name */ | |
1497 | FALSE, /* partial_inplace */ | |
1498 | 0, /* src_mask */ | |
1499 | 0xffff, /* dst_mask */ | |
1500 | FALSE), /* pcrel_offset */ | |
1501 | ||
1502 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ | |
1503 | HOWTO (R_PPC64_TPREL16_HIGHERA, | |
1504 | 32, /* rightshift */ | |
1505 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1506 | 16, /* bitsize */ | |
1507 | FALSE, /* pc_relative */ | |
1508 | 0, /* bitpos */ | |
1509 | complain_overflow_dont, /* complain_on_overflow */ | |
1510 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1511 | "R_PPC64_TPREL16_HIGHERA", /* name */ | |
1512 | FALSE, /* partial_inplace */ | |
1513 | 0, /* src_mask */ | |
1514 | 0xffff, /* dst_mask */ | |
1515 | FALSE), /* pcrel_offset */ | |
1516 | ||
1517 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ | |
1518 | HOWTO (R_PPC64_TPREL16_HIGHEST, | |
1519 | 48, /* rightshift */ | |
1520 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1521 | 16, /* bitsize */ | |
1522 | FALSE, /* pc_relative */ | |
1523 | 0, /* bitpos */ | |
1524 | complain_overflow_dont, /* complain_on_overflow */ | |
1525 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1526 | "R_PPC64_TPREL16_HIGHEST", /* name */ | |
1527 | FALSE, /* partial_inplace */ | |
1528 | 0, /* src_mask */ | |
1529 | 0xffff, /* dst_mask */ | |
1530 | FALSE), /* pcrel_offset */ | |
1531 | ||
1532 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1533 | HOWTO (R_PPC64_TPREL16_HIGHESTA, | |
1534 | 48, /* rightshift */ | |
1535 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1536 | 16, /* bitsize */ | |
1537 | FALSE, /* pc_relative */ | |
1538 | 0, /* bitpos */ | |
1539 | complain_overflow_dont, /* complain_on_overflow */ | |
1540 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1541 | "R_PPC64_TPREL16_HIGHESTA", /* name */ | |
1542 | FALSE, /* partial_inplace */ | |
1543 | 0, /* src_mask */ | |
1544 | 0xffff, /* dst_mask */ | |
1545 | FALSE), /* pcrel_offset */ | |
1546 | ||
1547 | /* Like TPREL16, but for insns with a DS field. */ | |
1548 | HOWTO (R_PPC64_TPREL16_DS, | |
1549 | 0, /* rightshift */ | |
1550 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1551 | 16, /* bitsize */ | |
1552 | FALSE, /* pc_relative */ | |
1553 | 0, /* bitpos */ | |
1554 | complain_overflow_signed, /* complain_on_overflow */ | |
1555 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1556 | "R_PPC64_TPREL16_DS", /* name */ | |
1557 | FALSE, /* partial_inplace */ | |
1558 | 0, /* src_mask */ | |
1559 | 0xfffc, /* dst_mask */ | |
1560 | FALSE), /* pcrel_offset */ | |
1561 | ||
1562 | /* Like TPREL16_DS, but no overflow. */ | |
1563 | HOWTO (R_PPC64_TPREL16_LO_DS, | |
1564 | 0, /* rightshift */ | |
1565 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1566 | 16, /* bitsize */ | |
1567 | FALSE, /* pc_relative */ | |
1568 | 0, /* bitpos */ | |
1569 | complain_overflow_dont, /* complain_on_overflow */ | |
1570 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1571 | "R_PPC64_TPREL16_LO_DS", /* name */ | |
1572 | FALSE, /* partial_inplace */ | |
1573 | 0, /* src_mask */ | |
1574 | 0xfffc, /* dst_mask */ | |
1575 | FALSE), /* pcrel_offset */ | |
1576 | ||
1577 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1578 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1579 | to the first entry relative to the TOC base (r2). */ | |
1580 | HOWTO (R_PPC64_GOT_TLSGD16, | |
1581 | 0, /* rightshift */ | |
1582 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1583 | 16, /* bitsize */ | |
1584 | FALSE, /* pc_relative */ | |
1585 | 0, /* bitpos */ | |
1586 | complain_overflow_signed, /* complain_on_overflow */ | |
1587 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1588 | "R_PPC64_GOT_TLSGD16", /* name */ | |
b34976b6 | 1589 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1590 | 0, /* src_mask */ |
1591 | 0xffff, /* dst_mask */ | |
b34976b6 | 1592 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1593 | |
411e1bfb AM |
1594 | /* Like GOT_TLSGD16, but no overflow. */ |
1595 | HOWTO (R_PPC64_GOT_TLSGD16_LO, | |
5bd4f169 AM |
1596 | 0, /* rightshift */ |
1597 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1598 | 16, /* bitsize */ | |
b34976b6 | 1599 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1600 | 0, /* bitpos */ |
1601 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1602 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1603 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
b34976b6 | 1604 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1605 | 0, /* src_mask */ |
1606 | 0xffff, /* dst_mask */ | |
b34976b6 | 1607 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1608 | |
411e1bfb AM |
1609 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1610 | HOWTO (R_PPC64_GOT_TLSGD16_HI, | |
5bd4f169 AM |
1611 | 16, /* rightshift */ |
1612 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1613 | 16, /* bitsize */ | |
b34976b6 | 1614 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1615 | 0, /* bitpos */ |
1616 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1617 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1618 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
b34976b6 | 1619 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1620 | 0, /* src_mask */ |
1621 | 0xffff, /* dst_mask */ | |
b34976b6 | 1622 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1623 | |
411e1bfb AM |
1624 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1625 | HOWTO (R_PPC64_GOT_TLSGD16_HA, | |
5bd4f169 AM |
1626 | 16, /* rightshift */ |
1627 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1628 | 16, /* bitsize */ | |
b34976b6 | 1629 | FALSE, /* pc_relative */ |
5bd4f169 | 1630 | 0, /* bitpos */ |
411e1bfb | 1631 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1632 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1633 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
b34976b6 | 1634 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1635 | 0, /* src_mask */ |
1636 | 0xffff, /* dst_mask */ | |
b34976b6 | 1637 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1638 | |
411e1bfb AM |
1639 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
1640 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1641 | first entry relative to the TOC base (r2). */ | |
1642 | HOWTO (R_PPC64_GOT_TLSLD16, | |
5bd4f169 AM |
1643 | 0, /* rightshift */ |
1644 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1645 | 16, /* bitsize */ | |
b34976b6 | 1646 | FALSE, /* pc_relative */ |
5bd4f169 | 1647 | 0, /* bitpos */ |
411e1bfb AM |
1648 | complain_overflow_signed, /* complain_on_overflow */ |
1649 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1650 | "R_PPC64_GOT_TLSLD16", /* name */ | |
b34976b6 | 1651 | FALSE, /* partial_inplace */ |
d006db6c | 1652 | 0, /* src_mask */ |
411e1bfb | 1653 | 0xffff, /* dst_mask */ |
b34976b6 | 1654 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1655 | |
411e1bfb AM |
1656 | /* Like GOT_TLSLD16, but no overflow. */ |
1657 | HOWTO (R_PPC64_GOT_TLSLD16_LO, | |
5bd4f169 AM |
1658 | 0, /* rightshift */ |
1659 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1660 | 16, /* bitsize */ | |
b34976b6 | 1661 | FALSE, /* pc_relative */ |
5bd4f169 | 1662 | 0, /* bitpos */ |
411e1bfb AM |
1663 | complain_overflow_dont, /* complain_on_overflow */ |
1664 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1665 | "R_PPC64_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1666 | FALSE, /* partial_inplace */ |
d006db6c | 1667 | 0, /* src_mask */ |
411e1bfb | 1668 | 0xffff, /* dst_mask */ |
b34976b6 | 1669 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1670 | |
411e1bfb AM |
1671 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1672 | HOWTO (R_PPC64_GOT_TLSLD16_HI, | |
1673 | 16, /* rightshift */ | |
5bd4f169 AM |
1674 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1675 | 16, /* bitsize */ | |
b34976b6 | 1676 | FALSE, /* pc_relative */ |
5bd4f169 | 1677 | 0, /* bitpos */ |
411e1bfb | 1678 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1679 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1680 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
b34976b6 | 1681 | FALSE, /* partial_inplace */ |
d006db6c | 1682 | 0, /* src_mask */ |
411e1bfb | 1683 | 0xffff, /* dst_mask */ |
b34976b6 | 1684 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1685 | |
411e1bfb AM |
1686 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1687 | HOWTO (R_PPC64_GOT_TLSLD16_HA, | |
1688 | 16, /* rightshift */ | |
5bd4f169 AM |
1689 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1690 | 16, /* bitsize */ | |
b34976b6 | 1691 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1692 | 0, /* bitpos */ |
1693 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1694 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1695 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
b34976b6 | 1696 | FALSE, /* partial_inplace */ |
d006db6c | 1697 | 0, /* src_mask */ |
411e1bfb | 1698 | 0xffff, /* dst_mask */ |
b34976b6 | 1699 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1700 | |
411e1bfb AM |
1701 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
1702 | the offset to the entry relative to the TOC base (r2). */ | |
1703 | HOWTO (R_PPC64_GOT_DTPREL16_DS, | |
5bd4f169 AM |
1704 | 0, /* rightshift */ |
1705 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1706 | 16, /* bitsize */ | |
b34976b6 | 1707 | FALSE, /* pc_relative */ |
5bd4f169 | 1708 | 0, /* bitpos */ |
411e1bfb | 1709 | complain_overflow_signed, /* complain_on_overflow */ |
805fc799 | 1710 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1711 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
b34976b6 | 1712 | FALSE, /* partial_inplace */ |
d006db6c | 1713 | 0, /* src_mask */ |
5bd4f169 | 1714 | 0xfffc, /* dst_mask */ |
b34976b6 | 1715 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1716 | |
411e1bfb AM |
1717 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
1718 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, | |
5bd4f169 | 1719 | 0, /* rightshift */ |
c061c2d8 AM |
1720 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1721 | 16, /* bitsize */ | |
b34976b6 | 1722 | FALSE, /* pc_relative */ |
5bd4f169 | 1723 | 0, /* bitpos */ |
411e1bfb AM |
1724 | complain_overflow_dont, /* complain_on_overflow */ |
1725 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1726 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ | |
b34976b6 | 1727 | FALSE, /* partial_inplace */ |
d006db6c | 1728 | 0, /* src_mask */ |
c061c2d8 | 1729 | 0xfffc, /* dst_mask */ |
b34976b6 | 1730 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1731 | |
411e1bfb AM |
1732 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
1733 | HOWTO (R_PPC64_GOT_DTPREL16_HI, | |
1734 | 16, /* rightshift */ | |
5bd4f169 AM |
1735 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1736 | 16, /* bitsize */ | |
b34976b6 | 1737 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1738 | 0, /* bitpos */ |
1739 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1740 | ppc64_elf_unhandled_reloc, /* special_function */ |
1741 | "R_PPC64_GOT_DTPREL16_HI", /* name */ | |
b34976b6 | 1742 | FALSE, /* partial_inplace */ |
d006db6c | 1743 | 0, /* src_mask */ |
411e1bfb | 1744 | 0xffff, /* dst_mask */ |
b34976b6 | 1745 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1746 | |
411e1bfb AM |
1747 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1748 | HOWTO (R_PPC64_GOT_DTPREL16_HA, | |
1749 | 16, /* rightshift */ | |
1750 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1751 | 16, /* bitsize */ | |
1752 | FALSE, /* pc_relative */ | |
1753 | 0, /* bitpos */ | |
1754 | complain_overflow_dont, /* complain_on_overflow */ | |
1755 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1756 | "R_PPC64_GOT_DTPREL16_HA", /* name */ | |
1757 | FALSE, /* partial_inplace */ | |
1758 | 0, /* src_mask */ | |
1759 | 0xffff, /* dst_mask */ | |
1760 | FALSE), /* pcrel_offset */ | |
1761 | ||
1762 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the | |
1763 | offset to the entry relative to the TOC base (r2). */ | |
1764 | HOWTO (R_PPC64_GOT_TPREL16_DS, | |
5bd4f169 AM |
1765 | 0, /* rightshift */ |
1766 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1767 | 16, /* bitsize */ | |
b34976b6 | 1768 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1769 | 0, /* bitpos */ |
1770 | complain_overflow_signed, /* complain_on_overflow */ | |
411e1bfb AM |
1771 | ppc64_elf_unhandled_reloc, /* special_function */ |
1772 | "R_PPC64_GOT_TPREL16_DS", /* name */ | |
b34976b6 | 1773 | FALSE, /* partial_inplace */ |
d006db6c | 1774 | 0, /* src_mask */ |
ad8e1ba5 | 1775 | 0xfffc, /* dst_mask */ |
b34976b6 | 1776 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1777 | |
411e1bfb AM |
1778 | /* Like GOT_TPREL16_DS, but no overflow. */ |
1779 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, | |
5bd4f169 AM |
1780 | 0, /* rightshift */ |
1781 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1782 | 16, /* bitsize */ | |
b34976b6 | 1783 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1784 | 0, /* bitpos */ |
1785 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1786 | ppc64_elf_unhandled_reloc, /* special_function */ |
1787 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ | |
b34976b6 | 1788 | FALSE, /* partial_inplace */ |
d006db6c | 1789 | 0, /* src_mask */ |
ad8e1ba5 | 1790 | 0xfffc, /* dst_mask */ |
b34976b6 | 1791 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1792 | |
411e1bfb AM |
1793 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
1794 | HOWTO (R_PPC64_GOT_TPREL16_HI, | |
1795 | 16, /* rightshift */ | |
5bd4f169 AM |
1796 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1797 | 16, /* bitsize */ | |
b34976b6 | 1798 | FALSE, /* pc_relative */ |
5bd4f169 | 1799 | 0, /* bitpos */ |
411e1bfb | 1800 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1801 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1802 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
b34976b6 | 1803 | FALSE, /* partial_inplace */ |
d006db6c | 1804 | 0, /* src_mask */ |
411e1bfb | 1805 | 0xffff, /* dst_mask */ |
b34976b6 | 1806 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1807 | |
411e1bfb AM |
1808 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
1809 | HOWTO (R_PPC64_GOT_TPREL16_HA, | |
1810 | 16, /* rightshift */ | |
5bd4f169 AM |
1811 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1812 | 16, /* bitsize */ | |
b34976b6 | 1813 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1814 | 0, /* bitpos */ |
1815 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1816 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1817 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
b34976b6 | 1818 | FALSE, /* partial_inplace */ |
d006db6c | 1819 | 0, /* src_mask */ |
411e1bfb | 1820 | 0xffff, /* dst_mask */ |
b34976b6 | 1821 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1822 | |
1823 | /* GNU extension to record C++ vtable hierarchy. */ | |
1824 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1825 | 0, /* rightshift */ | |
1826 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1827 | 0, /* bitsize */ | |
b34976b6 | 1828 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1829 | 0, /* bitpos */ |
1830 | complain_overflow_dont, /* complain_on_overflow */ | |
1831 | NULL, /* special_function */ | |
1832 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1833 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1834 | 0, /* src_mask */ |
1835 | 0, /* dst_mask */ | |
b34976b6 | 1836 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1837 | |
1838 | /* GNU extension to record C++ vtable member usage. */ | |
1839 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1840 | 0, /* rightshift */ | |
1841 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1842 | 0, /* bitsize */ | |
b34976b6 | 1843 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1844 | 0, /* bitpos */ |
1845 | complain_overflow_dont, /* complain_on_overflow */ | |
1846 | NULL, /* special_function */ | |
1847 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1848 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1849 | 0, /* src_mask */ |
1850 | 0, /* dst_mask */ | |
b34976b6 | 1851 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1852 | }; |
1853 | ||
1854 | \f | |
1855 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1856 | be done. */ | |
1857 | ||
1858 | static void | |
4ce794b7 | 1859 | ppc_howto_init (void) |
5bd4f169 AM |
1860 | { |
1861 | unsigned int i, type; | |
1862 | ||
1863 | for (i = 0; | |
1864 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1865 | i++) | |
1866 | { | |
1867 | type = ppc64_elf_howto_raw[i].type; | |
1868 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1869 | / sizeof (ppc64_elf_howto_table[0]))); | |
1870 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1871 | } | |
1872 | } | |
1873 | ||
1874 | static reloc_howto_type * | |
4ce794b7 AM |
1875 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1876 | bfd_reloc_code_real_type code) | |
5bd4f169 | 1877 | { |
411e1bfb | 1878 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
5bd4f169 AM |
1879 | |
1880 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1881 | /* Initialize howto table if needed. */ | |
1882 | ppc_howto_init (); | |
1883 | ||
4ce794b7 | 1884 | switch (code) |
5bd4f169 AM |
1885 | { |
1886 | default: | |
4ce794b7 | 1887 | return NULL; |
5bd4f169 | 1888 | |
411e1bfb AM |
1889 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
1890 | break; | |
1891 | case BFD_RELOC_32: r = R_PPC64_ADDR32; | |
1892 | break; | |
1893 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; | |
1894 | break; | |
1895 | case BFD_RELOC_16: r = R_PPC64_ADDR16; | |
1896 | break; | |
1897 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; | |
1898 | break; | |
1899 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; | |
1900 | break; | |
1901 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; | |
5bd4f169 | 1902 | break; |
411e1bfb | 1903 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
5bd4f169 | 1904 | break; |
411e1bfb | 1905 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
5bd4f169 | 1906 | break; |
411e1bfb | 1907 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
5bd4f169 | 1908 | break; |
411e1bfb | 1909 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
5bd4f169 | 1910 | break; |
411e1bfb | 1911 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
5bd4f169 | 1912 | break; |
411e1bfb | 1913 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
5bd4f169 | 1914 | break; |
411e1bfb | 1915 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
5bd4f169 | 1916 | break; |
411e1bfb | 1917 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
5bd4f169 | 1918 | break; |
411e1bfb | 1919 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
5bd4f169 | 1920 | break; |
411e1bfb | 1921 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
5bd4f169 | 1922 | break; |
411e1bfb | 1923 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
5bd4f169 | 1924 | break; |
411e1bfb | 1925 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
5bd4f169 | 1926 | break; |
411e1bfb | 1927 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
5bd4f169 | 1928 | break; |
411e1bfb | 1929 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
5bd4f169 | 1930 | break; |
411e1bfb | 1931 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
5bd4f169 | 1932 | break; |
411e1bfb | 1933 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
5bd4f169 | 1934 | break; |
411e1bfb | 1935 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
5bd4f169 | 1936 | break; |
411e1bfb | 1937 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
5bd4f169 | 1938 | break; |
411e1bfb | 1939 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
5bd4f169 | 1940 | break; |
411e1bfb | 1941 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
5bd4f169 | 1942 | break; |
411e1bfb | 1943 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
5bd4f169 | 1944 | break; |
411e1bfb | 1945 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
5bd4f169 | 1946 | break; |
411e1bfb | 1947 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
5bd4f169 | 1948 | break; |
411e1bfb | 1949 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
5bd4f169 | 1950 | break; |
411e1bfb | 1951 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
5bd4f169 | 1952 | break; |
411e1bfb | 1953 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
5bd4f169 | 1954 | break; |
411e1bfb | 1955 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
5bd4f169 | 1956 | break; |
411e1bfb | 1957 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
5bd4f169 | 1958 | break; |
411e1bfb | 1959 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
5bd4f169 | 1960 | break; |
411e1bfb | 1961 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
5bd4f169 | 1962 | break; |
411e1bfb | 1963 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
5bd4f169 | 1964 | break; |
411e1bfb | 1965 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
5bd4f169 | 1966 | break; |
411e1bfb | 1967 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
5bd4f169 | 1968 | break; |
411e1bfb | 1969 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
5bd4f169 | 1970 | break; |
411e1bfb | 1971 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
5bd4f169 | 1972 | break; |
411e1bfb | 1973 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
5bd4f169 | 1974 | break; |
411e1bfb | 1975 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
5bd4f169 | 1976 | break; |
411e1bfb | 1977 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
5bd4f169 | 1978 | break; |
411e1bfb | 1979 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
5bd4f169 | 1980 | break; |
411e1bfb | 1981 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
5bd4f169 | 1982 | break; |
411e1bfb | 1983 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
5bd4f169 | 1984 | break; |
411e1bfb | 1985 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
5bd4f169 | 1986 | break; |
411e1bfb | 1987 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
5bd4f169 | 1988 | break; |
411e1bfb | 1989 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
5bd4f169 | 1990 | break; |
411e1bfb | 1991 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
5bd4f169 | 1992 | break; |
411e1bfb | 1993 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
5bd4f169 | 1994 | break; |
411e1bfb | 1995 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
5bd4f169 | 1996 | break; |
411e1bfb | 1997 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
5bd4f169 | 1998 | break; |
411e1bfb | 1999 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
5bd4f169 | 2000 | break; |
411e1bfb | 2001 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
5bd4f169 | 2002 | break; |
411e1bfb | 2003 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
5bd4f169 | 2004 | break; |
411e1bfb | 2005 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
5bd4f169 | 2006 | break; |
411e1bfb | 2007 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
5bd4f169 | 2008 | break; |
411e1bfb | 2009 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
5bd4f169 | 2010 | break; |
411e1bfb | 2011 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
5bd4f169 | 2012 | break; |
411e1bfb | 2013 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
5bd4f169 | 2014 | break; |
411e1bfb | 2015 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
5bd4f169 | 2016 | break; |
411e1bfb | 2017 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
5bd4f169 | 2018 | break; |
411e1bfb | 2019 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
5bd4f169 | 2020 | break; |
411e1bfb AM |
2021 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
2022 | break; | |
2023 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; | |
2024 | break; | |
2025 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; | |
2026 | break; | |
2027 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; | |
2028 | break; | |
2029 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; | |
2030 | break; | |
2031 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; | |
2032 | break; | |
2033 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; | |
2034 | break; | |
2035 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; | |
2036 | break; | |
2037 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; | |
2038 | break; | |
2039 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; | |
2040 | break; | |
2041 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; | |
2042 | break; | |
2043 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; | |
2044 | break; | |
2045 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; | |
2046 | break; | |
2047 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; | |
2048 | break; | |
2049 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; | |
2050 | break; | |
2051 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; | |
2052 | break; | |
2053 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; | |
2054 | break; | |
2055 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; | |
2056 | break; | |
2057 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; | |
2058 | break; | |
2059 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; | |
2060 | break; | |
2061 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; | |
2062 | break; | |
2063 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; | |
2064 | break; | |
2065 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; | |
2066 | break; | |
2067 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; | |
2068 | break; | |
2069 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; | |
2070 | break; | |
2071 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; | |
2072 | break; | |
2073 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; | |
2074 | break; | |
2075 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; | |
2076 | break; | |
2077 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; | |
2078 | break; | |
2079 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; | |
2080 | break; | |
2081 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; | |
2082 | break; | |
2083 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; | |
2084 | break; | |
2085 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; | |
2086 | break; | |
2087 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; | |
2088 | break; | |
2089 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; | |
5bd4f169 AM |
2090 | break; |
2091 | } | |
2092 | ||
4ce794b7 | 2093 | return ppc64_elf_howto_table[r]; |
5bd4f169 AM |
2094 | }; |
2095 | ||
2096 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
2097 | ||
2098 | static void | |
4ce794b7 AM |
2099 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
2100 | Elf_Internal_Rela *dst) | |
5bd4f169 | 2101 | { |
65f38f15 AM |
2102 | unsigned int type; |
2103 | ||
ef60b7ff | 2104 | /* Initialize howto table if needed. */ |
5bd4f169 | 2105 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
2106 | ppc_howto_init (); |
2107 | ||
65f38f15 AM |
2108 | type = ELF64_R_TYPE (dst->r_info); |
2109 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
2110 | / sizeof (ppc64_elf_howto_table[0]))); | |
2111 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
2112 | } |
2113 | ||
04c9666a | 2114 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
2115 | |
2116 | static bfd_reloc_status_type | |
4ce794b7 AM |
2117 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2118 | void *data, asection *input_section, | |
2119 | bfd *output_bfd, char **error_message) | |
5bd4f169 | 2120 | { |
805fc799 AM |
2121 | /* If this is a relocatable link (output_bfd test tells us), just |
2122 | call the generic function. Any adjustment will be done at final | |
2123 | link time. */ | |
2124 | if (output_bfd != NULL) | |
cedb70c5 | 2125 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2126 | input_section, output_bfd, error_message); |
2127 | ||
2128 | /* Adjust the addend for sign extension of the low 16 bits. | |
2129 | We won't actually be using the low 16 bits, so trashing them | |
2130 | doesn't matter. */ | |
2131 | reloc_entry->addend += 0x8000; | |
2132 | return bfd_reloc_continue; | |
2133 | } | |
5bd4f169 | 2134 | |
805fc799 | 2135 | static bfd_reloc_status_type |
4ce794b7 AM |
2136 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2137 | void *data, asection *input_section, | |
2138 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2139 | { |
2140 | long insn; | |
04c9666a | 2141 | enum elf_ppc64_reloc_type r_type; |
805fc799 AM |
2142 | bfd_size_type octets; |
2143 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 2144 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
2145 | |
2146 | /* If this is a relocatable link (output_bfd test tells us), just | |
2147 | call the generic function. Any adjustment will be done at final | |
2148 | link time. */ | |
5bd4f169 | 2149 | if (output_bfd != NULL) |
cedb70c5 | 2150 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2151 | input_section, output_bfd, error_message); |
2152 | ||
2153 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2154 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2155 | insn &= ~(0x01 << 21); | |
4ce794b7 | 2156 | r_type = reloc_entry->howto->type; |
805fc799 AM |
2157 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
2158 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 2159 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
2160 | |
2161 | if (is_power4) | |
5bd4f169 | 2162 | { |
805fc799 AM |
2163 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
2164 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
2165 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
2166 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
2167 | insn |= 0x02 << 21; | |
2168 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
2169 | insn |= 0x08 << 21; | |
2170 | else | |
2171 | return bfd_reloc_continue; | |
5bd4f169 | 2172 | } |
805fc799 AM |
2173 | else |
2174 | { | |
2175 | bfd_vma target = 0; | |
2176 | bfd_vma from; | |
5bd4f169 | 2177 | |
805fc799 AM |
2178 | if (!bfd_is_com_section (symbol->section)) |
2179 | target = symbol->value; | |
2180 | target += symbol->section->output_section->vma; | |
2181 | target += symbol->section->output_offset; | |
2182 | target += reloc_entry->addend; | |
5bd4f169 | 2183 | |
805fc799 AM |
2184 | from = (reloc_entry->address |
2185 | + input_section->output_offset | |
2186 | + input_section->output_section->vma); | |
5bd4f169 | 2187 | |
805fc799 AM |
2188 | /* Invert 'y' bit if not the default. */ |
2189 | if ((bfd_signed_vma) (target - from) < 0) | |
2190 | insn ^= 0x01 << 21; | |
2191 | } | |
4ce794b7 | 2192 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
805fc799 AM |
2193 | return bfd_reloc_continue; |
2194 | } | |
5bd4f169 | 2195 | |
805fc799 | 2196 | static bfd_reloc_status_type |
4ce794b7 AM |
2197 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2198 | void *data, asection *input_section, | |
2199 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2200 | { |
2201 | /* If this is a relocatable link (output_bfd test tells us), just | |
2202 | call the generic function. Any adjustment will be done at final | |
2203 | link time. */ | |
2204 | if (output_bfd != NULL) | |
cedb70c5 | 2205 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 2206 | input_section, output_bfd, error_message); |
5bd4f169 | 2207 | |
805fc799 AM |
2208 | /* Subtract the symbol section base address. */ |
2209 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
2210 | return bfd_reloc_continue; |
2211 | } | |
2212 | ||
805fc799 | 2213 | static bfd_reloc_status_type |
4ce794b7 AM |
2214 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2215 | void *data, asection *input_section, | |
2216 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2217 | { |
2218 | /* If this is a relocatable link (output_bfd test tells us), just | |
2219 | call the generic function. Any adjustment will be done at final | |
2220 | link time. */ | |
2221 | if (output_bfd != NULL) | |
cedb70c5 | 2222 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2223 | input_section, output_bfd, error_message); |
2224 | ||
2225 | /* Subtract the symbol section base address. */ | |
2226 | reloc_entry->addend -= symbol->section->output_section->vma; | |
2227 | ||
2228 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2229 | reloc_entry->addend += 0x8000; | |
2230 | return bfd_reloc_continue; | |
2231 | } | |
2232 | ||
2233 | static bfd_reloc_status_type | |
4ce794b7 AM |
2234 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2235 | void *data, asection *input_section, | |
2236 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2237 | { |
2238 | bfd_vma TOCstart; | |
2239 | ||
2240 | /* If this is a relocatable link (output_bfd test tells us), just | |
2241 | call the generic function. Any adjustment will be done at final | |
2242 | link time. */ | |
2243 | if (output_bfd != NULL) | |
cedb70c5 | 2244 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2245 | input_section, output_bfd, error_message); |
2246 | ||
2247 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2248 | if (TOCstart == 0) | |
2249 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2250 | ||
2251 | /* Subtract the TOC base address. */ | |
2252 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2253 | return bfd_reloc_continue; | |
2254 | } | |
2255 | ||
2256 | static bfd_reloc_status_type | |
4ce794b7 AM |
2257 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2258 | void *data, asection *input_section, | |
2259 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2260 | { |
2261 | bfd_vma TOCstart; | |
2262 | ||
2263 | /* If this is a relocatable link (output_bfd test tells us), just | |
2264 | call the generic function. Any adjustment will be done at final | |
2265 | link time. */ | |
2266 | if (output_bfd != NULL) | |
cedb70c5 | 2267 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2268 | input_section, output_bfd, error_message); |
2269 | ||
2270 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2271 | if (TOCstart == 0) | |
2272 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2273 | ||
2274 | /* Subtract the TOC base address. */ | |
2275 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2276 | ||
2277 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2278 | reloc_entry->addend += 0x8000; | |
2279 | return bfd_reloc_continue; | |
2280 | } | |
2281 | ||
2282 | static bfd_reloc_status_type | |
4ce794b7 AM |
2283 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2284 | void *data, asection *input_section, | |
2285 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2286 | { |
2287 | bfd_vma TOCstart; | |
2288 | bfd_size_type octets; | |
2289 | ||
2290 | /* If this is a relocatable link (output_bfd test tells us), just | |
2291 | call the generic function. Any adjustment will be done at final | |
2292 | link time. */ | |
2293 | if (output_bfd != NULL) | |
cedb70c5 | 2294 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2295 | input_section, output_bfd, error_message); |
2296 | ||
2297 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2298 | if (TOCstart == 0) | |
2299 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2300 | ||
2301 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2302 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
2303 | return bfd_reloc_ok; | |
2304 | } | |
2305 | ||
2306 | static bfd_reloc_status_type | |
4ce794b7 AM |
2307 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2308 | void *data, asection *input_section, | |
2309 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2310 | { |
2311 | /* If this is a relocatable link (output_bfd test tells us), just | |
2312 | call the generic function. Any adjustment will be done at final | |
2313 | link time. */ | |
2314 | if (output_bfd != NULL) | |
cedb70c5 | 2315 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2316 | input_section, output_bfd, error_message); |
2317 | ||
2318 | if (error_message != NULL) | |
2319 | { | |
2320 | static char buf[60]; | |
2321 | sprintf (buf, "generic linker can't handle %s", | |
2322 | reloc_entry->howto->name); | |
2323 | *error_message = buf; | |
2324 | } | |
2325 | return bfd_reloc_dangerous; | |
2326 | } | |
2327 | ||
e717da7e AM |
2328 | struct ppc64_elf_obj_tdata |
2329 | { | |
2330 | struct elf_obj_tdata elf; | |
2331 | ||
2332 | /* Shortcuts to dynamic linker sections. */ | |
2333 | asection *got; | |
2334 | asection *relgot; | |
2335 | ||
81688140 AM |
2336 | /* Used during garbage collection. We attach global symbols defined |
2337 | on removed .opd entries to this section so that the sym is removed. */ | |
2338 | asection *deleted_section; | |
2339 | ||
e717da7e AM |
2340 | /* TLS local dynamic got entry handling. Suppose for multiple GOT |
2341 | sections means we potentially need one of these for each input bfd. */ | |
2342 | union { | |
2343 | bfd_signed_vma refcount; | |
2344 | bfd_vma offset; | |
2345 | } tlsld_got; | |
2346 | }; | |
2347 | ||
2348 | #define ppc64_elf_tdata(bfd) \ | |
2349 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) | |
2350 | ||
2351 | #define ppc64_tlsld_got(bfd) \ | |
2352 | (&ppc64_elf_tdata (bfd)->tlsld_got) | |
2353 | ||
2354 | /* Override the generic function because we store some extras. */ | |
2355 | ||
2356 | static bfd_boolean | |
2357 | ppc64_elf_mkobject (bfd *abfd) | |
2358 | { | |
2359 | bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); | |
2360 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2361 | if (abfd->tdata.any == NULL) | |
2362 | return FALSE; | |
2363 | return TRUE; | |
2364 | } | |
2365 | ||
feee612b AM |
2366 | /* Fix bad default arch selected for a 64 bit input bfd when the |
2367 | default is 32 bit. */ | |
2368 | ||
b34976b6 | 2369 | static bfd_boolean |
4ce794b7 | 2370 | ppc64_elf_object_p (bfd *abfd) |
feee612b AM |
2371 | { |
2372 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
2373 | { | |
2374 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2375 | ||
2376 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
2377 | { | |
2378 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
2379 | abfd->arch_info = abfd->arch_info->next; | |
2380 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
2381 | } | |
2382 | } | |
b34976b6 | 2383 | return TRUE; |
feee612b AM |
2384 | } |
2385 | ||
d37c89e5 AM |
2386 | /* Support for core dump NOTE sections. */ |
2387 | ||
2388 | static bfd_boolean | |
2389 | ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
2390 | { | |
eea6121a | 2391 | size_t offset, size; |
d37c89e5 AM |
2392 | |
2393 | if (note->descsz != 504) | |
2394 | return FALSE; | |
2395 | ||
2396 | /* pr_cursig */ | |
2397 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
2398 | ||
2399 | /* pr_pid */ | |
2400 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32); | |
2401 | ||
2402 | /* pr_reg */ | |
2403 | offset = 112; | |
eea6121a | 2404 | size = 384; |
d37c89e5 AM |
2405 | |
2406 | /* Make a ".reg/999" section. */ | |
2407 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
eea6121a | 2408 | size, note->descpos + offset); |
d37c89e5 AM |
2409 | } |
2410 | ||
2411 | static bfd_boolean | |
2412 | ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
2413 | { | |
2414 | if (note->descsz != 136) | |
2415 | return FALSE; | |
2416 | ||
2417 | elf_tdata (abfd)->core_program | |
2418 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |
2419 | elf_tdata (abfd)->core_command | |
2420 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |
2421 | ||
2422 | return TRUE; | |
2423 | } | |
2424 | ||
5bd4f169 AM |
2425 | /* Merge backend specific data from an object file to the output |
2426 | object file when linking. */ | |
2f6d9989 | 2427 | |
b34976b6 | 2428 | static bfd_boolean |
4ce794b7 | 2429 | ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
5bd4f169 | 2430 | { |
5bd4f169 AM |
2431 | /* Check if we have the same endianess. */ |
2432 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
87e226ce | 2433 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
5bd4f169 AM |
2434 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
2435 | { | |
2436 | const char *msg; | |
2437 | ||
2438 | if (bfd_big_endian (ibfd)) | |
d003868e | 2439 | msg = _("%B: compiled for a big endian system " |
4ce794b7 | 2440 | "and target is little endian"); |
5bd4f169 | 2441 | else |
d003868e | 2442 | msg = _("%B: compiled for a little endian system " |
4ce794b7 | 2443 | "and target is big endian"); |
5bd4f169 | 2444 | |
d003868e | 2445 | (*_bfd_error_handler) (msg, ibfd); |
5bd4f169 AM |
2446 | |
2447 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 2448 | return FALSE; |
5bd4f169 AM |
2449 | } |
2450 | ||
b34976b6 | 2451 | return TRUE; |
5bd4f169 | 2452 | } |
f0abc2a1 | 2453 | |
5d35169e AM |
2454 | /* Add extra PPC sections. */ |
2455 | ||
2456 | static struct bfd_elf_special_section const ppc64_elf_special_sections[]= | |
2457 | { | |
7dcb9820 AM |
2458 | { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
2459 | { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2460 | { ".plt", 4, 0, SHT_NOBITS, 0 }, | |
2461 | { ".toc", 4, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2462 | { ".toc1", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2463 | { ".tocbss", 7, 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2464 | { NULL, 0, 0, 0, 0 } | |
5d35169e AM |
2465 | }; |
2466 | ||
f0abc2a1 AM |
2467 | struct _ppc64_elf_section_data |
2468 | { | |
2469 | struct bfd_elf_section_data elf; | |
411e1bfb AM |
2470 | |
2471 | /* An array with one entry for each opd function descriptor. */ | |
f0abc2a1 AM |
2472 | union |
2473 | { | |
411e1bfb | 2474 | /* Points to the function code section for local opd entries. */ |
f0abc2a1 | 2475 | asection **func_sec; |
411e1bfb | 2476 | /* After editing .opd, adjust references to opd local syms. */ |
f0abc2a1 AM |
2477 | long *adjust; |
2478 | } opd; | |
411e1bfb AM |
2479 | |
2480 | /* An array for toc sections, indexed by offset/8. | |
2481 | Specifies the relocation symbol index used at a given toc offset. */ | |
2482 | unsigned *t_symndx; | |
f0abc2a1 AM |
2483 | }; |
2484 | ||
2485 | #define ppc64_elf_section_data(sec) \ | |
411e1bfb | 2486 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
f0abc2a1 AM |
2487 | |
2488 | static bfd_boolean | |
4ce794b7 | 2489 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
f0abc2a1 AM |
2490 | { |
2491 | struct _ppc64_elf_section_data *sdata; | |
2492 | bfd_size_type amt = sizeof (*sdata); | |
2493 | ||
4ce794b7 | 2494 | sdata = bfd_zalloc (abfd, amt); |
f0abc2a1 AM |
2495 | if (sdata == NULL) |
2496 | return FALSE; | |
4ce794b7 | 2497 | sec->used_by_bfd = sdata; |
f0abc2a1 AM |
2498 | |
2499 | return _bfd_elf_new_section_hook (abfd, sec); | |
2500 | } | |
4025353c AM |
2501 | |
2502 | static void * | |
2503 | get_opd_info (asection * sec) | |
2504 | { | |
2505 | if (sec != NULL | |
2506 | && ppc64_elf_section_data (sec) != NULL | |
2507 | && ppc64_elf_section_data (sec)->opd.adjust != NULL) | |
2508 | return ppc64_elf_section_data (sec)->opd.adjust; | |
2509 | return NULL; | |
2510 | } | |
5bd4f169 | 2511 | \f |
65f38f15 AM |
2512 | /* The following functions are specific to the ELF linker, while |
2513 | functions above are used generally. Those named ppc64_elf_* are | |
2514 | called by the main ELF linker code. They appear in this file more | |
2515 | or less in the order in which they are called. eg. | |
2516 | ppc64_elf_check_relocs is called early in the link process, | |
2517 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
2518 | called. |
2519 | ||
2520 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
2521 | functions have both a function code symbol and a function descriptor | |
2522 | symbol. A call to foo in a relocatable object file looks like: | |
2523 | ||
2524 | . .text | |
2525 | . x: | |
2526 | . bl .foo | |
2527 | . nop | |
2528 | ||
2529 | The function definition in another object file might be: | |
2530 | ||
2531 | . .section .opd | |
2532 | . foo: .quad .foo | |
2533 | . .quad .TOC.@tocbase | |
2534 | . .quad 0 | |
2535 | . | |
2536 | . .text | |
2537 | . .foo: blr | |
2538 | ||
2539 | When the linker resolves the call during a static link, the branch | |
2540 | unsurprisingly just goes to .foo and the .opd information is unused. | |
2541 | If the function definition is in a shared library, things are a little | |
2542 | different: The call goes via a plt call stub, the opd information gets | |
2543 | copied to the plt, and the linker patches the nop. | |
2544 | ||
2545 | . x: | |
2546 | . bl .foo_stub | |
2547 | . ld 2,40(1) | |
2548 | . | |
2549 | . | |
2550 | . .foo_stub: | |
2551 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
411e1bfb | 2552 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
e86ce104 AM |
2553 | . std 2,40(1) # this is the general idea |
2554 | . ld 11,0(12) | |
2555 | . ld 2,8(12) | |
2556 | . mtctr 11 | |
2557 | . ld 11,16(12) | |
2558 | . bctr | |
2559 | . | |
2560 | . .section .plt | |
2561 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
2562 | ||
2563 | The "reloc ()" notation is supposed to indicate that the linker emits | |
2564 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
2565 | copying. | |
2566 | ||
2567 | What are the difficulties here? Well, firstly, the relocations | |
2568 | examined by the linker in check_relocs are against the function code | |
2569 | sym .foo, while the dynamic relocation in the plt is emitted against | |
2570 | the function descriptor symbol, foo. Somewhere along the line, we need | |
2571 | to carefully copy dynamic link information from one symbol to the other. | |
2572 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
2573 | symbol as is normal for most other backends. We need foo dynamic | |
2574 | instead, at least for an application final link. However, when | |
2575 | creating a shared library containing foo, we need to have both symbols | |
2576 | dynamic so that references to .foo are satisfied during the early | |
2577 | stages of linking. Otherwise the linker might decide to pull in a | |
8387904d AM |
2578 | definition from some other object, eg. a static library. |
2579 | ||
2580 | Update: As of August 2004, we support a new convention. Function | |
2581 | calls may use the function descriptor symbol, ie. "bl foo". This | |
2582 | behaves exactly as "bl .foo". */ | |
65f38f15 AM |
2583 | |
2584 | /* The linker needs to keep track of the number of relocs that it | |
2585 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2586 | This is so that it can later discard them if they are found to be | |
2587 | unnecessary. We store the information in a field extending the | |
2588 | regular ELF linker hash table. */ | |
2589 | ||
2590 | struct ppc_dyn_relocs | |
2591 | { | |
2592 | struct ppc_dyn_relocs *next; | |
2593 | ||
2594 | /* The input section of the reloc. */ | |
2595 | asection *sec; | |
2596 | ||
2597 | /* Total number of relocs copied for the input section. */ | |
2598 | bfd_size_type count; | |
2599 | ||
2600 | /* Number of pc-relative relocs copied for the input section. */ | |
2601 | bfd_size_type pc_count; | |
2602 | }; | |
2603 | ||
411e1bfb AM |
2604 | /* Track GOT entries needed for a given symbol. We might need more |
2605 | than one got entry per symbol. */ | |
2606 | struct got_entry | |
2607 | { | |
2608 | struct got_entry *next; | |
2609 | ||
e7b938ca | 2610 | /* The symbol addend that we'll be placing in the GOT. */ |
411e1bfb AM |
2611 | bfd_vma addend; |
2612 | ||
e717da7e AM |
2613 | /* Unlike other ELF targets, we use separate GOT entries for the same |
2614 | symbol referenced from different input files. This is to support | |
2615 | automatic multiple TOC/GOT sections, where the TOC base can vary | |
2616 | from one input file to another. | |
2617 | ||
2618 | Point to the BFD owning this GOT entry. */ | |
2619 | bfd *owner; | |
2620 | ||
2621 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, | |
2622 | TLS_TPREL or TLS_DTPREL for tls entries. */ | |
2623 | char tls_type; | |
2624 | ||
e7b938ca | 2625 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ |
411e1bfb AM |
2626 | union |
2627 | { | |
2628 | bfd_signed_vma refcount; | |
2629 | bfd_vma offset; | |
2630 | } got; | |
411e1bfb AM |
2631 | }; |
2632 | ||
2633 | /* The same for PLT. */ | |
2634 | struct plt_entry | |
2635 | { | |
2636 | struct plt_entry *next; | |
2637 | ||
2638 | bfd_vma addend; | |
2639 | ||
2640 | union | |
2641 | { | |
2642 | bfd_signed_vma refcount; | |
2643 | bfd_vma offset; | |
2644 | } plt; | |
2645 | }; | |
2646 | ||
65f38f15 | 2647 | /* Of those relocs that might be copied as dynamic relocs, this macro |
58ac9f71 AM |
2648 | selects those that must be copied when linking a shared library, |
2649 | even when the symbol is local. */ | |
65f38f15 | 2650 | |
411e1bfb | 2651 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
805fc799 AM |
2652 | ((RTYPE) != R_PPC64_REL32 \ |
2653 | && (RTYPE) != R_PPC64_REL64 \ | |
04c9666a | 2654 | && (RTYPE) != R_PPC64_REL30) |
65f38f15 | 2655 | |
f4656909 AM |
2656 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2657 | copying dynamic variables from a shared lib into an app's dynbss | |
2658 | section, and instead use a dynamic relocation to point into the | |
5d35169e AM |
2659 | shared lib. With code that gcc generates, it's vital that this be |
2660 | enabled; In the PowerPC64 ABI, the address of a function is actually | |
2661 | the address of a function descriptor, which resides in the .opd | |
2662 | section. gcc uses the descriptor directly rather than going via the | |
2663 | GOT as some other ABI's do, which means that initialized function | |
2664 | pointers must reference the descriptor. Thus, a function pointer | |
2665 | initialized to the address of a function in a shared library will | |
2666 | either require a copy reloc, or a dynamic reloc. Using a copy reloc | |
4cc11e76 | 2667 | redefines the function descriptor symbol to point to the copy. This |
5d35169e AM |
2668 | presents a problem as a plt entry for that function is also |
2669 | initialized from the function descriptor symbol and the copy reloc | |
2670 | may not be initialized first. */ | |
a23b6845 | 2671 | #define ELIMINATE_COPY_RELOCS 1 |
f4656909 | 2672 | |
721956f4 AM |
2673 | /* Section name for stubs is the associated section name plus this |
2674 | string. */ | |
2675 | #define STUB_SUFFIX ".stub" | |
2676 | ||
2677 | /* Linker stubs. | |
2678 | ppc_stub_long_branch: | |
2679 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
2680 | destination, but a 24 bit branch in a stub section will reach. | |
2681 | . b dest | |
2682 | ||
2683 | ppc_stub_plt_branch: | |
2684 | Similar to the above, but a 24 bit branch in the stub section won't | |
2685 | reach its destination. | |
87e226ce AM |
2686 | . addis %r12,%r2,xxx@toc@ha |
2687 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
2688 | . mtctr %r11 |
2689 | . bctr | |
2690 | ||
2691 | ppc_stub_plt_call: | |
2c66dc6c AM |
2692 | Used to call a function in a shared library. If it so happens that |
2693 | the plt entry referenced crosses a 64k boundary, then an extra | |
2694 | "addis %r12,%r12,1" will be inserted before the load at xxx+8 or | |
2695 | xxx+16 as appropriate. | |
87e226ce | 2696 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 2697 | . std %r2,40(%r1) |
87e226ce AM |
2698 | . ld %r11,xxx+0@toc@l(%r12) |
2699 | . ld %r2,xxx+8@toc@l(%r12) | |
721956f4 | 2700 | . mtctr %r11 |
87e226ce | 2701 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 | 2702 | . bctr |
ad8e1ba5 AM |
2703 | |
2704 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional | |
2705 | code to adjust the value and save r2 to support multiple toc sections. | |
2706 | A ppc_stub_long_branch with an r2 offset looks like: | |
2707 | . std %r2,40(%r1) | |
2708 | . addis %r2,%r2,off@ha | |
2709 | . addi %r2,%r2,off@l | |
2710 | . b dest | |
2711 | ||
2712 | A ppc_stub_plt_branch with an r2 offset looks like: | |
2713 | . std %r2,40(%r1) | |
2714 | . addis %r12,%r2,xxx@toc@ha | |
2715 | . ld %r11,xxx@toc@l(%r12) | |
2716 | . addis %r2,%r2,off@ha | |
2717 | . addi %r2,%r2,off@l | |
2718 | . mtctr %r11 | |
2719 | . bctr | |
721956f4 AM |
2720 | */ |
2721 | ||
2722 | enum ppc_stub_type { | |
2723 | ppc_stub_none, | |
2724 | ppc_stub_long_branch, | |
ad8e1ba5 | 2725 | ppc_stub_long_branch_r2off, |
721956f4 | 2726 | ppc_stub_plt_branch, |
ad8e1ba5 | 2727 | ppc_stub_plt_branch_r2off, |
721956f4 AM |
2728 | ppc_stub_plt_call |
2729 | }; | |
2730 | ||
2731 | struct ppc_stub_hash_entry { | |
2732 | ||
2733 | /* Base hash table entry structure. */ | |
2734 | struct bfd_hash_entry root; | |
2735 | ||
ad8e1ba5 AM |
2736 | enum ppc_stub_type stub_type; |
2737 | ||
721956f4 AM |
2738 | /* The stub section. */ |
2739 | asection *stub_sec; | |
2740 | ||
2741 | /* Offset within stub_sec of the beginning of this stub. */ | |
2742 | bfd_vma stub_offset; | |
2743 | ||
2744 | /* Given the symbol's value and its section we can determine its final | |
2745 | value when building the stubs (so the stub knows where to jump. */ | |
2746 | bfd_vma target_value; | |
2747 | asection *target_section; | |
2748 | ||
721956f4 AM |
2749 | /* The symbol table entry, if any, that this was derived from. */ |
2750 | struct ppc_link_hash_entry *h; | |
2751 | ||
411e1bfb AM |
2752 | /* And the reloc addend that this was derived from. */ |
2753 | bfd_vma addend; | |
2754 | ||
721956f4 AM |
2755 | /* Where this stub is being called from, or, in the case of combined |
2756 | stub sections, the first input section in the group. */ | |
2757 | asection *id_sec; | |
2758 | }; | |
2759 | ||
2760 | struct ppc_branch_hash_entry { | |
2761 | ||
2762 | /* Base hash table entry structure. */ | |
2763 | struct bfd_hash_entry root; | |
2764 | ||
2765 | /* Offset within .branch_lt. */ | |
2766 | unsigned int offset; | |
2767 | ||
2768 | /* Generation marker. */ | |
2769 | unsigned int iter; | |
2770 | }; | |
65f38f15 AM |
2771 | |
2772 | struct ppc_link_hash_entry | |
2773 | { | |
2774 | struct elf_link_hash_entry elf; | |
2775 | ||
721956f4 AM |
2776 | /* A pointer to the most recently used stub hash entry against this |
2777 | symbol. */ | |
2778 | struct ppc_stub_hash_entry *stub_cache; | |
2779 | ||
65f38f15 AM |
2780 | /* Track dynamic relocs copied for this symbol. */ |
2781 | struct ppc_dyn_relocs *dyn_relocs; | |
e86ce104 | 2782 | |
721956f4 | 2783 | /* Link between function code and descriptor symbols. */ |
34814b9f | 2784 | struct ppc_link_hash_entry *oh; |
721956f4 | 2785 | |
e86ce104 AM |
2786 | /* Flag function code and descriptor symbols. */ |
2787 | unsigned int is_func:1; | |
2788 | unsigned int is_func_descriptor:1; | |
411e1bfb | 2789 | |
8843416a AM |
2790 | /* Whether global opd sym has been adjusted or not. |
2791 | After ppc64_elf_edit_opd has run, this flag should be set for all | |
2792 | globals defined in any opd section. */ | |
754021d0 AM |
2793 | unsigned int adjust_done:1; |
2794 | ||
99877b66 AM |
2795 | /* Set if we twiddled this symbol to weak at some stage. */ |
2796 | unsigned int was_undefined:1; | |
2797 | ||
411e1bfb | 2798 | /* Contexts in which symbol is used in the GOT (or TOC). |
e7b938ca AM |
2799 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
2800 | corresponding relocs are encountered during check_relocs. | |
2801 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2802 | indicate the corresponding GOT entry type is not needed. | |
2803 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into | |
2804 | a TPREL one. We use a separate flag rather than setting TPREL | |
2805 | just for convenience in distinguishing the two cases. */ | |
2806 | #define TLS_GD 1 /* GD reloc. */ | |
2807 | #define TLS_LD 2 /* LD reloc. */ | |
2808 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2809 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2810 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2811 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ | |
2812 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ | |
2813 | char tls_mask; | |
65f38f15 AM |
2814 | }; |
2815 | ||
2816 | /* ppc64 ELF linker hash table. */ | |
2817 | ||
2818 | struct ppc_link_hash_table | |
2819 | { | |
2820 | struct elf_link_hash_table elf; | |
2821 | ||
721956f4 AM |
2822 | /* The stub hash table. */ |
2823 | struct bfd_hash_table stub_hash_table; | |
2824 | ||
2825 | /* Another hash table for plt_branch stubs. */ | |
2826 | struct bfd_hash_table branch_hash_table; | |
2827 | ||
2828 | /* Linker stub bfd. */ | |
2829 | bfd *stub_bfd; | |
2830 | ||
2831 | /* Linker call-backs. */ | |
4ce794b7 AM |
2832 | asection * (*add_stub_section) (const char *, asection *); |
2833 | void (*layout_sections_again) (void); | |
721956f4 AM |
2834 | |
2835 | /* Array to keep track of which stub sections have been created, and | |
2836 | information on stub grouping. */ | |
2837 | struct map_stub { | |
2838 | /* This is the section to which stubs in the group will be attached. */ | |
2839 | asection *link_sec; | |
2840 | /* The stub section. */ | |
2841 | asection *stub_sec; | |
ad8e1ba5 AM |
2842 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
2843 | bfd_vma toc_off; | |
721956f4 AM |
2844 | } *stub_group; |
2845 | ||
ad8e1ba5 AM |
2846 | /* Temp used when calculating TOC pointers. */ |
2847 | bfd_vma toc_curr; | |
2848 | ||
8f3bab57 AM |
2849 | /* Highest input section id. */ |
2850 | int top_id; | |
2851 | ||
734b6cf9 AM |
2852 | /* Highest output section index. */ |
2853 | int top_index; | |
2854 | ||
2855 | /* List of input sections for each output section. */ | |
2856 | asection **input_list; | |
721956f4 | 2857 | |
65f38f15 | 2858 | /* Short-cuts to get to dynamic linker sections. */ |
4ce794b7 | 2859 | asection *got; |
4ce794b7 AM |
2860 | asection *plt; |
2861 | asection *relplt; | |
2862 | asection *dynbss; | |
2863 | asection *relbss; | |
2864 | asection *glink; | |
82bd7b59 | 2865 | asection *sfpr; |
4ce794b7 AM |
2866 | asection *brlt; |
2867 | asection *relbrlt; | |
ec338859 | 2868 | |
8387904d AM |
2869 | /* Shortcut to .__tls_get_addr and __tls_get_addr. */ |
2870 | struct ppc_link_hash_entry *tls_get_addr; | |
2871 | struct ppc_link_hash_entry *tls_get_addr_fd; | |
411e1bfb | 2872 | |
9b5ecbd0 AM |
2873 | /* Statistics. */ |
2874 | unsigned long stub_count[ppc_stub_plt_call]; | |
2875 | ||
ad8e1ba5 | 2876 | /* Set if we should emit symbols for stubs. */ |
99877b66 | 2877 | unsigned int emit_stub_syms:1; |
ad8e1ba5 | 2878 | |
5d1634d7 | 2879 | /* Set on error. */ |
99877b66 | 2880 | unsigned int stub_error:1; |
721956f4 AM |
2881 | |
2882 | /* Flag set when small branches are detected. Used to | |
2883 | select suitable defaults for the stub group size. */ | |
99877b66 AM |
2884 | unsigned int has_14bit_branch:1; |
2885 | ||
2886 | /* Temp used by ppc64_elf_check_directives. */ | |
2887 | unsigned int twiddled_syms:1; | |
721956f4 AM |
2888 | |
2889 | /* Incremented every time we size stubs. */ | |
2890 | unsigned int stub_iteration; | |
5d1634d7 | 2891 | |
ec338859 AM |
2892 | /* Small local sym to section mapping cache. */ |
2893 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
2894 | }; |
2895 | ||
2896 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ | |
2897 | ||
2898 | #define ppc_hash_table(p) \ | |
2899 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
2900 | ||
721956f4 AM |
2901 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
2902 | ((struct ppc_stub_hash_entry *) \ | |
2903 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2904 | ||
2905 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
2906 | ((struct ppc_branch_hash_entry *) \ | |
2907 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2908 | ||
2909 | /* Create an entry in the stub hash table. */ | |
2910 | ||
2911 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2912 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2913 | struct bfd_hash_table *table, | |
2914 | const char *string) | |
721956f4 AM |
2915 | { |
2916 | /* Allocate the structure if it has not already been allocated by a | |
2917 | subclass. */ | |
2918 | if (entry == NULL) | |
2919 | { | |
2920 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
2921 | if (entry == NULL) | |
2922 | return entry; | |
2923 | } | |
2924 | ||
2925 | /* Call the allocation method of the superclass. */ | |
2926 | entry = bfd_hash_newfunc (entry, table, string); | |
2927 | if (entry != NULL) | |
2928 | { | |
2929 | struct ppc_stub_hash_entry *eh; | |
2930 | ||
2931 | /* Initialize the local fields. */ | |
2932 | eh = (struct ppc_stub_hash_entry *) entry; | |
ad8e1ba5 | 2933 | eh->stub_type = ppc_stub_none; |
721956f4 AM |
2934 | eh->stub_sec = NULL; |
2935 | eh->stub_offset = 0; | |
2936 | eh->target_value = 0; | |
2937 | eh->target_section = NULL; | |
721956f4 AM |
2938 | eh->h = NULL; |
2939 | eh->id_sec = NULL; | |
2940 | } | |
2941 | ||
2942 | return entry; | |
2943 | } | |
2944 | ||
2945 | /* Create an entry in the branch hash table. */ | |
2946 | ||
2947 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2948 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
2949 | struct bfd_hash_table *table, | |
2950 | const char *string) | |
721956f4 AM |
2951 | { |
2952 | /* Allocate the structure if it has not already been allocated by a | |
2953 | subclass. */ | |
2954 | if (entry == NULL) | |
2955 | { | |
2956 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); | |
2957 | if (entry == NULL) | |
2958 | return entry; | |
2959 | } | |
2960 | ||
2961 | /* Call the allocation method of the superclass. */ | |
2962 | entry = bfd_hash_newfunc (entry, table, string); | |
2963 | if (entry != NULL) | |
2964 | { | |
2965 | struct ppc_branch_hash_entry *eh; | |
2966 | ||
2967 | /* Initialize the local fields. */ | |
2968 | eh = (struct ppc_branch_hash_entry *) entry; | |
2969 | eh->offset = 0; | |
2970 | eh->iter = 0; | |
2971 | } | |
2972 | ||
2973 | return entry; | |
2974 | } | |
2975 | ||
65f38f15 AM |
2976 | /* Create an entry in a ppc64 ELF linker hash table. */ |
2977 | ||
2978 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2979 | link_hash_newfunc (struct bfd_hash_entry *entry, |
2980 | struct bfd_hash_table *table, | |
2981 | const char *string) | |
65f38f15 AM |
2982 | { |
2983 | /* Allocate the structure if it has not already been allocated by a | |
2984 | subclass. */ | |
2985 | if (entry == NULL) | |
2986 | { | |
2987 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
2988 | if (entry == NULL) | |
2989 | return entry; | |
2990 | } | |
2991 | ||
2992 | /* Call the allocation method of the superclass. */ | |
2993 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2994 | if (entry != NULL) | |
2995 | { | |
2996 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
2997 | ||
721956f4 | 2998 | eh->stub_cache = NULL; |
65f38f15 | 2999 | eh->dyn_relocs = NULL; |
721956f4 | 3000 | eh->oh = NULL; |
e86ce104 AM |
3001 | eh->is_func = 0; |
3002 | eh->is_func_descriptor = 0; | |
754021d0 | 3003 | eh->adjust_done = 0; |
99877b66 | 3004 | eh->was_undefined = 0; |
e7b938ca | 3005 | eh->tls_mask = 0; |
65f38f15 AM |
3006 | } |
3007 | ||
3008 | return entry; | |
3009 | } | |
3010 | ||
3011 | /* Create a ppc64 ELF linker hash table. */ | |
3012 | ||
3013 | static struct bfd_link_hash_table * | |
4ce794b7 | 3014 | ppc64_elf_link_hash_table_create (bfd *abfd) |
65f38f15 AM |
3015 | { |
3016 | struct ppc_link_hash_table *htab; | |
3017 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
3018 | ||
4ce794b7 | 3019 | htab = bfd_zmalloc (amt); |
65f38f15 AM |
3020 | if (htab == NULL) |
3021 | return NULL; | |
3022 | ||
3023 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
3024 | { | |
e2d34d7d | 3025 | free (htab); |
65f38f15 AM |
3026 | return NULL; |
3027 | } | |
3028 | ||
721956f4 AM |
3029 | /* Init the stub hash table too. */ |
3030 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) | |
3031 | return NULL; | |
3032 | ||
3033 | /* And the branch hash table. */ | |
3034 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) | |
3035 | return NULL; | |
3036 | ||
3254fd24 AM |
3037 | /* Initializing two fields of the union is just cosmetic. We really |
3038 | only care about glist, but when compiled on a 32-bit host the | |
3039 | bfd_vma fields are larger. Setting the bfd_vma to zero makes | |
3040 | debugger inspection of these fields look nicer. */ | |
3041 | htab->elf.init_refcount.refcount = 0; | |
3042 | htab->elf.init_refcount.glist = NULL; | |
3043 | htab->elf.init_offset.offset = 0; | |
3044 | htab->elf.init_offset.glist = NULL; | |
3045 | ||
65f38f15 AM |
3046 | return &htab->elf.root; |
3047 | } | |
3048 | ||
721956f4 AM |
3049 | /* Free the derived linker hash table. */ |
3050 | ||
3051 | static void | |
4ce794b7 | 3052 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
721956f4 AM |
3053 | { |
3054 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
3055 | ||
3056 | bfd_hash_table_free (&ret->stub_hash_table); | |
3057 | bfd_hash_table_free (&ret->branch_hash_table); | |
3058 | _bfd_generic_link_hash_table_free (hash); | |
3059 | } | |
3060 | ||
e717da7e AM |
3061 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
3062 | ||
3063 | void | |
3064 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
3065 | { | |
3066 | struct ppc_link_hash_table *htab; | |
3067 | ||
3068 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; | |
3069 | ||
3070 | /* Always hook our dynamic sections into the first bfd, which is the | |
3071 | linker created stub bfd. This ensures that the GOT header is at | |
3072 | the start of the output TOC section. */ | |
3073 | htab = ppc_hash_table (info); | |
3074 | htab->stub_bfd = abfd; | |
3075 | htab->elf.dynobj = abfd; | |
3076 | } | |
3077 | ||
721956f4 AM |
3078 | /* Build a name for an entry in the stub hash table. */ |
3079 | ||
3080 | static char * | |
4ce794b7 AM |
3081 | ppc_stub_name (const asection *input_section, |
3082 | const asection *sym_sec, | |
3083 | const struct ppc_link_hash_entry *h, | |
3084 | const Elf_Internal_Rela *rel) | |
721956f4 AM |
3085 | { |
3086 | char *stub_name; | |
3087 | bfd_size_type len; | |
3088 | ||
3089 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
3090 | offsets from a sym as a branch target? In fact, we could | |
3091 | probably assume the addend is always zero. */ | |
3092 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
3093 | ||
3094 | if (h) | |
3095 | { | |
3096 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
3097 | stub_name = bfd_malloc (len); | |
3098 | if (stub_name != NULL) | |
3099 | { | |
97b639ba | 3100 | sprintf (stub_name, "%08x.%s+%x", |
721956f4 AM |
3101 | input_section->id & 0xffffffff, |
3102 | h->elf.root.root.string, | |
3103 | (int) rel->r_addend & 0xffffffff); | |
3104 | } | |
3105 | } | |
3106 | else | |
3107 | { | |
ad8e1ba5 | 3108 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
721956f4 AM |
3109 | stub_name = bfd_malloc (len); |
3110 | if (stub_name != NULL) | |
3111 | { | |
97b639ba | 3112 | sprintf (stub_name, "%08x.%x:%x+%x", |
721956f4 AM |
3113 | input_section->id & 0xffffffff, |
3114 | sym_sec->id & 0xffffffff, | |
3115 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
3116 | (int) rel->r_addend & 0xffffffff); | |
3117 | } | |
3118 | } | |
3119 | return stub_name; | |
3120 | } | |
3121 | ||
3122 | /* Look up an entry in the stub hash. Stub entries are cached because | |
3123 | creating the stub name takes a bit of time. */ | |
3124 | ||
3125 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3126 | ppc_get_stub_entry (const asection *input_section, |
3127 | const asection *sym_sec, | |
3128 | struct elf_link_hash_entry *hash, | |
3129 | const Elf_Internal_Rela *rel, | |
3130 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3131 | { |
3132 | struct ppc_stub_hash_entry *stub_entry; | |
3133 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; | |
3134 | const asection *id_sec; | |
3135 | ||
3136 | /* If this input section is part of a group of sections sharing one | |
3137 | stub section, then use the id of the first section in the group. | |
3138 | Stub names need to include a section id, as there may well be | |
3139 | more than one stub used to reach say, printf, and we need to | |
3140 | distinguish between them. */ | |
3141 | id_sec = htab->stub_group[input_section->id].link_sec; | |
3142 | ||
3143 | if (h != NULL && h->stub_cache != NULL | |
3144 | && h->stub_cache->h == h | |
3145 | && h->stub_cache->id_sec == id_sec) | |
3146 | { | |
3147 | stub_entry = h->stub_cache; | |
3148 | } | |
3149 | else | |
3150 | { | |
3151 | char *stub_name; | |
3152 | ||
3153 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
3154 | if (stub_name == NULL) | |
3155 | return NULL; | |
3156 | ||
3157 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 3158 | stub_name, FALSE, FALSE); |
721956f4 AM |
3159 | if (h != NULL) |
3160 | h->stub_cache = stub_entry; | |
3161 | ||
3162 | free (stub_name); | |
3163 | } | |
3164 | ||
3165 | return stub_entry; | |
3166 | } | |
3167 | ||
3168 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
3169 | stub entry are initialised. */ | |
3170 | ||
3171 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3172 | ppc_add_stub (const char *stub_name, |
3173 | asection *section, | |
3174 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3175 | { |
3176 | asection *link_sec; | |
3177 | asection *stub_sec; | |
3178 | struct ppc_stub_hash_entry *stub_entry; | |
3179 | ||
3180 | link_sec = htab->stub_group[section->id].link_sec; | |
3181 | stub_sec = htab->stub_group[section->id].stub_sec; | |
3182 | if (stub_sec == NULL) | |
3183 | { | |
3184 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
3185 | if (stub_sec == NULL) | |
3186 | { | |
d4c88bbb | 3187 | size_t namelen; |
721956f4 AM |
3188 | bfd_size_type len; |
3189 | char *s_name; | |
3190 | ||
d4c88bbb AM |
3191 | namelen = strlen (link_sec->name); |
3192 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
3193 | s_name = bfd_alloc (htab->stub_bfd, len); |
3194 | if (s_name == NULL) | |
3195 | return NULL; | |
3196 | ||
d4c88bbb AM |
3197 | memcpy (s_name, link_sec->name, namelen); |
3198 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
3199 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
3200 | if (stub_sec == NULL) | |
3201 | return NULL; | |
3202 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
3203 | } | |
3204 | htab->stub_group[section->id].stub_sec = stub_sec; | |
3205 | } | |
3206 | ||
3207 | /* Enter this entry into the linker stub hash table. */ | |
3208 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 3209 | TRUE, FALSE); |
721956f4 AM |
3210 | if (stub_entry == NULL) |
3211 | { | |
d003868e AM |
3212 | (*_bfd_error_handler) (_("%B: cannot create stub entry %s"), |
3213 | section->owner, stub_name); | |
721956f4 AM |
3214 | return NULL; |
3215 | } | |
3216 | ||
3217 | stub_entry->stub_sec = stub_sec; | |
3218 | stub_entry->stub_offset = 0; | |
3219 | stub_entry->id_sec = link_sec; | |
3220 | return stub_entry; | |
3221 | } | |
3222 | ||
82bd7b59 AM |
3223 | /* Create sections for linker generated code. */ |
3224 | ||
b34976b6 | 3225 | static bfd_boolean |
4ce794b7 | 3226 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
82bd7b59 AM |
3227 | { |
3228 | struct ppc_link_hash_table *htab; | |
3229 | flagword flags; | |
3230 | ||
3231 | htab = ppc_hash_table (info); | |
3232 | ||
3233 | /* Create .sfpr for code to save and restore fp regs. */ | |
3234 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
3235 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
721956f4 | 3236 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
82bd7b59 AM |
3237 | if (htab->sfpr == NULL |
3238 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) | |
3239 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) | |
b34976b6 | 3240 | return FALSE; |
82bd7b59 | 3241 | |
721956f4 | 3242 | /* Create .glink for lazy dynamic linking support. */ |
4ce794b7 AM |
3243 | htab->glink = bfd_make_section_anyway (dynobj, ".glink"); |
3244 | if (htab->glink == NULL | |
3245 | || ! bfd_set_section_flags (dynobj, htab->glink, flags) | |
3246 | || ! bfd_set_section_alignment (dynobj, htab->glink, 2)) | |
b34976b6 | 3247 | return FALSE; |
82bd7b59 | 3248 | |
721956f4 AM |
3249 | /* Create .branch_lt for plt_branch stubs. */ |
3250 | flags = (SEC_ALLOC | SEC_LOAD | |
3251 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3252 | htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt"); |
3253 | if (htab->brlt == NULL | |
3254 | || ! bfd_set_section_flags (dynobj, htab->brlt, flags) | |
3255 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) | |
b34976b6 | 3256 | return FALSE; |
721956f4 AM |
3257 | |
3258 | if (info->shared) | |
3259 | { | |
3260 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
3261 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3262 | htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
3263 | if (!htab->relbrlt | |
3264 | || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags) | |
3265 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) | |
b34976b6 | 3266 | return FALSE; |
721956f4 | 3267 | } |
b34976b6 | 3268 | return TRUE; |
82bd7b59 AM |
3269 | } |
3270 | ||
e717da7e AM |
3271 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
3272 | not already done. */ | |
65f38f15 | 3273 | |
b34976b6 | 3274 | static bfd_boolean |
e717da7e | 3275 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
65f38f15 | 3276 | { |
e717da7e AM |
3277 | asection *got, *relgot; |
3278 | flagword flags; | |
3279 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
65f38f15 | 3280 | |
4ce794b7 | 3281 | if (!htab->got) |
e717da7e AM |
3282 | { |
3283 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) | |
3284 | return FALSE; | |
3285 | ||
3286 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); | |
3287 | if (!htab->got) | |
3288 | abort (); | |
3289 | } | |
3290 | ||
3291 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3292 | | SEC_LINKER_CREATED); | |
3293 | ||
3294 | got = bfd_make_section (abfd, ".got"); | |
3295 | if (!got | |
3296 | || !bfd_set_section_flags (abfd, got, flags) | |
3297 | || !bfd_set_section_alignment (abfd, got, 3)) | |
3298 | return FALSE; | |
65f38f15 | 3299 | |
e717da7e AM |
3300 | relgot = bfd_make_section (abfd, ".rela.got"); |
3301 | if (!relgot | |
3302 | || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY) | |
3303 | || ! bfd_set_section_alignment (abfd, relgot, 3)) | |
b34976b6 | 3304 | return FALSE; |
e717da7e AM |
3305 | |
3306 | ppc64_elf_tdata (abfd)->got = got; | |
3307 | ppc64_elf_tdata (abfd)->relgot = relgot; | |
b34976b6 | 3308 | return TRUE; |
65f38f15 | 3309 | } |
5bd4f169 | 3310 | |
82bd7b59 | 3311 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 3312 | |
b34976b6 | 3313 | static bfd_boolean |
4ce794b7 | 3314 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5bd4f169 | 3315 | { |
65f38f15 | 3316 | struct ppc_link_hash_table *htab; |
5bd4f169 | 3317 | |
65f38f15 | 3318 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 3319 | return FALSE; |
65f38f15 | 3320 | |
e717da7e AM |
3321 | htab = ppc_hash_table (info); |
3322 | if (!htab->got) | |
3323 | htab->got = bfd_get_section_by_name (dynobj, ".got"); | |
4ce794b7 AM |
3324 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
3325 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3326 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
65f38f15 | 3327 | if (!info->shared) |
4ce794b7 | 3328 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
65f38f15 | 3329 | |
e717da7e | 3330 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
4ce794b7 | 3331 | || (!info->shared && !htab->relbss)) |
65f38f15 AM |
3332 | abort (); |
3333 | ||
b34976b6 | 3334 | return TRUE; |
5bd4f169 AM |
3335 | } |
3336 | ||
65f38f15 AM |
3337 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
3338 | ||
3339 | static void | |
9c5bfbb7 AM |
3340 | ppc64_elf_copy_indirect_symbol |
3341 | (const struct elf_backend_data *bed ATTRIBUTE_UNUSED, | |
3342 | struct elf_link_hash_entry *dir, | |
3343 | struct elf_link_hash_entry *ind) | |
65f38f15 AM |
3344 | { |
3345 | struct ppc_link_hash_entry *edir, *eind; | |
81848ca0 | 3346 | flagword mask; |
65f38f15 AM |
3347 | |
3348 | edir = (struct ppc_link_hash_entry *) dir; | |
3349 | eind = (struct ppc_link_hash_entry *) ind; | |
3350 | ||
411e1bfb | 3351 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
bbd7ec4a | 3352 | if (eind->dyn_relocs != NULL) |
65f38f15 | 3353 | { |
bbd7ec4a AM |
3354 | if (edir->dyn_relocs != NULL) |
3355 | { | |
3356 | struct ppc_dyn_relocs **pp; | |
3357 | struct ppc_dyn_relocs *p; | |
3358 | ||
411e1bfb | 3359 | if (eind->elf.root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
3360 | abort (); |
3361 | ||
3362 | /* Add reloc counts against the weak sym to the strong sym | |
3363 | list. Merge any entries against the same section. */ | |
3364 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3365 | { | |
3366 | struct ppc_dyn_relocs *q; | |
3367 | ||
3368 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3369 | if (q->sec == p->sec) | |
3370 | { | |
3371 | q->pc_count += p->pc_count; | |
3372 | q->count += p->count; | |
3373 | *pp = p->next; | |
3374 | break; | |
3375 | } | |
3376 | if (q == NULL) | |
3377 | pp = &p->next; | |
3378 | } | |
3379 | *pp = edir->dyn_relocs; | |
3380 | } | |
3381 | ||
65f38f15 AM |
3382 | edir->dyn_relocs = eind->dyn_relocs; |
3383 | eind->dyn_relocs = NULL; | |
3384 | } | |
65f38f15 | 3385 | |
6349e628 AM |
3386 | edir->is_func |= eind->is_func; |
3387 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
58ac9f71 | 3388 | edir->tls_mask |= eind->tls_mask; |
6349e628 | 3389 | |
81848ca0 | 3390 | mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR |
3addb0a9 DJ |
3391 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF |
3392 | | ELF_LINK_HASH_NEEDS_PLT); | |
81848ca0 AM |
3393 | /* If called to transfer flags for a weakdef during processing |
3394 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. | |
3395 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3396 | if (ELIMINATE_COPY_RELOCS | |
3397 | && eind->elf.root.type != bfd_link_hash_indirect | |
3398 | && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) | |
3399 | mask &= ~ELF_LINK_NON_GOT_REF; | |
3400 | ||
3401 | edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask; | |
6349e628 AM |
3402 | |
3403 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3404 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3405 | return; | |
3406 | ||
81848ca0 AM |
3407 | /* Copy over got entries that we may have already seen to the |
3408 | symbol which just became indirect. */ | |
411e1bfb AM |
3409 | if (eind->elf.got.glist != NULL) |
3410 | { | |
3411 | if (edir->elf.got.glist != NULL) | |
3412 | { | |
3413 | struct got_entry **entp; | |
3414 | struct got_entry *ent; | |
3415 | ||
3416 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) | |
3417 | { | |
3418 | struct got_entry *dent; | |
3419 | ||
3420 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) | |
3421 | if (dent->addend == ent->addend | |
e717da7e | 3422 | && dent->owner == ent->owner |
411e1bfb AM |
3423 | && dent->tls_type == ent->tls_type) |
3424 | { | |
3425 | dent->got.refcount += ent->got.refcount; | |
3426 | *entp = ent->next; | |
3427 | break; | |
3428 | } | |
3429 | if (dent == NULL) | |
3430 | entp = &ent->next; | |
3431 | } | |
3432 | *entp = edir->elf.got.glist; | |
3433 | } | |
3434 | ||
3435 | edir->elf.got.glist = eind->elf.got.glist; | |
3436 | eind->elf.got.glist = NULL; | |
3437 | } | |
3438 | ||
3439 | /* And plt entries. */ | |
3440 | if (eind->elf.plt.plist != NULL) | |
3441 | { | |
3442 | if (edir->elf.plt.plist != NULL) | |
3443 | { | |
3444 | struct plt_entry **entp; | |
3445 | struct plt_entry *ent; | |
3446 | ||
3447 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3448 | { | |
3449 | struct plt_entry *dent; | |
3450 | ||
3451 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3452 | if (dent->addend == ent->addend) | |
3453 | { | |
3454 | dent->plt.refcount += ent->plt.refcount; | |
3455 | *entp = ent->next; | |
3456 | break; | |
3457 | } | |
3458 | if (dent == NULL) | |
3459 | entp = &ent->next; | |
3460 | } | |
3461 | *entp = edir->elf.plt.plist; | |
3462 | } | |
3463 | ||
3464 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3465 | eind->elf.plt.plist = NULL; | |
3466 | } | |
3467 | ||
411e1bfb AM |
3468 | if (edir->elf.dynindx == -1) |
3469 | { | |
3470 | edir->elf.dynindx = eind->elf.dynindx; | |
3471 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3472 | eind->elf.dynindx = -1; | |
3473 | eind->elf.dynstr_index = 0; | |
3474 | } | |
3475 | else | |
3476 | BFD_ASSERT (eind->elf.dynindx == -1); | |
3477 | } | |
3478 | ||
8387904d AM |
3479 | /* Find the function descriptor hash entry from the given function code |
3480 | hash entry FH. Link the entries via their OH fields. */ | |
3481 | ||
3482 | static struct ppc_link_hash_entry * | |
3483 | get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) | |
3484 | { | |
3485 | struct ppc_link_hash_entry *fdh = fh->oh; | |
3486 | ||
3487 | if (fdh == NULL) | |
3488 | { | |
3489 | const char *fd_name = fh->elf.root.root.string + 1; | |
3490 | ||
3491 | fdh = (struct ppc_link_hash_entry *) | |
3492 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); | |
3493 | if (fdh != NULL) | |
3494 | { | |
3495 | fdh->is_func_descriptor = 1; | |
3496 | fdh->oh = fh; | |
3497 | fh->is_func = 1; | |
3498 | fh->oh = fdh; | |
3499 | } | |
3500 | } | |
3501 | ||
3502 | return fdh; | |
3503 | } | |
3504 | ||
3505 | /* Hacks to support old ABI code. | |
3506 | When making function calls, old ABI code references function entry | |
3507 | points (dot symbols), while new ABI code references the function | |
3508 | descriptor symbol. We need to make any combination of reference and | |
3509 | definition work together, without breaking archive linking. | |
3510 | ||
3511 | For a defined function "foo" and an undefined call to "bar": | |
3512 | An old object defines "foo" and ".foo", references ".bar" (possibly | |
3513 | "bar" too). | |
3514 | A new object defines "foo" and references "bar". | |
3515 | ||
3516 | A new object thus has no problem with its undefined symbols being | |
3517 | satisfied by definitions in an old object. On the other hand, the | |
3518 | old object won't have ".bar" satisfied by a new object. */ | |
3519 | ||
3520 | /* Fix function descriptor symbols defined in .opd sections to be | |
3521 | function type. */ | |
555cd476 AM |
3522 | |
3523 | static bfd_boolean | |
3524 | ppc64_elf_add_symbol_hook (bfd *ibfd ATTRIBUTE_UNUSED, | |
3525 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
3526 | Elf_Internal_Sym *isym, | |
3527 | const char **name ATTRIBUTE_UNUSED, | |
3528 | flagword *flags ATTRIBUTE_UNUSED, | |
3529 | asection **sec, | |
3530 | bfd_vma *value ATTRIBUTE_UNUSED) | |
3531 | { | |
8843416a AM |
3532 | if (*sec != NULL |
3533 | && strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0) | |
555cd476 AM |
3534 | isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC); |
3535 | return TRUE; | |
3536 | } | |
3537 | ||
8387904d AM |
3538 | /* This function makes an old ABI object reference to ".bar" cause the |
3539 | inclusion of a new ABI object archive that defines "bar". */ | |
3540 | ||
3541 | static struct elf_link_hash_entry * | |
3542 | ppc64_elf_archive_symbol_lookup (bfd *abfd, | |
3543 | struct bfd_link_info *info, | |
3544 | const char *name) | |
3545 | { | |
3546 | struct elf_link_hash_entry *h; | |
3547 | char *dot_name; | |
3548 | size_t len; | |
3549 | ||
3550 | h = _bfd_elf_archive_symbol_lookup (abfd, info, name); | |
3551 | if (h != NULL) | |
3552 | return h; | |
3553 | ||
3554 | if (name[0] == '.') | |
3555 | return h; | |
3556 | ||
3557 | len = strlen (name); | |
3558 | dot_name = bfd_alloc (abfd, len + 2); | |
3559 | if (dot_name == NULL) | |
3560 | return (struct elf_link_hash_entry *) 0 - 1; | |
3561 | dot_name[0] = '.'; | |
3562 | memcpy (dot_name + 1, name, len + 1); | |
3563 | h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name); | |
3564 | bfd_release (abfd, dot_name); | |
3565 | return h; | |
3566 | } | |
3567 | ||
3568 | /* This function satisfies all old ABI object references to ".bar" if a | |
99877b66 AM |
3569 | new ABI object defines "bar". Well, at least, undefined dot symbols |
3570 | are made weak. This stops later archive searches from including an | |
3571 | object if we already have a function descriptor definition. It also | |
35b0ce59 AM |
3572 | prevents the linker complaining about undefined symbols. |
3573 | We also check and correct mismatched symbol visibility here. The | |
3574 | most restrictive visibility of the function descriptor and the | |
3575 | function entry symbol is used. */ | |
8387904d AM |
3576 | |
3577 | static bfd_boolean | |
3578 | add_symbol_adjust (struct elf_link_hash_entry *h, void *inf) | |
3579 | { | |
3580 | struct bfd_link_info *info; | |
3581 | struct ppc_link_hash_table *htab; | |
99877b66 | 3582 | struct ppc_link_hash_entry *eh; |
8387904d AM |
3583 | struct ppc_link_hash_entry *fdh; |
3584 | ||
3585 | if (h->root.type == bfd_link_hash_indirect) | |
3586 | return TRUE; | |
3587 | ||
3588 | if (h->root.type == bfd_link_hash_warning) | |
3589 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3590 | ||
35b0ce59 | 3591 | if (h->root.root.string[0] != '.') |
8387904d AM |
3592 | return TRUE; |
3593 | ||
3594 | info = inf; | |
3595 | htab = ppc_hash_table (info); | |
99877b66 AM |
3596 | eh = (struct ppc_link_hash_entry *) h; |
3597 | fdh = get_fdh (eh, htab); | |
8387904d AM |
3598 | if (fdh != NULL) |
3599 | { | |
35b0ce59 AM |
3600 | unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1; |
3601 | unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1; | |
3602 | if (entry_vis < descr_vis) | |
3603 | fdh->elf.other += entry_vis - descr_vis; | |
3604 | else if (entry_vis > descr_vis) | |
3605 | eh->elf.other += descr_vis - entry_vis; | |
3606 | ||
3607 | if (eh->elf.root.type == bfd_link_hash_undefined) | |
3608 | { | |
3609 | eh->elf.root.type = bfd_link_hash_undefweak; | |
3610 | eh->was_undefined = 1; | |
3611 | htab->twiddled_syms = 1; | |
3612 | } | |
8387904d | 3613 | } |
99877b66 | 3614 | |
8387904d AM |
3615 | return TRUE; |
3616 | } | |
3617 | ||
3618 | static bfd_boolean | |
3619 | ppc64_elf_check_directives (bfd *abfd ATTRIBUTE_UNUSED, | |
3620 | struct bfd_link_info *info) | |
3621 | { | |
99877b66 | 3622 | struct ppc_link_hash_table *htab; |
35b0ce59 AM |
3623 | extern const bfd_target bfd_elf64_powerpc_vec; |
3624 | extern const bfd_target bfd_elf64_powerpcle_vec; | |
99877b66 AM |
3625 | |
3626 | htab = ppc_hash_table (info); | |
35b0ce59 AM |
3627 | if (htab->elf.root.creator != &bfd_elf64_powerpc_vec |
3628 | && htab->elf.root.creator != &bfd_elf64_powerpcle_vec) | |
3629 | return TRUE; | |
3630 | ||
8387904d | 3631 | elf_link_hash_traverse (&htab->elf, add_symbol_adjust, info); |
99877b66 AM |
3632 | |
3633 | /* We need to fix the undefs list for any syms we have twiddled to | |
3634 | undef_weak. */ | |
3635 | if (htab->twiddled_syms) | |
3636 | { | |
3637 | struct bfd_link_hash_entry **pun; | |
3638 | ||
3639 | pun = &htab->elf.root.undefs; | |
3640 | while (*pun != NULL) | |
3641 | { | |
3642 | struct bfd_link_hash_entry *h = *pun; | |
3643 | ||
3644 | if (h->type != bfd_link_hash_undefined | |
3645 | && h->type != bfd_link_hash_common) | |
3646 | { | |
3647 | *pun = h->und_next; | |
3648 | h->und_next = NULL; | |
3649 | if (h == htab->elf.root.undefs_tail) | |
3650 | { | |
3651 | if (pun == &htab->elf.root.undefs) | |
3652 | htab->elf.root.undefs_tail = NULL; | |
3653 | else | |
3654 | /* pun points at an und_next field. Go back to | |
3655 | the start of the link_hash_entry. */ | |
3656 | htab->elf.root.undefs_tail = (struct bfd_link_hash_entry *) | |
3657 | ((char *) pun - ((char *) &h->und_next - (char *) h)); | |
3658 | break; | |
3659 | } | |
3660 | } | |
3661 | else | |
3662 | pun = &h->und_next; | |
3663 | } | |
3664 | ||
3665 | htab->twiddled_syms = 0; | |
3666 | } | |
8387904d AM |
3667 | return TRUE; |
3668 | } | |
3669 | ||
411e1bfb | 3670 | static bfd_boolean |
4ce794b7 AM |
3671 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
3672 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) | |
411e1bfb AM |
3673 | { |
3674 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); | |
e7b938ca | 3675 | char *local_got_tls_masks; |
411e1bfb AM |
3676 | |
3677 | if (local_got_ents == NULL) | |
3678 | { | |
3679 | bfd_size_type size = symtab_hdr->sh_info; | |
3680 | ||
e7b938ca | 3681 | size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks); |
4ce794b7 | 3682 | local_got_ents = bfd_zalloc (abfd, size); |
411e1bfb AM |
3683 | if (local_got_ents == NULL) |
3684 | return FALSE; | |
3685 | elf_local_got_ents (abfd) = local_got_ents; | |
3686 | } | |
3687 | ||
3688 | if ((tls_type & TLS_EXPLICIT) == 0) | |
3689 | { | |
3690 | struct got_entry *ent; | |
3691 | ||
3692 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) | |
e717da7e AM |
3693 | if (ent->addend == r_addend |
3694 | && ent->owner == abfd | |
3695 | && ent->tls_type == tls_type) | |
411e1bfb AM |
3696 | break; |
3697 | if (ent == NULL) | |
3698 | { | |
3699 | bfd_size_type amt = sizeof (*ent); | |
4ce794b7 | 3700 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3701 | if (ent == NULL) |
3702 | return FALSE; | |
3703 | ent->next = local_got_ents[r_symndx]; | |
3704 | ent->addend = r_addend; | |
e717da7e | 3705 | ent->owner = abfd; |
411e1bfb AM |
3706 | ent->tls_type = tls_type; |
3707 | ent->got.refcount = 0; | |
3708 | local_got_ents[r_symndx] = ent; | |
3709 | } | |
3710 | ent->got.refcount += 1; | |
3711 | } | |
3712 | ||
e7b938ca AM |
3713 | local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
3714 | local_got_tls_masks[r_symndx] |= tls_type; | |
411e1bfb | 3715 | return TRUE; |
65f38f15 AM |
3716 | } |
3717 | ||
411e1bfb | 3718 | static bfd_boolean |
4ce794b7 | 3719 | update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend) |
1e2f5b6e | 3720 | { |
411e1bfb | 3721 | struct plt_entry *ent; |
1e2f5b6e | 3722 | |
411e1bfb AM |
3723 | for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next) |
3724 | if (ent->addend == addend) | |
3725 | break; | |
3726 | if (ent == NULL) | |
1e2f5b6e | 3727 | { |
411e1bfb | 3728 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3729 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3730 | if (ent == NULL) |
3731 | return FALSE; | |
3732 | ent->next = eh->elf.plt.plist; | |
3733 | ent->addend = addend; | |
3734 | ent->plt.refcount = 0; | |
3735 | eh->elf.plt.plist = ent; | |
1e2f5b6e | 3736 | } |
411e1bfb AM |
3737 | ent->plt.refcount += 1; |
3738 | eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3739 | eh->is_func = 1; | |
b34976b6 | 3740 | return TRUE; |
1e2f5b6e AM |
3741 | } |
3742 | ||
5bd4f169 | 3743 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 3744 | calculate needed space in the global offset table, procedure |
5d1634d7 | 3745 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 3746 | |
b34976b6 | 3747 | static bfd_boolean |
4ce794b7 AM |
3748 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
3749 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 3750 | { |
65f38f15 | 3751 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3752 | Elf_Internal_Shdr *symtab_hdr; |
3753 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
3754 | const Elf_Internal_Rela *rel; | |
3755 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 3756 | asection *sreloc; |
1e2f5b6e | 3757 | asection **opd_sym_map; |
5bd4f169 | 3758 | |
1049f94e | 3759 | if (info->relocatable) |
b34976b6 | 3760 | return TRUE; |
5bd4f169 | 3761 | |
680a3378 AM |
3762 | /* Don't do anything special with non-loaded, non-alloced sections. |
3763 | In particular, any relocs in such sections should not affect GOT | |
3764 | and PLT reference counting (ie. we don't allow them to create GOT | |
3765 | or PLT entries), there's no possibility or desire to optimize TLS | |
3766 | relocs, and there's not much point in propagating relocs to shared | |
3767 | libs that the dynamic linker won't relocate. */ | |
3768 | if ((sec->flags & SEC_ALLOC) == 0) | |
3769 | return TRUE; | |
3770 | ||
65f38f15 | 3771 | htab = ppc_hash_table (info); |
5bd4f169 | 3772 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
3773 | |
3774 | sym_hashes = elf_sym_hashes (abfd); | |
3775 | sym_hashes_end = (sym_hashes | |
1e2f5b6e AM |
3776 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
3777 | - symtab_hdr->sh_info); | |
5bd4f169 AM |
3778 | |
3779 | sreloc = NULL; | |
1e2f5b6e AM |
3780 | opd_sym_map = NULL; |
3781 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
3782 | { | |
3783 | /* Garbage collection needs some extra help with .opd sections. | |
3784 | We don't want to necessarily keep everything referenced by | |
3785 | relocs in .opd, as that would keep all functions. Instead, | |
3786 | if we reference an .opd symbol (a function descriptor), we | |
3787 | want to keep the function code symbol's section. This is | |
3788 | easy for global symbols, but for local syms we need to keep | |
3789 | information about the associated function section. Later, if | |
3790 | edit_opd deletes entries, we'll use this array to adjust | |
3791 | local syms in .opd. */ | |
3792 | union opd_info { | |
3793 | asection *func_section; | |
3794 | long entry_adjust; | |
3795 | }; | |
3796 | bfd_size_type amt; | |
3797 | ||
eea6121a | 3798 | amt = sec->size * sizeof (union opd_info) / 24; |
4ce794b7 | 3799 | opd_sym_map = bfd_zalloc (abfd, amt); |
1e2f5b6e | 3800 | if (opd_sym_map == NULL) |
b34976b6 | 3801 | return FALSE; |
f0abc2a1 | 3802 | ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map; |
1e2f5b6e | 3803 | } |
5bd4f169 | 3804 | |
82bd7b59 AM |
3805 | if (htab->sfpr == NULL |
3806 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 3807 | return FALSE; |
82bd7b59 | 3808 | |
5bd4f169 AM |
3809 | rel_end = relocs + sec->reloc_count; |
3810 | for (rel = relocs; rel < rel_end; rel++) | |
3811 | { | |
3812 | unsigned long r_symndx; | |
3813 | struct elf_link_hash_entry *h; | |
04c9666a | 3814 | enum elf_ppc64_reloc_type r_type; |
411e1bfb | 3815 | int tls_type = 0; |
5bd4f169 AM |
3816 | |
3817 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3818 | if (r_symndx < symtab_hdr->sh_info) | |
3819 | h = NULL; | |
3820 | else | |
3821 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3822 | ||
4ce794b7 | 3823 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 3824 | switch (r_type) |
5bd4f169 | 3825 | { |
411e1bfb AM |
3826 | case R_PPC64_GOT_TLSLD16: |
3827 | case R_PPC64_GOT_TLSLD16_LO: | |
3828 | case R_PPC64_GOT_TLSLD16_HI: | |
3829 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 3830 | ppc64_tlsld_got (abfd)->refcount += 1; |
951fd09b | 3831 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
3832 | goto dogottls; |
3833 | ||
3834 | case R_PPC64_GOT_TLSGD16: | |
3835 | case R_PPC64_GOT_TLSGD16_LO: | |
3836 | case R_PPC64_GOT_TLSGD16_HI: | |
3837 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 3838 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
3839 | goto dogottls; |
3840 | ||
3841 | case R_PPC64_GOT_TPREL16_DS: | |
3842 | case R_PPC64_GOT_TPREL16_LO_DS: | |
3843 | case R_PPC64_GOT_TPREL16_HI: | |
3844 | case R_PPC64_GOT_TPREL16_HA: | |
3845 | if (info->shared) | |
3846 | info->flags |= DF_STATIC_TLS; | |
3847 | tls_type = TLS_TLS | TLS_TPREL; | |
3848 | goto dogottls; | |
3849 | ||
3850 | case R_PPC64_GOT_DTPREL16_DS: | |
3851 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
3852 | case R_PPC64_GOT_DTPREL16_HI: | |
3853 | case R_PPC64_GOT_DTPREL16_HA: | |
3854 | tls_type = TLS_TLS | TLS_DTPREL; | |
3855 | dogottls: | |
3856 | sec->has_tls_reloc = 1; | |
3857 | /* Fall thru */ | |
3858 | ||
5bd4f169 | 3859 | case R_PPC64_GOT16: |
5bd4f169 | 3860 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
3861 | case R_PPC64_GOT16_HA: |
3862 | case R_PPC64_GOT16_HI: | |
3863 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 3864 | case R_PPC64_GOT16_LO_DS: |
65f38f15 | 3865 | /* This symbol requires a global offset table entry. */ |
ad8e1ba5 | 3866 | sec->has_gp_reloc = 1; |
e717da7e AM |
3867 | if (ppc64_elf_tdata (abfd)->got == NULL |
3868 | && !create_got_section (abfd, info)) | |
b34976b6 | 3869 | return FALSE; |
5bd4f169 AM |
3870 | |
3871 | if (h != NULL) | |
3872 | { | |
411e1bfb AM |
3873 | struct ppc_link_hash_entry *eh; |
3874 | struct got_entry *ent; | |
65f38f15 | 3875 | |
411e1bfb AM |
3876 | eh = (struct ppc_link_hash_entry *) h; |
3877 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) | |
3878 | if (ent->addend == rel->r_addend | |
e717da7e | 3879 | && ent->owner == abfd |
411e1bfb AM |
3880 | && ent->tls_type == tls_type) |
3881 | break; | |
3882 | if (ent == NULL) | |
5bd4f169 | 3883 | { |
411e1bfb | 3884 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3885 | ent = bfd_alloc (abfd, amt); |
411e1bfb | 3886 | if (ent == NULL) |
b34976b6 | 3887 | return FALSE; |
411e1bfb AM |
3888 | ent->next = eh->elf.got.glist; |
3889 | ent->addend = rel->r_addend; | |
e717da7e | 3890 | ent->owner = abfd; |
411e1bfb AM |
3891 | ent->tls_type = tls_type; |
3892 | ent->got.refcount = 0; | |
3893 | eh->elf.got.glist = ent; | |
5bd4f169 | 3894 | } |
411e1bfb | 3895 | ent->got.refcount += 1; |
e7b938ca | 3896 | eh->tls_mask |= tls_type; |
5bd4f169 | 3897 | } |
411e1bfb AM |
3898 | else |
3899 | /* This is a global offset table entry for a local symbol. */ | |
3900 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3901 | rel->r_addend, tls_type)) | |
3902 | return FALSE; | |
5bd4f169 AM |
3903 | break; |
3904 | ||
5bd4f169 | 3905 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
3906 | case R_PPC64_PLT16_HI: |
3907 | case R_PPC64_PLT16_LO: | |
3908 | case R_PPC64_PLT32: | |
3909 | case R_PPC64_PLT64: | |
5bd4f169 | 3910 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
3911 | actually build the entry in adjust_dynamic_symbol, |
3912 | because this might be a case of linking PIC code without | |
3913 | linking in any dynamic objects, in which case we don't | |
3914 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
3915 | if (h == NULL) |
3916 | { | |
3917 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 3918 | table entry for a local symbol. */ |
5bd4f169 | 3919 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3920 | return FALSE; |
5bd4f169 | 3921 | } |
411e1bfb AM |
3922 | else |
3923 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, | |
3924 | rel->r_addend)) | |
3925 | return FALSE; | |
5bd4f169 AM |
3926 | break; |
3927 | ||
3928 | /* The following relocations don't need to propagate the | |
3929 | relocation if linking a shared object since they are | |
3930 | section relative. */ | |
3931 | case R_PPC64_SECTOFF: | |
3932 | case R_PPC64_SECTOFF_LO: | |
3933 | case R_PPC64_SECTOFF_HI: | |
3934 | case R_PPC64_SECTOFF_HA: | |
3935 | case R_PPC64_SECTOFF_DS: | |
3936 | case R_PPC64_SECTOFF_LO_DS: | |
411e1bfb AM |
3937 | case R_PPC64_DTPREL16: |
3938 | case R_PPC64_DTPREL16_LO: | |
3939 | case R_PPC64_DTPREL16_HI: | |
3940 | case R_PPC64_DTPREL16_HA: | |
3941 | case R_PPC64_DTPREL16_DS: | |
3942 | case R_PPC64_DTPREL16_LO_DS: | |
3943 | case R_PPC64_DTPREL16_HIGHER: | |
3944 | case R_PPC64_DTPREL16_HIGHERA: | |
3945 | case R_PPC64_DTPREL16_HIGHEST: | |
3946 | case R_PPC64_DTPREL16_HIGHESTA: | |
5bd4f169 AM |
3947 | break; |
3948 | ||
ad8e1ba5 AM |
3949 | /* Nor do these. */ |
3950 | case R_PPC64_TOC16: | |
3951 | case R_PPC64_TOC16_LO: | |
3952 | case R_PPC64_TOC16_HI: | |
3953 | case R_PPC64_TOC16_HA: | |
3954 | case R_PPC64_TOC16_DS: | |
3955 | case R_PPC64_TOC16_LO_DS: | |
3956 | sec->has_gp_reloc = 1; | |
3957 | break; | |
3958 | ||
5bd4f169 AM |
3959 | /* This relocation describes the C++ object vtable hierarchy. |
3960 | Reconstruct it for later use during GC. */ | |
3961 | case R_PPC64_GNU_VTINHERIT: | |
c152c796 | 3962 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 3963 | return FALSE; |
5bd4f169 AM |
3964 | break; |
3965 | ||
3966 | /* This relocation describes which C++ vtable entries are actually | |
3967 | used. Record for later use during GC. */ | |
3968 | case R_PPC64_GNU_VTENTRY: | |
c152c796 | 3969 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 3970 | return FALSE; |
5bd4f169 AM |
3971 | break; |
3972 | ||
721956f4 AM |
3973 | case R_PPC64_REL14: |
3974 | case R_PPC64_REL14_BRTAKEN: | |
3975 | case R_PPC64_REL14_BRNTAKEN: | |
3976 | htab->has_14bit_branch = 1; | |
3977 | /* Fall through. */ | |
3978 | ||
5d1634d7 | 3979 | case R_PPC64_REL24: |
8387904d | 3980 | if (h != NULL) |
5d1634d7 AM |
3981 | { |
3982 | /* We may need a .plt entry if the function this reloc | |
3983 | refers to is in a shared lib. */ | |
411e1bfb AM |
3984 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
3985 | rel->r_addend)) | |
3986 | return FALSE; | |
8387904d AM |
3987 | if (h == &htab->tls_get_addr->elf |
3988 | || h == &htab->tls_get_addr_fd->elf) | |
411e1bfb | 3989 | sec->has_tls_reloc = 1; |
8387904d AM |
3990 | else if (htab->tls_get_addr == NULL |
3991 | && !strncmp (h->root.root.string, ".__tls_get_addr", 15) | |
a48ebf4d AM |
3992 | && (h->root.root.string[15] == 0 |
3993 | || h->root.root.string[15] == '@')) | |
411e1bfb | 3994 | { |
8387904d AM |
3995 | htab->tls_get_addr = (struct ppc_link_hash_entry *) h; |
3996 | sec->has_tls_reloc = 1; | |
3997 | } | |
3998 | else if (htab->tls_get_addr_fd == NULL | |
3999 | && !strncmp (h->root.root.string, "__tls_get_addr", 14) | |
4000 | && (h->root.root.string[14] == 0 | |
4001 | || h->root.root.string[14] == '@')) | |
4002 | { | |
4003 | htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) h; | |
411e1bfb AM |
4004 | sec->has_tls_reloc = 1; |
4005 | } | |
4006 | } | |
4007 | break; | |
4008 | ||
4009 | case R_PPC64_TPREL64: | |
4010 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | |
4011 | if (info->shared) | |
4012 | info->flags |= DF_STATIC_TLS; | |
4013 | goto dotlstoc; | |
4014 | ||
4015 | case R_PPC64_DTPMOD64: | |
4016 | if (rel + 1 < rel_end | |
4017 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
4018 | && rel[1].r_offset == rel->r_offset + 8) | |
951fd09b | 4019 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
411e1bfb | 4020 | else |
951fd09b | 4021 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
411e1bfb AM |
4022 | goto dotlstoc; |
4023 | ||
4024 | case R_PPC64_DTPREL64: | |
4025 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; | |
4026 | if (rel != relocs | |
4027 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) | |
4028 | && rel[-1].r_offset == rel->r_offset - 8) | |
4029 | /* This is the second reloc of a dtpmod, dtprel pair. | |
4030 | Don't mark with TLS_DTPREL. */ | |
4031 | goto dodyn; | |
4032 | ||
4033 | dotlstoc: | |
4034 | sec->has_tls_reloc = 1; | |
4035 | if (h != NULL) | |
4036 | { | |
4037 | struct ppc_link_hash_entry *eh; | |
4038 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 4039 | eh->tls_mask |= tls_type; |
411e1bfb AM |
4040 | } |
4041 | else | |
4042 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
4043 | rel->r_addend, tls_type)) | |
4044 | return FALSE; | |
4045 | ||
4046 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) | |
4047 | { | |
e7b938ca | 4048 | /* One extra to simplify get_tls_mask. */ |
eea6121a | 4049 | bfd_size_type amt = sec->size * sizeof (unsigned) / 8 + 1; |
4ce794b7 | 4050 | ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt); |
411e1bfb AM |
4051 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
4052 | return FALSE; | |
4053 | } | |
4054 | BFD_ASSERT (rel->r_offset % 8 == 0); | |
4055 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx; | |
951fd09b AM |
4056 | |
4057 | /* Mark the second slot of a GD or LD entry. | |
4058 | -1 to indicate GD and -2 to indicate LD. */ | |
4059 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | |
4060 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1; | |
4061 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) | |
4062 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2; | |
411e1bfb AM |
4063 | goto dodyn; |
4064 | ||
4065 | case R_PPC64_TPREL16: | |
4066 | case R_PPC64_TPREL16_LO: | |
4067 | case R_PPC64_TPREL16_HI: | |
4068 | case R_PPC64_TPREL16_HA: | |
4069 | case R_PPC64_TPREL16_DS: | |
4070 | case R_PPC64_TPREL16_LO_DS: | |
4071 | case R_PPC64_TPREL16_HIGHER: | |
4072 | case R_PPC64_TPREL16_HIGHERA: | |
4073 | case R_PPC64_TPREL16_HIGHEST: | |
4074 | case R_PPC64_TPREL16_HIGHESTA: | |
4075 | if (info->shared) | |
4076 | { | |
4077 | info->flags |= DF_STATIC_TLS; | |
4078 | goto dodyn; | |
5d1634d7 AM |
4079 | } |
4080 | break; | |
4081 | ||
e86ce104 | 4082 | case R_PPC64_ADDR64: |
1e2f5b6e | 4083 | if (opd_sym_map != NULL |
1e2f5b6e | 4084 | && rel + 1 < rel_end |
4ce794b7 | 4085 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
1e2f5b6e | 4086 | { |
8387904d AM |
4087 | if (h != NULL) |
4088 | { | |
4089 | if (h->root.root.string[0] == '.' | |
4090 | && h->root.root.string[1] != 0 | |
4091 | && get_fdh ((struct ppc_link_hash_entry *) h, htab)) | |
4092 | ; | |
4093 | else | |
4094 | ((struct ppc_link_hash_entry *) h)->is_func = 1; | |
4095 | } | |
4096 | else | |
4097 | { | |
4098 | asection *s; | |
1e2f5b6e | 4099 | |
8387904d AM |
4100 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, |
4101 | r_symndx); | |
4102 | if (s == NULL) | |
4103 | return FALSE; | |
4104 | else if (s != sec) | |
4105 | opd_sym_map[rel->r_offset / 24] = s; | |
4106 | } | |
1e2f5b6e | 4107 | } |
e86ce104 AM |
4108 | /* Fall through. */ |
4109 | ||
04c9666a | 4110 | case R_PPC64_REL30: |
5bd4f169 | 4111 | case R_PPC64_REL32: |
04c9666a | 4112 | case R_PPC64_REL64: |
65f38f15 AM |
4113 | case R_PPC64_ADDR14: |
4114 | case R_PPC64_ADDR14_BRNTAKEN: | |
4115 | case R_PPC64_ADDR14_BRTAKEN: | |
4116 | case R_PPC64_ADDR16: | |
4117 | case R_PPC64_ADDR16_DS: | |
4118 | case R_PPC64_ADDR16_HA: | |
4119 | case R_PPC64_ADDR16_HI: | |
4120 | case R_PPC64_ADDR16_HIGHER: | |
4121 | case R_PPC64_ADDR16_HIGHERA: | |
4122 | case R_PPC64_ADDR16_HIGHEST: | |
4123 | case R_PPC64_ADDR16_HIGHESTA: | |
4124 | case R_PPC64_ADDR16_LO: | |
4125 | case R_PPC64_ADDR16_LO_DS: | |
4126 | case R_PPC64_ADDR24: | |
65f38f15 | 4127 | case R_PPC64_ADDR32: |
65f38f15 AM |
4128 | case R_PPC64_UADDR16: |
4129 | case R_PPC64_UADDR32: | |
4130 | case R_PPC64_UADDR64: | |
5bd4f169 | 4131 | case R_PPC64_TOC: |
81848ca0 AM |
4132 | if (h != NULL && !info->shared) |
4133 | /* We may need a copy reloc. */ | |
4134 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
4135 | ||
41bd81ab | 4136 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 4137 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 4138 | break; |
e86ce104 | 4139 | |
65f38f15 AM |
4140 | /* If we are creating a shared library, and this is a reloc |
4141 | against a global symbol, or a non PC relative reloc | |
4142 | against a local symbol, then we need to copy the reloc | |
4143 | into the shared library. However, if we are linking with | |
4144 | -Bsymbolic, we do not need to copy a reloc against a | |
4145 | global symbol which is defined in an object we are | |
4146 | including in the link (i.e., DEF_REGULAR is set). At | |
4147 | this point we have not seen all the input files, so it is | |
4148 | possible that DEF_REGULAR is not set now but will be set | |
4149 | later (it is never cleared). In case of a weak definition, | |
4150 | DEF_REGULAR may be cleared later by a strong definition in | |
4151 | a shared library. We account for that possibility below by | |
f4656909 | 4152 | storing information in the dyn_relocs field of the hash |
65f38f15 AM |
4153 | table entry. A similar situation occurs when creating |
4154 | shared libraries and symbol visibility changes render the | |
4155 | symbol local. | |
4156 | ||
4157 | If on the other hand, we are creating an executable, we | |
4158 | may need to keep relocations for symbols satisfied by a | |
4159 | dynamic library if we manage to avoid copy relocs for the | |
4160 | symbol. */ | |
411e1bfb | 4161 | dodyn: |
65f38f15 | 4162 | if ((info->shared |
411e1bfb | 4163 | && (MUST_BE_DYN_RELOC (r_type) |
65f38f15 AM |
4164 | || (h != NULL |
4165 | && (! info->symbolic | |
4166 | || h->root.type == bfd_link_hash_defweak | |
4167 | || (h->elf_link_hash_flags | |
4168 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
f4656909 AM |
4169 | || (ELIMINATE_COPY_RELOCS |
4170 | && !info->shared | |
65f38f15 AM |
4171 | && h != NULL |
4172 | && (h->root.type == bfd_link_hash_defweak | |
4173 | || (h->elf_link_hash_flags | |
4174 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 4175 | { |
ec338859 AM |
4176 | struct ppc_dyn_relocs *p; |
4177 | struct ppc_dyn_relocs **head; | |
4178 | ||
65f38f15 AM |
4179 | /* We must copy these reloc types into the output file. |
4180 | Create a reloc section in dynobj and make room for | |
4181 | this reloc. */ | |
5bd4f169 AM |
4182 | if (sreloc == NULL) |
4183 | { | |
4184 | const char *name; | |
65f38f15 | 4185 | bfd *dynobj; |
5bd4f169 AM |
4186 | |
4187 | name = (bfd_elf_string_from_elf_section | |
4188 | (abfd, | |
4189 | elf_elfheader (abfd)->e_shstrndx, | |
4190 | elf_section_data (sec)->rel_hdr.sh_name)); | |
4191 | if (name == NULL) | |
b34976b6 | 4192 | return FALSE; |
5bd4f169 | 4193 | |
65f38f15 AM |
4194 | if (strncmp (name, ".rela", 5) != 0 |
4195 | || strcmp (bfd_get_section_name (abfd, sec), | |
4196 | name + 5) != 0) | |
4197 | { | |
4198 | (*_bfd_error_handler) | |
d003868e AM |
4199 | (_("%B: bad relocation section name `%s\'"), |
4200 | abfd, name); | |
5d1634d7 | 4201 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
4202 | } |
4203 | ||
65f38f15 | 4204 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
4205 | sreloc = bfd_get_section_by_name (dynobj, name); |
4206 | if (sreloc == NULL) | |
4207 | { | |
4208 | flagword flags; | |
4209 | ||
4210 | sreloc = bfd_make_section (dynobj, name); | |
4211 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
4212 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4213 | if ((sec->flags & SEC_ALLOC) != 0) | |
4214 | flags |= SEC_ALLOC | SEC_LOAD; | |
4215 | if (sreloc == NULL | |
4216 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 4217 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
b34976b6 | 4218 | return FALSE; |
5bd4f169 | 4219 | } |
65f38f15 | 4220 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
4221 | } |
4222 | ||
65f38f15 AM |
4223 | /* If this is a global symbol, we count the number of |
4224 | relocations we need for this symbol. */ | |
4225 | if (h != NULL) | |
4226 | { | |
ec338859 | 4227 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
4228 | } |
4229 | else | |
4230 | { | |
ec338859 AM |
4231 | /* Track dynamic relocs needed for local syms too. |
4232 | We really need local syms available to do this | |
4233 | easily. Oh well. */ | |
4234 | ||
4235 | asection *s; | |
4236 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
4237 | sec, r_symndx); | |
4238 | if (s == NULL) | |
b34976b6 | 4239 | return FALSE; |
ec338859 AM |
4240 | |
4241 | head = ((struct ppc_dyn_relocs **) | |
4242 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 4243 | } |
ec338859 AM |
4244 | |
4245 | p = *head; | |
4246 | if (p == NULL || p->sec != sec) | |
4247 | { | |
4ce794b7 | 4248 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
ec338859 | 4249 | if (p == NULL) |
b34976b6 | 4250 | return FALSE; |
ec338859 AM |
4251 | p->next = *head; |
4252 | *head = p; | |
4253 | p->sec = sec; | |
4254 | p->count = 0; | |
4255 | p->pc_count = 0; | |
4256 | } | |
4257 | ||
4258 | p->count += 1; | |
411e1bfb | 4259 | if (!MUST_BE_DYN_RELOC (r_type)) |
ec338859 | 4260 | p->pc_count += 1; |
65f38f15 | 4261 | } |
5bd4f169 | 4262 | break; |
65f38f15 AM |
4263 | |
4264 | default: | |
96e0dda4 | 4265 | break; |
5bd4f169 AM |
4266 | } |
4267 | } | |
4268 | ||
b34976b6 | 4269 | return TRUE; |
5bd4f169 AM |
4270 | } |
4271 | ||
8387904d AM |
4272 | /* OFFSET in OPD_SEC specifies a function descriptor. Return the address |
4273 | of the code entry point, and its section. */ | |
4274 | ||
4275 | static bfd_vma | |
4276 | opd_entry_value (asection *opd_sec, | |
4277 | bfd_vma offset, | |
4278 | asection **code_sec, | |
4279 | bfd_vma *code_off) | |
4280 | { | |
4281 | bfd *opd_bfd = opd_sec->owner; | |
4282 | Elf_Internal_Rela *lo, *hi, *look; | |
4283 | ||
4284 | /* Go find the opd reloc at the sym address. */ | |
4285 | lo = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE); | |
4286 | BFD_ASSERT (lo != NULL); | |
4287 | hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */ | |
4288 | ||
4289 | while (lo < hi) | |
4290 | { | |
4291 | look = lo + (hi - lo) / 2; | |
4292 | if (look->r_offset < offset) | |
4293 | lo = look + 1; | |
4294 | else if (look->r_offset > offset) | |
4295 | hi = look; | |
4296 | else | |
4297 | { | |
4298 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (opd_bfd)->symtab_hdr; | |
4299 | if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64 | |
4300 | && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC) | |
4301 | { | |
4302 | unsigned long symndx = ELF64_R_SYM (look->r_info); | |
4303 | bfd_vma val; | |
4304 | asection *sec; | |
4305 | ||
4306 | if (symndx < symtab_hdr->sh_info) | |
4307 | { | |
4308 | Elf_Internal_Sym *sym; | |
4309 | ||
4310 | sym = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4311 | if (sym == NULL) | |
4312 | { | |
4313 | sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, | |
4314 | symtab_hdr->sh_info, | |
4315 | 0, NULL, NULL, NULL); | |
4316 | if (sym == NULL) | |
4317 | return (bfd_vma) -1; | |
4318 | symtab_hdr->contents = (bfd_byte *) sym; | |
4319 | } | |
4320 | ||
4321 | sym += symndx; | |
4322 | val = sym->st_value; | |
4323 | sec = NULL; | |
4324 | if ((sym->st_shndx != SHN_UNDEF | |
4325 | && sym->st_shndx < SHN_LORESERVE) | |
4326 | || sym->st_shndx > SHN_HIRESERVE) | |
4327 | sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx); | |
4328 | BFD_ASSERT ((sec->flags & SEC_MERGE) == 0); | |
4329 | } | |
4330 | else | |
4331 | { | |
4332 | struct elf_link_hash_entry **sym_hashes; | |
4333 | struct elf_link_hash_entry *rh; | |
4334 | ||
4335 | sym_hashes = elf_sym_hashes (opd_bfd); | |
4336 | rh = sym_hashes[symndx - symtab_hdr->sh_info]; | |
4337 | while (rh->root.type == bfd_link_hash_indirect | |
4338 | || rh->root.type == bfd_link_hash_warning) | |
4339 | rh = ((struct elf_link_hash_entry *) rh->root.u.i.link); | |
4340 | BFD_ASSERT (rh->root.type == bfd_link_hash_defined | |
4341 | || rh->root.type == bfd_link_hash_defweak); | |
4342 | val = rh->root.u.def.value; | |
4343 | sec = rh->root.u.def.section; | |
4344 | } | |
4345 | val += look->r_addend; | |
4346 | if (code_off != NULL) | |
4347 | *code_off = val; | |
4348 | if (code_sec != NULL) | |
4349 | *code_sec = sec; | |
4350 | if (sec != NULL && sec->output_section != NULL) | |
4351 | val += sec->output_section->vma + sec->output_offset; | |
4352 | return val; | |
4353 | } | |
4354 | break; | |
4355 | } | |
4356 | } | |
4357 | return (bfd_vma) -1; | |
4358 | } | |
4359 | ||
5bd4f169 AM |
4360 | /* Return the section that should be marked against GC for a given |
4361 | relocation. */ | |
4362 | ||
4363 | static asection * | |
4ce794b7 | 4364 | ppc64_elf_gc_mark_hook (asection *sec, |
ccfa59ea | 4365 | struct bfd_link_info *info, |
4ce794b7 AM |
4366 | Elf_Internal_Rela *rel, |
4367 | struct elf_link_hash_entry *h, | |
4368 | Elf_Internal_Sym *sym) | |
5bd4f169 | 4369 | { |
ccfa59ea AM |
4370 | asection *rsec; |
4371 | ||
4372 | /* First mark all our entry sym sections. */ | |
4373 | if (info->gc_sym_list != NULL) | |
4374 | { | |
4375 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
4376 | struct bfd_sym_chain *sym = info->gc_sym_list; | |
4377 | ||
4378 | info->gc_sym_list = NULL; | |
4379 | do | |
4380 | { | |
4381 | struct ppc_link_hash_entry *eh; | |
4382 | ||
4383 | eh = (struct ppc_link_hash_entry *) | |
4384 | elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); | |
4385 | if (eh == NULL) | |
4386 | continue; | |
4387 | if (eh->elf.root.type != bfd_link_hash_defined | |
4388 | && eh->elf.root.type != bfd_link_hash_defweak) | |
4389 | continue; | |
4390 | ||
4391 | if (eh->is_func_descriptor) | |
4392 | rsec = eh->oh->elf.root.u.def.section; | |
8387904d AM |
4393 | else if (get_opd_info (eh->elf.root.u.def.section) != NULL |
4394 | && opd_entry_value (eh->elf.root.u.def.section, | |
4395 | eh->elf.root.u.def.value, | |
4396 | &rsec, NULL) != (bfd_vma) -1) | |
4397 | ; | |
ccfa59ea AM |
4398 | else |
4399 | continue; | |
4400 | ||
4401 | if (!rsec->gc_mark) | |
4402 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); | |
4403 | ||
4404 | rsec = eh->elf.root.u.def.section; | |
4405 | if (!rsec->gc_mark) | |
4406 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); | |
4407 | ||
4408 | sym = sym->next; | |
4409 | } | |
4410 | while (sym != NULL); | |
4411 | } | |
4412 | ||
4413 | /* Syms return NULL if we're marking .opd, so we avoid marking all | |
4414 | function sections, as all functions are referenced in .opd. */ | |
4415 | rsec = NULL; | |
4416 | if (get_opd_info (sec) != NULL) | |
4417 | return rsec; | |
1e2f5b6e | 4418 | |
5bd4f169 AM |
4419 | if (h != NULL) |
4420 | { | |
04c9666a | 4421 | enum elf_ppc64_reloc_type r_type; |
ccfa59ea | 4422 | struct ppc_link_hash_entry *eh; |
a33d1f77 | 4423 | |
4ce794b7 | 4424 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 4425 | switch (r_type) |
5bd4f169 AM |
4426 | { |
4427 | case R_PPC64_GNU_VTINHERIT: | |
4428 | case R_PPC64_GNU_VTENTRY: | |
4429 | break; | |
4430 | ||
4431 | default: | |
4432 | switch (h->root.type) | |
4433 | { | |
4434 | case bfd_link_hash_defined: | |
4435 | case bfd_link_hash_defweak: | |
ccfa59ea AM |
4436 | eh = (struct ppc_link_hash_entry *) h; |
4437 | if (eh->oh != NULL && eh->oh->is_func_descriptor) | |
4438 | eh = eh->oh; | |
1e2f5b6e AM |
4439 | |
4440 | /* Function descriptor syms cause the associated | |
4441 | function code sym section to be marked. */ | |
ccfa59ea AM |
4442 | if (eh->is_func_descriptor) |
4443 | { | |
4444 | /* They also mark their opd section. */ | |
4445 | if (!eh->elf.root.u.def.section->gc_mark) | |
4446 | _bfd_elf_gc_mark (info, eh->elf.root.u.def.section, | |
4447 | ppc64_elf_gc_mark_hook); | |
4448 | ||
4449 | rsec = eh->oh->elf.root.u.def.section; | |
4450 | } | |
8387904d AM |
4451 | else if (get_opd_info (eh->elf.root.u.def.section) != NULL |
4452 | && opd_entry_value (eh->elf.root.u.def.section, | |
4453 | eh->elf.root.u.def.value, | |
4454 | &rsec, NULL) != (bfd_vma) -1) | |
4455 | { | |
4456 | if (!eh->elf.root.u.def.section->gc_mark) | |
4457 | _bfd_elf_gc_mark (info, eh->elf.root.u.def.section, | |
4458 | ppc64_elf_gc_mark_hook); | |
4459 | } | |
ccfa59ea | 4460 | else |
1e2f5b6e AM |
4461 | rsec = h->root.u.def.section; |
4462 | break; | |
5bd4f169 AM |
4463 | |
4464 | case bfd_link_hash_common: | |
1e2f5b6e AM |
4465 | rsec = h->root.u.c.p->section; |
4466 | break; | |
5bd4f169 AM |
4467 | |
4468 | default: | |
4469 | break; | |
4470 | } | |
4471 | } | |
4472 | } | |
4473 | else | |
4474 | { | |
1e2f5b6e AM |
4475 | asection **opd_sym_section; |
4476 | ||
4477 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
ccfa59ea | 4478 | opd_sym_section = get_opd_info (rsec); |
1e2f5b6e | 4479 | if (opd_sym_section != NULL) |
ccfa59ea AM |
4480 | { |
4481 | if (!rsec->gc_mark) | |
4482 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); | |
4483 | ||
4484 | rsec = opd_sym_section[sym->st_value / 24]; | |
4485 | } | |
5bd4f169 AM |
4486 | } |
4487 | ||
1e2f5b6e | 4488 | return rsec; |
5bd4f169 AM |
4489 | } |
4490 | ||
65f38f15 AM |
4491 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
4492 | section being removed. */ | |
5bd4f169 | 4493 | |
b34976b6 | 4494 | static bfd_boolean |
4ce794b7 AM |
4495 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
4496 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 4497 | { |
411e1bfb | 4498 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
4499 | Elf_Internal_Shdr *symtab_hdr; |
4500 | struct elf_link_hash_entry **sym_hashes; | |
411e1bfb | 4501 | struct got_entry **local_got_ents; |
5bd4f169 | 4502 | const Elf_Internal_Rela *rel, *relend; |
5bd4f169 | 4503 | |
680a3378 AM |
4504 | if ((sec->flags & SEC_ALLOC) == 0) |
4505 | return TRUE; | |
4506 | ||
ec338859 AM |
4507 | elf_section_data (sec)->local_dynrel = NULL; |
4508 | ||
411e1bfb | 4509 | htab = ppc_hash_table (info); |
5bd4f169 AM |
4510 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4511 | sym_hashes = elf_sym_hashes (abfd); | |
411e1bfb | 4512 | local_got_ents = elf_local_got_ents (abfd); |
5bd4f169 AM |
4513 | |
4514 | relend = relocs + sec->reloc_count; | |
4515 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
4516 | { |
4517 | unsigned long r_symndx; | |
04c9666a | 4518 | enum elf_ppc64_reloc_type r_type; |
58ac9f71 | 4519 | struct elf_link_hash_entry *h = NULL; |
411e1bfb | 4520 | char tls_type = 0; |
5bd4f169 | 4521 | |
a33d1f77 | 4522 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 | 4523 | r_type = ELF64_R_TYPE (rel->r_info); |
58ac9f71 AM |
4524 | if (r_symndx >= symtab_hdr->sh_info) |
4525 | { | |
4526 | struct ppc_link_hash_entry *eh; | |
4527 | struct ppc_dyn_relocs **pp; | |
4528 | struct ppc_dyn_relocs *p; | |
4529 | ||
4530 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4531 | eh = (struct ppc_link_hash_entry *) h; | |
4532 | ||
4533 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4534 | if (p->sec == sec) | |
4535 | { | |
4536 | /* Everything must go for SEC. */ | |
4537 | *pp = p->next; | |
4538 | break; | |
4539 | } | |
4540 | } | |
4541 | ||
a33d1f77 AM |
4542 | switch (r_type) |
4543 | { | |
411e1bfb AM |
4544 | case R_PPC64_GOT_TLSLD16: |
4545 | case R_PPC64_GOT_TLSLD16_LO: | |
4546 | case R_PPC64_GOT_TLSLD16_HI: | |
4547 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 4548 | ppc64_tlsld_got (abfd)->refcount -= 1; |
951fd09b | 4549 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
4550 | goto dogot; |
4551 | ||
4552 | case R_PPC64_GOT_TLSGD16: | |
4553 | case R_PPC64_GOT_TLSGD16_LO: | |
4554 | case R_PPC64_GOT_TLSGD16_HI: | |
4555 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 4556 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
4557 | goto dogot; |
4558 | ||
4559 | case R_PPC64_GOT_TPREL16_DS: | |
4560 | case R_PPC64_GOT_TPREL16_LO_DS: | |
4561 | case R_PPC64_GOT_TPREL16_HI: | |
4562 | case R_PPC64_GOT_TPREL16_HA: | |
4563 | tls_type = TLS_TLS | TLS_TPREL; | |
4564 | goto dogot; | |
4565 | ||
4566 | case R_PPC64_GOT_DTPREL16_DS: | |
4567 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
4568 | case R_PPC64_GOT_DTPREL16_HI: | |
4569 | case R_PPC64_GOT_DTPREL16_HA: | |
4570 | tls_type = TLS_TLS | TLS_DTPREL; | |
4571 | goto dogot; | |
4572 | ||
a33d1f77 AM |
4573 | case R_PPC64_GOT16: |
4574 | case R_PPC64_GOT16_DS: | |
4575 | case R_PPC64_GOT16_HA: | |
4576 | case R_PPC64_GOT16_HI: | |
4577 | case R_PPC64_GOT16_LO: | |
4578 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb AM |
4579 | dogot: |
4580 | { | |
4581 | struct got_entry *ent; | |
4582 | ||
58ac9f71 AM |
4583 | if (h != NULL) |
4584 | ent = h->got.glist; | |
411e1bfb AM |
4585 | else |
4586 | ent = local_got_ents[r_symndx]; | |
4587 | ||
4588 | for (; ent != NULL; ent = ent->next) | |
4589 | if (ent->addend == rel->r_addend | |
e717da7e | 4590 | && ent->owner == abfd |
411e1bfb AM |
4591 | && ent->tls_type == tls_type) |
4592 | break; | |
4593 | if (ent == NULL) | |
4594 | abort (); | |
4595 | if (ent->got.refcount > 0) | |
4596 | ent->got.refcount -= 1; | |
4597 | } | |
a33d1f77 | 4598 | break; |
65f38f15 | 4599 | |
a33d1f77 AM |
4600 | case R_PPC64_PLT16_HA: |
4601 | case R_PPC64_PLT16_HI: | |
4602 | case R_PPC64_PLT16_LO: | |
4603 | case R_PPC64_PLT32: | |
4604 | case R_PPC64_PLT64: | |
721956f4 AM |
4605 | case R_PPC64_REL14: |
4606 | case R_PPC64_REL14_BRNTAKEN: | |
4607 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 | 4608 | case R_PPC64_REL24: |
58ac9f71 | 4609 | if (h != NULL) |
5d1634d7 | 4610 | { |
411e1bfb AM |
4611 | struct plt_entry *ent; |
4612 | ||
411e1bfb AM |
4613 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
4614 | if (ent->addend == rel->r_addend) | |
4615 | break; | |
4616 | if (ent == NULL) | |
4617 | abort (); | |
4618 | if (ent->plt.refcount > 0) | |
4619 | ent->plt.refcount -= 1; | |
5d1634d7 | 4620 | } |
e86ce104 | 4621 | break; |
5d1634d7 | 4622 | |
a33d1f77 AM |
4623 | default: |
4624 | break; | |
4625 | } | |
4626 | } | |
b34976b6 | 4627 | return TRUE; |
5bd4f169 AM |
4628 | } |
4629 | ||
e86ce104 AM |
4630 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
4631 | information on function code symbol entries to their corresponding | |
4632 | function descriptor symbol entries. */ | |
b34976b6 | 4633 | static bfd_boolean |
4ce794b7 | 4634 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 4635 | { |
e86ce104 | 4636 | struct bfd_link_info *info; |
65f38f15 | 4637 | struct ppc_link_hash_table *htab; |
411e1bfb | 4638 | struct plt_entry *ent; |
50bc7936 AM |
4639 | struct ppc_link_hash_entry *fh; |
4640 | struct ppc_link_hash_entry *fdh; | |
4641 | bfd_boolean force_local; | |
5bd4f169 | 4642 | |
50bc7936 AM |
4643 | fh = (struct ppc_link_hash_entry *) h; |
4644 | if (fh->elf.root.type == bfd_link_hash_indirect) | |
b34976b6 | 4645 | return TRUE; |
e86ce104 | 4646 | |
50bc7936 AM |
4647 | if (fh->elf.root.type == bfd_link_hash_warning) |
4648 | fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link; | |
e92d460e | 4649 | |
4ce794b7 | 4650 | info = inf; |
65f38f15 | 4651 | htab = ppc_hash_table (info); |
5bd4f169 | 4652 | |
e86ce104 AM |
4653 | /* If this is a function code symbol, transfer dynamic linking |
4654 | information to the function descriptor symbol. */ | |
50bc7936 | 4655 | if (!fh->is_func) |
b34976b6 | 4656 | return TRUE; |
e86ce104 | 4657 | |
50bc7936 | 4658 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
4659 | if (ent->plt.refcount > 0) |
4660 | break; | |
50bc7936 AM |
4661 | if (ent == NULL |
4662 | || fh->elf.root.root.string[0] != '.' | |
4663 | || fh->elf.root.root.string[1] == '\0') | |
4664 | return TRUE; | |
5bd4f169 | 4665 | |
50bc7936 AM |
4666 | /* Find the corresponding function descriptor symbol. Create it |
4667 | as undefined if necessary. */ | |
5bd4f169 | 4668 | |
50bc7936 AM |
4669 | fdh = get_fdh (fh, htab); |
4670 | if (fdh != NULL) | |
4671 | while (fdh->elf.root.type == bfd_link_hash_indirect | |
4672 | || fdh->elf.root.type == bfd_link_hash_warning) | |
4673 | fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link; | |
5bd4f169 | 4674 | |
50bc7936 AM |
4675 | if (fdh == NULL |
4676 | && info->shared | |
4677 | && (fh->elf.root.type == bfd_link_hash_undefined | |
4678 | || fh->elf.root.type == bfd_link_hash_undefweak)) | |
4679 | { | |
4680 | bfd *abfd; | |
4681 | asymbol *newsym; | |
4682 | struct bfd_link_hash_entry *bh; | |
4683 | ||
4684 | abfd = fh->elf.root.u.undef.abfd; | |
4685 | newsym = bfd_make_empty_symbol (abfd); | |
4686 | newsym->name = fh->elf.root.root.string + 1; | |
4687 | newsym->section = bfd_und_section_ptr; | |
4688 | newsym->value = 0; | |
4689 | newsym->flags = BSF_OBJECT; | |
4690 | if (fh->elf.root.type == bfd_link_hash_undefweak) | |
4691 | newsym->flags |= BSF_WEAK; | |
4692 | ||
4693 | bh = &fdh->elf.root; | |
4694 | if ( !(_bfd_generic_link_add_one_symbol | |
4695 | (info, abfd, newsym->name, newsym->flags, | |
4696 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) | |
648cca2c | 4697 | { |
50bc7936 | 4698 | return FALSE; |
648cca2c | 4699 | } |
50bc7936 AM |
4700 | fdh = (struct ppc_link_hash_entry *) bh; |
4701 | fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF; | |
4702 | fdh->elf.size = 24; | |
4703 | fdh->elf.type = STT_OBJECT; | |
4704 | } | |
648cca2c | 4705 | |
50bc7936 AM |
4706 | if (fdh != NULL |
4707 | && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 | |
4708 | && (info->shared | |
4709 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4710 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 | |
4711 | || (fdh->elf.root.type == bfd_link_hash_undefweak | |
4712 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) | |
4713 | { | |
4714 | if (fdh->elf.dynindx == -1) | |
c152c796 | 4715 | if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf)) |
50bc7936 AM |
4716 | return FALSE; |
4717 | fdh->elf.elf_link_hash_flags | |
4718 | |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
4719 | | ELF_LINK_HASH_REF_DYNAMIC | |
4720 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
4721 | | ELF_LINK_NON_GOT_REF)); | |
4722 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) | |
e86ce104 | 4723 | { |
8387904d AM |
4724 | struct plt_entry **ep = &fdh->elf.plt.plist; |
4725 | while (*ep != NULL) | |
4726 | ep = &(*ep)->next; | |
4727 | *ep = fh->elf.plt.plist; | |
4728 | fh->elf.plt.plist = NULL; | |
50bc7936 | 4729 | fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
e86ce104 | 4730 | } |
50bc7936 | 4731 | fdh->is_func_descriptor = 1; |
34814b9f AM |
4732 | fdh->oh = fh; |
4733 | fh->oh = fdh; | |
e86ce104 AM |
4734 | } |
4735 | ||
50bc7936 AM |
4736 | /* Now that the info is on the function descriptor, clear the |
4737 | function code sym info. Any function code syms for which we | |
4738 | don't have a definition in a regular file, we force local. | |
4739 | This prevents a shared library from exporting syms that have | |
4740 | been imported from another library. Function code syms that | |
4741 | are really in the library we must leave global to prevent the | |
4742 | linker dragging in a definition from a static library. */ | |
4743 | force_local | |
4744 | = (info->shared | |
4745 | && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4746 | || fdh == NULL | |
4747 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4748 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)); | |
4749 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); | |
4750 | ||
b34976b6 | 4751 | return TRUE; |
e86ce104 | 4752 | } |
40b8271b | 4753 | |
82bd7b59 AM |
4754 | #define MIN_SAVE_FPR 14 |
4755 | #define MAX_SAVE_FPR 31 | |
4756 | ||
e86ce104 | 4757 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
4758 | this hook to a) provide some gcc support functions, and b) transfer |
4759 | dynamic linking information gathered so far on function code symbol | |
4760 | entries, to their corresponding function descriptor symbol entries. */ | |
b34976b6 | 4761 | static bfd_boolean |
4ce794b7 AM |
4762 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
4763 | struct bfd_link_info *info) | |
e86ce104 AM |
4764 | { |
4765 | struct ppc_link_hash_table *htab; | |
82bd7b59 AM |
4766 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
4767 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; | |
4768 | unsigned int i; | |
4769 | struct elf_link_hash_entry *h; | |
721956f4 | 4770 | bfd_byte *p; |
82bd7b59 | 4771 | char sym[10]; |
e86ce104 AM |
4772 | |
4773 | htab = ppc_hash_table (info); | |
82bd7b59 AM |
4774 | |
4775 | if (htab->sfpr == NULL) | |
4776 | /* We don't have any relocs. */ | |
b34976b6 | 4777 | return TRUE; |
82bd7b59 AM |
4778 | |
4779 | /* First provide any missing ._savef* and ._restf* functions. */ | |
4780 | memcpy (sym, "._savef14", 10); | |
4781 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4782 | { | |
4783 | sym[7] = i / 10 + '0'; | |
4784 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4785 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4786 | if (h != NULL |
772119ce | 4787 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4788 | { |
4789 | if (lowest_savef > i) | |
4790 | lowest_savef = i; | |
4791 | h->root.type = bfd_link_hash_defined; | |
4792 | h->root.u.def.section = htab->sfpr; | |
4793 | h->root.u.def.value = (i - lowest_savef) * 4; | |
4794 | h->type = STT_FUNC; | |
4795 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4796 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4797 | } |
4798 | } | |
4799 | ||
4800 | memcpy (sym, "._restf14", 10); | |
4801 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4802 | { | |
4803 | sym[7] = i / 10 + '0'; | |
4804 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4805 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4806 | if (h != NULL |
772119ce | 4807 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4808 | { |
4809 | if (lowest_restf > i) | |
4810 | lowest_restf = i; | |
4811 | h->root.type = bfd_link_hash_defined; | |
4812 | h->root.u.def.section = htab->sfpr; | |
4813 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 | |
4814 | + (i - lowest_restf) * 4); | |
4815 | h->type = STT_FUNC; | |
4816 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4817 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4818 | } |
4819 | } | |
4820 | ||
4ce794b7 | 4821 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
805fc799 | 4822 | |
eea6121a AM |
4823 | htab->sfpr->size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
4824 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); | |
82bd7b59 | 4825 | |
eea6121a | 4826 | if (htab->sfpr->size == 0) |
805fc799 | 4827 | { |
06da1e8e AM |
4828 | _bfd_strip_section_from_output (info, htab->sfpr); |
4829 | return TRUE; | |
805fc799 | 4830 | } |
82bd7b59 | 4831 | |
eea6121a | 4832 | p = bfd_alloc (htab->elf.dynobj, htab->sfpr->size); |
721956f4 | 4833 | if (p == NULL) |
b34976b6 | 4834 | return FALSE; |
721956f4 AM |
4835 | htab->sfpr->contents = p; |
4836 | ||
4837 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) | |
4838 | { | |
4839 | unsigned int fpr = i << 21; | |
4840 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4841 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); | |
4842 | p += 4; | |
4843 | } | |
4844 | if (lowest_savef <= MAX_SAVE_FPR) | |
4845 | { | |
82bd7b59 AM |
4846 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
4847 | p += 4; | |
721956f4 | 4848 | } |
82bd7b59 | 4849 | |
721956f4 AM |
4850 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
4851 | { | |
4852 | unsigned int fpr = i << 21; | |
4853 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4854 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); | |
82bd7b59 AM |
4855 | p += 4; |
4856 | } | |
06da1e8e AM |
4857 | if (lowest_restf <= MAX_SAVE_FPR) |
4858 | bfd_put_32 (htab->elf.dynobj, BLR, p); | |
82bd7b59 | 4859 | |
b34976b6 | 4860 | return TRUE; |
e86ce104 AM |
4861 | } |
4862 | ||
4863 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
4864 | regular object. The current definition is in some section of the | |
4865 | dynamic object, but we're not including those sections. We have to | |
4866 | change the definition to something the rest of the link can | |
4867 | understand. */ | |
4868 | ||
b34976b6 | 4869 | static bfd_boolean |
4ce794b7 AM |
4870 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
4871 | struct elf_link_hash_entry *h) | |
e86ce104 AM |
4872 | { |
4873 | struct ppc_link_hash_table *htab; | |
e86ce104 AM |
4874 | asection *s; |
4875 | unsigned int power_of_two; | |
4876 | ||
4877 | htab = ppc_hash_table (info); | |
4878 | ||
4879 | /* Deal with function syms. */ | |
4880 | if (h->type == STT_FUNC | |
4881 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
4882 | { | |
4883 | /* Clear procedure linkage table information for any symbol that | |
4884 | won't need a .plt entry. */ | |
411e1bfb AM |
4885 | struct plt_entry *ent; |
4886 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4887 | if (ent->plt.refcount > 0) | |
4888 | break; | |
8387904d | 4889 | if (ent == NULL |
9c7a29a3 AM |
4890 | || SYMBOL_CALLS_LOCAL (info, h) |
4891 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4892 | && h->root.type == bfd_link_hash_undefweak)) | |
40b8271b | 4893 | { |
411e1bfb | 4894 | h->plt.plist = NULL; |
40b8271b | 4895 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
40b8271b | 4896 | } |
5bd4f169 | 4897 | } |
bbd7ec4a | 4898 | else |
411e1bfb | 4899 | h->plt.plist = NULL; |
5bd4f169 AM |
4900 | |
4901 | /* If this is a weak symbol, and there is a real definition, the | |
4902 | processor independent code will have arranged for us to see the | |
4903 | real definition first, and we can just use the same value. */ | |
4904 | if (h->weakdef != NULL) | |
4905 | { | |
4906 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
4907 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
4908 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
4909 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
a23b6845 AM |
4910 | if (ELIMINATE_COPY_RELOCS) |
4911 | h->elf_link_hash_flags | |
4912 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) | |
4913 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); | |
b34976b6 | 4914 | return TRUE; |
5bd4f169 AM |
4915 | } |
4916 | ||
5bd4f169 AM |
4917 | /* If we are creating a shared library, we must presume that the |
4918 | only references to the symbol are via the global offset table. | |
4919 | For such cases we need not do anything here; the relocations will | |
4920 | be handled correctly by relocate_section. */ | |
4921 | if (info->shared) | |
b34976b6 | 4922 | return TRUE; |
5bd4f169 | 4923 | |
65f38f15 AM |
4924 | /* If there are no references to this symbol that do not use the |
4925 | GOT, we don't need to generate a copy reloc. */ | |
4926 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 4927 | return TRUE; |
65f38f15 | 4928 | |
f4656909 | 4929 | if (ELIMINATE_COPY_RELOCS) |
65f38f15 | 4930 | { |
f4656909 AM |
4931 | struct ppc_link_hash_entry * eh; |
4932 | struct ppc_dyn_relocs *p; | |
65f38f15 | 4933 | |
f4656909 AM |
4934 | eh = (struct ppc_link_hash_entry *) h; |
4935 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4936 | { | |
4937 | s = p->sec->output_section; | |
4938 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
4939 | break; | |
4940 | } | |
4941 | ||
4942 | /* If we didn't find any dynamic relocs in read-only sections, then | |
4943 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
4944 | if (p == NULL) | |
4945 | { | |
4946 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
4947 | return TRUE; | |
4948 | } | |
65f38f15 AM |
4949 | } |
4950 | ||
5d35169e | 4951 | if (h->plt.plist != NULL) |
97b639ba AM |
4952 | { |
4953 | /* We should never get here, but unfortunately there are versions | |
4954 | of gcc out there that improperly (for this ABI) put initialized | |
4955 | function pointers, vtable refs and suchlike in read-only | |
4956 | sections. Allow them to proceed, but warn that this might | |
4957 | break at runtime. */ | |
4958 | (*_bfd_error_handler) | |
4959 | (_("copy reloc against `%s' requires lazy plt linking; " | |
4960 | "avoid setting LD_BIND_NOW=1 or upgrade gcc"), | |
4961 | h->root.root.string); | |
4962 | } | |
5d35169e AM |
4963 | |
4964 | /* This is a reference to a symbol defined by a dynamic object which | |
4965 | is not a function. */ | |
4966 | ||
5bd4f169 AM |
4967 | /* We must allocate the symbol in our .dynbss section, which will |
4968 | become part of the .bss section of the executable. There will be | |
4969 | an entry for this symbol in the .dynsym section. The dynamic | |
4970 | object will contain position independent code, so all references | |
4971 | from the dynamic object to this symbol will go through the global | |
4972 | offset table. The dynamic linker will use the .dynsym entry to | |
4973 | determine the address it must put in the global offset table, so | |
4974 | both the dynamic object and the regular object will refer to the | |
4975 | same memory location for the variable. */ | |
5bd4f169 | 4976 | |
04c9666a AM |
4977 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
4978 | to copy the initial value out of the dynamic object and into the | |
5bd4f169 AM |
4979 | runtime process image. We need to remember the offset into the |
4980 | .rela.bss section we are going to use. */ | |
4981 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
4982 | { | |
eea6121a | 4983 | htab->relbss->size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
4984 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
4985 | } | |
4986 | ||
4987 | /* We need to figure out the alignment required for this symbol. I | |
4988 | have no idea how ELF linkers handle this. */ | |
4989 | power_of_two = bfd_log2 (h->size); | |
4990 | if (power_of_two > 4) | |
4991 | power_of_two = 4; | |
4992 | ||
4993 | /* Apply the required alignment. */ | |
4ce794b7 | 4994 | s = htab->dynbss; |
eea6121a | 4995 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
65f38f15 | 4996 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) |
5bd4f169 | 4997 | { |
65f38f15 | 4998 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 4999 | return FALSE; |
5bd4f169 AM |
5000 | } |
5001 | ||
5002 | /* Define the symbol as being at this point in the section. */ | |
5003 | h->root.u.def.section = s; | |
eea6121a | 5004 | h->root.u.def.value = s->size; |
5bd4f169 AM |
5005 | |
5006 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 5007 | s->size += h->size; |
5bd4f169 | 5008 | |
b34976b6 | 5009 | return TRUE; |
5bd4f169 AM |
5010 | } |
5011 | ||
e86ce104 AM |
5012 | /* If given a function descriptor symbol, hide both the function code |
5013 | sym and the descriptor. */ | |
5014 | static void | |
4ce794b7 AM |
5015 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
5016 | struct elf_link_hash_entry *h, | |
5017 | bfd_boolean force_local) | |
e86ce104 | 5018 | { |
34814b9f | 5019 | struct ppc_link_hash_entry *eh; |
e86ce104 AM |
5020 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
5021 | ||
34814b9f AM |
5022 | eh = (struct ppc_link_hash_entry *) h; |
5023 | if (eh->is_func_descriptor) | |
e86ce104 | 5024 | { |
34814b9f | 5025 | struct ppc_link_hash_entry *fh = eh->oh; |
e86ce104 | 5026 | |
721956f4 | 5027 | if (fh == NULL) |
d1329ca3 AM |
5028 | { |
5029 | const char *p, *q; | |
5030 | struct ppc_link_hash_table *htab; | |
5031 | char save; | |
5032 | ||
5033 | /* We aren't supposed to use alloca in BFD because on | |
5034 | systems which do not have alloca the version in libiberty | |
5035 | calls xmalloc, which might cause the program to crash | |
5036 | when it runs out of memory. This function doesn't have a | |
5037 | return status, so there's no way to gracefully return an | |
5038 | error. So cheat. We know that string[-1] can be safely | |
34814b9f AM |
5039 | accessed; It's either a string in an ELF string table, |
5040 | or allocated in an objalloc structure. */ | |
d1329ca3 | 5041 | |
34814b9f | 5042 | p = eh->elf.root.root.string - 1; |
d1329ca3 AM |
5043 | save = *p; |
5044 | *(char *) p = '.'; | |
5045 | htab = ppc_hash_table (info); | |
34814b9f AM |
5046 | fh = (struct ppc_link_hash_entry *) |
5047 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
5048 | *(char *) p = save; |
5049 | ||
5050 | /* Unfortunately, if it so happens that the string we were | |
5051 | looking for was allocated immediately before this string, | |
5052 | then we overwrote the string terminator. That's the only | |
5053 | reason the lookup should fail. */ | |
5054 | if (fh == NULL) | |
5055 | { | |
34814b9f AM |
5056 | q = eh->elf.root.root.string + strlen (eh->elf.root.root.string); |
5057 | while (q >= eh->elf.root.root.string && *q == *p) | |
d1329ca3 | 5058 | --q, --p; |
34814b9f AM |
5059 | if (q < eh->elf.root.root.string && *p == '.') |
5060 | fh = (struct ppc_link_hash_entry *) | |
5061 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
5062 | } |
5063 | if (fh != NULL) | |
5064 | { | |
34814b9f AM |
5065 | eh->oh = fh; |
5066 | fh->oh = eh; | |
d1329ca3 AM |
5067 | } |
5068 | } | |
e86ce104 | 5069 | if (fh != NULL) |
34814b9f | 5070 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); |
e86ce104 AM |
5071 | } |
5072 | } | |
5073 | ||
411e1bfb | 5074 | static bfd_boolean |
8843416a AM |
5075 | get_sym_h (struct elf_link_hash_entry **hp, |
5076 | Elf_Internal_Sym **symp, | |
5077 | asection **symsecp, | |
5078 | char **tls_maskp, | |
5079 | Elf_Internal_Sym **locsymsp, | |
5080 | unsigned long r_symndx, | |
5081 | bfd *ibfd) | |
411e1bfb AM |
5082 | { |
5083 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5084 | ||
5085 | if (r_symndx >= symtab_hdr->sh_info) | |
5086 | { | |
5087 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
5088 | struct elf_link_hash_entry *h; | |
5089 | ||
5090 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5091 | while (h->root.type == bfd_link_hash_indirect | |
5092 | || h->root.type == bfd_link_hash_warning) | |
5093 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5094 | ||
5095 | if (hp != NULL) | |
5096 | *hp = h; | |
5097 | ||
5098 | if (symp != NULL) | |
5099 | *symp = NULL; | |
5100 | ||
5101 | if (symsecp != NULL) | |
5102 | { | |
5103 | asection *symsec = NULL; | |
5104 | if (h->root.type == bfd_link_hash_defined | |
5105 | || h->root.type == bfd_link_hash_defweak) | |
5106 | symsec = h->root.u.def.section; | |
5107 | *symsecp = symsec; | |
5108 | } | |
5109 | ||
e7b938ca | 5110 | if (tls_maskp != NULL) |
411e1bfb AM |
5111 | { |
5112 | struct ppc_link_hash_entry *eh; | |
5113 | ||
5114 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 5115 | *tls_maskp = &eh->tls_mask; |
411e1bfb AM |
5116 | } |
5117 | } | |
5118 | else | |
5119 | { | |
5120 | Elf_Internal_Sym *sym; | |
5121 | Elf_Internal_Sym *locsyms = *locsymsp; | |
5122 | ||
5123 | if (locsyms == NULL) | |
5124 | { | |
5125 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
5126 | if (locsyms == NULL) | |
5127 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
5128 | symtab_hdr->sh_info, | |
5129 | 0, NULL, NULL, NULL); | |
5130 | if (locsyms == NULL) | |
5131 | return FALSE; | |
5132 | *locsymsp = locsyms; | |
5133 | } | |
5134 | sym = locsyms + r_symndx; | |
5135 | ||
5136 | if (hp != NULL) | |
5137 | *hp = NULL; | |
5138 | ||
5139 | if (symp != NULL) | |
5140 | *symp = sym; | |
5141 | ||
5142 | if (symsecp != NULL) | |
5143 | { | |
5144 | asection *symsec = NULL; | |
5145 | if ((sym->st_shndx != SHN_UNDEF | |
5146 | && sym->st_shndx < SHN_LORESERVE) | |
5147 | || sym->st_shndx > SHN_HIRESERVE) | |
5148 | symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); | |
5149 | *symsecp = symsec; | |
5150 | } | |
5151 | ||
e7b938ca | 5152 | if (tls_maskp != NULL) |
411e1bfb AM |
5153 | { |
5154 | struct got_entry **lgot_ents; | |
e7b938ca | 5155 | char *tls_mask; |
411e1bfb | 5156 | |
e7b938ca | 5157 | tls_mask = NULL; |
411e1bfb AM |
5158 | lgot_ents = elf_local_got_ents (ibfd); |
5159 | if (lgot_ents != NULL) | |
5160 | { | |
e7b938ca AM |
5161 | char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info); |
5162 | tls_mask = &lgot_masks[r_symndx]; | |
411e1bfb | 5163 | } |
e7b938ca | 5164 | *tls_maskp = tls_mask; |
411e1bfb AM |
5165 | } |
5166 | } | |
5167 | return TRUE; | |
5168 | } | |
5169 | ||
e7b938ca | 5170 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
951fd09b | 5171 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
ad8e1ba5 | 5172 | type suitable for optimization, and 1 otherwise. */ |
951fd09b AM |
5173 | |
5174 | static int | |
0d4792f7 AM |
5175 | get_tls_mask (char **tls_maskp, unsigned long *toc_symndx, |
5176 | Elf_Internal_Sym **locsymsp, | |
4ce794b7 | 5177 | const Elf_Internal_Rela *rel, bfd *ibfd) |
411e1bfb AM |
5178 | { |
5179 | unsigned long r_symndx; | |
0d4792f7 | 5180 | int next_r; |
411e1bfb AM |
5181 | struct elf_link_hash_entry *h; |
5182 | Elf_Internal_Sym *sym; | |
5183 | asection *sec; | |
5184 | bfd_vma off; | |
5185 | ||
5186 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5187 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 5188 | return 0; |
411e1bfb | 5189 | |
e7b938ca | 5190 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
411e1bfb AM |
5191 | || sec == NULL |
5192 | || ppc64_elf_section_data (sec)->t_symndx == NULL) | |
951fd09b | 5193 | return 1; |
411e1bfb AM |
5194 | |
5195 | /* Look inside a TOC section too. */ | |
5196 | if (h != NULL) | |
5197 | { | |
5198 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
5199 | off = h->root.u.def.value; | |
5200 | } | |
5201 | else | |
5202 | off = sym->st_value; | |
5203 | off += rel->r_addend; | |
5204 | BFD_ASSERT (off % 8 == 0); | |
5205 | r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8]; | |
951fd09b | 5206 | next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1]; |
e7b938ca | 5207 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 5208 | return 0; |
0d4792f7 AM |
5209 | if (toc_symndx != NULL) |
5210 | *toc_symndx = r_symndx; | |
5211 | if ((h == NULL | |
5212 | || ((h->root.type == bfd_link_hash_defined | |
5213 | || h->root.type == bfd_link_hash_defweak) | |
5214 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
5215 | && (next_r == -1 || next_r == -2)) | |
5216 | return 1 - next_r; | |
951fd09b | 5217 | return 1; |
411e1bfb AM |
5218 | } |
5219 | ||
754021d0 | 5220 | /* Adjust all global syms defined in opd sections. In gcc generated |
8387904d | 5221 | code for the old ABI, these will already have been done. */ |
754021d0 AM |
5222 | |
5223 | static bfd_boolean | |
5224 | adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
5225 | { | |
5226 | struct ppc_link_hash_entry *eh; | |
5227 | asection *sym_sec; | |
5228 | long *opd_adjust; | |
5229 | ||
5230 | if (h->root.type == bfd_link_hash_indirect) | |
5231 | return TRUE; | |
5232 | ||
5233 | if (h->root.type == bfd_link_hash_warning) | |
5234 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5235 | ||
5236 | if (h->root.type != bfd_link_hash_defined | |
5237 | && h->root.type != bfd_link_hash_defweak) | |
5238 | return TRUE; | |
5239 | ||
5240 | eh = (struct ppc_link_hash_entry *) h; | |
5241 | if (eh->adjust_done) | |
5242 | return TRUE; | |
5243 | ||
5244 | sym_sec = eh->elf.root.u.def.section; | |
4025353c AM |
5245 | opd_adjust = get_opd_info (sym_sec); |
5246 | if (opd_adjust != NULL) | |
754021d0 | 5247 | { |
4025353c AM |
5248 | long adjust = opd_adjust[eh->elf.root.u.def.value / 24]; |
5249 | if (adjust == -1) | |
5250 | { | |
5251 | /* This entry has been deleted. */ | |
81688140 AM |
5252 | asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section; |
5253 | if (dsec == NULL) | |
5254 | { | |
5255 | for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next) | |
5256 | if (elf_discarded_section (dsec)) | |
5257 | { | |
5258 | ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec; | |
5259 | break; | |
5260 | } | |
5261 | } | |
4025353c | 5262 | eh->elf.root.u.def.value = 0; |
81688140 | 5263 | eh->elf.root.u.def.section = dsec; |
4025353c AM |
5264 | } |
5265 | else | |
5266 | eh->elf.root.u.def.value += adjust; | |
754021d0 AM |
5267 | eh->adjust_done = 1; |
5268 | } | |
5269 | return TRUE; | |
5270 | } | |
5271 | ||
5272 | /* Remove unused Official Procedure Descriptor entries. Currently we | |
5273 | only remove those associated with functions in discarded link-once | |
5274 | sections, or weakly defined functions that have been overridden. It | |
5275 | would be possible to remove many more entries for statically linked | |
5276 | applications. */ | |
5277 | ||
b34976b6 | 5278 | bfd_boolean |
4ce794b7 | 5279 | ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info) |
1e2f5b6e AM |
5280 | { |
5281 | bfd *ibfd; | |
754021d0 | 5282 | bfd_boolean some_edited = FALSE; |
1e2f5b6e | 5283 | |
411e1bfb | 5284 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1e2f5b6e AM |
5285 | { |
5286 | asection *sec; | |
5287 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5288 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 5289 | Elf_Internal_Sym *local_syms; |
1e2f5b6e AM |
5290 | struct elf_link_hash_entry **sym_hashes; |
5291 | bfd_vma offset; | |
d6fe2dc1 | 5292 | bfd_size_type amt; |
4025353c | 5293 | long *opd_adjust; |
b34976b6 | 5294 | bfd_boolean need_edit; |
1e2f5b6e AM |
5295 | |
5296 | sec = bfd_get_section_by_name (ibfd, ".opd"); | |
5297 | if (sec == NULL) | |
5298 | continue; | |
5299 | ||
eea6121a | 5300 | amt = sec->size * sizeof (long) / 24; |
4025353c AM |
5301 | opd_adjust = get_opd_info (sec); |
5302 | if (opd_adjust == NULL) | |
d6fe2dc1 AM |
5303 | { |
5304 | /* Must be a ld -r link. ie. check_relocs hasn't been | |
5305 | called. */ | |
4025353c AM |
5306 | opd_adjust = bfd_zalloc (obfd, amt); |
5307 | ppc64_elf_section_data (sec)->opd.adjust = opd_adjust; | |
d6fe2dc1 | 5308 | } |
4025353c | 5309 | memset (opd_adjust, 0, amt); |
1e2f5b6e AM |
5310 | |
5311 | if (sec->output_section == bfd_abs_section_ptr) | |
5312 | continue; | |
5313 | ||
5314 | /* Look through the section relocs. */ | |
5315 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
5316 | continue; | |
5317 | ||
6cdc0ccc | 5318 | local_syms = NULL; |
1e2f5b6e AM |
5319 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
5320 | sym_hashes = elf_sym_hashes (ibfd); | |
5321 | ||
5322 | /* Read the relocations. */ | |
4ce794b7 | 5323 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5324 | info->keep_memory); |
1e2f5b6e | 5325 | if (relstart == NULL) |
b34976b6 | 5326 | return FALSE; |
1e2f5b6e AM |
5327 | |
5328 | /* First run through the relocs to check they are sane, and to | |
5329 | determine whether we need to edit this opd section. */ | |
b34976b6 | 5330 | need_edit = FALSE; |
1e2f5b6e AM |
5331 | offset = 0; |
5332 | relend = relstart + sec->reloc_count; | |
50bc7936 | 5333 | for (rel = relstart; rel < relend; ) |
1e2f5b6e | 5334 | { |
04c9666a | 5335 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e AM |
5336 | unsigned long r_symndx; |
5337 | asection *sym_sec; | |
5338 | struct elf_link_hash_entry *h; | |
5339 | Elf_Internal_Sym *sym; | |
5340 | ||
5341 | /* .opd contains a regular array of 24 byte entries. We're | |
5342 | only interested in the reloc pointing to a function entry | |
5343 | point. */ | |
50bc7936 AM |
5344 | if (rel->r_offset != offset |
5345 | || rel + 1 >= relend | |
5346 | || (rel + 1)->r_offset != offset + 8) | |
1e2f5b6e AM |
5347 | { |
5348 | /* If someone messes with .opd alignment then after a | |
5349 | "ld -r" we might have padding in the middle of .opd. | |
5350 | Also, there's nothing to prevent someone putting | |
5351 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 5352 | optimization for them! */ |
1e2f5b6e | 5353 | (*_bfd_error_handler) |
d003868e | 5354 | (_("%B: .opd is not a regular array of opd entries"), ibfd); |
b34976b6 | 5355 | need_edit = FALSE; |
1e2f5b6e AM |
5356 | break; |
5357 | } | |
5358 | ||
50bc7936 AM |
5359 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
5360 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) | |
5361 | { | |
5362 | (*_bfd_error_handler) | |
d003868e AM |
5363 | (_("%B: unexpected reloc type %u in .opd section"), |
5364 | ibfd, r_type); | |
50bc7936 AM |
5365 | need_edit = FALSE; |
5366 | break; | |
5367 | } | |
5368 | ||
1e2f5b6e | 5369 | r_symndx = ELF64_R_SYM (rel->r_info); |
411e1bfb AM |
5370 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
5371 | r_symndx, ibfd)) | |
50bc7936 | 5372 | goto error_ret; |
1e2f5b6e AM |
5373 | |
5374 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
5375 | { | |
411e1bfb AM |
5376 | const char *sym_name; |
5377 | if (h != NULL) | |
5378 | sym_name = h->root.root.string; | |
5379 | else | |
5380 | sym_name = bfd_elf_local_sym_name (ibfd, sym); | |
5381 | ||
1e2f5b6e | 5382 | (*_bfd_error_handler) |
d003868e AM |
5383 | (_("%B: undefined sym `%s' in .opd section"), |
5384 | ibfd, sym_name); | |
b34976b6 | 5385 | need_edit = FALSE; |
1e2f5b6e AM |
5386 | break; |
5387 | } | |
5388 | ||
51020317 AM |
5389 | /* opd entries are always for functions defined in the |
5390 | current input bfd. If the symbol isn't defined in the | |
5391 | input bfd, then we won't be using the function in this | |
5392 | bfd; It must be defined in a linkonce section in another | |
5393 | bfd, or is weak. It's also possible that we are | |
5394 | discarding the function due to a linker script /DISCARD/, | |
5395 | which we test for via the output_section. */ | |
5396 | if (sym_sec->owner != ibfd | |
5397 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 5398 | need_edit = TRUE; |
1e2f5b6e AM |
5399 | |
5400 | offset += 24; | |
50bc7936 AM |
5401 | rel += 2; |
5402 | /* Allow for the possibility of a reloc on the third word. */ | |
5403 | if (rel < relend | |
5404 | && rel->r_offset == offset - 8) | |
5405 | rel += 1; | |
1e2f5b6e AM |
5406 | } |
5407 | ||
5408 | if (need_edit) | |
5409 | { | |
5410 | Elf_Internal_Rela *write_rel; | |
5411 | bfd_byte *rptr, *wptr; | |
b34976b6 | 5412 | bfd_boolean skip; |
1e2f5b6e AM |
5413 | |
5414 | /* This seems a waste of time as input .opd sections are all | |
5415 | zeros as generated by gcc, but I suppose there's no reason | |
5416 | this will always be so. We might start putting something in | |
5417 | the third word of .opd entries. */ | |
5418 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
5419 | { | |
eea6121a AM |
5420 | bfd_byte *loc; |
5421 | if (!bfd_malloc_and_get_section (ibfd, sec, &loc)) | |
6cdc0ccc | 5422 | { |
eea6121a AM |
5423 | if (loc != NULL) |
5424 | free (loc); | |
50bc7936 | 5425 | error_ret: |
6cdc0ccc AM |
5426 | if (local_syms != NULL |
5427 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5428 | free (local_syms); | |
6cdc0ccc AM |
5429 | if (elf_section_data (sec)->relocs != relstart) |
5430 | free (relstart); | |
b34976b6 | 5431 | return FALSE; |
6cdc0ccc | 5432 | } |
1e2f5b6e AM |
5433 | sec->contents = loc; |
5434 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
5435 | } | |
5436 | ||
5437 | elf_section_data (sec)->relocs = relstart; | |
5438 | ||
5439 | wptr = sec->contents; | |
5440 | rptr = sec->contents; | |
5441 | write_rel = relstart; | |
b34976b6 | 5442 | skip = FALSE; |
1e2f5b6e AM |
5443 | offset = 0; |
5444 | for (rel = relstart; rel < relend; rel++) | |
5445 | { | |
50bc7936 AM |
5446 | unsigned long r_symndx; |
5447 | asection *sym_sec; | |
5448 | struct elf_link_hash_entry *h; | |
5449 | Elf_Internal_Sym *sym; | |
5450 | ||
5451 | r_symndx = ELF64_R_SYM (rel->r_info); | |
5452 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
d37c89e5 | 5453 | r_symndx, ibfd)) |
50bc7936 AM |
5454 | goto error_ret; |
5455 | ||
1e2f5b6e AM |
5456 | if (rel->r_offset == offset) |
5457 | { | |
50bc7936 | 5458 | struct ppc_link_hash_entry *fdh = NULL; |
4025353c AM |
5459 | if (h != NULL |
5460 | && h->root.root.string[0] == '.') | |
50bc7936 AM |
5461 | fdh = get_fdh ((struct ppc_link_hash_entry *) h, |
5462 | ppc_hash_table (info)); | |
1e2f5b6e | 5463 | |
51020317 AM |
5464 | skip = (sym_sec->owner != ibfd |
5465 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
5466 | if (skip) |
5467 | { | |
4025353c | 5468 | if (fdh != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
5469 | { |
5470 | /* Arrange for the function descriptor sym | |
5471 | to be dropped. */ | |
d6fe2dc1 AM |
5472 | fdh->elf.root.u.def.value = 0; |
5473 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 | 5474 | } |
4025353c | 5475 | opd_adjust[rel->r_offset / 24] = -1; |
a4aa0fb7 AM |
5476 | } |
5477 | else | |
1e2f5b6e AM |
5478 | { |
5479 | /* We'll be keeping this opd entry. */ | |
5480 | ||
4025353c | 5481 | if (fdh != NULL) |
1e2f5b6e | 5482 | { |
754021d0 AM |
5483 | /* Redefine the function descriptor symbol to |
5484 | this location in the opd section. It is | |
5485 | necessary to update the value here rather | |
5486 | than using an array of adjustments as we do | |
5487 | for local symbols, because various places | |
5488 | in the generic ELF code use the value | |
5489 | stored in u.def.value. */ | |
d6fe2dc1 | 5490 | fdh->elf.root.u.def.value = wptr - sec->contents; |
754021d0 | 5491 | fdh->adjust_done = 1; |
1e2f5b6e | 5492 | } |
754021d0 AM |
5493 | |
5494 | /* Local syms are a bit tricky. We could | |
5495 | tweak them as they can be cached, but | |
5496 | we'd need to look through the local syms | |
5497 | for the function descriptor sym which we | |
5498 | don't have at the moment. So keep an | |
5499 | array of adjustments. */ | |
4025353c | 5500 | opd_adjust[rel->r_offset / 24] = wptr - rptr; |
1e2f5b6e AM |
5501 | |
5502 | if (wptr != rptr) | |
5503 | memcpy (wptr, rptr, 24); | |
5504 | wptr += 24; | |
5505 | } | |
5506 | rptr += 24; | |
5507 | offset += 24; | |
5508 | } | |
5509 | ||
50bc7936 AM |
5510 | if (skip) |
5511 | { | |
5512 | BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info))); | |
5513 | if (info->shared) | |
5514 | { | |
5515 | /* We won't be needing dynamic relocs here. */ | |
5516 | struct ppc_dyn_relocs **pp; | |
5517 | struct ppc_dyn_relocs *p; | |
5518 | ||
5519 | if (h != NULL) | |
5520 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; | |
5521 | else if (sym_sec != NULL) | |
5522 | pp = ((struct ppc_dyn_relocs **) | |
5523 | &elf_section_data (sym_sec)->local_dynrel); | |
5524 | else | |
5525 | pp = ((struct ppc_dyn_relocs **) | |
5526 | &elf_section_data (sec)->local_dynrel); | |
5527 | while ((p = *pp) != NULL) | |
5528 | { | |
5529 | if (p->sec == sec) | |
5530 | { | |
5531 | p->count -= 1; | |
5532 | if (p->count == 0) | |
d37c89e5 | 5533 | *pp = p->next; |
50bc7936 AM |
5534 | break; |
5535 | } | |
5536 | pp = &p->next; | |
5537 | } | |
5538 | } | |
5539 | } | |
5540 | else | |
1e2f5b6e | 5541 | { |
50bc7936 AM |
5542 | /* We need to adjust any reloc offsets to point to the |
5543 | new opd entries. While we're at it, we may as well | |
5544 | remove redundant relocs. */ | |
1e2f5b6e AM |
5545 | rel->r_offset += wptr - rptr; |
5546 | if (write_rel != rel) | |
5547 | memcpy (write_rel, rel, sizeof (*rel)); | |
5548 | ++write_rel; | |
5549 | } | |
5550 | } | |
5551 | ||
eea6121a | 5552 | sec->size = wptr - sec->contents; |
1e2f5b6e | 5553 | sec->reloc_count = write_rel - relstart; |
cdcf6e38 AM |
5554 | /* Fudge the size too, as this is used later in |
5555 | elf_bfd_final_link if we are emitting relocs. */ | |
5556 | elf_section_data (sec)->rel_hdr.sh_size | |
5557 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; | |
5558 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); | |
754021d0 | 5559 | some_edited = TRUE; |
1e2f5b6e | 5560 | } |
6cdc0ccc | 5561 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 5562 | free (relstart); |
6cdc0ccc | 5563 | |
411e1bfb AM |
5564 | if (local_syms != NULL |
5565 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5566 | { | |
5567 | if (!info->keep_memory) | |
5568 | free (local_syms); | |
5569 | else | |
5570 | symtab_hdr->contents = (unsigned char *) local_syms; | |
5571 | } | |
5572 | } | |
5573 | ||
754021d0 AM |
5574 | if (some_edited) |
5575 | elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL); | |
5576 | ||
411e1bfb AM |
5577 | return TRUE; |
5578 | } | |
5579 | ||
e1918d23 | 5580 | /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ |
411e1bfb | 5581 | |
e1918d23 | 5582 | asection * |
4ce794b7 | 5583 | ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
411e1bfb | 5584 | { |
411e1bfb AM |
5585 | struct ppc_link_hash_table *htab; |
5586 | ||
411e1bfb | 5587 | htab = ppc_hash_table (info); |
a48ebf4d AM |
5588 | if (htab->tls_get_addr != NULL) |
5589 | { | |
8387904d | 5590 | struct ppc_link_hash_entry *h = htab->tls_get_addr; |
a48ebf4d | 5591 | |
8387904d AM |
5592 | while (h->elf.root.type == bfd_link_hash_indirect |
5593 | || h->elf.root.type == bfd_link_hash_warning) | |
5594 | h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link; | |
a48ebf4d AM |
5595 | |
5596 | htab->tls_get_addr = h; | |
8387904d AM |
5597 | |
5598 | if (htab->tls_get_addr_fd == NULL | |
5599 | && h->oh != NULL | |
5600 | && h->oh->is_func_descriptor) | |
5601 | htab->tls_get_addr_fd = h->oh; | |
5602 | } | |
5603 | ||
5604 | if (htab->tls_get_addr_fd != NULL) | |
5605 | { | |
5606 | struct ppc_link_hash_entry *h = htab->tls_get_addr_fd; | |
5607 | ||
5608 | while (h->elf.root.type == bfd_link_hash_indirect | |
5609 | || h->elf.root.type == bfd_link_hash_warning) | |
5610 | h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link; | |
5611 | ||
5612 | htab->tls_get_addr_fd = h; | |
a48ebf4d AM |
5613 | } |
5614 | ||
e1918d23 | 5615 | return _bfd_elf_tls_setup (obfd, info); |
951fd09b | 5616 | } |
411e1bfb | 5617 | |
951fd09b AM |
5618 | /* Run through all the TLS relocs looking for optimization |
5619 | opportunities. The linker has been hacked (see ppc64elf.em) to do | |
5620 | a preliminary section layout so that we know the TLS segment | |
5621 | offsets. We can't optimize earlier because some optimizations need | |
5622 | to know the tp offset, and we need to optimize before allocating | |
5623 | dynamic relocations. */ | |
5624 | ||
5625 | bfd_boolean | |
4ce794b7 | 5626 | ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) |
951fd09b AM |
5627 | { |
5628 | bfd *ibfd; | |
5629 | asection *sec; | |
5630 | struct ppc_link_hash_table *htab; | |
5631 | ||
1049f94e | 5632 | if (info->relocatable || info->shared) |
411e1bfb AM |
5633 | return TRUE; |
5634 | ||
951fd09b | 5635 | htab = ppc_hash_table (info); |
411e1bfb AM |
5636 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5637 | { | |
5638 | Elf_Internal_Sym *locsyms = NULL; | |
5639 | ||
5640 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
5641 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
5642 | { | |
5643 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5644 | int expecting_tls_get_addr; | |
5645 | ||
5646 | /* Read the relocations. */ | |
4ce794b7 | 5647 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5648 | info->keep_memory); |
411e1bfb AM |
5649 | if (relstart == NULL) |
5650 | return FALSE; | |
5651 | ||
5652 | expecting_tls_get_addr = 0; | |
5653 | relend = relstart + sec->reloc_count; | |
5654 | for (rel = relstart; rel < relend; rel++) | |
5655 | { | |
5656 | enum elf_ppc64_reloc_type r_type; | |
5657 | unsigned long r_symndx; | |
5658 | struct elf_link_hash_entry *h; | |
5659 | Elf_Internal_Sym *sym; | |
5660 | asection *sym_sec; | |
e7b938ca AM |
5661 | char *tls_mask; |
5662 | char tls_set, tls_clear, tls_type = 0; | |
411e1bfb | 5663 | bfd_vma value; |
951fd09b | 5664 | bfd_boolean ok_tprel, is_local; |
411e1bfb AM |
5665 | |
5666 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5667 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, |
411e1bfb AM |
5668 | r_symndx, ibfd)) |
5669 | { | |
5670 | err_free_rel: | |
5671 | if (elf_section_data (sec)->relocs != relstart) | |
5672 | free (relstart); | |
5673 | if (locsyms != NULL | |
5674 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5675 | != (unsigned char *) locsyms)) | |
5676 | free (locsyms); | |
5677 | return FALSE; | |
5678 | } | |
5679 | ||
5680 | if (h != NULL) | |
5681 | { | |
5682 | if (h->root.type != bfd_link_hash_defined | |
5683 | && h->root.type != bfd_link_hash_defweak) | |
5684 | continue; | |
5685 | value = h->root.u.def.value; | |
5686 | } | |
5687 | else | |
4025353c AM |
5688 | /* Symbols referenced by TLS relocs must be of type |
5689 | STT_TLS. So no need for .opd local sym adjust. */ | |
5690 | value = sym->st_value; | |
951fd09b | 5691 | |
411e1bfb | 5692 | ok_tprel = FALSE; |
951fd09b AM |
5693 | is_local = FALSE; |
5694 | if (h == NULL | |
5695 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5696 | { |
951fd09b | 5697 | is_local = TRUE; |
411e1bfb AM |
5698 | value += sym_sec->output_offset; |
5699 | value += sym_sec->output_section->vma; | |
e1918d23 | 5700 | value -= htab->elf.tls_sec->vma; |
411e1bfb AM |
5701 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) |
5702 | < (bfd_vma) 1 << 32); | |
5703 | } | |
5704 | ||
4ce794b7 | 5705 | r_type = ELF64_R_TYPE (rel->r_info); |
411e1bfb AM |
5706 | switch (r_type) |
5707 | { | |
5708 | case R_PPC64_GOT_TLSLD16: | |
5709 | case R_PPC64_GOT_TLSLD16_LO: | |
5710 | case R_PPC64_GOT_TLSLD16_HI: | |
5711 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b AM |
5712 | /* These relocs should never be against a symbol |
5713 | defined in a shared lib. Leave them alone if | |
5714 | that turns out to be the case. */ | |
e717da7e | 5715 | ppc64_tlsld_got (ibfd)->refcount -= 1; |
951fd09b AM |
5716 | if (!is_local) |
5717 | continue; | |
5718 | ||
951fd09b AM |
5719 | /* LD -> LE */ |
5720 | tls_set = 0; | |
5721 | tls_clear = TLS_LD; | |
e7b938ca | 5722 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
5723 | expecting_tls_get_addr = 1; |
5724 | break; | |
5725 | ||
5726 | case R_PPC64_GOT_TLSGD16: | |
5727 | case R_PPC64_GOT_TLSGD16_LO: | |
5728 | case R_PPC64_GOT_TLSGD16_HI: | |
5729 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 5730 | if (ok_tprel) |
411e1bfb AM |
5731 | /* GD -> LE */ |
5732 | tls_set = 0; | |
5733 | else | |
5734 | /* GD -> IE */ | |
951fd09b AM |
5735 | tls_set = TLS_TLS | TLS_TPRELGD; |
5736 | tls_clear = TLS_GD; | |
e7b938ca | 5737 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
5738 | expecting_tls_get_addr = 1; |
5739 | break; | |
5740 | ||
5741 | case R_PPC64_GOT_TPREL16_DS: | |
5742 | case R_PPC64_GOT_TPREL16_LO_DS: | |
5743 | case R_PPC64_GOT_TPREL16_HI: | |
5744 | case R_PPC64_GOT_TPREL16_HA: | |
5745 | expecting_tls_get_addr = 0; | |
5746 | if (ok_tprel) | |
5747 | { | |
5748 | /* IE -> LE */ | |
5749 | tls_set = 0; | |
5750 | tls_clear = TLS_TPREL; | |
e7b938ca | 5751 | tls_type = TLS_TLS | TLS_TPREL; |
411e1bfb AM |
5752 | break; |
5753 | } | |
5754 | else | |
5755 | continue; | |
5756 | ||
5757 | case R_PPC64_REL14: | |
5758 | case R_PPC64_REL14_BRTAKEN: | |
5759 | case R_PPC64_REL14_BRNTAKEN: | |
5760 | case R_PPC64_REL24: | |
5761 | if (h != NULL | |
8387904d AM |
5762 | && (h == &htab->tls_get_addr->elf |
5763 | || h == &htab->tls_get_addr_fd->elf)) | |
411e1bfb AM |
5764 | { |
5765 | if (!expecting_tls_get_addr | |
5766 | && rel != relstart | |
5767 | && ((ELF64_R_TYPE (rel[-1].r_info) | |
5768 | == R_PPC64_TOC16) | |
5769 | || (ELF64_R_TYPE (rel[-1].r_info) | |
5770 | == R_PPC64_TOC16_LO))) | |
5771 | { | |
5772 | /* Check for toc tls entries. */ | |
5773 | char *toc_tls; | |
951fd09b | 5774 | int retval; |
411e1bfb | 5775 | |
0d4792f7 | 5776 | retval = get_tls_mask (&toc_tls, NULL, &locsyms, |
951fd09b AM |
5777 | rel - 1, ibfd); |
5778 | if (retval == 0) | |
411e1bfb AM |
5779 | goto err_free_rel; |
5780 | if (toc_tls != NULL) | |
951fd09b | 5781 | expecting_tls_get_addr = retval > 1; |
411e1bfb AM |
5782 | } |
5783 | ||
5784 | if (expecting_tls_get_addr) | |
5785 | { | |
5786 | struct plt_entry *ent; | |
5787 | for (ent = h->plt.plist; ent; ent = ent->next) | |
5788 | if (ent->addend == 0) | |
5789 | { | |
5790 | if (ent->plt.refcount > 0) | |
5791 | ent->plt.refcount -= 1; | |
5792 | break; | |
5793 | } | |
5794 | } | |
5795 | } | |
5796 | expecting_tls_get_addr = 0; | |
5797 | continue; | |
5798 | ||
5799 | case R_PPC64_TPREL64: | |
5800 | expecting_tls_get_addr = 0; | |
5801 | if (ok_tprel) | |
5802 | { | |
5803 | /* IE -> LE */ | |
5804 | tls_set = TLS_EXPLICIT; | |
5805 | tls_clear = TLS_TPREL; | |
5806 | break; | |
5807 | } | |
5808 | else | |
5809 | continue; | |
5810 | ||
5811 | case R_PPC64_DTPMOD64: | |
5812 | expecting_tls_get_addr = 0; | |
951fd09b AM |
5813 | if (rel + 1 < relend |
5814 | && (rel[1].r_info | |
5815 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) | |
5816 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 5817 | { |
951fd09b | 5818 | if (ok_tprel) |
411e1bfb | 5819 | /* GD -> LE */ |
951fd09b | 5820 | tls_set = TLS_EXPLICIT | TLS_GD; |
411e1bfb AM |
5821 | else |
5822 | /* GD -> IE */ | |
951fd09b AM |
5823 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; |
5824 | tls_clear = TLS_GD; | |
411e1bfb AM |
5825 | } |
5826 | else | |
5827 | { | |
951fd09b AM |
5828 | if (!is_local) |
5829 | continue; | |
5830 | ||
5831 | /* LD -> LE */ | |
5832 | tls_set = TLS_EXPLICIT; | |
5833 | tls_clear = TLS_LD; | |
411e1bfb AM |
5834 | } |
5835 | break; | |
5836 | ||
5837 | default: | |
5838 | expecting_tls_get_addr = 0; | |
5839 | continue; | |
5840 | } | |
5841 | ||
5842 | if ((tls_set & TLS_EXPLICIT) == 0) | |
5843 | { | |
5844 | struct got_entry *ent; | |
5845 | ||
5846 | /* Adjust got entry for this reloc. */ | |
5847 | if (h != NULL) | |
5848 | ent = h->got.glist; | |
5849 | else | |
5850 | ent = elf_local_got_ents (ibfd)[r_symndx]; | |
5851 | ||
5852 | for (; ent != NULL; ent = ent->next) | |
5853 | if (ent->addend == rel->r_addend | |
e717da7e | 5854 | && ent->owner == ibfd |
e7b938ca | 5855 | && ent->tls_type == tls_type) |
411e1bfb AM |
5856 | break; |
5857 | if (ent == NULL) | |
5858 | abort (); | |
5859 | ||
5860 | if (tls_set == 0) | |
5861 | { | |
5862 | /* We managed to get rid of a got entry. */ | |
5863 | if (ent->got.refcount > 0) | |
5864 | ent->got.refcount -= 1; | |
5865 | } | |
411e1bfb AM |
5866 | } |
5867 | else if (h != NULL) | |
5868 | { | |
5869 | struct ppc_link_hash_entry * eh; | |
5870 | struct ppc_dyn_relocs **pp; | |
5871 | struct ppc_dyn_relocs *p; | |
5872 | ||
5873 | /* Adjust dynamic relocs. */ | |
5874 | eh = (struct ppc_link_hash_entry *) h; | |
5875 | for (pp = &eh->dyn_relocs; | |
5876 | (p = *pp) != NULL; | |
5877 | pp = &p->next) | |
5878 | if (p->sec == sec) | |
5879 | { | |
5880 | /* If we got rid of a DTPMOD/DTPREL reloc | |
5881 | pair then we'll lose one or two dyn | |
5882 | relocs. */ | |
951fd09b | 5883 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
411e1bfb | 5884 | p->count -= 1; |
951fd09b | 5885 | p->count -= 1; |
411e1bfb AM |
5886 | if (p->count == 0) |
5887 | *pp = p->next; | |
5888 | break; | |
5889 | } | |
5890 | } | |
5891 | ||
e7b938ca AM |
5892 | *tls_mask |= tls_set; |
5893 | *tls_mask &= ~tls_clear; | |
411e1bfb AM |
5894 | } |
5895 | ||
5896 | if (elf_section_data (sec)->relocs != relstart) | |
5897 | free (relstart); | |
5898 | } | |
5899 | ||
5900 | if (locsyms != NULL | |
5901 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5902 | != (unsigned char *) locsyms)) | |
6cdc0ccc AM |
5903 | { |
5904 | if (!info->keep_memory) | |
411e1bfb | 5905 | free (locsyms); |
6cdc0ccc | 5906 | else |
411e1bfb | 5907 | elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; |
6cdc0ccc | 5908 | } |
1e2f5b6e | 5909 | } |
b34976b6 | 5910 | return TRUE; |
1e2f5b6e | 5911 | } |
b34976b6 | 5912 | |
65f38f15 AM |
5913 | /* Allocate space in .plt, .got and associated reloc sections for |
5914 | dynamic relocs. */ | |
5bd4f169 | 5915 | |
b34976b6 | 5916 | static bfd_boolean |
4ce794b7 | 5917 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 5918 | { |
65f38f15 AM |
5919 | struct bfd_link_info *info; |
5920 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 5921 | asection *s; |
65f38f15 AM |
5922 | struct ppc_link_hash_entry *eh; |
5923 | struct ppc_dyn_relocs *p; | |
411e1bfb | 5924 | struct got_entry *gent; |
5bd4f169 | 5925 | |
e92d460e | 5926 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5927 | return TRUE; |
5bd4f169 | 5928 | |
e92d460e AM |
5929 | if (h->root.type == bfd_link_hash_warning) |
5930 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5931 | ||
65f38f15 AM |
5932 | info = (struct bfd_link_info *) inf; |
5933 | htab = ppc_hash_table (info); | |
5bd4f169 | 5934 | |
65f38f15 | 5935 | if (htab->elf.dynamic_sections_created |
411e1bfb | 5936 | && h->dynindx != -1 |
9c7a29a3 | 5937 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) |
5bd4f169 | 5938 | { |
411e1bfb AM |
5939 | struct plt_entry *pent; |
5940 | bfd_boolean doneone = FALSE; | |
5941 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) | |
5942 | if (pent->plt.refcount > 0) | |
5943 | { | |
411e1bfb AM |
5944 | /* If this is the first .plt entry, make room for the special |
5945 | first entry. */ | |
4ce794b7 | 5946 | s = htab->plt; |
eea6121a AM |
5947 | if (s->size == 0) |
5948 | s->size += PLT_INITIAL_ENTRY_SIZE; | |
411e1bfb | 5949 | |
eea6121a | 5950 | pent->plt.offset = s->size; |
411e1bfb AM |
5951 | |
5952 | /* Make room for this entry. */ | |
eea6121a | 5953 | s->size += PLT_ENTRY_SIZE; |
411e1bfb AM |
5954 | |
5955 | /* Make room for the .glink code. */ | |
4ce794b7 | 5956 | s = htab->glink; |
eea6121a AM |
5957 | if (s->size == 0) |
5958 | s->size += GLINK_CALL_STUB_SIZE; | |
411e1bfb | 5959 | /* We need bigger stubs past index 32767. */ |
eea6121a AM |
5960 | if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4) |
5961 | s->size += 4; | |
5962 | s->size += 2*4; | |
411e1bfb AM |
5963 | |
5964 | /* We also need to make an entry in the .rela.plt section. */ | |
4ce794b7 | 5965 | s = htab->relplt; |
eea6121a | 5966 | s->size += sizeof (Elf64_External_Rela); |
411e1bfb AM |
5967 | doneone = TRUE; |
5968 | } | |
5969 | else | |
5970 | pent->plt.offset = (bfd_vma) -1; | |
5971 | if (!doneone) | |
65f38f15 | 5972 | { |
411e1bfb | 5973 | h->plt.plist = NULL; |
65f38f15 AM |
5974 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5975 | } | |
5976 | } | |
5977 | else | |
5978 | { | |
411e1bfb | 5979 | h->plt.plist = NULL; |
65f38f15 AM |
5980 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5981 | } | |
5982 | ||
951fd09b AM |
5983 | eh = (struct ppc_link_hash_entry *) h; |
5984 | /* Run through the TLS GD got entries first if we're changing them | |
5985 | to TPREL. */ | |
e7b938ca | 5986 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
951fd09b AM |
5987 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5988 | if (gent->got.refcount > 0 | |
5989 | && (gent->tls_type & TLS_GD) != 0) | |
5990 | { | |
5991 | /* This was a GD entry that has been converted to TPREL. If | |
5992 | there happens to be a TPREL entry we can use that one. */ | |
5993 | struct got_entry *ent; | |
5994 | for (ent = h->got.glist; ent != NULL; ent = ent->next) | |
5995 | if (ent->got.refcount > 0 | |
5996 | && (ent->tls_type & TLS_TPREL) != 0 | |
e717da7e AM |
5997 | && ent->addend == gent->addend |
5998 | && ent->owner == gent->owner) | |
951fd09b AM |
5999 | { |
6000 | gent->got.refcount = 0; | |
6001 | break; | |
6002 | } | |
6003 | ||
6004 | /* If not, then we'll be using our own TPREL entry. */ | |
6005 | if (gent->got.refcount != 0) | |
6006 | gent->tls_type = TLS_TLS | TLS_TPREL; | |
6007 | } | |
6008 | ||
411e1bfb AM |
6009 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
6010 | if (gent->got.refcount > 0) | |
6011 | { | |
951fd09b AM |
6012 | bfd_boolean dyn; |
6013 | ||
411e1bfb | 6014 | /* Make sure this symbol is output as a dynamic symbol. |
951fd09b AM |
6015 | Undefined weak syms won't yet be marked as dynamic, |
6016 | nor will all TLS symbols. */ | |
411e1bfb AM |
6017 | if (h->dynindx == -1 |
6018 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
6019 | { | |
c152c796 | 6020 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
411e1bfb AM |
6021 | return FALSE; |
6022 | } | |
65f38f15 | 6023 | |
d881513a AM |
6024 | if ((gent->tls_type & TLS_LD) != 0 |
6025 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 6026 | { |
e717da7e | 6027 | gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; |
951fd09b | 6028 | continue; |
411e1bfb | 6029 | } |
951fd09b | 6030 | |
e717da7e | 6031 | s = ppc64_elf_tdata (gent->owner)->got; |
eea6121a AM |
6032 | gent->got.offset = s->size; |
6033 | s->size | |
d881513a | 6034 | += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; |
951fd09b | 6035 | dyn = htab->elf.dynamic_sections_created; |
4e795f50 AM |
6036 | if ((info->shared |
6037 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
6038 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
6039 | || h->root.type != bfd_link_hash_undefweak)) | |
eea6121a | 6040 | ppc64_elf_tdata (gent->owner)->relgot->size |
e7b938ca | 6041 | += (gent->tls_type & eh->tls_mask & TLS_GD |
951fd09b AM |
6042 | ? 2 * sizeof (Elf64_External_Rela) |
6043 | : sizeof (Elf64_External_Rela)); | |
411e1bfb AM |
6044 | } |
6045 | else | |
6046 | gent->got.offset = (bfd_vma) -1; | |
65f38f15 | 6047 | |
65f38f15 | 6048 | if (eh->dyn_relocs == NULL) |
b34976b6 | 6049 | return TRUE; |
65f38f15 AM |
6050 | |
6051 | /* In the shared -Bsymbolic case, discard space allocated for | |
6052 | dynamic pc-relative relocs against symbols which turn out to be | |
6053 | defined in regular objects. For the normal shared case, discard | |
6054 | space for relocs that have become local due to symbol visibility | |
6055 | changes. */ | |
6056 | ||
6057 | if (info->shared) | |
6058 | { | |
9c7a29a3 AM |
6059 | /* Relocs that use pc_count are those that appear on a call insn, |
6060 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | |
6061 | generated via assembly. We want calls to protected symbols to | |
6062 | resolve directly to the function rather than going via the plt. | |
6063 | If people want function pointer comparisons to work as expected | |
6064 | then they should avoid writing weird assembly. */ | |
09695f56 | 6065 | if (SYMBOL_CALLS_LOCAL (info, h)) |
65f38f15 AM |
6066 | { |
6067 | struct ppc_dyn_relocs **pp; | |
6068 | ||
6069 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 6070 | { |
65f38f15 AM |
6071 | p->count -= p->pc_count; |
6072 | p->pc_count = 0; | |
6073 | if (p->count == 0) | |
6074 | *pp = p->next; | |
6075 | else | |
6076 | pp = &p->next; | |
5bd4f169 | 6077 | } |
65f38f15 | 6078 | } |
4e795f50 AM |
6079 | |
6080 | /* Also discard relocs on undefined weak syms with non-default | |
6081 | visibility. */ | |
6082 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
6083 | && h->root.type == bfd_link_hash_undefweak) | |
6084 | eh->dyn_relocs = NULL; | |
65f38f15 | 6085 | } |
f4656909 | 6086 | else if (ELIMINATE_COPY_RELOCS) |
65f38f15 AM |
6087 | { |
6088 | /* For the non-shared case, discard space for relocs against | |
6089 | symbols which turn out to need copy relocs or are not | |
6090 | dynamic. */ | |
6091 | ||
6092 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
6093 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
6094 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
65f38f15 AM |
6095 | { |
6096 | /* Make sure this symbol is output as a dynamic symbol. | |
6097 | Undefined weak syms won't yet be marked as dynamic. */ | |
6098 | if (h->dynindx == -1 | |
6099 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
6100 | { | |
c152c796 | 6101 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 6102 | return FALSE; |
65f38f15 AM |
6103 | } |
6104 | ||
6105 | /* If that succeeded, we know we'll be keeping all the | |
6106 | relocs. */ | |
6107 | if (h->dynindx != -1) | |
6108 | goto keep; | |
6109 | } | |
6110 | ||
6111 | eh->dyn_relocs = NULL; | |
6112 | ||
ec338859 | 6113 | keep: ; |
65f38f15 AM |
6114 | } |
6115 | ||
6116 | /* Finally, allocate space. */ | |
6117 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
6118 | { | |
6119 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
eea6121a | 6120 | sreloc->size += p->count * sizeof (Elf64_External_Rela); |
65f38f15 AM |
6121 | } |
6122 | ||
b34976b6 | 6123 | return TRUE; |
65f38f15 AM |
6124 | } |
6125 | ||
6126 | /* Find any dynamic relocs that apply to read-only sections. */ | |
6127 | ||
b34976b6 | 6128 | static bfd_boolean |
4ce794b7 | 6129 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
65f38f15 AM |
6130 | { |
6131 | struct ppc_link_hash_entry *eh; | |
6132 | struct ppc_dyn_relocs *p; | |
6133 | ||
e92d460e AM |
6134 | if (h->root.type == bfd_link_hash_warning) |
6135 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6136 | ||
65f38f15 AM |
6137 | eh = (struct ppc_link_hash_entry *) h; |
6138 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
6139 | { | |
6140 | asection *s = p->sec->output_section; | |
6141 | ||
6142 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
6143 | { | |
4ce794b7 | 6144 | struct bfd_link_info *info = inf; |
65f38f15 AM |
6145 | |
6146 | info->flags |= DF_TEXTREL; | |
6147 | ||
6148 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 6149 | return FALSE; |
65f38f15 AM |
6150 | } |
6151 | } | |
b34976b6 | 6152 | return TRUE; |
65f38f15 AM |
6153 | } |
6154 | ||
6155 | /* Set the sizes of the dynamic sections. */ | |
6156 | ||
b34976b6 | 6157 | static bfd_boolean |
4ce794b7 AM |
6158 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
6159 | struct bfd_link_info *info) | |
65f38f15 AM |
6160 | { |
6161 | struct ppc_link_hash_table *htab; | |
6162 | bfd *dynobj; | |
6163 | asection *s; | |
b34976b6 | 6164 | bfd_boolean relocs; |
65f38f15 AM |
6165 | bfd *ibfd; |
6166 | ||
6167 | htab = ppc_hash_table (info); | |
6168 | dynobj = htab->elf.dynobj; | |
6169 | if (dynobj == NULL) | |
6170 | abort (); | |
6171 | ||
6172 | if (htab->elf.dynamic_sections_created) | |
6173 | { | |
6174 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 6175 | if (info->executable) |
65f38f15 AM |
6176 | { |
6177 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
6178 | if (s == NULL) | |
6179 | abort (); | |
eea6121a | 6180 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
65f38f15 AM |
6181 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
6182 | } | |
6183 | } | |
6184 | ||
6185 | /* Set up .got offsets for local syms, and space for local dynamic | |
6186 | relocs. */ | |
6187 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
6188 | { | |
411e1bfb AM |
6189 | struct got_entry **lgot_ents; |
6190 | struct got_entry **end_lgot_ents; | |
e7b938ca | 6191 | char *lgot_masks; |
65f38f15 AM |
6192 | bfd_size_type locsymcount; |
6193 | Elf_Internal_Shdr *symtab_hdr; | |
6194 | asection *srel; | |
6195 | ||
6196 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
6197 | continue; | |
6198 | ||
e717da7e AM |
6199 | if (ppc64_tlsld_got (ibfd)->refcount > 0) |
6200 | { | |
6201 | s = ppc64_elf_tdata (ibfd)->got; | |
eea6121a AM |
6202 | ppc64_tlsld_got (ibfd)->offset = s->size; |
6203 | s->size += 16; | |
e717da7e AM |
6204 | if (info->shared) |
6205 | { | |
6206 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
eea6121a | 6207 | srel->size += sizeof (Elf64_External_Rela); |
e717da7e AM |
6208 | } |
6209 | } | |
6210 | else | |
6211 | ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; | |
6212 | ||
65f38f15 AM |
6213 | for (s = ibfd->sections; s != NULL; s = s->next) |
6214 | { | |
ec338859 | 6215 | struct ppc_dyn_relocs *p; |
65f38f15 | 6216 | |
ec338859 AM |
6217 | for (p = *((struct ppc_dyn_relocs **) |
6218 | &elf_section_data (s)->local_dynrel); | |
6219 | p != NULL; | |
6220 | p = p->next) | |
65f38f15 | 6221 | { |
ec338859 AM |
6222 | if (!bfd_is_abs_section (p->sec) |
6223 | && bfd_is_abs_section (p->sec->output_section)) | |
6224 | { | |
6225 | /* Input section has been discarded, either because | |
6226 | it is a copy of a linkonce section or due to | |
6227 | linker script /DISCARD/, so we'll be discarding | |
6228 | the relocs too. */ | |
6229 | } | |
248866a8 | 6230 | else if (p->count != 0) |
ec338859 AM |
6231 | { |
6232 | srel = elf_section_data (p->sec)->sreloc; | |
eea6121a | 6233 | srel->size += p->count * sizeof (Elf64_External_Rela); |
248866a8 AM |
6234 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
6235 | info->flags |= DF_TEXTREL; | |
ec338859 | 6236 | } |
65f38f15 AM |
6237 | } |
6238 | } | |
6239 | ||
411e1bfb AM |
6240 | lgot_ents = elf_local_got_ents (ibfd); |
6241 | if (!lgot_ents) | |
65f38f15 AM |
6242 | continue; |
6243 | ||
6244 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
6245 | locsymcount = symtab_hdr->sh_info; | |
411e1bfb | 6246 | end_lgot_ents = lgot_ents + locsymcount; |
e7b938ca | 6247 | lgot_masks = (char *) end_lgot_ents; |
e717da7e AM |
6248 | s = ppc64_elf_tdata (ibfd)->got; |
6249 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
e7b938ca | 6250 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
65f38f15 | 6251 | { |
411e1bfb AM |
6252 | struct got_entry *ent; |
6253 | ||
6254 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) | |
6255 | if (ent->got.refcount > 0) | |
6256 | { | |
e7b938ca | 6257 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
411e1bfb | 6258 | { |
e717da7e | 6259 | if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) |
411e1bfb | 6260 | { |
eea6121a AM |
6261 | ppc64_tlsld_got (ibfd)->offset = s->size; |
6262 | s->size += 16; | |
411e1bfb | 6263 | if (info->shared) |
eea6121a | 6264 | srel->size += sizeof (Elf64_External_Rela); |
411e1bfb | 6265 | } |
e717da7e | 6266 | ent->got.offset = ppc64_tlsld_got (ibfd)->offset; |
411e1bfb AM |
6267 | } |
6268 | else | |
6269 | { | |
eea6121a | 6270 | ent->got.offset = s->size; |
e7b938ca | 6271 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
411e1bfb | 6272 | { |
eea6121a | 6273 | s->size += 16; |
411e1bfb | 6274 | if (info->shared) |
eea6121a | 6275 | srel->size += 2 * sizeof (Elf64_External_Rela); |
411e1bfb AM |
6276 | } |
6277 | else | |
6278 | { | |
eea6121a | 6279 | s->size += 8; |
411e1bfb | 6280 | if (info->shared) |
eea6121a | 6281 | srel->size += sizeof (Elf64_External_Rela); |
411e1bfb AM |
6282 | } |
6283 | } | |
6284 | } | |
6285 | else | |
6286 | ent->got.offset = (bfd_vma) -1; | |
65f38f15 AM |
6287 | } |
6288 | } | |
6289 | ||
6290 | /* Allocate global sym .plt and .got entries, and space for global | |
6291 | sym dynamic relocs. */ | |
4ce794b7 | 6292 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
65f38f15 AM |
6293 | |
6294 | /* We now have determined the sizes of the various dynamic sections. | |
6295 | Allocate memory for them. */ | |
b34976b6 | 6296 | relocs = FALSE; |
65f38f15 AM |
6297 | for (s = dynobj->sections; s != NULL; s = s->next) |
6298 | { | |
6299 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
6300 | continue; | |
6301 | ||
4ce794b7 | 6302 | if (s == htab->brlt || s == htab->relbrlt) |
721956f4 AM |
6303 | /* These haven't been allocated yet; don't strip. */ |
6304 | continue; | |
e717da7e AM |
6305 | else if (s == htab->got |
6306 | || s == htab->plt | |
4ce794b7 | 6307 | || s == htab->glink) |
65f38f15 AM |
6308 | { |
6309 | /* Strip this section if we don't need it; see the | |
6310 | comment below. */ | |
5bd4f169 | 6311 | } |
65f38f15 | 6312 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 | 6313 | { |
eea6121a | 6314 | if (s->size == 0) |
5bd4f169 AM |
6315 | { |
6316 | /* If we don't need this section, strip it from the | |
6317 | output file. This is mostly to handle .rela.bss and | |
6318 | .rela.plt. We must create both sections in | |
6319 | create_dynamic_sections, because they must be created | |
6320 | before the linker maps input sections to output | |
6321 | sections. The linker does that before | |
6322 | adjust_dynamic_symbol is called, and it is that | |
6323 | function which decides whether anything needs to go | |
6324 | into these sections. */ | |
5bd4f169 AM |
6325 | } |
6326 | else | |
6327 | { | |
4ce794b7 | 6328 | if (s != htab->relplt) |
b34976b6 | 6329 | relocs = TRUE; |
5bd4f169 AM |
6330 | |
6331 | /* We use the reloc_count field as a counter if we need | |
6332 | to copy relocs into the output file. */ | |
6333 | s->reloc_count = 0; | |
6334 | } | |
6335 | } | |
65f38f15 | 6336 | else |
5bd4f169 AM |
6337 | { |
6338 | /* It's not one of our sections, so don't allocate space. */ | |
6339 | continue; | |
6340 | } | |
6341 | ||
eea6121a | 6342 | if (s->size == 0) |
5bd4f169 AM |
6343 | { |
6344 | _bfd_strip_section_from_output (info, s); | |
6345 | continue; | |
6346 | } | |
6347 | ||
5f333394 | 6348 | /* .plt is in the bss section. We don't initialise it. */ |
680a3378 | 6349 | if (s == htab->plt) |
5f333394 AM |
6350 | continue; |
6351 | ||
65f38f15 AM |
6352 | /* Allocate memory for the section contents. We use bfd_zalloc |
6353 | here in case unused entries are not reclaimed before the | |
6354 | section's contents are written out. This should not happen, | |
411e1bfb AM |
6355 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
6356 | sections instead of garbage. | |
6357 | We also rely on the section contents being zero when writing | |
6358 | the GOT. */ | |
eea6121a | 6359 | s->contents = bfd_zalloc (dynobj, s->size); |
65f38f15 | 6360 | if (s->contents == NULL) |
b34976b6 | 6361 | return FALSE; |
5bd4f169 AM |
6362 | } |
6363 | ||
e717da7e AM |
6364 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
6365 | { | |
6366 | s = ppc64_elf_tdata (ibfd)->got; | |
6367 | if (s != NULL && s != htab->got) | |
6368 | { | |
eea6121a | 6369 | if (s->size == 0) |
e717da7e AM |
6370 | _bfd_strip_section_from_output (info, s); |
6371 | else | |
6372 | { | |
eea6121a | 6373 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
6374 | if (s->contents == NULL) |
6375 | return FALSE; | |
6376 | } | |
6377 | } | |
6378 | s = ppc64_elf_tdata (ibfd)->relgot; | |
6379 | if (s != NULL) | |
6380 | { | |
eea6121a | 6381 | if (s->size == 0) |
e717da7e AM |
6382 | _bfd_strip_section_from_output (info, s); |
6383 | else | |
6384 | { | |
eea6121a | 6385 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
6386 | if (s->contents == NULL) |
6387 | return FALSE; | |
6388 | relocs = TRUE; | |
6389 | s->reloc_count = 0; | |
6390 | } | |
6391 | } | |
6392 | } | |
6393 | ||
e86ce104 | 6394 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
6395 | { |
6396 | /* Add some entries to the .dynamic section. We fill in the | |
6397 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
6398 | must add the entries now so that we get the correct size for | |
6399 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
6400 | dynamic linker and used by the debugger. */ | |
dc810e39 | 6401 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 6402 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 6403 | |
36af4a4e | 6404 | if (info->executable) |
5bd4f169 | 6405 | { |
dc810e39 | 6406 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 6407 | return FALSE; |
5bd4f169 AM |
6408 | } |
6409 | ||
eea6121a | 6410 | if (htab->plt != NULL && htab->plt->size != 0) |
5bd4f169 | 6411 | { |
dc810e39 AM |
6412 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
6413 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
6414 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
6415 | || !add_dynamic_entry (DT_JMPREL, 0) |
6416 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 6417 | return FALSE; |
5bd4f169 AM |
6418 | } |
6419 | ||
19397422 AM |
6420 | if (NO_OPD_RELOCS) |
6421 | { | |
6422 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
6423 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 6424 | return FALSE; |
19397422 AM |
6425 | } |
6426 | ||
5bd4f169 AM |
6427 | if (relocs) |
6428 | { | |
dc810e39 AM |
6429 | if (!add_dynamic_entry (DT_RELA, 0) |
6430 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6431 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 6432 | return FALSE; |
5bd4f169 | 6433 | |
65f38f15 AM |
6434 | /* If any dynamic relocs apply to a read-only section, |
6435 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 6436 | if ((info->flags & DF_TEXTREL) == 0) |
4ce794b7 | 6437 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
5bd4f169 | 6438 | |
65f38f15 | 6439 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 6440 | { |
65f38f15 | 6441 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 6442 | return FALSE; |
5bd4f169 | 6443 | } |
5bd4f169 | 6444 | } |
5bd4f169 | 6445 | } |
65f38f15 | 6446 | #undef add_dynamic_entry |
5bd4f169 | 6447 | |
b34976b6 | 6448 | return TRUE; |
5bd4f169 AM |
6449 | } |
6450 | ||
721956f4 | 6451 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 6452 | |
4ce794b7 AM |
6453 | static inline enum ppc_stub_type |
6454 | ppc_type_of_stub (asection *input_sec, | |
6455 | const Elf_Internal_Rela *rel, | |
6456 | struct ppc_link_hash_entry **hash, | |
6457 | bfd_vma destination) | |
5bd4f169 | 6458 | { |
721956f4 AM |
6459 | struct ppc_link_hash_entry *h = *hash; |
6460 | bfd_vma location; | |
6461 | bfd_vma branch_offset; | |
6462 | bfd_vma max_branch_offset; | |
4ce794b7 | 6463 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 | 6464 | |
721956f4 AM |
6465 | if (h != NULL) |
6466 | { | |
6467 | if (h->oh != NULL | |
8387904d AM |
6468 | && h->oh->is_func_descriptor) |
6469 | h = h->oh; | |
6470 | ||
6471 | if (h->elf.dynindx != -1) | |
5bd4f169 | 6472 | { |
411e1bfb | 6473 | struct plt_entry *ent; |
8387904d AM |
6474 | |
6475 | for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next) | |
411e1bfb AM |
6476 | if (ent->addend == rel->r_addend |
6477 | && ent->plt.offset != (bfd_vma) -1) | |
6478 | { | |
8387904d | 6479 | *hash = h; |
411e1bfb AM |
6480 | return ppc_stub_plt_call; |
6481 | } | |
5bd4f169 AM |
6482 | } |
6483 | ||
ee7de3e6 AM |
6484 | if (!(h->elf.root.type == bfd_link_hash_defined |
6485 | || h->elf.root.type == bfd_link_hash_defweak) | |
6486 | || h->elf.root.u.def.section->output_section == NULL) | |
721956f4 | 6487 | return ppc_stub_none; |
5d1634d7 | 6488 | } |
5d1634d7 | 6489 | |
721956f4 AM |
6490 | /* Determine where the call point is. */ |
6491 | location = (input_sec->output_offset | |
6492 | + input_sec->output_section->vma | |
6493 | + rel->r_offset); | |
5d1634d7 | 6494 | |
721956f4 AM |
6495 | branch_offset = destination - location; |
6496 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 6497 | |
721956f4 AM |
6498 | /* Determine if a long branch stub is needed. */ |
6499 | max_branch_offset = 1 << 25; | |
4ce794b7 | 6500 | if (r_type != R_PPC64_REL24) |
721956f4 | 6501 | max_branch_offset = 1 << 15; |
5d1634d7 | 6502 | |
721956f4 AM |
6503 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
6504 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
6505 | is needed later. */ | |
6506 | return ppc_stub_long_branch; | |
5d1634d7 | 6507 | |
721956f4 | 6508 | return ppc_stub_none; |
5d1634d7 AM |
6509 | } |
6510 | ||
6511 | /* Build a .plt call stub. */ | |
6512 | ||
4ce794b7 AM |
6513 | static inline bfd_byte * |
6514 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset) | |
5d1634d7 AM |
6515 | { |
6516 | #define PPC_LO(v) ((v) & 0xffff) | |
6517 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6518 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6519 | ||
5d1634d7 | 6520 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
ad8e1ba5 | 6521 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
5d1634d7 AM |
6522 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
6523 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6524 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6525 | offset += 8; |
6526 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
6527 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6528 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6529 | offset += 8; |
6530 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
6531 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
6532 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
6533 | return p; | |
6534 | } | |
6535 | ||
b34976b6 | 6536 | static bfd_boolean |
4ce794b7 | 6537 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
5d1634d7 | 6538 | { |
721956f4 AM |
6539 | struct ppc_stub_hash_entry *stub_entry; |
6540 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
6541 | struct bfd_link_info *info; |
6542 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
6543 | bfd_byte *loc; |
6544 | bfd_byte *p; | |
6545 | unsigned int indx; | |
411e1bfb | 6546 | struct plt_entry *ent; |
721956f4 AM |
6547 | bfd_vma off; |
6548 | int size; | |
5d1634d7 | 6549 | |
721956f4 AM |
6550 | /* Massage our args to the form they really have. */ |
6551 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6552 | info = in_arg; |
5d1634d7 | 6553 | |
5d1634d7 AM |
6554 | htab = ppc_hash_table (info); |
6555 | ||
721956f4 | 6556 | /* Make a note of the offset within the stubs for this entry. */ |
eea6121a | 6557 | stub_entry->stub_offset = stub_entry->stub_sec->size; |
97b639ba | 6558 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; |
721956f4 | 6559 | |
4ce794b7 | 6560 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
721956f4 | 6561 | switch (stub_entry->stub_type) |
5d1634d7 | 6562 | { |
721956f4 | 6563 | case ppc_stub_long_branch: |
ad8e1ba5 | 6564 | case ppc_stub_long_branch_r2off: |
721956f4 AM |
6565 | /* Branches are relative. This is where we are going to. */ |
6566 | off = (stub_entry->target_value | |
6567 | + stub_entry->target_section->output_offset | |
6568 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 6569 | |
721956f4 AM |
6570 | /* And this is where we are coming from. */ |
6571 | off -= (stub_entry->stub_offset | |
97b639ba AM |
6572 | + stub_entry->stub_sec->output_offset |
6573 | + stub_entry->stub_sec->output_section->vma); | |
e86ce104 | 6574 | |
ad8e1ba5 AM |
6575 | if (stub_entry->stub_type != ppc_stub_long_branch_r2off) |
6576 | size = 4; | |
6577 | else | |
6578 | { | |
6579 | bfd_vma r2off; | |
6580 | ||
6581 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6582 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6583 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6584 | loc += 4; |
97b639ba | 6585 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6586 | loc += 4; |
97b639ba | 6587 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6588 | loc += 4; |
6589 | off -= 12; | |
6590 | size = 16; | |
6591 | } | |
97b639ba | 6592 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
ad8e1ba5 AM |
6593 | |
6594 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); | |
721956f4 | 6595 | break; |
e86ce104 | 6596 | |
721956f4 | 6597 | case ppc_stub_plt_branch: |
ad8e1ba5 | 6598 | case ppc_stub_plt_branch_r2off: |
721956f4 AM |
6599 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
6600 | stub_entry->root.string + 9, | |
b34976b6 | 6601 | FALSE, FALSE); |
721956f4 AM |
6602 | if (br_entry == NULL) |
6603 | { | |
6604 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), | |
6605 | stub_entry->root.string + 9); | |
b34976b6 AM |
6606 | htab->stub_error = TRUE; |
6607 | return FALSE; | |
721956f4 AM |
6608 | } |
6609 | ||
6610 | off = (stub_entry->target_value | |
6611 | + stub_entry->target_section->output_offset | |
6612 | + stub_entry->target_section->output_section->vma); | |
6613 | ||
4ce794b7 AM |
6614 | bfd_put_64 (htab->brlt->owner, off, |
6615 | htab->brlt->contents + br_entry->offset); | |
721956f4 AM |
6616 | |
6617 | if (info->shared) | |
6618 | { | |
6619 | /* Create a reloc for the branch lookup table entry. */ | |
6620 | Elf_Internal_Rela rela; | |
ad8e1ba5 | 6621 | bfd_byte *rl; |
5d1634d7 | 6622 | |
721956f4 | 6623 | rela.r_offset = (br_entry->offset |
4ce794b7 AM |
6624 | + htab->brlt->output_offset |
6625 | + htab->brlt->output_section->vma); | |
721956f4 AM |
6626 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
6627 | rela.r_addend = off; | |
6628 | ||
4ce794b7 AM |
6629 | rl = htab->relbrlt->contents; |
6630 | rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela); | |
6631 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); | |
721956f4 AM |
6632 | } |
6633 | ||
6634 | off = (br_entry->offset | |
4ce794b7 AM |
6635 | + htab->brlt->output_offset |
6636 | + htab->brlt->output_section->vma | |
6637 | - elf_gp (htab->brlt->output_section->owner) | |
ad8e1ba5 | 6638 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6639 | |
ad8e1ba5 | 6640 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
5d1634d7 AM |
6641 | { |
6642 | (*_bfd_error_handler) | |
e86ce104 | 6643 | (_("linkage table error against `%s'"), |
721956f4 | 6644 | stub_entry->root.string); |
5d1634d7 | 6645 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
6646 | htab->stub_error = TRUE; |
6647 | return FALSE; | |
5d1634d7 | 6648 | } |
41bd81ab | 6649 | |
721956f4 | 6650 | indx = off; |
ad8e1ba5 AM |
6651 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
6652 | { | |
97b639ba | 6653 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6654 | loc += 4; |
97b639ba | 6655 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 AM |
6656 | size = 16; |
6657 | } | |
6658 | else | |
6659 | { | |
6660 | bfd_vma r2off; | |
6661 | ||
6662 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6663 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6664 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6665 | loc += 4; |
97b639ba | 6666 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6667 | loc += 4; |
97b639ba | 6668 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 | 6669 | loc += 4; |
97b639ba | 6670 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6671 | loc += 4; |
97b639ba | 6672 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6673 | size = 28; |
6674 | } | |
6675 | loc += 4; | |
97b639ba | 6676 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
ad8e1ba5 | 6677 | loc += 4; |
97b639ba | 6678 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
721956f4 | 6679 | break; |
5d1634d7 | 6680 | |
721956f4 | 6681 | case ppc_stub_plt_call: |
c862ae31 AM |
6682 | /* Do the best we can for shared libraries built without |
6683 | exporting ".foo" for each "foo". This can happen when symbol | |
6684 | versioning scripts strip all bar a subset of symbols. */ | |
8387904d AM |
6685 | if (stub_entry->h->oh != NULL |
6686 | && stub_entry->h->oh->elf.root.type != bfd_link_hash_defined | |
34814b9f | 6687 | && stub_entry->h->oh->elf.root.type != bfd_link_hash_defweak) |
c862ae31 AM |
6688 | { |
6689 | /* Point the symbol at the stub. There may be multiple stubs, | |
6690 | we don't really care; The main thing is to make this sym | |
8f3bab57 AM |
6691 | defined somewhere. Maybe defining the symbol in the stub |
6692 | section is a silly idea. If we didn't do this, htab->top_id | |
6693 | could disappear. */ | |
34814b9f AM |
6694 | stub_entry->h->oh->elf.root.type = bfd_link_hash_defined; |
6695 | stub_entry->h->oh->elf.root.u.def.section = stub_entry->stub_sec; | |
6696 | stub_entry->h->oh->elf.root.u.def.value = stub_entry->stub_offset; | |
c862ae31 AM |
6697 | } |
6698 | ||
721956f4 | 6699 | /* Now build the stub. */ |
411e1bfb AM |
6700 | off = (bfd_vma) -1; |
6701 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) | |
6702 | if (ent->addend == stub_entry->addend) | |
6703 | { | |
6704 | off = ent->plt.offset; | |
6705 | break; | |
6706 | } | |
721956f4 AM |
6707 | if (off >= (bfd_vma) -2) |
6708 | abort (); | |
6709 | ||
6710 | off &= ~ (bfd_vma) 1; | |
4ce794b7 AM |
6711 | off += (htab->plt->output_offset |
6712 | + htab->plt->output_section->vma | |
6713 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6714 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6715 | |
ad8e1ba5 | 6716 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
721956f4 AM |
6717 | { |
6718 | (*_bfd_error_handler) | |
6719 | (_("linkage table error against `%s'"), | |
6720 | stub_entry->h->elf.root.root.string); | |
6721 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 AM |
6722 | htab->stub_error = TRUE; |
6723 | return FALSE; | |
721956f4 AM |
6724 | } |
6725 | ||
97b639ba | 6726 | p = build_plt_stub (htab->stub_bfd, loc, off); |
721956f4 AM |
6727 | size = p - loc; |
6728 | break; | |
6729 | ||
6730 | default: | |
6731 | BFD_FAIL (); | |
b34976b6 | 6732 | return FALSE; |
721956f4 AM |
6733 | } |
6734 | ||
eea6121a | 6735 | stub_entry->stub_sec->size += size; |
97b639ba AM |
6736 | |
6737 | if (htab->emit_stub_syms | |
6738 | && !(stub_entry->stub_type == ppc_stub_plt_call | |
8387904d | 6739 | && stub_entry->h->oh != NULL |
34814b9f AM |
6740 | && stub_entry->h->oh->elf.root.type == bfd_link_hash_defined |
6741 | && stub_entry->h->oh->elf.root.u.def.section == stub_entry->stub_sec | |
6742 | && stub_entry->h->oh->elf.root.u.def.value == stub_entry->stub_offset)) | |
97b639ba AM |
6743 | { |
6744 | struct elf_link_hash_entry *h; | |
6745 | h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string, | |
6746 | TRUE, FALSE, FALSE); | |
6747 | if (h == NULL) | |
6748 | return FALSE; | |
6749 | if (h->root.type == bfd_link_hash_new) | |
6750 | { | |
6751 | h->root.type = bfd_link_hash_defined; | |
6752 | h->root.u.def.section = stub_entry->stub_sec; | |
6753 | h->root.u.def.value = stub_entry->stub_offset; | |
6754 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
6755 | | ELF_LINK_HASH_DEF_REGULAR | |
6756 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
6757 | | ELF_LINK_FORCED_LOCAL); | |
6758 | } | |
6759 | } | |
6760 | ||
b34976b6 | 6761 | return TRUE; |
721956f4 AM |
6762 | } |
6763 | ||
6764 | /* As above, but don't actually build the stub. Just bump offset so | |
6765 | we know stub section sizes, and select plt_branch stubs where | |
6766 | long_branch stubs won't do. */ | |
6767 | ||
b34976b6 | 6768 | static bfd_boolean |
4ce794b7 | 6769 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
721956f4 AM |
6770 | { |
6771 | struct ppc_stub_hash_entry *stub_entry; | |
63bc6f6c | 6772 | struct bfd_link_info *info; |
721956f4 AM |
6773 | struct ppc_link_hash_table *htab; |
6774 | bfd_vma off; | |
6775 | int size; | |
6776 | ||
6777 | /* Massage our args to the form they really have. */ | |
6778 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
63bc6f6c AM |
6779 | info = in_arg; |
6780 | ||
6781 | htab = ppc_hash_table (info); | |
721956f4 AM |
6782 | |
6783 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
6784 | { | |
411e1bfb | 6785 | struct plt_entry *ent; |
58ac9f71 | 6786 | off = (bfd_vma) -1; |
411e1bfb AM |
6787 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
6788 | if (ent->addend == stub_entry->addend) | |
6789 | { | |
6790 | off = ent->plt.offset & ~(bfd_vma) 1; | |
6791 | break; | |
6792 | } | |
58ac9f71 | 6793 | if (off >= (bfd_vma) -2) |
411e1bfb | 6794 | abort (); |
4ce794b7 AM |
6795 | off += (htab->plt->output_offset |
6796 | + htab->plt->output_section->vma | |
6797 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6798 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6799 | |
ad8e1ba5 | 6800 | size = PLT_CALL_STUB_SIZE; |
4ce794b7 | 6801 | if (PPC_HA (off + 16) != PPC_HA (off)) |
721956f4 AM |
6802 | size += 4; |
6803 | } | |
6804 | else | |
6805 | { | |
ad8e1ba5 AM |
6806 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
6807 | variants. */ | |
721956f4 AM |
6808 | off = (stub_entry->target_value |
6809 | + stub_entry->target_section->output_offset | |
6810 | + stub_entry->target_section->output_section->vma); | |
eea6121a | 6811 | off -= (stub_entry->stub_sec->size |
721956f4 AM |
6812 | + stub_entry->stub_sec->output_offset |
6813 | + stub_entry->stub_sec->output_section->vma); | |
6814 | ||
ad8e1ba5 AM |
6815 | /* Reset the stub type from the plt variant in case we now |
6816 | can reach with a shorter stub. */ | |
6817 | if (stub_entry->stub_type >= ppc_stub_plt_branch) | |
6818 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; | |
6819 | ||
6820 | size = 4; | |
6821 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
6822 | { | |
6823 | off -= 12; | |
6824 | size = 16; | |
6825 | } | |
6826 | ||
6827 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ | |
721956f4 AM |
6828 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
6829 | { | |
6830 | struct ppc_branch_hash_entry *br_entry; | |
6831 | ||
6832 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
6833 | stub_entry->root.string + 9, | |
b34976b6 | 6834 | TRUE, FALSE); |
721956f4 AM |
6835 | if (br_entry == NULL) |
6836 | { | |
6837 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), | |
6838 | stub_entry->root.string + 9); | |
b34976b6 AM |
6839 | htab->stub_error = TRUE; |
6840 | return FALSE; | |
721956f4 AM |
6841 | } |
6842 | ||
6843 | if (br_entry->iter != htab->stub_iteration) | |
6844 | { | |
6845 | br_entry->iter = htab->stub_iteration; | |
eea6121a AM |
6846 | br_entry->offset = htab->brlt->size; |
6847 | htab->brlt->size += 8; | |
63bc6f6c AM |
6848 | |
6849 | if (info->shared) | |
eea6121a | 6850 | htab->relbrlt->size += sizeof (Elf64_External_Rela); |
721956f4 | 6851 | } |
ad8e1ba5 AM |
6852 | |
6853 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | |
721956f4 | 6854 | size = 16; |
ad8e1ba5 AM |
6855 | if (stub_entry->stub_type != ppc_stub_plt_branch) |
6856 | size = 28; | |
721956f4 AM |
6857 | } |
6858 | } | |
6859 | ||
eea6121a | 6860 | stub_entry->stub_sec->size += size; |
b34976b6 | 6861 | return TRUE; |
721956f4 AM |
6862 | } |
6863 | ||
6864 | /* Set up various things so that we can make a list of input sections | |
6865 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 6866 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
6867 | |
6868 | int | |
4ce794b7 | 6869 | ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
721956f4 AM |
6870 | { |
6871 | bfd *input_bfd; | |
734b6cf9 | 6872 | int top_id, top_index, id; |
721956f4 | 6873 | asection *section; |
734b6cf9 | 6874 | asection **input_list; |
721956f4 AM |
6875 | bfd_size_type amt; |
6876 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6877 | ||
4ce794b7 | 6878 | if (htab->brlt == NULL) |
721956f4 AM |
6879 | return 0; |
6880 | ||
1e2f5b6e | 6881 | /* Find the top input section id. */ |
3d6f9012 | 6882 | for (input_bfd = info->input_bfds, top_id = 3; |
721956f4 AM |
6883 | input_bfd != NULL; |
6884 | input_bfd = input_bfd->link_next) | |
6885 | { | |
721956f4 AM |
6886 | for (section = input_bfd->sections; |
6887 | section != NULL; | |
6888 | section = section->next) | |
6889 | { | |
6890 | if (top_id < section->id) | |
6891 | top_id = section->id; | |
6892 | } | |
6893 | } | |
721956f4 | 6894 | |
8f3bab57 | 6895 | htab->top_id = top_id; |
721956f4 | 6896 | amt = sizeof (struct map_stub) * (top_id + 1); |
4ce794b7 | 6897 | htab->stub_group = bfd_zmalloc (amt); |
721956f4 AM |
6898 | if (htab->stub_group == NULL) |
6899 | return -1; | |
6900 | ||
3d6f9012 AM |
6901 | /* Set toc_off for com, und, abs and ind sections. */ |
6902 | for (id = 0; id < 3; id++) | |
6903 | htab->stub_group[id].toc_off = TOC_BASE_OFF; | |
721956f4 | 6904 | |
3d6f9012 | 6905 | elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd); |
734b6cf9 AM |
6906 | |
6907 | /* We can't use output_bfd->section_count here to find the top output | |
6908 | section index as some sections may have been removed, and | |
6909 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
6910 | for (section = output_bfd->sections, top_index = 0; | |
6911 | section != NULL; | |
6912 | section = section->next) | |
6913 | { | |
6914 | if (top_index < section->index) | |
6915 | top_index = section->index; | |
6916 | } | |
6917 | ||
6918 | htab->top_index = top_index; | |
6919 | amt = sizeof (asection *) * (top_index + 1); | |
4ce794b7 | 6920 | input_list = bfd_zmalloc (amt); |
734b6cf9 AM |
6921 | htab->input_list = input_list; |
6922 | if (input_list == NULL) | |
6923 | return -1; | |
6924 | ||
721956f4 AM |
6925 | return 1; |
6926 | } | |
6927 | ||
e717da7e AM |
6928 | /* The linker repeatedly calls this function for each TOC input section |
6929 | and linker generated GOT section. Group input bfds such that the toc | |
6930 | within a group is less than 64k in size. Will break with cute linker | |
6931 | scripts that play games with dot in the output toc section. */ | |
ad8e1ba5 AM |
6932 | |
6933 | void | |
4ce794b7 | 6934 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
ad8e1ba5 AM |
6935 | { |
6936 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
99877b66 AM |
6937 | bfd_vma addr = isec->output_offset + isec->output_section->vma; |
6938 | bfd_vma off = addr - htab->toc_curr; | |
ad8e1ba5 | 6939 | |
99877b66 AM |
6940 | if (off + isec->size > 0x10000) |
6941 | htab->toc_curr = addr; | |
6942 | ||
6943 | elf_gp (isec->owner) = (htab->toc_curr | |
6944 | - elf_gp (isec->output_section->owner) | |
6945 | + TOC_BASE_OFF); | |
ad8e1ba5 AM |
6946 | } |
6947 | ||
6948 | /* Called after the last call to the above function. */ | |
6949 | ||
6950 | void | |
4ce794b7 AM |
6951 | ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED, |
6952 | struct bfd_link_info *info) | |
ad8e1ba5 AM |
6953 | { |
6954 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
ad8e1ba5 AM |
6955 | |
6956 | /* toc_curr tracks the TOC offset used for code sections below in | |
6957 | ppc64_elf_next_input_section. Start off at 0x8000. */ | |
3d6f9012 | 6958 | htab->toc_curr = TOC_BASE_OFF; |
ad8e1ba5 AM |
6959 | } |
6960 | ||
9b5ecbd0 AM |
6961 | /* No toc references were found in ISEC. If the code in ISEC makes no |
6962 | calls, then there's no need to use toc adjusting stubs when branching | |
6963 | into ISEC. Actually, indirect calls from ISEC are OK as they will | |
6964 | load r2. */ | |
6965 | ||
6966 | static int | |
4ce794b7 | 6967 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
9b5ecbd0 AM |
6968 | { |
6969 | bfd_byte *contents; | |
6970 | bfd_size_type i; | |
6971 | int ret; | |
6972 | int branch_ok; | |
6973 | ||
772119ce AM |
6974 | /* We know none of our code bearing sections will need toc stubs. */ |
6975 | if ((isec->flags & SEC_LINKER_CREATED) != 0) | |
6976 | return 0; | |
6977 | ||
eea6121a | 6978 | if (isec->size == 0) |
082c50f8 AM |
6979 | return 0; |
6980 | ||
9b5ecbd0 AM |
6981 | /* Hack for linux kernel. .fixup contains branches, but only back to |
6982 | the function that hit an exception. */ | |
6983 | branch_ok = strcmp (isec->name, ".fixup") == 0; | |
6984 | ||
6985 | contents = elf_section_data (isec)->this_hdr.contents; | |
6986 | if (contents == NULL) | |
6987 | { | |
eea6121a | 6988 | if (!bfd_malloc_and_get_section (isec->owner, isec, &contents)) |
9b5ecbd0 | 6989 | { |
eea6121a AM |
6990 | if (contents != NULL) |
6991 | free (contents); | |
9b5ecbd0 AM |
6992 | return -1; |
6993 | } | |
6994 | if (info->keep_memory) | |
6995 | elf_section_data (isec)->this_hdr.contents = contents; | |
6996 | } | |
6997 | ||
6998 | /* Code scan, because we don't necessarily have relocs on calls to | |
6999 | static functions. */ | |
7000 | ret = 0; | |
eea6121a | 7001 | for (i = 0; i < isec->size; i += 4) |
9b5ecbd0 AM |
7002 | { |
7003 | unsigned long insn = bfd_get_32 (isec->owner, contents + i); | |
7004 | /* Is this a branch? */ | |
772119ce | 7005 | if ((insn & (0x3f << 26)) == (18 << 26) |
9b5ecbd0 AM |
7006 | /* If branch and link, it's a function call. */ |
7007 | && ((insn & 1) != 0 | |
7008 | /* Sibling calls use a plain branch. I don't know a way | |
7009 | of deciding whether a branch is really a sibling call. */ | |
7010 | || !branch_ok)) | |
7011 | { | |
7012 | ret = 1; | |
7013 | break; | |
7014 | } | |
7015 | } | |
7016 | ||
7017 | if (elf_section_data (isec)->this_hdr.contents != contents) | |
7018 | free (contents); | |
7019 | return ret; | |
7020 | } | |
7021 | ||
721956f4 AM |
7022 | /* The linker repeatedly calls this function for each input section, |
7023 | in the order that input sections are linked into output sections. | |
7024 | Build lists of input sections to determine groupings between which | |
7025 | we may insert linker stubs. */ | |
7026 | ||
9b5ecbd0 | 7027 | bfd_boolean |
4ce794b7 | 7028 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
721956f4 AM |
7029 | { |
7030 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
9b5ecbd0 | 7031 | int ret; |
721956f4 | 7032 | |
734b6cf9 AM |
7033 | if ((isec->output_section->flags & SEC_CODE) != 0 |
7034 | && isec->output_section->index <= htab->top_index) | |
721956f4 | 7035 | { |
734b6cf9 | 7036 | asection **list = htab->input_list + isec->output_section->index; |
3d6f9012 | 7037 | /* Steal the link_sec pointer for our list. */ |
721956f4 | 7038 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3d6f9012 AM |
7039 | /* This happens to make the list in reverse order, |
7040 | which is what we want. */ | |
734b6cf9 AM |
7041 | PREV_SEC (isec) = *list; |
7042 | *list = isec; | |
721956f4 | 7043 | } |
ad8e1ba5 AM |
7044 | |
7045 | /* If a code section has a function that uses the TOC then we need | |
7046 | to use the right TOC (obviously). Also, make sure that .opd gets | |
ee87f2da AM |
7047 | the correct TOC value for R_PPC64_TOC relocs that don't have or |
7048 | can't find their function symbol (shouldn't ever happen now). */ | |
ad8e1ba5 | 7049 | if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0) |
9b5ecbd0 AM |
7050 | { |
7051 | if (elf_gp (isec->owner) != 0) | |
7052 | htab->toc_curr = elf_gp (isec->owner); | |
7053 | } | |
7054 | else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0) | |
7055 | return FALSE; | |
7056 | else | |
7057 | isec->has_gp_reloc = ret; | |
ad8e1ba5 AM |
7058 | |
7059 | /* Functions that don't use the TOC can belong in any TOC group. | |
7060 | Use the last TOC base. This happens to make _init and _fini | |
7061 | pasting work. */ | |
7062 | htab->stub_group[isec->id].toc_off = htab->toc_curr; | |
9b5ecbd0 | 7063 | return TRUE; |
721956f4 AM |
7064 | } |
7065 | ||
7066 | /* See whether we can group stub sections together. Grouping stub | |
7067 | sections may result in fewer stubs. More importantly, we need to | |
7068 | put all .init* and .fini* stubs at the beginning of the .init or | |
7069 | .fini output sections respectively, because glibc splits the | |
7070 | _init and _fini functions into multiple parts. Putting a stub in | |
7071 | the middle of a function is not a good idea. */ | |
7072 | ||
7073 | static void | |
4ce794b7 AM |
7074 | group_sections (struct ppc_link_hash_table *htab, |
7075 | bfd_size_type stub_group_size, | |
7076 | bfd_boolean stubs_always_before_branch) | |
721956f4 | 7077 | { |
734b6cf9 AM |
7078 | asection **list = htab->input_list + htab->top_index; |
7079 | do | |
721956f4 | 7080 | { |
734b6cf9 AM |
7081 | asection *tail = *list; |
7082 | while (tail != NULL) | |
721956f4 | 7083 | { |
734b6cf9 AM |
7084 | asection *curr; |
7085 | asection *prev; | |
7086 | bfd_size_type total; | |
7087 | bfd_boolean big_sec; | |
7088 | bfd_vma curr_toc; | |
7089 | ||
7090 | curr = tail; | |
eea6121a | 7091 | total = tail->size; |
734b6cf9 AM |
7092 | big_sec = total >= stub_group_size; |
7093 | curr_toc = htab->stub_group[tail->id].toc_off; | |
7094 | ||
7095 | while ((prev = PREV_SEC (curr)) != NULL | |
7096 | && ((total += curr->output_offset - prev->output_offset) | |
ad8e1ba5 AM |
7097 | < stub_group_size) |
7098 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
734b6cf9 AM |
7099 | curr = prev; |
7100 | ||
7101 | /* OK, the size from the start of CURR to the end is less | |
7102 | than stub_group_size and thus can be handled by one stub | |
7103 | section. (or the tail section is itself larger than | |
7104 | stub_group_size, in which case we may be toast.) We | |
7105 | should really be keeping track of the total size of stubs | |
7106 | added here, as stubs contribute to the final output | |
7107 | section size. That's a little tricky, and this way will | |
7108 | only break if stubs added make the total size more than | |
7109 | 2^25, ie. for the default stub_group_size, if stubs total | |
7110 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ | |
7111 | do | |
721956f4 AM |
7112 | { |
7113 | prev = PREV_SEC (tail); | |
734b6cf9 | 7114 | /* Set up this stub group. */ |
721956f4 AM |
7115 | htab->stub_group[tail->id].link_sec = curr; |
7116 | } | |
734b6cf9 AM |
7117 | while (tail != curr && (tail = prev) != NULL); |
7118 | ||
7119 | /* But wait, there's more! Input sections up to stub_group_size | |
7120 | bytes before the stub section can be handled by it too. | |
7121 | Don't do this if we have a really large section after the | |
7122 | stubs, as adding more stubs increases the chance that | |
7123 | branches may not reach into the stub section. */ | |
7124 | if (!stubs_always_before_branch && !big_sec) | |
7125 | { | |
7126 | total = 0; | |
7127 | while (prev != NULL | |
7128 | && ((total += tail->output_offset - prev->output_offset) | |
7129 | < stub_group_size) | |
7130 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
7131 | { | |
7132 | tail = prev; | |
7133 | prev = PREV_SEC (tail); | |
7134 | htab->stub_group[tail->id].link_sec = curr; | |
7135 | } | |
7136 | } | |
7137 | tail = prev; | |
721956f4 AM |
7138 | } |
7139 | } | |
734b6cf9 AM |
7140 | while (list-- != htab->input_list); |
7141 | free (htab->input_list); | |
721956f4 AM |
7142 | #undef PREV_SEC |
7143 | } | |
7144 | ||
721956f4 AM |
7145 | /* Determine and set the size of the stub section for a final link. |
7146 | ||
7147 | The basic idea here is to examine all the relocations looking for | |
7148 | PC-relative calls to a target that is unreachable with a "bl" | |
7149 | instruction. */ | |
7150 | ||
b34976b6 | 7151 | bfd_boolean |
4ce794b7 | 7152 | ppc64_elf_size_stubs (bfd *output_bfd, |
4ce794b7 AM |
7153 | struct bfd_link_info *info, |
7154 | bfd_signed_vma group_size, | |
7155 | asection *(*add_stub_section) (const char *, asection *), | |
7156 | void (*layout_sections_again) (void)) | |
721956f4 AM |
7157 | { |
7158 | bfd_size_type stub_group_size; | |
b34976b6 | 7159 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
7160 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
7161 | ||
7162 | /* Stash our params away. */ | |
721956f4 AM |
7163 | htab->add_stub_section = add_stub_section; |
7164 | htab->layout_sections_again = layout_sections_again; | |
7165 | stubs_always_before_branch = group_size < 0; | |
7166 | if (group_size < 0) | |
7167 | stub_group_size = -group_size; | |
7168 | else | |
7169 | stub_group_size = group_size; | |
7170 | if (stub_group_size == 1) | |
7171 | { | |
7172 | /* Default values. */ | |
58ac9f71 AM |
7173 | if (stubs_always_before_branch) |
7174 | { | |
7175 | stub_group_size = 0x1e00000; | |
7176 | if (htab->has_14bit_branch) | |
7177 | stub_group_size = 0x7800; | |
7178 | } | |
7179 | else | |
7180 | { | |
7181 | stub_group_size = 0x1c00000; | |
7182 | if (htab->has_14bit_branch) | |
7183 | stub_group_size = 0x7000; | |
7184 | } | |
721956f4 AM |
7185 | } |
7186 | ||
7187 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
7188 | ||
721956f4 AM |
7189 | while (1) |
7190 | { | |
7191 | bfd *input_bfd; | |
7192 | unsigned int bfd_indx; | |
7193 | asection *stub_sec; | |
b34976b6 | 7194 | bfd_boolean stub_changed; |
721956f4 AM |
7195 | |
7196 | htab->stub_iteration += 1; | |
b34976b6 | 7197 | stub_changed = FALSE; |
721956f4 AM |
7198 | |
7199 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
7200 | input_bfd != NULL; | |
7201 | input_bfd = input_bfd->link_next, bfd_indx++) | |
7202 | { | |
7203 | Elf_Internal_Shdr *symtab_hdr; | |
7204 | asection *section; | |
6cdc0ccc | 7205 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 AM |
7206 | |
7207 | /* We'll need the symbol table in a second. */ | |
7208 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
7209 | if (symtab_hdr->sh_info == 0) | |
7210 | continue; | |
7211 | ||
721956f4 AM |
7212 | /* Walk over each section attached to the input bfd. */ |
7213 | for (section = input_bfd->sections; | |
7214 | section != NULL; | |
7215 | section = section->next) | |
7216 | { | |
721956f4 | 7217 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
7218 | |
7219 | /* If there aren't any relocs, then there's nothing more | |
7220 | to do. */ | |
7221 | if ((section->flags & SEC_RELOC) == 0 | |
7222 | || section->reloc_count == 0) | |
7223 | continue; | |
7224 | ||
7225 | /* If this section is a link-once section that will be | |
7226 | discarded, then don't create any stubs. */ | |
7227 | if (section->output_section == NULL | |
7228 | || section->output_section->owner != output_bfd) | |
7229 | continue; | |
7230 | ||
1e2f5b6e AM |
7231 | /* Get the relocs. */ |
7232 | internal_relocs | |
4ce794b7 | 7233 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 7234 | info->keep_memory); |
721956f4 | 7235 | if (internal_relocs == NULL) |
1e2f5b6e | 7236 | goto error_ret_free_local; |
721956f4 AM |
7237 | |
7238 | /* Now examine each relocation. */ | |
7239 | irela = internal_relocs; | |
7240 | irelaend = irela + section->reloc_count; | |
7241 | for (; irela < irelaend; irela++) | |
7242 | { | |
4ce794b7 AM |
7243 | enum elf_ppc64_reloc_type r_type; |
7244 | unsigned int r_indx; | |
721956f4 AM |
7245 | enum ppc_stub_type stub_type; |
7246 | struct ppc_stub_hash_entry *stub_entry; | |
8387904d | 7247 | asection *sym_sec, *code_sec; |
721956f4 AM |
7248 | bfd_vma sym_value; |
7249 | bfd_vma destination; | |
8843416a | 7250 | bfd_boolean ok_dest; |
721956f4 | 7251 | struct ppc_link_hash_entry *hash; |
8387904d | 7252 | struct ppc_link_hash_entry *fdh; |
411e1bfb AM |
7253 | struct elf_link_hash_entry *h; |
7254 | Elf_Internal_Sym *sym; | |
721956f4 AM |
7255 | char *stub_name; |
7256 | const asection *id_sec; | |
8387904d | 7257 | long *opd_adjust; |
721956f4 AM |
7258 | |
7259 | r_type = ELF64_R_TYPE (irela->r_info); | |
7260 | r_indx = ELF64_R_SYM (irela->r_info); | |
7261 | ||
4ce794b7 | 7262 | if (r_type >= R_PPC64_max) |
721956f4 AM |
7263 | { |
7264 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 7265 | goto error_ret_free_internal; |
721956f4 AM |
7266 | } |
7267 | ||
7268 | /* Only look for stubs on branch instructions. */ | |
4ce794b7 AM |
7269 | if (r_type != R_PPC64_REL24 |
7270 | && r_type != R_PPC64_REL14 | |
7271 | && r_type != R_PPC64_REL14_BRTAKEN | |
7272 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
721956f4 AM |
7273 | continue; |
7274 | ||
7275 | /* Now determine the call target, its name, value, | |
7276 | section. */ | |
411e1bfb AM |
7277 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
7278 | r_indx, input_bfd)) | |
7279 | goto error_ret_free_internal; | |
7280 | hash = (struct ppc_link_hash_entry *) h; | |
7281 | ||
8843416a | 7282 | ok_dest = FALSE; |
8387904d | 7283 | fdh = NULL; |
411e1bfb | 7284 | if (hash == NULL) |
721956f4 | 7285 | { |
411e1bfb | 7286 | sym_value = sym->st_value; |
8843416a | 7287 | ok_dest = TRUE; |
721956f4 AM |
7288 | } |
7289 | else | |
7290 | { | |
411e1bfb | 7291 | sym_value = 0; |
99877b66 AM |
7292 | /* Recognise an old ABI func code entry sym, and |
7293 | use the func descriptor sym instead. */ | |
7294 | if (hash->elf.root.type == bfd_link_hash_undefweak | |
8387904d AM |
7295 | && hash->elf.root.root.string[0] == '.' |
7296 | && (fdh = get_fdh (hash, htab)) != NULL) | |
7297 | { | |
8387904d AM |
7298 | if (fdh->elf.root.type == bfd_link_hash_defined |
7299 | || fdh->elf.root.type == bfd_link_hash_defweak) | |
7300 | { | |
7301 | sym_sec = fdh->elf.root.u.def.section; | |
7302 | sym_value = fdh->elf.root.u.def.value; | |
7303 | if (sym_sec->output_section != NULL) | |
7304 | ok_dest = TRUE; | |
7305 | } | |
99877b66 AM |
7306 | else |
7307 | fdh = NULL; | |
8387904d AM |
7308 | } |
7309 | else if (hash->elf.root.type == bfd_link_hash_defined | |
7310 | || hash->elf.root.type == bfd_link_hash_defweak) | |
721956f4 | 7311 | { |
721956f4 AM |
7312 | sym_value = hash->elf.root.u.def.value; |
7313 | if (sym_sec->output_section != NULL) | |
8843416a | 7314 | ok_dest = TRUE; |
721956f4 AM |
7315 | } |
7316 | else if (hash->elf.root.type == bfd_link_hash_undefweak) | |
7317 | ; | |
7318 | else if (hash->elf.root.type == bfd_link_hash_undefined) | |
7319 | ; | |
7320 | else | |
7321 | { | |
7322 | bfd_set_error (bfd_error_bad_value); | |
7323 | goto error_ret_free_internal; | |
7324 | } | |
7325 | } | |
7326 | ||
8843416a AM |
7327 | destination = 0; |
7328 | if (ok_dest) | |
7329 | { | |
7330 | sym_value += irela->r_addend; | |
7331 | destination = (sym_value | |
7332 | + sym_sec->output_offset | |
7333 | + sym_sec->output_section->vma); | |
7334 | } | |
7335 | ||
8387904d AM |
7336 | code_sec = sym_sec; |
7337 | opd_adjust = get_opd_info (sym_sec); | |
7338 | if (opd_adjust != NULL) | |
7339 | { | |
7340 | bfd_vma dest; | |
7341 | ||
7342 | if (hash == NULL) | |
7343 | { | |
7344 | long adjust = opd_adjust[sym_value / 24]; | |
7345 | if (adjust == -1) | |
7346 | continue; | |
7347 | sym_value += adjust; | |
7348 | } | |
7349 | dest = opd_entry_value (sym_sec, sym_value, | |
7350 | &code_sec, &sym_value); | |
7351 | if (dest != (bfd_vma) -1) | |
7352 | { | |
7353 | destination = dest; | |
7354 | if (fdh != NULL) | |
7355 | { | |
7356 | /* Fixup old ABI sym to point at code | |
7357 | entry. */ | |
99877b66 | 7358 | hash->elf.root.type = bfd_link_hash_defweak; |
8387904d AM |
7359 | hash->elf.root.u.def.section = code_sec; |
7360 | hash->elf.root.u.def.value = sym_value; | |
7361 | } | |
7362 | } | |
7363 | } | |
7364 | ||
721956f4 AM |
7365 | /* Determine what (if any) linker stub is needed. */ |
7366 | stub_type = ppc_type_of_stub (section, irela, &hash, | |
7367 | destination); | |
ad8e1ba5 AM |
7368 | |
7369 | if (stub_type != ppc_stub_plt_call) | |
7370 | { | |
7371 | /* Check whether we need a TOC adjusting stub. | |
7372 | Since the linker pastes together pieces from | |
7373 | different object files when creating the | |
7374 | _init and _fini functions, it may be that a | |
7375 | call to what looks like a local sym is in | |
7376 | fact a call needing a TOC adjustment. */ | |
8387904d AM |
7377 | if (code_sec != NULL |
7378 | && code_sec->output_section != NULL | |
7379 | && (htab->stub_group[code_sec->id].toc_off | |
9b5ecbd0 | 7380 | != htab->stub_group[section->id].toc_off) |
8387904d | 7381 | && code_sec->has_gp_reloc |
9b5ecbd0 | 7382 | && section->has_gp_reloc) |
ad8e1ba5 AM |
7383 | stub_type = ppc_stub_long_branch_r2off; |
7384 | } | |
7385 | ||
721956f4 AM |
7386 | if (stub_type == ppc_stub_none) |
7387 | continue; | |
7388 | ||
411e1bfb AM |
7389 | /* __tls_get_addr calls might be eliminated. */ |
7390 | if (stub_type != ppc_stub_plt_call | |
7391 | && hash != NULL | |
8387904d AM |
7392 | && (hash == htab->tls_get_addr |
7393 | || hash == htab->tls_get_addr_fd) | |
411e1bfb AM |
7394 | && section->has_tls_reloc |
7395 | && irela != internal_relocs) | |
7396 | { | |
7397 | /* Get tls info. */ | |
e7b938ca | 7398 | char *tls_mask; |
411e1bfb | 7399 | |
0d4792f7 | 7400 | if (!get_tls_mask (&tls_mask, NULL, &local_syms, |
411e1bfb AM |
7401 | irela - 1, input_bfd)) |
7402 | goto error_ret_free_internal; | |
e7b938ca | 7403 | if (*tls_mask != 0) |
411e1bfb AM |
7404 | continue; |
7405 | } | |
7406 | ||
721956f4 AM |
7407 | /* Support for grouping stub sections. */ |
7408 | id_sec = htab->stub_group[section->id].link_sec; | |
7409 | ||
7410 | /* Get the name of this stub. */ | |
7411 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
7412 | if (!stub_name) | |
7413 | goto error_ret_free_internal; | |
7414 | ||
7415 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 7416 | stub_name, FALSE, FALSE); |
721956f4 AM |
7417 | if (stub_entry != NULL) |
7418 | { | |
7419 | /* The proper stub has already been created. */ | |
7420 | free (stub_name); | |
7421 | continue; | |
7422 | } | |
7423 | ||
7424 | stub_entry = ppc_add_stub (stub_name, section, htab); | |
7425 | if (stub_entry == NULL) | |
7426 | { | |
7427 | free (stub_name); | |
6cdc0ccc AM |
7428 | error_ret_free_internal: |
7429 | if (elf_section_data (section)->relocs == NULL) | |
7430 | free (internal_relocs); | |
7431 | error_ret_free_local: | |
7432 | if (local_syms != NULL | |
7433 | && (symtab_hdr->contents | |
7434 | != (unsigned char *) local_syms)) | |
7435 | free (local_syms); | |
b34976b6 | 7436 | return FALSE; |
721956f4 AM |
7437 | } |
7438 | ||
ad8e1ba5 | 7439 | stub_entry->stub_type = stub_type; |
721956f4 | 7440 | stub_entry->target_value = sym_value; |
8387904d | 7441 | stub_entry->target_section = code_sec; |
721956f4 | 7442 | stub_entry->h = hash; |
411e1bfb | 7443 | stub_entry->addend = irela->r_addend; |
b34976b6 | 7444 | stub_changed = TRUE; |
721956f4 AM |
7445 | } |
7446 | ||
7447 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 7448 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 7449 | free (internal_relocs); |
721956f4 | 7450 | } |
6cdc0ccc AM |
7451 | |
7452 | if (local_syms != NULL | |
7453 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
7454 | { | |
7455 | if (!info->keep_memory) | |
7456 | free (local_syms); | |
7457 | else | |
7458 | symtab_hdr->contents = (unsigned char *) local_syms; | |
7459 | } | |
721956f4 AM |
7460 | } |
7461 | ||
7462 | if (!stub_changed) | |
7463 | break; | |
7464 | ||
7465 | /* OK, we've added some stubs. Find out the new size of the | |
7466 | stub sections. */ | |
7467 | for (stub_sec = htab->stub_bfd->sections; | |
7468 | stub_sec != NULL; | |
7469 | stub_sec = stub_sec->next) | |
e717da7e | 7470 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
eea6121a AM |
7471 | stub_sec->size = 0; |
7472 | ||
7473 | htab->brlt->size = 0; | |
63bc6f6c | 7474 | if (info->shared) |
eea6121a | 7475 | htab->relbrlt->size = 0; |
721956f4 | 7476 | |
63bc6f6c | 7477 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info); |
721956f4 AM |
7478 | |
7479 | /* Ask the linker to do its stuff. */ | |
7480 | (*htab->layout_sections_again) (); | |
7481 | } | |
7482 | ||
afbe61cf AM |
7483 | /* It would be nice to strip .branch_lt from the output if the |
7484 | section is empty, but it's too late. If we strip sections here, | |
7485 | the dynamic symbol table is corrupted since the section symbol | |
7486 | for the stripped section isn't written. */ | |
721956f4 | 7487 | |
b34976b6 | 7488 | return TRUE; |
721956f4 AM |
7489 | } |
7490 | ||
7491 | /* Called after we have determined section placement. If sections | |
805fc799 | 7492 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 7493 | |
805fc799 | 7494 | bfd_vma |
4ce794b7 | 7495 | ppc64_elf_toc (bfd *obfd) |
721956f4 | 7496 | { |
805fc799 AM |
7497 | asection *s; |
7498 | bfd_vma TOCstart; | |
721956f4 | 7499 | |
805fc799 AM |
7500 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
7501 | order. The TOC starts where the first of these sections starts. */ | |
7502 | s = bfd_get_section_by_name (obfd, ".got"); | |
7503 | if (s == NULL) | |
7504 | s = bfd_get_section_by_name (obfd, ".toc"); | |
7505 | if (s == NULL) | |
7506 | s = bfd_get_section_by_name (obfd, ".tocbss"); | |
7507 | if (s == NULL) | |
7508 | s = bfd_get_section_by_name (obfd, ".plt"); | |
7509 | if (s == NULL) | |
7510 | { | |
7511 | /* This may happen for | |
7512 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
7513 | .toc directive | |
7514 | o bad linker script | |
7515 | o --gc-sections and empty TOC sections | |
7516 | ||
7517 | FIXME: Warn user? */ | |
7518 | ||
7519 | /* Look for a likely section. We probably won't even be | |
7520 | using TOCstart. */ | |
7521 | for (s = obfd->sections; s != NULL; s = s->next) | |
7522 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) | |
7523 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7524 | break; | |
721956f4 | 7525 | if (s == NULL) |
805fc799 AM |
7526 | for (s = obfd->sections; s != NULL; s = s->next) |
7527 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) | |
7528 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7529 | break; | |
721956f4 | 7530 | if (s == NULL) |
805fc799 AM |
7531 | for (s = obfd->sections; s != NULL; s = s->next) |
7532 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) | |
7533 | break; | |
721956f4 | 7534 | if (s == NULL) |
805fc799 AM |
7535 | for (s = obfd->sections; s != NULL; s = s->next) |
7536 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) | |
7537 | break; | |
7538 | } | |
721956f4 | 7539 | |
805fc799 AM |
7540 | TOCstart = 0; |
7541 | if (s != NULL) | |
7542 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 7543 | |
805fc799 | 7544 | return TOCstart; |
721956f4 AM |
7545 | } |
7546 | ||
7547 | /* Build all the stubs associated with the current output file. | |
7548 | The stubs are kept in a hash table attached to the main linker | |
7549 | hash table. This function is called via gldelf64ppc_finish. */ | |
7550 | ||
b34976b6 | 7551 | bfd_boolean |
4ce794b7 AM |
7552 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
7553 | struct bfd_link_info *info, | |
7554 | char **stats) | |
5d1634d7 AM |
7555 | { |
7556 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 7557 | asection *stub_sec; |
5d1634d7 | 7558 | bfd_byte *p; |
e717da7e | 7559 | int stub_sec_count = 0; |
5d1634d7 | 7560 | |
ad8e1ba5 | 7561 | htab->emit_stub_syms = emit_stub_syms; |
eea6121a AM |
7562 | |
7563 | /* Allocate memory to hold the linker stubs. */ | |
721956f4 AM |
7564 | for (stub_sec = htab->stub_bfd->sections; |
7565 | stub_sec != NULL; | |
7566 | stub_sec = stub_sec->next) | |
eea6121a AM |
7567 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0 |
7568 | && stub_sec->size != 0) | |
e717da7e | 7569 | { |
eea6121a AM |
7570 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size); |
7571 | if (stub_sec->contents == NULL) | |
7572 | return FALSE; | |
7573 | /* We want to check that built size is the same as calculated | |
7574 | size. rawsize is a convenient location to use. */ | |
7575 | stub_sec->rawsize = stub_sec->size; | |
7576 | stub_sec->size = 0; | |
e717da7e | 7577 | } |
5d1634d7 | 7578 | |
4ce794b7 | 7579 | if (htab->plt != NULL) |
5d1634d7 | 7580 | { |
9f951329 | 7581 | unsigned int indx; |
ad8e1ba5 | 7582 | bfd_vma plt0; |
9f951329 | 7583 | |
721956f4 | 7584 | /* Build the .glink plt call stub. */ |
4ce794b7 AM |
7585 | plt0 = (htab->plt->output_section->vma |
7586 | + htab->plt->output_offset | |
7587 | - (htab->glink->output_section->vma | |
7588 | + htab->glink->output_offset | |
ad8e1ba5 AM |
7589 | + GLINK_CALL_STUB_SIZE)); |
7590 | if (plt0 + 0x80008000 > 0xffffffff) | |
721956f4 | 7591 | { |
ad8e1ba5 AM |
7592 | (*_bfd_error_handler) (_(".glink and .plt too far apart")); |
7593 | bfd_set_error (bfd_error_bad_value); | |
7594 | return FALSE; | |
721956f4 | 7595 | } |
721956f4 | 7596 | |
97b639ba AM |
7597 | if (htab->emit_stub_syms) |
7598 | { | |
7599 | struct elf_link_hash_entry *h; | |
7600 | h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE); | |
7601 | if (h == NULL) | |
7602 | return FALSE; | |
7603 | if (h->root.type == bfd_link_hash_new) | |
7604 | { | |
7605 | h->root.type = bfd_link_hash_defined; | |
7606 | h->root.u.def.section = htab->glink; | |
7607 | h->root.u.def.value = 0; | |
7608 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
7609 | | ELF_LINK_HASH_DEF_REGULAR | |
7610 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
7611 | | ELF_LINK_FORCED_LOCAL); | |
7612 | } | |
7613 | } | |
4ce794b7 AM |
7614 | p = htab->glink->contents; |
7615 | bfd_put_32 (htab->glink->owner, MFCTR_R12, p); | |
ad8e1ba5 | 7616 | p += 4; |
4ce794b7 | 7617 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p); |
ad8e1ba5 | 7618 | p += 4; |
4ce794b7 | 7619 | bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p); |
ad8e1ba5 | 7620 | p += 4; |
4ce794b7 | 7621 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7622 | p += 4; |
4ce794b7 | 7623 | bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p); |
ad8e1ba5 | 7624 | p += 4; |
4ce794b7 | 7625 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p); |
ad8e1ba5 | 7626 | p += 4; |
4ce794b7 | 7627 | bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p); |
ad8e1ba5 | 7628 | p += 4; |
4ce794b7 | 7629 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7630 | p += 4; |
4ce794b7 | 7631 | bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p); |
ad8e1ba5 | 7632 | p += 4; |
4ce794b7 | 7633 | bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p); |
ad8e1ba5 | 7634 | p += 4; |
4ce794b7 | 7635 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7636 | p += 4; |
4ce794b7 | 7637 | bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7638 | p += 4; |
4ce794b7 | 7639 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
ad8e1ba5 | 7640 | p += 4; |
4ce794b7 | 7641 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
ad8e1ba5 | 7642 | p += 4; |
4ce794b7 | 7643 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
ad8e1ba5 | 7644 | p += 4; |
4ce794b7 | 7645 | bfd_put_32 (htab->glink->owner, BCTR, p); |
ad8e1ba5 AM |
7646 | p += 4; |
7647 | ||
9f951329 AM |
7648 | /* Build the .glink lazy link call stubs. */ |
7649 | indx = 0; | |
eea6121a | 7650 | while (p < htab->glink->contents + htab->glink->size) |
9f951329 AM |
7651 | { |
7652 | if (indx < 0x8000) | |
7653 | { | |
4ce794b7 | 7654 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
9f951329 AM |
7655 | p += 4; |
7656 | } | |
7657 | else | |
7658 | { | |
4ce794b7 | 7659 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
9f951329 | 7660 | p += 4; |
4ce794b7 | 7661 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
9f951329 AM |
7662 | p += 4; |
7663 | } | |
4ce794b7 AM |
7664 | bfd_put_32 (htab->glink->owner, |
7665 | B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p); | |
a16d5acb | 7666 | indx++; |
9f951329 AM |
7667 | p += 4; |
7668 | } | |
eea6121a | 7669 | htab->glink->rawsize = p - htab->glink->contents; |
5d1634d7 | 7670 | } |
5d1634d7 | 7671 | |
eea6121a | 7672 | if (htab->brlt->size != 0) |
721956f4 | 7673 | { |
4ce794b7 | 7674 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
eea6121a | 7675 | htab->brlt->size); |
4ce794b7 | 7676 | if (htab->brlt->contents == NULL) |
b34976b6 | 7677 | return FALSE; |
721956f4 | 7678 | } |
eea6121a | 7679 | if (info->shared && htab->relbrlt->size != 0) |
63bc6f6c AM |
7680 | { |
7681 | htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner, | |
eea6121a | 7682 | htab->relbrlt->size); |
63bc6f6c AM |
7683 | if (htab->relbrlt->contents == NULL) |
7684 | return FALSE; | |
7685 | } | |
5d1634d7 | 7686 | |
721956f4 AM |
7687 | /* Build the stubs as directed by the stub hash table. */ |
7688 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 7689 | |
721956f4 AM |
7690 | for (stub_sec = htab->stub_bfd->sections; |
7691 | stub_sec != NULL; | |
7692 | stub_sec = stub_sec->next) | |
e717da7e AM |
7693 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7694 | { | |
7695 | stub_sec_count += 1; | |
eea6121a | 7696 | if (stub_sec->rawsize != stub_sec->size) |
e717da7e AM |
7697 | break; |
7698 | } | |
5d1634d7 | 7699 | |
721956f4 | 7700 | if (stub_sec != NULL |
eea6121a | 7701 | || htab->glink->rawsize != htab->glink->size) |
5d1634d7 | 7702 | { |
b34976b6 | 7703 | htab->stub_error = TRUE; |
721956f4 | 7704 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
5d1634d7 | 7705 | } |
721956f4 | 7706 | |
d2a300cf AM |
7707 | if (htab->stub_error) |
7708 | return FALSE; | |
7709 | ||
7710 | if (stats != NULL) | |
7711 | { | |
7712 | *stats = bfd_malloc (500); | |
7713 | if (*stats == NULL) | |
7714 | return FALSE; | |
7715 | ||
7716 | sprintf (*stats, _("linker stubs in %u groups\n" | |
7717 | " branch %lu\n" | |
7718 | " toc adjust %lu\n" | |
7719 | " long branch %lu\n" | |
7720 | " long toc adj %lu\n" | |
7721 | " plt call %lu"), | |
e717da7e | 7722 | stub_sec_count, |
4ce794b7 AM |
7723 | htab->stub_count[ppc_stub_long_branch - 1], |
7724 | htab->stub_count[ppc_stub_long_branch_r2off - 1], | |
7725 | htab->stub_count[ppc_stub_plt_branch - 1], | |
7726 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], | |
7727 | htab->stub_count[ppc_stub_plt_call - 1]); | |
d2a300cf AM |
7728 | } |
7729 | return TRUE; | |
5bd4f169 AM |
7730 | } |
7731 | ||
99877b66 AM |
7732 | /* This function undoes the changes made by add_symbol_adjust. */ |
7733 | ||
7734 | static bfd_boolean | |
7735 | undo_symbol_twiddle (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
7736 | { | |
7737 | struct ppc_link_hash_entry *eh; | |
7738 | ||
7739 | if (h->root.type == bfd_link_hash_indirect) | |
7740 | return TRUE; | |
7741 | ||
7742 | if (h->root.type == bfd_link_hash_warning) | |
7743 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7744 | ||
7745 | eh = (struct ppc_link_hash_entry *) h; | |
7746 | if (eh->elf.root.type != bfd_link_hash_undefweak || !eh->was_undefined) | |
7747 | return TRUE; | |
7748 | ||
7749 | eh->elf.root.type = bfd_link_hash_undefined; | |
7750 | return TRUE; | |
7751 | } | |
7752 | ||
7753 | void | |
7754 | ppc64_elf_restore_symbols (struct bfd_link_info *info) | |
7755 | { | |
7756 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
7757 | elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info); | |
7758 | } | |
7759 | ||
5bd4f169 AM |
7760 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
7761 | to handle the relocations for a section. | |
7762 | ||
7763 | The relocs are always passed as Rela structures; if the section | |
7764 | actually uses Rel structures, the r_addend field will always be | |
7765 | zero. | |
7766 | ||
7767 | This function is responsible for adjust the section contents as | |
7768 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 7769 | relocatable output file) adjusting the reloc addend as |
5bd4f169 AM |
7770 | necessary. |
7771 | ||
7772 | This function does not have to worry about setting the reloc | |
7773 | address or the reloc symbol index. | |
7774 | ||
7775 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
7776 | ||
7777 | LOCAL_SECTIONS is an array giving the section in the input file | |
7778 | corresponding to the st_shndx field of each local symbol. | |
7779 | ||
7780 | The global hash table entry for the global symbols can be found | |
7781 | via elf_sym_hashes (input_bfd). | |
7782 | ||
1049f94e | 7783 | When generating relocatable output, this function must handle |
5bd4f169 AM |
7784 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
7785 | going to be the section symbol corresponding to the output | |
7786 | section, which means that the addend must be adjusted | |
7787 | accordingly. */ | |
7788 | ||
b34976b6 | 7789 | static bfd_boolean |
4ce794b7 AM |
7790 | ppc64_elf_relocate_section (bfd *output_bfd, |
7791 | struct bfd_link_info *info, | |
7792 | bfd *input_bfd, | |
7793 | asection *input_section, | |
7794 | bfd_byte *contents, | |
7795 | Elf_Internal_Rela *relocs, | |
7796 | Elf_Internal_Sym *local_syms, | |
7797 | asection **local_sections) | |
5bd4f169 | 7798 | { |
65f38f15 | 7799 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
7800 | Elf_Internal_Shdr *symtab_hdr; |
7801 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
7802 | Elf_Internal_Rela *rel; |
7803 | Elf_Internal_Rela *relend; | |
411e1bfb AM |
7804 | Elf_Internal_Rela outrel; |
7805 | bfd_byte *loc; | |
411e1bfb | 7806 | struct got_entry **local_got_ents; |
5bd4f169 | 7807 | bfd_vma TOCstart; |
b34976b6 AM |
7808 | bfd_boolean ret = TRUE; |
7809 | bfd_boolean is_opd; | |
96e0dda4 | 7810 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 7811 | bfd_boolean is_power4 = FALSE; |
5bd4f169 | 7812 | |
1049f94e | 7813 | if (info->relocatable) |
b34976b6 | 7814 | return TRUE; |
b491616a | 7815 | |
65f38f15 | 7816 | /* Initialize howto table if needed. */ |
5bd4f169 | 7817 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
7818 | ppc_howto_init (); |
7819 | ||
65f38f15 | 7820 | htab = ppc_hash_table (info); |
411e1bfb | 7821 | local_got_ents = elf_local_got_ents (input_bfd); |
5bd4f169 | 7822 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
7823 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
7824 | sym_hashes = elf_sym_hashes (input_bfd); | |
f0abc2a1 | 7825 | is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL; |
65f38f15 | 7826 | |
5bd4f169 AM |
7827 | rel = relocs; |
7828 | relend = relocs + input_section->reloc_count; | |
7829 | for (; rel < relend; rel++) | |
7830 | { | |
04c9666a | 7831 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 AM |
7832 | bfd_vma addend; |
7833 | bfd_reloc_status_type r; | |
7834 | Elf_Internal_Sym *sym; | |
7835 | asection *sec; | |
7836 | struct elf_link_hash_entry *h; | |
721956f4 | 7837 | struct elf_link_hash_entry *fdh; |
5bd4f169 | 7838 | const char *sym_name; |
0d4792f7 | 7839 | unsigned long r_symndx, toc_symndx; |
951fd09b | 7840 | char tls_mask, tls_gd, tls_type; |
0d4792f7 | 7841 | char sym_type; |
5bd4f169 | 7842 | bfd_vma relocation; |
b34976b6 AM |
7843 | bfd_boolean unresolved_reloc; |
7844 | bfd_boolean warned; | |
50bc7936 | 7845 | unsigned long insn, mask; |
721956f4 AM |
7846 | struct ppc_stub_hash_entry *stub_entry; |
7847 | bfd_vma max_br_offset; | |
7848 | bfd_vma from; | |
5bd4f169 | 7849 | |
4ce794b7 | 7850 | r_type = ELF64_R_TYPE (rel->r_info); |
5bd4f169 | 7851 | r_symndx = ELF64_R_SYM (rel->r_info); |
ee87f2da AM |
7852 | |
7853 | /* For old style R_PPC64_TOC relocs with a zero symbol, use the | |
7854 | symbol of the previous ADDR64 reloc. The symbol gives us the | |
7855 | proper TOC base to use. */ | |
7856 | if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC) | |
7857 | && rel != relocs | |
7858 | && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64 | |
7859 | && is_opd) | |
7860 | r_symndx = ELF64_R_SYM (rel[-1].r_info); | |
7861 | ||
4ce794b7 AM |
7862 | sym = NULL; |
7863 | sec = NULL; | |
7864 | h = NULL; | |
7865 | sym_name = NULL; | |
b34976b6 AM |
7866 | unresolved_reloc = FALSE; |
7867 | warned = FALSE; | |
65f38f15 | 7868 | |
0b13192e | 7869 | if (r_symndx < symtab_hdr->sh_info) |
5bd4f169 AM |
7870 | { |
7871 | /* It's a local symbol. */ | |
4025353c AM |
7872 | long *opd_adjust; |
7873 | ||
5bd4f169 AM |
7874 | sym = local_syms + r_symndx; |
7875 | sec = local_sections[r_symndx]; | |
411e1bfb | 7876 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
0d4792f7 | 7877 | sym_type = ELF64_ST_TYPE (sym->st_info); |
8517fae7 | 7878 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
4025353c AM |
7879 | opd_adjust = get_opd_info (sec); |
7880 | if (opd_adjust != NULL) | |
1e2f5b6e | 7881 | { |
4025353c AM |
7882 | long adjust = opd_adjust[(sym->st_value + rel->r_addend) / 24]; |
7883 | if (adjust == -1) | |
7884 | relocation = 0; | |
7885 | else | |
7886 | relocation += adjust; | |
1e2f5b6e | 7887 | } |
5bd4f169 AM |
7888 | } |
7889 | else | |
7890 | { | |
b2a8e766 AM |
7891 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
7892 | r_symndx, symtab_hdr, sym_hashes, | |
7893 | h, sec, relocation, | |
7894 | unresolved_reloc, warned); | |
5bd4f169 | 7895 | sym_name = h->root.root.string; |
0d4792f7 | 7896 | sym_type = h->type; |
5bd4f169 AM |
7897 | } |
7898 | ||
951fd09b AM |
7899 | /* TLS optimizations. Replace instruction sequences and relocs |
7900 | based on information we collected in tls_optimize. We edit | |
7901 | RELOCS so that --emit-relocs will output something sensible | |
7902 | for the final instruction stream. */ | |
7903 | tls_mask = 0; | |
7904 | tls_gd = 0; | |
0d4792f7 | 7905 | toc_symndx = 0; |
d881513a | 7906 | if (IS_PPC64_TLS_RELOC (r_type)) |
411e1bfb AM |
7907 | { |
7908 | if (h != NULL) | |
e7b938ca | 7909 | tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask; |
411e1bfb AM |
7910 | else if (local_got_ents != NULL) |
7911 | { | |
e7b938ca AM |
7912 | char *lgot_masks; |
7913 | lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); | |
7914 | tls_mask = lgot_masks[r_symndx]; | |
411e1bfb | 7915 | } |
0d4792f7 AM |
7916 | if (tls_mask == 0 && r_type == R_PPC64_TLS) |
7917 | { | |
7918 | /* Check for toc tls entries. */ | |
7919 | char *toc_tls; | |
7920 | ||
7921 | if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms, | |
7922 | rel, input_bfd)) | |
7923 | return FALSE; | |
7924 | ||
7925 | if (toc_tls) | |
7926 | tls_mask = *toc_tls; | |
7927 | } | |
7928 | } | |
7929 | ||
7930 | /* Check that tls relocs are used with tls syms, and non-tls | |
7931 | relocs are used with non-tls syms. */ | |
7932 | if (r_symndx != 0 | |
7933 | && r_type != R_PPC64_NONE | |
7934 | && (h == NULL | |
7935 | || h->root.type == bfd_link_hash_defined | |
7936 | || h->root.type == bfd_link_hash_defweak) | |
7937 | && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
7938 | { | |
7939 | if (r_type == R_PPC64_TLS && tls_mask != 0) | |
7940 | /* R_PPC64_TLS is OK against a symbol in the TOC. */ | |
7941 | ; | |
7942 | else | |
7943 | (*_bfd_error_handler) | |
7944 | (sym_type == STT_TLS | |
d003868e AM |
7945 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") |
7946 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"), | |
7947 | input_bfd, | |
7948 | input_section, | |
0d4792f7 AM |
7949 | (long) rel->r_offset, |
7950 | ppc64_elf_howto_table[r_type]->name, | |
7951 | sym_name); | |
411e1bfb AM |
7952 | } |
7953 | ||
7954 | /* Ensure reloc mapping code below stays sane. */ | |
7955 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 | |
7956 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 | |
7957 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) | |
7958 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) | |
7959 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) | |
7960 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) | |
7961 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) | |
7962 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) | |
7963 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) | |
7964 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) | |
7965 | abort (); | |
0d4792f7 | 7966 | |
411e1bfb AM |
7967 | switch (r_type) |
7968 | { | |
7969 | default: | |
411e1bfb AM |
7970 | break; |
7971 | ||
7972 | case R_PPC64_TOC16: | |
7973 | case R_PPC64_TOC16_LO: | |
7974 | case R_PPC64_TOC16_DS: | |
7975 | case R_PPC64_TOC16_LO_DS: | |
411e1bfb AM |
7976 | { |
7977 | /* Check for toc tls entries. */ | |
7978 | char *toc_tls; | |
951fd09b | 7979 | int retval; |
411e1bfb | 7980 | |
0d4792f7 AM |
7981 | retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms, |
7982 | rel, input_bfd); | |
951fd09b | 7983 | if (retval == 0) |
411e1bfb AM |
7984 | return FALSE; |
7985 | ||
7986 | if (toc_tls) | |
7987 | { | |
951fd09b | 7988 | tls_mask = *toc_tls; |
411e1bfb AM |
7989 | if (r_type == R_PPC64_TOC16_DS |
7990 | || r_type == R_PPC64_TOC16_LO_DS) | |
81407a69 AM |
7991 | { |
7992 | if (tls_mask != 0 | |
7993 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) | |
7994 | goto toctprel; | |
7995 | } | |
411e1bfb | 7996 | else |
951fd09b AM |
7997 | { |
7998 | /* If we found a GD reloc pair, then we might be | |
7999 | doing a GD->IE transition. */ | |
8000 | if (retval == 2) | |
8001 | { | |
8002 | tls_gd = TLS_TPRELGD; | |
8003 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
8004 | goto tls_get_addr_check; | |
8005 | } | |
8006 | else if (retval == 3) | |
8007 | { | |
8008 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
8009 | goto tls_get_addr_check; | |
8010 | } | |
8011 | } | |
411e1bfb AM |
8012 | } |
8013 | } | |
8014 | break; | |
8015 | ||
8016 | case R_PPC64_GOT_TPREL16_DS: | |
8017 | case R_PPC64_GOT_TPREL16_LO_DS: | |
951fd09b AM |
8018 | if (tls_mask != 0 |
8019 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 8020 | { |
81407a69 | 8021 | toctprel: |
411e1bfb AM |
8022 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); |
8023 | insn &= 31 << 21; | |
8024 | insn |= 0x3c0d0000; /* addis 0,13,0 */ | |
8025 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
8026 | r_type = R_PPC64_TPREL16_HA; | |
0d4792f7 AM |
8027 | if (toc_symndx != 0) |
8028 | { | |
8029 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
8030 | /* We changed the symbol. Start over in order to | |
8031 | get h, sym, sec etc. right. */ | |
8032 | rel--; | |
8033 | continue; | |
8034 | } | |
8035 | else | |
8036 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
8037 | } |
8038 | break; | |
8039 | ||
8040 | case R_PPC64_TLS: | |
951fd09b AM |
8041 | if (tls_mask != 0 |
8042 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 8043 | { |
50bc7936 | 8044 | bfd_vma rtra; |
411e1bfb | 8045 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
772119ce | 8046 | if ((insn & ((0x3f << 26) | (31 << 11))) |
411e1bfb AM |
8047 | == ((31 << 26) | (13 << 11))) |
8048 | rtra = insn & ((1 << 26) - (1 << 16)); | |
772119ce | 8049 | else if ((insn & ((0x3f << 26) | (31 << 16))) |
411e1bfb AM |
8050 | == ((31 << 26) | (13 << 16))) |
8051 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
8052 | else | |
8053 | abort (); | |
8054 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
8055 | /* add -> addi. */ | |
8056 | insn = 14 << 26; | |
8057 | else if ((insn & (31 << 1)) == 23 << 1 | |
8058 | && ((insn & (31 << 6)) < 14 << 6 | |
8059 | || ((insn & (31 << 6)) >= 16 << 6 | |
8060 | && (insn & (31 << 6)) < 24 << 6))) | |
8061 | /* load and store indexed -> dform. */ | |
8062 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
8063 | else if ((insn & (31 << 1)) == 21 << 1 | |
8064 | && (insn & (0x1a << 6)) == 0) | |
8065 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
8066 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
8067 | | ((insn >> 6) & 1)); | |
8068 | else if ((insn & (31 << 1)) == 21 << 1 | |
8069 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
8070 | /* lwax -> lwa. */ | |
8071 | insn = (58 << 26) | 2; | |
8072 | else | |
8073 | abort (); | |
8074 | insn |= rtra; | |
8075 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
411e1bfb AM |
8076 | /* Was PPC64_TLS which sits on insn boundary, now |
8077 | PPC64_TPREL16_LO which is at insn+2. */ | |
8078 | rel->r_offset += 2; | |
0d4792f7 AM |
8079 | r_type = R_PPC64_TPREL16_LO; |
8080 | if (toc_symndx != 0) | |
8081 | { | |
8082 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
8083 | /* We changed the symbol. Start over in order to | |
8084 | get h, sym, sec etc. right. */ | |
8085 | rel--; | |
8086 | continue; | |
8087 | } | |
8088 | else | |
8089 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
8090 | } |
8091 | break; | |
8092 | ||
411e1bfb AM |
8093 | case R_PPC64_GOT_TLSGD16_HI: |
8094 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b AM |
8095 | tls_gd = TLS_TPRELGD; |
8096 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
8097 | goto tls_gdld_hi; | |
8098 | break; | |
8099 | ||
411e1bfb AM |
8100 | case R_PPC64_GOT_TLSLD16_HI: |
8101 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 8102 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
411e1bfb | 8103 | { |
951fd09b AM |
8104 | tls_gdld_hi: |
8105 | if ((tls_mask & tls_gd) != 0) | |
8106 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
8107 | + R_PPC64_GOT_TPREL16_DS); | |
8108 | else | |
411e1bfb | 8109 | { |
951fd09b AM |
8110 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
8111 | rel->r_offset -= 2; | |
8112 | r_type = R_PPC64_NONE; | |
411e1bfb | 8113 | } |
951fd09b | 8114 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb AM |
8115 | } |
8116 | break; | |
8117 | ||
951fd09b AM |
8118 | case R_PPC64_GOT_TLSGD16: |
8119 | case R_PPC64_GOT_TLSGD16_LO: | |
8120 | tls_gd = TLS_TPRELGD; | |
8121 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
8122 | goto tls_get_addr_check; | |
8123 | break; | |
411e1bfb | 8124 | |
951fd09b AM |
8125 | case R_PPC64_GOT_TLSLD16: |
8126 | case R_PPC64_GOT_TLSLD16_LO: | |
8127 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
8128 | { | |
8129 | tls_get_addr_check: | |
8130 | if (rel + 1 < relend) | |
411e1bfb | 8131 | { |
951fd09b AM |
8132 | enum elf_ppc64_reloc_type r_type2; |
8133 | unsigned long r_symndx2; | |
8134 | struct elf_link_hash_entry *h2; | |
8135 | bfd_vma insn1, insn2, insn3; | |
8136 | bfd_vma offset; | |
8137 | ||
8138 | /* The next instruction should be a call to | |
8139 | __tls_get_addr. Peek at the reloc to be sure. */ | |
4ce794b7 | 8140 | r_type2 = ELF64_R_TYPE (rel[1].r_info); |
951fd09b AM |
8141 | r_symndx2 = ELF64_R_SYM (rel[1].r_info); |
8142 | if (r_symndx2 < symtab_hdr->sh_info | |
8143 | || (r_type2 != R_PPC64_REL14 | |
8144 | && r_type2 != R_PPC64_REL14_BRTAKEN | |
8145 | && r_type2 != R_PPC64_REL14_BRNTAKEN | |
8146 | && r_type2 != R_PPC64_REL24)) | |
8147 | break; | |
8148 | ||
8149 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
8150 | while (h2->root.type == bfd_link_hash_indirect | |
8151 | || h2->root.type == bfd_link_hash_warning) | |
8152 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
8387904d AM |
8153 | if (h2 == NULL || (h2 != &htab->tls_get_addr->elf |
8154 | && h2 != &htab->tls_get_addr_fd->elf)) | |
951fd09b AM |
8155 | break; |
8156 | ||
8157 | /* OK, it checks out. Replace the call. */ | |
8158 | offset = rel[1].r_offset; | |
8159 | insn1 = bfd_get_32 (output_bfd, | |
8160 | contents + rel->r_offset - 2); | |
8161 | insn3 = bfd_get_32 (output_bfd, | |
8162 | contents + offset + 4); | |
8163 | if ((tls_mask & tls_gd) != 0) | |
411e1bfb | 8164 | { |
951fd09b AM |
8165 | /* IE */ |
8166 | insn1 &= (1 << 26) - (1 << 2); | |
8167 | insn1 |= 58 << 26; /* ld */ | |
8168 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
8169 | rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); | |
8170 | if ((tls_mask & TLS_EXPLICIT) == 0) | |
8171 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
8172 | + R_PPC64_GOT_TPREL16_DS); | |
8173 | else | |
8174 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; | |
8175 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
8176 | } |
8177 | else | |
951fd09b AM |
8178 | { |
8179 | /* LE */ | |
8180 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ | |
8181 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
8182 | if (tls_gd == 0) | |
8183 | { | |
8184 | /* Was an LD reloc. */ | |
8185 | r_symndx = 0; | |
e1918d23 AM |
8186 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
8187 | rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; | |
951fd09b | 8188 | } |
0d4792f7 AM |
8189 | else if (toc_symndx != 0) |
8190 | r_symndx = toc_symndx; | |
951fd09b AM |
8191 | r_type = R_PPC64_TPREL16_HA; |
8192 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
8193 | rel[1].r_info = ELF64_R_INFO (r_symndx, | |
8194 | R_PPC64_TPREL16_LO); | |
8195 | rel[1].r_offset += 2; | |
8196 | } | |
8197 | if (insn3 == NOP | |
8198 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
8199 | { | |
8200 | insn3 = insn2; | |
8201 | insn2 = NOP; | |
8202 | rel[1].r_offset += 4; | |
8203 | } | |
8204 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); | |
8205 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
8206 | bfd_put_32 (output_bfd, insn3, contents + offset + 4); | |
0d4792f7 | 8207 | if (tls_gd == 0 || toc_symndx != 0) |
951fd09b | 8208 | { |
0d4792f7 AM |
8209 | /* We changed the symbol. Start over in order |
8210 | to get h, sym, sec etc. right. */ | |
951fd09b AM |
8211 | rel--; |
8212 | continue; | |
8213 | } | |
411e1bfb | 8214 | } |
411e1bfb | 8215 | } |
411e1bfb AM |
8216 | break; |
8217 | ||
8218 | case R_PPC64_DTPMOD64: | |
951fd09b AM |
8219 | if (rel + 1 < relend |
8220 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
8221 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 8222 | { |
951fd09b AM |
8223 | if ((tls_mask & TLS_GD) == 0) |
8224 | { | |
8225 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); | |
8226 | if ((tls_mask & TLS_TPRELGD) != 0) | |
8227 | r_type = R_PPC64_TPREL64; | |
8228 | else | |
8229 | { | |
4ce794b7 | 8230 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
951fd09b AM |
8231 | r_type = R_PPC64_NONE; |
8232 | } | |
8233 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
8234 | } | |
8235 | } | |
8236 | else | |
8237 | { | |
8238 | if ((tls_mask & TLS_LD) == 0) | |
411e1bfb | 8239 | { |
4ce794b7 | 8240 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
411e1bfb | 8241 | r_type = R_PPC64_NONE; |
951fd09b | 8242 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb | 8243 | } |
411e1bfb AM |
8244 | } |
8245 | break; | |
8246 | ||
8247 | case R_PPC64_TPREL64: | |
951fd09b | 8248 | if ((tls_mask & TLS_TPREL) == 0) |
411e1bfb AM |
8249 | { |
8250 | r_type = R_PPC64_NONE; | |
8251 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
8252 | } | |
8253 | break; | |
8254 | } | |
8255 | ||
8256 | /* Handle other relocations that tweak non-addend part of insn. */ | |
86c76c7b | 8257 | insn = 0; |
b25116a9 AM |
8258 | max_br_offset = 1 << 25; |
8259 | addend = rel->r_addend; | |
65f38f15 | 8260 | switch (r_type) |
5bd4f169 AM |
8261 | { |
8262 | default: | |
65f38f15 | 8263 | break; |
5bd4f169 | 8264 | |
65f38f15 AM |
8265 | /* Branch taken prediction relocations. */ |
8266 | case R_PPC64_ADDR14_BRTAKEN: | |
8267 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
8268 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
8269 | /* Fall thru. */ | |
65f38f15 | 8270 | |
86c76c7b | 8271 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
8272 | case R_PPC64_ADDR14_BRNTAKEN: |
8273 | case R_PPC64_REL14_BRNTAKEN: | |
411e1bfb AM |
8274 | insn |= bfd_get_32 (output_bfd, |
8275 | contents + rel->r_offset) & ~(0x01 << 21); | |
b25116a9 | 8276 | /* Fall thru. */ |
86c76c7b | 8277 | |
b25116a9 AM |
8278 | case R_PPC64_REL14: |
8279 | max_br_offset = 1 << 15; | |
8280 | /* Fall thru. */ | |
5bd4f169 | 8281 | |
65f38f15 | 8282 | case R_PPC64_REL24: |
ad8e1ba5 AM |
8283 | /* Calls to functions with a different TOC, such as calls to |
8284 | shared objects, need to alter the TOC pointer. This is | |
8285 | done using a linkage stub. A REL24 branching to these | |
8286 | linkage stubs needs to be followed by a nop, as the nop | |
8287 | will be replaced with an instruction to restore the TOC | |
8288 | base pointer. */ | |
b25116a9 | 8289 | stub_entry = NULL; |
8387904d | 8290 | fdh = h; |
ad8e1ba5 | 8291 | if (((h != NULL |
8387904d AM |
8292 | && (((fdh = &((struct ppc_link_hash_entry *) h)->oh->elf) != NULL |
8293 | && fdh->plt.plist != NULL) | |
8294 | || (fdh = h)->plt.plist != NULL)) | |
8295 | || (sec != NULL | |
ad8e1ba5 | 8296 | && sec->output_section != NULL |
b25116a9 | 8297 | && sec->id <= htab->top_id |
ad8e1ba5 AM |
8298 | && (htab->stub_group[sec->id].toc_off |
8299 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 | 8300 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, |
ad8e1ba5 AM |
8301 | rel, htab)) != NULL |
8302 | && (stub_entry->stub_type == ppc_stub_plt_call | |
8303 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off | |
8304 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) | |
41bd81ab | 8305 | { |
b25116a9 | 8306 | bfd_boolean can_plt_call = FALSE; |
721956f4 | 8307 | |
eea6121a | 8308 | if (rel->r_offset + 8 <= input_section->size) |
41bd81ab | 8309 | { |
b25116a9 AM |
8310 | unsigned long nop; |
8311 | nop = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); | |
8312 | if (nop == NOP | |
8313 | || nop == CROR_151515 || nop == CROR_313131) | |
41bd81ab | 8314 | { |
4ce794b7 | 8315 | bfd_put_32 (input_bfd, LD_R2_40R1, |
411e1bfb | 8316 | contents + rel->r_offset + 4); |
b25116a9 | 8317 | can_plt_call = TRUE; |
41bd81ab | 8318 | } |
5bd4f169 | 8319 | } |
721956f4 AM |
8320 | |
8321 | if (!can_plt_call) | |
8322 | { | |
ad8e1ba5 AM |
8323 | if (stub_entry->stub_type == ppc_stub_plt_call) |
8324 | { | |
8325 | /* If this is a plain branch rather than a branch | |
8326 | and link, don't require a nop. */ | |
b25116a9 AM |
8327 | unsigned long br; |
8328 | br = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
8329 | if ((br & 1) == 0) | |
8330 | can_plt_call = TRUE; | |
ad8e1ba5 | 8331 | } |
6ab189d5 AM |
8332 | else if (h != NULL |
8333 | && strcmp (h->root.root.string, | |
8334 | ".__libc_start_main") == 0) | |
8335 | { | |
8336 | /* Allow crt1 branch to go via a toc adjusting stub. */ | |
b25116a9 | 8337 | can_plt_call = TRUE; |
6ab189d5 | 8338 | } |
ad8e1ba5 AM |
8339 | else |
8340 | { | |
8341 | if (strcmp (input_section->output_section->name, | |
8342 | ".init") == 0 | |
8343 | || strcmp (input_section->output_section->name, | |
8344 | ".fini") == 0) | |
8345 | (*_bfd_error_handler) | |
d003868e | 8346 | (_("%B(%A+0x%lx): automatic multiple TOCs " |
ad8e1ba5 AM |
8347 | "not supported using your crt files; " |
8348 | "recompile with -mminimal-toc or upgrade gcc"), | |
d003868e AM |
8349 | input_bfd, |
8350 | input_section, | |
ad8e1ba5 AM |
8351 | (long) rel->r_offset); |
8352 | else | |
8353 | (*_bfd_error_handler) | |
d003868e | 8354 | (_("%B(%A+0x%lx): sibling call optimization to `%s' " |
ad8e1ba5 AM |
8355 | "does not allow automatic multiple TOCs; " |
8356 | "recompile with -mminimal-toc or " | |
8357 | "-fno-optimize-sibling-calls, " | |
8358 | "or make `%s' extern"), | |
d003868e AM |
8359 | input_bfd, |
8360 | input_section, | |
ad8e1ba5 AM |
8361 | (long) rel->r_offset, |
8362 | sym_name, | |
8363 | sym_name); | |
8364 | bfd_set_error (bfd_error_bad_value); | |
8365 | ret = FALSE; | |
8366 | } | |
721956f4 AM |
8367 | } |
8368 | ||
b25116a9 AM |
8369 | if (can_plt_call |
8370 | && stub_entry->stub_type == ppc_stub_plt_call) | |
8371 | unresolved_reloc = FALSE; | |
8372 | } | |
8373 | ||
8387904d AM |
8374 | if (stub_entry == NULL |
8375 | && get_opd_info (sec) != NULL) | |
8376 | { | |
8377 | /* The branch destination is the value of the opd entry. */ | |
8378 | bfd_vma off = (relocation - sec->output_section->vma | |
8379 | - sec->output_offset + rel->r_addend); | |
8380 | bfd_vma dest = opd_entry_value (sec, off, NULL, NULL); | |
8381 | if (dest != (bfd_vma) -1) | |
8382 | { | |
8383 | relocation = dest; | |
8384 | addend = 0; | |
8385 | } | |
8386 | } | |
8387 | ||
b25116a9 AM |
8388 | /* If the branch is out of reach we ought to have a long |
8389 | branch stub. */ | |
8390 | from = (rel->r_offset | |
8391 | + input_section->output_offset | |
8392 | + input_section->output_section->vma); | |
8393 | ||
8394 | if (stub_entry == NULL | |
8395 | && (relocation + rel->r_addend - from + max_br_offset | |
8396 | >= 2 * max_br_offset) | |
8397 | && r_type != R_PPC64_ADDR14_BRTAKEN | |
8398 | && r_type != R_PPC64_ADDR14_BRNTAKEN) | |
8399 | stub_entry = ppc_get_stub_entry (input_section, sec, h, rel, htab); | |
8400 | ||
8401 | if (stub_entry != NULL) | |
8402 | { | |
8403 | /* Munge up the value and addend so that we call the stub | |
8404 | rather than the procedure directly. */ | |
8405 | relocation = (stub_entry->stub_offset | |
8406 | + stub_entry->stub_sec->output_offset | |
8407 | + stub_entry->stub_sec->output_section->vma); | |
8408 | addend = 0; | |
8409 | } | |
8410 | ||
8411 | if (insn != 0) | |
8412 | { | |
8413 | if (is_power4) | |
721956f4 | 8414 | { |
b25116a9 AM |
8415 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
8416 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
8417 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
8418 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
8419 | insn |= 0x02 << 21; | |
8420 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
8421 | insn |= 0x08 << 21; | |
8422 | else | |
8423 | break; | |
8424 | } | |
8425 | else | |
8426 | { | |
8427 | /* Invert 'y' bit if not the default. */ | |
8428 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
8429 | insn ^= 0x01 << 21; | |
721956f4 | 8430 | } |
b25116a9 AM |
8431 | |
8432 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
5bd4f169 | 8433 | } |
e86ce104 | 8434 | |
06da1e8e AM |
8435 | /* NOP out calls to undefined weak functions. |
8436 | We can thus call a weak function without first | |
8437 | checking whether the function is defined. */ | |
b25116a9 AM |
8438 | else if (h != NULL |
8439 | && h->root.type == bfd_link_hash_undefweak | |
8440 | && r_type == R_PPC64_REL24 | |
8441 | && relocation == 0 | |
8442 | && rel->r_addend == 0) | |
e86ce104 | 8443 | { |
06da1e8e AM |
8444 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
8445 | continue; | |
e86ce104 | 8446 | } |
65f38f15 AM |
8447 | break; |
8448 | } | |
5bd4f169 | 8449 | |
65f38f15 | 8450 | /* Set `addend'. */ |
411e1bfb | 8451 | tls_type = 0; |
65f38f15 AM |
8452 | switch (r_type) |
8453 | { | |
8454 | default: | |
8455 | (*_bfd_error_handler) | |
d003868e AM |
8456 | (_("%B: unknown relocation type %d for symbol %s"), |
8457 | input_bfd, (int) r_type, sym_name); | |
5bd4f169 | 8458 | |
65f38f15 | 8459 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 8460 | ret = FALSE; |
65f38f15 | 8461 | continue; |
5bd4f169 | 8462 | |
65f38f15 | 8463 | case R_PPC64_NONE: |
411e1bfb | 8464 | case R_PPC64_TLS: |
04c9666a AM |
8465 | case R_PPC64_GNU_VTINHERIT: |
8466 | case R_PPC64_GNU_VTENTRY: | |
65f38f15 | 8467 | continue; |
5bd4f169 AM |
8468 | |
8469 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
8470 | address in the GOT as relocation value instead of the | |
411e1bfb | 8471 | symbol's value itself. Also, create a GOT entry for the |
5bd4f169 | 8472 | symbol and put the symbol value there. */ |
411e1bfb AM |
8473 | case R_PPC64_GOT_TLSGD16: |
8474 | case R_PPC64_GOT_TLSGD16_LO: | |
8475 | case R_PPC64_GOT_TLSGD16_HI: | |
8476 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 8477 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
8478 | goto dogot; |
8479 | ||
8480 | case R_PPC64_GOT_TLSLD16: | |
8481 | case R_PPC64_GOT_TLSLD16_LO: | |
8482 | case R_PPC64_GOT_TLSLD16_HI: | |
8483 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 8484 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
8485 | goto dogot; |
8486 | ||
8487 | case R_PPC64_GOT_TPREL16_DS: | |
8488 | case R_PPC64_GOT_TPREL16_LO_DS: | |
8489 | case R_PPC64_GOT_TPREL16_HI: | |
8490 | case R_PPC64_GOT_TPREL16_HA: | |
8491 | tls_type = TLS_TLS | TLS_TPREL; | |
8492 | goto dogot; | |
8493 | ||
8494 | case R_PPC64_GOT_DTPREL16_DS: | |
8495 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
8496 | case R_PPC64_GOT_DTPREL16_HI: | |
8497 | case R_PPC64_GOT_DTPREL16_HA: | |
8498 | tls_type = TLS_TLS | TLS_DTPREL; | |
8499 | goto dogot; | |
8500 | ||
65f38f15 AM |
8501 | case R_PPC64_GOT16: |
8502 | case R_PPC64_GOT16_LO: | |
8503 | case R_PPC64_GOT16_HI: | |
8504 | case R_PPC64_GOT16_HA: | |
8505 | case R_PPC64_GOT16_DS: | |
8506 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb | 8507 | dogot: |
5bd4f169 AM |
8508 | { |
8509 | /* Relocation is to the entry for this symbol in the global | |
8510 | offset table. */ | |
e717da7e | 8511 | asection *got; |
d881513a | 8512 | bfd_vma *offp; |
5bd4f169 | 8513 | bfd_vma off; |
d881513a | 8514 | unsigned long indx = 0; |
65f38f15 | 8515 | |
d881513a AM |
8516 | if (tls_type == (TLS_TLS | TLS_LD) |
8517 | && (h == NULL | |
8518 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
e717da7e | 8519 | offp = &ppc64_tlsld_got (input_bfd)->offset; |
411e1bfb | 8520 | else |
5bd4f169 | 8521 | { |
d881513a | 8522 | struct got_entry *ent; |
5bd4f169 | 8523 | |
d881513a AM |
8524 | if (h != NULL) |
8525 | { | |
8526 | bfd_boolean dyn = htab->elf.dynamic_sections_created; | |
f4656909 | 8527 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
d881513a | 8528 | || (info->shared |
586119b3 | 8529 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
d881513a AM |
8530 | /* This is actually a static link, or it is a |
8531 | -Bsymbolic link and the symbol is defined | |
8532 | locally, or the symbol was forced to be local | |
8533 | because of a version file. */ | |
8534 | ; | |
8535 | else | |
8536 | { | |
8537 | indx = h->dynindx; | |
8538 | unresolved_reloc = FALSE; | |
8539 | } | |
8540 | ent = h->got.glist; | |
8541 | } | |
411e1bfb | 8542 | else |
5bd4f169 | 8543 | { |
d881513a AM |
8544 | if (local_got_ents == NULL) |
8545 | abort (); | |
8546 | ent = local_got_ents[r_symndx]; | |
5bd4f169 | 8547 | } |
d881513a AM |
8548 | |
8549 | for (; ent != NULL; ent = ent->next) | |
8550 | if (ent->addend == rel->r_addend | |
e717da7e | 8551 | && ent->owner == input_bfd |
d881513a AM |
8552 | && ent->tls_type == tls_type) |
8553 | break; | |
8554 | if (ent == NULL) | |
8555 | abort (); | |
8556 | offp = &ent->got.offset; | |
5bd4f169 | 8557 | } |
411e1bfb | 8558 | |
e717da7e AM |
8559 | got = ppc64_elf_tdata (input_bfd)->got; |
8560 | if (got == NULL) | |
8561 | abort (); | |
8562 | ||
411e1bfb AM |
8563 | /* The offset must always be a multiple of 8. We use the |
8564 | least significant bit to record whether we have already | |
8565 | processed this entry. */ | |
d881513a | 8566 | off = *offp; |
411e1bfb AM |
8567 | if ((off & 1) != 0) |
8568 | off &= ~1; | |
5bd4f169 AM |
8569 | else |
8570 | { | |
411e1bfb AM |
8571 | /* Generate relocs for the dynamic linker, except in |
8572 | the case of TLSLD where we'll use one entry per | |
8573 | module. */ | |
e717da7e AM |
8574 | asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; |
8575 | ||
d881513a | 8576 | *offp = off | 1; |
4e795f50 AM |
8577 | if ((info->shared || indx != 0) |
8578 | && (h == NULL | |
8579 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8580 | || h->root.type != bfd_link_hash_undefweak)) | |
5bd4f169 | 8581 | { |
e717da7e AM |
8582 | outrel.r_offset = (got->output_section->vma |
8583 | + got->output_offset | |
411e1bfb | 8584 | + off); |
81407a69 | 8585 | outrel.r_addend = rel->r_addend; |
d881513a | 8586 | if (tls_type & (TLS_LD | TLS_GD)) |
5bd4f169 | 8587 | { |
411e1bfb | 8588 | outrel.r_addend = 0; |
e515b051 | 8589 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
d881513a AM |
8590 | if (tls_type == (TLS_TLS | TLS_GD)) |
8591 | { | |
e717da7e AM |
8592 | loc = relgot->contents; |
8593 | loc += (relgot->reloc_count++ | |
d881513a AM |
8594 | * sizeof (Elf64_External_Rela)); |
8595 | bfd_elf64_swap_reloca_out (output_bfd, | |
8596 | &outrel, loc); | |
e515b051 | 8597 | outrel.r_offset += 8; |
81407a69 | 8598 | outrel.r_addend = rel->r_addend; |
d881513a AM |
8599 | outrel.r_info |
8600 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); | |
d881513a | 8601 | } |
411e1bfb | 8602 | } |
951fd09b | 8603 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
411e1bfb | 8604 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
951fd09b | 8605 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb AM |
8606 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
8607 | else if (indx == 0) | |
81407a69 AM |
8608 | { |
8609 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE); | |
8610 | ||
8611 | /* Write the .got section contents for the sake | |
8612 | of prelink. */ | |
e717da7e | 8613 | loc = got->contents + off; |
23fbd6fa JJ |
8614 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
8615 | loc); | |
81407a69 | 8616 | } |
411e1bfb AM |
8617 | else |
8618 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); | |
81407a69 AM |
8619 | |
8620 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) | |
e515b051 AM |
8621 | { |
8622 | outrel.r_addend += relocation; | |
8623 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 8624 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 8625 | } |
e717da7e AM |
8626 | loc = relgot->contents; |
8627 | loc += (relgot->reloc_count++ | |
411e1bfb AM |
8628 | * sizeof (Elf64_External_Rela)); |
8629 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
8630 | } | |
8631 | ||
ad8e1ba5 | 8632 | /* Init the .got section contents here if we're not |
81407a69 | 8633 | emitting a reloc. */ |
d881513a | 8634 | else |
411e1bfb | 8635 | { |
d881513a | 8636 | relocation += rel->r_addend; |
7b609f53 AM |
8637 | if (tls_type == (TLS_TLS | TLS_LD)) |
8638 | relocation = 1; | |
8639 | else if (tls_type != 0) | |
411e1bfb | 8640 | { |
e1918d23 | 8641 | relocation -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 8642 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 8643 | relocation += DTP_OFFSET - TP_OFFSET; |
5bd4f169 | 8644 | |
7b609f53 AM |
8645 | if (tls_type == (TLS_TLS | TLS_GD)) |
8646 | { | |
8647 | bfd_put_64 (output_bfd, relocation, | |
e717da7e | 8648 | got->contents + off + 8); |
7b609f53 AM |
8649 | relocation = 1; |
8650 | } | |
411e1bfb | 8651 | } |
7b609f53 | 8652 | |
411e1bfb | 8653 | bfd_put_64 (output_bfd, relocation, |
e717da7e | 8654 | got->contents + off); |
5bd4f169 AM |
8655 | } |
8656 | } | |
8657 | ||
65f38f15 AM |
8658 | if (off >= (bfd_vma) -2) |
8659 | abort (); | |
8660 | ||
e717da7e | 8661 | relocation = got->output_offset + off; |
65f38f15 | 8662 | |
5bd4f169 | 8663 | /* TOC base (r2) is TOC start plus 0x8000. */ |
e717da7e | 8664 | addend = -TOC_BASE_OFF; |
5bd4f169 | 8665 | } |
65f38f15 AM |
8666 | break; |
8667 | ||
8668 | case R_PPC64_PLT16_HA: | |
8669 | case R_PPC64_PLT16_HI: | |
8670 | case R_PPC64_PLT16_LO: | |
8671 | case R_PPC64_PLT32: | |
8672 | case R_PPC64_PLT64: | |
8673 | /* Relocation is to the entry for this symbol in the | |
8674 | procedure linkage table. */ | |
8675 | ||
8676 | /* Resolve a PLT reloc against a local symbol directly, | |
8677 | without using the procedure linkage table. */ | |
8678 | if (h == NULL) | |
8679 | break; | |
8680 | ||
411e1bfb AM |
8681 | /* It's possible that we didn't make a PLT entry for this |
8682 | symbol. This happens when statically linking PIC code, | |
8683 | or when using -Bsymbolic. Go find a match if there is a | |
8684 | PLT entry. */ | |
4ce794b7 | 8685 | if (htab->plt != NULL) |
65f38f15 | 8686 | { |
411e1bfb AM |
8687 | struct plt_entry *ent; |
8688 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8689 | if (ent->addend == rel->r_addend | |
8690 | && ent->plt.offset != (bfd_vma) -1) | |
8691 | { | |
4ce794b7 AM |
8692 | relocation = (htab->plt->output_section->vma |
8693 | + htab->plt->output_offset | |
411e1bfb AM |
8694 | + ent->plt.offset); |
8695 | unresolved_reloc = FALSE; | |
8696 | } | |
65f38f15 | 8697 | } |
65f38f15 | 8698 | break; |
5bd4f169 | 8699 | |
0b13192e AM |
8700 | case R_PPC64_TOC: |
8701 | /* Relocation value is TOC base. */ | |
8702 | relocation = TOCstart; | |
8703 | if (r_symndx == 0) | |
8704 | relocation += htab->stub_group[input_section->id].toc_off; | |
8517fae7 AM |
8705 | else if (unresolved_reloc) |
8706 | ; | |
8707 | else if (sec != NULL && sec->id <= htab->top_id) | |
0b13192e AM |
8708 | relocation += htab->stub_group[sec->id].toc_off; |
8709 | else | |
8710 | unresolved_reloc = TRUE; | |
8711 | goto dodyn2; | |
8712 | ||
5bd4f169 AM |
8713 | /* TOC16 relocs. We want the offset relative to the TOC base, |
8714 | which is the address of the start of the TOC plus 0x8000. | |
8715 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
8716 | in this order. */ | |
65f38f15 AM |
8717 | case R_PPC64_TOC16: |
8718 | case R_PPC64_TOC16_LO: | |
8719 | case R_PPC64_TOC16_HI: | |
8720 | case R_PPC64_TOC16_DS: | |
8721 | case R_PPC64_TOC16_LO_DS: | |
8722 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 8723 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
5bd4f169 AM |
8724 | break; |
8725 | ||
8726 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
8727 | case R_PPC64_SECTOFF: |
8728 | case R_PPC64_SECTOFF_LO: | |
8729 | case R_PPC64_SECTOFF_HI: | |
8730 | case R_PPC64_SECTOFF_DS: | |
8731 | case R_PPC64_SECTOFF_LO_DS: | |
8732 | case R_PPC64_SECTOFF_HA: | |
4ce794b7 | 8733 | if (sec != NULL) |
65f38f15 | 8734 | addend -= sec->output_section->vma; |
5bd4f169 AM |
8735 | break; |
8736 | ||
721956f4 AM |
8737 | case R_PPC64_REL14: |
8738 | case R_PPC64_REL14_BRNTAKEN: | |
8739 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
8740 | case R_PPC64_REL24: |
8741 | break; | |
8742 | ||
411e1bfb AM |
8743 | case R_PPC64_TPREL16: |
8744 | case R_PPC64_TPREL16_LO: | |
8745 | case R_PPC64_TPREL16_HI: | |
8746 | case R_PPC64_TPREL16_HA: | |
8747 | case R_PPC64_TPREL16_DS: | |
8748 | case R_PPC64_TPREL16_LO_DS: | |
8749 | case R_PPC64_TPREL16_HIGHER: | |
8750 | case R_PPC64_TPREL16_HIGHERA: | |
8751 | case R_PPC64_TPREL16_HIGHEST: | |
8752 | case R_PPC64_TPREL16_HIGHESTA: | |
e1918d23 | 8753 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8754 | if (info->shared) |
8755 | /* The TPREL16 relocs shouldn't really be used in shared | |
8756 | libs as they will result in DT_TEXTREL being set, but | |
8757 | support them anyway. */ | |
8758 | goto dodyn; | |
8759 | break; | |
8760 | ||
8761 | case R_PPC64_DTPREL16: | |
8762 | case R_PPC64_DTPREL16_LO: | |
8763 | case R_PPC64_DTPREL16_HI: | |
8764 | case R_PPC64_DTPREL16_HA: | |
8765 | case R_PPC64_DTPREL16_DS: | |
8766 | case R_PPC64_DTPREL16_LO_DS: | |
8767 | case R_PPC64_DTPREL16_HIGHER: | |
8768 | case R_PPC64_DTPREL16_HIGHERA: | |
8769 | case R_PPC64_DTPREL16_HIGHEST: | |
8770 | case R_PPC64_DTPREL16_HIGHESTA: | |
e1918d23 | 8771 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8772 | break; |
8773 | ||
e515b051 AM |
8774 | case R_PPC64_DTPMOD64: |
8775 | relocation = 1; | |
8776 | addend = 0; | |
8777 | goto dodyn; | |
8778 | ||
411e1bfb | 8779 | case R_PPC64_TPREL64: |
e1918d23 | 8780 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8781 | goto dodyn; |
8782 | ||
8783 | case R_PPC64_DTPREL64: | |
e1918d23 | 8784 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8785 | /* Fall thru */ |
8786 | ||
65f38f15 AM |
8787 | /* Relocations that may need to be propagated if this is a |
8788 | dynamic object. */ | |
04c9666a | 8789 | case R_PPC64_REL30: |
65f38f15 AM |
8790 | case R_PPC64_REL32: |
8791 | case R_PPC64_REL64: | |
8792 | case R_PPC64_ADDR14: | |
8793 | case R_PPC64_ADDR14_BRNTAKEN: | |
8794 | case R_PPC64_ADDR14_BRTAKEN: | |
8795 | case R_PPC64_ADDR16: | |
8796 | case R_PPC64_ADDR16_DS: | |
8797 | case R_PPC64_ADDR16_HA: | |
8798 | case R_PPC64_ADDR16_HI: | |
8799 | case R_PPC64_ADDR16_HIGHER: | |
8800 | case R_PPC64_ADDR16_HIGHERA: | |
8801 | case R_PPC64_ADDR16_HIGHEST: | |
8802 | case R_PPC64_ADDR16_HIGHESTA: | |
8803 | case R_PPC64_ADDR16_LO: | |
8804 | case R_PPC64_ADDR16_LO_DS: | |
8805 | case R_PPC64_ADDR24: | |
65f38f15 AM |
8806 | case R_PPC64_ADDR32: |
8807 | case R_PPC64_ADDR64: | |
8808 | case R_PPC64_UADDR16: | |
8809 | case R_PPC64_UADDR32: | |
8810 | case R_PPC64_UADDR64: | |
ec338859 AM |
8811 | /* r_symndx will be zero only for relocs against symbols |
8812 | from removed linkonce sections, or sections discarded by | |
8813 | a linker script. */ | |
411e1bfb | 8814 | dodyn: |
5d1634d7 AM |
8815 | if (r_symndx == 0) |
8816 | break; | |
8817 | /* Fall thru. */ | |
8818 | ||
0b13192e | 8819 | dodyn2: |
5d1634d7 | 8820 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
8821 | break; |
8822 | ||
41bd81ab AM |
8823 | if (NO_OPD_RELOCS && is_opd) |
8824 | break; | |
8825 | ||
65f38f15 | 8826 | if ((info->shared |
4e795f50 AM |
8827 | && (h == NULL |
8828 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8829 | || h->root.type != bfd_link_hash_undefweak) | |
411e1bfb | 8830 | && (MUST_BE_DYN_RELOC (r_type) |
f6c52c13 | 8831 | || !SYMBOL_CALLS_LOCAL (info, h))) |
f4656909 AM |
8832 | || (ELIMINATE_COPY_RELOCS |
8833 | && !info->shared | |
65f38f15 AM |
8834 | && h != NULL |
8835 | && h->dynindx != -1 | |
8836 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
8837 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
8838 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
65f38f15 AM |
8839 | { |
8840 | Elf_Internal_Rela outrel; | |
b34976b6 | 8841 | bfd_boolean skip, relocate; |
65f38f15 | 8842 | asection *sreloc; |
947216bf | 8843 | bfd_byte *loc; |
1cf1f670 | 8844 | bfd_vma out_off; |
65f38f15 AM |
8845 | |
8846 | /* When generating a dynamic object, these relocations | |
8847 | are copied into the output file to be resolved at run | |
8848 | time. */ | |
8849 | ||
b34976b6 AM |
8850 | skip = FALSE; |
8851 | relocate = FALSE; | |
65f38f15 | 8852 | |
1cf1f670 AM |
8853 | out_off = _bfd_elf_section_offset (output_bfd, info, |
8854 | input_section, rel->r_offset); | |
8855 | if (out_off == (bfd_vma) -1) | |
b34976b6 | 8856 | skip = TRUE; |
1cf1f670 | 8857 | else if (out_off == (bfd_vma) -2) |
b34976b6 | 8858 | skip = TRUE, relocate = TRUE; |
1cf1f670 AM |
8859 | out_off += (input_section->output_section->vma |
8860 | + input_section->output_offset); | |
8861 | outrel.r_offset = out_off; | |
411e1bfb | 8862 | outrel.r_addend = rel->r_addend; |
65f38f15 | 8863 | |
1cf1f670 AM |
8864 | /* Optimize unaligned reloc use. */ |
8865 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) | |
8866 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) | |
8867 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; | |
8868 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) | |
8869 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) | |
8870 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; | |
8871 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) | |
8872 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) | |
8873 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; | |
8874 | ||
65f38f15 | 8875 | if (skip) |
0bb2d96a | 8876 | memset (&outrel, 0, sizeof outrel); |
f6c52c13 | 8877 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
0b13192e AM |
8878 | && !is_opd |
8879 | && r_type != R_PPC64_TOC) | |
0bb2d96a | 8880 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
65f38f15 AM |
8881 | else |
8882 | { | |
41bd81ab AM |
8883 | /* This symbol is local, or marked to become local, |
8884 | or this is an opd section reloc which must point | |
8885 | at a local function. */ | |
65f38f15 | 8886 | outrel.r_addend += relocation; |
e86ce104 | 8887 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 8888 | { |
3fad3c7c | 8889 | if (is_opd && h != NULL) |
afbe61cf AM |
8890 | { |
8891 | /* Lie about opd entries. This case occurs | |
8892 | when building shared libraries and we | |
8893 | reference a function in another shared | |
3fad3c7c AM |
8894 | lib. The same thing happens for a weak |
8895 | definition in an application that's | |
8896 | overridden by a strong definition in a | |
8897 | shared lib. (I believe this is a generic | |
8898 | bug in binutils handling of weak syms.) | |
8899 | In these cases we won't use the opd | |
1e2f5b6e | 8900 | entry in this lib. */ |
b34976b6 | 8901 | unresolved_reloc = FALSE; |
afbe61cf | 8902 | } |
65f38f15 | 8903 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
81407a69 AM |
8904 | |
8905 | /* We need to relocate .opd contents for ld.so. | |
8906 | Prelink also wants simple and consistent rules | |
8907 | for relocs. This make all RELATIVE relocs have | |
8908 | *r_offset equal to r_addend. */ | |
8909 | relocate = TRUE; | |
65f38f15 AM |
8910 | } |
8911 | else | |
8912 | { | |
8913 | long indx = 0; | |
8914 | ||
41bd81ab | 8915 | if (bfd_is_abs_section (sec)) |
65f38f15 AM |
8916 | ; |
8917 | else if (sec == NULL || sec->owner == NULL) | |
8918 | { | |
8919 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8920 | return FALSE; |
65f38f15 AM |
8921 | } |
8922 | else | |
8923 | { | |
8924 | asection *osec; | |
8925 | ||
8926 | osec = sec->output_section; | |
8927 | indx = elf_section_data (osec)->dynindx; | |
8928 | ||
8929 | /* We are turning this relocation into one | |
8930 | against a section symbol, so subtract out | |
8931 | the output section's address but not the | |
8932 | offset of the input section in the output | |
8933 | section. */ | |
8934 | outrel.r_addend -= osec->vma; | |
8935 | } | |
8936 | ||
8937 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
8938 | } | |
8939 | } | |
8940 | ||
8941 | sreloc = elf_section_data (input_section)->sreloc; | |
8942 | if (sreloc == NULL) | |
8943 | abort (); | |
8944 | ||
947216bf AM |
8945 | loc = sreloc->contents; |
8946 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
8947 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
8948 | ||
8949 | /* If this reloc is against an external symbol, it will | |
8950 | be computed at runtime, so there's no need to do | |
81407a69 AM |
8951 | anything now. However, for the sake of prelink ensure |
8952 | that the section contents are a known value. */ | |
65f38f15 | 8953 | if (! relocate) |
81407a69 AM |
8954 | { |
8955 | unresolved_reloc = FALSE; | |
8956 | /* The value chosen here is quite arbitrary as ld.so | |
8957 | ignores section contents except for the special | |
8958 | case of .opd where the contents might be accessed | |
8959 | before relocation. Choose zero, as that won't | |
8960 | cause reloc overflow. */ | |
8961 | relocation = 0; | |
8962 | addend = 0; | |
8963 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs | |
8964 | to improve backward compatibility with older | |
8965 | versions of ld. */ | |
8966 | if (r_type == R_PPC64_ADDR64) | |
8967 | addend = outrel.r_addend; | |
8968 | /* Adjust pc_relative relocs to have zero in *r_offset. */ | |
4ce794b7 | 8969 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
000732f7 AM |
8970 | addend = (input_section->output_section->vma |
8971 | + input_section->output_offset | |
8972 | + rel->r_offset); | |
81407a69 | 8973 | } |
65f38f15 | 8974 | } |
5bd4f169 AM |
8975 | break; |
8976 | ||
65f38f15 AM |
8977 | case R_PPC64_COPY: |
8978 | case R_PPC64_GLOB_DAT: | |
8979 | case R_PPC64_JMP_SLOT: | |
8980 | case R_PPC64_RELATIVE: | |
8981 | /* We shouldn't ever see these dynamic relocs in relocatable | |
8982 | files. */ | |
ae9a127f | 8983 | /* Fall through. */ |
65f38f15 AM |
8984 | |
8985 | case R_PPC64_PLTGOT16: | |
8986 | case R_PPC64_PLTGOT16_DS: | |
8987 | case R_PPC64_PLTGOT16_HA: | |
8988 | case R_PPC64_PLTGOT16_HI: | |
8989 | case R_PPC64_PLTGOT16_LO: | |
8990 | case R_PPC64_PLTGOT16_LO_DS: | |
8991 | case R_PPC64_PLTREL32: | |
8992 | case R_PPC64_PLTREL64: | |
8993 | /* These ones haven't been implemented yet. */ | |
8994 | ||
8995 | (*_bfd_error_handler) | |
d003868e AM |
8996 | (_("%B: relocation %s is not supported for symbol %s."), |
8997 | input_bfd, | |
4ce794b7 | 8998 | ppc64_elf_howto_table[r_type]->name, sym_name); |
5bd4f169 AM |
8999 | |
9000 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 9001 | ret = FALSE; |
5bd4f169 | 9002 | continue; |
65f38f15 | 9003 | } |
5bd4f169 | 9004 | |
65f38f15 AM |
9005 | /* Do any further special processing. */ |
9006 | switch (r_type) | |
9007 | { | |
9008 | default: | |
9009 | break; | |
9010 | ||
9011 | case R_PPC64_ADDR16_HA: | |
9012 | case R_PPC64_ADDR16_HIGHERA: | |
9013 | case R_PPC64_ADDR16_HIGHESTA: | |
86bbe32f AM |
9014 | case R_PPC64_GOT16_HA: |
9015 | case R_PPC64_PLTGOT16_HA: | |
65f38f15 AM |
9016 | case R_PPC64_PLT16_HA: |
9017 | case R_PPC64_TOC16_HA: | |
9018 | case R_PPC64_SECTOFF_HA: | |
411e1bfb AM |
9019 | case R_PPC64_TPREL16_HA: |
9020 | case R_PPC64_DTPREL16_HA: | |
9021 | case R_PPC64_GOT_TLSGD16_HA: | |
9022 | case R_PPC64_GOT_TLSLD16_HA: | |
9023 | case R_PPC64_GOT_TPREL16_HA: | |
9024 | case R_PPC64_GOT_DTPREL16_HA: | |
9025 | case R_PPC64_TPREL16_HIGHER: | |
9026 | case R_PPC64_TPREL16_HIGHERA: | |
9027 | case R_PPC64_TPREL16_HIGHEST: | |
9028 | case R_PPC64_TPREL16_HIGHESTA: | |
9029 | case R_PPC64_DTPREL16_HIGHER: | |
9030 | case R_PPC64_DTPREL16_HIGHERA: | |
9031 | case R_PPC64_DTPREL16_HIGHEST: | |
9032 | case R_PPC64_DTPREL16_HIGHESTA: | |
65f38f15 AM |
9033 | /* It's just possible that this symbol is a weak symbol |
9034 | that's not actually defined anywhere. In that case, | |
9035 | 'sec' would be NULL, and we should leave the symbol | |
9036 | alone (it will be set to zero elsewhere in the link). */ | |
9037 | if (sec != NULL) | |
e515b051 AM |
9038 | /* Add 0x10000 if sign bit in 0:15 is set. |
9039 | Bits 0:15 are not used. */ | |
9040 | addend += 0x8000; | |
65f38f15 AM |
9041 | break; |
9042 | ||
9043 | case R_PPC64_ADDR16_DS: | |
9044 | case R_PPC64_ADDR16_LO_DS: | |
9045 | case R_PPC64_GOT16_DS: | |
9046 | case R_PPC64_GOT16_LO_DS: | |
9047 | case R_PPC64_PLT16_LO_DS: | |
9048 | case R_PPC64_SECTOFF_DS: | |
9049 | case R_PPC64_SECTOFF_LO_DS: | |
9050 | case R_PPC64_TOC16_DS: | |
9051 | case R_PPC64_TOC16_LO_DS: | |
9052 | case R_PPC64_PLTGOT16_DS: | |
9053 | case R_PPC64_PLTGOT16_LO_DS: | |
411e1bfb AM |
9054 | case R_PPC64_GOT_TPREL16_DS: |
9055 | case R_PPC64_GOT_TPREL16_LO_DS: | |
9056 | case R_PPC64_GOT_DTPREL16_DS: | |
9057 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
9058 | case R_PPC64_TPREL16_DS: | |
9059 | case R_PPC64_TPREL16_LO_DS: | |
9060 | case R_PPC64_DTPREL16_DS: | |
9061 | case R_PPC64_DTPREL16_LO_DS: | |
adadcc0c AM |
9062 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
9063 | mask = 3; | |
9064 | /* If this reloc is against an lq insn, then the value must be | |
9065 | a multiple of 16. This is somewhat of a hack, but the | |
9066 | "correct" way to do this by defining _DQ forms of all the | |
9067 | _DS relocs bloats all reloc switches in this file. It | |
9068 | doesn't seem to make much sense to use any of these relocs | |
9069 | in data, so testing the insn should be safe. */ | |
494dac0c | 9070 | if ((insn & (0x3f << 26)) == (56u << 26)) |
adadcc0c AM |
9071 | mask = 15; |
9072 | if (((relocation + addend) & mask) != 0) | |
65f38f15 AM |
9073 | { |
9074 | (*_bfd_error_handler) | |
d003868e AM |
9075 | (_("%B: error: relocation %s not a multiple of %d"), |
9076 | input_bfd, | |
4ce794b7 | 9077 | ppc64_elf_howto_table[r_type]->name, |
adadcc0c | 9078 | mask + 1); |
65f38f15 | 9079 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 9080 | ret = FALSE; |
65f38f15 AM |
9081 | continue; |
9082 | } | |
9083 | break; | |
5bd4f169 AM |
9084 | } |
9085 | ||
239e1f3a AM |
9086 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
9087 | because such sections are not SEC_ALLOC and thus ld.so will | |
9088 | not process them. */ | |
65f38f15 | 9089 | if (unresolved_reloc |
239e1f3a | 9090 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
65f38f15 | 9091 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
9c07fe7c AM |
9092 | { |
9093 | (*_bfd_error_handler) | |
d003868e AM |
9094 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
9095 | input_bfd, | |
9096 | input_section, | |
9c07fe7c | 9097 | (long) rel->r_offset, |
7b609f53 | 9098 | ppc64_elf_howto_table[(int) r_type]->name, |
9c07fe7c | 9099 | h->root.root.string); |
b34976b6 | 9100 | ret = FALSE; |
9c07fe7c | 9101 | } |
5bd4f169 | 9102 | |
65f38f15 | 9103 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
9104 | input_bfd, |
9105 | input_section, | |
9106 | contents, | |
411e1bfb | 9107 | rel->r_offset, |
5bd4f169 AM |
9108 | relocation, |
9109 | addend); | |
9110 | ||
ef60b7ff | 9111 | if (r != bfd_reloc_ok) |
5bd4f169 | 9112 | { |
cd27b276 AM |
9113 | if (sym_name == NULL) |
9114 | sym_name = "(null)"; | |
9115 | if (r == bfd_reloc_overflow) | |
5bd4f169 | 9116 | { |
cd27b276 AM |
9117 | if (warned) |
9118 | continue; | |
9119 | if (h != NULL | |
9120 | && h->root.type == bfd_link_hash_undefweak | |
4ce794b7 | 9121 | && ppc64_elf_howto_table[r_type]->pc_relative) |
5bd4f169 AM |
9122 | { |
9123 | /* Assume this is a call protected by other code that | |
9124 | detects the symbol is undefined. If this is the case, | |
9125 | we can safely ignore the overflow. If not, the | |
9126 | program is hosed anyway, and a little warning isn't | |
9127 | going to help. */ | |
9128 | ||
9129 | continue; | |
9130 | } | |
9131 | ||
ef60b7ff | 9132 | if (!((*info->callbacks->reloc_overflow) |
4ce794b7 | 9133 | (info, sym_name, ppc64_elf_howto_table[r_type]->name, |
411e1bfb | 9134 | rel->r_addend, input_bfd, input_section, rel->r_offset))) |
b34976b6 | 9135 | return FALSE; |
ef60b7ff AM |
9136 | } |
9137 | else | |
9138 | { | |
9139 | (*_bfd_error_handler) | |
d003868e AM |
9140 | (_("%B(%A+0x%lx): %s reloc against `%s': error %d"), |
9141 | input_bfd, | |
9142 | input_section, | |
7b609f53 | 9143 | (long) rel->r_offset, |
4ce794b7 | 9144 | ppc64_elf_howto_table[r_type]->name, |
7b609f53 AM |
9145 | sym_name, |
9146 | (int) r); | |
b34976b6 | 9147 | ret = FALSE; |
ef60b7ff | 9148 | } |
5bd4f169 | 9149 | } |
5bd4f169 AM |
9150 | } |
9151 | ||
5bd4f169 AM |
9152 | return ret; |
9153 | } | |
9154 | ||
754021d0 AM |
9155 | /* Adjust the value of any local symbols in opd sections. */ |
9156 | ||
9157 | static bfd_boolean | |
9158 | ppc64_elf_output_symbol_hook (struct bfd_link_info *info, | |
9159 | const char *name ATTRIBUTE_UNUSED, | |
9160 | Elf_Internal_Sym *elfsym, | |
9161 | asection *input_sec, | |
9162 | struct elf_link_hash_entry *h) | |
9163 | { | |
4025353c | 9164 | long *opd_adjust, adjust; |
754021d0 AM |
9165 | bfd_vma value; |
9166 | ||
4025353c AM |
9167 | if (h != NULL) |
9168 | return TRUE; | |
9169 | ||
9170 | opd_adjust = get_opd_info (input_sec); | |
9171 | if (opd_adjust == NULL) | |
754021d0 AM |
9172 | return TRUE; |
9173 | ||
9174 | value = elfsym->st_value - input_sec->output_offset; | |
9175 | if (!info->relocatable) | |
9176 | value -= input_sec->output_section->vma; | |
9177 | ||
4025353c AM |
9178 | adjust = opd_adjust[value / 24]; |
9179 | if (adjust == -1) | |
9180 | elfsym->st_value = 0; | |
9181 | else | |
9182 | elfsym->st_value += adjust; | |
754021d0 AM |
9183 | return TRUE; |
9184 | } | |
9185 | ||
5bd4f169 AM |
9186 | /* Finish up dynamic symbol handling. We set the contents of various |
9187 | dynamic sections here. */ | |
9188 | ||
b34976b6 | 9189 | static bfd_boolean |
4ce794b7 AM |
9190 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
9191 | struct bfd_link_info *info, | |
9192 | struct elf_link_hash_entry *h, | |
9193 | Elf_Internal_Sym *sym) | |
5bd4f169 | 9194 | { |
65f38f15 | 9195 | struct ppc_link_hash_table *htab; |
5bd4f169 | 9196 | bfd *dynobj; |
8387904d AM |
9197 | struct plt_entry *ent; |
9198 | Elf_Internal_Rela rela; | |
9199 | bfd_byte *loc; | |
5bd4f169 | 9200 | |
65f38f15 AM |
9201 | htab = ppc_hash_table (info); |
9202 | dynobj = htab->elf.dynobj; | |
5bd4f169 | 9203 | |
8387904d AM |
9204 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
9205 | if (ent->plt.offset != (bfd_vma) -1) | |
9206 | { | |
9207 | /* This symbol has an entry in the procedure linkage | |
9208 | table. Set it up. */ | |
9209 | ||
9210 | if (htab->plt == NULL | |
9211 | || htab->relplt == NULL | |
9212 | || htab->glink == NULL) | |
9213 | abort (); | |
9214 | ||
9215 | /* Create a JMP_SLOT reloc to inform the dynamic linker to | |
9216 | fill in the PLT entry. */ | |
9217 | rela.r_offset = (htab->plt->output_section->vma | |
9218 | + htab->plt->output_offset | |
9219 | + ent->plt.offset); | |
9220 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); | |
9221 | rela.r_addend = ent->addend; | |
9222 | ||
9223 | loc = htab->relplt->contents; | |
9224 | loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE | |
9225 | * sizeof (Elf64_External_Rela)); | |
9226 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
9227 | } | |
5bd4f169 AM |
9228 | |
9229 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
9230 | { | |
5bd4f169 | 9231 | Elf_Internal_Rela rela; |
947216bf | 9232 | bfd_byte *loc; |
5bd4f169 | 9233 | |
65f38f15 | 9234 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 9235 | |
65f38f15 AM |
9236 | if (h->dynindx == -1 |
9237 | || (h->root.type != bfd_link_hash_defined | |
9238 | && h->root.type != bfd_link_hash_defweak) | |
4ce794b7 | 9239 | || htab->relbss == NULL) |
65f38f15 | 9240 | abort (); |
5bd4f169 AM |
9241 | |
9242 | rela.r_offset = (h->root.u.def.value | |
9243 | + h->root.u.def.section->output_section->vma | |
9244 | + h->root.u.def.section->output_offset); | |
9245 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
9246 | rela.r_addend = 0; | |
4ce794b7 AM |
9247 | loc = htab->relbss->contents; |
9248 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 9249 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
9250 | } |
9251 | ||
5bd4f169 AM |
9252 | /* Mark some specially defined symbols as absolute. */ |
9253 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
9254 | sym->st_shndx = SHN_ABS; | |
9255 | ||
b34976b6 | 9256 | return TRUE; |
5bd4f169 AM |
9257 | } |
9258 | ||
65f38f15 AM |
9259 | /* Used to decide how to sort relocs in an optimal manner for the |
9260 | dynamic linker, before writing them out. */ | |
9261 | ||
9262 | static enum elf_reloc_type_class | |
4ce794b7 | 9263 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
65f38f15 | 9264 | { |
04c9666a | 9265 | enum elf_ppc64_reloc_type r_type; |
a33d1f77 | 9266 | |
4ce794b7 | 9267 | r_type = ELF64_R_TYPE (rela->r_info); |
a33d1f77 | 9268 | switch (r_type) |
65f38f15 AM |
9269 | { |
9270 | case R_PPC64_RELATIVE: | |
9271 | return reloc_class_relative; | |
9272 | case R_PPC64_JMP_SLOT: | |
9273 | return reloc_class_plt; | |
9274 | case R_PPC64_COPY: | |
9275 | return reloc_class_copy; | |
9276 | default: | |
9277 | return reloc_class_normal; | |
9278 | } | |
9279 | } | |
9280 | ||
5bd4f169 AM |
9281 | /* Finish up the dynamic sections. */ |
9282 | ||
b34976b6 | 9283 | static bfd_boolean |
4ce794b7 AM |
9284 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
9285 | struct bfd_link_info *info) | |
5bd4f169 | 9286 | { |
65f38f15 AM |
9287 | struct ppc_link_hash_table *htab; |
9288 | bfd *dynobj; | |
5bd4f169 | 9289 | asection *sdyn; |
5bd4f169 | 9290 | |
65f38f15 AM |
9291 | htab = ppc_hash_table (info); |
9292 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
9293 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
9294 | ||
65f38f15 | 9295 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 9296 | { |
5bd4f169 AM |
9297 | Elf64_External_Dyn *dyncon, *dynconend; |
9298 | ||
4ce794b7 | 9299 | if (sdyn == NULL || htab->got == NULL) |
65f38f15 | 9300 | abort (); |
5bd4f169 AM |
9301 | |
9302 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
eea6121a | 9303 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
5bd4f169 AM |
9304 | for (; dyncon < dynconend; dyncon++) |
9305 | { | |
9306 | Elf_Internal_Dyn dyn; | |
19397422 | 9307 | asection *s; |
5bd4f169 AM |
9308 | |
9309 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
9310 | ||
9311 | switch (dyn.d_tag) | |
9312 | { | |
65f38f15 AM |
9313 | default: |
9314 | continue; | |
5bd4f169 | 9315 | |
5d1634d7 | 9316 | case DT_PPC64_GLINK: |
4ce794b7 | 9317 | s = htab->glink; |
6348e046 | 9318 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
ad8e1ba5 AM |
9319 | /* We stupidly defined DT_PPC64_GLINK to be the start |
9320 | of glink rather than the first entry point, which is | |
9321 | what ld.so needs, and now have a bigger stub to | |
9322 | support automatic multiple TOCs. */ | |
9323 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; | |
5d1634d7 AM |
9324 | break; |
9325 | ||
19397422 AM |
9326 | case DT_PPC64_OPD: |
9327 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
9328 | if (s == NULL) |
9329 | continue; | |
9330 | dyn.d_un.d_ptr = s->vma; | |
19397422 AM |
9331 | break; |
9332 | ||
9333 | case DT_PPC64_OPDSZ: | |
9334 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
9335 | if (s == NULL) |
9336 | continue; | |
eea6121a | 9337 | dyn.d_un.d_val = s->size; |
19397422 AM |
9338 | break; |
9339 | ||
65f38f15 | 9340 | case DT_PLTGOT: |
4ce794b7 | 9341 | s = htab->plt; |
6348e046 | 9342 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 AM |
9343 | break; |
9344 | ||
9345 | case DT_JMPREL: | |
4ce794b7 | 9346 | s = htab->relplt; |
6348e046 | 9347 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 | 9348 | break; |
5bd4f169 | 9349 | |
65f38f15 | 9350 | case DT_PLTRELSZ: |
eea6121a | 9351 | dyn.d_un.d_val = htab->relplt->size; |
5d1634d7 AM |
9352 | break; |
9353 | ||
9354 | case DT_RELASZ: | |
9355 | /* Don't count procedure linkage table relocs in the | |
9356 | overall reloc count. */ | |
4ce794b7 | 9357 | s = htab->relplt; |
6348e046 AM |
9358 | if (s == NULL) |
9359 | continue; | |
eea6121a | 9360 | dyn.d_un.d_val -= s->size; |
6348e046 AM |
9361 | break; |
9362 | ||
9363 | case DT_RELA: | |
9364 | /* We may not be using the standard ELF linker script. | |
9365 | If .rela.plt is the first .rela section, we adjust | |
9366 | DT_RELA to not include it. */ | |
4ce794b7 | 9367 | s = htab->relplt; |
6348e046 AM |
9368 | if (s == NULL) |
9369 | continue; | |
9370 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
9371 | continue; | |
eea6121a | 9372 | dyn.d_un.d_ptr += s->size; |
65f38f15 | 9373 | break; |
5bd4f169 | 9374 | } |
5bd4f169 | 9375 | |
65f38f15 | 9376 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 9377 | } |
5bd4f169 AM |
9378 | } |
9379 | ||
eea6121a | 9380 | if (htab->got != NULL && htab->got->size != 0) |
5d1634d7 AM |
9381 | { |
9382 | /* Fill in the first entry in the global offset table. | |
9383 | We use it to hold the link-time TOCbase. */ | |
9384 | bfd_put_64 (output_bfd, | |
60ee0d4a | 9385 | elf_gp (output_bfd) + TOC_BASE_OFF, |
4ce794b7 | 9386 | htab->got->contents); |
5d1634d7 AM |
9387 | |
9388 | /* Set .got entry size. */ | |
4ce794b7 | 9389 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
5d1634d7 AM |
9390 | } |
9391 | ||
eea6121a | 9392 | if (htab->plt != NULL && htab->plt->size != 0) |
5d1634d7 AM |
9393 | { |
9394 | /* Set .plt entry size. */ | |
4ce794b7 | 9395 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
5d1634d7 AM |
9396 | = PLT_ENTRY_SIZE; |
9397 | } | |
9398 | ||
e717da7e AM |
9399 | /* We need to handle writing out multiple GOT sections ourselves, |
9400 | since we didn't add them to DYNOBJ. */ | |
9401 | while ((dynobj = dynobj->link_next) != NULL) | |
9402 | { | |
9403 | asection *s; | |
9404 | s = ppc64_elf_tdata (dynobj)->got; | |
9405 | if (s != NULL | |
eea6121a | 9406 | && s->size != 0 |
e717da7e AM |
9407 | && s->output_section != bfd_abs_section_ptr |
9408 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
9409 | s->contents, s->output_offset, | |
eea6121a | 9410 | s->size)) |
e717da7e AM |
9411 | return FALSE; |
9412 | s = ppc64_elf_tdata (dynobj)->relgot; | |
9413 | if (s != NULL | |
eea6121a | 9414 | && s->size != 0 |
e717da7e AM |
9415 | && s->output_section != bfd_abs_section_ptr |
9416 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
9417 | s->contents, s->output_offset, | |
eea6121a | 9418 | s->size)) |
e717da7e AM |
9419 | return FALSE; |
9420 | } | |
f6c52c13 | 9421 | |
b34976b6 | 9422 | return TRUE; |
5bd4f169 AM |
9423 | } |
9424 | ||
5bd4f169 | 9425 | #include "elf64-target.h" |