Commit | Line | Data |
---|---|---|
5bd4f169 | 1 | /* PowerPC64-specific support for 64-bit ELF. |
b2a8e766 AM |
2 | Copyright 1999, 2000, 2001, 2002, 2003, 2004 |
3 | Free Software Foundation, Inc. | |
5bd4f169 AM |
4 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
5 | based on elf32-ppc.c by Ian Lance Taylor. | |
d37c89e5 | 6 | Largely rewritten by Alan Modra <amodra@bigpond.net.au> |
5bd4f169 | 7 | |
ae9a127f | 8 | This file is part of BFD, the Binary File Descriptor library. |
5bd4f169 | 9 | |
ae9a127f NC |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
5bd4f169 | 14 | |
ae9a127f NC |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
5bd4f169 | 19 | |
4ce794b7 AM |
20 | You should have received a copy of the GNU General Public License along |
21 | with this program; if not, write to the Free Software Foundation, Inc., | |
22 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
5bd4f169 | 23 | |
4ce794b7 AM |
24 | /* The 64-bit PowerPC ELF ABI may be found at |
25 | http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and | |
26 | http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */ | |
5bd4f169 AM |
27 | |
28 | #include "bfd.h" | |
29 | #include "sysdep.h" | |
30 | #include "bfdlink.h" | |
31 | #include "libbfd.h" | |
32 | #include "elf-bfd.h" | |
04c9666a | 33 | #include "elf/ppc64.h" |
5d1634d7 | 34 | #include "elf64-ppc.h" |
5bd4f169 | 35 | |
805fc799 | 36 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
4ce794b7 | 37 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 38 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
4ce794b7 | 39 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 40 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
4ce794b7 | 41 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 42 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
4ce794b7 | 43 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 44 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
4ce794b7 | 45 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 46 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
4ce794b7 | 47 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 48 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
4ce794b7 | 49 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 50 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
4ce794b7 | 51 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5bd4f169 AM |
52 | |
53 | ||
ad8e1ba5 AM |
54 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
55 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
56 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
57 | #define TARGET_BIG_NAME "elf64-powerpc" | |
58 | #define ELF_ARCH bfd_arch_powerpc | |
59 | #define ELF_MACHINE_CODE EM_PPC64 | |
60 | #define ELF_MAXPAGESIZE 0x10000 | |
61 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
62 | ||
63 | #define elf_backend_want_got_sym 0 | |
64 | #define elf_backend_want_plt_sym 0 | |
65 | #define elf_backend_plt_alignment 3 | |
66 | #define elf_backend_plt_not_loaded 1 | |
67 | #define elf_backend_got_symbol_offset 0 | |
68 | #define elf_backend_got_header_size 8 | |
ad8e1ba5 AM |
69 | #define elf_backend_can_gc_sections 1 |
70 | #define elf_backend_can_refcount 1 | |
71 | #define elf_backend_rela_normal 1 | |
72 | ||
e717da7e | 73 | #define bfd_elf64_mkobject ppc64_elf_mkobject |
ad8e1ba5 AM |
74 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
75 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data | |
76 | #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook | |
77 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create | |
78 | #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free | |
79 | ||
80 | #define elf_backend_object_p ppc64_elf_object_p | |
d37c89e5 AM |
81 | #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus |
82 | #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo | |
ad8e1ba5 AM |
83 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
84 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
555cd476 | 85 | #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook |
ad8e1ba5 AM |
86 | #define elf_backend_check_relocs ppc64_elf_check_relocs |
87 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
88 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
89 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
90 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol | |
91 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
92 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
93 | #define elf_backend_relocate_section ppc64_elf_relocate_section | |
94 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
95 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
96 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
754021d0 | 97 | #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook |
2f89ff8d | 98 | #define elf_backend_special_sections ppc64_elf_special_sections |
ad8e1ba5 | 99 | |
5bd4f169 AM |
100 | /* The name of the dynamic interpreter. This is put in the .interp |
101 | section. */ | |
102 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
103 | ||
104 | /* The size in bytes of an entry in the procedure linkage table. */ | |
105 | #define PLT_ENTRY_SIZE 24 | |
106 | ||
107 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 108 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
109 | |
110 | /* TOC base pointers offset from start of TOC. */ | |
411e1bfb AM |
111 | #define TOC_BASE_OFF 0x8000 |
112 | ||
113 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
114 | #define TP_OFFSET 0x7000 | |
115 | #define DTP_OFFSET 0x8000 | |
5bd4f169 | 116 | |
ad8e1ba5 AM |
117 | /* .plt call stub instructions. The normal stub is like this, but |
118 | sometimes the .plt entry crosses a 64k boundary and we need to | |
119 | insert an addis to adjust r12. */ | |
120 | #define PLT_CALL_STUB_SIZE (7*4) | |
5d1634d7 AM |
121 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
122 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
123 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
124 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
125 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
126 | /* ld %r11,xxx+16@l(%r12) */ | |
127 | #define BCTR 0x4e800420 /* bctr */ | |
128 | ||
5d1634d7 | 129 | |
ad8e1ba5 AM |
130 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
131 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ | |
132 | ||
133 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
134 | ||
135 | /* glink call stub instructions. We enter with the index in R0, and the | |
136 | address of glink entry in CTR. From that, we can calculate PLT0. */ | |
137 | #define GLINK_CALL_STUB_SIZE (16*4) | |
138 | #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */ | |
139 | #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */ | |
140 | #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */ | |
141 | #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */ | |
142 | #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */ | |
143 | #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */ | |
144 | #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */ | |
145 | /* sub %r12,%r12,%r11 */ | |
146 | #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */ | |
147 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */ | |
148 | /* ld %r11,xxx@l(%r12) */ | |
149 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */ | |
150 | /* ld %r2,8(%r12) */ | |
151 | /* mtctr %r11 */ | |
152 | /* ld %r11,16(%r12) */ | |
153 | /* bctr */ | |
5d1634d7 AM |
154 | |
155 | /* Pad with this. */ | |
156 | #define NOP 0x60000000 | |
157 | ||
721956f4 AM |
158 | /* Some other nops. */ |
159 | #define CROR_151515 0x4def7b82 | |
160 | #define CROR_313131 0x4ffffb82 | |
161 | ||
cedb70c5 | 162 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
163 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
164 | #define B_DOT 0x48000000 /* b . */ | |
165 | ||
166 | /* After that, we need two instructions to load the index, followed by | |
167 | a branch. */ | |
168 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 169 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 170 | |
82bd7b59 AM |
171 | /* Instructions to save and restore floating point regs. */ |
172 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ | |
173 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
174 | #define BLR 0x4e800020 /* blr */ | |
175 | ||
41bd81ab AM |
176 | /* Since .opd is an array of descriptors and each entry will end up |
177 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
178 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 179 | relocate .opd without reloc entries. */ |
41bd81ab AM |
180 | #ifndef NO_OPD_RELOCS |
181 | #define NO_OPD_RELOCS 0 | |
182 | #endif | |
5bd4f169 | 183 | \f |
f5e87a1d | 184 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 185 | |
5bd4f169 | 186 | /* Relocation HOWTO's. */ |
04c9666a | 187 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
5bd4f169 AM |
188 | |
189 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
190 | /* This reloc does nothing. */ | |
191 | HOWTO (R_PPC64_NONE, /* type */ | |
192 | 0, /* rightshift */ | |
411e1bfb AM |
193 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
194 | 32, /* bitsize */ | |
b34976b6 | 195 | FALSE, /* pc_relative */ |
5bd4f169 | 196 | 0, /* bitpos */ |
f5e87a1d | 197 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
198 | bfd_elf_generic_reloc, /* special_function */ |
199 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 200 | FALSE, /* partial_inplace */ |
d006db6c | 201 | 0, /* src_mask */ |
5bd4f169 | 202 | 0, /* dst_mask */ |
b34976b6 | 203 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
204 | |
205 | /* A standard 32 bit relocation. */ | |
206 | HOWTO (R_PPC64_ADDR32, /* type */ | |
207 | 0, /* rightshift */ | |
208 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
209 | 32, /* bitsize */ | |
b34976b6 | 210 | FALSE, /* pc_relative */ |
5bd4f169 AM |
211 | 0, /* bitpos */ |
212 | complain_overflow_bitfield, /* complain_on_overflow */ | |
213 | bfd_elf_generic_reloc, /* special_function */ | |
214 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 215 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
216 | 0, /* src_mask */ |
217 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 218 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
219 | |
220 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
221 | FIXME: we don't check that, we just clear them. */ | |
222 | HOWTO (R_PPC64_ADDR24, /* type */ | |
223 | 0, /* rightshift */ | |
224 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
225 | 26, /* bitsize */ | |
b34976b6 | 226 | FALSE, /* pc_relative */ |
5bd4f169 AM |
227 | 0, /* bitpos */ |
228 | complain_overflow_bitfield, /* complain_on_overflow */ | |
229 | bfd_elf_generic_reloc, /* special_function */ | |
230 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 231 | FALSE, /* partial_inplace */ |
d006db6c | 232 | 0, /* src_mask */ |
f5e87a1d | 233 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 234 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
235 | |
236 | /* A standard 16 bit relocation. */ | |
237 | HOWTO (R_PPC64_ADDR16, /* type */ | |
238 | 0, /* rightshift */ | |
239 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
240 | 16, /* 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_ADDR16", /* name */ | |
b34976b6 | 246 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
247 | 0, /* src_mask */ |
248 | 0xffff, /* dst_mask */ | |
b34976b6 | 249 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
250 | |
251 | /* A 16 bit relocation without overflow. */ | |
252 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
253 | 0, /* rightshift */ | |
254 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
255 | 16, /* bitsize */ | |
b34976b6 | 256 | FALSE, /* pc_relative */ |
5bd4f169 AM |
257 | 0, /* bitpos */ |
258 | complain_overflow_dont,/* complain_on_overflow */ | |
259 | bfd_elf_generic_reloc, /* special_function */ | |
260 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 261 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
262 | 0, /* src_mask */ |
263 | 0xffff, /* dst_mask */ | |
b34976b6 | 264 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
265 | |
266 | /* Bits 16-31 of an address. */ | |
267 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
268 | 16, /* rightshift */ | |
269 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
270 | 16, /* bitsize */ | |
b34976b6 | 271 | FALSE, /* pc_relative */ |
5bd4f169 AM |
272 | 0, /* bitpos */ |
273 | complain_overflow_dont, /* complain_on_overflow */ | |
274 | bfd_elf_generic_reloc, /* special_function */ | |
275 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 276 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
277 | 0, /* src_mask */ |
278 | 0xffff, /* dst_mask */ | |
b34976b6 | 279 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
280 | |
281 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
282 | bits, treated as a signed number, is negative. */ | |
283 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
284 | 16, /* 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 */ | |
805fc799 | 290 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 291 | "R_PPC64_ADDR16_HA", /* 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 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
298 | FIXME: we don't check that, we just clear them. */ | |
299 | HOWTO (R_PPC64_ADDR14, /* type */ | |
300 | 0, /* rightshift */ | |
301 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
302 | 16, /* bitsize */ | |
b34976b6 | 303 | FALSE, /* pc_relative */ |
5bd4f169 AM |
304 | 0, /* bitpos */ |
305 | complain_overflow_bitfield, /* complain_on_overflow */ | |
306 | bfd_elf_generic_reloc, /* special_function */ | |
307 | "R_PPC64_ADDR14", /* name */ | |
b34976b6 | 308 | FALSE, /* partial_inplace */ |
d006db6c | 309 | 0, /* src_mask */ |
f5e87a1d | 310 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 311 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
312 | |
313 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
314 | indicate that the branch is expected to be taken. The lower two | |
315 | bits must be zero. */ | |
316 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
317 | 0, /* rightshift */ | |
318 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
319 | 16, /* bitsize */ | |
b34976b6 | 320 | FALSE, /* pc_relative */ |
5bd4f169 AM |
321 | 0, /* bitpos */ |
322 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 323 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 324 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 325 | FALSE, /* partial_inplace */ |
d006db6c | 326 | 0, /* src_mask */ |
f5e87a1d | 327 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 328 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
329 | |
330 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
331 | indicate that the branch is not expected to be taken. The lower | |
332 | two bits must be zero. */ | |
333 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
334 | 0, /* rightshift */ | |
335 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
336 | 16, /* bitsize */ | |
b34976b6 | 337 | FALSE, /* pc_relative */ |
5bd4f169 AM |
338 | 0, /* bitpos */ |
339 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 340 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 341 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 342 | FALSE, /* partial_inplace */ |
d006db6c | 343 | 0, /* src_mask */ |
f5e87a1d | 344 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 345 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
346 | |
347 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
348 | HOWTO (R_PPC64_REL24, /* type */ | |
349 | 0, /* rightshift */ | |
350 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
351 | 26, /* bitsize */ | |
b34976b6 | 352 | TRUE, /* pc_relative */ |
5bd4f169 AM |
353 | 0, /* bitpos */ |
354 | complain_overflow_signed, /* complain_on_overflow */ | |
355 | bfd_elf_generic_reloc, /* special_function */ | |
356 | "R_PPC64_REL24", /* name */ | |
b34976b6 | 357 | FALSE, /* partial_inplace */ |
d006db6c | 358 | 0, /* src_mask */ |
f5e87a1d | 359 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 360 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
361 | |
362 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
363 | HOWTO (R_PPC64_REL14, /* type */ | |
364 | 0, /* rightshift */ | |
365 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
366 | 16, /* bitsize */ | |
b34976b6 | 367 | TRUE, /* pc_relative */ |
5bd4f169 AM |
368 | 0, /* bitpos */ |
369 | complain_overflow_signed, /* complain_on_overflow */ | |
370 | bfd_elf_generic_reloc, /* special_function */ | |
371 | "R_PPC64_REL14", /* name */ | |
b34976b6 | 372 | FALSE, /* partial_inplace */ |
d006db6c | 373 | 0, /* src_mask */ |
f5e87a1d | 374 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 375 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
376 | |
377 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
378 | the branch is expected to be taken. The lower two bits must be | |
379 | zero. */ | |
380 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
381 | 0, /* rightshift */ | |
382 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
383 | 16, /* bitsize */ | |
b34976b6 | 384 | TRUE, /* pc_relative */ |
5bd4f169 AM |
385 | 0, /* bitpos */ |
386 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 387 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 388 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 389 | FALSE, /* partial_inplace */ |
d006db6c | 390 | 0, /* src_mask */ |
f5e87a1d | 391 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 392 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
393 | |
394 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
395 | the branch is not expected to be taken. The lower two bits must | |
396 | be zero. */ | |
397 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
398 | 0, /* rightshift */ | |
399 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
400 | 16, /* bitsize */ | |
b34976b6 | 401 | TRUE, /* pc_relative */ |
5bd4f169 AM |
402 | 0, /* bitpos */ |
403 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 404 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 405 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 406 | FALSE, /* partial_inplace */ |
d006db6c | 407 | 0, /* src_mask */ |
f5e87a1d | 408 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 409 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
410 | |
411 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
412 | symbol. */ | |
413 | HOWTO (R_PPC64_GOT16, /* type */ | |
414 | 0, /* rightshift */ | |
415 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
416 | 16, /* bitsize */ | |
b34976b6 | 417 | FALSE, /* pc_relative */ |
5bd4f169 AM |
418 | 0, /* bitpos */ |
419 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 420 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 421 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 422 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
423 | 0, /* src_mask */ |
424 | 0xffff, /* dst_mask */ | |
b34976b6 | 425 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
426 | |
427 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
428 | the symbol. */ | |
429 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
430 | 0, /* rightshift */ | |
431 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
432 | 16, /* bitsize */ | |
b34976b6 | 433 | FALSE, /* pc_relative */ |
5bd4f169 AM |
434 | 0, /* bitpos */ |
435 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 436 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 437 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 438 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
439 | 0, /* src_mask */ |
440 | 0xffff, /* dst_mask */ | |
b34976b6 | 441 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
442 | |
443 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
444 | the symbol. */ | |
445 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
446 | 16, /* rightshift */ | |
447 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
448 | 16, /* bitsize */ | |
b34976b6 | 449 | FALSE, /* pc_relative */ |
5bd4f169 AM |
450 | 0, /* bitpos */ |
451 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 452 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 453 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 454 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
455 | 0, /* src_mask */ |
456 | 0xffff, /* dst_mask */ | |
b34976b6 | 457 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
458 | |
459 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
460 | the symbol. */ | |
461 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
462 | 16, /* rightshift */ | |
463 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
464 | 16, /* bitsize */ | |
b34976b6 | 465 | FALSE, /* pc_relative */ |
5bd4f169 AM |
466 | 0, /* bitpos */ |
467 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 468 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 469 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 470 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
471 | 0, /* src_mask */ |
472 | 0xffff, /* dst_mask */ | |
b34976b6 | 473 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
474 | |
475 | /* This is used only by the dynamic linker. The symbol should exist | |
476 | both in the object being run and in some shared library. The | |
477 | dynamic linker copies the data addressed by the symbol from the | |
478 | shared library into the object, because the object being | |
479 | run has to have the data at some particular address. */ | |
480 | HOWTO (R_PPC64_COPY, /* type */ | |
481 | 0, /* rightshift */ | |
f5e87a1d AM |
482 | 0, /* this one is variable size */ |
483 | 0, /* bitsize */ | |
b34976b6 | 484 | FALSE, /* pc_relative */ |
5bd4f169 | 485 | 0, /* bitpos */ |
f5e87a1d AM |
486 | complain_overflow_dont, /* complain_on_overflow */ |
487 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 488 | "R_PPC64_COPY", /* name */ |
b34976b6 | 489 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
490 | 0, /* src_mask */ |
491 | 0, /* dst_mask */ | |
b34976b6 | 492 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
493 | |
494 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
495 | entries. */ | |
496 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
497 | 0, /* rightshift */ | |
498 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
499 | 64, /* bitsize */ | |
b34976b6 | 500 | FALSE, /* pc_relative */ |
5bd4f169 AM |
501 | 0, /* bitpos */ |
502 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 503 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 504 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 505 | FALSE, /* partial_inplace */ |
5bd4f169 | 506 | 0, /* src_mask */ |
f5e87a1d | 507 | ONES (64), /* dst_mask */ |
b34976b6 | 508 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
509 | |
510 | /* Created by the link editor. Marks a procedure linkage table | |
511 | entry for a symbol. */ | |
512 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
513 | 0, /* rightshift */ | |
514 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
515 | 0, /* bitsize */ | |
b34976b6 | 516 | FALSE, /* pc_relative */ |
5bd4f169 AM |
517 | 0, /* bitpos */ |
518 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 519 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 520 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 521 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
522 | 0, /* src_mask */ |
523 | 0, /* dst_mask */ | |
b34976b6 | 524 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
525 | |
526 | /* Used only by the dynamic linker. When the object is run, this | |
527 | doubleword64 is set to the load address of the object, plus the | |
528 | addend. */ | |
529 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
530 | 0, /* rightshift */ | |
531 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
532 | 64, /* bitsize */ | |
b34976b6 | 533 | FALSE, /* pc_relative */ |
5bd4f169 AM |
534 | 0, /* bitpos */ |
535 | complain_overflow_dont, /* complain_on_overflow */ | |
536 | bfd_elf_generic_reloc, /* special_function */ | |
537 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 538 | FALSE, /* partial_inplace */ |
5bd4f169 | 539 | 0, /* src_mask */ |
f5e87a1d | 540 | ONES (64), /* dst_mask */ |
b34976b6 | 541 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
542 | |
543 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
544 | HOWTO (R_PPC64_UADDR32, /* type */ | |
545 | 0, /* rightshift */ | |
546 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
547 | 32, /* bitsize */ | |
b34976b6 | 548 | FALSE, /* pc_relative */ |
5bd4f169 AM |
549 | 0, /* bitpos */ |
550 | complain_overflow_bitfield, /* complain_on_overflow */ | |
551 | bfd_elf_generic_reloc, /* special_function */ | |
552 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 553 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
554 | 0, /* src_mask */ |
555 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 556 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
557 | |
558 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
559 | HOWTO (R_PPC64_UADDR16, /* type */ | |
560 | 0, /* rightshift */ | |
561 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
562 | 16, /* bitsize */ | |
b34976b6 | 563 | FALSE, /* pc_relative */ |
5bd4f169 AM |
564 | 0, /* bitpos */ |
565 | complain_overflow_bitfield, /* complain_on_overflow */ | |
566 | bfd_elf_generic_reloc, /* special_function */ | |
567 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 568 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
569 | 0, /* src_mask */ |
570 | 0xffff, /* dst_mask */ | |
b34976b6 | 571 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
572 | |
573 | /* 32-bit PC relative. */ | |
574 | HOWTO (R_PPC64_REL32, /* type */ | |
575 | 0, /* rightshift */ | |
576 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
577 | 32, /* bitsize */ | |
b34976b6 | 578 | TRUE, /* pc_relative */ |
5bd4f169 | 579 | 0, /* bitpos */ |
cedb70c5 | 580 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
581 | complain_overflow_signed, /* complain_on_overflow */ |
582 | bfd_elf_generic_reloc, /* special_function */ | |
583 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 584 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
585 | 0, /* src_mask */ |
586 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 587 | TRUE), /* pcrel_offset */ |
5bd4f169 | 588 | |
10ed1bba | 589 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
590 | HOWTO (R_PPC64_PLT32, /* type */ |
591 | 0, /* rightshift */ | |
592 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
593 | 32, /* bitsize */ | |
b34976b6 | 594 | FALSE, /* pc_relative */ |
5bd4f169 AM |
595 | 0, /* bitpos */ |
596 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 597 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 598 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 599 | FALSE, /* partial_inplace */ |
5bd4f169 | 600 | 0, /* src_mask */ |
f5e87a1d | 601 | 0xffffffff, /* dst_mask */ |
b34976b6 | 602 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
603 | |
604 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
605 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
606 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
607 | 0, /* rightshift */ | |
608 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
609 | 32, /* bitsize */ | |
b34976b6 | 610 | TRUE, /* pc_relative */ |
5bd4f169 AM |
611 | 0, /* bitpos */ |
612 | complain_overflow_signed, /* complain_on_overflow */ | |
613 | bfd_elf_generic_reloc, /* special_function */ | |
614 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 615 | FALSE, /* partial_inplace */ |
5bd4f169 | 616 | 0, /* src_mask */ |
f5e87a1d | 617 | 0xffffffff, /* dst_mask */ |
b34976b6 | 618 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
619 | |
620 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
621 | the symbol. */ | |
622 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
623 | 0, /* rightshift */ | |
624 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
625 | 16, /* bitsize */ | |
b34976b6 | 626 | FALSE, /* pc_relative */ |
5bd4f169 AM |
627 | 0, /* bitpos */ |
628 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 629 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 630 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 631 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
632 | 0, /* src_mask */ |
633 | 0xffff, /* dst_mask */ | |
b34976b6 | 634 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
635 | |
636 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
637 | the symbol. */ | |
638 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
639 | 16, /* rightshift */ | |
640 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
641 | 16, /* bitsize */ | |
b34976b6 | 642 | FALSE, /* pc_relative */ |
5bd4f169 AM |
643 | 0, /* bitpos */ |
644 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 645 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 646 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 647 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
648 | 0, /* src_mask */ |
649 | 0xffff, /* dst_mask */ | |
b34976b6 | 650 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
651 | |
652 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
653 | the symbol. */ | |
654 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
655 | 16, /* rightshift */ | |
656 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
657 | 16, /* bitsize */ | |
b34976b6 | 658 | FALSE, /* pc_relative */ |
5bd4f169 AM |
659 | 0, /* bitpos */ |
660 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 661 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 662 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 663 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
664 | 0, /* src_mask */ |
665 | 0xffff, /* dst_mask */ | |
b34976b6 | 666 | FALSE), /* pcrel_offset */ |
5bd4f169 | 667 | |
c061c2d8 | 668 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
669 | HOWTO (R_PPC64_SECTOFF, /* type */ |
670 | 0, /* rightshift */ | |
c061c2d8 AM |
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_bitfield, /* complain_on_overflow */ | |
805fc799 | 676 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 677 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 678 | FALSE, /* partial_inplace */ |
5bd4f169 | 679 | 0, /* src_mask */ |
c061c2d8 | 680 | 0xffff, /* dst_mask */ |
b34976b6 | 681 | FALSE), /* pcrel_offset */ |
5bd4f169 | 682 | |
c061c2d8 | 683 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
684 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
685 | 0, /* rightshift */ | |
686 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
687 | 16, /* bitsize */ | |
b34976b6 | 688 | FALSE, /* pc_relative */ |
5bd4f169 AM |
689 | 0, /* bitpos */ |
690 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 691 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 692 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 693 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
694 | 0, /* src_mask */ |
695 | 0xffff, /* dst_mask */ | |
b34976b6 | 696 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
697 | |
698 | /* 16-bit upper half section relative relocation. */ | |
699 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
700 | 16, /* rightshift */ | |
701 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
702 | 16, /* bitsize */ | |
b34976b6 | 703 | FALSE, /* pc_relative */ |
5bd4f169 AM |
704 | 0, /* bitpos */ |
705 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 706 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 707 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 708 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
709 | 0, /* src_mask */ |
710 | 0xffff, /* dst_mask */ | |
b34976b6 | 711 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
712 | |
713 | /* 16-bit upper half adjusted section relative relocation. */ | |
714 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
715 | 16, /* rightshift */ | |
716 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
717 | 16, /* bitsize */ | |
b34976b6 | 718 | FALSE, /* pc_relative */ |
5bd4f169 AM |
719 | 0, /* bitpos */ |
720 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 721 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 722 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 723 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
724 | 0, /* src_mask */ |
725 | 0xffff, /* dst_mask */ | |
b34976b6 | 726 | FALSE), /* pcrel_offset */ |
5bd4f169 | 727 | |
04c9666a AM |
728 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
729 | HOWTO (R_PPC64_REL30, /* type */ | |
5bd4f169 AM |
730 | 2, /* rightshift */ |
731 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
732 | 30, /* bitsize */ | |
b34976b6 | 733 | TRUE, /* pc_relative */ |
5bd4f169 AM |
734 | 0, /* bitpos */ |
735 | complain_overflow_dont, /* complain_on_overflow */ | |
736 | bfd_elf_generic_reloc, /* special_function */ | |
04c9666a | 737 | "R_PPC64_REL30", /* name */ |
b34976b6 | 738 | FALSE, /* partial_inplace */ |
d006db6c | 739 | 0, /* src_mask */ |
5bd4f169 | 740 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 741 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
742 | |
743 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
744 | ||
745 | /* A standard 64-bit relocation. */ | |
746 | HOWTO (R_PPC64_ADDR64, /* type */ | |
747 | 0, /* rightshift */ | |
748 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
749 | 64, /* bitsize */ | |
b34976b6 | 750 | FALSE, /* pc_relative */ |
5bd4f169 AM |
751 | 0, /* bitpos */ |
752 | complain_overflow_dont, /* complain_on_overflow */ | |
753 | bfd_elf_generic_reloc, /* special_function */ | |
754 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 755 | FALSE, /* partial_inplace */ |
5bd4f169 | 756 | 0, /* src_mask */ |
f5e87a1d | 757 | ONES (64), /* dst_mask */ |
b34976b6 | 758 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
759 | |
760 | /* The bits 32-47 of an address. */ | |
761 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
762 | 32, /* rightshift */ | |
763 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
764 | 16, /* bitsize */ | |
b34976b6 | 765 | FALSE, /* pc_relative */ |
5bd4f169 AM |
766 | 0, /* bitpos */ |
767 | complain_overflow_dont, /* complain_on_overflow */ | |
768 | bfd_elf_generic_reloc, /* special_function */ | |
769 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 770 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
771 | 0, /* src_mask */ |
772 | 0xffff, /* dst_mask */ | |
b34976b6 | 773 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
774 | |
775 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
776 | 16 bits, treated as a signed number, is negative. */ | |
777 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
778 | 32, /* rightshift */ | |
779 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
780 | 16, /* bitsize */ | |
b34976b6 | 781 | FALSE, /* pc_relative */ |
5bd4f169 AM |
782 | 0, /* bitpos */ |
783 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 784 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 785 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 786 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
787 | 0, /* src_mask */ |
788 | 0xffff, /* dst_mask */ | |
b34976b6 | 789 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
790 | |
791 | /* The bits 48-63 of an address. */ | |
792 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
793 | 48, /* 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_HIGHEST", /* 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 48-63 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_HIGHESTA,/* type */ | |
809 | 48, /* 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_HIGHESTA", /* 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 | /* Like ADDR64, but may be unaligned. */ | |
823 | HOWTO (R_PPC64_UADDR64, /* type */ | |
824 | 0, /* rightshift */ | |
825 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
826 | 64, /* 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_UADDR64", /* name */ | |
b34976b6 | 832 | FALSE, /* partial_inplace */ |
5bd4f169 | 833 | 0, /* src_mask */ |
f5e87a1d | 834 | ONES (64), /* dst_mask */ |
b34976b6 | 835 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
836 | |
837 | /* 64-bit relative relocation. */ | |
838 | HOWTO (R_PPC64_REL64, /* type */ | |
839 | 0, /* rightshift */ | |
840 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
841 | 64, /* bitsize */ | |
b34976b6 | 842 | TRUE, /* pc_relative */ |
5bd4f169 AM |
843 | 0, /* bitpos */ |
844 | complain_overflow_dont, /* complain_on_overflow */ | |
845 | bfd_elf_generic_reloc, /* special_function */ | |
846 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 847 | FALSE, /* partial_inplace */ |
5bd4f169 | 848 | 0, /* src_mask */ |
f5e87a1d | 849 | ONES (64), /* dst_mask */ |
b34976b6 | 850 | TRUE), /* pcrel_offset */ |
5bd4f169 | 851 | |
cedb70c5 | 852 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
853 | HOWTO (R_PPC64_PLT64, /* type */ |
854 | 0, /* rightshift */ | |
855 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
856 | 64, /* bitsize */ | |
b34976b6 | 857 | FALSE, /* pc_relative */ |
5bd4f169 AM |
858 | 0, /* bitpos */ |
859 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 860 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 861 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 862 | FALSE, /* partial_inplace */ |
5bd4f169 | 863 | 0, /* src_mask */ |
f5e87a1d | 864 | ONES (64), /* dst_mask */ |
b34976b6 | 865 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
866 | |
867 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
868 | table. */ | |
869 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
870 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
871 | 0, /* rightshift */ | |
872 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
873 | 64, /* bitsize */ | |
b34976b6 | 874 | TRUE, /* pc_relative */ |
5bd4f169 AM |
875 | 0, /* bitpos */ |
876 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 877 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 878 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 879 | FALSE, /* partial_inplace */ |
5bd4f169 | 880 | 0, /* src_mask */ |
f5e87a1d | 881 | ONES (64), /* dst_mask */ |
b34976b6 | 882 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
883 | |
884 | /* 16 bit TOC-relative relocation. */ | |
885 | ||
886 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
887 | HOWTO (R_PPC64_TOC16, /* type */ | |
888 | 0, /* rightshift */ | |
889 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
890 | 16, /* bitsize */ | |
b34976b6 | 891 | FALSE, /* pc_relative */ |
5bd4f169 AM |
892 | 0, /* bitpos */ |
893 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 894 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 895 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 896 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
897 | 0, /* src_mask */ |
898 | 0xffff, /* dst_mask */ | |
b34976b6 | 899 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
900 | |
901 | /* 16 bit TOC-relative relocation without overflow. */ | |
902 | ||
903 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
904 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
905 | 0, /* rightshift */ | |
906 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
907 | 16, /* bitsize */ | |
b34976b6 | 908 | FALSE, /* pc_relative */ |
5bd4f169 AM |
909 | 0, /* bitpos */ |
910 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 911 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 912 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 913 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
914 | 0, /* src_mask */ |
915 | 0xffff, /* dst_mask */ | |
b34976b6 | 916 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
917 | |
918 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
919 | ||
920 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
921 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
922 | 16, /* rightshift */ | |
923 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
924 | 16, /* bitsize */ | |
b34976b6 | 925 | FALSE, /* pc_relative */ |
5bd4f169 AM |
926 | 0, /* bitpos */ |
927 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 928 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 929 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 930 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
931 | 0, /* src_mask */ |
932 | 0xffff, /* dst_mask */ | |
b34976b6 | 933 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
934 | |
935 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
936 | contents of the low 16 bits, treated as a signed number, is | |
937 | negative. */ | |
938 | ||
939 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
940 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
941 | 16, /* rightshift */ | |
942 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
943 | 16, /* bitsize */ | |
b34976b6 | 944 | FALSE, /* pc_relative */ |
5bd4f169 AM |
945 | 0, /* bitpos */ |
946 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 947 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 948 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 949 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
950 | 0, /* src_mask */ |
951 | 0xffff, /* dst_mask */ | |
b34976b6 | 952 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
953 | |
954 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
955 | ||
956 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
957 | HOWTO (R_PPC64_TOC, /* type */ | |
958 | 0, /* rightshift */ | |
959 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
960 | 64, /* bitsize */ | |
b34976b6 | 961 | FALSE, /* pc_relative */ |
5bd4f169 AM |
962 | 0, /* bitpos */ |
963 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 964 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 965 | "R_PPC64_TOC", /* name */ |
b34976b6 | 966 | FALSE, /* partial_inplace */ |
5bd4f169 | 967 | 0, /* src_mask */ |
f5e87a1d | 968 | ONES (64), /* dst_mask */ |
b34976b6 | 969 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
970 | |
971 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
972 | value to relocate may (!) refer to a PLT entry which the link | |
973 | editor (a) may replace with the symbol value. If the link editor | |
974 | is unable to fully resolve the symbol, it may (b) create a PLT | |
975 | entry and store the address to the new PLT entry in the GOT. | |
976 | This permits lazy resolution of function symbols at run time. | |
977 | The link editor may also skip all of this and just (c) emit a | |
978 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
979 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
980 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
981 | 0, /* rightshift */ | |
982 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
983 | 16, /* bitsize */ | |
b34976b6 | 984 | FALSE, /* pc_relative */ |
5bd4f169 AM |
985 | 0, /* bitpos */ |
986 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 987 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb AM |
988 | "R_PPC64_PLTGOT16", /* name */ |
989 | FALSE, /* partial_inplace */ | |
990 | 0, /* src_mask */ | |
991 | 0xffff, /* dst_mask */ | |
992 | FALSE), /* pcrel_offset */ | |
993 | ||
994 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
995 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
996 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
997 | 0, /* rightshift */ | |
998 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
999 | 16, /* bitsize */ | |
1000 | FALSE, /* pc_relative */ | |
1001 | 0, /* bitpos */ | |
1002 | complain_overflow_dont, /* complain_on_overflow */ | |
1003 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1004 | "R_PPC64_PLTGOT16_LO", /* name */ | |
1005 | FALSE, /* partial_inplace */ | |
1006 | 0, /* src_mask */ | |
1007 | 0xffff, /* dst_mask */ | |
1008 | FALSE), /* pcrel_offset */ | |
1009 | ||
1010 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
1011 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
1012 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
1013 | 16, /* rightshift */ | |
1014 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1015 | 16, /* bitsize */ | |
1016 | FALSE, /* pc_relative */ | |
1017 | 0, /* bitpos */ | |
1018 | complain_overflow_dont, /* complain_on_overflow */ | |
1019 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1020 | "R_PPC64_PLTGOT16_HI", /* name */ | |
1021 | FALSE, /* partial_inplace */ | |
1022 | 0, /* src_mask */ | |
1023 | 0xffff, /* dst_mask */ | |
1024 | FALSE), /* pcrel_offset */ | |
1025 | ||
1026 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
1027 | 1 if the contents of the low 16 bits, treated as a signed number, | |
1028 | is negative. */ | |
1029 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
1030 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
1031 | 16, /* rightshift */ | |
1032 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1033 | 16, /* bitsize */ | |
1034 | FALSE, /* pc_relative */ | |
1035 | 0, /* bitpos */ | |
1036 | complain_overflow_dont,/* complain_on_overflow */ | |
1037 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1038 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1039 | FALSE, /* partial_inplace */ | |
1040 | 0, /* src_mask */ | |
1041 | 0xffff, /* dst_mask */ | |
1042 | FALSE), /* pcrel_offset */ | |
1043 | ||
1044 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1045 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1046 | 0, /* rightshift */ | |
1047 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1048 | 16, /* bitsize */ | |
1049 | FALSE, /* pc_relative */ | |
1050 | 0, /* bitpos */ | |
1051 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1052 | bfd_elf_generic_reloc, /* special_function */ | |
1053 | "R_PPC64_ADDR16_DS", /* name */ | |
1054 | FALSE, /* partial_inplace */ | |
1055 | 0, /* src_mask */ | |
1056 | 0xfffc, /* dst_mask */ | |
1057 | FALSE), /* pcrel_offset */ | |
1058 | ||
1059 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1060 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1061 | 0, /* rightshift */ | |
1062 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1063 | 16, /* bitsize */ | |
1064 | FALSE, /* pc_relative */ | |
1065 | 0, /* bitpos */ | |
1066 | complain_overflow_dont,/* complain_on_overflow */ | |
1067 | bfd_elf_generic_reloc, /* special_function */ | |
1068 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1069 | FALSE, /* partial_inplace */ | |
1070 | 0, /* src_mask */ | |
1071 | 0xfffc, /* dst_mask */ | |
1072 | FALSE), /* pcrel_offset */ | |
1073 | ||
1074 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1075 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1076 | 0, /* rightshift */ | |
1077 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1078 | 16, /* bitsize */ | |
1079 | FALSE, /* pc_relative */ | |
1080 | 0, /* bitpos */ | |
1081 | complain_overflow_signed, /* complain_on_overflow */ | |
1082 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1083 | "R_PPC64_GOT16_DS", /* name */ | |
1084 | FALSE, /* partial_inplace */ | |
1085 | 0, /* src_mask */ | |
1086 | 0xfffc, /* dst_mask */ | |
1087 | FALSE), /* pcrel_offset */ | |
1088 | ||
1089 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1090 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1091 | 0, /* rightshift */ | |
1092 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1093 | 16, /* bitsize */ | |
1094 | FALSE, /* pc_relative */ | |
1095 | 0, /* bitpos */ | |
1096 | complain_overflow_dont, /* complain_on_overflow */ | |
1097 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1098 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1099 | FALSE, /* partial_inplace */ | |
1100 | 0, /* src_mask */ | |
1101 | 0xfffc, /* dst_mask */ | |
1102 | FALSE), /* pcrel_offset */ | |
1103 | ||
1104 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1105 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1106 | 0, /* rightshift */ | |
1107 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1108 | 16, /* bitsize */ | |
1109 | FALSE, /* pc_relative */ | |
1110 | 0, /* bitpos */ | |
1111 | complain_overflow_dont, /* complain_on_overflow */ | |
1112 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1113 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1114 | FALSE, /* partial_inplace */ | |
1115 | 0, /* src_mask */ | |
1116 | 0xfffc, /* dst_mask */ | |
1117 | FALSE), /* pcrel_offset */ | |
1118 | ||
1119 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1120 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1121 | 0, /* rightshift */ | |
1122 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1123 | 16, /* bitsize */ | |
1124 | FALSE, /* pc_relative */ | |
1125 | 0, /* bitpos */ | |
1126 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1127 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1128 | "R_PPC64_SECTOFF_DS", /* name */ | |
1129 | FALSE, /* partial_inplace */ | |
1130 | 0, /* src_mask */ | |
1131 | 0xfffc, /* dst_mask */ | |
1132 | FALSE), /* pcrel_offset */ | |
1133 | ||
1134 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1135 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1136 | 0, /* rightshift */ | |
1137 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1138 | 16, /* bitsize */ | |
1139 | FALSE, /* pc_relative */ | |
1140 | 0, /* bitpos */ | |
1141 | complain_overflow_dont, /* complain_on_overflow */ | |
1142 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1143 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1144 | FALSE, /* partial_inplace */ | |
1145 | 0, /* src_mask */ | |
1146 | 0xfffc, /* dst_mask */ | |
1147 | FALSE), /* pcrel_offset */ | |
1148 | ||
1149 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1150 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1151 | 0, /* rightshift */ | |
1152 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1153 | 16, /* bitsize */ | |
1154 | FALSE, /* pc_relative */ | |
1155 | 0, /* bitpos */ | |
1156 | complain_overflow_signed, /* complain_on_overflow */ | |
1157 | ppc64_elf_toc_reloc, /* special_function */ | |
1158 | "R_PPC64_TOC16_DS", /* name */ | |
1159 | FALSE, /* partial_inplace */ | |
1160 | 0, /* src_mask */ | |
1161 | 0xfffc, /* dst_mask */ | |
1162 | FALSE), /* pcrel_offset */ | |
1163 | ||
1164 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1165 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1166 | 0, /* rightshift */ | |
1167 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1168 | 16, /* bitsize */ | |
1169 | FALSE, /* pc_relative */ | |
1170 | 0, /* bitpos */ | |
1171 | complain_overflow_dont, /* complain_on_overflow */ | |
1172 | ppc64_elf_toc_reloc, /* special_function */ | |
1173 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1174 | FALSE, /* partial_inplace */ | |
1175 | 0, /* src_mask */ | |
1176 | 0xfffc, /* dst_mask */ | |
1177 | FALSE), /* pcrel_offset */ | |
1178 | ||
1179 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1180 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1181 | HOWTO (R_PPC64_PLTGOT16_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_unhandled_reloc, /* special_function */ | |
1189 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1190 | FALSE, /* partial_inplace */ | |
1191 | 0, /* src_mask */ | |
1192 | 0xfffc, /* dst_mask */ | |
1193 | FALSE), /* pcrel_offset */ | |
1194 | ||
1195 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1196 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1197 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1198 | 0, /* rightshift */ | |
1199 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1200 | 16, /* bitsize */ | |
1201 | FALSE, /* pc_relative */ | |
1202 | 0, /* bitpos */ | |
1203 | complain_overflow_dont, /* complain_on_overflow */ | |
1204 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1205 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1206 | FALSE, /* partial_inplace */ | |
1207 | 0, /* src_mask */ | |
1208 | 0xfffc, /* dst_mask */ | |
1209 | FALSE), /* pcrel_offset */ | |
1210 | ||
1211 | /* Marker reloc for TLS. */ | |
1212 | HOWTO (R_PPC64_TLS, | |
1213 | 0, /* rightshift */ | |
1214 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1215 | 32, /* bitsize */ | |
1216 | FALSE, /* pc_relative */ | |
1217 | 0, /* bitpos */ | |
1218 | complain_overflow_dont, /* complain_on_overflow */ | |
1219 | bfd_elf_generic_reloc, /* special_function */ | |
1220 | "R_PPC64_TLS", /* name */ | |
1221 | FALSE, /* partial_inplace */ | |
1222 | 0, /* src_mask */ | |
1223 | 0, /* dst_mask */ | |
1224 | FALSE), /* pcrel_offset */ | |
1225 | ||
1226 | /* Computes the load module index of the load module that contains the | |
1227 | definition of its TLS sym. */ | |
1228 | HOWTO (R_PPC64_DTPMOD64, | |
1229 | 0, /* rightshift */ | |
1230 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1231 | 64, /* 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_DTPMOD64", /* name */ | |
1237 | FALSE, /* partial_inplace */ | |
1238 | 0, /* src_mask */ | |
1239 | ONES (64), /* dst_mask */ | |
1240 | FALSE), /* pcrel_offset */ | |
1241 | ||
1242 | /* Computes a dtv-relative displacement, the difference between the value | |
1243 | of sym+add and the base address of the thread-local storage block that | |
1244 | contains the definition of sym, minus 0x8000. */ | |
1245 | HOWTO (R_PPC64_DTPREL64, | |
1246 | 0, /* rightshift */ | |
1247 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1248 | 64, /* bitsize */ | |
1249 | FALSE, /* pc_relative */ | |
1250 | 0, /* bitpos */ | |
1251 | complain_overflow_dont, /* complain_on_overflow */ | |
1252 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1253 | "R_PPC64_DTPREL64", /* name */ | |
1254 | FALSE, /* partial_inplace */ | |
1255 | 0, /* src_mask */ | |
1256 | ONES (64), /* dst_mask */ | |
1257 | FALSE), /* pcrel_offset */ | |
1258 | ||
1259 | /* A 16 bit dtprel reloc. */ | |
1260 | HOWTO (R_PPC64_DTPREL16, | |
1261 | 0, /* rightshift */ | |
1262 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1263 | 16, /* bitsize */ | |
1264 | FALSE, /* pc_relative */ | |
1265 | 0, /* bitpos */ | |
1266 | complain_overflow_signed, /* complain_on_overflow */ | |
1267 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1268 | "R_PPC64_DTPREL16", /* name */ | |
1269 | FALSE, /* partial_inplace */ | |
1270 | 0, /* src_mask */ | |
1271 | 0xffff, /* dst_mask */ | |
1272 | FALSE), /* pcrel_offset */ | |
1273 | ||
1274 | /* Like DTPREL16, but no overflow. */ | |
1275 | HOWTO (R_PPC64_DTPREL16_LO, | |
1276 | 0, /* rightshift */ | |
1277 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1278 | 16, /* bitsize */ | |
1279 | FALSE, /* pc_relative */ | |
1280 | 0, /* bitpos */ | |
1281 | complain_overflow_dont, /* complain_on_overflow */ | |
1282 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1283 | "R_PPC64_DTPREL16_LO", /* name */ | |
1284 | FALSE, /* partial_inplace */ | |
1285 | 0, /* src_mask */ | |
1286 | 0xffff, /* dst_mask */ | |
1287 | FALSE), /* pcrel_offset */ | |
1288 | ||
1289 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ | |
1290 | HOWTO (R_PPC64_DTPREL16_HI, | |
1291 | 16, /* rightshift */ | |
1292 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1293 | 16, /* bitsize */ | |
1294 | FALSE, /* pc_relative */ | |
1295 | 0, /* bitpos */ | |
1296 | complain_overflow_dont, /* complain_on_overflow */ | |
1297 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1298 | "R_PPC64_DTPREL16_HI", /* name */ | |
1299 | FALSE, /* partial_inplace */ | |
1300 | 0, /* src_mask */ | |
1301 | 0xffff, /* dst_mask */ | |
1302 | FALSE), /* pcrel_offset */ | |
1303 | ||
1304 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ | |
1305 | HOWTO (R_PPC64_DTPREL16_HA, | |
1306 | 16, /* rightshift */ | |
1307 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1308 | 16, /* bitsize */ | |
1309 | FALSE, /* pc_relative */ | |
1310 | 0, /* bitpos */ | |
1311 | complain_overflow_dont, /* complain_on_overflow */ | |
1312 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1313 | "R_PPC64_DTPREL16_HA", /* name */ | |
1314 | FALSE, /* partial_inplace */ | |
1315 | 0, /* src_mask */ | |
1316 | 0xffff, /* dst_mask */ | |
1317 | FALSE), /* pcrel_offset */ | |
1318 | ||
1319 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ | |
1320 | HOWTO (R_PPC64_DTPREL16_HIGHER, | |
1321 | 32, /* rightshift */ | |
1322 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1323 | 16, /* bitsize */ | |
1324 | FALSE, /* pc_relative */ | |
1325 | 0, /* bitpos */ | |
1326 | complain_overflow_dont, /* complain_on_overflow */ | |
1327 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1328 | "R_PPC64_DTPREL16_HIGHER", /* name */ | |
1329 | FALSE, /* partial_inplace */ | |
1330 | 0, /* src_mask */ | |
1331 | 0xffff, /* dst_mask */ | |
1332 | FALSE), /* pcrel_offset */ | |
1333 | ||
1334 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ | |
1335 | HOWTO (R_PPC64_DTPREL16_HIGHERA, | |
1336 | 32, /* rightshift */ | |
1337 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1338 | 16, /* bitsize */ | |
1339 | FALSE, /* pc_relative */ | |
1340 | 0, /* bitpos */ | |
1341 | complain_overflow_dont, /* complain_on_overflow */ | |
1342 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1343 | "R_PPC64_DTPREL16_HIGHERA", /* name */ | |
1344 | FALSE, /* partial_inplace */ | |
1345 | 0, /* src_mask */ | |
1346 | 0xffff, /* dst_mask */ | |
1347 | FALSE), /* pcrel_offset */ | |
1348 | ||
1349 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ | |
1350 | HOWTO (R_PPC64_DTPREL16_HIGHEST, | |
1351 | 48, /* rightshift */ | |
1352 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1353 | 16, /* bitsize */ | |
1354 | FALSE, /* pc_relative */ | |
1355 | 0, /* bitpos */ | |
1356 | complain_overflow_dont, /* complain_on_overflow */ | |
1357 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1358 | "R_PPC64_DTPREL16_HIGHEST", /* name */ | |
1359 | FALSE, /* partial_inplace */ | |
1360 | 0, /* src_mask */ | |
1361 | 0xffff, /* dst_mask */ | |
1362 | FALSE), /* pcrel_offset */ | |
1363 | ||
1364 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1365 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, | |
1366 | 48, /* rightshift */ | |
1367 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1368 | 16, /* bitsize */ | |
1369 | FALSE, /* pc_relative */ | |
1370 | 0, /* bitpos */ | |
1371 | complain_overflow_dont, /* complain_on_overflow */ | |
1372 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1373 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ | |
1374 | FALSE, /* partial_inplace */ | |
1375 | 0, /* src_mask */ | |
1376 | 0xffff, /* dst_mask */ | |
1377 | FALSE), /* pcrel_offset */ | |
1378 | ||
1379 | /* Like DTPREL16, but for insns with a DS field. */ | |
1380 | HOWTO (R_PPC64_DTPREL16_DS, | |
1381 | 0, /* rightshift */ | |
1382 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1383 | 16, /* bitsize */ | |
1384 | FALSE, /* pc_relative */ | |
1385 | 0, /* bitpos */ | |
1386 | complain_overflow_signed, /* complain_on_overflow */ | |
1387 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1388 | "R_PPC64_DTPREL16_DS", /* name */ | |
1389 | FALSE, /* partial_inplace */ | |
1390 | 0, /* src_mask */ | |
1391 | 0xfffc, /* dst_mask */ | |
1392 | FALSE), /* pcrel_offset */ | |
1393 | ||
1394 | /* Like DTPREL16_DS, but no overflow. */ | |
1395 | HOWTO (R_PPC64_DTPREL16_LO_DS, | |
1396 | 0, /* rightshift */ | |
1397 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1398 | 16, /* bitsize */ | |
1399 | FALSE, /* pc_relative */ | |
1400 | 0, /* bitpos */ | |
1401 | complain_overflow_dont, /* complain_on_overflow */ | |
1402 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1403 | "R_PPC64_DTPREL16_LO_DS", /* name */ | |
1404 | FALSE, /* partial_inplace */ | |
1405 | 0, /* src_mask */ | |
1406 | 0xfffc, /* dst_mask */ | |
1407 | FALSE), /* pcrel_offset */ | |
1408 | ||
1409 | /* Computes a tp-relative displacement, the difference between the value of | |
1410 | sym+add and the value of the thread pointer (r13). */ | |
1411 | HOWTO (R_PPC64_TPREL64, | |
1412 | 0, /* rightshift */ | |
1413 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1414 | 64, /* bitsize */ | |
1415 | FALSE, /* pc_relative */ | |
1416 | 0, /* bitpos */ | |
1417 | complain_overflow_dont, /* complain_on_overflow */ | |
1418 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1419 | "R_PPC64_TPREL64", /* name */ | |
1420 | FALSE, /* partial_inplace */ | |
1421 | 0, /* src_mask */ | |
1422 | ONES (64), /* dst_mask */ | |
1423 | FALSE), /* pcrel_offset */ | |
1424 | ||
1425 | /* A 16 bit tprel reloc. */ | |
1426 | HOWTO (R_PPC64_TPREL16, | |
1427 | 0, /* rightshift */ | |
1428 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1429 | 16, /* bitsize */ | |
1430 | FALSE, /* pc_relative */ | |
1431 | 0, /* bitpos */ | |
1432 | complain_overflow_signed, /* complain_on_overflow */ | |
1433 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1434 | "R_PPC64_TPREL16", /* name */ | |
1435 | FALSE, /* partial_inplace */ | |
1436 | 0, /* src_mask */ | |
1437 | 0xffff, /* dst_mask */ | |
1438 | FALSE), /* pcrel_offset */ | |
1439 | ||
1440 | /* Like TPREL16, but no overflow. */ | |
1441 | HOWTO (R_PPC64_TPREL16_LO, | |
1442 | 0, /* rightshift */ | |
1443 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1444 | 16, /* bitsize */ | |
1445 | FALSE, /* pc_relative */ | |
1446 | 0, /* bitpos */ | |
1447 | complain_overflow_dont, /* complain_on_overflow */ | |
1448 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1449 | "R_PPC64_TPREL16_LO", /* name */ | |
1450 | FALSE, /* partial_inplace */ | |
1451 | 0, /* src_mask */ | |
1452 | 0xffff, /* dst_mask */ | |
1453 | FALSE), /* pcrel_offset */ | |
1454 | ||
1455 | /* Like TPREL16_LO, but next higher group of 16 bits. */ | |
1456 | HOWTO (R_PPC64_TPREL16_HI, | |
1457 | 16, /* rightshift */ | |
1458 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1459 | 16, /* bitsize */ | |
1460 | FALSE, /* pc_relative */ | |
1461 | 0, /* bitpos */ | |
1462 | complain_overflow_dont, /* complain_on_overflow */ | |
1463 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1464 | "R_PPC64_TPREL16_HI", /* name */ | |
1465 | FALSE, /* partial_inplace */ | |
1466 | 0, /* src_mask */ | |
1467 | 0xffff, /* dst_mask */ | |
1468 | FALSE), /* pcrel_offset */ | |
1469 | ||
1470 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1471 | HOWTO (R_PPC64_TPREL16_HA, | |
1472 | 16, /* rightshift */ | |
1473 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1474 | 16, /* bitsize */ | |
1475 | FALSE, /* pc_relative */ | |
1476 | 0, /* bitpos */ | |
1477 | complain_overflow_dont, /* complain_on_overflow */ | |
1478 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1479 | "R_PPC64_TPREL16_HA", /* name */ | |
1480 | FALSE, /* partial_inplace */ | |
1481 | 0, /* src_mask */ | |
1482 | 0xffff, /* dst_mask */ | |
1483 | FALSE), /* pcrel_offset */ | |
1484 | ||
1485 | /* Like TPREL16_HI, but next higher group of 16 bits. */ | |
1486 | HOWTO (R_PPC64_TPREL16_HIGHER, | |
1487 | 32, /* rightshift */ | |
1488 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1489 | 16, /* bitsize */ | |
1490 | FALSE, /* pc_relative */ | |
1491 | 0, /* bitpos */ | |
1492 | complain_overflow_dont, /* complain_on_overflow */ | |
1493 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1494 | "R_PPC64_TPREL16_HIGHER", /* name */ | |
1495 | FALSE, /* partial_inplace */ | |
1496 | 0, /* src_mask */ | |
1497 | 0xffff, /* dst_mask */ | |
1498 | FALSE), /* pcrel_offset */ | |
1499 | ||
1500 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ | |
1501 | HOWTO (R_PPC64_TPREL16_HIGHERA, | |
1502 | 32, /* rightshift */ | |
1503 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1504 | 16, /* bitsize */ | |
1505 | FALSE, /* pc_relative */ | |
1506 | 0, /* bitpos */ | |
1507 | complain_overflow_dont, /* complain_on_overflow */ | |
1508 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1509 | "R_PPC64_TPREL16_HIGHERA", /* name */ | |
1510 | FALSE, /* partial_inplace */ | |
1511 | 0, /* src_mask */ | |
1512 | 0xffff, /* dst_mask */ | |
1513 | FALSE), /* pcrel_offset */ | |
1514 | ||
1515 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ | |
1516 | HOWTO (R_PPC64_TPREL16_HIGHEST, | |
1517 | 48, /* rightshift */ | |
1518 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1519 | 16, /* bitsize */ | |
1520 | FALSE, /* pc_relative */ | |
1521 | 0, /* bitpos */ | |
1522 | complain_overflow_dont, /* complain_on_overflow */ | |
1523 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1524 | "R_PPC64_TPREL16_HIGHEST", /* name */ | |
1525 | FALSE, /* partial_inplace */ | |
1526 | 0, /* src_mask */ | |
1527 | 0xffff, /* dst_mask */ | |
1528 | FALSE), /* pcrel_offset */ | |
1529 | ||
1530 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1531 | HOWTO (R_PPC64_TPREL16_HIGHESTA, | |
1532 | 48, /* rightshift */ | |
1533 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1534 | 16, /* bitsize */ | |
1535 | FALSE, /* pc_relative */ | |
1536 | 0, /* bitpos */ | |
1537 | complain_overflow_dont, /* complain_on_overflow */ | |
1538 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1539 | "R_PPC64_TPREL16_HIGHESTA", /* name */ | |
1540 | FALSE, /* partial_inplace */ | |
1541 | 0, /* src_mask */ | |
1542 | 0xffff, /* dst_mask */ | |
1543 | FALSE), /* pcrel_offset */ | |
1544 | ||
1545 | /* Like TPREL16, but for insns with a DS field. */ | |
1546 | HOWTO (R_PPC64_TPREL16_DS, | |
1547 | 0, /* rightshift */ | |
1548 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1549 | 16, /* bitsize */ | |
1550 | FALSE, /* pc_relative */ | |
1551 | 0, /* bitpos */ | |
1552 | complain_overflow_signed, /* complain_on_overflow */ | |
1553 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1554 | "R_PPC64_TPREL16_DS", /* name */ | |
1555 | FALSE, /* partial_inplace */ | |
1556 | 0, /* src_mask */ | |
1557 | 0xfffc, /* dst_mask */ | |
1558 | FALSE), /* pcrel_offset */ | |
1559 | ||
1560 | /* Like TPREL16_DS, but no overflow. */ | |
1561 | HOWTO (R_PPC64_TPREL16_LO_DS, | |
1562 | 0, /* rightshift */ | |
1563 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1564 | 16, /* bitsize */ | |
1565 | FALSE, /* pc_relative */ | |
1566 | 0, /* bitpos */ | |
1567 | complain_overflow_dont, /* complain_on_overflow */ | |
1568 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1569 | "R_PPC64_TPREL16_LO_DS", /* name */ | |
1570 | FALSE, /* partial_inplace */ | |
1571 | 0, /* src_mask */ | |
1572 | 0xfffc, /* dst_mask */ | |
1573 | FALSE), /* pcrel_offset */ | |
1574 | ||
1575 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1576 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1577 | to the first entry relative to the TOC base (r2). */ | |
1578 | HOWTO (R_PPC64_GOT_TLSGD16, | |
1579 | 0, /* rightshift */ | |
1580 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1581 | 16, /* bitsize */ | |
1582 | FALSE, /* pc_relative */ | |
1583 | 0, /* bitpos */ | |
1584 | complain_overflow_signed, /* complain_on_overflow */ | |
1585 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1586 | "R_PPC64_GOT_TLSGD16", /* name */ | |
b34976b6 | 1587 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1588 | 0, /* src_mask */ |
1589 | 0xffff, /* dst_mask */ | |
b34976b6 | 1590 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1591 | |
411e1bfb AM |
1592 | /* Like GOT_TLSGD16, but no overflow. */ |
1593 | HOWTO (R_PPC64_GOT_TLSGD16_LO, | |
5bd4f169 AM |
1594 | 0, /* rightshift */ |
1595 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1596 | 16, /* bitsize */ | |
b34976b6 | 1597 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1598 | 0, /* bitpos */ |
1599 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1600 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1601 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
b34976b6 | 1602 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1603 | 0, /* src_mask */ |
1604 | 0xffff, /* dst_mask */ | |
b34976b6 | 1605 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1606 | |
411e1bfb AM |
1607 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1608 | HOWTO (R_PPC64_GOT_TLSGD16_HI, | |
5bd4f169 AM |
1609 | 16, /* rightshift */ |
1610 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1611 | 16, /* bitsize */ | |
b34976b6 | 1612 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1613 | 0, /* bitpos */ |
1614 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1615 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1616 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
b34976b6 | 1617 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1618 | 0, /* src_mask */ |
1619 | 0xffff, /* dst_mask */ | |
b34976b6 | 1620 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1621 | |
411e1bfb AM |
1622 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1623 | HOWTO (R_PPC64_GOT_TLSGD16_HA, | |
5bd4f169 AM |
1624 | 16, /* rightshift */ |
1625 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1626 | 16, /* bitsize */ | |
b34976b6 | 1627 | FALSE, /* pc_relative */ |
5bd4f169 | 1628 | 0, /* bitpos */ |
411e1bfb | 1629 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1630 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1631 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
b34976b6 | 1632 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1633 | 0, /* src_mask */ |
1634 | 0xffff, /* dst_mask */ | |
b34976b6 | 1635 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1636 | |
411e1bfb AM |
1637 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
1638 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1639 | first entry relative to the TOC base (r2). */ | |
1640 | HOWTO (R_PPC64_GOT_TLSLD16, | |
5bd4f169 AM |
1641 | 0, /* rightshift */ |
1642 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1643 | 16, /* bitsize */ | |
b34976b6 | 1644 | FALSE, /* pc_relative */ |
5bd4f169 | 1645 | 0, /* bitpos */ |
411e1bfb AM |
1646 | complain_overflow_signed, /* complain_on_overflow */ |
1647 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1648 | "R_PPC64_GOT_TLSLD16", /* name */ | |
b34976b6 | 1649 | FALSE, /* partial_inplace */ |
d006db6c | 1650 | 0, /* src_mask */ |
411e1bfb | 1651 | 0xffff, /* dst_mask */ |
b34976b6 | 1652 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1653 | |
411e1bfb AM |
1654 | /* Like GOT_TLSLD16, but no overflow. */ |
1655 | HOWTO (R_PPC64_GOT_TLSLD16_LO, | |
5bd4f169 AM |
1656 | 0, /* rightshift */ |
1657 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1658 | 16, /* bitsize */ | |
b34976b6 | 1659 | FALSE, /* pc_relative */ |
5bd4f169 | 1660 | 0, /* bitpos */ |
411e1bfb AM |
1661 | complain_overflow_dont, /* complain_on_overflow */ |
1662 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1663 | "R_PPC64_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1664 | FALSE, /* partial_inplace */ |
d006db6c | 1665 | 0, /* src_mask */ |
411e1bfb | 1666 | 0xffff, /* dst_mask */ |
b34976b6 | 1667 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1668 | |
411e1bfb AM |
1669 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1670 | HOWTO (R_PPC64_GOT_TLSLD16_HI, | |
1671 | 16, /* rightshift */ | |
5bd4f169 AM |
1672 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1673 | 16, /* bitsize */ | |
b34976b6 | 1674 | FALSE, /* pc_relative */ |
5bd4f169 | 1675 | 0, /* bitpos */ |
411e1bfb | 1676 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1677 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1678 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
b34976b6 | 1679 | FALSE, /* partial_inplace */ |
d006db6c | 1680 | 0, /* src_mask */ |
411e1bfb | 1681 | 0xffff, /* dst_mask */ |
b34976b6 | 1682 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1683 | |
411e1bfb AM |
1684 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1685 | HOWTO (R_PPC64_GOT_TLSLD16_HA, | |
1686 | 16, /* rightshift */ | |
5bd4f169 AM |
1687 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1688 | 16, /* bitsize */ | |
b34976b6 | 1689 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1690 | 0, /* bitpos */ |
1691 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1692 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1693 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
b34976b6 | 1694 | FALSE, /* partial_inplace */ |
d006db6c | 1695 | 0, /* src_mask */ |
411e1bfb | 1696 | 0xffff, /* dst_mask */ |
b34976b6 | 1697 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1698 | |
411e1bfb AM |
1699 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
1700 | the offset to the entry relative to the TOC base (r2). */ | |
1701 | HOWTO (R_PPC64_GOT_DTPREL16_DS, | |
5bd4f169 AM |
1702 | 0, /* rightshift */ |
1703 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1704 | 16, /* bitsize */ | |
b34976b6 | 1705 | FALSE, /* pc_relative */ |
5bd4f169 | 1706 | 0, /* bitpos */ |
411e1bfb | 1707 | complain_overflow_signed, /* complain_on_overflow */ |
805fc799 | 1708 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1709 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
b34976b6 | 1710 | FALSE, /* partial_inplace */ |
d006db6c | 1711 | 0, /* src_mask */ |
5bd4f169 | 1712 | 0xfffc, /* dst_mask */ |
b34976b6 | 1713 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1714 | |
411e1bfb AM |
1715 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
1716 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, | |
5bd4f169 | 1717 | 0, /* rightshift */ |
c061c2d8 AM |
1718 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1719 | 16, /* bitsize */ | |
b34976b6 | 1720 | FALSE, /* pc_relative */ |
5bd4f169 | 1721 | 0, /* bitpos */ |
411e1bfb AM |
1722 | complain_overflow_dont, /* complain_on_overflow */ |
1723 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1724 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ | |
b34976b6 | 1725 | FALSE, /* partial_inplace */ |
d006db6c | 1726 | 0, /* src_mask */ |
c061c2d8 | 1727 | 0xfffc, /* dst_mask */ |
b34976b6 | 1728 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1729 | |
411e1bfb AM |
1730 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
1731 | HOWTO (R_PPC64_GOT_DTPREL16_HI, | |
1732 | 16, /* rightshift */ | |
5bd4f169 AM |
1733 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1734 | 16, /* bitsize */ | |
b34976b6 | 1735 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1736 | 0, /* bitpos */ |
1737 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1738 | ppc64_elf_unhandled_reloc, /* special_function */ |
1739 | "R_PPC64_GOT_DTPREL16_HI", /* name */ | |
b34976b6 | 1740 | FALSE, /* partial_inplace */ |
d006db6c | 1741 | 0, /* src_mask */ |
411e1bfb | 1742 | 0xffff, /* dst_mask */ |
b34976b6 | 1743 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1744 | |
411e1bfb AM |
1745 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1746 | HOWTO (R_PPC64_GOT_DTPREL16_HA, | |
1747 | 16, /* rightshift */ | |
1748 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1749 | 16, /* bitsize */ | |
1750 | FALSE, /* pc_relative */ | |
1751 | 0, /* bitpos */ | |
1752 | complain_overflow_dont, /* complain_on_overflow */ | |
1753 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1754 | "R_PPC64_GOT_DTPREL16_HA", /* name */ | |
1755 | FALSE, /* partial_inplace */ | |
1756 | 0, /* src_mask */ | |
1757 | 0xffff, /* dst_mask */ | |
1758 | FALSE), /* pcrel_offset */ | |
1759 | ||
1760 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the | |
1761 | offset to the entry relative to the TOC base (r2). */ | |
1762 | HOWTO (R_PPC64_GOT_TPREL16_DS, | |
5bd4f169 AM |
1763 | 0, /* rightshift */ |
1764 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1765 | 16, /* bitsize */ | |
b34976b6 | 1766 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1767 | 0, /* bitpos */ |
1768 | complain_overflow_signed, /* complain_on_overflow */ | |
411e1bfb AM |
1769 | ppc64_elf_unhandled_reloc, /* special_function */ |
1770 | "R_PPC64_GOT_TPREL16_DS", /* name */ | |
b34976b6 | 1771 | FALSE, /* partial_inplace */ |
d006db6c | 1772 | 0, /* src_mask */ |
ad8e1ba5 | 1773 | 0xfffc, /* dst_mask */ |
b34976b6 | 1774 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1775 | |
411e1bfb AM |
1776 | /* Like GOT_TPREL16_DS, but no overflow. */ |
1777 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, | |
5bd4f169 AM |
1778 | 0, /* rightshift */ |
1779 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1780 | 16, /* bitsize */ | |
b34976b6 | 1781 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1782 | 0, /* bitpos */ |
1783 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1784 | ppc64_elf_unhandled_reloc, /* special_function */ |
1785 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ | |
b34976b6 | 1786 | FALSE, /* partial_inplace */ |
d006db6c | 1787 | 0, /* src_mask */ |
ad8e1ba5 | 1788 | 0xfffc, /* dst_mask */ |
b34976b6 | 1789 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1790 | |
411e1bfb AM |
1791 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
1792 | HOWTO (R_PPC64_GOT_TPREL16_HI, | |
1793 | 16, /* rightshift */ | |
5bd4f169 AM |
1794 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1795 | 16, /* bitsize */ | |
b34976b6 | 1796 | FALSE, /* pc_relative */ |
5bd4f169 | 1797 | 0, /* bitpos */ |
411e1bfb | 1798 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1799 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1800 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
b34976b6 | 1801 | FALSE, /* partial_inplace */ |
d006db6c | 1802 | 0, /* src_mask */ |
411e1bfb | 1803 | 0xffff, /* dst_mask */ |
b34976b6 | 1804 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1805 | |
411e1bfb AM |
1806 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
1807 | HOWTO (R_PPC64_GOT_TPREL16_HA, | |
1808 | 16, /* rightshift */ | |
5bd4f169 AM |
1809 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1810 | 16, /* bitsize */ | |
b34976b6 | 1811 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1812 | 0, /* bitpos */ |
1813 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1814 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1815 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
b34976b6 | 1816 | FALSE, /* partial_inplace */ |
d006db6c | 1817 | 0, /* src_mask */ |
411e1bfb | 1818 | 0xffff, /* dst_mask */ |
b34976b6 | 1819 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1820 | |
1821 | /* GNU extension to record C++ vtable hierarchy. */ | |
1822 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1823 | 0, /* rightshift */ | |
1824 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1825 | 0, /* bitsize */ | |
b34976b6 | 1826 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1827 | 0, /* bitpos */ |
1828 | complain_overflow_dont, /* complain_on_overflow */ | |
1829 | NULL, /* special_function */ | |
1830 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1831 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1832 | 0, /* src_mask */ |
1833 | 0, /* dst_mask */ | |
b34976b6 | 1834 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1835 | |
1836 | /* GNU extension to record C++ vtable member usage. */ | |
1837 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1838 | 0, /* rightshift */ | |
1839 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1840 | 0, /* bitsize */ | |
b34976b6 | 1841 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1842 | 0, /* bitpos */ |
1843 | complain_overflow_dont, /* complain_on_overflow */ | |
1844 | NULL, /* special_function */ | |
1845 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1846 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1847 | 0, /* src_mask */ |
1848 | 0, /* dst_mask */ | |
b34976b6 | 1849 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1850 | }; |
1851 | ||
1852 | \f | |
1853 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1854 | be done. */ | |
1855 | ||
1856 | static void | |
4ce794b7 | 1857 | ppc_howto_init (void) |
5bd4f169 AM |
1858 | { |
1859 | unsigned int i, type; | |
1860 | ||
1861 | for (i = 0; | |
1862 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1863 | i++) | |
1864 | { | |
1865 | type = ppc64_elf_howto_raw[i].type; | |
1866 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1867 | / sizeof (ppc64_elf_howto_table[0]))); | |
1868 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1869 | } | |
1870 | } | |
1871 | ||
1872 | static reloc_howto_type * | |
4ce794b7 AM |
1873 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1874 | bfd_reloc_code_real_type code) | |
5bd4f169 | 1875 | { |
411e1bfb | 1876 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
5bd4f169 AM |
1877 | |
1878 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1879 | /* Initialize howto table if needed. */ | |
1880 | ppc_howto_init (); | |
1881 | ||
4ce794b7 | 1882 | switch (code) |
5bd4f169 AM |
1883 | { |
1884 | default: | |
4ce794b7 | 1885 | return NULL; |
5bd4f169 | 1886 | |
411e1bfb AM |
1887 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
1888 | break; | |
1889 | case BFD_RELOC_32: r = R_PPC64_ADDR32; | |
1890 | break; | |
1891 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; | |
1892 | break; | |
1893 | case BFD_RELOC_16: r = R_PPC64_ADDR16; | |
1894 | break; | |
1895 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; | |
1896 | break; | |
1897 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; | |
1898 | break; | |
1899 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; | |
5bd4f169 | 1900 | break; |
411e1bfb | 1901 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
5bd4f169 | 1902 | break; |
411e1bfb | 1903 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
5bd4f169 | 1904 | break; |
411e1bfb | 1905 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
5bd4f169 | 1906 | break; |
411e1bfb | 1907 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
5bd4f169 | 1908 | break; |
411e1bfb | 1909 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
5bd4f169 | 1910 | break; |
411e1bfb | 1911 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
5bd4f169 | 1912 | break; |
411e1bfb | 1913 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
5bd4f169 | 1914 | break; |
411e1bfb | 1915 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
5bd4f169 | 1916 | break; |
411e1bfb | 1917 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
5bd4f169 | 1918 | break; |
411e1bfb | 1919 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
5bd4f169 | 1920 | break; |
411e1bfb | 1921 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
5bd4f169 | 1922 | break; |
411e1bfb | 1923 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
5bd4f169 | 1924 | break; |
411e1bfb | 1925 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
5bd4f169 | 1926 | break; |
411e1bfb | 1927 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
5bd4f169 | 1928 | break; |
411e1bfb | 1929 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
5bd4f169 | 1930 | break; |
411e1bfb | 1931 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
5bd4f169 | 1932 | break; |
411e1bfb | 1933 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
5bd4f169 | 1934 | break; |
411e1bfb | 1935 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
5bd4f169 | 1936 | break; |
411e1bfb | 1937 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
5bd4f169 | 1938 | break; |
411e1bfb | 1939 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
5bd4f169 | 1940 | break; |
411e1bfb | 1941 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
5bd4f169 | 1942 | break; |
411e1bfb | 1943 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
5bd4f169 | 1944 | break; |
411e1bfb | 1945 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
5bd4f169 | 1946 | break; |
411e1bfb | 1947 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
5bd4f169 | 1948 | break; |
411e1bfb | 1949 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
5bd4f169 | 1950 | break; |
411e1bfb | 1951 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
5bd4f169 | 1952 | break; |
411e1bfb | 1953 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
5bd4f169 | 1954 | break; |
411e1bfb | 1955 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
5bd4f169 | 1956 | break; |
411e1bfb | 1957 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
5bd4f169 | 1958 | break; |
411e1bfb | 1959 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
5bd4f169 | 1960 | break; |
411e1bfb | 1961 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
5bd4f169 | 1962 | break; |
411e1bfb | 1963 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
5bd4f169 | 1964 | break; |
411e1bfb | 1965 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
5bd4f169 | 1966 | break; |
411e1bfb | 1967 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
5bd4f169 | 1968 | break; |
411e1bfb | 1969 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
5bd4f169 | 1970 | break; |
411e1bfb | 1971 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
5bd4f169 | 1972 | break; |
411e1bfb | 1973 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
5bd4f169 | 1974 | break; |
411e1bfb | 1975 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
5bd4f169 | 1976 | break; |
411e1bfb | 1977 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
5bd4f169 | 1978 | break; |
411e1bfb | 1979 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
5bd4f169 | 1980 | break; |
411e1bfb | 1981 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
5bd4f169 | 1982 | break; |
411e1bfb | 1983 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
5bd4f169 | 1984 | break; |
411e1bfb | 1985 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
5bd4f169 | 1986 | break; |
411e1bfb | 1987 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
5bd4f169 | 1988 | break; |
411e1bfb | 1989 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
5bd4f169 | 1990 | break; |
411e1bfb | 1991 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
5bd4f169 | 1992 | break; |
411e1bfb | 1993 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
5bd4f169 | 1994 | break; |
411e1bfb | 1995 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
5bd4f169 | 1996 | break; |
411e1bfb | 1997 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
5bd4f169 | 1998 | break; |
411e1bfb | 1999 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
5bd4f169 | 2000 | break; |
411e1bfb | 2001 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
5bd4f169 | 2002 | break; |
411e1bfb | 2003 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
5bd4f169 | 2004 | break; |
411e1bfb | 2005 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
5bd4f169 | 2006 | break; |
411e1bfb | 2007 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
5bd4f169 | 2008 | break; |
411e1bfb | 2009 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
5bd4f169 | 2010 | break; |
411e1bfb | 2011 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
5bd4f169 | 2012 | break; |
411e1bfb | 2013 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
5bd4f169 | 2014 | break; |
411e1bfb | 2015 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
5bd4f169 | 2016 | break; |
411e1bfb | 2017 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
5bd4f169 | 2018 | break; |
411e1bfb AM |
2019 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
2020 | break; | |
2021 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; | |
2022 | break; | |
2023 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; | |
2024 | break; | |
2025 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; | |
2026 | break; | |
2027 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; | |
2028 | break; | |
2029 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; | |
2030 | break; | |
2031 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; | |
2032 | break; | |
2033 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; | |
2034 | break; | |
2035 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; | |
2036 | break; | |
2037 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; | |
2038 | break; | |
2039 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; | |
2040 | break; | |
2041 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; | |
2042 | break; | |
2043 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; | |
2044 | break; | |
2045 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; | |
2046 | break; | |
2047 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; | |
2048 | break; | |
2049 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; | |
2050 | break; | |
2051 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; | |
2052 | break; | |
2053 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; | |
2054 | break; | |
2055 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; | |
2056 | break; | |
2057 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; | |
2058 | break; | |
2059 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; | |
2060 | break; | |
2061 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; | |
2062 | break; | |
2063 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; | |
2064 | break; | |
2065 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; | |
2066 | break; | |
2067 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; | |
2068 | break; | |
2069 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; | |
2070 | break; | |
2071 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; | |
2072 | break; | |
2073 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; | |
2074 | break; | |
2075 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; | |
2076 | break; | |
2077 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; | |
2078 | break; | |
2079 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; | |
2080 | break; | |
2081 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; | |
2082 | break; | |
2083 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; | |
2084 | break; | |
2085 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; | |
2086 | break; | |
2087 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; | |
5bd4f169 AM |
2088 | break; |
2089 | } | |
2090 | ||
4ce794b7 | 2091 | return ppc64_elf_howto_table[r]; |
5bd4f169 AM |
2092 | }; |
2093 | ||
2094 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
2095 | ||
2096 | static void | |
4ce794b7 AM |
2097 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
2098 | Elf_Internal_Rela *dst) | |
5bd4f169 | 2099 | { |
65f38f15 AM |
2100 | unsigned int type; |
2101 | ||
ef60b7ff | 2102 | /* Initialize howto table if needed. */ |
5bd4f169 | 2103 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
2104 | ppc_howto_init (); |
2105 | ||
65f38f15 AM |
2106 | type = ELF64_R_TYPE (dst->r_info); |
2107 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
2108 | / sizeof (ppc64_elf_howto_table[0]))); | |
2109 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
2110 | } |
2111 | ||
04c9666a | 2112 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
2113 | |
2114 | static bfd_reloc_status_type | |
4ce794b7 AM |
2115 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2116 | void *data, asection *input_section, | |
2117 | bfd *output_bfd, char **error_message) | |
5bd4f169 | 2118 | { |
805fc799 AM |
2119 | /* If this is a relocatable link (output_bfd test tells us), just |
2120 | call the generic function. Any adjustment will be done at final | |
2121 | link time. */ | |
2122 | if (output_bfd != NULL) | |
cedb70c5 | 2123 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2124 | input_section, output_bfd, error_message); |
2125 | ||
2126 | /* Adjust the addend for sign extension of the low 16 bits. | |
2127 | We won't actually be using the low 16 bits, so trashing them | |
2128 | doesn't matter. */ | |
2129 | reloc_entry->addend += 0x8000; | |
2130 | return bfd_reloc_continue; | |
2131 | } | |
5bd4f169 | 2132 | |
805fc799 | 2133 | static bfd_reloc_status_type |
4ce794b7 AM |
2134 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2135 | void *data, asection *input_section, | |
2136 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2137 | { |
2138 | long insn; | |
04c9666a | 2139 | enum elf_ppc64_reloc_type r_type; |
805fc799 AM |
2140 | bfd_size_type octets; |
2141 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 2142 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
2143 | |
2144 | /* If this is a relocatable link (output_bfd test tells us), just | |
2145 | call the generic function. Any adjustment will be done at final | |
2146 | link time. */ | |
5bd4f169 | 2147 | if (output_bfd != NULL) |
cedb70c5 | 2148 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2149 | input_section, output_bfd, error_message); |
2150 | ||
2151 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2152 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2153 | insn &= ~(0x01 << 21); | |
4ce794b7 | 2154 | r_type = reloc_entry->howto->type; |
805fc799 AM |
2155 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
2156 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 2157 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
2158 | |
2159 | if (is_power4) | |
5bd4f169 | 2160 | { |
805fc799 AM |
2161 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
2162 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
2163 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
2164 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
2165 | insn |= 0x02 << 21; | |
2166 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
2167 | insn |= 0x08 << 21; | |
2168 | else | |
2169 | return bfd_reloc_continue; | |
5bd4f169 | 2170 | } |
805fc799 AM |
2171 | else |
2172 | { | |
2173 | bfd_vma target = 0; | |
2174 | bfd_vma from; | |
5bd4f169 | 2175 | |
805fc799 AM |
2176 | if (!bfd_is_com_section (symbol->section)) |
2177 | target = symbol->value; | |
2178 | target += symbol->section->output_section->vma; | |
2179 | target += symbol->section->output_offset; | |
2180 | target += reloc_entry->addend; | |
5bd4f169 | 2181 | |
805fc799 AM |
2182 | from = (reloc_entry->address |
2183 | + input_section->output_offset | |
2184 | + input_section->output_section->vma); | |
5bd4f169 | 2185 | |
805fc799 AM |
2186 | /* Invert 'y' bit if not the default. */ |
2187 | if ((bfd_signed_vma) (target - from) < 0) | |
2188 | insn ^= 0x01 << 21; | |
2189 | } | |
4ce794b7 | 2190 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
805fc799 AM |
2191 | return bfd_reloc_continue; |
2192 | } | |
5bd4f169 | 2193 | |
805fc799 | 2194 | static bfd_reloc_status_type |
4ce794b7 AM |
2195 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2196 | void *data, asection *input_section, | |
2197 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2198 | { |
2199 | /* If this is a relocatable link (output_bfd test tells us), just | |
2200 | call the generic function. Any adjustment will be done at final | |
2201 | link time. */ | |
2202 | if (output_bfd != NULL) | |
cedb70c5 | 2203 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 2204 | input_section, output_bfd, error_message); |
5bd4f169 | 2205 | |
805fc799 AM |
2206 | /* Subtract the symbol section base address. */ |
2207 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
2208 | return bfd_reloc_continue; |
2209 | } | |
2210 | ||
805fc799 | 2211 | static bfd_reloc_status_type |
4ce794b7 AM |
2212 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2213 | void *data, asection *input_section, | |
2214 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2215 | { |
2216 | /* If this is a relocatable link (output_bfd test tells us), just | |
2217 | call the generic function. Any adjustment will be done at final | |
2218 | link time. */ | |
2219 | if (output_bfd != NULL) | |
cedb70c5 | 2220 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2221 | input_section, output_bfd, error_message); |
2222 | ||
2223 | /* Subtract the symbol section base address. */ | |
2224 | reloc_entry->addend -= symbol->section->output_section->vma; | |
2225 | ||
2226 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2227 | reloc_entry->addend += 0x8000; | |
2228 | return bfd_reloc_continue; | |
2229 | } | |
2230 | ||
2231 | static bfd_reloc_status_type | |
4ce794b7 AM |
2232 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2233 | void *data, asection *input_section, | |
2234 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2235 | { |
2236 | bfd_vma TOCstart; | |
2237 | ||
2238 | /* If this is a relocatable link (output_bfd test tells us), just | |
2239 | call the generic function. Any adjustment will be done at final | |
2240 | link time. */ | |
2241 | if (output_bfd != NULL) | |
cedb70c5 | 2242 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2243 | input_section, output_bfd, error_message); |
2244 | ||
2245 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2246 | if (TOCstart == 0) | |
2247 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2248 | ||
2249 | /* Subtract the TOC base address. */ | |
2250 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2251 | return bfd_reloc_continue; | |
2252 | } | |
2253 | ||
2254 | static bfd_reloc_status_type | |
4ce794b7 AM |
2255 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2256 | void *data, asection *input_section, | |
2257 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2258 | { |
2259 | bfd_vma TOCstart; | |
2260 | ||
2261 | /* If this is a relocatable link (output_bfd test tells us), just | |
2262 | call the generic function. Any adjustment will be done at final | |
2263 | link time. */ | |
2264 | if (output_bfd != NULL) | |
cedb70c5 | 2265 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2266 | input_section, output_bfd, error_message); |
2267 | ||
2268 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2269 | if (TOCstart == 0) | |
2270 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2271 | ||
2272 | /* Subtract the TOC base address. */ | |
2273 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2274 | ||
2275 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2276 | reloc_entry->addend += 0x8000; | |
2277 | return bfd_reloc_continue; | |
2278 | } | |
2279 | ||
2280 | static bfd_reloc_status_type | |
4ce794b7 AM |
2281 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2282 | void *data, asection *input_section, | |
2283 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2284 | { |
2285 | bfd_vma TOCstart; | |
2286 | bfd_size_type octets; | |
2287 | ||
2288 | /* If this is a relocatable link (output_bfd test tells us), just | |
2289 | call the generic function. Any adjustment will be done at final | |
2290 | link time. */ | |
2291 | if (output_bfd != NULL) | |
cedb70c5 | 2292 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2293 | input_section, output_bfd, error_message); |
2294 | ||
2295 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2296 | if (TOCstart == 0) | |
2297 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2298 | ||
2299 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2300 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
2301 | return bfd_reloc_ok; | |
2302 | } | |
2303 | ||
2304 | static bfd_reloc_status_type | |
4ce794b7 AM |
2305 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2306 | void *data, asection *input_section, | |
2307 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2308 | { |
2309 | /* If this is a relocatable link (output_bfd test tells us), just | |
2310 | call the generic function. Any adjustment will be done at final | |
2311 | link time. */ | |
2312 | if (output_bfd != NULL) | |
cedb70c5 | 2313 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2314 | input_section, output_bfd, error_message); |
2315 | ||
2316 | if (error_message != NULL) | |
2317 | { | |
2318 | static char buf[60]; | |
2319 | sprintf (buf, "generic linker can't handle %s", | |
2320 | reloc_entry->howto->name); | |
2321 | *error_message = buf; | |
2322 | } | |
2323 | return bfd_reloc_dangerous; | |
2324 | } | |
2325 | ||
e717da7e AM |
2326 | struct ppc64_elf_obj_tdata |
2327 | { | |
2328 | struct elf_obj_tdata elf; | |
2329 | ||
2330 | /* Shortcuts to dynamic linker sections. */ | |
2331 | asection *got; | |
2332 | asection *relgot; | |
2333 | ||
2334 | /* TLS local dynamic got entry handling. Suppose for multiple GOT | |
2335 | sections means we potentially need one of these for each input bfd. */ | |
2336 | union { | |
2337 | bfd_signed_vma refcount; | |
2338 | bfd_vma offset; | |
2339 | } tlsld_got; | |
2340 | }; | |
2341 | ||
2342 | #define ppc64_elf_tdata(bfd) \ | |
2343 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) | |
2344 | ||
2345 | #define ppc64_tlsld_got(bfd) \ | |
2346 | (&ppc64_elf_tdata (bfd)->tlsld_got) | |
2347 | ||
2348 | /* Override the generic function because we store some extras. */ | |
2349 | ||
2350 | static bfd_boolean | |
2351 | ppc64_elf_mkobject (bfd *abfd) | |
2352 | { | |
2353 | bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); | |
2354 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2355 | if (abfd->tdata.any == NULL) | |
2356 | return FALSE; | |
2357 | return TRUE; | |
2358 | } | |
2359 | ||
feee612b AM |
2360 | /* Fix bad default arch selected for a 64 bit input bfd when the |
2361 | default is 32 bit. */ | |
2362 | ||
b34976b6 | 2363 | static bfd_boolean |
4ce794b7 | 2364 | ppc64_elf_object_p (bfd *abfd) |
feee612b AM |
2365 | { |
2366 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
2367 | { | |
2368 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2369 | ||
2370 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
2371 | { | |
2372 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
2373 | abfd->arch_info = abfd->arch_info->next; | |
2374 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
2375 | } | |
2376 | } | |
b34976b6 | 2377 | return TRUE; |
feee612b AM |
2378 | } |
2379 | ||
d37c89e5 AM |
2380 | /* Support for core dump NOTE sections. */ |
2381 | ||
2382 | static bfd_boolean | |
2383 | ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |
2384 | { | |
eea6121a | 2385 | size_t offset, size; |
d37c89e5 AM |
2386 | |
2387 | if (note->descsz != 504) | |
2388 | return FALSE; | |
2389 | ||
2390 | /* pr_cursig */ | |
2391 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
2392 | ||
2393 | /* pr_pid */ | |
2394 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32); | |
2395 | ||
2396 | /* pr_reg */ | |
2397 | offset = 112; | |
eea6121a | 2398 | size = 384; |
d37c89e5 AM |
2399 | |
2400 | /* Make a ".reg/999" section. */ | |
2401 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
eea6121a | 2402 | size, note->descpos + offset); |
d37c89e5 AM |
2403 | } |
2404 | ||
2405 | static bfd_boolean | |
2406 | ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |
2407 | { | |
2408 | if (note->descsz != 136) | |
2409 | return FALSE; | |
2410 | ||
2411 | elf_tdata (abfd)->core_program | |
2412 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |
2413 | elf_tdata (abfd)->core_command | |
2414 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |
2415 | ||
2416 | return TRUE; | |
2417 | } | |
2418 | ||
5bd4f169 AM |
2419 | /* Merge backend specific data from an object file to the output |
2420 | object file when linking. */ | |
2f6d9989 | 2421 | |
b34976b6 | 2422 | static bfd_boolean |
4ce794b7 | 2423 | ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
5bd4f169 | 2424 | { |
5bd4f169 AM |
2425 | /* Check if we have the same endianess. */ |
2426 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
87e226ce | 2427 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
5bd4f169 AM |
2428 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
2429 | { | |
2430 | const char *msg; | |
2431 | ||
2432 | if (bfd_big_endian (ibfd)) | |
4ce794b7 AM |
2433 | msg = _("%s: compiled for a big endian system " |
2434 | "and target is little endian"); | |
5bd4f169 | 2435 | else |
4ce794b7 AM |
2436 | msg = _("%s: compiled for a little endian system " |
2437 | "and target is big endian"); | |
5bd4f169 | 2438 | |
8f615d07 | 2439 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
5bd4f169 AM |
2440 | |
2441 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 2442 | return FALSE; |
5bd4f169 AM |
2443 | } |
2444 | ||
b34976b6 | 2445 | return TRUE; |
5bd4f169 | 2446 | } |
f0abc2a1 | 2447 | |
5d35169e AM |
2448 | /* Add extra PPC sections. */ |
2449 | ||
2450 | static struct bfd_elf_special_section const ppc64_elf_special_sections[]= | |
2451 | { | |
7dcb9820 AM |
2452 | { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
2453 | { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2454 | { ".plt", 4, 0, SHT_NOBITS, 0 }, | |
2455 | { ".toc", 4, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2456 | { ".toc1", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2457 | { ".tocbss", 7, 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2458 | { NULL, 0, 0, 0, 0 } | |
5d35169e AM |
2459 | }; |
2460 | ||
f0abc2a1 AM |
2461 | struct _ppc64_elf_section_data |
2462 | { | |
2463 | struct bfd_elf_section_data elf; | |
411e1bfb AM |
2464 | |
2465 | /* An array with one entry for each opd function descriptor. */ | |
f0abc2a1 AM |
2466 | union |
2467 | { | |
411e1bfb | 2468 | /* Points to the function code section for local opd entries. */ |
f0abc2a1 | 2469 | asection **func_sec; |
411e1bfb | 2470 | /* After editing .opd, adjust references to opd local syms. */ |
f0abc2a1 AM |
2471 | long *adjust; |
2472 | } opd; | |
411e1bfb AM |
2473 | |
2474 | /* An array for toc sections, indexed by offset/8. | |
2475 | Specifies the relocation symbol index used at a given toc offset. */ | |
2476 | unsigned *t_symndx; | |
f0abc2a1 AM |
2477 | }; |
2478 | ||
2479 | #define ppc64_elf_section_data(sec) \ | |
411e1bfb | 2480 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
f0abc2a1 AM |
2481 | |
2482 | static bfd_boolean | |
4ce794b7 | 2483 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
f0abc2a1 AM |
2484 | { |
2485 | struct _ppc64_elf_section_data *sdata; | |
2486 | bfd_size_type amt = sizeof (*sdata); | |
2487 | ||
4ce794b7 | 2488 | sdata = bfd_zalloc (abfd, amt); |
f0abc2a1 AM |
2489 | if (sdata == NULL) |
2490 | return FALSE; | |
4ce794b7 | 2491 | sec->used_by_bfd = sdata; |
f0abc2a1 AM |
2492 | |
2493 | return _bfd_elf_new_section_hook (abfd, sec); | |
2494 | } | |
4025353c AM |
2495 | |
2496 | static void * | |
2497 | get_opd_info (asection * sec) | |
2498 | { | |
2499 | if (sec != NULL | |
2500 | && ppc64_elf_section_data (sec) != NULL | |
2501 | && ppc64_elf_section_data (sec)->opd.adjust != NULL) | |
2502 | return ppc64_elf_section_data (sec)->opd.adjust; | |
2503 | return NULL; | |
2504 | } | |
5bd4f169 | 2505 | \f |
65f38f15 AM |
2506 | /* The following functions are specific to the ELF linker, while |
2507 | functions above are used generally. Those named ppc64_elf_* are | |
2508 | called by the main ELF linker code. They appear in this file more | |
2509 | or less in the order in which they are called. eg. | |
2510 | ppc64_elf_check_relocs is called early in the link process, | |
2511 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
2512 | called. |
2513 | ||
2514 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
2515 | functions have both a function code symbol and a function descriptor | |
2516 | symbol. A call to foo in a relocatable object file looks like: | |
2517 | ||
2518 | . .text | |
2519 | . x: | |
2520 | . bl .foo | |
2521 | . nop | |
2522 | ||
2523 | The function definition in another object file might be: | |
2524 | ||
2525 | . .section .opd | |
2526 | . foo: .quad .foo | |
2527 | . .quad .TOC.@tocbase | |
2528 | . .quad 0 | |
2529 | . | |
2530 | . .text | |
2531 | . .foo: blr | |
2532 | ||
2533 | When the linker resolves the call during a static link, the branch | |
2534 | unsurprisingly just goes to .foo and the .opd information is unused. | |
2535 | If the function definition is in a shared library, things are a little | |
2536 | different: The call goes via a plt call stub, the opd information gets | |
2537 | copied to the plt, and the linker patches the nop. | |
2538 | ||
2539 | . x: | |
2540 | . bl .foo_stub | |
2541 | . ld 2,40(1) | |
2542 | . | |
2543 | . | |
2544 | . .foo_stub: | |
2545 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
411e1bfb | 2546 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
e86ce104 AM |
2547 | . std 2,40(1) # this is the general idea |
2548 | . ld 11,0(12) | |
2549 | . ld 2,8(12) | |
2550 | . mtctr 11 | |
2551 | . ld 11,16(12) | |
2552 | . bctr | |
2553 | . | |
2554 | . .section .plt | |
2555 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
2556 | ||
2557 | The "reloc ()" notation is supposed to indicate that the linker emits | |
2558 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
2559 | copying. | |
2560 | ||
2561 | What are the difficulties here? Well, firstly, the relocations | |
2562 | examined by the linker in check_relocs are against the function code | |
2563 | sym .foo, while the dynamic relocation in the plt is emitted against | |
2564 | the function descriptor symbol, foo. Somewhere along the line, we need | |
2565 | to carefully copy dynamic link information from one symbol to the other. | |
2566 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
2567 | symbol as is normal for most other backends. We need foo dynamic | |
2568 | instead, at least for an application final link. However, when | |
2569 | creating a shared library containing foo, we need to have both symbols | |
2570 | dynamic so that references to .foo are satisfied during the early | |
2571 | stages of linking. Otherwise the linker might decide to pull in a | |
41bd81ab | 2572 | definition from some other object, eg. a static library. */ |
65f38f15 AM |
2573 | |
2574 | /* The linker needs to keep track of the number of relocs that it | |
2575 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2576 | This is so that it can later discard them if they are found to be | |
2577 | unnecessary. We store the information in a field extending the | |
2578 | regular ELF linker hash table. */ | |
2579 | ||
2580 | struct ppc_dyn_relocs | |
2581 | { | |
2582 | struct ppc_dyn_relocs *next; | |
2583 | ||
2584 | /* The input section of the reloc. */ | |
2585 | asection *sec; | |
2586 | ||
2587 | /* Total number of relocs copied for the input section. */ | |
2588 | bfd_size_type count; | |
2589 | ||
2590 | /* Number of pc-relative relocs copied for the input section. */ | |
2591 | bfd_size_type pc_count; | |
2592 | }; | |
2593 | ||
411e1bfb AM |
2594 | /* Track GOT entries needed for a given symbol. We might need more |
2595 | than one got entry per symbol. */ | |
2596 | struct got_entry | |
2597 | { | |
2598 | struct got_entry *next; | |
2599 | ||
e7b938ca | 2600 | /* The symbol addend that we'll be placing in the GOT. */ |
411e1bfb AM |
2601 | bfd_vma addend; |
2602 | ||
e717da7e AM |
2603 | /* Unlike other ELF targets, we use separate GOT entries for the same |
2604 | symbol referenced from different input files. This is to support | |
2605 | automatic multiple TOC/GOT sections, where the TOC base can vary | |
2606 | from one input file to another. | |
2607 | ||
2608 | Point to the BFD owning this GOT entry. */ | |
2609 | bfd *owner; | |
2610 | ||
2611 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, | |
2612 | TLS_TPREL or TLS_DTPREL for tls entries. */ | |
2613 | char tls_type; | |
2614 | ||
e7b938ca | 2615 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ |
411e1bfb AM |
2616 | union |
2617 | { | |
2618 | bfd_signed_vma refcount; | |
2619 | bfd_vma offset; | |
2620 | } got; | |
411e1bfb AM |
2621 | }; |
2622 | ||
2623 | /* The same for PLT. */ | |
2624 | struct plt_entry | |
2625 | { | |
2626 | struct plt_entry *next; | |
2627 | ||
2628 | bfd_vma addend; | |
2629 | ||
2630 | union | |
2631 | { | |
2632 | bfd_signed_vma refcount; | |
2633 | bfd_vma offset; | |
2634 | } plt; | |
2635 | }; | |
2636 | ||
65f38f15 | 2637 | /* Of those relocs that might be copied as dynamic relocs, this macro |
58ac9f71 AM |
2638 | selects those that must be copied when linking a shared library, |
2639 | even when the symbol is local. */ | |
65f38f15 | 2640 | |
411e1bfb | 2641 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
805fc799 AM |
2642 | ((RTYPE) != R_PPC64_REL32 \ |
2643 | && (RTYPE) != R_PPC64_REL64 \ | |
04c9666a | 2644 | && (RTYPE) != R_PPC64_REL30) |
65f38f15 | 2645 | |
f4656909 AM |
2646 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2647 | copying dynamic variables from a shared lib into an app's dynbss | |
2648 | section, and instead use a dynamic relocation to point into the | |
5d35169e AM |
2649 | shared lib. With code that gcc generates, it's vital that this be |
2650 | enabled; In the PowerPC64 ABI, the address of a function is actually | |
2651 | the address of a function descriptor, which resides in the .opd | |
2652 | section. gcc uses the descriptor directly rather than going via the | |
2653 | GOT as some other ABI's do, which means that initialized function | |
2654 | pointers must reference the descriptor. Thus, a function pointer | |
2655 | initialized to the address of a function in a shared library will | |
2656 | either require a copy reloc, or a dynamic reloc. Using a copy reloc | |
4cc11e76 | 2657 | redefines the function descriptor symbol to point to the copy. This |
5d35169e AM |
2658 | presents a problem as a plt entry for that function is also |
2659 | initialized from the function descriptor symbol and the copy reloc | |
2660 | may not be initialized first. */ | |
a23b6845 | 2661 | #define ELIMINATE_COPY_RELOCS 1 |
f4656909 | 2662 | |
721956f4 AM |
2663 | /* Section name for stubs is the associated section name plus this |
2664 | string. */ | |
2665 | #define STUB_SUFFIX ".stub" | |
2666 | ||
2667 | /* Linker stubs. | |
2668 | ppc_stub_long_branch: | |
2669 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
2670 | destination, but a 24 bit branch in a stub section will reach. | |
2671 | . b dest | |
2672 | ||
2673 | ppc_stub_plt_branch: | |
2674 | Similar to the above, but a 24 bit branch in the stub section won't | |
2675 | reach its destination. | |
87e226ce AM |
2676 | . addis %r12,%r2,xxx@toc@ha |
2677 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
2678 | . mtctr %r11 |
2679 | . bctr | |
2680 | ||
2681 | ppc_stub_plt_call: | |
2c66dc6c AM |
2682 | Used to call a function in a shared library. If it so happens that |
2683 | the plt entry referenced crosses a 64k boundary, then an extra | |
2684 | "addis %r12,%r12,1" will be inserted before the load at xxx+8 or | |
2685 | xxx+16 as appropriate. | |
87e226ce | 2686 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 2687 | . std %r2,40(%r1) |
87e226ce AM |
2688 | . ld %r11,xxx+0@toc@l(%r12) |
2689 | . ld %r2,xxx+8@toc@l(%r12) | |
721956f4 | 2690 | . mtctr %r11 |
87e226ce | 2691 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 | 2692 | . bctr |
ad8e1ba5 AM |
2693 | |
2694 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional | |
2695 | code to adjust the value and save r2 to support multiple toc sections. | |
2696 | A ppc_stub_long_branch with an r2 offset looks like: | |
2697 | . std %r2,40(%r1) | |
2698 | . addis %r2,%r2,off@ha | |
2699 | . addi %r2,%r2,off@l | |
2700 | . b dest | |
2701 | ||
2702 | A ppc_stub_plt_branch with an r2 offset looks like: | |
2703 | . std %r2,40(%r1) | |
2704 | . addis %r12,%r2,xxx@toc@ha | |
2705 | . ld %r11,xxx@toc@l(%r12) | |
2706 | . addis %r2,%r2,off@ha | |
2707 | . addi %r2,%r2,off@l | |
2708 | . mtctr %r11 | |
2709 | . bctr | |
721956f4 AM |
2710 | */ |
2711 | ||
2712 | enum ppc_stub_type { | |
2713 | ppc_stub_none, | |
2714 | ppc_stub_long_branch, | |
ad8e1ba5 | 2715 | ppc_stub_long_branch_r2off, |
721956f4 | 2716 | ppc_stub_plt_branch, |
ad8e1ba5 | 2717 | ppc_stub_plt_branch_r2off, |
721956f4 AM |
2718 | ppc_stub_plt_call |
2719 | }; | |
2720 | ||
2721 | struct ppc_stub_hash_entry { | |
2722 | ||
2723 | /* Base hash table entry structure. */ | |
2724 | struct bfd_hash_entry root; | |
2725 | ||
ad8e1ba5 AM |
2726 | enum ppc_stub_type stub_type; |
2727 | ||
721956f4 AM |
2728 | /* The stub section. */ |
2729 | asection *stub_sec; | |
2730 | ||
2731 | /* Offset within stub_sec of the beginning of this stub. */ | |
2732 | bfd_vma stub_offset; | |
2733 | ||
2734 | /* Given the symbol's value and its section we can determine its final | |
2735 | value when building the stubs (so the stub knows where to jump. */ | |
2736 | bfd_vma target_value; | |
2737 | asection *target_section; | |
2738 | ||
721956f4 AM |
2739 | /* The symbol table entry, if any, that this was derived from. */ |
2740 | struct ppc_link_hash_entry *h; | |
2741 | ||
411e1bfb AM |
2742 | /* And the reloc addend that this was derived from. */ |
2743 | bfd_vma addend; | |
2744 | ||
721956f4 AM |
2745 | /* Where this stub is being called from, or, in the case of combined |
2746 | stub sections, the first input section in the group. */ | |
2747 | asection *id_sec; | |
2748 | }; | |
2749 | ||
2750 | struct ppc_branch_hash_entry { | |
2751 | ||
2752 | /* Base hash table entry structure. */ | |
2753 | struct bfd_hash_entry root; | |
2754 | ||
2755 | /* Offset within .branch_lt. */ | |
2756 | unsigned int offset; | |
2757 | ||
2758 | /* Generation marker. */ | |
2759 | unsigned int iter; | |
2760 | }; | |
65f38f15 AM |
2761 | |
2762 | struct ppc_link_hash_entry | |
2763 | { | |
2764 | struct elf_link_hash_entry elf; | |
2765 | ||
721956f4 AM |
2766 | /* A pointer to the most recently used stub hash entry against this |
2767 | symbol. */ | |
2768 | struct ppc_stub_hash_entry *stub_cache; | |
2769 | ||
65f38f15 AM |
2770 | /* Track dynamic relocs copied for this symbol. */ |
2771 | struct ppc_dyn_relocs *dyn_relocs; | |
e86ce104 | 2772 | |
721956f4 | 2773 | /* Link between function code and descriptor symbols. */ |
34814b9f | 2774 | struct ppc_link_hash_entry *oh; |
721956f4 | 2775 | |
e86ce104 AM |
2776 | /* Flag function code and descriptor symbols. */ |
2777 | unsigned int is_func:1; | |
2778 | unsigned int is_func_descriptor:1; | |
1e2f5b6e | 2779 | unsigned int is_entry:1; |
411e1bfb | 2780 | |
754021d0 AM |
2781 | /* Whether global opd sym has been adjusted or not. */ |
2782 | unsigned int adjust_done:1; | |
2783 | ||
411e1bfb | 2784 | /* Contexts in which symbol is used in the GOT (or TOC). |
e7b938ca AM |
2785 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
2786 | corresponding relocs are encountered during check_relocs. | |
2787 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2788 | indicate the corresponding GOT entry type is not needed. | |
2789 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into | |
2790 | a TPREL one. We use a separate flag rather than setting TPREL | |
2791 | just for convenience in distinguishing the two cases. */ | |
2792 | #define TLS_GD 1 /* GD reloc. */ | |
2793 | #define TLS_LD 2 /* LD reloc. */ | |
2794 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2795 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2796 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2797 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ | |
2798 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ | |
2799 | char tls_mask; | |
65f38f15 AM |
2800 | }; |
2801 | ||
2802 | /* ppc64 ELF linker hash table. */ | |
2803 | ||
2804 | struct ppc_link_hash_table | |
2805 | { | |
2806 | struct elf_link_hash_table elf; | |
2807 | ||
721956f4 AM |
2808 | /* The stub hash table. */ |
2809 | struct bfd_hash_table stub_hash_table; | |
2810 | ||
2811 | /* Another hash table for plt_branch stubs. */ | |
2812 | struct bfd_hash_table branch_hash_table; | |
2813 | ||
2814 | /* Linker stub bfd. */ | |
2815 | bfd *stub_bfd; | |
2816 | ||
2817 | /* Linker call-backs. */ | |
4ce794b7 AM |
2818 | asection * (*add_stub_section) (const char *, asection *); |
2819 | void (*layout_sections_again) (void); | |
721956f4 AM |
2820 | |
2821 | /* Array to keep track of which stub sections have been created, and | |
2822 | information on stub grouping. */ | |
2823 | struct map_stub { | |
2824 | /* This is the section to which stubs in the group will be attached. */ | |
2825 | asection *link_sec; | |
2826 | /* The stub section. */ | |
2827 | asection *stub_sec; | |
ad8e1ba5 AM |
2828 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
2829 | bfd_vma toc_off; | |
721956f4 AM |
2830 | } *stub_group; |
2831 | ||
ad8e1ba5 AM |
2832 | /* Support for multiple toc sections. */ |
2833 | unsigned int no_multi_toc; | |
2834 | unsigned int multi_toc_needed; | |
2835 | ||
2836 | /* Temp used when calculating TOC pointers. */ | |
2837 | bfd_vma toc_curr; | |
2838 | ||
8f3bab57 AM |
2839 | /* Highest input section id. */ |
2840 | int top_id; | |
2841 | ||
734b6cf9 AM |
2842 | /* Highest output section index. */ |
2843 | int top_index; | |
2844 | ||
2845 | /* List of input sections for each output section. */ | |
2846 | asection **input_list; | |
721956f4 | 2847 | |
65f38f15 | 2848 | /* Short-cuts to get to dynamic linker sections. */ |
4ce794b7 | 2849 | asection *got; |
4ce794b7 AM |
2850 | asection *plt; |
2851 | asection *relplt; | |
2852 | asection *dynbss; | |
2853 | asection *relbss; | |
2854 | asection *glink; | |
82bd7b59 | 2855 | asection *sfpr; |
4ce794b7 AM |
2856 | asection *brlt; |
2857 | asection *relbrlt; | |
ec338859 | 2858 | |
411e1bfb AM |
2859 | /* Shortcut to .__tls_get_addr. */ |
2860 | struct elf_link_hash_entry *tls_get_addr; | |
2861 | ||
9b5ecbd0 AM |
2862 | /* Statistics. */ |
2863 | unsigned long stub_count[ppc_stub_plt_call]; | |
2864 | ||
ad8e1ba5 AM |
2865 | /* Set if we should emit symbols for stubs. */ |
2866 | unsigned int emit_stub_syms; | |
2867 | ||
5d1634d7 | 2868 | /* Set on error. */ |
721956f4 AM |
2869 | unsigned int stub_error; |
2870 | ||
2871 | /* Flag set when small branches are detected. Used to | |
2872 | select suitable defaults for the stub group size. */ | |
2873 | unsigned int has_14bit_branch; | |
2874 | ||
2875 | /* Incremented every time we size stubs. */ | |
2876 | unsigned int stub_iteration; | |
5d1634d7 | 2877 | |
ec338859 AM |
2878 | /* Small local sym to section mapping cache. */ |
2879 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
2880 | }; |
2881 | ||
2882 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ | |
2883 | ||
2884 | #define ppc_hash_table(p) \ | |
2885 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
2886 | ||
721956f4 AM |
2887 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
2888 | ((struct ppc_stub_hash_entry *) \ | |
2889 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2890 | ||
2891 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
2892 | ((struct ppc_branch_hash_entry *) \ | |
2893 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2894 | ||
2895 | /* Create an entry in the stub hash table. */ | |
2896 | ||
2897 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2898 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2899 | struct bfd_hash_table *table, | |
2900 | const char *string) | |
721956f4 AM |
2901 | { |
2902 | /* Allocate the structure if it has not already been allocated by a | |
2903 | subclass. */ | |
2904 | if (entry == NULL) | |
2905 | { | |
2906 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
2907 | if (entry == NULL) | |
2908 | return entry; | |
2909 | } | |
2910 | ||
2911 | /* Call the allocation method of the superclass. */ | |
2912 | entry = bfd_hash_newfunc (entry, table, string); | |
2913 | if (entry != NULL) | |
2914 | { | |
2915 | struct ppc_stub_hash_entry *eh; | |
2916 | ||
2917 | /* Initialize the local fields. */ | |
2918 | eh = (struct ppc_stub_hash_entry *) entry; | |
ad8e1ba5 | 2919 | eh->stub_type = ppc_stub_none; |
721956f4 AM |
2920 | eh->stub_sec = NULL; |
2921 | eh->stub_offset = 0; | |
2922 | eh->target_value = 0; | |
2923 | eh->target_section = NULL; | |
721956f4 AM |
2924 | eh->h = NULL; |
2925 | eh->id_sec = NULL; | |
2926 | } | |
2927 | ||
2928 | return entry; | |
2929 | } | |
2930 | ||
2931 | /* Create an entry in the branch hash table. */ | |
2932 | ||
2933 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2934 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
2935 | struct bfd_hash_table *table, | |
2936 | const char *string) | |
721956f4 AM |
2937 | { |
2938 | /* Allocate the structure if it has not already been allocated by a | |
2939 | subclass. */ | |
2940 | if (entry == NULL) | |
2941 | { | |
2942 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); | |
2943 | if (entry == NULL) | |
2944 | return entry; | |
2945 | } | |
2946 | ||
2947 | /* Call the allocation method of the superclass. */ | |
2948 | entry = bfd_hash_newfunc (entry, table, string); | |
2949 | if (entry != NULL) | |
2950 | { | |
2951 | struct ppc_branch_hash_entry *eh; | |
2952 | ||
2953 | /* Initialize the local fields. */ | |
2954 | eh = (struct ppc_branch_hash_entry *) entry; | |
2955 | eh->offset = 0; | |
2956 | eh->iter = 0; | |
2957 | } | |
2958 | ||
2959 | return entry; | |
2960 | } | |
2961 | ||
65f38f15 AM |
2962 | /* Create an entry in a ppc64 ELF linker hash table. */ |
2963 | ||
2964 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2965 | link_hash_newfunc (struct bfd_hash_entry *entry, |
2966 | struct bfd_hash_table *table, | |
2967 | const char *string) | |
65f38f15 AM |
2968 | { |
2969 | /* Allocate the structure if it has not already been allocated by a | |
2970 | subclass. */ | |
2971 | if (entry == NULL) | |
2972 | { | |
2973 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
2974 | if (entry == NULL) | |
2975 | return entry; | |
2976 | } | |
2977 | ||
2978 | /* Call the allocation method of the superclass. */ | |
2979 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2980 | if (entry != NULL) | |
2981 | { | |
2982 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
2983 | ||
721956f4 | 2984 | eh->stub_cache = NULL; |
65f38f15 | 2985 | eh->dyn_relocs = NULL; |
721956f4 | 2986 | eh->oh = NULL; |
e86ce104 AM |
2987 | eh->is_func = 0; |
2988 | eh->is_func_descriptor = 0; | |
1e2f5b6e | 2989 | eh->is_entry = 0; |
754021d0 | 2990 | eh->adjust_done = 0; |
e7b938ca | 2991 | eh->tls_mask = 0; |
65f38f15 AM |
2992 | } |
2993 | ||
2994 | return entry; | |
2995 | } | |
2996 | ||
2997 | /* Create a ppc64 ELF linker hash table. */ | |
2998 | ||
2999 | static struct bfd_link_hash_table * | |
4ce794b7 | 3000 | ppc64_elf_link_hash_table_create (bfd *abfd) |
65f38f15 AM |
3001 | { |
3002 | struct ppc_link_hash_table *htab; | |
3003 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
3004 | ||
4ce794b7 | 3005 | htab = bfd_zmalloc (amt); |
65f38f15 AM |
3006 | if (htab == NULL) |
3007 | return NULL; | |
3008 | ||
3009 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
3010 | { | |
e2d34d7d | 3011 | free (htab); |
65f38f15 AM |
3012 | return NULL; |
3013 | } | |
3014 | ||
721956f4 AM |
3015 | /* Init the stub hash table too. */ |
3016 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) | |
3017 | return NULL; | |
3018 | ||
3019 | /* And the branch hash table. */ | |
3020 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) | |
3021 | return NULL; | |
3022 | ||
3254fd24 AM |
3023 | /* Initializing two fields of the union is just cosmetic. We really |
3024 | only care about glist, but when compiled on a 32-bit host the | |
3025 | bfd_vma fields are larger. Setting the bfd_vma to zero makes | |
3026 | debugger inspection of these fields look nicer. */ | |
3027 | htab->elf.init_refcount.refcount = 0; | |
3028 | htab->elf.init_refcount.glist = NULL; | |
3029 | htab->elf.init_offset.offset = 0; | |
3030 | htab->elf.init_offset.glist = NULL; | |
3031 | ||
65f38f15 AM |
3032 | return &htab->elf.root; |
3033 | } | |
3034 | ||
721956f4 AM |
3035 | /* Free the derived linker hash table. */ |
3036 | ||
3037 | static void | |
4ce794b7 | 3038 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
721956f4 AM |
3039 | { |
3040 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
3041 | ||
3042 | bfd_hash_table_free (&ret->stub_hash_table); | |
3043 | bfd_hash_table_free (&ret->branch_hash_table); | |
3044 | _bfd_generic_link_hash_table_free (hash); | |
3045 | } | |
3046 | ||
e717da7e AM |
3047 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
3048 | ||
3049 | void | |
3050 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
3051 | { | |
3052 | struct ppc_link_hash_table *htab; | |
3053 | ||
3054 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; | |
3055 | ||
3056 | /* Always hook our dynamic sections into the first bfd, which is the | |
3057 | linker created stub bfd. This ensures that the GOT header is at | |
3058 | the start of the output TOC section. */ | |
3059 | htab = ppc_hash_table (info); | |
3060 | htab->stub_bfd = abfd; | |
3061 | htab->elf.dynobj = abfd; | |
3062 | } | |
3063 | ||
721956f4 AM |
3064 | /* Build a name for an entry in the stub hash table. */ |
3065 | ||
3066 | static char * | |
4ce794b7 AM |
3067 | ppc_stub_name (const asection *input_section, |
3068 | const asection *sym_sec, | |
3069 | const struct ppc_link_hash_entry *h, | |
3070 | const Elf_Internal_Rela *rel) | |
721956f4 AM |
3071 | { |
3072 | char *stub_name; | |
3073 | bfd_size_type len; | |
3074 | ||
3075 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
3076 | offsets from a sym as a branch target? In fact, we could | |
3077 | probably assume the addend is always zero. */ | |
3078 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
3079 | ||
3080 | if (h) | |
3081 | { | |
3082 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
3083 | stub_name = bfd_malloc (len); | |
3084 | if (stub_name != NULL) | |
3085 | { | |
97b639ba | 3086 | sprintf (stub_name, "%08x.%s+%x", |
721956f4 AM |
3087 | input_section->id & 0xffffffff, |
3088 | h->elf.root.root.string, | |
3089 | (int) rel->r_addend & 0xffffffff); | |
3090 | } | |
3091 | } | |
3092 | else | |
3093 | { | |
ad8e1ba5 | 3094 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
721956f4 AM |
3095 | stub_name = bfd_malloc (len); |
3096 | if (stub_name != NULL) | |
3097 | { | |
97b639ba | 3098 | sprintf (stub_name, "%08x.%x:%x+%x", |
721956f4 AM |
3099 | input_section->id & 0xffffffff, |
3100 | sym_sec->id & 0xffffffff, | |
3101 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
3102 | (int) rel->r_addend & 0xffffffff); | |
3103 | } | |
3104 | } | |
3105 | return stub_name; | |
3106 | } | |
3107 | ||
3108 | /* Look up an entry in the stub hash. Stub entries are cached because | |
3109 | creating the stub name takes a bit of time. */ | |
3110 | ||
3111 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3112 | ppc_get_stub_entry (const asection *input_section, |
3113 | const asection *sym_sec, | |
3114 | struct elf_link_hash_entry *hash, | |
3115 | const Elf_Internal_Rela *rel, | |
3116 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3117 | { |
3118 | struct ppc_stub_hash_entry *stub_entry; | |
3119 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; | |
3120 | const asection *id_sec; | |
3121 | ||
3122 | /* If this input section is part of a group of sections sharing one | |
3123 | stub section, then use the id of the first section in the group. | |
3124 | Stub names need to include a section id, as there may well be | |
3125 | more than one stub used to reach say, printf, and we need to | |
3126 | distinguish between them. */ | |
3127 | id_sec = htab->stub_group[input_section->id].link_sec; | |
3128 | ||
3129 | if (h != NULL && h->stub_cache != NULL | |
3130 | && h->stub_cache->h == h | |
3131 | && h->stub_cache->id_sec == id_sec) | |
3132 | { | |
3133 | stub_entry = h->stub_cache; | |
3134 | } | |
3135 | else | |
3136 | { | |
3137 | char *stub_name; | |
3138 | ||
3139 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
3140 | if (stub_name == NULL) | |
3141 | return NULL; | |
3142 | ||
3143 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 3144 | stub_name, FALSE, FALSE); |
721956f4 AM |
3145 | if (h != NULL) |
3146 | h->stub_cache = stub_entry; | |
3147 | ||
3148 | free (stub_name); | |
3149 | } | |
3150 | ||
3151 | return stub_entry; | |
3152 | } | |
3153 | ||
3154 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
3155 | stub entry are initialised. */ | |
3156 | ||
3157 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3158 | ppc_add_stub (const char *stub_name, |
3159 | asection *section, | |
3160 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3161 | { |
3162 | asection *link_sec; | |
3163 | asection *stub_sec; | |
3164 | struct ppc_stub_hash_entry *stub_entry; | |
3165 | ||
3166 | link_sec = htab->stub_group[section->id].link_sec; | |
3167 | stub_sec = htab->stub_group[section->id].stub_sec; | |
3168 | if (stub_sec == NULL) | |
3169 | { | |
3170 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
3171 | if (stub_sec == NULL) | |
3172 | { | |
d4c88bbb | 3173 | size_t namelen; |
721956f4 AM |
3174 | bfd_size_type len; |
3175 | char *s_name; | |
3176 | ||
d4c88bbb AM |
3177 | namelen = strlen (link_sec->name); |
3178 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
3179 | s_name = bfd_alloc (htab->stub_bfd, len); |
3180 | if (s_name == NULL) | |
3181 | return NULL; | |
3182 | ||
d4c88bbb AM |
3183 | memcpy (s_name, link_sec->name, namelen); |
3184 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
3185 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
3186 | if (stub_sec == NULL) | |
3187 | return NULL; | |
3188 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
3189 | } | |
3190 | htab->stub_group[section->id].stub_sec = stub_sec; | |
3191 | } | |
3192 | ||
3193 | /* Enter this entry into the linker stub hash table. */ | |
3194 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 3195 | TRUE, FALSE); |
721956f4 AM |
3196 | if (stub_entry == NULL) |
3197 | { | |
3198 | (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), | |
3199 | bfd_archive_filename (section->owner), | |
3200 | stub_name); | |
3201 | return NULL; | |
3202 | } | |
3203 | ||
3204 | stub_entry->stub_sec = stub_sec; | |
3205 | stub_entry->stub_offset = 0; | |
3206 | stub_entry->id_sec = link_sec; | |
3207 | return stub_entry; | |
3208 | } | |
3209 | ||
82bd7b59 AM |
3210 | /* Create sections for linker generated code. */ |
3211 | ||
b34976b6 | 3212 | static bfd_boolean |
4ce794b7 | 3213 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
82bd7b59 AM |
3214 | { |
3215 | struct ppc_link_hash_table *htab; | |
3216 | flagword flags; | |
3217 | ||
3218 | htab = ppc_hash_table (info); | |
3219 | ||
3220 | /* Create .sfpr for code to save and restore fp regs. */ | |
3221 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
3222 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
721956f4 | 3223 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
82bd7b59 AM |
3224 | if (htab->sfpr == NULL |
3225 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) | |
3226 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) | |
b34976b6 | 3227 | return FALSE; |
82bd7b59 | 3228 | |
721956f4 | 3229 | /* Create .glink for lazy dynamic linking support. */ |
4ce794b7 AM |
3230 | htab->glink = bfd_make_section_anyway (dynobj, ".glink"); |
3231 | if (htab->glink == NULL | |
3232 | || ! bfd_set_section_flags (dynobj, htab->glink, flags) | |
3233 | || ! bfd_set_section_alignment (dynobj, htab->glink, 2)) | |
b34976b6 | 3234 | return FALSE; |
82bd7b59 | 3235 | |
721956f4 AM |
3236 | /* Create .branch_lt for plt_branch stubs. */ |
3237 | flags = (SEC_ALLOC | SEC_LOAD | |
3238 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3239 | htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt"); |
3240 | if (htab->brlt == NULL | |
3241 | || ! bfd_set_section_flags (dynobj, htab->brlt, flags) | |
3242 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) | |
b34976b6 | 3243 | return FALSE; |
721956f4 AM |
3244 | |
3245 | if (info->shared) | |
3246 | { | |
3247 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
3248 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3249 | htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
3250 | if (!htab->relbrlt | |
3251 | || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags) | |
3252 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) | |
b34976b6 | 3253 | return FALSE; |
721956f4 | 3254 | } |
b34976b6 | 3255 | return TRUE; |
82bd7b59 AM |
3256 | } |
3257 | ||
e717da7e AM |
3258 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
3259 | not already done. */ | |
65f38f15 | 3260 | |
b34976b6 | 3261 | static bfd_boolean |
e717da7e | 3262 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
65f38f15 | 3263 | { |
e717da7e AM |
3264 | asection *got, *relgot; |
3265 | flagword flags; | |
3266 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
65f38f15 | 3267 | |
4ce794b7 | 3268 | if (!htab->got) |
e717da7e AM |
3269 | { |
3270 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) | |
3271 | return FALSE; | |
3272 | ||
3273 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); | |
3274 | if (!htab->got) | |
3275 | abort (); | |
3276 | } | |
3277 | ||
3278 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3279 | | SEC_LINKER_CREATED); | |
3280 | ||
3281 | got = bfd_make_section (abfd, ".got"); | |
3282 | if (!got | |
3283 | || !bfd_set_section_flags (abfd, got, flags) | |
3284 | || !bfd_set_section_alignment (abfd, got, 3)) | |
3285 | return FALSE; | |
65f38f15 | 3286 | |
e717da7e AM |
3287 | relgot = bfd_make_section (abfd, ".rela.got"); |
3288 | if (!relgot | |
3289 | || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY) | |
3290 | || ! bfd_set_section_alignment (abfd, relgot, 3)) | |
b34976b6 | 3291 | return FALSE; |
e717da7e AM |
3292 | |
3293 | ppc64_elf_tdata (abfd)->got = got; | |
3294 | ppc64_elf_tdata (abfd)->relgot = relgot; | |
b34976b6 | 3295 | return TRUE; |
65f38f15 | 3296 | } |
5bd4f169 | 3297 | |
82bd7b59 | 3298 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 3299 | |
b34976b6 | 3300 | static bfd_boolean |
4ce794b7 | 3301 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5bd4f169 | 3302 | { |
65f38f15 | 3303 | struct ppc_link_hash_table *htab; |
5bd4f169 | 3304 | |
65f38f15 | 3305 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 3306 | return FALSE; |
65f38f15 | 3307 | |
e717da7e AM |
3308 | htab = ppc_hash_table (info); |
3309 | if (!htab->got) | |
3310 | htab->got = bfd_get_section_by_name (dynobj, ".got"); | |
4ce794b7 AM |
3311 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
3312 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3313 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
65f38f15 | 3314 | if (!info->shared) |
4ce794b7 | 3315 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
65f38f15 | 3316 | |
e717da7e | 3317 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
4ce794b7 | 3318 | || (!info->shared && !htab->relbss)) |
65f38f15 AM |
3319 | abort (); |
3320 | ||
b34976b6 | 3321 | return TRUE; |
5bd4f169 AM |
3322 | } |
3323 | ||
65f38f15 AM |
3324 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
3325 | ||
3326 | static void | |
9c5bfbb7 AM |
3327 | ppc64_elf_copy_indirect_symbol |
3328 | (const struct elf_backend_data *bed ATTRIBUTE_UNUSED, | |
3329 | struct elf_link_hash_entry *dir, | |
3330 | struct elf_link_hash_entry *ind) | |
65f38f15 AM |
3331 | { |
3332 | struct ppc_link_hash_entry *edir, *eind; | |
81848ca0 | 3333 | flagword mask; |
65f38f15 AM |
3334 | |
3335 | edir = (struct ppc_link_hash_entry *) dir; | |
3336 | eind = (struct ppc_link_hash_entry *) ind; | |
3337 | ||
411e1bfb | 3338 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
bbd7ec4a | 3339 | if (eind->dyn_relocs != NULL) |
65f38f15 | 3340 | { |
bbd7ec4a AM |
3341 | if (edir->dyn_relocs != NULL) |
3342 | { | |
3343 | struct ppc_dyn_relocs **pp; | |
3344 | struct ppc_dyn_relocs *p; | |
3345 | ||
411e1bfb | 3346 | if (eind->elf.root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
3347 | abort (); |
3348 | ||
3349 | /* Add reloc counts against the weak sym to the strong sym | |
3350 | list. Merge any entries against the same section. */ | |
3351 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3352 | { | |
3353 | struct ppc_dyn_relocs *q; | |
3354 | ||
3355 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3356 | if (q->sec == p->sec) | |
3357 | { | |
3358 | q->pc_count += p->pc_count; | |
3359 | q->count += p->count; | |
3360 | *pp = p->next; | |
3361 | break; | |
3362 | } | |
3363 | if (q == NULL) | |
3364 | pp = &p->next; | |
3365 | } | |
3366 | *pp = edir->dyn_relocs; | |
3367 | } | |
3368 | ||
65f38f15 AM |
3369 | edir->dyn_relocs = eind->dyn_relocs; |
3370 | eind->dyn_relocs = NULL; | |
3371 | } | |
65f38f15 | 3372 | |
6349e628 AM |
3373 | edir->is_func |= eind->is_func; |
3374 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
3375 | edir->is_entry |= eind->is_entry; | |
58ac9f71 | 3376 | edir->tls_mask |= eind->tls_mask; |
6349e628 | 3377 | |
81848ca0 | 3378 | mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR |
3addb0a9 DJ |
3379 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF |
3380 | | ELF_LINK_HASH_NEEDS_PLT); | |
81848ca0 AM |
3381 | /* If called to transfer flags for a weakdef during processing |
3382 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. | |
3383 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3384 | if (ELIMINATE_COPY_RELOCS | |
3385 | && eind->elf.root.type != bfd_link_hash_indirect | |
3386 | && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) | |
3387 | mask &= ~ELF_LINK_NON_GOT_REF; | |
3388 | ||
3389 | edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask; | |
6349e628 AM |
3390 | |
3391 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3392 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3393 | return; | |
3394 | ||
81848ca0 AM |
3395 | /* Copy over got entries that we may have already seen to the |
3396 | symbol which just became indirect. */ | |
411e1bfb AM |
3397 | if (eind->elf.got.glist != NULL) |
3398 | { | |
3399 | if (edir->elf.got.glist != NULL) | |
3400 | { | |
3401 | struct got_entry **entp; | |
3402 | struct got_entry *ent; | |
3403 | ||
3404 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) | |
3405 | { | |
3406 | struct got_entry *dent; | |
3407 | ||
3408 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) | |
3409 | if (dent->addend == ent->addend | |
e717da7e | 3410 | && dent->owner == ent->owner |
411e1bfb AM |
3411 | && dent->tls_type == ent->tls_type) |
3412 | { | |
3413 | dent->got.refcount += ent->got.refcount; | |
3414 | *entp = ent->next; | |
3415 | break; | |
3416 | } | |
3417 | if (dent == NULL) | |
3418 | entp = &ent->next; | |
3419 | } | |
3420 | *entp = edir->elf.got.glist; | |
3421 | } | |
3422 | ||
3423 | edir->elf.got.glist = eind->elf.got.glist; | |
3424 | eind->elf.got.glist = NULL; | |
3425 | } | |
3426 | ||
3427 | /* And plt entries. */ | |
3428 | if (eind->elf.plt.plist != NULL) | |
3429 | { | |
3430 | if (edir->elf.plt.plist != NULL) | |
3431 | { | |
3432 | struct plt_entry **entp; | |
3433 | struct plt_entry *ent; | |
3434 | ||
3435 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3436 | { | |
3437 | struct plt_entry *dent; | |
3438 | ||
3439 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3440 | if (dent->addend == ent->addend) | |
3441 | { | |
3442 | dent->plt.refcount += ent->plt.refcount; | |
3443 | *entp = ent->next; | |
3444 | break; | |
3445 | } | |
3446 | if (dent == NULL) | |
3447 | entp = &ent->next; | |
3448 | } | |
3449 | *entp = edir->elf.plt.plist; | |
3450 | } | |
3451 | ||
3452 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3453 | eind->elf.plt.plist = NULL; | |
3454 | } | |
3455 | ||
411e1bfb AM |
3456 | if (edir->elf.dynindx == -1) |
3457 | { | |
3458 | edir->elf.dynindx = eind->elf.dynindx; | |
3459 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3460 | eind->elf.dynindx = -1; | |
3461 | eind->elf.dynstr_index = 0; | |
3462 | } | |
3463 | else | |
3464 | BFD_ASSERT (eind->elf.dynindx == -1); | |
3465 | } | |
3466 | ||
3467 | /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and | |
3468 | symbols undefined on the command-line. */ | |
3469 | ||
3470 | bfd_boolean | |
4ce794b7 | 3471 | ppc64_elf_mark_entry_syms (struct bfd_link_info *info) |
411e1bfb AM |
3472 | { |
3473 | struct ppc_link_hash_table *htab; | |
3474 | struct bfd_sym_chain *sym; | |
3475 | ||
3476 | htab = ppc_hash_table (info); | |
3477 | for (sym = info->gc_sym_list; sym; sym = sym->next) | |
3478 | { | |
3479 | struct elf_link_hash_entry *h; | |
3480 | ||
3481 | h = elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); | |
3482 | if (h != NULL) | |
3483 | ((struct ppc_link_hash_entry *) h)->is_entry = 1; | |
3484 | } | |
3485 | return TRUE; | |
3486 | } | |
3487 | ||
555cd476 AM |
3488 | /* Hack symbols defined in .opd sections to be function type. */ |
3489 | ||
3490 | static bfd_boolean | |
3491 | ppc64_elf_add_symbol_hook (bfd *ibfd ATTRIBUTE_UNUSED, | |
3492 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
3493 | Elf_Internal_Sym *isym, | |
3494 | const char **name ATTRIBUTE_UNUSED, | |
3495 | flagword *flags ATTRIBUTE_UNUSED, | |
3496 | asection **sec, | |
3497 | bfd_vma *value ATTRIBUTE_UNUSED) | |
3498 | { | |
3499 | if (strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0) | |
3500 | isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC); | |
3501 | return TRUE; | |
3502 | } | |
3503 | ||
411e1bfb | 3504 | static bfd_boolean |
4ce794b7 AM |
3505 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
3506 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) | |
411e1bfb AM |
3507 | { |
3508 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); | |
e7b938ca | 3509 | char *local_got_tls_masks; |
411e1bfb AM |
3510 | |
3511 | if (local_got_ents == NULL) | |
3512 | { | |
3513 | bfd_size_type size = symtab_hdr->sh_info; | |
3514 | ||
e7b938ca | 3515 | size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks); |
4ce794b7 | 3516 | local_got_ents = bfd_zalloc (abfd, size); |
411e1bfb AM |
3517 | if (local_got_ents == NULL) |
3518 | return FALSE; | |
3519 | elf_local_got_ents (abfd) = local_got_ents; | |
3520 | } | |
3521 | ||
3522 | if ((tls_type & TLS_EXPLICIT) == 0) | |
3523 | { | |
3524 | struct got_entry *ent; | |
3525 | ||
3526 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) | |
e717da7e AM |
3527 | if (ent->addend == r_addend |
3528 | && ent->owner == abfd | |
3529 | && ent->tls_type == tls_type) | |
411e1bfb AM |
3530 | break; |
3531 | if (ent == NULL) | |
3532 | { | |
3533 | bfd_size_type amt = sizeof (*ent); | |
4ce794b7 | 3534 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3535 | if (ent == NULL) |
3536 | return FALSE; | |
3537 | ent->next = local_got_ents[r_symndx]; | |
3538 | ent->addend = r_addend; | |
e717da7e | 3539 | ent->owner = abfd; |
411e1bfb AM |
3540 | ent->tls_type = tls_type; |
3541 | ent->got.refcount = 0; | |
3542 | local_got_ents[r_symndx] = ent; | |
3543 | } | |
3544 | ent->got.refcount += 1; | |
3545 | } | |
3546 | ||
e7b938ca AM |
3547 | local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
3548 | local_got_tls_masks[r_symndx] |= tls_type; | |
411e1bfb | 3549 | return TRUE; |
65f38f15 AM |
3550 | } |
3551 | ||
411e1bfb | 3552 | static bfd_boolean |
4ce794b7 | 3553 | update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend) |
1e2f5b6e | 3554 | { |
411e1bfb | 3555 | struct plt_entry *ent; |
1e2f5b6e | 3556 | |
411e1bfb AM |
3557 | for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next) |
3558 | if (ent->addend == addend) | |
3559 | break; | |
3560 | if (ent == NULL) | |
1e2f5b6e | 3561 | { |
411e1bfb | 3562 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3563 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3564 | if (ent == NULL) |
3565 | return FALSE; | |
3566 | ent->next = eh->elf.plt.plist; | |
3567 | ent->addend = addend; | |
3568 | ent->plt.refcount = 0; | |
3569 | eh->elf.plt.plist = ent; | |
1e2f5b6e | 3570 | } |
411e1bfb AM |
3571 | ent->plt.refcount += 1; |
3572 | eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3573 | eh->is_func = 1; | |
b34976b6 | 3574 | return TRUE; |
1e2f5b6e AM |
3575 | } |
3576 | ||
50bc7936 AM |
3577 | /* Find the function descriptor hash entry from the given function code |
3578 | hash entry FH. Link the entries via their OH fields. */ | |
3579 | static struct ppc_link_hash_entry * | |
3580 | get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) | |
3581 | { | |
34814b9f | 3582 | struct ppc_link_hash_entry *fdh = fh->oh; |
50bc7936 AM |
3583 | |
3584 | if (fdh == NULL) | |
3585 | { | |
3586 | const char *fd_name = fh->elf.root.root.string + 1; | |
3587 | ||
3588 | fdh = (struct ppc_link_hash_entry *) | |
3589 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); | |
3590 | if (fdh != NULL) | |
3591 | { | |
3592 | fdh->is_func_descriptor = 1; | |
34814b9f | 3593 | fdh->oh = fh; |
50bc7936 | 3594 | fh->is_func = 1; |
34814b9f | 3595 | fh->oh = fdh; |
50bc7936 AM |
3596 | } |
3597 | } | |
3598 | ||
3599 | return fdh; | |
3600 | } | |
3601 | ||
5bd4f169 | 3602 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 3603 | calculate needed space in the global offset table, procedure |
5d1634d7 | 3604 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 3605 | |
b34976b6 | 3606 | static bfd_boolean |
4ce794b7 AM |
3607 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
3608 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 3609 | { |
65f38f15 | 3610 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3611 | Elf_Internal_Shdr *symtab_hdr; |
3612 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
3613 | const Elf_Internal_Rela *rel; | |
3614 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 3615 | asection *sreloc; |
1e2f5b6e | 3616 | asection **opd_sym_map; |
5bd4f169 | 3617 | |
1049f94e | 3618 | if (info->relocatable) |
b34976b6 | 3619 | return TRUE; |
5bd4f169 | 3620 | |
680a3378 AM |
3621 | /* Don't do anything special with non-loaded, non-alloced sections. |
3622 | In particular, any relocs in such sections should not affect GOT | |
3623 | and PLT reference counting (ie. we don't allow them to create GOT | |
3624 | or PLT entries), there's no possibility or desire to optimize TLS | |
3625 | relocs, and there's not much point in propagating relocs to shared | |
3626 | libs that the dynamic linker won't relocate. */ | |
3627 | if ((sec->flags & SEC_ALLOC) == 0) | |
3628 | return TRUE; | |
3629 | ||
65f38f15 | 3630 | htab = ppc_hash_table (info); |
5bd4f169 | 3631 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
3632 | |
3633 | sym_hashes = elf_sym_hashes (abfd); | |
3634 | sym_hashes_end = (sym_hashes | |
1e2f5b6e AM |
3635 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
3636 | - symtab_hdr->sh_info); | |
5bd4f169 AM |
3637 | |
3638 | sreloc = NULL; | |
1e2f5b6e AM |
3639 | opd_sym_map = NULL; |
3640 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
3641 | { | |
3642 | /* Garbage collection needs some extra help with .opd sections. | |
3643 | We don't want to necessarily keep everything referenced by | |
3644 | relocs in .opd, as that would keep all functions. Instead, | |
3645 | if we reference an .opd symbol (a function descriptor), we | |
3646 | want to keep the function code symbol's section. This is | |
3647 | easy for global symbols, but for local syms we need to keep | |
3648 | information about the associated function section. Later, if | |
3649 | edit_opd deletes entries, we'll use this array to adjust | |
3650 | local syms in .opd. */ | |
3651 | union opd_info { | |
3652 | asection *func_section; | |
3653 | long entry_adjust; | |
3654 | }; | |
3655 | bfd_size_type amt; | |
3656 | ||
eea6121a | 3657 | amt = sec->size * sizeof (union opd_info) / 24; |
4ce794b7 | 3658 | opd_sym_map = bfd_zalloc (abfd, amt); |
1e2f5b6e | 3659 | if (opd_sym_map == NULL) |
b34976b6 | 3660 | return FALSE; |
f0abc2a1 | 3661 | ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map; |
1e2f5b6e | 3662 | } |
5bd4f169 | 3663 | |
82bd7b59 AM |
3664 | if (htab->sfpr == NULL |
3665 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 3666 | return FALSE; |
82bd7b59 | 3667 | |
5bd4f169 AM |
3668 | rel_end = relocs + sec->reloc_count; |
3669 | for (rel = relocs; rel < rel_end; rel++) | |
3670 | { | |
3671 | unsigned long r_symndx; | |
3672 | struct elf_link_hash_entry *h; | |
04c9666a | 3673 | enum elf_ppc64_reloc_type r_type; |
411e1bfb | 3674 | int tls_type = 0; |
5bd4f169 AM |
3675 | |
3676 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3677 | if (r_symndx < symtab_hdr->sh_info) | |
3678 | h = NULL; | |
3679 | else | |
3680 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3681 | ||
4ce794b7 | 3682 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 3683 | switch (r_type) |
5bd4f169 | 3684 | { |
411e1bfb AM |
3685 | case R_PPC64_GOT_TLSLD16: |
3686 | case R_PPC64_GOT_TLSLD16_LO: | |
3687 | case R_PPC64_GOT_TLSLD16_HI: | |
3688 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 3689 | ppc64_tlsld_got (abfd)->refcount += 1; |
951fd09b | 3690 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
3691 | goto dogottls; |
3692 | ||
3693 | case R_PPC64_GOT_TLSGD16: | |
3694 | case R_PPC64_GOT_TLSGD16_LO: | |
3695 | case R_PPC64_GOT_TLSGD16_HI: | |
3696 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 3697 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
3698 | goto dogottls; |
3699 | ||
3700 | case R_PPC64_GOT_TPREL16_DS: | |
3701 | case R_PPC64_GOT_TPREL16_LO_DS: | |
3702 | case R_PPC64_GOT_TPREL16_HI: | |
3703 | case R_PPC64_GOT_TPREL16_HA: | |
3704 | if (info->shared) | |
3705 | info->flags |= DF_STATIC_TLS; | |
3706 | tls_type = TLS_TLS | TLS_TPREL; | |
3707 | goto dogottls; | |
3708 | ||
3709 | case R_PPC64_GOT_DTPREL16_DS: | |
3710 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
3711 | case R_PPC64_GOT_DTPREL16_HI: | |
3712 | case R_PPC64_GOT_DTPREL16_HA: | |
3713 | tls_type = TLS_TLS | TLS_DTPREL; | |
3714 | dogottls: | |
3715 | sec->has_tls_reloc = 1; | |
3716 | /* Fall thru */ | |
3717 | ||
5bd4f169 | 3718 | case R_PPC64_GOT16: |
5bd4f169 | 3719 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
3720 | case R_PPC64_GOT16_HA: |
3721 | case R_PPC64_GOT16_HI: | |
3722 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 3723 | case R_PPC64_GOT16_LO_DS: |
65f38f15 | 3724 | /* This symbol requires a global offset table entry. */ |
ad8e1ba5 | 3725 | sec->has_gp_reloc = 1; |
e717da7e AM |
3726 | if (ppc64_elf_tdata (abfd)->got == NULL |
3727 | && !create_got_section (abfd, info)) | |
b34976b6 | 3728 | return FALSE; |
5bd4f169 AM |
3729 | |
3730 | if (h != NULL) | |
3731 | { | |
411e1bfb AM |
3732 | struct ppc_link_hash_entry *eh; |
3733 | struct got_entry *ent; | |
65f38f15 | 3734 | |
411e1bfb AM |
3735 | eh = (struct ppc_link_hash_entry *) h; |
3736 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) | |
3737 | if (ent->addend == rel->r_addend | |
e717da7e | 3738 | && ent->owner == abfd |
411e1bfb AM |
3739 | && ent->tls_type == tls_type) |
3740 | break; | |
3741 | if (ent == NULL) | |
5bd4f169 | 3742 | { |
411e1bfb | 3743 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3744 | ent = bfd_alloc (abfd, amt); |
411e1bfb | 3745 | if (ent == NULL) |
b34976b6 | 3746 | return FALSE; |
411e1bfb AM |
3747 | ent->next = eh->elf.got.glist; |
3748 | ent->addend = rel->r_addend; | |
e717da7e | 3749 | ent->owner = abfd; |
411e1bfb AM |
3750 | ent->tls_type = tls_type; |
3751 | ent->got.refcount = 0; | |
3752 | eh->elf.got.glist = ent; | |
5bd4f169 | 3753 | } |
411e1bfb | 3754 | ent->got.refcount += 1; |
e7b938ca | 3755 | eh->tls_mask |= tls_type; |
5bd4f169 | 3756 | } |
411e1bfb AM |
3757 | else |
3758 | /* This is a global offset table entry for a local symbol. */ | |
3759 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3760 | rel->r_addend, tls_type)) | |
3761 | return FALSE; | |
5bd4f169 AM |
3762 | break; |
3763 | ||
5bd4f169 | 3764 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
3765 | case R_PPC64_PLT16_HI: |
3766 | case R_PPC64_PLT16_LO: | |
3767 | case R_PPC64_PLT32: | |
3768 | case R_PPC64_PLT64: | |
5bd4f169 | 3769 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
3770 | actually build the entry in adjust_dynamic_symbol, |
3771 | because this might be a case of linking PIC code without | |
3772 | linking in any dynamic objects, in which case we don't | |
3773 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
3774 | if (h == NULL) |
3775 | { | |
3776 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 3777 | table entry for a local symbol. */ |
5bd4f169 | 3778 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3779 | return FALSE; |
5bd4f169 | 3780 | } |
411e1bfb AM |
3781 | else |
3782 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, | |
3783 | rel->r_addend)) | |
3784 | return FALSE; | |
5bd4f169 AM |
3785 | break; |
3786 | ||
3787 | /* The following relocations don't need to propagate the | |
3788 | relocation if linking a shared object since they are | |
3789 | section relative. */ | |
3790 | case R_PPC64_SECTOFF: | |
3791 | case R_PPC64_SECTOFF_LO: | |
3792 | case R_PPC64_SECTOFF_HI: | |
3793 | case R_PPC64_SECTOFF_HA: | |
3794 | case R_PPC64_SECTOFF_DS: | |
3795 | case R_PPC64_SECTOFF_LO_DS: | |
411e1bfb AM |
3796 | case R_PPC64_DTPREL16: |
3797 | case R_PPC64_DTPREL16_LO: | |
3798 | case R_PPC64_DTPREL16_HI: | |
3799 | case R_PPC64_DTPREL16_HA: | |
3800 | case R_PPC64_DTPREL16_DS: | |
3801 | case R_PPC64_DTPREL16_LO_DS: | |
3802 | case R_PPC64_DTPREL16_HIGHER: | |
3803 | case R_PPC64_DTPREL16_HIGHERA: | |
3804 | case R_PPC64_DTPREL16_HIGHEST: | |
3805 | case R_PPC64_DTPREL16_HIGHESTA: | |
5bd4f169 AM |
3806 | break; |
3807 | ||
ad8e1ba5 AM |
3808 | /* Nor do these. */ |
3809 | case R_PPC64_TOC16: | |
3810 | case R_PPC64_TOC16_LO: | |
3811 | case R_PPC64_TOC16_HI: | |
3812 | case R_PPC64_TOC16_HA: | |
3813 | case R_PPC64_TOC16_DS: | |
3814 | case R_PPC64_TOC16_LO_DS: | |
3815 | sec->has_gp_reloc = 1; | |
3816 | break; | |
3817 | ||
5bd4f169 AM |
3818 | /* This relocation describes the C++ object vtable hierarchy. |
3819 | Reconstruct it for later use during GC. */ | |
3820 | case R_PPC64_GNU_VTINHERIT: | |
c152c796 | 3821 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 3822 | return FALSE; |
5bd4f169 AM |
3823 | break; |
3824 | ||
3825 | /* This relocation describes which C++ vtable entries are actually | |
3826 | used. Record for later use during GC. */ | |
3827 | case R_PPC64_GNU_VTENTRY: | |
c152c796 | 3828 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 3829 | return FALSE; |
5bd4f169 AM |
3830 | break; |
3831 | ||
721956f4 AM |
3832 | case R_PPC64_REL14: |
3833 | case R_PPC64_REL14_BRTAKEN: | |
3834 | case R_PPC64_REL14_BRNTAKEN: | |
3835 | htab->has_14bit_branch = 1; | |
3836 | /* Fall through. */ | |
3837 | ||
5d1634d7 | 3838 | case R_PPC64_REL24: |
e86ce104 AM |
3839 | if (h != NULL |
3840 | && h->root.root.string[0] == '.' | |
3841 | && h->root.root.string[1] != 0) | |
5d1634d7 AM |
3842 | { |
3843 | /* We may need a .plt entry if the function this reloc | |
3844 | refers to is in a shared lib. */ | |
411e1bfb AM |
3845 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
3846 | rel->r_addend)) | |
3847 | return FALSE; | |
3848 | if (h == htab->tls_get_addr) | |
3849 | sec->has_tls_reloc = 1; | |
a48ebf4d AM |
3850 | else if ((strncmp (h->root.root.string, ".__tls_get_addr", 15) |
3851 | == 0) | |
3852 | && (h->root.root.string[15] == 0 | |
3853 | || h->root.root.string[15] == '@')) | |
411e1bfb AM |
3854 | { |
3855 | htab->tls_get_addr = h; | |
3856 | sec->has_tls_reloc = 1; | |
3857 | } | |
3858 | } | |
3859 | break; | |
3860 | ||
3861 | case R_PPC64_TPREL64: | |
3862 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | |
3863 | if (info->shared) | |
3864 | info->flags |= DF_STATIC_TLS; | |
3865 | goto dotlstoc; | |
3866 | ||
3867 | case R_PPC64_DTPMOD64: | |
3868 | if (rel + 1 < rel_end | |
3869 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
3870 | && rel[1].r_offset == rel->r_offset + 8) | |
951fd09b | 3871 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
411e1bfb | 3872 | else |
951fd09b | 3873 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
411e1bfb AM |
3874 | goto dotlstoc; |
3875 | ||
3876 | case R_PPC64_DTPREL64: | |
3877 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; | |
3878 | if (rel != relocs | |
3879 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) | |
3880 | && rel[-1].r_offset == rel->r_offset - 8) | |
3881 | /* This is the second reloc of a dtpmod, dtprel pair. | |
3882 | Don't mark with TLS_DTPREL. */ | |
3883 | goto dodyn; | |
3884 | ||
3885 | dotlstoc: | |
3886 | sec->has_tls_reloc = 1; | |
3887 | if (h != NULL) | |
3888 | { | |
3889 | struct ppc_link_hash_entry *eh; | |
3890 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 3891 | eh->tls_mask |= tls_type; |
411e1bfb AM |
3892 | } |
3893 | else | |
3894 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3895 | rel->r_addend, tls_type)) | |
3896 | return FALSE; | |
3897 | ||
3898 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) | |
3899 | { | |
e7b938ca | 3900 | /* One extra to simplify get_tls_mask. */ |
eea6121a | 3901 | bfd_size_type amt = sec->size * sizeof (unsigned) / 8 + 1; |
4ce794b7 | 3902 | ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt); |
411e1bfb AM |
3903 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
3904 | return FALSE; | |
3905 | } | |
3906 | BFD_ASSERT (rel->r_offset % 8 == 0); | |
3907 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx; | |
951fd09b AM |
3908 | |
3909 | /* Mark the second slot of a GD or LD entry. | |
3910 | -1 to indicate GD and -2 to indicate LD. */ | |
3911 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | |
3912 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1; | |
3913 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) | |
3914 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2; | |
411e1bfb AM |
3915 | goto dodyn; |
3916 | ||
3917 | case R_PPC64_TPREL16: | |
3918 | case R_PPC64_TPREL16_LO: | |
3919 | case R_PPC64_TPREL16_HI: | |
3920 | case R_PPC64_TPREL16_HA: | |
3921 | case R_PPC64_TPREL16_DS: | |
3922 | case R_PPC64_TPREL16_LO_DS: | |
3923 | case R_PPC64_TPREL16_HIGHER: | |
3924 | case R_PPC64_TPREL16_HIGHERA: | |
3925 | case R_PPC64_TPREL16_HIGHEST: | |
3926 | case R_PPC64_TPREL16_HIGHESTA: | |
3927 | if (info->shared) | |
3928 | { | |
3929 | info->flags |= DF_STATIC_TLS; | |
3930 | goto dodyn; | |
5d1634d7 AM |
3931 | } |
3932 | break; | |
3933 | ||
e86ce104 | 3934 | case R_PPC64_ADDR64: |
1e2f5b6e | 3935 | if (opd_sym_map != NULL |
e86ce104 AM |
3936 | && h != NULL |
3937 | && h->root.root.string[0] == '.' | |
3938 | && h->root.root.string[1] != 0) | |
50bc7936 | 3939 | get_fdh ((struct ppc_link_hash_entry *) h, htab); |
e86ce104 | 3940 | |
1e2f5b6e AM |
3941 | if (opd_sym_map != NULL |
3942 | && h == NULL | |
3943 | && rel + 1 < rel_end | |
4ce794b7 | 3944 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
1e2f5b6e AM |
3945 | { |
3946 | asection *s; | |
3947 | ||
3948 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, | |
3949 | r_symndx); | |
3950 | if (s == NULL) | |
b34976b6 | 3951 | return FALSE; |
1e2f5b6e AM |
3952 | else if (s != sec) |
3953 | opd_sym_map[rel->r_offset / 24] = s; | |
3954 | } | |
e86ce104 AM |
3955 | /* Fall through. */ |
3956 | ||
04c9666a | 3957 | case R_PPC64_REL30: |
5bd4f169 | 3958 | case R_PPC64_REL32: |
04c9666a | 3959 | case R_PPC64_REL64: |
65f38f15 AM |
3960 | case R_PPC64_ADDR14: |
3961 | case R_PPC64_ADDR14_BRNTAKEN: | |
3962 | case R_PPC64_ADDR14_BRTAKEN: | |
3963 | case R_PPC64_ADDR16: | |
3964 | case R_PPC64_ADDR16_DS: | |
3965 | case R_PPC64_ADDR16_HA: | |
3966 | case R_PPC64_ADDR16_HI: | |
3967 | case R_PPC64_ADDR16_HIGHER: | |
3968 | case R_PPC64_ADDR16_HIGHERA: | |
3969 | case R_PPC64_ADDR16_HIGHEST: | |
3970 | case R_PPC64_ADDR16_HIGHESTA: | |
3971 | case R_PPC64_ADDR16_LO: | |
3972 | case R_PPC64_ADDR16_LO_DS: | |
3973 | case R_PPC64_ADDR24: | |
65f38f15 | 3974 | case R_PPC64_ADDR32: |
65f38f15 AM |
3975 | case R_PPC64_UADDR16: |
3976 | case R_PPC64_UADDR32: | |
3977 | case R_PPC64_UADDR64: | |
5bd4f169 | 3978 | case R_PPC64_TOC: |
81848ca0 AM |
3979 | if (h != NULL && !info->shared) |
3980 | /* We may need a copy reloc. */ | |
3981 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
3982 | ||
41bd81ab | 3983 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 3984 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 3985 | break; |
e86ce104 | 3986 | |
65f38f15 AM |
3987 | /* If we are creating a shared library, and this is a reloc |
3988 | against a global symbol, or a non PC relative reloc | |
3989 | against a local symbol, then we need to copy the reloc | |
3990 | into the shared library. However, if we are linking with | |
3991 | -Bsymbolic, we do not need to copy a reloc against a | |
3992 | global symbol which is defined in an object we are | |
3993 | including in the link (i.e., DEF_REGULAR is set). At | |
3994 | this point we have not seen all the input files, so it is | |
3995 | possible that DEF_REGULAR is not set now but will be set | |
3996 | later (it is never cleared). In case of a weak definition, | |
3997 | DEF_REGULAR may be cleared later by a strong definition in | |
3998 | a shared library. We account for that possibility below by | |
f4656909 | 3999 | storing information in the dyn_relocs field of the hash |
65f38f15 AM |
4000 | table entry. A similar situation occurs when creating |
4001 | shared libraries and symbol visibility changes render the | |
4002 | symbol local. | |
4003 | ||
4004 | If on the other hand, we are creating an executable, we | |
4005 | may need to keep relocations for symbols satisfied by a | |
4006 | dynamic library if we manage to avoid copy relocs for the | |
4007 | symbol. */ | |
411e1bfb | 4008 | dodyn: |
65f38f15 | 4009 | if ((info->shared |
411e1bfb | 4010 | && (MUST_BE_DYN_RELOC (r_type) |
65f38f15 AM |
4011 | || (h != NULL |
4012 | && (! info->symbolic | |
4013 | || h->root.type == bfd_link_hash_defweak | |
4014 | || (h->elf_link_hash_flags | |
4015 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
f4656909 AM |
4016 | || (ELIMINATE_COPY_RELOCS |
4017 | && !info->shared | |
65f38f15 AM |
4018 | && h != NULL |
4019 | && (h->root.type == bfd_link_hash_defweak | |
4020 | || (h->elf_link_hash_flags | |
4021 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 4022 | { |
ec338859 AM |
4023 | struct ppc_dyn_relocs *p; |
4024 | struct ppc_dyn_relocs **head; | |
4025 | ||
65f38f15 AM |
4026 | /* We must copy these reloc types into the output file. |
4027 | Create a reloc section in dynobj and make room for | |
4028 | this reloc. */ | |
5bd4f169 AM |
4029 | if (sreloc == NULL) |
4030 | { | |
4031 | const char *name; | |
65f38f15 | 4032 | bfd *dynobj; |
5bd4f169 AM |
4033 | |
4034 | name = (bfd_elf_string_from_elf_section | |
4035 | (abfd, | |
4036 | elf_elfheader (abfd)->e_shstrndx, | |
4037 | elf_section_data (sec)->rel_hdr.sh_name)); | |
4038 | if (name == NULL) | |
b34976b6 | 4039 | return FALSE; |
5bd4f169 | 4040 | |
65f38f15 AM |
4041 | if (strncmp (name, ".rela", 5) != 0 |
4042 | || strcmp (bfd_get_section_name (abfd, sec), | |
4043 | name + 5) != 0) | |
4044 | { | |
4045 | (*_bfd_error_handler) | |
4046 | (_("%s: bad relocation section name `%s\'"), | |
4047 | bfd_archive_filename (abfd), name); | |
5d1634d7 | 4048 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
4049 | } |
4050 | ||
65f38f15 | 4051 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
4052 | sreloc = bfd_get_section_by_name (dynobj, name); |
4053 | if (sreloc == NULL) | |
4054 | { | |
4055 | flagword flags; | |
4056 | ||
4057 | sreloc = bfd_make_section (dynobj, name); | |
4058 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
4059 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4060 | if ((sec->flags & SEC_ALLOC) != 0) | |
4061 | flags |= SEC_ALLOC | SEC_LOAD; | |
4062 | if (sreloc == NULL | |
4063 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 4064 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
b34976b6 | 4065 | return FALSE; |
5bd4f169 | 4066 | } |
65f38f15 | 4067 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
4068 | } |
4069 | ||
65f38f15 AM |
4070 | /* If this is a global symbol, we count the number of |
4071 | relocations we need for this symbol. */ | |
4072 | if (h != NULL) | |
4073 | { | |
ec338859 | 4074 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
4075 | } |
4076 | else | |
4077 | { | |
ec338859 AM |
4078 | /* Track dynamic relocs needed for local syms too. |
4079 | We really need local syms available to do this | |
4080 | easily. Oh well. */ | |
4081 | ||
4082 | asection *s; | |
4083 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
4084 | sec, r_symndx); | |
4085 | if (s == NULL) | |
b34976b6 | 4086 | return FALSE; |
ec338859 AM |
4087 | |
4088 | head = ((struct ppc_dyn_relocs **) | |
4089 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 4090 | } |
ec338859 AM |
4091 | |
4092 | p = *head; | |
4093 | if (p == NULL || p->sec != sec) | |
4094 | { | |
4ce794b7 | 4095 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
ec338859 | 4096 | if (p == NULL) |
b34976b6 | 4097 | return FALSE; |
ec338859 AM |
4098 | p->next = *head; |
4099 | *head = p; | |
4100 | p->sec = sec; | |
4101 | p->count = 0; | |
4102 | p->pc_count = 0; | |
4103 | } | |
4104 | ||
4105 | p->count += 1; | |
411e1bfb | 4106 | if (!MUST_BE_DYN_RELOC (r_type)) |
ec338859 | 4107 | p->pc_count += 1; |
65f38f15 | 4108 | } |
5bd4f169 | 4109 | break; |
65f38f15 AM |
4110 | |
4111 | default: | |
96e0dda4 | 4112 | break; |
5bd4f169 AM |
4113 | } |
4114 | } | |
4115 | ||
b34976b6 | 4116 | return TRUE; |
5bd4f169 AM |
4117 | } |
4118 | ||
4119 | /* Return the section that should be marked against GC for a given | |
4120 | relocation. */ | |
4121 | ||
4122 | static asection * | |
4ce794b7 AM |
4123 | ppc64_elf_gc_mark_hook (asection *sec, |
4124 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
4125 | Elf_Internal_Rela *rel, | |
4126 | struct elf_link_hash_entry *h, | |
4127 | Elf_Internal_Sym *sym) | |
5bd4f169 | 4128 | { |
1e2f5b6e AM |
4129 | asection *rsec = NULL; |
4130 | ||
5bd4f169 AM |
4131 | if (h != NULL) |
4132 | { | |
04c9666a | 4133 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e | 4134 | struct ppc_link_hash_entry *fdh; |
a33d1f77 | 4135 | |
4ce794b7 | 4136 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 4137 | switch (r_type) |
5bd4f169 AM |
4138 | { |
4139 | case R_PPC64_GNU_VTINHERIT: | |
4140 | case R_PPC64_GNU_VTENTRY: | |
4141 | break; | |
4142 | ||
4143 | default: | |
4144 | switch (h->root.type) | |
4145 | { | |
4146 | case bfd_link_hash_defined: | |
4147 | case bfd_link_hash_defweak: | |
1e2f5b6e AM |
4148 | fdh = (struct ppc_link_hash_entry *) h; |
4149 | ||
4150 | /* Function descriptor syms cause the associated | |
4151 | function code sym section to be marked. */ | |
4152 | if (fdh->is_func_descriptor) | |
34814b9f | 4153 | rsec = fdh->oh->elf.root.u.def.section; |
1e2f5b6e AM |
4154 | |
4155 | /* Function entry syms return NULL if they are in .opd | |
4156 | and are not ._start (or others undefined on the ld | |
4157 | command line). Thus we avoid marking all function | |
b34976b6 | 4158 | sections, as all functions are referenced in .opd. */ |
34814b9f | 4159 | else if ((fdh->oh != NULL && fdh->oh->is_entry) |
f0abc2a1 | 4160 | || ppc64_elf_section_data (sec)->opd.func_sec == NULL) |
1e2f5b6e AM |
4161 | rsec = h->root.u.def.section; |
4162 | break; | |
5bd4f169 AM |
4163 | |
4164 | case bfd_link_hash_common: | |
1e2f5b6e AM |
4165 | rsec = h->root.u.c.p->section; |
4166 | break; | |
5bd4f169 AM |
4167 | |
4168 | default: | |
4169 | break; | |
4170 | } | |
4171 | } | |
4172 | } | |
4173 | else | |
4174 | { | |
1e2f5b6e AM |
4175 | asection **opd_sym_section; |
4176 | ||
4177 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
f0abc2a1 | 4178 | opd_sym_section = ppc64_elf_section_data (rsec)->opd.func_sec; |
1e2f5b6e AM |
4179 | if (opd_sym_section != NULL) |
4180 | rsec = opd_sym_section[sym->st_value / 24]; | |
f0abc2a1 | 4181 | else if (ppc64_elf_section_data (sec)->opd.func_sec != NULL) |
1e2f5b6e | 4182 | rsec = NULL; |
5bd4f169 AM |
4183 | } |
4184 | ||
1e2f5b6e | 4185 | return rsec; |
5bd4f169 AM |
4186 | } |
4187 | ||
65f38f15 AM |
4188 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
4189 | section being removed. */ | |
5bd4f169 | 4190 | |
b34976b6 | 4191 | static bfd_boolean |
4ce794b7 AM |
4192 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
4193 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 4194 | { |
411e1bfb | 4195 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
4196 | Elf_Internal_Shdr *symtab_hdr; |
4197 | struct elf_link_hash_entry **sym_hashes; | |
411e1bfb | 4198 | struct got_entry **local_got_ents; |
5bd4f169 | 4199 | const Elf_Internal_Rela *rel, *relend; |
5bd4f169 | 4200 | |
680a3378 AM |
4201 | if ((sec->flags & SEC_ALLOC) == 0) |
4202 | return TRUE; | |
4203 | ||
ec338859 AM |
4204 | elf_section_data (sec)->local_dynrel = NULL; |
4205 | ||
411e1bfb | 4206 | htab = ppc_hash_table (info); |
5bd4f169 AM |
4207 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4208 | sym_hashes = elf_sym_hashes (abfd); | |
411e1bfb | 4209 | local_got_ents = elf_local_got_ents (abfd); |
5bd4f169 AM |
4210 | |
4211 | relend = relocs + sec->reloc_count; | |
4212 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
4213 | { |
4214 | unsigned long r_symndx; | |
04c9666a | 4215 | enum elf_ppc64_reloc_type r_type; |
58ac9f71 | 4216 | struct elf_link_hash_entry *h = NULL; |
411e1bfb | 4217 | char tls_type = 0; |
5bd4f169 | 4218 | |
a33d1f77 | 4219 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 | 4220 | r_type = ELF64_R_TYPE (rel->r_info); |
58ac9f71 AM |
4221 | if (r_symndx >= symtab_hdr->sh_info) |
4222 | { | |
4223 | struct ppc_link_hash_entry *eh; | |
4224 | struct ppc_dyn_relocs **pp; | |
4225 | struct ppc_dyn_relocs *p; | |
4226 | ||
4227 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4228 | eh = (struct ppc_link_hash_entry *) h; | |
4229 | ||
4230 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4231 | if (p->sec == sec) | |
4232 | { | |
4233 | /* Everything must go for SEC. */ | |
4234 | *pp = p->next; | |
4235 | break; | |
4236 | } | |
4237 | } | |
4238 | ||
a33d1f77 AM |
4239 | switch (r_type) |
4240 | { | |
411e1bfb AM |
4241 | case R_PPC64_GOT_TLSLD16: |
4242 | case R_PPC64_GOT_TLSLD16_LO: | |
4243 | case R_PPC64_GOT_TLSLD16_HI: | |
4244 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 4245 | ppc64_tlsld_got (abfd)->refcount -= 1; |
951fd09b | 4246 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
4247 | goto dogot; |
4248 | ||
4249 | case R_PPC64_GOT_TLSGD16: | |
4250 | case R_PPC64_GOT_TLSGD16_LO: | |
4251 | case R_PPC64_GOT_TLSGD16_HI: | |
4252 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 4253 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
4254 | goto dogot; |
4255 | ||
4256 | case R_PPC64_GOT_TPREL16_DS: | |
4257 | case R_PPC64_GOT_TPREL16_LO_DS: | |
4258 | case R_PPC64_GOT_TPREL16_HI: | |
4259 | case R_PPC64_GOT_TPREL16_HA: | |
4260 | tls_type = TLS_TLS | TLS_TPREL; | |
4261 | goto dogot; | |
4262 | ||
4263 | case R_PPC64_GOT_DTPREL16_DS: | |
4264 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
4265 | case R_PPC64_GOT_DTPREL16_HI: | |
4266 | case R_PPC64_GOT_DTPREL16_HA: | |
4267 | tls_type = TLS_TLS | TLS_DTPREL; | |
4268 | goto dogot; | |
4269 | ||
a33d1f77 AM |
4270 | case R_PPC64_GOT16: |
4271 | case R_PPC64_GOT16_DS: | |
4272 | case R_PPC64_GOT16_HA: | |
4273 | case R_PPC64_GOT16_HI: | |
4274 | case R_PPC64_GOT16_LO: | |
4275 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb AM |
4276 | dogot: |
4277 | { | |
4278 | struct got_entry *ent; | |
4279 | ||
58ac9f71 AM |
4280 | if (h != NULL) |
4281 | ent = h->got.glist; | |
411e1bfb AM |
4282 | else |
4283 | ent = local_got_ents[r_symndx]; | |
4284 | ||
4285 | for (; ent != NULL; ent = ent->next) | |
4286 | if (ent->addend == rel->r_addend | |
e717da7e | 4287 | && ent->owner == abfd |
411e1bfb AM |
4288 | && ent->tls_type == tls_type) |
4289 | break; | |
4290 | if (ent == NULL) | |
4291 | abort (); | |
4292 | if (ent->got.refcount > 0) | |
4293 | ent->got.refcount -= 1; | |
4294 | } | |
a33d1f77 | 4295 | break; |
65f38f15 | 4296 | |
a33d1f77 AM |
4297 | case R_PPC64_PLT16_HA: |
4298 | case R_PPC64_PLT16_HI: | |
4299 | case R_PPC64_PLT16_LO: | |
4300 | case R_PPC64_PLT32: | |
4301 | case R_PPC64_PLT64: | |
721956f4 AM |
4302 | case R_PPC64_REL14: |
4303 | case R_PPC64_REL14_BRNTAKEN: | |
4304 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 | 4305 | case R_PPC64_REL24: |
58ac9f71 | 4306 | if (h != NULL) |
5d1634d7 | 4307 | { |
411e1bfb AM |
4308 | struct plt_entry *ent; |
4309 | ||
411e1bfb AM |
4310 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
4311 | if (ent->addend == rel->r_addend) | |
4312 | break; | |
4313 | if (ent == NULL) | |
4314 | abort (); | |
4315 | if (ent->plt.refcount > 0) | |
4316 | ent->plt.refcount -= 1; | |
5d1634d7 | 4317 | } |
e86ce104 | 4318 | break; |
5d1634d7 | 4319 | |
a33d1f77 AM |
4320 | default: |
4321 | break; | |
4322 | } | |
4323 | } | |
b34976b6 | 4324 | return TRUE; |
5bd4f169 AM |
4325 | } |
4326 | ||
e86ce104 AM |
4327 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
4328 | information on function code symbol entries to their corresponding | |
4329 | function descriptor symbol entries. */ | |
b34976b6 | 4330 | static bfd_boolean |
4ce794b7 | 4331 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 4332 | { |
e86ce104 | 4333 | struct bfd_link_info *info; |
65f38f15 | 4334 | struct ppc_link_hash_table *htab; |
411e1bfb | 4335 | struct plt_entry *ent; |
50bc7936 AM |
4336 | struct ppc_link_hash_entry *fh; |
4337 | struct ppc_link_hash_entry *fdh; | |
4338 | bfd_boolean force_local; | |
5bd4f169 | 4339 | |
50bc7936 AM |
4340 | fh = (struct ppc_link_hash_entry *) h; |
4341 | if (fh->elf.root.type == bfd_link_hash_indirect) | |
b34976b6 | 4342 | return TRUE; |
e86ce104 | 4343 | |
50bc7936 AM |
4344 | if (fh->elf.root.type == bfd_link_hash_warning) |
4345 | fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link; | |
e92d460e | 4346 | |
4ce794b7 | 4347 | info = inf; |
65f38f15 | 4348 | htab = ppc_hash_table (info); |
5bd4f169 | 4349 | |
e86ce104 AM |
4350 | /* If this is a function code symbol, transfer dynamic linking |
4351 | information to the function descriptor symbol. */ | |
50bc7936 | 4352 | if (!fh->is_func) |
b34976b6 | 4353 | return TRUE; |
e86ce104 | 4354 | |
50bc7936 | 4355 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
4356 | if (ent->plt.refcount > 0) |
4357 | break; | |
50bc7936 AM |
4358 | if (ent == NULL |
4359 | || fh->elf.root.root.string[0] != '.' | |
4360 | || fh->elf.root.root.string[1] == '\0') | |
4361 | return TRUE; | |
5bd4f169 | 4362 | |
50bc7936 AM |
4363 | /* Find the corresponding function descriptor symbol. Create it |
4364 | as undefined if necessary. */ | |
5bd4f169 | 4365 | |
50bc7936 AM |
4366 | fdh = get_fdh (fh, htab); |
4367 | if (fdh != NULL) | |
4368 | while (fdh->elf.root.type == bfd_link_hash_indirect | |
4369 | || fdh->elf.root.type == bfd_link_hash_warning) | |
4370 | fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link; | |
5bd4f169 | 4371 | |
50bc7936 AM |
4372 | if (fdh == NULL |
4373 | && info->shared | |
4374 | && (fh->elf.root.type == bfd_link_hash_undefined | |
4375 | || fh->elf.root.type == bfd_link_hash_undefweak)) | |
4376 | { | |
4377 | bfd *abfd; | |
4378 | asymbol *newsym; | |
4379 | struct bfd_link_hash_entry *bh; | |
4380 | ||
4381 | abfd = fh->elf.root.u.undef.abfd; | |
4382 | newsym = bfd_make_empty_symbol (abfd); | |
4383 | newsym->name = fh->elf.root.root.string + 1; | |
4384 | newsym->section = bfd_und_section_ptr; | |
4385 | newsym->value = 0; | |
4386 | newsym->flags = BSF_OBJECT; | |
4387 | if (fh->elf.root.type == bfd_link_hash_undefweak) | |
4388 | newsym->flags |= BSF_WEAK; | |
4389 | ||
4390 | bh = &fdh->elf.root; | |
4391 | if ( !(_bfd_generic_link_add_one_symbol | |
4392 | (info, abfd, newsym->name, newsym->flags, | |
4393 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) | |
648cca2c | 4394 | { |
50bc7936 | 4395 | return FALSE; |
648cca2c | 4396 | } |
50bc7936 AM |
4397 | fdh = (struct ppc_link_hash_entry *) bh; |
4398 | fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF; | |
4399 | fdh->elf.size = 24; | |
4400 | fdh->elf.type = STT_OBJECT; | |
4401 | } | |
648cca2c | 4402 | |
50bc7936 AM |
4403 | if (fdh != NULL |
4404 | && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 | |
4405 | && (info->shared | |
4406 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4407 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 | |
4408 | || (fdh->elf.root.type == bfd_link_hash_undefweak | |
4409 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) | |
4410 | { | |
4411 | if (fdh->elf.dynindx == -1) | |
c152c796 | 4412 | if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf)) |
50bc7936 AM |
4413 | return FALSE; |
4414 | fdh->elf.elf_link_hash_flags | |
4415 | |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
4416 | | ELF_LINK_HASH_REF_DYNAMIC | |
4417 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
4418 | | ELF_LINK_NON_GOT_REF)); | |
4419 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) | |
e86ce104 | 4420 | { |
50bc7936 AM |
4421 | fdh->elf.plt.plist = fh->elf.plt.plist; |
4422 | fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
e86ce104 | 4423 | } |
50bc7936 | 4424 | fdh->is_func_descriptor = 1; |
34814b9f AM |
4425 | fdh->oh = fh; |
4426 | fh->oh = fdh; | |
e86ce104 AM |
4427 | } |
4428 | ||
50bc7936 AM |
4429 | /* Now that the info is on the function descriptor, clear the |
4430 | function code sym info. Any function code syms for which we | |
4431 | don't have a definition in a regular file, we force local. | |
4432 | This prevents a shared library from exporting syms that have | |
4433 | been imported from another library. Function code syms that | |
4434 | are really in the library we must leave global to prevent the | |
4435 | linker dragging in a definition from a static library. */ | |
4436 | force_local | |
4437 | = (info->shared | |
4438 | && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4439 | || fdh == NULL | |
4440 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4441 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)); | |
4442 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); | |
4443 | ||
b34976b6 | 4444 | return TRUE; |
e86ce104 | 4445 | } |
40b8271b | 4446 | |
82bd7b59 AM |
4447 | #define MIN_SAVE_FPR 14 |
4448 | #define MAX_SAVE_FPR 31 | |
4449 | ||
e86ce104 | 4450 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
4451 | this hook to a) provide some gcc support functions, and b) transfer |
4452 | dynamic linking information gathered so far on function code symbol | |
4453 | entries, to their corresponding function descriptor symbol entries. */ | |
b34976b6 | 4454 | static bfd_boolean |
4ce794b7 AM |
4455 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
4456 | struct bfd_link_info *info) | |
e86ce104 AM |
4457 | { |
4458 | struct ppc_link_hash_table *htab; | |
82bd7b59 AM |
4459 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
4460 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; | |
4461 | unsigned int i; | |
4462 | struct elf_link_hash_entry *h; | |
721956f4 | 4463 | bfd_byte *p; |
82bd7b59 | 4464 | char sym[10]; |
e86ce104 AM |
4465 | |
4466 | htab = ppc_hash_table (info); | |
82bd7b59 AM |
4467 | |
4468 | if (htab->sfpr == NULL) | |
4469 | /* We don't have any relocs. */ | |
b34976b6 | 4470 | return TRUE; |
82bd7b59 AM |
4471 | |
4472 | /* First provide any missing ._savef* and ._restf* functions. */ | |
4473 | memcpy (sym, "._savef14", 10); | |
4474 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4475 | { | |
4476 | sym[7] = i / 10 + '0'; | |
4477 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4478 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4479 | if (h != NULL |
772119ce | 4480 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4481 | { |
4482 | if (lowest_savef > i) | |
4483 | lowest_savef = i; | |
4484 | h->root.type = bfd_link_hash_defined; | |
4485 | h->root.u.def.section = htab->sfpr; | |
4486 | h->root.u.def.value = (i - lowest_savef) * 4; | |
4487 | h->type = STT_FUNC; | |
4488 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4489 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4490 | } |
4491 | } | |
4492 | ||
4493 | memcpy (sym, "._restf14", 10); | |
4494 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4495 | { | |
4496 | sym[7] = i / 10 + '0'; | |
4497 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4498 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4499 | if (h != NULL |
772119ce | 4500 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4501 | { |
4502 | if (lowest_restf > i) | |
4503 | lowest_restf = i; | |
4504 | h->root.type = bfd_link_hash_defined; | |
4505 | h->root.u.def.section = htab->sfpr; | |
4506 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 | |
4507 | + (i - lowest_restf) * 4); | |
4508 | h->type = STT_FUNC; | |
4509 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4510 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4511 | } |
4512 | } | |
4513 | ||
4ce794b7 | 4514 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
805fc799 | 4515 | |
eea6121a AM |
4516 | htab->sfpr->size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
4517 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); | |
82bd7b59 | 4518 | |
eea6121a | 4519 | if (htab->sfpr->size == 0) |
805fc799 | 4520 | { |
06da1e8e AM |
4521 | _bfd_strip_section_from_output (info, htab->sfpr); |
4522 | return TRUE; | |
805fc799 | 4523 | } |
82bd7b59 | 4524 | |
eea6121a | 4525 | p = bfd_alloc (htab->elf.dynobj, htab->sfpr->size); |
721956f4 | 4526 | if (p == NULL) |
b34976b6 | 4527 | return FALSE; |
721956f4 AM |
4528 | htab->sfpr->contents = p; |
4529 | ||
4530 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) | |
4531 | { | |
4532 | unsigned int fpr = i << 21; | |
4533 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4534 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); | |
4535 | p += 4; | |
4536 | } | |
4537 | if (lowest_savef <= MAX_SAVE_FPR) | |
4538 | { | |
82bd7b59 AM |
4539 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
4540 | p += 4; | |
721956f4 | 4541 | } |
82bd7b59 | 4542 | |
721956f4 AM |
4543 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
4544 | { | |
4545 | unsigned int fpr = i << 21; | |
4546 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4547 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); | |
82bd7b59 AM |
4548 | p += 4; |
4549 | } | |
06da1e8e AM |
4550 | if (lowest_restf <= MAX_SAVE_FPR) |
4551 | bfd_put_32 (htab->elf.dynobj, BLR, p); | |
82bd7b59 | 4552 | |
b34976b6 | 4553 | return TRUE; |
e86ce104 AM |
4554 | } |
4555 | ||
4556 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
4557 | regular object. The current definition is in some section of the | |
4558 | dynamic object, but we're not including those sections. We have to | |
4559 | change the definition to something the rest of the link can | |
4560 | understand. */ | |
4561 | ||
b34976b6 | 4562 | static bfd_boolean |
4ce794b7 AM |
4563 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
4564 | struct elf_link_hash_entry *h) | |
e86ce104 AM |
4565 | { |
4566 | struct ppc_link_hash_table *htab; | |
e86ce104 AM |
4567 | asection *s; |
4568 | unsigned int power_of_two; | |
4569 | ||
4570 | htab = ppc_hash_table (info); | |
4571 | ||
4572 | /* Deal with function syms. */ | |
4573 | if (h->type == STT_FUNC | |
4574 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
4575 | { | |
4576 | /* Clear procedure linkage table information for any symbol that | |
4577 | won't need a .plt entry. */ | |
411e1bfb AM |
4578 | struct plt_entry *ent; |
4579 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4580 | if (ent->plt.refcount > 0) | |
4581 | break; | |
e86ce104 | 4582 | if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor |
411e1bfb | 4583 | || ent == NULL |
9c7a29a3 AM |
4584 | || SYMBOL_CALLS_LOCAL (info, h) |
4585 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4586 | && h->root.type == bfd_link_hash_undefweak)) | |
40b8271b | 4587 | { |
411e1bfb | 4588 | h->plt.plist = NULL; |
40b8271b | 4589 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
40b8271b | 4590 | } |
5bd4f169 | 4591 | } |
bbd7ec4a | 4592 | else |
411e1bfb | 4593 | h->plt.plist = NULL; |
5bd4f169 AM |
4594 | |
4595 | /* If this is a weak symbol, and there is a real definition, the | |
4596 | processor independent code will have arranged for us to see the | |
4597 | real definition first, and we can just use the same value. */ | |
4598 | if (h->weakdef != NULL) | |
4599 | { | |
4600 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
4601 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
4602 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
4603 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
a23b6845 AM |
4604 | if (ELIMINATE_COPY_RELOCS) |
4605 | h->elf_link_hash_flags | |
4606 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) | |
4607 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); | |
b34976b6 | 4608 | return TRUE; |
5bd4f169 AM |
4609 | } |
4610 | ||
5bd4f169 AM |
4611 | /* If we are creating a shared library, we must presume that the |
4612 | only references to the symbol are via the global offset table. | |
4613 | For such cases we need not do anything here; the relocations will | |
4614 | be handled correctly by relocate_section. */ | |
4615 | if (info->shared) | |
b34976b6 | 4616 | return TRUE; |
5bd4f169 | 4617 | |
65f38f15 AM |
4618 | /* If there are no references to this symbol that do not use the |
4619 | GOT, we don't need to generate a copy reloc. */ | |
4620 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 4621 | return TRUE; |
65f38f15 | 4622 | |
f4656909 | 4623 | if (ELIMINATE_COPY_RELOCS) |
65f38f15 | 4624 | { |
f4656909 AM |
4625 | struct ppc_link_hash_entry * eh; |
4626 | struct ppc_dyn_relocs *p; | |
65f38f15 | 4627 | |
f4656909 AM |
4628 | eh = (struct ppc_link_hash_entry *) h; |
4629 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4630 | { | |
4631 | s = p->sec->output_section; | |
4632 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
4633 | break; | |
4634 | } | |
4635 | ||
4636 | /* If we didn't find any dynamic relocs in read-only sections, then | |
4637 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
4638 | if (p == NULL) | |
4639 | { | |
4640 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
4641 | return TRUE; | |
4642 | } | |
65f38f15 AM |
4643 | } |
4644 | ||
5d35169e | 4645 | if (h->plt.plist != NULL) |
97b639ba AM |
4646 | { |
4647 | /* We should never get here, but unfortunately there are versions | |
4648 | of gcc out there that improperly (for this ABI) put initialized | |
4649 | function pointers, vtable refs and suchlike in read-only | |
4650 | sections. Allow them to proceed, but warn that this might | |
4651 | break at runtime. */ | |
4652 | (*_bfd_error_handler) | |
4653 | (_("copy reloc against `%s' requires lazy plt linking; " | |
4654 | "avoid setting LD_BIND_NOW=1 or upgrade gcc"), | |
4655 | h->root.root.string); | |
4656 | } | |
5d35169e AM |
4657 | |
4658 | /* This is a reference to a symbol defined by a dynamic object which | |
4659 | is not a function. */ | |
4660 | ||
5bd4f169 AM |
4661 | /* We must allocate the symbol in our .dynbss section, which will |
4662 | become part of the .bss section of the executable. There will be | |
4663 | an entry for this symbol in the .dynsym section. The dynamic | |
4664 | object will contain position independent code, so all references | |
4665 | from the dynamic object to this symbol will go through the global | |
4666 | offset table. The dynamic linker will use the .dynsym entry to | |
4667 | determine the address it must put in the global offset table, so | |
4668 | both the dynamic object and the regular object will refer to the | |
4669 | same memory location for the variable. */ | |
5bd4f169 | 4670 | |
04c9666a AM |
4671 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
4672 | to copy the initial value out of the dynamic object and into the | |
5bd4f169 AM |
4673 | runtime process image. We need to remember the offset into the |
4674 | .rela.bss section we are going to use. */ | |
4675 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
4676 | { | |
eea6121a | 4677 | htab->relbss->size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
4678 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
4679 | } | |
4680 | ||
4681 | /* We need to figure out the alignment required for this symbol. I | |
4682 | have no idea how ELF linkers handle this. */ | |
4683 | power_of_two = bfd_log2 (h->size); | |
4684 | if (power_of_two > 4) | |
4685 | power_of_two = 4; | |
4686 | ||
4687 | /* Apply the required alignment. */ | |
4ce794b7 | 4688 | s = htab->dynbss; |
eea6121a | 4689 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
65f38f15 | 4690 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) |
5bd4f169 | 4691 | { |
65f38f15 | 4692 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 4693 | return FALSE; |
5bd4f169 AM |
4694 | } |
4695 | ||
4696 | /* Define the symbol as being at this point in the section. */ | |
4697 | h->root.u.def.section = s; | |
eea6121a | 4698 | h->root.u.def.value = s->size; |
5bd4f169 AM |
4699 | |
4700 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 4701 | s->size += h->size; |
5bd4f169 | 4702 | |
b34976b6 | 4703 | return TRUE; |
5bd4f169 AM |
4704 | } |
4705 | ||
e86ce104 AM |
4706 | /* If given a function descriptor symbol, hide both the function code |
4707 | sym and the descriptor. */ | |
4708 | static void | |
4ce794b7 AM |
4709 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
4710 | struct elf_link_hash_entry *h, | |
4711 | bfd_boolean force_local) | |
e86ce104 | 4712 | { |
34814b9f | 4713 | struct ppc_link_hash_entry *eh; |
e86ce104 AM |
4714 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
4715 | ||
34814b9f AM |
4716 | eh = (struct ppc_link_hash_entry *) h; |
4717 | if (eh->is_func_descriptor) | |
e86ce104 | 4718 | { |
34814b9f | 4719 | struct ppc_link_hash_entry *fh = eh->oh; |
e86ce104 | 4720 | |
721956f4 | 4721 | if (fh == NULL) |
d1329ca3 AM |
4722 | { |
4723 | const char *p, *q; | |
4724 | struct ppc_link_hash_table *htab; | |
4725 | char save; | |
4726 | ||
4727 | /* We aren't supposed to use alloca in BFD because on | |
4728 | systems which do not have alloca the version in libiberty | |
4729 | calls xmalloc, which might cause the program to crash | |
4730 | when it runs out of memory. This function doesn't have a | |
4731 | return status, so there's no way to gracefully return an | |
4732 | error. So cheat. We know that string[-1] can be safely | |
34814b9f AM |
4733 | accessed; It's either a string in an ELF string table, |
4734 | or allocated in an objalloc structure. */ | |
d1329ca3 | 4735 | |
34814b9f | 4736 | p = eh->elf.root.root.string - 1; |
d1329ca3 AM |
4737 | save = *p; |
4738 | *(char *) p = '.'; | |
4739 | htab = ppc_hash_table (info); | |
34814b9f AM |
4740 | fh = (struct ppc_link_hash_entry *) |
4741 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
4742 | *(char *) p = save; |
4743 | ||
4744 | /* Unfortunately, if it so happens that the string we were | |
4745 | looking for was allocated immediately before this string, | |
4746 | then we overwrote the string terminator. That's the only | |
4747 | reason the lookup should fail. */ | |
4748 | if (fh == NULL) | |
4749 | { | |
34814b9f AM |
4750 | q = eh->elf.root.root.string + strlen (eh->elf.root.root.string); |
4751 | while (q >= eh->elf.root.root.string && *q == *p) | |
d1329ca3 | 4752 | --q, --p; |
34814b9f AM |
4753 | if (q < eh->elf.root.root.string && *p == '.') |
4754 | fh = (struct ppc_link_hash_entry *) | |
4755 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); | |
d1329ca3 AM |
4756 | } |
4757 | if (fh != NULL) | |
4758 | { | |
34814b9f AM |
4759 | eh->oh = fh; |
4760 | fh->oh = eh; | |
d1329ca3 AM |
4761 | } |
4762 | } | |
e86ce104 | 4763 | if (fh != NULL) |
34814b9f | 4764 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); |
e86ce104 AM |
4765 | } |
4766 | } | |
4767 | ||
411e1bfb | 4768 | static bfd_boolean |
4ce794b7 AM |
4769 | get_sym_h (struct elf_link_hash_entry **hp, Elf_Internal_Sym **symp, |
4770 | asection **symsecp, char **tls_maskp, Elf_Internal_Sym **locsymsp, | |
4771 | unsigned long r_symndx, bfd *ibfd) | |
411e1bfb AM |
4772 | { |
4773 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
4774 | ||
4775 | if (r_symndx >= symtab_hdr->sh_info) | |
4776 | { | |
4777 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
4778 | struct elf_link_hash_entry *h; | |
4779 | ||
4780 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4781 | while (h->root.type == bfd_link_hash_indirect | |
4782 | || h->root.type == bfd_link_hash_warning) | |
4783 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4784 | ||
4785 | if (hp != NULL) | |
4786 | *hp = h; | |
4787 | ||
4788 | if (symp != NULL) | |
4789 | *symp = NULL; | |
4790 | ||
4791 | if (symsecp != NULL) | |
4792 | { | |
4793 | asection *symsec = NULL; | |
4794 | if (h->root.type == bfd_link_hash_defined | |
4795 | || h->root.type == bfd_link_hash_defweak) | |
4796 | symsec = h->root.u.def.section; | |
4797 | *symsecp = symsec; | |
4798 | } | |
4799 | ||
e7b938ca | 4800 | if (tls_maskp != NULL) |
411e1bfb AM |
4801 | { |
4802 | struct ppc_link_hash_entry *eh; | |
4803 | ||
4804 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 4805 | *tls_maskp = &eh->tls_mask; |
411e1bfb AM |
4806 | } |
4807 | } | |
4808 | else | |
4809 | { | |
4810 | Elf_Internal_Sym *sym; | |
4811 | Elf_Internal_Sym *locsyms = *locsymsp; | |
4812 | ||
4813 | if (locsyms == NULL) | |
4814 | { | |
4815 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4816 | if (locsyms == NULL) | |
4817 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
4818 | symtab_hdr->sh_info, | |
4819 | 0, NULL, NULL, NULL); | |
4820 | if (locsyms == NULL) | |
4821 | return FALSE; | |
4822 | *locsymsp = locsyms; | |
4823 | } | |
4824 | sym = locsyms + r_symndx; | |
4825 | ||
4826 | if (hp != NULL) | |
4827 | *hp = NULL; | |
4828 | ||
4829 | if (symp != NULL) | |
4830 | *symp = sym; | |
4831 | ||
4832 | if (symsecp != NULL) | |
4833 | { | |
4834 | asection *symsec = NULL; | |
4835 | if ((sym->st_shndx != SHN_UNDEF | |
4836 | && sym->st_shndx < SHN_LORESERVE) | |
4837 | || sym->st_shndx > SHN_HIRESERVE) | |
4838 | symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); | |
4839 | *symsecp = symsec; | |
4840 | } | |
4841 | ||
e7b938ca | 4842 | if (tls_maskp != NULL) |
411e1bfb AM |
4843 | { |
4844 | struct got_entry **lgot_ents; | |
e7b938ca | 4845 | char *tls_mask; |
411e1bfb | 4846 | |
e7b938ca | 4847 | tls_mask = NULL; |
411e1bfb AM |
4848 | lgot_ents = elf_local_got_ents (ibfd); |
4849 | if (lgot_ents != NULL) | |
4850 | { | |
e7b938ca AM |
4851 | char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info); |
4852 | tls_mask = &lgot_masks[r_symndx]; | |
411e1bfb | 4853 | } |
e7b938ca | 4854 | *tls_maskp = tls_mask; |
411e1bfb AM |
4855 | } |
4856 | } | |
4857 | return TRUE; | |
4858 | } | |
4859 | ||
e7b938ca | 4860 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
951fd09b | 4861 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
ad8e1ba5 | 4862 | type suitable for optimization, and 1 otherwise. */ |
951fd09b AM |
4863 | |
4864 | static int | |
0d4792f7 AM |
4865 | get_tls_mask (char **tls_maskp, unsigned long *toc_symndx, |
4866 | Elf_Internal_Sym **locsymsp, | |
4ce794b7 | 4867 | const Elf_Internal_Rela *rel, bfd *ibfd) |
411e1bfb AM |
4868 | { |
4869 | unsigned long r_symndx; | |
0d4792f7 | 4870 | int next_r; |
411e1bfb AM |
4871 | struct elf_link_hash_entry *h; |
4872 | Elf_Internal_Sym *sym; | |
4873 | asection *sec; | |
4874 | bfd_vma off; | |
4875 | ||
4876 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 4877 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 4878 | return 0; |
411e1bfb | 4879 | |
e7b938ca | 4880 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
411e1bfb AM |
4881 | || sec == NULL |
4882 | || ppc64_elf_section_data (sec)->t_symndx == NULL) | |
951fd09b | 4883 | return 1; |
411e1bfb AM |
4884 | |
4885 | /* Look inside a TOC section too. */ | |
4886 | if (h != NULL) | |
4887 | { | |
4888 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
4889 | off = h->root.u.def.value; | |
4890 | } | |
4891 | else | |
4892 | off = sym->st_value; | |
4893 | off += rel->r_addend; | |
4894 | BFD_ASSERT (off % 8 == 0); | |
4895 | r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8]; | |
951fd09b | 4896 | next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1]; |
e7b938ca | 4897 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 4898 | return 0; |
0d4792f7 AM |
4899 | if (toc_symndx != NULL) |
4900 | *toc_symndx = r_symndx; | |
4901 | if ((h == NULL | |
4902 | || ((h->root.type == bfd_link_hash_defined | |
4903 | || h->root.type == bfd_link_hash_defweak) | |
4904 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
4905 | && (next_r == -1 || next_r == -2)) | |
4906 | return 1 - next_r; | |
951fd09b | 4907 | return 1; |
411e1bfb AM |
4908 | } |
4909 | ||
754021d0 AM |
4910 | /* Adjust all global syms defined in opd sections. In gcc generated |
4911 | code these will already have been done, but I suppose we have to | |
4912 | cater for all sorts of hand written assembly. */ | |
4913 | ||
4914 | static bfd_boolean | |
4915 | adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) | |
4916 | { | |
4917 | struct ppc_link_hash_entry *eh; | |
4918 | asection *sym_sec; | |
4919 | long *opd_adjust; | |
4920 | ||
4921 | if (h->root.type == bfd_link_hash_indirect) | |
4922 | return TRUE; | |
4923 | ||
4924 | if (h->root.type == bfd_link_hash_warning) | |
4925 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4926 | ||
4927 | if (h->root.type != bfd_link_hash_defined | |
4928 | && h->root.type != bfd_link_hash_defweak) | |
4929 | return TRUE; | |
4930 | ||
4931 | eh = (struct ppc_link_hash_entry *) h; | |
4932 | if (eh->adjust_done) | |
4933 | return TRUE; | |
4934 | ||
4935 | sym_sec = eh->elf.root.u.def.section; | |
4025353c AM |
4936 | opd_adjust = get_opd_info (sym_sec); |
4937 | if (opd_adjust != NULL) | |
754021d0 | 4938 | { |
4025353c AM |
4939 | long adjust = opd_adjust[eh->elf.root.u.def.value / 24]; |
4940 | if (adjust == -1) | |
4941 | { | |
4942 | /* This entry has been deleted. */ | |
4943 | eh->elf.root.u.def.value = 0; | |
4944 | eh->elf.root.u.def.section = &bfd_abs_section; | |
4945 | } | |
4946 | else | |
4947 | eh->elf.root.u.def.value += adjust; | |
754021d0 AM |
4948 | eh->adjust_done = 1; |
4949 | } | |
4950 | return TRUE; | |
4951 | } | |
4952 | ||
4953 | /* Remove unused Official Procedure Descriptor entries. Currently we | |
4954 | only remove those associated with functions in discarded link-once | |
4955 | sections, or weakly defined functions that have been overridden. It | |
4956 | would be possible to remove many more entries for statically linked | |
4957 | applications. */ | |
4958 | ||
b34976b6 | 4959 | bfd_boolean |
4ce794b7 | 4960 | ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info) |
1e2f5b6e AM |
4961 | { |
4962 | bfd *ibfd; | |
754021d0 | 4963 | bfd_boolean some_edited = FALSE; |
1e2f5b6e | 4964 | |
411e1bfb | 4965 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1e2f5b6e AM |
4966 | { |
4967 | asection *sec; | |
4968 | Elf_Internal_Rela *relstart, *rel, *relend; | |
4969 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 4970 | Elf_Internal_Sym *local_syms; |
1e2f5b6e AM |
4971 | struct elf_link_hash_entry **sym_hashes; |
4972 | bfd_vma offset; | |
d6fe2dc1 | 4973 | bfd_size_type amt; |
4025353c | 4974 | long *opd_adjust; |
b34976b6 | 4975 | bfd_boolean need_edit; |
1e2f5b6e AM |
4976 | |
4977 | sec = bfd_get_section_by_name (ibfd, ".opd"); | |
4978 | if (sec == NULL) | |
4979 | continue; | |
4980 | ||
eea6121a | 4981 | amt = sec->size * sizeof (long) / 24; |
4025353c AM |
4982 | opd_adjust = get_opd_info (sec); |
4983 | if (opd_adjust == NULL) | |
d6fe2dc1 AM |
4984 | { |
4985 | /* Must be a ld -r link. ie. check_relocs hasn't been | |
4986 | called. */ | |
4025353c AM |
4987 | opd_adjust = bfd_zalloc (obfd, amt); |
4988 | ppc64_elf_section_data (sec)->opd.adjust = opd_adjust; | |
d6fe2dc1 | 4989 | } |
4025353c | 4990 | memset (opd_adjust, 0, amt); |
1e2f5b6e AM |
4991 | |
4992 | if (sec->output_section == bfd_abs_section_ptr) | |
4993 | continue; | |
4994 | ||
4995 | /* Look through the section relocs. */ | |
4996 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
4997 | continue; | |
4998 | ||
6cdc0ccc | 4999 | local_syms = NULL; |
1e2f5b6e AM |
5000 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
5001 | sym_hashes = elf_sym_hashes (ibfd); | |
5002 | ||
5003 | /* Read the relocations. */ | |
4ce794b7 | 5004 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5005 | info->keep_memory); |
1e2f5b6e | 5006 | if (relstart == NULL) |
b34976b6 | 5007 | return FALSE; |
1e2f5b6e AM |
5008 | |
5009 | /* First run through the relocs to check they are sane, and to | |
5010 | determine whether we need to edit this opd section. */ | |
b34976b6 | 5011 | need_edit = FALSE; |
1e2f5b6e AM |
5012 | offset = 0; |
5013 | relend = relstart + sec->reloc_count; | |
50bc7936 | 5014 | for (rel = relstart; rel < relend; ) |
1e2f5b6e | 5015 | { |
04c9666a | 5016 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e AM |
5017 | unsigned long r_symndx; |
5018 | asection *sym_sec; | |
5019 | struct elf_link_hash_entry *h; | |
5020 | Elf_Internal_Sym *sym; | |
5021 | ||
5022 | /* .opd contains a regular array of 24 byte entries. We're | |
5023 | only interested in the reloc pointing to a function entry | |
5024 | point. */ | |
50bc7936 AM |
5025 | if (rel->r_offset != offset |
5026 | || rel + 1 >= relend | |
5027 | || (rel + 1)->r_offset != offset + 8) | |
1e2f5b6e AM |
5028 | { |
5029 | /* If someone messes with .opd alignment then after a | |
5030 | "ld -r" we might have padding in the middle of .opd. | |
5031 | Also, there's nothing to prevent someone putting | |
5032 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 5033 | optimization for them! */ |
1e2f5b6e AM |
5034 | (*_bfd_error_handler) |
5035 | (_("%s: .opd is not a regular array of opd entries"), | |
5036 | bfd_archive_filename (ibfd)); | |
b34976b6 | 5037 | need_edit = FALSE; |
1e2f5b6e AM |
5038 | break; |
5039 | } | |
5040 | ||
50bc7936 AM |
5041 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
5042 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) | |
5043 | { | |
5044 | (*_bfd_error_handler) | |
5045 | (_("%s: unexpected reloc type %u in .opd section"), | |
5046 | bfd_archive_filename (ibfd), r_type); | |
5047 | need_edit = FALSE; | |
5048 | break; | |
5049 | } | |
5050 | ||
1e2f5b6e | 5051 | r_symndx = ELF64_R_SYM (rel->r_info); |
411e1bfb AM |
5052 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
5053 | r_symndx, ibfd)) | |
50bc7936 | 5054 | goto error_ret; |
1e2f5b6e AM |
5055 | |
5056 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
5057 | { | |
411e1bfb AM |
5058 | const char *sym_name; |
5059 | if (h != NULL) | |
5060 | sym_name = h->root.root.string; | |
5061 | else | |
5062 | sym_name = bfd_elf_local_sym_name (ibfd, sym); | |
5063 | ||
1e2f5b6e AM |
5064 | (*_bfd_error_handler) |
5065 | (_("%s: undefined sym `%s' in .opd section"), | |
5066 | bfd_archive_filename (ibfd), | |
411e1bfb | 5067 | sym_name); |
b34976b6 | 5068 | need_edit = FALSE; |
1e2f5b6e AM |
5069 | break; |
5070 | } | |
5071 | ||
51020317 AM |
5072 | /* opd entries are always for functions defined in the |
5073 | current input bfd. If the symbol isn't defined in the | |
5074 | input bfd, then we won't be using the function in this | |
5075 | bfd; It must be defined in a linkonce section in another | |
5076 | bfd, or is weak. It's also possible that we are | |
5077 | discarding the function due to a linker script /DISCARD/, | |
5078 | which we test for via the output_section. */ | |
5079 | if (sym_sec->owner != ibfd | |
5080 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 5081 | need_edit = TRUE; |
1e2f5b6e AM |
5082 | |
5083 | offset += 24; | |
50bc7936 AM |
5084 | rel += 2; |
5085 | /* Allow for the possibility of a reloc on the third word. */ | |
5086 | if (rel < relend | |
5087 | && rel->r_offset == offset - 8) | |
5088 | rel += 1; | |
1e2f5b6e AM |
5089 | } |
5090 | ||
5091 | if (need_edit) | |
5092 | { | |
5093 | Elf_Internal_Rela *write_rel; | |
5094 | bfd_byte *rptr, *wptr; | |
b34976b6 | 5095 | bfd_boolean skip; |
1e2f5b6e AM |
5096 | |
5097 | /* This seems a waste of time as input .opd sections are all | |
5098 | zeros as generated by gcc, but I suppose there's no reason | |
5099 | this will always be so. We might start putting something in | |
5100 | the third word of .opd entries. */ | |
5101 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
5102 | { | |
eea6121a AM |
5103 | bfd_byte *loc; |
5104 | if (!bfd_malloc_and_get_section (ibfd, sec, &loc)) | |
6cdc0ccc | 5105 | { |
eea6121a AM |
5106 | if (loc != NULL) |
5107 | free (loc); | |
50bc7936 | 5108 | error_ret: |
6cdc0ccc AM |
5109 | if (local_syms != NULL |
5110 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5111 | free (local_syms); | |
6cdc0ccc AM |
5112 | if (elf_section_data (sec)->relocs != relstart) |
5113 | free (relstart); | |
b34976b6 | 5114 | return FALSE; |
6cdc0ccc | 5115 | } |
1e2f5b6e AM |
5116 | sec->contents = loc; |
5117 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
5118 | } | |
5119 | ||
5120 | elf_section_data (sec)->relocs = relstart; | |
5121 | ||
5122 | wptr = sec->contents; | |
5123 | rptr = sec->contents; | |
5124 | write_rel = relstart; | |
b34976b6 | 5125 | skip = FALSE; |
1e2f5b6e AM |
5126 | offset = 0; |
5127 | for (rel = relstart; rel < relend; rel++) | |
5128 | { | |
50bc7936 AM |
5129 | unsigned long r_symndx; |
5130 | asection *sym_sec; | |
5131 | struct elf_link_hash_entry *h; | |
5132 | Elf_Internal_Sym *sym; | |
5133 | ||
5134 | r_symndx = ELF64_R_SYM (rel->r_info); | |
5135 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
d37c89e5 | 5136 | r_symndx, ibfd)) |
50bc7936 AM |
5137 | goto error_ret; |
5138 | ||
1e2f5b6e AM |
5139 | if (rel->r_offset == offset) |
5140 | { | |
50bc7936 | 5141 | struct ppc_link_hash_entry *fdh = NULL; |
4025353c AM |
5142 | if (h != NULL |
5143 | && h->root.root.string[0] == '.') | |
50bc7936 AM |
5144 | fdh = get_fdh ((struct ppc_link_hash_entry *) h, |
5145 | ppc_hash_table (info)); | |
1e2f5b6e | 5146 | |
51020317 AM |
5147 | skip = (sym_sec->owner != ibfd |
5148 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
5149 | if (skip) |
5150 | { | |
4025353c | 5151 | if (fdh != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
5152 | { |
5153 | /* Arrange for the function descriptor sym | |
5154 | to be dropped. */ | |
d6fe2dc1 AM |
5155 | fdh->elf.root.u.def.value = 0; |
5156 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 | 5157 | } |
4025353c | 5158 | opd_adjust[rel->r_offset / 24] = -1; |
a4aa0fb7 AM |
5159 | } |
5160 | else | |
1e2f5b6e AM |
5161 | { |
5162 | /* We'll be keeping this opd entry. */ | |
5163 | ||
4025353c | 5164 | if (fdh != NULL) |
1e2f5b6e | 5165 | { |
754021d0 AM |
5166 | /* Redefine the function descriptor symbol to |
5167 | this location in the opd section. It is | |
5168 | necessary to update the value here rather | |
5169 | than using an array of adjustments as we do | |
5170 | for local symbols, because various places | |
5171 | in the generic ELF code use the value | |
5172 | stored in u.def.value. */ | |
d6fe2dc1 | 5173 | fdh->elf.root.u.def.value = wptr - sec->contents; |
754021d0 | 5174 | fdh->adjust_done = 1; |
1e2f5b6e | 5175 | } |
754021d0 AM |
5176 | |
5177 | /* Local syms are a bit tricky. We could | |
5178 | tweak them as they can be cached, but | |
5179 | we'd need to look through the local syms | |
5180 | for the function descriptor sym which we | |
5181 | don't have at the moment. So keep an | |
5182 | array of adjustments. */ | |
4025353c | 5183 | opd_adjust[rel->r_offset / 24] = wptr - rptr; |
1e2f5b6e AM |
5184 | |
5185 | if (wptr != rptr) | |
5186 | memcpy (wptr, rptr, 24); | |
5187 | wptr += 24; | |
5188 | } | |
5189 | rptr += 24; | |
5190 | offset += 24; | |
5191 | } | |
5192 | ||
50bc7936 AM |
5193 | if (skip) |
5194 | { | |
5195 | BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info))); | |
5196 | if (info->shared) | |
5197 | { | |
5198 | /* We won't be needing dynamic relocs here. */ | |
5199 | struct ppc_dyn_relocs **pp; | |
5200 | struct ppc_dyn_relocs *p; | |
5201 | ||
5202 | if (h != NULL) | |
5203 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; | |
5204 | else if (sym_sec != NULL) | |
5205 | pp = ((struct ppc_dyn_relocs **) | |
5206 | &elf_section_data (sym_sec)->local_dynrel); | |
5207 | else | |
5208 | pp = ((struct ppc_dyn_relocs **) | |
5209 | &elf_section_data (sec)->local_dynrel); | |
5210 | while ((p = *pp) != NULL) | |
5211 | { | |
5212 | if (p->sec == sec) | |
5213 | { | |
5214 | p->count -= 1; | |
5215 | if (p->count == 0) | |
d37c89e5 | 5216 | *pp = p->next; |
50bc7936 AM |
5217 | break; |
5218 | } | |
5219 | pp = &p->next; | |
5220 | } | |
5221 | } | |
5222 | } | |
5223 | else | |
1e2f5b6e | 5224 | { |
50bc7936 AM |
5225 | /* We need to adjust any reloc offsets to point to the |
5226 | new opd entries. While we're at it, we may as well | |
5227 | remove redundant relocs. */ | |
1e2f5b6e AM |
5228 | rel->r_offset += wptr - rptr; |
5229 | if (write_rel != rel) | |
5230 | memcpy (write_rel, rel, sizeof (*rel)); | |
5231 | ++write_rel; | |
5232 | } | |
5233 | } | |
5234 | ||
eea6121a | 5235 | sec->size = wptr - sec->contents; |
1e2f5b6e | 5236 | sec->reloc_count = write_rel - relstart; |
cdcf6e38 AM |
5237 | /* Fudge the size too, as this is used later in |
5238 | elf_bfd_final_link if we are emitting relocs. */ | |
5239 | elf_section_data (sec)->rel_hdr.sh_size | |
5240 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; | |
5241 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); | |
754021d0 | 5242 | some_edited = TRUE; |
1e2f5b6e | 5243 | } |
6cdc0ccc | 5244 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 5245 | free (relstart); |
6cdc0ccc | 5246 | |
411e1bfb AM |
5247 | if (local_syms != NULL |
5248 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5249 | { | |
5250 | if (!info->keep_memory) | |
5251 | free (local_syms); | |
5252 | else | |
5253 | symtab_hdr->contents = (unsigned char *) local_syms; | |
5254 | } | |
5255 | } | |
5256 | ||
754021d0 AM |
5257 | if (some_edited) |
5258 | elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL); | |
5259 | ||
411e1bfb AM |
5260 | return TRUE; |
5261 | } | |
5262 | ||
e1918d23 | 5263 | /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ |
411e1bfb | 5264 | |
e1918d23 | 5265 | asection * |
4ce794b7 | 5266 | ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
411e1bfb | 5267 | { |
411e1bfb AM |
5268 | struct ppc_link_hash_table *htab; |
5269 | ||
411e1bfb | 5270 | htab = ppc_hash_table (info); |
a48ebf4d AM |
5271 | if (htab->tls_get_addr != NULL) |
5272 | { | |
5273 | struct elf_link_hash_entry *h = htab->tls_get_addr; | |
5274 | ||
5275 | while (h->root.type == bfd_link_hash_indirect | |
5276 | || h->root.type == bfd_link_hash_warning) | |
5277 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5278 | ||
5279 | htab->tls_get_addr = h; | |
5280 | } | |
5281 | ||
e1918d23 | 5282 | return _bfd_elf_tls_setup (obfd, info); |
951fd09b | 5283 | } |
411e1bfb | 5284 | |
951fd09b AM |
5285 | /* Run through all the TLS relocs looking for optimization |
5286 | opportunities. The linker has been hacked (see ppc64elf.em) to do | |
5287 | a preliminary section layout so that we know the TLS segment | |
5288 | offsets. We can't optimize earlier because some optimizations need | |
5289 | to know the tp offset, and we need to optimize before allocating | |
5290 | dynamic relocations. */ | |
5291 | ||
5292 | bfd_boolean | |
4ce794b7 | 5293 | ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) |
951fd09b AM |
5294 | { |
5295 | bfd *ibfd; | |
5296 | asection *sec; | |
5297 | struct ppc_link_hash_table *htab; | |
5298 | ||
1049f94e | 5299 | if (info->relocatable || info->shared) |
411e1bfb AM |
5300 | return TRUE; |
5301 | ||
951fd09b | 5302 | htab = ppc_hash_table (info); |
411e1bfb AM |
5303 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5304 | { | |
5305 | Elf_Internal_Sym *locsyms = NULL; | |
5306 | ||
5307 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
5308 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
5309 | { | |
5310 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5311 | int expecting_tls_get_addr; | |
5312 | ||
5313 | /* Read the relocations. */ | |
4ce794b7 | 5314 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5315 | info->keep_memory); |
411e1bfb AM |
5316 | if (relstart == NULL) |
5317 | return FALSE; | |
5318 | ||
5319 | expecting_tls_get_addr = 0; | |
5320 | relend = relstart + sec->reloc_count; | |
5321 | for (rel = relstart; rel < relend; rel++) | |
5322 | { | |
5323 | enum elf_ppc64_reloc_type r_type; | |
5324 | unsigned long r_symndx; | |
5325 | struct elf_link_hash_entry *h; | |
5326 | Elf_Internal_Sym *sym; | |
5327 | asection *sym_sec; | |
e7b938ca AM |
5328 | char *tls_mask; |
5329 | char tls_set, tls_clear, tls_type = 0; | |
411e1bfb | 5330 | bfd_vma value; |
951fd09b | 5331 | bfd_boolean ok_tprel, is_local; |
411e1bfb AM |
5332 | |
5333 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5334 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, |
411e1bfb AM |
5335 | r_symndx, ibfd)) |
5336 | { | |
5337 | err_free_rel: | |
5338 | if (elf_section_data (sec)->relocs != relstart) | |
5339 | free (relstart); | |
5340 | if (locsyms != NULL | |
5341 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5342 | != (unsigned char *) locsyms)) | |
5343 | free (locsyms); | |
5344 | return FALSE; | |
5345 | } | |
5346 | ||
5347 | if (h != NULL) | |
5348 | { | |
5349 | if (h->root.type != bfd_link_hash_defined | |
5350 | && h->root.type != bfd_link_hash_defweak) | |
5351 | continue; | |
5352 | value = h->root.u.def.value; | |
5353 | } | |
5354 | else | |
4025353c AM |
5355 | /* Symbols referenced by TLS relocs must be of type |
5356 | STT_TLS. So no need for .opd local sym adjust. */ | |
5357 | value = sym->st_value; | |
951fd09b | 5358 | |
411e1bfb | 5359 | ok_tprel = FALSE; |
951fd09b AM |
5360 | is_local = FALSE; |
5361 | if (h == NULL | |
5362 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5363 | { |
951fd09b | 5364 | is_local = TRUE; |
411e1bfb AM |
5365 | value += sym_sec->output_offset; |
5366 | value += sym_sec->output_section->vma; | |
e1918d23 | 5367 | value -= htab->elf.tls_sec->vma; |
411e1bfb AM |
5368 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) |
5369 | < (bfd_vma) 1 << 32); | |
5370 | } | |
5371 | ||
4ce794b7 | 5372 | r_type = ELF64_R_TYPE (rel->r_info); |
411e1bfb AM |
5373 | switch (r_type) |
5374 | { | |
5375 | case R_PPC64_GOT_TLSLD16: | |
5376 | case R_PPC64_GOT_TLSLD16_LO: | |
5377 | case R_PPC64_GOT_TLSLD16_HI: | |
5378 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b AM |
5379 | /* These relocs should never be against a symbol |
5380 | defined in a shared lib. Leave them alone if | |
5381 | that turns out to be the case. */ | |
e717da7e | 5382 | ppc64_tlsld_got (ibfd)->refcount -= 1; |
951fd09b AM |
5383 | if (!is_local) |
5384 | continue; | |
5385 | ||
951fd09b AM |
5386 | /* LD -> LE */ |
5387 | tls_set = 0; | |
5388 | tls_clear = TLS_LD; | |
e7b938ca | 5389 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
5390 | expecting_tls_get_addr = 1; |
5391 | break; | |
5392 | ||
5393 | case R_PPC64_GOT_TLSGD16: | |
5394 | case R_PPC64_GOT_TLSGD16_LO: | |
5395 | case R_PPC64_GOT_TLSGD16_HI: | |
5396 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 5397 | if (ok_tprel) |
411e1bfb AM |
5398 | /* GD -> LE */ |
5399 | tls_set = 0; | |
5400 | else | |
5401 | /* GD -> IE */ | |
951fd09b AM |
5402 | tls_set = TLS_TLS | TLS_TPRELGD; |
5403 | tls_clear = TLS_GD; | |
e7b938ca | 5404 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
5405 | expecting_tls_get_addr = 1; |
5406 | break; | |
5407 | ||
5408 | case R_PPC64_GOT_TPREL16_DS: | |
5409 | case R_PPC64_GOT_TPREL16_LO_DS: | |
5410 | case R_PPC64_GOT_TPREL16_HI: | |
5411 | case R_PPC64_GOT_TPREL16_HA: | |
5412 | expecting_tls_get_addr = 0; | |
5413 | if (ok_tprel) | |
5414 | { | |
5415 | /* IE -> LE */ | |
5416 | tls_set = 0; | |
5417 | tls_clear = TLS_TPREL; | |
e7b938ca | 5418 | tls_type = TLS_TLS | TLS_TPREL; |
411e1bfb AM |
5419 | break; |
5420 | } | |
5421 | else | |
5422 | continue; | |
5423 | ||
5424 | case R_PPC64_REL14: | |
5425 | case R_PPC64_REL14_BRTAKEN: | |
5426 | case R_PPC64_REL14_BRNTAKEN: | |
5427 | case R_PPC64_REL24: | |
5428 | if (h != NULL | |
5429 | && h == htab->tls_get_addr) | |
5430 | { | |
5431 | if (!expecting_tls_get_addr | |
5432 | && rel != relstart | |
5433 | && ((ELF64_R_TYPE (rel[-1].r_info) | |
5434 | == R_PPC64_TOC16) | |
5435 | || (ELF64_R_TYPE (rel[-1].r_info) | |
5436 | == R_PPC64_TOC16_LO))) | |
5437 | { | |
5438 | /* Check for toc tls entries. */ | |
5439 | char *toc_tls; | |
951fd09b | 5440 | int retval; |
411e1bfb | 5441 | |
0d4792f7 | 5442 | retval = get_tls_mask (&toc_tls, NULL, &locsyms, |
951fd09b AM |
5443 | rel - 1, ibfd); |
5444 | if (retval == 0) | |
411e1bfb AM |
5445 | goto err_free_rel; |
5446 | if (toc_tls != NULL) | |
951fd09b | 5447 | expecting_tls_get_addr = retval > 1; |
411e1bfb AM |
5448 | } |
5449 | ||
5450 | if (expecting_tls_get_addr) | |
5451 | { | |
5452 | struct plt_entry *ent; | |
5453 | for (ent = h->plt.plist; ent; ent = ent->next) | |
5454 | if (ent->addend == 0) | |
5455 | { | |
5456 | if (ent->plt.refcount > 0) | |
5457 | ent->plt.refcount -= 1; | |
5458 | break; | |
5459 | } | |
5460 | } | |
5461 | } | |
5462 | expecting_tls_get_addr = 0; | |
5463 | continue; | |
5464 | ||
5465 | case R_PPC64_TPREL64: | |
5466 | expecting_tls_get_addr = 0; | |
5467 | if (ok_tprel) | |
5468 | { | |
5469 | /* IE -> LE */ | |
5470 | tls_set = TLS_EXPLICIT; | |
5471 | tls_clear = TLS_TPREL; | |
5472 | break; | |
5473 | } | |
5474 | else | |
5475 | continue; | |
5476 | ||
5477 | case R_PPC64_DTPMOD64: | |
5478 | expecting_tls_get_addr = 0; | |
951fd09b AM |
5479 | if (rel + 1 < relend |
5480 | && (rel[1].r_info | |
5481 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) | |
5482 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 5483 | { |
951fd09b | 5484 | if (ok_tprel) |
411e1bfb | 5485 | /* GD -> LE */ |
951fd09b | 5486 | tls_set = TLS_EXPLICIT | TLS_GD; |
411e1bfb AM |
5487 | else |
5488 | /* GD -> IE */ | |
951fd09b AM |
5489 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; |
5490 | tls_clear = TLS_GD; | |
411e1bfb AM |
5491 | } |
5492 | else | |
5493 | { | |
951fd09b AM |
5494 | if (!is_local) |
5495 | continue; | |
5496 | ||
5497 | /* LD -> LE */ | |
5498 | tls_set = TLS_EXPLICIT; | |
5499 | tls_clear = TLS_LD; | |
411e1bfb AM |
5500 | } |
5501 | break; | |
5502 | ||
5503 | default: | |
5504 | expecting_tls_get_addr = 0; | |
5505 | continue; | |
5506 | } | |
5507 | ||
5508 | if ((tls_set & TLS_EXPLICIT) == 0) | |
5509 | { | |
5510 | struct got_entry *ent; | |
5511 | ||
5512 | /* Adjust got entry for this reloc. */ | |
5513 | if (h != NULL) | |
5514 | ent = h->got.glist; | |
5515 | else | |
5516 | ent = elf_local_got_ents (ibfd)[r_symndx]; | |
5517 | ||
5518 | for (; ent != NULL; ent = ent->next) | |
5519 | if (ent->addend == rel->r_addend | |
e717da7e | 5520 | && ent->owner == ibfd |
e7b938ca | 5521 | && ent->tls_type == tls_type) |
411e1bfb AM |
5522 | break; |
5523 | if (ent == NULL) | |
5524 | abort (); | |
5525 | ||
5526 | if (tls_set == 0) | |
5527 | { | |
5528 | /* We managed to get rid of a got entry. */ | |
5529 | if (ent->got.refcount > 0) | |
5530 | ent->got.refcount -= 1; | |
5531 | } | |
411e1bfb AM |
5532 | } |
5533 | else if (h != NULL) | |
5534 | { | |
5535 | struct ppc_link_hash_entry * eh; | |
5536 | struct ppc_dyn_relocs **pp; | |
5537 | struct ppc_dyn_relocs *p; | |
5538 | ||
5539 | /* Adjust dynamic relocs. */ | |
5540 | eh = (struct ppc_link_hash_entry *) h; | |
5541 | for (pp = &eh->dyn_relocs; | |
5542 | (p = *pp) != NULL; | |
5543 | pp = &p->next) | |
5544 | if (p->sec == sec) | |
5545 | { | |
5546 | /* If we got rid of a DTPMOD/DTPREL reloc | |
5547 | pair then we'll lose one or two dyn | |
5548 | relocs. */ | |
951fd09b | 5549 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
411e1bfb | 5550 | p->count -= 1; |
951fd09b | 5551 | p->count -= 1; |
411e1bfb AM |
5552 | if (p->count == 0) |
5553 | *pp = p->next; | |
5554 | break; | |
5555 | } | |
5556 | } | |
5557 | ||
e7b938ca AM |
5558 | *tls_mask |= tls_set; |
5559 | *tls_mask &= ~tls_clear; | |
411e1bfb AM |
5560 | } |
5561 | ||
5562 | if (elf_section_data (sec)->relocs != relstart) | |
5563 | free (relstart); | |
5564 | } | |
5565 | ||
5566 | if (locsyms != NULL | |
5567 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5568 | != (unsigned char *) locsyms)) | |
6cdc0ccc AM |
5569 | { |
5570 | if (!info->keep_memory) | |
411e1bfb | 5571 | free (locsyms); |
6cdc0ccc | 5572 | else |
411e1bfb | 5573 | elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; |
6cdc0ccc | 5574 | } |
1e2f5b6e | 5575 | } |
b34976b6 | 5576 | return TRUE; |
1e2f5b6e | 5577 | } |
b34976b6 | 5578 | |
65f38f15 AM |
5579 | /* Allocate space in .plt, .got and associated reloc sections for |
5580 | dynamic relocs. */ | |
5bd4f169 | 5581 | |
b34976b6 | 5582 | static bfd_boolean |
4ce794b7 | 5583 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 5584 | { |
65f38f15 AM |
5585 | struct bfd_link_info *info; |
5586 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 5587 | asection *s; |
65f38f15 AM |
5588 | struct ppc_link_hash_entry *eh; |
5589 | struct ppc_dyn_relocs *p; | |
411e1bfb | 5590 | struct got_entry *gent; |
5bd4f169 | 5591 | |
e92d460e | 5592 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5593 | return TRUE; |
5bd4f169 | 5594 | |
e92d460e AM |
5595 | if (h->root.type == bfd_link_hash_warning) |
5596 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5597 | ||
65f38f15 AM |
5598 | info = (struct bfd_link_info *) inf; |
5599 | htab = ppc_hash_table (info); | |
5bd4f169 | 5600 | |
65f38f15 | 5601 | if (htab->elf.dynamic_sections_created |
411e1bfb | 5602 | && h->dynindx != -1 |
9c7a29a3 | 5603 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) |
5bd4f169 | 5604 | { |
411e1bfb AM |
5605 | struct plt_entry *pent; |
5606 | bfd_boolean doneone = FALSE; | |
5607 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) | |
5608 | if (pent->plt.refcount > 0) | |
5609 | { | |
5610 | BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor); | |
5611 | ||
5612 | /* If this is the first .plt entry, make room for the special | |
5613 | first entry. */ | |
4ce794b7 | 5614 | s = htab->plt; |
eea6121a AM |
5615 | if (s->size == 0) |
5616 | s->size += PLT_INITIAL_ENTRY_SIZE; | |
411e1bfb | 5617 | |
eea6121a | 5618 | pent->plt.offset = s->size; |
411e1bfb AM |
5619 | |
5620 | /* Make room for this entry. */ | |
eea6121a | 5621 | s->size += PLT_ENTRY_SIZE; |
411e1bfb AM |
5622 | |
5623 | /* Make room for the .glink code. */ | |
4ce794b7 | 5624 | s = htab->glink; |
eea6121a AM |
5625 | if (s->size == 0) |
5626 | s->size += GLINK_CALL_STUB_SIZE; | |
411e1bfb | 5627 | /* We need bigger stubs past index 32767. */ |
eea6121a AM |
5628 | if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4) |
5629 | s->size += 4; | |
5630 | s->size += 2*4; | |
411e1bfb AM |
5631 | |
5632 | /* We also need to make an entry in the .rela.plt section. */ | |
4ce794b7 | 5633 | s = htab->relplt; |
eea6121a | 5634 | s->size += sizeof (Elf64_External_Rela); |
411e1bfb AM |
5635 | doneone = TRUE; |
5636 | } | |
5637 | else | |
5638 | pent->plt.offset = (bfd_vma) -1; | |
5639 | if (!doneone) | |
65f38f15 | 5640 | { |
411e1bfb | 5641 | h->plt.plist = NULL; |
65f38f15 AM |
5642 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5643 | } | |
5644 | } | |
5645 | else | |
5646 | { | |
411e1bfb | 5647 | h->plt.plist = NULL; |
65f38f15 AM |
5648 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5649 | } | |
5650 | ||
951fd09b AM |
5651 | eh = (struct ppc_link_hash_entry *) h; |
5652 | /* Run through the TLS GD got entries first if we're changing them | |
5653 | to TPREL. */ | |
e7b938ca | 5654 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
951fd09b AM |
5655 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5656 | if (gent->got.refcount > 0 | |
5657 | && (gent->tls_type & TLS_GD) != 0) | |
5658 | { | |
5659 | /* This was a GD entry that has been converted to TPREL. If | |
5660 | there happens to be a TPREL entry we can use that one. */ | |
5661 | struct got_entry *ent; | |
5662 | for (ent = h->got.glist; ent != NULL; ent = ent->next) | |
5663 | if (ent->got.refcount > 0 | |
5664 | && (ent->tls_type & TLS_TPREL) != 0 | |
e717da7e AM |
5665 | && ent->addend == gent->addend |
5666 | && ent->owner == gent->owner) | |
951fd09b AM |
5667 | { |
5668 | gent->got.refcount = 0; | |
5669 | break; | |
5670 | } | |
5671 | ||
5672 | /* If not, then we'll be using our own TPREL entry. */ | |
5673 | if (gent->got.refcount != 0) | |
5674 | gent->tls_type = TLS_TLS | TLS_TPREL; | |
5675 | } | |
5676 | ||
411e1bfb AM |
5677 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5678 | if (gent->got.refcount > 0) | |
5679 | { | |
951fd09b AM |
5680 | bfd_boolean dyn; |
5681 | ||
411e1bfb | 5682 | /* Make sure this symbol is output as a dynamic symbol. |
951fd09b AM |
5683 | Undefined weak syms won't yet be marked as dynamic, |
5684 | nor will all TLS symbols. */ | |
411e1bfb AM |
5685 | if (h->dynindx == -1 |
5686 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5687 | { | |
c152c796 | 5688 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
411e1bfb AM |
5689 | return FALSE; |
5690 | } | |
65f38f15 | 5691 | |
d881513a AM |
5692 | if ((gent->tls_type & TLS_LD) != 0 |
5693 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5694 | { |
e717da7e | 5695 | gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; |
951fd09b | 5696 | continue; |
411e1bfb | 5697 | } |
951fd09b | 5698 | |
e717da7e | 5699 | s = ppc64_elf_tdata (gent->owner)->got; |
eea6121a AM |
5700 | gent->got.offset = s->size; |
5701 | s->size | |
d881513a | 5702 | += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; |
951fd09b | 5703 | dyn = htab->elf.dynamic_sections_created; |
4e795f50 AM |
5704 | if ((info->shared |
5705 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
5706 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5707 | || h->root.type != bfd_link_hash_undefweak)) | |
eea6121a | 5708 | ppc64_elf_tdata (gent->owner)->relgot->size |
e7b938ca | 5709 | += (gent->tls_type & eh->tls_mask & TLS_GD |
951fd09b AM |
5710 | ? 2 * sizeof (Elf64_External_Rela) |
5711 | : sizeof (Elf64_External_Rela)); | |
411e1bfb AM |
5712 | } |
5713 | else | |
5714 | gent->got.offset = (bfd_vma) -1; | |
65f38f15 | 5715 | |
65f38f15 | 5716 | if (eh->dyn_relocs == NULL) |
b34976b6 | 5717 | return TRUE; |
65f38f15 AM |
5718 | |
5719 | /* In the shared -Bsymbolic case, discard space allocated for | |
5720 | dynamic pc-relative relocs against symbols which turn out to be | |
5721 | defined in regular objects. For the normal shared case, discard | |
5722 | space for relocs that have become local due to symbol visibility | |
5723 | changes. */ | |
5724 | ||
5725 | if (info->shared) | |
5726 | { | |
9c7a29a3 AM |
5727 | /* Relocs that use pc_count are those that appear on a call insn, |
5728 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | |
5729 | generated via assembly. We want calls to protected symbols to | |
5730 | resolve directly to the function rather than going via the plt. | |
5731 | If people want function pointer comparisons to work as expected | |
5732 | then they should avoid writing weird assembly. */ | |
09695f56 | 5733 | if (SYMBOL_CALLS_LOCAL (info, h)) |
65f38f15 AM |
5734 | { |
5735 | struct ppc_dyn_relocs **pp; | |
5736 | ||
5737 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 5738 | { |
65f38f15 AM |
5739 | p->count -= p->pc_count; |
5740 | p->pc_count = 0; | |
5741 | if (p->count == 0) | |
5742 | *pp = p->next; | |
5743 | else | |
5744 | pp = &p->next; | |
5bd4f169 | 5745 | } |
65f38f15 | 5746 | } |
4e795f50 AM |
5747 | |
5748 | /* Also discard relocs on undefined weak syms with non-default | |
5749 | visibility. */ | |
5750 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
5751 | && h->root.type == bfd_link_hash_undefweak) | |
5752 | eh->dyn_relocs = NULL; | |
65f38f15 | 5753 | } |
f4656909 | 5754 | else if (ELIMINATE_COPY_RELOCS) |
65f38f15 AM |
5755 | { |
5756 | /* For the non-shared case, discard space for relocs against | |
5757 | symbols which turn out to need copy relocs or are not | |
5758 | dynamic. */ | |
5759 | ||
5760 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
5761 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
5762 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
65f38f15 AM |
5763 | { |
5764 | /* Make sure this symbol is output as a dynamic symbol. | |
5765 | Undefined weak syms won't yet be marked as dynamic. */ | |
5766 | if (h->dynindx == -1 | |
5767 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5768 | { | |
c152c796 | 5769 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 5770 | return FALSE; |
65f38f15 AM |
5771 | } |
5772 | ||
5773 | /* If that succeeded, we know we'll be keeping all the | |
5774 | relocs. */ | |
5775 | if (h->dynindx != -1) | |
5776 | goto keep; | |
5777 | } | |
5778 | ||
5779 | eh->dyn_relocs = NULL; | |
5780 | ||
ec338859 | 5781 | keep: ; |
65f38f15 AM |
5782 | } |
5783 | ||
5784 | /* Finally, allocate space. */ | |
5785 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5786 | { | |
5787 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
eea6121a | 5788 | sreloc->size += p->count * sizeof (Elf64_External_Rela); |
65f38f15 AM |
5789 | } |
5790 | ||
b34976b6 | 5791 | return TRUE; |
65f38f15 AM |
5792 | } |
5793 | ||
5794 | /* Find any dynamic relocs that apply to read-only sections. */ | |
5795 | ||
b34976b6 | 5796 | static bfd_boolean |
4ce794b7 | 5797 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
65f38f15 AM |
5798 | { |
5799 | struct ppc_link_hash_entry *eh; | |
5800 | struct ppc_dyn_relocs *p; | |
5801 | ||
e92d460e AM |
5802 | if (h->root.type == bfd_link_hash_warning) |
5803 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5804 | ||
65f38f15 AM |
5805 | eh = (struct ppc_link_hash_entry *) h; |
5806 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5807 | { | |
5808 | asection *s = p->sec->output_section; | |
5809 | ||
5810 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
5811 | { | |
4ce794b7 | 5812 | struct bfd_link_info *info = inf; |
65f38f15 AM |
5813 | |
5814 | info->flags |= DF_TEXTREL; | |
5815 | ||
5816 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 5817 | return FALSE; |
65f38f15 AM |
5818 | } |
5819 | } | |
b34976b6 | 5820 | return TRUE; |
65f38f15 AM |
5821 | } |
5822 | ||
5823 | /* Set the sizes of the dynamic sections. */ | |
5824 | ||
b34976b6 | 5825 | static bfd_boolean |
4ce794b7 AM |
5826 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
5827 | struct bfd_link_info *info) | |
65f38f15 AM |
5828 | { |
5829 | struct ppc_link_hash_table *htab; | |
5830 | bfd *dynobj; | |
5831 | asection *s; | |
b34976b6 | 5832 | bfd_boolean relocs; |
65f38f15 AM |
5833 | bfd *ibfd; |
5834 | ||
5835 | htab = ppc_hash_table (info); | |
5836 | dynobj = htab->elf.dynobj; | |
5837 | if (dynobj == NULL) | |
5838 | abort (); | |
5839 | ||
5840 | if (htab->elf.dynamic_sections_created) | |
5841 | { | |
5842 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 5843 | if (info->executable) |
65f38f15 AM |
5844 | { |
5845 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
5846 | if (s == NULL) | |
5847 | abort (); | |
eea6121a | 5848 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
65f38f15 AM |
5849 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
5850 | } | |
5851 | } | |
5852 | ||
5853 | /* Set up .got offsets for local syms, and space for local dynamic | |
5854 | relocs. */ | |
5855 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
5856 | { | |
411e1bfb AM |
5857 | struct got_entry **lgot_ents; |
5858 | struct got_entry **end_lgot_ents; | |
e7b938ca | 5859 | char *lgot_masks; |
65f38f15 AM |
5860 | bfd_size_type locsymcount; |
5861 | Elf_Internal_Shdr *symtab_hdr; | |
5862 | asection *srel; | |
5863 | ||
5864 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
5865 | continue; | |
5866 | ||
e717da7e AM |
5867 | if (ppc64_tlsld_got (ibfd)->refcount > 0) |
5868 | { | |
5869 | s = ppc64_elf_tdata (ibfd)->got; | |
eea6121a AM |
5870 | ppc64_tlsld_got (ibfd)->offset = s->size; |
5871 | s->size += 16; | |
e717da7e AM |
5872 | if (info->shared) |
5873 | { | |
5874 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
eea6121a | 5875 | srel->size += sizeof (Elf64_External_Rela); |
e717da7e AM |
5876 | } |
5877 | } | |
5878 | else | |
5879 | ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; | |
5880 | ||
65f38f15 AM |
5881 | for (s = ibfd->sections; s != NULL; s = s->next) |
5882 | { | |
ec338859 | 5883 | struct ppc_dyn_relocs *p; |
65f38f15 | 5884 | |
ec338859 AM |
5885 | for (p = *((struct ppc_dyn_relocs **) |
5886 | &elf_section_data (s)->local_dynrel); | |
5887 | p != NULL; | |
5888 | p = p->next) | |
65f38f15 | 5889 | { |
ec338859 AM |
5890 | if (!bfd_is_abs_section (p->sec) |
5891 | && bfd_is_abs_section (p->sec->output_section)) | |
5892 | { | |
5893 | /* Input section has been discarded, either because | |
5894 | it is a copy of a linkonce section or due to | |
5895 | linker script /DISCARD/, so we'll be discarding | |
5896 | the relocs too. */ | |
5897 | } | |
248866a8 | 5898 | else if (p->count != 0) |
ec338859 AM |
5899 | { |
5900 | srel = elf_section_data (p->sec)->sreloc; | |
eea6121a | 5901 | srel->size += p->count * sizeof (Elf64_External_Rela); |
248866a8 AM |
5902 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
5903 | info->flags |= DF_TEXTREL; | |
ec338859 | 5904 | } |
65f38f15 AM |
5905 | } |
5906 | } | |
5907 | ||
411e1bfb AM |
5908 | lgot_ents = elf_local_got_ents (ibfd); |
5909 | if (!lgot_ents) | |
65f38f15 AM |
5910 | continue; |
5911 | ||
5912 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5913 | locsymcount = symtab_hdr->sh_info; | |
411e1bfb | 5914 | end_lgot_ents = lgot_ents + locsymcount; |
e7b938ca | 5915 | lgot_masks = (char *) end_lgot_ents; |
e717da7e AM |
5916 | s = ppc64_elf_tdata (ibfd)->got; |
5917 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
e7b938ca | 5918 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
65f38f15 | 5919 | { |
411e1bfb AM |
5920 | struct got_entry *ent; |
5921 | ||
5922 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) | |
5923 | if (ent->got.refcount > 0) | |
5924 | { | |
e7b938ca | 5925 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
411e1bfb | 5926 | { |
e717da7e | 5927 | if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) |
411e1bfb | 5928 | { |
eea6121a AM |
5929 | ppc64_tlsld_got (ibfd)->offset = s->size; |
5930 | s->size += 16; | |
411e1bfb | 5931 | if (info->shared) |
eea6121a | 5932 | srel->size += sizeof (Elf64_External_Rela); |
411e1bfb | 5933 | } |
e717da7e | 5934 | ent->got.offset = ppc64_tlsld_got (ibfd)->offset; |
411e1bfb AM |
5935 | } |
5936 | else | |
5937 | { | |
eea6121a | 5938 | ent->got.offset = s->size; |
e7b938ca | 5939 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
411e1bfb | 5940 | { |
eea6121a | 5941 | s->size += 16; |
411e1bfb | 5942 | if (info->shared) |
eea6121a | 5943 | srel->size += 2 * sizeof (Elf64_External_Rela); |
411e1bfb AM |
5944 | } |
5945 | else | |
5946 | { | |
eea6121a | 5947 | s->size += 8; |
411e1bfb | 5948 | if (info->shared) |
eea6121a | 5949 | srel->size += sizeof (Elf64_External_Rela); |
411e1bfb AM |
5950 | } |
5951 | } | |
5952 | } | |
5953 | else | |
5954 | ent->got.offset = (bfd_vma) -1; | |
65f38f15 AM |
5955 | } |
5956 | } | |
5957 | ||
5958 | /* Allocate global sym .plt and .got entries, and space for global | |
5959 | sym dynamic relocs. */ | |
4ce794b7 | 5960 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
65f38f15 AM |
5961 | |
5962 | /* We now have determined the sizes of the various dynamic sections. | |
5963 | Allocate memory for them. */ | |
b34976b6 | 5964 | relocs = FALSE; |
65f38f15 AM |
5965 | for (s = dynobj->sections; s != NULL; s = s->next) |
5966 | { | |
5967 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
5968 | continue; | |
5969 | ||
4ce794b7 | 5970 | if (s == htab->brlt || s == htab->relbrlt) |
721956f4 AM |
5971 | /* These haven't been allocated yet; don't strip. */ |
5972 | continue; | |
e717da7e AM |
5973 | else if (s == htab->got |
5974 | || s == htab->plt | |
4ce794b7 | 5975 | || s == htab->glink) |
65f38f15 AM |
5976 | { |
5977 | /* Strip this section if we don't need it; see the | |
5978 | comment below. */ | |
5bd4f169 | 5979 | } |
65f38f15 | 5980 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 | 5981 | { |
eea6121a | 5982 | if (s->size == 0) |
5bd4f169 AM |
5983 | { |
5984 | /* If we don't need this section, strip it from the | |
5985 | output file. This is mostly to handle .rela.bss and | |
5986 | .rela.plt. We must create both sections in | |
5987 | create_dynamic_sections, because they must be created | |
5988 | before the linker maps input sections to output | |
5989 | sections. The linker does that before | |
5990 | adjust_dynamic_symbol is called, and it is that | |
5991 | function which decides whether anything needs to go | |
5992 | into these sections. */ | |
5bd4f169 AM |
5993 | } |
5994 | else | |
5995 | { | |
4ce794b7 | 5996 | if (s != htab->relplt) |
b34976b6 | 5997 | relocs = TRUE; |
5bd4f169 AM |
5998 | |
5999 | /* We use the reloc_count field as a counter if we need | |
6000 | to copy relocs into the output file. */ | |
6001 | s->reloc_count = 0; | |
6002 | } | |
6003 | } | |
65f38f15 | 6004 | else |
5bd4f169 AM |
6005 | { |
6006 | /* It's not one of our sections, so don't allocate space. */ | |
6007 | continue; | |
6008 | } | |
6009 | ||
eea6121a | 6010 | if (s->size == 0) |
5bd4f169 AM |
6011 | { |
6012 | _bfd_strip_section_from_output (info, s); | |
6013 | continue; | |
6014 | } | |
6015 | ||
5f333394 | 6016 | /* .plt is in the bss section. We don't initialise it. */ |
680a3378 | 6017 | if (s == htab->plt) |
5f333394 AM |
6018 | continue; |
6019 | ||
65f38f15 AM |
6020 | /* Allocate memory for the section contents. We use bfd_zalloc |
6021 | here in case unused entries are not reclaimed before the | |
6022 | section's contents are written out. This should not happen, | |
411e1bfb AM |
6023 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
6024 | sections instead of garbage. | |
6025 | We also rely on the section contents being zero when writing | |
6026 | the GOT. */ | |
eea6121a | 6027 | s->contents = bfd_zalloc (dynobj, s->size); |
65f38f15 | 6028 | if (s->contents == NULL) |
b34976b6 | 6029 | return FALSE; |
5bd4f169 AM |
6030 | } |
6031 | ||
e717da7e AM |
6032 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
6033 | { | |
6034 | s = ppc64_elf_tdata (ibfd)->got; | |
6035 | if (s != NULL && s != htab->got) | |
6036 | { | |
eea6121a | 6037 | if (s->size == 0) |
e717da7e AM |
6038 | _bfd_strip_section_from_output (info, s); |
6039 | else | |
6040 | { | |
eea6121a | 6041 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
6042 | if (s->contents == NULL) |
6043 | return FALSE; | |
6044 | } | |
6045 | } | |
6046 | s = ppc64_elf_tdata (ibfd)->relgot; | |
6047 | if (s != NULL) | |
6048 | { | |
eea6121a | 6049 | if (s->size == 0) |
e717da7e AM |
6050 | _bfd_strip_section_from_output (info, s); |
6051 | else | |
6052 | { | |
eea6121a | 6053 | s->contents = bfd_zalloc (ibfd, s->size); |
e717da7e AM |
6054 | if (s->contents == NULL) |
6055 | return FALSE; | |
6056 | relocs = TRUE; | |
6057 | s->reloc_count = 0; | |
6058 | } | |
6059 | } | |
6060 | } | |
6061 | ||
e86ce104 | 6062 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
6063 | { |
6064 | /* Add some entries to the .dynamic section. We fill in the | |
6065 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
6066 | must add the entries now so that we get the correct size for | |
6067 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
6068 | dynamic linker and used by the debugger. */ | |
dc810e39 | 6069 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 6070 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 6071 | |
36af4a4e | 6072 | if (info->executable) |
5bd4f169 | 6073 | { |
dc810e39 | 6074 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 6075 | return FALSE; |
5bd4f169 AM |
6076 | } |
6077 | ||
eea6121a | 6078 | if (htab->plt != NULL && htab->plt->size != 0) |
5bd4f169 | 6079 | { |
dc810e39 AM |
6080 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
6081 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
6082 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
6083 | || !add_dynamic_entry (DT_JMPREL, 0) |
6084 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 6085 | return FALSE; |
5bd4f169 AM |
6086 | } |
6087 | ||
19397422 AM |
6088 | if (NO_OPD_RELOCS) |
6089 | { | |
6090 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
6091 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 6092 | return FALSE; |
19397422 AM |
6093 | } |
6094 | ||
5bd4f169 AM |
6095 | if (relocs) |
6096 | { | |
dc810e39 AM |
6097 | if (!add_dynamic_entry (DT_RELA, 0) |
6098 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6099 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 6100 | return FALSE; |
5bd4f169 | 6101 | |
65f38f15 AM |
6102 | /* If any dynamic relocs apply to a read-only section, |
6103 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 6104 | if ((info->flags & DF_TEXTREL) == 0) |
4ce794b7 | 6105 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
5bd4f169 | 6106 | |
65f38f15 | 6107 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 6108 | { |
65f38f15 | 6109 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 6110 | return FALSE; |
5bd4f169 | 6111 | } |
5bd4f169 | 6112 | } |
5bd4f169 | 6113 | } |
65f38f15 | 6114 | #undef add_dynamic_entry |
5bd4f169 | 6115 | |
b34976b6 | 6116 | return TRUE; |
5bd4f169 AM |
6117 | } |
6118 | ||
721956f4 | 6119 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 6120 | |
4ce794b7 AM |
6121 | static inline enum ppc_stub_type |
6122 | ppc_type_of_stub (asection *input_sec, | |
6123 | const Elf_Internal_Rela *rel, | |
6124 | struct ppc_link_hash_entry **hash, | |
6125 | bfd_vma destination) | |
5bd4f169 | 6126 | { |
721956f4 AM |
6127 | struct ppc_link_hash_entry *h = *hash; |
6128 | bfd_vma location; | |
6129 | bfd_vma branch_offset; | |
6130 | bfd_vma max_branch_offset; | |
4ce794b7 | 6131 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 | 6132 | |
721956f4 AM |
6133 | if (h != NULL) |
6134 | { | |
6135 | if (h->oh != NULL | |
34814b9f | 6136 | && h->oh->elf.dynindx != -1) |
5bd4f169 | 6137 | { |
411e1bfb | 6138 | struct plt_entry *ent; |
34814b9f | 6139 | for (ent = h->oh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
6140 | if (ent->addend == rel->r_addend |
6141 | && ent->plt.offset != (bfd_vma) -1) | |
6142 | { | |
34814b9f | 6143 | *hash = h->oh; |
411e1bfb AM |
6144 | return ppc_stub_plt_call; |
6145 | } | |
5bd4f169 AM |
6146 | } |
6147 | ||
ee7de3e6 AM |
6148 | if (!(h->elf.root.type == bfd_link_hash_defined |
6149 | || h->elf.root.type == bfd_link_hash_defweak) | |
6150 | || h->elf.root.u.def.section->output_section == NULL) | |
721956f4 | 6151 | return ppc_stub_none; |
5d1634d7 | 6152 | } |
5d1634d7 | 6153 | |
721956f4 AM |
6154 | /* Determine where the call point is. */ |
6155 | location = (input_sec->output_offset | |
6156 | + input_sec->output_section->vma | |
6157 | + rel->r_offset); | |
5d1634d7 | 6158 | |
721956f4 AM |
6159 | branch_offset = destination - location; |
6160 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 6161 | |
721956f4 AM |
6162 | /* Determine if a long branch stub is needed. */ |
6163 | max_branch_offset = 1 << 25; | |
4ce794b7 | 6164 | if (r_type != R_PPC64_REL24) |
721956f4 | 6165 | max_branch_offset = 1 << 15; |
5d1634d7 | 6166 | |
721956f4 AM |
6167 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
6168 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
6169 | is needed later. */ | |
6170 | return ppc_stub_long_branch; | |
5d1634d7 | 6171 | |
721956f4 | 6172 | return ppc_stub_none; |
5d1634d7 AM |
6173 | } |
6174 | ||
6175 | /* Build a .plt call stub. */ | |
6176 | ||
4ce794b7 AM |
6177 | static inline bfd_byte * |
6178 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset) | |
5d1634d7 AM |
6179 | { |
6180 | #define PPC_LO(v) ((v) & 0xffff) | |
6181 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6182 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6183 | ||
5d1634d7 | 6184 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
ad8e1ba5 | 6185 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
5d1634d7 AM |
6186 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
6187 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6188 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6189 | offset += 8; |
6190 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
6191 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6192 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6193 | offset += 8; |
6194 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
6195 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
6196 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
6197 | return p; | |
6198 | } | |
6199 | ||
b34976b6 | 6200 | static bfd_boolean |
4ce794b7 | 6201 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
5d1634d7 | 6202 | { |
721956f4 AM |
6203 | struct ppc_stub_hash_entry *stub_entry; |
6204 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
6205 | struct bfd_link_info *info; |
6206 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
6207 | bfd_byte *loc; |
6208 | bfd_byte *p; | |
6209 | unsigned int indx; | |
411e1bfb | 6210 | struct plt_entry *ent; |
721956f4 AM |
6211 | bfd_vma off; |
6212 | int size; | |
5d1634d7 | 6213 | |
721956f4 AM |
6214 | /* Massage our args to the form they really have. */ |
6215 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6216 | info = in_arg; |
5d1634d7 | 6217 | |
5d1634d7 AM |
6218 | htab = ppc_hash_table (info); |
6219 | ||
721956f4 | 6220 | /* Make a note of the offset within the stubs for this entry. */ |
eea6121a | 6221 | stub_entry->stub_offset = stub_entry->stub_sec->size; |
97b639ba | 6222 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; |
721956f4 | 6223 | |
4ce794b7 | 6224 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
721956f4 | 6225 | switch (stub_entry->stub_type) |
5d1634d7 | 6226 | { |
721956f4 | 6227 | case ppc_stub_long_branch: |
ad8e1ba5 | 6228 | case ppc_stub_long_branch_r2off: |
721956f4 AM |
6229 | /* Branches are relative. This is where we are going to. */ |
6230 | off = (stub_entry->target_value | |
6231 | + stub_entry->target_section->output_offset | |
6232 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 6233 | |
721956f4 AM |
6234 | /* And this is where we are coming from. */ |
6235 | off -= (stub_entry->stub_offset | |
97b639ba AM |
6236 | + stub_entry->stub_sec->output_offset |
6237 | + stub_entry->stub_sec->output_section->vma); | |
e86ce104 | 6238 | |
ad8e1ba5 AM |
6239 | if (stub_entry->stub_type != ppc_stub_long_branch_r2off) |
6240 | size = 4; | |
6241 | else | |
6242 | { | |
6243 | bfd_vma r2off; | |
6244 | ||
6245 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6246 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6247 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6248 | loc += 4; |
97b639ba | 6249 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6250 | loc += 4; |
97b639ba | 6251 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6252 | loc += 4; |
6253 | off -= 12; | |
6254 | size = 16; | |
6255 | } | |
97b639ba | 6256 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
ad8e1ba5 AM |
6257 | |
6258 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); | |
721956f4 | 6259 | break; |
e86ce104 | 6260 | |
721956f4 | 6261 | case ppc_stub_plt_branch: |
ad8e1ba5 | 6262 | case ppc_stub_plt_branch_r2off: |
721956f4 AM |
6263 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
6264 | stub_entry->root.string + 9, | |
b34976b6 | 6265 | FALSE, FALSE); |
721956f4 AM |
6266 | if (br_entry == NULL) |
6267 | { | |
6268 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), | |
6269 | stub_entry->root.string + 9); | |
b34976b6 AM |
6270 | htab->stub_error = TRUE; |
6271 | return FALSE; | |
721956f4 AM |
6272 | } |
6273 | ||
6274 | off = (stub_entry->target_value | |
6275 | + stub_entry->target_section->output_offset | |
6276 | + stub_entry->target_section->output_section->vma); | |
6277 | ||
4ce794b7 AM |
6278 | bfd_put_64 (htab->brlt->owner, off, |
6279 | htab->brlt->contents + br_entry->offset); | |
721956f4 AM |
6280 | |
6281 | if (info->shared) | |
6282 | { | |
6283 | /* Create a reloc for the branch lookup table entry. */ | |
6284 | Elf_Internal_Rela rela; | |
ad8e1ba5 | 6285 | bfd_byte *rl; |
5d1634d7 | 6286 | |
721956f4 | 6287 | rela.r_offset = (br_entry->offset |
4ce794b7 AM |
6288 | + htab->brlt->output_offset |
6289 | + htab->brlt->output_section->vma); | |
721956f4 AM |
6290 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
6291 | rela.r_addend = off; | |
6292 | ||
4ce794b7 AM |
6293 | rl = htab->relbrlt->contents; |
6294 | rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela); | |
6295 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); | |
721956f4 AM |
6296 | } |
6297 | ||
6298 | off = (br_entry->offset | |
4ce794b7 AM |
6299 | + htab->brlt->output_offset |
6300 | + htab->brlt->output_section->vma | |
6301 | - elf_gp (htab->brlt->output_section->owner) | |
ad8e1ba5 | 6302 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6303 | |
ad8e1ba5 | 6304 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
5d1634d7 AM |
6305 | { |
6306 | (*_bfd_error_handler) | |
e86ce104 | 6307 | (_("linkage table error against `%s'"), |
721956f4 | 6308 | stub_entry->root.string); |
5d1634d7 | 6309 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
6310 | htab->stub_error = TRUE; |
6311 | return FALSE; | |
5d1634d7 | 6312 | } |
41bd81ab | 6313 | |
721956f4 | 6314 | indx = off; |
ad8e1ba5 AM |
6315 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
6316 | { | |
97b639ba | 6317 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6318 | loc += 4; |
97b639ba | 6319 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 AM |
6320 | size = 16; |
6321 | } | |
6322 | else | |
6323 | { | |
6324 | bfd_vma r2off; | |
6325 | ||
6326 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6327 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6328 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6329 | loc += 4; |
97b639ba | 6330 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6331 | loc += 4; |
97b639ba | 6332 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 | 6333 | loc += 4; |
97b639ba | 6334 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6335 | loc += 4; |
97b639ba | 6336 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6337 | size = 28; |
6338 | } | |
6339 | loc += 4; | |
97b639ba | 6340 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
ad8e1ba5 | 6341 | loc += 4; |
97b639ba | 6342 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
721956f4 | 6343 | break; |
5d1634d7 | 6344 | |
721956f4 | 6345 | case ppc_stub_plt_call: |
c862ae31 AM |
6346 | /* Do the best we can for shared libraries built without |
6347 | exporting ".foo" for each "foo". This can happen when symbol | |
6348 | versioning scripts strip all bar a subset of symbols. */ | |
34814b9f AM |
6349 | if (stub_entry->h->oh->elf.root.type != bfd_link_hash_defined |
6350 | && stub_entry->h->oh->elf.root.type != bfd_link_hash_defweak) | |
c862ae31 AM |
6351 | { |
6352 | /* Point the symbol at the stub. There may be multiple stubs, | |
6353 | we don't really care; The main thing is to make this sym | |
8f3bab57 AM |
6354 | defined somewhere. Maybe defining the symbol in the stub |
6355 | section is a silly idea. If we didn't do this, htab->top_id | |
6356 | could disappear. */ | |
34814b9f AM |
6357 | stub_entry->h->oh->elf.root.type = bfd_link_hash_defined; |
6358 | stub_entry->h->oh->elf.root.u.def.section = stub_entry->stub_sec; | |
6359 | stub_entry->h->oh->elf.root.u.def.value = stub_entry->stub_offset; | |
c862ae31 AM |
6360 | } |
6361 | ||
721956f4 | 6362 | /* Now build the stub. */ |
411e1bfb AM |
6363 | off = (bfd_vma) -1; |
6364 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) | |
6365 | if (ent->addend == stub_entry->addend) | |
6366 | { | |
6367 | off = ent->plt.offset; | |
6368 | break; | |
6369 | } | |
721956f4 AM |
6370 | if (off >= (bfd_vma) -2) |
6371 | abort (); | |
6372 | ||
6373 | off &= ~ (bfd_vma) 1; | |
4ce794b7 AM |
6374 | off += (htab->plt->output_offset |
6375 | + htab->plt->output_section->vma | |
6376 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6377 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6378 | |
ad8e1ba5 | 6379 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
721956f4 AM |
6380 | { |
6381 | (*_bfd_error_handler) | |
6382 | (_("linkage table error against `%s'"), | |
6383 | stub_entry->h->elf.root.root.string); | |
6384 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 AM |
6385 | htab->stub_error = TRUE; |
6386 | return FALSE; | |
721956f4 AM |
6387 | } |
6388 | ||
97b639ba | 6389 | p = build_plt_stub (htab->stub_bfd, loc, off); |
721956f4 AM |
6390 | size = p - loc; |
6391 | break; | |
6392 | ||
6393 | default: | |
6394 | BFD_FAIL (); | |
b34976b6 | 6395 | return FALSE; |
721956f4 AM |
6396 | } |
6397 | ||
eea6121a | 6398 | stub_entry->stub_sec->size += size; |
97b639ba AM |
6399 | |
6400 | if (htab->emit_stub_syms | |
6401 | && !(stub_entry->stub_type == ppc_stub_plt_call | |
34814b9f AM |
6402 | && stub_entry->h->oh->elf.root.type == bfd_link_hash_defined |
6403 | && stub_entry->h->oh->elf.root.u.def.section == stub_entry->stub_sec | |
6404 | && stub_entry->h->oh->elf.root.u.def.value == stub_entry->stub_offset)) | |
97b639ba AM |
6405 | { |
6406 | struct elf_link_hash_entry *h; | |
6407 | h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string, | |
6408 | TRUE, FALSE, FALSE); | |
6409 | if (h == NULL) | |
6410 | return FALSE; | |
6411 | if (h->root.type == bfd_link_hash_new) | |
6412 | { | |
6413 | h->root.type = bfd_link_hash_defined; | |
6414 | h->root.u.def.section = stub_entry->stub_sec; | |
6415 | h->root.u.def.value = stub_entry->stub_offset; | |
6416 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
6417 | | ELF_LINK_HASH_DEF_REGULAR | |
6418 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
6419 | | ELF_LINK_FORCED_LOCAL); | |
6420 | } | |
6421 | } | |
6422 | ||
b34976b6 | 6423 | return TRUE; |
721956f4 AM |
6424 | } |
6425 | ||
6426 | /* As above, but don't actually build the stub. Just bump offset so | |
6427 | we know stub section sizes, and select plt_branch stubs where | |
6428 | long_branch stubs won't do. */ | |
6429 | ||
b34976b6 | 6430 | static bfd_boolean |
4ce794b7 | 6431 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
721956f4 AM |
6432 | { |
6433 | struct ppc_stub_hash_entry *stub_entry; | |
63bc6f6c | 6434 | struct bfd_link_info *info; |
721956f4 AM |
6435 | struct ppc_link_hash_table *htab; |
6436 | bfd_vma off; | |
6437 | int size; | |
6438 | ||
6439 | /* Massage our args to the form they really have. */ | |
6440 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
63bc6f6c AM |
6441 | info = in_arg; |
6442 | ||
6443 | htab = ppc_hash_table (info); | |
721956f4 AM |
6444 | |
6445 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
6446 | { | |
411e1bfb | 6447 | struct plt_entry *ent; |
58ac9f71 | 6448 | off = (bfd_vma) -1; |
411e1bfb AM |
6449 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
6450 | if (ent->addend == stub_entry->addend) | |
6451 | { | |
6452 | off = ent->plt.offset & ~(bfd_vma) 1; | |
6453 | break; | |
6454 | } | |
58ac9f71 | 6455 | if (off >= (bfd_vma) -2) |
411e1bfb | 6456 | abort (); |
4ce794b7 AM |
6457 | off += (htab->plt->output_offset |
6458 | + htab->plt->output_section->vma | |
6459 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6460 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6461 | |
ad8e1ba5 | 6462 | size = PLT_CALL_STUB_SIZE; |
4ce794b7 | 6463 | if (PPC_HA (off + 16) != PPC_HA (off)) |
721956f4 AM |
6464 | size += 4; |
6465 | } | |
6466 | else | |
6467 | { | |
ad8e1ba5 AM |
6468 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
6469 | variants. */ | |
721956f4 AM |
6470 | off = (stub_entry->target_value |
6471 | + stub_entry->target_section->output_offset | |
6472 | + stub_entry->target_section->output_section->vma); | |
eea6121a | 6473 | off -= (stub_entry->stub_sec->size |
721956f4 AM |
6474 | + stub_entry->stub_sec->output_offset |
6475 | + stub_entry->stub_sec->output_section->vma); | |
6476 | ||
ad8e1ba5 AM |
6477 | /* Reset the stub type from the plt variant in case we now |
6478 | can reach with a shorter stub. */ | |
6479 | if (stub_entry->stub_type >= ppc_stub_plt_branch) | |
6480 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; | |
6481 | ||
6482 | size = 4; | |
6483 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
6484 | { | |
6485 | off -= 12; | |
6486 | size = 16; | |
6487 | } | |
6488 | ||
6489 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ | |
721956f4 AM |
6490 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
6491 | { | |
6492 | struct ppc_branch_hash_entry *br_entry; | |
6493 | ||
6494 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
6495 | stub_entry->root.string + 9, | |
b34976b6 | 6496 | TRUE, FALSE); |
721956f4 AM |
6497 | if (br_entry == NULL) |
6498 | { | |
6499 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), | |
6500 | stub_entry->root.string + 9); | |
b34976b6 AM |
6501 | htab->stub_error = TRUE; |
6502 | return FALSE; | |
721956f4 AM |
6503 | } |
6504 | ||
6505 | if (br_entry->iter != htab->stub_iteration) | |
6506 | { | |
6507 | br_entry->iter = htab->stub_iteration; | |
eea6121a AM |
6508 | br_entry->offset = htab->brlt->size; |
6509 | htab->brlt->size += 8; | |
63bc6f6c AM |
6510 | |
6511 | if (info->shared) | |
eea6121a | 6512 | htab->relbrlt->size += sizeof (Elf64_External_Rela); |
721956f4 | 6513 | } |
ad8e1ba5 AM |
6514 | |
6515 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | |
721956f4 | 6516 | size = 16; |
ad8e1ba5 AM |
6517 | if (stub_entry->stub_type != ppc_stub_plt_branch) |
6518 | size = 28; | |
721956f4 AM |
6519 | } |
6520 | } | |
6521 | ||
eea6121a | 6522 | stub_entry->stub_sec->size += size; |
b34976b6 | 6523 | return TRUE; |
721956f4 AM |
6524 | } |
6525 | ||
6526 | /* Set up various things so that we can make a list of input sections | |
6527 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 6528 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
6529 | |
6530 | int | |
4ce794b7 | 6531 | ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
721956f4 AM |
6532 | { |
6533 | bfd *input_bfd; | |
734b6cf9 | 6534 | int top_id, top_index, id; |
721956f4 | 6535 | asection *section; |
734b6cf9 | 6536 | asection **input_list; |
721956f4 AM |
6537 | bfd_size_type amt; |
6538 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6539 | ||
4ce794b7 | 6540 | if (htab->brlt == NULL) |
721956f4 AM |
6541 | return 0; |
6542 | ||
1e2f5b6e | 6543 | /* Find the top input section id. */ |
3d6f9012 | 6544 | for (input_bfd = info->input_bfds, top_id = 3; |
721956f4 AM |
6545 | input_bfd != NULL; |
6546 | input_bfd = input_bfd->link_next) | |
6547 | { | |
721956f4 AM |
6548 | for (section = input_bfd->sections; |
6549 | section != NULL; | |
6550 | section = section->next) | |
6551 | { | |
6552 | if (top_id < section->id) | |
6553 | top_id = section->id; | |
6554 | } | |
6555 | } | |
721956f4 | 6556 | |
8f3bab57 | 6557 | htab->top_id = top_id; |
721956f4 | 6558 | amt = sizeof (struct map_stub) * (top_id + 1); |
4ce794b7 | 6559 | htab->stub_group = bfd_zmalloc (amt); |
721956f4 AM |
6560 | if (htab->stub_group == NULL) |
6561 | return -1; | |
6562 | ||
3d6f9012 AM |
6563 | /* Set toc_off for com, und, abs and ind sections. */ |
6564 | for (id = 0; id < 3; id++) | |
6565 | htab->stub_group[id].toc_off = TOC_BASE_OFF; | |
721956f4 | 6566 | |
3d6f9012 | 6567 | elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd); |
734b6cf9 AM |
6568 | |
6569 | /* We can't use output_bfd->section_count here to find the top output | |
6570 | section index as some sections may have been removed, and | |
6571 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
6572 | for (section = output_bfd->sections, top_index = 0; | |
6573 | section != NULL; | |
6574 | section = section->next) | |
6575 | { | |
6576 | if (top_index < section->index) | |
6577 | top_index = section->index; | |
6578 | } | |
6579 | ||
6580 | htab->top_index = top_index; | |
6581 | amt = sizeof (asection *) * (top_index + 1); | |
4ce794b7 | 6582 | input_list = bfd_zmalloc (amt); |
734b6cf9 AM |
6583 | htab->input_list = input_list; |
6584 | if (input_list == NULL) | |
6585 | return -1; | |
6586 | ||
721956f4 AM |
6587 | return 1; |
6588 | } | |
6589 | ||
e717da7e AM |
6590 | /* The linker repeatedly calls this function for each TOC input section |
6591 | and linker generated GOT section. Group input bfds such that the toc | |
6592 | within a group is less than 64k in size. Will break with cute linker | |
6593 | scripts that play games with dot in the output toc section. */ | |
ad8e1ba5 AM |
6594 | |
6595 | void | |
4ce794b7 | 6596 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
ad8e1ba5 AM |
6597 | { |
6598 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6599 | ||
6600 | if (!htab->no_multi_toc) | |
6601 | { | |
6602 | bfd_vma addr = isec->output_offset + isec->output_section->vma; | |
6603 | bfd_vma off = addr - htab->toc_curr; | |
eea6121a | 6604 | if (off + isec->size > 0x10000) |
ad8e1ba5 AM |
6605 | { |
6606 | htab->toc_curr = addr; | |
6607 | htab->multi_toc_needed = 1; | |
6608 | } | |
6609 | elf_gp (isec->owner) = (htab->toc_curr | |
6610 | - elf_gp (isec->output_section->owner) | |
6611 | + TOC_BASE_OFF); | |
6612 | } | |
6613 | } | |
6614 | ||
6615 | /* Called after the last call to the above function. */ | |
6616 | ||
6617 | void | |
4ce794b7 AM |
6618 | ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED, |
6619 | struct bfd_link_info *info) | |
ad8e1ba5 AM |
6620 | { |
6621 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
ad8e1ba5 AM |
6622 | |
6623 | /* toc_curr tracks the TOC offset used for code sections below in | |
6624 | ppc64_elf_next_input_section. Start off at 0x8000. */ | |
3d6f9012 | 6625 | htab->toc_curr = TOC_BASE_OFF; |
ad8e1ba5 AM |
6626 | } |
6627 | ||
9b5ecbd0 AM |
6628 | /* No toc references were found in ISEC. If the code in ISEC makes no |
6629 | calls, then there's no need to use toc adjusting stubs when branching | |
6630 | into ISEC. Actually, indirect calls from ISEC are OK as they will | |
6631 | load r2. */ | |
6632 | ||
6633 | static int | |
4ce794b7 | 6634 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
9b5ecbd0 AM |
6635 | { |
6636 | bfd_byte *contents; | |
6637 | bfd_size_type i; | |
6638 | int ret; | |
6639 | int branch_ok; | |
6640 | ||
772119ce AM |
6641 | /* We know none of our code bearing sections will need toc stubs. */ |
6642 | if ((isec->flags & SEC_LINKER_CREATED) != 0) | |
6643 | return 0; | |
6644 | ||
eea6121a | 6645 | if (isec->size == 0) |
082c50f8 AM |
6646 | return 0; |
6647 | ||
9b5ecbd0 AM |
6648 | /* Hack for linux kernel. .fixup contains branches, but only back to |
6649 | the function that hit an exception. */ | |
6650 | branch_ok = strcmp (isec->name, ".fixup") == 0; | |
6651 | ||
6652 | contents = elf_section_data (isec)->this_hdr.contents; | |
6653 | if (contents == NULL) | |
6654 | { | |
eea6121a | 6655 | if (!bfd_malloc_and_get_section (isec->owner, isec, &contents)) |
9b5ecbd0 | 6656 | { |
eea6121a AM |
6657 | if (contents != NULL) |
6658 | free (contents); | |
9b5ecbd0 AM |
6659 | return -1; |
6660 | } | |
6661 | if (info->keep_memory) | |
6662 | elf_section_data (isec)->this_hdr.contents = contents; | |
6663 | } | |
6664 | ||
6665 | /* Code scan, because we don't necessarily have relocs on calls to | |
6666 | static functions. */ | |
6667 | ret = 0; | |
eea6121a | 6668 | for (i = 0; i < isec->size; i += 4) |
9b5ecbd0 AM |
6669 | { |
6670 | unsigned long insn = bfd_get_32 (isec->owner, contents + i); | |
6671 | /* Is this a branch? */ | |
772119ce | 6672 | if ((insn & (0x3f << 26)) == (18 << 26) |
9b5ecbd0 AM |
6673 | /* If branch and link, it's a function call. */ |
6674 | && ((insn & 1) != 0 | |
6675 | /* Sibling calls use a plain branch. I don't know a way | |
6676 | of deciding whether a branch is really a sibling call. */ | |
6677 | || !branch_ok)) | |
6678 | { | |
6679 | ret = 1; | |
6680 | break; | |
6681 | } | |
6682 | } | |
6683 | ||
6684 | if (elf_section_data (isec)->this_hdr.contents != contents) | |
6685 | free (contents); | |
6686 | return ret; | |
6687 | } | |
6688 | ||
721956f4 AM |
6689 | /* The linker repeatedly calls this function for each input section, |
6690 | in the order that input sections are linked into output sections. | |
6691 | Build lists of input sections to determine groupings between which | |
6692 | we may insert linker stubs. */ | |
6693 | ||
9b5ecbd0 | 6694 | bfd_boolean |
4ce794b7 | 6695 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
721956f4 AM |
6696 | { |
6697 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
9b5ecbd0 | 6698 | int ret; |
721956f4 | 6699 | |
734b6cf9 AM |
6700 | if ((isec->output_section->flags & SEC_CODE) != 0 |
6701 | && isec->output_section->index <= htab->top_index) | |
721956f4 | 6702 | { |
734b6cf9 | 6703 | asection **list = htab->input_list + isec->output_section->index; |
3d6f9012 | 6704 | /* Steal the link_sec pointer for our list. */ |
721956f4 | 6705 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3d6f9012 AM |
6706 | /* This happens to make the list in reverse order, |
6707 | which is what we want. */ | |
734b6cf9 AM |
6708 | PREV_SEC (isec) = *list; |
6709 | *list = isec; | |
721956f4 | 6710 | } |
ad8e1ba5 AM |
6711 | |
6712 | /* If a code section has a function that uses the TOC then we need | |
6713 | to use the right TOC (obviously). Also, make sure that .opd gets | |
ee87f2da AM |
6714 | the correct TOC value for R_PPC64_TOC relocs that don't have or |
6715 | can't find their function symbol (shouldn't ever happen now). */ | |
ad8e1ba5 | 6716 | if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0) |
9b5ecbd0 AM |
6717 | { |
6718 | if (elf_gp (isec->owner) != 0) | |
6719 | htab->toc_curr = elf_gp (isec->owner); | |
6720 | } | |
6721 | else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0) | |
6722 | return FALSE; | |
6723 | else | |
6724 | isec->has_gp_reloc = ret; | |
ad8e1ba5 AM |
6725 | |
6726 | /* Functions that don't use the TOC can belong in any TOC group. | |
6727 | Use the last TOC base. This happens to make _init and _fini | |
6728 | pasting work. */ | |
6729 | htab->stub_group[isec->id].toc_off = htab->toc_curr; | |
9b5ecbd0 | 6730 | return TRUE; |
721956f4 AM |
6731 | } |
6732 | ||
6733 | /* See whether we can group stub sections together. Grouping stub | |
6734 | sections may result in fewer stubs. More importantly, we need to | |
6735 | put all .init* and .fini* stubs at the beginning of the .init or | |
6736 | .fini output sections respectively, because glibc splits the | |
6737 | _init and _fini functions into multiple parts. Putting a stub in | |
6738 | the middle of a function is not a good idea. */ | |
6739 | ||
6740 | static void | |
4ce794b7 AM |
6741 | group_sections (struct ppc_link_hash_table *htab, |
6742 | bfd_size_type stub_group_size, | |
6743 | bfd_boolean stubs_always_before_branch) | |
721956f4 | 6744 | { |
734b6cf9 AM |
6745 | asection **list = htab->input_list + htab->top_index; |
6746 | do | |
721956f4 | 6747 | { |
734b6cf9 AM |
6748 | asection *tail = *list; |
6749 | while (tail != NULL) | |
721956f4 | 6750 | { |
734b6cf9 AM |
6751 | asection *curr; |
6752 | asection *prev; | |
6753 | bfd_size_type total; | |
6754 | bfd_boolean big_sec; | |
6755 | bfd_vma curr_toc; | |
6756 | ||
6757 | curr = tail; | |
eea6121a | 6758 | total = tail->size; |
734b6cf9 AM |
6759 | big_sec = total >= stub_group_size; |
6760 | curr_toc = htab->stub_group[tail->id].toc_off; | |
6761 | ||
6762 | while ((prev = PREV_SEC (curr)) != NULL | |
6763 | && ((total += curr->output_offset - prev->output_offset) | |
ad8e1ba5 AM |
6764 | < stub_group_size) |
6765 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
734b6cf9 AM |
6766 | curr = prev; |
6767 | ||
6768 | /* OK, the size from the start of CURR to the end is less | |
6769 | than stub_group_size and thus can be handled by one stub | |
6770 | section. (or the tail section is itself larger than | |
6771 | stub_group_size, in which case we may be toast.) We | |
6772 | should really be keeping track of the total size of stubs | |
6773 | added here, as stubs contribute to the final output | |
6774 | section size. That's a little tricky, and this way will | |
6775 | only break if stubs added make the total size more than | |
6776 | 2^25, ie. for the default stub_group_size, if stubs total | |
6777 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ | |
6778 | do | |
721956f4 AM |
6779 | { |
6780 | prev = PREV_SEC (tail); | |
734b6cf9 | 6781 | /* Set up this stub group. */ |
721956f4 AM |
6782 | htab->stub_group[tail->id].link_sec = curr; |
6783 | } | |
734b6cf9 AM |
6784 | while (tail != curr && (tail = prev) != NULL); |
6785 | ||
6786 | /* But wait, there's more! Input sections up to stub_group_size | |
6787 | bytes before the stub section can be handled by it too. | |
6788 | Don't do this if we have a really large section after the | |
6789 | stubs, as adding more stubs increases the chance that | |
6790 | branches may not reach into the stub section. */ | |
6791 | if (!stubs_always_before_branch && !big_sec) | |
6792 | { | |
6793 | total = 0; | |
6794 | while (prev != NULL | |
6795 | && ((total += tail->output_offset - prev->output_offset) | |
6796 | < stub_group_size) | |
6797 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
6798 | { | |
6799 | tail = prev; | |
6800 | prev = PREV_SEC (tail); | |
6801 | htab->stub_group[tail->id].link_sec = curr; | |
6802 | } | |
6803 | } | |
6804 | tail = prev; | |
721956f4 AM |
6805 | } |
6806 | } | |
734b6cf9 AM |
6807 | while (list-- != htab->input_list); |
6808 | free (htab->input_list); | |
721956f4 AM |
6809 | #undef PREV_SEC |
6810 | } | |
6811 | ||
721956f4 AM |
6812 | /* Determine and set the size of the stub section for a final link. |
6813 | ||
6814 | The basic idea here is to examine all the relocations looking for | |
6815 | PC-relative calls to a target that is unreachable with a "bl" | |
6816 | instruction. */ | |
6817 | ||
b34976b6 | 6818 | bfd_boolean |
4ce794b7 | 6819 | ppc64_elf_size_stubs (bfd *output_bfd, |
4ce794b7 AM |
6820 | struct bfd_link_info *info, |
6821 | bfd_signed_vma group_size, | |
6822 | asection *(*add_stub_section) (const char *, asection *), | |
6823 | void (*layout_sections_again) (void)) | |
721956f4 AM |
6824 | { |
6825 | bfd_size_type stub_group_size; | |
b34976b6 | 6826 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
6827 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
6828 | ||
6829 | /* Stash our params away. */ | |
721956f4 AM |
6830 | htab->add_stub_section = add_stub_section; |
6831 | htab->layout_sections_again = layout_sections_again; | |
6832 | stubs_always_before_branch = group_size < 0; | |
6833 | if (group_size < 0) | |
6834 | stub_group_size = -group_size; | |
6835 | else | |
6836 | stub_group_size = group_size; | |
6837 | if (stub_group_size == 1) | |
6838 | { | |
6839 | /* Default values. */ | |
58ac9f71 AM |
6840 | if (stubs_always_before_branch) |
6841 | { | |
6842 | stub_group_size = 0x1e00000; | |
6843 | if (htab->has_14bit_branch) | |
6844 | stub_group_size = 0x7800; | |
6845 | } | |
6846 | else | |
6847 | { | |
6848 | stub_group_size = 0x1c00000; | |
6849 | if (htab->has_14bit_branch) | |
6850 | stub_group_size = 0x7000; | |
6851 | } | |
721956f4 AM |
6852 | } |
6853 | ||
6854 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
6855 | ||
721956f4 AM |
6856 | while (1) |
6857 | { | |
6858 | bfd *input_bfd; | |
6859 | unsigned int bfd_indx; | |
6860 | asection *stub_sec; | |
b34976b6 | 6861 | bfd_boolean stub_changed; |
721956f4 AM |
6862 | |
6863 | htab->stub_iteration += 1; | |
b34976b6 | 6864 | stub_changed = FALSE; |
721956f4 AM |
6865 | |
6866 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
6867 | input_bfd != NULL; | |
6868 | input_bfd = input_bfd->link_next, bfd_indx++) | |
6869 | { | |
6870 | Elf_Internal_Shdr *symtab_hdr; | |
6871 | asection *section; | |
6cdc0ccc | 6872 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 AM |
6873 | |
6874 | /* We'll need the symbol table in a second. */ | |
6875 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
6876 | if (symtab_hdr->sh_info == 0) | |
6877 | continue; | |
6878 | ||
721956f4 AM |
6879 | /* Walk over each section attached to the input bfd. */ |
6880 | for (section = input_bfd->sections; | |
6881 | section != NULL; | |
6882 | section = section->next) | |
6883 | { | |
721956f4 | 6884 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
6885 | |
6886 | /* If there aren't any relocs, then there's nothing more | |
6887 | to do. */ | |
6888 | if ((section->flags & SEC_RELOC) == 0 | |
6889 | || section->reloc_count == 0) | |
6890 | continue; | |
6891 | ||
6892 | /* If this section is a link-once section that will be | |
6893 | discarded, then don't create any stubs. */ | |
6894 | if (section->output_section == NULL | |
6895 | || section->output_section->owner != output_bfd) | |
6896 | continue; | |
6897 | ||
1e2f5b6e AM |
6898 | /* Get the relocs. */ |
6899 | internal_relocs | |
4ce794b7 | 6900 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 6901 | info->keep_memory); |
721956f4 | 6902 | if (internal_relocs == NULL) |
1e2f5b6e | 6903 | goto error_ret_free_local; |
721956f4 AM |
6904 | |
6905 | /* Now examine each relocation. */ | |
6906 | irela = internal_relocs; | |
6907 | irelaend = irela + section->reloc_count; | |
6908 | for (; irela < irelaend; irela++) | |
6909 | { | |
4ce794b7 AM |
6910 | enum elf_ppc64_reloc_type r_type; |
6911 | unsigned int r_indx; | |
721956f4 AM |
6912 | enum ppc_stub_type stub_type; |
6913 | struct ppc_stub_hash_entry *stub_entry; | |
6914 | asection *sym_sec; | |
6915 | bfd_vma sym_value; | |
6916 | bfd_vma destination; | |
6917 | struct ppc_link_hash_entry *hash; | |
411e1bfb AM |
6918 | struct elf_link_hash_entry *h; |
6919 | Elf_Internal_Sym *sym; | |
721956f4 AM |
6920 | char *stub_name; |
6921 | const asection *id_sec; | |
6922 | ||
6923 | r_type = ELF64_R_TYPE (irela->r_info); | |
6924 | r_indx = ELF64_R_SYM (irela->r_info); | |
6925 | ||
4ce794b7 | 6926 | if (r_type >= R_PPC64_max) |
721956f4 AM |
6927 | { |
6928 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 6929 | goto error_ret_free_internal; |
721956f4 AM |
6930 | } |
6931 | ||
6932 | /* Only look for stubs on branch instructions. */ | |
4ce794b7 AM |
6933 | if (r_type != R_PPC64_REL24 |
6934 | && r_type != R_PPC64_REL14 | |
6935 | && r_type != R_PPC64_REL14_BRTAKEN | |
6936 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
721956f4 AM |
6937 | continue; |
6938 | ||
6939 | /* Now determine the call target, its name, value, | |
6940 | section. */ | |
721956f4 | 6941 | destination = 0; |
411e1bfb AM |
6942 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
6943 | r_indx, input_bfd)) | |
6944 | goto error_ret_free_internal; | |
6945 | hash = (struct ppc_link_hash_entry *) h; | |
6946 | ||
6947 | if (hash == NULL) | |
721956f4 AM |
6948 | { |
6949 | /* It's a local symbol. */ | |
411e1bfb | 6950 | sym_value = sym->st_value; |
721956f4 AM |
6951 | destination = (sym_value + irela->r_addend |
6952 | + sym_sec->output_offset | |
6953 | + sym_sec->output_section->vma); | |
6954 | } | |
6955 | else | |
6956 | { | |
6957 | /* It's an external symbol. */ | |
411e1bfb | 6958 | sym_value = 0; |
721956f4 AM |
6959 | if (hash->elf.root.type == bfd_link_hash_defined |
6960 | || hash->elf.root.type == bfd_link_hash_defweak) | |
6961 | { | |
721956f4 AM |
6962 | sym_value = hash->elf.root.u.def.value; |
6963 | if (sym_sec->output_section != NULL) | |
6964 | destination = (sym_value + irela->r_addend | |
6965 | + sym_sec->output_offset | |
6966 | + sym_sec->output_section->vma); | |
6967 | } | |
6968 | else if (hash->elf.root.type == bfd_link_hash_undefweak) | |
6969 | ; | |
6970 | else if (hash->elf.root.type == bfd_link_hash_undefined) | |
6971 | ; | |
6972 | else | |
6973 | { | |
6974 | bfd_set_error (bfd_error_bad_value); | |
6975 | goto error_ret_free_internal; | |
6976 | } | |
6977 | } | |
6978 | ||
6979 | /* Determine what (if any) linker stub is needed. */ | |
6980 | stub_type = ppc_type_of_stub (section, irela, &hash, | |
6981 | destination); | |
ad8e1ba5 AM |
6982 | |
6983 | if (stub_type != ppc_stub_plt_call) | |
6984 | { | |
6985 | /* Check whether we need a TOC adjusting stub. | |
6986 | Since the linker pastes together pieces from | |
6987 | different object files when creating the | |
6988 | _init and _fini functions, it may be that a | |
6989 | call to what looks like a local sym is in | |
6990 | fact a call needing a TOC adjustment. */ | |
6991 | if (sym_sec != NULL | |
6992 | && sym_sec->output_section != NULL | |
6993 | && (htab->stub_group[sym_sec->id].toc_off | |
9b5ecbd0 AM |
6994 | != htab->stub_group[section->id].toc_off) |
6995 | && sym_sec->has_gp_reloc | |
6996 | && section->has_gp_reloc) | |
ad8e1ba5 AM |
6997 | stub_type = ppc_stub_long_branch_r2off; |
6998 | } | |
6999 | ||
721956f4 AM |
7000 | if (stub_type == ppc_stub_none) |
7001 | continue; | |
7002 | ||
411e1bfb AM |
7003 | /* __tls_get_addr calls might be eliminated. */ |
7004 | if (stub_type != ppc_stub_plt_call | |
7005 | && hash != NULL | |
7006 | && &hash->elf == htab->tls_get_addr | |
7007 | && section->has_tls_reloc | |
7008 | && irela != internal_relocs) | |
7009 | { | |
7010 | /* Get tls info. */ | |
e7b938ca | 7011 | char *tls_mask; |
411e1bfb | 7012 | |
0d4792f7 | 7013 | if (!get_tls_mask (&tls_mask, NULL, &local_syms, |
411e1bfb AM |
7014 | irela - 1, input_bfd)) |
7015 | goto error_ret_free_internal; | |
e7b938ca | 7016 | if (*tls_mask != 0) |
411e1bfb AM |
7017 | continue; |
7018 | } | |
7019 | ||
721956f4 AM |
7020 | /* Support for grouping stub sections. */ |
7021 | id_sec = htab->stub_group[section->id].link_sec; | |
7022 | ||
7023 | /* Get the name of this stub. */ | |
7024 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
7025 | if (!stub_name) | |
7026 | goto error_ret_free_internal; | |
7027 | ||
7028 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 7029 | stub_name, FALSE, FALSE); |
721956f4 AM |
7030 | if (stub_entry != NULL) |
7031 | { | |
7032 | /* The proper stub has already been created. */ | |
7033 | free (stub_name); | |
7034 | continue; | |
7035 | } | |
7036 | ||
7037 | stub_entry = ppc_add_stub (stub_name, section, htab); | |
7038 | if (stub_entry == NULL) | |
7039 | { | |
7040 | free (stub_name); | |
6cdc0ccc AM |
7041 | error_ret_free_internal: |
7042 | if (elf_section_data (section)->relocs == NULL) | |
7043 | free (internal_relocs); | |
7044 | error_ret_free_local: | |
7045 | if (local_syms != NULL | |
7046 | && (symtab_hdr->contents | |
7047 | != (unsigned char *) local_syms)) | |
7048 | free (local_syms); | |
b34976b6 | 7049 | return FALSE; |
721956f4 AM |
7050 | } |
7051 | ||
ad8e1ba5 | 7052 | stub_entry->stub_type = stub_type; |
721956f4 AM |
7053 | stub_entry->target_value = sym_value; |
7054 | stub_entry->target_section = sym_sec; | |
721956f4 | 7055 | stub_entry->h = hash; |
411e1bfb | 7056 | stub_entry->addend = irela->r_addend; |
b34976b6 | 7057 | stub_changed = TRUE; |
721956f4 AM |
7058 | } |
7059 | ||
7060 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 7061 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 7062 | free (internal_relocs); |
721956f4 | 7063 | } |
6cdc0ccc AM |
7064 | |
7065 | if (local_syms != NULL | |
7066 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
7067 | { | |
7068 | if (!info->keep_memory) | |
7069 | free (local_syms); | |
7070 | else | |
7071 | symtab_hdr->contents = (unsigned char *) local_syms; | |
7072 | } | |
721956f4 AM |
7073 | } |
7074 | ||
7075 | if (!stub_changed) | |
7076 | break; | |
7077 | ||
7078 | /* OK, we've added some stubs. Find out the new size of the | |
7079 | stub sections. */ | |
7080 | for (stub_sec = htab->stub_bfd->sections; | |
7081 | stub_sec != NULL; | |
7082 | stub_sec = stub_sec->next) | |
e717da7e | 7083 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
eea6121a AM |
7084 | stub_sec->size = 0; |
7085 | ||
7086 | htab->brlt->size = 0; | |
63bc6f6c | 7087 | if (info->shared) |
eea6121a | 7088 | htab->relbrlt->size = 0; |
721956f4 | 7089 | |
63bc6f6c | 7090 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info); |
721956f4 AM |
7091 | |
7092 | /* Ask the linker to do its stuff. */ | |
7093 | (*htab->layout_sections_again) (); | |
7094 | } | |
7095 | ||
afbe61cf AM |
7096 | /* It would be nice to strip .branch_lt from the output if the |
7097 | section is empty, but it's too late. If we strip sections here, | |
7098 | the dynamic symbol table is corrupted since the section symbol | |
7099 | for the stripped section isn't written. */ | |
721956f4 | 7100 | |
b34976b6 | 7101 | return TRUE; |
721956f4 AM |
7102 | } |
7103 | ||
7104 | /* Called after we have determined section placement. If sections | |
805fc799 | 7105 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 7106 | |
805fc799 | 7107 | bfd_vma |
4ce794b7 | 7108 | ppc64_elf_toc (bfd *obfd) |
721956f4 | 7109 | { |
805fc799 AM |
7110 | asection *s; |
7111 | bfd_vma TOCstart; | |
721956f4 | 7112 | |
805fc799 AM |
7113 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
7114 | order. The TOC starts where the first of these sections starts. */ | |
7115 | s = bfd_get_section_by_name (obfd, ".got"); | |
7116 | if (s == NULL) | |
7117 | s = bfd_get_section_by_name (obfd, ".toc"); | |
7118 | if (s == NULL) | |
7119 | s = bfd_get_section_by_name (obfd, ".tocbss"); | |
7120 | if (s == NULL) | |
7121 | s = bfd_get_section_by_name (obfd, ".plt"); | |
7122 | if (s == NULL) | |
7123 | { | |
7124 | /* This may happen for | |
7125 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
7126 | .toc directive | |
7127 | o bad linker script | |
7128 | o --gc-sections and empty TOC sections | |
7129 | ||
7130 | FIXME: Warn user? */ | |
7131 | ||
7132 | /* Look for a likely section. We probably won't even be | |
7133 | using TOCstart. */ | |
7134 | for (s = obfd->sections; s != NULL; s = s->next) | |
7135 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) | |
7136 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7137 | break; | |
721956f4 | 7138 | if (s == NULL) |
805fc799 AM |
7139 | for (s = obfd->sections; s != NULL; s = s->next) |
7140 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) | |
7141 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7142 | break; | |
721956f4 | 7143 | if (s == NULL) |
805fc799 AM |
7144 | for (s = obfd->sections; s != NULL; s = s->next) |
7145 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) | |
7146 | break; | |
721956f4 | 7147 | if (s == NULL) |
805fc799 AM |
7148 | for (s = obfd->sections; s != NULL; s = s->next) |
7149 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) | |
7150 | break; | |
7151 | } | |
721956f4 | 7152 | |
805fc799 AM |
7153 | TOCstart = 0; |
7154 | if (s != NULL) | |
7155 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 7156 | |
805fc799 | 7157 | return TOCstart; |
721956f4 AM |
7158 | } |
7159 | ||
7160 | /* Build all the stubs associated with the current output file. | |
7161 | The stubs are kept in a hash table attached to the main linker | |
7162 | hash table. This function is called via gldelf64ppc_finish. */ | |
7163 | ||
b34976b6 | 7164 | bfd_boolean |
4ce794b7 AM |
7165 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
7166 | struct bfd_link_info *info, | |
7167 | char **stats) | |
5d1634d7 AM |
7168 | { |
7169 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 7170 | asection *stub_sec; |
5d1634d7 | 7171 | bfd_byte *p; |
e717da7e | 7172 | int stub_sec_count = 0; |
5d1634d7 | 7173 | |
ad8e1ba5 | 7174 | htab->emit_stub_syms = emit_stub_syms; |
eea6121a AM |
7175 | |
7176 | /* Allocate memory to hold the linker stubs. */ | |
721956f4 AM |
7177 | for (stub_sec = htab->stub_bfd->sections; |
7178 | stub_sec != NULL; | |
7179 | stub_sec = stub_sec->next) | |
eea6121a AM |
7180 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0 |
7181 | && stub_sec->size != 0) | |
e717da7e | 7182 | { |
eea6121a AM |
7183 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size); |
7184 | if (stub_sec->contents == NULL) | |
7185 | return FALSE; | |
7186 | /* We want to check that built size is the same as calculated | |
7187 | size. rawsize is a convenient location to use. */ | |
7188 | stub_sec->rawsize = stub_sec->size; | |
7189 | stub_sec->size = 0; | |
e717da7e | 7190 | } |
5d1634d7 | 7191 | |
4ce794b7 | 7192 | if (htab->plt != NULL) |
5d1634d7 | 7193 | { |
9f951329 | 7194 | unsigned int indx; |
ad8e1ba5 | 7195 | bfd_vma plt0; |
9f951329 | 7196 | |
721956f4 | 7197 | /* Build the .glink plt call stub. */ |
4ce794b7 AM |
7198 | plt0 = (htab->plt->output_section->vma |
7199 | + htab->plt->output_offset | |
7200 | - (htab->glink->output_section->vma | |
7201 | + htab->glink->output_offset | |
ad8e1ba5 AM |
7202 | + GLINK_CALL_STUB_SIZE)); |
7203 | if (plt0 + 0x80008000 > 0xffffffff) | |
721956f4 | 7204 | { |
ad8e1ba5 AM |
7205 | (*_bfd_error_handler) (_(".glink and .plt too far apart")); |
7206 | bfd_set_error (bfd_error_bad_value); | |
7207 | return FALSE; | |
721956f4 | 7208 | } |
721956f4 | 7209 | |
97b639ba AM |
7210 | if (htab->emit_stub_syms) |
7211 | { | |
7212 | struct elf_link_hash_entry *h; | |
7213 | h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE); | |
7214 | if (h == NULL) | |
7215 | return FALSE; | |
7216 | if (h->root.type == bfd_link_hash_new) | |
7217 | { | |
7218 | h->root.type = bfd_link_hash_defined; | |
7219 | h->root.u.def.section = htab->glink; | |
7220 | h->root.u.def.value = 0; | |
7221 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
7222 | | ELF_LINK_HASH_DEF_REGULAR | |
7223 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
7224 | | ELF_LINK_FORCED_LOCAL); | |
7225 | } | |
7226 | } | |
4ce794b7 AM |
7227 | p = htab->glink->contents; |
7228 | bfd_put_32 (htab->glink->owner, MFCTR_R12, p); | |
ad8e1ba5 | 7229 | p += 4; |
4ce794b7 | 7230 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p); |
ad8e1ba5 | 7231 | p += 4; |
4ce794b7 | 7232 | bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p); |
ad8e1ba5 | 7233 | p += 4; |
4ce794b7 | 7234 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7235 | p += 4; |
4ce794b7 | 7236 | bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p); |
ad8e1ba5 | 7237 | p += 4; |
4ce794b7 | 7238 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p); |
ad8e1ba5 | 7239 | p += 4; |
4ce794b7 | 7240 | bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p); |
ad8e1ba5 | 7241 | p += 4; |
4ce794b7 | 7242 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7243 | p += 4; |
4ce794b7 | 7244 | bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p); |
ad8e1ba5 | 7245 | p += 4; |
4ce794b7 | 7246 | bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p); |
ad8e1ba5 | 7247 | p += 4; |
4ce794b7 | 7248 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7249 | p += 4; |
4ce794b7 | 7250 | bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7251 | p += 4; |
4ce794b7 | 7252 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
ad8e1ba5 | 7253 | p += 4; |
4ce794b7 | 7254 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
ad8e1ba5 | 7255 | p += 4; |
4ce794b7 | 7256 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
ad8e1ba5 | 7257 | p += 4; |
4ce794b7 | 7258 | bfd_put_32 (htab->glink->owner, BCTR, p); |
ad8e1ba5 AM |
7259 | p += 4; |
7260 | ||
9f951329 AM |
7261 | /* Build the .glink lazy link call stubs. */ |
7262 | indx = 0; | |
eea6121a | 7263 | while (p < htab->glink->contents + htab->glink->size) |
9f951329 AM |
7264 | { |
7265 | if (indx < 0x8000) | |
7266 | { | |
4ce794b7 | 7267 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
9f951329 AM |
7268 | p += 4; |
7269 | } | |
7270 | else | |
7271 | { | |
4ce794b7 | 7272 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
9f951329 | 7273 | p += 4; |
4ce794b7 | 7274 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
9f951329 AM |
7275 | p += 4; |
7276 | } | |
4ce794b7 AM |
7277 | bfd_put_32 (htab->glink->owner, |
7278 | B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p); | |
a16d5acb | 7279 | indx++; |
9f951329 AM |
7280 | p += 4; |
7281 | } | |
eea6121a | 7282 | htab->glink->rawsize = p - htab->glink->contents; |
5d1634d7 | 7283 | } |
5d1634d7 | 7284 | |
eea6121a | 7285 | if (htab->brlt->size != 0) |
721956f4 | 7286 | { |
4ce794b7 | 7287 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
eea6121a | 7288 | htab->brlt->size); |
4ce794b7 | 7289 | if (htab->brlt->contents == NULL) |
b34976b6 | 7290 | return FALSE; |
721956f4 | 7291 | } |
eea6121a | 7292 | if (info->shared && htab->relbrlt->size != 0) |
63bc6f6c AM |
7293 | { |
7294 | htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner, | |
eea6121a | 7295 | htab->relbrlt->size); |
63bc6f6c AM |
7296 | if (htab->relbrlt->contents == NULL) |
7297 | return FALSE; | |
7298 | } | |
5d1634d7 | 7299 | |
721956f4 AM |
7300 | /* Build the stubs as directed by the stub hash table. */ |
7301 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 7302 | |
721956f4 AM |
7303 | for (stub_sec = htab->stub_bfd->sections; |
7304 | stub_sec != NULL; | |
7305 | stub_sec = stub_sec->next) | |
e717da7e AM |
7306 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7307 | { | |
7308 | stub_sec_count += 1; | |
eea6121a | 7309 | if (stub_sec->rawsize != stub_sec->size) |
e717da7e AM |
7310 | break; |
7311 | } | |
5d1634d7 | 7312 | |
721956f4 | 7313 | if (stub_sec != NULL |
eea6121a | 7314 | || htab->glink->rawsize != htab->glink->size) |
5d1634d7 | 7315 | { |
b34976b6 | 7316 | htab->stub_error = TRUE; |
721956f4 | 7317 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
5d1634d7 | 7318 | } |
721956f4 | 7319 | |
d2a300cf AM |
7320 | if (htab->stub_error) |
7321 | return FALSE; | |
7322 | ||
7323 | if (stats != NULL) | |
7324 | { | |
7325 | *stats = bfd_malloc (500); | |
7326 | if (*stats == NULL) | |
7327 | return FALSE; | |
7328 | ||
7329 | sprintf (*stats, _("linker stubs in %u groups\n" | |
7330 | " branch %lu\n" | |
7331 | " toc adjust %lu\n" | |
7332 | " long branch %lu\n" | |
7333 | " long toc adj %lu\n" | |
7334 | " plt call %lu"), | |
e717da7e | 7335 | stub_sec_count, |
4ce794b7 AM |
7336 | htab->stub_count[ppc_stub_long_branch - 1], |
7337 | htab->stub_count[ppc_stub_long_branch_r2off - 1], | |
7338 | htab->stub_count[ppc_stub_plt_branch - 1], | |
7339 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], | |
7340 | htab->stub_count[ppc_stub_plt_call - 1]); | |
d2a300cf AM |
7341 | } |
7342 | return TRUE; | |
5bd4f169 AM |
7343 | } |
7344 | ||
5bd4f169 AM |
7345 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
7346 | to handle the relocations for a section. | |
7347 | ||
7348 | The relocs are always passed as Rela structures; if the section | |
7349 | actually uses Rel structures, the r_addend field will always be | |
7350 | zero. | |
7351 | ||
7352 | This function is responsible for adjust the section contents as | |
7353 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 7354 | relocatable output file) adjusting the reloc addend as |
5bd4f169 AM |
7355 | necessary. |
7356 | ||
7357 | This function does not have to worry about setting the reloc | |
7358 | address or the reloc symbol index. | |
7359 | ||
7360 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
7361 | ||
7362 | LOCAL_SECTIONS is an array giving the section in the input file | |
7363 | corresponding to the st_shndx field of each local symbol. | |
7364 | ||
7365 | The global hash table entry for the global symbols can be found | |
7366 | via elf_sym_hashes (input_bfd). | |
7367 | ||
1049f94e | 7368 | When generating relocatable output, this function must handle |
5bd4f169 AM |
7369 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
7370 | going to be the section symbol corresponding to the output | |
7371 | section, which means that the addend must be adjusted | |
7372 | accordingly. */ | |
7373 | ||
b34976b6 | 7374 | static bfd_boolean |
4ce794b7 AM |
7375 | ppc64_elf_relocate_section (bfd *output_bfd, |
7376 | struct bfd_link_info *info, | |
7377 | bfd *input_bfd, | |
7378 | asection *input_section, | |
7379 | bfd_byte *contents, | |
7380 | Elf_Internal_Rela *relocs, | |
7381 | Elf_Internal_Sym *local_syms, | |
7382 | asection **local_sections) | |
5bd4f169 | 7383 | { |
65f38f15 | 7384 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
7385 | Elf_Internal_Shdr *symtab_hdr; |
7386 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
7387 | Elf_Internal_Rela *rel; |
7388 | Elf_Internal_Rela *relend; | |
411e1bfb AM |
7389 | Elf_Internal_Rela outrel; |
7390 | bfd_byte *loc; | |
411e1bfb | 7391 | struct got_entry **local_got_ents; |
5bd4f169 | 7392 | bfd_vma TOCstart; |
b34976b6 AM |
7393 | bfd_boolean ret = TRUE; |
7394 | bfd_boolean is_opd; | |
96e0dda4 | 7395 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 7396 | bfd_boolean is_power4 = FALSE; |
5bd4f169 | 7397 | |
1049f94e | 7398 | if (info->relocatable) |
b34976b6 | 7399 | return TRUE; |
b491616a | 7400 | |
65f38f15 | 7401 | /* Initialize howto table if needed. */ |
5bd4f169 | 7402 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
7403 | ppc_howto_init (); |
7404 | ||
65f38f15 | 7405 | htab = ppc_hash_table (info); |
411e1bfb | 7406 | local_got_ents = elf_local_got_ents (input_bfd); |
5bd4f169 | 7407 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
7408 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
7409 | sym_hashes = elf_sym_hashes (input_bfd); | |
f0abc2a1 | 7410 | is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL; |
65f38f15 | 7411 | |
5bd4f169 AM |
7412 | rel = relocs; |
7413 | relend = relocs + input_section->reloc_count; | |
7414 | for (; rel < relend; rel++) | |
7415 | { | |
04c9666a | 7416 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 AM |
7417 | bfd_vma addend; |
7418 | bfd_reloc_status_type r; | |
7419 | Elf_Internal_Sym *sym; | |
7420 | asection *sec; | |
7421 | struct elf_link_hash_entry *h; | |
721956f4 | 7422 | struct elf_link_hash_entry *fdh; |
5bd4f169 | 7423 | const char *sym_name; |
0d4792f7 | 7424 | unsigned long r_symndx, toc_symndx; |
951fd09b | 7425 | char tls_mask, tls_gd, tls_type; |
0d4792f7 | 7426 | char sym_type; |
5bd4f169 | 7427 | bfd_vma relocation; |
b34976b6 AM |
7428 | bfd_boolean unresolved_reloc; |
7429 | bfd_boolean warned; | |
50bc7936 | 7430 | unsigned long insn, mask; |
721956f4 AM |
7431 | struct ppc_stub_hash_entry *stub_entry; |
7432 | bfd_vma max_br_offset; | |
7433 | bfd_vma from; | |
5bd4f169 | 7434 | |
4ce794b7 | 7435 | r_type = ELF64_R_TYPE (rel->r_info); |
5bd4f169 | 7436 | r_symndx = ELF64_R_SYM (rel->r_info); |
ee87f2da AM |
7437 | |
7438 | /* For old style R_PPC64_TOC relocs with a zero symbol, use the | |
7439 | symbol of the previous ADDR64 reloc. The symbol gives us the | |
7440 | proper TOC base to use. */ | |
7441 | if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC) | |
7442 | && rel != relocs | |
7443 | && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64 | |
7444 | && is_opd) | |
7445 | r_symndx = ELF64_R_SYM (rel[-1].r_info); | |
7446 | ||
4ce794b7 AM |
7447 | sym = NULL; |
7448 | sec = NULL; | |
7449 | h = NULL; | |
7450 | sym_name = NULL; | |
b34976b6 AM |
7451 | unresolved_reloc = FALSE; |
7452 | warned = FALSE; | |
65f38f15 | 7453 | |
0b13192e | 7454 | if (r_symndx < symtab_hdr->sh_info) |
5bd4f169 AM |
7455 | { |
7456 | /* It's a local symbol. */ | |
4025353c AM |
7457 | long *opd_adjust; |
7458 | ||
5bd4f169 AM |
7459 | sym = local_syms + r_symndx; |
7460 | sec = local_sections[r_symndx]; | |
411e1bfb | 7461 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
0d4792f7 | 7462 | sym_type = ELF64_ST_TYPE (sym->st_info); |
8517fae7 | 7463 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
4025353c AM |
7464 | opd_adjust = get_opd_info (sec); |
7465 | if (opd_adjust != NULL) | |
1e2f5b6e | 7466 | { |
4025353c AM |
7467 | long adjust = opd_adjust[(sym->st_value + rel->r_addend) / 24]; |
7468 | if (adjust == -1) | |
7469 | relocation = 0; | |
7470 | else | |
7471 | relocation += adjust; | |
1e2f5b6e | 7472 | } |
5bd4f169 AM |
7473 | } |
7474 | else | |
7475 | { | |
b2a8e766 AM |
7476 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
7477 | r_symndx, symtab_hdr, sym_hashes, | |
7478 | h, sec, relocation, | |
7479 | unresolved_reloc, warned); | |
5bd4f169 | 7480 | sym_name = h->root.root.string; |
0d4792f7 | 7481 | sym_type = h->type; |
5bd4f169 AM |
7482 | } |
7483 | ||
951fd09b AM |
7484 | /* TLS optimizations. Replace instruction sequences and relocs |
7485 | based on information we collected in tls_optimize. We edit | |
7486 | RELOCS so that --emit-relocs will output something sensible | |
7487 | for the final instruction stream. */ | |
7488 | tls_mask = 0; | |
7489 | tls_gd = 0; | |
0d4792f7 | 7490 | toc_symndx = 0; |
d881513a | 7491 | if (IS_PPC64_TLS_RELOC (r_type)) |
411e1bfb AM |
7492 | { |
7493 | if (h != NULL) | |
e7b938ca | 7494 | tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask; |
411e1bfb AM |
7495 | else if (local_got_ents != NULL) |
7496 | { | |
e7b938ca AM |
7497 | char *lgot_masks; |
7498 | lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); | |
7499 | tls_mask = lgot_masks[r_symndx]; | |
411e1bfb | 7500 | } |
0d4792f7 AM |
7501 | if (tls_mask == 0 && r_type == R_PPC64_TLS) |
7502 | { | |
7503 | /* Check for toc tls entries. */ | |
7504 | char *toc_tls; | |
7505 | ||
7506 | if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms, | |
7507 | rel, input_bfd)) | |
7508 | return FALSE; | |
7509 | ||
7510 | if (toc_tls) | |
7511 | tls_mask = *toc_tls; | |
7512 | } | |
7513 | } | |
7514 | ||
7515 | /* Check that tls relocs are used with tls syms, and non-tls | |
7516 | relocs are used with non-tls syms. */ | |
7517 | if (r_symndx != 0 | |
7518 | && r_type != R_PPC64_NONE | |
7519 | && (h == NULL | |
7520 | || h->root.type == bfd_link_hash_defined | |
7521 | || h->root.type == bfd_link_hash_defweak) | |
7522 | && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
7523 | { | |
7524 | if (r_type == R_PPC64_TLS && tls_mask != 0) | |
7525 | /* R_PPC64_TLS is OK against a symbol in the TOC. */ | |
7526 | ; | |
7527 | else | |
7528 | (*_bfd_error_handler) | |
7529 | (sym_type == STT_TLS | |
7530 | ? _("%s(%s+0x%lx): %s used with TLS symbol %s") | |
7531 | : _("%s(%s+0x%lx): %s used with non-TLS symbol %s"), | |
7532 | bfd_archive_filename (input_bfd), | |
7533 | input_section->name, | |
7534 | (long) rel->r_offset, | |
7535 | ppc64_elf_howto_table[r_type]->name, | |
7536 | sym_name); | |
411e1bfb AM |
7537 | } |
7538 | ||
7539 | /* Ensure reloc mapping code below stays sane. */ | |
7540 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 | |
7541 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 | |
7542 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) | |
7543 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) | |
7544 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) | |
7545 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) | |
7546 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) | |
7547 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) | |
7548 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) | |
7549 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) | |
7550 | abort (); | |
0d4792f7 | 7551 | |
411e1bfb AM |
7552 | switch (r_type) |
7553 | { | |
7554 | default: | |
411e1bfb AM |
7555 | break; |
7556 | ||
7557 | case R_PPC64_TOC16: | |
7558 | case R_PPC64_TOC16_LO: | |
7559 | case R_PPC64_TOC16_DS: | |
7560 | case R_PPC64_TOC16_LO_DS: | |
411e1bfb AM |
7561 | { |
7562 | /* Check for toc tls entries. */ | |
7563 | char *toc_tls; | |
951fd09b | 7564 | int retval; |
411e1bfb | 7565 | |
0d4792f7 AM |
7566 | retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms, |
7567 | rel, input_bfd); | |
951fd09b | 7568 | if (retval == 0) |
411e1bfb AM |
7569 | return FALSE; |
7570 | ||
7571 | if (toc_tls) | |
7572 | { | |
951fd09b | 7573 | tls_mask = *toc_tls; |
411e1bfb AM |
7574 | if (r_type == R_PPC64_TOC16_DS |
7575 | || r_type == R_PPC64_TOC16_LO_DS) | |
81407a69 AM |
7576 | { |
7577 | if (tls_mask != 0 | |
7578 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) | |
7579 | goto toctprel; | |
7580 | } | |
411e1bfb | 7581 | else |
951fd09b AM |
7582 | { |
7583 | /* If we found a GD reloc pair, then we might be | |
7584 | doing a GD->IE transition. */ | |
7585 | if (retval == 2) | |
7586 | { | |
7587 | tls_gd = TLS_TPRELGD; | |
7588 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7589 | goto tls_get_addr_check; | |
7590 | } | |
7591 | else if (retval == 3) | |
7592 | { | |
7593 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7594 | goto tls_get_addr_check; | |
7595 | } | |
7596 | } | |
411e1bfb AM |
7597 | } |
7598 | } | |
7599 | break; | |
7600 | ||
7601 | case R_PPC64_GOT_TPREL16_DS: | |
7602 | case R_PPC64_GOT_TPREL16_LO_DS: | |
951fd09b AM |
7603 | if (tls_mask != 0 |
7604 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7605 | { |
81407a69 | 7606 | toctprel: |
411e1bfb AM |
7607 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); |
7608 | insn &= 31 << 21; | |
7609 | insn |= 0x3c0d0000; /* addis 0,13,0 */ | |
7610 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
7611 | r_type = R_PPC64_TPREL16_HA; | |
0d4792f7 AM |
7612 | if (toc_symndx != 0) |
7613 | { | |
7614 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
7615 | /* We changed the symbol. Start over in order to | |
7616 | get h, sym, sec etc. right. */ | |
7617 | rel--; | |
7618 | continue; | |
7619 | } | |
7620 | else | |
7621 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7622 | } |
7623 | break; | |
7624 | ||
7625 | case R_PPC64_TLS: | |
951fd09b AM |
7626 | if (tls_mask != 0 |
7627 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7628 | { |
50bc7936 | 7629 | bfd_vma rtra; |
411e1bfb | 7630 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
772119ce | 7631 | if ((insn & ((0x3f << 26) | (31 << 11))) |
411e1bfb AM |
7632 | == ((31 << 26) | (13 << 11))) |
7633 | rtra = insn & ((1 << 26) - (1 << 16)); | |
772119ce | 7634 | else if ((insn & ((0x3f << 26) | (31 << 16))) |
411e1bfb AM |
7635 | == ((31 << 26) | (13 << 16))) |
7636 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
7637 | else | |
7638 | abort (); | |
7639 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
7640 | /* add -> addi. */ | |
7641 | insn = 14 << 26; | |
7642 | else if ((insn & (31 << 1)) == 23 << 1 | |
7643 | && ((insn & (31 << 6)) < 14 << 6 | |
7644 | || ((insn & (31 << 6)) >= 16 << 6 | |
7645 | && (insn & (31 << 6)) < 24 << 6))) | |
7646 | /* load and store indexed -> dform. */ | |
7647 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
7648 | else if ((insn & (31 << 1)) == 21 << 1 | |
7649 | && (insn & (0x1a << 6)) == 0) | |
7650 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
7651 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
7652 | | ((insn >> 6) & 1)); | |
7653 | else if ((insn & (31 << 1)) == 21 << 1 | |
7654 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
7655 | /* lwax -> lwa. */ | |
7656 | insn = (58 << 26) | 2; | |
7657 | else | |
7658 | abort (); | |
7659 | insn |= rtra; | |
7660 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
411e1bfb AM |
7661 | /* Was PPC64_TLS which sits on insn boundary, now |
7662 | PPC64_TPREL16_LO which is at insn+2. */ | |
7663 | rel->r_offset += 2; | |
0d4792f7 AM |
7664 | r_type = R_PPC64_TPREL16_LO; |
7665 | if (toc_symndx != 0) | |
7666 | { | |
7667 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | |
7668 | /* We changed the symbol. Start over in order to | |
7669 | get h, sym, sec etc. right. */ | |
7670 | rel--; | |
7671 | continue; | |
7672 | } | |
7673 | else | |
7674 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7675 | } |
7676 | break; | |
7677 | ||
411e1bfb AM |
7678 | case R_PPC64_GOT_TLSGD16_HI: |
7679 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b AM |
7680 | tls_gd = TLS_TPRELGD; |
7681 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7682 | goto tls_gdld_hi; | |
7683 | break; | |
7684 | ||
411e1bfb AM |
7685 | case R_PPC64_GOT_TLSLD16_HI: |
7686 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 7687 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
411e1bfb | 7688 | { |
951fd09b AM |
7689 | tls_gdld_hi: |
7690 | if ((tls_mask & tls_gd) != 0) | |
7691 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7692 | + R_PPC64_GOT_TPREL16_DS); | |
7693 | else | |
411e1bfb | 7694 | { |
951fd09b AM |
7695 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
7696 | rel->r_offset -= 2; | |
7697 | r_type = R_PPC64_NONE; | |
411e1bfb | 7698 | } |
951fd09b | 7699 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb AM |
7700 | } |
7701 | break; | |
7702 | ||
951fd09b AM |
7703 | case R_PPC64_GOT_TLSGD16: |
7704 | case R_PPC64_GOT_TLSGD16_LO: | |
7705 | tls_gd = TLS_TPRELGD; | |
7706 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7707 | goto tls_get_addr_check; | |
7708 | break; | |
411e1bfb | 7709 | |
951fd09b AM |
7710 | case R_PPC64_GOT_TLSLD16: |
7711 | case R_PPC64_GOT_TLSLD16_LO: | |
7712 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7713 | { | |
7714 | tls_get_addr_check: | |
7715 | if (rel + 1 < relend) | |
411e1bfb | 7716 | { |
951fd09b AM |
7717 | enum elf_ppc64_reloc_type r_type2; |
7718 | unsigned long r_symndx2; | |
7719 | struct elf_link_hash_entry *h2; | |
7720 | bfd_vma insn1, insn2, insn3; | |
7721 | bfd_vma offset; | |
7722 | ||
7723 | /* The next instruction should be a call to | |
7724 | __tls_get_addr. Peek at the reloc to be sure. */ | |
4ce794b7 | 7725 | r_type2 = ELF64_R_TYPE (rel[1].r_info); |
951fd09b AM |
7726 | r_symndx2 = ELF64_R_SYM (rel[1].r_info); |
7727 | if (r_symndx2 < symtab_hdr->sh_info | |
7728 | || (r_type2 != R_PPC64_REL14 | |
7729 | && r_type2 != R_PPC64_REL14_BRTAKEN | |
7730 | && r_type2 != R_PPC64_REL14_BRNTAKEN | |
7731 | && r_type2 != R_PPC64_REL24)) | |
7732 | break; | |
7733 | ||
7734 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
7735 | while (h2->root.type == bfd_link_hash_indirect | |
7736 | || h2->root.type == bfd_link_hash_warning) | |
7737 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
7738 | if (h2 == NULL || h2 != htab->tls_get_addr) | |
7739 | break; | |
7740 | ||
7741 | /* OK, it checks out. Replace the call. */ | |
7742 | offset = rel[1].r_offset; | |
7743 | insn1 = bfd_get_32 (output_bfd, | |
7744 | contents + rel->r_offset - 2); | |
7745 | insn3 = bfd_get_32 (output_bfd, | |
7746 | contents + offset + 4); | |
7747 | if ((tls_mask & tls_gd) != 0) | |
411e1bfb | 7748 | { |
951fd09b AM |
7749 | /* IE */ |
7750 | insn1 &= (1 << 26) - (1 << 2); | |
7751 | insn1 |= 58 << 26; /* ld */ | |
7752 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
7753 | rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); | |
7754 | if ((tls_mask & TLS_EXPLICIT) == 0) | |
7755 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7756 | + R_PPC64_GOT_TPREL16_DS); | |
7757 | else | |
7758 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; | |
7759 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7760 | } |
7761 | else | |
951fd09b AM |
7762 | { |
7763 | /* LE */ | |
7764 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ | |
7765 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7766 | if (tls_gd == 0) | |
7767 | { | |
7768 | /* Was an LD reloc. */ | |
7769 | r_symndx = 0; | |
e1918d23 AM |
7770 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
7771 | rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; | |
951fd09b | 7772 | } |
0d4792f7 AM |
7773 | else if (toc_symndx != 0) |
7774 | r_symndx = toc_symndx; | |
951fd09b AM |
7775 | r_type = R_PPC64_TPREL16_HA; |
7776 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7777 | rel[1].r_info = ELF64_R_INFO (r_symndx, | |
7778 | R_PPC64_TPREL16_LO); | |
7779 | rel[1].r_offset += 2; | |
7780 | } | |
7781 | if (insn3 == NOP | |
7782 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
7783 | { | |
7784 | insn3 = insn2; | |
7785 | insn2 = NOP; | |
7786 | rel[1].r_offset += 4; | |
7787 | } | |
7788 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); | |
7789 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7790 | bfd_put_32 (output_bfd, insn3, contents + offset + 4); | |
0d4792f7 | 7791 | if (tls_gd == 0 || toc_symndx != 0) |
951fd09b | 7792 | { |
0d4792f7 AM |
7793 | /* We changed the symbol. Start over in order |
7794 | to get h, sym, sec etc. right. */ | |
951fd09b AM |
7795 | rel--; |
7796 | continue; | |
7797 | } | |
411e1bfb | 7798 | } |
411e1bfb | 7799 | } |
411e1bfb AM |
7800 | break; |
7801 | ||
7802 | case R_PPC64_DTPMOD64: | |
951fd09b AM |
7803 | if (rel + 1 < relend |
7804 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
7805 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 7806 | { |
951fd09b AM |
7807 | if ((tls_mask & TLS_GD) == 0) |
7808 | { | |
7809 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); | |
7810 | if ((tls_mask & TLS_TPRELGD) != 0) | |
7811 | r_type = R_PPC64_TPREL64; | |
7812 | else | |
7813 | { | |
4ce794b7 | 7814 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
951fd09b AM |
7815 | r_type = R_PPC64_NONE; |
7816 | } | |
7817 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7818 | } | |
7819 | } | |
7820 | else | |
7821 | { | |
7822 | if ((tls_mask & TLS_LD) == 0) | |
411e1bfb | 7823 | { |
4ce794b7 | 7824 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
411e1bfb | 7825 | r_type = R_PPC64_NONE; |
951fd09b | 7826 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb | 7827 | } |
411e1bfb AM |
7828 | } |
7829 | break; | |
7830 | ||
7831 | case R_PPC64_TPREL64: | |
951fd09b | 7832 | if ((tls_mask & TLS_TPREL) == 0) |
411e1bfb AM |
7833 | { |
7834 | r_type = R_PPC64_NONE; | |
7835 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7836 | } | |
7837 | break; | |
7838 | } | |
7839 | ||
7840 | /* Handle other relocations that tweak non-addend part of insn. */ | |
86c76c7b | 7841 | insn = 0; |
65f38f15 | 7842 | switch (r_type) |
5bd4f169 AM |
7843 | { |
7844 | default: | |
65f38f15 | 7845 | break; |
5bd4f169 | 7846 | |
65f38f15 AM |
7847 | /* Branch taken prediction relocations. */ |
7848 | case R_PPC64_ADDR14_BRTAKEN: | |
7849 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
7850 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
7851 | /* Fall thru. */ | |
65f38f15 | 7852 | |
86c76c7b | 7853 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
7854 | case R_PPC64_ADDR14_BRNTAKEN: |
7855 | case R_PPC64_REL14_BRNTAKEN: | |
411e1bfb AM |
7856 | insn |= bfd_get_32 (output_bfd, |
7857 | contents + rel->r_offset) & ~(0x01 << 21); | |
96e0dda4 AM |
7858 | if (is_power4) |
7859 | { | |
7860 | /* Set 'a' bit. This is 0b00010 in BO field for branch | |
7861 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
7862 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
7863 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
7864 | insn |= 0x02 << 21; | |
7865 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
7866 | insn |= 0x08 << 21; | |
7867 | else | |
7868 | break; | |
7869 | } | |
65f38f15 | 7870 | else |
96e0dda4 | 7871 | { |
411e1bfb | 7872 | from = (rel->r_offset |
805fc799 AM |
7873 | + input_section->output_offset |
7874 | + input_section->output_section->vma); | |
7875 | ||
96e0dda4 | 7876 | /* Invert 'y' bit if not the default. */ |
411e1bfb | 7877 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) |
96e0dda4 AM |
7878 | insn ^= 0x01 << 21; |
7879 | } | |
86c76c7b | 7880 | |
4ce794b7 | 7881 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
65f38f15 | 7882 | break; |
5bd4f169 | 7883 | |
65f38f15 | 7884 | case R_PPC64_REL24: |
ad8e1ba5 AM |
7885 | /* Calls to functions with a different TOC, such as calls to |
7886 | shared objects, need to alter the TOC pointer. This is | |
7887 | done using a linkage stub. A REL24 branching to these | |
7888 | linkage stubs needs to be followed by a nop, as the nop | |
7889 | will be replaced with an instruction to restore the TOC | |
7890 | base pointer. */ | |
7891 | if (((h != NULL | |
34814b9f | 7892 | && (fdh = &((struct ppc_link_hash_entry *) h)->oh->elf) != NULL |
ad8e1ba5 AM |
7893 | && fdh->plt.plist != NULL) |
7894 | || ((fdh = h, sec) != NULL | |
7895 | && sec->output_section != NULL | |
7896 | && (htab->stub_group[sec->id].toc_off | |
7897 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 | 7898 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, |
ad8e1ba5 AM |
7899 | rel, htab)) != NULL |
7900 | && (stub_entry->stub_type == ppc_stub_plt_call | |
7901 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off | |
7902 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) | |
41bd81ab | 7903 | { |
b34976b6 | 7904 | bfd_boolean can_plt_call = 0; |
721956f4 | 7905 | |
eea6121a | 7906 | if (rel->r_offset + 8 <= input_section->size) |
41bd81ab | 7907 | { |
411e1bfb | 7908 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); |
721956f4 AM |
7909 | if (insn == NOP |
7910 | || insn == CROR_151515 || insn == CROR_313131) | |
41bd81ab | 7911 | { |
4ce794b7 | 7912 | bfd_put_32 (input_bfd, LD_R2_40R1, |
411e1bfb | 7913 | contents + rel->r_offset + 4); |
721956f4 | 7914 | can_plt_call = 1; |
41bd81ab | 7915 | } |
5bd4f169 | 7916 | } |
721956f4 AM |
7917 | |
7918 | if (!can_plt_call) | |
7919 | { | |
ad8e1ba5 AM |
7920 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7921 | { | |
7922 | /* If this is a plain branch rather than a branch | |
7923 | and link, don't require a nop. */ | |
7924 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
7925 | if ((insn & 1) == 0) | |
7926 | can_plt_call = 1; | |
7927 | } | |
6ab189d5 AM |
7928 | else if (h != NULL |
7929 | && strcmp (h->root.root.string, | |
7930 | ".__libc_start_main") == 0) | |
7931 | { | |
7932 | /* Allow crt1 branch to go via a toc adjusting stub. */ | |
7933 | can_plt_call = 1; | |
7934 | } | |
ad8e1ba5 AM |
7935 | else |
7936 | { | |
7937 | if (strcmp (input_section->output_section->name, | |
7938 | ".init") == 0 | |
7939 | || strcmp (input_section->output_section->name, | |
7940 | ".fini") == 0) | |
7941 | (*_bfd_error_handler) | |
7942 | (_("%s(%s+0x%lx): automatic multiple TOCs " | |
7943 | "not supported using your crt files; " | |
7944 | "recompile with -mminimal-toc or upgrade gcc"), | |
7945 | bfd_archive_filename (input_bfd), | |
7946 | input_section->name, | |
7947 | (long) rel->r_offset); | |
7948 | else | |
7949 | (*_bfd_error_handler) | |
7950 | (_("%s(%s+0x%lx): sibling call optimization to `%s' " | |
7951 | "does not allow automatic multiple TOCs; " | |
7952 | "recompile with -mminimal-toc or " | |
7953 | "-fno-optimize-sibling-calls, " | |
7954 | "or make `%s' extern"), | |
7955 | bfd_archive_filename (input_bfd), | |
7956 | input_section->name, | |
7957 | (long) rel->r_offset, | |
7958 | sym_name, | |
7959 | sym_name); | |
7960 | bfd_set_error (bfd_error_bad_value); | |
7961 | ret = FALSE; | |
7962 | } | |
721956f4 AM |
7963 | } |
7964 | ||
7965 | if (can_plt_call) | |
7966 | { | |
7967 | relocation = (stub_entry->stub_offset | |
7968 | + stub_entry->stub_sec->output_offset | |
7969 | + stub_entry->stub_sec->output_section->vma); | |
ad8e1ba5 AM |
7970 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7971 | unresolved_reloc = FALSE; | |
721956f4 | 7972 | } |
5bd4f169 | 7973 | } |
e86ce104 | 7974 | |
06da1e8e AM |
7975 | /* NOP out calls to undefined weak functions. |
7976 | We can thus call a weak function without first | |
7977 | checking whether the function is defined. */ | |
e86ce104 AM |
7978 | if (h != NULL |
7979 | && h->root.type == bfd_link_hash_undefweak | |
721956f4 | 7980 | && relocation == 0 |
411e1bfb | 7981 | && rel->r_addend == 0) |
e86ce104 | 7982 | { |
06da1e8e AM |
7983 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
7984 | continue; | |
e86ce104 | 7985 | } |
65f38f15 AM |
7986 | break; |
7987 | } | |
5bd4f169 | 7988 | |
65f38f15 | 7989 | /* Set `addend'. */ |
411e1bfb AM |
7990 | tls_type = 0; |
7991 | addend = rel->r_addend; | |
65f38f15 AM |
7992 | switch (r_type) |
7993 | { | |
7994 | default: | |
7995 | (*_bfd_error_handler) | |
7996 | (_("%s: unknown relocation type %d for symbol %s"), | |
7997 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); | |
5bd4f169 | 7998 | |
65f38f15 | 7999 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 8000 | ret = FALSE; |
65f38f15 | 8001 | continue; |
5bd4f169 | 8002 | |
65f38f15 | 8003 | case R_PPC64_NONE: |
411e1bfb | 8004 | case R_PPC64_TLS: |
04c9666a AM |
8005 | case R_PPC64_GNU_VTINHERIT: |
8006 | case R_PPC64_GNU_VTENTRY: | |
65f38f15 | 8007 | continue; |
5bd4f169 AM |
8008 | |
8009 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
8010 | address in the GOT as relocation value instead of the | |
411e1bfb | 8011 | symbol's value itself. Also, create a GOT entry for the |
5bd4f169 | 8012 | symbol and put the symbol value there. */ |
411e1bfb AM |
8013 | case R_PPC64_GOT_TLSGD16: |
8014 | case R_PPC64_GOT_TLSGD16_LO: | |
8015 | case R_PPC64_GOT_TLSGD16_HI: | |
8016 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 8017 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
8018 | goto dogot; |
8019 | ||
8020 | case R_PPC64_GOT_TLSLD16: | |
8021 | case R_PPC64_GOT_TLSLD16_LO: | |
8022 | case R_PPC64_GOT_TLSLD16_HI: | |
8023 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 8024 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
8025 | goto dogot; |
8026 | ||
8027 | case R_PPC64_GOT_TPREL16_DS: | |
8028 | case R_PPC64_GOT_TPREL16_LO_DS: | |
8029 | case R_PPC64_GOT_TPREL16_HI: | |
8030 | case R_PPC64_GOT_TPREL16_HA: | |
8031 | tls_type = TLS_TLS | TLS_TPREL; | |
8032 | goto dogot; | |
8033 | ||
8034 | case R_PPC64_GOT_DTPREL16_DS: | |
8035 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
8036 | case R_PPC64_GOT_DTPREL16_HI: | |
8037 | case R_PPC64_GOT_DTPREL16_HA: | |
8038 | tls_type = TLS_TLS | TLS_DTPREL; | |
8039 | goto dogot; | |
8040 | ||
65f38f15 AM |
8041 | case R_PPC64_GOT16: |
8042 | case R_PPC64_GOT16_LO: | |
8043 | case R_PPC64_GOT16_HI: | |
8044 | case R_PPC64_GOT16_HA: | |
8045 | case R_PPC64_GOT16_DS: | |
8046 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb | 8047 | dogot: |
5bd4f169 AM |
8048 | { |
8049 | /* Relocation is to the entry for this symbol in the global | |
8050 | offset table. */ | |
e717da7e | 8051 | asection *got; |
d881513a | 8052 | bfd_vma *offp; |
5bd4f169 | 8053 | bfd_vma off; |
d881513a | 8054 | unsigned long indx = 0; |
65f38f15 | 8055 | |
d881513a AM |
8056 | if (tls_type == (TLS_TLS | TLS_LD) |
8057 | && (h == NULL | |
8058 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
e717da7e | 8059 | offp = &ppc64_tlsld_got (input_bfd)->offset; |
411e1bfb | 8060 | else |
5bd4f169 | 8061 | { |
d881513a | 8062 | struct got_entry *ent; |
5bd4f169 | 8063 | |
d881513a AM |
8064 | if (h != NULL) |
8065 | { | |
8066 | bfd_boolean dyn = htab->elf.dynamic_sections_created; | |
f4656909 | 8067 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
d881513a | 8068 | || (info->shared |
586119b3 | 8069 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
d881513a AM |
8070 | /* This is actually a static link, or it is a |
8071 | -Bsymbolic link and the symbol is defined | |
8072 | locally, or the symbol was forced to be local | |
8073 | because of a version file. */ | |
8074 | ; | |
8075 | else | |
8076 | { | |
8077 | indx = h->dynindx; | |
8078 | unresolved_reloc = FALSE; | |
8079 | } | |
8080 | ent = h->got.glist; | |
8081 | } | |
411e1bfb | 8082 | else |
5bd4f169 | 8083 | { |
d881513a AM |
8084 | if (local_got_ents == NULL) |
8085 | abort (); | |
8086 | ent = local_got_ents[r_symndx]; | |
5bd4f169 | 8087 | } |
d881513a AM |
8088 | |
8089 | for (; ent != NULL; ent = ent->next) | |
8090 | if (ent->addend == rel->r_addend | |
e717da7e | 8091 | && ent->owner == input_bfd |
d881513a AM |
8092 | && ent->tls_type == tls_type) |
8093 | break; | |
8094 | if (ent == NULL) | |
8095 | abort (); | |
8096 | offp = &ent->got.offset; | |
5bd4f169 | 8097 | } |
411e1bfb | 8098 | |
e717da7e AM |
8099 | got = ppc64_elf_tdata (input_bfd)->got; |
8100 | if (got == NULL) | |
8101 | abort (); | |
8102 | ||
411e1bfb AM |
8103 | /* The offset must always be a multiple of 8. We use the |
8104 | least significant bit to record whether we have already | |
8105 | processed this entry. */ | |
d881513a | 8106 | off = *offp; |
411e1bfb AM |
8107 | if ((off & 1) != 0) |
8108 | off &= ~1; | |
5bd4f169 AM |
8109 | else |
8110 | { | |
411e1bfb AM |
8111 | /* Generate relocs for the dynamic linker, except in |
8112 | the case of TLSLD where we'll use one entry per | |
8113 | module. */ | |
e717da7e AM |
8114 | asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; |
8115 | ||
d881513a | 8116 | *offp = off | 1; |
4e795f50 AM |
8117 | if ((info->shared || indx != 0) |
8118 | && (h == NULL | |
8119 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8120 | || h->root.type != bfd_link_hash_undefweak)) | |
5bd4f169 | 8121 | { |
e717da7e AM |
8122 | outrel.r_offset = (got->output_section->vma |
8123 | + got->output_offset | |
411e1bfb | 8124 | + off); |
81407a69 | 8125 | outrel.r_addend = rel->r_addend; |
d881513a | 8126 | if (tls_type & (TLS_LD | TLS_GD)) |
5bd4f169 | 8127 | { |
411e1bfb | 8128 | outrel.r_addend = 0; |
e515b051 | 8129 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
d881513a AM |
8130 | if (tls_type == (TLS_TLS | TLS_GD)) |
8131 | { | |
e717da7e AM |
8132 | loc = relgot->contents; |
8133 | loc += (relgot->reloc_count++ | |
d881513a AM |
8134 | * sizeof (Elf64_External_Rela)); |
8135 | bfd_elf64_swap_reloca_out (output_bfd, | |
8136 | &outrel, loc); | |
e515b051 | 8137 | outrel.r_offset += 8; |
81407a69 | 8138 | outrel.r_addend = rel->r_addend; |
d881513a AM |
8139 | outrel.r_info |
8140 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); | |
d881513a | 8141 | } |
411e1bfb | 8142 | } |
951fd09b | 8143 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
411e1bfb | 8144 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
951fd09b | 8145 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb AM |
8146 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
8147 | else if (indx == 0) | |
81407a69 AM |
8148 | { |
8149 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE); | |
8150 | ||
8151 | /* Write the .got section contents for the sake | |
8152 | of prelink. */ | |
e717da7e | 8153 | loc = got->contents + off; |
23fbd6fa JJ |
8154 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
8155 | loc); | |
81407a69 | 8156 | } |
411e1bfb AM |
8157 | else |
8158 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); | |
81407a69 AM |
8159 | |
8160 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) | |
e515b051 AM |
8161 | { |
8162 | outrel.r_addend += relocation; | |
8163 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
e1918d23 | 8164 | outrel.r_addend -= htab->elf.tls_sec->vma; |
e515b051 | 8165 | } |
e717da7e AM |
8166 | loc = relgot->contents; |
8167 | loc += (relgot->reloc_count++ | |
411e1bfb AM |
8168 | * sizeof (Elf64_External_Rela)); |
8169 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
8170 | } | |
8171 | ||
ad8e1ba5 | 8172 | /* Init the .got section contents here if we're not |
81407a69 | 8173 | emitting a reloc. */ |
d881513a | 8174 | else |
411e1bfb | 8175 | { |
d881513a | 8176 | relocation += rel->r_addend; |
7b609f53 AM |
8177 | if (tls_type == (TLS_TLS | TLS_LD)) |
8178 | relocation = 1; | |
8179 | else if (tls_type != 0) | |
411e1bfb | 8180 | { |
e1918d23 | 8181 | relocation -= htab->elf.tls_sec->vma + DTP_OFFSET; |
7b609f53 | 8182 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 8183 | relocation += DTP_OFFSET - TP_OFFSET; |
5bd4f169 | 8184 | |
7b609f53 AM |
8185 | if (tls_type == (TLS_TLS | TLS_GD)) |
8186 | { | |
8187 | bfd_put_64 (output_bfd, relocation, | |
e717da7e | 8188 | got->contents + off + 8); |
7b609f53 AM |
8189 | relocation = 1; |
8190 | } | |
411e1bfb | 8191 | } |
7b609f53 | 8192 | |
411e1bfb | 8193 | bfd_put_64 (output_bfd, relocation, |
e717da7e | 8194 | got->contents + off); |
5bd4f169 AM |
8195 | } |
8196 | } | |
8197 | ||
65f38f15 AM |
8198 | if (off >= (bfd_vma) -2) |
8199 | abort (); | |
8200 | ||
e717da7e | 8201 | relocation = got->output_offset + off; |
65f38f15 | 8202 | |
5bd4f169 | 8203 | /* TOC base (r2) is TOC start plus 0x8000. */ |
e717da7e | 8204 | addend = -TOC_BASE_OFF; |
5bd4f169 | 8205 | } |
65f38f15 AM |
8206 | break; |
8207 | ||
8208 | case R_PPC64_PLT16_HA: | |
8209 | case R_PPC64_PLT16_HI: | |
8210 | case R_PPC64_PLT16_LO: | |
8211 | case R_PPC64_PLT32: | |
8212 | case R_PPC64_PLT64: | |
8213 | /* Relocation is to the entry for this symbol in the | |
8214 | procedure linkage table. */ | |
8215 | ||
8216 | /* Resolve a PLT reloc against a local symbol directly, | |
8217 | without using the procedure linkage table. */ | |
8218 | if (h == NULL) | |
8219 | break; | |
8220 | ||
411e1bfb AM |
8221 | /* It's possible that we didn't make a PLT entry for this |
8222 | symbol. This happens when statically linking PIC code, | |
8223 | or when using -Bsymbolic. Go find a match if there is a | |
8224 | PLT entry. */ | |
4ce794b7 | 8225 | if (htab->plt != NULL) |
65f38f15 | 8226 | { |
411e1bfb AM |
8227 | struct plt_entry *ent; |
8228 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8229 | if (ent->addend == rel->r_addend | |
8230 | && ent->plt.offset != (bfd_vma) -1) | |
8231 | { | |
4ce794b7 AM |
8232 | relocation = (htab->plt->output_section->vma |
8233 | + htab->plt->output_offset | |
411e1bfb AM |
8234 | + ent->plt.offset); |
8235 | unresolved_reloc = FALSE; | |
8236 | } | |
65f38f15 | 8237 | } |
65f38f15 | 8238 | break; |
5bd4f169 | 8239 | |
0b13192e AM |
8240 | case R_PPC64_TOC: |
8241 | /* Relocation value is TOC base. */ | |
8242 | relocation = TOCstart; | |
8243 | if (r_symndx == 0) | |
8244 | relocation += htab->stub_group[input_section->id].toc_off; | |
8517fae7 AM |
8245 | else if (unresolved_reloc) |
8246 | ; | |
8247 | else if (sec != NULL && sec->id <= htab->top_id) | |
0b13192e AM |
8248 | relocation += htab->stub_group[sec->id].toc_off; |
8249 | else | |
8250 | unresolved_reloc = TRUE; | |
8251 | goto dodyn2; | |
8252 | ||
5bd4f169 AM |
8253 | /* TOC16 relocs. We want the offset relative to the TOC base, |
8254 | which is the address of the start of the TOC plus 0x8000. | |
8255 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
8256 | in this order. */ | |
65f38f15 AM |
8257 | case R_PPC64_TOC16: |
8258 | case R_PPC64_TOC16_LO: | |
8259 | case R_PPC64_TOC16_HI: | |
8260 | case R_PPC64_TOC16_DS: | |
8261 | case R_PPC64_TOC16_LO_DS: | |
8262 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 8263 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
5bd4f169 AM |
8264 | break; |
8265 | ||
8266 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
8267 | case R_PPC64_SECTOFF: |
8268 | case R_PPC64_SECTOFF_LO: | |
8269 | case R_PPC64_SECTOFF_HI: | |
8270 | case R_PPC64_SECTOFF_DS: | |
8271 | case R_PPC64_SECTOFF_LO_DS: | |
8272 | case R_PPC64_SECTOFF_HA: | |
4ce794b7 | 8273 | if (sec != NULL) |
65f38f15 | 8274 | addend -= sec->output_section->vma; |
5bd4f169 AM |
8275 | break; |
8276 | ||
721956f4 AM |
8277 | case R_PPC64_REL14: |
8278 | case R_PPC64_REL14_BRNTAKEN: | |
8279 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
8280 | case R_PPC64_REL24: |
8281 | break; | |
8282 | ||
411e1bfb AM |
8283 | case R_PPC64_TPREL16: |
8284 | case R_PPC64_TPREL16_LO: | |
8285 | case R_PPC64_TPREL16_HI: | |
8286 | case R_PPC64_TPREL16_HA: | |
8287 | case R_PPC64_TPREL16_DS: | |
8288 | case R_PPC64_TPREL16_LO_DS: | |
8289 | case R_PPC64_TPREL16_HIGHER: | |
8290 | case R_PPC64_TPREL16_HIGHERA: | |
8291 | case R_PPC64_TPREL16_HIGHEST: | |
8292 | case R_PPC64_TPREL16_HIGHESTA: | |
e1918d23 | 8293 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8294 | if (info->shared) |
8295 | /* The TPREL16 relocs shouldn't really be used in shared | |
8296 | libs as they will result in DT_TEXTREL being set, but | |
8297 | support them anyway. */ | |
8298 | goto dodyn; | |
8299 | break; | |
8300 | ||
8301 | case R_PPC64_DTPREL16: | |
8302 | case R_PPC64_DTPREL16_LO: | |
8303 | case R_PPC64_DTPREL16_HI: | |
8304 | case R_PPC64_DTPREL16_HA: | |
8305 | case R_PPC64_DTPREL16_DS: | |
8306 | case R_PPC64_DTPREL16_LO_DS: | |
8307 | case R_PPC64_DTPREL16_HIGHER: | |
8308 | case R_PPC64_DTPREL16_HIGHERA: | |
8309 | case R_PPC64_DTPREL16_HIGHEST: | |
8310 | case R_PPC64_DTPREL16_HIGHESTA: | |
e1918d23 | 8311 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8312 | break; |
8313 | ||
e515b051 AM |
8314 | case R_PPC64_DTPMOD64: |
8315 | relocation = 1; | |
8316 | addend = 0; | |
8317 | goto dodyn; | |
8318 | ||
411e1bfb | 8319 | case R_PPC64_TPREL64: |
e1918d23 | 8320 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
411e1bfb AM |
8321 | goto dodyn; |
8322 | ||
8323 | case R_PPC64_DTPREL64: | |
e1918d23 | 8324 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
411e1bfb AM |
8325 | /* Fall thru */ |
8326 | ||
65f38f15 AM |
8327 | /* Relocations that may need to be propagated if this is a |
8328 | dynamic object. */ | |
04c9666a | 8329 | case R_PPC64_REL30: |
65f38f15 AM |
8330 | case R_PPC64_REL32: |
8331 | case R_PPC64_REL64: | |
8332 | case R_PPC64_ADDR14: | |
8333 | case R_PPC64_ADDR14_BRNTAKEN: | |
8334 | case R_PPC64_ADDR14_BRTAKEN: | |
8335 | case R_PPC64_ADDR16: | |
8336 | case R_PPC64_ADDR16_DS: | |
8337 | case R_PPC64_ADDR16_HA: | |
8338 | case R_PPC64_ADDR16_HI: | |
8339 | case R_PPC64_ADDR16_HIGHER: | |
8340 | case R_PPC64_ADDR16_HIGHERA: | |
8341 | case R_PPC64_ADDR16_HIGHEST: | |
8342 | case R_PPC64_ADDR16_HIGHESTA: | |
8343 | case R_PPC64_ADDR16_LO: | |
8344 | case R_PPC64_ADDR16_LO_DS: | |
8345 | case R_PPC64_ADDR24: | |
65f38f15 AM |
8346 | case R_PPC64_ADDR32: |
8347 | case R_PPC64_ADDR64: | |
8348 | case R_PPC64_UADDR16: | |
8349 | case R_PPC64_UADDR32: | |
8350 | case R_PPC64_UADDR64: | |
ec338859 AM |
8351 | /* r_symndx will be zero only for relocs against symbols |
8352 | from removed linkonce sections, or sections discarded by | |
8353 | a linker script. */ | |
411e1bfb | 8354 | dodyn: |
5d1634d7 AM |
8355 | if (r_symndx == 0) |
8356 | break; | |
8357 | /* Fall thru. */ | |
8358 | ||
0b13192e | 8359 | dodyn2: |
5d1634d7 | 8360 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
8361 | break; |
8362 | ||
41bd81ab AM |
8363 | if (NO_OPD_RELOCS && is_opd) |
8364 | break; | |
8365 | ||
65f38f15 | 8366 | if ((info->shared |
4e795f50 AM |
8367 | && (h == NULL |
8368 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8369 | || h->root.type != bfd_link_hash_undefweak) | |
411e1bfb | 8370 | && (MUST_BE_DYN_RELOC (r_type) |
f6c52c13 | 8371 | || !SYMBOL_CALLS_LOCAL (info, h))) |
f4656909 AM |
8372 | || (ELIMINATE_COPY_RELOCS |
8373 | && !info->shared | |
65f38f15 AM |
8374 | && h != NULL |
8375 | && h->dynindx != -1 | |
8376 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
8377 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
8378 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
65f38f15 AM |
8379 | { |
8380 | Elf_Internal_Rela outrel; | |
b34976b6 | 8381 | bfd_boolean skip, relocate; |
65f38f15 | 8382 | asection *sreloc; |
947216bf | 8383 | bfd_byte *loc; |
1cf1f670 | 8384 | bfd_vma out_off; |
65f38f15 AM |
8385 | |
8386 | /* When generating a dynamic object, these relocations | |
8387 | are copied into the output file to be resolved at run | |
8388 | time. */ | |
8389 | ||
b34976b6 AM |
8390 | skip = FALSE; |
8391 | relocate = FALSE; | |
65f38f15 | 8392 | |
1cf1f670 AM |
8393 | out_off = _bfd_elf_section_offset (output_bfd, info, |
8394 | input_section, rel->r_offset); | |
8395 | if (out_off == (bfd_vma) -1) | |
b34976b6 | 8396 | skip = TRUE; |
1cf1f670 | 8397 | else if (out_off == (bfd_vma) -2) |
b34976b6 | 8398 | skip = TRUE, relocate = TRUE; |
1cf1f670 AM |
8399 | out_off += (input_section->output_section->vma |
8400 | + input_section->output_offset); | |
8401 | outrel.r_offset = out_off; | |
411e1bfb | 8402 | outrel.r_addend = rel->r_addend; |
65f38f15 | 8403 | |
1cf1f670 AM |
8404 | /* Optimize unaligned reloc use. */ |
8405 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) | |
8406 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) | |
8407 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; | |
8408 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) | |
8409 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) | |
8410 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; | |
8411 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) | |
8412 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) | |
8413 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; | |
8414 | ||
65f38f15 | 8415 | if (skip) |
0bb2d96a | 8416 | memset (&outrel, 0, sizeof outrel); |
f6c52c13 | 8417 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
0b13192e AM |
8418 | && !is_opd |
8419 | && r_type != R_PPC64_TOC) | |
0bb2d96a | 8420 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
65f38f15 AM |
8421 | else |
8422 | { | |
41bd81ab AM |
8423 | /* This symbol is local, or marked to become local, |
8424 | or this is an opd section reloc which must point | |
8425 | at a local function. */ | |
65f38f15 | 8426 | outrel.r_addend += relocation; |
e86ce104 | 8427 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 8428 | { |
3fad3c7c | 8429 | if (is_opd && h != NULL) |
afbe61cf AM |
8430 | { |
8431 | /* Lie about opd entries. This case occurs | |
8432 | when building shared libraries and we | |
8433 | reference a function in another shared | |
3fad3c7c AM |
8434 | lib. The same thing happens for a weak |
8435 | definition in an application that's | |
8436 | overridden by a strong definition in a | |
8437 | shared lib. (I believe this is a generic | |
8438 | bug in binutils handling of weak syms.) | |
8439 | In these cases we won't use the opd | |
1e2f5b6e | 8440 | entry in this lib. */ |
b34976b6 | 8441 | unresolved_reloc = FALSE; |
afbe61cf | 8442 | } |
65f38f15 | 8443 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
81407a69 AM |
8444 | |
8445 | /* We need to relocate .opd contents for ld.so. | |
8446 | Prelink also wants simple and consistent rules | |
8447 | for relocs. This make all RELATIVE relocs have | |
8448 | *r_offset equal to r_addend. */ | |
8449 | relocate = TRUE; | |
65f38f15 AM |
8450 | } |
8451 | else | |
8452 | { | |
8453 | long indx = 0; | |
8454 | ||
41bd81ab | 8455 | if (bfd_is_abs_section (sec)) |
65f38f15 AM |
8456 | ; |
8457 | else if (sec == NULL || sec->owner == NULL) | |
8458 | { | |
8459 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8460 | return FALSE; |
65f38f15 AM |
8461 | } |
8462 | else | |
8463 | { | |
8464 | asection *osec; | |
8465 | ||
8466 | osec = sec->output_section; | |
8467 | indx = elf_section_data (osec)->dynindx; | |
8468 | ||
8469 | /* We are turning this relocation into one | |
8470 | against a section symbol, so subtract out | |
8471 | the output section's address but not the | |
8472 | offset of the input section in the output | |
8473 | section. */ | |
8474 | outrel.r_addend -= osec->vma; | |
8475 | } | |
8476 | ||
8477 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
8478 | } | |
8479 | } | |
8480 | ||
8481 | sreloc = elf_section_data (input_section)->sreloc; | |
8482 | if (sreloc == NULL) | |
8483 | abort (); | |
8484 | ||
947216bf AM |
8485 | loc = sreloc->contents; |
8486 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
8487 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
8488 | ||
8489 | /* If this reloc is against an external symbol, it will | |
8490 | be computed at runtime, so there's no need to do | |
81407a69 AM |
8491 | anything now. However, for the sake of prelink ensure |
8492 | that the section contents are a known value. */ | |
65f38f15 | 8493 | if (! relocate) |
81407a69 AM |
8494 | { |
8495 | unresolved_reloc = FALSE; | |
8496 | /* The value chosen here is quite arbitrary as ld.so | |
8497 | ignores section contents except for the special | |
8498 | case of .opd where the contents might be accessed | |
8499 | before relocation. Choose zero, as that won't | |
8500 | cause reloc overflow. */ | |
8501 | relocation = 0; | |
8502 | addend = 0; | |
8503 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs | |
8504 | to improve backward compatibility with older | |
8505 | versions of ld. */ | |
8506 | if (r_type == R_PPC64_ADDR64) | |
8507 | addend = outrel.r_addend; | |
8508 | /* Adjust pc_relative relocs to have zero in *r_offset. */ | |
4ce794b7 | 8509 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
000732f7 AM |
8510 | addend = (input_section->output_section->vma |
8511 | + input_section->output_offset | |
8512 | + rel->r_offset); | |
81407a69 | 8513 | } |
65f38f15 | 8514 | } |
5bd4f169 AM |
8515 | break; |
8516 | ||
65f38f15 AM |
8517 | case R_PPC64_COPY: |
8518 | case R_PPC64_GLOB_DAT: | |
8519 | case R_PPC64_JMP_SLOT: | |
8520 | case R_PPC64_RELATIVE: | |
8521 | /* We shouldn't ever see these dynamic relocs in relocatable | |
8522 | files. */ | |
ae9a127f | 8523 | /* Fall through. */ |
65f38f15 AM |
8524 | |
8525 | case R_PPC64_PLTGOT16: | |
8526 | case R_PPC64_PLTGOT16_DS: | |
8527 | case R_PPC64_PLTGOT16_HA: | |
8528 | case R_PPC64_PLTGOT16_HI: | |
8529 | case R_PPC64_PLTGOT16_LO: | |
8530 | case R_PPC64_PLTGOT16_LO_DS: | |
8531 | case R_PPC64_PLTREL32: | |
8532 | case R_PPC64_PLTREL64: | |
8533 | /* These ones haven't been implemented yet. */ | |
8534 | ||
8535 | (*_bfd_error_handler) | |
7b609f53 | 8536 | (_("%s: relocation %s is not supported for symbol %s."), |
65f38f15 | 8537 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8538 | ppc64_elf_howto_table[r_type]->name, sym_name); |
5bd4f169 AM |
8539 | |
8540 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 8541 | ret = FALSE; |
5bd4f169 | 8542 | continue; |
65f38f15 | 8543 | } |
5bd4f169 | 8544 | |
65f38f15 AM |
8545 | /* Do any further special processing. */ |
8546 | switch (r_type) | |
8547 | { | |
8548 | default: | |
8549 | break; | |
8550 | ||
8551 | case R_PPC64_ADDR16_HA: | |
8552 | case R_PPC64_ADDR16_HIGHERA: | |
8553 | case R_PPC64_ADDR16_HIGHESTA: | |
86bbe32f AM |
8554 | case R_PPC64_GOT16_HA: |
8555 | case R_PPC64_PLTGOT16_HA: | |
65f38f15 AM |
8556 | case R_PPC64_PLT16_HA: |
8557 | case R_PPC64_TOC16_HA: | |
8558 | case R_PPC64_SECTOFF_HA: | |
411e1bfb AM |
8559 | case R_PPC64_TPREL16_HA: |
8560 | case R_PPC64_DTPREL16_HA: | |
8561 | case R_PPC64_GOT_TLSGD16_HA: | |
8562 | case R_PPC64_GOT_TLSLD16_HA: | |
8563 | case R_PPC64_GOT_TPREL16_HA: | |
8564 | case R_PPC64_GOT_DTPREL16_HA: | |
8565 | case R_PPC64_TPREL16_HIGHER: | |
8566 | case R_PPC64_TPREL16_HIGHERA: | |
8567 | case R_PPC64_TPREL16_HIGHEST: | |
8568 | case R_PPC64_TPREL16_HIGHESTA: | |
8569 | case R_PPC64_DTPREL16_HIGHER: | |
8570 | case R_PPC64_DTPREL16_HIGHERA: | |
8571 | case R_PPC64_DTPREL16_HIGHEST: | |
8572 | case R_PPC64_DTPREL16_HIGHESTA: | |
65f38f15 AM |
8573 | /* It's just possible that this symbol is a weak symbol |
8574 | that's not actually defined anywhere. In that case, | |
8575 | 'sec' would be NULL, and we should leave the symbol | |
8576 | alone (it will be set to zero elsewhere in the link). */ | |
8577 | if (sec != NULL) | |
e515b051 AM |
8578 | /* Add 0x10000 if sign bit in 0:15 is set. |
8579 | Bits 0:15 are not used. */ | |
8580 | addend += 0x8000; | |
65f38f15 AM |
8581 | break; |
8582 | ||
8583 | case R_PPC64_ADDR16_DS: | |
8584 | case R_PPC64_ADDR16_LO_DS: | |
8585 | case R_PPC64_GOT16_DS: | |
8586 | case R_PPC64_GOT16_LO_DS: | |
8587 | case R_PPC64_PLT16_LO_DS: | |
8588 | case R_PPC64_SECTOFF_DS: | |
8589 | case R_PPC64_SECTOFF_LO_DS: | |
8590 | case R_PPC64_TOC16_DS: | |
8591 | case R_PPC64_TOC16_LO_DS: | |
8592 | case R_PPC64_PLTGOT16_DS: | |
8593 | case R_PPC64_PLTGOT16_LO_DS: | |
411e1bfb AM |
8594 | case R_PPC64_GOT_TPREL16_DS: |
8595 | case R_PPC64_GOT_TPREL16_LO_DS: | |
8596 | case R_PPC64_GOT_DTPREL16_DS: | |
8597 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
8598 | case R_PPC64_TPREL16_DS: | |
8599 | case R_PPC64_TPREL16_LO_DS: | |
8600 | case R_PPC64_DTPREL16_DS: | |
8601 | case R_PPC64_DTPREL16_LO_DS: | |
adadcc0c AM |
8602 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
8603 | mask = 3; | |
8604 | /* If this reloc is against an lq insn, then the value must be | |
8605 | a multiple of 16. This is somewhat of a hack, but the | |
8606 | "correct" way to do this by defining _DQ forms of all the | |
8607 | _DS relocs bloats all reloc switches in this file. It | |
8608 | doesn't seem to make much sense to use any of these relocs | |
8609 | in data, so testing the insn should be safe. */ | |
494dac0c | 8610 | if ((insn & (0x3f << 26)) == (56u << 26)) |
adadcc0c AM |
8611 | mask = 15; |
8612 | if (((relocation + addend) & mask) != 0) | |
65f38f15 AM |
8613 | { |
8614 | (*_bfd_error_handler) | |
adadcc0c | 8615 | (_("%s: error: relocation %s not a multiple of %d"), |
65f38f15 | 8616 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8617 | ppc64_elf_howto_table[r_type]->name, |
adadcc0c | 8618 | mask + 1); |
65f38f15 | 8619 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 8620 | ret = FALSE; |
65f38f15 AM |
8621 | continue; |
8622 | } | |
8623 | break; | |
721956f4 AM |
8624 | |
8625 | case R_PPC64_REL14: | |
8626 | case R_PPC64_REL14_BRNTAKEN: | |
8627 | case R_PPC64_REL14_BRTAKEN: | |
8628 | max_br_offset = 1 << 15; | |
8629 | goto branch_check; | |
8630 | ||
8631 | case R_PPC64_REL24: | |
8632 | max_br_offset = 1 << 25; | |
8633 | ||
8634 | branch_check: | |
ad8e1ba5 AM |
8635 | /* If the branch is out of reach or the TOC register needs |
8636 | adjusting, then redirect the call to the local stub for | |
8637 | this function. */ | |
411e1bfb | 8638 | from = (rel->r_offset |
721956f4 AM |
8639 | + input_section->output_offset |
8640 | + input_section->output_section->vma); | |
ad8e1ba5 AM |
8641 | if ((relocation + addend - from + max_br_offset >= 2 * max_br_offset |
8642 | || (sec != NULL | |
8643 | && sec->output_section != NULL | |
8f3bab57 | 8644 | && sec->id <= htab->top_id |
ad8e1ba5 AM |
8645 | && (htab->stub_group[sec->id].toc_off |
8646 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 AM |
8647 | && (stub_entry = ppc_get_stub_entry (input_section, sec, h, |
8648 | rel, htab)) != NULL) | |
8649 | { | |
8650 | /* Munge up the value and addend so that we call the stub | |
8651 | rather than the procedure directly. */ | |
8652 | relocation = (stub_entry->stub_offset | |
8653 | + stub_entry->stub_sec->output_offset | |
8654 | + stub_entry->stub_sec->output_section->vma); | |
8655 | addend = 0; | |
8656 | } | |
8657 | break; | |
5bd4f169 AM |
8658 | } |
8659 | ||
239e1f3a AM |
8660 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
8661 | because such sections are not SEC_ALLOC and thus ld.so will | |
8662 | not process them. */ | |
65f38f15 | 8663 | if (unresolved_reloc |
239e1f3a | 8664 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
65f38f15 | 8665 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
9c07fe7c AM |
8666 | { |
8667 | (*_bfd_error_handler) | |
7b609f53 | 8668 | (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), |
9c07fe7c AM |
8669 | bfd_archive_filename (input_bfd), |
8670 | bfd_get_section_name (input_bfd, input_section), | |
8671 | (long) rel->r_offset, | |
7b609f53 | 8672 | ppc64_elf_howto_table[(int) r_type]->name, |
9c07fe7c | 8673 | h->root.root.string); |
b34976b6 | 8674 | ret = FALSE; |
9c07fe7c | 8675 | } |
5bd4f169 | 8676 | |
65f38f15 | 8677 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
8678 | input_bfd, |
8679 | input_section, | |
8680 | contents, | |
411e1bfb | 8681 | rel->r_offset, |
5bd4f169 AM |
8682 | relocation, |
8683 | addend); | |
8684 | ||
ef60b7ff | 8685 | if (r != bfd_reloc_ok) |
5bd4f169 | 8686 | { |
cd27b276 AM |
8687 | if (sym_name == NULL) |
8688 | sym_name = "(null)"; | |
8689 | if (r == bfd_reloc_overflow) | |
5bd4f169 | 8690 | { |
cd27b276 AM |
8691 | if (warned) |
8692 | continue; | |
8693 | if (h != NULL | |
8694 | && h->root.type == bfd_link_hash_undefweak | |
4ce794b7 | 8695 | && ppc64_elf_howto_table[r_type]->pc_relative) |
5bd4f169 AM |
8696 | { |
8697 | /* Assume this is a call protected by other code that | |
8698 | detects the symbol is undefined. If this is the case, | |
8699 | we can safely ignore the overflow. If not, the | |
8700 | program is hosed anyway, and a little warning isn't | |
8701 | going to help. */ | |
8702 | ||
8703 | continue; | |
8704 | } | |
8705 | ||
ef60b7ff | 8706 | if (!((*info->callbacks->reloc_overflow) |
4ce794b7 | 8707 | (info, sym_name, ppc64_elf_howto_table[r_type]->name, |
411e1bfb | 8708 | rel->r_addend, input_bfd, input_section, rel->r_offset))) |
b34976b6 | 8709 | return FALSE; |
ef60b7ff AM |
8710 | } |
8711 | else | |
8712 | { | |
8713 | (*_bfd_error_handler) | |
7b609f53 | 8714 | (_("%s(%s+0x%lx): %s reloc against `%s': error %d"), |
ef60b7ff AM |
8715 | bfd_archive_filename (input_bfd), |
8716 | bfd_get_section_name (input_bfd, input_section), | |
7b609f53 | 8717 | (long) rel->r_offset, |
4ce794b7 | 8718 | ppc64_elf_howto_table[r_type]->name, |
7b609f53 AM |
8719 | sym_name, |
8720 | (int) r); | |
b34976b6 | 8721 | ret = FALSE; |
ef60b7ff | 8722 | } |
5bd4f169 | 8723 | } |
5bd4f169 AM |
8724 | } |
8725 | ||
5bd4f169 AM |
8726 | return ret; |
8727 | } | |
8728 | ||
754021d0 AM |
8729 | /* Adjust the value of any local symbols in opd sections. */ |
8730 | ||
8731 | static bfd_boolean | |
8732 | ppc64_elf_output_symbol_hook (struct bfd_link_info *info, | |
8733 | const char *name ATTRIBUTE_UNUSED, | |
8734 | Elf_Internal_Sym *elfsym, | |
8735 | asection *input_sec, | |
8736 | struct elf_link_hash_entry *h) | |
8737 | { | |
4025353c | 8738 | long *opd_adjust, adjust; |
754021d0 AM |
8739 | bfd_vma value; |
8740 | ||
4025353c AM |
8741 | if (h != NULL) |
8742 | return TRUE; | |
8743 | ||
8744 | opd_adjust = get_opd_info (input_sec); | |
8745 | if (opd_adjust == NULL) | |
754021d0 AM |
8746 | return TRUE; |
8747 | ||
8748 | value = elfsym->st_value - input_sec->output_offset; | |
8749 | if (!info->relocatable) | |
8750 | value -= input_sec->output_section->vma; | |
8751 | ||
4025353c AM |
8752 | adjust = opd_adjust[value / 24]; |
8753 | if (adjust == -1) | |
8754 | elfsym->st_value = 0; | |
8755 | else | |
8756 | elfsym->st_value += adjust; | |
754021d0 AM |
8757 | return TRUE; |
8758 | } | |
8759 | ||
5bd4f169 AM |
8760 | /* Finish up dynamic symbol handling. We set the contents of various |
8761 | dynamic sections here. */ | |
8762 | ||
b34976b6 | 8763 | static bfd_boolean |
4ce794b7 AM |
8764 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
8765 | struct bfd_link_info *info, | |
8766 | struct elf_link_hash_entry *h, | |
8767 | Elf_Internal_Sym *sym) | |
5bd4f169 | 8768 | { |
65f38f15 | 8769 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
8770 | bfd *dynobj; |
8771 | ||
65f38f15 AM |
8772 | htab = ppc_hash_table (info); |
8773 | dynobj = htab->elf.dynobj; | |
5bd4f169 | 8774 | |
411e1bfb | 8775 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
5bd4f169 | 8776 | { |
411e1bfb | 8777 | struct plt_entry *ent; |
65f38f15 | 8778 | Elf_Internal_Rela rela; |
947216bf | 8779 | bfd_byte *loc; |
5bd4f169 | 8780 | |
411e1bfb AM |
8781 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
8782 | if (ent->plt.offset != (bfd_vma) -1) | |
8783 | { | |
8784 | /* This symbol has an entry in the procedure linkage | |
8785 | table. Set it up. */ | |
5bd4f169 | 8786 | |
4ce794b7 AM |
8787 | if (htab->plt == NULL |
8788 | || htab->relplt == NULL | |
8789 | || htab->glink == NULL) | |
411e1bfb | 8790 | abort (); |
5bd4f169 | 8791 | |
411e1bfb AM |
8792 | /* Create a JMP_SLOT reloc to inform the dynamic linker to |
8793 | fill in the PLT entry. */ | |
4ce794b7 AM |
8794 | rela.r_offset = (htab->plt->output_section->vma |
8795 | + htab->plt->output_offset | |
411e1bfb AM |
8796 | + ent->plt.offset); |
8797 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); | |
8798 | rela.r_addend = ent->addend; | |
5bd4f169 | 8799 | |
4ce794b7 | 8800 | loc = htab->relplt->contents; |
411e1bfb AM |
8801 | loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE |
8802 | * sizeof (Elf64_External_Rela)); | |
8803 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
8804 | } | |
5bd4f169 AM |
8805 | } |
8806 | ||
8807 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
8808 | { | |
5bd4f169 | 8809 | Elf_Internal_Rela rela; |
947216bf | 8810 | bfd_byte *loc; |
5bd4f169 | 8811 | |
65f38f15 | 8812 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 8813 | |
65f38f15 AM |
8814 | if (h->dynindx == -1 |
8815 | || (h->root.type != bfd_link_hash_defined | |
8816 | && h->root.type != bfd_link_hash_defweak) | |
4ce794b7 | 8817 | || htab->relbss == NULL) |
65f38f15 | 8818 | abort (); |
5bd4f169 AM |
8819 | |
8820 | rela.r_offset = (h->root.u.def.value | |
8821 | + h->root.u.def.section->output_section->vma | |
8822 | + h->root.u.def.section->output_offset); | |
8823 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
8824 | rela.r_addend = 0; | |
4ce794b7 AM |
8825 | loc = htab->relbss->contents; |
8826 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 8827 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
8828 | } |
8829 | ||
5bd4f169 AM |
8830 | /* Mark some specially defined symbols as absolute. */ |
8831 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
8832 | sym->st_shndx = SHN_ABS; | |
8833 | ||
b34976b6 | 8834 | return TRUE; |
5bd4f169 AM |
8835 | } |
8836 | ||
65f38f15 AM |
8837 | /* Used to decide how to sort relocs in an optimal manner for the |
8838 | dynamic linker, before writing them out. */ | |
8839 | ||
8840 | static enum elf_reloc_type_class | |
4ce794b7 | 8841 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
65f38f15 | 8842 | { |
04c9666a | 8843 | enum elf_ppc64_reloc_type r_type; |
a33d1f77 | 8844 | |
4ce794b7 | 8845 | r_type = ELF64_R_TYPE (rela->r_info); |
a33d1f77 | 8846 | switch (r_type) |
65f38f15 AM |
8847 | { |
8848 | case R_PPC64_RELATIVE: | |
8849 | return reloc_class_relative; | |
8850 | case R_PPC64_JMP_SLOT: | |
8851 | return reloc_class_plt; | |
8852 | case R_PPC64_COPY: | |
8853 | return reloc_class_copy; | |
8854 | default: | |
8855 | return reloc_class_normal; | |
8856 | } | |
8857 | } | |
8858 | ||
5bd4f169 AM |
8859 | /* Finish up the dynamic sections. */ |
8860 | ||
b34976b6 | 8861 | static bfd_boolean |
4ce794b7 AM |
8862 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
8863 | struct bfd_link_info *info) | |
5bd4f169 | 8864 | { |
65f38f15 AM |
8865 | struct ppc_link_hash_table *htab; |
8866 | bfd *dynobj; | |
5bd4f169 | 8867 | asection *sdyn; |
5bd4f169 | 8868 | |
65f38f15 AM |
8869 | htab = ppc_hash_table (info); |
8870 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
8871 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
8872 | ||
65f38f15 | 8873 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 8874 | { |
5bd4f169 AM |
8875 | Elf64_External_Dyn *dyncon, *dynconend; |
8876 | ||
4ce794b7 | 8877 | if (sdyn == NULL || htab->got == NULL) |
65f38f15 | 8878 | abort (); |
5bd4f169 AM |
8879 | |
8880 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
eea6121a | 8881 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
5bd4f169 AM |
8882 | for (; dyncon < dynconend; dyncon++) |
8883 | { | |
8884 | Elf_Internal_Dyn dyn; | |
19397422 | 8885 | asection *s; |
5bd4f169 AM |
8886 | |
8887 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
8888 | ||
8889 | switch (dyn.d_tag) | |
8890 | { | |
65f38f15 AM |
8891 | default: |
8892 | continue; | |
5bd4f169 | 8893 | |
5d1634d7 | 8894 | case DT_PPC64_GLINK: |
4ce794b7 | 8895 | s = htab->glink; |
6348e046 | 8896 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
ad8e1ba5 AM |
8897 | /* We stupidly defined DT_PPC64_GLINK to be the start |
8898 | of glink rather than the first entry point, which is | |
8899 | what ld.so needs, and now have a bigger stub to | |
8900 | support automatic multiple TOCs. */ | |
8901 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; | |
5d1634d7 AM |
8902 | break; |
8903 | ||
19397422 AM |
8904 | case DT_PPC64_OPD: |
8905 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8906 | if (s == NULL) |
8907 | continue; | |
8908 | dyn.d_un.d_ptr = s->vma; | |
19397422 AM |
8909 | break; |
8910 | ||
8911 | case DT_PPC64_OPDSZ: | |
8912 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8913 | if (s == NULL) |
8914 | continue; | |
eea6121a | 8915 | dyn.d_un.d_val = s->size; |
19397422 AM |
8916 | break; |
8917 | ||
65f38f15 | 8918 | case DT_PLTGOT: |
4ce794b7 | 8919 | s = htab->plt; |
6348e046 | 8920 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 AM |
8921 | break; |
8922 | ||
8923 | case DT_JMPREL: | |
4ce794b7 | 8924 | s = htab->relplt; |
6348e046 | 8925 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 | 8926 | break; |
5bd4f169 | 8927 | |
65f38f15 | 8928 | case DT_PLTRELSZ: |
eea6121a | 8929 | dyn.d_un.d_val = htab->relplt->size; |
5d1634d7 AM |
8930 | break; |
8931 | ||
8932 | case DT_RELASZ: | |
8933 | /* Don't count procedure linkage table relocs in the | |
8934 | overall reloc count. */ | |
4ce794b7 | 8935 | s = htab->relplt; |
6348e046 AM |
8936 | if (s == NULL) |
8937 | continue; | |
eea6121a | 8938 | dyn.d_un.d_val -= s->size; |
6348e046 AM |
8939 | break; |
8940 | ||
8941 | case DT_RELA: | |
8942 | /* We may not be using the standard ELF linker script. | |
8943 | If .rela.plt is the first .rela section, we adjust | |
8944 | DT_RELA to not include it. */ | |
4ce794b7 | 8945 | s = htab->relplt; |
6348e046 AM |
8946 | if (s == NULL) |
8947 | continue; | |
8948 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
8949 | continue; | |
eea6121a | 8950 | dyn.d_un.d_ptr += s->size; |
65f38f15 | 8951 | break; |
5bd4f169 | 8952 | } |
5bd4f169 | 8953 | |
65f38f15 | 8954 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 8955 | } |
5bd4f169 AM |
8956 | } |
8957 | ||
eea6121a | 8958 | if (htab->got != NULL && htab->got->size != 0) |
5d1634d7 AM |
8959 | { |
8960 | /* Fill in the first entry in the global offset table. | |
8961 | We use it to hold the link-time TOCbase. */ | |
8962 | bfd_put_64 (output_bfd, | |
60ee0d4a | 8963 | elf_gp (output_bfd) + TOC_BASE_OFF, |
4ce794b7 | 8964 | htab->got->contents); |
5d1634d7 AM |
8965 | |
8966 | /* Set .got entry size. */ | |
4ce794b7 | 8967 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
5d1634d7 AM |
8968 | } |
8969 | ||
eea6121a | 8970 | if (htab->plt != NULL && htab->plt->size != 0) |
5d1634d7 AM |
8971 | { |
8972 | /* Set .plt entry size. */ | |
4ce794b7 | 8973 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
5d1634d7 AM |
8974 | = PLT_ENTRY_SIZE; |
8975 | } | |
8976 | ||
e717da7e AM |
8977 | /* We need to handle writing out multiple GOT sections ourselves, |
8978 | since we didn't add them to DYNOBJ. */ | |
8979 | while ((dynobj = dynobj->link_next) != NULL) | |
8980 | { | |
8981 | asection *s; | |
8982 | s = ppc64_elf_tdata (dynobj)->got; | |
8983 | if (s != NULL | |
eea6121a | 8984 | && s->size != 0 |
e717da7e AM |
8985 | && s->output_section != bfd_abs_section_ptr |
8986 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8987 | s->contents, s->output_offset, | |
eea6121a | 8988 | s->size)) |
e717da7e AM |
8989 | return FALSE; |
8990 | s = ppc64_elf_tdata (dynobj)->relgot; | |
8991 | if (s != NULL | |
eea6121a | 8992 | && s->size != 0 |
e717da7e AM |
8993 | && s->output_section != bfd_abs_section_ptr |
8994 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8995 | s->contents, s->output_offset, | |
eea6121a | 8996 | s->size)) |
e717da7e AM |
8997 | return FALSE; |
8998 | } | |
f6c52c13 | 8999 | |
b34976b6 | 9000 | return TRUE; |
5bd4f169 AM |
9001 | } |
9002 | ||
5bd4f169 | 9003 | #include "elf64-target.h" |