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 **); |
2441e016 AM |
38 | static bfd_reloc_status_type ppc64_elf_branch_reloc |
39 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
805fc799 | 40 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
4ce794b7 | 41 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 42 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
4ce794b7 | 43 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 44 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
4ce794b7 | 45 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 46 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
4ce794b7 | 47 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 48 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
4ce794b7 | 49 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 50 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
4ce794b7 | 51 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 52 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
4ce794b7 | 53 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
2441e016 AM |
54 | static bfd_vma opd_entry_value |
55 | (asection *, bfd_vma, asection **, bfd_vma *); | |
5bd4f169 | 56 | |
ad8e1ba5 AM |
57 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
58 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
59 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
60 | #define TARGET_BIG_NAME "elf64-powerpc" | |
61 | #define ELF_ARCH bfd_arch_powerpc | |
62 | #define ELF_MACHINE_CODE EM_PPC64 | |
63 | #define ELF_MAXPAGESIZE 0x10000 | |
64 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
65 | ||
66 | #define elf_backend_want_got_sym 0 | |
67 | #define elf_backend_want_plt_sym 0 | |
68 | #define elf_backend_plt_alignment 3 | |
69 | #define elf_backend_plt_not_loaded 1 | |
70 | #define elf_backend_got_symbol_offset 0 | |
71 | #define elf_backend_got_header_size 8 | |
ad8e1ba5 AM |
72 | #define elf_backend_can_gc_sections 1 |
73 | #define elf_backend_can_refcount 1 | |
74 | #define elf_backend_rela_normal 1 | |
75 | ||
e717da7e | 76 | #define bfd_elf64_mkobject ppc64_elf_mkobject |
ad8e1ba5 AM |
77 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
78 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data | |
79 | #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook | |
80 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create | |
81 | #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free | |
82 | ||
83 | #define elf_backend_object_p ppc64_elf_object_p | |
d37c89e5 AM |
84 | #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus |
85 | #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo | |
ad8e1ba5 AM |
86 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
87 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
555cd476 | 88 | #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook |
8387904d AM |
89 | #define elf_backend_check_directives ppc64_elf_check_directives |
90 | #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup | |
ad8e1ba5 AM |
91 | #define elf_backend_check_relocs ppc64_elf_check_relocs |
92 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
93 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
94 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
95 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol | |
96 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
97 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
98 | #define elf_backend_relocate_section ppc64_elf_relocate_section | |
99 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
100 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
101 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
754021d0 | 102 | #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook |
2f89ff8d | 103 | #define elf_backend_special_sections ppc64_elf_special_sections |
ad8e1ba5 | 104 | |
5bd4f169 AM |
105 | /* The name of the dynamic interpreter. This is put in the .interp |
106 | section. */ | |
107 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
108 | ||
109 | /* The size in bytes of an entry in the procedure linkage table. */ | |
110 | #define PLT_ENTRY_SIZE 24 | |
111 | ||
112 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 113 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
114 | |
115 | /* TOC base pointers offset from start of TOC. */ | |
411e1bfb AM |
116 | #define TOC_BASE_OFF 0x8000 |
117 | ||
118 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
119 | #define TP_OFFSET 0x7000 | |
120 | #define DTP_OFFSET 0x8000 | |
5bd4f169 | 121 | |
ad8e1ba5 AM |
122 | /* .plt call stub instructions. The normal stub is like this, but |
123 | sometimes the .plt entry crosses a 64k boundary and we need to | |
124 | insert an addis to adjust r12. */ | |
125 | #define PLT_CALL_STUB_SIZE (7*4) | |
5d1634d7 AM |
126 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
127 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
128 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
129 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
130 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
131 | /* ld %r11,xxx+16@l(%r12) */ | |
132 | #define BCTR 0x4e800420 /* bctr */ | |
133 | ||
5d1634d7 | 134 | |
ad8e1ba5 AM |
135 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
136 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ | |
137 | ||
138 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
139 | ||
140 | /* glink call stub instructions. We enter with the index in R0, and the | |
141 | address of glink entry in CTR. From that, we can calculate PLT0. */ | |
142 | #define GLINK_CALL_STUB_SIZE (16*4) | |
143 | #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */ | |
144 | #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */ | |
145 | #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */ | |
146 | #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */ | |
147 | #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */ | |
148 | #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */ | |
149 | #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */ | |
150 | /* sub %r12,%r12,%r11 */ | |
151 | #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */ | |
152 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */ | |
153 | /* ld %r11,xxx@l(%r12) */ | |
154 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */ | |
155 | /* ld %r2,8(%r12) */ | |
156 | /* mtctr %r11 */ | |
157 | /* ld %r11,16(%r12) */ | |
158 | /* bctr */ | |
5d1634d7 AM |
159 | |
160 | /* Pad with this. */ | |
161 | #define NOP 0x60000000 | |
162 | ||
721956f4 AM |
163 | /* Some other nops. */ |
164 | #define CROR_151515 0x4def7b82 | |
165 | #define CROR_313131 0x4ffffb82 | |
166 | ||
cedb70c5 | 167 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
168 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
169 | #define B_DOT 0x48000000 /* b . */ | |
170 | ||
171 | /* After that, we need two instructions to load the index, followed by | |
172 | a branch. */ | |
173 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 174 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 175 | |
82bd7b59 AM |
176 | /* Instructions to save and restore floating point regs. */ |
177 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ | |
178 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
179 | #define BLR 0x4e800020 /* blr */ | |
180 | ||
41bd81ab AM |
181 | /* Since .opd is an array of descriptors and each entry will end up |
182 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
183 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 184 | relocate .opd without reloc entries. */ |
41bd81ab AM |
185 | #ifndef NO_OPD_RELOCS |
186 | #define NO_OPD_RELOCS 0 | |
187 | #endif | |
5bd4f169 | 188 | \f |
f5e87a1d | 189 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 190 | |
5bd4f169 | 191 | /* Relocation HOWTO's. */ |
04c9666a | 192 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
5bd4f169 AM |
193 | |
194 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
195 | /* This reloc does nothing. */ | |
196 | HOWTO (R_PPC64_NONE, /* type */ | |
197 | 0, /* rightshift */ | |
411e1bfb AM |
198 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
199 | 32, /* bitsize */ | |
b34976b6 | 200 | FALSE, /* pc_relative */ |
5bd4f169 | 201 | 0, /* bitpos */ |
f5e87a1d | 202 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
203 | bfd_elf_generic_reloc, /* special_function */ |
204 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 205 | FALSE, /* partial_inplace */ |
d006db6c | 206 | 0, /* src_mask */ |
5bd4f169 | 207 | 0, /* dst_mask */ |
b34976b6 | 208 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
209 | |
210 | /* A standard 32 bit relocation. */ | |
211 | HOWTO (R_PPC64_ADDR32, /* type */ | |
212 | 0, /* rightshift */ | |
213 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
214 | 32, /* bitsize */ | |
b34976b6 | 215 | FALSE, /* pc_relative */ |
5bd4f169 AM |
216 | 0, /* bitpos */ |
217 | complain_overflow_bitfield, /* complain_on_overflow */ | |
218 | bfd_elf_generic_reloc, /* special_function */ | |
219 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 220 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
221 | 0, /* src_mask */ |
222 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 223 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
224 | |
225 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
226 | FIXME: we don't check that, we just clear them. */ | |
227 | HOWTO (R_PPC64_ADDR24, /* type */ | |
228 | 0, /* rightshift */ | |
229 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
230 | 26, /* bitsize */ | |
b34976b6 | 231 | FALSE, /* pc_relative */ |
5bd4f169 AM |
232 | 0, /* bitpos */ |
233 | complain_overflow_bitfield, /* complain_on_overflow */ | |
234 | bfd_elf_generic_reloc, /* special_function */ | |
235 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 236 | FALSE, /* partial_inplace */ |
d006db6c | 237 | 0, /* src_mask */ |
f5e87a1d | 238 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 239 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
240 | |
241 | /* A standard 16 bit relocation. */ | |
242 | HOWTO (R_PPC64_ADDR16, /* type */ | |
243 | 0, /* rightshift */ | |
244 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
245 | 16, /* bitsize */ | |
b34976b6 | 246 | FALSE, /* pc_relative */ |
5bd4f169 AM |
247 | 0, /* bitpos */ |
248 | complain_overflow_bitfield, /* complain_on_overflow */ | |
249 | bfd_elf_generic_reloc, /* special_function */ | |
250 | "R_PPC64_ADDR16", /* name */ | |
b34976b6 | 251 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
252 | 0, /* src_mask */ |
253 | 0xffff, /* dst_mask */ | |
b34976b6 | 254 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
255 | |
256 | /* A 16 bit relocation without overflow. */ | |
257 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
258 | 0, /* rightshift */ | |
259 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
260 | 16, /* bitsize */ | |
b34976b6 | 261 | FALSE, /* pc_relative */ |
5bd4f169 AM |
262 | 0, /* bitpos */ |
263 | complain_overflow_dont,/* complain_on_overflow */ | |
264 | bfd_elf_generic_reloc, /* special_function */ | |
265 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 266 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
267 | 0, /* src_mask */ |
268 | 0xffff, /* dst_mask */ | |
b34976b6 | 269 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
270 | |
271 | /* Bits 16-31 of an address. */ | |
272 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
273 | 16, /* rightshift */ | |
274 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
275 | 16, /* bitsize */ | |
b34976b6 | 276 | FALSE, /* pc_relative */ |
5bd4f169 AM |
277 | 0, /* bitpos */ |
278 | complain_overflow_dont, /* complain_on_overflow */ | |
279 | bfd_elf_generic_reloc, /* special_function */ | |
280 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 281 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
282 | 0, /* src_mask */ |
283 | 0xffff, /* dst_mask */ | |
b34976b6 | 284 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
285 | |
286 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
287 | bits, treated as a signed number, is negative. */ | |
288 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
289 | 16, /* rightshift */ | |
290 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
291 | 16, /* bitsize */ | |
b34976b6 | 292 | FALSE, /* pc_relative */ |
5bd4f169 AM |
293 | 0, /* bitpos */ |
294 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 295 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 296 | "R_PPC64_ADDR16_HA", /* name */ |
b34976b6 | 297 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
298 | 0, /* src_mask */ |
299 | 0xffff, /* dst_mask */ | |
b34976b6 | 300 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
301 | |
302 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
303 | FIXME: we don't check that, we just clear them. */ | |
304 | HOWTO (R_PPC64_ADDR14, /* type */ | |
305 | 0, /* rightshift */ | |
306 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
307 | 16, /* bitsize */ | |
b34976b6 | 308 | FALSE, /* pc_relative */ |
5bd4f169 AM |
309 | 0, /* bitpos */ |
310 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2441e016 | 311 | ppc64_elf_branch_reloc, /* special_function */ |
5bd4f169 | 312 | "R_PPC64_ADDR14", /* name */ |
b34976b6 | 313 | FALSE, /* partial_inplace */ |
d006db6c | 314 | 0, /* src_mask */ |
f5e87a1d | 315 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 316 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
317 | |
318 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
319 | indicate that the branch is expected to be taken. The lower two | |
320 | bits must be zero. */ | |
321 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
322 | 0, /* rightshift */ | |
323 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
324 | 16, /* bitsize */ | |
b34976b6 | 325 | FALSE, /* pc_relative */ |
5bd4f169 AM |
326 | 0, /* bitpos */ |
327 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 328 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 329 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 330 | FALSE, /* partial_inplace */ |
d006db6c | 331 | 0, /* src_mask */ |
f5e87a1d | 332 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 333 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
334 | |
335 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
336 | indicate that the branch is not expected to be taken. The lower | |
337 | two bits must be zero. */ | |
338 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
339 | 0, /* rightshift */ | |
340 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
341 | 16, /* bitsize */ | |
b34976b6 | 342 | FALSE, /* pc_relative */ |
5bd4f169 AM |
343 | 0, /* bitpos */ |
344 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 345 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 346 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 347 | FALSE, /* partial_inplace */ |
d006db6c | 348 | 0, /* src_mask */ |
f5e87a1d | 349 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 350 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
351 | |
352 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
353 | HOWTO (R_PPC64_REL24, /* type */ | |
354 | 0, /* rightshift */ | |
355 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
356 | 26, /* bitsize */ | |
b34976b6 | 357 | TRUE, /* pc_relative */ |
5bd4f169 AM |
358 | 0, /* bitpos */ |
359 | complain_overflow_signed, /* complain_on_overflow */ | |
2441e016 | 360 | ppc64_elf_branch_reloc, /* special_function */ |
5bd4f169 | 361 | "R_PPC64_REL24", /* name */ |
b34976b6 | 362 | FALSE, /* partial_inplace */ |
d006db6c | 363 | 0, /* src_mask */ |
f5e87a1d | 364 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 365 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
366 | |
367 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
368 | HOWTO (R_PPC64_REL14, /* type */ | |
369 | 0, /* rightshift */ | |
370 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
371 | 16, /* bitsize */ | |
b34976b6 | 372 | TRUE, /* pc_relative */ |
5bd4f169 AM |
373 | 0, /* bitpos */ |
374 | complain_overflow_signed, /* complain_on_overflow */ | |
2441e016 | 375 | ppc64_elf_branch_reloc, /* special_function */ |
5bd4f169 | 376 | "R_PPC64_REL14", /* name */ |
b34976b6 | 377 | FALSE, /* partial_inplace */ |
d006db6c | 378 | 0, /* src_mask */ |
f5e87a1d | 379 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 380 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
381 | |
382 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
383 | the branch is expected to be taken. The lower two bits must be | |
384 | zero. */ | |
385 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
386 | 0, /* rightshift */ | |
387 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
388 | 16, /* bitsize */ | |
b34976b6 | 389 | TRUE, /* pc_relative */ |
5bd4f169 AM |
390 | 0, /* bitpos */ |
391 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 392 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 393 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 394 | FALSE, /* partial_inplace */ |
d006db6c | 395 | 0, /* src_mask */ |
f5e87a1d | 396 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 397 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
398 | |
399 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
400 | the branch is not expected to be taken. The lower two bits must | |
401 | be zero. */ | |
402 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
403 | 0, /* rightshift */ | |
404 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
405 | 16, /* bitsize */ | |
b34976b6 | 406 | TRUE, /* pc_relative */ |
5bd4f169 AM |
407 | 0, /* bitpos */ |
408 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 409 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 410 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 411 | FALSE, /* partial_inplace */ |
d006db6c | 412 | 0, /* src_mask */ |
f5e87a1d | 413 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 414 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
415 | |
416 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
417 | symbol. */ | |
418 | HOWTO (R_PPC64_GOT16, /* type */ | |
419 | 0, /* rightshift */ | |
420 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
421 | 16, /* bitsize */ | |
b34976b6 | 422 | FALSE, /* pc_relative */ |
5bd4f169 AM |
423 | 0, /* bitpos */ |
424 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 425 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 426 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 427 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
428 | 0, /* src_mask */ |
429 | 0xffff, /* dst_mask */ | |
b34976b6 | 430 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
431 | |
432 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
433 | the symbol. */ | |
434 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
435 | 0, /* rightshift */ | |
436 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
437 | 16, /* bitsize */ | |
b34976b6 | 438 | FALSE, /* pc_relative */ |
5bd4f169 AM |
439 | 0, /* bitpos */ |
440 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 441 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 442 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 443 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
444 | 0, /* src_mask */ |
445 | 0xffff, /* dst_mask */ | |
b34976b6 | 446 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
447 | |
448 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
449 | the symbol. */ | |
450 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
451 | 16, /* rightshift */ | |
452 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
453 | 16, /* bitsize */ | |
b34976b6 | 454 | FALSE, /* pc_relative */ |
5bd4f169 AM |
455 | 0, /* bitpos */ |
456 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 457 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 458 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 459 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
460 | 0, /* src_mask */ |
461 | 0xffff, /* dst_mask */ | |
b34976b6 | 462 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
463 | |
464 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
465 | the symbol. */ | |
466 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
467 | 16, /* rightshift */ | |
468 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
469 | 16, /* bitsize */ | |
b34976b6 | 470 | FALSE, /* pc_relative */ |
5bd4f169 AM |
471 | 0, /* bitpos */ |
472 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 473 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 474 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 475 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
476 | 0, /* src_mask */ |
477 | 0xffff, /* dst_mask */ | |
b34976b6 | 478 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
479 | |
480 | /* This is used only by the dynamic linker. The symbol should exist | |
481 | both in the object being run and in some shared library. The | |
482 | dynamic linker copies the data addressed by the symbol from the | |
483 | shared library into the object, because the object being | |
484 | run has to have the data at some particular address. */ | |
485 | HOWTO (R_PPC64_COPY, /* type */ | |
486 | 0, /* rightshift */ | |
f5e87a1d AM |
487 | 0, /* this one is variable size */ |
488 | 0, /* bitsize */ | |
b34976b6 | 489 | FALSE, /* pc_relative */ |
5bd4f169 | 490 | 0, /* bitpos */ |
f5e87a1d AM |
491 | complain_overflow_dont, /* complain_on_overflow */ |
492 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 493 | "R_PPC64_COPY", /* name */ |
b34976b6 | 494 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
495 | 0, /* src_mask */ |
496 | 0, /* dst_mask */ | |
b34976b6 | 497 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
498 | |
499 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
500 | entries. */ | |
501 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
502 | 0, /* rightshift */ | |
503 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
504 | 64, /* bitsize */ | |
b34976b6 | 505 | FALSE, /* pc_relative */ |
5bd4f169 AM |
506 | 0, /* bitpos */ |
507 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 508 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 509 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 510 | FALSE, /* partial_inplace */ |
5bd4f169 | 511 | 0, /* src_mask */ |
f5e87a1d | 512 | ONES (64), /* dst_mask */ |
b34976b6 | 513 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
514 | |
515 | /* Created by the link editor. Marks a procedure linkage table | |
516 | entry for a symbol. */ | |
517 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
518 | 0, /* rightshift */ | |
519 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
520 | 0, /* bitsize */ | |
b34976b6 | 521 | FALSE, /* pc_relative */ |
5bd4f169 AM |
522 | 0, /* bitpos */ |
523 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 524 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 525 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 526 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
527 | 0, /* src_mask */ |
528 | 0, /* dst_mask */ | |
b34976b6 | 529 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
530 | |
531 | /* Used only by the dynamic linker. When the object is run, this | |
532 | doubleword64 is set to the load address of the object, plus the | |
533 | addend. */ | |
534 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
535 | 0, /* rightshift */ | |
536 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
537 | 64, /* bitsize */ | |
b34976b6 | 538 | FALSE, /* pc_relative */ |
5bd4f169 AM |
539 | 0, /* bitpos */ |
540 | complain_overflow_dont, /* complain_on_overflow */ | |
541 | bfd_elf_generic_reloc, /* special_function */ | |
542 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 543 | FALSE, /* partial_inplace */ |
5bd4f169 | 544 | 0, /* src_mask */ |
f5e87a1d | 545 | ONES (64), /* dst_mask */ |
b34976b6 | 546 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
547 | |
548 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
549 | HOWTO (R_PPC64_UADDR32, /* type */ | |
550 | 0, /* rightshift */ | |
551 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
552 | 32, /* bitsize */ | |
b34976b6 | 553 | FALSE, /* pc_relative */ |
5bd4f169 AM |
554 | 0, /* bitpos */ |
555 | complain_overflow_bitfield, /* complain_on_overflow */ | |
556 | bfd_elf_generic_reloc, /* special_function */ | |
557 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 558 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
559 | 0, /* src_mask */ |
560 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 561 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
562 | |
563 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
564 | HOWTO (R_PPC64_UADDR16, /* type */ | |
565 | 0, /* rightshift */ | |
566 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
567 | 16, /* bitsize */ | |
b34976b6 | 568 | FALSE, /* pc_relative */ |
5bd4f169 AM |
569 | 0, /* bitpos */ |
570 | complain_overflow_bitfield, /* complain_on_overflow */ | |
571 | bfd_elf_generic_reloc, /* special_function */ | |
572 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 573 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
574 | 0, /* src_mask */ |
575 | 0xffff, /* dst_mask */ | |
b34976b6 | 576 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
577 | |
578 | /* 32-bit PC relative. */ | |
579 | HOWTO (R_PPC64_REL32, /* type */ | |
580 | 0, /* rightshift */ | |
581 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
582 | 32, /* bitsize */ | |
b34976b6 | 583 | TRUE, /* pc_relative */ |
5bd4f169 | 584 | 0, /* bitpos */ |
cedb70c5 | 585 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
586 | complain_overflow_signed, /* complain_on_overflow */ |
587 | bfd_elf_generic_reloc, /* special_function */ | |
588 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 589 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
590 | 0, /* src_mask */ |
591 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 592 | TRUE), /* pcrel_offset */ |
5bd4f169 | 593 | |
10ed1bba | 594 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
595 | HOWTO (R_PPC64_PLT32, /* type */ |
596 | 0, /* rightshift */ | |
597 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
598 | 32, /* bitsize */ | |
b34976b6 | 599 | FALSE, /* pc_relative */ |
5bd4f169 AM |
600 | 0, /* bitpos */ |
601 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 602 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 603 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 604 | FALSE, /* partial_inplace */ |
5bd4f169 | 605 | 0, /* src_mask */ |
f5e87a1d | 606 | 0xffffffff, /* dst_mask */ |
b34976b6 | 607 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
608 | |
609 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
610 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
611 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
612 | 0, /* rightshift */ | |
613 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
614 | 32, /* bitsize */ | |
b34976b6 | 615 | TRUE, /* pc_relative */ |
5bd4f169 AM |
616 | 0, /* bitpos */ |
617 | complain_overflow_signed, /* complain_on_overflow */ | |
618 | bfd_elf_generic_reloc, /* special_function */ | |
619 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 620 | FALSE, /* partial_inplace */ |
5bd4f169 | 621 | 0, /* src_mask */ |
f5e87a1d | 622 | 0xffffffff, /* dst_mask */ |
b34976b6 | 623 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
624 | |
625 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
626 | the symbol. */ | |
627 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
628 | 0, /* rightshift */ | |
629 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
630 | 16, /* bitsize */ | |
b34976b6 | 631 | FALSE, /* pc_relative */ |
5bd4f169 AM |
632 | 0, /* bitpos */ |
633 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 634 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 635 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 636 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
637 | 0, /* src_mask */ |
638 | 0xffff, /* dst_mask */ | |
b34976b6 | 639 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
640 | |
641 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
642 | the symbol. */ | |
643 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
644 | 16, /* rightshift */ | |
645 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
646 | 16, /* bitsize */ | |
b34976b6 | 647 | FALSE, /* pc_relative */ |
5bd4f169 AM |
648 | 0, /* bitpos */ |
649 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 650 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 651 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 652 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
653 | 0, /* src_mask */ |
654 | 0xffff, /* dst_mask */ | |
b34976b6 | 655 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
656 | |
657 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
658 | the symbol. */ | |
659 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
660 | 16, /* rightshift */ | |
661 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
662 | 16, /* bitsize */ | |
b34976b6 | 663 | FALSE, /* pc_relative */ |
5bd4f169 AM |
664 | 0, /* bitpos */ |
665 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 666 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 667 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 668 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
669 | 0, /* src_mask */ |
670 | 0xffff, /* dst_mask */ | |
b34976b6 | 671 | FALSE), /* pcrel_offset */ |
5bd4f169 | 672 | |
c061c2d8 | 673 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
674 | HOWTO (R_PPC64_SECTOFF, /* type */ |
675 | 0, /* rightshift */ | |
c061c2d8 AM |
676 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
677 | 16, /* bitsize */ | |
b34976b6 | 678 | FALSE, /* pc_relative */ |
5bd4f169 AM |
679 | 0, /* bitpos */ |
680 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 681 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 682 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 683 | FALSE, /* partial_inplace */ |
5bd4f169 | 684 | 0, /* src_mask */ |
c061c2d8 | 685 | 0xffff, /* dst_mask */ |
b34976b6 | 686 | FALSE), /* pcrel_offset */ |
5bd4f169 | 687 | |
c061c2d8 | 688 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
689 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
690 | 0, /* rightshift */ | |
691 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
692 | 16, /* bitsize */ | |
b34976b6 | 693 | FALSE, /* pc_relative */ |
5bd4f169 AM |
694 | 0, /* bitpos */ |
695 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 696 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 697 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 698 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
699 | 0, /* src_mask */ |
700 | 0xffff, /* dst_mask */ | |
b34976b6 | 701 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
702 | |
703 | /* 16-bit upper half section relative relocation. */ | |
704 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
705 | 16, /* rightshift */ | |
706 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
707 | 16, /* bitsize */ | |
b34976b6 | 708 | FALSE, /* pc_relative */ |
5bd4f169 AM |
709 | 0, /* bitpos */ |
710 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 711 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 712 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 713 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
714 | 0, /* src_mask */ |
715 | 0xffff, /* dst_mask */ | |
b34976b6 | 716 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
717 | |
718 | /* 16-bit upper half adjusted section relative relocation. */ | |
719 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
720 | 16, /* rightshift */ | |
721 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
722 | 16, /* bitsize */ | |
b34976b6 | 723 | FALSE, /* pc_relative */ |
5bd4f169 AM |
724 | 0, /* bitpos */ |
725 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 726 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 727 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 728 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
729 | 0, /* src_mask */ |
730 | 0xffff, /* dst_mask */ | |
b34976b6 | 731 | FALSE), /* pcrel_offset */ |
5bd4f169 | 732 | |
04c9666a AM |
733 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
734 | HOWTO (R_PPC64_REL30, /* type */ | |
5bd4f169 AM |
735 | 2, /* rightshift */ |
736 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
737 | 30, /* bitsize */ | |
b34976b6 | 738 | TRUE, /* pc_relative */ |
5bd4f169 AM |
739 | 0, /* bitpos */ |
740 | complain_overflow_dont, /* complain_on_overflow */ | |
741 | bfd_elf_generic_reloc, /* special_function */ | |
04c9666a | 742 | "R_PPC64_REL30", /* name */ |
b34976b6 | 743 | FALSE, /* partial_inplace */ |
d006db6c | 744 | 0, /* src_mask */ |
5bd4f169 | 745 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 746 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
747 | |
748 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
749 | ||
750 | /* A standard 64-bit relocation. */ | |
751 | HOWTO (R_PPC64_ADDR64, /* type */ | |
752 | 0, /* rightshift */ | |
753 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
754 | 64, /* bitsize */ | |
b34976b6 | 755 | FALSE, /* pc_relative */ |
5bd4f169 AM |
756 | 0, /* bitpos */ |
757 | complain_overflow_dont, /* complain_on_overflow */ | |
758 | bfd_elf_generic_reloc, /* special_function */ | |
759 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 760 | FALSE, /* partial_inplace */ |
5bd4f169 | 761 | 0, /* src_mask */ |
f5e87a1d | 762 | ONES (64), /* dst_mask */ |
b34976b6 | 763 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
764 | |
765 | /* The bits 32-47 of an address. */ | |
766 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
767 | 32, /* rightshift */ | |
768 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
769 | 16, /* bitsize */ | |
b34976b6 | 770 | FALSE, /* pc_relative */ |
5bd4f169 AM |
771 | 0, /* bitpos */ |
772 | complain_overflow_dont, /* complain_on_overflow */ | |
773 | bfd_elf_generic_reloc, /* special_function */ | |
774 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 775 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
776 | 0, /* src_mask */ |
777 | 0xffff, /* dst_mask */ | |
b34976b6 | 778 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
779 | |
780 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
781 | 16 bits, treated as a signed number, is negative. */ | |
782 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
783 | 32, /* rightshift */ | |
784 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
785 | 16, /* bitsize */ | |
b34976b6 | 786 | FALSE, /* pc_relative */ |
5bd4f169 AM |
787 | 0, /* bitpos */ |
788 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 789 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 790 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 791 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
792 | 0, /* src_mask */ |
793 | 0xffff, /* dst_mask */ | |
b34976b6 | 794 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
795 | |
796 | /* The bits 48-63 of an address. */ | |
797 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
798 | 48, /* rightshift */ | |
799 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
800 | 16, /* bitsize */ | |
b34976b6 | 801 | FALSE, /* pc_relative */ |
5bd4f169 AM |
802 | 0, /* bitpos */ |
803 | complain_overflow_dont, /* complain_on_overflow */ | |
804 | bfd_elf_generic_reloc, /* special_function */ | |
805 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
b34976b6 | 806 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
807 | 0, /* src_mask */ |
808 | 0xffff, /* dst_mask */ | |
b34976b6 | 809 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
810 | |
811 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
812 | 16 bits, treated as a signed number, is negative. */ | |
813 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
814 | 48, /* rightshift */ | |
815 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
816 | 16, /* bitsize */ | |
b34976b6 | 817 | FALSE, /* pc_relative */ |
5bd4f169 AM |
818 | 0, /* bitpos */ |
819 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 820 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 821 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
b34976b6 | 822 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
823 | 0, /* src_mask */ |
824 | 0xffff, /* dst_mask */ | |
b34976b6 | 825 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
826 | |
827 | /* Like ADDR64, but may be unaligned. */ | |
828 | HOWTO (R_PPC64_UADDR64, /* type */ | |
829 | 0, /* rightshift */ | |
830 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
831 | 64, /* bitsize */ | |
b34976b6 | 832 | FALSE, /* pc_relative */ |
5bd4f169 AM |
833 | 0, /* bitpos */ |
834 | complain_overflow_dont, /* complain_on_overflow */ | |
835 | bfd_elf_generic_reloc, /* special_function */ | |
836 | "R_PPC64_UADDR64", /* name */ | |
b34976b6 | 837 | FALSE, /* partial_inplace */ |
5bd4f169 | 838 | 0, /* src_mask */ |
f5e87a1d | 839 | ONES (64), /* dst_mask */ |
b34976b6 | 840 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
841 | |
842 | /* 64-bit relative relocation. */ | |
843 | HOWTO (R_PPC64_REL64, /* type */ | |
844 | 0, /* rightshift */ | |
845 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
846 | 64, /* bitsize */ | |
b34976b6 | 847 | TRUE, /* pc_relative */ |
5bd4f169 AM |
848 | 0, /* bitpos */ |
849 | complain_overflow_dont, /* complain_on_overflow */ | |
850 | bfd_elf_generic_reloc, /* special_function */ | |
851 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 852 | FALSE, /* partial_inplace */ |
5bd4f169 | 853 | 0, /* src_mask */ |
f5e87a1d | 854 | ONES (64), /* dst_mask */ |
b34976b6 | 855 | TRUE), /* pcrel_offset */ |
5bd4f169 | 856 | |
cedb70c5 | 857 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
858 | HOWTO (R_PPC64_PLT64, /* type */ |
859 | 0, /* rightshift */ | |
860 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
861 | 64, /* bitsize */ | |
b34976b6 | 862 | FALSE, /* pc_relative */ |
5bd4f169 AM |
863 | 0, /* bitpos */ |
864 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 865 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 866 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 867 | FALSE, /* partial_inplace */ |
5bd4f169 | 868 | 0, /* src_mask */ |
f5e87a1d | 869 | ONES (64), /* dst_mask */ |
b34976b6 | 870 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
871 | |
872 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
873 | table. */ | |
874 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
875 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
876 | 0, /* rightshift */ | |
877 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
878 | 64, /* bitsize */ | |
b34976b6 | 879 | TRUE, /* pc_relative */ |
5bd4f169 AM |
880 | 0, /* bitpos */ |
881 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 882 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 883 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 884 | FALSE, /* partial_inplace */ |
5bd4f169 | 885 | 0, /* src_mask */ |
f5e87a1d | 886 | ONES (64), /* dst_mask */ |
b34976b6 | 887 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
888 | |
889 | /* 16 bit TOC-relative relocation. */ | |
890 | ||
891 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
892 | HOWTO (R_PPC64_TOC16, /* type */ | |
893 | 0, /* rightshift */ | |
894 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
895 | 16, /* bitsize */ | |
b34976b6 | 896 | FALSE, /* pc_relative */ |
5bd4f169 AM |
897 | 0, /* bitpos */ |
898 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 899 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 900 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 901 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
902 | 0, /* src_mask */ |
903 | 0xffff, /* dst_mask */ | |
b34976b6 | 904 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
905 | |
906 | /* 16 bit TOC-relative relocation without overflow. */ | |
907 | ||
908 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
909 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
910 | 0, /* rightshift */ | |
911 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
912 | 16, /* bitsize */ | |
b34976b6 | 913 | FALSE, /* pc_relative */ |
5bd4f169 AM |
914 | 0, /* bitpos */ |
915 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 916 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 917 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 918 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
919 | 0, /* src_mask */ |
920 | 0xffff, /* dst_mask */ | |
b34976b6 | 921 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
922 | |
923 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
924 | ||
925 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
926 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
927 | 16, /* rightshift */ | |
928 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
929 | 16, /* bitsize */ | |
b34976b6 | 930 | FALSE, /* pc_relative */ |
5bd4f169 AM |
931 | 0, /* bitpos */ |
932 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 933 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 934 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 935 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
936 | 0, /* src_mask */ |
937 | 0xffff, /* dst_mask */ | |
b34976b6 | 938 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
939 | |
940 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
941 | contents of the low 16 bits, treated as a signed number, is | |
942 | negative. */ | |
943 | ||
944 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
945 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
946 | 16, /* rightshift */ | |
947 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
948 | 16, /* bitsize */ | |
b34976b6 | 949 | FALSE, /* pc_relative */ |
5bd4f169 AM |
950 | 0, /* bitpos */ |
951 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 952 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 953 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 954 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
955 | 0, /* src_mask */ |
956 | 0xffff, /* dst_mask */ | |
b34976b6 | 957 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
958 | |
959 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
960 | ||
961 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
962 | HOWTO (R_PPC64_TOC, /* type */ | |
963 | 0, /* rightshift */ | |
964 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
965 | 64, /* bitsize */ | |
b34976b6 | 966 | FALSE, /* pc_relative */ |
5bd4f169 AM |
967 | 0, /* bitpos */ |
968 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 969 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 970 | "R_PPC64_TOC", /* name */ |
b34976b6 | 971 | FALSE, /* partial_inplace */ |
5bd4f169 | 972 | 0, /* src_mask */ |
f5e87a1d | 973 | ONES (64), /* dst_mask */ |
b34976b6 | 974 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
975 | |
976 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
977 | value to relocate may (!) refer to a PLT entry which the link | |
978 | editor (a) may replace with the symbol value. If the link editor | |
979 | is unable to fully resolve the symbol, it may (b) create a PLT | |
980 | entry and store the address to the new PLT entry in the GOT. | |
981 | This permits lazy resolution of function symbols at run time. | |
982 | The link editor may also skip all of this and just (c) emit a | |
983 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
984 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
985 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
986 | 0, /* rightshift */ | |
987 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
988 | 16, /* bitsize */ | |
b34976b6 | 989 | FALSE, /* pc_relative */ |
5bd4f169 AM |
990 | 0, /* bitpos */ |
991 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 992 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb AM |
993 | "R_PPC64_PLTGOT16", /* name */ |
994 | FALSE, /* partial_inplace */ | |
995 | 0, /* src_mask */ | |
996 | 0xffff, /* dst_mask */ | |
997 | FALSE), /* pcrel_offset */ | |
998 | ||
999 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
1000 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1001 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
1002 | 0, /* rightshift */ | |
1003 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1004 | 16, /* bitsize */ | |
1005 | FALSE, /* pc_relative */ | |
1006 | 0, /* bitpos */ | |
1007 | complain_overflow_dont, /* complain_on_overflow */ | |
1008 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1009 | "R_PPC64_PLTGOT16_LO", /* name */ | |
1010 | FALSE, /* partial_inplace */ | |
1011 | 0, /* src_mask */ | |
1012 | 0xffff, /* dst_mask */ | |
1013 | FALSE), /* pcrel_offset */ | |
1014 | ||
1015 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
1016 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
1017 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
1018 | 16, /* rightshift */ | |
1019 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1020 | 16, /* bitsize */ | |
1021 | FALSE, /* pc_relative */ | |
1022 | 0, /* bitpos */ | |
1023 | complain_overflow_dont, /* complain_on_overflow */ | |
1024 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1025 | "R_PPC64_PLTGOT16_HI", /* name */ | |
1026 | FALSE, /* partial_inplace */ | |
1027 | 0, /* src_mask */ | |
1028 | 0xffff, /* dst_mask */ | |
1029 | FALSE), /* pcrel_offset */ | |
1030 | ||
1031 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
1032 | 1 if the contents of the low 16 bits, treated as a signed number, | |
1033 | is negative. */ | |
1034 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
1035 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
1036 | 16, /* rightshift */ | |
1037 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1038 | 16, /* bitsize */ | |
1039 | FALSE, /* pc_relative */ | |
1040 | 0, /* bitpos */ | |
1041 | complain_overflow_dont,/* complain_on_overflow */ | |
1042 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1043 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1044 | FALSE, /* partial_inplace */ | |
1045 | 0, /* src_mask */ | |
1046 | 0xffff, /* dst_mask */ | |
1047 | FALSE), /* pcrel_offset */ | |
1048 | ||
1049 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1050 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1051 | 0, /* rightshift */ | |
1052 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1053 | 16, /* bitsize */ | |
1054 | FALSE, /* pc_relative */ | |
1055 | 0, /* bitpos */ | |
1056 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1057 | bfd_elf_generic_reloc, /* special_function */ | |
1058 | "R_PPC64_ADDR16_DS", /* name */ | |
1059 | FALSE, /* partial_inplace */ | |
1060 | 0, /* src_mask */ | |
1061 | 0xfffc, /* dst_mask */ | |
1062 | FALSE), /* pcrel_offset */ | |
1063 | ||
1064 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1065 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1066 | 0, /* rightshift */ | |
1067 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1068 | 16, /* bitsize */ | |
1069 | FALSE, /* pc_relative */ | |
1070 | 0, /* bitpos */ | |
1071 | complain_overflow_dont,/* complain_on_overflow */ | |
1072 | bfd_elf_generic_reloc, /* special_function */ | |
1073 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1074 | FALSE, /* partial_inplace */ | |
1075 | 0, /* src_mask */ | |
1076 | 0xfffc, /* dst_mask */ | |
1077 | FALSE), /* pcrel_offset */ | |
1078 | ||
1079 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1080 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1081 | 0, /* rightshift */ | |
1082 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1083 | 16, /* bitsize */ | |
1084 | FALSE, /* pc_relative */ | |
1085 | 0, /* bitpos */ | |
1086 | complain_overflow_signed, /* complain_on_overflow */ | |
1087 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1088 | "R_PPC64_GOT16_DS", /* name */ | |
1089 | FALSE, /* partial_inplace */ | |
1090 | 0, /* src_mask */ | |
1091 | 0xfffc, /* dst_mask */ | |
1092 | FALSE), /* pcrel_offset */ | |
1093 | ||
1094 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1095 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1096 | 0, /* rightshift */ | |
1097 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1098 | 16, /* bitsize */ | |
1099 | FALSE, /* pc_relative */ | |
1100 | 0, /* bitpos */ | |
1101 | complain_overflow_dont, /* complain_on_overflow */ | |
1102 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1103 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1104 | FALSE, /* partial_inplace */ | |
1105 | 0, /* src_mask */ | |
1106 | 0xfffc, /* dst_mask */ | |
1107 | FALSE), /* pcrel_offset */ | |
1108 | ||
1109 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1110 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1111 | 0, /* rightshift */ | |
1112 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1113 | 16, /* bitsize */ | |
1114 | FALSE, /* pc_relative */ | |
1115 | 0, /* bitpos */ | |
1116 | complain_overflow_dont, /* complain_on_overflow */ | |
1117 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1118 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1119 | FALSE, /* partial_inplace */ | |
1120 | 0, /* src_mask */ | |
1121 | 0xfffc, /* dst_mask */ | |
1122 | FALSE), /* pcrel_offset */ | |
1123 | ||
1124 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1125 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1126 | 0, /* rightshift */ | |
1127 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1128 | 16, /* bitsize */ | |
1129 | FALSE, /* pc_relative */ | |
1130 | 0, /* bitpos */ | |
1131 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1132 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1133 | "R_PPC64_SECTOFF_DS", /* name */ | |
1134 | FALSE, /* partial_inplace */ | |
1135 | 0, /* src_mask */ | |
1136 | 0xfffc, /* dst_mask */ | |
1137 | FALSE), /* pcrel_offset */ | |
1138 | ||
1139 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1140 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1141 | 0, /* rightshift */ | |
1142 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1143 | 16, /* bitsize */ | |
1144 | FALSE, /* pc_relative */ | |
1145 | 0, /* bitpos */ | |
1146 | complain_overflow_dont, /* complain_on_overflow */ | |
1147 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1148 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1149 | FALSE, /* partial_inplace */ | |
1150 | 0, /* src_mask */ | |
1151 | 0xfffc, /* dst_mask */ | |
1152 | FALSE), /* pcrel_offset */ | |
1153 | ||
1154 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1155 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1156 | 0, /* rightshift */ | |
1157 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1158 | 16, /* bitsize */ | |
1159 | FALSE, /* pc_relative */ | |
1160 | 0, /* bitpos */ | |
1161 | complain_overflow_signed, /* complain_on_overflow */ | |
1162 | ppc64_elf_toc_reloc, /* special_function */ | |
1163 | "R_PPC64_TOC16_DS", /* name */ | |
1164 | FALSE, /* partial_inplace */ | |
1165 | 0, /* src_mask */ | |
1166 | 0xfffc, /* dst_mask */ | |
1167 | FALSE), /* pcrel_offset */ | |
1168 | ||
1169 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1170 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1171 | 0, /* rightshift */ | |
1172 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1173 | 16, /* bitsize */ | |
1174 | FALSE, /* pc_relative */ | |
1175 | 0, /* bitpos */ | |
1176 | complain_overflow_dont, /* complain_on_overflow */ | |
1177 | ppc64_elf_toc_reloc, /* special_function */ | |
1178 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1179 | FALSE, /* partial_inplace */ | |
1180 | 0, /* src_mask */ | |
1181 | 0xfffc, /* dst_mask */ | |
1182 | FALSE), /* pcrel_offset */ | |
1183 | ||
1184 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1185 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1186 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ | |
1187 | 0, /* rightshift */ | |
1188 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1189 | 16, /* bitsize */ | |
1190 | FALSE, /* pc_relative */ | |
1191 | 0, /* bitpos */ | |
1192 | complain_overflow_signed, /* complain_on_overflow */ | |
1193 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1194 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1195 | FALSE, /* partial_inplace */ | |
1196 | 0, /* src_mask */ | |
1197 | 0xfffc, /* dst_mask */ | |
1198 | FALSE), /* pcrel_offset */ | |
1199 | ||
1200 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1201 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1202 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1203 | 0, /* rightshift */ | |
1204 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1205 | 16, /* bitsize */ | |
1206 | FALSE, /* pc_relative */ | |
1207 | 0, /* bitpos */ | |
1208 | complain_overflow_dont, /* complain_on_overflow */ | |
1209 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1210 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1211 | FALSE, /* partial_inplace */ | |
1212 | 0, /* src_mask */ | |
1213 | 0xfffc, /* dst_mask */ | |
1214 | FALSE), /* pcrel_offset */ | |
1215 | ||
1216 | /* Marker reloc for TLS. */ | |
1217 | HOWTO (R_PPC64_TLS, | |
1218 | 0, /* rightshift */ | |
1219 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1220 | 32, /* bitsize */ | |
1221 | FALSE, /* pc_relative */ | |
1222 | 0, /* bitpos */ | |
1223 | complain_overflow_dont, /* complain_on_overflow */ | |
1224 | bfd_elf_generic_reloc, /* special_function */ | |
1225 | "R_PPC64_TLS", /* name */ | |
1226 | FALSE, /* partial_inplace */ | |
1227 | 0, /* src_mask */ | |
1228 | 0, /* dst_mask */ | |
1229 | FALSE), /* pcrel_offset */ | |
1230 | ||
1231 | /* Computes the load module index of the load module that contains the | |
1232 | definition of its TLS sym. */ | |
1233 | HOWTO (R_PPC64_DTPMOD64, | |
1234 | 0, /* rightshift */ | |
1235 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1236 | 64, /* bitsize */ | |
1237 | FALSE, /* pc_relative */ | |
1238 | 0, /* bitpos */ | |
1239 | complain_overflow_dont, /* complain_on_overflow */ | |
1240 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1241 | "R_PPC64_DTPMOD64", /* name */ | |
1242 | FALSE, /* partial_inplace */ | |
1243 | 0, /* src_mask */ | |
1244 | ONES (64), /* dst_mask */ | |
1245 | FALSE), /* pcrel_offset */ | |
1246 | ||
1247 | /* Computes a dtv-relative displacement, the difference between the value | |
1248 | of sym+add and the base address of the thread-local storage block that | |
1249 | contains the definition of sym, minus 0x8000. */ | |
1250 | HOWTO (R_PPC64_DTPREL64, | |
1251 | 0, /* rightshift */ | |
1252 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1253 | 64, /* bitsize */ | |
1254 | FALSE, /* pc_relative */ | |
1255 | 0, /* bitpos */ | |
1256 | complain_overflow_dont, /* complain_on_overflow */ | |
1257 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1258 | "R_PPC64_DTPREL64", /* name */ | |
1259 | FALSE, /* partial_inplace */ | |
1260 | 0, /* src_mask */ | |
1261 | ONES (64), /* dst_mask */ | |
1262 | FALSE), /* pcrel_offset */ | |
1263 | ||
1264 | /* A 16 bit dtprel reloc. */ | |
1265 | HOWTO (R_PPC64_DTPREL16, | |
1266 | 0, /* rightshift */ | |
1267 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1268 | 16, /* bitsize */ | |
1269 | FALSE, /* pc_relative */ | |
1270 | 0, /* bitpos */ | |
1271 | complain_overflow_signed, /* complain_on_overflow */ | |
1272 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1273 | "R_PPC64_DTPREL16", /* name */ | |
1274 | FALSE, /* partial_inplace */ | |
1275 | 0, /* src_mask */ | |
1276 | 0xffff, /* dst_mask */ | |
1277 | FALSE), /* pcrel_offset */ | |
1278 | ||
1279 | /* Like DTPREL16, but no overflow. */ | |
1280 | HOWTO (R_PPC64_DTPREL16_LO, | |
1281 | 0, /* rightshift */ | |
1282 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1283 | 16, /* bitsize */ | |
1284 | FALSE, /* pc_relative */ | |
1285 | 0, /* bitpos */ | |
1286 | complain_overflow_dont, /* complain_on_overflow */ | |
1287 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1288 | "R_PPC64_DTPREL16_LO", /* name */ | |
1289 | FALSE, /* partial_inplace */ | |
1290 | 0, /* src_mask */ | |
1291 | 0xffff, /* dst_mask */ | |
1292 | FALSE), /* pcrel_offset */ | |
1293 | ||
1294 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ | |
1295 | HOWTO (R_PPC64_DTPREL16_HI, | |
1296 | 16, /* rightshift */ | |
1297 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1298 | 16, /* bitsize */ | |
1299 | FALSE, /* pc_relative */ | |
1300 | 0, /* bitpos */ | |
1301 | complain_overflow_dont, /* complain_on_overflow */ | |
1302 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1303 | "R_PPC64_DTPREL16_HI", /* name */ | |
1304 | FALSE, /* partial_inplace */ | |
1305 | 0, /* src_mask */ | |
1306 | 0xffff, /* dst_mask */ | |
1307 | FALSE), /* pcrel_offset */ | |
1308 | ||
1309 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ | |
1310 | HOWTO (R_PPC64_DTPREL16_HA, | |
1311 | 16, /* rightshift */ | |
1312 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1313 | 16, /* bitsize */ | |
1314 | FALSE, /* pc_relative */ | |
1315 | 0, /* bitpos */ | |
1316 | complain_overflow_dont, /* complain_on_overflow */ | |
1317 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1318 | "R_PPC64_DTPREL16_HA", /* name */ | |
1319 | FALSE, /* partial_inplace */ | |
1320 | 0, /* src_mask */ | |
1321 | 0xffff, /* dst_mask */ | |
1322 | FALSE), /* pcrel_offset */ | |
1323 | ||
1324 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ | |
1325 | HOWTO (R_PPC64_DTPREL16_HIGHER, | |
1326 | 32, /* rightshift */ | |
1327 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1328 | 16, /* bitsize */ | |
1329 | FALSE, /* pc_relative */ | |
1330 | 0, /* bitpos */ | |
1331 | complain_overflow_dont, /* complain_on_overflow */ | |
1332 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1333 | "R_PPC64_DTPREL16_HIGHER", /* name */ | |
1334 | FALSE, /* partial_inplace */ | |
1335 | 0, /* src_mask */ | |
1336 | 0xffff, /* dst_mask */ | |
1337 | FALSE), /* pcrel_offset */ | |
1338 | ||
1339 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ | |
1340 | HOWTO (R_PPC64_DTPREL16_HIGHERA, | |
1341 | 32, /* rightshift */ | |
1342 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1343 | 16, /* bitsize */ | |
1344 | FALSE, /* pc_relative */ | |
1345 | 0, /* bitpos */ | |
1346 | complain_overflow_dont, /* complain_on_overflow */ | |
1347 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1348 | "R_PPC64_DTPREL16_HIGHERA", /* name */ | |
1349 | FALSE, /* partial_inplace */ | |
1350 | 0, /* src_mask */ | |
1351 | 0xffff, /* dst_mask */ | |
1352 | FALSE), /* pcrel_offset */ | |
1353 | ||
1354 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ | |
1355 | HOWTO (R_PPC64_DTPREL16_HIGHEST, | |
1356 | 48, /* rightshift */ | |
1357 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1358 | 16, /* bitsize */ | |
1359 | FALSE, /* pc_relative */ | |
1360 | 0, /* bitpos */ | |
1361 | complain_overflow_dont, /* complain_on_overflow */ | |
1362 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1363 | "R_PPC64_DTPREL16_HIGHEST", /* name */ | |
1364 | FALSE, /* partial_inplace */ | |
1365 | 0, /* src_mask */ | |
1366 | 0xffff, /* dst_mask */ | |
1367 | FALSE), /* pcrel_offset */ | |
1368 | ||
1369 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1370 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, | |
1371 | 48, /* rightshift */ | |
1372 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1373 | 16, /* bitsize */ | |
1374 | FALSE, /* pc_relative */ | |
1375 | 0, /* bitpos */ | |
1376 | complain_overflow_dont, /* complain_on_overflow */ | |
1377 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1378 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ | |
1379 | FALSE, /* partial_inplace */ | |
1380 | 0, /* src_mask */ | |
1381 | 0xffff, /* dst_mask */ | |
1382 | FALSE), /* pcrel_offset */ | |
1383 | ||
1384 | /* Like DTPREL16, but for insns with a DS field. */ | |
1385 | HOWTO (R_PPC64_DTPREL16_DS, | |
1386 | 0, /* rightshift */ | |
1387 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1388 | 16, /* bitsize */ | |
1389 | FALSE, /* pc_relative */ | |
1390 | 0, /* bitpos */ | |
1391 | complain_overflow_signed, /* complain_on_overflow */ | |
1392 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1393 | "R_PPC64_DTPREL16_DS", /* name */ | |
1394 | FALSE, /* partial_inplace */ | |
1395 | 0, /* src_mask */ | |
1396 | 0xfffc, /* dst_mask */ | |
1397 | FALSE), /* pcrel_offset */ | |
1398 | ||
1399 | /* Like DTPREL16_DS, but no overflow. */ | |
1400 | HOWTO (R_PPC64_DTPREL16_LO_DS, | |
1401 | 0, /* rightshift */ | |
1402 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1403 | 16, /* bitsize */ | |
1404 | FALSE, /* pc_relative */ | |
1405 | 0, /* bitpos */ | |
1406 | complain_overflow_dont, /* complain_on_overflow */ | |
1407 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1408 | "R_PPC64_DTPREL16_LO_DS", /* name */ | |
1409 | FALSE, /* partial_inplace */ | |
1410 | 0, /* src_mask */ | |
1411 | 0xfffc, /* dst_mask */ | |
1412 | FALSE), /* pcrel_offset */ | |
1413 | ||
1414 | /* Computes a tp-relative displacement, the difference between the value of | |
1415 | sym+add and the value of the thread pointer (r13). */ | |
1416 | HOWTO (R_PPC64_TPREL64, | |
1417 | 0, /* rightshift */ | |
1418 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1419 | 64, /* bitsize */ | |
1420 | FALSE, /* pc_relative */ | |
1421 | 0, /* bitpos */ | |
1422 | complain_overflow_dont, /* complain_on_overflow */ | |
1423 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1424 | "R_PPC64_TPREL64", /* name */ | |
1425 | FALSE, /* partial_inplace */ | |
1426 | 0, /* src_mask */ | |
1427 | ONES (64), /* dst_mask */ | |
1428 | FALSE), /* pcrel_offset */ | |
1429 | ||
1430 | /* A 16 bit tprel reloc. */ | |
1431 | HOWTO (R_PPC64_TPREL16, | |
1432 | 0, /* rightshift */ | |
1433 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1434 | 16, /* bitsize */ | |
1435 | FALSE, /* pc_relative */ | |
1436 | 0, /* bitpos */ | |
1437 | complain_overflow_signed, /* complain_on_overflow */ | |
1438 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1439 | "R_PPC64_TPREL16", /* name */ | |
1440 | FALSE, /* partial_inplace */ | |
1441 | 0, /* src_mask */ | |
1442 | 0xffff, /* dst_mask */ | |
1443 | FALSE), /* pcrel_offset */ | |
1444 | ||
1445 | /* Like TPREL16, but no overflow. */ | |
1446 | HOWTO (R_PPC64_TPREL16_LO, | |
1447 | 0, /* rightshift */ | |
1448 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1449 | 16, /* bitsize */ | |
1450 | FALSE, /* pc_relative */ | |
1451 | 0, /* bitpos */ | |
1452 | complain_overflow_dont, /* complain_on_overflow */ | |
1453 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1454 | "R_PPC64_TPREL16_LO", /* name */ | |
1455 | FALSE, /* partial_inplace */ | |
1456 | 0, /* src_mask */ | |
1457 | 0xffff, /* dst_mask */ | |
1458 | FALSE), /* pcrel_offset */ | |
1459 | ||
1460 | /* Like TPREL16_LO, but next higher group of 16 bits. */ | |
1461 | HOWTO (R_PPC64_TPREL16_HI, | |
1462 | 16, /* rightshift */ | |
1463 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1464 | 16, /* bitsize */ | |
1465 | FALSE, /* pc_relative */ | |
1466 | 0, /* bitpos */ | |
1467 | complain_overflow_dont, /* complain_on_overflow */ | |
1468 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1469 | "R_PPC64_TPREL16_HI", /* name */ | |
1470 | FALSE, /* partial_inplace */ | |
1471 | 0, /* src_mask */ | |
1472 | 0xffff, /* dst_mask */ | |
1473 | FALSE), /* pcrel_offset */ | |
1474 | ||
1475 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1476 | HOWTO (R_PPC64_TPREL16_HA, | |
1477 | 16, /* rightshift */ | |
1478 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1479 | 16, /* bitsize */ | |
1480 | FALSE, /* pc_relative */ | |
1481 | 0, /* bitpos */ | |
1482 | complain_overflow_dont, /* complain_on_overflow */ | |
1483 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1484 | "R_PPC64_TPREL16_HA", /* name */ | |
1485 | FALSE, /* partial_inplace */ | |
1486 | 0, /* src_mask */ | |
1487 | 0xffff, /* dst_mask */ | |
1488 | FALSE), /* pcrel_offset */ | |
1489 | ||
1490 | /* Like TPREL16_HI, but next higher group of 16 bits. */ | |
1491 | HOWTO (R_PPC64_TPREL16_HIGHER, | |
1492 | 32, /* rightshift */ | |
1493 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1494 | 16, /* bitsize */ | |
1495 | FALSE, /* pc_relative */ | |
1496 | 0, /* bitpos */ | |
1497 | complain_overflow_dont, /* complain_on_overflow */ | |
1498 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1499 | "R_PPC64_TPREL16_HIGHER", /* name */ | |
1500 | FALSE, /* partial_inplace */ | |
1501 | 0, /* src_mask */ | |
1502 | 0xffff, /* dst_mask */ | |
1503 | FALSE), /* pcrel_offset */ | |
1504 | ||
1505 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ | |
1506 | HOWTO (R_PPC64_TPREL16_HIGHERA, | |
1507 | 32, /* rightshift */ | |
1508 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1509 | 16, /* bitsize */ | |
1510 | FALSE, /* pc_relative */ | |
1511 | 0, /* bitpos */ | |
1512 | complain_overflow_dont, /* complain_on_overflow */ | |
1513 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1514 | "R_PPC64_TPREL16_HIGHERA", /* name */ | |
1515 | FALSE, /* partial_inplace */ | |
1516 | 0, /* src_mask */ | |
1517 | 0xffff, /* dst_mask */ | |
1518 | FALSE), /* pcrel_offset */ | |
1519 | ||
1520 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ | |
1521 | HOWTO (R_PPC64_TPREL16_HIGHEST, | |
1522 | 48, /* rightshift */ | |
1523 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1524 | 16, /* bitsize */ | |
1525 | FALSE, /* pc_relative */ | |
1526 | 0, /* bitpos */ | |
1527 | complain_overflow_dont, /* complain_on_overflow */ | |
1528 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1529 | "R_PPC64_TPREL16_HIGHEST", /* name */ | |
1530 | FALSE, /* partial_inplace */ | |
1531 | 0, /* src_mask */ | |
1532 | 0xffff, /* dst_mask */ | |
1533 | FALSE), /* pcrel_offset */ | |
1534 | ||
1535 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1536 | HOWTO (R_PPC64_TPREL16_HIGHESTA, | |
1537 | 48, /* rightshift */ | |
1538 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1539 | 16, /* bitsize */ | |
1540 | FALSE, /* pc_relative */ | |
1541 | 0, /* bitpos */ | |
1542 | complain_overflow_dont, /* complain_on_overflow */ | |
1543 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1544 | "R_PPC64_TPREL16_HIGHESTA", /* name */ | |
1545 | FALSE, /* partial_inplace */ | |
1546 | 0, /* src_mask */ | |
1547 | 0xffff, /* dst_mask */ | |
1548 | FALSE), /* pcrel_offset */ | |
1549 | ||
1550 | /* Like TPREL16, but for insns with a DS field. */ | |
1551 | HOWTO (R_PPC64_TPREL16_DS, | |
1552 | 0, /* rightshift */ | |
1553 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1554 | 16, /* bitsize */ | |
1555 | FALSE, /* pc_relative */ | |
1556 | 0, /* bitpos */ | |
1557 | complain_overflow_signed, /* complain_on_overflow */ | |
1558 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1559 | "R_PPC64_TPREL16_DS", /* name */ | |
1560 | FALSE, /* partial_inplace */ | |
1561 | 0, /* src_mask */ | |
1562 | 0xfffc, /* dst_mask */ | |
1563 | FALSE), /* pcrel_offset */ | |
1564 | ||
1565 | /* Like TPREL16_DS, but no overflow. */ | |
1566 | HOWTO (R_PPC64_TPREL16_LO_DS, | |
1567 | 0, /* rightshift */ | |
1568 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1569 | 16, /* bitsize */ | |
1570 | FALSE, /* pc_relative */ | |
1571 | 0, /* bitpos */ | |
1572 | complain_overflow_dont, /* complain_on_overflow */ | |
1573 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1574 | "R_PPC64_TPREL16_LO_DS", /* name */ | |
1575 | FALSE, /* partial_inplace */ | |
1576 | 0, /* src_mask */ | |
1577 | 0xfffc, /* dst_mask */ | |
1578 | FALSE), /* pcrel_offset */ | |
1579 | ||
1580 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1581 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1582 | to the first entry relative to the TOC base (r2). */ | |
1583 | HOWTO (R_PPC64_GOT_TLSGD16, | |
1584 | 0, /* rightshift */ | |
1585 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1586 | 16, /* bitsize */ | |
1587 | FALSE, /* pc_relative */ | |
1588 | 0, /* bitpos */ | |
1589 | complain_overflow_signed, /* complain_on_overflow */ | |
1590 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1591 | "R_PPC64_GOT_TLSGD16", /* name */ | |
b34976b6 | 1592 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1593 | 0, /* src_mask */ |
1594 | 0xffff, /* dst_mask */ | |
b34976b6 | 1595 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1596 | |
411e1bfb AM |
1597 | /* Like GOT_TLSGD16, but no overflow. */ |
1598 | HOWTO (R_PPC64_GOT_TLSGD16_LO, | |
5bd4f169 AM |
1599 | 0, /* rightshift */ |
1600 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1601 | 16, /* bitsize */ | |
b34976b6 | 1602 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1603 | 0, /* bitpos */ |
1604 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1605 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1606 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
b34976b6 | 1607 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1608 | 0, /* src_mask */ |
1609 | 0xffff, /* dst_mask */ | |
b34976b6 | 1610 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1611 | |
411e1bfb AM |
1612 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1613 | HOWTO (R_PPC64_GOT_TLSGD16_HI, | |
5bd4f169 AM |
1614 | 16, /* rightshift */ |
1615 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1616 | 16, /* bitsize */ | |
b34976b6 | 1617 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1618 | 0, /* bitpos */ |
1619 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1620 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1621 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
b34976b6 | 1622 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1623 | 0, /* src_mask */ |
1624 | 0xffff, /* dst_mask */ | |
b34976b6 | 1625 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1626 | |
411e1bfb AM |
1627 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1628 | HOWTO (R_PPC64_GOT_TLSGD16_HA, | |
5bd4f169 AM |
1629 | 16, /* rightshift */ |
1630 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1631 | 16, /* bitsize */ | |
b34976b6 | 1632 | FALSE, /* pc_relative */ |
5bd4f169 | 1633 | 0, /* bitpos */ |
411e1bfb | 1634 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1635 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1636 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
b34976b6 | 1637 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1638 | 0, /* src_mask */ |
1639 | 0xffff, /* dst_mask */ | |
b34976b6 | 1640 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1641 | |
411e1bfb AM |
1642 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
1643 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1644 | first entry relative to the TOC base (r2). */ | |
1645 | HOWTO (R_PPC64_GOT_TLSLD16, | |
5bd4f169 AM |
1646 | 0, /* rightshift */ |
1647 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1648 | 16, /* bitsize */ | |
b34976b6 | 1649 | FALSE, /* pc_relative */ |
5bd4f169 | 1650 | 0, /* bitpos */ |
411e1bfb AM |
1651 | complain_overflow_signed, /* complain_on_overflow */ |
1652 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1653 | "R_PPC64_GOT_TLSLD16", /* name */ | |
b34976b6 | 1654 | FALSE, /* partial_inplace */ |
d006db6c | 1655 | 0, /* src_mask */ |
411e1bfb | 1656 | 0xffff, /* dst_mask */ |
b34976b6 | 1657 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1658 | |
411e1bfb AM |
1659 | /* Like GOT_TLSLD16, but no overflow. */ |
1660 | HOWTO (R_PPC64_GOT_TLSLD16_LO, | |
5bd4f169 AM |
1661 | 0, /* rightshift */ |
1662 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1663 | 16, /* bitsize */ | |
b34976b6 | 1664 | FALSE, /* pc_relative */ |
5bd4f169 | 1665 | 0, /* bitpos */ |
411e1bfb AM |
1666 | complain_overflow_dont, /* complain_on_overflow */ |
1667 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1668 | "R_PPC64_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1669 | FALSE, /* partial_inplace */ |
d006db6c | 1670 | 0, /* src_mask */ |
411e1bfb | 1671 | 0xffff, /* dst_mask */ |
b34976b6 | 1672 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1673 | |
411e1bfb AM |
1674 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1675 | HOWTO (R_PPC64_GOT_TLSLD16_HI, | |
1676 | 16, /* rightshift */ | |
5bd4f169 AM |
1677 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1678 | 16, /* bitsize */ | |
b34976b6 | 1679 | FALSE, /* pc_relative */ |
5bd4f169 | 1680 | 0, /* bitpos */ |
411e1bfb | 1681 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1682 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1683 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
b34976b6 | 1684 | FALSE, /* partial_inplace */ |
d006db6c | 1685 | 0, /* src_mask */ |
411e1bfb | 1686 | 0xffff, /* dst_mask */ |
b34976b6 | 1687 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1688 | |
411e1bfb AM |
1689 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1690 | HOWTO (R_PPC64_GOT_TLSLD16_HA, | |
1691 | 16, /* rightshift */ | |
5bd4f169 AM |
1692 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1693 | 16, /* bitsize */ | |
b34976b6 | 1694 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1695 | 0, /* bitpos */ |
1696 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1697 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1698 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
b34976b6 | 1699 | FALSE, /* partial_inplace */ |
d006db6c | 1700 | 0, /* src_mask */ |
411e1bfb | 1701 | 0xffff, /* dst_mask */ |
b34976b6 | 1702 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1703 | |
411e1bfb AM |
1704 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
1705 | the offset to the entry relative to the TOC base (r2). */ | |
1706 | HOWTO (R_PPC64_GOT_DTPREL16_DS, | |
5bd4f169 AM |
1707 | 0, /* rightshift */ |
1708 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1709 | 16, /* bitsize */ | |
b34976b6 | 1710 | FALSE, /* pc_relative */ |
5bd4f169 | 1711 | 0, /* bitpos */ |
411e1bfb | 1712 | complain_overflow_signed, /* complain_on_overflow */ |
805fc799 | 1713 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1714 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
b34976b6 | 1715 | FALSE, /* partial_inplace */ |
d006db6c | 1716 | 0, /* src_mask */ |
5bd4f169 | 1717 | 0xfffc, /* dst_mask */ |
b34976b6 | 1718 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1719 | |
411e1bfb AM |
1720 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
1721 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, | |
5bd4f169 | 1722 | 0, /* rightshift */ |
c061c2d8 AM |
1723 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1724 | 16, /* bitsize */ | |
b34976b6 | 1725 | FALSE, /* pc_relative */ |
5bd4f169 | 1726 | 0, /* bitpos */ |
411e1bfb AM |
1727 | complain_overflow_dont, /* complain_on_overflow */ |
1728 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1729 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ | |
b34976b6 | 1730 | FALSE, /* partial_inplace */ |
d006db6c | 1731 | 0, /* src_mask */ |
c061c2d8 | 1732 | 0xfffc, /* dst_mask */ |
b34976b6 | 1733 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1734 | |
411e1bfb AM |
1735 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
1736 | HOWTO (R_PPC64_GOT_DTPREL16_HI, | |
1737 | 16, /* rightshift */ | |
5bd4f169 AM |
1738 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1739 | 16, /* bitsize */ | |
b34976b6 | 1740 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1741 | 0, /* bitpos */ |
1742 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1743 | ppc64_elf_unhandled_reloc, /* special_function */ |
1744 | "R_PPC64_GOT_DTPREL16_HI", /* name */ | |
b34976b6 | 1745 | FALSE, /* partial_inplace */ |
d006db6c | 1746 | 0, /* src_mask */ |
411e1bfb | 1747 | 0xffff, /* dst_mask */ |
b34976b6 | 1748 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1749 | |
411e1bfb AM |
1750 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1751 | HOWTO (R_PPC64_GOT_DTPREL16_HA, | |
1752 | 16, /* rightshift */ | |
1753 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1754 | 16, /* bitsize */ | |
1755 | FALSE, /* pc_relative */ | |
1756 | 0, /* bitpos */ | |
1757 | complain_overflow_dont, /* complain_on_overflow */ | |
1758 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1759 | "R_PPC64_GOT_DTPREL16_HA", /* name */ | |
1760 | FALSE, /* partial_inplace */ | |
1761 | 0, /* src_mask */ | |
1762 | 0xffff, /* dst_mask */ | |
1763 | FALSE), /* pcrel_offset */ | |
1764 | ||
1765 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the | |
1766 | offset to the entry relative to the TOC base (r2). */ | |
1767 | HOWTO (R_PPC64_GOT_TPREL16_DS, | |
5bd4f169 AM |
1768 | 0, /* rightshift */ |
1769 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1770 | 16, /* bitsize */ | |
b34976b6 | 1771 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1772 | 0, /* bitpos */ |
1773 | complain_overflow_signed, /* complain_on_overflow */ | |
411e1bfb AM |
1774 | ppc64_elf_unhandled_reloc, /* special_function */ |
1775 | "R_PPC64_GOT_TPREL16_DS", /* name */ | |
b34976b6 | 1776 | FALSE, /* partial_inplace */ |
d006db6c | 1777 | 0, /* src_mask */ |
ad8e1ba5 | 1778 | 0xfffc, /* dst_mask */ |
b34976b6 | 1779 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1780 | |
411e1bfb AM |
1781 | /* Like GOT_TPREL16_DS, but no overflow. */ |
1782 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, | |
5bd4f169 AM |
1783 | 0, /* rightshift */ |
1784 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1785 | 16, /* bitsize */ | |
b34976b6 | 1786 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1787 | 0, /* bitpos */ |
1788 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1789 | ppc64_elf_unhandled_reloc, /* special_function */ |
1790 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ | |
b34976b6 | 1791 | FALSE, /* partial_inplace */ |
d006db6c | 1792 | 0, /* src_mask */ |
ad8e1ba5 | 1793 | 0xfffc, /* dst_mask */ |
b34976b6 | 1794 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1795 | |
411e1bfb AM |
1796 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
1797 | HOWTO (R_PPC64_GOT_TPREL16_HI, | |
1798 | 16, /* rightshift */ | |
5bd4f169 AM |
1799 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1800 | 16, /* bitsize */ | |
b34976b6 | 1801 | FALSE, /* pc_relative */ |
5bd4f169 | 1802 | 0, /* bitpos */ |
411e1bfb | 1803 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1804 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1805 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
b34976b6 | 1806 | FALSE, /* partial_inplace */ |
d006db6c | 1807 | 0, /* src_mask */ |
411e1bfb | 1808 | 0xffff, /* dst_mask */ |
b34976b6 | 1809 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1810 | |
411e1bfb AM |
1811 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
1812 | HOWTO (R_PPC64_GOT_TPREL16_HA, | |
1813 | 16, /* rightshift */ | |
5bd4f169 AM |
1814 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1815 | 16, /* bitsize */ | |
b34976b6 | 1816 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1817 | 0, /* bitpos */ |
1818 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1819 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1820 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
b34976b6 | 1821 | FALSE, /* partial_inplace */ |
d006db6c | 1822 | 0, /* src_mask */ |
411e1bfb | 1823 | 0xffff, /* dst_mask */ |
b34976b6 | 1824 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1825 | |
1826 | /* GNU extension to record C++ vtable hierarchy. */ | |
1827 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1828 | 0, /* rightshift */ | |
1829 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1830 | 0, /* bitsize */ | |
b34976b6 | 1831 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1832 | 0, /* bitpos */ |
1833 | complain_overflow_dont, /* complain_on_overflow */ | |
1834 | NULL, /* special_function */ | |
1835 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1836 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1837 | 0, /* src_mask */ |
1838 | 0, /* dst_mask */ | |
b34976b6 | 1839 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1840 | |
1841 | /* GNU extension to record C++ vtable member usage. */ | |
1842 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1843 | 0, /* rightshift */ | |
1844 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1845 | 0, /* bitsize */ | |
b34976b6 | 1846 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1847 | 0, /* bitpos */ |
1848 | complain_overflow_dont, /* complain_on_overflow */ | |
1849 | NULL, /* special_function */ | |
1850 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1851 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1852 | 0, /* src_mask */ |
1853 | 0, /* dst_mask */ | |
b34976b6 | 1854 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1855 | }; |
1856 | ||
1857 | \f | |
1858 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1859 | be done. */ | |
1860 | ||
1861 | static void | |
4ce794b7 | 1862 | ppc_howto_init (void) |
5bd4f169 AM |
1863 | { |
1864 | unsigned int i, type; | |
1865 | ||
1866 | for (i = 0; | |
1867 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1868 | i++) | |
1869 | { | |
1870 | type = ppc64_elf_howto_raw[i].type; | |
1871 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1872 | / sizeof (ppc64_elf_howto_table[0]))); | |
1873 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1874 | } | |
1875 | } | |
1876 | ||
1877 | static reloc_howto_type * | |
4ce794b7 AM |
1878 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1879 | bfd_reloc_code_real_type code) | |
5bd4f169 | 1880 | { |
411e1bfb | 1881 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
5bd4f169 AM |
1882 | |
1883 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1884 | /* Initialize howto table if needed. */ | |
1885 | ppc_howto_init (); | |
1886 | ||
4ce794b7 | 1887 | switch (code) |
5bd4f169 AM |
1888 | { |
1889 | default: | |
4ce794b7 | 1890 | return NULL; |
5bd4f169 | 1891 | |
411e1bfb AM |
1892 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
1893 | break; | |
1894 | case BFD_RELOC_32: r = R_PPC64_ADDR32; | |
1895 | break; | |
1896 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; | |
1897 | break; | |
1898 | case BFD_RELOC_16: r = R_PPC64_ADDR16; | |
1899 | break; | |
1900 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; | |
1901 | break; | |
1902 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; | |
1903 | break; | |
1904 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; | |
5bd4f169 | 1905 | break; |
411e1bfb | 1906 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
5bd4f169 | 1907 | break; |
411e1bfb | 1908 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
5bd4f169 | 1909 | break; |
411e1bfb | 1910 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
5bd4f169 | 1911 | break; |
411e1bfb | 1912 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
5bd4f169 | 1913 | break; |
411e1bfb | 1914 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
5bd4f169 | 1915 | break; |
411e1bfb | 1916 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
5bd4f169 | 1917 | break; |
411e1bfb | 1918 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
5bd4f169 | 1919 | break; |
411e1bfb | 1920 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
5bd4f169 | 1921 | break; |
411e1bfb | 1922 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
5bd4f169 | 1923 | break; |
411e1bfb | 1924 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
5bd4f169 | 1925 | break; |
411e1bfb | 1926 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
5bd4f169 | 1927 | break; |
411e1bfb | 1928 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
5bd4f169 | 1929 | break; |
411e1bfb | 1930 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
5bd4f169 | 1931 | break; |
411e1bfb | 1932 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
5bd4f169 | 1933 | break; |
411e1bfb | 1934 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
5bd4f169 | 1935 | break; |
411e1bfb | 1936 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
5bd4f169 | 1937 | break; |
411e1bfb | 1938 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
5bd4f169 | 1939 | break; |
411e1bfb | 1940 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
5bd4f169 | 1941 | break; |
411e1bfb | 1942 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
5bd4f169 | 1943 | break; |
411e1bfb | 1944 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
5bd4f169 | 1945 | break; |
411e1bfb | 1946 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
5bd4f169 | 1947 | break; |
411e1bfb | 1948 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
5bd4f169 | 1949 | break; |
411e1bfb | 1950 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
5bd4f169 | 1951 | break; |
411e1bfb | 1952 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
5bd4f169 | 1953 | break; |
411e1bfb | 1954 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
5bd4f169 | 1955 | break; |
411e1bfb | 1956 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
5bd4f169 | 1957 | break; |
411e1bfb | 1958 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
5bd4f169 | 1959 | break; |
411e1bfb | 1960 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
5bd4f169 | 1961 | break; |
411e1bfb | 1962 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
5bd4f169 | 1963 | break; |
411e1bfb | 1964 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
5bd4f169 | 1965 | break; |
411e1bfb | 1966 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
5bd4f169 | 1967 | break; |
411e1bfb | 1968 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
5bd4f169 | 1969 | break; |
411e1bfb | 1970 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
5bd4f169 | 1971 | break; |
411e1bfb | 1972 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
5bd4f169 | 1973 | break; |
411e1bfb | 1974 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
5bd4f169 | 1975 | break; |
411e1bfb | 1976 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
5bd4f169 | 1977 | break; |
411e1bfb | 1978 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
5bd4f169 | 1979 | break; |
411e1bfb | 1980 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
5bd4f169 | 1981 | break; |
411e1bfb | 1982 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
5bd4f169 | 1983 | break; |
411e1bfb | 1984 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
5bd4f169 | 1985 | break; |
411e1bfb | 1986 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
5bd4f169 | 1987 | break; |
411e1bfb | 1988 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
5bd4f169 | 1989 | break; |
411e1bfb | 1990 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
5bd4f169 | 1991 | break; |
411e1bfb | 1992 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
5bd4f169 | 1993 | break; |
411e1bfb | 1994 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
5bd4f169 | 1995 | break; |
411e1bfb | 1996 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
5bd4f169 | 1997 | break; |
411e1bfb | 1998 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
5bd4f169 | 1999 | break; |
411e1bfb | 2000 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
5bd4f169 | 2001 | break; |
411e1bfb | 2002 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
5bd4f169 | 2003 | break; |
411e1bfb | 2004 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
5bd4f169 | 2005 | break; |
411e1bfb | 2006 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
5bd4f169 | 2007 | break; |
411e1bfb | 2008 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
5bd4f169 | 2009 | break; |
411e1bfb | 2010 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
5bd4f169 | 2011 | break; |
411e1bfb | 2012 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
5bd4f169 | 2013 | break; |
411e1bfb | 2014 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
5bd4f169 | 2015 | break; |
411e1bfb | 2016 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
5bd4f169 | 2017 | break; |
411e1bfb | 2018 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
5bd4f169 | 2019 | break; |
411e1bfb | 2020 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
5bd4f169 | 2021 | break; |
411e1bfb | 2022 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
5bd4f169 | 2023 | break; |
411e1bfb AM |
2024 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
2025 | break; | |
2026 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; | |
2027 | break; | |
2028 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; | |
2029 | break; | |
2030 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; | |
2031 | break; | |
2032 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; | |
2033 | break; | |
2034 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; | |
2035 | break; | |
2036 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; | |
2037 | break; | |
2038 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; | |
2039 | break; | |
2040 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; | |
2041 | break; | |
2042 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; | |
2043 | break; | |
2044 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; | |
2045 | break; | |
2046 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; | |
2047 | break; | |
2048 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; | |
2049 | break; | |
2050 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; | |
2051 | break; | |
2052 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; | |
2053 | break; | |
2054 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; | |
2055 | break; | |
2056 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; | |
2057 | break; | |
2058 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; | |
2059 | break; | |
2060 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; | |
2061 | break; | |
2062 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; | |
2063 | break; | |
2064 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; | |
2065 | break; | |
2066 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; | |
2067 | break; | |
2068 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; | |
2069 | break; | |
2070 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; | |
2071 | break; | |
2072 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; | |
2073 | break; | |
2074 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; | |
2075 | break; | |
2076 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; | |
2077 | break; | |
2078 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; | |
2079 | break; | |
2080 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; | |
2081 | break; | |
2082 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; | |
2083 | break; | |
2084 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; | |
2085 | break; | |
2086 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; | |
2087 | break; | |
2088 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; | |
2089 | break; | |
2090 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; | |
2091 | break; | |
2092 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; | |
5bd4f169 AM |
2093 | break; |
2094 | } | |
2095 | ||
4ce794b7 | 2096 | return ppc64_elf_howto_table[r]; |
5bd4f169 AM |
2097 | }; |
2098 | ||
2099 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
2100 | ||
2101 | static void | |
4ce794b7 AM |
2102 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
2103 | Elf_Internal_Rela *dst) | |
5bd4f169 | 2104 | { |
65f38f15 AM |
2105 | unsigned int type; |
2106 | ||
ef60b7ff | 2107 | /* Initialize howto table if needed. */ |
5bd4f169 | 2108 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
2109 | ppc_howto_init (); |
2110 | ||
65f38f15 AM |
2111 | type = ELF64_R_TYPE (dst->r_info); |
2112 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
2113 | / sizeof (ppc64_elf_howto_table[0]))); | |
2114 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
2115 | } |
2116 | ||
04c9666a | 2117 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
2118 | |
2119 | static bfd_reloc_status_type | |
4ce794b7 AM |
2120 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2121 | void *data, asection *input_section, | |
2122 | bfd *output_bfd, char **error_message) | |
5bd4f169 | 2123 | { |
805fc799 AM |
2124 | /* If this is a relocatable link (output_bfd test tells us), just |
2125 | call the generic function. Any adjustment will be done at final | |
2126 | link time. */ | |
2127 | if (output_bfd != NULL) | |
cedb70c5 | 2128 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2129 | input_section, output_bfd, error_message); |
2130 | ||
2131 | /* Adjust the addend for sign extension of the low 16 bits. | |
2132 | We won't actually be using the low 16 bits, so trashing them | |
2133 | doesn't matter. */ | |
2134 | reloc_entry->addend += 0x8000; | |
2135 | return bfd_reloc_continue; | |
2136 | } | |
5bd4f169 | 2137 | |
2441e016 AM |
2138 | static bfd_reloc_status_type |
2139 | ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
2140 | void *data, asection *input_section, | |
2141 | bfd *output_bfd, char **error_message) | |
2142 | { | |
2143 | if (output_bfd != NULL) | |
2144 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
2145 | input_section, output_bfd, error_message); | |
2146 | ||
2147 | if (strcmp (symbol->section->name, ".opd") == 0) | |
2148 | { | |
2149 | bfd_vma dest = opd_entry_value (symbol->section, | |
2150 | symbol->value + reloc_entry->addend, | |
2151 | NULL, NULL); | |
2152 | if (dest != (bfd_vma) -1) | |
2153 | reloc_entry->addend = dest - (symbol->value | |
2154 | + symbol->section->output_section->vma | |
2155 | + symbol->section->output_offset); | |
2156 | } | |
2157 | return bfd_reloc_continue; | |
2158 | } | |
2159 | ||
805fc799 | 2160 | static bfd_reloc_status_type |
4ce794b7 AM |
2161 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2162 | void *data, asection *input_section, | |
2163 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2164 | { |
2165 | long insn; | |
04c9666a | 2166 | enum elf_ppc64_reloc_type r_type; |
805fc799 AM |
2167 | bfd_size_type octets; |
2168 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 2169 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
2170 | |
2171 | /* If this is a relocatable link (output_bfd test tells us), just | |
2172 | call the generic function. Any adjustment will be done at final | |
2173 | link time. */ | |
5bd4f169 | 2174 | if (output_bfd != NULL) |
cedb70c5 | 2175 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2176 | input_section, output_bfd, error_message); |
2177 | ||
2178 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2179 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2180 | insn &= ~(0x01 << 21); | |
4ce794b7 | 2181 | r_type = reloc_entry->howto->type; |
805fc799 AM |
2182 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
2183 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 2184 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
2185 | |
2186 | if (is_power4) | |
5bd4f169 | 2187 | { |
805fc799 AM |
2188 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
2189 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
2190 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
2191 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
2192 | insn |= 0x02 << 21; | |
2193 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
2194 | insn |= 0x08 << 21; | |
2195 | else | |
2441e016 | 2196 | goto out; |
5bd4f169 | 2197 | } |
805fc799 AM |
2198 | else |
2199 | { | |
2200 | bfd_vma target = 0; | |
2201 | bfd_vma from; | |
5bd4f169 | 2202 | |
805fc799 AM |
2203 | if (!bfd_is_com_section (symbol->section)) |
2204 | target = symbol->value; | |
2205 | target += symbol->section->output_section->vma; | |
2206 | target += symbol->section->output_offset; | |
2207 | target += reloc_entry->addend; | |
5bd4f169 | 2208 | |
805fc799 AM |
2209 | from = (reloc_entry->address |
2210 | + input_section->output_offset | |
2211 | + input_section->output_section->vma); | |
5bd4f169 | 2212 | |
805fc799 AM |
2213 | /* Invert 'y' bit if not the default. */ |
2214 | if ((bfd_signed_vma) (target - from) < 0) | |
2215 | insn ^= 0x01 << 21; | |
2216 | } | |
4ce794b7 | 2217 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
2441e016 AM |
2218 | out: |
2219 | return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data, | |
2220 | input_section, output_bfd, error_message); | |
805fc799 | 2221 | } |
5bd4f169 | 2222 | |
805fc799 | 2223 | static bfd_reloc_status_type |
4ce794b7 AM |
2224 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2225 | void *data, asection *input_section, | |
2226 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2227 | { |
2228 | /* If this is a relocatable link (output_bfd test tells us), just | |
2229 | call the generic function. Any adjustment will be done at final | |
2230 | link time. */ | |
2231 | if (output_bfd != NULL) | |
cedb70c5 | 2232 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 2233 | input_section, output_bfd, error_message); |
5bd4f169 | 2234 | |
805fc799 AM |
2235 | /* Subtract the symbol section base address. */ |
2236 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
2237 | return bfd_reloc_continue; |
2238 | } | |
2239 | ||
805fc799 | 2240 | static bfd_reloc_status_type |
4ce794b7 AM |
2241 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2242 | void *data, asection *input_section, | |
2243 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2244 | { |
2245 | /* If this is a relocatable link (output_bfd test tells us), just | |
2246 | call the generic function. Any adjustment will be done at final | |
2247 | link time. */ | |
2248 | if (output_bfd != NULL) | |
cedb70c5 | 2249 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2250 | input_section, output_bfd, error_message); |
2251 | ||
2252 | /* Subtract the symbol section base address. */ | |
2253 | reloc_entry->addend -= symbol->section->output_section->vma; | |
2254 | ||
2255 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2256 | reloc_entry->addend += 0x8000; | |
2257 | return bfd_reloc_continue; | |
2258 | } | |
2259 | ||
2260 | static bfd_reloc_status_type | |
4ce794b7 AM |
2261 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2262 | void *data, asection *input_section, | |
2263 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2264 | { |
2265 | bfd_vma TOCstart; | |
2266 | ||
2267 | /* If this is a relocatable link (output_bfd test tells us), just | |
2268 | call the generic function. Any adjustment will be done at final | |
2269 | link time. */ | |
2270 | if (output_bfd != NULL) | |
cedb70c5 | 2271 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2272 | input_section, output_bfd, error_message); |
2273 | ||
2274 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2275 | if (TOCstart == 0) | |
2276 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2277 | ||
2278 | /* Subtract the TOC base address. */ | |
2279 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2280 | return bfd_reloc_continue; | |
2281 | } | |
2282 | ||
2283 | static bfd_reloc_status_type | |
4ce794b7 AM |
2284 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2285 | void *data, asection *input_section, | |
2286 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2287 | { |
2288 | bfd_vma TOCstart; | |
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 | /* Subtract the TOC base address. */ | |
2302 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2303 | ||
2304 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2305 | reloc_entry->addend += 0x8000; | |
2306 | return bfd_reloc_continue; | |
2307 | } | |
2308 | ||
2309 | static bfd_reloc_status_type | |
4ce794b7 AM |
2310 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2311 | void *data, asection *input_section, | |
2312 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2313 | { |
2314 | bfd_vma TOCstart; | |
2315 | bfd_size_type octets; | |
2316 | ||
2317 | /* If this is a relocatable link (output_bfd test tells us), just | |
2318 | call the generic function. Any adjustment will be done at final | |
2319 | link time. */ | |
2320 | if (output_bfd != NULL) | |
cedb70c5 | 2321 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2322 | input_section, output_bfd, error_message); |
2323 | ||
2324 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2325 | if (TOCstart == 0) | |
2326 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2327 | ||
2328 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2329 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
2330 | return bfd_reloc_ok; | |
2331 | } | |
2332 | ||
2333 | static bfd_reloc_status_type | |
4ce794b7 AM |
2334 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2335 | void *data, asection *input_section, | |
2336 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2337 | { |
2338 | /* If this is a relocatable link (output_bfd test tells us), just | |
2339 | call the generic function. Any adjustment will be done at final | |
2340 | link time. */ | |
2341 | if (output_bfd != NULL) | |
cedb70c5 | 2342 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2343 | input_section, output_bfd, error_message); |
2344 | ||
2345 | if (error_message != NULL) | |
2346 | { | |
2347 | static char buf[60]; | |
2348 | sprintf (buf, "generic linker can't handle %s", | |
2349 | reloc_entry->howto->name); | |
2350 | *error_message = buf; | |
2351 | } | |
2352 | return bfd_reloc_dangerous; | |
2353 | } | |
2354 | ||
e717da7e AM |
2355 | struct ppc64_elf_obj_tdata |
2356 | { | |
2357 | struct elf_obj_tdata elf; | |
2358 | ||
2359 | /* Shortcuts to dynamic linker sections. */ | |
2360 | asection *got; | |
2361 | asection *relgot; | |
2362 | ||
81688140 AM |
2363 | /* Used during garbage collection. We attach global symbols defined |
2364 | on removed .opd entries to this section so that the sym is removed. */ | |
2365 | asection *deleted_section; | |
2366 | ||
e717da7e AM |
2367 | /* TLS local dynamic got entry handling. Suppose for multiple GOT |
2368 | sections means we potentially need one of these for each input bfd. */ | |
2369 | union { | |
2370 | bfd_signed_vma refcount; | |
2371 | bfd_vma offset; | |
2372 | } tlsld_got; | |
2373 | }; | |
2374 | ||
2375 | #define ppc64_elf_tdata(bfd) \ | |
2376 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) | |
2377 | ||
2378 | #define ppc64_tlsld_got(bfd) \ | |
2379 | (&ppc64_elf_tdata (bfd)->tlsld_got) | |
2380 | ||
2381 | /* Override the generic function because we store some extras. */ | |
2382 | ||
2383 | static bfd_boolean | |
2384 | ppc64_elf_mkobject (bfd *abfd) | |
2385 | { | |
2386 | bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); | |
2387 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2388 | if (abfd->tdata.any == NULL) | |
2389 | return FALSE; | |
2390 | return TRUE; | |
2391 | } | |
2392 | ||
feee612b AM |
2393 | /* Fix bad default arch selected for a 64 bit input bfd when the |
2394 | default is 32 bit. */ | |
2395 | ||
b34976b6 | 2396 | static bfd_boolean |
4ce794b7 | 2397 | ppc64_elf_object_p (bfd *abfd) |
feee612b AM |
2398 | { |
2399 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
2400 | { | |
2401 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2402 | ||
2403 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
2404 | { | |
2405 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
2406 | abfd->arch_info = abfd->arch_info->next; | |
2407 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
2408 | } | |
2409 | } | |
b34976b6 | 2410 | return TRUE; |
feee612b AM |
2411 | } |
2412 | ||
d37c89e5 AM |
2413 | /* Support for core dump NOTE sections. */ |
2414 | ||
2415 | static bfd_boolean | |
2416 | ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
2417 | { | |
eea6121a | 2418 | size_t offset, size; |
d37c89e5 AM |
2419 | |
2420 | if (note->descsz != 504) | |
2421 | return FALSE; | |
2422 | ||
2423 | /* pr_cursig */ | |
2424 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
2425 | ||
2426 | /* pr_pid */ | |
2427 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32); | |
2428 | ||
2429 | /* pr_reg */ | |
2430 | offset = 112; | |
eea6121a | 2431 | size = 384; |
d37c89e5 AM |
2432 | |
2433 | /* Make a ".reg/999" section. */ | |
2434 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
eea6121a | 2435 | size, note->descpos + offset); |
d37c89e5 AM |
2436 | } |
2437 | ||
2438 | static bfd_boolean | |
2439 | ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
2440 | { | |
2441 | if (note->descsz != 136) | |
2442 | return FALSE; | |
2443 | ||
2444 | elf_tdata (abfd)->core_program | |
2445 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |
2446 | elf_tdata (abfd)->core_command | |
2447 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |
2448 | ||
2449 | return TRUE; | |
2450 | } | |
2451 | ||
5bd4f169 AM |
2452 | /* Merge backend specific data from an object file to the output |
2453 | object file when linking. */ | |
2f6d9989 | 2454 | |
b34976b6 | 2455 | static bfd_boolean |
4ce794b7 | 2456 | ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
5bd4f169 | 2457 | { |
5bd4f169 AM |
2458 | /* Check if we have the same endianess. */ |
2459 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
87e226ce | 2460 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
5bd4f169 AM |
2461 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
2462 | { | |
2463 | const char *msg; | |
2464 | ||
2465 | if (bfd_big_endian (ibfd)) | |
d003868e | 2466 | msg = _("%B: compiled for a big endian system " |
4ce794b7 | 2467 | "and target is little endian"); |
5bd4f169 | 2468 | else |
d003868e | 2469 | msg = _("%B: compiled for a little endian system " |
4ce794b7 | 2470 | "and target is big endian"); |
5bd4f169 | 2471 | |
d003868e | 2472 | (*_bfd_error_handler) (msg, ibfd); |
5bd4f169 AM |
2473 | |
2474 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 2475 | return FALSE; |
5bd4f169 AM |
2476 | } |
2477 | ||
b34976b6 | 2478 | return TRUE; |
5bd4f169 | 2479 | } |
f0abc2a1 | 2480 | |
5d35169e AM |
2481 | /* Add extra PPC sections. */ |
2482 | ||
2483 | static struct bfd_elf_special_section const ppc64_elf_special_sections[]= | |
2484 | { | |
7dcb9820 AM |
2485 | { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
2486 | { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2487 | { ".plt", 4, 0, SHT_NOBITS, 0 }, | |
2488 | { ".toc", 4, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2489 | { ".toc1", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2490 | { ".tocbss", 7, 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2491 | { NULL, 0, 0, 0, 0 } | |
5d35169e AM |
2492 | }; |
2493 | ||
f0abc2a1 AM |
2494 | struct _ppc64_elf_section_data |
2495 | { | |
2496 | struct bfd_elf_section_data elf; | |
411e1bfb AM |
2497 | |
2498 | /* An array with one entry for each opd function descriptor. */ | |
f0abc2a1 AM |
2499 | union |
2500 | { | |
411e1bfb | 2501 | /* Points to the function code section for local opd entries. */ |
f0abc2a1 | 2502 | asection **func_sec; |
411e1bfb | 2503 | /* After editing .opd, adjust references to opd local syms. */ |
f0abc2a1 AM |
2504 | long *adjust; |
2505 | } opd; | |
411e1bfb AM |
2506 | |
2507 | /* An array for toc sections, indexed by offset/8. | |
2508 | Specifies the relocation symbol index used at a given toc offset. */ | |
2509 | unsigned *t_symndx; | |
f0abc2a1 AM |
2510 | }; |
2511 | ||
2512 | #define ppc64_elf_section_data(sec) \ | |
411e1bfb | 2513 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
f0abc2a1 AM |
2514 | |
2515 | static bfd_boolean | |
4ce794b7 | 2516 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
f0abc2a1 AM |
2517 | { |
2518 | struct _ppc64_elf_section_data *sdata; | |
2519 | bfd_size_type amt = sizeof (*sdata); | |
2520 | ||
4ce794b7 | 2521 | sdata = bfd_zalloc (abfd, amt); |
f0abc2a1 AM |
2522 | if (sdata == NULL) |
2523 | return FALSE; | |
4ce794b7 | 2524 | sec->used_by_bfd = sdata; |
f0abc2a1 AM |
2525 | |
2526 | return _bfd_elf_new_section_hook (abfd, sec); | |
2527 | } | |
4025353c AM |
2528 | |
2529 | static void * | |
2530 | get_opd_info (asection * sec) | |
2531 | { | |
2532 | if (sec != NULL | |
2533 | && ppc64_elf_section_data (sec) != NULL | |
2534 | && ppc64_elf_section_data (sec)->opd.adjust != NULL) | |
2535 | return ppc64_elf_section_data (sec)->opd.adjust; | |
2536 | return NULL; | |
2537 | } | |
5bd4f169 | 2538 | \f |
65f38f15 AM |
2539 | /* The following functions are specific to the ELF linker, while |
2540 | functions above are used generally. Those named ppc64_elf_* are | |
2541 | called by the main ELF linker code. They appear in this file more | |
2542 | or less in the order in which they are called. eg. | |
2543 | ppc64_elf_check_relocs is called early in the link process, | |
2544 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
2545 | called. |
2546 | ||
2547 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
2548 | functions have both a function code symbol and a function descriptor | |
2549 | symbol. A call to foo in a relocatable object file looks like: | |
2550 | ||
2551 | . .text | |
2552 | . x: | |
2553 | . bl .foo | |
2554 | . nop | |
2555 | ||
2556 | The function definition in another object file might be: | |
2557 | ||
2558 | . .section .opd | |
2559 | . foo: .quad .foo | |
2560 | . .quad .TOC.@tocbase | |
2561 | . .quad 0 | |
2562 | . | |
2563 | . .text | |
2564 | . .foo: blr | |
2565 | ||
2566 | When the linker resolves the call during a static link, the branch | |
2567 | unsurprisingly just goes to .foo and the .opd information is unused. | |
2568 | If the function definition is in a shared library, things are a little | |
2569 | different: The call goes via a plt call stub, the opd information gets | |
2570 | copied to the plt, and the linker patches the nop. | |
2571 | ||
2572 | . x: | |
2573 | . bl .foo_stub | |
2574 | . ld 2,40(1) | |
2575 | . | |
2576 | . | |
2577 | . .foo_stub: | |
2578 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
411e1bfb | 2579 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
e86ce104 AM |
2580 | . std 2,40(1) # this is the general idea |
2581 | . ld 11,0(12) | |
2582 | . ld 2,8(12) | |
2583 | . mtctr 11 | |
2584 | . ld 11,16(12) | |
2585 | . bctr | |
2586 | . | |
2587 | . .section .plt | |
2588 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
2589 | ||
2590 | The "reloc ()" notation is supposed to indicate that the linker emits | |
2591 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
2592 | copying. | |
2593 | ||
2594 | What are the difficulties here? Well, firstly, the relocations | |
2595 | examined by the linker in check_relocs are against the function code | |
2596 | sym .foo, while the dynamic relocation in the plt is emitted against | |
2597 | the function descriptor symbol, foo. Somewhere along the line, we need | |
2598 | to carefully copy dynamic link information from one symbol to the other. | |
2599 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
2600 | symbol as is normal for most other backends. We need foo dynamic | |
2601 | instead, at least for an application final link. However, when | |
2602 | creating a shared library containing foo, we need to have both symbols | |
2603 | dynamic so that references to .foo are satisfied during the early | |
2604 | stages of linking. Otherwise the linker might decide to pull in a | |
8387904d AM |
2605 | definition from some other object, eg. a static library. |
2606 | ||
2607 | Update: As of August 2004, we support a new convention. Function | |
2608 | calls may use the function descriptor symbol, ie. "bl foo". This | |
2609 | behaves exactly as "bl .foo". */ | |
65f38f15 AM |
2610 | |
2611 | /* The linker needs to keep track of the number of relocs that it | |
2612 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2613 | This is so that it can later discard them if they are found to be | |
2614 | unnecessary. We store the information in a field extending the | |
2615 | regular ELF linker hash table. */ | |
2616 | ||
2617 | struct ppc_dyn_relocs | |
2618 | { | |
2619 | struct ppc_dyn_relocs *next; | |
2620 | ||
2621 | /* The input section of the reloc. */ | |
2622 | asection *sec; | |
2623 | ||
2624 | /* Total number of relocs copied for the input section. */ | |
2625 | bfd_size_type count; | |
2626 | ||
2627 | /* Number of pc-relative relocs copied for the input section. */ | |
2628 | bfd_size_type pc_count; | |
2629 | }; | |
2630 | ||
411e1bfb AM |
2631 | /* Track GOT entries needed for a given symbol. We might need more |
2632 | than one got entry per symbol. */ | |
2633 | struct got_entry | |
2634 | { | |
2635 | struct got_entry *next; | |
2636 | ||
e7b938ca | 2637 | /* The symbol addend that we'll be placing in the GOT. */ |
411e1bfb AM |
2638 | bfd_vma addend; |
2639 | ||
e717da7e AM |
2640 | /* Unlike other ELF targets, we use separate GOT entries for the same |
2641 | symbol referenced from different input files. This is to support | |
2642 | automatic multiple TOC/GOT sections, where the TOC base can vary | |
2643 | from one input file to another. | |
2644 | ||
2645 | Point to the BFD owning this GOT entry. */ | |
2646 | bfd *owner; | |
2647 | ||
2648 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, | |
2649 | TLS_TPREL or TLS_DTPREL for tls entries. */ | |
2650 | char tls_type; | |
2651 | ||
e7b938ca | 2652 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ |
411e1bfb AM |
2653 | union |
2654 | { | |
2655 | bfd_signed_vma refcount; | |
2656 | bfd_vma offset; | |
2657 | } got; | |
411e1bfb AM |
2658 | }; |
2659 | ||
2660 | /* The same for PLT. */ | |
2661 | struct plt_entry | |
2662 | { | |
2663 | struct plt_entry *next; | |
2664 | ||
2665 | bfd_vma addend; | |
2666 | ||
2667 | union | |
2668 | { | |
2669 | bfd_signed_vma refcount; | |
2670 | bfd_vma offset; | |
2671 | } plt; | |
2672 | }; | |
2673 | ||
65f38f15 | 2674 | /* Of those relocs that might be copied as dynamic relocs, this macro |
58ac9f71 AM |
2675 | selects those that must be copied when linking a shared library, |
2676 | even when the symbol is local. */ | |
65f38f15 | 2677 | |
411e1bfb | 2678 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
805fc799 AM |
2679 | ((RTYPE) != R_PPC64_REL32 \ |
2680 | && (RTYPE) != R_PPC64_REL64 \ | |
04c9666a | 2681 | && (RTYPE) != R_PPC64_REL30) |
65f38f15 | 2682 | |
f4656909 AM |
2683 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2684 | copying dynamic variables from a shared lib into an app's dynbss | |
2685 | section, and instead use a dynamic relocation to point into the | |
5d35169e AM |
2686 | shared lib. With code that gcc generates, it's vital that this be |
2687 | enabled; In the PowerPC64 ABI, the address of a function is actually | |
2688 | the address of a function descriptor, which resides in the .opd | |
2689 | section. gcc uses the descriptor directly rather than going via the | |
2690 | GOT as some other ABI's do, which means that initialized function | |
2691 | pointers must reference the descriptor. Thus, a function pointer | |
2692 | initialized to the address of a function in a shared library will | |
2693 | either require a copy reloc, or a dynamic reloc. Using a copy reloc | |
4cc11e76 | 2694 | redefines the function descriptor symbol to point to the copy. This |
5d35169e AM |
2695 | presents a problem as a plt entry for that function is also |
2696 | initialized from the function descriptor symbol and the copy reloc | |
2697 | may not be initialized first. */ | |
a23b6845 | 2698 | #define ELIMINATE_COPY_RELOCS 1 |
f4656909 | 2699 | |
721956f4 AM |
2700 | /* Section name for stubs is the associated section name plus this |
2701 | string. */ | |
2702 | #define STUB_SUFFIX ".stub" | |
2703 | ||
2704 | /* Linker stubs. | |
2705 | ppc_stub_long_branch: | |
2706 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
2707 | destination, but a 24 bit branch in a stub section will reach. | |
2708 | . b dest | |
2709 | ||
2710 | ppc_stub_plt_branch: | |
2711 | Similar to the above, but a 24 bit branch in the stub section won't | |
2712 | reach its destination. | |
87e226ce AM |
2713 | . addis %r12,%r2,xxx@toc@ha |
2714 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
2715 | . mtctr %r11 |
2716 | . bctr | |
2717 | ||
2718 | ppc_stub_plt_call: | |
2c66dc6c AM |
2719 | Used to call a function in a shared library. If it so happens that |
2720 | the plt entry referenced crosses a 64k boundary, then an extra | |
2721 | "addis %r12,%r12,1" will be inserted before the load at xxx+8 or | |
2722 | xxx+16 as appropriate. | |
87e226ce | 2723 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 2724 | . std %r2,40(%r1) |
87e226ce AM |
2725 | . ld %r11,xxx+0@toc@l(%r12) |
2726 | . ld %r2,xxx+8@toc@l(%r12) | |
721956f4 | 2727 | . mtctr %r11 |
87e226ce | 2728 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 | 2729 | . bctr |
ad8e1ba5 AM |
2730 | |
2731 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional | |
2732 | code to adjust the value and save r2 to support multiple toc sections. | |
2733 | A ppc_stub_long_branch with an r2 offset looks like: | |
2734 | . std %r2,40(%r1) | |
2735 | . addis %r2,%r2,off@ha | |
2736 | . addi %r2,%r2,off@l | |
2737 | . b dest | |
2738 | ||
2739 | A ppc_stub_plt_branch with an r2 offset looks like: | |
2740 | . std %r2,40(%r1) | |
2741 | . addis %r12,%r2,xxx@toc@ha | |
2742 | . ld %r11,xxx@toc@l(%r12) | |
2743 | . addis %r2,%r2,off@ha | |
2744 | . addi %r2,%r2,off@l | |
2745 | . mtctr %r11 | |
2746 | . bctr | |
721956f4 AM |
2747 | */ |
2748 | ||
2749 | enum ppc_stub_type { | |
2750 | ppc_stub_none, | |
2751 | ppc_stub_long_branch, | |
ad8e1ba5 | 2752 | ppc_stub_long_branch_r2off, |
721956f4 | 2753 | ppc_stub_plt_branch, |
ad8e1ba5 | 2754 | ppc_stub_plt_branch_r2off, |
721956f4 AM |
2755 | ppc_stub_plt_call |
2756 | }; | |
2757 | ||
2758 | struct ppc_stub_hash_entry { | |
2759 | ||
2760 | /* Base hash table entry structure. */ | |
2761 | struct bfd_hash_entry root; | |
2762 | ||
ad8e1ba5 AM |
2763 | enum ppc_stub_type stub_type; |
2764 | ||
721956f4 AM |
2765 | /* The stub section. */ |
2766 | asection *stub_sec; | |
2767 | ||
2768 | /* Offset within stub_sec of the beginning of this stub. */ | |
2769 | bfd_vma stub_offset; | |
2770 | ||
2771 | /* Given the symbol's value and its section we can determine its final | |
2772 | value when building the stubs (so the stub knows where to jump. */ | |
2773 | bfd_vma target_value; | |
2774 | asection *target_section; | |
2775 | ||
721956f4 AM |
2776 | /* The symbol table entry, if any, that this was derived from. */ |
2777 | struct ppc_link_hash_entry *h; | |
2778 | ||
411e1bfb AM |
2779 | /* And the reloc addend that this was derived from. */ |
2780 | bfd_vma addend; | |
2781 | ||
721956f4 AM |
2782 | /* Where this stub is being called from, or, in the case of combined |
2783 | stub sections, the first input section in the group. */ | |
2784 | asection *id_sec; | |
2785 | }; | |
2786 | ||
2787 | struct ppc_branch_hash_entry { | |
2788 | ||
2789 | /* Base hash table entry structure. */ | |
2790 | struct bfd_hash_entry root; | |
2791 | ||
2792 | /* Offset within .branch_lt. */ | |
2793 | unsigned int offset; | |
2794 | ||
2795 | /* Generation marker. */ | |
2796 | unsigned int iter; | |
2797 | }; | |
65f38f15 AM |
2798 | |
2799 | struct ppc_link_hash_entry | |
2800 | { | |
2801 | struct elf_link_hash_entry elf; | |
2802 | ||
721956f4 AM |
2803 | /* A pointer to the most recently used stub hash entry against this |
2804 | symbol. */ | |
2805 | struct ppc_stub_hash_entry *stub_cache; | |
2806 | ||
65f38f15 AM |
2807 | /* Track dynamic relocs copied for this symbol. */ |
2808 | struct ppc_dyn_relocs *dyn_relocs; | |
e86ce104 | 2809 | |
721956f4 | 2810 | /* Link between function code and descriptor symbols. */ |
34814b9f | 2811 | struct ppc_link_hash_entry *oh; |
721956f4 | 2812 | |
e86ce104 AM |
2813 | /* Flag function code and descriptor symbols. */ |
2814 | unsigned int is_func:1; | |
2815 | unsigned int is_func_descriptor:1; | |
411e1bfb | 2816 | |
8843416a AM |
2817 | /* Whether global opd sym has been adjusted or not. |
2818 | After ppc64_elf_edit_opd has run, this flag should be set for all | |
2819 | globals defined in any opd section. */ | |
754021d0 AM |
2820 | unsigned int adjust_done:1; |
2821 | ||
99877b66 AM |
2822 | /* Set if we twiddled this symbol to weak at some stage. */ |
2823 | unsigned int was_undefined:1; | |
2824 | ||
411e1bfb | 2825 | /* Contexts in which symbol is used in the GOT (or TOC). |
e7b938ca AM |
2826 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
2827 | corresponding relocs are encountered during check_relocs. | |
2828 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2829 | indicate the corresponding GOT entry type is not needed. | |
2830 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into | |
2831 | a TPREL one. We use a separate flag rather than setting TPREL | |
2832 | just for convenience in distinguishing the two cases. */ | |
2833 | #define TLS_GD 1 /* GD reloc. */ | |
2834 | #define TLS_LD 2 /* LD reloc. */ | |
2835 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2836 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2837 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2838 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ | |
2839 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ | |
2840 | char tls_mask; | |
65f38f15 AM |
2841 | }; |
2842 | ||
2843 | /* ppc64 ELF linker hash table. */ | |
2844 | ||
2845 | struct ppc_link_hash_table | |
2846 | { | |
2847 | struct elf_link_hash_table elf; | |
2848 | ||
721956f4 AM |
2849 | /* The stub hash table. */ |
2850 | struct bfd_hash_table stub_hash_table; | |
2851 | ||
2852 | /* Another hash table for plt_branch stubs. */ | |
2853 | struct bfd_hash_table branch_hash_table; | |
2854 | ||
2855 | /* Linker stub bfd. */ | |
2856 | bfd *stub_bfd; | |
2857 | ||
2858 | /* Linker call-backs. */ | |
4ce794b7 AM |
2859 | asection * (*add_stub_section) (const char *, asection *); |
2860 | void (*layout_sections_again) (void); | |
721956f4 AM |
2861 | |
2862 | /* Array to keep track of which stub sections have been created, and | |
2863 | information on stub grouping. */ | |
2864 | struct map_stub { | |
2865 | /* This is the section to which stubs in the group will be attached. */ | |
2866 | asection *link_sec; | |
2867 | /* The stub section. */ | |
2868 | asection *stub_sec; | |
ad8e1ba5 AM |
2869 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
2870 | bfd_vma toc_off; | |
721956f4 AM |
2871 | } *stub_group; |
2872 | ||
ad8e1ba5 AM |
2873 | /* Temp used when calculating TOC pointers. */ |
2874 | bfd_vma toc_curr; | |
2875 | ||
8f3bab57 AM |
2876 | /* Highest input section id. */ |
2877 | int top_id; | |
2878 | ||
734b6cf9 AM |
2879 | /* Highest output section index. */ |
2880 | int top_index; | |
2881 | ||
2882 | /* List of input sections for each output section. */ | |
2883 | asection **input_list; | |
721956f4 | 2884 | |
65f38f15 | 2885 | /* Short-cuts to get to dynamic linker sections. */ |
4ce794b7 | 2886 | asection *got; |
4ce794b7 AM |
2887 | asection *plt; |
2888 | asection *relplt; | |
2889 | asection *dynbss; | |
2890 | asection *relbss; | |
2891 | asection *glink; | |
82bd7b59 | 2892 | asection *sfpr; |
4ce794b7 AM |
2893 | asection *brlt; |
2894 | asection *relbrlt; | |
ec338859 | 2895 | |
8387904d AM |
2896 | /* Shortcut to .__tls_get_addr and __tls_get_addr. */ |
2897 | struct ppc_link_hash_entry *tls_get_addr; | |
2898 | struct ppc_link_hash_entry *tls_get_addr_fd; | |
411e1bfb | 2899 | |
9b5ecbd0 AM |
2900 | /* Statistics. */ |
2901 | unsigned long stub_count[ppc_stub_plt_call]; | |
2902 | ||
ad8e1ba5 | 2903 | /* Set if we should emit symbols for stubs. */ |
99877b66 | 2904 | unsigned int emit_stub_syms:1; |
ad8e1ba5 | 2905 | |
5d1634d7 | 2906 | /* Set on error. */ |
99877b66 | 2907 | unsigned int stub_error:1; |
721956f4 AM |
2908 | |
2909 | /* Flag set when small branches are detected. Used to | |
2910 | select suitable defaults for the stub group size. */ | |
99877b66 AM |
2911 | unsigned int has_14bit_branch:1; |
2912 | ||
2913 | /* Temp used by ppc64_elf_check_directives. */ | |
2914 | unsigned int twiddled_syms:1; | |
721956f4 AM |
2915 | |
2916 | /* Incremented every time we size stubs. */ | |
2917 | unsigned int stub_iteration; | |
5d1634d7 | 2918 | |
ec338859 AM |
2919 | /* Small local sym to section mapping cache. */ |
2920 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
2921 | }; |
2922 | ||
2923 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ | |
2924 | ||
2925 | #define ppc_hash_table(p) \ | |
2926 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
2927 | ||
721956f4 AM |
2928 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
2929 | ((struct ppc_stub_hash_entry *) \ | |
2930 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2931 | ||
2932 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
2933 | ((struct ppc_branch_hash_entry *) \ | |
2934 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2935 | ||
2936 | /* Create an entry in the stub hash table. */ | |
2937 | ||
2938 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2939 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2940 | struct bfd_hash_table *table, | |
2941 | const char *string) | |
721956f4 AM |
2942 | { |
2943 | /* Allocate the structure if it has not already been allocated by a | |
2944 | subclass. */ | |
2945 | if (entry == NULL) | |
2946 | { | |
2947 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
2948 | if (entry == NULL) | |
2949 | return entry; | |
2950 | } | |
2951 | ||
2952 | /* Call the allocation method of the superclass. */ | |
2953 | entry = bfd_hash_newfunc (entry, table, string); | |
2954 | if (entry != NULL) | |
2955 | { | |
2956 | struct ppc_stub_hash_entry *eh; | |
2957 | ||
2958 | /* Initialize the local fields. */ | |
2959 | eh = (struct ppc_stub_hash_entry *) entry; | |
ad8e1ba5 | 2960 | eh->stub_type = ppc_stub_none; |
721956f4 AM |
2961 | eh->stub_sec = NULL; |
2962 | eh->stub_offset = 0; | |
2963 | eh->target_value = 0; | |
2964 | eh->target_section = NULL; | |
721956f4 AM |
2965 | eh->h = NULL; |
2966 | eh->id_sec = NULL; | |
2967 | } | |
2968 | ||
2969 | return entry; | |
2970 | } | |
2971 | ||
2972 | /* Create an entry in the branch hash table. */ | |
2973 | ||
2974 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2975 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
2976 | struct bfd_hash_table *table, | |
2977 | const char *string) | |
721956f4 AM |
2978 | { |
2979 | /* Allocate the structure if it has not already been allocated by a | |
2980 | subclass. */ | |
2981 | if (entry == NULL) | |
2982 | { | |
2983 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); | |
2984 | if (entry == NULL) | |
2985 | return entry; | |
2986 | } | |
2987 | ||
2988 | /* Call the allocation method of the superclass. */ | |
2989 | entry = bfd_hash_newfunc (entry, table, string); | |
2990 | if (entry != NULL) | |
2991 | { | |
2992 | struct ppc_branch_hash_entry *eh; | |
2993 | ||
2994 | /* Initialize the local fields. */ | |
2995 | eh = (struct ppc_branch_hash_entry *) entry; | |
2996 | eh->offset = 0; | |
2997 | eh->iter = 0; | |
2998 | } | |
2999 | ||
3000 | return entry; | |
3001 | } | |
3002 | ||
65f38f15 AM |
3003 | /* Create an entry in a ppc64 ELF linker hash table. */ |
3004 | ||
3005 | static struct bfd_hash_entry * | |
4ce794b7 AM |
3006 | link_hash_newfunc (struct bfd_hash_entry *entry, |
3007 | struct bfd_hash_table *table, | |
3008 | const char *string) | |
65f38f15 AM |
3009 | { |
3010 | /* Allocate the structure if it has not already been allocated by a | |
3011 | subclass. */ | |
3012 | if (entry == NULL) | |
3013 | { | |
3014 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
3015 | if (entry == NULL) | |
3016 | return entry; | |
3017 | } | |
3018 | ||
3019 | /* Call the allocation method of the superclass. */ | |
3020 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
3021 | if (entry != NULL) | |
3022 | { | |
3023 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
3024 | ||
721956f4 | 3025 | eh->stub_cache = NULL; |
65f38f15 | 3026 | eh->dyn_relocs = NULL; |
721956f4 | 3027 | eh->oh = NULL; |
e86ce104 AM |
3028 | eh->is_func = 0; |
3029 | eh->is_func_descriptor = 0; | |
754021d0 | 3030 | eh->adjust_done = 0; |
99877b66 | 3031 | eh->was_undefined = 0; |
e7b938ca | 3032 | eh->tls_mask = 0; |
65f38f15 AM |
3033 | } |
3034 | ||
3035 | return entry; | |
3036 | } | |
3037 | ||
3038 | /* Create a ppc64 ELF linker hash table. */ | |
3039 | ||
3040 | static struct bfd_link_hash_table * | |
4ce794b7 | 3041 | ppc64_elf_link_hash_table_create (bfd *abfd) |
65f38f15 AM |
3042 | { |
3043 | struct ppc_link_hash_table *htab; | |
3044 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
3045 | ||
4ce794b7 | 3046 | htab = bfd_zmalloc (amt); |
65f38f15 AM |
3047 | if (htab == NULL) |
3048 | return NULL; | |
3049 | ||
3050 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
3051 | { | |
e2d34d7d | 3052 | free (htab); |
65f38f15 AM |
3053 | return NULL; |
3054 | } | |
3055 | ||
721956f4 AM |
3056 | /* Init the stub hash table too. */ |
3057 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) | |
3058 | return NULL; | |
3059 | ||
3060 | /* And the branch hash table. */ | |
3061 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) | |
3062 | return NULL; | |
3063 | ||
3254fd24 AM |
3064 | /* Initializing two fields of the union is just cosmetic. We really |
3065 | only care about glist, but when compiled on a 32-bit host the | |
3066 | bfd_vma fields are larger. Setting the bfd_vma to zero makes | |
3067 | debugger inspection of these fields look nicer. */ | |
3068 | htab->elf.init_refcount.refcount = 0; | |
3069 | htab->elf.init_refcount.glist = NULL; | |
3070 | htab->elf.init_offset.offset = 0; | |
3071 | htab->elf.init_offset.glist = NULL; | |
3072 | ||
65f38f15 AM |
3073 | return &htab->elf.root; |
3074 | } | |
3075 | ||
721956f4 AM |
3076 | /* Free the derived linker hash table. */ |
3077 | ||
3078 | static void | |
4ce794b7 | 3079 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
721956f4 AM |
3080 | { |
3081 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
3082 | ||
3083 | bfd_hash_table_free (&ret->stub_hash_table); | |
3084 | bfd_hash_table_free (&ret->branch_hash_table); | |
3085 | _bfd_generic_link_hash_table_free (hash); | |
3086 | } | |
3087 | ||
e717da7e AM |
3088 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
3089 | ||
3090 | void | |
3091 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
3092 | { | |
3093 | struct ppc_link_hash_table *htab; | |
3094 | ||
3095 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; | |
3096 | ||
3097 | /* Always hook our dynamic sections into the first bfd, which is the | |
3098 | linker created stub bfd. This ensures that the GOT header is at | |
3099 | the start of the output TOC section. */ | |
3100 | htab = ppc_hash_table (info); | |
3101 | htab->stub_bfd = abfd; | |
3102 | htab->elf.dynobj = abfd; | |
3103 | } | |
3104 | ||
721956f4 AM |
3105 | /* Build a name for an entry in the stub hash table. */ |
3106 | ||
3107 | static char * | |
4ce794b7 AM |
3108 | ppc_stub_name (const asection *input_section, |
3109 | const asection *sym_sec, | |
3110 | const struct ppc_link_hash_entry *h, | |
3111 | const Elf_Internal_Rela *rel) | |
721956f4 AM |
3112 | { |
3113 | char *stub_name; | |
3114 | bfd_size_type len; | |
3115 | ||
3116 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
3117 | offsets from a sym as a branch target? In fact, we could | |
3118 | probably assume the addend is always zero. */ | |
3119 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
3120 | ||
3121 | if (h) | |
3122 | { | |
3123 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
3124 | stub_name = bfd_malloc (len); | |
3125 | if (stub_name != NULL) | |
3126 | { | |
97b639ba | 3127 | sprintf (stub_name, "%08x.%s+%x", |
721956f4 AM |
3128 | input_section->id & 0xffffffff, |
3129 | h->elf.root.root.string, | |
3130 | (int) rel->r_addend & 0xffffffff); | |
3131 | } | |
3132 | } | |
3133 | else | |
3134 | { | |
ad8e1ba5 | 3135 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
721956f4 AM |
3136 | stub_name = bfd_malloc (len); |
3137 | if (stub_name != NULL) | |
3138 | { | |
97b639ba | 3139 | sprintf (stub_name, "%08x.%x:%x+%x", |
721956f4 AM |
3140 | input_section->id & 0xffffffff, |
3141 | sym_sec->id & 0xffffffff, | |
3142 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
3143 | (int) rel->r_addend & 0xffffffff); | |
3144 | } | |
3145 | } | |
3146 | return stub_name; | |
3147 | } | |
3148 | ||
3149 | /* Look up an entry in the stub hash. Stub entries are cached because | |
3150 | creating the stub name takes a bit of time. */ | |
3151 | ||
3152 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3153 | ppc_get_stub_entry (const asection *input_section, |
3154 | const asection *sym_sec, | |
3155 | struct elf_link_hash_entry *hash, | |
3156 | const Elf_Internal_Rela *rel, | |
3157 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3158 | { |
3159 | struct ppc_stub_hash_entry *stub_entry; | |
3160 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; | |
3161 | const asection *id_sec; | |
3162 | ||
3163 | /* If this input section is part of a group of sections sharing one | |
3164 | stub section, then use the id of the first section in the group. | |
3165 | Stub names need to include a section id, as there may well be | |
3166 | more than one stub used to reach say, printf, and we need to | |
3167 | distinguish between them. */ | |
3168 | id_sec = htab->stub_group[input_section->id].link_sec; | |
3169 | ||
3170 | if (h != NULL && h->stub_cache != NULL | |
3171 | && h->stub_cache->h == h | |
3172 | && h->stub_cache->id_sec == id_sec) | |
3173 | { | |
3174 | stub_entry = h->stub_cache; | |
3175 | } | |
3176 | else | |
3177 | { | |
3178 | char *stub_name; | |
3179 | ||
3180 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
3181 | if (stub_name == NULL) | |
3182 | return NULL; | |
3183 | ||
3184 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 3185 | stub_name, FALSE, FALSE); |
721956f4 AM |
3186 | if (h != NULL) |
3187 | h->stub_cache = stub_entry; | |
3188 | ||
3189 | free (stub_name); | |
3190 | } | |
3191 | ||
3192 | return stub_entry; | |
3193 | } | |
3194 | ||
3195 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
3196 | stub entry are initialised. */ | |
3197 | ||
3198 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3199 | ppc_add_stub (const char *stub_name, |
3200 | asection *section, | |
3201 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3202 | { |
3203 | asection *link_sec; | |
3204 | asection *stub_sec; | |
3205 | struct ppc_stub_hash_entry *stub_entry; | |
3206 | ||
3207 | link_sec = htab->stub_group[section->id].link_sec; | |
3208 | stub_sec = htab->stub_group[section->id].stub_sec; | |
3209 | if (stub_sec == NULL) | |
3210 | { | |
3211 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
3212 | if (stub_sec == NULL) | |
3213 | { | |
d4c88bbb | 3214 | size_t namelen; |
721956f4 AM |
3215 | bfd_size_type len; |
3216 | char *s_name; | |
3217 | ||
d4c88bbb AM |
3218 | namelen = strlen (link_sec->name); |
3219 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
3220 | s_name = bfd_alloc (htab->stub_bfd, len); |
3221 | if (s_name == NULL) | |
3222 | return NULL; | |
3223 | ||
d4c88bbb AM |
3224 | memcpy (s_name, link_sec->name, namelen); |
3225 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
3226 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
3227 | if (stub_sec == NULL) | |
3228 | return NULL; | |
3229 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
3230 | } | |
3231 | htab->stub_group[section->id].stub_sec = stub_sec; | |
3232 | } | |
3233 | ||
3234 | /* Enter this entry into the linker stub hash table. */ | |
3235 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 3236 | TRUE, FALSE); |
721956f4 AM |
3237 | if (stub_entry == NULL) |
3238 | { | |
d003868e AM |
3239 | (*_bfd_error_handler) (_("%B: cannot create stub entry %s"), |
3240 | section->owner, stub_name); | |
721956f4 AM |
3241 | return NULL; |
3242 | } | |
3243 | ||
3244 | stub_entry->stub_sec = stub_sec; | |
3245 | stub_entry->stub_offset = 0; | |
3246 | stub_entry->id_sec = link_sec; | |
3247 | return stub_entry; | |
3248 | } | |
3249 | ||
82bd7b59 AM |
3250 | /* Create sections for linker generated code. */ |
3251 | ||
b34976b6 | 3252 | static bfd_boolean |
4ce794b7 | 3253 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
82bd7b59 AM |
3254 | { |
3255 | struct ppc_link_hash_table *htab; | |
3256 | flagword flags; | |
3257 | ||
3258 | htab = ppc_hash_table (info); | |
3259 | ||
3260 | /* Create .sfpr for code to save and restore fp regs. */ | |
3261 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
3262 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
721956f4 | 3263 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
82bd7b59 AM |
3264 | if (htab->sfpr == NULL |
3265 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) | |
3266 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) | |
b34976b6 | 3267 | return FALSE; |
82bd7b59 | 3268 | |
721956f4 | 3269 | /* Create .glink for lazy dynamic linking support. */ |
4ce794b7 AM |
3270 | htab->glink = bfd_make_section_anyway (dynobj, ".glink"); |
3271 | if (htab->glink == NULL | |
3272 | || ! bfd_set_section_flags (dynobj, htab->glink, flags) | |
3273 | || ! bfd_set_section_alignment (dynobj, htab->glink, 2)) | |
b34976b6 | 3274 | return FALSE; |
82bd7b59 | 3275 | |
721956f4 AM |
3276 | /* Create .branch_lt for plt_branch stubs. */ |
3277 | flags = (SEC_ALLOC | SEC_LOAD | |
3278 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3279 | htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt"); |
3280 | if (htab->brlt == NULL | |
3281 | || ! bfd_set_section_flags (dynobj, htab->brlt, flags) | |
3282 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) | |
b34976b6 | 3283 | return FALSE; |
721956f4 AM |
3284 | |
3285 | if (info->shared) | |
3286 | { | |
3287 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
3288 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3289 | htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
3290 | if (!htab->relbrlt | |
3291 | || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags) | |
3292 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) | |
b34976b6 | 3293 | return FALSE; |
721956f4 | 3294 | } |
b34976b6 | 3295 | return TRUE; |
82bd7b59 AM |
3296 | } |
3297 | ||
e717da7e AM |
3298 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
3299 | not already done. */ | |
65f38f15 | 3300 | |
b34976b6 | 3301 | static bfd_boolean |
e717da7e | 3302 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
65f38f15 | 3303 | { |
e717da7e AM |
3304 | asection *got, *relgot; |
3305 | flagword flags; | |
3306 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
65f38f15 | 3307 | |
4ce794b7 | 3308 | if (!htab->got) |
e717da7e AM |
3309 | { |
3310 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) | |
3311 | return FALSE; | |
3312 | ||
3313 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); | |
3314 | if (!htab->got) | |
3315 | abort (); | |
3316 | } | |
3317 | ||
3318 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3319 | | SEC_LINKER_CREATED); | |
3320 | ||
3321 | got = bfd_make_section (abfd, ".got"); | |
3322 | if (!got | |
3323 | || !bfd_set_section_flags (abfd, got, flags) | |
3324 | || !bfd_set_section_alignment (abfd, got, 3)) | |
3325 | return FALSE; | |
65f38f15 | 3326 | |
e717da7e AM |
3327 | relgot = bfd_make_section (abfd, ".rela.got"); |
3328 | if (!relgot | |
3329 | || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY) | |
3330 | || ! bfd_set_section_alignment (abfd, relgot, 3)) | |
b34976b6 | 3331 | return FALSE; |
e717da7e AM |
3332 | |
3333 | ppc64_elf_tdata (abfd)->got = got; | |
3334 | ppc64_elf_tdata (abfd)->relgot = relgot; | |
b34976b6 | 3335 | return TRUE; |
65f38f15 | 3336 | } |
5bd4f169 | 3337 | |
82bd7b59 | 3338 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 3339 | |
b34976b6 | 3340 | static bfd_boolean |
4ce794b7 | 3341 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5bd4f169 | 3342 | { |
65f38f15 | 3343 | struct ppc_link_hash_table *htab; |
5bd4f169 | 3344 | |
65f38f15 | 3345 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 3346 | return FALSE; |
65f38f15 | 3347 | |
e717da7e AM |
3348 | htab = ppc_hash_table (info); |
3349 | if (!htab->got) | |
3350 | htab->got = bfd_get_section_by_name (dynobj, ".got"); | |
4ce794b7 AM |
3351 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
3352 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3353 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
65f38f15 | 3354 | if (!info->shared) |
4ce794b7 | 3355 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
65f38f15 | 3356 | |
e717da7e | 3357 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
4ce794b7 | 3358 | || (!info->shared && !htab->relbss)) |
65f38f15 AM |
3359 | abort (); |
3360 | ||
b34976b6 | 3361 | return TRUE; |
5bd4f169 AM |
3362 | } |
3363 | ||
65f38f15 AM |
3364 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
3365 | ||
3366 | static void | |
9c5bfbb7 AM |
3367 | ppc64_elf_copy_indirect_symbol |
3368 | (const struct elf_backend_data *bed ATTRIBUTE_UNUSED, | |
3369 | struct elf_link_hash_entry *dir, | |
3370 | struct elf_link_hash_entry *ind) | |
65f38f15 AM |
3371 | { |
3372 | struct ppc_link_hash_entry *edir, *eind; | |
81848ca0 | 3373 | flagword mask; |
65f38f15 AM |
3374 | |
3375 | edir = (struct ppc_link_hash_entry *) dir; | |
3376 | eind = (struct ppc_link_hash_entry *) ind; | |
3377 | ||
411e1bfb | 3378 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
bbd7ec4a | 3379 | if (eind->dyn_relocs != NULL) |
65f38f15 | 3380 | { |
bbd7ec4a AM |
3381 | if (edir->dyn_relocs != NULL) |
3382 | { | |
3383 | struct ppc_dyn_relocs **pp; | |
3384 | struct ppc_dyn_relocs *p; | |
3385 | ||
411e1bfb | 3386 | if (eind->elf.root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
3387 | abort (); |
3388 | ||
3389 | /* Add reloc counts against the weak sym to the strong sym | |
3390 | list. Merge any entries against the same section. */ | |
3391 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3392 | { | |
3393 | struct ppc_dyn_relocs *q; | |
3394 | ||
3395 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3396 | if (q->sec == p->sec) | |
3397 | { | |
3398 | q->pc_count += p->pc_count; | |
3399 | q->count += p->count; | |
3400 | *pp = p->next; | |
3401 | break; | |
3402 | } | |
3403 | if (q == NULL) | |
3404 | pp = &p->next; | |
3405 | } | |
3406 | *pp = edir->dyn_relocs; | |
3407 | } | |
3408 | ||
65f38f15 AM |
3409 | edir->dyn_relocs = eind->dyn_relocs; |
3410 | eind->dyn_relocs = NULL; | |
3411 | } | |
65f38f15 | 3412 | |
6349e628 AM |
3413 | edir->is_func |= eind->is_func; |
3414 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
58ac9f71 | 3415 | edir->tls_mask |= eind->tls_mask; |
6349e628 | 3416 | |
81848ca0 | 3417 | mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR |
3addb0a9 DJ |
3418 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF |
3419 | | ELF_LINK_HASH_NEEDS_PLT); | |
81848ca0 AM |
3420 | /* If called to transfer flags for a weakdef during processing |
3421 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. | |
3422 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3423 | if (ELIMINATE_COPY_RELOCS | |
3424 | && eind->elf.root.type != bfd_link_hash_indirect | |
3425 | && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) | |
3426 | mask &= ~ELF_LINK_NON_GOT_REF; | |
3427 | ||
3428 | edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask; | |
6349e628 AM |
3429 | |
3430 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3431 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3432 | return; | |
3433 | ||
81848ca0 AM |
3434 | /* Copy over got entries that we may have already seen to the |
3435 | symbol which just became indirect. */ | |
411e1bfb AM |
3436 | if (eind->elf.got.glist != NULL) |
3437 | { | |
3438 | if (edir->elf.got.glist != NULL) | |
3439 | { | |
3440 | struct got_entry **entp; | |
3441 | struct got_entry *ent; | |
3442 | ||
3443 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) | |
3444 | { | |
3445 | struct got_entry *dent; | |
3446 | ||
3447 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) | |
3448 | if (dent->addend == ent->addend | |
e717da7e | 3449 | && dent->owner == ent->owner |
411e1bfb AM |
3450 | && dent->tls_type == ent->tls_type) |
3451 | { | |
3452 | dent->got.refcount += ent->got.refcount; | |
3453 | *entp = ent->next; | |
3454 | break; | |
3455 | } | |
3456 | if (dent == NULL) | |
3457 | entp = &ent->next; | |
3458 | } | |
3459 | *entp = edir->elf.got.glist; | |
3460 | } | |
3461 | ||
3462 | edir->elf.got.glist = eind->elf.got.glist; | |
3463 | eind->elf.got.glist = NULL; | |
3464 | } | |
3465 | ||
3466 | /* And plt entries. */ | |
3467 | if (eind->elf.plt.plist != NULL) | |
3468 | { | |
3469 | if (edir->elf.plt.plist != NULL) | |
3470 | { | |
3471 | struct plt_entry **entp; | |
3472 | struct plt_entry *ent; | |
3473 | ||
3474 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3475 | { | |
3476 | struct plt_entry *dent; | |
3477 | ||
3478 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3479 | if (dent->addend == ent->addend) | |
3480 | { | |
3481 | dent->plt.refcount += ent->plt.refcount; | |
3482 | *entp = ent->next; | |
3483 | break; | |
3484 | } | |
3485 | if (dent == NULL) | |
3486 | entp = &ent->next; | |
3487 | } | |
3488 | *entp = edir->elf.plt.plist; | |
3489 | } | |
3490 | ||
3491 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3492 | eind->elf.plt.plist = NULL; | |
3493 | } | |
3494 | ||
411e1bfb AM |
3495 | if (edir->elf.dynindx == -1) |
3496 | { | |
3497 | edir->elf.dynindx = eind->elf.dynindx; | |
3498 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3499 | eind->elf.dynindx = -1; | |
3500 | eind->elf.dynstr_index = 0; | |
3501 | } | |
3502 | else | |
3503 | BFD_ASSERT (eind->elf.dynindx == -1); | |
3504 | } | |
3505 | ||
8387904d AM |
3506 | /* Find the function descriptor hash entry from the given function code |
3507 | hash entry FH. Link the entries via their OH fields. */ | |
3508 | ||
3509 | static struct ppc_link_hash_entry * | |
3510 | get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) | |
3511 | { | |
3512 | struct ppc_link_hash_entry *fdh = fh->oh; | |
3513 | ||
3514 | if (fdh == NULL) | |
3515 | { | |
3516 | const char *fd_name = fh->elf.root.root.string + 1; | |
3517 | ||
3518 | fdh = (struct ppc_link_hash_entry *) | |
3519 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); | |
3520 | if (fdh != NULL) | |
3521 | { | |
3522 | fdh->is_func_descriptor = 1; | |
3523 | fdh->oh = fh; | |
3524 | fh->is_func = 1; | |
3525 | fh->oh = fdh; | |
3526 | } | |
3527 | } | |
3528 | ||
3529 | return fdh; | |
3530 | } | |
3531 | ||
3532 | /* Hacks to support old ABI code. | |
3533 | When making function calls, old ABI code references function entry | |
3534 | points (dot symbols), while new ABI code references the function | |
3535 | descriptor symbol. We need to make any combination of reference and | |
3536 | definition work together, without breaking archive linking. | |
3537 | ||
3538 | For a defined function "foo" and an undefined call to "bar": | |
3539 | An old object defines "foo" and ".foo", references ".bar" (possibly | |
3540 | "bar" too). | |
3541 | A new object defines "foo" and references "bar". | |
3542 | ||
3543 | A new object thus has no problem with its undefined symbols being | |
3544 | satisfied by definitions in an old object. On the other hand, the | |
3545 | old object won't have ".bar" satisfied by a new object. */ | |
3546 | ||
3547 | /* Fix function descriptor symbols defined in .opd sections to be | |
3548 | function type. */ | |
555cd476 AM |
3549 | |
3550 | static bfd_boolean | |
3551 | ppc64_elf_add_symbol_hook (bfd *ibfd ATTRIBUTE_UNUSED, | |
3552 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
3553 | Elf_Internal_Sym *isym, | |
3554 | const char **name ATTRIBUTE_UNUSED, | |
3555 | flagword *flags ATTRIBUTE_UNUSED, | |
3556 | asection **sec, | |
3557 | bfd_vma *value ATTRIBUTE_UNUSED) | |
3558 | { | |
8843416a AM |
3559 | if (*sec != NULL |
3560 | && strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0) | |
555cd476 AM |
3561 | isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC); |
3562 | return TRUE; | |
3563 | } | |
3564 | ||
8387904d AM |
3565 | /* This function makes an old ABI object reference to ".bar" cause the |
3566 | inclusion of a new ABI object archive that defines "bar". */ | |
3567 | ||
3568 | static struct elf_link_hash_entry * | |
3569 | ppc64_elf_archive_symbol_lookup (bfd *abfd, | |
3570 | struct bfd_link_info *info, | |
3571 | const char *name) | |
3572 | { | |
3573 | struct elf_link_hash_entry *h; | |
3574 | char *dot_name; | |
3575 | size_t len; | |
3576 | ||
3577 | h = _bfd_elf_archive_symbol_lookup (abfd, info, name); | |
3578 | if (h != NULL) | |
3579 | return h; | |
3580 | ||
3581 | if (name[0] == '.') | |
3582 | return h; | |
3583 | ||
3584 | len = strlen (name); | |
3585 | dot_name = bfd_alloc (abfd, len + 2); | |
3586 | if (dot_name == NULL) | |
3587 | return (struct elf_link_hash_entry *) 0 - 1; | |
3588 | dot_name[0] = '.'; | |
3589 | memcpy (dot_name + 1, name, len + 1); | |
3590 | h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name); | |
3591 | bfd_release (abfd, dot_name); | |
3592 | return h; | |
3593 | } | |
3594 | ||
3595 | /* This function satisfies all old ABI object references to ".bar" if a | |
99877b66 AM |
3596 | new ABI object defines "bar". Well, at least, undefined dot symbols |
3597 | are made weak. This stops later archive searches from including an | |
3598 | object if we already have a function descriptor definition. It also | |
35b0ce59 AM |
3599 | prevents the linker complaining about undefined symbols. |
3600 | We also check and correct mismatched symbol visibility here. The | |
3601 | most restrictive visibility of the function descriptor and the | |
3602 | function entry symbol is used. */ | |
8387904d AM |
3603 | |
3604 | static bfd_boolean | |
3605 | add_symbol_adjust (struct elf_link_hash_entry *h, void *inf) | |
3606 | { | |
3607 | struct bfd_link_info *info; | |
3608 | struct ppc_link_hash_table *htab; | |
99877b66 | 3609 | struct ppc_link_hash_entry *eh; |
8387904d AM |
3610 | struct ppc_link_hash_entry *fdh; |
3611 | ||
3612 | if (h->root.type == bfd_link_hash_indirect) | |
3613 | return TRUE; | |
3614 | ||
3615 | if (h->root.type == bfd_link_hash_warning) | |
3616 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3617 | ||
35b0ce59 | 3618 | if (h->root.root.string[0] != '.') |
8387904d AM |
3619 | return TRUE; |
3620 | ||
3621 | info = inf; | |
3622 | htab = ppc_hash_table (info); | |
99877b66 AM |
3623 | eh = (struct ppc_link_hash_entry *) h; |
3624 | fdh = get_fdh (eh, htab); | |
8387904d AM |
3625 | if (fdh != NULL) |
3626 | { | |
35b0ce59 AM |
3627 | unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1; |
3628 | unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1; | |
3629 | if (entry_vis < descr_vis) | |
3630 | fdh->elf.other += entry_vis - descr_vis; | |
3631 | else if (entry_vis > descr_vis) | |
3632 | eh->elf.other += descr_vis - entry_vis; | |
3633 | ||
3634 | if (eh->elf.root.type == bfd_link_hash_undefined) | |
3635 | { | |
3636 | eh->elf.root.type = bfd_link_hash_undefweak; | |
3637 | eh->was_undefined = 1; | |
3638 | htab->twiddled_syms = 1; | |
3639 | } | |
8387904d | 3640 | } |
99877b66 | 3641 | |
8387904d AM |
3642 | return TRUE; |
3643 | } | |
3644 | ||
3645 | static bfd_boolean | |
3646 | ppc64_elf_check_directives (bfd *abfd ATTRIBUTE_UNUSED, | |
3647 | struct bfd_link_info *info) | |
3648 | { | |
99877b66 | 3649 | struct ppc_link_hash_table *htab; |
35b0ce59 AM |
3650 | extern const bfd_target bfd_elf64_powerpc_vec; |
3651 | extern const bfd_target bfd_elf64_powerpcle_vec; | |
99877b66 AM |
3652 | |
3653 | htab = ppc_hash_table (info); | |
35b0ce59 AM |
3654 | if (htab->elf.root.creator != &bfd_elf64_powerpc_vec |
3655 | && htab->elf.root.creator != &bfd_elf64_powerpcle_vec) | |
3656 | return TRUE; | |
3657 | ||
8387904d | 3658 | elf_link_hash_traverse (&htab->elf, add_symbol_adjust, info); |
99877b66 AM |
3659 | |
3660 | /* We need to fix the undefs list for any syms we have twiddled to | |
3661 | undef_weak. */ | |
3662 | if (htab->twiddled_syms) | |
3663 | { | |
3664 | struct bfd_link_hash_entry **pun; | |
3665 | ||
3666 | pun = &htab->elf.root.undefs; | |
3667 | while (*pun != NULL) | |
3668 | { | |
3669 | struct bfd_link_hash_entry *h = *pun; | |
3670 | ||
3671 | if (h->type != bfd_link_hash_undefined | |
3672 | && h->type != bfd_link_hash_common) | |
3673 | { | |
3674 | *pun = h->und_next; | |
3675 | h->und_next = NULL; | |
3676 | if (h == htab->elf.root.undefs_tail) | |
3677 | { | |
3678 | if (pun == &htab->elf.root.undefs) | |
3679 | htab->elf.root.undefs_tail = NULL; | |
3680 | else | |
3681 | /* pun points at an und_next field. Go back to | |
3682 | the start of the link_hash_entry. */ | |
3683 | htab->elf.root.undefs_tail = (struct bfd_link_hash_entry *) | |
3684 | ((char *) pun - ((char *) &h->und_next - (char *) h)); | |
3685 | break; | |
3686 | } | |
3687 | } | |
3688 | else | |
3689 | pun = &h->und_next; | |
3690 | } | |
3691 | ||
3692 | htab->twiddled_syms = 0; | |
3693 | } | |
8387904d AM |
3694 | return TRUE; |
3695 | } | |
3696 | ||
411e1bfb | 3697 | static bfd_boolean |
4ce794b7 AM |
3698 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
3699 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) | |
411e1bfb AM |
3700 | { |
3701 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); | |
e7b938ca | 3702 | char *local_got_tls_masks; |
411e1bfb AM |
3703 | |
3704 | if (local_got_ents == NULL) | |
3705 | { | |
3706 | bfd_size_type size = symtab_hdr->sh_info; | |
3707 | ||
e7b938ca | 3708 | size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks); |
4ce794b7 | 3709 | local_got_ents = bfd_zalloc (abfd, size); |
411e1bfb AM |
3710 | if (local_got_ents == NULL) |
3711 | return FALSE; | |
3712 | elf_local_got_ents (abfd) = local_got_ents; | |
3713 | } | |
3714 | ||
3715 | if ((tls_type & TLS_EXPLICIT) == 0) | |
3716 | { | |
3717 | struct got_entry *ent; | |
3718 | ||
3719 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) | |
e717da7e AM |
3720 | if (ent->addend == r_addend |
3721 | && ent->owner == abfd | |
3722 | && ent->tls_type == tls_type) | |
411e1bfb AM |
3723 | break; |
3724 | if (ent == NULL) | |
3725 | { | |
3726 | bfd_size_type amt = sizeof (*ent); | |
4ce794b7 | 3727 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3728 | if (ent == NULL) |
3729 | return FALSE; | |
3730 | ent->next = local_got_ents[r_symndx]; | |
3731 | ent->addend = r_addend; | |
e717da7e | 3732 | ent->owner = abfd; |
411e1bfb AM |
3733 | ent->tls_type = tls_type; |
3734 | ent->got.refcount = 0; | |
3735 | local_got_ents[r_symndx] = ent; | |
3736 | } | |
3737 | ent->got.refcount += 1; | |
3738 | } | |
3739 | ||
e7b938ca AM |
3740 | local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
3741 | local_got_tls_masks[r_symndx] |= tls_type; | |
411e1bfb | 3742 | return TRUE; |
65f38f15 AM |
3743 | } |
3744 | ||
411e1bfb | 3745 | static bfd_boolean |
4ce794b7 | 3746 | update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend) |
1e2f5b6e | 3747 | { |
411e1bfb | 3748 | struct plt_entry *ent; |
1e2f5b6e | 3749 | |
411e1bfb AM |
3750 | for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next) |
3751 | if (ent->addend == addend) | |
3752 | break; | |
3753 | if (ent == NULL) | |
1e2f5b6e | 3754 | { |
411e1bfb | 3755 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3756 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3757 | if (ent == NULL) |
3758 | return FALSE; | |
3759 | ent->next = eh->elf.plt.plist; | |
3760 | ent->addend = addend; | |
3761 | ent->plt.refcount = 0; | |
3762 | eh->elf.plt.plist = ent; | |
1e2f5b6e | 3763 | } |
411e1bfb AM |
3764 | ent->plt.refcount += 1; |
3765 | eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3766 | eh->is_func = 1; | |
b34976b6 | 3767 | return TRUE; |
1e2f5b6e AM |
3768 | } |
3769 | ||
5bd4f169 | 3770 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 3771 | calculate needed space in the global offset table, procedure |
5d1634d7 | 3772 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 3773 | |
b34976b6 | 3774 | static bfd_boolean |
4ce794b7 AM |
3775 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
3776 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 3777 | { |
65f38f15 | 3778 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3779 | Elf_Internal_Shdr *symtab_hdr; |
3780 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
3781 | const Elf_Internal_Rela *rel; | |
3782 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 3783 | asection *sreloc; |
1e2f5b6e | 3784 | asection **opd_sym_map; |
5bd4f169 | 3785 | |
1049f94e | 3786 | if (info->relocatable) |
b34976b6 | 3787 | return TRUE; |
5bd4f169 | 3788 | |
680a3378 AM |
3789 | /* Don't do anything special with non-loaded, non-alloced sections. |
3790 | In particular, any relocs in such sections should not affect GOT | |
3791 | and PLT reference counting (ie. we don't allow them to create GOT | |
3792 | or PLT entries), there's no possibility or desire to optimize TLS | |
3793 | relocs, and there's not much point in propagating relocs to shared | |
3794 | libs that the dynamic linker won't relocate. */ | |
3795 | if ((sec->flags & SEC_ALLOC) == 0) | |
3796 | return TRUE; | |
3797 | ||
65f38f15 | 3798 | htab = ppc_hash_table (info); |
5bd4f169 | 3799 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
3800 | |
3801 | sym_hashes = elf_sym_hashes (abfd); | |
3802 | sym_hashes_end = (sym_hashes | |
1e2f5b6e AM |
3803 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
3804 | - symtab_hdr->sh_info); | |
5bd4f169 AM |
3805 | |
3806 | sreloc = NULL; | |
1e2f5b6e AM |
3807 | opd_sym_map = NULL; |
3808 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
3809 | { | |
3810 | /* Garbage collection needs some extra help with .opd sections. | |
3811 | We don't want to necessarily keep everything referenced by | |
3812 | relocs in .opd, as that would keep all functions. Instead, | |
3813 | if we reference an .opd symbol (a function descriptor), we | |
3814 | want to keep the function code symbol's section. This is | |
3815 | easy for global symbols, but for local syms we need to keep | |
3816 | information about the associated function section. Later, if | |
3817 | edit_opd deletes entries, we'll use this array to adjust | |
3818 | local syms in .opd. */ | |
3819 | union opd_info { | |
3820 | asection *func_section; | |
3821 | long entry_adjust; | |
3822 | }; | |
3823 | bfd_size_type amt; | |
3824 | ||
eea6121a | 3825 | amt = sec->size * sizeof (union opd_info) / 24; |
4ce794b7 | 3826 | opd_sym_map = bfd_zalloc (abfd, amt); |
1e2f5b6e | 3827 | if (opd_sym_map == NULL) |
b34976b6 | 3828 | return FALSE; |
f0abc2a1 | 3829 | ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map; |
1e2f5b6e | 3830 | } |
5bd4f169 | 3831 | |
82bd7b59 AM |
3832 | if (htab->sfpr == NULL |
3833 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 3834 | return FALSE; |
82bd7b59 | 3835 | |
5bd4f169 AM |
3836 | rel_end = relocs + sec->reloc_count; |
3837 | for (rel = relocs; rel < rel_end; rel++) | |
3838 | { | |
3839 | unsigned long r_symndx; | |
3840 | struct elf_link_hash_entry *h; | |
04c9666a | 3841 | enum elf_ppc64_reloc_type r_type; |
411e1bfb | 3842 | int tls_type = 0; |
5bd4f169 AM |
3843 | |
3844 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3845 | if (r_symndx < symtab_hdr->sh_info) | |
3846 | h = NULL; | |
3847 | else | |
3848 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3849 | ||
4ce794b7 | 3850 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 3851 | switch (r_type) |
5bd4f169 | 3852 | { |
411e1bfb AM |
3853 | case R_PPC64_GOT_TLSLD16: |
3854 | case R_PPC64_GOT_TLSLD16_LO: | |
3855 | case R_PPC64_GOT_TLSLD16_HI: | |
3856 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 3857 | ppc64_tlsld_got (abfd)->refcount += 1; |
951fd09b | 3858 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
3859 | goto dogottls; |
3860 | ||
3861 | case R_PPC64_GOT_TLSGD16: | |
3862 | case R_PPC64_GOT_TLSGD16_LO: | |
3863 | case R_PPC64_GOT_TLSGD16_HI: | |
3864 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 3865 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
3866 | goto dogottls; |
3867 | ||
3868 | case R_PPC64_GOT_TPREL16_DS: | |
3869 | case R_PPC64_GOT_TPREL16_LO_DS: | |
3870 | case R_PPC64_GOT_TPREL16_HI: | |
3871 | case R_PPC64_GOT_TPREL16_HA: | |
3872 | if (info->shared) | |
3873 | info->flags |= DF_STATIC_TLS; | |
3874 | tls_type = TLS_TLS | TLS_TPREL; | |
3875 | goto dogottls; | |
3876 | ||
3877 | case R_PPC64_GOT_DTPREL16_DS: | |
3878 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
3879 | case R_PPC64_GOT_DTPREL16_HI: | |
3880 | case R_PPC64_GOT_DTPREL16_HA: | |
3881 | tls_type = TLS_TLS | TLS_DTPREL; | |
3882 | dogottls: | |
3883 | sec->has_tls_reloc = 1; | |
3884 | /* Fall thru */ | |
3885 | ||
5bd4f169 | 3886 | case R_PPC64_GOT16: |
5bd4f169 | 3887 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
3888 | case R_PPC64_GOT16_HA: |
3889 | case R_PPC64_GOT16_HI: | |
3890 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 3891 | case R_PPC64_GOT16_LO_DS: |
65f38f15 | 3892 | /* This symbol requires a global offset table entry. */ |
ad8e1ba5 | 3893 | sec->has_gp_reloc = 1; |
e717da7e AM |
3894 | if (ppc64_elf_tdata (abfd)->got == NULL |
3895 | && !create_got_section (abfd, info)) | |
b34976b6 | 3896 | return FALSE; |
5bd4f169 AM |
3897 | |
3898 | if (h != NULL) | |
3899 | { | |
411e1bfb AM |
3900 | struct ppc_link_hash_entry *eh; |
3901 | struct got_entry *ent; | |
65f38f15 | 3902 | |
411e1bfb AM |
3903 | eh = (struct ppc_link_hash_entry *) h; |
3904 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) | |
3905 | if (ent->addend == rel->r_addend | |
e717da7e | 3906 | && ent->owner == abfd |
411e1bfb AM |
3907 | && ent->tls_type == tls_type) |
3908 | break; | |
3909 | if (ent == NULL) | |
5bd4f169 | 3910 | { |
411e1bfb | 3911 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3912 | ent = bfd_alloc (abfd, amt); |
411e1bfb | 3913 | if (ent == NULL) |
b34976b6 | 3914 | return FALSE; |
411e1bfb AM |
3915 | ent->next = eh->elf.got.glist; |
3916 | ent->addend = rel->r_addend; | |
e717da7e | 3917 | ent->owner = abfd; |
411e1bfb AM |
3918 | ent->tls_type = tls_type; |
3919 | ent->got.refcount = 0; | |
3920 | eh->elf.got.glist = ent; | |
5bd4f169 | 3921 | } |
411e1bfb | 3922 | ent->got.refcount += 1; |
e7b938ca | 3923 | eh->tls_mask |= tls_type; |
5bd4f169 | 3924 | } |
411e1bfb AM |
3925 | else |
3926 | /* This is a global offset table entry for a local symbol. */ | |
3927 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3928 | rel->r_addend, tls_type)) | |
3929 | return FALSE; | |
5bd4f169 AM |
3930 | break; |
3931 | ||
5bd4f169 | 3932 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
3933 | case R_PPC64_PLT16_HI: |
3934 | case R_PPC64_PLT16_LO: | |
3935 | case R_PPC64_PLT32: | |
3936 | case R_PPC64_PLT64: | |
5bd4f169 | 3937 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
3938 | actually build the entry in adjust_dynamic_symbol, |
3939 | because this might be a case of linking PIC code without | |
3940 | linking in any dynamic objects, in which case we don't | |
3941 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
3942 | if (h == NULL) |
3943 | { | |
3944 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 3945 | table entry for a local symbol. */ |
5bd4f169 | 3946 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3947 | return FALSE; |
5bd4f169 | 3948 | } |
411e1bfb AM |
3949 | else |
3950 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, | |
3951 | rel->r_addend)) | |
3952 | return FALSE; | |
5bd4f169 AM |
3953 | break; |
3954 | ||
3955 | /* The following relocations don't need to propagate the | |
3956 | relocation if linking a shared object since they are | |
3957 | section relative. */ | |
3958 | case R_PPC64_SECTOFF: | |
3959 | case R_PPC64_SECTOFF_LO: | |
3960 | case R_PPC64_SECTOFF_HI: | |
3961 | case R_PPC64_SECTOFF_HA: | |
3962 | case R_PPC64_SECTOFF_DS: | |
3963 | case R_PPC64_SECTOFF_LO_DS: | |
411e1bfb AM |
3964 | case R_PPC64_DTPREL16: |
3965 | case R_PPC64_DTPREL16_LO: | |
3966 | case R_PPC64_DTPREL16_HI: | |
3967 | case R_PPC64_DTPREL16_HA: | |
3968 | case R_PPC64_DTPREL16_DS: | |
3969 | case R_PPC64_DTPREL16_LO_DS: | |
3970 | case R_PPC64_DTPREL16_HIGHER: | |
3971 | case R_PPC64_DTPREL16_HIGHERA: | |
3972 | case R_PPC64_DTPREL16_HIGHEST: | |
3973 | case R_PPC64_DTPREL16_HIGHESTA: | |
5bd4f169 AM |
3974 | break; |
3975 | ||
ad8e1ba5 AM |
3976 | /* Nor do these. */ |
3977 | case R_PPC64_TOC16: | |
3978 | case R_PPC64_TOC16_LO: | |
3979 | case R_PPC64_TOC16_HI: | |
3980 | case R_PPC64_TOC16_HA: | |
3981 | case R_PPC64_TOC16_DS: | |
3982 | case R_PPC64_TOC16_LO_DS: | |
3983 | sec->has_gp_reloc = 1; | |
3984 | break; | |
3985 | ||
5bd4f169 AM |
3986 | /* This relocation describes the C++ object vtable hierarchy. |
3987 | Reconstruct it for later use during GC. */ | |
3988 | case R_PPC64_GNU_VTINHERIT: | |
c152c796 | 3989 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 3990 | return FALSE; |
5bd4f169 AM |
3991 | break; |
3992 | ||
3993 | /* This relocation describes which C++ vtable entries are actually | |
3994 | used. Record for later use during GC. */ | |
3995 | case R_PPC64_GNU_VTENTRY: | |
c152c796 | 3996 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 3997 | return FALSE; |
5bd4f169 AM |
3998 | break; |
3999 | ||
721956f4 AM |
4000 | case R_PPC64_REL14: |
4001 | case R_PPC64_REL14_BRTAKEN: | |
4002 | case R_PPC64_REL14_BRNTAKEN: | |
4003 | htab->has_14bit_branch = 1; | |
4004 | /* Fall through. */ | |
4005 | ||
5d1634d7 | 4006 | case R_PPC64_REL24: |
8387904d | 4007 | if (h != NULL) |
5d1634d7 AM |
4008 | { |
4009 | /* We may need a .plt entry if the function this reloc | |
4010 | refers to is in a shared lib. */ | |
411e1bfb AM |
4011 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
4012 | rel->r_addend)) | |
4013 | return FALSE; | |
8387904d AM |
4014 | if (h == &htab->tls_get_addr->elf |
4015 | || h == &htab->tls_get_addr_fd->elf) | |
411e1bfb | 4016 | sec->has_tls_reloc = 1; |
8387904d AM |
4017 | else if (htab->tls_get_addr == NULL |
4018 | && !strncmp (h->root.root.string, ".__tls_get_addr", 15) | |
a48ebf4d AM |
4019 | && (h->root.root.string[15] == 0 |
4020 | || h->root.root.string[15] == '@')) | |
411e1bfb | 4021 | { |
8387904d AM |
4022 | htab->tls_get_addr = (struct ppc_link_hash_entry *) h; |
4023 | sec->has_tls_reloc = 1; | |
4024 | } | |
4025 | else if (htab->tls_get_addr_fd == NULL | |
4026 | && !strncmp (h->root.root.string, "__tls_get_addr", 14) | |
4027 | && (h->root.root.string[14] == 0 | |
4028 | || h->root.root.string[14] == '@')) | |
4029 | { | |
4030 | htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) h; | |
411e1bfb AM |
4031 | sec->has_tls_reloc = 1; |
4032 | } | |
4033 | } | |
4034 | break; | |
4035 | ||
4036 | case R_PPC64_TPREL64: | |
4037 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | |
4038 | if (info->shared) | |
4039 | info->flags |= DF_STATIC_TLS; | |
4040 | goto dotlstoc; | |
4041 | ||
4042 | case R_PPC64_DTPMOD64: | |
4043 | if (rel + 1 < rel_end | |
4044 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
4045 | && rel[1].r_offset == rel->r_offset + 8) | |
951fd09b | 4046 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
411e1bfb | 4047 | else |
951fd09b | 4048 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
411e1bfb AM |
4049 | goto dotlstoc; |
4050 | ||
4051 | case R_PPC64_DTPREL64: | |
4052 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; | |
4053 | if (rel != relocs | |
4054 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) | |
4055 | && rel[-1].r_offset == rel->r_offset - 8) | |
4056 | /* This is the second reloc of a dtpmod, dtprel pair. | |
4057 | Don't mark with TLS_DTPREL. */ | |
4058 | goto dodyn; | |
4059 | ||
4060 | dotlstoc: | |
4061 | sec->has_tls_reloc = 1; | |
4062 | if (h != NULL) | |
4063 | { | |
4064 | struct ppc_link_hash_entry *eh; | |
4065 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 4066 | eh->tls_mask |= tls_type; |
411e1bfb AM |
4067 | } |
4068 | else | |
4069 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
4070 | rel->r_addend, tls_type)) | |
4071 | return FALSE; | |
4072 | ||
4073 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) | |
4074 | { | |
e7b938ca | 4075 | /* One extra to simplify get_tls_mask. */ |
eea6121a | 4076 | bfd_size_type amt = sec->size * sizeof (unsigned) / 8 + 1; |
4ce794b7 | 4077 | ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt); |
411e1bfb AM |
4078 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
4079 | return FALSE; | |
4080 | } | |
4081 | BFD_ASSERT (rel->r_offset % 8 == 0); | |
4082 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx; | |
951fd09b AM |
4083 | |
4084 | /* Mark the second slot of a GD or LD entry. | |
4085 | -1 to indicate GD and -2 to indicate LD. */ | |
4086 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | |
4087 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1; | |
4088 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) | |
4089 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2; | |
411e1bfb AM |
4090 | goto dodyn; |
4091 | ||
4092 | case R_PPC64_TPREL16: | |
4093 | case R_PPC64_TPREL16_LO: | |
4094 | case R_PPC64_TPREL16_HI: | |
4095 | case R_PPC64_TPREL16_HA: | |
4096 | case R_PPC64_TPREL16_DS: | |
4097 | case R_PPC64_TPREL16_LO_DS: | |
4098 | case R_PPC64_TPREL16_HIGHER: | |
4099 | case R_PPC64_TPREL16_HIGHERA: | |
4100 | case R_PPC64_TPREL16_HIGHEST: | |
4101 | case R_PPC64_TPREL16_HIGHESTA: | |
4102 | if (info->shared) | |
4103 | { | |
4104 | info->flags |= DF_STATIC_TLS; | |
4105 | goto dodyn; | |
5d1634d7 AM |
4106 | } |
4107 | break; | |
4108 | ||
e86ce104 | 4109 | case R_PPC64_ADDR64: |
1e2f5b6e | 4110 | if (opd_sym_map != NULL |
1e2f5b6e | 4111 | && rel + 1 < rel_end |
4ce794b7 | 4112 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
1e2f5b6e | 4113 | { |
8387904d AM |
4114 | if (h != NULL) |
4115 | { | |
4116 | if (h->root.root.string[0] == '.' | |
4117 | && h->root.root.string[1] != 0 | |
4118 | && get_fdh ((struct ppc_link_hash_entry *) h, htab)) | |
4119 | ; | |
4120 | else | |
4121 | ((struct ppc_link_hash_entry *) h)->is_func = 1; | |
4122 | } | |
4123 | else | |
4124 | { | |
4125 | asection *s; | |
1e2f5b6e | 4126 | |
8387904d AM |
4127 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, |
4128 | r_symndx); | |
4129 | if (s == NULL) | |
4130 | return FALSE; | |
4131 | else if (s != sec) | |
4132 | opd_sym_map[rel->r_offset / 24] = s; | |
4133 | } | |
1e2f5b6e | 4134 | } |
e86ce104 AM |
4135 | /* Fall through. */ |
4136 | ||
04c9666a | 4137 | case R_PPC64_REL30: |
5bd4f169 | 4138 | case R_PPC64_REL32: |
04c9666a | 4139 | case R_PPC64_REL64: |
65f38f15 AM |
4140 | case R_PPC64_ADDR14: |
4141 | case R_PPC64_ADDR14_BRNTAKEN: | |
4142 | case R_PPC64_ADDR14_BRTAKEN: | |
4143 | case R_PPC64_ADDR16: | |
4144 | case R_PPC64_ADDR16_DS: | |
4145 | case R_PPC64_ADDR16_HA: | |
4146 | case R_PPC64_ADDR16_HI: | |
4147 | case R_PPC64_ADDR16_HIGHER: | |
4148 | case R_PPC64_ADDR16_HIGHERA: | |
4149 | case R_PPC64_ADDR16_HIGHEST: | |
4150 | case R_PPC64_ADDR16_HIGHESTA: | |
4151 | case R_PPC64_ADDR16_LO: | |
4152 | case R_PPC64_ADDR16_LO_DS: | |
4153 | case R_PPC64_ADDR24: | |
65f38f15 | 4154 | case R_PPC64_ADDR32: |
65f38f15 AM |
4155 | case R_PPC64_UADDR16: |
4156 | case R_PPC64_UADDR32: | |
4157 | case R_PPC64_UADDR64: | |
5bd4f169 | 4158 | case R_PPC64_TOC: |
81848ca0 AM |
4159 | if (h != NULL && !info->shared) |
4160 | /* We may need a copy reloc. */ | |
4161 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
4162 | ||
41bd81ab | 4163 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 4164 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 4165 | break; |
e86ce104 | 4166 | |
65f38f15 AM |
4167 | /* If we are creating a shared library, and this is a reloc |
4168 | against a global symbol, or a non PC relative reloc | |
4169 | against a local symbol, then we need to copy the reloc | |
4170 | into the shared library. However, if we are linking with | |
4171 | -Bsymbolic, we do not need to copy a reloc against a | |
4172 | global symbol which is defined in an object we are | |
4173 | including in the link (i.e., DEF_REGULAR is set). At | |
4174 | this point we have not seen all the input files, so it is | |
4175 | possible that DEF_REGULAR is not set now but will be set | |
4176 | later (it is never cleared). In case of a weak definition, | |
4177 | DEF_REGULAR may be cleared later by a strong definition in | |
4178 | a shared library. We account for that possibility below by | |
f4656909 | 4179 | storing information in the dyn_relocs field of the hash |
65f38f15 AM |
4180 | table entry. A similar situation occurs when creating |
4181 | shared libraries and symbol visibility changes render the | |
4182 | symbol local. | |
4183 | ||
4184 | If on the other hand, we are creating an executable, we | |
4185 | may need to keep relocations for symbols satisfied by a | |
4186 | dynamic library if we manage to avoid copy relocs for the | |
4187 | symbol. */ | |
411e1bfb | 4188 | dodyn: |
65f38f15 | 4189 | if ((info->shared |
411e1bfb | 4190 | && (MUST_BE_DYN_RELOC (r_type) |
65f38f15 AM |
4191 | || (h != NULL |
4192 | && (! info->symbolic | |
4193 | || h->root.type == bfd_link_hash_defweak | |
4194 | || (h->elf_link_hash_flags | |
4195 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
f4656909 AM |
4196 | || (ELIMINATE_COPY_RELOCS |
4197 | && !info->shared | |
65f38f15 AM |
4198 | && h != NULL |
4199 | && (h->root.type == bfd_link_hash_defweak | |
4200 | || (h->elf_link_hash_flags | |
4201 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 4202 | { |
ec338859 AM |
4203 | struct ppc_dyn_relocs *p; |
4204 | struct ppc_dyn_relocs **head; | |
4205 | ||
65f38f15 AM |
4206 | /* We must copy these reloc types into the output file. |
4207 | Create a reloc section in dynobj and make room for | |
4208 | this reloc. */ | |
5bd4f169 AM |
4209 | if (sreloc == NULL) |
4210 | { | |
4211 | const char *name; | |
65f38f15 | 4212 | bfd *dynobj; |
5bd4f169 AM |
4213 | |
4214 | name = (bfd_elf_string_from_elf_section | |
4215 | (abfd, | |
4216 | elf_elfheader (abfd)->e_shstrndx, | |
4217 | elf_section_data (sec)->rel_hdr.sh_name)); | |
4218 | if (name == NULL) | |
b34976b6 | 4219 | return FALSE; |
5bd4f169 | 4220 | |
65f38f15 AM |
4221 | if (strncmp (name, ".rela", 5) != 0 |
4222 | || strcmp (bfd_get_section_name (abfd, sec), | |
4223 | name + 5) != 0) | |
4224 | { | |
4225 | (*_bfd_error_handler) | |
d003868e AM |
4226 | (_("%B: bad relocation section name `%s\'"), |
4227 | abfd, name); | |
5d1634d7 | 4228 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
4229 | } |
4230 | ||
65f38f15 | 4231 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
4232 | sreloc = bfd_get_section_by_name (dynobj, name); |
4233 | if (sreloc == NULL) | |
4234 | { | |
4235 | flagword flags; | |
4236 | ||
4237 | sreloc = bfd_make_section (dynobj, name); | |
4238 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
4239 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4240 | if ((sec->flags & SEC_ALLOC) != 0) | |
4241 | flags |= SEC_ALLOC | SEC_LOAD; | |
4242 | if (sreloc == NULL | |
4243 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 4244 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
b34976b6 | 4245 | return FALSE; |
5bd4f169 | 4246 | } |
65f38f15 | 4247 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
4248 | } |
4249 | ||
65f38f15 AM |
4250 | /* If this is a global symbol, we count the number of |
4251 | relocations we need for this symbol. */ | |
4252 | if (h != NULL) | |
4253 | { | |
ec338859 | 4254 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
4255 | } |
4256 | else | |
4257 | { | |
ec338859 AM |
4258 | /* Track dynamic relocs needed for local syms too. |
4259 | We really need local syms available to do this | |
4260 | easily. Oh well. */ | |
4261 | ||
4262 | asection *s; | |
4263 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
4264 | sec, r_symndx); | |
4265 | if (s == NULL) | |
b34976b6 | 4266 | return FALSE; |
ec338859 AM |
4267 | |
4268 | head = ((struct ppc_dyn_relocs **) | |
4269 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 4270 | } |
ec338859 AM |
4271 | |
4272 | p = *head; | |
4273 | if (p == NULL || p->sec != sec) | |
4274 | { | |
4ce794b7 | 4275 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
ec338859 | 4276 | if (p == NULL) |
b34976b6 | 4277 | return FALSE; |
ec338859 AM |
4278 | p->next = *head; |
4279 | *head = p; | |
4280 | p->sec = sec; | |
4281 | p->count = 0; | |
4282 | p->pc_count = 0; | |
4283 | } | |
4284 | ||
4285 | p->count += 1; | |
411e1bfb | 4286 | if (!MUST_BE_DYN_RELOC (r_type)) |
ec338859 | 4287 | p->pc_count += 1; |
65f38f15 | 4288 | } |
5bd4f169 | 4289 | break; |
65f38f15 AM |
4290 | |
4291 | default: | |
96e0dda4 | 4292 | break; |
5bd4f169 AM |
4293 | } |
4294 | } | |
4295 | ||
b34976b6 | 4296 | return TRUE; |
5bd4f169 AM |
4297 | } |
4298 | ||
8387904d AM |
4299 | /* OFFSET in OPD_SEC specifies a function descriptor. Return the address |
4300 | of the code entry point, and its section. */ | |
4301 | ||
4302 | static bfd_vma | |
4303 | opd_entry_value (asection *opd_sec, | |
4304 | bfd_vma offset, | |
4305 | asection **code_sec, | |
4306 | bfd_vma *code_off) | |
4307 | { | |
4308 | bfd *opd_bfd = opd_sec->owner; | |
4309 | Elf_Internal_Rela *lo, *hi, *look; | |
4310 | ||
4311 | /* Go find the opd reloc at the sym address. */ | |
4312 | lo = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE); | |
4313 | BFD_ASSERT (lo != NULL); | |
4314 | hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */ | |
4315 | ||
4316 | while (lo < hi) | |
4317 | { | |
4318 | look = lo + (hi - lo) / 2; | |
4319 | if (look->r_offset < offset) | |
4320 | lo = look + 1; | |
4321 | else if (look->r_offset > offset) | |
4322 | hi = look; | |
4323 | else | |
4324 | { | |
4325 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (opd_bfd)->symtab_hdr; | |
4326 | if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64 | |
4327 | && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC) | |
4328 | { | |
4329 | unsigned long symndx = ELF64_R_SYM (look->r_info); | |
4330 | bfd_vma val; | |
4331 | asection *sec; | |
4332 | ||
4333 | if (symndx < symtab_hdr->sh_info) | |
4334 | { | |
4335 | Elf_Internal_Sym *sym; | |
4336 | ||
4337 | sym = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4338 | if (sym == NULL) | |
4339 | { | |
4340 | sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, | |
4341 | symtab_hdr->sh_info, | |
4342 | 0, NULL, NULL, NULL); | |
4343 | if (sym == NULL) | |
4344 | return (bfd_vma) -1; | |
4345 | symtab_hdr->contents = (bfd_byte *) sym; | |
4346 | } | |
4347 | ||
4348 | sym += symndx; | |
4349 | val = sym->st_value; | |
4350 | sec = NULL; | |
4351 | if ((sym->st_shndx != SHN_UNDEF | |
4352 | && sym->st_shndx < SHN_LORESERVE) | |
4353 | || sym->st_shndx > SHN_HIRESERVE) | |
4354 | sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx); | |
4355 | BFD_ASSERT ((sec->flags & SEC_MERGE) == 0); | |
4356 | } | |
4357 | else | |
4358 | { | |
4359 | struct elf_link_hash_entry **sym_hashes; | |
4360 | struct elf_link_hash_entry *rh; | |
4361 | ||
4362 | sym_hashes = elf_sym_hashes (opd_bfd); | |
4363 | rh = sym_hashes[symndx - symtab_hdr->sh_info]; | |
4364 | while (rh->root.type == bfd_link_hash_indirect | |
4365 | || rh->root.type == bfd_link_hash_warning) | |
4366 | rh = ((struct elf_link_hash_entry *) rh->root.u.i.link); | |
4367 | BFD_ASSERT (rh->root.type == bfd_link_hash_defined | |
4368 | || rh->root.type == bfd_link_hash_defweak); | |
4369 | val = rh->root.u.def.value; | |
4370 | sec = rh->root.u.def.section; | |
4371 | } | |
4372 | val += look->r_addend; | |
4373 | if (code_off != NULL) | |
4374 | *code_off = val; | |
4375 | if (code_sec != NULL) | |
4376 | *code_sec = sec; | |
4377 | if (sec != NULL && sec->output_section != NULL) | |
4378 | val += sec->output_section->vma + sec->output_offset; | |
4379 | return val; | |
4380 | } | |
4381 | break; | |
4382 | } | |
4383 | } | |
4384 | return (bfd_vma) -1; | |
4385 | } | |
4386 | ||
5bd4f169 AM |
4387 | /* Return the section that should be marked against GC for a given |
4388 | relocation. */ | |
4389 | ||
4390 | static asection * | |
4ce794b7 | 4391 | ppc64_elf_gc_mark_hook (asection *sec, |
ccfa59ea | 4392 | struct bfd_link_info *info, |
4ce794b7 AM |
4393 | Elf_Internal_Rela *rel, |
4394 | struct elf_link_hash_entry *h, | |
4395 | Elf_Internal_Sym *sym) | |
5bd4f169 | 4396 | { |
ccfa59ea AM |
4397 | asection *rsec; |
4398 | ||
4399 | /* First mark all our entry sym sections. */ | |
4400 | if (info->gc_sym_list != NULL) | |
4401 | { | |
4402 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
4403 | struct bfd_sym_chain *sym = info->gc_sym_list; | |
4404 | ||
4405 | info->gc_sym_list = NULL; | |
4406 | do | |
4407 | { | |
4408 | struct ppc_link_hash_entry *eh; | |
4409 | ||
4410 | eh = (struct ppc_link_hash_entry *) | |
4411 | elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); | |
4412 | if (eh == NULL) | |
4413 | continue; | |
4414 | if (eh->elf.root.type != bfd_link_hash_defined | |
4415 | && eh->elf.root.type != bfd_link_hash_defweak) | |
4416 | continue; | |
4417 | ||
4418 | if (eh->is_func_descriptor) | |
4419 | rsec = eh->oh->elf.root.u.def.section; | |
8387904d AM |
4420 | else if (get_opd_info (eh->elf.root.u.def.section) != NULL |
4421 | && opd_entry_value (eh->elf.root.u.def.section, | |
4422 | eh->elf.root.u.def.value, | |
4423 | &rsec, NULL) != (bfd_vma) -1) | |
4424 | ; | |
ccfa59ea AM |
4425 | else |
4426 | continue; | |
4427 | ||
4428 | if (!rsec->gc_mark) | |
4429 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); | |
4430 | ||
4431 | rsec = eh->elf.root.u.def.section; | |
4432 | if (!rsec->gc_mark) | |
4433 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); | |
4434 | ||
4435 | sym = sym->next; | |
4436 | } | |
4437 | while (sym != NULL); | |
4438 | } | |
4439 | ||
4440 | /* Syms return NULL if we're marking .opd, so we avoid marking all | |
4441 | function sections, as all functions are referenced in .opd. */ | |
4442 | rsec = NULL; | |
4443 | if (get_opd_info (sec) != NULL) | |
4444 | return rsec; | |
1e2f5b6e | 4445 | |
5bd4f169 AM |
4446 | if (h != NULL) |
4447 | { | |
04c9666a | 4448 | enum elf_ppc64_reloc_type r_type; |
ccfa59ea | 4449 | struct ppc_link_hash_entry *eh; |
a33d1f77 | 4450 | |
4ce794b7 | 4451 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 4452 | switch (r_type) |
5bd4f169 AM |
4453 | { |
4454 | case R_PPC64_GNU_VTINHERIT: | |
4455 | case R_PPC64_GNU_VTENTRY: | |
4456 | break; | |
4457 | ||
4458 | default: | |
4459 | switch (h->root.type) | |
4460 | { | |
4461 | case bfd_link_hash_defined: | |
4462 | case bfd_link_hash_defweak: | |
ccfa59ea AM |
4463 | eh = (struct ppc_link_hash_entry *) h; |
4464 | if (eh->oh != NULL && eh->oh->is_func_descriptor) | |
4465 | eh = eh->oh; | |
1e2f5b6e AM |
4466 | |
4467 | /* Function descriptor syms cause the associated | |
4468 | function code sym section to be marked. */ | |
ccfa59ea AM |
4469 | if (eh->is_func_descriptor) |
4470 | { | |
4471 | /* They also mark their opd section. */ | |
4472 | if (!eh->elf.root.u.def.section->gc_mark) | |
4473 | _bfd_elf_gc_mark (info, eh->elf.root.u.def.section, | |
4474 | ppc64_elf_gc_mark_hook); | |
4475 | ||
4476 | rsec = eh->oh->elf.root.u.def.section; | |
4477 | } | |
8387904d AM |
4478 | else if (get_opd_info (eh->elf.root.u.def.section) != NULL |
4479 | && opd_entry_value (eh->elf.root.u.def.section, | |
4480 | eh->elf.root.u.def.value, | |
4481 | &rsec, NULL) != (bfd_vma) -1) | |
4482 | { | |
4483 | if (!eh->elf.root.u.def.section->gc_mark) | |
4484 | _bfd_elf_gc_mark (info, eh->elf.root.u.def.section, | |
4485 | ppc64_elf_gc_mark_hook); | |
4486 | } | |
ccfa59ea | 4487 | else |
1e2f5b6e AM |
4488 | rsec = h->root.u.def.section; |
4489 | break; | |
5bd4f169 AM |
4490 | |
4491 | case bfd_link_hash_common: | |
1e2f5b6e AM |
4492 | rsec = h->root.u.c.p->section; |
4493 | break; | |
5bd4f169 AM |
4494 | |
4495 | default: | |
4496 | break; | |
4497 | } | |
4498 | } | |
4499 | } | |
4500 | else | |
4501 | { | |
1e2f5b6e AM |
4502 | asection **opd_sym_section; |
4503 | ||
4504 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
ccfa59ea | 4505 | opd_sym_section = get_opd_info (rsec); |
1e2f5b6e | 4506 | if (opd_sym_section != NULL) |
ccfa59ea AM |
4507 | { |
4508 | if (!rsec->gc_mark) | |
4509 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); | |
4510 | ||
4511 | rsec = opd_sym_section[sym->st_value / 24]; | |
4512 | } | |
5bd4f169 AM |
4513 | } |
4514 | ||
1e2f5b6e | 4515 | return rsec; |
5bd4f169 AM |
4516 | } |
4517 | ||
65f38f15 AM |
4518 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
4519 | section being removed. */ | |
5bd4f169 | 4520 | |
b34976b6 | 4521 | static bfd_boolean |
4ce794b7 AM |
4522 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
4523 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 4524 | { |
411e1bfb | 4525 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
4526 | Elf_Internal_Shdr *symtab_hdr; |
4527 | struct elf_link_hash_entry **sym_hashes; | |
411e1bfb | 4528 | struct got_entry **local_got_ents; |
5bd4f169 | 4529 | const Elf_Internal_Rela *rel, *relend; |
5bd4f169 | 4530 | |
680a3378 AM |
4531 | if ((sec->flags & SEC_ALLOC) == 0) |
4532 | return TRUE; | |
4533 | ||
ec338859 AM |
4534 | elf_section_data (sec)->local_dynrel = NULL; |
4535 | ||
411e1bfb | 4536 | htab = ppc_hash_table (info); |
5bd4f169 AM |
4537 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4538 | sym_hashes = elf_sym_hashes (abfd); | |
411e1bfb | 4539 | local_got_ents = elf_local_got_ents (abfd); |
5bd4f169 AM |
4540 | |
4541 | relend = relocs + sec->reloc_count; | |
4542 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
4543 | { |
4544 | unsigned long r_symndx; | |
04c9666a | 4545 | enum elf_ppc64_reloc_type r_type; |
58ac9f71 | 4546 | struct elf_link_hash_entry *h = NULL; |
411e1bfb | 4547 | char tls_type = 0; |
5bd4f169 | 4548 | |
a33d1f77 | 4549 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 | 4550 | r_type = ELF64_R_TYPE (rel->r_info); |
58ac9f71 AM |
4551 | if (r_symndx >= symtab_hdr->sh_info) |
4552 | { | |
4553 | struct ppc_link_hash_entry *eh; | |
4554 | struct ppc_dyn_relocs **pp; | |
4555 | struct ppc_dyn_relocs *p; | |
4556 | ||
4557 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4558 | eh = (struct ppc_link_hash_entry *) h; | |
4559 | ||
4560 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4561 | if (p->sec == sec) | |
4562 | { | |
4563 | /* Everything must go for SEC. */ | |
4564 | *pp = p->next; | |
4565 | break; | |
4566 | } | |
4567 | } | |
4568 | ||
a33d1f77 AM |
4569 | switch (r_type) |
4570 | { | |
411e1bfb AM |
4571 | case R_PPC64_GOT_TLSLD16: |
4572 | case R_PPC64_GOT_TLSLD16_LO: | |
4573 | case R_PPC64_GOT_TLSLD16_HI: | |
4574 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 4575 | ppc64_tlsld_got (abfd)->refcount -= 1; |
951fd09b | 4576 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
4577 | goto dogot; |
4578 | ||
4579 | case R_PPC64_GOT_TLSGD16: | |
4580 | case R_PPC64_GOT_TLSGD16_LO: | |
4581 | case R_PPC64_GOT_TLSGD16_HI: | |
4582 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 4583 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
4584 | goto dogot; |
4585 | ||
4586 | case R_PPC64_GOT_TPREL16_DS: | |
4587 | case R_PPC64_GOT_TPREL16_LO_DS: | |
4588 | case R_PPC64_GOT_TPREL16_HI: | |
4589 | case R_PPC64_GOT_TPREL16_HA: | |
4590 | tls_type = TLS_TLS | TLS_TPREL; | |
4591 | goto dogot; | |
4592 | ||
4593 | case R_PPC64_GOT_DTPREL16_DS: | |
4594 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
4595 | case R_PPC64_GOT_DTPREL16_HI: | |
4596 | case R_PPC64_GOT_DTPREL16_HA: | |
4597 | tls_type = TLS_TLS | TLS_DTPREL; | |
4598 | goto dogot; | |
4599 | ||
a33d1f77 AM |
4600 | case R_PPC64_GOT16: |
4601 | case R_PPC64_GOT16_DS: | |
4602 | case R_PPC64_GOT16_HA: | |
4603 | case R_PPC64_GOT16_HI: | |
4604 | case R_PPC64_GOT16_LO: | |
4605 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb AM |
4606 | dogot: |
4607 | { | |
4608 | struct got_entry *ent; | |
4609 | ||
58ac9f71 AM |
4610 | if (h != NULL) |
4611 | ent = h->got.glist; | |
411e1bfb AM |
4612 | else |
4613 | ent = local_got_ents[r_symndx]; | |
4614 | ||
4615 | for (; ent != NULL; ent = ent->next) | |
4616 | if (ent->addend == rel->r_addend | |
e717da7e | 4617 | && ent->owner == abfd |
411e1bfb AM |
4618 | && ent->tls_type == tls_type) |
4619 | break; | |
4620 | if (ent == NULL) | |
4621 | abort (); | |
4622 | if (ent->got.refcount > 0) | |
4623 | ent->got.refcount -= 1; | |
4624 | } | |
a33d1f77 | 4625 | break; |
65f38f15 | 4626 | |
a33d1f77 AM |
4627 | case R_PPC64_PLT16_HA: |
4628 | case R_PPC64_PLT16_HI: | |
4629 | case R_PPC64_PLT16_LO: | |
4630 | case R_PPC64_PLT32: | |
4631 | case R_PPC64_PLT64: | |
721956f4 AM |
4632 | case R_PPC64_REL14: |
4633 | case R_PPC64_REL14_BRNTAKEN: | |
4634 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 | 4635 | case R_PPC64_REL24: |
58ac9f71 | 4636 | if (h != NULL) |
5d1634d7 | 4637 | { |
411e1bfb AM |
4638 | struct plt_entry *ent; |
4639 | ||
411e1bfb AM |
4640 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
4641 | if (ent->addend == rel->r_addend) | |
4642 | break; | |
4643 | if (ent == NULL) | |
4644 | abort (); | |
4645 | if (ent->plt.refcount > 0) | |
4646 | ent->plt.refcount -= 1; | |
5d1634d7 | 4647 | } |
e86ce104 | 4648 | break; |
5d1634d7 | 4649 | |
a33d1f77 AM |
4650 | default: |
4651 | break; | |
4652 | } | |
4653 | } | |
b34976b6 | 4654 | return TRUE; |
5bd4f169 AM |
4655 | } |
4656 | ||
e86ce104 AM |
4657 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
4658 | information on function code symbol entries to their corresponding | |
4659 | function descriptor symbol entries. */ | |
b34976b6 | 4660 | static bfd_boolean |
4ce794b7 | 4661 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 4662 | { |
e86ce104 | 4663 | struct bfd_link_info *info; |
65f38f15 | 4664 | struct ppc_link_hash_table *htab; |
411e1bfb | 4665 | struct plt_entry *ent; |
50bc7936 AM |
4666 | struct ppc_link_hash_entry *fh; |
4667 | struct ppc_link_hash_entry *fdh; | |
4668 | bfd_boolean force_local; | |
5bd4f169 | 4669 | |
50bc7936 AM |
4670 | fh = (struct ppc_link_hash_entry *) h; |
4671 | if (fh->elf.root.type == bfd_link_hash_indirect) | |
b34976b6 | 4672 | return TRUE; |
e86ce104 | 4673 | |
50bc7936 AM |
4674 | if (fh->elf.root.type == bfd_link_hash_warning) |
4675 | fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link; | |
e92d460e | 4676 | |
4ce794b7 | 4677 | info = inf; |
65f38f15 | 4678 | htab = ppc_hash_table (info); |
5bd4f169 | 4679 | |
e86ce104 AM |
4680 | /* If this is a function code symbol, transfer dynamic linking |
4681 | information to the function descriptor symbol. */ | |
50bc7936 | 4682 | if (!fh->is_func) |
b34976b6 | 4683 | return TRUE; |
e86ce104 | 4684 | |
50bc7936 | 4685 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
4686 | if (ent->plt.refcount > 0) |
4687 | break; | |
50bc7936 AM |
4688 | if (ent == NULL |
4689 | || fh->elf.root.root.string[0] != '.' | |
4690 | || fh->elf.root.root.string[1] == '\0') | |
4691 | return TRUE; | |
5bd4f169 | 4692 | |
50bc7936 AM |
4693 | /* Find the corresponding function descriptor symbol. Create it |
4694 | as undefined if necessary. */ | |
5bd4f169 | 4695 | |
50bc7936 AM |
4696 | fdh = get_fdh (fh, htab); |
4697 | if (fdh != NULL) | |
4698 | while (fdh->elf.root.type == bfd_link_hash_indirect | |
4699 | || fdh->elf.root.type == bfd_link_hash_warning) | |
4700 | fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link; | |
5bd4f169 | 4701 | |
50bc7936 AM |
4702 | if (fdh == NULL |
4703 | && info->shared | |
4704 | && (fh->elf.root.type == bfd_link_hash_undefined | |
4705 | || fh->elf.root.type == bfd_link_hash_undefweak)) | |
4706 | { | |
4707 | bfd *abfd; | |
4708 | asymbol *newsym; | |
4709 | struct bfd_link_hash_entry *bh; | |
4710 | ||
4711 | abfd = fh->elf.root.u.undef.abfd; | |
4712 | newsym = bfd_make_empty_symbol (abfd); | |
4713 | newsym->name = fh->elf.root.root.string + 1; | |
4714 | newsym->section = bfd_und_section_ptr; | |
4715 | newsym->value = 0; | |
4716 | newsym->flags = BSF_OBJECT; | |
4717 | if (fh->elf.root.type == bfd_link_hash_undefweak) | |
4718 | newsym->flags |= BSF_WEAK; | |
4719 | ||
4720 | bh = &fdh->elf.root; | |
4721 | if ( !(_bfd_generic_link_add_one_symbol | |
4722 | (info, abfd, newsym->name, newsym->flags, | |
4723 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) | |
648cca2c | 4724 | { |
50bc7936 | 4725 | return FALSE; |
648cca2c | 4726 | } |
50bc7936 AM |
4727 | fdh = (struct ppc_link_hash_entry *) bh; |
4728 | fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF; | |
4729 | fdh->elf.size = 24; | |
4730 | fdh->elf.type = STT_OBJECT; | |
4731 | } | |
648cca2c | 4732 | |
50bc7936 AM |
4733 | if (fdh != NULL |
4734 | && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 | |
4735 | && (info->shared | |
4736 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4737 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 | |
4738 | || (fdh->elf.root.type == bfd_link_hash_undefweak | |
4739 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) | |
4740 | { | |
4741 | if (fdh->elf.dynindx == -1) | |
c152c796 | 4742 | if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf)) |
50bc7936 AM |
4743 | return FALSE; |
4744 | fdh->elf.elf_link_hash_flags | |
4745 | |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
4746 | | ELF_LINK_HASH_REF_DYNAMIC | |
4747 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
4748 | | ELF_LINK_NON_GOT_REF)); | |
4749 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) | |
e86ce104 | 4750 | { |
8387904d AM |
4751 | struct plt_entry **ep = &fdh->elf.plt.plist; |
4752 | while (*ep != NULL) | |
4753 | ep = &(*ep)->next; | |
4754 | *ep = fh->elf.plt.plist; | |
4755 | fh->elf.plt.plist = NULL; | |
50bc7936 | 4756 | fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
e86ce104 | 4757 | } |
50bc7936 | 4758 | fdh->is_func_descriptor = 1; |
34814b9f AM |
4759 | fdh->oh = fh; |
4760 | fh->oh = fdh; | |
e86ce104 AM |
4761 | } |
4762 | ||
50bc7936 AM |
4763 | /* Now that the info is on the function descriptor, clear the |
4764 | function code sym info. Any function code syms for which we | |
4765 | don't have a definition in a regular file, we force local. | |
4766 | This prevents a shared library from exporting syms that have | |
4767 | been imported from another library. Function code syms that | |
4768 | are really in the library we must leave global to prevent the | |
4769 | linker dragging in a definition from a static library. */ | |
4770 | force_local | |
4771 | = (info->shared | |
4772 | && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4773 | || fdh == NULL | |
4774 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4775 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)); | |
4776 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); | |
4777 | ||
b34976b6 | 4778 | return TRUE; |
e86ce104 | 4779 | } |
40b8271b | 4780 | |
82bd7b59 AM |
4781 | #define MIN_SAVE_FPR 14 |
4782 | #define MAX_SAVE_FPR 31 | |
4783 | ||
e86ce104 | 4784 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
4785 | this hook to a) provide some gcc support functions, and b) transfer |
4786 | dynamic linking information gathered so far on function code symbol | |
4787 | entries, to their corresponding function descriptor symbol entries. */ | |
b34976b6 | 4788 | static bfd_boolean |
4ce794b7 AM |
4789 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
4790 | struct bfd_link_info *info) | |
e86ce104 AM |
4791 | { |
4792 | struct ppc_link_hash_table *htab; | |
82bd7b59 AM |
4793 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
4794 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; | |
4795 | unsigned int i; | |
4796 | struct elf_link_hash_entry *h; | |
721956f4 | 4797 | bfd_byte *p; |
82bd7b59 | 4798 | char sym[10]; |
e86ce104 AM |
4799 | |
4800 | htab = ppc_hash_table (info); | |
82bd7b59 AM |
4801 | |
4802 | if (htab->sfpr == NULL) | |
4803 | /* We don't have any relocs. */ | |
b34976b6 | 4804 | return TRUE; |
82bd7b59 AM |
4805 | |
4806 | /* First provide any missing ._savef* and ._restf* functions. */ | |
4807 | memcpy (sym, "._savef14", 10); | |
4808 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4809 | { | |
4810 | sym[7] = i / 10 + '0'; | |
4811 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4812 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4813 | if (h != NULL |
772119ce | 4814 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4815 | { |
4816 | if (lowest_savef > i) | |
4817 | lowest_savef = i; | |
4818 | h->root.type = bfd_link_hash_defined; | |
4819 | h->root.u.def.section = htab->sfpr; | |
4820 | h->root.u.def.value = (i - lowest_savef) * 4; | |
4821 | h->type = STT_FUNC; | |
4822 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4823 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4824 | } |
4825 | } | |
4826 | ||
4827 | memcpy (sym, "._restf14", 10); | |
4828 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4829 | { | |
4830 | sym[7] = i / 10 + '0'; | |
4831 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4832 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4833 | if (h != NULL |
772119ce | 4834 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4835 | { |
4836 | if (lowest_restf > i) | |
4837 | lowest_restf = i; | |
4838 | h->root.type = bfd_link_hash_defined; | |
4839 | h->root.u.def.section = htab->sfpr; | |
4840 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 | |
4841 | + (i - lowest_restf) * 4); | |
4842 | h->type = STT_FUNC; | |
4843 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4844 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4845 | } |
4846 | } | |
4847 | ||
4ce794b7 | 4848 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
805fc799 | 4849 | |
eea6121a AM |
4850 | htab->sfpr->size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
4851 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); | |
82bd7b59 | 4852 | |
eea6121a | 4853 | if (htab->sfpr->size == 0) |
805fc799 | 4854 | { |
06da1e8e AM |
4855 | _bfd_strip_section_from_output (info, htab->sfpr); |
4856 | return TRUE; | |
805fc799 | 4857 | } |
82bd7b59 | 4858 | |
eea6121a | 4859 | p = bfd_alloc (htab->elf.dynobj, htab->sfpr->size); |
721956f4 | 4860 | if (p == NULL) |
b34976b6 | 4861 | return FALSE; |
721956f4 AM |
4862 | htab->sfpr->contents = p; |
4863 | ||
4864 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) | |
4865 | { | |
4866 | unsigned int fpr = i << 21; | |
4867 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4868 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); | |
4869 | p += 4; | |
4870 | } | |
4871 | if (lowest_savef <= MAX_SAVE_FPR) | |
4872 | { | |
82bd7b59 AM |
4873 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
4874 | p += 4; | |
721956f4 | 4875 | } |
82bd7b59 | 4876 | |
721956f4 AM |
4877 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
4878 | { | |
4879 | unsigned int fpr = i << 21; | |
4880 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4881 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); | |
82bd7b59 AM |
4882 | p += 4; |
4883 | } | |
06da1e8e AM |
4884 | if (lowest_restf <= MAX_SAVE_FPR) |
4885 | bfd_put_32 (htab->elf.dynobj, BLR, p); | |
82bd7b59 | 4886 | |
b34976b6 | 4887 | return TRUE; |
e86ce104 AM |
4888 | } |
4889 | ||
4890 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
4891 | regular object. The current definition is in some section of the | |
4892 | dynamic object, but we're not including those sections. We have to | |
4893 | change the definition to something the rest of the link can | |
4894 | understand. */ | |
4895 | ||
b34976b6 | 4896 | static bfd_boolean |
4ce794b7 AM |
4897 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
4898 | struct elf_link_hash_entry *h) | |
e86ce104 AM |
4899 | { |
4900 | struct ppc_link_hash_table *htab; | |
e86ce104 AM |
4901 | asection *s; |
4902 | unsigned int power_of_two; | |
4903 | ||
4904 | htab = ppc_hash_table (info); | |
4905 | ||
4906 | /* Deal with function syms. */ | |
4907 | if (h->type == STT_FUNC | |
4908 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
4909 | { | |
4910 | /* Clear procedure linkage table information for any symbol that | |
4911 | won't need a .plt entry. */ | |
411e1bfb AM |
4912 | struct plt_entry *ent; |
4913 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4914 | if (ent->plt.refcount > 0) | |
4915 | break; | |
8387904d | 4916 | if (ent == NULL |
9c7a29a3 AM |
4917 | || SYMBOL_CALLS_LOCAL (info, h) |
4918 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4919 | && h->root.type == bfd_link_hash_undefweak)) | |
40b8271b | 4920 | { |
411e1bfb | 4921 | h->plt.plist = NULL; |
40b8271b | 4922 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
40b8271b | 4923 | } |
5bd4f169 | 4924 | } |
bbd7ec4a | 4925 | else |
411e1bfb | 4926 | h->plt.plist = NULL; |
5bd4f169 AM |
4927 | |
4928 | /* If this is a weak symbol, and there is a real definition, the | |
4929 | processor independent code will have arranged for us to see the | |
4930 | real definition first, and we can just use the same value. */ | |
4931 | if (h->weakdef != NULL) | |
4932 | { | |
4933 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
4934 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
4935 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
4936 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
a23b6845 AM |
4937 | if (ELIMINATE_COPY_RELOCS) |
4938 | h->elf_link_hash_flags | |
4939 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) | |
4940 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); | |
b34976b6 | 4941 | return TRUE; |
5bd4f169 AM |
4942 | } |
4943 | ||
5bd4f169 AM |
4944 | /* If we are creating a shared library, we must presume that the |
4945 | only references to the symbol are via the global offset table. | |
4946 | For such cases we need not do anything here; the relocations will | |
4947 | be handled correctly by relocate_section. */ | |
4948 | if (info->shared) | |
b34976b6 | 4949 | return TRUE; |
5bd4f169 | 4950 | |
65f38f15 AM |
4951 | /* If there are no references to this symbol that do not use the |
4952 | GOT, we don't need to generate a copy reloc. */ | |
4953 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 4954 | return TRUE; |
65f38f15 | 4955 | |
f4656909 | 4956 | if (ELIMINATE_COPY_RELOCS) |
65f38f15 | 4957 | { |
f4656909 AM |
4958 | struct ppc_link_hash_entry * eh; |
4959 | struct ppc_dyn_relocs *p; | |
65f38f15 | 4960 | |
f4656909 AM |
4961 | eh = (struct ppc_link_hash_entry *) h; |
4962 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4963 | { | |
4964 | s = p->sec->output_section; | |
4965 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
4966 | break; | |
4967 | } | |
4968 | ||
4969 | /* If we didn't find any dynamic relocs in read-only sections, then | |
4970 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
4971 | if (p == NULL) | |
4972 | { | |
4973 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
4974 | return TRUE; | |
4975 | } | |
65f38f15 AM |
4976 | } |
4977 | ||
5d35169e | 4978 | if (h->plt.plist != NULL) |
97b639ba AM |
4979 | { |
4980 | /* We should never get here, but unfortunately there are versions | |
4981 | of gcc out there that improperly (for this ABI) put initialized | |
4982 | function pointers, vtable refs and suchlike in read-only | |
4983 | sections. Allow them to proceed, but warn that this might | |
4984 | break at runtime. */ | |
4985 | (*_bfd_error_handler) | |
4986 | (_("copy reloc against `%s' requires lazy plt linking; " | |
4987 | "avoid setting LD_BIND_NOW=1 or upgrade gcc"), | |
4988 | h->root.root.string); | |
4989 | } | |
5d35169e AM |
4990 | |
4991 | /* This is a reference to a symbol defined by a dynamic object which | |
4992 | is not a function. */ | |
4993 | ||
5bd4f169 AM |
4994 | /* We must allocate the symbol in our .dynbss section, which will |
4995 | become part of the .bss section of the executable. There will be | |
4996 | an entry for this symbol in the .dynsym section. The dynamic | |
4997 | object will contain position independent code, so all references | |
4998 | from the dynamic object to this symbol will go through the global | |
4999 | offset table. The dynamic linker will use the .dynsym entry to | |
5000 | determine the address it must put in the global offset table, so | |
5001 | both the dynamic object and the regular object will refer to the | |
5002 | same memory location for the variable. */ | |
5bd4f169 | 5003 | |
04c9666a AM |
5004 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
5005 | to copy the initial value out of the dynamic object and into the | |
5bd4f169 AM |
5006 | runtime process image. We need to remember the offset into the |
5007 | .rela.bss section we are going to use. */ | |
5008 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
5009 | { | |
eea6121a | 5010 | htab->relbss->size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
5011 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
5012 | } | |
5013 | ||
5014 | /* We need to figure out the alignment required for this symbol. I | |
5015 | have no idea how ELF linkers handle this. */ | |
5016 | power_of_two = bfd_log2 (h->size); | |
5017 | if (power_of_two > 4) | |
5018 | power_of_two = 4; | |
5019 | ||
5020 | /* Apply the required alignment. */ | |
4ce794b7 | 5021 | s = htab->dynbss; |
eea6121a | 5022 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
65f38f15 | 5023 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) |
5bd4f169 | 5024 | { |
65f38f15 | 5025 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 5026 | return FALSE; |
5bd4f169 AM |
5027 | } |
5028 | ||
5029 | /* Define the symbol as being at this point in the section. */ | |
5030 | h->root.u.def.section = s; | |
eea6121a | 5031 | h->root.u.def.value = s->size; |
5bd4f169 AM |
5032 | |
5033 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 5034 | s->size += h->size; |
5bd4f169 | 5035 | |
b34976b6 | 5036 | return TRUE; |
5bd4f169 AM |
5037 | } |
5038 | ||
e86ce104 AM |
5039 | /* If given a function descriptor symbol, hide both the function code |
5040 | sym and the descriptor. */ | |
5041 | static void | |
4ce794b7 AM |
5042 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
5043 | struct elf_link_hash_entry *h, | |
5044 | bfd_boolean force_local) | |
e86ce104 | 5045 | { |
34814b9f | 5046 | struct ppc_link_hash_entry *eh; |
e86ce104 AM |
5047 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
5048 | ||
34814b9f AM |
5049 | eh = (struct ppc_link_hash_entry *) h; |
5050 | if (eh->is_func_descriptor) | |
e86ce104 | 5051 | { |
34814b9f | 5052 | struct ppc_link_hash_entry *fh = eh->oh; |
e86ce104 | 5053 | |
721956f4 | 5054 | if (fh == NULL) |
d1329ca3 AM |
5055 | { |
5056 | const char *p, *q; | |
5057 | struct ppc_link_hash_table *htab; | |
5058 | char save; | |
5059 | ||
5060 | /* We aren't supposed to use alloca in BFD because on | |
5061 | systems which do not have alloca the version in libiberty | |
5062 | calls xmalloc, which might cause the program to crash | |
5063 | when it runs out of memory. This function doesn't have a | |
5064 | return status, so there's no way to gracefully return an | |
5065 | error. So cheat. We know that string[-1] can be safely | |
34814b9f AM |
5066 | accessed; It's either a string in an ELF string table, |
5067 | or allocated in an objalloc structure. */ | |
d1329ca3 | 5068 | |
34814b9f | 5069 | p = eh->elf.root.root.string - 1; |
d1329ca3 AM |
5070 | save = *p; |
5071 | *(char *) p = '.'; | |
5072 | htab = ppc_hash_table (info); | |
34814b9f AM |
5073 | fh = (struct ppc_link_hash_entry *) |
5074 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
5075 | *(char *) p = save; |
5076 | ||
5077 | /* Unfortunately, if it so happens that the string we were | |
5078 | looking for was allocated immediately before this string, | |
5079 | then we overwrote the string terminator. That's the only | |
5080 | reason the lookup should fail. */ | |
5081 | if (fh == NULL) | |
5082 | { | |
34814b9f AM |
5083 | q = eh->elf.root.root.string + strlen (eh->elf.root.root.string); |
5084 | while (q >= eh->elf.root.root.string && *q == *p) | |
d1329ca3 | 5085 | --q, --p; |
34814b9f AM |
5086 | if (q < eh->elf.root.root.string && *p == '.') |
5087 | fh = (struct ppc_link_hash_entry *) | |
5088 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
5089 | } |
5090 | if (fh != NULL) | |
5091 | { | |
34814b9f AM |
5092 | eh->oh = fh; |
5093 | fh->oh = eh; | |
d1329ca3 AM |
5094 | } |
5095 | } | |
e86ce104 | 5096 | if (fh != NULL) |
34814b9f | 5097 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); |
e86ce104 AM |
5098 | } |
5099 | } | |
5100 | ||
411e1bfb | 5101 | static bfd_boolean |
8843416a AM |
5102 | get_sym_h (struct elf_link_hash_entry **hp, |
5103 | Elf_Internal_Sym **symp, | |
5104 | asection **symsecp, | |
5105 | char **tls_maskp, | |
5106 | Elf_Internal_Sym **locsymsp, | |
5107 | unsigned long r_symndx, | |
5108 | bfd *ibfd) | |
411e1bfb AM |
5109 | { |
5110 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5111 | ||
5112 | if (r_symndx >= symtab_hdr->sh_info) | |
5113 | { | |
5114 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
5115 | struct elf_link_hash_entry *h; | |
5116 | ||
5117 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
5118 | while (h->root.type == bfd_link_hash_indirect | |
5119 | || h->root.type == bfd_link_hash_warning) | |
5120 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5121 | ||
5122 | if (hp != NULL) | |
5123 | *hp = h; | |
5124 | ||
5125 | if (symp != NULL) | |
5126 | *symp = NULL; | |
5127 | ||
5128 | if (symsecp != NULL) | |
5129 | { | |
5130 | asection *symsec = NULL; | |
5131 | if (h->root.type == bfd_link_hash_defined | |
5132 | || h->root.type == bfd_link_hash_defweak) | |
5133 | symsec = h->root.u.def.section; | |
5134 | *symsecp = symsec; | |
5135 | } | |
5136 | ||
e7b938ca | 5137 | if (tls_maskp != NULL) |
411e1bfb AM |
5138 | { |
5139 | struct ppc_link_hash_entry *eh; | |
5140 | ||
5141 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 5142 | *tls_maskp = &eh->tls_mask; |
411e1bfb AM |
5143 | } |
5144 | } | |
5145 | else | |
5146 | { | |
5147 | Elf_Internal_Sym *sym; | |
5148 | Elf_Internal_Sym *locsyms = *locsymsp; | |
5149 | ||
5150 | if (locsyms == NULL) | |
5151 | { | |
5152 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
5153 | if (locsyms == NULL) | |
5154 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
5155 | symtab_hdr->sh_info, | |
5156 | 0, NULL, NULL, NULL); | |
5157 | if (locsyms == NULL) | |
5158 | return FALSE; | |
5159 | *locsymsp = locsyms; | |
5160 | } | |
5161 | sym = locsyms + r_symndx; | |
5162 | ||
5163 | if (hp != NULL) | |
5164 | *hp = NULL; | |
5165 | ||
5166 | if (symp != NULL) | |
5167 | *symp = sym; | |
5168 | ||
5169 | if (symsecp != NULL) | |
5170 | { | |
5171 | asection *symsec = NULL; | |
5172 | if ((sym->st_shndx != SHN_UNDEF | |
5173 | && sym->st_shndx < SHN_LORESERVE) | |
5174 | || sym->st_shndx > SHN_HIRESERVE) | |
5175 | symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); | |
5176 | *symsecp = symsec; | |
5177 | } | |
5178 | ||
e7b938ca | 5179 | if (tls_maskp != NULL) |
411e1bfb AM |
5180 | { |
5181 | struct got_entry **lgot_ents; | |
e7b938ca | 5182 | char *tls_mask; |
411e1bfb | 5183 | |
e7b938ca | 5184 | tls_mask = NULL; |
411e1bfb AM |
5185 | lgot_ents = elf_local_got_ents (ibfd); |
5186 | if (lgot_ents != NULL) | |
5187 | { | |
e7b938ca AM |
5188 | char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info); |
5189 | tls_mask = &lgot_masks[r_symndx]; | |
411e1bfb | 5190 | } |
e7b938ca | 5191 | *tls_maskp = tls_mask; |
411e1bfb AM |
5192 | } |
5193 | } | |
5194 | return TRUE; | |
5195 | } | |
5196 | ||
e7b938ca | 5197 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
951fd09b | 5198 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
ad8e1ba5 | 5199 | type suitable for optimization, and 1 otherwise. */ |
951fd09b AM |
5200 | |
5201 | static int | |
0d4792f7 AM |
5202 | get_tls_mask (char **tls_maskp, unsigned long *toc_symndx, |
5203 | Elf_Internal_Sym **locsymsp, | |
4ce794b7 | 5204 | const Elf_Internal_Rela *rel, bfd *ibfd) |
411e1bfb AM |
5205 | { |
5206 | unsigned long r_symndx; | |
0d4792f7 | 5207 | int next_r; |
411e1bfb AM |
5208 | struct elf_link_hash_entry *h; |
5209 | Elf_Internal_Sym *sym; | |
5210 | asection *sec; | |
5211 | bfd_vma off; | |
5212 | ||
5213 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5214 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 5215 | return 0; |
411e1bfb | 5216 | |
e7b938ca | 5217 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
411e1bfb AM |
5218 | || sec == NULL |
5219 | || ppc64_elf_section_data (sec)->t_symndx == NULL) | |
951fd09b | 5220 | return 1; |
411e1bfb AM |
5221 | |
5222 | /* Look inside a TOC section too. */ | |
5223 | if (h != NULL) | |
5224 | { | |
5225 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
5226 | off = h->root.u.def.value; | |
5227 | } | |
5228 | else | |
5229 | off = sym->st_value; | |
5230 | off += rel->r_addend; | |
5231 | BFD_ASSERT (off % 8 == 0); | |
5232 | r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8]; | |
951fd09b | 5233 | next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1]; |
e7b938ca | 5234 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 5235 | return 0; |
0d4792f7 AM |
5236 | if (toc_symndx != NULL) |
5237 | *toc_symndx = r_symndx; | |
5238 | if ((h == NULL | |
5239 | || ((h->root.type == bfd_link_hash_defined | |
5240 | || h->root.type == bfd_link_hash_defweak) | |
5241 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
5242 | && (next_r == -1 || next_r == -2)) | |
5243 | return 1 - next_r; | |
951fd09b | 5244 | return 1; |
411e1bfb AM |
5245 | } |
5246 | ||
754021d0 | 5247 | /* Adjust all global syms defined in opd sections. In gcc generated |
8387904d | 5248 | code for the old ABI, these will already have been done. */ |
754021d0 AM |
5249 | |
5250 | static bfd_boolean | |
5251 | adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
5252 | { | |
5253 | struct ppc_link_hash_entry *eh; | |
5254 | asection *sym_sec; | |
5255 | long *opd_adjust; | |
5256 | ||
5257 | if (h->root.type == bfd_link_hash_indirect) | |
5258 | return TRUE; | |
5259 | ||
5260 | if (h->root.type == bfd_link_hash_warning) | |
5261 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5262 | ||
5263 | if (h->root.type != bfd_link_hash_defined | |
5264 | && h->root.type != bfd_link_hash_defweak) | |
5265 | return TRUE; | |
5266 | ||
5267 | eh = (struct ppc_link_hash_entry *) h; | |
5268 | if (eh->adjust_done) | |
5269 | return TRUE; | |
5270 | ||
5271 | sym_sec = eh->elf.root.u.def.section; | |
4025353c AM |
5272 | opd_adjust = get_opd_info (sym_sec); |
5273 | if (opd_adjust != NULL) | |
754021d0 | 5274 | { |
4025353c AM |
5275 | long adjust = opd_adjust[eh->elf.root.u.def.value / 24]; |
5276 | if (adjust == -1) | |
5277 | { | |
5278 | /* This entry has been deleted. */ | |
81688140 AM |
5279 | asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section; |
5280 | if (dsec == NULL) | |
5281 | { | |
5282 | for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next) | |
5283 | if (elf_discarded_section (dsec)) | |
5284 | { | |
5285 | ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec; | |
5286 | break; | |
5287 | } | |
5288 | } | |
4025353c | 5289 | eh->elf.root.u.def.value = 0; |
81688140 | 5290 | eh->elf.root.u.def.section = dsec; |
4025353c AM |
5291 | } |
5292 | else | |
5293 | eh->elf.root.u.def.value += adjust; | |
754021d0 AM |
5294 | eh->adjust_done = 1; |
5295 | } | |
5296 | return TRUE; | |
5297 | } | |
5298 | ||
5299 | /* Remove unused Official Procedure Descriptor entries. Currently we | |
5300 | only remove those associated with functions in discarded link-once | |
5301 | sections, or weakly defined functions that have been overridden. It | |
5302 | would be possible to remove many more entries for statically linked | |
5303 | applications. */ | |
5304 | ||
b34976b6 | 5305 | bfd_boolean |
4ce794b7 | 5306 | ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info) |
1e2f5b6e AM |
5307 | { |
5308 | bfd *ibfd; | |
754021d0 | 5309 | bfd_boolean some_edited = FALSE; |
1e2f5b6e | 5310 | |
411e1bfb | 5311 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1e2f5b6e AM |
5312 | { |
5313 | asection *sec; | |
5314 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5315 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 5316 | Elf_Internal_Sym *local_syms; |
1e2f5b6e AM |
5317 | struct elf_link_hash_entry **sym_hashes; |
5318 | bfd_vma offset; | |
d6fe2dc1 | 5319 | bfd_size_type amt; |
4025353c | 5320 | long *opd_adjust; |
b34976b6 | 5321 | bfd_boolean need_edit; |
1e2f5b6e AM |
5322 | |
5323 | sec = bfd_get_section_by_name (ibfd, ".opd"); | |
5324 | if (sec == NULL) | |
5325 | continue; | |
5326 | ||
eea6121a | 5327 | amt = sec->size * sizeof (long) / 24; |
4025353c AM |
5328 | opd_adjust = get_opd_info (sec); |
5329 | if (opd_adjust == NULL) | |
d6fe2dc1 AM |
5330 | { |
5331 | /* Must be a ld -r link. ie. check_relocs hasn't been | |
5332 | called. */ | |
4025353c AM |
5333 | opd_adjust = bfd_zalloc (obfd, amt); |
5334 | ppc64_elf_section_data (sec)->opd.adjust = opd_adjust; | |
d6fe2dc1 | 5335 | } |
4025353c | 5336 | memset (opd_adjust, 0, amt); |
1e2f5b6e AM |
5337 | |
5338 | if (sec->output_section == bfd_abs_section_ptr) | |
5339 | continue; | |
5340 | ||
5341 | /* Look through the section relocs. */ | |
5342 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
5343 | continue; | |
5344 | ||
6cdc0ccc | 5345 | local_syms = NULL; |
1e2f5b6e AM |
5346 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
5347 | sym_hashes = elf_sym_hashes (ibfd); | |
5348 | ||
5349 | /* Read the relocations. */ | |
4ce794b7 | 5350 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5351 | info->keep_memory); |
1e2f5b6e | 5352 | if (relstart == NULL) |
b34976b6 | 5353 | return FALSE; |
1e2f5b6e AM |
5354 | |
5355 | /* First run through the relocs to check they are sane, and to | |
5356 | determine whether we need to edit this opd section. */ | |
b34976b6 | 5357 | need_edit = FALSE; |
1e2f5b6e AM |
5358 | offset = 0; |
5359 | relend = relstart + sec->reloc_count; | |
50bc7936 | 5360 | for (rel = relstart; rel < relend; ) |
1e2f5b6e | 5361 | { |
04c9666a | 5362 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e AM |
5363 | unsigned long r_symndx; |
5364 | asection *sym_sec; | |
5365 | struct elf_link_hash_entry *h; | |
5366 | Elf_Internal_Sym *sym; | |
5367 | ||
5368 | /* .opd contains a regular array of 24 byte entries. We're | |
5369 | only interested in the reloc pointing to a function entry | |
5370 | point. */ | |
50bc7936 AM |
5371 | if (rel->r_offset != offset |
5372 | || rel + 1 >= relend | |
5373 | || (rel + 1)->r_offset != offset + 8) | |
1e2f5b6e AM |
5374 | { |
5375 | /* If someone messes with .opd alignment then after a | |
5376 | "ld -r" we might have padding in the middle of .opd. | |
5377 | Also, there's nothing to prevent someone putting | |
5378 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 5379 | optimization for them! */ |
1e2f5b6e | 5380 | (*_bfd_error_handler) |
d003868e | 5381 | (_("%B: .opd is not a regular array of opd entries"), ibfd); |
b34976b6 | 5382 | need_edit = FALSE; |
1e2f5b6e AM |
5383 | break; |
5384 | } | |
5385 | ||
50bc7936 AM |
5386 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
5387 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) | |
5388 | { | |
5389 | (*_bfd_error_handler) | |
d003868e AM |
5390 | (_("%B: unexpected reloc type %u in .opd section"), |
5391 | ibfd, r_type); | |
50bc7936 AM |
5392 | need_edit = FALSE; |
5393 | break; | |
5394 | } | |
5395 | ||
1e2f5b6e | 5396 | r_symndx = ELF64_R_SYM (rel->r_info); |
411e1bfb AM |
5397 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
5398 | r_symndx, ibfd)) | |
50bc7936 | 5399 | goto error_ret; |
1e2f5b6e AM |
5400 | |
5401 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
5402 | { | |
411e1bfb AM |
5403 | const char *sym_name; |
5404 | if (h != NULL) | |
5405 | sym_name = h->root.root.string; | |
5406 | else | |
5407 | sym_name = bfd_elf_local_sym_name (ibfd, sym); | |
5408 | ||
1e2f5b6e | 5409 | (*_bfd_error_handler) |
d003868e AM |
5410 | (_("%B: undefined sym `%s' in .opd section"), |
5411 | ibfd, sym_name); | |
b34976b6 | 5412 | need_edit = FALSE; |
1e2f5b6e AM |
5413 | break; |
5414 | } | |
5415 | ||
51020317 AM |
5416 | /* opd entries are always for functions defined in the |
5417 | current input bfd. If the symbol isn't defined in the | |
5418 | input bfd, then we won't be using the function in this | |
5419 | bfd; It must be defined in a linkonce section in another | |
5420 | bfd, or is weak. It's also possible that we are | |
5421 | discarding the function due to a linker script /DISCARD/, | |
5422 | which we test for via the output_section. */ | |
5423 | if (sym_sec->owner != ibfd | |
5424 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 5425 | need_edit = TRUE; |
1e2f5b6e AM |
5426 | |
5427 | offset += 24; | |
50bc7936 AM |
5428 | rel += 2; |
5429 | /* Allow for the possibility of a reloc on the third word. */ | |
5430 | if (rel < relend | |
5431 | && rel->r_offset == offset - 8) | |
5432 | rel += 1; | |
1e2f5b6e AM |
5433 | } |
5434 | ||
5435 | if (need_edit) | |
5436 | { | |
5437 | Elf_Internal_Rela *write_rel; | |
5438 | bfd_byte *rptr, *wptr; | |
b34976b6 | 5439 | bfd_boolean skip; |
1e2f5b6e AM |
5440 | |
5441 | /* This seems a waste of time as input .opd sections are all | |
5442 | zeros as generated by gcc, but I suppose there's no reason | |
5443 | this will always be so. We might start putting something in | |
5444 | the third word of .opd entries. */ | |
5445 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
5446 | { | |
eea6121a AM |
5447 | bfd_byte *loc; |
5448 | if (!bfd_malloc_and_get_section (ibfd, sec, &loc)) | |
6cdc0ccc | 5449 | { |
eea6121a AM |
5450 | if (loc != NULL) |
5451 | free (loc); | |
50bc7936 | 5452 | error_ret: |
6cdc0ccc AM |
5453 | if (local_syms != NULL |
5454 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5455 | free (local_syms); | |
6cdc0ccc AM |
5456 | if (elf_section_data (sec)->relocs != relstart) |
5457 | free (relstart); | |
b34976b6 | 5458 | return FALSE; |
6cdc0ccc | 5459 | } |
1e2f5b6e AM |
5460 | sec->contents = loc; |
5461 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
5462 | } | |
5463 | ||
5464 | elf_section_data (sec)->relocs = relstart; | |
5465 | ||
5466 | wptr = sec->contents; | |
5467 | rptr = sec->contents; | |
5468 | write_rel = relstart; | |
b34976b6 | 5469 | skip = FALSE; |
1e2f5b6e AM |
5470 | offset = 0; |
5471 | for (rel = relstart; rel < relend; rel++) | |
5472 | { | |
50bc7936 AM |
5473 | unsigned long r_symndx; |
5474 | asection *sym_sec; | |
5475 | struct elf_link_hash_entry *h; | |
5476 | Elf_Internal_Sym *sym; | |
5477 | ||
5478 | r_symndx = ELF64_R_SYM (rel->r_info); | |
5479 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
d37c89e5 | 5480 | r_symndx, ibfd)) |
50bc7936 AM |
5481 | goto error_ret; |
5482 | ||
1e2f5b6e AM |
5483 | if (rel->r_offset == offset) |
5484 | { | |
50bc7936 | 5485 | struct ppc_link_hash_entry *fdh = NULL; |
4025353c AM |
5486 | if (h != NULL |
5487 | && h->root.root.string[0] == '.') | |
50bc7936 AM |
5488 | fdh = get_fdh ((struct ppc_link_hash_entry *) h, |
5489 | ppc_hash_table (info)); | |
1e2f5b6e | 5490 | |
51020317 AM |
5491 | skip = (sym_sec->owner != ibfd |
5492 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
5493 | if (skip) |
5494 | { | |
4025353c | 5495 | if (fdh != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
5496 | { |
5497 | /* Arrange for the function descriptor sym | |
5498 | to be dropped. */ | |
d6fe2dc1 AM |
5499 | fdh->elf.root.u.def.value = 0; |
5500 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 | 5501 | } |
4025353c | 5502 | opd_adjust[rel->r_offset / 24] = -1; |
a4aa0fb7 AM |
5503 | } |
5504 | else | |
1e2f5b6e AM |
5505 | { |
5506 | /* We'll be keeping this opd entry. */ | |
5507 | ||
4025353c | 5508 | if (fdh != NULL) |
1e2f5b6e | 5509 | { |
754021d0 AM |
5510 | /* Redefine the function descriptor symbol to |
5511 | this location in the opd section. It is | |
5512 | necessary to update the value here rather | |
5513 | than using an array of adjustments as we do | |
5514 | for local symbols, because various places | |
5515 | in the generic ELF code use the value | |
5516 | stored in u.def.value. */ | |
d6fe2dc1 | 5517 | fdh->elf.root.u.def.value = wptr - sec->contents; |
754021d0 | 5518 | fdh->adjust_done = 1; |
1e2f5b6e | 5519 | } |
754021d0 AM |
5520 | |
5521 | /* Local syms are a bit tricky. We could | |
5522 | tweak them as they can be cached, but | |
5523 | we'd need to look through the local syms | |
5524 | for the function descriptor sym which we | |
5525 | don't have at the moment. So keep an | |
5526 | array of adjustments. */ | |
4025353c | 5527 | opd_adjust[rel->r_offset / 24] = wptr - rptr; |
1e2f5b6e AM |
5528 | |
5529 | if (wptr != rptr) | |
5530 | memcpy (wptr, rptr, 24); | |
5531 | wptr += 24; | |
5532 | } | |
5533 | rptr += 24; | |
5534 | offset += 24; | |
5535 | } | |
5536 | ||
50bc7936 AM |
5537 | if (skip) |
5538 | { | |
5539 | BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info))); | |
5540 | if (info->shared) | |
5541 | { | |
5542 | /* We won't be needing dynamic relocs here. */ | |
5543 | struct ppc_dyn_relocs **pp; | |
5544 | struct ppc_dyn_relocs *p; | |
5545 | ||
5546 | if (h != NULL) | |
5547 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; | |
5548 | else if (sym_sec != NULL) | |
5549 | pp = ((struct ppc_dyn_relocs **) | |
5550 | &elf_section_data (sym_sec)->local_dynrel); | |
5551 | else | |
5552 | pp = ((struct ppc_dyn_relocs **) | |
5553 | &elf_section_data (sec)->local_dynrel); | |
5554 | while ((p = *pp) != NULL) | |
5555 | { | |
5556 | if (p->sec == sec) | |
5557 | { | |
5558 | p->count -= 1; | |
5559 | if (p->count == 0) | |
d37c89e5 | 5560 | *pp = p->next; |
50bc7936 AM |
5561 | break; |
5562 | } | |
5563 | pp = &p->next; | |
5564 | } | |
5565 | } | |
5566 | } | |
5567 | else | |
1e2f5b6e | 5568 | { |
50bc7936 AM |
5569 | /* We need to adjust any reloc offsets to point to the |
5570 | new opd entries. While we're at it, we may as well | |
5571 | remove redundant relocs. */ | |
1e2f5b6e AM |
5572 | rel->r_offset += wptr - rptr; |
5573 | if (write_rel != rel) | |
5574 | memcpy (write_rel, rel, sizeof (*rel)); | |
5575 | ++write_rel; | |
5576 | } | |
5577 | } | |
5578 | ||
eea6121a | 5579 | sec->size = wptr - sec->contents; |
1e2f5b6e | 5580 | sec->reloc_count = write_rel - relstart; |
cdcf6e38 AM |
5581 | /* Fudge the size too, as this is used later in |
5582 | elf_bfd_final_link if we are emitting relocs. */ | |
5583 | elf_section_data (sec)->rel_hdr.sh_size | |
5584 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; | |
5585 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); | |
754021d0 | 5586 | some_edited = TRUE; |
1e2f5b6e | 5587 | } |
6cdc0ccc | 5588 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 5589 | free (relstart); |
6cdc0ccc | 5590 | |
411e1bfb AM |
5591 | if (local_syms != NULL |
5592 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5593 | { | |
5594 | if (!info->keep_memory) | |
5595 | free (local_syms); | |
5596 | else | |
5597 | symtab_hdr->contents = (unsigned char *) local_syms; | |
5598 | } | |
5599 | } | |
5600 | ||
754021d0 AM |
5601 | if (some_edited) |
5602 | elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL); | |
5603 | ||
411e1bfb AM |
5604 | return TRUE; |
5605 | } | |
5606 | ||
e1918d23 | 5607 | /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ |
411e1bfb | 5608 | |
e1918d23 | 5609 | asection * |
4ce794b7 | 5610 | ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
411e1bfb | 5611 | { |
411e1bfb AM |
5612 | struct ppc_link_hash_table *htab; |
5613 | ||
411e1bfb | 5614 | htab = ppc_hash_table (info); |
a48ebf4d AM |
5615 | if (htab->tls_get_addr != NULL) |
5616 | { | |
8387904d | 5617 | struct ppc_link_hash_entry *h = htab->tls_get_addr; |
a48ebf4d | 5618 | |
8387904d AM |
5619 | while (h->elf.root.type == bfd_link_hash_indirect |
5620 | || h->elf.root.type == bfd_link_hash_warning) | |
5621 | h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link; | |
a48ebf4d AM |
5622 | |
5623 | htab->tls_get_addr = h; | |
8387904d AM |
5624 | |
5625 | if (htab->tls_get_addr_fd == NULL | |
5626 | && h->oh != NULL | |
5627 | && h->oh->is_func_descriptor) | |
5628 | htab->tls_get_addr_fd = h->oh; | |
5629 | } | |
5630 | ||
5631 | if (htab->tls_get_addr_fd != NULL) | |
5632 | { | |
5633 | struct ppc_link_hash_entry *h = htab->tls_get_addr_fd; | |
5634 | ||
5635 | while (h->elf.root.type == bfd_link_hash_indirect | |
5636 | || h->elf.root.type == bfd_link_hash_warning) | |
5637 | h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link; | |
5638 | ||
5639 | htab->tls_get_addr_fd = h; | |
a48ebf4d AM |
5640 | } |
5641 | ||
e1918d23 | 5642 | return _bfd_elf_tls_setup (obfd, info); |
951fd09b | 5643 | } |
411e1bfb | 5644 | |
951fd09b AM |
5645 | /* Run through all the TLS relocs looking for optimization |
5646 | opportunities. The linker has been hacked (see ppc64elf.em) to do | |
5647 | a preliminary section layout so that we know the TLS segment | |
5648 | offsets. We can't optimize earlier because some optimizations need | |
5649 | to know the tp offset, and we need to optimize before allocating | |
5650 | dynamic relocations. */ | |
5651 | ||
5652 | bfd_boolean | |
4ce794b7 | 5653 | ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) |
951fd09b AM |
5654 | { |
5655 | bfd *ibfd; | |
5656 | asection *sec; | |
5657 | struct ppc_link_hash_table *htab; | |
5658 | ||
1049f94e | 5659 | if (info->relocatable || info->shared) |
411e1bfb AM |
5660 | return TRUE; |
5661 | ||
951fd09b | 5662 | htab = ppc_hash_table (info); |
411e1bfb AM |
5663 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5664 | { | |
5665 | Elf_Internal_Sym *locsyms = NULL; | |
5666 | ||
5667 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
5668 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
5669 | { | |
5670 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5671 | int expecting_tls_get_addr; | |
5672 | ||
5673 | /* Read the relocations. */ | |
4ce794b7 | 5674 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5675 | info->keep_memory); |
411e1bfb AM |
5676 | if (relstart == NULL) |
5677 | return FALSE; | |
5678 | ||
5679 | expecting_tls_get_addr = 0; | |
5680 | relend = relstart + sec->reloc_count; | |
5681 | for (rel = relstart; rel < relend; rel++) | |
5682 | { | |
5683 | enum elf_ppc64_reloc_type r_type; | |
5684 | unsigned long r_symndx; | |
5685 | struct elf_link_hash_entry *h; | |
5686 | Elf_Internal_Sym *sym; | |
5687 | asection *sym_sec; | |
e7b938ca AM |
5688 | char *tls_mask; |
5689 | char tls_set, tls_clear, tls_type = 0; | |
411e1bfb | 5690 | bfd_vma value; |
951fd09b | 5691 | bfd_boolean ok_tprel, is_local; |
411e1bfb AM |
5692 | |
5693 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5694 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, |
411e1bfb AM |
5695 | r_symndx, ibfd)) |
5696 | { | |
5697 | err_free_rel: | |
5698 | if (elf_section_data (sec)->relocs != relstart) | |
5699 | free (relstart); | |
5700 | if (locsyms != NULL | |
5701 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5702 | != (unsigned char *) locsyms)) | |
5703 | free (locsyms); | |
5704 | return FALSE; | |
5705 | } | |
5706 | ||
5707 | if (h != NULL) | |
5708 | { | |
5709 | if (h->root.type != bfd_link_hash_defined | |
5710 | && h->root.type != bfd_link_hash_defweak) | |
5711 | continue; | |
5712 | value = h->root.u.def.value; | |
5713 | } | |
5714 | else | |
4025353c AM |
5715 | /* Symbols referenced by TLS relocs must be of type |
5716 | STT_TLS. So no need for .opd local sym adjust. */ | |
5717 | value = sym->st_value; | |
951fd09b | 5718 | |
411e1bfb | 5719 | ok_tprel = FALSE; |
951fd09b AM |
5720 | is_local = FALSE; |
5721 | if (h == NULL | |
5722 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5723 | { |
951fd09b | 5724 | is_local = TRUE; |
411e1bfb AM |
5725 | value += sym_sec->output_offset; |
5726 | value += sym_sec->output_section->vma; | |
e1918d23 | 5727 | value -= htab->elf.tls_sec->vma; |
411e1bfb AM |
5728 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) |
5729 | < (bfd_vma) 1 << 32); | |
5730 | } | |
5731 | ||
4ce794b7 | 5732 | r_type = ELF64_R_TYPE (rel->r_info); |
411e1bfb AM |
5733 | switch (r_type) |
5734 | { | |
5735 | case R_PPC64_GOT_TLSLD16: | |
5736 | case R_PPC64_GOT_TLSLD16_LO: | |
5737 | case R_PPC64_GOT_TLSLD16_HI: | |
5738 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b AM |
5739 | /* These relocs should never be against a symbol |
5740 | defined in a shared lib. Leave them alone if | |
5741 | that turns out to be the case. */ | |
e717da7e | 5742 | ppc64_tlsld_got (ibfd)->refcount -= 1; |
951fd09b AM |
5743 | if (!is_local) |
5744 | continue; | |
5745 | ||
951fd09b AM |
5746 | /* LD -> LE */ |
5747 | tls_set = 0; | |
5748 | tls_clear = TLS_LD; | |
e7b938ca | 5749 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
5750 | expecting_tls_get_addr = 1; |
5751 | break; | |
5752 | ||
5753 | case R_PPC64_GOT_TLSGD16: | |
5754 | case R_PPC64_GOT_TLSGD16_LO: | |
5755 | case R_PPC64_GOT_TLSGD16_HI: | |
5756 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 5757 | if (ok_tprel) |
411e1bfb AM |
5758 | /* GD -> LE */ |
5759 | tls_set = 0; | |
5760 | else | |
5761 | /* GD -> IE */ | |
951fd09b AM |
5762 | tls_set = TLS_TLS | TLS_TPRELGD; |
5763 | tls_clear = TLS_GD; | |
e7b938ca | 5764 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
5765 | expecting_tls_get_addr = 1; |
5766 | break; | |
5767 | ||
5768 | case R_PPC64_GOT_TPREL16_DS: | |
5769 | case R_PPC64_GOT_TPREL16_LO_DS: | |
5770 | case R_PPC64_GOT_TPREL16_HI: | |
5771 | case R_PPC64_GOT_TPREL16_HA: | |
5772 | expecting_tls_get_addr = 0; | |
5773 | if (ok_tprel) | |
5774 | { | |
5775 | /* IE -> LE */ | |
5776 | tls_set = 0; | |
5777 | tls_clear = TLS_TPREL; | |
e7b938ca | 5778 | tls_type = TLS_TLS | TLS_TPREL; |
411e1bfb AM |
5779 | break; |
5780 | } | |
5781 | else | |
5782 | continue; | |
5783 | ||
5784 | case R_PPC64_REL14: | |
5785 | case R_PPC64_REL14_BRTAKEN: | |
5786 | case R_PPC64_REL14_BRNTAKEN: | |
5787 | case R_PPC64_REL24: | |
5788 | if (h != NULL | |
8387904d AM |
5789 | && (h == &htab->tls_get_addr->elf |
5790 | || h == &htab->tls_get_addr_fd->elf)) | |
411e1bfb AM |
5791 | { |
5792 | if (!expecting_tls_get_addr | |
5793 | && rel != relstart | |
5794 | && ((ELF64_R_TYPE (rel[-1].r_info) | |
5795 | == R_PPC64_TOC16) | |
5796 | || (ELF64_R_TYPE (rel[-1].r_info) | |
5797 | == R_PPC64_TOC16_LO))) | |
5798 | { | |
5799 | /* Check for toc tls entries. */ | |
5800 | char *toc_tls; | |
951fd09b | 5801 | int retval; |
411e1bfb | 5802 | |
0d4792f7 | 5803 | retval = get_tls_mask (&toc_tls, NULL, &locsyms, |
951fd09b AM |
5804 | rel - 1, ibfd); |
5805 | if (retval == 0) | |
411e1bfb AM |
5806 | goto err_free_rel; |
5807 | if (toc_tls != NULL) | |
951fd09b | 5808 | expecting_tls_get_addr = retval > 1; |
411e1bfb AM |
5809 | } |
5810 | ||
5811 | if (expecting_tls_get_addr) | |
5812 | { | |
5813 | struct plt_entry *ent; | |
5814 | for (ent = h->plt.plist; ent; ent = ent->next) | |
5815 | if (ent->addend == 0) | |
5816 | { | |
5817 | if (ent->plt.refcount > 0) | |
5818 | ent->plt.refcount -= 1; | |
5819 | break; | |
5820 | } | |
5821 | } | |
5822 | } | |
5823 | expecting_tls_get_addr = 0; | |
5824 | continue; | |
5825 | ||
5826 | case R_PPC64_TPREL64: | |
5827 | expecting_tls_get_addr = 0; | |
5828 | if (ok_tprel) | |
5829 | { | |
5830 | /* IE -> LE */ | |
5831 | tls_set = TLS_EXPLICIT; | |
5832 | tls_clear = TLS_TPREL; | |
5833 | break; | |
5834 | } | |
5835 | else | |
5836 | continue; | |
5837 | ||
5838 | case R_PPC64_DTPMOD64: | |
5839 | expecting_tls_get_addr = 0; | |
951fd09b AM |
5840 | if (rel + 1 < relend |
5841 | && (rel[1].r_info | |
5842 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) | |
5843 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 5844 | { |
951fd09b | 5845 | if (ok_tprel) |
411e1bfb | 5846 | /* GD -> LE */ |
951fd09b | 5847 | tls_set = TLS_EXPLICIT | TLS_GD; |
411e1bfb AM |
5848 | else |
5849 | /* GD -> IE */ | |
951fd09b AM |
5850 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; |
5851 | tls_clear = TLS_GD; | |
411e1bfb AM |
5852 | } |
5853 | else | |
5854 | { | |
951fd09b AM |
5855 | if (!is_local) |
5856 | continue; | |
5857 | ||
5858 | /* LD -> LE */ | |
5859 | tls_set = TLS_EXPLICIT; | |
5860 | tls_clear = TLS_LD; | |
411e1bfb AM |
5861 | } |
5862 | break; | |
5863 | ||
5864 | default: | |
5865 | expecting_tls_get_addr = 0; | |
5866 | continue; | |
5867 | } | |
5868 | ||
5869 | if ((tls_set & TLS_EXPLICIT) == 0) | |
5870 | { | |
5871 | struct got_entry *ent; | |
5872 | ||
5873 | /* Adjust got entry for this reloc. */ | |
5874 | if (h != NULL) | |
5875 | ent = h->got.glist; | |
5876 | else | |
5877 | ent = elf_local_got_ents (ibfd)[r_symndx]; | |
5878 | ||
5879 | for (; ent != NULL; ent = ent->next) | |
5880 | if (ent->addend == rel->r_addend | |
e717da7e | 5881 | && ent->owner == ibfd |
e7b938ca | 5882 | && ent->tls_type == tls_type) |
411e1bfb AM |
5883 | break; |
5884 | if (ent == NULL) | |
5885 | abort (); | |
5886 | ||
5887 | if (tls_set == 0) | |
5888 | { | |
5889 | /* We managed to get rid of a got entry. */ | |
5890 | if (ent->got.refcount > 0) | |
5891 | ent->got.refcount -= 1; | |
5892 | } | |
411e1bfb AM |
5893 | } |
5894 | else if (h != NULL) | |
5895 | { | |
5896 | struct ppc_link_hash_entry * eh; | |
5897 | struct ppc_dyn_relocs **pp; | |
5898 | struct ppc_dyn_relocs *p; | |
5899 | ||
5900 | /* Adjust dynamic relocs. */ | |
5901 | eh = (struct ppc_link_hash_entry *) h; | |
5902 | for (pp = &eh->dyn_relocs; | |
5903 | (p = *pp) != NULL; | |
5904 | pp = &p->next) | |
5905 | if (p->sec == sec) | |
5906 | { | |
5907 | /* If we got rid of a DTPMOD/DTPREL reloc | |
5908 | pair then we'll lose one or two dyn | |
5909 | relocs. */ | |
951fd09b | 5910 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
411e1bfb | 5911 | p->count -= 1; |
951fd09b | 5912 | p->count -= 1; |
411e1bfb AM |
5913 | if (p->count == 0) |
5914 | *pp = p->next; | |
5915 | break; | |
5916 | } | |
5917 | } | |
5918 | ||
e7b938ca AM |
5919 | *tls_mask |= tls_set; |
5920 | *tls_mask &= ~tls_clear; | |
411e1bfb AM |
5921 | } |
5922 | ||
5923 | if (elf_section_data (sec)->relocs != relstart) | |
5924 | free (relstart); | |
5925 | } | |
5926 | ||
5927 | if (locsyms != NULL | |
5928 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5929 | != (unsigned char *) locsyms)) | |
6cdc0ccc AM |
5930 | { |
5931 | if (!info->keep_memory) | |
411e1bfb | 5932 | free (locsyms); |
6cdc0ccc | 5933 | else |
411e1bfb | 5934 | elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; |
6cdc0ccc | 5935 | } |
1e2f5b6e | 5936 | } |
b34976b6 | 5937 | return TRUE; |
1e2f5b6e | 5938 | } |
b34976b6 | 5939 | |
65f38f15 AM |
5940 | /* Allocate space in .plt, .got and associated reloc sections for |
5941 | dynamic relocs. */ | |
5bd4f169 | 5942 | |
b34976b6 | 5943 | static bfd_boolean |
4ce794b7 | 5944 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 5945 | { |
65f38f15 AM |
5946 | struct bfd_link_info *info; |
5947 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 5948 | asection *s; |
65f38f15 AM |
5949 | struct ppc_link_hash_entry *eh; |
5950 | struct ppc_dyn_relocs *p; | |
411e1bfb | 5951 | struct got_entry *gent; |
5bd4f169 | 5952 | |
e92d460e | 5953 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5954 | return TRUE; |
5bd4f169 | 5955 | |
e92d460e AM |
5956 | if (h->root.type == bfd_link_hash_warning) |
5957 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5958 | ||
65f38f15 AM |
5959 | info = (struct bfd_link_info *) inf; |
5960 | htab = ppc_hash_table (info); | |
5bd4f169 | 5961 | |
65f38f15 | 5962 | if (htab->elf.dynamic_sections_created |
411e1bfb | 5963 | && h->dynindx != -1 |
9c7a29a3 | 5964 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) |
5bd4f169 | 5965 | { |
411e1bfb AM |
5966 | struct plt_entry *pent; |
5967 | bfd_boolean doneone = FALSE; | |
5968 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) | |
5969 | if (pent->plt.refcount > 0) | |
5970 | { | |
411e1bfb AM |
5971 | /* If this is the first .plt entry, make room for the special |
5972 | first entry. */ | |
4ce794b7 | 5973 | s = htab->plt; |
eea6121a AM |
5974 | if (s->size == 0) |
5975 | s->size += PLT_INITIAL_ENTRY_SIZE; | |
411e1bfb | 5976 | |
eea6121a | 5977 | pent->plt.offset = s->size; |
411e1bfb AM |
5978 | |
5979 | /* Make room for this entry. */ | |
eea6121a | 5980 | s->size += PLT_ENTRY_SIZE; |
411e1bfb AM |
5981 | |
5982 | /* Make room for the .glink code. */ | |
4ce794b7 | 5983 | s = htab->glink; |
eea6121a AM |
5984 | if (s->size == 0) |
5985 | s->size += GLINK_CALL_STUB_SIZE; | |
411e1bfb | 5986 | /* We need bigger stubs past index 32767. */ |
eea6121a AM |
5987 | if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4) |
5988 | s->size += 4; | |
5989 | s->size += 2*4; | |
411e1bfb AM |
5990 | |
5991 | /* We also need to make an entry in the .rela.plt section. */ | |
4ce794b7 | 5992 | s = htab->relplt; |
eea6121a | 5993 | s->size += sizeof (Elf64_External_Rela); |
411e1bfb AM |
5994 | doneone = TRUE; |
5995 | } | |
5996 | else | |
5997 | pent->plt.offset = (bfd_vma) -1; | |
5998 | if (!doneone) | |
65f38f15 | 5999 | { |
411e1bfb | 6000 | h->plt.plist = NULL; |
65f38f15 AM |
6001 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
6002 | } | |
6003 | } | |
6004 | else | |
6005 | { | |
411e1bfb | 6006 | h->plt.plist = NULL; |
65f38f15 AM |
6007 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
6008 | } | |
6009 | ||
951fd09b AM |
6010 | eh = (struct ppc_link_hash_entry *) h; |
6011 | /* Run through the TLS GD got entries first if we're changing them | |
6012 | to TPREL. */ | |
e7b938ca | 6013 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
951fd09b AM |
6014 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
6015 | if (gent->got.refcount > 0 | |
6016 | && (gent->tls_type & TLS_GD) != 0) | |
6017 | { | |
6018 | /* This was a GD entry that has been converted to TPREL. If | |
6019 | there happens to be a TPREL entry we can use that one. */ | |
6020 | struct got_entry *ent; | |
6021 | for (ent = h->got.glist; ent != NULL; ent = ent->next) | |
6022 | if (ent->got.refcount > 0 | |
6023 | && (ent->tls_type & TLS_TPREL) != 0 | |
e717da7e AM |
6024 | && ent->addend == gent->addend |
6025 | && ent->owner == gent->owner) | |
951fd09b AM |
6026 | { |
6027 | gent->got.refcount = 0; | |
6028 | break; | |
6029 | } | |
6030 | ||
6031 | /* If not, then we'll be using our own TPREL entry. */ | |
6032 | if (gent->got.refcount != 0) | |
6033 | gent->tls_type = TLS_TLS | TLS_TPREL; | |
6034 | } | |
6035 | ||
411e1bfb AM |
6036 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
6037 | if (gent->got.refcount > 0) | |
6038 | { | |
951fd09b AM |
6039 | bfd_boolean dyn; |
6040 | ||
411e1bfb | 6041 | /* Make sure this symbol is output as a dynamic symbol. |
951fd09b AM |
6042 | Undefined weak syms won't yet be marked as dynamic, |
6043 | nor will all TLS symbols. */ | |
411e1bfb AM |
6044 | if (h->dynindx == -1 |
6045 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
6046 | { | |
c152c796 | 6047 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
411e1bfb AM |
6048 | return FALSE; |
6049 | } | |
65f38f15 | 6050 | |
d881513a AM |
6051 | if ((gent->tls_type & TLS_LD) != 0 |
6052 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 6053 | { |
e717da7e | 6054 | gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; |
951fd09b | 6055 | continue; |
411e1bfb | 6056 | } |
951fd09b | 6057 | |
e717da7e | 6058 | s = ppc64_elf_tdata (gent->owner)->got; |
eea6121a AM |
6059 | gent->got.offset = s->size; |
6060 | s->size | |
d881513a | 6061 | += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; |
951fd09b | 6062 | dyn = htab->elf.dynamic_sections_created; |
4e795f50 AM |
6063 | if ((info->shared |
6064 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
6065 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
6066 | || h->root.type != bfd_link_hash_undefweak)) | |
eea6121a | 6067 | ppc64_elf_tdata (gent->owner)->relgot->size |
e7b938ca | 6068 | += (gent->tls_type & eh->tls_mask & TLS_GD |
951fd09b AM |
6069 | ? 2 * sizeof (Elf64_External_Rela) |
6070 | : sizeof (Elf64_External_Rela)); | |
411e1bfb AM |
6071 | } |
6072 | else | |
6073 | gent->got.offset = (bfd_vma) -1; | |
65f38f15 | 6074 | |
65f38f15 | 6075 | if (eh->dyn_relocs == NULL) |
b34976b6 | 6076 | return TRUE; |
65f38f15 AM |
6077 | |
6078 | /* In the shared -Bsymbolic case, discard space allocated for | |
6079 | dynamic pc-relative relocs against symbols which turn out to be | |
6080 | defined in regular objects. For the normal shared case, discard | |
6081 | space for relocs that have become local due to symbol visibility | |
6082 | changes. */ | |
6083 | ||
6084 | if (info->shared) | |
6085 | { | |
9c7a29a3 AM |
6086 | /* Relocs that use pc_count are those that appear on a call insn, |
6087 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | |
6088 | generated via assembly. We want calls to protected symbols to | |
6089 | resolve directly to the function rather than going via the plt. | |
6090 | If people want function pointer comparisons to work as expected | |
6091 | then they should avoid writing weird assembly. */ | |
09695f56 | 6092 | if (SYMBOL_CALLS_LOCAL (info, h)) |
65f38f15 AM |
6093 | { |
6094 | struct ppc_dyn_relocs **pp; | |
6095 | ||
6096 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 6097 | { |
65f38f15 AM |
6098 | p->count -= p->pc_count; |
6099 | p->pc_count = 0; | |
6100 | if (p->count == 0) | |
6101 | *pp = p->next; | |
6102 | else | |
6103 | pp = &p->next; | |
5bd4f169 | 6104 | } |
65f38f15 | 6105 | } |
4e795f50 AM |
6106 | |
6107 | /* Also discard relocs on undefined weak syms with non-default | |
6108 | visibility. */ | |
6109 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
6110 | && h->root.type == bfd_link_hash_undefweak) | |
6111 | eh->dyn_relocs = NULL; | |
65f38f15 | 6112 | } |
f4656909 | 6113 | else if (ELIMINATE_COPY_RELOCS) |
65f38f15 AM |
6114 | { |
6115 | /* For the non-shared case, discard space for relocs against | |
6116 | symbols which turn out to need copy relocs or are not | |
6117 | dynamic. */ | |
6118 | ||
6119 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
6120 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
6121 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
65f38f15 AM |
6122 | { |
6123 | /* Make sure this symbol is output as a dynamic symbol. | |
6124 | Undefined weak syms won't yet be marked as dynamic. */ | |
6125 | if (h->dynindx == -1 | |
6126 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
6127 | { | |
c152c796 | 6128 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 6129 | return FALSE; |
65f38f15 AM |
6130 | } |
6131 | ||
6132 | /* If that succeeded, we know we'll be keeping all the | |
6133 | relocs. */ | |
6134 | if (h->dynindx != -1) | |
6135 | goto keep; | |
6136 | } | |
6137 | ||
6138 | eh->dyn_relocs = NULL; | |
6139 | ||
ec338859 | 6140 | keep: ; |
65f38f15 AM |
6141 | } |
6142 | ||
6143 | /* Finally, allocate space. */ | |
6144 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
6145 | { | |
6146 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
eea6121a | 6147 | sreloc->size += p->count * sizeof (Elf64_External_Rela); |
65f38f15 AM |
6148 | } |
6149 | ||
b34976b6 | 6150 | return TRUE; |
65f38f15 AM |
6151 | } |
6152 | ||
6153 | /* Find any dynamic relocs that apply to read-only sections. */ | |
6154 | ||
b34976b6 | 6155 | static bfd_boolean |
4ce794b7 | 6156 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
65f38f15 AM |
6157 | { |
6158 | struct ppc_link_hash_entry *eh; | |
6159 | struct ppc_dyn_relocs *p; | |
6160 | ||
e92d460e AM |
6161 | if (h->root.type == bfd_link_hash_warning) |
6162 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
6163 | ||
65f38f15 AM |
6164 | eh = (struct ppc_link_hash_entry *) h; |
6165 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
6166 | { | |
6167 | asection *s = p->sec->output_section; | |
6168 | ||
6169 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
6170 | { | |
4ce794b7 | 6171 | struct bfd_link_info *info = inf; |
65f38f15 AM |
6172 | |
6173 | info->flags |= DF_TEXTREL; | |
6174 | ||
6175 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 6176 | return FALSE; |
65f38f15 AM |
6177 | } |
6178 | } | |
b34976b6 | 6179 | return TRUE; |
65f38f15 AM |
6180 | } |
6181 | ||
6182 | /* Set the sizes of the dynamic sections. */ | |
6183 | ||
b34976b6 | 6184 | static bfd_boolean |
4ce794b7 AM |
6185 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
6186 | struct bfd_link_info *info) | |
65f38f15 AM |
6187 | { |
6188 | struct ppc_link_hash_table *htab; | |
6189 | bfd *dynobj; | |
6190 | asection *s; | |
b34976b6 | 6191 | bfd_boolean relocs; |
65f38f15 AM |
6192 | bfd *ibfd; |
6193 | ||
6194 | htab = ppc_hash_table (info); | |
6195 | dynobj = htab->elf.dynobj; | |
6196 | if (dynobj == NULL) | |
6197 | abort (); | |
6198 | ||
6199 | if (htab->elf.dynamic_sections_created) | |
6200 | { | |
6201 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 6202 | if (info->executable) |
65f38f15 AM |
6203 | { |
6204 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
6205 | if (s == NULL) | |
6206 | abort (); | |
eea6121a | 6207 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
65f38f15 AM |
6208 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
6209 | } | |
6210 | } | |
6211 | ||
6212 | /* Set up .got offsets for local syms, and space for local dynamic | |
6213 | relocs. */ | |
6214 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
6215 | { | |
411e1bfb AM |
6216 | struct got_entry **lgot_ents; |
6217 | struct got_entry **end_lgot_ents; | |
e7b938ca | 6218 | char *lgot_masks; |
65f38f15 AM |
6219 | bfd_size_type locsymcount; |
6220 | Elf_Internal_Shdr *symtab_hdr; | |
6221 | asection *srel; | |
6222 | ||
6223 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
6224 | continue; | |
6225 | ||
e717da7e AM |
6226 | if (ppc64_tlsld_got (ibfd)->refcount > 0) |
6227 | { | |
6228 | s = ppc64_elf_tdata (ibfd)->got; | |
eea6121a AM |
6229 | ppc64_tlsld_got (ibfd)->offset = s->size; |
6230 | s->size += 16; | |
e717da7e AM |
6231 | if (info->shared) |
6232 | { | |
6233 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
eea6121a | 6234 | srel->size += sizeof (Elf64_External_Rela); |
e717da7e AM |
6235 | } |
6236 | } | |
6237 | else | |
6238 | ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; | |
6239 | ||
65f38f15 AM |
6240 | for (s = ibfd->sections; s != NULL; s = s->next) |
6241 | { | |
ec338859 | 6242 | struct ppc_dyn_relocs *p; |
65f38f15 | 6243 | |
ec338859 AM |
6244 | for (p = *((struct ppc_dyn_relocs **) |
6245 | &elf_section_data (s)->local_dynrel); | |
6246 | p != NULL; | |
6247 | p = p->next) | |
65f38f15 | 6248 | { |
ec338859 AM |
6249 | if (!bfd_is_abs_section (p->sec) |
6250 | && bfd_is_abs_section (p->sec->output_section)) | |
6251 | { | |
6252 | /* Input section has been discarded, either because | |
6253 | it is a copy of a linkonce section or due to | |
6254 | linker script /DISCARD/, so we'll be discarding | |
6255 | the relocs too. */ | |
6256 | } | |
248866a8 | 6257 | else if (p->count != 0) |
ec338859 AM |
6258 | { |
6259 | srel = elf_section_data (p->sec)->sreloc; | |
eea6121a | 6260 | srel->size += p->count * sizeof (Elf64_External_Rela); |
248866a8 AM |
6261 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
6262 | info->flags |= DF_TEXTREL; | |
ec338859 | 6263 | } |
65f38f15 AM |
6264 | } |
6265 | } | |
6266 | ||
411e1bfb AM |
6267 | lgot_ents = elf_local_got_ents (ibfd); |
6268 | if (!lgot_ents) | |
65f38f15 AM |
6269 | continue; |
6270 | ||
6271 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
6272 | locsymcount = symtab_hdr->sh_info; | |
411e1bfb | 6273 | end_lgot_ents = lgot_ents + locsymcount; |
e7b938ca | 6274 | lgot_masks = (char *) end_lgot_ents; |
e717da7e AM |
6275 | s = ppc64_elf_tdata (ibfd)->got; |
6276 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
e7b938ca | 6277 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
65f38f15 | 6278 | { |
411e1bfb AM |
6279 | struct got_entry *ent; |
6280 | ||
6281 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) | |
6282 | if (ent->got.refcount > 0) | |
6283 | { | |
e7b938ca | 6284 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
411e1bfb | 6285 | { |
e717da7e | 6286 | if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) |
411e1bfb | 6287 | { |
eea6121a AM |
6288 | ppc64_tlsld_got (ibfd)->offset = s->size; |
6289 | s->size += 16; | |
411e1bfb | 6290 | if (info->shared) |
eea6121a | 6291 | srel->size += sizeof (Elf64_External_Rela); |
411e1bfb | 6292 | } |
e717da7e | 6293 | ent->got.offset = ppc64_tlsld_got (ibfd)->offset; |
411e1bfb AM |
6294 | } |
6295 | else | |
6296 | { | |
eea6121a | 6297 | ent->got.offset = s->size; |
e7b938ca | 6298 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
411e1bfb | 6299 | { |
eea6121a | 6300 | s->size += 16; |
411e1bfb | 6301 | if (info->shared) |
eea6121a | 6302 | srel->size += 2 * sizeof (Elf64_External_Rela); |
411e1bfb AM |
6303 | } |
6304 | else | |
6305 | { | |
eea6121a | 6306 | s->size += 8; |
411e1bfb | 6307 | if (info->shared) |
eea6121a | 6308 | srel->size += sizeof (Elf64_External_Rela); |
411e1bfb AM |
6309 | } |
6310 | } | |
6311 | } | |
6312 | else | |
6313 | ent->got.offset = (bfd_vma) -1; | |
65f38f15 AM |
6314 | } |
6315 | } | |
6316 | ||
6317 | /* Allocate global sym .plt and .got entries, and space for global | |
6318 | sym dynamic relocs. */ | |
4ce794b7 | 6319 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
65f38f15 AM |
6320 | |
6321 | /* We now have determined the sizes of the various dynamic sections. | |
6322 | Allocate memory for them. */ | |
b34976b6 | 6323 | relocs = FALSE; |
65f38f15 AM |
6324 | for (s = dynobj->sections; s != NULL; s = s->next) |
6325 | { | |
6326 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
6327 | continue; | |
6328 | ||
4ce794b7 | 6329 | if (s == htab->brlt || s == htab->relbrlt) |
721956f4 AM |
6330 | /* These haven't been allocated yet; don't strip. */ |
6331 | continue; | |
e717da7e AM |
6332 | else if (s == htab->got |
6333 | || s == htab->plt | |
4ce794b7 | 6334 | || s == htab->glink) |
65f38f15 AM |
6335 | { |
6336 | /* Strip this section if we don't need it; see the | |
6337 | comment below. */ | |
5bd4f169 | 6338 | } |
65f38f15 | 6339 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 | 6340 | { |
eea6121a | 6341 | if (s->size == 0) |
5bd4f169 AM |
6342 | { |
6343 | /* If we don't need this section, strip it from the | |
6344 | output file. This is mostly to handle .rela.bss and | |
6345 | .rela.plt. We must create both sections in | |
6346 | create_dynamic_sections, because they must be created | |
6347 | before the linker maps input sections to output | |
6348 | sections. The linker does that before | |
6349 | adjust_dynamic_symbol is called, and it is that | |
6350 | function which decides whether anything needs to go | |
6351 | into these sections. */ | |
5bd4f169 AM |
6352 | } |
6353 | else | |
6354 | { | |
4ce794b7 | 6355 | if (s != htab->relplt) |
b34976b6 | 6356 | relocs = TRUE; |
5bd4f169 AM |
6357 | |
6358 | /* We use the reloc_count field as a counter if we need | |
6359 | to copy relocs into the output file. */ | |
6360 | s->reloc_count = 0; | |
6361 | } | |
6362 | } | |
65f38f15 | 6363 | else |
5bd4f169 AM |
6364 | { |
6365 | /* It's not one of our sections, so don't allocate space. */ | |
6366 | continue; | |
6367 | } | |
6368 | ||
eea6121a | 6369 | if (s->size == 0) |
5bd4f169 AM |
6370 | { |
6371 | _bfd_strip_section_from_output (info, s); | |
6372 | continue; | |
6373 | } | |
6374 | ||
5f333394 | 6375 | /* .plt is in the bss section. We don't initialise it. */ |
680a3378 | 6376 | if (s == htab->plt) |
5f333394 AM |
6377 | continue; |
6378 | ||
65f38f15 AM |
6379 | /* Allocate memory for the section contents. We use bfd_zalloc |
6380 | here in case unused entries are not reclaimed before the | |
6381 | section's contents are written out. This should not happen, | |
411e1bfb AM |
6382 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
6383 | sections instead of garbage. | |
6384 | We also rely on the section contents being zero when writing | |
6385 | the GOT. */ | |
eea6121a | 6386 | s->contents = bfd_zalloc (dynobj, s->size); |
65f38f15 | 6387 | if (s->contents == NULL) |
b34976b6 | 6388 | return FALSE; |
5bd4f169 AM |
6389 | } |
6390 | ||
e717da7e AM |
6391 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
6392 | { | |
6393 | s = ppc64_elf_tdata (ibfd)->got; | |
6394 | if (s != NULL && s != htab->got) | |
6395 | { | |
eea6121a | 6396 | if (s->size == 0) |
e717da7e AM |
6397 | _bfd_strip_section_from_output (info, s); |
6398 | else | |
6399 | { | |
eea6121a | 6400 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
6401 | if (s->contents == NULL) |
6402 | return FALSE; | |
6403 | } | |
6404 | } | |
6405 | s = ppc64_elf_tdata (ibfd)->relgot; | |
6406 | if (s != NULL) | |
6407 | { | |
eea6121a | 6408 | if (s->size == 0) |
e717da7e AM |
6409 | _bfd_strip_section_from_output (info, s); |
6410 | else | |
6411 | { | |
eea6121a | 6412 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
6413 | if (s->contents == NULL) |
6414 | return FALSE; | |
6415 | relocs = TRUE; | |
6416 | s->reloc_count = 0; | |
6417 | } | |
6418 | } | |
6419 | } | |
6420 | ||
e86ce104 | 6421 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
6422 | { |
6423 | /* Add some entries to the .dynamic section. We fill in the | |
6424 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
6425 | must add the entries now so that we get the correct size for | |
6426 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
6427 | dynamic linker and used by the debugger. */ | |
dc810e39 | 6428 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 6429 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 6430 | |
36af4a4e | 6431 | if (info->executable) |
5bd4f169 | 6432 | { |
dc810e39 | 6433 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 6434 | return FALSE; |
5bd4f169 AM |
6435 | } |
6436 | ||
eea6121a | 6437 | if (htab->plt != NULL && htab->plt->size != 0) |
5bd4f169 | 6438 | { |
dc810e39 AM |
6439 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
6440 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
6441 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
6442 | || !add_dynamic_entry (DT_JMPREL, 0) |
6443 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 6444 | return FALSE; |
5bd4f169 AM |
6445 | } |
6446 | ||
19397422 AM |
6447 | if (NO_OPD_RELOCS) |
6448 | { | |
6449 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
6450 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 6451 | return FALSE; |
19397422 AM |
6452 | } |
6453 | ||
5bd4f169 AM |
6454 | if (relocs) |
6455 | { | |
dc810e39 AM |
6456 | if (!add_dynamic_entry (DT_RELA, 0) |
6457 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6458 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 6459 | return FALSE; |
5bd4f169 | 6460 | |
65f38f15 AM |
6461 | /* If any dynamic relocs apply to a read-only section, |
6462 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 6463 | if ((info->flags & DF_TEXTREL) == 0) |
4ce794b7 | 6464 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
5bd4f169 | 6465 | |
65f38f15 | 6466 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 6467 | { |
65f38f15 | 6468 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 6469 | return FALSE; |
5bd4f169 | 6470 | } |
5bd4f169 | 6471 | } |
5bd4f169 | 6472 | } |
65f38f15 | 6473 | #undef add_dynamic_entry |
5bd4f169 | 6474 | |
b34976b6 | 6475 | return TRUE; |
5bd4f169 AM |
6476 | } |
6477 | ||
721956f4 | 6478 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 6479 | |
4ce794b7 AM |
6480 | static inline enum ppc_stub_type |
6481 | ppc_type_of_stub (asection *input_sec, | |
6482 | const Elf_Internal_Rela *rel, | |
6483 | struct ppc_link_hash_entry **hash, | |
6484 | bfd_vma destination) | |
5bd4f169 | 6485 | { |
721956f4 AM |
6486 | struct ppc_link_hash_entry *h = *hash; |
6487 | bfd_vma location; | |
6488 | bfd_vma branch_offset; | |
6489 | bfd_vma max_branch_offset; | |
4ce794b7 | 6490 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 | 6491 | |
721956f4 AM |
6492 | if (h != NULL) |
6493 | { | |
6494 | if (h->oh != NULL | |
8387904d AM |
6495 | && h->oh->is_func_descriptor) |
6496 | h = h->oh; | |
6497 | ||
6498 | if (h->elf.dynindx != -1) | |
5bd4f169 | 6499 | { |
411e1bfb | 6500 | struct plt_entry *ent; |
8387904d AM |
6501 | |
6502 | for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next) | |
411e1bfb AM |
6503 | if (ent->addend == rel->r_addend |
6504 | && ent->plt.offset != (bfd_vma) -1) | |
6505 | { | |
8387904d | 6506 | *hash = h; |
411e1bfb AM |
6507 | return ppc_stub_plt_call; |
6508 | } | |
5bd4f169 AM |
6509 | } |
6510 | ||
ee7de3e6 AM |
6511 | if (!(h->elf.root.type == bfd_link_hash_defined |
6512 | || h->elf.root.type == bfd_link_hash_defweak) | |
6513 | || h->elf.root.u.def.section->output_section == NULL) | |
721956f4 | 6514 | return ppc_stub_none; |
5d1634d7 | 6515 | } |
5d1634d7 | 6516 | |
721956f4 AM |
6517 | /* Determine where the call point is. */ |
6518 | location = (input_sec->output_offset | |
6519 | + input_sec->output_section->vma | |
6520 | + rel->r_offset); | |
5d1634d7 | 6521 | |
721956f4 AM |
6522 | branch_offset = destination - location; |
6523 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 6524 | |
721956f4 AM |
6525 | /* Determine if a long branch stub is needed. */ |
6526 | max_branch_offset = 1 << 25; | |
4ce794b7 | 6527 | if (r_type != R_PPC64_REL24) |
721956f4 | 6528 | max_branch_offset = 1 << 15; |
5d1634d7 | 6529 | |
721956f4 AM |
6530 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
6531 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
6532 | is needed later. */ | |
6533 | return ppc_stub_long_branch; | |
5d1634d7 | 6534 | |
721956f4 | 6535 | return ppc_stub_none; |
5d1634d7 AM |
6536 | } |
6537 | ||
6538 | /* Build a .plt call stub. */ | |
6539 | ||
4ce794b7 AM |
6540 | static inline bfd_byte * |
6541 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset) | |
5d1634d7 AM |
6542 | { |
6543 | #define PPC_LO(v) ((v) & 0xffff) | |
6544 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6545 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6546 | ||
5d1634d7 | 6547 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
ad8e1ba5 | 6548 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
5d1634d7 AM |
6549 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
6550 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6551 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6552 | offset += 8; |
6553 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
6554 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6555 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6556 | offset += 8; |
6557 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
6558 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
6559 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
6560 | return p; | |
6561 | } | |
6562 | ||
b34976b6 | 6563 | static bfd_boolean |
4ce794b7 | 6564 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
5d1634d7 | 6565 | { |
721956f4 AM |
6566 | struct ppc_stub_hash_entry *stub_entry; |
6567 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
6568 | struct bfd_link_info *info; |
6569 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
6570 | bfd_byte *loc; |
6571 | bfd_byte *p; | |
6572 | unsigned int indx; | |
411e1bfb | 6573 | struct plt_entry *ent; |
721956f4 AM |
6574 | bfd_vma off; |
6575 | int size; | |
5d1634d7 | 6576 | |
721956f4 AM |
6577 | /* Massage our args to the form they really have. */ |
6578 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6579 | info = in_arg; |
5d1634d7 | 6580 | |
5d1634d7 AM |
6581 | htab = ppc_hash_table (info); |
6582 | ||
721956f4 | 6583 | /* Make a note of the offset within the stubs for this entry. */ |
eea6121a | 6584 | stub_entry->stub_offset = stub_entry->stub_sec->size; |
97b639ba | 6585 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; |
721956f4 | 6586 | |
4ce794b7 | 6587 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
721956f4 | 6588 | switch (stub_entry->stub_type) |
5d1634d7 | 6589 | { |
721956f4 | 6590 | case ppc_stub_long_branch: |
ad8e1ba5 | 6591 | case ppc_stub_long_branch_r2off: |
721956f4 AM |
6592 | /* Branches are relative. This is where we are going to. */ |
6593 | off = (stub_entry->target_value | |
6594 | + stub_entry->target_section->output_offset | |
6595 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 6596 | |
721956f4 AM |
6597 | /* And this is where we are coming from. */ |
6598 | off -= (stub_entry->stub_offset | |
97b639ba AM |
6599 | + stub_entry->stub_sec->output_offset |
6600 | + stub_entry->stub_sec->output_section->vma); | |
e86ce104 | 6601 | |
ad8e1ba5 AM |
6602 | if (stub_entry->stub_type != ppc_stub_long_branch_r2off) |
6603 | size = 4; | |
6604 | else | |
6605 | { | |
6606 | bfd_vma r2off; | |
6607 | ||
6608 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6609 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6610 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6611 | loc += 4; |
97b639ba | 6612 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6613 | loc += 4; |
97b639ba | 6614 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6615 | loc += 4; |
6616 | off -= 12; | |
6617 | size = 16; | |
6618 | } | |
97b639ba | 6619 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
ad8e1ba5 AM |
6620 | |
6621 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); | |
721956f4 | 6622 | break; |
e86ce104 | 6623 | |
721956f4 | 6624 | case ppc_stub_plt_branch: |
ad8e1ba5 | 6625 | case ppc_stub_plt_branch_r2off: |
721956f4 AM |
6626 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
6627 | stub_entry->root.string + 9, | |
b34976b6 | 6628 | FALSE, FALSE); |
721956f4 AM |
6629 | if (br_entry == NULL) |
6630 | { | |
6631 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), | |
6632 | stub_entry->root.string + 9); | |
b34976b6 AM |
6633 | htab->stub_error = TRUE; |
6634 | return FALSE; | |
721956f4 AM |
6635 | } |
6636 | ||
6637 | off = (stub_entry->target_value | |
6638 | + stub_entry->target_section->output_offset | |
6639 | + stub_entry->target_section->output_section->vma); | |
6640 | ||
4ce794b7 AM |
6641 | bfd_put_64 (htab->brlt->owner, off, |
6642 | htab->brlt->contents + br_entry->offset); | |
721956f4 AM |
6643 | |
6644 | if (info->shared) | |
6645 | { | |
6646 | /* Create a reloc for the branch lookup table entry. */ | |
6647 | Elf_Internal_Rela rela; | |
ad8e1ba5 | 6648 | bfd_byte *rl; |
5d1634d7 | 6649 | |
721956f4 | 6650 | rela.r_offset = (br_entry->offset |
4ce794b7 AM |
6651 | + htab->brlt->output_offset |
6652 | + htab->brlt->output_section->vma); | |
721956f4 AM |
6653 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
6654 | rela.r_addend = off; | |
6655 | ||
4ce794b7 AM |
6656 | rl = htab->relbrlt->contents; |
6657 | rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela); | |
6658 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); | |
721956f4 AM |
6659 | } |
6660 | ||
6661 | off = (br_entry->offset | |
4ce794b7 AM |
6662 | + htab->brlt->output_offset |
6663 | + htab->brlt->output_section->vma | |
6664 | - elf_gp (htab->brlt->output_section->owner) | |
ad8e1ba5 | 6665 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6666 | |
ad8e1ba5 | 6667 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
5d1634d7 AM |
6668 | { |
6669 | (*_bfd_error_handler) | |
e86ce104 | 6670 | (_("linkage table error against `%s'"), |
721956f4 | 6671 | stub_entry->root.string); |
5d1634d7 | 6672 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
6673 | htab->stub_error = TRUE; |
6674 | return FALSE; | |
5d1634d7 | 6675 | } |
41bd81ab | 6676 | |
721956f4 | 6677 | indx = off; |
ad8e1ba5 AM |
6678 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
6679 | { | |
97b639ba | 6680 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6681 | loc += 4; |
97b639ba | 6682 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 AM |
6683 | size = 16; |
6684 | } | |
6685 | else | |
6686 | { | |
6687 | bfd_vma r2off; | |
6688 | ||
6689 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6690 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6691 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6692 | loc += 4; |
97b639ba | 6693 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6694 | loc += 4; |
97b639ba | 6695 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 | 6696 | loc += 4; |
97b639ba | 6697 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6698 | loc += 4; |
97b639ba | 6699 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6700 | size = 28; |
6701 | } | |
6702 | loc += 4; | |
97b639ba | 6703 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
ad8e1ba5 | 6704 | loc += 4; |
97b639ba | 6705 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
721956f4 | 6706 | break; |
5d1634d7 | 6707 | |
721956f4 | 6708 | case ppc_stub_plt_call: |
c862ae31 AM |
6709 | /* Do the best we can for shared libraries built without |
6710 | exporting ".foo" for each "foo". This can happen when symbol | |
6711 | versioning scripts strip all bar a subset of symbols. */ | |
8387904d AM |
6712 | if (stub_entry->h->oh != NULL |
6713 | && stub_entry->h->oh->elf.root.type != bfd_link_hash_defined | |
34814b9f | 6714 | && stub_entry->h->oh->elf.root.type != bfd_link_hash_defweak) |
c862ae31 AM |
6715 | { |
6716 | /* Point the symbol at the stub. There may be multiple stubs, | |
6717 | we don't really care; The main thing is to make this sym | |
8f3bab57 AM |
6718 | defined somewhere. Maybe defining the symbol in the stub |
6719 | section is a silly idea. If we didn't do this, htab->top_id | |
6720 | could disappear. */ | |
34814b9f AM |
6721 | stub_entry->h->oh->elf.root.type = bfd_link_hash_defined; |
6722 | stub_entry->h->oh->elf.root.u.def.section = stub_entry->stub_sec; | |
6723 | stub_entry->h->oh->elf.root.u.def.value = stub_entry->stub_offset; | |
c862ae31 AM |
6724 | } |
6725 | ||
721956f4 | 6726 | /* Now build the stub. */ |
411e1bfb AM |
6727 | off = (bfd_vma) -1; |
6728 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) | |
6729 | if (ent->addend == stub_entry->addend) | |
6730 | { | |
6731 | off = ent->plt.offset; | |
6732 | break; | |
6733 | } | |
721956f4 AM |
6734 | if (off >= (bfd_vma) -2) |
6735 | abort (); | |
6736 | ||
6737 | off &= ~ (bfd_vma) 1; | |
4ce794b7 AM |
6738 | off += (htab->plt->output_offset |
6739 | + htab->plt->output_section->vma | |
6740 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6741 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6742 | |
ad8e1ba5 | 6743 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
721956f4 AM |
6744 | { |
6745 | (*_bfd_error_handler) | |
6746 | (_("linkage table error against `%s'"), | |
6747 | stub_entry->h->elf.root.root.string); | |
6748 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 AM |
6749 | htab->stub_error = TRUE; |
6750 | return FALSE; | |
721956f4 AM |
6751 | } |
6752 | ||
97b639ba | 6753 | p = build_plt_stub (htab->stub_bfd, loc, off); |
721956f4 AM |
6754 | size = p - loc; |
6755 | break; | |
6756 | ||
6757 | default: | |
6758 | BFD_FAIL (); | |
b34976b6 | 6759 | return FALSE; |
721956f4 AM |
6760 | } |
6761 | ||
eea6121a | 6762 | stub_entry->stub_sec->size += size; |
97b639ba AM |
6763 | |
6764 | if (htab->emit_stub_syms | |
6765 | && !(stub_entry->stub_type == ppc_stub_plt_call | |
8387904d | 6766 | && stub_entry->h->oh != NULL |
34814b9f AM |
6767 | && stub_entry->h->oh->elf.root.type == bfd_link_hash_defined |
6768 | && stub_entry->h->oh->elf.root.u.def.section == stub_entry->stub_sec | |
6769 | && stub_entry->h->oh->elf.root.u.def.value == stub_entry->stub_offset)) | |
97b639ba AM |
6770 | { |
6771 | struct elf_link_hash_entry *h; | |
6772 | h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string, | |
6773 | TRUE, FALSE, FALSE); | |
6774 | if (h == NULL) | |
6775 | return FALSE; | |
6776 | if (h->root.type == bfd_link_hash_new) | |
6777 | { | |
6778 | h->root.type = bfd_link_hash_defined; | |
6779 | h->root.u.def.section = stub_entry->stub_sec; | |
6780 | h->root.u.def.value = stub_entry->stub_offset; | |
6781 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
6782 | | ELF_LINK_HASH_DEF_REGULAR | |
6783 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
6784 | | ELF_LINK_FORCED_LOCAL); | |
6785 | } | |
6786 | } | |
6787 | ||
b34976b6 | 6788 | return TRUE; |
721956f4 AM |
6789 | } |
6790 | ||
6791 | /* As above, but don't actually build the stub. Just bump offset so | |
6792 | we know stub section sizes, and select plt_branch stubs where | |
6793 | long_branch stubs won't do. */ | |
6794 | ||
b34976b6 | 6795 | static bfd_boolean |
4ce794b7 | 6796 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
721956f4 AM |
6797 | { |
6798 | struct ppc_stub_hash_entry *stub_entry; | |
63bc6f6c | 6799 | struct bfd_link_info *info; |
721956f4 AM |
6800 | struct ppc_link_hash_table *htab; |
6801 | bfd_vma off; | |
6802 | int size; | |
6803 | ||
6804 | /* Massage our args to the form they really have. */ | |
6805 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
63bc6f6c AM |
6806 | info = in_arg; |
6807 | ||
6808 | htab = ppc_hash_table (info); | |
721956f4 AM |
6809 | |
6810 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
6811 | { | |
411e1bfb | 6812 | struct plt_entry *ent; |
58ac9f71 | 6813 | off = (bfd_vma) -1; |
411e1bfb AM |
6814 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
6815 | if (ent->addend == stub_entry->addend) | |
6816 | { | |
6817 | off = ent->plt.offset & ~(bfd_vma) 1; | |
6818 | break; | |
6819 | } | |
58ac9f71 | 6820 | if (off >= (bfd_vma) -2) |
411e1bfb | 6821 | abort (); |
4ce794b7 AM |
6822 | off += (htab->plt->output_offset |
6823 | + htab->plt->output_section->vma | |
6824 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6825 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6826 | |
ad8e1ba5 | 6827 | size = PLT_CALL_STUB_SIZE; |
4ce794b7 | 6828 | if (PPC_HA (off + 16) != PPC_HA (off)) |
721956f4 AM |
6829 | size += 4; |
6830 | } | |
6831 | else | |
6832 | { | |
ad8e1ba5 AM |
6833 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
6834 | variants. */ | |
721956f4 AM |
6835 | off = (stub_entry->target_value |
6836 | + stub_entry->target_section->output_offset | |
6837 | + stub_entry->target_section->output_section->vma); | |
eea6121a | 6838 | off -= (stub_entry->stub_sec->size |
721956f4 AM |
6839 | + stub_entry->stub_sec->output_offset |
6840 | + stub_entry->stub_sec->output_section->vma); | |
6841 | ||
ad8e1ba5 AM |
6842 | /* Reset the stub type from the plt variant in case we now |
6843 | can reach with a shorter stub. */ | |
6844 | if (stub_entry->stub_type >= ppc_stub_plt_branch) | |
6845 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; | |
6846 | ||
6847 | size = 4; | |
6848 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
6849 | { | |
6850 | off -= 12; | |
6851 | size = 16; | |
6852 | } | |
6853 | ||
6854 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ | |
721956f4 AM |
6855 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
6856 | { | |
6857 | struct ppc_branch_hash_entry *br_entry; | |
6858 | ||
6859 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
6860 | stub_entry->root.string + 9, | |
b34976b6 | 6861 | TRUE, FALSE); |
721956f4 AM |
6862 | if (br_entry == NULL) |
6863 | { | |
6864 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), | |
6865 | stub_entry->root.string + 9); | |
b34976b6 AM |
6866 | htab->stub_error = TRUE; |
6867 | return FALSE; | |
721956f4 AM |
6868 | } |
6869 | ||
6870 | if (br_entry->iter != htab->stub_iteration) | |
6871 | { | |
6872 | br_entry->iter = htab->stub_iteration; | |
eea6121a AM |
6873 | br_entry->offset = htab->brlt->size; |
6874 | htab->brlt->size += 8; | |
63bc6f6c AM |
6875 | |
6876 | if (info->shared) | |
eea6121a | 6877 | htab->relbrlt->size += sizeof (Elf64_External_Rela); |
721956f4 | 6878 | } |
ad8e1ba5 AM |
6879 | |
6880 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | |
721956f4 | 6881 | size = 16; |
ad8e1ba5 AM |
6882 | if (stub_entry->stub_type != ppc_stub_plt_branch) |
6883 | size = 28; | |
721956f4 AM |
6884 | } |
6885 | } | |
6886 | ||
eea6121a | 6887 | stub_entry->stub_sec->size += size; |
b34976b6 | 6888 | return TRUE; |
721956f4 AM |
6889 | } |
6890 | ||
6891 | /* Set up various things so that we can make a list of input sections | |
6892 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 6893 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
6894 | |
6895 | int | |
4ce794b7 | 6896 | ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
721956f4 AM |
6897 | { |
6898 | bfd *input_bfd; | |
734b6cf9 | 6899 | int top_id, top_index, id; |
721956f4 | 6900 | asection *section; |
734b6cf9 | 6901 | asection **input_list; |
721956f4 AM |
6902 | bfd_size_type amt; |
6903 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6904 | ||
4ce794b7 | 6905 | if (htab->brlt == NULL) |
721956f4 AM |
6906 | return 0; |
6907 | ||
1e2f5b6e | 6908 | /* Find the top input section id. */ |
3d6f9012 | 6909 | for (input_bfd = info->input_bfds, top_id = 3; |
721956f4 AM |
6910 | input_bfd != NULL; |
6911 | input_bfd = input_bfd->link_next) | |
6912 | { | |
721956f4 AM |
6913 | for (section = input_bfd->sections; |
6914 | section != NULL; | |
6915 | section = section->next) | |
6916 | { | |
6917 | if (top_id < section->id) | |
6918 | top_id = section->id; | |
6919 | } | |
6920 | } | |
721956f4 | 6921 | |
8f3bab57 | 6922 | htab->top_id = top_id; |
721956f4 | 6923 | amt = sizeof (struct map_stub) * (top_id + 1); |
4ce794b7 | 6924 | htab->stub_group = bfd_zmalloc (amt); |
721956f4 AM |
6925 | if (htab->stub_group == NULL) |
6926 | return -1; | |
6927 | ||
3d6f9012 AM |
6928 | /* Set toc_off for com, und, abs and ind sections. */ |
6929 | for (id = 0; id < 3; id++) | |
6930 | htab->stub_group[id].toc_off = TOC_BASE_OFF; | |
721956f4 | 6931 | |
3d6f9012 | 6932 | elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd); |
734b6cf9 AM |
6933 | |
6934 | /* We can't use output_bfd->section_count here to find the top output | |
6935 | section index as some sections may have been removed, and | |
6936 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
6937 | for (section = output_bfd->sections, top_index = 0; | |
6938 | section != NULL; | |
6939 | section = section->next) | |
6940 | { | |
6941 | if (top_index < section->index) | |
6942 | top_index = section->index; | |
6943 | } | |
6944 | ||
6945 | htab->top_index = top_index; | |
6946 | amt = sizeof (asection *) * (top_index + 1); | |
4ce794b7 | 6947 | input_list = bfd_zmalloc (amt); |
734b6cf9 AM |
6948 | htab->input_list = input_list; |
6949 | if (input_list == NULL) | |
6950 | return -1; | |
6951 | ||
721956f4 AM |
6952 | return 1; |
6953 | } | |
6954 | ||
e717da7e AM |
6955 | /* The linker repeatedly calls this function for each TOC input section |
6956 | and linker generated GOT section. Group input bfds such that the toc | |
6957 | within a group is less than 64k in size. Will break with cute linker | |
6958 | scripts that play games with dot in the output toc section. */ | |
ad8e1ba5 AM |
6959 | |
6960 | void | |
4ce794b7 | 6961 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
ad8e1ba5 AM |
6962 | { |
6963 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
99877b66 AM |
6964 | bfd_vma addr = isec->output_offset + isec->output_section->vma; |
6965 | bfd_vma off = addr - htab->toc_curr; | |
ad8e1ba5 | 6966 | |
99877b66 AM |
6967 | if (off + isec->size > 0x10000) |
6968 | htab->toc_curr = addr; | |
6969 | ||
6970 | elf_gp (isec->owner) = (htab->toc_curr | |
6971 | - elf_gp (isec->output_section->owner) | |
6972 | + TOC_BASE_OFF); | |
ad8e1ba5 AM |
6973 | } |
6974 | ||
6975 | /* Called after the last call to the above function. */ | |
6976 | ||
6977 | void | |
4ce794b7 AM |
6978 | ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED, |
6979 | struct bfd_link_info *info) | |
ad8e1ba5 AM |
6980 | { |
6981 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
ad8e1ba5 AM |
6982 | |
6983 | /* toc_curr tracks the TOC offset used for code sections below in | |
6984 | ppc64_elf_next_input_section. Start off at 0x8000. */ | |
3d6f9012 | 6985 | htab->toc_curr = TOC_BASE_OFF; |
ad8e1ba5 AM |
6986 | } |
6987 | ||
9b5ecbd0 AM |
6988 | /* No toc references were found in ISEC. If the code in ISEC makes no |
6989 | calls, then there's no need to use toc adjusting stubs when branching | |
6990 | into ISEC. Actually, indirect calls from ISEC are OK as they will | |
6991 | load r2. */ | |
6992 | ||
6993 | static int | |
4ce794b7 | 6994 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
9b5ecbd0 AM |
6995 | { |
6996 | bfd_byte *contents; | |
6997 | bfd_size_type i; | |
6998 | int ret; | |
6999 | int branch_ok; | |
7000 | ||
772119ce AM |
7001 | /* We know none of our code bearing sections will need toc stubs. */ |
7002 | if ((isec->flags & SEC_LINKER_CREATED) != 0) | |
7003 | return 0; | |
7004 | ||
eea6121a | 7005 | if (isec->size == 0) |
082c50f8 AM |
7006 | return 0; |
7007 | ||
9b5ecbd0 AM |
7008 | /* Hack for linux kernel. .fixup contains branches, but only back to |
7009 | the function that hit an exception. */ | |
7010 | branch_ok = strcmp (isec->name, ".fixup") == 0; | |
7011 | ||
7012 | contents = elf_section_data (isec)->this_hdr.contents; | |
7013 | if (contents == NULL) | |
7014 | { | |
eea6121a | 7015 | if (!bfd_malloc_and_get_section (isec->owner, isec, &contents)) |
9b5ecbd0 | 7016 | { |
eea6121a AM |
7017 | if (contents != NULL) |
7018 | free (contents); | |
9b5ecbd0 AM |
7019 | return -1; |
7020 | } | |
7021 | if (info->keep_memory) | |
7022 | elf_section_data (isec)->this_hdr.contents = contents; | |
7023 | } | |
7024 | ||
7025 | /* Code scan, because we don't necessarily have relocs on calls to | |
7026 | static functions. */ | |
7027 | ret = 0; | |
eea6121a | 7028 | for (i = 0; i < isec->size; i += 4) |
9b5ecbd0 AM |
7029 | { |
7030 | unsigned long insn = bfd_get_32 (isec->owner, contents + i); | |
7031 | /* Is this a branch? */ | |
772119ce | 7032 | if ((insn & (0x3f << 26)) == (18 << 26) |
9b5ecbd0 AM |
7033 | /* If branch and link, it's a function call. */ |
7034 | && ((insn & 1) != 0 | |
7035 | /* Sibling calls use a plain branch. I don't know a way | |
7036 | of deciding whether a branch is really a sibling call. */ | |
7037 | || !branch_ok)) | |
7038 | { | |
7039 | ret = 1; | |
7040 | break; | |
7041 | } | |
7042 | } | |
7043 | ||
7044 | if (elf_section_data (isec)->this_hdr.contents != contents) | |
7045 | free (contents); | |
7046 | return ret; | |
7047 | } | |
7048 | ||
721956f4 AM |
7049 | /* The linker repeatedly calls this function for each input section, |
7050 | in the order that input sections are linked into output sections. | |
7051 | Build lists of input sections to determine groupings between which | |
7052 | we may insert linker stubs. */ | |
7053 | ||
9b5ecbd0 | 7054 | bfd_boolean |
4ce794b7 | 7055 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
721956f4 AM |
7056 | { |
7057 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
9b5ecbd0 | 7058 | int ret; |
721956f4 | 7059 | |
734b6cf9 AM |
7060 | if ((isec->output_section->flags & SEC_CODE) != 0 |
7061 | && isec->output_section->index <= htab->top_index) | |
721956f4 | 7062 | { |
734b6cf9 | 7063 | asection **list = htab->input_list + isec->output_section->index; |
3d6f9012 | 7064 | /* Steal the link_sec pointer for our list. */ |
721956f4 | 7065 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3d6f9012 AM |
7066 | /* This happens to make the list in reverse order, |
7067 | which is what we want. */ | |
734b6cf9 AM |
7068 | PREV_SEC (isec) = *list; |
7069 | *list = isec; | |
721956f4 | 7070 | } |
ad8e1ba5 AM |
7071 | |
7072 | /* If a code section has a function that uses the TOC then we need | |
7073 | to use the right TOC (obviously). Also, make sure that .opd gets | |
ee87f2da AM |
7074 | the correct TOC value for R_PPC64_TOC relocs that don't have or |
7075 | can't find their function symbol (shouldn't ever happen now). */ | |
ad8e1ba5 | 7076 | if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0) |
9b5ecbd0 AM |
7077 | { |
7078 | if (elf_gp (isec->owner) != 0) | |
7079 | htab->toc_curr = elf_gp (isec->owner); | |
7080 | } | |
7081 | else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0) | |
7082 | return FALSE; | |
7083 | else | |
7084 | isec->has_gp_reloc = ret; | |
ad8e1ba5 AM |
7085 | |
7086 | /* Functions that don't use the TOC can belong in any TOC group. | |
7087 | Use the last TOC base. This happens to make _init and _fini | |
7088 | pasting work. */ | |
7089 | htab->stub_group[isec->id].toc_off = htab->toc_curr; | |
9b5ecbd0 | 7090 | return TRUE; |
721956f4 AM |
7091 | } |
7092 | ||
7093 | /* See whether we can group stub sections together. Grouping stub | |
7094 | sections may result in fewer stubs. More importantly, we need to | |
7095 | put all .init* and .fini* stubs at the beginning of the .init or | |
7096 | .fini output sections respectively, because glibc splits the | |
7097 | _init and _fini functions into multiple parts. Putting a stub in | |
7098 | the middle of a function is not a good idea. */ | |
7099 | ||
7100 | static void | |
4ce794b7 AM |
7101 | group_sections (struct ppc_link_hash_table *htab, |
7102 | bfd_size_type stub_group_size, | |
7103 | bfd_boolean stubs_always_before_branch) | |
721956f4 | 7104 | { |
734b6cf9 AM |
7105 | asection **list = htab->input_list + htab->top_index; |
7106 | do | |
721956f4 | 7107 | { |
734b6cf9 AM |
7108 | asection *tail = *list; |
7109 | while (tail != NULL) | |
721956f4 | 7110 | { |
734b6cf9 AM |
7111 | asection *curr; |
7112 | asection *prev; | |
7113 | bfd_size_type total; | |
7114 | bfd_boolean big_sec; | |
7115 | bfd_vma curr_toc; | |
7116 | ||
7117 | curr = tail; | |
eea6121a | 7118 | total = tail->size; |
734b6cf9 AM |
7119 | big_sec = total >= stub_group_size; |
7120 | curr_toc = htab->stub_group[tail->id].toc_off; | |
7121 | ||
7122 | while ((prev = PREV_SEC (curr)) != NULL | |
7123 | && ((total += curr->output_offset - prev->output_offset) | |
ad8e1ba5 AM |
7124 | < stub_group_size) |
7125 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
734b6cf9 AM |
7126 | curr = prev; |
7127 | ||
7128 | /* OK, the size from the start of CURR to the end is less | |
7129 | than stub_group_size and thus can be handled by one stub | |
7130 | section. (or the tail section is itself larger than | |
7131 | stub_group_size, in which case we may be toast.) We | |
7132 | should really be keeping track of the total size of stubs | |
7133 | added here, as stubs contribute to the final output | |
7134 | section size. That's a little tricky, and this way will | |
7135 | only break if stubs added make the total size more than | |
7136 | 2^25, ie. for the default stub_group_size, if stubs total | |
7137 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ | |
7138 | do | |
721956f4 AM |
7139 | { |
7140 | prev = PREV_SEC (tail); | |
734b6cf9 | 7141 | /* Set up this stub group. */ |
721956f4 AM |
7142 | htab->stub_group[tail->id].link_sec = curr; |
7143 | } | |
734b6cf9 AM |
7144 | while (tail != curr && (tail = prev) != NULL); |
7145 | ||
7146 | /* But wait, there's more! Input sections up to stub_group_size | |
7147 | bytes before the stub section can be handled by it too. | |
7148 | Don't do this if we have a really large section after the | |
7149 | stubs, as adding more stubs increases the chance that | |
7150 | branches may not reach into the stub section. */ | |
7151 | if (!stubs_always_before_branch && !big_sec) | |
7152 | { | |
7153 | total = 0; | |
7154 | while (prev != NULL | |
7155 | && ((total += tail->output_offset - prev->output_offset) | |
7156 | < stub_group_size) | |
7157 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
7158 | { | |
7159 | tail = prev; | |
7160 | prev = PREV_SEC (tail); | |
7161 | htab->stub_group[tail->id].link_sec = curr; | |
7162 | } | |
7163 | } | |
7164 | tail = prev; | |
721956f4 AM |
7165 | } |
7166 | } | |
734b6cf9 AM |
7167 | while (list-- != htab->input_list); |
7168 | free (htab->input_list); | |
721956f4 AM |
7169 | #undef PREV_SEC |
7170 | } | |
7171 | ||
721956f4 AM |
7172 | /* Determine and set the size of the stub section for a final link. |
7173 | ||
7174 | The basic idea here is to examine all the relocations looking for | |
7175 | PC-relative calls to a target that is unreachable with a "bl" | |
7176 | instruction. */ | |
7177 | ||
b34976b6 | 7178 | bfd_boolean |
4ce794b7 | 7179 | ppc64_elf_size_stubs (bfd *output_bfd, |
4ce794b7 AM |
7180 | struct bfd_link_info *info, |
7181 | bfd_signed_vma group_size, | |
7182 | asection *(*add_stub_section) (const char *, asection *), | |
7183 | void (*layout_sections_again) (void)) | |
721956f4 AM |
7184 | { |
7185 | bfd_size_type stub_group_size; | |
b34976b6 | 7186 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
7187 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
7188 | ||
7189 | /* Stash our params away. */ | |
721956f4 AM |
7190 | htab->add_stub_section = add_stub_section; |
7191 | htab->layout_sections_again = layout_sections_again; | |
7192 | stubs_always_before_branch = group_size < 0; | |
7193 | if (group_size < 0) | |
7194 | stub_group_size = -group_size; | |
7195 | else | |
7196 | stub_group_size = group_size; | |
7197 | if (stub_group_size == 1) | |
7198 | { | |
7199 | /* Default values. */ | |
58ac9f71 AM |
7200 | if (stubs_always_before_branch) |
7201 | { | |
7202 | stub_group_size = 0x1e00000; | |
7203 | if (htab->has_14bit_branch) | |
7204 | stub_group_size = 0x7800; | |
7205 | } | |
7206 | else | |
7207 | { | |
7208 | stub_group_size = 0x1c00000; | |
7209 | if (htab->has_14bit_branch) | |
7210 | stub_group_size = 0x7000; | |
7211 | } | |
721956f4 AM |
7212 | } |
7213 | ||
7214 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
7215 | ||
721956f4 AM |
7216 | while (1) |
7217 | { | |
7218 | bfd *input_bfd; | |
7219 | unsigned int bfd_indx; | |
7220 | asection *stub_sec; | |
b34976b6 | 7221 | bfd_boolean stub_changed; |
721956f4 AM |
7222 | |
7223 | htab->stub_iteration += 1; | |
b34976b6 | 7224 | stub_changed = FALSE; |
721956f4 AM |
7225 | |
7226 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
7227 | input_bfd != NULL; | |
7228 | input_bfd = input_bfd->link_next, bfd_indx++) | |
7229 | { | |
7230 | Elf_Internal_Shdr *symtab_hdr; | |
7231 | asection *section; | |
6cdc0ccc | 7232 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 AM |
7233 | |
7234 | /* We'll need the symbol table in a second. */ | |
7235 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
7236 | if (symtab_hdr->sh_info == 0) | |
7237 | continue; | |
7238 | ||
721956f4 AM |
7239 | /* Walk over each section attached to the input bfd. */ |
7240 | for (section = input_bfd->sections; | |
7241 | section != NULL; | |
7242 | section = section->next) | |
7243 | { | |
721956f4 | 7244 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
7245 | |
7246 | /* If there aren't any relocs, then there's nothing more | |
7247 | to do. */ | |
7248 | if ((section->flags & SEC_RELOC) == 0 | |
7249 | || section->reloc_count == 0) | |
7250 | continue; | |
7251 | ||
7252 | /* If this section is a link-once section that will be | |
7253 | discarded, then don't create any stubs. */ | |
7254 | if (section->output_section == NULL | |
7255 | || section->output_section->owner != output_bfd) | |
7256 | continue; | |
7257 | ||
1e2f5b6e AM |
7258 | /* Get the relocs. */ |
7259 | internal_relocs | |
4ce794b7 | 7260 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 7261 | info->keep_memory); |
721956f4 | 7262 | if (internal_relocs == NULL) |
1e2f5b6e | 7263 | goto error_ret_free_local; |
721956f4 AM |
7264 | |
7265 | /* Now examine each relocation. */ | |
7266 | irela = internal_relocs; | |
7267 | irelaend = irela + section->reloc_count; | |
7268 | for (; irela < irelaend; irela++) | |
7269 | { | |
4ce794b7 AM |
7270 | enum elf_ppc64_reloc_type r_type; |
7271 | unsigned int r_indx; | |
721956f4 AM |
7272 | enum ppc_stub_type stub_type; |
7273 | struct ppc_stub_hash_entry *stub_entry; | |
8387904d | 7274 | asection *sym_sec, *code_sec; |
721956f4 AM |
7275 | bfd_vma sym_value; |
7276 | bfd_vma destination; | |
8843416a | 7277 | bfd_boolean ok_dest; |
721956f4 | 7278 | struct ppc_link_hash_entry *hash; |
8387904d | 7279 | struct ppc_link_hash_entry *fdh; |
411e1bfb AM |
7280 | struct elf_link_hash_entry *h; |
7281 | Elf_Internal_Sym *sym; | |
721956f4 AM |
7282 | char *stub_name; |
7283 | const asection *id_sec; | |
8387904d | 7284 | long *opd_adjust; |
721956f4 AM |
7285 | |
7286 | r_type = ELF64_R_TYPE (irela->r_info); | |
7287 | r_indx = ELF64_R_SYM (irela->r_info); | |
7288 | ||
4ce794b7 | 7289 | if (r_type >= R_PPC64_max) |
721956f4 AM |
7290 | { |
7291 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 7292 | goto error_ret_free_internal; |
721956f4 AM |
7293 | } |
7294 | ||
7295 | /* Only look for stubs on branch instructions. */ | |
4ce794b7 AM |
7296 | if (r_type != R_PPC64_REL24 |
7297 | && r_type != R_PPC64_REL14 | |
7298 | && r_type != R_PPC64_REL14_BRTAKEN | |
7299 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
721956f4 AM |
7300 | continue; |
7301 | ||
7302 | /* Now determine the call target, its name, value, | |
7303 | section. */ | |
411e1bfb AM |
7304 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
7305 | r_indx, input_bfd)) | |
7306 | goto error_ret_free_internal; | |
7307 | hash = (struct ppc_link_hash_entry *) h; | |
7308 | ||
8843416a | 7309 | ok_dest = FALSE; |
8387904d | 7310 | fdh = NULL; |
411e1bfb | 7311 | if (hash == NULL) |
721956f4 | 7312 | { |
411e1bfb | 7313 | sym_value = sym->st_value; |
8843416a | 7314 | ok_dest = TRUE; |
721956f4 AM |
7315 | } |
7316 | else | |
7317 | { | |
411e1bfb | 7318 | sym_value = 0; |
99877b66 AM |
7319 | /* Recognise an old ABI func code entry sym, and |
7320 | use the func descriptor sym instead. */ | |
7321 | if (hash->elf.root.type == bfd_link_hash_undefweak | |
8387904d AM |
7322 | && hash->elf.root.root.string[0] == '.' |
7323 | && (fdh = get_fdh (hash, htab)) != NULL) | |
7324 | { | |
8387904d AM |
7325 | if (fdh->elf.root.type == bfd_link_hash_defined |
7326 | || fdh->elf.root.type == bfd_link_hash_defweak) | |
7327 | { | |
7328 | sym_sec = fdh->elf.root.u.def.section; | |
7329 | sym_value = fdh->elf.root.u.def.value; | |
7330 | if (sym_sec->output_section != NULL) | |
7331 | ok_dest = TRUE; | |
7332 | } | |
99877b66 AM |
7333 | else |
7334 | fdh = NULL; | |
8387904d AM |
7335 | } |
7336 | else if (hash->elf.root.type == bfd_link_hash_defined | |
7337 | || hash->elf.root.type == bfd_link_hash_defweak) | |
721956f4 | 7338 | { |
721956f4 AM |
7339 | sym_value = hash->elf.root.u.def.value; |
7340 | if (sym_sec->output_section != NULL) | |
8843416a | 7341 | ok_dest = TRUE; |
721956f4 AM |
7342 | } |
7343 | else if (hash->elf.root.type == bfd_link_hash_undefweak) | |
7344 | ; | |
7345 | else if (hash->elf.root.type == bfd_link_hash_undefined) | |
7346 | ; | |
7347 | else | |
7348 | { | |
7349 | bfd_set_error (bfd_error_bad_value); | |
7350 | goto error_ret_free_internal; | |
7351 | } | |
7352 | } | |
7353 | ||
8843416a AM |
7354 | destination = 0; |
7355 | if (ok_dest) | |
7356 | { | |
7357 | sym_value += irela->r_addend; | |
7358 | destination = (sym_value | |
7359 | + sym_sec->output_offset | |
7360 | + sym_sec->output_section->vma); | |
7361 | } | |
7362 | ||
8387904d AM |
7363 | code_sec = sym_sec; |
7364 | opd_adjust = get_opd_info (sym_sec); | |
7365 | if (opd_adjust != NULL) | |
7366 | { | |
7367 | bfd_vma dest; | |
7368 | ||
7369 | if (hash == NULL) | |
7370 | { | |
7371 | long adjust = opd_adjust[sym_value / 24]; | |
7372 | if (adjust == -1) | |
7373 | continue; | |
7374 | sym_value += adjust; | |
7375 | } | |
7376 | dest = opd_entry_value (sym_sec, sym_value, | |
7377 | &code_sec, &sym_value); | |
7378 | if (dest != (bfd_vma) -1) | |
7379 | { | |
7380 | destination = dest; | |
7381 | if (fdh != NULL) | |
7382 | { | |
7383 | /* Fixup old ABI sym to point at code | |
7384 | entry. */ | |
99877b66 | 7385 | hash->elf.root.type = bfd_link_hash_defweak; |
8387904d AM |
7386 | hash->elf.root.u.def.section = code_sec; |
7387 | hash->elf.root.u.def.value = sym_value; | |
7388 | } | |
7389 | } | |
7390 | } | |
7391 | ||
721956f4 AM |
7392 | /* Determine what (if any) linker stub is needed. */ |
7393 | stub_type = ppc_type_of_stub (section, irela, &hash, | |
7394 | destination); | |
ad8e1ba5 AM |
7395 | |
7396 | if (stub_type != ppc_stub_plt_call) | |
7397 | { | |
7398 | /* Check whether we need a TOC adjusting stub. | |
7399 | Since the linker pastes together pieces from | |
7400 | different object files when creating the | |
7401 | _init and _fini functions, it may be that a | |
7402 | call to what looks like a local sym is in | |
7403 | fact a call needing a TOC adjustment. */ | |
8387904d AM |
7404 | if (code_sec != NULL |
7405 | && code_sec->output_section != NULL | |
7406 | && (htab->stub_group[code_sec->id].toc_off | |
9b5ecbd0 | 7407 | != htab->stub_group[section->id].toc_off) |
8387904d | 7408 | && code_sec->has_gp_reloc |
9b5ecbd0 | 7409 | && section->has_gp_reloc) |
ad8e1ba5 AM |
7410 | stub_type = ppc_stub_long_branch_r2off; |
7411 | } | |
7412 | ||
721956f4 AM |
7413 | if (stub_type == ppc_stub_none) |
7414 | continue; | |
7415 | ||
411e1bfb AM |
7416 | /* __tls_get_addr calls might be eliminated. */ |
7417 | if (stub_type != ppc_stub_plt_call | |
7418 | && hash != NULL | |
8387904d AM |
7419 | && (hash == htab->tls_get_addr |
7420 | || hash == htab->tls_get_addr_fd) | |
411e1bfb AM |
7421 | && section->has_tls_reloc |
7422 | && irela != internal_relocs) | |
7423 | { | |
7424 | /* Get tls info. */ | |
e7b938ca | 7425 | char *tls_mask; |
411e1bfb | 7426 | |
0d4792f7 | 7427 | if (!get_tls_mask (&tls_mask, NULL, &local_syms, |
411e1bfb AM |
7428 | irela - 1, input_bfd)) |
7429 | goto error_ret_free_internal; | |
e7b938ca | 7430 | if (*tls_mask != 0) |
411e1bfb AM |
7431 | continue; |
7432 | } | |
7433 | ||
721956f4 AM |
7434 | /* Support for grouping stub sections. */ |
7435 | id_sec = htab->stub_group[section->id].link_sec; | |
7436 | ||
7437 | /* Get the name of this stub. */ | |
7438 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
7439 | if (!stub_name) | |
7440 | goto error_ret_free_internal; | |
7441 | ||
7442 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 7443 | stub_name, FALSE, FALSE); |
721956f4 AM |
7444 | if (stub_entry != NULL) |
7445 | { | |
7446 | /* The proper stub has already been created. */ | |
7447 | free (stub_name); | |
7448 | continue; | |
7449 | } | |
7450 | ||
7451 | stub_entry = ppc_add_stub (stub_name, section, htab); | |
7452 | if (stub_entry == NULL) | |
7453 | { | |
7454 | free (stub_name); | |
6cdc0ccc AM |
7455 | error_ret_free_internal: |
7456 | if (elf_section_data (section)->relocs == NULL) | |
7457 | free (internal_relocs); | |
7458 | error_ret_free_local: | |
7459 | if (local_syms != NULL | |
7460 | && (symtab_hdr->contents | |
7461 | != (unsigned char *) local_syms)) | |
7462 | free (local_syms); | |
b34976b6 | 7463 | return FALSE; |
721956f4 AM |
7464 | } |
7465 | ||
ad8e1ba5 | 7466 | stub_entry->stub_type = stub_type; |
721956f4 | 7467 | stub_entry->target_value = sym_value; |
8387904d | 7468 | stub_entry->target_section = code_sec; |
721956f4 | 7469 | stub_entry->h = hash; |
411e1bfb | 7470 | stub_entry->addend = irela->r_addend; |
b34976b6 | 7471 | stub_changed = TRUE; |
721956f4 AM |
7472 | } |
7473 | ||
7474 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 7475 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 7476 | free (internal_relocs); |
721956f4 | 7477 | } |
6cdc0ccc AM |
7478 | |
7479 | if (local_syms != NULL | |
7480 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
7481 | { | |
7482 | if (!info->keep_memory) | |
7483 | free (local_syms); | |
7484 | else | |
7485 | symtab_hdr->contents = (unsigned char *) local_syms; | |
7486 | } | |
721956f4 AM |
7487 | } |
7488 | ||
7489 | if (!stub_changed) | |
7490 | break; | |
7491 | ||
7492 | /* OK, we've added some stubs. Find out the new size of the | |
7493 | stub sections. */ | |
7494 | for (stub_sec = htab->stub_bfd->sections; | |
7495 | stub_sec != NULL; | |
7496 | stub_sec = stub_sec->next) | |
e717da7e | 7497 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
eea6121a AM |
7498 | stub_sec->size = 0; |
7499 | ||
7500 | htab->brlt->size = 0; | |
63bc6f6c | 7501 | if (info->shared) |
eea6121a | 7502 | htab->relbrlt->size = 0; |
721956f4 | 7503 | |
63bc6f6c | 7504 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info); |
721956f4 AM |
7505 | |
7506 | /* Ask the linker to do its stuff. */ | |
7507 | (*htab->layout_sections_again) (); | |
7508 | } | |
7509 | ||
afbe61cf AM |
7510 | /* It would be nice to strip .branch_lt from the output if the |
7511 | section is empty, but it's too late. If we strip sections here, | |
7512 | the dynamic symbol table is corrupted since the section symbol | |
7513 | for the stripped section isn't written. */ | |
721956f4 | 7514 | |
b34976b6 | 7515 | return TRUE; |
721956f4 AM |
7516 | } |
7517 | ||
7518 | /* Called after we have determined section placement. If sections | |
805fc799 | 7519 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 7520 | |
805fc799 | 7521 | bfd_vma |
4ce794b7 | 7522 | ppc64_elf_toc (bfd *obfd) |
721956f4 | 7523 | { |
805fc799 AM |
7524 | asection *s; |
7525 | bfd_vma TOCstart; | |
721956f4 | 7526 | |
805fc799 AM |
7527 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
7528 | order. The TOC starts where the first of these sections starts. */ | |
7529 | s = bfd_get_section_by_name (obfd, ".got"); | |
7530 | if (s == NULL) | |
7531 | s = bfd_get_section_by_name (obfd, ".toc"); | |
7532 | if (s == NULL) | |
7533 | s = bfd_get_section_by_name (obfd, ".tocbss"); | |
7534 | if (s == NULL) | |
7535 | s = bfd_get_section_by_name (obfd, ".plt"); | |
7536 | if (s == NULL) | |
7537 | { | |
7538 | /* This may happen for | |
7539 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
7540 | .toc directive | |
7541 | o bad linker script | |
7542 | o --gc-sections and empty TOC sections | |
7543 | ||
7544 | FIXME: Warn user? */ | |
7545 | ||
7546 | /* Look for a likely section. We probably won't even be | |
7547 | using TOCstart. */ | |
7548 | for (s = obfd->sections; s != NULL; s = s->next) | |
7549 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) | |
7550 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7551 | break; | |
721956f4 | 7552 | if (s == NULL) |
805fc799 AM |
7553 | for (s = obfd->sections; s != NULL; s = s->next) |
7554 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) | |
7555 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7556 | break; | |
721956f4 | 7557 | if (s == NULL) |
805fc799 AM |
7558 | for (s = obfd->sections; s != NULL; s = s->next) |
7559 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) | |
7560 | break; | |
721956f4 | 7561 | if (s == NULL) |
805fc799 AM |
7562 | for (s = obfd->sections; s != NULL; s = s->next) |
7563 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) | |
7564 | break; | |
7565 | } | |
721956f4 | 7566 | |
805fc799 AM |
7567 | TOCstart = 0; |
7568 | if (s != NULL) | |
7569 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 7570 | |
805fc799 | 7571 | return TOCstart; |
721956f4 AM |
7572 | } |
7573 | ||
7574 | /* Build all the stubs associated with the current output file. | |
7575 | The stubs are kept in a hash table attached to the main linker | |
7576 | hash table. This function is called via gldelf64ppc_finish. */ | |
7577 | ||
b34976b6 | 7578 | bfd_boolean |
4ce794b7 AM |
7579 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
7580 | struct bfd_link_info *info, | |
7581 | char **stats) | |
5d1634d7 AM |
7582 | { |
7583 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 7584 | asection *stub_sec; |
5d1634d7 | 7585 | bfd_byte *p; |
e717da7e | 7586 | int stub_sec_count = 0; |
5d1634d7 | 7587 | |
ad8e1ba5 | 7588 | htab->emit_stub_syms = emit_stub_syms; |
eea6121a AM |
7589 | |
7590 | /* Allocate memory to hold the linker stubs. */ | |
721956f4 AM |
7591 | for (stub_sec = htab->stub_bfd->sections; |
7592 | stub_sec != NULL; | |
7593 | stub_sec = stub_sec->next) | |
eea6121a AM |
7594 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0 |
7595 | && stub_sec->size != 0) | |
e717da7e | 7596 | { |
eea6121a AM |
7597 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size); |
7598 | if (stub_sec->contents == NULL) | |
7599 | return FALSE; | |
7600 | /* We want to check that built size is the same as calculated | |
7601 | size. rawsize is a convenient location to use. */ | |
7602 | stub_sec->rawsize = stub_sec->size; | |
7603 | stub_sec->size = 0; | |
e717da7e | 7604 | } |
5d1634d7 | 7605 | |
4ce794b7 | 7606 | if (htab->plt != NULL) |
5d1634d7 | 7607 | { |
9f951329 | 7608 | unsigned int indx; |
ad8e1ba5 | 7609 | bfd_vma plt0; |
9f951329 | 7610 | |
721956f4 | 7611 | /* Build the .glink plt call stub. */ |
4ce794b7 AM |
7612 | plt0 = (htab->plt->output_section->vma |
7613 | + htab->plt->output_offset | |
7614 | - (htab->glink->output_section->vma | |
7615 | + htab->glink->output_offset | |
ad8e1ba5 AM |
7616 | + GLINK_CALL_STUB_SIZE)); |
7617 | if (plt0 + 0x80008000 > 0xffffffff) | |
721956f4 | 7618 | { |
ad8e1ba5 AM |
7619 | (*_bfd_error_handler) (_(".glink and .plt too far apart")); |
7620 | bfd_set_error (bfd_error_bad_value); | |
7621 | return FALSE; | |
721956f4 | 7622 | } |
721956f4 | 7623 | |
97b639ba AM |
7624 | if (htab->emit_stub_syms) |
7625 | { | |
7626 | struct elf_link_hash_entry *h; | |
7627 | h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE); | |
7628 | if (h == NULL) | |
7629 | return FALSE; | |
7630 | if (h->root.type == bfd_link_hash_new) | |
7631 | { | |
7632 | h->root.type = bfd_link_hash_defined; | |
7633 | h->root.u.def.section = htab->glink; | |
7634 | h->root.u.def.value = 0; | |
7635 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
7636 | | ELF_LINK_HASH_DEF_REGULAR | |
7637 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
7638 | | ELF_LINK_FORCED_LOCAL); | |
7639 | } | |
7640 | } | |
4ce794b7 AM |
7641 | p = htab->glink->contents; |
7642 | bfd_put_32 (htab->glink->owner, MFCTR_R12, p); | |
ad8e1ba5 | 7643 | p += 4; |
4ce794b7 | 7644 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p); |
ad8e1ba5 | 7645 | p += 4; |
4ce794b7 | 7646 | bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p); |
ad8e1ba5 | 7647 | p += 4; |
4ce794b7 | 7648 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7649 | p += 4; |
4ce794b7 | 7650 | bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p); |
ad8e1ba5 | 7651 | p += 4; |
4ce794b7 | 7652 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p); |
ad8e1ba5 | 7653 | p += 4; |
4ce794b7 | 7654 | bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p); |
ad8e1ba5 | 7655 | p += 4; |
4ce794b7 | 7656 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7657 | p += 4; |
4ce794b7 | 7658 | bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p); |
ad8e1ba5 | 7659 | p += 4; |
4ce794b7 | 7660 | bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p); |
ad8e1ba5 | 7661 | p += 4; |
4ce794b7 | 7662 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7663 | p += 4; |
4ce794b7 | 7664 | bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7665 | p += 4; |
4ce794b7 | 7666 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
ad8e1ba5 | 7667 | p += 4; |
4ce794b7 | 7668 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
ad8e1ba5 | 7669 | p += 4; |
4ce794b7 | 7670 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
ad8e1ba5 | 7671 | p += 4; |
4ce794b7 | 7672 | bfd_put_32 (htab->glink->owner, BCTR, p); |
ad8e1ba5 AM |
7673 | p += 4; |
7674 | ||
9f951329 AM |
7675 | /* Build the .glink lazy link call stubs. */ |
7676 | indx = 0; | |
eea6121a | 7677 | while (p < htab->glink->contents + htab->glink->size) |
9f951329 AM |
7678 | { |
7679 | if (indx < 0x8000) | |
7680 | { | |
4ce794b7 | 7681 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
9f951329 AM |
7682 | p += 4; |
7683 | } | |
7684 | else | |
7685 | { | |
4ce794b7 | 7686 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
9f951329 | 7687 | p += 4; |
4ce794b7 | 7688 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
9f951329 AM |
7689 | p += 4; |
7690 | } | |
4ce794b7 AM |
7691 | bfd_put_32 (htab->glink->owner, |
7692 | B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p); | |
a16d5acb | 7693 | indx++; |
9f951329 AM |
7694 | p += 4; |
7695 | } | |
eea6121a | 7696 | htab->glink->rawsize = p - htab->glink->contents; |
5d1634d7 | 7697 | } |
5d1634d7 | 7698 | |
eea6121a | 7699 | if (htab->brlt->size != 0) |
721956f4 | 7700 | { |
4ce794b7 | 7701 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
eea6121a | 7702 | htab->brlt->size); |
4ce794b7 | 7703 | if (htab->brlt->contents == NULL) |
b34976b6 | 7704 | return FALSE; |
721956f4 | 7705 | } |
eea6121a | 7706 | if (info->shared && htab->relbrlt->size != 0) |
63bc6f6c AM |
7707 | { |
7708 | htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner, | |
eea6121a | 7709 | htab->relbrlt->size); |
63bc6f6c AM |
7710 | if (htab->relbrlt->contents == NULL) |
7711 | return FALSE; | |
7712 | } | |
5d1634d7 | 7713 | |
721956f4 AM |
7714 | /* Build the stubs as directed by the stub hash table. */ |
7715 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 7716 | |
721956f4 AM |
7717 | for (stub_sec = htab->stub_bfd->sections; |
7718 | stub_sec != NULL; | |
7719 | stub_sec = stub_sec->next) | |
e717da7e AM |
7720 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7721 | { | |
7722 | stub_sec_count += 1; | |
eea6121a | 7723 | if (stub_sec->rawsize != stub_sec->size) |
e717da7e AM |
7724 | break; |
7725 | } | |
5d1634d7 | 7726 | |
721956f4 | 7727 | if (stub_sec != NULL |
eea6121a | 7728 | || htab->glink->rawsize != htab->glink->size) |
5d1634d7 | 7729 | { |
b34976b6 | 7730 | htab->stub_error = TRUE; |
721956f4 | 7731 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
5d1634d7 | 7732 | } |
721956f4 | 7733 | |
d2a300cf AM |
7734 | if (htab->stub_error) |
7735 | return FALSE; | |
7736 | ||
7737 | if (stats != NULL) | |
7738 | { | |
7739 | *stats = bfd_malloc (500); | |
7740 | if (*stats == NULL) | |
7741 | return FALSE; | |
7742 | ||
7743 | sprintf (*stats, _("linker stubs in %u groups\n" | |
7744 | " branch %lu\n" | |
7745 | " toc adjust %lu\n" | |
7746 | " long branch %lu\n" | |
7747 | " long toc adj %lu\n" | |
7748 | " plt call %lu"), | |
e717da7e | 7749 | stub_sec_count, |
4ce794b7 AM |
7750 | htab->stub_count[ppc_stub_long_branch - 1], |
7751 | htab->stub_count[ppc_stub_long_branch_r2off - 1], | |
7752 | htab->stub_count[ppc_stub_plt_branch - 1], | |
7753 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], | |
7754 | htab->stub_count[ppc_stub_plt_call - 1]); | |
d2a300cf AM |
7755 | } |
7756 | return TRUE; | |
5bd4f169 AM |
7757 | } |
7758 | ||
99877b66 AM |
7759 | /* This function undoes the changes made by add_symbol_adjust. */ |
7760 | ||
7761 | static bfd_boolean | |
7762 | undo_symbol_twiddle (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
7763 | { | |
7764 | struct ppc_link_hash_entry *eh; | |
7765 | ||
7766 | if (h->root.type == bfd_link_hash_indirect) | |
7767 | return TRUE; | |
7768 | ||
7769 | if (h->root.type == bfd_link_hash_warning) | |
7770 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7771 | ||
7772 | eh = (struct ppc_link_hash_entry *) h; | |
7773 | if (eh->elf.root.type != bfd_link_hash_undefweak || !eh->was_undefined) | |
7774 | return TRUE; | |
7775 | ||
7776 | eh->elf.root.type = bfd_link_hash_undefined; | |
7777 | return TRUE; | |
7778 | } | |
7779 | ||
7780 | void | |
7781 | ppc64_elf_restore_symbols (struct bfd_link_info *info) | |
7782 | { | |
7783 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
7784 | elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info); | |
7785 | } | |
7786 | ||
5bd4f169 AM |
7787 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
7788 | to handle the relocations for a section. | |
7789 | ||
7790 | The relocs are always passed as Rela structures; if the section | |
7791 | actually uses Rel structures, the r_addend field will always be | |
7792 | zero. | |
7793 | ||
7794 | This function is responsible for adjust the section contents as | |
7795 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 7796 | relocatable output file) adjusting the reloc addend as |
5bd4f169 AM |
7797 | necessary. |
7798 | ||
7799 | This function does not have to worry about setting the reloc | |
7800 | address or the reloc symbol index. | |
7801 | ||
7802 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
7803 | ||
7804 | LOCAL_SECTIONS is an array giving the section in the input file | |
7805 | corresponding to the st_shndx field of each local symbol. | |
7806 | ||
7807 | The global hash table entry for the global symbols can be found | |
7808 | via elf_sym_hashes (input_bfd). | |
7809 | ||
1049f94e | 7810 | When generating relocatable output, this function must handle |
5bd4f169 AM |
7811 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
7812 | going to be the section symbol corresponding to the output | |
7813 | section, which means that the addend must be adjusted | |
7814 | accordingly. */ | |
7815 | ||
b34976b6 | 7816 | static bfd_boolean |
4ce794b7 AM |
7817 | ppc64_elf_relocate_section (bfd *output_bfd, |
7818 | struct bfd_link_info *info, | |
7819 | bfd *input_bfd, | |
7820 | asection *input_section, | |
7821 | bfd_byte *contents, | |
7822 | Elf_Internal_Rela *relocs, | |
7823 | Elf_Internal_Sym *local_syms, | |
7824 | asection **local_sections) | |
5bd4f169 | 7825 | { |
65f38f15 | 7826 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
7827 | Elf_Internal_Shdr *symtab_hdr; |
7828 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
7829 | Elf_Internal_Rela *rel; |
7830 | Elf_Internal_Rela *relend; | |
411e1bfb AM |
7831 | Elf_Internal_Rela outrel; |
7832 | bfd_byte *loc; | |
411e1bfb | 7833 | struct got_entry **local_got_ents; |
5bd4f169 | 7834 | bfd_vma TOCstart; |
b34976b6 AM |
7835 | bfd_boolean ret = TRUE; |
7836 | bfd_boolean is_opd; | |
96e0dda4 | 7837 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 7838 | bfd_boolean is_power4 = FALSE; |
5bd4f169 | 7839 | |
1049f94e | 7840 | if (info->relocatable) |
b34976b6 | 7841 | return TRUE; |
b491616a | 7842 | |
65f38f15 | 7843 | /* Initialize howto table if needed. */ |
5bd4f169 | 7844 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
7845 | ppc_howto_init (); |
7846 | ||
65f38f15 | 7847 | htab = ppc_hash_table (info); |
411e1bfb | 7848 | local_got_ents = elf_local_got_ents (input_bfd); |
5bd4f169 | 7849 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
7850 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
7851 | sym_hashes = elf_sym_hashes (input_bfd); | |
f0abc2a1 | 7852 | is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL; |
65f38f15 | 7853 | |
5bd4f169 AM |
7854 | rel = relocs; |
7855 | relend = relocs + input_section->reloc_count; | |
7856 | for (; rel < relend; rel++) | |
7857 | { | |
04c9666a | 7858 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 AM |
7859 | bfd_vma addend; |
7860 | bfd_reloc_status_type r; | |
7861 | Elf_Internal_Sym *sym; | |
7862 | asection *sec; | |
7863 | struct elf_link_hash_entry *h; | |
721956f4 | 7864 | struct elf_link_hash_entry *fdh; |
5bd4f169 | 7865 | const char *sym_name; |
0d4792f7 | 7866 | unsigned long r_symndx, toc_symndx; |
951fd09b | 7867 | char tls_mask, tls_gd, tls_type; |
0d4792f7 | 7868 | char sym_type; |
5bd4f169 | 7869 | bfd_vma relocation; |
b34976b6 AM |
7870 | bfd_boolean unresolved_reloc; |
7871 | bfd_boolean warned; | |
50bc7936 | 7872 | unsigned long insn, mask; |
721956f4 AM |
7873 | struct ppc_stub_hash_entry *stub_entry; |
7874 | bfd_vma max_br_offset; | |
7875 | bfd_vma from; | |
5bd4f169 | 7876 | |
4ce794b7 | 7877 | r_type = ELF64_R_TYPE (rel->r_info); |
5bd4f169 | 7878 | r_symndx = ELF64_R_SYM (rel->r_info); |
ee87f2da AM |
7879 | |
7880 | /* For old style R_PPC64_TOC relocs with a zero symbol, use the | |
7881 | symbol of the previous ADDR64 reloc. The symbol gives us the | |
7882 | proper TOC base to use. */ | |
7883 | if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC) | |
7884 | && rel != relocs | |
7885 | && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64 | |
7886 | && is_opd) | |
7887 | r_symndx = ELF64_R_SYM (rel[-1].r_info); | |
7888 | ||
4ce794b7 AM |
7889 | sym = NULL; |
7890 | sec = NULL; | |
7891 | h = NULL; | |
7892 | sym_name = NULL; | |
b34976b6 AM |
7893 | unresolved_reloc = FALSE; |
7894 | warned = FALSE; | |
65f38f15 | 7895 | |
0b13192e | 7896 | if (r_symndx < symtab_hdr->sh_info) |
5bd4f169 AM |
7897 | { |
7898 | /* It's a local symbol. */ | |
4025353c AM |
7899 | long *opd_adjust; |
7900 | ||
5bd4f169 AM |
7901 | sym = local_syms + r_symndx; |
7902 | sec = local_sections[r_symndx]; | |
411e1bfb | 7903 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
0d4792f7 | 7904 | sym_type = ELF64_ST_TYPE (sym->st_info); |
8517fae7 | 7905 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
4025353c AM |
7906 | opd_adjust = get_opd_info (sec); |
7907 | if (opd_adjust != NULL) | |
1e2f5b6e | 7908 | { |
4025353c AM |
7909 | long adjust = opd_adjust[(sym->st_value + rel->r_addend) / 24]; |
7910 | if (adjust == -1) | |
7911 | relocation = 0; | |
7912 | else | |
7913 | relocation += adjust; | |
1e2f5b6e | 7914 | } |
5bd4f169 AM |
7915 | } |
7916 | else | |
7917 | { | |
b2a8e766 AM |
7918 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
7919 | r_symndx, symtab_hdr, sym_hashes, | |
7920 | h, sec, relocation, | |
7921 | unresolved_reloc, warned); | |
5bd4f169 | 7922 | sym_name = h->root.root.string; |
0d4792f7 | 7923 | sym_type = h->type; |
5bd4f169 AM |
7924 | } |
7925 | ||
951fd09b AM |
7926 | /* TLS optimizations. Replace instruction sequences and relocs |
7927 | based on information we collected in tls_optimize. We edit | |
7928 | RELOCS so that --emit-relocs will output something sensible | |
7929 | for the final instruction stream. */ | |
7930 | tls_mask = 0; | |
7931 | tls_gd = 0; | |
0d4792f7 | 7932 | toc_symndx = 0; |
d881513a | 7933 | if (IS_PPC64_TLS_RELOC (r_type)) |
411e1bfb AM |
7934 | { |
7935 | if (h != NULL) | |
e7b938ca | 7936 | tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask; |
411e1bfb AM |
7937 | else if (local_got_ents != NULL) |
7938 | { | |
e7b938ca AM |
7939 | char *lgot_masks; |
7940 | lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); | |
7941 | tls_mask = lgot_masks[r_symndx]; | |
411e1bfb | 7942 | } |
0d4792f7 AM |
7943 | if (tls_mask == 0 && r_type == R_PPC64_TLS) |
7944 | { | |
7945 | /* Check for toc tls entries. */ | |
7946 | char *toc_tls; | |
7947 | ||
7948 | if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms, | |
7949 | rel, input_bfd)) | |
7950 | return FALSE; | |
7951 | ||
7952 | if (toc_tls) | |
7953 | tls_mask = *toc_tls; | |
7954 | } | |
7955 | } | |
7956 | ||
7957 | /* Check that tls relocs are used with tls syms, and non-tls | |
7958 | relocs are used with non-tls syms. */ | |
7959 | if (r_symndx != 0 | |
7960 | && r_type != R_PPC64_NONE | |
7961 | && (h == NULL | |
7962 | || h->root.type == bfd_link_hash_defined | |
7963 | || h->root.type == bfd_link_hash_defweak) | |
7964 | && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
7965 | { | |
7966 | if (r_type == R_PPC64_TLS && tls_mask != 0) | |
7967 | /* R_PPC64_TLS is OK against a symbol in the TOC. */ | |
7968 | ; | |
7969 | else | |
7970 | (*_bfd_error_handler) | |
7971 | (sym_type == STT_TLS | |
d003868e AM |
7972 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") |
7973 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"), | |
7974 | input_bfd, | |
7975 | input_section, | |
0d4792f7 AM |
7976 | (long) rel->r_offset, |
7977 | ppc64_elf_howto_table[r_type]->name, | |
7978 | sym_name); | |
411e1bfb AM |
7979 | } |
7980 | ||
7981 | /* Ensure reloc mapping code below stays sane. */ | |
7982 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 | |
7983 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 | |
7984 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) | |
7985 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) | |
7986 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) | |
7987 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) | |
7988 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) | |
7989 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) | |
7990 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) | |
7991 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) | |
7992 | abort (); | |
0d4792f7 | 7993 | |
411e1bfb AM |
7994 | switch (r_type) |
7995 | { | |
7996 | default: | |
411e1bfb AM |
7997 | break; |
7998 | ||
7999 | case R_PPC64_TOC16: | |
8000 | case R_PPC64_TOC16_LO: | |
8001 | case R_PPC64_TOC16_DS: | |
8002 | case R_PPC64_TOC16_LO_DS: | |
411e1bfb AM |
8003 | { |
8004 | /* Check for toc tls entries. */ | |
8005 | char *toc_tls; | |
951fd09b | 8006 | int retval; |
411e1bfb | 8007 | |
0d4792f7 AM |
8008 | retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms, |
8009 | rel, input_bfd); | |
951fd09b | 8010 | if (retval == 0) |
411e1bfb AM |
8011 | return FALSE; |
8012 | ||
8013 | if (toc_tls) | |
8014 | { | |
951fd09b | 8015 | tls_mask = *toc_tls; |
411e1bfb AM |
8016 | if (r_type == R_PPC64_TOC16_DS |
8017 | || r_type == R_PPC64_TOC16_LO_DS) | |
81407a69 AM |
8018 | { |
8019 | if (tls_mask != 0 | |
8020 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) | |
8021 | goto toctprel; | |
8022 | } | |
411e1bfb | 8023 | else |
951fd09b AM |
8024 | { |
8025 | /* If we found a GD reloc pair, then we might be | |
8026 | doing a GD->IE transition. */ | |
8027 | if (retval == 2) | |
8028 | { | |
8029 | tls_gd = TLS_TPRELGD; | |
8030 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
8031 | goto tls_get_addr_check; | |
8032 | } | |
8033 | else if (retval == 3) | |
8034 | { | |
8035 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
8036 | goto tls_get_addr_check; | |
8037 | } | |
8038 | } | |
411e1bfb AM |
8039 | } |
8040 | } | |
8041 | break; | |
8042 | ||
8043 | case R_PPC64_GOT_TPREL16_DS: | |
8044 | case R_PPC64_GOT_TPREL16_LO_DS: | |
951fd09b AM |
8045 | if (tls_mask != 0 |
8046 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 8047 | { |
81407a69 | 8048 | toctprel: |
411e1bfb AM |
8049 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); |
8050 | insn &= 31 << 21; | |
8051 | insn |= 0x3c0d0000; /* addis 0,13,0 */ | |
8052 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
8053 | r_type = R_PPC64_TPREL16_HA; | |
0d4792f7 AM |
8054 | if (toc_symndx != 0) |
8055 | { | |
8056 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
8057 | /* We changed the symbol. Start over in order to | |
8058 | get h, sym, sec etc. right. */ | |
8059 | rel--; | |
8060 | continue; | |
8061 | } | |
8062 | else | |
8063 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
8064 | } |
8065 | break; | |
8066 | ||
8067 | case R_PPC64_TLS: | |
951fd09b AM |
8068 | if (tls_mask != 0 |
8069 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 8070 | { |
50bc7936 | 8071 | bfd_vma rtra; |
411e1bfb | 8072 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
772119ce | 8073 | if ((insn & ((0x3f << 26) | (31 << 11))) |
411e1bfb AM |
8074 | == ((31 << 26) | (13 << 11))) |
8075 | rtra = insn & ((1 << 26) - (1 << 16)); | |
772119ce | 8076 | else if ((insn & ((0x3f << 26) | (31 << 16))) |
411e1bfb AM |
8077 | == ((31 << 26) | (13 << 16))) |
8078 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
8079 | else | |
8080 | abort (); | |
8081 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
8082 | /* add -> addi. */ | |
8083 | insn = 14 << 26; | |
8084 | else if ((insn & (31 << 1)) == 23 << 1 | |
8085 | && ((insn & (31 << 6)) < 14 << 6 | |
8086 | || ((insn & (31 << 6)) >= 16 << 6 | |
8087 | && (insn & (31 << 6)) < 24 << 6))) | |
8088 | /* load and store indexed -> dform. */ | |
8089 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
8090 | else if ((insn & (31 << 1)) == 21 << 1 | |
8091 | && (insn & (0x1a << 6)) == 0) | |
8092 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
8093 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
8094 | | ((insn >> 6) & 1)); | |
8095 | else if ((insn & (31 << 1)) == 21 << 1 | |
8096 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
8097 | /* lwax -> lwa. */ | |
8098 | insn = (58 << 26) | 2; | |
8099 | else | |
8100 | abort (); | |
8101 | insn |= rtra; | |
8102 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
411e1bfb AM |
8103 | /* Was PPC64_TLS which sits on insn boundary, now |
8104 | PPC64_TPREL16_LO which is at insn+2. */ | |
8105 | rel->r_offset += 2; | |
0d4792f7 AM |
8106 | r_type = R_PPC64_TPREL16_LO; |
8107 | if (toc_symndx != 0) | |
8108 | { | |
8109 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
8110 | /* We changed the symbol. Start over in order to | |
8111 | get h, sym, sec etc. right. */ | |
8112 | rel--; | |
8113 | continue; | |
8114 | } | |
8115 | else | |
8116 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
8117 | } |
8118 | break; | |
8119 | ||
411e1bfb AM |
8120 | case R_PPC64_GOT_TLSGD16_HI: |
8121 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b AM |
8122 | tls_gd = TLS_TPRELGD; |
8123 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
8124 | goto tls_gdld_hi; | |
8125 | break; | |
8126 | ||
411e1bfb AM |
8127 | case R_PPC64_GOT_TLSLD16_HI: |
8128 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 8129 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
411e1bfb | 8130 | { |
951fd09b AM |
8131 | tls_gdld_hi: |
8132 | if ((tls_mask & tls_gd) != 0) | |
8133 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
8134 | + R_PPC64_GOT_TPREL16_DS); | |
8135 | else | |
411e1bfb | 8136 | { |
951fd09b AM |
8137 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
8138 | rel->r_offset -= 2; | |
8139 | r_type = R_PPC64_NONE; | |
411e1bfb | 8140 | } |
951fd09b | 8141 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb AM |
8142 | } |
8143 | break; | |
8144 | ||
951fd09b AM |
8145 | case R_PPC64_GOT_TLSGD16: |
8146 | case R_PPC64_GOT_TLSGD16_LO: | |
8147 | tls_gd = TLS_TPRELGD; | |
8148 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
8149 | goto tls_get_addr_check; | |
8150 | break; | |
411e1bfb | 8151 | |
951fd09b AM |
8152 | case R_PPC64_GOT_TLSLD16: |
8153 | case R_PPC64_GOT_TLSLD16_LO: | |
8154 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
8155 | { | |
8156 | tls_get_addr_check: | |
8157 | if (rel + 1 < relend) | |
411e1bfb | 8158 | { |
951fd09b AM |
8159 | enum elf_ppc64_reloc_type r_type2; |
8160 | unsigned long r_symndx2; | |
8161 | struct elf_link_hash_entry *h2; | |
8162 | bfd_vma insn1, insn2, insn3; | |
8163 | bfd_vma offset; | |
8164 | ||
8165 | /* The next instruction should be a call to | |
8166 | __tls_get_addr. Peek at the reloc to be sure. */ | |
4ce794b7 | 8167 | r_type2 = ELF64_R_TYPE (rel[1].r_info); |
951fd09b AM |
8168 | r_symndx2 = ELF64_R_SYM (rel[1].r_info); |
8169 | if (r_symndx2 < symtab_hdr->sh_info | |
8170 | || (r_type2 != R_PPC64_REL14 | |
8171 | && r_type2 != R_PPC64_REL14_BRTAKEN | |
8172 | && r_type2 != R_PPC64_REL14_BRNTAKEN | |
8173 | && r_type2 != R_PPC64_REL24)) | |
8174 | break; | |
8175 | ||
8176 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
8177 | while (h2->root.type == bfd_link_hash_indirect | |
8178 | || h2->root.type == bfd_link_hash_warning) | |
8179 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
8387904d AM |
8180 | if (h2 == NULL || (h2 != &htab->tls_get_addr->elf |
8181 | && h2 != &htab->tls_get_addr_fd->elf)) | |
951fd09b AM |
8182 | break; |
8183 | ||
8184 | /* OK, it checks out. Replace the call. */ | |
8185 | offset = rel[1].r_offset; | |
8186 | insn1 = bfd_get_32 (output_bfd, | |
8187 | contents + rel->r_offset - 2); | |
8188 | insn3 = bfd_get_32 (output_bfd, | |
8189 | contents + offset + 4); | |
8190 | if ((tls_mask & tls_gd) != 0) | |
411e1bfb | 8191 | { |
951fd09b AM |
8192 | /* IE */ |
8193 | insn1 &= (1 << 26) - (1 << 2); | |
8194 | insn1 |= 58 << 26; /* ld */ | |
8195 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
8196 | rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); | |
8197 | if ((tls_mask & TLS_EXPLICIT) == 0) | |
8198 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
8199 | + R_PPC64_GOT_TPREL16_DS); | |
8200 | else | |
8201 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; | |
8202 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
8203 | } |
8204 | else | |
951fd09b AM |
8205 | { |
8206 | /* LE */ | |
8207 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ | |
8208 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
8209 | if (tls_gd == 0) | |
8210 | { | |
8211 | /* Was an LD reloc. */ | |
8212 | r_symndx = 0; | |
e1918d23 AM |
8213 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
8214 | rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; | |
951fd09b | 8215 | } |
0d4792f7 AM |
8216 | else if (toc_symndx != 0) |
8217 | r_symndx = toc_symndx; | |
951fd09b AM |
8218 | r_type = R_PPC64_TPREL16_HA; |
8219 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
8220 | rel[1].r_info = ELF64_R_INFO (r_symndx, | |
8221 | R_PPC64_TPREL16_LO); | |
8222 | rel[1].r_offset += 2; | |
8223 | } | |
8224 | if (insn3 == NOP | |
8225 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
8226 | { | |
8227 | insn3 = insn2; | |
8228 | insn2 = NOP; | |
8229 | rel[1].r_offset += 4; | |
8230 | } | |
8231 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); | |
8232 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
8233 | bfd_put_32 (output_bfd, insn3, contents + offset + 4); | |
0d4792f7 | 8234 | if (tls_gd == 0 || toc_symndx != 0) |
951fd09b | 8235 | { |
0d4792f7 AM |
8236 | /* We changed the symbol. Start over in order |
8237 | to get h, sym, sec etc. right. */ | |
951fd09b AM |
8238 | rel--; |
8239 | continue; | |
8240 | } | |
411e1bfb | 8241 | } |
411e1bfb | 8242 | } |
411e1bfb AM |
8243 | break; |
8244 | ||
8245 | case R_PPC64_DTPMOD64: | |
951fd09b AM |
8246 | if (rel + 1 < relend |
8247 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
8248 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 8249 | { |
951fd09b AM |
8250 | if ((tls_mask & TLS_GD) == 0) |
8251 | { | |
8252 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); | |
8253 | if ((tls_mask & TLS_TPRELGD) != 0) | |
8254 | r_type = R_PPC64_TPREL64; | |
8255 | else | |
8256 | { | |
4ce794b7 | 8257 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
951fd09b AM |
8258 | r_type = R_PPC64_NONE; |
8259 | } | |
8260 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
8261 | } | |
8262 | } | |
8263 | else | |
8264 | { | |
8265 | if ((tls_mask & TLS_LD) == 0) | |
411e1bfb | 8266 | { |
4ce794b7 | 8267 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
411e1bfb | 8268 | r_type = R_PPC64_NONE; |
951fd09b | 8269 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb | 8270 | } |
411e1bfb AM |
8271 | } |
8272 | break; | |
8273 | ||
8274 | case R_PPC64_TPREL64: | |
951fd09b | 8275 | if ((tls_mask & TLS_TPREL) == 0) |
411e1bfb AM |
8276 | { |
8277 | r_type = R_PPC64_NONE; | |
8278 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
8279 | } | |
8280 | break; | |
8281 | } | |
8282 | ||
8283 | /* Handle other relocations that tweak non-addend part of insn. */ | |
86c76c7b | 8284 | insn = 0; |
b25116a9 AM |
8285 | max_br_offset = 1 << 25; |
8286 | addend = rel->r_addend; | |
65f38f15 | 8287 | switch (r_type) |
5bd4f169 AM |
8288 | { |
8289 | default: | |
65f38f15 | 8290 | break; |
5bd4f169 | 8291 | |
65f38f15 AM |
8292 | /* Branch taken prediction relocations. */ |
8293 | case R_PPC64_ADDR14_BRTAKEN: | |
8294 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
8295 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
8296 | /* Fall thru. */ | |
65f38f15 | 8297 | |
86c76c7b | 8298 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
8299 | case R_PPC64_ADDR14_BRNTAKEN: |
8300 | case R_PPC64_REL14_BRNTAKEN: | |
411e1bfb AM |
8301 | insn |= bfd_get_32 (output_bfd, |
8302 | contents + rel->r_offset) & ~(0x01 << 21); | |
b25116a9 | 8303 | /* Fall thru. */ |
86c76c7b | 8304 | |
b25116a9 AM |
8305 | case R_PPC64_REL14: |
8306 | max_br_offset = 1 << 15; | |
8307 | /* Fall thru. */ | |
5bd4f169 | 8308 | |
65f38f15 | 8309 | case R_PPC64_REL24: |
ad8e1ba5 AM |
8310 | /* Calls to functions with a different TOC, such as calls to |
8311 | shared objects, need to alter the TOC pointer. This is | |
8312 | done using a linkage stub. A REL24 branching to these | |
8313 | linkage stubs needs to be followed by a nop, as the nop | |
8314 | will be replaced with an instruction to restore the TOC | |
8315 | base pointer. */ | |
b25116a9 | 8316 | stub_entry = NULL; |
8387904d | 8317 | fdh = h; |
ad8e1ba5 | 8318 | if (((h != NULL |
8387904d AM |
8319 | && (((fdh = &((struct ppc_link_hash_entry *) h)->oh->elf) != NULL |
8320 | && fdh->plt.plist != NULL) | |
8321 | || (fdh = h)->plt.plist != NULL)) | |
8322 | || (sec != NULL | |
ad8e1ba5 | 8323 | && sec->output_section != NULL |
b25116a9 | 8324 | && sec->id <= htab->top_id |
ad8e1ba5 AM |
8325 | && (htab->stub_group[sec->id].toc_off |
8326 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 | 8327 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, |
ad8e1ba5 AM |
8328 | rel, htab)) != NULL |
8329 | && (stub_entry->stub_type == ppc_stub_plt_call | |
8330 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off | |
8331 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) | |
41bd81ab | 8332 | { |
b25116a9 | 8333 | bfd_boolean can_plt_call = FALSE; |
721956f4 | 8334 | |
eea6121a | 8335 | if (rel->r_offset + 8 <= input_section->size) |
41bd81ab | 8336 | { |
b25116a9 AM |
8337 | unsigned long nop; |
8338 | nop = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); | |
8339 | if (nop == NOP | |
8340 | || nop == CROR_151515 || nop == CROR_313131) | |
41bd81ab | 8341 | { |
4ce794b7 | 8342 | bfd_put_32 (input_bfd, LD_R2_40R1, |
411e1bfb | 8343 | contents + rel->r_offset + 4); |
b25116a9 | 8344 | can_plt_call = TRUE; |
41bd81ab | 8345 | } |
5bd4f169 | 8346 | } |
721956f4 AM |
8347 | |
8348 | if (!can_plt_call) | |
8349 | { | |
ad8e1ba5 AM |
8350 | if (stub_entry->stub_type == ppc_stub_plt_call) |
8351 | { | |
8352 | /* If this is a plain branch rather than a branch | |
8353 | and link, don't require a nop. */ | |
b25116a9 AM |
8354 | unsigned long br; |
8355 | br = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
8356 | if ((br & 1) == 0) | |
8357 | can_plt_call = TRUE; | |
ad8e1ba5 | 8358 | } |
6ab189d5 AM |
8359 | else if (h != NULL |
8360 | && strcmp (h->root.root.string, | |
8361 | ".__libc_start_main") == 0) | |
8362 | { | |
8363 | /* Allow crt1 branch to go via a toc adjusting stub. */ | |
b25116a9 | 8364 | can_plt_call = TRUE; |
6ab189d5 | 8365 | } |
ad8e1ba5 AM |
8366 | else |
8367 | { | |
8368 | if (strcmp (input_section->output_section->name, | |
8369 | ".init") == 0 | |
8370 | || strcmp (input_section->output_section->name, | |
8371 | ".fini") == 0) | |
8372 | (*_bfd_error_handler) | |
d003868e | 8373 | (_("%B(%A+0x%lx): automatic multiple TOCs " |
ad8e1ba5 AM |
8374 | "not supported using your crt files; " |
8375 | "recompile with -mminimal-toc or upgrade gcc"), | |
d003868e AM |
8376 | input_bfd, |
8377 | input_section, | |
ad8e1ba5 AM |
8378 | (long) rel->r_offset); |
8379 | else | |
8380 | (*_bfd_error_handler) | |
d003868e | 8381 | (_("%B(%A+0x%lx): sibling call optimization to `%s' " |
ad8e1ba5 AM |
8382 | "does not allow automatic multiple TOCs; " |
8383 | "recompile with -mminimal-toc or " | |
8384 | "-fno-optimize-sibling-calls, " | |
8385 | "or make `%s' extern"), | |
d003868e AM |
8386 | input_bfd, |
8387 | input_section, | |
ad8e1ba5 AM |
8388 | (long) rel->r_offset, |
8389 | sym_name, | |
8390 | sym_name); | |
8391 | bfd_set_error (bfd_error_bad_value); | |
8392 | ret = FALSE; | |
8393 | } | |
721956f4 AM |
8394 | } |
8395 | ||
b25116a9 AM |
8396 | if (can_plt_call |
8397 | && stub_entry->stub_type == ppc_stub_plt_call) | |
8398 | unresolved_reloc = FALSE; | |
8399 | } | |
8400 | ||
8387904d AM |
8401 | if (stub_entry == NULL |
8402 | && get_opd_info (sec) != NULL) | |
8403 | { | |
8404 | /* The branch destination is the value of the opd entry. */ | |
8405 | bfd_vma off = (relocation - sec->output_section->vma | |
8406 | - sec->output_offset + rel->r_addend); | |
8407 | bfd_vma dest = opd_entry_value (sec, off, NULL, NULL); | |
8408 | if (dest != (bfd_vma) -1) | |
8409 | { | |
8410 | relocation = dest; | |
8411 | addend = 0; | |
8412 | } | |
8413 | } | |
8414 | ||
b25116a9 AM |
8415 | /* If the branch is out of reach we ought to have a long |
8416 | branch stub. */ | |
8417 | from = (rel->r_offset | |
8418 | + input_section->output_offset | |
8419 | + input_section->output_section->vma); | |
8420 | ||
8421 | if (stub_entry == NULL | |
8422 | && (relocation + rel->r_addend - from + max_br_offset | |
8423 | >= 2 * max_br_offset) | |
8424 | && r_type != R_PPC64_ADDR14_BRTAKEN | |
8425 | && r_type != R_PPC64_ADDR14_BRNTAKEN) | |
8426 | stub_entry = ppc_get_stub_entry (input_section, sec, h, rel, htab); | |
8427 | ||
8428 | if (stub_entry != NULL) | |
8429 | { | |
8430 | /* Munge up the value and addend so that we call the stub | |
8431 | rather than the procedure directly. */ | |
8432 | relocation = (stub_entry->stub_offset | |
8433 | + stub_entry->stub_sec->output_offset | |
8434 | + stub_entry->stub_sec->output_section->vma); | |
8435 | addend = 0; | |
8436 | } | |
8437 | ||
8438 | if (insn != 0) | |
8439 | { | |
8440 | if (is_power4) | |
721956f4 | 8441 | { |
b25116a9 AM |
8442 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
8443 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
8444 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
8445 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
8446 | insn |= 0x02 << 21; | |
8447 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
8448 | insn |= 0x08 << 21; | |
8449 | else | |
8450 | break; | |
8451 | } | |
8452 | else | |
8453 | { | |
8454 | /* Invert 'y' bit if not the default. */ | |
8455 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
8456 | insn ^= 0x01 << 21; | |
721956f4 | 8457 | } |
b25116a9 AM |
8458 | |
8459 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
5bd4f169 | 8460 | } |
e86ce104 | 8461 | |
06da1e8e AM |
8462 | /* NOP out calls to undefined weak functions. |
8463 | We can thus call a weak function without first | |
8464 | checking whether the function is defined. */ | |
b25116a9 AM |
8465 | else if (h != NULL |
8466 | && h->root.type == bfd_link_hash_undefweak | |
8467 | && r_type == R_PPC64_REL24 | |
8468 | && relocation == 0 | |
8469 | && rel->r_addend == 0) | |
e86ce104 | 8470 | { |
06da1e8e AM |
8471 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
8472 | continue; | |
e86ce104 | 8473 | } |
65f38f15 AM |
8474 | break; |
8475 | } | |
5bd4f169 | 8476 | |
65f38f15 | 8477 | /* Set `addend'. */ |
411e1bfb | 8478 | tls_type = 0; |
65f38f15 AM |
8479 | switch (r_type) |
8480 | { | |
8481 | default: | |
8482 | (*_bfd_error_handler) | |
d003868e AM |
8483 | (_("%B: unknown relocation type %d for symbol %s"), |
8484 | input_bfd, (int) r_type, sym_name); | |
5bd4f169 | 8485 | |
65f38f15 | 8486 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 8487 | ret = FALSE; |
65f38f15 | 8488 | continue; |
5bd4f169 | 8489 | |
65f38f15 | 8490 | case R_PPC64_NONE: |
411e1bfb | 8491 | case R_PPC64_TLS: |
04c9666a AM |
8492 | case R_PPC64_GNU_VTINHERIT: |
8493 | case R_PPC64_GNU_VTENTRY: | |
65f38f15 | 8494 | continue; |
5bd4f169 AM |
8495 | |
8496 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
8497 | address in the GOT as relocation value instead of the | |
411e1bfb | 8498 | symbol's value itself. Also, create a GOT entry for the |
5bd4f169 | 8499 | symbol and put the symbol value there. */ |
411e1bfb AM |
8500 | case R_PPC64_GOT_TLSGD16: |
8501 | case R_PPC64_GOT_TLSGD16_LO: | |
8502 | case R_PPC64_GOT_TLSGD16_HI: | |
8503 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 8504 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
8505 | goto dogot; |
8506 | ||
8507 | case R_PPC64_GOT_TLSLD16: | |
8508 | case R_PPC64_GOT_TLSLD16_LO: | |
8509 | case R_PPC64_GOT_TLSLD16_HI: | |
8510 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 8511 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
8512 | goto dogot; |
8513 | ||
8514 | case R_PPC64_GOT_TPREL16_DS: | |
8515 | case R_PPC64_GOT_TPREL16_LO_DS: | |
8516 | case R_PPC64_GOT_TPREL16_HI: | |
8517 | case R_PPC64_GOT_TPREL16_HA: | |
8518 | tls_type = TLS_TLS | TLS_TPREL; | |
8519 | goto dogot; | |
8520 | ||
8521 | case R_PPC64_GOT_DTPREL16_DS: | |
8522 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
8523 | case R_PPC64_GOT_DTPREL16_HI: | |
8524 | case R_PPC64_GOT_DTPREL16_HA: | |
8525 | tls_type = TLS_TLS | TLS_DTPREL; | |
8526 | goto dogot; | |
8527 | ||
65f38f15 AM |
8528 | case R_PPC64_GOT16: |
8529 | case R_PPC64_GOT16_LO: | |
8530 | case R_PPC64_GOT16_HI: | |
8531 | case R_PPC64_GOT16_HA: | |
8532 | case R_PPC64_GOT16_DS: | |
8533 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb | 8534 | dogot: |
5bd4f169 AM |
8535 | { |
8536 | /* Relocation is to the entry for this symbol in the global | |
8537 | offset table. */ | |
e717da7e | 8538 | asection *got; |
d881513a | 8539 | bfd_vma *offp; |
5bd4f169 | 8540 | bfd_vma off; |
d881513a | 8541 | unsigned long indx = 0; |
65f38f15 | 8542 | |
d881513a AM |
8543 | if (tls_type == (TLS_TLS | TLS_LD) |
8544 | && (h == NULL | |
8545 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
e717da7e | 8546 | offp = &ppc64_tlsld_got (input_bfd)->offset; |
411e1bfb | 8547 | else |
5bd4f169 | 8548 | { |
d881513a | 8549 | struct got_entry *ent; |
5bd4f169 | 8550 | |
d881513a AM |
8551 | if (h != NULL) |
8552 | { | |
8553 | bfd_boolean dyn = htab->elf.dynamic_sections_created; | |
f4656909 | 8554 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
d881513a | 8555 | || (info->shared |
586119b3 | 8556 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
d881513a AM |
8557 | /* This is actually a static link, or it is a |
8558 | -Bsymbolic link and the symbol is defined | |
8559 | locally, or the symbol was forced to be local | |
8560 | because of a version file. */ | |
8561 | ; | |
8562 | else | |
8563 | { | |
8564 | indx = h->dynindx; | |
8565 | unresolved_reloc = FALSE; | |
8566 | } | |
8567 | ent = h->got.glist; | |
8568 | } | |
411e1bfb | 8569 | else |
5bd4f169 | 8570 | { |
d881513a AM |
8571 | if (local_got_ents == NULL) |
8572 | abort (); | |
8573 | ent = local_got_ents[r_symndx]; | |
5bd4f169 | 8574 | } |
d881513a AM |
8575 | |
8576 | for (; ent != NULL; ent = ent->next) | |
8577 | if (ent->addend == rel->r_addend | |
e717da7e | 8578 | && ent->owner == input_bfd |
d881513a AM |
8579 | && ent->tls_type == tls_type) |
8580 | break; | |
8581 | if (ent == NULL) | |
8582 | abort (); | |
8583 | offp = &ent->got.offset; | |
5bd4f169 | 8584 | } |
411e1bfb | 8585 | |
e717da7e AM |
8586 | got = ppc64_elf_tdata (input_bfd)->got; |
8587 | if (got == NULL) | |
8588 | abort (); | |
8589 | ||
411e1bfb AM |
8590 | /* The offset must always be a multiple of 8. We use the |
8591 | least significant bit to record whether we have already | |
8592 | processed this entry. */ | |
d881513a | 8593 | off = *offp; |
411e1bfb AM |
8594 | if ((off & 1) != 0) |
8595 | off &= ~1; | |
5bd4f169 AM |
8596 | else |
8597 | { | |
411e1bfb AM |
8598 | /* Generate relocs for the dynamic linker, except in |
8599 | the case of TLSLD where we'll use one entry per | |
8600 | module. */ | |
e717da7e AM |
8601 | asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; |
8602 | ||
d881513a | 8603 | *offp = off | 1; |
4e795f50 AM |
8604 | if ((info->shared || indx != 0) |
8605 | && (h == NULL | |
8606 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8607 | || h->root.type != bfd_link_hash_undefweak)) | |
5bd4f169 | 8608 | { |
e717da7e AM |
8609 | outrel.r_offset = (got->output_section->vma |
8610 | + got->output_offset | |
411e1bfb | 8611 | + off); |
81407a69 | 8612 | outrel.r_addend = rel->r_addend; |
d881513a | 8613 | if (tls_type & (TLS_LD | TLS_GD)) |
5bd4f169 | 8614 | { |
411e1bfb | 8615 | outrel.r_addend = 0; |
e515b051 | 8616 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
d881513a AM |
8617 | if (tls_type == (TLS_TLS | TLS_GD)) |
8618 | { | |
e717da7e AM |
8619 | loc = relgot->contents; |
8620 | loc += (relgot->reloc_count++ | |
d881513a AM |
8621 | * sizeof (Elf64_External_Rela)); |
8622 | bfd_elf64_swap_reloca_out (output_bfd, | |
8623 | &outrel, loc); | |
e515b051 | 8624 | outrel.r_offset += 8; |
81407a69 | 8625 | outrel.r_addend = rel->r_addend; |
d881513a AM |
8626 | outrel.r_info |
8627 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); | |
d881513a | 8628 | } |
411e1bfb | 8629 | } |
951fd09b | 8630 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
411e1bfb | 8631 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
951fd09b | 8632 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb AM |
8633 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
8634 | else if (indx == 0) | |
81407a69 AM |
8635 | { |
8636 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE); | |
8637 | ||
8638 | /* Write the .got section contents for the sake | |
8639 | of prelink. */ | |
e717da7e | 8640 | loc = got->contents + off; |
23fbd6fa JJ |
8641 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
8642 | loc); | |
81407a69 | 8643 | } |
411e1bfb AM |
8644 | else |
8645 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); | |
81407a69 AM |
8646 | |
8647 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) | |
e515b051 AM |
8648 | { |
8649 | outrel.r_addend += relocation; | |
8650 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 8651 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 8652 | } |
e717da7e AM |
8653 | loc = relgot->contents; |
8654 | loc += (relgot->reloc_count++ | |
411e1bfb AM |
8655 | * sizeof (Elf64_External_Rela)); |
8656 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
8657 | } | |
8658 | ||
ad8e1ba5 | 8659 | /* Init the .got section contents here if we're not |
81407a69 | 8660 | emitting a reloc. */ |
d881513a | 8661 | else |
411e1bfb | 8662 | { |
d881513a | 8663 | relocation += rel->r_addend; |
7b609f53 AM |
8664 | if (tls_type == (TLS_TLS | TLS_LD)) |
8665 | relocation = 1; | |
8666 | else if (tls_type != 0) | |
411e1bfb | 8667 | { |
e1918d23 | 8668 | relocation -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 8669 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 8670 | relocation += DTP_OFFSET - TP_OFFSET; |
5bd4f169 | 8671 | |
7b609f53 AM |
8672 | if (tls_type == (TLS_TLS | TLS_GD)) |
8673 | { | |
8674 | bfd_put_64 (output_bfd, relocation, | |
e717da7e | 8675 | got->contents + off + 8); |
7b609f53 AM |
8676 | relocation = 1; |
8677 | } | |
411e1bfb | 8678 | } |
7b609f53 | 8679 | |
411e1bfb | 8680 | bfd_put_64 (output_bfd, relocation, |
e717da7e | 8681 | got->contents + off); |
5bd4f169 AM |
8682 | } |
8683 | } | |
8684 | ||
65f38f15 AM |
8685 | if (off >= (bfd_vma) -2) |
8686 | abort (); | |
8687 | ||
e717da7e | 8688 | relocation = got->output_offset + off; |
65f38f15 | 8689 | |
5bd4f169 | 8690 | /* TOC base (r2) is TOC start plus 0x8000. */ |
e717da7e | 8691 | addend = -TOC_BASE_OFF; |
5bd4f169 | 8692 | } |
65f38f15 AM |
8693 | break; |
8694 | ||
8695 | case R_PPC64_PLT16_HA: | |
8696 | case R_PPC64_PLT16_HI: | |
8697 | case R_PPC64_PLT16_LO: | |
8698 | case R_PPC64_PLT32: | |
8699 | case R_PPC64_PLT64: | |
8700 | /* Relocation is to the entry for this symbol in the | |
8701 | procedure linkage table. */ | |
8702 | ||
8703 | /* Resolve a PLT reloc against a local symbol directly, | |
8704 | without using the procedure linkage table. */ | |
8705 | if (h == NULL) | |
8706 | break; | |
8707 | ||
411e1bfb AM |
8708 | /* It's possible that we didn't make a PLT entry for this |
8709 | symbol. This happens when statically linking PIC code, | |
8710 | or when using -Bsymbolic. Go find a match if there is a | |
8711 | PLT entry. */ | |
4ce794b7 | 8712 | if (htab->plt != NULL) |
65f38f15 | 8713 | { |
411e1bfb AM |
8714 | struct plt_entry *ent; |
8715 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8716 | if (ent->addend == rel->r_addend | |
8717 | && ent->plt.offset != (bfd_vma) -1) | |
8718 | { | |
4ce794b7 AM |
8719 | relocation = (htab->plt->output_section->vma |
8720 | + htab->plt->output_offset | |
411e1bfb AM |
8721 | + ent->plt.offset); |
8722 | unresolved_reloc = FALSE; | |
8723 | } | |
65f38f15 | 8724 | } |
65f38f15 | 8725 | break; |
5bd4f169 | 8726 | |
0b13192e AM |
8727 | case R_PPC64_TOC: |
8728 | /* Relocation value is TOC base. */ | |
8729 | relocation = TOCstart; | |
8730 | if (r_symndx == 0) | |
8731 | relocation += htab->stub_group[input_section->id].toc_off; | |
8517fae7 AM |
8732 | else if (unresolved_reloc) |
8733 | ; | |
8734 | else if (sec != NULL && sec->id <= htab->top_id) | |
0b13192e AM |
8735 | relocation += htab->stub_group[sec->id].toc_off; |
8736 | else | |
8737 | unresolved_reloc = TRUE; | |
8738 | goto dodyn2; | |
8739 | ||
5bd4f169 AM |
8740 | /* TOC16 relocs. We want the offset relative to the TOC base, |
8741 | which is the address of the start of the TOC plus 0x8000. | |
8742 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
8743 | in this order. */ | |
65f38f15 AM |
8744 | case R_PPC64_TOC16: |
8745 | case R_PPC64_TOC16_LO: | |
8746 | case R_PPC64_TOC16_HI: | |
8747 | case R_PPC64_TOC16_DS: | |
8748 | case R_PPC64_TOC16_LO_DS: | |
8749 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 8750 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
5bd4f169 AM |
8751 | break; |
8752 | ||
8753 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
8754 | case R_PPC64_SECTOFF: |
8755 | case R_PPC64_SECTOFF_LO: | |
8756 | case R_PPC64_SECTOFF_HI: | |
8757 | case R_PPC64_SECTOFF_DS: | |
8758 | case R_PPC64_SECTOFF_LO_DS: | |
8759 | case R_PPC64_SECTOFF_HA: | |
4ce794b7 | 8760 | if (sec != NULL) |
65f38f15 | 8761 | addend -= sec->output_section->vma; |
5bd4f169 AM |
8762 | break; |
8763 | ||
721956f4 AM |
8764 | case R_PPC64_REL14: |
8765 | case R_PPC64_REL14_BRNTAKEN: | |
8766 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
8767 | case R_PPC64_REL24: |
8768 | break; | |
8769 | ||
411e1bfb AM |
8770 | case R_PPC64_TPREL16: |
8771 | case R_PPC64_TPREL16_LO: | |
8772 | case R_PPC64_TPREL16_HI: | |
8773 | case R_PPC64_TPREL16_HA: | |
8774 | case R_PPC64_TPREL16_DS: | |
8775 | case R_PPC64_TPREL16_LO_DS: | |
8776 | case R_PPC64_TPREL16_HIGHER: | |
8777 | case R_PPC64_TPREL16_HIGHERA: | |
8778 | case R_PPC64_TPREL16_HIGHEST: | |
8779 | case R_PPC64_TPREL16_HIGHESTA: | |
e1918d23 | 8780 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8781 | if (info->shared) |
8782 | /* The TPREL16 relocs shouldn't really be used in shared | |
8783 | libs as they will result in DT_TEXTREL being set, but | |
8784 | support them anyway. */ | |
8785 | goto dodyn; | |
8786 | break; | |
8787 | ||
8788 | case R_PPC64_DTPREL16: | |
8789 | case R_PPC64_DTPREL16_LO: | |
8790 | case R_PPC64_DTPREL16_HI: | |
8791 | case R_PPC64_DTPREL16_HA: | |
8792 | case R_PPC64_DTPREL16_DS: | |
8793 | case R_PPC64_DTPREL16_LO_DS: | |
8794 | case R_PPC64_DTPREL16_HIGHER: | |
8795 | case R_PPC64_DTPREL16_HIGHERA: | |
8796 | case R_PPC64_DTPREL16_HIGHEST: | |
8797 | case R_PPC64_DTPREL16_HIGHESTA: | |
e1918d23 | 8798 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8799 | break; |
8800 | ||
e515b051 AM |
8801 | case R_PPC64_DTPMOD64: |
8802 | relocation = 1; | |
8803 | addend = 0; | |
8804 | goto dodyn; | |
8805 | ||
411e1bfb | 8806 | case R_PPC64_TPREL64: |
e1918d23 | 8807 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8808 | goto dodyn; |
8809 | ||
8810 | case R_PPC64_DTPREL64: | |
e1918d23 | 8811 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8812 | /* Fall thru */ |
8813 | ||
65f38f15 AM |
8814 | /* Relocations that may need to be propagated if this is a |
8815 | dynamic object. */ | |
04c9666a | 8816 | case R_PPC64_REL30: |
65f38f15 AM |
8817 | case R_PPC64_REL32: |
8818 | case R_PPC64_REL64: | |
8819 | case R_PPC64_ADDR14: | |
8820 | case R_PPC64_ADDR14_BRNTAKEN: | |
8821 | case R_PPC64_ADDR14_BRTAKEN: | |
8822 | case R_PPC64_ADDR16: | |
8823 | case R_PPC64_ADDR16_DS: | |
8824 | case R_PPC64_ADDR16_HA: | |
8825 | case R_PPC64_ADDR16_HI: | |
8826 | case R_PPC64_ADDR16_HIGHER: | |
8827 | case R_PPC64_ADDR16_HIGHERA: | |
8828 | case R_PPC64_ADDR16_HIGHEST: | |
8829 | case R_PPC64_ADDR16_HIGHESTA: | |
8830 | case R_PPC64_ADDR16_LO: | |
8831 | case R_PPC64_ADDR16_LO_DS: | |
8832 | case R_PPC64_ADDR24: | |
65f38f15 AM |
8833 | case R_PPC64_ADDR32: |
8834 | case R_PPC64_ADDR64: | |
8835 | case R_PPC64_UADDR16: | |
8836 | case R_PPC64_UADDR32: | |
8837 | case R_PPC64_UADDR64: | |
ec338859 AM |
8838 | /* r_symndx will be zero only for relocs against symbols |
8839 | from removed linkonce sections, or sections discarded by | |
8840 | a linker script. */ | |
411e1bfb | 8841 | dodyn: |
5d1634d7 AM |
8842 | if (r_symndx == 0) |
8843 | break; | |
8844 | /* Fall thru. */ | |
8845 | ||
0b13192e | 8846 | dodyn2: |
5d1634d7 | 8847 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
8848 | break; |
8849 | ||
41bd81ab AM |
8850 | if (NO_OPD_RELOCS && is_opd) |
8851 | break; | |
8852 | ||
65f38f15 | 8853 | if ((info->shared |
4e795f50 AM |
8854 | && (h == NULL |
8855 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8856 | || h->root.type != bfd_link_hash_undefweak) | |
411e1bfb | 8857 | && (MUST_BE_DYN_RELOC (r_type) |
f6c52c13 | 8858 | || !SYMBOL_CALLS_LOCAL (info, h))) |
f4656909 AM |
8859 | || (ELIMINATE_COPY_RELOCS |
8860 | && !info->shared | |
65f38f15 AM |
8861 | && h != NULL |
8862 | && h->dynindx != -1 | |
8863 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
8864 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
8865 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
65f38f15 AM |
8866 | { |
8867 | Elf_Internal_Rela outrel; | |
b34976b6 | 8868 | bfd_boolean skip, relocate; |
65f38f15 | 8869 | asection *sreloc; |
947216bf | 8870 | bfd_byte *loc; |
1cf1f670 | 8871 | bfd_vma out_off; |
65f38f15 AM |
8872 | |
8873 | /* When generating a dynamic object, these relocations | |
8874 | are copied into the output file to be resolved at run | |
8875 | time. */ | |
8876 | ||
b34976b6 AM |
8877 | skip = FALSE; |
8878 | relocate = FALSE; | |
65f38f15 | 8879 | |
1cf1f670 AM |
8880 | out_off = _bfd_elf_section_offset (output_bfd, info, |
8881 | input_section, rel->r_offset); | |
8882 | if (out_off == (bfd_vma) -1) | |
b34976b6 | 8883 | skip = TRUE; |
1cf1f670 | 8884 | else if (out_off == (bfd_vma) -2) |
b34976b6 | 8885 | skip = TRUE, relocate = TRUE; |
1cf1f670 AM |
8886 | out_off += (input_section->output_section->vma |
8887 | + input_section->output_offset); | |
8888 | outrel.r_offset = out_off; | |
411e1bfb | 8889 | outrel.r_addend = rel->r_addend; |
65f38f15 | 8890 | |
1cf1f670 AM |
8891 | /* Optimize unaligned reloc use. */ |
8892 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) | |
8893 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) | |
8894 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; | |
8895 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) | |
8896 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) | |
8897 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; | |
8898 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) | |
8899 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) | |
8900 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; | |
8901 | ||
65f38f15 | 8902 | if (skip) |
0bb2d96a | 8903 | memset (&outrel, 0, sizeof outrel); |
f6c52c13 | 8904 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
0b13192e AM |
8905 | && !is_opd |
8906 | && r_type != R_PPC64_TOC) | |
0bb2d96a | 8907 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
65f38f15 AM |
8908 | else |
8909 | { | |
41bd81ab AM |
8910 | /* This symbol is local, or marked to become local, |
8911 | or this is an opd section reloc which must point | |
8912 | at a local function. */ | |
65f38f15 | 8913 | outrel.r_addend += relocation; |
e86ce104 | 8914 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 8915 | { |
3fad3c7c | 8916 | if (is_opd && h != NULL) |
afbe61cf AM |
8917 | { |
8918 | /* Lie about opd entries. This case occurs | |
8919 | when building shared libraries and we | |
8920 | reference a function in another shared | |
3fad3c7c AM |
8921 | lib. The same thing happens for a weak |
8922 | definition in an application that's | |
8923 | overridden by a strong definition in a | |
8924 | shared lib. (I believe this is a generic | |
8925 | bug in binutils handling of weak syms.) | |
8926 | In these cases we won't use the opd | |
1e2f5b6e | 8927 | entry in this lib. */ |
b34976b6 | 8928 | unresolved_reloc = FALSE; |
afbe61cf | 8929 | } |
65f38f15 | 8930 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
81407a69 AM |
8931 | |
8932 | /* We need to relocate .opd contents for ld.so. | |
8933 | Prelink also wants simple and consistent rules | |
8934 | for relocs. This make all RELATIVE relocs have | |
8935 | *r_offset equal to r_addend. */ | |
8936 | relocate = TRUE; | |
65f38f15 AM |
8937 | } |
8938 | else | |
8939 | { | |
8940 | long indx = 0; | |
8941 | ||
41bd81ab | 8942 | if (bfd_is_abs_section (sec)) |
65f38f15 AM |
8943 | ; |
8944 | else if (sec == NULL || sec->owner == NULL) | |
8945 | { | |
8946 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8947 | return FALSE; |
65f38f15 AM |
8948 | } |
8949 | else | |
8950 | { | |
8951 | asection *osec; | |
8952 | ||
8953 | osec = sec->output_section; | |
8954 | indx = elf_section_data (osec)->dynindx; | |
8955 | ||
8956 | /* We are turning this relocation into one | |
8957 | against a section symbol, so subtract out | |
8958 | the output section's address but not the | |
8959 | offset of the input section in the output | |
8960 | section. */ | |
8961 | outrel.r_addend -= osec->vma; | |
8962 | } | |
8963 | ||
8964 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
8965 | } | |
8966 | } | |
8967 | ||
8968 | sreloc = elf_section_data (input_section)->sreloc; | |
8969 | if (sreloc == NULL) | |
8970 | abort (); | |
8971 | ||
947216bf AM |
8972 | loc = sreloc->contents; |
8973 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
8974 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
8975 | ||
8976 | /* If this reloc is against an external symbol, it will | |
8977 | be computed at runtime, so there's no need to do | |
81407a69 AM |
8978 | anything now. However, for the sake of prelink ensure |
8979 | that the section contents are a known value. */ | |
65f38f15 | 8980 | if (! relocate) |
81407a69 AM |
8981 | { |
8982 | unresolved_reloc = FALSE; | |
8983 | /* The value chosen here is quite arbitrary as ld.so | |
8984 | ignores section contents except for the special | |
8985 | case of .opd where the contents might be accessed | |
8986 | before relocation. Choose zero, as that won't | |
8987 | cause reloc overflow. */ | |
8988 | relocation = 0; | |
8989 | addend = 0; | |
8990 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs | |
8991 | to improve backward compatibility with older | |
8992 | versions of ld. */ | |
8993 | if (r_type == R_PPC64_ADDR64) | |
8994 | addend = outrel.r_addend; | |
8995 | /* Adjust pc_relative relocs to have zero in *r_offset. */ | |
4ce794b7 | 8996 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
000732f7 AM |
8997 | addend = (input_section->output_section->vma |
8998 | + input_section->output_offset | |
8999 | + rel->r_offset); | |
81407a69 | 9000 | } |
65f38f15 | 9001 | } |
5bd4f169 AM |
9002 | break; |
9003 | ||
65f38f15 AM |
9004 | case R_PPC64_COPY: |
9005 | case R_PPC64_GLOB_DAT: | |
9006 | case R_PPC64_JMP_SLOT: | |
9007 | case R_PPC64_RELATIVE: | |
9008 | /* We shouldn't ever see these dynamic relocs in relocatable | |
9009 | files. */ | |
ae9a127f | 9010 | /* Fall through. */ |
65f38f15 AM |
9011 | |
9012 | case R_PPC64_PLTGOT16: | |
9013 | case R_PPC64_PLTGOT16_DS: | |
9014 | case R_PPC64_PLTGOT16_HA: | |
9015 | case R_PPC64_PLTGOT16_HI: | |
9016 | case R_PPC64_PLTGOT16_LO: | |
9017 | case R_PPC64_PLTGOT16_LO_DS: | |
9018 | case R_PPC64_PLTREL32: | |
9019 | case R_PPC64_PLTREL64: | |
9020 | /* These ones haven't been implemented yet. */ | |
9021 | ||
9022 | (*_bfd_error_handler) | |
d003868e AM |
9023 | (_("%B: relocation %s is not supported for symbol %s."), |
9024 | input_bfd, | |
4ce794b7 | 9025 | ppc64_elf_howto_table[r_type]->name, sym_name); |
5bd4f169 AM |
9026 | |
9027 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 9028 | ret = FALSE; |
5bd4f169 | 9029 | continue; |
65f38f15 | 9030 | } |
5bd4f169 | 9031 | |
65f38f15 AM |
9032 | /* Do any further special processing. */ |
9033 | switch (r_type) | |
9034 | { | |
9035 | default: | |
9036 | break; | |
9037 | ||
9038 | case R_PPC64_ADDR16_HA: | |
9039 | case R_PPC64_ADDR16_HIGHERA: | |
9040 | case R_PPC64_ADDR16_HIGHESTA: | |
86bbe32f AM |
9041 | case R_PPC64_GOT16_HA: |
9042 | case R_PPC64_PLTGOT16_HA: | |
65f38f15 AM |
9043 | case R_PPC64_PLT16_HA: |
9044 | case R_PPC64_TOC16_HA: | |
9045 | case R_PPC64_SECTOFF_HA: | |
411e1bfb AM |
9046 | case R_PPC64_TPREL16_HA: |
9047 | case R_PPC64_DTPREL16_HA: | |
9048 | case R_PPC64_GOT_TLSGD16_HA: | |
9049 | case R_PPC64_GOT_TLSLD16_HA: | |
9050 | case R_PPC64_GOT_TPREL16_HA: | |
9051 | case R_PPC64_GOT_DTPREL16_HA: | |
9052 | case R_PPC64_TPREL16_HIGHER: | |
9053 | case R_PPC64_TPREL16_HIGHERA: | |
9054 | case R_PPC64_TPREL16_HIGHEST: | |
9055 | case R_PPC64_TPREL16_HIGHESTA: | |
9056 | case R_PPC64_DTPREL16_HIGHER: | |
9057 | case R_PPC64_DTPREL16_HIGHERA: | |
9058 | case R_PPC64_DTPREL16_HIGHEST: | |
9059 | case R_PPC64_DTPREL16_HIGHESTA: | |
65f38f15 AM |
9060 | /* It's just possible that this symbol is a weak symbol |
9061 | that's not actually defined anywhere. In that case, | |
9062 | 'sec' would be NULL, and we should leave the symbol | |
9063 | alone (it will be set to zero elsewhere in the link). */ | |
9064 | if (sec != NULL) | |
e515b051 AM |
9065 | /* Add 0x10000 if sign bit in 0:15 is set. |
9066 | Bits 0:15 are not used. */ | |
9067 | addend += 0x8000; | |
65f38f15 AM |
9068 | break; |
9069 | ||
9070 | case R_PPC64_ADDR16_DS: | |
9071 | case R_PPC64_ADDR16_LO_DS: | |
9072 | case R_PPC64_GOT16_DS: | |
9073 | case R_PPC64_GOT16_LO_DS: | |
9074 | case R_PPC64_PLT16_LO_DS: | |
9075 | case R_PPC64_SECTOFF_DS: | |
9076 | case R_PPC64_SECTOFF_LO_DS: | |
9077 | case R_PPC64_TOC16_DS: | |
9078 | case R_PPC64_TOC16_LO_DS: | |
9079 | case R_PPC64_PLTGOT16_DS: | |
9080 | case R_PPC64_PLTGOT16_LO_DS: | |
411e1bfb AM |
9081 | case R_PPC64_GOT_TPREL16_DS: |
9082 | case R_PPC64_GOT_TPREL16_LO_DS: | |
9083 | case R_PPC64_GOT_DTPREL16_DS: | |
9084 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
9085 | case R_PPC64_TPREL16_DS: | |
9086 | case R_PPC64_TPREL16_LO_DS: | |
9087 | case R_PPC64_DTPREL16_DS: | |
9088 | case R_PPC64_DTPREL16_LO_DS: | |
adadcc0c AM |
9089 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
9090 | mask = 3; | |
9091 | /* If this reloc is against an lq insn, then the value must be | |
9092 | a multiple of 16. This is somewhat of a hack, but the | |
9093 | "correct" way to do this by defining _DQ forms of all the | |
9094 | _DS relocs bloats all reloc switches in this file. It | |
9095 | doesn't seem to make much sense to use any of these relocs | |
9096 | in data, so testing the insn should be safe. */ | |
494dac0c | 9097 | if ((insn & (0x3f << 26)) == (56u << 26)) |
adadcc0c AM |
9098 | mask = 15; |
9099 | if (((relocation + addend) & mask) != 0) | |
65f38f15 AM |
9100 | { |
9101 | (*_bfd_error_handler) | |
d003868e AM |
9102 | (_("%B: error: relocation %s not a multiple of %d"), |
9103 | input_bfd, | |
4ce794b7 | 9104 | ppc64_elf_howto_table[r_type]->name, |
adadcc0c | 9105 | mask + 1); |
65f38f15 | 9106 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 9107 | ret = FALSE; |
65f38f15 AM |
9108 | continue; |
9109 | } | |
9110 | break; | |
5bd4f169 AM |
9111 | } |
9112 | ||
239e1f3a AM |
9113 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
9114 | because such sections are not SEC_ALLOC and thus ld.so will | |
9115 | not process them. */ | |
65f38f15 | 9116 | if (unresolved_reloc |
239e1f3a | 9117 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
65f38f15 | 9118 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
9c07fe7c AM |
9119 | { |
9120 | (*_bfd_error_handler) | |
d003868e AM |
9121 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
9122 | input_bfd, | |
9123 | input_section, | |
9c07fe7c | 9124 | (long) rel->r_offset, |
7b609f53 | 9125 | ppc64_elf_howto_table[(int) r_type]->name, |
9c07fe7c | 9126 | h->root.root.string); |
b34976b6 | 9127 | ret = FALSE; |
9c07fe7c | 9128 | } |
5bd4f169 | 9129 | |
65f38f15 | 9130 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
9131 | input_bfd, |
9132 | input_section, | |
9133 | contents, | |
411e1bfb | 9134 | rel->r_offset, |
5bd4f169 AM |
9135 | relocation, |
9136 | addend); | |
9137 | ||
ef60b7ff | 9138 | if (r != bfd_reloc_ok) |
5bd4f169 | 9139 | { |
cd27b276 AM |
9140 | if (sym_name == NULL) |
9141 | sym_name = "(null)"; | |
9142 | if (r == bfd_reloc_overflow) | |
5bd4f169 | 9143 | { |
cd27b276 AM |
9144 | if (warned) |
9145 | continue; | |
9146 | if (h != NULL | |
9147 | && h->root.type == bfd_link_hash_undefweak | |
4ce794b7 | 9148 | && ppc64_elf_howto_table[r_type]->pc_relative) |
5bd4f169 AM |
9149 | { |
9150 | /* Assume this is a call protected by other code that | |
9151 | detects the symbol is undefined. If this is the case, | |
9152 | we can safely ignore the overflow. If not, the | |
9153 | program is hosed anyway, and a little warning isn't | |
9154 | going to help. */ | |
9155 | ||
9156 | continue; | |
9157 | } | |
9158 | ||
ef60b7ff | 9159 | if (!((*info->callbacks->reloc_overflow) |
4ce794b7 | 9160 | (info, sym_name, ppc64_elf_howto_table[r_type]->name, |
411e1bfb | 9161 | rel->r_addend, input_bfd, input_section, rel->r_offset))) |
b34976b6 | 9162 | return FALSE; |
ef60b7ff AM |
9163 | } |
9164 | else | |
9165 | { | |
9166 | (*_bfd_error_handler) | |
d003868e AM |
9167 | (_("%B(%A+0x%lx): %s reloc against `%s': error %d"), |
9168 | input_bfd, | |
9169 | input_section, | |
7b609f53 | 9170 | (long) rel->r_offset, |
4ce794b7 | 9171 | ppc64_elf_howto_table[r_type]->name, |
7b609f53 AM |
9172 | sym_name, |
9173 | (int) r); | |
b34976b6 | 9174 | ret = FALSE; |
ef60b7ff | 9175 | } |
5bd4f169 | 9176 | } |
5bd4f169 AM |
9177 | } |
9178 | ||
5bd4f169 AM |
9179 | return ret; |
9180 | } | |
9181 | ||
754021d0 AM |
9182 | /* Adjust the value of any local symbols in opd sections. */ |
9183 | ||
9184 | static bfd_boolean | |
9185 | ppc64_elf_output_symbol_hook (struct bfd_link_info *info, | |
9186 | const char *name ATTRIBUTE_UNUSED, | |
9187 | Elf_Internal_Sym *elfsym, | |
9188 | asection *input_sec, | |
9189 | struct elf_link_hash_entry *h) | |
9190 | { | |
4025353c | 9191 | long *opd_adjust, adjust; |
754021d0 AM |
9192 | bfd_vma value; |
9193 | ||
4025353c AM |
9194 | if (h != NULL) |
9195 | return TRUE; | |
9196 | ||
9197 | opd_adjust = get_opd_info (input_sec); | |
9198 | if (opd_adjust == NULL) | |
754021d0 AM |
9199 | return TRUE; |
9200 | ||
9201 | value = elfsym->st_value - input_sec->output_offset; | |
9202 | if (!info->relocatable) | |
9203 | value -= input_sec->output_section->vma; | |
9204 | ||
4025353c AM |
9205 | adjust = opd_adjust[value / 24]; |
9206 | if (adjust == -1) | |
9207 | elfsym->st_value = 0; | |
9208 | else | |
9209 | elfsym->st_value += adjust; | |
754021d0 AM |
9210 | return TRUE; |
9211 | } | |
9212 | ||
5bd4f169 AM |
9213 | /* Finish up dynamic symbol handling. We set the contents of various |
9214 | dynamic sections here. */ | |
9215 | ||
b34976b6 | 9216 | static bfd_boolean |
4ce794b7 AM |
9217 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
9218 | struct bfd_link_info *info, | |
9219 | struct elf_link_hash_entry *h, | |
9220 | Elf_Internal_Sym *sym) | |
5bd4f169 | 9221 | { |
65f38f15 | 9222 | struct ppc_link_hash_table *htab; |
5bd4f169 | 9223 | bfd *dynobj; |
8387904d AM |
9224 | struct plt_entry *ent; |
9225 | Elf_Internal_Rela rela; | |
9226 | bfd_byte *loc; | |
5bd4f169 | 9227 | |
65f38f15 AM |
9228 | htab = ppc_hash_table (info); |
9229 | dynobj = htab->elf.dynobj; | |
5bd4f169 | 9230 | |
8387904d AM |
9231 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
9232 | if (ent->plt.offset != (bfd_vma) -1) | |
9233 | { | |
9234 | /* This symbol has an entry in the procedure linkage | |
9235 | table. Set it up. */ | |
9236 | ||
9237 | if (htab->plt == NULL | |
9238 | || htab->relplt == NULL | |
9239 | || htab->glink == NULL) | |
9240 | abort (); | |
9241 | ||
9242 | /* Create a JMP_SLOT reloc to inform the dynamic linker to | |
9243 | fill in the PLT entry. */ | |
9244 | rela.r_offset = (htab->plt->output_section->vma | |
9245 | + htab->plt->output_offset | |
9246 | + ent->plt.offset); | |
9247 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); | |
9248 | rela.r_addend = ent->addend; | |
9249 | ||
9250 | loc = htab->relplt->contents; | |
9251 | loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE | |
9252 | * sizeof (Elf64_External_Rela)); | |
9253 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
9254 | } | |
5bd4f169 AM |
9255 | |
9256 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
9257 | { | |
5bd4f169 | 9258 | Elf_Internal_Rela rela; |
947216bf | 9259 | bfd_byte *loc; |
5bd4f169 | 9260 | |
65f38f15 | 9261 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 9262 | |
65f38f15 AM |
9263 | if (h->dynindx == -1 |
9264 | || (h->root.type != bfd_link_hash_defined | |
9265 | && h->root.type != bfd_link_hash_defweak) | |
4ce794b7 | 9266 | || htab->relbss == NULL) |
65f38f15 | 9267 | abort (); |
5bd4f169 AM |
9268 | |
9269 | rela.r_offset = (h->root.u.def.value | |
9270 | + h->root.u.def.section->output_section->vma | |
9271 | + h->root.u.def.section->output_offset); | |
9272 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
9273 | rela.r_addend = 0; | |
4ce794b7 AM |
9274 | loc = htab->relbss->contents; |
9275 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 9276 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
9277 | } |
9278 | ||
5bd4f169 AM |
9279 | /* Mark some specially defined symbols as absolute. */ |
9280 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
9281 | sym->st_shndx = SHN_ABS; | |
9282 | ||
b34976b6 | 9283 | return TRUE; |
5bd4f169 AM |
9284 | } |
9285 | ||
65f38f15 AM |
9286 | /* Used to decide how to sort relocs in an optimal manner for the |
9287 | dynamic linker, before writing them out. */ | |
9288 | ||
9289 | static enum elf_reloc_type_class | |
4ce794b7 | 9290 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
65f38f15 | 9291 | { |
04c9666a | 9292 | enum elf_ppc64_reloc_type r_type; |
a33d1f77 | 9293 | |
4ce794b7 | 9294 | r_type = ELF64_R_TYPE (rela->r_info); |
a33d1f77 | 9295 | switch (r_type) |
65f38f15 AM |
9296 | { |
9297 | case R_PPC64_RELATIVE: | |
9298 | return reloc_class_relative; | |
9299 | case R_PPC64_JMP_SLOT: | |
9300 | return reloc_class_plt; | |
9301 | case R_PPC64_COPY: | |
9302 | return reloc_class_copy; | |
9303 | default: | |
9304 | return reloc_class_normal; | |
9305 | } | |
9306 | } | |
9307 | ||
5bd4f169 AM |
9308 | /* Finish up the dynamic sections. */ |
9309 | ||
b34976b6 | 9310 | static bfd_boolean |
4ce794b7 AM |
9311 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
9312 | struct bfd_link_info *info) | |
5bd4f169 | 9313 | { |
65f38f15 AM |
9314 | struct ppc_link_hash_table *htab; |
9315 | bfd *dynobj; | |
5bd4f169 | 9316 | asection *sdyn; |
5bd4f169 | 9317 | |
65f38f15 AM |
9318 | htab = ppc_hash_table (info); |
9319 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
9320 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
9321 | ||
65f38f15 | 9322 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 9323 | { |
5bd4f169 AM |
9324 | Elf64_External_Dyn *dyncon, *dynconend; |
9325 | ||
4ce794b7 | 9326 | if (sdyn == NULL || htab->got == NULL) |
65f38f15 | 9327 | abort (); |
5bd4f169 AM |
9328 | |
9329 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
eea6121a | 9330 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
5bd4f169 AM |
9331 | for (; dyncon < dynconend; dyncon++) |
9332 | { | |
9333 | Elf_Internal_Dyn dyn; | |
19397422 | 9334 | asection *s; |
5bd4f169 AM |
9335 | |
9336 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
9337 | ||
9338 | switch (dyn.d_tag) | |
9339 | { | |
65f38f15 AM |
9340 | default: |
9341 | continue; | |
5bd4f169 | 9342 | |
5d1634d7 | 9343 | case DT_PPC64_GLINK: |
4ce794b7 | 9344 | s = htab->glink; |
6348e046 | 9345 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
ad8e1ba5 AM |
9346 | /* We stupidly defined DT_PPC64_GLINK to be the start |
9347 | of glink rather than the first entry point, which is | |
9348 | what ld.so needs, and now have a bigger stub to | |
9349 | support automatic multiple TOCs. */ | |
9350 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; | |
5d1634d7 AM |
9351 | break; |
9352 | ||
19397422 AM |
9353 | case DT_PPC64_OPD: |
9354 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
9355 | if (s == NULL) |
9356 | continue; | |
9357 | dyn.d_un.d_ptr = s->vma; | |
19397422 AM |
9358 | break; |
9359 | ||
9360 | case DT_PPC64_OPDSZ: | |
9361 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
9362 | if (s == NULL) |
9363 | continue; | |
eea6121a | 9364 | dyn.d_un.d_val = s->size; |
19397422 AM |
9365 | break; |
9366 | ||
65f38f15 | 9367 | case DT_PLTGOT: |
4ce794b7 | 9368 | s = htab->plt; |
6348e046 | 9369 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 AM |
9370 | break; |
9371 | ||
9372 | case DT_JMPREL: | |
4ce794b7 | 9373 | s = htab->relplt; |
6348e046 | 9374 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 | 9375 | break; |
5bd4f169 | 9376 | |
65f38f15 | 9377 | case DT_PLTRELSZ: |
eea6121a | 9378 | dyn.d_un.d_val = htab->relplt->size; |
5d1634d7 AM |
9379 | break; |
9380 | ||
9381 | case DT_RELASZ: | |
9382 | /* Don't count procedure linkage table relocs in the | |
9383 | overall reloc count. */ | |
4ce794b7 | 9384 | s = htab->relplt; |
6348e046 AM |
9385 | if (s == NULL) |
9386 | continue; | |
eea6121a | 9387 | dyn.d_un.d_val -= s->size; |
6348e046 AM |
9388 | break; |
9389 | ||
9390 | case DT_RELA: | |
9391 | /* We may not be using the standard ELF linker script. | |
9392 | If .rela.plt is the first .rela section, we adjust | |
9393 | DT_RELA to not include it. */ | |
4ce794b7 | 9394 | s = htab->relplt; |
6348e046 AM |
9395 | if (s == NULL) |
9396 | continue; | |
9397 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
9398 | continue; | |
eea6121a | 9399 | dyn.d_un.d_ptr += s->size; |
65f38f15 | 9400 | break; |
5bd4f169 | 9401 | } |
5bd4f169 | 9402 | |
65f38f15 | 9403 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 9404 | } |
5bd4f169 AM |
9405 | } |
9406 | ||
eea6121a | 9407 | if (htab->got != NULL && htab->got->size != 0) |
5d1634d7 AM |
9408 | { |
9409 | /* Fill in the first entry in the global offset table. | |
9410 | We use it to hold the link-time TOCbase. */ | |
9411 | bfd_put_64 (output_bfd, | |
60ee0d4a | 9412 | elf_gp (output_bfd) + TOC_BASE_OFF, |
4ce794b7 | 9413 | htab->got->contents); |
5d1634d7 AM |
9414 | |
9415 | /* Set .got entry size. */ | |
4ce794b7 | 9416 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
5d1634d7 AM |
9417 | } |
9418 | ||
eea6121a | 9419 | if (htab->plt != NULL && htab->plt->size != 0) |
5d1634d7 AM |
9420 | { |
9421 | /* Set .plt entry size. */ | |
4ce794b7 | 9422 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
5d1634d7 AM |
9423 | = PLT_ENTRY_SIZE; |
9424 | } | |
9425 | ||
e717da7e AM |
9426 | /* We need to handle writing out multiple GOT sections ourselves, |
9427 | since we didn't add them to DYNOBJ. */ | |
9428 | while ((dynobj = dynobj->link_next) != NULL) | |
9429 | { | |
9430 | asection *s; | |
9431 | s = ppc64_elf_tdata (dynobj)->got; | |
9432 | if (s != NULL | |
eea6121a | 9433 | && s->size != 0 |
e717da7e AM |
9434 | && s->output_section != bfd_abs_section_ptr |
9435 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
9436 | s->contents, s->output_offset, | |
eea6121a | 9437 | s->size)) |
e717da7e AM |
9438 | return FALSE; |
9439 | s = ppc64_elf_tdata (dynobj)->relgot; | |
9440 | if (s != NULL | |
eea6121a | 9441 | && s->size != 0 |
e717da7e AM |
9442 | && s->output_section != bfd_abs_section_ptr |
9443 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
9444 | s->contents, s->output_offset, | |
eea6121a | 9445 | s->size)) |
e717da7e AM |
9446 | return FALSE; |
9447 | } | |
f6c52c13 | 9448 | |
b34976b6 | 9449 | return TRUE; |
5bd4f169 AM |
9450 | } |
9451 | ||
5bd4f169 | 9452 | #include "elf64-target.h" |