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
;
1330 unsigned long r_symndx
;
1332 struct elf_link_hash_entry
*h
;
1334 elf_section_data (sec
)->local_dynrel
= NULL
;
1336 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1337 sym_hashes
= elf_sym_hashes (abfd
);
1338 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1340 relend
= relocs
+ sec
->reloc_count
;
1341 for (rel
= relocs
; rel
< relend
; rel
++)
1343 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1345 if (r_symndx
< symtab_hdr
->sh_info
)
1348 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1350 r_type
= elf_s390_tls_transition (info
,
1351 ELF32_R_TYPE (rel
->r_info
),
1352 r_symndx
>= symtab_hdr
->sh_info
);
1355 case R_390_TLS_LDM32
:
1356 if (elf_s390_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1357 elf_s390_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1360 case R_390_TLS_GD32
:
1361 case R_390_TLS_IE32
:
1362 case R_390_TLS_GOTIE12
:
1363 case R_390_TLS_GOTIE32
:
1364 case R_390_TLS_IEENT
:
1368 case R_390_GOTOFF16
:
1369 case R_390_GOTOFF32
:
1371 case R_390_GOTPCDBL
:
1375 if (h
->got
.refcount
> 0)
1376 h
->got
.refcount
-= 1;
1378 else if (local_got_refcounts
!= NULL
)
1380 if (local_got_refcounts
[r_symndx
] > 0)
1381 local_got_refcounts
[r_symndx
] -= 1;
1383 if (r_type
!= R_390_TLS_IE32
)
1387 case R_390_TLS_LE32
:
1402 struct elf_s390_link_hash_entry
*eh
;
1403 struct elf_s390_dyn_relocs
**pp
;
1404 struct elf_s390_dyn_relocs
*p
;
1406 if (!info
->shared
&& h
->plt
.refcount
> 0)
1407 h
->plt
.refcount
-= 1;
1409 eh
= (struct elf_s390_link_hash_entry
*) h
;
1411 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1414 if (ELF32_R_TYPE (rel
->r_info
) == R_390_PC16
1415 || ELF32_R_TYPE (rel
->r_info
) == R_390_PC16DBL
1416 || ELF32_R_TYPE (rel
->r_info
) == R_390_PC32DBL
1417 || ELF32_R_TYPE (rel
->r_info
) == R_390_PC32
)
1427 case R_390_PLT16DBL
:
1428 case R_390_PLT32DBL
:
1430 case R_390_PLTOFF16
:
1431 case R_390_PLTOFF32
:
1434 if (h
->plt
.refcount
> 0)
1435 h
->plt
.refcount
-= 1;
1439 case R_390_GOTPLT12
:
1440 case R_390_GOTPLT16
:
1441 case R_390_GOTPLT32
:
1442 case R_390_GOTPLTENT
:
1445 if (h
->plt
.refcount
> 0)
1447 ((struct elf_s390_link_hash_entry
*) h
)->gotplt_refcount
--;
1448 h
->plt
.refcount
-= 1;
1451 else if (local_got_refcounts
!= NULL
)
1453 if (local_got_refcounts
[r_symndx
] > 0)
1454 local_got_refcounts
[r_symndx
] -= 1;
1466 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1467 entry but we found we will not create any. Called when we find we will
1468 not have any PLT for this symbol, by for example
1469 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
1470 or elf_s390_size_dynamic_sections if no dynamic sections will be
1471 created (we're only linking static objects). */
1474 elf_s390_adjust_gotplt (h
)
1475 struct elf_s390_link_hash_entry
*h
;
1477 if (h
->elf
.root
.type
== bfd_link_hash_warning
)
1478 h
= (struct elf_s390_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
1480 if (h
->gotplt_refcount
<= 0)
1483 /* We simply add the number of gotplt references to the number
1484 * of got references for this symbol. */
1485 h
->elf
.got
.refcount
+= h
->gotplt_refcount
;
1486 h
->gotplt_refcount
= -1;
1489 /* Adjust a symbol defined by a dynamic object and referenced by a
1490 regular object. The current definition is in some section of the
1491 dynamic object, but we're not including those sections. We have to
1492 change the definition to something the rest of the link can
1496 elf_s390_adjust_dynamic_symbol (info
, h
)
1497 struct bfd_link_info
*info
;
1498 struct elf_link_hash_entry
*h
;
1500 struct elf_s390_link_hash_table
*htab
;
1501 struct elf_s390_link_hash_entry
* eh
;
1502 struct elf_s390_dyn_relocs
*p
;
1504 unsigned int power_of_two
;
1506 /* If this is a function, put it in the procedure linkage table. We
1507 will fill in the contents of the procedure linkage table later
1508 (although we could actually do it here). */
1509 if (h
->type
== STT_FUNC
1510 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1512 if (h
->plt
.refcount
<= 0
1514 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1515 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
1516 && h
->root
.type
!= bfd_link_hash_undefweak
1517 && h
->root
.type
!= bfd_link_hash_undefined
))
1519 /* This case can occur if we saw a PLT32 reloc in an input
1520 file, but the symbol was never referred to by a dynamic
1521 object, or if all references were garbage collected. In
1522 such a case, we don't actually need to build a procedure
1523 linkage table, and we can just do a PC32 reloc instead. */
1524 h
->plt
.offset
= (bfd_vma
) -1;
1525 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1526 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1532 /* It's possible that we incorrectly decided a .plt reloc was
1533 needed for an R_390_PC32 reloc to a non-function sym in
1534 check_relocs. We can't decide accurately between function and
1535 non-function syms in check-relocs; Objects loaded later in
1536 the link may change h->type. So fix it now. */
1537 h
->plt
.offset
= (bfd_vma
) -1;
1539 /* If this is a weak symbol, and there is a real definition, the
1540 processor independent code will have arranged for us to see the
1541 real definition first, and we can just use the same value. */
1542 if (h
->weakdef
!= NULL
)
1544 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1545 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1546 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1547 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1551 /* This is a reference to a symbol defined by a dynamic object which
1552 is not a function. */
1554 /* If we are creating a shared library, we must presume that the
1555 only references to the symbol are via the global offset table.
1556 For such cases we need not do anything here; the relocations will
1557 be handled correctly by relocate_section. */
1561 /* If there are no references to this symbol that do not use the
1562 GOT, we don't need to generate a copy reloc. */
1563 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1566 /* If -z nocopyreloc was given, we won't generate them either. */
1567 if (info
->nocopyreloc
)
1569 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1573 eh
= (struct elf_s390_link_hash_entry
*) h
;
1574 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1576 s
= p
->sec
->output_section
;
1577 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1581 /* If we didn't find any dynamic relocs in read-only sections, then
1582 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1585 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1589 /* We must allocate the symbol in our .dynbss section, which will
1590 become part of the .bss section of the executable. There will be
1591 an entry for this symbol in the .dynsym section. The dynamic
1592 object will contain position independent code, so all references
1593 from the dynamic object to this symbol will go through the global
1594 offset table. The dynamic linker will use the .dynsym entry to
1595 determine the address it must put in the global offset table, so
1596 both the dynamic object and the regular object will refer to the
1597 same memory location for the variable. */
1599 htab
= elf_s390_hash_table (info
);
1601 /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1602 copy the initial value out of the dynamic object and into the
1603 runtime process image. */
1604 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1606 htab
->srelbss
->_raw_size
+= sizeof (Elf32_External_Rela
);
1607 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1610 /* We need to figure out the alignment required for this symbol. I
1611 have no idea how ELF linkers handle this. */
1612 power_of_two
= bfd_log2 (h
->size
);
1613 if (power_of_two
> 3)
1616 /* Apply the required alignment. */
1618 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
1619 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1621 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1625 /* Define the symbol as being at this point in the section. */
1626 h
->root
.u
.def
.section
= s
;
1627 h
->root
.u
.def
.value
= s
->_raw_size
;
1629 /* Increment the section size to make room for the symbol. */
1630 s
->_raw_size
+= h
->size
;
1635 /* This is the condition under which elf_s390_finish_dynamic_symbol
1636 will be called from elflink.h. If elflink.h doesn't call our
1637 finish_dynamic_symbol routine, we'll need to do something about
1638 initializing any .plt and .got entries in elf_s390_relocate_section. */
1639 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1641 && ((INFO)->shared \
1642 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1643 && ((H)->dynindx != -1 \
1644 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1646 /* Allocate space in .plt, .got and associated reloc sections for
1650 allocate_dynrelocs (h
, inf
)
1651 struct elf_link_hash_entry
*h
;
1654 struct bfd_link_info
*info
;
1655 struct elf_s390_link_hash_table
*htab
;
1656 struct elf_s390_link_hash_entry
*eh
;
1657 struct elf_s390_dyn_relocs
*p
;
1659 if (h
->root
.type
== bfd_link_hash_indirect
)
1662 if (h
->root
.type
== bfd_link_hash_warning
)
1663 /* When warning symbols are created, they **replace** the "real"
1664 entry in the hash table, thus we never get to see the real
1665 symbol in a hash traversal. So look at it now. */
1666 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1668 info
= (struct bfd_link_info
*) inf
;
1669 htab
= elf_s390_hash_table (info
);
1671 if (htab
->elf
.dynamic_sections_created
1672 && h
->plt
.refcount
> 0)
1674 /* Make sure this symbol is output as a dynamic symbol.
1675 Undefined weak syms won't yet be marked as dynamic. */
1676 if (h
->dynindx
== -1
1677 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1679 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1683 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
1685 asection
*s
= htab
->splt
;
1687 /* If this is the first .plt entry, make room for the special
1689 if (s
->_raw_size
== 0)
1690 s
->_raw_size
+= PLT_FIRST_ENTRY_SIZE
;
1692 h
->plt
.offset
= s
->_raw_size
;
1694 /* If this symbol is not defined in a regular file, and we are
1695 not generating a shared library, then set the symbol to this
1696 location in the .plt. This is required to make function
1697 pointers compare as equal between the normal executable and
1698 the shared library. */
1700 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1702 h
->root
.u
.def
.section
= s
;
1703 h
->root
.u
.def
.value
= h
->plt
.offset
;
1706 /* Make room for this entry. */
1707 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1709 /* We also need to make an entry in the .got.plt section, which
1710 will be placed in the .got section by the linker script. */
1711 htab
->sgotplt
->_raw_size
+= GOT_ENTRY_SIZE
;
1713 /* We also need to make an entry in the .rela.plt section. */
1714 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
1718 h
->plt
.offset
= (bfd_vma
) -1;
1719 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1720 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1725 h
->plt
.offset
= (bfd_vma
) -1;
1726 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1727 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1730 /* If R_390_TLS_{IE32,GOTIE32,GOTIE12,IEENT} symbol is now local to
1731 the binary, we can optimize a bit. IE32 and GOTIE32 get converted
1732 to R_390_TLS_LE32 requiring no TLS entry. For GOTIE12 and IEENT
1733 we can save the dynamic TLS relocation. */
1734 if (h
->got
.refcount
> 0
1737 && elf_s390_hash_entry(h
)->tls_type
>= GOT_TLS_IE
)
1739 if (elf_s390_hash_entry(h
)->tls_type
== GOT_TLS_IE_NLT
)
1740 /* For the GOTIE access without a literal pool entry the offset has
1741 to be stored somewhere. The immediate value in the instruction
1742 is not bit enough so the value is stored in the got. */
1744 h
->got
.offset
= htab
->sgot
->_raw_size
;
1745 htab
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1748 h
->got
.offset
= (bfd_vma
) -1;
1750 else if (h
->got
.refcount
> 0)
1754 int tls_type
= elf_s390_hash_entry(h
)->tls_type
;
1756 /* Make sure this symbol is output as a dynamic symbol.
1757 Undefined weak syms won't yet be marked as dynamic. */
1758 if (h
->dynindx
== -1
1759 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1761 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1766 h
->got
.offset
= s
->_raw_size
;
1767 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1768 /* R_390_TLS_GD32 needs 2 consecutive GOT slots. */
1769 if (tls_type
== GOT_TLS_GD
)
1770 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1771 dyn
= htab
->elf
.dynamic_sections_created
;
1772 /* R_390_TLS_IE32 needs one dynamic relocation,
1773 R_390_TLS_GD32 needs one if local symbol and two if global. */
1774 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
1775 || tls_type
>= GOT_TLS_IE
)
1776 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1777 else if (tls_type
== GOT_TLS_GD
)
1778 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf32_External_Rela
);
1779 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
1780 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1783 h
->got
.offset
= (bfd_vma
) -1;
1785 eh
= (struct elf_s390_link_hash_entry
*) h
;
1786 if (eh
->dyn_relocs
== NULL
)
1789 /* In the shared -Bsymbolic case, discard space allocated for
1790 dynamic pc-relative relocs against symbols which turn out to be
1791 defined in regular objects. For the normal shared case, discard
1792 space for pc-relative relocs that have become local due to symbol
1793 visibility changes. */
1797 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1798 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
1801 struct elf_s390_dyn_relocs
**pp
;
1803 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1805 p
->count
-= p
->pc_count
;
1816 /* For the non-shared case, discard space for relocs against
1817 symbols which turn out to need copy relocs or are not
1820 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1821 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1822 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1823 || (htab
->elf
.dynamic_sections_created
1824 && (h
->root
.type
== bfd_link_hash_undefweak
1825 || h
->root
.type
== bfd_link_hash_undefined
))))
1827 /* Make sure this symbol is output as a dynamic symbol.
1828 Undefined weak syms won't yet be marked as dynamic. */
1829 if (h
->dynindx
== -1
1830 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1832 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1836 /* If that succeeded, we know we'll be keeping all the
1838 if (h
->dynindx
!= -1)
1842 eh
->dyn_relocs
= NULL
;
1847 /* Finally, allocate space. */
1848 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1850 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1852 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
1858 /* Find any dynamic relocs that apply to read-only sections. */
1861 readonly_dynrelocs (h
, inf
)
1862 struct elf_link_hash_entry
*h
;
1865 struct elf_s390_link_hash_entry
*eh
;
1866 struct elf_s390_dyn_relocs
*p
;
1868 if (h
->root
.type
== bfd_link_hash_warning
)
1869 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1871 eh
= (struct elf_s390_link_hash_entry
*) h
;
1872 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1874 asection
*s
= p
->sec
->output_section
;
1876 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1878 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1880 info
->flags
|= DF_TEXTREL
;
1882 /* Not an error, just cut short the traversal. */
1889 /* Set the sizes of the dynamic sections. */
1892 elf_s390_size_dynamic_sections (output_bfd
, info
)
1893 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1894 struct bfd_link_info
*info
;
1896 struct elf_s390_link_hash_table
*htab
;
1902 htab
= elf_s390_hash_table (info
);
1903 dynobj
= htab
->elf
.dynobj
;
1907 if (htab
->elf
.dynamic_sections_created
)
1909 /* Set the contents of the .interp section to the interpreter. */
1912 s
= bfd_get_section_by_name (dynobj
, ".interp");
1915 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1916 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1920 /* Set up .got offsets for local syms, and space for local dynamic
1922 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1924 bfd_signed_vma
*local_got
;
1925 bfd_signed_vma
*end_local_got
;
1926 char *local_tls_type
;
1927 bfd_size_type locsymcount
;
1928 Elf_Internal_Shdr
*symtab_hdr
;
1931 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1934 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1936 struct elf_s390_dyn_relocs
*p
;
1938 for (p
= *((struct elf_s390_dyn_relocs
**)
1939 &elf_section_data (s
)->local_dynrel
);
1943 if (!bfd_is_abs_section (p
->sec
)
1944 && bfd_is_abs_section (p
->sec
->output_section
))
1946 /* Input section has been discarded, either because
1947 it is a copy of a linkonce section or due to
1948 linker script /DISCARD/, so we'll be discarding
1951 else if (p
->count
!= 0)
1953 srela
= elf_section_data (p
->sec
)->sreloc
;
1954 srela
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
1955 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1956 info
->flags
|= DF_TEXTREL
;
1961 local_got
= elf_local_got_refcounts (ibfd
);
1965 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1966 locsymcount
= symtab_hdr
->sh_info
;
1967 end_local_got
= local_got
+ locsymcount
;
1968 local_tls_type
= elf_s390_local_got_tls_type (ibfd
);
1970 srela
= htab
->srelgot
;
1971 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
1975 *local_got
= s
->_raw_size
;
1976 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1977 if (*local_tls_type
== GOT_TLS_GD
)
1978 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1980 srela
->_raw_size
+= sizeof (Elf32_External_Rela
);
1983 *local_got
= (bfd_vma
) -1;
1987 if (htab
->tls_ldm_got
.refcount
> 0)
1989 /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM32
1991 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
1992 htab
->sgot
->_raw_size
+= 2 * GOT_ENTRY_SIZE
;
1993 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1996 htab
->tls_ldm_got
.offset
= -1;
1998 /* Allocate global sym .plt and .got entries, and space for global
1999 sym dynamic relocs. */
2000 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
2002 /* We now have determined the sizes of the various dynamic sections.
2003 Allocate memory for them. */
2005 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2007 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2012 || s
== htab
->sgotplt
)
2014 /* Strip this section if we don't need it; see the
2017 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
2019 if (s
->_raw_size
!= 0)
2022 /* We use the reloc_count field as a counter if we need
2023 to copy relocs into the output file. */
2028 /* It's not one of our sections, so don't allocate space. */
2032 if (s
->_raw_size
== 0)
2034 /* If we don't need this section, strip it from the
2035 output file. This is to handle .rela.bss and
2036 .rela.plt. We must create it in
2037 create_dynamic_sections, because it must be created
2038 before the linker maps input sections to output
2039 sections. The linker does that before
2040 adjust_dynamic_symbol is called, and it is that
2041 function which decides whether anything needs to go
2042 into these sections. */
2044 _bfd_strip_section_from_output (info
, s
);
2048 /* Allocate memory for the section contents. We use bfd_zalloc
2049 here in case unused entries are not reclaimed before the
2050 section's contents are written out. This should not happen,
2051 but this way if it does, we get a R_390_NONE reloc instead
2053 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2054 if (s
->contents
== NULL
)
2058 if (htab
->elf
.dynamic_sections_created
)
2060 /* Add some entries to the .dynamic section. We fill in the
2061 values later, in elf_s390_finish_dynamic_sections, but we
2062 must add the entries now so that we get the correct size for
2063 the .dynamic section. The DT_DEBUG entry is filled in by the
2064 dynamic linker and used by the debugger. */
2065 #define add_dynamic_entry(TAG, VAL) \
2066 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2070 if (!add_dynamic_entry (DT_DEBUG
, 0))
2074 if (htab
->splt
->_raw_size
!= 0)
2076 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2077 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2078 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2079 || !add_dynamic_entry (DT_JMPREL
, 0))
2085 if (!add_dynamic_entry (DT_RELA
, 0)
2086 || !add_dynamic_entry (DT_RELASZ
, 0)
2087 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
2090 /* If any dynamic relocs apply to a read-only section,
2091 then we need a DT_TEXTREL entry. */
2092 if ((info
->flags
& DF_TEXTREL
) == 0)
2093 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2096 if ((info
->flags
& DF_TEXTREL
) != 0)
2098 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2103 #undef add_dynamic_entry
2108 /* Return the base VMA address which should be subtracted from real addresses
2109 when resolving @dtpoff relocation.
2110 This is PT_TLS segment p_vaddr. */
2114 struct bfd_link_info
*info
;
2116 /* If tls_segment is NULL, we should have signalled an error already. */
2117 if (elf_hash_table (info
)->tls_segment
== NULL
)
2119 return elf_hash_table (info
)->tls_segment
->start
;
2122 /* Return the relocation value for @tpoff relocation
2123 if STT_TLS virtual address is ADDRESS. */
2126 tpoff (info
, address
)
2127 struct bfd_link_info
*info
;
2130 struct elf_link_tls_segment
*tls_segment
2131 = elf_hash_table (info
)->tls_segment
;
2133 /* If tls_segment is NULL, we should have signalled an error already. */
2134 if (tls_segment
== NULL
)
2136 return (align_power (tls_segment
->size
, tls_segment
->align
)
2137 + tls_segment
->start
- address
);
2140 /* Complain if TLS instruction relocation is against an invalid
2144 invalid_tls_insn (input_bfd
, input_section
, rel
)
2146 asection
*input_section
;
2147 Elf_Internal_Rela
*rel
;
2149 reloc_howto_type
*howto
;
2151 howto
= elf_howto_table
+ ELF32_R_TYPE (rel
->r_info
);
2152 (*_bfd_error_handler
)
2153 (_("%s(%s+0x%lx): invalid instruction for TLS relocation %s"),
2154 bfd_archive_filename (input_bfd
),
2155 bfd_get_section_name (input_bfd
, input_section
),
2156 (long) rel
->r_offset
,
2160 /* Relocate a 390 ELF section. */
2163 elf_s390_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2164 contents
, relocs
, local_syms
, local_sections
)
2166 struct bfd_link_info
*info
;
2168 asection
*input_section
;
2170 Elf_Internal_Rela
*relocs
;
2171 Elf_Internal_Sym
*local_syms
;
2172 asection
**local_sections
;
2174 struct elf_s390_link_hash_table
*htab
;
2175 Elf_Internal_Shdr
*symtab_hdr
;
2176 struct elf_link_hash_entry
**sym_hashes
;
2177 bfd_vma
*local_got_offsets
;
2178 Elf_Internal_Rela
*rel
;
2179 Elf_Internal_Rela
*relend
;
2181 if (info
->relocateable
)
2184 htab
= elf_s390_hash_table (info
);
2185 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2186 sym_hashes
= elf_sym_hashes (input_bfd
);
2187 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2190 relend
= relocs
+ input_section
->reloc_count
;
2191 for (; rel
< relend
; rel
++)
2193 unsigned int r_type
;
2194 reloc_howto_type
*howto
;
2195 unsigned long r_symndx
;
2196 struct elf_link_hash_entry
*h
;
2197 Elf_Internal_Sym
*sym
;
2201 bfd_boolean unresolved_reloc
;
2202 bfd_reloc_status_type r
;
2205 r_type
= ELF32_R_TYPE (rel
->r_info
);
2206 if (r_type
== (int) R_390_GNU_VTINHERIT
2207 || r_type
== (int) R_390_GNU_VTENTRY
)
2209 if (r_type
>= (int) R_390_max
)
2211 bfd_set_error (bfd_error_bad_value
);
2215 howto
= elf_howto_table
+ r_type
;
2216 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2218 /* This is a final link. */
2222 unresolved_reloc
= FALSE
;
2223 if (r_symndx
< symtab_hdr
->sh_info
)
2225 sym
= local_syms
+ r_symndx
;
2226 sec
= local_sections
[r_symndx
];
2227 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
2231 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2232 while (h
->root
.type
== bfd_link_hash_indirect
2233 || h
->root
.type
== bfd_link_hash_warning
)
2234 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2236 if (h
->root
.type
== bfd_link_hash_defined
2237 || h
->root
.type
== bfd_link_hash_defweak
)
2239 sec
= h
->root
.u
.def
.section
;
2240 if (sec
->output_section
== NULL
)
2242 /* Set a flag that will be cleared later if we find a
2243 relocation value for this symbol. output_section
2244 is typically NULL for symbols satisfied by a shared
2246 unresolved_reloc
= TRUE
;
2250 relocation
= (h
->root
.u
.def
.value
2251 + sec
->output_section
->vma
2252 + sec
->output_offset
);
2254 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2256 else if (info
->shared
2257 && !info
->no_undefined
2258 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2262 if (! ((*info
->callbacks
->undefined_symbol
)
2263 (info
, h
->root
.root
.string
, input_bfd
,
2264 input_section
, rel
->r_offset
,
2265 (!info
->shared
|| info
->no_undefined
2266 || ELF_ST_VISIBILITY (h
->other
)))))
2274 case R_390_GOTPLT12
:
2275 case R_390_GOTPLT16
:
2276 case R_390_GOTPLT32
:
2277 case R_390_GOTPLTENT
:
2278 /* There are three cases for a GOTPLT relocation. 1) The
2279 relocation is against the jump slot entry of a plt that
2280 will get emitted to the output file. 2) The relocation
2281 is against the jump slot of a plt entry that has been
2282 removed. elf_s390_adjust_gotplt has created a GOT entry
2283 as replacement. 3) The relocation is against a local symbol.
2284 Cases 2) and 3) are the same as the GOT relocation code
2285 so we just have to test for case 1 and fall through for
2287 if (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
2292 Current offset - size first entry / entry size. */
2293 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) /
2296 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2298 relocation
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2299 unresolved_reloc
= FALSE
;
2301 if (r_type
== R_390_GOTPLTENT
)
2302 relocation
+= htab
->sgot
->output_section
->vma
;
2311 /* Relocation is to the entry for this symbol in the global
2313 if (htab
->sgot
== NULL
)
2320 off
= h
->got
.offset
;
2321 dyn
= htab
->elf
.dynamic_sections_created
;
2322 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
2326 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
2327 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2329 /* This is actually a static link, or it is a
2330 -Bsymbolic link and the symbol is defined
2331 locally, or the symbol was forced to be local
2332 because of a version file. We must initialize
2333 this entry in the global offset table. Since the
2334 offset must always be a multiple of 2, we use the
2335 least significant bit to record whether we have
2336 initialized it already.
2338 When doing a dynamic link, we create a .rel.got
2339 relocation entry to initialize the value. This
2340 is done in the finish_dynamic_symbol routine. */
2345 bfd_put_32 (output_bfd
, relocation
,
2346 htab
->sgot
->contents
+ off
);
2351 unresolved_reloc
= FALSE
;
2355 if (local_got_offsets
== NULL
)
2358 off
= local_got_offsets
[r_symndx
];
2360 /* The offset must always be a multiple of 4. We use
2361 the least significant bit to record whether we have
2362 already generated the necessary reloc. */
2367 bfd_put_32 (output_bfd
, relocation
,
2368 htab
->sgot
->contents
+ off
);
2373 Elf_Internal_Rela outrel
;
2376 srelgot
= htab
->srelgot
;
2377 if (srelgot
== NULL
)
2380 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2381 + htab
->sgot
->output_offset
2383 outrel
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
2384 outrel
.r_addend
= relocation
;
2385 loc
= srelgot
->contents
;
2386 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2387 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2390 local_got_offsets
[r_symndx
] |= 1;
2394 if (off
>= (bfd_vma
) -2)
2397 relocation
= htab
->sgot
->output_offset
+ off
;
2399 /* For @GOTENT the relocation is against the offset between
2400 the instruction and the symbols entry in the GOT and not
2401 between the start of the GOT and the symbols entry. We
2402 add the vma of the GOT to get the correct value. */
2403 if ( r_type
== R_390_GOTENT
2404 || r_type
== R_390_GOTPLTENT
)
2405 relocation
+= htab
->sgot
->output_section
->vma
;
2409 case R_390_GOTOFF16
:
2410 case R_390_GOTOFF32
:
2411 /* Relocation is relative to the start of the global offset
2414 /* Note that sgot->output_offset is not involved in this
2415 calculation. We always want the start of .got. If we
2416 defined _GLOBAL_OFFSET_TABLE in a different way, as is
2417 permitted by the ABI, we might have to change this
2419 relocation
-= htab
->sgot
->output_section
->vma
;
2423 case R_390_GOTPCDBL
:
2424 /* Use global offset table as symbol value. */
2425 relocation
= htab
->sgot
->output_section
->vma
;
2426 unresolved_reloc
= FALSE
;
2429 case R_390_PLT16DBL
:
2430 case R_390_PLT32DBL
:
2432 /* Relocation is to the entry for this symbol in the
2433 procedure linkage table. */
2435 /* Resolve a PLT32 reloc against a local symbol directly,
2436 without using the procedure linkage table. */
2440 if (h
->plt
.offset
== (bfd_vma
) -1
2441 || htab
->splt
== NULL
)
2443 /* We didn't make a PLT entry for this symbol. This
2444 happens when statically linking PIC code, or when
2445 using -Bsymbolic. */
2449 relocation
= (htab
->splt
->output_section
->vma
2450 + htab
->splt
->output_offset
2452 unresolved_reloc
= FALSE
;
2455 case R_390_PLTOFF16
:
2456 case R_390_PLTOFF32
:
2457 /* Relocation is to the entry for this symbol in the
2458 procedure linkage table relative to the start of the GOT. */
2460 /* For local symbols or if we didn't make a PLT entry for
2461 this symbol resolve the symbol directly. */
2463 || h
->plt
.offset
== (bfd_vma
) -1
2464 || htab
->splt
== NULL
)
2466 relocation
-= htab
->sgot
->output_section
->vma
;
2470 relocation
= (htab
->splt
->output_section
->vma
2471 + htab
->splt
->output_offset
2473 - htab
->sgot
->output_section
->vma
);
2474 unresolved_reloc
= FALSE
;
2484 /* r_symndx will be zero only for relocs against symbols
2485 from removed linkonce sections, or sections discarded by
2488 || (input_section
->flags
& SEC_ALLOC
) == 0)
2492 && ((r_type
!= R_390_PC16
2493 && r_type
!= R_390_PC16DBL
2494 && r_type
!= R_390_PC32DBL
2495 && r_type
!= R_390_PC32
)
2498 && (! info
->symbolic
2499 || (h
->elf_link_hash_flags
2500 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2504 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2505 && (((h
->elf_link_hash_flags
2506 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2507 && (h
->elf_link_hash_flags
2508 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2509 || h
->root
.type
== bfd_link_hash_undefweak
2510 || h
->root
.type
== bfd_link_hash_undefined
)))
2512 Elf_Internal_Rela outrel
;
2513 bfd_boolean skip
, relocate
;
2517 /* When generating a shared object, these relocations
2518 are copied into the output file to be resolved at run
2525 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2527 if (outrel
.r_offset
== (bfd_vma
) -1)
2529 else if (outrel
.r_offset
== (bfd_vma
) -2)
2530 skip
= TRUE
, relocate
= TRUE
;
2531 outrel
.r_offset
+= (input_section
->output_section
->vma
2532 + input_section
->output_offset
);
2535 memset (&outrel
, 0, sizeof outrel
);
2538 && (r_type
== R_390_PC16
2539 || r_type
== R_390_PC16DBL
2540 || r_type
== R_390_PC32DBL
2541 || r_type
== R_390_PC32
2544 || (h
->elf_link_hash_flags
2545 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2547 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2548 outrel
.r_addend
= rel
->r_addend
;
2552 /* This symbol is local, or marked to become local. */
2554 outrel
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
2555 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2558 sreloc
= elf_section_data (input_section
)->sreloc
;
2562 loc
= sreloc
->contents
;
2563 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2564 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2566 /* If this reloc is against an external symbol, we do
2567 not want to fiddle with the addend. Otherwise, we
2568 need to include the symbol value so that it becomes
2569 an addend for the dynamic reloc. */
2575 /* Relocations for tls literal pool entries. */
2576 case R_390_TLS_IE32
:
2579 Elf_Internal_Rela outrel
;
2583 outrel
.r_offset
= rel
->r_offset
2584 + input_section
->output_section
->vma
2585 + input_section
->output_offset
;
2586 outrel
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
2587 sreloc
= elf_section_data (input_section
)->sreloc
;
2590 loc
= sreloc
->contents
;
2591 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2592 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2596 case R_390_TLS_GD32
:
2597 case R_390_TLS_GOTIE32
:
2598 r_type
= elf_s390_tls_transition (info
, r_type
, h
== NULL
);
2599 tls_type
= GOT_UNKNOWN
;
2600 if (h
== NULL
&& local_got_offsets
)
2601 tls_type
= elf_s390_local_got_tls_type (input_bfd
) [r_symndx
];
2604 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2605 if (!info
->shared
&& h
->dynindx
== -1 && tls_type
>= GOT_TLS_IE
)
2606 r_type
= R_390_TLS_LE32
;
2608 if (r_type
== R_390_TLS_GD32
&& tls_type
>= GOT_TLS_IE
)
2609 r_type
= R_390_TLS_IE32
;
2611 if (r_type
== R_390_TLS_LE32
)
2613 /* This relocation gets optimized away by the local exec
2614 access optimization. */
2615 BFD_ASSERT (! unresolved_reloc
);
2616 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2617 contents
+ rel
->r_offset
);
2621 if (htab
->sgot
== NULL
)
2625 off
= h
->got
.offset
;
2628 if (local_got_offsets
== NULL
)
2631 off
= local_got_offsets
[r_symndx
];
2640 Elf_Internal_Rela outrel
;
2644 if (htab
->srelgot
== NULL
)
2647 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2648 + htab
->sgot
->output_offset
+ off
);
2650 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2651 if (r_type
== R_390_TLS_GD32
)
2652 dr_type
= R_390_TLS_DTPMOD
;
2654 dr_type
= R_390_TLS_TPOFF
;
2655 if (dr_type
== R_390_TLS_TPOFF
&& indx
== 0)
2656 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2658 outrel
.r_addend
= 0;
2659 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
2660 loc
= htab
->srelgot
->contents
;
2661 loc
+= htab
->srelgot
->reloc_count
++
2662 * sizeof (Elf32_External_Rela
);
2663 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2665 if (r_type
== R_390_TLS_GD32
)
2669 BFD_ASSERT (! unresolved_reloc
);
2670 bfd_put_32 (output_bfd
,
2671 relocation
- dtpoff_base (info
),
2672 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2676 outrel
.r_info
= ELF32_R_INFO (indx
, R_390_TLS_DTPOFF
);
2677 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
2678 outrel
.r_addend
= 0;
2679 htab
->srelgot
->reloc_count
++;
2680 loc
+= sizeof (Elf32_External_Rela
);
2681 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2688 local_got_offsets
[r_symndx
] |= 1;
2691 if (off
>= (bfd_vma
) -2)
2693 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
2695 relocation
= htab
->sgot
->output_offset
+ off
;
2696 if (r_type
== R_390_TLS_IE32
|| r_type
== R_390_TLS_IEENT
)
2697 relocation
+= htab
->sgot
->output_section
->vma
;
2698 unresolved_reloc
= FALSE
;
2702 bfd_put_32 (output_bfd
, htab
->sgot
->output_offset
+ off
,
2703 contents
+ rel
->r_offset
);
2708 case R_390_TLS_GOTIE12
:
2709 case R_390_TLS_IEENT
:
2712 if (local_got_offsets
== NULL
)
2714 off
= local_got_offsets
[r_symndx
];
2716 goto emit_tls_relocs
;
2720 off
= h
->got
.offset
;
2721 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2722 if (info
->shared
|| h
->dynindx
!= -1 || tls_type
< GOT_TLS_IE
)
2723 goto emit_tls_relocs
;
2726 if (htab
->sgot
== NULL
)
2729 BFD_ASSERT (! unresolved_reloc
);
2730 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2731 htab
->sgot
->contents
+ off
);
2732 relocation
= htab
->sgot
->output_offset
+ off
;
2733 if (r_type
== R_390_TLS_IEENT
)
2734 relocation
+= htab
->sgot
->output_section
->vma
;
2735 unresolved_reloc
= FALSE
;
2738 case R_390_TLS_LDM32
:
2740 /* The literal pool entry this relocation refers to gets ignored
2741 by the optimized code of the local exec model. Do nothing
2742 and the value will turn out zero. */
2745 if (htab
->sgot
== NULL
)
2748 off
= htab
->tls_ldm_got
.offset
;
2753 Elf_Internal_Rela outrel
;
2756 if (htab
->srelgot
== NULL
)
2759 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2760 + htab
->sgot
->output_offset
+ off
);
2762 bfd_put_32 (output_bfd
, 0,
2763 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2764 outrel
.r_info
= ELF32_R_INFO (0, R_390_TLS_DTPMOD
);
2765 outrel
.r_addend
= 0;
2766 loc
= htab
->srelgot
->contents
;
2767 loc
+= htab
->srelgot
->reloc_count
++
2768 * sizeof (Elf32_External_Rela
);
2769 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2770 htab
->tls_ldm_got
.offset
|= 1;
2772 relocation
= htab
->sgot
->output_offset
+ off
;
2773 unresolved_reloc
= FALSE
;
2776 case R_390_TLS_LE32
:
2779 /* Linking a shared library with non-fpic code requires
2780 a R_390_TLS_TPOFF relocation. */
2781 Elf_Internal_Rela outrel
;
2786 outrel
.r_offset
= rel
->r_offset
2787 + input_section
->output_section
->vma
2788 + input_section
->output_offset
;
2789 if (h
!= NULL
&& h
->dynindx
!= -1)
2793 outrel
.r_info
= ELF32_R_INFO (indx
, R_390_TLS_TPOFF
);
2795 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2797 outrel
.r_addend
= 0;
2798 sreloc
= elf_section_data (input_section
)->sreloc
;
2801 loc
= sreloc
->contents
;
2802 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2803 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
2807 BFD_ASSERT (! unresolved_reloc
);
2808 bfd_put_32 (output_bfd
, -tpoff (info
, relocation
),
2809 contents
+ rel
->r_offset
);
2813 case R_390_TLS_LDO32
:
2814 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
2815 relocation
-= dtpoff_base (info
);
2817 /* When converting LDO to LE, we must negate. */
2818 relocation
= -tpoff (info
, relocation
);
2821 /* Relocations for tls instructions. */
2822 case R_390_TLS_LOAD
:
2823 case R_390_TLS_GDCALL
:
2824 case R_390_TLS_LDCALL
:
2825 tls_type
= GOT_UNKNOWN
;
2826 if (h
== NULL
&& local_got_offsets
)
2827 tls_type
= elf_s390_local_got_tls_type (input_bfd
) [r_symndx
];
2829 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2831 if (tls_type
== GOT_TLS_GD
)
2834 if (r_type
== R_390_TLS_LOAD
)
2836 if (!info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
2838 /* IE->LE transition. Four valid cases:
2839 l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0
2840 l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0
2841 l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0
2842 l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */
2843 unsigned int insn
, ry
;
2845 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2847 if ((insn
& 0xff00f000) == 0x58000000)
2848 /* l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0 */
2849 ry
= (insn
& 0x000f0000);
2850 else if ((insn
& 0xff0f0000) == 0x58000000)
2851 /* l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0 */
2852 ry
= (insn
& 0x0000f000) << 4;
2853 else if ((insn
& 0xff00f000) == 0x5800c000)
2854 /* l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0 */
2855 ry
= (insn
& 0x000f0000);
2856 else if ((insn
& 0xff0f0000) == 0x580c0000)
2857 /* l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */
2858 ry
= (insn
& 0x0000f000) << 4;
2860 invalid_tls_insn (input_bfd
, input_section
, rel
);
2861 insn
= 0x18000700 | (insn
& 0x00f00000) | ry
;
2862 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
2865 else if (r_type
== R_390_TLS_GDCALL
)
2869 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2870 if ((insn
& 0xff000fff) != 0x4d000000)
2871 invalid_tls_insn (input_bfd
, input_section
, rel
);
2872 if (!info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
2873 /* GD->LE transition.
2874 bas %r14,0(%rx,%r13) -> bc 0,0 */
2877 /* GD->IE transition.
2878 bas %r14,0(%rx,%r13) -> l %r2,0(%r2,%r12) */
2880 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
2882 else if (r_type
== R_390_TLS_LDCALL
)
2888 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2889 if ((insn
& 0xff000fff) != 0x4d000000)
2890 invalid_tls_insn (input_bfd
, input_section
, rel
);
2891 /* LD->LE transition.
2892 bas %r14,0(%rx,%r13) -> bc 0,0 */
2894 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
2903 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2904 because such sections are not SEC_ALLOC and thus ld.so will
2905 not process them. */
2906 if (unresolved_reloc
2907 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
2908 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2909 (*_bfd_error_handler
)
2910 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
2911 bfd_archive_filename (input_bfd
),
2912 bfd_get_section_name (input_bfd
, input_section
),
2913 (long) rel
->r_offset
,
2914 h
->root
.root
.string
);
2916 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2917 contents
, rel
->r_offset
,
2918 relocation
, rel
->r_addend
);
2920 if (r
!= bfd_reloc_ok
)
2925 name
= h
->root
.root
.string
;
2928 name
= bfd_elf_string_from_elf_section (input_bfd
,
2929 symtab_hdr
->sh_link
,
2934 name
= bfd_section_name (input_bfd
, sec
);
2937 if (r
== bfd_reloc_overflow
)
2940 if (! ((*info
->callbacks
->reloc_overflow
)
2941 (info
, name
, howto
->name
, (bfd_vma
) 0,
2942 input_bfd
, input_section
, rel
->r_offset
)))
2947 (*_bfd_error_handler
)
2948 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
2949 bfd_archive_filename (input_bfd
),
2950 bfd_get_section_name (input_bfd
, input_section
),
2951 (long) rel
->r_offset
, name
, (int) r
);
2960 /* Finish up dynamic symbol handling. We set the contents of various
2961 dynamic sections here. */
2964 elf_s390_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2966 struct bfd_link_info
*info
;
2967 struct elf_link_hash_entry
*h
;
2968 Elf_Internal_Sym
*sym
;
2970 struct elf_s390_link_hash_table
*htab
;
2972 htab
= elf_s390_hash_table (info
);
2974 if (h
->plt
.offset
!= (bfd_vma
) -1)
2978 Elf_Internal_Rela rela
;
2980 bfd_vma relative_offset
;
2982 /* This symbol has an entry in the procedure linkage table. Set
2984 if (h
->dynindx
== -1
2985 || htab
->splt
== NULL
2986 || htab
->sgotplt
== NULL
2987 || htab
->srelplt
== NULL
)
2991 Current offset - size first entry / entry size. */
2992 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
2994 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2996 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2998 /* S390 uses halfwords for relative branch calc! */
2999 relative_offset
= - ((PLT_FIRST_ENTRY_SIZE
+
3000 (PLT_ENTRY_SIZE
* plt_index
) + 18) / 2);
3001 /* If offset is > 32768, branch to a previous branch
3002 390 can only handle +-64 K jumps. */
3003 if ( -32768 > (int) relative_offset
)
3005 -(unsigned) (((65536 / PLT_ENTRY_SIZE
- 1) * PLT_ENTRY_SIZE
) / 2);
3007 /* Fill in the entry in the procedure linkage table. */
3010 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD0
,
3011 htab
->splt
->contents
+ h
->plt
.offset
);
3012 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD1
,
3013 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3014 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD2
,
3015 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3016 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD3
,
3017 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3018 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD4
,
3019 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3020 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3021 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3022 bfd_put_32 (output_bfd
,
3023 (htab
->sgotplt
->output_section
->vma
3024 + htab
->sgotplt
->output_offset
3026 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3028 else if (got_offset
< 4096)
3030 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD0
+ got_offset
,
3031 htab
->splt
->contents
+ h
->plt
.offset
);
3032 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD1
,
3033 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3034 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD2
,
3035 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3036 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD3
,
3037 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3038 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC12_ENTRY_WORD4
,
3039 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3040 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3041 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3042 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3043 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3045 else if (got_offset
< 32768)
3047 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD0
+ got_offset
,
3048 htab
->splt
->contents
+ h
->plt
.offset
);
3049 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD1
,
3050 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3051 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD2
,
3052 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3053 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD3
,
3054 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3055 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC16_ENTRY_WORD4
,
3056 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3057 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3058 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3059 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3060 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3064 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD0
,
3065 htab
->splt
->contents
+ h
->plt
.offset
);
3066 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD1
,
3067 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3068 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD2
,
3069 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3070 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD3
,
3071 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3072 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_ENTRY_WORD4
,
3073 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3074 bfd_put_32 (output_bfd
, (bfd_vma
) 0+(relative_offset
<< 16),
3075 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3076 bfd_put_32 (output_bfd
, got_offset
,
3077 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3079 /* Insert offset into reloc. table here. */
3080 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
3081 htab
->splt
->contents
+ h
->plt
.offset
+ 28);
3083 /* Fill in the entry in the global offset table.
3084 Points to instruction after GOT offset. */
3085 bfd_put_32 (output_bfd
,
3086 (htab
->splt
->output_section
->vma
3087 + htab
->splt
->output_offset
3090 htab
->sgotplt
->contents
+ got_offset
);
3092 /* Fill in the entry in the .rela.plt section. */
3093 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
3094 + htab
->sgotplt
->output_offset
3096 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_390_JMP_SLOT
);
3098 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
3099 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3101 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3103 /* Mark the symbol as undefined, rather than as defined in
3104 the .plt section. Leave the value alone. This is a clue
3105 for the dynamic linker, to make function pointer
3106 comparisons work between an application and shared
3108 sym
->st_shndx
= SHN_UNDEF
;
3112 if (h
->got
.offset
!= (bfd_vma
) -1
3113 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_GD
3114 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_IE
3115 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_IE_NLT
)
3117 Elf_Internal_Rela rela
;
3120 /* This symbol has an entry in the global offset table. Set it
3123 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3126 rela
.r_offset
= (htab
->sgot
->output_section
->vma
3127 + htab
->sgot
->output_offset
3128 + (h
->got
.offset
&~ (bfd_vma
) 1));
3130 /* If this is a static link, or it is a -Bsymbolic link and the
3131 symbol is defined locally or was forced to be local because
3132 of a version file, we just want to emit a RELATIVE reloc.
3133 The entry in the global offset table will already have been
3134 initialized in the relocate_section function. */
3138 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
3139 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3141 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3142 rela
.r_info
= ELF32_R_INFO (0, R_390_RELATIVE
);
3143 rela
.r_addend
= (h
->root
.u
.def
.value
3144 + h
->root
.u
.def
.section
->output_section
->vma
3145 + h
->root
.u
.def
.section
->output_offset
);
3149 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3150 bfd_put_32 (output_bfd
, (bfd_vma
) 0, htab
->sgot
->contents
+ h
->got
.offset
);
3151 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_390_GLOB_DAT
);
3155 loc
= htab
->srelgot
->contents
;
3156 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3157 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3160 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3162 Elf_Internal_Rela rela
;
3165 /* This symbols needs a copy reloc. Set it up. */
3167 if (h
->dynindx
== -1
3168 || (h
->root
.type
!= bfd_link_hash_defined
3169 && h
->root
.type
!= bfd_link_hash_defweak
)
3170 || htab
->srelbss
== NULL
)
3173 rela
.r_offset
= (h
->root
.u
.def
.value
3174 + h
->root
.u
.def
.section
->output_section
->vma
3175 + h
->root
.u
.def
.section
->output_offset
);
3176 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_390_COPY
);
3178 loc
= htab
->srelbss
->contents
;
3179 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3180 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3183 /* Mark some specially defined symbols as absolute. */
3184 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3185 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3186 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3187 sym
->st_shndx
= SHN_ABS
;
3192 /* Used to decide how to sort relocs in an optimal manner for the
3193 dynamic linker, before writing them out. */
3195 static enum elf_reloc_type_class
3196 elf_s390_reloc_type_class (rela
)
3197 const Elf_Internal_Rela
*rela
;
3199 switch ((int) ELF32_R_TYPE (rela
->r_info
))
3201 case R_390_RELATIVE
:
3202 return reloc_class_relative
;
3203 case R_390_JMP_SLOT
:
3204 return reloc_class_plt
;
3206 return reloc_class_copy
;
3208 return reloc_class_normal
;
3212 /* Finish up the dynamic sections. */
3215 elf_s390_finish_dynamic_sections (output_bfd
, info
)
3217 struct bfd_link_info
*info
;
3219 struct elf_s390_link_hash_table
*htab
;
3223 htab
= elf_s390_hash_table (info
);
3224 dynobj
= htab
->elf
.dynobj
;
3225 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3227 if (htab
->elf
.dynamic_sections_created
)
3229 Elf32_External_Dyn
*dyncon
, *dynconend
;
3231 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3234 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3235 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3236 for (; dyncon
< dynconend
; dyncon
++)
3238 Elf_Internal_Dyn dyn
;
3241 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3249 dyn
.d_un
.d_ptr
= htab
->sgot
->output_section
->vma
;
3253 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
3257 s
= htab
->srelplt
->output_section
;
3258 if (s
->_cooked_size
!= 0)
3259 dyn
.d_un
.d_val
= s
->_cooked_size
;
3261 dyn
.d_un
.d_val
= s
->_raw_size
;
3265 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3268 /* Fill in the special first entry in the procedure linkage table. */
3269 if (htab
->splt
&& htab
->splt
->_raw_size
> 0)
3271 memset (htab
->splt
->contents
, 0, PLT_FIRST_ENTRY_SIZE
);
3274 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD0
,
3275 htab
->splt
->contents
);
3276 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD1
,
3277 htab
->splt
->contents
+4 );
3278 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD2
,
3279 htab
->splt
->contents
+8 );
3280 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD3
,
3281 htab
->splt
->contents
+12 );
3282 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_PIC_FIRST_ENTRY_WORD4
,
3283 htab
->splt
->contents
+16 );
3287 bfd_put_32 (output_bfd
, (bfd_vma
)PLT_FIRST_ENTRY_WORD0
,
3288 htab
->splt
->contents
);
3289 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD1
,
3290 htab
->splt
->contents
+4 );
3291 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD2
,
3292 htab
->splt
->contents
+8 );
3293 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD3
,
3294 htab
->splt
->contents
+12 );
3295 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD4
,
3296 htab
->splt
->contents
+16 );
3297 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD5
,
3298 htab
->splt
->contents
+20 );
3299 bfd_put_32 (output_bfd
,
3300 htab
->sgotplt
->output_section
->vma
3301 + htab
->sgotplt
->output_offset
,
3302 htab
->splt
->contents
+ 24);
3304 elf_section_data (htab
->splt
->output_section
)
3305 ->this_hdr
.sh_entsize
= 4;
3312 /* Fill in the first three entries in the global offset table. */
3313 if (htab
->sgotplt
->_raw_size
> 0)
3315 bfd_put_32 (output_bfd
,
3316 (sdyn
== NULL
? (bfd_vma
) 0
3317 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
3318 htab
->sgotplt
->contents
);
3319 /* One entry for shared object struct ptr. */
3320 bfd_put_32 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 4);
3321 /* One entry for _dl_runtime_resolve. */
3322 bfd_put_32 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 8);
3325 elf_section_data (htab
->sgotplt
->output_section
)
3326 ->this_hdr
.sh_entsize
= 4;
3332 elf_s390_grok_prstatus (abfd
, note
)
3334 Elf_Internal_Note
* note
;
3337 unsigned int raw_size
;
3339 switch (note
->descsz
)
3344 case 224: /* S/390 Linux. */
3346 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3349 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3357 /* Make a ".reg/999" section. */
3358 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
3359 raw_size
, note
->descpos
+ offset
);
3362 #define TARGET_BIG_SYM bfd_elf32_s390_vec
3363 #define TARGET_BIG_NAME "elf32-s390"
3364 #define ELF_ARCH bfd_arch_s390
3365 #define ELF_MACHINE_CODE EM_S390
3366 #define ELF_MACHINE_ALT1 EM_S390_OLD
3367 #define ELF_MAXPAGESIZE 0x1000
3369 #define elf_backend_can_gc_sections 1
3370 #define elf_backend_can_refcount 1
3371 #define elf_backend_want_got_plt 1
3372 #define elf_backend_plt_readonly 1
3373 #define elf_backend_want_plt_sym 0
3374 #define elf_backend_got_header_size 12
3375 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
3376 #define elf_backend_rela_normal 1
3378 #define elf_info_to_howto elf_s390_info_to_howto
3380 #define bfd_elf32_bfd_is_local_label_name elf_s390_is_local_label_name
3381 #define bfd_elf32_bfd_link_hash_table_create elf_s390_link_hash_table_create
3382 #define bfd_elf32_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
3384 #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
3385 #define elf_backend_check_relocs elf_s390_check_relocs
3386 #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
3387 #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
3388 #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
3389 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
3390 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
3391 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
3392 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3393 #define elf_backend_relocate_section elf_s390_relocate_section
3394 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
3395 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3396 #define elf_backend_grok_prstatus elf_s390_grok_prstatus
3398 #define bfd_elf32_mkobject elf_s390_mkobject
3399 #define elf_backend_object_p elf_s390_object_p
3401 #include "elf32-target.h"