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