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