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