1 /* IBM S/390-specific support for 32-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Carl B. Pedersen and Martin Schwidefsky.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 static reloc_howto_type *elf_s390_reloc_type_lookup
30 PARAMS ((bfd *, bfd_reloc_code_real_type));
31 static void elf_s390_info_to_howto
32 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
33 static bfd_boolean elf_s390_is_local_label_name
34 PARAMS ((bfd *, const char *));
35 static struct bfd_hash_entry *link_hash_newfunc
36 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
37 static struct bfd_link_hash_table *elf_s390_link_hash_table_create
39 static bfd_boolean create_got_section
40 PARAMS((bfd *, struct bfd_link_info *));
41 static bfd_boolean elf_s390_create_dynamic_sections
42 PARAMS((bfd *, struct bfd_link_info *));
43 static void elf_s390_copy_indirect_symbol
44 PARAMS ((const struct elf_backend_data *, struct elf_link_hash_entry *,
45 struct elf_link_hash_entry *));
46 static bfd_boolean elf_s390_check_relocs
47 PARAMS ((bfd *, struct bfd_link_info *, asection *,
48 const Elf_Internal_Rela *));
49 static asection *elf_s390_gc_mark_hook
50 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
51 struct elf_link_hash_entry *, Elf_Internal_Sym *));
52 static bfd_boolean elf_s390_gc_sweep_hook
53 PARAMS ((bfd *, struct bfd_link_info *, asection *,
54 const Elf_Internal_Rela *));
55 struct elf_s390_link_hash_entry;
56 static void elf_s390_adjust_gotplt
57 PARAMS ((struct elf_s390_link_hash_entry *));
58 static bfd_boolean elf_s390_adjust_dynamic_symbol
59 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
60 static bfd_boolean allocate_dynrelocs
61 PARAMS ((struct elf_link_hash_entry *, PTR));
62 static bfd_boolean readonly_dynrelocs
63 PARAMS ((struct elf_link_hash_entry *, PTR));
64 static bfd_boolean elf_s390_size_dynamic_sections
65 PARAMS ((bfd *, struct bfd_link_info *));
66 static bfd_boolean elf_s390_relocate_section
67 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
68 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
69 static bfd_boolean elf_s390_finish_dynamic_symbol
70 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
72 static enum elf_reloc_type_class elf_s390_reloc_type_class
73 PARAMS ((const Elf_Internal_Rela *));
74 static bfd_boolean elf_s390_finish_dynamic_sections
75 PARAMS ((bfd *, struct bfd_link_info *));
76 static bfd_boolean elf_s390_mkobject
78 static bfd_boolean elf_s390_object_p
80 static bfd_boolean elf_s390_grok_prstatus
81 PARAMS ((bfd *, Elf_Internal_Note *));
82 static int elf_s390_tls_transition
83 PARAMS ((struct bfd_link_info *, int, int));
84 static bfd_reloc_status_type s390_tls_reloc
85 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
86 static bfd_vma dtpoff_base
87 PARAMS ((struct bfd_link_info *));
89 PARAMS ((struct bfd_link_info *, bfd_vma));
90 static void invalid_tls_insn
91 PARAMS ((bfd *, asection *, Elf_Internal_Rela *));
92 static bfd_reloc_status_type s390_elf_ldisp_reloc
93 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
97 /* The relocation "howto" table. */
99 static reloc_howto_type elf_howto_table[] =
101 HOWTO (R_390_NONE, /* type */
103 0, /* size (0 = byte, 1 = short, 2 = long) */
105 FALSE, /* pc_relative */
107 complain_overflow_dont, /* complain_on_overflow */
108 bfd_elf_generic_reloc, /* special_function */
109 "R_390_NONE", /* name */
110 FALSE, /* partial_inplace */
113 FALSE), /* pcrel_offset */
115 HOWTO(R_390_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
116 bfd_elf_generic_reloc, "R_390_8", FALSE, 0,0x000000ff, FALSE),
117 HOWTO(R_390_12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
118 bfd_elf_generic_reloc, "R_390_12", FALSE, 0,0x00000fff, FALSE),
119 HOWTO(R_390_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
120 bfd_elf_generic_reloc, "R_390_16", FALSE, 0,0x0000ffff, FALSE),
121 HOWTO(R_390_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
122 bfd_elf_generic_reloc, "R_390_32", FALSE, 0,0xffffffff, FALSE),
123 HOWTO(R_390_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
124 bfd_elf_generic_reloc, "R_390_PC32", FALSE, 0,0xffffffff, TRUE),
125 HOWTO(R_390_GOT12, 0, 1, 12, FALSE, 0, complain_overflow_bitfield,
126 bfd_elf_generic_reloc, "R_390_GOT12", FALSE, 0,0x00000fff, FALSE),
127 HOWTO(R_390_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
128 bfd_elf_generic_reloc, "R_390_GOT32", FALSE, 0,0xffffffff, FALSE),
129 HOWTO(R_390_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
130 bfd_elf_generic_reloc, "R_390_PLT32", FALSE, 0,0xffffffff, TRUE),
131 HOWTO(R_390_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
132 bfd_elf_generic_reloc, "R_390_COPY", FALSE, 0,0xffffffff, FALSE),
133 HOWTO(R_390_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
134 bfd_elf_generic_reloc, "R_390_GLOB_DAT", FALSE, 0,0xffffffff, FALSE),
135 HOWTO(R_390_JMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
136 bfd_elf_generic_reloc, "R_390_JMP_SLOT", FALSE, 0,0xffffffff, FALSE),
137 HOWTO(R_390_RELATIVE, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
138 bfd_elf_generic_reloc, "R_390_RELATIVE", FALSE, 0,0xffffffff, FALSE),
139 HOWTO(R_390_GOTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
140 bfd_elf_generic_reloc, "R_390_GOTOFF32", FALSE, 0,0xffffffff, FALSE),
141 HOWTO(R_390_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
142 bfd_elf_generic_reloc, "R_390_GOTPC", FALSE, 0,0xffffffff, TRUE),
143 HOWTO(R_390_GOT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
144 bfd_elf_generic_reloc, "R_390_GOT16", FALSE, 0,0x0000ffff, FALSE),
145 HOWTO(R_390_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
146 bfd_elf_generic_reloc, "R_390_PC16", FALSE, 0,0x0000ffff, TRUE),
147 HOWTO(R_390_PC16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield,
148 bfd_elf_generic_reloc, "R_390_PC16DBL", FALSE, 0,0x0000ffff, TRUE),
149 HOWTO(R_390_PLT16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield,
150 bfd_elf_generic_reloc, "R_390_PLT16DBL", FALSE, 0,0x0000ffff, TRUE),
151 HOWTO(R_390_PC32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
152 bfd_elf_generic_reloc, "R_390_PC32DBL", FALSE, 0,0xffffffff, TRUE),
153 HOWTO(R_390_PLT32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
154 bfd_elf_generic_reloc, "R_390_PLT32DBL", FALSE, 0,0xffffffff, TRUE),
155 HOWTO(R_390_GOTPCDBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
156 bfd_elf_generic_reloc, "R_390_GOTPCDBL", FALSE, 0,0xffffffff, TRUE),
157 EMPTY_HOWTO (R_390_64), /* Empty entry for R_390_64. */
158 EMPTY_HOWTO (R_390_PC64), /* Empty entry for R_390_PC64. */
159 EMPTY_HOWTO (R_390_GOT64), /* Empty entry for R_390_GOT64. */
160 EMPTY_HOWTO (R_390_PLT64), /* Empty entry for R_390_PLT64. */
161 HOWTO(R_390_GOTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
162 bfd_elf_generic_reloc, "R_390_GOTENT", FALSE, 0,0xffffffff, TRUE),
163 HOWTO(R_390_GOTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
164 bfd_elf_generic_reloc, "R_390_GOTOFF16", FALSE, 0,0x0000ffff, FALSE),
165 EMPTY_HOWTO (R_390_GOTOFF64), /* Empty entry for R_390_GOTOFF64. */
166 HOWTO(R_390_GOTPLT12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
167 bfd_elf_generic_reloc, "R_390_GOTPLT12", FALSE, 0,0x00000fff, FALSE),
168 HOWTO(R_390_GOTPLT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
169 bfd_elf_generic_reloc, "R_390_GOTPLT16", FALSE, 0,0x0000ffff, FALSE),
170 HOWTO(R_390_GOTPLT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
171 bfd_elf_generic_reloc, "R_390_GOTPLT32", FALSE, 0,0xffffffff, FALSE),
172 EMPTY_HOWTO (R_390_GOTPLT64), /* Empty entry for R_390_GOTPLT64. */
173 HOWTO(R_390_GOTPLTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
174 bfd_elf_generic_reloc, "R_390_GOTPLTENT",FALSE, 0,0xffffffff, TRUE),
175 HOWTO(R_390_PLTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
176 bfd_elf_generic_reloc, "R_390_PLTOFF16", FALSE, 0,0x0000ffff, FALSE),
177 HOWTO(R_390_PLTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
178 bfd_elf_generic_reloc, "R_390_PLTOFF32", FALSE, 0,0xffffffff, FALSE),
179 EMPTY_HOWTO (R_390_PLTOFF64), /* Empty entry for R_390_PLTOFF64. */
180 HOWTO(R_390_TLS_LOAD, 0, 0, 0, FALSE, 0, complain_overflow_dont,
181 s390_tls_reloc, "R_390_TLS_LOAD", FALSE, 0, 0, FALSE),
182 HOWTO(R_390_TLS_GDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
183 s390_tls_reloc, "R_390_TLS_GDCALL", FALSE, 0, 0, FALSE),
184 HOWTO(R_390_TLS_LDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
185 s390_tls_reloc, "R_390_TLS_LDCALL", FALSE, 0, 0, FALSE),
186 HOWTO(R_390_TLS_GD32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
187 bfd_elf_generic_reloc, "R_390_TLS_GD32", FALSE, 0, 0xffffffff, FALSE),
188 EMPTY_HOWTO (R_390_TLS_GD64), /* Empty entry for R_390_TLS_GD64. */
189 HOWTO(R_390_TLS_GOTIE12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
190 bfd_elf_generic_reloc, "R_390_TLS_GOTIE12", FALSE, 0, 0x00000fff, FALSE),
191 HOWTO(R_390_TLS_GOTIE32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
192 bfd_elf_generic_reloc, "R_390_TLS_GOTIE32", FALSE, 0, 0xffffffff, FALSE),
193 EMPTY_HOWTO (R_390_TLS_GOTIE64), /* Empty entry for R_390_TLS_GOTIE64. */
194 HOWTO(R_390_TLS_LDM32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
195 bfd_elf_generic_reloc, "R_390_TLS_LDM32", FALSE, 0, 0xffffffff, FALSE),
196 EMPTY_HOWTO (R_390_TLS_LDM64), /* Empty entry for R_390_TLS_LDM64. */
197 HOWTO(R_390_TLS_IE32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
198 bfd_elf_generic_reloc, "R_390_TLS_IE32", FALSE, 0, 0xffffffff, FALSE),
199 EMPTY_HOWTO (R_390_TLS_IE64), /* Empty entry for R_390_TLS_IE64. */
200 HOWTO(R_390_TLS_IEENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
201 bfd_elf_generic_reloc, "R_390_TLS_IEENT", FALSE, 0, 0xffffffff, TRUE),
202 HOWTO(R_390_TLS_LE32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
203 bfd_elf_generic_reloc, "R_390_TLS_LE32", FALSE, 0, 0xffffffff, FALSE),
204 EMPTY_HOWTO (R_390_TLS_LE64), /* Empty entry for R_390_TLS_LE64. */
205 HOWTO(R_390_TLS_LDO32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
206 bfd_elf_generic_reloc, "R_390_TLS_LDO32", FALSE, 0, 0xffffffff, FALSE),
207 EMPTY_HOWTO (R_390_TLS_LDO64), /* Empty entry for R_390_TLS_LDO64. */
208 HOWTO(R_390_TLS_DTPMOD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
209 bfd_elf_generic_reloc, "R_390_TLS_DTPMOD", FALSE, 0, 0xffffffff, FALSE),
210 HOWTO(R_390_TLS_DTPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
211 bfd_elf_generic_reloc, "R_390_TLS_DTPOFF", FALSE, 0, 0xffffffff, FALSE),
212 HOWTO(R_390_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
213 bfd_elf_generic_reloc, "R_390_TLS_TPOFF", FALSE, 0, 0xffffffff, FALSE),
214 HOWTO(R_390_20, 0, 2, 20, FALSE, 8, complain_overflow_dont,
215 s390_elf_ldisp_reloc, "R_390_20", FALSE, 0,0x0fffff00, FALSE),
216 HOWTO(R_390_GOT20, 0, 2, 20, FALSE, 8, complain_overflow_dont,
217 s390_elf_ldisp_reloc, "R_390_GOT20", FALSE, 0,0x0fffff00, FALSE),
218 HOWTO(R_390_GOTPLT20, 0, 2, 20, FALSE, 8, complain_overflow_dont,
219 s390_elf_ldisp_reloc, "R_390_GOTPLT20", FALSE, 0,0x0fffff00, FALSE),
220 HOWTO(R_390_TLS_GOTIE20, 0, 2, 20, FALSE, 8, complain_overflow_dont,
221 s390_elf_ldisp_reloc, "R_390_TLS_GOTIE20", FALSE, 0,0x0fffff00, FALSE),
224 /* GNU extension to record C++ vtable hierarchy. */
225 static reloc_howto_type elf32_s390_vtinherit_howto =
226 HOWTO (R_390_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", FALSE,0, 0, FALSE);
227 static reloc_howto_type elf32_s390_vtentry_howto =
228 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);
230 static reloc_howto_type *
231 elf_s390_reloc_type_lookup (abfd, code)
232 bfd *abfd ATTRIBUTE_UNUSED;
233 bfd_reloc_code_real_type code;
238 return &elf_howto_table[(int) R_390_NONE];
240 return &elf_howto_table[(int) R_390_8];
241 case BFD_RELOC_390_12:
242 return &elf_howto_table[(int) R_390_12];
244 return &elf_howto_table[(int) R_390_16];
246 return &elf_howto_table[(int) R_390_32];
248 return &elf_howto_table[(int) R_390_32];
249 case BFD_RELOC_32_PCREL:
250 return &elf_howto_table[(int) R_390_PC32];
251 case BFD_RELOC_390_GOT12:
252 return &elf_howto_table[(int) R_390_GOT12];
253 case BFD_RELOC_32_GOT_PCREL:
254 return &elf_howto_table[(int) R_390_GOT32];
255 case BFD_RELOC_390_PLT32:
256 return &elf_howto_table[(int) R_390_PLT32];
257 case BFD_RELOC_390_COPY:
258 return &elf_howto_table[(int) R_390_COPY];
259 case BFD_RELOC_390_GLOB_DAT:
260 return &elf_howto_table[(int) R_390_GLOB_DAT];
261 case BFD_RELOC_390_JMP_SLOT:
262 return &elf_howto_table[(int) R_390_JMP_SLOT];
263 case BFD_RELOC_390_RELATIVE:
264 return &elf_howto_table[(int) R_390_RELATIVE];
265 case BFD_RELOC_32_GOTOFF:
266 return &elf_howto_table[(int) R_390_GOTOFF32];
267 case BFD_RELOC_390_GOTPC:
268 return &elf_howto_table[(int) R_390_GOTPC];
269 case BFD_RELOC_390_GOT16:
270 return &elf_howto_table[(int) R_390_GOT16];
271 case BFD_RELOC_16_PCREL:
272 return &elf_howto_table[(int) R_390_PC16];
273 case BFD_RELOC_390_PC16DBL:
274 return &elf_howto_table[(int) R_390_PC16DBL];
275 case BFD_RELOC_390_PLT16DBL:
276 return &elf_howto_table[(int) R_390_PLT16DBL];
277 case BFD_RELOC_390_PC32DBL:
278 return &elf_howto_table[(int) R_390_PC32DBL];
279 case BFD_RELOC_390_PLT32DBL:
280 return &elf_howto_table[(int) R_390_PLT32DBL];
281 case BFD_RELOC_390_GOTPCDBL:
282 return &elf_howto_table[(int) R_390_GOTPCDBL];
283 case BFD_RELOC_390_GOTENT:
284 return &elf_howto_table[(int) R_390_GOTENT];
285 case BFD_RELOC_16_GOTOFF:
286 return &elf_howto_table[(int) R_390_GOTOFF16];
287 case BFD_RELOC_390_GOTPLT12:
288 return &elf_howto_table[(int) R_390_GOTPLT12];
289 case BFD_RELOC_390_GOTPLT16:
290 return &elf_howto_table[(int) R_390_GOTPLT16];
291 case BFD_RELOC_390_GOTPLT32:
292 return &elf_howto_table[(int) R_390_GOTPLT32];
293 case BFD_RELOC_390_GOTPLTENT:
294 return &elf_howto_table[(int) R_390_GOTPLTENT];
295 case BFD_RELOC_390_PLTOFF16:
296 return &elf_howto_table[(int) R_390_PLTOFF16];
297 case BFD_RELOC_390_PLTOFF32:
298 return &elf_howto_table[(int) R_390_PLTOFF32];
299 case BFD_RELOC_390_TLS_LOAD:
300 return &elf_howto_table[(int) R_390_TLS_LOAD];
301 case BFD_RELOC_390_TLS_GDCALL:
302 return &elf_howto_table[(int) R_390_TLS_GDCALL];
303 case BFD_RELOC_390_TLS_LDCALL:
304 return &elf_howto_table[(int) R_390_TLS_LDCALL];
305 case BFD_RELOC_390_TLS_GD32:
306 return &elf_howto_table[(int) R_390_TLS_GD32];
307 case BFD_RELOC_390_TLS_GOTIE12:
308 return &elf_howto_table[(int) R_390_TLS_GOTIE12];
309 case BFD_RELOC_390_TLS_GOTIE32:
310 return &elf_howto_table[(int) R_390_TLS_GOTIE32];
311 case BFD_RELOC_390_TLS_LDM32:
312 return &elf_howto_table[(int) R_390_TLS_LDM32];
313 case BFD_RELOC_390_TLS_IE32:
314 return &elf_howto_table[(int) R_390_TLS_IE32];
315 case BFD_RELOC_390_TLS_IEENT:
316 return &elf_howto_table[(int) R_390_TLS_IEENT];
317 case BFD_RELOC_390_TLS_LE32:
318 return &elf_howto_table[(int) R_390_TLS_LE32];
319 case BFD_RELOC_390_TLS_LDO32:
320 return &elf_howto_table[(int) R_390_TLS_LDO32];
321 case BFD_RELOC_390_TLS_DTPMOD:
322 return &elf_howto_table[(int) R_390_TLS_DTPMOD];
323 case BFD_RELOC_390_TLS_DTPOFF:
324 return &elf_howto_table[(int) R_390_TLS_DTPOFF];
325 case BFD_RELOC_390_TLS_TPOFF:
326 return &elf_howto_table[(int) R_390_TLS_TPOFF];
327 case BFD_RELOC_390_20:
328 return &elf_howto_table[(int) R_390_20];
329 case BFD_RELOC_390_GOT20:
330 return &elf_howto_table[(int) R_390_GOT20];
331 case BFD_RELOC_390_GOTPLT20:
332 return &elf_howto_table[(int) R_390_GOTPLT20];
333 case BFD_RELOC_390_TLS_GOTIE20:
334 return &elf_howto_table[(int) R_390_TLS_GOTIE20];
335 case BFD_RELOC_VTABLE_INHERIT:
336 return &elf32_s390_vtinherit_howto;
337 case BFD_RELOC_VTABLE_ENTRY:
338 return &elf32_s390_vtentry_howto;
345 /* We need to use ELF32_R_TYPE so we have our own copy of this function,
346 and elf32-s390.c has its own copy. */
349 elf_s390_info_to_howto (abfd, cache_ptr, dst)
350 bfd *abfd ATTRIBUTE_UNUSED;
352 Elf_Internal_Rela *dst;
354 switch (ELF32_R_TYPE(dst->r_info))
356 case R_390_GNU_VTINHERIT:
357 cache_ptr->howto = &elf32_s390_vtinherit_howto;
360 case R_390_GNU_VTENTRY:
361 cache_ptr->howto = &elf32_s390_vtentry_howto;
365 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_390_max);
366 cache_ptr->howto = &elf_howto_table[ELF32_R_TYPE(dst->r_info)];
370 /* A relocation function which doesn't do anything. */
371 static bfd_reloc_status_type
372 s390_tls_reloc (abfd, reloc_entry, symbol, data, input_section,
373 output_bfd, error_message)
374 bfd *abfd ATTRIBUTE_UNUSED;
375 arelent *reloc_entry;
376 asymbol *symbol ATTRIBUTE_UNUSED;
377 PTR data ATTRIBUTE_UNUSED;
378 asection *input_section;
380 char **error_message ATTRIBUTE_UNUSED;
383 reloc_entry->address += input_section->output_offset;
387 /* Handle the large displacement relocs. */
388 static bfd_reloc_status_type
389 s390_elf_ldisp_reloc (abfd, reloc_entry, symbol, data, input_section,
390 output_bfd, error_message)
391 bfd *abfd ATTRIBUTE_UNUSED;
392 arelent *reloc_entry;
394 PTR data ATTRIBUTE_UNUSED;
395 asection *input_section;
397 char **error_message ATTRIBUTE_UNUSED;
399 reloc_howto_type *howto = reloc_entry->howto;
403 if (output_bfd != (bfd *) NULL
404 && (symbol->flags & BSF_SECTION_SYM) == 0
405 && (! howto->partial_inplace
406 || reloc_entry->addend == 0))
408 reloc_entry->address += input_section->output_offset;
412 if (output_bfd != NULL)
413 return bfd_reloc_continue;
415 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
416 return bfd_reloc_outofrange;
418 relocation = (symbol->value
419 + symbol->section->output_section->vma
420 + symbol->section->output_offset);
421 relocation += reloc_entry->addend;
422 if (howto->pc_relative)
424 relocation -= (input_section->output_section->vma
425 + input_section->output_offset);
426 relocation -= reloc_entry->address;
429 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
430 insn |= (relocation & 0xfff) << 16 | (relocation & 0xff000) >> 4;
431 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
433 if ((bfd_signed_vma) relocation < - 0x80000
434 || (bfd_signed_vma) relocation > 0x7ffff)
435 return bfd_reloc_overflow;
441 elf_s390_is_local_label_name (abfd, name)
445 if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
448 return _bfd_elf_is_local_label_name (abfd, name);
451 /* Functions for the 390 ELF linker. */
453 /* The name of the dynamic interpreter. This is put in the .interp
456 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
458 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
459 copying dynamic variables from a shared lib into an app's dynbss
460 section, and instead use a dynamic relocation to point into the
462 #define ELIMINATE_COPY_RELOCS 1
464 /* The size in bytes of the first entry in the procedure linkage table. */
465 #define PLT_FIRST_ENTRY_SIZE 32
466 /* The size in bytes of an entry in the procedure linkage table. */
467 #define PLT_ENTRY_SIZE 32
469 #define GOT_ENTRY_SIZE 4
471 /* The first three entries in a procedure linkage table are reserved,
472 and the initial contents are unimportant (we zero them out).
473 Subsequent entries look like this. See the SVR4 ABI 386
474 supplement to see how this works. */
476 /* For the s390, simple addr offset can only be 0 - 4096.
477 To use the full 2 GB address space, several instructions
478 are needed to load an address in a register and execute
479 a branch( or just saving the address)
481 Furthermore, only r 0 and 1 are free to use!!! */
483 /* The first 3 words in the GOT are then reserved.
484 Word 0 is the address of the dynamic table.
485 Word 1 is a pointer to a structure describing the object
486 Word 2 is used to point to the loader entry address.
488 The code for position independent PLT entries looks like this:
490 r12 holds addr of the current GOT at entry to the PLT
492 The GOT holds the address in the PLT to be executed.
493 The loader then gets:
494 24(15) = Pointer to the structure describing the object.
495 28(15) = Offset in symbol table
497 The loader must then find the module where the function is
498 and insert the address in the GOT.
500 Note: 390 can only address +- 64 K relative.
501 We check if offset > 65536, then make a relative branch -64xxx
502 back to a previous defined branch
504 PLT1: BASR 1,0 # 2 bytes
505 L 1,22(1) # 4 bytes Load offset in GOT in r 1
506 L 1,(1,12) # 4 bytes Load address from GOT in r1
507 BCR 15,1 # 2 bytes Jump to address
508 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
509 L 1,14(1) # 4 bytes Load offset in symol table in r1
510 BRC 15,-x # 4 bytes Jump to start of PLT
511 .word 0 # 2 bytes filler
512 .long ? # 4 bytes offset in GOT
513 .long ? # 4 bytes offset into symbol table
515 This was the general case. There are two additional, optimizes PLT
516 definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768.
517 First the one for GOT offsets < 4096:
519 PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1
520 BCR 15,1 # 2 bytes Jump to address
521 .word 0,0,0 # 6 bytes filler
522 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
523 L 1,14(1) # 4 bytes Load offset in symbol table in r1
524 BRC 15,-x # 4 bytes Jump to start of PLT
525 .word 0,0,0 # 6 bytes filler
526 .long ? # 4 bytes offset into symbol table
528 Second the one for GOT offsets < 32768:
530 PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1
531 L 1,(1,12) # 4 bytes Load address from GOT to r1
532 BCR 15,1 # 2 bytes Jump to address
533 .word 0 # 2 bytes filler
534 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
535 L 1,14(1) # 4 bytes Load offset in symbol table in r1
536 BRC 15,-x # 4 bytes Jump to start of PLT
537 .word 0,0,0 # 6 bytes filler
538 .long ? # 4 bytes offset into symbol table
540 Total = 32 bytes per PLT entry
542 The code for static build PLT entries looks like this:
544 PLT1: BASR 1,0 # 2 bytes
545 L 1,22(1) # 4 bytes Load address of GOT entry
546 L 1,0(0,1) # 4 bytes Load address from GOT in r1
547 BCR 15,1 # 2 bytes Jump to address
548 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
549 L 1,14(1) # 4 bytes Load offset in symbol table in r1
550 BRC 15,-x # 4 bytes Jump to start of PLT
551 .word 0 # 2 bytes filler
552 .long ? # 4 bytes address of GOT entry
553 .long ? # 4 bytes offset into symbol table */
555 #define PLT_PIC_ENTRY_WORD0 0x0d105810
556 #define PLT_PIC_ENTRY_WORD1 0x10165811
557 #define PLT_PIC_ENTRY_WORD2 0xc00007f1
558 #define PLT_PIC_ENTRY_WORD3 0x0d105810
559 #define PLT_PIC_ENTRY_WORD4 0x100ea7f4
561 #define PLT_PIC12_ENTRY_WORD0 0x5810c000
562 #define PLT_PIC12_ENTRY_WORD1 0x07f10000
563 #define PLT_PIC12_ENTRY_WORD2 0x00000000
564 #define PLT_PIC12_ENTRY_WORD3 0x0d105810
565 #define PLT_PIC12_ENTRY_WORD4 0x100ea7f4
567 #define PLT_PIC16_ENTRY_WORD0 0xa7180000
568 #define PLT_PIC16_ENTRY_WORD1 0x5811c000
569 #define PLT_PIC16_ENTRY_WORD2 0x07f10000
570 #define PLT_PIC16_ENTRY_WORD3 0x0d105810
571 #define PLT_PIC16_ENTRY_WORD4 0x100ea7f4
573 #define PLT_ENTRY_WORD0 0x0d105810
574 #define PLT_ENTRY_WORD1 0x10165810
575 #define PLT_ENTRY_WORD2 0x100007f1
576 #define PLT_ENTRY_WORD3 0x0d105810
577 #define PLT_ENTRY_WORD4 0x100ea7f4
579 /* The first PLT entry pushes the offset into the symbol table
580 from R1 onto the stack at 8(15) and the loader object info
581 at 12(15), loads the loader address in R1 and jumps to it. */
583 /* The first entry in the PLT for PIC code:
586 ST 1,28(15) # R1 has offset into symbol table
587 L 1,4(12) # Get loader ino(object struct address)
588 ST 1,24(15) # Store address
589 L 1,8(12) # Entry address of loader in R1
590 BR 1 # Jump to loader
592 The first entry in the PLT for static code:
595 ST 1,28(15) # R1 has offset into symbol table
597 L 1,18(0,1) # Get address of GOT
598 MVC 24(4,15),4(1) # Move loader ino to stack
599 L 1,8(1) # Get address of loader
600 BR 1 # Jump to loader
602 .long got # address of GOT */
604 #define PLT_PIC_FIRST_ENTRY_WORD0 0x5010f01c
605 #define PLT_PIC_FIRST_ENTRY_WORD1 0x5810c004
606 #define PLT_PIC_FIRST_ENTRY_WORD2 0x5010f018
607 #define PLT_PIC_FIRST_ENTRY_WORD3 0x5810c008
608 #define PLT_PIC_FIRST_ENTRY_WORD4 0x07f10000
610 #define PLT_FIRST_ENTRY_WORD0 0x5010f01c
611 #define PLT_FIRST_ENTRY_WORD1 0x0d105810
612 #define PLT_FIRST_ENTRY_WORD2 0x1012D203
613 #define PLT_FIRST_ENTRY_WORD3 0xf0181004
614 #define PLT_FIRST_ENTRY_WORD4 0x58101008
615 #define PLT_FIRST_ENTRY_WORD5 0x07f10000
617 /* The s390 linker needs to keep track of the number of relocs that it
618 decides to copy as dynamic relocs in check_relocs for each symbol.
619 This is so that it can later discard them if they are found to be
620 unnecessary. We store the information in a field extending the
621 regular ELF linker hash table. */
623 struct elf_s390_dyn_relocs
625 struct elf_s390_dyn_relocs *next;
627 /* The input section of the reloc. */
630 /* Total number of relocs copied for the input section. */
633 /* Number of pc-relative relocs copied for the input section. */
634 bfd_size_type pc_count;
637 /* s390 ELF linker hash entry. */
639 struct elf_s390_link_hash_entry
641 struct elf_link_hash_entry elf;
643 /* Track dynamic relocs copied for this symbol. */
644 struct elf_s390_dyn_relocs *dyn_relocs;
646 /* Number of GOTPLT references for a function. */
647 bfd_signed_vma gotplt_refcount;
649 #define GOT_UNKNOWN 0
653 #define GOT_TLS_IE_NLT 4
654 unsigned char tls_type;
657 #define elf_s390_hash_entry(ent) \
658 ((struct elf_s390_link_hash_entry *)(ent))
660 struct elf_s390_obj_tdata
662 struct elf_obj_tdata root;
664 /* tls_type for each local got entry. */
665 char *local_got_tls_type;
668 #define elf_s390_tdata(abfd) \
669 ((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
671 #define elf_s390_local_got_tls_type(abfd) \
672 (elf_s390_tdata (abfd)->local_got_tls_type)
675 elf_s390_mkobject (abfd)
678 bfd_size_type amt = sizeof (struct elf_s390_obj_tdata);
679 abfd->tdata.any = bfd_zalloc (abfd, amt);
680 if (abfd->tdata.any == NULL)
686 elf_s390_object_p (abfd)
689 /* Set the right machine number for an s390 elf32 file. */
690 return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_31);
693 /* s390 ELF linker hash table. */
695 struct elf_s390_link_hash_table
697 struct elf_link_hash_table elf;
699 /* Short-cuts to get to dynamic linker sections. */
709 bfd_signed_vma refcount;
713 /* Small local sym to section mapping cache. */
714 struct sym_sec_cache sym_sec;
717 /* Get the s390 ELF linker hash table from a link_info structure. */
719 #define elf_s390_hash_table(p) \
720 ((struct elf_s390_link_hash_table *) ((p)->hash))
722 /* Create an entry in an s390 ELF linker hash table. */
724 static struct bfd_hash_entry *
725 link_hash_newfunc (entry, table, string)
726 struct bfd_hash_entry *entry;
727 struct bfd_hash_table *table;
730 /* Allocate the structure if it has not already been allocated by a
734 entry = bfd_hash_allocate (table,
735 sizeof (struct elf_s390_link_hash_entry));
740 /* Call the allocation method of the superclass. */
741 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
744 struct elf_s390_link_hash_entry *eh;
746 eh = (struct elf_s390_link_hash_entry *) entry;
747 eh->dyn_relocs = NULL;
748 eh->gotplt_refcount = 0;
749 eh->tls_type = GOT_UNKNOWN;
755 /* Create an s390 ELF linker hash table. */
757 static struct bfd_link_hash_table *
758 elf_s390_link_hash_table_create (abfd)
761 struct elf_s390_link_hash_table *ret;
762 bfd_size_type amt = sizeof (struct elf_s390_link_hash_table);
764 ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt);
768 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc))
781 ret->tls_ldm_got.refcount = 0;
782 ret->sym_sec.abfd = NULL;
784 return &ret->elf.root;
787 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
788 shortcuts to them in our hash table. */
791 create_got_section (dynobj, info)
793 struct bfd_link_info *info;
795 struct elf_s390_link_hash_table *htab;
797 if (! _bfd_elf_create_got_section (dynobj, info))
800 htab = elf_s390_hash_table (info);
801 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
802 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
803 if (!htab->sgot || !htab->sgotplt)
806 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
807 if (htab->srelgot == NULL
808 || ! bfd_set_section_flags (dynobj, htab->srelgot,
809 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
810 | SEC_IN_MEMORY | SEC_LINKER_CREATED
812 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
817 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
818 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
822 elf_s390_create_dynamic_sections (dynobj, info)
824 struct bfd_link_info *info;
826 struct elf_s390_link_hash_table *htab;
828 htab = elf_s390_hash_table (info);
829 if (!htab->sgot && !create_got_section (dynobj, info))
832 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
835 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
836 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
837 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
839 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
841 if (!htab->splt || !htab->srelplt || !htab->sdynbss
842 || (!info->shared && !htab->srelbss))
848 /* Copy the extra info we tack onto an elf_link_hash_entry. */
851 elf_s390_copy_indirect_symbol (bed, dir, ind)
852 const struct elf_backend_data *bed;
853 struct elf_link_hash_entry *dir, *ind;
855 struct elf_s390_link_hash_entry *edir, *eind;
857 edir = (struct elf_s390_link_hash_entry *) dir;
858 eind = (struct elf_s390_link_hash_entry *) ind;
860 if (eind->dyn_relocs != NULL)
862 if (edir->dyn_relocs != NULL)
864 struct elf_s390_dyn_relocs **pp;
865 struct elf_s390_dyn_relocs *p;
867 if (ind->root.type == bfd_link_hash_indirect)
870 /* Add reloc counts against the weak sym to the strong sym
871 list. Merge any entries against the same section. */
872 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
874 struct elf_s390_dyn_relocs *q;
876 for (q = edir->dyn_relocs; q != NULL; q = q->next)
877 if (q->sec == p->sec)
879 q->pc_count += p->pc_count;
880 q->count += p->count;
887 *pp = edir->dyn_relocs;
890 edir->dyn_relocs = eind->dyn_relocs;
891 eind->dyn_relocs = NULL;
894 if (ind->root.type == bfd_link_hash_indirect
895 && dir->got.refcount <= 0)
897 edir->tls_type = eind->tls_type;
898 eind->tls_type = GOT_UNKNOWN;
901 if (ELIMINATE_COPY_RELOCS
902 && ind->root.type != bfd_link_hash_indirect
903 && dir->dynamic_adjusted)
905 /* If called to transfer flags for a weakdef during processing
906 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
907 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
908 dir->ref_dynamic |= ind->ref_dynamic;
909 dir->ref_regular |= ind->ref_regular;
910 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
911 dir->needs_plt |= ind->needs_plt;
914 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
918 elf_s390_tls_transition (info, r_type, is_local)
919 struct bfd_link_info *info;
931 return R_390_TLS_LE32;
932 return R_390_TLS_IE32;
933 case R_390_TLS_GOTIE32:
935 return R_390_TLS_LE32;
936 return R_390_TLS_GOTIE32;
937 case R_390_TLS_LDM32:
938 return R_390_TLS_LE32;
944 /* Look through the relocs for a section during the first phase, and
945 allocate space in the global offset table or procedure linkage
949 elf_s390_check_relocs (abfd, info, sec, relocs)
951 struct bfd_link_info *info;
953 const Elf_Internal_Rela *relocs;
955 struct elf_s390_link_hash_table *htab;
956 Elf_Internal_Shdr *symtab_hdr;
957 struct elf_link_hash_entry **sym_hashes;
958 const Elf_Internal_Rela *rel;
959 const Elf_Internal_Rela *rel_end;
961 bfd_signed_vma *local_got_refcounts;
962 int tls_type, old_tls_type;
964 if (info->relocatable)
967 htab = elf_s390_hash_table (info);
968 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
969 sym_hashes = elf_sym_hashes (abfd);
970 local_got_refcounts = elf_local_got_refcounts (abfd);
974 rel_end = relocs + sec->reloc_count;
975 for (rel = relocs; rel < rel_end; rel++)
978 unsigned long r_symndx;
979 struct elf_link_hash_entry *h;
981 r_symndx = ELF32_R_SYM (rel->r_info);
983 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
985 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
990 if (r_symndx < symtab_hdr->sh_info)
993 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
995 /* Create got section and local_got_refcounts array if they
997 r_type = elf_s390_tls_transition (info,
998 ELF32_R_TYPE (rel->r_info),
1007 case R_390_GOTPLT12:
1008 case R_390_GOTPLT16:
1009 case R_390_GOTPLT20:
1010 case R_390_GOTPLT32:
1011 case R_390_GOTPLTENT:
1012 case R_390_TLS_GD32:
1013 case R_390_TLS_GOTIE12:
1014 case R_390_TLS_GOTIE20:
1015 case R_390_TLS_GOTIE32:
1016 case R_390_TLS_IEENT:
1017 case R_390_TLS_IE32:
1018 case R_390_TLS_LDM32:
1020 && local_got_refcounts == NULL)
1024 size = symtab_hdr->sh_info;
1025 size *= (sizeof (bfd_signed_vma) + sizeof(char));
1026 local_got_refcounts = ((bfd_signed_vma *)
1027 bfd_zalloc (abfd, size));
1028 if (local_got_refcounts == NULL)
1030 elf_local_got_refcounts (abfd) = local_got_refcounts;
1031 elf_s390_local_got_tls_type (abfd)
1032 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
1035 case R_390_GOTOFF16:
1036 case R_390_GOTOFF32:
1038 case R_390_GOTPCDBL:
1039 if (htab->sgot == NULL)
1041 if (htab->elf.dynobj == NULL)
1042 htab->elf.dynobj = abfd;
1043 if (!create_got_section (htab->elf.dynobj, info))
1050 case R_390_GOTOFF16:
1051 case R_390_GOTOFF32:
1053 case R_390_GOTPCDBL:
1054 /* Got is created, nothing to be done. */
1057 case R_390_PLT16DBL:
1058 case R_390_PLT32DBL:
1060 case R_390_PLTOFF16:
1061 case R_390_PLTOFF32:
1062 /* This symbol requires a procedure linkage table entry. We
1063 actually build the entry in adjust_dynamic_symbol,
1064 because this might be a case of linking PIC code which is
1065 never referenced by a dynamic object, in which case we
1066 don't need to generate a procedure linkage table entry
1069 /* If this is a local symbol, we resolve it directly without
1070 creating a procedure linkage table entry. */
1074 h->plt.refcount += 1;
1078 case R_390_GOTPLT12:
1079 case R_390_GOTPLT16:
1080 case R_390_GOTPLT20:
1081 case R_390_GOTPLT32:
1082 case R_390_GOTPLTENT:
1083 /* This symbol requires either a procedure linkage table entry
1084 or an entry in the local got. We actually build the entry
1085 in adjust_dynamic_symbol because whether this is really a
1086 global reference can change and with it the fact if we have
1087 to create a plt entry or a local got entry. To be able to
1088 make a once global symbol a local one we have to keep track
1089 of the number of gotplt references that exist for this
1093 ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount++;
1095 h->plt.refcount += 1;
1098 local_got_refcounts[r_symndx] += 1;
1101 case R_390_TLS_LDM32:
1102 htab->tls_ldm_got.refcount += 1;
1105 case R_390_TLS_IE32:
1106 case R_390_TLS_GOTIE12:
1107 case R_390_TLS_GOTIE20:
1108 case R_390_TLS_GOTIE32:
1109 case R_390_TLS_IEENT:
1111 info->flags |= DF_STATIC_TLS;
1119 case R_390_TLS_GD32:
1120 /* This symbol requires a global offset table entry. */
1129 tls_type = GOT_NORMAL;
1131 case R_390_TLS_GD32:
1132 tls_type = GOT_TLS_GD;
1134 case R_390_TLS_IE32:
1135 case R_390_TLS_GOTIE32:
1136 tls_type = GOT_TLS_IE;
1138 case R_390_TLS_GOTIE12:
1139 case R_390_TLS_GOTIE20:
1140 case R_390_TLS_IEENT:
1141 tls_type = GOT_TLS_IE_NLT;
1147 h->got.refcount += 1;
1148 old_tls_type = elf_s390_hash_entry(h)->tls_type;
1152 local_got_refcounts[r_symndx] += 1;
1153 old_tls_type = elf_s390_local_got_tls_type (abfd) [r_symndx];
1155 /* If a TLS symbol is accessed using IE at least once,
1156 there is no point to use dynamic model for it. */
1157 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN)
1159 if (old_tls_type == GOT_NORMAL || tls_type == GOT_NORMAL)
1161 (*_bfd_error_handler)
1162 (_("%B: `%s' accessed both as normal and thread local symbol"),
1163 abfd, h->root.root.string);
1166 if (old_tls_type > tls_type)
1167 tls_type = old_tls_type;
1170 if (old_tls_type != tls_type)
1173 elf_s390_hash_entry (h)->tls_type = tls_type;
1175 elf_s390_local_got_tls_type (abfd) [r_symndx] = tls_type;
1178 if (r_type != R_390_TLS_IE32)
1182 case R_390_TLS_LE32:
1185 info->flags |= DF_STATIC_TLS;
1195 if (h != NULL && !info->shared)
1197 /* If this reloc is in a read-only section, we might
1198 need a copy reloc. We can't check reliably at this
1199 stage whether the section is read-only, as input
1200 sections have not yet been mapped to output sections.
1201 Tentatively set the flag for now, and correct in
1202 adjust_dynamic_symbol. */
1205 /* We may need a .plt entry if the function this reloc
1206 refers to is in a shared lib. */
1207 h->plt.refcount += 1;
1210 /* If we are creating a shared library, and this is a reloc
1211 against a global symbol, or a non PC relative reloc
1212 against a local symbol, then we need to copy the reloc
1213 into the shared library. However, if we are linking with
1214 -Bsymbolic, we do not need to copy a reloc against a
1215 global symbol which is defined in an object we are
1216 including in the link (i.e., DEF_REGULAR is set). At
1217 this point we have not seen all the input files, so it is
1218 possible that DEF_REGULAR is not set now but will be set
1219 later (it is never cleared). In case of a weak definition,
1220 DEF_REGULAR may be cleared later by a strong definition in
1221 a shared library. We account for that possibility below by
1222 storing information in the relocs_copied field of the hash
1223 table entry. A similar situation occurs when creating
1224 shared libraries and symbol visibility changes render the
1227 If on the other hand, we are creating an executable, we
1228 may need to keep relocations for symbols satisfied by a
1229 dynamic library if we manage to avoid copy relocs for the
1232 && (sec->flags & SEC_ALLOC) != 0
1233 && ((ELF32_R_TYPE (rel->r_info) != R_390_PC16
1234 && ELF32_R_TYPE (rel->r_info) != R_390_PC16DBL
1235 && ELF32_R_TYPE (rel->r_info) != R_390_PC32DBL
1236 && ELF32_R_TYPE (rel->r_info) != R_390_PC32)
1238 && (! info->symbolic
1239 || h->root.type == bfd_link_hash_defweak
1240 || !h->def_regular))))
1241 || (ELIMINATE_COPY_RELOCS
1243 && (sec->flags & SEC_ALLOC) != 0
1245 && (h->root.type == bfd_link_hash_defweak
1246 || !h->def_regular)))
1248 struct elf_s390_dyn_relocs *p;
1249 struct elf_s390_dyn_relocs **head;
1251 /* We must copy these reloc types into the output file.
1252 Create a reloc section in dynobj and make room for
1259 name = (bfd_elf_string_from_elf_section
1261 elf_elfheader (abfd)->e_shstrndx,
1262 elf_section_data (sec)->rel_hdr.sh_name));
1266 if (strncmp (name, ".rela", 5) != 0
1267 || strcmp (bfd_get_section_name (abfd, sec),
1270 (*_bfd_error_handler)
1271 (_("%B: bad relocation section name `%s\'"),
1275 if (htab->elf.dynobj == NULL)
1276 htab->elf.dynobj = abfd;
1278 dynobj = htab->elf.dynobj;
1279 sreloc = bfd_get_section_by_name (dynobj, name);
1284 sreloc = bfd_make_section (dynobj, name);
1285 flags = (SEC_HAS_CONTENTS | SEC_READONLY
1286 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1287 if ((sec->flags & SEC_ALLOC) != 0)
1288 flags |= SEC_ALLOC | SEC_LOAD;
1290 || ! bfd_set_section_flags (dynobj, sreloc, flags)
1291 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
1294 elf_section_data (sec)->sreloc = sreloc;
1297 /* If this is a global symbol, we count the number of
1298 relocations we need for this symbol. */
1301 head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs;
1305 /* Track dynamic relocs needed for local syms too.
1306 We really need local syms available to do this
1310 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
1315 head = ((struct elf_s390_dyn_relocs **)
1316 &elf_section_data (s)->local_dynrel);
1320 if (p == NULL || p->sec != sec)
1322 bfd_size_type amt = sizeof *p;
1324 p = ((struct elf_s390_dyn_relocs *)
1325 bfd_alloc (htab->elf.dynobj, amt));
1336 if (ELF32_R_TYPE (rel->r_info) == R_390_PC16
1337 || ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL
1338 || ELF32_R_TYPE (rel->r_info) == R_390_PC32DBL
1339 || ELF32_R_TYPE (rel->r_info) == R_390_PC32)
1344 /* This relocation describes the C++ object vtable hierarchy.
1345 Reconstruct it for later use during GC. */
1346 case R_390_GNU_VTINHERIT:
1347 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1351 /* This relocation describes which C++ vtable entries are actually
1352 used. Record for later use during GC. */
1353 case R_390_GNU_VTENTRY:
1354 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1366 /* Return the section that should be marked against GC for a given
1370 elf_s390_gc_mark_hook (sec, info, rel, h, sym)
1372 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1373 Elf_Internal_Rela *rel;
1374 struct elf_link_hash_entry *h;
1375 Elf_Internal_Sym *sym;
1379 switch (ELF32_R_TYPE (rel->r_info))
1381 case R_390_GNU_VTINHERIT:
1382 case R_390_GNU_VTENTRY:
1386 switch (h->root.type)
1388 case bfd_link_hash_defined:
1389 case bfd_link_hash_defweak:
1390 return h->root.u.def.section;
1392 case bfd_link_hash_common:
1393 return h->root.u.c.p->section;
1401 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
1406 /* Update the got entry reference counts for the section being removed. */
1409 elf_s390_gc_sweep_hook (abfd, info, sec, relocs)
1411 struct bfd_link_info *info;
1413 const Elf_Internal_Rela *relocs;
1415 Elf_Internal_Shdr *symtab_hdr;
1416 struct elf_link_hash_entry **sym_hashes;
1417 bfd_signed_vma *local_got_refcounts;
1418 const Elf_Internal_Rela *rel, *relend;
1420 elf_section_data (sec)->local_dynrel = NULL;
1422 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1423 sym_hashes = elf_sym_hashes (abfd);
1424 local_got_refcounts = elf_local_got_refcounts (abfd);
1426 relend = relocs + sec->reloc_count;
1427 for (rel = relocs; rel < relend; rel++)
1429 unsigned long r_symndx;
1430 unsigned int r_type;
1431 struct elf_link_hash_entry *h = NULL;
1433 r_symndx = ELF32_R_SYM (rel->r_info);
1434 if (r_symndx >= symtab_hdr->sh_info)
1436 struct elf_s390_link_hash_entry *eh;
1437 struct elf_s390_dyn_relocs **pp;
1438 struct elf_s390_dyn_relocs *p;
1440 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1441 while (h->root.type == bfd_link_hash_indirect
1442 || h->root.type == bfd_link_hash_warning)
1443 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1444 eh = (struct elf_s390_link_hash_entry *) h;
1446 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1449 /* Everything must go for SEC. */
1455 r_type = ELF32_R_TYPE (rel->r_info);
1456 r_type = elf_s390_tls_transition (info, r_type, h != NULL);
1459 case R_390_TLS_LDM32:
1460 if (elf_s390_hash_table (info)->tls_ldm_got.refcount > 0)
1461 elf_s390_hash_table (info)->tls_ldm_got.refcount -= 1;
1464 case R_390_TLS_GD32:
1465 case R_390_TLS_IE32:
1466 case R_390_TLS_GOTIE12:
1467 case R_390_TLS_GOTIE20:
1468 case R_390_TLS_GOTIE32:
1469 case R_390_TLS_IEENT:
1474 case R_390_GOTOFF16:
1475 case R_390_GOTOFF32:
1477 case R_390_GOTPCDBL:
1481 if (h->got.refcount > 0)
1482 h->got.refcount -= 1;
1484 else if (local_got_refcounts != NULL)
1486 if (local_got_refcounts[r_symndx] > 0)
1487 local_got_refcounts[r_symndx] -= 1;
1504 case R_390_PLT16DBL:
1505 case R_390_PLT32DBL:
1507 case R_390_PLTOFF16:
1508 case R_390_PLTOFF32:
1511 if (h->plt.refcount > 0)
1512 h->plt.refcount -= 1;
1516 case R_390_GOTPLT12:
1517 case R_390_GOTPLT16:
1518 case R_390_GOTPLT20:
1519 case R_390_GOTPLT32:
1520 case R_390_GOTPLTENT:
1523 if (h->plt.refcount > 0)
1525 ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount--;
1526 h->plt.refcount -= 1;
1529 else if (local_got_refcounts != NULL)
1531 if (local_got_refcounts[r_symndx] > 0)
1532 local_got_refcounts[r_symndx] -= 1;
1544 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1545 entry but we found we will not create any. Called when we find we will
1546 not have any PLT for this symbol, by for example
1547 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
1548 or elf_s390_size_dynamic_sections if no dynamic sections will be
1549 created (we're only linking static objects). */
1552 elf_s390_adjust_gotplt (h)
1553 struct elf_s390_link_hash_entry *h;
1555 if (h->elf.root.type == bfd_link_hash_warning)
1556 h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link;
1558 if (h->gotplt_refcount <= 0)
1561 /* We simply add the number of gotplt references to the number
1562 * of got references for this symbol. */
1563 h->elf.got.refcount += h->gotplt_refcount;
1564 h->gotplt_refcount = -1;
1567 /* Adjust a symbol defined by a dynamic object and referenced by a
1568 regular object. The current definition is in some section of the
1569 dynamic object, but we're not including those sections. We have to
1570 change the definition to something the rest of the link can
1574 elf_s390_adjust_dynamic_symbol (info, h)
1575 struct bfd_link_info *info;
1576 struct elf_link_hash_entry *h;
1578 struct elf_s390_link_hash_table *htab;
1580 unsigned int power_of_two;
1582 /* If this is a function, put it in the procedure linkage table. We
1583 will fill in the contents of the procedure linkage table later
1584 (although we could actually do it here). */
1585 if (h->type == STT_FUNC
1588 if (h->plt.refcount <= 0
1592 && h->root.type != bfd_link_hash_undefweak
1593 && h->root.type != bfd_link_hash_undefined))
1595 /* This case can occur if we saw a PLT32 reloc in an input
1596 file, but the symbol was never referred to by a dynamic
1597 object, or if all references were garbage collected. In
1598 such a case, we don't actually need to build a procedure
1599 linkage table, and we can just do a PC32 reloc instead. */
1600 h->plt.offset = (bfd_vma) -1;
1602 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1608 /* It's possible that we incorrectly decided a .plt reloc was
1609 needed for an R_390_PC32 reloc to a non-function sym in
1610 check_relocs. We can't decide accurately between function and
1611 non-function syms in check-relocs; Objects loaded later in
1612 the link may change h->type. So fix it now. */
1613 h->plt.offset = (bfd_vma) -1;
1615 /* If this is a weak symbol, and there is a real definition, the
1616 processor independent code will have arranged for us to see the
1617 real definition first, and we can just use the same value. */
1618 if (h->u.weakdef != NULL)
1620 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1621 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1622 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1623 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1624 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1625 h->non_got_ref = h->u.weakdef->non_got_ref;
1629 /* This is a reference to a symbol defined by a dynamic object which
1630 is not a function. */
1632 /* If we are creating a shared library, we must presume that the
1633 only references to the symbol are via the global offset table.
1634 For such cases we need not do anything here; the relocations will
1635 be handled correctly by relocate_section. */
1639 /* If there are no references to this symbol that do not use the
1640 GOT, we don't need to generate a copy reloc. */
1641 if (!h->non_got_ref)
1644 /* If -z nocopyreloc was given, we won't generate them either. */
1645 if (info->nocopyreloc)
1651 if (ELIMINATE_COPY_RELOCS)
1653 struct elf_s390_link_hash_entry * eh;
1654 struct elf_s390_dyn_relocs *p;
1656 eh = (struct elf_s390_link_hash_entry *) h;
1657 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1659 s = p->sec->output_section;
1660 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1664 /* If we didn't find any dynamic relocs in read-only sections, then
1665 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1673 /* We must allocate the symbol in our .dynbss section, which will
1674 become part of the .bss section of the executable. There will be
1675 an entry for this symbol in the .dynsym section. The dynamic
1676 object will contain position independent code, so all references
1677 from the dynamic object to this symbol will go through the global
1678 offset table. The dynamic linker will use the .dynsym entry to
1679 determine the address it must put in the global offset table, so
1680 both the dynamic object and the regular object will refer to the
1681 same memory location for the variable. */
1683 htab = elf_s390_hash_table (info);
1685 /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1686 copy the initial value out of the dynamic object and into the
1687 runtime process image. */
1688 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1690 htab->srelbss->size += sizeof (Elf32_External_Rela);
1694 /* We need to figure out the alignment required for this symbol. I
1695 have no idea how ELF linkers handle this. */
1696 power_of_two = bfd_log2 (h->size);
1697 if (power_of_two > 3)
1700 /* Apply the required alignment. */
1702 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
1703 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
1705 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
1709 /* Define the symbol as being at this point in the section. */
1710 h->root.u.def.section = s;
1711 h->root.u.def.value = s->size;
1713 /* Increment the section size to make room for the symbol. */
1719 /* Allocate space in .plt, .got and associated reloc sections for
1723 allocate_dynrelocs (h, inf)
1724 struct elf_link_hash_entry *h;
1727 struct bfd_link_info *info;
1728 struct elf_s390_link_hash_table *htab;
1729 struct elf_s390_link_hash_entry *eh;
1730 struct elf_s390_dyn_relocs *p;
1732 if (h->root.type == bfd_link_hash_indirect)
1735 if (h->root.type == bfd_link_hash_warning)
1736 /* When warning symbols are created, they **replace** the "real"
1737 entry in the hash table, thus we never get to see the real
1738 symbol in a hash traversal. So look at it now. */
1739 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1741 info = (struct bfd_link_info *) inf;
1742 htab = elf_s390_hash_table (info);
1744 if (htab->elf.dynamic_sections_created
1745 && h->plt.refcount > 0
1746 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1747 || h->root.type != bfd_link_hash_undefweak))
1749 /* Make sure this symbol is output as a dynamic symbol.
1750 Undefined weak syms won't yet be marked as dynamic. */
1751 if (h->dynindx == -1
1752 && !h->forced_local)
1754 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1759 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
1761 asection *s = htab->splt;
1763 /* If this is the first .plt entry, make room for the special
1766 s->size += PLT_FIRST_ENTRY_SIZE;
1768 h->plt.offset = s->size;
1770 /* If this symbol is not defined in a regular file, and we are
1771 not generating a shared library, then set the symbol to this
1772 location in the .plt. This is required to make function
1773 pointers compare as equal between the normal executable and
1774 the shared library. */
1778 h->root.u.def.section = s;
1779 h->root.u.def.value = h->plt.offset;
1782 /* Make room for this entry. */
1783 s->size += PLT_ENTRY_SIZE;
1785 /* We also need to make an entry in the .got.plt section, which
1786 will be placed in the .got section by the linker script. */
1787 htab->sgotplt->size += GOT_ENTRY_SIZE;
1789 /* We also need to make an entry in the .rela.plt section. */
1790 htab->srelplt->size += sizeof (Elf32_External_Rela);
1794 h->plt.offset = (bfd_vma) -1;
1796 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1801 h->plt.offset = (bfd_vma) -1;
1803 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1806 /* If R_390_TLS_{IE32,GOTIE32,GOTIE12,IEENT} symbol is now local to
1807 the binary, we can optimize a bit. IE32 and GOTIE32 get converted
1808 to R_390_TLS_LE32 requiring no TLS entry. For GOTIE12 and IEENT
1809 we can save the dynamic TLS relocation. */
1810 if (h->got.refcount > 0
1813 && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE)
1815 if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT)
1816 /* For the GOTIE access without a literal pool entry the offset has
1817 to be stored somewhere. The immediate value in the instruction
1818 is not bit enough so the value is stored in the got. */
1820 h->got.offset = htab->sgot->size;
1821 htab->sgot->size += GOT_ENTRY_SIZE;
1824 h->got.offset = (bfd_vma) -1;
1826 else if (h->got.refcount > 0)
1830 int tls_type = elf_s390_hash_entry(h)->tls_type;
1832 /* Make sure this symbol is output as a dynamic symbol.
1833 Undefined weak syms won't yet be marked as dynamic. */
1834 if (h->dynindx == -1
1835 && !h->forced_local)
1837 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1842 h->got.offset = s->size;
1843 s->size += GOT_ENTRY_SIZE;
1844 /* R_390_TLS_GD32 needs 2 consecutive GOT slots. */
1845 if (tls_type == GOT_TLS_GD)
1846 s->size += GOT_ENTRY_SIZE;
1847 dyn = htab->elf.dynamic_sections_created;
1848 /* R_390_TLS_IE32 needs one dynamic relocation,
1849 R_390_TLS_GD32 needs one if local symbol and two if global. */
1850 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
1851 || tls_type >= GOT_TLS_IE)
1852 htab->srelgot->size += sizeof (Elf32_External_Rela);
1853 else if (tls_type == GOT_TLS_GD)
1854 htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
1855 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1856 || h->root.type != bfd_link_hash_undefweak)
1858 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
1859 htab->srelgot->size += sizeof (Elf32_External_Rela);
1862 h->got.offset = (bfd_vma) -1;
1864 eh = (struct elf_s390_link_hash_entry *) h;
1865 if (eh->dyn_relocs == NULL)
1868 /* In the shared -Bsymbolic case, discard space allocated for
1869 dynamic pc-relative relocs against symbols which turn out to be
1870 defined in regular objects. For the normal shared case, discard
1871 space for pc-relative relocs that have become local due to symbol
1872 visibility changes. */
1876 if (SYMBOL_REFERENCES_LOCAL (info, h))
1878 struct elf_s390_dyn_relocs **pp;
1880 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1882 p->count -= p->pc_count;
1891 /* Also discard relocs on undefined weak syms with non-default
1893 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1894 && h->root.type == bfd_link_hash_undefweak)
1895 eh->dyn_relocs = NULL;
1897 else if (ELIMINATE_COPY_RELOCS)
1899 /* For the non-shared case, discard space for relocs against
1900 symbols which turn out to need copy relocs or are not
1906 || (htab->elf.dynamic_sections_created
1907 && (h->root.type == bfd_link_hash_undefweak
1908 || h->root.type == bfd_link_hash_undefined))))
1910 /* Make sure this symbol is output as a dynamic symbol.
1911 Undefined weak syms won't yet be marked as dynamic. */
1912 if (h->dynindx == -1
1913 && !h->forced_local)
1915 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1919 /* If that succeeded, we know we'll be keeping all the
1921 if (h->dynindx != -1)
1925 eh->dyn_relocs = NULL;
1930 /* Finally, allocate space. */
1931 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1933 asection *sreloc = elf_section_data (p->sec)->sreloc;
1935 sreloc->size += p->count * sizeof (Elf32_External_Rela);
1941 /* Find any dynamic relocs that apply to read-only sections. */
1944 readonly_dynrelocs (h, inf)
1945 struct elf_link_hash_entry *h;
1948 struct elf_s390_link_hash_entry *eh;
1949 struct elf_s390_dyn_relocs *p;
1951 if (h->root.type == bfd_link_hash_warning)
1952 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1954 eh = (struct elf_s390_link_hash_entry *) h;
1955 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1957 asection *s = p->sec->output_section;
1959 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1961 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1963 info->flags |= DF_TEXTREL;
1965 /* Not an error, just cut short the traversal. */
1972 /* Set the sizes of the dynamic sections. */
1975 elf_s390_size_dynamic_sections (output_bfd, info)
1976 bfd *output_bfd ATTRIBUTE_UNUSED;
1977 struct bfd_link_info *info;
1979 struct elf_s390_link_hash_table *htab;
1985 htab = elf_s390_hash_table (info);
1986 dynobj = htab->elf.dynobj;
1990 if (htab->elf.dynamic_sections_created)
1992 /* Set the contents of the .interp section to the interpreter. */
1993 if (info->executable)
1995 s = bfd_get_section_by_name (dynobj, ".interp");
1998 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1999 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2003 /* Set up .got offsets for local syms, and space for local dynamic
2005 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2007 bfd_signed_vma *local_got;
2008 bfd_signed_vma *end_local_got;
2009 char *local_tls_type;
2010 bfd_size_type locsymcount;
2011 Elf_Internal_Shdr *symtab_hdr;
2014 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2017 for (s = ibfd->sections; s != NULL; s = s->next)
2019 struct elf_s390_dyn_relocs *p;
2021 for (p = *((struct elf_s390_dyn_relocs **)
2022 &elf_section_data (s)->local_dynrel);
2026 if (!bfd_is_abs_section (p->sec)
2027 && bfd_is_abs_section (p->sec->output_section))
2029 /* Input section has been discarded, either because
2030 it is a copy of a linkonce section or due to
2031 linker script /DISCARD/, so we'll be discarding
2034 else if (p->count != 0)
2036 srela = elf_section_data (p->sec)->sreloc;
2037 srela->size += p->count * sizeof (Elf32_External_Rela);
2038 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2039 info->flags |= DF_TEXTREL;
2044 local_got = elf_local_got_refcounts (ibfd);
2048 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2049 locsymcount = symtab_hdr->sh_info;
2050 end_local_got = local_got + locsymcount;
2051 local_tls_type = elf_s390_local_got_tls_type (ibfd);
2053 srela = htab->srelgot;
2054 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
2058 *local_got = s->size;
2059 s->size += GOT_ENTRY_SIZE;
2060 if (*local_tls_type == GOT_TLS_GD)
2061 s->size += GOT_ENTRY_SIZE;
2063 srela->size += sizeof (Elf32_External_Rela);
2066 *local_got = (bfd_vma) -1;
2070 if (htab->tls_ldm_got.refcount > 0)
2072 /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM32
2074 htab->tls_ldm_got.offset = htab->sgot->size;
2075 htab->sgot->size += 2 * GOT_ENTRY_SIZE;
2076 htab->srelgot->size += sizeof (Elf32_External_Rela);
2079 htab->tls_ldm_got.offset = -1;
2081 /* Allocate global sym .plt and .got entries, and space for global
2082 sym dynamic relocs. */
2083 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
2085 /* We now have determined the sizes of the various dynamic sections.
2086 Allocate memory for them. */
2088 for (s = dynobj->sections; s != NULL; s = s->next)
2090 if ((s->flags & SEC_LINKER_CREATED) == 0)
2095 || s == htab->sgotplt)
2097 /* Strip this section if we don't need it; see the
2100 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
2105 /* We use the reloc_count field as a counter if we need
2106 to copy relocs into the output file. */
2111 /* It's not one of our sections, so don't allocate space. */
2117 /* If we don't need this section, strip it from the
2118 output file. This is to handle .rela.bss and
2119 .rela.plt. We must create it in
2120 create_dynamic_sections, because it must be created
2121 before the linker maps input sections to output
2122 sections. The linker does that before
2123 adjust_dynamic_symbol is called, and it is that
2124 function which decides whether anything needs to go
2125 into these sections. */
2127 _bfd_strip_section_from_output (info, s);
2131 /* Allocate memory for the section contents. We use bfd_zalloc
2132 here in case unused entries are not reclaimed before the
2133 section's contents are written out. This should not happen,
2134 but this way if it does, we get a R_390_NONE reloc instead
2136 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2137 if (s->contents == NULL)
2141 if (htab->elf.dynamic_sections_created)
2143 /* Add some entries to the .dynamic section. We fill in the
2144 values later, in elf_s390_finish_dynamic_sections, but we
2145 must add the entries now so that we get the correct size for
2146 the .dynamic section. The DT_DEBUG entry is filled in by the
2147 dynamic linker and used by the debugger. */
2148 #define add_dynamic_entry(TAG, VAL) \
2149 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2151 if (info->executable)
2153 if (!add_dynamic_entry (DT_DEBUG, 0))
2157 if (htab->splt->size != 0)
2159 if (!add_dynamic_entry (DT_PLTGOT, 0)
2160 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2161 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2162 || !add_dynamic_entry (DT_JMPREL, 0))
2168 if (!add_dynamic_entry (DT_RELA, 0)
2169 || !add_dynamic_entry (DT_RELASZ, 0)
2170 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
2173 /* If any dynamic relocs apply to a read-only section,
2174 then we need a DT_TEXTREL entry. */
2175 if ((info->flags & DF_TEXTREL) == 0)
2176 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
2179 if ((info->flags & DF_TEXTREL) != 0)
2181 if (!add_dynamic_entry (DT_TEXTREL, 0))
2186 #undef add_dynamic_entry
2191 /* Return the base VMA address which should be subtracted from real addresses
2192 when resolving @dtpoff relocation.
2193 This is PT_TLS segment p_vaddr. */
2197 struct bfd_link_info *info;
2199 /* If tls_sec is NULL, we should have signalled an error already. */
2200 if (elf_hash_table (info)->tls_sec == NULL)
2202 return elf_hash_table (info)->tls_sec->vma;
2205 /* Return the relocation value for @tpoff relocation
2206 if STT_TLS virtual address is ADDRESS. */
2209 tpoff (info, address)
2210 struct bfd_link_info *info;
2213 struct elf_link_hash_table *htab = elf_hash_table (info);
2215 /* If tls_sec is NULL, we should have signalled an error already. */
2216 if (htab->tls_sec == NULL)
2218 return htab->tls_size + htab->tls_sec->vma - address;
2221 /* Complain if TLS instruction relocation is against an invalid
2225 invalid_tls_insn (input_bfd, input_section, rel)
2227 asection *input_section;
2228 Elf_Internal_Rela *rel;
2230 reloc_howto_type *howto;
2232 howto = elf_howto_table + ELF32_R_TYPE (rel->r_info);
2233 (*_bfd_error_handler)
2234 (_("%B(%A+0x%lx): invalid instruction for TLS relocation %s"),
2237 (long) rel->r_offset,
2241 /* Relocate a 390 ELF section. */
2244 elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
2245 contents, relocs, local_syms, local_sections)
2247 struct bfd_link_info *info;
2249 asection *input_section;
2251 Elf_Internal_Rela *relocs;
2252 Elf_Internal_Sym *local_syms;
2253 asection **local_sections;
2255 struct elf_s390_link_hash_table *htab;
2256 Elf_Internal_Shdr *symtab_hdr;
2257 struct elf_link_hash_entry **sym_hashes;
2258 bfd_vma *local_got_offsets;
2259 Elf_Internal_Rela *rel;
2260 Elf_Internal_Rela *relend;
2262 if (info->relocatable)
2265 htab = elf_s390_hash_table (info);
2266 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2267 sym_hashes = elf_sym_hashes (input_bfd);
2268 local_got_offsets = elf_local_got_offsets (input_bfd);
2271 relend = relocs + input_section->reloc_count;
2272 for (; rel < relend; rel++)
2274 unsigned int r_type;
2275 reloc_howto_type *howto;
2276 unsigned long r_symndx;
2277 struct elf_link_hash_entry *h;
2278 Elf_Internal_Sym *sym;
2282 bfd_boolean unresolved_reloc;
2283 bfd_reloc_status_type r;
2286 r_type = ELF32_R_TYPE (rel->r_info);
2287 if (r_type == (int) R_390_GNU_VTINHERIT
2288 || r_type == (int) R_390_GNU_VTENTRY)
2290 if (r_type >= (int) R_390_max)
2292 bfd_set_error (bfd_error_bad_value);
2296 howto = elf_howto_table + r_type;
2297 r_symndx = ELF32_R_SYM (rel->r_info);
2299 /* This is a final link. */
2303 unresolved_reloc = FALSE;
2304 if (r_symndx < symtab_hdr->sh_info)
2306 sym = local_syms + r_symndx;
2307 sec = local_sections[r_symndx];
2308 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2312 bfd_boolean warned ATTRIBUTE_UNUSED;
2314 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2315 r_symndx, symtab_hdr, sym_hashes,
2317 unresolved_reloc, warned);
2322 case R_390_GOTPLT12:
2323 case R_390_GOTPLT16:
2324 case R_390_GOTPLT20:
2325 case R_390_GOTPLT32:
2326 case R_390_GOTPLTENT:
2327 /* There are three cases for a GOTPLT relocation. 1) The
2328 relocation is against the jump slot entry of a plt that
2329 will get emitted to the output file. 2) The relocation
2330 is against the jump slot of a plt entry that has been
2331 removed. elf_s390_adjust_gotplt has created a GOT entry
2332 as replacement. 3) The relocation is against a local symbol.
2333 Cases 2) and 3) are the same as the GOT relocation code
2334 so we just have to test for case 1 and fall through for
2336 if (h != NULL && h->plt.offset != (bfd_vma) -1)
2341 Current offset - size first entry / entry size. */
2342 plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) /
2345 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2347 relocation = (plt_index + 3) * GOT_ENTRY_SIZE;
2348 unresolved_reloc = FALSE;
2350 if (r_type == R_390_GOTPLTENT)
2351 relocation += htab->sgot->output_section->vma;
2361 /* Relocation is to the entry for this symbol in the global
2363 if (htab->sgot == NULL)
2370 off = h->got.offset;
2371 dyn = htab->elf.dynamic_sections_created;
2372 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2378 || (ELF_ST_VISIBILITY (h->other)
2379 && h->root.type == bfd_link_hash_undefweak))
2381 /* This is actually a static link, or it is a
2382 -Bsymbolic link and the symbol is defined
2383 locally, or the symbol was forced to be local
2384 because of a version file. We must initialize
2385 this entry in the global offset table. Since the
2386 offset must always be a multiple of 2, we use the
2387 least significant bit to record whether we have
2388 initialized it already.
2390 When doing a dynamic link, we create a .rel.got
2391 relocation entry to initialize the value. This
2392 is done in the finish_dynamic_symbol routine. */
2397 bfd_put_32 (output_bfd, relocation,
2398 htab->sgot->contents + off);
2403 unresolved_reloc = FALSE;
2407 if (local_got_offsets == NULL)
2410 off = local_got_offsets[r_symndx];
2412 /* The offset must always be a multiple of 4. We use
2413 the least significant bit to record whether we have
2414 already generated the necessary reloc. */
2419 bfd_put_32 (output_bfd, relocation,
2420 htab->sgot->contents + off);
2425 Elf_Internal_Rela outrel;
2428 srelgot = htab->srelgot;
2429 if (srelgot == NULL)
2432 outrel.r_offset = (htab->sgot->output_section->vma
2433 + htab->sgot->output_offset
2435 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
2436 outrel.r_addend = relocation;
2437 loc = srelgot->contents;
2438 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
2439 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2442 local_got_offsets[r_symndx] |= 1;
2446 if (off >= (bfd_vma) -2)
2449 relocation = htab->sgot->output_offset + off;
2451 /* For @GOTENT the relocation is against the offset between
2452 the instruction and the symbols entry in the GOT and not
2453 between the start of the GOT and the symbols entry. We
2454 add the vma of the GOT to get the correct value. */
2455 if ( r_type == R_390_GOTENT
2456 || r_type == R_390_GOTPLTENT)
2457 relocation += htab->sgot->output_section->vma;
2461 case R_390_GOTOFF16:
2462 case R_390_GOTOFF32:
2463 /* Relocation is relative to the start of the global offset
2466 /* Note that sgot->output_offset is not involved in this
2467 calculation. We always want the start of .got. If we
2468 defined _GLOBAL_OFFSET_TABLE in a different way, as is
2469 permitted by the ABI, we might have to change this
2471 relocation -= htab->sgot->output_section->vma;
2475 case R_390_GOTPCDBL:
2476 /* Use global offset table as symbol value. */
2477 relocation = htab->sgot->output_section->vma;
2478 unresolved_reloc = FALSE;
2481 case R_390_PLT16DBL:
2482 case R_390_PLT32DBL:
2484 /* Relocation is to the entry for this symbol in the
2485 procedure linkage table. */
2487 /* Resolve a PLT32 reloc against a local symbol directly,
2488 without using the procedure linkage table. */
2492 if (h->plt.offset == (bfd_vma) -1
2493 || htab->splt == NULL)
2495 /* We didn't make a PLT entry for this symbol. This
2496 happens when statically linking PIC code, or when
2497 using -Bsymbolic. */
2501 relocation = (htab->splt->output_section->vma
2502 + htab->splt->output_offset
2504 unresolved_reloc = FALSE;
2507 case R_390_PLTOFF16:
2508 case R_390_PLTOFF32:
2509 /* Relocation is to the entry for this symbol in the
2510 procedure linkage table relative to the start of the GOT. */
2512 /* For local symbols or if we didn't make a PLT entry for
2513 this symbol resolve the symbol directly. */
2515 || h->plt.offset == (bfd_vma) -1
2516 || htab->splt == NULL)
2518 relocation -= htab->sgot->output_section->vma;
2522 relocation = (htab->splt->output_section->vma
2523 + htab->splt->output_offset
2525 - htab->sgot->output_section->vma);
2526 unresolved_reloc = FALSE;
2536 /* r_symndx will be zero only for relocs against symbols
2537 from removed linkonce sections, or sections discarded by
2540 || (input_section->flags & SEC_ALLOC) == 0)
2545 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2546 || h->root.type != bfd_link_hash_undefweak)
2547 && ((r_type != R_390_PC16
2548 && r_type != R_390_PC16DBL
2549 && r_type != R_390_PC32DBL
2550 && r_type != R_390_PC32)
2552 && !SYMBOL_REFERENCES_LOCAL (info, h))))
2553 || (ELIMINATE_COPY_RELOCS
2560 || h->root.type == bfd_link_hash_undefweak
2561 || h->root.type == bfd_link_hash_undefined)))
2563 Elf_Internal_Rela outrel;
2564 bfd_boolean skip, relocate;
2568 /* When generating a shared object, these relocations
2569 are copied into the output file to be resolved at run
2576 _bfd_elf_section_offset (output_bfd, info, input_section,
2578 if (outrel.r_offset == (bfd_vma) -1)
2580 else if (outrel.r_offset == (bfd_vma) -2)
2581 skip = TRUE, relocate = TRUE;
2582 outrel.r_offset += (input_section->output_section->vma
2583 + input_section->output_offset);
2586 memset (&outrel, 0, sizeof outrel);
2589 && (r_type == R_390_PC16
2590 || r_type == R_390_PC16DBL
2591 || r_type == R_390_PC32DBL
2592 || r_type == R_390_PC32
2595 || !h->def_regular))
2597 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2598 outrel.r_addend = rel->r_addend;
2602 /* This symbol is local, or marked to become local. */
2603 outrel.r_addend = relocation + rel->r_addend;
2604 if (r_type == R_390_32)
2607 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
2613 if (bfd_is_abs_section (sec))
2615 else if (sec == NULL || sec->owner == NULL)
2617 bfd_set_error(bfd_error_bad_value);
2624 osec = sec->output_section;
2625 sindx = elf_section_data (osec)->dynindx;
2626 BFD_ASSERT (sindx > 0);
2628 /* We are turning this relocation into one
2629 against a section symbol, so subtract out
2630 the output section's address but not the
2631 offset of the input section in the output
2634 outrel.r_addend -= osec->vma;
2636 outrel.r_info = ELF32_R_INFO (sindx, r_type);
2640 sreloc = elf_section_data (input_section)->sreloc;
2644 loc = sreloc->contents;
2645 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
2646 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2648 /* If this reloc is against an external symbol, we do
2649 not want to fiddle with the addend. Otherwise, we
2650 need to include the symbol value so that it becomes
2651 an addend for the dynamic reloc. */
2657 /* Relocations for tls literal pool entries. */
2658 case R_390_TLS_IE32:
2661 Elf_Internal_Rela outrel;
2665 outrel.r_offset = rel->r_offset
2666 + input_section->output_section->vma
2667 + input_section->output_offset;
2668 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
2669 sreloc = elf_section_data (input_section)->sreloc;
2672 loc = sreloc->contents;
2673 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
2674 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2678 case R_390_TLS_GD32:
2679 case R_390_TLS_GOTIE32:
2680 r_type = elf_s390_tls_transition (info, r_type, h == NULL);
2681 tls_type = GOT_UNKNOWN;
2682 if (h == NULL && local_got_offsets)
2683 tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
2686 tls_type = elf_s390_hash_entry(h)->tls_type;
2687 if (!info->shared && h->dynindx == -1 && tls_type >= GOT_TLS_IE)
2688 r_type = R_390_TLS_LE32;
2690 if (r_type == R_390_TLS_GD32 && tls_type >= GOT_TLS_IE)
2691 r_type = R_390_TLS_IE32;
2693 if (r_type == R_390_TLS_LE32)
2695 /* This relocation gets optimized away by the local exec
2696 access optimization. */
2697 BFD_ASSERT (! unresolved_reloc);
2698 bfd_put_32 (output_bfd, -tpoff (info, relocation),
2699 contents + rel->r_offset);
2703 if (htab->sgot == NULL)
2707 off = h->got.offset;
2710 if (local_got_offsets == NULL)
2713 off = local_got_offsets[r_symndx];
2722 Elf_Internal_Rela outrel;
2726 if (htab->srelgot == NULL)
2729 outrel.r_offset = (htab->sgot->output_section->vma
2730 + htab->sgot->output_offset + off);
2732 indx = h && h->dynindx != -1 ? h->dynindx : 0;
2733 if (r_type == R_390_TLS_GD32)
2734 dr_type = R_390_TLS_DTPMOD;
2736 dr_type = R_390_TLS_TPOFF;
2737 if (dr_type == R_390_TLS_TPOFF && indx == 0)
2738 outrel.r_addend = relocation - dtpoff_base (info);
2740 outrel.r_addend = 0;
2741 outrel.r_info = ELF32_R_INFO (indx, dr_type);
2742 loc = htab->srelgot->contents;
2743 loc += htab->srelgot->reloc_count++
2744 * sizeof (Elf32_External_Rela);
2745 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2747 if (r_type == R_390_TLS_GD32)
2751 BFD_ASSERT (! unresolved_reloc);
2752 bfd_put_32 (output_bfd,
2753 relocation - dtpoff_base (info),
2754 htab->sgot->contents + off + GOT_ENTRY_SIZE);
2758 outrel.r_info = ELF32_R_INFO (indx, R_390_TLS_DTPOFF);
2759 outrel.r_offset += GOT_ENTRY_SIZE;
2760 outrel.r_addend = 0;
2761 htab->srelgot->reloc_count++;
2762 loc += sizeof (Elf32_External_Rela);
2763 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2770 local_got_offsets[r_symndx] |= 1;
2773 if (off >= (bfd_vma) -2)
2775 if (r_type == ELF32_R_TYPE (rel->r_info))
2777 relocation = htab->sgot->output_offset + off;
2778 if (r_type == R_390_TLS_IE32 || r_type == R_390_TLS_IEENT)
2779 relocation += htab->sgot->output_section->vma;
2780 unresolved_reloc = FALSE;
2784 bfd_put_32 (output_bfd, htab->sgot->output_offset + off,
2785 contents + rel->r_offset);
2790 case R_390_TLS_GOTIE12:
2791 case R_390_TLS_GOTIE20:
2792 case R_390_TLS_IEENT:
2795 if (local_got_offsets == NULL)
2797 off = local_got_offsets[r_symndx];
2799 goto emit_tls_relocs;
2803 off = h->got.offset;
2804 tls_type = elf_s390_hash_entry(h)->tls_type;
2805 if (info->shared || h->dynindx != -1 || tls_type < GOT_TLS_IE)
2806 goto emit_tls_relocs;
2809 if (htab->sgot == NULL)
2812 BFD_ASSERT (! unresolved_reloc);
2813 bfd_put_32 (output_bfd, -tpoff (info, relocation),
2814 htab->sgot->contents + off);
2815 relocation = htab->sgot->output_offset + off;
2816 if (r_type == R_390_TLS_IEENT)
2817 relocation += htab->sgot->output_section->vma;
2818 unresolved_reloc = FALSE;
2821 case R_390_TLS_LDM32:
2823 /* The literal pool entry this relocation refers to gets ignored
2824 by the optimized code of the local exec model. Do nothing
2825 and the value will turn out zero. */
2828 if (htab->sgot == NULL)
2831 off = htab->tls_ldm_got.offset;
2836 Elf_Internal_Rela outrel;
2839 if (htab->srelgot == NULL)
2842 outrel.r_offset = (htab->sgot->output_section->vma
2843 + htab->sgot->output_offset + off);
2845 bfd_put_32 (output_bfd, 0,
2846 htab->sgot->contents + off + GOT_ENTRY_SIZE);
2847 outrel.r_info = ELF32_R_INFO (0, R_390_TLS_DTPMOD);
2848 outrel.r_addend = 0;
2849 loc = htab->srelgot->contents;
2850 loc += htab->srelgot->reloc_count++
2851 * sizeof (Elf32_External_Rela);
2852 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2853 htab->tls_ldm_got.offset |= 1;
2855 relocation = htab->sgot->output_offset + off;
2856 unresolved_reloc = FALSE;
2859 case R_390_TLS_LE32:
2862 /* Linking a shared library with non-fpic code requires
2863 a R_390_TLS_TPOFF relocation. */
2864 Elf_Internal_Rela outrel;
2869 outrel.r_offset = rel->r_offset
2870 + input_section->output_section->vma
2871 + input_section->output_offset;
2872 if (h != NULL && h->dynindx != -1)
2876 outrel.r_info = ELF32_R_INFO (indx, R_390_TLS_TPOFF);
2878 outrel.r_addend = relocation - dtpoff_base (info);
2880 outrel.r_addend = 0;
2881 sreloc = elf_section_data (input_section)->sreloc;
2884 loc = sreloc->contents;
2885 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
2886 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
2890 BFD_ASSERT (! unresolved_reloc);
2891 bfd_put_32 (output_bfd, -tpoff (info, relocation),
2892 contents + rel->r_offset);
2896 case R_390_TLS_LDO32:
2897 if (info->shared || (input_section->flags & SEC_CODE) == 0)
2898 relocation -= dtpoff_base (info);
2900 /* When converting LDO to LE, we must negate. */
2901 relocation = -tpoff (info, relocation);
2904 /* Relocations for tls instructions. */
2905 case R_390_TLS_LOAD:
2906 case R_390_TLS_GDCALL:
2907 case R_390_TLS_LDCALL:
2908 tls_type = GOT_UNKNOWN;
2909 if (h == NULL && local_got_offsets)
2910 tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
2912 tls_type = elf_s390_hash_entry(h)->tls_type;
2914 if (tls_type == GOT_TLS_GD)
2917 if (r_type == R_390_TLS_LOAD)
2919 if (!info->shared && (h == NULL || h->dynindx == -1))
2921 /* IE->LE transition. Four valid cases:
2922 l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0
2923 l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0
2924 l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0
2925 l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */
2926 unsigned int insn, ry;
2928 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2930 if ((insn & 0xff00f000) == 0x58000000)
2931 /* l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0 */
2932 ry = (insn & 0x000f0000);
2933 else if ((insn & 0xff0f0000) == 0x58000000)
2934 /* l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0 */
2935 ry = (insn & 0x0000f000) << 4;
2936 else if ((insn & 0xff00f000) == 0x5800c000)
2937 /* l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0 */
2938 ry = (insn & 0x000f0000);
2939 else if ((insn & 0xff0f0000) == 0x580c0000)
2940 /* l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */
2941 ry = (insn & 0x0000f000) << 4;
2943 invalid_tls_insn (input_bfd, input_section, rel);
2944 insn = 0x18000700 | (insn & 0x00f00000) | ry;
2945 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
2948 else if (r_type == R_390_TLS_GDCALL)
2952 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2953 if ((insn & 0xff000fff) != 0x4d000000)
2954 invalid_tls_insn (input_bfd, input_section, rel);
2955 if (!info->shared && (h == NULL || h->dynindx == -1))
2956 /* GD->LE transition.
2957 bas %r14,0(%rx,%r13) -> bc 0,0 */
2960 /* GD->IE transition.
2961 bas %r14,0(%rx,%r13) -> l %r2,0(%r2,%r12) */
2963 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
2965 else if (r_type == R_390_TLS_LDCALL)
2971 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2972 if ((insn & 0xff000fff) != 0x4d000000)
2973 invalid_tls_insn (input_bfd, input_section, rel);
2974 /* LD->LE transition.
2975 bas %r14,0(%rx,%r13) -> bc 0,0 */
2977 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
2986 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2987 because such sections are not SEC_ALLOC and thus ld.so will
2988 not process them. */
2989 if (unresolved_reloc
2990 && !((input_section->flags & SEC_DEBUGGING) != 0
2992 (*_bfd_error_handler)
2993 (_("%B(%A+0x%lx): unresolvable relocation against symbol `%s'"),
2996 (long) rel->r_offset,
2997 h->root.root.string);
2999 if (r_type == R_390_20
3000 || r_type == R_390_GOT20
3001 || r_type == R_390_GOTPLT20
3002 || r_type == R_390_TLS_GOTIE20)
3004 relocation += rel->r_addend;
3005 relocation = (relocation&0xfff) << 8 | (relocation&0xff000) >> 12;
3006 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3007 contents, rel->r_offset,
3011 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3012 contents, rel->r_offset,
3013 relocation, rel->r_addend);
3015 if (r != bfd_reloc_ok)
3020 name = h->root.root.string;
3023 name = bfd_elf_string_from_elf_section (input_bfd,
3024 symtab_hdr->sh_link,
3029 name = bfd_section_name (input_bfd, sec);
3032 if (r == bfd_reloc_overflow)
3035 if (! ((*info->callbacks->reloc_overflow)
3036 (info, (h ? &h->root : NULL), name, howto->name,
3037 (bfd_vma) 0, input_bfd, input_section,
3043 (*_bfd_error_handler)
3044 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3045 input_bfd, input_section,
3046 (long) rel->r_offset, name, (int) r);
3055 /* Finish up dynamic symbol handling. We set the contents of various
3056 dynamic sections here. */
3059 elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym)
3061 struct bfd_link_info *info;
3062 struct elf_link_hash_entry *h;
3063 Elf_Internal_Sym *sym;
3065 struct elf_s390_link_hash_table *htab;
3067 htab = elf_s390_hash_table (info);
3069 if (h->plt.offset != (bfd_vma) -1)
3073 Elf_Internal_Rela rela;
3075 bfd_vma relative_offset;
3077 /* This symbol has an entry in the procedure linkage table. Set
3079 if (h->dynindx == -1
3080 || htab->splt == NULL
3081 || htab->sgotplt == NULL
3082 || htab->srelplt == NULL)
3086 Current offset - size first entry / entry size. */
3087 plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
3089 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
3091 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
3093 /* S390 uses halfwords for relative branch calc! */
3094 relative_offset = - ((PLT_FIRST_ENTRY_SIZE +
3095 (PLT_ENTRY_SIZE * plt_index) + 18) / 2);
3096 /* If offset is > 32768, branch to a previous branch
3097 390 can only handle +-64 K jumps. */
3098 if ( -32768 > (int) relative_offset )
3100 = -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2);
3102 /* Fill in the entry in the procedure linkage table. */
3105 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0,
3106 htab->splt->contents + h->plt.offset);
3107 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1,
3108 htab->splt->contents + h->plt.offset + 4);
3109 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2,
3110 htab->splt->contents + h->plt.offset + 8);
3111 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3,
3112 htab->splt->contents + h->plt.offset + 12);
3113 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4,
3114 htab->splt->contents + h->plt.offset + 16);
3115 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
3116 htab->splt->contents + h->plt.offset + 20);
3117 bfd_put_32 (output_bfd,
3118 (htab->sgotplt->output_section->vma
3119 + htab->sgotplt->output_offset
3121 htab->splt->contents + h->plt.offset + 24);
3123 else if (got_offset < 4096)
3125 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD0 + got_offset,
3126 htab->splt->contents + h->plt.offset);
3127 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD1,
3128 htab->splt->contents + h->plt.offset + 4);
3129 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD2,
3130 htab->splt->contents + h->plt.offset + 8);
3131 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD3,
3132 htab->splt->contents + h->plt.offset + 12);
3133 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD4,
3134 htab->splt->contents + h->plt.offset + 16);
3135 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
3136 htab->splt->contents + h->plt.offset + 20);
3137 bfd_put_32 (output_bfd, (bfd_vma) 0,
3138 htab->splt->contents + h->plt.offset + 24);
3140 else if (got_offset < 32768)
3142 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD0 + got_offset,
3143 htab->splt->contents + h->plt.offset);
3144 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD1,
3145 htab->splt->contents + h->plt.offset + 4);
3146 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD2,
3147 htab->splt->contents + h->plt.offset + 8);
3148 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD3,
3149 htab->splt->contents + h->plt.offset + 12);
3150 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD4,
3151 htab->splt->contents + h->plt.offset + 16);
3152 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
3153 htab->splt->contents + h->plt.offset + 20);
3154 bfd_put_32 (output_bfd, (bfd_vma) 0,
3155 htab->splt->contents + h->plt.offset + 24);
3159 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD0,
3160 htab->splt->contents + h->plt.offset);
3161 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD1,
3162 htab->splt->contents + h->plt.offset + 4);
3163 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD2,
3164 htab->splt->contents + h->plt.offset + 8);
3165 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD3,
3166 htab->splt->contents + h->plt.offset + 12);
3167 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD4,
3168 htab->splt->contents + h->plt.offset + 16);
3169 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16),
3170 htab->splt->contents + h->plt.offset + 20);
3171 bfd_put_32 (output_bfd, got_offset,
3172 htab->splt->contents + h->plt.offset + 24);
3174 /* Insert offset into reloc. table here. */
3175 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
3176 htab->splt->contents + h->plt.offset + 28);
3178 /* Fill in the entry in the global offset table.
3179 Points to instruction after GOT offset. */
3180 bfd_put_32 (output_bfd,
3181 (htab->splt->output_section->vma
3182 + htab->splt->output_offset
3185 htab->sgotplt->contents + got_offset);
3187 /* Fill in the entry in the .rela.plt section. */
3188 rela.r_offset = (htab->sgotplt->output_section->vma
3189 + htab->sgotplt->output_offset
3191 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT);
3193 loc = htab->srelplt->contents + plt_index * sizeof (Elf32_External_Rela);
3194 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3196 if (!h->def_regular)
3198 /* Mark the symbol as undefined, rather than as defined in
3199 the .plt section. Leave the value alone. This is a clue
3200 for the dynamic linker, to make function pointer
3201 comparisons work between an application and shared
3203 sym->st_shndx = SHN_UNDEF;
3207 if (h->got.offset != (bfd_vma) -1
3208 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD
3209 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE
3210 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT)
3212 Elf_Internal_Rela rela;
3215 /* This symbol has an entry in the global offset table. Set it
3218 if (htab->sgot == NULL || htab->srelgot == NULL)
3221 rela.r_offset = (htab->sgot->output_section->vma
3222 + htab->sgot->output_offset
3223 + (h->got.offset &~ (bfd_vma) 1));
3225 /* If this is a static link, or it is a -Bsymbolic link and the
3226 symbol is defined locally or was forced to be local because
3227 of a version file, we just want to emit a RELATIVE reloc.
3228 The entry in the global offset table will already have been
3229 initialized in the relocate_section function. */
3236 BFD_ASSERT((h->got.offset & 1) != 0);
3237 rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
3238 rela.r_addend = (h->root.u.def.value
3239 + h->root.u.def.section->output_section->vma
3240 + h->root.u.def.section->output_offset);
3244 BFD_ASSERT((h->got.offset & 1) == 0);
3245 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.offset);
3246 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_GLOB_DAT);
3250 loc = htab->srelgot->contents;
3251 loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
3252 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3257 Elf_Internal_Rela rela;
3260 /* This symbols needs a copy reloc. Set it up. */
3262 if (h->dynindx == -1
3263 || (h->root.type != bfd_link_hash_defined
3264 && h->root.type != bfd_link_hash_defweak)
3265 || htab->srelbss == NULL)
3268 rela.r_offset = (h->root.u.def.value
3269 + h->root.u.def.section->output_section->vma
3270 + h->root.u.def.section->output_offset);
3271 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_COPY);
3273 loc = htab->srelbss->contents;
3274 loc += htab->srelbss->reloc_count++ * sizeof (Elf32_External_Rela);
3275 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3278 /* Mark some specially defined symbols as absolute. */
3279 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3280 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
3281 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3282 sym->st_shndx = SHN_ABS;
3287 /* Used to decide how to sort relocs in an optimal manner for the
3288 dynamic linker, before writing them out. */
3290 static enum elf_reloc_type_class
3291 elf_s390_reloc_type_class (rela)
3292 const Elf_Internal_Rela *rela;
3294 switch ((int) ELF32_R_TYPE (rela->r_info))
3296 case R_390_RELATIVE:
3297 return reloc_class_relative;
3298 case R_390_JMP_SLOT:
3299 return reloc_class_plt;
3301 return reloc_class_copy;
3303 return reloc_class_normal;
3307 /* Finish up the dynamic sections. */
3310 elf_s390_finish_dynamic_sections (output_bfd, info)
3312 struct bfd_link_info *info;
3314 struct elf_s390_link_hash_table *htab;
3318 htab = elf_s390_hash_table (info);
3319 dynobj = htab->elf.dynobj;
3320 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3322 if (htab->elf.dynamic_sections_created)
3324 Elf32_External_Dyn *dyncon, *dynconend;
3326 if (sdyn == NULL || htab->sgot == NULL)
3329 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3330 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3331 for (; dyncon < dynconend; dyncon++)
3333 Elf_Internal_Dyn dyn;
3336 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3344 dyn.d_un.d_ptr = htab->sgot->output_section->vma;
3348 dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
3352 s = htab->srelplt->output_section;
3353 dyn.d_un.d_val = s->size;
3357 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3360 /* Fill in the special first entry in the procedure linkage table. */
3361 if (htab->splt && htab->splt->size > 0)
3363 memset (htab->splt->contents, 0, PLT_FIRST_ENTRY_SIZE);
3366 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD0,
3367 htab->splt->contents );
3368 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD1,
3369 htab->splt->contents +4 );
3370 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD2,
3371 htab->splt->contents +8 );
3372 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD3,
3373 htab->splt->contents +12 );
3374 bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD4,
3375 htab->splt->contents +16 );
3379 bfd_put_32 (output_bfd, (bfd_vma)PLT_FIRST_ENTRY_WORD0,
3380 htab->splt->contents );
3381 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1,
3382 htab->splt->contents +4 );
3383 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD2,
3384 htab->splt->contents +8 );
3385 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3,
3386 htab->splt->contents +12 );
3387 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4,
3388 htab->splt->contents +16 );
3389 bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5,
3390 htab->splt->contents +20 );
3391 bfd_put_32 (output_bfd,
3392 htab->sgotplt->output_section->vma
3393 + htab->sgotplt->output_offset,
3394 htab->splt->contents + 24);
3396 elf_section_data (htab->splt->output_section)
3397 ->this_hdr.sh_entsize = 4;
3404 /* Fill in the first three entries in the global offset table. */
3405 if (htab->sgotplt->size > 0)
3407 bfd_put_32 (output_bfd,
3408 (sdyn == NULL ? (bfd_vma) 0
3409 : sdyn->output_section->vma + sdyn->output_offset),
3410 htab->sgotplt->contents);
3411 /* One entry for shared object struct ptr. */
3412 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 4);
3413 /* One entry for _dl_runtime_resolve. */
3414 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8);
3417 elf_section_data (htab->sgotplt->output_section)
3418 ->this_hdr.sh_entsize = 4;
3424 elf_s390_grok_prstatus (abfd, note)
3426 Elf_Internal_Note * note;
3431 switch (note->descsz)
3436 case 224: /* S/390 Linux. */
3438 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
3441 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
3449 /* Make a ".reg/999" section. */
3450 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
3451 size, note->descpos + offset);
3454 /* Return address for Ith PLT stub in section PLT, for relocation REL
3455 or (bfd_vma) -1 if it should not be included. */
3458 elf_s390_plt_sym_val (bfd_vma i, const asection *plt,
3459 const arelent *rel ATTRIBUTE_UNUSED)
3461 return plt->vma + PLT_FIRST_ENTRY_SIZE + i * PLT_ENTRY_SIZE;
3465 #define TARGET_BIG_SYM bfd_elf32_s390_vec
3466 #define TARGET_BIG_NAME "elf32-s390"
3467 #define ELF_ARCH bfd_arch_s390
3468 #define ELF_MACHINE_CODE EM_S390
3469 #define ELF_MACHINE_ALT1 EM_S390_OLD
3470 #define ELF_MAXPAGESIZE 0x1000
3472 #define elf_backend_can_gc_sections 1
3473 #define elf_backend_can_refcount 1
3474 #define elf_backend_want_got_plt 1
3475 #define elf_backend_plt_readonly 1
3476 #define elf_backend_want_plt_sym 0
3477 #define elf_backend_got_header_size 12
3478 #define elf_backend_rela_normal 1
3480 #define elf_info_to_howto elf_s390_info_to_howto
3482 #define bfd_elf32_bfd_is_local_label_name elf_s390_is_local_label_name
3483 #define bfd_elf32_bfd_link_hash_table_create elf_s390_link_hash_table_create
3484 #define bfd_elf32_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
3486 #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
3487 #define elf_backend_check_relocs elf_s390_check_relocs
3488 #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
3489 #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
3490 #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
3491 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
3492 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
3493 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
3494 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3495 #define elf_backend_relocate_section elf_s390_relocate_section
3496 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
3497 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3498 #define elf_backend_grok_prstatus elf_s390_grok_prstatus
3499 #define elf_backend_plt_sym_val elf_s390_plt_sym_val
3501 #define bfd_elf32_mkobject elf_s390_mkobject
3502 #define elf_backend_object_p elf_s390_object_p
3504 #include "elf32-target.h"