Commit | Line | Data |
---|---|---|
5bd4f169 | 1 | /* PowerPC64-specific support for 64-bit ELF. |
3a71aa26 | 2 | Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
df22d223 | 3 | 2009, 2010, 2011 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. | |
32ca9640 | 6 | Largely rewritten by Alan Modra. |
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 | |
cd123cb7 | 12 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 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., | |
3e110533 | 22 | 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
5bd4f169 | 23 | |
cd123cb7 | 24 | |
4ce794b7 AM |
25 | /* The 64-bit PowerPC ELF ABI may be found at |
26 | http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and | |
27 | http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */ | |
5bd4f169 | 28 | |
3db64b00 | 29 | #include "sysdep.h" |
183e98be | 30 | #include <stdarg.h> |
5bd4f169 | 31 | #include "bfd.h" |
5bd4f169 AM |
32 | #include "bfdlink.h" |
33 | #include "libbfd.h" | |
34 | #include "elf-bfd.h" | |
04c9666a | 35 | #include "elf/ppc64.h" |
5d1634d7 | 36 | #include "elf64-ppc.h" |
58d180e8 | 37 | #include "dwarf2.h" |
5bd4f169 | 38 | |
805fc799 | 39 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
4ce794b7 | 40 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
2441e016 AM |
41 | static bfd_reloc_status_type ppc64_elf_branch_reloc |
42 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
805fc799 | 43 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
4ce794b7 | 44 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 45 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
4ce794b7 | 46 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 47 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
4ce794b7 | 48 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 49 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
4ce794b7 | 50 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 51 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
4ce794b7 | 52 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 53 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
4ce794b7 | 54 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 55 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
4ce794b7 | 56 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
2441e016 AM |
57 | static bfd_vma opd_entry_value |
58 | (asection *, bfd_vma, asection **, bfd_vma *); | |
5bd4f169 | 59 | |
ad8e1ba5 AM |
60 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
61 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
62 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
63 | #define TARGET_BIG_NAME "elf64-powerpc" | |
64 | #define ELF_ARCH bfd_arch_powerpc | |
ae95ffa6 | 65 | #define ELF_TARGET_ID PPC64_ELF_DATA |
ad8e1ba5 AM |
66 | #define ELF_MACHINE_CODE EM_PPC64 |
67 | #define ELF_MAXPAGESIZE 0x10000 | |
24718e3b | 68 | #define ELF_COMMONPAGESIZE 0x1000 |
ad8e1ba5 AM |
69 | #define elf_info_to_howto ppc64_elf_info_to_howto |
70 | ||
71 | #define elf_backend_want_got_sym 0 | |
72 | #define elf_backend_want_plt_sym 0 | |
73 | #define elf_backend_plt_alignment 3 | |
74 | #define elf_backend_plt_not_loaded 1 | |
ad8e1ba5 | 75 | #define elf_backend_got_header_size 8 |
ad8e1ba5 AM |
76 | #define elf_backend_can_gc_sections 1 |
77 | #define elf_backend_can_refcount 1 | |
78 | #define elf_backend_rela_normal 1 | |
6bfdb61b | 79 | #define elf_backend_default_execstack 0 |
ad8e1ba5 | 80 | |
e717da7e | 81 | #define bfd_elf64_mkobject ppc64_elf_mkobject |
ad8e1ba5 | 82 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
aa374f67 | 83 | #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup |
c79d6685 | 84 | #define bfd_elf64_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match |
ad8e1ba5 AM |
85 | #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook |
86 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create | |
87 | #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free | |
90e3cdf2 | 88 | #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab |
aa374f67 | 89 | #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms |
ad8e1ba5 AM |
90 | |
91 | #define elf_backend_object_p ppc64_elf_object_p | |
d37c89e5 AM |
92 | #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus |
93 | #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo | |
183e98be | 94 | #define elf_backend_write_core_note ppc64_elf_write_core_note |
ad8e1ba5 AM |
95 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
96 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
555cd476 | 97 | #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook |
7d9616d7 | 98 | #define elf_backend_check_directives ppc64_elf_process_dot_syms |
97fed1c9 | 99 | #define elf_backend_as_needed_cleanup ppc64_elf_as_needed_cleanup |
8387904d | 100 | #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup |
ad8e1ba5 | 101 | #define elf_backend_check_relocs ppc64_elf_check_relocs |
74f0fb50 | 102 | #define elf_backend_gc_keep ppc64_elf_gc_keep |
64d03ab5 | 103 | #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref |
ad8e1ba5 AM |
104 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook |
105 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
106 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
107 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol | |
108 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
109 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
74541ad4 | 110 | #define elf_backend_init_index_section _bfd_elf_init_2_index_sections |
60124e18 | 111 | #define elf_backend_action_discarded ppc64_elf_action_discarded |
ad8e1ba5 AM |
112 | #define elf_backend_relocate_section ppc64_elf_relocate_section |
113 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
114 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
115 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
754021d0 | 116 | #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook |
29ef7005 | 117 | #define elf_backend_special_sections ppc64_elf_special_sections |
e054468f | 118 | #define elf_backend_post_process_headers _bfd_elf_set_osabi |
ad8e1ba5 | 119 | |
5bd4f169 AM |
120 | /* The name of the dynamic interpreter. This is put in the .interp |
121 | section. */ | |
122 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
123 | ||
124 | /* The size in bytes of an entry in the procedure linkage table. */ | |
125 | #define PLT_ENTRY_SIZE 24 | |
126 | ||
127 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 128 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
129 | |
130 | /* TOC base pointers offset from start of TOC. */ | |
411e1bfb AM |
131 | #define TOC_BASE_OFF 0x8000 |
132 | ||
133 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
134 | #define TP_OFFSET 0x7000 | |
135 | #define DTP_OFFSET 0x8000 | |
5bd4f169 | 136 | |
ad8e1ba5 AM |
137 | /* .plt call stub instructions. The normal stub is like this, but |
138 | sometimes the .plt entry crosses a 64k boundary and we need to | |
ac2df442 | 139 | insert an addi to adjust r12. */ |
ad8e1ba5 | 140 | #define PLT_CALL_STUB_SIZE (7*4) |
5d1634d7 AM |
141 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
142 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
143 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
5d1634d7 | 144 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ |
ac2df442 | 145 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ |
5d1634d7 AM |
146 | /* ld %r11,xxx+16@l(%r12) */ |
147 | #define BCTR 0x4e800420 /* bctr */ | |
148 | ||
5d1634d7 | 149 | |
ee4bf8d2 | 150 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */ |
ac2df442 | 151 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */ |
ad8e1ba5 AM |
152 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
153 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ | |
154 | ||
ac2df442 AM |
155 | #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */ |
156 | #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */ | |
157 | ||
ad8e1ba5 AM |
158 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ |
159 | ||
ee4bf8d2 | 160 | /* glink call stub instructions. We enter with the index in R0. */ |
ad8e1ba5 | 161 | #define GLINK_CALL_STUB_SIZE (16*4) |
ee4bf8d2 AM |
162 | /* 0: */ |
163 | /* .quad plt0-1f */ | |
164 | /* __glink: */ | |
165 | #define MFLR_R12 0x7d8802a6 /* mflr %12 */ | |
166 | #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */ | |
167 | /* 1: */ | |
168 | #define MFLR_R11 0x7d6802a6 /* mflr %11 */ | |
169 | #define LD_R2_M16R11 0xe84bfff0 /* ld %2,(0b-1b)(%11) */ | |
170 | #define MTLR_R12 0x7d8803a6 /* mtlr %12 */ | |
171 | #define ADD_R12_R2_R11 0x7d825a14 /* add %12,%2,%11 */ | |
172 | /* ld %11,0(%12) */ | |
173 | /* ld %2,8(%12) */ | |
174 | /* mtctr %11 */ | |
175 | /* ld %11,16(%12) */ | |
176 | /* bctr */ | |
5d1634d7 AM |
177 | |
178 | /* Pad with this. */ | |
179 | #define NOP 0x60000000 | |
180 | ||
721956f4 AM |
181 | /* Some other nops. */ |
182 | #define CROR_151515 0x4def7b82 | |
183 | #define CROR_313131 0x4ffffb82 | |
184 | ||
cedb70c5 | 185 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
186 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
187 | #define B_DOT 0x48000000 /* b . */ | |
188 | ||
189 | /* After that, we need two instructions to load the index, followed by | |
190 | a branch. */ | |
191 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 192 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 193 | |
deb0e272 AM |
194 | /* Instructions used by the save and restore reg functions. */ |
195 | #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */ | |
196 | #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */ | |
197 | #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */ | |
198 | #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */ | |
82bd7b59 AM |
199 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ |
200 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
deb0e272 AM |
201 | #define LI_R12_0 0x39800000 /* li %r12,0 */ |
202 | #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */ | |
203 | #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */ | |
204 | #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */ | |
82bd7b59 AM |
205 | #define BLR 0x4e800020 /* blr */ |
206 | ||
41bd81ab AM |
207 | /* Since .opd is an array of descriptors and each entry will end up |
208 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
209 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 210 | relocate .opd without reloc entries. */ |
41bd81ab AM |
211 | #ifndef NO_OPD_RELOCS |
212 | #define NO_OPD_RELOCS 0 | |
213 | #endif | |
5bd4f169 | 214 | \f |
f5e87a1d | 215 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 216 | |
5bd4f169 | 217 | /* Relocation HOWTO's. */ |
04c9666a | 218 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
5bd4f169 AM |
219 | |
220 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
221 | /* This reloc does nothing. */ | |
222 | HOWTO (R_PPC64_NONE, /* type */ | |
223 | 0, /* rightshift */ | |
411e1bfb AM |
224 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
225 | 32, /* bitsize */ | |
b34976b6 | 226 | FALSE, /* pc_relative */ |
5bd4f169 | 227 | 0, /* bitpos */ |
f5e87a1d | 228 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
229 | bfd_elf_generic_reloc, /* special_function */ |
230 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 231 | FALSE, /* partial_inplace */ |
d006db6c | 232 | 0, /* src_mask */ |
5bd4f169 | 233 | 0, /* dst_mask */ |
b34976b6 | 234 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
235 | |
236 | /* A standard 32 bit relocation. */ | |
237 | HOWTO (R_PPC64_ADDR32, /* type */ | |
238 | 0, /* rightshift */ | |
239 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
240 | 32, /* bitsize */ | |
b34976b6 | 241 | FALSE, /* pc_relative */ |
5bd4f169 AM |
242 | 0, /* bitpos */ |
243 | complain_overflow_bitfield, /* complain_on_overflow */ | |
244 | bfd_elf_generic_reloc, /* special_function */ | |
245 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 246 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
247 | 0, /* src_mask */ |
248 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 249 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
250 | |
251 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
252 | FIXME: we don't check that, we just clear them. */ | |
253 | HOWTO (R_PPC64_ADDR24, /* type */ | |
254 | 0, /* rightshift */ | |
255 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
256 | 26, /* bitsize */ | |
b34976b6 | 257 | FALSE, /* pc_relative */ |
5bd4f169 AM |
258 | 0, /* bitpos */ |
259 | complain_overflow_bitfield, /* complain_on_overflow */ | |
260 | bfd_elf_generic_reloc, /* special_function */ | |
261 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 262 | FALSE, /* partial_inplace */ |
d006db6c | 263 | 0, /* src_mask */ |
f5e87a1d | 264 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 265 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
266 | |
267 | /* A standard 16 bit relocation. */ | |
268 | HOWTO (R_PPC64_ADDR16, /* type */ | |
269 | 0, /* rightshift */ | |
270 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
271 | 16, /* bitsize */ | |
b34976b6 | 272 | FALSE, /* pc_relative */ |
5bd4f169 AM |
273 | 0, /* bitpos */ |
274 | complain_overflow_bitfield, /* complain_on_overflow */ | |
275 | bfd_elf_generic_reloc, /* special_function */ | |
276 | "R_PPC64_ADDR16", /* name */ | |
b34976b6 | 277 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
278 | 0, /* src_mask */ |
279 | 0xffff, /* dst_mask */ | |
b34976b6 | 280 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
281 | |
282 | /* A 16 bit relocation without overflow. */ | |
283 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
284 | 0, /* rightshift */ | |
285 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
286 | 16, /* bitsize */ | |
b34976b6 | 287 | FALSE, /* pc_relative */ |
5bd4f169 AM |
288 | 0, /* bitpos */ |
289 | complain_overflow_dont,/* complain_on_overflow */ | |
290 | bfd_elf_generic_reloc, /* special_function */ | |
291 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 292 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
293 | 0, /* src_mask */ |
294 | 0xffff, /* dst_mask */ | |
b34976b6 | 295 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
296 | |
297 | /* Bits 16-31 of an address. */ | |
298 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
299 | 16, /* rightshift */ | |
300 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
301 | 16, /* bitsize */ | |
b34976b6 | 302 | FALSE, /* pc_relative */ |
5bd4f169 AM |
303 | 0, /* bitpos */ |
304 | complain_overflow_dont, /* complain_on_overflow */ | |
305 | bfd_elf_generic_reloc, /* special_function */ | |
306 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 307 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
308 | 0, /* src_mask */ |
309 | 0xffff, /* dst_mask */ | |
b34976b6 | 310 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
311 | |
312 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
313 | bits, treated as a signed number, is negative. */ | |
314 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
315 | 16, /* rightshift */ | |
316 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
317 | 16, /* bitsize */ | |
b34976b6 | 318 | FALSE, /* pc_relative */ |
5bd4f169 AM |
319 | 0, /* bitpos */ |
320 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 321 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 322 | "R_PPC64_ADDR16_HA", /* name */ |
b34976b6 | 323 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
324 | 0, /* src_mask */ |
325 | 0xffff, /* dst_mask */ | |
b34976b6 | 326 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
327 | |
328 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
329 | FIXME: we don't check that, we just clear them. */ | |
330 | HOWTO (R_PPC64_ADDR14, /* type */ | |
331 | 0, /* rightshift */ | |
332 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
333 | 16, /* bitsize */ | |
b34976b6 | 334 | FALSE, /* pc_relative */ |
5bd4f169 AM |
335 | 0, /* bitpos */ |
336 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2441e016 | 337 | ppc64_elf_branch_reloc, /* special_function */ |
5bd4f169 | 338 | "R_PPC64_ADDR14", /* name */ |
b34976b6 | 339 | FALSE, /* partial_inplace */ |
d006db6c | 340 | 0, /* src_mask */ |
f5e87a1d | 341 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 342 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
343 | |
344 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
345 | indicate that the branch is expected to be taken. The lower two | |
346 | bits must be zero. */ | |
347 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
348 | 0, /* rightshift */ | |
349 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
350 | 16, /* bitsize */ | |
b34976b6 | 351 | FALSE, /* pc_relative */ |
5bd4f169 AM |
352 | 0, /* bitpos */ |
353 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 354 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 355 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 356 | FALSE, /* partial_inplace */ |
d006db6c | 357 | 0, /* src_mask */ |
f5e87a1d | 358 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 359 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
360 | |
361 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
362 | indicate that the branch is not expected to be taken. The lower | |
363 | two bits must be zero. */ | |
364 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
365 | 0, /* rightshift */ | |
366 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
367 | 16, /* bitsize */ | |
b34976b6 | 368 | FALSE, /* pc_relative */ |
5bd4f169 AM |
369 | 0, /* bitpos */ |
370 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 371 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 372 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 373 | FALSE, /* partial_inplace */ |
d006db6c | 374 | 0, /* src_mask */ |
f5e87a1d | 375 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 376 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
377 | |
378 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
379 | HOWTO (R_PPC64_REL24, /* type */ | |
380 | 0, /* rightshift */ | |
381 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
382 | 26, /* bitsize */ | |
b34976b6 | 383 | TRUE, /* pc_relative */ |
5bd4f169 AM |
384 | 0, /* bitpos */ |
385 | complain_overflow_signed, /* complain_on_overflow */ | |
2441e016 | 386 | ppc64_elf_branch_reloc, /* special_function */ |
5bd4f169 | 387 | "R_PPC64_REL24", /* name */ |
b34976b6 | 388 | FALSE, /* partial_inplace */ |
d006db6c | 389 | 0, /* src_mask */ |
f5e87a1d | 390 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 391 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
392 | |
393 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
394 | HOWTO (R_PPC64_REL14, /* type */ | |
395 | 0, /* rightshift */ | |
396 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
397 | 16, /* bitsize */ | |
b34976b6 | 398 | TRUE, /* pc_relative */ |
5bd4f169 AM |
399 | 0, /* bitpos */ |
400 | complain_overflow_signed, /* complain_on_overflow */ | |
2441e016 | 401 | ppc64_elf_branch_reloc, /* special_function */ |
5bd4f169 | 402 | "R_PPC64_REL14", /* name */ |
b34976b6 | 403 | FALSE, /* partial_inplace */ |
d006db6c | 404 | 0, /* src_mask */ |
f5e87a1d | 405 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 406 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
407 | |
408 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
409 | the branch is expected to be taken. The lower two bits must be | |
410 | zero. */ | |
411 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
412 | 0, /* rightshift */ | |
413 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
414 | 16, /* bitsize */ | |
b34976b6 | 415 | TRUE, /* pc_relative */ |
5bd4f169 AM |
416 | 0, /* bitpos */ |
417 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 418 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 419 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 420 | FALSE, /* partial_inplace */ |
d006db6c | 421 | 0, /* src_mask */ |
f5e87a1d | 422 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 423 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
424 | |
425 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
426 | the branch is not expected to be taken. The lower two bits must | |
427 | be zero. */ | |
428 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
429 | 0, /* rightshift */ | |
430 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
431 | 16, /* bitsize */ | |
b34976b6 | 432 | TRUE, /* pc_relative */ |
5bd4f169 AM |
433 | 0, /* bitpos */ |
434 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 435 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 436 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 437 | FALSE, /* partial_inplace */ |
d006db6c | 438 | 0, /* src_mask */ |
f5e87a1d | 439 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 440 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
441 | |
442 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
443 | symbol. */ | |
444 | HOWTO (R_PPC64_GOT16, /* type */ | |
445 | 0, /* rightshift */ | |
446 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
447 | 16, /* bitsize */ | |
b34976b6 | 448 | FALSE, /* pc_relative */ |
5bd4f169 AM |
449 | 0, /* bitpos */ |
450 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 451 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 452 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 453 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
454 | 0, /* src_mask */ |
455 | 0xffff, /* dst_mask */ | |
b34976b6 | 456 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
457 | |
458 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
459 | the symbol. */ | |
460 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
461 | 0, /* rightshift */ | |
462 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
463 | 16, /* bitsize */ | |
b34976b6 | 464 | FALSE, /* pc_relative */ |
5bd4f169 AM |
465 | 0, /* bitpos */ |
466 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 467 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 468 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 469 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
470 | 0, /* src_mask */ |
471 | 0xffff, /* dst_mask */ | |
b34976b6 | 472 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
473 | |
474 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
475 | the symbol. */ | |
476 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
477 | 16, /* rightshift */ | |
478 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
479 | 16, /* bitsize */ | |
b34976b6 | 480 | FALSE, /* pc_relative */ |
5bd4f169 AM |
481 | 0, /* bitpos */ |
482 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 483 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 484 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 485 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
486 | 0, /* src_mask */ |
487 | 0xffff, /* dst_mask */ | |
b34976b6 | 488 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
489 | |
490 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
491 | the symbol. */ | |
492 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
493 | 16, /* rightshift */ | |
494 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
495 | 16, /* bitsize */ | |
b34976b6 | 496 | FALSE, /* pc_relative */ |
5bd4f169 AM |
497 | 0, /* bitpos */ |
498 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 499 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 500 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 501 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
502 | 0, /* src_mask */ |
503 | 0xffff, /* dst_mask */ | |
b34976b6 | 504 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
505 | |
506 | /* This is used only by the dynamic linker. The symbol should exist | |
507 | both in the object being run and in some shared library. The | |
508 | dynamic linker copies the data addressed by the symbol from the | |
509 | shared library into the object, because the object being | |
510 | run has to have the data at some particular address. */ | |
511 | HOWTO (R_PPC64_COPY, /* type */ | |
512 | 0, /* rightshift */ | |
f5e87a1d AM |
513 | 0, /* this one is variable size */ |
514 | 0, /* bitsize */ | |
b34976b6 | 515 | FALSE, /* pc_relative */ |
5bd4f169 | 516 | 0, /* bitpos */ |
f5e87a1d AM |
517 | complain_overflow_dont, /* complain_on_overflow */ |
518 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 519 | "R_PPC64_COPY", /* name */ |
b34976b6 | 520 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
521 | 0, /* src_mask */ |
522 | 0, /* dst_mask */ | |
b34976b6 | 523 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
524 | |
525 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
526 | entries. */ | |
527 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
528 | 0, /* rightshift */ | |
529 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
530 | 64, /* bitsize */ | |
b34976b6 | 531 | FALSE, /* pc_relative */ |
5bd4f169 AM |
532 | 0, /* bitpos */ |
533 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 534 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 535 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 536 | FALSE, /* partial_inplace */ |
5bd4f169 | 537 | 0, /* src_mask */ |
f5e87a1d | 538 | ONES (64), /* dst_mask */ |
b34976b6 | 539 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
540 | |
541 | /* Created by the link editor. Marks a procedure linkage table | |
542 | entry for a symbol. */ | |
543 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
544 | 0, /* rightshift */ | |
545 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
546 | 0, /* bitsize */ | |
b34976b6 | 547 | FALSE, /* pc_relative */ |
5bd4f169 AM |
548 | 0, /* bitpos */ |
549 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 550 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 551 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 552 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
553 | 0, /* src_mask */ |
554 | 0, /* dst_mask */ | |
b34976b6 | 555 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
556 | |
557 | /* Used only by the dynamic linker. When the object is run, this | |
558 | doubleword64 is set to the load address of the object, plus the | |
559 | addend. */ | |
560 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
561 | 0, /* rightshift */ | |
562 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
563 | 64, /* bitsize */ | |
b34976b6 | 564 | FALSE, /* pc_relative */ |
5bd4f169 AM |
565 | 0, /* bitpos */ |
566 | complain_overflow_dont, /* complain_on_overflow */ | |
567 | bfd_elf_generic_reloc, /* special_function */ | |
568 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 569 | FALSE, /* partial_inplace */ |
5bd4f169 | 570 | 0, /* src_mask */ |
f5e87a1d | 571 | ONES (64), /* dst_mask */ |
b34976b6 | 572 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
573 | |
574 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
575 | HOWTO (R_PPC64_UADDR32, /* type */ | |
576 | 0, /* rightshift */ | |
577 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
578 | 32, /* bitsize */ | |
b34976b6 | 579 | FALSE, /* pc_relative */ |
5bd4f169 AM |
580 | 0, /* bitpos */ |
581 | complain_overflow_bitfield, /* complain_on_overflow */ | |
582 | bfd_elf_generic_reloc, /* special_function */ | |
583 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 584 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
585 | 0, /* src_mask */ |
586 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 587 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
588 | |
589 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
590 | HOWTO (R_PPC64_UADDR16, /* type */ | |
591 | 0, /* rightshift */ | |
592 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
593 | 16, /* bitsize */ | |
b34976b6 | 594 | FALSE, /* pc_relative */ |
5bd4f169 AM |
595 | 0, /* bitpos */ |
596 | complain_overflow_bitfield, /* complain_on_overflow */ | |
597 | bfd_elf_generic_reloc, /* special_function */ | |
598 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 599 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
600 | 0, /* src_mask */ |
601 | 0xffff, /* dst_mask */ | |
b34976b6 | 602 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
603 | |
604 | /* 32-bit PC relative. */ | |
605 | HOWTO (R_PPC64_REL32, /* type */ | |
606 | 0, /* rightshift */ | |
607 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
608 | 32, /* bitsize */ | |
b34976b6 | 609 | TRUE, /* pc_relative */ |
5bd4f169 | 610 | 0, /* bitpos */ |
cedb70c5 | 611 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
612 | complain_overflow_signed, /* complain_on_overflow */ |
613 | bfd_elf_generic_reloc, /* special_function */ | |
614 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 615 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
616 | 0, /* src_mask */ |
617 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 618 | TRUE), /* pcrel_offset */ |
5bd4f169 | 619 | |
10ed1bba | 620 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
621 | HOWTO (R_PPC64_PLT32, /* type */ |
622 | 0, /* rightshift */ | |
623 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
624 | 32, /* bitsize */ | |
b34976b6 | 625 | FALSE, /* pc_relative */ |
5bd4f169 AM |
626 | 0, /* bitpos */ |
627 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 628 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 629 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 630 | FALSE, /* partial_inplace */ |
5bd4f169 | 631 | 0, /* src_mask */ |
f5e87a1d | 632 | 0xffffffff, /* dst_mask */ |
b34976b6 | 633 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
634 | |
635 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
636 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
637 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
638 | 0, /* rightshift */ | |
639 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
640 | 32, /* bitsize */ | |
b34976b6 | 641 | TRUE, /* pc_relative */ |
5bd4f169 AM |
642 | 0, /* bitpos */ |
643 | complain_overflow_signed, /* complain_on_overflow */ | |
644 | bfd_elf_generic_reloc, /* special_function */ | |
645 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 646 | FALSE, /* partial_inplace */ |
5bd4f169 | 647 | 0, /* src_mask */ |
f5e87a1d | 648 | 0xffffffff, /* dst_mask */ |
b34976b6 | 649 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
650 | |
651 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
652 | the symbol. */ | |
653 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
654 | 0, /* rightshift */ | |
655 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
656 | 16, /* bitsize */ | |
b34976b6 | 657 | FALSE, /* pc_relative */ |
5bd4f169 AM |
658 | 0, /* bitpos */ |
659 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 660 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 661 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 662 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
663 | 0, /* src_mask */ |
664 | 0xffff, /* dst_mask */ | |
b34976b6 | 665 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
666 | |
667 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
668 | the symbol. */ | |
669 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
670 | 16, /* rightshift */ | |
671 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
672 | 16, /* bitsize */ | |
b34976b6 | 673 | FALSE, /* pc_relative */ |
5bd4f169 AM |
674 | 0, /* bitpos */ |
675 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 676 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 677 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 678 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
679 | 0, /* src_mask */ |
680 | 0xffff, /* dst_mask */ | |
b34976b6 | 681 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
682 | |
683 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
684 | the symbol. */ | |
685 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
686 | 16, /* rightshift */ | |
687 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
688 | 16, /* bitsize */ | |
b34976b6 | 689 | FALSE, /* pc_relative */ |
5bd4f169 AM |
690 | 0, /* bitpos */ |
691 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 692 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 693 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 694 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
695 | 0, /* src_mask */ |
696 | 0xffff, /* dst_mask */ | |
b34976b6 | 697 | FALSE), /* pcrel_offset */ |
5bd4f169 | 698 | |
c061c2d8 | 699 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
700 | HOWTO (R_PPC64_SECTOFF, /* type */ |
701 | 0, /* rightshift */ | |
c061c2d8 AM |
702 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
703 | 16, /* bitsize */ | |
b34976b6 | 704 | FALSE, /* pc_relative */ |
5bd4f169 AM |
705 | 0, /* bitpos */ |
706 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 707 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 708 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 709 | FALSE, /* partial_inplace */ |
5bd4f169 | 710 | 0, /* src_mask */ |
c061c2d8 | 711 | 0xffff, /* dst_mask */ |
b34976b6 | 712 | FALSE), /* pcrel_offset */ |
5bd4f169 | 713 | |
c061c2d8 | 714 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
715 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
716 | 0, /* rightshift */ | |
717 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
718 | 16, /* bitsize */ | |
b34976b6 | 719 | FALSE, /* pc_relative */ |
5bd4f169 AM |
720 | 0, /* bitpos */ |
721 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 722 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 723 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 724 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
725 | 0, /* src_mask */ |
726 | 0xffff, /* dst_mask */ | |
b34976b6 | 727 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
728 | |
729 | /* 16-bit upper half section relative relocation. */ | |
730 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
731 | 16, /* rightshift */ | |
732 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
733 | 16, /* bitsize */ | |
b34976b6 | 734 | FALSE, /* pc_relative */ |
5bd4f169 AM |
735 | 0, /* bitpos */ |
736 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 737 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 738 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 739 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
740 | 0, /* src_mask */ |
741 | 0xffff, /* dst_mask */ | |
b34976b6 | 742 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
743 | |
744 | /* 16-bit upper half adjusted section relative relocation. */ | |
745 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
746 | 16, /* rightshift */ | |
747 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
748 | 16, /* bitsize */ | |
b34976b6 | 749 | FALSE, /* pc_relative */ |
5bd4f169 AM |
750 | 0, /* bitpos */ |
751 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 752 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 753 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 754 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
755 | 0, /* src_mask */ |
756 | 0xffff, /* dst_mask */ | |
b34976b6 | 757 | FALSE), /* pcrel_offset */ |
5bd4f169 | 758 | |
04c9666a AM |
759 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
760 | HOWTO (R_PPC64_REL30, /* type */ | |
5bd4f169 AM |
761 | 2, /* rightshift */ |
762 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
763 | 30, /* bitsize */ | |
b34976b6 | 764 | TRUE, /* pc_relative */ |
5bd4f169 AM |
765 | 0, /* bitpos */ |
766 | complain_overflow_dont, /* complain_on_overflow */ | |
767 | bfd_elf_generic_reloc, /* special_function */ | |
04c9666a | 768 | "R_PPC64_REL30", /* name */ |
b34976b6 | 769 | FALSE, /* partial_inplace */ |
d006db6c | 770 | 0, /* src_mask */ |
5bd4f169 | 771 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 772 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
773 | |
774 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
775 | ||
776 | /* A standard 64-bit relocation. */ | |
777 | HOWTO (R_PPC64_ADDR64, /* type */ | |
778 | 0, /* rightshift */ | |
779 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
780 | 64, /* bitsize */ | |
b34976b6 | 781 | FALSE, /* pc_relative */ |
5bd4f169 AM |
782 | 0, /* bitpos */ |
783 | complain_overflow_dont, /* complain_on_overflow */ | |
784 | bfd_elf_generic_reloc, /* special_function */ | |
785 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 786 | FALSE, /* partial_inplace */ |
5bd4f169 | 787 | 0, /* src_mask */ |
f5e87a1d | 788 | ONES (64), /* dst_mask */ |
b34976b6 | 789 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
790 | |
791 | /* The bits 32-47 of an address. */ | |
792 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
793 | 32, /* rightshift */ | |
794 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
795 | 16, /* bitsize */ | |
b34976b6 | 796 | FALSE, /* pc_relative */ |
5bd4f169 AM |
797 | 0, /* bitpos */ |
798 | complain_overflow_dont, /* complain_on_overflow */ | |
799 | bfd_elf_generic_reloc, /* special_function */ | |
800 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 801 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
802 | 0, /* src_mask */ |
803 | 0xffff, /* dst_mask */ | |
b34976b6 | 804 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
805 | |
806 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
807 | 16 bits, treated as a signed number, is negative. */ | |
808 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
809 | 32, /* rightshift */ | |
810 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
811 | 16, /* bitsize */ | |
b34976b6 | 812 | FALSE, /* pc_relative */ |
5bd4f169 AM |
813 | 0, /* bitpos */ |
814 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 815 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 816 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 817 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
818 | 0, /* src_mask */ |
819 | 0xffff, /* dst_mask */ | |
b34976b6 | 820 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
821 | |
822 | /* The bits 48-63 of an address. */ | |
823 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
824 | 48, /* rightshift */ | |
825 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
826 | 16, /* bitsize */ | |
b34976b6 | 827 | FALSE, /* pc_relative */ |
5bd4f169 AM |
828 | 0, /* bitpos */ |
829 | complain_overflow_dont, /* complain_on_overflow */ | |
830 | bfd_elf_generic_reloc, /* special_function */ | |
831 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
b34976b6 | 832 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
833 | 0, /* src_mask */ |
834 | 0xffff, /* dst_mask */ | |
b34976b6 | 835 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
836 | |
837 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
838 | 16 bits, treated as a signed number, is negative. */ | |
839 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
840 | 48, /* rightshift */ | |
841 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
842 | 16, /* bitsize */ | |
b34976b6 | 843 | FALSE, /* pc_relative */ |
5bd4f169 AM |
844 | 0, /* bitpos */ |
845 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 846 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 847 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
b34976b6 | 848 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
849 | 0, /* src_mask */ |
850 | 0xffff, /* dst_mask */ | |
b34976b6 | 851 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
852 | |
853 | /* Like ADDR64, but may be unaligned. */ | |
854 | HOWTO (R_PPC64_UADDR64, /* type */ | |
855 | 0, /* rightshift */ | |
856 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
857 | 64, /* bitsize */ | |
b34976b6 | 858 | FALSE, /* pc_relative */ |
5bd4f169 AM |
859 | 0, /* bitpos */ |
860 | complain_overflow_dont, /* complain_on_overflow */ | |
861 | bfd_elf_generic_reloc, /* special_function */ | |
862 | "R_PPC64_UADDR64", /* name */ | |
b34976b6 | 863 | FALSE, /* partial_inplace */ |
5bd4f169 | 864 | 0, /* src_mask */ |
f5e87a1d | 865 | ONES (64), /* dst_mask */ |
b34976b6 | 866 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
867 | |
868 | /* 64-bit relative relocation. */ | |
869 | HOWTO (R_PPC64_REL64, /* type */ | |
870 | 0, /* rightshift */ | |
871 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
872 | 64, /* bitsize */ | |
b34976b6 | 873 | TRUE, /* pc_relative */ |
5bd4f169 AM |
874 | 0, /* bitpos */ |
875 | complain_overflow_dont, /* complain_on_overflow */ | |
876 | bfd_elf_generic_reloc, /* special_function */ | |
877 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 878 | FALSE, /* partial_inplace */ |
5bd4f169 | 879 | 0, /* src_mask */ |
f5e87a1d | 880 | ONES (64), /* dst_mask */ |
b34976b6 | 881 | TRUE), /* pcrel_offset */ |
5bd4f169 | 882 | |
cedb70c5 | 883 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
884 | HOWTO (R_PPC64_PLT64, /* type */ |
885 | 0, /* rightshift */ | |
886 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
887 | 64, /* bitsize */ | |
b34976b6 | 888 | FALSE, /* pc_relative */ |
5bd4f169 AM |
889 | 0, /* bitpos */ |
890 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 891 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 892 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 893 | FALSE, /* partial_inplace */ |
5bd4f169 | 894 | 0, /* src_mask */ |
f5e87a1d | 895 | ONES (64), /* dst_mask */ |
b34976b6 | 896 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
897 | |
898 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
899 | table. */ | |
900 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
901 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
902 | 0, /* rightshift */ | |
903 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
904 | 64, /* bitsize */ | |
b34976b6 | 905 | TRUE, /* pc_relative */ |
5bd4f169 AM |
906 | 0, /* bitpos */ |
907 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 908 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 909 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 910 | FALSE, /* partial_inplace */ |
5bd4f169 | 911 | 0, /* src_mask */ |
f5e87a1d | 912 | ONES (64), /* dst_mask */ |
b34976b6 | 913 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
914 | |
915 | /* 16 bit TOC-relative relocation. */ | |
916 | ||
917 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
918 | HOWTO (R_PPC64_TOC16, /* type */ | |
919 | 0, /* rightshift */ | |
920 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
921 | 16, /* bitsize */ | |
b34976b6 | 922 | FALSE, /* pc_relative */ |
5bd4f169 AM |
923 | 0, /* bitpos */ |
924 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 925 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 926 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 927 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
928 | 0, /* src_mask */ |
929 | 0xffff, /* dst_mask */ | |
b34976b6 | 930 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
931 | |
932 | /* 16 bit TOC-relative relocation without overflow. */ | |
933 | ||
934 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
935 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
936 | 0, /* rightshift */ | |
937 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
938 | 16, /* bitsize */ | |
b34976b6 | 939 | FALSE, /* pc_relative */ |
5bd4f169 AM |
940 | 0, /* bitpos */ |
941 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 942 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 943 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 944 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
945 | 0, /* src_mask */ |
946 | 0xffff, /* dst_mask */ | |
b34976b6 | 947 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
948 | |
949 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
950 | ||
951 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
952 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
953 | 16, /* rightshift */ | |
954 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
955 | 16, /* bitsize */ | |
b34976b6 | 956 | FALSE, /* pc_relative */ |
5bd4f169 AM |
957 | 0, /* bitpos */ |
958 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 959 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 960 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 961 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
962 | 0, /* src_mask */ |
963 | 0xffff, /* dst_mask */ | |
b34976b6 | 964 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
965 | |
966 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
967 | contents of the low 16 bits, treated as a signed number, is | |
968 | negative. */ | |
969 | ||
970 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
971 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
972 | 16, /* rightshift */ | |
973 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
974 | 16, /* bitsize */ | |
b34976b6 | 975 | FALSE, /* pc_relative */ |
5bd4f169 AM |
976 | 0, /* bitpos */ |
977 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 978 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 979 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 980 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
981 | 0, /* src_mask */ |
982 | 0xffff, /* dst_mask */ | |
b34976b6 | 983 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
984 | |
985 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
986 | ||
987 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
988 | HOWTO (R_PPC64_TOC, /* type */ | |
989 | 0, /* rightshift */ | |
990 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
991 | 64, /* bitsize */ | |
b34976b6 | 992 | FALSE, /* pc_relative */ |
5bd4f169 AM |
993 | 0, /* bitpos */ |
994 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 995 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 996 | "R_PPC64_TOC", /* name */ |
b34976b6 | 997 | FALSE, /* partial_inplace */ |
5bd4f169 | 998 | 0, /* src_mask */ |
f5e87a1d | 999 | ONES (64), /* dst_mask */ |
b34976b6 | 1000 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1001 | |
1002 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
1003 | value to relocate may (!) refer to a PLT entry which the link | |
1004 | editor (a) may replace with the symbol value. If the link editor | |
1005 | is unable to fully resolve the symbol, it may (b) create a PLT | |
1006 | entry and store the address to the new PLT entry in the GOT. | |
1007 | This permits lazy resolution of function symbols at run time. | |
1008 | The link editor may also skip all of this and just (c) emit a | |
1009 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
1010 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
1011 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
1012 | 0, /* rightshift */ | |
1013 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1014 | 16, /* bitsize */ | |
b34976b6 | 1015 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1016 | 0, /* bitpos */ |
1017 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 1018 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb AM |
1019 | "R_PPC64_PLTGOT16", /* name */ |
1020 | FALSE, /* partial_inplace */ | |
1021 | 0, /* src_mask */ | |
1022 | 0xffff, /* dst_mask */ | |
1023 | FALSE), /* pcrel_offset */ | |
1024 | ||
1025 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
1026 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1027 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
1028 | 0, /* rightshift */ | |
1029 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1030 | 16, /* bitsize */ | |
1031 | FALSE, /* pc_relative */ | |
1032 | 0, /* bitpos */ | |
1033 | complain_overflow_dont, /* complain_on_overflow */ | |
1034 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1035 | "R_PPC64_PLTGOT16_LO", /* name */ | |
1036 | FALSE, /* partial_inplace */ | |
1037 | 0, /* src_mask */ | |
1038 | 0xffff, /* dst_mask */ | |
1039 | FALSE), /* pcrel_offset */ | |
1040 | ||
1041 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
1042 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
1043 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
1044 | 16, /* rightshift */ | |
1045 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1046 | 16, /* bitsize */ | |
1047 | FALSE, /* pc_relative */ | |
1048 | 0, /* bitpos */ | |
1049 | complain_overflow_dont, /* complain_on_overflow */ | |
1050 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1051 | "R_PPC64_PLTGOT16_HI", /* name */ | |
1052 | FALSE, /* partial_inplace */ | |
1053 | 0, /* src_mask */ | |
1054 | 0xffff, /* dst_mask */ | |
1055 | FALSE), /* pcrel_offset */ | |
1056 | ||
1057 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
1058 | 1 if the contents of the low 16 bits, treated as a signed number, | |
1059 | is negative. */ | |
1060 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
1061 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
1062 | 16, /* rightshift */ | |
1063 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1064 | 16, /* bitsize */ | |
1065 | FALSE, /* pc_relative */ | |
1066 | 0, /* bitpos */ | |
1067 | complain_overflow_dont,/* complain_on_overflow */ | |
1068 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1069 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1070 | FALSE, /* partial_inplace */ | |
1071 | 0, /* src_mask */ | |
1072 | 0xffff, /* dst_mask */ | |
1073 | FALSE), /* pcrel_offset */ | |
1074 | ||
1075 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1076 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1077 | 0, /* rightshift */ | |
1078 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1079 | 16, /* bitsize */ | |
1080 | FALSE, /* pc_relative */ | |
1081 | 0, /* bitpos */ | |
1082 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1083 | bfd_elf_generic_reloc, /* special_function */ | |
1084 | "R_PPC64_ADDR16_DS", /* name */ | |
1085 | FALSE, /* partial_inplace */ | |
1086 | 0, /* src_mask */ | |
1087 | 0xfffc, /* dst_mask */ | |
1088 | FALSE), /* pcrel_offset */ | |
1089 | ||
1090 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1091 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1092 | 0, /* rightshift */ | |
1093 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1094 | 16, /* bitsize */ | |
1095 | FALSE, /* pc_relative */ | |
1096 | 0, /* bitpos */ | |
1097 | complain_overflow_dont,/* complain_on_overflow */ | |
1098 | bfd_elf_generic_reloc, /* special_function */ | |
1099 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1100 | FALSE, /* partial_inplace */ | |
1101 | 0, /* src_mask */ | |
1102 | 0xfffc, /* dst_mask */ | |
1103 | FALSE), /* pcrel_offset */ | |
1104 | ||
1105 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1106 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1107 | 0, /* rightshift */ | |
1108 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1109 | 16, /* bitsize */ | |
1110 | FALSE, /* pc_relative */ | |
1111 | 0, /* bitpos */ | |
1112 | complain_overflow_signed, /* complain_on_overflow */ | |
1113 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1114 | "R_PPC64_GOT16_DS", /* name */ | |
1115 | FALSE, /* partial_inplace */ | |
1116 | 0, /* src_mask */ | |
1117 | 0xfffc, /* dst_mask */ | |
1118 | FALSE), /* pcrel_offset */ | |
1119 | ||
1120 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1121 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1122 | 0, /* rightshift */ | |
1123 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1124 | 16, /* bitsize */ | |
1125 | FALSE, /* pc_relative */ | |
1126 | 0, /* bitpos */ | |
1127 | complain_overflow_dont, /* complain_on_overflow */ | |
1128 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1129 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1130 | FALSE, /* partial_inplace */ | |
1131 | 0, /* src_mask */ | |
1132 | 0xfffc, /* dst_mask */ | |
1133 | FALSE), /* pcrel_offset */ | |
1134 | ||
1135 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1136 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1137 | 0, /* rightshift */ | |
1138 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1139 | 16, /* bitsize */ | |
1140 | FALSE, /* pc_relative */ | |
1141 | 0, /* bitpos */ | |
1142 | complain_overflow_dont, /* complain_on_overflow */ | |
1143 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1144 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1145 | FALSE, /* partial_inplace */ | |
1146 | 0, /* src_mask */ | |
1147 | 0xfffc, /* dst_mask */ | |
1148 | FALSE), /* pcrel_offset */ | |
1149 | ||
1150 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1151 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1152 | 0, /* rightshift */ | |
1153 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1154 | 16, /* bitsize */ | |
1155 | FALSE, /* pc_relative */ | |
1156 | 0, /* bitpos */ | |
1157 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1158 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1159 | "R_PPC64_SECTOFF_DS", /* name */ | |
1160 | FALSE, /* partial_inplace */ | |
1161 | 0, /* src_mask */ | |
1162 | 0xfffc, /* dst_mask */ | |
1163 | FALSE), /* pcrel_offset */ | |
1164 | ||
1165 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1166 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1167 | 0, /* rightshift */ | |
1168 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1169 | 16, /* bitsize */ | |
1170 | FALSE, /* pc_relative */ | |
1171 | 0, /* bitpos */ | |
1172 | complain_overflow_dont, /* complain_on_overflow */ | |
1173 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1174 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1175 | FALSE, /* partial_inplace */ | |
1176 | 0, /* src_mask */ | |
1177 | 0xfffc, /* dst_mask */ | |
1178 | FALSE), /* pcrel_offset */ | |
1179 | ||
1180 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1181 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1182 | 0, /* rightshift */ | |
1183 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1184 | 16, /* bitsize */ | |
1185 | FALSE, /* pc_relative */ | |
1186 | 0, /* bitpos */ | |
1187 | complain_overflow_signed, /* complain_on_overflow */ | |
1188 | ppc64_elf_toc_reloc, /* special_function */ | |
1189 | "R_PPC64_TOC16_DS", /* name */ | |
1190 | FALSE, /* partial_inplace */ | |
1191 | 0, /* src_mask */ | |
1192 | 0xfffc, /* dst_mask */ | |
1193 | FALSE), /* pcrel_offset */ | |
1194 | ||
1195 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1196 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1197 | 0, /* rightshift */ | |
1198 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1199 | 16, /* bitsize */ | |
1200 | FALSE, /* pc_relative */ | |
1201 | 0, /* bitpos */ | |
1202 | complain_overflow_dont, /* complain_on_overflow */ | |
1203 | ppc64_elf_toc_reloc, /* special_function */ | |
1204 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1205 | FALSE, /* partial_inplace */ | |
1206 | 0, /* src_mask */ | |
1207 | 0xfffc, /* dst_mask */ | |
1208 | FALSE), /* pcrel_offset */ | |
1209 | ||
1210 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1211 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
6bfdb61b | 1212 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ |
411e1bfb AM |
1213 | 0, /* rightshift */ |
1214 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1215 | 16, /* bitsize */ | |
1216 | FALSE, /* pc_relative */ | |
1217 | 0, /* bitpos */ | |
1218 | complain_overflow_signed, /* complain_on_overflow */ | |
1219 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1220 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1221 | FALSE, /* partial_inplace */ | |
1222 | 0, /* src_mask */ | |
1223 | 0xfffc, /* dst_mask */ | |
1224 | FALSE), /* pcrel_offset */ | |
1225 | ||
1226 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1227 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1228 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1229 | 0, /* rightshift */ | |
1230 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1231 | 16, /* bitsize */ | |
1232 | FALSE, /* pc_relative */ | |
1233 | 0, /* bitpos */ | |
1234 | complain_overflow_dont, /* complain_on_overflow */ | |
1235 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1236 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1237 | FALSE, /* partial_inplace */ | |
1238 | 0, /* src_mask */ | |
1239 | 0xfffc, /* dst_mask */ | |
1240 | FALSE), /* pcrel_offset */ | |
1241 | ||
727fc41e | 1242 | /* Marker relocs for TLS. */ |
411e1bfb AM |
1243 | HOWTO (R_PPC64_TLS, |
1244 | 0, /* rightshift */ | |
1245 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1246 | 32, /* bitsize */ | |
1247 | FALSE, /* pc_relative */ | |
1248 | 0, /* bitpos */ | |
1249 | complain_overflow_dont, /* complain_on_overflow */ | |
1250 | bfd_elf_generic_reloc, /* special_function */ | |
1251 | "R_PPC64_TLS", /* name */ | |
1252 | FALSE, /* partial_inplace */ | |
1253 | 0, /* src_mask */ | |
1254 | 0, /* dst_mask */ | |
1255 | FALSE), /* pcrel_offset */ | |
1256 | ||
727fc41e AM |
1257 | HOWTO (R_PPC64_TLSGD, |
1258 | 0, /* rightshift */ | |
1259 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1260 | 32, /* bitsize */ | |
1261 | FALSE, /* pc_relative */ | |
1262 | 0, /* bitpos */ | |
1263 | complain_overflow_dont, /* complain_on_overflow */ | |
1264 | bfd_elf_generic_reloc, /* special_function */ | |
1265 | "R_PPC64_TLSGD", /* name */ | |
1266 | FALSE, /* partial_inplace */ | |
1267 | 0, /* src_mask */ | |
1268 | 0, /* dst_mask */ | |
1269 | FALSE), /* pcrel_offset */ | |
1270 | ||
1271 | HOWTO (R_PPC64_TLSLD, | |
1272 | 0, /* rightshift */ | |
1273 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1274 | 32, /* bitsize */ | |
1275 | FALSE, /* pc_relative */ | |
1276 | 0, /* bitpos */ | |
1277 | complain_overflow_dont, /* complain_on_overflow */ | |
1278 | bfd_elf_generic_reloc, /* special_function */ | |
1279 | "R_PPC64_TLSLD", /* name */ | |
1280 | FALSE, /* partial_inplace */ | |
1281 | 0, /* src_mask */ | |
1282 | 0, /* dst_mask */ | |
1283 | FALSE), /* pcrel_offset */ | |
1284 | ||
411e1bfb AM |
1285 | /* Computes the load module index of the load module that contains the |
1286 | definition of its TLS sym. */ | |
1287 | HOWTO (R_PPC64_DTPMOD64, | |
1288 | 0, /* rightshift */ | |
1289 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1290 | 64, /* bitsize */ | |
1291 | FALSE, /* pc_relative */ | |
1292 | 0, /* bitpos */ | |
1293 | complain_overflow_dont, /* complain_on_overflow */ | |
1294 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1295 | "R_PPC64_DTPMOD64", /* name */ | |
1296 | FALSE, /* partial_inplace */ | |
1297 | 0, /* src_mask */ | |
1298 | ONES (64), /* dst_mask */ | |
1299 | FALSE), /* pcrel_offset */ | |
1300 | ||
1301 | /* Computes a dtv-relative displacement, the difference between the value | |
1302 | of sym+add and the base address of the thread-local storage block that | |
1303 | contains the definition of sym, minus 0x8000. */ | |
1304 | HOWTO (R_PPC64_DTPREL64, | |
1305 | 0, /* rightshift */ | |
1306 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1307 | 64, /* bitsize */ | |
1308 | FALSE, /* pc_relative */ | |
1309 | 0, /* bitpos */ | |
1310 | complain_overflow_dont, /* complain_on_overflow */ | |
1311 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1312 | "R_PPC64_DTPREL64", /* name */ | |
1313 | FALSE, /* partial_inplace */ | |
1314 | 0, /* src_mask */ | |
1315 | ONES (64), /* dst_mask */ | |
1316 | FALSE), /* pcrel_offset */ | |
1317 | ||
1318 | /* A 16 bit dtprel reloc. */ | |
1319 | HOWTO (R_PPC64_DTPREL16, | |
1320 | 0, /* rightshift */ | |
1321 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1322 | 16, /* bitsize */ | |
1323 | FALSE, /* pc_relative */ | |
1324 | 0, /* bitpos */ | |
1325 | complain_overflow_signed, /* complain_on_overflow */ | |
1326 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1327 | "R_PPC64_DTPREL16", /* name */ | |
1328 | FALSE, /* partial_inplace */ | |
1329 | 0, /* src_mask */ | |
1330 | 0xffff, /* dst_mask */ | |
1331 | FALSE), /* pcrel_offset */ | |
1332 | ||
1333 | /* Like DTPREL16, but no overflow. */ | |
1334 | HOWTO (R_PPC64_DTPREL16_LO, | |
1335 | 0, /* rightshift */ | |
1336 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1337 | 16, /* bitsize */ | |
1338 | FALSE, /* pc_relative */ | |
1339 | 0, /* bitpos */ | |
1340 | complain_overflow_dont, /* complain_on_overflow */ | |
1341 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1342 | "R_PPC64_DTPREL16_LO", /* name */ | |
1343 | FALSE, /* partial_inplace */ | |
1344 | 0, /* src_mask */ | |
1345 | 0xffff, /* dst_mask */ | |
1346 | FALSE), /* pcrel_offset */ | |
1347 | ||
1348 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ | |
1349 | HOWTO (R_PPC64_DTPREL16_HI, | |
1350 | 16, /* rightshift */ | |
1351 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1352 | 16, /* bitsize */ | |
1353 | FALSE, /* pc_relative */ | |
1354 | 0, /* bitpos */ | |
1355 | complain_overflow_dont, /* complain_on_overflow */ | |
1356 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1357 | "R_PPC64_DTPREL16_HI", /* name */ | |
1358 | FALSE, /* partial_inplace */ | |
1359 | 0, /* src_mask */ | |
1360 | 0xffff, /* dst_mask */ | |
1361 | FALSE), /* pcrel_offset */ | |
1362 | ||
1363 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ | |
1364 | HOWTO (R_PPC64_DTPREL16_HA, | |
1365 | 16, /* rightshift */ | |
1366 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1367 | 16, /* bitsize */ | |
1368 | FALSE, /* pc_relative */ | |
1369 | 0, /* bitpos */ | |
1370 | complain_overflow_dont, /* complain_on_overflow */ | |
1371 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1372 | "R_PPC64_DTPREL16_HA", /* name */ | |
1373 | FALSE, /* partial_inplace */ | |
1374 | 0, /* src_mask */ | |
1375 | 0xffff, /* dst_mask */ | |
1376 | FALSE), /* pcrel_offset */ | |
1377 | ||
1378 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ | |
1379 | HOWTO (R_PPC64_DTPREL16_HIGHER, | |
1380 | 32, /* rightshift */ | |
1381 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1382 | 16, /* bitsize */ | |
1383 | FALSE, /* pc_relative */ | |
1384 | 0, /* bitpos */ | |
1385 | complain_overflow_dont, /* complain_on_overflow */ | |
1386 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1387 | "R_PPC64_DTPREL16_HIGHER", /* name */ | |
1388 | FALSE, /* partial_inplace */ | |
1389 | 0, /* src_mask */ | |
1390 | 0xffff, /* dst_mask */ | |
1391 | FALSE), /* pcrel_offset */ | |
1392 | ||
1393 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ | |
1394 | HOWTO (R_PPC64_DTPREL16_HIGHERA, | |
1395 | 32, /* rightshift */ | |
1396 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1397 | 16, /* bitsize */ | |
1398 | FALSE, /* pc_relative */ | |
1399 | 0, /* bitpos */ | |
1400 | complain_overflow_dont, /* complain_on_overflow */ | |
1401 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1402 | "R_PPC64_DTPREL16_HIGHERA", /* name */ | |
1403 | FALSE, /* partial_inplace */ | |
1404 | 0, /* src_mask */ | |
1405 | 0xffff, /* dst_mask */ | |
1406 | FALSE), /* pcrel_offset */ | |
1407 | ||
1408 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ | |
1409 | HOWTO (R_PPC64_DTPREL16_HIGHEST, | |
1410 | 48, /* rightshift */ | |
1411 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1412 | 16, /* bitsize */ | |
1413 | FALSE, /* pc_relative */ | |
1414 | 0, /* bitpos */ | |
1415 | complain_overflow_dont, /* complain_on_overflow */ | |
1416 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1417 | "R_PPC64_DTPREL16_HIGHEST", /* name */ | |
1418 | FALSE, /* partial_inplace */ | |
1419 | 0, /* src_mask */ | |
1420 | 0xffff, /* dst_mask */ | |
1421 | FALSE), /* pcrel_offset */ | |
1422 | ||
1423 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1424 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, | |
1425 | 48, /* rightshift */ | |
1426 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1427 | 16, /* bitsize */ | |
1428 | FALSE, /* pc_relative */ | |
1429 | 0, /* bitpos */ | |
1430 | complain_overflow_dont, /* complain_on_overflow */ | |
1431 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1432 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ | |
1433 | FALSE, /* partial_inplace */ | |
1434 | 0, /* src_mask */ | |
1435 | 0xffff, /* dst_mask */ | |
1436 | FALSE), /* pcrel_offset */ | |
1437 | ||
1438 | /* Like DTPREL16, but for insns with a DS field. */ | |
1439 | HOWTO (R_PPC64_DTPREL16_DS, | |
1440 | 0, /* rightshift */ | |
1441 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1442 | 16, /* bitsize */ | |
1443 | FALSE, /* pc_relative */ | |
1444 | 0, /* bitpos */ | |
1445 | complain_overflow_signed, /* complain_on_overflow */ | |
1446 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1447 | "R_PPC64_DTPREL16_DS", /* name */ | |
1448 | FALSE, /* partial_inplace */ | |
1449 | 0, /* src_mask */ | |
1450 | 0xfffc, /* dst_mask */ | |
1451 | FALSE), /* pcrel_offset */ | |
1452 | ||
1453 | /* Like DTPREL16_DS, but no overflow. */ | |
1454 | HOWTO (R_PPC64_DTPREL16_LO_DS, | |
1455 | 0, /* rightshift */ | |
1456 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1457 | 16, /* bitsize */ | |
1458 | FALSE, /* pc_relative */ | |
1459 | 0, /* bitpos */ | |
1460 | complain_overflow_dont, /* complain_on_overflow */ | |
1461 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1462 | "R_PPC64_DTPREL16_LO_DS", /* name */ | |
1463 | FALSE, /* partial_inplace */ | |
1464 | 0, /* src_mask */ | |
1465 | 0xfffc, /* dst_mask */ | |
1466 | FALSE), /* pcrel_offset */ | |
1467 | ||
1468 | /* Computes a tp-relative displacement, the difference between the value of | |
1469 | sym+add and the value of the thread pointer (r13). */ | |
1470 | HOWTO (R_PPC64_TPREL64, | |
1471 | 0, /* rightshift */ | |
1472 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1473 | 64, /* bitsize */ | |
1474 | FALSE, /* pc_relative */ | |
1475 | 0, /* bitpos */ | |
1476 | complain_overflow_dont, /* complain_on_overflow */ | |
1477 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1478 | "R_PPC64_TPREL64", /* name */ | |
1479 | FALSE, /* partial_inplace */ | |
1480 | 0, /* src_mask */ | |
1481 | ONES (64), /* dst_mask */ | |
1482 | FALSE), /* pcrel_offset */ | |
1483 | ||
1484 | /* A 16 bit tprel reloc. */ | |
1485 | HOWTO (R_PPC64_TPREL16, | |
1486 | 0, /* rightshift */ | |
1487 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1488 | 16, /* bitsize */ | |
1489 | FALSE, /* pc_relative */ | |
1490 | 0, /* bitpos */ | |
1491 | complain_overflow_signed, /* complain_on_overflow */ | |
1492 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1493 | "R_PPC64_TPREL16", /* name */ | |
1494 | FALSE, /* partial_inplace */ | |
1495 | 0, /* src_mask */ | |
1496 | 0xffff, /* dst_mask */ | |
1497 | FALSE), /* pcrel_offset */ | |
1498 | ||
1499 | /* Like TPREL16, but no overflow. */ | |
1500 | HOWTO (R_PPC64_TPREL16_LO, | |
1501 | 0, /* rightshift */ | |
1502 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1503 | 16, /* bitsize */ | |
1504 | FALSE, /* pc_relative */ | |
1505 | 0, /* bitpos */ | |
1506 | complain_overflow_dont, /* complain_on_overflow */ | |
1507 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1508 | "R_PPC64_TPREL16_LO", /* name */ | |
1509 | FALSE, /* partial_inplace */ | |
1510 | 0, /* src_mask */ | |
1511 | 0xffff, /* dst_mask */ | |
1512 | FALSE), /* pcrel_offset */ | |
1513 | ||
1514 | /* Like TPREL16_LO, but next higher group of 16 bits. */ | |
1515 | HOWTO (R_PPC64_TPREL16_HI, | |
1516 | 16, /* rightshift */ | |
1517 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1518 | 16, /* bitsize */ | |
1519 | FALSE, /* pc_relative */ | |
1520 | 0, /* bitpos */ | |
1521 | complain_overflow_dont, /* complain_on_overflow */ | |
1522 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1523 | "R_PPC64_TPREL16_HI", /* name */ | |
1524 | FALSE, /* partial_inplace */ | |
1525 | 0, /* src_mask */ | |
1526 | 0xffff, /* dst_mask */ | |
1527 | FALSE), /* pcrel_offset */ | |
1528 | ||
1529 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1530 | HOWTO (R_PPC64_TPREL16_HA, | |
1531 | 16, /* rightshift */ | |
1532 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1533 | 16, /* bitsize */ | |
1534 | FALSE, /* pc_relative */ | |
1535 | 0, /* bitpos */ | |
1536 | complain_overflow_dont, /* complain_on_overflow */ | |
1537 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1538 | "R_PPC64_TPREL16_HA", /* name */ | |
1539 | FALSE, /* partial_inplace */ | |
1540 | 0, /* src_mask */ | |
1541 | 0xffff, /* dst_mask */ | |
1542 | FALSE), /* pcrel_offset */ | |
1543 | ||
1544 | /* Like TPREL16_HI, but next higher group of 16 bits. */ | |
1545 | HOWTO (R_PPC64_TPREL16_HIGHER, | |
1546 | 32, /* rightshift */ | |
1547 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1548 | 16, /* bitsize */ | |
1549 | FALSE, /* pc_relative */ | |
1550 | 0, /* bitpos */ | |
1551 | complain_overflow_dont, /* complain_on_overflow */ | |
1552 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1553 | "R_PPC64_TPREL16_HIGHER", /* name */ | |
1554 | FALSE, /* partial_inplace */ | |
1555 | 0, /* src_mask */ | |
1556 | 0xffff, /* dst_mask */ | |
1557 | FALSE), /* pcrel_offset */ | |
1558 | ||
1559 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ | |
1560 | HOWTO (R_PPC64_TPREL16_HIGHERA, | |
1561 | 32, /* rightshift */ | |
1562 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1563 | 16, /* bitsize */ | |
1564 | FALSE, /* pc_relative */ | |
1565 | 0, /* bitpos */ | |
1566 | complain_overflow_dont, /* complain_on_overflow */ | |
1567 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1568 | "R_PPC64_TPREL16_HIGHERA", /* name */ | |
1569 | FALSE, /* partial_inplace */ | |
1570 | 0, /* src_mask */ | |
1571 | 0xffff, /* dst_mask */ | |
1572 | FALSE), /* pcrel_offset */ | |
1573 | ||
1574 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ | |
1575 | HOWTO (R_PPC64_TPREL16_HIGHEST, | |
1576 | 48, /* rightshift */ | |
1577 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1578 | 16, /* bitsize */ | |
1579 | FALSE, /* pc_relative */ | |
1580 | 0, /* bitpos */ | |
1581 | complain_overflow_dont, /* complain_on_overflow */ | |
1582 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1583 | "R_PPC64_TPREL16_HIGHEST", /* name */ | |
1584 | FALSE, /* partial_inplace */ | |
1585 | 0, /* src_mask */ | |
1586 | 0xffff, /* dst_mask */ | |
1587 | FALSE), /* pcrel_offset */ | |
1588 | ||
1589 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1590 | HOWTO (R_PPC64_TPREL16_HIGHESTA, | |
1591 | 48, /* rightshift */ | |
1592 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1593 | 16, /* bitsize */ | |
1594 | FALSE, /* pc_relative */ | |
1595 | 0, /* bitpos */ | |
1596 | complain_overflow_dont, /* complain_on_overflow */ | |
1597 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1598 | "R_PPC64_TPREL16_HIGHESTA", /* name */ | |
1599 | FALSE, /* partial_inplace */ | |
1600 | 0, /* src_mask */ | |
1601 | 0xffff, /* dst_mask */ | |
1602 | FALSE), /* pcrel_offset */ | |
1603 | ||
1604 | /* Like TPREL16, but for insns with a DS field. */ | |
1605 | HOWTO (R_PPC64_TPREL16_DS, | |
1606 | 0, /* rightshift */ | |
1607 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1608 | 16, /* bitsize */ | |
1609 | FALSE, /* pc_relative */ | |
1610 | 0, /* bitpos */ | |
1611 | complain_overflow_signed, /* complain_on_overflow */ | |
1612 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1613 | "R_PPC64_TPREL16_DS", /* name */ | |
1614 | FALSE, /* partial_inplace */ | |
1615 | 0, /* src_mask */ | |
1616 | 0xfffc, /* dst_mask */ | |
1617 | FALSE), /* pcrel_offset */ | |
1618 | ||
1619 | /* Like TPREL16_DS, but no overflow. */ | |
1620 | HOWTO (R_PPC64_TPREL16_LO_DS, | |
1621 | 0, /* rightshift */ | |
1622 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1623 | 16, /* bitsize */ | |
1624 | FALSE, /* pc_relative */ | |
1625 | 0, /* bitpos */ | |
1626 | complain_overflow_dont, /* complain_on_overflow */ | |
1627 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1628 | "R_PPC64_TPREL16_LO_DS", /* name */ | |
1629 | FALSE, /* partial_inplace */ | |
1630 | 0, /* src_mask */ | |
1631 | 0xfffc, /* dst_mask */ | |
1632 | FALSE), /* pcrel_offset */ | |
1633 | ||
1634 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1635 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1636 | to the first entry relative to the TOC base (r2). */ | |
1637 | HOWTO (R_PPC64_GOT_TLSGD16, | |
1638 | 0, /* rightshift */ | |
1639 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1640 | 16, /* bitsize */ | |
1641 | FALSE, /* pc_relative */ | |
1642 | 0, /* bitpos */ | |
1643 | complain_overflow_signed, /* complain_on_overflow */ | |
1644 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1645 | "R_PPC64_GOT_TLSGD16", /* name */ | |
b34976b6 | 1646 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1647 | 0, /* src_mask */ |
1648 | 0xffff, /* dst_mask */ | |
b34976b6 | 1649 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1650 | |
411e1bfb AM |
1651 | /* Like GOT_TLSGD16, but no overflow. */ |
1652 | HOWTO (R_PPC64_GOT_TLSGD16_LO, | |
5bd4f169 AM |
1653 | 0, /* rightshift */ |
1654 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1655 | 16, /* bitsize */ | |
b34976b6 | 1656 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1657 | 0, /* bitpos */ |
1658 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1659 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1660 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
b34976b6 | 1661 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1662 | 0, /* src_mask */ |
1663 | 0xffff, /* dst_mask */ | |
b34976b6 | 1664 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1665 | |
411e1bfb AM |
1666 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1667 | HOWTO (R_PPC64_GOT_TLSGD16_HI, | |
5bd4f169 AM |
1668 | 16, /* rightshift */ |
1669 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1670 | 16, /* bitsize */ | |
b34976b6 | 1671 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1672 | 0, /* bitpos */ |
1673 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1674 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1675 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
b34976b6 | 1676 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1677 | 0, /* src_mask */ |
1678 | 0xffff, /* dst_mask */ | |
b34976b6 | 1679 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1680 | |
411e1bfb AM |
1681 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1682 | HOWTO (R_PPC64_GOT_TLSGD16_HA, | |
5bd4f169 AM |
1683 | 16, /* rightshift */ |
1684 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1685 | 16, /* bitsize */ | |
b34976b6 | 1686 | FALSE, /* pc_relative */ |
5bd4f169 | 1687 | 0, /* bitpos */ |
411e1bfb | 1688 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1689 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1690 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
b34976b6 | 1691 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1692 | 0, /* src_mask */ |
1693 | 0xffff, /* dst_mask */ | |
b34976b6 | 1694 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1695 | |
411e1bfb AM |
1696 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
1697 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1698 | first entry relative to the TOC base (r2). */ | |
1699 | HOWTO (R_PPC64_GOT_TLSLD16, | |
5bd4f169 AM |
1700 | 0, /* rightshift */ |
1701 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1702 | 16, /* bitsize */ | |
b34976b6 | 1703 | FALSE, /* pc_relative */ |
5bd4f169 | 1704 | 0, /* bitpos */ |
411e1bfb AM |
1705 | complain_overflow_signed, /* complain_on_overflow */ |
1706 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1707 | "R_PPC64_GOT_TLSLD16", /* name */ | |
b34976b6 | 1708 | FALSE, /* partial_inplace */ |
d006db6c | 1709 | 0, /* src_mask */ |
411e1bfb | 1710 | 0xffff, /* dst_mask */ |
b34976b6 | 1711 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1712 | |
411e1bfb AM |
1713 | /* Like GOT_TLSLD16, but no overflow. */ |
1714 | HOWTO (R_PPC64_GOT_TLSLD16_LO, | |
5bd4f169 AM |
1715 | 0, /* rightshift */ |
1716 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1717 | 16, /* bitsize */ | |
b34976b6 | 1718 | FALSE, /* pc_relative */ |
5bd4f169 | 1719 | 0, /* bitpos */ |
411e1bfb AM |
1720 | complain_overflow_dont, /* complain_on_overflow */ |
1721 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1722 | "R_PPC64_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1723 | FALSE, /* partial_inplace */ |
d006db6c | 1724 | 0, /* src_mask */ |
411e1bfb | 1725 | 0xffff, /* dst_mask */ |
b34976b6 | 1726 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1727 | |
411e1bfb AM |
1728 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1729 | HOWTO (R_PPC64_GOT_TLSLD16_HI, | |
1730 | 16, /* rightshift */ | |
5bd4f169 AM |
1731 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1732 | 16, /* bitsize */ | |
b34976b6 | 1733 | FALSE, /* pc_relative */ |
5bd4f169 | 1734 | 0, /* bitpos */ |
411e1bfb | 1735 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1736 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1737 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
b34976b6 | 1738 | FALSE, /* partial_inplace */ |
d006db6c | 1739 | 0, /* src_mask */ |
411e1bfb | 1740 | 0xffff, /* dst_mask */ |
b34976b6 | 1741 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1742 | |
411e1bfb AM |
1743 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1744 | HOWTO (R_PPC64_GOT_TLSLD16_HA, | |
1745 | 16, /* rightshift */ | |
5bd4f169 AM |
1746 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1747 | 16, /* bitsize */ | |
b34976b6 | 1748 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1749 | 0, /* bitpos */ |
1750 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1751 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1752 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
b34976b6 | 1753 | FALSE, /* partial_inplace */ |
d006db6c | 1754 | 0, /* src_mask */ |
411e1bfb | 1755 | 0xffff, /* dst_mask */ |
b34976b6 | 1756 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1757 | |
411e1bfb AM |
1758 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
1759 | the offset to the entry relative to the TOC base (r2). */ | |
1760 | HOWTO (R_PPC64_GOT_DTPREL16_DS, | |
5bd4f169 AM |
1761 | 0, /* rightshift */ |
1762 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1763 | 16, /* bitsize */ | |
b34976b6 | 1764 | FALSE, /* pc_relative */ |
5bd4f169 | 1765 | 0, /* bitpos */ |
411e1bfb | 1766 | complain_overflow_signed, /* complain_on_overflow */ |
805fc799 | 1767 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1768 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
b34976b6 | 1769 | FALSE, /* partial_inplace */ |
d006db6c | 1770 | 0, /* src_mask */ |
5bd4f169 | 1771 | 0xfffc, /* dst_mask */ |
b34976b6 | 1772 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1773 | |
411e1bfb AM |
1774 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
1775 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, | |
5bd4f169 | 1776 | 0, /* rightshift */ |
c061c2d8 AM |
1777 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1778 | 16, /* bitsize */ | |
b34976b6 | 1779 | FALSE, /* pc_relative */ |
5bd4f169 | 1780 | 0, /* bitpos */ |
411e1bfb AM |
1781 | complain_overflow_dont, /* complain_on_overflow */ |
1782 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1783 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ | |
b34976b6 | 1784 | FALSE, /* partial_inplace */ |
d006db6c | 1785 | 0, /* src_mask */ |
c061c2d8 | 1786 | 0xfffc, /* dst_mask */ |
b34976b6 | 1787 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1788 | |
411e1bfb AM |
1789 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
1790 | HOWTO (R_PPC64_GOT_DTPREL16_HI, | |
1791 | 16, /* rightshift */ | |
5bd4f169 AM |
1792 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1793 | 16, /* bitsize */ | |
b34976b6 | 1794 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1795 | 0, /* bitpos */ |
1796 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1797 | ppc64_elf_unhandled_reloc, /* special_function */ |
1798 | "R_PPC64_GOT_DTPREL16_HI", /* name */ | |
b34976b6 | 1799 | FALSE, /* partial_inplace */ |
d006db6c | 1800 | 0, /* src_mask */ |
411e1bfb | 1801 | 0xffff, /* dst_mask */ |
b34976b6 | 1802 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1803 | |
411e1bfb AM |
1804 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1805 | HOWTO (R_PPC64_GOT_DTPREL16_HA, | |
1806 | 16, /* rightshift */ | |
1807 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1808 | 16, /* bitsize */ | |
1809 | FALSE, /* pc_relative */ | |
1810 | 0, /* bitpos */ | |
1811 | complain_overflow_dont, /* complain_on_overflow */ | |
1812 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1813 | "R_PPC64_GOT_DTPREL16_HA", /* name */ | |
1814 | FALSE, /* partial_inplace */ | |
1815 | 0, /* src_mask */ | |
1816 | 0xffff, /* dst_mask */ | |
1817 | FALSE), /* pcrel_offset */ | |
1818 | ||
1819 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the | |
1820 | offset to the entry relative to the TOC base (r2). */ | |
1821 | HOWTO (R_PPC64_GOT_TPREL16_DS, | |
5bd4f169 AM |
1822 | 0, /* rightshift */ |
1823 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1824 | 16, /* bitsize */ | |
b34976b6 | 1825 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1826 | 0, /* bitpos */ |
1827 | complain_overflow_signed, /* complain_on_overflow */ | |
411e1bfb AM |
1828 | ppc64_elf_unhandled_reloc, /* special_function */ |
1829 | "R_PPC64_GOT_TPREL16_DS", /* name */ | |
b34976b6 | 1830 | FALSE, /* partial_inplace */ |
d006db6c | 1831 | 0, /* src_mask */ |
ad8e1ba5 | 1832 | 0xfffc, /* dst_mask */ |
b34976b6 | 1833 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1834 | |
411e1bfb AM |
1835 | /* Like GOT_TPREL16_DS, but no overflow. */ |
1836 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, | |
5bd4f169 AM |
1837 | 0, /* rightshift */ |
1838 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1839 | 16, /* bitsize */ | |
b34976b6 | 1840 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1841 | 0, /* bitpos */ |
1842 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1843 | ppc64_elf_unhandled_reloc, /* special_function */ |
1844 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ | |
b34976b6 | 1845 | FALSE, /* partial_inplace */ |
d006db6c | 1846 | 0, /* src_mask */ |
ad8e1ba5 | 1847 | 0xfffc, /* dst_mask */ |
b34976b6 | 1848 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1849 | |
411e1bfb AM |
1850 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
1851 | HOWTO (R_PPC64_GOT_TPREL16_HI, | |
1852 | 16, /* rightshift */ | |
5bd4f169 AM |
1853 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1854 | 16, /* bitsize */ | |
b34976b6 | 1855 | FALSE, /* pc_relative */ |
5bd4f169 | 1856 | 0, /* bitpos */ |
411e1bfb | 1857 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1858 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1859 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
b34976b6 | 1860 | FALSE, /* partial_inplace */ |
d006db6c | 1861 | 0, /* src_mask */ |
411e1bfb | 1862 | 0xffff, /* dst_mask */ |
b34976b6 | 1863 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1864 | |
411e1bfb AM |
1865 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
1866 | HOWTO (R_PPC64_GOT_TPREL16_HA, | |
1867 | 16, /* rightshift */ | |
5bd4f169 AM |
1868 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1869 | 16, /* bitsize */ | |
b34976b6 | 1870 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1871 | 0, /* bitpos */ |
1872 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1873 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1874 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
b34976b6 | 1875 | FALSE, /* partial_inplace */ |
d006db6c | 1876 | 0, /* src_mask */ |
411e1bfb | 1877 | 0xffff, /* dst_mask */ |
b34976b6 | 1878 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1879 | |
25f23106 AM |
1880 | HOWTO (R_PPC64_JMP_IREL, /* type */ |
1881 | 0, /* rightshift */ | |
1882 | 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
1883 | 0, /* bitsize */ | |
1884 | FALSE, /* pc_relative */ | |
1885 | 0, /* bitpos */ | |
1886 | complain_overflow_dont, /* complain_on_overflow */ | |
1887 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1888 | "R_PPC64_JMP_IREL", /* name */ | |
1889 | FALSE, /* partial_inplace */ | |
1890 | 0, /* src_mask */ | |
1891 | 0, /* dst_mask */ | |
1892 | FALSE), /* pcrel_offset */ | |
1893 | ||
e054468f AM |
1894 | HOWTO (R_PPC64_IRELATIVE, /* type */ |
1895 | 0, /* rightshift */ | |
1896 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
1897 | 64, /* bitsize */ | |
1898 | FALSE, /* pc_relative */ | |
1899 | 0, /* bitpos */ | |
1900 | complain_overflow_dont, /* complain_on_overflow */ | |
1901 | bfd_elf_generic_reloc, /* special_function */ | |
1902 | "R_PPC64_IRELATIVE", /* name */ | |
1903 | FALSE, /* partial_inplace */ | |
1904 | 0, /* src_mask */ | |
1905 | ONES (64), /* dst_mask */ | |
1906 | FALSE), /* pcrel_offset */ | |
1907 | ||
25f23106 AM |
1908 | /* A 16 bit relative relocation. */ |
1909 | HOWTO (R_PPC64_REL16, /* type */ | |
1910 | 0, /* rightshift */ | |
1911 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1912 | 16, /* bitsize */ | |
1913 | TRUE, /* pc_relative */ | |
1914 | 0, /* bitpos */ | |
1915 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1916 | bfd_elf_generic_reloc, /* special_function */ | |
1917 | "R_PPC64_REL16", /* name */ | |
1918 | FALSE, /* partial_inplace */ | |
1919 | 0, /* src_mask */ | |
1920 | 0xffff, /* dst_mask */ | |
1921 | TRUE), /* pcrel_offset */ | |
1922 | ||
1923 | /* A 16 bit relative relocation without overflow. */ | |
1924 | HOWTO (R_PPC64_REL16_LO, /* type */ | |
1925 | 0, /* rightshift */ | |
1926 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1927 | 16, /* bitsize */ | |
1928 | TRUE, /* pc_relative */ | |
1929 | 0, /* bitpos */ | |
1930 | complain_overflow_dont,/* complain_on_overflow */ | |
1931 | bfd_elf_generic_reloc, /* special_function */ | |
1932 | "R_PPC64_REL16_LO", /* name */ | |
1933 | FALSE, /* partial_inplace */ | |
1934 | 0, /* src_mask */ | |
1935 | 0xffff, /* dst_mask */ | |
1936 | TRUE), /* pcrel_offset */ | |
1937 | ||
1938 | /* The high order 16 bits of a relative address. */ | |
1939 | HOWTO (R_PPC64_REL16_HI, /* type */ | |
1940 | 16, /* rightshift */ | |
1941 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1942 | 16, /* bitsize */ | |
1943 | TRUE, /* pc_relative */ | |
1944 | 0, /* bitpos */ | |
1945 | complain_overflow_dont, /* complain_on_overflow */ | |
1946 | bfd_elf_generic_reloc, /* special_function */ | |
1947 | "R_PPC64_REL16_HI", /* name */ | |
1948 | FALSE, /* partial_inplace */ | |
1949 | 0, /* src_mask */ | |
1950 | 0xffff, /* dst_mask */ | |
1951 | TRUE), /* pcrel_offset */ | |
1952 | ||
1953 | /* The high order 16 bits of a relative address, plus 1 if the contents of | |
1954 | the low 16 bits, treated as a signed number, is negative. */ | |
1955 | HOWTO (R_PPC64_REL16_HA, /* type */ | |
1956 | 16, /* rightshift */ | |
1957 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1958 | 16, /* bitsize */ | |
1959 | TRUE, /* pc_relative */ | |
1960 | 0, /* bitpos */ | |
1961 | complain_overflow_dont, /* complain_on_overflow */ | |
1962 | ppc64_elf_ha_reloc, /* special_function */ | |
1963 | "R_PPC64_REL16_HA", /* name */ | |
1964 | FALSE, /* partial_inplace */ | |
1965 | 0, /* src_mask */ | |
1966 | 0xffff, /* dst_mask */ | |
1967 | TRUE), /* pcrel_offset */ | |
1968 | ||
5bd4f169 AM |
1969 | /* GNU extension to record C++ vtable hierarchy. */ |
1970 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1971 | 0, /* rightshift */ | |
1972 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1973 | 0, /* bitsize */ | |
b34976b6 | 1974 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1975 | 0, /* bitpos */ |
1976 | complain_overflow_dont, /* complain_on_overflow */ | |
1977 | NULL, /* special_function */ | |
1978 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1979 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1980 | 0, /* src_mask */ |
1981 | 0, /* dst_mask */ | |
b34976b6 | 1982 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1983 | |
1984 | /* GNU extension to record C++ vtable member usage. */ | |
1985 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1986 | 0, /* rightshift */ | |
1987 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1988 | 0, /* bitsize */ | |
b34976b6 | 1989 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1990 | 0, /* bitpos */ |
1991 | complain_overflow_dont, /* complain_on_overflow */ | |
1992 | NULL, /* special_function */ | |
1993 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1994 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1995 | 0, /* src_mask */ |
1996 | 0, /* dst_mask */ | |
b34976b6 | 1997 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1998 | }; |
1999 | ||
2000 | \f | |
2001 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
2002 | be done. */ | |
2003 | ||
2004 | static void | |
4ce794b7 | 2005 | ppc_howto_init (void) |
5bd4f169 AM |
2006 | { |
2007 | unsigned int i, type; | |
2008 | ||
2009 | for (i = 0; | |
2010 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
2011 | i++) | |
2012 | { | |
2013 | type = ppc64_elf_howto_raw[i].type; | |
2014 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
2015 | / sizeof (ppc64_elf_howto_table[0]))); | |
2016 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
2017 | } | |
2018 | } | |
2019 | ||
2020 | static reloc_howto_type * | |
4ce794b7 AM |
2021 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
2022 | bfd_reloc_code_real_type code) | |
5bd4f169 | 2023 | { |
411e1bfb | 2024 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
5bd4f169 AM |
2025 | |
2026 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
2027 | /* Initialize howto table if needed. */ | |
2028 | ppc_howto_init (); | |
2029 | ||
4ce794b7 | 2030 | switch (code) |
5bd4f169 AM |
2031 | { |
2032 | default: | |
4ce794b7 | 2033 | return NULL; |
5bd4f169 | 2034 | |
411e1bfb AM |
2035 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
2036 | break; | |
2037 | case BFD_RELOC_32: r = R_PPC64_ADDR32; | |
2038 | break; | |
2039 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; | |
2040 | break; | |
2041 | case BFD_RELOC_16: r = R_PPC64_ADDR16; | |
2042 | break; | |
2043 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; | |
2044 | break; | |
2045 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; | |
2046 | break; | |
2047 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; | |
5bd4f169 | 2048 | break; |
411e1bfb | 2049 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
5bd4f169 | 2050 | break; |
411e1bfb | 2051 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
5bd4f169 | 2052 | break; |
411e1bfb | 2053 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
5bd4f169 | 2054 | break; |
411e1bfb | 2055 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
5bd4f169 | 2056 | break; |
411e1bfb | 2057 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
5bd4f169 | 2058 | break; |
411e1bfb | 2059 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
5bd4f169 | 2060 | break; |
411e1bfb | 2061 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
5bd4f169 | 2062 | break; |
411e1bfb | 2063 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
5bd4f169 | 2064 | break; |
411e1bfb | 2065 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
5bd4f169 | 2066 | break; |
411e1bfb | 2067 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
5bd4f169 | 2068 | break; |
411e1bfb | 2069 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
5bd4f169 | 2070 | break; |
411e1bfb | 2071 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
5bd4f169 | 2072 | break; |
411e1bfb | 2073 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
5bd4f169 | 2074 | break; |
411e1bfb | 2075 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
5bd4f169 | 2076 | break; |
411e1bfb | 2077 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
5bd4f169 | 2078 | break; |
411e1bfb | 2079 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
5bd4f169 | 2080 | break; |
411e1bfb | 2081 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
5bd4f169 | 2082 | break; |
411e1bfb | 2083 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
5bd4f169 | 2084 | break; |
411e1bfb | 2085 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
5bd4f169 | 2086 | break; |
411e1bfb | 2087 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
5bd4f169 | 2088 | break; |
411e1bfb | 2089 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
5bd4f169 | 2090 | break; |
411e1bfb | 2091 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
5bd4f169 | 2092 | break; |
411e1bfb | 2093 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
5bd4f169 | 2094 | break; |
411e1bfb | 2095 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
5bd4f169 | 2096 | break; |
411e1bfb | 2097 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
5bd4f169 | 2098 | break; |
411e1bfb | 2099 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
5bd4f169 | 2100 | break; |
411e1bfb | 2101 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
5bd4f169 | 2102 | break; |
411e1bfb | 2103 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
5bd4f169 | 2104 | break; |
411e1bfb | 2105 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
5bd4f169 | 2106 | break; |
411e1bfb | 2107 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
5bd4f169 | 2108 | break; |
411e1bfb | 2109 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
5bd4f169 | 2110 | break; |
411e1bfb | 2111 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
5bd4f169 | 2112 | break; |
411e1bfb | 2113 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
5bd4f169 | 2114 | break; |
411e1bfb | 2115 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
5bd4f169 | 2116 | break; |
411e1bfb | 2117 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
5bd4f169 | 2118 | break; |
411e1bfb | 2119 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
5bd4f169 | 2120 | break; |
411e1bfb | 2121 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
5bd4f169 | 2122 | break; |
411e1bfb | 2123 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
5bd4f169 | 2124 | break; |
411e1bfb | 2125 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
5bd4f169 | 2126 | break; |
411e1bfb | 2127 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
5bd4f169 | 2128 | break; |
411e1bfb | 2129 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
5bd4f169 | 2130 | break; |
411e1bfb | 2131 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
5bd4f169 | 2132 | break; |
411e1bfb | 2133 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
5bd4f169 | 2134 | break; |
411e1bfb | 2135 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
5bd4f169 | 2136 | break; |
411e1bfb | 2137 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
5bd4f169 | 2138 | break; |
411e1bfb | 2139 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
5bd4f169 | 2140 | break; |
411e1bfb | 2141 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
5bd4f169 | 2142 | break; |
411e1bfb | 2143 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
5bd4f169 | 2144 | break; |
411e1bfb | 2145 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
5bd4f169 | 2146 | break; |
411e1bfb | 2147 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
5bd4f169 | 2148 | break; |
411e1bfb | 2149 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
5bd4f169 | 2150 | break; |
411e1bfb | 2151 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
5bd4f169 | 2152 | break; |
411e1bfb | 2153 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
5bd4f169 | 2154 | break; |
727fc41e AM |
2155 | case BFD_RELOC_PPC_TLSGD: r = R_PPC64_TLSGD; |
2156 | break; | |
2157 | case BFD_RELOC_PPC_TLSLD: r = R_PPC64_TLSLD; | |
2158 | break; | |
411e1bfb | 2159 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
5bd4f169 | 2160 | break; |
411e1bfb | 2161 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
5bd4f169 | 2162 | break; |
411e1bfb | 2163 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
5bd4f169 | 2164 | break; |
411e1bfb | 2165 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
5bd4f169 | 2166 | break; |
411e1bfb | 2167 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
5bd4f169 | 2168 | break; |
411e1bfb | 2169 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
5bd4f169 | 2170 | break; |
411e1bfb AM |
2171 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
2172 | break; | |
2173 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; | |
2174 | break; | |
2175 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; | |
2176 | break; | |
2177 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; | |
2178 | break; | |
2179 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; | |
2180 | break; | |
2181 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; | |
2182 | break; | |
2183 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; | |
2184 | break; | |
2185 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; | |
2186 | break; | |
2187 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; | |
2188 | break; | |
2189 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; | |
2190 | break; | |
2191 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; | |
2192 | break; | |
2193 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; | |
2194 | break; | |
2195 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; | |
2196 | break; | |
2197 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; | |
2198 | break; | |
2199 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; | |
2200 | break; | |
2201 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; | |
2202 | break; | |
2203 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; | |
2204 | break; | |
2205 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; | |
2206 | break; | |
2207 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; | |
2208 | break; | |
2209 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; | |
2210 | break; | |
2211 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; | |
2212 | break; | |
2213 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; | |
2214 | break; | |
2215 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; | |
2216 | break; | |
2217 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; | |
2218 | break; | |
2219 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; | |
2220 | break; | |
2221 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; | |
2222 | break; | |
2223 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; | |
2224 | break; | |
2225 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; | |
2226 | break; | |
2227 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; | |
2228 | break; | |
2229 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; | |
2230 | break; | |
2231 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; | |
2232 | break; | |
2233 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; | |
2234 | break; | |
2235 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; | |
2236 | break; | |
25f23106 AM |
2237 | case BFD_RELOC_16_PCREL: r = R_PPC64_REL16; |
2238 | break; | |
2239 | case BFD_RELOC_LO16_PCREL: r = R_PPC64_REL16_LO; | |
2240 | break; | |
2241 | case BFD_RELOC_HI16_PCREL: r = R_PPC64_REL16_HI; | |
2242 | break; | |
2243 | case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA; | |
2244 | break; | |
411e1bfb AM |
2245 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; |
2246 | break; | |
2247 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; | |
5bd4f169 AM |
2248 | break; |
2249 | } | |
2250 | ||
4ce794b7 | 2251 | return ppc64_elf_howto_table[r]; |
5bd4f169 AM |
2252 | }; |
2253 | ||
157090f7 AM |
2254 | static reloc_howto_type * |
2255 | ppc64_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
2256 | const char *r_name) | |
2257 | { | |
2258 | unsigned int i; | |
2259 | ||
2260 | for (i = 0; | |
2261 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
2262 | i++) | |
2263 | if (ppc64_elf_howto_raw[i].name != NULL | |
2264 | && strcasecmp (ppc64_elf_howto_raw[i].name, r_name) == 0) | |
2265 | return &ppc64_elf_howto_raw[i]; | |
2266 | ||
2267 | return NULL; | |
2268 | } | |
2269 | ||
5bd4f169 AM |
2270 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
2271 | ||
2272 | static void | |
4ce794b7 AM |
2273 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
2274 | Elf_Internal_Rela *dst) | |
5bd4f169 | 2275 | { |
65f38f15 AM |
2276 | unsigned int type; |
2277 | ||
ef60b7ff | 2278 | /* Initialize howto table if needed. */ |
5bd4f169 | 2279 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
2280 | ppc_howto_init (); |
2281 | ||
65f38f15 | 2282 | type = ELF64_R_TYPE (dst->r_info); |
d0fb9a8d JJ |
2283 | if (type >= (sizeof (ppc64_elf_howto_table) |
2284 | / sizeof (ppc64_elf_howto_table[0]))) | |
2285 | { | |
2286 | (*_bfd_error_handler) (_("%B: invalid relocation type %d"), | |
3ec2b351 NC |
2287 | abfd, (int) type); |
2288 | type = R_PPC64_NONE; | |
d0fb9a8d | 2289 | } |
65f38f15 | 2290 | cache_ptr->howto = ppc64_elf_howto_table[type]; |
5bd4f169 AM |
2291 | } |
2292 | ||
04c9666a | 2293 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
2294 | |
2295 | static bfd_reloc_status_type | |
4ce794b7 AM |
2296 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2297 | void *data, asection *input_section, | |
2298 | bfd *output_bfd, char **error_message) | |
5bd4f169 | 2299 | { |
805fc799 AM |
2300 | /* If this is a relocatable link (output_bfd test tells us), just |
2301 | call the generic function. Any adjustment will be done at final | |
2302 | link time. */ | |
2303 | if (output_bfd != NULL) | |
cedb70c5 | 2304 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2305 | input_section, output_bfd, error_message); |
2306 | ||
2307 | /* Adjust the addend for sign extension of the low 16 bits. | |
2308 | We won't actually be using the low 16 bits, so trashing them | |
2309 | doesn't matter. */ | |
2310 | reloc_entry->addend += 0x8000; | |
2311 | return bfd_reloc_continue; | |
2312 | } | |
5bd4f169 | 2313 | |
2441e016 AM |
2314 | static bfd_reloc_status_type |
2315 | ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
2316 | void *data, asection *input_section, | |
2317 | bfd *output_bfd, char **error_message) | |
2318 | { | |
2319 | if (output_bfd != NULL) | |
2320 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
2321 | input_section, output_bfd, error_message); | |
2322 | ||
699733f6 AM |
2323 | if (strcmp (symbol->section->name, ".opd") == 0 |
2324 | && (symbol->section->owner->flags & DYNAMIC) == 0) | |
2441e016 AM |
2325 | { |
2326 | bfd_vma dest = opd_entry_value (symbol->section, | |
2327 | symbol->value + reloc_entry->addend, | |
2328 | NULL, NULL); | |
2329 | if (dest != (bfd_vma) -1) | |
2330 | reloc_entry->addend = dest - (symbol->value | |
2331 | + symbol->section->output_section->vma | |
2332 | + symbol->section->output_offset); | |
2333 | } | |
2334 | return bfd_reloc_continue; | |
2335 | } | |
2336 | ||
805fc799 | 2337 | static bfd_reloc_status_type |
4ce794b7 AM |
2338 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2339 | void *data, asection *input_section, | |
2340 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2341 | { |
2342 | long insn; | |
04c9666a | 2343 | enum elf_ppc64_reloc_type r_type; |
805fc799 AM |
2344 | bfd_size_type octets; |
2345 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 2346 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
2347 | |
2348 | /* If this is a relocatable link (output_bfd test tells us), just | |
2349 | call the generic function. Any adjustment will be done at final | |
2350 | link time. */ | |
5bd4f169 | 2351 | if (output_bfd != NULL) |
cedb70c5 | 2352 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2353 | input_section, output_bfd, error_message); |
2354 | ||
2355 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2356 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2357 | insn &= ~(0x01 << 21); | |
4ce794b7 | 2358 | r_type = reloc_entry->howto->type; |
805fc799 AM |
2359 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
2360 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 2361 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
2362 | |
2363 | if (is_power4) | |
5bd4f169 | 2364 | { |
805fc799 AM |
2365 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
2366 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
2367 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
2368 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
2369 | insn |= 0x02 << 21; | |
2370 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
2371 | insn |= 0x08 << 21; | |
2372 | else | |
2441e016 | 2373 | goto out; |
5bd4f169 | 2374 | } |
805fc799 AM |
2375 | else |
2376 | { | |
2377 | bfd_vma target = 0; | |
2378 | bfd_vma from; | |
5bd4f169 | 2379 | |
805fc799 AM |
2380 | if (!bfd_is_com_section (symbol->section)) |
2381 | target = symbol->value; | |
2382 | target += symbol->section->output_section->vma; | |
2383 | target += symbol->section->output_offset; | |
2384 | target += reloc_entry->addend; | |
5bd4f169 | 2385 | |
805fc799 AM |
2386 | from = (reloc_entry->address |
2387 | + input_section->output_offset | |
2388 | + input_section->output_section->vma); | |
5bd4f169 | 2389 | |
805fc799 AM |
2390 | /* Invert 'y' bit if not the default. */ |
2391 | if ((bfd_signed_vma) (target - from) < 0) | |
2392 | insn ^= 0x01 << 21; | |
2393 | } | |
4ce794b7 | 2394 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
2441e016 AM |
2395 | out: |
2396 | return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data, | |
2397 | input_section, output_bfd, error_message); | |
805fc799 | 2398 | } |
5bd4f169 | 2399 | |
805fc799 | 2400 | static bfd_reloc_status_type |
4ce794b7 AM |
2401 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2402 | void *data, asection *input_section, | |
2403 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2404 | { |
2405 | /* If this is a relocatable link (output_bfd test tells us), just | |
2406 | call the generic function. Any adjustment will be done at final | |
2407 | link time. */ | |
2408 | if (output_bfd != NULL) | |
cedb70c5 | 2409 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 2410 | input_section, output_bfd, error_message); |
5bd4f169 | 2411 | |
805fc799 AM |
2412 | /* Subtract the symbol section base address. */ |
2413 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
2414 | return bfd_reloc_continue; |
2415 | } | |
2416 | ||
805fc799 | 2417 | static bfd_reloc_status_type |
4ce794b7 AM |
2418 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2419 | void *data, asection *input_section, | |
2420 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2421 | { |
2422 | /* If this is a relocatable link (output_bfd test tells us), just | |
2423 | call the generic function. Any adjustment will be done at final | |
2424 | link time. */ | |
2425 | if (output_bfd != NULL) | |
cedb70c5 | 2426 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2427 | input_section, output_bfd, error_message); |
2428 | ||
2429 | /* Subtract the symbol section base address. */ | |
2430 | reloc_entry->addend -= symbol->section->output_section->vma; | |
2431 | ||
2432 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2433 | reloc_entry->addend += 0x8000; | |
2434 | return bfd_reloc_continue; | |
2435 | } | |
2436 | ||
2437 | static bfd_reloc_status_type | |
4ce794b7 AM |
2438 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2439 | void *data, asection *input_section, | |
2440 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2441 | { |
2442 | bfd_vma TOCstart; | |
2443 | ||
2444 | /* If this is a relocatable link (output_bfd test tells us), just | |
2445 | call the generic function. Any adjustment will be done at final | |
2446 | link time. */ | |
2447 | if (output_bfd != NULL) | |
cedb70c5 | 2448 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2449 | input_section, output_bfd, error_message); |
2450 | ||
2451 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2452 | if (TOCstart == 0) | |
2453 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2454 | ||
2455 | /* Subtract the TOC base address. */ | |
2456 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2457 | return bfd_reloc_continue; | |
2458 | } | |
2459 | ||
2460 | static bfd_reloc_status_type | |
4ce794b7 AM |
2461 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2462 | void *data, asection *input_section, | |
2463 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2464 | { |
2465 | bfd_vma TOCstart; | |
2466 | ||
2467 | /* If this is a relocatable link (output_bfd test tells us), just | |
2468 | call the generic function. Any adjustment will be done at final | |
2469 | link time. */ | |
2470 | if (output_bfd != NULL) | |
cedb70c5 | 2471 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2472 | input_section, output_bfd, error_message); |
2473 | ||
2474 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2475 | if (TOCstart == 0) | |
2476 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2477 | ||
2478 | /* Subtract the TOC base address. */ | |
2479 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2480 | ||
2481 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2482 | reloc_entry->addend += 0x8000; | |
2483 | return bfd_reloc_continue; | |
2484 | } | |
2485 | ||
2486 | static bfd_reloc_status_type | |
4ce794b7 AM |
2487 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2488 | void *data, asection *input_section, | |
2489 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2490 | { |
2491 | bfd_vma TOCstart; | |
2492 | bfd_size_type octets; | |
2493 | ||
2494 | /* If this is a relocatable link (output_bfd test tells us), just | |
2495 | call the generic function. Any adjustment will be done at final | |
2496 | link time. */ | |
2497 | if (output_bfd != NULL) | |
cedb70c5 | 2498 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2499 | input_section, output_bfd, error_message); |
2500 | ||
2501 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2502 | if (TOCstart == 0) | |
2503 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2504 | ||
2505 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2506 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
2507 | return bfd_reloc_ok; | |
2508 | } | |
2509 | ||
2510 | static bfd_reloc_status_type | |
4ce794b7 AM |
2511 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2512 | void *data, asection *input_section, | |
2513 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2514 | { |
2515 | /* If this is a relocatable link (output_bfd test tells us), just | |
2516 | call the generic function. Any adjustment will be done at final | |
2517 | link time. */ | |
2518 | if (output_bfd != NULL) | |
cedb70c5 | 2519 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2520 | input_section, output_bfd, error_message); |
2521 | ||
2522 | if (error_message != NULL) | |
2523 | { | |
2524 | static char buf[60]; | |
2525 | sprintf (buf, "generic linker can't handle %s", | |
2526 | reloc_entry->howto->name); | |
2527 | *error_message = buf; | |
2528 | } | |
2529 | return bfd_reloc_dangerous; | |
2530 | } | |
2531 | ||
927be08e AM |
2532 | /* Track GOT entries needed for a given symbol. We might need more |
2533 | than one got entry per symbol. */ | |
2534 | struct got_entry | |
2535 | { | |
2536 | struct got_entry *next; | |
2537 | ||
2538 | /* The symbol addend that we'll be placing in the GOT. */ | |
2539 | bfd_vma addend; | |
2540 | ||
2541 | /* Unlike other ELF targets, we use separate GOT entries for the same | |
2542 | symbol referenced from different input files. This is to support | |
2543 | automatic multiple TOC/GOT sections, where the TOC base can vary | |
2544 | from one input file to another. After partitioning into TOC groups | |
2545 | we merge entries within the group. | |
2546 | ||
2547 | Point to the BFD owning this GOT entry. */ | |
2548 | bfd *owner; | |
2549 | ||
2550 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, | |
2551 | TLS_TPREL or TLS_DTPREL for tls entries. */ | |
f961d9dd | 2552 | unsigned char tls_type; |
927be08e AM |
2553 | |
2554 | /* Non-zero if got.ent points to real entry. */ | |
f961d9dd | 2555 | unsigned char is_indirect; |
927be08e AM |
2556 | |
2557 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ | |
2558 | union | |
2559 | { | |
2560 | bfd_signed_vma refcount; | |
2561 | bfd_vma offset; | |
2562 | struct got_entry *ent; | |
2563 | } got; | |
2564 | }; | |
2565 | ||
2566 | /* The same for PLT. */ | |
2567 | struct plt_entry | |
2568 | { | |
2569 | struct plt_entry *next; | |
2570 | ||
2571 | bfd_vma addend; | |
2572 | ||
2573 | union | |
2574 | { | |
2575 | bfd_signed_vma refcount; | |
2576 | bfd_vma offset; | |
2577 | } plt; | |
2578 | }; | |
2579 | ||
e717da7e AM |
2580 | struct ppc64_elf_obj_tdata |
2581 | { | |
2582 | struct elf_obj_tdata elf; | |
2583 | ||
2584 | /* Shortcuts to dynamic linker sections. */ | |
2585 | asection *got; | |
2586 | asection *relgot; | |
2587 | ||
b3fac117 AM |
2588 | /* Used during garbage collection. We attach global symbols defined |
2589 | on removed .opd entries to this section so that the sym is removed. */ | |
2590 | asection *deleted_section; | |
81688140 | 2591 | |
927be08e | 2592 | /* TLS local dynamic got entry handling. Support for multiple GOT |
e717da7e | 2593 | sections means we potentially need one of these for each input bfd. */ |
927be08e | 2594 | struct got_entry tlsld_got; |
8860955f AM |
2595 | |
2596 | /* A copy of relocs before they are modified for --emit-relocs. */ | |
2597 | Elf_Internal_Rela *opd_relocs; | |
d77c8a4b AM |
2598 | |
2599 | /* Nonzero if this bfd has small toc/got relocs, ie. that expect | |
2600 | the reloc to be in the range -32768 to 32767. */ | |
2601 | unsigned int has_small_toc_reloc; | |
e717da7e AM |
2602 | }; |
2603 | ||
2604 | #define ppc64_elf_tdata(bfd) \ | |
2605 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) | |
2606 | ||
2607 | #define ppc64_tlsld_got(bfd) \ | |
2608 | (&ppc64_elf_tdata (bfd)->tlsld_got) | |
2609 | ||
0c8d6e5c AM |
2610 | #define is_ppc64_elf(bfd) \ |
2611 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
4dfe6ac6 | 2612 | && elf_object_id (bfd) == PPC64_ELF_DATA) |
0c8d6e5c | 2613 | |
e717da7e AM |
2614 | /* Override the generic function because we store some extras. */ |
2615 | ||
2616 | static bfd_boolean | |
2617 | ppc64_elf_mkobject (bfd *abfd) | |
2618 | { | |
0ffa91dd | 2619 | return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata), |
4dfe6ac6 | 2620 | PPC64_ELF_DATA); |
e717da7e AM |
2621 | } |
2622 | ||
feee612b AM |
2623 | /* Fix bad default arch selected for a 64 bit input bfd when the |
2624 | default is 32 bit. */ | |
2625 | ||
b34976b6 | 2626 | static bfd_boolean |
4ce794b7 | 2627 | ppc64_elf_object_p (bfd *abfd) |
feee612b AM |
2628 | { |
2629 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
2630 | { | |
2631 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2632 | ||
2633 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
2634 | { | |
2635 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
2636 | abfd->arch_info = abfd->arch_info->next; | |
2637 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
2638 | } | |
2639 | } | |
b34976b6 | 2640 | return TRUE; |
feee612b AM |
2641 | } |
2642 | ||
d37c89e5 AM |
2643 | /* Support for core dump NOTE sections. */ |
2644 | ||
2645 | static bfd_boolean | |
2646 | ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
2647 | { | |
eea6121a | 2648 | size_t offset, size; |
d37c89e5 AM |
2649 | |
2650 | if (note->descsz != 504) | |
2651 | return FALSE; | |
2652 | ||
2653 | /* pr_cursig */ | |
2654 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
2655 | ||
2656 | /* pr_pid */ | |
261b8d08 | 2657 | elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 32); |
d37c89e5 AM |
2658 | |
2659 | /* pr_reg */ | |
2660 | offset = 112; | |
eea6121a | 2661 | size = 384; |
d37c89e5 AM |
2662 | |
2663 | /* Make a ".reg/999" section. */ | |
2664 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
eea6121a | 2665 | size, note->descpos + offset); |
d37c89e5 AM |
2666 | } |
2667 | ||
2668 | static bfd_boolean | |
2669 | ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
2670 | { | |
2671 | if (note->descsz != 136) | |
2672 | return FALSE; | |
2673 | ||
bc989cdc JK |
2674 | elf_tdata (abfd)->core_pid |
2675 | = bfd_get_32 (abfd, note->descdata + 24); | |
d37c89e5 AM |
2676 | elf_tdata (abfd)->core_program |
2677 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |
2678 | elf_tdata (abfd)->core_command | |
2679 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |
2680 | ||
2681 | return TRUE; | |
2682 | } | |
2683 | ||
183e98be AM |
2684 | static char * |
2685 | ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, | |
2686 | ...) | |
2687 | { | |
2688 | switch (note_type) | |
2689 | { | |
2690 | default: | |
2691 | return NULL; | |
2692 | ||
2693 | case NT_PRPSINFO: | |
2694 | { | |
2695 | char data[136]; | |
2696 | va_list ap; | |
2697 | ||
2698 | va_start (ap, note_type); | |
2699 | memset (data, 0, 40); | |
2700 | strncpy (data + 40, va_arg (ap, const char *), 16); | |
2701 | strncpy (data + 56, va_arg (ap, const char *), 80); | |
2702 | va_end (ap); | |
2703 | return elfcore_write_note (abfd, buf, bufsiz, | |
2704 | "CORE", note_type, data, sizeof (data)); | |
2705 | } | |
2706 | ||
2707 | case NT_PRSTATUS: | |
2708 | { | |
2709 | char data[504]; | |
2710 | va_list ap; | |
2711 | long pid; | |
2712 | int cursig; | |
2713 | const void *greg; | |
2714 | ||
2715 | va_start (ap, note_type); | |
2716 | memset (data, 0, 112); | |
2717 | pid = va_arg (ap, long); | |
2718 | bfd_put_32 (abfd, pid, data + 32); | |
2719 | cursig = va_arg (ap, int); | |
2720 | bfd_put_16 (abfd, cursig, data + 12); | |
2721 | greg = va_arg (ap, const void *); | |
2722 | memcpy (data + 112, greg, 384); | |
2723 | memset (data + 496, 0, 8); | |
2724 | va_end (ap); | |
2725 | return elfcore_write_note (abfd, buf, bufsiz, | |
2726 | "CORE", note_type, data, sizeof (data)); | |
2727 | } | |
2728 | } | |
2729 | } | |
2730 | ||
5d35169e AM |
2731 | /* Add extra PPC sections. */ |
2732 | ||
b35d266b | 2733 | static const struct bfd_elf_special_section ppc64_elf_special_sections[]= |
7f4d3958 | 2734 | { |
0112cd26 NC |
2735 | { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, 0 }, |
2736 | { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2737 | { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2738 | { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2739 | { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2740 | { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2741 | { NULL, 0, 0, 0, 0 } | |
5d35169e AM |
2742 | }; |
2743 | ||
7c8fe5c4 AM |
2744 | enum _ppc64_sec_type { |
2745 | sec_normal = 0, | |
2746 | sec_opd = 1, | |
2747 | sec_toc = 2 | |
2748 | }; | |
2749 | ||
f0abc2a1 AM |
2750 | struct _ppc64_elf_section_data |
2751 | { | |
2752 | struct bfd_elf_section_data elf; | |
411e1bfb | 2753 | |
f0abc2a1 AM |
2754 | union |
2755 | { | |
74f0fb50 AM |
2756 | /* An array with one entry for each opd function descriptor. */ |
2757 | struct _opd_sec_data | |
2758 | { | |
2759 | /* Points to the function code section for local opd entries. */ | |
2760 | asection **func_sec; | |
2761 | ||
2762 | /* After editing .opd, adjust references to opd local syms. */ | |
2763 | long *adjust; | |
2764 | } opd; | |
7c8fe5c4 | 2765 | |
3a71aa26 AM |
2766 | /* An array for toc sections, indexed by offset/8. */ |
2767 | struct _toc_sec_data | |
2768 | { | |
2769 | /* Specifies the relocation symbol index used at a given toc offset. */ | |
2770 | unsigned *symndx; | |
2771 | ||
2772 | /* And the relocation addend. */ | |
2773 | bfd_vma *add; | |
2774 | } toc; | |
7c8fe5c4 AM |
2775 | } u; |
2776 | ||
2777 | enum _ppc64_sec_type sec_type:2; | |
411e1bfb | 2778 | |
7c8fe5c4 AM |
2779 | /* Flag set when small branches are detected. Used to |
2780 | select suitable defaults for the stub group size. */ | |
2781 | unsigned int has_14bit_branch:1; | |
f0abc2a1 AM |
2782 | }; |
2783 | ||
2784 | #define ppc64_elf_section_data(sec) \ | |
411e1bfb | 2785 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
f0abc2a1 AM |
2786 | |
2787 | static bfd_boolean | |
4ce794b7 | 2788 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
f0abc2a1 | 2789 | { |
f592407e AM |
2790 | if (!sec->used_by_bfd) |
2791 | { | |
2792 | struct _ppc64_elf_section_data *sdata; | |
2793 | bfd_size_type amt = sizeof (*sdata); | |
f0abc2a1 | 2794 | |
f592407e AM |
2795 | sdata = bfd_zalloc (abfd, amt); |
2796 | if (sdata == NULL) | |
2797 | return FALSE; | |
2798 | sec->used_by_bfd = sdata; | |
2799 | } | |
f0abc2a1 AM |
2800 | |
2801 | return _bfd_elf_new_section_hook (abfd, sec); | |
2802 | } | |
4025353c | 2803 | |
74f0fb50 | 2804 | static struct _opd_sec_data * |
4025353c AM |
2805 | get_opd_info (asection * sec) |
2806 | { | |
2807 | if (sec != NULL | |
2808 | && ppc64_elf_section_data (sec) != NULL | |
7c8fe5c4 | 2809 | && ppc64_elf_section_data (sec)->sec_type == sec_opd) |
74f0fb50 | 2810 | return &ppc64_elf_section_data (sec)->u.opd; |
4025353c AM |
2811 | return NULL; |
2812 | } | |
90e3cdf2 JJ |
2813 | \f |
2814 | /* Parameters for the qsort hook. */ | |
90e3cdf2 JJ |
2815 | static bfd_boolean synthetic_relocatable; |
2816 | ||
699733f6 | 2817 | /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */ |
90e3cdf2 JJ |
2818 | |
2819 | static int | |
2820 | compare_symbols (const void *ap, const void *bp) | |
2821 | { | |
2822 | const asymbol *a = * (const asymbol **) ap; | |
2823 | const asymbol *b = * (const asymbol **) bp; | |
2824 | ||
699733f6 AM |
2825 | /* Section symbols first. */ |
2826 | if ((a->flags & BSF_SECTION_SYM) && !(b->flags & BSF_SECTION_SYM)) | |
90e3cdf2 | 2827 | return -1; |
699733f6 | 2828 | if (!(a->flags & BSF_SECTION_SYM) && (b->flags & BSF_SECTION_SYM)) |
90e3cdf2 JJ |
2829 | return 1; |
2830 | ||
699733f6 | 2831 | /* then .opd symbols. */ |
ffcfec52 AM |
2832 | if (strcmp (a->section->name, ".opd") == 0 |
2833 | && strcmp (b->section->name, ".opd") != 0) | |
90e3cdf2 | 2834 | return -1; |
ffcfec52 AM |
2835 | if (strcmp (a->section->name, ".opd") != 0 |
2836 | && strcmp (b->section->name, ".opd") == 0) | |
90e3cdf2 JJ |
2837 | return 1; |
2838 | ||
699733f6 | 2839 | /* then other code symbols. */ |
90e3cdf2 JJ |
2840 | if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) |
2841 | == (SEC_CODE | SEC_ALLOC) | |
2842 | && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) | |
2843 | != (SEC_CODE | SEC_ALLOC)) | |
2844 | return -1; | |
2845 | ||
2846 | if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) | |
2847 | != (SEC_CODE | SEC_ALLOC) | |
2848 | && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) | |
2849 | == (SEC_CODE | SEC_ALLOC)) | |
2850 | return 1; | |
2851 | ||
2852 | if (synthetic_relocatable) | |
2853 | { | |
2854 | if (a->section->id < b->section->id) | |
2855 | return -1; | |
2856 | ||
2857 | if (a->section->id > b->section->id) | |
2858 | return 1; | |
2859 | } | |
2860 | ||
2861 | if (a->value + a->section->vma < b->value + b->section->vma) | |
2862 | return -1; | |
2863 | ||
2864 | if (a->value + a->section->vma > b->value + b->section->vma) | |
2865 | return 1; | |
2866 | ||
4d35a0aa AM |
2867 | /* For syms with the same value, prefer strong dynamic global function |
2868 | syms over other syms. */ | |
2869 | if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0) | |
2870 | return -1; | |
2871 | ||
2872 | if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0) | |
2873 | return 1; | |
2874 | ||
2875 | if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0) | |
2876 | return -1; | |
2877 | ||
2878 | if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0) | |
2879 | return 1; | |
2880 | ||
2881 | if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0) | |
2882 | return -1; | |
2883 | ||
2884 | if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0) | |
2885 | return 1; | |
2886 | ||
2887 | if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0) | |
2888 | return -1; | |
2889 | ||
2890 | if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0) | |
2891 | return 1; | |
2892 | ||
90e3cdf2 JJ |
2893 | return 0; |
2894 | } | |
2895 | ||
699733f6 | 2896 | /* Search SYMS for a symbol of the given VALUE. */ |
90e3cdf2 | 2897 | |
699733f6 AM |
2898 | static asymbol * |
2899 | sym_exists_at (asymbol **syms, long lo, long hi, int id, bfd_vma value) | |
90e3cdf2 | 2900 | { |
699733f6 | 2901 | long mid; |
90e3cdf2 | 2902 | |
699733f6 AM |
2903 | if (id == -1) |
2904 | { | |
2905 | while (lo < hi) | |
2906 | { | |
2907 | mid = (lo + hi) >> 1; | |
2908 | if (syms[mid]->value + syms[mid]->section->vma < value) | |
2909 | lo = mid + 1; | |
2910 | else if (syms[mid]->value + syms[mid]->section->vma > value) | |
2911 | hi = mid; | |
2912 | else | |
2913 | return syms[mid]; | |
2914 | } | |
2915 | } | |
2916 | else | |
2917 | { | |
2918 | while (lo < hi) | |
2919 | { | |
2920 | mid = (lo + hi) >> 1; | |
2921 | if (syms[mid]->section->id < id) | |
2922 | lo = mid + 1; | |
2923 | else if (syms[mid]->section->id > id) | |
2924 | hi = mid; | |
2925 | else if (syms[mid]->value < value) | |
2926 | lo = mid + 1; | |
2927 | else if (syms[mid]->value > value) | |
2928 | hi = mid; | |
2929 | else | |
2930 | return syms[mid]; | |
2931 | } | |
2932 | } | |
2933 | return NULL; | |
90e3cdf2 JJ |
2934 | } |
2935 | ||
468392fb AM |
2936 | static bfd_boolean |
2937 | section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr) | |
2938 | { | |
2939 | bfd_vma vma = *(bfd_vma *) ptr; | |
2940 | return ((section->flags & SEC_ALLOC) != 0 | |
2941 | && section->vma <= vma | |
2942 | && vma < section->vma + section->size); | |
2943 | } | |
2944 | ||
699733f6 | 2945 | /* Create synthetic symbols, effectively restoring "dot-symbol" function |
468392fb | 2946 | entry syms. Also generate @plt symbols for the glink branch table. */ |
90e3cdf2 JJ |
2947 | |
2948 | static long | |
a7535cf3 AM |
2949 | ppc64_elf_get_synthetic_symtab (bfd *abfd, |
2950 | long static_count, asymbol **static_syms, | |
2951 | long dyn_count, asymbol **dyn_syms, | |
c9727e01 | 2952 | asymbol **ret) |
90e3cdf2 JJ |
2953 | { |
2954 | asymbol *s; | |
699733f6 AM |
2955 | long i; |
2956 | long count; | |
90e3cdf2 | 2957 | char *names; |
a7535cf3 | 2958 | long symcount, codesecsym, codesecsymend, secsymend, opdsymend; |
699733f6 | 2959 | asection *opd; |
90e3cdf2 | 2960 | bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0; |
a7535cf3 | 2961 | asymbol **syms; |
90e3cdf2 JJ |
2962 | |
2963 | *ret = NULL; | |
2964 | ||
2965 | opd = bfd_get_section_by_name (abfd, ".opd"); | |
2966 | if (opd == NULL) | |
2967 | return 0; | |
2968 | ||
a7535cf3 | 2969 | symcount = static_count; |
c9727e01 | 2970 | if (!relocatable) |
a7535cf3 | 2971 | symcount += dyn_count; |
90e3cdf2 | 2972 | if (symcount == 0) |
c9727e01 | 2973 | return 0; |
90e3cdf2 | 2974 | |
a7535cf3 AM |
2975 | syms = bfd_malloc ((symcount + 1) * sizeof (*syms)); |
2976 | if (syms == NULL) | |
7356fed5 | 2977 | return -1; |
a7535cf3 AM |
2978 | |
2979 | if (!relocatable && static_count != 0 && dyn_count != 0) | |
2980 | { | |
2981 | /* Use both symbol tables. */ | |
2982 | memcpy (syms, static_syms, static_count * sizeof (*syms)); | |
2983 | memcpy (syms + static_count, dyn_syms, (dyn_count + 1) * sizeof (*syms)); | |
2984 | } | |
2985 | else if (!relocatable && static_count == 0) | |
2986 | memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms)); | |
2987 | else | |
2988 | memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms)); | |
2989 | ||
90e3cdf2 | 2990 | synthetic_relocatable = relocatable; |
595da8c5 | 2991 | qsort (syms, symcount, sizeof (*syms), compare_symbols); |
90e3cdf2 | 2992 | |
c9727e01 AM |
2993 | if (!relocatable && symcount > 1) |
2994 | { | |
2995 | long j; | |
2996 | /* Trim duplicate syms, since we may have merged the normal and | |
2997 | dynamic symbols. Actually, we only care about syms that have | |
3b36f7e6 | 2998 | different values, so trim any with the same value. */ |
c9727e01 AM |
2999 | for (i = 1, j = 1; i < symcount; ++i) |
3000 | if (syms[i - 1]->value + syms[i - 1]->section->vma | |
3001 | != syms[i]->value + syms[i]->section->vma) | |
3002 | syms[j++] = syms[i]; | |
3003 | symcount = j; | |
3004 | } | |
3005 | ||
699733f6 | 3006 | i = 0; |
ffcfec52 | 3007 | if (strcmp (syms[i]->section->name, ".opd") == 0) |
699733f6 AM |
3008 | ++i; |
3009 | codesecsym = i; | |
90e3cdf2 | 3010 | |
699733f6 AM |
3011 | for (; i < symcount; ++i) |
3012 | if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) | |
3013 | != (SEC_CODE | SEC_ALLOC)) | |
3014 | || (syms[i]->flags & BSF_SECTION_SYM) == 0) | |
3015 | break; | |
3016 | codesecsymend = i; | |
90e3cdf2 | 3017 | |
699733f6 AM |
3018 | for (; i < symcount; ++i) |
3019 | if ((syms[i]->flags & BSF_SECTION_SYM) == 0) | |
3020 | break; | |
3021 | secsymend = i; | |
90e3cdf2 | 3022 | |
699733f6 | 3023 | for (; i < symcount; ++i) |
ffcfec52 | 3024 | if (strcmp (syms[i]->section->name, ".opd") != 0) |
699733f6 AM |
3025 | break; |
3026 | opdsymend = i; | |
90e3cdf2 | 3027 | |
699733f6 AM |
3028 | for (; i < symcount; ++i) |
3029 | if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) | |
3030 | != (SEC_CODE | SEC_ALLOC)) | |
3031 | break; | |
3032 | symcount = i; | |
3033 | ||
c9727e01 | 3034 | count = 0; |
90e3cdf2 | 3035 | |
699733f6 | 3036 | if (relocatable) |
90e3cdf2 | 3037 | { |
699733f6 AM |
3038 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); |
3039 | arelent *r; | |
3040 | size_t size; | |
3041 | long relcount; | |
90e3cdf2 | 3042 | |
468392fb AM |
3043 | if (opdsymend == secsymend) |
3044 | goto done; | |
3045 | ||
699733f6 | 3046 | slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; |
90e3cdf2 | 3047 | relcount = (opd->flags & SEC_RELOC) ? opd->reloc_count : 0; |
7356fed5 | 3048 | if (relcount == 0) |
c9727e01 | 3049 | goto done; |
90e3cdf2 | 3050 | |
7356fed5 AM |
3051 | if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE)) |
3052 | { | |
3053 | count = -1; | |
3054 | goto done; | |
3055 | } | |
3056 | ||
699733f6 | 3057 | size = 0; |
595da8c5 | 3058 | for (i = secsymend, r = opd->relocation; i < opdsymend; ++i) |
699733f6 AM |
3059 | { |
3060 | asymbol *sym; | |
90e3cdf2 | 3061 | |
595da8c5 | 3062 | while (r < opd->relocation + relcount |
699733f6 AM |
3063 | && r->address < syms[i]->value + opd->vma) |
3064 | ++r; | |
90e3cdf2 | 3065 | |
595da8c5 | 3066 | if (r == opd->relocation + relcount) |
699733f6 | 3067 | break; |
90e3cdf2 | 3068 | |
699733f6 AM |
3069 | if (r->address != syms[i]->value + opd->vma) |
3070 | continue; | |
90e3cdf2 | 3071 | |
699733f6 AM |
3072 | if (r->howto->type != R_PPC64_ADDR64) |
3073 | continue; | |
90e3cdf2 | 3074 | |
699733f6 AM |
3075 | sym = *r->sym_ptr_ptr; |
3076 | if (!sym_exists_at (syms, opdsymend, symcount, | |
3077 | sym->section->id, sym->value + r->addend)) | |
3078 | { | |
3079 | ++count; | |
3080 | size += sizeof (asymbol); | |
3081 | size += strlen (syms[i]->name) + 2; | |
3082 | } | |
3083 | } | |
90e3cdf2 | 3084 | |
699733f6 AM |
3085 | s = *ret = bfd_malloc (size); |
3086 | if (s == NULL) | |
3087 | { | |
7356fed5 | 3088 | count = -1; |
c9727e01 | 3089 | goto done; |
699733f6 | 3090 | } |
90e3cdf2 | 3091 | |
699733f6 | 3092 | names = (char *) (s + count); |
90e3cdf2 | 3093 | |
595da8c5 | 3094 | for (i = secsymend, r = opd->relocation; i < opdsymend; ++i) |
90e3cdf2 | 3095 | { |
699733f6 | 3096 | asymbol *sym; |
90e3cdf2 | 3097 | |
595da8c5 | 3098 | while (r < opd->relocation + relcount |
699733f6 AM |
3099 | && r->address < syms[i]->value + opd->vma) |
3100 | ++r; | |
90e3cdf2 | 3101 | |
595da8c5 | 3102 | if (r == opd->relocation + relcount) |
699733f6 AM |
3103 | break; |
3104 | ||
3105 | if (r->address != syms[i]->value + opd->vma) | |
3106 | continue; | |
3107 | ||
3108 | if (r->howto->type != R_PPC64_ADDR64) | |
3109 | continue; | |
90e3cdf2 | 3110 | |
699733f6 AM |
3111 | sym = *r->sym_ptr_ptr; |
3112 | if (!sym_exists_at (syms, opdsymend, symcount, | |
3113 | sym->section->id, sym->value + r->addend)) | |
3114 | { | |
3115 | size_t len; | |
3116 | ||
3117 | *s = *syms[i]; | |
6ba2a415 | 3118 | s->flags |= BSF_SYNTHETIC; |
699733f6 AM |
3119 | s->section = sym->section; |
3120 | s->value = sym->value + r->addend; | |
3121 | s->name = names; | |
3122 | *names++ = '.'; | |
3123 | len = strlen (syms[i]->name); | |
3124 | memcpy (names, syms[i]->name, len + 1); | |
3125 | names += len + 1; | |
6f610d07 UW |
3126 | /* Have udata.p point back to the original symbol this |
3127 | synthetic symbol was derived from. */ | |
3128 | s->udata.p = syms[i]; | |
699733f6 AM |
3129 | s++; |
3130 | } | |
3131 | } | |
3132 | } | |
3133 | else | |
90e3cdf2 | 3134 | { |
468392fb | 3135 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); |
699733f6 AM |
3136 | bfd_byte *contents; |
3137 | size_t size; | |
468392fb AM |
3138 | long plt_count = 0; |
3139 | bfd_vma glink_vma = 0, resolv_vma = 0; | |
3140 | asection *dynamic, *glink = NULL, *relplt = NULL; | |
3141 | arelent *p; | |
90e3cdf2 | 3142 | |
699733f6 AM |
3143 | if (!bfd_malloc_and_get_section (abfd, opd, &contents)) |
3144 | { | |
3145 | if (contents) | |
c9727e01 AM |
3146 | { |
3147 | free_contents_and_exit: | |
3148 | free (contents); | |
3149 | } | |
7356fed5 | 3150 | count = -1; |
c9727e01 | 3151 | goto done; |
699733f6 | 3152 | } |
90e3cdf2 | 3153 | |
699733f6 AM |
3154 | size = 0; |
3155 | for (i = secsymend; i < opdsymend; ++i) | |
3156 | { | |
3157 | bfd_vma ent; | |
90e3cdf2 | 3158 | |
5ef11c02 AM |
3159 | /* Ignore bogus symbols. */ |
3160 | if (syms[i]->value > opd->size - 8) | |
3161 | continue; | |
3162 | ||
699733f6 AM |
3163 | ent = bfd_get_64 (abfd, contents + syms[i]->value); |
3164 | if (!sym_exists_at (syms, opdsymend, symcount, -1, ent)) | |
3165 | { | |
3166 | ++count; | |
3167 | size += sizeof (asymbol); | |
3168 | size += strlen (syms[i]->name) + 2; | |
3169 | } | |
3170 | } | |
90e3cdf2 | 3171 | |
468392fb | 3172 | /* Get start of .glink stubs from DT_PPC64_GLINK. */ |
066ee829 AM |
3173 | if (dyn_count != 0 |
3174 | && (dynamic = bfd_get_section_by_name (abfd, ".dynamic")) != NULL) | |
468392fb AM |
3175 | { |
3176 | bfd_byte *dynbuf, *extdyn, *extdynend; | |
3177 | size_t extdynsize; | |
3178 | void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *); | |
3179 | ||
3180 | if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf)) | |
3181 | goto free_contents_and_exit; | |
3182 | ||
3183 | extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; | |
3184 | swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in; | |
3185 | ||
3186 | extdyn = dynbuf; | |
3187 | extdynend = extdyn + dynamic->size; | |
3188 | for (; extdyn < extdynend; extdyn += extdynsize) | |
3189 | { | |
3190 | Elf_Internal_Dyn dyn; | |
3191 | (*swap_dyn_in) (abfd, extdyn, &dyn); | |
3192 | ||
3193 | if (dyn.d_tag == DT_NULL) | |
3194 | break; | |
3195 | ||
3196 | if (dyn.d_tag == DT_PPC64_GLINK) | |
3197 | { | |
3198 | /* The first glink stub starts at offset 32; see comment in | |
3199 | ppc64_elf_finish_dynamic_sections. */ | |
3200 | glink_vma = dyn.d_un.d_val + 32; | |
3201 | /* The .glink section usually does not survive the final | |
3202 | link; search for the section (usually .text) where the | |
3203 | glink stubs now reside. */ | |
3204 | glink = bfd_sections_find_if (abfd, section_covers_vma, | |
3205 | &glink_vma); | |
3206 | break; | |
3207 | } | |
3208 | } | |
3209 | ||
3210 | free (dynbuf); | |
3211 | } | |
3212 | ||
3213 | if (glink != NULL) | |
3214 | { | |
3215 | /* Determine __glink trampoline by reading the relative branch | |
3216 | from the first glink stub. */ | |
3217 | bfd_byte buf[4]; | |
3218 | if (bfd_get_section_contents (abfd, glink, buf, | |
3219 | glink_vma + 4 - glink->vma, 4)) | |
3220 | { | |
3221 | unsigned int insn = bfd_get_32 (abfd, buf); | |
3222 | insn ^= B_DOT; | |
3223 | if ((insn & ~0x3fffffc) == 0) | |
3224 | resolv_vma = glink_vma + 4 + (insn ^ 0x2000000) - 0x2000000; | |
3225 | } | |
3226 | ||
3227 | if (resolv_vma) | |
3228 | size += sizeof (asymbol) + sizeof ("__glink_PLTresolve"); | |
468392fb | 3229 | |
066ee829 AM |
3230 | relplt = bfd_get_section_by_name (abfd, ".rela.plt"); |
3231 | if (relplt != NULL) | |
3232 | { | |
3233 | slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; | |
3234 | if (! (*slurp_relocs) (abfd, relplt, dyn_syms, TRUE)) | |
3235 | goto free_contents_and_exit; | |
468392fb | 3236 | |
066ee829 AM |
3237 | plt_count = relplt->size / sizeof (Elf64_External_Rela); |
3238 | size += plt_count * sizeof (asymbol); | |
468392fb | 3239 | |
066ee829 AM |
3240 | p = relplt->relocation; |
3241 | for (i = 0; i < plt_count; i++, p++) | |
e054468f AM |
3242 | { |
3243 | size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt"); | |
3244 | if (p->addend != 0) | |
3245 | size += sizeof ("+0x") - 1 + 16; | |
3246 | } | |
066ee829 | 3247 | } |
468392fb AM |
3248 | } |
3249 | ||
699733f6 AM |
3250 | s = *ret = bfd_malloc (size); |
3251 | if (s == NULL) | |
7356fed5 | 3252 | goto free_contents_and_exit; |
90e3cdf2 | 3253 | |
468392fb | 3254 | names = (char *) (s + count + plt_count + (resolv_vma != 0)); |
90e3cdf2 | 3255 | |
699733f6 | 3256 | for (i = secsymend; i < opdsymend; ++i) |
90e3cdf2 | 3257 | { |
699733f6 | 3258 | bfd_vma ent; |
90e3cdf2 | 3259 | |
5ef11c02 AM |
3260 | if (syms[i]->value > opd->size - 8) |
3261 | continue; | |
3262 | ||
699733f6 AM |
3263 | ent = bfd_get_64 (abfd, contents + syms[i]->value); |
3264 | if (!sym_exists_at (syms, opdsymend, symcount, -1, ent)) | |
90e3cdf2 | 3265 | { |
c9727e01 | 3266 | long lo, hi; |
699733f6 | 3267 | size_t len; |
c9727e01 | 3268 | asection *sec = abfd->sections; |
90e3cdf2 | 3269 | |
699733f6 AM |
3270 | *s = *syms[i]; |
3271 | lo = codesecsym; | |
3272 | hi = codesecsymend; | |
3273 | while (lo < hi) | |
3274 | { | |
c9727e01 | 3275 | long mid = (lo + hi) >> 1; |
699733f6 AM |
3276 | if (syms[mid]->section->vma < ent) |
3277 | lo = mid + 1; | |
3278 | else if (syms[mid]->section->vma > ent) | |
3279 | hi = mid; | |
3280 | else | |
c9727e01 AM |
3281 | { |
3282 | sec = syms[mid]->section; | |
3283 | break; | |
3284 | } | |
699733f6 AM |
3285 | } |
3286 | ||
c9727e01 | 3287 | if (lo >= hi && lo > codesecsym) |
699733f6 | 3288 | sec = syms[lo - 1]->section; |
699733f6 AM |
3289 | |
3290 | for (; sec != NULL; sec = sec->next) | |
3291 | { | |
3292 | if (sec->vma > ent) | |
3293 | break; | |
63524580 JK |
3294 | /* SEC_LOAD may not be set if SEC is from a separate debug |
3295 | info file. */ | |
3296 | if ((sec->flags & SEC_ALLOC) == 0) | |
699733f6 AM |
3297 | break; |
3298 | if ((sec->flags & SEC_CODE) != 0) | |
3299 | s->section = sec; | |
3300 | } | |
6ba2a415 | 3301 | s->flags |= BSF_SYNTHETIC; |
699733f6 AM |
3302 | s->value = ent - s->section->vma; |
3303 | s->name = names; | |
3304 | *names++ = '.'; | |
3305 | len = strlen (syms[i]->name); | |
3306 | memcpy (names, syms[i]->name, len + 1); | |
3307 | names += len + 1; | |
6f610d07 UW |
3308 | /* Have udata.p point back to the original symbol this |
3309 | synthetic symbol was derived from. */ | |
3310 | s->udata.p = syms[i]; | |
699733f6 | 3311 | s++; |
90e3cdf2 | 3312 | } |
90e3cdf2 | 3313 | } |
699733f6 | 3314 | free (contents); |
468392fb AM |
3315 | |
3316 | if (glink != NULL && relplt != NULL) | |
3317 | { | |
3318 | if (resolv_vma) | |
3319 | { | |
3320 | /* Add a symbol for the main glink trampoline. */ | |
86a4952b | 3321 | memset (s, 0, sizeof *s); |
468392fb | 3322 | s->the_bfd = abfd; |
6ba2a415 | 3323 | s->flags = BSF_GLOBAL | BSF_SYNTHETIC; |
468392fb AM |
3324 | s->section = glink; |
3325 | s->value = resolv_vma - glink->vma; | |
3326 | s->name = names; | |
3327 | memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve")); | |
3328 | names += sizeof ("__glink_PLTresolve"); | |
3329 | s++; | |
3330 | count++; | |
3331 | } | |
3332 | ||
3333 | /* FIXME: It would be very much nicer to put sym@plt on the | |
3334 | stub rather than on the glink branch table entry. The | |
3335 | objdump disassembler would then use a sensible symbol | |
3336 | name on plt calls. The difficulty in doing so is | |
3337 | a) finding the stubs, and, | |
3338 | b) matching stubs against plt entries, and, | |
3339 | c) there can be multiple stubs for a given plt entry. | |
3340 | ||
3341 | Solving (a) could be done by code scanning, but older | |
3342 | ppc64 binaries used different stubs to current code. | |
3343 | (b) is the tricky one since you need to known the toc | |
3344 | pointer for at least one function that uses a pic stub to | |
3345 | be able to calculate the plt address referenced. | |
3346 | (c) means gdb would need to set multiple breakpoints (or | |
3347 | find the glink branch itself) when setting breakpoints | |
3348 | for pending shared library loads. */ | |
3349 | p = relplt->relocation; | |
3350 | for (i = 0; i < plt_count; i++, p++) | |
3351 | { | |
3352 | size_t len; | |
3353 | ||
3354 | *s = **p->sym_ptr_ptr; | |
3355 | /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since | |
3356 | we are defining a symbol, ensure one of them is set. */ | |
3357 | if ((s->flags & BSF_LOCAL) == 0) | |
3358 | s->flags |= BSF_GLOBAL; | |
6ba2a415 | 3359 | s->flags |= BSF_SYNTHETIC; |
468392fb AM |
3360 | s->section = glink; |
3361 | s->value = glink_vma - glink->vma; | |
3362 | s->name = names; | |
3363 | s->udata.p = NULL; | |
3364 | len = strlen ((*p->sym_ptr_ptr)->name); | |
3365 | memcpy (names, (*p->sym_ptr_ptr)->name, len); | |
3366 | names += len; | |
e054468f AM |
3367 | if (p->addend != 0) |
3368 | { | |
3369 | memcpy (names, "+0x", sizeof ("+0x") - 1); | |
3370 | names += sizeof ("+0x") - 1; | |
3371 | bfd_sprintf_vma (abfd, names, p->addend); | |
3372 | names += strlen (names); | |
3373 | } | |
468392fb AM |
3374 | memcpy (names, "@plt", sizeof ("@plt")); |
3375 | names += sizeof ("@plt"); | |
3376 | s++; | |
3377 | glink_vma += 8; | |
3378 | if (i >= 0x8000) | |
3379 | glink_vma += 4; | |
3380 | } | |
3381 | count += plt_count; | |
3382 | } | |
90e3cdf2 JJ |
3383 | } |
3384 | ||
c9727e01 | 3385 | done: |
a7535cf3 | 3386 | free (syms); |
90e3cdf2 JJ |
3387 | return count; |
3388 | } | |
5bd4f169 | 3389 | \f |
65f38f15 AM |
3390 | /* The following functions are specific to the ELF linker, while |
3391 | functions above are used generally. Those named ppc64_elf_* are | |
3392 | called by the main ELF linker code. They appear in this file more | |
3393 | or less in the order in which they are called. eg. | |
3394 | ppc64_elf_check_relocs is called early in the link process, | |
3395 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
3396 | called. |
3397 | ||
3398 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
3399 | functions have both a function code symbol and a function descriptor | |
3400 | symbol. A call to foo in a relocatable object file looks like: | |
3401 | ||
3402 | . .text | |
3403 | . x: | |
3404 | . bl .foo | |
3405 | . nop | |
3406 | ||
3407 | The function definition in another object file might be: | |
3408 | ||
3409 | . .section .opd | |
3410 | . foo: .quad .foo | |
3411 | . .quad .TOC.@tocbase | |
3412 | . .quad 0 | |
3413 | . | |
3414 | . .text | |
3415 | . .foo: blr | |
3416 | ||
3417 | When the linker resolves the call during a static link, the branch | |
3418 | unsurprisingly just goes to .foo and the .opd information is unused. | |
3419 | If the function definition is in a shared library, things are a little | |
3420 | different: The call goes via a plt call stub, the opd information gets | |
3421 | copied to the plt, and the linker patches the nop. | |
3422 | ||
3423 | . x: | |
3424 | . bl .foo_stub | |
3425 | . ld 2,40(1) | |
3426 | . | |
3427 | . | |
3428 | . .foo_stub: | |
3429 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
411e1bfb | 3430 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
e86ce104 AM |
3431 | . std 2,40(1) # this is the general idea |
3432 | . ld 11,0(12) | |
3433 | . ld 2,8(12) | |
3434 | . mtctr 11 | |
3435 | . ld 11,16(12) | |
3436 | . bctr | |
3437 | . | |
3438 | . .section .plt | |
3439 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
3440 | ||
3441 | The "reloc ()" notation is supposed to indicate that the linker emits | |
3442 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
3443 | copying. | |
3444 | ||
3445 | What are the difficulties here? Well, firstly, the relocations | |
3446 | examined by the linker in check_relocs are against the function code | |
3447 | sym .foo, while the dynamic relocation in the plt is emitted against | |
3448 | the function descriptor symbol, foo. Somewhere along the line, we need | |
3449 | to carefully copy dynamic link information from one symbol to the other. | |
3450 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
3451 | symbol as is normal for most other backends. We need foo dynamic | |
3452 | instead, at least for an application final link. However, when | |
3453 | creating a shared library containing foo, we need to have both symbols | |
3454 | dynamic so that references to .foo are satisfied during the early | |
3455 | stages of linking. Otherwise the linker might decide to pull in a | |
8387904d AM |
3456 | definition from some other object, eg. a static library. |
3457 | ||
3458 | Update: As of August 2004, we support a new convention. Function | |
3459 | calls may use the function descriptor symbol, ie. "bl foo". This | |
3460 | behaves exactly as "bl .foo". */ | |
65f38f15 | 3461 | |
1d483afe | 3462 | /* Of those relocs that might be copied as dynamic relocs, this function |
58ac9f71 AM |
3463 | selects those that must be copied when linking a shared library, |
3464 | even when the symbol is local. */ | |
65f38f15 | 3465 | |
1d483afe AM |
3466 | static int |
3467 | must_be_dyn_reloc (struct bfd_link_info *info, | |
3468 | enum elf_ppc64_reloc_type r_type) | |
3469 | { | |
3470 | switch (r_type) | |
3471 | { | |
3472 | default: | |
3473 | return 1; | |
3474 | ||
3475 | case R_PPC64_REL32: | |
3476 | case R_PPC64_REL64: | |
3477 | case R_PPC64_REL30: | |
3478 | return 0; | |
3479 | ||
3480 | case R_PPC64_TPREL16: | |
3481 | case R_PPC64_TPREL16_LO: | |
3482 | case R_PPC64_TPREL16_HI: | |
3483 | case R_PPC64_TPREL16_HA: | |
3484 | case R_PPC64_TPREL16_DS: | |
3485 | case R_PPC64_TPREL16_LO_DS: | |
3486 | case R_PPC64_TPREL16_HIGHER: | |
3487 | case R_PPC64_TPREL16_HIGHERA: | |
3488 | case R_PPC64_TPREL16_HIGHEST: | |
3489 | case R_PPC64_TPREL16_HIGHESTA: | |
3490 | case R_PPC64_TPREL64: | |
3491 | return !info->executable; | |
3492 | } | |
3493 | } | |
65f38f15 | 3494 | |
f4656909 AM |
3495 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
3496 | copying dynamic variables from a shared lib into an app's dynbss | |
3497 | section, and instead use a dynamic relocation to point into the | |
5d35169e AM |
3498 | shared lib. With code that gcc generates, it's vital that this be |
3499 | enabled; In the PowerPC64 ABI, the address of a function is actually | |
3500 | the address of a function descriptor, which resides in the .opd | |
3501 | section. gcc uses the descriptor directly rather than going via the | |
3502 | GOT as some other ABI's do, which means that initialized function | |
3503 | pointers must reference the descriptor. Thus, a function pointer | |
3504 | initialized to the address of a function in a shared library will | |
3505 | either require a copy reloc, or a dynamic reloc. Using a copy reloc | |
4cc11e76 | 3506 | redefines the function descriptor symbol to point to the copy. This |
5d35169e AM |
3507 | presents a problem as a plt entry for that function is also |
3508 | initialized from the function descriptor symbol and the copy reloc | |
3509 | may not be initialized first. */ | |
a23b6845 | 3510 | #define ELIMINATE_COPY_RELOCS 1 |
f4656909 | 3511 | |
721956f4 AM |
3512 | /* Section name for stubs is the associated section name plus this |
3513 | string. */ | |
3514 | #define STUB_SUFFIX ".stub" | |
3515 | ||
3516 | /* Linker stubs. | |
3517 | ppc_stub_long_branch: | |
3518 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
3519 | destination, but a 24 bit branch in a stub section will reach. | |
3520 | . b dest | |
3521 | ||
3522 | ppc_stub_plt_branch: | |
3523 | Similar to the above, but a 24 bit branch in the stub section won't | |
3524 | reach its destination. | |
87e226ce AM |
3525 | . addis %r12,%r2,xxx@toc@ha |
3526 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
3527 | . mtctr %r11 |
3528 | . bctr | |
3529 | ||
3530 | ppc_stub_plt_call: | |
2c66dc6c AM |
3531 | Used to call a function in a shared library. If it so happens that |
3532 | the plt entry referenced crosses a 64k boundary, then an extra | |
ac2df442 | 3533 | "addi %r12,%r12,xxx@toc@l" will be inserted before the "mtctr". |
87e226ce | 3534 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 3535 | . std %r2,40(%r1) |
87e226ce | 3536 | . ld %r11,xxx+0@toc@l(%r12) |
721956f4 | 3537 | . mtctr %r11 |
ac2df442 | 3538 | . ld %r2,xxx+8@toc@l(%r12) |
87e226ce | 3539 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 | 3540 | . bctr |
ad8e1ba5 AM |
3541 | |
3542 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional | |
3543 | code to adjust the value and save r2 to support multiple toc sections. | |
3544 | A ppc_stub_long_branch with an r2 offset looks like: | |
3545 | . std %r2,40(%r1) | |
3546 | . addis %r2,%r2,off@ha | |
3547 | . addi %r2,%r2,off@l | |
3548 | . b dest | |
3549 | ||
3550 | A ppc_stub_plt_branch with an r2 offset looks like: | |
3551 | . std %r2,40(%r1) | |
3552 | . addis %r12,%r2,xxx@toc@ha | |
3553 | . ld %r11,xxx@toc@l(%r12) | |
3554 | . addis %r2,%r2,off@ha | |
3555 | . addi %r2,%r2,off@l | |
3556 | . mtctr %r11 | |
3557 | . bctr | |
ac2df442 AM |
3558 | |
3559 | In cases where the "addis" instruction would add zero, the "addis" is | |
3560 | omitted and following instructions modified slightly in some cases. | |
721956f4 AM |
3561 | */ |
3562 | ||
3563 | enum ppc_stub_type { | |
3564 | ppc_stub_none, | |
3565 | ppc_stub_long_branch, | |
ad8e1ba5 | 3566 | ppc_stub_long_branch_r2off, |
721956f4 | 3567 | ppc_stub_plt_branch, |
ad8e1ba5 | 3568 | ppc_stub_plt_branch_r2off, |
721956f4 AM |
3569 | ppc_stub_plt_call |
3570 | }; | |
3571 | ||
3572 | struct ppc_stub_hash_entry { | |
3573 | ||
3574 | /* Base hash table entry structure. */ | |
3575 | struct bfd_hash_entry root; | |
3576 | ||
ad8e1ba5 AM |
3577 | enum ppc_stub_type stub_type; |
3578 | ||
721956f4 AM |
3579 | /* The stub section. */ |
3580 | asection *stub_sec; | |
3581 | ||
3582 | /* Offset within stub_sec of the beginning of this stub. */ | |
3583 | bfd_vma stub_offset; | |
3584 | ||
3585 | /* Given the symbol's value and its section we can determine its final | |
3586 | value when building the stubs (so the stub knows where to jump. */ | |
3587 | bfd_vma target_value; | |
3588 | asection *target_section; | |
3589 | ||
721956f4 AM |
3590 | /* The symbol table entry, if any, that this was derived from. */ |
3591 | struct ppc_link_hash_entry *h; | |
e054468f | 3592 | struct plt_entry *plt_ent; |
721956f4 | 3593 | |
411e1bfb AM |
3594 | /* And the reloc addend that this was derived from. */ |
3595 | bfd_vma addend; | |
3596 | ||
721956f4 AM |
3597 | /* Where this stub is being called from, or, in the case of combined |
3598 | stub sections, the first input section in the group. */ | |
3599 | asection *id_sec; | |
3600 | }; | |
3601 | ||
3602 | struct ppc_branch_hash_entry { | |
3603 | ||
3604 | /* Base hash table entry structure. */ | |
3605 | struct bfd_hash_entry root; | |
3606 | ||
c456f082 | 3607 | /* Offset within branch lookup table. */ |
721956f4 AM |
3608 | unsigned int offset; |
3609 | ||
3610 | /* Generation marker. */ | |
3611 | unsigned int iter; | |
3612 | }; | |
65f38f15 AM |
3613 | |
3614 | struct ppc_link_hash_entry | |
3615 | { | |
3616 | struct elf_link_hash_entry elf; | |
3617 | ||
b3fac117 AM |
3618 | union { |
3619 | /* A pointer to the most recently used stub hash entry against this | |
3620 | symbol. */ | |
3621 | struct ppc_stub_hash_entry *stub_cache; | |
3622 | ||
3623 | /* A pointer to the next symbol starting with a '.' */ | |
3624 | struct ppc_link_hash_entry *next_dot_sym; | |
3625 | } u; | |
721956f4 | 3626 | |
65f38f15 | 3627 | /* Track dynamic relocs copied for this symbol. */ |
6061a67d | 3628 | struct elf_dyn_relocs *dyn_relocs; |
e86ce104 | 3629 | |
721956f4 | 3630 | /* Link between function code and descriptor symbols. */ |
34814b9f | 3631 | struct ppc_link_hash_entry *oh; |
721956f4 | 3632 | |
e86ce104 AM |
3633 | /* Flag function code and descriptor symbols. */ |
3634 | unsigned int is_func:1; | |
3635 | unsigned int is_func_descriptor:1; | |
908b32fc | 3636 | unsigned int fake:1; |
411e1bfb | 3637 | |
c5614fa4 AM |
3638 | /* Whether global opd/toc sym has been adjusted or not. |
3639 | After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag | |
3640 | should be set for all globals defined in any opd/toc section. */ | |
754021d0 AM |
3641 | unsigned int adjust_done:1; |
3642 | ||
99877b66 AM |
3643 | /* Set if we twiddled this symbol to weak at some stage. */ |
3644 | unsigned int was_undefined:1; | |
3645 | ||
411e1bfb | 3646 | /* Contexts in which symbol is used in the GOT (or TOC). |
e7b938ca AM |
3647 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
3648 | corresponding relocs are encountered during check_relocs. | |
3649 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
3650 | indicate the corresponding GOT entry type is not needed. | |
3651 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into | |
3652 | a TPREL one. We use a separate flag rather than setting TPREL | |
3653 | just for convenience in distinguishing the two cases. */ | |
3654 | #define TLS_GD 1 /* GD reloc. */ | |
3655 | #define TLS_LD 2 /* LD reloc. */ | |
3656 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
3657 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
3658 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
3659 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ | |
3660 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ | |
e054468f | 3661 | #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */ |
f961d9dd | 3662 | unsigned char tls_mask; |
65f38f15 AM |
3663 | }; |
3664 | ||
3665 | /* ppc64 ELF linker hash table. */ | |
3666 | ||
3667 | struct ppc_link_hash_table | |
3668 | { | |
3669 | struct elf_link_hash_table elf; | |
3670 | ||
721956f4 AM |
3671 | /* The stub hash table. */ |
3672 | struct bfd_hash_table stub_hash_table; | |
3673 | ||
3674 | /* Another hash table for plt_branch stubs. */ | |
3675 | struct bfd_hash_table branch_hash_table; | |
3676 | ||
3677 | /* Linker stub bfd. */ | |
3678 | bfd *stub_bfd; | |
3679 | ||
3680 | /* Linker call-backs. */ | |
4ce794b7 AM |
3681 | asection * (*add_stub_section) (const char *, asection *); |
3682 | void (*layout_sections_again) (void); | |
721956f4 AM |
3683 | |
3684 | /* Array to keep track of which stub sections have been created, and | |
3685 | information on stub grouping. */ | |
3686 | struct map_stub { | |
3687 | /* This is the section to which stubs in the group will be attached. */ | |
3688 | asection *link_sec; | |
3689 | /* The stub section. */ | |
3690 | asection *stub_sec; | |
ad8e1ba5 AM |
3691 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
3692 | bfd_vma toc_off; | |
721956f4 AM |
3693 | } *stub_group; |
3694 | ||
ad8e1ba5 AM |
3695 | /* Temp used when calculating TOC pointers. */ |
3696 | bfd_vma toc_curr; | |
bf102f86 AM |
3697 | bfd *toc_bfd; |
3698 | asection *toc_first_sec; | |
ad8e1ba5 | 3699 | |
8f3bab57 AM |
3700 | /* Highest input section id. */ |
3701 | int top_id; | |
3702 | ||
734b6cf9 AM |
3703 | /* Highest output section index. */ |
3704 | int top_index; | |
3705 | ||
b3fac117 AM |
3706 | /* Used when adding symbols. */ |
3707 | struct ppc_link_hash_entry *dot_syms; | |
3708 | ||
734b6cf9 AM |
3709 | /* List of input sections for each output section. */ |
3710 | asection **input_list; | |
721956f4 | 3711 | |
65f38f15 | 3712 | /* Short-cuts to get to dynamic linker sections. */ |
4ce794b7 | 3713 | asection *got; |
4ce794b7 AM |
3714 | asection *plt; |
3715 | asection *relplt; | |
e054468f AM |
3716 | asection *iplt; |
3717 | asection *reliplt; | |
4ce794b7 AM |
3718 | asection *dynbss; |
3719 | asection *relbss; | |
3720 | asection *glink; | |
82bd7b59 | 3721 | asection *sfpr; |
4ce794b7 AM |
3722 | asection *brlt; |
3723 | asection *relbrlt; | |
58d180e8 | 3724 | asection *glink_eh_frame; |
ec338859 | 3725 | |
8387904d AM |
3726 | /* Shortcut to .__tls_get_addr and __tls_get_addr. */ |
3727 | struct ppc_link_hash_entry *tls_get_addr; | |
3728 | struct ppc_link_hash_entry *tls_get_addr_fd; | |
411e1bfb | 3729 | |
927be08e AM |
3730 | /* The size of reliplt used by got entry relocs. */ |
3731 | bfd_size_type got_reli_size; | |
3732 | ||
9b5ecbd0 AM |
3733 | /* Statistics. */ |
3734 | unsigned long stub_count[ppc_stub_plt_call]; | |
3735 | ||
ee75fd95 AM |
3736 | /* Number of stubs against global syms. */ |
3737 | unsigned long stub_globals; | |
3738 | ||
9df0ef5f AM |
3739 | /* Set if PLT call stubs should load r11. */ |
3740 | unsigned int plt_static_chain:1; | |
3741 | ||
ad8e1ba5 | 3742 | /* Set if we should emit symbols for stubs. */ |
99877b66 | 3743 | unsigned int emit_stub_syms:1; |
ad8e1ba5 | 3744 | |
a7f2871e AM |
3745 | /* Set if __tls_get_addr optimization should not be done. */ |
3746 | unsigned int no_tls_get_addr_opt:1; | |
3747 | ||
4c52953f | 3748 | /* Support for multiple toc sections. */ |
33c0ec9d | 3749 | unsigned int do_multi_toc:1; |
4c52953f | 3750 | unsigned int multi_toc_needed:1; |
927be08e | 3751 | unsigned int second_toc_pass:1; |
67f0cbdb | 3752 | unsigned int do_toc_opt:1; |
4c52953f | 3753 | |
5d1634d7 | 3754 | /* Set on error. */ |
99877b66 | 3755 | unsigned int stub_error:1; |
721956f4 | 3756 | |
7d9616d7 | 3757 | /* Temp used by ppc64_elf_process_dot_syms. */ |
99877b66 | 3758 | unsigned int twiddled_syms:1; |
721956f4 AM |
3759 | |
3760 | /* Incremented every time we size stubs. */ | |
3761 | unsigned int stub_iteration; | |
5d1634d7 | 3762 | |
87d72d41 AM |
3763 | /* Small local sym cache. */ |
3764 | struct sym_cache sym_cache; | |
65f38f15 AM |
3765 | }; |
3766 | ||
4c52953f AM |
3767 | /* Rename some of the generic section flags to better document how they |
3768 | are used here. */ | |
b0dddeec AM |
3769 | |
3770 | /* Nonzero if this section has TLS related relocations. */ | |
3771 | #define has_tls_reloc sec_flg0 | |
3772 | ||
3773 | /* Nonzero if this section has a call to __tls_get_addr. */ | |
3774 | #define has_tls_get_addr_call sec_flg1 | |
3775 | ||
3776 | /* Nonzero if this section has any toc or got relocs. */ | |
3777 | #define has_toc_reloc sec_flg2 | |
3778 | ||
3779 | /* Nonzero if this section has a call to another section that uses | |
3780 | the toc or got. */ | |
d77c8a4b | 3781 | #define makes_toc_func_call sec_flg3 |
b0dddeec AM |
3782 | |
3783 | /* Recursion protection when determining above flag. */ | |
d77c8a4b | 3784 | #define call_check_in_progress sec_flg4 |
70cc837d | 3785 | #define call_check_done sec_flg5 |
4c52953f | 3786 | |
65f38f15 AM |
3787 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ |
3788 | ||
3789 | #define ppc_hash_table(p) \ | |
4dfe6ac6 NC |
3790 | (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ |
3791 | == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL) | |
65f38f15 | 3792 | |
721956f4 AM |
3793 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
3794 | ((struct ppc_stub_hash_entry *) \ | |
3795 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
3796 | ||
3797 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
3798 | ((struct ppc_branch_hash_entry *) \ | |
3799 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
3800 | ||
3801 | /* Create an entry in the stub hash table. */ | |
3802 | ||
3803 | static struct bfd_hash_entry * | |
4ce794b7 AM |
3804 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
3805 | struct bfd_hash_table *table, | |
3806 | const char *string) | |
721956f4 AM |
3807 | { |
3808 | /* Allocate the structure if it has not already been allocated by a | |
3809 | subclass. */ | |
3810 | if (entry == NULL) | |
3811 | { | |
3812 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
3813 | if (entry == NULL) | |
3814 | return entry; | |
3815 | } | |
3816 | ||
3817 | /* Call the allocation method of the superclass. */ | |
3818 | entry = bfd_hash_newfunc (entry, table, string); | |
3819 | if (entry != NULL) | |
3820 | { | |
3821 | struct ppc_stub_hash_entry *eh; | |
3822 | ||
3823 | /* Initialize the local fields. */ | |
3824 | eh = (struct ppc_stub_hash_entry *) entry; | |
ad8e1ba5 | 3825 | eh->stub_type = ppc_stub_none; |
721956f4 AM |
3826 | eh->stub_sec = NULL; |
3827 | eh->stub_offset = 0; | |
3828 | eh->target_value = 0; | |
3829 | eh->target_section = NULL; | |
721956f4 AM |
3830 | eh->h = NULL; |
3831 | eh->id_sec = NULL; | |
3832 | } | |
3833 | ||
3834 | return entry; | |
3835 | } | |
3836 | ||
3837 | /* Create an entry in the branch hash table. */ | |
3838 | ||
3839 | static struct bfd_hash_entry * | |
4ce794b7 AM |
3840 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
3841 | struct bfd_hash_table *table, | |
3842 | const char *string) | |
721956f4 AM |
3843 | { |
3844 | /* Allocate the structure if it has not already been allocated by a | |
3845 | subclass. */ | |
3846 | if (entry == NULL) | |
3847 | { | |
3848 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); | |
3849 | if (entry == NULL) | |
3850 | return entry; | |
3851 | } | |
3852 | ||
3853 | /* Call the allocation method of the superclass. */ | |
3854 | entry = bfd_hash_newfunc (entry, table, string); | |
3855 | if (entry != NULL) | |
3856 | { | |
3857 | struct ppc_branch_hash_entry *eh; | |
3858 | ||
3859 | /* Initialize the local fields. */ | |
3860 | eh = (struct ppc_branch_hash_entry *) entry; | |
3861 | eh->offset = 0; | |
3862 | eh->iter = 0; | |
3863 | } | |
3864 | ||
3865 | return entry; | |
3866 | } | |
3867 | ||
65f38f15 AM |
3868 | /* Create an entry in a ppc64 ELF linker hash table. */ |
3869 | ||
3870 | static struct bfd_hash_entry * | |
4ce794b7 AM |
3871 | link_hash_newfunc (struct bfd_hash_entry *entry, |
3872 | struct bfd_hash_table *table, | |
3873 | const char *string) | |
65f38f15 AM |
3874 | { |
3875 | /* Allocate the structure if it has not already been allocated by a | |
3876 | subclass. */ | |
3877 | if (entry == NULL) | |
3878 | { | |
3879 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
3880 | if (entry == NULL) | |
3881 | return entry; | |
3882 | } | |
3883 | ||
3884 | /* Call the allocation method of the superclass. */ | |
3885 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
3886 | if (entry != NULL) | |
3887 | { | |
3888 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
3889 | ||
b3fac117 | 3890 | memset (&eh->u.stub_cache, 0, |
908b32fc | 3891 | (sizeof (struct ppc_link_hash_entry) |
b3fac117 AM |
3892 | - offsetof (struct ppc_link_hash_entry, u.stub_cache))); |
3893 | ||
3894 | /* When making function calls, old ABI code references function entry | |
3895 | points (dot symbols), while new ABI code references the function | |
3896 | descriptor symbol. We need to make any combination of reference and | |
3897 | definition work together, without breaking archive linking. | |
3898 | ||
3899 | For a defined function "foo" and an undefined call to "bar": | |
3900 | An old object defines "foo" and ".foo", references ".bar" (possibly | |
3901 | "bar" too). | |
3902 | A new object defines "foo" and references "bar". | |
3903 | ||
3904 | A new object thus has no problem with its undefined symbols being | |
3905 | satisfied by definitions in an old object. On the other hand, the | |
3906 | old object won't have ".bar" satisfied by a new object. | |
3907 | ||
3908 | Keep a list of newly added dot-symbols. */ | |
3909 | ||
3910 | if (string[0] == '.') | |
3911 | { | |
3912 | struct ppc_link_hash_table *htab; | |
3913 | ||
3914 | htab = (struct ppc_link_hash_table *) table; | |
3915 | eh->u.next_dot_sym = htab->dot_syms; | |
3916 | htab->dot_syms = eh; | |
3917 | } | |
65f38f15 AM |
3918 | } |
3919 | ||
3920 | return entry; | |
3921 | } | |
3922 | ||
3923 | /* Create a ppc64 ELF linker hash table. */ | |
3924 | ||
3925 | static struct bfd_link_hash_table * | |
4ce794b7 | 3926 | ppc64_elf_link_hash_table_create (bfd *abfd) |
65f38f15 AM |
3927 | { |
3928 | struct ppc_link_hash_table *htab; | |
3929 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
3930 | ||
4ce794b7 | 3931 | htab = bfd_zmalloc (amt); |
65f38f15 AM |
3932 | if (htab == NULL) |
3933 | return NULL; | |
3934 | ||
66eb6687 | 3935 | if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc, |
4dfe6ac6 NC |
3936 | sizeof (struct ppc_link_hash_entry), |
3937 | PPC64_ELF_DATA)) | |
65f38f15 | 3938 | { |
e2d34d7d | 3939 | free (htab); |
65f38f15 AM |
3940 | return NULL; |
3941 | } | |
3942 | ||
721956f4 | 3943 | /* Init the stub hash table too. */ |
66eb6687 AM |
3944 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc, |
3945 | sizeof (struct ppc_stub_hash_entry))) | |
721956f4 AM |
3946 | return NULL; |
3947 | ||
3948 | /* And the branch hash table. */ | |
66eb6687 AM |
3949 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc, |
3950 | sizeof (struct ppc_branch_hash_entry))) | |
721956f4 AM |
3951 | return NULL; |
3952 | ||
3254fd24 AM |
3953 | /* Initializing two fields of the union is just cosmetic. We really |
3954 | only care about glist, but when compiled on a 32-bit host the | |
3955 | bfd_vma fields are larger. Setting the bfd_vma to zero makes | |
3956 | debugger inspection of these fields look nicer. */ | |
a6aa5195 AM |
3957 | htab->elf.init_got_refcount.refcount = 0; |
3958 | htab->elf.init_got_refcount.glist = NULL; | |
3959 | htab->elf.init_plt_refcount.refcount = 0; | |
3960 | htab->elf.init_plt_refcount.glist = NULL; | |
3961 | htab->elf.init_got_offset.offset = 0; | |
3962 | htab->elf.init_got_offset.glist = NULL; | |
3963 | htab->elf.init_plt_offset.offset = 0; | |
3964 | htab->elf.init_plt_offset.glist = NULL; | |
3254fd24 | 3965 | |
65f38f15 AM |
3966 | return &htab->elf.root; |
3967 | } | |
3968 | ||
721956f4 AM |
3969 | /* Free the derived linker hash table. */ |
3970 | ||
3971 | static void | |
4ce794b7 | 3972 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
721956f4 AM |
3973 | { |
3974 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
3975 | ||
3976 | bfd_hash_table_free (&ret->stub_hash_table); | |
3977 | bfd_hash_table_free (&ret->branch_hash_table); | |
3978 | _bfd_generic_link_hash_table_free (hash); | |
3979 | } | |
3980 | ||
e717da7e AM |
3981 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
3982 | ||
3983 | void | |
3984 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
3985 | { | |
3986 | struct ppc_link_hash_table *htab; | |
3987 | ||
3988 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; | |
3989 | ||
3990 | /* Always hook our dynamic sections into the first bfd, which is the | |
3991 | linker created stub bfd. This ensures that the GOT header is at | |
3992 | the start of the output TOC section. */ | |
3993 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
3994 | if (htab == NULL) |
3995 | return; | |
e717da7e AM |
3996 | htab->stub_bfd = abfd; |
3997 | htab->elf.dynobj = abfd; | |
3998 | } | |
3999 | ||
721956f4 AM |
4000 | /* Build a name for an entry in the stub hash table. */ |
4001 | ||
4002 | static char * | |
4ce794b7 AM |
4003 | ppc_stub_name (const asection *input_section, |
4004 | const asection *sym_sec, | |
4005 | const struct ppc_link_hash_entry *h, | |
4006 | const Elf_Internal_Rela *rel) | |
721956f4 AM |
4007 | { |
4008 | char *stub_name; | |
4009 | bfd_size_type len; | |
4010 | ||
4011 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
4012 | offsets from a sym as a branch target? In fact, we could | |
4013 | probably assume the addend is always zero. */ | |
4014 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
4015 | ||
4016 | if (h) | |
4017 | { | |
4018 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
4019 | stub_name = bfd_malloc (len); | |
46de2a7c AM |
4020 | if (stub_name == NULL) |
4021 | return stub_name; | |
4022 | ||
4023 | sprintf (stub_name, "%08x.%s+%x", | |
4024 | input_section->id & 0xffffffff, | |
4025 | h->elf.root.root.string, | |
4026 | (int) rel->r_addend & 0xffffffff); | |
721956f4 AM |
4027 | } |
4028 | else | |
4029 | { | |
ad8e1ba5 | 4030 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
721956f4 | 4031 | stub_name = bfd_malloc (len); |
46de2a7c AM |
4032 | if (stub_name == NULL) |
4033 | return stub_name; | |
4034 | ||
4035 | sprintf (stub_name, "%08x.%x:%x+%x", | |
4036 | input_section->id & 0xffffffff, | |
4037 | sym_sec->id & 0xffffffff, | |
4038 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
4039 | (int) rel->r_addend & 0xffffffff); | |
721956f4 | 4040 | } |
ee75fd95 AM |
4041 | if (stub_name[len - 2] == '+' && stub_name[len - 1] == '0') |
4042 | stub_name[len - 2] = 0; | |
721956f4 AM |
4043 | return stub_name; |
4044 | } | |
4045 | ||
4046 | /* Look up an entry in the stub hash. Stub entries are cached because | |
4047 | creating the stub name takes a bit of time. */ | |
4048 | ||
4049 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
4050 | ppc_get_stub_entry (const asection *input_section, |
4051 | const asection *sym_sec, | |
039b3fef | 4052 | struct ppc_link_hash_entry *h, |
4ce794b7 AM |
4053 | const Elf_Internal_Rela *rel, |
4054 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
4055 | { |
4056 | struct ppc_stub_hash_entry *stub_entry; | |
721956f4 AM |
4057 | const asection *id_sec; |
4058 | ||
4059 | /* If this input section is part of a group of sections sharing one | |
4060 | stub section, then use the id of the first section in the group. | |
4061 | Stub names need to include a section id, as there may well be | |
4062 | more than one stub used to reach say, printf, and we need to | |
4063 | distinguish between them. */ | |
4064 | id_sec = htab->stub_group[input_section->id].link_sec; | |
4065 | ||
b3fac117 AM |
4066 | if (h != NULL && h->u.stub_cache != NULL |
4067 | && h->u.stub_cache->h == h | |
4068 | && h->u.stub_cache->id_sec == id_sec) | |
721956f4 | 4069 | { |
b3fac117 | 4070 | stub_entry = h->u.stub_cache; |
721956f4 AM |
4071 | } |
4072 | else | |
4073 | { | |
4074 | char *stub_name; | |
4075 | ||
4076 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
4077 | if (stub_name == NULL) | |
4078 | return NULL; | |
4079 | ||
4080 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 4081 | stub_name, FALSE, FALSE); |
721956f4 | 4082 | if (h != NULL) |
b3fac117 | 4083 | h->u.stub_cache = stub_entry; |
721956f4 AM |
4084 | |
4085 | free (stub_name); | |
4086 | } | |
4087 | ||
4088 | return stub_entry; | |
4089 | } | |
4090 | ||
4091 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
4092 | stub entry are initialised. */ | |
4093 | ||
4094 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
4095 | ppc_add_stub (const char *stub_name, |
4096 | asection *section, | |
25f53a85 | 4097 | struct bfd_link_info *info) |
721956f4 | 4098 | { |
25f53a85 | 4099 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
721956f4 AM |
4100 | asection *link_sec; |
4101 | asection *stub_sec; | |
4102 | struct ppc_stub_hash_entry *stub_entry; | |
4103 | ||
4104 | link_sec = htab->stub_group[section->id].link_sec; | |
4105 | stub_sec = htab->stub_group[section->id].stub_sec; | |
4106 | if (stub_sec == NULL) | |
4107 | { | |
4108 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
4109 | if (stub_sec == NULL) | |
4110 | { | |
d4c88bbb | 4111 | size_t namelen; |
721956f4 AM |
4112 | bfd_size_type len; |
4113 | char *s_name; | |
4114 | ||
d4c88bbb AM |
4115 | namelen = strlen (link_sec->name); |
4116 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
4117 | s_name = bfd_alloc (htab->stub_bfd, len); |
4118 | if (s_name == NULL) | |
4119 | return NULL; | |
4120 | ||
d4c88bbb AM |
4121 | memcpy (s_name, link_sec->name, namelen); |
4122 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
4123 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
4124 | if (stub_sec == NULL) | |
4125 | return NULL; | |
4126 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
4127 | } | |
4128 | htab->stub_group[section->id].stub_sec = stub_sec; | |
4129 | } | |
4130 | ||
4131 | /* Enter this entry into the linker stub hash table. */ | |
4132 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 4133 | TRUE, FALSE); |
721956f4 AM |
4134 | if (stub_entry == NULL) |
4135 | { | |
25f53a85 AM |
4136 | info->callbacks->einfo (_("%B: cannot create stub entry %s\n"), |
4137 | section->owner, stub_name); | |
721956f4 AM |
4138 | return NULL; |
4139 | } | |
4140 | ||
4141 | stub_entry->stub_sec = stub_sec; | |
4142 | stub_entry->stub_offset = 0; | |
4143 | stub_entry->id_sec = link_sec; | |
4144 | return stub_entry; | |
4145 | } | |
4146 | ||
82bd7b59 AM |
4147 | /* Create sections for linker generated code. */ |
4148 | ||
b34976b6 | 4149 | static bfd_boolean |
4ce794b7 | 4150 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
82bd7b59 AM |
4151 | { |
4152 | struct ppc_link_hash_table *htab; | |
4153 | flagword flags; | |
4154 | ||
4155 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
4156 | if (htab == NULL) |
4157 | return FALSE; | |
82bd7b59 AM |
4158 | |
4159 | /* Create .sfpr for code to save and restore fp regs. */ | |
4160 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
4161 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3496cb2a L |
4162 | htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr", |
4163 | flags); | |
82bd7b59 | 4164 | if (htab->sfpr == NULL |
82bd7b59 | 4165 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) |
b34976b6 | 4166 | return FALSE; |
82bd7b59 | 4167 | |
721956f4 | 4168 | /* Create .glink for lazy dynamic linking support. */ |
3496cb2a L |
4169 | htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink", |
4170 | flags); | |
4ce794b7 | 4171 | if (htab->glink == NULL |
ee4bf8d2 | 4172 | || ! bfd_set_section_alignment (dynobj, htab->glink, 3)) |
b34976b6 | 4173 | return FALSE; |
82bd7b59 | 4174 | |
58d180e8 AM |
4175 | if (!info->no_ld_generated_unwind_info) |
4176 | { | |
4177 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | |
4178 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4179 | htab->glink_eh_frame = bfd_make_section_anyway_with_flags (dynobj, | |
4180 | ".eh_frame", | |
4181 | flags); | |
4182 | if (htab->glink_eh_frame == NULL | |
4183 | || !bfd_set_section_alignment (abfd, htab->glink_eh_frame, 2)) | |
4184 | return FALSE; | |
4185 | } | |
4186 | ||
e054468f AM |
4187 | flags = SEC_ALLOC | SEC_LINKER_CREATED; |
4188 | htab->iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags); | |
4189 | if (htab->iplt == NULL | |
4190 | || ! bfd_set_section_alignment (dynobj, htab->iplt, 3)) | |
4191 | return FALSE; | |
4192 | ||
4193 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
4194 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4195 | htab->reliplt = bfd_make_section_anyway_with_flags (dynobj, | |
4196 | ".rela.iplt", | |
4197 | flags); | |
4198 | if (htab->reliplt == NULL | |
4199 | || ! bfd_set_section_alignment (dynobj, htab->reliplt, 3)) | |
4200 | return FALSE; | |
4201 | ||
c456f082 | 4202 | /* Create branch lookup table for plt_branch stubs. */ |
e4e0193e AM |
4203 | flags = (SEC_ALLOC | SEC_LOAD |
4204 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4205 | htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt", | |
4206 | flags); | |
4ce794b7 | 4207 | if (htab->brlt == NULL |
4ce794b7 | 4208 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) |
b34976b6 | 4209 | return FALSE; |
721956f4 | 4210 | |
e4e0193e | 4211 | if (!info->shared) |
c456f082 AM |
4212 | return TRUE; |
4213 | ||
e4e0193e AM |
4214 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY |
4215 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4216 | htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj, | |
4217 | ".rela.branch_lt", | |
4218 | flags); | |
e054468f | 4219 | if (htab->relbrlt == NULL |
c456f082 AM |
4220 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) |
4221 | return FALSE; | |
4222 | ||
b34976b6 | 4223 | return TRUE; |
82bd7b59 AM |
4224 | } |
4225 | ||
e717da7e AM |
4226 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
4227 | not already done. */ | |
65f38f15 | 4228 | |
b34976b6 | 4229 | static bfd_boolean |
e717da7e | 4230 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
65f38f15 | 4231 | { |
e717da7e AM |
4232 | asection *got, *relgot; |
4233 | flagword flags; | |
4234 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
65f38f15 | 4235 | |
0c8d6e5c | 4236 | if (!is_ppc64_elf (abfd)) |
0ffa91dd | 4237 | return FALSE; |
4dfe6ac6 NC |
4238 | if (htab == NULL) |
4239 | return FALSE; | |
0ffa91dd | 4240 | |
4ce794b7 | 4241 | if (!htab->got) |
e717da7e AM |
4242 | { |
4243 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) | |
4244 | return FALSE; | |
4245 | ||
4246 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); | |
4247 | if (!htab->got) | |
4248 | abort (); | |
4249 | } | |
4250 | ||
4251 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
4252 | | SEC_LINKER_CREATED); | |
4253 | ||
c456f082 | 4254 | got = bfd_make_section_anyway_with_flags (abfd, ".got", flags); |
e717da7e | 4255 | if (!got |
e717da7e AM |
4256 | || !bfd_set_section_alignment (abfd, got, 3)) |
4257 | return FALSE; | |
65f38f15 | 4258 | |
c456f082 AM |
4259 | relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got", |
4260 | flags | SEC_READONLY); | |
e717da7e | 4261 | if (!relgot |
e717da7e | 4262 | || ! bfd_set_section_alignment (abfd, relgot, 3)) |
b34976b6 | 4263 | return FALSE; |
e717da7e AM |
4264 | |
4265 | ppc64_elf_tdata (abfd)->got = got; | |
4266 | ppc64_elf_tdata (abfd)->relgot = relgot; | |
b34976b6 | 4267 | return TRUE; |
65f38f15 | 4268 | } |
5bd4f169 | 4269 | |
82bd7b59 | 4270 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 4271 | |
b34976b6 | 4272 | static bfd_boolean |
4ce794b7 | 4273 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5bd4f169 | 4274 | { |
65f38f15 | 4275 | struct ppc_link_hash_table *htab; |
5bd4f169 | 4276 | |
65f38f15 | 4277 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 4278 | return FALSE; |
65f38f15 | 4279 | |
e717da7e | 4280 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
4281 | if (htab == NULL) |
4282 | return FALSE; | |
4283 | ||
e717da7e AM |
4284 | if (!htab->got) |
4285 | htab->got = bfd_get_section_by_name (dynobj, ".got"); | |
4ce794b7 AM |
4286 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
4287 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
4288 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
65f38f15 | 4289 | if (!info->shared) |
4ce794b7 | 4290 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
65f38f15 | 4291 | |
e717da7e | 4292 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
4ce794b7 | 4293 | || (!info->shared && !htab->relbss)) |
65f38f15 AM |
4294 | abort (); |
4295 | ||
b34976b6 | 4296 | return TRUE; |
5bd4f169 AM |
4297 | } |
4298 | ||
b31867b6 AM |
4299 | /* Follow indirect and warning symbol links. */ |
4300 | ||
4301 | static inline struct bfd_link_hash_entry * | |
4302 | follow_link (struct bfd_link_hash_entry *h) | |
4303 | { | |
4304 | while (h->type == bfd_link_hash_indirect | |
4305 | || h->type == bfd_link_hash_warning) | |
4306 | h = h->u.i.link; | |
4307 | return h; | |
4308 | } | |
4309 | ||
4310 | static inline struct elf_link_hash_entry * | |
4311 | elf_follow_link (struct elf_link_hash_entry *h) | |
4312 | { | |
4313 | return (struct elf_link_hash_entry *) follow_link (&h->root); | |
4314 | } | |
4315 | ||
4316 | static inline struct ppc_link_hash_entry * | |
4317 | ppc_follow_link (struct ppc_link_hash_entry *h) | |
4318 | { | |
4319 | return (struct ppc_link_hash_entry *) follow_link (&h->elf.root); | |
4320 | } | |
4321 | ||
40d16e0b AM |
4322 | /* Merge PLT info on FROM with that on TO. */ |
4323 | ||
4324 | static void | |
4325 | move_plt_plist (struct ppc_link_hash_entry *from, | |
4326 | struct ppc_link_hash_entry *to) | |
4327 | { | |
4328 | if (from->elf.plt.plist != NULL) | |
4329 | { | |
4330 | if (to->elf.plt.plist != NULL) | |
4331 | { | |
4332 | struct plt_entry **entp; | |
4333 | struct plt_entry *ent; | |
4334 | ||
4335 | for (entp = &from->elf.plt.plist; (ent = *entp) != NULL; ) | |
4336 | { | |
4337 | struct plt_entry *dent; | |
4338 | ||
4339 | for (dent = to->elf.plt.plist; dent != NULL; dent = dent->next) | |
4340 | if (dent->addend == ent->addend) | |
4341 | { | |
4342 | dent->plt.refcount += ent->plt.refcount; | |
4343 | *entp = ent->next; | |
4344 | break; | |
4345 | } | |
4346 | if (dent == NULL) | |
4347 | entp = &ent->next; | |
4348 | } | |
4349 | *entp = to->elf.plt.plist; | |
4350 | } | |
4351 | ||
4352 | to->elf.plt.plist = from->elf.plt.plist; | |
4353 | from->elf.plt.plist = NULL; | |
4354 | } | |
4355 | } | |
4356 | ||
65f38f15 AM |
4357 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
4358 | ||
4359 | static void | |
fcfa13d2 AM |
4360 | ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info, |
4361 | struct elf_link_hash_entry *dir, | |
4362 | struct elf_link_hash_entry *ind) | |
65f38f15 AM |
4363 | { |
4364 | struct ppc_link_hash_entry *edir, *eind; | |
4365 | ||
4366 | edir = (struct ppc_link_hash_entry *) dir; | |
4367 | eind = (struct ppc_link_hash_entry *) ind; | |
4368 | ||
c79d6685 AM |
4369 | edir->is_func |= eind->is_func; |
4370 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
4371 | edir->tls_mask |= eind->tls_mask; | |
4372 | if (eind->oh != NULL) | |
4373 | edir->oh = ppc_follow_link (eind->oh); | |
4374 | ||
4375 | /* If called to transfer flags for a weakdef during processing | |
4376 | of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF. | |
4377 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
4378 | if (!(ELIMINATE_COPY_RELOCS | |
4379 | && eind->elf.root.type != bfd_link_hash_indirect | |
4380 | && edir->elf.dynamic_adjusted)) | |
4381 | edir->elf.non_got_ref |= eind->elf.non_got_ref; | |
4382 | ||
4383 | edir->elf.ref_dynamic |= eind->elf.ref_dynamic; | |
4384 | edir->elf.ref_regular |= eind->elf.ref_regular; | |
4385 | edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak; | |
4386 | edir->elf.needs_plt |= eind->elf.needs_plt; | |
4387 | ||
4388 | /* If we were called to copy over info for a weak sym, that's all. */ | |
4389 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
4390 | return; | |
4391 | ||
411e1bfb | 4392 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
bbd7ec4a | 4393 | if (eind->dyn_relocs != NULL) |
65f38f15 | 4394 | { |
bbd7ec4a AM |
4395 | if (edir->dyn_relocs != NULL) |
4396 | { | |
6061a67d AM |
4397 | struct elf_dyn_relocs **pp; |
4398 | struct elf_dyn_relocs *p; | |
bbd7ec4a | 4399 | |
fcfa13d2 | 4400 | /* Add reloc counts against the indirect sym to the direct sym |
bbd7ec4a AM |
4401 | list. Merge any entries against the same section. */ |
4402 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
4403 | { | |
6061a67d | 4404 | struct elf_dyn_relocs *q; |
bbd7ec4a AM |
4405 | |
4406 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
4407 | if (q->sec == p->sec) | |
4408 | { | |
4409 | q->pc_count += p->pc_count; | |
4410 | q->count += p->count; | |
4411 | *pp = p->next; | |
4412 | break; | |
4413 | } | |
4414 | if (q == NULL) | |
4415 | pp = &p->next; | |
4416 | } | |
4417 | *pp = edir->dyn_relocs; | |
4418 | } | |
4419 | ||
65f38f15 AM |
4420 | edir->dyn_relocs = eind->dyn_relocs; |
4421 | eind->dyn_relocs = NULL; | |
4422 | } | |
65f38f15 | 4423 | |
81848ca0 AM |
4424 | /* Copy over got entries that we may have already seen to the |
4425 | symbol which just became indirect. */ | |
411e1bfb AM |
4426 | if (eind->elf.got.glist != NULL) |
4427 | { | |
4428 | if (edir->elf.got.glist != NULL) | |
4429 | { | |
4430 | struct got_entry **entp; | |
4431 | struct got_entry *ent; | |
4432 | ||
4433 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) | |
4434 | { | |
4435 | struct got_entry *dent; | |
4436 | ||
4437 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) | |
4438 | if (dent->addend == ent->addend | |
e717da7e | 4439 | && dent->owner == ent->owner |
411e1bfb AM |
4440 | && dent->tls_type == ent->tls_type) |
4441 | { | |
4442 | dent->got.refcount += ent->got.refcount; | |
4443 | *entp = ent->next; | |
4444 | break; | |
4445 | } | |
4446 | if (dent == NULL) | |
4447 | entp = &ent->next; | |
4448 | } | |
4449 | *entp = edir->elf.got.glist; | |
4450 | } | |
4451 | ||
4452 | edir->elf.got.glist = eind->elf.got.glist; | |
4453 | eind->elf.got.glist = NULL; | |
4454 | } | |
4455 | ||
4456 | /* And plt entries. */ | |
40d16e0b | 4457 | move_plt_plist (eind, edir); |
411e1bfb | 4458 | |
fcfa13d2 | 4459 | if (eind->elf.dynindx != -1) |
411e1bfb | 4460 | { |
fcfa13d2 AM |
4461 | if (edir->elf.dynindx != -1) |
4462 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
4463 | edir->elf.dynstr_index); | |
411e1bfb AM |
4464 | edir->elf.dynindx = eind->elf.dynindx; |
4465 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
4466 | eind->elf.dynindx = -1; | |
4467 | eind->elf.dynstr_index = 0; | |
4468 | } | |
411e1bfb AM |
4469 | } |
4470 | ||
8387904d AM |
4471 | /* Find the function descriptor hash entry from the given function code |
4472 | hash entry FH. Link the entries via their OH fields. */ | |
4473 | ||
4474 | static struct ppc_link_hash_entry * | |
b31867b6 | 4475 | lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) |
8387904d AM |
4476 | { |
4477 | struct ppc_link_hash_entry *fdh = fh->oh; | |
4478 | ||
4479 | if (fdh == NULL) | |
4480 | { | |
4481 | const char *fd_name = fh->elf.root.root.string + 1; | |
4482 | ||
4483 | fdh = (struct ppc_link_hash_entry *) | |
4484 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); | |
b31867b6 AM |
4485 | if (fdh == NULL) |
4486 | return fdh; | |
4487 | ||
4488 | fdh->is_func_descriptor = 1; | |
4489 | fdh->oh = fh; | |
4490 | fh->is_func = 1; | |
4491 | fh->oh = fdh; | |
8387904d AM |
4492 | } |
4493 | ||
b31867b6 | 4494 | return ppc_follow_link (fdh); |
8387904d AM |
4495 | } |
4496 | ||
bb700d78 AM |
4497 | /* Make a fake function descriptor sym for the code sym FH. */ |
4498 | ||
4499 | static struct ppc_link_hash_entry * | |
4500 | make_fdh (struct bfd_link_info *info, | |
908b32fc | 4501 | struct ppc_link_hash_entry *fh) |
bb700d78 AM |
4502 | { |
4503 | bfd *abfd; | |
4504 | asymbol *newsym; | |
4505 | struct bfd_link_hash_entry *bh; | |
4506 | struct ppc_link_hash_entry *fdh; | |
4507 | ||
4508 | abfd = fh->elf.root.u.undef.abfd; | |
4509 | newsym = bfd_make_empty_symbol (abfd); | |
4510 | newsym->name = fh->elf.root.root.string + 1; | |
4511 | newsym->section = bfd_und_section_ptr; | |
4512 | newsym->value = 0; | |
908b32fc | 4513 | newsym->flags = BSF_WEAK; |
bb700d78 AM |
4514 | |
4515 | bh = NULL; | |
4516 | if (!_bfd_generic_link_add_one_symbol (info, abfd, newsym->name, | |
4517 | newsym->flags, newsym->section, | |
4518 | newsym->value, NULL, FALSE, FALSE, | |
4519 | &bh)) | |
4520 | return NULL; | |
4521 | ||
4522 | fdh = (struct ppc_link_hash_entry *) bh; | |
4523 | fdh->elf.non_elf = 0; | |
908b32fc AM |
4524 | fdh->fake = 1; |
4525 | fdh->is_func_descriptor = 1; | |
4526 | fdh->oh = fh; | |
4527 | fh->is_func = 1; | |
4528 | fh->oh = fdh; | |
bb700d78 AM |
4529 | return fdh; |
4530 | } | |
4531 | ||
8387904d AM |
4532 | /* Fix function descriptor symbols defined in .opd sections to be |
4533 | function type. */ | |
555cd476 AM |
4534 | |
4535 | static bfd_boolean | |
c16153ae | 4536 | ppc64_elf_add_symbol_hook (bfd *ibfd, |
e054468f | 4537 | struct bfd_link_info *info, |
555cd476 | 4538 | Elf_Internal_Sym *isym, |
b3fac117 | 4539 | const char **name ATTRIBUTE_UNUSED, |
555cd476 AM |
4540 | flagword *flags ATTRIBUTE_UNUSED, |
4541 | asection **sec, | |
4542 | bfd_vma *value ATTRIBUTE_UNUSED) | |
4543 | { | |
f64b2e8d NC |
4544 | if ((ibfd->flags & DYNAMIC) == 0 |
4545 | && ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE) | |
4546 | elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; | |
4547 | ||
e054468f | 4548 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
c16153ae L |
4549 | { |
4550 | if ((ibfd->flags & DYNAMIC) == 0) | |
f64b2e8d | 4551 | elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; |
c16153ae | 4552 | } |
e054468f AM |
4553 | else if (ELF_ST_TYPE (isym->st_info) == STT_FUNC) |
4554 | ; | |
4555 | else if (*sec != NULL | |
70cc837d | 4556 | && strcmp ((*sec)->name, ".opd") == 0) |
555cd476 | 4557 | isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC); |
433817dd | 4558 | |
555cd476 AM |
4559 | return TRUE; |
4560 | } | |
4561 | ||
8387904d | 4562 | /* This function makes an old ABI object reference to ".bar" cause the |
908b32fc AM |
4563 | inclusion of a new ABI object archive that defines "bar". |
4564 | NAME is a symbol defined in an archive. Return a symbol in the hash | |
4565 | table that might be satisfied by the archive symbols. */ | |
8387904d AM |
4566 | |
4567 | static struct elf_link_hash_entry * | |
4568 | ppc64_elf_archive_symbol_lookup (bfd *abfd, | |
4569 | struct bfd_link_info *info, | |
4570 | const char *name) | |
4571 | { | |
4572 | struct elf_link_hash_entry *h; | |
4573 | char *dot_name; | |
4574 | size_t len; | |
4575 | ||
4576 | h = _bfd_elf_archive_symbol_lookup (abfd, info, name); | |
908b32fc AM |
4577 | if (h != NULL |
4578 | /* Don't return this sym if it is a fake function descriptor | |
4579 | created by add_symbol_adjust. */ | |
4580 | && !(h->root.type == bfd_link_hash_undefweak | |
4581 | && ((struct ppc_link_hash_entry *) h)->fake)) | |
8387904d AM |
4582 | return h; |
4583 | ||
4584 | if (name[0] == '.') | |
4585 | return h; | |
4586 | ||
4587 | len = strlen (name); | |
4588 | dot_name = bfd_alloc (abfd, len + 2); | |
4589 | if (dot_name == NULL) | |
4590 | return (struct elf_link_hash_entry *) 0 - 1; | |
4591 | dot_name[0] = '.'; | |
4592 | memcpy (dot_name + 1, name, len + 1); | |
4593 | h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name); | |
4594 | bfd_release (abfd, dot_name); | |
4595 | return h; | |
4596 | } | |
4597 | ||
4598 | /* This function satisfies all old ABI object references to ".bar" if a | |
99877b66 AM |
4599 | new ABI object defines "bar". Well, at least, undefined dot symbols |
4600 | are made weak. This stops later archive searches from including an | |
4601 | object if we already have a function descriptor definition. It also | |
35b0ce59 AM |
4602 | prevents the linker complaining about undefined symbols. |
4603 | We also check and correct mismatched symbol visibility here. The | |
4604 | most restrictive visibility of the function descriptor and the | |
4605 | function entry symbol is used. */ | |
8387904d AM |
4606 | |
4607 | static bfd_boolean | |
b3fac117 | 4608 | add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info) |
8387904d | 4609 | { |
8387904d AM |
4610 | struct ppc_link_hash_table *htab; |
4611 | struct ppc_link_hash_entry *fdh; | |
4612 | ||
b3fac117 | 4613 | if (eh->elf.root.type == bfd_link_hash_indirect) |
8387904d AM |
4614 | return TRUE; |
4615 | ||
b3fac117 AM |
4616 | if (eh->elf.root.type == bfd_link_hash_warning) |
4617 | eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link; | |
8387904d | 4618 | |
b3fac117 AM |
4619 | if (eh->elf.root.root.string[0] != '.') |
4620 | abort (); | |
8387904d | 4621 | |
b3fac117 | 4622 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
4623 | if (htab == NULL) |
4624 | return FALSE; | |
4625 | ||
b31867b6 AM |
4626 | fdh = lookup_fdh (eh, htab); |
4627 | if (fdh == NULL) | |
4628 | { | |
4629 | if (!info->relocatable | |
4630 | && (eh->elf.root.type == bfd_link_hash_undefined | |
4631 | || eh->elf.root.type == bfd_link_hash_undefweak) | |
4632 | && eh->elf.ref_regular) | |
4633 | { | |
4634 | /* Make an undefweak function descriptor sym, which is enough to | |
4635 | pull in an --as-needed shared lib, but won't cause link | |
4636 | errors. Archives are handled elsewhere. */ | |
4637 | fdh = make_fdh (info, eh); | |
4638 | if (fdh == NULL) | |
4639 | return FALSE; | |
4640 | fdh->elf.ref_regular = 1; | |
4641 | } | |
bb700d78 | 4642 | } |
b31867b6 | 4643 | else |
8387904d | 4644 | { |
35b0ce59 AM |
4645 | unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1; |
4646 | unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1; | |
4647 | if (entry_vis < descr_vis) | |
4648 | fdh->elf.other += entry_vis - descr_vis; | |
4649 | else if (entry_vis > descr_vis) | |
4650 | eh->elf.other += descr_vis - entry_vis; | |
4651 | ||
e87d886e AM |
4652 | if ((fdh->elf.root.type == bfd_link_hash_defined |
4653 | || fdh->elf.root.type == bfd_link_hash_defweak) | |
4654 | && eh->elf.root.type == bfd_link_hash_undefined) | |
35b0ce59 AM |
4655 | { |
4656 | eh->elf.root.type = bfd_link_hash_undefweak; | |
4657 | eh->was_undefined = 1; | |
4658 | htab->twiddled_syms = 1; | |
4659 | } | |
8387904d | 4660 | } |
99877b66 | 4661 | |
8387904d AM |
4662 | return TRUE; |
4663 | } | |
4664 | ||
b3fac117 AM |
4665 | /* Process list of dot-symbols we made in link_hash_newfunc. */ |
4666 | ||
8387904d | 4667 | static bfd_boolean |
7d9616d7 | 4668 | ppc64_elf_process_dot_syms (bfd *ibfd, struct bfd_link_info *info) |
8387904d | 4669 | { |
99877b66 | 4670 | struct ppc_link_hash_table *htab; |
b3fac117 | 4671 | struct ppc_link_hash_entry **p, *eh; |
433817dd | 4672 | |
0c8d6e5c | 4673 | if (!is_ppc64_elf (info->output_bfd)) |
35b0ce59 | 4674 | return TRUE; |
4dfe6ac6 NC |
4675 | htab = ppc_hash_table (info); |
4676 | if (htab == NULL) | |
4677 | return FALSE; | |
35b0ce59 | 4678 | |
0c8d6e5c | 4679 | if (is_ppc64_elf (ibfd)) |
b3fac117 AM |
4680 | { |
4681 | p = &htab->dot_syms; | |
4682 | while ((eh = *p) != NULL) | |
4683 | { | |
4684 | *p = NULL; | |
4685 | if (!add_symbol_adjust (eh, info)) | |
4686 | return FALSE; | |
4687 | p = &eh->u.next_dot_sym; | |
4688 | } | |
4689 | } | |
4690 | ||
4691 | /* Clear the list for non-ppc64 input files. */ | |
4692 | p = &htab->dot_syms; | |
4693 | while ((eh = *p) != NULL) | |
4694 | { | |
4695 | *p = NULL; | |
4696 | p = &eh->u.next_dot_sym; | |
4697 | } | |
99877b66 AM |
4698 | |
4699 | /* We need to fix the undefs list for any syms we have twiddled to | |
4700 | undef_weak. */ | |
4701 | if (htab->twiddled_syms) | |
4702 | { | |
77cfaee6 | 4703 | bfd_link_repair_undef_list (&htab->elf.root); |
99877b66 AM |
4704 | htab->twiddled_syms = 0; |
4705 | } | |
b3fac117 | 4706 | return TRUE; |
8387904d AM |
4707 | } |
4708 | ||
97fed1c9 JJ |
4709 | /* Undo hash table changes when an --as-needed input file is determined |
4710 | not to be needed. */ | |
4711 | ||
4712 | static bfd_boolean | |
4713 | ppc64_elf_as_needed_cleanup (bfd *ibfd ATTRIBUTE_UNUSED, | |
4714 | struct bfd_link_info *info) | |
4715 | { | |
4dfe6ac6 NC |
4716 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
4717 | ||
4718 | if (htab == NULL) | |
4719 | return FALSE; | |
4720 | ||
4721 | htab->dot_syms = NULL; | |
97fed1c9 JJ |
4722 | return TRUE; |
4723 | } | |
4724 | ||
aa374f67 AM |
4725 | /* If --just-symbols against a final linked binary, then assume we need |
4726 | toc adjusting stubs when calling functions defined there. */ | |
4727 | ||
4728 | static void | |
4729 | ppc64_elf_link_just_syms (asection *sec, struct bfd_link_info *info) | |
4730 | { | |
4731 | if ((sec->flags & SEC_CODE) != 0 | |
4732 | && (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0 | |
4733 | && is_ppc64_elf (sec->owner)) | |
4734 | { | |
4735 | asection *got = bfd_get_section_by_name (sec->owner, ".got"); | |
4736 | if (got != NULL | |
4737 | && got->size >= elf_backend_got_header_size | |
4738 | && bfd_get_section_by_name (sec->owner, ".opd") != NULL) | |
4739 | sec->has_toc_reloc = 1; | |
4740 | } | |
4741 | _bfd_elf_link_just_syms (sec, info); | |
4742 | } | |
4743 | ||
e054468f | 4744 | static struct plt_entry ** |
4ce794b7 AM |
4745 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
4746 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) | |
411e1bfb AM |
4747 | { |
4748 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); | |
e054468f | 4749 | struct plt_entry **local_plt; |
f961d9dd | 4750 | unsigned char *local_got_tls_masks; |
411e1bfb AM |
4751 | |
4752 | if (local_got_ents == NULL) | |
4753 | { | |
4754 | bfd_size_type size = symtab_hdr->sh_info; | |
4755 | ||
e054468f AM |
4756 | size *= (sizeof (*local_got_ents) |
4757 | + sizeof (*local_plt) | |
4758 | + sizeof (*local_got_tls_masks)); | |
4ce794b7 | 4759 | local_got_ents = bfd_zalloc (abfd, size); |
411e1bfb | 4760 | if (local_got_ents == NULL) |
e054468f | 4761 | return NULL; |
411e1bfb AM |
4762 | elf_local_got_ents (abfd) = local_got_ents; |
4763 | } | |
4764 | ||
e054468f | 4765 | if ((tls_type & (PLT_IFUNC | TLS_EXPLICIT)) == 0) |
411e1bfb AM |
4766 | { |
4767 | struct got_entry *ent; | |
4768 | ||
4769 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) | |
e717da7e AM |
4770 | if (ent->addend == r_addend |
4771 | && ent->owner == abfd | |
4772 | && ent->tls_type == tls_type) | |
411e1bfb AM |
4773 | break; |
4774 | if (ent == NULL) | |
4775 | { | |
4776 | bfd_size_type amt = sizeof (*ent); | |
4ce794b7 | 4777 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
4778 | if (ent == NULL) |
4779 | return FALSE; | |
4780 | ent->next = local_got_ents[r_symndx]; | |
4781 | ent->addend = r_addend; | |
e717da7e | 4782 | ent->owner = abfd; |
411e1bfb | 4783 | ent->tls_type = tls_type; |
927be08e | 4784 | ent->is_indirect = FALSE; |
411e1bfb AM |
4785 | ent->got.refcount = 0; |
4786 | local_got_ents[r_symndx] = ent; | |
4787 | } | |
4788 | ent->got.refcount += 1; | |
4789 | } | |
4790 | ||
e054468f | 4791 | local_plt = (struct plt_entry **) (local_got_ents + symtab_hdr->sh_info); |
f961d9dd | 4792 | local_got_tls_masks = (unsigned char *) (local_plt + symtab_hdr->sh_info); |
e7b938ca | 4793 | local_got_tls_masks[r_symndx] |= tls_type; |
e054468f AM |
4794 | |
4795 | return local_plt + r_symndx; | |
65f38f15 AM |
4796 | } |
4797 | ||
411e1bfb | 4798 | static bfd_boolean |
e054468f | 4799 | update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend) |
1e2f5b6e | 4800 | { |
411e1bfb | 4801 | struct plt_entry *ent; |
1e2f5b6e | 4802 | |
e054468f | 4803 | for (ent = *plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
4804 | if (ent->addend == addend) |
4805 | break; | |
4806 | if (ent == NULL) | |
1e2f5b6e | 4807 | { |
411e1bfb | 4808 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 4809 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
4810 | if (ent == NULL) |
4811 | return FALSE; | |
e054468f | 4812 | ent->next = *plist; |
411e1bfb AM |
4813 | ent->addend = addend; |
4814 | ent->plt.refcount = 0; | |
e054468f | 4815 | *plist = ent; |
1e2f5b6e | 4816 | } |
411e1bfb | 4817 | ent->plt.refcount += 1; |
b34976b6 | 4818 | return TRUE; |
1e2f5b6e AM |
4819 | } |
4820 | ||
e054468f AM |
4821 | static bfd_boolean |
4822 | is_branch_reloc (enum elf_ppc64_reloc_type r_type) | |
4823 | { | |
4824 | return (r_type == R_PPC64_REL24 | |
4825 | || r_type == R_PPC64_REL14 | |
4826 | || r_type == R_PPC64_REL14_BRTAKEN | |
4827 | || r_type == R_PPC64_REL14_BRNTAKEN | |
4828 | || r_type == R_PPC64_ADDR24 | |
4829 | || r_type == R_PPC64_ADDR14 | |
4830 | || r_type == R_PPC64_ADDR14_BRTAKEN | |
4831 | || r_type == R_PPC64_ADDR14_BRNTAKEN); | |
4832 | } | |
4833 | ||
5bd4f169 | 4834 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 4835 | calculate needed space in the global offset table, procedure |
5d1634d7 | 4836 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 4837 | |
b34976b6 | 4838 | static bfd_boolean |
4ce794b7 AM |
4839 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
4840 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 4841 | { |
65f38f15 | 4842 | struct ppc_link_hash_table *htab; |
5bd4f169 | 4843 | Elf_Internal_Shdr *symtab_hdr; |
c7e2358a | 4844 | struct elf_link_hash_entry **sym_hashes; |
5bd4f169 AM |
4845 | const Elf_Internal_Rela *rel; |
4846 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 4847 | asection *sreloc; |
1e2f5b6e | 4848 | asection **opd_sym_map; |
3a71aa26 | 4849 | struct elf_link_hash_entry *tga, *dottga; |
5bd4f169 | 4850 | |
1049f94e | 4851 | if (info->relocatable) |
b34976b6 | 4852 | return TRUE; |
5bd4f169 | 4853 | |
680a3378 AM |
4854 | /* Don't do anything special with non-loaded, non-alloced sections. |
4855 | In particular, any relocs in such sections should not affect GOT | |
4856 | and PLT reference counting (ie. we don't allow them to create GOT | |
4857 | or PLT entries), there's no possibility or desire to optimize TLS | |
4858 | relocs, and there's not much point in propagating relocs to shared | |
4859 | libs that the dynamic linker won't relocate. */ | |
4860 | if ((sec->flags & SEC_ALLOC) == 0) | |
4861 | return TRUE; | |
4862 | ||
0c8d6e5c | 4863 | BFD_ASSERT (is_ppc64_elf (abfd)); |
0ffa91dd | 4864 | |
65f38f15 | 4865 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
4866 | if (htab == NULL) |
4867 | return FALSE; | |
4868 | ||
3a71aa26 AM |
4869 | tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", |
4870 | FALSE, FALSE, TRUE); | |
4871 | dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr", | |
4872 | FALSE, FALSE, TRUE); | |
0ffa91dd | 4873 | symtab_hdr = &elf_symtab_hdr (abfd); |
5bd4f169 | 4874 | sym_hashes = elf_sym_hashes (abfd); |
5bd4f169 | 4875 | sreloc = NULL; |
1e2f5b6e | 4876 | opd_sym_map = NULL; |
70cc837d | 4877 | if (strcmp (sec->name, ".opd") == 0) |
1e2f5b6e AM |
4878 | { |
4879 | /* Garbage collection needs some extra help with .opd sections. | |
4880 | We don't want to necessarily keep everything referenced by | |
4881 | relocs in .opd, as that would keep all functions. Instead, | |
4882 | if we reference an .opd symbol (a function descriptor), we | |
4883 | want to keep the function code symbol's section. This is | |
4884 | easy for global symbols, but for local syms we need to keep | |
74f0fb50 | 4885 | information about the associated function section. */ |
1e2f5b6e AM |
4886 | bfd_size_type amt; |
4887 | ||
74f0fb50 | 4888 | amt = sec->size * sizeof (*opd_sym_map) / 8; |
4ce794b7 | 4889 | opd_sym_map = bfd_zalloc (abfd, amt); |
1e2f5b6e | 4890 | if (opd_sym_map == NULL) |
b34976b6 | 4891 | return FALSE; |
74f0fb50 | 4892 | ppc64_elf_section_data (sec)->u.opd.func_sec = opd_sym_map; |
7c8fe5c4 AM |
4893 | BFD_ASSERT (ppc64_elf_section_data (sec)->sec_type == sec_normal); |
4894 | ppc64_elf_section_data (sec)->sec_type = sec_opd; | |
1e2f5b6e | 4895 | } |
5bd4f169 | 4896 | |
82bd7b59 AM |
4897 | if (htab->sfpr == NULL |
4898 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 4899 | return FALSE; |
82bd7b59 | 4900 | |
5bd4f169 AM |
4901 | rel_end = relocs + sec->reloc_count; |
4902 | for (rel = relocs; rel < rel_end; rel++) | |
4903 | { | |
4904 | unsigned long r_symndx; | |
4905 | struct elf_link_hash_entry *h; | |
04c9666a | 4906 | enum elf_ppc64_reloc_type r_type; |
727fc41e | 4907 | int tls_type; |
7c8fe5c4 | 4908 | struct _ppc64_elf_section_data *ppc64_sec; |
e054468f | 4909 | struct plt_entry **ifunc; |
5bd4f169 AM |
4910 | |
4911 | r_symndx = ELF64_R_SYM (rel->r_info); | |
4912 | if (r_symndx < symtab_hdr->sh_info) | |
4913 | h = NULL; | |
4914 | else | |
973a3492 L |
4915 | { |
4916 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
b31867b6 | 4917 | h = elf_follow_link (h); |
973a3492 | 4918 | } |
5bd4f169 | 4919 | |
727fc41e | 4920 | tls_type = 0; |
e054468f | 4921 | ifunc = NULL; |
25f23106 AM |
4922 | if (h != NULL) |
4923 | { | |
4924 | if (h->type == STT_GNU_IFUNC) | |
4925 | { | |
4926 | h->needs_plt = 1; | |
4927 | ifunc = &h->plt.plist; | |
4928 | } | |
4929 | } | |
4930 | else | |
4931 | { | |
4932 | Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache, | |
4933 | abfd, r_symndx); | |
4934 | if (isym == NULL) | |
4935 | return FALSE; | |
4936 | ||
4937 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) | |
4938 | { | |
4939 | ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
4940 | rel->r_addend, PLT_IFUNC); | |
4941 | if (ifunc == NULL) | |
4942 | return FALSE; | |
4943 | } | |
4944 | } | |
4ce794b7 | 4945 | r_type = ELF64_R_TYPE (rel->r_info); |
e054468f AM |
4946 | if (is_branch_reloc (r_type)) |
4947 | { | |
4948 | if (h != NULL && (h == tga || h == dottga)) | |
4949 | { | |
4950 | if (rel != relocs | |
4951 | && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD | |
4952 | || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD)) | |
4953 | /* We have a new-style __tls_get_addr call with a marker | |
4954 | reloc. */ | |
4955 | ; | |
4956 | else | |
4957 | /* Mark this section as having an old-style call. */ | |
4958 | sec->has_tls_get_addr_call = 1; | |
4959 | } | |
727fc41e | 4960 | |
e054468f | 4961 | /* STT_GNU_IFUNC symbols must have a PLT entry. */ |
e054468f AM |
4962 | if (ifunc != NULL |
4963 | && !update_plt_info (abfd, ifunc, rel->r_addend)) | |
4964 | return FALSE; | |
4965 | } | |
727fc41e | 4966 | |
a33d1f77 | 4967 | switch (r_type) |
5bd4f169 | 4968 | { |
727fc41e AM |
4969 | case R_PPC64_TLSGD: |
4970 | case R_PPC64_TLSLD: | |
4971 | /* These special tls relocs tie a call to __tls_get_addr with | |
4972 | its parameter symbol. */ | |
4973 | break; | |
4974 | ||
411e1bfb AM |
4975 | case R_PPC64_GOT_TLSLD16: |
4976 | case R_PPC64_GOT_TLSLD16_LO: | |
4977 | case R_PPC64_GOT_TLSLD16_HI: | |
4978 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 4979 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
4980 | goto dogottls; |
4981 | ||
4982 | case R_PPC64_GOT_TLSGD16: | |
4983 | case R_PPC64_GOT_TLSGD16_LO: | |
4984 | case R_PPC64_GOT_TLSGD16_HI: | |
4985 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 4986 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
4987 | goto dogottls; |
4988 | ||
4989 | case R_PPC64_GOT_TPREL16_DS: | |
4990 | case R_PPC64_GOT_TPREL16_LO_DS: | |
4991 | case R_PPC64_GOT_TPREL16_HI: | |
4992 | case R_PPC64_GOT_TPREL16_HA: | |
1d483afe | 4993 | if (!info->executable) |
411e1bfb AM |
4994 | info->flags |= DF_STATIC_TLS; |
4995 | tls_type = TLS_TLS | TLS_TPREL; | |
4996 | goto dogottls; | |
4997 | ||
4998 | case R_PPC64_GOT_DTPREL16_DS: | |
4999 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
5000 | case R_PPC64_GOT_DTPREL16_HI: | |
5001 | case R_PPC64_GOT_DTPREL16_HA: | |
5002 | tls_type = TLS_TLS | TLS_DTPREL; | |
5003 | dogottls: | |
5004 | sec->has_tls_reloc = 1; | |
5005 | /* Fall thru */ | |
5006 | ||
5bd4f169 | 5007 | case R_PPC64_GOT16: |
5bd4f169 | 5008 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
5009 | case R_PPC64_GOT16_HA: |
5010 | case R_PPC64_GOT16_HI: | |
5011 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 5012 | case R_PPC64_GOT16_LO_DS: |
65f38f15 | 5013 | /* This symbol requires a global offset table entry. */ |
4c52953f | 5014 | sec->has_toc_reloc = 1; |
33c0ec9d AM |
5015 | if (r_type == R_PPC64_GOT_TLSLD16 |
5016 | || r_type == R_PPC64_GOT_TLSGD16 | |
5017 | || r_type == R_PPC64_GOT_TPREL16_DS | |
5018 | || r_type == R_PPC64_GOT_DTPREL16_DS | |
5019 | || r_type == R_PPC64_GOT16 | |
5020 | || r_type == R_PPC64_GOT16_DS) | |
5021 | { | |
5022 | htab->do_multi_toc = 1; | |
d77c8a4b | 5023 | ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1; |
33c0ec9d AM |
5024 | } |
5025 | ||
e717da7e AM |
5026 | if (ppc64_elf_tdata (abfd)->got == NULL |
5027 | && !create_got_section (abfd, info)) | |
b34976b6 | 5028 | return FALSE; |
5bd4f169 AM |
5029 | |
5030 | if (h != NULL) | |
5031 | { | |
411e1bfb AM |
5032 | struct ppc_link_hash_entry *eh; |
5033 | struct got_entry *ent; | |
65f38f15 | 5034 | |
411e1bfb AM |
5035 | eh = (struct ppc_link_hash_entry *) h; |
5036 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) | |
5037 | if (ent->addend == rel->r_addend | |
e717da7e | 5038 | && ent->owner == abfd |
411e1bfb AM |
5039 | && ent->tls_type == tls_type) |
5040 | break; | |
5041 | if (ent == NULL) | |
5bd4f169 | 5042 | { |
411e1bfb | 5043 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 5044 | ent = bfd_alloc (abfd, amt); |
411e1bfb | 5045 | if (ent == NULL) |
b34976b6 | 5046 | return FALSE; |
411e1bfb AM |
5047 | ent->next = eh->elf.got.glist; |
5048 | ent->addend = rel->r_addend; | |
e717da7e | 5049 | ent->owner = abfd; |
411e1bfb | 5050 | ent->tls_type = tls_type; |
927be08e | 5051 | ent->is_indirect = FALSE; |
411e1bfb AM |
5052 | ent->got.refcount = 0; |
5053 | eh->elf.got.glist = ent; | |
5bd4f169 | 5054 | } |
411e1bfb | 5055 | ent->got.refcount += 1; |
e7b938ca | 5056 | eh->tls_mask |= tls_type; |
5bd4f169 | 5057 | } |
411e1bfb AM |
5058 | else |
5059 | /* This is a global offset table entry for a local symbol. */ | |
5060 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
5061 | rel->r_addend, tls_type)) | |
5062 | return FALSE; | |
5bd4f169 AM |
5063 | break; |
5064 | ||
5bd4f169 | 5065 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
5066 | case R_PPC64_PLT16_HI: |
5067 | case R_PPC64_PLT16_LO: | |
5068 | case R_PPC64_PLT32: | |
5069 | case R_PPC64_PLT64: | |
5bd4f169 | 5070 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
5071 | actually build the entry in adjust_dynamic_symbol, |
5072 | because this might be a case of linking PIC code without | |
5073 | linking in any dynamic objects, in which case we don't | |
5074 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
5075 | if (h == NULL) |
5076 | { | |
5077 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 5078 | table entry for a local symbol. */ |
5bd4f169 | 5079 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 5080 | return FALSE; |
5bd4f169 | 5081 | } |
411e1bfb | 5082 | else |
e054468f AM |
5083 | { |
5084 | if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend)) | |
5085 | return FALSE; | |
5086 | h->needs_plt = 1; | |
5087 | if (h->root.root.string[0] == '.' | |
5088 | && h->root.root.string[1] != '\0') | |
5089 | ((struct ppc_link_hash_entry *) h)->is_func = 1; | |
5090 | } | |
5bd4f169 AM |
5091 | break; |
5092 | ||
5093 | /* The following relocations don't need to propagate the | |
5094 | relocation if linking a shared object since they are | |
5095 | section relative. */ | |
5096 | case R_PPC64_SECTOFF: | |
5097 | case R_PPC64_SECTOFF_LO: | |
5098 | case R_PPC64_SECTOFF_HI: | |
5099 | case R_PPC64_SECTOFF_HA: | |
5100 | case R_PPC64_SECTOFF_DS: | |
5101 | case R_PPC64_SECTOFF_LO_DS: | |
411e1bfb AM |
5102 | case R_PPC64_DTPREL16: |
5103 | case R_PPC64_DTPREL16_LO: | |
5104 | case R_PPC64_DTPREL16_HI: | |
5105 | case R_PPC64_DTPREL16_HA: | |
5106 | case R_PPC64_DTPREL16_DS: | |
5107 | case R_PPC64_DTPREL16_LO_DS: | |
5108 | case R_PPC64_DTPREL16_HIGHER: | |
5109 | case R_PPC64_DTPREL16_HIGHERA: | |
5110 | case R_PPC64_DTPREL16_HIGHEST: | |
5111 | case R_PPC64_DTPREL16_HIGHESTA: | |
5bd4f169 AM |
5112 | break; |
5113 | ||
ad8e1ba5 | 5114 | /* Nor do these. */ |
25f23106 AM |
5115 | case R_PPC64_REL16: |
5116 | case R_PPC64_REL16_LO: | |
5117 | case R_PPC64_REL16_HI: | |
5118 | case R_PPC64_REL16_HA: | |
5119 | break; | |
5120 | ||
ad8e1ba5 | 5121 | case R_PPC64_TOC16: |
33c0ec9d AM |
5122 | case R_PPC64_TOC16_DS: |
5123 | htab->do_multi_toc = 1; | |
d77c8a4b | 5124 | ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1; |
ad8e1ba5 AM |
5125 | case R_PPC64_TOC16_LO: |
5126 | case R_PPC64_TOC16_HI: | |
5127 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 5128 | case R_PPC64_TOC16_LO_DS: |
4c52953f | 5129 | sec->has_toc_reloc = 1; |
ad8e1ba5 AM |
5130 | break; |
5131 | ||
5bd4f169 AM |
5132 | /* This relocation describes the C++ object vtable hierarchy. |
5133 | Reconstruct it for later use during GC. */ | |
5134 | case R_PPC64_GNU_VTINHERIT: | |
c152c796 | 5135 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 5136 | return FALSE; |
5bd4f169 AM |
5137 | break; |
5138 | ||
5139 | /* This relocation describes which C++ vtable entries are actually | |
5140 | used. Record for later use during GC. */ | |
5141 | case R_PPC64_GNU_VTENTRY: | |
d17e0c6e JB |
5142 | BFD_ASSERT (h != NULL); |
5143 | if (h != NULL | |
5144 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 5145 | return FALSE; |
5bd4f169 AM |
5146 | break; |
5147 | ||
721956f4 AM |
5148 | case R_PPC64_REL14: |
5149 | case R_PPC64_REL14_BRTAKEN: | |
5150 | case R_PPC64_REL14_BRNTAKEN: | |
220c76dd AM |
5151 | { |
5152 | asection *dest = NULL; | |
5153 | ||
5154 | /* Heuristic: If jumping outside our section, chances are | |
5155 | we are going to need a stub. */ | |
5156 | if (h != NULL) | |
5157 | { | |
5158 | /* If the sym is weak it may be overridden later, so | |
5159 | don't assume we know where a weak sym lives. */ | |
5160 | if (h->root.type == bfd_link_hash_defined) | |
5161 | dest = h->root.u.def.section; | |
5162 | } | |
5163 | else | |
87d72d41 AM |
5164 | { |
5165 | Elf_Internal_Sym *isym; | |
5166 | ||
5167 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, | |
5168 | abfd, r_symndx); | |
5169 | if (isym == NULL) | |
5170 | return FALSE; | |
5171 | ||
5172 | dest = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
5173 | } | |
5174 | ||
220c76dd | 5175 | if (dest != sec) |
7c8fe5c4 | 5176 | ppc64_elf_section_data (sec)->has_14bit_branch = 1; |
220c76dd | 5177 | } |
721956f4 AM |
5178 | /* Fall through. */ |
5179 | ||
5d1634d7 | 5180 | case R_PPC64_REL24: |
e054468f | 5181 | if (h != NULL && ifunc == NULL) |
5d1634d7 AM |
5182 | { |
5183 | /* We may need a .plt entry if the function this reloc | |
5184 | refers to is in a shared lib. */ | |
e054468f | 5185 | if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend)) |
411e1bfb | 5186 | return FALSE; |
e054468f AM |
5187 | h->needs_plt = 1; |
5188 | if (h->root.root.string[0] == '.' | |
5189 | && h->root.root.string[1] != '\0') | |
5190 | ((struct ppc_link_hash_entry *) h)->is_func = 1; | |
3a71aa26 | 5191 | if (h == tga || h == dottga) |
411e1bfb | 5192 | sec->has_tls_reloc = 1; |
411e1bfb AM |
5193 | } |
5194 | break; | |
5195 | ||
5196 | case R_PPC64_TPREL64: | |
5197 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | |
1d483afe | 5198 | if (!info->executable) |
411e1bfb AM |
5199 | info->flags |= DF_STATIC_TLS; |
5200 | goto dotlstoc; | |
5201 | ||
5202 | case R_PPC64_DTPMOD64: | |
5203 | if (rel + 1 < rel_end | |
5204 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
5205 | && rel[1].r_offset == rel->r_offset + 8) | |
951fd09b | 5206 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
411e1bfb | 5207 | else |
951fd09b | 5208 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
411e1bfb AM |
5209 | goto dotlstoc; |
5210 | ||
5211 | case R_PPC64_DTPREL64: | |
5212 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; | |
5213 | if (rel != relocs | |
5214 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) | |
5215 | && rel[-1].r_offset == rel->r_offset - 8) | |
5216 | /* This is the second reloc of a dtpmod, dtprel pair. | |
5217 | Don't mark with TLS_DTPREL. */ | |
5218 | goto dodyn; | |
5219 | ||
5220 | dotlstoc: | |
5221 | sec->has_tls_reloc = 1; | |
5222 | if (h != NULL) | |
5223 | { | |
5224 | struct ppc_link_hash_entry *eh; | |
5225 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 5226 | eh->tls_mask |= tls_type; |
411e1bfb AM |
5227 | } |
5228 | else | |
5229 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
5230 | rel->r_addend, tls_type)) | |
5231 | return FALSE; | |
5232 | ||
7c8fe5c4 AM |
5233 | ppc64_sec = ppc64_elf_section_data (sec); |
5234 | if (ppc64_sec->sec_type != sec_toc) | |
411e1bfb | 5235 | { |
3a71aa26 AM |
5236 | bfd_size_type amt; |
5237 | ||
e7b938ca | 5238 | /* One extra to simplify get_tls_mask. */ |
3a71aa26 AM |
5239 | amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned); |
5240 | ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt); | |
5241 | if (ppc64_sec->u.toc.symndx == NULL) | |
5242 | return FALSE; | |
5243 | amt = sec->size * sizeof (bfd_vma) / 8; | |
5244 | ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt); | |
5245 | if (ppc64_sec->u.toc.add == NULL) | |
411e1bfb | 5246 | return FALSE; |
7c8fe5c4 AM |
5247 | BFD_ASSERT (ppc64_sec->sec_type == sec_normal); |
5248 | ppc64_sec->sec_type = sec_toc; | |
411e1bfb AM |
5249 | } |
5250 | BFD_ASSERT (rel->r_offset % 8 == 0); | |
3a71aa26 AM |
5251 | ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx; |
5252 | ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend; | |
951fd09b AM |
5253 | |
5254 | /* Mark the second slot of a GD or LD entry. | |
5255 | -1 to indicate GD and -2 to indicate LD. */ | |
5256 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | |
3a71aa26 | 5257 | ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -1; |
951fd09b | 5258 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) |
3a71aa26 | 5259 | ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2; |
411e1bfb AM |
5260 | goto dodyn; |
5261 | ||
5262 | case R_PPC64_TPREL16: | |
5263 | case R_PPC64_TPREL16_LO: | |
5264 | case R_PPC64_TPREL16_HI: | |
5265 | case R_PPC64_TPREL16_HA: | |
5266 | case R_PPC64_TPREL16_DS: | |
5267 | case R_PPC64_TPREL16_LO_DS: | |
5268 | case R_PPC64_TPREL16_HIGHER: | |
5269 | case R_PPC64_TPREL16_HIGHERA: | |
5270 | case R_PPC64_TPREL16_HIGHEST: | |
5271 | case R_PPC64_TPREL16_HIGHESTA: | |
5272 | if (info->shared) | |
5273 | { | |
1d483afe AM |
5274 | if (!info->executable) |
5275 | info->flags |= DF_STATIC_TLS; | |
411e1bfb | 5276 | goto dodyn; |
5d1634d7 AM |
5277 | } |
5278 | break; | |
5279 | ||
e86ce104 | 5280 | case R_PPC64_ADDR64: |
1e2f5b6e | 5281 | if (opd_sym_map != NULL |
1e2f5b6e | 5282 | && rel + 1 < rel_end |
4ce794b7 | 5283 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
1e2f5b6e | 5284 | { |
8387904d AM |
5285 | if (h != NULL) |
5286 | { | |
5287 | if (h->root.root.string[0] == '.' | |
5288 | && h->root.root.string[1] != 0 | |
b31867b6 | 5289 | && lookup_fdh ((struct ppc_link_hash_entry *) h, htab)) |
8387904d AM |
5290 | ; |
5291 | else | |
5292 | ((struct ppc_link_hash_entry *) h)->is_func = 1; | |
5293 | } | |
5294 | else | |
5295 | { | |
5296 | asection *s; | |
87d72d41 | 5297 | Elf_Internal_Sym *isym; |
1e2f5b6e | 5298 | |
87d72d41 AM |
5299 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
5300 | abfd, r_symndx); | |
5301 | if (isym == NULL) | |
8387904d | 5302 | return FALSE; |
87d72d41 AM |
5303 | |
5304 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
5305 | if (s != NULL && s != sec) | |
3f764659 | 5306 | opd_sym_map[rel->r_offset / 8] = s; |
8387904d | 5307 | } |
1e2f5b6e | 5308 | } |
e86ce104 AM |
5309 | /* Fall through. */ |
5310 | ||
04c9666a | 5311 | case R_PPC64_REL30: |
5bd4f169 | 5312 | case R_PPC64_REL32: |
04c9666a | 5313 | case R_PPC64_REL64: |
65f38f15 AM |
5314 | case R_PPC64_ADDR14: |
5315 | case R_PPC64_ADDR14_BRNTAKEN: | |
5316 | case R_PPC64_ADDR14_BRTAKEN: | |
5317 | case R_PPC64_ADDR16: | |
5318 | case R_PPC64_ADDR16_DS: | |
5319 | case R_PPC64_ADDR16_HA: | |
5320 | case R_PPC64_ADDR16_HI: | |
5321 | case R_PPC64_ADDR16_HIGHER: | |
5322 | case R_PPC64_ADDR16_HIGHERA: | |
5323 | case R_PPC64_ADDR16_HIGHEST: | |
5324 | case R_PPC64_ADDR16_HIGHESTA: | |
5325 | case R_PPC64_ADDR16_LO: | |
5326 | case R_PPC64_ADDR16_LO_DS: | |
5327 | case R_PPC64_ADDR24: | |
65f38f15 | 5328 | case R_PPC64_ADDR32: |
65f38f15 AM |
5329 | case R_PPC64_UADDR16: |
5330 | case R_PPC64_UADDR32: | |
5331 | case R_PPC64_UADDR64: | |
5bd4f169 | 5332 | case R_PPC64_TOC: |
81848ca0 AM |
5333 | if (h != NULL && !info->shared) |
5334 | /* We may need a copy reloc. */ | |
f5385ebf | 5335 | h->non_got_ref = 1; |
81848ca0 | 5336 | |
41bd81ab | 5337 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 5338 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 5339 | break; |
e86ce104 | 5340 | |
65f38f15 AM |
5341 | /* If we are creating a shared library, and this is a reloc |
5342 | against a global symbol, or a non PC relative reloc | |
5343 | against a local symbol, then we need to copy the reloc | |
5344 | into the shared library. However, if we are linking with | |
5345 | -Bsymbolic, we do not need to copy a reloc against a | |
5346 | global symbol which is defined in an object we are | |
5347 | including in the link (i.e., DEF_REGULAR is set). At | |
5348 | this point we have not seen all the input files, so it is | |
5349 | possible that DEF_REGULAR is not set now but will be set | |
5350 | later (it is never cleared). In case of a weak definition, | |
5351 | DEF_REGULAR may be cleared later by a strong definition in | |
5352 | a shared library. We account for that possibility below by | |
f4656909 | 5353 | storing information in the dyn_relocs field of the hash |
65f38f15 AM |
5354 | table entry. A similar situation occurs when creating |
5355 | shared libraries and symbol visibility changes render the | |
5356 | symbol local. | |
5357 | ||
5358 | If on the other hand, we are creating an executable, we | |
5359 | may need to keep relocations for symbols satisfied by a | |
5360 | dynamic library if we manage to avoid copy relocs for the | |
5361 | symbol. */ | |
411e1bfb | 5362 | dodyn: |
65f38f15 | 5363 | if ((info->shared |
1d483afe | 5364 | && (must_be_dyn_reloc (info, r_type) |
65f38f15 AM |
5365 | || (h != NULL |
5366 | && (! info->symbolic | |
5367 | || h->root.type == bfd_link_hash_defweak | |
f5385ebf | 5368 | || !h->def_regular)))) |
f4656909 AM |
5369 | || (ELIMINATE_COPY_RELOCS |
5370 | && !info->shared | |
65f38f15 AM |
5371 | && h != NULL |
5372 | && (h->root.type == bfd_link_hash_defweak | |
25f23106 AM |
5373 | || !h->def_regular)) |
5374 | || (!info->shared | |
5375 | && ifunc != NULL)) | |
5bd4f169 | 5376 | { |
6061a67d AM |
5377 | struct elf_dyn_relocs *p; |
5378 | struct elf_dyn_relocs **head; | |
ec338859 | 5379 | |
65f38f15 AM |
5380 | /* We must copy these reloc types into the output file. |
5381 | Create a reloc section in dynobj and make room for | |
5382 | this reloc. */ | |
5bd4f169 AM |
5383 | if (sreloc == NULL) |
5384 | { | |
83bac4b0 NC |
5385 | sreloc = _bfd_elf_make_dynamic_reloc_section |
5386 | (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE); | |
65f38f15 | 5387 | |
5bd4f169 | 5388 | if (sreloc == NULL) |
83bac4b0 | 5389 | return FALSE; |
5bd4f169 AM |
5390 | } |
5391 | ||
65f38f15 AM |
5392 | /* If this is a global symbol, we count the number of |
5393 | relocations we need for this symbol. */ | |
5394 | if (h != NULL) | |
5395 | { | |
ec338859 | 5396 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
5397 | } |
5398 | else | |
5399 | { | |
ec338859 AM |
5400 | /* Track dynamic relocs needed for local syms too. |
5401 | We really need local syms available to do this | |
5402 | easily. Oh well. */ | |
ec338859 | 5403 | asection *s; |
6edfbbad | 5404 | void *vpp; |
87d72d41 | 5405 | Elf_Internal_Sym *isym; |
6edfbbad | 5406 | |
87d72d41 AM |
5407 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
5408 | abfd, r_symndx); | |
5409 | if (isym == NULL) | |
b34976b6 | 5410 | return FALSE; |
ec338859 | 5411 | |
87d72d41 AM |
5412 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
5413 | if (s == NULL) | |
5414 | s = sec; | |
5415 | ||
6edfbbad | 5416 | vpp = &elf_section_data (s)->local_dynrel; |
6061a67d | 5417 | head = (struct elf_dyn_relocs **) vpp; |
65f38f15 | 5418 | } |
ec338859 AM |
5419 | |
5420 | p = *head; | |
5421 | if (p == NULL || p->sec != sec) | |
5422 | { | |
4ce794b7 | 5423 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
ec338859 | 5424 | if (p == NULL) |
b34976b6 | 5425 | return FALSE; |
ec338859 AM |
5426 | p->next = *head; |
5427 | *head = p; | |
5428 | p->sec = sec; | |
5429 | p->count = 0; | |
5430 | p->pc_count = 0; | |
5431 | } | |
5432 | ||
5433 | p->count += 1; | |
1d483afe | 5434 | if (!must_be_dyn_reloc (info, r_type)) |
ec338859 | 5435 | p->pc_count += 1; |
65f38f15 | 5436 | } |
5bd4f169 | 5437 | break; |
65f38f15 AM |
5438 | |
5439 | default: | |
96e0dda4 | 5440 | break; |
5bd4f169 AM |
5441 | } |
5442 | } | |
5443 | ||
b34976b6 | 5444 | return TRUE; |
5bd4f169 AM |
5445 | } |
5446 | ||
8387904d AM |
5447 | /* OFFSET in OPD_SEC specifies a function descriptor. Return the address |
5448 | of the code entry point, and its section. */ | |
5449 | ||
5450 | static bfd_vma | |
5451 | opd_entry_value (asection *opd_sec, | |
5452 | bfd_vma offset, | |
5453 | asection **code_sec, | |
5454 | bfd_vma *code_off) | |
5455 | { | |
5456 | bfd *opd_bfd = opd_sec->owner; | |
8860955f | 5457 | Elf_Internal_Rela *relocs; |
8387904d | 5458 | Elf_Internal_Rela *lo, *hi, *look; |
645ea6a9 | 5459 | bfd_vma val; |
8387904d | 5460 | |
4b85d634 AM |
5461 | /* No relocs implies we are linking a --just-symbols object. */ |
5462 | if (opd_sec->reloc_count == 0) | |
5463 | { | |
aa374f67 AM |
5464 | char buf[8]; |
5465 | ||
5466 | if (!bfd_get_section_contents (opd_bfd, opd_sec, buf, offset, 8)) | |
4b85d634 | 5467 | return (bfd_vma) -1; |
3b36f7e6 | 5468 | |
aa374f67 | 5469 | val = bfd_get_64 (opd_bfd, buf); |
4b85d634 AM |
5470 | if (code_sec != NULL) |
5471 | { | |
5472 | asection *sec, *likely = NULL; | |
5473 | for (sec = opd_bfd->sections; sec != NULL; sec = sec->next) | |
5474 | if (sec->vma <= val | |
5475 | && (sec->flags & SEC_LOAD) != 0 | |
5476 | && (sec->flags & SEC_ALLOC) != 0) | |
5477 | likely = sec; | |
5478 | if (likely != NULL) | |
5479 | { | |
5480 | *code_sec = likely; | |
5481 | if (code_off != NULL) | |
5482 | *code_off = val - likely->vma; | |
5483 | } | |
5484 | } | |
5485 | return val; | |
5486 | } | |
5487 | ||
0c8d6e5c | 5488 | BFD_ASSERT (is_ppc64_elf (opd_bfd)); |
0ffa91dd | 5489 | |
8860955f AM |
5490 | relocs = ppc64_elf_tdata (opd_bfd)->opd_relocs; |
5491 | if (relocs == NULL) | |
5492 | relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE); | |
645ea6a9 | 5493 | |
8387904d | 5494 | /* Go find the opd reloc at the sym address. */ |
8860955f | 5495 | lo = relocs; |
8387904d AM |
5496 | BFD_ASSERT (lo != NULL); |
5497 | hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */ | |
645ea6a9 | 5498 | val = (bfd_vma) -1; |
8387904d AM |
5499 | while (lo < hi) |
5500 | { | |
5501 | look = lo + (hi - lo) / 2; | |
5502 | if (look->r_offset < offset) | |
5503 | lo = look + 1; | |
5504 | else if (look->r_offset > offset) | |
5505 | hi = look; | |
5506 | else | |
5507 | { | |
0ffa91dd NC |
5508 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (opd_bfd); |
5509 | ||
8387904d AM |
5510 | if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64 |
5511 | && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC) | |
5512 | { | |
5513 | unsigned long symndx = ELF64_R_SYM (look->r_info); | |
8387904d AM |
5514 | asection *sec; |
5515 | ||
5516 | if (symndx < symtab_hdr->sh_info) | |
5517 | { | |
5518 | Elf_Internal_Sym *sym; | |
5519 | ||
5520 | sym = (Elf_Internal_Sym *) symtab_hdr->contents; | |
5521 | if (sym == NULL) | |
5522 | { | |
5523 | sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, | |
5524 | symtab_hdr->sh_info, | |
5525 | 0, NULL, NULL, NULL); | |
5526 | if (sym == NULL) | |
645ea6a9 | 5527 | break; |
8387904d AM |
5528 | symtab_hdr->contents = (bfd_byte *) sym; |
5529 | } | |
5530 | ||
5531 | sym += symndx; | |
5532 | val = sym->st_value; | |
cb33740c | 5533 | sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx); |
8387904d AM |
5534 | BFD_ASSERT ((sec->flags & SEC_MERGE) == 0); |
5535 | } | |
5536 | else | |
5537 | { | |
5538 | struct elf_link_hash_entry **sym_hashes; | |
5539 | struct elf_link_hash_entry *rh; | |
5540 | ||
5541 | sym_hashes = elf_sym_hashes (opd_bfd); | |
5542 | rh = sym_hashes[symndx - symtab_hdr->sh_info]; | |
b31867b6 | 5543 | rh = elf_follow_link (rh); |
8387904d AM |
5544 | BFD_ASSERT (rh->root.type == bfd_link_hash_defined |
5545 | || rh->root.type == bfd_link_hash_defweak); | |
5546 | val = rh->root.u.def.value; | |
5547 | sec = rh->root.u.def.section; | |
5548 | } | |
5549 | val += look->r_addend; | |
5550 | if (code_off != NULL) | |
5551 | *code_off = val; | |
5552 | if (code_sec != NULL) | |
5553 | *code_sec = sec; | |
5554 | if (sec != NULL && sec->output_section != NULL) | |
5555 | val += sec->output_section->vma + sec->output_offset; | |
8387904d AM |
5556 | } |
5557 | break; | |
5558 | } | |
5559 | } | |
645ea6a9 | 5560 | |
645ea6a9 | 5561 | return val; |
8387904d AM |
5562 | } |
5563 | ||
854b41e7 AM |
5564 | /* Return true if symbol is defined in a regular object file. */ |
5565 | ||
5566 | static bfd_boolean | |
5567 | is_static_defined (struct elf_link_hash_entry *h) | |
5568 | { | |
5569 | return ((h->root.type == bfd_link_hash_defined | |
5570 | || h->root.type == bfd_link_hash_defweak) | |
5571 | && h->root.u.def.section != NULL | |
5572 | && h->root.u.def.section->output_section != NULL); | |
5573 | } | |
5574 | ||
b31867b6 AM |
5575 | /* If FDH is a function descriptor symbol, return the associated code |
5576 | entry symbol if it is defined. Return NULL otherwise. */ | |
5577 | ||
5578 | static struct ppc_link_hash_entry * | |
5579 | defined_code_entry (struct ppc_link_hash_entry *fdh) | |
5580 | { | |
5581 | if (fdh->is_func_descriptor) | |
5582 | { | |
5583 | struct ppc_link_hash_entry *fh = ppc_follow_link (fdh->oh); | |
5584 | if (fh->elf.root.type == bfd_link_hash_defined | |
5585 | || fh->elf.root.type == bfd_link_hash_defweak) | |
5586 | return fh; | |
5587 | } | |
5588 | return NULL; | |
5589 | } | |
5590 | ||
5591 | /* If FH is a function code entry symbol, return the associated | |
5592 | function descriptor symbol if it is defined. Return NULL otherwise. */ | |
5593 | ||
5594 | static struct ppc_link_hash_entry * | |
5595 | defined_func_desc (struct ppc_link_hash_entry *fh) | |
5596 | { | |
5597 | if (fh->oh != NULL | |
5598 | && fh->oh->is_func_descriptor) | |
5599 | { | |
5600 | struct ppc_link_hash_entry *fdh = ppc_follow_link (fh->oh); | |
5601 | if (fdh->elf.root.type == bfd_link_hash_defined | |
5602 | || fdh->elf.root.type == bfd_link_hash_defweak) | |
5603 | return fdh; | |
5604 | } | |
5605 | return NULL; | |
5606 | } | |
5607 | ||
74f0fb50 AM |
5608 | /* Mark all our entry sym sections, both opd and code section. */ |
5609 | ||
5610 | static void | |
5611 | ppc64_elf_gc_keep (struct bfd_link_info *info) | |
5612 | { | |
5613 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
5614 | struct bfd_sym_chain *sym; | |
5615 | ||
4dfe6ac6 NC |
5616 | if (htab == NULL) |
5617 | return; | |
5618 | ||
74f0fb50 AM |
5619 | for (sym = info->gc_sym_list; sym != NULL; sym = sym->next) |
5620 | { | |
b31867b6 | 5621 | struct ppc_link_hash_entry *eh, *fh; |
74f0fb50 AM |
5622 | asection *sec; |
5623 | ||
5624 | eh = (struct ppc_link_hash_entry *) | |
b31867b6 | 5625 | elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE); |
74f0fb50 AM |
5626 | if (eh == NULL) |
5627 | continue; | |
5628 | if (eh->elf.root.type != bfd_link_hash_defined | |
5629 | && eh->elf.root.type != bfd_link_hash_defweak) | |
5630 | continue; | |
5631 | ||
b31867b6 AM |
5632 | fh = defined_code_entry (eh); |
5633 | if (fh != NULL) | |
74f0fb50 | 5634 | { |
b31867b6 | 5635 | sec = fh->elf.root.u.def.section; |
74f0fb50 AM |
5636 | sec->flags |= SEC_KEEP; |
5637 | } | |
5638 | else if (get_opd_info (eh->elf.root.u.def.section) != NULL | |
5639 | && opd_entry_value (eh->elf.root.u.def.section, | |
5640 | eh->elf.root.u.def.value, | |
5641 | &sec, NULL) != (bfd_vma) -1) | |
5642 | sec->flags |= SEC_KEEP; | |
5643 | ||
5644 | sec = eh->elf.root.u.def.section; | |
5645 | sec->flags |= SEC_KEEP; | |
5646 | } | |
5647 | } | |
5648 | ||
64d03ab5 AM |
5649 | /* Mark sections containing dynamically referenced symbols. When |
5650 | building shared libraries, we must assume that any visible symbol is | |
5651 | referenced. */ | |
5652 | ||
5653 | static bfd_boolean | |
5654 | ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf) | |
5655 | { | |
5656 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
5657 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h; | |
b31867b6 | 5658 | struct ppc_link_hash_entry *fdh; |
64d03ab5 | 5659 | |
64d03ab5 | 5660 | /* Dynamic linking info is on the func descriptor sym. */ |
b31867b6 AM |
5661 | fdh = defined_func_desc (eh); |
5662 | if (fdh != NULL) | |
5663 | eh = fdh; | |
64d03ab5 AM |
5664 | |
5665 | if ((eh->elf.root.type == bfd_link_hash_defined | |
5666 | || eh->elf.root.type == bfd_link_hash_defweak) | |
5667 | && (eh->elf.ref_dynamic | |
5668 | || (!info->executable | |
5669 | && eh->elf.def_regular | |
5670 | && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL | |
5671 | && ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN))) | |
5672 | { | |
5673 | asection *code_sec; | |
b31867b6 | 5674 | struct ppc_link_hash_entry *fh; |
64d03ab5 AM |
5675 | |
5676 | eh->elf.root.u.def.section->flags |= SEC_KEEP; | |
5677 | ||
5678 | /* Function descriptor syms cause the associated | |
5679 | function code sym section to be marked. */ | |
b31867b6 AM |
5680 | fh = defined_code_entry (eh); |
5681 | if (fh != NULL) | |
5682 | { | |
5683 | code_sec = fh->elf.root.u.def.section; | |
5684 | code_sec->flags |= SEC_KEEP; | |
5685 | } | |
64d03ab5 AM |
5686 | else if (get_opd_info (eh->elf.root.u.def.section) != NULL |
5687 | && opd_entry_value (eh->elf.root.u.def.section, | |
5688 | eh->elf.root.u.def.value, | |
5689 | &code_sec, NULL) != (bfd_vma) -1) | |
5690 | code_sec->flags |= SEC_KEEP; | |
5691 | } | |
5692 | ||
5693 | return TRUE; | |
5694 | } | |
5695 | ||
5bd4f169 AM |
5696 | /* Return the section that should be marked against GC for a given |
5697 | relocation. */ | |
5698 | ||
5699 | static asection * | |
4ce794b7 | 5700 | ppc64_elf_gc_mark_hook (asection *sec, |
fb34365b | 5701 | struct bfd_link_info *info, |
4ce794b7 AM |
5702 | Elf_Internal_Rela *rel, |
5703 | struct elf_link_hash_entry *h, | |
5704 | Elf_Internal_Sym *sym) | |
5bd4f169 | 5705 | { |
ccfa59ea AM |
5706 | asection *rsec; |
5707 | ||
ccfa59ea AM |
5708 | /* Syms return NULL if we're marking .opd, so we avoid marking all |
5709 | function sections, as all functions are referenced in .opd. */ | |
5710 | rsec = NULL; | |
5711 | if (get_opd_info (sec) != NULL) | |
5712 | return rsec; | |
1e2f5b6e | 5713 | |
5bd4f169 AM |
5714 | if (h != NULL) |
5715 | { | |
04c9666a | 5716 | enum elf_ppc64_reloc_type r_type; |
b31867b6 | 5717 | struct ppc_link_hash_entry *eh, *fh, *fdh; |
a33d1f77 | 5718 | |
4ce794b7 | 5719 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 5720 | switch (r_type) |
5bd4f169 AM |
5721 | { |
5722 | case R_PPC64_GNU_VTINHERIT: | |
5723 | case R_PPC64_GNU_VTENTRY: | |
5724 | break; | |
5725 | ||
5726 | default: | |
5727 | switch (h->root.type) | |
5728 | { | |
5729 | case bfd_link_hash_defined: | |
5730 | case bfd_link_hash_defweak: | |
ccfa59ea | 5731 | eh = (struct ppc_link_hash_entry *) h; |
b31867b6 AM |
5732 | fdh = defined_func_desc (eh); |
5733 | if (fdh != NULL) | |
5734 | eh = fdh; | |
1e2f5b6e AM |
5735 | |
5736 | /* Function descriptor syms cause the associated | |
5737 | function code sym section to be marked. */ | |
b31867b6 AM |
5738 | fh = defined_code_entry (eh); |
5739 | if (fh != NULL) | |
ccfa59ea AM |
5740 | { |
5741 | /* They also mark their opd section. */ | |
74f0fb50 | 5742 | eh->elf.root.u.def.section->gc_mark = 1; |
ccfa59ea | 5743 | |
b31867b6 | 5744 | rsec = fh->elf.root.u.def.section; |
ccfa59ea | 5745 | } |
8387904d AM |
5746 | else if (get_opd_info (eh->elf.root.u.def.section) != NULL |
5747 | && opd_entry_value (eh->elf.root.u.def.section, | |
5748 | eh->elf.root.u.def.value, | |
5749 | &rsec, NULL) != (bfd_vma) -1) | |
74f0fb50 | 5750 | eh->elf.root.u.def.section->gc_mark = 1; |
ccfa59ea | 5751 | else |
1e2f5b6e AM |
5752 | rsec = h->root.u.def.section; |
5753 | break; | |
5bd4f169 AM |
5754 | |
5755 | case bfd_link_hash_common: | |
1e2f5b6e AM |
5756 | rsec = h->root.u.c.p->section; |
5757 | break; | |
5bd4f169 AM |
5758 | |
5759 | default: | |
fb34365b | 5760 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); |
5bd4f169 AM |
5761 | } |
5762 | } | |
5763 | } | |
5764 | else | |
5765 | { | |
74f0fb50 | 5766 | struct _opd_sec_data *opd; |
1e2f5b6e AM |
5767 | |
5768 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
74f0fb50 AM |
5769 | opd = get_opd_info (rsec); |
5770 | if (opd != NULL && opd->func_sec != NULL) | |
ccfa59ea | 5771 | { |
74f0fb50 | 5772 | rsec->gc_mark = 1; |
ccfa59ea | 5773 | |
74f0fb50 | 5774 | rsec = opd->func_sec[(sym->st_value + rel->r_addend) / 8]; |
ccfa59ea | 5775 | } |
5bd4f169 AM |
5776 | } |
5777 | ||
1e2f5b6e | 5778 | return rsec; |
5bd4f169 AM |
5779 | } |
5780 | ||
65f38f15 AM |
5781 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
5782 | section being removed. */ | |
5bd4f169 | 5783 | |
b34976b6 | 5784 | static bfd_boolean |
4ce794b7 AM |
5785 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
5786 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 5787 | { |
411e1bfb | 5788 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
5789 | Elf_Internal_Shdr *symtab_hdr; |
5790 | struct elf_link_hash_entry **sym_hashes; | |
411e1bfb | 5791 | struct got_entry **local_got_ents; |
5bd4f169 | 5792 | const Elf_Internal_Rela *rel, *relend; |
5bd4f169 | 5793 | |
7dda2462 TG |
5794 | if (info->relocatable) |
5795 | return TRUE; | |
5796 | ||
680a3378 AM |
5797 | if ((sec->flags & SEC_ALLOC) == 0) |
5798 | return TRUE; | |
5799 | ||
ec338859 AM |
5800 | elf_section_data (sec)->local_dynrel = NULL; |
5801 | ||
411e1bfb | 5802 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
5803 | if (htab == NULL) |
5804 | return FALSE; | |
5805 | ||
0ffa91dd | 5806 | symtab_hdr = &elf_symtab_hdr (abfd); |
5bd4f169 | 5807 | sym_hashes = elf_sym_hashes (abfd); |
411e1bfb | 5808 | local_got_ents = elf_local_got_ents (abfd); |
5bd4f169 AM |
5809 | |
5810 | relend = relocs + sec->reloc_count; | |
5811 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
5812 | { |
5813 | unsigned long r_symndx; | |
04c9666a | 5814 | enum elf_ppc64_reloc_type r_type; |
58ac9f71 | 5815 | struct elf_link_hash_entry *h = NULL; |
f961d9dd | 5816 | unsigned char tls_type = 0; |
5bd4f169 | 5817 | |
a33d1f77 | 5818 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 | 5819 | r_type = ELF64_R_TYPE (rel->r_info); |
58ac9f71 AM |
5820 | if (r_symndx >= symtab_hdr->sh_info) |
5821 | { | |
5822 | struct ppc_link_hash_entry *eh; | |
6061a67d AM |
5823 | struct elf_dyn_relocs **pp; |
5824 | struct elf_dyn_relocs *p; | |
58ac9f71 AM |
5825 | |
5826 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
b31867b6 | 5827 | h = elf_follow_link (h); |
58ac9f71 AM |
5828 | eh = (struct ppc_link_hash_entry *) h; |
5829 | ||
5830 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
5831 | if (p->sec == sec) | |
5832 | { | |
5833 | /* Everything must go for SEC. */ | |
5834 | *pp = p->next; | |
5835 | break; | |
5836 | } | |
5837 | } | |
5838 | ||
e054468f AM |
5839 | if (is_branch_reloc (r_type)) |
5840 | { | |
5841 | struct plt_entry **ifunc = NULL; | |
5842 | if (h != NULL) | |
5843 | { | |
5844 | if (h->type == STT_GNU_IFUNC) | |
5845 | ifunc = &h->plt.plist; | |
5846 | } | |
5847 | else if (local_got_ents != NULL) | |
5848 | { | |
5849 | struct plt_entry **local_plt = (struct plt_entry **) | |
5850 | (local_got_ents + symtab_hdr->sh_info); | |
f961d9dd | 5851 | unsigned char *local_got_tls_masks = (unsigned char *) |
e054468f AM |
5852 | (local_plt + symtab_hdr->sh_info); |
5853 | if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0) | |
5854 | ifunc = local_plt + r_symndx; | |
5855 | } | |
5856 | if (ifunc != NULL) | |
5857 | { | |
5858 | struct plt_entry *ent; | |
5859 | ||
5860 | for (ent = *ifunc; ent != NULL; ent = ent->next) | |
5861 | if (ent->addend == rel->r_addend) | |
5862 | break; | |
5863 | if (ent == NULL) | |
5864 | abort (); | |
5865 | if (ent->plt.refcount > 0) | |
5866 | ent->plt.refcount -= 1; | |
5867 | continue; | |
5868 | } | |
5869 | } | |
5870 | ||
a33d1f77 AM |
5871 | switch (r_type) |
5872 | { | |
411e1bfb AM |
5873 | case R_PPC64_GOT_TLSLD16: |
5874 | case R_PPC64_GOT_TLSLD16_LO: | |
5875 | case R_PPC64_GOT_TLSLD16_HI: | |
5876 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 5877 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
5878 | goto dogot; |
5879 | ||
5880 | case R_PPC64_GOT_TLSGD16: | |
5881 | case R_PPC64_GOT_TLSGD16_LO: | |
5882 | case R_PPC64_GOT_TLSGD16_HI: | |
5883 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 5884 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
5885 | goto dogot; |
5886 | ||
5887 | case R_PPC64_GOT_TPREL16_DS: | |
5888 | case R_PPC64_GOT_TPREL16_LO_DS: | |
5889 | case R_PPC64_GOT_TPREL16_HI: | |
5890 | case R_PPC64_GOT_TPREL16_HA: | |
5891 | tls_type = TLS_TLS | TLS_TPREL; | |
5892 | goto dogot; | |
5893 | ||
5894 | case R_PPC64_GOT_DTPREL16_DS: | |
5895 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
5896 | case R_PPC64_GOT_DTPREL16_HI: | |
5897 | case R_PPC64_GOT_DTPREL16_HA: | |
5898 | tls_type = TLS_TLS | TLS_DTPREL; | |
5899 | goto dogot; | |
5900 | ||
a33d1f77 AM |
5901 | case R_PPC64_GOT16: |
5902 | case R_PPC64_GOT16_DS: | |
5903 | case R_PPC64_GOT16_HA: | |
5904 | case R_PPC64_GOT16_HI: | |
5905 | case R_PPC64_GOT16_LO: | |
5906 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb AM |
5907 | dogot: |
5908 | { | |
5909 | struct got_entry *ent; | |
5910 | ||
58ac9f71 AM |
5911 | if (h != NULL) |
5912 | ent = h->got.glist; | |
411e1bfb AM |
5913 | else |
5914 | ent = local_got_ents[r_symndx]; | |
5915 | ||
5916 | for (; ent != NULL; ent = ent->next) | |
5917 | if (ent->addend == rel->r_addend | |
e717da7e | 5918 | && ent->owner == abfd |
411e1bfb AM |
5919 | && ent->tls_type == tls_type) |
5920 | break; | |
5921 | if (ent == NULL) | |
5922 | abort (); | |
5923 | if (ent->got.refcount > 0) | |
5924 | ent->got.refcount -= 1; | |
5925 | } | |
a33d1f77 | 5926 | break; |
65f38f15 | 5927 | |
a33d1f77 AM |
5928 | case R_PPC64_PLT16_HA: |
5929 | case R_PPC64_PLT16_HI: | |
5930 | case R_PPC64_PLT16_LO: | |
5931 | case R_PPC64_PLT32: | |
5932 | case R_PPC64_PLT64: | |
721956f4 AM |
5933 | case R_PPC64_REL14: |
5934 | case R_PPC64_REL14_BRNTAKEN: | |
5935 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 | 5936 | case R_PPC64_REL24: |
58ac9f71 | 5937 | if (h != NULL) |
5d1634d7 | 5938 | { |
411e1bfb AM |
5939 | struct plt_entry *ent; |
5940 | ||
411e1bfb AM |
5941 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
5942 | if (ent->addend == rel->r_addend) | |
5943 | break; | |
7c6c1722 | 5944 | if (ent != NULL && ent->plt.refcount > 0) |
411e1bfb | 5945 | ent->plt.refcount -= 1; |
5d1634d7 | 5946 | } |
e86ce104 | 5947 | break; |
5d1634d7 | 5948 | |
a33d1f77 AM |
5949 | default: |
5950 | break; | |
5951 | } | |
5952 | } | |
b34976b6 | 5953 | return TRUE; |
5bd4f169 AM |
5954 | } |
5955 | ||
deb0e272 AM |
5956 | /* The maximum size of .sfpr. */ |
5957 | #define SFPR_MAX (218*4) | |
5958 | ||
5959 | struct sfpr_def_parms | |
5960 | { | |
699733f6 AM |
5961 | const char name[12]; |
5962 | unsigned char lo, hi; | |
deb0e272 AM |
5963 | bfd_byte * (*write_ent) (bfd *, bfd_byte *, int); |
5964 | bfd_byte * (*write_tail) (bfd *, bfd_byte *, int); | |
5965 | }; | |
5966 | ||
5967 | /* Auto-generate _save*, _rest* functions in .sfpr. */ | |
5968 | ||
4dfe6ac6 | 5969 | static bfd_boolean |
deb0e272 AM |
5970 | sfpr_define (struct bfd_link_info *info, const struct sfpr_def_parms *parm) |
5971 | { | |
5972 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
5973 | unsigned int i; | |
5974 | size_t len = strlen (parm->name); | |
5975 | bfd_boolean writing = FALSE; | |
699733f6 | 5976 | char sym[16]; |
deb0e272 | 5977 | |
4dfe6ac6 NC |
5978 | if (htab == NULL) |
5979 | return FALSE; | |
5980 | ||
deb0e272 AM |
5981 | memcpy (sym, parm->name, len); |
5982 | sym[len + 2] = 0; | |
5983 | ||
5984 | for (i = parm->lo; i <= parm->hi; i++) | |
5985 | { | |
5986 | struct elf_link_hash_entry *h; | |
5987 | ||
5988 | sym[len + 0] = i / 10 + '0'; | |
5989 | sym[len + 1] = i % 10 + '0'; | |
5990 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); | |
5991 | if (h != NULL | |
f5385ebf | 5992 | && !h->def_regular) |
deb0e272 AM |
5993 | { |
5994 | h->root.type = bfd_link_hash_defined; | |
5995 | h->root.u.def.section = htab->sfpr; | |
5996 | h->root.u.def.value = htab->sfpr->size; | |
5997 | h->type = STT_FUNC; | |
f5385ebf | 5998 | h->def_regular = 1; |
deb0e272 AM |
5999 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
6000 | writing = TRUE; | |
6001 | if (htab->sfpr->contents == NULL) | |
6002 | { | |
6003 | htab->sfpr->contents = bfd_alloc (htab->elf.dynobj, SFPR_MAX); | |
6004 | if (htab->sfpr->contents == NULL) | |
6005 | return FALSE; | |
6006 | } | |
6007 | } | |
6008 | if (writing) | |
6009 | { | |
6010 | bfd_byte *p = htab->sfpr->contents + htab->sfpr->size; | |
6011 | if (i != parm->hi) | |
6012 | p = (*parm->write_ent) (htab->elf.dynobj, p, i); | |
6013 | else | |
6014 | p = (*parm->write_tail) (htab->elf.dynobj, p, i); | |
6015 | htab->sfpr->size = p - htab->sfpr->contents; | |
6016 | } | |
6017 | } | |
6018 | ||
6019 | return TRUE; | |
6020 | } | |
6021 | ||
6022 | static bfd_byte * | |
6023 | savegpr0 (bfd *abfd, bfd_byte *p, int r) | |
6024 | { | |
6025 | bfd_put_32 (abfd, STD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p); | |
6026 | return p + 4; | |
6027 | } | |
6028 | ||
6029 | static bfd_byte * | |
6030 | savegpr0_tail (bfd *abfd, bfd_byte *p, int r) | |
6031 | { | |
6032 | p = savegpr0 (abfd, p, r); | |
6033 | bfd_put_32 (abfd, STD_R0_0R1 + 16, p); | |
6034 | p = p + 4; | |
6035 | bfd_put_32 (abfd, BLR, p); | |
6036 | return p + 4; | |
6037 | } | |
6038 | ||
6039 | static bfd_byte * | |
6040 | restgpr0 (bfd *abfd, bfd_byte *p, int r) | |
6041 | { | |
6042 | bfd_put_32 (abfd, LD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p); | |
6043 | return p + 4; | |
6044 | } | |
6045 | ||
6046 | static bfd_byte * | |
6047 | restgpr0_tail (bfd *abfd, bfd_byte *p, int r) | |
6048 | { | |
6049 | bfd_put_32 (abfd, LD_R0_0R1 + 16, p); | |
6050 | p = p + 4; | |
6051 | p = restgpr0 (abfd, p, r); | |
6052 | bfd_put_32 (abfd, MTLR_R0, p); | |
6053 | p = p + 4; | |
6054 | if (r == 29) | |
6055 | { | |
6056 | p = restgpr0 (abfd, p, 30); | |
6057 | p = restgpr0 (abfd, p, 31); | |
6058 | } | |
6059 | bfd_put_32 (abfd, BLR, p); | |
6060 | return p + 4; | |
6061 | } | |
6062 | ||
6063 | static bfd_byte * | |
6064 | savegpr1 (bfd *abfd, bfd_byte *p, int r) | |
6065 | { | |
6066 | bfd_put_32 (abfd, STD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p); | |
6067 | return p + 4; | |
6068 | } | |
6069 | ||
6070 | static bfd_byte * | |
6071 | savegpr1_tail (bfd *abfd, bfd_byte *p, int r) | |
6072 | { | |
6073 | p = savegpr1 (abfd, p, r); | |
6074 | bfd_put_32 (abfd, BLR, p); | |
6075 | return p + 4; | |
6076 | } | |
6077 | ||
6078 | static bfd_byte * | |
6079 | restgpr1 (bfd *abfd, bfd_byte *p, int r) | |
6080 | { | |
6081 | bfd_put_32 (abfd, LD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p); | |
6082 | return p + 4; | |
6083 | } | |
6084 | ||
6085 | static bfd_byte * | |
6086 | restgpr1_tail (bfd *abfd, bfd_byte *p, int r) | |
6087 | { | |
6088 | p = restgpr1 (abfd, p, r); | |
6089 | bfd_put_32 (abfd, BLR, p); | |
6090 | return p + 4; | |
6091 | } | |
6092 | ||
6093 | static bfd_byte * | |
6094 | savefpr (bfd *abfd, bfd_byte *p, int r) | |
6095 | { | |
6096 | bfd_put_32 (abfd, STFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p); | |
6097 | return p + 4; | |
6098 | } | |
6099 | ||
6100 | static bfd_byte * | |
6101 | savefpr0_tail (bfd *abfd, bfd_byte *p, int r) | |
6102 | { | |
6103 | p = savefpr (abfd, p, r); | |
6104 | bfd_put_32 (abfd, STD_R0_0R1 + 16, p); | |
6105 | p = p + 4; | |
6106 | bfd_put_32 (abfd, BLR, p); | |
6107 | return p + 4; | |
6108 | } | |
6109 | ||
6110 | static bfd_byte * | |
6111 | restfpr (bfd *abfd, bfd_byte *p, int r) | |
6112 | { | |
6113 | bfd_put_32 (abfd, LFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p); | |
6114 | return p + 4; | |
6115 | } | |
6116 | ||
6117 | static bfd_byte * | |
6118 | restfpr0_tail (bfd *abfd, bfd_byte *p, int r) | |
6119 | { | |
6120 | bfd_put_32 (abfd, LD_R0_0R1 + 16, p); | |
6121 | p = p + 4; | |
6122 | p = restfpr (abfd, p, r); | |
6123 | bfd_put_32 (abfd, MTLR_R0, p); | |
6124 | p = p + 4; | |
6125 | if (r == 29) | |
6126 | { | |
6127 | p = restfpr (abfd, p, 30); | |
6128 | p = restfpr (abfd, p, 31); | |
6129 | } | |
6130 | bfd_put_32 (abfd, BLR, p); | |
6131 | return p + 4; | |
6132 | } | |
6133 | ||
6134 | static bfd_byte * | |
6135 | savefpr1_tail (bfd *abfd, bfd_byte *p, int r) | |
6136 | { | |
6137 | p = savefpr (abfd, p, r); | |
6138 | bfd_put_32 (abfd, BLR, p); | |
6139 | return p + 4; | |
6140 | } | |
6141 | ||
6142 | static bfd_byte * | |
6143 | restfpr1_tail (bfd *abfd, bfd_byte *p, int r) | |
6144 | { | |
6145 | p = restfpr (abfd, p, r); | |
6146 | bfd_put_32 (abfd, BLR, p); | |
6147 | return p + 4; | |
6148 | } | |
6149 | ||
6150 | static bfd_byte * | |
6151 | savevr (bfd *abfd, bfd_byte *p, int r) | |
6152 | { | |
6153 | bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p); | |
6154 | p = p + 4; | |
6155 | bfd_put_32 (abfd, STVX_VR0_R12_R0 + (r << 21), p); | |
6156 | return p + 4; | |
6157 | } | |
6158 | ||
6159 | static bfd_byte * | |
6160 | savevr_tail (bfd *abfd, bfd_byte *p, int r) | |
6161 | { | |
6162 | p = savevr (abfd, p, r); | |
6163 | bfd_put_32 (abfd, BLR, p); | |
6164 | return p + 4; | |
6165 | } | |
6166 | ||
6167 | static bfd_byte * | |
6168 | restvr (bfd *abfd, bfd_byte *p, int r) | |
6169 | { | |
6170 | bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p); | |
6171 | p = p + 4; | |
6172 | bfd_put_32 (abfd, LVX_VR0_R12_R0 + (r << 21), p); | |
6173 | return p + 4; | |
6174 | } | |
6175 | ||
6176 | static bfd_byte * | |
6177 | restvr_tail (bfd *abfd, bfd_byte *p, int r) | |
6178 | { | |
6179 | p = restvr (abfd, p, r); | |
6180 | bfd_put_32 (abfd, BLR, p); | |
6181 | return p + 4; | |
6182 | } | |
6183 | ||
e86ce104 AM |
6184 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
6185 | information on function code symbol entries to their corresponding | |
6186 | function descriptor symbol entries. */ | |
deb0e272 | 6187 | |
b34976b6 | 6188 | static bfd_boolean |
4ce794b7 | 6189 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 6190 | { |
e86ce104 | 6191 | struct bfd_link_info *info; |
65f38f15 | 6192 | struct ppc_link_hash_table *htab; |
411e1bfb | 6193 | struct plt_entry *ent; |
50bc7936 AM |
6194 | struct ppc_link_hash_entry *fh; |
6195 | struct ppc_link_hash_entry *fdh; | |
6196 | bfd_boolean force_local; | |
5bd4f169 | 6197 | |
50bc7936 AM |
6198 | fh = (struct ppc_link_hash_entry *) h; |
6199 | if (fh->elf.root.type == bfd_link_hash_indirect) | |
b34976b6 | 6200 | return TRUE; |
e86ce104 | 6201 | |
4ce794b7 | 6202 | info = inf; |
65f38f15 | 6203 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
6204 | if (htab == NULL) |
6205 | return FALSE; | |
5bd4f169 | 6206 | |
c09bdfe5 AM |
6207 | /* Resolve undefined references to dot-symbols as the value |
6208 | in the function descriptor, if we have one in a regular object. | |
6209 | This is to satisfy cases like ".quad .foo". Calls to functions | |
6210 | in dynamic objects are handled elsewhere. */ | |
6211 | if (fh->elf.root.type == bfd_link_hash_undefweak | |
6212 | && fh->was_undefined | |
b31867b6 AM |
6213 | && (fdh = defined_func_desc (fh)) != NULL |
6214 | && get_opd_info (fdh->elf.root.u.def.section) != NULL | |
6215 | && opd_entry_value (fdh->elf.root.u.def.section, | |
6216 | fdh->elf.root.u.def.value, | |
c09bdfe5 AM |
6217 | &fh->elf.root.u.def.section, |
6218 | &fh->elf.root.u.def.value) != (bfd_vma) -1) | |
6219 | { | |
b31867b6 | 6220 | fh->elf.root.type = fdh->elf.root.type; |
f5385ebf | 6221 | fh->elf.forced_local = 1; |
b31867b6 AM |
6222 | fh->elf.def_regular = fdh->elf.def_regular; |
6223 | fh->elf.def_dynamic = fdh->elf.def_dynamic; | |
c09bdfe5 AM |
6224 | } |
6225 | ||
e86ce104 AM |
6226 | /* If this is a function code symbol, transfer dynamic linking |
6227 | information to the function descriptor symbol. */ | |
50bc7936 | 6228 | if (!fh->is_func) |
b34976b6 | 6229 | return TRUE; |
e86ce104 | 6230 | |
50bc7936 | 6231 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
6232 | if (ent->plt.refcount > 0) |
6233 | break; | |
50bc7936 AM |
6234 | if (ent == NULL |
6235 | || fh->elf.root.root.string[0] != '.' | |
6236 | || fh->elf.root.root.string[1] == '\0') | |
6237 | return TRUE; | |
5bd4f169 | 6238 | |
50bc7936 AM |
6239 | /* Find the corresponding function descriptor symbol. Create it |
6240 | as undefined if necessary. */ | |
5bd4f169 | 6241 | |
b31867b6 | 6242 | fdh = lookup_fdh (fh, htab); |
50bc7936 | 6243 | if (fdh == NULL |
df131623 | 6244 | && !info->executable |
50bc7936 AM |
6245 | && (fh->elf.root.type == bfd_link_hash_undefined |
6246 | || fh->elf.root.type == bfd_link_hash_undefweak)) | |
6247 | { | |
908b32fc | 6248 | fdh = make_fdh (info, fh); |
bb700d78 AM |
6249 | if (fdh == NULL) |
6250 | return FALSE; | |
50bc7936 | 6251 | } |
648cca2c | 6252 | |
908b32fc | 6253 | /* Fake function descriptors are made undefweak. If the function |
433817dd AM |
6254 | code symbol is strong undefined, make the fake sym the same. |
6255 | If the function code symbol is defined, then force the fake | |
6256 | descriptor local; We can't support overriding of symbols in a | |
6257 | shared library on a fake descriptor. */ | |
908b32fc AM |
6258 | |
6259 | if (fdh != NULL | |
6260 | && fdh->fake | |
433817dd | 6261 | && fdh->elf.root.type == bfd_link_hash_undefweak) |
908b32fc | 6262 | { |
433817dd AM |
6263 | if (fh->elf.root.type == bfd_link_hash_undefined) |
6264 | { | |
6265 | fdh->elf.root.type = bfd_link_hash_undefined; | |
6266 | bfd_link_add_undef (&htab->elf.root, &fdh->elf.root); | |
6267 | } | |
6268 | else if (fh->elf.root.type == bfd_link_hash_defined | |
6269 | || fh->elf.root.type == bfd_link_hash_defweak) | |
6270 | { | |
6271 | _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE); | |
6272 | } | |
908b32fc AM |
6273 | } |
6274 | ||
50bc7936 | 6275 | if (fdh != NULL |
f5385ebf | 6276 | && !fdh->elf.forced_local |
df131623 | 6277 | && (!info->executable |
f5385ebf AM |
6278 | || fdh->elf.def_dynamic |
6279 | || fdh->elf.ref_dynamic | |
50bc7936 AM |
6280 | || (fdh->elf.root.type == bfd_link_hash_undefweak |
6281 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) | |
6282 | { | |
6283 | if (fdh->elf.dynindx == -1) | |
c152c796 | 6284 | if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf)) |
50bc7936 | 6285 | return FALSE; |
f5385ebf AM |
6286 | fdh->elf.ref_regular |= fh->elf.ref_regular; |
6287 | fdh->elf.ref_dynamic |= fh->elf.ref_dynamic; | |
6288 | fdh->elf.ref_regular_nonweak |= fh->elf.ref_regular_nonweak; | |
6289 | fdh->elf.non_got_ref |= fh->elf.non_got_ref; | |
50bc7936 | 6290 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) |
e86ce104 | 6291 | { |
40d16e0b | 6292 | move_plt_plist (fh, fdh); |
f5385ebf | 6293 | fdh->elf.needs_plt = 1; |
e86ce104 | 6294 | } |
50bc7936 | 6295 | fdh->is_func_descriptor = 1; |
34814b9f AM |
6296 | fdh->oh = fh; |
6297 | fh->oh = fdh; | |
e86ce104 AM |
6298 | } |
6299 | ||
50bc7936 AM |
6300 | /* Now that the info is on the function descriptor, clear the |
6301 | function code sym info. Any function code syms for which we | |
6302 | don't have a definition in a regular file, we force local. | |
6303 | This prevents a shared library from exporting syms that have | |
6304 | been imported from another library. Function code syms that | |
6305 | are really in the library we must leave global to prevent the | |
6306 | linker dragging in a definition from a static library. */ | |
93f3fa99 AM |
6307 | force_local = (!fh->elf.def_regular |
6308 | || fdh == NULL | |
6309 | || !fdh->elf.def_regular | |
6310 | || fdh->elf.forced_local); | |
50bc7936 AM |
6311 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); |
6312 | ||
b34976b6 | 6313 | return TRUE; |
e86ce104 | 6314 | } |
40b8271b | 6315 | |
e86ce104 | 6316 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
6317 | this hook to a) provide some gcc support functions, and b) transfer |
6318 | dynamic linking information gathered so far on function code symbol | |
6319 | entries, to their corresponding function descriptor symbol entries. */ | |
deb0e272 | 6320 | |
b34976b6 | 6321 | static bfd_boolean |
4ce794b7 AM |
6322 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
6323 | struct bfd_link_info *info) | |
e86ce104 AM |
6324 | { |
6325 | struct ppc_link_hash_table *htab; | |
82bd7b59 | 6326 | unsigned int i; |
deb0e272 AM |
6327 | const struct sfpr_def_parms funcs[] = |
6328 | { | |
6329 | { "_savegpr0_", 14, 31, savegpr0, savegpr0_tail }, | |
6330 | { "_restgpr0_", 14, 29, restgpr0, restgpr0_tail }, | |
6331 | { "_restgpr0_", 30, 31, restgpr0, restgpr0_tail }, | |
6332 | { "_savegpr1_", 14, 31, savegpr1, savegpr1_tail }, | |
6333 | { "_restgpr1_", 14, 31, restgpr1, restgpr1_tail }, | |
6334 | { "_savefpr_", 14, 31, savefpr, savefpr0_tail }, | |
6335 | { "_restfpr_", 14, 29, restfpr, restfpr0_tail }, | |
6336 | { "_restfpr_", 30, 31, restfpr, restfpr0_tail }, | |
6337 | { "._savef", 14, 31, savefpr, savefpr1_tail }, | |
6338 | { "._restf", 14, 31, restfpr, restfpr1_tail }, | |
6339 | { "_savevr_", 20, 31, savevr, savevr_tail }, | |
6340 | { "_restvr_", 20, 31, restvr, restvr_tail } | |
6341 | }; | |
e86ce104 AM |
6342 | |
6343 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
6344 | if (htab == NULL) |
6345 | return FALSE; | |
6346 | ||
82bd7b59 AM |
6347 | if (htab->sfpr == NULL) |
6348 | /* We don't have any relocs. */ | |
b34976b6 | 6349 | return TRUE; |
82bd7b59 | 6350 | |
deb0e272 AM |
6351 | /* Provide any missing _save* and _rest* functions. */ |
6352 | htab->sfpr->size = 0; | |
6353 | for (i = 0; i < sizeof (funcs) / sizeof (funcs[0]); i++) | |
6354 | if (!sfpr_define (info, &funcs[i])) | |
6355 | return FALSE; | |
82bd7b59 | 6356 | |
4ce794b7 | 6357 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
805fc799 | 6358 | |
eea6121a | 6359 | if (htab->sfpr->size == 0) |
8423293d | 6360 | htab->sfpr->flags |= SEC_EXCLUDE; |
82bd7b59 | 6361 | |
b34976b6 | 6362 | return TRUE; |
e86ce104 AM |
6363 | } |
6364 | ||
6365 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
6366 | regular object. The current definition is in some section of the | |
6367 | dynamic object, but we're not including those sections. We have to | |
6368 | change the definition to something the rest of the link can | |
6369 | understand. */ | |
6370 | ||
b34976b6 | 6371 | static bfd_boolean |
4ce794b7 AM |
6372 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
6373 | struct elf_link_hash_entry *h) | |
e86ce104 AM |
6374 | { |
6375 | struct ppc_link_hash_table *htab; | |
e86ce104 | 6376 | asection *s; |
e86ce104 AM |
6377 | |
6378 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
6379 | if (htab == NULL) |
6380 | return FALSE; | |
e86ce104 AM |
6381 | |
6382 | /* Deal with function syms. */ | |
6383 | if (h->type == STT_FUNC | |
e054468f | 6384 | || h->type == STT_GNU_IFUNC |
f5385ebf | 6385 | || h->needs_plt) |
e86ce104 AM |
6386 | { |
6387 | /* Clear procedure linkage table information for any symbol that | |
6388 | won't need a .plt entry. */ | |
411e1bfb AM |
6389 | struct plt_entry *ent; |
6390 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
6391 | if (ent->plt.refcount > 0) | |
6392 | break; | |
8387904d | 6393 | if (ent == NULL |
e054468f AM |
6394 | || (h->type != STT_GNU_IFUNC |
6395 | && (SYMBOL_CALLS_LOCAL (info, h) | |
6396 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
6397 | && h->root.type == bfd_link_hash_undefweak)))) | |
40b8271b | 6398 | { |
411e1bfb | 6399 | h->plt.plist = NULL; |
f5385ebf | 6400 | h->needs_plt = 0; |
40b8271b | 6401 | } |
5bd4f169 | 6402 | } |
bbd7ec4a | 6403 | else |
411e1bfb | 6404 | h->plt.plist = NULL; |
5bd4f169 AM |
6405 | |
6406 | /* If this is a weak symbol, and there is a real definition, the | |
6407 | processor independent code will have arranged for us to see the | |
6408 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 6409 | if (h->u.weakdef != NULL) |
5bd4f169 | 6410 | { |
f6e332e6 AM |
6411 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
6412 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
6413 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
6414 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
a23b6845 | 6415 | if (ELIMINATE_COPY_RELOCS) |
f6e332e6 | 6416 | h->non_got_ref = h->u.weakdef->non_got_ref; |
b34976b6 | 6417 | return TRUE; |
5bd4f169 AM |
6418 | } |
6419 | ||
5bd4f169 AM |
6420 | /* If we are creating a shared library, we must presume that the |
6421 | only references to the symbol are via the global offset table. | |
6422 | For such cases we need not do anything here; the relocations will | |
6423 | be handled correctly by relocate_section. */ | |
6424 | if (info->shared) | |
b34976b6 | 6425 | return TRUE; |
5bd4f169 | 6426 | |
65f38f15 AM |
6427 | /* If there are no references to this symbol that do not use the |
6428 | GOT, we don't need to generate a copy reloc. */ | |
f5385ebf | 6429 | if (!h->non_got_ref) |
b34976b6 | 6430 | return TRUE; |
65f38f15 | 6431 | |
b186458a JJ |
6432 | /* Don't generate a copy reloc for symbols defined in the executable. */ |
6433 | if (!h->def_dynamic || !h->ref_regular || h->def_regular) | |
6434 | return TRUE; | |
6435 | ||
f4656909 | 6436 | if (ELIMINATE_COPY_RELOCS) |
65f38f15 | 6437 | { |
f4656909 | 6438 | struct ppc_link_hash_entry * eh; |
6061a67d | 6439 | struct elf_dyn_relocs *p; |
65f38f15 | 6440 | |
f4656909 AM |
6441 | eh = (struct ppc_link_hash_entry *) h; |
6442 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
6443 | { | |
6444 | s = p->sec->output_section; | |
6445 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
6446 | break; | |
6447 | } | |
6448 | ||
6449 | /* If we didn't find any dynamic relocs in read-only sections, then | |
6450 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
6451 | if (p == NULL) | |
6452 | { | |
f5385ebf | 6453 | h->non_got_ref = 0; |
f4656909 AM |
6454 | return TRUE; |
6455 | } | |
65f38f15 AM |
6456 | } |
6457 | ||
5d35169e | 6458 | if (h->plt.plist != NULL) |
97b639ba AM |
6459 | { |
6460 | /* We should never get here, but unfortunately there are versions | |
6461 | of gcc out there that improperly (for this ABI) put initialized | |
6462 | function pointers, vtable refs and suchlike in read-only | |
6463 | sections. Allow them to proceed, but warn that this might | |
6464 | break at runtime. */ | |
25f53a85 | 6465 | info->callbacks->einfo |
97b639ba | 6466 | (_("copy reloc against `%s' requires lazy plt linking; " |
25f53a85 | 6467 | "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"), |
97b639ba AM |
6468 | h->root.root.string); |
6469 | } | |
5d35169e AM |
6470 | |
6471 | /* This is a reference to a symbol defined by a dynamic object which | |
6472 | is not a function. */ | |
6473 | ||
909272ee AM |
6474 | if (h->size == 0) |
6475 | { | |
25f53a85 AM |
6476 | info->callbacks->einfo (_("dynamic variable `%s' is zero size\n"), |
6477 | h->root.root.string); | |
909272ee AM |
6478 | return TRUE; |
6479 | } | |
6480 | ||
5bd4f169 AM |
6481 | /* We must allocate the symbol in our .dynbss section, which will |
6482 | become part of the .bss section of the executable. There will be | |
6483 | an entry for this symbol in the .dynsym section. The dynamic | |
6484 | object will contain position independent code, so all references | |
6485 | from the dynamic object to this symbol will go through the global | |
6486 | offset table. The dynamic linker will use the .dynsym entry to | |
6487 | determine the address it must put in the global offset table, so | |
6488 | both the dynamic object and the regular object will refer to the | |
6489 | same memory location for the variable. */ | |
5bd4f169 | 6490 | |
04c9666a AM |
6491 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
6492 | to copy the initial value out of the dynamic object and into the | |
5bd4f169 AM |
6493 | runtime process image. We need to remember the offset into the |
6494 | .rela.bss section we are going to use. */ | |
6495 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
6496 | { | |
eea6121a | 6497 | htab->relbss->size += sizeof (Elf64_External_Rela); |
f5385ebf | 6498 | h->needs_copy = 1; |
5bd4f169 AM |
6499 | } |
6500 | ||
4ce794b7 | 6501 | s = htab->dynbss; |
5bd4f169 | 6502 | |
027297b7 | 6503 | return _bfd_elf_adjust_dynamic_copy (h, s); |
5bd4f169 AM |
6504 | } |
6505 | ||
e86ce104 AM |
6506 | /* If given a function descriptor symbol, hide both the function code |
6507 | sym and the descriptor. */ | |
6508 | static void | |
4ce794b7 AM |
6509 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
6510 | struct elf_link_hash_entry *h, | |
6511 | bfd_boolean force_local) | |
e86ce104 | 6512 | { |
34814b9f | 6513 | struct ppc_link_hash_entry *eh; |
e86ce104 AM |
6514 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
6515 | ||
34814b9f AM |
6516 | eh = (struct ppc_link_hash_entry *) h; |
6517 | if (eh->is_func_descriptor) | |
e86ce104 | 6518 | { |
34814b9f | 6519 | struct ppc_link_hash_entry *fh = eh->oh; |
e86ce104 | 6520 | |
721956f4 | 6521 | if (fh == NULL) |
d1329ca3 AM |
6522 | { |
6523 | const char *p, *q; | |
6524 | struct ppc_link_hash_table *htab; | |
6525 | char save; | |
6526 | ||
6527 | /* We aren't supposed to use alloca in BFD because on | |
6528 | systems which do not have alloca the version in libiberty | |
6529 | calls xmalloc, which might cause the program to crash | |
6530 | when it runs out of memory. This function doesn't have a | |
6531 | return status, so there's no way to gracefully return an | |
6532 | error. So cheat. We know that string[-1] can be safely | |
34814b9f AM |
6533 | accessed; It's either a string in an ELF string table, |
6534 | or allocated in an objalloc structure. */ | |
d1329ca3 | 6535 | |
34814b9f | 6536 | p = eh->elf.root.root.string - 1; |
d1329ca3 AM |
6537 | save = *p; |
6538 | *(char *) p = '.'; | |
6539 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
6540 | if (htab == NULL) |
6541 | return; | |
6542 | ||
34814b9f AM |
6543 | fh = (struct ppc_link_hash_entry *) |
6544 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
6545 | *(char *) p = save; |
6546 | ||
6547 | /* Unfortunately, if it so happens that the string we were | |
6548 | looking for was allocated immediately before this string, | |
6549 | then we overwrote the string terminator. That's the only | |
6550 | reason the lookup should fail. */ | |
6551 | if (fh == NULL) | |
6552 | { | |
34814b9f AM |
6553 | q = eh->elf.root.root.string + strlen (eh->elf.root.root.string); |
6554 | while (q >= eh->elf.root.root.string && *q == *p) | |
d1329ca3 | 6555 | --q, --p; |
34814b9f AM |
6556 | if (q < eh->elf.root.root.string && *p == '.') |
6557 | fh = (struct ppc_link_hash_entry *) | |
6558 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
6559 | } |
6560 | if (fh != NULL) | |
6561 | { | |
34814b9f AM |
6562 | eh->oh = fh; |
6563 | fh->oh = eh; | |
d1329ca3 AM |
6564 | } |
6565 | } | |
e86ce104 | 6566 | if (fh != NULL) |
34814b9f | 6567 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); |
e86ce104 AM |
6568 | } |
6569 | } | |
6570 | ||
411e1bfb | 6571 | static bfd_boolean |
8843416a AM |
6572 | get_sym_h (struct elf_link_hash_entry **hp, |
6573 | Elf_Internal_Sym **symp, | |
6574 | asection **symsecp, | |
f961d9dd | 6575 | unsigned char **tls_maskp, |
8843416a AM |
6576 | Elf_Internal_Sym **locsymsp, |
6577 | unsigned long r_symndx, | |
6578 | bfd *ibfd) | |
411e1bfb | 6579 | { |
0ffa91dd | 6580 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); |
411e1bfb AM |
6581 | |
6582 | if (r_symndx >= symtab_hdr->sh_info) | |
6583 | { | |
6584 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
6585 | struct elf_link_hash_entry *h; | |
6586 | ||
6587 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
b31867b6 | 6588 | h = elf_follow_link (h); |
411e1bfb AM |
6589 | |
6590 | if (hp != NULL) | |
6591 | *hp = h; | |
6592 | ||
6593 | if (symp != NULL) | |
6594 | *symp = NULL; | |
6595 | ||
6596 | if (symsecp != NULL) | |
6597 | { | |
6598 | asection *symsec = NULL; | |
6599 | if (h->root.type == bfd_link_hash_defined | |
6600 | || h->root.type == bfd_link_hash_defweak) | |
6601 | symsec = h->root.u.def.section; | |
6602 | *symsecp = symsec; | |
6603 | } | |
6604 | ||
e7b938ca | 6605 | if (tls_maskp != NULL) |
411e1bfb AM |
6606 | { |
6607 | struct ppc_link_hash_entry *eh; | |
6608 | ||
6609 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 6610 | *tls_maskp = &eh->tls_mask; |
411e1bfb AM |
6611 | } |
6612 | } | |
6613 | else | |
6614 | { | |
6615 | Elf_Internal_Sym *sym; | |
6616 | Elf_Internal_Sym *locsyms = *locsymsp; | |
6617 | ||
6618 | if (locsyms == NULL) | |
6619 | { | |
6620 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
6621 | if (locsyms == NULL) | |
6622 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
6623 | symtab_hdr->sh_info, | |
6624 | 0, NULL, NULL, NULL); | |
6625 | if (locsyms == NULL) | |
6626 | return FALSE; | |
6627 | *locsymsp = locsyms; | |
6628 | } | |
6629 | sym = locsyms + r_symndx; | |
6630 | ||
6631 | if (hp != NULL) | |
6632 | *hp = NULL; | |
6633 | ||
6634 | if (symp != NULL) | |
6635 | *symp = sym; | |
6636 | ||
6637 | if (symsecp != NULL) | |
cb33740c | 6638 | *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx); |
411e1bfb | 6639 | |
e7b938ca | 6640 | if (tls_maskp != NULL) |
411e1bfb AM |
6641 | { |
6642 | struct got_entry **lgot_ents; | |
f961d9dd | 6643 | unsigned char *tls_mask; |
411e1bfb | 6644 | |
e7b938ca | 6645 | tls_mask = NULL; |
411e1bfb AM |
6646 | lgot_ents = elf_local_got_ents (ibfd); |
6647 | if (lgot_ents != NULL) | |
6648 | { | |
e054468f AM |
6649 | struct plt_entry **local_plt = (struct plt_entry **) |
6650 | (lgot_ents + symtab_hdr->sh_info); | |
f961d9dd | 6651 | unsigned char *lgot_masks = (unsigned char *) |
e054468f | 6652 | (local_plt + symtab_hdr->sh_info); |
e7b938ca | 6653 | tls_mask = &lgot_masks[r_symndx]; |
411e1bfb | 6654 | } |
e7b938ca | 6655 | *tls_maskp = tls_mask; |
411e1bfb AM |
6656 | } |
6657 | } | |
6658 | return TRUE; | |
6659 | } | |
6660 | ||
e7b938ca | 6661 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
951fd09b | 6662 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
ad8e1ba5 | 6663 | type suitable for optimization, and 1 otherwise. */ |
951fd09b AM |
6664 | |
6665 | static int | |
f961d9dd | 6666 | get_tls_mask (unsigned char **tls_maskp, |
3a71aa26 AM |
6667 | unsigned long *toc_symndx, |
6668 | bfd_vma *toc_addend, | |
0d4792f7 | 6669 | Elf_Internal_Sym **locsymsp, |
3a71aa26 AM |
6670 | const Elf_Internal_Rela *rel, |
6671 | bfd *ibfd) | |
411e1bfb AM |
6672 | { |
6673 | unsigned long r_symndx; | |
0d4792f7 | 6674 | int next_r; |
411e1bfb AM |
6675 | struct elf_link_hash_entry *h; |
6676 | Elf_Internal_Sym *sym; | |
6677 | asection *sec; | |
6678 | bfd_vma off; | |
6679 | ||
6680 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 6681 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 6682 | return 0; |
411e1bfb | 6683 | |
e7b938ca | 6684 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
411e1bfb | 6685 | || sec == NULL |
6bee8834 | 6686 | || ppc64_elf_section_data (sec) == NULL |
7c8fe5c4 | 6687 | || ppc64_elf_section_data (sec)->sec_type != sec_toc) |
951fd09b | 6688 | return 1; |
411e1bfb AM |
6689 | |
6690 | /* Look inside a TOC section too. */ | |
6691 | if (h != NULL) | |
6692 | { | |
6693 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
6694 | off = h->root.u.def.value; | |
6695 | } | |
6696 | else | |
6697 | off = sym->st_value; | |
6698 | off += rel->r_addend; | |
6699 | BFD_ASSERT (off % 8 == 0); | |
3a71aa26 AM |
6700 | r_symndx = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8]; |
6701 | next_r = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8 + 1]; | |
0d4792f7 AM |
6702 | if (toc_symndx != NULL) |
6703 | *toc_symndx = r_symndx; | |
3a71aa26 AM |
6704 | if (toc_addend != NULL) |
6705 | *toc_addend = ppc64_elf_section_data (sec)->u.toc.add[off / 8]; | |
6706 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) | |
6707 | return 0; | |
854b41e7 | 6708 | if ((h == NULL || is_static_defined (h)) |
0d4792f7 AM |
6709 | && (next_r == -1 || next_r == -2)) |
6710 | return 1 - next_r; | |
951fd09b | 6711 | return 1; |
411e1bfb AM |
6712 | } |
6713 | ||
754021d0 | 6714 | /* Adjust all global syms defined in opd sections. In gcc generated |
8387904d | 6715 | code for the old ABI, these will already have been done. */ |
754021d0 AM |
6716 | |
6717 | static bfd_boolean | |
6718 | adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
6719 | { | |
6720 | struct ppc_link_hash_entry *eh; | |
6721 | asection *sym_sec; | |
74f0fb50 | 6722 | struct _opd_sec_data *opd; |
754021d0 AM |
6723 | |
6724 | if (h->root.type == bfd_link_hash_indirect) | |
6725 | return TRUE; | |
6726 | ||
754021d0 AM |
6727 | if (h->root.type != bfd_link_hash_defined |
6728 | && h->root.type != bfd_link_hash_defweak) | |
6729 | return TRUE; | |
6730 | ||
6731 | eh = (struct ppc_link_hash_entry *) h; | |
6732 | if (eh->adjust_done) | |
6733 | return TRUE; | |
6734 | ||
6735 | sym_sec = eh->elf.root.u.def.section; | |
74f0fb50 AM |
6736 | opd = get_opd_info (sym_sec); |
6737 | if (opd != NULL && opd->adjust != NULL) | |
754021d0 | 6738 | { |
74f0fb50 | 6739 | long adjust = opd->adjust[eh->elf.root.u.def.value / 8]; |
4025353c AM |
6740 | if (adjust == -1) |
6741 | { | |
6742 | /* This entry has been deleted. */ | |
b3fac117 | 6743 | asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section; |
81688140 AM |
6744 | if (dsec == NULL) |
6745 | { | |
6746 | for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next) | |
6747 | if (elf_discarded_section (dsec)) | |
6748 | { | |
b3fac117 | 6749 | ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec; |
81688140 AM |
6750 | break; |
6751 | } | |
6752 | } | |
4025353c | 6753 | eh->elf.root.u.def.value = 0; |
81688140 | 6754 | eh->elf.root.u.def.section = dsec; |
4025353c AM |
6755 | } |
6756 | else | |
6757 | eh->elf.root.u.def.value += adjust; | |
754021d0 AM |
6758 | eh->adjust_done = 1; |
6759 | } | |
6760 | return TRUE; | |
6761 | } | |
6762 | ||
8c1d1bb8 AM |
6763 | /* Handles decrementing dynamic reloc counts for the reloc specified by |
6764 | R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC | |
6765 | have already been determined. */ | |
6766 | ||
6767 | static bfd_boolean | |
6768 | dec_dynrel_count (bfd_vma r_info, | |
6769 | asection *sec, | |
6770 | struct bfd_link_info *info, | |
6771 | Elf_Internal_Sym **local_syms, | |
6772 | struct elf_link_hash_entry *h, | |
6773 | asection *sym_sec) | |
6774 | { | |
6775 | enum elf_ppc64_reloc_type r_type; | |
6061a67d AM |
6776 | struct elf_dyn_relocs *p; |
6777 | struct elf_dyn_relocs **pp; | |
8c1d1bb8 AM |
6778 | |
6779 | /* Can this reloc be dynamic? This switch, and later tests here | |
6780 | should be kept in sync with the code in check_relocs. */ | |
6781 | r_type = ELF64_R_TYPE (r_info); | |
6782 | switch (r_type) | |
6783 | { | |
6784 | default: | |
6785 | return TRUE; | |
6786 | ||
6787 | case R_PPC64_TPREL16: | |
6788 | case R_PPC64_TPREL16_LO: | |
6789 | case R_PPC64_TPREL16_HI: | |
6790 | case R_PPC64_TPREL16_HA: | |
6791 | case R_PPC64_TPREL16_DS: | |
6792 | case R_PPC64_TPREL16_LO_DS: | |
6793 | case R_PPC64_TPREL16_HIGHER: | |
6794 | case R_PPC64_TPREL16_HIGHERA: | |
6795 | case R_PPC64_TPREL16_HIGHEST: | |
6796 | case R_PPC64_TPREL16_HIGHESTA: | |
6797 | if (!info->shared) | |
6798 | return TRUE; | |
6799 | ||
6800 | case R_PPC64_TPREL64: | |
6801 | case R_PPC64_DTPMOD64: | |
6802 | case R_PPC64_DTPREL64: | |
6803 | case R_PPC64_ADDR64: | |
6804 | case R_PPC64_REL30: | |
6805 | case R_PPC64_REL32: | |
6806 | case R_PPC64_REL64: | |
6807 | case R_PPC64_ADDR14: | |
6808 | case R_PPC64_ADDR14_BRNTAKEN: | |
6809 | case R_PPC64_ADDR14_BRTAKEN: | |
6810 | case R_PPC64_ADDR16: | |
6811 | case R_PPC64_ADDR16_DS: | |
6812 | case R_PPC64_ADDR16_HA: | |
6813 | case R_PPC64_ADDR16_HI: | |
6814 | case R_PPC64_ADDR16_HIGHER: | |
6815 | case R_PPC64_ADDR16_HIGHERA: | |
6816 | case R_PPC64_ADDR16_HIGHEST: | |
6817 | case R_PPC64_ADDR16_HIGHESTA: | |
6818 | case R_PPC64_ADDR16_LO: | |
6819 | case R_PPC64_ADDR16_LO_DS: | |
6820 | case R_PPC64_ADDR24: | |
6821 | case R_PPC64_ADDR32: | |
6822 | case R_PPC64_UADDR16: | |
6823 | case R_PPC64_UADDR32: | |
6824 | case R_PPC64_UADDR64: | |
6825 | case R_PPC64_TOC: | |
6826 | break; | |
6827 | } | |
6828 | ||
6829 | if (local_syms != NULL) | |
6830 | { | |
6831 | unsigned long r_symndx; | |
6832 | Elf_Internal_Sym *sym; | |
6833 | bfd *ibfd = sec->owner; | |
6834 | ||
6835 | r_symndx = ELF64_R_SYM (r_info); | |
6836 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd)) | |
6837 | return FALSE; | |
6838 | } | |
6839 | ||
6840 | if ((info->shared | |
1d483afe | 6841 | && (must_be_dyn_reloc (info, r_type) |
8c1d1bb8 AM |
6842 | || (h != NULL |
6843 | && (!info->symbolic | |
6844 | || h->root.type == bfd_link_hash_defweak | |
6845 | || !h->def_regular)))) | |
6846 | || (ELIMINATE_COPY_RELOCS | |
6847 | && !info->shared | |
6848 | && h != NULL | |
6849 | && (h->root.type == bfd_link_hash_defweak | |
6850 | || !h->def_regular))) | |
6851 | ; | |
6852 | else | |
6853 | return TRUE; | |
6854 | ||
6855 | if (h != NULL) | |
6856 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; | |
8c1d1bb8 | 6857 | else |
6edfbbad | 6858 | { |
60124e18 AM |
6859 | if (sym_sec != NULL) |
6860 | { | |
6861 | void *vpp = &elf_section_data (sym_sec)->local_dynrel; | |
6061a67d | 6862 | pp = (struct elf_dyn_relocs **) vpp; |
60124e18 AM |
6863 | } |
6864 | else | |
6865 | { | |
6866 | void *vpp = &elf_section_data (sec)->local_dynrel; | |
6061a67d | 6867 | pp = (struct elf_dyn_relocs **) vpp; |
60124e18 AM |
6868 | } |
6869 | ||
6870 | /* elf_gc_sweep may have already removed all dyn relocs associated | |
6871 | with local syms for a given section. Don't report a dynreloc | |
6872 | miscount. */ | |
6873 | if (*pp == NULL) | |
6874 | return TRUE; | |
6edfbbad | 6875 | } |
8c1d1bb8 AM |
6876 | |
6877 | while ((p = *pp) != NULL) | |
6878 | { | |
6879 | if (p->sec == sec) | |
6880 | { | |
1d483afe | 6881 | if (!must_be_dyn_reloc (info, r_type)) |
8c1d1bb8 AM |
6882 | p->pc_count -= 1; |
6883 | p->count -= 1; | |
6884 | if (p->count == 0) | |
6885 | *pp = p->next; | |
6886 | return TRUE; | |
6887 | } | |
6888 | pp = &p->next; | |
6889 | } | |
6890 | ||
25f53a85 AM |
6891 | info->callbacks->einfo (_("dynreloc miscount for %B, section %A\n"), |
6892 | sec->owner, sec); | |
8c1d1bb8 AM |
6893 | bfd_set_error (bfd_error_bad_value); |
6894 | return FALSE; | |
6895 | } | |
6896 | ||
754021d0 AM |
6897 | /* Remove unused Official Procedure Descriptor entries. Currently we |
6898 | only remove those associated with functions in discarded link-once | |
6899 | sections, or weakly defined functions that have been overridden. It | |
6900 | would be possible to remove many more entries for statically linked | |
6901 | applications. */ | |
6902 | ||
b34976b6 | 6903 | bfd_boolean |
33c0ec9d | 6904 | ppc64_elf_edit_opd (struct bfd_link_info *info, bfd_boolean non_overlapping) |
1e2f5b6e AM |
6905 | { |
6906 | bfd *ibfd; | |
754021d0 | 6907 | bfd_boolean some_edited = FALSE; |
3f764659 | 6908 | asection *need_pad = NULL; |
1e2f5b6e | 6909 | |
411e1bfb | 6910 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1e2f5b6e AM |
6911 | { |
6912 | asection *sec; | |
6913 | Elf_Internal_Rela *relstart, *rel, *relend; | |
6914 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 6915 | Elf_Internal_Sym *local_syms; |
1e2f5b6e | 6916 | bfd_vma offset; |
74f0fb50 | 6917 | struct _opd_sec_data *opd; |
3f764659 JJ |
6918 | bfd_boolean need_edit, add_aux_fields; |
6919 | bfd_size_type cnt_16b = 0; | |
1e2f5b6e | 6920 | |
854b41e7 AM |
6921 | if (!is_ppc64_elf (ibfd)) |
6922 | continue; | |
6923 | ||
1e2f5b6e | 6924 | sec = bfd_get_section_by_name (ibfd, ".opd"); |
46de2a7c | 6925 | if (sec == NULL || sec->size == 0) |
1e2f5b6e AM |
6926 | continue; |
6927 | ||
4b85d634 AM |
6928 | if (sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS) |
6929 | continue; | |
6930 | ||
1e2f5b6e AM |
6931 | if (sec->output_section == bfd_abs_section_ptr) |
6932 | continue; | |
6933 | ||
6934 | /* Look through the section relocs. */ | |
6935 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
6936 | continue; | |
6937 | ||
6cdc0ccc | 6938 | local_syms = NULL; |
0ffa91dd | 6939 | symtab_hdr = &elf_symtab_hdr (ibfd); |
1e2f5b6e AM |
6940 | |
6941 | /* Read the relocations. */ | |
4ce794b7 | 6942 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 6943 | info->keep_memory); |
1e2f5b6e | 6944 | if (relstart == NULL) |
b34976b6 | 6945 | return FALSE; |
1e2f5b6e AM |
6946 | |
6947 | /* First run through the relocs to check they are sane, and to | |
6948 | determine whether we need to edit this opd section. */ | |
b34976b6 | 6949 | need_edit = FALSE; |
3f764659 | 6950 | need_pad = sec; |
1e2f5b6e AM |
6951 | offset = 0; |
6952 | relend = relstart + sec->reloc_count; | |
50bc7936 | 6953 | for (rel = relstart; rel < relend; ) |
1e2f5b6e | 6954 | { |
04c9666a | 6955 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e AM |
6956 | unsigned long r_symndx; |
6957 | asection *sym_sec; | |
6958 | struct elf_link_hash_entry *h; | |
6959 | Elf_Internal_Sym *sym; | |
6960 | ||
3f764659 | 6961 | /* .opd contains a regular array of 16 or 24 byte entries. We're |
1e2f5b6e AM |
6962 | only interested in the reloc pointing to a function entry |
6963 | point. */ | |
50bc7936 AM |
6964 | if (rel->r_offset != offset |
6965 | || rel + 1 >= relend | |
6966 | || (rel + 1)->r_offset != offset + 8) | |
1e2f5b6e AM |
6967 | { |
6968 | /* If someone messes with .opd alignment then after a | |
6969 | "ld -r" we might have padding in the middle of .opd. | |
6970 | Also, there's nothing to prevent someone putting | |
6971 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 6972 | optimization for them! */ |
3f764659 | 6973 | broken_opd: |
1e2f5b6e | 6974 | (*_bfd_error_handler) |
d003868e | 6975 | (_("%B: .opd is not a regular array of opd entries"), ibfd); |
b34976b6 | 6976 | need_edit = FALSE; |
1e2f5b6e AM |
6977 | break; |
6978 | } | |
6979 | ||
50bc7936 AM |
6980 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
6981 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) | |
6982 | { | |
6983 | (*_bfd_error_handler) | |
d003868e AM |
6984 | (_("%B: unexpected reloc type %u in .opd section"), |
6985 | ibfd, r_type); | |
50bc7936 AM |
6986 | need_edit = FALSE; |
6987 | break; | |
6988 | } | |
6989 | ||
1e2f5b6e | 6990 | r_symndx = ELF64_R_SYM (rel->r_info); |
411e1bfb AM |
6991 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
6992 | r_symndx, ibfd)) | |
50bc7936 | 6993 | goto error_ret; |
1e2f5b6e AM |
6994 | |
6995 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
6996 | { | |
411e1bfb AM |
6997 | const char *sym_name; |
6998 | if (h != NULL) | |
6999 | sym_name = h->root.root.string; | |
7000 | else | |
26c61ae5 L |
7001 | sym_name = bfd_elf_sym_name (ibfd, symtab_hdr, sym, |
7002 | sym_sec); | |
411e1bfb | 7003 | |
1e2f5b6e | 7004 | (*_bfd_error_handler) |
d003868e AM |
7005 | (_("%B: undefined sym `%s' in .opd section"), |
7006 | ibfd, sym_name); | |
b34976b6 | 7007 | need_edit = FALSE; |
1e2f5b6e AM |
7008 | break; |
7009 | } | |
7010 | ||
51020317 AM |
7011 | /* opd entries are always for functions defined in the |
7012 | current input bfd. If the symbol isn't defined in the | |
7013 | input bfd, then we won't be using the function in this | |
7014 | bfd; It must be defined in a linkonce section in another | |
7015 | bfd, or is weak. It's also possible that we are | |
7016 | discarding the function due to a linker script /DISCARD/, | |
7017 | which we test for via the output_section. */ | |
7018 | if (sym_sec->owner != ibfd | |
7019 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 7020 | need_edit = TRUE; |
1e2f5b6e | 7021 | |
50bc7936 | 7022 | rel += 2; |
3f764659 JJ |
7023 | if (rel == relend |
7024 | || (rel + 1 == relend && rel->r_offset == offset + 16)) | |
7025 | { | |
7026 | if (sec->size == offset + 24) | |
7027 | { | |
7028 | need_pad = NULL; | |
7029 | break; | |
7030 | } | |
7031 | if (rel == relend && sec->size == offset + 16) | |
7032 | { | |
7033 | cnt_16b++; | |
7034 | break; | |
7035 | } | |
7036 | goto broken_opd; | |
7037 | } | |
7038 | ||
7039 | if (rel->r_offset == offset + 24) | |
7040 | offset += 24; | |
7041 | else if (rel->r_offset != offset + 16) | |
7042 | goto broken_opd; | |
7043 | else if (rel + 1 < relend | |
7044 | && ELF64_R_TYPE (rel[0].r_info) == R_PPC64_ADDR64 | |
7045 | && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOC) | |
7046 | { | |
7047 | offset += 16; | |
7048 | cnt_16b++; | |
7049 | } | |
7050 | else if (rel + 2 < relend | |
7051 | && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_ADDR64 | |
7052 | && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_TOC) | |
7053 | { | |
7054 | offset += 24; | |
7055 | rel += 1; | |
7056 | } | |
7057 | else | |
7058 | goto broken_opd; | |
1e2f5b6e AM |
7059 | } |
7060 | ||
3f764659 JJ |
7061 | add_aux_fields = non_overlapping && cnt_16b > 0; |
7062 | ||
7063 | if (need_edit || add_aux_fields) | |
1e2f5b6e AM |
7064 | { |
7065 | Elf_Internal_Rela *write_rel; | |
d4730f92 | 7066 | Elf_Internal_Shdr *rel_hdr; |
1e2f5b6e | 7067 | bfd_byte *rptr, *wptr; |
983bddc8 | 7068 | bfd_byte *new_contents; |
b34976b6 | 7069 | bfd_boolean skip; |
3f764659 | 7070 | long opd_ent_size; |
74f0fb50 AM |
7071 | bfd_size_type amt; |
7072 | ||
983bddc8 | 7073 | new_contents = NULL; |
74f0fb50 AM |
7074 | amt = sec->size * sizeof (long) / 8; |
7075 | opd = &ppc64_elf_section_data (sec)->u.opd; | |
33c0ec9d | 7076 | opd->adjust = bfd_zalloc (sec->owner, amt); |
74f0fb50 AM |
7077 | if (opd->adjust == NULL) |
7078 | return FALSE; | |
7079 | ppc64_elf_section_data (sec)->sec_type = sec_opd; | |
1e2f5b6e AM |
7080 | |
7081 | /* This seems a waste of time as input .opd sections are all | |
7082 | zeros as generated by gcc, but I suppose there's no reason | |
7083 | this will always be so. We might start putting something in | |
7084 | the third word of .opd entries. */ | |
7085 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
7086 | { | |
eea6121a AM |
7087 | bfd_byte *loc; |
7088 | if (!bfd_malloc_and_get_section (ibfd, sec, &loc)) | |
6cdc0ccc | 7089 | { |
eea6121a AM |
7090 | if (loc != NULL) |
7091 | free (loc); | |
50bc7936 | 7092 | error_ret: |
6cdc0ccc AM |
7093 | if (local_syms != NULL |
7094 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
7095 | free (local_syms); | |
6cdc0ccc AM |
7096 | if (elf_section_data (sec)->relocs != relstart) |
7097 | free (relstart); | |
b34976b6 | 7098 | return FALSE; |
6cdc0ccc | 7099 | } |
1e2f5b6e AM |
7100 | sec->contents = loc; |
7101 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
7102 | } | |
7103 | ||
7104 | elf_section_data (sec)->relocs = relstart; | |
7105 | ||
3f764659 | 7106 | new_contents = sec->contents; |
3f764659 JJ |
7107 | if (add_aux_fields) |
7108 | { | |
7109 | new_contents = bfd_malloc (sec->size + cnt_16b * 8); | |
7110 | if (new_contents == NULL) | |
7111 | return FALSE; | |
7112 | need_pad = FALSE; | |
3f764659 | 7113 | } |
b4f4e59f AM |
7114 | wptr = new_contents; |
7115 | rptr = sec->contents; | |
3f764659 | 7116 | |
1e2f5b6e | 7117 | write_rel = relstart; |
b34976b6 | 7118 | skip = FALSE; |
1e2f5b6e | 7119 | offset = 0; |
3f764659 | 7120 | opd_ent_size = 0; |
1e2f5b6e AM |
7121 | for (rel = relstart; rel < relend; rel++) |
7122 | { | |
50bc7936 AM |
7123 | unsigned long r_symndx; |
7124 | asection *sym_sec; | |
7125 | struct elf_link_hash_entry *h; | |
7126 | Elf_Internal_Sym *sym; | |
7127 | ||
7128 | r_symndx = ELF64_R_SYM (rel->r_info); | |
7129 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
d37c89e5 | 7130 | r_symndx, ibfd)) |
50bc7936 AM |
7131 | goto error_ret; |
7132 | ||
1e2f5b6e AM |
7133 | if (rel->r_offset == offset) |
7134 | { | |
50bc7936 | 7135 | struct ppc_link_hash_entry *fdh = NULL; |
3f764659 JJ |
7136 | |
7137 | /* See if the .opd entry is full 24 byte or | |
7138 | 16 byte (with fd_aux entry overlapped with next | |
7139 | fd_func). */ | |
7140 | opd_ent_size = 24; | |
7141 | if ((rel + 2 == relend && sec->size == offset + 16) | |
7142 | || (rel + 3 < relend | |
7143 | && rel[2].r_offset == offset + 16 | |
7144 | && rel[3].r_offset == offset + 24 | |
7145 | && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_ADDR64 | |
7146 | && ELF64_R_TYPE (rel[3].r_info) == R_PPC64_TOC)) | |
7147 | opd_ent_size = 16; | |
7148 | ||
4025353c AM |
7149 | if (h != NULL |
7150 | && h->root.root.string[0] == '.') | |
c4f68ce3 | 7151 | { |
4dfe6ac6 NC |
7152 | struct ppc_link_hash_table *htab; |
7153 | ||
7154 | htab = ppc_hash_table (info); | |
7155 | if (htab != NULL) | |
7156 | fdh = lookup_fdh ((struct ppc_link_hash_entry *) h, | |
7157 | htab); | |
c4f68ce3 AM |
7158 | if (fdh != NULL |
7159 | && fdh->elf.root.type != bfd_link_hash_defined | |
7160 | && fdh->elf.root.type != bfd_link_hash_defweak) | |
7161 | fdh = NULL; | |
7162 | } | |
1e2f5b6e | 7163 | |
51020317 AM |
7164 | skip = (sym_sec->owner != ibfd |
7165 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
7166 | if (skip) |
7167 | { | |
4025353c | 7168 | if (fdh != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
7169 | { |
7170 | /* Arrange for the function descriptor sym | |
7171 | to be dropped. */ | |
d6fe2dc1 AM |
7172 | fdh->elf.root.u.def.value = 0; |
7173 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 | 7174 | } |
74f0fb50 | 7175 | opd->adjust[rel->r_offset / 8] = -1; |
a4aa0fb7 AM |
7176 | } |
7177 | else | |
1e2f5b6e AM |
7178 | { |
7179 | /* We'll be keeping this opd entry. */ | |
7180 | ||
4025353c | 7181 | if (fdh != NULL) |
1e2f5b6e | 7182 | { |
754021d0 AM |
7183 | /* Redefine the function descriptor symbol to |
7184 | this location in the opd section. It is | |
7185 | necessary to update the value here rather | |
7186 | than using an array of adjustments as we do | |
7187 | for local symbols, because various places | |
7188 | in the generic ELF code use the value | |
7189 | stored in u.def.value. */ | |
3f764659 | 7190 | fdh->elf.root.u.def.value = wptr - new_contents; |
754021d0 | 7191 | fdh->adjust_done = 1; |
1e2f5b6e | 7192 | } |
754021d0 AM |
7193 | |
7194 | /* Local syms are a bit tricky. We could | |
7195 | tweak them as they can be cached, but | |
7196 | we'd need to look through the local syms | |
7197 | for the function descriptor sym which we | |
7198 | don't have at the moment. So keep an | |
7199 | array of adjustments. */ | |
74f0fb50 | 7200 | opd->adjust[rel->r_offset / 8] |
3f764659 | 7201 | = (wptr - new_contents) - (rptr - sec->contents); |
1e2f5b6e AM |
7202 | |
7203 | if (wptr != rptr) | |
3f764659 JJ |
7204 | memcpy (wptr, rptr, opd_ent_size); |
7205 | wptr += opd_ent_size; | |
7206 | if (add_aux_fields && opd_ent_size == 16) | |
7207 | { | |
7208 | memset (wptr, '\0', 8); | |
7209 | wptr += 8; | |
7210 | } | |
1e2f5b6e | 7211 | } |
3f764659 JJ |
7212 | rptr += opd_ent_size; |
7213 | offset += opd_ent_size; | |
1e2f5b6e AM |
7214 | } |
7215 | ||
50bc7936 AM |
7216 | if (skip) |
7217 | { | |
60124e18 AM |
7218 | if (!NO_OPD_RELOCS |
7219 | && !info->relocatable | |
18d944df AM |
7220 | && !dec_dynrel_count (rel->r_info, sec, info, |
7221 | NULL, h, sym_sec)) | |
8c1d1bb8 | 7222 | goto error_ret; |
50bc7936 AM |
7223 | } |
7224 | else | |
1e2f5b6e | 7225 | { |
50bc7936 AM |
7226 | /* We need to adjust any reloc offsets to point to the |
7227 | new opd entries. While we're at it, we may as well | |
7228 | remove redundant relocs. */ | |
74f0fb50 | 7229 | rel->r_offset += opd->adjust[(offset - opd_ent_size) / 8]; |
1e2f5b6e AM |
7230 | if (write_rel != rel) |
7231 | memcpy (write_rel, rel, sizeof (*rel)); | |
7232 | ++write_rel; | |
7233 | } | |
7234 | } | |
7235 | ||
3f764659 | 7236 | sec->size = wptr - new_contents; |
1e2f5b6e | 7237 | sec->reloc_count = write_rel - relstart; |
3f764659 JJ |
7238 | if (add_aux_fields) |
7239 | { | |
7240 | free (sec->contents); | |
7241 | sec->contents = new_contents; | |
7242 | } | |
7243 | ||
05bf9422 | 7244 | /* Fudge the header size too, as this is used later in |
cdcf6e38 | 7245 | elf_bfd_final_link if we are emitting relocs. */ |
d4730f92 BS |
7246 | rel_hdr = _bfd_elf_single_rel_hdr (sec); |
7247 | rel_hdr->sh_size = sec->reloc_count * rel_hdr->sh_entsize; | |
754021d0 | 7248 | some_edited = TRUE; |
1e2f5b6e | 7249 | } |
6cdc0ccc | 7250 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 7251 | free (relstart); |
6cdc0ccc | 7252 | |
411e1bfb AM |
7253 | if (local_syms != NULL |
7254 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
7255 | { | |
7256 | if (!info->keep_memory) | |
7257 | free (local_syms); | |
7258 | else | |
7259 | symtab_hdr->contents = (unsigned char *) local_syms; | |
7260 | } | |
7261 | } | |
7262 | ||
754021d0 AM |
7263 | if (some_edited) |
7264 | elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL); | |
7265 | ||
3f764659 JJ |
7266 | /* If we are doing a final link and the last .opd entry is just 16 byte |
7267 | long, add a 8 byte padding after it. */ | |
7268 | if (need_pad != NULL && !info->relocatable) | |
7269 | { | |
7270 | bfd_byte *p; | |
7271 | ||
7272 | if ((need_pad->flags & SEC_IN_MEMORY) == 0) | |
7273 | { | |
7274 | BFD_ASSERT (need_pad->size > 0); | |
7275 | ||
7276 | p = bfd_malloc (need_pad->size + 8); | |
7277 | if (p == NULL) | |
7278 | return FALSE; | |
699733f6 | 7279 | |
3f764659 JJ |
7280 | if (! bfd_get_section_contents (need_pad->owner, need_pad, |
7281 | p, 0, need_pad->size)) | |
7282 | return FALSE; | |
7283 | ||
7284 | need_pad->contents = p; | |
7285 | need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
7286 | } | |
7287 | else | |
7288 | { | |
7289 | p = bfd_realloc (need_pad->contents, need_pad->size + 8); | |
7290 | if (p == NULL) | |
7291 | return FALSE; | |
7292 | ||
7293 | need_pad->contents = p; | |
7294 | } | |
7295 | ||
7296 | memset (need_pad->contents + need_pad->size, 0, 8); | |
7297 | need_pad->size += 8; | |
7298 | } | |
7299 | ||
411e1bfb AM |
7300 | return TRUE; |
7301 | } | |
7302 | ||
e1918d23 | 7303 | /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ |
411e1bfb | 7304 | |
e1918d23 | 7305 | asection * |
33c0ec9d AM |
7306 | ppc64_elf_tls_setup (struct bfd_link_info *info, |
7307 | int no_tls_get_addr_opt, | |
7308 | int *no_multi_toc) | |
411e1bfb | 7309 | { |
411e1bfb AM |
7310 | struct ppc_link_hash_table *htab; |
7311 | ||
411e1bfb | 7312 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
7313 | if (htab == NULL) |
7314 | return NULL; | |
7315 | ||
33c0ec9d AM |
7316 | if (*no_multi_toc) |
7317 | htab->do_multi_toc = 0; | |
7318 | else if (!htab->do_multi_toc) | |
7319 | *no_multi_toc = 1; | |
7320 | ||
3a71aa26 AM |
7321 | htab->tls_get_addr = ((struct ppc_link_hash_entry *) |
7322 | elf_link_hash_lookup (&htab->elf, ".__tls_get_addr", | |
7323 | FALSE, FALSE, TRUE)); | |
a7f2871e AM |
7324 | /* Move dynamic linking info to the function descriptor sym. */ |
7325 | if (htab->tls_get_addr != NULL) | |
7326 | func_desc_adjust (&htab->tls_get_addr->elf, info); | |
3a71aa26 AM |
7327 | htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *) |
7328 | elf_link_hash_lookup (&htab->elf, "__tls_get_addr", | |
7329 | FALSE, FALSE, TRUE)); | |
a7f2871e AM |
7330 | if (!no_tls_get_addr_opt) |
7331 | { | |
7332 | struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd; | |
7333 | ||
7334 | opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt", | |
7335 | FALSE, FALSE, TRUE); | |
7336 | if (opt != NULL) | |
7337 | func_desc_adjust (opt, info); | |
7338 | opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt", | |
7339 | FALSE, FALSE, TRUE); | |
7340 | if (opt_fd != NULL | |
7341 | && (opt_fd->root.type == bfd_link_hash_defined | |
7342 | || opt_fd->root.type == bfd_link_hash_defweak)) | |
7343 | { | |
7344 | /* If glibc supports an optimized __tls_get_addr call stub, | |
7345 | signalled by the presence of __tls_get_addr_opt, and we'll | |
7346 | be calling __tls_get_addr via a plt call stub, then | |
7347 | make __tls_get_addr point to __tls_get_addr_opt. */ | |
7348 | tga_fd = &htab->tls_get_addr_fd->elf; | |
7349 | if (htab->elf.dynamic_sections_created | |
7350 | && tga_fd != NULL | |
7351 | && (tga_fd->type == STT_FUNC | |
7352 | || tga_fd->needs_plt) | |
7353 | && !(SYMBOL_CALLS_LOCAL (info, tga_fd) | |
7354 | || (ELF_ST_VISIBILITY (tga_fd->other) != STV_DEFAULT | |
7355 | && tga_fd->root.type == bfd_link_hash_undefweak))) | |
7356 | { | |
7357 | struct plt_entry *ent; | |
7358 | ||
7359 | for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next) | |
7360 | if (ent->plt.refcount > 0) | |
7361 | break; | |
7362 | if (ent != NULL) | |
7363 | { | |
7364 | tga_fd->root.type = bfd_link_hash_indirect; | |
7365 | tga_fd->root.u.i.link = &opt_fd->root; | |
7366 | ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd); | |
7367 | if (opt_fd->dynindx != -1) | |
7368 | { | |
7369 | /* Use __tls_get_addr_opt in dynamic relocations. */ | |
7370 | opt_fd->dynindx = -1; | |
7371 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
7372 | opt_fd->dynstr_index); | |
7373 | if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd)) | |
854b41e7 | 7374 | return NULL; |
a7f2871e AM |
7375 | } |
7376 | htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) opt_fd; | |
7377 | tga = &htab->tls_get_addr->elf; | |
7378 | if (opt != NULL && tga != NULL) | |
7379 | { | |
7380 | tga->root.type = bfd_link_hash_indirect; | |
7381 | tga->root.u.i.link = &opt->root; | |
7382 | ppc64_elf_copy_indirect_symbol (info, opt, tga); | |
7383 | _bfd_elf_link_hash_hide_symbol (info, opt, | |
7384 | tga->forced_local); | |
7385 | htab->tls_get_addr = (struct ppc_link_hash_entry *) opt; | |
7386 | } | |
7387 | htab->tls_get_addr_fd->oh = htab->tls_get_addr; | |
7388 | htab->tls_get_addr_fd->is_func_descriptor = 1; | |
7389 | if (htab->tls_get_addr != NULL) | |
7390 | { | |
7391 | htab->tls_get_addr->oh = htab->tls_get_addr_fd; | |
7392 | htab->tls_get_addr->is_func = 1; | |
7393 | } | |
7394 | } | |
7395 | } | |
7396 | } | |
7397 | else | |
7398 | no_tls_get_addr_opt = TRUE; | |
7399 | } | |
7400 | htab->no_tls_get_addr_opt = no_tls_get_addr_opt; | |
33c0ec9d | 7401 | return _bfd_elf_tls_setup (info->output_bfd, info); |
3a71aa26 | 7402 | } |
8387904d | 7403 | |
3a71aa26 AM |
7404 | /* Return TRUE iff REL is a branch reloc with a global symbol matching |
7405 | HASH1 or HASH2. */ | |
8387904d | 7406 | |
3a71aa26 AM |
7407 | static bfd_boolean |
7408 | branch_reloc_hash_match (const bfd *ibfd, | |
7409 | const Elf_Internal_Rela *rel, | |
7410 | const struct ppc_link_hash_entry *hash1, | |
7411 | const struct ppc_link_hash_entry *hash2) | |
7412 | { | |
7413 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); | |
7414 | enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info); | |
7415 | unsigned int r_symndx = ELF64_R_SYM (rel->r_info); | |
7416 | ||
e054468f | 7417 | if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type)) |
8387904d | 7418 | { |
3a71aa26 AM |
7419 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); |
7420 | struct elf_link_hash_entry *h; | |
8387904d | 7421 | |
3a71aa26 | 7422 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
b31867b6 | 7423 | h = elf_follow_link (h); |
3a71aa26 AM |
7424 | if (h == &hash1->elf || h == &hash2->elf) |
7425 | return TRUE; | |
a48ebf4d | 7426 | } |
3a71aa26 | 7427 | return FALSE; |
951fd09b | 7428 | } |
411e1bfb | 7429 | |
951fd09b AM |
7430 | /* Run through all the TLS relocs looking for optimization |
7431 | opportunities. The linker has been hacked (see ppc64elf.em) to do | |
7432 | a preliminary section layout so that we know the TLS segment | |
7433 | offsets. We can't optimize earlier because some optimizations need | |
7434 | to know the tp offset, and we need to optimize before allocating | |
7435 | dynamic relocations. */ | |
7436 | ||
7437 | bfd_boolean | |
33c0ec9d | 7438 | ppc64_elf_tls_optimize (struct bfd_link_info *info) |
951fd09b AM |
7439 | { |
7440 | bfd *ibfd; | |
7441 | asection *sec; | |
7442 | struct ppc_link_hash_table *htab; | |
663a1470 | 7443 | unsigned char *toc_ref; |
102890f0 | 7444 | int pass; |
951fd09b | 7445 | |
1d483afe | 7446 | if (info->relocatable || !info->executable) |
411e1bfb AM |
7447 | return TRUE; |
7448 | ||
951fd09b | 7449 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
7450 | if (htab == NULL) |
7451 | return FALSE; | |
7452 | ||
663a1470 AM |
7453 | /* Make two passes over the relocs. On the first pass, mark toc |
7454 | entries involved with tls relocs, and check that tls relocs | |
7455 | involved in setting up a tls_get_addr call are indeed followed by | |
7456 | such a call. If they are not, we can't do any tls optimization. | |
7457 | On the second pass twiddle tls_mask flags to notify | |
7458 | relocate_section that optimization can be done, and adjust got | |
7459 | and plt refcounts. */ | |
7460 | toc_ref = NULL; | |
7461 | for (pass = 0; pass < 2; ++pass) | |
7462 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
7463 | { | |
7464 | Elf_Internal_Sym *locsyms = NULL; | |
7465 | asection *toc = bfd_get_section_by_name (ibfd, ".toc"); | |
7466 | ||
102890f0 AM |
7467 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
7468 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
7469 | { | |
7470 | Elf_Internal_Rela *relstart, *rel, *relend; | |
663a1470 | 7471 | bfd_boolean found_tls_get_addr_arg = 0; |
411e1bfb | 7472 | |
102890f0 AM |
7473 | /* Read the relocations. */ |
7474 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, | |
7475 | info->keep_memory); | |
7476 | if (relstart == NULL) | |
7477 | return FALSE; | |
411e1bfb | 7478 | |
102890f0 AM |
7479 | relend = relstart + sec->reloc_count; |
7480 | for (rel = relstart; rel < relend; rel++) | |
7481 | { | |
7482 | enum elf_ppc64_reloc_type r_type; | |
7483 | unsigned long r_symndx; | |
7484 | struct elf_link_hash_entry *h; | |
7485 | Elf_Internal_Sym *sym; | |
7486 | asection *sym_sec; | |
f961d9dd AM |
7487 | unsigned char *tls_mask; |
7488 | unsigned char tls_set, tls_clear, tls_type = 0; | |
102890f0 AM |
7489 | bfd_vma value; |
7490 | bfd_boolean ok_tprel, is_local; | |
7491 | long toc_ref_index = 0; | |
7492 | int expecting_tls_get_addr = 0; | |
663a1470 | 7493 | bfd_boolean ret = FALSE; |
411e1bfb | 7494 | |
102890f0 AM |
7495 | r_symndx = ELF64_R_SYM (rel->r_info); |
7496 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, | |
7497 | r_symndx, ibfd)) | |
7498 | { | |
7499 | err_free_rel: | |
7500 | if (elf_section_data (sec)->relocs != relstart) | |
7501 | free (relstart); | |
7502 | if (toc_ref != NULL) | |
7503 | free (toc_ref); | |
7504 | if (locsyms != NULL | |
0ffa91dd | 7505 | && (elf_symtab_hdr (ibfd).contents |
102890f0 AM |
7506 | != (unsigned char *) locsyms)) |
7507 | free (locsyms); | |
663a1470 | 7508 | return ret; |
102890f0 | 7509 | } |
411e1bfb | 7510 | |
102890f0 AM |
7511 | if (h != NULL) |
7512 | { | |
766bc656 AM |
7513 | if (h->root.type == bfd_link_hash_defined |
7514 | || h->root.type == bfd_link_hash_defweak) | |
7515 | value = h->root.u.def.value; | |
7516 | else if (h->root.type == bfd_link_hash_undefweak) | |
7517 | value = 0; | |
7518 | else | |
663a1470 AM |
7519 | { |
7520 | found_tls_get_addr_arg = 0; | |
7521 | continue; | |
7522 | } | |
102890f0 AM |
7523 | } |
7524 | else | |
7525 | /* Symbols referenced by TLS relocs must be of type | |
7526 | STT_TLS. So no need for .opd local sym adjust. */ | |
7527 | value = sym->st_value; | |
7528 | ||
7529 | ok_tprel = FALSE; | |
7530 | is_local = FALSE; | |
7531 | if (h == NULL | |
7532 | || !h->def_dynamic) | |
7533 | { | |
7534 | is_local = TRUE; | |
766bc656 AM |
7535 | if (h != NULL |
7536 | && h->root.type == bfd_link_hash_undefweak) | |
7537 | ok_tprel = TRUE; | |
7538 | else | |
7539 | { | |
7540 | value += sym_sec->output_offset; | |
7541 | value += sym_sec->output_section->vma; | |
7542 | value -= htab->elf.tls_sec->vma; | |
7543 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) | |
7544 | < (bfd_vma) 1 << 32); | |
7545 | } | |
102890f0 | 7546 | } |
951fd09b | 7547 | |
102890f0 | 7548 | r_type = ELF64_R_TYPE (rel->r_info); |
663a1470 AM |
7549 | /* If this section has old-style __tls_get_addr calls |
7550 | without marker relocs, then check that each | |
7551 | __tls_get_addr call reloc is preceded by a reloc | |
7552 | that conceivably belongs to the __tls_get_addr arg | |
7553 | setup insn. If we don't find matching arg setup | |
7554 | relocs, don't do any tls optimization. */ | |
7555 | if (pass == 0 | |
7556 | && sec->has_tls_get_addr_call | |
7557 | && h != NULL | |
7558 | && (h == &htab->tls_get_addr->elf | |
7559 | || h == &htab->tls_get_addr_fd->elf) | |
7560 | && !found_tls_get_addr_arg | |
7561 | && is_branch_reloc (r_type)) | |
7562 | { | |
25f53a85 | 7563 | info->callbacks->minfo (_("%H __tls_get_addr lost arg, " |
663a1470 AM |
7564 | "TLS optimization disabled\n"), |
7565 | ibfd, sec, rel->r_offset); | |
7566 | ret = TRUE; | |
7567 | goto err_free_rel; | |
7568 | } | |
7569 | ||
7570 | found_tls_get_addr_arg = 0; | |
102890f0 AM |
7571 | switch (r_type) |
7572 | { | |
7573 | case R_PPC64_GOT_TLSLD16: | |
7574 | case R_PPC64_GOT_TLSLD16_LO: | |
7575 | expecting_tls_get_addr = 1; | |
663a1470 | 7576 | found_tls_get_addr_arg = 1; |
102890f0 AM |
7577 | /* Fall thru */ |
7578 | ||
7579 | case R_PPC64_GOT_TLSLD16_HI: | |
7580 | case R_PPC64_GOT_TLSLD16_HA: | |
7581 | /* These relocs should never be against a symbol | |
7582 | defined in a shared lib. Leave them alone if | |
7583 | that turns out to be the case. */ | |
7584 | if (!is_local) | |
7585 | continue; | |
411e1bfb | 7586 | |
102890f0 | 7587 | /* LD -> LE */ |
411e1bfb | 7588 | tls_set = 0; |
102890f0 AM |
7589 | tls_clear = TLS_LD; |
7590 | tls_type = TLS_TLS | TLS_LD; | |
7591 | break; | |
411e1bfb | 7592 | |
102890f0 AM |
7593 | case R_PPC64_GOT_TLSGD16: |
7594 | case R_PPC64_GOT_TLSGD16_LO: | |
7595 | expecting_tls_get_addr = 1; | |
663a1470 | 7596 | found_tls_get_addr_arg = 1; |
102890f0 AM |
7597 | /* Fall thru */ |
7598 | ||
7599 | case R_PPC64_GOT_TLSGD16_HI: | |
7600 | case R_PPC64_GOT_TLSGD16_HA: | |
7601 | if (ok_tprel) | |
7602 | /* GD -> LE */ | |
411e1bfb | 7603 | tls_set = 0; |
102890f0 AM |
7604 | else |
7605 | /* GD -> IE */ | |
7606 | tls_set = TLS_TLS | TLS_TPRELGD; | |
7607 | tls_clear = TLS_GD; | |
7608 | tls_type = TLS_TLS | TLS_GD; | |
7609 | break; | |
7610 | ||
7611 | case R_PPC64_GOT_TPREL16_DS: | |
7612 | case R_PPC64_GOT_TPREL16_LO_DS: | |
7613 | case R_PPC64_GOT_TPREL16_HI: | |
7614 | case R_PPC64_GOT_TPREL16_HA: | |
7615 | if (ok_tprel) | |
7616 | { | |
7617 | /* IE -> LE */ | |
7618 | tls_set = 0; | |
7619 | tls_clear = TLS_TPREL; | |
7620 | tls_type = TLS_TLS | TLS_TPREL; | |
7621 | break; | |
7622 | } | |
411e1bfb AM |
7623 | continue; |
7624 | ||
727fc41e AM |
7625 | case R_PPC64_TLSGD: |
7626 | case R_PPC64_TLSLD: | |
663a1470 AM |
7627 | found_tls_get_addr_arg = 1; |
7628 | /* Fall thru */ | |
7629 | ||
7630 | case R_PPC64_TLS: | |
7631 | case R_PPC64_TOC16: | |
7632 | case R_PPC64_TOC16_LO: | |
102890f0 AM |
7633 | if (sym_sec == NULL || sym_sec != toc) |
7634 | continue; | |
7635 | ||
7636 | /* Mark this toc entry as referenced by a TLS | |
7637 | code sequence. We can do that now in the | |
7638 | case of R_PPC64_TLS, and after checking for | |
7639 | tls_get_addr for the TOC16 relocs. */ | |
7640 | if (toc_ref == NULL) | |
663a1470 AM |
7641 | toc_ref = bfd_zmalloc (toc->output_section->rawsize / 8); |
7642 | if (toc_ref == NULL) | |
7643 | goto err_free_rel; | |
7644 | ||
102890f0 AM |
7645 | if (h != NULL) |
7646 | value = h->root.u.def.value; | |
7647 | else | |
7648 | value = sym->st_value; | |
7649 | value += rel->r_addend; | |
7650 | BFD_ASSERT (value < toc->size && value % 8 == 0); | |
663a1470 | 7651 | toc_ref_index = (value + toc->output_offset) / 8; |
727fc41e AM |
7652 | if (r_type == R_PPC64_TLS |
7653 | || r_type == R_PPC64_TLSGD | |
7654 | || r_type == R_PPC64_TLSLD) | |
102890f0 AM |
7655 | { |
7656 | toc_ref[toc_ref_index] = 1; | |
7657 | continue; | |
7658 | } | |
7659 | ||
7660 | if (pass != 0 && toc_ref[toc_ref_index] == 0) | |
7661 | continue; | |
7662 | ||
7663 | tls_set = 0; | |
7664 | tls_clear = 0; | |
7665 | expecting_tls_get_addr = 2; | |
7666 | break; | |
7667 | ||
7668 | case R_PPC64_TPREL64: | |
7669 | if (pass == 0 | |
7670 | || sec != toc | |
7671 | || toc_ref == NULL | |
663a1470 | 7672 | || !toc_ref[(rel->r_offset + toc->output_offset) / 8]) |
102890f0 AM |
7673 | continue; |
7674 | if (ok_tprel) | |
7675 | { | |
7676 | /* IE -> LE */ | |
7677 | tls_set = TLS_EXPLICIT; | |
7678 | tls_clear = TLS_TPREL; | |
7679 | break; | |
7680 | } | |
7681 | continue; | |
7682 | ||
7683 | case R_PPC64_DTPMOD64: | |
7684 | if (pass == 0 | |
7685 | || sec != toc | |
7686 | || toc_ref == NULL | |
663a1470 | 7687 | || !toc_ref[(rel->r_offset + toc->output_offset) / 8]) |
102890f0 AM |
7688 | continue; |
7689 | if (rel + 1 < relend | |
7690 | && (rel[1].r_info | |
7691 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) | |
7692 | && rel[1].r_offset == rel->r_offset + 8) | |
7693 | { | |
7694 | if (ok_tprel) | |
7695 | /* GD -> LE */ | |
7696 | tls_set = TLS_EXPLICIT | TLS_GD; | |
7697 | else | |
7698 | /* GD -> IE */ | |
7699 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; | |
7700 | tls_clear = TLS_GD; | |
7701 | } | |
7702 | else | |
7703 | { | |
7704 | if (!is_local) | |
7705 | continue; | |
7706 | ||
7707 | /* LD -> LE */ | |
7708 | tls_set = TLS_EXPLICIT; | |
7709 | tls_clear = TLS_LD; | |
7710 | } | |
7711 | break; | |
7712 | ||
7713 | default: | |
7714 | continue; | |
7715 | } | |
7716 | ||
7717 | if (pass == 0) | |
7718 | { | |
727fc41e AM |
7719 | if (!expecting_tls_get_addr |
7720 | || !sec->has_tls_get_addr_call) | |
102890f0 AM |
7721 | continue; |
7722 | ||
3a71aa26 AM |
7723 | if (rel + 1 < relend |
7724 | && branch_reloc_hash_match (ibfd, rel + 1, | |
7725 | htab->tls_get_addr, | |
7726 | htab->tls_get_addr_fd)) | |
102890f0 | 7727 | { |
3a71aa26 | 7728 | if (expecting_tls_get_addr == 2) |
102890f0 | 7729 | { |
3a71aa26 | 7730 | /* Check for toc tls entries. */ |
f961d9dd | 7731 | unsigned char *toc_tls; |
3a71aa26 AM |
7732 | int retval; |
7733 | ||
7734 | retval = get_tls_mask (&toc_tls, NULL, NULL, | |
7735 | &locsyms, | |
7736 | rel, ibfd); | |
7737 | if (retval == 0) | |
7738 | goto err_free_rel; | |
663a1470 AM |
7739 | if (toc_tls != NULL) |
7740 | { | |
7741 | if ((*toc_tls & (TLS_GD | TLS_LD)) != 0) | |
7742 | found_tls_get_addr_arg = 1; | |
7743 | if (retval > 1) | |
7744 | toc_ref[toc_ref_index] = 1; | |
7745 | } | |
102890f0 | 7746 | } |
3a71aa26 | 7747 | continue; |
102890f0 AM |
7748 | } |
7749 | ||
7750 | if (expecting_tls_get_addr != 1) | |
7751 | continue; | |
7752 | ||
7753 | /* Uh oh, we didn't find the expected call. We | |
7754 | could just mark this symbol to exclude it | |
7755 | from tls optimization but it's safer to skip | |
663a1470 | 7756 | the entire optimization. */ |
25f53a85 | 7757 | info->callbacks->minfo (_("%H arg lost __tls_get_addr, " |
663a1470 AM |
7758 | "TLS optimization disabled\n"), |
7759 | ibfd, sec, rel->r_offset); | |
7760 | ret = TRUE; | |
7761 | goto err_free_rel; | |
102890f0 AM |
7762 | } |
7763 | ||
85f7a9cb | 7764 | if (expecting_tls_get_addr && htab->tls_get_addr != NULL) |
102890f0 AM |
7765 | { |
7766 | struct plt_entry *ent; | |
7767 | for (ent = htab->tls_get_addr->elf.plt.plist; | |
7768 | ent != NULL; | |
7769 | ent = ent->next) | |
7770 | if (ent->addend == 0) | |
411e1bfb | 7771 | { |
102890f0 | 7772 | if (ent->plt.refcount > 0) |
30038c59 | 7773 | { |
102890f0 AM |
7774 | ent->plt.refcount -= 1; |
7775 | expecting_tls_get_addr = 0; | |
30038c59 | 7776 | } |
102890f0 | 7777 | break; |
411e1bfb | 7778 | } |
102890f0 | 7779 | } |
411e1bfb | 7780 | |
85f7a9cb | 7781 | if (expecting_tls_get_addr && htab->tls_get_addr_fd != NULL) |
102890f0 AM |
7782 | { |
7783 | struct plt_entry *ent; | |
7784 | for (ent = htab->tls_get_addr_fd->elf.plt.plist; | |
7785 | ent != NULL; | |
7786 | ent = ent->next) | |
7787 | if (ent->addend == 0) | |
411e1bfb | 7788 | { |
102890f0 AM |
7789 | if (ent->plt.refcount > 0) |
7790 | ent->plt.refcount -= 1; | |
7791 | break; | |
411e1bfb | 7792 | } |
102890f0 | 7793 | } |
411e1bfb | 7794 | |
102890f0 | 7795 | if (tls_clear == 0) |
30038c59 AM |
7796 | continue; |
7797 | ||
102890f0 AM |
7798 | if ((tls_set & TLS_EXPLICIT) == 0) |
7799 | { | |
7800 | struct got_entry *ent; | |
411e1bfb | 7801 | |
102890f0 AM |
7802 | /* Adjust got entry for this reloc. */ |
7803 | if (h != NULL) | |
7804 | ent = h->got.glist; | |
7805 | else | |
7806 | ent = elf_local_got_ents (ibfd)[r_symndx]; | |
411e1bfb | 7807 | |
102890f0 AM |
7808 | for (; ent != NULL; ent = ent->next) |
7809 | if (ent->addend == rel->r_addend | |
7810 | && ent->owner == ibfd | |
7811 | && ent->tls_type == tls_type) | |
7812 | break; | |
7813 | if (ent == NULL) | |
7814 | abort (); | |
411e1bfb | 7815 | |
102890f0 AM |
7816 | if (tls_set == 0) |
7817 | { | |
7818 | /* We managed to get rid of a got entry. */ | |
7819 | if (ent->got.refcount > 0) | |
7820 | ent->got.refcount -= 1; | |
7821 | } | |
7822 | } | |
7823 | else | |
7824 | { | |
7825 | /* If we got rid of a DTPMOD/DTPREL reloc pair then | |
7826 | we'll lose one or two dyn relocs. */ | |
7827 | if (!dec_dynrel_count (rel->r_info, sec, info, | |
7828 | NULL, h, sym_sec)) | |
7829 | return FALSE; | |
411e1bfb | 7830 | |
102890f0 AM |
7831 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
7832 | { | |
7833 | if (!dec_dynrel_count ((rel + 1)->r_info, sec, info, | |
7834 | NULL, h, sym_sec)) | |
7835 | return FALSE; | |
7836 | } | |
7837 | } | |
411e1bfb | 7838 | |
102890f0 AM |
7839 | *tls_mask |= tls_set; |
7840 | *tls_mask &= ~tls_clear; | |
7841 | } | |
8c1d1bb8 | 7842 | |
102890f0 AM |
7843 | if (elf_section_data (sec)->relocs != relstart) |
7844 | free (relstart); | |
7845 | } | |
411e1bfb | 7846 | |
663a1470 AM |
7847 | if (locsyms != NULL |
7848 | && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms)) | |
7849 | { | |
7850 | if (!info->keep_memory) | |
7851 | free (locsyms); | |
7852 | else | |
7853 | elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms; | |
7854 | } | |
7855 | } | |
411e1bfb | 7856 | |
663a1470 AM |
7857 | if (toc_ref != NULL) |
7858 | free (toc_ref); | |
b34976b6 | 7859 | return TRUE; |
1e2f5b6e | 7860 | } |
b34976b6 | 7861 | |
c5614fa4 AM |
7862 | /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust |
7863 | the values of any global symbols in a toc section that has been | |
7864 | edited. Globals in toc sections should be a rarity, so this function | |
7865 | sets a flag if any are found in toc sections other than the one just | |
7866 | edited, so that futher hash table traversals can be avoided. */ | |
7867 | ||
7868 | struct adjust_toc_info | |
7869 | { | |
7870 | asection *toc; | |
7871 | unsigned long *skip; | |
7872 | bfd_boolean global_toc_syms; | |
7873 | }; | |
7874 | ||
ba761f19 AM |
7875 | enum toc_skip_enum { ref_from_discarded = 1, can_optimize = 2 }; |
7876 | ||
c5614fa4 AM |
7877 | static bfd_boolean |
7878 | adjust_toc_syms (struct elf_link_hash_entry *h, void *inf) | |
7879 | { | |
7880 | struct ppc_link_hash_entry *eh; | |
7881 | struct adjust_toc_info *toc_inf = (struct adjust_toc_info *) inf; | |
854b41e7 | 7882 | unsigned long i; |
c5614fa4 AM |
7883 | |
7884 | if (h->root.type == bfd_link_hash_indirect) | |
7885 | return TRUE; | |
7886 | ||
c5614fa4 AM |
7887 | if (h->root.type != bfd_link_hash_defined |
7888 | && h->root.type != bfd_link_hash_defweak) | |
7889 | return TRUE; | |
7890 | ||
7891 | eh = (struct ppc_link_hash_entry *) h; | |
7892 | if (eh->adjust_done) | |
7893 | return TRUE; | |
7894 | ||
7895 | if (eh->elf.root.u.def.section == toc_inf->toc) | |
7896 | { | |
854b41e7 AM |
7897 | if (eh->elf.root.u.def.value > toc_inf->toc->rawsize) |
7898 | i = toc_inf->toc->rawsize >> 3; | |
c5614fa4 | 7899 | else |
854b41e7 AM |
7900 | i = eh->elf.root.u.def.value >> 3; |
7901 | ||
ba761f19 | 7902 | if ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0) |
c5614fa4 AM |
7903 | { |
7904 | (*_bfd_error_handler) | |
854b41e7 AM |
7905 | (_("%s defined on removed toc entry"), eh->elf.root.root.string); |
7906 | do | |
7907 | ++i; | |
ba761f19 | 7908 | while ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0); |
854b41e7 | 7909 | eh->elf.root.u.def.value = (bfd_vma) i << 3; |
c5614fa4 | 7910 | } |
854b41e7 AM |
7911 | |
7912 | eh->elf.root.u.def.value -= toc_inf->skip[i]; | |
c5614fa4 AM |
7913 | eh->adjust_done = 1; |
7914 | } | |
7915 | else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0) | |
7916 | toc_inf->global_toc_syms = TRUE; | |
7917 | ||
7918 | return TRUE; | |
7919 | } | |
7920 | ||
7921 | /* Examine all relocs referencing .toc sections in order to remove | |
7922 | unused .toc entries. */ | |
7923 | ||
7924 | bfd_boolean | |
33c0ec9d | 7925 | ppc64_elf_edit_toc (struct bfd_link_info *info) |
c5614fa4 AM |
7926 | { |
7927 | bfd *ibfd; | |
7928 | struct adjust_toc_info toc_inf; | |
67f0cbdb | 7929 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
c5614fa4 | 7930 | |
67f0cbdb | 7931 | htab->do_toc_opt = 1; |
c5614fa4 AM |
7932 | toc_inf.global_toc_syms = TRUE; |
7933 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
7934 | { | |
7935 | asection *toc, *sec; | |
7936 | Elf_Internal_Shdr *symtab_hdr; | |
7937 | Elf_Internal_Sym *local_syms; | |
425b145b | 7938 | Elf_Internal_Rela *relstart, *rel, *toc_relocs; |
c5614fa4 AM |
7939 | unsigned long *skip, *drop; |
7940 | unsigned char *used; | |
7941 | unsigned char *keep, last, some_unused; | |
7942 | ||
854b41e7 AM |
7943 | if (!is_ppc64_elf (ibfd)) |
7944 | continue; | |
7945 | ||
c5614fa4 AM |
7946 | toc = bfd_get_section_by_name (ibfd, ".toc"); |
7947 | if (toc == NULL | |
92b7a70f | 7948 | || toc->size == 0 |
c5614fa4 AM |
7949 | || toc->sec_info_type == ELF_INFO_TYPE_JUST_SYMS |
7950 | || elf_discarded_section (toc)) | |
7951 | continue; | |
7952 | ||
425b145b | 7953 | toc_relocs = NULL; |
c5614fa4 | 7954 | local_syms = NULL; |
0ffa91dd | 7955 | symtab_hdr = &elf_symtab_hdr (ibfd); |
c5614fa4 AM |
7956 | |
7957 | /* Look at sections dropped from the final link. */ | |
7958 | skip = NULL; | |
7959 | relstart = NULL; | |
7960 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
7961 | { | |
7962 | if (sec->reloc_count == 0 | |
7963 | || !elf_discarded_section (sec) | |
7964 | || get_opd_info (sec) | |
7965 | || (sec->flags & SEC_ALLOC) == 0 | |
7966 | || (sec->flags & SEC_DEBUGGING) != 0) | |
7967 | continue; | |
7968 | ||
7969 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE); | |
7970 | if (relstart == NULL) | |
7971 | goto error_ret; | |
7972 | ||
7973 | /* Run through the relocs to see which toc entries might be | |
7974 | unused. */ | |
7975 | for (rel = relstart; rel < relstart + sec->reloc_count; ++rel) | |
7976 | { | |
7977 | enum elf_ppc64_reloc_type r_type; | |
7978 | unsigned long r_symndx; | |
7979 | asection *sym_sec; | |
7980 | struct elf_link_hash_entry *h; | |
7981 | Elf_Internal_Sym *sym; | |
7982 | bfd_vma val; | |
7983 | ||
7984 | r_type = ELF64_R_TYPE (rel->r_info); | |
7985 | switch (r_type) | |
7986 | { | |
7987 | default: | |
7988 | continue; | |
7989 | ||
7990 | case R_PPC64_TOC16: | |
7991 | case R_PPC64_TOC16_LO: | |
7992 | case R_PPC64_TOC16_HI: | |
7993 | case R_PPC64_TOC16_HA: | |
7994 | case R_PPC64_TOC16_DS: | |
7995 | case R_PPC64_TOC16_LO_DS: | |
7996 | break; | |
7997 | } | |
7998 | ||
7999 | r_symndx = ELF64_R_SYM (rel->r_info); | |
8000 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
8001 | r_symndx, ibfd)) | |
8002 | goto error_ret; | |
8003 | ||
8004 | if (sym_sec != toc) | |
8005 | continue; | |
8006 | ||
8007 | if (h != NULL) | |
8008 | val = h->root.u.def.value; | |
8009 | else | |
8010 | val = sym->st_value; | |
8011 | val += rel->r_addend; | |
8012 | ||
8013 | if (val >= toc->size) | |
8014 | continue; | |
8015 | ||
8016 | /* Anything in the toc ought to be aligned to 8 bytes. | |
8017 | If not, don't mark as unused. */ | |
8018 | if (val & 7) | |
8019 | continue; | |
8020 | ||
8021 | if (skip == NULL) | |
8022 | { | |
854b41e7 | 8023 | skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8); |
c5614fa4 AM |
8024 | if (skip == NULL) |
8025 | goto error_ret; | |
8026 | } | |
8027 | ||
ba761f19 | 8028 | skip[val >> 3] = ref_from_discarded; |
c5614fa4 AM |
8029 | } |
8030 | ||
8031 | if (elf_section_data (sec)->relocs != relstart) | |
8032 | free (relstart); | |
8033 | } | |
8034 | ||
ba761f19 AM |
8035 | /* For largetoc loads of address constants, we can convert |
8036 | . addis rx,2,addr@got@ha | |
8037 | . ld ry,addr@got@l(rx) | |
8038 | to | |
8039 | . addis rx,2,addr@toc@ha | |
8040 | . addi ry,rx,addr@toc@l | |
8041 | when addr is within 2G of the toc pointer. This then means | |
8042 | that the word storing "addr" in the toc is no longer needed. */ | |
8043 | ||
8044 | if (!ppc64_elf_tdata (ibfd)->has_small_toc_reloc | |
8045 | && toc->output_section->rawsize < (bfd_vma) 1 << 31 | |
8046 | && toc->reloc_count != 0) | |
8047 | { | |
8048 | /* Read toc relocs. */ | |
425b145b AM |
8049 | toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL, |
8050 | info->keep_memory); | |
8051 | if (toc_relocs == NULL) | |
ba761f19 AM |
8052 | goto error_ret; |
8053 | ||
425b145b | 8054 | for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel) |
ba761f19 AM |
8055 | { |
8056 | enum elf_ppc64_reloc_type r_type; | |
8057 | unsigned long r_symndx; | |
8058 | asection *sym_sec; | |
8059 | struct elf_link_hash_entry *h; | |
8060 | Elf_Internal_Sym *sym; | |
8061 | bfd_vma val, addr; | |
8062 | ||
8063 | r_type = ELF64_R_TYPE (rel->r_info); | |
8064 | if (r_type != R_PPC64_ADDR64) | |
8065 | continue; | |
8066 | ||
8067 | r_symndx = ELF64_R_SYM (rel->r_info); | |
8068 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
8069 | r_symndx, ibfd)) | |
8070 | goto error_ret; | |
8071 | ||
425b145b AM |
8072 | if (sym_sec == NULL |
8073 | || elf_discarded_section (sym_sec)) | |
8074 | continue; | |
8075 | ||
726d3ab0 | 8076 | if (!SYMBOL_CALLS_LOCAL (info, h)) |
ba761f19 AM |
8077 | continue; |
8078 | ||
8079 | if (h != NULL) | |
bddc25c9 AM |
8080 | { |
8081 | if (h->type == STT_GNU_IFUNC) | |
8082 | continue; | |
8083 | val = h->root.u.def.value; | |
8084 | } | |
ba761f19 | 8085 | else |
bddc25c9 AM |
8086 | { |
8087 | if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
8088 | continue; | |
8089 | val = sym->st_value; | |
8090 | } | |
ba761f19 AM |
8091 | val += rel->r_addend; |
8092 | val += sym_sec->output_section->vma + sym_sec->output_offset; | |
8093 | ||
8094 | /* We don't yet know the exact toc pointer value, but we | |
8095 | know it will be somewhere in the toc section. Don't | |
8096 | optimize if the difference from any possible toc | |
8097 | pointer is outside [ff..f80008000, 7fff7fff]. */ | |
8098 | addr = toc->output_section->vma + TOC_BASE_OFF; | |
8099 | if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32) | |
8100 | continue; | |
8101 | ||
8102 | addr = toc->output_section->vma + toc->output_section->rawsize; | |
8103 | if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32) | |
8104 | continue; | |
8105 | ||
8106 | if (skip == NULL) | |
8107 | { | |
8108 | skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8); | |
8109 | if (skip == NULL) | |
8110 | goto error_ret; | |
8111 | } | |
8112 | ||
8113 | skip[rel->r_offset >> 3] | |
425b145b | 8114 | |= can_optimize | ((rel - toc_relocs) << 2); |
ba761f19 | 8115 | } |
ba761f19 AM |
8116 | } |
8117 | ||
c5614fa4 AM |
8118 | if (skip == NULL) |
8119 | continue; | |
8120 | ||
8121 | used = bfd_zmalloc (sizeof (*used) * (toc->size + 7) / 8); | |
8122 | if (used == NULL) | |
8123 | { | |
8124 | error_ret: | |
8125 | if (local_syms != NULL | |
8126 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
8127 | free (local_syms); | |
8128 | if (sec != NULL | |
8129 | && relstart != NULL | |
8130 | && elf_section_data (sec)->relocs != relstart) | |
8131 | free (relstart); | |
425b145b AM |
8132 | if (toc_relocs != NULL |
8133 | && elf_section_data (toc)->relocs != toc_relocs) | |
8134 | free (toc_relocs); | |
c5614fa4 AM |
8135 | if (skip != NULL) |
8136 | free (skip); | |
8137 | return FALSE; | |
8138 | } | |
8139 | ||
30038c59 AM |
8140 | /* Now check all kept sections that might reference the toc. |
8141 | Check the toc itself last. */ | |
8142 | for (sec = (ibfd->sections == toc && toc->next ? toc->next | |
8143 | : ibfd->sections); | |
c5614fa4 | 8144 | sec != NULL; |
c5614fa4 | 8145 | sec = (sec == toc ? NULL |
c5614fa4 | 8146 | : sec->next == NULL ? toc |
30038c59 | 8147 | : sec->next == toc && toc->next ? toc->next |
c5614fa4 AM |
8148 | : sec->next)) |
8149 | { | |
8150 | int repeat; | |
8151 | ||
8152 | if (sec->reloc_count == 0 | |
8153 | || elf_discarded_section (sec) | |
8154 | || get_opd_info (sec) | |
8155 | || (sec->flags & SEC_ALLOC) == 0 | |
8156 | || (sec->flags & SEC_DEBUGGING) != 0) | |
8157 | continue; | |
8158 | ||
854b41e7 AM |
8159 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
8160 | info->keep_memory); | |
c5614fa4 AM |
8161 | if (relstart == NULL) |
8162 | goto error_ret; | |
8163 | ||
8164 | /* Mark toc entries referenced as used. */ | |
8165 | repeat = 0; | |
8166 | do | |
8167 | for (rel = relstart; rel < relstart + sec->reloc_count; ++rel) | |
8168 | { | |
8169 | enum elf_ppc64_reloc_type r_type; | |
8170 | unsigned long r_symndx; | |
8171 | asection *sym_sec; | |
8172 | struct elf_link_hash_entry *h; | |
8173 | Elf_Internal_Sym *sym; | |
8174 | bfd_vma val; | |
8175 | ||
8176 | r_type = ELF64_R_TYPE (rel->r_info); | |
8177 | switch (r_type) | |
8178 | { | |
8179 | case R_PPC64_TOC16: | |
8180 | case R_PPC64_TOC16_LO: | |
8181 | case R_PPC64_TOC16_HI: | |
8182 | case R_PPC64_TOC16_HA: | |
8183 | case R_PPC64_TOC16_DS: | |
8184 | case R_PPC64_TOC16_LO_DS: | |
8185 | /* In case we're taking addresses of toc entries. */ | |
8186 | case R_PPC64_ADDR64: | |
8187 | break; | |
8188 | ||
8189 | default: | |
8190 | continue; | |
8191 | } | |
8192 | ||
8193 | r_symndx = ELF64_R_SYM (rel->r_info); | |
8194 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
8195 | r_symndx, ibfd)) | |
8196 | { | |
8197 | free (used); | |
8198 | goto error_ret; | |
8199 | } | |
8200 | ||
8201 | if (sym_sec != toc) | |
8202 | continue; | |
8203 | ||
8204 | if (h != NULL) | |
8205 | val = h->root.u.def.value; | |
8206 | else | |
8207 | val = sym->st_value; | |
8208 | val += rel->r_addend; | |
8209 | ||
8210 | if (val >= toc->size) | |
8211 | continue; | |
8212 | ||
ba761f19 AM |
8213 | if ((skip[val >> 3] & can_optimize) != 0) |
8214 | { | |
8215 | bfd_vma off; | |
8216 | unsigned char opc; | |
8217 | ||
8218 | switch (r_type) | |
8219 | { | |
8220 | case R_PPC64_TOC16_HA: | |
8221 | break; | |
8222 | ||
8223 | case R_PPC64_TOC16_LO_DS: | |
8224 | off = rel->r_offset + (bfd_big_endian (ibfd) ? -2 : 3); | |
8225 | if (!bfd_get_section_contents (ibfd, sec, &opc, off, 1)) | |
8226 | return FALSE; | |
8227 | if ((opc & (0x3f << 2)) == (58u << 2)) | |
8228 | break; | |
8229 | /* Fall thru */ | |
8230 | ||
8231 | default: | |
8232 | /* Wrong sort of reloc, or not a ld. We may | |
8233 | as well clear ref_from_discarded too. */ | |
8234 | skip[val >> 3] = 0; | |
8235 | } | |
8236 | } | |
8237 | ||
c5614fa4 AM |
8238 | /* For the toc section, we only mark as used if |
8239 | this entry itself isn't unused. */ | |
8240 | if (sec == toc | |
8241 | && !used[val >> 3] | |
8242 | && (used[rel->r_offset >> 3] | |
ba761f19 | 8243 | || !(skip[rel->r_offset >> 3] & ref_from_discarded))) |
c5614fa4 AM |
8244 | /* Do all the relocs again, to catch reference |
8245 | chains. */ | |
8246 | repeat = 1; | |
8247 | ||
8248 | used[val >> 3] = 1; | |
8249 | } | |
8250 | while (repeat); | |
854b41e7 AM |
8251 | |
8252 | if (elf_section_data (sec)->relocs != relstart) | |
8253 | free (relstart); | |
c5614fa4 AM |
8254 | } |
8255 | ||
8256 | /* Merge the used and skip arrays. Assume that TOC | |
8257 | doublewords not appearing as either used or unused belong | |
8258 | to to an entry more than one doubleword in size. */ | |
8259 | for (drop = skip, keep = used, last = 0, some_unused = 0; | |
8260 | drop < skip + (toc->size + 7) / 8; | |
8261 | ++drop, ++keep) | |
8262 | { | |
8263 | if (*keep) | |
8264 | { | |
ba761f19 AM |
8265 | *drop &= ~ref_from_discarded; |
8266 | if ((*drop & can_optimize) != 0) | |
8267 | some_unused = 1; | |
c5614fa4 AM |
8268 | last = 0; |
8269 | } | |
8270 | else if (*drop) | |
8271 | { | |
8272 | some_unused = 1; | |
ba761f19 | 8273 | last = ref_from_discarded; |
c5614fa4 AM |
8274 | } |
8275 | else | |
8276 | *drop = last; | |
8277 | } | |
8278 | ||
8279 | free (used); | |
8280 | ||
8281 | if (some_unused) | |
8282 | { | |
8283 | bfd_byte *contents, *src; | |
8284 | unsigned long off; | |
d62b3684 | 8285 | Elf_Internal_Sym *sym; |
ba761f19 | 8286 | bfd_boolean local_toc_syms = FALSE; |
c5614fa4 AM |
8287 | |
8288 | /* Shuffle the toc contents, and at the same time convert the | |
8289 | skip array from booleans into offsets. */ | |
8290 | if (!bfd_malloc_and_get_section (ibfd, toc, &contents)) | |
8291 | goto error_ret; | |
8292 | ||
8293 | elf_section_data (toc)->this_hdr.contents = contents; | |
8294 | ||
8295 | for (src = contents, off = 0, drop = skip; | |
8296 | src < contents + toc->size; | |
8297 | src += 8, ++drop) | |
8298 | { | |
ba761f19 AM |
8299 | if ((*drop & (can_optimize | ref_from_discarded)) != 0) |
8300 | off += 8; | |
c5614fa4 AM |
8301 | else if (off != 0) |
8302 | { | |
8303 | *drop = off; | |
8304 | memcpy (src - off, src, 8); | |
8305 | } | |
8306 | } | |
854b41e7 | 8307 | *drop = off; |
c5614fa4 AM |
8308 | toc->rawsize = toc->size; |
8309 | toc->size = src - contents - off; | |
8310 | ||
ba761f19 AM |
8311 | /* Adjust addends for relocs against the toc section sym, |
8312 | and optimize any accesses we can. */ | |
c5614fa4 AM |
8313 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
8314 | { | |
8315 | if (sec->reloc_count == 0 | |
8316 | || elf_discarded_section (sec)) | |
8317 | continue; | |
8318 | ||
8319 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, | |
854b41e7 | 8320 | info->keep_memory); |
c5614fa4 AM |
8321 | if (relstart == NULL) |
8322 | goto error_ret; | |
8323 | ||
8324 | for (rel = relstart; rel < relstart + sec->reloc_count; ++rel) | |
8325 | { | |
8326 | enum elf_ppc64_reloc_type r_type; | |
8327 | unsigned long r_symndx; | |
8328 | asection *sym_sec; | |
8329 | struct elf_link_hash_entry *h; | |
854b41e7 | 8330 | bfd_vma val; |
c5614fa4 AM |
8331 | |
8332 | r_type = ELF64_R_TYPE (rel->r_info); | |
8333 | switch (r_type) | |
8334 | { | |
8335 | default: | |
8336 | continue; | |
8337 | ||
8338 | case R_PPC64_TOC16: | |
8339 | case R_PPC64_TOC16_LO: | |
8340 | case R_PPC64_TOC16_HI: | |
8341 | case R_PPC64_TOC16_HA: | |
8342 | case R_PPC64_TOC16_DS: | |
8343 | case R_PPC64_TOC16_LO_DS: | |
8344 | case R_PPC64_ADDR64: | |
8345 | break; | |
8346 | } | |
8347 | ||
8348 | r_symndx = ELF64_R_SYM (rel->r_info); | |
8349 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
8350 | r_symndx, ibfd)) | |
8351 | goto error_ret; | |
8352 | ||
ba761f19 | 8353 | if (sym_sec != toc) |
c5614fa4 AM |
8354 | continue; |
8355 | ||
ba761f19 AM |
8356 | if (h != NULL) |
8357 | val = h->root.u.def.value; | |
8358 | else | |
8359 | { | |
8360 | val = sym->st_value; | |
8361 | if (val != 0) | |
8362 | local_toc_syms = TRUE; | |
8363 | } | |
8364 | ||
8365 | val += rel->r_addend; | |
854b41e7 AM |
8366 | |
8367 | if (val > toc->rawsize) | |
8368 | val = toc->rawsize; | |
ba761f19 AM |
8369 | else if ((skip[val >> 3] & ref_from_discarded) != 0) |
8370 | continue; | |
8371 | else if ((skip[val >> 3] & can_optimize) != 0) | |
8372 | { | |
8373 | Elf_Internal_Rela *tocrel | |
425b145b | 8374 | = toc_relocs + (skip[val >> 3] >> 2); |
ba761f19 AM |
8375 | unsigned long tsym = ELF64_R_SYM (tocrel->r_info); |
8376 | ||
8377 | switch (r_type) | |
8378 | { | |
8379 | case R_PPC64_TOC16_HA: | |
8380 | rel->r_info = ELF64_R_INFO (tsym, R_PPC64_TOC16_HA); | |
8381 | break; | |
8382 | ||
8383 | case R_PPC64_TOC16_LO_DS: | |
8384 | rel->r_info = ELF64_R_INFO (tsym, R_PPC64_LO_DS_OPT); | |
8385 | break; | |
8386 | ||
8387 | default: | |
8388 | abort (); | |
8389 | } | |
8390 | rel->r_addend = tocrel->r_addend; | |
8391 | elf_section_data (sec)->relocs = relstart; | |
8392 | continue; | |
8393 | } | |
8394 | ||
8395 | if (h != NULL || sym->st_value != 0) | |
8396 | continue; | |
854b41e7 AM |
8397 | |
8398 | rel->r_addend -= skip[val >> 3]; | |
8399 | elf_section_data (sec)->relocs = relstart; | |
c5614fa4 | 8400 | } |
854b41e7 AM |
8401 | |
8402 | if (elf_section_data (sec)->relocs != relstart) | |
8403 | free (relstart); | |
c5614fa4 AM |
8404 | } |
8405 | ||
8406 | /* We shouldn't have local or global symbols defined in the TOC, | |
8407 | but handle them anyway. */ | |
df22d223 AM |
8408 | if (local_syms != NULL) |
8409 | for (sym = local_syms; | |
8410 | sym < local_syms + symtab_hdr->sh_info; | |
8411 | ++sym) | |
8412 | if (sym->st_value != 0 | |
8413 | && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc) | |
8414 | { | |
8415 | unsigned long i; | |
854b41e7 | 8416 | |
df22d223 AM |
8417 | if (sym->st_value > toc->rawsize) |
8418 | i = toc->rawsize >> 3; | |
8419 | else | |
8420 | i = sym->st_value >> 3; | |
854b41e7 | 8421 | |
df22d223 AM |
8422 | if ((skip[i] & (ref_from_discarded | can_optimize)) != 0) |
8423 | { | |
8424 | if (local_toc_syms) | |
8425 | (*_bfd_error_handler) | |
8426 | (_("%s defined on removed toc entry"), | |
8427 | bfd_elf_sym_name (ibfd, symtab_hdr, sym, NULL)); | |
8428 | do | |
8429 | ++i; | |
8430 | while ((skip[i] & (ref_from_discarded | can_optimize))); | |
8431 | sym->st_value = (bfd_vma) i << 3; | |
8432 | } | |
d62b3684 | 8433 | |
df22d223 AM |
8434 | sym->st_value -= skip[i]; |
8435 | symtab_hdr->contents = (unsigned char *) local_syms; | |
8436 | } | |
c5614fa4 | 8437 | |
854b41e7 | 8438 | /* Adjust any global syms defined in this toc input section. */ |
c5614fa4 AM |
8439 | if (toc_inf.global_toc_syms) |
8440 | { | |
8441 | toc_inf.toc = toc; | |
8442 | toc_inf.skip = skip; | |
8443 | toc_inf.global_toc_syms = FALSE; | |
8444 | elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms, | |
8445 | &toc_inf); | |
8446 | } | |
854b41e7 AM |
8447 | |
8448 | if (toc->reloc_count != 0) | |
8449 | { | |
d4730f92 | 8450 | Elf_Internal_Shdr *rel_hdr; |
854b41e7 AM |
8451 | Elf_Internal_Rela *wrel; |
8452 | bfd_size_type sz; | |
8453 | ||
854b41e7 | 8454 | /* Remove unused toc relocs, and adjust those we keep. */ |
28be611c AM |
8455 | if (toc_relocs == NULL) |
8456 | toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL, | |
8457 | info->keep_memory); | |
8458 | if (toc_relocs == NULL) | |
8459 | goto error_ret; | |
8460 | ||
425b145b AM |
8461 | wrel = toc_relocs; |
8462 | for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel) | |
ba761f19 AM |
8463 | if ((skip[rel->r_offset >> 3] |
8464 | & (ref_from_discarded | can_optimize)) == 0) | |
854b41e7 AM |
8465 | { |
8466 | wrel->r_offset = rel->r_offset - skip[rel->r_offset >> 3]; | |
8467 | wrel->r_info = rel->r_info; | |
8468 | wrel->r_addend = rel->r_addend; | |
8469 | ++wrel; | |
8470 | } | |
8471 | else if (!dec_dynrel_count (rel->r_info, toc, info, | |
8472 | &local_syms, NULL, NULL)) | |
8473 | goto error_ret; | |
8474 | ||
425b145b AM |
8475 | elf_section_data (toc)->relocs = toc_relocs; |
8476 | toc->reloc_count = wrel - toc_relocs; | |
d4730f92 BS |
8477 | rel_hdr = _bfd_elf_single_rel_hdr (toc); |
8478 | sz = rel_hdr->sh_entsize; | |
8479 | rel_hdr->sh_size = toc->reloc_count * sz; | |
854b41e7 | 8480 | } |
c5614fa4 | 8481 | } |
28be611c AM |
8482 | else if (toc_relocs != NULL |
8483 | && elf_section_data (toc)->relocs != toc_relocs) | |
425b145b | 8484 | free (toc_relocs); |
c5614fa4 AM |
8485 | |
8486 | if (local_syms != NULL | |
8487 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
8488 | { | |
8489 | if (!info->keep_memory) | |
8490 | free (local_syms); | |
8491 | else | |
8492 | symtab_hdr->contents = (unsigned char *) local_syms; | |
8493 | } | |
8494 | free (skip); | |
8495 | } | |
8496 | ||
8497 | return TRUE; | |
8498 | } | |
8499 | ||
1bbe0902 AM |
8500 | /* Return true iff input section I references the TOC using |
8501 | instructions limited to +/-32k offsets. */ | |
8502 | ||
8503 | bfd_boolean | |
8504 | ppc64_elf_has_small_toc_reloc (asection *i) | |
8505 | { | |
8506 | return (is_ppc64_elf (i->owner) | |
8507 | && ppc64_elf_tdata (i->owner)->has_small_toc_reloc); | |
8508 | } | |
8509 | ||
927be08e AM |
8510 | /* Allocate space for one GOT entry. */ |
8511 | ||
8512 | static void | |
8513 | allocate_got (struct elf_link_hash_entry *h, | |
8514 | struct bfd_link_info *info, | |
8515 | struct got_entry *gent) | |
8516 | { | |
8517 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
8518 | bfd_boolean dyn; | |
8519 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h; | |
8520 | int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD) | |
8521 | ? 16 : 8); | |
8522 | int rentsize = (gent->tls_type & eh->tls_mask & TLS_GD | |
8523 | ? 2 : 1) * sizeof (Elf64_External_Rela); | |
8524 | asection *got = ppc64_elf_tdata (gent->owner)->got; | |
8525 | ||
8526 | gent->got.offset = got->size; | |
8527 | got->size += entsize; | |
8528 | ||
8529 | dyn = htab->elf.dynamic_sections_created; | |
8530 | if ((info->shared | |
8531 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
8532 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8533 | || h->root.type != bfd_link_hash_undefweak)) | |
8534 | { | |
8535 | asection *relgot = ppc64_elf_tdata (gent->owner)->relgot; | |
8536 | relgot->size += rentsize; | |
8537 | } | |
8538 | else if (h->type == STT_GNU_IFUNC) | |
8539 | { | |
8540 | asection *relgot = htab->reliplt; | |
8541 | relgot->size += rentsize; | |
8542 | htab->got_reli_size += rentsize; | |
8543 | } | |
8544 | } | |
8545 | ||
7865406b AM |
8546 | /* This function merges got entries in the same toc group. */ |
8547 | ||
8548 | static void | |
8549 | merge_got_entries (struct got_entry **pent) | |
8550 | { | |
8551 | struct got_entry *ent, *ent2; | |
8552 | ||
8553 | for (ent = *pent; ent != NULL; ent = ent->next) | |
8554 | if (!ent->is_indirect) | |
8555 | for (ent2 = ent->next; ent2 != NULL; ent2 = ent2->next) | |
8556 | if (!ent2->is_indirect | |
8557 | && ent2->addend == ent->addend | |
8558 | && ent2->tls_type == ent->tls_type | |
8559 | && elf_gp (ent2->owner) == elf_gp (ent->owner)) | |
8560 | { | |
8561 | ent2->is_indirect = TRUE; | |
8562 | ent2->got.ent = ent; | |
8563 | } | |
8564 | } | |
8565 | ||
65f38f15 AM |
8566 | /* Allocate space in .plt, .got and associated reloc sections for |
8567 | dynamic relocs. */ | |
5bd4f169 | 8568 | |
b34976b6 | 8569 | static bfd_boolean |
4ce794b7 | 8570 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 8571 | { |
65f38f15 AM |
8572 | struct bfd_link_info *info; |
8573 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 8574 | asection *s; |
65f38f15 | 8575 | struct ppc_link_hash_entry *eh; |
6061a67d | 8576 | struct elf_dyn_relocs *p; |
0b8bcf0d | 8577 | struct got_entry **pgent, *gent; |
5bd4f169 | 8578 | |
e92d460e | 8579 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 8580 | return TRUE; |
5bd4f169 | 8581 | |
65f38f15 AM |
8582 | info = (struct bfd_link_info *) inf; |
8583 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
8584 | if (htab == NULL) |
8585 | return FALSE; | |
5bd4f169 | 8586 | |
e054468f AM |
8587 | if ((htab->elf.dynamic_sections_created |
8588 | && h->dynindx != -1 | |
8589 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) | |
8590 | || h->type == STT_GNU_IFUNC) | |
5bd4f169 | 8591 | { |
411e1bfb AM |
8592 | struct plt_entry *pent; |
8593 | bfd_boolean doneone = FALSE; | |
8594 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) | |
8595 | if (pent->plt.refcount > 0) | |
8596 | { | |
25f23106 AM |
8597 | if (!htab->elf.dynamic_sections_created |
8598 | || h->dynindx == -1) | |
e054468f AM |
8599 | { |
8600 | s = htab->iplt; | |
8601 | pent->plt.offset = s->size; | |
8602 | s->size += PLT_ENTRY_SIZE; | |
8603 | s = htab->reliplt; | |
8604 | } | |
8605 | else | |
8606 | { | |
8607 | /* If this is the first .plt entry, make room for the special | |
8608 | first entry. */ | |
8609 | s = htab->plt; | |
8610 | if (s->size == 0) | |
8611 | s->size += PLT_INITIAL_ENTRY_SIZE; | |
8612 | ||
8613 | pent->plt.offset = s->size; | |
8614 | ||
8615 | /* Make room for this entry. */ | |
8616 | s->size += PLT_ENTRY_SIZE; | |
8617 | ||
8618 | /* Make room for the .glink code. */ | |
8619 | s = htab->glink; | |
8620 | if (s->size == 0) | |
8621 | s->size += GLINK_CALL_STUB_SIZE; | |
8622 | /* We need bigger stubs past index 32767. */ | |
8623 | if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4) | |
8624 | s->size += 4; | |
8625 | s->size += 2*4; | |
8626 | ||
8627 | /* We also need to make an entry in the .rela.plt section. */ | |
8628 | s = htab->relplt; | |
8629 | } | |
eea6121a | 8630 | s->size += sizeof (Elf64_External_Rela); |
411e1bfb AM |
8631 | doneone = TRUE; |
8632 | } | |
8633 | else | |
8634 | pent->plt.offset = (bfd_vma) -1; | |
8635 | if (!doneone) | |
65f38f15 | 8636 | { |
411e1bfb | 8637 | h->plt.plist = NULL; |
f5385ebf | 8638 | h->needs_plt = 0; |
65f38f15 AM |
8639 | } |
8640 | } | |
8641 | else | |
8642 | { | |
411e1bfb | 8643 | h->plt.plist = NULL; |
f5385ebf | 8644 | h->needs_plt = 0; |
65f38f15 AM |
8645 | } |
8646 | ||
951fd09b AM |
8647 | eh = (struct ppc_link_hash_entry *) h; |
8648 | /* Run through the TLS GD got entries first if we're changing them | |
8649 | to TPREL. */ | |
e7b938ca | 8650 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
951fd09b AM |
8651 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
8652 | if (gent->got.refcount > 0 | |
8653 | && (gent->tls_type & TLS_GD) != 0) | |
8654 | { | |
8655 | /* This was a GD entry that has been converted to TPREL. If | |
8656 | there happens to be a TPREL entry we can use that one. */ | |
8657 | struct got_entry *ent; | |
8658 | for (ent = h->got.glist; ent != NULL; ent = ent->next) | |
8659 | if (ent->got.refcount > 0 | |
8660 | && (ent->tls_type & TLS_TPREL) != 0 | |
e717da7e AM |
8661 | && ent->addend == gent->addend |
8662 | && ent->owner == gent->owner) | |
951fd09b AM |
8663 | { |
8664 | gent->got.refcount = 0; | |
8665 | break; | |
8666 | } | |
8667 | ||
8668 | /* If not, then we'll be using our own TPREL entry. */ | |
8669 | if (gent->got.refcount != 0) | |
8670 | gent->tls_type = TLS_TLS | TLS_TPREL; | |
8671 | } | |
8672 | ||
7865406b AM |
8673 | /* Remove any list entry that won't generate a word in the GOT before |
8674 | we call merge_got_entries. Otherwise we risk merging to empty | |
8675 | entries. */ | |
0b8bcf0d AM |
8676 | pgent = &h->got.glist; |
8677 | while ((gent = *pgent) != NULL) | |
411e1bfb | 8678 | if (gent->got.refcount > 0) |
7865406b AM |
8679 | { |
8680 | if ((gent->tls_type & TLS_LD) != 0 | |
8681 | && !h->def_dynamic) | |
8682 | { | |
8683 | ppc64_tlsld_got (gent->owner)->got.refcount += 1; | |
8684 | *pgent = gent->next; | |
8685 | } | |
8686 | else | |
8687 | pgent = &gent->next; | |
8688 | } | |
8689 | else | |
8690 | *pgent = gent->next; | |
8691 | ||
8692 | if (!htab->do_multi_toc) | |
8693 | merge_got_entries (&h->got.glist); | |
8694 | ||
8695 | for (gent = h->got.glist; gent != NULL; gent = gent->next) | |
8696 | if (!gent->is_indirect) | |
411e1bfb AM |
8697 | { |
8698 | /* Make sure this symbol is output as a dynamic symbol. | |
951fd09b AM |
8699 | Undefined weak syms won't yet be marked as dynamic, |
8700 | nor will all TLS symbols. */ | |
411e1bfb | 8701 | if (h->dynindx == -1 |
b099ab9f | 8702 | && !h->forced_local |
25f23106 | 8703 | && h->type != STT_GNU_IFUNC |
b099ab9f | 8704 | && htab->elf.dynamic_sections_created) |
411e1bfb | 8705 | { |
c152c796 | 8706 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
411e1bfb AM |
8707 | return FALSE; |
8708 | } | |
65f38f15 | 8709 | |
0c8d6e5c | 8710 | if (!is_ppc64_elf (gent->owner)) |
927be08e | 8711 | abort (); |
0ffa91dd | 8712 | |
927be08e | 8713 | allocate_got (h, info, gent); |
411e1bfb | 8714 | } |
65f38f15 | 8715 | |
b099ab9f | 8716 | if (eh->dyn_relocs == NULL |
25f23106 AM |
8717 | || (!htab->elf.dynamic_sections_created |
8718 | && h->type != STT_GNU_IFUNC)) | |
b34976b6 | 8719 | return TRUE; |
65f38f15 AM |
8720 | |
8721 | /* In the shared -Bsymbolic case, discard space allocated for | |
8722 | dynamic pc-relative relocs against symbols which turn out to be | |
8723 | defined in regular objects. For the normal shared case, discard | |
8724 | space for relocs that have become local due to symbol visibility | |
8725 | changes. */ | |
8726 | ||
8727 | if (info->shared) | |
8728 | { | |
9c7a29a3 | 8729 | /* Relocs that use pc_count are those that appear on a call insn, |
1d483afe | 8730 | or certain REL relocs (see must_be_dyn_reloc) that can be |
9c7a29a3 AM |
8731 | generated via assembly. We want calls to protected symbols to |
8732 | resolve directly to the function rather than going via the plt. | |
8733 | If people want function pointer comparisons to work as expected | |
8734 | then they should avoid writing weird assembly. */ | |
09695f56 | 8735 | if (SYMBOL_CALLS_LOCAL (info, h)) |
65f38f15 | 8736 | { |
6061a67d | 8737 | struct elf_dyn_relocs **pp; |
65f38f15 AM |
8738 | |
8739 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 8740 | { |
65f38f15 AM |
8741 | p->count -= p->pc_count; |
8742 | p->pc_count = 0; | |
8743 | if (p->count == 0) | |
8744 | *pp = p->next; | |
8745 | else | |
8746 | pp = &p->next; | |
5bd4f169 | 8747 | } |
65f38f15 | 8748 | } |
4e795f50 AM |
8749 | |
8750 | /* Also discard relocs on undefined weak syms with non-default | |
8751 | visibility. */ | |
cab87ef9 AM |
8752 | if (eh->dyn_relocs != NULL |
8753 | && h->root.type == bfd_link_hash_undefweak) | |
dfbb6ac9 AM |
8754 | { |
8755 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
8756 | eh->dyn_relocs = NULL; | |
8757 | ||
8758 | /* Make sure this symbol is output as a dynamic symbol. | |
8759 | Undefined weak syms won't yet be marked as dynamic. */ | |
8760 | else if (h->dynindx == -1 | |
8761 | && !h->forced_local) | |
8762 | { | |
8763 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
8764 | return FALSE; | |
8765 | } | |
8766 | } | |
65f38f15 | 8767 | } |
25f23106 AM |
8768 | else if (h->type == STT_GNU_IFUNC) |
8769 | { | |
8770 | if (!h->non_got_ref) | |
8771 | eh->dyn_relocs = NULL; | |
8772 | } | |
f4656909 | 8773 | else if (ELIMINATE_COPY_RELOCS) |
65f38f15 AM |
8774 | { |
8775 | /* For the non-shared case, discard space for relocs against | |
8776 | symbols which turn out to need copy relocs or are not | |
8777 | dynamic. */ | |
8778 | ||
f5385ebf | 8779 | if (!h->non_got_ref |
f5385ebf | 8780 | && !h->def_regular) |
65f38f15 AM |
8781 | { |
8782 | /* Make sure this symbol is output as a dynamic symbol. | |
8783 | Undefined weak syms won't yet be marked as dynamic. */ | |
8784 | if (h->dynindx == -1 | |
f5385ebf | 8785 | && !h->forced_local) |
65f38f15 | 8786 | { |
c152c796 | 8787 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 8788 | return FALSE; |
65f38f15 AM |
8789 | } |
8790 | ||
8791 | /* If that succeeded, we know we'll be keeping all the | |
8792 | relocs. */ | |
8793 | if (h->dynindx != -1) | |
8794 | goto keep; | |
8795 | } | |
8796 | ||
8797 | eh->dyn_relocs = NULL; | |
8798 | ||
ec338859 | 8799 | keep: ; |
65f38f15 AM |
8800 | } |
8801 | ||
8802 | /* Finally, allocate space. */ | |
8803 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
8804 | { | |
8805 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
25f23106 AM |
8806 | if (!htab->elf.dynamic_sections_created) |
8807 | sreloc = htab->reliplt; | |
eea6121a | 8808 | sreloc->size += p->count * sizeof (Elf64_External_Rela); |
65f38f15 AM |
8809 | } |
8810 | ||
b34976b6 | 8811 | return TRUE; |
65f38f15 AM |
8812 | } |
8813 | ||
8814 | /* Find any dynamic relocs that apply to read-only sections. */ | |
8815 | ||
b34976b6 | 8816 | static bfd_boolean |
4ce794b7 | 8817 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
65f38f15 AM |
8818 | { |
8819 | struct ppc_link_hash_entry *eh; | |
6061a67d | 8820 | struct elf_dyn_relocs *p; |
65f38f15 AM |
8821 | |
8822 | eh = (struct ppc_link_hash_entry *) h; | |
8823 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
8824 | { | |
8825 | asection *s = p->sec->output_section; | |
8826 | ||
8827 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
8828 | { | |
4ce794b7 | 8829 | struct bfd_link_info *info = inf; |
65f38f15 AM |
8830 | |
8831 | info->flags |= DF_TEXTREL; | |
8832 | ||
8833 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 8834 | return FALSE; |
65f38f15 AM |
8835 | } |
8836 | } | |
b34976b6 | 8837 | return TRUE; |
65f38f15 AM |
8838 | } |
8839 | ||
8840 | /* Set the sizes of the dynamic sections. */ | |
8841 | ||
b34976b6 | 8842 | static bfd_boolean |
4ce794b7 AM |
8843 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
8844 | struct bfd_link_info *info) | |
65f38f15 AM |
8845 | { |
8846 | struct ppc_link_hash_table *htab; | |
8847 | bfd *dynobj; | |
8848 | asection *s; | |
b34976b6 | 8849 | bfd_boolean relocs; |
65f38f15 | 8850 | bfd *ibfd; |
7865406b | 8851 | struct got_entry *first_tlsld; |
65f38f15 AM |
8852 | |
8853 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
8854 | if (htab == NULL) |
8855 | return FALSE; | |
8856 | ||
65f38f15 AM |
8857 | dynobj = htab->elf.dynobj; |
8858 | if (dynobj == NULL) | |
8859 | abort (); | |
8860 | ||
8861 | if (htab->elf.dynamic_sections_created) | |
8862 | { | |
8863 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 8864 | if (info->executable) |
65f38f15 AM |
8865 | { |
8866 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
8867 | if (s == NULL) | |
8868 | abort (); | |
eea6121a | 8869 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
65f38f15 AM |
8870 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
8871 | } | |
8872 | } | |
8873 | ||
8874 | /* Set up .got offsets for local syms, and space for local dynamic | |
8875 | relocs. */ | |
8876 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
8877 | { | |
411e1bfb AM |
8878 | struct got_entry **lgot_ents; |
8879 | struct got_entry **end_lgot_ents; | |
e054468f AM |
8880 | struct plt_entry **local_plt; |
8881 | struct plt_entry **end_local_plt; | |
f961d9dd | 8882 | unsigned char *lgot_masks; |
65f38f15 AM |
8883 | bfd_size_type locsymcount; |
8884 | Elf_Internal_Shdr *symtab_hdr; | |
8885 | asection *srel; | |
8886 | ||
0c8d6e5c | 8887 | if (!is_ppc64_elf (ibfd)) |
65f38f15 AM |
8888 | continue; |
8889 | ||
8890 | for (s = ibfd->sections; s != NULL; s = s->next) | |
8891 | { | |
6061a67d | 8892 | struct elf_dyn_relocs *p; |
65f38f15 | 8893 | |
6edfbbad | 8894 | for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) |
65f38f15 | 8895 | { |
ec338859 AM |
8896 | if (!bfd_is_abs_section (p->sec) |
8897 | && bfd_is_abs_section (p->sec->output_section)) | |
8898 | { | |
8899 | /* Input section has been discarded, either because | |
8900 | it is a copy of a linkonce section or due to | |
8901 | linker script /DISCARD/, so we'll be discarding | |
8902 | the relocs too. */ | |
8903 | } | |
248866a8 | 8904 | else if (p->count != 0) |
ec338859 AM |
8905 | { |
8906 | srel = elf_section_data (p->sec)->sreloc; | |
25f23106 AM |
8907 | if (!htab->elf.dynamic_sections_created) |
8908 | srel = htab->reliplt; | |
eea6121a | 8909 | srel->size += p->count * sizeof (Elf64_External_Rela); |
248866a8 AM |
8910 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
8911 | info->flags |= DF_TEXTREL; | |
ec338859 | 8912 | } |
65f38f15 AM |
8913 | } |
8914 | } | |
8915 | ||
411e1bfb AM |
8916 | lgot_ents = elf_local_got_ents (ibfd); |
8917 | if (!lgot_ents) | |
65f38f15 AM |
8918 | continue; |
8919 | ||
0ffa91dd | 8920 | symtab_hdr = &elf_symtab_hdr (ibfd); |
65f38f15 | 8921 | locsymcount = symtab_hdr->sh_info; |
411e1bfb | 8922 | end_lgot_ents = lgot_ents + locsymcount; |
e054468f AM |
8923 | local_plt = (struct plt_entry **) end_lgot_ents; |
8924 | end_local_plt = local_plt + locsymcount; | |
f961d9dd | 8925 | lgot_masks = (unsigned char *) end_local_plt; |
e717da7e AM |
8926 | s = ppc64_elf_tdata (ibfd)->got; |
8927 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
e7b938ca | 8928 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
65f38f15 | 8929 | { |
0b8bcf0d | 8930 | struct got_entry **pent, *ent; |
411e1bfb | 8931 | |
0b8bcf0d AM |
8932 | pent = lgot_ents; |
8933 | while ((ent = *pent) != NULL) | |
411e1bfb AM |
8934 | if (ent->got.refcount > 0) |
8935 | { | |
e7b938ca | 8936 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
411e1bfb | 8937 | { |
927be08e | 8938 | ppc64_tlsld_got (ibfd)->got.refcount += 1; |
0b8bcf0d | 8939 | *pent = ent->next; |
411e1bfb AM |
8940 | } |
8941 | else | |
8942 | { | |
25f23106 | 8943 | unsigned int num = 1; |
eea6121a | 8944 | ent->got.offset = s->size; |
e7b938ca | 8945 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
25f23106 AM |
8946 | num = 2; |
8947 | s->size += num * 8; | |
8948 | if (info->shared) | |
8949 | srel->size += num * sizeof (Elf64_External_Rela); | |
8950 | else if ((*lgot_masks & PLT_IFUNC) != 0) | |
927be08e AM |
8951 | { |
8952 | htab->reliplt->size | |
8953 | += num * sizeof (Elf64_External_Rela); | |
8954 | htab->got_reli_size | |
8955 | += num * sizeof (Elf64_External_Rela); | |
8956 | } | |
0b8bcf0d | 8957 | pent = &ent->next; |
411e1bfb AM |
8958 | } |
8959 | } | |
8960 | else | |
0b8bcf0d | 8961 | *pent = ent->next; |
65f38f15 | 8962 | } |
e054468f AM |
8963 | |
8964 | /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */ | |
8965 | for (; local_plt < end_local_plt; ++local_plt) | |
8966 | { | |
8967 | struct plt_entry *ent; | |
8968 | ||
8969 | for (ent = *local_plt; ent != NULL; ent = ent->next) | |
8970 | if (ent->plt.refcount > 0) | |
8971 | { | |
91d6fa6a | 8972 | s = htab->iplt; |
e054468f AM |
8973 | ent->plt.offset = s->size; |
8974 | s->size += PLT_ENTRY_SIZE; | |
8975 | ||
25f23106 | 8976 | htab->reliplt->size += sizeof (Elf64_External_Rela); |
e054468f AM |
8977 | } |
8978 | else | |
8979 | ent->plt.offset = (bfd_vma) -1; | |
8980 | } | |
65f38f15 AM |
8981 | } |
8982 | ||
8983 | /* Allocate global sym .plt and .got entries, and space for global | |
8984 | sym dynamic relocs. */ | |
4ce794b7 | 8985 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
65f38f15 | 8986 | |
7865406b | 8987 | first_tlsld = NULL; |
102890f0 AM |
8988 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
8989 | { | |
7865406b AM |
8990 | struct got_entry *ent; |
8991 | ||
0c8d6e5c | 8992 | if (!is_ppc64_elf (ibfd)) |
102890f0 AM |
8993 | continue; |
8994 | ||
7865406b AM |
8995 | ent = ppc64_tlsld_got (ibfd); |
8996 | if (ent->got.refcount > 0) | |
102890f0 | 8997 | { |
7865406b | 8998 | if (!htab->do_multi_toc && first_tlsld != NULL) |
102890f0 | 8999 | { |
7865406b AM |
9000 | ent->is_indirect = TRUE; |
9001 | ent->got.ent = first_tlsld; | |
9002 | } | |
9003 | else | |
9004 | { | |
9005 | if (first_tlsld == NULL) | |
9006 | first_tlsld = ent; | |
9007 | s = ppc64_elf_tdata (ibfd)->got; | |
9008 | ent->got.offset = s->size; | |
9009 | ent->owner = ibfd; | |
9010 | s->size += 16; | |
9011 | if (info->shared) | |
9012 | { | |
9013 | asection *srel = ppc64_elf_tdata (ibfd)->relgot; | |
9014 | srel->size += sizeof (Elf64_External_Rela); | |
9015 | } | |
102890f0 AM |
9016 | } |
9017 | } | |
9018 | else | |
7865406b | 9019 | ent->got.offset = (bfd_vma) -1; |
102890f0 AM |
9020 | } |
9021 | ||
65f38f15 AM |
9022 | /* We now have determined the sizes of the various dynamic sections. |
9023 | Allocate memory for them. */ | |
b34976b6 | 9024 | relocs = FALSE; |
65f38f15 AM |
9025 | for (s = dynobj->sections; s != NULL; s = s->next) |
9026 | { | |
9027 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
9028 | continue; | |
9029 | ||
4ce794b7 | 9030 | if (s == htab->brlt || s == htab->relbrlt) |
721956f4 AM |
9031 | /* These haven't been allocated yet; don't strip. */ |
9032 | continue; | |
e717da7e AM |
9033 | else if (s == htab->got |
9034 | || s == htab->plt | |
e054468f | 9035 | || s == htab->iplt |
c456f082 AM |
9036 | || s == htab->glink |
9037 | || s == htab->dynbss) | |
65f38f15 AM |
9038 | { |
9039 | /* Strip this section if we don't need it; see the | |
9040 | comment below. */ | |
5bd4f169 | 9041 | } |
58d180e8 AM |
9042 | else if (s == htab->glink_eh_frame) |
9043 | { | |
9044 | if (!bfd_is_abs_section (s->output_section)) | |
9045 | /* Not sized yet. */ | |
9046 | continue; | |
9047 | } | |
70cc837d | 9048 | else if (CONST_STRNEQ (s->name, ".rela")) |
5bd4f169 | 9049 | { |
c456f082 | 9050 | if (s->size != 0) |
5bd4f169 | 9051 | { |
4ce794b7 | 9052 | if (s != htab->relplt) |
b34976b6 | 9053 | relocs = TRUE; |
5bd4f169 AM |
9054 | |
9055 | /* We use the reloc_count field as a counter if we need | |
9056 | to copy relocs into the output file. */ | |
9057 | s->reloc_count = 0; | |
9058 | } | |
9059 | } | |
65f38f15 | 9060 | else |
5bd4f169 AM |
9061 | { |
9062 | /* It's not one of our sections, so don't allocate space. */ | |
9063 | continue; | |
9064 | } | |
9065 | ||
eea6121a | 9066 | if (s->size == 0) |
5bd4f169 | 9067 | { |
c456f082 AM |
9068 | /* If we don't need this section, strip it from the |
9069 | output file. This is mostly to handle .rela.bss and | |
9070 | .rela.plt. We must create both sections in | |
9071 | create_dynamic_sections, because they must be created | |
9072 | before the linker maps input sections to output | |
9073 | sections. The linker does that before | |
9074 | adjust_dynamic_symbol is called, and it is that | |
9075 | function which decides whether anything needs to go | |
9076 | into these sections. */ | |
8423293d | 9077 | s->flags |= SEC_EXCLUDE; |
5bd4f169 AM |
9078 | continue; |
9079 | } | |
9080 | ||
c456f082 | 9081 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
5f333394 AM |
9082 | continue; |
9083 | ||
65f38f15 AM |
9084 | /* Allocate memory for the section contents. We use bfd_zalloc |
9085 | here in case unused entries are not reclaimed before the | |
9086 | section's contents are written out. This should not happen, | |
411e1bfb AM |
9087 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
9088 | sections instead of garbage. | |
9089 | We also rely on the section contents being zero when writing | |
9090 | the GOT. */ | |
eea6121a | 9091 | s->contents = bfd_zalloc (dynobj, s->size); |
65f38f15 | 9092 | if (s->contents == NULL) |
b34976b6 | 9093 | return FALSE; |
5bd4f169 AM |
9094 | } |
9095 | ||
e717da7e AM |
9096 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
9097 | { | |
0c8d6e5c | 9098 | if (!is_ppc64_elf (ibfd)) |
7b53ace3 AM |
9099 | continue; |
9100 | ||
e717da7e AM |
9101 | s = ppc64_elf_tdata (ibfd)->got; |
9102 | if (s != NULL && s != htab->got) | |
9103 | { | |
eea6121a | 9104 | if (s->size == 0) |
8423293d | 9105 | s->flags |= SEC_EXCLUDE; |
e717da7e AM |
9106 | else |
9107 | { | |
eea6121a | 9108 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
9109 | if (s->contents == NULL) |
9110 | return FALSE; | |
9111 | } | |
9112 | } | |
9113 | s = ppc64_elf_tdata (ibfd)->relgot; | |
9114 | if (s != NULL) | |
9115 | { | |
eea6121a | 9116 | if (s->size == 0) |
8423293d | 9117 | s->flags |= SEC_EXCLUDE; |
e717da7e AM |
9118 | else |
9119 | { | |
eea6121a | 9120 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
9121 | if (s->contents == NULL) |
9122 | return FALSE; | |
9123 | relocs = TRUE; | |
9124 | s->reloc_count = 0; | |
9125 | } | |
9126 | } | |
9127 | } | |
9128 | ||
e86ce104 | 9129 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
9130 | { |
9131 | /* Add some entries to the .dynamic section. We fill in the | |
9132 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
9133 | must add the entries now so that we get the correct size for | |
9134 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
9135 | dynamic linker and used by the debugger. */ | |
dc810e39 | 9136 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 9137 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 9138 | |
36af4a4e | 9139 | if (info->executable) |
5bd4f169 | 9140 | { |
dc810e39 | 9141 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 9142 | return FALSE; |
5bd4f169 AM |
9143 | } |
9144 | ||
eea6121a | 9145 | if (htab->plt != NULL && htab->plt->size != 0) |
5bd4f169 | 9146 | { |
dc810e39 AM |
9147 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
9148 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
9149 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
9150 | || !add_dynamic_entry (DT_JMPREL, 0) |
9151 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 9152 | return FALSE; |
5bd4f169 AM |
9153 | } |
9154 | ||
19397422 AM |
9155 | if (NO_OPD_RELOCS) |
9156 | { | |
9157 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
9158 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 9159 | return FALSE; |
19397422 AM |
9160 | } |
9161 | ||
a7f2871e AM |
9162 | if (!htab->no_tls_get_addr_opt |
9163 | && htab->tls_get_addr_fd != NULL | |
9164 | && htab->tls_get_addr_fd->elf.plt.plist != NULL | |
9165 | && !add_dynamic_entry (DT_PPC64_TLSOPT, 0)) | |
9166 | return FALSE; | |
9167 | ||
5bd4f169 AM |
9168 | if (relocs) |
9169 | { | |
dc810e39 AM |
9170 | if (!add_dynamic_entry (DT_RELA, 0) |
9171 | || !add_dynamic_entry (DT_RELASZ, 0) | |
9172 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 9173 | return FALSE; |
5bd4f169 | 9174 | |
65f38f15 AM |
9175 | /* If any dynamic relocs apply to a read-only section, |
9176 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 9177 | if ((info->flags & DF_TEXTREL) == 0) |
4ce794b7 | 9178 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
5bd4f169 | 9179 | |
65f38f15 | 9180 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 9181 | { |
65f38f15 | 9182 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 9183 | return FALSE; |
5bd4f169 | 9184 | } |
5bd4f169 | 9185 | } |
5bd4f169 | 9186 | } |
65f38f15 | 9187 | #undef add_dynamic_entry |
5bd4f169 | 9188 | |
b34976b6 | 9189 | return TRUE; |
5bd4f169 AM |
9190 | } |
9191 | ||
721956f4 | 9192 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 9193 | |
4ce794b7 AM |
9194 | static inline enum ppc_stub_type |
9195 | ppc_type_of_stub (asection *input_sec, | |
9196 | const Elf_Internal_Rela *rel, | |
9197 | struct ppc_link_hash_entry **hash, | |
e054468f | 9198 | struct plt_entry **plt_ent, |
4ce794b7 | 9199 | bfd_vma destination) |
5bd4f169 | 9200 | { |
721956f4 AM |
9201 | struct ppc_link_hash_entry *h = *hash; |
9202 | bfd_vma location; | |
9203 | bfd_vma branch_offset; | |
9204 | bfd_vma max_branch_offset; | |
4ce794b7 | 9205 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 | 9206 | |
721956f4 AM |
9207 | if (h != NULL) |
9208 | { | |
e054468f | 9209 | struct plt_entry *ent; |
7fe2b9a6 | 9210 | struct ppc_link_hash_entry *fdh = h; |
b31867b6 AM |
9211 | if (h->oh != NULL |
9212 | && h->oh->is_func_descriptor) | |
7b8f6675 AM |
9213 | { |
9214 | fdh = ppc_follow_link (h->oh); | |
9215 | *hash = fdh; | |
9216 | } | |
8387904d | 9217 | |
e054468f AM |
9218 | for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next) |
9219 | if (ent->addend == rel->r_addend | |
9220 | && ent->plt.offset != (bfd_vma) -1) | |
9221 | { | |
e054468f AM |
9222 | *plt_ent = ent; |
9223 | return ppc_stub_plt_call; | |
9224 | } | |
5bd4f169 | 9225 | |
7fe2b9a6 AM |
9226 | /* Here, we know we don't have a plt entry. If we don't have a |
9227 | either a defined function descriptor or a defined entry symbol | |
9228 | in a regular object file, then it is pointless trying to make | |
9229 | any other type of stub. */ | |
854b41e7 AM |
9230 | if (!is_static_defined (&fdh->elf) |
9231 | && !is_static_defined (&h->elf)) | |
721956f4 | 9232 | return ppc_stub_none; |
5d1634d7 | 9233 | } |
e054468f AM |
9234 | else if (elf_local_got_ents (input_sec->owner) != NULL) |
9235 | { | |
9236 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_sec->owner); | |
9237 | struct plt_entry **local_plt = (struct plt_entry **) | |
9238 | elf_local_got_ents (input_sec->owner) + symtab_hdr->sh_info; | |
9239 | unsigned long r_symndx = ELF64_R_SYM (rel->r_info); | |
9240 | ||
9241 | if (local_plt[r_symndx] != NULL) | |
9242 | { | |
9243 | struct plt_entry *ent; | |
9244 | ||
9245 | for (ent = local_plt[r_symndx]; ent != NULL; ent = ent->next) | |
9246 | if (ent->addend == rel->r_addend | |
9247 | && ent->plt.offset != (bfd_vma) -1) | |
9248 | { | |
9249 | *plt_ent = ent; | |
9250 | return ppc_stub_plt_call; | |
9251 | } | |
9252 | } | |
9253 | } | |
5d1634d7 | 9254 | |
721956f4 AM |
9255 | /* Determine where the call point is. */ |
9256 | location = (input_sec->output_offset | |
9257 | + input_sec->output_section->vma | |
9258 | + rel->r_offset); | |
5d1634d7 | 9259 | |
721956f4 AM |
9260 | branch_offset = destination - location; |
9261 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 9262 | |
721956f4 AM |
9263 | /* Determine if a long branch stub is needed. */ |
9264 | max_branch_offset = 1 << 25; | |
4ce794b7 | 9265 | if (r_type != R_PPC64_REL24) |
721956f4 | 9266 | max_branch_offset = 1 << 15; |
5d1634d7 | 9267 | |
721956f4 AM |
9268 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
9269 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
9270 | is needed later. */ | |
9271 | return ppc_stub_long_branch; | |
5d1634d7 | 9272 | |
721956f4 | 9273 | return ppc_stub_none; |
5d1634d7 AM |
9274 | } |
9275 | ||
9276 | /* Build a .plt call stub. */ | |
9277 | ||
4ce794b7 | 9278 | static inline bfd_byte * |
9df0ef5f AM |
9279 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset, Elf_Internal_Rela *r, |
9280 | bfd_boolean plt_static_chain) | |
5d1634d7 AM |
9281 | { |
9282 | #define PPC_LO(v) ((v) & 0xffff) | |
9283 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
9284 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
9285 | ||
ac2df442 AM |
9286 | if (PPC_HA (offset) != 0) |
9287 | { | |
176a0d42 AM |
9288 | if (r != NULL) |
9289 | { | |
9290 | r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA); | |
9291 | r[1].r_offset = r[0].r_offset + 8; | |
9292 | r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS); | |
9293 | r[1].r_addend = r[0].r_addend; | |
c7131b65 | 9294 | if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset)) |
176a0d42 AM |
9295 | { |
9296 | r[2].r_offset = r[1].r_offset + 4; | |
9297 | r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO); | |
9298 | r[2].r_addend = r[0].r_addend; | |
9299 | } | |
9300 | else | |
9301 | { | |
9302 | r[2].r_offset = r[1].r_offset + 8; | |
9303 | r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS); | |
9304 | r[2].r_addend = r[0].r_addend + 8; | |
c7131b65 AM |
9305 | if (plt_static_chain) |
9306 | { | |
9307 | r[3].r_offset = r[2].r_offset + 4; | |
9308 | r[3].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS); | |
9309 | r[3].r_addend = r[0].r_addend + 16; | |
9310 | } | |
176a0d42 AM |
9311 | } |
9312 | } | |
ac2df442 AM |
9313 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
9314 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; | |
9315 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
9df0ef5f | 9316 | if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset)) |
ac2df442 AM |
9317 | { |
9318 | bfd_put_32 (obfd, ADDI_R12_R12 | PPC_LO (offset), p), p += 4; | |
9319 | offset = 0; | |
9320 | } | |
9321 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
9322 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset + 8), p), p += 4; | |
9df0ef5f AM |
9323 | if (plt_static_chain) |
9324 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset + 16), p), p += 4; | |
ac2df442 AM |
9325 | bfd_put_32 (obfd, BCTR, p), p += 4; |
9326 | } | |
9327 | else | |
9328 | { | |
176a0d42 AM |
9329 | if (r != NULL) |
9330 | { | |
9331 | r[0].r_offset += 4; | |
9332 | r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS); | |
c7131b65 | 9333 | if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset)) |
176a0d42 AM |
9334 | { |
9335 | r[1].r_offset = r[0].r_offset + 4; | |
9336 | r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16); | |
9337 | r[1].r_addend = r[0].r_addend; | |
9338 | } | |
9339 | else | |
9340 | { | |
9341 | r[1].r_offset = r[0].r_offset + 8; | |
9342 | r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS); | |
c7131b65 AM |
9343 | r[1].r_addend = r[0].r_addend + 8 + 8 * plt_static_chain; |
9344 | if (plt_static_chain) | |
9345 | { | |
9346 | r[2].r_offset = r[1].r_offset + 4; | |
9347 | r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS); | |
9348 | r[2].r_addend = r[0].r_addend + 8; | |
9349 | } | |
176a0d42 AM |
9350 | } |
9351 | } | |
ac2df442 AM |
9352 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
9353 | bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset), p), p += 4; | |
9df0ef5f | 9354 | if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset)) |
ac2df442 AM |
9355 | { |
9356 | bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p), p += 4; | |
9357 | offset = 0; | |
9358 | } | |
9359 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
9df0ef5f AM |
9360 | if (plt_static_chain) |
9361 | bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset + 16), p), p += 4; | |
ac2df442 AM |
9362 | bfd_put_32 (obfd, LD_R2_0R2 | PPC_LO (offset + 8), p), p += 4; |
9363 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
9364 | } | |
5d1634d7 AM |
9365 | return p; |
9366 | } | |
9367 | ||
a7f2871e AM |
9368 | /* Build a special .plt call stub for __tls_get_addr. */ |
9369 | ||
9370 | #define LD_R11_0R3 0xe9630000 | |
9371 | #define LD_R12_0R3 0xe9830000 | |
9372 | #define MR_R0_R3 0x7c601b78 | |
9373 | #define CMPDI_R11_0 0x2c2b0000 | |
9374 | #define ADD_R3_R12_R13 0x7c6c6a14 | |
9375 | #define BEQLR 0x4d820020 | |
9376 | #define MR_R3_R0 0x7c030378 | |
9377 | #define MFLR_R11 0x7d6802a6 | |
9378 | #define STD_R11_0R1 0xf9610000 | |
9379 | #define BCTRL 0x4e800421 | |
9380 | #define LD_R11_0R1 0xe9610000 | |
9381 | #define LD_R2_0R1 0xe8410000 | |
9382 | #define MTLR_R11 0x7d6803a6 | |
9383 | ||
9384 | static inline bfd_byte * | |
9385 | build_tls_get_addr_stub (bfd *obfd, bfd_byte *p, int offset, | |
9df0ef5f | 9386 | Elf_Internal_Rela *r, bfd_boolean plt_static_chain) |
a7f2871e AM |
9387 | { |
9388 | bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4; | |
9389 | bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4; | |
9390 | bfd_put_32 (obfd, MR_R0_R3, p), p += 4; | |
9391 | bfd_put_32 (obfd, CMPDI_R11_0, p), p += 4; | |
9392 | bfd_put_32 (obfd, ADD_R3_R12_R13, p), p += 4; | |
9393 | bfd_put_32 (obfd, BEQLR, p), p += 4; | |
9394 | bfd_put_32 (obfd, MR_R3_R0, p), p += 4; | |
9395 | bfd_put_32 (obfd, MFLR_R11, p), p += 4; | |
9396 | bfd_put_32 (obfd, STD_R11_0R1 + 32, p), p += 4; | |
9397 | ||
9398 | if (r != NULL) | |
9399 | r[0].r_offset += 9 * 4; | |
9df0ef5f | 9400 | p = build_plt_stub (obfd, p, offset, r, plt_static_chain); |
a7f2871e AM |
9401 | bfd_put_32 (obfd, BCTRL, p - 4); |
9402 | ||
9403 | bfd_put_32 (obfd, LD_R11_0R1 + 32, p), p += 4; | |
9404 | bfd_put_32 (obfd, LD_R2_0R1 + 40, p), p += 4; | |
9405 | bfd_put_32 (obfd, MTLR_R11, p), p += 4; | |
9406 | bfd_put_32 (obfd, BLR, p), p += 4; | |
9407 | ||
9408 | return p; | |
9409 | } | |
9410 | ||
176a0d42 AM |
9411 | static Elf_Internal_Rela * |
9412 | get_relocs (asection *sec, int count) | |
9413 | { | |
9414 | Elf_Internal_Rela *relocs; | |
9415 | struct bfd_elf_section_data *elfsec_data; | |
9416 | ||
9417 | elfsec_data = elf_section_data (sec); | |
9418 | relocs = elfsec_data->relocs; | |
9419 | if (relocs == NULL) | |
9420 | { | |
9421 | bfd_size_type relsize; | |
9422 | relsize = sec->reloc_count * sizeof (*relocs); | |
9423 | relocs = bfd_alloc (sec->owner, relsize); | |
9424 | if (relocs == NULL) | |
9425 | return NULL; | |
9426 | elfsec_data->relocs = relocs; | |
d4730f92 BS |
9427 | elfsec_data->rela.hdr = bfd_zalloc (sec->owner, |
9428 | sizeof (Elf_Internal_Shdr)); | |
9429 | if (elfsec_data->rela.hdr == NULL) | |
9430 | return NULL; | |
9431 | elfsec_data->rela.hdr->sh_size = (sec->reloc_count | |
9432 | * sizeof (Elf64_External_Rela)); | |
9433 | elfsec_data->rela.hdr->sh_entsize = sizeof (Elf64_External_Rela); | |
176a0d42 AM |
9434 | sec->reloc_count = 0; |
9435 | } | |
9436 | relocs += sec->reloc_count; | |
9437 | sec->reloc_count += count; | |
9438 | return relocs; | |
9439 | } | |
9440 | ||
aa374f67 | 9441 | static bfd_vma |
25f53a85 | 9442 | get_r2off (struct bfd_link_info *info, |
aa374f67 AM |
9443 | struct ppc_stub_hash_entry *stub_entry) |
9444 | { | |
25f53a85 | 9445 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
aa374f67 AM |
9446 | bfd_vma r2off = htab->stub_group[stub_entry->target_section->id].toc_off; |
9447 | ||
9448 | if (r2off == 0) | |
9449 | { | |
9450 | /* Support linking -R objects. Get the toc pointer from the | |
9451 | opd entry. */ | |
9452 | char buf[8]; | |
9453 | asection *opd = stub_entry->h->elf.root.u.def.section; | |
9454 | bfd_vma opd_off = stub_entry->h->elf.root.u.def.value; | |
9455 | ||
9456 | if (strcmp (opd->name, ".opd") != 0 | |
9457 | || opd->reloc_count != 0) | |
9458 | { | |
25f53a85 AM |
9459 | info->callbacks->einfo (_("cannot find opd entry toc for %s\n"), |
9460 | stub_entry->h->elf.root.root.string); | |
aa374f67 AM |
9461 | bfd_set_error (bfd_error_bad_value); |
9462 | return 0; | |
9463 | } | |
9464 | if (!bfd_get_section_contents (opd->owner, opd, buf, opd_off + 8, 8)) | |
9465 | return 0; | |
9466 | r2off = bfd_get_64 (opd->owner, buf); | |
25f53a85 | 9467 | r2off -= elf_gp (info->output_bfd); |
aa374f67 AM |
9468 | } |
9469 | r2off -= htab->stub_group[stub_entry->id_sec->id].toc_off; | |
9470 | return r2off; | |
9471 | } | |
9472 | ||
b34976b6 | 9473 | static bfd_boolean |
4ce794b7 | 9474 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
5d1634d7 | 9475 | { |
721956f4 AM |
9476 | struct ppc_stub_hash_entry *stub_entry; |
9477 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
9478 | struct bfd_link_info *info; |
9479 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
9480 | bfd_byte *loc; |
9481 | bfd_byte *p; | |
ee75fd95 | 9482 | bfd_vma dest, off; |
721956f4 | 9483 | int size; |
176a0d42 | 9484 | Elf_Internal_Rela *r; |
e054468f | 9485 | asection *plt; |
5d1634d7 | 9486 | |
721956f4 AM |
9487 | /* Massage our args to the form they really have. */ |
9488 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 9489 | info = in_arg; |
5d1634d7 | 9490 | |
5d1634d7 | 9491 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
9492 | if (htab == NULL) |
9493 | return FALSE; | |
5d1634d7 | 9494 | |
721956f4 | 9495 | /* Make a note of the offset within the stubs for this entry. */ |
eea6121a | 9496 | stub_entry->stub_offset = stub_entry->stub_sec->size; |
97b639ba | 9497 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; |
721956f4 | 9498 | |
4ce794b7 | 9499 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
721956f4 | 9500 | switch (stub_entry->stub_type) |
5d1634d7 | 9501 | { |
721956f4 | 9502 | case ppc_stub_long_branch: |
ad8e1ba5 | 9503 | case ppc_stub_long_branch_r2off: |
721956f4 | 9504 | /* Branches are relative. This is where we are going to. */ |
ee75fd95 AM |
9505 | off = dest = (stub_entry->target_value |
9506 | + stub_entry->target_section->output_offset | |
9507 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 9508 | |
721956f4 AM |
9509 | /* And this is where we are coming from. */ |
9510 | off -= (stub_entry->stub_offset | |
97b639ba AM |
9511 | + stub_entry->stub_sec->output_offset |
9512 | + stub_entry->stub_sec->output_section->vma); | |
e86ce104 | 9513 | |
ac2df442 AM |
9514 | size = 4; |
9515 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
ad8e1ba5 | 9516 | { |
25f53a85 | 9517 | bfd_vma r2off = get_r2off (info, stub_entry); |
ad8e1ba5 | 9518 | |
aa374f67 AM |
9519 | if (r2off == 0) |
9520 | { | |
9521 | htab->stub_error = TRUE; | |
9522 | return FALSE; | |
9523 | } | |
97b639ba | 9524 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 9525 | loc += 4; |
ac2df442 AM |
9526 | size = 12; |
9527 | if (PPC_HA (r2off) != 0) | |
9528 | { | |
9529 | size = 16; | |
9530 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); | |
9531 | loc += 4; | |
9532 | } | |
97b639ba | 9533 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 | 9534 | loc += 4; |
ac2df442 | 9535 | off -= size - 4; |
ad8e1ba5 | 9536 | } |
97b639ba | 9537 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
ad8e1ba5 | 9538 | |
5c3dead3 AM |
9539 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
9540 | { | |
25f53a85 AM |
9541 | info->callbacks->einfo (_("long branch stub `%s' offset overflow\n"), |
9542 | stub_entry->root.string); | |
5c3dead3 AM |
9543 | htab->stub_error = TRUE; |
9544 | return FALSE; | |
9545 | } | |
ee75fd95 AM |
9546 | |
9547 | if (info->emitrelocations) | |
9548 | { | |
176a0d42 AM |
9549 | r = get_relocs (stub_entry->stub_sec, 1); |
9550 | if (r == NULL) | |
9551 | return FALSE; | |
ee75fd95 AM |
9552 | r->r_offset = loc - stub_entry->stub_sec->contents; |
9553 | r->r_info = ELF64_R_INFO (0, R_PPC64_REL24); | |
9554 | r->r_addend = dest; | |
9555 | if (stub_entry->h != NULL) | |
9556 | { | |
9557 | struct elf_link_hash_entry **hashes; | |
9558 | unsigned long symndx; | |
9559 | struct ppc_link_hash_entry *h; | |
9560 | ||
9561 | hashes = elf_sym_hashes (htab->stub_bfd); | |
9562 | if (hashes == NULL) | |
9563 | { | |
9564 | bfd_size_type hsize; | |
9565 | ||
9566 | hsize = (htab->stub_globals + 1) * sizeof (*hashes); | |
9567 | hashes = bfd_zalloc (htab->stub_bfd, hsize); | |
9568 | if (hashes == NULL) | |
9569 | return FALSE; | |
9570 | elf_sym_hashes (htab->stub_bfd) = hashes; | |
9571 | htab->stub_globals = 1; | |
9572 | } | |
9573 | symndx = htab->stub_globals++; | |
9574 | h = stub_entry->h; | |
9575 | hashes[symndx] = &h->elf; | |
9576 | r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24); | |
9577 | if (h->oh != NULL && h->oh->is_func) | |
b31867b6 | 9578 | h = ppc_follow_link (h->oh); |
ee75fd95 AM |
9579 | if (h->elf.root.u.def.section != stub_entry->target_section) |
9580 | /* H is an opd symbol. The addend must be zero. */ | |
9581 | r->r_addend = 0; | |
9582 | else | |
9583 | { | |
9584 | off = (h->elf.root.u.def.value | |
9585 | + h->elf.root.u.def.section->output_offset | |
9586 | + h->elf.root.u.def.section->output_section->vma); | |
9587 | r->r_addend -= off; | |
9588 | } | |
9589 | } | |
9590 | } | |
721956f4 | 9591 | break; |
e86ce104 | 9592 | |
721956f4 | 9593 | case ppc_stub_plt_branch: |
ad8e1ba5 | 9594 | case ppc_stub_plt_branch_r2off: |
721956f4 AM |
9595 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
9596 | stub_entry->root.string + 9, | |
b34976b6 | 9597 | FALSE, FALSE); |
721956f4 AM |
9598 | if (br_entry == NULL) |
9599 | { | |
25f53a85 AM |
9600 | info->callbacks->einfo (_("can't find branch stub `%s'\n"), |
9601 | stub_entry->root.string); | |
b34976b6 AM |
9602 | htab->stub_error = TRUE; |
9603 | return FALSE; | |
721956f4 AM |
9604 | } |
9605 | ||
176a0d42 AM |
9606 | dest = (stub_entry->target_value |
9607 | + stub_entry->target_section->output_offset | |
9608 | + stub_entry->target_section->output_section->vma); | |
721956f4 | 9609 | |
176a0d42 | 9610 | bfd_put_64 (htab->brlt->owner, dest, |
4ce794b7 | 9611 | htab->brlt->contents + br_entry->offset); |
721956f4 | 9612 | |
f94498ff | 9613 | if (br_entry->iter == htab->stub_iteration) |
721956f4 | 9614 | { |
f94498ff | 9615 | br_entry->iter = 0; |
84f5d08e | 9616 | |
f94498ff | 9617 | if (htab->relbrlt != NULL) |
84f5d08e | 9618 | { |
f94498ff AM |
9619 | /* Create a reloc for the branch lookup table entry. */ |
9620 | Elf_Internal_Rela rela; | |
9621 | bfd_byte *rl; | |
9622 | ||
9623 | rela.r_offset = (br_entry->offset | |
9624 | + htab->brlt->output_offset | |
9625 | + htab->brlt->output_section->vma); | |
9626 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
176a0d42 | 9627 | rela.r_addend = dest; |
f94498ff AM |
9628 | |
9629 | rl = htab->relbrlt->contents; | |
9630 | rl += (htab->relbrlt->reloc_count++ | |
9631 | * sizeof (Elf64_External_Rela)); | |
9632 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); | |
9633 | } | |
9634 | else if (info->emitrelocations) | |
9635 | { | |
176a0d42 AM |
9636 | r = get_relocs (htab->brlt, 1); |
9637 | if (r == NULL) | |
9638 | return FALSE; | |
9639 | /* brlt, being SEC_LINKER_CREATED does not go through the | |
9640 | normal reloc processing. Symbols and offsets are not | |
9641 | translated from input file to output file form, so | |
9642 | set up the offset per the output file. */ | |
f94498ff AM |
9643 | r->r_offset = (br_entry->offset |
9644 | + htab->brlt->output_offset | |
9645 | + htab->brlt->output_section->vma); | |
9646 | r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
176a0d42 | 9647 | r->r_addend = dest; |
84f5d08e | 9648 | } |
84f5d08e | 9649 | } |
721956f4 | 9650 | |
176a0d42 AM |
9651 | dest = (br_entry->offset |
9652 | + htab->brlt->output_offset | |
9653 | + htab->brlt->output_section->vma); | |
9654 | ||
9655 | off = (dest | |
4ce794b7 | 9656 | - elf_gp (htab->brlt->output_section->owner) |
ad8e1ba5 | 9657 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 9658 | |
ad8e1ba5 | 9659 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
5d1634d7 | 9660 | { |
25f53a85 AM |
9661 | info->callbacks->einfo |
9662 | (_("linkage table error against `%s'\n"), | |
721956f4 | 9663 | stub_entry->root.string); |
5d1634d7 | 9664 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
9665 | htab->stub_error = TRUE; |
9666 | return FALSE; | |
5d1634d7 | 9667 | } |
41bd81ab | 9668 | |
176a0d42 AM |
9669 | if (info->emitrelocations) |
9670 | { | |
9671 | r = get_relocs (stub_entry->stub_sec, 1 + (PPC_HA (off) != 0)); | |
9672 | if (r == NULL) | |
9673 | return FALSE; | |
9674 | r[0].r_offset = loc - stub_entry->stub_sec->contents; | |
7cfbafbc AM |
9675 | if (bfd_big_endian (info->output_bfd)) |
9676 | r[0].r_offset += 2; | |
176a0d42 AM |
9677 | if (stub_entry->stub_type == ppc_stub_plt_branch_r2off) |
9678 | r[0].r_offset += 4; | |
9679 | r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS); | |
9680 | r[0].r_addend = dest; | |
9681 | if (PPC_HA (off) != 0) | |
9682 | { | |
9683 | r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA); | |
9684 | r[1].r_offset = r[0].r_offset + 4; | |
9685 | r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS); | |
9686 | r[1].r_addend = r[0].r_addend; | |
9687 | } | |
9688 | } | |
9689 | ||
ad8e1ba5 AM |
9690 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
9691 | { | |
176a0d42 | 9692 | if (PPC_HA (off) != 0) |
ac2df442 AM |
9693 | { |
9694 | size = 16; | |
176a0d42 | 9695 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (off), loc); |
ac2df442 | 9696 | loc += 4; |
176a0d42 | 9697 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (off), loc); |
ac2df442 AM |
9698 | } |
9699 | else | |
9700 | { | |
9701 | size = 12; | |
176a0d42 | 9702 | bfd_put_32 (htab->stub_bfd, LD_R11_0R2 | PPC_LO (off), loc); |
ac2df442 | 9703 | } |
ad8e1ba5 AM |
9704 | } |
9705 | else | |
9706 | { | |
25f53a85 | 9707 | bfd_vma r2off = get_r2off (info, stub_entry); |
aa374f67 AM |
9708 | |
9709 | if (r2off == 0) | |
9710 | { | |
9711 | htab->stub_error = TRUE; | |
9712 | return FALSE; | |
9713 | } | |
ad8e1ba5 | 9714 | |
97b639ba | 9715 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 9716 | loc += 4; |
ac2df442 | 9717 | size = 20; |
176a0d42 | 9718 | if (PPC_HA (off) != 0) |
ac2df442 AM |
9719 | { |
9720 | size += 4; | |
176a0d42 | 9721 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (off), loc); |
ac2df442 | 9722 | loc += 4; |
176a0d42 | 9723 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (off), loc); |
ac2df442 AM |
9724 | loc += 4; |
9725 | } | |
9726 | else | |
9727 | { | |
176a0d42 | 9728 | bfd_put_32 (htab->stub_bfd, LD_R11_0R2 | PPC_LO (off), loc); |
ac2df442 AM |
9729 | loc += 4; |
9730 | } | |
9731 | ||
9732 | if (PPC_HA (r2off) != 0) | |
9733 | { | |
9734 | size += 4; | |
9735 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); | |
9736 | loc += 4; | |
9737 | } | |
97b639ba | 9738 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
9739 | } |
9740 | loc += 4; | |
97b639ba | 9741 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
ad8e1ba5 | 9742 | loc += 4; |
97b639ba | 9743 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
721956f4 | 9744 | break; |
5d1634d7 | 9745 | |
721956f4 | 9746 | case ppc_stub_plt_call: |
e054468f | 9747 | if (stub_entry->h != NULL |
b31867b6 AM |
9748 | && stub_entry->h->is_func_descriptor |
9749 | && stub_entry->h->oh != NULL) | |
c862ae31 | 9750 | { |
b31867b6 AM |
9751 | struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh); |
9752 | ||
9753 | /* If the old-ABI "dot-symbol" is undefined make it weak so | |
9754 | we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. | |
9755 | FIXME: We used to define the symbol on one of the call | |
9756 | stubs instead, which is why we test symbol section id | |
9757 | against htab->top_id in various places. Likely all | |
9758 | these checks could now disappear. */ | |
9759 | if (fh->elf.root.type == bfd_link_hash_undefined) | |
9760 | fh->elf.root.type = bfd_link_hash_undefweak; | |
9507a174 AM |
9761 | /* Stop undo_symbol_twiddle changing it back to undefined. */ |
9762 | fh->was_undefined = 0; | |
c862ae31 AM |
9763 | } |
9764 | ||
721956f4 | 9765 | /* Now build the stub. */ |
e054468f | 9766 | dest = stub_entry->plt_ent->plt.offset & ~1; |
176a0d42 | 9767 | if (dest >= (bfd_vma) -2) |
721956f4 AM |
9768 | abort (); |
9769 | ||
e054468f | 9770 | plt = htab->plt; |
25f23106 AM |
9771 | if (!htab->elf.dynamic_sections_created |
9772 | || stub_entry->h == NULL | |
9773 | || stub_entry->h->elf.dynindx == -1) | |
e054468f AM |
9774 | plt = htab->iplt; |
9775 | ||
9776 | dest += plt->output_offset + plt->output_section->vma; | |
9777 | ||
9778 | if (stub_entry->h == NULL | |
9779 | && (stub_entry->plt_ent->plt.offset & 1) == 0) | |
9780 | { | |
9781 | Elf_Internal_Rela rela; | |
9782 | bfd_byte *rl; | |
9783 | ||
9784 | rela.r_offset = dest; | |
25f23106 | 9785 | rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL); |
e054468f AM |
9786 | rela.r_addend = (stub_entry->target_value |
9787 | + stub_entry->target_section->output_offset | |
9788 | + stub_entry->target_section->output_section->vma); | |
9789 | ||
25f23106 AM |
9790 | rl = (htab->reliplt->contents |
9791 | + (htab->reliplt->reloc_count++ | |
9792 | * sizeof (Elf64_External_Rela))); | |
9793 | bfd_elf64_swap_reloca_out (info->output_bfd, &rela, rl); | |
e054468f AM |
9794 | stub_entry->plt_ent->plt.offset |= 1; |
9795 | } | |
176a0d42 AM |
9796 | |
9797 | off = (dest | |
e054468f | 9798 | - elf_gp (plt->output_section->owner) |
176a0d42 | 9799 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 9800 | |
ad8e1ba5 | 9801 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
721956f4 | 9802 | { |
25f53a85 AM |
9803 | info->callbacks->einfo |
9804 | (_("linkage table error against `%s'\n"), | |
e054468f AM |
9805 | stub_entry->h != NULL |
9806 | ? stub_entry->h->elf.root.root.string | |
9807 | : "<local sym>"); | |
721956f4 | 9808 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
9809 | htab->stub_error = TRUE; |
9810 | return FALSE; | |
721956f4 AM |
9811 | } |
9812 | ||
176a0d42 AM |
9813 | r = NULL; |
9814 | if (info->emitrelocations) | |
9815 | { | |
9816 | r = get_relocs (stub_entry->stub_sec, | |
c7131b65 AM |
9817 | (2 |
9818 | + (PPC_HA (off) != 0) | |
9819 | + (htab->plt_static_chain | |
9820 | && PPC_HA (off + 16) == PPC_HA (off)))); | |
176a0d42 AM |
9821 | if (r == NULL) |
9822 | return FALSE; | |
9823 | r[0].r_offset = loc - stub_entry->stub_sec->contents; | |
7cfbafbc AM |
9824 | if (bfd_big_endian (info->output_bfd)) |
9825 | r[0].r_offset += 2; | |
176a0d42 AM |
9826 | r[0].r_addend = dest; |
9827 | } | |
a7f2871e AM |
9828 | if (stub_entry->h != NULL |
9829 | && (stub_entry->h == htab->tls_get_addr_fd | |
9830 | || stub_entry->h == htab->tls_get_addr) | |
9831 | && !htab->no_tls_get_addr_opt) | |
9df0ef5f AM |
9832 | p = build_tls_get_addr_stub (htab->stub_bfd, loc, off, r, |
9833 | htab->plt_static_chain); | |
a7f2871e | 9834 | else |
9df0ef5f AM |
9835 | p = build_plt_stub (htab->stub_bfd, loc, off, r, |
9836 | htab->plt_static_chain); | |
721956f4 AM |
9837 | size = p - loc; |
9838 | break; | |
9839 | ||
9840 | default: | |
9841 | BFD_FAIL (); | |
b34976b6 | 9842 | return FALSE; |
721956f4 AM |
9843 | } |
9844 | ||
eea6121a | 9845 | stub_entry->stub_sec->size += size; |
97b639ba | 9846 | |
ee75fd95 | 9847 | if (htab->emit_stub_syms) |
97b639ba AM |
9848 | { |
9849 | struct elf_link_hash_entry *h; | |
ee75fd95 AM |
9850 | size_t len1, len2; |
9851 | char *name; | |
9852 | const char *const stub_str[] = { "long_branch", | |
9853 | "long_branch_r2off", | |
9854 | "plt_branch", | |
9855 | "plt_branch_r2off", | |
9856 | "plt_call" }; | |
9857 | ||
9858 | len1 = strlen (stub_str[stub_entry->stub_type - 1]); | |
9859 | len2 = strlen (stub_entry->root.string); | |
9860 | name = bfd_malloc (len1 + len2 + 2); | |
9861 | if (name == NULL) | |
9862 | return FALSE; | |
9863 | memcpy (name, stub_entry->root.string, 9); | |
9864 | memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1); | |
9865 | memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1); | |
9866 | h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE); | |
97b639ba AM |
9867 | if (h == NULL) |
9868 | return FALSE; | |
9869 | if (h->root.type == bfd_link_hash_new) | |
9870 | { | |
9871 | h->root.type = bfd_link_hash_defined; | |
9872 | h->root.u.def.section = stub_entry->stub_sec; | |
9873 | h->root.u.def.value = stub_entry->stub_offset; | |
f5385ebf AM |
9874 | h->ref_regular = 1; |
9875 | h->def_regular = 1; | |
9876 | h->ref_regular_nonweak = 1; | |
9877 | h->forced_local = 1; | |
9878 | h->non_elf = 0; | |
97b639ba AM |
9879 | } |
9880 | } | |
9881 | ||
b34976b6 | 9882 | return TRUE; |
721956f4 AM |
9883 | } |
9884 | ||
9885 | /* As above, but don't actually build the stub. Just bump offset so | |
9886 | we know stub section sizes, and select plt_branch stubs where | |
9887 | long_branch stubs won't do. */ | |
9888 | ||
b34976b6 | 9889 | static bfd_boolean |
4ce794b7 | 9890 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
721956f4 AM |
9891 | { |
9892 | struct ppc_stub_hash_entry *stub_entry; | |
63bc6f6c | 9893 | struct bfd_link_info *info; |
721956f4 AM |
9894 | struct ppc_link_hash_table *htab; |
9895 | bfd_vma off; | |
9896 | int size; | |
9897 | ||
9898 | /* Massage our args to the form they really have. */ | |
9899 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
63bc6f6c AM |
9900 | info = in_arg; |
9901 | ||
9902 | htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
9903 | if (htab == NULL) |
9904 | return FALSE; | |
721956f4 AM |
9905 | |
9906 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
9907 | { | |
e054468f AM |
9908 | asection *plt; |
9909 | off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1; | |
58ac9f71 | 9910 | if (off >= (bfd_vma) -2) |
411e1bfb | 9911 | abort (); |
e054468f | 9912 | plt = htab->plt; |
25f23106 AM |
9913 | if (!htab->elf.dynamic_sections_created |
9914 | || stub_entry->h == NULL | |
9915 | || stub_entry->h->elf.dynindx == -1) | |
e054468f AM |
9916 | plt = htab->iplt; |
9917 | off += (plt->output_offset | |
9918 | + plt->output_section->vma | |
9919 | - elf_gp (plt->output_section->owner) | |
ad8e1ba5 | 9920 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 9921 | |
ad8e1ba5 | 9922 | size = PLT_CALL_STUB_SIZE; |
9df0ef5f AM |
9923 | if (!htab->plt_static_chain) |
9924 | size -= 4; | |
ac2df442 AM |
9925 | if (PPC_HA (off) == 0) |
9926 | size -= 4; | |
c7131b65 | 9927 | if (PPC_HA (off + 8 + 8 * htab->plt_static_chain) != PPC_HA (off)) |
721956f4 | 9928 | size += 4; |
a7f2871e AM |
9929 | if (stub_entry->h != NULL |
9930 | && (stub_entry->h == htab->tls_get_addr_fd | |
9931 | || stub_entry->h == htab->tls_get_addr) | |
9932 | && !htab->no_tls_get_addr_opt) | |
9933 | size += 13 * 4; | |
176a0d42 AM |
9934 | if (info->emitrelocations) |
9935 | { | |
9936 | stub_entry->stub_sec->reloc_count | |
c7131b65 AM |
9937 | += (2 |
9938 | + (PPC_HA (off) != 0) | |
9939 | + (htab->plt_static_chain | |
9940 | && PPC_HA (off + 16) == PPC_HA (off))); | |
176a0d42 AM |
9941 | stub_entry->stub_sec->flags |= SEC_RELOC; |
9942 | } | |
721956f4 AM |
9943 | } |
9944 | else | |
9945 | { | |
ad8e1ba5 AM |
9946 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
9947 | variants. */ | |
ac2df442 AM |
9948 | bfd_vma r2off = 0; |
9949 | ||
721956f4 AM |
9950 | off = (stub_entry->target_value |
9951 | + stub_entry->target_section->output_offset | |
9952 | + stub_entry->target_section->output_section->vma); | |
eea6121a | 9953 | off -= (stub_entry->stub_sec->size |
721956f4 AM |
9954 | + stub_entry->stub_sec->output_offset |
9955 | + stub_entry->stub_sec->output_section->vma); | |
9956 | ||
ad8e1ba5 AM |
9957 | /* Reset the stub type from the plt variant in case we now |
9958 | can reach with a shorter stub. */ | |
9959 | if (stub_entry->stub_type >= ppc_stub_plt_branch) | |
9960 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; | |
9961 | ||
9962 | size = 4; | |
9963 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
9964 | { | |
25f53a85 | 9965 | r2off = get_r2off (info, stub_entry); |
aa374f67 AM |
9966 | if (r2off == 0) |
9967 | { | |
9968 | htab->stub_error = TRUE; | |
9969 | return FALSE; | |
9970 | } | |
ac2df442 AM |
9971 | size = 12; |
9972 | if (PPC_HA (r2off) != 0) | |
9973 | size = 16; | |
9974 | off -= size - 4; | |
ad8e1ba5 AM |
9975 | } |
9976 | ||
9977 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ | |
721956f4 AM |
9978 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
9979 | { | |
9980 | struct ppc_branch_hash_entry *br_entry; | |
9981 | ||
9982 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
9983 | stub_entry->root.string + 9, | |
b34976b6 | 9984 | TRUE, FALSE); |
721956f4 AM |
9985 | if (br_entry == NULL) |
9986 | { | |
25f53a85 AM |
9987 | info->callbacks->einfo (_("can't build branch stub `%s'\n"), |
9988 | stub_entry->root.string); | |
b34976b6 AM |
9989 | htab->stub_error = TRUE; |
9990 | return FALSE; | |
721956f4 AM |
9991 | } |
9992 | ||
9993 | if (br_entry->iter != htab->stub_iteration) | |
9994 | { | |
9995 | br_entry->iter = htab->stub_iteration; | |
eea6121a AM |
9996 | br_entry->offset = htab->brlt->size; |
9997 | htab->brlt->size += 8; | |
63bc6f6c | 9998 | |
ee75fd95 | 9999 | if (htab->relbrlt != NULL) |
eea6121a | 10000 | htab->relbrlt->size += sizeof (Elf64_External_Rela); |
84f5d08e AM |
10001 | else if (info->emitrelocations) |
10002 | { | |
10003 | htab->brlt->reloc_count += 1; | |
10004 | htab->brlt->flags |= SEC_RELOC; | |
10005 | } | |
721956f4 | 10006 | } |
ad8e1ba5 AM |
10007 | |
10008 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | |
ac2df442 AM |
10009 | off = (br_entry->offset |
10010 | + htab->brlt->output_offset | |
10011 | + htab->brlt->output_section->vma | |
10012 | - elf_gp (htab->brlt->output_section->owner) | |
10013 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
10014 | ||
176a0d42 AM |
10015 | if (info->emitrelocations) |
10016 | { | |
10017 | stub_entry->stub_sec->reloc_count += 1 + (PPC_HA (off) != 0); | |
10018 | stub_entry->stub_sec->flags |= SEC_RELOC; | |
10019 | } | |
10020 | ||
ac2df442 AM |
10021 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
10022 | { | |
10023 | size = 12; | |
176a0d42 | 10024 | if (PPC_HA (off) != 0) |
ac2df442 AM |
10025 | size = 16; |
10026 | } | |
10027 | else | |
10028 | { | |
10029 | size = 20; | |
176a0d42 | 10030 | if (PPC_HA (off) != 0) |
ac2df442 AM |
10031 | size += 4; |
10032 | ||
10033 | if (PPC_HA (r2off) != 0) | |
10034 | size += 4; | |
10035 | } | |
721956f4 | 10036 | } |
84f5d08e AM |
10037 | else if (info->emitrelocations) |
10038 | { | |
10039 | stub_entry->stub_sec->reloc_count += 1; | |
10040 | stub_entry->stub_sec->flags |= SEC_RELOC; | |
10041 | } | |
721956f4 AM |
10042 | } |
10043 | ||
eea6121a | 10044 | stub_entry->stub_sec->size += size; |
b34976b6 | 10045 | return TRUE; |
721956f4 AM |
10046 | } |
10047 | ||
10048 | /* Set up various things so that we can make a list of input sections | |
10049 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 10050 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
10051 | |
10052 | int | |
927be08e AM |
10053 | ppc64_elf_setup_section_lists |
10054 | (struct bfd_link_info *info, | |
10055 | asection *(*add_stub_section) (const char *, asection *), | |
10056 | void (*layout_sections_again) (void)) | |
721956f4 AM |
10057 | { |
10058 | bfd *input_bfd; | |
734b6cf9 | 10059 | int top_id, top_index, id; |
721956f4 | 10060 | asection *section; |
734b6cf9 | 10061 | asection **input_list; |
721956f4 AM |
10062 | bfd_size_type amt; |
10063 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
10064 | ||
4dfe6ac6 NC |
10065 | if (htab == NULL) |
10066 | return -1; | |
927be08e AM |
10067 | /* Stash our params away. */ |
10068 | htab->add_stub_section = add_stub_section; | |
10069 | htab->layout_sections_again = layout_sections_again; | |
4c52953f | 10070 | |
4ce794b7 | 10071 | if (htab->brlt == NULL) |
721956f4 AM |
10072 | return 0; |
10073 | ||
1e2f5b6e | 10074 | /* Find the top input section id. */ |
3d6f9012 | 10075 | for (input_bfd = info->input_bfds, top_id = 3; |
721956f4 AM |
10076 | input_bfd != NULL; |
10077 | input_bfd = input_bfd->link_next) | |
10078 | { | |
721956f4 AM |
10079 | for (section = input_bfd->sections; |
10080 | section != NULL; | |
10081 | section = section->next) | |
10082 | { | |
10083 | if (top_id < section->id) | |
10084 | top_id = section->id; | |
10085 | } | |
10086 | } | |
721956f4 | 10087 | |
8f3bab57 | 10088 | htab->top_id = top_id; |
721956f4 | 10089 | amt = sizeof (struct map_stub) * (top_id + 1); |
4ce794b7 | 10090 | htab->stub_group = bfd_zmalloc (amt); |
721956f4 AM |
10091 | if (htab->stub_group == NULL) |
10092 | return -1; | |
10093 | ||
3d6f9012 AM |
10094 | /* Set toc_off for com, und, abs and ind sections. */ |
10095 | for (id = 0; id < 3; id++) | |
10096 | htab->stub_group[id].toc_off = TOC_BASE_OFF; | |
721956f4 | 10097 | |
734b6cf9 AM |
10098 | /* We can't use output_bfd->section_count here to find the top output |
10099 | section index as some sections may have been removed, and | |
8423293d | 10100 | strip_excluded_output_sections doesn't renumber the indices. */ |
927be08e | 10101 | for (section = info->output_bfd->sections, top_index = 0; |
734b6cf9 AM |
10102 | section != NULL; |
10103 | section = section->next) | |
10104 | { | |
10105 | if (top_index < section->index) | |
10106 | top_index = section->index; | |
10107 | } | |
10108 | ||
10109 | htab->top_index = top_index; | |
10110 | amt = sizeof (asection *) * (top_index + 1); | |
4ce794b7 | 10111 | input_list = bfd_zmalloc (amt); |
734b6cf9 AM |
10112 | htab->input_list = input_list; |
10113 | if (input_list == NULL) | |
10114 | return -1; | |
10115 | ||
721956f4 AM |
10116 | return 1; |
10117 | } | |
10118 | ||
927be08e AM |
10119 | /* Set up for first pass at multitoc partitioning. */ |
10120 | ||
10121 | void | |
10122 | ppc64_elf_start_multitoc_partition (struct bfd_link_info *info) | |
10123 | { | |
10124 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
10125 | ||
10126 | elf_gp (info->output_bfd) = ppc64_elf_toc (info->output_bfd); | |
10127 | htab->toc_curr = elf_gp (info->output_bfd); | |
10128 | htab->toc_bfd = NULL; | |
10129 | htab->toc_first_sec = NULL; | |
10130 | } | |
10131 | ||
e717da7e AM |
10132 | /* The linker repeatedly calls this function for each TOC input section |
10133 | and linker generated GOT section. Group input bfds such that the toc | |
927be08e | 10134 | within a group is less than 64k in size. */ |
ad8e1ba5 | 10135 | |
927be08e | 10136 | bfd_boolean |
4ce794b7 | 10137 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
ad8e1ba5 AM |
10138 | { |
10139 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
d77c8a4b | 10140 | bfd_vma addr, off, limit; |
ad8e1ba5 | 10141 | |
4dfe6ac6 NC |
10142 | if (htab == NULL) |
10143 | return FALSE; | |
10144 | ||
927be08e | 10145 | if (!htab->second_toc_pass) |
4c52953f | 10146 | { |
927be08e | 10147 | /* Keep track of the first .toc or .got section for this input bfd. */ |
bf102f86 AM |
10148 | if (htab->toc_bfd != isec->owner) |
10149 | { | |
10150 | htab->toc_bfd = isec->owner; | |
10151 | htab->toc_first_sec = isec; | |
10152 | } | |
927be08e | 10153 | |
bf102f86 AM |
10154 | addr = isec->output_offset + isec->output_section->vma; |
10155 | off = addr - htab->toc_curr; | |
d77c8a4b AM |
10156 | limit = 0x80008000; |
10157 | if (ppc64_elf_tdata (isec->owner)->has_small_toc_reloc) | |
10158 | limit = 0x10000; | |
10159 | if (off + isec->size > limit) | |
bf102f86 AM |
10160 | { |
10161 | addr = (htab->toc_first_sec->output_offset | |
10162 | + htab->toc_first_sec->output_section->vma); | |
10163 | htab->toc_curr = addr; | |
10164 | } | |
99877b66 | 10165 | |
927be08e AM |
10166 | /* toc_curr is the base address of this toc group. Set elf_gp |
10167 | for the input section to be the offset relative to the | |
10168 | output toc base plus 0x8000. Making the input elf_gp an | |
10169 | offset allows us to move the toc as a whole without | |
10170 | recalculating input elf_gp. */ | |
10171 | off = htab->toc_curr - elf_gp (isec->output_section->owner); | |
10172 | off += TOC_BASE_OFF; | |
10173 | ||
10174 | /* Die if someone uses a linker script that doesn't keep input | |
10175 | file .toc and .got together. */ | |
10176 | if (elf_gp (isec->owner) != 0 | |
10177 | && elf_gp (isec->owner) != off) | |
10178 | return FALSE; | |
10179 | ||
10180 | elf_gp (isec->owner) = off; | |
10181 | return TRUE; | |
4c52953f | 10182 | } |
927be08e AM |
10183 | |
10184 | /* During the second pass toc_first_sec points to the start of | |
10185 | a toc group, and toc_curr is used to track the old elf_gp. | |
10186 | We use toc_bfd to ensure we only look at each bfd once. */ | |
10187 | if (htab->toc_bfd == isec->owner) | |
10188 | return TRUE; | |
10189 | htab->toc_bfd = isec->owner; | |
10190 | ||
10191 | if (htab->toc_first_sec == NULL | |
10192 | || htab->toc_curr != elf_gp (isec->owner)) | |
10193 | { | |
10194 | htab->toc_curr = elf_gp (isec->owner); | |
10195 | htab->toc_first_sec = isec; | |
10196 | } | |
10197 | addr = (htab->toc_first_sec->output_offset | |
10198 | + htab->toc_first_sec->output_section->vma); | |
10199 | off = addr - elf_gp (isec->output_section->owner) + TOC_BASE_OFF; | |
10200 | elf_gp (isec->owner) = off; | |
10201 | ||
10202 | return TRUE; | |
ad8e1ba5 AM |
10203 | } |
10204 | ||
927be08e AM |
10205 | /* Called via elf_link_hash_traverse to merge GOT entries for global |
10206 | symbol H. */ | |
10207 | ||
10208 | static bfd_boolean | |
10209 | merge_global_got (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
10210 | { | |
10211 | if (h->root.type == bfd_link_hash_indirect) | |
10212 | return TRUE; | |
10213 | ||
927be08e AM |
10214 | merge_got_entries (&h->got.glist); |
10215 | ||
10216 | return TRUE; | |
10217 | } | |
10218 | ||
10219 | /* Called via elf_link_hash_traverse to allocate GOT entries for global | |
10220 | symbol H. */ | |
10221 | ||
10222 | static bfd_boolean | |
10223 | reallocate_got (struct elf_link_hash_entry *h, void *inf) | |
10224 | { | |
10225 | struct got_entry *gent; | |
10226 | ||
10227 | if (h->root.type == bfd_link_hash_indirect) | |
10228 | return TRUE; | |
10229 | ||
927be08e AM |
10230 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
10231 | if (!gent->is_indirect) | |
10232 | allocate_got (h, (struct bfd_link_info *) inf, gent); | |
10233 | return TRUE; | |
10234 | } | |
10235 | ||
10236 | /* Called on the first multitoc pass after the last call to | |
10237 | ppc64_elf_next_toc_section. This function removes duplicate GOT | |
10238 | entries. */ | |
10239 | ||
10240 | bfd_boolean | |
10241 | ppc64_elf_layout_multitoc (struct bfd_link_info *info) | |
ad8e1ba5 AM |
10242 | { |
10243 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
927be08e AM |
10244 | struct bfd *ibfd, *ibfd2; |
10245 | bfd_boolean done_something; | |
10246 | ||
10247 | htab->multi_toc_needed = htab->toc_curr != elf_gp (info->output_bfd); | |
ad8e1ba5 | 10248 | |
7865406b AM |
10249 | if (!htab->do_multi_toc) |
10250 | return FALSE; | |
10251 | ||
d0fae19d | 10252 | /* Merge global sym got entries within a toc group. */ |
927be08e AM |
10253 | elf_link_hash_traverse (&htab->elf, merge_global_got, info); |
10254 | ||
10255 | /* And tlsld_got. */ | |
10256 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
10257 | { | |
10258 | struct got_entry *ent, *ent2; | |
10259 | ||
10260 | if (!is_ppc64_elf (ibfd)) | |
10261 | continue; | |
10262 | ||
10263 | ent = ppc64_tlsld_got (ibfd); | |
10264 | if (!ent->is_indirect | |
10265 | && ent->got.offset != (bfd_vma) -1) | |
10266 | { | |
10267 | for (ibfd2 = ibfd->link_next; ibfd2 != NULL; ibfd2 = ibfd2->link_next) | |
10268 | { | |
10269 | if (!is_ppc64_elf (ibfd2)) | |
10270 | continue; | |
10271 | ||
10272 | ent2 = ppc64_tlsld_got (ibfd2); | |
10273 | if (!ent2->is_indirect | |
10274 | && ent2->got.offset != (bfd_vma) -1 | |
10275 | && elf_gp (ibfd2) == elf_gp (ibfd)) | |
10276 | { | |
10277 | ent2->is_indirect = TRUE; | |
10278 | ent2->got.ent = ent; | |
10279 | } | |
10280 | } | |
10281 | } | |
10282 | } | |
10283 | ||
10284 | /* Zap sizes of got sections. */ | |
10285 | htab->reliplt->rawsize = htab->reliplt->size; | |
10286 | htab->reliplt->size -= htab->got_reli_size; | |
10287 | htab->got_reli_size = 0; | |
10288 | ||
10289 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
10290 | { | |
10291 | asection *got, *relgot; | |
10292 | ||
10293 | if (!is_ppc64_elf (ibfd)) | |
10294 | continue; | |
10295 | ||
10296 | got = ppc64_elf_tdata (ibfd)->got; | |
10297 | if (got != NULL) | |
10298 | { | |
10299 | got->rawsize = got->size; | |
10300 | got->size = 0; | |
10301 | relgot = ppc64_elf_tdata (ibfd)->relgot; | |
10302 | relgot->rawsize = relgot->size; | |
10303 | relgot->size = 0; | |
10304 | } | |
10305 | } | |
10306 | ||
10307 | /* Now reallocate the got, local syms first. We don't need to | |
10308 | allocate section contents again since we never increase size. */ | |
10309 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
10310 | { | |
10311 | struct got_entry **lgot_ents; | |
10312 | struct got_entry **end_lgot_ents; | |
10313 | struct plt_entry **local_plt; | |
10314 | struct plt_entry **end_local_plt; | |
f961d9dd | 10315 | unsigned char *lgot_masks; |
927be08e AM |
10316 | bfd_size_type locsymcount; |
10317 | Elf_Internal_Shdr *symtab_hdr; | |
10318 | asection *s, *srel; | |
10319 | ||
10320 | if (!is_ppc64_elf (ibfd)) | |
10321 | continue; | |
10322 | ||
10323 | lgot_ents = elf_local_got_ents (ibfd); | |
10324 | if (!lgot_ents) | |
10325 | continue; | |
10326 | ||
10327 | symtab_hdr = &elf_symtab_hdr (ibfd); | |
10328 | locsymcount = symtab_hdr->sh_info; | |
10329 | end_lgot_ents = lgot_ents + locsymcount; | |
10330 | local_plt = (struct plt_entry **) end_lgot_ents; | |
10331 | end_local_plt = local_plt + locsymcount; | |
f961d9dd | 10332 | lgot_masks = (unsigned char *) end_local_plt; |
927be08e AM |
10333 | s = ppc64_elf_tdata (ibfd)->got; |
10334 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
10335 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) | |
10336 | { | |
10337 | struct got_entry *ent; | |
10338 | ||
10339 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) | |
d0fae19d AM |
10340 | { |
10341 | unsigned int num = 1; | |
10342 | ent->got.offset = s->size; | |
10343 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) | |
10344 | num = 2; | |
10345 | s->size += num * 8; | |
10346 | if (info->shared) | |
10347 | srel->size += num * sizeof (Elf64_External_Rela); | |
10348 | else if ((*lgot_masks & PLT_IFUNC) != 0) | |
10349 | { | |
10350 | htab->reliplt->size | |
10351 | += num * sizeof (Elf64_External_Rela); | |
10352 | htab->got_reli_size | |
10353 | += num * sizeof (Elf64_External_Rela); | |
10354 | } | |
10355 | } | |
927be08e AM |
10356 | } |
10357 | } | |
10358 | ||
10359 | elf_link_hash_traverse (&htab->elf, reallocate_got, info); | |
10360 | ||
10361 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
10362 | { | |
10363 | struct got_entry *ent; | |
10364 | ||
10365 | if (!is_ppc64_elf (ibfd)) | |
10366 | continue; | |
10367 | ||
10368 | ent = ppc64_tlsld_got (ibfd); | |
10369 | if (!ent->is_indirect | |
10370 | && ent->got.offset != (bfd_vma) -1) | |
10371 | { | |
10372 | asection *s = ppc64_elf_tdata (ibfd)->got; | |
10373 | ent->got.offset = s->size; | |
10374 | s->size += 16; | |
10375 | if (info->shared) | |
10376 | { | |
10377 | asection *srel = ppc64_elf_tdata (ibfd)->relgot; | |
10378 | srel->size += sizeof (Elf64_External_Rela); | |
10379 | } | |
10380 | } | |
10381 | } | |
10382 | ||
10383 | done_something = htab->reliplt->rawsize != htab->reliplt->size; | |
10384 | if (!done_something) | |
10385 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
10386 | { | |
10387 | asection *got; | |
10388 | ||
10389 | if (!is_ppc64_elf (ibfd)) | |
10390 | continue; | |
10391 | ||
10392 | got = ppc64_elf_tdata (ibfd)->got; | |
10393 | if (got != NULL) | |
10394 | { | |
10395 | done_something = got->rawsize != got->size; | |
10396 | if (done_something) | |
10397 | break; | |
10398 | } | |
10399 | } | |
10400 | ||
10401 | if (done_something) | |
10402 | (*htab->layout_sections_again) (); | |
10403 | ||
10404 | /* Set up for second pass over toc sections to recalculate elf_gp | |
10405 | on input sections. */ | |
10406 | htab->toc_bfd = NULL; | |
10407 | htab->toc_first_sec = NULL; | |
10408 | htab->second_toc_pass = TRUE; | |
10409 | return done_something; | |
10410 | } | |
10411 | ||
10412 | /* Called after second pass of multitoc partitioning. */ | |
10413 | ||
10414 | void | |
10415 | ppc64_elf_finish_multitoc_partition (struct bfd_link_info *info) | |
10416 | { | |
10417 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
10418 | ||
10419 | /* After the second pass, toc_curr tracks the TOC offset used | |
10420 | for code sections below in ppc64_elf_next_input_section. */ | |
3d6f9012 | 10421 | htab->toc_curr = TOC_BASE_OFF; |
ad8e1ba5 AM |
10422 | } |
10423 | ||
9b5ecbd0 AM |
10424 | /* No toc references were found in ISEC. If the code in ISEC makes no |
10425 | calls, then there's no need to use toc adjusting stubs when branching | |
10426 | into ISEC. Actually, indirect calls from ISEC are OK as they will | |
4c52953f AM |
10427 | load r2. Returns -1 on error, 0 for no stub needed, 1 for stub |
10428 | needed, and 2 if a cyclical call-graph was found but no other reason | |
10429 | for a stub was detected. If called from the top level, a return of | |
10430 | 2 means the same as a return of 0. */ | |
9b5ecbd0 AM |
10431 | |
10432 | static int | |
4ce794b7 | 10433 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
9b5ecbd0 | 10434 | { |
9b5ecbd0 | 10435 | int ret; |
70cc837d AM |
10436 | |
10437 | /* Mark this section as checked. */ | |
10438 | isec->call_check_done = 1; | |
9b5ecbd0 | 10439 | |
772119ce AM |
10440 | /* We know none of our code bearing sections will need toc stubs. */ |
10441 | if ((isec->flags & SEC_LINKER_CREATED) != 0) | |
10442 | return 0; | |
10443 | ||
eea6121a | 10444 | if (isec->size == 0) |
082c50f8 AM |
10445 | return 0; |
10446 | ||
4c52953f AM |
10447 | if (isec->output_section == NULL) |
10448 | return 0; | |
10449 | ||
4c52953f | 10450 | ret = 0; |
70cc837d | 10451 | if (isec->reloc_count != 0) |
9b5ecbd0 | 10452 | { |
70cc837d AM |
10453 | Elf_Internal_Rela *relstart, *rel; |
10454 | Elf_Internal_Sym *local_syms; | |
10455 | struct ppc_link_hash_table *htab; | |
2917689a | 10456 | |
70cc837d AM |
10457 | relstart = _bfd_elf_link_read_relocs (isec->owner, isec, NULL, NULL, |
10458 | info->keep_memory); | |
10459 | if (relstart == NULL) | |
10460 | return -1; | |
90aecf7a | 10461 | |
70cc837d AM |
10462 | /* Look for branches to outside of this section. */ |
10463 | local_syms = NULL; | |
10464 | htab = ppc_hash_table (info); | |
10465 | if (htab == NULL) | |
10466 | return -1; | |
4c52953f | 10467 | |
70cc837d | 10468 | for (rel = relstart; rel < relstart + isec->reloc_count; ++rel) |
4c52953f | 10469 | { |
70cc837d AM |
10470 | enum elf_ppc64_reloc_type r_type; |
10471 | unsigned long r_symndx; | |
10472 | struct elf_link_hash_entry *h; | |
10473 | struct ppc_link_hash_entry *eh; | |
10474 | Elf_Internal_Sym *sym; | |
10475 | asection *sym_sec; | |
10476 | struct _opd_sec_data *opd; | |
10477 | bfd_vma sym_value; | |
10478 | bfd_vma dest; | |
10479 | ||
10480 | r_type = ELF64_R_TYPE (rel->r_info); | |
10481 | if (r_type != R_PPC64_REL24 | |
10482 | && r_type != R_PPC64_REL14 | |
10483 | && r_type != R_PPC64_REL14_BRTAKEN | |
10484 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
10485 | continue; | |
4c52953f | 10486 | |
70cc837d AM |
10487 | r_symndx = ELF64_R_SYM (rel->r_info); |
10488 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx, | |
10489 | isec->owner)) | |
4c52953f | 10490 | { |
70cc837d AM |
10491 | ret = -1; |
10492 | break; | |
10493 | } | |
4c52953f | 10494 | |
70cc837d AM |
10495 | /* Calls to dynamic lib functions go through a plt call stub |
10496 | that uses r2. */ | |
10497 | eh = (struct ppc_link_hash_entry *) h; | |
10498 | if (eh != NULL | |
10499 | && (eh->elf.plt.plist != NULL | |
10500 | || (eh->oh != NULL | |
10501 | && ppc_follow_link (eh->oh)->elf.plt.plist != NULL))) | |
10502 | { | |
10503 | ret = 1; | |
10504 | break; | |
4c52953f AM |
10505 | } |
10506 | ||
70cc837d AM |
10507 | if (sym_sec == NULL) |
10508 | /* Ignore other undefined symbols. */ | |
4c52953f | 10509 | continue; |
4c52953f | 10510 | |
70cc837d AM |
10511 | /* Assume branches to other sections not included in the |
10512 | link need stubs too, to cover -R and absolute syms. */ | |
10513 | if (sym_sec->output_section == NULL) | |
10514 | { | |
10515 | ret = 1; | |
10516 | break; | |
10517 | } | |
4c52953f | 10518 | |
70cc837d AM |
10519 | if (h == NULL) |
10520 | sym_value = sym->st_value; | |
10521 | else | |
10522 | { | |
10523 | if (h->root.type != bfd_link_hash_defined | |
10524 | && h->root.type != bfd_link_hash_defweak) | |
10525 | abort (); | |
10526 | sym_value = h->root.u.def.value; | |
10527 | } | |
10528 | sym_value += rel->r_addend; | |
4c52953f | 10529 | |
70cc837d AM |
10530 | /* If this branch reloc uses an opd sym, find the code section. */ |
10531 | opd = get_opd_info (sym_sec); | |
10532 | if (opd != NULL) | |
10533 | { | |
10534 | if (h == NULL && opd->adjust != NULL) | |
10535 | { | |
10536 | long adjust; | |
4c52953f | 10537 | |
70cc837d AM |
10538 | adjust = opd->adjust[sym->st_value / 8]; |
10539 | if (adjust == -1) | |
10540 | /* Assume deleted functions won't ever be called. */ | |
10541 | continue; | |
10542 | sym_value += adjust; | |
10543 | } | |
4c52953f | 10544 | |
70cc837d AM |
10545 | dest = opd_entry_value (sym_sec, sym_value, &sym_sec, NULL); |
10546 | if (dest == (bfd_vma) -1) | |
10547 | continue; | |
10548 | } | |
10549 | else | |
10550 | dest = (sym_value | |
10551 | + sym_sec->output_offset | |
10552 | + sym_sec->output_section->vma); | |
4c52953f | 10553 | |
70cc837d AM |
10554 | /* Ignore branch to self. */ |
10555 | if (sym_sec == isec) | |
10556 | continue; | |
4c52953f | 10557 | |
70cc837d AM |
10558 | /* If the called function uses the toc, we need a stub. */ |
10559 | if (sym_sec->has_toc_reloc | |
10560 | || sym_sec->makes_toc_func_call) | |
4c52953f | 10561 | { |
70cc837d | 10562 | ret = 1; |
4c52953f AM |
10563 | break; |
10564 | } | |
70cc837d AM |
10565 | |
10566 | /* Assume any branch that needs a long branch stub might in fact | |
10567 | need a plt_branch stub. A plt_branch stub uses r2. */ | |
10568 | else if (dest - (isec->output_offset | |
10569 | + isec->output_section->vma | |
10570 | + rel->r_offset) + (1 << 25) >= (2 << 25)) | |
4c52953f | 10571 | { |
70cc837d AM |
10572 | ret = 1; |
10573 | break; | |
10574 | } | |
10575 | ||
10576 | /* If calling back to a section in the process of being | |
10577 | tested, we can't say for sure that no toc adjusting stubs | |
10578 | are needed, so don't return zero. */ | |
10579 | else if (sym_sec->call_check_in_progress) | |
10580 | ret = 2; | |
10581 | ||
10582 | /* Branches to another section that itself doesn't have any TOC | |
10583 | references are OK. Recursively call ourselves to check. */ | |
10584 | else if (!sym_sec->call_check_done) | |
10585 | { | |
10586 | int recur; | |
10587 | ||
10588 | /* Mark current section as indeterminate, so that other | |
10589 | sections that call back to current won't be marked as | |
10590 | known. */ | |
10591 | isec->call_check_in_progress = 1; | |
10592 | recur = toc_adjusting_stub_needed (info, sym_sec); | |
10593 | isec->call_check_in_progress = 0; | |
10594 | ||
4c52953f AM |
10595 | if (recur != 0) |
10596 | { | |
70cc837d AM |
10597 | ret = recur; |
10598 | if (recur != 2) | |
10599 | break; | |
4c52953f AM |
10600 | } |
10601 | } | |
4c52953f | 10602 | } |
70cc837d AM |
10603 | |
10604 | if (local_syms != NULL | |
10605 | && (elf_symtab_hdr (isec->owner).contents | |
10606 | != (unsigned char *) local_syms)) | |
10607 | free (local_syms); | |
10608 | if (elf_section_data (isec)->relocs != relstart) | |
10609 | free (relstart); | |
9b5ecbd0 AM |
10610 | } |
10611 | ||
70cc837d AM |
10612 | if ((ret & 1) == 0 |
10613 | && isec->map_head.s != NULL | |
10614 | && (strcmp (isec->output_section->name, ".init") == 0 | |
10615 | || strcmp (isec->output_section->name, ".fini") == 0)) | |
10616 | { | |
10617 | if (isec->map_head.s->has_toc_reloc | |
10618 | || isec->map_head.s->makes_toc_func_call) | |
10619 | ret = 1; | |
10620 | else if (!isec->map_head.s->call_check_done) | |
10621 | { | |
10622 | int recur; | |
10623 | isec->call_check_in_progress = 1; | |
10624 | recur = toc_adjusting_stub_needed (info, isec->map_head.s); | |
10625 | isec->call_check_in_progress = 0; | |
10626 | if (recur != 0) | |
10627 | ret = recur; | |
10628 | } | |
10629 | } | |
10630 | ||
10631 | if (ret == 1) | |
10632 | isec->makes_toc_func_call = 1; | |
4c52953f | 10633 | |
9b5ecbd0 AM |
10634 | return ret; |
10635 | } | |
10636 | ||
721956f4 AM |
10637 | /* The linker repeatedly calls this function for each input section, |
10638 | in the order that input sections are linked into output sections. | |
10639 | Build lists of input sections to determine groupings between which | |
10640 | we may insert linker stubs. */ | |
10641 | ||
9b5ecbd0 | 10642 | bfd_boolean |
4ce794b7 | 10643 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
721956f4 AM |
10644 | { |
10645 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
10646 | ||
4dfe6ac6 NC |
10647 | if (htab == NULL) |
10648 | return FALSE; | |
10649 | ||
734b6cf9 AM |
10650 | if ((isec->output_section->flags & SEC_CODE) != 0 |
10651 | && isec->output_section->index <= htab->top_index) | |
721956f4 | 10652 | { |
734b6cf9 | 10653 | asection **list = htab->input_list + isec->output_section->index; |
3d6f9012 | 10654 | /* Steal the link_sec pointer for our list. */ |
721956f4 | 10655 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3d6f9012 AM |
10656 | /* This happens to make the list in reverse order, |
10657 | which is what we want. */ | |
734b6cf9 AM |
10658 | PREV_SEC (isec) = *list; |
10659 | *list = isec; | |
721956f4 | 10660 | } |
ad8e1ba5 | 10661 | |
4c52953f | 10662 | if (htab->multi_toc_needed) |
9b5ecbd0 | 10663 | { |
4c52953f AM |
10664 | /* If a code section has a function that uses the TOC then we need |
10665 | to use the right TOC (obviously). Also, make sure that .opd gets | |
10666 | the correct TOC value for R_PPC64_TOC relocs that don't have or | |
f94498ff AM |
10667 | can't find their function symbol (shouldn't ever happen now). |
10668 | Also specially treat .fixup for the linux kernel. .fixup | |
10669 | contains branches, but only back to the function that hit an | |
10670 | exception. */ | |
10671 | if (isec->has_toc_reloc | |
10672 | || (isec->flags & SEC_CODE) == 0 | |
10673 | || strcmp (isec->name, ".fixup") == 0) | |
4c52953f AM |
10674 | { |
10675 | if (elf_gp (isec->owner) != 0) | |
10676 | htab->toc_curr = elf_gp (isec->owner); | |
10677 | } | |
6683a28d AM |
10678 | else |
10679 | { | |
10680 | if (!isec->call_check_done | |
10681 | && toc_adjusting_stub_needed (info, isec) < 0) | |
10682 | return FALSE; | |
10683 | /* If we make a local call from this section, ie. a branch | |
10684 | without a following nop, then we have no place to put a | |
10685 | toc restoring insn. We must use the same toc group as | |
10686 | the callee. | |
10687 | Testing makes_toc_func_call actually tests for *any* | |
10688 | calls to functions that need a good toc pointer. A more | |
10689 | precise test would be better, as this one will set | |
10690 | incorrect values for pasted .init/.fini fragments. | |
10691 | (Fixed later in check_pasted_section.) */ | |
10692 | if (isec->makes_toc_func_call | |
10693 | && elf_gp (isec->owner) != 0) | |
10694 | htab->toc_curr = elf_gp (isec->owner); | |
10695 | } | |
9b5ecbd0 | 10696 | } |
ad8e1ba5 AM |
10697 | |
10698 | /* Functions that don't use the TOC can belong in any TOC group. | |
6683a28d | 10699 | Use the last TOC base. */ |
ad8e1ba5 | 10700 | htab->stub_group[isec->id].toc_off = htab->toc_curr; |
9b5ecbd0 | 10701 | return TRUE; |
721956f4 AM |
10702 | } |
10703 | ||
70cc837d AM |
10704 | /* Check that all .init and .fini sections use the same toc, if they |
10705 | have toc relocs. */ | |
10706 | ||
10707 | static bfd_boolean | |
10708 | check_pasted_section (struct bfd_link_info *info, const char *name) | |
10709 | { | |
10710 | asection *o = bfd_get_section_by_name (info->output_bfd, name); | |
10711 | ||
10712 | if (o != NULL) | |
10713 | { | |
10714 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
10715 | bfd_vma toc_off = 0; | |
10716 | asection *i; | |
10717 | ||
10718 | for (i = o->map_head.s; i != NULL; i = i->map_head.s) | |
10719 | if (i->has_toc_reloc) | |
10720 | { | |
10721 | if (toc_off == 0) | |
10722 | toc_off = htab->stub_group[i->id].toc_off; | |
10723 | else if (toc_off != htab->stub_group[i->id].toc_off) | |
10724 | return FALSE; | |
10725 | } | |
6683a28d AM |
10726 | |
10727 | if (toc_off == 0) | |
10728 | for (i = o->map_head.s; i != NULL; i = i->map_head.s) | |
10729 | if (i->makes_toc_func_call) | |
10730 | { | |
10731 | toc_off = htab->stub_group[i->id].toc_off; | |
10732 | break; | |
10733 | } | |
10734 | ||
70cc837d AM |
10735 | /* Make sure the whole pasted function uses the same toc offset. */ |
10736 | if (toc_off != 0) | |
10737 | for (i = o->map_head.s; i != NULL; i = i->map_head.s) | |
10738 | htab->stub_group[i->id].toc_off = toc_off; | |
10739 | } | |
10740 | return TRUE; | |
10741 | } | |
10742 | ||
10743 | bfd_boolean | |
10744 | ppc64_elf_check_init_fini (struct bfd_link_info *info) | |
10745 | { | |
10746 | return (check_pasted_section (info, ".init") | |
10747 | & check_pasted_section (info, ".fini")); | |
10748 | } | |
10749 | ||
721956f4 AM |
10750 | /* See whether we can group stub sections together. Grouping stub |
10751 | sections may result in fewer stubs. More importantly, we need to | |
10752 | put all .init* and .fini* stubs at the beginning of the .init or | |
10753 | .fini output sections respectively, because glibc splits the | |
10754 | _init and _fini functions into multiple parts. Putting a stub in | |
10755 | the middle of a function is not a good idea. */ | |
10756 | ||
10757 | static void | |
4ce794b7 AM |
10758 | group_sections (struct ppc_link_hash_table *htab, |
10759 | bfd_size_type stub_group_size, | |
10760 | bfd_boolean stubs_always_before_branch) | |
721956f4 | 10761 | { |
7c8fe5c4 AM |
10762 | asection **list; |
10763 | bfd_size_type stub14_group_size; | |
10764 | bfd_boolean suppress_size_errors; | |
10765 | ||
10766 | suppress_size_errors = FALSE; | |
10767 | stub14_group_size = stub_group_size; | |
10768 | if (stub_group_size == 1) | |
10769 | { | |
10770 | /* Default values. */ | |
10771 | if (stubs_always_before_branch) | |
10772 | { | |
10773 | stub_group_size = 0x1e00000; | |
10774 | stub14_group_size = 0x7800; | |
10775 | } | |
10776 | else | |
10777 | { | |
10778 | stub_group_size = 0x1c00000; | |
10779 | stub14_group_size = 0x7000; | |
10780 | } | |
10781 | suppress_size_errors = TRUE; | |
10782 | } | |
10783 | ||
10784 | list = htab->input_list + htab->top_index; | |
734b6cf9 | 10785 | do |
721956f4 | 10786 | { |
734b6cf9 AM |
10787 | asection *tail = *list; |
10788 | while (tail != NULL) | |
721956f4 | 10789 | { |
734b6cf9 AM |
10790 | asection *curr; |
10791 | asection *prev; | |
10792 | bfd_size_type total; | |
10793 | bfd_boolean big_sec; | |
10794 | bfd_vma curr_toc; | |
10795 | ||
10796 | curr = tail; | |
eea6121a | 10797 | total = tail->size; |
6bee8834 AM |
10798 | big_sec = total > (ppc64_elf_section_data (tail) != NULL |
10799 | && ppc64_elf_section_data (tail)->has_14bit_branch | |
7c8fe5c4 AM |
10800 | ? stub14_group_size : stub_group_size); |
10801 | if (big_sec && !suppress_size_errors) | |
5c3dead3 AM |
10802 | (*_bfd_error_handler) (_("%B section %A exceeds stub group size"), |
10803 | tail->owner, tail); | |
734b6cf9 AM |
10804 | curr_toc = htab->stub_group[tail->id].toc_off; |
10805 | ||
10806 | while ((prev = PREV_SEC (curr)) != NULL | |
10807 | && ((total += curr->output_offset - prev->output_offset) | |
6bee8834 AM |
10808 | < (ppc64_elf_section_data (prev) != NULL |
10809 | && ppc64_elf_section_data (prev)->has_14bit_branch | |
7c8fe5c4 | 10810 | ? stub14_group_size : stub_group_size)) |
ad8e1ba5 | 10811 | && htab->stub_group[prev->id].toc_off == curr_toc) |
734b6cf9 AM |
10812 | curr = prev; |
10813 | ||
10814 | /* OK, the size from the start of CURR to the end is less | |
10815 | than stub_group_size and thus can be handled by one stub | |
10816 | section. (or the tail section is itself larger than | |
10817 | stub_group_size, in which case we may be toast.) We | |
10818 | should really be keeping track of the total size of stubs | |
10819 | added here, as stubs contribute to the final output | |
10820 | section size. That's a little tricky, and this way will | |
10821 | only break if stubs added make the total size more than | |
10822 | 2^25, ie. for the default stub_group_size, if stubs total | |
10823 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ | |
10824 | do | |
721956f4 AM |
10825 | { |
10826 | prev = PREV_SEC (tail); | |
734b6cf9 | 10827 | /* Set up this stub group. */ |
721956f4 AM |
10828 | htab->stub_group[tail->id].link_sec = curr; |
10829 | } | |
734b6cf9 AM |
10830 | while (tail != curr && (tail = prev) != NULL); |
10831 | ||
10832 | /* But wait, there's more! Input sections up to stub_group_size | |
10833 | bytes before the stub section can be handled by it too. | |
10834 | Don't do this if we have a really large section after the | |
10835 | stubs, as adding more stubs increases the chance that | |
10836 | branches may not reach into the stub section. */ | |
10837 | if (!stubs_always_before_branch && !big_sec) | |
10838 | { | |
10839 | total = 0; | |
10840 | while (prev != NULL | |
10841 | && ((total += tail->output_offset - prev->output_offset) | |
6bee8834 AM |
10842 | < (ppc64_elf_section_data (prev) != NULL |
10843 | && ppc64_elf_section_data (prev)->has_14bit_branch | |
7c8fe5c4 | 10844 | ? stub14_group_size : stub_group_size)) |
734b6cf9 AM |
10845 | && htab->stub_group[prev->id].toc_off == curr_toc) |
10846 | { | |
10847 | tail = prev; | |
10848 | prev = PREV_SEC (tail); | |
10849 | htab->stub_group[tail->id].link_sec = curr; | |
10850 | } | |
10851 | } | |
10852 | tail = prev; | |
721956f4 AM |
10853 | } |
10854 | } | |
734b6cf9 AM |
10855 | while (list-- != htab->input_list); |
10856 | free (htab->input_list); | |
721956f4 AM |
10857 | #undef PREV_SEC |
10858 | } | |
10859 | ||
58d180e8 AM |
10860 | static const unsigned char glink_eh_frame_cie[] = |
10861 | { | |
10862 | 0, 0, 0, 16, /* length. */ | |
10863 | 0, 0, 0, 0, /* id. */ | |
10864 | 1, /* CIE version. */ | |
10865 | 'z', 'R', 0, /* Augmentation string. */ | |
10866 | 4, /* Code alignment. */ | |
10867 | 0x78, /* Data alignment. */ | |
10868 | 65, /* RA reg. */ | |
10869 | 1, /* Augmentation size. */ | |
10870 | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */ | |
10871 | DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */ | |
10872 | }; | |
10873 | ||
721956f4 AM |
10874 | /* Determine and set the size of the stub section for a final link. |
10875 | ||
10876 | The basic idea here is to examine all the relocations looking for | |
10877 | PC-relative calls to a target that is unreachable with a "bl" | |
10878 | instruction. */ | |
10879 | ||
b34976b6 | 10880 | bfd_boolean |
9df0ef5f AM |
10881 | ppc64_elf_size_stubs (struct bfd_link_info *info, bfd_signed_vma group_size, |
10882 | bfd_boolean plt_static_chain) | |
721956f4 AM |
10883 | { |
10884 | bfd_size_type stub_group_size; | |
b34976b6 | 10885 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
10886 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
10887 | ||
4dfe6ac6 NC |
10888 | if (htab == NULL) |
10889 | return FALSE; | |
10890 | ||
9df0ef5f | 10891 | htab->plt_static_chain = plt_static_chain; |
721956f4 AM |
10892 | stubs_always_before_branch = group_size < 0; |
10893 | if (group_size < 0) | |
10894 | stub_group_size = -group_size; | |
10895 | else | |
10896 | stub_group_size = group_size; | |
721956f4 AM |
10897 | |
10898 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
10899 | ||
721956f4 AM |
10900 | while (1) |
10901 | { | |
10902 | bfd *input_bfd; | |
10903 | unsigned int bfd_indx; | |
10904 | asection *stub_sec; | |
721956f4 AM |
10905 | |
10906 | htab->stub_iteration += 1; | |
721956f4 AM |
10907 | |
10908 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
10909 | input_bfd != NULL; | |
10910 | input_bfd = input_bfd->link_next, bfd_indx++) | |
10911 | { | |
10912 | Elf_Internal_Shdr *symtab_hdr; | |
10913 | asection *section; | |
6cdc0ccc | 10914 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 | 10915 | |
0c8d6e5c | 10916 | if (!is_ppc64_elf (input_bfd)) |
67f93c31 AM |
10917 | continue; |
10918 | ||
721956f4 | 10919 | /* We'll need the symbol table in a second. */ |
0ffa91dd | 10920 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
721956f4 AM |
10921 | if (symtab_hdr->sh_info == 0) |
10922 | continue; | |
10923 | ||
721956f4 AM |
10924 | /* Walk over each section attached to the input bfd. */ |
10925 | for (section = input_bfd->sections; | |
10926 | section != NULL; | |
10927 | section = section->next) | |
10928 | { | |
721956f4 | 10929 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
10930 | |
10931 | /* If there aren't any relocs, then there's nothing more | |
10932 | to do. */ | |
10933 | if ((section->flags & SEC_RELOC) == 0 | |
12c0f757 AM |
10934 | || (section->flags & SEC_ALLOC) == 0 |
10935 | || (section->flags & SEC_LOAD) == 0 | |
10936 | || (section->flags & SEC_CODE) == 0 | |
721956f4 AM |
10937 | || section->reloc_count == 0) |
10938 | continue; | |
10939 | ||
10940 | /* If this section is a link-once section that will be | |
10941 | discarded, then don't create any stubs. */ | |
10942 | if (section->output_section == NULL | |
927be08e | 10943 | || section->output_section->owner != info->output_bfd) |
721956f4 AM |
10944 | continue; |
10945 | ||
1e2f5b6e AM |
10946 | /* Get the relocs. */ |
10947 | internal_relocs | |
4ce794b7 | 10948 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 10949 | info->keep_memory); |
721956f4 | 10950 | if (internal_relocs == NULL) |
1e2f5b6e | 10951 | goto error_ret_free_local; |
721956f4 AM |
10952 | |
10953 | /* Now examine each relocation. */ | |
10954 | irela = internal_relocs; | |
10955 | irelaend = irela + section->reloc_count; | |
10956 | for (; irela < irelaend; irela++) | |
10957 | { | |
4ce794b7 AM |
10958 | enum elf_ppc64_reloc_type r_type; |
10959 | unsigned int r_indx; | |
721956f4 AM |
10960 | enum ppc_stub_type stub_type; |
10961 | struct ppc_stub_hash_entry *stub_entry; | |
8387904d | 10962 | asection *sym_sec, *code_sec; |
e054468f | 10963 | bfd_vma sym_value, code_value; |
721956f4 | 10964 | bfd_vma destination; |
8843416a | 10965 | bfd_boolean ok_dest; |
721956f4 | 10966 | struct ppc_link_hash_entry *hash; |
8387904d | 10967 | struct ppc_link_hash_entry *fdh; |
411e1bfb AM |
10968 | struct elf_link_hash_entry *h; |
10969 | Elf_Internal_Sym *sym; | |
721956f4 AM |
10970 | char *stub_name; |
10971 | const asection *id_sec; | |
74f0fb50 | 10972 | struct _opd_sec_data *opd; |
e054468f | 10973 | struct plt_entry *plt_ent; |
721956f4 AM |
10974 | |
10975 | r_type = ELF64_R_TYPE (irela->r_info); | |
10976 | r_indx = ELF64_R_SYM (irela->r_info); | |
10977 | ||
4ce794b7 | 10978 | if (r_type >= R_PPC64_max) |
721956f4 AM |
10979 | { |
10980 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 10981 | goto error_ret_free_internal; |
721956f4 AM |
10982 | } |
10983 | ||
10984 | /* Only look for stubs on branch instructions. */ | |
4ce794b7 AM |
10985 | if (r_type != R_PPC64_REL24 |
10986 | && r_type != R_PPC64_REL14 | |
10987 | && r_type != R_PPC64_REL14_BRTAKEN | |
10988 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
721956f4 AM |
10989 | continue; |
10990 | ||
10991 | /* Now determine the call target, its name, value, | |
10992 | section. */ | |
411e1bfb AM |
10993 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
10994 | r_indx, input_bfd)) | |
10995 | goto error_ret_free_internal; | |
10996 | hash = (struct ppc_link_hash_entry *) h; | |
10997 | ||
8843416a | 10998 | ok_dest = FALSE; |
8387904d | 10999 | fdh = NULL; |
7fe2b9a6 | 11000 | sym_value = 0; |
411e1bfb | 11001 | if (hash == NULL) |
721956f4 | 11002 | { |
411e1bfb | 11003 | sym_value = sym->st_value; |
8843416a | 11004 | ok_dest = TRUE; |
721956f4 | 11005 | } |
7fe2b9a6 AM |
11006 | else if (hash->elf.root.type == bfd_link_hash_defined |
11007 | || hash->elf.root.type == bfd_link_hash_defweak) | |
11008 | { | |
11009 | sym_value = hash->elf.root.u.def.value; | |
11010 | if (sym_sec->output_section != NULL) | |
11011 | ok_dest = TRUE; | |
11012 | } | |
11013 | else if (hash->elf.root.type == bfd_link_hash_undefweak | |
11014 | || hash->elf.root.type == bfd_link_hash_undefined) | |
721956f4 | 11015 | { |
99877b66 | 11016 | /* Recognise an old ABI func code entry sym, and |
7fe2b9a6 AM |
11017 | use the func descriptor sym instead if it is |
11018 | defined. */ | |
ceb1f1ef | 11019 | if (hash->elf.root.root.string[0] == '.' |
b31867b6 | 11020 | && (fdh = lookup_fdh (hash, htab)) != NULL) |
8387904d | 11021 | { |
8387904d AM |
11022 | if (fdh->elf.root.type == bfd_link_hash_defined |
11023 | || fdh->elf.root.type == bfd_link_hash_defweak) | |
11024 | { | |
11025 | sym_sec = fdh->elf.root.u.def.section; | |
11026 | sym_value = fdh->elf.root.u.def.value; | |
11027 | if (sym_sec->output_section != NULL) | |
11028 | ok_dest = TRUE; | |
11029 | } | |
99877b66 AM |
11030 | else |
11031 | fdh = NULL; | |
8387904d | 11032 | } |
7fe2b9a6 AM |
11033 | } |
11034 | else | |
11035 | { | |
11036 | bfd_set_error (bfd_error_bad_value); | |
11037 | goto error_ret_free_internal; | |
721956f4 AM |
11038 | } |
11039 | ||
8843416a AM |
11040 | destination = 0; |
11041 | if (ok_dest) | |
11042 | { | |
11043 | sym_value += irela->r_addend; | |
11044 | destination = (sym_value | |
11045 | + sym_sec->output_offset | |
11046 | + sym_sec->output_section->vma); | |
11047 | } | |
11048 | ||
8387904d | 11049 | code_sec = sym_sec; |
e054468f | 11050 | code_value = sym_value; |
74f0fb50 AM |
11051 | opd = get_opd_info (sym_sec); |
11052 | if (opd != NULL) | |
8387904d AM |
11053 | { |
11054 | bfd_vma dest; | |
11055 | ||
74f0fb50 | 11056 | if (hash == NULL && opd->adjust != NULL) |
8387904d | 11057 | { |
74f0fb50 | 11058 | long adjust = opd->adjust[sym_value / 8]; |
8387904d AM |
11059 | if (adjust == -1) |
11060 | continue; | |
e054468f | 11061 | code_value += adjust; |
8387904d AM |
11062 | sym_value += adjust; |
11063 | } | |
11064 | dest = opd_entry_value (sym_sec, sym_value, | |
e054468f | 11065 | &code_sec, &code_value); |
8387904d AM |
11066 | if (dest != (bfd_vma) -1) |
11067 | { | |
11068 | destination = dest; | |
11069 | if (fdh != NULL) | |
11070 | { | |
11071 | /* Fixup old ABI sym to point at code | |
11072 | entry. */ | |
99877b66 | 11073 | hash->elf.root.type = bfd_link_hash_defweak; |
8387904d | 11074 | hash->elf.root.u.def.section = code_sec; |
e054468f | 11075 | hash->elf.root.u.def.value = code_value; |
8387904d AM |
11076 | } |
11077 | } | |
11078 | } | |
11079 | ||
721956f4 | 11080 | /* Determine what (if any) linker stub is needed. */ |
e054468f | 11081 | plt_ent = NULL; |
721956f4 | 11082 | stub_type = ppc_type_of_stub (section, irela, &hash, |
e054468f | 11083 | &plt_ent, destination); |
ad8e1ba5 AM |
11084 | |
11085 | if (stub_type != ppc_stub_plt_call) | |
11086 | { | |
11087 | /* Check whether we need a TOC adjusting stub. | |
11088 | Since the linker pastes together pieces from | |
11089 | different object files when creating the | |
11090 | _init and _fini functions, it may be that a | |
11091 | call to what looks like a local sym is in | |
11092 | fact a call needing a TOC adjustment. */ | |
8387904d AM |
11093 | if (code_sec != NULL |
11094 | && code_sec->output_section != NULL | |
11095 | && (htab->stub_group[code_sec->id].toc_off | |
9b5ecbd0 | 11096 | != htab->stub_group[section->id].toc_off) |
4c52953f AM |
11097 | && (code_sec->has_toc_reloc |
11098 | || code_sec->makes_toc_func_call)) | |
ad8e1ba5 AM |
11099 | stub_type = ppc_stub_long_branch_r2off; |
11100 | } | |
11101 | ||
721956f4 AM |
11102 | if (stub_type == ppc_stub_none) |
11103 | continue; | |
11104 | ||
411e1bfb AM |
11105 | /* __tls_get_addr calls might be eliminated. */ |
11106 | if (stub_type != ppc_stub_plt_call | |
11107 | && hash != NULL | |
8387904d AM |
11108 | && (hash == htab->tls_get_addr |
11109 | || hash == htab->tls_get_addr_fd) | |
411e1bfb AM |
11110 | && section->has_tls_reloc |
11111 | && irela != internal_relocs) | |
11112 | { | |
11113 | /* Get tls info. */ | |
f961d9dd | 11114 | unsigned char *tls_mask; |
411e1bfb | 11115 | |
3a71aa26 | 11116 | if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms, |
411e1bfb AM |
11117 | irela - 1, input_bfd)) |
11118 | goto error_ret_free_internal; | |
e7b938ca | 11119 | if (*tls_mask != 0) |
411e1bfb AM |
11120 | continue; |
11121 | } | |
11122 | ||
721956f4 AM |
11123 | /* Support for grouping stub sections. */ |
11124 | id_sec = htab->stub_group[section->id].link_sec; | |
11125 | ||
11126 | /* Get the name of this stub. */ | |
11127 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
11128 | if (!stub_name) | |
11129 | goto error_ret_free_internal; | |
11130 | ||
11131 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 11132 | stub_name, FALSE, FALSE); |
721956f4 AM |
11133 | if (stub_entry != NULL) |
11134 | { | |
11135 | /* The proper stub has already been created. */ | |
11136 | free (stub_name); | |
11137 | continue; | |
11138 | } | |
11139 | ||
25f53a85 | 11140 | stub_entry = ppc_add_stub (stub_name, section, info); |
721956f4 AM |
11141 | if (stub_entry == NULL) |
11142 | { | |
11143 | free (stub_name); | |
6cdc0ccc AM |
11144 | error_ret_free_internal: |
11145 | if (elf_section_data (section)->relocs == NULL) | |
11146 | free (internal_relocs); | |
11147 | error_ret_free_local: | |
11148 | if (local_syms != NULL | |
11149 | && (symtab_hdr->contents | |
11150 | != (unsigned char *) local_syms)) | |
11151 | free (local_syms); | |
b34976b6 | 11152 | return FALSE; |
721956f4 AM |
11153 | } |
11154 | ||
ad8e1ba5 | 11155 | stub_entry->stub_type = stub_type; |
e054468f AM |
11156 | if (stub_type != ppc_stub_plt_call) |
11157 | { | |
11158 | stub_entry->target_value = code_value; | |
11159 | stub_entry->target_section = code_sec; | |
11160 | } | |
11161 | else | |
11162 | { | |
11163 | stub_entry->target_value = sym_value; | |
11164 | stub_entry->target_section = sym_sec; | |
11165 | } | |
721956f4 | 11166 | stub_entry->h = hash; |
e054468f | 11167 | stub_entry->plt_ent = plt_ent; |
411e1bfb | 11168 | stub_entry->addend = irela->r_addend; |
ee75fd95 AM |
11169 | |
11170 | if (stub_entry->h != NULL) | |
11171 | htab->stub_globals += 1; | |
721956f4 AM |
11172 | } |
11173 | ||
11174 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 11175 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 11176 | free (internal_relocs); |
721956f4 | 11177 | } |
6cdc0ccc AM |
11178 | |
11179 | if (local_syms != NULL | |
11180 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
11181 | { | |
11182 | if (!info->keep_memory) | |
11183 | free (local_syms); | |
11184 | else | |
11185 | symtab_hdr->contents = (unsigned char *) local_syms; | |
11186 | } | |
721956f4 AM |
11187 | } |
11188 | ||
5c3dead3 | 11189 | /* We may have added some stubs. Find out the new size of the |
721956f4 AM |
11190 | stub sections. */ |
11191 | for (stub_sec = htab->stub_bfd->sections; | |
11192 | stub_sec != NULL; | |
11193 | stub_sec = stub_sec->next) | |
e717da7e | 11194 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
ee75fd95 | 11195 | { |
5c3dead3 | 11196 | stub_sec->rawsize = stub_sec->size; |
ee75fd95 AM |
11197 | stub_sec->size = 0; |
11198 | stub_sec->reloc_count = 0; | |
84f5d08e | 11199 | stub_sec->flags &= ~SEC_RELOC; |
ee75fd95 | 11200 | } |
eea6121a AM |
11201 | |
11202 | htab->brlt->size = 0; | |
84f5d08e AM |
11203 | htab->brlt->reloc_count = 0; |
11204 | htab->brlt->flags &= ~SEC_RELOC; | |
ee75fd95 | 11205 | if (htab->relbrlt != NULL) |
eea6121a | 11206 | htab->relbrlt->size = 0; |
721956f4 | 11207 | |
63bc6f6c | 11208 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info); |
721956f4 | 11209 | |
176a0d42 AM |
11210 | if (info->emitrelocations |
11211 | && htab->glink != NULL && htab->glink->size != 0) | |
11212 | { | |
11213 | htab->glink->reloc_count = 1; | |
11214 | htab->glink->flags |= SEC_RELOC; | |
11215 | } | |
11216 | ||
58d180e8 AM |
11217 | if (htab->glink_eh_frame != NULL |
11218 | && !bfd_is_abs_section (htab->glink_eh_frame->output_section) | |
11219 | && (htab->glink_eh_frame->flags & SEC_EXCLUDE) == 0) | |
11220 | { | |
11221 | bfd_size_type size = 0; | |
11222 | ||
11223 | for (stub_sec = htab->stub_bfd->sections; | |
11224 | stub_sec != NULL; | |
11225 | stub_sec = stub_sec->next) | |
11226 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) | |
11227 | size += 20; | |
11228 | if (htab->glink != NULL && htab->glink->size != 0) | |
11229 | size += 24; | |
11230 | if (size != 0) | |
11231 | size += sizeof (glink_eh_frame_cie); | |
11232 | htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size; | |
11233 | htab->glink_eh_frame->size = size; | |
11234 | } | |
11235 | ||
5c3dead3 AM |
11236 | for (stub_sec = htab->stub_bfd->sections; |
11237 | stub_sec != NULL; | |
11238 | stub_sec = stub_sec->next) | |
11239 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0 | |
11240 | && stub_sec->rawsize != stub_sec->size) | |
11241 | break; | |
11242 | ||
11243 | /* Exit from this loop when no stubs have been added, and no stubs | |
11244 | have changed size. */ | |
58d180e8 AM |
11245 | if (stub_sec == NULL |
11246 | && (htab->glink_eh_frame == NULL | |
11247 | || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size)) | |
5c3dead3 AM |
11248 | break; |
11249 | ||
721956f4 AM |
11250 | /* Ask the linker to do its stuff. */ |
11251 | (*htab->layout_sections_again) (); | |
11252 | } | |
11253 | ||
c456f082 | 11254 | /* It would be nice to strip htab->brlt from the output if the |
afbe61cf AM |
11255 | section is empty, but it's too late. If we strip sections here, |
11256 | the dynamic symbol table is corrupted since the section symbol | |
11257 | for the stripped section isn't written. */ | |
721956f4 | 11258 | |
b34976b6 | 11259 | return TRUE; |
721956f4 AM |
11260 | } |
11261 | ||
11262 | /* Called after we have determined section placement. If sections | |
805fc799 | 11263 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 11264 | |
805fc799 | 11265 | bfd_vma |
4ce794b7 | 11266 | ppc64_elf_toc (bfd *obfd) |
721956f4 | 11267 | { |
805fc799 AM |
11268 | asection *s; |
11269 | bfd_vma TOCstart; | |
721956f4 | 11270 | |
805fc799 AM |
11271 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
11272 | order. The TOC starts where the first of these sections starts. */ | |
11273 | s = bfd_get_section_by_name (obfd, ".got"); | |
e054468f | 11274 | if (s == NULL || (s->flags & SEC_EXCLUDE) != 0) |
805fc799 | 11275 | s = bfd_get_section_by_name (obfd, ".toc"); |
e054468f | 11276 | if (s == NULL || (s->flags & SEC_EXCLUDE) != 0) |
805fc799 | 11277 | s = bfd_get_section_by_name (obfd, ".tocbss"); |
e054468f | 11278 | if (s == NULL || (s->flags & SEC_EXCLUDE) != 0) |
805fc799 | 11279 | s = bfd_get_section_by_name (obfd, ".plt"); |
e054468f | 11280 | if (s == NULL || (s->flags & SEC_EXCLUDE) != 0) |
805fc799 AM |
11281 | { |
11282 | /* This may happen for | |
11283 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
11284 | .toc directive | |
11285 | o bad linker script | |
11286 | o --gc-sections and empty TOC sections | |
11287 | ||
11288 | FIXME: Warn user? */ | |
11289 | ||
11290 | /* Look for a likely section. We probably won't even be | |
11291 | using TOCstart. */ | |
11292 | for (s = obfd->sections; s != NULL; s = s->next) | |
e054468f AM |
11293 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY |
11294 | | SEC_EXCLUDE)) | |
805fc799 AM |
11295 | == (SEC_ALLOC | SEC_SMALL_DATA)) |
11296 | break; | |
721956f4 | 11297 | if (s == NULL) |
805fc799 | 11298 | for (s = obfd->sections; s != NULL; s = s->next) |
e054468f | 11299 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_EXCLUDE)) |
805fc799 AM |
11300 | == (SEC_ALLOC | SEC_SMALL_DATA)) |
11301 | break; | |
721956f4 | 11302 | if (s == NULL) |
805fc799 | 11303 | for (s = obfd->sections; s != NULL; s = s->next) |
e054468f AM |
11304 | if ((s->flags & (SEC_ALLOC | SEC_READONLY | SEC_EXCLUDE)) |
11305 | == SEC_ALLOC) | |
805fc799 | 11306 | break; |
721956f4 | 11307 | if (s == NULL) |
805fc799 | 11308 | for (s = obfd->sections; s != NULL; s = s->next) |
e054468f | 11309 | if ((s->flags & (SEC_ALLOC | SEC_EXCLUDE)) == SEC_ALLOC) |
805fc799 AM |
11310 | break; |
11311 | } | |
721956f4 | 11312 | |
805fc799 AM |
11313 | TOCstart = 0; |
11314 | if (s != NULL) | |
11315 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 11316 | |
805fc799 | 11317 | return TOCstart; |
721956f4 AM |
11318 | } |
11319 | ||
11320 | /* Build all the stubs associated with the current output file. | |
11321 | The stubs are kept in a hash table attached to the main linker | |
11322 | hash table. This function is called via gldelf64ppc_finish. */ | |
11323 | ||
b34976b6 | 11324 | bfd_boolean |
4ce794b7 AM |
11325 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
11326 | struct bfd_link_info *info, | |
11327 | char **stats) | |
5d1634d7 AM |
11328 | { |
11329 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 11330 | asection *stub_sec; |
5d1634d7 | 11331 | bfd_byte *p; |
e717da7e | 11332 | int stub_sec_count = 0; |
5d1634d7 | 11333 | |
4dfe6ac6 NC |
11334 | if (htab == NULL) |
11335 | return FALSE; | |
11336 | ||
ad8e1ba5 | 11337 | htab->emit_stub_syms = emit_stub_syms; |
eea6121a AM |
11338 | |
11339 | /* Allocate memory to hold the linker stubs. */ | |
721956f4 AM |
11340 | for (stub_sec = htab->stub_bfd->sections; |
11341 | stub_sec != NULL; | |
11342 | stub_sec = stub_sec->next) | |
eea6121a AM |
11343 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0 |
11344 | && stub_sec->size != 0) | |
e717da7e | 11345 | { |
eea6121a AM |
11346 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size); |
11347 | if (stub_sec->contents == NULL) | |
11348 | return FALSE; | |
11349 | /* We want to check that built size is the same as calculated | |
11350 | size. rawsize is a convenient location to use. */ | |
11351 | stub_sec->rawsize = stub_sec->size; | |
11352 | stub_sec->size = 0; | |
e717da7e | 11353 | } |
5d1634d7 | 11354 | |
23eb7e01 | 11355 | if (htab->glink != NULL && htab->glink->size != 0) |
5d1634d7 | 11356 | { |
9f951329 | 11357 | unsigned int indx; |
ad8e1ba5 | 11358 | bfd_vma plt0; |
9f951329 | 11359 | |
721956f4 | 11360 | /* Build the .glink plt call stub. */ |
97b639ba AM |
11361 | if (htab->emit_stub_syms) |
11362 | { | |
11363 | struct elf_link_hash_entry *h; | |
468392fb AM |
11364 | h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve", |
11365 | TRUE, FALSE, FALSE); | |
97b639ba AM |
11366 | if (h == NULL) |
11367 | return FALSE; | |
11368 | if (h->root.type == bfd_link_hash_new) | |
11369 | { | |
11370 | h->root.type = bfd_link_hash_defined; | |
11371 | h->root.u.def.section = htab->glink; | |
ee4bf8d2 | 11372 | h->root.u.def.value = 8; |
f5385ebf AM |
11373 | h->ref_regular = 1; |
11374 | h->def_regular = 1; | |
11375 | h->ref_regular_nonweak = 1; | |
11376 | h->forced_local = 1; | |
11377 | h->non_elf = 0; | |
97b639ba AM |
11378 | } |
11379 | } | |
176a0d42 AM |
11380 | plt0 = htab->plt->output_section->vma + htab->plt->output_offset - 16; |
11381 | if (info->emitrelocations) | |
11382 | { | |
11383 | Elf_Internal_Rela *r = get_relocs (htab->glink, 1); | |
11384 | if (r == NULL) | |
11385 | return FALSE; | |
11386 | r->r_offset = (htab->glink->output_offset | |
11387 | + htab->glink->output_section->vma); | |
11388 | r->r_info = ELF64_R_INFO (0, R_PPC64_REL64); | |
11389 | r->r_addend = plt0; | |
11390 | } | |
4ce794b7 | 11391 | p = htab->glink->contents; |
176a0d42 | 11392 | plt0 -= htab->glink->output_section->vma + htab->glink->output_offset; |
ee4bf8d2 AM |
11393 | bfd_put_64 (htab->glink->owner, plt0, p); |
11394 | p += 8; | |
11395 | bfd_put_32 (htab->glink->owner, MFLR_R12, p); | |
ad8e1ba5 | 11396 | p += 4; |
ee4bf8d2 | 11397 | bfd_put_32 (htab->glink->owner, BCL_20_31, p); |
ad8e1ba5 | 11398 | p += 4; |
ee4bf8d2 | 11399 | bfd_put_32 (htab->glink->owner, MFLR_R11, p); |
ad8e1ba5 | 11400 | p += 4; |
ee4bf8d2 | 11401 | bfd_put_32 (htab->glink->owner, LD_R2_M16R11, p); |
ad8e1ba5 | 11402 | p += 4; |
ee4bf8d2 | 11403 | bfd_put_32 (htab->glink->owner, MTLR_R12, p); |
ad8e1ba5 | 11404 | p += 4; |
ee4bf8d2 | 11405 | bfd_put_32 (htab->glink->owner, ADD_R12_R2_R11, p); |
ad8e1ba5 | 11406 | p += 4; |
ee4bf8d2 | 11407 | bfd_put_32 (htab->glink->owner, LD_R11_0R12, p); |
ad8e1ba5 | 11408 | p += 4; |
4ce794b7 | 11409 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
ad8e1ba5 | 11410 | p += 4; |
4ce794b7 | 11411 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
ad8e1ba5 | 11412 | p += 4; |
4ce794b7 | 11413 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
ad8e1ba5 | 11414 | p += 4; |
4ce794b7 | 11415 | bfd_put_32 (htab->glink->owner, BCTR, p); |
ad8e1ba5 | 11416 | p += 4; |
ee4bf8d2 AM |
11417 | while (p - htab->glink->contents < GLINK_CALL_STUB_SIZE) |
11418 | { | |
11419 | bfd_put_32 (htab->glink->owner, NOP, p); | |
11420 | p += 4; | |
11421 | } | |
ad8e1ba5 | 11422 | |
9f951329 AM |
11423 | /* Build the .glink lazy link call stubs. */ |
11424 | indx = 0; | |
eea6121a | 11425 | while (p < htab->glink->contents + htab->glink->size) |
9f951329 AM |
11426 | { |
11427 | if (indx < 0x8000) | |
11428 | { | |
4ce794b7 | 11429 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
9f951329 AM |
11430 | p += 4; |
11431 | } | |
11432 | else | |
11433 | { | |
4ce794b7 | 11434 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
9f951329 | 11435 | p += 4; |
4ce794b7 | 11436 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
9f951329 AM |
11437 | p += 4; |
11438 | } | |
4ce794b7 | 11439 | bfd_put_32 (htab->glink->owner, |
ee4bf8d2 | 11440 | B_DOT | ((htab->glink->contents - p + 8) & 0x3fffffc), p); |
a16d5acb | 11441 | indx++; |
9f951329 AM |
11442 | p += 4; |
11443 | } | |
eea6121a | 11444 | htab->glink->rawsize = p - htab->glink->contents; |
5d1634d7 | 11445 | } |
5d1634d7 | 11446 | |
eea6121a | 11447 | if (htab->brlt->size != 0) |
721956f4 | 11448 | { |
4ce794b7 | 11449 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
eea6121a | 11450 | htab->brlt->size); |
4ce794b7 | 11451 | if (htab->brlt->contents == NULL) |
b34976b6 | 11452 | return FALSE; |
721956f4 | 11453 | } |
ee75fd95 | 11454 | if (htab->relbrlt != NULL && htab->relbrlt->size != 0) |
63bc6f6c AM |
11455 | { |
11456 | htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner, | |
eea6121a | 11457 | htab->relbrlt->size); |
63bc6f6c AM |
11458 | if (htab->relbrlt->contents == NULL) |
11459 | return FALSE; | |
11460 | } | |
5d1634d7 | 11461 | |
58d180e8 AM |
11462 | if (htab->glink_eh_frame != NULL |
11463 | && htab->glink_eh_frame->size != 0) | |
11464 | { | |
11465 | bfd_vma val; | |
11466 | ||
11467 | p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size); | |
11468 | if (p == NULL) | |
11469 | return FALSE; | |
11470 | htab->glink_eh_frame->contents = p; | |
11471 | ||
11472 | htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size; | |
11473 | ||
11474 | memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie)); | |
11475 | /* CIE length (rewrite in case little-endian). */ | |
11476 | bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p); | |
11477 | p += sizeof (glink_eh_frame_cie); | |
11478 | ||
11479 | for (stub_sec = htab->stub_bfd->sections; | |
11480 | stub_sec != NULL; | |
11481 | stub_sec = stub_sec->next) | |
11482 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) | |
11483 | { | |
11484 | /* FDE length. */ | |
11485 | bfd_put_32 (htab->elf.dynobj, 16, p); | |
11486 | p += 4; | |
11487 | /* CIE pointer. */ | |
11488 | val = p - htab->glink_eh_frame->contents; | |
11489 | bfd_put_32 (htab->elf.dynobj, val, p); | |
11490 | p += 4; | |
11491 | /* Offset to stub section. */ | |
11492 | val = (stub_sec->output_section->vma | |
11493 | + stub_sec->output_offset); | |
11494 | val -= (htab->glink_eh_frame->output_section->vma | |
11495 | + htab->glink_eh_frame->output_offset); | |
11496 | val -= p - htab->glink_eh_frame->contents; | |
11497 | if (val + 0x80000000 > 0xffffffff) | |
11498 | { | |
11499 | info->callbacks->einfo | |
11500 | (_("%s offset too large for .eh_frame sdata4 encoding"), | |
11501 | stub_sec->name); | |
11502 | return FALSE; | |
11503 | } | |
11504 | bfd_put_32 (htab->elf.dynobj, val, p); | |
11505 | p += 4; | |
11506 | /* stub section size. */ | |
11507 | bfd_put_32 (htab->elf.dynobj, stub_sec->rawsize, p); | |
11508 | p += 4; | |
11509 | /* Augmentation. */ | |
11510 | p += 1; | |
11511 | /* Pad. */ | |
11512 | p += 3; | |
11513 | } | |
11514 | if (htab->glink != NULL && htab->glink->size != 0) | |
11515 | { | |
11516 | /* FDE length. */ | |
11517 | bfd_put_32 (htab->elf.dynobj, 20, p); | |
11518 | p += 4; | |
11519 | /* CIE pointer. */ | |
11520 | val = p - htab->glink_eh_frame->contents; | |
11521 | bfd_put_32 (htab->elf.dynobj, val, p); | |
11522 | p += 4; | |
11523 | /* Offset to .glink. */ | |
11524 | val = (htab->glink->output_section->vma | |
11525 | + htab->glink->output_offset | |
11526 | + 8); | |
11527 | val -= (htab->glink_eh_frame->output_section->vma | |
11528 | + htab->glink_eh_frame->output_offset); | |
11529 | val -= p - htab->glink_eh_frame->contents; | |
11530 | if (val + 0x80000000 > 0xffffffff) | |
11531 | { | |
11532 | info->callbacks->einfo | |
11533 | (_("%s offset too large for .eh_frame sdata4 encoding"), | |
11534 | htab->glink->name); | |
11535 | return FALSE; | |
11536 | } | |
11537 | bfd_put_32 (htab->elf.dynobj, val, p); | |
11538 | p += 4; | |
11539 | /* .glink size. */ | |
11540 | bfd_put_32 (htab->elf.dynobj, htab->glink->rawsize - 8, p); | |
11541 | p += 4; | |
11542 | /* Augmentation. */ | |
11543 | p += 1; | |
11544 | ||
11545 | *p++ = DW_CFA_advance_loc + 1; | |
11546 | *p++ = DW_CFA_register; | |
11547 | *p++ = 65; | |
11548 | *p++ = 12; | |
11549 | *p++ = DW_CFA_advance_loc + 4; | |
11550 | *p++ = DW_CFA_restore_extended; | |
11551 | *p++ = 65; | |
11552 | } | |
11553 | htab->glink_eh_frame->size = p - htab->glink_eh_frame->contents; | |
11554 | } | |
11555 | ||
721956f4 AM |
11556 | /* Build the stubs as directed by the stub hash table. */ |
11557 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 11558 | |
aa8a7074 AM |
11559 | if (htab->relbrlt != NULL) |
11560 | htab->relbrlt->reloc_count = 0; | |
11561 | ||
721956f4 AM |
11562 | for (stub_sec = htab->stub_bfd->sections; |
11563 | stub_sec != NULL; | |
11564 | stub_sec = stub_sec->next) | |
e717da7e AM |
11565 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
11566 | { | |
11567 | stub_sec_count += 1; | |
eea6121a | 11568 | if (stub_sec->rawsize != stub_sec->size) |
e717da7e AM |
11569 | break; |
11570 | } | |
5d1634d7 | 11571 | |
721956f4 | 11572 | if (stub_sec != NULL |
58d180e8 AM |
11573 | || htab->glink->rawsize != htab->glink->size |
11574 | || (htab->glink_eh_frame != NULL | |
11575 | && htab->glink_eh_frame->rawsize != htab->glink_eh_frame->size)) | |
5d1634d7 | 11576 | { |
b34976b6 | 11577 | htab->stub_error = TRUE; |
25f53a85 | 11578 | info->callbacks->einfo (_("stubs don't match calculated size\n")); |
5d1634d7 | 11579 | } |
721956f4 | 11580 | |
d2a300cf AM |
11581 | if (htab->stub_error) |
11582 | return FALSE; | |
11583 | ||
11584 | if (stats != NULL) | |
11585 | { | |
11586 | *stats = bfd_malloc (500); | |
11587 | if (*stats == NULL) | |
11588 | return FALSE; | |
11589 | ||
ee75fd95 | 11590 | sprintf (*stats, _("linker stubs in %u group%s\n" |
d2a300cf AM |
11591 | " branch %lu\n" |
11592 | " toc adjust %lu\n" | |
11593 | " long branch %lu\n" | |
11594 | " long toc adj %lu\n" | |
11595 | " plt call %lu"), | |
e717da7e | 11596 | stub_sec_count, |
ee75fd95 | 11597 | stub_sec_count == 1 ? "" : "s", |
4ce794b7 AM |
11598 | htab->stub_count[ppc_stub_long_branch - 1], |
11599 | htab->stub_count[ppc_stub_long_branch_r2off - 1], | |
11600 | htab->stub_count[ppc_stub_plt_branch - 1], | |
11601 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], | |
11602 | htab->stub_count[ppc_stub_plt_call - 1]); | |
d2a300cf AM |
11603 | } |
11604 | return TRUE; | |
5bd4f169 AM |
11605 | } |
11606 | ||
99877b66 AM |
11607 | /* This function undoes the changes made by add_symbol_adjust. */ |
11608 | ||
11609 | static bfd_boolean | |
11610 | undo_symbol_twiddle (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
11611 | { | |
11612 | struct ppc_link_hash_entry *eh; | |
11613 | ||
11614 | if (h->root.type == bfd_link_hash_indirect) | |
11615 | return TRUE; | |
11616 | ||
99877b66 AM |
11617 | eh = (struct ppc_link_hash_entry *) h; |
11618 | if (eh->elf.root.type != bfd_link_hash_undefweak || !eh->was_undefined) | |
11619 | return TRUE; | |
11620 | ||
11621 | eh->elf.root.type = bfd_link_hash_undefined; | |
11622 | return TRUE; | |
11623 | } | |
11624 | ||
11625 | void | |
11626 | ppc64_elf_restore_symbols (struct bfd_link_info *info) | |
11627 | { | |
11628 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
4dfe6ac6 NC |
11629 | |
11630 | if (htab != NULL) | |
11631 | elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info); | |
99877b66 AM |
11632 | } |
11633 | ||
60124e18 AM |
11634 | /* What to do when ld finds relocations against symbols defined in |
11635 | discarded sections. */ | |
11636 | ||
11637 | static unsigned int | |
11638 | ppc64_elf_action_discarded (asection *sec) | |
11639 | { | |
11640 | if (strcmp (".opd", sec->name) == 0) | |
11641 | return 0; | |
11642 | ||
11643 | if (strcmp (".toc", sec->name) == 0) | |
11644 | return 0; | |
11645 | ||
bce50a28 JJ |
11646 | if (strcmp (".toc1", sec->name) == 0) |
11647 | return 0; | |
11648 | ||
60124e18 AM |
11649 | return _bfd_elf_default_action_discarded (sec); |
11650 | } | |
11651 | ||
ba761f19 | 11652 | /* REL points to a low-part reloc on a largetoc instruction sequence. |
67f0cbdb | 11653 | Find the matching high-part reloc instruction and verify that it |
d983b7a0 AM |
11654 | is addis REG,x,imm. If so, set *REG to x and return a pointer to |
11655 | the high-part reloc. */ | |
67f0cbdb AM |
11656 | |
11657 | static const Elf_Internal_Rela * | |
11658 | ha_reloc_match (const Elf_Internal_Rela *relocs, | |
11659 | const Elf_Internal_Rela *rel, | |
d983b7a0 AM |
11660 | unsigned int *reg, |
11661 | bfd_boolean match_addend, | |
67f0cbdb AM |
11662 | const bfd *input_bfd, |
11663 | const bfd_byte *contents) | |
11664 | { | |
11665 | enum elf_ppc64_reloc_type r_type, r_type_ha; | |
11666 | bfd_vma r_info_ha, r_addend; | |
11667 | ||
11668 | r_type = ELF64_R_TYPE (rel->r_info); | |
11669 | switch (r_type) | |
11670 | { | |
11671 | case R_PPC64_GOT_TLSLD16_LO: | |
11672 | case R_PPC64_GOT_TLSGD16_LO: | |
11673 | case R_PPC64_GOT_TPREL16_LO_DS: | |
11674 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
11675 | case R_PPC64_GOT16_LO: | |
11676 | case R_PPC64_TOC16_LO: | |
11677 | r_type_ha = r_type + 2; | |
11678 | break; | |
11679 | case R_PPC64_GOT16_LO_DS: | |
11680 | r_type_ha = R_PPC64_GOT16_HA; | |
11681 | break; | |
11682 | case R_PPC64_TOC16_LO_DS: | |
11683 | r_type_ha = R_PPC64_TOC16_HA; | |
11684 | break; | |
11685 | default: | |
11686 | abort (); | |
11687 | } | |
11688 | r_info_ha = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), r_type_ha); | |
11689 | r_addend = rel->r_addend; | |
11690 | ||
11691 | while (--rel >= relocs) | |
11692 | if (rel->r_info == r_info_ha | |
d983b7a0 AM |
11693 | && (!match_addend |
11694 | || rel->r_addend == r_addend)) | |
67f0cbdb AM |
11695 | { |
11696 | const bfd_byte *p = contents + (rel->r_offset & ~3); | |
11697 | unsigned int insn = bfd_get_32 (input_bfd, p); | |
d983b7a0 AM |
11698 | if ((insn & (0x3f << 26)) == (15u << 26) /* addis rt,x,imm */ |
11699 | && (insn & (0x1f << 21)) == (*reg << 21)) | |
11700 | { | |
11701 | *reg = (insn >> 16) & 0x1f; | |
11702 | return rel; | |
11703 | } | |
67f0cbdb AM |
11704 | break; |
11705 | } | |
11706 | return NULL; | |
11707 | } | |
11708 | ||
5bd4f169 AM |
11709 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
11710 | to handle the relocations for a section. | |
11711 | ||
11712 | The relocs are always passed as Rela structures; if the section | |
11713 | actually uses Rel structures, the r_addend field will always be | |
11714 | zero. | |
11715 | ||
11716 | This function is responsible for adjust the section contents as | |
11717 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 11718 | relocatable output file) adjusting the reloc addend as |
5bd4f169 AM |
11719 | necessary. |
11720 | ||
11721 | This function does not have to worry about setting the reloc | |
11722 | address or the reloc symbol index. | |
11723 | ||
11724 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
11725 | ||
11726 | LOCAL_SECTIONS is an array giving the section in the input file | |
11727 | corresponding to the st_shndx field of each local symbol. | |
11728 | ||
11729 | The global hash table entry for the global symbols can be found | |
11730 | via elf_sym_hashes (input_bfd). | |
11731 | ||
1049f94e | 11732 | When generating relocatable output, this function must handle |
5bd4f169 AM |
11733 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
11734 | going to be the section symbol corresponding to the output | |
11735 | section, which means that the addend must be adjusted | |
11736 | accordingly. */ | |
11737 | ||
b34976b6 | 11738 | static bfd_boolean |
4ce794b7 AM |
11739 | ppc64_elf_relocate_section (bfd *output_bfd, |
11740 | struct bfd_link_info *info, | |
11741 | bfd *input_bfd, | |
11742 | asection *input_section, | |
11743 | bfd_byte *contents, | |
11744 | Elf_Internal_Rela *relocs, | |
11745 | Elf_Internal_Sym *local_syms, | |
11746 | asection **local_sections) | |
5bd4f169 | 11747 | { |
65f38f15 | 11748 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
11749 | Elf_Internal_Shdr *symtab_hdr; |
11750 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
11751 | Elf_Internal_Rela *rel; |
11752 | Elf_Internal_Rela *relend; | |
411e1bfb AM |
11753 | Elf_Internal_Rela outrel; |
11754 | bfd_byte *loc; | |
411e1bfb | 11755 | struct got_entry **local_got_ents; |
d983b7a0 | 11756 | unsigned char *ha_opt; |
5bd4f169 | 11757 | bfd_vma TOCstart; |
d983b7a0 | 11758 | bfd_boolean no_ha_opt; |
b34976b6 AM |
11759 | bfd_boolean ret = TRUE; |
11760 | bfd_boolean is_opd; | |
96e0dda4 | 11761 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 11762 | bfd_boolean is_power4 = FALSE; |
4fe5ca5b | 11763 | bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0); |
5bd4f169 | 11764 | |
65f38f15 | 11765 | /* Initialize howto table if needed. */ |
5bd4f169 | 11766 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
11767 | ppc_howto_init (); |
11768 | ||
65f38f15 | 11769 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
11770 | if (htab == NULL) |
11771 | return FALSE; | |
ee75fd95 AM |
11772 | |
11773 | /* Don't relocate stub sections. */ | |
11774 | if (input_section->owner == htab->stub_bfd) | |
11775 | return TRUE; | |
11776 | ||
0c8d6e5c | 11777 | BFD_ASSERT (is_ppc64_elf (input_bfd)); |
0ffa91dd | 11778 | |
411e1bfb | 11779 | local_got_ents = elf_local_got_ents (input_bfd); |
5bd4f169 | 11780 | TOCstart = elf_gp (output_bfd); |
0ffa91dd | 11781 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
5bd4f169 | 11782 | sym_hashes = elf_sym_hashes (input_bfd); |
7c8fe5c4 | 11783 | is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd; |
d983b7a0 AM |
11784 | ha_opt = NULL; |
11785 | no_ha_opt = FALSE; | |
65f38f15 | 11786 | |
5bd4f169 AM |
11787 | rel = relocs; |
11788 | relend = relocs + input_section->reloc_count; | |
11789 | for (; rel < relend; rel++) | |
11790 | { | |
04c9666a | 11791 | enum elf_ppc64_reloc_type r_type; |
4cc603a5 | 11792 | bfd_vma addend, orig_addend; |
5bd4f169 AM |
11793 | bfd_reloc_status_type r; |
11794 | Elf_Internal_Sym *sym; | |
11795 | asection *sec; | |
039b3fef AM |
11796 | struct elf_link_hash_entry *h_elf; |
11797 | struct ppc_link_hash_entry *h; | |
11798 | struct ppc_link_hash_entry *fdh; | |
5bd4f169 | 11799 | const char *sym_name; |
0d4792f7 | 11800 | unsigned long r_symndx, toc_symndx; |
3a71aa26 | 11801 | bfd_vma toc_addend; |
f961d9dd AM |
11802 | unsigned char tls_mask, tls_gd, tls_type; |
11803 | unsigned char sym_type; | |
5bd4f169 | 11804 | bfd_vma relocation; |
b34976b6 AM |
11805 | bfd_boolean unresolved_reloc; |
11806 | bfd_boolean warned; | |
67f0cbdb | 11807 | unsigned int insn; |
e11840f9 | 11808 | unsigned int mask; |
721956f4 AM |
11809 | struct ppc_stub_hash_entry *stub_entry; |
11810 | bfd_vma max_br_offset; | |
11811 | bfd_vma from; | |
5bd4f169 | 11812 | |
4ce794b7 | 11813 | r_type = ELF64_R_TYPE (rel->r_info); |
5bd4f169 | 11814 | r_symndx = ELF64_R_SYM (rel->r_info); |
ee87f2da AM |
11815 | |
11816 | /* For old style R_PPC64_TOC relocs with a zero symbol, use the | |
11817 | symbol of the previous ADDR64 reloc. The symbol gives us the | |
11818 | proper TOC base to use. */ | |
11819 | if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC) | |
11820 | && rel != relocs | |
11821 | && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64 | |
11822 | && is_opd) | |
11823 | r_symndx = ELF64_R_SYM (rel[-1].r_info); | |
11824 | ||
4ce794b7 AM |
11825 | sym = NULL; |
11826 | sec = NULL; | |
039b3fef | 11827 | h_elf = NULL; |
4ce794b7 | 11828 | sym_name = NULL; |
b34976b6 AM |
11829 | unresolved_reloc = FALSE; |
11830 | warned = FALSE; | |
4cc603a5 | 11831 | orig_addend = rel->r_addend; |
65f38f15 | 11832 | |
0b13192e | 11833 | if (r_symndx < symtab_hdr->sh_info) |
5bd4f169 AM |
11834 | { |
11835 | /* It's a local symbol. */ | |
74f0fb50 | 11836 | struct _opd_sec_data *opd; |
4025353c | 11837 | |
5bd4f169 AM |
11838 | sym = local_syms + r_symndx; |
11839 | sec = local_sections[r_symndx]; | |
26c61ae5 | 11840 | sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec); |
0d4792f7 | 11841 | sym_type = ELF64_ST_TYPE (sym->st_info); |
8517fae7 | 11842 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
74f0fb50 AM |
11843 | opd = get_opd_info (sec); |
11844 | if (opd != NULL && opd->adjust != NULL) | |
1e2f5b6e | 11845 | { |
74f0fb50 | 11846 | long adjust = opd->adjust[(sym->st_value + rel->r_addend) / 8]; |
4025353c AM |
11847 | if (adjust == -1) |
11848 | relocation = 0; | |
11849 | else | |
4cc603a5 AM |
11850 | { |
11851 | /* If this is a relocation against the opd section sym | |
11852 | and we have edited .opd, adjust the reloc addend so | |
11853 | that ld -r and ld --emit-relocs output is correct. | |
11854 | If it is a reloc against some other .opd symbol, | |
11855 | then the symbol value will be adjusted later. */ | |
11856 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
11857 | rel->r_addend += adjust; | |
11858 | else | |
11859 | relocation += adjust; | |
11860 | } | |
1e2f5b6e | 11861 | } |
5bd4f169 AM |
11862 | } |
11863 | else | |
11864 | { | |
b2a8e766 AM |
11865 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
11866 | r_symndx, symtab_hdr, sym_hashes, | |
039b3fef | 11867 | h_elf, sec, relocation, |
b2a8e766 | 11868 | unresolved_reloc, warned); |
039b3fef AM |
11869 | sym_name = h_elf->root.root.string; |
11870 | sym_type = h_elf->type; | |
5bd4f169 | 11871 | } |
039b3fef | 11872 | h = (struct ppc_link_hash_entry *) h_elf; |
5bd4f169 | 11873 | |
ab96bf03 | 11874 | if (sec != NULL && elf_discarded_section (sec)) |
e4067dbb DJ |
11875 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
11876 | rel, relend, | |
11877 | ppc64_elf_howto_table[r_type], | |
11878 | contents); | |
ab96bf03 AM |
11879 | |
11880 | if (info->relocatable) | |
11881 | continue; | |
11882 | ||
951fd09b AM |
11883 | /* TLS optimizations. Replace instruction sequences and relocs |
11884 | based on information we collected in tls_optimize. We edit | |
11885 | RELOCS so that --emit-relocs will output something sensible | |
11886 | for the final instruction stream. */ | |
11887 | tls_mask = 0; | |
11888 | tls_gd = 0; | |
0d4792f7 | 11889 | toc_symndx = 0; |
727fc41e AM |
11890 | if (h != NULL) |
11891 | tls_mask = h->tls_mask; | |
11892 | else if (local_got_ents != NULL) | |
411e1bfb | 11893 | { |
e054468f AM |
11894 | struct plt_entry **local_plt = (struct plt_entry **) |
11895 | (local_got_ents + symtab_hdr->sh_info); | |
f961d9dd | 11896 | unsigned char *lgot_masks = (unsigned char *) |
e054468f | 11897 | (local_plt + symtab_hdr->sh_info); |
727fc41e AM |
11898 | tls_mask = lgot_masks[r_symndx]; |
11899 | } | |
11900 | if (tls_mask == 0 | |
11901 | && (r_type == R_PPC64_TLS | |
11902 | || r_type == R_PPC64_TLSGD | |
11903 | || r_type == R_PPC64_TLSLD)) | |
11904 | { | |
11905 | /* Check for toc tls entries. */ | |
f961d9dd | 11906 | unsigned char *toc_tls; |
0d4792f7 | 11907 | |
727fc41e AM |
11908 | if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend, |
11909 | &local_syms, rel, input_bfd)) | |
11910 | return FALSE; | |
0d4792f7 | 11911 | |
727fc41e AM |
11912 | if (toc_tls) |
11913 | tls_mask = *toc_tls; | |
0d4792f7 AM |
11914 | } |
11915 | ||
11916 | /* Check that tls relocs are used with tls syms, and non-tls | |
11917 | relocs are used with non-tls syms. */ | |
cf35638d | 11918 | if (r_symndx != STN_UNDEF |
0d4792f7 AM |
11919 | && r_type != R_PPC64_NONE |
11920 | && (h == NULL | |
039b3fef AM |
11921 | || h->elf.root.type == bfd_link_hash_defined |
11922 | || h->elf.root.type == bfd_link_hash_defweak) | |
1d483afe AM |
11923 | && (IS_PPC64_TLS_RELOC (r_type) |
11924 | != (sym_type == STT_TLS | |
11925 | || (sym_type == STT_SECTION | |
11926 | && (sec->flags & SEC_THREAD_LOCAL) != 0)))) | |
0d4792f7 | 11927 | { |
727fc41e AM |
11928 | if (tls_mask != 0 |
11929 | && (r_type == R_PPC64_TLS | |
11930 | || r_type == R_PPC64_TLSGD | |
11931 | || r_type == R_PPC64_TLSLD)) | |
0d4792f7 AM |
11932 | /* R_PPC64_TLS is OK against a symbol in the TOC. */ |
11933 | ; | |
11934 | else | |
25f53a85 | 11935 | info->callbacks->einfo |
1d483afe | 11936 | (!IS_PPC64_TLS_RELOC (r_type) |
25f53a85 AM |
11937 | ? _("%H: %s used with TLS symbol %s\n") |
11938 | : _("%H: %s used with non-TLS symbol %s\n"), | |
11939 | input_bfd, input_section, rel->r_offset, | |
0d4792f7 AM |
11940 | ppc64_elf_howto_table[r_type]->name, |
11941 | sym_name); | |
411e1bfb AM |
11942 | } |
11943 | ||
11944 | /* Ensure reloc mapping code below stays sane. */ | |
11945 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 | |
11946 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 | |
11947 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) | |
11948 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) | |
11949 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) | |
11950 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) | |
11951 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) | |
11952 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) | |
11953 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) | |
11954 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) | |
11955 | abort (); | |
0d4792f7 | 11956 | |
411e1bfb AM |
11957 | switch (r_type) |
11958 | { | |
11959 | default: | |
411e1bfb AM |
11960 | break; |
11961 | ||
ba761f19 AM |
11962 | case R_PPC64_LO_DS_OPT: |
11963 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset); | |
11964 | if ((insn & (0x3f << 26)) != 58u << 26) | |
11965 | abort (); | |
11966 | insn += (14u << 26) - (58u << 26); | |
11967 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset); | |
11968 | r_type = R_PPC64_TOC16_LO; | |
11969 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
11970 | break; | |
11971 | ||
411e1bfb AM |
11972 | case R_PPC64_TOC16: |
11973 | case R_PPC64_TOC16_LO: | |
11974 | case R_PPC64_TOC16_DS: | |
11975 | case R_PPC64_TOC16_LO_DS: | |
411e1bfb AM |
11976 | { |
11977 | /* Check for toc tls entries. */ | |
f961d9dd | 11978 | unsigned char *toc_tls; |
951fd09b | 11979 | int retval; |
411e1bfb | 11980 | |
3a71aa26 AM |
11981 | retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend, |
11982 | &local_syms, rel, input_bfd); | |
951fd09b | 11983 | if (retval == 0) |
411e1bfb AM |
11984 | return FALSE; |
11985 | ||
11986 | if (toc_tls) | |
11987 | { | |
951fd09b | 11988 | tls_mask = *toc_tls; |
411e1bfb AM |
11989 | if (r_type == R_PPC64_TOC16_DS |
11990 | || r_type == R_PPC64_TOC16_LO_DS) | |
81407a69 AM |
11991 | { |
11992 | if (tls_mask != 0 | |
11993 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) | |
11994 | goto toctprel; | |
11995 | } | |
411e1bfb | 11996 | else |
951fd09b AM |
11997 | { |
11998 | /* If we found a GD reloc pair, then we might be | |
11999 | doing a GD->IE transition. */ | |
12000 | if (retval == 2) | |
12001 | { | |
12002 | tls_gd = TLS_TPRELGD; | |
12003 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
102890f0 | 12004 | goto tls_ldgd_opt; |
951fd09b AM |
12005 | } |
12006 | else if (retval == 3) | |
12007 | { | |
12008 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
102890f0 | 12009 | goto tls_ldgd_opt; |
951fd09b AM |
12010 | } |
12011 | } | |
411e1bfb AM |
12012 | } |
12013 | } | |
12014 | break; | |
12015 | ||
9d6ded02 AM |
12016 | case R_PPC64_GOT_TPREL16_HI: |
12017 | case R_PPC64_GOT_TPREL16_HA: | |
12018 | if (tls_mask != 0 | |
12019 | && (tls_mask & TLS_TPREL) == 0) | |
12020 | { | |
12021 | rel->r_offset -= d_offset; | |
12022 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); | |
12023 | r_type = R_PPC64_NONE; | |
12024 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
12025 | } | |
12026 | break; | |
12027 | ||
411e1bfb AM |
12028 | case R_PPC64_GOT_TPREL16_DS: |
12029 | case R_PPC64_GOT_TPREL16_LO_DS: | |
951fd09b AM |
12030 | if (tls_mask != 0 |
12031 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 12032 | { |
81407a69 | 12033 | toctprel: |
4fe5ca5b | 12034 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset); |
411e1bfb AM |
12035 | insn &= 31 << 21; |
12036 | insn |= 0x3c0d0000; /* addis 0,13,0 */ | |
4fe5ca5b | 12037 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset); |
411e1bfb | 12038 | r_type = R_PPC64_TPREL16_HA; |
0d4792f7 AM |
12039 | if (toc_symndx != 0) |
12040 | { | |
12041 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
3a71aa26 | 12042 | rel->r_addend = toc_addend; |
0d4792f7 AM |
12043 | /* We changed the symbol. Start over in order to |
12044 | get h, sym, sec etc. right. */ | |
12045 | rel--; | |
12046 | continue; | |
12047 | } | |
12048 | else | |
12049 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
12050 | } |
12051 | break; | |
12052 | ||
12053 | case R_PPC64_TLS: | |
951fd09b AM |
12054 | if (tls_mask != 0 |
12055 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 12056 | { |
411e1bfb | 12057 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
2d0f3896 AM |
12058 | insn = _bfd_elf_ppc_at_tls_transform (insn, 13); |
12059 | if (insn == 0) | |
411e1bfb | 12060 | abort (); |
411e1bfb | 12061 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
411e1bfb | 12062 | /* Was PPC64_TLS which sits on insn boundary, now |
4fe5ca5b GM |
12063 | PPC64_TPREL16_LO which is at low-order half-word. */ |
12064 | rel->r_offset += d_offset; | |
0d4792f7 AM |
12065 | r_type = R_PPC64_TPREL16_LO; |
12066 | if (toc_symndx != 0) | |
12067 | { | |
12068 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
3a71aa26 | 12069 | rel->r_addend = toc_addend; |
0d4792f7 AM |
12070 | /* We changed the symbol. Start over in order to |
12071 | get h, sym, sec etc. right. */ | |
12072 | rel--; | |
12073 | continue; | |
12074 | } | |
12075 | else | |
12076 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
12077 | } |
12078 | break; | |
12079 | ||
411e1bfb AM |
12080 | case R_PPC64_GOT_TLSGD16_HI: |
12081 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b AM |
12082 | tls_gd = TLS_TPRELGD; |
12083 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
12084 | goto tls_gdld_hi; | |
12085 | break; | |
12086 | ||
411e1bfb AM |
12087 | case R_PPC64_GOT_TLSLD16_HI: |
12088 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 12089 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
411e1bfb | 12090 | { |
951fd09b AM |
12091 | tls_gdld_hi: |
12092 | if ((tls_mask & tls_gd) != 0) | |
12093 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
12094 | + R_PPC64_GOT_TPREL16_DS); | |
12095 | else | |
411e1bfb | 12096 | { |
4fe5ca5b | 12097 | rel->r_offset -= d_offset; |
727ac201 | 12098 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
951fd09b | 12099 | r_type = R_PPC64_NONE; |
411e1bfb | 12100 | } |
951fd09b | 12101 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb AM |
12102 | } |
12103 | break; | |
12104 | ||
951fd09b AM |
12105 | case R_PPC64_GOT_TLSGD16: |
12106 | case R_PPC64_GOT_TLSGD16_LO: | |
12107 | tls_gd = TLS_TPRELGD; | |
12108 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
102890f0 | 12109 | goto tls_ldgd_opt; |
951fd09b | 12110 | break; |
411e1bfb | 12111 | |
951fd09b AM |
12112 | case R_PPC64_GOT_TLSLD16: |
12113 | case R_PPC64_GOT_TLSLD16_LO: | |
12114 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
12115 | { | |
3a71aa26 | 12116 | unsigned int insn1, insn2, insn3; |
102890f0 AM |
12117 | bfd_vma offset; |
12118 | ||
12119 | tls_ldgd_opt: | |
727fc41e AM |
12120 | offset = (bfd_vma) -1; |
12121 | /* If not using the newer R_PPC64_TLSGD/LD to mark | |
12122 | __tls_get_addr calls, we must trust that the call | |
12123 | stays with its arg setup insns, ie. that the next | |
12124 | reloc is the __tls_get_addr call associated with | |
12125 | the current reloc. Edit both insns. */ | |
12126 | if (input_section->has_tls_get_addr_call | |
12127 | && rel + 1 < relend | |
12128 | && branch_reloc_hash_match (input_bfd, rel + 1, | |
12129 | htab->tls_get_addr, | |
12130 | htab->tls_get_addr_fd)) | |
12131 | offset = rel[1].r_offset; | |
102890f0 | 12132 | if ((tls_mask & tls_gd) != 0) |
411e1bfb | 12133 | { |
102890f0 | 12134 | /* IE */ |
3a71aa26 AM |
12135 | insn1 = bfd_get_32 (output_bfd, |
12136 | contents + rel->r_offset - d_offset); | |
102890f0 AM |
12137 | insn1 &= (1 << 26) - (1 << 2); |
12138 | insn1 |= 58 << 26; /* ld */ | |
12139 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
727fc41e | 12140 | if (offset != (bfd_vma) -1) |
f58d5a2d | 12141 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE); |
102890f0 AM |
12142 | if ((tls_mask & TLS_EXPLICIT) == 0) |
12143 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
12144 | + R_PPC64_GOT_TPREL16_DS); | |
411e1bfb | 12145 | else |
102890f0 AM |
12146 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; |
12147 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
12148 | } | |
12149 | else | |
12150 | { | |
12151 | /* LE */ | |
12152 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ | |
12153 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
12154 | if (tls_gd == 0) | |
951fd09b | 12155 | { |
102890f0 | 12156 | /* Was an LD reloc. */ |
1d483afe AM |
12157 | if (toc_symndx) |
12158 | sec = local_sections[toc_symndx]; | |
12159 | for (r_symndx = 0; | |
12160 | r_symndx < symtab_hdr->sh_info; | |
12161 | r_symndx++) | |
12162 | if (local_sections[r_symndx] == sec) | |
12163 | break; | |
12164 | if (r_symndx >= symtab_hdr->sh_info) | |
cf35638d | 12165 | r_symndx = STN_UNDEF; |
102890f0 | 12166 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
cf35638d | 12167 | if (r_symndx != STN_UNDEF) |
1d483afe AM |
12168 | rel->r_addend -= (local_syms[r_symndx].st_value |
12169 | + sec->output_offset | |
12170 | + sec->output_section->vma); | |
951fd09b | 12171 | } |
102890f0 | 12172 | else if (toc_symndx != 0) |
3a71aa26 AM |
12173 | { |
12174 | r_symndx = toc_symndx; | |
12175 | rel->r_addend = toc_addend; | |
12176 | } | |
102890f0 AM |
12177 | r_type = R_PPC64_TPREL16_HA; |
12178 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
727fc41e AM |
12179 | if (offset != (bfd_vma) -1) |
12180 | { | |
12181 | rel[1].r_info = ELF64_R_INFO (r_symndx, | |
12182 | R_PPC64_TPREL16_LO); | |
12183 | rel[1].r_offset = offset + d_offset; | |
12184 | rel[1].r_addend = rel->r_addend; | |
12185 | } | |
102890f0 | 12186 | } |
3a71aa26 AM |
12187 | bfd_put_32 (output_bfd, insn1, |
12188 | contents + rel->r_offset - d_offset); | |
727fc41e AM |
12189 | if (offset != (bfd_vma) -1) |
12190 | { | |
12191 | insn3 = bfd_get_32 (output_bfd, | |
12192 | contents + offset + 4); | |
12193 | if (insn3 == NOP | |
12194 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
12195 | { | |
12196 | rel[1].r_offset += 4; | |
12197 | bfd_put_32 (output_bfd, insn2, contents + offset + 4); | |
12198 | insn2 = NOP; | |
12199 | } | |
12200 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
12201 | } | |
12202 | if ((tls_mask & tls_gd) == 0 | |
12203 | && (tls_gd == 0 || toc_symndx != 0)) | |
12204 | { | |
12205 | /* We changed the symbol. Start over in order | |
12206 | to get h, sym, sec etc. right. */ | |
12207 | rel--; | |
12208 | continue; | |
12209 | } | |
12210 | } | |
12211 | break; | |
12212 | ||
12213 | case R_PPC64_TLSGD: | |
12214 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
12215 | { | |
12216 | unsigned int insn2, insn3; | |
12217 | bfd_vma offset = rel->r_offset; | |
12218 | ||
12219 | if ((tls_mask & TLS_TPRELGD) != 0) | |
12220 | { | |
12221 | /* IE */ | |
12222 | r_type = R_PPC64_NONE; | |
12223 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
12224 | } | |
12225 | else | |
12226 | { | |
12227 | /* LE */ | |
12228 | if (toc_symndx != 0) | |
12229 | { | |
12230 | r_symndx = toc_symndx; | |
12231 | rel->r_addend = toc_addend; | |
12232 | } | |
12233 | r_type = R_PPC64_TPREL16_LO; | |
12234 | rel->r_offset = offset + d_offset; | |
12235 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
12236 | } | |
12237 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
12238 | /* Zap the reloc on the _tls_get_addr call too. */ | |
12239 | BFD_ASSERT (offset == rel[1].r_offset); | |
f58d5a2d | 12240 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE); |
3a71aa26 AM |
12241 | insn3 = bfd_get_32 (output_bfd, |
12242 | contents + offset + 4); | |
102890f0 AM |
12243 | if (insn3 == NOP |
12244 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
12245 | { | |
727fc41e | 12246 | rel->r_offset += 4; |
3a71aa26 AM |
12247 | bfd_put_32 (output_bfd, insn2, contents + offset + 4); |
12248 | insn2 = NOP; | |
102890f0 | 12249 | } |
102890f0 | 12250 | bfd_put_32 (output_bfd, insn2, contents + offset); |
727fc41e | 12251 | if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0) |
102890f0 | 12252 | { |
102890f0 AM |
12253 | rel--; |
12254 | continue; | |
411e1bfb | 12255 | } |
411e1bfb | 12256 | } |
411e1bfb AM |
12257 | break; |
12258 | ||
727fc41e AM |
12259 | case R_PPC64_TLSLD: |
12260 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
12261 | { | |
12262 | unsigned int insn2, insn3; | |
12263 | bfd_vma offset = rel->r_offset; | |
12264 | ||
12265 | if (toc_symndx) | |
12266 | sec = local_sections[toc_symndx]; | |
12267 | for (r_symndx = 0; | |
12268 | r_symndx < symtab_hdr->sh_info; | |
12269 | r_symndx++) | |
12270 | if (local_sections[r_symndx] == sec) | |
12271 | break; | |
12272 | if (r_symndx >= symtab_hdr->sh_info) | |
cf35638d | 12273 | r_symndx = STN_UNDEF; |
727fc41e | 12274 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
cf35638d | 12275 | if (r_symndx != STN_UNDEF) |
727fc41e AM |
12276 | rel->r_addend -= (local_syms[r_symndx].st_value |
12277 | + sec->output_offset | |
12278 | + sec->output_section->vma); | |
12279 | ||
12280 | r_type = R_PPC64_TPREL16_LO; | |
12281 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
12282 | rel->r_offset = offset + d_offset; | |
12283 | /* Zap the reloc on the _tls_get_addr call too. */ | |
12284 | BFD_ASSERT (offset == rel[1].r_offset); | |
f58d5a2d | 12285 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE); |
727fc41e AM |
12286 | insn2 = 0x38630000; /* addi 3,3,0 */ |
12287 | insn3 = bfd_get_32 (output_bfd, | |
12288 | contents + offset + 4); | |
12289 | if (insn3 == NOP | |
12290 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
12291 | { | |
12292 | rel->r_offset += 4; | |
12293 | bfd_put_32 (output_bfd, insn2, contents + offset + 4); | |
12294 | insn2 = NOP; | |
12295 | } | |
12296 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
12297 | rel--; | |
12298 | continue; | |
12299 | } | |
12300 | break; | |
12301 | ||
411e1bfb | 12302 | case R_PPC64_DTPMOD64: |
951fd09b AM |
12303 | if (rel + 1 < relend |
12304 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
12305 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 12306 | { |
951fd09b AM |
12307 | if ((tls_mask & TLS_GD) == 0) |
12308 | { | |
12309 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); | |
12310 | if ((tls_mask & TLS_TPRELGD) != 0) | |
12311 | r_type = R_PPC64_TPREL64; | |
12312 | else | |
12313 | { | |
4ce794b7 | 12314 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
951fd09b AM |
12315 | r_type = R_PPC64_NONE; |
12316 | } | |
12317 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
12318 | } | |
12319 | } | |
12320 | else | |
12321 | { | |
12322 | if ((tls_mask & TLS_LD) == 0) | |
411e1bfb | 12323 | { |
4ce794b7 | 12324 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
411e1bfb | 12325 | r_type = R_PPC64_NONE; |
951fd09b | 12326 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb | 12327 | } |
411e1bfb AM |
12328 | } |
12329 | break; | |
12330 | ||
12331 | case R_PPC64_TPREL64: | |
951fd09b | 12332 | if ((tls_mask & TLS_TPREL) == 0) |
411e1bfb AM |
12333 | { |
12334 | r_type = R_PPC64_NONE; | |
12335 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
12336 | } | |
12337 | break; | |
12338 | } | |
12339 | ||
12340 | /* Handle other relocations that tweak non-addend part of insn. */ | |
86c76c7b | 12341 | insn = 0; |
b25116a9 AM |
12342 | max_br_offset = 1 << 25; |
12343 | addend = rel->r_addend; | |
65f38f15 | 12344 | switch (r_type) |
5bd4f169 AM |
12345 | { |
12346 | default: | |
65f38f15 | 12347 | break; |
5bd4f169 | 12348 | |
65f38f15 AM |
12349 | /* Branch taken prediction relocations. */ |
12350 | case R_PPC64_ADDR14_BRTAKEN: | |
12351 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
12352 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
12353 | /* Fall thru. */ | |
65f38f15 | 12354 | |
86c76c7b | 12355 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
12356 | case R_PPC64_ADDR14_BRNTAKEN: |
12357 | case R_PPC64_REL14_BRNTAKEN: | |
411e1bfb AM |
12358 | insn |= bfd_get_32 (output_bfd, |
12359 | contents + rel->r_offset) & ~(0x01 << 21); | |
b25116a9 | 12360 | /* Fall thru. */ |
86c76c7b | 12361 | |
b25116a9 AM |
12362 | case R_PPC64_REL14: |
12363 | max_br_offset = 1 << 15; | |
12364 | /* Fall thru. */ | |
5bd4f169 | 12365 | |
65f38f15 | 12366 | case R_PPC64_REL24: |
ad8e1ba5 AM |
12367 | /* Calls to functions with a different TOC, such as calls to |
12368 | shared objects, need to alter the TOC pointer. This is | |
12369 | done using a linkage stub. A REL24 branching to these | |
12370 | linkage stubs needs to be followed by a nop, as the nop | |
12371 | will be replaced with an instruction to restore the TOC | |
12372 | base pointer. */ | |
8387904d | 12373 | fdh = h; |
b31867b6 AM |
12374 | if (h != NULL |
12375 | && h->oh != NULL | |
12376 | && h->oh->is_func_descriptor) | |
12377 | fdh = ppc_follow_link (h->oh); | |
6abec6bc AM |
12378 | stub_entry = ppc_get_stub_entry (input_section, sec, fdh, rel, htab); |
12379 | if (stub_entry != NULL | |
ad8e1ba5 AM |
12380 | && (stub_entry->stub_type == ppc_stub_plt_call |
12381 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off | |
12382 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) | |
41bd81ab | 12383 | { |
b25116a9 | 12384 | bfd_boolean can_plt_call = FALSE; |
721956f4 | 12385 | |
eea6121a | 12386 | if (rel->r_offset + 8 <= input_section->size) |
41bd81ab | 12387 | { |
b25116a9 AM |
12388 | unsigned long nop; |
12389 | nop = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); | |
12390 | if (nop == NOP | |
12391 | || nop == CROR_151515 || nop == CROR_313131) | |
41bd81ab | 12392 | { |
a7f2871e AM |
12393 | if (h != NULL |
12394 | && (h == htab->tls_get_addr_fd | |
12395 | || h == htab->tls_get_addr) | |
12396 | && !htab->no_tls_get_addr_opt) | |
12397 | { | |
12398 | /* Special stub used, leave nop alone. */ | |
12399 | } | |
12400 | else | |
12401 | bfd_put_32 (input_bfd, LD_R2_40R1, | |
12402 | contents + rel->r_offset + 4); | |
b25116a9 | 12403 | can_plt_call = TRUE; |
41bd81ab | 12404 | } |
5bd4f169 | 12405 | } |
721956f4 AM |
12406 | |
12407 | if (!can_plt_call) | |
12408 | { | |
ad8e1ba5 AM |
12409 | if (stub_entry->stub_type == ppc_stub_plt_call) |
12410 | { | |
12411 | /* If this is a plain branch rather than a branch | |
4fa1c237 AM |
12412 | and link, don't require a nop. However, don't |
12413 | allow tail calls in a shared library as they | |
12414 | will result in r2 being corrupted. */ | |
b25116a9 AM |
12415 | unsigned long br; |
12416 | br = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
4fa1c237 | 12417 | if (info->executable && (br & 1) == 0) |
b25116a9 | 12418 | can_plt_call = TRUE; |
15b552e9 AM |
12419 | else |
12420 | stub_entry = NULL; | |
ad8e1ba5 | 12421 | } |
6ab189d5 | 12422 | else if (h != NULL |
039b3fef | 12423 | && strcmp (h->elf.root.root.string, |
6ab189d5 AM |
12424 | ".__libc_start_main") == 0) |
12425 | { | |
12426 | /* Allow crt1 branch to go via a toc adjusting stub. */ | |
b25116a9 | 12427 | can_plt_call = TRUE; |
6ab189d5 | 12428 | } |
ad8e1ba5 AM |
12429 | else |
12430 | { | |
12431 | if (strcmp (input_section->output_section->name, | |
12432 | ".init") == 0 | |
12433 | || strcmp (input_section->output_section->name, | |
12434 | ".fini") == 0) | |
25f53a85 AM |
12435 | info->callbacks->einfo |
12436 | (_("%H: automatic multiple TOCs " | |
ad8e1ba5 | 12437 | "not supported using your crt files; " |
25f53a85 AM |
12438 | "recompile with -mminimal-toc or upgrade gcc\n"), |
12439 | input_bfd, input_section, rel->r_offset); | |
ad8e1ba5 | 12440 | else |
25f53a85 AM |
12441 | info->callbacks->einfo |
12442 | (_("%H: sibling call optimization to `%s' " | |
ad8e1ba5 AM |
12443 | "does not allow automatic multiple TOCs; " |
12444 | "recompile with -mminimal-toc or " | |
12445 | "-fno-optimize-sibling-calls, " | |
25f53a85 AM |
12446 | "or make `%s' extern\n"), |
12447 | input_bfd, input_section, rel->r_offset, | |
ad8e1ba5 AM |
12448 | sym_name, |
12449 | sym_name); | |
12450 | bfd_set_error (bfd_error_bad_value); | |
12451 | ret = FALSE; | |
12452 | } | |
721956f4 AM |
12453 | } |
12454 | ||
b25116a9 AM |
12455 | if (can_plt_call |
12456 | && stub_entry->stub_type == ppc_stub_plt_call) | |
12457 | unresolved_reloc = FALSE; | |
12458 | } | |
12459 | ||
6abec6bc AM |
12460 | if ((stub_entry == NULL |
12461 | || stub_entry->stub_type == ppc_stub_long_branch | |
12462 | || stub_entry->stub_type == ppc_stub_plt_branch) | |
8387904d AM |
12463 | && get_opd_info (sec) != NULL) |
12464 | { | |
12465 | /* The branch destination is the value of the opd entry. */ | |
4cc603a5 AM |
12466 | bfd_vma off = (relocation + addend |
12467 | - sec->output_section->vma | |
12468 | - sec->output_offset); | |
8387904d AM |
12469 | bfd_vma dest = opd_entry_value (sec, off, NULL, NULL); |
12470 | if (dest != (bfd_vma) -1) | |
12471 | { | |
12472 | relocation = dest; | |
12473 | addend = 0; | |
12474 | } | |
12475 | } | |
12476 | ||
b25116a9 AM |
12477 | /* If the branch is out of reach we ought to have a long |
12478 | branch stub. */ | |
12479 | from = (rel->r_offset | |
12480 | + input_section->output_offset | |
12481 | + input_section->output_section->vma); | |
12482 | ||
6abec6bc AM |
12483 | if (stub_entry != NULL |
12484 | && (stub_entry->stub_type == ppc_stub_long_branch | |
12485 | || stub_entry->stub_type == ppc_stub_plt_branch) | |
12486 | && (r_type == R_PPC64_ADDR14_BRTAKEN | |
12487 | || r_type == R_PPC64_ADDR14_BRNTAKEN | |
12488 | || (relocation + addend - from + max_br_offset | |
12489 | < 2 * max_br_offset))) | |
12490 | /* Don't use the stub if this branch is in range. */ | |
12491 | stub_entry = NULL; | |
b25116a9 AM |
12492 | |
12493 | if (stub_entry != NULL) | |
12494 | { | |
12495 | /* Munge up the value and addend so that we call the stub | |
12496 | rather than the procedure directly. */ | |
12497 | relocation = (stub_entry->stub_offset | |
12498 | + stub_entry->stub_sec->output_offset | |
12499 | + stub_entry->stub_sec->output_section->vma); | |
12500 | addend = 0; | |
12501 | } | |
12502 | ||
12503 | if (insn != 0) | |
12504 | { | |
12505 | if (is_power4) | |
721956f4 | 12506 | { |
b25116a9 AM |
12507 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
12508 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
12509 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
12510 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
12511 | insn |= 0x02 << 21; | |
12512 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
12513 | insn |= 0x08 << 21; | |
12514 | else | |
12515 | break; | |
12516 | } | |
12517 | else | |
12518 | { | |
12519 | /* Invert 'y' bit if not the default. */ | |
4cc603a5 | 12520 | if ((bfd_signed_vma) (relocation + addend - from) < 0) |
b25116a9 | 12521 | insn ^= 0x01 << 21; |
721956f4 | 12522 | } |
b25116a9 AM |
12523 | |
12524 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
5bd4f169 | 12525 | } |
e86ce104 | 12526 | |
06da1e8e AM |
12527 | /* NOP out calls to undefined weak functions. |
12528 | We can thus call a weak function without first | |
12529 | checking whether the function is defined. */ | |
b25116a9 | 12530 | else if (h != NULL |
039b3fef | 12531 | && h->elf.root.type == bfd_link_hash_undefweak |
766bc656 | 12532 | && h->elf.dynindx == -1 |
b25116a9 AM |
12533 | && r_type == R_PPC64_REL24 |
12534 | && relocation == 0 | |
4cc603a5 | 12535 | && addend == 0) |
e86ce104 | 12536 | { |
06da1e8e AM |
12537 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
12538 | continue; | |
e86ce104 | 12539 | } |
65f38f15 AM |
12540 | break; |
12541 | } | |
5bd4f169 | 12542 | |
65f38f15 | 12543 | /* Set `addend'. */ |
411e1bfb | 12544 | tls_type = 0; |
65f38f15 AM |
12545 | switch (r_type) |
12546 | { | |
12547 | default: | |
25f53a85 AM |
12548 | info->callbacks->einfo |
12549 | (_("%B: unknown relocation type %d for symbol %s\n"), | |
d003868e | 12550 | input_bfd, (int) r_type, sym_name); |
5bd4f169 | 12551 | |
65f38f15 | 12552 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 12553 | ret = FALSE; |
65f38f15 | 12554 | continue; |
5bd4f169 | 12555 | |
65f38f15 | 12556 | case R_PPC64_NONE: |
411e1bfb | 12557 | case R_PPC64_TLS: |
727fc41e AM |
12558 | case R_PPC64_TLSGD: |
12559 | case R_PPC64_TLSLD: | |
04c9666a AM |
12560 | case R_PPC64_GNU_VTINHERIT: |
12561 | case R_PPC64_GNU_VTENTRY: | |
65f38f15 | 12562 | continue; |
5bd4f169 AM |
12563 | |
12564 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
12565 | address in the GOT as relocation value instead of the | |
411e1bfb | 12566 | symbol's value itself. Also, create a GOT entry for the |
5bd4f169 | 12567 | symbol and put the symbol value there. */ |
411e1bfb AM |
12568 | case R_PPC64_GOT_TLSGD16: |
12569 | case R_PPC64_GOT_TLSGD16_LO: | |
12570 | case R_PPC64_GOT_TLSGD16_HI: | |
12571 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 12572 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
12573 | goto dogot; |
12574 | ||
12575 | case R_PPC64_GOT_TLSLD16: | |
12576 | case R_PPC64_GOT_TLSLD16_LO: | |
12577 | case R_PPC64_GOT_TLSLD16_HI: | |
12578 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 12579 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
12580 | goto dogot; |
12581 | ||
12582 | case R_PPC64_GOT_TPREL16_DS: | |
12583 | case R_PPC64_GOT_TPREL16_LO_DS: | |
12584 | case R_PPC64_GOT_TPREL16_HI: | |
12585 | case R_PPC64_GOT_TPREL16_HA: | |
12586 | tls_type = TLS_TLS | TLS_TPREL; | |
12587 | goto dogot; | |
12588 | ||
12589 | case R_PPC64_GOT_DTPREL16_DS: | |
12590 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
12591 | case R_PPC64_GOT_DTPREL16_HI: | |
12592 | case R_PPC64_GOT_DTPREL16_HA: | |
12593 | tls_type = TLS_TLS | TLS_DTPREL; | |
12594 | goto dogot; | |
12595 | ||
65f38f15 AM |
12596 | case R_PPC64_GOT16: |
12597 | case R_PPC64_GOT16_LO: | |
12598 | case R_PPC64_GOT16_HI: | |
12599 | case R_PPC64_GOT16_HA: | |
12600 | case R_PPC64_GOT16_DS: | |
12601 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb | 12602 | dogot: |
5bd4f169 AM |
12603 | { |
12604 | /* Relocation is to the entry for this symbol in the global | |
12605 | offset table. */ | |
e717da7e | 12606 | asection *got; |
d881513a | 12607 | bfd_vma *offp; |
5bd4f169 | 12608 | bfd_vma off; |
d881513a | 12609 | unsigned long indx = 0; |
927be08e | 12610 | struct got_entry *ent; |
65f38f15 | 12611 | |
d881513a AM |
12612 | if (tls_type == (TLS_TLS | TLS_LD) |
12613 | && (h == NULL | |
f5385ebf | 12614 | || !h->elf.def_dynamic)) |
927be08e | 12615 | ent = ppc64_tlsld_got (input_bfd); |
411e1bfb | 12616 | else |
5bd4f169 | 12617 | { |
5bd4f169 | 12618 | |
d881513a AM |
12619 | if (h != NULL) |
12620 | { | |
12621 | bfd_boolean dyn = htab->elf.dynamic_sections_created; | |
039b3fef AM |
12622 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, |
12623 | &h->elf) | |
d881513a | 12624 | || (info->shared |
726d3ab0 | 12625 | && SYMBOL_CALLS_LOCAL (info, &h->elf))) |
d881513a AM |
12626 | /* This is actually a static link, or it is a |
12627 | -Bsymbolic link and the symbol is defined | |
12628 | locally, or the symbol was forced to be local | |
12629 | because of a version file. */ | |
12630 | ; | |
12631 | else | |
12632 | { | |
039b3fef | 12633 | indx = h->elf.dynindx; |
d881513a AM |
12634 | unresolved_reloc = FALSE; |
12635 | } | |
039b3fef | 12636 | ent = h->elf.got.glist; |
d881513a | 12637 | } |
411e1bfb | 12638 | else |
5bd4f169 | 12639 | { |
d881513a AM |
12640 | if (local_got_ents == NULL) |
12641 | abort (); | |
12642 | ent = local_got_ents[r_symndx]; | |
5bd4f169 | 12643 | } |
d881513a AM |
12644 | |
12645 | for (; ent != NULL; ent = ent->next) | |
4cc603a5 | 12646 | if (ent->addend == orig_addend |
e717da7e | 12647 | && ent->owner == input_bfd |
d881513a AM |
12648 | && ent->tls_type == tls_type) |
12649 | break; | |
5bd4f169 | 12650 | } |
411e1bfb | 12651 | |
927be08e AM |
12652 | if (ent == NULL) |
12653 | abort (); | |
12654 | if (ent->is_indirect) | |
12655 | ent = ent->got.ent; | |
12656 | offp = &ent->got.offset; | |
12657 | got = ppc64_elf_tdata (ent->owner)->got; | |
e717da7e AM |
12658 | if (got == NULL) |
12659 | abort (); | |
12660 | ||
411e1bfb AM |
12661 | /* The offset must always be a multiple of 8. We use the |
12662 | least significant bit to record whether we have already | |
12663 | processed this entry. */ | |
d881513a | 12664 | off = *offp; |
411e1bfb AM |
12665 | if ((off & 1) != 0) |
12666 | off &= ~1; | |
5bd4f169 AM |
12667 | else |
12668 | { | |
411e1bfb AM |
12669 | /* Generate relocs for the dynamic linker, except in |
12670 | the case of TLSLD where we'll use one entry per | |
12671 | module. */ | |
25f23106 AM |
12672 | asection *relgot; |
12673 | bfd_boolean ifunc; | |
e717da7e | 12674 | |
d881513a | 12675 | *offp = off | 1; |
25f23106 AM |
12676 | relgot = NULL; |
12677 | ifunc = (h != NULL | |
12678 | ? h->elf.type == STT_GNU_IFUNC | |
12679 | : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC); | |
4e795f50 | 12680 | if ((info->shared || indx != 0) |
927be08e AM |
12681 | && (h == NULL |
12682 | || (tls_type == (TLS_TLS | TLS_LD) | |
12683 | && !h->elf.def_dynamic) | |
039b3fef AM |
12684 | || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT |
12685 | || h->elf.root.type != bfd_link_hash_undefweak)) | |
927be08e | 12686 | relgot = ppc64_elf_tdata (ent->owner)->relgot; |
25f23106 AM |
12687 | else if (ifunc) |
12688 | relgot = htab->reliplt; | |
12689 | if (relgot != NULL) | |
5bd4f169 | 12690 | { |
e717da7e AM |
12691 | outrel.r_offset = (got->output_section->vma |
12692 | + got->output_offset | |
411e1bfb | 12693 | + off); |
4cc603a5 | 12694 | outrel.r_addend = addend; |
d881513a | 12695 | if (tls_type & (TLS_LD | TLS_GD)) |
5bd4f169 | 12696 | { |
411e1bfb | 12697 | outrel.r_addend = 0; |
e515b051 | 12698 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
d881513a AM |
12699 | if (tls_type == (TLS_TLS | TLS_GD)) |
12700 | { | |
e717da7e AM |
12701 | loc = relgot->contents; |
12702 | loc += (relgot->reloc_count++ | |
d881513a AM |
12703 | * sizeof (Elf64_External_Rela)); |
12704 | bfd_elf64_swap_reloca_out (output_bfd, | |
12705 | &outrel, loc); | |
e515b051 | 12706 | outrel.r_offset += 8; |
4cc603a5 | 12707 | outrel.r_addend = addend; |
d881513a AM |
12708 | outrel.r_info |
12709 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); | |
d881513a | 12710 | } |
411e1bfb | 12711 | } |
951fd09b | 12712 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
411e1bfb | 12713 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
951fd09b | 12714 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 12715 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
25f23106 AM |
12716 | else if (indx != 0) |
12717 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); | |
12718 | else | |
81407a69 | 12719 | { |
25f23106 AM |
12720 | if (ifunc) |
12721 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE); | |
12722 | else | |
12723 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
81407a69 AM |
12724 | |
12725 | /* Write the .got section contents for the sake | |
12726 | of prelink. */ | |
e717da7e | 12727 | loc = got->contents + off; |
23fbd6fa JJ |
12728 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
12729 | loc); | |
81407a69 | 12730 | } |
81407a69 AM |
12731 | |
12732 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) | |
e515b051 AM |
12733 | { |
12734 | outrel.r_addend += relocation; | |
12735 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 12736 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 12737 | } |
e717da7e AM |
12738 | loc = relgot->contents; |
12739 | loc += (relgot->reloc_count++ | |
411e1bfb AM |
12740 | * sizeof (Elf64_External_Rela)); |
12741 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
12742 | } | |
12743 | ||
ad8e1ba5 | 12744 | /* Init the .got section contents here if we're not |
81407a69 | 12745 | emitting a reloc. */ |
d881513a | 12746 | else |
411e1bfb | 12747 | { |
4cc603a5 | 12748 | relocation += addend; |
7b609f53 AM |
12749 | if (tls_type == (TLS_TLS | TLS_LD)) |
12750 | relocation = 1; | |
12751 | else if (tls_type != 0) | |
411e1bfb | 12752 | { |
e1918d23 | 12753 | relocation -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 12754 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 12755 | relocation += DTP_OFFSET - TP_OFFSET; |
5bd4f169 | 12756 | |
7b609f53 AM |
12757 | if (tls_type == (TLS_TLS | TLS_GD)) |
12758 | { | |
12759 | bfd_put_64 (output_bfd, relocation, | |
e717da7e | 12760 | got->contents + off + 8); |
7b609f53 AM |
12761 | relocation = 1; |
12762 | } | |
411e1bfb | 12763 | } |
7b609f53 | 12764 | |
411e1bfb | 12765 | bfd_put_64 (output_bfd, relocation, |
e717da7e | 12766 | got->contents + off); |
5bd4f169 AM |
12767 | } |
12768 | } | |
12769 | ||
65f38f15 AM |
12770 | if (off >= (bfd_vma) -2) |
12771 | abort (); | |
12772 | ||
bf102f86 AM |
12773 | relocation = got->output_section->vma + got->output_offset + off; |
12774 | addend = -(TOCstart + htab->stub_group[input_section->id].toc_off); | |
5bd4f169 | 12775 | } |
65f38f15 AM |
12776 | break; |
12777 | ||
12778 | case R_PPC64_PLT16_HA: | |
12779 | case R_PPC64_PLT16_HI: | |
12780 | case R_PPC64_PLT16_LO: | |
12781 | case R_PPC64_PLT32: | |
12782 | case R_PPC64_PLT64: | |
12783 | /* Relocation is to the entry for this symbol in the | |
12784 | procedure linkage table. */ | |
12785 | ||
12786 | /* Resolve a PLT reloc against a local symbol directly, | |
12787 | without using the procedure linkage table. */ | |
12788 | if (h == NULL) | |
12789 | break; | |
12790 | ||
411e1bfb AM |
12791 | /* It's possible that we didn't make a PLT entry for this |
12792 | symbol. This happens when statically linking PIC code, | |
12793 | or when using -Bsymbolic. Go find a match if there is a | |
12794 | PLT entry. */ | |
4ce794b7 | 12795 | if (htab->plt != NULL) |
65f38f15 | 12796 | { |
411e1bfb | 12797 | struct plt_entry *ent; |
039b3fef | 12798 | for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next) |
4cc603a5 | 12799 | if (ent->addend == orig_addend |
411e1bfb AM |
12800 | && ent->plt.offset != (bfd_vma) -1) |
12801 | { | |
4ce794b7 AM |
12802 | relocation = (htab->plt->output_section->vma |
12803 | + htab->plt->output_offset | |
411e1bfb AM |
12804 | + ent->plt.offset); |
12805 | unresolved_reloc = FALSE; | |
12806 | } | |
65f38f15 | 12807 | } |
65f38f15 | 12808 | break; |
5bd4f169 | 12809 | |
0b13192e AM |
12810 | case R_PPC64_TOC: |
12811 | /* Relocation value is TOC base. */ | |
12812 | relocation = TOCstart; | |
cf35638d | 12813 | if (r_symndx == STN_UNDEF) |
0b13192e | 12814 | relocation += htab->stub_group[input_section->id].toc_off; |
8517fae7 AM |
12815 | else if (unresolved_reloc) |
12816 | ; | |
12817 | else if (sec != NULL && sec->id <= htab->top_id) | |
0b13192e AM |
12818 | relocation += htab->stub_group[sec->id].toc_off; |
12819 | else | |
12820 | unresolved_reloc = TRUE; | |
ab96bf03 | 12821 | goto dodyn; |
0b13192e | 12822 | |
5bd4f169 AM |
12823 | /* TOC16 relocs. We want the offset relative to the TOC base, |
12824 | which is the address of the start of the TOC plus 0x8000. | |
12825 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
12826 | in this order. */ | |
65f38f15 AM |
12827 | case R_PPC64_TOC16: |
12828 | case R_PPC64_TOC16_LO: | |
12829 | case R_PPC64_TOC16_HI: | |
12830 | case R_PPC64_TOC16_DS: | |
12831 | case R_PPC64_TOC16_LO_DS: | |
12832 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 12833 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
5bd4f169 AM |
12834 | break; |
12835 | ||
12836 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
12837 | case R_PPC64_SECTOFF: |
12838 | case R_PPC64_SECTOFF_LO: | |
12839 | case R_PPC64_SECTOFF_HI: | |
12840 | case R_PPC64_SECTOFF_DS: | |
12841 | case R_PPC64_SECTOFF_LO_DS: | |
12842 | case R_PPC64_SECTOFF_HA: | |
4ce794b7 | 12843 | if (sec != NULL) |
65f38f15 | 12844 | addend -= sec->output_section->vma; |
5bd4f169 AM |
12845 | break; |
12846 | ||
25f23106 AM |
12847 | case R_PPC64_REL16: |
12848 | case R_PPC64_REL16_LO: | |
12849 | case R_PPC64_REL16_HI: | |
12850 | case R_PPC64_REL16_HA: | |
12851 | break; | |
12852 | ||
721956f4 AM |
12853 | case R_PPC64_REL14: |
12854 | case R_PPC64_REL14_BRNTAKEN: | |
12855 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
12856 | case R_PPC64_REL24: |
12857 | break; | |
12858 | ||
411e1bfb AM |
12859 | case R_PPC64_TPREL16: |
12860 | case R_PPC64_TPREL16_LO: | |
12861 | case R_PPC64_TPREL16_HI: | |
12862 | case R_PPC64_TPREL16_HA: | |
12863 | case R_PPC64_TPREL16_DS: | |
12864 | case R_PPC64_TPREL16_LO_DS: | |
12865 | case R_PPC64_TPREL16_HIGHER: | |
12866 | case R_PPC64_TPREL16_HIGHERA: | |
12867 | case R_PPC64_TPREL16_HIGHEST: | |
12868 | case R_PPC64_TPREL16_HIGHESTA: | |
766bc656 AM |
12869 | if (h != NULL |
12870 | && h->elf.root.type == bfd_link_hash_undefweak | |
12871 | && h->elf.dynindx == -1) | |
12872 | { | |
12873 | /* Make this relocation against an undefined weak symbol | |
12874 | resolve to zero. This is really just a tweak, since | |
12875 | code using weak externs ought to check that they are | |
12876 | defined before using them. */ | |
12877 | bfd_byte *p = contents + rel->r_offset - d_offset; | |
12878 | ||
12879 | insn = bfd_get_32 (output_bfd, p); | |
12880 | insn = _bfd_elf_ppc_at_tprel_transform (insn, 13); | |
12881 | if (insn != 0) | |
12882 | bfd_put_32 (output_bfd, insn, p); | |
12883 | break; | |
12884 | } | |
e1918d23 | 12885 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
12886 | if (info->shared) |
12887 | /* The TPREL16 relocs shouldn't really be used in shared | |
12888 | libs as they will result in DT_TEXTREL being set, but | |
12889 | support them anyway. */ | |
12890 | goto dodyn; | |
12891 | break; | |
12892 | ||
12893 | case R_PPC64_DTPREL16: | |
12894 | case R_PPC64_DTPREL16_LO: | |
12895 | case R_PPC64_DTPREL16_HI: | |
12896 | case R_PPC64_DTPREL16_HA: | |
12897 | case R_PPC64_DTPREL16_DS: | |
12898 | case R_PPC64_DTPREL16_LO_DS: | |
12899 | case R_PPC64_DTPREL16_HIGHER: | |
12900 | case R_PPC64_DTPREL16_HIGHERA: | |
12901 | case R_PPC64_DTPREL16_HIGHEST: | |
12902 | case R_PPC64_DTPREL16_HIGHESTA: | |
e1918d23 | 12903 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
12904 | break; |
12905 | ||
e515b051 AM |
12906 | case R_PPC64_DTPMOD64: |
12907 | relocation = 1; | |
12908 | addend = 0; | |
12909 | goto dodyn; | |
12910 | ||
411e1bfb | 12911 | case R_PPC64_TPREL64: |
e1918d23 | 12912 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
12913 | goto dodyn; |
12914 | ||
12915 | case R_PPC64_DTPREL64: | |
e1918d23 | 12916 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
12917 | /* Fall thru */ |
12918 | ||
65f38f15 AM |
12919 | /* Relocations that may need to be propagated if this is a |
12920 | dynamic object. */ | |
04c9666a | 12921 | case R_PPC64_REL30: |
65f38f15 AM |
12922 | case R_PPC64_REL32: |
12923 | case R_PPC64_REL64: | |
12924 | case R_PPC64_ADDR14: | |
12925 | case R_PPC64_ADDR14_BRNTAKEN: | |
12926 | case R_PPC64_ADDR14_BRTAKEN: | |
12927 | case R_PPC64_ADDR16: | |
12928 | case R_PPC64_ADDR16_DS: | |
12929 | case R_PPC64_ADDR16_HA: | |
12930 | case R_PPC64_ADDR16_HI: | |
12931 | case R_PPC64_ADDR16_HIGHER: | |
12932 | case R_PPC64_ADDR16_HIGHERA: | |
12933 | case R_PPC64_ADDR16_HIGHEST: | |
12934 | case R_PPC64_ADDR16_HIGHESTA: | |
12935 | case R_PPC64_ADDR16_LO: | |
12936 | case R_PPC64_ADDR16_LO_DS: | |
12937 | case R_PPC64_ADDR24: | |
65f38f15 AM |
12938 | case R_PPC64_ADDR32: |
12939 | case R_PPC64_ADDR64: | |
12940 | case R_PPC64_UADDR16: | |
12941 | case R_PPC64_UADDR32: | |
12942 | case R_PPC64_UADDR64: | |
411e1bfb | 12943 | dodyn: |
5d1634d7 | 12944 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
12945 | break; |
12946 | ||
41bd81ab AM |
12947 | if (NO_OPD_RELOCS && is_opd) |
12948 | break; | |
12949 | ||
65f38f15 | 12950 | if ((info->shared |
4e795f50 | 12951 | && (h == NULL |
039b3fef AM |
12952 | || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT |
12953 | || h->elf.root.type != bfd_link_hash_undefweak) | |
1d483afe | 12954 | && (must_be_dyn_reloc (info, r_type) |
039b3fef | 12955 | || !SYMBOL_CALLS_LOCAL (info, &h->elf))) |
f4656909 AM |
12956 | || (ELIMINATE_COPY_RELOCS |
12957 | && !info->shared | |
65f38f15 | 12958 | && h != NULL |
039b3fef | 12959 | && h->elf.dynindx != -1 |
f5385ebf | 12960 | && !h->elf.non_got_ref |
25f23106 AM |
12961 | && !h->elf.def_regular) |
12962 | || (!info->shared | |
12963 | && (h != NULL | |
12964 | ? h->elf.type == STT_GNU_IFUNC | |
12965 | : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))) | |
65f38f15 | 12966 | { |
b34976b6 | 12967 | bfd_boolean skip, relocate; |
65f38f15 | 12968 | asection *sreloc; |
1cf1f670 | 12969 | bfd_vma out_off; |
65f38f15 AM |
12970 | |
12971 | /* When generating a dynamic object, these relocations | |
12972 | are copied into the output file to be resolved at run | |
12973 | time. */ | |
12974 | ||
b34976b6 AM |
12975 | skip = FALSE; |
12976 | relocate = FALSE; | |
65f38f15 | 12977 | |
1cf1f670 AM |
12978 | out_off = _bfd_elf_section_offset (output_bfd, info, |
12979 | input_section, rel->r_offset); | |
12980 | if (out_off == (bfd_vma) -1) | |
b34976b6 | 12981 | skip = TRUE; |
1cf1f670 | 12982 | else if (out_off == (bfd_vma) -2) |
b34976b6 | 12983 | skip = TRUE, relocate = TRUE; |
1cf1f670 AM |
12984 | out_off += (input_section->output_section->vma |
12985 | + input_section->output_offset); | |
12986 | outrel.r_offset = out_off; | |
411e1bfb | 12987 | outrel.r_addend = rel->r_addend; |
65f38f15 | 12988 | |
1cf1f670 AM |
12989 | /* Optimize unaligned reloc use. */ |
12990 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) | |
12991 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) | |
12992 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; | |
12993 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) | |
12994 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) | |
12995 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; | |
12996 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) | |
12997 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) | |
12998 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; | |
12999 | ||
65f38f15 | 13000 | if (skip) |
0bb2d96a | 13001 | memset (&outrel, 0, sizeof outrel); |
726d3ab0 | 13002 | else if (!SYMBOL_CALLS_LOCAL (info, &h->elf) |
0b13192e AM |
13003 | && !is_opd |
13004 | && r_type != R_PPC64_TOC) | |
039b3fef | 13005 | outrel.r_info = ELF64_R_INFO (h->elf.dynindx, r_type); |
65f38f15 AM |
13006 | else |
13007 | { | |
41bd81ab AM |
13008 | /* This symbol is local, or marked to become local, |
13009 | or this is an opd section reloc which must point | |
13010 | at a local function. */ | |
65f38f15 | 13011 | outrel.r_addend += relocation; |
e86ce104 | 13012 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 13013 | { |
3fad3c7c | 13014 | if (is_opd && h != NULL) |
afbe61cf AM |
13015 | { |
13016 | /* Lie about opd entries. This case occurs | |
13017 | when building shared libraries and we | |
13018 | reference a function in another shared | |
3fad3c7c AM |
13019 | lib. The same thing happens for a weak |
13020 | definition in an application that's | |
13021 | overridden by a strong definition in a | |
13022 | shared lib. (I believe this is a generic | |
13023 | bug in binutils handling of weak syms.) | |
13024 | In these cases we won't use the opd | |
1e2f5b6e | 13025 | entry in this lib. */ |
b34976b6 | 13026 | unresolved_reloc = FALSE; |
afbe61cf | 13027 | } |
25f23106 AM |
13028 | if (!is_opd |
13029 | && r_type == R_PPC64_ADDR64 | |
13030 | && (h != NULL | |
13031 | ? h->elf.type == STT_GNU_IFUNC | |
13032 | : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)) | |
13033 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE); | |
13034 | else | |
13035 | { | |
13036 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
81407a69 | 13037 | |
25f23106 AM |
13038 | /* We need to relocate .opd contents for ld.so. |
13039 | Prelink also wants simple and consistent rules | |
13040 | for relocs. This make all RELATIVE relocs have | |
13041 | *r_offset equal to r_addend. */ | |
13042 | relocate = TRUE; | |
13043 | } | |
65f38f15 AM |
13044 | } |
13045 | else | |
13046 | { | |
13047 | long indx = 0; | |
13048 | ||
25f23106 AM |
13049 | if (h != NULL |
13050 | ? h->elf.type == STT_GNU_IFUNC | |
13051 | : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
13052 | { | |
25f53a85 AM |
13053 | info->callbacks->einfo |
13054 | (_("%H: relocation %s for indirect " | |
13055 | "function %s unsupported\n"), | |
13056 | input_bfd, input_section, rel->r_offset, | |
25f23106 AM |
13057 | ppc64_elf_howto_table[r_type]->name, |
13058 | sym_name); | |
13059 | ret = FALSE; | |
13060 | } | |
cf35638d | 13061 | else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec)) |
65f38f15 AM |
13062 | ; |
13063 | else if (sec == NULL || sec->owner == NULL) | |
13064 | { | |
13065 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 13066 | return FALSE; |
65f38f15 AM |
13067 | } |
13068 | else | |
13069 | { | |
13070 | asection *osec; | |
13071 | ||
13072 | osec = sec->output_section; | |
13073 | indx = elf_section_data (osec)->dynindx; | |
13074 | ||
74541ad4 AM |
13075 | if (indx == 0) |
13076 | { | |
13077 | if ((osec->flags & SEC_READONLY) == 0 | |
13078 | && htab->elf.data_index_section != NULL) | |
13079 | osec = htab->elf.data_index_section; | |
13080 | else | |
13081 | osec = htab->elf.text_index_section; | |
13082 | indx = elf_section_data (osec)->dynindx; | |
13083 | } | |
13084 | BFD_ASSERT (indx != 0); | |
13085 | ||
65f38f15 AM |
13086 | /* We are turning this relocation into one |
13087 | against a section symbol, so subtract out | |
13088 | the output section's address but not the | |
13089 | offset of the input section in the output | |
13090 | section. */ | |
13091 | outrel.r_addend -= osec->vma; | |
13092 | } | |
13093 | ||
13094 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
13095 | } | |
13096 | } | |
13097 | ||
13098 | sreloc = elf_section_data (input_section)->sreloc; | |
25f23106 AM |
13099 | if (!htab->elf.dynamic_sections_created) |
13100 | sreloc = htab->reliplt; | |
65f38f15 AM |
13101 | if (sreloc == NULL) |
13102 | abort (); | |
13103 | ||
dfbb6ac9 AM |
13104 | if (sreloc->reloc_count * sizeof (Elf64_External_Rela) |
13105 | >= sreloc->size) | |
13106 | abort (); | |
947216bf AM |
13107 | loc = sreloc->contents; |
13108 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
13109 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
13110 | ||
13111 | /* If this reloc is against an external symbol, it will | |
13112 | be computed at runtime, so there's no need to do | |
81407a69 AM |
13113 | anything now. However, for the sake of prelink ensure |
13114 | that the section contents are a known value. */ | |
65f38f15 | 13115 | if (! relocate) |
81407a69 AM |
13116 | { |
13117 | unresolved_reloc = FALSE; | |
13118 | /* The value chosen here is quite arbitrary as ld.so | |
13119 | ignores section contents except for the special | |
13120 | case of .opd where the contents might be accessed | |
13121 | before relocation. Choose zero, as that won't | |
13122 | cause reloc overflow. */ | |
13123 | relocation = 0; | |
13124 | addend = 0; | |
13125 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs | |
13126 | to improve backward compatibility with older | |
13127 | versions of ld. */ | |
13128 | if (r_type == R_PPC64_ADDR64) | |
13129 | addend = outrel.r_addend; | |
13130 | /* Adjust pc_relative relocs to have zero in *r_offset. */ | |
4ce794b7 | 13131 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
000732f7 AM |
13132 | addend = (input_section->output_section->vma |
13133 | + input_section->output_offset | |
13134 | + rel->r_offset); | |
81407a69 | 13135 | } |
65f38f15 | 13136 | } |
5bd4f169 AM |
13137 | break; |
13138 | ||
65f38f15 AM |
13139 | case R_PPC64_COPY: |
13140 | case R_PPC64_GLOB_DAT: | |
13141 | case R_PPC64_JMP_SLOT: | |
25f23106 | 13142 | case R_PPC64_JMP_IREL: |
65f38f15 AM |
13143 | case R_PPC64_RELATIVE: |
13144 | /* We shouldn't ever see these dynamic relocs in relocatable | |
13145 | files. */ | |
ae9a127f | 13146 | /* Fall through. */ |
65f38f15 AM |
13147 | |
13148 | case R_PPC64_PLTGOT16: | |
13149 | case R_PPC64_PLTGOT16_DS: | |
13150 | case R_PPC64_PLTGOT16_HA: | |
13151 | case R_PPC64_PLTGOT16_HI: | |
13152 | case R_PPC64_PLTGOT16_LO: | |
13153 | case R_PPC64_PLTGOT16_LO_DS: | |
13154 | case R_PPC64_PLTREL32: | |
13155 | case R_PPC64_PLTREL64: | |
13156 | /* These ones haven't been implemented yet. */ | |
13157 | ||
25f53a85 AM |
13158 | info->callbacks->einfo |
13159 | (_("%B: relocation %s is not supported for symbol %s\n"), | |
d003868e | 13160 | input_bfd, |
4ce794b7 | 13161 | ppc64_elf_howto_table[r_type]->name, sym_name); |
5bd4f169 AM |
13162 | |
13163 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 13164 | ret = FALSE; |
5bd4f169 | 13165 | continue; |
65f38f15 | 13166 | } |
5bd4f169 | 13167 | |
67f0cbdb AM |
13168 | /* Multi-instruction sequences that access the TOC can be |
13169 | optimized, eg. addis ra,r2,0; addi rb,ra,x; | |
13170 | to nop; addi rb,r2,x; */ | |
13171 | switch (r_type) | |
13172 | { | |
13173 | default: | |
13174 | break; | |
13175 | ||
13176 | case R_PPC64_GOT_TLSLD16_HI: | |
13177 | case R_PPC64_GOT_TLSGD16_HI: | |
13178 | case R_PPC64_GOT_TPREL16_HI: | |
13179 | case R_PPC64_GOT_DTPREL16_HI: | |
13180 | case R_PPC64_GOT16_HI: | |
13181 | case R_PPC64_TOC16_HI: | |
13182 | /* These relocs would only be useful if building up an | |
13183 | offset to later add to r2, perhaps in an indexed | |
13184 | addressing mode instruction. Don't try to optimize. | |
13185 | Unfortunately, the possibility of someone building up an | |
13186 | offset like this or even with the HA relocs, means that | |
13187 | we need to check the high insn when optimizing the low | |
13188 | insn. */ | |
13189 | break; | |
13190 | ||
13191 | case R_PPC64_GOT_TLSLD16_HA: | |
13192 | case R_PPC64_GOT_TLSGD16_HA: | |
13193 | case R_PPC64_GOT_TPREL16_HA: | |
13194 | case R_PPC64_GOT_DTPREL16_HA: | |
13195 | case R_PPC64_GOT16_HA: | |
13196 | case R_PPC64_TOC16_HA: | |
d983b7a0 | 13197 | /* nop is done later. */ |
67f0cbdb AM |
13198 | break; |
13199 | ||
13200 | case R_PPC64_GOT_TLSLD16_LO: | |
13201 | case R_PPC64_GOT_TLSGD16_LO: | |
13202 | case R_PPC64_GOT_TPREL16_LO_DS: | |
13203 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
13204 | case R_PPC64_GOT16_LO: | |
13205 | case R_PPC64_GOT16_LO_DS: | |
13206 | case R_PPC64_TOC16_LO: | |
13207 | case R_PPC64_TOC16_LO_DS: | |
13208 | if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000) | |
13209 | { | |
13210 | bfd_byte *p = contents + (rel->r_offset & ~3); | |
13211 | insn = bfd_get_32 (input_bfd, p); | |
13212 | if ((insn & (0x3f << 26)) == 14u << 26 /* addi */ | |
13213 | || (insn & (0x3f << 26)) == 32u << 26 /* lwz */ | |
13214 | || (insn & (0x3f << 26)) == 34u << 26 /* lbz */ | |
13215 | || (insn & (0x3f << 26)) == 36u << 26 /* stw */ | |
13216 | || (insn & (0x3f << 26)) == 38u << 26 /* stb */ | |
13217 | || (insn & (0x3f << 26)) == 40u << 26 /* lhz */ | |
13218 | || (insn & (0x3f << 26)) == 42u << 26 /* lha */ | |
13219 | || (insn & (0x3f << 26)) == 44u << 26 /* sth */ | |
13220 | || (insn & (0x3f << 26)) == 46u << 26 /* lmw */ | |
13221 | || (insn & (0x3f << 26)) == 47u << 26 /* stmw */ | |
13222 | || (insn & (0x3f << 26)) == 48u << 26 /* lfs */ | |
13223 | || (insn & (0x3f << 26)) == 50u << 26 /* lfd */ | |
13224 | || (insn & (0x3f << 26)) == 52u << 26 /* stfs */ | |
13225 | || (insn & (0x3f << 26)) == 54u << 26 /* stfd */ | |
13226 | || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */ | |
13227 | && (insn & 3) != 1) | |
13228 | || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */ | |
13229 | && ((insn & 3) == 0 || (insn & 3) == 3))) | |
13230 | { | |
13231 | unsigned int reg = (insn >> 16) & 0x1f; | |
d983b7a0 AM |
13232 | const Elf_Internal_Rela *ha; |
13233 | bfd_boolean match_addend; | |
13234 | ||
13235 | match_addend = (sym != NULL | |
13236 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION); | |
13237 | ha = ha_reloc_match (relocs, rel, ®, match_addend, | |
13238 | input_bfd, contents); | |
13239 | if (ha != NULL) | |
67f0cbdb AM |
13240 | { |
13241 | insn &= ~(0x1f << 16); | |
d983b7a0 | 13242 | insn |= reg << 16; |
67f0cbdb | 13243 | bfd_put_32 (input_bfd, insn, p); |
d983b7a0 AM |
13244 | if (ha_opt == NULL) |
13245 | { | |
13246 | ha_opt = bfd_zmalloc (input_section->reloc_count); | |
13247 | if (ha_opt == NULL) | |
13248 | return FALSE; | |
13249 | } | |
13250 | ha_opt[ha - relocs] = 1; | |
67f0cbdb | 13251 | } |
d983b7a0 AM |
13252 | else |
13253 | /* If we don't find a matching high part insn, | |
13254 | something is fishy. Refuse to nop any high | |
13255 | part insn in this section. */ | |
13256 | no_ha_opt = TRUE; | |
67f0cbdb AM |
13257 | } |
13258 | } | |
13259 | break; | |
13260 | } | |
13261 | ||
65f38f15 AM |
13262 | /* Do any further special processing. */ |
13263 | switch (r_type) | |
13264 | { | |
13265 | default: | |
13266 | break; | |
13267 | ||
13268 | case R_PPC64_ADDR16_HA: | |
25f23106 | 13269 | case R_PPC64_REL16_HA: |
65f38f15 AM |
13270 | case R_PPC64_ADDR16_HIGHERA: |
13271 | case R_PPC64_ADDR16_HIGHESTA: | |
65f38f15 AM |
13272 | case R_PPC64_TOC16_HA: |
13273 | case R_PPC64_SECTOFF_HA: | |
411e1bfb AM |
13274 | case R_PPC64_TPREL16_HA: |
13275 | case R_PPC64_DTPREL16_HA: | |
411e1bfb AM |
13276 | case R_PPC64_TPREL16_HIGHER: |
13277 | case R_PPC64_TPREL16_HIGHERA: | |
13278 | case R_PPC64_TPREL16_HIGHEST: | |
13279 | case R_PPC64_TPREL16_HIGHESTA: | |
13280 | case R_PPC64_DTPREL16_HIGHER: | |
13281 | case R_PPC64_DTPREL16_HIGHERA: | |
13282 | case R_PPC64_DTPREL16_HIGHEST: | |
13283 | case R_PPC64_DTPREL16_HIGHESTA: | |
65f38f15 AM |
13284 | /* It's just possible that this symbol is a weak symbol |
13285 | that's not actually defined anywhere. In that case, | |
13286 | 'sec' would be NULL, and we should leave the symbol | |
13287 | alone (it will be set to zero elsewhere in the link). */ | |
5c5f6e17 AM |
13288 | if (sec == NULL) |
13289 | break; | |
13290 | /* Fall thru */ | |
13291 | ||
13292 | case R_PPC64_GOT16_HA: | |
13293 | case R_PPC64_PLTGOT16_HA: | |
13294 | case R_PPC64_PLT16_HA: | |
13295 | case R_PPC64_GOT_TLSGD16_HA: | |
13296 | case R_PPC64_GOT_TLSLD16_HA: | |
13297 | case R_PPC64_GOT_TPREL16_HA: | |
13298 | case R_PPC64_GOT_DTPREL16_HA: | |
13299 | /* Add 0x10000 if sign bit in 0:15 is set. | |
13300 | Bits 0:15 are not used. */ | |
13301 | addend += 0x8000; | |
65f38f15 AM |
13302 | break; |
13303 | ||
13304 | case R_PPC64_ADDR16_DS: | |
13305 | case R_PPC64_ADDR16_LO_DS: | |
13306 | case R_PPC64_GOT16_DS: | |
13307 | case R_PPC64_GOT16_LO_DS: | |
13308 | case R_PPC64_PLT16_LO_DS: | |
13309 | case R_PPC64_SECTOFF_DS: | |
13310 | case R_PPC64_SECTOFF_LO_DS: | |
13311 | case R_PPC64_TOC16_DS: | |
13312 | case R_PPC64_TOC16_LO_DS: | |
13313 | case R_PPC64_PLTGOT16_DS: | |
13314 | case R_PPC64_PLTGOT16_LO_DS: | |
411e1bfb AM |
13315 | case R_PPC64_GOT_TPREL16_DS: |
13316 | case R_PPC64_GOT_TPREL16_LO_DS: | |
13317 | case R_PPC64_GOT_DTPREL16_DS: | |
13318 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
13319 | case R_PPC64_TPREL16_DS: | |
13320 | case R_PPC64_TPREL16_LO_DS: | |
13321 | case R_PPC64_DTPREL16_DS: | |
13322 | case R_PPC64_DTPREL16_LO_DS: | |
adadcc0c AM |
13323 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
13324 | mask = 3; | |
13325 | /* If this reloc is against an lq insn, then the value must be | |
13326 | a multiple of 16. This is somewhat of a hack, but the | |
13327 | "correct" way to do this by defining _DQ forms of all the | |
13328 | _DS relocs bloats all reloc switches in this file. It | |
13329 | doesn't seem to make much sense to use any of these relocs | |
13330 | in data, so testing the insn should be safe. */ | |
494dac0c | 13331 | if ((insn & (0x3f << 26)) == (56u << 26)) |
adadcc0c AM |
13332 | mask = 15; |
13333 | if (((relocation + addend) & mask) != 0) | |
65f38f15 | 13334 | { |
25f53a85 AM |
13335 | info->callbacks->einfo |
13336 | (_("%H: error: %s not a multiple of %u\n"), | |
13337 | input_bfd, input_section, rel->r_offset, | |
4ce794b7 | 13338 | ppc64_elf_howto_table[r_type]->name, |
adadcc0c | 13339 | mask + 1); |
65f38f15 | 13340 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 13341 | ret = FALSE; |
65f38f15 AM |
13342 | continue; |
13343 | } | |
13344 | break; | |
5bd4f169 AM |
13345 | } |
13346 | ||
239e1f3a AM |
13347 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
13348 | because such sections are not SEC_ALLOC and thus ld.so will | |
13349 | not process them. */ | |
65f38f15 | 13350 | if (unresolved_reloc |
239e1f3a | 13351 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
f5385ebf | 13352 | && h->elf.def_dynamic)) |
9c07fe7c | 13353 | { |
25f53a85 AM |
13354 | info->callbacks->einfo |
13355 | (_("%H: unresolvable %s relocation against symbol `%s'\n"), | |
13356 | input_bfd, input_section, rel->r_offset, | |
7b609f53 | 13357 | ppc64_elf_howto_table[(int) r_type]->name, |
039b3fef | 13358 | h->elf.root.root.string); |
b34976b6 | 13359 | ret = FALSE; |
9c07fe7c | 13360 | } |
5bd4f169 | 13361 | |
65f38f15 | 13362 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
13363 | input_bfd, |
13364 | input_section, | |
13365 | contents, | |
411e1bfb | 13366 | rel->r_offset, |
5bd4f169 AM |
13367 | relocation, |
13368 | addend); | |
13369 | ||
ef60b7ff | 13370 | if (r != bfd_reloc_ok) |
5bd4f169 | 13371 | { |
cd27b276 AM |
13372 | if (sym_name == NULL) |
13373 | sym_name = "(null)"; | |
13374 | if (r == bfd_reloc_overflow) | |
5bd4f169 | 13375 | { |
cd27b276 AM |
13376 | if (warned) |
13377 | continue; | |
13378 | if (h != NULL | |
039b3fef | 13379 | && h->elf.root.type == bfd_link_hash_undefweak |
4ce794b7 | 13380 | && ppc64_elf_howto_table[r_type]->pc_relative) |
5bd4f169 AM |
13381 | { |
13382 | /* Assume this is a call protected by other code that | |
13383 | detects the symbol is undefined. If this is the case, | |
13384 | we can safely ignore the overflow. If not, the | |
13385 | program is hosed anyway, and a little warning isn't | |
13386 | going to help. */ | |
13387 | ||
13388 | continue; | |
13389 | } | |
13390 | ||
ef60b7ff | 13391 | if (!((*info->callbacks->reloc_overflow) |
dfeffb9f L |
13392 | (info, (h ? &h->elf.root : NULL), sym_name, |
13393 | ppc64_elf_howto_table[r_type]->name, | |
4cc603a5 | 13394 | orig_addend, input_bfd, input_section, rel->r_offset))) |
b34976b6 | 13395 | return FALSE; |
ef60b7ff AM |
13396 | } |
13397 | else | |
13398 | { | |
25f53a85 AM |
13399 | info->callbacks->einfo |
13400 | (_("%H: %s reloc against `%s': error %d\n"), | |
13401 | input_bfd, input_section, rel->r_offset, | |
4ce794b7 | 13402 | ppc64_elf_howto_table[r_type]->name, |
7b609f53 AM |
13403 | sym_name, |
13404 | (int) r); | |
b34976b6 | 13405 | ret = FALSE; |
ef60b7ff | 13406 | } |
5bd4f169 | 13407 | } |
5bd4f169 AM |
13408 | } |
13409 | ||
d983b7a0 AM |
13410 | if (ha_opt != NULL) |
13411 | { | |
13412 | if (!no_ha_opt) | |
13413 | { | |
13414 | unsigned char *opt = ha_opt; | |
13415 | rel = relocs; | |
13416 | relend = relocs + input_section->reloc_count; | |
13417 | for (; rel < relend; opt++, rel++) | |
13418 | if (*opt != 0) | |
13419 | { | |
13420 | bfd_byte *p = contents + (rel->r_offset & ~3); | |
13421 | bfd_put_32 (input_bfd, NOP, p); | |
13422 | } | |
13423 | } | |
13424 | free (ha_opt); | |
13425 | } | |
13426 | ||
645ea6a9 AM |
13427 | /* If we're emitting relocations, then shortly after this function |
13428 | returns, reloc offsets and addends for this section will be | |
13429 | adjusted. Worse, reloc symbol indices will be for the output | |
8860955f AM |
13430 | file rather than the input. Save a copy of the relocs for |
13431 | opd_entry_value. */ | |
4cc603a5 | 13432 | if (is_opd && (info->emitrelocations || info->relocatable)) |
8860955f AM |
13433 | { |
13434 | bfd_size_type amt; | |
13435 | amt = input_section->reloc_count * sizeof (Elf_Internal_Rela); | |
13436 | rel = bfd_alloc (input_bfd, amt); | |
13437 | BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd_relocs == NULL); | |
13438 | ppc64_elf_tdata (input_bfd)->opd_relocs = rel; | |
13439 | if (rel == NULL) | |
13440 | return FALSE; | |
13441 | memcpy (rel, relocs, amt); | |
13442 | } | |
5bd4f169 AM |
13443 | return ret; |
13444 | } | |
13445 | ||
754021d0 AM |
13446 | /* Adjust the value of any local symbols in opd sections. */ |
13447 | ||
6e0b88f1 | 13448 | static int |
754021d0 AM |
13449 | ppc64_elf_output_symbol_hook (struct bfd_link_info *info, |
13450 | const char *name ATTRIBUTE_UNUSED, | |
13451 | Elf_Internal_Sym *elfsym, | |
13452 | asection *input_sec, | |
13453 | struct elf_link_hash_entry *h) | |
13454 | { | |
74f0fb50 AM |
13455 | struct _opd_sec_data *opd; |
13456 | long adjust; | |
754021d0 AM |
13457 | bfd_vma value; |
13458 | ||
4025353c | 13459 | if (h != NULL) |
6e0b88f1 | 13460 | return 1; |
4025353c | 13461 | |
74f0fb50 AM |
13462 | opd = get_opd_info (input_sec); |
13463 | if (opd == NULL || opd->adjust == NULL) | |
6e0b88f1 | 13464 | return 1; |
754021d0 AM |
13465 | |
13466 | value = elfsym->st_value - input_sec->output_offset; | |
13467 | if (!info->relocatable) | |
13468 | value -= input_sec->output_section->vma; | |
13469 | ||
74f0fb50 | 13470 | adjust = opd->adjust[value / 8]; |
4025353c | 13471 | if (adjust == -1) |
6e0b88f1 AM |
13472 | return 2; |
13473 | ||
13474 | elfsym->st_value += adjust; | |
13475 | return 1; | |
754021d0 AM |
13476 | } |
13477 | ||
5bd4f169 AM |
13478 | /* Finish up dynamic symbol handling. We set the contents of various |
13479 | dynamic sections here. */ | |
13480 | ||
b34976b6 | 13481 | static bfd_boolean |
4ce794b7 AM |
13482 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
13483 | struct bfd_link_info *info, | |
13484 | struct elf_link_hash_entry *h, | |
13485 | Elf_Internal_Sym *sym) | |
5bd4f169 | 13486 | { |
65f38f15 | 13487 | struct ppc_link_hash_table *htab; |
8387904d AM |
13488 | struct plt_entry *ent; |
13489 | Elf_Internal_Rela rela; | |
13490 | bfd_byte *loc; | |
5bd4f169 | 13491 | |
65f38f15 | 13492 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
13493 | if (htab == NULL) |
13494 | return FALSE; | |
5bd4f169 | 13495 | |
8387904d AM |
13496 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
13497 | if (ent->plt.offset != (bfd_vma) -1) | |
13498 | { | |
13499 | /* This symbol has an entry in the procedure linkage | |
13500 | table. Set it up. */ | |
e054468f AM |
13501 | if (!htab->elf.dynamic_sections_created |
13502 | || h->dynindx == -1) | |
13503 | { | |
13504 | BFD_ASSERT (h->type == STT_GNU_IFUNC | |
13505 | && h->def_regular | |
13506 | && (h->root.type == bfd_link_hash_defined | |
13507 | || h->root.type == bfd_link_hash_defweak)); | |
25f23106 AM |
13508 | rela.r_offset = (htab->iplt->output_section->vma |
13509 | + htab->iplt->output_offset | |
13510 | + ent->plt.offset); | |
13511 | rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL); | |
e054468f AM |
13512 | rela.r_addend = (h->root.u.def.value |
13513 | + h->root.u.def.section->output_offset | |
13514 | + h->root.u.def.section->output_section->vma | |
13515 | + ent->addend); | |
25f23106 AM |
13516 | loc = (htab->reliplt->contents |
13517 | + (htab->reliplt->reloc_count++ | |
13518 | * sizeof (Elf64_External_Rela))); | |
e054468f AM |
13519 | } |
13520 | else | |
13521 | { | |
25f23106 AM |
13522 | rela.r_offset = (htab->plt->output_section->vma |
13523 | + htab->plt->output_offset | |
13524 | + ent->plt.offset); | |
e054468f AM |
13525 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); |
13526 | rela.r_addend = ent->addend; | |
25f23106 AM |
13527 | loc = (htab->relplt->contents |
13528 | + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) | |
13529 | / (PLT_ENTRY_SIZE / sizeof (Elf64_External_Rela)))); | |
e054468f | 13530 | } |
8387904d AM |
13531 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
13532 | } | |
5bd4f169 | 13533 | |
f5385ebf | 13534 | if (h->needs_copy) |
5bd4f169 | 13535 | { |
65f38f15 | 13536 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 13537 | |
65f38f15 AM |
13538 | if (h->dynindx == -1 |
13539 | || (h->root.type != bfd_link_hash_defined | |
13540 | && h->root.type != bfd_link_hash_defweak) | |
4ce794b7 | 13541 | || htab->relbss == NULL) |
65f38f15 | 13542 | abort (); |
5bd4f169 AM |
13543 | |
13544 | rela.r_offset = (h->root.u.def.value | |
13545 | + h->root.u.def.section->output_section->vma | |
13546 | + h->root.u.def.section->output_offset); | |
13547 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
13548 | rela.r_addend = 0; | |
4ce794b7 AM |
13549 | loc = htab->relbss->contents; |
13550 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 13551 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
13552 | } |
13553 | ||
5bd4f169 AM |
13554 | /* Mark some specially defined symbols as absolute. */ |
13555 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
13556 | sym->st_shndx = SHN_ABS; | |
13557 | ||
b34976b6 | 13558 | return TRUE; |
5bd4f169 AM |
13559 | } |
13560 | ||
65f38f15 AM |
13561 | /* Used to decide how to sort relocs in an optimal manner for the |
13562 | dynamic linker, before writing them out. */ | |
13563 | ||
13564 | static enum elf_reloc_type_class | |
4ce794b7 | 13565 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
65f38f15 | 13566 | { |
04c9666a | 13567 | enum elf_ppc64_reloc_type r_type; |
a33d1f77 | 13568 | |
4ce794b7 | 13569 | r_type = ELF64_R_TYPE (rela->r_info); |
a33d1f77 | 13570 | switch (r_type) |
65f38f15 AM |
13571 | { |
13572 | case R_PPC64_RELATIVE: | |
13573 | return reloc_class_relative; | |
13574 | case R_PPC64_JMP_SLOT: | |
13575 | return reloc_class_plt; | |
13576 | case R_PPC64_COPY: | |
13577 | return reloc_class_copy; | |
13578 | default: | |
13579 | return reloc_class_normal; | |
13580 | } | |
13581 | } | |
13582 | ||
5bd4f169 AM |
13583 | /* Finish up the dynamic sections. */ |
13584 | ||
b34976b6 | 13585 | static bfd_boolean |
4ce794b7 AM |
13586 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
13587 | struct bfd_link_info *info) | |
5bd4f169 | 13588 | { |
65f38f15 AM |
13589 | struct ppc_link_hash_table *htab; |
13590 | bfd *dynobj; | |
5bd4f169 | 13591 | asection *sdyn; |
5bd4f169 | 13592 | |
65f38f15 | 13593 | htab = ppc_hash_table (info); |
4dfe6ac6 NC |
13594 | if (htab == NULL) |
13595 | return FALSE; | |
13596 | ||
65f38f15 | 13597 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
13598 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
13599 | ||
65f38f15 | 13600 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 13601 | { |
5bd4f169 AM |
13602 | Elf64_External_Dyn *dyncon, *dynconend; |
13603 | ||
4ce794b7 | 13604 | if (sdyn == NULL || htab->got == NULL) |
65f38f15 | 13605 | abort (); |
5bd4f169 AM |
13606 | |
13607 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
eea6121a | 13608 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
5bd4f169 AM |
13609 | for (; dyncon < dynconend; dyncon++) |
13610 | { | |
13611 | Elf_Internal_Dyn dyn; | |
19397422 | 13612 | asection *s; |
5bd4f169 AM |
13613 | |
13614 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
13615 | ||
13616 | switch (dyn.d_tag) | |
13617 | { | |
65f38f15 AM |
13618 | default: |
13619 | continue; | |
5bd4f169 | 13620 | |
5d1634d7 | 13621 | case DT_PPC64_GLINK: |
4ce794b7 | 13622 | s = htab->glink; |
6348e046 | 13623 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
ad8e1ba5 AM |
13624 | /* We stupidly defined DT_PPC64_GLINK to be the start |
13625 | of glink rather than the first entry point, which is | |
13626 | what ld.so needs, and now have a bigger stub to | |
13627 | support automatic multiple TOCs. */ | |
13628 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; | |
5d1634d7 AM |
13629 | break; |
13630 | ||
19397422 AM |
13631 | case DT_PPC64_OPD: |
13632 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
13633 | if (s == NULL) |
13634 | continue; | |
13635 | dyn.d_un.d_ptr = s->vma; | |
19397422 AM |
13636 | break; |
13637 | ||
13638 | case DT_PPC64_OPDSZ: | |
13639 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
13640 | if (s == NULL) |
13641 | continue; | |
eea6121a | 13642 | dyn.d_un.d_val = s->size; |
19397422 AM |
13643 | break; |
13644 | ||
65f38f15 | 13645 | case DT_PLTGOT: |
4ce794b7 | 13646 | s = htab->plt; |
6348e046 | 13647 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 AM |
13648 | break; |
13649 | ||
13650 | case DT_JMPREL: | |
4ce794b7 | 13651 | s = htab->relplt; |
6348e046 | 13652 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 | 13653 | break; |
5bd4f169 | 13654 | |
65f38f15 | 13655 | case DT_PLTRELSZ: |
eea6121a | 13656 | dyn.d_un.d_val = htab->relplt->size; |
5d1634d7 AM |
13657 | break; |
13658 | ||
13659 | case DT_RELASZ: | |
13660 | /* Don't count procedure linkage table relocs in the | |
13661 | overall reloc count. */ | |
4ce794b7 | 13662 | s = htab->relplt; |
6348e046 AM |
13663 | if (s == NULL) |
13664 | continue; | |
eea6121a | 13665 | dyn.d_un.d_val -= s->size; |
6348e046 AM |
13666 | break; |
13667 | ||
13668 | case DT_RELA: | |
13669 | /* We may not be using the standard ELF linker script. | |
13670 | If .rela.plt is the first .rela section, we adjust | |
13671 | DT_RELA to not include it. */ | |
4ce794b7 | 13672 | s = htab->relplt; |
6348e046 AM |
13673 | if (s == NULL) |
13674 | continue; | |
13675 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
13676 | continue; | |
eea6121a | 13677 | dyn.d_un.d_ptr += s->size; |
65f38f15 | 13678 | break; |
5bd4f169 | 13679 | } |
5bd4f169 | 13680 | |
65f38f15 | 13681 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 13682 | } |
5bd4f169 AM |
13683 | } |
13684 | ||
eea6121a | 13685 | if (htab->got != NULL && htab->got->size != 0) |
5d1634d7 AM |
13686 | { |
13687 | /* Fill in the first entry in the global offset table. | |
13688 | We use it to hold the link-time TOCbase. */ | |
13689 | bfd_put_64 (output_bfd, | |
60ee0d4a | 13690 | elf_gp (output_bfd) + TOC_BASE_OFF, |
4ce794b7 | 13691 | htab->got->contents); |
5d1634d7 AM |
13692 | |
13693 | /* Set .got entry size. */ | |
4ce794b7 | 13694 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
5d1634d7 AM |
13695 | } |
13696 | ||
eea6121a | 13697 | if (htab->plt != NULL && htab->plt->size != 0) |
5d1634d7 AM |
13698 | { |
13699 | /* Set .plt entry size. */ | |
4ce794b7 | 13700 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
5d1634d7 AM |
13701 | = PLT_ENTRY_SIZE; |
13702 | } | |
13703 | ||
84f5d08e AM |
13704 | /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for |
13705 | brlt ourselves if emitrelocations. */ | |
13706 | if (htab->brlt != NULL | |
13707 | && htab->brlt->reloc_count != 0 | |
13708 | && !_bfd_elf_link_output_relocs (output_bfd, | |
13709 | htab->brlt, | |
d4730f92 | 13710 | elf_section_data (htab->brlt)->rela.hdr, |
84f5d08e AM |
13711 | elf_section_data (htab->brlt)->relocs, |
13712 | NULL)) | |
13713 | return FALSE; | |
13714 | ||
176a0d42 AM |
13715 | if (htab->glink != NULL |
13716 | && htab->glink->reloc_count != 0 | |
13717 | && !_bfd_elf_link_output_relocs (output_bfd, | |
13718 | htab->glink, | |
d4730f92 | 13719 | elf_section_data (htab->glink)->rela.hdr, |
176a0d42 AM |
13720 | elf_section_data (htab->glink)->relocs, |
13721 | NULL)) | |
13722 | return FALSE; | |
13723 | ||
58d180e8 AM |
13724 | |
13725 | if (htab->glink_eh_frame != NULL | |
13726 | && htab->glink_eh_frame->sec_info_type == ELF_INFO_TYPE_EH_FRAME | |
13727 | && !_bfd_elf_write_section_eh_frame (output_bfd, info, | |
13728 | htab->glink_eh_frame, | |
13729 | htab->glink_eh_frame->contents)) | |
13730 | return FALSE; | |
13731 | ||
e717da7e | 13732 | /* We need to handle writing out multiple GOT sections ourselves, |
7b53ace3 AM |
13733 | since we didn't add them to DYNOBJ. We know dynobj is the first |
13734 | bfd. */ | |
e717da7e AM |
13735 | while ((dynobj = dynobj->link_next) != NULL) |
13736 | { | |
13737 | asection *s; | |
7b53ace3 | 13738 | |
0c8d6e5c | 13739 | if (!is_ppc64_elf (dynobj)) |
7b53ace3 AM |
13740 | continue; |
13741 | ||
e717da7e AM |
13742 | s = ppc64_elf_tdata (dynobj)->got; |
13743 | if (s != NULL | |
eea6121a | 13744 | && s->size != 0 |
e717da7e AM |
13745 | && s->output_section != bfd_abs_section_ptr |
13746 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
13747 | s->contents, s->output_offset, | |
eea6121a | 13748 | s->size)) |
e717da7e AM |
13749 | return FALSE; |
13750 | s = ppc64_elf_tdata (dynobj)->relgot; | |
13751 | if (s != NULL | |
eea6121a | 13752 | && s->size != 0 |
e717da7e AM |
13753 | && s->output_section != bfd_abs_section_ptr |
13754 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
13755 | s->contents, s->output_offset, | |
eea6121a | 13756 | s->size)) |
e717da7e AM |
13757 | return FALSE; |
13758 | } | |
f6c52c13 | 13759 | |
b34976b6 | 13760 | return TRUE; |
5bd4f169 AM |
13761 | } |
13762 | ||
5bd4f169 | 13763 | #include "elf64-target.h" |