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