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