1 /* IBM S/390-specific support for 32-bit ELF
2 Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Carl B. Pedersen and Martin Schwidefsky.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 static reloc_howto_type
*elf_s390_reloc_type_lookup
29 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
30 static void elf_s390_info_to_howto
31 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
32 static bfd_boolean elf_s390_is_local_label_name
33 PARAMS ((bfd
*, const char *));
34 static struct bfd_hash_entry
*link_hash_newfunc
35 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
36 static struct bfd_link_hash_table
*elf_s390_link_hash_table_create
38 static bfd_boolean create_got_section
39 PARAMS((bfd
*, struct bfd_link_info
*));
40 static bfd_boolean elf_s390_create_dynamic_sections
41 PARAMS((bfd
*, struct bfd_link_info
*));
42 static void elf_s390_copy_indirect_symbol
43 PARAMS ((struct elf_backend_data
*, struct elf_link_hash_entry
*,
44 struct elf_link_hash_entry
*));
45 static bfd_boolean elf_s390_check_relocs
46 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
47 const Elf_Internal_Rela
*));
48 static asection
*elf_s390_gc_mark_hook
49 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
50 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
51 static bfd_boolean elf_s390_gc_sweep_hook
52 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
53 const Elf_Internal_Rela
*));
54 struct elf_s390_link_hash_entry
;
55 static void elf_s390_adjust_gotplt
56 PARAMS ((struct elf_s390_link_hash_entry
*));
57 static bfd_boolean elf_s390_adjust_dynamic_symbol
58 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
59 static bfd_boolean allocate_dynrelocs
60 PARAMS ((struct elf_link_hash_entry
*, PTR
));
61 static bfd_boolean readonly_dynrelocs
62 PARAMS ((struct elf_link_hash_entry
*, PTR
));
63 static bfd_boolean elf_s390_size_dynamic_sections
64 PARAMS ((bfd
*, struct bfd_link_info
*));
65 static bfd_boolean elf_s390_relocate_section
66 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
67 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
68 static bfd_boolean elf_s390_finish_dynamic_symbol
69 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
71 static enum elf_reloc_type_class elf_s390_reloc_type_class
72 PARAMS ((const Elf_Internal_Rela
*));
73 static bfd_boolean elf_s390_finish_dynamic_sections
74 PARAMS ((bfd
*, struct bfd_link_info
*));
75 static bfd_boolean elf_s390_mkobject
77 static bfd_boolean elf_s390_object_p
79 static bfd_boolean elf_s390_grok_prstatus
80 PARAMS ((bfd
*, Elf_Internal_Note
*));
81 static int elf_s390_tls_transition
82 PARAMS ((struct bfd_link_info
*, int, int));
83 static bfd_reloc_status_type s390_tls_reloc
84 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
85 static bfd_vma dtpoff_base
86 PARAMS ((struct bfd_link_info
*));
88 PARAMS ((struct bfd_link_info
*, bfd_vma
));
89 static void invalid_tls_insn
90 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*));
94 /* The relocation "howto" table. */
96 static reloc_howto_type elf_howto_table
[] =
98 HOWTO (R_390_NONE
, /* type */
100 0, /* size (0 = byte, 1 = short, 2 = long) */
102 FALSE
, /* pc_relative */
104 complain_overflow_dont
, /* complain_on_overflow */
105 bfd_elf_generic_reloc
, /* special_function */
106 "R_390_NONE", /* name */
107 FALSE
, /* partial_inplace */
110 FALSE
), /* pcrel_offset */
112 HOWTO(R_390_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
113 bfd_elf_generic_reloc
, "R_390_8", FALSE
, 0,0x000000ff, FALSE
),
114 HOWTO(R_390_12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
115 bfd_elf_generic_reloc
, "R_390_12", FALSE
, 0,0x00000fff, FALSE
),
116 HOWTO(R_390_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_390_16", FALSE
, 0,0x0000ffff, FALSE
),
118 HOWTO(R_390_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
119 bfd_elf_generic_reloc
, "R_390_32", FALSE
, 0,0xffffffff, FALSE
),
120 HOWTO(R_390_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
121 bfd_elf_generic_reloc
, "R_390_PC32", FALSE
, 0,0xffffffff, TRUE
),
122 HOWTO(R_390_GOT12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
123 bfd_elf_generic_reloc
, "R_390_GOT12", FALSE
, 0,0x00000fff, FALSE
),
124 HOWTO(R_390_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
125 bfd_elf_generic_reloc
, "R_390_GOT32", FALSE
, 0,0xffffffff, FALSE
),
126 HOWTO(R_390_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_390_PLT32", FALSE
, 0,0xffffffff, TRUE
),
128 HOWTO(R_390_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
129 bfd_elf_generic_reloc
, "R_390_COPY", FALSE
, 0,0xffffffff, FALSE
),
130 HOWTO(R_390_GLOB_DAT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
131 bfd_elf_generic_reloc
, "R_390_GLOB_DAT", FALSE
, 0,0xffffffff, FALSE
),
132 HOWTO(R_390_JMP_SLOT
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
133 bfd_elf_generic_reloc
, "R_390_JMP_SLOT", FALSE
, 0,0xffffffff, FALSE
),
134 HOWTO(R_390_RELATIVE
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
135 bfd_elf_generic_reloc
, "R_390_RELATIVE", FALSE
, 0,0xffffffff, FALSE
),
136 HOWTO(R_390_GOTOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
137 bfd_elf_generic_reloc
, "R_390_GOTOFF32", FALSE
, 0,0xffffffff, FALSE
),
138 HOWTO(R_390_GOTPC
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
139 bfd_elf_generic_reloc
, "R_390_GOTPC", FALSE
, 0,0xffffffff, TRUE
),
140 HOWTO(R_390_GOT16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
141 bfd_elf_generic_reloc
, "R_390_GOT16", FALSE
, 0,0x0000ffff, FALSE
),
142 HOWTO(R_390_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
143 bfd_elf_generic_reloc
, "R_390_PC16", FALSE
, 0,0x0000ffff, TRUE
),
144 HOWTO(R_390_PC16DBL
, 1, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
145 bfd_elf_generic_reloc
, "R_390_PC16DBL", FALSE
, 0,0x0000ffff, TRUE
),
146 HOWTO(R_390_PLT16DBL
, 1, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
147 bfd_elf_generic_reloc
, "R_390_PLT16DBL", FALSE
, 0,0x0000ffff, TRUE
),
148 HOWTO(R_390_PC32DBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
149 bfd_elf_generic_reloc
, "R_390_PC32DBL", FALSE
, 0,0xffffffff, TRUE
),
150 HOWTO(R_390_PLT32DBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
151 bfd_elf_generic_reloc
, "R_390_PLT32DBL", FALSE
, 0,0xffffffff, TRUE
),
152 HOWTO(R_390_GOTPCDBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
153 bfd_elf_generic_reloc
, "R_390_GOTPCDBL", FALSE
, 0,0xffffffff, TRUE
),
154 EMPTY_HOWTO (R_390_64
), /* Empty entry for R_390_64. */
155 EMPTY_HOWTO (R_390_PC64
), /* Empty entry for R_390_PC64. */
156 EMPTY_HOWTO (R_390_GOT64
), /* Empty entry for R_390_GOT64. */
157 EMPTY_HOWTO (R_390_PLT64
), /* Empty entry for R_390_PLT64. */
158 HOWTO(R_390_GOTENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
159 bfd_elf_generic_reloc
, "R_390_GOTENT", FALSE
, 0,0xffffffff, TRUE
),
160 HOWTO(R_390_GOTOFF16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
161 bfd_elf_generic_reloc
, "R_390_GOTOFF16", FALSE
, 0,0x0000ffff, FALSE
),
162 EMPTY_HOWTO (R_390_GOTOFF64
), /* Empty entry for R_390_GOTOFF64. */
163 HOWTO(R_390_GOTPLT12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
164 bfd_elf_generic_reloc
, "R_390_GOTPLT12", FALSE
, 0,0x00000fff, FALSE
),
165 HOWTO(R_390_GOTPLT16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
166 bfd_elf_generic_reloc
, "R_390_GOTPLT16", FALSE
, 0,0x0000ffff, FALSE
),
167 HOWTO(R_390_GOTPLT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
168 bfd_elf_generic_reloc
, "R_390_GOTPLT32", FALSE
, 0,0xffffffff, FALSE
),
169 EMPTY_HOWTO (R_390_GOTPLT64
), /* Empty entry for R_390_GOTPLT64. */
170 HOWTO(R_390_GOTPLTENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
171 bfd_elf_generic_reloc
, "R_390_GOTPLTENT",FALSE
, 0,0xffffffff, TRUE
),
172 HOWTO(R_390_PLTOFF16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
173 bfd_elf_generic_reloc
, "R_390_PLTOFF16", FALSE
, 0,0x0000ffff, FALSE
),
174 HOWTO(R_390_PLTOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
175 bfd_elf_generic_reloc
, "R_390_PLTOFF32", FALSE
, 0,0xffffffff, FALSE
),
176 EMPTY_HOWTO (R_390_PLTOFF64
), /* Empty entry for R_390_PLTOFF64. */
177 HOWTO(R_390_TLS_LOAD
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
178 s390_tls_reloc
, "R_390_TLS_LOAD", FALSE
, 0, 0, FALSE
),
179 HOWTO(R_390_TLS_GDCALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
180 s390_tls_reloc
, "R_390_TLS_GDCALL", FALSE
, 0, 0, FALSE
),
181 HOWTO(R_390_TLS_LDCALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
182 s390_tls_reloc
, "R_390_TLS_LDCALL", FALSE
, 0, 0, FALSE
),
183 HOWTO(R_390_TLS_GD32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
184 bfd_elf_generic_reloc
, "R_390_TLS_GD32", FALSE
, 0, 0xffffffff, FALSE
),
185 EMPTY_HOWTO (R_390_TLS_GD64
), /* Empty entry for R_390_TLS_GD64. */
186 HOWTO(R_390_TLS_GOTIE12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
187 bfd_elf_generic_reloc
, "R_390_TLS_GOTIE12", FALSE
, 0, 0x00000fff, FALSE
),
188 HOWTO(R_390_TLS_GOTIE32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
189 bfd_elf_generic_reloc
, "R_390_TLS_GOTIE32", FALSE
, 0, 0xffffffff, FALSE
),
190 EMPTY_HOWTO (R_390_TLS_GOTIE64
), /* Empty entry for R_390_TLS_GOTIE64. */
191 HOWTO(R_390_TLS_LDM32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
192 bfd_elf_generic_reloc
, "R_390_TLS_LDM32", FALSE
, 0, 0xffffffff, FALSE
),
193 EMPTY_HOWTO (R_390_TLS_LDM64
), /* Empty entry for R_390_TLS_LDM64. */
194 HOWTO(R_390_TLS_IE32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
195 bfd_elf_generic_reloc
, "R_390_TLS_IE32", FALSE
, 0, 0xffffffff, FALSE
),
196 EMPTY_HOWTO (R_390_TLS_IE64
), /* Empty entry for R_390_TLS_IE64. */
197 HOWTO(R_390_TLS_IEENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
198 bfd_elf_generic_reloc
, "R_390_TLS_IEENT", FALSE
, 0, 0xffffffff, TRUE
),
199 HOWTO(R_390_TLS_LE32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
200 bfd_elf_generic_reloc
, "R_390_TLS_LE32", FALSE
, 0, 0xffffffff, FALSE
),
201 EMPTY_HOWTO (R_390_TLS_LE64
), /* Empty entry for R_390_TLS_LE64. */
202 HOWTO(R_390_TLS_LDO32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
203 bfd_elf_generic_reloc
, "R_390_TLS_LDO32", FALSE
, 0, 0xffffffff, FALSE
),
204 EMPTY_HOWTO (R_390_TLS_LDO64
), /* Empty entry for R_390_TLS_LDO64. */
205 HOWTO(R_390_TLS_DTPMOD
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
206 bfd_elf_generic_reloc
, "R_390_TLS_DTPMOD", FALSE
, 0, 0xffffffff, FALSE
),
207 HOWTO(R_390_TLS_DTPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
208 bfd_elf_generic_reloc
, "R_390_TLS_DTPOFF", FALSE
, 0, 0xffffffff, FALSE
),
209 HOWTO(R_390_TLS_TPOFF
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
210 bfd_elf_generic_reloc
, "R_390_TLS_TPOFF", FALSE
, 0, 0xffffffff, FALSE
),
213 /* GNU extension to record C++ vtable hierarchy. */
214 static reloc_howto_type elf32_s390_vtinherit_howto
=
215 HOWTO (R_390_GNU_VTINHERIT
, 0,2,0,FALSE
,0,complain_overflow_dont
, NULL
, "R_390_GNU_VTINHERIT", FALSE
,0, 0, FALSE
);
216 static reloc_howto_type elf32_s390_vtentry_howto
=
217 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
);
219 static reloc_howto_type
*
220 elf_s390_reloc_type_lookup (abfd
, code
)
221 bfd
*abfd ATTRIBUTE_UNUSED
;
222 bfd_reloc_code_real_type code
;
227 return &elf_howto_table
[(int) R_390_NONE
];
229 return &elf_howto_table
[(int) R_390_8
];
230 case BFD_RELOC_390_12
:
231 return &elf_howto_table
[(int) R_390_12
];
233 return &elf_howto_table
[(int) R_390_16
];
235 return &elf_howto_table
[(int) R_390_32
];
237 return &elf_howto_table
[(int) R_390_32
];
238 case BFD_RELOC_32_PCREL
:
239 return &elf_howto_table
[(int) R_390_PC32
];
240 case BFD_RELOC_390_GOT12
:
241 return &elf_howto_table
[(int) R_390_GOT12
];
242 case BFD_RELOC_32_GOT_PCREL
:
243 return &elf_howto_table
[(int) R_390_GOT32
];
244 case BFD_RELOC_390_PLT32
:
245 return &elf_howto_table
[(int) R_390_PLT32
];
246 case BFD_RELOC_390_COPY
:
247 return &elf_howto_table
[(int) R_390_COPY
];
248 case BFD_RELOC_390_GLOB_DAT
:
249 return &elf_howto_table
[(int) R_390_GLOB_DAT
];
250 case BFD_RELOC_390_JMP_SLOT
:
251 return &elf_howto_table
[(int) R_390_JMP_SLOT
];
252 case BFD_RELOC_390_RELATIVE
:
253 return &elf_howto_table
[(int) R_390_RELATIVE
];
254 case BFD_RELOC_32_GOTOFF
:
255 return &elf_howto_table
[(int) R_390_GOTOFF32
];
256 case BFD_RELOC_390_GOTPC
:
257 return &elf_howto_table
[(int) R_390_GOTPC
];
258 case BFD_RELOC_390_GOT16
:
259 return &elf_howto_table
[(int) R_390_GOT16
];
260 case BFD_RELOC_16_PCREL
:
261 return &elf_howto_table
[(int) R_390_PC16
];
262 case BFD_RELOC_390_PC16DBL
:
263 return &elf_howto_table
[(int) R_390_PC16DBL
];
264 case BFD_RELOC_390_PLT16DBL
:
265 return &elf_howto_table
[(int) R_390_PLT16DBL
];
266 case BFD_RELOC_390_PC32DBL
:
267 return &elf_howto_table
[(int) R_390_PC32DBL
];
268 case BFD_RELOC_390_PLT32DBL
:
269 return &elf_howto_table
[(int) R_390_PLT32DBL
];
270 case BFD_RELOC_390_GOTPCDBL
:
271 return &elf_howto_table
[(int) R_390_GOTPCDBL
];
272 case BFD_RELOC_390_GOTENT
:
273 return &elf_howto_table
[(int) R_390_GOTENT
];
274 case BFD_RELOC_16_GOTOFF
:
275 return &elf_howto_table
[(int) R_390_GOTOFF16
];
276 case BFD_RELOC_390_GOTPLT12
:
277 return &elf_howto_table
[(int) R_390_GOTPLT12
];
278 case BFD_RELOC_390_GOTPLT16
:
279 return &elf_howto_table
[(int) R_390_GOTPLT16
];
280 case BFD_RELOC_390_GOTPLT32
:
281 return &elf_howto_table
[(int) R_390_GOTPLT32
];
282 case BFD_RELOC_390_GOTPLTENT
:
283 return &elf_howto_table
[(int) R_390_GOTPLTENT
];
284 case BFD_RELOC_390_PLTOFF16
:
285 return &elf_howto_table
[(int) R_390_PLTOFF16
];
286 case BFD_RELOC_390_PLTOFF32
:
287 return &elf_howto_table
[(int) R_390_PLTOFF32
];
288 case BFD_RELOC_390_TLS_LOAD
:
289 return &elf_howto_table
[(int) R_390_TLS_LOAD
];
290 case BFD_RELOC_390_TLS_GDCALL
:
291 return &elf_howto_table
[(int) R_390_TLS_GDCALL
];
292 case BFD_RELOC_390_TLS_LDCALL
:
293 return &elf_howto_table
[(int) R_390_TLS_LDCALL
];
294 case BFD_RELOC_390_TLS_GD32
:
295 return &elf_howto_table
[(int) R_390_TLS_GD32
];
296 case BFD_RELOC_390_TLS_GOTIE12
:
297 return &elf_howto_table
[(int) R_390_TLS_GOTIE12
];
298 case BFD_RELOC_390_TLS_GOTIE32
:
299 return &elf_howto_table
[(int) R_390_TLS_GOTIE32
];
300 case BFD_RELOC_390_TLS_LDM32
:
301 return &elf_howto_table
[(int) R_390_TLS_LDM32
];
302 case BFD_RELOC_390_TLS_IE32
:
303 return &elf_howto_table
[(int) R_390_TLS_IE32
];
304 case BFD_RELOC_390_TLS_IEENT
:
305 return &elf_howto_table
[(int) R_390_TLS_IEENT
];
306 case BFD_RELOC_390_TLS_LE32
:
307 return &elf_howto_table
[(int) R_390_TLS_LE32
];
308 case BFD_RELOC_390_TLS_LDO32
:
309 return &elf_howto_table
[(int) R_390_TLS_LDO32
];
310 case BFD_RELOC_390_TLS_DTPMOD
:
311 return &elf_howto_table
[(int) R_390_TLS_DTPMOD
];
312 case BFD_RELOC_390_TLS_DTPOFF
:
313 return &elf_howto_table
[(int) R_390_TLS_DTPOFF
];
314 case BFD_RELOC_390_TLS_TPOFF
:
315 return &elf_howto_table
[(int) R_390_TLS_TPOFF
];
316 case BFD_RELOC_VTABLE_INHERIT
:
317 return &elf32_s390_vtinherit_howto
;
318 case BFD_RELOC_VTABLE_ENTRY
:
319 return &elf32_s390_vtentry_howto
;
326 /* We need to use ELF32_R_TYPE so we have our own copy of this function,
327 and elf32-s390.c has its own copy. */
330 elf_s390_info_to_howto (abfd
, cache_ptr
, dst
)
331 bfd
*abfd ATTRIBUTE_UNUSED
;
333 Elf_Internal_Rela
*dst
;
335 switch (ELF32_R_TYPE(dst
->r_info
))
337 case R_390_GNU_VTINHERIT
:
338 cache_ptr
->howto
= &elf32_s390_vtinherit_howto
;
341 case R_390_GNU_VTENTRY
:
342 cache_ptr
->howto
= &elf32_s390_vtentry_howto
;
346 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_390_max
);
347 cache_ptr
->howto
= &elf_howto_table
[ELF32_R_TYPE(dst
->r_info
)];
351 /* A relocation function which doesn't do anything. */
352 static bfd_reloc_status_type
353 s390_tls_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
354 output_bfd
, error_message
)
355 bfd
*abfd ATTRIBUTE_UNUSED
;
356 arelent
*reloc_entry
;
357 asymbol
*symbol ATTRIBUTE_UNUSED
;
358 PTR data ATTRIBUTE_UNUSED
;
359 asection
*input_section
;
361 char **error_message ATTRIBUTE_UNUSED
;
364 reloc_entry
->address
+= input_section
->output_offset
;
369 elf_s390_is_local_label_name (abfd
, name
)
373 if (name
[0] == '.' && (name
[1] == 'X' || name
[1] == 'L'))
376 return _bfd_elf_is_local_label_name (abfd
, name
);
379 /* Functions for the 390 ELF linker. */
381 /* The name of the dynamic interpreter. This is put in the .interp
384 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
386 /* The size in bytes of the first entry in the procedure linkage table. */
387 #define PLT_FIRST_ENTRY_SIZE 32
388 /* The size in bytes of an entry in the procedure linkage table. */
389 #define PLT_ENTRY_SIZE 32
391 #define GOT_ENTRY_SIZE 4
393 /* The first three entries in a procedure linkage table are reserved,
394 and the initial contents are unimportant (we zero them out).
395 Subsequent entries look like this. See the SVR4 ABI 386
396 supplement to see how this works. */
398 /* For the s390, simple addr offset can only be 0 - 4096.
399 To use the full 2 GB address space, several instructions
400 are needed to load an address in a register and execute
401 a branch( or just saving the address)
403 Furthermore, only r 0 and 1 are free to use!!! */
405 /* The first 3 words in the GOT are then reserved.
406 Word 0 is the address of the dynamic table.
407 Word 1 is a pointer to a structure describing the object
408 Word 2 is used to point to the loader entry address.
410 The code for position independand PLT entries looks like this:
412 r12 holds addr of the current GOT at entry to the PLT
414 The GOT holds the address in the PLT to be executed.
415 The loader then gets:
416 24(15) = Pointer to the structure describing the object.
417 28(15) = Offset in symbol table
419 The loader must then find the module where the function is
420 and insert the address in the GOT.
422 Note: 390 can only address +- 64 K relative.
423 We check if offset > 65536, then make a relative branch -64xxx
424 back to a previous defined branch
426 PLT1: BASR 1,0 # 2 bytes
427 L 1,22(1) # 4 bytes Load offset in GOT in r 1
428 L 1,(1,12) # 4 bytes Load address from GOT in r1
429 BCR 15,1 # 2 bytes Jump to address
430 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
431 L 1,14(1) # 4 bytes Load offset in symol table in r1
432 BRC 15,-x # 4 bytes Jump to start of PLT
433 .word 0 # 2 bytes filler
434 .long ? # 4 bytes offset in GOT
435 .long ? # 4 bytes offset into symbol table
437 This was the general case. There are two additional, optimizes PLT
438 definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768.
439 First the one for GOT offsets < 4096:
441 PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1
442 BCR 15,1 # 2 bytes Jump to address
443 .word 0,0,0 # 6 bytes filler
444 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
445 L 1,14(1) # 4 bytes Load offset in symbol table in r1
446 BRC 15,-x # 4 bytes Jump to start of PLT
447 .word 0,0,0 # 6 bytes filler
448 .long ? # 4 bytes offset into symbol table
450 Second the one for GOT offsets < 32768:
452 PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1
453 L 1,(1,12) # 4 bytes Load address from GOT to r1
454 BCR 15,1 # 2 bytes Jump to address
455 .word 0 # 2 bytes filler
456 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
457 L 1,14(1) # 4 bytes Load offset in symbol table in r1
458 BRC 15,-x # 4 bytes Jump to start of PLT
459 .word 0,0,0 # 6 bytes filler
460 .long ? # 4 bytes offset into symbol table
462 Total = 32 bytes per PLT entry
464 The code for static build PLT entries looks like this:
466 PLT1: BASR 1,0 # 2 bytes
467 L 1,22(1) # 4 bytes Load address of GOT entry
468 L 1,0(0,1) # 4 bytes Load address from GOT in r1
469 BCR 15,1 # 2 bytes Jump to address
470 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
471 L 1,14(1) # 4 bytes Load offset in symbol table in r1
472 BRC 15,-x # 4 bytes Jump to start of PLT
473 .word 0 # 2 bytes filler
474 .long ? # 4 bytes address of GOT entry
475 .long ? # 4 bytes offset into symbol table */
477 #define PLT_PIC_ENTRY_WORD0 0x0d105810
478 #define PLT_PIC_ENTRY_WORD1 0x10165811
479 #define PLT_PIC_ENTRY_WORD2 0xc00007f1
480 #define PLT_PIC_ENTRY_WORD3 0x0d105810
481 #define PLT_PIC_ENTRY_WORD4 0x100ea7f4
483 #define PLT_PIC12_ENTRY_WORD0 0x5810c000
484 #define PLT_PIC12_ENTRY_WORD1 0x07f10000
485 #define PLT_PIC12_ENTRY_WORD2 0x00000000
486 #define PLT_PIC12_ENTRY_WORD3 0x0d105810
487 #define PLT_PIC12_ENTRY_WORD4 0x100ea7f4
489 #define PLT_PIC16_ENTRY_WORD0 0xa7180000
490 #define PLT_PIC16_ENTRY_WORD1 0x5811c000
491 #define PLT_PIC16_ENTRY_WORD2 0x07f10000
492 #define PLT_PIC16_ENTRY_WORD3 0x0d105810
493 #define PLT_PIC16_ENTRY_WORD4 0x100ea7f4
495 #define PLT_ENTRY_WORD0 0x0d105810
496 #define PLT_ENTRY_WORD1 0x10165810
497 #define PLT_ENTRY_WORD2 0x100007f1
498 #define PLT_ENTRY_WORD3 0x0d105810
499 #define PLT_ENTRY_WORD4 0x100ea7f4
501 /* The first PLT entry pushes the offset into the symbol table
502 from R1 onto the stack at 8(15) and the loader object info
503 at 12(15), loads the loader address in R1 and jumps to it. */
505 /* The first entry in the PLT for PIC code:
508 ST 1,28(15) # R1 has offset into symbol table
509 L 1,4(12) # Get loader ino(object struct address)
510 ST 1,24(15) # Store address
511 L 1,8(12) # Entry address of loader in R1
512 BR 1 # Jump to loader
514 The first entry in the PLT for static code:
517 ST 1,28(15) # R1 has offset into symbol table
519 L 1,18(0,1) # Get address of GOT
520 MVC 24(4,15),4(1) # Move loader ino to stack
521 L 1,8(1) # Get address of loader
522 BR 1 # Jump to loader
524 .long got # address of GOT */
526 #define PLT_PIC_FIRST_ENTRY_WORD0 0x5010f01c
527 #define PLT_PIC_FIRST_ENTRY_WORD1 0x5810c004
528 #define PLT_PIC_FIRST_ENTRY_WORD2 0x5010f018
529 #define PLT_PIC_FIRST_ENTRY_WORD3 0x5810c008
530 #define PLT_PIC_FIRST_ENTRY_WORD4 0x07f10000
532 #define PLT_FIRST_ENTRY_WORD0 0x5010f01c
533 #define PLT_FIRST_ENTRY_WORD1 0x0d105810
534 #define PLT_FIRST_ENTRY_WORD2 0x1012D203
535 #define PLT_FIRST_ENTRY_WORD3 0xf0181004
536 #define PLT_FIRST_ENTRY_WORD4 0x58101008
537 #define PLT_FIRST_ENTRY_WORD5 0x07f10000
539 /* The s390 linker needs to keep track of the number of relocs that it
540 decides to copy as dynamic relocs in check_relocs for each symbol.
541 This is so that it can later discard them if they are found to be
542 unnecessary. We store the information in a field extending the
543 regular ELF linker hash table. */
545 struct elf_s390_dyn_relocs
547 struct elf_s390_dyn_relocs
*next
;
549 /* The input section of the reloc. */
552 /* Total number of relocs copied for the input section. */
555 /* Number of pc-relative relocs copied for the input section. */
556 bfd_size_type pc_count
;
559 /* s390 ELF linker hash entry. */
561 struct elf_s390_link_hash_entry
563 struct elf_link_hash_entry elf
;
565 /* Track dynamic relocs copied for this symbol. */
566 struct elf_s390_dyn_relocs
*dyn_relocs
;
568 /* Number of GOTPLT references for a function. */
569 bfd_signed_vma gotplt_refcount
;
571 #define GOT_UNKNOWN 0
575 #define GOT_TLS_IE_NLT 4
576 unsigned char tls_type
;
579 #define elf_s390_hash_entry(ent) \
580 ((struct elf_s390_link_hash_entry *)(ent))
582 struct elf_s390_obj_tdata
584 struct elf_obj_tdata root
;
586 /* tls_type for each local got entry. */
587 char *local_got_tls_type
;
590 #define elf_s390_tdata(abfd) \
591 ((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
593 #define elf_s390_local_got_tls_type(abfd) \
594 (elf_s390_tdata (abfd)->local_got_tls_type)
597 elf_s390_mkobject (abfd
)
600 bfd_size_type amt
= sizeof (struct elf_s390_obj_tdata
);
601 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
602 if (abfd
->tdata
.any
== NULL
)
608 elf_s390_object_p (abfd
)
611 /* Allocate our special target data. */
612 struct elf_s390_obj_tdata
*new_tdata
;
613 bfd_size_type amt
= sizeof (struct elf_s390_obj_tdata
);
614 new_tdata
= bfd_zalloc (abfd
, amt
);
615 if (new_tdata
== NULL
)
617 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
618 abfd
->tdata
.any
= new_tdata
;
619 /* Set the right machine number for an s390 elf32 file. */
620 return bfd_default_set_arch_mach (abfd
, bfd_arch_s390
, bfd_mach_s390_31
);
623 /* s390 ELF linker hash table. */
625 struct elf_s390_link_hash_table
627 struct elf_link_hash_table elf
;
629 /* Short-cuts to get to dynamic linker sections. */
639 bfd_signed_vma refcount
;
643 /* Small local sym to section mapping cache. */
644 struct sym_sec_cache sym_sec
;
647 /* Get the s390 ELF linker hash table from a link_info structure. */
649 #define elf_s390_hash_table(p) \
650 ((struct elf_s390_link_hash_table *) ((p)->hash))
652 /* Create an entry in an s390 ELF linker hash table. */
654 static struct bfd_hash_entry
*
655 link_hash_newfunc (entry
, table
, string
)
656 struct bfd_hash_entry
*entry
;
657 struct bfd_hash_table
*table
;
660 /* Allocate the structure if it has not already been allocated by a
664 entry
= bfd_hash_allocate (table
,
665 sizeof (struct elf_s390_link_hash_entry
));
670 /* Call the allocation method of the superclass. */
671 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
674 struct elf_s390_link_hash_entry
*eh
;
676 eh
= (struct elf_s390_link_hash_entry
*) entry
;
677 eh
->dyn_relocs
= NULL
;
678 eh
->gotplt_refcount
= 0;
679 eh
->tls_type
= GOT_UNKNOWN
;
685 /* Create an s390 ELF linker hash table. */
687 static struct bfd_link_hash_table
*
688 elf_s390_link_hash_table_create (abfd
)
691 struct elf_s390_link_hash_table
*ret
;
692 bfd_size_type amt
= sizeof (struct elf_s390_link_hash_table
);
694 ret
= (struct elf_s390_link_hash_table
*) bfd_malloc (amt
);
698 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
711 ret
->tls_ldm_got
.refcount
= 0;
712 ret
->sym_sec
.abfd
= NULL
;
714 return &ret
->elf
.root
;
717 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
718 shortcuts to them in our hash table. */
721 create_got_section (dynobj
, info
)
723 struct bfd_link_info
*info
;
725 struct elf_s390_link_hash_table
*htab
;
727 if (! _bfd_elf_create_got_section (dynobj
, info
))
730 htab
= elf_s390_hash_table (info
);
731 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
732 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
733 if (!htab
->sgot
|| !htab
->sgotplt
)
736 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
737 if (htab
->srelgot
== NULL
738 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
739 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
740 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
742 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
747 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
748 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
752 elf_s390_create_dynamic_sections (dynobj
, info
)
754 struct bfd_link_info
*info
;
756 struct elf_s390_link_hash_table
*htab
;
758 htab
= elf_s390_hash_table (info
);
759 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
762 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
765 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
766 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
767 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
769 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
771 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
772 || (!info
->shared
&& !htab
->srelbss
))
778 /* Copy the extra info we tack onto an elf_link_hash_entry. */
781 elf_s390_copy_indirect_symbol (bed
, dir
, ind
)
782 struct elf_backend_data
*bed
;
783 struct elf_link_hash_entry
*dir
, *ind
;
785 struct elf_s390_link_hash_entry
*edir
, *eind
;
787 edir
= (struct elf_s390_link_hash_entry
*) dir
;
788 eind
= (struct elf_s390_link_hash_entry
*) ind
;
790 if (eind
->dyn_relocs
!= NULL
)
792 if (edir
->dyn_relocs
!= NULL
)
794 struct elf_s390_dyn_relocs
**pp
;
795 struct elf_s390_dyn_relocs
*p
;
797 if (ind
->root
.type
== bfd_link_hash_indirect
)
800 /* Add reloc counts against the weak sym to the strong sym
801 list. Merge any entries against the same section. */
802 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
804 struct elf_s390_dyn_relocs
*q
;
806 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
807 if (q
->sec
== p
->sec
)
809 q
->pc_count
+= p
->pc_count
;
810 q
->count
+= p
->count
;
817 *pp
= edir
->dyn_relocs
;
820 edir
->dyn_relocs
= eind
->dyn_relocs
;
821 eind
->dyn_relocs
= NULL
;
824 if (ind
->root
.type
== bfd_link_hash_indirect
825 && dir
->got
.refcount
<= 0)
827 edir
->tls_type
= eind
->tls_type
;
828 eind
->tls_type
= GOT_UNKNOWN
;
831 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
835 elf_s390_tls_transition (info
, r_type
, is_local
)
836 struct bfd_link_info
*info
;
848 return R_390_TLS_LE32
;
849 return R_390_TLS_IE32
;
850 case R_390_TLS_GOTIE32
:
852 return R_390_TLS_LE32
;
853 return R_390_TLS_GOTIE32
;
854 case R_390_TLS_LDM32
:
855 return R_390_TLS_LE32
;
861 /* Look through the relocs for a section during the first phase, and
862 allocate space in the global offset table or procedure linkage
866 elf_s390_check_relocs (abfd
, info
, sec
, relocs
)
868 struct bfd_link_info
*info
;
870 const Elf_Internal_Rela
*relocs
;
872 struct elf_s390_link_hash_table
*htab
;
873 Elf_Internal_Shdr
*symtab_hdr
;
874 struct elf_link_hash_entry
**sym_hashes
;
875 const Elf_Internal_Rela
*rel
;
876 const Elf_Internal_Rela
*rel_end
;
878 bfd_signed_vma
*local_got_refcounts
;
879 int tls_type
, old_tls_type
;
881 if (info
->relocateable
)
884 htab
= elf_s390_hash_table (info
);
885 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
886 sym_hashes
= elf_sym_hashes (abfd
);
887 local_got_refcounts
= elf_local_got_refcounts (abfd
);
891 rel_end
= relocs
+ sec
->reloc_count
;
892 for (rel
= relocs
; rel
< rel_end
; rel
++)
895 unsigned long r_symndx
;
896 struct elf_link_hash_entry
*h
;
898 r_symndx
= ELF32_R_SYM (rel
->r_info
);
900 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
902 (*_bfd_error_handler
) (_("%s: bad symbol index: %d"),
903 bfd_archive_filename (abfd
),
908 if (r_symndx
< symtab_hdr
->sh_info
)
911 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
913 /* Create got section and local_got_refcounts array if they
915 r_type
= elf_s390_tls_transition (info
,
916 ELF32_R_TYPE (rel
->r_info
),
927 case R_390_GOTPLTENT
:
929 case R_390_TLS_GOTIE12
:
930 case R_390_TLS_GOTIE32
:
931 case R_390_TLS_IEENT
:
933 case R_390_TLS_LDM32
:
935 && local_got_refcounts
== NULL
)
939 size
= symtab_hdr
->sh_info
;
940 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
941 local_got_refcounts
= ((bfd_signed_vma
*)
942 bfd_zalloc (abfd
, size
));
943 if (local_got_refcounts
== NULL
)
945 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
946 elf_s390_local_got_tls_type (abfd
)
947 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
954 if (htab
->sgot
== NULL
)
956 if (htab
->elf
.dynobj
== NULL
)
957 htab
->elf
.dynobj
= abfd
;
958 if (!create_got_section (htab
->elf
.dynobj
, info
))
969 /* Got is created, nothing to be done. */
977 /* This symbol requires a procedure linkage table entry. We
978 actually build the entry in adjust_dynamic_symbol,
979 because this might be a case of linking PIC code which is
980 never referenced by a dynamic object, in which case we
981 don't need to generate a procedure linkage table entry
984 /* If this is a local symbol, we resolve it directly without
985 creating a procedure linkage table entry. */
988 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
989 h
->plt
.refcount
+= 1;
996 case R_390_GOTPLTENT
:
997 /* This symbol requires either a procedure linkage table entry
998 or an entry in the local got. We actually build the entry
999 in adjust_dynamic_symbol because whether this is really a
1000 global reference can change and with it the fact if we have
1001 to create a plt entry or a local got entry. To be able to
1002 make a once global symbol a local one we have to keep track
1003 of the number of gotplt references that exist for this
1007 ((struct elf_s390_link_hash_entry
*) h
)->gotplt_refcount
++;
1008 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1009 h
->plt
.refcount
+= 1;
1012 local_got_refcounts
[r_symndx
] += 1;
1015 case R_390_TLS_LDM32
:
1016 htab
->tls_ldm_got
.refcount
+= 1;
1019 case R_390_TLS_IE32
:
1020 case R_390_TLS_GOTIE12
:
1021 case R_390_TLS_GOTIE32
:
1022 case R_390_TLS_IEENT
:
1024 info
->flags
|= DF_STATIC_TLS
;
1031 case R_390_TLS_GD32
:
1032 /* This symbol requires a global offset table entry. */
1040 tls_type
= GOT_NORMAL
;
1042 case R_390_TLS_GD32
:
1043 tls_type
= GOT_TLS_GD
;
1045 case R_390_TLS_IE32
:
1046 case R_390_TLS_GOTIE32
:
1047 tls_type
= GOT_TLS_IE
;
1049 case R_390_TLS_GOTIE12
:
1050 case R_390_TLS_IEENT
:
1051 tls_type
= GOT_TLS_IE_NLT
;
1057 h
->got
.refcount
+= 1;
1058 old_tls_type
= elf_s390_hash_entry(h
)->tls_type
;
1062 local_got_refcounts
[r_symndx
] += 1;
1063 old_tls_type
= elf_s390_local_got_tls_type (abfd
) [r_symndx
];
1065 /* If a TLS symbol is accessed using IE at least once,
1066 there is no point to use dynamic model for it. */
1067 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
)
1069 if (old_tls_type
== GOT_NORMAL
|| tls_type
== GOT_NORMAL
)
1071 (*_bfd_error_handler
)
1072 (_("%s: `%s' accessed both as normal and thread local symbol"),
1073 bfd_archive_filename (abfd
), h
->root
.root
.string
);
1076 if (old_tls_type
> tls_type
)
1077 tls_type
= old_tls_type
;
1080 if (old_tls_type
!= tls_type
)
1083 elf_s390_hash_entry (h
)->tls_type
= tls_type
;
1085 elf_s390_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1088 if (r_type
!= R_390_TLS_IE32
)
1092 case R_390_TLS_LE32
:
1095 info
->flags
|= DF_STATIC_TLS
;
1105 if (h
!= NULL
&& !info
->shared
)
1107 /* If this reloc is in a read-only section, we might
1108 need a copy reloc. We can't check reliably at this
1109 stage whether the section is read-only, as input
1110 sections have not yet been mapped to output sections.
1111 Tentatively set the flag for now, and correct in
1112 adjust_dynamic_symbol. */
1113 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1115 /* We may need a .plt entry if the function this reloc
1116 refers to is in a shared lib. */
1117 h
->plt
.refcount
+= 1;
1120 /* If we are creating a shared library, and this is a reloc
1121 against a global symbol, or a non PC relative reloc
1122 against a local symbol, then we need to copy the reloc
1123 into the shared library. However, if we are linking with
1124 -Bsymbolic, we do not need to copy a reloc against a
1125 global symbol which is defined in an object we are
1126 including in the link (i.e., DEF_REGULAR is set). At
1127 this point we have not seen all the input files, so it is
1128 possible that DEF_REGULAR is not set now but will be set
1129 later (it is never cleared). In case of a weak definition,
1130 DEF_REGULAR may be cleared later by a strong definition in
1131 a shared library. We account for that possibility below by
1132 storing information in the relocs_copied field of the hash
1133 table entry. A similar situation occurs when creating
1134 shared libraries and symbol visibility changes render the
1137 If on the other hand, we are creating an executable, we
1138 may need to keep relocations for symbols satisfied by a
1139 dynamic library if we manage to avoid copy relocs for the
1142 && (sec
->flags
& SEC_ALLOC
) != 0
1143 && ((ELF32_R_TYPE (rel
->r_info
) != R_390_PC16
1144 && ELF32_R_TYPE (rel
->r_info
) != R_390_PC16DBL
1145 && ELF32_R_TYPE (rel
->r_info
) != R_390_PC32DBL
1146 && ELF32_R_TYPE (rel
->r_info
) != R_390_PC32
)
1148 && (! info
->symbolic
1149 || h
->root
.type
== bfd_link_hash_defweak
1150 || (h
->elf_link_hash_flags
1151 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1153 && (sec
->flags
& SEC_ALLOC
) != 0
1155 && (h
->root
.type
== bfd_link_hash_defweak
1156 || (h
->elf_link_hash_flags
1157 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1159 struct elf_s390_dyn_relocs
*p
;
1160 struct elf_s390_dyn_relocs
**head
;
1162 /* We must copy these reloc types into the output file.
1163 Create a reloc section in dynobj and make room for
1170 name
= (bfd_elf_string_from_elf_section
1172 elf_elfheader (abfd
)->e_shstrndx
,
1173 elf_section_data (sec
)->rel_hdr
.sh_name
));
1177 if (strncmp (name
, ".rela", 5) != 0
1178 || strcmp (bfd_get_section_name (abfd
, sec
),
1181 (*_bfd_error_handler
)
1182 (_("%s: bad relocation section name `%s\'"),
1183 bfd_archive_filename (abfd
), name
);
1186 if (htab
->elf
.dynobj
== NULL
)
1187 htab
->elf
.dynobj
= abfd
;
1189 dynobj
= htab
->elf
.dynobj
;
1190 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1195 sreloc
= bfd_make_section (dynobj
, name
);
1196 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1197 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1198 if ((sec
->flags
& SEC_ALLOC
) != 0)
1199 flags
|= SEC_ALLOC
| SEC_LOAD
;
1201 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
1202 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1205 elf_section_data (sec
)->sreloc
= sreloc
;
1208 /* If this is a global symbol, we count the number of
1209 relocations we need for this symbol. */
1212 head
= &((struct elf_s390_link_hash_entry
*) h
)->dyn_relocs
;
1216 /* Track dynamic relocs needed for local syms too.
1217 We really need local syms available to do this
1221 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1226 head
= ((struct elf_s390_dyn_relocs
**)
1227 &elf_section_data (s
)->local_dynrel
);
1231 if (p
== NULL
|| p
->sec
!= sec
)
1233 bfd_size_type amt
= sizeof *p
;
1235 p
= ((struct elf_s390_dyn_relocs
*)
1236 bfd_alloc (htab
->elf
.dynobj
, amt
));
1247 if (ELF32_R_TYPE (rel
->r_info
) == R_390_PC16
1248 || ELF32_R_TYPE (rel
->r_info
) == R_390_PC16DBL
1249 || ELF32_R_TYPE (rel
->r_info
) == R_390_PC32DBL
1250 || ELF32_R_TYPE (rel
->r_info
) == R_390_PC32
)
1255 /* This relocation describes the C++ object vtable hierarchy.
1256 Reconstruct it for later use during GC. */
1257 case R_390_GNU_VTINHERIT
:
1258 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1262 /* This relocation describes which C++ vtable entries are actually
1263 used. Record for later use during GC. */
1264 case R_390_GNU_VTENTRY
:
1265 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1277 /* Return the section that should be marked against GC for a given
1281 elf_s390_gc_mark_hook (sec
, info
, rel
, h
, sym
)
1283 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1284 Elf_Internal_Rela
*rel
;
1285 struct elf_link_hash_entry
*h
;
1286 Elf_Internal_Sym
*sym
;
1290 switch (ELF32_R_TYPE (rel
->r_info
))
1292 case R_390_GNU_VTINHERIT
:
1293 case R_390_GNU_VTENTRY
:
1297 switch (h
->root
.type
)
1299 case bfd_link_hash_defined
:
1300 case bfd_link_hash_defweak
:
1301 return h
->root
.u
.def
.section
;
1303 case bfd_link_hash_common
:
1304 return h
->root
.u
.c
.p
->section
;
1312 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1317 /* Update the got entry reference counts for the section being removed. */
1320 elf_s390_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1322 struct bfd_link_info
*info
;
1324 const Elf_Internal_Rela
*relocs
;
1326 Elf_Internal_Shdr
*symtab_hdr
;
1327 struct elf_link_hash_entry
**sym_hashes
;
1328 bfd_signed_vma
*local_got_refcounts
;
1329 const Elf_Internal_Rela
*rel
, *relend
;
1331 elf_section_data (sec
)->local_dynrel
= NULL
;
1333 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1334 sym_hashes
= elf_sym_hashes (abfd
);
1335 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1337 relend
= relocs
+ sec
->reloc_count
;
1338 for (rel
= relocs
; rel
< relend
; rel
++)
1340 unsigned long r_symndx
;
1341 unsigned int r_type
;
1342 struct elf_link_hash_entry
*h
= NULL
;
1344 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1345 if (r_symndx
>= symtab_hdr
->sh_info
)
1347 struct elf_s390_link_hash_entry
*eh
;
1348 struct elf_s390_dyn_relocs
**pp
;
1349 struct elf_s390_dyn_relocs
*p
;
1351 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1352 eh
= (struct elf_s390_link_hash_entry
*) h
;
1354 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1357 /* Everything must go for SEC. */
1363 r_type
= ELF32_R_TYPE (rel
->r_info
);
1364 r_type
= elf_s390_tls_transition (info
, r_type
, h
!= NULL
);
1367 case R_390_TLS_LDM32
:
1368 if (elf_s390_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1369 elf_s390_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1372 case R_390_TLS_GD32
:
1373 case R_390_TLS_IE32
:
1374 case R_390_TLS_GOTIE12
:
1375 case R_390_TLS_GOTIE32
:
1376 case R_390_TLS_IEENT
:
1380 case R_390_GOTOFF16
:
1381 case R_390_GOTOFF32
:
1383 case R_390_GOTPCDBL
:
1387 if (h
->got
.refcount
> 0)
1388 h
->got
.refcount
-= 1;
1390 else if (local_got_refcounts
!= NULL
)
1392 if (local_got_refcounts
[r_symndx
] > 0)
1393 local_got_refcounts
[r_symndx
] -= 1;
1409 case R_390_PLT16DBL
:
1410 case R_390_PLT32DBL
:
1412 case R_390_PLTOFF16
:
1413 case R_390_PLTOFF32
:
1416 if (h
->plt
.refcount
> 0)
1417 h
->plt
.refcount
-= 1;
1421 case R_390_GOTPLT12
:
1422 case R_390_GOTPLT16
:
1423 case R_390_GOTPLT32
:
1424 case R_390_GOTPLTENT
:
1427 if (h
->plt
.refcount
> 0)
1429 ((struct elf_s390_link_hash_entry
*) h
)->gotplt_refcount
--;
1430 h
->plt
.refcount
-= 1;
1433 else if (local_got_refcounts
!= NULL
)
1435 if (local_got_refcounts
[r_symndx
] > 0)
1436 local_got_refcounts
[r_symndx
] -= 1;
1448 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1449 entry but we found we will not create any. Called when we find we will
1450 not have any PLT for this symbol, by for example
1451 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
1452 or elf_s390_size_dynamic_sections if no dynamic sections will be
1453 created (we're only linking static objects). */
1456 elf_s390_adjust_gotplt (h
)
1457 struct elf_s390_link_hash_entry
*h
;
1459 if (h
->elf
.root
.type
== bfd_link_hash_warning
)
1460 h
= (struct elf_s390_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
1462 if (h
->gotplt_refcount
<= 0)
1465 /* We simply add the number of gotplt references to the number
1466 * of got references for this symbol. */
1467 h
->elf
.got
.refcount
+= h
->gotplt_refcount
;
1468 h
->gotplt_refcount
= -1;
1471 /* Adjust a symbol defined by a dynamic object and referenced by a
1472 regular object. The current definition is in some section of the
1473 dynamic object, but we're not including those sections. We have to
1474 change the definition to something the rest of the link can
1478 elf_s390_adjust_dynamic_symbol (info
, h
)
1479 struct bfd_link_info
*info
;
1480 struct elf_link_hash_entry
*h
;
1482 struct elf_s390_link_hash_table
*htab
;
1483 struct elf_s390_link_hash_entry
* eh
;
1484 struct elf_s390_dyn_relocs
*p
;
1486 unsigned int power_of_two
;
1488 /* If this is a function, put it in the procedure linkage table. We
1489 will fill in the contents of the procedure linkage table later
1490 (although we could actually do it here). */
1491 if (h
->type
== STT_FUNC
1492 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1494 if (h
->plt
.refcount
<= 0
1496 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1497 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
1498 && h
->root
.type
!= bfd_link_hash_undefweak
1499 && h
->root
.type
!= bfd_link_hash_undefined
))
1501 /* This case can occur if we saw a PLT32 reloc in an input
1502 file, but the symbol was never referred to by a dynamic
1503 object, or if all references were garbage collected. In
1504 such a case, we don't actually need to build a procedure
1505 linkage table, and we can just do a PC32 reloc instead. */
1506 h
->plt
.offset
= (bfd_vma
) -1;
1507 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1508 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1514 /* It's possible that we incorrectly decided a .plt reloc was
1515 needed for an R_390_PC32 reloc to a non-function sym in
1516 check_relocs. We can't decide accurately between function and
1517 non-function syms in check-relocs; Objects loaded later in
1518 the link may change h->type. So fix it now. */
1519 h
->plt
.offset
= (bfd_vma
) -1;
1521 /* If this is a weak symbol, and there is a real definition, the
1522 processor independent code will have arranged for us to see the
1523 real definition first, and we can just use the same value. */
1524 if (h
->weakdef
!= NULL
)
1526 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1527 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1528 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1529 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1533 /* This is a reference to a symbol defined by a dynamic object which
1534 is not a function. */
1536 /* If we are creating a shared library, we must presume that the
1537 only references to the symbol are via the global offset table.
1538 For such cases we need not do anything here; the relocations will
1539 be handled correctly by relocate_section. */
1543 /* If there are no references to this symbol that do not use the
1544 GOT, we don't need to generate a copy reloc. */
1545 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1548 /* If -z nocopyreloc was given, we won't generate them either. */
1549 if (info
->nocopyreloc
)
1551 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1555 eh
= (struct elf_s390_link_hash_entry
*) h
;
1556 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1558 s
= p
->sec
->output_section
;
1559 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1563 /* If we didn't find any dynamic relocs in read-only sections, then
1564 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1567 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1571 /* We must allocate the symbol in our .dynbss section, which will
1572 become part of the .bss section of the executable. There will be
1573 an entry for this symbol in the .dynsym section. The dynamic
1574 object will contain position independent code, so all references
1575 from the dynamic object to this symbol will go through the global
1576 offset table. The dynamic linker will use the .dynsym entry to
1577 determine the address it must put in the global offset table, so
1578 both the dynamic object and the regular object will refer to the
1579 same memory location for the variable. */
1581 htab
= elf_s390_hash_table (info
);
1583 /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1584 copy the initial value out of the dynamic object and into the
1585 runtime process image. */
1586 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1588 htab
->srelbss
->_raw_size
+= sizeof (Elf32_External_Rela
);
1589 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1592 /* We need to figure out the alignment required for this symbol. I
1593 have no idea how ELF linkers handle this. */
1594 power_of_two
= bfd_log2 (h
->size
);
1595 if (power_of_two
> 3)
1598 /* Apply the required alignment. */
1600 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
1601 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1603 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1607 /* Define the symbol as being at this point in the section. */
1608 h
->root
.u
.def
.section
= s
;
1609 h
->root
.u
.def
.value
= s
->_raw_size
;
1611 /* Increment the section size to make room for the symbol. */
1612 s
->_raw_size
+= h
->size
;
1617 /* This is the condition under which elf_s390_finish_dynamic_symbol
1618 will be called from elflink.h. If elflink.h doesn't call our
1619 finish_dynamic_symbol routine, we'll need to do something about
1620 initializing any .plt and .got entries in elf_s390_relocate_section. */
1621 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1623 && ((INFO)->shared \
1624 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1625 && ((H)->dynindx != -1 \
1626 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1628 /* Allocate space in .plt, .got and associated reloc sections for
1632 allocate_dynrelocs (h
, inf
)
1633 struct elf_link_hash_entry
*h
;
1636 struct bfd_link_info
*info
;
1637 struct elf_s390_link_hash_table
*htab
;
1638 struct elf_s390_link_hash_entry
*eh
;
1639 struct elf_s390_dyn_relocs
*p
;
1641 if (h
->root
.type
== bfd_link_hash_indirect
)
1644 if (h
->root
.type
== bfd_link_hash_warning
)
1645 /* When warning symbols are created, they **replace** the "real"
1646 entry in the hash table, thus we never get to see the real
1647 symbol in a hash traversal. So look at it now. */
1648 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1650 info
= (struct bfd_link_info
*) inf
;
1651 htab
= elf_s390_hash_table (info
);
1653 if (htab
->elf
.dynamic_sections_created
1654 && h
->plt
.refcount
> 0)
1656 /* Make sure this symbol is output as a dynamic symbol.
1657 Undefined weak syms won't yet be marked as dynamic. */
1658 if (h
->dynindx
== -1
1659 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1661 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1665 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
1667 asection
*s
= htab
->splt
;
1669 /* If this is the first .plt entry, make room for the special
1671 if (s
->_raw_size
== 0)
1672 s
->_raw_size
+= PLT_FIRST_ENTRY_SIZE
;
1674 h
->plt
.offset
= s
->_raw_size
;
1676 /* If this symbol is not defined in a regular file, and we are
1677 not generating a shared library, then set the symbol to this
1678 location in the .plt. This is required to make function
1679 pointers compare as equal between the normal executable and
1680 the shared library. */
1682 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1684 h
->root
.u
.def
.section
= s
;
1685 h
->root
.u
.def
.value
= h
->plt
.offset
;
1688 /* Make room for this entry. */
1689 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1691 /* We also need to make an entry in the .got.plt section, which
1692 will be placed in the .got section by the linker script. */
1693 htab
->sgotplt
->_raw_size
+= GOT_ENTRY_SIZE
;
1695 /* We also need to make an entry in the .rela.plt section. */
1696 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
1700 h
->plt
.offset
= (bfd_vma
) -1;
1701 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1702 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1707 h
->plt
.offset
= (bfd_vma
) -1;
1708 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1709 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1712 /* If R_390_TLS_{IE32,GOTIE32,GOTIE12,IEENT} symbol is now local to
1713 the binary, we can optimize a bit. IE32 and GOTIE32 get converted
1714 to R_390_TLS_LE32 requiring no TLS entry. For GOTIE12 and IEENT
1715 we can save the dynamic TLS relocation. */
1716 if (h
->got
.refcount
> 0
1719 && elf_s390_hash_entry(h
)->tls_type
>= GOT_TLS_IE
)
1721 if (elf_s390_hash_entry(h
)->tls_type
== GOT_TLS_IE_NLT
)
1722 /* For the GOTIE access without a literal pool entry the offset has
1723 to be stored somewhere. The immediate value in the instruction
1724 is not bit enough so the value is stored in the got. */
1726 h
->got
.offset
= htab
->sgot
->_raw_size
;
1727 htab
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1730 h
->got
.offset
= (bfd_vma
) -1;
1732 else if (h
->got
.refcount
> 0)
1736 int tls_type
= elf_s390_hash_entry(h
)->tls_type
;
1738 /* Make sure this symbol is output as a dynamic symbol.
1739 Undefined weak syms won't yet be marked as dynamic. */
1740 if (h
->dynindx
== -1
1741 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1743 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1748 h
->got
.offset
= s
->_raw_size
;
1749 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1750 /* R_390_TLS_GD32 needs 2 consecutive GOT slots. */
1751 if (tls_type
== GOT_TLS_GD
)
1752 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1753 dyn
= htab
->elf
.dynamic_sections_created
;
1754 /* R_390_TLS_IE32 needs one dynamic relocation,
1755 R_390_TLS_GD32 needs one if local symbol and two if global. */
1756 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
1757 || tls_type
>= GOT_TLS_IE
)
1758 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1759 else if (tls_type
== GOT_TLS_GD
)
1760 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf32_External_Rela
);
1761 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
1762 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1765 h
->got
.offset
= (bfd_vma
) -1;
1767 eh
= (struct elf_s390_link_hash_entry
*) h
;
1768 if (eh
->dyn_relocs
== NULL
)
1771 /* In the shared -Bsymbolic case, discard space allocated for
1772 dynamic pc-relative relocs against symbols which turn out to be
1773 defined in regular objects. For the normal shared case, discard
1774 space for pc-relative relocs that have become local due to symbol
1775 visibility changes. */
1779 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1780 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
1783 struct elf_s390_dyn_relocs
**pp
;
1785 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1787 p
->count
-= p
->pc_count
;
1798 /* For the non-shared case, discard space for relocs against
1799 symbols which turn out to need copy relocs or are not
1802 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1803 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1804 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1805 || (htab
->elf
.dynamic_sections_created
1806 && (h
->root
.type
== bfd_link_hash_undefweak
1807 || h
->root
.type
== bfd_link_hash_undefined
))))
1809 /* Make sure this symbol is output as a dynamic symbol.
1810 Undefined weak syms won't yet be marked as dynamic. */
1811 if (h
->dynindx
== -1
1812 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1814 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1818 /* If that succeeded, we know we'll be keeping all the
1820 if (h
->dynindx
!= -1)
1824 eh
->dyn_relocs
= NULL
;
1829 /* Finally, allocate space. */
1830 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1832 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1834 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
1840 /* Find any dynamic relocs that apply to read-only sections. */
1843 readonly_dynrelocs (h
, inf
)
1844 struct elf_link_hash_entry
*h
;
1847 struct elf_s390_link_hash_entry
*eh
;
1848 struct elf_s390_dyn_relocs
*p
;
1850 if (h
->root
.type
== bfd_link_hash_warning
)
1851 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1853 eh
= (struct elf_s390_link_hash_entry
*) h
;
1854 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1856 asection
*s
= p
->sec
->output_section
;
1858 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1860 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1862 info
->flags
|= DF_TEXTREL
;
1864 /* Not an error, just cut short the traversal. */
1871 /* Set the sizes of the dynamic sections. */
1874 elf_s390_size_dynamic_sections (output_bfd
, info
)
1875 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1876 struct bfd_link_info
*info
;
1878 struct elf_s390_link_hash_table
*htab
;
1884 htab
= elf_s390_hash_table (info
);
1885 dynobj
= htab
->elf
.dynobj
;
1889 if (htab
->elf
.dynamic_sections_created
)
1891 /* Set the contents of the .interp section to the interpreter. */
1894 s
= bfd_get_section_by_name (dynobj
, ".interp");
1897 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1898 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1902 /* Set up .got offsets for local syms, and space for local dynamic
1904 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1906 bfd_signed_vma
*local_got
;
1907 bfd_signed_vma
*end_local_got
;
1908 char *local_tls_type
;
1909 bfd_size_type locsymcount
;
1910 Elf_Internal_Shdr
*symtab_hdr
;
1913 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1916 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1918 struct elf_s390_dyn_relocs
*p
;
1920 for (p
= *((struct elf_s390_dyn_relocs
**)
1921 &elf_section_data (s
)->local_dynrel
);
1925 if (!bfd_is_abs_section (p
->sec
)
1926 && bfd_is_abs_section (p
->sec
->output_section
))
1928 /* Input section has been discarded, either because
1929 it is a copy of a linkonce section or due to
1930 linker script /DISCARD/, so we'll be discarding
1933 else if (p
->count
!= 0)
1935 srela
= elf_section_data (p
->sec
)->sreloc
;
1936 srela
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
1937 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1938 info
->flags
|= DF_TEXTREL
;
1943 local_got
= elf_local_got_refcounts (ibfd
);
1947 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1948 locsymcount
= symtab_hdr
->sh_info
;
1949 end_local_got
= local_got
+ locsymcount
;
1950 local_tls_type
= elf_s390_local_got_tls_type (ibfd
);
1952 srela
= htab
->srelgot
;
1953 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
1957 *local_got
= s
->_raw_size
;
1958 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1959 if (*local_tls_type
== GOT_TLS_GD
)
1960 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1962 srela
->_raw_size
+= sizeof (Elf32_External_Rela
);
1965 *local_got
= (bfd_vma
) -1;
1969 if (htab
->tls_ldm_got
.refcount
> 0)
1971 /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM32
1973 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
1974 htab
->sgot
->_raw_size
+= 2 * GOT_ENTRY_SIZE
;
1975 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1978 htab
->tls_ldm_got
.offset
= -1;
1980 /* Allocate global sym .plt and .got entries, and space for global
1981 sym dynamic relocs. */
1982 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1984 /* We now have determined the sizes of the various dynamic sections.
1985 Allocate memory for them. */
1987 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1989 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1994 || s
== htab
->sgotplt
)
1996 /* Strip this section if we don't need it; see the
1999 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
2001 if (s
->_raw_size
!= 0)
2004 /* We use the reloc_count field as a counter if we need
2005 to copy relocs into the output file. */
2010 /* It's not one of our sections, so don't allocate space. */
2014 if (s
->_raw_size
== 0)
2016 /* If we don't need this section, strip it from the
2017 output file. This is to handle .rela.bss and
2018 .rela.plt. We must create it in
2019 create_dynamic_sections, because it must be created
2020 before the linker maps input sections to output
2021 sections. The linker does that before
2022 adjust_dynamic_symbol is called, and it is that
2023 function which decides whether anything needs to go
2024 into these sections. */
2026 _bfd_strip_section_from_output (info
, s
);
2030 /* Allocate memory for the section contents. We use bfd_zalloc
2031 here in case unused entries are not reclaimed before the
2032 section's contents are written out. This should not happen,
2033 but this way if it does, we get a R_390_NONE reloc instead
2035 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2036 if (s
->contents
== NULL
)
2040 if (htab
->elf
.dynamic_sections_created
)
2042 /* Add some entries to the .dynamic section. We fill in the
2043 values later, in elf_s390_finish_dynamic_sections, but we
2044 must add the entries now so that we get the correct size for
2045 the .dynamic section. The DT_DEBUG entry is filled in by the
2046 dynamic linker and used by the debugger. */
2047 #define add_dynamic_entry(TAG, VAL) \
2048 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2052 if (!add_dynamic_entry (DT_DEBUG
, 0))
2056 if (htab
->splt
->_raw_size
!= 0)
2058 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2059 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2060 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2061 || !add_dynamic_entry (DT_JMPREL
, 0))
2067 if (!add_dynamic_entry (DT_RELA
, 0)
2068 || !add_dynamic_entry (DT_RELASZ
, 0)
2069 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
2072 /* If any dynamic relocs apply to a read-only section,
2073 then we need a DT_TEXTREL entry. */
2074 if ((info
->flags
& DF_TEXTREL
) == 0)
2075 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2078 if ((info
->flags
& DF_TEXTREL
) != 0)
2080 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2085 #undef add_dynamic_entry
2090 /* Return the base VMA address which should be subtracted from real addresses
2091 when resolving @dtpoff relocation.
2092 This is PT_TLS segment p_vaddr. */
2096 struct bfd_link_info
*info
;
2098 /* If tls_segment is NULL, we should have signalled an error already. */
2099 if (elf_hash_table (info
)->tls_segment
== NULL
)
2101 return elf_hash_table (info
)->tls_segment
->start
;
2104 /* Return the relocation value for @tpoff relocation
2105 if STT_TLS virtual address is ADDRESS. */
2108 tpoff (info
, address
)
2109 struct bfd_link_info
*info
;
2112 struct elf_link_tls_segment
*tls_segment
2113 = elf_hash_table (info
)->tls_segment
;
2115 /* If tls_segment is NULL, we should have signalled an error already. */
2116 if (tls_segment
== NULL
)
2118 return (align_power (tls_segment
->size
, tls_segment
->align
)
2119 + tls_segment
->start
- address
);
2122 /* Complain if TLS instruction relocation is against an invalid
2126 invalid_tls_insn (input_bfd
, input_section
, rel
)
2128 asection
*input_section
;
2129 Elf_Internal_Rela
*rel
;
2131 reloc_howto_type
*howto
;
2133 howto
= elf_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2134 (*_bfd_error_handler
)
2135 (_("%s(%s+0x%lx): invalid instruction for TLS relocation %s"),
2136 bfd_archive_filename (input_bfd
),
2137 bfd_get_section_name (input_bfd
, input_section
),
2138 (long) rel
->r_offset
,
2142 /* Relocate a 390 ELF section. */
2145 elf_s390_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2146 contents
, relocs
, local_syms
, local_sections
)
2148 struct bfd_link_info
*info
;
2150 asection
*input_section
;
2152 Elf_Internal_Rela
*relocs
;
2153 Elf_Internal_Sym
*local_syms
;
2154 asection
**local_sections
;
2156 struct elf_s390_link_hash_table
*htab
;
2157 Elf_Internal_Shdr
*symtab_hdr
;
2158 struct elf_link_hash_entry
**sym_hashes
;
2159 bfd_vma
*local_got_offsets
;
2160 Elf_Internal_Rela
*rel
;
2161 Elf_Internal_Rela
*relend
;
2163 if (info
->relocateable
)
2166 htab
= elf_s390_hash_table (info
);
2167 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2168 sym_hashes
= elf_sym_hashes (input_bfd
);
2169 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2172 relend
= relocs
+ input_section
->reloc_count
;
2173 for (; rel
< relend
; rel
++)
2175 unsigned int r_type
;
2176 reloc_howto_type
*howto
;
2177 unsigned long r_symndx
;
2178 struct elf_link_hash_entry
*h
;
2179 Elf_Internal_Sym
*sym
;
2183 bfd_boolean unresolved_reloc
;
2184 bfd_reloc_status_type r
;
2187 r_type
= ELF32_R_TYPE (rel
->r_info
);
2188 if (r_type
== (int) R_390_GNU_VTINHERIT
2189 || r_type
== (int) R_390_GNU_VTENTRY
)
2191 if (r_type
>= (int) R_390_max
)
2193 bfd_set_error (bfd_error_bad_value
);
2197 howto
= elf_howto_table
+ r_type
;
2198 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2200 /* This is a final link. */
2204 unresolved_reloc
= FALSE
;
2205 if (r_symndx
< symtab_hdr
->sh_info
)
2207 sym
= local_syms
+ r_symndx
;
2208 sec
= local_sections
[r_symndx
];
2209 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
2213 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2214 while (h
->root
.type
== bfd_link_hash_indirect
2215 || h
->root
.type
== bfd_link_hash_warning
)
2216 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2218 if (h
->root
.type
== bfd_link_hash_defined
2219 || h
->root
.type
== bfd_link_hash_defweak
)
2221 sec
= h
->root
.u
.def
.section
;
2222 if (sec
->output_section
== NULL
)
2224 /* Set a flag that will be cleared later if we find a
2225 relocation value for this symbol. output_section
2226 is typically NULL for symbols satisfied by a shared
2228 unresolved_reloc
= TRUE
;
2232 relocation
= (h
->root
.u
.def
.value
2233 + sec
->output_section
->vma
2234 + sec
->output_offset
);
2236 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2238 else if (info
->shared
2239 && !info
->no_undefined
2240 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2244 if (! ((*info
->callbacks
->undefined_symbol
)
2245 (info
, h
->root
.root
.string
, input_bfd
,
2246 input_section
, rel
->r_offset
,
2247 (!info
->shared
|| info
->no_undefined
2248 || ELF_ST_VISIBILITY (h
->other
)))))
2256 case R_390_GOTPLT12
:
2257 case R_390_GOTPLT16
:
2258 case R_390_GOTPLT32
:
2259 case R_390_GOTPLTENT
:
2260 /* There are three cases for a GOTPLT relocation. 1) The
2261 relocation is against the jump slot entry of a plt that
2262 will get emitted to the output file. 2) The relocation
2263 is against the jump slot of a plt entry that has been
2264 removed. elf_s390_adjust_gotplt has created a GOT entry
2265 as replacement. 3) The relocation is against a local symbol.
2266 Cases 2) and 3) are the same as the GOT relocation code
2267 so we just have to test for case 1 and fall through for
2269 if (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
2274 Current offset - size first entry / entry size. */
2275 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) /
2278 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2280 relocation
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2281 unresolved_reloc
= FALSE
;
2283 if (r_type
== R_390_GOTPLTENT
)
2284 relocation
+= htab
->sgot
->output_section
->vma
;
2293 /* Relocation is to the entry for this symbol in the global
2295 if (htab
->sgot
== NULL
)
2302 off
= h
->got
.offset
;
2303 dyn
= htab
->elf
.dynamic_sections_created
;
2304 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
2308 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
2309 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2311 /* This is actually a static link, or it is a
2312 -Bsymbolic link and the symbol is defined
2313 locally, or the symbol was forced to be local
2314 because of a version file. We must initialize
2315 this entry in the global offset table. Since the
2316 offset must always be a multiple of 2, we use the
2317 least significant bit to record whether we have
2318 initialized it already.
2320 When doing a dynamic link, we create a .rel.got
2321 relocation entry to initialize the value. This
2322 is done in the finish_dynamic_symbol routine. */
2327 bfd_put_32 (output_bfd
, relocation
,
2328 htab
->sgot
->contents
+ off
);
2333 unresolved_reloc
= FALSE
;
2337 if (local_got_offsets
== NULL
)
2340 off
= local_got_offsets
[r_symndx
];
2342 /* The offset must always be a multiple of 4. We use
2343 the least significant bit to record whether we have
2344 already generated the necessary reloc. */
2349 bfd_put_32 (output_bfd
, relocation
,
2350 htab
->sgot
->contents
+ off
);
2355 Elf_Internal_Rela outrel
;
2358 srelgot
= htab
->srelgot
;
2359 if (srelgot
== NULL
)
2362 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2363 + htab
->sgot
->output_offset
2365 outrel
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
2366 outrel
.r_addend
= relocation
;
2367 loc
= srelgot
->contents
;
2368 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2369 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2372 local_got_offsets
[r_symndx
] |= 1;
2376 if (off
>= (bfd_vma
) -2)
2379 relocation
= htab
->sgot
->output_offset
+ off
;
2381 /* For @GOTENT the relocation is against the offset between
2382 the instruction and the symbols entry in the GOT and not
2383 between the start of the GOT and the symbols entry. We
2384 add the vma of the GOT to get the correct value. */
2385 if ( r_type
== R_390_GOTENT
2386 || r_type
== R_390_GOTPLTENT
)
2387 relocation
+= htab
->sgot
->output_section
->vma
;
2391 case R_390_GOTOFF16
:
2392 case R_390_GOTOFF32
:
2393 /* Relocation is relative to the start of the global offset
2396 /* Note that sgot->output_offset is not involved in this
2397 calculation. We always want the start of .got. If we
2398 defined _GLOBAL_OFFSET_TABLE in a different way, as is
2399 permitted by the ABI, we might have to change this
2401 relocation
-= htab
->sgot
->output_section
->vma
;
2405 case R_390_GOTPCDBL
:
2406 /* Use global offset table as symbol value. */
2407 relocation
= htab
->sgot
->output_section
->vma
;
2408 unresolved_reloc
= FALSE
;
2411 case R_390_PLT16DBL
:
2412 case R_390_PLT32DBL
:
2414 /* Relocation is to the entry for this symbol in the
2415 procedure linkage table. */
2417 /* Resolve a PLT32 reloc against a local symbol directly,
2418 without using the procedure linkage table. */
2422 if (h
->plt
.offset
== (bfd_vma
) -1
2423 || htab
->splt
== NULL
)
2425 /* We didn't make a PLT entry for this symbol. This
2426 happens when statically linking PIC code, or when
2427 using -Bsymbolic. */
2431 relocation
= (htab
->splt
->output_section
->vma
2432 + htab
->splt
->output_offset
2434 unresolved_reloc
= FALSE
;
2437 case R_390_PLTOFF16
:
2438 case R_390_PLTOFF32
:
2439 /* Relocation is to the entry for this symbol in the
2440 procedure linkage table relative to the start of the GOT. */
2442 /* For local symbols or if we didn't make a PLT entry for
2443 this symbol resolve the symbol directly. */
2445 || h
->plt
.offset
== (bfd_vma
) -1
2446 || htab
->splt
== NULL
)
2448 relocation
-= htab
->sgot
->output_section
->vma
;
2452 relocation
= (htab
->splt
->output_section
->vma
2453 + htab
->splt
->output_offset
2455 - htab
->sgot
->output_section
->vma
);
2456 unresolved_reloc
= FALSE
;
2466 /* r_symndx will be zero only for relocs against symbols
2467 from removed linkonce sections, or sections discarded by
2470 || (input_section
->flags
& SEC_ALLOC
) == 0)
2474 && ((r_type
!= R_390_PC16
2475 && r_type
!= R_390_PC16DBL
2476 && r_type
!= R_390_PC32DBL
2477 && r_type
!= R_390_PC32
)
2480 && (! info
->symbolic
2481 || (h
->elf_link_hash_flags
2482 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2486 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2487 && (((h
->elf_link_hash_flags
2488 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2489 && (h
->elf_link_hash_flags
2490 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2491 || h
->root
.type
== bfd_link_hash_undefweak
2492 || h
->root
.type
== bfd_link_hash_undefined
)))
2494 Elf_Internal_Rela outrel
;
2495 bfd_boolean skip
, relocate
;
2499 /* When generating a shared object, these relocations
2500 are copied into the output file to be resolved at run
2507 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2509 if (outrel
.r_offset
== (bfd_vma
) -1)
2511 else if (outrel
.r_offset
== (bfd_vma
) -2)
2512 skip
= TRUE
, relocate
= TRUE
;
2513 outrel
.r_offset
+= (input_section
->output_section
->vma
2514 + input_section
->output_offset
);
2517 memset (&outrel
, 0, sizeof outrel
);
2520 && (r_type
== R_390_PC16
2521 || r_type
== R_390_PC16DBL
2522 || r_type
== R_390_PC32DBL
2523 || r_type
== R_390_PC32
2526 || (h
->elf_link_hash_flags
2527 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2529 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2530 outrel
.r_addend
= rel
->r_addend
;
2534 /* This symbol is local, or marked to become local. */
2536 outrel
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
2537 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2540 sreloc
= elf_section_data (input_section
)->sreloc
;
2544 loc
= sreloc
->contents
;
2545 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2546 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2548 /* If this reloc is against an external symbol, we do
2549 not want to fiddle with the addend. Otherwise, we
2550 need to include the symbol value so that it becomes
2551 an addend for the dynamic reloc. */
2557 /* Relocations for tls literal pool entries. */
2558 case R_390_TLS_IE32
:
2561 Elf_Internal_Rela outrel
;
2565 outrel
.r_offset
= rel
->r_offset
2566 + input_section
->output_section
->vma
2567 + input_section
->output_offset
;
2568 outrel
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
2569 sreloc
= elf_section_data (input_section
)->sreloc
;
2572 loc
= sreloc
->contents
;
2573 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2574 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2578 case R_390_TLS_GD32
:
2579 case R_390_TLS_GOTIE32
:
2580 r_type
= elf_s390_tls_transition (info
, r_type
, h
== NULL
);
2581 tls_type
= GOT_UNKNOWN
;
2582 if (h
== NULL
&& local_got_offsets
)
2583 tls_type
= elf_s390_local_got_tls_type (input_bfd
) [r_symndx
];
2586 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2587 if (!info
->shared
&& h
->dynindx
== -1 && tls_type
>= GOT_TLS_IE
)
2588 r_type
= R_390_TLS_LE32
;
2590 if (r_type
== R_390_TLS_GD32
&& tls_type
>= GOT_TLS_IE
)
2591 r_type
= R_390_TLS_IE32
;
2593 if (r_type
== R_390_TLS_LE32
)
2595 /* This relocation gets optimized away by the local exec
2596 access optimization. */
2597 BFD_ASSERT (! unresolved_reloc
);
2598 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2599 contents
+ rel
->r_offset
);
2603 if (htab
->sgot
== NULL
)
2607 off
= h
->got
.offset
;
2610 if (local_got_offsets
== NULL
)
2613 off
= local_got_offsets
[r_symndx
];
2622 Elf_Internal_Rela outrel
;
2626 if (htab
->srelgot
== NULL
)
2629 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2630 + htab
->sgot
->output_offset
+ off
);
2632 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2633 if (r_type
== R_390_TLS_GD32
)
2634 dr_type
= R_390_TLS_DTPMOD
;
2636 dr_type
= R_390_TLS_TPOFF
;
2637 if (dr_type
== R_390_TLS_TPOFF
&& indx
== 0)
2638 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2640 outrel
.r_addend
= 0;
2641 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
2642 loc
= htab
->srelgot
->contents
;
2643 loc
+= htab
->srelgot
->reloc_count
++
2644 * sizeof (Elf32_External_Rela
);
2645 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2647 if (r_type
== R_390_TLS_GD32
)
2651 BFD_ASSERT (! unresolved_reloc
);
2652 bfd_put_32 (output_bfd
,
2653 relocation
- dtpoff_base (info
),
2654 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2658 outrel
.r_info
= ELF32_R_INFO (indx
, R_390_TLS_DTPOFF
);
2659 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
2660 outrel
.r_addend
= 0;
2661 htab
->srelgot
->reloc_count
++;
2662 loc
+= sizeof (Elf32_External_Rela
);
2663 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2670 local_got_offsets
[r_symndx
] |= 1;
2673 if (off
>= (bfd_vma
) -2)
2675 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
2677 relocation
= htab
->sgot
->output_offset
+ off
;
2678 if (r_type
== R_390_TLS_IE32
|| r_type
== R_390_TLS_IEENT
)
2679 relocation
+= htab
->sgot
->output_section
->vma
;
2680 unresolved_reloc
= FALSE
;
2684 bfd_put_32 (output_bfd
, htab
->sgot
->output_offset
+ off
,
2685 contents
+ rel
->r_offset
);
2690 case R_390_TLS_GOTIE12
:
2691 case R_390_TLS_IEENT
:
2694 if (local_got_offsets
== NULL
)
2696 off
= local_got_offsets
[r_symndx
];
2698 goto emit_tls_relocs
;
2702 off
= h
->got
.offset
;
2703 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2704 if (info
->shared
|| h
->dynindx
!= -1 || tls_type
< GOT_TLS_IE
)
2705 goto emit_tls_relocs
;
2708 if (htab
->sgot
== NULL
)
2711 BFD_ASSERT (! unresolved_reloc
);
2712 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2713 htab
->sgot
->contents
+ off
);
2714 relocation
= htab
->sgot
->output_offset
+ off
;
2715 if (r_type
== R_390_TLS_IEENT
)
2716 relocation
+= htab
->sgot
->output_section
->vma
;
2717 unresolved_reloc
= FALSE
;
2720 case R_390_TLS_LDM32
:
2722 /* The literal pool entry this relocation refers to gets ignored
2723 by the optimized code of the local exec model. Do nothing
2724 and the value will turn out zero. */
2727 if (htab
->sgot
== NULL
)
2730 off
= htab
->tls_ldm_got
.offset
;
2735 Elf_Internal_Rela outrel
;
2738 if (htab
->srelgot
== NULL
)
2741 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2742 + htab
->sgot
->output_offset
+ off
);
2744 bfd_put_32 (output_bfd
, 0,
2745 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2746 outrel
.r_info
= ELF32_R_INFO (0, R_390_TLS_DTPMOD
);
2747 outrel
.r_addend
= 0;
2748 loc
= htab
->srelgot
->contents
;
2749 loc
+= htab
->srelgot
->reloc_count
++
2750 * sizeof (Elf32_External_Rela
);
2751 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2752 htab
->tls_ldm_got
.offset
|= 1;
2754 relocation
= htab
->sgot
->output_offset
+ off
;
2755 unresolved_reloc
= FALSE
;
2758 case R_390_TLS_LE32
:
2761 /* Linking a shared library with non-fpic code requires
2762 a R_390_TLS_TPOFF relocation. */
2763 Elf_Internal_Rela outrel
;
2768 outrel
.r_offset
= rel
->r_offset
2769 + input_section
->output_section
->vma
2770 + input_section
->output_offset
;
2771 if (h
!= NULL
&& h
->dynindx
!= -1)
2775 outrel
.r_info
= ELF32_R_INFO (indx
, R_390_TLS_TPOFF
);
2777 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2779 outrel
.r_addend
= 0;
2780 sreloc
= elf_section_data (input_section
)->sreloc
;
2783 loc
= sreloc
->contents
;
2784 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2785 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2789 BFD_ASSERT (! unresolved_reloc
);
2790 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2791 contents
+ rel
->r_offset
);
2795 case R_390_TLS_LDO32
:
2796 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
2797 relocation
-= dtpoff_base (info
);
2799 /* When converting LDO to LE, we must negate. */
2800 relocation
= -tpoff (info
, relocation
);
2803 /* Relocations for tls instructions. */
2804 case R_390_TLS_LOAD
:
2805 case R_390_TLS_GDCALL
:
2806 case R_390_TLS_LDCALL
:
2807 tls_type
= GOT_UNKNOWN
;
2808 if (h
== NULL
&& local_got_offsets
)
2809 tls_type
= elf_s390_local_got_tls_type (input_bfd
) [r_symndx
];
2811 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2813 if (tls_type
== GOT_TLS_GD
)
2816 if (r_type
== R_390_TLS_LOAD
)
2818 if (!info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
2820 /* IE->LE transition. Four valid cases:
2821 l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0
2822 l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0
2823 l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0
2824 l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */
2825 unsigned int insn
, ry
;
2827 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2829 if ((insn
& 0xff00f000) == 0x58000000)
2830 /* l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0 */
2831 ry
= (insn
& 0x000f0000);
2832 else if ((insn
& 0xff0f0000) == 0x58000000)
2833 /* l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0 */
2834 ry
= (insn
& 0x0000f000) << 4;
2835 else if ((insn
& 0xff00f000) == 0x5800c000)
2836 /* l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0 */
2837 ry
= (insn
& 0x000f0000);
2838 else if ((insn
& 0xff0f0000) == 0x580c0000)
2839 /* l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */
2840 ry
= (insn
& 0x0000f000) << 4;
2842 invalid_tls_insn (input_bfd
, input_section
, rel
);
2843 insn
= 0x18000700 | (insn
& 0x00f00000) | ry
;
2844 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
2847 else if (r_type
== R_390_TLS_GDCALL
)
2851 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2852 if ((insn
& 0xff000fff) != 0x4d000000)
2853 invalid_tls_insn (input_bfd
, input_section
, rel
);
2854 if (!info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
2855 /* GD->LE transition.
2856 bas %r14,0(%rx,%r13) -> bc 0,0 */
2859 /* GD->IE transition.
2860 bas %r14,0(%rx,%r13) -> l %r2,0(%r2,%r12) */
2862 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
2864 else if (r_type
== R_390_TLS_LDCALL
)
2870 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2871 if ((insn
& 0xff000fff) != 0x4d000000)
2872 invalid_tls_insn (input_bfd
, input_section
, rel
);
2873 /* LD->LE transition.
2874 bas %r14,0(%rx,%r13) -> bc 0,0 */
2876 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
2885 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2886 because such sections are not SEC_ALLOC and thus ld.so will
2887 not process them. */
2888 if (unresolved_reloc
2889 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
2890 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2891 (*_bfd_error_handler
)
2892 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
2893 bfd_archive_filename (input_bfd
),
2894 bfd_get_section_name (input_bfd
, input_section
),
2895 (long) rel
->r_offset
,
2896 h
->root
.root
.string
);
2898 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2899 contents
, rel
->r_offset
,
2900 relocation
, rel
->r_addend
);
2902 if (r
!= bfd_reloc_ok
)
2907 name
= h
->root
.root
.string
;
2910 name
= bfd_elf_string_from_elf_section (input_bfd
,
2911 symtab_hdr
->sh_link
,
2916 name
= bfd_section_name (input_bfd
, sec
);
2919 if (r
== bfd_reloc_overflow
)
2922 if (! ((*info
->callbacks
->reloc_overflow
)
2923 (info
, name
, howto
->name
, (bfd_vma
) 0,
2924 input_bfd
, input_section
, rel
->r_offset
)))
2929 (*_bfd_error_handler
)
2930 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
2931 bfd_archive_filename (input_bfd
),
2932 bfd_get_section_name (input_bfd
, input_section
),
2933 (long) rel
->r_offset
, name
, (int) r
);
2942 /* Finish up dynamic symbol handling. We set the contents of various
2943 dynamic sections here. */
2946 elf_s390_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2948 struct bfd_link_info
*info
;
2949 struct elf_link_hash_entry
*h
;
2950 Elf_Internal_Sym
*sym
;
2952 struct elf_s390_link_hash_table
*htab
;
2954 htab
= elf_s390_hash_table (info
);
2956 if (h
->plt
.offset
!= (bfd_vma
) -1)
2960 Elf_Internal_Rela rela
;
2962 bfd_vma relative_offset
;
2964 /* This symbol has an entry in the procedure linkage table. Set
2966 if (h
->dynindx
== -1
2967 || htab
->splt
== NULL
2968 || htab
->sgotplt
== NULL
2969 || htab
->srelplt
== NULL
)
2973 Current offset - size first entry / entry size. */
2974 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
2976 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2978 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2980 /* S390 uses halfwords for relative branch calc! */
2981 relative_offset
= - ((PLT_FIRST_ENTRY_SIZE
+
2982 (PLT_ENTRY_SIZE
* plt_index
) + 18) / 2);
2983 /* If offset is > 32768, branch to a previous branch
2984 390 can only handle +-64 K jumps. */
2985 if ( -32768 > (int) relative_offset
)
2987 = -(unsigned) (((65536 / PLT_ENTRY_SIZE
- 1) * PLT_ENTRY_SIZE
) / 2);
2989 /* Fill in the entry in the procedure linkage table. */
2992 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD0
,
2993 htab
->splt
->contents
+ h
->plt
.offset
);
2994 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD1
,
2995 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
2996 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD2
,
2997 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
2998 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD3
,
2999 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3000 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD4
,
3001 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3002 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3003 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3004 bfd_put_32 (output_bfd
,
3005 (htab
->sgotplt
->output_section
->vma
3006 + htab
->sgotplt
->output_offset
3008 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3010 else if (got_offset
< 4096)
3012 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD0
+ got_offset
,
3013 htab
->splt
->contents
+ h
->plt
.offset
);
3014 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD1
,
3015 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3016 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD2
,
3017 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3018 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD3
,
3019 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3020 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD4
,
3021 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3022 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3023 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3024 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3025 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3027 else if (got_offset
< 32768)
3029 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD0
+ got_offset
,
3030 htab
->splt
->contents
+ h
->plt
.offset
);
3031 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD1
,
3032 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3033 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD2
,
3034 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3035 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD3
,
3036 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3037 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD4
,
3038 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3039 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3040 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3041 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3042 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3046 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD0
,
3047 htab
->splt
->contents
+ h
->plt
.offset
);
3048 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD1
,
3049 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3050 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD2
,
3051 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3052 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD3
,
3053 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3054 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD4
,
3055 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3056 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3057 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3058 bfd_put_32 (output_bfd
, got_offset
,
3059 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3061 /* Insert offset into reloc. table here. */
3062 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
3063 htab
->splt
->contents
+ h
->plt
.offset
+ 28);
3065 /* Fill in the entry in the global offset table.
3066 Points to instruction after GOT offset. */
3067 bfd_put_32 (output_bfd
,
3068 (htab
->splt
->output_section
->vma
3069 + htab
->splt
->output_offset
3072 htab
->sgotplt
->contents
+ got_offset
);
3074 /* Fill in the entry in the .rela.plt section. */
3075 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
3076 + htab
->sgotplt
->output_offset
3078 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_390_JMP_SLOT
);
3080 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
3081 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3083 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3085 /* Mark the symbol as undefined, rather than as defined in
3086 the .plt section. Leave the value alone. This is a clue
3087 for the dynamic linker, to make function pointer
3088 comparisons work between an application and shared
3090 sym
->st_shndx
= SHN_UNDEF
;
3094 if (h
->got
.offset
!= (bfd_vma
) -1
3095 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_GD
3096 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_IE
3097 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_IE_NLT
)
3099 Elf_Internal_Rela rela
;
3102 /* This symbol has an entry in the global offset table. Set it
3105 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3108 rela
.r_offset
= (htab
->sgot
->output_section
->vma
3109 + htab
->sgot
->output_offset
3110 + (h
->got
.offset
&~ (bfd_vma
) 1));
3112 /* If this is a static link, or it is a -Bsymbolic link and the
3113 symbol is defined locally or was forced to be local because
3114 of a version file, we just want to emit a RELATIVE reloc.
3115 The entry in the global offset table will already have been
3116 initialized in the relocate_section function. */
3120 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
3121 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3123 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3124 rela
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
3125 rela
.r_addend
= (h
->root
.u
.def
.value
3126 + h
->root
.u
.def
.section
->output_section
->vma
3127 + h
->root
.u
.def
.section
->output_offset
);
3131 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3132 bfd_put_32 (output_bfd
, (bfd_vma
) 0, htab
->sgot
->contents
+ h
->got
.offset
);
3133 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_390_GLOB_DAT
);
3137 loc
= htab
->srelgot
->contents
;
3138 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3139 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3142 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3144 Elf_Internal_Rela rela
;
3147 /* This symbols needs a copy reloc. Set it up. */
3149 if (h
->dynindx
== -1
3150 || (h
->root
.type
!= bfd_link_hash_defined
3151 && h
->root
.type
!= bfd_link_hash_defweak
)
3152 || htab
->srelbss
== NULL
)
3155 rela
.r_offset
= (h
->root
.u
.def
.value
3156 + h
->root
.u
.def
.section
->output_section
->vma
3157 + h
->root
.u
.def
.section
->output_offset
);
3158 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_390_COPY
);
3160 loc
= htab
->srelbss
->contents
;
3161 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3162 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3165 /* Mark some specially defined symbols as absolute. */
3166 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3167 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3168 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3169 sym
->st_shndx
= SHN_ABS
;
3174 /* Used to decide how to sort relocs in an optimal manner for the
3175 dynamic linker, before writing them out. */
3177 static enum elf_reloc_type_class
3178 elf_s390_reloc_type_class (rela
)
3179 const Elf_Internal_Rela
*rela
;
3181 switch ((int) ELF32_R_TYPE (rela
->r_info
))
3183 case R_390_RELATIVE
:
3184 return reloc_class_relative
;
3185 case R_390_JMP_SLOT
:
3186 return reloc_class_plt
;
3188 return reloc_class_copy
;
3190 return reloc_class_normal
;
3194 /* Finish up the dynamic sections. */
3197 elf_s390_finish_dynamic_sections (output_bfd
, info
)
3199 struct bfd_link_info
*info
;
3201 struct elf_s390_link_hash_table
*htab
;
3205 htab
= elf_s390_hash_table (info
);
3206 dynobj
= htab
->elf
.dynobj
;
3207 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3209 if (htab
->elf
.dynamic_sections_created
)
3211 Elf32_External_Dyn
*dyncon
, *dynconend
;
3213 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3216 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3217 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3218 for (; dyncon
< dynconend
; dyncon
++)
3220 Elf_Internal_Dyn dyn
;
3223 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3231 dyn
.d_un
.d_ptr
= htab
->sgot
->output_section
->vma
;
3235 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
3239 s
= htab
->srelplt
->output_section
;
3240 if (s
->_cooked_size
!= 0)
3241 dyn
.d_un
.d_val
= s
->_cooked_size
;
3243 dyn
.d_un
.d_val
= s
->_raw_size
;
3247 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3250 /* Fill in the special first entry in the procedure linkage table. */
3251 if (htab
->splt
&& htab
->splt
->_raw_size
> 0)
3253 memset (htab
->splt
->contents
, 0, PLT_FIRST_ENTRY_SIZE
);
3256 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD0
,
3257 htab
->splt
->contents
);
3258 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD1
,
3259 htab
->splt
->contents
+4 );
3260 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD2
,
3261 htab
->splt
->contents
+8 );
3262 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD3
,
3263 htab
->splt
->contents
+12 );
3264 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD4
,
3265 htab
->splt
->contents
+16 );
3269 bfd_put_32 (output_bfd
, (bfd_vma
)PLT_FIRST_ENTRY_WORD0
,
3270 htab
->splt
->contents
);
3271 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD1
,
3272 htab
->splt
->contents
+4 );
3273 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD2
,
3274 htab
->splt
->contents
+8 );
3275 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD3
,
3276 htab
->splt
->contents
+12 );
3277 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD4
,
3278 htab
->splt
->contents
+16 );
3279 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD5
,
3280 htab
->splt
->contents
+20 );
3281 bfd_put_32 (output_bfd
,
3282 htab
->sgotplt
->output_section
->vma
3283 + htab
->sgotplt
->output_offset
,
3284 htab
->splt
->contents
+ 24);
3286 elf_section_data (htab
->splt
->output_section
)
3287 ->this_hdr
.sh_entsize
= 4;
3294 /* Fill in the first three entries in the global offset table. */
3295 if (htab
->sgotplt
->_raw_size
> 0)
3297 bfd_put_32 (output_bfd
,
3298 (sdyn
== NULL
? (bfd_vma
) 0
3299 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
3300 htab
->sgotplt
->contents
);
3301 /* One entry for shared object struct ptr. */
3302 bfd_put_32 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 4);
3303 /* One entry for _dl_runtime_resolve. */
3304 bfd_put_32 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 8);
3307 elf_section_data (htab
->sgotplt
->output_section
)
3308 ->this_hdr
.sh_entsize
= 4;
3314 elf_s390_grok_prstatus (abfd
, note
)
3316 Elf_Internal_Note
* note
;
3319 unsigned int raw_size
;
3321 switch (note
->descsz
)
3326 case 224: /* S/390 Linux. */
3328 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3331 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3339 /* Make a ".reg/999" section. */
3340 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
3341 raw_size
, note
->descpos
+ offset
);
3344 #define TARGET_BIG_SYM bfd_elf32_s390_vec
3345 #define TARGET_BIG_NAME "elf32-s390"
3346 #define ELF_ARCH bfd_arch_s390
3347 #define ELF_MACHINE_CODE EM_S390
3348 #define ELF_MACHINE_ALT1 EM_S390_OLD
3349 #define ELF_MAXPAGESIZE 0x1000
3351 #define elf_backend_can_gc_sections 1
3352 #define elf_backend_can_refcount 1
3353 #define elf_backend_want_got_plt 1
3354 #define elf_backend_plt_readonly 1
3355 #define elf_backend_want_plt_sym 0
3356 #define elf_backend_got_header_size 12
3357 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
3358 #define elf_backend_rela_normal 1
3360 #define elf_info_to_howto elf_s390_info_to_howto
3362 #define bfd_elf32_bfd_is_local_label_name elf_s390_is_local_label_name
3363 #define bfd_elf32_bfd_link_hash_table_create elf_s390_link_hash_table_create
3364 #define bfd_elf32_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
3366 #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
3367 #define elf_backend_check_relocs elf_s390_check_relocs
3368 #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
3369 #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
3370 #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
3371 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
3372 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
3373 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
3374 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3375 #define elf_backend_relocate_section elf_s390_relocate_section
3376 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
3377 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3378 #define elf_backend_grok_prstatus elf_s390_grok_prstatus
3380 #define bfd_elf32_mkobject elf_s390_mkobject
3381 #define elf_backend_object_p elf_s390_object_p
3383 #include "elf32-target.h"