]>
Commit | Line | Data |
---|---|---|
a85d7ed0 | 1 | /* IBM S/390-specific support for 64-bit ELF |
7898deda | 2 | Copyright 2000, 2001 Free Software Foundation, Inc. |
a85d7ed0 NC |
3 | Contributed Martin Schwidefsky ([email protected]). |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
24 | #include "bfdlink.h" | |
25 | #include "libbfd.h" | |
26 | #include "elf-bfd.h" | |
27 | ||
28 | static reloc_howto_type *elf_s390_reloc_type_lookup | |
29 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
30 | static void elf_s390_info_to_howto | |
31 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); | |
0451c93c MS |
32 | static boolean elf_s390_is_local_label_name |
33 | PARAMS ((bfd *, const char *)); | |
34 | static struct bfd_hash_entry *link_hash_newfunc | |
a85d7ed0 NC |
35 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); |
36 | static struct bfd_link_hash_table *elf_s390_link_hash_table_create | |
37 | PARAMS ((bfd *)); | |
0451c93c MS |
38 | static boolean create_got_section |
39 | PARAMS((bfd *, struct bfd_link_info *)); | |
40 | static boolean elf_s390_create_dynamic_sections | |
41 | PARAMS((bfd *, struct bfd_link_info *)); | |
42 | static void elf_s390_copy_indirect_symbol | |
43 | PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *)); | |
a85d7ed0 NC |
44 | static boolean elf_s390_check_relocs |
45 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
46 | const Elf_Internal_Rela *)); | |
99c79b2e AJ |
47 | static asection *elf_s390_gc_mark_hook |
48 | PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, | |
49 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | |
50 | static boolean elf_s390_gc_sweep_hook | |
51 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
52 | const Elf_Internal_Rela *)); | |
a85d7ed0 NC |
53 | static boolean elf_s390_adjust_dynamic_symbol |
54 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
0451c93c MS |
55 | static boolean allocate_dynrelocs |
56 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
57 | static boolean readonly_dynrelocs | |
58 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
a85d7ed0 NC |
59 | static boolean elf_s390_size_dynamic_sections |
60 | PARAMS ((bfd *, struct bfd_link_info *)); | |
61 | static boolean elf_s390_relocate_section | |
62 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
63 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
64 | static boolean elf_s390_finish_dynamic_symbol | |
65 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
66 | Elf_Internal_Sym *)); | |
0451c93c MS |
67 | static enum elf_reloc_type_class elf_s390_reloc_type_class |
68 | PARAMS ((const Elf_Internal_Rela *)); | |
a85d7ed0 NC |
69 | static boolean elf_s390_finish_dynamic_sections |
70 | PARAMS ((bfd *, struct bfd_link_info *)); | |
99c79b2e | 71 | static boolean elf_s390_object_p PARAMS ((bfd *)); |
a85d7ed0 NC |
72 | |
73 | #define USE_RELA 1 /* We want RELA relocations, not REL. */ | |
74 | ||
75 | #include "elf/s390.h" | |
76 | ||
77 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value | |
78 | from smaller values. Start with zero, widen, *then* decrement. */ | |
79 | #define MINUS_ONE (((bfd_vma)0) - 1) | |
80 | ||
81 | /* The relocation "howto" table. */ | |
82 | static reloc_howto_type elf_howto_table[] = | |
83 | { | |
84 | HOWTO (R_390_NONE, /* type */ | |
85 | 0, /* rightshift */ | |
86 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
87 | 0, /* bitsize */ | |
88 | false, /* pc_relative */ | |
89 | 0, /* bitpos */ | |
90 | complain_overflow_dont, /* complain_on_overflow */ | |
91 | bfd_elf_generic_reloc, /* special_function */ | |
92 | "R_390_NONE", /* name */ | |
93 | false, /* partial_inplace */ | |
94 | 0, /* src_mask */ | |
95 | 0, /* dst_mask */ | |
96 | false), /* pcrel_offset */ | |
97 | ||
98 | HOWTO(R_390_8, 0, 0, 8, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_8", false, 0,0x000000ff, false), | |
99 | HOWTO(R_390_12, 0, 1, 12, false, 0, complain_overflow_dont, bfd_elf_generic_reloc, "R_390_12", false, 0,0x00000fff, false), | |
100 | HOWTO(R_390_16, 0, 1, 16, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_16", false, 0,0x0000ffff, false), | |
101 | HOWTO(R_390_32, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_32", false, 0,0xffffffff, false), | |
102 | HOWTO(R_390_PC32, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC32", false, 0,0xffffffff, true), | |
103 | HOWTO(R_390_GOT12, 0, 1, 12, false, 0, complain_overflow_dont, bfd_elf_generic_reloc, "R_390_GOT12", false, 0,0x00000fff, false), | |
104 | HOWTO(R_390_GOT32, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOT32", false, 0,0xffffffff, false), | |
105 | HOWTO(R_390_PLT32, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT32", false, 0,0xffffffff, true), | |
106 | HOWTO(R_390_COPY, 0, 4, 64, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_COPY", false, 0,MINUS_ONE, false), | |
107 | HOWTO(R_390_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GLOB_DAT",false, 0,MINUS_ONE, false), | |
108 | HOWTO(R_390_JMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_JMP_SLOT",false, 0,MINUS_ONE, false), | |
109 | HOWTO(R_390_RELATIVE, 0, 4, 64, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_RELATIVE",false, 0,MINUS_ONE, false), | |
110 | HOWTO(R_390_GOTOFF, 0, 4, 64, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTOFF", false, 0,MINUS_ONE, false), | |
111 | HOWTO(R_390_GOTPC, 0, 4, 64, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTPC", false, 0,MINUS_ONE, true), | |
112 | HOWTO(R_390_GOT16, 0, 1, 16, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOT16", false, 0,0x0000ffff, false), | |
113 | HOWTO(R_390_PC16, 0, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC16", false, 0,0x0000ffff, true), | |
114 | HOWTO(R_390_PC16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC16DBL", false, 0,0x0000ffff, true), | |
115 | HOWTO(R_390_PLT16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT16DBL", false, 0,0x0000ffff, true), | |
116 | HOWTO(R_390_PC32DBL, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC32DBL", false, 0,0xffffffff, true), | |
117 | HOWTO(R_390_PLT32DBL, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT32DBL", false, 0,0xffffffff, true), | |
118 | HOWTO(R_390_GOTPCDBL, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTPCDBL", false, 0,MINUS_ONE, true), | |
119 | HOWTO(R_390_64, 0, 4, 64, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_64", false, 0,MINUS_ONE, false), | |
120 | HOWTO(R_390_PC64, 0, 4, 64, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC64", false, 0,MINUS_ONE, true), | |
121 | HOWTO(R_390_GOT64, 0, 4, 64, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOT64", false, 0,MINUS_ONE, false), | |
122 | HOWTO(R_390_PLT64, 0, 4, 64, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT64", false, 0,MINUS_ONE, true), | |
123 | HOWTO(R_390_GOTENT, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTENT", false, 0,MINUS_ONE, true), | |
124 | }; | |
125 | ||
126 | /* GNU extension to record C++ vtable hierarchy. */ | |
127 | static reloc_howto_type elf64_s390_vtinherit_howto = | |
128 | HOWTO (R_390_GNU_VTINHERIT, 0,4,0,false,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", false,0, 0, false); | |
129 | static reloc_howto_type elf64_s390_vtentry_howto = | |
99c79b2e | 130 | HOWTO (R_390_GNU_VTENTRY, 0,4,0,false,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", false,0,0, false); |
a85d7ed0 NC |
131 | |
132 | static reloc_howto_type * | |
133 | elf_s390_reloc_type_lookup (abfd, code) | |
134 | bfd *abfd ATTRIBUTE_UNUSED; | |
135 | bfd_reloc_code_real_type code; | |
136 | { | |
0451c93c MS |
137 | switch (code) |
138 | { | |
139 | case BFD_RELOC_NONE: | |
140 | return &elf_howto_table[(int) R_390_NONE]; | |
141 | case BFD_RELOC_8: | |
142 | return &elf_howto_table[(int) R_390_8]; | |
143 | case BFD_RELOC_390_12: | |
144 | return &elf_howto_table[(int) R_390_12]; | |
145 | case BFD_RELOC_16: | |
146 | return &elf_howto_table[(int) R_390_16]; | |
147 | case BFD_RELOC_32: | |
148 | return &elf_howto_table[(int) R_390_32]; | |
149 | case BFD_RELOC_CTOR: | |
150 | return &elf_howto_table[(int) R_390_32]; | |
151 | case BFD_RELOC_32_PCREL: | |
152 | return &elf_howto_table[(int) R_390_PC32]; | |
153 | case BFD_RELOC_390_GOT12: | |
154 | return &elf_howto_table[(int) R_390_GOT12]; | |
155 | case BFD_RELOC_32_GOT_PCREL: | |
156 | return &elf_howto_table[(int) R_390_GOT32]; | |
157 | case BFD_RELOC_390_PLT32: | |
158 | return &elf_howto_table[(int) R_390_PLT32]; | |
159 | case BFD_RELOC_390_COPY: | |
160 | return &elf_howto_table[(int) R_390_COPY]; | |
161 | case BFD_RELOC_390_GLOB_DAT: | |
162 | return &elf_howto_table[(int) R_390_GLOB_DAT]; | |
163 | case BFD_RELOC_390_JMP_SLOT: | |
164 | return &elf_howto_table[(int) R_390_JMP_SLOT]; | |
165 | case BFD_RELOC_390_RELATIVE: | |
166 | return &elf_howto_table[(int) R_390_RELATIVE]; | |
167 | case BFD_RELOC_32_GOTOFF: | |
168 | return &elf_howto_table[(int) R_390_GOTOFF]; | |
169 | case BFD_RELOC_390_GOTPC: | |
170 | return &elf_howto_table[(int) R_390_GOTPC]; | |
171 | case BFD_RELOC_390_GOT16: | |
172 | return &elf_howto_table[(int) R_390_GOT16]; | |
173 | case BFD_RELOC_16_PCREL: | |
174 | return &elf_howto_table[(int) R_390_PC16]; | |
175 | case BFD_RELOC_390_PC16DBL: | |
176 | return &elf_howto_table[(int) R_390_PC16DBL]; | |
177 | case BFD_RELOC_390_PLT16DBL: | |
178 | return &elf_howto_table[(int) R_390_PLT16DBL]; | |
179 | case BFD_RELOC_VTABLE_INHERIT: | |
180 | return &elf64_s390_vtinherit_howto; | |
181 | case BFD_RELOC_VTABLE_ENTRY: | |
182 | return &elf64_s390_vtentry_howto; | |
183 | case BFD_RELOC_390_PC32DBL: | |
184 | return &elf_howto_table[(int) R_390_PC32DBL]; | |
185 | case BFD_RELOC_390_PLT32DBL: | |
186 | return &elf_howto_table[(int) R_390_PLT32DBL]; | |
187 | case BFD_RELOC_390_GOTPCDBL: | |
188 | return &elf_howto_table[(int) R_390_GOTPCDBL]; | |
189 | case BFD_RELOC_64: | |
190 | return &elf_howto_table[(int) R_390_64]; | |
191 | case BFD_RELOC_64_PCREL: | |
192 | return &elf_howto_table[(int) R_390_PC64]; | |
193 | case BFD_RELOC_390_GOT64: | |
194 | return &elf_howto_table[(int) R_390_GOT64]; | |
195 | case BFD_RELOC_390_PLT64: | |
196 | return &elf_howto_table[(int) R_390_PLT64]; | |
197 | case BFD_RELOC_390_GOTENT: | |
198 | return &elf_howto_table[(int) R_390_GOTENT]; | |
199 | default: | |
200 | break; | |
201 | } | |
a85d7ed0 NC |
202 | return 0; |
203 | } | |
204 | ||
205 | /* We need to use ELF64_R_TYPE so we have our own copy of this function, | |
206 | and elf64-s390.c has its own copy. */ | |
207 | ||
208 | static void | |
209 | elf_s390_info_to_howto (abfd, cache_ptr, dst) | |
210 | bfd *abfd ATTRIBUTE_UNUSED; | |
211 | arelent *cache_ptr; | |
212 | Elf_Internal_Rela *dst; | |
213 | { | |
214 | switch (ELF64_R_TYPE(dst->r_info)) | |
215 | { | |
216 | case R_390_GNU_VTINHERIT: | |
217 | cache_ptr->howto = &elf64_s390_vtinherit_howto; | |
218 | break; | |
219 | ||
220 | case R_390_GNU_VTENTRY: | |
221 | cache_ptr->howto = &elf64_s390_vtentry_howto; | |
222 | break; | |
223 | ||
224 | default: | |
225 | BFD_ASSERT (ELF64_R_TYPE(dst->r_info) < (unsigned int) R_390_max); | |
226 | cache_ptr->howto = &elf_howto_table[ELF64_R_TYPE(dst->r_info)]; | |
99c79b2e | 227 | } |
a85d7ed0 NC |
228 | } |
229 | ||
230 | static boolean | |
231 | elf_s390_is_local_label_name (abfd, name) | |
232 | bfd *abfd; | |
233 | const char *name; | |
234 | { | |
235 | if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L')) | |
236 | return true; | |
237 | ||
238 | return _bfd_elf_is_local_label_name (abfd, name); | |
239 | } | |
240 | ||
241 | /* Functions for the 390 ELF linker. */ | |
242 | ||
243 | /* The name of the dynamic interpreter. This is put in the .interp | |
244 | section. */ | |
245 | ||
246 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
247 | ||
a85d7ed0 NC |
248 | /* The size in bytes of the first entry in the procedure linkage table. */ |
249 | #define PLT_FIRST_ENTRY_SIZE 32 | |
250 | /* The size in bytes of an entry in the procedure linkage table. */ | |
99c79b2e | 251 | #define PLT_ENTRY_SIZE 32 |
a85d7ed0 NC |
252 | |
253 | #define GOT_ENTRY_SIZE 8 | |
254 | ||
255 | /* The first three entries in a procedure linkage table are reserved, | |
256 | and the initial contents are unimportant (we zero them out). | |
257 | Subsequent entries look like this. See the SVR4 ABI 386 | |
258 | supplement to see how this works. */ | |
259 | ||
260 | /* For the s390, simple addr offset can only be 0 - 4096. | |
261 | To use the full 16777216 TB address space, several instructions | |
262 | are needed to load an address in a register and execute | |
263 | a branch( or just saving the address) | |
264 | ||
99c79b2e | 265 | Furthermore, only r 0 and 1 are free to use!!! */ |
a85d7ed0 NC |
266 | |
267 | /* The first 3 words in the GOT are then reserved. | |
268 | Word 0 is the address of the dynamic table. | |
269 | Word 1 is a pointer to a structure describing the object | |
270 | Word 2 is used to point to the loader entry address. | |
271 | ||
272 | The code for PLT entries looks like this: | |
273 | ||
274 | The GOT holds the address in the PLT to be executed. | |
275 | The loader then gets: | |
276 | 24(15) = Pointer to the structure describing the object. | |
99c79b2e | 277 | 28(15) = Offset in symbol table |
a85d7ed0 NC |
278 | The loader must then find the module where the function is |
279 | and insert the address in the GOT. | |
280 | ||
281 | PLT1: LARL 1,<fn>@GOTENT # 6 bytes Load address of GOT entry in r1 | |
282 | LG 1,0(1) # 6 bytes Load address from GOT in r1 | |
283 | BCR 15,1 # 2 bytes Jump to address | |
284 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | |
285 | LGF 1,12(1) # 6 bytes Load offset in symbl table in r1 | |
286 | BRCL 15,-x # 6 bytes Jump to start of PLT | |
287 | .long ? # 4 bytes offset into symbol table | |
288 | ||
289 | Total = 32 bytes per PLT entry | |
290 | Fixup at offset 2: relative address to GOT entry | |
291 | Fixup at offset 22: relative branch to PLT0 | |
292 | Fixup at offset 28: 32 bit offset into symbol table | |
293 | ||
294 | A 32 bit offset into the symbol table is enough. It allows for symbol | |
295 | tables up to a size of 2 gigabyte. A single dynamic object (the main | |
296 | program, any shared library) is limited to 4GB in size and I want to see | |
297 | the program that manages to have a symbol table of more than 2 GB with a | |
298 | total size of at max 4 GB. */ | |
299 | ||
dc810e39 AM |
300 | #define PLT_ENTRY_WORD0 (bfd_vma) 0xc0100000 |
301 | #define PLT_ENTRY_WORD1 (bfd_vma) 0x0000e310 | |
302 | #define PLT_ENTRY_WORD2 (bfd_vma) 0x10000004 | |
303 | #define PLT_ENTRY_WORD3 (bfd_vma) 0x07f10d10 | |
304 | #define PLT_ENTRY_WORD4 (bfd_vma) 0xe310100c | |
305 | #define PLT_ENTRY_WORD5 (bfd_vma) 0x0014c0f4 | |
306 | #define PLT_ENTRY_WORD6 (bfd_vma) 0x00000000 | |
307 | #define PLT_ENTRY_WORD7 (bfd_vma) 0x00000000 | |
a85d7ed0 NC |
308 | |
309 | /* The first PLT entry pushes the offset into the symbol table | |
310 | from R1 onto the stack at 8(15) and the loader object info | |
311 | at 12(15), loads the loader address in R1 and jumps to it. */ | |
312 | ||
313 | /* The first entry in the PLT: | |
314 | ||
315 | PLT0: | |
316 | STG 1,56(15) # r1 contains the offset into the symbol table | |
317 | LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table | |
318 | MVC 48(8,15),8(1) # move loader ino (object struct address) to stack | |
319 | LG 1,16(1) # get entry address of loader | |
320 | BCR 15,1 # jump to loader | |
321 | ||
322 | Fixup at offset 8: relative address to start of GOT. */ | |
323 | ||
dc810e39 AM |
324 | #define PLT_FIRST_ENTRY_WORD0 (bfd_vma) 0xe310f038 |
325 | #define PLT_FIRST_ENTRY_WORD1 (bfd_vma) 0x0024c010 | |
326 | #define PLT_FIRST_ENTRY_WORD2 (bfd_vma) 0x00000000 | |
327 | #define PLT_FIRST_ENTRY_WORD3 (bfd_vma) 0xd207f030 | |
328 | #define PLT_FIRST_ENTRY_WORD4 (bfd_vma) 0x1008e310 | |
329 | #define PLT_FIRST_ENTRY_WORD5 (bfd_vma) 0x10100004 | |
330 | #define PLT_FIRST_ENTRY_WORD6 (bfd_vma) 0x07f10700 | |
331 | #define PLT_FIRST_ENTRY_WORD7 (bfd_vma) 0x07000700 | |
a85d7ed0 NC |
332 | |
333 | /* The s390 linker needs to keep track of the number of relocs that it | |
0451c93c MS |
334 | decides to copy as dynamic relocs in check_relocs for each symbol. |
335 | This is so that it can later discard them if they are found to be | |
336 | unnecessary. We store the information in a field extending the | |
337 | regular ELF linker hash table. */ | |
a85d7ed0 | 338 | |
0451c93c | 339 | struct elf_s390_dyn_relocs |
a85d7ed0 | 340 | { |
0451c93c MS |
341 | struct elf_s390_dyn_relocs *next; |
342 | ||
343 | /* The input section of the reloc. */ | |
344 | asection *sec; | |
345 | ||
346 | /* Total number of relocs copied for the input section. */ | |
a85d7ed0 | 347 | bfd_size_type count; |
0451c93c MS |
348 | |
349 | /* Number of pc-relative relocs copied for the input section. */ | |
350 | bfd_size_type pc_count; | |
a85d7ed0 NC |
351 | }; |
352 | ||
353 | /* s390 ELF linker hash entry. */ | |
354 | ||
355 | struct elf_s390_link_hash_entry | |
356 | { | |
0451c93c | 357 | struct elf_link_hash_entry elf; |
a85d7ed0 | 358 | |
0451c93c MS |
359 | /* Track dynamic relocs copied for this symbol. */ |
360 | struct elf_s390_dyn_relocs *dyn_relocs; | |
a85d7ed0 NC |
361 | }; |
362 | ||
363 | /* s390 ELF linker hash table. */ | |
364 | ||
365 | struct elf_s390_link_hash_table | |
366 | { | |
0451c93c | 367 | struct elf_link_hash_table elf; |
a85d7ed0 | 368 | |
0451c93c MS |
369 | /* Short-cuts to get to dynamic linker sections. */ |
370 | asection *sgot; | |
371 | asection *sgotplt; | |
372 | asection *srelgot; | |
373 | asection *splt; | |
374 | asection *srelplt; | |
375 | asection *sdynbss; | |
376 | asection *srelbss; | |
ec338859 AM |
377 | |
378 | /* Small local sym to section mapping cache. */ | |
379 | struct sym_sec_cache sym_sec; | |
0451c93c | 380 | }; |
a85d7ed0 NC |
381 | |
382 | /* Get the s390 ELF linker hash table from a link_info structure. */ | |
383 | ||
384 | #define elf_s390_hash_table(p) \ | |
385 | ((struct elf_s390_link_hash_table *) ((p)->hash)) | |
386 | ||
387 | /* Create an entry in an s390 ELF linker hash table. */ | |
388 | ||
389 | static struct bfd_hash_entry * | |
0451c93c | 390 | link_hash_newfunc (entry, table, string) |
a85d7ed0 NC |
391 | struct bfd_hash_entry *entry; |
392 | struct bfd_hash_table *table; | |
393 | const char *string; | |
394 | { | |
a85d7ed0 NC |
395 | /* Allocate the structure if it has not already been allocated by a |
396 | subclass. */ | |
0451c93c MS |
397 | if (entry == NULL) |
398 | { | |
399 | entry = bfd_hash_allocate (table, | |
400 | sizeof (struct elf_s390_link_hash_entry)); | |
401 | if (entry == NULL) | |
402 | return entry; | |
403 | } | |
a85d7ed0 NC |
404 | |
405 | /* Call the allocation method of the superclass. */ | |
0451c93c MS |
406 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
407 | if (entry != NULL) | |
a85d7ed0 | 408 | { |
0451c93c MS |
409 | struct elf_s390_link_hash_entry *eh; |
410 | ||
411 | eh = (struct elf_s390_link_hash_entry *) entry; | |
412 | eh->dyn_relocs = NULL; | |
a85d7ed0 NC |
413 | } |
414 | ||
0451c93c | 415 | return entry; |
a85d7ed0 NC |
416 | } |
417 | ||
418 | /* Create an s390 ELF linker hash table. */ | |
419 | ||
420 | static struct bfd_link_hash_table * | |
421 | elf_s390_link_hash_table_create (abfd) | |
422 | bfd *abfd; | |
423 | { | |
424 | struct elf_s390_link_hash_table *ret; | |
dc810e39 | 425 | bfd_size_type amt = sizeof (struct elf_s390_link_hash_table); |
a85d7ed0 | 426 | |
0451c93c MS |
427 | ret = (struct elf_s390_link_hash_table *) bfd_alloc (abfd, amt); |
428 | if (ret == NULL) | |
a85d7ed0 NC |
429 | return NULL; |
430 | ||
0451c93c | 431 | if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc)) |
a85d7ed0 NC |
432 | { |
433 | bfd_release (abfd, ret); | |
434 | return NULL; | |
435 | } | |
436 | ||
0451c93c MS |
437 | ret->sgot = NULL; |
438 | ret->sgotplt = NULL; | |
439 | ret->srelgot = NULL; | |
440 | ret->splt = NULL; | |
441 | ret->srelplt = NULL; | |
442 | ret->sdynbss = NULL; | |
443 | ret->srelbss = NULL; | |
ec338859 | 444 | ret->sym_sec.abfd = NULL; |
0451c93c MS |
445 | |
446 | return &ret->elf.root; | |
447 | } | |
448 | ||
449 | /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up | |
450 | shortcuts to them in our hash table. */ | |
451 | ||
452 | static boolean | |
453 | create_got_section (dynobj, info) | |
454 | bfd *dynobj; | |
455 | struct bfd_link_info *info; | |
456 | { | |
457 | struct elf_s390_link_hash_table *htab; | |
458 | ||
459 | if (! _bfd_elf_create_got_section (dynobj, info)) | |
460 | return false; | |
461 | ||
462 | htab = elf_s390_hash_table (info); | |
463 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); | |
464 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
465 | if (!htab->sgot || !htab->sgotplt) | |
466 | abort (); | |
467 | ||
468 | htab->srelgot = bfd_make_section (dynobj, ".rela.got"); | |
469 | if (htab->srelgot == NULL | |
470 | || ! bfd_set_section_flags (dynobj, htab->srelgot, | |
471 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
472 | | SEC_IN_MEMORY | SEC_LINKER_CREATED | |
473 | | SEC_READONLY)) | |
474 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) | |
475 | return false; | |
476 | return true; | |
477 | } | |
478 | ||
479 | /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and | |
480 | .rela.bss sections in DYNOBJ, and set up shortcuts to them in our | |
481 | hash table. */ | |
482 | ||
483 | static boolean | |
484 | elf_s390_create_dynamic_sections (dynobj, info) | |
485 | bfd *dynobj; | |
486 | struct bfd_link_info *info; | |
487 | { | |
488 | struct elf_s390_link_hash_table *htab; | |
489 | ||
490 | htab = elf_s390_hash_table (info); | |
491 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
492 | return false; | |
493 | ||
494 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
495 | return false; | |
496 | ||
497 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
498 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
499 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
500 | if (!info->shared) | |
501 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
502 | ||
503 | if (!htab->splt || !htab->srelplt || !htab->sdynbss | |
504 | || (!info->shared && !htab->srelbss)) | |
505 | abort (); | |
506 | ||
507 | return true; | |
a85d7ed0 NC |
508 | } |
509 | ||
0451c93c MS |
510 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
511 | ||
512 | static void | |
513 | elf_s390_copy_indirect_symbol (dir, ind) | |
514 | struct elf_link_hash_entry *dir, *ind; | |
515 | { | |
516 | struct elf_s390_link_hash_entry *edir, *eind; | |
517 | ||
518 | edir = (struct elf_s390_link_hash_entry *) dir; | |
519 | eind = (struct elf_s390_link_hash_entry *) ind; | |
520 | ||
521 | if (eind->dyn_relocs != NULL) | |
522 | { | |
523 | if (edir->dyn_relocs != NULL) | |
524 | { | |
525 | struct elf_s390_dyn_relocs **pp; | |
526 | struct elf_s390_dyn_relocs *p; | |
527 | ||
528 | if (ind->root.type == bfd_link_hash_indirect) | |
529 | abort (); | |
530 | ||
531 | /* Add reloc counts against the weak sym to the strong sym | |
532 | list. Merge any entries against the same section. */ | |
533 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
534 | { | |
535 | struct elf_s390_dyn_relocs *q; | |
536 | ||
537 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
538 | if (q->sec == p->sec) | |
539 | { | |
540 | q->pc_count += p->pc_count; | |
541 | q->count += p->count; | |
542 | *pp = p->next; | |
543 | break; | |
544 | } | |
545 | if (q == NULL) | |
546 | pp = &p->next; | |
547 | } | |
548 | *pp = edir->dyn_relocs; | |
549 | } | |
550 | ||
551 | edir->dyn_relocs = eind->dyn_relocs; | |
552 | eind->dyn_relocs = NULL; | |
553 | } | |
554 | ||
555 | _bfd_elf_link_hash_copy_indirect (dir, ind); | |
556 | } | |
a85d7ed0 NC |
557 | |
558 | /* Look through the relocs for a section during the first phase, and | |
559 | allocate space in the global offset table or procedure linkage | |
560 | table. */ | |
561 | ||
562 | static boolean | |
563 | elf_s390_check_relocs (abfd, info, sec, relocs) | |
564 | bfd *abfd; | |
565 | struct bfd_link_info *info; | |
566 | asection *sec; | |
567 | const Elf_Internal_Rela *relocs; | |
568 | { | |
0451c93c | 569 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
570 | Elf_Internal_Shdr *symtab_hdr; |
571 | struct elf_link_hash_entry **sym_hashes; | |
a85d7ed0 NC |
572 | const Elf_Internal_Rela *rel; |
573 | const Elf_Internal_Rela *rel_end; | |
a85d7ed0 NC |
574 | asection *sreloc; |
575 | ||
576 | if (info->relocateable) | |
577 | return true; | |
578 | ||
0451c93c | 579 | htab = elf_s390_hash_table (info); |
a85d7ed0 NC |
580 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
581 | sym_hashes = elf_sym_hashes (abfd); | |
a85d7ed0 | 582 | |
a85d7ed0 NC |
583 | sreloc = NULL; |
584 | ||
585 | rel_end = relocs + sec->reloc_count; | |
586 | for (rel = relocs; rel < rel_end; rel++) | |
587 | { | |
588 | unsigned long r_symndx; | |
589 | struct elf_link_hash_entry *h; | |
590 | ||
591 | r_symndx = ELF64_R_SYM (rel->r_info); | |
592 | ||
0451c93c MS |
593 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
594 | { | |
595 | (*_bfd_error_handler) (_("%s: bad symbol index: %d"), | |
596 | bfd_archive_filename (abfd), | |
597 | r_symndx); | |
598 | return false; | |
599 | } | |
600 | ||
a85d7ed0 NC |
601 | if (r_symndx < symtab_hdr->sh_info) |
602 | h = NULL; | |
603 | else | |
99c79b2e | 604 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
a85d7ed0 | 605 | |
a85d7ed0 NC |
606 | switch (ELF64_R_TYPE (rel->r_info)) |
607 | { | |
608 | case R_390_GOT12: | |
609 | case R_390_GOT16: | |
610 | case R_390_GOT32: | |
611 | case R_390_GOT64: | |
612 | case R_390_GOTENT: | |
613 | /* This symbol requires a global offset table entry. */ | |
a85d7ed0 NC |
614 | if (h != NULL) |
615 | { | |
51b64d56 | 616 | h->got.refcount += 1; |
a85d7ed0 NC |
617 | } |
618 | else | |
619 | { | |
0451c93c MS |
620 | bfd_signed_vma *local_got_refcounts; |
621 | ||
99c79b2e | 622 | /* This is a global offset table entry for a local symbol. */ |
0451c93c | 623 | local_got_refcounts = elf_local_got_refcounts (abfd); |
a85d7ed0 NC |
624 | if (local_got_refcounts == NULL) |
625 | { | |
dc810e39 | 626 | bfd_size_type size; |
ec338859 | 627 | |
0451c93c MS |
628 | size = symtab_hdr->sh_info; |
629 | size *= sizeof (bfd_signed_vma); | |
dc810e39 | 630 | local_got_refcounts = ((bfd_signed_vma *) |
51b64d56 | 631 | bfd_zalloc (abfd, size)); |
a85d7ed0 NC |
632 | if (local_got_refcounts == NULL) |
633 | return false; | |
634 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
a85d7ed0 | 635 | } |
51b64d56 | 636 | local_got_refcounts[r_symndx] += 1; |
a85d7ed0 | 637 | } |
0451c93c | 638 | /* Fall through */ |
a85d7ed0 | 639 | |
0451c93c MS |
640 | case R_390_GOTOFF: |
641 | case R_390_GOTPC: | |
642 | case R_390_GOTPCDBL: | |
643 | if (htab->sgot == NULL) | |
644 | { | |
645 | if (htab->elf.dynobj == NULL) | |
646 | htab->elf.dynobj = abfd; | |
647 | if (!create_got_section (htab->elf.dynobj, info)) | |
648 | return false; | |
649 | } | |
650 | break; | |
ec338859 | 651 | |
a85d7ed0 NC |
652 | case R_390_PLT16DBL: |
653 | case R_390_PLT32: | |
654 | case R_390_PLT32DBL: | |
655 | case R_390_PLT64: | |
656 | /* This symbol requires a procedure linkage table entry. We | |
657 | actually build the entry in adjust_dynamic_symbol, | |
658 | because this might be a case of linking PIC code which is | |
659 | never referenced by a dynamic object, in which case we | |
660 | don't need to generate a procedure linkage table entry | |
661 | after all. */ | |
ec338859 | 662 | |
a85d7ed0 NC |
663 | /* If this is a local symbol, we resolve it directly without |
664 | creating a procedure linkage table entry. */ | |
665 | if (h == NULL) | |
666 | continue; | |
ec338859 | 667 | |
51b64d56 AM |
668 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
669 | h->plt.refcount += 1; | |
a85d7ed0 | 670 | break; |
ec338859 | 671 | |
a85d7ed0 NC |
672 | case R_390_8: |
673 | case R_390_16: | |
674 | case R_390_32: | |
675 | case R_390_64: | |
676 | case R_390_PC16: | |
677 | case R_390_PC16DBL: | |
678 | case R_390_PC32: | |
679 | case R_390_PC32DBL: | |
680 | case R_390_PC64: | |
0451c93c MS |
681 | if (h != NULL && !info->shared) |
682 | { | |
683 | /* If this reloc is in a read-only section, we might | |
684 | need a copy reloc. We can't check reliably at this | |
685 | stage whether the section is read-only, as input | |
686 | sections have not yet been mapped to output sections. | |
687 | Tentatively set the flag for now, and correct in | |
688 | adjust_dynamic_symbol. */ | |
689 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
ec338859 | 690 | |
0451c93c MS |
691 | /* We may need a .plt entry if the function this reloc |
692 | refers to is in a shared lib. */ | |
693 | h->plt.refcount += 1; | |
694 | } | |
ec338859 | 695 | |
a85d7ed0 | 696 | /* If we are creating a shared library, and this is a reloc |
0451c93c MS |
697 | against a global symbol, or a non PC relative reloc |
698 | against a local symbol, then we need to copy the reloc | |
699 | into the shared library. However, if we are linking with | |
700 | -Bsymbolic, we do not need to copy a reloc against a | |
701 | global symbol which is defined in an object we are | |
702 | including in the link (i.e., DEF_REGULAR is set). At | |
703 | this point we have not seen all the input files, so it is | |
704 | possible that DEF_REGULAR is not set now but will be set | |
705 | later (it is never cleared). In case of a weak definition, | |
706 | DEF_REGULAR may be cleared later by a strong definition in | |
707 | a shared library. We account for that possibility below by | |
708 | storing information in the relocs_copied field of the hash | |
709 | table entry. A similar situation occurs when creating | |
710 | shared libraries and symbol visibility changes render the | |
711 | symbol local. | |
712 | ||
713 | If on the other hand, we are creating an executable, we | |
714 | may need to keep relocations for symbols satisfied by a | |
715 | dynamic library if we manage to avoid copy relocs for the | |
716 | symbol. */ | |
717 | if ((info->shared | |
718 | && (sec->flags & SEC_ALLOC) != 0 | |
719 | && ((ELF64_R_TYPE (rel->r_info) != R_390_PC16 | |
720 | && ELF64_R_TYPE (rel->r_info) != R_390_PC16DBL | |
721 | && ELF64_R_TYPE (rel->r_info) != R_390_PC32 | |
722 | && ELF64_R_TYPE (rel->r_info) != R_390_PC32DBL | |
723 | && ELF64_R_TYPE (rel->r_info) != R_390_PC64) | |
724 | || (h != NULL | |
725 | && (! info->symbolic | |
726 | || h->root.type == bfd_link_hash_defweak | |
727 | || (h->elf_link_hash_flags | |
728 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
729 | || (!info->shared | |
730 | && (sec->flags & SEC_ALLOC) != 0 | |
731 | && h != NULL | |
732 | && (h->root.type == bfd_link_hash_defweak | |
733 | || (h->elf_link_hash_flags | |
734 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
a85d7ed0 | 735 | { |
ec338859 AM |
736 | struct elf_s390_dyn_relocs *p; |
737 | struct elf_s390_dyn_relocs **head; | |
738 | ||
0451c93c MS |
739 | /* We must copy these reloc types into the output file. |
740 | Create a reloc section in dynobj and make room for | |
741 | this reloc. */ | |
a85d7ed0 NC |
742 | if (sreloc == NULL) |
743 | { | |
744 | const char *name; | |
0451c93c | 745 | bfd *dynobj; |
ec338859 | 746 | |
a85d7ed0 NC |
747 | name = (bfd_elf_string_from_elf_section |
748 | (abfd, | |
749 | elf_elfheader (abfd)->e_shstrndx, | |
750 | elf_section_data (sec)->rel_hdr.sh_name)); | |
751 | if (name == NULL) | |
752 | return false; | |
ec338859 | 753 | |
0451c93c MS |
754 | if (strncmp (name, ".rela", 5) != 0 |
755 | || strcmp (bfd_get_section_name (abfd, sec), | |
756 | name + 5) != 0) | |
757 | { | |
758 | (*_bfd_error_handler) | |
759 | (_("%s: bad relocation section name `%s\'"), | |
760 | bfd_archive_filename (abfd), name); | |
761 | } | |
ec338859 | 762 | |
0451c93c MS |
763 | if (htab->elf.dynobj == NULL) |
764 | htab->elf.dynobj = abfd; | |
a85d7ed0 | 765 | |
0451c93c | 766 | dynobj = htab->elf.dynobj; |
a85d7ed0 NC |
767 | sreloc = bfd_get_section_by_name (dynobj, name); |
768 | if (sreloc == NULL) | |
769 | { | |
770 | flagword flags; | |
ec338859 | 771 | |
a85d7ed0 NC |
772 | sreloc = bfd_make_section (dynobj, name); |
773 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
774 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
775 | if ((sec->flags & SEC_ALLOC) != 0) | |
776 | flags |= SEC_ALLOC | SEC_LOAD; | |
777 | if (sreloc == NULL | |
778 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
779 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) | |
780 | return false; | |
781 | } | |
0451c93c | 782 | elf_section_data (sec)->sreloc = sreloc; |
a85d7ed0 | 783 | } |
ec338859 | 784 | |
0451c93c MS |
785 | /* If this is a global symbol, we count the number of |
786 | relocations we need for this symbol. */ | |
787 | if (h != NULL) | |
a85d7ed0 | 788 | { |
ec338859 | 789 | head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs; |
0451c93c MS |
790 | } |
791 | else | |
792 | { | |
ec338859 AM |
793 | /* Track dynamic relocs needed for local syms too. |
794 | We really need local syms available to do this | |
795 | easily. Oh well. */ | |
796 | ||
797 | asection *s; | |
798 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
799 | sec, r_symndx); | |
800 | if (s == NULL) | |
801 | return false; | |
802 | ||
803 | head = ((struct elf_s390_dyn_relocs **) | |
804 | &elf_section_data (s)->local_dynrel); | |
805 | } | |
806 | ||
807 | p = *head; | |
808 | if (p == NULL || p->sec != sec) | |
809 | { | |
810 | bfd_size_type amt = sizeof *p; | |
811 | p = ((struct elf_s390_dyn_relocs *) | |
812 | bfd_alloc (htab->elf.dynobj, amt)); | |
813 | if (p == NULL) | |
814 | return false; | |
815 | p->next = *head; | |
816 | *head = p; | |
817 | p->sec = sec; | |
818 | p->count = 0; | |
819 | p->pc_count = 0; | |
a85d7ed0 | 820 | } |
ec338859 AM |
821 | |
822 | p->count += 1; | |
823 | if (ELF64_R_TYPE (rel->r_info) == R_390_PC16 | |
824 | || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL | |
825 | || ELF64_R_TYPE (rel->r_info) == R_390_PC32 | |
826 | || ELF64_R_TYPE (rel->r_info) == R_390_PC32DBL | |
827 | || ELF64_R_TYPE (rel->r_info) == R_390_PC64) | |
828 | p->pc_count += 1; | |
a85d7ed0 | 829 | } |
a85d7ed0 | 830 | break; |
ec338859 | 831 | |
a85d7ed0 NC |
832 | /* This relocation describes the C++ object vtable hierarchy. |
833 | Reconstruct it for later use during GC. */ | |
834 | case R_390_GNU_VTINHERIT: | |
835 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
836 | return false; | |
837 | break; | |
ec338859 | 838 | |
a85d7ed0 NC |
839 | /* This relocation describes which C++ vtable entries are actually |
840 | used. Record for later use during GC. */ | |
841 | case R_390_GNU_VTENTRY: | |
db727808 | 842 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
a85d7ed0 NC |
843 | return false; |
844 | break; | |
ec338859 | 845 | |
a85d7ed0 NC |
846 | default: |
847 | break; | |
848 | } | |
849 | } | |
850 | ||
851 | return true; | |
852 | } | |
853 | ||
854 | /* Return the section that should be marked against GC for a given | |
855 | relocation. */ | |
856 | ||
857 | static asection * | |
858 | elf_s390_gc_mark_hook (abfd, info, rel, h, sym) | |
859 | bfd *abfd; | |
860 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
861 | Elf_Internal_Rela *rel; | |
862 | struct elf_link_hash_entry *h; | |
863 | Elf_Internal_Sym *sym; | |
864 | { | |
865 | if (h != NULL) | |
866 | { | |
867 | switch (ELF64_R_TYPE (rel->r_info)) | |
868 | { | |
869 | case R_390_GNU_VTINHERIT: | |
870 | case R_390_GNU_VTENTRY: | |
871 | break; | |
872 | ||
873 | default: | |
874 | switch (h->root.type) | |
875 | { | |
876 | case bfd_link_hash_defined: | |
877 | case bfd_link_hash_defweak: | |
878 | return h->root.u.def.section; | |
879 | ||
880 | case bfd_link_hash_common: | |
881 | return h->root.u.c.p->section; | |
882 | ||
883 | default: | |
884 | break; | |
885 | } | |
886 | } | |
887 | } | |
888 | else | |
889 | { | |
9ad5cbcf | 890 | return bfd_section_from_elf_index (abfd, sym->st_shndx); |
a85d7ed0 NC |
891 | } |
892 | ||
893 | return NULL; | |
894 | } | |
895 | ||
896 | /* Update the got entry reference counts for the section being removed. */ | |
897 | ||
898 | static boolean | |
899 | elf_s390_gc_sweep_hook (abfd, info, sec, relocs) | |
0451c93c MS |
900 | bfd *abfd; |
901 | struct bfd_link_info *info; | |
902 | asection *sec; | |
903 | const Elf_Internal_Rela *relocs; | |
a85d7ed0 NC |
904 | { |
905 | Elf_Internal_Shdr *symtab_hdr; | |
906 | struct elf_link_hash_entry **sym_hashes; | |
907 | bfd_signed_vma *local_got_refcounts; | |
908 | const Elf_Internal_Rela *rel, *relend; | |
909 | unsigned long r_symndx; | |
910 | struct elf_link_hash_entry *h; | |
a85d7ed0 | 911 | |
ec338859 | 912 | elf_section_data (sec)->local_dynrel = NULL; |
a85d7ed0 | 913 | |
0451c93c MS |
914 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
915 | sym_hashes = elf_sym_hashes (abfd); | |
916 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
a85d7ed0 NC |
917 | |
918 | relend = relocs + sec->reloc_count; | |
919 | for (rel = relocs; rel < relend; rel++) | |
920 | switch (ELF64_R_TYPE (rel->r_info)) | |
921 | { | |
922 | case R_390_GOT12: | |
923 | case R_390_GOT16: | |
924 | case R_390_GOT32: | |
925 | case R_390_GOT64: | |
926 | case R_390_GOTOFF: | |
927 | case R_390_GOTPC: | |
928 | case R_390_GOTPCDBL: | |
929 | case R_390_GOTENT: | |
930 | r_symndx = ELF64_R_SYM (rel->r_info); | |
931 | if (r_symndx >= symtab_hdr->sh_info) | |
932 | { | |
933 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
934 | if (h->got.refcount > 0) | |
0451c93c | 935 | h->got.refcount -= 1; |
a85d7ed0 NC |
936 | } |
937 | else if (local_got_refcounts != NULL) | |
938 | { | |
939 | if (local_got_refcounts[r_symndx] > 0) | |
0451c93c MS |
940 | local_got_refcounts[r_symndx] -= 1; |
941 | } | |
942 | break; | |
943 | ||
944 | case R_390_8: | |
945 | case R_390_12: | |
946 | case R_390_16: | |
947 | case R_390_32: | |
948 | case R_390_64: | |
949 | case R_390_PC16: | |
950 | case R_390_PC16DBL: | |
951 | case R_390_PC32: | |
952 | case R_390_PC32DBL: | |
953 | case R_390_PC64: | |
954 | r_symndx = ELF64_R_SYM (rel->r_info); | |
955 | if (r_symndx >= symtab_hdr->sh_info) | |
956 | { | |
957 | struct elf_s390_link_hash_entry *eh; | |
958 | struct elf_s390_dyn_relocs **pp; | |
959 | struct elf_s390_dyn_relocs *p; | |
960 | ||
961 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
962 | ||
963 | if (!info->shared && h->plt.refcount > 0) | |
964 | h->plt.refcount -= 1; | |
965 | ||
966 | eh = (struct elf_s390_link_hash_entry *) h; | |
967 | ||
968 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
969 | if (p->sec == sec) | |
970 | { | |
971 | if (ELF64_R_TYPE (rel->r_info) == R_390_PC16 | |
972 | || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL | |
973 | || ELF64_R_TYPE (rel->r_info) == R_390_PC32) | |
974 | p->pc_count -= 1; | |
975 | p->count -= 1; | |
976 | if (p->count == 0) | |
977 | *pp = p->next; | |
978 | break; | |
979 | } | |
a85d7ed0 NC |
980 | } |
981 | break; | |
982 | ||
983 | case R_390_PLT16DBL: | |
984 | case R_390_PLT32: | |
985 | case R_390_PLT32DBL: | |
986 | case R_390_PLT64: | |
987 | r_symndx = ELF64_R_SYM (rel->r_info); | |
988 | if (r_symndx >= symtab_hdr->sh_info) | |
989 | { | |
990 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
991 | if (h->plt.refcount > 0) | |
992 | h->plt.refcount -= 1; | |
993 | } | |
994 | break; | |
995 | ||
996 | default: | |
997 | break; | |
998 | } | |
999 | ||
1000 | return true; | |
1001 | } | |
1002 | ||
1003 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
1004 | regular object. The current definition is in some section of the | |
1005 | dynamic object, but we're not including those sections. We have to | |
1006 | change the definition to something the rest of the link can | |
1007 | understand. */ | |
1008 | ||
1009 | static boolean | |
1010 | elf_s390_adjust_dynamic_symbol (info, h) | |
1011 | struct bfd_link_info *info; | |
1012 | struct elf_link_hash_entry *h; | |
1013 | { | |
0451c93c MS |
1014 | struct elf_s390_link_hash_table *htab; |
1015 | struct elf_s390_link_hash_entry * eh; | |
1016 | struct elf_s390_dyn_relocs *p; | |
a85d7ed0 NC |
1017 | asection *s; |
1018 | unsigned int power_of_two; | |
1019 | ||
a85d7ed0 NC |
1020 | /* If this is a function, put it in the procedure linkage table. We |
1021 | will fill in the contents of the procedure linkage table later | |
1022 | (although we could actually do it here). */ | |
1023 | if (h->type == STT_FUNC | |
1024 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
1025 | { | |
0451c93c MS |
1026 | if (h->plt.refcount <= 0 |
1027 | || (! info->shared | |
1028 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 | |
f9cd9119 MS |
1029 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0 |
1030 | && h->root.type != bfd_link_hash_undefweak | |
1031 | && h->root.type != bfd_link_hash_undefined)) | |
a85d7ed0 NC |
1032 | { |
1033 | /* This case can occur if we saw a PLT32 reloc in an input | |
1034 | file, but the symbol was never referred to by a dynamic | |
0451c93c MS |
1035 | object, or if all references were garbage collected. In |
1036 | such a case, we don't actually need to build a procedure | |
1037 | linkage table, and we can just do a PC32 reloc instead. */ | |
a85d7ed0 NC |
1038 | h->plt.offset = (bfd_vma) -1; |
1039 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
a85d7ed0 NC |
1040 | } |
1041 | ||
a85d7ed0 NC |
1042 | return true; |
1043 | } | |
bbd7ec4a | 1044 | else |
0451c93c MS |
1045 | /* It's possible that we incorrectly decided a .plt reloc was |
1046 | needed for an R_390_PC32 reloc to a non-function sym in | |
1047 | check_relocs. We can't decide accurately between function and | |
1048 | non-function syms in check-relocs; Objects loaded later in | |
1049 | the link may change h->type. So fix it now. */ | |
bbd7ec4a | 1050 | h->plt.offset = (bfd_vma) -1; |
a85d7ed0 NC |
1051 | |
1052 | /* If this is a weak symbol, and there is a real definition, the | |
1053 | processor independent code will have arranged for us to see the | |
1054 | real definition first, and we can just use the same value. */ | |
1055 | if (h->weakdef != NULL) | |
1056 | { | |
1057 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
1058 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
1059 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
1060 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
1061 | return true; | |
1062 | } | |
1063 | ||
1064 | /* This is a reference to a symbol defined by a dynamic object which | |
1065 | is not a function. */ | |
1066 | ||
1067 | /* If we are creating a shared library, we must presume that the | |
1068 | only references to the symbol are via the global offset table. | |
1069 | For such cases we need not do anything here; the relocations will | |
1070 | be handled correctly by relocate_section. */ | |
1071 | if (info->shared) | |
1072 | return true; | |
1073 | ||
1074 | /* If there are no references to this symbol that do not use the | |
1075 | GOT, we don't need to generate a copy reloc. */ | |
1076 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
1077 | return true; | |
1078 | ||
0451c93c MS |
1079 | /* If -z nocopyreloc was given, we won't generate them either. */ |
1080 | if (info->nocopyreloc) | |
1081 | { | |
1082 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
1083 | return true; | |
1084 | } | |
1085 | ||
1086 | eh = (struct elf_s390_link_hash_entry *) h; | |
1087 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
1088 | { | |
1089 | s = p->sec->output_section; | |
1090 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
1091 | break; | |
1092 | } | |
1093 | ||
1094 | /* If we didn't find any dynamic relocs in read-only sections, then | |
1095 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
1096 | if (p == NULL) | |
1097 | { | |
1098 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
1099 | return true; | |
1100 | } | |
1101 | ||
a85d7ed0 NC |
1102 | /* We must allocate the symbol in our .dynbss section, which will |
1103 | become part of the .bss section of the executable. There will be | |
1104 | an entry for this symbol in the .dynsym section. The dynamic | |
1105 | object will contain position independent code, so all references | |
1106 | from the dynamic object to this symbol will go through the global | |
1107 | offset table. The dynamic linker will use the .dynsym entry to | |
1108 | determine the address it must put in the global offset table, so | |
1109 | both the dynamic object and the regular object will refer to the | |
1110 | same memory location for the variable. */ | |
1111 | ||
0451c93c | 1112 | htab = elf_s390_hash_table (info); |
a85d7ed0 | 1113 | |
0451c93c MS |
1114 | /* We must generate a R_390_COPY reloc to tell the dynamic linker to |
1115 | copy the initial value out of the dynamic object and into the | |
1116 | runtime process image. */ | |
a85d7ed0 NC |
1117 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
1118 | { | |
0451c93c | 1119 | htab->srelbss->_raw_size += sizeof (Elf64_External_Rela); |
a85d7ed0 NC |
1120 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
1121 | } | |
1122 | ||
1123 | /* We need to figure out the alignment required for this symbol. I | |
1124 | have no idea how ELF linkers handle this. */ | |
1125 | power_of_two = bfd_log2 (h->size); | |
1126 | if (power_of_two > 3) | |
1127 | power_of_two = 3; | |
1128 | ||
1129 | /* Apply the required alignment. */ | |
0451c93c MS |
1130 | s = htab->sdynbss; |
1131 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); | |
1132 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
a85d7ed0 | 1133 | { |
0451c93c | 1134 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
a85d7ed0 NC |
1135 | return false; |
1136 | } | |
1137 | ||
1138 | /* Define the symbol as being at this point in the section. */ | |
1139 | h->root.u.def.section = s; | |
1140 | h->root.u.def.value = s->_raw_size; | |
1141 | ||
1142 | /* Increment the section size to make room for the symbol. */ | |
1143 | s->_raw_size += h->size; | |
1144 | ||
1145 | return true; | |
1146 | } | |
1147 | ||
0451c93c MS |
1148 | /* This is the condition under which elf_s390_finish_dynamic_symbol |
1149 | will be called from elflink.h. If elflink.h doesn't call our | |
1150 | finish_dynamic_symbol routine, we'll need to do something about | |
1151 | initializing any .plt and .got entries in elf_s390_relocate_section. */ | |
1152 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ | |
1153 | ((DYN) \ | |
1154 | && ((INFO)->shared \ | |
1155 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ | |
1156 | && ((H)->dynindx != -1 \ | |
1157 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
1158 | ||
1159 | /* Allocate space in .plt, .got and associated reloc sections for | |
1160 | dynamic relocs. */ | |
1161 | ||
1162 | static boolean | |
1163 | allocate_dynrelocs (h, inf) | |
1164 | struct elf_link_hash_entry *h; | |
1165 | PTR inf; | |
1166 | { | |
1167 | struct bfd_link_info *info; | |
1168 | struct elf_s390_link_hash_table *htab; | |
1169 | struct elf_s390_link_hash_entry *eh; | |
1170 | struct elf_s390_dyn_relocs *p; | |
1171 | ||
1172 | if (h->root.type == bfd_link_hash_indirect | |
1173 | || h->root.type == bfd_link_hash_warning) | |
1174 | return true; | |
1175 | ||
1176 | info = (struct bfd_link_info *) inf; | |
1177 | htab = elf_s390_hash_table (info); | |
1178 | ||
1179 | if (htab->elf.dynamic_sections_created | |
1180 | && h->plt.refcount > 0) | |
1181 | { | |
1182 | /* Make sure this symbol is output as a dynamic symbol. | |
1183 | Undefined weak syms won't yet be marked as dynamic. */ | |
1184 | if (h->dynindx == -1 | |
1185 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
1186 | { | |
1187 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
1188 | return false; | |
1189 | } | |
1190 | ||
1191 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) | |
1192 | { | |
1193 | asection *s = htab->splt; | |
1194 | ||
1195 | /* If this is the first .plt entry, make room for the special | |
1196 | first entry. */ | |
1197 | if (s->_raw_size == 0) | |
1198 | s->_raw_size += PLT_FIRST_ENTRY_SIZE; | |
1199 | ||
1200 | h->plt.offset = s->_raw_size; | |
1201 | ||
1202 | /* If this symbol is not defined in a regular file, and we are | |
1203 | not generating a shared library, then set the symbol to this | |
1204 | location in the .plt. This is required to make function | |
1205 | pointers compare as equal between the normal executable and | |
1206 | the shared library. */ | |
1207 | if (! info->shared | |
1208 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
1209 | { | |
1210 | h->root.u.def.section = s; | |
1211 | h->root.u.def.value = h->plt.offset; | |
1212 | } | |
ec338859 | 1213 | |
0451c93c MS |
1214 | /* Make room for this entry. */ |
1215 | s->_raw_size += PLT_ENTRY_SIZE; | |
ec338859 | 1216 | |
0451c93c MS |
1217 | /* We also need to make an entry in the .got.plt section, which |
1218 | will be placed in the .got section by the linker script. */ | |
1219 | htab->sgotplt->_raw_size += GOT_ENTRY_SIZE; | |
1220 | ||
1221 | /* We also need to make an entry in the .rela.plt section. */ | |
1222 | htab->srelplt->_raw_size += sizeof (Elf64_External_Rela); | |
1223 | } | |
1224 | else | |
1225 | { | |
1226 | h->plt.offset = (bfd_vma) -1; | |
1227 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
1228 | } | |
1229 | } | |
1230 | else | |
1231 | { | |
1232 | h->plt.offset = (bfd_vma) -1; | |
1233 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
1234 | } | |
1235 | ||
1236 | if (h->got.refcount > 0) | |
1237 | { | |
1238 | asection *s; | |
1239 | boolean dyn; | |
1240 | ||
1241 | /* Make sure this symbol is output as a dynamic symbol. | |
1242 | Undefined weak syms won't yet be marked as dynamic. */ | |
1243 | if (h->dynindx == -1 | |
1244 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
1245 | { | |
1246 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
1247 | return false; | |
1248 | } | |
1249 | ||
1250 | s = htab->sgot; | |
1251 | h->got.offset = s->_raw_size; | |
1252 | s->_raw_size += GOT_ENTRY_SIZE; | |
1253 | dyn = htab->elf.dynamic_sections_created; | |
1254 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) | |
1255 | htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); | |
1256 | } | |
1257 | else | |
1258 | h->got.offset = (bfd_vma) -1; | |
1259 | ||
1260 | eh = (struct elf_s390_link_hash_entry *) h; | |
1261 | if (eh->dyn_relocs == NULL) | |
1262 | return true; | |
1263 | ||
1264 | /* In the shared -Bsymbolic case, discard space allocated for | |
1265 | dynamic pc-relative relocs against symbols which turn out to be | |
1266 | defined in regular objects. For the normal shared case, discard | |
1267 | space for pc-relative relocs that have become local due to symbol | |
1268 | visibility changes. */ | |
1269 | ||
1270 | if (info->shared) | |
1271 | { | |
1272 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 | |
1273 | && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 | |
1274 | || info->symbolic)) | |
1275 | { | |
1276 | struct elf_s390_dyn_relocs **pp; | |
1277 | ||
1278 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
1279 | { | |
1280 | p->count -= p->pc_count; | |
1281 | p->pc_count = 0; | |
1282 | if (p->count == 0) | |
1283 | *pp = p->next; | |
1284 | else | |
1285 | pp = &p->next; | |
1286 | } | |
1287 | } | |
1288 | } | |
1289 | else | |
1290 | { | |
1291 | /* For the non-shared case, discard space for relocs against | |
1292 | symbols which turn out to need copy relocs or are not | |
1293 | dynamic. */ | |
1294 | ||
1295 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
1296 | && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
1297 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
1298 | || (htab->elf.dynamic_sections_created | |
1299 | && (h->root.type == bfd_link_hash_undefweak | |
1300 | || h->root.type == bfd_link_hash_undefined)))) | |
1301 | { | |
1302 | /* Make sure this symbol is output as a dynamic symbol. | |
1303 | Undefined weak syms won't yet be marked as dynamic. */ | |
1304 | if (h->dynindx == -1 | |
1305 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
1306 | { | |
1307 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
1308 | return false; | |
1309 | } | |
1310 | ||
1311 | /* If that succeeded, we know we'll be keeping all the | |
1312 | relocs. */ | |
1313 | if (h->dynindx != -1) | |
1314 | goto keep; | |
1315 | } | |
1316 | ||
1317 | eh->dyn_relocs = NULL; | |
1318 | ||
ec338859 | 1319 | keep: ; |
0451c93c MS |
1320 | } |
1321 | ||
1322 | /* Finally, allocate space. */ | |
1323 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
1324 | { | |
1325 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
1326 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
1327 | } | |
1328 | ||
1329 | return true; | |
1330 | } | |
1331 | ||
1332 | /* Find any dynamic relocs that apply to read-only sections. */ | |
1333 | ||
1334 | static boolean | |
1335 | readonly_dynrelocs (h, inf) | |
1336 | struct elf_link_hash_entry *h; | |
1337 | PTR inf; | |
1338 | { | |
1339 | struct elf_s390_link_hash_entry *eh; | |
1340 | struct elf_s390_dyn_relocs *p; | |
1341 | ||
1342 | eh = (struct elf_s390_link_hash_entry *) h; | |
1343 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
1344 | { | |
1345 | asection *s = p->sec->output_section; | |
1346 | ||
1347 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
1348 | { | |
1349 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
1350 | ||
1351 | info->flags |= DF_TEXTREL; | |
1352 | ||
1353 | /* Not an error, just cut short the traversal. */ | |
1354 | return false; | |
1355 | } | |
1356 | } | |
1357 | return true; | |
1358 | } | |
1359 | ||
a85d7ed0 NC |
1360 | /* Set the sizes of the dynamic sections. */ |
1361 | ||
1362 | static boolean | |
1363 | elf_s390_size_dynamic_sections (output_bfd, info) | |
29c2fb7c | 1364 | bfd *output_bfd ATTRIBUTE_UNUSED; |
a85d7ed0 NC |
1365 | struct bfd_link_info *info; |
1366 | { | |
0451c93c | 1367 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
1368 | bfd *dynobj; |
1369 | asection *s; | |
a85d7ed0 | 1370 | boolean relocs; |
0451c93c | 1371 | bfd *ibfd; |
a85d7ed0 | 1372 | |
0451c93c MS |
1373 | htab = elf_s390_hash_table (info); |
1374 | dynobj = htab->elf.dynobj; | |
1375 | if (dynobj == NULL) | |
1376 | abort (); | |
a85d7ed0 | 1377 | |
0451c93c | 1378 | if (htab->elf.dynamic_sections_created) |
a85d7ed0 NC |
1379 | { |
1380 | /* Set the contents of the .interp section to the interpreter. */ | |
1381 | if (! info->shared) | |
1382 | { | |
1383 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
0451c93c MS |
1384 | if (s == NULL) |
1385 | abort (); | |
a85d7ed0 NC |
1386 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; |
1387 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
1388 | } | |
1389 | } | |
a85d7ed0 | 1390 | |
0451c93c MS |
1391 | /* Set up .got offsets for local syms, and space for local dynamic |
1392 | relocs. */ | |
1393 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
a85d7ed0 | 1394 | { |
0451c93c MS |
1395 | bfd_signed_vma *local_got; |
1396 | bfd_signed_vma *end_local_got; | |
1397 | bfd_size_type locsymcount; | |
1398 | Elf_Internal_Shdr *symtab_hdr; | |
1399 | asection *srela; | |
a85d7ed0 | 1400 | |
0451c93c | 1401 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
a85d7ed0 NC |
1402 | continue; |
1403 | ||
0451c93c | 1404 | for (s = ibfd->sections; s != NULL; s = s->next) |
a85d7ed0 | 1405 | { |
ec338859 | 1406 | struct elf_s390_dyn_relocs *p; |
0451c93c | 1407 | |
ec338859 AM |
1408 | for (p = *((struct elf_s390_dyn_relocs **) |
1409 | &elf_section_data (s)->local_dynrel); | |
1410 | p != NULL; | |
1411 | p = p->next) | |
a85d7ed0 | 1412 | { |
ec338859 AM |
1413 | if (!bfd_is_abs_section (p->sec) |
1414 | && bfd_is_abs_section (p->sec->output_section)) | |
1415 | { | |
1416 | /* Input section has been discarded, either because | |
1417 | it is a copy of a linkonce section or due to | |
1418 | linker script /DISCARD/, so we'll be discarding | |
1419 | the relocs too. */ | |
1420 | } | |
248866a8 | 1421 | else if (p->count != 0) |
ec338859 AM |
1422 | { |
1423 | srela = elf_section_data (p->sec)->sreloc; | |
1424 | srela->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
248866a8 AM |
1425 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
1426 | info->flags |= DF_TEXTREL; | |
ec338859 | 1427 | } |
a85d7ed0 NC |
1428 | } |
1429 | } | |
0451c93c MS |
1430 | |
1431 | local_got = elf_local_got_refcounts (ibfd); | |
1432 | if (!local_got) | |
1433 | continue; | |
1434 | ||
1435 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
1436 | locsymcount = symtab_hdr->sh_info; | |
1437 | end_local_got = local_got + locsymcount; | |
1438 | s = htab->sgot; | |
1439 | srela = htab->srelgot; | |
1440 | for (; local_got < end_local_got; ++local_got) | |
a85d7ed0 | 1441 | { |
0451c93c | 1442 | if (*local_got > 0) |
a85d7ed0 | 1443 | { |
0451c93c MS |
1444 | *local_got = s->_raw_size; |
1445 | s->_raw_size += GOT_ENTRY_SIZE; | |
1446 | if (info->shared) | |
1447 | srela->_raw_size += sizeof (Elf64_External_Rela); | |
a85d7ed0 NC |
1448 | } |
1449 | else | |
0451c93c | 1450 | *local_got = (bfd_vma) -1; |
a85d7ed0 | 1451 | } |
0451c93c MS |
1452 | } |
1453 | ||
1454 | /* Allocate global sym .plt and .got entries, and space for global | |
1455 | sym dynamic relocs. */ | |
1456 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); | |
1457 | ||
1458 | /* We now have determined the sizes of the various dynamic sections. | |
1459 | Allocate memory for them. */ | |
1460 | relocs = false; | |
1461 | for (s = dynobj->sections; s != NULL; s = s->next) | |
1462 | { | |
1463 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
1464 | continue; | |
1465 | ||
1466 | if (s == htab->splt | |
1467 | || s == htab->sgot | |
1468 | || s == htab->sgotplt) | |
1469 | { | |
1470 | /* Strip this section if we don't need it; see the | |
1471 | comment below. */ | |
1472 | } | |
1473 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) | |
1474 | { | |
1475 | if (s->_raw_size != 0 && s != htab->srelplt) | |
1476 | relocs = true; | |
ec338859 | 1477 | |
0451c93c MS |
1478 | /* We use the reloc_count field as a counter if we need |
1479 | to copy relocs into the output file. */ | |
1480 | s->reloc_count = 0; | |
1481 | } | |
1482 | else | |
a85d7ed0 NC |
1483 | { |
1484 | /* It's not one of our sections, so don't allocate space. */ | |
1485 | continue; | |
1486 | } | |
1487 | ||
0451c93c | 1488 | if (s->_raw_size == 0) |
a85d7ed0 | 1489 | { |
0451c93c MS |
1490 | /* If we don't need this section, strip it from the |
1491 | output file. This is to handle .rela.bss and | |
1492 | .rela.plt. We must create it in | |
1493 | create_dynamic_sections, because it must be created | |
1494 | before the linker maps input sections to output | |
1495 | sections. The linker does that before | |
1496 | adjust_dynamic_symbol is called, and it is that | |
1497 | function which decides whether anything needs to go | |
1498 | into these sections. */ | |
1499 | ||
a85d7ed0 NC |
1500 | _bfd_strip_section_from_output (info, s); |
1501 | continue; | |
1502 | } | |
1503 | ||
0451c93c MS |
1504 | /* Allocate memory for the section contents. We use bfd_zalloc |
1505 | here in case unused entries are not reclaimed before the | |
1506 | section's contents are written out. This should not happen, | |
1507 | but this way if it does, we get a R_390_NONE reloc instead | |
1508 | of garbage. */ | |
1509 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); | |
1510 | if (s->contents == NULL) | |
a85d7ed0 NC |
1511 | return false; |
1512 | } | |
1513 | ||
0451c93c | 1514 | if (htab->elf.dynamic_sections_created) |
a85d7ed0 NC |
1515 | { |
1516 | /* Add some entries to the .dynamic section. We fill in the | |
1517 | values later, in elf_s390_finish_dynamic_sections, but we | |
1518 | must add the entries now so that we get the correct size for | |
1519 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
1520 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
1521 | #define add_dynamic_entry(TAG, VAL) \ |
1522 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
1523 | ||
a85d7ed0 NC |
1524 | if (! info->shared) |
1525 | { | |
dc810e39 | 1526 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
a85d7ed0 NC |
1527 | return false; |
1528 | } | |
1529 | ||
0451c93c | 1530 | if (htab->splt->_raw_size != 0) |
a85d7ed0 | 1531 | { |
dc810e39 AM |
1532 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
1533 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
1534 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
1535 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
a85d7ed0 NC |
1536 | return false; |
1537 | } | |
1538 | ||
1539 | if (relocs) | |
1540 | { | |
dc810e39 AM |
1541 | if (!add_dynamic_entry (DT_RELA, 0) |
1542 | || !add_dynamic_entry (DT_RELASZ, 0) | |
1543 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
a85d7ed0 | 1544 | return false; |
ec338859 | 1545 | |
0451c93c MS |
1546 | /* If any dynamic relocs apply to a read-only section, |
1547 | then we need a DT_TEXTREL entry. */ | |
248866a8 AM |
1548 | if ((info->flags & DF_TEXTREL) == 0) |
1549 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, | |
1550 | (PTR) info); | |
ec338859 | 1551 | |
0451c93c MS |
1552 | if ((info->flags & DF_TEXTREL) != 0) |
1553 | { | |
1554 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
1555 | return false; | |
1556 | } | |
a85d7ed0 NC |
1557 | } |
1558 | } | |
dc810e39 | 1559 | #undef add_dynamic_entry |
a85d7ed0 NC |
1560 | |
1561 | return true; | |
1562 | } | |
1563 | ||
a85d7ed0 NC |
1564 | /* Relocate a 390 ELF section. */ |
1565 | ||
1566 | static boolean | |
1567 | elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, | |
1568 | contents, relocs, local_syms, local_sections) | |
1569 | bfd *output_bfd; | |
1570 | struct bfd_link_info *info; | |
1571 | bfd *input_bfd; | |
1572 | asection *input_section; | |
1573 | bfd_byte *contents; | |
1574 | Elf_Internal_Rela *relocs; | |
1575 | Elf_Internal_Sym *local_syms; | |
1576 | asection **local_sections; | |
1577 | { | |
0451c93c | 1578 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
1579 | Elf_Internal_Shdr *symtab_hdr; |
1580 | struct elf_link_hash_entry **sym_hashes; | |
1581 | bfd_vma *local_got_offsets; | |
a85d7ed0 NC |
1582 | Elf_Internal_Rela *rel; |
1583 | Elf_Internal_Rela *relend; | |
1584 | ||
0451c93c | 1585 | htab = elf_s390_hash_table (info); |
a85d7ed0 NC |
1586 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
1587 | sym_hashes = elf_sym_hashes (input_bfd); | |
1588 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
1589 | ||
a85d7ed0 NC |
1590 | rel = relocs; |
1591 | relend = relocs + input_section->reloc_count; | |
1592 | for (; rel < relend; rel++) | |
1593 | { | |
1594 | int r_type; | |
1595 | reloc_howto_type *howto; | |
1596 | unsigned long r_symndx; | |
1597 | struct elf_link_hash_entry *h; | |
1598 | Elf_Internal_Sym *sym; | |
1599 | asection *sec; | |
0451c93c | 1600 | bfd_vma off; |
a85d7ed0 | 1601 | bfd_vma relocation; |
0451c93c | 1602 | boolean unresolved_reloc; |
a85d7ed0 NC |
1603 | bfd_reloc_status_type r; |
1604 | ||
1605 | r_type = ELF64_R_TYPE (rel->r_info); | |
0451c93c MS |
1606 | if (r_type == (int) R_390_GNU_VTINHERIT |
1607 | || r_type == (int) R_390_GNU_VTENTRY) | |
a85d7ed0 NC |
1608 | continue; |
1609 | if (r_type < 0 || r_type >= (int) R_390_max) | |
1610 | { | |
1611 | bfd_set_error (bfd_error_bad_value); | |
1612 | return false; | |
1613 | } | |
1614 | howto = elf_howto_table + r_type; | |
1615 | ||
1616 | r_symndx = ELF64_R_SYM (rel->r_info); | |
1617 | ||
1618 | if (info->relocateable) | |
1619 | { | |
1620 | /* This is a relocateable link. We don't have to change | |
1621 | anything, unless the reloc is against a section symbol, | |
1622 | in which case we have to adjust according to where the | |
1623 | section symbol winds up in the output section. */ | |
1624 | if (r_symndx < symtab_hdr->sh_info) | |
1625 | { | |
1626 | sym = local_syms + r_symndx; | |
1627 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
1628 | { | |
1629 | sec = local_sections[r_symndx]; | |
1630 | rel->r_addend += sec->output_offset + sym->st_value; | |
1631 | } | |
1632 | } | |
1633 | ||
1634 | continue; | |
1635 | } | |
1636 | ||
1637 | /* This is a final link. */ | |
1638 | h = NULL; | |
1639 | sym = NULL; | |
1640 | sec = NULL; | |
0451c93c | 1641 | unresolved_reloc = false; |
a85d7ed0 NC |
1642 | if (r_symndx < symtab_hdr->sh_info) |
1643 | { | |
1644 | sym = local_syms + r_symndx; | |
1645 | sec = local_sections[r_symndx]; | |
f8df10f4 | 1646 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
a85d7ed0 NC |
1647 | } |
1648 | else | |
1649 | { | |
1650 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1651 | while (h->root.type == bfd_link_hash_indirect | |
1652 | || h->root.type == bfd_link_hash_warning) | |
1653 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
0451c93c | 1654 | |
a85d7ed0 NC |
1655 | if (h->root.type == bfd_link_hash_defined |
1656 | || h->root.type == bfd_link_hash_defweak) | |
1657 | { | |
1658 | sec = h->root.u.def.section; | |
27018c3f | 1659 | if (sec->output_section == NULL) |
a85d7ed0 | 1660 | { |
0451c93c MS |
1661 | /* Set a flag that will be cleared later if we find a |
1662 | relocation value for this symbol. output_section | |
1663 | is typically NULL for symbols satisfied by a shared | |
1664 | library. */ | |
1665 | unresolved_reloc = true; | |
a85d7ed0 NC |
1666 | relocation = 0; |
1667 | } | |
1668 | else | |
1669 | relocation = (h->root.u.def.value | |
1670 | + sec->output_section->vma | |
1671 | + sec->output_offset); | |
1672 | } | |
1673 | else if (h->root.type == bfd_link_hash_undefweak) | |
1674 | relocation = 0; | |
671bae9c NC |
1675 | else if (info->shared |
1676 | && (!info->symbolic || info->allow_shlib_undefined) | |
a85d7ed0 NC |
1677 | && !info->no_undefined |
1678 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
1679 | relocation = 0; | |
1680 | else | |
1681 | { | |
1682 | if (! ((*info->callbacks->undefined_symbol) | |
1683 | (info, h->root.root.string, input_bfd, | |
0451c93c MS |
1684 | input_section, rel->r_offset, |
1685 | (!info->shared || info->no_undefined | |
1686 | || ELF_ST_VISIBILITY (h->other))))) | |
a85d7ed0 NC |
1687 | return false; |
1688 | relocation = 0; | |
1689 | } | |
1690 | } | |
1691 | ||
1692 | switch (r_type) | |
1693 | { | |
1694 | case R_390_GOT12: | |
1695 | case R_390_GOT16: | |
1696 | case R_390_GOT32: | |
1697 | case R_390_GOT64: | |
1698 | case R_390_GOTENT: | |
1699 | /* Relocation is to the entry for this symbol in the global | |
1700 | offset table. */ | |
0451c93c MS |
1701 | if (htab->sgot == NULL) |
1702 | abort (); | |
a85d7ed0 NC |
1703 | |
1704 | if (h != NULL) | |
1705 | { | |
0451c93c | 1706 | boolean dyn; |
a85d7ed0 NC |
1707 | |
1708 | off = h->got.offset; | |
0451c93c MS |
1709 | dyn = htab->elf.dynamic_sections_created; |
1710 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) | |
a85d7ed0 | 1711 | || (info->shared |
0451c93c MS |
1712 | && (info->symbolic |
1713 | || h->dynindx == -1 | |
1714 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) | |
a85d7ed0 NC |
1715 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) |
1716 | { | |
1717 | /* This is actually a static link, or it is a | |
1718 | -Bsymbolic link and the symbol is defined | |
1719 | locally, or the symbol was forced to be local | |
1720 | because of a version file. We must initialize | |
1721 | this entry in the global offset table. Since the | |
1722 | offset must always be a multiple of 2, we use the | |
1723 | least significant bit to record whether we have | |
1724 | initialized it already. | |
1725 | ||
1726 | When doing a dynamic link, we create a .rel.got | |
1727 | relocation entry to initialize the value. This | |
1728 | is done in the finish_dynamic_symbol routine. */ | |
1729 | if ((off & 1) != 0) | |
1730 | off &= ~1; | |
1731 | else | |
1732 | { | |
1733 | bfd_put_64 (output_bfd, relocation, | |
0451c93c | 1734 | htab->sgot->contents + off); |
a85d7ed0 NC |
1735 | h->got.offset |= 1; |
1736 | } | |
1737 | } | |
0451c93c MS |
1738 | else |
1739 | unresolved_reloc = false; | |
a85d7ed0 NC |
1740 | } |
1741 | else | |
1742 | { | |
0451c93c MS |
1743 | if (local_got_offsets == NULL) |
1744 | abort (); | |
a85d7ed0 NC |
1745 | |
1746 | off = local_got_offsets[r_symndx]; | |
1747 | ||
1748 | /* The offset must always be a multiple of 8. We use | |
1749 | the least significant bit to record whether we have | |
1750 | already generated the necessary reloc. */ | |
1751 | if ((off & 1) != 0) | |
1752 | off &= ~1; | |
1753 | else | |
1754 | { | |
0451c93c MS |
1755 | bfd_put_64 (output_bfd, relocation, |
1756 | htab->sgot->contents + off); | |
a85d7ed0 NC |
1757 | |
1758 | if (info->shared) | |
1759 | { | |
1760 | asection *srelgot; | |
1761 | Elf_Internal_Rela outrel; | |
0451c93c | 1762 | Elf64_External_Rela *loc; |
a85d7ed0 | 1763 | |
0451c93c MS |
1764 | srelgot = htab->srelgot; |
1765 | if (srelgot == NULL) | |
1766 | abort (); | |
a85d7ed0 | 1767 | |
0451c93c MS |
1768 | outrel.r_offset = (htab->sgot->output_section->vma |
1769 | + htab->sgot->output_offset | |
a85d7ed0 NC |
1770 | + off); |
1771 | outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE); | |
1772 | outrel.r_addend = relocation; | |
0451c93c MS |
1773 | loc = (Elf64_External_Rela *) srelgot->contents; |
1774 | loc += srelgot->reloc_count++; | |
1775 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
a85d7ed0 NC |
1776 | } |
1777 | ||
1778 | local_got_offsets[r_symndx] |= 1; | |
1779 | } | |
a85d7ed0 NC |
1780 | } |
1781 | ||
0451c93c MS |
1782 | if (off >= (bfd_vma) -2) |
1783 | abort (); | |
1784 | ||
1785 | relocation = htab->sgot->output_offset + off; | |
1786 | ||
a85d7ed0 NC |
1787 | /* |
1788 | * For @GOTENT the relocation is against the offset between | |
1789 | * the instruction and the symbols entry in the GOT and not | |
1790 | * between the start of the GOT and the symbols entry. We | |
1791 | * add the vma of the GOT to get the correct value. | |
1792 | */ | |
1793 | if (r_type == R_390_GOTENT) | |
0451c93c | 1794 | relocation += htab->sgot->output_section->vma; |
a85d7ed0 NC |
1795 | |
1796 | break; | |
99c79b2e | 1797 | |
a85d7ed0 NC |
1798 | case R_390_GOTOFF: |
1799 | /* Relocation is relative to the start of the global offset | |
1800 | table. */ | |
1801 | ||
a85d7ed0 NC |
1802 | /* Note that sgot->output_offset is not involved in this |
1803 | calculation. We always want the start of .got. If we | |
1804 | defined _GLOBAL_OFFSET_TABLE in a different way, as is | |
1805 | permitted by the ABI, we might have to change this | |
1806 | calculation. */ | |
0451c93c | 1807 | relocation -= htab->sgot->output_section->vma; |
a85d7ed0 NC |
1808 | |
1809 | break; | |
1810 | ||
1811 | case R_390_GOTPC: | |
1812 | case R_390_GOTPCDBL: | |
1813 | /* Use global offset table as symbol value. */ | |
0451c93c MS |
1814 | relocation = htab->sgot->output_section->vma; |
1815 | unresolved_reloc = false; | |
1816 | break; | |
a85d7ed0 NC |
1817 | |
1818 | case R_390_PLT16DBL: | |
1819 | case R_390_PLT32: | |
1820 | case R_390_PLT32DBL: | |
1821 | case R_390_PLT64: | |
1822 | /* Relocation is to the entry for this symbol in the | |
1823 | procedure linkage table. */ | |
1824 | ||
1825 | /* Resolve a PLT32 reloc against a local symbol directly, | |
1826 | without using the procedure linkage table. */ | |
1827 | if (h == NULL) | |
1828 | break; | |
1829 | ||
0451c93c MS |
1830 | if (h->plt.offset == (bfd_vma) -1 |
1831 | || htab->splt == NULL) | |
a85d7ed0 NC |
1832 | { |
1833 | /* We didn't make a PLT entry for this symbol. This | |
1834 | happens when statically linking PIC code, or when | |
1835 | using -Bsymbolic. */ | |
1836 | break; | |
1837 | } | |
1838 | ||
0451c93c MS |
1839 | relocation = (htab->splt->output_section->vma |
1840 | + htab->splt->output_offset | |
a85d7ed0 | 1841 | + h->plt.offset); |
0451c93c | 1842 | unresolved_reloc = false; |
a85d7ed0 NC |
1843 | break; |
1844 | ||
1845 | case R_390_8: | |
1846 | case R_390_16: | |
1847 | case R_390_32: | |
1848 | case R_390_64: | |
1849 | case R_390_PC16: | |
1850 | case R_390_PC16DBL: | |
1851 | case R_390_PC32: | |
1852 | case R_390_PC32DBL: | |
1853 | case R_390_PC64: | |
ec338859 AM |
1854 | /* r_symndx will be zero only for relocs against symbols |
1855 | from removed linkonce sections, or sections discarded by | |
1856 | a linker script. */ | |
1857 | if (r_symndx == 0 | |
1858 | || (input_section->flags & SEC_ALLOC) == 0) | |
1859 | break; | |
1860 | ||
0451c93c | 1861 | if ((info->shared |
0451c93c MS |
1862 | && ((r_type != R_390_PC16 |
1863 | && r_type != R_390_PC16DBL | |
1864 | && r_type != R_390_PC32 | |
1865 | && r_type != R_390_PC32DBL | |
1866 | && r_type != R_390_PC64) | |
1867 | || (h != NULL | |
1868 | && h->dynindx != -1 | |
1869 | && (! info->symbolic | |
1870 | || (h->elf_link_hash_flags | |
1871 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
1872 | || (!info->shared | |
0451c93c MS |
1873 | && h != NULL |
1874 | && h->dynindx != -1 | |
1875 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
1876 | && (((h->elf_link_hash_flags | |
1877 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
1878 | && (h->elf_link_hash_flags | |
1879 | & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
1880 | || h->root.type == bfd_link_hash_undefweak | |
1881 | || h->root.type == bfd_link_hash_undefined))) | |
a85d7ed0 NC |
1882 | { |
1883 | Elf_Internal_Rela outrel; | |
1884 | boolean skip, relocate; | |
0451c93c MS |
1885 | asection *sreloc; |
1886 | Elf64_External_Rela *loc; | |
a85d7ed0 NC |
1887 | |
1888 | /* When generating a shared object, these relocations | |
1889 | are copied into the output file to be resolved at run | |
1890 | time. */ | |
1891 | ||
a85d7ed0 NC |
1892 | skip = false; |
1893 | ||
c629eae0 JJ |
1894 | outrel.r_offset = |
1895 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
1896 | rel->r_offset); | |
1897 | if (outrel.r_offset == (bfd_vma) -1) | |
1898 | skip = true; | |
a85d7ed0 NC |
1899 | |
1900 | outrel.r_offset += (input_section->output_section->vma | |
1901 | + input_section->output_offset); | |
1902 | ||
1903 | if (skip) | |
1904 | { | |
1905 | memset (&outrel, 0, sizeof outrel); | |
1906 | relocate = false; | |
1907 | } | |
0451c93c MS |
1908 | else if (h != NULL |
1909 | && h->dynindx != -1 | |
1910 | && (r_type == R_390_PC16 | |
1911 | || r_type == R_390_PC16DBL | |
1912 | || r_type == R_390_PC32 | |
1913 | || r_type == R_390_PC32DBL | |
1914 | || r_type == R_390_PC64 | |
1915 | || !info->shared | |
1916 | || !info->symbolic | |
1917 | || (h->elf_link_hash_flags | |
1918 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
a85d7ed0 | 1919 | { |
a85d7ed0 NC |
1920 | relocate = false; |
1921 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); | |
27018c3f | 1922 | outrel.r_addend = rel->r_addend; |
a85d7ed0 NC |
1923 | } |
1924 | else | |
1925 | { | |
0451c93c MS |
1926 | /* This symbol is local, or marked to become local. */ |
1927 | relocate = true; | |
1928 | outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE); | |
1929 | outrel.r_addend = relocation + rel->r_addend; | |
1930 | } | |
a85d7ed0 | 1931 | |
0451c93c MS |
1932 | sreloc = elf_section_data (input_section)->sreloc; |
1933 | if (sreloc == NULL) | |
1934 | abort (); | |
1935 | ||
1936 | loc = (Elf64_External_Rela *) sreloc->contents; | |
1937 | loc += sreloc->reloc_count++; | |
1938 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
a85d7ed0 NC |
1939 | |
1940 | /* If this reloc is against an external symbol, we do | |
1941 | not want to fiddle with the addend. Otherwise, we | |
1942 | need to include the symbol value so that it becomes | |
1943 | an addend for the dynamic reloc. */ | |
1944 | if (! relocate) | |
1945 | continue; | |
1946 | } | |
1947 | ||
1948 | break; | |
1949 | ||
1950 | default: | |
1951 | break; | |
1952 | } | |
1953 | ||
0451c93c MS |
1954 | if (unresolved_reloc |
1955 | && !(info->shared | |
1956 | && (input_section->flags & SEC_DEBUGGING) != 0 | |
1957 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) | |
1958 | (*_bfd_error_handler) | |
1959 | (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"), | |
1960 | bfd_archive_filename (input_bfd), | |
1961 | bfd_get_section_name (input_bfd, input_section), | |
1962 | (long) rel->r_offset, | |
1963 | h->root.root.string); | |
1964 | ||
a85d7ed0 NC |
1965 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
1966 | contents, rel->r_offset, | |
1967 | relocation, rel->r_addend); | |
1968 | ||
1969 | if (r != bfd_reloc_ok) | |
1970 | { | |
0451c93c | 1971 | const char *name; |
ec338859 | 1972 | |
0451c93c MS |
1973 | if (h != NULL) |
1974 | name = h->root.root.string; | |
1975 | else | |
a85d7ed0 | 1976 | { |
0451c93c MS |
1977 | name = bfd_elf_string_from_elf_section (input_bfd, |
1978 | symtab_hdr->sh_link, | |
1979 | sym->st_name); | |
1980 | if (name == NULL) | |
1981 | return false; | |
1982 | if (*name == '\0') | |
1983 | name = bfd_section_name (input_bfd, sec); | |
1984 | } | |
ec338859 | 1985 | |
0451c93c MS |
1986 | if (r == bfd_reloc_overflow) |
1987 | { | |
ec338859 | 1988 | |
0451c93c MS |
1989 | if (! ((*info->callbacks->reloc_overflow) |
1990 | (info, name, howto->name, (bfd_vma) 0, | |
1991 | input_bfd, input_section, rel->r_offset))) | |
1992 | return false; | |
1993 | } | |
1994 | else | |
1995 | { | |
1996 | (*_bfd_error_handler) | |
1997 | (_("%s(%s+0x%lx): reloc against `%s': error %d"), | |
1998 | bfd_archive_filename (input_bfd), | |
1999 | bfd_get_section_name (input_bfd, input_section), | |
2000 | (long) rel->r_offset, name, (int) r); | |
2001 | return false; | |
a85d7ed0 NC |
2002 | } |
2003 | } | |
2004 | } | |
2005 | ||
2006 | return true; | |
2007 | } | |
2008 | ||
2009 | /* Finish up dynamic symbol handling. We set the contents of various | |
2010 | dynamic sections here. */ | |
2011 | ||
2012 | static boolean | |
2013 | elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym) | |
2014 | bfd *output_bfd; | |
2015 | struct bfd_link_info *info; | |
2016 | struct elf_link_hash_entry *h; | |
2017 | Elf_Internal_Sym *sym; | |
2018 | { | |
0451c93c | 2019 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 | 2020 | |
0451c93c | 2021 | htab = elf_s390_hash_table (info); |
a85d7ed0 NC |
2022 | |
2023 | if (h->plt.offset != (bfd_vma) -1) | |
2024 | { | |
a85d7ed0 | 2025 | bfd_vma plt_index; |
0451c93c MS |
2026 | bfd_vma got_offset; |
2027 | Elf_Internal_Rela rela; | |
2028 | Elf64_External_Rela *loc; | |
a85d7ed0 NC |
2029 | |
2030 | /* This symbol has an entry in the procedure linkage table. Set | |
2031 | it up. */ | |
2032 | ||
0451c93c MS |
2033 | if (h->dynindx == -1 |
2034 | || htab->splt == NULL | |
2035 | || htab->sgotplt == NULL | |
2036 | || htab->srelplt == NULL) | |
2037 | abort (); | |
a85d7ed0 | 2038 | |
99c79b2e | 2039 | /* Calc. index no. |
a85d7ed0 NC |
2040 | Current offset - size first entry / entry size. */ |
2041 | plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE; | |
2042 | ||
2043 | /* Offset in GOT is PLT index plus GOT headers(3) times 8, | |
2044 | addr & GOT addr. */ | |
2045 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; | |
2046 | ||
2047 | /* Fill in the blueprint of a PLT. */ | |
0451c93c MS |
2048 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0, |
2049 | htab->splt->contents + h->plt.offset); | |
2050 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1, | |
2051 | htab->splt->contents + h->plt.offset + 4); | |
2052 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2, | |
2053 | htab->splt->contents + h->plt.offset + 8); | |
2054 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3, | |
2055 | htab->splt->contents + h->plt.offset + 12); | |
2056 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4, | |
2057 | htab->splt->contents + h->plt.offset + 16); | |
2058 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD5, | |
2059 | htab->splt->contents + h->plt.offset + 20); | |
2060 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD6, | |
2061 | htab->splt->contents + h->plt.offset + 24); | |
2062 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD7, | |
2063 | htab->splt->contents + h->plt.offset + 28); | |
a85d7ed0 NC |
2064 | /* Fixup the relative address to the GOT entry */ |
2065 | bfd_put_32 (output_bfd, | |
0451c93c MS |
2066 | (htab->sgotplt->output_section->vma + |
2067 | htab->sgotplt->output_offset + got_offset | |
2068 | - (htab->splt->output_section->vma + h->plt.offset))/2, | |
2069 | htab->splt->contents + h->plt.offset + 2); | |
a85d7ed0 NC |
2070 | /* Fixup the relative branch to PLT 0 */ |
2071 | bfd_put_32 (output_bfd, - (PLT_FIRST_ENTRY_SIZE + | |
2072 | (PLT_ENTRY_SIZE * plt_index) + 22)/2, | |
0451c93c | 2073 | htab->splt->contents + h->plt.offset + 24); |
a85d7ed0 NC |
2074 | /* Fixup offset into symbol table */ |
2075 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf64_External_Rela), | |
0451c93c | 2076 | htab->splt->contents + h->plt.offset + 28); |
a85d7ed0 NC |
2077 | |
2078 | /* Fill in the entry in the global offset table. | |
2079 | Points to instruction after GOT offset. */ | |
2080 | bfd_put_64 (output_bfd, | |
0451c93c MS |
2081 | (htab->splt->output_section->vma |
2082 | + htab->splt->output_offset | |
a85d7ed0 NC |
2083 | + h->plt.offset |
2084 | + 14), | |
0451c93c | 2085 | htab->sgotplt->contents + got_offset); |
a85d7ed0 | 2086 | |
0451c93c MS |
2087 | /* Fill in the entry in the .rela.plt section. */ |
2088 | rela.r_offset = (htab->sgotplt->output_section->vma | |
2089 | + htab->sgotplt->output_offset | |
2090 | + got_offset); | |
2091 | rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT); | |
2092 | rela.r_addend = 0; | |
2093 | loc = (Elf64_External_Rela *) htab->srelplt->contents + plt_index; | |
2094 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
a85d7ed0 NC |
2095 | |
2096 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
2097 | { | |
2098 | /* Mark the symbol as undefined, rather than as defined in | |
0451c93c MS |
2099 | the .plt section. Leave the value alone. This is a clue |
2100 | for the dynamic linker, to make function pointer | |
2101 | comparisons work between an application and shared | |
2102 | library. */ | |
a85d7ed0 NC |
2103 | sym->st_shndx = SHN_UNDEF; |
2104 | } | |
2105 | } | |
2106 | ||
2107 | if (h->got.offset != (bfd_vma) -1) | |
2108 | { | |
a85d7ed0 | 2109 | Elf_Internal_Rela rela; |
0451c93c | 2110 | Elf64_External_Rela *loc; |
a85d7ed0 NC |
2111 | |
2112 | /* This symbol has an entry in the global offset table. Set it | |
2113 | up. */ | |
2114 | ||
0451c93c MS |
2115 | if (htab->sgot == NULL || htab->srelgot == NULL) |
2116 | abort (); | |
a85d7ed0 | 2117 | |
0451c93c MS |
2118 | rela.r_offset = (htab->sgot->output_section->vma |
2119 | + htab->sgot->output_offset | |
dc810e39 | 2120 | + (h->got.offset &~ (bfd_vma) 1)); |
a85d7ed0 NC |
2121 | |
2122 | /* If this is a static link, or it is a -Bsymbolic link and the | |
2123 | symbol is defined locally or was forced to be local because | |
2124 | of a version file, we just want to emit a RELATIVE reloc. | |
2125 | The entry in the global offset table will already have been | |
2126 | initialized in the relocate_section function. */ | |
0451c93c MS |
2127 | if (info->shared |
2128 | && (info->symbolic | |
2129 | || h->dynindx == -1 | |
2130 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) | |
2131 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) | |
a85d7ed0 | 2132 | { |
0451c93c | 2133 | BFD_ASSERT((h->got.offset & 1) != 0); |
a85d7ed0 NC |
2134 | rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE); |
2135 | rela.r_addend = (h->root.u.def.value | |
2136 | + h->root.u.def.section->output_section->vma | |
2137 | + h->root.u.def.section->output_offset); | |
2138 | } | |
2139 | else | |
2140 | { | |
2141 | BFD_ASSERT((h->got.offset & 1) == 0); | |
0451c93c | 2142 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.offset); |
a85d7ed0 NC |
2143 | rela.r_info = ELF64_R_INFO (h->dynindx, R_390_GLOB_DAT); |
2144 | rela.r_addend = 0; | |
2145 | } | |
2146 | ||
0451c93c MS |
2147 | loc = (Elf64_External_Rela *) htab->srelgot->contents; |
2148 | loc += htab->srelgot->reloc_count++; | |
2149 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
a85d7ed0 NC |
2150 | } |
2151 | ||
2152 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
2153 | { | |
a85d7ed0 | 2154 | Elf_Internal_Rela rela; |
0451c93c | 2155 | Elf64_External_Rela *loc; |
a85d7ed0 NC |
2156 | |
2157 | /* This symbols needs a copy reloc. Set it up. */ | |
2158 | ||
0451c93c MS |
2159 | if (h->dynindx == -1 |
2160 | || (h->root.type != bfd_link_hash_defined | |
2161 | && h->root.type != bfd_link_hash_defweak) | |
2162 | || htab->srelbss == NULL) | |
2163 | abort (); | |
a85d7ed0 NC |
2164 | |
2165 | rela.r_offset = (h->root.u.def.value | |
2166 | + h->root.u.def.section->output_section->vma | |
2167 | + h->root.u.def.section->output_offset); | |
2168 | rela.r_info = ELF64_R_INFO (h->dynindx, R_390_COPY); | |
2169 | rela.r_addend = 0; | |
0451c93c MS |
2170 | loc = (Elf64_External_Rela *) htab->srelbss->contents; |
2171 | loc += htab->srelbss->reloc_count++; | |
2172 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
a85d7ed0 NC |
2173 | } |
2174 | ||
2175 | /* Mark some specially defined symbols as absolute. */ | |
2176 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
2177 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 | |
2178 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) | |
2179 | sym->st_shndx = SHN_ABS; | |
2180 | ||
2181 | return true; | |
2182 | } | |
2183 | ||
0451c93c MS |
2184 | /* Used to decide how to sort relocs in an optimal manner for the |
2185 | dynamic linker, before writing them out. */ | |
2186 | ||
2187 | static enum elf_reloc_type_class | |
2188 | elf_s390_reloc_type_class (rela) | |
2189 | const Elf_Internal_Rela *rela; | |
2190 | { | |
2191 | switch ((int) ELF64_R_TYPE (rela->r_info)) | |
2192 | { | |
2193 | case R_390_RELATIVE: | |
2194 | return reloc_class_relative; | |
2195 | case R_390_JMP_SLOT: | |
2196 | return reloc_class_plt; | |
2197 | case R_390_COPY: | |
2198 | return reloc_class_copy; | |
2199 | default: | |
2200 | return reloc_class_normal; | |
2201 | } | |
2202 | } | |
2203 | ||
a85d7ed0 NC |
2204 | /* Finish up the dynamic sections. */ |
2205 | ||
2206 | static boolean | |
2207 | elf_s390_finish_dynamic_sections (output_bfd, info) | |
2208 | bfd *output_bfd; | |
2209 | struct bfd_link_info *info; | |
2210 | { | |
0451c93c | 2211 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
2212 | bfd *dynobj; |
2213 | asection *sdyn; | |
a85d7ed0 | 2214 | |
0451c93c MS |
2215 | htab = elf_s390_hash_table (info); |
2216 | dynobj = htab->elf.dynobj; | |
a85d7ed0 NC |
2217 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
2218 | ||
0451c93c | 2219 | if (htab->elf.dynamic_sections_created) |
a85d7ed0 | 2220 | { |
a85d7ed0 NC |
2221 | Elf64_External_Dyn *dyncon, *dynconend; |
2222 | ||
0451c93c MS |
2223 | if (sdyn == NULL || htab->sgot == NULL) |
2224 | abort (); | |
a85d7ed0 NC |
2225 | |
2226 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
2227 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
2228 | for (; dyncon < dynconend; dyncon++) | |
2229 | { | |
2230 | Elf_Internal_Dyn dyn; | |
a85d7ed0 | 2231 | asection *s; |
ec338859 | 2232 | |
a85d7ed0 | 2233 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); |
ec338859 | 2234 | |
a85d7ed0 NC |
2235 | switch (dyn.d_tag) |
2236 | { | |
2237 | default: | |
0451c93c | 2238 | continue; |
ec338859 | 2239 | |
a85d7ed0 | 2240 | case DT_PLTGOT: |
0451c93c MS |
2241 | dyn.d_un.d_ptr = htab->sgot->output_section->vma; |
2242 | break; | |
ec338859 | 2243 | |
a85d7ed0 | 2244 | case DT_JMPREL: |
0451c93c | 2245 | dyn.d_un.d_ptr = htab->srelplt->output_section->vma; |
a85d7ed0 | 2246 | break; |
ec338859 | 2247 | |
a85d7ed0 | 2248 | case DT_PLTRELSZ: |
0451c93c | 2249 | s = htab->srelplt->output_section; |
a85d7ed0 NC |
2250 | if (s->_cooked_size != 0) |
2251 | dyn.d_un.d_val = s->_cooked_size; | |
2252 | else | |
2253 | dyn.d_un.d_val = s->_raw_size; | |
a85d7ed0 | 2254 | break; |
ec338859 | 2255 | |
a85d7ed0 NC |
2256 | case DT_RELASZ: |
2257 | /* The procedure linkage table relocs (DT_JMPREL) should | |
2258 | not be included in the overall relocs (DT_RELA). | |
2259 | Therefore, we override the DT_RELASZ entry here to | |
2260 | make it not include the JMPREL relocs. Since the | |
2261 | linker script arranges for .rela.plt to follow all | |
2262 | other relocation sections, we don't have to worry | |
2263 | about changing the DT_RELA entry. */ | |
0451c93c MS |
2264 | s = htab->srelplt->output_section; |
2265 | if (s->_cooked_size != 0) | |
2266 | dyn.d_un.d_val -= s->_cooked_size; | |
2267 | else | |
2268 | dyn.d_un.d_val -= s->_raw_size; | |
a85d7ed0 NC |
2269 | break; |
2270 | } | |
0451c93c MS |
2271 | |
2272 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | |
a85d7ed0 NC |
2273 | } |
2274 | ||
2275 | /* Fill in the special first entry in the procedure linkage table. */ | |
0451c93c | 2276 | if (htab->splt && htab->splt->_raw_size > 0) |
a85d7ed0 NC |
2277 | { |
2278 | /* fill in blueprint for plt 0 entry */ | |
0451c93c MS |
2279 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD0, |
2280 | htab->splt->contents ); | |
2281 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1, | |
2282 | htab->splt->contents +4 ); | |
2283 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3, | |
2284 | htab->splt->contents +12 ); | |
2285 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4, | |
2286 | htab->splt->contents +16 ); | |
2287 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5, | |
2288 | htab->splt->contents +20 ); | |
2289 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD6, | |
2290 | htab->splt->contents + 24); | |
2291 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD7, | |
2292 | htab->splt->contents + 28 ); | |
a85d7ed0 NC |
2293 | /* Fixup relative address to start of GOT */ |
2294 | bfd_put_32 (output_bfd, | |
0451c93c MS |
2295 | (htab->sgotplt->output_section->vma + |
2296 | htab->sgotplt->output_offset | |
2297 | - htab->splt->output_section->vma - 6)/2, | |
2298 | htab->splt->contents + 8); | |
a85d7ed0 | 2299 | } |
0451c93c MS |
2300 | elf_section_data (htab->splt->output_section) |
2301 | ->this_hdr.sh_entsize = PLT_ENTRY_SIZE; | |
a85d7ed0 NC |
2302 | } |
2303 | ||
0451c93c | 2304 | if (htab->sgotplt) |
a85d7ed0 | 2305 | { |
0451c93c MS |
2306 | /* Fill in the first three entries in the global offset table. */ |
2307 | if (htab->sgotplt->_raw_size > 0) | |
2308 | { | |
2309 | bfd_put_64 (output_bfd, | |
2310 | (sdyn == NULL ? (bfd_vma) 0 | |
2311 | : sdyn->output_section->vma + sdyn->output_offset), | |
2312 | htab->sgotplt->contents); | |
2313 | /* One entry for shared object struct ptr. */ | |
2314 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8); | |
2315 | /* One entry for _dl_runtime_resolve. */ | |
2316 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 12); | |
2317 | } | |
a85d7ed0 | 2318 | |
0451c93c MS |
2319 | elf_section_data (htab->sgot->output_section) |
2320 | ->this_hdr.sh_entsize = 8; | |
2321 | } | |
a85d7ed0 NC |
2322 | return true; |
2323 | } | |
2324 | ||
2325 | static boolean | |
2326 | elf_s390_object_p (abfd) | |
2327 | bfd *abfd; | |
2328 | { | |
2329 | return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_esame); | |
2330 | } | |
2331 | ||
2332 | /* | |
2333 | * Why was the hash table entry size definition changed from | |
2334 | * ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and | |
2335 | * this is the only reason for the s390_elf64_size_info structure. | |
2336 | */ | |
2337 | ||
2338 | const struct elf_size_info s390_elf64_size_info = | |
2339 | { | |
2340 | sizeof (Elf64_External_Ehdr), | |
2341 | sizeof (Elf64_External_Phdr), | |
2342 | sizeof (Elf64_External_Shdr), | |
2343 | sizeof (Elf64_External_Rel), | |
2344 | sizeof (Elf64_External_Rela), | |
2345 | sizeof (Elf64_External_Sym), | |
2346 | sizeof (Elf64_External_Dyn), | |
2347 | sizeof (Elf_External_Note), | |
2348 | 8, /* hash-table entry size */ | |
2349 | 1, /* internal relocations per external relocations */ | |
2350 | 64, /* arch_size */ | |
2351 | 8, /* file_align */ | |
2352 | ELFCLASS64, EV_CURRENT, | |
2353 | bfd_elf64_write_out_phdrs, | |
2354 | bfd_elf64_write_shdrs_and_ehdr, | |
2355 | bfd_elf64_write_relocs, | |
2356 | bfd_elf64_swap_symbol_out, | |
2357 | bfd_elf64_slurp_reloc_table, | |
2358 | bfd_elf64_slurp_symbol_table, | |
2359 | bfd_elf64_swap_dyn_in, | |
2360 | bfd_elf64_swap_dyn_out, | |
2361 | NULL, | |
2362 | NULL, | |
2363 | NULL, | |
2364 | NULL | |
2365 | }; | |
2366 | ||
2367 | #define TARGET_BIG_SYM bfd_elf64_s390_vec | |
2368 | #define TARGET_BIG_NAME "elf64-s390" | |
2369 | #define ELF_ARCH bfd_arch_s390 | |
2370 | #define ELF_MACHINE_CODE EM_S390 | |
2371 | #define ELF_MACHINE_ALT1 EM_S390_OLD | |
2372 | #define ELF_MAXPAGESIZE 0x1000 | |
2373 | ||
2374 | #define elf_backend_size_info s390_elf64_size_info | |
2375 | ||
2376 | #define elf_backend_can_gc_sections 1 | |
51b64d56 | 2377 | #define elf_backend_can_refcount 1 |
a85d7ed0 NC |
2378 | #define elf_backend_want_got_plt 1 |
2379 | #define elf_backend_plt_readonly 1 | |
2380 | #define elf_backend_want_plt_sym 0 | |
2381 | #define elf_backend_got_header_size 24 | |
2382 | #define elf_backend_plt_header_size PLT_ENTRY_SIZE | |
2383 | ||
2384 | #define elf_info_to_howto elf_s390_info_to_howto | |
2385 | ||
a85d7ed0 NC |
2386 | #define bfd_elf64_bfd_is_local_label_name elf_s390_is_local_label_name |
2387 | #define bfd_elf64_bfd_link_hash_table_create elf_s390_link_hash_table_create | |
2388 | #define bfd_elf64_bfd_reloc_type_lookup elf_s390_reloc_type_lookup | |
2389 | ||
2390 | #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol | |
2391 | #define elf_backend_check_relocs elf_s390_check_relocs | |
0451c93c MS |
2392 | #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol |
2393 | #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections | |
a85d7ed0 NC |
2394 | #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections |
2395 | #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol | |
2396 | #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook | |
2397 | #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook | |
0451c93c | 2398 | #define elf_backend_reloc_type_class elf_s390_reloc_type_class |
a85d7ed0 NC |
2399 | #define elf_backend_relocate_section elf_s390_relocate_section |
2400 | #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections | |
29c2fb7c | 2401 | #define elf_backend_reloc_type_class elf_s390_reloc_type_class |
a85d7ed0 NC |
2402 | |
2403 | #define elf_backend_object_p elf_s390_object_p | |
2404 | ||
2405 | #include "elf64-target.h" |