1 /* IBM S/390-specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed Martin Schwidefsky (schwidefsky@de.ibm.com).
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
80 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
81 from smaller values. Start with zero, widen, *then* decrement. */
82 #define MINUS_ONE (((bfd_vma)0) - 1)
84 /* The relocation "howto" table. */
85 static reloc_howto_type elf_howto_table
[] =
87 HOWTO (R_390_NONE
, /* type */
89 0, /* size (0 = byte, 1 = short, 2 = long) */
91 FALSE
, /* pc_relative */
93 complain_overflow_dont
, /* complain_on_overflow */
94 bfd_elf_generic_reloc
, /* special_function */
95 "R_390_NONE", /* name */
96 FALSE
, /* partial_inplace */
99 FALSE
), /* pcrel_offset */
101 HOWTO(R_390_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
102 bfd_elf_generic_reloc
, "R_390_8", FALSE
, 0,0x000000ff, FALSE
),
103 HOWTO(R_390_12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
104 bfd_elf_generic_reloc
, "R_390_12", FALSE
, 0,0x00000fff, FALSE
),
105 HOWTO(R_390_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_390_16", FALSE
, 0,0x0000ffff, FALSE
),
107 HOWTO(R_390_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
108 bfd_elf_generic_reloc
, "R_390_32", FALSE
, 0,0xffffffff, FALSE
),
109 HOWTO(R_390_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
110 bfd_elf_generic_reloc
, "R_390_PC32", FALSE
, 0,0xffffffff, TRUE
),
111 HOWTO(R_390_GOT12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
112 bfd_elf_generic_reloc
, "R_390_GOT12", FALSE
, 0,0x00000fff, FALSE
),
113 HOWTO(R_390_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
114 bfd_elf_generic_reloc
, "R_390_GOT32", FALSE
, 0,0xffffffff, FALSE
),
115 HOWTO(R_390_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
116 bfd_elf_generic_reloc
, "R_390_PLT32", FALSE
, 0,0xffffffff, TRUE
),
117 HOWTO(R_390_COPY
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
118 bfd_elf_generic_reloc
, "R_390_COPY", FALSE
, 0,MINUS_ONE
, FALSE
),
119 HOWTO(R_390_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_390_GLOB_DAT", FALSE
, 0,MINUS_ONE
, FALSE
),
121 HOWTO(R_390_JMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
122 bfd_elf_generic_reloc
, "R_390_JMP_SLOT", FALSE
, 0,MINUS_ONE
, FALSE
),
123 HOWTO(R_390_RELATIVE
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
124 bfd_elf_generic_reloc
, "R_390_RELATIVE", FALSE
, 0,MINUS_ONE
, FALSE
),
125 HOWTO(R_390_GOTOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
126 bfd_elf_generic_reloc
, "R_390_GOTOFF32", FALSE
, 0,MINUS_ONE
, FALSE
),
127 HOWTO(R_390_GOTPC
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_390_GOTPC", FALSE
, 0,MINUS_ONE
, TRUE
),
129 HOWTO(R_390_GOT16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_390_GOT16", FALSE
, 0,0x0000ffff, FALSE
),
131 HOWTO(R_390_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
132 bfd_elf_generic_reloc
, "R_390_PC16", FALSE
, 0,0x0000ffff, TRUE
),
133 HOWTO(R_390_PC16DBL
, 1, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
134 bfd_elf_generic_reloc
, "R_390_PC16DBL", FALSE
, 0,0x0000ffff, TRUE
),
135 HOWTO(R_390_PLT16DBL
, 1, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
136 bfd_elf_generic_reloc
, "R_390_PLT16DBL", FALSE
, 0,0x0000ffff, TRUE
),
137 HOWTO(R_390_PC32DBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_390_PC32DBL", FALSE
, 0,0xffffffff, TRUE
),
139 HOWTO(R_390_PLT32DBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
140 bfd_elf_generic_reloc
, "R_390_PLT32DBL", FALSE
, 0,0xffffffff, TRUE
),
141 HOWTO(R_390_GOTPCDBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
142 bfd_elf_generic_reloc
, "R_390_GOTPCDBL", FALSE
, 0,MINUS_ONE
, TRUE
),
143 HOWTO(R_390_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_390_64", FALSE
, 0,MINUS_ONE
, FALSE
),
145 HOWTO(R_390_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
146 bfd_elf_generic_reloc
, "R_390_PC64", FALSE
, 0,MINUS_ONE
, TRUE
),
147 HOWTO(R_390_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
148 bfd_elf_generic_reloc
, "R_390_GOT64", FALSE
, 0,MINUS_ONE
, FALSE
),
149 HOWTO(R_390_PLT64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
150 bfd_elf_generic_reloc
, "R_390_PLT64", FALSE
, 0,MINUS_ONE
, TRUE
),
151 HOWTO(R_390_GOTENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
152 bfd_elf_generic_reloc
, "R_390_GOTENT", FALSE
, 0,MINUS_ONE
, TRUE
),
153 HOWTO(R_390_GOTOFF16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
154 bfd_elf_generic_reloc
, "R_390_GOTOFF16", FALSE
, 0,0x0000ffff, FALSE
),
155 HOWTO(R_390_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
156 bfd_elf_generic_reloc
, "R_390_GOTOFF64", FALSE
, 0,MINUS_ONE
, FALSE
),
157 HOWTO(R_390_GOTPLT12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
158 bfd_elf_generic_reloc
, "R_390_GOTPLT12", FALSE
, 0,0x00000fff, FALSE
),
159 HOWTO(R_390_GOTPLT16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
160 bfd_elf_generic_reloc
, "R_390_GOTPLT16", FALSE
, 0,0x0000ffff, FALSE
),
161 HOWTO(R_390_GOTPLT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
162 bfd_elf_generic_reloc
, "R_390_GOTPLT32", FALSE
, 0,0xffffffff, FALSE
),
163 HOWTO(R_390_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
164 bfd_elf_generic_reloc
, "R_390_GOTPLT64", FALSE
, 0,MINUS_ONE
, FALSE
),
165 HOWTO(R_390_GOTPLTENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
166 bfd_elf_generic_reloc
, "R_390_GOTPLTENT",FALSE
, 0,MINUS_ONE
, TRUE
),
167 HOWTO(R_390_PLTOFF16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
168 bfd_elf_generic_reloc
, "R_390_PLTOFF16", FALSE
, 0,0x0000ffff, FALSE
),
169 HOWTO(R_390_PLTOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
170 bfd_elf_generic_reloc
, "R_390_PLTOFF32", FALSE
, 0,0xffffffff, FALSE
),
171 HOWTO(R_390_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
172 bfd_elf_generic_reloc
, "R_390_PLTOFF64", FALSE
, 0,MINUS_ONE
, FALSE
),
175 /* GNU extension to record C++ vtable hierarchy. */
176 static reloc_howto_type elf64_s390_vtinherit_howto
=
177 HOWTO (R_390_GNU_VTINHERIT
, 0,4,0,FALSE
,0,complain_overflow_dont
, NULL
, "R_390_GNU_VTINHERIT", FALSE
,0, 0, FALSE
);
178 static reloc_howto_type elf64_s390_vtentry_howto
=
179 HOWTO (R_390_GNU_VTENTRY
, 0,4,0,FALSE
,0,complain_overflow_dont
, _bfd_elf_rel_vtable_reloc_fn
,"R_390_GNU_VTENTRY", FALSE
,0,0, FALSE
);
181 static reloc_howto_type
*
182 elf_s390_reloc_type_lookup (abfd
, code
)
183 bfd
*abfd ATTRIBUTE_UNUSED
;
184 bfd_reloc_code_real_type code
;
189 return &elf_howto_table
[(int) R_390_NONE
];
191 return &elf_howto_table
[(int) R_390_8
];
192 case BFD_RELOC_390_12
:
193 return &elf_howto_table
[(int) R_390_12
];
195 return &elf_howto_table
[(int) R_390_16
];
197 return &elf_howto_table
[(int) R_390_32
];
199 return &elf_howto_table
[(int) R_390_32
];
200 case BFD_RELOC_32_PCREL
:
201 return &elf_howto_table
[(int) R_390_PC32
];
202 case BFD_RELOC_390_GOT12
:
203 return &elf_howto_table
[(int) R_390_GOT12
];
204 case BFD_RELOC_32_GOT_PCREL
:
205 return &elf_howto_table
[(int) R_390_GOT32
];
206 case BFD_RELOC_390_PLT32
:
207 return &elf_howto_table
[(int) R_390_PLT32
];
208 case BFD_RELOC_390_COPY
:
209 return &elf_howto_table
[(int) R_390_COPY
];
210 case BFD_RELOC_390_GLOB_DAT
:
211 return &elf_howto_table
[(int) R_390_GLOB_DAT
];
212 case BFD_RELOC_390_JMP_SLOT
:
213 return &elf_howto_table
[(int) R_390_JMP_SLOT
];
214 case BFD_RELOC_390_RELATIVE
:
215 return &elf_howto_table
[(int) R_390_RELATIVE
];
216 case BFD_RELOC_32_GOTOFF
:
217 return &elf_howto_table
[(int) R_390_GOTOFF32
];
218 case BFD_RELOC_390_GOTPC
:
219 return &elf_howto_table
[(int) R_390_GOTPC
];
220 case BFD_RELOC_390_GOT16
:
221 return &elf_howto_table
[(int) R_390_GOT16
];
222 case BFD_RELOC_16_PCREL
:
223 return &elf_howto_table
[(int) R_390_PC16
];
224 case BFD_RELOC_390_PC16DBL
:
225 return &elf_howto_table
[(int) R_390_PC16DBL
];
226 case BFD_RELOC_390_PLT16DBL
:
227 return &elf_howto_table
[(int) R_390_PLT16DBL
];
228 case BFD_RELOC_390_PC32DBL
:
229 return &elf_howto_table
[(int) R_390_PC32DBL
];
230 case BFD_RELOC_390_PLT32DBL
:
231 return &elf_howto_table
[(int) R_390_PLT32DBL
];
232 case BFD_RELOC_390_GOTPCDBL
:
233 return &elf_howto_table
[(int) R_390_GOTPCDBL
];
235 return &elf_howto_table
[(int) R_390_64
];
236 case BFD_RELOC_64_PCREL
:
237 return &elf_howto_table
[(int) R_390_PC64
];
238 case BFD_RELOC_390_GOT64
:
239 return &elf_howto_table
[(int) R_390_GOT64
];
240 case BFD_RELOC_390_PLT64
:
241 return &elf_howto_table
[(int) R_390_PLT64
];
242 case BFD_RELOC_390_GOTENT
:
243 return &elf_howto_table
[(int) R_390_GOTENT
];
244 case BFD_RELOC_16_GOTOFF
:
245 return &elf_howto_table
[(int) R_390_GOTOFF16
];
246 case BFD_RELOC_390_GOTOFF64
:
247 return &elf_howto_table
[(int) R_390_GOTOFF64
];
248 case BFD_RELOC_390_GOTPLT12
:
249 return &elf_howto_table
[(int) R_390_GOTPLT12
];
250 case BFD_RELOC_390_GOTPLT16
:
251 return &elf_howto_table
[(int) R_390_GOTPLT16
];
252 case BFD_RELOC_390_GOTPLT32
:
253 return &elf_howto_table
[(int) R_390_GOTPLT32
];
254 case BFD_RELOC_390_GOTPLT64
:
255 return &elf_howto_table
[(int) R_390_GOTPLT64
];
256 case BFD_RELOC_390_GOTPLTENT
:
257 return &elf_howto_table
[(int) R_390_GOTPLTENT
];
258 case BFD_RELOC_390_PLTOFF16
:
259 return &elf_howto_table
[(int) R_390_PLTOFF16
];
260 case BFD_RELOC_390_PLTOFF32
:
261 return &elf_howto_table
[(int) R_390_PLTOFF32
];
262 case BFD_RELOC_390_PLTOFF64
:
263 return &elf_howto_table
[(int) R_390_PLTOFF64
];
264 case BFD_RELOC_VTABLE_INHERIT
:
265 return &elf64_s390_vtinherit_howto
;
266 case BFD_RELOC_VTABLE_ENTRY
:
267 return &elf64_s390_vtentry_howto
;
274 /* We need to use ELF64_R_TYPE so we have our own copy of this function,
275 and elf64-s390.c has its own copy. */
278 elf_s390_info_to_howto (abfd
, cache_ptr
, dst
)
279 bfd
*abfd ATTRIBUTE_UNUSED
;
281 Elf_Internal_Rela
*dst
;
283 switch (ELF64_R_TYPE(dst
->r_info
))
285 case R_390_GNU_VTINHERIT
:
286 cache_ptr
->howto
= &elf64_s390_vtinherit_howto
;
289 case R_390_GNU_VTENTRY
:
290 cache_ptr
->howto
= &elf64_s390_vtentry_howto
;
294 BFD_ASSERT (ELF64_R_TYPE(dst
->r_info
) < (unsigned int) R_390_max
);
295 cache_ptr
->howto
= &elf_howto_table
[ELF64_R_TYPE(dst
->r_info
)];
300 elf_s390_is_local_label_name (abfd
, name
)
304 if (name
[0] == '.' && (name
[1] == 'X' || name
[1] == 'L'))
307 return _bfd_elf_is_local_label_name (abfd
, name
);
310 /* Functions for the 390 ELF linker. */
312 /* The name of the dynamic interpreter. This is put in the .interp
315 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
317 /* The size in bytes of the first entry in the procedure linkage table. */
318 #define PLT_FIRST_ENTRY_SIZE 32
319 /* The size in bytes of an entry in the procedure linkage table. */
320 #define PLT_ENTRY_SIZE 32
322 #define GOT_ENTRY_SIZE 8
324 /* The first three entries in a procedure linkage table are reserved,
325 and the initial contents are unimportant (we zero them out).
326 Subsequent entries look like this. See the SVR4 ABI 386
327 supplement to see how this works. */
329 /* For the s390, simple addr offset can only be 0 - 4096.
330 To use the full 16777216 TB address space, several instructions
331 are needed to load an address in a register and execute
332 a branch( or just saving the address)
334 Furthermore, only r 0 and 1 are free to use!!! */
336 /* The first 3 words in the GOT are then reserved.
337 Word 0 is the address of the dynamic table.
338 Word 1 is a pointer to a structure describing the object
339 Word 2 is used to point to the loader entry address.
341 The code for PLT entries looks like this:
343 The GOT holds the address in the PLT to be executed.
344 The loader then gets:
345 24(15) = Pointer to the structure describing the object.
346 28(15) = Offset in symbol table
347 The loader must then find the module where the function is
348 and insert the address in the GOT.
350 PLT1: LARL 1,<fn>@GOTENT # 6 bytes Load address of GOT entry in r1
351 LG 1,0(1) # 6 bytes Load address from GOT in r1
352 BCR 15,1 # 2 bytes Jump to address
353 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
354 LGF 1,12(1) # 6 bytes Load offset in symbl table in r1
355 BRCL 15,-x # 6 bytes Jump to start of PLT
356 .long ? # 4 bytes offset into symbol table
358 Total = 32 bytes per PLT entry
359 Fixup at offset 2: relative address to GOT entry
360 Fixup at offset 22: relative branch to PLT0
361 Fixup at offset 28: 32 bit offset into symbol table
363 A 32 bit offset into the symbol table is enough. It allows for symbol
364 tables up to a size of 2 gigabyte. A single dynamic object (the main
365 program, any shared library) is limited to 4GB in size and I want to see
366 the program that manages to have a symbol table of more than 2 GB with a
367 total size of at max 4 GB. */
369 #define PLT_ENTRY_WORD0 (bfd_vma) 0xc0100000
370 #define PLT_ENTRY_WORD1 (bfd_vma) 0x0000e310
371 #define PLT_ENTRY_WORD2 (bfd_vma) 0x10000004
372 #define PLT_ENTRY_WORD3 (bfd_vma) 0x07f10d10
373 #define PLT_ENTRY_WORD4 (bfd_vma) 0xe310100c
374 #define PLT_ENTRY_WORD5 (bfd_vma) 0x0014c0f4
375 #define PLT_ENTRY_WORD6 (bfd_vma) 0x00000000
376 #define PLT_ENTRY_WORD7 (bfd_vma) 0x00000000
378 /* The first PLT entry pushes the offset into the symbol table
379 from R1 onto the stack at 8(15) and the loader object info
380 at 12(15), loads the loader address in R1 and jumps to it. */
382 /* The first entry in the PLT:
385 STG 1,56(15) # r1 contains the offset into the symbol table
386 LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table
387 MVC 48(8,15),8(1) # move loader ino (object struct address) to stack
388 LG 1,16(1) # get entry address of loader
389 BCR 15,1 # jump to loader
391 Fixup at offset 8: relative address to start of GOT. */
393 #define PLT_FIRST_ENTRY_WORD0 (bfd_vma) 0xe310f038
394 #define PLT_FIRST_ENTRY_WORD1 (bfd_vma) 0x0024c010
395 #define PLT_FIRST_ENTRY_WORD2 (bfd_vma) 0x00000000
396 #define PLT_FIRST_ENTRY_WORD3 (bfd_vma) 0xd207f030
397 #define PLT_FIRST_ENTRY_WORD4 (bfd_vma) 0x1008e310
398 #define PLT_FIRST_ENTRY_WORD5 (bfd_vma) 0x10100004
399 #define PLT_FIRST_ENTRY_WORD6 (bfd_vma) 0x07f10700
400 #define PLT_FIRST_ENTRY_WORD7 (bfd_vma) 0x07000700
402 /* The s390 linker needs to keep track of the number of relocs that it
403 decides to copy as dynamic relocs in check_relocs for each symbol.
404 This is so that it can later discard them if they are found to be
405 unnecessary. We store the information in a field extending the
406 regular ELF linker hash table. */
408 struct elf_s390_dyn_relocs
410 struct elf_s390_dyn_relocs
*next
;
412 /* The input section of the reloc. */
415 /* Total number of relocs copied for the input section. */
418 /* Number of pc-relative relocs copied for the input section. */
419 bfd_size_type pc_count
;
422 /* s390 ELF linker hash entry. */
424 struct elf_s390_link_hash_entry
426 struct elf_link_hash_entry elf
;
428 /* Track dynamic relocs copied for this symbol. */
429 struct elf_s390_dyn_relocs
*dyn_relocs
;
431 /* Number of GOTPLT references for a function. */
432 bfd_signed_vma gotplt_refcount
;
435 /* s390 ELF linker hash table. */
437 struct elf_s390_link_hash_table
439 struct elf_link_hash_table elf
;
441 /* Short-cuts to get to dynamic linker sections. */
450 /* Small local sym to section mapping cache. */
451 struct sym_sec_cache sym_sec
;
454 /* Get the s390 ELF linker hash table from a link_info structure. */
456 #define elf_s390_hash_table(p) \
457 ((struct elf_s390_link_hash_table *) ((p)->hash))
459 /* Create an entry in an s390 ELF linker hash table. */
461 static struct bfd_hash_entry
*
462 link_hash_newfunc (entry
, table
, string
)
463 struct bfd_hash_entry
*entry
;
464 struct bfd_hash_table
*table
;
467 /* Allocate the structure if it has not already been allocated by a
471 entry
= bfd_hash_allocate (table
,
472 sizeof (struct elf_s390_link_hash_entry
));
477 /* Call the allocation method of the superclass. */
478 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
481 struct elf_s390_link_hash_entry
*eh
;
483 eh
= (struct elf_s390_link_hash_entry
*) entry
;
484 eh
->dyn_relocs
= NULL
;
485 eh
->gotplt_refcount
= 0;
491 /* Create an s390 ELF linker hash table. */
493 static struct bfd_link_hash_table
*
494 elf_s390_link_hash_table_create (abfd
)
497 struct elf_s390_link_hash_table
*ret
;
498 bfd_size_type amt
= sizeof (struct elf_s390_link_hash_table
);
500 ret
= (struct elf_s390_link_hash_table
*) bfd_malloc (amt
);
504 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
517 ret
->sym_sec
.abfd
= NULL
;
519 return &ret
->elf
.root
;
522 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
523 shortcuts to them in our hash table. */
526 create_got_section (dynobj
, info
)
528 struct bfd_link_info
*info
;
530 struct elf_s390_link_hash_table
*htab
;
532 if (! _bfd_elf_create_got_section (dynobj
, info
))
535 htab
= elf_s390_hash_table (info
);
536 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
537 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
538 if (!htab
->sgot
|| !htab
->sgotplt
)
541 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
542 if (htab
->srelgot
== NULL
543 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
544 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
545 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
547 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
552 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
553 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
557 elf_s390_create_dynamic_sections (dynobj
, info
)
559 struct bfd_link_info
*info
;
561 struct elf_s390_link_hash_table
*htab
;
563 htab
= elf_s390_hash_table (info
);
564 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
567 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
570 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
571 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
572 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
574 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
576 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
577 || (!info
->shared
&& !htab
->srelbss
))
583 /* Copy the extra info we tack onto an elf_link_hash_entry. */
586 elf_s390_copy_indirect_symbol (bed
, dir
, ind
)
587 struct elf_backend_data
*bed
;
588 struct elf_link_hash_entry
*dir
, *ind
;
590 struct elf_s390_link_hash_entry
*edir
, *eind
;
592 edir
= (struct elf_s390_link_hash_entry
*) dir
;
593 eind
= (struct elf_s390_link_hash_entry
*) ind
;
595 if (eind
->dyn_relocs
!= NULL
)
597 if (edir
->dyn_relocs
!= NULL
)
599 struct elf_s390_dyn_relocs
**pp
;
600 struct elf_s390_dyn_relocs
*p
;
602 if (ind
->root
.type
== bfd_link_hash_indirect
)
605 /* Add reloc counts against the weak sym to the strong sym
606 list. Merge any entries against the same section. */
607 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
609 struct elf_s390_dyn_relocs
*q
;
611 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
612 if (q
->sec
== p
->sec
)
614 q
->pc_count
+= p
->pc_count
;
615 q
->count
+= p
->count
;
622 *pp
= edir
->dyn_relocs
;
625 edir
->dyn_relocs
= eind
->dyn_relocs
;
626 eind
->dyn_relocs
= NULL
;
629 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
632 /* Look through the relocs for a section during the first phase, and
633 allocate space in the global offset table or procedure linkage
637 elf_s390_check_relocs (abfd
, info
, sec
, relocs
)
639 struct bfd_link_info
*info
;
641 const Elf_Internal_Rela
*relocs
;
643 struct elf_s390_link_hash_table
*htab
;
644 Elf_Internal_Shdr
*symtab_hdr
;
645 struct elf_link_hash_entry
**sym_hashes
;
646 const Elf_Internal_Rela
*rel
;
647 const Elf_Internal_Rela
*rel_end
;
649 bfd_signed_vma
*local_got_refcounts
;
651 if (info
->relocateable
)
654 htab
= elf_s390_hash_table (info
);
655 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
656 sym_hashes
= elf_sym_hashes (abfd
);
657 local_got_refcounts
= elf_local_got_refcounts (abfd
);
661 rel_end
= relocs
+ sec
->reloc_count
;
662 for (rel
= relocs
; rel
< rel_end
; rel
++)
664 unsigned long r_symndx
;
665 struct elf_link_hash_entry
*h
;
667 r_symndx
= ELF64_R_SYM (rel
->r_info
);
669 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
671 (*_bfd_error_handler
) (_("%s: bad symbol index: %d"),
672 bfd_archive_filename (abfd
),
677 if (r_symndx
< symtab_hdr
->sh_info
)
680 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
682 /* Create got section and local_got_refcounts array if they
684 switch (ELF64_R_TYPE (rel
->r_info
))
695 case R_390_GOTPLTENT
:
697 && local_got_refcounts
== NULL
)
701 size
= symtab_hdr
->sh_info
;
702 size
*= sizeof (bfd_signed_vma
);
703 local_got_refcounts
= ((bfd_signed_vma
*)
704 bfd_zalloc (abfd
, size
));
705 if (local_got_refcounts
== NULL
)
707 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
715 if (htab
->sgot
== NULL
)
717 if (htab
->elf
.dynobj
== NULL
)
718 htab
->elf
.dynobj
= abfd
;
719 if (!create_got_section (htab
->elf
.dynobj
, info
))
724 switch (ELF64_R_TYPE (rel
->r_info
))
731 /* This symbol requires a global offset table entry. */
734 h
->got
.refcount
+= 1;
738 local_got_refcounts
[r_symndx
] += 1;
747 /* Got is created, nothing to be done. */
757 /* This symbol requires a procedure linkage table entry. We
758 actually build the entry in adjust_dynamic_symbol,
759 because this might be a case of linking PIC code which is
760 never referenced by a dynamic object, in which case we
761 don't need to generate a procedure linkage table entry
764 /* If this is a local symbol, we resolve it directly without
765 creating a procedure linkage table entry. */
768 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
769 h
->plt
.refcount
+= 1;
777 case R_390_GOTPLTENT
:
778 /* This symbol requires either a procedure linkage table entry
779 or an entry in the local got. We actually build the entry
780 in adjust_dynamic_symbol because whether this is really a
781 global reference can change and with it the fact if we have
782 to create a plt entry or a local got entry. To be able to
783 make a once global symbol a local one we have to keep track
784 of the number of gotplt references that exist for this
788 ((struct elf_s390_link_hash_entry
*) h
)->gotplt_refcount
++;
789 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
790 h
->plt
.refcount
+= 1;
794 local_got_refcounts
[r_symndx
] += 1;
807 if (h
!= NULL
&& !info
->shared
)
809 /* If this reloc is in a read-only section, we might
810 need a copy reloc. We can't check reliably at this
811 stage whether the section is read-only, as input
812 sections have not yet been mapped to output sections.
813 Tentatively set the flag for now, and correct in
814 adjust_dynamic_symbol. */
815 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
817 /* We may need a .plt entry if the function this reloc
818 refers to is in a shared lib. */
819 h
->plt
.refcount
+= 1;
822 /* If we are creating a shared library, and this is a reloc
823 against a global symbol, or a non PC relative reloc
824 against a local symbol, then we need to copy the reloc
825 into the shared library. However, if we are linking with
826 -Bsymbolic, we do not need to copy a reloc against a
827 global symbol which is defined in an object we are
828 including in the link (i.e., DEF_REGULAR is set). At
829 this point we have not seen all the input files, so it is
830 possible that DEF_REGULAR is not set now but will be set
831 later (it is never cleared). In case of a weak definition,
832 DEF_REGULAR may be cleared later by a strong definition in
833 a shared library. We account for that possibility below by
834 storing information in the relocs_copied field of the hash
835 table entry. A similar situation occurs when creating
836 shared libraries and symbol visibility changes render the
839 If on the other hand, we are creating an executable, we
840 may need to keep relocations for symbols satisfied by a
841 dynamic library if we manage to avoid copy relocs for the
844 && (sec
->flags
& SEC_ALLOC
) != 0
845 && ((ELF64_R_TYPE (rel
->r_info
) != R_390_PC16
846 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC16DBL
847 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC32
848 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC32DBL
849 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC64
)
852 || h
->root
.type
== bfd_link_hash_defweak
853 || (h
->elf_link_hash_flags
854 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
856 && (sec
->flags
& SEC_ALLOC
) != 0
858 && (h
->root
.type
== bfd_link_hash_defweak
859 || (h
->elf_link_hash_flags
860 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
862 struct elf_s390_dyn_relocs
*p
;
863 struct elf_s390_dyn_relocs
**head
;
865 /* We must copy these reloc types into the output file.
866 Create a reloc section in dynobj and make room for
873 name
= (bfd_elf_string_from_elf_section
875 elf_elfheader (abfd
)->e_shstrndx
,
876 elf_section_data (sec
)->rel_hdr
.sh_name
));
880 if (strncmp (name
, ".rela", 5) != 0
881 || strcmp (bfd_get_section_name (abfd
, sec
),
884 (*_bfd_error_handler
)
885 (_("%s: bad relocation section name `%s\'"),
886 bfd_archive_filename (abfd
), name
);
889 if (htab
->elf
.dynobj
== NULL
)
890 htab
->elf
.dynobj
= abfd
;
892 dynobj
= htab
->elf
.dynobj
;
893 sreloc
= bfd_get_section_by_name (dynobj
, name
);
898 sreloc
= bfd_make_section (dynobj
, name
);
899 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
900 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
901 if ((sec
->flags
& SEC_ALLOC
) != 0)
902 flags
|= SEC_ALLOC
| SEC_LOAD
;
904 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
905 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
908 elf_section_data (sec
)->sreloc
= sreloc
;
911 /* If this is a global symbol, we count the number of
912 relocations we need for this symbol. */
915 head
= &((struct elf_s390_link_hash_entry
*) h
)->dyn_relocs
;
919 /* Track dynamic relocs needed for local syms too.
920 We really need local syms available to do this
924 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
929 head
= ((struct elf_s390_dyn_relocs
**)
930 &elf_section_data (s
)->local_dynrel
);
934 if (p
== NULL
|| p
->sec
!= sec
)
936 bfd_size_type amt
= sizeof *p
;
937 p
= ((struct elf_s390_dyn_relocs
*)
938 bfd_alloc (htab
->elf
.dynobj
, amt
));
949 if (ELF64_R_TYPE (rel
->r_info
) == R_390_PC16
950 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC16DBL
951 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC32
952 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC32DBL
953 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC64
)
958 /* This relocation describes the C++ object vtable hierarchy.
959 Reconstruct it for later use during GC. */
960 case R_390_GNU_VTINHERIT
:
961 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
965 /* This relocation describes which C++ vtable entries are actually
966 used. Record for later use during GC. */
967 case R_390_GNU_VTENTRY
:
968 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
980 /* Return the section that should be marked against GC for a given
984 elf_s390_gc_mark_hook (sec
, info
, rel
, h
, sym
)
986 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
987 Elf_Internal_Rela
*rel
;
988 struct elf_link_hash_entry
*h
;
989 Elf_Internal_Sym
*sym
;
993 switch (ELF64_R_TYPE (rel
->r_info
))
995 case R_390_GNU_VTINHERIT
:
996 case R_390_GNU_VTENTRY
:
1000 switch (h
->root
.type
)
1002 case bfd_link_hash_defined
:
1003 case bfd_link_hash_defweak
:
1004 return h
->root
.u
.def
.section
;
1006 case bfd_link_hash_common
:
1007 return h
->root
.u
.c
.p
->section
;
1015 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1020 /* Update the got entry reference counts for the section being removed. */
1023 elf_s390_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1025 struct bfd_link_info
*info
;
1027 const Elf_Internal_Rela
*relocs
;
1029 Elf_Internal_Shdr
*symtab_hdr
;
1030 struct elf_link_hash_entry
**sym_hashes
;
1031 bfd_signed_vma
*local_got_refcounts
;
1032 const Elf_Internal_Rela
*rel
, *relend
;
1033 unsigned long r_symndx
;
1034 struct elf_link_hash_entry
*h
;
1036 elf_section_data (sec
)->local_dynrel
= NULL
;
1038 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1039 sym_hashes
= elf_sym_hashes (abfd
);
1040 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1042 relend
= relocs
+ sec
->reloc_count
;
1043 for (rel
= relocs
; rel
< relend
; rel
++)
1045 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1047 if (r_symndx
< symtab_hdr
->sh_info
)
1050 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1052 switch (ELF64_R_TYPE (rel
->r_info
))
1058 case R_390_GOTOFF16
:
1059 case R_390_GOTOFF32
:
1060 case R_390_GOTOFF64
:
1062 case R_390_GOTPCDBL
:
1066 if (h
->got
.refcount
> 0)
1067 h
->got
.refcount
-= 1;
1069 else if (local_got_refcounts
!= NULL
)
1071 if (local_got_refcounts
[r_symndx
] > 0)
1072 local_got_refcounts
[r_symndx
] -= 1;
1076 case R_390_PLT16DBL
:
1078 case R_390_PLT32DBL
:
1080 case R_390_PLTOFF16
:
1081 case R_390_PLTOFF32
:
1082 case R_390_PLTOFF64
:
1085 if (h
->plt
.refcount
> 0)
1086 h
->plt
.refcount
-= 1;
1090 case R_390_GOTPLT12
:
1091 case R_390_GOTPLT16
:
1092 case R_390_GOTPLT32
:
1093 case R_390_GOTPLT64
:
1094 case R_390_GOTPLTENT
:
1097 if (h
->plt
.refcount
> 0)
1099 ((struct elf_s390_link_hash_entry
*) h
)->gotplt_refcount
--;
1100 h
->plt
.refcount
-= 1;
1103 else if (local_got_refcounts
!= NULL
)
1105 if (local_got_refcounts
[r_symndx
] > 0)
1106 local_got_refcounts
[r_symndx
] -= 1;
1122 struct elf_s390_link_hash_entry
*eh
;
1123 struct elf_s390_dyn_relocs
**pp
;
1124 struct elf_s390_dyn_relocs
*p
;
1126 if (!info
->shared
&& h
->plt
.refcount
> 0)
1127 h
->plt
.refcount
-= 1;
1129 eh
= (struct elf_s390_link_hash_entry
*) h
;
1131 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1134 if (ELF64_R_TYPE (rel
->r_info
) == R_390_PC16
1135 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC16DBL
1136 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC32
1137 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC32DBL
1138 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC64
)
1156 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1157 entry but we found we will not create any. Called when we find we will
1158 not have any PLT for this symbol, by for example
1159 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
1160 or elf_s390_size_dynamic_sections if no dynamic sections will be
1161 created (we're only linking static objects). */
1164 elf_s390_adjust_gotplt (h
)
1165 struct elf_s390_link_hash_entry
*h
;
1167 if (h
->elf
.root
.type
== bfd_link_hash_warning
)
1168 h
= (struct elf_s390_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
1170 if (h
->gotplt_refcount
<= 0)
1173 /* We simply add the number of gotplt references to the number
1174 * of got references for this symbol. */
1175 h
->elf
.got
.refcount
+= h
->gotplt_refcount
;
1176 h
->gotplt_refcount
= -1;
1179 /* Adjust a symbol defined by a dynamic object and referenced by a
1180 regular object. The current definition is in some section of the
1181 dynamic object, but we're not including those sections. We have to
1182 change the definition to something the rest of the link can
1186 elf_s390_adjust_dynamic_symbol (info
, h
)
1187 struct bfd_link_info
*info
;
1188 struct elf_link_hash_entry
*h
;
1190 struct elf_s390_link_hash_table
*htab
;
1191 struct elf_s390_link_hash_entry
* eh
;
1192 struct elf_s390_dyn_relocs
*p
;
1194 unsigned int power_of_two
;
1196 /* If this is a function, put it in the procedure linkage table. We
1197 will fill in the contents of the procedure linkage table later
1198 (although we could actually do it here). */
1199 if (h
->type
== STT_FUNC
1200 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1202 if (h
->plt
.refcount
<= 0
1204 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1205 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
1206 && h
->root
.type
!= bfd_link_hash_undefweak
1207 && h
->root
.type
!= bfd_link_hash_undefined
))
1209 /* This case can occur if we saw a PLT32 reloc in an input
1210 file, but the symbol was never referred to by a dynamic
1211 object, or if all references were garbage collected. In
1212 such a case, we don't actually need to build a procedure
1213 linkage table, and we can just do a PC32 reloc instead. */
1214 h
->plt
.offset
= (bfd_vma
) -1;
1215 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1216 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1222 /* It's possible that we incorrectly decided a .plt reloc was
1223 needed for an R_390_PC32 reloc to a non-function sym in
1224 check_relocs. We can't decide accurately between function and
1225 non-function syms in check-relocs; Objects loaded later in
1226 the link may change h->type. So fix it now. */
1227 h
->plt
.offset
= (bfd_vma
) -1;
1229 /* If this is a weak symbol, and there is a real definition, the
1230 processor independent code will have arranged for us to see the
1231 real definition first, and we can just use the same value. */
1232 if (h
->weakdef
!= NULL
)
1234 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1235 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1236 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1237 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1241 /* This is a reference to a symbol defined by a dynamic object which
1242 is not a function. */
1244 /* If we are creating a shared library, we must presume that the
1245 only references to the symbol are via the global offset table.
1246 For such cases we need not do anything here; the relocations will
1247 be handled correctly by relocate_section. */
1251 /* If there are no references to this symbol that do not use the
1252 GOT, we don't need to generate a copy reloc. */
1253 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1256 /* If -z nocopyreloc was given, we won't generate them either. */
1257 if (info
->nocopyreloc
)
1259 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1263 eh
= (struct elf_s390_link_hash_entry
*) h
;
1264 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1266 s
= p
->sec
->output_section
;
1267 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1271 /* If we didn't find any dynamic relocs in read-only sections, then
1272 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1275 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1279 /* We must allocate the symbol in our .dynbss section, which will
1280 become part of the .bss section of the executable. There will be
1281 an entry for this symbol in the .dynsym section. The dynamic
1282 object will contain position independent code, so all references
1283 from the dynamic object to this symbol will go through the global
1284 offset table. The dynamic linker will use the .dynsym entry to
1285 determine the address it must put in the global offset table, so
1286 both the dynamic object and the regular object will refer to the
1287 same memory location for the variable. */
1289 htab
= elf_s390_hash_table (info
);
1291 /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1292 copy the initial value out of the dynamic object and into the
1293 runtime process image. */
1294 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1296 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
1297 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1300 /* We need to figure out the alignment required for this symbol. I
1301 have no idea how ELF linkers handle this. */
1302 power_of_two
= bfd_log2 (h
->size
);
1303 if (power_of_two
> 3)
1306 /* Apply the required alignment. */
1308 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
1309 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1311 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1315 /* Define the symbol as being at this point in the section. */
1316 h
->root
.u
.def
.section
= s
;
1317 h
->root
.u
.def
.value
= s
->_raw_size
;
1319 /* Increment the section size to make room for the symbol. */
1320 s
->_raw_size
+= h
->size
;
1325 /* This is the condition under which elf_s390_finish_dynamic_symbol
1326 will be called from elflink.h. If elflink.h doesn't call our
1327 finish_dynamic_symbol routine, we'll need to do something about
1328 initializing any .plt and .got entries in elf_s390_relocate_section. */
1329 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1331 && ((INFO)->shared \
1332 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1333 && ((H)->dynindx != -1 \
1334 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1336 /* Allocate space in .plt, .got and associated reloc sections for
1340 allocate_dynrelocs (h
, inf
)
1341 struct elf_link_hash_entry
*h
;
1344 struct bfd_link_info
*info
;
1345 struct elf_s390_link_hash_table
*htab
;
1346 struct elf_s390_link_hash_entry
*eh
;
1347 struct elf_s390_dyn_relocs
*p
;
1349 if (h
->root
.type
== bfd_link_hash_indirect
)
1352 if (h
->root
.type
== bfd_link_hash_warning
)
1353 /* When warning symbols are created, they **replace** the "real"
1354 entry in the hash table, thus we never get to see the real
1355 symbol in a hash traversal. So look at it now. */
1356 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1358 info
= (struct bfd_link_info
*) inf
;
1359 htab
= elf_s390_hash_table (info
);
1361 if (htab
->elf
.dynamic_sections_created
1362 && h
->plt
.refcount
> 0)
1364 /* Make sure this symbol is output as a dynamic symbol.
1365 Undefined weak syms won't yet be marked as dynamic. */
1366 if (h
->dynindx
== -1
1367 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1369 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1373 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
1375 asection
*s
= htab
->splt
;
1377 /* If this is the first .plt entry, make room for the special
1379 if (s
->_raw_size
== 0)
1380 s
->_raw_size
+= PLT_FIRST_ENTRY_SIZE
;
1382 h
->plt
.offset
= s
->_raw_size
;
1384 /* If this symbol is not defined in a regular file, and we are
1385 not generating a shared library, then set the symbol to this
1386 location in the .plt. This is required to make function
1387 pointers compare as equal between the normal executable and
1388 the shared library. */
1390 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1392 h
->root
.u
.def
.section
= s
;
1393 h
->root
.u
.def
.value
= h
->plt
.offset
;
1396 /* Make room for this entry. */
1397 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1399 /* We also need to make an entry in the .got.plt section, which
1400 will be placed in the .got section by the linker script. */
1401 htab
->sgotplt
->_raw_size
+= GOT_ENTRY_SIZE
;
1403 /* We also need to make an entry in the .rela.plt section. */
1404 htab
->srelplt
->_raw_size
+= sizeof (Elf64_External_Rela
);
1408 h
->plt
.offset
= (bfd_vma
) -1;
1409 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1410 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1415 h
->plt
.offset
= (bfd_vma
) -1;
1416 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1417 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1420 if (h
->got
.refcount
> 0)
1425 /* Make sure this symbol is output as a dynamic symbol.
1426 Undefined weak syms won't yet be marked as dynamic. */
1427 if (h
->dynindx
== -1
1428 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1430 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1435 h
->got
.offset
= s
->_raw_size
;
1436 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1437 dyn
= htab
->elf
.dynamic_sections_created
;
1438 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
1439 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1442 h
->got
.offset
= (bfd_vma
) -1;
1444 eh
= (struct elf_s390_link_hash_entry
*) h
;
1445 if (eh
->dyn_relocs
== NULL
)
1448 /* In the shared -Bsymbolic case, discard space allocated for
1449 dynamic pc-relative relocs against symbols which turn out to be
1450 defined in regular objects. For the normal shared case, discard
1451 space for pc-relative relocs that have become local due to symbol
1452 visibility changes. */
1456 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1457 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
1460 struct elf_s390_dyn_relocs
**pp
;
1462 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1464 p
->count
-= p
->pc_count
;
1475 /* For the non-shared case, discard space for relocs against
1476 symbols which turn out to need copy relocs or are not
1479 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1480 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1481 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1482 || (htab
->elf
.dynamic_sections_created
1483 && (h
->root
.type
== bfd_link_hash_undefweak
1484 || h
->root
.type
== bfd_link_hash_undefined
))))
1486 /* Make sure this symbol is output as a dynamic symbol.
1487 Undefined weak syms won't yet be marked as dynamic. */
1488 if (h
->dynindx
== -1
1489 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1491 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1495 /* If that succeeded, we know we'll be keeping all the
1497 if (h
->dynindx
!= -1)
1501 eh
->dyn_relocs
= NULL
;
1506 /* Finally, allocate space. */
1507 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1509 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1510 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1516 /* Find any dynamic relocs that apply to read-only sections. */
1519 readonly_dynrelocs (h
, inf
)
1520 struct elf_link_hash_entry
*h
;
1523 struct elf_s390_link_hash_entry
*eh
;
1524 struct elf_s390_dyn_relocs
*p
;
1526 if (h
->root
.type
== bfd_link_hash_warning
)
1527 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1529 eh
= (struct elf_s390_link_hash_entry
*) h
;
1530 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1532 asection
*s
= p
->sec
->output_section
;
1534 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1536 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1538 info
->flags
|= DF_TEXTREL
;
1540 /* Not an error, just cut short the traversal. */
1547 /* Set the sizes of the dynamic sections. */
1550 elf_s390_size_dynamic_sections (output_bfd
, info
)
1551 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1552 struct bfd_link_info
*info
;
1554 struct elf_s390_link_hash_table
*htab
;
1560 htab
= elf_s390_hash_table (info
);
1561 dynobj
= htab
->elf
.dynobj
;
1565 if (htab
->elf
.dynamic_sections_created
)
1567 /* Set the contents of the .interp section to the interpreter. */
1570 s
= bfd_get_section_by_name (dynobj
, ".interp");
1573 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1574 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1578 /* Set up .got offsets for local syms, and space for local dynamic
1580 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1582 bfd_signed_vma
*local_got
;
1583 bfd_signed_vma
*end_local_got
;
1584 bfd_size_type locsymcount
;
1585 Elf_Internal_Shdr
*symtab_hdr
;
1588 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1591 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1593 struct elf_s390_dyn_relocs
*p
;
1595 for (p
= *((struct elf_s390_dyn_relocs
**)
1596 &elf_section_data (s
)->local_dynrel
);
1600 if (!bfd_is_abs_section (p
->sec
)
1601 && bfd_is_abs_section (p
->sec
->output_section
))
1603 /* Input section has been discarded, either because
1604 it is a copy of a linkonce section or due to
1605 linker script /DISCARD/, so we'll be discarding
1608 else if (p
->count
!= 0)
1610 srela
= elf_section_data (p
->sec
)->sreloc
;
1611 srela
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1612 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1613 info
->flags
|= DF_TEXTREL
;
1618 local_got
= elf_local_got_refcounts (ibfd
);
1622 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1623 locsymcount
= symtab_hdr
->sh_info
;
1624 end_local_got
= local_got
+ locsymcount
;
1626 srela
= htab
->srelgot
;
1627 for (; local_got
< end_local_got
; ++local_got
)
1631 *local_got
= s
->_raw_size
;
1632 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1634 srela
->_raw_size
+= sizeof (Elf64_External_Rela
);
1637 *local_got
= (bfd_vma
) -1;
1641 /* Allocate global sym .plt and .got entries, and space for global
1642 sym dynamic relocs. */
1643 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1645 /* We now have determined the sizes of the various dynamic sections.
1646 Allocate memory for them. */
1648 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1650 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1655 || s
== htab
->sgotplt
)
1657 /* Strip this section if we don't need it; see the
1660 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
1662 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
1665 /* We use the reloc_count field as a counter if we need
1666 to copy relocs into the output file. */
1671 /* It's not one of our sections, so don't allocate space. */
1675 if (s
->_raw_size
== 0)
1677 /* If we don't need this section, strip it from the
1678 output file. This is to handle .rela.bss and
1679 .rela.plt. We must create it in
1680 create_dynamic_sections, because it must be created
1681 before the linker maps input sections to output
1682 sections. The linker does that before
1683 adjust_dynamic_symbol is called, and it is that
1684 function which decides whether anything needs to go
1685 into these sections. */
1687 _bfd_strip_section_from_output (info
, s
);
1691 /* Allocate memory for the section contents. We use bfd_zalloc
1692 here in case unused entries are not reclaimed before the
1693 section's contents are written out. This should not happen,
1694 but this way if it does, we get a R_390_NONE reloc instead
1696 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1697 if (s
->contents
== NULL
)
1701 if (htab
->elf
.dynamic_sections_created
)
1703 /* Add some entries to the .dynamic section. We fill in the
1704 values later, in elf_s390_finish_dynamic_sections, but we
1705 must add the entries now so that we get the correct size for
1706 the .dynamic section. The DT_DEBUG entry is filled in by the
1707 dynamic linker and used by the debugger. */
1708 #define add_dynamic_entry(TAG, VAL) \
1709 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1713 if (!add_dynamic_entry (DT_DEBUG
, 0))
1717 if (htab
->splt
->_raw_size
!= 0)
1719 if (!add_dynamic_entry (DT_PLTGOT
, 0)
1720 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
1721 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1722 || !add_dynamic_entry (DT_JMPREL
, 0))
1728 if (!add_dynamic_entry (DT_RELA
, 0)
1729 || !add_dynamic_entry (DT_RELASZ
, 0)
1730 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1733 /* If any dynamic relocs apply to a read-only section,
1734 then we need a DT_TEXTREL entry. */
1735 if ((info
->flags
& DF_TEXTREL
) == 0)
1736 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
1739 if ((info
->flags
& DF_TEXTREL
) != 0)
1741 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1746 #undef add_dynamic_entry
1751 /* Relocate a 390 ELF section. */
1754 elf_s390_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1755 contents
, relocs
, local_syms
, local_sections
)
1757 struct bfd_link_info
*info
;
1759 asection
*input_section
;
1761 Elf_Internal_Rela
*relocs
;
1762 Elf_Internal_Sym
*local_syms
;
1763 asection
**local_sections
;
1765 struct elf_s390_link_hash_table
*htab
;
1766 Elf_Internal_Shdr
*symtab_hdr
;
1767 struct elf_link_hash_entry
**sym_hashes
;
1768 bfd_vma
*local_got_offsets
;
1769 Elf_Internal_Rela
*rel
;
1770 Elf_Internal_Rela
*relend
;
1772 if (info
->relocateable
)
1775 htab
= elf_s390_hash_table (info
);
1776 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1777 sym_hashes
= elf_sym_hashes (input_bfd
);
1778 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1781 relend
= relocs
+ input_section
->reloc_count
;
1782 for (; rel
< relend
; rel
++)
1784 unsigned int r_type
;
1785 reloc_howto_type
*howto
;
1786 unsigned long r_symndx
;
1787 struct elf_link_hash_entry
*h
;
1788 Elf_Internal_Sym
*sym
;
1792 bfd_boolean unresolved_reloc
;
1793 bfd_reloc_status_type r
;
1795 r_type
= ELF64_R_TYPE (rel
->r_info
);
1796 if (r_type
== (int) R_390_GNU_VTINHERIT
1797 || r_type
== (int) R_390_GNU_VTENTRY
)
1799 if (r_type
>= (int) R_390_max
)
1801 bfd_set_error (bfd_error_bad_value
);
1805 howto
= elf_howto_table
+ r_type
;
1806 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1808 /* This is a final link. */
1812 unresolved_reloc
= FALSE
;
1813 if (r_symndx
< symtab_hdr
->sh_info
)
1815 sym
= local_syms
+ r_symndx
;
1816 sec
= local_sections
[r_symndx
];
1817 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
1821 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1822 while (h
->root
.type
== bfd_link_hash_indirect
1823 || h
->root
.type
== bfd_link_hash_warning
)
1824 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1826 if (h
->root
.type
== bfd_link_hash_defined
1827 || h
->root
.type
== bfd_link_hash_defweak
)
1829 sec
= h
->root
.u
.def
.section
;
1830 if (sec
->output_section
== NULL
)
1832 /* Set a flag that will be cleared later if we find a
1833 relocation value for this symbol. output_section
1834 is typically NULL for symbols satisfied by a shared
1836 unresolved_reloc
= TRUE
;
1840 relocation
= (h
->root
.u
.def
.value
1841 + sec
->output_section
->vma
1842 + sec
->output_offset
);
1844 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1846 else if (info
->shared
1847 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
1848 && !info
->no_undefined
1849 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1853 if (! ((*info
->callbacks
->undefined_symbol
)
1854 (info
, h
->root
.root
.string
, input_bfd
,
1855 input_section
, rel
->r_offset
,
1856 (!info
->shared
|| info
->no_undefined
1857 || ELF_ST_VISIBILITY (h
->other
)))))
1865 case R_390_GOTPLT12
:
1866 case R_390_GOTPLT16
:
1867 case R_390_GOTPLT32
:
1868 case R_390_GOTPLT64
:
1869 case R_390_GOTPLTENT
:
1870 /* There are three cases for a GOTPLT relocation. 1) The
1871 relocation is against the jump slot entry of a plt that
1872 will get emitted to the output file. 2) The relocation
1873 is against the jump slot of a plt entry that has been
1874 removed. elf_s390_adjust_gotplt has created a GOT entry
1875 as replacement. 3) The relocation is against a local symbol.
1876 Cases 2) and 3) are the same as the GOT relocation code
1877 so we just have to test for case 1 and fall through for
1879 if (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
1884 Current offset - size first entry / entry size. */
1885 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) /
1888 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
1890 relocation
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
1891 unresolved_reloc
= FALSE
;
1893 if (r_type
== R_390_GOTPLTENT
)
1894 relocation
+= htab
->sgot
->output_section
->vma
;
1904 /* Relocation is to the entry for this symbol in the global
1906 if (htab
->sgot
== NULL
)
1913 off
= h
->got
.offset
;
1914 dyn
= htab
->elf
.dynamic_sections_created
;
1915 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
1919 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
1920 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1922 /* This is actually a static link, or it is a
1923 -Bsymbolic link and the symbol is defined
1924 locally, or the symbol was forced to be local
1925 because of a version file. We must initialize
1926 this entry in the global offset table. Since the
1927 offset must always be a multiple of 2, we use the
1928 least significant bit to record whether we have
1929 initialized it already.
1931 When doing a dynamic link, we create a .rel.got
1932 relocation entry to initialize the value. This
1933 is done in the finish_dynamic_symbol routine. */
1938 bfd_put_64 (output_bfd
, relocation
,
1939 htab
->sgot
->contents
+ off
);
1944 unresolved_reloc
= FALSE
;
1948 if (local_got_offsets
== NULL
)
1951 off
= local_got_offsets
[r_symndx
];
1953 /* The offset must always be a multiple of 8. We use
1954 the least significant bit to record whether we have
1955 already generated the necessary reloc. */
1960 bfd_put_64 (output_bfd
, relocation
,
1961 htab
->sgot
->contents
+ off
);
1966 Elf_Internal_Rela outrel
;
1973 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
1974 + htab
->sgot
->output_offset
1976 outrel
.r_info
= ELF64_R_INFO (0, R_390_RELATIVE
);
1977 outrel
.r_addend
= relocation
;
1979 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1980 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1983 local_got_offsets
[r_symndx
] |= 1;
1987 if (off
>= (bfd_vma
) -2)
1990 relocation
= htab
->sgot
->output_offset
+ off
;
1993 * For @GOTENT the relocation is against the offset between
1994 * the instruction and the symbols entry in the GOT and not
1995 * between the start of the GOT and the symbols entry. We
1996 * add the vma of the GOT to get the correct value.
1998 if ( r_type
== R_390_GOTENT
1999 || r_type
== R_390_GOTPLTENT
)
2000 relocation
+= htab
->sgot
->output_section
->vma
;
2004 case R_390_GOTOFF16
:
2005 case R_390_GOTOFF32
:
2006 case R_390_GOTOFF64
:
2007 /* Relocation is relative to the start of the global offset
2010 /* Note that sgot->output_offset is not involved in this
2011 calculation. We always want the start of .got. If we
2012 defined _GLOBAL_OFFSET_TABLE in a different way, as is
2013 permitted by the ABI, we might have to change this
2015 relocation
-= htab
->sgot
->output_section
->vma
;
2019 case R_390_GOTPCDBL
:
2020 /* Use global offset table as symbol value. */
2021 relocation
= htab
->sgot
->output_section
->vma
;
2022 unresolved_reloc
= FALSE
;
2025 case R_390_PLT16DBL
:
2027 case R_390_PLT32DBL
:
2029 /* Relocation is to the entry for this symbol in the
2030 procedure linkage table. */
2032 /* Resolve a PLT32 reloc against a local symbol directly,
2033 without using the procedure linkage table. */
2037 if (h
->plt
.offset
== (bfd_vma
) -1
2038 || htab
->splt
== NULL
)
2040 /* We didn't make a PLT entry for this symbol. This
2041 happens when statically linking PIC code, or when
2042 using -Bsymbolic. */
2046 relocation
= (htab
->splt
->output_section
->vma
2047 + htab
->splt
->output_offset
2049 unresolved_reloc
= FALSE
;
2052 case R_390_PLTOFF16
:
2053 case R_390_PLTOFF32
:
2054 case R_390_PLTOFF64
:
2055 /* Relocation is to the entry for this symbol in the
2056 procedure linkage table relative to the start of the GOT. */
2058 /* For local symbols or if we didn't make a PLT entry for
2059 this symbol resolve the symbol directly. */
2061 || h
->plt
.offset
== (bfd_vma
) -1
2062 || htab
->splt
== NULL
)
2064 relocation
-= htab
->sgot
->output_section
->vma
;
2068 relocation
= (htab
->splt
->output_section
->vma
2069 + htab
->splt
->output_offset
2071 - htab
->sgot
->output_section
->vma
);
2072 unresolved_reloc
= FALSE
;
2084 /* r_symndx will be zero only for relocs against symbols
2085 from removed linkonce sections, or sections discarded by
2088 || (input_section
->flags
& SEC_ALLOC
) == 0)
2092 && ((r_type
!= R_390_PC16
2093 && r_type
!= R_390_PC16DBL
2094 && r_type
!= R_390_PC32
2095 && r_type
!= R_390_PC32DBL
2096 && r_type
!= R_390_PC64
)
2099 && (! info
->symbolic
2100 || (h
->elf_link_hash_flags
2101 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2105 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2106 && (((h
->elf_link_hash_flags
2107 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2108 && (h
->elf_link_hash_flags
2109 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2110 || h
->root
.type
== bfd_link_hash_undefweak
2111 || h
->root
.type
== bfd_link_hash_undefined
)))
2113 Elf_Internal_Rela outrel
;
2114 bfd_boolean skip
, relocate
;
2118 /* When generating a shared object, these relocations
2119 are copied into the output file to be resolved at run
2126 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2128 if (outrel
.r_offset
== (bfd_vma
) -1)
2130 else if (outrel
.r_offset
== (bfd_vma
) -2)
2131 skip
= TRUE
, relocate
= TRUE
;
2133 outrel
.r_offset
+= (input_section
->output_section
->vma
2134 + input_section
->output_offset
);
2137 memset (&outrel
, 0, sizeof outrel
);
2140 && (r_type
== R_390_PC16
2141 || r_type
== R_390_PC16DBL
2142 || r_type
== R_390_PC32
2143 || r_type
== R_390_PC32DBL
2144 || r_type
== R_390_PC64
2147 || (h
->elf_link_hash_flags
2148 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2150 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
2151 outrel
.r_addend
= rel
->r_addend
;
2155 /* This symbol is local, or marked to become local. */
2157 outrel
.r_info
= ELF64_R_INFO (0, R_390_RELATIVE
);
2158 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2161 sreloc
= elf_section_data (input_section
)->sreloc
;
2165 loc
= sreloc
->contents
;
2166 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2167 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2169 /* If this reloc is against an external symbol, we do
2170 not want to fiddle with the addend. Otherwise, we
2171 need to include the symbol value so that it becomes
2172 an addend for the dynamic reloc. */
2183 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2184 because such sections are not SEC_ALLOC and thus ld.so will
2185 not process them. */
2186 if (unresolved_reloc
2187 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
2188 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2189 (*_bfd_error_handler
)
2190 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
2191 bfd_archive_filename (input_bfd
),
2192 bfd_get_section_name (input_bfd
, input_section
),
2193 (long) rel
->r_offset
,
2194 h
->root
.root
.string
);
2196 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2197 contents
, rel
->r_offset
,
2198 relocation
, rel
->r_addend
);
2200 if (r
!= bfd_reloc_ok
)
2205 name
= h
->root
.root
.string
;
2208 name
= bfd_elf_string_from_elf_section (input_bfd
,
2209 symtab_hdr
->sh_link
,
2214 name
= bfd_section_name (input_bfd
, sec
);
2217 if (r
== bfd_reloc_overflow
)
2220 if (! ((*info
->callbacks
->reloc_overflow
)
2221 (info
, name
, howto
->name
, (bfd_vma
) 0,
2222 input_bfd
, input_section
, rel
->r_offset
)))
2227 (*_bfd_error_handler
)
2228 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
2229 bfd_archive_filename (input_bfd
),
2230 bfd_get_section_name (input_bfd
, input_section
),
2231 (long) rel
->r_offset
, name
, (int) r
);
2240 /* Finish up dynamic symbol handling. We set the contents of various
2241 dynamic sections here. */
2244 elf_s390_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2246 struct bfd_link_info
*info
;
2247 struct elf_link_hash_entry
*h
;
2248 Elf_Internal_Sym
*sym
;
2250 struct elf_s390_link_hash_table
*htab
;
2252 htab
= elf_s390_hash_table (info
);
2254 if (h
->plt
.offset
!= (bfd_vma
) -1)
2258 Elf_Internal_Rela rela
;
2261 /* This symbol has an entry in the procedure linkage table. Set
2264 if (h
->dynindx
== -1
2265 || htab
->splt
== NULL
2266 || htab
->sgotplt
== NULL
2267 || htab
->srelplt
== NULL
)
2271 Current offset - size first entry / entry size. */
2272 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
2274 /* Offset in GOT is PLT index plus GOT headers(3) times 8,
2276 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2278 /* Fill in the blueprint of a PLT. */
2279 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD0
,
2280 htab
->splt
->contents
+ h
->plt
.offset
);
2281 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD1
,
2282 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
2283 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD2
,
2284 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
2285 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD3
,
2286 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
2287 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD4
,
2288 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
2289 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD5
,
2290 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
2291 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD6
,
2292 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
2293 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD7
,
2294 htab
->splt
->contents
+ h
->plt
.offset
+ 28);
2295 /* Fixup the relative address to the GOT entry */
2296 bfd_put_32 (output_bfd
,
2297 (htab
->sgotplt
->output_section
->vma
+
2298 htab
->sgotplt
->output_offset
+ got_offset
2299 - (htab
->splt
->output_section
->vma
+ h
->plt
.offset
))/2,
2300 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
2301 /* Fixup the relative branch to PLT 0 */
2302 bfd_put_32 (output_bfd
, - (PLT_FIRST_ENTRY_SIZE
+
2303 (PLT_ENTRY_SIZE
* plt_index
) + 22)/2,
2304 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
2305 /* Fixup offset into symbol table */
2306 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf64_External_Rela
),
2307 htab
->splt
->contents
+ h
->plt
.offset
+ 28);
2309 /* Fill in the entry in the global offset table.
2310 Points to instruction after GOT offset. */
2311 bfd_put_64 (output_bfd
,
2312 (htab
->splt
->output_section
->vma
2313 + htab
->splt
->output_offset
2316 htab
->sgotplt
->contents
+ got_offset
);
2318 /* Fill in the entry in the .rela.plt section. */
2319 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
2320 + htab
->sgotplt
->output_offset
2322 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_390_JMP_SLOT
);
2324 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
2325 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2327 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2329 /* Mark the symbol as undefined, rather than as defined in
2330 the .plt section. Leave the value alone. This is a clue
2331 for the dynamic linker, to make function pointer
2332 comparisons work between an application and shared
2334 sym
->st_shndx
= SHN_UNDEF
;
2338 if (h
->got
.offset
!= (bfd_vma
) -1)
2340 Elf_Internal_Rela rela
;
2343 /* This symbol has an entry in the global offset table. Set it
2346 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
2349 rela
.r_offset
= (htab
->sgot
->output_section
->vma
2350 + htab
->sgot
->output_offset
2351 + (h
->got
.offset
&~ (bfd_vma
) 1));
2353 /* If this is a static link, or it is a -Bsymbolic link and the
2354 symbol is defined locally or was forced to be local because
2355 of a version file, we just want to emit a RELATIVE reloc.
2356 The entry in the global offset table will already have been
2357 initialized in the relocate_section function. */
2361 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
2362 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2364 BFD_ASSERT((h
->got
.offset
& 1) != 0);
2365 rela
.r_info
= ELF64_R_INFO (0, R_390_RELATIVE
);
2366 rela
.r_addend
= (h
->root
.u
.def
.value
2367 + h
->root
.u
.def
.section
->output_section
->vma
2368 + h
->root
.u
.def
.section
->output_offset
);
2372 BFD_ASSERT((h
->got
.offset
& 1) == 0);
2373 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgot
->contents
+ h
->got
.offset
);
2374 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_390_GLOB_DAT
);
2378 loc
= htab
->srelgot
->contents
;
2379 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2380 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2383 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2385 Elf_Internal_Rela rela
;
2388 /* This symbols needs a copy reloc. Set it up. */
2390 if (h
->dynindx
== -1
2391 || (h
->root
.type
!= bfd_link_hash_defined
2392 && h
->root
.type
!= bfd_link_hash_defweak
)
2393 || htab
->srelbss
== NULL
)
2396 rela
.r_offset
= (h
->root
.u
.def
.value
2397 + h
->root
.u
.def
.section
->output_section
->vma
2398 + h
->root
.u
.def
.section
->output_offset
);
2399 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_390_COPY
);
2401 loc
= htab
->srelbss
->contents
;
2402 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2403 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2406 /* Mark some specially defined symbols as absolute. */
2407 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2408 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2409 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2410 sym
->st_shndx
= SHN_ABS
;
2415 /* Used to decide how to sort relocs in an optimal manner for the
2416 dynamic linker, before writing them out. */
2418 static enum elf_reloc_type_class
2419 elf_s390_reloc_type_class (rela
)
2420 const Elf_Internal_Rela
*rela
;
2422 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2424 case R_390_RELATIVE
:
2425 return reloc_class_relative
;
2426 case R_390_JMP_SLOT
:
2427 return reloc_class_plt
;
2429 return reloc_class_copy
;
2431 return reloc_class_normal
;
2435 /* Finish up the dynamic sections. */
2438 elf_s390_finish_dynamic_sections (output_bfd
, info
)
2440 struct bfd_link_info
*info
;
2442 struct elf_s390_link_hash_table
*htab
;
2446 htab
= elf_s390_hash_table (info
);
2447 dynobj
= htab
->elf
.dynobj
;
2448 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2450 if (htab
->elf
.dynamic_sections_created
)
2452 Elf64_External_Dyn
*dyncon
, *dynconend
;
2454 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
2457 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2458 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2459 for (; dyncon
< dynconend
; dyncon
++)
2461 Elf_Internal_Dyn dyn
;
2464 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2472 dyn
.d_un
.d_ptr
= htab
->sgot
->output_section
->vma
;
2476 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
2480 s
= htab
->srelplt
->output_section
;
2481 if (s
->_cooked_size
!= 0)
2482 dyn
.d_un
.d_val
= s
->_cooked_size
;
2484 dyn
.d_un
.d_val
= s
->_raw_size
;
2488 /* The procedure linkage table relocs (DT_JMPREL) should
2489 not be included in the overall relocs (DT_RELA).
2490 Therefore, we override the DT_RELASZ entry here to
2491 make it not include the JMPREL relocs. Since the
2492 linker script arranges for .rela.plt to follow all
2493 other relocation sections, we don't have to worry
2494 about changing the DT_RELA entry. */
2495 s
= htab
->srelplt
->output_section
;
2496 if (s
->_cooked_size
!= 0)
2497 dyn
.d_un
.d_val
-= s
->_cooked_size
;
2499 dyn
.d_un
.d_val
-= s
->_raw_size
;
2503 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2506 /* Fill in the special first entry in the procedure linkage table. */
2507 if (htab
->splt
&& htab
->splt
->_raw_size
> 0)
2509 /* fill in blueprint for plt 0 entry */
2510 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD0
,
2511 htab
->splt
->contents
);
2512 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD1
,
2513 htab
->splt
->contents
+4 );
2514 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD3
,
2515 htab
->splt
->contents
+12 );
2516 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD4
,
2517 htab
->splt
->contents
+16 );
2518 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD5
,
2519 htab
->splt
->contents
+20 );
2520 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD6
,
2521 htab
->splt
->contents
+ 24);
2522 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD7
,
2523 htab
->splt
->contents
+ 28 );
2524 /* Fixup relative address to start of GOT */
2525 bfd_put_32 (output_bfd
,
2526 (htab
->sgotplt
->output_section
->vma
+
2527 htab
->sgotplt
->output_offset
2528 - htab
->splt
->output_section
->vma
- 6)/2,
2529 htab
->splt
->contents
+ 8);
2531 elf_section_data (htab
->splt
->output_section
)
2532 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
2537 /* Fill in the first three entries in the global offset table. */
2538 if (htab
->sgotplt
->_raw_size
> 0)
2540 bfd_put_64 (output_bfd
,
2541 (sdyn
== NULL
? (bfd_vma
) 0
2542 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
2543 htab
->sgotplt
->contents
);
2544 /* One entry for shared object struct ptr. */
2545 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 8);
2546 /* One entry for _dl_runtime_resolve. */
2547 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 12);
2550 elf_section_data (htab
->sgot
->output_section
)
2551 ->this_hdr
.sh_entsize
= 8;
2557 elf_s390_object_p (abfd
)
2560 return bfd_default_set_arch_mach (abfd
, bfd_arch_s390
, bfd_mach_s390_64
);
2564 * Why was the hash table entry size definition changed from
2565 * ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
2566 * this is the only reason for the s390_elf64_size_info structure.
2569 const struct elf_size_info s390_elf64_size_info
=
2571 sizeof (Elf64_External_Ehdr
),
2572 sizeof (Elf64_External_Phdr
),
2573 sizeof (Elf64_External_Shdr
),
2574 sizeof (Elf64_External_Rel
),
2575 sizeof (Elf64_External_Rela
),
2576 sizeof (Elf64_External_Sym
),
2577 sizeof (Elf64_External_Dyn
),
2578 sizeof (Elf_External_Note
),
2579 8, /* hash-table entry size */
2580 1, /* internal relocations per external relocations */
2583 ELFCLASS64
, EV_CURRENT
,
2584 bfd_elf64_write_out_phdrs
,
2585 bfd_elf64_write_shdrs_and_ehdr
,
2586 bfd_elf64_write_relocs
,
2587 bfd_elf64_swap_symbol_in
,
2588 bfd_elf64_swap_symbol_out
,
2589 bfd_elf64_slurp_reloc_table
,
2590 bfd_elf64_slurp_symbol_table
,
2591 bfd_elf64_swap_dyn_in
,
2592 bfd_elf64_swap_dyn_out
,
2593 bfd_elf64_swap_reloc_in
,
2594 bfd_elf64_swap_reloc_out
,
2595 bfd_elf64_swap_reloca_in
,
2596 bfd_elf64_swap_reloca_out
2599 #define TARGET_BIG_SYM bfd_elf64_s390_vec
2600 #define TARGET_BIG_NAME "elf64-s390"
2601 #define ELF_ARCH bfd_arch_s390
2602 #define ELF_MACHINE_CODE EM_S390
2603 #define ELF_MACHINE_ALT1 EM_S390_OLD
2604 #define ELF_MAXPAGESIZE 0x1000
2606 #define elf_backend_size_info s390_elf64_size_info
2608 #define elf_backend_can_gc_sections 1
2609 #define elf_backend_can_refcount 1
2610 #define elf_backend_want_got_plt 1
2611 #define elf_backend_plt_readonly 1
2612 #define elf_backend_want_plt_sym 0
2613 #define elf_backend_got_header_size 24
2614 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
2615 #define elf_backend_rela_normal 1
2617 #define elf_info_to_howto elf_s390_info_to_howto
2619 #define bfd_elf64_bfd_is_local_label_name elf_s390_is_local_label_name
2620 #define bfd_elf64_bfd_link_hash_table_create elf_s390_link_hash_table_create
2621 #define bfd_elf64_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
2623 #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
2624 #define elf_backend_check_relocs elf_s390_check_relocs
2625 #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
2626 #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
2627 #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
2628 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
2629 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
2630 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
2631 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
2632 #define elf_backend_relocate_section elf_s390_relocate_section
2633 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
2634 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
2636 #define elf_backend_object_p elf_s390_object_p
2638 #include "elf64-target.h"