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 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 boolean create_got_section
39 PARAMS((bfd *, struct bfd_link_info *));
40 static boolean elf_s390_create_dynamic_sections
41 PARAMS((bfd *, struct bfd_link_info *));
42 static void elf_s390_copy_indirect_symbol
43 PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
44 static boolean elf_s390_check_relocs
45 PARAMS ((bfd *, struct bfd_link_info *, asection *,
46 const Elf_Internal_Rela *));
47 static asection *elf_s390_gc_mark_hook
48 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
49 struct elf_link_hash_entry *, Elf_Internal_Sym *));
50 static boolean elf_s390_gc_sweep_hook
51 PARAMS ((bfd *, struct bfd_link_info *, asection *,
52 const Elf_Internal_Rela *));
53 static boolean elf_s390_adjust_dynamic_symbol
54 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
55 static boolean allocate_dynrelocs
56 PARAMS ((struct elf_link_hash_entry *, PTR));
57 static boolean readonly_dynrelocs
58 PARAMS ((struct elf_link_hash_entry *, PTR));
59 static boolean elf_s390_size_dynamic_sections
60 PARAMS ((bfd *, struct bfd_link_info *));
61 static boolean elf_s390_relocate_section
62 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
63 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
64 static boolean elf_s390_finish_dynamic_symbol
65 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
67 static enum elf_reloc_type_class elf_s390_reloc_type_class
68 PARAMS ((const Elf_Internal_Rela *));
69 static boolean elf_s390_finish_dynamic_sections
70 PARAMS ((bfd *, struct bfd_link_info *));
71 static boolean elf_s390_object_p PARAMS ((bfd *));
72 static boolean elf_s390_grok_prstatus PARAMS ((bfd *, Elf_Internal_Note *));
76 /* The relocation "howto" table. */
78 static reloc_howto_type elf_howto_table[] =
80 HOWTO (R_390_NONE, /* type */
82 0, /* size (0 = byte, 1 = short, 2 = long) */
84 false, /* pc_relative */
86 complain_overflow_dont, /* complain_on_overflow */
87 bfd_elf_generic_reloc, /* special_function */
88 "R_390_NONE", /* name */
89 false, /* partial_inplace */
92 false), /* pcrel_offset */
94 HOWTO(R_390_8, 0, 0, 8, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_8", false, 0,0x000000ff, false),
95 HOWTO(R_390_12, 0, 1, 12, false, 0, complain_overflow_dont, bfd_elf_generic_reloc, "R_390_12", false, 0,0x00000fff, false),
96 HOWTO(R_390_16, 0, 1, 16, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_16", false, 0,0x0000ffff, false),
97 HOWTO(R_390_32, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_32", false, 0,0xffffffff, false),
98 HOWTO(R_390_PC32, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC32", false, 0,0xffffffff, true),
99 HOWTO(R_390_GOT12, 0, 1, 12, false, 0, complain_overflow_dont, bfd_elf_generic_reloc, "R_390_GOT12", false, 0,0x00000fff, false),
100 HOWTO(R_390_GOT32, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOT32", false, 0,0xffffffff, false),
101 HOWTO(R_390_PLT32, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT32", false, 0,0xffffffff, true),
102 HOWTO(R_390_COPY, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_COPY", false, 0,0xffffffff, false),
103 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),
104 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),
105 HOWTO(R_390_RELATIVE, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_RELATIVE",false, 0,0xffffffff, false),
106 HOWTO(R_390_GOTOFF, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTOFF", false, 0,0xffffffff, false),
107 HOWTO(R_390_GOTPC, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTPC", false, 0,0xffffffff, true),
108 HOWTO(R_390_GOT16, 0, 1, 16, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOT16", false, 0,0x0000ffff, false),
109 HOWTO(R_390_PC16, 0, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC16", false, 0,0x0000ffff, true),
110 HOWTO(R_390_PC16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC16DBL", false, 0,0x0000ffff, true),
111 HOWTO(R_390_PLT16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT16DBL", false, 0,0x0000ffff, true),
112 HOWTO(R_390_PC32DBL, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC32DBL", false, 0,0xffffffff, true),
113 HOWTO(R_390_PLT32DBL, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT32DBL", false, 0,0xffffffff, true),
114 HOWTO(R_390_GOTPCDBL, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTPCDBL", false, 0,0xffffffff, true),
115 HOWTO(R_390_GOTENT, 1, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTENT", false, 0,0xffffffff, true),
118 /* GNU extension to record C++ vtable hierarchy. */
119 static reloc_howto_type elf32_s390_vtinherit_howto =
120 HOWTO (R_390_GNU_VTINHERIT, 0,2,0,false,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", false,0, 0, false);
121 static reloc_howto_type elf32_s390_vtentry_howto =
122 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);
124 static reloc_howto_type *
125 elf_s390_reloc_type_lookup (abfd, code)
126 bfd *abfd ATTRIBUTE_UNUSED;
127 bfd_reloc_code_real_type code;
132 return &elf_howto_table[(int) R_390_NONE];
134 return &elf_howto_table[(int) R_390_8];
135 case BFD_RELOC_390_12:
136 return &elf_howto_table[(int) R_390_12];
138 return &elf_howto_table[(int) R_390_16];
140 return &elf_howto_table[(int) R_390_32];
142 return &elf_howto_table[(int) R_390_32];
143 case BFD_RELOC_32_PCREL:
144 return &elf_howto_table[(int) R_390_PC32];
145 case BFD_RELOC_390_GOT12:
146 return &elf_howto_table[(int) R_390_GOT12];
147 case BFD_RELOC_32_GOT_PCREL:
148 return &elf_howto_table[(int) R_390_GOT32];
149 case BFD_RELOC_390_PLT32:
150 return &elf_howto_table[(int) R_390_PLT32];
151 case BFD_RELOC_390_COPY:
152 return &elf_howto_table[(int) R_390_COPY];
153 case BFD_RELOC_390_GLOB_DAT:
154 return &elf_howto_table[(int) R_390_GLOB_DAT];
155 case BFD_RELOC_390_JMP_SLOT:
156 return &elf_howto_table[(int) R_390_JMP_SLOT];
157 case BFD_RELOC_390_RELATIVE:
158 return &elf_howto_table[(int) R_390_RELATIVE];
159 case BFD_RELOC_32_GOTOFF:
160 return &elf_howto_table[(int) R_390_GOTOFF];
161 case BFD_RELOC_390_GOTPC:
162 return &elf_howto_table[(int) R_390_GOTPC];
163 case BFD_RELOC_390_GOT16:
164 return &elf_howto_table[(int) R_390_GOT16];
165 case BFD_RELOC_16_PCREL:
166 return &elf_howto_table[(int) R_390_PC16];
167 case BFD_RELOC_390_PC16DBL:
168 return &elf_howto_table[(int) R_390_PC16DBL];
169 case BFD_RELOC_390_PLT16DBL:
170 return &elf_howto_table[(int) R_390_PLT16DBL];
171 case BFD_RELOC_390_PC32DBL:
172 return &elf_howto_table[(int) R_390_PC32DBL];
173 case BFD_RELOC_390_PLT32DBL:
174 return &elf_howto_table[(int) R_390_PLT32DBL];
175 case BFD_RELOC_390_GOTPCDBL:
176 return &elf_howto_table[(int) R_390_GOTPCDBL];
177 case BFD_RELOC_390_GOTENT:
178 return &elf_howto_table[(int) R_390_GOTENT];
179 case BFD_RELOC_VTABLE_INHERIT:
180 return &elf32_s390_vtinherit_howto;
181 case BFD_RELOC_VTABLE_ENTRY:
182 return &elf32_s390_vtentry_howto;
189 /* We need to use ELF32_R_TYPE so we have our own copy of this function,
190 and elf32-s390.c has its own copy. */
193 elf_s390_info_to_howto (abfd, cache_ptr, dst)
194 bfd *abfd ATTRIBUTE_UNUSED;
196 Elf_Internal_Rela *dst;
198 switch (ELF32_R_TYPE(dst->r_info))
200 case R_390_GNU_VTINHERIT:
201 cache_ptr->howto = &elf32_s390_vtinherit_howto;
204 case R_390_GNU_VTENTRY:
205 cache_ptr->howto = &elf32_s390_vtentry_howto;
209 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_390_max);
210 cache_ptr->howto = &elf_howto_table[ELF32_R_TYPE(dst->r_info)];
215 elf_s390_is_local_label_name (abfd, name)
219 if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
222 return _bfd_elf_is_local_label_name (abfd, name);
225 /* Functions for the 390 ELF linker. */
227 /* The name of the dynamic interpreter. This is put in the .interp
230 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
232 /* The size in bytes of the first entry in the procedure linkage table. */
233 #define PLT_FIRST_ENTRY_SIZE 32
234 /* The size in bytes of an entry in the procedure linkage table. */
235 #define PLT_ENTRY_SIZE 32
237 #define GOT_ENTRY_SIZE 4
239 /* The first three entries in a procedure linkage table are reserved,
240 and the initial contents are unimportant (we zero them out).
241 Subsequent entries look like this. See the SVR4 ABI 386
242 supplement to see how this works. */
244 /* For the s390, simple addr offset can only be 0 - 4096.
245 To use the full 2 GB address space, several instructions
246 are needed to load an address in a register and execute
247 a branch( or just saving the address)
249 Furthermore, only r 0 and 1 are free to use!!! */
251 /* The first 3 words in the GOT are then reserved.
252 Word 0 is the address of the dynamic table.
253 Word 1 is a pointer to a structure describing the object
254 Word 2 is used to point to the loader entry address.
256 The code for position independand PLT entries looks like this:
258 r12 holds addr of the current GOT at entry to the PLT
260 The GOT holds the address in the PLT to be executed.
261 The loader then gets:
262 24(15) = Pointer to the structure describing the object.
263 28(15) = Offset in symbol table
265 The loader must then find the module where the function is
266 and insert the address in the GOT.
268 Note: 390 can only address +- 64 K relative.
269 We check if offset > 65536, then make a relative branch -64xxx
270 back to a previous defined branch
272 PLT1: BASR 1,0 # 2 bytes
273 L 1,22(1) # 4 bytes Load offset in GOT in r 1
274 L 1,(1,12) # 4 bytes Load address from GOT in r1
275 BCR 15,1 # 2 bytes Jump to address
276 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
277 L 1,14(1) # 4 bytes Load offset in symol table in r1
278 BRC 15,-x # 4 bytes Jump to start of PLT
279 .word 0 # 2 bytes filler
280 .long ? # 4 bytes offset in GOT
281 .long ? # 4 bytes offset into symbol table
283 This was the general case. There are two additional, optimizes PLT
284 definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768.
285 First the one for GOT offsets < 4096:
287 PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1
288 BCR 15,1 # 2 bytes Jump to address
289 .word 0,0,0 # 6 bytes filler
290 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
291 L 1,14(1) # 4 bytes Load offset in symbol table in r1
292 BRC 15,-x # 4 bytes Jump to start of PLT
293 .word 0,0,0 # 6 bytes filler
294 .long ? # 4 bytes offset into symbol table
296 Second the one for GOT offsets < 32768:
298 PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1
299 L 1,(1,12) # 4 bytes Load address from GOT to r1
300 BCR 15,1 # 2 bytes Jump to address
301 .word 0 # 2 bytes filler
302 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
303 L 1,14(1) # 4 bytes Load offset in symbol table in r1
304 BRC 15,-x # 4 bytes Jump to start of PLT
305 .word 0,0,0 # 6 bytes filler
306 .long ? # 4 bytes offset into symbol table
308 Total = 32 bytes per PLT entry
310 The code for static build PLT entries looks like this:
312 PLT1: BASR 1,0 # 2 bytes
313 L 1,22(1) # 4 bytes Load address of GOT entry
314 L 1,0(0,1) # 4 bytes Load address from GOT in r1
315 BCR 15,1 # 2 bytes Jump to address
316 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
317 L 1,14(1) # 4 bytes Load offset in symbol table in r1
318 BRC 15,-x # 4 bytes Jump to start of PLT
319 .word 0 # 2 bytes filler
320 .long ? # 4 bytes address of GOT entry
321 .long ? # 4 bytes offset into symbol table */
323 #define PLT_PIC_ENTRY_WORD0 0x0d105810
324 #define PLT_PIC_ENTRY_WORD1 0x10165811
325 #define PLT_PIC_ENTRY_WORD2 0xc00007f1
326 #define PLT_PIC_ENTRY_WORD3 0x0d105810
327 #define PLT_PIC_ENTRY_WORD4 0x100ea7f4
329 #define PLT_PIC12_ENTRY_WORD0 0x5810c000
330 #define PLT_PIC12_ENTRY_WORD1 0x07f10000
331 #define PLT_PIC12_ENTRY_WORD2 0x00000000
332 #define PLT_PIC12_ENTRY_WORD3 0x0d105810
333 #define PLT_PIC12_ENTRY_WORD4 0x100ea7f4
335 #define PLT_PIC16_ENTRY_WORD0 0xa7180000
336 #define PLT_PIC16_ENTRY_WORD1 0x5811c000
337 #define PLT_PIC16_ENTRY_WORD2 0x07f10000
338 #define PLT_PIC16_ENTRY_WORD3 0x0d105810
339 #define PLT_PIC16_ENTRY_WORD4 0x100ea7f4
341 #define PLT_ENTRY_WORD0 0x0d105810
342 #define PLT_ENTRY_WORD1 0x10165810
343 #define PLT_ENTRY_WORD2 0x100007f1
344 #define PLT_ENTRY_WORD3 0x0d105810
345 #define PLT_ENTRY_WORD4 0x100ea7f4
347 /* The first PLT entry pushes the offset into the symbol table
348 from R1 onto the stack at 8(15) and the loader object info
349 at 12(15), loads the loader address in R1 and jumps to it. */
351 /* The first entry in the PLT for PIC code:
354 ST 1,28(15) # R1 has offset into symbol table
355 L 1,4(12) # Get loader ino(object struct address)
356 ST 1,24(15) # Store address
357 L 1,8(12) # Entry address of loader in R1
358 BR 1 # Jump to loader
360 The first entry in the PLT for static code:
363 ST 1,28(15) # R1 has offset into symbol table
365 L 1,18(0,1) # Get address of GOT
366 MVC 24(4,15),4(1) # Move loader ino to stack
367 L 1,8(1) # Get address of loader
368 BR 1 # Jump to loader
370 .long got # address of GOT */
372 #define PLT_PIC_FIRST_ENTRY_WORD0 0x5010f01c
373 #define PLT_PIC_FIRST_ENTRY_WORD1 0x5810c004
374 #define PLT_PIC_FIRST_ENTRY_WORD2 0x5010f018
375 #define PLT_PIC_FIRST_ENTRY_WORD3 0x5810c008
376 #define PLT_PIC_FIRST_ENTRY_WORD4 0x07f10000
378 #define PLT_FIRST_ENTRY_WORD0 0x5010f01c
379 #define PLT_FIRST_ENTRY_WORD1 0x0d105810
380 #define PLT_FIRST_ENTRY_WORD2 0x1012D203
381 #define PLT_FIRST_ENTRY_WORD3 0xf0181004
382 #define PLT_FIRST_ENTRY_WORD4 0x58101008
383 #define PLT_FIRST_ENTRY_WORD5 0x07f10000
385 /* The s390 linker needs to keep track of the number of relocs that it
386 decides to copy as dynamic relocs in check_relocs for each symbol.
387 This is so that it can later discard them if they are found to be
388 unnecessary. We store the information in a field extending the
389 regular ELF linker hash table. */
391 struct elf_s390_dyn_relocs
393 struct elf_s390_dyn_relocs *next;
395 /* The input section of the reloc. */
398 /* Total number of relocs copied for the input section. */
401 /* Number of pc-relative relocs copied for the input section. */
402 bfd_size_type pc_count;
405 /* s390 ELF linker hash entry. */
407 struct elf_s390_link_hash_entry
409 struct elf_link_hash_entry elf;
411 /* Track dynamic relocs copied for this symbol. */
412 struct elf_s390_dyn_relocs *dyn_relocs;
415 /* s390 ELF linker hash table. */
417 struct elf_s390_link_hash_table
419 struct elf_link_hash_table elf;
421 /* Short-cuts to get to dynamic linker sections. */
430 /* Small local sym to section mapping cache. */
431 struct sym_sec_cache sym_sec;
434 /* Get the s390 ELF linker hash table from a link_info structure. */
436 #define elf_s390_hash_table(p) \
437 ((struct elf_s390_link_hash_table *) ((p)->hash))
439 /* Create an entry in an s390 ELF linker hash table. */
441 static struct bfd_hash_entry *
442 link_hash_newfunc (entry, table, string)
443 struct bfd_hash_entry *entry;
444 struct bfd_hash_table *table;
447 /* Allocate the structure if it has not already been allocated by a
451 entry = bfd_hash_allocate (table,
452 sizeof (struct elf_s390_link_hash_entry));
457 /* Call the allocation method of the superclass. */
458 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
461 struct elf_s390_link_hash_entry *eh;
463 eh = (struct elf_s390_link_hash_entry *) entry;
464 eh->dyn_relocs = NULL;
470 /* Create an s390 ELF linker hash table. */
472 static struct bfd_link_hash_table *
473 elf_s390_link_hash_table_create (abfd)
476 struct elf_s390_link_hash_table *ret;
477 bfd_size_type amt = sizeof (struct elf_s390_link_hash_table);
479 ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt);
483 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc))
496 ret->sym_sec.abfd = NULL;
498 return &ret->elf.root;
501 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
502 shortcuts to them in our hash table. */
505 create_got_section (dynobj, info)
507 struct bfd_link_info *info;
509 struct elf_s390_link_hash_table *htab;
511 if (! _bfd_elf_create_got_section (dynobj, info))
514 htab = elf_s390_hash_table (info);
515 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
516 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
517 if (!htab->sgot || !htab->sgotplt)
520 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
521 if (htab->srelgot == NULL
522 || ! bfd_set_section_flags (dynobj, htab->srelgot,
523 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
524 | SEC_IN_MEMORY | SEC_LINKER_CREATED
526 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
531 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
532 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
536 elf_s390_create_dynamic_sections (dynobj, info)
538 struct bfd_link_info *info;
540 struct elf_s390_link_hash_table *htab;
542 htab = elf_s390_hash_table (info);
543 if (!htab->sgot && !create_got_section (dynobj, info))
546 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
549 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
550 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
551 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
553 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
555 if (!htab->splt || !htab->srelplt || !htab->sdynbss
556 || (!info->shared && !htab->srelbss))
562 /* Copy the extra info we tack onto an elf_link_hash_entry. */
565 elf_s390_copy_indirect_symbol (dir, ind)
566 struct elf_link_hash_entry *dir, *ind;
568 struct elf_s390_link_hash_entry *edir, *eind;
570 edir = (struct elf_s390_link_hash_entry *) dir;
571 eind = (struct elf_s390_link_hash_entry *) ind;
573 if (eind->dyn_relocs != NULL)
575 if (edir->dyn_relocs != NULL)
577 struct elf_s390_dyn_relocs **pp;
578 struct elf_s390_dyn_relocs *p;
580 if (ind->root.type == bfd_link_hash_indirect)
583 /* Add reloc counts against the weak sym to the strong sym
584 list. Merge any entries against the same section. */
585 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
587 struct elf_s390_dyn_relocs *q;
589 for (q = edir->dyn_relocs; q != NULL; q = q->next)
590 if (q->sec == p->sec)
592 q->pc_count += p->pc_count;
593 q->count += p->count;
600 *pp = edir->dyn_relocs;
603 edir->dyn_relocs = eind->dyn_relocs;
604 eind->dyn_relocs = NULL;
607 _bfd_elf_link_hash_copy_indirect (dir, ind);
610 /* Look through the relocs for a section during the first phase, and
611 allocate space in the global offset table or procedure linkage
615 elf_s390_check_relocs (abfd, info, sec, relocs)
617 struct bfd_link_info *info;
619 const Elf_Internal_Rela *relocs;
621 struct elf_s390_link_hash_table *htab;
622 Elf_Internal_Shdr *symtab_hdr;
623 struct elf_link_hash_entry **sym_hashes;
624 const Elf_Internal_Rela *rel;
625 const Elf_Internal_Rela *rel_end;
628 if (info->relocateable)
631 htab = elf_s390_hash_table (info);
632 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
633 sym_hashes = elf_sym_hashes (abfd);
637 rel_end = relocs + sec->reloc_count;
638 for (rel = relocs; rel < rel_end; rel++)
640 unsigned long r_symndx;
641 struct elf_link_hash_entry *h;
643 r_symndx = ELF32_R_SYM (rel->r_info);
645 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
647 (*_bfd_error_handler) (_("%s: bad symbol index: %d"),
648 bfd_archive_filename (abfd),
653 if (r_symndx < symtab_hdr->sh_info)
656 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
658 switch (ELF32_R_TYPE (rel->r_info))
664 /* This symbol requires a global offset table entry. */
667 h->got.refcount += 1;
671 bfd_signed_vma *local_got_refcounts;
673 /* This is a global offset table entry for a local symbol. */
674 local_got_refcounts = elf_local_got_refcounts (abfd);
675 if (local_got_refcounts == NULL)
679 size = symtab_hdr->sh_info;
680 size *= sizeof (bfd_signed_vma);
681 local_got_refcounts = ((bfd_signed_vma *)
682 bfd_zalloc (abfd, size));
683 if (local_got_refcounts == NULL)
685 elf_local_got_refcounts (abfd) = local_got_refcounts;
687 local_got_refcounts[r_symndx] += 1;
694 if (htab->sgot == NULL)
696 if (htab->elf.dynobj == NULL)
697 htab->elf.dynobj = abfd;
698 if (!create_got_section (htab->elf.dynobj, info))
706 /* This symbol requires a procedure linkage table entry. We
707 actually build the entry in adjust_dynamic_symbol,
708 because this might be a case of linking PIC code which is
709 never referenced by a dynamic object, in which case we
710 don't need to generate a procedure linkage table entry
713 /* If this is a local symbol, we resolve it directly without
714 creating a procedure linkage table entry. */
718 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
719 h->plt.refcount += 1;
729 if (h != NULL && !info->shared)
731 /* If this reloc is in a read-only section, we might
732 need a copy reloc. We can't check reliably at this
733 stage whether the section is read-only, as input
734 sections have not yet been mapped to output sections.
735 Tentatively set the flag for now, and correct in
736 adjust_dynamic_symbol. */
737 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
739 /* We may need a .plt entry if the function this reloc
740 refers to is in a shared lib. */
741 h->plt.refcount += 1;
744 /* If we are creating a shared library, and this is a reloc
745 against a global symbol, or a non PC relative reloc
746 against a local symbol, then we need to copy the reloc
747 into the shared library. However, if we are linking with
748 -Bsymbolic, we do not need to copy a reloc against a
749 global symbol which is defined in an object we are
750 including in the link (i.e., DEF_REGULAR is set). At
751 this point we have not seen all the input files, so it is
752 possible that DEF_REGULAR is not set now but will be set
753 later (it is never cleared). In case of a weak definition,
754 DEF_REGULAR may be cleared later by a strong definition in
755 a shared library. We account for that possibility below by
756 storing information in the relocs_copied field of the hash
757 table entry. A similar situation occurs when creating
758 shared libraries and symbol visibility changes render the
761 If on the other hand, we are creating an executable, we
762 may need to keep relocations for symbols satisfied by a
763 dynamic library if we manage to avoid copy relocs for the
766 && (sec->flags & SEC_ALLOC) != 0
767 && ((ELF32_R_TYPE (rel->r_info) != R_390_PC16
768 && ELF32_R_TYPE (rel->r_info) != R_390_PC16DBL
769 && ELF32_R_TYPE (rel->r_info) != R_390_PC32DBL
770 && ELF32_R_TYPE (rel->r_info) != R_390_PC32)
773 || h->root.type == bfd_link_hash_defweak
774 || (h->elf_link_hash_flags
775 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
777 && (sec->flags & SEC_ALLOC) != 0
779 && (h->root.type == bfd_link_hash_defweak
780 || (h->elf_link_hash_flags
781 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
783 struct elf_s390_dyn_relocs *p;
784 struct elf_s390_dyn_relocs **head;
786 /* We must copy these reloc types into the output file.
787 Create a reloc section in dynobj and make room for
794 name = (bfd_elf_string_from_elf_section
796 elf_elfheader (abfd)->e_shstrndx,
797 elf_section_data (sec)->rel_hdr.sh_name));
801 if (strncmp (name, ".rela", 5) != 0
802 || strcmp (bfd_get_section_name (abfd, sec),
805 (*_bfd_error_handler)
806 (_("%s: bad relocation section name `%s\'"),
807 bfd_archive_filename (abfd), name);
810 if (htab->elf.dynobj == NULL)
811 htab->elf.dynobj = abfd;
813 dynobj = htab->elf.dynobj;
814 sreloc = bfd_get_section_by_name (dynobj, name);
819 sreloc = bfd_make_section (dynobj, name);
820 flags = (SEC_HAS_CONTENTS | SEC_READONLY
821 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
822 if ((sec->flags & SEC_ALLOC) != 0)
823 flags |= SEC_ALLOC | SEC_LOAD;
825 || ! bfd_set_section_flags (dynobj, sreloc, flags)
826 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
829 elf_section_data (sec)->sreloc = sreloc;
832 /* If this is a global symbol, we count the number of
833 relocations we need for this symbol. */
836 head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs;
840 /* Track dynamic relocs needed for local syms too.
841 We really need local syms available to do this
845 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
850 head = ((struct elf_s390_dyn_relocs **)
851 &elf_section_data (s)->local_dynrel);
855 if (p == NULL || p->sec != sec)
857 bfd_size_type amt = sizeof *p;
858 p = ((struct elf_s390_dyn_relocs *)
859 bfd_alloc (htab->elf.dynobj, amt));
870 if (ELF32_R_TYPE (rel->r_info) == R_390_PC16
871 || ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL
872 || ELF32_R_TYPE (rel->r_info) == R_390_PC32DBL
873 || ELF32_R_TYPE (rel->r_info) == R_390_PC32)
878 /* This relocation describes the C++ object vtable hierarchy.
879 Reconstruct it for later use during GC. */
880 case R_390_GNU_VTINHERIT:
881 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
885 /* This relocation describes which C++ vtable entries are actually
886 used. Record for later use during GC. */
887 case R_390_GNU_VTENTRY:
888 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
900 /* Return the section that should be marked against GC for a given
904 elf_s390_gc_mark_hook (sec, info, rel, h, sym)
906 struct bfd_link_info *info ATTRIBUTE_UNUSED;
907 Elf_Internal_Rela *rel;
908 struct elf_link_hash_entry *h;
909 Elf_Internal_Sym *sym;
913 switch (ELF32_R_TYPE (rel->r_info))
915 case R_390_GNU_VTINHERIT:
916 case R_390_GNU_VTENTRY:
920 switch (h->root.type)
922 case bfd_link_hash_defined:
923 case bfd_link_hash_defweak:
924 return h->root.u.def.section;
926 case bfd_link_hash_common:
927 return h->root.u.c.p->section;
935 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
940 /* Update the got entry reference counts for the section being removed. */
943 elf_s390_gc_sweep_hook (abfd, info, sec, relocs)
945 struct bfd_link_info *info;
947 const Elf_Internal_Rela *relocs;
949 Elf_Internal_Shdr *symtab_hdr;
950 struct elf_link_hash_entry **sym_hashes;
951 bfd_signed_vma *local_got_refcounts;
952 const Elf_Internal_Rela *rel, *relend;
953 unsigned long r_symndx;
954 struct elf_link_hash_entry *h;
956 elf_section_data (sec)->local_dynrel = NULL;
958 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
959 sym_hashes = elf_sym_hashes (abfd);
960 local_got_refcounts = elf_local_got_refcounts (abfd);
962 relend = relocs + sec->reloc_count;
963 for (rel = relocs; rel < relend; rel++)
964 switch (ELF32_R_TYPE (rel->r_info))
973 r_symndx = ELF32_R_SYM (rel->r_info);
974 if (r_symndx >= symtab_hdr->sh_info)
976 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
977 if (h->got.refcount > 0)
978 h->got.refcount -= 1;
980 else if (local_got_refcounts != NULL)
982 if (local_got_refcounts[r_symndx] > 0)
983 local_got_refcounts[r_symndx] -= 1;
995 r_symndx = ELF32_R_SYM (rel->r_info);
996 if (r_symndx >= symtab_hdr->sh_info)
998 struct elf_s390_link_hash_entry *eh;
999 struct elf_s390_dyn_relocs **pp;
1000 struct elf_s390_dyn_relocs *p;
1002 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1004 if (!info->shared && h->plt.refcount > 0)
1005 h->plt.refcount -= 1;
1007 eh = (struct elf_s390_link_hash_entry *) h;
1009 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1012 if (ELF32_R_TYPE (rel->r_info) == R_390_PC16
1013 || ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL
1014 || ELF32_R_TYPE (rel->r_info) == R_390_PC32DBL
1015 || ELF32_R_TYPE (rel->r_info) == R_390_PC32)
1025 case R_390_PLT16DBL:
1026 case R_390_PLT32DBL:
1028 r_symndx = ELF32_R_SYM (rel->r_info);
1029 if (r_symndx >= symtab_hdr->sh_info)
1031 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1032 if (h->plt.refcount > 0)
1033 h->plt.refcount -= 1;
1044 /* Adjust a symbol defined by a dynamic object and referenced by a
1045 regular object. The current definition is in some section of the
1046 dynamic object, but we're not including those sections. We have to
1047 change the definition to something the rest of the link can
1051 elf_s390_adjust_dynamic_symbol (info, h)
1052 struct bfd_link_info *info;
1053 struct elf_link_hash_entry *h;
1055 struct elf_s390_link_hash_table *htab;
1056 struct elf_s390_link_hash_entry * eh;
1057 struct elf_s390_dyn_relocs *p;
1059 unsigned int power_of_two;
1061 /* If this is a function, put it in the procedure linkage table. We
1062 will fill in the contents of the procedure linkage table later
1063 (although we could actually do it here). */
1064 if (h->type == STT_FUNC
1065 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1067 if (h->plt.refcount <= 0
1069 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
1070 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
1071 && h->root.type != bfd_link_hash_undefweak
1072 && h->root.type != bfd_link_hash_undefined))
1074 /* This case can occur if we saw a PLT32 reloc in an input
1075 file, but the symbol was never referred to by a dynamic
1076 object, or if all references were garbage collected. In
1077 such a case, we don't actually need to build a procedure
1078 linkage table, and we can just do a PC32 reloc instead. */
1079 h->plt.offset = (bfd_vma) -1;
1080 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1086 /* It's possible that we incorrectly decided a .plt reloc was
1087 needed for an R_390_PC32 reloc to a non-function sym in
1088 check_relocs. We can't decide accurately between function and
1089 non-function syms in check-relocs; Objects loaded later in
1090 the link may change h->type. So fix it now. */
1091 h->plt.offset = (bfd_vma) -1;
1093 /* If this is a weak symbol, and there is a real definition, the
1094 processor independent code will have arranged for us to see the
1095 real definition first, and we can just use the same value. */
1096 if (h->weakdef != NULL)
1098 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1099 || h->weakdef->root.type == bfd_link_hash_defweak);
1100 h->root.u.def.section = h->weakdef->root.u.def.section;
1101 h->root.u.def.value = h->weakdef->root.u.def.value;
1105 /* This is a reference to a symbol defined by a dynamic object which
1106 is not a function. */
1108 /* If we are creating a shared library, we must presume that the
1109 only references to the symbol are via the global offset table.
1110 For such cases we need not do anything here; the relocations will
1111 be handled correctly by relocate_section. */
1115 /* If there are no references to this symbol that do not use the
1116 GOT, we don't need to generate a copy reloc. */
1117 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
1120 /* If -z nocopyreloc was given, we won't generate them either. */
1121 if (info->nocopyreloc)
1123 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
1127 eh = (struct elf_s390_link_hash_entry *) h;
1128 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1130 s = p->sec->output_section;
1131 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1135 /* If we didn't find any dynamic relocs in read-only sections, then
1136 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1139 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
1143 /* We must allocate the symbol in our .dynbss section, which will
1144 become part of the .bss section of the executable. There will be
1145 an entry for this symbol in the .dynsym section. The dynamic
1146 object will contain position independent code, so all references
1147 from the dynamic object to this symbol will go through the global
1148 offset table. The dynamic linker will use the .dynsym entry to
1149 determine the address it must put in the global offset table, so
1150 both the dynamic object and the regular object will refer to the
1151 same memory location for the variable. */
1153 htab = elf_s390_hash_table (info);
1155 /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1156 copy the initial value out of the dynamic object and into the
1157 runtime process image. */
1158 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1160 htab->srelbss->_raw_size += sizeof (Elf32_External_Rela);
1161 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1164 /* We need to figure out the alignment required for this symbol. I
1165 have no idea how ELF linkers handle this. */
1166 power_of_two = bfd_log2 (h->size);
1167 if (power_of_two > 3)
1170 /* Apply the required alignment. */
1172 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
1173 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
1175 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
1179 /* Define the symbol as being at this point in the section. */
1180 h->root.u.def.section = s;
1181 h->root.u.def.value = s->_raw_size;
1183 /* Increment the section size to make room for the symbol. */
1184 s->_raw_size += h->size;
1189 /* This is the condition under which elf_s390_finish_dynamic_symbol
1190 will be called from elflink.h. If elflink.h doesn't call our
1191 finish_dynamic_symbol routine, we'll need to do something about
1192 initializing any .plt and .got entries in elf_s390_relocate_section. */
1193 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1195 && ((INFO)->shared \
1196 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1197 && ((H)->dynindx != -1 \
1198 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1200 /* Allocate space in .plt, .got and associated reloc sections for
1204 allocate_dynrelocs (h, inf)
1205 struct elf_link_hash_entry *h;
1208 struct bfd_link_info *info;
1209 struct elf_s390_link_hash_table *htab;
1210 struct elf_s390_link_hash_entry *eh;
1211 struct elf_s390_dyn_relocs *p;
1213 if (h->root.type == bfd_link_hash_indirect)
1216 if (h->root.type == bfd_link_hash_warning)
1217 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1219 info = (struct bfd_link_info *) inf;
1220 htab = elf_s390_hash_table (info);
1222 if (htab->elf.dynamic_sections_created
1223 && h->plt.refcount > 0)
1225 /* Make sure this symbol is output as a dynamic symbol.
1226 Undefined weak syms won't yet be marked as dynamic. */
1227 if (h->dynindx == -1
1228 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1230 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1234 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
1236 asection *s = htab->splt;
1238 /* If this is the first .plt entry, make room for the special
1240 if (s->_raw_size == 0)
1241 s->_raw_size += PLT_FIRST_ENTRY_SIZE;
1243 h->plt.offset = s->_raw_size;
1245 /* If this symbol is not defined in a regular file, and we are
1246 not generating a shared library, then set the symbol to this
1247 location in the .plt. This is required to make function
1248 pointers compare as equal between the normal executable and
1249 the shared library. */
1251 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1253 h->root.u.def.section = s;
1254 h->root.u.def.value = h->plt.offset;
1257 /* Make room for this entry. */
1258 s->_raw_size += PLT_ENTRY_SIZE;
1260 /* We also need to make an entry in the .got.plt section, which
1261 will be placed in the .got section by the linker script. */
1262 htab->sgotplt->_raw_size += GOT_ENTRY_SIZE;
1264 /* We also need to make an entry in the .rela.plt section. */
1265 htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
1269 h->plt.offset = (bfd_vma) -1;
1270 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1275 h->plt.offset = (bfd_vma) -1;
1276 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1279 if (h->got.refcount > 0)
1284 /* Make sure this symbol is output as a dynamic symbol.
1285 Undefined weak syms won't yet be marked as dynamic. */
1286 if (h->dynindx == -1
1287 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1289 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1294 h->got.offset = s->_raw_size;
1295 s->_raw_size += GOT_ENTRY_SIZE;
1296 dyn = htab->elf.dynamic_sections_created;
1297 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
1298 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
1301 h->got.offset = (bfd_vma) -1;
1303 eh = (struct elf_s390_link_hash_entry *) h;
1304 if (eh->dyn_relocs == NULL)
1307 /* In the shared -Bsymbolic case, discard space allocated for
1308 dynamic pc-relative relocs against symbols which turn out to be
1309 defined in regular objects. For the normal shared case, discard
1310 space for pc-relative relocs that have become local due to symbol
1311 visibility changes. */
1315 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
1316 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
1319 struct elf_s390_dyn_relocs **pp;
1321 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1323 p->count -= p->pc_count;
1334 /* For the non-shared case, discard space for relocs against
1335 symbols which turn out to need copy relocs or are not
1338 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
1339 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1340 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1341 || (htab->elf.dynamic_sections_created
1342 && (h->root.type == bfd_link_hash_undefweak
1343 || h->root.type == bfd_link_hash_undefined))))
1345 /* Make sure this symbol is output as a dynamic symbol.
1346 Undefined weak syms won't yet be marked as dynamic. */
1347 if (h->dynindx == -1
1348 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1350 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1354 /* If that succeeded, we know we'll be keeping all the
1356 if (h->dynindx != -1)
1360 eh->dyn_relocs = NULL;
1365 /* Finally, allocate space. */
1366 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1368 asection *sreloc = elf_section_data (p->sec)->sreloc;
1369 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
1375 /* Find any dynamic relocs that apply to read-only sections. */
1378 readonly_dynrelocs (h, inf)
1379 struct elf_link_hash_entry *h;
1382 struct elf_s390_link_hash_entry *eh;
1383 struct elf_s390_dyn_relocs *p;
1385 if (h->root.type == bfd_link_hash_warning)
1386 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1388 eh = (struct elf_s390_link_hash_entry *) h;
1389 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1391 asection *s = p->sec->output_section;
1393 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1395 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1397 info->flags |= DF_TEXTREL;
1399 /* Not an error, just cut short the traversal. */
1406 /* Set the sizes of the dynamic sections. */
1409 elf_s390_size_dynamic_sections (output_bfd, info)
1410 bfd *output_bfd ATTRIBUTE_UNUSED;
1411 struct bfd_link_info *info;
1413 struct elf_s390_link_hash_table *htab;
1419 htab = elf_s390_hash_table (info);
1420 dynobj = htab->elf.dynobj;
1424 if (htab->elf.dynamic_sections_created)
1426 /* Set the contents of the .interp section to the interpreter. */
1429 s = bfd_get_section_by_name (dynobj, ".interp");
1432 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1433 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1437 /* Set up .got offsets for local syms, and space for local dynamic
1439 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1441 bfd_signed_vma *local_got;
1442 bfd_signed_vma *end_local_got;
1443 bfd_size_type locsymcount;
1444 Elf_Internal_Shdr *symtab_hdr;
1447 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
1450 for (s = ibfd->sections; s != NULL; s = s->next)
1452 struct elf_s390_dyn_relocs *p;
1454 for (p = *((struct elf_s390_dyn_relocs **)
1455 &elf_section_data (s)->local_dynrel);
1459 if (!bfd_is_abs_section (p->sec)
1460 && bfd_is_abs_section (p->sec->output_section))
1462 /* Input section has been discarded, either because
1463 it is a copy of a linkonce section or due to
1464 linker script /DISCARD/, so we'll be discarding
1467 else if (p->count != 0)
1469 srela = elf_section_data (p->sec)->sreloc;
1470 srela->_raw_size += p->count * sizeof (Elf32_External_Rela);
1471 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
1472 info->flags |= DF_TEXTREL;
1477 local_got = elf_local_got_refcounts (ibfd);
1481 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
1482 locsymcount = symtab_hdr->sh_info;
1483 end_local_got = local_got + locsymcount;
1485 srela = htab->srelgot;
1486 for (; local_got < end_local_got; ++local_got)
1490 *local_got = s->_raw_size;
1491 s->_raw_size += GOT_ENTRY_SIZE;
1493 srela->_raw_size += sizeof (Elf32_External_Rela);
1496 *local_got = (bfd_vma) -1;
1500 /* Allocate global sym .plt and .got entries, and space for global
1501 sym dynamic relocs. */
1502 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
1504 /* We now have determined the sizes of the various dynamic sections.
1505 Allocate memory for them. */
1507 for (s = dynobj->sections; s != NULL; s = s->next)
1509 if ((s->flags & SEC_LINKER_CREATED) == 0)
1514 || s == htab->sgotplt)
1516 /* Strip this section if we don't need it; see the
1519 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
1521 if (s->_raw_size != 0 && s != htab->srelplt)
1524 /* We use the reloc_count field as a counter if we need
1525 to copy relocs into the output file. */
1530 /* It's not one of our sections, so don't allocate space. */
1534 if (s->_raw_size == 0)
1536 /* If we don't need this section, strip it from the
1537 output file. This is to handle .rela.bss and
1538 .rela.plt. We must create it in
1539 create_dynamic_sections, because it must be created
1540 before the linker maps input sections to output
1541 sections. The linker does that before
1542 adjust_dynamic_symbol is called, and it is that
1543 function which decides whether anything needs to go
1544 into these sections. */
1546 _bfd_strip_section_from_output (info, s);
1550 /* Allocate memory for the section contents. We use bfd_zalloc
1551 here in case unused entries are not reclaimed before the
1552 section's contents are written out. This should not happen,
1553 but this way if it does, we get a R_390_NONE reloc instead
1555 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1556 if (s->contents == NULL)
1560 if (htab->elf.dynamic_sections_created)
1562 /* Add some entries to the .dynamic section. We fill in the
1563 values later, in elf_s390_finish_dynamic_sections, but we
1564 must add the entries now so that we get the correct size for
1565 the .dynamic section. The DT_DEBUG entry is filled in by the
1566 dynamic linker and used by the debugger. */
1567 #define add_dynamic_entry(TAG, VAL) \
1568 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1572 if (!add_dynamic_entry (DT_DEBUG, 0))
1576 if (htab->splt->_raw_size != 0)
1578 if (!add_dynamic_entry (DT_PLTGOT, 0)
1579 || !add_dynamic_entry (DT_PLTRELSZ, 0)
1580 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1581 || !add_dynamic_entry (DT_JMPREL, 0))
1587 if (!add_dynamic_entry (DT_RELA, 0)
1588 || !add_dynamic_entry (DT_RELASZ, 0)
1589 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
1592 /* If any dynamic relocs apply to a read-only section,
1593 then we need a DT_TEXTREL entry. */
1594 if ((info->flags & DF_TEXTREL) == 0)
1595 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
1598 if ((info->flags & DF_TEXTREL) != 0)
1600 if (!add_dynamic_entry (DT_TEXTREL, 0))
1605 #undef add_dynamic_entry
1610 /* Relocate a 390 ELF section. */
1613 elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
1614 contents, relocs, local_syms, local_sections)
1616 struct bfd_link_info *info;
1618 asection *input_section;
1620 Elf_Internal_Rela *relocs;
1621 Elf_Internal_Sym *local_syms;
1622 asection **local_sections;
1624 struct elf_s390_link_hash_table *htab;
1625 Elf_Internal_Shdr *symtab_hdr;
1626 struct elf_link_hash_entry **sym_hashes;
1627 bfd_vma *local_got_offsets;
1628 Elf_Internal_Rela *rel;
1629 Elf_Internal_Rela *relend;
1631 if (info->relocateable)
1634 htab = elf_s390_hash_table (info);
1635 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1636 sym_hashes = elf_sym_hashes (input_bfd);
1637 local_got_offsets = elf_local_got_offsets (input_bfd);
1640 relend = relocs + input_section->reloc_count;
1641 for (; rel < relend; rel++)
1644 reloc_howto_type *howto;
1645 unsigned long r_symndx;
1646 struct elf_link_hash_entry *h;
1647 Elf_Internal_Sym *sym;
1651 boolean unresolved_reloc;
1652 bfd_reloc_status_type r;
1654 r_type = ELF32_R_TYPE (rel->r_info);
1655 if (r_type == (int) R_390_GNU_VTINHERIT
1656 || r_type == (int) R_390_GNU_VTENTRY)
1658 if (r_type < 0 || r_type >= (int) R_390_max)
1660 bfd_set_error (bfd_error_bad_value);
1664 howto = elf_howto_table + r_type;
1665 r_symndx = ELF32_R_SYM (rel->r_info);
1669 unresolved_reloc = false;
1670 if (r_symndx < symtab_hdr->sh_info)
1672 sym = local_syms + r_symndx;
1673 sec = local_sections[r_symndx];
1674 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
1678 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1679 while (h->root.type == bfd_link_hash_indirect
1680 || h->root.type == bfd_link_hash_warning)
1681 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1683 if (h->root.type == bfd_link_hash_defined
1684 || h->root.type == bfd_link_hash_defweak)
1686 sec = h->root.u.def.section;
1687 if (sec->output_section == NULL)
1689 /* Set a flag that will be cleared later if we find a
1690 relocation value for this symbol. output_section
1691 is typically NULL for symbols satisfied by a shared
1693 unresolved_reloc = true;
1697 relocation = (h->root.u.def.value
1698 + sec->output_section->vma
1699 + sec->output_offset);
1701 else if (h->root.type == bfd_link_hash_undefweak)
1703 else if (info->shared
1704 && (!info->symbolic || info->allow_shlib_undefined)
1705 && !info->no_undefined
1706 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1710 if (! ((*info->callbacks->undefined_symbol)
1711 (info, h->root.root.string, input_bfd,
1712 input_section, rel->r_offset,
1713 (!info->shared || info->no_undefined
1714 || ELF_ST_VISIBILITY (h->other)))))
1726 /* Relocation is to the entry for this symbol in the global
1728 if (htab->sgot == NULL)
1735 off = h->got.offset;
1736 dyn = htab->elf.dynamic_sections_created;
1737 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
1741 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
1742 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1744 /* This is actually a static link, or it is a
1745 -Bsymbolic link and the symbol is defined
1746 locally, or the symbol was forced to be local
1747 because of a version file. We must initialize
1748 this entry in the global offset table. Since the
1749 offset must always be a multiple of 2, we use the
1750 least significant bit to record whether we have
1751 initialized it already.
1753 When doing a dynamic link, we create a .rel.got
1754 relocation entry to initialize the value. This
1755 is done in the finish_dynamic_symbol routine. */
1760 bfd_put_32 (output_bfd, relocation,
1761 htab->sgot->contents + off);
1766 unresolved_reloc = false;
1770 if (local_got_offsets == NULL)
1773 off = local_got_offsets[r_symndx];
1775 /* The offset must always be a multiple of 4. We use
1776 the least significant bit to record whether we have
1777 already generated the necessary reloc. */
1782 bfd_put_32 (output_bfd, relocation,
1783 htab->sgot->contents + off);
1788 Elf_Internal_Rela outrel;
1789 Elf32_External_Rela *loc;
1791 srelgot = htab->srelgot;
1792 if (srelgot == NULL)
1795 outrel.r_offset = (htab->sgot->output_section->vma
1796 + htab->sgot->output_offset
1798 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
1799 outrel.r_addend = relocation;
1800 loc = (Elf32_External_Rela *) srelgot->contents;
1801 loc += srelgot->reloc_count++;
1802 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1805 local_got_offsets[r_symndx] |= 1;
1809 if (off >= (bfd_vma) -2)
1812 relocation = htab->sgot->output_offset + off;
1815 * For @GOTENT the relocation is against the offset between
1816 * the instruction and the symbols entry in the GOT and not
1817 * between the start of the GOT and the symbols entry. We
1818 * add the vma of the GOT to get the correct value.
1820 if (r_type == R_390_GOTENT)
1821 relocation += htab->sgot->output_section->vma;
1826 /* Relocation is relative to the start of the global offset
1829 /* Note that sgot->output_offset is not involved in this
1830 calculation. We always want the start of .got. If we
1831 defined _GLOBAL_OFFSET_TABLE in a different way, as is
1832 permitted by the ABI, we might have to change this
1834 relocation -= htab->sgot->output_section->vma;
1838 case R_390_GOTPCDBL:
1839 /* Use global offset table as symbol value. */
1840 relocation = htab->sgot->output_section->vma;
1841 unresolved_reloc = false;
1844 case R_390_PLT16DBL:
1845 case R_390_PLT32DBL:
1847 /* Relocation is to the entry for this symbol in the
1848 procedure linkage table. */
1850 /* Resolve a PLT32 reloc against a local symbol directly,
1851 without using the procedure linkage table. */
1855 if (h->plt.offset == (bfd_vma) -1
1856 || htab->splt == NULL)
1858 /* We didn't make a PLT entry for this symbol. This
1859 happens when statically linking PIC code, or when
1860 using -Bsymbolic. */
1864 relocation = (htab->splt->output_section->vma
1865 + htab->splt->output_offset
1867 unresolved_reloc = false;
1877 /* r_symndx will be zero only for relocs against symbols
1878 from removed linkonce sections, or sections discarded by
1881 || (input_section->flags & SEC_ALLOC) == 0)
1885 && ((r_type != R_390_PC16
1886 && r_type != R_390_PC16DBL
1887 && r_type != R_390_PC32DBL
1888 && r_type != R_390_PC32)
1891 && (! info->symbolic
1892 || (h->elf_link_hash_flags
1893 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
1897 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
1898 && (((h->elf_link_hash_flags
1899 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1900 && (h->elf_link_hash_flags
1901 & ELF_LINK_HASH_DEF_REGULAR) == 0)
1902 || h->root.type == bfd_link_hash_undefweak
1903 || h->root.type == bfd_link_hash_undefined)))
1905 Elf_Internal_Rela outrel;
1906 boolean skip, relocate;
1908 Elf32_External_Rela *loc;
1910 /* When generating a shared object, these relocations
1911 are copied into the output file to be resolved at run
1918 _bfd_elf_section_offset (output_bfd, info, input_section,
1920 if (outrel.r_offset == (bfd_vma) -1)
1922 else if (outrel.r_offset == (bfd_vma) -2)
1923 skip = true, relocate = true;
1924 outrel.r_offset += (input_section->output_section->vma
1925 + input_section->output_offset);
1928 memset (&outrel, 0, sizeof outrel);
1931 && (r_type == R_390_PC16
1932 || r_type == R_390_PC16DBL
1933 || r_type == R_390_PC32DBL
1934 || r_type == R_390_PC32
1937 || (h->elf_link_hash_flags
1938 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1940 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1941 outrel.r_addend = rel->r_addend;
1945 /* This symbol is local, or marked to become local. */
1947 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
1948 outrel.r_addend = relocation + rel->r_addend;
1951 sreloc = elf_section_data (input_section)->sreloc;
1955 loc = (Elf32_External_Rela *) sreloc->contents;
1956 loc += sreloc->reloc_count++;
1957 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1959 /* If this reloc is against an external symbol, we do
1960 not want to fiddle with the addend. Otherwise, we
1961 need to include the symbol value so that it becomes
1962 an addend for the dynamic reloc. */
1972 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
1973 because such sections are not SEC_ALLOC and thus ld.so will
1974 not process them. */
1975 if (unresolved_reloc
1976 && !((input_section->flags & SEC_DEBUGGING) != 0
1977 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
1978 (*_bfd_error_handler)
1979 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
1980 bfd_archive_filename (input_bfd),
1981 bfd_get_section_name (input_bfd, input_section),
1982 (long) rel->r_offset,
1983 h->root.root.string);
1985 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1986 contents, rel->r_offset,
1987 relocation, rel->r_addend);
1989 if (r != bfd_reloc_ok)
1994 name = h->root.root.string;
1997 name = bfd_elf_string_from_elf_section (input_bfd,
1998 symtab_hdr->sh_link,
2003 name = bfd_section_name (input_bfd, sec);
2006 if (r == bfd_reloc_overflow)
2009 if (! ((*info->callbacks->reloc_overflow)
2010 (info, name, howto->name, (bfd_vma) 0,
2011 input_bfd, input_section, rel->r_offset)))
2016 (*_bfd_error_handler)
2017 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
2018 bfd_archive_filename (input_bfd),
2019 bfd_get_section_name (input_bfd, input_section),
2020 (long) rel->r_offset, name, (int) r);
2029 /* Finish up dynamic symbol handling. We set the contents of various
2030 dynamic sections here. */
2033 elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym)
2035 struct bfd_link_info *info;
2036 struct elf_link_hash_entry *h;
2037 Elf_Internal_Sym *sym;
2039 struct elf_s390_link_hash_table *htab;
2041 htab = elf_s390_hash_table (info);
2043 if (h->plt.offset != (bfd_vma) -1)
2047 Elf_Internal_Rela rela;
2048 Elf32_External_Rela *loc;
2049 bfd_vma relative_offset;
2051 /* This symbol has an entry in the procedure linkage table. Set
2054 if (h->dynindx == -1
2055 || htab->splt == NULL
2056 || htab->sgotplt == NULL
2057 || htab->srelplt == NULL)
2061 Current offset - size first entry / entry size. */
2062 plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
2064 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2066 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
2068 /* S390 uses halfwords for relative branch calc! */
2069 relative_offset = - ((PLT_FIRST_ENTRY_SIZE +
2070 (PLT_ENTRY_SIZE * plt_index) + 18) / 2);
2071 /* If offset is > 32768, branch to a previous branch
2072 390 can only handle +-64 K jumps. */
2073 if ( -32768 > (int) relative_offset )
2075 -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2);
2077 /* Fill in the entry in the procedure linkage table. */
2080 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0,
2081 htab->splt->contents + h->plt.offset);
2082 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1,
2083 htab->splt->contents + h->plt.offset + 4);
2084 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2,
2085 htab->splt->contents + h->plt.offset + 8);
2086 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3,
2087 htab->splt->contents + h->plt.offset + 12);
2088 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4,
2089 htab->splt->contents + h->plt.offset + 16);
2090 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2091 htab->splt->contents + h->plt.offset + 20);
2092 bfd_put_32 (output_bfd,
2093 (htab->sgotplt->output_section->vma
2094 + htab->sgotplt->output_offset
2096 htab->splt->contents + h->plt.offset + 24);
2098 else if (got_offset < 4096)
2100 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD0 + got_offset,
2101 htab->splt->contents + h->plt.offset);
2102 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD1,
2103 htab->splt->contents + h->plt.offset + 4);
2104 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD2,
2105 htab->splt->contents + h->plt.offset + 8);
2106 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD3,
2107 htab->splt->contents + h->plt.offset + 12);
2108 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD4,
2109 htab->splt->contents + h->plt.offset + 16);
2110 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2111 htab->splt->contents + h->plt.offset + 20);
2112 bfd_put_32 (output_bfd, (bfd_vma) 0,
2113 htab->splt->contents + h->plt.offset + 24);
2115 else if (got_offset < 32768)
2117 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD0 + got_offset,
2118 htab->splt->contents + h->plt.offset);
2119 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD1,
2120 htab->splt->contents + h->plt.offset + 4);
2121 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD2,
2122 htab->splt->contents + h->plt.offset + 8);
2123 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD3,
2124 htab->splt->contents + h->plt.offset + 12);
2125 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD4,
2126 htab->splt->contents + h->plt.offset + 16);
2127 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2128 htab->splt->contents + h->plt.offset + 20);
2129 bfd_put_32 (output_bfd, (bfd_vma) 0,
2130 htab->splt->contents + h->plt.offset + 24);
2134 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD0,
2135 htab->splt->contents + h->plt.offset);
2136 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD1,
2137 htab->splt->contents + h->plt.offset + 4);
2138 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD2,
2139 htab->splt->contents + h->plt.offset + 8);
2140 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD3,
2141 htab->splt->contents + h->plt.offset + 12);
2142 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD4,
2143 htab->splt->contents + h->plt.offset + 16);
2144 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
2145 htab->splt->contents + h->plt.offset + 20);
2146 bfd_put_32 (output_bfd, got_offset,
2147 htab->splt->contents + h->plt.offset + 24);
2149 /* Insert offset into reloc. table here. */
2150 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
2151 htab->splt->contents + h->plt.offset + 28);
2153 /* Fill in the entry in the global offset table.
2154 Points to instruction after GOT offset. */
2155 bfd_put_32 (output_bfd,
2156 (htab->splt->output_section->vma
2157 + htab->splt->output_offset
2160 htab->sgotplt->contents + got_offset);
2162 /* Fill in the entry in the .rela.plt section. */
2163 rela.r_offset = (htab->sgotplt->output_section->vma
2164 + htab->sgotplt->output_offset
2166 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT);
2168 loc = (Elf32_External_Rela *) htab->srelplt->contents + plt_index;
2169 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2171 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2173 /* Mark the symbol as undefined, rather than as defined in
2174 the .plt section. Leave the value alone. This is a clue
2175 for the dynamic linker, to make function pointer
2176 comparisons work between an application and shared
2178 sym->st_shndx = SHN_UNDEF;
2182 if (h->got.offset != (bfd_vma) -1)
2184 Elf_Internal_Rela rela;
2185 Elf32_External_Rela *loc;
2187 /* This symbol has an entry in the global offset table. Set it
2190 if (htab->sgot == NULL || htab->srelgot == NULL)
2193 rela.r_offset = (htab->sgot->output_section->vma
2194 + htab->sgot->output_offset
2195 + (h->got.offset &~ (bfd_vma) 1));
2197 /* If this is a static link, or it is a -Bsymbolic link and the
2198 symbol is defined locally or was forced to be local because
2199 of a version file, we just want to emit a RELATIVE reloc.
2200 The entry in the global offset table will already have been
2201 initialized in the relocate_section function. */
2205 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
2206 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2208 BFD_ASSERT((h->got.offset & 1) != 0);
2209 rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
2210 rela.r_addend = (h->root.u.def.value
2211 + h->root.u.def.section->output_section->vma
2212 + h->root.u.def.section->output_offset);
2216 BFD_ASSERT((h->got.offset & 1) == 0);
2217 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.offset);
2218 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_GLOB_DAT);
2222 loc = (Elf32_External_Rela *) htab->srelgot->contents;
2223 loc += htab->srelgot->reloc_count++;
2224 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2227 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2229 Elf_Internal_Rela rela;
2230 Elf32_External_Rela *loc;
2232 /* This symbols needs a copy reloc. Set it up. */
2234 if (h->dynindx == -1
2235 || (h->root.type != bfd_link_hash_defined
2236 && h->root.type != bfd_link_hash_defweak)
2237 || htab->srelbss == NULL)
2240 rela.r_offset = (h->root.u.def.value
2241 + h->root.u.def.section->output_section->vma
2242 + h->root.u.def.section->output_offset);
2243 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_COPY);
2245 loc = (Elf32_External_Rela *) htab->srelbss->contents;
2246 loc += htab->srelbss->reloc_count++;
2247 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2250 /* Mark some specially defined symbols as absolute. */
2251 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2252 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
2253 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2254 sym->st_shndx = SHN_ABS;
2259 /* Used to decide how to sort relocs in an optimal manner for the
2260 dynamic linker, before writing them out. */
2262 static enum elf_reloc_type_class
2263 elf_s390_reloc_type_class (rela)
2264 const Elf_Internal_Rela *rela;
2266 switch ((int) ELF32_R_TYPE (rela->r_info))
2268 case R_390_RELATIVE:
2269 return reloc_class_relative;
2270 case R_390_JMP_SLOT:
2271 return reloc_class_plt;
2273 return reloc_class_copy;
2275 return reloc_class_normal;
2279 /* Finish up the dynamic sections. */
2282 elf_s390_finish_dynamic_sections (output_bfd, info)
2284 struct bfd_link_info *info;
2286 struct elf_s390_link_hash_table *htab;
2290 htab = elf_s390_hash_table (info);
2291 dynobj = htab->elf.dynobj;
2292 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2294 if (htab->elf.dynamic_sections_created)
2296 Elf32_External_Dyn *dyncon, *dynconend;
2298 if (sdyn == NULL || htab->sgot == NULL)
2301 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2302 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2303 for (; dyncon < dynconend; dyncon++)
2305 Elf_Internal_Dyn dyn;
2308 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2316 dyn.d_un.d_ptr = htab->sgot->output_section->vma;
2320 dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
2324 s = htab->srelplt->output_section;
2325 if (s->_cooked_size != 0)
2326 dyn.d_un.d_val = s->_cooked_size;
2328 dyn.d_un.d_val = s->_raw_size;
2332 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2335 /* Fill in the special first entry in the procedure linkage table. */
2336 if (htab->splt && htab->splt->_raw_size > 0)
2338 memset (htab->splt->contents, 0, PLT_FIRST_ENTRY_SIZE);
2341 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD0,
2342 htab->splt->contents );
2343 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD1,
2344 htab->splt->contents +4 );
2345 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD2,
2346 htab->splt->contents +8 );
2347 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD3,
2348 htab->splt->contents +12 );
2349 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD4,
2350 htab->splt->contents +16 );
2354 bfd_put_32 (output_bfd, (bfd_vma)PLT_FIRST_ENTRY_WORD0,
2355 htab->splt->contents );
2356 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1,
2357 htab->splt->contents +4 );
2358 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD2,
2359 htab->splt->contents +8 );
2360 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3,
2361 htab->splt->contents +12 );
2362 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4,
2363 htab->splt->contents +16 );
2364 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5,
2365 htab->splt->contents +20 );
2366 bfd_put_32 (output_bfd,
2367 htab->sgotplt->output_section->vma
2368 + htab->sgotplt->output_offset,
2369 htab->splt->contents + 24);
2371 elf_section_data (htab->splt->output_section)
2372 ->this_hdr.sh_entsize = 4;
2379 /* Fill in the first three entries in the global offset table. */
2380 if (htab->sgotplt->_raw_size > 0)
2382 bfd_put_32 (output_bfd,
2383 (sdyn == NULL ? (bfd_vma) 0
2384 : sdyn->output_section->vma + sdyn->output_offset),
2385 htab->sgotplt->contents);
2386 /* One entry for shared object struct ptr. */
2387 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 4);
2388 /* One entry for _dl_runtime_resolve. */
2389 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8);
2392 elf_section_data (htab->sgotplt->output_section)
2393 ->this_hdr.sh_entsize = 4;
2399 elf_s390_object_p (abfd)
2402 return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_31);
2406 elf_s390_grok_prstatus (abfd, note)
2408 Elf_Internal_Note * note;
2411 unsigned int raw_size;
2413 switch (note->descsz)
2418 case 224: /* S/390 Linux. */
2420 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2423 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
2431 /* Make a ".reg/999" section. */
2432 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2433 raw_size, note->descpos + offset);
2436 #define TARGET_BIG_SYM bfd_elf32_s390_vec
2437 #define TARGET_BIG_NAME "elf32-s390"
2438 #define ELF_ARCH bfd_arch_s390
2439 #define ELF_MACHINE_CODE EM_S390
2440 #define ELF_MACHINE_ALT1 EM_S390_OLD
2441 #define ELF_MAXPAGESIZE 0x1000
2443 #define elf_backend_can_gc_sections 1
2444 #define elf_backend_can_refcount 1
2445 #define elf_backend_want_got_plt 1
2446 #define elf_backend_plt_readonly 1
2447 #define elf_backend_want_plt_sym 0
2448 #define elf_backend_got_header_size 12
2449 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
2450 #define elf_backend_rela_normal 1
2452 #define elf_info_to_howto elf_s390_info_to_howto
2454 #define bfd_elf32_bfd_is_local_label_name elf_s390_is_local_label_name
2455 #define bfd_elf32_bfd_link_hash_table_create elf_s390_link_hash_table_create
2456 #define bfd_elf32_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
2458 #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
2459 #define elf_backend_check_relocs elf_s390_check_relocs
2460 #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
2461 #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
2462 #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
2463 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
2464 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
2465 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
2466 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
2467 #define elf_backend_relocate_section elf_s390_relocate_section
2468 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
2469 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
2470 #define elf_backend_grok_prstatus elf_s390_grok_prstatus
2472 #define elf_backend_object_p elf_s390_object_p
2474 #include "elf32-target.h"