Commit | Line | Data |
---|---|---|
5bd4f169 | 1 | /* PowerPC64-specific support for 64-bit ELF. |
86bbe32f | 2 | Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
5bd4f169 AM |
3 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
4 | based on elf32-ppc.c by Ian Lance Taylor. | |
5 | ||
ae9a127f | 6 | This file is part of BFD, the Binary File Descriptor library. |
5bd4f169 | 7 | |
ae9a127f NC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
5bd4f169 | 12 | |
ae9a127f NC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
5bd4f169 | 17 | |
4ce794b7 AM |
18 | You should have received a copy of the GNU General Public License along |
19 | with this program; if not, write to the Free Software Foundation, Inc., | |
20 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
5bd4f169 | 21 | |
4ce794b7 AM |
22 | /* The 64-bit PowerPC ELF ABI may be found at |
23 | http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and | |
24 | http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */ | |
5bd4f169 AM |
25 | |
26 | #include "bfd.h" | |
27 | #include "sysdep.h" | |
28 | #include "bfdlink.h" | |
29 | #include "libbfd.h" | |
30 | #include "elf-bfd.h" | |
2f89ff8d | 31 | #include "elf/ppc.h" |
04c9666a | 32 | #include "elf/ppc64.h" |
5d1634d7 | 33 | #include "elf64-ppc.h" |
5bd4f169 | 34 | |
805fc799 | 35 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
4ce794b7 | 36 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 37 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
4ce794b7 | 38 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 39 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
4ce794b7 | 40 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 41 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
4ce794b7 | 42 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 43 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
4ce794b7 | 44 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 45 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
4ce794b7 | 46 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 47 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
4ce794b7 | 48 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
805fc799 | 49 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
4ce794b7 | 50 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5bd4f169 AM |
51 | |
52 | ||
ad8e1ba5 AM |
53 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
54 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
55 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
56 | #define TARGET_BIG_NAME "elf64-powerpc" | |
57 | #define ELF_ARCH bfd_arch_powerpc | |
58 | #define ELF_MACHINE_CODE EM_PPC64 | |
59 | #define ELF_MAXPAGESIZE 0x10000 | |
60 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
61 | ||
62 | #define elf_backend_want_got_sym 0 | |
63 | #define elf_backend_want_plt_sym 0 | |
64 | #define elf_backend_plt_alignment 3 | |
65 | #define elf_backend_plt_not_loaded 1 | |
66 | #define elf_backend_got_symbol_offset 0 | |
67 | #define elf_backend_got_header_size 8 | |
68 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE | |
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 | |
81 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections | |
82 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
83 | #define elf_backend_check_relocs ppc64_elf_check_relocs | |
84 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
85 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
86 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
87 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol | |
88 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust | |
89 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
90 | #define elf_backend_relocate_section ppc64_elf_relocate_section | |
91 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
92 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
93 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
2f89ff8d | 94 | #define elf_backend_special_sections ppc64_elf_special_sections |
ad8e1ba5 | 95 | |
5bd4f169 AM |
96 | /* The name of the dynamic interpreter. This is put in the .interp |
97 | section. */ | |
98 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
99 | ||
100 | /* The size in bytes of an entry in the procedure linkage table. */ | |
101 | #define PLT_ENTRY_SIZE 24 | |
102 | ||
103 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 104 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
105 | |
106 | /* TOC base pointers offset from start of TOC. */ | |
411e1bfb AM |
107 | #define TOC_BASE_OFF 0x8000 |
108 | ||
109 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
110 | #define TP_OFFSET 0x7000 | |
111 | #define DTP_OFFSET 0x8000 | |
5bd4f169 | 112 | |
ad8e1ba5 AM |
113 | /* .plt call stub instructions. The normal stub is like this, but |
114 | sometimes the .plt entry crosses a 64k boundary and we need to | |
115 | insert an addis to adjust r12. */ | |
116 | #define PLT_CALL_STUB_SIZE (7*4) | |
5d1634d7 AM |
117 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
118 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
119 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
120 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
121 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
122 | /* ld %r11,xxx+16@l(%r12) */ | |
123 | #define BCTR 0x4e800420 /* bctr */ | |
124 | ||
5d1634d7 | 125 | |
ad8e1ba5 AM |
126 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
127 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ | |
128 | ||
129 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
130 | ||
131 | /* glink call stub instructions. We enter with the index in R0, and the | |
132 | address of glink entry in CTR. From that, we can calculate PLT0. */ | |
133 | #define GLINK_CALL_STUB_SIZE (16*4) | |
134 | #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */ | |
135 | #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */ | |
136 | #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */ | |
137 | #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */ | |
138 | #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */ | |
139 | #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */ | |
140 | #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */ | |
141 | /* sub %r12,%r12,%r11 */ | |
142 | #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */ | |
143 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */ | |
144 | /* ld %r11,xxx@l(%r12) */ | |
145 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */ | |
146 | /* ld %r2,8(%r12) */ | |
147 | /* mtctr %r11 */ | |
148 | /* ld %r11,16(%r12) */ | |
149 | /* bctr */ | |
5d1634d7 AM |
150 | |
151 | /* Pad with this. */ | |
152 | #define NOP 0x60000000 | |
153 | ||
721956f4 AM |
154 | /* Some other nops. */ |
155 | #define CROR_151515 0x4def7b82 | |
156 | #define CROR_313131 0x4ffffb82 | |
157 | ||
cedb70c5 | 158 | /* .glink entries for the first 32k functions are two instructions. */ |
5d1634d7 AM |
159 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
160 | #define B_DOT 0x48000000 /* b . */ | |
161 | ||
162 | /* After that, we need two instructions to load the index, followed by | |
163 | a branch. */ | |
164 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 165 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
41bd81ab | 166 | |
82bd7b59 AM |
167 | /* Instructions to save and restore floating point regs. */ |
168 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ | |
169 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ | |
170 | #define BLR 0x4e800020 /* blr */ | |
171 | ||
41bd81ab AM |
172 | /* Since .opd is an array of descriptors and each entry will end up |
173 | with identical R_PPC64_RELATIVE relocs, there is really no need to | |
174 | propagate .opd relocs; The dynamic linker should be taught to | |
1e2f5b6e | 175 | relocate .opd without reloc entries. */ |
41bd81ab AM |
176 | #ifndef NO_OPD_RELOCS |
177 | #define NO_OPD_RELOCS 0 | |
178 | #endif | |
5bd4f169 | 179 | \f |
f5e87a1d | 180 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
b34976b6 | 181 | |
5bd4f169 | 182 | /* Relocation HOWTO's. */ |
04c9666a | 183 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
5bd4f169 AM |
184 | |
185 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
186 | /* This reloc does nothing. */ | |
187 | HOWTO (R_PPC64_NONE, /* type */ | |
188 | 0, /* rightshift */ | |
411e1bfb AM |
189 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
190 | 32, /* bitsize */ | |
b34976b6 | 191 | FALSE, /* pc_relative */ |
5bd4f169 | 192 | 0, /* bitpos */ |
f5e87a1d | 193 | complain_overflow_dont, /* complain_on_overflow */ |
5bd4f169 AM |
194 | bfd_elf_generic_reloc, /* special_function */ |
195 | "R_PPC64_NONE", /* name */ | |
b34976b6 | 196 | FALSE, /* partial_inplace */ |
d006db6c | 197 | 0, /* src_mask */ |
5bd4f169 | 198 | 0, /* dst_mask */ |
b34976b6 | 199 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
200 | |
201 | /* A standard 32 bit relocation. */ | |
202 | HOWTO (R_PPC64_ADDR32, /* type */ | |
203 | 0, /* rightshift */ | |
204 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
205 | 32, /* bitsize */ | |
b34976b6 | 206 | FALSE, /* pc_relative */ |
5bd4f169 AM |
207 | 0, /* bitpos */ |
208 | complain_overflow_bitfield, /* complain_on_overflow */ | |
209 | bfd_elf_generic_reloc, /* special_function */ | |
210 | "R_PPC64_ADDR32", /* name */ | |
b34976b6 | 211 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
212 | 0, /* src_mask */ |
213 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 214 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
215 | |
216 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
217 | FIXME: we don't check that, we just clear them. */ | |
218 | HOWTO (R_PPC64_ADDR24, /* type */ | |
219 | 0, /* rightshift */ | |
220 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
221 | 26, /* bitsize */ | |
b34976b6 | 222 | FALSE, /* pc_relative */ |
5bd4f169 AM |
223 | 0, /* bitpos */ |
224 | complain_overflow_bitfield, /* complain_on_overflow */ | |
225 | bfd_elf_generic_reloc, /* special_function */ | |
226 | "R_PPC64_ADDR24", /* name */ | |
b34976b6 | 227 | FALSE, /* partial_inplace */ |
d006db6c | 228 | 0, /* src_mask */ |
f5e87a1d | 229 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 230 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
231 | |
232 | /* A standard 16 bit relocation. */ | |
233 | HOWTO (R_PPC64_ADDR16, /* type */ | |
234 | 0, /* rightshift */ | |
235 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
236 | 16, /* bitsize */ | |
b34976b6 | 237 | FALSE, /* pc_relative */ |
5bd4f169 AM |
238 | 0, /* bitpos */ |
239 | complain_overflow_bitfield, /* complain_on_overflow */ | |
240 | bfd_elf_generic_reloc, /* special_function */ | |
241 | "R_PPC64_ADDR16", /* name */ | |
b34976b6 | 242 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
243 | 0, /* src_mask */ |
244 | 0xffff, /* dst_mask */ | |
b34976b6 | 245 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
246 | |
247 | /* A 16 bit relocation without overflow. */ | |
248 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
249 | 0, /* rightshift */ | |
250 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
251 | 16, /* bitsize */ | |
b34976b6 | 252 | FALSE, /* pc_relative */ |
5bd4f169 AM |
253 | 0, /* bitpos */ |
254 | complain_overflow_dont,/* complain_on_overflow */ | |
255 | bfd_elf_generic_reloc, /* special_function */ | |
256 | "R_PPC64_ADDR16_LO", /* name */ | |
b34976b6 | 257 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
258 | 0, /* src_mask */ |
259 | 0xffff, /* dst_mask */ | |
b34976b6 | 260 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
261 | |
262 | /* Bits 16-31 of an address. */ | |
263 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
264 | 16, /* rightshift */ | |
265 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
266 | 16, /* bitsize */ | |
b34976b6 | 267 | FALSE, /* pc_relative */ |
5bd4f169 AM |
268 | 0, /* bitpos */ |
269 | complain_overflow_dont, /* complain_on_overflow */ | |
270 | bfd_elf_generic_reloc, /* special_function */ | |
271 | "R_PPC64_ADDR16_HI", /* name */ | |
b34976b6 | 272 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
273 | 0, /* src_mask */ |
274 | 0xffff, /* dst_mask */ | |
b34976b6 | 275 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
276 | |
277 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
278 | bits, treated as a signed number, is negative. */ | |
279 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
280 | 16, /* rightshift */ | |
281 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
282 | 16, /* bitsize */ | |
b34976b6 | 283 | FALSE, /* pc_relative */ |
5bd4f169 AM |
284 | 0, /* bitpos */ |
285 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 286 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 287 | "R_PPC64_ADDR16_HA", /* name */ |
b34976b6 | 288 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
289 | 0, /* src_mask */ |
290 | 0xffff, /* dst_mask */ | |
b34976b6 | 291 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
292 | |
293 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
294 | FIXME: we don't check that, we just clear them. */ | |
295 | HOWTO (R_PPC64_ADDR14, /* type */ | |
296 | 0, /* rightshift */ | |
297 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
298 | 16, /* bitsize */ | |
b34976b6 | 299 | FALSE, /* pc_relative */ |
5bd4f169 AM |
300 | 0, /* bitpos */ |
301 | complain_overflow_bitfield, /* complain_on_overflow */ | |
302 | bfd_elf_generic_reloc, /* special_function */ | |
303 | "R_PPC64_ADDR14", /* name */ | |
b34976b6 | 304 | FALSE, /* partial_inplace */ |
d006db6c | 305 | 0, /* src_mask */ |
f5e87a1d | 306 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 307 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
308 | |
309 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
310 | indicate that the branch is expected to be taken. The lower two | |
311 | bits must be zero. */ | |
312 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
313 | 0, /* rightshift */ | |
314 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
315 | 16, /* bitsize */ | |
b34976b6 | 316 | FALSE, /* pc_relative */ |
5bd4f169 AM |
317 | 0, /* bitpos */ |
318 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 319 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 320 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
b34976b6 | 321 | FALSE, /* partial_inplace */ |
d006db6c | 322 | 0, /* src_mask */ |
f5e87a1d | 323 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 324 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
325 | |
326 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
327 | indicate that the branch is not expected to be taken. The lower | |
328 | two bits must be zero. */ | |
329 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
330 | 0, /* rightshift */ | |
331 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
332 | 16, /* bitsize */ | |
b34976b6 | 333 | FALSE, /* pc_relative */ |
5bd4f169 AM |
334 | 0, /* bitpos */ |
335 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 336 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 337 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
b34976b6 | 338 | FALSE, /* partial_inplace */ |
d006db6c | 339 | 0, /* src_mask */ |
f5e87a1d | 340 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 341 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
342 | |
343 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
344 | HOWTO (R_PPC64_REL24, /* type */ | |
345 | 0, /* rightshift */ | |
346 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
347 | 26, /* bitsize */ | |
b34976b6 | 348 | TRUE, /* pc_relative */ |
5bd4f169 AM |
349 | 0, /* bitpos */ |
350 | complain_overflow_signed, /* complain_on_overflow */ | |
351 | bfd_elf_generic_reloc, /* special_function */ | |
352 | "R_PPC64_REL24", /* name */ | |
b34976b6 | 353 | FALSE, /* partial_inplace */ |
d006db6c | 354 | 0, /* src_mask */ |
f5e87a1d | 355 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 356 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
357 | |
358 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
359 | HOWTO (R_PPC64_REL14, /* type */ | |
360 | 0, /* rightshift */ | |
361 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
362 | 16, /* bitsize */ | |
b34976b6 | 363 | TRUE, /* pc_relative */ |
5bd4f169 AM |
364 | 0, /* bitpos */ |
365 | complain_overflow_signed, /* complain_on_overflow */ | |
366 | bfd_elf_generic_reloc, /* special_function */ | |
367 | "R_PPC64_REL14", /* name */ | |
b34976b6 | 368 | FALSE, /* partial_inplace */ |
d006db6c | 369 | 0, /* src_mask */ |
f5e87a1d | 370 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 371 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
372 | |
373 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
374 | the branch is expected to be taken. The lower two bits must be | |
375 | zero. */ | |
376 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
377 | 0, /* rightshift */ | |
378 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
379 | 16, /* bitsize */ | |
b34976b6 | 380 | TRUE, /* pc_relative */ |
5bd4f169 AM |
381 | 0, /* bitpos */ |
382 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 383 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 384 | "R_PPC64_REL14_BRTAKEN", /* name */ |
b34976b6 | 385 | FALSE, /* partial_inplace */ |
d006db6c | 386 | 0, /* src_mask */ |
f5e87a1d | 387 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 388 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
389 | |
390 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
391 | the branch is not expected to be taken. The lower two bits must | |
392 | be zero. */ | |
393 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
394 | 0, /* rightshift */ | |
395 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
396 | 16, /* bitsize */ | |
b34976b6 | 397 | TRUE, /* pc_relative */ |
5bd4f169 AM |
398 | 0, /* bitpos */ |
399 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 400 | ppc64_elf_brtaken_reloc, /* special_function */ |
5bd4f169 | 401 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
b34976b6 | 402 | FALSE, /* partial_inplace */ |
d006db6c | 403 | 0, /* src_mask */ |
f5e87a1d | 404 | 0x0000fffc, /* dst_mask */ |
b34976b6 | 405 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
406 | |
407 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
408 | symbol. */ | |
409 | HOWTO (R_PPC64_GOT16, /* type */ | |
410 | 0, /* rightshift */ | |
411 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
412 | 16, /* bitsize */ | |
b34976b6 | 413 | FALSE, /* pc_relative */ |
5bd4f169 AM |
414 | 0, /* bitpos */ |
415 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 416 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 417 | "R_PPC64_GOT16", /* name */ |
b34976b6 | 418 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
419 | 0, /* src_mask */ |
420 | 0xffff, /* dst_mask */ | |
b34976b6 | 421 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
422 | |
423 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
424 | the symbol. */ | |
425 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
426 | 0, /* rightshift */ | |
427 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
428 | 16, /* bitsize */ | |
b34976b6 | 429 | FALSE, /* pc_relative */ |
5bd4f169 AM |
430 | 0, /* bitpos */ |
431 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 432 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 433 | "R_PPC64_GOT16_LO", /* name */ |
b34976b6 | 434 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
435 | 0, /* src_mask */ |
436 | 0xffff, /* dst_mask */ | |
b34976b6 | 437 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
438 | |
439 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
440 | the symbol. */ | |
441 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
442 | 16, /* rightshift */ | |
443 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
444 | 16, /* bitsize */ | |
b34976b6 | 445 | FALSE, /* pc_relative */ |
5bd4f169 AM |
446 | 0, /* bitpos */ |
447 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 448 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 449 | "R_PPC64_GOT16_HI", /* name */ |
b34976b6 | 450 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
451 | 0, /* src_mask */ |
452 | 0xffff, /* dst_mask */ | |
b34976b6 | 453 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
454 | |
455 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
456 | the symbol. */ | |
457 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
458 | 16, /* rightshift */ | |
459 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
460 | 16, /* bitsize */ | |
b34976b6 | 461 | FALSE, /* pc_relative */ |
5bd4f169 AM |
462 | 0, /* bitpos */ |
463 | complain_overflow_dont,/* complain_on_overflow */ | |
805fc799 | 464 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 465 | "R_PPC64_GOT16_HA", /* name */ |
b34976b6 | 466 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
467 | 0, /* src_mask */ |
468 | 0xffff, /* dst_mask */ | |
b34976b6 | 469 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
470 | |
471 | /* This is used only by the dynamic linker. The symbol should exist | |
472 | both in the object being run and in some shared library. The | |
473 | dynamic linker copies the data addressed by the symbol from the | |
474 | shared library into the object, because the object being | |
475 | run has to have the data at some particular address. */ | |
476 | HOWTO (R_PPC64_COPY, /* type */ | |
477 | 0, /* rightshift */ | |
f5e87a1d AM |
478 | 0, /* this one is variable size */ |
479 | 0, /* bitsize */ | |
b34976b6 | 480 | FALSE, /* pc_relative */ |
5bd4f169 | 481 | 0, /* bitpos */ |
f5e87a1d AM |
482 | complain_overflow_dont, /* complain_on_overflow */ |
483 | ppc64_elf_unhandled_reloc, /* special_function */ | |
5bd4f169 | 484 | "R_PPC64_COPY", /* name */ |
b34976b6 | 485 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
486 | 0, /* src_mask */ |
487 | 0, /* dst_mask */ | |
b34976b6 | 488 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
489 | |
490 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
491 | entries. */ | |
492 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
493 | 0, /* rightshift */ | |
494 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
495 | 64, /* bitsize */ | |
b34976b6 | 496 | FALSE, /* pc_relative */ |
5bd4f169 AM |
497 | 0, /* bitpos */ |
498 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 499 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 500 | "R_PPC64_GLOB_DAT", /* name */ |
b34976b6 | 501 | FALSE, /* partial_inplace */ |
5bd4f169 | 502 | 0, /* src_mask */ |
f5e87a1d | 503 | ONES (64), /* dst_mask */ |
b34976b6 | 504 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
505 | |
506 | /* Created by the link editor. Marks a procedure linkage table | |
507 | entry for a symbol. */ | |
508 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
509 | 0, /* rightshift */ | |
510 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
511 | 0, /* bitsize */ | |
b34976b6 | 512 | FALSE, /* pc_relative */ |
5bd4f169 AM |
513 | 0, /* bitpos */ |
514 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 515 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 516 | "R_PPC64_JMP_SLOT", /* name */ |
b34976b6 | 517 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
518 | 0, /* src_mask */ |
519 | 0, /* dst_mask */ | |
b34976b6 | 520 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
521 | |
522 | /* Used only by the dynamic linker. When the object is run, this | |
523 | doubleword64 is set to the load address of the object, plus the | |
524 | addend. */ | |
525 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
526 | 0, /* rightshift */ | |
527 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
528 | 64, /* bitsize */ | |
b34976b6 | 529 | FALSE, /* pc_relative */ |
5bd4f169 AM |
530 | 0, /* bitpos */ |
531 | complain_overflow_dont, /* complain_on_overflow */ | |
532 | bfd_elf_generic_reloc, /* special_function */ | |
533 | "R_PPC64_RELATIVE", /* name */ | |
b34976b6 | 534 | FALSE, /* partial_inplace */ |
5bd4f169 | 535 | 0, /* src_mask */ |
f5e87a1d | 536 | ONES (64), /* dst_mask */ |
b34976b6 | 537 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
538 | |
539 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
540 | HOWTO (R_PPC64_UADDR32, /* type */ | |
541 | 0, /* rightshift */ | |
542 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
543 | 32, /* bitsize */ | |
b34976b6 | 544 | FALSE, /* pc_relative */ |
5bd4f169 AM |
545 | 0, /* bitpos */ |
546 | complain_overflow_bitfield, /* complain_on_overflow */ | |
547 | bfd_elf_generic_reloc, /* special_function */ | |
548 | "R_PPC64_UADDR32", /* name */ | |
b34976b6 | 549 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
550 | 0, /* src_mask */ |
551 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 552 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
553 | |
554 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
555 | HOWTO (R_PPC64_UADDR16, /* type */ | |
556 | 0, /* rightshift */ | |
557 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
558 | 16, /* bitsize */ | |
b34976b6 | 559 | FALSE, /* pc_relative */ |
5bd4f169 AM |
560 | 0, /* bitpos */ |
561 | complain_overflow_bitfield, /* complain_on_overflow */ | |
562 | bfd_elf_generic_reloc, /* special_function */ | |
563 | "R_PPC64_UADDR16", /* name */ | |
b34976b6 | 564 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
565 | 0, /* src_mask */ |
566 | 0xffff, /* dst_mask */ | |
b34976b6 | 567 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
568 | |
569 | /* 32-bit PC relative. */ | |
570 | HOWTO (R_PPC64_REL32, /* type */ | |
571 | 0, /* rightshift */ | |
572 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
573 | 32, /* bitsize */ | |
b34976b6 | 574 | TRUE, /* pc_relative */ |
5bd4f169 | 575 | 0, /* bitpos */ |
cedb70c5 | 576 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
5bd4f169 AM |
577 | complain_overflow_signed, /* complain_on_overflow */ |
578 | bfd_elf_generic_reloc, /* special_function */ | |
579 | "R_PPC64_REL32", /* name */ | |
b34976b6 | 580 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
581 | 0, /* src_mask */ |
582 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 583 | TRUE), /* pcrel_offset */ |
5bd4f169 | 584 | |
10ed1bba | 585 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
586 | HOWTO (R_PPC64_PLT32, /* type */ |
587 | 0, /* rightshift */ | |
588 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
589 | 32, /* bitsize */ | |
b34976b6 | 590 | FALSE, /* pc_relative */ |
5bd4f169 AM |
591 | 0, /* bitpos */ |
592 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 593 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 594 | "R_PPC64_PLT32", /* name */ |
b34976b6 | 595 | FALSE, /* partial_inplace */ |
5bd4f169 | 596 | 0, /* src_mask */ |
f5e87a1d | 597 | 0xffffffff, /* dst_mask */ |
b34976b6 | 598 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
599 | |
600 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
601 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
602 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
603 | 0, /* rightshift */ | |
604 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
605 | 32, /* bitsize */ | |
b34976b6 | 606 | TRUE, /* pc_relative */ |
5bd4f169 AM |
607 | 0, /* bitpos */ |
608 | complain_overflow_signed, /* complain_on_overflow */ | |
609 | bfd_elf_generic_reloc, /* special_function */ | |
610 | "R_PPC64_PLTREL32", /* name */ | |
b34976b6 | 611 | FALSE, /* partial_inplace */ |
5bd4f169 | 612 | 0, /* src_mask */ |
f5e87a1d | 613 | 0xffffffff, /* dst_mask */ |
b34976b6 | 614 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
615 | |
616 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
617 | the symbol. */ | |
618 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
619 | 0, /* rightshift */ | |
620 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
621 | 16, /* bitsize */ | |
b34976b6 | 622 | FALSE, /* pc_relative */ |
5bd4f169 AM |
623 | 0, /* bitpos */ |
624 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 625 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 626 | "R_PPC64_PLT16_LO", /* name */ |
b34976b6 | 627 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
628 | 0, /* src_mask */ |
629 | 0xffff, /* dst_mask */ | |
b34976b6 | 630 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
631 | |
632 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
633 | the symbol. */ | |
634 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
635 | 16, /* rightshift */ | |
636 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
637 | 16, /* bitsize */ | |
b34976b6 | 638 | FALSE, /* pc_relative */ |
5bd4f169 AM |
639 | 0, /* bitpos */ |
640 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 641 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 642 | "R_PPC64_PLT16_HI", /* name */ |
b34976b6 | 643 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
644 | 0, /* src_mask */ |
645 | 0xffff, /* dst_mask */ | |
b34976b6 | 646 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
647 | |
648 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
649 | the symbol. */ | |
650 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
651 | 16, /* rightshift */ | |
652 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
653 | 16, /* bitsize */ | |
b34976b6 | 654 | FALSE, /* pc_relative */ |
5bd4f169 AM |
655 | 0, /* bitpos */ |
656 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 657 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 658 | "R_PPC64_PLT16_HA", /* name */ |
b34976b6 | 659 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
660 | 0, /* src_mask */ |
661 | 0xffff, /* dst_mask */ | |
b34976b6 | 662 | FALSE), /* pcrel_offset */ |
5bd4f169 | 663 | |
c061c2d8 | 664 | /* 16-bit section relative relocation. */ |
5bd4f169 AM |
665 | HOWTO (R_PPC64_SECTOFF, /* type */ |
666 | 0, /* rightshift */ | |
c061c2d8 AM |
667 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
668 | 16, /* bitsize */ | |
b34976b6 | 669 | FALSE, /* pc_relative */ |
5bd4f169 AM |
670 | 0, /* bitpos */ |
671 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 672 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 673 | "R_PPC64_SECTOFF", /* name */ |
b34976b6 | 674 | FALSE, /* partial_inplace */ |
5bd4f169 | 675 | 0, /* src_mask */ |
c061c2d8 | 676 | 0xffff, /* dst_mask */ |
b34976b6 | 677 | FALSE), /* pcrel_offset */ |
5bd4f169 | 678 | |
c061c2d8 | 679 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
5bd4f169 AM |
680 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
681 | 0, /* rightshift */ | |
682 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
683 | 16, /* bitsize */ | |
b34976b6 | 684 | FALSE, /* pc_relative */ |
5bd4f169 AM |
685 | 0, /* bitpos */ |
686 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 687 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 688 | "R_PPC64_SECTOFF_LO", /* name */ |
b34976b6 | 689 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
690 | 0, /* src_mask */ |
691 | 0xffff, /* dst_mask */ | |
b34976b6 | 692 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
693 | |
694 | /* 16-bit upper half section relative relocation. */ | |
695 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
696 | 16, /* rightshift */ | |
697 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
698 | 16, /* bitsize */ | |
b34976b6 | 699 | FALSE, /* pc_relative */ |
5bd4f169 AM |
700 | 0, /* bitpos */ |
701 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 702 | ppc64_elf_sectoff_reloc, /* special_function */ |
5bd4f169 | 703 | "R_PPC64_SECTOFF_HI", /* name */ |
b34976b6 | 704 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
705 | 0, /* src_mask */ |
706 | 0xffff, /* dst_mask */ | |
b34976b6 | 707 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
708 | |
709 | /* 16-bit upper half adjusted section relative relocation. */ | |
710 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
711 | 16, /* rightshift */ | |
712 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
713 | 16, /* bitsize */ | |
b34976b6 | 714 | FALSE, /* pc_relative */ |
5bd4f169 AM |
715 | 0, /* bitpos */ |
716 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 717 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
5bd4f169 | 718 | "R_PPC64_SECTOFF_HA", /* name */ |
b34976b6 | 719 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
720 | 0, /* src_mask */ |
721 | 0xffff, /* dst_mask */ | |
b34976b6 | 722 | FALSE), /* pcrel_offset */ |
5bd4f169 | 723 | |
04c9666a AM |
724 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
725 | HOWTO (R_PPC64_REL30, /* type */ | |
5bd4f169 AM |
726 | 2, /* rightshift */ |
727 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
728 | 30, /* bitsize */ | |
b34976b6 | 729 | TRUE, /* pc_relative */ |
5bd4f169 AM |
730 | 0, /* bitpos */ |
731 | complain_overflow_dont, /* complain_on_overflow */ | |
732 | bfd_elf_generic_reloc, /* special_function */ | |
04c9666a | 733 | "R_PPC64_REL30", /* name */ |
b34976b6 | 734 | FALSE, /* partial_inplace */ |
d006db6c | 735 | 0, /* src_mask */ |
5bd4f169 | 736 | 0xfffffffc, /* dst_mask */ |
b34976b6 | 737 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
738 | |
739 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
740 | ||
741 | /* A standard 64-bit relocation. */ | |
742 | HOWTO (R_PPC64_ADDR64, /* type */ | |
743 | 0, /* rightshift */ | |
744 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
745 | 64, /* bitsize */ | |
b34976b6 | 746 | FALSE, /* pc_relative */ |
5bd4f169 AM |
747 | 0, /* bitpos */ |
748 | complain_overflow_dont, /* complain_on_overflow */ | |
749 | bfd_elf_generic_reloc, /* special_function */ | |
750 | "R_PPC64_ADDR64", /* name */ | |
b34976b6 | 751 | FALSE, /* partial_inplace */ |
5bd4f169 | 752 | 0, /* src_mask */ |
f5e87a1d | 753 | ONES (64), /* dst_mask */ |
b34976b6 | 754 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
755 | |
756 | /* The bits 32-47 of an address. */ | |
757 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
758 | 32, /* rightshift */ | |
759 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
760 | 16, /* bitsize */ | |
b34976b6 | 761 | FALSE, /* pc_relative */ |
5bd4f169 AM |
762 | 0, /* bitpos */ |
763 | complain_overflow_dont, /* complain_on_overflow */ | |
764 | bfd_elf_generic_reloc, /* special_function */ | |
765 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
b34976b6 | 766 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
767 | 0, /* src_mask */ |
768 | 0xffff, /* dst_mask */ | |
b34976b6 | 769 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
770 | |
771 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
772 | 16 bits, treated as a signed number, is negative. */ | |
773 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
774 | 32, /* rightshift */ | |
775 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
776 | 16, /* bitsize */ | |
b34976b6 | 777 | FALSE, /* pc_relative */ |
5bd4f169 AM |
778 | 0, /* bitpos */ |
779 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 780 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 781 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
b34976b6 | 782 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
783 | 0, /* src_mask */ |
784 | 0xffff, /* dst_mask */ | |
b34976b6 | 785 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
786 | |
787 | /* The bits 48-63 of an address. */ | |
788 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
789 | 48, /* rightshift */ | |
790 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
791 | 16, /* bitsize */ | |
b34976b6 | 792 | FALSE, /* pc_relative */ |
5bd4f169 AM |
793 | 0, /* bitpos */ |
794 | complain_overflow_dont, /* complain_on_overflow */ | |
795 | bfd_elf_generic_reloc, /* special_function */ | |
796 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
b34976b6 | 797 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
798 | 0, /* src_mask */ |
799 | 0xffff, /* dst_mask */ | |
b34976b6 | 800 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
801 | |
802 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
803 | 16 bits, treated as a signed number, is negative. */ | |
804 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
805 | 48, /* rightshift */ | |
806 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
807 | 16, /* bitsize */ | |
b34976b6 | 808 | FALSE, /* pc_relative */ |
5bd4f169 AM |
809 | 0, /* bitpos */ |
810 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 811 | ppc64_elf_ha_reloc, /* special_function */ |
5bd4f169 | 812 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
b34976b6 | 813 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
814 | 0, /* src_mask */ |
815 | 0xffff, /* dst_mask */ | |
b34976b6 | 816 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
817 | |
818 | /* Like ADDR64, but may be unaligned. */ | |
819 | HOWTO (R_PPC64_UADDR64, /* type */ | |
820 | 0, /* rightshift */ | |
821 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
822 | 64, /* bitsize */ | |
b34976b6 | 823 | FALSE, /* pc_relative */ |
5bd4f169 AM |
824 | 0, /* bitpos */ |
825 | complain_overflow_dont, /* complain_on_overflow */ | |
826 | bfd_elf_generic_reloc, /* special_function */ | |
827 | "R_PPC64_UADDR64", /* name */ | |
b34976b6 | 828 | FALSE, /* partial_inplace */ |
5bd4f169 | 829 | 0, /* src_mask */ |
f5e87a1d | 830 | ONES (64), /* dst_mask */ |
b34976b6 | 831 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
832 | |
833 | /* 64-bit relative relocation. */ | |
834 | HOWTO (R_PPC64_REL64, /* type */ | |
835 | 0, /* rightshift */ | |
836 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
837 | 64, /* bitsize */ | |
b34976b6 | 838 | TRUE, /* pc_relative */ |
5bd4f169 AM |
839 | 0, /* bitpos */ |
840 | complain_overflow_dont, /* complain_on_overflow */ | |
841 | bfd_elf_generic_reloc, /* special_function */ | |
842 | "R_PPC64_REL64", /* name */ | |
b34976b6 | 843 | FALSE, /* partial_inplace */ |
5bd4f169 | 844 | 0, /* src_mask */ |
f5e87a1d | 845 | ONES (64), /* dst_mask */ |
b34976b6 | 846 | TRUE), /* pcrel_offset */ |
5bd4f169 | 847 | |
cedb70c5 | 848 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
849 | HOWTO (R_PPC64_PLT64, /* type */ |
850 | 0, /* rightshift */ | |
851 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
852 | 64, /* bitsize */ | |
b34976b6 | 853 | FALSE, /* pc_relative */ |
5bd4f169 AM |
854 | 0, /* bitpos */ |
855 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 856 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 857 | "R_PPC64_PLT64", /* name */ |
b34976b6 | 858 | FALSE, /* partial_inplace */ |
5bd4f169 | 859 | 0, /* src_mask */ |
f5e87a1d | 860 | ONES (64), /* dst_mask */ |
b34976b6 | 861 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
862 | |
863 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
864 | table. */ | |
865 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
866 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
867 | 0, /* rightshift */ | |
868 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
869 | 64, /* bitsize */ | |
b34976b6 | 870 | TRUE, /* pc_relative */ |
5bd4f169 AM |
871 | 0, /* bitpos */ |
872 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 873 | ppc64_elf_unhandled_reloc, /* special_function */ |
5bd4f169 | 874 | "R_PPC64_PLTREL64", /* name */ |
b34976b6 | 875 | FALSE, /* partial_inplace */ |
5bd4f169 | 876 | 0, /* src_mask */ |
f5e87a1d | 877 | ONES (64), /* dst_mask */ |
b34976b6 | 878 | TRUE), /* pcrel_offset */ |
5bd4f169 AM |
879 | |
880 | /* 16 bit TOC-relative relocation. */ | |
881 | ||
882 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
883 | HOWTO (R_PPC64_TOC16, /* type */ | |
884 | 0, /* rightshift */ | |
885 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
886 | 16, /* bitsize */ | |
b34976b6 | 887 | FALSE, /* pc_relative */ |
5bd4f169 AM |
888 | 0, /* bitpos */ |
889 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 890 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 891 | "R_PPC64_TOC16", /* name */ |
b34976b6 | 892 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
893 | 0, /* src_mask */ |
894 | 0xffff, /* dst_mask */ | |
b34976b6 | 895 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
896 | |
897 | /* 16 bit TOC-relative relocation without overflow. */ | |
898 | ||
899 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
900 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
901 | 0, /* rightshift */ | |
902 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
903 | 16, /* bitsize */ | |
b34976b6 | 904 | FALSE, /* pc_relative */ |
5bd4f169 AM |
905 | 0, /* bitpos */ |
906 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 907 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 908 | "R_PPC64_TOC16_LO", /* name */ |
b34976b6 | 909 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
910 | 0, /* src_mask */ |
911 | 0xffff, /* dst_mask */ | |
b34976b6 | 912 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
913 | |
914 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
915 | ||
916 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
917 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
918 | 16, /* rightshift */ | |
919 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
920 | 16, /* bitsize */ | |
b34976b6 | 921 | FALSE, /* pc_relative */ |
5bd4f169 AM |
922 | 0, /* bitpos */ |
923 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 924 | ppc64_elf_toc_reloc, /* special_function */ |
5bd4f169 | 925 | "R_PPC64_TOC16_HI", /* name */ |
b34976b6 | 926 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
927 | 0, /* src_mask */ |
928 | 0xffff, /* dst_mask */ | |
b34976b6 | 929 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
930 | |
931 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
932 | contents of the low 16 bits, treated as a signed number, is | |
933 | negative. */ | |
934 | ||
935 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
936 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
937 | 16, /* rightshift */ | |
938 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
939 | 16, /* bitsize */ | |
b34976b6 | 940 | FALSE, /* pc_relative */ |
5bd4f169 AM |
941 | 0, /* bitpos */ |
942 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 943 | ppc64_elf_toc_ha_reloc, /* special_function */ |
5bd4f169 | 944 | "R_PPC64_TOC16_HA", /* name */ |
b34976b6 | 945 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
946 | 0, /* src_mask */ |
947 | 0xffff, /* dst_mask */ | |
b34976b6 | 948 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
949 | |
950 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
951 | ||
952 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
953 | HOWTO (R_PPC64_TOC, /* type */ | |
954 | 0, /* rightshift */ | |
955 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
956 | 64, /* bitsize */ | |
b34976b6 | 957 | FALSE, /* pc_relative */ |
5bd4f169 AM |
958 | 0, /* bitpos */ |
959 | complain_overflow_bitfield, /* complain_on_overflow */ | |
805fc799 | 960 | ppc64_elf_toc64_reloc, /* special_function */ |
5bd4f169 | 961 | "R_PPC64_TOC", /* name */ |
b34976b6 | 962 | FALSE, /* partial_inplace */ |
5bd4f169 | 963 | 0, /* src_mask */ |
f5e87a1d | 964 | ONES (64), /* dst_mask */ |
b34976b6 | 965 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
966 | |
967 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
968 | value to relocate may (!) refer to a PLT entry which the link | |
969 | editor (a) may replace with the symbol value. If the link editor | |
970 | is unable to fully resolve the symbol, it may (b) create a PLT | |
971 | entry and store the address to the new PLT entry in the GOT. | |
972 | This permits lazy resolution of function symbols at run time. | |
973 | The link editor may also skip all of this and just (c) emit a | |
974 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
975 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
976 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
977 | 0, /* rightshift */ | |
978 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
979 | 16, /* bitsize */ | |
b34976b6 | 980 | FALSE, /* pc_relative */ |
5bd4f169 AM |
981 | 0, /* bitpos */ |
982 | complain_overflow_signed, /* complain_on_overflow */ | |
805fc799 | 983 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb AM |
984 | "R_PPC64_PLTGOT16", /* name */ |
985 | FALSE, /* partial_inplace */ | |
986 | 0, /* src_mask */ | |
987 | 0xffff, /* dst_mask */ | |
988 | FALSE), /* pcrel_offset */ | |
989 | ||
990 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
991 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
992 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
993 | 0, /* rightshift */ | |
994 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
995 | 16, /* bitsize */ | |
996 | FALSE, /* pc_relative */ | |
997 | 0, /* bitpos */ | |
998 | complain_overflow_dont, /* complain_on_overflow */ | |
999 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1000 | "R_PPC64_PLTGOT16_LO", /* name */ | |
1001 | FALSE, /* partial_inplace */ | |
1002 | 0, /* src_mask */ | |
1003 | 0xffff, /* dst_mask */ | |
1004 | FALSE), /* pcrel_offset */ | |
1005 | ||
1006 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
1007 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
1008 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
1009 | 16, /* rightshift */ | |
1010 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1011 | 16, /* bitsize */ | |
1012 | FALSE, /* pc_relative */ | |
1013 | 0, /* bitpos */ | |
1014 | complain_overflow_dont, /* complain_on_overflow */ | |
1015 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1016 | "R_PPC64_PLTGOT16_HI", /* name */ | |
1017 | FALSE, /* partial_inplace */ | |
1018 | 0, /* src_mask */ | |
1019 | 0xffff, /* dst_mask */ | |
1020 | FALSE), /* pcrel_offset */ | |
1021 | ||
1022 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
1023 | 1 if the contents of the low 16 bits, treated as a signed number, | |
1024 | is negative. */ | |
1025 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
1026 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
1027 | 16, /* rightshift */ | |
1028 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1029 | 16, /* bitsize */ | |
1030 | FALSE, /* pc_relative */ | |
1031 | 0, /* bitpos */ | |
1032 | complain_overflow_dont,/* complain_on_overflow */ | |
1033 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1034 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1035 | FALSE, /* partial_inplace */ | |
1036 | 0, /* src_mask */ | |
1037 | 0xffff, /* dst_mask */ | |
1038 | FALSE), /* pcrel_offset */ | |
1039 | ||
1040 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1041 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1042 | 0, /* rightshift */ | |
1043 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1044 | 16, /* bitsize */ | |
1045 | FALSE, /* pc_relative */ | |
1046 | 0, /* bitpos */ | |
1047 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1048 | bfd_elf_generic_reloc, /* special_function */ | |
1049 | "R_PPC64_ADDR16_DS", /* name */ | |
1050 | FALSE, /* partial_inplace */ | |
1051 | 0, /* src_mask */ | |
1052 | 0xfffc, /* dst_mask */ | |
1053 | FALSE), /* pcrel_offset */ | |
1054 | ||
1055 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1056 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1057 | 0, /* rightshift */ | |
1058 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1059 | 16, /* bitsize */ | |
1060 | FALSE, /* pc_relative */ | |
1061 | 0, /* bitpos */ | |
1062 | complain_overflow_dont,/* complain_on_overflow */ | |
1063 | bfd_elf_generic_reloc, /* special_function */ | |
1064 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1065 | FALSE, /* partial_inplace */ | |
1066 | 0, /* src_mask */ | |
1067 | 0xfffc, /* dst_mask */ | |
1068 | FALSE), /* pcrel_offset */ | |
1069 | ||
1070 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1071 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1072 | 0, /* rightshift */ | |
1073 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1074 | 16, /* bitsize */ | |
1075 | FALSE, /* pc_relative */ | |
1076 | 0, /* bitpos */ | |
1077 | complain_overflow_signed, /* complain_on_overflow */ | |
1078 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1079 | "R_PPC64_GOT16_DS", /* name */ | |
1080 | FALSE, /* partial_inplace */ | |
1081 | 0, /* src_mask */ | |
1082 | 0xfffc, /* dst_mask */ | |
1083 | FALSE), /* pcrel_offset */ | |
1084 | ||
1085 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1086 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1087 | 0, /* rightshift */ | |
1088 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1089 | 16, /* bitsize */ | |
1090 | FALSE, /* pc_relative */ | |
1091 | 0, /* bitpos */ | |
1092 | complain_overflow_dont, /* complain_on_overflow */ | |
1093 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1094 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1095 | FALSE, /* partial_inplace */ | |
1096 | 0, /* src_mask */ | |
1097 | 0xfffc, /* dst_mask */ | |
1098 | FALSE), /* pcrel_offset */ | |
1099 | ||
1100 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1101 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1102 | 0, /* rightshift */ | |
1103 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1104 | 16, /* bitsize */ | |
1105 | FALSE, /* pc_relative */ | |
1106 | 0, /* bitpos */ | |
1107 | complain_overflow_dont, /* complain_on_overflow */ | |
1108 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1109 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1110 | FALSE, /* partial_inplace */ | |
1111 | 0, /* src_mask */ | |
1112 | 0xfffc, /* dst_mask */ | |
1113 | FALSE), /* pcrel_offset */ | |
1114 | ||
1115 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1116 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1117 | 0, /* rightshift */ | |
1118 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1119 | 16, /* bitsize */ | |
1120 | FALSE, /* pc_relative */ | |
1121 | 0, /* bitpos */ | |
1122 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1123 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1124 | "R_PPC64_SECTOFF_DS", /* name */ | |
1125 | FALSE, /* partial_inplace */ | |
1126 | 0, /* src_mask */ | |
1127 | 0xfffc, /* dst_mask */ | |
1128 | FALSE), /* pcrel_offset */ | |
1129 | ||
1130 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1131 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1132 | 0, /* rightshift */ | |
1133 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1134 | 16, /* bitsize */ | |
1135 | FALSE, /* pc_relative */ | |
1136 | 0, /* bitpos */ | |
1137 | complain_overflow_dont, /* complain_on_overflow */ | |
1138 | ppc64_elf_sectoff_reloc, /* special_function */ | |
1139 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1140 | FALSE, /* partial_inplace */ | |
1141 | 0, /* src_mask */ | |
1142 | 0xfffc, /* dst_mask */ | |
1143 | FALSE), /* pcrel_offset */ | |
1144 | ||
1145 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1146 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1147 | 0, /* rightshift */ | |
1148 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1149 | 16, /* bitsize */ | |
1150 | FALSE, /* pc_relative */ | |
1151 | 0, /* bitpos */ | |
1152 | complain_overflow_signed, /* complain_on_overflow */ | |
1153 | ppc64_elf_toc_reloc, /* special_function */ | |
1154 | "R_PPC64_TOC16_DS", /* name */ | |
1155 | FALSE, /* partial_inplace */ | |
1156 | 0, /* src_mask */ | |
1157 | 0xfffc, /* dst_mask */ | |
1158 | FALSE), /* pcrel_offset */ | |
1159 | ||
1160 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1161 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1162 | 0, /* rightshift */ | |
1163 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1164 | 16, /* bitsize */ | |
1165 | FALSE, /* pc_relative */ | |
1166 | 0, /* bitpos */ | |
1167 | complain_overflow_dont, /* complain_on_overflow */ | |
1168 | ppc64_elf_toc_reloc, /* special_function */ | |
1169 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1170 | FALSE, /* partial_inplace */ | |
1171 | 0, /* src_mask */ | |
1172 | 0xfffc, /* dst_mask */ | |
1173 | FALSE), /* pcrel_offset */ | |
1174 | ||
1175 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1176 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1177 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ | |
1178 | 0, /* rightshift */ | |
1179 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1180 | 16, /* bitsize */ | |
1181 | FALSE, /* pc_relative */ | |
1182 | 0, /* bitpos */ | |
1183 | complain_overflow_signed, /* complain_on_overflow */ | |
1184 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1185 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1186 | FALSE, /* partial_inplace */ | |
1187 | 0, /* src_mask */ | |
1188 | 0xfffc, /* dst_mask */ | |
1189 | FALSE), /* pcrel_offset */ | |
1190 | ||
1191 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1192 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1193 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1194 | 0, /* rightshift */ | |
1195 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1196 | 16, /* bitsize */ | |
1197 | FALSE, /* pc_relative */ | |
1198 | 0, /* bitpos */ | |
1199 | complain_overflow_dont, /* complain_on_overflow */ | |
1200 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1201 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1202 | FALSE, /* partial_inplace */ | |
1203 | 0, /* src_mask */ | |
1204 | 0xfffc, /* dst_mask */ | |
1205 | FALSE), /* pcrel_offset */ | |
1206 | ||
1207 | /* Marker reloc for TLS. */ | |
1208 | HOWTO (R_PPC64_TLS, | |
1209 | 0, /* rightshift */ | |
1210 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1211 | 32, /* bitsize */ | |
1212 | FALSE, /* pc_relative */ | |
1213 | 0, /* bitpos */ | |
1214 | complain_overflow_dont, /* complain_on_overflow */ | |
1215 | bfd_elf_generic_reloc, /* special_function */ | |
1216 | "R_PPC64_TLS", /* name */ | |
1217 | FALSE, /* partial_inplace */ | |
1218 | 0, /* src_mask */ | |
1219 | 0, /* dst_mask */ | |
1220 | FALSE), /* pcrel_offset */ | |
1221 | ||
1222 | /* Computes the load module index of the load module that contains the | |
1223 | definition of its TLS sym. */ | |
1224 | HOWTO (R_PPC64_DTPMOD64, | |
1225 | 0, /* rightshift */ | |
1226 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1227 | 64, /* bitsize */ | |
1228 | FALSE, /* pc_relative */ | |
1229 | 0, /* bitpos */ | |
1230 | complain_overflow_dont, /* complain_on_overflow */ | |
1231 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1232 | "R_PPC64_DTPMOD64", /* name */ | |
1233 | FALSE, /* partial_inplace */ | |
1234 | 0, /* src_mask */ | |
1235 | ONES (64), /* dst_mask */ | |
1236 | FALSE), /* pcrel_offset */ | |
1237 | ||
1238 | /* Computes a dtv-relative displacement, the difference between the value | |
1239 | of sym+add and the base address of the thread-local storage block that | |
1240 | contains the definition of sym, minus 0x8000. */ | |
1241 | HOWTO (R_PPC64_DTPREL64, | |
1242 | 0, /* rightshift */ | |
1243 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1244 | 64, /* bitsize */ | |
1245 | FALSE, /* pc_relative */ | |
1246 | 0, /* bitpos */ | |
1247 | complain_overflow_dont, /* complain_on_overflow */ | |
1248 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1249 | "R_PPC64_DTPREL64", /* name */ | |
1250 | FALSE, /* partial_inplace */ | |
1251 | 0, /* src_mask */ | |
1252 | ONES (64), /* dst_mask */ | |
1253 | FALSE), /* pcrel_offset */ | |
1254 | ||
1255 | /* A 16 bit dtprel reloc. */ | |
1256 | HOWTO (R_PPC64_DTPREL16, | |
1257 | 0, /* rightshift */ | |
1258 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1259 | 16, /* bitsize */ | |
1260 | FALSE, /* pc_relative */ | |
1261 | 0, /* bitpos */ | |
1262 | complain_overflow_signed, /* complain_on_overflow */ | |
1263 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1264 | "R_PPC64_DTPREL16", /* name */ | |
1265 | FALSE, /* partial_inplace */ | |
1266 | 0, /* src_mask */ | |
1267 | 0xffff, /* dst_mask */ | |
1268 | FALSE), /* pcrel_offset */ | |
1269 | ||
1270 | /* Like DTPREL16, but no overflow. */ | |
1271 | HOWTO (R_PPC64_DTPREL16_LO, | |
1272 | 0, /* rightshift */ | |
1273 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1274 | 16, /* bitsize */ | |
1275 | FALSE, /* pc_relative */ | |
1276 | 0, /* bitpos */ | |
1277 | complain_overflow_dont, /* complain_on_overflow */ | |
1278 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1279 | "R_PPC64_DTPREL16_LO", /* name */ | |
1280 | FALSE, /* partial_inplace */ | |
1281 | 0, /* src_mask */ | |
1282 | 0xffff, /* dst_mask */ | |
1283 | FALSE), /* pcrel_offset */ | |
1284 | ||
1285 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ | |
1286 | HOWTO (R_PPC64_DTPREL16_HI, | |
1287 | 16, /* rightshift */ | |
1288 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1289 | 16, /* bitsize */ | |
1290 | FALSE, /* pc_relative */ | |
1291 | 0, /* bitpos */ | |
1292 | complain_overflow_dont, /* complain_on_overflow */ | |
1293 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1294 | "R_PPC64_DTPREL16_HI", /* name */ | |
1295 | FALSE, /* partial_inplace */ | |
1296 | 0, /* src_mask */ | |
1297 | 0xffff, /* dst_mask */ | |
1298 | FALSE), /* pcrel_offset */ | |
1299 | ||
1300 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ | |
1301 | HOWTO (R_PPC64_DTPREL16_HA, | |
1302 | 16, /* rightshift */ | |
1303 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1304 | 16, /* bitsize */ | |
1305 | FALSE, /* pc_relative */ | |
1306 | 0, /* bitpos */ | |
1307 | complain_overflow_dont, /* complain_on_overflow */ | |
1308 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1309 | "R_PPC64_DTPREL16_HA", /* name */ | |
1310 | FALSE, /* partial_inplace */ | |
1311 | 0, /* src_mask */ | |
1312 | 0xffff, /* dst_mask */ | |
1313 | FALSE), /* pcrel_offset */ | |
1314 | ||
1315 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ | |
1316 | HOWTO (R_PPC64_DTPREL16_HIGHER, | |
1317 | 32, /* rightshift */ | |
1318 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1319 | 16, /* bitsize */ | |
1320 | FALSE, /* pc_relative */ | |
1321 | 0, /* bitpos */ | |
1322 | complain_overflow_dont, /* complain_on_overflow */ | |
1323 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1324 | "R_PPC64_DTPREL16_HIGHER", /* name */ | |
1325 | FALSE, /* partial_inplace */ | |
1326 | 0, /* src_mask */ | |
1327 | 0xffff, /* dst_mask */ | |
1328 | FALSE), /* pcrel_offset */ | |
1329 | ||
1330 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ | |
1331 | HOWTO (R_PPC64_DTPREL16_HIGHERA, | |
1332 | 32, /* rightshift */ | |
1333 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1334 | 16, /* bitsize */ | |
1335 | FALSE, /* pc_relative */ | |
1336 | 0, /* bitpos */ | |
1337 | complain_overflow_dont, /* complain_on_overflow */ | |
1338 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1339 | "R_PPC64_DTPREL16_HIGHERA", /* name */ | |
1340 | FALSE, /* partial_inplace */ | |
1341 | 0, /* src_mask */ | |
1342 | 0xffff, /* dst_mask */ | |
1343 | FALSE), /* pcrel_offset */ | |
1344 | ||
1345 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ | |
1346 | HOWTO (R_PPC64_DTPREL16_HIGHEST, | |
1347 | 48, /* rightshift */ | |
1348 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1349 | 16, /* bitsize */ | |
1350 | FALSE, /* pc_relative */ | |
1351 | 0, /* bitpos */ | |
1352 | complain_overflow_dont, /* complain_on_overflow */ | |
1353 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1354 | "R_PPC64_DTPREL16_HIGHEST", /* name */ | |
1355 | FALSE, /* partial_inplace */ | |
1356 | 0, /* src_mask */ | |
1357 | 0xffff, /* dst_mask */ | |
1358 | FALSE), /* pcrel_offset */ | |
1359 | ||
1360 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1361 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, | |
1362 | 48, /* rightshift */ | |
1363 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1364 | 16, /* bitsize */ | |
1365 | FALSE, /* pc_relative */ | |
1366 | 0, /* bitpos */ | |
1367 | complain_overflow_dont, /* complain_on_overflow */ | |
1368 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1369 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ | |
1370 | FALSE, /* partial_inplace */ | |
1371 | 0, /* src_mask */ | |
1372 | 0xffff, /* dst_mask */ | |
1373 | FALSE), /* pcrel_offset */ | |
1374 | ||
1375 | /* Like DTPREL16, but for insns with a DS field. */ | |
1376 | HOWTO (R_PPC64_DTPREL16_DS, | |
1377 | 0, /* rightshift */ | |
1378 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1379 | 16, /* bitsize */ | |
1380 | FALSE, /* pc_relative */ | |
1381 | 0, /* bitpos */ | |
1382 | complain_overflow_signed, /* complain_on_overflow */ | |
1383 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1384 | "R_PPC64_DTPREL16_DS", /* name */ | |
1385 | FALSE, /* partial_inplace */ | |
1386 | 0, /* src_mask */ | |
1387 | 0xfffc, /* dst_mask */ | |
1388 | FALSE), /* pcrel_offset */ | |
1389 | ||
1390 | /* Like DTPREL16_DS, but no overflow. */ | |
1391 | HOWTO (R_PPC64_DTPREL16_LO_DS, | |
1392 | 0, /* rightshift */ | |
1393 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1394 | 16, /* bitsize */ | |
1395 | FALSE, /* pc_relative */ | |
1396 | 0, /* bitpos */ | |
1397 | complain_overflow_dont, /* complain_on_overflow */ | |
1398 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1399 | "R_PPC64_DTPREL16_LO_DS", /* name */ | |
1400 | FALSE, /* partial_inplace */ | |
1401 | 0, /* src_mask */ | |
1402 | 0xfffc, /* dst_mask */ | |
1403 | FALSE), /* pcrel_offset */ | |
1404 | ||
1405 | /* Computes a tp-relative displacement, the difference between the value of | |
1406 | sym+add and the value of the thread pointer (r13). */ | |
1407 | HOWTO (R_PPC64_TPREL64, | |
1408 | 0, /* rightshift */ | |
1409 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1410 | 64, /* bitsize */ | |
1411 | FALSE, /* pc_relative */ | |
1412 | 0, /* bitpos */ | |
1413 | complain_overflow_dont, /* complain_on_overflow */ | |
1414 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1415 | "R_PPC64_TPREL64", /* name */ | |
1416 | FALSE, /* partial_inplace */ | |
1417 | 0, /* src_mask */ | |
1418 | ONES (64), /* dst_mask */ | |
1419 | FALSE), /* pcrel_offset */ | |
1420 | ||
1421 | /* A 16 bit tprel reloc. */ | |
1422 | HOWTO (R_PPC64_TPREL16, | |
1423 | 0, /* rightshift */ | |
1424 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1425 | 16, /* bitsize */ | |
1426 | FALSE, /* pc_relative */ | |
1427 | 0, /* bitpos */ | |
1428 | complain_overflow_signed, /* complain_on_overflow */ | |
1429 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1430 | "R_PPC64_TPREL16", /* name */ | |
1431 | FALSE, /* partial_inplace */ | |
1432 | 0, /* src_mask */ | |
1433 | 0xffff, /* dst_mask */ | |
1434 | FALSE), /* pcrel_offset */ | |
1435 | ||
1436 | /* Like TPREL16, but no overflow. */ | |
1437 | HOWTO (R_PPC64_TPREL16_LO, | |
1438 | 0, /* rightshift */ | |
1439 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1440 | 16, /* bitsize */ | |
1441 | FALSE, /* pc_relative */ | |
1442 | 0, /* bitpos */ | |
1443 | complain_overflow_dont, /* complain_on_overflow */ | |
1444 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1445 | "R_PPC64_TPREL16_LO", /* name */ | |
1446 | FALSE, /* partial_inplace */ | |
1447 | 0, /* src_mask */ | |
1448 | 0xffff, /* dst_mask */ | |
1449 | FALSE), /* pcrel_offset */ | |
1450 | ||
1451 | /* Like TPREL16_LO, but next higher group of 16 bits. */ | |
1452 | HOWTO (R_PPC64_TPREL16_HI, | |
1453 | 16, /* rightshift */ | |
1454 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1455 | 16, /* bitsize */ | |
1456 | FALSE, /* pc_relative */ | |
1457 | 0, /* bitpos */ | |
1458 | complain_overflow_dont, /* complain_on_overflow */ | |
1459 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1460 | "R_PPC64_TPREL16_HI", /* name */ | |
1461 | FALSE, /* partial_inplace */ | |
1462 | 0, /* src_mask */ | |
1463 | 0xffff, /* dst_mask */ | |
1464 | FALSE), /* pcrel_offset */ | |
1465 | ||
1466 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1467 | HOWTO (R_PPC64_TPREL16_HA, | |
1468 | 16, /* rightshift */ | |
1469 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1470 | 16, /* bitsize */ | |
1471 | FALSE, /* pc_relative */ | |
1472 | 0, /* bitpos */ | |
1473 | complain_overflow_dont, /* complain_on_overflow */ | |
1474 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1475 | "R_PPC64_TPREL16_HA", /* name */ | |
1476 | FALSE, /* partial_inplace */ | |
1477 | 0, /* src_mask */ | |
1478 | 0xffff, /* dst_mask */ | |
1479 | FALSE), /* pcrel_offset */ | |
1480 | ||
1481 | /* Like TPREL16_HI, but next higher group of 16 bits. */ | |
1482 | HOWTO (R_PPC64_TPREL16_HIGHER, | |
1483 | 32, /* rightshift */ | |
1484 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1485 | 16, /* bitsize */ | |
1486 | FALSE, /* pc_relative */ | |
1487 | 0, /* bitpos */ | |
1488 | complain_overflow_dont, /* complain_on_overflow */ | |
1489 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1490 | "R_PPC64_TPREL16_HIGHER", /* name */ | |
1491 | FALSE, /* partial_inplace */ | |
1492 | 0, /* src_mask */ | |
1493 | 0xffff, /* dst_mask */ | |
1494 | FALSE), /* pcrel_offset */ | |
1495 | ||
1496 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ | |
1497 | HOWTO (R_PPC64_TPREL16_HIGHERA, | |
1498 | 32, /* rightshift */ | |
1499 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1500 | 16, /* bitsize */ | |
1501 | FALSE, /* pc_relative */ | |
1502 | 0, /* bitpos */ | |
1503 | complain_overflow_dont, /* complain_on_overflow */ | |
1504 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1505 | "R_PPC64_TPREL16_HIGHERA", /* name */ | |
1506 | FALSE, /* partial_inplace */ | |
1507 | 0, /* src_mask */ | |
1508 | 0xffff, /* dst_mask */ | |
1509 | FALSE), /* pcrel_offset */ | |
1510 | ||
1511 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ | |
1512 | HOWTO (R_PPC64_TPREL16_HIGHEST, | |
1513 | 48, /* rightshift */ | |
1514 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1515 | 16, /* bitsize */ | |
1516 | FALSE, /* pc_relative */ | |
1517 | 0, /* bitpos */ | |
1518 | complain_overflow_dont, /* complain_on_overflow */ | |
1519 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1520 | "R_PPC64_TPREL16_HIGHEST", /* name */ | |
1521 | FALSE, /* partial_inplace */ | |
1522 | 0, /* src_mask */ | |
1523 | 0xffff, /* dst_mask */ | |
1524 | FALSE), /* pcrel_offset */ | |
1525 | ||
1526 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ | |
1527 | HOWTO (R_PPC64_TPREL16_HIGHESTA, | |
1528 | 48, /* rightshift */ | |
1529 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1530 | 16, /* bitsize */ | |
1531 | FALSE, /* pc_relative */ | |
1532 | 0, /* bitpos */ | |
1533 | complain_overflow_dont, /* complain_on_overflow */ | |
1534 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1535 | "R_PPC64_TPREL16_HIGHESTA", /* name */ | |
1536 | FALSE, /* partial_inplace */ | |
1537 | 0, /* src_mask */ | |
1538 | 0xffff, /* dst_mask */ | |
1539 | FALSE), /* pcrel_offset */ | |
1540 | ||
1541 | /* Like TPREL16, but for insns with a DS field. */ | |
1542 | HOWTO (R_PPC64_TPREL16_DS, | |
1543 | 0, /* rightshift */ | |
1544 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1545 | 16, /* bitsize */ | |
1546 | FALSE, /* pc_relative */ | |
1547 | 0, /* bitpos */ | |
1548 | complain_overflow_signed, /* complain_on_overflow */ | |
1549 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1550 | "R_PPC64_TPREL16_DS", /* name */ | |
1551 | FALSE, /* partial_inplace */ | |
1552 | 0, /* src_mask */ | |
1553 | 0xfffc, /* dst_mask */ | |
1554 | FALSE), /* pcrel_offset */ | |
1555 | ||
1556 | /* Like TPREL16_DS, but no overflow. */ | |
1557 | HOWTO (R_PPC64_TPREL16_LO_DS, | |
1558 | 0, /* rightshift */ | |
1559 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1560 | 16, /* bitsize */ | |
1561 | FALSE, /* pc_relative */ | |
1562 | 0, /* bitpos */ | |
1563 | complain_overflow_dont, /* complain_on_overflow */ | |
1564 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1565 | "R_PPC64_TPREL16_LO_DS", /* name */ | |
1566 | FALSE, /* partial_inplace */ | |
1567 | 0, /* src_mask */ | |
1568 | 0xfffc, /* dst_mask */ | |
1569 | FALSE), /* pcrel_offset */ | |
1570 | ||
1571 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1572 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1573 | to the first entry relative to the TOC base (r2). */ | |
1574 | HOWTO (R_PPC64_GOT_TLSGD16, | |
1575 | 0, /* rightshift */ | |
1576 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1577 | 16, /* bitsize */ | |
1578 | FALSE, /* pc_relative */ | |
1579 | 0, /* bitpos */ | |
1580 | complain_overflow_signed, /* complain_on_overflow */ | |
1581 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1582 | "R_PPC64_GOT_TLSGD16", /* name */ | |
b34976b6 | 1583 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1584 | 0, /* src_mask */ |
1585 | 0xffff, /* dst_mask */ | |
b34976b6 | 1586 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1587 | |
411e1bfb AM |
1588 | /* Like GOT_TLSGD16, but no overflow. */ |
1589 | HOWTO (R_PPC64_GOT_TLSGD16_LO, | |
5bd4f169 AM |
1590 | 0, /* rightshift */ |
1591 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1592 | 16, /* bitsize */ | |
b34976b6 | 1593 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1594 | 0, /* bitpos */ |
1595 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1596 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1597 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
b34976b6 | 1598 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1599 | 0, /* src_mask */ |
1600 | 0xffff, /* dst_mask */ | |
b34976b6 | 1601 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1602 | |
411e1bfb AM |
1603 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1604 | HOWTO (R_PPC64_GOT_TLSGD16_HI, | |
5bd4f169 AM |
1605 | 16, /* rightshift */ |
1606 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1607 | 16, /* bitsize */ | |
b34976b6 | 1608 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1609 | 0, /* bitpos */ |
1610 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1611 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1612 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
b34976b6 | 1613 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1614 | 0, /* src_mask */ |
1615 | 0xffff, /* dst_mask */ | |
b34976b6 | 1616 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1617 | |
411e1bfb AM |
1618 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1619 | HOWTO (R_PPC64_GOT_TLSGD16_HA, | |
5bd4f169 AM |
1620 | 16, /* rightshift */ |
1621 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1622 | 16, /* bitsize */ | |
b34976b6 | 1623 | FALSE, /* pc_relative */ |
5bd4f169 | 1624 | 0, /* bitpos */ |
411e1bfb | 1625 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1626 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1627 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
b34976b6 | 1628 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1629 | 0, /* src_mask */ |
1630 | 0xffff, /* dst_mask */ | |
b34976b6 | 1631 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1632 | |
411e1bfb AM |
1633 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
1634 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1635 | first entry relative to the TOC base (r2). */ | |
1636 | HOWTO (R_PPC64_GOT_TLSLD16, | |
5bd4f169 AM |
1637 | 0, /* rightshift */ |
1638 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1639 | 16, /* bitsize */ | |
b34976b6 | 1640 | FALSE, /* pc_relative */ |
5bd4f169 | 1641 | 0, /* bitpos */ |
411e1bfb AM |
1642 | complain_overflow_signed, /* complain_on_overflow */ |
1643 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1644 | "R_PPC64_GOT_TLSLD16", /* name */ | |
b34976b6 | 1645 | FALSE, /* partial_inplace */ |
d006db6c | 1646 | 0, /* src_mask */ |
411e1bfb | 1647 | 0xffff, /* dst_mask */ |
b34976b6 | 1648 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1649 | |
411e1bfb AM |
1650 | /* Like GOT_TLSLD16, but no overflow. */ |
1651 | HOWTO (R_PPC64_GOT_TLSLD16_LO, | |
5bd4f169 AM |
1652 | 0, /* rightshift */ |
1653 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1654 | 16, /* bitsize */ | |
b34976b6 | 1655 | FALSE, /* pc_relative */ |
5bd4f169 | 1656 | 0, /* bitpos */ |
411e1bfb AM |
1657 | complain_overflow_dont, /* complain_on_overflow */ |
1658 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1659 | "R_PPC64_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1660 | FALSE, /* partial_inplace */ |
d006db6c | 1661 | 0, /* src_mask */ |
411e1bfb | 1662 | 0xffff, /* dst_mask */ |
b34976b6 | 1663 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1664 | |
411e1bfb AM |
1665 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1666 | HOWTO (R_PPC64_GOT_TLSLD16_HI, | |
1667 | 16, /* rightshift */ | |
5bd4f169 AM |
1668 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1669 | 16, /* bitsize */ | |
b34976b6 | 1670 | FALSE, /* pc_relative */ |
5bd4f169 | 1671 | 0, /* bitpos */ |
411e1bfb | 1672 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1673 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1674 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
b34976b6 | 1675 | FALSE, /* partial_inplace */ |
d006db6c | 1676 | 0, /* src_mask */ |
411e1bfb | 1677 | 0xffff, /* dst_mask */ |
b34976b6 | 1678 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1679 | |
411e1bfb AM |
1680 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1681 | HOWTO (R_PPC64_GOT_TLSLD16_HA, | |
1682 | 16, /* rightshift */ | |
5bd4f169 AM |
1683 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1684 | 16, /* bitsize */ | |
b34976b6 | 1685 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1686 | 0, /* bitpos */ |
1687 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1688 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1689 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
b34976b6 | 1690 | FALSE, /* partial_inplace */ |
d006db6c | 1691 | 0, /* src_mask */ |
411e1bfb | 1692 | 0xffff, /* dst_mask */ |
b34976b6 | 1693 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1694 | |
411e1bfb AM |
1695 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
1696 | the offset to the entry relative to the TOC base (r2). */ | |
1697 | HOWTO (R_PPC64_GOT_DTPREL16_DS, | |
5bd4f169 AM |
1698 | 0, /* rightshift */ |
1699 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1700 | 16, /* bitsize */ | |
b34976b6 | 1701 | FALSE, /* pc_relative */ |
5bd4f169 | 1702 | 0, /* bitpos */ |
411e1bfb | 1703 | complain_overflow_signed, /* complain_on_overflow */ |
805fc799 | 1704 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1705 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
b34976b6 | 1706 | FALSE, /* partial_inplace */ |
d006db6c | 1707 | 0, /* src_mask */ |
5bd4f169 | 1708 | 0xfffc, /* dst_mask */ |
b34976b6 | 1709 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1710 | |
411e1bfb AM |
1711 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
1712 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, | |
5bd4f169 | 1713 | 0, /* rightshift */ |
c061c2d8 AM |
1714 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1715 | 16, /* bitsize */ | |
b34976b6 | 1716 | FALSE, /* pc_relative */ |
5bd4f169 | 1717 | 0, /* bitpos */ |
411e1bfb AM |
1718 | complain_overflow_dont, /* complain_on_overflow */ |
1719 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1720 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ | |
b34976b6 | 1721 | FALSE, /* partial_inplace */ |
d006db6c | 1722 | 0, /* src_mask */ |
c061c2d8 | 1723 | 0xfffc, /* dst_mask */ |
b34976b6 | 1724 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1725 | |
411e1bfb AM |
1726 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
1727 | HOWTO (R_PPC64_GOT_DTPREL16_HI, | |
1728 | 16, /* rightshift */ | |
5bd4f169 AM |
1729 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1730 | 16, /* bitsize */ | |
b34976b6 | 1731 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1732 | 0, /* bitpos */ |
1733 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1734 | ppc64_elf_unhandled_reloc, /* special_function */ |
1735 | "R_PPC64_GOT_DTPREL16_HI", /* name */ | |
b34976b6 | 1736 | FALSE, /* partial_inplace */ |
d006db6c | 1737 | 0, /* src_mask */ |
411e1bfb | 1738 | 0xffff, /* dst_mask */ |
b34976b6 | 1739 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1740 | |
411e1bfb AM |
1741 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1742 | HOWTO (R_PPC64_GOT_DTPREL16_HA, | |
1743 | 16, /* rightshift */ | |
1744 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1745 | 16, /* bitsize */ | |
1746 | FALSE, /* pc_relative */ | |
1747 | 0, /* bitpos */ | |
1748 | complain_overflow_dont, /* complain_on_overflow */ | |
1749 | ppc64_elf_unhandled_reloc, /* special_function */ | |
1750 | "R_PPC64_GOT_DTPREL16_HA", /* name */ | |
1751 | FALSE, /* partial_inplace */ | |
1752 | 0, /* src_mask */ | |
1753 | 0xffff, /* dst_mask */ | |
1754 | FALSE), /* pcrel_offset */ | |
1755 | ||
1756 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the | |
1757 | offset to the entry relative to the TOC base (r2). */ | |
1758 | HOWTO (R_PPC64_GOT_TPREL16_DS, | |
5bd4f169 AM |
1759 | 0, /* rightshift */ |
1760 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1761 | 16, /* bitsize */ | |
b34976b6 | 1762 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1763 | 0, /* bitpos */ |
1764 | complain_overflow_signed, /* complain_on_overflow */ | |
411e1bfb AM |
1765 | ppc64_elf_unhandled_reloc, /* special_function */ |
1766 | "R_PPC64_GOT_TPREL16_DS", /* name */ | |
b34976b6 | 1767 | FALSE, /* partial_inplace */ |
d006db6c | 1768 | 0, /* src_mask */ |
ad8e1ba5 | 1769 | 0xfffc, /* dst_mask */ |
b34976b6 | 1770 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1771 | |
411e1bfb AM |
1772 | /* Like GOT_TPREL16_DS, but no overflow. */ |
1773 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, | |
5bd4f169 AM |
1774 | 0, /* rightshift */ |
1775 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1776 | 16, /* bitsize */ | |
b34976b6 | 1777 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1778 | 0, /* bitpos */ |
1779 | complain_overflow_dont, /* complain_on_overflow */ | |
411e1bfb AM |
1780 | ppc64_elf_unhandled_reloc, /* special_function */ |
1781 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ | |
b34976b6 | 1782 | FALSE, /* partial_inplace */ |
d006db6c | 1783 | 0, /* src_mask */ |
ad8e1ba5 | 1784 | 0xfffc, /* dst_mask */ |
b34976b6 | 1785 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1786 | |
411e1bfb AM |
1787 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
1788 | HOWTO (R_PPC64_GOT_TPREL16_HI, | |
1789 | 16, /* rightshift */ | |
5bd4f169 AM |
1790 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1791 | 16, /* bitsize */ | |
b34976b6 | 1792 | FALSE, /* pc_relative */ |
5bd4f169 | 1793 | 0, /* bitpos */ |
411e1bfb | 1794 | complain_overflow_dont, /* complain_on_overflow */ |
805fc799 | 1795 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1796 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
b34976b6 | 1797 | FALSE, /* partial_inplace */ |
d006db6c | 1798 | 0, /* src_mask */ |
411e1bfb | 1799 | 0xffff, /* dst_mask */ |
b34976b6 | 1800 | FALSE), /* pcrel_offset */ |
5bd4f169 | 1801 | |
411e1bfb AM |
1802 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
1803 | HOWTO (R_PPC64_GOT_TPREL16_HA, | |
1804 | 16, /* rightshift */ | |
5bd4f169 AM |
1805 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1806 | 16, /* bitsize */ | |
b34976b6 | 1807 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1808 | 0, /* bitpos */ |
1809 | complain_overflow_dont, /* complain_on_overflow */ | |
805fc799 | 1810 | ppc64_elf_unhandled_reloc, /* special_function */ |
411e1bfb | 1811 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
b34976b6 | 1812 | FALSE, /* partial_inplace */ |
d006db6c | 1813 | 0, /* src_mask */ |
411e1bfb | 1814 | 0xffff, /* dst_mask */ |
b34976b6 | 1815 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1816 | |
1817 | /* GNU extension to record C++ vtable hierarchy. */ | |
1818 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1819 | 0, /* rightshift */ | |
1820 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1821 | 0, /* bitsize */ | |
b34976b6 | 1822 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1823 | 0, /* bitpos */ |
1824 | complain_overflow_dont, /* complain_on_overflow */ | |
1825 | NULL, /* special_function */ | |
1826 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1827 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1828 | 0, /* src_mask */ |
1829 | 0, /* dst_mask */ | |
b34976b6 | 1830 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1831 | |
1832 | /* GNU extension to record C++ vtable member usage. */ | |
1833 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1834 | 0, /* rightshift */ | |
1835 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1836 | 0, /* bitsize */ | |
b34976b6 | 1837 | FALSE, /* pc_relative */ |
5bd4f169 AM |
1838 | 0, /* bitpos */ |
1839 | complain_overflow_dont, /* complain_on_overflow */ | |
1840 | NULL, /* special_function */ | |
1841 | "R_PPC64_GNU_VTENTRY", /* name */ | |
b34976b6 | 1842 | FALSE, /* partial_inplace */ |
5bd4f169 AM |
1843 | 0, /* src_mask */ |
1844 | 0, /* dst_mask */ | |
b34976b6 | 1845 | FALSE), /* pcrel_offset */ |
5bd4f169 AM |
1846 | }; |
1847 | ||
1848 | \f | |
1849 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1850 | be done. */ | |
1851 | ||
1852 | static void | |
4ce794b7 | 1853 | ppc_howto_init (void) |
5bd4f169 AM |
1854 | { |
1855 | unsigned int i, type; | |
1856 | ||
1857 | for (i = 0; | |
1858 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1859 | i++) | |
1860 | { | |
1861 | type = ppc64_elf_howto_raw[i].type; | |
1862 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1863 | / sizeof (ppc64_elf_howto_table[0]))); | |
1864 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1865 | } | |
1866 | } | |
1867 | ||
1868 | static reloc_howto_type * | |
4ce794b7 AM |
1869 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1870 | bfd_reloc_code_real_type code) | |
5bd4f169 | 1871 | { |
411e1bfb | 1872 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
5bd4f169 AM |
1873 | |
1874 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1875 | /* Initialize howto table if needed. */ | |
1876 | ppc_howto_init (); | |
1877 | ||
4ce794b7 | 1878 | switch (code) |
5bd4f169 AM |
1879 | { |
1880 | default: | |
4ce794b7 | 1881 | return NULL; |
5bd4f169 | 1882 | |
411e1bfb AM |
1883 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
1884 | break; | |
1885 | case BFD_RELOC_32: r = R_PPC64_ADDR32; | |
1886 | break; | |
1887 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; | |
1888 | break; | |
1889 | case BFD_RELOC_16: r = R_PPC64_ADDR16; | |
1890 | break; | |
1891 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; | |
1892 | break; | |
1893 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; | |
1894 | break; | |
1895 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; | |
5bd4f169 | 1896 | break; |
411e1bfb | 1897 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
5bd4f169 | 1898 | break; |
411e1bfb | 1899 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
5bd4f169 | 1900 | break; |
411e1bfb | 1901 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
5bd4f169 | 1902 | break; |
411e1bfb | 1903 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
5bd4f169 | 1904 | break; |
411e1bfb | 1905 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
5bd4f169 | 1906 | break; |
411e1bfb | 1907 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
5bd4f169 | 1908 | break; |
411e1bfb | 1909 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
5bd4f169 | 1910 | break; |
411e1bfb | 1911 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
5bd4f169 | 1912 | break; |
411e1bfb | 1913 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
5bd4f169 | 1914 | break; |
411e1bfb | 1915 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
5bd4f169 | 1916 | break; |
411e1bfb | 1917 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
5bd4f169 | 1918 | break; |
411e1bfb | 1919 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
5bd4f169 | 1920 | break; |
411e1bfb | 1921 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
5bd4f169 | 1922 | break; |
411e1bfb | 1923 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
5bd4f169 | 1924 | break; |
411e1bfb | 1925 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
5bd4f169 | 1926 | break; |
411e1bfb | 1927 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
5bd4f169 | 1928 | break; |
411e1bfb | 1929 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
5bd4f169 | 1930 | break; |
411e1bfb | 1931 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
5bd4f169 | 1932 | break; |
411e1bfb | 1933 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
5bd4f169 | 1934 | break; |
411e1bfb | 1935 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
5bd4f169 | 1936 | break; |
411e1bfb | 1937 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
5bd4f169 | 1938 | break; |
411e1bfb | 1939 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
5bd4f169 | 1940 | break; |
411e1bfb | 1941 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
5bd4f169 | 1942 | break; |
411e1bfb | 1943 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
5bd4f169 | 1944 | break; |
411e1bfb | 1945 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
5bd4f169 | 1946 | break; |
411e1bfb | 1947 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
5bd4f169 | 1948 | break; |
411e1bfb | 1949 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
5bd4f169 | 1950 | break; |
411e1bfb | 1951 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
5bd4f169 | 1952 | break; |
411e1bfb | 1953 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
5bd4f169 | 1954 | break; |
411e1bfb | 1955 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
5bd4f169 | 1956 | break; |
411e1bfb | 1957 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
5bd4f169 | 1958 | break; |
411e1bfb | 1959 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
5bd4f169 | 1960 | break; |
411e1bfb | 1961 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
5bd4f169 | 1962 | break; |
411e1bfb | 1963 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
5bd4f169 | 1964 | break; |
411e1bfb | 1965 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
5bd4f169 | 1966 | break; |
411e1bfb | 1967 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
5bd4f169 | 1968 | break; |
411e1bfb | 1969 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
5bd4f169 | 1970 | break; |
411e1bfb | 1971 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
5bd4f169 | 1972 | break; |
411e1bfb | 1973 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
5bd4f169 | 1974 | break; |
411e1bfb | 1975 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
5bd4f169 | 1976 | break; |
411e1bfb | 1977 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
5bd4f169 | 1978 | break; |
411e1bfb | 1979 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
5bd4f169 | 1980 | break; |
411e1bfb | 1981 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
5bd4f169 | 1982 | break; |
411e1bfb | 1983 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
5bd4f169 | 1984 | break; |
411e1bfb | 1985 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
5bd4f169 | 1986 | break; |
411e1bfb | 1987 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
5bd4f169 | 1988 | break; |
411e1bfb | 1989 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
5bd4f169 | 1990 | break; |
411e1bfb | 1991 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
5bd4f169 | 1992 | break; |
411e1bfb | 1993 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
5bd4f169 | 1994 | break; |
411e1bfb | 1995 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
5bd4f169 | 1996 | break; |
411e1bfb | 1997 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
5bd4f169 | 1998 | break; |
411e1bfb | 1999 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
5bd4f169 | 2000 | break; |
411e1bfb | 2001 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
5bd4f169 | 2002 | break; |
411e1bfb | 2003 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
5bd4f169 | 2004 | break; |
411e1bfb | 2005 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
5bd4f169 | 2006 | break; |
411e1bfb | 2007 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
5bd4f169 | 2008 | break; |
411e1bfb | 2009 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
5bd4f169 | 2010 | break; |
411e1bfb | 2011 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
5bd4f169 | 2012 | break; |
411e1bfb | 2013 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
5bd4f169 | 2014 | break; |
411e1bfb AM |
2015 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
2016 | break; | |
2017 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; | |
2018 | break; | |
2019 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; | |
2020 | break; | |
2021 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; | |
2022 | break; | |
2023 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; | |
2024 | break; | |
2025 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; | |
2026 | break; | |
2027 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; | |
2028 | break; | |
2029 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; | |
2030 | break; | |
2031 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; | |
2032 | break; | |
2033 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; | |
2034 | break; | |
2035 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; | |
2036 | break; | |
2037 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; | |
2038 | break; | |
2039 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; | |
2040 | break; | |
2041 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; | |
2042 | break; | |
2043 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; | |
2044 | break; | |
2045 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; | |
2046 | break; | |
2047 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; | |
2048 | break; | |
2049 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; | |
2050 | break; | |
2051 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; | |
2052 | break; | |
2053 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; | |
2054 | break; | |
2055 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; | |
2056 | break; | |
2057 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; | |
2058 | break; | |
2059 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; | |
2060 | break; | |
2061 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; | |
2062 | break; | |
2063 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; | |
2064 | break; | |
2065 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; | |
2066 | break; | |
2067 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; | |
2068 | break; | |
2069 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; | |
2070 | break; | |
2071 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; | |
2072 | break; | |
2073 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; | |
2074 | break; | |
2075 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; | |
2076 | break; | |
2077 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; | |
2078 | break; | |
2079 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; | |
2080 | break; | |
2081 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; | |
2082 | break; | |
2083 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; | |
5bd4f169 AM |
2084 | break; |
2085 | } | |
2086 | ||
4ce794b7 | 2087 | return ppc64_elf_howto_table[r]; |
5bd4f169 AM |
2088 | }; |
2089 | ||
2090 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
2091 | ||
2092 | static void | |
4ce794b7 AM |
2093 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
2094 | Elf_Internal_Rela *dst) | |
5bd4f169 | 2095 | { |
65f38f15 AM |
2096 | unsigned int type; |
2097 | ||
ef60b7ff | 2098 | /* Initialize howto table if needed. */ |
5bd4f169 | 2099 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
2100 | ppc_howto_init (); |
2101 | ||
65f38f15 AM |
2102 | type = ELF64_R_TYPE (dst->r_info); |
2103 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
2104 | / sizeof (ppc64_elf_howto_table[0]))); | |
2105 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
2106 | } |
2107 | ||
04c9666a | 2108 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
2109 | |
2110 | static bfd_reloc_status_type | |
4ce794b7 AM |
2111 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2112 | void *data, asection *input_section, | |
2113 | bfd *output_bfd, char **error_message) | |
5bd4f169 | 2114 | { |
805fc799 AM |
2115 | /* If this is a relocatable link (output_bfd test tells us), just |
2116 | call the generic function. Any adjustment will be done at final | |
2117 | link time. */ | |
2118 | if (output_bfd != NULL) | |
cedb70c5 | 2119 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2120 | input_section, output_bfd, error_message); |
2121 | ||
2122 | /* Adjust the addend for sign extension of the low 16 bits. | |
2123 | We won't actually be using the low 16 bits, so trashing them | |
2124 | doesn't matter. */ | |
2125 | reloc_entry->addend += 0x8000; | |
2126 | return bfd_reloc_continue; | |
2127 | } | |
5bd4f169 | 2128 | |
805fc799 | 2129 | static bfd_reloc_status_type |
4ce794b7 AM |
2130 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2131 | void *data, asection *input_section, | |
2132 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2133 | { |
2134 | long insn; | |
04c9666a | 2135 | enum elf_ppc64_reloc_type r_type; |
805fc799 AM |
2136 | bfd_size_type octets; |
2137 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ | |
b34976b6 | 2138 | bfd_boolean is_power4 = FALSE; |
805fc799 AM |
2139 | |
2140 | /* If this is a relocatable link (output_bfd test tells us), just | |
2141 | call the generic function. Any adjustment will be done at final | |
2142 | link time. */ | |
5bd4f169 | 2143 | if (output_bfd != NULL) |
cedb70c5 | 2144 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2145 | input_section, output_bfd, error_message); |
2146 | ||
2147 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2148 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); | |
2149 | insn &= ~(0x01 << 21); | |
4ce794b7 | 2150 | r_type = reloc_entry->howto->type; |
805fc799 AM |
2151 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
2152 | || r_type == R_PPC64_REL14_BRTAKEN) | |
cedb70c5 | 2153 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
805fc799 AM |
2154 | |
2155 | if (is_power4) | |
5bd4f169 | 2156 | { |
805fc799 AM |
2157 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
2158 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
2159 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
2160 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
2161 | insn |= 0x02 << 21; | |
2162 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
2163 | insn |= 0x08 << 21; | |
2164 | else | |
2165 | return bfd_reloc_continue; | |
5bd4f169 | 2166 | } |
805fc799 AM |
2167 | else |
2168 | { | |
2169 | bfd_vma target = 0; | |
2170 | bfd_vma from; | |
5bd4f169 | 2171 | |
805fc799 AM |
2172 | if (!bfd_is_com_section (symbol->section)) |
2173 | target = symbol->value; | |
2174 | target += symbol->section->output_section->vma; | |
2175 | target += symbol->section->output_offset; | |
2176 | target += reloc_entry->addend; | |
5bd4f169 | 2177 | |
805fc799 AM |
2178 | from = (reloc_entry->address |
2179 | + input_section->output_offset | |
2180 | + input_section->output_section->vma); | |
5bd4f169 | 2181 | |
805fc799 AM |
2182 | /* Invert 'y' bit if not the default. */ |
2183 | if ((bfd_signed_vma) (target - from) < 0) | |
2184 | insn ^= 0x01 << 21; | |
2185 | } | |
4ce794b7 | 2186 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
805fc799 AM |
2187 | return bfd_reloc_continue; |
2188 | } | |
5bd4f169 | 2189 | |
805fc799 | 2190 | static bfd_reloc_status_type |
4ce794b7 AM |
2191 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2192 | void *data, asection *input_section, | |
2193 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2194 | { |
2195 | /* If this is a relocatable link (output_bfd test tells us), just | |
2196 | call the generic function. Any adjustment will be done at final | |
2197 | link time. */ | |
2198 | if (output_bfd != NULL) | |
cedb70c5 | 2199 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 | 2200 | input_section, output_bfd, error_message); |
5bd4f169 | 2201 | |
805fc799 AM |
2202 | /* Subtract the symbol section base address. */ |
2203 | reloc_entry->addend -= symbol->section->output_section->vma; | |
5bd4f169 AM |
2204 | return bfd_reloc_continue; |
2205 | } | |
2206 | ||
805fc799 | 2207 | static bfd_reloc_status_type |
4ce794b7 AM |
2208 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2209 | void *data, asection *input_section, | |
2210 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2211 | { |
2212 | /* If this is a relocatable link (output_bfd test tells us), just | |
2213 | call the generic function. Any adjustment will be done at final | |
2214 | link time. */ | |
2215 | if (output_bfd != NULL) | |
cedb70c5 | 2216 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2217 | input_section, output_bfd, error_message); |
2218 | ||
2219 | /* Subtract the symbol section base address. */ | |
2220 | reloc_entry->addend -= symbol->section->output_section->vma; | |
2221 | ||
2222 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2223 | reloc_entry->addend += 0x8000; | |
2224 | return bfd_reloc_continue; | |
2225 | } | |
2226 | ||
2227 | static bfd_reloc_status_type | |
4ce794b7 AM |
2228 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2229 | void *data, asection *input_section, | |
2230 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2231 | { |
2232 | bfd_vma TOCstart; | |
2233 | ||
2234 | /* If this is a relocatable link (output_bfd test tells us), just | |
2235 | call the generic function. Any adjustment will be done at final | |
2236 | link time. */ | |
2237 | if (output_bfd != NULL) | |
cedb70c5 | 2238 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2239 | input_section, output_bfd, error_message); |
2240 | ||
2241 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2242 | if (TOCstart == 0) | |
2243 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2244 | ||
2245 | /* Subtract the TOC base address. */ | |
2246 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2247 | return bfd_reloc_continue; | |
2248 | } | |
2249 | ||
2250 | static bfd_reloc_status_type | |
4ce794b7 AM |
2251 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2252 | void *data, asection *input_section, | |
2253 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2254 | { |
2255 | bfd_vma TOCstart; | |
2256 | ||
2257 | /* If this is a relocatable link (output_bfd test tells us), just | |
2258 | call the generic function. Any adjustment will be done at final | |
2259 | link time. */ | |
2260 | if (output_bfd != NULL) | |
cedb70c5 | 2261 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2262 | input_section, output_bfd, error_message); |
2263 | ||
2264 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2265 | if (TOCstart == 0) | |
2266 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2267 | ||
2268 | /* Subtract the TOC base address. */ | |
2269 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; | |
2270 | ||
2271 | /* Adjust the addend for sign extension of the low 16 bits. */ | |
2272 | reloc_entry->addend += 0x8000; | |
2273 | return bfd_reloc_continue; | |
2274 | } | |
2275 | ||
2276 | static bfd_reloc_status_type | |
4ce794b7 AM |
2277 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2278 | void *data, asection *input_section, | |
2279 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2280 | { |
2281 | bfd_vma TOCstart; | |
2282 | bfd_size_type octets; | |
2283 | ||
2284 | /* If this is a relocatable link (output_bfd test tells us), just | |
2285 | call the generic function. Any adjustment will be done at final | |
2286 | link time. */ | |
2287 | if (output_bfd != NULL) | |
cedb70c5 | 2288 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2289 | input_section, output_bfd, error_message); |
2290 | ||
2291 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); | |
2292 | if (TOCstart == 0) | |
2293 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); | |
2294 | ||
2295 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); | |
2296 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); | |
2297 | return bfd_reloc_ok; | |
2298 | } | |
2299 | ||
2300 | static bfd_reloc_status_type | |
4ce794b7 AM |
2301 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2302 | void *data, asection *input_section, | |
2303 | bfd *output_bfd, char **error_message) | |
805fc799 AM |
2304 | { |
2305 | /* If this is a relocatable link (output_bfd test tells us), just | |
2306 | call the generic function. Any adjustment will be done at final | |
2307 | link time. */ | |
2308 | if (output_bfd != NULL) | |
cedb70c5 | 2309 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
805fc799 AM |
2310 | input_section, output_bfd, error_message); |
2311 | ||
2312 | if (error_message != NULL) | |
2313 | { | |
2314 | static char buf[60]; | |
2315 | sprintf (buf, "generic linker can't handle %s", | |
2316 | reloc_entry->howto->name); | |
2317 | *error_message = buf; | |
2318 | } | |
2319 | return bfd_reloc_dangerous; | |
2320 | } | |
2321 | ||
e717da7e AM |
2322 | struct ppc64_elf_obj_tdata |
2323 | { | |
2324 | struct elf_obj_tdata elf; | |
2325 | ||
2326 | /* Shortcuts to dynamic linker sections. */ | |
2327 | asection *got; | |
2328 | asection *relgot; | |
2329 | ||
2330 | /* TLS local dynamic got entry handling. Suppose for multiple GOT | |
2331 | sections means we potentially need one of these for each input bfd. */ | |
2332 | union { | |
2333 | bfd_signed_vma refcount; | |
2334 | bfd_vma offset; | |
2335 | } tlsld_got; | |
2336 | }; | |
2337 | ||
2338 | #define ppc64_elf_tdata(bfd) \ | |
2339 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) | |
2340 | ||
2341 | #define ppc64_tlsld_got(bfd) \ | |
2342 | (&ppc64_elf_tdata (bfd)->tlsld_got) | |
2343 | ||
2344 | /* Override the generic function because we store some extras. */ | |
2345 | ||
2346 | static bfd_boolean | |
2347 | ppc64_elf_mkobject (bfd *abfd) | |
2348 | { | |
2349 | bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); | |
2350 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2351 | if (abfd->tdata.any == NULL) | |
2352 | return FALSE; | |
2353 | return TRUE; | |
2354 | } | |
2355 | ||
feee612b AM |
2356 | /* Fix bad default arch selected for a 64 bit input bfd when the |
2357 | default is 32 bit. */ | |
2358 | ||
b34976b6 | 2359 | static bfd_boolean |
4ce794b7 | 2360 | ppc64_elf_object_p (bfd *abfd) |
feee612b AM |
2361 | { |
2362 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) | |
2363 | { | |
2364 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2365 | ||
2366 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
2367 | { | |
2368 | /* Relies on arch after 32 bit default being 64 bit default. */ | |
2369 | abfd->arch_info = abfd->arch_info->next; | |
2370 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); | |
2371 | } | |
2372 | } | |
b34976b6 | 2373 | return TRUE; |
feee612b AM |
2374 | } |
2375 | ||
5bd4f169 AM |
2376 | /* Merge backend specific data from an object file to the output |
2377 | object file when linking. */ | |
2f6d9989 | 2378 | |
b34976b6 | 2379 | static bfd_boolean |
4ce794b7 | 2380 | ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
5bd4f169 | 2381 | { |
5bd4f169 AM |
2382 | /* Check if we have the same endianess. */ |
2383 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
87e226ce | 2384 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
5bd4f169 AM |
2385 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
2386 | { | |
2387 | const char *msg; | |
2388 | ||
2389 | if (bfd_big_endian (ibfd)) | |
4ce794b7 AM |
2390 | msg = _("%s: compiled for a big endian system " |
2391 | "and target is little endian"); | |
5bd4f169 | 2392 | else |
4ce794b7 AM |
2393 | msg = _("%s: compiled for a little endian system " |
2394 | "and target is big endian"); | |
5bd4f169 | 2395 | |
8f615d07 | 2396 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
5bd4f169 AM |
2397 | |
2398 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 2399 | return FALSE; |
5bd4f169 AM |
2400 | } |
2401 | ||
b34976b6 | 2402 | return TRUE; |
5bd4f169 | 2403 | } |
f0abc2a1 | 2404 | |
5d35169e AM |
2405 | /* Add extra PPC sections. */ |
2406 | ||
2407 | static struct bfd_elf_special_section const ppc64_elf_special_sections[]= | |
2408 | { | |
2409 | { ".sdata", 0, NULL, 0, | |
2410 | SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2411 | { ".sbss", 0, NULL, 0, | |
2412 | SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2413 | { ".plt", 0, NULL, 0, | |
2414 | SHT_NOBITS, 0 }, | |
2415 | { ".toc", 0, NULL, 0, | |
2416 | SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2417 | { ".toc1", 0, NULL, 0, | |
2418 | SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
2419 | { ".tocbss", 0, NULL, 0, | |
2420 | SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
2421 | { NULL, 0, NULL, 0, | |
2422 | 0, 0 } | |
2423 | }; | |
2424 | ||
f0abc2a1 AM |
2425 | struct _ppc64_elf_section_data |
2426 | { | |
2427 | struct bfd_elf_section_data elf; | |
411e1bfb AM |
2428 | |
2429 | /* An array with one entry for each opd function descriptor. */ | |
f0abc2a1 AM |
2430 | union |
2431 | { | |
411e1bfb | 2432 | /* Points to the function code section for local opd entries. */ |
f0abc2a1 | 2433 | asection **func_sec; |
411e1bfb | 2434 | /* After editing .opd, adjust references to opd local syms. */ |
f0abc2a1 AM |
2435 | long *adjust; |
2436 | } opd; | |
411e1bfb AM |
2437 | |
2438 | /* An array for toc sections, indexed by offset/8. | |
2439 | Specifies the relocation symbol index used at a given toc offset. */ | |
2440 | unsigned *t_symndx; | |
f0abc2a1 AM |
2441 | }; |
2442 | ||
2443 | #define ppc64_elf_section_data(sec) \ | |
411e1bfb | 2444 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
f0abc2a1 AM |
2445 | |
2446 | static bfd_boolean | |
4ce794b7 | 2447 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
f0abc2a1 AM |
2448 | { |
2449 | struct _ppc64_elf_section_data *sdata; | |
2450 | bfd_size_type amt = sizeof (*sdata); | |
2451 | ||
4ce794b7 | 2452 | sdata = bfd_zalloc (abfd, amt); |
f0abc2a1 AM |
2453 | if (sdata == NULL) |
2454 | return FALSE; | |
4ce794b7 | 2455 | sec->used_by_bfd = sdata; |
f0abc2a1 AM |
2456 | |
2457 | return _bfd_elf_new_section_hook (abfd, sec); | |
2458 | } | |
5bd4f169 | 2459 | \f |
65f38f15 AM |
2460 | /* The following functions are specific to the ELF linker, while |
2461 | functions above are used generally. Those named ppc64_elf_* are | |
2462 | called by the main ELF linker code. They appear in this file more | |
2463 | or less in the order in which they are called. eg. | |
2464 | ppc64_elf_check_relocs is called early in the link process, | |
2465 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
e86ce104 AM |
2466 | called. |
2467 | ||
2468 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that | |
2469 | functions have both a function code symbol and a function descriptor | |
2470 | symbol. A call to foo in a relocatable object file looks like: | |
2471 | ||
2472 | . .text | |
2473 | . x: | |
2474 | . bl .foo | |
2475 | . nop | |
2476 | ||
2477 | The function definition in another object file might be: | |
2478 | ||
2479 | . .section .opd | |
2480 | . foo: .quad .foo | |
2481 | . .quad .TOC.@tocbase | |
2482 | . .quad 0 | |
2483 | . | |
2484 | . .text | |
2485 | . .foo: blr | |
2486 | ||
2487 | When the linker resolves the call during a static link, the branch | |
2488 | unsurprisingly just goes to .foo and the .opd information is unused. | |
2489 | If the function definition is in a shared library, things are a little | |
2490 | different: The call goes via a plt call stub, the opd information gets | |
2491 | copied to the plt, and the linker patches the nop. | |
2492 | ||
2493 | . x: | |
2494 | . bl .foo_stub | |
2495 | . ld 2,40(1) | |
2496 | . | |
2497 | . | |
2498 | . .foo_stub: | |
2499 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub | |
411e1bfb | 2500 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
e86ce104 AM |
2501 | . std 2,40(1) # this is the general idea |
2502 | . ld 11,0(12) | |
2503 | . ld 2,8(12) | |
2504 | . mtctr 11 | |
2505 | . ld 11,16(12) | |
2506 | . bctr | |
2507 | . | |
2508 | . .section .plt | |
2509 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) | |
2510 | ||
2511 | The "reloc ()" notation is supposed to indicate that the linker emits | |
2512 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd | |
2513 | copying. | |
2514 | ||
2515 | What are the difficulties here? Well, firstly, the relocations | |
2516 | examined by the linker in check_relocs are against the function code | |
2517 | sym .foo, while the dynamic relocation in the plt is emitted against | |
2518 | the function descriptor symbol, foo. Somewhere along the line, we need | |
2519 | to carefully copy dynamic link information from one symbol to the other. | |
2520 | Secondly, the generic part of the elf linker will make .foo a dynamic | |
2521 | symbol as is normal for most other backends. We need foo dynamic | |
2522 | instead, at least for an application final link. However, when | |
2523 | creating a shared library containing foo, we need to have both symbols | |
2524 | dynamic so that references to .foo are satisfied during the early | |
2525 | stages of linking. Otherwise the linker might decide to pull in a | |
41bd81ab | 2526 | definition from some other object, eg. a static library. */ |
65f38f15 AM |
2527 | |
2528 | /* The linker needs to keep track of the number of relocs that it | |
2529 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
2530 | This is so that it can later discard them if they are found to be | |
2531 | unnecessary. We store the information in a field extending the | |
2532 | regular ELF linker hash table. */ | |
2533 | ||
2534 | struct ppc_dyn_relocs | |
2535 | { | |
2536 | struct ppc_dyn_relocs *next; | |
2537 | ||
2538 | /* The input section of the reloc. */ | |
2539 | asection *sec; | |
2540 | ||
2541 | /* Total number of relocs copied for the input section. */ | |
2542 | bfd_size_type count; | |
2543 | ||
2544 | /* Number of pc-relative relocs copied for the input section. */ | |
2545 | bfd_size_type pc_count; | |
2546 | }; | |
2547 | ||
411e1bfb AM |
2548 | /* Track GOT entries needed for a given symbol. We might need more |
2549 | than one got entry per symbol. */ | |
2550 | struct got_entry | |
2551 | { | |
2552 | struct got_entry *next; | |
2553 | ||
e7b938ca | 2554 | /* The symbol addend that we'll be placing in the GOT. */ |
411e1bfb AM |
2555 | bfd_vma addend; |
2556 | ||
e717da7e AM |
2557 | /* Unlike other ELF targets, we use separate GOT entries for the same |
2558 | symbol referenced from different input files. This is to support | |
2559 | automatic multiple TOC/GOT sections, where the TOC base can vary | |
2560 | from one input file to another. | |
2561 | ||
2562 | Point to the BFD owning this GOT entry. */ | |
2563 | bfd *owner; | |
2564 | ||
2565 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, | |
2566 | TLS_TPREL or TLS_DTPREL for tls entries. */ | |
2567 | char tls_type; | |
2568 | ||
e7b938ca | 2569 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ |
411e1bfb AM |
2570 | union |
2571 | { | |
2572 | bfd_signed_vma refcount; | |
2573 | bfd_vma offset; | |
2574 | } got; | |
411e1bfb AM |
2575 | }; |
2576 | ||
2577 | /* The same for PLT. */ | |
2578 | struct plt_entry | |
2579 | { | |
2580 | struct plt_entry *next; | |
2581 | ||
2582 | bfd_vma addend; | |
2583 | ||
2584 | union | |
2585 | { | |
2586 | bfd_signed_vma refcount; | |
2587 | bfd_vma offset; | |
2588 | } plt; | |
2589 | }; | |
2590 | ||
65f38f15 | 2591 | /* Of those relocs that might be copied as dynamic relocs, this macro |
58ac9f71 AM |
2592 | selects those that must be copied when linking a shared library, |
2593 | even when the symbol is local. */ | |
65f38f15 | 2594 | |
411e1bfb | 2595 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
805fc799 AM |
2596 | ((RTYPE) != R_PPC64_REL32 \ |
2597 | && (RTYPE) != R_PPC64_REL64 \ | |
04c9666a | 2598 | && (RTYPE) != R_PPC64_REL30) |
65f38f15 | 2599 | |
f4656909 AM |
2600 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2601 | copying dynamic variables from a shared lib into an app's dynbss | |
2602 | section, and instead use a dynamic relocation to point into the | |
5d35169e AM |
2603 | shared lib. With code that gcc generates, it's vital that this be |
2604 | enabled; In the PowerPC64 ABI, the address of a function is actually | |
2605 | the address of a function descriptor, which resides in the .opd | |
2606 | section. gcc uses the descriptor directly rather than going via the | |
2607 | GOT as some other ABI's do, which means that initialized function | |
2608 | pointers must reference the descriptor. Thus, a function pointer | |
2609 | initialized to the address of a function in a shared library will | |
2610 | either require a copy reloc, or a dynamic reloc. Using a copy reloc | |
2611 | redefines the function desctriptor symbol to point to the copy. This | |
2612 | presents a problem as a plt entry for that function is also | |
2613 | initialized from the function descriptor symbol and the copy reloc | |
2614 | may not be initialized first. */ | |
a23b6845 | 2615 | #define ELIMINATE_COPY_RELOCS 1 |
f4656909 | 2616 | |
721956f4 AM |
2617 | /* Section name for stubs is the associated section name plus this |
2618 | string. */ | |
2619 | #define STUB_SUFFIX ".stub" | |
2620 | ||
2621 | /* Linker stubs. | |
2622 | ppc_stub_long_branch: | |
2623 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its | |
2624 | destination, but a 24 bit branch in a stub section will reach. | |
2625 | . b dest | |
2626 | ||
2627 | ppc_stub_plt_branch: | |
2628 | Similar to the above, but a 24 bit branch in the stub section won't | |
2629 | reach its destination. | |
87e226ce AM |
2630 | . addis %r12,%r2,xxx@toc@ha |
2631 | . ld %r11,xxx@toc@l(%r12) | |
721956f4 AM |
2632 | . mtctr %r11 |
2633 | . bctr | |
2634 | ||
2635 | ppc_stub_plt_call: | |
2636 | Used to call a function in a shared library. | |
87e226ce | 2637 | . addis %r12,%r2,xxx@toc@ha |
721956f4 | 2638 | . std %r2,40(%r1) |
87e226ce AM |
2639 | . ld %r11,xxx+0@toc@l(%r12) |
2640 | . ld %r2,xxx+8@toc@l(%r12) | |
721956f4 | 2641 | . mtctr %r11 |
87e226ce | 2642 | . ld %r11,xxx+16@toc@l(%r12) |
721956f4 | 2643 | . bctr |
ad8e1ba5 AM |
2644 | |
2645 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional | |
2646 | code to adjust the value and save r2 to support multiple toc sections. | |
2647 | A ppc_stub_long_branch with an r2 offset looks like: | |
2648 | . std %r2,40(%r1) | |
2649 | . addis %r2,%r2,off@ha | |
2650 | . addi %r2,%r2,off@l | |
2651 | . b dest | |
2652 | ||
2653 | A ppc_stub_plt_branch with an r2 offset looks like: | |
2654 | . std %r2,40(%r1) | |
2655 | . addis %r12,%r2,xxx@toc@ha | |
2656 | . ld %r11,xxx@toc@l(%r12) | |
2657 | . addis %r2,%r2,off@ha | |
2658 | . addi %r2,%r2,off@l | |
2659 | . mtctr %r11 | |
2660 | . bctr | |
721956f4 AM |
2661 | */ |
2662 | ||
2663 | enum ppc_stub_type { | |
2664 | ppc_stub_none, | |
2665 | ppc_stub_long_branch, | |
ad8e1ba5 | 2666 | ppc_stub_long_branch_r2off, |
721956f4 | 2667 | ppc_stub_plt_branch, |
ad8e1ba5 | 2668 | ppc_stub_plt_branch_r2off, |
721956f4 AM |
2669 | ppc_stub_plt_call |
2670 | }; | |
2671 | ||
2672 | struct ppc_stub_hash_entry { | |
2673 | ||
2674 | /* Base hash table entry structure. */ | |
2675 | struct bfd_hash_entry root; | |
2676 | ||
ad8e1ba5 AM |
2677 | enum ppc_stub_type stub_type; |
2678 | ||
721956f4 AM |
2679 | /* The stub section. */ |
2680 | asection *stub_sec; | |
2681 | ||
2682 | /* Offset within stub_sec of the beginning of this stub. */ | |
2683 | bfd_vma stub_offset; | |
2684 | ||
2685 | /* Given the symbol's value and its section we can determine its final | |
2686 | value when building the stubs (so the stub knows where to jump. */ | |
2687 | bfd_vma target_value; | |
2688 | asection *target_section; | |
2689 | ||
721956f4 AM |
2690 | /* The symbol table entry, if any, that this was derived from. */ |
2691 | struct ppc_link_hash_entry *h; | |
2692 | ||
411e1bfb AM |
2693 | /* And the reloc addend that this was derived from. */ |
2694 | bfd_vma addend; | |
2695 | ||
721956f4 AM |
2696 | /* Where this stub is being called from, or, in the case of combined |
2697 | stub sections, the first input section in the group. */ | |
2698 | asection *id_sec; | |
2699 | }; | |
2700 | ||
2701 | struct ppc_branch_hash_entry { | |
2702 | ||
2703 | /* Base hash table entry structure. */ | |
2704 | struct bfd_hash_entry root; | |
2705 | ||
2706 | /* Offset within .branch_lt. */ | |
2707 | unsigned int offset; | |
2708 | ||
2709 | /* Generation marker. */ | |
2710 | unsigned int iter; | |
2711 | }; | |
65f38f15 AM |
2712 | |
2713 | struct ppc_link_hash_entry | |
2714 | { | |
2715 | struct elf_link_hash_entry elf; | |
2716 | ||
721956f4 AM |
2717 | /* A pointer to the most recently used stub hash entry against this |
2718 | symbol. */ | |
2719 | struct ppc_stub_hash_entry *stub_cache; | |
2720 | ||
65f38f15 AM |
2721 | /* Track dynamic relocs copied for this symbol. */ |
2722 | struct ppc_dyn_relocs *dyn_relocs; | |
e86ce104 | 2723 | |
721956f4 AM |
2724 | /* Link between function code and descriptor symbols. */ |
2725 | struct elf_link_hash_entry *oh; | |
2726 | ||
e86ce104 AM |
2727 | /* Flag function code and descriptor symbols. */ |
2728 | unsigned int is_func:1; | |
2729 | unsigned int is_func_descriptor:1; | |
1e2f5b6e | 2730 | unsigned int is_entry:1; |
411e1bfb AM |
2731 | |
2732 | /* Contexts in which symbol is used in the GOT (or TOC). | |
e7b938ca AM |
2733 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
2734 | corresponding relocs are encountered during check_relocs. | |
2735 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
2736 | indicate the corresponding GOT entry type is not needed. | |
2737 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into | |
2738 | a TPREL one. We use a separate flag rather than setting TPREL | |
2739 | just for convenience in distinguishing the two cases. */ | |
2740 | #define TLS_GD 1 /* GD reloc. */ | |
2741 | #define TLS_LD 2 /* LD reloc. */ | |
2742 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
2743 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
2744 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
2745 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ | |
2746 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ | |
2747 | char tls_mask; | |
65f38f15 AM |
2748 | }; |
2749 | ||
2750 | /* ppc64 ELF linker hash table. */ | |
2751 | ||
2752 | struct ppc_link_hash_table | |
2753 | { | |
2754 | struct elf_link_hash_table elf; | |
2755 | ||
721956f4 AM |
2756 | /* The stub hash table. */ |
2757 | struct bfd_hash_table stub_hash_table; | |
2758 | ||
2759 | /* Another hash table for plt_branch stubs. */ | |
2760 | struct bfd_hash_table branch_hash_table; | |
2761 | ||
2762 | /* Linker stub bfd. */ | |
2763 | bfd *stub_bfd; | |
2764 | ||
2765 | /* Linker call-backs. */ | |
4ce794b7 AM |
2766 | asection * (*add_stub_section) (const char *, asection *); |
2767 | void (*layout_sections_again) (void); | |
721956f4 AM |
2768 | |
2769 | /* Array to keep track of which stub sections have been created, and | |
2770 | information on stub grouping. */ | |
2771 | struct map_stub { | |
2772 | /* This is the section to which stubs in the group will be attached. */ | |
2773 | asection *link_sec; | |
2774 | /* The stub section. */ | |
2775 | asection *stub_sec; | |
ad8e1ba5 AM |
2776 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
2777 | bfd_vma toc_off; | |
721956f4 AM |
2778 | } *stub_group; |
2779 | ||
ad8e1ba5 AM |
2780 | /* Support for multiple toc sections. */ |
2781 | unsigned int no_multi_toc; | |
2782 | unsigned int multi_toc_needed; | |
2783 | ||
2784 | /* Temp used when calculating TOC pointers. */ | |
2785 | bfd_vma toc_curr; | |
2786 | ||
8f3bab57 AM |
2787 | /* Highest input section id. */ |
2788 | int top_id; | |
2789 | ||
734b6cf9 AM |
2790 | /* Highest output section index. */ |
2791 | int top_index; | |
2792 | ||
2793 | /* List of input sections for each output section. */ | |
2794 | asection **input_list; | |
721956f4 | 2795 | |
65f38f15 | 2796 | /* Short-cuts to get to dynamic linker sections. */ |
4ce794b7 | 2797 | asection *got; |
4ce794b7 AM |
2798 | asection *plt; |
2799 | asection *relplt; | |
2800 | asection *dynbss; | |
2801 | asection *relbss; | |
2802 | asection *glink; | |
82bd7b59 | 2803 | asection *sfpr; |
4ce794b7 AM |
2804 | asection *brlt; |
2805 | asection *relbrlt; | |
ec338859 | 2806 | |
411e1bfb AM |
2807 | /* Short-cut to first output tls section. */ |
2808 | asection *tls_sec; | |
2809 | ||
2810 | /* Shortcut to .__tls_get_addr. */ | |
2811 | struct elf_link_hash_entry *tls_get_addr; | |
2812 | ||
9b5ecbd0 AM |
2813 | /* Statistics. */ |
2814 | unsigned long stub_count[ppc_stub_plt_call]; | |
2815 | ||
ad8e1ba5 AM |
2816 | /* Set if we should emit symbols for stubs. */ |
2817 | unsigned int emit_stub_syms; | |
2818 | ||
5d1634d7 | 2819 | /* Set on error. */ |
721956f4 AM |
2820 | unsigned int stub_error; |
2821 | ||
2822 | /* Flag set when small branches are detected. Used to | |
2823 | select suitable defaults for the stub group size. */ | |
2824 | unsigned int has_14bit_branch; | |
2825 | ||
805fc799 AM |
2826 | /* Set if we detect a reference undefined weak symbol. */ |
2827 | unsigned int have_undefweak; | |
2828 | ||
721956f4 AM |
2829 | /* Incremented every time we size stubs. */ |
2830 | unsigned int stub_iteration; | |
5d1634d7 | 2831 | |
ec338859 AM |
2832 | /* Small local sym to section mapping cache. */ |
2833 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
2834 | }; |
2835 | ||
2836 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ | |
2837 | ||
2838 | #define ppc_hash_table(p) \ | |
2839 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
2840 | ||
721956f4 AM |
2841 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
2842 | ((struct ppc_stub_hash_entry *) \ | |
2843 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2844 | ||
2845 | #define ppc_branch_hash_lookup(table, string, create, copy) \ | |
2846 | ((struct ppc_branch_hash_entry *) \ | |
2847 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
2848 | ||
2849 | /* Create an entry in the stub hash table. */ | |
2850 | ||
2851 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2852 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2853 | struct bfd_hash_table *table, | |
2854 | const char *string) | |
721956f4 AM |
2855 | { |
2856 | /* Allocate the structure if it has not already been allocated by a | |
2857 | subclass. */ | |
2858 | if (entry == NULL) | |
2859 | { | |
2860 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); | |
2861 | if (entry == NULL) | |
2862 | return entry; | |
2863 | } | |
2864 | ||
2865 | /* Call the allocation method of the superclass. */ | |
2866 | entry = bfd_hash_newfunc (entry, table, string); | |
2867 | if (entry != NULL) | |
2868 | { | |
2869 | struct ppc_stub_hash_entry *eh; | |
2870 | ||
2871 | /* Initialize the local fields. */ | |
2872 | eh = (struct ppc_stub_hash_entry *) entry; | |
ad8e1ba5 | 2873 | eh->stub_type = ppc_stub_none; |
721956f4 AM |
2874 | eh->stub_sec = NULL; |
2875 | eh->stub_offset = 0; | |
2876 | eh->target_value = 0; | |
2877 | eh->target_section = NULL; | |
721956f4 AM |
2878 | eh->h = NULL; |
2879 | eh->id_sec = NULL; | |
2880 | } | |
2881 | ||
2882 | return entry; | |
2883 | } | |
2884 | ||
2885 | /* Create an entry in the branch hash table. */ | |
2886 | ||
2887 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2888 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
2889 | struct bfd_hash_table *table, | |
2890 | const char *string) | |
721956f4 AM |
2891 | { |
2892 | /* Allocate the structure if it has not already been allocated by a | |
2893 | subclass. */ | |
2894 | if (entry == NULL) | |
2895 | { | |
2896 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); | |
2897 | if (entry == NULL) | |
2898 | return entry; | |
2899 | } | |
2900 | ||
2901 | /* Call the allocation method of the superclass. */ | |
2902 | entry = bfd_hash_newfunc (entry, table, string); | |
2903 | if (entry != NULL) | |
2904 | { | |
2905 | struct ppc_branch_hash_entry *eh; | |
2906 | ||
2907 | /* Initialize the local fields. */ | |
2908 | eh = (struct ppc_branch_hash_entry *) entry; | |
2909 | eh->offset = 0; | |
2910 | eh->iter = 0; | |
2911 | } | |
2912 | ||
2913 | return entry; | |
2914 | } | |
2915 | ||
65f38f15 AM |
2916 | /* Create an entry in a ppc64 ELF linker hash table. */ |
2917 | ||
2918 | static struct bfd_hash_entry * | |
4ce794b7 AM |
2919 | link_hash_newfunc (struct bfd_hash_entry *entry, |
2920 | struct bfd_hash_table *table, | |
2921 | const char *string) | |
65f38f15 AM |
2922 | { |
2923 | /* Allocate the structure if it has not already been allocated by a | |
2924 | subclass. */ | |
2925 | if (entry == NULL) | |
2926 | { | |
2927 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
2928 | if (entry == NULL) | |
2929 | return entry; | |
2930 | } | |
2931 | ||
2932 | /* Call the allocation method of the superclass. */ | |
2933 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2934 | if (entry != NULL) | |
2935 | { | |
2936 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
2937 | ||
721956f4 | 2938 | eh->stub_cache = NULL; |
65f38f15 | 2939 | eh->dyn_relocs = NULL; |
721956f4 | 2940 | eh->oh = NULL; |
e86ce104 AM |
2941 | eh->is_func = 0; |
2942 | eh->is_func_descriptor = 0; | |
1e2f5b6e | 2943 | eh->is_entry = 0; |
e7b938ca | 2944 | eh->tls_mask = 0; |
65f38f15 AM |
2945 | } |
2946 | ||
2947 | return entry; | |
2948 | } | |
2949 | ||
2950 | /* Create a ppc64 ELF linker hash table. */ | |
2951 | ||
2952 | static struct bfd_link_hash_table * | |
4ce794b7 | 2953 | ppc64_elf_link_hash_table_create (bfd *abfd) |
65f38f15 AM |
2954 | { |
2955 | struct ppc_link_hash_table *htab; | |
2956 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
2957 | ||
4ce794b7 | 2958 | htab = bfd_zmalloc (amt); |
65f38f15 AM |
2959 | if (htab == NULL) |
2960 | return NULL; | |
2961 | ||
2962 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
2963 | { | |
e2d34d7d | 2964 | free (htab); |
65f38f15 AM |
2965 | return NULL; |
2966 | } | |
2967 | ||
721956f4 AM |
2968 | /* Init the stub hash table too. */ |
2969 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) | |
2970 | return NULL; | |
2971 | ||
2972 | /* And the branch hash table. */ | |
2973 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) | |
2974 | return NULL; | |
2975 | ||
3254fd24 AM |
2976 | /* Initializing two fields of the union is just cosmetic. We really |
2977 | only care about glist, but when compiled on a 32-bit host the | |
2978 | bfd_vma fields are larger. Setting the bfd_vma to zero makes | |
2979 | debugger inspection of these fields look nicer. */ | |
2980 | htab->elf.init_refcount.refcount = 0; | |
2981 | htab->elf.init_refcount.glist = NULL; | |
2982 | htab->elf.init_offset.offset = 0; | |
2983 | htab->elf.init_offset.glist = NULL; | |
2984 | ||
65f38f15 AM |
2985 | return &htab->elf.root; |
2986 | } | |
2987 | ||
721956f4 AM |
2988 | /* Free the derived linker hash table. */ |
2989 | ||
2990 | static void | |
4ce794b7 | 2991 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
721956f4 AM |
2992 | { |
2993 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; | |
2994 | ||
2995 | bfd_hash_table_free (&ret->stub_hash_table); | |
2996 | bfd_hash_table_free (&ret->branch_hash_table); | |
2997 | _bfd_generic_link_hash_table_free (hash); | |
2998 | } | |
2999 | ||
e717da7e AM |
3000 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
3001 | ||
3002 | void | |
3003 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) | |
3004 | { | |
3005 | struct ppc_link_hash_table *htab; | |
3006 | ||
3007 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; | |
3008 | ||
3009 | /* Always hook our dynamic sections into the first bfd, which is the | |
3010 | linker created stub bfd. This ensures that the GOT header is at | |
3011 | the start of the output TOC section. */ | |
3012 | htab = ppc_hash_table (info); | |
3013 | htab->stub_bfd = abfd; | |
3014 | htab->elf.dynobj = abfd; | |
3015 | } | |
3016 | ||
721956f4 AM |
3017 | /* Build a name for an entry in the stub hash table. */ |
3018 | ||
3019 | static char * | |
4ce794b7 AM |
3020 | ppc_stub_name (const asection *input_section, |
3021 | const asection *sym_sec, | |
3022 | const struct ppc_link_hash_entry *h, | |
3023 | const Elf_Internal_Rela *rel) | |
721956f4 AM |
3024 | { |
3025 | char *stub_name; | |
3026 | bfd_size_type len; | |
3027 | ||
3028 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 | |
3029 | offsets from a sym as a branch target? In fact, we could | |
3030 | probably assume the addend is always zero. */ | |
3031 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); | |
3032 | ||
3033 | if (h) | |
3034 | { | |
3035 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; | |
3036 | stub_name = bfd_malloc (len); | |
3037 | if (stub_name != NULL) | |
3038 | { | |
97b639ba | 3039 | sprintf (stub_name, "%08x.%s+%x", |
721956f4 AM |
3040 | input_section->id & 0xffffffff, |
3041 | h->elf.root.root.string, | |
3042 | (int) rel->r_addend & 0xffffffff); | |
3043 | } | |
3044 | } | |
3045 | else | |
3046 | { | |
ad8e1ba5 | 3047 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
721956f4 AM |
3048 | stub_name = bfd_malloc (len); |
3049 | if (stub_name != NULL) | |
3050 | { | |
97b639ba | 3051 | sprintf (stub_name, "%08x.%x:%x+%x", |
721956f4 AM |
3052 | input_section->id & 0xffffffff, |
3053 | sym_sec->id & 0xffffffff, | |
3054 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, | |
3055 | (int) rel->r_addend & 0xffffffff); | |
3056 | } | |
3057 | } | |
3058 | return stub_name; | |
3059 | } | |
3060 | ||
3061 | /* Look up an entry in the stub hash. Stub entries are cached because | |
3062 | creating the stub name takes a bit of time. */ | |
3063 | ||
3064 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3065 | ppc_get_stub_entry (const asection *input_section, |
3066 | const asection *sym_sec, | |
3067 | struct elf_link_hash_entry *hash, | |
3068 | const Elf_Internal_Rela *rel, | |
3069 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3070 | { |
3071 | struct ppc_stub_hash_entry *stub_entry; | |
3072 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; | |
3073 | const asection *id_sec; | |
3074 | ||
3075 | /* If this input section is part of a group of sections sharing one | |
3076 | stub section, then use the id of the first section in the group. | |
3077 | Stub names need to include a section id, as there may well be | |
3078 | more than one stub used to reach say, printf, and we need to | |
3079 | distinguish between them. */ | |
3080 | id_sec = htab->stub_group[input_section->id].link_sec; | |
3081 | ||
3082 | if (h != NULL && h->stub_cache != NULL | |
3083 | && h->stub_cache->h == h | |
3084 | && h->stub_cache->id_sec == id_sec) | |
3085 | { | |
3086 | stub_entry = h->stub_cache; | |
3087 | } | |
3088 | else | |
3089 | { | |
3090 | char *stub_name; | |
3091 | ||
3092 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); | |
3093 | if (stub_name == NULL) | |
3094 | return NULL; | |
3095 | ||
3096 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 3097 | stub_name, FALSE, FALSE); |
721956f4 AM |
3098 | if (h != NULL) |
3099 | h->stub_cache = stub_entry; | |
3100 | ||
3101 | free (stub_name); | |
3102 | } | |
3103 | ||
3104 | return stub_entry; | |
3105 | } | |
3106 | ||
3107 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
3108 | stub entry are initialised. */ | |
3109 | ||
3110 | static struct ppc_stub_hash_entry * | |
4ce794b7 AM |
3111 | ppc_add_stub (const char *stub_name, |
3112 | asection *section, | |
3113 | struct ppc_link_hash_table *htab) | |
721956f4 AM |
3114 | { |
3115 | asection *link_sec; | |
3116 | asection *stub_sec; | |
3117 | struct ppc_stub_hash_entry *stub_entry; | |
3118 | ||
3119 | link_sec = htab->stub_group[section->id].link_sec; | |
3120 | stub_sec = htab->stub_group[section->id].stub_sec; | |
3121 | if (stub_sec == NULL) | |
3122 | { | |
3123 | stub_sec = htab->stub_group[link_sec->id].stub_sec; | |
3124 | if (stub_sec == NULL) | |
3125 | { | |
d4c88bbb | 3126 | size_t namelen; |
721956f4 AM |
3127 | bfd_size_type len; |
3128 | char *s_name; | |
3129 | ||
d4c88bbb AM |
3130 | namelen = strlen (link_sec->name); |
3131 | len = namelen + sizeof (STUB_SUFFIX); | |
721956f4 AM |
3132 | s_name = bfd_alloc (htab->stub_bfd, len); |
3133 | if (s_name == NULL) | |
3134 | return NULL; | |
3135 | ||
d4c88bbb AM |
3136 | memcpy (s_name, link_sec->name, namelen); |
3137 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
721956f4 AM |
3138 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
3139 | if (stub_sec == NULL) | |
3140 | return NULL; | |
3141 | htab->stub_group[link_sec->id].stub_sec = stub_sec; | |
3142 | } | |
3143 | htab->stub_group[section->id].stub_sec = stub_sec; | |
3144 | } | |
3145 | ||
3146 | /* Enter this entry into the linker stub hash table. */ | |
3147 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
b34976b6 | 3148 | TRUE, FALSE); |
721956f4 AM |
3149 | if (stub_entry == NULL) |
3150 | { | |
3151 | (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), | |
3152 | bfd_archive_filename (section->owner), | |
3153 | stub_name); | |
3154 | return NULL; | |
3155 | } | |
3156 | ||
3157 | stub_entry->stub_sec = stub_sec; | |
3158 | stub_entry->stub_offset = 0; | |
3159 | stub_entry->id_sec = link_sec; | |
3160 | return stub_entry; | |
3161 | } | |
3162 | ||
82bd7b59 AM |
3163 | /* Create sections for linker generated code. */ |
3164 | ||
b34976b6 | 3165 | static bfd_boolean |
4ce794b7 | 3166 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
82bd7b59 AM |
3167 | { |
3168 | struct ppc_link_hash_table *htab; | |
3169 | flagword flags; | |
3170 | ||
3171 | htab = ppc_hash_table (info); | |
3172 | ||
3173 | /* Create .sfpr for code to save and restore fp regs. */ | |
3174 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
3175 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
721956f4 | 3176 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
82bd7b59 AM |
3177 | if (htab->sfpr == NULL |
3178 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) | |
3179 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) | |
b34976b6 | 3180 | return FALSE; |
82bd7b59 | 3181 | |
721956f4 | 3182 | /* Create .glink for lazy dynamic linking support. */ |
4ce794b7 AM |
3183 | htab->glink = bfd_make_section_anyway (dynobj, ".glink"); |
3184 | if (htab->glink == NULL | |
3185 | || ! bfd_set_section_flags (dynobj, htab->glink, flags) | |
3186 | || ! bfd_set_section_alignment (dynobj, htab->glink, 2)) | |
b34976b6 | 3187 | return FALSE; |
82bd7b59 | 3188 | |
721956f4 AM |
3189 | /* Create .branch_lt for plt_branch stubs. */ |
3190 | flags = (SEC_ALLOC | SEC_LOAD | |
3191 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3192 | htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt"); |
3193 | if (htab->brlt == NULL | |
3194 | || ! bfd_set_section_flags (dynobj, htab->brlt, flags) | |
3195 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) | |
b34976b6 | 3196 | return FALSE; |
721956f4 AM |
3197 | |
3198 | if (info->shared) | |
3199 | { | |
3200 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | |
3201 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
4ce794b7 AM |
3202 | htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
3203 | if (!htab->relbrlt | |
3204 | || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags) | |
3205 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) | |
b34976b6 | 3206 | return FALSE; |
721956f4 | 3207 | } |
b34976b6 | 3208 | return TRUE; |
82bd7b59 AM |
3209 | } |
3210 | ||
e717da7e AM |
3211 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
3212 | not already done. */ | |
65f38f15 | 3213 | |
b34976b6 | 3214 | static bfd_boolean |
e717da7e | 3215 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
65f38f15 | 3216 | { |
e717da7e AM |
3217 | asection *got, *relgot; |
3218 | flagword flags; | |
3219 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
65f38f15 | 3220 | |
4ce794b7 | 3221 | if (!htab->got) |
e717da7e AM |
3222 | { |
3223 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) | |
3224 | return FALSE; | |
3225 | ||
3226 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); | |
3227 | if (!htab->got) | |
3228 | abort (); | |
3229 | } | |
3230 | ||
3231 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3232 | | SEC_LINKER_CREATED); | |
3233 | ||
3234 | got = bfd_make_section (abfd, ".got"); | |
3235 | if (!got | |
3236 | || !bfd_set_section_flags (abfd, got, flags) | |
3237 | || !bfd_set_section_alignment (abfd, got, 3)) | |
3238 | return FALSE; | |
65f38f15 | 3239 | |
e717da7e AM |
3240 | relgot = bfd_make_section (abfd, ".rela.got"); |
3241 | if (!relgot | |
3242 | || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY) | |
3243 | || ! bfd_set_section_alignment (abfd, relgot, 3)) | |
b34976b6 | 3244 | return FALSE; |
e717da7e AM |
3245 | |
3246 | ppc64_elf_tdata (abfd)->got = got; | |
3247 | ppc64_elf_tdata (abfd)->relgot = relgot; | |
b34976b6 | 3248 | return TRUE; |
65f38f15 | 3249 | } |
5bd4f169 | 3250 | |
82bd7b59 | 3251 | /* Create the dynamic sections, and set up shortcuts. */ |
5bd4f169 | 3252 | |
b34976b6 | 3253 | static bfd_boolean |
4ce794b7 | 3254 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5bd4f169 | 3255 | { |
65f38f15 | 3256 | struct ppc_link_hash_table *htab; |
5bd4f169 | 3257 | |
65f38f15 | 3258 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 3259 | return FALSE; |
65f38f15 | 3260 | |
e717da7e AM |
3261 | htab = ppc_hash_table (info); |
3262 | if (!htab->got) | |
3263 | htab->got = bfd_get_section_by_name (dynobj, ".got"); | |
4ce794b7 AM |
3264 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
3265 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3266 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
65f38f15 | 3267 | if (!info->shared) |
4ce794b7 | 3268 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
65f38f15 | 3269 | |
e717da7e | 3270 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
4ce794b7 | 3271 | || (!info->shared && !htab->relbss)) |
65f38f15 AM |
3272 | abort (); |
3273 | ||
b34976b6 | 3274 | return TRUE; |
5bd4f169 AM |
3275 | } |
3276 | ||
65f38f15 AM |
3277 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
3278 | ||
3279 | static void | |
9c5bfbb7 AM |
3280 | ppc64_elf_copy_indirect_symbol |
3281 | (const struct elf_backend_data *bed ATTRIBUTE_UNUSED, | |
3282 | struct elf_link_hash_entry *dir, | |
3283 | struct elf_link_hash_entry *ind) | |
65f38f15 AM |
3284 | { |
3285 | struct ppc_link_hash_entry *edir, *eind; | |
81848ca0 | 3286 | flagword mask; |
65f38f15 AM |
3287 | |
3288 | edir = (struct ppc_link_hash_entry *) dir; | |
3289 | eind = (struct ppc_link_hash_entry *) ind; | |
3290 | ||
411e1bfb | 3291 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
bbd7ec4a | 3292 | if (eind->dyn_relocs != NULL) |
65f38f15 | 3293 | { |
bbd7ec4a AM |
3294 | if (edir->dyn_relocs != NULL) |
3295 | { | |
3296 | struct ppc_dyn_relocs **pp; | |
3297 | struct ppc_dyn_relocs *p; | |
3298 | ||
411e1bfb | 3299 | if (eind->elf.root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
3300 | abort (); |
3301 | ||
3302 | /* Add reloc counts against the weak sym to the strong sym | |
3303 | list. Merge any entries against the same section. */ | |
3304 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
3305 | { | |
3306 | struct ppc_dyn_relocs *q; | |
3307 | ||
3308 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
3309 | if (q->sec == p->sec) | |
3310 | { | |
3311 | q->pc_count += p->pc_count; | |
3312 | q->count += p->count; | |
3313 | *pp = p->next; | |
3314 | break; | |
3315 | } | |
3316 | if (q == NULL) | |
3317 | pp = &p->next; | |
3318 | } | |
3319 | *pp = edir->dyn_relocs; | |
3320 | } | |
3321 | ||
65f38f15 AM |
3322 | edir->dyn_relocs = eind->dyn_relocs; |
3323 | eind->dyn_relocs = NULL; | |
3324 | } | |
65f38f15 | 3325 | |
6349e628 AM |
3326 | edir->is_func |= eind->is_func; |
3327 | edir->is_func_descriptor |= eind->is_func_descriptor; | |
3328 | edir->is_entry |= eind->is_entry; | |
58ac9f71 | 3329 | edir->tls_mask |= eind->tls_mask; |
6349e628 | 3330 | |
81848ca0 AM |
3331 | mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR |
3332 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF); | |
3333 | /* If called to transfer flags for a weakdef during processing | |
3334 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. | |
3335 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
3336 | if (ELIMINATE_COPY_RELOCS | |
3337 | && eind->elf.root.type != bfd_link_hash_indirect | |
3338 | && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) | |
3339 | mask &= ~ELF_LINK_NON_GOT_REF; | |
3340 | ||
3341 | edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask; | |
6349e628 AM |
3342 | |
3343 | /* If we were called to copy over info for a weak sym, that's all. */ | |
3344 | if (eind->elf.root.type != bfd_link_hash_indirect) | |
3345 | return; | |
3346 | ||
81848ca0 AM |
3347 | /* Copy over got entries that we may have already seen to the |
3348 | symbol which just became indirect. */ | |
411e1bfb AM |
3349 | if (eind->elf.got.glist != NULL) |
3350 | { | |
3351 | if (edir->elf.got.glist != NULL) | |
3352 | { | |
3353 | struct got_entry **entp; | |
3354 | struct got_entry *ent; | |
3355 | ||
3356 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) | |
3357 | { | |
3358 | struct got_entry *dent; | |
3359 | ||
3360 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) | |
3361 | if (dent->addend == ent->addend | |
e717da7e | 3362 | && dent->owner == ent->owner |
411e1bfb AM |
3363 | && dent->tls_type == ent->tls_type) |
3364 | { | |
3365 | dent->got.refcount += ent->got.refcount; | |
3366 | *entp = ent->next; | |
3367 | break; | |
3368 | } | |
3369 | if (dent == NULL) | |
3370 | entp = &ent->next; | |
3371 | } | |
3372 | *entp = edir->elf.got.glist; | |
3373 | } | |
3374 | ||
3375 | edir->elf.got.glist = eind->elf.got.glist; | |
3376 | eind->elf.got.glist = NULL; | |
3377 | } | |
3378 | ||
3379 | /* And plt entries. */ | |
3380 | if (eind->elf.plt.plist != NULL) | |
3381 | { | |
3382 | if (edir->elf.plt.plist != NULL) | |
3383 | { | |
3384 | struct plt_entry **entp; | |
3385 | struct plt_entry *ent; | |
3386 | ||
3387 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) | |
3388 | { | |
3389 | struct plt_entry *dent; | |
3390 | ||
3391 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) | |
3392 | if (dent->addend == ent->addend) | |
3393 | { | |
3394 | dent->plt.refcount += ent->plt.refcount; | |
3395 | *entp = ent->next; | |
3396 | break; | |
3397 | } | |
3398 | if (dent == NULL) | |
3399 | entp = &ent->next; | |
3400 | } | |
3401 | *entp = edir->elf.plt.plist; | |
3402 | } | |
3403 | ||
3404 | edir->elf.plt.plist = eind->elf.plt.plist; | |
3405 | eind->elf.plt.plist = NULL; | |
3406 | } | |
3407 | ||
411e1bfb AM |
3408 | if (edir->elf.dynindx == -1) |
3409 | { | |
3410 | edir->elf.dynindx = eind->elf.dynindx; | |
3411 | edir->elf.dynstr_index = eind->elf.dynstr_index; | |
3412 | eind->elf.dynindx = -1; | |
3413 | eind->elf.dynstr_index = 0; | |
3414 | } | |
3415 | else | |
3416 | BFD_ASSERT (eind->elf.dynindx == -1); | |
3417 | } | |
3418 | ||
3419 | /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and | |
3420 | symbols undefined on the command-line. */ | |
3421 | ||
3422 | bfd_boolean | |
4ce794b7 | 3423 | ppc64_elf_mark_entry_syms (struct bfd_link_info *info) |
411e1bfb AM |
3424 | { |
3425 | struct ppc_link_hash_table *htab; | |
3426 | struct bfd_sym_chain *sym; | |
3427 | ||
3428 | htab = ppc_hash_table (info); | |
3429 | for (sym = info->gc_sym_list; sym; sym = sym->next) | |
3430 | { | |
3431 | struct elf_link_hash_entry *h; | |
3432 | ||
3433 | h = elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); | |
3434 | if (h != NULL) | |
3435 | ((struct ppc_link_hash_entry *) h)->is_entry = 1; | |
3436 | } | |
3437 | return TRUE; | |
3438 | } | |
3439 | ||
3440 | static bfd_boolean | |
4ce794b7 AM |
3441 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
3442 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) | |
411e1bfb AM |
3443 | { |
3444 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); | |
e7b938ca | 3445 | char *local_got_tls_masks; |
411e1bfb AM |
3446 | |
3447 | if (local_got_ents == NULL) | |
3448 | { | |
3449 | bfd_size_type size = symtab_hdr->sh_info; | |
3450 | ||
e7b938ca | 3451 | size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks); |
4ce794b7 | 3452 | local_got_ents = bfd_zalloc (abfd, size); |
411e1bfb AM |
3453 | if (local_got_ents == NULL) |
3454 | return FALSE; | |
3455 | elf_local_got_ents (abfd) = local_got_ents; | |
3456 | } | |
3457 | ||
3458 | if ((tls_type & TLS_EXPLICIT) == 0) | |
3459 | { | |
3460 | struct got_entry *ent; | |
3461 | ||
3462 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) | |
e717da7e AM |
3463 | if (ent->addend == r_addend |
3464 | && ent->owner == abfd | |
3465 | && ent->tls_type == tls_type) | |
411e1bfb AM |
3466 | break; |
3467 | if (ent == NULL) | |
3468 | { | |
3469 | bfd_size_type amt = sizeof (*ent); | |
4ce794b7 | 3470 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3471 | if (ent == NULL) |
3472 | return FALSE; | |
3473 | ent->next = local_got_ents[r_symndx]; | |
3474 | ent->addend = r_addend; | |
e717da7e | 3475 | ent->owner = abfd; |
411e1bfb AM |
3476 | ent->tls_type = tls_type; |
3477 | ent->got.refcount = 0; | |
3478 | local_got_ents[r_symndx] = ent; | |
3479 | } | |
3480 | ent->got.refcount += 1; | |
3481 | } | |
3482 | ||
e7b938ca AM |
3483 | local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
3484 | local_got_tls_masks[r_symndx] |= tls_type; | |
411e1bfb | 3485 | return TRUE; |
65f38f15 AM |
3486 | } |
3487 | ||
411e1bfb | 3488 | static bfd_boolean |
4ce794b7 | 3489 | update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend) |
1e2f5b6e | 3490 | { |
411e1bfb | 3491 | struct plt_entry *ent; |
1e2f5b6e | 3492 | |
411e1bfb AM |
3493 | for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next) |
3494 | if (ent->addend == addend) | |
3495 | break; | |
3496 | if (ent == NULL) | |
1e2f5b6e | 3497 | { |
411e1bfb | 3498 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3499 | ent = bfd_alloc (abfd, amt); |
411e1bfb AM |
3500 | if (ent == NULL) |
3501 | return FALSE; | |
3502 | ent->next = eh->elf.plt.plist; | |
3503 | ent->addend = addend; | |
3504 | ent->plt.refcount = 0; | |
3505 | eh->elf.plt.plist = ent; | |
1e2f5b6e | 3506 | } |
411e1bfb AM |
3507 | ent->plt.refcount += 1; |
3508 | eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3509 | eh->is_func = 1; | |
b34976b6 | 3510 | return TRUE; |
1e2f5b6e AM |
3511 | } |
3512 | ||
50bc7936 AM |
3513 | /* Find the function descriptor hash entry from the given function code |
3514 | hash entry FH. Link the entries via their OH fields. */ | |
3515 | static struct ppc_link_hash_entry * | |
3516 | get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) | |
3517 | { | |
3518 | struct ppc_link_hash_entry *fdh = (struct ppc_link_hash_entry *) fh->oh; | |
3519 | ||
3520 | if (fdh == NULL) | |
3521 | { | |
3522 | const char *fd_name = fh->elf.root.root.string + 1; | |
3523 | ||
3524 | fdh = (struct ppc_link_hash_entry *) | |
3525 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); | |
3526 | if (fdh != NULL) | |
3527 | { | |
3528 | fdh->is_func_descriptor = 1; | |
3529 | fdh->oh = &fh->elf; | |
3530 | fh->is_func = 1; | |
3531 | fh->oh = &fdh->elf; | |
3532 | } | |
3533 | } | |
3534 | ||
3535 | return fdh; | |
3536 | } | |
3537 | ||
5bd4f169 | 3538 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 3539 | calculate needed space in the global offset table, procedure |
5d1634d7 | 3540 | linkage table, and dynamic reloc sections. */ |
5bd4f169 | 3541 | |
b34976b6 | 3542 | static bfd_boolean |
4ce794b7 AM |
3543 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
3544 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 3545 | { |
65f38f15 | 3546 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3547 | Elf_Internal_Shdr *symtab_hdr; |
3548 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
3549 | const Elf_Internal_Rela *rel; | |
3550 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 3551 | asection *sreloc; |
1e2f5b6e | 3552 | asection **opd_sym_map; |
5bd4f169 | 3553 | |
1049f94e | 3554 | if (info->relocatable) |
b34976b6 | 3555 | return TRUE; |
5bd4f169 | 3556 | |
65f38f15 | 3557 | htab = ppc_hash_table (info); |
5bd4f169 | 3558 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
3559 | |
3560 | sym_hashes = elf_sym_hashes (abfd); | |
3561 | sym_hashes_end = (sym_hashes | |
1e2f5b6e AM |
3562 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
3563 | - symtab_hdr->sh_info); | |
5bd4f169 AM |
3564 | |
3565 | sreloc = NULL; | |
1e2f5b6e AM |
3566 | opd_sym_map = NULL; |
3567 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
3568 | { | |
3569 | /* Garbage collection needs some extra help with .opd sections. | |
3570 | We don't want to necessarily keep everything referenced by | |
3571 | relocs in .opd, as that would keep all functions. Instead, | |
3572 | if we reference an .opd symbol (a function descriptor), we | |
3573 | want to keep the function code symbol's section. This is | |
3574 | easy for global symbols, but for local syms we need to keep | |
3575 | information about the associated function section. Later, if | |
3576 | edit_opd deletes entries, we'll use this array to adjust | |
3577 | local syms in .opd. */ | |
3578 | union opd_info { | |
3579 | asection *func_section; | |
3580 | long entry_adjust; | |
3581 | }; | |
3582 | bfd_size_type amt; | |
3583 | ||
3584 | amt = sec->_raw_size * sizeof (union opd_info) / 24; | |
4ce794b7 | 3585 | opd_sym_map = bfd_zalloc (abfd, amt); |
1e2f5b6e | 3586 | if (opd_sym_map == NULL) |
b34976b6 | 3587 | return FALSE; |
f0abc2a1 | 3588 | ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map; |
1e2f5b6e | 3589 | } |
5bd4f169 | 3590 | |
82bd7b59 AM |
3591 | if (htab->sfpr == NULL |
3592 | && !create_linkage_sections (htab->elf.dynobj, info)) | |
b34976b6 | 3593 | return FALSE; |
82bd7b59 | 3594 | |
5bd4f169 AM |
3595 | rel_end = relocs + sec->reloc_count; |
3596 | for (rel = relocs; rel < rel_end; rel++) | |
3597 | { | |
3598 | unsigned long r_symndx; | |
3599 | struct elf_link_hash_entry *h; | |
04c9666a | 3600 | enum elf_ppc64_reloc_type r_type; |
411e1bfb | 3601 | int tls_type = 0; |
5bd4f169 AM |
3602 | |
3603 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3604 | if (r_symndx < symtab_hdr->sh_info) | |
3605 | h = NULL; | |
3606 | else | |
3607 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3608 | ||
4ce794b7 | 3609 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 3610 | switch (r_type) |
5bd4f169 | 3611 | { |
411e1bfb AM |
3612 | case R_PPC64_GOT_TLSLD16: |
3613 | case R_PPC64_GOT_TLSLD16_LO: | |
3614 | case R_PPC64_GOT_TLSLD16_HI: | |
3615 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 3616 | ppc64_tlsld_got (abfd)->refcount += 1; |
951fd09b | 3617 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
3618 | goto dogottls; |
3619 | ||
3620 | case R_PPC64_GOT_TLSGD16: | |
3621 | case R_PPC64_GOT_TLSGD16_LO: | |
3622 | case R_PPC64_GOT_TLSGD16_HI: | |
3623 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 3624 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
3625 | goto dogottls; |
3626 | ||
3627 | case R_PPC64_GOT_TPREL16_DS: | |
3628 | case R_PPC64_GOT_TPREL16_LO_DS: | |
3629 | case R_PPC64_GOT_TPREL16_HI: | |
3630 | case R_PPC64_GOT_TPREL16_HA: | |
3631 | if (info->shared) | |
3632 | info->flags |= DF_STATIC_TLS; | |
3633 | tls_type = TLS_TLS | TLS_TPREL; | |
3634 | goto dogottls; | |
3635 | ||
3636 | case R_PPC64_GOT_DTPREL16_DS: | |
3637 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
3638 | case R_PPC64_GOT_DTPREL16_HI: | |
3639 | case R_PPC64_GOT_DTPREL16_HA: | |
3640 | tls_type = TLS_TLS | TLS_DTPREL; | |
3641 | dogottls: | |
3642 | sec->has_tls_reloc = 1; | |
3643 | /* Fall thru */ | |
3644 | ||
5bd4f169 | 3645 | case R_PPC64_GOT16: |
5bd4f169 | 3646 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
3647 | case R_PPC64_GOT16_HA: |
3648 | case R_PPC64_GOT16_HI: | |
3649 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 3650 | case R_PPC64_GOT16_LO_DS: |
65f38f15 | 3651 | /* This symbol requires a global offset table entry. */ |
ad8e1ba5 | 3652 | sec->has_gp_reloc = 1; |
e717da7e AM |
3653 | if (ppc64_elf_tdata (abfd)->got == NULL |
3654 | && !create_got_section (abfd, info)) | |
b34976b6 | 3655 | return FALSE; |
5bd4f169 AM |
3656 | |
3657 | if (h != NULL) | |
3658 | { | |
411e1bfb AM |
3659 | struct ppc_link_hash_entry *eh; |
3660 | struct got_entry *ent; | |
65f38f15 | 3661 | |
411e1bfb AM |
3662 | eh = (struct ppc_link_hash_entry *) h; |
3663 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) | |
3664 | if (ent->addend == rel->r_addend | |
e717da7e | 3665 | && ent->owner == abfd |
411e1bfb AM |
3666 | && ent->tls_type == tls_type) |
3667 | break; | |
3668 | if (ent == NULL) | |
5bd4f169 | 3669 | { |
411e1bfb | 3670 | bfd_size_type amt = sizeof (*ent); |
4ce794b7 | 3671 | ent = bfd_alloc (abfd, amt); |
411e1bfb | 3672 | if (ent == NULL) |
b34976b6 | 3673 | return FALSE; |
411e1bfb AM |
3674 | ent->next = eh->elf.got.glist; |
3675 | ent->addend = rel->r_addend; | |
e717da7e | 3676 | ent->owner = abfd; |
411e1bfb AM |
3677 | ent->tls_type = tls_type; |
3678 | ent->got.refcount = 0; | |
3679 | eh->elf.got.glist = ent; | |
5bd4f169 | 3680 | } |
411e1bfb | 3681 | ent->got.refcount += 1; |
e7b938ca | 3682 | eh->tls_mask |= tls_type; |
5bd4f169 | 3683 | } |
411e1bfb AM |
3684 | else |
3685 | /* This is a global offset table entry for a local symbol. */ | |
3686 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3687 | rel->r_addend, tls_type)) | |
3688 | return FALSE; | |
5bd4f169 AM |
3689 | break; |
3690 | ||
5bd4f169 | 3691 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
3692 | case R_PPC64_PLT16_HI: |
3693 | case R_PPC64_PLT16_LO: | |
3694 | case R_PPC64_PLT32: | |
3695 | case R_PPC64_PLT64: | |
5bd4f169 | 3696 | /* This symbol requires a procedure linkage table entry. We |
3fad3c7c AM |
3697 | actually build the entry in adjust_dynamic_symbol, |
3698 | because this might be a case of linking PIC code without | |
3699 | linking in any dynamic objects, in which case we don't | |
3700 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
3701 | if (h == NULL) |
3702 | { | |
3703 | /* It does not make sense to have a procedure linkage | |
3fad3c7c | 3704 | table entry for a local symbol. */ |
5bd4f169 | 3705 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3706 | return FALSE; |
5bd4f169 | 3707 | } |
411e1bfb AM |
3708 | else |
3709 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, | |
3710 | rel->r_addend)) | |
3711 | return FALSE; | |
5bd4f169 AM |
3712 | break; |
3713 | ||
3714 | /* The following relocations don't need to propagate the | |
3715 | relocation if linking a shared object since they are | |
3716 | section relative. */ | |
3717 | case R_PPC64_SECTOFF: | |
3718 | case R_PPC64_SECTOFF_LO: | |
3719 | case R_PPC64_SECTOFF_HI: | |
3720 | case R_PPC64_SECTOFF_HA: | |
3721 | case R_PPC64_SECTOFF_DS: | |
3722 | case R_PPC64_SECTOFF_LO_DS: | |
411e1bfb AM |
3723 | case R_PPC64_DTPREL16: |
3724 | case R_PPC64_DTPREL16_LO: | |
3725 | case R_PPC64_DTPREL16_HI: | |
3726 | case R_PPC64_DTPREL16_HA: | |
3727 | case R_PPC64_DTPREL16_DS: | |
3728 | case R_PPC64_DTPREL16_LO_DS: | |
3729 | case R_PPC64_DTPREL16_HIGHER: | |
3730 | case R_PPC64_DTPREL16_HIGHERA: | |
3731 | case R_PPC64_DTPREL16_HIGHEST: | |
3732 | case R_PPC64_DTPREL16_HIGHESTA: | |
5bd4f169 AM |
3733 | break; |
3734 | ||
ad8e1ba5 AM |
3735 | /* Nor do these. */ |
3736 | case R_PPC64_TOC16: | |
3737 | case R_PPC64_TOC16_LO: | |
3738 | case R_PPC64_TOC16_HI: | |
3739 | case R_PPC64_TOC16_HA: | |
3740 | case R_PPC64_TOC16_DS: | |
3741 | case R_PPC64_TOC16_LO_DS: | |
3742 | sec->has_gp_reloc = 1; | |
3743 | break; | |
3744 | ||
5bd4f169 AM |
3745 | /* This relocation describes the C++ object vtable hierarchy. |
3746 | Reconstruct it for later use during GC. */ | |
3747 | case R_PPC64_GNU_VTINHERIT: | |
3748 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
b34976b6 | 3749 | return FALSE; |
5bd4f169 AM |
3750 | break; |
3751 | ||
3752 | /* This relocation describes which C++ vtable entries are actually | |
3753 | used. Record for later use during GC. */ | |
3754 | case R_PPC64_GNU_VTENTRY: | |
3755 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 3756 | return FALSE; |
5bd4f169 AM |
3757 | break; |
3758 | ||
721956f4 AM |
3759 | case R_PPC64_REL14: |
3760 | case R_PPC64_REL14_BRTAKEN: | |
3761 | case R_PPC64_REL14_BRNTAKEN: | |
3762 | htab->has_14bit_branch = 1; | |
3763 | /* Fall through. */ | |
3764 | ||
5d1634d7 | 3765 | case R_PPC64_REL24: |
e86ce104 AM |
3766 | if (h != NULL |
3767 | && h->root.root.string[0] == '.' | |
3768 | && h->root.root.string[1] != 0) | |
5d1634d7 AM |
3769 | { |
3770 | /* We may need a .plt entry if the function this reloc | |
3771 | refers to is in a shared lib. */ | |
411e1bfb AM |
3772 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
3773 | rel->r_addend)) | |
3774 | return FALSE; | |
3775 | if (h == htab->tls_get_addr) | |
3776 | sec->has_tls_reloc = 1; | |
a48ebf4d AM |
3777 | else if ((strncmp (h->root.root.string, ".__tls_get_addr", 15) |
3778 | == 0) | |
3779 | && (h->root.root.string[15] == 0 | |
3780 | || h->root.root.string[15] == '@')) | |
411e1bfb AM |
3781 | { |
3782 | htab->tls_get_addr = h; | |
3783 | sec->has_tls_reloc = 1; | |
3784 | } | |
3785 | } | |
3786 | break; | |
3787 | ||
3788 | case R_PPC64_TPREL64: | |
3789 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | |
3790 | if (info->shared) | |
3791 | info->flags |= DF_STATIC_TLS; | |
3792 | goto dotlstoc; | |
3793 | ||
3794 | case R_PPC64_DTPMOD64: | |
3795 | if (rel + 1 < rel_end | |
3796 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
3797 | && rel[1].r_offset == rel->r_offset + 8) | |
951fd09b | 3798 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
411e1bfb | 3799 | else |
951fd09b | 3800 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
411e1bfb AM |
3801 | goto dotlstoc; |
3802 | ||
3803 | case R_PPC64_DTPREL64: | |
3804 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; | |
3805 | if (rel != relocs | |
3806 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) | |
3807 | && rel[-1].r_offset == rel->r_offset - 8) | |
3808 | /* This is the second reloc of a dtpmod, dtprel pair. | |
3809 | Don't mark with TLS_DTPREL. */ | |
3810 | goto dodyn; | |
3811 | ||
3812 | dotlstoc: | |
3813 | sec->has_tls_reloc = 1; | |
3814 | if (h != NULL) | |
3815 | { | |
3816 | struct ppc_link_hash_entry *eh; | |
3817 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 3818 | eh->tls_mask |= tls_type; |
411e1bfb AM |
3819 | } |
3820 | else | |
3821 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, | |
3822 | rel->r_addend, tls_type)) | |
3823 | return FALSE; | |
3824 | ||
3825 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) | |
3826 | { | |
e7b938ca | 3827 | /* One extra to simplify get_tls_mask. */ |
951fd09b | 3828 | bfd_size_type amt = sec->_raw_size * sizeof (unsigned) / 8 + 1; |
4ce794b7 | 3829 | ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt); |
411e1bfb AM |
3830 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
3831 | return FALSE; | |
3832 | } | |
3833 | BFD_ASSERT (rel->r_offset % 8 == 0); | |
3834 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx; | |
951fd09b AM |
3835 | |
3836 | /* Mark the second slot of a GD or LD entry. | |
3837 | -1 to indicate GD and -2 to indicate LD. */ | |
3838 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | |
3839 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1; | |
3840 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) | |
3841 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2; | |
411e1bfb AM |
3842 | goto dodyn; |
3843 | ||
3844 | case R_PPC64_TPREL16: | |
3845 | case R_PPC64_TPREL16_LO: | |
3846 | case R_PPC64_TPREL16_HI: | |
3847 | case R_PPC64_TPREL16_HA: | |
3848 | case R_PPC64_TPREL16_DS: | |
3849 | case R_PPC64_TPREL16_LO_DS: | |
3850 | case R_PPC64_TPREL16_HIGHER: | |
3851 | case R_PPC64_TPREL16_HIGHERA: | |
3852 | case R_PPC64_TPREL16_HIGHEST: | |
3853 | case R_PPC64_TPREL16_HIGHESTA: | |
3854 | if (info->shared) | |
3855 | { | |
3856 | info->flags |= DF_STATIC_TLS; | |
3857 | goto dodyn; | |
5d1634d7 AM |
3858 | } |
3859 | break; | |
3860 | ||
e86ce104 | 3861 | case R_PPC64_ADDR64: |
1e2f5b6e | 3862 | if (opd_sym_map != NULL |
e86ce104 AM |
3863 | && h != NULL |
3864 | && h->root.root.string[0] == '.' | |
3865 | && h->root.root.string[1] != 0) | |
50bc7936 | 3866 | get_fdh ((struct ppc_link_hash_entry *) h, htab); |
e86ce104 | 3867 | |
1e2f5b6e AM |
3868 | if (opd_sym_map != NULL |
3869 | && h == NULL | |
3870 | && rel + 1 < rel_end | |
4ce794b7 | 3871 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
1e2f5b6e AM |
3872 | { |
3873 | asection *s; | |
3874 | ||
3875 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, | |
3876 | r_symndx); | |
3877 | if (s == NULL) | |
b34976b6 | 3878 | return FALSE; |
1e2f5b6e AM |
3879 | else if (s != sec) |
3880 | opd_sym_map[rel->r_offset / 24] = s; | |
3881 | } | |
e86ce104 AM |
3882 | /* Fall through. */ |
3883 | ||
04c9666a | 3884 | case R_PPC64_REL30: |
5bd4f169 | 3885 | case R_PPC64_REL32: |
04c9666a | 3886 | case R_PPC64_REL64: |
65f38f15 AM |
3887 | case R_PPC64_ADDR14: |
3888 | case R_PPC64_ADDR14_BRNTAKEN: | |
3889 | case R_PPC64_ADDR14_BRTAKEN: | |
3890 | case R_PPC64_ADDR16: | |
3891 | case R_PPC64_ADDR16_DS: | |
3892 | case R_PPC64_ADDR16_HA: | |
3893 | case R_PPC64_ADDR16_HI: | |
3894 | case R_PPC64_ADDR16_HIGHER: | |
3895 | case R_PPC64_ADDR16_HIGHERA: | |
3896 | case R_PPC64_ADDR16_HIGHEST: | |
3897 | case R_PPC64_ADDR16_HIGHESTA: | |
3898 | case R_PPC64_ADDR16_LO: | |
3899 | case R_PPC64_ADDR16_LO_DS: | |
3900 | case R_PPC64_ADDR24: | |
65f38f15 | 3901 | case R_PPC64_ADDR32: |
65f38f15 AM |
3902 | case R_PPC64_UADDR16: |
3903 | case R_PPC64_UADDR32: | |
3904 | case R_PPC64_UADDR64: | |
5bd4f169 | 3905 | case R_PPC64_TOC: |
81848ca0 AM |
3906 | if (h != NULL && !info->shared) |
3907 | /* We may need a copy reloc. */ | |
3908 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
3909 | ||
41bd81ab | 3910 | /* Don't propagate .opd relocs. */ |
1e2f5b6e | 3911 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
e86ce104 | 3912 | break; |
e86ce104 | 3913 | |
f4656909 AM |
3914 | /* Don't propagate relocs that the dynamic linker won't relocate. */ |
3915 | if ((sec->flags & SEC_ALLOC) == 0) | |
3916 | break; | |
3917 | ||
65f38f15 AM |
3918 | /* If we are creating a shared library, and this is a reloc |
3919 | against a global symbol, or a non PC relative reloc | |
3920 | against a local symbol, then we need to copy the reloc | |
3921 | into the shared library. However, if we are linking with | |
3922 | -Bsymbolic, we do not need to copy a reloc against a | |
3923 | global symbol which is defined in an object we are | |
3924 | including in the link (i.e., DEF_REGULAR is set). At | |
3925 | this point we have not seen all the input files, so it is | |
3926 | possible that DEF_REGULAR is not set now but will be set | |
3927 | later (it is never cleared). In case of a weak definition, | |
3928 | DEF_REGULAR may be cleared later by a strong definition in | |
3929 | a shared library. We account for that possibility below by | |
f4656909 | 3930 | storing information in the dyn_relocs field of the hash |
65f38f15 AM |
3931 | table entry. A similar situation occurs when creating |
3932 | shared libraries and symbol visibility changes render the | |
3933 | symbol local. | |
3934 | ||
3935 | If on the other hand, we are creating an executable, we | |
3936 | may need to keep relocations for symbols satisfied by a | |
3937 | dynamic library if we manage to avoid copy relocs for the | |
3938 | symbol. */ | |
411e1bfb | 3939 | dodyn: |
65f38f15 | 3940 | if ((info->shared |
411e1bfb | 3941 | && (MUST_BE_DYN_RELOC (r_type) |
65f38f15 AM |
3942 | || (h != NULL |
3943 | && (! info->symbolic | |
3944 | || h->root.type == bfd_link_hash_defweak | |
3945 | || (h->elf_link_hash_flags | |
3946 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
f4656909 AM |
3947 | || (ELIMINATE_COPY_RELOCS |
3948 | && !info->shared | |
65f38f15 AM |
3949 | && h != NULL |
3950 | && (h->root.type == bfd_link_hash_defweak | |
3951 | || (h->elf_link_hash_flags | |
3952 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 3953 | { |
ec338859 AM |
3954 | struct ppc_dyn_relocs *p; |
3955 | struct ppc_dyn_relocs **head; | |
3956 | ||
65f38f15 AM |
3957 | /* We must copy these reloc types into the output file. |
3958 | Create a reloc section in dynobj and make room for | |
3959 | this reloc. */ | |
5bd4f169 AM |
3960 | if (sreloc == NULL) |
3961 | { | |
3962 | const char *name; | |
65f38f15 | 3963 | bfd *dynobj; |
5bd4f169 AM |
3964 | |
3965 | name = (bfd_elf_string_from_elf_section | |
3966 | (abfd, | |
3967 | elf_elfheader (abfd)->e_shstrndx, | |
3968 | elf_section_data (sec)->rel_hdr.sh_name)); | |
3969 | if (name == NULL) | |
b34976b6 | 3970 | return FALSE; |
5bd4f169 | 3971 | |
65f38f15 AM |
3972 | if (strncmp (name, ".rela", 5) != 0 |
3973 | || strcmp (bfd_get_section_name (abfd, sec), | |
3974 | name + 5) != 0) | |
3975 | { | |
3976 | (*_bfd_error_handler) | |
3977 | (_("%s: bad relocation section name `%s\'"), | |
3978 | bfd_archive_filename (abfd), name); | |
5d1634d7 | 3979 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
3980 | } |
3981 | ||
65f38f15 | 3982 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
3983 | sreloc = bfd_get_section_by_name (dynobj, name); |
3984 | if (sreloc == NULL) | |
3985 | { | |
3986 | flagword flags; | |
3987 | ||
3988 | sreloc = bfd_make_section (dynobj, name); | |
3989 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
3990 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3991 | if ((sec->flags & SEC_ALLOC) != 0) | |
3992 | flags |= SEC_ALLOC | SEC_LOAD; | |
3993 | if (sreloc == NULL | |
3994 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 3995 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
b34976b6 | 3996 | return FALSE; |
5bd4f169 | 3997 | } |
65f38f15 | 3998 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
3999 | } |
4000 | ||
65f38f15 AM |
4001 | /* If this is a global symbol, we count the number of |
4002 | relocations we need for this symbol. */ | |
4003 | if (h != NULL) | |
4004 | { | |
ec338859 | 4005 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
4006 | } |
4007 | else | |
4008 | { | |
ec338859 AM |
4009 | /* Track dynamic relocs needed for local syms too. |
4010 | We really need local syms available to do this | |
4011 | easily. Oh well. */ | |
4012 | ||
4013 | asection *s; | |
4014 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
4015 | sec, r_symndx); | |
4016 | if (s == NULL) | |
b34976b6 | 4017 | return FALSE; |
ec338859 AM |
4018 | |
4019 | head = ((struct ppc_dyn_relocs **) | |
4020 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 4021 | } |
ec338859 AM |
4022 | |
4023 | p = *head; | |
4024 | if (p == NULL || p->sec != sec) | |
4025 | { | |
4ce794b7 | 4026 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
ec338859 | 4027 | if (p == NULL) |
b34976b6 | 4028 | return FALSE; |
ec338859 AM |
4029 | p->next = *head; |
4030 | *head = p; | |
4031 | p->sec = sec; | |
4032 | p->count = 0; | |
4033 | p->pc_count = 0; | |
4034 | } | |
4035 | ||
4036 | p->count += 1; | |
411e1bfb | 4037 | if (!MUST_BE_DYN_RELOC (r_type)) |
ec338859 | 4038 | p->pc_count += 1; |
65f38f15 | 4039 | } |
5bd4f169 | 4040 | break; |
65f38f15 AM |
4041 | |
4042 | default: | |
96e0dda4 | 4043 | break; |
5bd4f169 AM |
4044 | } |
4045 | } | |
4046 | ||
b34976b6 | 4047 | return TRUE; |
5bd4f169 AM |
4048 | } |
4049 | ||
4050 | /* Return the section that should be marked against GC for a given | |
4051 | relocation. */ | |
4052 | ||
4053 | static asection * | |
4ce794b7 AM |
4054 | ppc64_elf_gc_mark_hook (asection *sec, |
4055 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
4056 | Elf_Internal_Rela *rel, | |
4057 | struct elf_link_hash_entry *h, | |
4058 | Elf_Internal_Sym *sym) | |
5bd4f169 | 4059 | { |
1e2f5b6e AM |
4060 | asection *rsec = NULL; |
4061 | ||
5bd4f169 AM |
4062 | if (h != NULL) |
4063 | { | |
04c9666a | 4064 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e | 4065 | struct ppc_link_hash_entry *fdh; |
a33d1f77 | 4066 | |
4ce794b7 | 4067 | r_type = ELF64_R_TYPE (rel->r_info); |
a33d1f77 | 4068 | switch (r_type) |
5bd4f169 AM |
4069 | { |
4070 | case R_PPC64_GNU_VTINHERIT: | |
4071 | case R_PPC64_GNU_VTENTRY: | |
4072 | break; | |
4073 | ||
4074 | default: | |
4075 | switch (h->root.type) | |
4076 | { | |
4077 | case bfd_link_hash_defined: | |
4078 | case bfd_link_hash_defweak: | |
1e2f5b6e AM |
4079 | fdh = (struct ppc_link_hash_entry *) h; |
4080 | ||
4081 | /* Function descriptor syms cause the associated | |
4082 | function code sym section to be marked. */ | |
4083 | if (fdh->is_func_descriptor) | |
4084 | rsec = fdh->oh->root.u.def.section; | |
4085 | ||
4086 | /* Function entry syms return NULL if they are in .opd | |
4087 | and are not ._start (or others undefined on the ld | |
4088 | command line). Thus we avoid marking all function | |
b34976b6 | 4089 | sections, as all functions are referenced in .opd. */ |
1e2f5b6e AM |
4090 | else if ((fdh->oh != NULL |
4091 | && ((struct ppc_link_hash_entry *) fdh->oh)->is_entry) | |
f0abc2a1 | 4092 | || ppc64_elf_section_data (sec)->opd.func_sec == NULL) |
1e2f5b6e AM |
4093 | rsec = h->root.u.def.section; |
4094 | break; | |
5bd4f169 AM |
4095 | |
4096 | case bfd_link_hash_common: | |
1e2f5b6e AM |
4097 | rsec = h->root.u.c.p->section; |
4098 | break; | |
5bd4f169 AM |
4099 | |
4100 | default: | |
4101 | break; | |
4102 | } | |
4103 | } | |
4104 | } | |
4105 | else | |
4106 | { | |
1e2f5b6e AM |
4107 | asection **opd_sym_section; |
4108 | ||
4109 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
f0abc2a1 | 4110 | opd_sym_section = ppc64_elf_section_data (rsec)->opd.func_sec; |
1e2f5b6e AM |
4111 | if (opd_sym_section != NULL) |
4112 | rsec = opd_sym_section[sym->st_value / 24]; | |
f0abc2a1 | 4113 | else if (ppc64_elf_section_data (sec)->opd.func_sec != NULL) |
1e2f5b6e | 4114 | rsec = NULL; |
5bd4f169 AM |
4115 | } |
4116 | ||
1e2f5b6e | 4117 | return rsec; |
5bd4f169 AM |
4118 | } |
4119 | ||
65f38f15 AM |
4120 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
4121 | section being removed. */ | |
5bd4f169 | 4122 | |
b34976b6 | 4123 | static bfd_boolean |
4ce794b7 AM |
4124 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
4125 | asection *sec, const Elf_Internal_Rela *relocs) | |
5bd4f169 | 4126 | { |
411e1bfb | 4127 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
4128 | Elf_Internal_Shdr *symtab_hdr; |
4129 | struct elf_link_hash_entry **sym_hashes; | |
411e1bfb | 4130 | struct got_entry **local_got_ents; |
5bd4f169 | 4131 | const Elf_Internal_Rela *rel, *relend; |
5bd4f169 | 4132 | |
ec338859 AM |
4133 | elf_section_data (sec)->local_dynrel = NULL; |
4134 | ||
411e1bfb | 4135 | htab = ppc_hash_table (info); |
5bd4f169 AM |
4136 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4137 | sym_hashes = elf_sym_hashes (abfd); | |
411e1bfb | 4138 | local_got_ents = elf_local_got_ents (abfd); |
5bd4f169 AM |
4139 | |
4140 | relend = relocs + sec->reloc_count; | |
4141 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
4142 | { |
4143 | unsigned long r_symndx; | |
04c9666a | 4144 | enum elf_ppc64_reloc_type r_type; |
58ac9f71 | 4145 | struct elf_link_hash_entry *h = NULL; |
411e1bfb | 4146 | char tls_type = 0; |
5bd4f169 | 4147 | |
a33d1f77 | 4148 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 | 4149 | r_type = ELF64_R_TYPE (rel->r_info); |
58ac9f71 AM |
4150 | if (r_symndx >= symtab_hdr->sh_info) |
4151 | { | |
4152 | struct ppc_link_hash_entry *eh; | |
4153 | struct ppc_dyn_relocs **pp; | |
4154 | struct ppc_dyn_relocs *p; | |
4155 | ||
4156 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4157 | eh = (struct ppc_link_hash_entry *) h; | |
4158 | ||
4159 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
4160 | if (p->sec == sec) | |
4161 | { | |
4162 | /* Everything must go for SEC. */ | |
4163 | *pp = p->next; | |
4164 | break; | |
4165 | } | |
4166 | } | |
4167 | ||
a33d1f77 AM |
4168 | switch (r_type) |
4169 | { | |
411e1bfb AM |
4170 | case R_PPC64_GOT_TLSLD16: |
4171 | case R_PPC64_GOT_TLSLD16_LO: | |
4172 | case R_PPC64_GOT_TLSLD16_HI: | |
4173 | case R_PPC64_GOT_TLSLD16_HA: | |
e717da7e | 4174 | ppc64_tlsld_got (abfd)->refcount -= 1; |
951fd09b | 4175 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
4176 | goto dogot; |
4177 | ||
4178 | case R_PPC64_GOT_TLSGD16: | |
4179 | case R_PPC64_GOT_TLSGD16_LO: | |
4180 | case R_PPC64_GOT_TLSGD16_HI: | |
4181 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 4182 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
4183 | goto dogot; |
4184 | ||
4185 | case R_PPC64_GOT_TPREL16_DS: | |
4186 | case R_PPC64_GOT_TPREL16_LO_DS: | |
4187 | case R_PPC64_GOT_TPREL16_HI: | |
4188 | case R_PPC64_GOT_TPREL16_HA: | |
4189 | tls_type = TLS_TLS | TLS_TPREL; | |
4190 | goto dogot; | |
4191 | ||
4192 | case R_PPC64_GOT_DTPREL16_DS: | |
4193 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
4194 | case R_PPC64_GOT_DTPREL16_HI: | |
4195 | case R_PPC64_GOT_DTPREL16_HA: | |
4196 | tls_type = TLS_TLS | TLS_DTPREL; | |
4197 | goto dogot; | |
4198 | ||
a33d1f77 AM |
4199 | case R_PPC64_GOT16: |
4200 | case R_PPC64_GOT16_DS: | |
4201 | case R_PPC64_GOT16_HA: | |
4202 | case R_PPC64_GOT16_HI: | |
4203 | case R_PPC64_GOT16_LO: | |
4204 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb AM |
4205 | dogot: |
4206 | { | |
4207 | struct got_entry *ent; | |
4208 | ||
58ac9f71 AM |
4209 | if (h != NULL) |
4210 | ent = h->got.glist; | |
411e1bfb AM |
4211 | else |
4212 | ent = local_got_ents[r_symndx]; | |
4213 | ||
4214 | for (; ent != NULL; ent = ent->next) | |
4215 | if (ent->addend == rel->r_addend | |
e717da7e | 4216 | && ent->owner == abfd |
411e1bfb AM |
4217 | && ent->tls_type == tls_type) |
4218 | break; | |
4219 | if (ent == NULL) | |
4220 | abort (); | |
4221 | if (ent->got.refcount > 0) | |
4222 | ent->got.refcount -= 1; | |
4223 | } | |
a33d1f77 | 4224 | break; |
65f38f15 | 4225 | |
a33d1f77 AM |
4226 | case R_PPC64_PLT16_HA: |
4227 | case R_PPC64_PLT16_HI: | |
4228 | case R_PPC64_PLT16_LO: | |
4229 | case R_PPC64_PLT32: | |
4230 | case R_PPC64_PLT64: | |
721956f4 AM |
4231 | case R_PPC64_REL14: |
4232 | case R_PPC64_REL14_BRNTAKEN: | |
4233 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 | 4234 | case R_PPC64_REL24: |
58ac9f71 | 4235 | if (h != NULL) |
5d1634d7 | 4236 | { |
411e1bfb AM |
4237 | struct plt_entry *ent; |
4238 | ||
411e1bfb AM |
4239 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
4240 | if (ent->addend == rel->r_addend) | |
4241 | break; | |
4242 | if (ent == NULL) | |
4243 | abort (); | |
4244 | if (ent->plt.refcount > 0) | |
4245 | ent->plt.refcount -= 1; | |
5d1634d7 | 4246 | } |
e86ce104 | 4247 | break; |
5d1634d7 | 4248 | |
a33d1f77 AM |
4249 | default: |
4250 | break; | |
4251 | } | |
4252 | } | |
b34976b6 | 4253 | return TRUE; |
5bd4f169 AM |
4254 | } |
4255 | ||
e86ce104 AM |
4256 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
4257 | information on function code symbol entries to their corresponding | |
4258 | function descriptor symbol entries. */ | |
b34976b6 | 4259 | static bfd_boolean |
4ce794b7 | 4260 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 4261 | { |
e86ce104 | 4262 | struct bfd_link_info *info; |
65f38f15 | 4263 | struct ppc_link_hash_table *htab; |
411e1bfb | 4264 | struct plt_entry *ent; |
50bc7936 AM |
4265 | struct ppc_link_hash_entry *fh; |
4266 | struct ppc_link_hash_entry *fdh; | |
4267 | bfd_boolean force_local; | |
5bd4f169 | 4268 | |
50bc7936 AM |
4269 | fh = (struct ppc_link_hash_entry *) h; |
4270 | if (fh->elf.root.type == bfd_link_hash_indirect) | |
b34976b6 | 4271 | return TRUE; |
e86ce104 | 4272 | |
50bc7936 AM |
4273 | if (fh->elf.root.type == bfd_link_hash_warning) |
4274 | fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link; | |
e92d460e | 4275 | |
4ce794b7 | 4276 | info = inf; |
65f38f15 | 4277 | htab = ppc_hash_table (info); |
5bd4f169 | 4278 | |
e86ce104 AM |
4279 | /* If this is a function code symbol, transfer dynamic linking |
4280 | information to the function descriptor symbol. */ | |
50bc7936 | 4281 | if (!fh->is_func) |
b34976b6 | 4282 | return TRUE; |
e86ce104 | 4283 | |
50bc7936 AM |
4284 | if (fh->elf.root.type == bfd_link_hash_undefweak |
4285 | && (fh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR)) | |
b34976b6 | 4286 | htab->have_undefweak = TRUE; |
805fc799 | 4287 | |
50bc7936 | 4288 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
411e1bfb AM |
4289 | if (ent->plt.refcount > 0) |
4290 | break; | |
50bc7936 AM |
4291 | if (ent == NULL |
4292 | || fh->elf.root.root.string[0] != '.' | |
4293 | || fh->elf.root.root.string[1] == '\0') | |
4294 | return TRUE; | |
5bd4f169 | 4295 | |
50bc7936 AM |
4296 | /* Find the corresponding function descriptor symbol. Create it |
4297 | as undefined if necessary. */ | |
5bd4f169 | 4298 | |
50bc7936 AM |
4299 | fdh = get_fdh (fh, htab); |
4300 | if (fdh != NULL) | |
4301 | while (fdh->elf.root.type == bfd_link_hash_indirect | |
4302 | || fdh->elf.root.type == bfd_link_hash_warning) | |
4303 | fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link; | |
5bd4f169 | 4304 | |
50bc7936 AM |
4305 | if (fdh == NULL |
4306 | && info->shared | |
4307 | && (fh->elf.root.type == bfd_link_hash_undefined | |
4308 | || fh->elf.root.type == bfd_link_hash_undefweak)) | |
4309 | { | |
4310 | bfd *abfd; | |
4311 | asymbol *newsym; | |
4312 | struct bfd_link_hash_entry *bh; | |
4313 | ||
4314 | abfd = fh->elf.root.u.undef.abfd; | |
4315 | newsym = bfd_make_empty_symbol (abfd); | |
4316 | newsym->name = fh->elf.root.root.string + 1; | |
4317 | newsym->section = bfd_und_section_ptr; | |
4318 | newsym->value = 0; | |
4319 | newsym->flags = BSF_OBJECT; | |
4320 | if (fh->elf.root.type == bfd_link_hash_undefweak) | |
4321 | newsym->flags |= BSF_WEAK; | |
4322 | ||
4323 | bh = &fdh->elf.root; | |
4324 | if ( !(_bfd_generic_link_add_one_symbol | |
4325 | (info, abfd, newsym->name, newsym->flags, | |
4326 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) | |
648cca2c | 4327 | { |
50bc7936 | 4328 | return FALSE; |
648cca2c | 4329 | } |
50bc7936 AM |
4330 | fdh = (struct ppc_link_hash_entry *) bh; |
4331 | fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF; | |
4332 | fdh->elf.size = 24; | |
4333 | fdh->elf.type = STT_OBJECT; | |
4334 | } | |
648cca2c | 4335 | |
50bc7936 AM |
4336 | if (fdh != NULL |
4337 | && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 | |
4338 | && (info->shared | |
4339 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4340 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 | |
4341 | || (fdh->elf.root.type == bfd_link_hash_undefweak | |
4342 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) | |
4343 | { | |
4344 | if (fdh->elf.dynindx == -1) | |
4345 | if (! bfd_elf64_link_record_dynamic_symbol (info, &fdh->elf)) | |
4346 | return FALSE; | |
4347 | fdh->elf.elf_link_hash_flags | |
4348 | |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
4349 | | ELF_LINK_HASH_REF_DYNAMIC | |
4350 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
4351 | | ELF_LINK_NON_GOT_REF)); | |
4352 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) | |
e86ce104 | 4353 | { |
50bc7936 AM |
4354 | fdh->elf.plt.plist = fh->elf.plt.plist; |
4355 | fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
e86ce104 | 4356 | } |
50bc7936 AM |
4357 | fdh->is_func_descriptor = 1; |
4358 | fdh->oh = &fh->elf; | |
4359 | fh->oh = &fdh->elf; | |
e86ce104 AM |
4360 | } |
4361 | ||
50bc7936 AM |
4362 | /* Now that the info is on the function descriptor, clear the |
4363 | function code sym info. Any function code syms for which we | |
4364 | don't have a definition in a regular file, we force local. | |
4365 | This prevents a shared library from exporting syms that have | |
4366 | been imported from another library. Function code syms that | |
4367 | are really in the library we must leave global to prevent the | |
4368 | linker dragging in a definition from a static library. */ | |
4369 | force_local | |
4370 | = (info->shared | |
4371 | && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4372 | || fdh == NULL | |
4373 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
4374 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)); | |
4375 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); | |
4376 | ||
b34976b6 | 4377 | return TRUE; |
e86ce104 | 4378 | } |
40b8271b | 4379 | |
82bd7b59 AM |
4380 | #define MIN_SAVE_FPR 14 |
4381 | #define MAX_SAVE_FPR 31 | |
4382 | ||
e86ce104 | 4383 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
82bd7b59 AM |
4384 | this hook to a) provide some gcc support functions, and b) transfer |
4385 | dynamic linking information gathered so far on function code symbol | |
4386 | entries, to their corresponding function descriptor symbol entries. */ | |
b34976b6 | 4387 | static bfd_boolean |
4ce794b7 AM |
4388 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
4389 | struct bfd_link_info *info) | |
e86ce104 AM |
4390 | { |
4391 | struct ppc_link_hash_table *htab; | |
82bd7b59 AM |
4392 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
4393 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; | |
4394 | unsigned int i; | |
4395 | struct elf_link_hash_entry *h; | |
721956f4 | 4396 | bfd_byte *p; |
82bd7b59 | 4397 | char sym[10]; |
e86ce104 AM |
4398 | |
4399 | htab = ppc_hash_table (info); | |
82bd7b59 AM |
4400 | |
4401 | if (htab->sfpr == NULL) | |
4402 | /* We don't have any relocs. */ | |
b34976b6 | 4403 | return TRUE; |
82bd7b59 AM |
4404 | |
4405 | /* First provide any missing ._savef* and ._restf* functions. */ | |
4406 | memcpy (sym, "._savef14", 10); | |
4407 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4408 | { | |
4409 | sym[7] = i / 10 + '0'; | |
4410 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4411 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4412 | if (h != NULL |
772119ce | 4413 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4414 | { |
4415 | if (lowest_savef > i) | |
4416 | lowest_savef = i; | |
4417 | h->root.type = bfd_link_hash_defined; | |
4418 | h->root.u.def.section = htab->sfpr; | |
4419 | h->root.u.def.value = (i - lowest_savef) * 4; | |
4420 | h->type = STT_FUNC; | |
4421 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4422 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4423 | } |
4424 | } | |
4425 | ||
4426 | memcpy (sym, "._restf14", 10); | |
4427 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) | |
4428 | { | |
4429 | sym[7] = i / 10 + '0'; | |
4430 | sym[8] = i % 10 + '0'; | |
b34976b6 | 4431 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
82bd7b59 | 4432 | if (h != NULL |
772119ce | 4433 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
82bd7b59 AM |
4434 | { |
4435 | if (lowest_restf > i) | |
4436 | lowest_restf = i; | |
4437 | h->root.type = bfd_link_hash_defined; | |
4438 | h->root.u.def.section = htab->sfpr; | |
4439 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 | |
4440 | + (i - lowest_restf) * 4); | |
4441 | h->type = STT_FUNC; | |
4442 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
772119ce | 4443 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
82bd7b59 AM |
4444 | } |
4445 | } | |
4446 | ||
4ce794b7 | 4447 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
805fc799 | 4448 | |
82bd7b59 AM |
4449 | htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
4450 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); | |
4451 | ||
4452 | if (htab->sfpr->_raw_size == 0) | |
805fc799 AM |
4453 | { |
4454 | if (!htab->have_undefweak) | |
4455 | { | |
4456 | _bfd_strip_section_from_output (info, htab->sfpr); | |
b34976b6 | 4457 | return TRUE; |
805fc799 AM |
4458 | } |
4459 | ||
4460 | htab->sfpr->_raw_size = 4; | |
4461 | } | |
82bd7b59 | 4462 | |
4ce794b7 | 4463 | p = bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size); |
721956f4 | 4464 | if (p == NULL) |
b34976b6 | 4465 | return FALSE; |
721956f4 AM |
4466 | htab->sfpr->contents = p; |
4467 | ||
4468 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) | |
4469 | { | |
4470 | unsigned int fpr = i << 21; | |
4471 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4472 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); | |
4473 | p += 4; | |
4474 | } | |
4475 | if (lowest_savef <= MAX_SAVE_FPR) | |
4476 | { | |
82bd7b59 AM |
4477 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
4478 | p += 4; | |
721956f4 | 4479 | } |
82bd7b59 | 4480 | |
721956f4 AM |
4481 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
4482 | { | |
4483 | unsigned int fpr = i << 21; | |
4484 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; | |
4485 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); | |
82bd7b59 AM |
4486 | p += 4; |
4487 | } | |
721956f4 AM |
4488 | if (lowest_restf <= MAX_SAVE_FPR |
4489 | || htab->sfpr->_raw_size == 4) | |
4490 | { | |
4491 | bfd_put_32 (htab->elf.dynobj, BLR, p); | |
4492 | } | |
82bd7b59 | 4493 | |
b34976b6 | 4494 | return TRUE; |
e86ce104 AM |
4495 | } |
4496 | ||
4497 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
4498 | regular object. The current definition is in some section of the | |
4499 | dynamic object, but we're not including those sections. We have to | |
4500 | change the definition to something the rest of the link can | |
4501 | understand. */ | |
4502 | ||
b34976b6 | 4503 | static bfd_boolean |
4ce794b7 AM |
4504 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
4505 | struct elf_link_hash_entry *h) | |
e86ce104 AM |
4506 | { |
4507 | struct ppc_link_hash_table *htab; | |
e86ce104 AM |
4508 | asection *s; |
4509 | unsigned int power_of_two; | |
4510 | ||
4511 | htab = ppc_hash_table (info); | |
4512 | ||
4513 | /* Deal with function syms. */ | |
4514 | if (h->type == STT_FUNC | |
4515 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
4516 | { | |
4517 | /* Clear procedure linkage table information for any symbol that | |
4518 | won't need a .plt entry. */ | |
411e1bfb AM |
4519 | struct plt_entry *ent; |
4520 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
4521 | if (ent->plt.refcount > 0) | |
4522 | break; | |
e86ce104 | 4523 | if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor |
411e1bfb | 4524 | || ent == NULL |
9c7a29a3 AM |
4525 | || SYMBOL_CALLS_LOCAL (info, h) |
4526 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
4527 | && h->root.type == bfd_link_hash_undefweak)) | |
40b8271b | 4528 | { |
411e1bfb | 4529 | h->plt.plist = NULL; |
40b8271b | 4530 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
40b8271b | 4531 | } |
5bd4f169 | 4532 | } |
bbd7ec4a | 4533 | else |
411e1bfb | 4534 | h->plt.plist = NULL; |
5bd4f169 AM |
4535 | |
4536 | /* If this is a weak symbol, and there is a real definition, the | |
4537 | processor independent code will have arranged for us to see the | |
4538 | real definition first, and we can just use the same value. */ | |
4539 | if (h->weakdef != NULL) | |
4540 | { | |
4541 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
4542 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
4543 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
4544 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
a23b6845 AM |
4545 | if (ELIMINATE_COPY_RELOCS) |
4546 | h->elf_link_hash_flags | |
4547 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) | |
4548 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); | |
b34976b6 | 4549 | return TRUE; |
5bd4f169 AM |
4550 | } |
4551 | ||
5bd4f169 AM |
4552 | /* If we are creating a shared library, we must presume that the |
4553 | only references to the symbol are via the global offset table. | |
4554 | For such cases we need not do anything here; the relocations will | |
4555 | be handled correctly by relocate_section. */ | |
4556 | if (info->shared) | |
b34976b6 | 4557 | return TRUE; |
5bd4f169 | 4558 | |
65f38f15 AM |
4559 | /* If there are no references to this symbol that do not use the |
4560 | GOT, we don't need to generate a copy reloc. */ | |
4561 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 4562 | return TRUE; |
65f38f15 | 4563 | |
f4656909 | 4564 | if (ELIMINATE_COPY_RELOCS) |
65f38f15 | 4565 | { |
f4656909 AM |
4566 | struct ppc_link_hash_entry * eh; |
4567 | struct ppc_dyn_relocs *p; | |
65f38f15 | 4568 | |
f4656909 AM |
4569 | eh = (struct ppc_link_hash_entry *) h; |
4570 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
4571 | { | |
4572 | s = p->sec->output_section; | |
4573 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
4574 | break; | |
4575 | } | |
4576 | ||
4577 | /* If we didn't find any dynamic relocs in read-only sections, then | |
4578 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
4579 | if (p == NULL) | |
4580 | { | |
4581 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
4582 | return TRUE; | |
4583 | } | |
65f38f15 AM |
4584 | } |
4585 | ||
5d35169e | 4586 | if (h->plt.plist != NULL) |
97b639ba AM |
4587 | { |
4588 | /* We should never get here, but unfortunately there are versions | |
4589 | of gcc out there that improperly (for this ABI) put initialized | |
4590 | function pointers, vtable refs and suchlike in read-only | |
4591 | sections. Allow them to proceed, but warn that this might | |
4592 | break at runtime. */ | |
4593 | (*_bfd_error_handler) | |
4594 | (_("copy reloc against `%s' requires lazy plt linking; " | |
4595 | "avoid setting LD_BIND_NOW=1 or upgrade gcc"), | |
4596 | h->root.root.string); | |
4597 | } | |
5d35169e AM |
4598 | |
4599 | /* This is a reference to a symbol defined by a dynamic object which | |
4600 | is not a function. */ | |
4601 | ||
5bd4f169 AM |
4602 | /* We must allocate the symbol in our .dynbss section, which will |
4603 | become part of the .bss section of the executable. There will be | |
4604 | an entry for this symbol in the .dynsym section. The dynamic | |
4605 | object will contain position independent code, so all references | |
4606 | from the dynamic object to this symbol will go through the global | |
4607 | offset table. The dynamic linker will use the .dynsym entry to | |
4608 | determine the address it must put in the global offset table, so | |
4609 | both the dynamic object and the regular object will refer to the | |
4610 | same memory location for the variable. */ | |
5bd4f169 | 4611 | |
04c9666a AM |
4612 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
4613 | to copy the initial value out of the dynamic object and into the | |
5bd4f169 AM |
4614 | runtime process image. We need to remember the offset into the |
4615 | .rela.bss section we are going to use. */ | |
4616 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
4617 | { | |
4ce794b7 | 4618 | htab->relbss->_raw_size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
4619 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
4620 | } | |
4621 | ||
4622 | /* We need to figure out the alignment required for this symbol. I | |
4623 | have no idea how ELF linkers handle this. */ | |
4624 | power_of_two = bfd_log2 (h->size); | |
4625 | if (power_of_two > 4) | |
4626 | power_of_two = 4; | |
4627 | ||
4628 | /* Apply the required alignment. */ | |
4ce794b7 | 4629 | s = htab->dynbss; |
65f38f15 AM |
4630 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); |
4631 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
5bd4f169 | 4632 | { |
65f38f15 | 4633 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 4634 | return FALSE; |
5bd4f169 AM |
4635 | } |
4636 | ||
4637 | /* Define the symbol as being at this point in the section. */ | |
4638 | h->root.u.def.section = s; | |
4639 | h->root.u.def.value = s->_raw_size; | |
4640 | ||
4641 | /* Increment the section size to make room for the symbol. */ | |
4642 | s->_raw_size += h->size; | |
4643 | ||
b34976b6 | 4644 | return TRUE; |
5bd4f169 AM |
4645 | } |
4646 | ||
e86ce104 AM |
4647 | /* If given a function descriptor symbol, hide both the function code |
4648 | sym and the descriptor. */ | |
4649 | static void | |
4ce794b7 AM |
4650 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
4651 | struct elf_link_hash_entry *h, | |
4652 | bfd_boolean force_local) | |
e86ce104 AM |
4653 | { |
4654 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); | |
4655 | ||
4656 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) | |
4657 | { | |
721956f4 | 4658 | struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh; |
e86ce104 | 4659 | |
721956f4 | 4660 | if (fh == NULL) |
d1329ca3 AM |
4661 | { |
4662 | const char *p, *q; | |
4663 | struct ppc_link_hash_table *htab; | |
4664 | char save; | |
4665 | ||
4666 | /* We aren't supposed to use alloca in BFD because on | |
4667 | systems which do not have alloca the version in libiberty | |
4668 | calls xmalloc, which might cause the program to crash | |
4669 | when it runs out of memory. This function doesn't have a | |
4670 | return status, so there's no way to gracefully return an | |
4671 | error. So cheat. We know that string[-1] can be safely | |
4672 | dereferenced; It's either a string in an ELF string | |
4673 | table, or allocated in an objalloc structure. */ | |
4674 | ||
4675 | p = h->root.root.string - 1; | |
4676 | save = *p; | |
4677 | *(char *) p = '.'; | |
4678 | htab = ppc_hash_table (info); | |
b34976b6 | 4679 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
4680 | *(char *) p = save; |
4681 | ||
4682 | /* Unfortunately, if it so happens that the string we were | |
4683 | looking for was allocated immediately before this string, | |
4684 | then we overwrote the string terminator. That's the only | |
4685 | reason the lookup should fail. */ | |
4686 | if (fh == NULL) | |
4687 | { | |
4688 | q = h->root.root.string + strlen (h->root.root.string); | |
4689 | while (q >= h->root.root.string && *q == *p) | |
4690 | --q, --p; | |
4691 | if (q < h->root.root.string && *p == '.') | |
b34976b6 | 4692 | fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
d1329ca3 AM |
4693 | } |
4694 | if (fh != NULL) | |
4695 | { | |
4696 | ((struct ppc_link_hash_entry *) h)->oh = fh; | |
4697 | ((struct ppc_link_hash_entry *) fh)->oh = h; | |
4698 | } | |
4699 | } | |
e86ce104 AM |
4700 | if (fh != NULL) |
4701 | _bfd_elf_link_hash_hide_symbol (info, fh, force_local); | |
4702 | } | |
4703 | } | |
4704 | ||
411e1bfb | 4705 | static bfd_boolean |
4ce794b7 AM |
4706 | get_sym_h (struct elf_link_hash_entry **hp, Elf_Internal_Sym **symp, |
4707 | asection **symsecp, char **tls_maskp, Elf_Internal_Sym **locsymsp, | |
4708 | unsigned long r_symndx, bfd *ibfd) | |
411e1bfb AM |
4709 | { |
4710 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
4711 | ||
4712 | if (r_symndx >= symtab_hdr->sh_info) | |
4713 | { | |
4714 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); | |
4715 | struct elf_link_hash_entry *h; | |
4716 | ||
4717 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4718 | while (h->root.type == bfd_link_hash_indirect | |
4719 | || h->root.type == bfd_link_hash_warning) | |
4720 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4721 | ||
4722 | if (hp != NULL) | |
4723 | *hp = h; | |
4724 | ||
4725 | if (symp != NULL) | |
4726 | *symp = NULL; | |
4727 | ||
4728 | if (symsecp != NULL) | |
4729 | { | |
4730 | asection *symsec = NULL; | |
4731 | if (h->root.type == bfd_link_hash_defined | |
4732 | || h->root.type == bfd_link_hash_defweak) | |
4733 | symsec = h->root.u.def.section; | |
4734 | *symsecp = symsec; | |
4735 | } | |
4736 | ||
e7b938ca | 4737 | if (tls_maskp != NULL) |
411e1bfb AM |
4738 | { |
4739 | struct ppc_link_hash_entry *eh; | |
4740 | ||
4741 | eh = (struct ppc_link_hash_entry *) h; | |
e7b938ca | 4742 | *tls_maskp = &eh->tls_mask; |
411e1bfb AM |
4743 | } |
4744 | } | |
4745 | else | |
4746 | { | |
4747 | Elf_Internal_Sym *sym; | |
4748 | Elf_Internal_Sym *locsyms = *locsymsp; | |
4749 | ||
4750 | if (locsyms == NULL) | |
4751 | { | |
4752 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4753 | if (locsyms == NULL) | |
4754 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
4755 | symtab_hdr->sh_info, | |
4756 | 0, NULL, NULL, NULL); | |
4757 | if (locsyms == NULL) | |
4758 | return FALSE; | |
4759 | *locsymsp = locsyms; | |
4760 | } | |
4761 | sym = locsyms + r_symndx; | |
4762 | ||
4763 | if (hp != NULL) | |
4764 | *hp = NULL; | |
4765 | ||
4766 | if (symp != NULL) | |
4767 | *symp = sym; | |
4768 | ||
4769 | if (symsecp != NULL) | |
4770 | { | |
4771 | asection *symsec = NULL; | |
4772 | if ((sym->st_shndx != SHN_UNDEF | |
4773 | && sym->st_shndx < SHN_LORESERVE) | |
4774 | || sym->st_shndx > SHN_HIRESERVE) | |
4775 | symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); | |
4776 | *symsecp = symsec; | |
4777 | } | |
4778 | ||
e7b938ca | 4779 | if (tls_maskp != NULL) |
411e1bfb AM |
4780 | { |
4781 | struct got_entry **lgot_ents; | |
e7b938ca | 4782 | char *tls_mask; |
411e1bfb | 4783 | |
e7b938ca | 4784 | tls_mask = NULL; |
411e1bfb AM |
4785 | lgot_ents = elf_local_got_ents (ibfd); |
4786 | if (lgot_ents != NULL) | |
4787 | { | |
e7b938ca AM |
4788 | char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info); |
4789 | tls_mask = &lgot_masks[r_symndx]; | |
411e1bfb | 4790 | } |
e7b938ca | 4791 | *tls_maskp = tls_mask; |
411e1bfb AM |
4792 | } |
4793 | } | |
4794 | return TRUE; | |
4795 | } | |
4796 | ||
e7b938ca | 4797 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
951fd09b | 4798 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
ad8e1ba5 | 4799 | type suitable for optimization, and 1 otherwise. */ |
951fd09b AM |
4800 | |
4801 | static int | |
4ce794b7 AM |
4802 | get_tls_mask (char **tls_maskp, Elf_Internal_Sym **locsymsp, |
4803 | const Elf_Internal_Rela *rel, bfd *ibfd) | |
411e1bfb AM |
4804 | { |
4805 | unsigned long r_symndx; | |
951fd09b | 4806 | unsigned int next_r; |
411e1bfb AM |
4807 | struct elf_link_hash_entry *h; |
4808 | Elf_Internal_Sym *sym; | |
4809 | asection *sec; | |
4810 | bfd_vma off; | |
4811 | ||
4812 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 4813 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b | 4814 | return 0; |
411e1bfb | 4815 | |
e7b938ca | 4816 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
411e1bfb AM |
4817 | || sec == NULL |
4818 | || ppc64_elf_section_data (sec)->t_symndx == NULL) | |
951fd09b | 4819 | return 1; |
411e1bfb AM |
4820 | |
4821 | /* Look inside a TOC section too. */ | |
4822 | if (h != NULL) | |
4823 | { | |
4824 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); | |
4825 | off = h->root.u.def.value; | |
4826 | } | |
4827 | else | |
4828 | off = sym->st_value; | |
4829 | off += rel->r_addend; | |
4830 | BFD_ASSERT (off % 8 == 0); | |
4831 | r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8]; | |
951fd09b | 4832 | next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1]; |
e7b938ca | 4833 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
951fd09b AM |
4834 | return 0; |
4835 | if (h == NULL | |
4836 | || h->root.type == bfd_link_hash_defined | |
4837 | || h->root.type == bfd_link_hash_defweak) | |
4838 | { | |
4839 | if (next_r == (unsigned) -1) | |
4840 | return 2; | |
4841 | if (next_r == (unsigned) -2 | |
4842 | && (h == NULL | |
4843 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
4844 | return 3; | |
4845 | } | |
4846 | return 1; | |
411e1bfb AM |
4847 | } |
4848 | ||
b34976b6 | 4849 | bfd_boolean |
4ce794b7 | 4850 | ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info) |
1e2f5b6e AM |
4851 | { |
4852 | bfd *ibfd; | |
1e2f5b6e | 4853 | |
411e1bfb | 4854 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1e2f5b6e AM |
4855 | { |
4856 | asection *sec; | |
4857 | Elf_Internal_Rela *relstart, *rel, *relend; | |
4858 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 4859 | Elf_Internal_Sym *local_syms; |
1e2f5b6e AM |
4860 | struct elf_link_hash_entry **sym_hashes; |
4861 | bfd_vma offset; | |
d6fe2dc1 | 4862 | bfd_size_type amt; |
1e2f5b6e | 4863 | long *adjust; |
b34976b6 | 4864 | bfd_boolean need_edit; |
1e2f5b6e AM |
4865 | |
4866 | sec = bfd_get_section_by_name (ibfd, ".opd"); | |
4867 | if (sec == NULL) | |
4868 | continue; | |
4869 | ||
d6fe2dc1 | 4870 | amt = sec->_raw_size * sizeof (long) / 24; |
f0abc2a1 | 4871 | adjust = ppc64_elf_section_data (sec)->opd.adjust; |
d6fe2dc1 AM |
4872 | if (adjust == NULL) |
4873 | { | |
4874 | /* Must be a ld -r link. ie. check_relocs hasn't been | |
4875 | called. */ | |
4ce794b7 | 4876 | adjust = bfd_zalloc (obfd, amt); |
f0abc2a1 | 4877 | ppc64_elf_section_data (sec)->opd.adjust = adjust; |
d6fe2dc1 | 4878 | } |
4ce794b7 | 4879 | memset (adjust, 0, amt); |
1e2f5b6e AM |
4880 | |
4881 | if (sec->output_section == bfd_abs_section_ptr) | |
4882 | continue; | |
4883 | ||
4884 | /* Look through the section relocs. */ | |
4885 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
4886 | continue; | |
4887 | ||
6cdc0ccc | 4888 | local_syms = NULL; |
1e2f5b6e AM |
4889 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
4890 | sym_hashes = elf_sym_hashes (ibfd); | |
4891 | ||
4892 | /* Read the relocations. */ | |
4ce794b7 | 4893 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 4894 | info->keep_memory); |
1e2f5b6e | 4895 | if (relstart == NULL) |
b34976b6 | 4896 | return FALSE; |
1e2f5b6e AM |
4897 | |
4898 | /* First run through the relocs to check they are sane, and to | |
4899 | determine whether we need to edit this opd section. */ | |
b34976b6 | 4900 | need_edit = FALSE; |
1e2f5b6e AM |
4901 | offset = 0; |
4902 | relend = relstart + sec->reloc_count; | |
50bc7936 | 4903 | for (rel = relstart; rel < relend; ) |
1e2f5b6e | 4904 | { |
04c9666a | 4905 | enum elf_ppc64_reloc_type r_type; |
1e2f5b6e AM |
4906 | unsigned long r_symndx; |
4907 | asection *sym_sec; | |
4908 | struct elf_link_hash_entry *h; | |
4909 | Elf_Internal_Sym *sym; | |
4910 | ||
4911 | /* .opd contains a regular array of 24 byte entries. We're | |
4912 | only interested in the reloc pointing to a function entry | |
4913 | point. */ | |
50bc7936 AM |
4914 | if (rel->r_offset != offset |
4915 | || rel + 1 >= relend | |
4916 | || (rel + 1)->r_offset != offset + 8) | |
1e2f5b6e AM |
4917 | { |
4918 | /* If someone messes with .opd alignment then after a | |
4919 | "ld -r" we might have padding in the middle of .opd. | |
4920 | Also, there's nothing to prevent someone putting | |
4921 | something silly in .opd with the assembler. No .opd | |
b34976b6 | 4922 | optimization for them! */ |
1e2f5b6e AM |
4923 | (*_bfd_error_handler) |
4924 | (_("%s: .opd is not a regular array of opd entries"), | |
4925 | bfd_archive_filename (ibfd)); | |
b34976b6 | 4926 | need_edit = FALSE; |
1e2f5b6e AM |
4927 | break; |
4928 | } | |
4929 | ||
50bc7936 AM |
4930 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
4931 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) | |
4932 | { | |
4933 | (*_bfd_error_handler) | |
4934 | (_("%s: unexpected reloc type %u in .opd section"), | |
4935 | bfd_archive_filename (ibfd), r_type); | |
4936 | need_edit = FALSE; | |
4937 | break; | |
4938 | } | |
4939 | ||
1e2f5b6e | 4940 | r_symndx = ELF64_R_SYM (rel->r_info); |
411e1bfb AM |
4941 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
4942 | r_symndx, ibfd)) | |
50bc7936 | 4943 | goto error_ret; |
1e2f5b6e AM |
4944 | |
4945 | if (sym_sec == NULL || sym_sec->owner == NULL) | |
4946 | { | |
411e1bfb AM |
4947 | const char *sym_name; |
4948 | if (h != NULL) | |
4949 | sym_name = h->root.root.string; | |
4950 | else | |
4951 | sym_name = bfd_elf_local_sym_name (ibfd, sym); | |
4952 | ||
1e2f5b6e AM |
4953 | (*_bfd_error_handler) |
4954 | (_("%s: undefined sym `%s' in .opd section"), | |
4955 | bfd_archive_filename (ibfd), | |
411e1bfb | 4956 | sym_name); |
b34976b6 | 4957 | need_edit = FALSE; |
1e2f5b6e AM |
4958 | break; |
4959 | } | |
4960 | ||
51020317 AM |
4961 | /* opd entries are always for functions defined in the |
4962 | current input bfd. If the symbol isn't defined in the | |
4963 | input bfd, then we won't be using the function in this | |
4964 | bfd; It must be defined in a linkonce section in another | |
4965 | bfd, or is weak. It's also possible that we are | |
4966 | discarding the function due to a linker script /DISCARD/, | |
4967 | which we test for via the output_section. */ | |
4968 | if (sym_sec->owner != ibfd | |
4969 | || sym_sec->output_section == bfd_abs_section_ptr) | |
b34976b6 | 4970 | need_edit = TRUE; |
1e2f5b6e AM |
4971 | |
4972 | offset += 24; | |
50bc7936 AM |
4973 | rel += 2; |
4974 | /* Allow for the possibility of a reloc on the third word. */ | |
4975 | if (rel < relend | |
4976 | && rel->r_offset == offset - 8) | |
4977 | rel += 1; | |
1e2f5b6e AM |
4978 | } |
4979 | ||
4980 | if (need_edit) | |
4981 | { | |
4982 | Elf_Internal_Rela *write_rel; | |
4983 | bfd_byte *rptr, *wptr; | |
b34976b6 | 4984 | bfd_boolean skip; |
1e2f5b6e AM |
4985 | |
4986 | /* This seems a waste of time as input .opd sections are all | |
4987 | zeros as generated by gcc, but I suppose there's no reason | |
4988 | this will always be so. We might start putting something in | |
4989 | the third word of .opd entries. */ | |
4990 | if ((sec->flags & SEC_IN_MEMORY) == 0) | |
4991 | { | |
4992 | bfd_byte *loc = bfd_alloc (ibfd, sec->_raw_size); | |
6cdc0ccc | 4993 | if (loc == NULL |
4ce794b7 | 4994 | || !bfd_get_section_contents (ibfd, sec, loc, 0, |
6cdc0ccc AM |
4995 | sec->_raw_size)) |
4996 | { | |
50bc7936 | 4997 | error_ret: |
6cdc0ccc AM |
4998 | if (local_syms != NULL |
4999 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5000 | free (local_syms); | |
6cdc0ccc AM |
5001 | if (elf_section_data (sec)->relocs != relstart) |
5002 | free (relstart); | |
b34976b6 | 5003 | return FALSE; |
6cdc0ccc | 5004 | } |
1e2f5b6e AM |
5005 | sec->contents = loc; |
5006 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); | |
5007 | } | |
5008 | ||
5009 | elf_section_data (sec)->relocs = relstart; | |
5010 | ||
5011 | wptr = sec->contents; | |
5012 | rptr = sec->contents; | |
5013 | write_rel = relstart; | |
b34976b6 | 5014 | skip = FALSE; |
1e2f5b6e AM |
5015 | offset = 0; |
5016 | for (rel = relstart; rel < relend; rel++) | |
5017 | { | |
50bc7936 AM |
5018 | unsigned long r_symndx; |
5019 | asection *sym_sec; | |
5020 | struct elf_link_hash_entry *h; | |
5021 | Elf_Internal_Sym *sym; | |
5022 | ||
5023 | r_symndx = ELF64_R_SYM (rel->r_info); | |
5024 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, | |
5025 | r_symndx, ibfd)) | |
5026 | goto error_ret; | |
5027 | ||
1e2f5b6e AM |
5028 | if (rel->r_offset == offset) |
5029 | { | |
50bc7936 AM |
5030 | struct ppc_link_hash_entry *fdh = NULL; |
5031 | if (h != NULL) | |
5032 | fdh = get_fdh ((struct ppc_link_hash_entry *) h, | |
5033 | ppc_hash_table (info)); | |
1e2f5b6e | 5034 | |
51020317 AM |
5035 | skip = (sym_sec->owner != ibfd |
5036 | || sym_sec->output_section == bfd_abs_section_ptr); | |
a4aa0fb7 AM |
5037 | if (skip) |
5038 | { | |
0be617ce | 5039 | if (h != NULL && sym_sec->owner == ibfd) |
a4aa0fb7 AM |
5040 | { |
5041 | /* Arrange for the function descriptor sym | |
5042 | to be dropped. */ | |
d6fe2dc1 AM |
5043 | fdh->elf.root.u.def.value = 0; |
5044 | fdh->elf.root.u.def.section = sym_sec; | |
a4aa0fb7 AM |
5045 | } |
5046 | } | |
5047 | else | |
1e2f5b6e AM |
5048 | { |
5049 | /* We'll be keeping this opd entry. */ | |
5050 | ||
5051 | if (h != NULL) | |
5052 | { | |
5053 | /* Redefine the function descriptor symbol | |
5054 | to this location in the opd section. | |
5055 | We've checked above that opd relocs are | |
5056 | ordered. */ | |
d6fe2dc1 | 5057 | fdh->elf.root.u.def.value = wptr - sec->contents; |
1e2f5b6e AM |
5058 | } |
5059 | else | |
5060 | { | |
6cdc0ccc AM |
5061 | /* Local syms are a bit tricky. We could |
5062 | tweak them as they can be cached, but | |
5063 | we'd need to look through the local syms | |
5064 | for the function descriptor sym which we | |
5065 | don't have at the moment. So keep an | |
b34976b6 | 5066 | array of adjustments. */ |
7f6a7663 | 5067 | adjust[rel->r_offset / 24] = wptr - rptr; |
1e2f5b6e AM |
5068 | } |
5069 | ||
5070 | if (wptr != rptr) | |
5071 | memcpy (wptr, rptr, 24); | |
5072 | wptr += 24; | |
5073 | } | |
5074 | rptr += 24; | |
5075 | offset += 24; | |
5076 | } | |
5077 | ||
50bc7936 AM |
5078 | if (skip) |
5079 | { | |
5080 | BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info))); | |
5081 | if (info->shared) | |
5082 | { | |
5083 | /* We won't be needing dynamic relocs here. */ | |
5084 | struct ppc_dyn_relocs **pp; | |
5085 | struct ppc_dyn_relocs *p; | |
5086 | ||
5087 | if (h != NULL) | |
5088 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; | |
5089 | else if (sym_sec != NULL) | |
5090 | pp = ((struct ppc_dyn_relocs **) | |
5091 | &elf_section_data (sym_sec)->local_dynrel); | |
5092 | else | |
5093 | pp = ((struct ppc_dyn_relocs **) | |
5094 | &elf_section_data (sec)->local_dynrel); | |
5095 | while ((p = *pp) != NULL) | |
5096 | { | |
5097 | if (p->sec == sec) | |
5098 | { | |
5099 | p->count -= 1; | |
5100 | if (p->count == 0) | |
5101 | *pp = p->next; | |
5102 | break; | |
5103 | } | |
5104 | pp = &p->next; | |
5105 | } | |
5106 | } | |
5107 | } | |
5108 | else | |
1e2f5b6e | 5109 | { |
50bc7936 AM |
5110 | /* We need to adjust any reloc offsets to point to the |
5111 | new opd entries. While we're at it, we may as well | |
5112 | remove redundant relocs. */ | |
1e2f5b6e AM |
5113 | rel->r_offset += wptr - rptr; |
5114 | if (write_rel != rel) | |
5115 | memcpy (write_rel, rel, sizeof (*rel)); | |
5116 | ++write_rel; | |
5117 | } | |
5118 | } | |
5119 | ||
5120 | sec->_cooked_size = wptr - sec->contents; | |
5121 | sec->reloc_count = write_rel - relstart; | |
cdcf6e38 AM |
5122 | /* Fudge the size too, as this is used later in |
5123 | elf_bfd_final_link if we are emitting relocs. */ | |
5124 | elf_section_data (sec)->rel_hdr.sh_size | |
5125 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; | |
5126 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); | |
1e2f5b6e | 5127 | } |
6cdc0ccc | 5128 | else if (elf_section_data (sec)->relocs != relstart) |
1e2f5b6e | 5129 | free (relstart); |
6cdc0ccc | 5130 | |
411e1bfb AM |
5131 | if (local_syms != NULL |
5132 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
5133 | { | |
5134 | if (!info->keep_memory) | |
5135 | free (local_syms); | |
5136 | else | |
5137 | symtab_hdr->contents = (unsigned char *) local_syms; | |
5138 | } | |
5139 | } | |
5140 | ||
5141 | return TRUE; | |
5142 | } | |
5143 | ||
951fd09b | 5144 | /* Set htab->tls_sec. */ |
411e1bfb AM |
5145 | |
5146 | bfd_boolean | |
4ce794b7 | 5147 | ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
411e1bfb AM |
5148 | { |
5149 | asection *tls; | |
411e1bfb AM |
5150 | struct ppc_link_hash_table *htab; |
5151 | ||
411e1bfb AM |
5152 | for (tls = obfd->sections; tls != NULL; tls = tls->next) |
5153 | if ((tls->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) | |
5154 | == (SEC_THREAD_LOCAL | SEC_LOAD)) | |
5155 | break; | |
411e1bfb AM |
5156 | |
5157 | htab = ppc_hash_table (info); | |
5158 | htab->tls_sec = tls; | |
a48ebf4d AM |
5159 | |
5160 | if (htab->tls_get_addr != NULL) | |
5161 | { | |
5162 | struct elf_link_hash_entry *h = htab->tls_get_addr; | |
5163 | ||
5164 | while (h->root.type == bfd_link_hash_indirect | |
5165 | || h->root.type == bfd_link_hash_warning) | |
5166 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5167 | ||
5168 | htab->tls_get_addr = h; | |
5169 | } | |
5170 | ||
951fd09b AM |
5171 | return tls != NULL; |
5172 | } | |
411e1bfb | 5173 | |
951fd09b AM |
5174 | /* Run through all the TLS relocs looking for optimization |
5175 | opportunities. The linker has been hacked (see ppc64elf.em) to do | |
5176 | a preliminary section layout so that we know the TLS segment | |
5177 | offsets. We can't optimize earlier because some optimizations need | |
5178 | to know the tp offset, and we need to optimize before allocating | |
5179 | dynamic relocations. */ | |
5180 | ||
5181 | bfd_boolean | |
4ce794b7 | 5182 | ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) |
951fd09b AM |
5183 | { |
5184 | bfd *ibfd; | |
5185 | asection *sec; | |
5186 | struct ppc_link_hash_table *htab; | |
5187 | ||
1049f94e | 5188 | if (info->relocatable || info->shared) |
411e1bfb AM |
5189 | return TRUE; |
5190 | ||
951fd09b | 5191 | htab = ppc_hash_table (info); |
411e1bfb AM |
5192 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5193 | { | |
5194 | Elf_Internal_Sym *locsyms = NULL; | |
5195 | ||
5196 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
5197 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
5198 | { | |
5199 | Elf_Internal_Rela *relstart, *rel, *relend; | |
5200 | int expecting_tls_get_addr; | |
5201 | ||
5202 | /* Read the relocations. */ | |
4ce794b7 | 5203 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
45d6a902 | 5204 | info->keep_memory); |
411e1bfb AM |
5205 | if (relstart == NULL) |
5206 | return FALSE; | |
5207 | ||
5208 | expecting_tls_get_addr = 0; | |
5209 | relend = relstart + sec->reloc_count; | |
5210 | for (rel = relstart; rel < relend; rel++) | |
5211 | { | |
5212 | enum elf_ppc64_reloc_type r_type; | |
5213 | unsigned long r_symndx; | |
5214 | struct elf_link_hash_entry *h; | |
5215 | Elf_Internal_Sym *sym; | |
5216 | asection *sym_sec; | |
e7b938ca AM |
5217 | char *tls_mask; |
5218 | char tls_set, tls_clear, tls_type = 0; | |
411e1bfb | 5219 | bfd_vma value; |
951fd09b | 5220 | bfd_boolean ok_tprel, is_local; |
411e1bfb AM |
5221 | |
5222 | r_symndx = ELF64_R_SYM (rel->r_info); | |
e7b938ca | 5223 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, |
411e1bfb AM |
5224 | r_symndx, ibfd)) |
5225 | { | |
5226 | err_free_rel: | |
5227 | if (elf_section_data (sec)->relocs != relstart) | |
5228 | free (relstart); | |
5229 | if (locsyms != NULL | |
5230 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5231 | != (unsigned char *) locsyms)) | |
5232 | free (locsyms); | |
5233 | return FALSE; | |
5234 | } | |
5235 | ||
5236 | if (h != NULL) | |
5237 | { | |
5238 | if (h->root.type != bfd_link_hash_defined | |
5239 | && h->root.type != bfd_link_hash_defweak) | |
5240 | continue; | |
5241 | value = h->root.u.def.value; | |
5242 | } | |
5243 | else | |
5244 | value = sym->st_value; | |
951fd09b | 5245 | |
411e1bfb | 5246 | ok_tprel = FALSE; |
951fd09b AM |
5247 | is_local = FALSE; |
5248 | if (h == NULL | |
5249 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5250 | { |
951fd09b | 5251 | is_local = TRUE; |
411e1bfb AM |
5252 | value += sym_sec->output_offset; |
5253 | value += sym_sec->output_section->vma; | |
5254 | value -= htab->tls_sec->vma; | |
5255 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) | |
5256 | < (bfd_vma) 1 << 32); | |
5257 | } | |
5258 | ||
4ce794b7 | 5259 | r_type = ELF64_R_TYPE (rel->r_info); |
411e1bfb AM |
5260 | switch (r_type) |
5261 | { | |
5262 | case R_PPC64_GOT_TLSLD16: | |
5263 | case R_PPC64_GOT_TLSLD16_LO: | |
5264 | case R_PPC64_GOT_TLSLD16_HI: | |
5265 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b AM |
5266 | /* These relocs should never be against a symbol |
5267 | defined in a shared lib. Leave them alone if | |
5268 | that turns out to be the case. */ | |
e717da7e | 5269 | ppc64_tlsld_got (ibfd)->refcount -= 1; |
951fd09b AM |
5270 | if (!is_local) |
5271 | continue; | |
5272 | ||
951fd09b AM |
5273 | /* LD -> LE */ |
5274 | tls_set = 0; | |
5275 | tls_clear = TLS_LD; | |
e7b938ca | 5276 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
5277 | expecting_tls_get_addr = 1; |
5278 | break; | |
5279 | ||
5280 | case R_PPC64_GOT_TLSGD16: | |
5281 | case R_PPC64_GOT_TLSGD16_LO: | |
5282 | case R_PPC64_GOT_TLSGD16_HI: | |
5283 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 5284 | if (ok_tprel) |
411e1bfb AM |
5285 | /* GD -> LE */ |
5286 | tls_set = 0; | |
5287 | else | |
5288 | /* GD -> IE */ | |
951fd09b AM |
5289 | tls_set = TLS_TLS | TLS_TPRELGD; |
5290 | tls_clear = TLS_GD; | |
e7b938ca | 5291 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
5292 | expecting_tls_get_addr = 1; |
5293 | break; | |
5294 | ||
5295 | case R_PPC64_GOT_TPREL16_DS: | |
5296 | case R_PPC64_GOT_TPREL16_LO_DS: | |
5297 | case R_PPC64_GOT_TPREL16_HI: | |
5298 | case R_PPC64_GOT_TPREL16_HA: | |
5299 | expecting_tls_get_addr = 0; | |
5300 | if (ok_tprel) | |
5301 | { | |
5302 | /* IE -> LE */ | |
5303 | tls_set = 0; | |
5304 | tls_clear = TLS_TPREL; | |
e7b938ca | 5305 | tls_type = TLS_TLS | TLS_TPREL; |
411e1bfb AM |
5306 | break; |
5307 | } | |
5308 | else | |
5309 | continue; | |
5310 | ||
5311 | case R_PPC64_REL14: | |
5312 | case R_PPC64_REL14_BRTAKEN: | |
5313 | case R_PPC64_REL14_BRNTAKEN: | |
5314 | case R_PPC64_REL24: | |
5315 | if (h != NULL | |
5316 | && h == htab->tls_get_addr) | |
5317 | { | |
5318 | if (!expecting_tls_get_addr | |
5319 | && rel != relstart | |
5320 | && ((ELF64_R_TYPE (rel[-1].r_info) | |
5321 | == R_PPC64_TOC16) | |
5322 | || (ELF64_R_TYPE (rel[-1].r_info) | |
5323 | == R_PPC64_TOC16_LO))) | |
5324 | { | |
5325 | /* Check for toc tls entries. */ | |
5326 | char *toc_tls; | |
951fd09b | 5327 | int retval; |
411e1bfb | 5328 | |
e7b938ca | 5329 | retval = get_tls_mask (&toc_tls, &locsyms, |
951fd09b AM |
5330 | rel - 1, ibfd); |
5331 | if (retval == 0) | |
411e1bfb AM |
5332 | goto err_free_rel; |
5333 | if (toc_tls != NULL) | |
951fd09b | 5334 | expecting_tls_get_addr = retval > 1; |
411e1bfb AM |
5335 | } |
5336 | ||
5337 | if (expecting_tls_get_addr) | |
5338 | { | |
5339 | struct plt_entry *ent; | |
5340 | for (ent = h->plt.plist; ent; ent = ent->next) | |
5341 | if (ent->addend == 0) | |
5342 | { | |
5343 | if (ent->plt.refcount > 0) | |
5344 | ent->plt.refcount -= 1; | |
5345 | break; | |
5346 | } | |
5347 | } | |
5348 | } | |
5349 | expecting_tls_get_addr = 0; | |
5350 | continue; | |
5351 | ||
5352 | case R_PPC64_TPREL64: | |
5353 | expecting_tls_get_addr = 0; | |
5354 | if (ok_tprel) | |
5355 | { | |
5356 | /* IE -> LE */ | |
5357 | tls_set = TLS_EXPLICIT; | |
5358 | tls_clear = TLS_TPREL; | |
5359 | break; | |
5360 | } | |
5361 | else | |
5362 | continue; | |
5363 | ||
5364 | case R_PPC64_DTPMOD64: | |
5365 | expecting_tls_get_addr = 0; | |
951fd09b AM |
5366 | if (rel + 1 < relend |
5367 | && (rel[1].r_info | |
5368 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) | |
5369 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 5370 | { |
951fd09b | 5371 | if (ok_tprel) |
411e1bfb | 5372 | /* GD -> LE */ |
951fd09b | 5373 | tls_set = TLS_EXPLICIT | TLS_GD; |
411e1bfb AM |
5374 | else |
5375 | /* GD -> IE */ | |
951fd09b AM |
5376 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; |
5377 | tls_clear = TLS_GD; | |
411e1bfb AM |
5378 | } |
5379 | else | |
5380 | { | |
951fd09b AM |
5381 | if (!is_local) |
5382 | continue; | |
5383 | ||
5384 | /* LD -> LE */ | |
5385 | tls_set = TLS_EXPLICIT; | |
5386 | tls_clear = TLS_LD; | |
411e1bfb AM |
5387 | } |
5388 | break; | |
5389 | ||
5390 | default: | |
5391 | expecting_tls_get_addr = 0; | |
5392 | continue; | |
5393 | } | |
5394 | ||
5395 | if ((tls_set & TLS_EXPLICIT) == 0) | |
5396 | { | |
5397 | struct got_entry *ent; | |
5398 | ||
5399 | /* Adjust got entry for this reloc. */ | |
5400 | if (h != NULL) | |
5401 | ent = h->got.glist; | |
5402 | else | |
5403 | ent = elf_local_got_ents (ibfd)[r_symndx]; | |
5404 | ||
5405 | for (; ent != NULL; ent = ent->next) | |
5406 | if (ent->addend == rel->r_addend | |
e717da7e | 5407 | && ent->owner == ibfd |
e7b938ca | 5408 | && ent->tls_type == tls_type) |
411e1bfb AM |
5409 | break; |
5410 | if (ent == NULL) | |
5411 | abort (); | |
5412 | ||
5413 | if (tls_set == 0) | |
5414 | { | |
5415 | /* We managed to get rid of a got entry. */ | |
5416 | if (ent->got.refcount > 0) | |
5417 | ent->got.refcount -= 1; | |
5418 | } | |
411e1bfb AM |
5419 | } |
5420 | else if (h != NULL) | |
5421 | { | |
5422 | struct ppc_link_hash_entry * eh; | |
5423 | struct ppc_dyn_relocs **pp; | |
5424 | struct ppc_dyn_relocs *p; | |
5425 | ||
5426 | /* Adjust dynamic relocs. */ | |
5427 | eh = (struct ppc_link_hash_entry *) h; | |
5428 | for (pp = &eh->dyn_relocs; | |
5429 | (p = *pp) != NULL; | |
5430 | pp = &p->next) | |
5431 | if (p->sec == sec) | |
5432 | { | |
5433 | /* If we got rid of a DTPMOD/DTPREL reloc | |
5434 | pair then we'll lose one or two dyn | |
5435 | relocs. */ | |
951fd09b | 5436 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
411e1bfb | 5437 | p->count -= 1; |
951fd09b | 5438 | p->count -= 1; |
411e1bfb AM |
5439 | if (p->count == 0) |
5440 | *pp = p->next; | |
5441 | break; | |
5442 | } | |
5443 | } | |
5444 | ||
e7b938ca AM |
5445 | *tls_mask |= tls_set; |
5446 | *tls_mask &= ~tls_clear; | |
411e1bfb AM |
5447 | } |
5448 | ||
5449 | if (elf_section_data (sec)->relocs != relstart) | |
5450 | free (relstart); | |
5451 | } | |
5452 | ||
5453 | if (locsyms != NULL | |
5454 | && (elf_tdata (ibfd)->symtab_hdr.contents | |
5455 | != (unsigned char *) locsyms)) | |
6cdc0ccc AM |
5456 | { |
5457 | if (!info->keep_memory) | |
411e1bfb | 5458 | free (locsyms); |
6cdc0ccc | 5459 | else |
411e1bfb | 5460 | elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; |
6cdc0ccc | 5461 | } |
1e2f5b6e | 5462 | } |
b34976b6 | 5463 | return TRUE; |
1e2f5b6e | 5464 | } |
b34976b6 | 5465 | |
65f38f15 AM |
5466 | /* This is the condition under which ppc64_elf_finish_dynamic_symbol |
5467 | will be called from elflink.h. If elflink.h doesn't call our | |
5468 | finish_dynamic_symbol routine, we'll need to do something about | |
5469 | initializing any .plt and .got entries in ppc64_elf_relocate_section. */ | |
f4656909 | 5470 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \ |
65f38f15 | 5471 | ((DYN) \ |
f4656909 | 5472 | && ((SHARED) \ |
65f38f15 AM |
5473 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ |
5474 | && ((H)->dynindx != -1 \ | |
5475 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
5bd4f169 | 5476 | |
65f38f15 AM |
5477 | /* Allocate space in .plt, .got and associated reloc sections for |
5478 | dynamic relocs. */ | |
5bd4f169 | 5479 | |
b34976b6 | 5480 | static bfd_boolean |
4ce794b7 | 5481 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
5bd4f169 | 5482 | { |
65f38f15 AM |
5483 | struct bfd_link_info *info; |
5484 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 5485 | asection *s; |
65f38f15 AM |
5486 | struct ppc_link_hash_entry *eh; |
5487 | struct ppc_dyn_relocs *p; | |
411e1bfb | 5488 | struct got_entry *gent; |
5bd4f169 | 5489 | |
e92d460e | 5490 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 5491 | return TRUE; |
5bd4f169 | 5492 | |
e92d460e AM |
5493 | if (h->root.type == bfd_link_hash_warning) |
5494 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5495 | ||
65f38f15 AM |
5496 | info = (struct bfd_link_info *) inf; |
5497 | htab = ppc_hash_table (info); | |
5bd4f169 | 5498 | |
65f38f15 | 5499 | if (htab->elf.dynamic_sections_created |
411e1bfb | 5500 | && h->dynindx != -1 |
9c7a29a3 | 5501 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) |
5bd4f169 | 5502 | { |
411e1bfb AM |
5503 | struct plt_entry *pent; |
5504 | bfd_boolean doneone = FALSE; | |
5505 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) | |
5506 | if (pent->plt.refcount > 0) | |
5507 | { | |
5508 | BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor); | |
5509 | ||
5510 | /* If this is the first .plt entry, make room for the special | |
5511 | first entry. */ | |
4ce794b7 | 5512 | s = htab->plt; |
411e1bfb AM |
5513 | if (s->_raw_size == 0) |
5514 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; | |
5515 | ||
5516 | pent->plt.offset = s->_raw_size; | |
5517 | ||
5518 | /* Make room for this entry. */ | |
5519 | s->_raw_size += PLT_ENTRY_SIZE; | |
5520 | ||
5521 | /* Make room for the .glink code. */ | |
4ce794b7 | 5522 | s = htab->glink; |
411e1bfb AM |
5523 | if (s->_raw_size == 0) |
5524 | s->_raw_size += GLINK_CALL_STUB_SIZE; | |
5525 | /* We need bigger stubs past index 32767. */ | |
5526 | if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4) | |
5527 | s->_raw_size += 4; | |
5528 | s->_raw_size += 2*4; | |
5529 | ||
5530 | /* We also need to make an entry in the .rela.plt section. */ | |
4ce794b7 | 5531 | s = htab->relplt; |
411e1bfb AM |
5532 | s->_raw_size += sizeof (Elf64_External_Rela); |
5533 | doneone = TRUE; | |
5534 | } | |
5535 | else | |
5536 | pent->plt.offset = (bfd_vma) -1; | |
5537 | if (!doneone) | |
65f38f15 | 5538 | { |
411e1bfb | 5539 | h->plt.plist = NULL; |
65f38f15 AM |
5540 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5541 | } | |
5542 | } | |
5543 | else | |
5544 | { | |
411e1bfb | 5545 | h->plt.plist = NULL; |
65f38f15 AM |
5546 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
5547 | } | |
5548 | ||
951fd09b AM |
5549 | eh = (struct ppc_link_hash_entry *) h; |
5550 | /* Run through the TLS GD got entries first if we're changing them | |
5551 | to TPREL. */ | |
e7b938ca | 5552 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
951fd09b AM |
5553 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5554 | if (gent->got.refcount > 0 | |
5555 | && (gent->tls_type & TLS_GD) != 0) | |
5556 | { | |
5557 | /* This was a GD entry that has been converted to TPREL. If | |
5558 | there happens to be a TPREL entry we can use that one. */ | |
5559 | struct got_entry *ent; | |
5560 | for (ent = h->got.glist; ent != NULL; ent = ent->next) | |
5561 | if (ent->got.refcount > 0 | |
5562 | && (ent->tls_type & TLS_TPREL) != 0 | |
e717da7e AM |
5563 | && ent->addend == gent->addend |
5564 | && ent->owner == gent->owner) | |
951fd09b AM |
5565 | { |
5566 | gent->got.refcount = 0; | |
5567 | break; | |
5568 | } | |
5569 | ||
5570 | /* If not, then we'll be using our own TPREL entry. */ | |
5571 | if (gent->got.refcount != 0) | |
5572 | gent->tls_type = TLS_TLS | TLS_TPREL; | |
5573 | } | |
5574 | ||
411e1bfb AM |
5575 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
5576 | if (gent->got.refcount > 0) | |
5577 | { | |
951fd09b AM |
5578 | bfd_boolean dyn; |
5579 | ||
411e1bfb | 5580 | /* Make sure this symbol is output as a dynamic symbol. |
951fd09b AM |
5581 | Undefined weak syms won't yet be marked as dynamic, |
5582 | nor will all TLS symbols. */ | |
411e1bfb AM |
5583 | if (h->dynindx == -1 |
5584 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5585 | { | |
5586 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
5587 | return FALSE; | |
5588 | } | |
65f38f15 | 5589 | |
d881513a AM |
5590 | if ((gent->tls_type & TLS_LD) != 0 |
5591 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
411e1bfb | 5592 | { |
e717da7e | 5593 | gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; |
951fd09b | 5594 | continue; |
411e1bfb | 5595 | } |
951fd09b | 5596 | |
e717da7e | 5597 | s = ppc64_elf_tdata (gent->owner)->got; |
951fd09b | 5598 | gent->got.offset = s->_raw_size; |
d881513a AM |
5599 | s->_raw_size |
5600 | += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; | |
951fd09b | 5601 | dyn = htab->elf.dynamic_sections_created; |
4e795f50 AM |
5602 | if ((info->shared |
5603 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) | |
5604 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5605 | || h->root.type != bfd_link_hash_undefweak)) | |
e717da7e | 5606 | ppc64_elf_tdata (gent->owner)->relgot->_raw_size |
e7b938ca | 5607 | += (gent->tls_type & eh->tls_mask & TLS_GD |
951fd09b AM |
5608 | ? 2 * sizeof (Elf64_External_Rela) |
5609 | : sizeof (Elf64_External_Rela)); | |
411e1bfb AM |
5610 | } |
5611 | else | |
5612 | gent->got.offset = (bfd_vma) -1; | |
65f38f15 | 5613 | |
65f38f15 | 5614 | if (eh->dyn_relocs == NULL) |
b34976b6 | 5615 | return TRUE; |
65f38f15 AM |
5616 | |
5617 | /* In the shared -Bsymbolic case, discard space allocated for | |
5618 | dynamic pc-relative relocs against symbols which turn out to be | |
5619 | defined in regular objects. For the normal shared case, discard | |
5620 | space for relocs that have become local due to symbol visibility | |
5621 | changes. */ | |
5622 | ||
5623 | if (info->shared) | |
5624 | { | |
9c7a29a3 AM |
5625 | /* Relocs that use pc_count are those that appear on a call insn, |
5626 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | |
5627 | generated via assembly. We want calls to protected symbols to | |
5628 | resolve directly to the function rather than going via the plt. | |
5629 | If people want function pointer comparisons to work as expected | |
5630 | then they should avoid writing weird assembly. */ | |
09695f56 | 5631 | if (SYMBOL_CALLS_LOCAL (info, h)) |
65f38f15 AM |
5632 | { |
5633 | struct ppc_dyn_relocs **pp; | |
5634 | ||
5635 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 5636 | { |
65f38f15 AM |
5637 | p->count -= p->pc_count; |
5638 | p->pc_count = 0; | |
5639 | if (p->count == 0) | |
5640 | *pp = p->next; | |
5641 | else | |
5642 | pp = &p->next; | |
5bd4f169 | 5643 | } |
65f38f15 | 5644 | } |
4e795f50 AM |
5645 | |
5646 | /* Also discard relocs on undefined weak syms with non-default | |
5647 | visibility. */ | |
5648 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
5649 | && h->root.type == bfd_link_hash_undefweak) | |
5650 | eh->dyn_relocs = NULL; | |
65f38f15 | 5651 | } |
f4656909 | 5652 | else if (ELIMINATE_COPY_RELOCS) |
65f38f15 AM |
5653 | { |
5654 | /* For the non-shared case, discard space for relocs against | |
5655 | symbols which turn out to need copy relocs or are not | |
5656 | dynamic. */ | |
5657 | ||
5658 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
5659 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
5660 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
65f38f15 AM |
5661 | { |
5662 | /* Make sure this symbol is output as a dynamic symbol. | |
5663 | Undefined weak syms won't yet be marked as dynamic. */ | |
5664 | if (h->dynindx == -1 | |
5665 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5666 | { | |
ec338859 | 5667 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
b34976b6 | 5668 | return FALSE; |
65f38f15 AM |
5669 | } |
5670 | ||
5671 | /* If that succeeded, we know we'll be keeping all the | |
5672 | relocs. */ | |
5673 | if (h->dynindx != -1) | |
5674 | goto keep; | |
5675 | } | |
5676 | ||
5677 | eh->dyn_relocs = NULL; | |
5678 | ||
ec338859 | 5679 | keep: ; |
65f38f15 AM |
5680 | } |
5681 | ||
5682 | /* Finally, allocate space. */ | |
5683 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5684 | { | |
5685 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
5686 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
5687 | } | |
5688 | ||
b34976b6 | 5689 | return TRUE; |
65f38f15 AM |
5690 | } |
5691 | ||
5692 | /* Find any dynamic relocs that apply to read-only sections. */ | |
5693 | ||
b34976b6 | 5694 | static bfd_boolean |
4ce794b7 | 5695 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
65f38f15 AM |
5696 | { |
5697 | struct ppc_link_hash_entry *eh; | |
5698 | struct ppc_dyn_relocs *p; | |
5699 | ||
e92d460e AM |
5700 | if (h->root.type == bfd_link_hash_warning) |
5701 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5702 | ||
65f38f15 AM |
5703 | eh = (struct ppc_link_hash_entry *) h; |
5704 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
5705 | { | |
5706 | asection *s = p->sec->output_section; | |
5707 | ||
5708 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
5709 | { | |
4ce794b7 | 5710 | struct bfd_link_info *info = inf; |
65f38f15 AM |
5711 | |
5712 | info->flags |= DF_TEXTREL; | |
5713 | ||
5714 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 5715 | return FALSE; |
65f38f15 AM |
5716 | } |
5717 | } | |
b34976b6 | 5718 | return TRUE; |
65f38f15 AM |
5719 | } |
5720 | ||
5721 | /* Set the sizes of the dynamic sections. */ | |
5722 | ||
b34976b6 | 5723 | static bfd_boolean |
4ce794b7 AM |
5724 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
5725 | struct bfd_link_info *info) | |
65f38f15 AM |
5726 | { |
5727 | struct ppc_link_hash_table *htab; | |
5728 | bfd *dynobj; | |
5729 | asection *s; | |
b34976b6 | 5730 | bfd_boolean relocs; |
65f38f15 AM |
5731 | bfd *ibfd; |
5732 | ||
5733 | htab = ppc_hash_table (info); | |
5734 | dynobj = htab->elf.dynobj; | |
5735 | if (dynobj == NULL) | |
5736 | abort (); | |
5737 | ||
5738 | if (htab->elf.dynamic_sections_created) | |
5739 | { | |
5740 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 5741 | if (info->executable) |
65f38f15 AM |
5742 | { |
5743 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
5744 | if (s == NULL) | |
5745 | abort (); | |
5746 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5747 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
5748 | } | |
5749 | } | |
5750 | ||
5751 | /* Set up .got offsets for local syms, and space for local dynamic | |
5752 | relocs. */ | |
5753 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
5754 | { | |
411e1bfb AM |
5755 | struct got_entry **lgot_ents; |
5756 | struct got_entry **end_lgot_ents; | |
e7b938ca | 5757 | char *lgot_masks; |
65f38f15 AM |
5758 | bfd_size_type locsymcount; |
5759 | Elf_Internal_Shdr *symtab_hdr; | |
5760 | asection *srel; | |
5761 | ||
5762 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
5763 | continue; | |
5764 | ||
e717da7e AM |
5765 | if (ppc64_tlsld_got (ibfd)->refcount > 0) |
5766 | { | |
5767 | s = ppc64_elf_tdata (ibfd)->got; | |
5768 | ppc64_tlsld_got (ibfd)->offset = s->_raw_size; | |
5769 | s->_raw_size += 16; | |
5770 | if (info->shared) | |
5771 | { | |
5772 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
5773 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5774 | } | |
5775 | } | |
5776 | else | |
5777 | ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; | |
5778 | ||
65f38f15 AM |
5779 | for (s = ibfd->sections; s != NULL; s = s->next) |
5780 | { | |
ec338859 | 5781 | struct ppc_dyn_relocs *p; |
65f38f15 | 5782 | |
ec338859 AM |
5783 | for (p = *((struct ppc_dyn_relocs **) |
5784 | &elf_section_data (s)->local_dynrel); | |
5785 | p != NULL; | |
5786 | p = p->next) | |
65f38f15 | 5787 | { |
ec338859 AM |
5788 | if (!bfd_is_abs_section (p->sec) |
5789 | && bfd_is_abs_section (p->sec->output_section)) | |
5790 | { | |
5791 | /* Input section has been discarded, either because | |
5792 | it is a copy of a linkonce section or due to | |
5793 | linker script /DISCARD/, so we'll be discarding | |
5794 | the relocs too. */ | |
5795 | } | |
248866a8 | 5796 | else if (p->count != 0) |
ec338859 AM |
5797 | { |
5798 | srel = elf_section_data (p->sec)->sreloc; | |
5799 | srel->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
248866a8 AM |
5800 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
5801 | info->flags |= DF_TEXTREL; | |
ec338859 | 5802 | } |
65f38f15 AM |
5803 | } |
5804 | } | |
5805 | ||
411e1bfb AM |
5806 | lgot_ents = elf_local_got_ents (ibfd); |
5807 | if (!lgot_ents) | |
65f38f15 AM |
5808 | continue; |
5809 | ||
5810 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5811 | locsymcount = symtab_hdr->sh_info; | |
411e1bfb | 5812 | end_lgot_ents = lgot_ents + locsymcount; |
e7b938ca | 5813 | lgot_masks = (char *) end_lgot_ents; |
e717da7e AM |
5814 | s = ppc64_elf_tdata (ibfd)->got; |
5815 | srel = ppc64_elf_tdata (ibfd)->relgot; | |
e7b938ca | 5816 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
65f38f15 | 5817 | { |
411e1bfb AM |
5818 | struct got_entry *ent; |
5819 | ||
5820 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) | |
5821 | if (ent->got.refcount > 0) | |
5822 | { | |
e7b938ca | 5823 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
411e1bfb | 5824 | { |
e717da7e | 5825 | if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) |
411e1bfb | 5826 | { |
e717da7e | 5827 | ppc64_tlsld_got (ibfd)->offset = s->_raw_size; |
411e1bfb AM |
5828 | s->_raw_size += 16; |
5829 | if (info->shared) | |
5830 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5831 | } | |
e717da7e | 5832 | ent->got.offset = ppc64_tlsld_got (ibfd)->offset; |
411e1bfb AM |
5833 | } |
5834 | else | |
5835 | { | |
5836 | ent->got.offset = s->_raw_size; | |
e7b938ca | 5837 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
411e1bfb AM |
5838 | { |
5839 | s->_raw_size += 16; | |
5840 | if (info->shared) | |
5841 | srel->_raw_size += 2 * sizeof (Elf64_External_Rela); | |
5842 | } | |
5843 | else | |
5844 | { | |
5845 | s->_raw_size += 8; | |
5846 | if (info->shared) | |
5847 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5848 | } | |
5849 | } | |
5850 | } | |
5851 | else | |
5852 | ent->got.offset = (bfd_vma) -1; | |
65f38f15 AM |
5853 | } |
5854 | } | |
5855 | ||
5856 | /* Allocate global sym .plt and .got entries, and space for global | |
5857 | sym dynamic relocs. */ | |
4ce794b7 | 5858 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
65f38f15 AM |
5859 | |
5860 | /* We now have determined the sizes of the various dynamic sections. | |
5861 | Allocate memory for them. */ | |
b34976b6 | 5862 | relocs = FALSE; |
65f38f15 AM |
5863 | for (s = dynobj->sections; s != NULL; s = s->next) |
5864 | { | |
5865 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
5866 | continue; | |
5867 | ||
411e1bfb AM |
5868 | /* Reset _cooked_size since prelim layout will set it wrongly, |
5869 | and a non-zero _cooked_size sticks. */ | |
5870 | s->_cooked_size = 0; | |
5871 | ||
4ce794b7 | 5872 | if (s == htab->brlt || s == htab->relbrlt) |
721956f4 AM |
5873 | /* These haven't been allocated yet; don't strip. */ |
5874 | continue; | |
e717da7e AM |
5875 | else if (s == htab->got |
5876 | || s == htab->plt | |
4ce794b7 | 5877 | || s == htab->glink) |
65f38f15 AM |
5878 | { |
5879 | /* Strip this section if we don't need it; see the | |
5880 | comment below. */ | |
5bd4f169 | 5881 | } |
65f38f15 | 5882 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 AM |
5883 | { |
5884 | if (s->_raw_size == 0) | |
5885 | { | |
5886 | /* If we don't need this section, strip it from the | |
5887 | output file. This is mostly to handle .rela.bss and | |
5888 | .rela.plt. We must create both sections in | |
5889 | create_dynamic_sections, because they must be created | |
5890 | before the linker maps input sections to output | |
5891 | sections. The linker does that before | |
5892 | adjust_dynamic_symbol is called, and it is that | |
5893 | function which decides whether anything needs to go | |
5894 | into these sections. */ | |
5bd4f169 AM |
5895 | } |
5896 | else | |
5897 | { | |
4ce794b7 | 5898 | if (s != htab->relplt) |
b34976b6 | 5899 | relocs = TRUE; |
5bd4f169 AM |
5900 | |
5901 | /* We use the reloc_count field as a counter if we need | |
5902 | to copy relocs into the output file. */ | |
5903 | s->reloc_count = 0; | |
5904 | } | |
5905 | } | |
65f38f15 | 5906 | else |
5bd4f169 AM |
5907 | { |
5908 | /* It's not one of our sections, so don't allocate space. */ | |
5909 | continue; | |
5910 | } | |
5911 | ||
65f38f15 | 5912 | if (s->_raw_size == 0) |
5bd4f169 AM |
5913 | { |
5914 | _bfd_strip_section_from_output (info, s); | |
5915 | continue; | |
5916 | } | |
5917 | ||
5f333394 AM |
5918 | /* .plt is in the bss section. We don't initialise it. */ |
5919 | if ((s->flags & SEC_LOAD) == 0) | |
5920 | continue; | |
5921 | ||
65f38f15 AM |
5922 | /* Allocate memory for the section contents. We use bfd_zalloc |
5923 | here in case unused entries are not reclaimed before the | |
5924 | section's contents are written out. This should not happen, | |
411e1bfb AM |
5925 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
5926 | sections instead of garbage. | |
5927 | We also rely on the section contents being zero when writing | |
5928 | the GOT. */ | |
4ce794b7 | 5929 | s->contents = bfd_zalloc (dynobj, s->_raw_size); |
65f38f15 | 5930 | if (s->contents == NULL) |
b34976b6 | 5931 | return FALSE; |
5bd4f169 AM |
5932 | } |
5933 | ||
e717da7e AM |
5934 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
5935 | { | |
5936 | s = ppc64_elf_tdata (ibfd)->got; | |
5937 | if (s != NULL && s != htab->got) | |
5938 | { | |
5939 | s->_cooked_size = 0; | |
5940 | if (s->_raw_size == 0) | |
5941 | _bfd_strip_section_from_output (info, s); | |
5942 | else | |
5943 | { | |
5944 | s->contents = bfd_zalloc (ibfd, s->_raw_size); | |
5945 | if (s->contents == NULL) | |
5946 | return FALSE; | |
5947 | } | |
5948 | } | |
5949 | s = ppc64_elf_tdata (ibfd)->relgot; | |
5950 | if (s != NULL) | |
5951 | { | |
5952 | s->_cooked_size = 0; | |
5953 | if (s->_raw_size == 0) | |
5954 | _bfd_strip_section_from_output (info, s); | |
5955 | else | |
5956 | { | |
5957 | s->contents = bfd_zalloc (ibfd, s->_raw_size); | |
5958 | if (s->contents == NULL) | |
5959 | return FALSE; | |
5960 | relocs = TRUE; | |
5961 | s->reloc_count = 0; | |
5962 | } | |
5963 | } | |
5964 | } | |
5965 | ||
e86ce104 | 5966 | if (htab->elf.dynamic_sections_created) |
5bd4f169 AM |
5967 | { |
5968 | /* Add some entries to the .dynamic section. We fill in the | |
5969 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
5970 | must add the entries now so that we get the correct size for | |
5971 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5972 | dynamic linker and used by the debugger. */ | |
dc810e39 | 5973 | #define add_dynamic_entry(TAG, VAL) \ |
4ce794b7 | 5974 | bfd_elf64_add_dynamic_entry (info, (TAG), (VAL)) |
dc810e39 | 5975 | |
36af4a4e | 5976 | if (info->executable) |
5bd4f169 | 5977 | { |
dc810e39 | 5978 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 5979 | return FALSE; |
5bd4f169 AM |
5980 | } |
5981 | ||
4ce794b7 | 5982 | if (htab->plt != NULL && htab->plt->_raw_size != 0) |
5bd4f169 | 5983 | { |
dc810e39 AM |
5984 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
5985 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
5986 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
5987 | || !add_dynamic_entry (DT_JMPREL, 0) |
5988 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
b34976b6 | 5989 | return FALSE; |
5bd4f169 AM |
5990 | } |
5991 | ||
19397422 AM |
5992 | if (NO_OPD_RELOCS) |
5993 | { | |
5994 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) | |
5995 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) | |
b34976b6 | 5996 | return FALSE; |
19397422 AM |
5997 | } |
5998 | ||
5bd4f169 AM |
5999 | if (relocs) |
6000 | { | |
dc810e39 AM |
6001 | if (!add_dynamic_entry (DT_RELA, 0) |
6002 | || !add_dynamic_entry (DT_RELASZ, 0) | |
6003 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 6004 | return FALSE; |
5bd4f169 | 6005 | |
65f38f15 AM |
6006 | /* If any dynamic relocs apply to a read-only section, |
6007 | then we need a DT_TEXTREL entry. */ | |
248866a8 | 6008 | if ((info->flags & DF_TEXTREL) == 0) |
4ce794b7 | 6009 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
5bd4f169 | 6010 | |
65f38f15 | 6011 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 6012 | { |
65f38f15 | 6013 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 6014 | return FALSE; |
5bd4f169 | 6015 | } |
5bd4f169 | 6016 | } |
5bd4f169 | 6017 | } |
65f38f15 | 6018 | #undef add_dynamic_entry |
5bd4f169 | 6019 | |
b34976b6 | 6020 | return TRUE; |
5bd4f169 AM |
6021 | } |
6022 | ||
721956f4 | 6023 | /* Determine the type of stub needed, if any, for a call. */ |
5bd4f169 | 6024 | |
4ce794b7 AM |
6025 | static inline enum ppc_stub_type |
6026 | ppc_type_of_stub (asection *input_sec, | |
6027 | const Elf_Internal_Rela *rel, | |
6028 | struct ppc_link_hash_entry **hash, | |
6029 | bfd_vma destination) | |
5bd4f169 | 6030 | { |
721956f4 AM |
6031 | struct ppc_link_hash_entry *h = *hash; |
6032 | bfd_vma location; | |
6033 | bfd_vma branch_offset; | |
6034 | bfd_vma max_branch_offset; | |
4ce794b7 | 6035 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 | 6036 | |
721956f4 AM |
6037 | if (h != NULL) |
6038 | { | |
6039 | if (h->oh != NULL | |
721956f4 | 6040 | && h->oh->dynindx != -1) |
5bd4f169 | 6041 | { |
411e1bfb AM |
6042 | struct plt_entry *ent; |
6043 | for (ent = h->oh->plt.plist; ent != NULL; ent = ent->next) | |
6044 | if (ent->addend == rel->r_addend | |
6045 | && ent->plt.offset != (bfd_vma) -1) | |
6046 | { | |
6047 | *hash = (struct ppc_link_hash_entry *) h->oh; | |
6048 | return ppc_stub_plt_call; | |
6049 | } | |
5bd4f169 AM |
6050 | } |
6051 | ||
ad8e1ba5 AM |
6052 | if (h->elf.root.type != bfd_link_hash_defined |
6053 | && h->elf.root.type != bfd_link_hash_defweak) | |
721956f4 | 6054 | return ppc_stub_none; |
5d1634d7 | 6055 | } |
5d1634d7 | 6056 | |
721956f4 AM |
6057 | /* Determine where the call point is. */ |
6058 | location = (input_sec->output_offset | |
6059 | + input_sec->output_section->vma | |
6060 | + rel->r_offset); | |
5d1634d7 | 6061 | |
721956f4 AM |
6062 | branch_offset = destination - location; |
6063 | r_type = ELF64_R_TYPE (rel->r_info); | |
5d1634d7 | 6064 | |
721956f4 AM |
6065 | /* Determine if a long branch stub is needed. */ |
6066 | max_branch_offset = 1 << 25; | |
4ce794b7 | 6067 | if (r_type != R_PPC64_REL24) |
721956f4 | 6068 | max_branch_offset = 1 << 15; |
5d1634d7 | 6069 | |
721956f4 AM |
6070 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
6071 | /* We need a stub. Figure out whether a long_branch or plt_branch | |
6072 | is needed later. */ | |
6073 | return ppc_stub_long_branch; | |
5d1634d7 | 6074 | |
721956f4 | 6075 | return ppc_stub_none; |
5d1634d7 AM |
6076 | } |
6077 | ||
6078 | /* Build a .plt call stub. */ | |
6079 | ||
4ce794b7 AM |
6080 | static inline bfd_byte * |
6081 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset) | |
5d1634d7 AM |
6082 | { |
6083 | #define PPC_LO(v) ((v) & 0xffff) | |
6084 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
6085 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
6086 | ||
5d1634d7 | 6087 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
ad8e1ba5 | 6088 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
5d1634d7 AM |
6089 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
6090 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6091 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6092 | offset += 8; |
6093 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
6094 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
ad8e1ba5 | 6095 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
5d1634d7 AM |
6096 | offset += 8; |
6097 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
6098 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
6099 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
6100 | return p; | |
6101 | } | |
6102 | ||
b34976b6 | 6103 | static bfd_boolean |
4ce794b7 | 6104 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
5d1634d7 | 6105 | { |
721956f4 AM |
6106 | struct ppc_stub_hash_entry *stub_entry; |
6107 | struct ppc_branch_hash_entry *br_entry; | |
5d1634d7 AM |
6108 | struct bfd_link_info *info; |
6109 | struct ppc_link_hash_table *htab; | |
721956f4 AM |
6110 | bfd_byte *loc; |
6111 | bfd_byte *p; | |
6112 | unsigned int indx; | |
411e1bfb | 6113 | struct plt_entry *ent; |
721956f4 AM |
6114 | bfd_vma off; |
6115 | int size; | |
5d1634d7 | 6116 | |
721956f4 AM |
6117 | /* Massage our args to the form they really have. */ |
6118 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6119 | info = in_arg; |
5d1634d7 | 6120 | |
5d1634d7 AM |
6121 | htab = ppc_hash_table (info); |
6122 | ||
721956f4 | 6123 | /* Make a note of the offset within the stubs for this entry. */ |
97b639ba AM |
6124 | stub_entry->stub_offset = stub_entry->stub_sec->_cooked_size; |
6125 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; | |
721956f4 | 6126 | |
4ce794b7 | 6127 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
721956f4 | 6128 | switch (stub_entry->stub_type) |
5d1634d7 | 6129 | { |
721956f4 | 6130 | case ppc_stub_long_branch: |
ad8e1ba5 | 6131 | case ppc_stub_long_branch_r2off: |
721956f4 AM |
6132 | /* Branches are relative. This is where we are going to. */ |
6133 | off = (stub_entry->target_value | |
6134 | + stub_entry->target_section->output_offset | |
6135 | + stub_entry->target_section->output_section->vma); | |
5d1634d7 | 6136 | |
721956f4 AM |
6137 | /* And this is where we are coming from. */ |
6138 | off -= (stub_entry->stub_offset | |
97b639ba AM |
6139 | + stub_entry->stub_sec->output_offset |
6140 | + stub_entry->stub_sec->output_section->vma); | |
e86ce104 | 6141 | |
ad8e1ba5 AM |
6142 | if (stub_entry->stub_type != ppc_stub_long_branch_r2off) |
6143 | size = 4; | |
6144 | else | |
6145 | { | |
6146 | bfd_vma r2off; | |
6147 | ||
6148 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6149 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6150 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6151 | loc += 4; |
97b639ba | 6152 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6153 | loc += 4; |
97b639ba | 6154 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6155 | loc += 4; |
6156 | off -= 12; | |
6157 | size = 16; | |
6158 | } | |
97b639ba | 6159 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
ad8e1ba5 AM |
6160 | |
6161 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); | |
721956f4 | 6162 | break; |
e86ce104 | 6163 | |
721956f4 | 6164 | case ppc_stub_plt_branch: |
ad8e1ba5 | 6165 | case ppc_stub_plt_branch_r2off: |
721956f4 AM |
6166 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
6167 | stub_entry->root.string + 9, | |
b34976b6 | 6168 | FALSE, FALSE); |
721956f4 AM |
6169 | if (br_entry == NULL) |
6170 | { | |
6171 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), | |
6172 | stub_entry->root.string + 9); | |
b34976b6 AM |
6173 | htab->stub_error = TRUE; |
6174 | return FALSE; | |
721956f4 AM |
6175 | } |
6176 | ||
6177 | off = (stub_entry->target_value | |
6178 | + stub_entry->target_section->output_offset | |
6179 | + stub_entry->target_section->output_section->vma); | |
6180 | ||
4ce794b7 AM |
6181 | bfd_put_64 (htab->brlt->owner, off, |
6182 | htab->brlt->contents + br_entry->offset); | |
721956f4 AM |
6183 | |
6184 | if (info->shared) | |
6185 | { | |
6186 | /* Create a reloc for the branch lookup table entry. */ | |
6187 | Elf_Internal_Rela rela; | |
ad8e1ba5 | 6188 | bfd_byte *rl; |
5d1634d7 | 6189 | |
721956f4 | 6190 | rela.r_offset = (br_entry->offset |
4ce794b7 AM |
6191 | + htab->brlt->output_offset |
6192 | + htab->brlt->output_section->vma); | |
721956f4 AM |
6193 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
6194 | rela.r_addend = off; | |
6195 | ||
4ce794b7 AM |
6196 | rl = htab->relbrlt->contents; |
6197 | rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela); | |
6198 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); | |
721956f4 AM |
6199 | } |
6200 | ||
6201 | off = (br_entry->offset | |
4ce794b7 AM |
6202 | + htab->brlt->output_offset |
6203 | + htab->brlt->output_section->vma | |
6204 | - elf_gp (htab->brlt->output_section->owner) | |
ad8e1ba5 | 6205 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6206 | |
ad8e1ba5 | 6207 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
5d1634d7 AM |
6208 | { |
6209 | (*_bfd_error_handler) | |
e86ce104 | 6210 | (_("linkage table error against `%s'"), |
721956f4 | 6211 | stub_entry->root.string); |
5d1634d7 | 6212 | bfd_set_error (bfd_error_bad_value); |
b34976b6 AM |
6213 | htab->stub_error = TRUE; |
6214 | return FALSE; | |
5d1634d7 | 6215 | } |
41bd81ab | 6216 | |
721956f4 | 6217 | indx = off; |
ad8e1ba5 AM |
6218 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
6219 | { | |
97b639ba | 6220 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6221 | loc += 4; |
97b639ba | 6222 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 AM |
6223 | size = 16; |
6224 | } | |
6225 | else | |
6226 | { | |
6227 | bfd_vma r2off; | |
6228 | ||
6229 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off | |
6230 | - htab->stub_group[stub_entry->id_sec->id].toc_off); | |
97b639ba | 6231 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
ad8e1ba5 | 6232 | loc += 4; |
97b639ba | 6233 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
ad8e1ba5 | 6234 | loc += 4; |
97b639ba | 6235 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
ad8e1ba5 | 6236 | loc += 4; |
97b639ba | 6237 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
ad8e1ba5 | 6238 | loc += 4; |
97b639ba | 6239 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
ad8e1ba5 AM |
6240 | size = 28; |
6241 | } | |
6242 | loc += 4; | |
97b639ba | 6243 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
ad8e1ba5 | 6244 | loc += 4; |
97b639ba | 6245 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
721956f4 | 6246 | break; |
5d1634d7 | 6247 | |
721956f4 | 6248 | case ppc_stub_plt_call: |
c862ae31 AM |
6249 | /* Do the best we can for shared libraries built without |
6250 | exporting ".foo" for each "foo". This can happen when symbol | |
6251 | versioning scripts strip all bar a subset of symbols. */ | |
6252 | if (stub_entry->h->oh->root.type != bfd_link_hash_defined | |
6253 | && stub_entry->h->oh->root.type != bfd_link_hash_defweak) | |
6254 | { | |
6255 | /* Point the symbol at the stub. There may be multiple stubs, | |
6256 | we don't really care; The main thing is to make this sym | |
8f3bab57 AM |
6257 | defined somewhere. Maybe defining the symbol in the stub |
6258 | section is a silly idea. If we didn't do this, htab->top_id | |
6259 | could disappear. */ | |
c862ae31 AM |
6260 | stub_entry->h->oh->root.type = bfd_link_hash_defined; |
6261 | stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec; | |
6262 | stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset; | |
6263 | } | |
6264 | ||
721956f4 | 6265 | /* Now build the stub. */ |
411e1bfb AM |
6266 | off = (bfd_vma) -1; |
6267 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) | |
6268 | if (ent->addend == stub_entry->addend) | |
6269 | { | |
6270 | off = ent->plt.offset; | |
6271 | break; | |
6272 | } | |
721956f4 AM |
6273 | if (off >= (bfd_vma) -2) |
6274 | abort (); | |
6275 | ||
6276 | off &= ~ (bfd_vma) 1; | |
4ce794b7 AM |
6277 | off += (htab->plt->output_offset |
6278 | + htab->plt->output_section->vma | |
6279 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6280 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6281 | |
ad8e1ba5 | 6282 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
721956f4 AM |
6283 | { |
6284 | (*_bfd_error_handler) | |
6285 | (_("linkage table error against `%s'"), | |
6286 | stub_entry->h->elf.root.root.string); | |
6287 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 AM |
6288 | htab->stub_error = TRUE; |
6289 | return FALSE; | |
721956f4 AM |
6290 | } |
6291 | ||
97b639ba | 6292 | p = build_plt_stub (htab->stub_bfd, loc, off); |
721956f4 AM |
6293 | size = p - loc; |
6294 | break; | |
6295 | ||
6296 | default: | |
6297 | BFD_FAIL (); | |
b34976b6 | 6298 | return FALSE; |
721956f4 AM |
6299 | } |
6300 | ||
97b639ba AM |
6301 | stub_entry->stub_sec->_cooked_size += size; |
6302 | ||
6303 | if (htab->emit_stub_syms | |
6304 | && !(stub_entry->stub_type == ppc_stub_plt_call | |
6305 | && stub_entry->h->oh->root.type == bfd_link_hash_defined | |
6306 | && stub_entry->h->oh->root.u.def.section == stub_entry->stub_sec | |
6307 | && stub_entry->h->oh->root.u.def.value == stub_entry->stub_offset)) | |
6308 | { | |
6309 | struct elf_link_hash_entry *h; | |
6310 | h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string, | |
6311 | TRUE, FALSE, FALSE); | |
6312 | if (h == NULL) | |
6313 | return FALSE; | |
6314 | if (h->root.type == bfd_link_hash_new) | |
6315 | { | |
6316 | h->root.type = bfd_link_hash_defined; | |
6317 | h->root.u.def.section = stub_entry->stub_sec; | |
6318 | h->root.u.def.value = stub_entry->stub_offset; | |
6319 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
6320 | | ELF_LINK_HASH_DEF_REGULAR | |
6321 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
6322 | | ELF_LINK_FORCED_LOCAL); | |
6323 | } | |
6324 | } | |
6325 | ||
b34976b6 | 6326 | return TRUE; |
721956f4 AM |
6327 | } |
6328 | ||
6329 | /* As above, but don't actually build the stub. Just bump offset so | |
6330 | we know stub section sizes, and select plt_branch stubs where | |
6331 | long_branch stubs won't do. */ | |
6332 | ||
b34976b6 | 6333 | static bfd_boolean |
4ce794b7 | 6334 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
721956f4 AM |
6335 | { |
6336 | struct ppc_stub_hash_entry *stub_entry; | |
6337 | struct ppc_link_hash_table *htab; | |
6338 | bfd_vma off; | |
6339 | int size; | |
6340 | ||
6341 | /* Massage our args to the form they really have. */ | |
6342 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; | |
4ce794b7 | 6343 | htab = in_arg; |
721956f4 AM |
6344 | |
6345 | if (stub_entry->stub_type == ppc_stub_plt_call) | |
6346 | { | |
411e1bfb | 6347 | struct plt_entry *ent; |
58ac9f71 | 6348 | off = (bfd_vma) -1; |
411e1bfb AM |
6349 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
6350 | if (ent->addend == stub_entry->addend) | |
6351 | { | |
6352 | off = ent->plt.offset & ~(bfd_vma) 1; | |
6353 | break; | |
6354 | } | |
58ac9f71 | 6355 | if (off >= (bfd_vma) -2) |
411e1bfb | 6356 | abort (); |
4ce794b7 AM |
6357 | off += (htab->plt->output_offset |
6358 | + htab->plt->output_section->vma | |
6359 | - elf_gp (htab->plt->output_section->owner) | |
ad8e1ba5 | 6360 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
721956f4 | 6361 | |
ad8e1ba5 | 6362 | size = PLT_CALL_STUB_SIZE; |
4ce794b7 | 6363 | if (PPC_HA (off + 16) != PPC_HA (off)) |
721956f4 AM |
6364 | size += 4; |
6365 | } | |
6366 | else | |
6367 | { | |
ad8e1ba5 AM |
6368 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
6369 | variants. */ | |
721956f4 AM |
6370 | off = (stub_entry->target_value |
6371 | + stub_entry->target_section->output_offset | |
6372 | + stub_entry->target_section->output_section->vma); | |
6373 | off -= (stub_entry->stub_sec->_raw_size | |
6374 | + stub_entry->stub_sec->output_offset | |
6375 | + stub_entry->stub_sec->output_section->vma); | |
6376 | ||
ad8e1ba5 AM |
6377 | /* Reset the stub type from the plt variant in case we now |
6378 | can reach with a shorter stub. */ | |
6379 | if (stub_entry->stub_type >= ppc_stub_plt_branch) | |
6380 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; | |
6381 | ||
6382 | size = 4; | |
6383 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) | |
6384 | { | |
6385 | off -= 12; | |
6386 | size = 16; | |
6387 | } | |
6388 | ||
6389 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ | |
721956f4 AM |
6390 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
6391 | { | |
6392 | struct ppc_branch_hash_entry *br_entry; | |
6393 | ||
6394 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, | |
6395 | stub_entry->root.string + 9, | |
b34976b6 | 6396 | TRUE, FALSE); |
721956f4 AM |
6397 | if (br_entry == NULL) |
6398 | { | |
6399 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), | |
6400 | stub_entry->root.string + 9); | |
b34976b6 AM |
6401 | htab->stub_error = TRUE; |
6402 | return FALSE; | |
721956f4 AM |
6403 | } |
6404 | ||
6405 | if (br_entry->iter != htab->stub_iteration) | |
6406 | { | |
6407 | br_entry->iter = htab->stub_iteration; | |
4ce794b7 AM |
6408 | br_entry->offset = htab->brlt->_raw_size; |
6409 | htab->brlt->_raw_size += 8; | |
721956f4 | 6410 | } |
ad8e1ba5 AM |
6411 | |
6412 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | |
721956f4 | 6413 | size = 16; |
ad8e1ba5 AM |
6414 | if (stub_entry->stub_type != ppc_stub_plt_branch) |
6415 | size = 28; | |
721956f4 AM |
6416 | } |
6417 | } | |
6418 | ||
6419 | stub_entry->stub_sec->_raw_size += size; | |
b34976b6 | 6420 | return TRUE; |
721956f4 AM |
6421 | } |
6422 | ||
6423 | /* Set up various things so that we can make a list of input sections | |
6424 | for each output section included in the link. Returns -1 on error, | |
cedb70c5 | 6425 | 0 when no stubs will be needed, and 1 on success. */ |
721956f4 AM |
6426 | |
6427 | int | |
4ce794b7 | 6428 | ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
721956f4 AM |
6429 | { |
6430 | bfd *input_bfd; | |
734b6cf9 | 6431 | int top_id, top_index, id; |
721956f4 | 6432 | asection *section; |
734b6cf9 | 6433 | asection **input_list; |
721956f4 AM |
6434 | bfd_size_type amt; |
6435 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6436 | ||
4ce794b7 | 6437 | if (htab->brlt == NULL) |
721956f4 AM |
6438 | return 0; |
6439 | ||
1e2f5b6e | 6440 | /* Find the top input section id. */ |
3d6f9012 | 6441 | for (input_bfd = info->input_bfds, top_id = 3; |
721956f4 AM |
6442 | input_bfd != NULL; |
6443 | input_bfd = input_bfd->link_next) | |
6444 | { | |
721956f4 AM |
6445 | for (section = input_bfd->sections; |
6446 | section != NULL; | |
6447 | section = section->next) | |
6448 | { | |
6449 | if (top_id < section->id) | |
6450 | top_id = section->id; | |
6451 | } | |
6452 | } | |
721956f4 | 6453 | |
8f3bab57 | 6454 | htab->top_id = top_id; |
721956f4 | 6455 | amt = sizeof (struct map_stub) * (top_id + 1); |
4ce794b7 | 6456 | htab->stub_group = bfd_zmalloc (amt); |
721956f4 AM |
6457 | if (htab->stub_group == NULL) |
6458 | return -1; | |
6459 | ||
3d6f9012 AM |
6460 | /* Set toc_off for com, und, abs and ind sections. */ |
6461 | for (id = 0; id < 3; id++) | |
6462 | htab->stub_group[id].toc_off = TOC_BASE_OFF; | |
721956f4 | 6463 | |
3d6f9012 | 6464 | elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd); |
734b6cf9 AM |
6465 | |
6466 | /* We can't use output_bfd->section_count here to find the top output | |
6467 | section index as some sections may have been removed, and | |
6468 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
6469 | for (section = output_bfd->sections, top_index = 0; | |
6470 | section != NULL; | |
6471 | section = section->next) | |
6472 | { | |
6473 | if (top_index < section->index) | |
6474 | top_index = section->index; | |
6475 | } | |
6476 | ||
6477 | htab->top_index = top_index; | |
6478 | amt = sizeof (asection *) * (top_index + 1); | |
4ce794b7 | 6479 | input_list = bfd_zmalloc (amt); |
734b6cf9 AM |
6480 | htab->input_list = input_list; |
6481 | if (input_list == NULL) | |
6482 | return -1; | |
6483 | ||
721956f4 AM |
6484 | return 1; |
6485 | } | |
6486 | ||
e717da7e AM |
6487 | /* The linker repeatedly calls this function for each TOC input section |
6488 | and linker generated GOT section. Group input bfds such that the toc | |
6489 | within a group is less than 64k in size. Will break with cute linker | |
6490 | scripts that play games with dot in the output toc section. */ | |
ad8e1ba5 AM |
6491 | |
6492 | void | |
4ce794b7 | 6493 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
ad8e1ba5 AM |
6494 | { |
6495 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
6496 | ||
6497 | if (!htab->no_multi_toc) | |
6498 | { | |
6499 | bfd_vma addr = isec->output_offset + isec->output_section->vma; | |
6500 | bfd_vma off = addr - htab->toc_curr; | |
6501 | if (off + isec->_raw_size > 0x10000) | |
6502 | { | |
6503 | htab->toc_curr = addr; | |
6504 | htab->multi_toc_needed = 1; | |
6505 | } | |
6506 | elf_gp (isec->owner) = (htab->toc_curr | |
6507 | - elf_gp (isec->output_section->owner) | |
6508 | + TOC_BASE_OFF); | |
6509 | } | |
6510 | } | |
6511 | ||
6512 | /* Called after the last call to the above function. */ | |
6513 | ||
6514 | void | |
4ce794b7 AM |
6515 | ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED, |
6516 | struct bfd_link_info *info) | |
ad8e1ba5 AM |
6517 | { |
6518 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
ad8e1ba5 AM |
6519 | |
6520 | /* toc_curr tracks the TOC offset used for code sections below in | |
6521 | ppc64_elf_next_input_section. Start off at 0x8000. */ | |
3d6f9012 | 6522 | htab->toc_curr = TOC_BASE_OFF; |
ad8e1ba5 AM |
6523 | } |
6524 | ||
9b5ecbd0 AM |
6525 | /* No toc references were found in ISEC. If the code in ISEC makes no |
6526 | calls, then there's no need to use toc adjusting stubs when branching | |
6527 | into ISEC. Actually, indirect calls from ISEC are OK as they will | |
6528 | load r2. */ | |
6529 | ||
6530 | static int | |
4ce794b7 | 6531 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
9b5ecbd0 AM |
6532 | { |
6533 | bfd_byte *contents; | |
6534 | bfd_size_type i; | |
6535 | int ret; | |
6536 | int branch_ok; | |
6537 | ||
772119ce AM |
6538 | /* We know none of our code bearing sections will need toc stubs. */ |
6539 | if ((isec->flags & SEC_LINKER_CREATED) != 0) | |
6540 | return 0; | |
6541 | ||
9b5ecbd0 AM |
6542 | /* Hack for linux kernel. .fixup contains branches, but only back to |
6543 | the function that hit an exception. */ | |
6544 | branch_ok = strcmp (isec->name, ".fixup") == 0; | |
6545 | ||
6546 | contents = elf_section_data (isec)->this_hdr.contents; | |
6547 | if (contents == NULL) | |
6548 | { | |
6549 | contents = bfd_malloc (isec->_raw_size); | |
6550 | if (contents == NULL) | |
6551 | return -1; | |
6552 | if (! bfd_get_section_contents (isec->owner, isec, contents, | |
e717da7e | 6553 | 0, isec->_raw_size)) |
9b5ecbd0 AM |
6554 | { |
6555 | free (contents); | |
6556 | return -1; | |
6557 | } | |
6558 | if (info->keep_memory) | |
6559 | elf_section_data (isec)->this_hdr.contents = contents; | |
6560 | } | |
6561 | ||
6562 | /* Code scan, because we don't necessarily have relocs on calls to | |
6563 | static functions. */ | |
6564 | ret = 0; | |
6565 | for (i = 0; i < isec->_raw_size; i += 4) | |
6566 | { | |
6567 | unsigned long insn = bfd_get_32 (isec->owner, contents + i); | |
6568 | /* Is this a branch? */ | |
772119ce | 6569 | if ((insn & (0x3f << 26)) == (18 << 26) |
9b5ecbd0 AM |
6570 | /* If branch and link, it's a function call. */ |
6571 | && ((insn & 1) != 0 | |
6572 | /* Sibling calls use a plain branch. I don't know a way | |
6573 | of deciding whether a branch is really a sibling call. */ | |
6574 | || !branch_ok)) | |
6575 | { | |
6576 | ret = 1; | |
6577 | break; | |
6578 | } | |
6579 | } | |
6580 | ||
6581 | if (elf_section_data (isec)->this_hdr.contents != contents) | |
6582 | free (contents); | |
6583 | return ret; | |
6584 | } | |
6585 | ||
721956f4 AM |
6586 | /* The linker repeatedly calls this function for each input section, |
6587 | in the order that input sections are linked into output sections. | |
6588 | Build lists of input sections to determine groupings between which | |
6589 | we may insert linker stubs. */ | |
6590 | ||
9b5ecbd0 | 6591 | bfd_boolean |
4ce794b7 | 6592 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
721956f4 AM |
6593 | { |
6594 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
9b5ecbd0 | 6595 | int ret; |
721956f4 | 6596 | |
734b6cf9 AM |
6597 | if ((isec->output_section->flags & SEC_CODE) != 0 |
6598 | && isec->output_section->index <= htab->top_index) | |
721956f4 | 6599 | { |
734b6cf9 | 6600 | asection **list = htab->input_list + isec->output_section->index; |
3d6f9012 | 6601 | /* Steal the link_sec pointer for our list. */ |
721956f4 | 6602 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3d6f9012 AM |
6603 | /* This happens to make the list in reverse order, |
6604 | which is what we want. */ | |
734b6cf9 AM |
6605 | PREV_SEC (isec) = *list; |
6606 | *list = isec; | |
721956f4 | 6607 | } |
ad8e1ba5 AM |
6608 | |
6609 | /* If a code section has a function that uses the TOC then we need | |
6610 | to use the right TOC (obviously). Also, make sure that .opd gets | |
6611 | the correct TOC value. */ | |
6612 | if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0) | |
9b5ecbd0 AM |
6613 | { |
6614 | if (elf_gp (isec->owner) != 0) | |
6615 | htab->toc_curr = elf_gp (isec->owner); | |
6616 | } | |
6617 | else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0) | |
6618 | return FALSE; | |
6619 | else | |
6620 | isec->has_gp_reloc = ret; | |
ad8e1ba5 AM |
6621 | |
6622 | /* Functions that don't use the TOC can belong in any TOC group. | |
6623 | Use the last TOC base. This happens to make _init and _fini | |
6624 | pasting work. */ | |
6625 | htab->stub_group[isec->id].toc_off = htab->toc_curr; | |
9b5ecbd0 | 6626 | return TRUE; |
721956f4 AM |
6627 | } |
6628 | ||
6629 | /* See whether we can group stub sections together. Grouping stub | |
6630 | sections may result in fewer stubs. More importantly, we need to | |
6631 | put all .init* and .fini* stubs at the beginning of the .init or | |
6632 | .fini output sections respectively, because glibc splits the | |
6633 | _init and _fini functions into multiple parts. Putting a stub in | |
6634 | the middle of a function is not a good idea. */ | |
6635 | ||
6636 | static void | |
4ce794b7 AM |
6637 | group_sections (struct ppc_link_hash_table *htab, |
6638 | bfd_size_type stub_group_size, | |
6639 | bfd_boolean stubs_always_before_branch) | |
721956f4 | 6640 | { |
734b6cf9 AM |
6641 | asection **list = htab->input_list + htab->top_index; |
6642 | do | |
721956f4 | 6643 | { |
734b6cf9 AM |
6644 | asection *tail = *list; |
6645 | while (tail != NULL) | |
721956f4 | 6646 | { |
734b6cf9 AM |
6647 | asection *curr; |
6648 | asection *prev; | |
6649 | bfd_size_type total; | |
6650 | bfd_boolean big_sec; | |
6651 | bfd_vma curr_toc; | |
6652 | ||
6653 | curr = tail; | |
6654 | if (tail->_cooked_size) | |
6655 | total = tail->_cooked_size; | |
6656 | else | |
6657 | total = tail->_raw_size; | |
6658 | big_sec = total >= stub_group_size; | |
6659 | curr_toc = htab->stub_group[tail->id].toc_off; | |
6660 | ||
6661 | while ((prev = PREV_SEC (curr)) != NULL | |
6662 | && ((total += curr->output_offset - prev->output_offset) | |
ad8e1ba5 AM |
6663 | < stub_group_size) |
6664 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
734b6cf9 AM |
6665 | curr = prev; |
6666 | ||
6667 | /* OK, the size from the start of CURR to the end is less | |
6668 | than stub_group_size and thus can be handled by one stub | |
6669 | section. (or the tail section is itself larger than | |
6670 | stub_group_size, in which case we may be toast.) We | |
6671 | should really be keeping track of the total size of stubs | |
6672 | added here, as stubs contribute to the final output | |
6673 | section size. That's a little tricky, and this way will | |
6674 | only break if stubs added make the total size more than | |
6675 | 2^25, ie. for the default stub_group_size, if stubs total | |
6676 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ | |
6677 | do | |
721956f4 AM |
6678 | { |
6679 | prev = PREV_SEC (tail); | |
734b6cf9 | 6680 | /* Set up this stub group. */ |
721956f4 AM |
6681 | htab->stub_group[tail->id].link_sec = curr; |
6682 | } | |
734b6cf9 AM |
6683 | while (tail != curr && (tail = prev) != NULL); |
6684 | ||
6685 | /* But wait, there's more! Input sections up to stub_group_size | |
6686 | bytes before the stub section can be handled by it too. | |
6687 | Don't do this if we have a really large section after the | |
6688 | stubs, as adding more stubs increases the chance that | |
6689 | branches may not reach into the stub section. */ | |
6690 | if (!stubs_always_before_branch && !big_sec) | |
6691 | { | |
6692 | total = 0; | |
6693 | while (prev != NULL | |
6694 | && ((total += tail->output_offset - prev->output_offset) | |
6695 | < stub_group_size) | |
6696 | && htab->stub_group[prev->id].toc_off == curr_toc) | |
6697 | { | |
6698 | tail = prev; | |
6699 | prev = PREV_SEC (tail); | |
6700 | htab->stub_group[tail->id].link_sec = curr; | |
6701 | } | |
6702 | } | |
6703 | tail = prev; | |
721956f4 AM |
6704 | } |
6705 | } | |
734b6cf9 AM |
6706 | while (list-- != htab->input_list); |
6707 | free (htab->input_list); | |
721956f4 AM |
6708 | #undef PREV_SEC |
6709 | } | |
6710 | ||
721956f4 AM |
6711 | /* Determine and set the size of the stub section for a final link. |
6712 | ||
6713 | The basic idea here is to examine all the relocations looking for | |
6714 | PC-relative calls to a target that is unreachable with a "bl" | |
6715 | instruction. */ | |
6716 | ||
b34976b6 | 6717 | bfd_boolean |
4ce794b7 | 6718 | ppc64_elf_size_stubs (bfd *output_bfd, |
4ce794b7 AM |
6719 | struct bfd_link_info *info, |
6720 | bfd_signed_vma group_size, | |
6721 | asection *(*add_stub_section) (const char *, asection *), | |
6722 | void (*layout_sections_again) (void)) | |
721956f4 AM |
6723 | { |
6724 | bfd_size_type stub_group_size; | |
b34976b6 | 6725 | bfd_boolean stubs_always_before_branch; |
721956f4 AM |
6726 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
6727 | ||
6728 | /* Stash our params away. */ | |
721956f4 AM |
6729 | htab->add_stub_section = add_stub_section; |
6730 | htab->layout_sections_again = layout_sections_again; | |
6731 | stubs_always_before_branch = group_size < 0; | |
6732 | if (group_size < 0) | |
6733 | stub_group_size = -group_size; | |
6734 | else | |
6735 | stub_group_size = group_size; | |
6736 | if (stub_group_size == 1) | |
6737 | { | |
6738 | /* Default values. */ | |
58ac9f71 AM |
6739 | if (stubs_always_before_branch) |
6740 | { | |
6741 | stub_group_size = 0x1e00000; | |
6742 | if (htab->has_14bit_branch) | |
6743 | stub_group_size = 0x7800; | |
6744 | } | |
6745 | else | |
6746 | { | |
6747 | stub_group_size = 0x1c00000; | |
6748 | if (htab->has_14bit_branch) | |
6749 | stub_group_size = 0x7000; | |
6750 | } | |
721956f4 AM |
6751 | } |
6752 | ||
6753 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
6754 | ||
721956f4 AM |
6755 | while (1) |
6756 | { | |
6757 | bfd *input_bfd; | |
6758 | unsigned int bfd_indx; | |
6759 | asection *stub_sec; | |
b34976b6 | 6760 | bfd_boolean stub_changed; |
721956f4 AM |
6761 | |
6762 | htab->stub_iteration += 1; | |
b34976b6 | 6763 | stub_changed = FALSE; |
721956f4 AM |
6764 | |
6765 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
6766 | input_bfd != NULL; | |
6767 | input_bfd = input_bfd->link_next, bfd_indx++) | |
6768 | { | |
6769 | Elf_Internal_Shdr *symtab_hdr; | |
6770 | asection *section; | |
6cdc0ccc | 6771 | Elf_Internal_Sym *local_syms = NULL; |
721956f4 AM |
6772 | |
6773 | /* We'll need the symbol table in a second. */ | |
6774 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
6775 | if (symtab_hdr->sh_info == 0) | |
6776 | continue; | |
6777 | ||
721956f4 AM |
6778 | /* Walk over each section attached to the input bfd. */ |
6779 | for (section = input_bfd->sections; | |
6780 | section != NULL; | |
6781 | section = section->next) | |
6782 | { | |
721956f4 | 6783 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
721956f4 AM |
6784 | |
6785 | /* If there aren't any relocs, then there's nothing more | |
6786 | to do. */ | |
6787 | if ((section->flags & SEC_RELOC) == 0 | |
6788 | || section->reloc_count == 0) | |
6789 | continue; | |
6790 | ||
6791 | /* If this section is a link-once section that will be | |
6792 | discarded, then don't create any stubs. */ | |
6793 | if (section->output_section == NULL | |
6794 | || section->output_section->owner != output_bfd) | |
6795 | continue; | |
6796 | ||
1e2f5b6e AM |
6797 | /* Get the relocs. */ |
6798 | internal_relocs | |
4ce794b7 | 6799 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
45d6a902 | 6800 | info->keep_memory); |
721956f4 | 6801 | if (internal_relocs == NULL) |
1e2f5b6e | 6802 | goto error_ret_free_local; |
721956f4 AM |
6803 | |
6804 | /* Now examine each relocation. */ | |
6805 | irela = internal_relocs; | |
6806 | irelaend = irela + section->reloc_count; | |
6807 | for (; irela < irelaend; irela++) | |
6808 | { | |
4ce794b7 AM |
6809 | enum elf_ppc64_reloc_type r_type; |
6810 | unsigned int r_indx; | |
721956f4 AM |
6811 | enum ppc_stub_type stub_type; |
6812 | struct ppc_stub_hash_entry *stub_entry; | |
6813 | asection *sym_sec; | |
6814 | bfd_vma sym_value; | |
6815 | bfd_vma destination; | |
6816 | struct ppc_link_hash_entry *hash; | |
411e1bfb AM |
6817 | struct elf_link_hash_entry *h; |
6818 | Elf_Internal_Sym *sym; | |
721956f4 AM |
6819 | char *stub_name; |
6820 | const asection *id_sec; | |
6821 | ||
6822 | r_type = ELF64_R_TYPE (irela->r_info); | |
6823 | r_indx = ELF64_R_SYM (irela->r_info); | |
6824 | ||
4ce794b7 | 6825 | if (r_type >= R_PPC64_max) |
721956f4 AM |
6826 | { |
6827 | bfd_set_error (bfd_error_bad_value); | |
6cdc0ccc | 6828 | goto error_ret_free_internal; |
721956f4 AM |
6829 | } |
6830 | ||
6831 | /* Only look for stubs on branch instructions. */ | |
4ce794b7 AM |
6832 | if (r_type != R_PPC64_REL24 |
6833 | && r_type != R_PPC64_REL14 | |
6834 | && r_type != R_PPC64_REL14_BRTAKEN | |
6835 | && r_type != R_PPC64_REL14_BRNTAKEN) | |
721956f4 AM |
6836 | continue; |
6837 | ||
6838 | /* Now determine the call target, its name, value, | |
6839 | section. */ | |
721956f4 | 6840 | destination = 0; |
411e1bfb AM |
6841 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
6842 | r_indx, input_bfd)) | |
6843 | goto error_ret_free_internal; | |
6844 | hash = (struct ppc_link_hash_entry *) h; | |
6845 | ||
6846 | if (hash == NULL) | |
721956f4 AM |
6847 | { |
6848 | /* It's a local symbol. */ | |
411e1bfb | 6849 | sym_value = sym->st_value; |
721956f4 AM |
6850 | destination = (sym_value + irela->r_addend |
6851 | + sym_sec->output_offset | |
6852 | + sym_sec->output_section->vma); | |
6853 | } | |
6854 | else | |
6855 | { | |
6856 | /* It's an external symbol. */ | |
411e1bfb | 6857 | sym_value = 0; |
721956f4 AM |
6858 | if (hash->elf.root.type == bfd_link_hash_defined |
6859 | || hash->elf.root.type == bfd_link_hash_defweak) | |
6860 | { | |
721956f4 AM |
6861 | sym_value = hash->elf.root.u.def.value; |
6862 | if (sym_sec->output_section != NULL) | |
6863 | destination = (sym_value + irela->r_addend | |
6864 | + sym_sec->output_offset | |
6865 | + sym_sec->output_section->vma); | |
6866 | } | |
6867 | else if (hash->elf.root.type == bfd_link_hash_undefweak) | |
6868 | ; | |
6869 | else if (hash->elf.root.type == bfd_link_hash_undefined) | |
6870 | ; | |
6871 | else | |
6872 | { | |
6873 | bfd_set_error (bfd_error_bad_value); | |
6874 | goto error_ret_free_internal; | |
6875 | } | |
6876 | } | |
6877 | ||
6878 | /* Determine what (if any) linker stub is needed. */ | |
6879 | stub_type = ppc_type_of_stub (section, irela, &hash, | |
6880 | destination); | |
ad8e1ba5 AM |
6881 | |
6882 | if (stub_type != ppc_stub_plt_call) | |
6883 | { | |
6884 | /* Check whether we need a TOC adjusting stub. | |
6885 | Since the linker pastes together pieces from | |
6886 | different object files when creating the | |
6887 | _init and _fini functions, it may be that a | |
6888 | call to what looks like a local sym is in | |
6889 | fact a call needing a TOC adjustment. */ | |
6890 | if (sym_sec != NULL | |
6891 | && sym_sec->output_section != NULL | |
6892 | && (htab->stub_group[sym_sec->id].toc_off | |
9b5ecbd0 AM |
6893 | != htab->stub_group[section->id].toc_off) |
6894 | && sym_sec->has_gp_reloc | |
6895 | && section->has_gp_reloc) | |
ad8e1ba5 AM |
6896 | stub_type = ppc_stub_long_branch_r2off; |
6897 | } | |
6898 | ||
721956f4 AM |
6899 | if (stub_type == ppc_stub_none) |
6900 | continue; | |
6901 | ||
411e1bfb AM |
6902 | /* __tls_get_addr calls might be eliminated. */ |
6903 | if (stub_type != ppc_stub_plt_call | |
6904 | && hash != NULL | |
6905 | && &hash->elf == htab->tls_get_addr | |
6906 | && section->has_tls_reloc | |
6907 | && irela != internal_relocs) | |
6908 | { | |
6909 | /* Get tls info. */ | |
e7b938ca | 6910 | char *tls_mask; |
411e1bfb | 6911 | |
e7b938ca | 6912 | if (!get_tls_mask (&tls_mask, &local_syms, |
411e1bfb AM |
6913 | irela - 1, input_bfd)) |
6914 | goto error_ret_free_internal; | |
e7b938ca | 6915 | if (*tls_mask != 0) |
411e1bfb AM |
6916 | continue; |
6917 | } | |
6918 | ||
721956f4 AM |
6919 | /* Support for grouping stub sections. */ |
6920 | id_sec = htab->stub_group[section->id].link_sec; | |
6921 | ||
6922 | /* Get the name of this stub. */ | |
6923 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); | |
6924 | if (!stub_name) | |
6925 | goto error_ret_free_internal; | |
6926 | ||
6927 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, | |
b34976b6 | 6928 | stub_name, FALSE, FALSE); |
721956f4 AM |
6929 | if (stub_entry != NULL) |
6930 | { | |
6931 | /* The proper stub has already been created. */ | |
6932 | free (stub_name); | |
6933 | continue; | |
6934 | } | |
6935 | ||
6936 | stub_entry = ppc_add_stub (stub_name, section, htab); | |
6937 | if (stub_entry == NULL) | |
6938 | { | |
6939 | free (stub_name); | |
6cdc0ccc AM |
6940 | error_ret_free_internal: |
6941 | if (elf_section_data (section)->relocs == NULL) | |
6942 | free (internal_relocs); | |
6943 | error_ret_free_local: | |
6944 | if (local_syms != NULL | |
6945 | && (symtab_hdr->contents | |
6946 | != (unsigned char *) local_syms)) | |
6947 | free (local_syms); | |
b34976b6 | 6948 | return FALSE; |
721956f4 AM |
6949 | } |
6950 | ||
ad8e1ba5 | 6951 | stub_entry->stub_type = stub_type; |
721956f4 AM |
6952 | stub_entry->target_value = sym_value; |
6953 | stub_entry->target_section = sym_sec; | |
721956f4 | 6954 | stub_entry->h = hash; |
411e1bfb | 6955 | stub_entry->addend = irela->r_addend; |
b34976b6 | 6956 | stub_changed = TRUE; |
721956f4 AM |
6957 | } |
6958 | ||
6959 | /* We're done with the internal relocs, free them. */ | |
6cdc0ccc | 6960 | if (elf_section_data (section)->relocs != internal_relocs) |
1e2f5b6e | 6961 | free (internal_relocs); |
721956f4 | 6962 | } |
6cdc0ccc AM |
6963 | |
6964 | if (local_syms != NULL | |
6965 | && symtab_hdr->contents != (unsigned char *) local_syms) | |
6966 | { | |
6967 | if (!info->keep_memory) | |
6968 | free (local_syms); | |
6969 | else | |
6970 | symtab_hdr->contents = (unsigned char *) local_syms; | |
6971 | } | |
721956f4 AM |
6972 | } |
6973 | ||
6974 | if (!stub_changed) | |
6975 | break; | |
6976 | ||
6977 | /* OK, we've added some stubs. Find out the new size of the | |
6978 | stub sections. */ | |
6979 | for (stub_sec = htab->stub_bfd->sections; | |
6980 | stub_sec != NULL; | |
6981 | stub_sec = stub_sec->next) | |
e717da7e AM |
6982 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
6983 | { | |
6984 | stub_sec->_raw_size = 0; | |
6985 | stub_sec->_cooked_size = 0; | |
6986 | } | |
4ce794b7 AM |
6987 | htab->brlt->_raw_size = 0; |
6988 | htab->brlt->_cooked_size = 0; | |
721956f4 AM |
6989 | |
6990 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab); | |
6991 | ||
6992 | /* Ask the linker to do its stuff. */ | |
6993 | (*htab->layout_sections_again) (); | |
6994 | } | |
6995 | ||
afbe61cf AM |
6996 | /* It would be nice to strip .branch_lt from the output if the |
6997 | section is empty, but it's too late. If we strip sections here, | |
6998 | the dynamic symbol table is corrupted since the section symbol | |
6999 | for the stripped section isn't written. */ | |
721956f4 | 7000 | |
b34976b6 | 7001 | return TRUE; |
721956f4 AM |
7002 | } |
7003 | ||
7004 | /* Called after we have determined section placement. If sections | |
805fc799 | 7005 | move, we'll be called again. Provide a value for TOCstart. */ |
721956f4 | 7006 | |
805fc799 | 7007 | bfd_vma |
4ce794b7 | 7008 | ppc64_elf_toc (bfd *obfd) |
721956f4 | 7009 | { |
805fc799 AM |
7010 | asection *s; |
7011 | bfd_vma TOCstart; | |
721956f4 | 7012 | |
805fc799 AM |
7013 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
7014 | order. The TOC starts where the first of these sections starts. */ | |
7015 | s = bfd_get_section_by_name (obfd, ".got"); | |
7016 | if (s == NULL) | |
7017 | s = bfd_get_section_by_name (obfd, ".toc"); | |
7018 | if (s == NULL) | |
7019 | s = bfd_get_section_by_name (obfd, ".tocbss"); | |
7020 | if (s == NULL) | |
7021 | s = bfd_get_section_by_name (obfd, ".plt"); | |
7022 | if (s == NULL) | |
7023 | { | |
7024 | /* This may happen for | |
7025 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
7026 | .toc directive | |
7027 | o bad linker script | |
7028 | o --gc-sections and empty TOC sections | |
7029 | ||
7030 | FIXME: Warn user? */ | |
7031 | ||
7032 | /* Look for a likely section. We probably won't even be | |
7033 | using TOCstart. */ | |
7034 | for (s = obfd->sections; s != NULL; s = s->next) | |
7035 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) | |
7036 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7037 | break; | |
721956f4 | 7038 | if (s == NULL) |
805fc799 AM |
7039 | for (s = obfd->sections; s != NULL; s = s->next) |
7040 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) | |
7041 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
7042 | break; | |
721956f4 | 7043 | if (s == NULL) |
805fc799 AM |
7044 | for (s = obfd->sections; s != NULL; s = s->next) |
7045 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) | |
7046 | break; | |
721956f4 | 7047 | if (s == NULL) |
805fc799 AM |
7048 | for (s = obfd->sections; s != NULL; s = s->next) |
7049 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) | |
7050 | break; | |
7051 | } | |
721956f4 | 7052 | |
805fc799 AM |
7053 | TOCstart = 0; |
7054 | if (s != NULL) | |
7055 | TOCstart = s->output_section->vma + s->output_offset; | |
721956f4 | 7056 | |
805fc799 | 7057 | return TOCstart; |
721956f4 AM |
7058 | } |
7059 | ||
7060 | /* Build all the stubs associated with the current output file. | |
7061 | The stubs are kept in a hash table attached to the main linker | |
7062 | hash table. This function is called via gldelf64ppc_finish. */ | |
7063 | ||
b34976b6 | 7064 | bfd_boolean |
4ce794b7 AM |
7065 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
7066 | struct bfd_link_info *info, | |
7067 | char **stats) | |
5d1634d7 AM |
7068 | { |
7069 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
721956f4 | 7070 | asection *stub_sec; |
5d1634d7 | 7071 | bfd_byte *p; |
e717da7e | 7072 | int stub_sec_count = 0; |
5d1634d7 | 7073 | |
ad8e1ba5 | 7074 | htab->emit_stub_syms = emit_stub_syms; |
721956f4 AM |
7075 | for (stub_sec = htab->stub_bfd->sections; |
7076 | stub_sec != NULL; | |
7077 | stub_sec = stub_sec->next) | |
e717da7e AM |
7078 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7079 | { | |
7080 | bfd_size_type size; | |
721956f4 | 7081 | |
e717da7e AM |
7082 | /* Allocate memory to hold the linker stubs. */ |
7083 | size = stub_sec->_raw_size; | |
7084 | if (size != 0) | |
7085 | { | |
7086 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); | |
7087 | if (stub_sec->contents == NULL) | |
7088 | return FALSE; | |
7089 | } | |
7090 | stub_sec->_cooked_size = 0; | |
7091 | } | |
5d1634d7 | 7092 | |
4ce794b7 | 7093 | if (htab->plt != NULL) |
5d1634d7 | 7094 | { |
9f951329 | 7095 | unsigned int indx; |
ad8e1ba5 | 7096 | bfd_vma plt0; |
9f951329 | 7097 | |
721956f4 | 7098 | /* Build the .glink plt call stub. */ |
4ce794b7 AM |
7099 | plt0 = (htab->plt->output_section->vma |
7100 | + htab->plt->output_offset | |
7101 | - (htab->glink->output_section->vma | |
7102 | + htab->glink->output_offset | |
ad8e1ba5 AM |
7103 | + GLINK_CALL_STUB_SIZE)); |
7104 | if (plt0 + 0x80008000 > 0xffffffff) | |
721956f4 | 7105 | { |
ad8e1ba5 AM |
7106 | (*_bfd_error_handler) (_(".glink and .plt too far apart")); |
7107 | bfd_set_error (bfd_error_bad_value); | |
7108 | return FALSE; | |
721956f4 | 7109 | } |
721956f4 | 7110 | |
97b639ba AM |
7111 | if (htab->emit_stub_syms) |
7112 | { | |
7113 | struct elf_link_hash_entry *h; | |
7114 | h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE); | |
7115 | if (h == NULL) | |
7116 | return FALSE; | |
7117 | if (h->root.type == bfd_link_hash_new) | |
7118 | { | |
7119 | h->root.type = bfd_link_hash_defined; | |
7120 | h->root.u.def.section = htab->glink; | |
7121 | h->root.u.def.value = 0; | |
7122 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR | |
7123 | | ELF_LINK_HASH_DEF_REGULAR | |
7124 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | |
7125 | | ELF_LINK_FORCED_LOCAL); | |
7126 | } | |
7127 | } | |
4ce794b7 AM |
7128 | p = htab->glink->contents; |
7129 | bfd_put_32 (htab->glink->owner, MFCTR_R12, p); | |
ad8e1ba5 | 7130 | p += 4; |
4ce794b7 | 7131 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p); |
ad8e1ba5 | 7132 | p += 4; |
4ce794b7 | 7133 | bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p); |
ad8e1ba5 | 7134 | p += 4; |
4ce794b7 | 7135 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7136 | p += 4; |
4ce794b7 | 7137 | bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p); |
ad8e1ba5 | 7138 | p += 4; |
4ce794b7 | 7139 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p); |
ad8e1ba5 | 7140 | p += 4; |
4ce794b7 | 7141 | bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p); |
ad8e1ba5 | 7142 | p += 4; |
4ce794b7 | 7143 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
ad8e1ba5 | 7144 | p += 4; |
4ce794b7 | 7145 | bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p); |
ad8e1ba5 | 7146 | p += 4; |
4ce794b7 | 7147 | bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p); |
ad8e1ba5 | 7148 | p += 4; |
4ce794b7 | 7149 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7150 | p += 4; |
4ce794b7 | 7151 | bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p); |
ad8e1ba5 | 7152 | p += 4; |
4ce794b7 | 7153 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
ad8e1ba5 | 7154 | p += 4; |
4ce794b7 | 7155 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
ad8e1ba5 | 7156 | p += 4; |
4ce794b7 | 7157 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
ad8e1ba5 | 7158 | p += 4; |
4ce794b7 | 7159 | bfd_put_32 (htab->glink->owner, BCTR, p); |
ad8e1ba5 AM |
7160 | p += 4; |
7161 | ||
9f951329 AM |
7162 | /* Build the .glink lazy link call stubs. */ |
7163 | indx = 0; | |
4ce794b7 | 7164 | while (p < htab->glink->contents + htab->glink->_raw_size) |
9f951329 AM |
7165 | { |
7166 | if (indx < 0x8000) | |
7167 | { | |
4ce794b7 | 7168 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
9f951329 AM |
7169 | p += 4; |
7170 | } | |
7171 | else | |
7172 | { | |
4ce794b7 | 7173 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
9f951329 | 7174 | p += 4; |
4ce794b7 | 7175 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
9f951329 AM |
7176 | p += 4; |
7177 | } | |
4ce794b7 AM |
7178 | bfd_put_32 (htab->glink->owner, |
7179 | B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p); | |
a16d5acb | 7180 | indx++; |
9f951329 AM |
7181 | p += 4; |
7182 | } | |
4ce794b7 | 7183 | htab->glink->_cooked_size = p - htab->glink->contents; |
5d1634d7 | 7184 | } |
5d1634d7 | 7185 | |
4ce794b7 | 7186 | if (htab->brlt->_raw_size != 0) |
721956f4 | 7187 | { |
4ce794b7 AM |
7188 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
7189 | htab->brlt->_raw_size); | |
7190 | if (htab->brlt->contents == NULL) | |
b34976b6 | 7191 | return FALSE; |
721956f4 | 7192 | } |
5d1634d7 | 7193 | |
721956f4 AM |
7194 | /* Build the stubs as directed by the stub hash table. */ |
7195 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); | |
5d1634d7 | 7196 | |
721956f4 AM |
7197 | for (stub_sec = htab->stub_bfd->sections; |
7198 | stub_sec != NULL; | |
7199 | stub_sec = stub_sec->next) | |
e717da7e AM |
7200 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
7201 | { | |
7202 | stub_sec_count += 1; | |
7203 | if (stub_sec->_raw_size != stub_sec->_cooked_size) | |
7204 | break; | |
7205 | } | |
5d1634d7 | 7206 | |
721956f4 | 7207 | if (stub_sec != NULL |
4ce794b7 | 7208 | || htab->glink->_raw_size != htab->glink->_cooked_size) |
5d1634d7 | 7209 | { |
b34976b6 | 7210 | htab->stub_error = TRUE; |
721956f4 | 7211 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
5d1634d7 | 7212 | } |
721956f4 | 7213 | |
d2a300cf AM |
7214 | if (htab->stub_error) |
7215 | return FALSE; | |
7216 | ||
7217 | if (stats != NULL) | |
7218 | { | |
7219 | *stats = bfd_malloc (500); | |
7220 | if (*stats == NULL) | |
7221 | return FALSE; | |
7222 | ||
7223 | sprintf (*stats, _("linker stubs in %u groups\n" | |
7224 | " branch %lu\n" | |
7225 | " toc adjust %lu\n" | |
7226 | " long branch %lu\n" | |
7227 | " long toc adj %lu\n" | |
7228 | " plt call %lu"), | |
e717da7e | 7229 | stub_sec_count, |
4ce794b7 AM |
7230 | htab->stub_count[ppc_stub_long_branch - 1], |
7231 | htab->stub_count[ppc_stub_long_branch_r2off - 1], | |
7232 | htab->stub_count[ppc_stub_plt_branch - 1], | |
7233 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], | |
7234 | htab->stub_count[ppc_stub_plt_call - 1]); | |
d2a300cf AM |
7235 | } |
7236 | return TRUE; | |
5bd4f169 AM |
7237 | } |
7238 | ||
5bd4f169 AM |
7239 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
7240 | to handle the relocations for a section. | |
7241 | ||
7242 | The relocs are always passed as Rela structures; if the section | |
7243 | actually uses Rel structures, the r_addend field will always be | |
7244 | zero. | |
7245 | ||
7246 | This function is responsible for adjust the section contents as | |
7247 | necessary, and (if using Rela relocs and generating a | |
1049f94e | 7248 | relocatable output file) adjusting the reloc addend as |
5bd4f169 AM |
7249 | necessary. |
7250 | ||
7251 | This function does not have to worry about setting the reloc | |
7252 | address or the reloc symbol index. | |
7253 | ||
7254 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
7255 | ||
7256 | LOCAL_SECTIONS is an array giving the section in the input file | |
7257 | corresponding to the st_shndx field of each local symbol. | |
7258 | ||
7259 | The global hash table entry for the global symbols can be found | |
7260 | via elf_sym_hashes (input_bfd). | |
7261 | ||
1049f94e | 7262 | When generating relocatable output, this function must handle |
5bd4f169 AM |
7263 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
7264 | going to be the section symbol corresponding to the output | |
7265 | section, which means that the addend must be adjusted | |
7266 | accordingly. */ | |
7267 | ||
b34976b6 | 7268 | static bfd_boolean |
4ce794b7 AM |
7269 | ppc64_elf_relocate_section (bfd *output_bfd, |
7270 | struct bfd_link_info *info, | |
7271 | bfd *input_bfd, | |
7272 | asection *input_section, | |
7273 | bfd_byte *contents, | |
7274 | Elf_Internal_Rela *relocs, | |
7275 | Elf_Internal_Sym *local_syms, | |
7276 | asection **local_sections) | |
5bd4f169 | 7277 | { |
65f38f15 | 7278 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
7279 | Elf_Internal_Shdr *symtab_hdr; |
7280 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
7281 | Elf_Internal_Rela *rel; |
7282 | Elf_Internal_Rela *relend; | |
411e1bfb AM |
7283 | Elf_Internal_Rela outrel; |
7284 | bfd_byte *loc; | |
411e1bfb | 7285 | struct got_entry **local_got_ents; |
5bd4f169 | 7286 | bfd_vma TOCstart; |
b34976b6 AM |
7287 | bfd_boolean ret = TRUE; |
7288 | bfd_boolean is_opd; | |
96e0dda4 | 7289 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
b34976b6 | 7290 | bfd_boolean is_power4 = FALSE; |
5bd4f169 | 7291 | |
1049f94e | 7292 | if (info->relocatable) |
b34976b6 | 7293 | return TRUE; |
b491616a | 7294 | |
65f38f15 | 7295 | /* Initialize howto table if needed. */ |
5bd4f169 | 7296 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
7297 | ppc_howto_init (); |
7298 | ||
65f38f15 | 7299 | htab = ppc_hash_table (info); |
411e1bfb | 7300 | local_got_ents = elf_local_got_ents (input_bfd); |
5bd4f169 | 7301 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
7302 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
7303 | sym_hashes = elf_sym_hashes (input_bfd); | |
f0abc2a1 | 7304 | is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL; |
65f38f15 | 7305 | |
5bd4f169 AM |
7306 | rel = relocs; |
7307 | relend = relocs + input_section->reloc_count; | |
7308 | for (; rel < relend; rel++) | |
7309 | { | |
04c9666a | 7310 | enum elf_ppc64_reloc_type r_type; |
5bd4f169 AM |
7311 | bfd_vma addend; |
7312 | bfd_reloc_status_type r; | |
7313 | Elf_Internal_Sym *sym; | |
7314 | asection *sec; | |
7315 | struct elf_link_hash_entry *h; | |
721956f4 | 7316 | struct elf_link_hash_entry *fdh; |
5bd4f169 | 7317 | const char *sym_name; |
5bd4f169 | 7318 | unsigned long r_symndx; |
951fd09b | 7319 | char tls_mask, tls_gd, tls_type; |
5bd4f169 | 7320 | bfd_vma relocation; |
b34976b6 AM |
7321 | bfd_boolean unresolved_reloc; |
7322 | bfd_boolean warned; | |
50bc7936 | 7323 | unsigned long insn, mask; |
721956f4 AM |
7324 | struct ppc_stub_hash_entry *stub_entry; |
7325 | bfd_vma max_br_offset; | |
7326 | bfd_vma from; | |
5bd4f169 | 7327 | |
4ce794b7 | 7328 | r_type = ELF64_R_TYPE (rel->r_info); |
5bd4f169 | 7329 | r_symndx = ELF64_R_SYM (rel->r_info); |
4ce794b7 AM |
7330 | sym = NULL; |
7331 | sec = NULL; | |
7332 | h = NULL; | |
7333 | sym_name = NULL; | |
b34976b6 AM |
7334 | unresolved_reloc = FALSE; |
7335 | warned = FALSE; | |
65f38f15 | 7336 | |
0b13192e | 7337 | if (r_symndx < symtab_hdr->sh_info) |
5bd4f169 AM |
7338 | { |
7339 | /* It's a local symbol. */ | |
7340 | sym = local_syms + r_symndx; | |
7341 | sec = local_sections[r_symndx]; | |
411e1bfb | 7342 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
f8df10f4 | 7343 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
1e2f5b6e AM |
7344 | if (elf_section_data (sec) != NULL) |
7345 | { | |
7346 | long *opd_sym_adjust; | |
7347 | ||
f0abc2a1 | 7348 | opd_sym_adjust = ppc64_elf_section_data (sec)->opd.adjust; |
1e2f5b6e AM |
7349 | if (opd_sym_adjust != NULL && sym->st_value % 24 == 0) |
7350 | relocation += opd_sym_adjust[sym->st_value / 24]; | |
7351 | } | |
5bd4f169 AM |
7352 | } |
7353 | else | |
7354 | { | |
7355 | /* It's a global symbol. */ | |
7356 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
7357 | while (h->root.type == bfd_link_hash_indirect | |
7358 | || h->root.type == bfd_link_hash_warning) | |
7359 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
7360 | sym_name = h->root.root.string; | |
65f38f15 | 7361 | relocation = 0; |
5bd4f169 AM |
7362 | if (h->root.type == bfd_link_hash_defined |
7363 | || h->root.type == bfd_link_hash_defweak) | |
7364 | { | |
7365 | sec = h->root.u.def.section; | |
65f38f15 AM |
7366 | if (sec->output_section == NULL) |
7367 | /* Set a flag that will be cleared later if we find a | |
7368 | relocation value for this symbol. output_section | |
7369 | is typically NULL for symbols satisfied by a shared | |
7370 | library. */ | |
b34976b6 | 7371 | unresolved_reloc = TRUE; |
5bd4f169 AM |
7372 | else |
7373 | relocation = (h->root.u.def.value | |
7374 | + sec->output_section->vma | |
7375 | + sec->output_offset); | |
7376 | } | |
7377 | else if (h->root.type == bfd_link_hash_undefweak) | |
65f38f15 | 7378 | ; |
9203ba99 | 7379 | else if (!info->executable |
65f38f15 AM |
7380 | && !info->no_undefined |
7381 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
7382 | ; | |
5bd4f169 AM |
7383 | else |
7384 | { | |
7385 | if (! ((*info->callbacks->undefined_symbol) | |
7386 | (info, h->root.root.string, input_bfd, input_section, | |
15f40dfc | 7387 | rel->r_offset, (info->executable |
411e1bfb AM |
7388 | || info->no_undefined |
7389 | || ELF_ST_VISIBILITY (h->other))))) | |
b34976b6 AM |
7390 | return FALSE; |
7391 | warned = TRUE; | |
5bd4f169 AM |
7392 | } |
7393 | } | |
7394 | ||
951fd09b AM |
7395 | /* TLS optimizations. Replace instruction sequences and relocs |
7396 | based on information we collected in tls_optimize. We edit | |
7397 | RELOCS so that --emit-relocs will output something sensible | |
7398 | for the final instruction stream. */ | |
7399 | tls_mask = 0; | |
7400 | tls_gd = 0; | |
d881513a | 7401 | if (IS_PPC64_TLS_RELOC (r_type)) |
411e1bfb AM |
7402 | { |
7403 | if (h != NULL) | |
e7b938ca | 7404 | tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask; |
411e1bfb AM |
7405 | else if (local_got_ents != NULL) |
7406 | { | |
e7b938ca AM |
7407 | char *lgot_masks; |
7408 | lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); | |
7409 | tls_mask = lgot_masks[r_symndx]; | |
411e1bfb AM |
7410 | } |
7411 | } | |
7412 | ||
7413 | /* Ensure reloc mapping code below stays sane. */ | |
7414 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 | |
7415 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 | |
7416 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) | |
7417 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) | |
7418 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) | |
7419 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) | |
7420 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) | |
7421 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) | |
7422 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) | |
7423 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) | |
7424 | abort (); | |
7425 | switch (r_type) | |
7426 | { | |
7427 | default: | |
411e1bfb AM |
7428 | break; |
7429 | ||
7430 | case R_PPC64_TOC16: | |
7431 | case R_PPC64_TOC16_LO: | |
7432 | case R_PPC64_TOC16_DS: | |
7433 | case R_PPC64_TOC16_LO_DS: | |
411e1bfb AM |
7434 | { |
7435 | /* Check for toc tls entries. */ | |
7436 | char *toc_tls; | |
951fd09b | 7437 | int retval; |
411e1bfb | 7438 | |
e7b938ca | 7439 | retval = get_tls_mask (&toc_tls, &local_syms, rel, input_bfd); |
951fd09b | 7440 | if (retval == 0) |
411e1bfb AM |
7441 | return FALSE; |
7442 | ||
7443 | if (toc_tls) | |
7444 | { | |
951fd09b | 7445 | tls_mask = *toc_tls; |
411e1bfb AM |
7446 | if (r_type == R_PPC64_TOC16_DS |
7447 | || r_type == R_PPC64_TOC16_LO_DS) | |
81407a69 AM |
7448 | { |
7449 | if (tls_mask != 0 | |
7450 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) | |
7451 | goto toctprel; | |
7452 | } | |
411e1bfb | 7453 | else |
951fd09b AM |
7454 | { |
7455 | /* If we found a GD reloc pair, then we might be | |
7456 | doing a GD->IE transition. */ | |
7457 | if (retval == 2) | |
7458 | { | |
7459 | tls_gd = TLS_TPRELGD; | |
7460 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7461 | goto tls_get_addr_check; | |
7462 | } | |
7463 | else if (retval == 3) | |
7464 | { | |
7465 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7466 | goto tls_get_addr_check; | |
7467 | } | |
7468 | } | |
411e1bfb AM |
7469 | } |
7470 | } | |
7471 | break; | |
7472 | ||
7473 | case R_PPC64_GOT_TPREL16_DS: | |
7474 | case R_PPC64_GOT_TPREL16_LO_DS: | |
951fd09b AM |
7475 | if (tls_mask != 0 |
7476 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7477 | { |
81407a69 | 7478 | toctprel: |
411e1bfb AM |
7479 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); |
7480 | insn &= 31 << 21; | |
7481 | insn |= 0x3c0d0000; /* addis 0,13,0 */ | |
7482 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
7483 | r_type = R_PPC64_TPREL16_HA; | |
7484 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7485 | } | |
7486 | break; | |
7487 | ||
7488 | case R_PPC64_TLS: | |
951fd09b | 7489 | if (tls_mask == 0) |
411e1bfb AM |
7490 | { |
7491 | /* Check for toc tls entries. */ | |
7492 | char *toc_tls; | |
7493 | ||
e7b938ca | 7494 | if (!get_tls_mask (&toc_tls, &local_syms, rel, input_bfd)) |
411e1bfb AM |
7495 | return FALSE; |
7496 | ||
7497 | if (toc_tls) | |
951fd09b | 7498 | tls_mask = *toc_tls; |
411e1bfb | 7499 | } |
951fd09b AM |
7500 | if (tls_mask != 0 |
7501 | && (tls_mask & TLS_TPREL) == 0) | |
411e1bfb | 7502 | { |
50bc7936 | 7503 | bfd_vma rtra; |
411e1bfb | 7504 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
772119ce | 7505 | if ((insn & ((0x3f << 26) | (31 << 11))) |
411e1bfb AM |
7506 | == ((31 << 26) | (13 << 11))) |
7507 | rtra = insn & ((1 << 26) - (1 << 16)); | |
772119ce | 7508 | else if ((insn & ((0x3f << 26) | (31 << 16))) |
411e1bfb AM |
7509 | == ((31 << 26) | (13 << 16))) |
7510 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
7511 | else | |
7512 | abort (); | |
7513 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
7514 | /* add -> addi. */ | |
7515 | insn = 14 << 26; | |
7516 | else if ((insn & (31 << 1)) == 23 << 1 | |
7517 | && ((insn & (31 << 6)) < 14 << 6 | |
7518 | || ((insn & (31 << 6)) >= 16 << 6 | |
7519 | && (insn & (31 << 6)) < 24 << 6))) | |
7520 | /* load and store indexed -> dform. */ | |
7521 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
7522 | else if ((insn & (31 << 1)) == 21 << 1 | |
7523 | && (insn & (0x1a << 6)) == 0) | |
7524 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
7525 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
7526 | | ((insn >> 6) & 1)); | |
7527 | else if ((insn & (31 << 1)) == 21 << 1 | |
7528 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
7529 | /* lwax -> lwa. */ | |
7530 | insn = (58 << 26) | 2; | |
7531 | else | |
7532 | abort (); | |
7533 | insn |= rtra; | |
7534 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
7535 | r_type = R_PPC64_TPREL16_LO; | |
7536 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7537 | /* Was PPC64_TLS which sits on insn boundary, now | |
7538 | PPC64_TPREL16_LO which is at insn+2. */ | |
7539 | rel->r_offset += 2; | |
7540 | } | |
7541 | break; | |
7542 | ||
411e1bfb AM |
7543 | case R_PPC64_GOT_TLSGD16_HI: |
7544 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b AM |
7545 | tls_gd = TLS_TPRELGD; |
7546 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7547 | goto tls_gdld_hi; | |
7548 | break; | |
7549 | ||
411e1bfb AM |
7550 | case R_PPC64_GOT_TLSLD16_HI: |
7551 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 7552 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
411e1bfb | 7553 | { |
951fd09b AM |
7554 | tls_gdld_hi: |
7555 | if ((tls_mask & tls_gd) != 0) | |
7556 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7557 | + R_PPC64_GOT_TPREL16_DS); | |
7558 | else | |
411e1bfb | 7559 | { |
951fd09b AM |
7560 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
7561 | rel->r_offset -= 2; | |
7562 | r_type = R_PPC64_NONE; | |
411e1bfb | 7563 | } |
951fd09b | 7564 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb AM |
7565 | } |
7566 | break; | |
7567 | ||
951fd09b AM |
7568 | case R_PPC64_GOT_TLSGD16: |
7569 | case R_PPC64_GOT_TLSGD16_LO: | |
7570 | tls_gd = TLS_TPRELGD; | |
7571 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
7572 | goto tls_get_addr_check; | |
7573 | break; | |
411e1bfb | 7574 | |
951fd09b AM |
7575 | case R_PPC64_GOT_TLSLD16: |
7576 | case R_PPC64_GOT_TLSLD16_LO: | |
7577 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
7578 | { | |
7579 | tls_get_addr_check: | |
7580 | if (rel + 1 < relend) | |
411e1bfb | 7581 | { |
951fd09b AM |
7582 | enum elf_ppc64_reloc_type r_type2; |
7583 | unsigned long r_symndx2; | |
7584 | struct elf_link_hash_entry *h2; | |
7585 | bfd_vma insn1, insn2, insn3; | |
7586 | bfd_vma offset; | |
7587 | ||
7588 | /* The next instruction should be a call to | |
7589 | __tls_get_addr. Peek at the reloc to be sure. */ | |
4ce794b7 | 7590 | r_type2 = ELF64_R_TYPE (rel[1].r_info); |
951fd09b AM |
7591 | r_symndx2 = ELF64_R_SYM (rel[1].r_info); |
7592 | if (r_symndx2 < symtab_hdr->sh_info | |
7593 | || (r_type2 != R_PPC64_REL14 | |
7594 | && r_type2 != R_PPC64_REL14_BRTAKEN | |
7595 | && r_type2 != R_PPC64_REL14_BRNTAKEN | |
7596 | && r_type2 != R_PPC64_REL24)) | |
7597 | break; | |
7598 | ||
7599 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
7600 | while (h2->root.type == bfd_link_hash_indirect | |
7601 | || h2->root.type == bfd_link_hash_warning) | |
7602 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
7603 | if (h2 == NULL || h2 != htab->tls_get_addr) | |
7604 | break; | |
7605 | ||
7606 | /* OK, it checks out. Replace the call. */ | |
7607 | offset = rel[1].r_offset; | |
7608 | insn1 = bfd_get_32 (output_bfd, | |
7609 | contents + rel->r_offset - 2); | |
7610 | insn3 = bfd_get_32 (output_bfd, | |
7611 | contents + offset + 4); | |
7612 | if ((tls_mask & tls_gd) != 0) | |
411e1bfb | 7613 | { |
951fd09b AM |
7614 | /* IE */ |
7615 | insn1 &= (1 << 26) - (1 << 2); | |
7616 | insn1 |= 58 << 26; /* ld */ | |
7617 | insn2 = 0x7c636a14; /* add 3,3,13 */ | |
7618 | rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); | |
7619 | if ((tls_mask & TLS_EXPLICIT) == 0) | |
7620 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) | |
7621 | + R_PPC64_GOT_TPREL16_DS); | |
7622 | else | |
7623 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; | |
7624 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
411e1bfb AM |
7625 | } |
7626 | else | |
951fd09b AM |
7627 | { |
7628 | /* LE */ | |
7629 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ | |
7630 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
7631 | if (tls_gd == 0) | |
7632 | { | |
7633 | /* Was an LD reloc. */ | |
7634 | r_symndx = 0; | |
7635 | rel->r_addend = htab->tls_sec->vma + DTP_OFFSET; | |
7636 | rel[1].r_addend = htab->tls_sec->vma + DTP_OFFSET; | |
7637 | } | |
7638 | r_type = R_PPC64_TPREL16_HA; | |
7639 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7640 | rel[1].r_info = ELF64_R_INFO (r_symndx, | |
7641 | R_PPC64_TPREL16_LO); | |
7642 | rel[1].r_offset += 2; | |
7643 | } | |
7644 | if (insn3 == NOP | |
7645 | || insn3 == CROR_151515 || insn3 == CROR_313131) | |
7646 | { | |
7647 | insn3 = insn2; | |
7648 | insn2 = NOP; | |
7649 | rel[1].r_offset += 4; | |
7650 | } | |
7651 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); | |
7652 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7653 | bfd_put_32 (output_bfd, insn3, contents + offset + 4); | |
7654 | if (tls_gd == 0) | |
7655 | { | |
7656 | /* We changed the symbol on an LD reloc. Start over | |
ad8e1ba5 | 7657 | in order to get h, sym, sec etc. right. */ |
951fd09b AM |
7658 | rel--; |
7659 | continue; | |
7660 | } | |
411e1bfb | 7661 | } |
411e1bfb | 7662 | } |
411e1bfb AM |
7663 | break; |
7664 | ||
7665 | case R_PPC64_DTPMOD64: | |
951fd09b AM |
7666 | if (rel + 1 < relend |
7667 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) | |
7668 | && rel[1].r_offset == rel->r_offset + 8) | |
411e1bfb | 7669 | { |
951fd09b AM |
7670 | if ((tls_mask & TLS_GD) == 0) |
7671 | { | |
7672 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); | |
7673 | if ((tls_mask & TLS_TPRELGD) != 0) | |
7674 | r_type = R_PPC64_TPREL64; | |
7675 | else | |
7676 | { | |
4ce794b7 | 7677 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
951fd09b AM |
7678 | r_type = R_PPC64_NONE; |
7679 | } | |
7680 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7681 | } | |
7682 | } | |
7683 | else | |
7684 | { | |
7685 | if ((tls_mask & TLS_LD) == 0) | |
411e1bfb | 7686 | { |
4ce794b7 | 7687 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
411e1bfb | 7688 | r_type = R_PPC64_NONE; |
951fd09b | 7689 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
411e1bfb | 7690 | } |
411e1bfb AM |
7691 | } |
7692 | break; | |
7693 | ||
7694 | case R_PPC64_TPREL64: | |
951fd09b | 7695 | if ((tls_mask & TLS_TPREL) == 0) |
411e1bfb AM |
7696 | { |
7697 | r_type = R_PPC64_NONE; | |
7698 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); | |
7699 | } | |
7700 | break; | |
7701 | } | |
7702 | ||
7703 | /* Handle other relocations that tweak non-addend part of insn. */ | |
86c76c7b | 7704 | insn = 0; |
65f38f15 | 7705 | switch (r_type) |
5bd4f169 AM |
7706 | { |
7707 | default: | |
65f38f15 | 7708 | break; |
5bd4f169 | 7709 | |
65f38f15 AM |
7710 | /* Branch taken prediction relocations. */ |
7711 | case R_PPC64_ADDR14_BRTAKEN: | |
7712 | case R_PPC64_REL14_BRTAKEN: | |
cedb70c5 KH |
7713 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
7714 | /* Fall thru. */ | |
65f38f15 | 7715 | |
86c76c7b | 7716 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
7717 | case R_PPC64_ADDR14_BRNTAKEN: |
7718 | case R_PPC64_REL14_BRNTAKEN: | |
411e1bfb AM |
7719 | insn |= bfd_get_32 (output_bfd, |
7720 | contents + rel->r_offset) & ~(0x01 << 21); | |
96e0dda4 AM |
7721 | if (is_power4) |
7722 | { | |
7723 | /* Set 'a' bit. This is 0b00010 in BO field for branch | |
7724 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 | |
7725 | for branch on CTR insns (BO == 1a00t or 1a01t). */ | |
7726 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
7727 | insn |= 0x02 << 21; | |
7728 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
7729 | insn |= 0x08 << 21; | |
7730 | else | |
7731 | break; | |
7732 | } | |
65f38f15 | 7733 | else |
96e0dda4 | 7734 | { |
411e1bfb | 7735 | from = (rel->r_offset |
805fc799 AM |
7736 | + input_section->output_offset |
7737 | + input_section->output_section->vma); | |
7738 | ||
96e0dda4 | 7739 | /* Invert 'y' bit if not the default. */ |
411e1bfb | 7740 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) |
96e0dda4 AM |
7741 | insn ^= 0x01 << 21; |
7742 | } | |
86c76c7b | 7743 | |
4ce794b7 | 7744 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
65f38f15 | 7745 | break; |
5bd4f169 | 7746 | |
65f38f15 | 7747 | case R_PPC64_REL24: |
ad8e1ba5 AM |
7748 | /* Calls to functions with a different TOC, such as calls to |
7749 | shared objects, need to alter the TOC pointer. This is | |
7750 | done using a linkage stub. A REL24 branching to these | |
7751 | linkage stubs needs to be followed by a nop, as the nop | |
7752 | will be replaced with an instruction to restore the TOC | |
7753 | base pointer. */ | |
7754 | if (((h != NULL | |
7755 | && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL | |
7756 | && fdh->plt.plist != NULL) | |
7757 | || ((fdh = h, sec) != NULL | |
7758 | && sec->output_section != NULL | |
7759 | && (htab->stub_group[sec->id].toc_off | |
7760 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 | 7761 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, |
ad8e1ba5 AM |
7762 | rel, htab)) != NULL |
7763 | && (stub_entry->stub_type == ppc_stub_plt_call | |
7764 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off | |
7765 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) | |
41bd81ab | 7766 | { |
b34976b6 | 7767 | bfd_boolean can_plt_call = 0; |
721956f4 | 7768 | |
411e1bfb | 7769 | if (rel->r_offset + 8 <= input_section->_cooked_size) |
41bd81ab | 7770 | { |
411e1bfb | 7771 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); |
721956f4 AM |
7772 | if (insn == NOP |
7773 | || insn == CROR_151515 || insn == CROR_313131) | |
41bd81ab | 7774 | { |
4ce794b7 | 7775 | bfd_put_32 (input_bfd, LD_R2_40R1, |
411e1bfb | 7776 | contents + rel->r_offset + 4); |
721956f4 | 7777 | can_plt_call = 1; |
41bd81ab | 7778 | } |
5bd4f169 | 7779 | } |
721956f4 AM |
7780 | |
7781 | if (!can_plt_call) | |
7782 | { | |
ad8e1ba5 AM |
7783 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7784 | { | |
7785 | /* If this is a plain branch rather than a branch | |
7786 | and link, don't require a nop. */ | |
7787 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
7788 | if ((insn & 1) == 0) | |
7789 | can_plt_call = 1; | |
7790 | } | |
6ab189d5 AM |
7791 | else if (h != NULL |
7792 | && strcmp (h->root.root.string, | |
7793 | ".__libc_start_main") == 0) | |
7794 | { | |
7795 | /* Allow crt1 branch to go via a toc adjusting stub. */ | |
7796 | can_plt_call = 1; | |
7797 | } | |
ad8e1ba5 AM |
7798 | else |
7799 | { | |
7800 | if (strcmp (input_section->output_section->name, | |
7801 | ".init") == 0 | |
7802 | || strcmp (input_section->output_section->name, | |
7803 | ".fini") == 0) | |
7804 | (*_bfd_error_handler) | |
7805 | (_("%s(%s+0x%lx): automatic multiple TOCs " | |
7806 | "not supported using your crt files; " | |
7807 | "recompile with -mminimal-toc or upgrade gcc"), | |
7808 | bfd_archive_filename (input_bfd), | |
7809 | input_section->name, | |
7810 | (long) rel->r_offset); | |
7811 | else | |
7812 | (*_bfd_error_handler) | |
7813 | (_("%s(%s+0x%lx): sibling call optimization to `%s' " | |
7814 | "does not allow automatic multiple TOCs; " | |
7815 | "recompile with -mminimal-toc or " | |
7816 | "-fno-optimize-sibling-calls, " | |
7817 | "or make `%s' extern"), | |
7818 | bfd_archive_filename (input_bfd), | |
7819 | input_section->name, | |
7820 | (long) rel->r_offset, | |
7821 | sym_name, | |
7822 | sym_name); | |
7823 | bfd_set_error (bfd_error_bad_value); | |
7824 | ret = FALSE; | |
7825 | } | |
721956f4 AM |
7826 | } |
7827 | ||
7828 | if (can_plt_call) | |
7829 | { | |
7830 | relocation = (stub_entry->stub_offset | |
7831 | + stub_entry->stub_sec->output_offset | |
7832 | + stub_entry->stub_sec->output_section->vma); | |
ad8e1ba5 AM |
7833 | if (stub_entry->stub_type == ppc_stub_plt_call) |
7834 | unresolved_reloc = FALSE; | |
721956f4 | 7835 | } |
5bd4f169 | 7836 | } |
e86ce104 AM |
7837 | |
7838 | if (h != NULL | |
7839 | && h->root.type == bfd_link_hash_undefweak | |
721956f4 | 7840 | && relocation == 0 |
411e1bfb | 7841 | && rel->r_addend == 0) |
e86ce104 | 7842 | { |
721956f4 AM |
7843 | /* Tweak calls to undefined weak functions to point at a |
7844 | blr. We can thus call a weak function without first | |
7845 | checking whether the function is defined. We have a | |
7846 | blr at the end of .sfpr. */ | |
805fc799 | 7847 | BFD_ASSERT (htab->sfpr->_raw_size != 0); |
721956f4 AM |
7848 | relocation = (htab->sfpr->_raw_size - 4 |
7849 | + htab->sfpr->output_offset | |
7850 | + htab->sfpr->output_section->vma); | |
411e1bfb | 7851 | from = (rel->r_offset |
721956f4 AM |
7852 | + input_section->output_offset |
7853 | + input_section->output_section->vma); | |
805fc799 | 7854 | |
721956f4 AM |
7855 | /* But let's not be silly about it. If the blr isn't in |
7856 | reach, just go to the next instruction. */ | |
805fc799 AM |
7857 | if (relocation - from + (1 << 25) >= (1 << 26) |
7858 | || htab->sfpr->_raw_size == 0) | |
721956f4 | 7859 | relocation = from + 4; |
e86ce104 | 7860 | } |
65f38f15 AM |
7861 | break; |
7862 | } | |
5bd4f169 | 7863 | |
65f38f15 | 7864 | /* Set `addend'. */ |
411e1bfb AM |
7865 | tls_type = 0; |
7866 | addend = rel->r_addend; | |
65f38f15 AM |
7867 | switch (r_type) |
7868 | { | |
7869 | default: | |
7870 | (*_bfd_error_handler) | |
7871 | (_("%s: unknown relocation type %d for symbol %s"), | |
7872 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); | |
5bd4f169 | 7873 | |
65f38f15 | 7874 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 7875 | ret = FALSE; |
65f38f15 | 7876 | continue; |
5bd4f169 | 7877 | |
65f38f15 | 7878 | case R_PPC64_NONE: |
411e1bfb | 7879 | case R_PPC64_TLS: |
04c9666a AM |
7880 | case R_PPC64_GNU_VTINHERIT: |
7881 | case R_PPC64_GNU_VTENTRY: | |
65f38f15 | 7882 | continue; |
5bd4f169 AM |
7883 | |
7884 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
7885 | address in the GOT as relocation value instead of the | |
411e1bfb | 7886 | symbol's value itself. Also, create a GOT entry for the |
5bd4f169 | 7887 | symbol and put the symbol value there. */ |
411e1bfb AM |
7888 | case R_PPC64_GOT_TLSGD16: |
7889 | case R_PPC64_GOT_TLSGD16_LO: | |
7890 | case R_PPC64_GOT_TLSGD16_HI: | |
7891 | case R_PPC64_GOT_TLSGD16_HA: | |
951fd09b | 7892 | tls_type = TLS_TLS | TLS_GD; |
411e1bfb AM |
7893 | goto dogot; |
7894 | ||
7895 | case R_PPC64_GOT_TLSLD16: | |
7896 | case R_PPC64_GOT_TLSLD16_LO: | |
7897 | case R_PPC64_GOT_TLSLD16_HI: | |
7898 | case R_PPC64_GOT_TLSLD16_HA: | |
951fd09b | 7899 | tls_type = TLS_TLS | TLS_LD; |
411e1bfb AM |
7900 | goto dogot; |
7901 | ||
7902 | case R_PPC64_GOT_TPREL16_DS: | |
7903 | case R_PPC64_GOT_TPREL16_LO_DS: | |
7904 | case R_PPC64_GOT_TPREL16_HI: | |
7905 | case R_PPC64_GOT_TPREL16_HA: | |
7906 | tls_type = TLS_TLS | TLS_TPREL; | |
7907 | goto dogot; | |
7908 | ||
7909 | case R_PPC64_GOT_DTPREL16_DS: | |
7910 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
7911 | case R_PPC64_GOT_DTPREL16_HI: | |
7912 | case R_PPC64_GOT_DTPREL16_HA: | |
7913 | tls_type = TLS_TLS | TLS_DTPREL; | |
7914 | goto dogot; | |
7915 | ||
65f38f15 AM |
7916 | case R_PPC64_GOT16: |
7917 | case R_PPC64_GOT16_LO: | |
7918 | case R_PPC64_GOT16_HI: | |
7919 | case R_PPC64_GOT16_HA: | |
7920 | case R_PPC64_GOT16_DS: | |
7921 | case R_PPC64_GOT16_LO_DS: | |
411e1bfb | 7922 | dogot: |
5bd4f169 AM |
7923 | { |
7924 | /* Relocation is to the entry for this symbol in the global | |
7925 | offset table. */ | |
e717da7e | 7926 | asection *got; |
d881513a | 7927 | bfd_vma *offp; |
5bd4f169 | 7928 | bfd_vma off; |
d881513a | 7929 | unsigned long indx = 0; |
65f38f15 | 7930 | |
d881513a AM |
7931 | if (tls_type == (TLS_TLS | TLS_LD) |
7932 | && (h == NULL | |
7933 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) | |
e717da7e | 7934 | offp = &ppc64_tlsld_got (input_bfd)->offset; |
411e1bfb | 7935 | else |
5bd4f169 | 7936 | { |
d881513a | 7937 | struct got_entry *ent; |
5bd4f169 | 7938 | |
d881513a AM |
7939 | if (h != NULL) |
7940 | { | |
7941 | bfd_boolean dyn = htab->elf.dynamic_sections_created; | |
f4656909 | 7942 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
d881513a | 7943 | || (info->shared |
586119b3 | 7944 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
d881513a AM |
7945 | /* This is actually a static link, or it is a |
7946 | -Bsymbolic link and the symbol is defined | |
7947 | locally, or the symbol was forced to be local | |
7948 | because of a version file. */ | |
7949 | ; | |
7950 | else | |
7951 | { | |
7952 | indx = h->dynindx; | |
7953 | unresolved_reloc = FALSE; | |
7954 | } | |
7955 | ent = h->got.glist; | |
7956 | } | |
411e1bfb | 7957 | else |
5bd4f169 | 7958 | { |
d881513a AM |
7959 | if (local_got_ents == NULL) |
7960 | abort (); | |
7961 | ent = local_got_ents[r_symndx]; | |
5bd4f169 | 7962 | } |
d881513a AM |
7963 | |
7964 | for (; ent != NULL; ent = ent->next) | |
7965 | if (ent->addend == rel->r_addend | |
e717da7e | 7966 | && ent->owner == input_bfd |
d881513a AM |
7967 | && ent->tls_type == tls_type) |
7968 | break; | |
7969 | if (ent == NULL) | |
7970 | abort (); | |
7971 | offp = &ent->got.offset; | |
5bd4f169 | 7972 | } |
411e1bfb | 7973 | |
e717da7e AM |
7974 | got = ppc64_elf_tdata (input_bfd)->got; |
7975 | if (got == NULL) | |
7976 | abort (); | |
7977 | ||
411e1bfb AM |
7978 | /* The offset must always be a multiple of 8. We use the |
7979 | least significant bit to record whether we have already | |
7980 | processed this entry. */ | |
d881513a | 7981 | off = *offp; |
411e1bfb AM |
7982 | if ((off & 1) != 0) |
7983 | off &= ~1; | |
5bd4f169 AM |
7984 | else |
7985 | { | |
411e1bfb AM |
7986 | /* Generate relocs for the dynamic linker, except in |
7987 | the case of TLSLD where we'll use one entry per | |
7988 | module. */ | |
e717da7e AM |
7989 | asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; |
7990 | ||
d881513a | 7991 | *offp = off | 1; |
4e795f50 AM |
7992 | if ((info->shared || indx != 0) |
7993 | && (h == NULL | |
7994 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
7995 | || h->root.type != bfd_link_hash_undefweak)) | |
5bd4f169 | 7996 | { |
e717da7e AM |
7997 | outrel.r_offset = (got->output_section->vma |
7998 | + got->output_offset | |
411e1bfb | 7999 | + off); |
81407a69 | 8000 | outrel.r_addend = rel->r_addend; |
d881513a | 8001 | if (tls_type & (TLS_LD | TLS_GD)) |
5bd4f169 | 8002 | { |
411e1bfb | 8003 | outrel.r_addend = 0; |
e515b051 | 8004 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
d881513a AM |
8005 | if (tls_type == (TLS_TLS | TLS_GD)) |
8006 | { | |
e717da7e AM |
8007 | loc = relgot->contents; |
8008 | loc += (relgot->reloc_count++ | |
d881513a AM |
8009 | * sizeof (Elf64_External_Rela)); |
8010 | bfd_elf64_swap_reloca_out (output_bfd, | |
8011 | &outrel, loc); | |
e515b051 | 8012 | outrel.r_offset += 8; |
81407a69 | 8013 | outrel.r_addend = rel->r_addend; |
d881513a AM |
8014 | outrel.r_info |
8015 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); | |
d881513a | 8016 | } |
411e1bfb | 8017 | } |
951fd09b | 8018 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
411e1bfb | 8019 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
951fd09b | 8020 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb AM |
8021 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
8022 | else if (indx == 0) | |
81407a69 AM |
8023 | { |
8024 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE); | |
8025 | ||
8026 | /* Write the .got section contents for the sake | |
8027 | of prelink. */ | |
e717da7e | 8028 | loc = got->contents + off; |
23fbd6fa JJ |
8029 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
8030 | loc); | |
81407a69 | 8031 | } |
411e1bfb AM |
8032 | else |
8033 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); | |
81407a69 AM |
8034 | |
8035 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) | |
e515b051 AM |
8036 | { |
8037 | outrel.r_addend += relocation; | |
8038 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
8039 | outrel.r_addend -= htab->tls_sec->vma; | |
8040 | } | |
e717da7e AM |
8041 | loc = relgot->contents; |
8042 | loc += (relgot->reloc_count++ | |
411e1bfb AM |
8043 | * sizeof (Elf64_External_Rela)); |
8044 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
8045 | } | |
8046 | ||
ad8e1ba5 | 8047 | /* Init the .got section contents here if we're not |
81407a69 | 8048 | emitting a reloc. */ |
d881513a | 8049 | else |
411e1bfb | 8050 | { |
d881513a | 8051 | relocation += rel->r_addend; |
7b609f53 AM |
8052 | if (tls_type == (TLS_TLS | TLS_LD)) |
8053 | relocation = 1; | |
8054 | else if (tls_type != 0) | |
411e1bfb AM |
8055 | { |
8056 | relocation -= htab->tls_sec->vma + DTP_OFFSET; | |
7b609f53 | 8057 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
411e1bfb | 8058 | relocation += DTP_OFFSET - TP_OFFSET; |
5bd4f169 | 8059 | |
7b609f53 AM |
8060 | if (tls_type == (TLS_TLS | TLS_GD)) |
8061 | { | |
8062 | bfd_put_64 (output_bfd, relocation, | |
e717da7e | 8063 | got->contents + off + 8); |
7b609f53 AM |
8064 | relocation = 1; |
8065 | } | |
411e1bfb | 8066 | } |
7b609f53 | 8067 | |
411e1bfb | 8068 | bfd_put_64 (output_bfd, relocation, |
e717da7e | 8069 | got->contents + off); |
5bd4f169 AM |
8070 | } |
8071 | } | |
8072 | ||
65f38f15 AM |
8073 | if (off >= (bfd_vma) -2) |
8074 | abort (); | |
8075 | ||
e717da7e | 8076 | relocation = got->output_offset + off; |
65f38f15 | 8077 | |
5bd4f169 | 8078 | /* TOC base (r2) is TOC start plus 0x8000. */ |
e717da7e | 8079 | addend = -TOC_BASE_OFF; |
5bd4f169 | 8080 | } |
65f38f15 AM |
8081 | break; |
8082 | ||
8083 | case R_PPC64_PLT16_HA: | |
8084 | case R_PPC64_PLT16_HI: | |
8085 | case R_PPC64_PLT16_LO: | |
8086 | case R_PPC64_PLT32: | |
8087 | case R_PPC64_PLT64: | |
8088 | /* Relocation is to the entry for this symbol in the | |
8089 | procedure linkage table. */ | |
8090 | ||
8091 | /* Resolve a PLT reloc against a local symbol directly, | |
8092 | without using the procedure linkage table. */ | |
8093 | if (h == NULL) | |
8094 | break; | |
8095 | ||
411e1bfb AM |
8096 | /* It's possible that we didn't make a PLT entry for this |
8097 | symbol. This happens when statically linking PIC code, | |
8098 | or when using -Bsymbolic. Go find a match if there is a | |
8099 | PLT entry. */ | |
4ce794b7 | 8100 | if (htab->plt != NULL) |
65f38f15 | 8101 | { |
411e1bfb AM |
8102 | struct plt_entry *ent; |
8103 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) | |
8104 | if (ent->addend == rel->r_addend | |
8105 | && ent->plt.offset != (bfd_vma) -1) | |
8106 | { | |
4ce794b7 AM |
8107 | relocation = (htab->plt->output_section->vma |
8108 | + htab->plt->output_offset | |
411e1bfb AM |
8109 | + ent->plt.offset); |
8110 | unresolved_reloc = FALSE; | |
8111 | } | |
65f38f15 | 8112 | } |
65f38f15 | 8113 | break; |
5bd4f169 | 8114 | |
0b13192e AM |
8115 | case R_PPC64_TOC: |
8116 | /* Relocation value is TOC base. */ | |
8117 | relocation = TOCstart; | |
8118 | if (r_symndx == 0) | |
8119 | relocation += htab->stub_group[input_section->id].toc_off; | |
8120 | else if (sec != NULL && !unresolved_reloc) | |
8121 | relocation += htab->stub_group[sec->id].toc_off; | |
8122 | else | |
8123 | unresolved_reloc = TRUE; | |
8124 | goto dodyn2; | |
8125 | ||
5bd4f169 AM |
8126 | /* TOC16 relocs. We want the offset relative to the TOC base, |
8127 | which is the address of the start of the TOC plus 0x8000. | |
8128 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
8129 | in this order. */ | |
65f38f15 AM |
8130 | case R_PPC64_TOC16: |
8131 | case R_PPC64_TOC16_LO: | |
8132 | case R_PPC64_TOC16_HI: | |
8133 | case R_PPC64_TOC16_DS: | |
8134 | case R_PPC64_TOC16_LO_DS: | |
8135 | case R_PPC64_TOC16_HA: | |
ad8e1ba5 | 8136 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
5bd4f169 AM |
8137 | break; |
8138 | ||
8139 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
8140 | case R_PPC64_SECTOFF: |
8141 | case R_PPC64_SECTOFF_LO: | |
8142 | case R_PPC64_SECTOFF_HI: | |
8143 | case R_PPC64_SECTOFF_DS: | |
8144 | case R_PPC64_SECTOFF_LO_DS: | |
8145 | case R_PPC64_SECTOFF_HA: | |
4ce794b7 | 8146 | if (sec != NULL) |
65f38f15 | 8147 | addend -= sec->output_section->vma; |
5bd4f169 AM |
8148 | break; |
8149 | ||
721956f4 AM |
8150 | case R_PPC64_REL14: |
8151 | case R_PPC64_REL14_BRNTAKEN: | |
8152 | case R_PPC64_REL14_BRTAKEN: | |
5d1634d7 AM |
8153 | case R_PPC64_REL24: |
8154 | break; | |
8155 | ||
411e1bfb AM |
8156 | case R_PPC64_TPREL16: |
8157 | case R_PPC64_TPREL16_LO: | |
8158 | case R_PPC64_TPREL16_HI: | |
8159 | case R_PPC64_TPREL16_HA: | |
8160 | case R_PPC64_TPREL16_DS: | |
8161 | case R_PPC64_TPREL16_LO_DS: | |
8162 | case R_PPC64_TPREL16_HIGHER: | |
8163 | case R_PPC64_TPREL16_HIGHERA: | |
8164 | case R_PPC64_TPREL16_HIGHEST: | |
8165 | case R_PPC64_TPREL16_HIGHESTA: | |
8166 | addend -= htab->tls_sec->vma + TP_OFFSET; | |
8167 | if (info->shared) | |
8168 | /* The TPREL16 relocs shouldn't really be used in shared | |
8169 | libs as they will result in DT_TEXTREL being set, but | |
8170 | support them anyway. */ | |
8171 | goto dodyn; | |
8172 | break; | |
8173 | ||
8174 | case R_PPC64_DTPREL16: | |
8175 | case R_PPC64_DTPREL16_LO: | |
8176 | case R_PPC64_DTPREL16_HI: | |
8177 | case R_PPC64_DTPREL16_HA: | |
8178 | case R_PPC64_DTPREL16_DS: | |
8179 | case R_PPC64_DTPREL16_LO_DS: | |
8180 | case R_PPC64_DTPREL16_HIGHER: | |
8181 | case R_PPC64_DTPREL16_HIGHERA: | |
8182 | case R_PPC64_DTPREL16_HIGHEST: | |
8183 | case R_PPC64_DTPREL16_HIGHESTA: | |
8184 | addend -= htab->tls_sec->vma + DTP_OFFSET; | |
8185 | break; | |
8186 | ||
e515b051 AM |
8187 | case R_PPC64_DTPMOD64: |
8188 | relocation = 1; | |
8189 | addend = 0; | |
8190 | goto dodyn; | |
8191 | ||
411e1bfb AM |
8192 | case R_PPC64_TPREL64: |
8193 | addend -= htab->tls_sec->vma + TP_OFFSET; | |
8194 | goto dodyn; | |
8195 | ||
8196 | case R_PPC64_DTPREL64: | |
8197 | addend -= htab->tls_sec->vma + DTP_OFFSET; | |
8198 | /* Fall thru */ | |
8199 | ||
65f38f15 AM |
8200 | /* Relocations that may need to be propagated if this is a |
8201 | dynamic object. */ | |
04c9666a | 8202 | case R_PPC64_REL30: |
65f38f15 AM |
8203 | case R_PPC64_REL32: |
8204 | case R_PPC64_REL64: | |
8205 | case R_PPC64_ADDR14: | |
8206 | case R_PPC64_ADDR14_BRNTAKEN: | |
8207 | case R_PPC64_ADDR14_BRTAKEN: | |
8208 | case R_PPC64_ADDR16: | |
8209 | case R_PPC64_ADDR16_DS: | |
8210 | case R_PPC64_ADDR16_HA: | |
8211 | case R_PPC64_ADDR16_HI: | |
8212 | case R_PPC64_ADDR16_HIGHER: | |
8213 | case R_PPC64_ADDR16_HIGHERA: | |
8214 | case R_PPC64_ADDR16_HIGHEST: | |
8215 | case R_PPC64_ADDR16_HIGHESTA: | |
8216 | case R_PPC64_ADDR16_LO: | |
8217 | case R_PPC64_ADDR16_LO_DS: | |
8218 | case R_PPC64_ADDR24: | |
65f38f15 AM |
8219 | case R_PPC64_ADDR32: |
8220 | case R_PPC64_ADDR64: | |
8221 | case R_PPC64_UADDR16: | |
8222 | case R_PPC64_UADDR32: | |
8223 | case R_PPC64_UADDR64: | |
ec338859 AM |
8224 | /* r_symndx will be zero only for relocs against symbols |
8225 | from removed linkonce sections, or sections discarded by | |
8226 | a linker script. */ | |
411e1bfb | 8227 | dodyn: |
5d1634d7 AM |
8228 | if (r_symndx == 0) |
8229 | break; | |
8230 | /* Fall thru. */ | |
8231 | ||
0b13192e | 8232 | dodyn2: |
5d1634d7 | 8233 | if ((input_section->flags & SEC_ALLOC) == 0) |
ec338859 AM |
8234 | break; |
8235 | ||
41bd81ab AM |
8236 | if (NO_OPD_RELOCS && is_opd) |
8237 | break; | |
8238 | ||
65f38f15 | 8239 | if ((info->shared |
4e795f50 AM |
8240 | && (h == NULL |
8241 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8242 | || h->root.type != bfd_link_hash_undefweak) | |
411e1bfb | 8243 | && (MUST_BE_DYN_RELOC (r_type) |
f6c52c13 | 8244 | || !SYMBOL_CALLS_LOCAL (info, h))) |
f4656909 AM |
8245 | || (ELIMINATE_COPY_RELOCS |
8246 | && !info->shared | |
65f38f15 AM |
8247 | && h != NULL |
8248 | && h->dynindx != -1 | |
8249 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
58ac9f71 AM |
8250 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
8251 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
65f38f15 AM |
8252 | { |
8253 | Elf_Internal_Rela outrel; | |
b34976b6 | 8254 | bfd_boolean skip, relocate; |
65f38f15 | 8255 | asection *sreloc; |
947216bf | 8256 | bfd_byte *loc; |
1cf1f670 | 8257 | bfd_vma out_off; |
65f38f15 AM |
8258 | |
8259 | /* When generating a dynamic object, these relocations | |
8260 | are copied into the output file to be resolved at run | |
8261 | time. */ | |
8262 | ||
b34976b6 AM |
8263 | skip = FALSE; |
8264 | relocate = FALSE; | |
65f38f15 | 8265 | |
1cf1f670 AM |
8266 | out_off = _bfd_elf_section_offset (output_bfd, info, |
8267 | input_section, rel->r_offset); | |
8268 | if (out_off == (bfd_vma) -1) | |
b34976b6 | 8269 | skip = TRUE; |
1cf1f670 | 8270 | else if (out_off == (bfd_vma) -2) |
b34976b6 | 8271 | skip = TRUE, relocate = TRUE; |
1cf1f670 AM |
8272 | out_off += (input_section->output_section->vma |
8273 | + input_section->output_offset); | |
8274 | outrel.r_offset = out_off; | |
411e1bfb | 8275 | outrel.r_addend = rel->r_addend; |
65f38f15 | 8276 | |
1cf1f670 AM |
8277 | /* Optimize unaligned reloc use. */ |
8278 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) | |
8279 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) | |
8280 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; | |
8281 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) | |
8282 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) | |
8283 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; | |
8284 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) | |
8285 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) | |
8286 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; | |
8287 | ||
65f38f15 | 8288 | if (skip) |
0bb2d96a | 8289 | memset (&outrel, 0, sizeof outrel); |
f6c52c13 | 8290 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
0b13192e AM |
8291 | && !is_opd |
8292 | && r_type != R_PPC64_TOC) | |
0bb2d96a | 8293 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
65f38f15 AM |
8294 | else |
8295 | { | |
41bd81ab AM |
8296 | /* This symbol is local, or marked to become local, |
8297 | or this is an opd section reloc which must point | |
8298 | at a local function. */ | |
65f38f15 | 8299 | outrel.r_addend += relocation; |
e86ce104 | 8300 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
65f38f15 | 8301 | { |
3fad3c7c | 8302 | if (is_opd && h != NULL) |
afbe61cf AM |
8303 | { |
8304 | /* Lie about opd entries. This case occurs | |
8305 | when building shared libraries and we | |
8306 | reference a function in another shared | |
3fad3c7c AM |
8307 | lib. The same thing happens for a weak |
8308 | definition in an application that's | |
8309 | overridden by a strong definition in a | |
8310 | shared lib. (I believe this is a generic | |
8311 | bug in binutils handling of weak syms.) | |
8312 | In these cases we won't use the opd | |
1e2f5b6e | 8313 | entry in this lib. */ |
b34976b6 | 8314 | unresolved_reloc = FALSE; |
afbe61cf | 8315 | } |
65f38f15 | 8316 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
81407a69 AM |
8317 | |
8318 | /* We need to relocate .opd contents for ld.so. | |
8319 | Prelink also wants simple and consistent rules | |
8320 | for relocs. This make all RELATIVE relocs have | |
8321 | *r_offset equal to r_addend. */ | |
8322 | relocate = TRUE; | |
65f38f15 AM |
8323 | } |
8324 | else | |
8325 | { | |
8326 | long indx = 0; | |
8327 | ||
41bd81ab | 8328 | if (bfd_is_abs_section (sec)) |
65f38f15 AM |
8329 | ; |
8330 | else if (sec == NULL || sec->owner == NULL) | |
8331 | { | |
8332 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 8333 | return FALSE; |
65f38f15 AM |
8334 | } |
8335 | else | |
8336 | { | |
8337 | asection *osec; | |
8338 | ||
8339 | osec = sec->output_section; | |
8340 | indx = elf_section_data (osec)->dynindx; | |
8341 | ||
8342 | /* We are turning this relocation into one | |
8343 | against a section symbol, so subtract out | |
8344 | the output section's address but not the | |
8345 | offset of the input section in the output | |
8346 | section. */ | |
8347 | outrel.r_addend -= osec->vma; | |
8348 | } | |
8349 | ||
8350 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
8351 | } | |
8352 | } | |
8353 | ||
8354 | sreloc = elf_section_data (input_section)->sreloc; | |
8355 | if (sreloc == NULL) | |
8356 | abort (); | |
8357 | ||
947216bf AM |
8358 | loc = sreloc->contents; |
8359 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 AM |
8360 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
8361 | ||
8362 | /* If this reloc is against an external symbol, it will | |
8363 | be computed at runtime, so there's no need to do | |
81407a69 AM |
8364 | anything now. However, for the sake of prelink ensure |
8365 | that the section contents are a known value. */ | |
65f38f15 | 8366 | if (! relocate) |
81407a69 AM |
8367 | { |
8368 | unresolved_reloc = FALSE; | |
8369 | /* The value chosen here is quite arbitrary as ld.so | |
8370 | ignores section contents except for the special | |
8371 | case of .opd where the contents might be accessed | |
8372 | before relocation. Choose zero, as that won't | |
8373 | cause reloc overflow. */ | |
8374 | relocation = 0; | |
8375 | addend = 0; | |
8376 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs | |
8377 | to improve backward compatibility with older | |
8378 | versions of ld. */ | |
8379 | if (r_type == R_PPC64_ADDR64) | |
8380 | addend = outrel.r_addend; | |
8381 | /* Adjust pc_relative relocs to have zero in *r_offset. */ | |
4ce794b7 | 8382 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
000732f7 AM |
8383 | addend = (input_section->output_section->vma |
8384 | + input_section->output_offset | |
8385 | + rel->r_offset); | |
81407a69 | 8386 | } |
65f38f15 | 8387 | } |
5bd4f169 AM |
8388 | break; |
8389 | ||
65f38f15 AM |
8390 | case R_PPC64_COPY: |
8391 | case R_PPC64_GLOB_DAT: | |
8392 | case R_PPC64_JMP_SLOT: | |
8393 | case R_PPC64_RELATIVE: | |
8394 | /* We shouldn't ever see these dynamic relocs in relocatable | |
8395 | files. */ | |
ae9a127f | 8396 | /* Fall through. */ |
65f38f15 AM |
8397 | |
8398 | case R_PPC64_PLTGOT16: | |
8399 | case R_PPC64_PLTGOT16_DS: | |
8400 | case R_PPC64_PLTGOT16_HA: | |
8401 | case R_PPC64_PLTGOT16_HI: | |
8402 | case R_PPC64_PLTGOT16_LO: | |
8403 | case R_PPC64_PLTGOT16_LO_DS: | |
8404 | case R_PPC64_PLTREL32: | |
8405 | case R_PPC64_PLTREL64: | |
8406 | /* These ones haven't been implemented yet. */ | |
8407 | ||
8408 | (*_bfd_error_handler) | |
7b609f53 | 8409 | (_("%s: relocation %s is not supported for symbol %s."), |
65f38f15 | 8410 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8411 | ppc64_elf_howto_table[r_type]->name, sym_name); |
5bd4f169 AM |
8412 | |
8413 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 8414 | ret = FALSE; |
5bd4f169 | 8415 | continue; |
65f38f15 | 8416 | } |
5bd4f169 | 8417 | |
65f38f15 AM |
8418 | /* Do any further special processing. */ |
8419 | switch (r_type) | |
8420 | { | |
8421 | default: | |
8422 | break; | |
8423 | ||
8424 | case R_PPC64_ADDR16_HA: | |
8425 | case R_PPC64_ADDR16_HIGHERA: | |
8426 | case R_PPC64_ADDR16_HIGHESTA: | |
86bbe32f AM |
8427 | case R_PPC64_GOT16_HA: |
8428 | case R_PPC64_PLTGOT16_HA: | |
65f38f15 AM |
8429 | case R_PPC64_PLT16_HA: |
8430 | case R_PPC64_TOC16_HA: | |
8431 | case R_PPC64_SECTOFF_HA: | |
411e1bfb AM |
8432 | case R_PPC64_TPREL16_HA: |
8433 | case R_PPC64_DTPREL16_HA: | |
8434 | case R_PPC64_GOT_TLSGD16_HA: | |
8435 | case R_PPC64_GOT_TLSLD16_HA: | |
8436 | case R_PPC64_GOT_TPREL16_HA: | |
8437 | case R_PPC64_GOT_DTPREL16_HA: | |
8438 | case R_PPC64_TPREL16_HIGHER: | |
8439 | case R_PPC64_TPREL16_HIGHERA: | |
8440 | case R_PPC64_TPREL16_HIGHEST: | |
8441 | case R_PPC64_TPREL16_HIGHESTA: | |
8442 | case R_PPC64_DTPREL16_HIGHER: | |
8443 | case R_PPC64_DTPREL16_HIGHERA: | |
8444 | case R_PPC64_DTPREL16_HIGHEST: | |
8445 | case R_PPC64_DTPREL16_HIGHESTA: | |
65f38f15 AM |
8446 | /* It's just possible that this symbol is a weak symbol |
8447 | that's not actually defined anywhere. In that case, | |
8448 | 'sec' would be NULL, and we should leave the symbol | |
8449 | alone (it will be set to zero elsewhere in the link). */ | |
8450 | if (sec != NULL) | |
e515b051 AM |
8451 | /* Add 0x10000 if sign bit in 0:15 is set. |
8452 | Bits 0:15 are not used. */ | |
8453 | addend += 0x8000; | |
65f38f15 AM |
8454 | break; |
8455 | ||
8456 | case R_PPC64_ADDR16_DS: | |
8457 | case R_PPC64_ADDR16_LO_DS: | |
8458 | case R_PPC64_GOT16_DS: | |
8459 | case R_PPC64_GOT16_LO_DS: | |
8460 | case R_PPC64_PLT16_LO_DS: | |
8461 | case R_PPC64_SECTOFF_DS: | |
8462 | case R_PPC64_SECTOFF_LO_DS: | |
8463 | case R_PPC64_TOC16_DS: | |
8464 | case R_PPC64_TOC16_LO_DS: | |
8465 | case R_PPC64_PLTGOT16_DS: | |
8466 | case R_PPC64_PLTGOT16_LO_DS: | |
411e1bfb AM |
8467 | case R_PPC64_GOT_TPREL16_DS: |
8468 | case R_PPC64_GOT_TPREL16_LO_DS: | |
8469 | case R_PPC64_GOT_DTPREL16_DS: | |
8470 | case R_PPC64_GOT_DTPREL16_LO_DS: | |
8471 | case R_PPC64_TPREL16_DS: | |
8472 | case R_PPC64_TPREL16_LO_DS: | |
8473 | case R_PPC64_DTPREL16_DS: | |
8474 | case R_PPC64_DTPREL16_LO_DS: | |
adadcc0c AM |
8475 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
8476 | mask = 3; | |
8477 | /* If this reloc is against an lq insn, then the value must be | |
8478 | a multiple of 16. This is somewhat of a hack, but the | |
8479 | "correct" way to do this by defining _DQ forms of all the | |
8480 | _DS relocs bloats all reloc switches in this file. It | |
8481 | doesn't seem to make much sense to use any of these relocs | |
8482 | in data, so testing the insn should be safe. */ | |
494dac0c | 8483 | if ((insn & (0x3f << 26)) == (56u << 26)) |
adadcc0c AM |
8484 | mask = 15; |
8485 | if (((relocation + addend) & mask) != 0) | |
65f38f15 AM |
8486 | { |
8487 | (*_bfd_error_handler) | |
adadcc0c | 8488 | (_("%s: error: relocation %s not a multiple of %d"), |
65f38f15 | 8489 | bfd_archive_filename (input_bfd), |
4ce794b7 | 8490 | ppc64_elf_howto_table[r_type]->name, |
adadcc0c | 8491 | mask + 1); |
65f38f15 | 8492 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 8493 | ret = FALSE; |
65f38f15 AM |
8494 | continue; |
8495 | } | |
8496 | break; | |
721956f4 AM |
8497 | |
8498 | case R_PPC64_REL14: | |
8499 | case R_PPC64_REL14_BRNTAKEN: | |
8500 | case R_PPC64_REL14_BRTAKEN: | |
8501 | max_br_offset = 1 << 15; | |
8502 | goto branch_check; | |
8503 | ||
8504 | case R_PPC64_REL24: | |
8505 | max_br_offset = 1 << 25; | |
8506 | ||
8507 | branch_check: | |
ad8e1ba5 AM |
8508 | /* If the branch is out of reach or the TOC register needs |
8509 | adjusting, then redirect the call to the local stub for | |
8510 | this function. */ | |
411e1bfb | 8511 | from = (rel->r_offset |
721956f4 AM |
8512 | + input_section->output_offset |
8513 | + input_section->output_section->vma); | |
ad8e1ba5 AM |
8514 | if ((relocation + addend - from + max_br_offset >= 2 * max_br_offset |
8515 | || (sec != NULL | |
8516 | && sec->output_section != NULL | |
8f3bab57 | 8517 | && sec->id <= htab->top_id |
ad8e1ba5 AM |
8518 | && (htab->stub_group[sec->id].toc_off |
8519 | != htab->stub_group[input_section->id].toc_off))) | |
721956f4 AM |
8520 | && (stub_entry = ppc_get_stub_entry (input_section, sec, h, |
8521 | rel, htab)) != NULL) | |
8522 | { | |
8523 | /* Munge up the value and addend so that we call the stub | |
8524 | rather than the procedure directly. */ | |
8525 | relocation = (stub_entry->stub_offset | |
8526 | + stub_entry->stub_sec->output_offset | |
8527 | + stub_entry->stub_sec->output_section->vma); | |
8528 | addend = 0; | |
8529 | } | |
8530 | break; | |
5bd4f169 AM |
8531 | } |
8532 | ||
239e1f3a AM |
8533 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
8534 | because such sections are not SEC_ALLOC and thus ld.so will | |
8535 | not process them. */ | |
65f38f15 | 8536 | if (unresolved_reloc |
239e1f3a | 8537 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
65f38f15 | 8538 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
9c07fe7c AM |
8539 | { |
8540 | (*_bfd_error_handler) | |
7b609f53 | 8541 | (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), |
9c07fe7c AM |
8542 | bfd_archive_filename (input_bfd), |
8543 | bfd_get_section_name (input_bfd, input_section), | |
8544 | (long) rel->r_offset, | |
7b609f53 | 8545 | ppc64_elf_howto_table[(int) r_type]->name, |
9c07fe7c | 8546 | h->root.root.string); |
b34976b6 | 8547 | ret = FALSE; |
9c07fe7c | 8548 | } |
5bd4f169 | 8549 | |
65f38f15 | 8550 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
8551 | input_bfd, |
8552 | input_section, | |
8553 | contents, | |
411e1bfb | 8554 | rel->r_offset, |
5bd4f169 AM |
8555 | relocation, |
8556 | addend); | |
8557 | ||
ef60b7ff | 8558 | if (r != bfd_reloc_ok) |
5bd4f169 | 8559 | { |
cd27b276 AM |
8560 | if (sym_name == NULL) |
8561 | sym_name = "(null)"; | |
8562 | if (r == bfd_reloc_overflow) | |
5bd4f169 | 8563 | { |
cd27b276 AM |
8564 | if (warned) |
8565 | continue; | |
8566 | if (h != NULL | |
8567 | && h->root.type == bfd_link_hash_undefweak | |
4ce794b7 | 8568 | && ppc64_elf_howto_table[r_type]->pc_relative) |
5bd4f169 AM |
8569 | { |
8570 | /* Assume this is a call protected by other code that | |
8571 | detects the symbol is undefined. If this is the case, | |
8572 | we can safely ignore the overflow. If not, the | |
8573 | program is hosed anyway, and a little warning isn't | |
8574 | going to help. */ | |
8575 | ||
8576 | continue; | |
8577 | } | |
8578 | ||
ef60b7ff | 8579 | if (!((*info->callbacks->reloc_overflow) |
4ce794b7 | 8580 | (info, sym_name, ppc64_elf_howto_table[r_type]->name, |
411e1bfb | 8581 | rel->r_addend, input_bfd, input_section, rel->r_offset))) |
b34976b6 | 8582 | return FALSE; |
ef60b7ff AM |
8583 | } |
8584 | else | |
8585 | { | |
8586 | (*_bfd_error_handler) | |
7b609f53 | 8587 | (_("%s(%s+0x%lx): %s reloc against `%s': error %d"), |
ef60b7ff AM |
8588 | bfd_archive_filename (input_bfd), |
8589 | bfd_get_section_name (input_bfd, input_section), | |
7b609f53 | 8590 | (long) rel->r_offset, |
4ce794b7 | 8591 | ppc64_elf_howto_table[r_type]->name, |
7b609f53 AM |
8592 | sym_name, |
8593 | (int) r); | |
b34976b6 | 8594 | ret = FALSE; |
ef60b7ff | 8595 | } |
5bd4f169 | 8596 | } |
5bd4f169 AM |
8597 | } |
8598 | ||
5bd4f169 AM |
8599 | return ret; |
8600 | } | |
8601 | ||
8602 | /* Finish up dynamic symbol handling. We set the contents of various | |
8603 | dynamic sections here. */ | |
8604 | ||
b34976b6 | 8605 | static bfd_boolean |
4ce794b7 AM |
8606 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
8607 | struct bfd_link_info *info, | |
8608 | struct elf_link_hash_entry *h, | |
8609 | Elf_Internal_Sym *sym) | |
5bd4f169 | 8610 | { |
65f38f15 | 8611 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
8612 | bfd *dynobj; |
8613 | ||
65f38f15 AM |
8614 | htab = ppc_hash_table (info); |
8615 | dynobj = htab->elf.dynobj; | |
5bd4f169 | 8616 | |
411e1bfb | 8617 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
5bd4f169 | 8618 | { |
411e1bfb | 8619 | struct plt_entry *ent; |
65f38f15 | 8620 | Elf_Internal_Rela rela; |
947216bf | 8621 | bfd_byte *loc; |
5bd4f169 | 8622 | |
411e1bfb AM |
8623 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
8624 | if (ent->plt.offset != (bfd_vma) -1) | |
8625 | { | |
8626 | /* This symbol has an entry in the procedure linkage | |
8627 | table. Set it up. */ | |
5bd4f169 | 8628 | |
4ce794b7 AM |
8629 | if (htab->plt == NULL |
8630 | || htab->relplt == NULL | |
8631 | || htab->glink == NULL) | |
411e1bfb | 8632 | abort (); |
5bd4f169 | 8633 | |
411e1bfb AM |
8634 | /* Create a JMP_SLOT reloc to inform the dynamic linker to |
8635 | fill in the PLT entry. */ | |
4ce794b7 AM |
8636 | rela.r_offset = (htab->plt->output_section->vma |
8637 | + htab->plt->output_offset | |
411e1bfb AM |
8638 | + ent->plt.offset); |
8639 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); | |
8640 | rela.r_addend = ent->addend; | |
5bd4f169 | 8641 | |
4ce794b7 | 8642 | loc = htab->relplt->contents; |
411e1bfb AM |
8643 | loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE |
8644 | * sizeof (Elf64_External_Rela)); | |
8645 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
8646 | } | |
5bd4f169 AM |
8647 | } |
8648 | ||
8649 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
8650 | { | |
5bd4f169 | 8651 | Elf_Internal_Rela rela; |
947216bf | 8652 | bfd_byte *loc; |
5bd4f169 | 8653 | |
65f38f15 | 8654 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 8655 | |
65f38f15 AM |
8656 | if (h->dynindx == -1 |
8657 | || (h->root.type != bfd_link_hash_defined | |
8658 | && h->root.type != bfd_link_hash_defweak) | |
4ce794b7 | 8659 | || htab->relbss == NULL) |
65f38f15 | 8660 | abort (); |
5bd4f169 AM |
8661 | |
8662 | rela.r_offset = (h->root.u.def.value | |
8663 | + h->root.u.def.section->output_section->vma | |
8664 | + h->root.u.def.section->output_offset); | |
8665 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
8666 | rela.r_addend = 0; | |
4ce794b7 AM |
8667 | loc = htab->relbss->contents; |
8668 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
65f38f15 | 8669 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
5bd4f169 AM |
8670 | } |
8671 | ||
5bd4f169 AM |
8672 | /* Mark some specially defined symbols as absolute. */ |
8673 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
8674 | sym->st_shndx = SHN_ABS; | |
8675 | ||
b34976b6 | 8676 | return TRUE; |
5bd4f169 AM |
8677 | } |
8678 | ||
65f38f15 AM |
8679 | /* Used to decide how to sort relocs in an optimal manner for the |
8680 | dynamic linker, before writing them out. */ | |
8681 | ||
8682 | static enum elf_reloc_type_class | |
4ce794b7 | 8683 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
65f38f15 | 8684 | { |
04c9666a | 8685 | enum elf_ppc64_reloc_type r_type; |
a33d1f77 | 8686 | |
4ce794b7 | 8687 | r_type = ELF64_R_TYPE (rela->r_info); |
a33d1f77 | 8688 | switch (r_type) |
65f38f15 AM |
8689 | { |
8690 | case R_PPC64_RELATIVE: | |
8691 | return reloc_class_relative; | |
8692 | case R_PPC64_JMP_SLOT: | |
8693 | return reloc_class_plt; | |
8694 | case R_PPC64_COPY: | |
8695 | return reloc_class_copy; | |
8696 | default: | |
8697 | return reloc_class_normal; | |
8698 | } | |
8699 | } | |
8700 | ||
5bd4f169 AM |
8701 | /* Finish up the dynamic sections. */ |
8702 | ||
b34976b6 | 8703 | static bfd_boolean |
4ce794b7 AM |
8704 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
8705 | struct bfd_link_info *info) | |
5bd4f169 | 8706 | { |
65f38f15 AM |
8707 | struct ppc_link_hash_table *htab; |
8708 | bfd *dynobj; | |
5bd4f169 | 8709 | asection *sdyn; |
5bd4f169 | 8710 | |
65f38f15 AM |
8711 | htab = ppc_hash_table (info); |
8712 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
8713 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
8714 | ||
65f38f15 | 8715 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 8716 | { |
5bd4f169 AM |
8717 | Elf64_External_Dyn *dyncon, *dynconend; |
8718 | ||
4ce794b7 | 8719 | if (sdyn == NULL || htab->got == NULL) |
65f38f15 | 8720 | abort (); |
5bd4f169 AM |
8721 | |
8722 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
8723 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
8724 | for (; dyncon < dynconend; dyncon++) | |
8725 | { | |
8726 | Elf_Internal_Dyn dyn; | |
19397422 | 8727 | asection *s; |
5bd4f169 AM |
8728 | |
8729 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
8730 | ||
8731 | switch (dyn.d_tag) | |
8732 | { | |
65f38f15 AM |
8733 | default: |
8734 | continue; | |
5bd4f169 | 8735 | |
5d1634d7 | 8736 | case DT_PPC64_GLINK: |
4ce794b7 | 8737 | s = htab->glink; |
6348e046 | 8738 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
ad8e1ba5 AM |
8739 | /* We stupidly defined DT_PPC64_GLINK to be the start |
8740 | of glink rather than the first entry point, which is | |
8741 | what ld.so needs, and now have a bigger stub to | |
8742 | support automatic multiple TOCs. */ | |
8743 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; | |
5d1634d7 AM |
8744 | break; |
8745 | ||
19397422 AM |
8746 | case DT_PPC64_OPD: |
8747 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8748 | if (s == NULL) |
8749 | continue; | |
8750 | dyn.d_un.d_ptr = s->vma; | |
19397422 AM |
8751 | break; |
8752 | ||
8753 | case DT_PPC64_OPDSZ: | |
8754 | s = bfd_get_section_by_name (output_bfd, ".opd"); | |
6348e046 AM |
8755 | if (s == NULL) |
8756 | continue; | |
8757 | dyn.d_un.d_val = s->_raw_size; | |
19397422 AM |
8758 | break; |
8759 | ||
65f38f15 | 8760 | case DT_PLTGOT: |
4ce794b7 | 8761 | s = htab->plt; |
6348e046 | 8762 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 AM |
8763 | break; |
8764 | ||
8765 | case DT_JMPREL: | |
4ce794b7 | 8766 | s = htab->relplt; |
6348e046 | 8767 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
65f38f15 | 8768 | break; |
5bd4f169 | 8769 | |
65f38f15 | 8770 | case DT_PLTRELSZ: |
4ce794b7 | 8771 | dyn.d_un.d_val = htab->relplt->_raw_size; |
5d1634d7 AM |
8772 | break; |
8773 | ||
8774 | case DT_RELASZ: | |
8775 | /* Don't count procedure linkage table relocs in the | |
8776 | overall reloc count. */ | |
4ce794b7 | 8777 | s = htab->relplt; |
6348e046 AM |
8778 | if (s == NULL) |
8779 | continue; | |
8780 | dyn.d_un.d_val -= s->_raw_size; | |
8781 | break; | |
8782 | ||
8783 | case DT_RELA: | |
8784 | /* We may not be using the standard ELF linker script. | |
8785 | If .rela.plt is the first .rela section, we adjust | |
8786 | DT_RELA to not include it. */ | |
4ce794b7 | 8787 | s = htab->relplt; |
6348e046 AM |
8788 | if (s == NULL) |
8789 | continue; | |
8790 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) | |
8791 | continue; | |
8792 | dyn.d_un.d_ptr += s->_raw_size; | |
65f38f15 | 8793 | break; |
5bd4f169 | 8794 | } |
5bd4f169 | 8795 | |
65f38f15 | 8796 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 8797 | } |
5bd4f169 AM |
8798 | } |
8799 | ||
4ce794b7 | 8800 | if (htab->got != NULL && htab->got->_raw_size != 0) |
5d1634d7 AM |
8801 | { |
8802 | /* Fill in the first entry in the global offset table. | |
8803 | We use it to hold the link-time TOCbase. */ | |
8804 | bfd_put_64 (output_bfd, | |
60ee0d4a | 8805 | elf_gp (output_bfd) + TOC_BASE_OFF, |
4ce794b7 | 8806 | htab->got->contents); |
5d1634d7 AM |
8807 | |
8808 | /* Set .got entry size. */ | |
4ce794b7 | 8809 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
5d1634d7 AM |
8810 | } |
8811 | ||
4ce794b7 | 8812 | if (htab->plt != NULL && htab->plt->_raw_size != 0) |
5d1634d7 AM |
8813 | { |
8814 | /* Set .plt entry size. */ | |
4ce794b7 | 8815 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
5d1634d7 AM |
8816 | = PLT_ENTRY_SIZE; |
8817 | } | |
8818 | ||
e717da7e AM |
8819 | /* We need to handle writing out multiple GOT sections ourselves, |
8820 | since we didn't add them to DYNOBJ. */ | |
8821 | while ((dynobj = dynobj->link_next) != NULL) | |
8822 | { | |
8823 | asection *s; | |
8824 | s = ppc64_elf_tdata (dynobj)->got; | |
8825 | if (s != NULL | |
8826 | && s->_raw_size != 0 | |
8827 | && s->output_section != bfd_abs_section_ptr | |
8828 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8829 | s->contents, s->output_offset, | |
8830 | s->_raw_size)) | |
8831 | return FALSE; | |
8832 | s = ppc64_elf_tdata (dynobj)->relgot; | |
8833 | if (s != NULL | |
8834 | && s->_raw_size != 0 | |
8835 | && s->output_section != bfd_abs_section_ptr | |
8836 | && !bfd_set_section_contents (output_bfd, s->output_section, | |
8837 | s->contents, s->output_offset, | |
8838 | s->_raw_size)) | |
8839 | return FALSE; | |
8840 | } | |
f6c52c13 | 8841 | |
b34976b6 | 8842 | return TRUE; |
5bd4f169 AM |
8843 | } |
8844 | ||
5bd4f169 | 8845 | #include "elf64-target.h" |