1 /* IBM S/390-specific support for 32-bit ELF
2 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Carl B. Pedersen and Martin Schwidefsky.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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
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 bfd_boolean elf_s390_is_local_label_name
33 PARAMS ((bfd *, const char *));
34 static struct bfd_hash_entry *link_hash_newfunc
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
38 static bfd_boolean create_got_section
39 PARAMS((bfd *, struct bfd_link_info *));
40 static bfd_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_backend_data *, struct elf_link_hash_entry *,
44 struct elf_link_hash_entry *));
45 static bfd_boolean elf_s390_check_relocs
46 PARAMS ((bfd *, struct bfd_link_info *, asection *,
47 const Elf_Internal_Rela *));
48 static asection *elf_s390_gc_mark_hook
49 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
50 struct elf_link_hash_entry *, Elf_Internal_Sym *));
51 static bfd_boolean elf_s390_gc_sweep_hook
52 PARAMS ((bfd *, struct bfd_link_info *, asection *,
53 const Elf_Internal_Rela *));
54 struct elf_s390_link_hash_entry;
55 static void elf_s390_adjust_gotplt
56 PARAMS ((struct elf_s390_link_hash_entry *));
57 static bfd_boolean elf_s390_adjust_dynamic_symbol
58 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
59 static bfd_boolean allocate_dynrelocs
60 PARAMS ((struct elf_link_hash_entry *, PTR));
61 static bfd_boolean readonly_dynrelocs
62 PARAMS ((struct elf_link_hash_entry *, PTR));
63 static bfd_boolean elf_s390_size_dynamic_sections
64 PARAMS ((bfd *, struct bfd_link_info *));
65 static bfd_boolean elf_s390_relocate_section
66 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
67 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
68 static bfd_boolean elf_s390_finish_dynamic_symbol
69 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
71 static enum elf_reloc_type_class elf_s390_reloc_type_class
72 PARAMS ((const Elf_Internal_Rela *));
73 static bfd_boolean elf_s390_finish_dynamic_sections
74 PARAMS ((bfd *, struct bfd_link_info *));
75 static bfd_boolean elf_s390_object_p
77 static bfd_boolean elf_s390_grok_prstatus
78 PARAMS ((bfd *, Elf_Internal_Note *));
82 /* The relocation "howto" table. */
84 static reloc_howto_type elf_howto_table[] =
86 HOWTO (R_390_NONE, /* type */
88 0, /* size (0 = byte, 1 = short, 2 = long) */
90 FALSE, /* pc_relative */
92 complain_overflow_dont, /* complain_on_overflow */
93 bfd_elf_generic_reloc, /* special_function */
94 "R_390_NONE", /* name */
95 FALSE, /* partial_inplace */
98 FALSE), /* pcrel_offset */
100 HOWTO(R_390_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
101 bfd_elf_generic_reloc, "R_390_8", FALSE, 0,0x000000ff, FALSE),
102 HOWTO(R_390_12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
103 bfd_elf_generic_reloc, "R_390_12", FALSE, 0,0x00000fff, FALSE),
104 HOWTO(R_390_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
105 bfd_elf_generic_reloc, "R_390_16", FALSE, 0,0x0000ffff, FALSE),
106 HOWTO(R_390_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
107 bfd_elf_generic_reloc, "R_390_32", FALSE, 0,0xffffffff, FALSE),
108 HOWTO(R_390_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
109 bfd_elf_generic_reloc, "R_390_PC32", FALSE, 0,0xffffffff, TRUE),
110 HOWTO(R_390_GOT12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
111 bfd_elf_generic_reloc, "R_390_GOT12", FALSE, 0,0x00000fff, FALSE),
112 HOWTO(R_390_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
113 bfd_elf_generic_reloc, "R_390_GOT32", FALSE, 0,0xffffffff, FALSE),
114 HOWTO(R_390_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
115 bfd_elf_generic_reloc, "R_390_PLT32", FALSE, 0,0xffffffff, TRUE),
116 HOWTO(R_390_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
117 bfd_elf_generic_reloc, "R_390_COPY", FALSE, 0,0xffffffff, FALSE),
118 HOWTO(R_390_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
119 bfd_elf_generic_reloc, "R_390_GLOB_DAT", FALSE, 0,0xffffffff, FALSE),
120 HOWTO(R_390_JMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
121 bfd_elf_generic_reloc, "R_390_JMP_SLOT", FALSE, 0,0xffffffff, FALSE),
122 HOWTO(R_390_RELATIVE, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
123 bfd_elf_generic_reloc, "R_390_RELATIVE", FALSE, 0,0xffffffff, FALSE),
124 HOWTO(R_390_GOTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
125 bfd_elf_generic_reloc, "R_390_GOTOFF32", FALSE, 0,0xffffffff, FALSE),
126 HOWTO(R_390_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
127 bfd_elf_generic_reloc, "R_390_GOTPC", FALSE, 0,0xffffffff, TRUE),
128 HOWTO(R_390_GOT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
129 bfd_elf_generic_reloc, "R_390_GOT16", FALSE, 0,0x0000ffff, FALSE),
130 HOWTO(R_390_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
131 bfd_elf_generic_reloc, "R_390_PC16", FALSE, 0,0x0000ffff, TRUE),
132 HOWTO(R_390_PC16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield,
133 bfd_elf_generic_reloc, "R_390_PC16DBL", FALSE, 0,0x0000ffff, TRUE),
134 HOWTO(R_390_PLT16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield,
135 bfd_elf_generic_reloc, "R_390_PLT16DBL", FALSE, 0,0x0000ffff, TRUE),
136 HOWTO(R_390_PC32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
137 bfd_elf_generic_reloc, "R_390_PC32DBL", FALSE, 0,0xffffffff, TRUE),
138 HOWTO(R_390_PLT32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
139 bfd_elf_generic_reloc, "R_390_PLT32DBL", FALSE, 0,0xffffffff, TRUE),
140 HOWTO(R_390_GOTPCDBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
141 bfd_elf_generic_reloc, "R_390_GOTPCDBL", FALSE, 0,0xffffffff, TRUE),
142 EMPTY_HOWTO (R_390_64), /* Empty entry for R_390_64. */
143 EMPTY_HOWTO (R_390_PC64), /* Empty entry for R_390_PC64. */
144 EMPTY_HOWTO (R_390_GOT64), /* Empty entry for R_390_GOT64. */
145 EMPTY_HOWTO (R_390_PLT64), /* Empty entry for R_390_PLT64. */
146 HOWTO(R_390_GOTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
147 bfd_elf_generic_reloc, "R_390_GOTENT", FALSE, 0,0xffffffff, TRUE),
148 HOWTO(R_390_GOTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
149 bfd_elf_generic_reloc, "R_390_GOTOFF16", FALSE, 0,0x0000ffff, FALSE),
150 EMPTY_HOWTO (R_390_GOTOFF64), /* Empty entry for R_390_GOTOFF64. */
151 HOWTO(R_390_GOTPLT12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
152 bfd_elf_generic_reloc, "R_390_GOTPLT12", FALSE, 0,0x00000fff, FALSE),
153 HOWTO(R_390_GOTPLT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
154 bfd_elf_generic_reloc, "R_390_GOTPLT16", FALSE, 0,0x0000ffff, FALSE),
155 HOWTO(R_390_GOTPLT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
156 bfd_elf_generic_reloc, "R_390_GOTPLT32", FALSE, 0,0xffffffff, FALSE),
157 EMPTY_HOWTO (R_390_GOTPLT64), /* Empty entry for R_390_GOTPLT64. */
158 HOWTO(R_390_GOTPLTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
159 bfd_elf_generic_reloc, "R_390_GOTPLTENT",FALSE, 0,0xffffffff, TRUE),
160 HOWTO(R_390_PLTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
161 bfd_elf_generic_reloc, "R_390_PLTOFF16", FALSE, 0,0x0000ffff, FALSE),
162 HOWTO(R_390_PLTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
163 bfd_elf_generic_reloc, "R_390_PLTOFF32", FALSE, 0,0xffffffff, FALSE),
164 EMPTY_HOWTO (R_390_PLTOFF64), /* Empty entry for R_390_PLTOFF64. */
167 /* GNU extension to record C++ vtable hierarchy. */
168 static reloc_howto_type elf32_s390_vtinherit_howto =
169 HOWTO (R_390_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", FALSE,0, 0, FALSE);
170 static reloc_howto_type elf32_s390_vtentry_howto =
171 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);
173 static reloc_howto_type *
174 elf_s390_reloc_type_lookup (abfd, code)
175 bfd *abfd ATTRIBUTE_UNUSED;
176 bfd_reloc_code_real_type code;
181 return &elf_howto_table[(int) R_390_NONE];
183 return &elf_howto_table[(int) R_390_8];
184 case BFD_RELOC_390_12:
185 return &elf_howto_table[(int) R_390_12];
187 return &elf_howto_table[(int) R_390_16];
189 return &elf_howto_table[(int) R_390_32];
191 return &elf_howto_table[(int) R_390_32];
192 case BFD_RELOC_32_PCREL:
193 return &elf_howto_table[(int) R_390_PC32];
194 case BFD_RELOC_390_GOT12:
195 return &elf_howto_table[(int) R_390_GOT12];
196 case BFD_RELOC_32_GOT_PCREL:
197 return &elf_howto_table[(int) R_390_GOT32];
198 case BFD_RELOC_390_PLT32:
199 return &elf_howto_table[(int) R_390_PLT32];
200 case BFD_RELOC_390_COPY:
201 return &elf_howto_table[(int) R_390_COPY];
202 case BFD_RELOC_390_GLOB_DAT:
203 return &elf_howto_table[(int) R_390_GLOB_DAT];
204 case BFD_RELOC_390_JMP_SLOT:
205 return &elf_howto_table[(int) R_390_JMP_SLOT];
206 case BFD_RELOC_390_RELATIVE:
207 return &elf_howto_table[(int) R_390_RELATIVE];
208 case BFD_RELOC_32_GOTOFF:
209 return &elf_howto_table[(int) R_390_GOTOFF32];
210 case BFD_RELOC_390_GOTPC:
211 return &elf_howto_table[(int) R_390_GOTPC];
212 case BFD_RELOC_390_GOT16:
213 return &elf_howto_table[(int) R_390_GOT16];
214 case BFD_RELOC_16_PCREL:
215 return &elf_howto_table[(int) R_390_PC16];
216 case BFD_RELOC_390_PC16DBL:
217 return &elf_howto_table[(int) R_390_PC16DBL];
218 case BFD_RELOC_390_PLT16DBL:
219 return &elf_howto_table[(int) R_390_PLT16DBL];
220 case BFD_RELOC_390_PC32DBL:
221 return &elf_howto_table[(int) R_390_PC32DBL];
222 case BFD_RELOC_390_PLT32DBL:
223 return &elf_howto_table[(int) R_390_PLT32DBL];
224 case BFD_RELOC_390_GOTPCDBL:
225 return &elf_howto_table[(int) R_390_GOTPCDBL];
226 case BFD_RELOC_390_GOTENT:
227 return &elf_howto_table[(int) R_390_GOTENT];
228 case BFD_RELOC_16_GOTOFF:
229 return &elf_howto_table[(int) R_390_GOTOFF16];
230 case BFD_RELOC_390_GOTPLT12:
231 return &elf_howto_table[(int) R_390_GOTPLT12];
232 case BFD_RELOC_390_GOTPLT16:
233 return &elf_howto_table[(int) R_390_GOTPLT16];
234 case BFD_RELOC_390_GOTPLT32:
235 return &elf_howto_table[(int) R_390_GOTPLT32];
236 case BFD_RELOC_390_GOTPLTENT:
237 return &elf_howto_table[(int) R_390_GOTPLTENT];
238 case BFD_RELOC_390_PLTOFF16:
239 return &elf_howto_table[(int) R_390_PLTOFF16];
240 case BFD_RELOC_390_PLTOFF32:
241 return &elf_howto_table[(int) R_390_PLTOFF32];
242 case BFD_RELOC_VTABLE_INHERIT:
243 return &elf32_s390_vtinherit_howto;
244 case BFD_RELOC_VTABLE_ENTRY:
245 return &elf32_s390_vtentry_howto;
252 /* We need to use ELF32_R_TYPE so we have our own copy of this function,
253 and elf32-s390.c has its own copy. */
256 elf_s390_info_to_howto (abfd, cache_ptr, dst)
257 bfd *abfd ATTRIBUTE_UNUSED;
259 Elf_Internal_Rela *dst;
261 switch (ELF32_R_TYPE(dst->r_info))
263 case R_390_GNU_VTINHERIT:
264 cache_ptr->howto = &elf32_s390_vtinherit_howto;
267 case R_390_GNU_VTENTRY:
268 cache_ptr->howto = &elf32_s390_vtentry_howto;
272 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_390_max);
273 cache_ptr->howto = &elf_howto_table[ELF32_R_TYPE(dst->r_info)];
278 elf_s390_is_local_label_name (abfd, name)
282 if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
285 return _bfd_elf_is_local_label_name (abfd, name);
288 /* Functions for the 390 ELF linker. */
290 /* The name of the dynamic interpreter. This is put in the .interp
293 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
295 /* The size in bytes of the first entry in the procedure linkage table. */
296 #define PLT_FIRST_ENTRY_SIZE 32
297 /* The size in bytes of an entry in the procedure linkage table. */
298 #define PLT_ENTRY_SIZE 32
300 #define GOT_ENTRY_SIZE 4
302 /* The first three entries in a procedure linkage table are reserved,
303 and the initial contents are unimportant (we zero them out).
304 Subsequent entries look like this. See the SVR4 ABI 386
305 supplement to see how this works. */
307 /* For the s390, simple addr offset can only be 0 - 4096.
308 To use the full 2 GB address space, several instructions
309 are needed to load an address in a register and execute
310 a branch( or just saving the address)
312 Furthermore, only r 0 and 1 are free to use!!! */
314 /* The first 3 words in the GOT are then reserved.
315 Word 0 is the address of the dynamic table.
316 Word 1 is a pointer to a structure describing the object
317 Word 2 is used to point to the loader entry address.
319 The code for position independand PLT entries looks like this:
321 r12 holds addr of the current GOT at entry to the PLT
323 The GOT holds the address in the PLT to be executed.
324 The loader then gets:
325 24(15) = Pointer to the structure describing the object.
326 28(15) = Offset in symbol table
328 The loader must then find the module where the function is
329 and insert the address in the GOT.
331 Note: 390 can only address +- 64 K relative.
332 We check if offset > 65536, then make a relative branch -64xxx
333 back to a previous defined branch
335 PLT1: BASR 1,0 # 2 bytes
336 L 1,22(1) # 4 bytes Load offset in GOT in r 1
337 L 1,(1,12) # 4 bytes Load address from GOT in r1
338 BCR 15,1 # 2 bytes Jump to address
339 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
340 L 1,14(1) # 4 bytes Load offset in symol table in r1
341 BRC 15,-x # 4 bytes Jump to start of PLT
342 .word 0 # 2 bytes filler
343 .long ? # 4 bytes offset in GOT
344 .long ? # 4 bytes offset into symbol table
346 This was the general case. There are two additional, optimizes PLT
347 definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768.
348 First the one for GOT offsets < 4096:
350 PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1
351 BCR 15,1 # 2 bytes Jump to address
352 .word 0,0,0 # 6 bytes filler
353 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
354 L 1,14(1) # 4 bytes Load offset in symbol table in r1
355 BRC 15,-x # 4 bytes Jump to start of PLT
356 .word 0,0,0 # 6 bytes filler
357 .long ? # 4 bytes offset into symbol table
359 Second the one for GOT offsets < 32768:
361 PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1
362 L 1,(1,12) # 4 bytes Load address from GOT to r1
363 BCR 15,1 # 2 bytes Jump to address
364 .word 0 # 2 bytes filler
365 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
366 L 1,14(1) # 4 bytes Load offset in symbol table in r1
367 BRC 15,-x # 4 bytes Jump to start of PLT
368 .word 0,0,0 # 6 bytes filler
369 .long ? # 4 bytes offset into symbol table
371 Total = 32 bytes per PLT entry
373 The code for static build PLT entries looks like this:
375 PLT1: BASR 1,0 # 2 bytes
376 L 1,22(1) # 4 bytes Load address of GOT entry
377 L 1,0(0,1) # 4 bytes Load address from GOT in r1
378 BCR 15,1 # 2 bytes Jump to address
379 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
380 L 1,14(1) # 4 bytes Load offset in symbol table in r1
381 BRC 15,-x # 4 bytes Jump to start of PLT
382 .word 0 # 2 bytes filler
383 .long ? # 4 bytes address of GOT entry
384 .long ? # 4 bytes offset into symbol table */
386 #define PLT_PIC_ENTRY_WORD0 0x0d105810
387 #define PLT_PIC_ENTRY_WORD1 0x10165811
388 #define PLT_PIC_ENTRY_WORD2 0xc00007f1
389 #define PLT_PIC_ENTRY_WORD3 0x0d105810
390 #define PLT_PIC_ENTRY_WORD4 0x100ea7f4
392 #define PLT_PIC12_ENTRY_WORD0 0x5810c000
393 #define PLT_PIC12_ENTRY_WORD1 0x07f10000
394 #define PLT_PIC12_ENTRY_WORD2 0x00000000
395 #define PLT_PIC12_ENTRY_WORD3 0x0d105810
396 #define PLT_PIC12_ENTRY_WORD4 0x100ea7f4
398 #define PLT_PIC16_ENTRY_WORD0 0xa7180000
399 #define PLT_PIC16_ENTRY_WORD1 0x5811c000
400 #define PLT_PIC16_ENTRY_WORD2 0x07f10000
401 #define PLT_PIC16_ENTRY_WORD3 0x0d105810
402 #define PLT_PIC16_ENTRY_WORD4 0x100ea7f4
404 #define PLT_ENTRY_WORD0 0x0d105810
405 #define PLT_ENTRY_WORD1 0x10165810
406 #define PLT_ENTRY_WORD2 0x100007f1
407 #define PLT_ENTRY_WORD3 0x0d105810
408 #define PLT_ENTRY_WORD4 0x100ea7f4
410 /* The first PLT entry pushes the offset into the symbol table
411 from R1 onto the stack at 8(15) and the loader object info
412 at 12(15), loads the loader address in R1 and jumps to it. */
414 /* The first entry in the PLT for PIC code:
417 ST 1,28(15) # R1 has offset into symbol table
418 L 1,4(12) # Get loader ino(object struct address)
419 ST 1,24(15) # Store address
420 L 1,8(12) # Entry address of loader in R1
421 BR 1 # Jump to loader
423 The first entry in the PLT for static code:
426 ST 1,28(15) # R1 has offset into symbol table
428 L 1,18(0,1) # Get address of GOT
429 MVC 24(4,15),4(1) # Move loader ino to stack
430 L 1,8(1) # Get address of loader
431 BR 1 # Jump to loader
433 .long got # address of GOT */
435 #define PLT_PIC_FIRST_ENTRY_WORD0 0x5010f01c
436 #define PLT_PIC_FIRST_ENTRY_WORD1 0x5810c004
437 #define PLT_PIC_FIRST_ENTRY_WORD2 0x5010f018
438 #define PLT_PIC_FIRST_ENTRY_WORD3 0x5810c008
439 #define PLT_PIC_FIRST_ENTRY_WORD4 0x07f10000
441 #define PLT_FIRST_ENTRY_WORD0 0x5010f01c
442 #define PLT_FIRST_ENTRY_WORD1 0x0d105810
443 #define PLT_FIRST_ENTRY_WORD2 0x1012D203
444 #define PLT_FIRST_ENTRY_WORD3 0xf0181004
445 #define PLT_FIRST_ENTRY_WORD4 0x58101008
446 #define PLT_FIRST_ENTRY_WORD5 0x07f10000
448 /* The s390 linker needs to keep track of the number of relocs that it
449 decides to copy as dynamic relocs in check_relocs for each symbol.
450 This is so that it can later discard them if they are found to be
451 unnecessary. We store the information in a field extending the
452 regular ELF linker hash table. */
454 struct elf_s390_dyn_relocs
456 struct elf_s390_dyn_relocs *next;
458 /* The input section of the reloc. */
461 /* Total number of relocs copied for the input section. */
464 /* Number of pc-relative relocs copied for the input section. */
465 bfd_size_type pc_count;
468 /* s390 ELF linker hash entry. */
470 struct elf_s390_link_hash_entry
472 struct elf_link_hash_entry elf;
474 /* Track dynamic relocs copied for this symbol. */
475 struct elf_s390_dyn_relocs *dyn_relocs;
477 /* Number of GOTPLT references for a function. */
478 bfd_signed_vma gotplt_refcount;
481 /* s390 ELF linker hash table. */
483 struct elf_s390_link_hash_table
485 struct elf_link_hash_table elf;
487 /* Short-cuts to get to dynamic linker sections. */
496 /* Small local sym to section mapping cache. */
497 struct sym_sec_cache sym_sec;
500 /* Get the s390 ELF linker hash table from a link_info structure. */
502 #define elf_s390_hash_table(p) \
503 ((struct elf_s390_link_hash_table *) ((p)->hash))
505 /* Create an entry in an s390 ELF linker hash table. */
507 static struct bfd_hash_entry *
508 link_hash_newfunc (entry, table, string)
509 struct bfd_hash_entry *entry;
510 struct bfd_hash_table *table;
513 /* Allocate the structure if it has not already been allocated by a
517 entry = bfd_hash_allocate (table,
518 sizeof (struct elf_s390_link_hash_entry));
523 /* Call the allocation method of the superclass. */
524 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
527 struct elf_s390_link_hash_entry *eh;
529 eh = (struct elf_s390_link_hash_entry *) entry;
530 eh->dyn_relocs = NULL;
531 eh->gotplt_refcount = 0;
537 /* Create an s390 ELF linker hash table. */
539 static struct bfd_link_hash_table *
540 elf_s390_link_hash_table_create (abfd)
543 struct elf_s390_link_hash_table *ret;
544 bfd_size_type amt = sizeof (struct elf_s390_link_hash_table);
546 ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt);
550 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc))
563 ret->sym_sec.abfd = NULL;
565 return &ret->elf.root;
568 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
569 shortcuts to them in our hash table. */
572 create_got_section (dynobj, info)
574 struct bfd_link_info *info;
576 struct elf_s390_link_hash_table *htab;
578 if (! _bfd_elf_create_got_section (dynobj, info))
581 htab = elf_s390_hash_table (info);
582 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
583 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
584 if (!htab->sgot || !htab->sgotplt)
587 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
588 if (htab->srelgot == NULL
589 || ! bfd_set_section_flags (dynobj, htab->srelgot,
590 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
591 | SEC_IN_MEMORY | SEC_LINKER_CREATED
593 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
598 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
599 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
603 elf_s390_create_dynamic_sections (dynobj, info)
605 struct bfd_link_info *info;
607 struct elf_s390_link_hash_table *htab;
609 htab = elf_s390_hash_table (info);
610 if (!htab->sgot && !create_got_section (dynobj, info))
613 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
616 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
617 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
618 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
620 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
622 if (!htab->splt || !htab->srelplt || !htab->sdynbss
623 || (!info->shared && !htab->srelbss))
629 /* Copy the extra info we tack onto an elf_link_hash_entry. */
632 elf_s390_copy_indirect_symbol (bed, dir, ind)
633 struct elf_backend_data *bed;
634 struct elf_link_hash_entry *dir, *ind;
636 struct elf_s390_link_hash_entry *edir, *eind;
638 edir = (struct elf_s390_link_hash_entry *) dir;
639 eind = (struct elf_s390_link_hash_entry *) ind;
641 if (eind->dyn_relocs != NULL)
643 if (edir->dyn_relocs != NULL)
645 struct elf_s390_dyn_relocs **pp;
646 struct elf_s390_dyn_relocs *p;
648 if (ind->root.type == bfd_link_hash_indirect)
651 /* Add reloc counts against the weak sym to the strong sym
652 list. Merge any entries against the same section. */
653 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
655 struct elf_s390_dyn_relocs *q;
657 for (q = edir->dyn_relocs; q != NULL; q = q->next)
658 if (q->sec == p->sec)
660 q->pc_count += p->pc_count;
661 q->count += p->count;
668 *pp = edir->dyn_relocs;
671 edir->dyn_relocs = eind->dyn_relocs;
672 eind->dyn_relocs = NULL;
675 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
678 /* Look through the relocs for a section during the first phase, and
679 allocate space in the global offset table or procedure linkage
683 elf_s390_check_relocs (abfd, info, sec, relocs)
685 struct bfd_link_info *info;
687 const Elf_Internal_Rela *relocs;
689 struct elf_s390_link_hash_table *htab;
690 Elf_Internal_Shdr *symtab_hdr;
691 struct elf_link_hash_entry **sym_hashes;
692 const Elf_Internal_Rela *rel;
693 const Elf_Internal_Rela *rel_end;
695 bfd_signed_vma *local_got_refcounts;
697 if (info->relocateable)
700 htab = elf_s390_hash_table (info);
701 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
702 sym_hashes = elf_sym_hashes (abfd);
703 local_got_refcounts = elf_local_got_refcounts (abfd);
707 rel_end = relocs + sec->reloc_count;
708 for (rel = relocs; rel < rel_end; rel++)
710 unsigned long r_symndx;
711 struct elf_link_hash_entry *h;
713 r_symndx = ELF32_R_SYM (rel->r_info);
715 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
717 (*_bfd_error_handler) (_("%s: bad symbol index: %d"),
718 bfd_archive_filename (abfd),
723 if (r_symndx < symtab_hdr->sh_info)
726 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
728 /* Create got section and local_got_refcounts array if they
730 switch (ELF32_R_TYPE (rel->r_info))
739 case R_390_GOTPLTENT:
741 && local_got_refcounts == NULL)
745 size = symtab_hdr->sh_info;
746 size *= sizeof (bfd_signed_vma);
747 local_got_refcounts = ((bfd_signed_vma *)
748 bfd_zalloc (abfd, size));
749 if (local_got_refcounts == NULL)
751 elf_local_got_refcounts (abfd) = local_got_refcounts;
758 if (htab->sgot == NULL)
760 if (htab->elf.dynobj == NULL)
761 htab->elf.dynobj = abfd;
762 if (!create_got_section (htab->elf.dynobj, info))
767 switch (ELF32_R_TYPE (rel->r_info))
773 /* This symbol requires a global offset table entry. */
775 h->got.refcount += 1;
777 local_got_refcounts[r_symndx] += 1;
784 /* Got is created, nothing to be done. */
792 /* This symbol requires a procedure linkage table entry. We
793 actually build the entry in adjust_dynamic_symbol,
794 because this might be a case of linking PIC code which is
795 never referenced by a dynamic object, in which case we
796 don't need to generate a procedure linkage table entry
799 /* If this is a local symbol, we resolve it directly without
800 creating a procedure linkage table entry. */
803 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
804 h->plt.refcount += 1;
811 case R_390_GOTPLTENT:
812 /* This symbol requires either a procedure linkage table entry
813 or an entry in the local got. We actually build the entry
814 in adjust_dynamic_symbol because whether this is really a
815 global reference can change and with it the fact if we have
816 to create a plt entry or a local got entry. To be able to
817 make a once global symbol a local one we have to keep track
818 of the number of gotplt references that exist for this
822 ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount++;
823 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
824 h->plt.refcount += 1;
827 local_got_refcounts[r_symndx] += 1;
837 if (h != NULL && !info->shared)
839 /* If this reloc is in a read-only section, we might
840 need a copy reloc. We can't check reliably at this
841 stage whether the section is read-only, as input
842 sections have not yet been mapped to output sections.
843 Tentatively set the flag for now, and correct in
844 adjust_dynamic_symbol. */
845 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
847 /* We may need a .plt entry if the function this reloc
848 refers to is in a shared lib. */
849 h->plt.refcount += 1;
852 /* If we are creating a shared library, and this is a reloc
853 against a global symbol, or a non PC relative reloc
854 against a local symbol, then we need to copy the reloc
855 into the shared library. However, if we are linking with
856 -Bsymbolic, we do not need to copy a reloc against a
857 global symbol which is defined in an object we are
858 including in the link (i.e., DEF_REGULAR is set). At
859 this point we have not seen all the input files, so it is
860 possible that DEF_REGULAR is not set now but will be set
861 later (it is never cleared). In case of a weak definition,
862 DEF_REGULAR may be cleared later by a strong definition in
863 a shared library. We account for that possibility below by
864 storing information in the relocs_copied field of the hash
865 table entry. A similar situation occurs when creating
866 shared libraries and symbol visibility changes render the
869 If on the other hand, we are creating an executable, we
870 may need to keep relocations for symbols satisfied by a
871 dynamic library if we manage to avoid copy relocs for the
874 && (sec->flags & SEC_ALLOC) != 0
875 && ((ELF32_R_TYPE (rel->r_info) != R_390_PC16
876 && ELF32_R_TYPE (rel->r_info) != R_390_PC16DBL
877 && ELF32_R_TYPE (rel->r_info) != R_390_PC32DBL
878 && ELF32_R_TYPE (rel->r_info) != R_390_PC32)
881 || h->root.type == bfd_link_hash_defweak
882 || (h->elf_link_hash_flags
883 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
885 && (sec->flags & SEC_ALLOC) != 0
887 && (h->root.type == bfd_link_hash_defweak
888 || (h->elf_link_hash_flags
889 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
891 struct elf_s390_dyn_relocs *p;
892 struct elf_s390_dyn_relocs **head;
894 /* We must copy these reloc types into the output file.
895 Create a reloc section in dynobj and make room for
902 name = (bfd_elf_string_from_elf_section
904 elf_elfheader (abfd)->e_shstrndx,
905 elf_section_data (sec)->rel_hdr.sh_name));
909 if (strncmp (name, ".rela", 5) != 0
910 || strcmp (bfd_get_section_name (abfd, sec),
913 (*_bfd_error_handler)
914 (_("%s: bad relocation section name `%s\'"),
915 bfd_archive_filename (abfd), name);
918 if (htab->elf.dynobj == NULL)
919 htab->elf.dynobj = abfd;
921 dynobj = htab->elf.dynobj;
922 sreloc = bfd_get_section_by_name (dynobj, name);
927 sreloc = bfd_make_section (dynobj, name);
928 flags = (SEC_HAS_CONTENTS | SEC_READONLY
929 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
930 if ((sec->flags & SEC_ALLOC) != 0)
931 flags |= SEC_ALLOC | SEC_LOAD;
933 || ! bfd_set_section_flags (dynobj, sreloc, flags)
934 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
937 elf_section_data (sec)->sreloc = sreloc;
940 /* If this is a global symbol, we count the number of
941 relocations we need for this symbol. */
944 head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs;
948 /* Track dynamic relocs needed for local syms too.
949 We really need local syms available to do this
953 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
958 head = ((struct elf_s390_dyn_relocs **)
959 &elf_section_data (s)->local_dynrel);
963 if (p == NULL || p->sec != sec)
965 bfd_size_type amt = sizeof *p;
966 p = ((struct elf_s390_dyn_relocs *)
967 bfd_alloc (htab->elf.dynobj, amt));
978 if (ELF32_R_TYPE (rel->r_info) == R_390_PC16
979 || ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL
980 || ELF32_R_TYPE (rel->r_info) == R_390_PC32DBL
981 || ELF32_R_TYPE (rel->r_info) == R_390_PC32)
986 /* This relocation describes the C++ object vtable hierarchy.
987 Reconstruct it for later use during GC. */
988 case R_390_GNU_VTINHERIT:
989 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
993 /* This relocation describes which C++ vtable entries are actually
994 used. Record for later use during GC. */
995 case R_390_GNU_VTENTRY:
996 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1008 /* Return the section that should be marked against GC for a given
1012 elf_s390_gc_mark_hook (sec, info, rel, h, sym)
1014 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1015 Elf_Internal_Rela *rel;
1016 struct elf_link_hash_entry *h;
1017 Elf_Internal_Sym *sym;
1021 switch (ELF32_R_TYPE (rel->r_info))
1023 case R_390_GNU_VTINHERIT:
1024 case R_390_GNU_VTENTRY:
1028 switch (h->root.type)
1030 case bfd_link_hash_defined:
1031 case bfd_link_hash_defweak:
1032 return h->root.u.def.section;
1034 case bfd_link_hash_common:
1035 return h->root.u.c.p->section;
1043 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
1048 /* Update the got entry reference counts for the section being removed. */
1051 elf_s390_gc_sweep_hook (abfd, info, sec, relocs)
1053 struct bfd_link_info *info;
1055 const Elf_Internal_Rela *relocs;
1057 Elf_Internal_Shdr *symtab_hdr;
1058 struct elf_link_hash_entry **sym_hashes;
1059 bfd_signed_vma *local_got_refcounts;
1060 const Elf_Internal_Rela *rel, *relend;
1061 unsigned long r_symndx;
1062 struct elf_link_hash_entry *h;
1064 elf_section_data (sec)->local_dynrel = NULL;
1066 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1067 sym_hashes = elf_sym_hashes (abfd);
1068 local_got_refcounts = elf_local_got_refcounts (abfd);
1070 relend = relocs + sec->reloc_count;
1071 for (rel = relocs; rel < relend; rel++)
1073 r_symndx = ELF32_R_SYM (rel->r_info);
1075 if (r_symndx < symtab_hdr->sh_info)
1078 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1080 switch (ELF32_R_TYPE (rel->r_info))
1085 case R_390_GOTOFF16:
1086 case R_390_GOTOFF32:
1088 case R_390_GOTPCDBL:
1092 if (h->got.refcount > 0)
1093 h->got.refcount -= 1;
1095 else if (local_got_refcounts != NULL)
1097 if (local_got_refcounts[r_symndx] > 0)
1098 local_got_refcounts[r_symndx] -= 1;
1102 case R_390_PLT16DBL:
1103 case R_390_PLT32DBL:
1105 case R_390_PLTOFF16:
1106 case R_390_PLTOFF32:
1109 if (h->plt.refcount > 0)
1110 h->plt.refcount -= 1;
1114 case R_390_GOTPLT12:
1115 case R_390_GOTPLT16:
1116 case R_390_GOTPLT32:
1117 case R_390_GOTPLTENT:
1120 if (h->plt.refcount > 0)
1122 ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount--;
1123 h->plt.refcount -= 1;
1126 else if (local_got_refcounts != NULL)
1128 if (local_got_refcounts[r_symndx] > 0)
1129 local_got_refcounts[r_symndx] -= 1;
1143 struct elf_s390_link_hash_entry *eh;
1144 struct elf_s390_dyn_relocs **pp;
1145 struct elf_s390_dyn_relocs *p;
1147 if (!info->shared && h->plt.refcount > 0)
1148 h->plt.refcount -= 1;
1150 eh = (struct elf_s390_link_hash_entry *) h;
1152 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1155 if (ELF32_R_TYPE (rel->r_info) == R_390_PC16
1156 || ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL
1157 || ELF32_R_TYPE (rel->r_info) == R_390_PC32DBL
1158 || ELF32_R_TYPE (rel->r_info) == R_390_PC32)
1176 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1177 entry but we found we will not create any. Called when we find we will
1178 not have any PLT for this symbol, by for example
1179 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
1180 or elf_s390_size_dynamic_sections if no dynamic sections will be
1181 created (we're only linking static objects). */
1184 elf_s390_adjust_gotplt (h)
1185 struct elf_s390_link_hash_entry *h;
1187 if (h->elf.root.type == bfd_link_hash_warning)
1188 h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link;
1190 if (h->gotplt_refcount <= 0)
1193 /* We simply add the number of gotplt references to the number
1194 * of got references for this symbol. */
1195 h->elf.got.refcount += h->gotplt_refcount;
1196 h->gotplt_refcount = -1;
1199 /* Adjust a symbol defined by a dynamic object and referenced by a
1200 regular object. The current definition is in some section of the
1201 dynamic object, but we're not including those sections. We have to
1202 change the definition to something the rest of the link can
1206 elf_s390_adjust_dynamic_symbol (info, h)
1207 struct bfd_link_info *info;
1208 struct elf_link_hash_entry *h;
1210 struct elf_s390_link_hash_table *htab;
1211 struct elf_s390_link_hash_entry * eh;
1212 struct elf_s390_dyn_relocs *p;
1214 unsigned int power_of_two;
1216 /* If this is a function, put it in the procedure linkage table. We
1217 will fill in the contents of the procedure linkage table later
1218 (although we could actually do it here). */
1219 if (h->type == STT_FUNC
1220 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1222 if (h->plt.refcount <= 0
1224 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
1225 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
1226 && h->root.type != bfd_link_hash_undefweak
1227 && h->root.type != bfd_link_hash_undefined))
1229 /* This case can occur if we saw a PLT32 reloc in an input
1230 file, but the symbol was never referred to by a dynamic
1231 object, or if all references were garbage collected. In
1232 such a case, we don't actually need to build a procedure
1233 linkage table, and we can just do a PC32 reloc instead. */
1234 h->plt.offset = (bfd_vma) -1;
1235 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1236 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1242 /* It's possible that we incorrectly decided a .plt reloc was
1243 needed for an R_390_PC32 reloc to a non-function sym in
1244 check_relocs. We can't decide accurately between function and
1245 non-function syms in check-relocs; Objects loaded later in
1246 the link may change h->type. So fix it now. */
1247 h->plt.offset = (bfd_vma) -1;
1249 /* If this is a weak symbol, and there is a real definition, the
1250 processor independent code will have arranged for us to see the
1251 real definition first, and we can just use the same value. */
1252 if (h->weakdef != NULL)
1254 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1255 || h->weakdef->root.type == bfd_link_hash_defweak);
1256 h->root.u.def.section = h->weakdef->root.u.def.section;
1257 h->root.u.def.value = h->weakdef->root.u.def.value;
1261 /* This is a reference to a symbol defined by a dynamic object which
1262 is not a function. */
1264 /* If we are creating a shared library, we must presume that the
1265 only references to the symbol are via the global offset table.
1266 For such cases we need not do anything here; the relocations will
1267 be handled correctly by relocate_section. */
1271 /* If there are no references to this symbol that do not use the
1272 GOT, we don't need to generate a copy reloc. */
1273 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
1276 /* If -z nocopyreloc was given, we won't generate them either. */
1277 if (info->nocopyreloc)
1279 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
1283 eh = (struct elf_s390_link_hash_entry *) h;
1284 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1286 s = p->sec->output_section;
1287 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1291 /* If we didn't find any dynamic relocs in read-only sections, then
1292 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1295 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
1299 /* We must allocate the symbol in our .dynbss section, which will
1300 become part of the .bss section of the executable. There will be
1301 an entry for this symbol in the .dynsym section. The dynamic
1302 object will contain position independent code, so all references
1303 from the dynamic object to this symbol will go through the global
1304 offset table. The dynamic linker will use the .dynsym entry to
1305 determine the address it must put in the global offset table, so
1306 both the dynamic object and the regular object will refer to the
1307 same memory location for the variable. */
1309 htab = elf_s390_hash_table (info);
1311 /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1312 copy the initial value out of the dynamic object and into the
1313 runtime process image. */
1314 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1316 htab->srelbss->_raw_size += sizeof (Elf32_External_Rela);
1317 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1320 /* We need to figure out the alignment required for this symbol. I
1321 have no idea how ELF linkers handle this. */
1322 power_of_two = bfd_log2 (h->size);
1323 if (power_of_two > 3)
1326 /* Apply the required alignment. */
1328 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
1329 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
1331 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
1335 /* Define the symbol as being at this point in the section. */
1336 h->root.u.def.section = s;
1337 h->root.u.def.value = s->_raw_size;
1339 /* Increment the section size to make room for the symbol. */
1340 s->_raw_size += h->size;
1345 /* This is the condition under which elf_s390_finish_dynamic_symbol
1346 will be called from elflink.h. If elflink.h doesn't call our
1347 finish_dynamic_symbol routine, we'll need to do something about
1348 initializing any .plt and .got entries in elf_s390_relocate_section. */
1349 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1351 && ((INFO)->shared \
1352 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1353 && ((H)->dynindx != -1 \
1354 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1356 /* Allocate space in .plt, .got and associated reloc sections for
1360 allocate_dynrelocs (h, inf)
1361 struct elf_link_hash_entry *h;
1364 struct bfd_link_info *info;
1365 struct elf_s390_link_hash_table *htab;
1366 struct elf_s390_link_hash_entry *eh;
1367 struct elf_s390_dyn_relocs *p;
1369 if (h->root.type == bfd_link_hash_indirect)
1372 if (h->root.type == bfd_link_hash_warning)
1373 /* When warning symbols are created, they **replace** the "real"
1374 entry in the hash table, thus we never get to see the real
1375 symbol in a hash traversal. So look at it now. */
1376 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1378 info = (struct bfd_link_info *) inf;
1379 htab = elf_s390_hash_table (info);
1381 if (htab->elf.dynamic_sections_created
1382 && h->plt.refcount > 0)
1384 /* Make sure this symbol is output as a dynamic symbol.
1385 Undefined weak syms won't yet be marked as dynamic. */
1386 if (h->dynindx == -1
1387 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1389 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1393 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
1395 asection *s = htab->splt;
1397 /* If this is the first .plt entry, make room for the special
1399 if (s->_raw_size == 0)
1400 s->_raw_size += PLT_FIRST_ENTRY_SIZE;
1402 h->plt.offset = s->_raw_size;
1404 /* If this symbol is not defined in a regular file, and we are
1405 not generating a shared library, then set the symbol to this
1406 location in the .plt. This is required to make function
1407 pointers compare as equal between the normal executable and
1408 the shared library. */
1410 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1412 h->root.u.def.section = s;
1413 h->root.u.def.value = h->plt.offset;
1416 /* Make room for this entry. */
1417 s->_raw_size += PLT_ENTRY_SIZE;
1419 /* We also need to make an entry in the .got.plt section, which
1420 will be placed in the .got section by the linker script. */
1421 htab->sgotplt->_raw_size += GOT_ENTRY_SIZE;
1423 /* We also need to make an entry in the .rela.plt section. */
1424 htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
1428 h->plt.offset = (bfd_vma) -1;
1429 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1430 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1435 h->plt.offset = (bfd_vma) -1;
1436 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1437 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1440 if (h->got.refcount > 0)
1445 /* Make sure this symbol is output as a dynamic symbol.
1446 Undefined weak syms won't yet be marked as dynamic. */
1447 if (h->dynindx == -1
1448 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1450 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1455 h->got.offset = s->_raw_size;
1456 s->_raw_size += GOT_ENTRY_SIZE;
1457 dyn = htab->elf.dynamic_sections_created;
1458 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
1459 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
1462 h->got.offset = (bfd_vma) -1;
1464 eh = (struct elf_s390_link_hash_entry *) h;
1465 if (eh->dyn_relocs == NULL)
1468 /* In the shared -Bsymbolic case, discard space allocated for
1469 dynamic pc-relative relocs against symbols which turn out to be
1470 defined in regular objects. For the normal shared case, discard
1471 space for pc-relative relocs that have become local due to symbol
1472 visibility changes. */
1476 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
1477 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
1480 struct elf_s390_dyn_relocs **pp;
1482 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1484 p->count -= p->pc_count;
1495 /* For the non-shared case, discard space for relocs against
1496 symbols which turn out to need copy relocs or are not
1499 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
1500 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1501 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1502 || (htab->elf.dynamic_sections_created
1503 && (h->root.type == bfd_link_hash_undefweak
1504 || h->root.type == bfd_link_hash_undefined))))
1506 /* Make sure this symbol is output as a dynamic symbol.
1507 Undefined weak syms won't yet be marked as dynamic. */
1508 if (h->dynindx == -1
1509 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1511 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1515 /* If that succeeded, we know we'll be keeping all the
1517 if (h->dynindx != -1)
1521 eh->dyn_relocs = NULL;
1526 /* Finally, allocate space. */
1527 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1529 asection *sreloc = elf_section_data (p->sec)->sreloc;
1530 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
1536 /* Find any dynamic relocs that apply to read-only sections. */
1539 readonly_dynrelocs (h, inf)
1540 struct elf_link_hash_entry *h;
1543 struct elf_s390_link_hash_entry *eh;
1544 struct elf_s390_dyn_relocs *p;
1546 if (h->root.type == bfd_link_hash_warning)
1547 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1549 eh = (struct elf_s390_link_hash_entry *) h;
1550 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1552 asection *s = p->sec->output_section;
1554 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1556 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1558 info->flags |= DF_TEXTREL;
1560 /* Not an error, just cut short the traversal. */
1567 /* Set the sizes of the dynamic sections. */
1570 elf_s390_size_dynamic_sections (output_bfd, info)
1571 bfd *output_bfd ATTRIBUTE_UNUSED;
1572 struct bfd_link_info *info;
1574 struct elf_s390_link_hash_table *htab;
1580 htab = elf_s390_hash_table (info);
1581 dynobj = htab->elf.dynobj;
1585 if (htab->elf.dynamic_sections_created)
1587 /* Set the contents of the .interp section to the interpreter. */
1590 s = bfd_get_section_by_name (dynobj, ".interp");
1593 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1594 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1598 /* Set up .got offsets for local syms, and space for local dynamic
1600 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1602 bfd_signed_vma *local_got;
1603 bfd_signed_vma *end_local_got;
1604 bfd_size_type locsymcount;
1605 Elf_Internal_Shdr *symtab_hdr;
1608 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
1611 for (s = ibfd->sections; s != NULL; s = s->next)
1613 struct elf_s390_dyn_relocs *p;
1615 for (p = *((struct elf_s390_dyn_relocs **)
1616 &elf_section_data (s)->local_dynrel);
1620 if (!bfd_is_abs_section (p->sec)
1621 && bfd_is_abs_section (p->sec->output_section))
1623 /* Input section has been discarded, either because
1624 it is a copy of a linkonce section or due to
1625 linker script /DISCARD/, so we'll be discarding
1628 else if (p->count != 0)
1630 srela = elf_section_data (p->sec)->sreloc;
1631 srela->_raw_size += p->count * sizeof (Elf32_External_Rela);
1632 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
1633 info->flags |= DF_TEXTREL;
1638 local_got = elf_local_got_refcounts (ibfd);
1642 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
1643 locsymcount = symtab_hdr->sh_info;
1644 end_local_got = local_got + locsymcount;
1646 srela = htab->srelgot;
1647 for (; local_got < end_local_got; ++local_got)
1651 *local_got = s->_raw_size;
1652 s->_raw_size += GOT_ENTRY_SIZE;
1654 srela->_raw_size += sizeof (Elf32_External_Rela);
1657 *local_got = (bfd_vma) -1;
1661 /* Allocate global sym .plt and .got entries, and space for global
1662 sym dynamic relocs. */
1663 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
1665 /* We now have determined the sizes of the various dynamic sections.
1666 Allocate memory for them. */
1668 for (s = dynobj->sections; s != NULL; s = s->next)
1670 if ((s->flags & SEC_LINKER_CREATED) == 0)
1675 || s == htab->sgotplt)
1677 /* Strip this section if we don't need it; see the
1680 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
1682 if (s->_raw_size != 0 && s != htab->srelplt)
1685 /* We use the reloc_count field as a counter if we need
1686 to copy relocs into the output file. */
1691 /* It's not one of our sections, so don't allocate space. */
1695 if (s->_raw_size == 0)
1697 /* If we don't need this section, strip it from the
1698 output file. This is to handle .rela.bss and
1699 .rela.plt. We must create it in
1700 create_dynamic_sections, because it must be created
1701 before the linker maps input sections to output
1702 sections. The linker does that before
1703 adjust_dynamic_symbol is called, and it is that
1704 function which decides whether anything needs to go
1705 into these sections. */
1707 _bfd_strip_section_from_output (info, s);
1711 /* Allocate memory for the section contents. We use bfd_zalloc
1712 here in case unused entries are not reclaimed before the
1713 section's contents are written out. This should not happen,
1714 but this way if it does, we get a R_390_NONE reloc instead
1716 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1717 if (s->contents == NULL)
1721 if (htab->elf.dynamic_sections_created)
1723 /* Add some entries to the .dynamic section. We fill in the
1724 values later, in elf_s390_finish_dynamic_sections, but we
1725 must add the entries now so that we get the correct size for
1726 the .dynamic section. The DT_DEBUG entry is filled in by the
1727 dynamic linker and used by the debugger. */
1728 #define add_dynamic_entry(TAG, VAL) \
1729 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1733 if (!add_dynamic_entry (DT_DEBUG, 0))
1737 if (htab->splt->_raw_size != 0)
1739 if (!add_dynamic_entry (DT_PLTGOT, 0)
1740 || !add_dynamic_entry (DT_PLTRELSZ, 0)
1741 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1742 || !add_dynamic_entry (DT_JMPREL, 0))
1748 if (!add_dynamic_entry (DT_RELA, 0)
1749 || !add_dynamic_entry (DT_RELASZ, 0)
1750 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
1753 /* If any dynamic relocs apply to a read-only section,
1754 then we need a DT_TEXTREL entry. */
1755 if ((info->flags & DF_TEXTREL) == 0)
1756 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
1759 if ((info->flags & DF_TEXTREL) != 0)
1761 if (!add_dynamic_entry (DT_TEXTREL, 0))
1766 #undef add_dynamic_entry
1771 /* Relocate a 390 ELF section. */
1774 elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
1775 contents, relocs, local_syms, local_sections)
1777 struct bfd_link_info *info;
1779 asection *input_section;
1781 Elf_Internal_Rela *relocs;
1782 Elf_Internal_Sym *local_syms;
1783 asection **local_sections;
1785 struct elf_s390_link_hash_table *htab;
1786 Elf_Internal_Shdr *symtab_hdr;
1787 struct elf_link_hash_entry **sym_hashes;
1788 bfd_vma *local_got_offsets;
1789 Elf_Internal_Rela *rel;
1790 Elf_Internal_Rela *relend;
1792 if (info->relocateable)
1795 htab = elf_s390_hash_table (info);
1796 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1797 sym_hashes = elf_sym_hashes (input_bfd);
1798 local_got_offsets = elf_local_got_offsets (input_bfd);
1801 relend = relocs + input_section->reloc_count;
1802 for (; rel < relend; rel++)
1804 unsigned int r_type;
1805 reloc_howto_type *howto;
1806 unsigned long r_symndx;
1807 struct elf_link_hash_entry *h;
1808 Elf_Internal_Sym *sym;
1812 bfd_boolean unresolved_reloc;
1813 bfd_reloc_status_type r;
1815 r_type = ELF32_R_TYPE (rel->r_info);
1816 if (r_type == (int) R_390_GNU_VTINHERIT
1817 || r_type == (int) R_390_GNU_VTENTRY)
1819 if (r_type >= (int) R_390_max)
1821 bfd_set_error (bfd_error_bad_value);
1825 howto = elf_howto_table + r_type;
1826 r_symndx = ELF32_R_SYM (rel->r_info);
1828 /* This is a final link. */
1832 unresolved_reloc = FALSE;
1833 if (r_symndx < symtab_hdr->sh_info)
1835 sym = local_syms + r_symndx;
1836 sec = local_sections[r_symndx];
1837 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
1841 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1842 while (h->root.type == bfd_link_hash_indirect
1843 || h->root.type == bfd_link_hash_warning)
1844 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1846 if (h->root.type == bfd_link_hash_defined
1847 || h->root.type == bfd_link_hash_defweak)
1849 sec = h->root.u.def.section;
1850 if (sec->output_section == NULL)
1852 /* Set a flag that will be cleared later if we find a
1853 relocation value for this symbol. output_section
1854 is typically NULL for symbols satisfied by a shared
1856 unresolved_reloc = TRUE;
1860 relocation = (h->root.u.def.value
1861 + sec->output_section->vma
1862 + sec->output_offset);
1864 else if (h->root.type == bfd_link_hash_undefweak)
1866 else if (info->shared
1867 && (!info->symbolic || info->allow_shlib_undefined)
1868 && !info->no_undefined
1869 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1873 if (! ((*info->callbacks->undefined_symbol)
1874 (info, h->root.root.string, input_bfd,
1875 input_section, rel->r_offset,
1876 (!info->shared || info->no_undefined
1877 || ELF_ST_VISIBILITY (h->other)))))
1885 case R_390_GOTPLT12:
1886 case R_390_GOTPLT16:
1887 case R_390_GOTPLT32:
1888 case R_390_GOTPLTENT:
1889 /* There are three cases for a GOTPLT relocation. 1) The
1890 relocation is against the jump slot entry of a plt that
1891 will get emitted to the output file. 2) The relocation
1892 is against the jump slot of a plt entry that has been
1893 removed. elf_s390_adjust_gotplt has created a GOT entry
1894 as replacement. 3) The relocation is against a local symbol.
1895 Cases 2) and 3) are the same as the GOT relocation code
1896 so we just have to test for case 1 and fall through for
1898 if (h != NULL && h->plt.offset != (bfd_vma) -1)
1903 Current offset - size first entry / entry size. */
1904 plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) /
1907 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
1909 relocation = (plt_index + 3) * GOT_ENTRY_SIZE;
1910 unresolved_reloc = FALSE;
1912 if (r_type == R_390_GOTPLTENT)
1913 relocation += htab->sgot->output_section->vma;
1922 /* Relocation is to the entry for this symbol in the global
1924 if (htab->sgot == NULL)
1931 off = h->got.offset;
1932 dyn = htab->elf.dynamic_sections_created;
1933 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
1937 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
1938 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1940 /* This is actually a static link, or it is a
1941 -Bsymbolic link and the symbol is defined
1942 locally, or the symbol was forced to be local
1943 because of a version file. We must initialize
1944 this entry in the global offset table. Since the
1945 offset must always be a multiple of 2, we use the
1946 least significant bit to record whether we have
1947 initialized it already.
1949 When doing a dynamic link, we create a .rel.got
1950 relocation entry to initialize the value. This
1951 is done in the finish_dynamic_symbol routine. */
1956 bfd_put_32 (output_bfd, relocation,
1957 htab->sgot->contents + off);
1962 unresolved_reloc = FALSE;
1966 if (local_got_offsets == NULL)
1969 off = local_got_offsets[r_symndx];
1971 /* The offset must always be a multiple of 4. We use
1972 the least significant bit to record whether we have
1973 already generated the necessary reloc. */
1978 bfd_put_32 (output_bfd, relocation,
1979 htab->sgot->contents + off);
1984 Elf_Internal_Rela outrel;
1987 srelgot = htab->srelgot;
1988 if (srelgot == NULL)
1991 outrel.r_offset = (htab->sgot->output_section->vma
1992 + htab->sgot->output_offset
1994 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
1995 outrel.r_addend = relocation;
1996 loc = srelgot->contents;
1997 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
1998 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2001 local_got_offsets[r_symndx] |= 1;
2005 if (off >= (bfd_vma) -2)
2008 relocation = htab->sgot->output_offset + off;
2011 * For @GOTENT the relocation is against the offset between
2012 * the instruction and the symbols entry in the GOT and not
2013 * between the start of the GOT and the symbols entry. We
2014 * add the vma of the GOT to get the correct value.
2016 if ( r_type == R_390_GOTENT
2017 || r_type == R_390_GOTPLTENT)
2018 relocation += htab->sgot->output_section->vma;
2022 case R_390_GOTOFF16:
2023 case R_390_GOTOFF32:
2024 /* Relocation is relative to the start of the global offset
2027 /* Note that sgot->output_offset is not involved in this
2028 calculation. We always want the start of .got. If we
2029 defined _GLOBAL_OFFSET_TABLE in a different way, as is
2030 permitted by the ABI, we might have to change this
2032 relocation -= htab->sgot->output_section->vma;
2036 case R_390_GOTPCDBL:
2037 /* Use global offset table as symbol value. */
2038 relocation = htab->sgot->output_section->vma;
2039 unresolved_reloc = FALSE;
2042 case R_390_PLT16DBL:
2043 case R_390_PLT32DBL:
2045 /* Relocation is to the entry for this symbol in the
2046 procedure linkage table. */
2048 /* Resolve a PLT32 reloc against a local symbol directly,
2049 without using the procedure linkage table. */
2053 if (h->plt.offset == (bfd_vma) -1
2054 || htab->splt == NULL)
2056 /* We didn't make a PLT entry for this symbol. This
2057 happens when statically linking PIC code, or when
2058 using -Bsymbolic. */
2062 relocation = (htab->splt->output_section->vma
2063 + htab->splt->output_offset
2065 unresolved_reloc = FALSE;
2068 case R_390_PLTOFF16:
2069 case R_390_PLTOFF32:
2070 /* Relocation is to the entry for this symbol in the
2071 procedure linkage table relative to the start of the GOT. */
2073 /* For local symbols or if we didn't make a PLT entry for
2074 this symbol resolve the symbol directly. */
2076 || h->plt.offset == (bfd_vma) -1
2077 || htab->splt == NULL)
2079 relocation -= htab->sgot->output_section->vma;
2083 relocation = (htab->splt->output_section->vma
2084 + htab->splt->output_offset
2086 - htab->sgot->output_section->vma);
2087 unresolved_reloc = FALSE;
2097 /* r_symndx will be zero only for relocs against symbols
2098 from removed linkonce sections, or sections discarded by
2101 || (input_section->flags & SEC_ALLOC) == 0)
2105 && ((r_type != R_390_PC16
2106 && r_type != R_390_PC16DBL
2107 && r_type != R_390_PC32DBL
2108 && r_type != R_390_PC32)
2111 && (! info->symbolic
2112 || (h->elf_link_hash_flags
2113 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
2117 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
2118 && (((h->elf_link_hash_flags
2119 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2120 && (h->elf_link_hash_flags
2121 & ELF_LINK_HASH_DEF_REGULAR) == 0)
2122 || h->root.type == bfd_link_hash_undefweak
2123 || h->root.type == bfd_link_hash_undefined)))
2125 Elf_Internal_Rela outrel;
2126 bfd_boolean skip, relocate;
2130 /* When generating a shared object, these relocations
2131 are copied into the output file to be resolved at run
2138 _bfd_elf_section_offset (output_bfd, info, input_section,
2140 if (outrel.r_offset == (bfd_vma) -1)
2142 else if (outrel.r_offset == (bfd_vma) -2)
2143 skip = TRUE, relocate = TRUE;
2144 outrel.r_offset += (input_section->output_section->vma
2145 + input_section->output_offset);
2148 memset (&outrel, 0, sizeof outrel);
2151 && (r_type == R_390_PC16
2152 || r_type == R_390_PC16DBL
2153 || r_type == R_390_PC32DBL
2154 || r_type == R_390_PC32
2157 || (h->elf_link_hash_flags
2158 & ELF_LINK_HASH_DEF_REGULAR) == 0))
2160 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2161 outrel.r_addend = rel->r_addend;
2165 /* This symbol is local, or marked to become local. */
2167 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
2168 outrel.r_addend = relocation + rel->r_addend;
2171 sreloc = elf_section_data (input_section)->sreloc;
2175 loc = sreloc->contents;
2176 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
2177 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2179 /* If this reloc is against an external symbol, we do
2180 not want to fiddle with the addend. Otherwise, we
2181 need to include the symbol value so that it becomes
2182 an addend for the dynamic reloc. */
2192 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2193 because such sections are not SEC_ALLOC and thus ld.so will
2194 not process them. */
2195 if (unresolved_reloc
2196 && !((input_section->flags & SEC_DEBUGGING) != 0
2197 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
2198 (*_bfd_error_handler)
2199 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
2200 bfd_archive_filename (input_bfd),
2201 bfd_get_section_name (input_bfd, input_section),
2202 (long) rel->r_offset,
2203 h->root.root.string);
2205 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2206 contents, rel->r_offset,
2207 relocation, rel->r_addend);
2209 if (r != bfd_reloc_ok)
2214 name = h->root.root.string;
2217 name = bfd_elf_string_from_elf_section (input_bfd,
2218 symtab_hdr->sh_link,
2223 name = bfd_section_name (input_bfd, sec);
2226 if (r == bfd_reloc_overflow)
2229 if (! ((*info->callbacks->reloc_overflow)
2230 (info, name, howto->name, (bfd_vma) 0,
2231 input_bfd, input_section, rel->r_offset)))
2236 (*_bfd_error_handler)
2237 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
2238 bfd_archive_filename (input_bfd),
2239 bfd_get_section_name (input_bfd, input_section),
2240 (long) rel->r_offset, name, (int) r);
2249 /* Finish up dynamic symbol handling. We set the contents of various
2250 dynamic sections here. */
2253 elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym)
2255 struct bfd_link_info *info;
2256 struct elf_link_hash_entry *h;
2257 Elf_Internal_Sym *sym;
2259 struct elf_s390_link_hash_table *htab;
2261 htab = elf_s390_hash_table (info);
2263 if (h->plt.offset != (bfd_vma) -1)
2267 Elf_Internal_Rela rela;
2269 bfd_vma relative_offset;
2271 /* This symbol has an entry in the procedure linkage table. Set
2274 if (h->dynindx == -1
2275 || htab->splt == NULL
2276 || htab->sgotplt == NULL
2277 || htab->srelplt == NULL)
2281 Current offset - size first entry / entry size. */
2282 plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
2284 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2286 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
2288 /* S390 uses halfwords for relative branch calc! */
2289 relative_offset = - ((PLT_FIRST_ENTRY_SIZE +
2290 (PLT_ENTRY_SIZE * plt_index) + 18) / 2);
2291 /* If offset is > 32768, branch to a previous branch
2292 390 can only handle +-64 K jumps. */
2293 if ( -32768 > (int) relative_offset )
2295 -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2);
2297 /* Fill in the entry in the procedure linkage table. */
2300 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0,
2301 htab->splt->contents + h->plt.offset);
2302 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1,
2303 htab->splt->contents + h->plt.offset + 4);
2304 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2,
2305 htab->splt->contents + h->plt.offset + 8);
2306 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3,
2307 htab->splt->contents + h->plt.offset + 12);
2308 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4,
2309 htab->splt->contents + h->plt.offset + 16);
2310 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2311 htab->splt->contents + h->plt.offset + 20);
2312 bfd_put_32 (output_bfd,
2313 (htab->sgotplt->output_section->vma
2314 + htab->sgotplt->output_offset
2316 htab->splt->contents + h->plt.offset + 24);
2318 else if (got_offset < 4096)
2320 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD0 + got_offset,
2321 htab->splt->contents + h->plt.offset);
2322 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD1,
2323 htab->splt->contents + h->plt.offset + 4);
2324 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD2,
2325 htab->splt->contents + h->plt.offset + 8);
2326 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD3,
2327 htab->splt->contents + h->plt.offset + 12);
2328 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD4,
2329 htab->splt->contents + h->plt.offset + 16);
2330 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2331 htab->splt->contents + h->plt.offset + 20);
2332 bfd_put_32 (output_bfd, (bfd_vma) 0,
2333 htab->splt->contents + h->plt.offset + 24);
2335 else if (got_offset < 32768)
2337 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD0 + got_offset,
2338 htab->splt->contents + h->plt.offset);
2339 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD1,
2340 htab->splt->contents + h->plt.offset + 4);
2341 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD2,
2342 htab->splt->contents + h->plt.offset + 8);
2343 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD3,
2344 htab->splt->contents + h->plt.offset + 12);
2345 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD4,
2346 htab->splt->contents + h->plt.offset + 16);
2347 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2348 htab->splt->contents + h->plt.offset + 20);
2349 bfd_put_32 (output_bfd, (bfd_vma) 0,
2350 htab->splt->contents + h->plt.offset + 24);
2354 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD0,
2355 htab->splt->contents + h->plt.offset);
2356 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD1,
2357 htab->splt->contents + h->plt.offset + 4);
2358 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD2,
2359 htab->splt->contents + h->plt.offset + 8);
2360 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD3,
2361 htab->splt->contents + h->plt.offset + 12);
2362 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD4,
2363 htab->splt->contents + h->plt.offset + 16);
2364 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2365 htab->splt->contents + h->plt.offset + 20);
2366 bfd_put_32 (output_bfd, got_offset,
2367 htab->splt->contents + h->plt.offset + 24);
2369 /* Insert offset into reloc. table here. */
2370 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
2371 htab->splt->contents + h->plt.offset + 28);
2373 /* Fill in the entry in the global offset table.
2374 Points to instruction after GOT offset. */
2375 bfd_put_32 (output_bfd,
2376 (htab->splt->output_section->vma
2377 + htab->splt->output_offset
2380 htab->sgotplt->contents + got_offset);
2382 /* Fill in the entry in the .rela.plt section. */
2383 rela.r_offset = (htab->sgotplt->output_section->vma
2384 + htab->sgotplt->output_offset
2386 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT);
2388 loc = htab->srelplt->contents + plt_index * sizeof (Elf32_External_Rela);
2389 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2391 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2393 /* Mark the symbol as undefined, rather than as defined in
2394 the .plt section. Leave the value alone. This is a clue
2395 for the dynamic linker, to make function pointer
2396 comparisons work between an application and shared
2398 sym->st_shndx = SHN_UNDEF;
2402 if (h->got.offset != (bfd_vma) -1)
2404 Elf_Internal_Rela rela;
2407 /* This symbol has an entry in the global offset table. Set it
2410 if (htab->sgot == NULL || htab->srelgot == NULL)
2413 rela.r_offset = (htab->sgot->output_section->vma
2414 + htab->sgot->output_offset
2415 + (h->got.offset &~ (bfd_vma) 1));
2417 /* If this is a static link, or it is a -Bsymbolic link and the
2418 symbol is defined locally or was forced to be local because
2419 of a version file, we just want to emit a RELATIVE reloc.
2420 The entry in the global offset table will already have been
2421 initialized in the relocate_section function. */
2425 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
2426 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2428 BFD_ASSERT((h->got.offset & 1) != 0);
2429 rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
2430 rela.r_addend = (h->root.u.def.value
2431 + h->root.u.def.section->output_section->vma
2432 + h->root.u.def.section->output_offset);
2436 BFD_ASSERT((h->got.offset & 1) == 0);
2437 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.offset);
2438 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_GLOB_DAT);
2442 loc = htab->srelgot->contents;
2443 loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
2444 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2447 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2449 Elf_Internal_Rela rela;
2452 /* This symbols needs a copy reloc. Set it up. */
2454 if (h->dynindx == -1
2455 || (h->root.type != bfd_link_hash_defined
2456 && h->root.type != bfd_link_hash_defweak)
2457 || htab->srelbss == NULL)
2460 rela.r_offset = (h->root.u.def.value
2461 + h->root.u.def.section->output_section->vma
2462 + h->root.u.def.section->output_offset);
2463 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_COPY);
2465 loc = htab->srelbss->contents;
2466 loc += htab->srelbss->reloc_count++ * sizeof (Elf32_External_Rela);
2467 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2470 /* Mark some specially defined symbols as absolute. */
2471 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2472 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
2473 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2474 sym->st_shndx = SHN_ABS;
2479 /* Used to decide how to sort relocs in an optimal manner for the
2480 dynamic linker, before writing them out. */
2482 static enum elf_reloc_type_class
2483 elf_s390_reloc_type_class (rela)
2484 const Elf_Internal_Rela *rela;
2486 switch ((int) ELF32_R_TYPE (rela->r_info))
2488 case R_390_RELATIVE:
2489 return reloc_class_relative;
2490 case R_390_JMP_SLOT:
2491 return reloc_class_plt;
2493 return reloc_class_copy;
2495 return reloc_class_normal;
2499 /* Finish up the dynamic sections. */
2502 elf_s390_finish_dynamic_sections (output_bfd, info)
2504 struct bfd_link_info *info;
2506 struct elf_s390_link_hash_table *htab;
2510 htab = elf_s390_hash_table (info);
2511 dynobj = htab->elf.dynobj;
2512 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2514 if (htab->elf.dynamic_sections_created)
2516 Elf32_External_Dyn *dyncon, *dynconend;
2518 if (sdyn == NULL || htab->sgot == NULL)
2521 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2522 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2523 for (; dyncon < dynconend; dyncon++)
2525 Elf_Internal_Dyn dyn;
2528 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2536 dyn.d_un.d_ptr = htab->sgot->output_section->vma;
2540 dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
2544 s = htab->srelplt->output_section;
2545 if (s->_cooked_size != 0)
2546 dyn.d_un.d_val = s->_cooked_size;
2548 dyn.d_un.d_val = s->_raw_size;
2552 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2555 /* Fill in the special first entry in the procedure linkage table. */
2556 if (htab->splt && htab->splt->_raw_size > 0)
2558 memset (htab->splt->contents, 0, PLT_FIRST_ENTRY_SIZE);
2561 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD0,
2562 htab->splt->contents );
2563 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD1,
2564 htab->splt->contents +4 );
2565 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD2,
2566 htab->splt->contents +8 );
2567 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD3,
2568 htab->splt->contents +12 );
2569 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD4,
2570 htab->splt->contents +16 );
2574 bfd_put_32 (output_bfd, (bfd_vma)PLT_FIRST_ENTRY_WORD0,
2575 htab->splt->contents );
2576 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1,
2577 htab->splt->contents +4 );
2578 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD2,
2579 htab->splt->contents +8 );
2580 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3,
2581 htab->splt->contents +12 );
2582 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4,
2583 htab->splt->contents +16 );
2584 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5,
2585 htab->splt->contents +20 );
2586 bfd_put_32 (output_bfd,
2587 htab->sgotplt->output_section->vma
2588 + htab->sgotplt->output_offset,
2589 htab->splt->contents + 24);
2591 elf_section_data (htab->splt->output_section)
2592 ->this_hdr.sh_entsize = 4;
2599 /* Fill in the first three entries in the global offset table. */
2600 if (htab->sgotplt->_raw_size > 0)
2602 bfd_put_32 (output_bfd,
2603 (sdyn == NULL ? (bfd_vma) 0
2604 : sdyn->output_section->vma + sdyn->output_offset),
2605 htab->sgotplt->contents);
2606 /* One entry for shared object struct ptr. */
2607 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 4);
2608 /* One entry for _dl_runtime_resolve. */
2609 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8);
2612 elf_section_data (htab->sgotplt->output_section)
2613 ->this_hdr.sh_entsize = 4;
2619 elf_s390_object_p (abfd)
2622 return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_31);
2626 elf_s390_grok_prstatus (abfd, note)
2628 Elf_Internal_Note * note;
2631 unsigned int raw_size;
2633 switch (note->descsz)
2638 case 224: /* S/390 Linux. */
2640 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2643 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
2651 /* Make a ".reg/999" section. */
2652 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2653 raw_size, note->descpos + offset);
2656 #define TARGET_BIG_SYM bfd_elf32_s390_vec
2657 #define TARGET_BIG_NAME "elf32-s390"
2658 #define ELF_ARCH bfd_arch_s390
2659 #define ELF_MACHINE_CODE EM_S390
2660 #define ELF_MACHINE_ALT1 EM_S390_OLD
2661 #define ELF_MAXPAGESIZE 0x1000
2663 #define elf_backend_can_gc_sections 1
2664 #define elf_backend_can_refcount 1
2665 #define elf_backend_want_got_plt 1
2666 #define elf_backend_plt_readonly 1
2667 #define elf_backend_want_plt_sym 0
2668 #define elf_backend_got_header_size 12
2669 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
2670 #define elf_backend_rela_normal 1
2672 #define elf_info_to_howto elf_s390_info_to_howto
2674 #define bfd_elf32_bfd_is_local_label_name elf_s390_is_local_label_name
2675 #define bfd_elf32_bfd_link_hash_table_create elf_s390_link_hash_table_create
2676 #define bfd_elf32_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
2678 #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
2679 #define elf_backend_check_relocs elf_s390_check_relocs
2680 #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
2681 #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
2682 #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
2683 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
2684 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
2685 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
2686 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
2687 #define elf_backend_relocate_section elf_s390_relocate_section
2688 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
2689 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
2690 #define elf_backend_grok_prstatus elf_s390_grok_prstatus
2692 #define elf_backend_object_p elf_s390_object_p
2694 #include "elf32-target.h"