1 /* IBM S/390-specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed Martin Schwidefsky (schwidefsky@de.ibm.com).
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 static reloc_howto_type
*elf_s390_reloc_type_lookup
29 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
30 static void elf_s390_info_to_howto
31 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
32 static bfd_boolean elf_s390_is_local_label_name
33 PARAMS ((bfd
*, const char *));
34 static struct bfd_hash_entry
*link_hash_newfunc
35 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
36 static struct bfd_link_hash_table
*elf_s390_link_hash_table_create
38 static bfd_boolean create_got_section
39 PARAMS((bfd
*, struct bfd_link_info
*));
40 static bfd_boolean elf_s390_create_dynamic_sections
41 PARAMS((bfd
*, struct bfd_link_info
*));
42 static void elf_s390_copy_indirect_symbol
43 PARAMS ((struct elf_backend_data
*, struct elf_link_hash_entry
*,
44 struct elf_link_hash_entry
*));
45 static bfd_boolean elf_s390_check_relocs
46 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
47 const Elf_Internal_Rela
*));
48 static asection
*elf_s390_gc_mark_hook
49 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
50 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
51 static bfd_boolean elf_s390_gc_sweep_hook
52 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
53 const Elf_Internal_Rela
*));
54 struct elf_s390_link_hash_entry
;
55 static void elf_s390_adjust_gotplt
56 PARAMS ((struct elf_s390_link_hash_entry
*));
57 static bfd_boolean elf_s390_adjust_dynamic_symbol
58 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
59 static bfd_boolean allocate_dynrelocs
60 PARAMS ((struct elf_link_hash_entry
*, PTR
));
61 static bfd_boolean readonly_dynrelocs
62 PARAMS ((struct elf_link_hash_entry
*, PTR
));
63 static bfd_boolean elf_s390_size_dynamic_sections
64 PARAMS ((bfd
*, struct bfd_link_info
*));
65 static bfd_boolean elf_s390_relocate_section
66 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
67 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
68 static bfd_boolean elf_s390_finish_dynamic_symbol
69 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
71 static enum elf_reloc_type_class elf_s390_reloc_type_class
72 PARAMS ((const Elf_Internal_Rela
*));
73 static bfd_boolean elf_s390_finish_dynamic_sections
74 PARAMS ((bfd
*, struct bfd_link_info
*));
75 static bfd_boolean elf_s390_mkobject
77 static bfd_boolean elf_s390_object_p
79 static int elf_s390_tls_transition
80 PARAMS ((struct bfd_link_info
*, int, int));
81 static bfd_reloc_status_type s390_tls_reloc
82 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
83 static bfd_vma dtpoff_base
84 PARAMS ((struct bfd_link_info
*));
86 PARAMS ((struct bfd_link_info
*, bfd_vma
));
87 static void invalid_tls_insn
88 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*));
92 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
93 from smaller values. Start with zero, widen, *then* decrement. */
94 #define MINUS_ONE (((bfd_vma)0) - 1)
96 /* The relocation "howto" table. */
97 static reloc_howto_type elf_howto_table
[] =
99 HOWTO (R_390_NONE
, /* type */
101 0, /* size (0 = byte, 1 = short, 2 = long) */
103 FALSE
, /* pc_relative */
105 complain_overflow_dont
, /* complain_on_overflow */
106 bfd_elf_generic_reloc
, /* special_function */
107 "R_390_NONE", /* name */
108 FALSE
, /* partial_inplace */
111 FALSE
), /* pcrel_offset */
113 HOWTO(R_390_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
114 bfd_elf_generic_reloc
, "R_390_8", FALSE
, 0,0x000000ff, FALSE
),
115 HOWTO(R_390_12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
116 bfd_elf_generic_reloc
, "R_390_12", FALSE
, 0,0x00000fff, FALSE
),
117 HOWTO(R_390_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
118 bfd_elf_generic_reloc
, "R_390_16", FALSE
, 0,0x0000ffff, FALSE
),
119 HOWTO(R_390_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_390_32", FALSE
, 0,0xffffffff, FALSE
),
121 HOWTO(R_390_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
122 bfd_elf_generic_reloc
, "R_390_PC32", FALSE
, 0,0xffffffff, TRUE
),
123 HOWTO(R_390_GOT12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
124 bfd_elf_generic_reloc
, "R_390_GOT12", FALSE
, 0,0x00000fff, FALSE
),
125 HOWTO(R_390_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
126 bfd_elf_generic_reloc
, "R_390_GOT32", FALSE
, 0,0xffffffff, FALSE
),
127 HOWTO(R_390_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_390_PLT32", FALSE
, 0,0xffffffff, TRUE
),
129 HOWTO(R_390_COPY
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_390_COPY", FALSE
, 0,MINUS_ONE
, FALSE
),
131 HOWTO(R_390_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
132 bfd_elf_generic_reloc
, "R_390_GLOB_DAT", FALSE
, 0,MINUS_ONE
, FALSE
),
133 HOWTO(R_390_JMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
134 bfd_elf_generic_reloc
, "R_390_JMP_SLOT", FALSE
, 0,MINUS_ONE
, FALSE
),
135 HOWTO(R_390_RELATIVE
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
136 bfd_elf_generic_reloc
, "R_390_RELATIVE", FALSE
, 0,MINUS_ONE
, FALSE
),
137 HOWTO(R_390_GOTOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
138 bfd_elf_generic_reloc
, "R_390_GOTOFF32", FALSE
, 0,MINUS_ONE
, FALSE
),
139 HOWTO(R_390_GOTPC
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
140 bfd_elf_generic_reloc
, "R_390_GOTPC", FALSE
, 0,MINUS_ONE
, TRUE
),
141 HOWTO(R_390_GOT16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
142 bfd_elf_generic_reloc
, "R_390_GOT16", FALSE
, 0,0x0000ffff, FALSE
),
143 HOWTO(R_390_PC16
, 0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
144 bfd_elf_generic_reloc
, "R_390_PC16", FALSE
, 0,0x0000ffff, TRUE
),
145 HOWTO(R_390_PC16DBL
, 1, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
146 bfd_elf_generic_reloc
, "R_390_PC16DBL", FALSE
, 0,0x0000ffff, TRUE
),
147 HOWTO(R_390_PLT16DBL
, 1, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
148 bfd_elf_generic_reloc
, "R_390_PLT16DBL", FALSE
, 0,0x0000ffff, TRUE
),
149 HOWTO(R_390_PC32DBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
150 bfd_elf_generic_reloc
, "R_390_PC32DBL", FALSE
, 0,0xffffffff, TRUE
),
151 HOWTO(R_390_PLT32DBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
152 bfd_elf_generic_reloc
, "R_390_PLT32DBL", FALSE
, 0,0xffffffff, TRUE
),
153 HOWTO(R_390_GOTPCDBL
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
154 bfd_elf_generic_reloc
, "R_390_GOTPCDBL", FALSE
, 0,MINUS_ONE
, TRUE
),
155 HOWTO(R_390_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
156 bfd_elf_generic_reloc
, "R_390_64", FALSE
, 0,MINUS_ONE
, FALSE
),
157 HOWTO(R_390_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
158 bfd_elf_generic_reloc
, "R_390_PC64", FALSE
, 0,MINUS_ONE
, TRUE
),
159 HOWTO(R_390_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
160 bfd_elf_generic_reloc
, "R_390_GOT64", FALSE
, 0,MINUS_ONE
, FALSE
),
161 HOWTO(R_390_PLT64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
162 bfd_elf_generic_reloc
, "R_390_PLT64", FALSE
, 0,MINUS_ONE
, TRUE
),
163 HOWTO(R_390_GOTENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
164 bfd_elf_generic_reloc
, "R_390_GOTENT", FALSE
, 0,MINUS_ONE
, TRUE
),
165 HOWTO(R_390_GOTOFF16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
166 bfd_elf_generic_reloc
, "R_390_GOTOFF16", FALSE
, 0,0x0000ffff, FALSE
),
167 HOWTO(R_390_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
168 bfd_elf_generic_reloc
, "R_390_GOTOFF64", FALSE
, 0,MINUS_ONE
, FALSE
),
169 HOWTO(R_390_GOTPLT12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
170 bfd_elf_generic_reloc
, "R_390_GOTPLT12", FALSE
, 0,0x00000fff, FALSE
),
171 HOWTO(R_390_GOTPLT16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
172 bfd_elf_generic_reloc
, "R_390_GOTPLT16", FALSE
, 0,0x0000ffff, FALSE
),
173 HOWTO(R_390_GOTPLT32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
174 bfd_elf_generic_reloc
, "R_390_GOTPLT32", FALSE
, 0,0xffffffff, FALSE
),
175 HOWTO(R_390_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
176 bfd_elf_generic_reloc
, "R_390_GOTPLT64", FALSE
, 0,MINUS_ONE
, FALSE
),
177 HOWTO(R_390_GOTPLTENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
178 bfd_elf_generic_reloc
, "R_390_GOTPLTENT",FALSE
, 0,MINUS_ONE
, TRUE
),
179 HOWTO(R_390_PLTOFF16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
180 bfd_elf_generic_reloc
, "R_390_PLTOFF16", FALSE
, 0,0x0000ffff, FALSE
),
181 HOWTO(R_390_PLTOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
182 bfd_elf_generic_reloc
, "R_390_PLTOFF32", FALSE
, 0,0xffffffff, FALSE
),
183 HOWTO(R_390_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
184 bfd_elf_generic_reloc
, "R_390_PLTOFF64", FALSE
, 0,MINUS_ONE
, FALSE
),
185 HOWTO(R_390_TLS_LOAD
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
186 s390_tls_reloc
, "R_390_TLS_LOAD", FALSE
, 0, 0, FALSE
),
187 HOWTO(R_390_TLS_GDCALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
188 s390_tls_reloc
, "R_390_TLS_GDCALL", FALSE
, 0, 0, FALSE
),
189 HOWTO(R_390_TLS_LDCALL
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
190 s390_tls_reloc
, "R_390_TLS_LDCALL", FALSE
, 0, 0, FALSE
),
191 EMPTY_HOWTO (R_390_TLS_GD32
), /* Empty entry for R_390_TLS_GD32. */
192 HOWTO(R_390_TLS_GD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
193 bfd_elf_generic_reloc
, "R_390_TLS_GD64", FALSE
, 0, MINUS_ONE
, FALSE
),
194 HOWTO(R_390_TLS_GOTIE12
, 0, 1, 12, FALSE
, 0, complain_overflow_dont
,
195 bfd_elf_generic_reloc
, "R_390_TLS_GOTIE12", FALSE
, 0, 0x00000fff, FALSE
),
196 EMPTY_HOWTO (R_390_TLS_GOTIE32
), /* Empty entry for R_390_TLS_GOTIE32. */
197 HOWTO(R_390_TLS_GOTIE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
198 bfd_elf_generic_reloc
, "R_390_TLS_GOTIE64", FALSE
, 0, MINUS_ONE
, FALSE
),
199 EMPTY_HOWTO (R_390_TLS_LDM32
), /* Empty entry for R_390_TLS_LDM32. */
200 HOWTO(R_390_TLS_LDM64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
201 bfd_elf_generic_reloc
, "R_390_TLS_LDM64", FALSE
, 0, MINUS_ONE
, FALSE
),
202 EMPTY_HOWTO (R_390_TLS_IE32
), /* Empty entry for R_390_TLS_IE32. */
203 HOWTO(R_390_TLS_IE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
204 bfd_elf_generic_reloc
, "R_390_TLS_IE64", FALSE
, 0, MINUS_ONE
, FALSE
),
205 HOWTO(R_390_TLS_IEENT
, 1, 2, 32, TRUE
, 0, complain_overflow_bitfield
,
206 bfd_elf_generic_reloc
, "R_390_TLS_IEENT", FALSE
, 0, MINUS_ONE
, TRUE
),
207 EMPTY_HOWTO (R_390_TLS_LE32
), /* Empty entry for R_390_TLS_LE32. */
208 HOWTO(R_390_TLS_LE64
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
209 bfd_elf_generic_reloc
, "R_390_TLS_LE64", FALSE
, 0, MINUS_ONE
, FALSE
),
210 EMPTY_HOWTO (R_390_TLS_LDO32
), /* Empty entry for R_390_TLS_LDO32. */
211 HOWTO(R_390_TLS_LDO64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
212 bfd_elf_generic_reloc
, "R_390_TLS_LDO64", FALSE
, 0, MINUS_ONE
, FALSE
),
213 HOWTO(R_390_TLS_DTPMOD
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
214 bfd_elf_generic_reloc
, "R_390_TLS_DTPMOD", FALSE
, 0, MINUS_ONE
, FALSE
),
215 HOWTO(R_390_TLS_DTPOFF
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
216 bfd_elf_generic_reloc
, "R_390_TLS_DTPOFF", FALSE
, 0, MINUS_ONE
, FALSE
),
217 HOWTO(R_390_TLS_TPOFF
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
218 bfd_elf_generic_reloc
, "R_390_TLS_TPOFF", FALSE
, 0, MINUS_ONE
, FALSE
),
221 /* GNU extension to record C++ vtable hierarchy. */
222 static reloc_howto_type elf64_s390_vtinherit_howto
=
223 HOWTO (R_390_GNU_VTINHERIT
, 0,4,0,FALSE
,0,complain_overflow_dont
, NULL
, "R_390_GNU_VTINHERIT", FALSE
,0, 0, FALSE
);
224 static reloc_howto_type elf64_s390_vtentry_howto
=
225 HOWTO (R_390_GNU_VTENTRY
, 0,4,0,FALSE
,0,complain_overflow_dont
, _bfd_elf_rel_vtable_reloc_fn
,"R_390_GNU_VTENTRY", FALSE
,0,0, FALSE
);
227 static reloc_howto_type
*
228 elf_s390_reloc_type_lookup (abfd
, code
)
229 bfd
*abfd ATTRIBUTE_UNUSED
;
230 bfd_reloc_code_real_type code
;
235 return &elf_howto_table
[(int) R_390_NONE
];
237 return &elf_howto_table
[(int) R_390_8
];
238 case BFD_RELOC_390_12
:
239 return &elf_howto_table
[(int) R_390_12
];
241 return &elf_howto_table
[(int) R_390_16
];
243 return &elf_howto_table
[(int) R_390_32
];
245 return &elf_howto_table
[(int) R_390_32
];
246 case BFD_RELOC_32_PCREL
:
247 return &elf_howto_table
[(int) R_390_PC32
];
248 case BFD_RELOC_390_GOT12
:
249 return &elf_howto_table
[(int) R_390_GOT12
];
250 case BFD_RELOC_32_GOT_PCREL
:
251 return &elf_howto_table
[(int) R_390_GOT32
];
252 case BFD_RELOC_390_PLT32
:
253 return &elf_howto_table
[(int) R_390_PLT32
];
254 case BFD_RELOC_390_COPY
:
255 return &elf_howto_table
[(int) R_390_COPY
];
256 case BFD_RELOC_390_GLOB_DAT
:
257 return &elf_howto_table
[(int) R_390_GLOB_DAT
];
258 case BFD_RELOC_390_JMP_SLOT
:
259 return &elf_howto_table
[(int) R_390_JMP_SLOT
];
260 case BFD_RELOC_390_RELATIVE
:
261 return &elf_howto_table
[(int) R_390_RELATIVE
];
262 case BFD_RELOC_32_GOTOFF
:
263 return &elf_howto_table
[(int) R_390_GOTOFF32
];
264 case BFD_RELOC_390_GOTPC
:
265 return &elf_howto_table
[(int) R_390_GOTPC
];
266 case BFD_RELOC_390_GOT16
:
267 return &elf_howto_table
[(int) R_390_GOT16
];
268 case BFD_RELOC_16_PCREL
:
269 return &elf_howto_table
[(int) R_390_PC16
];
270 case BFD_RELOC_390_PC16DBL
:
271 return &elf_howto_table
[(int) R_390_PC16DBL
];
272 case BFD_RELOC_390_PLT16DBL
:
273 return &elf_howto_table
[(int) R_390_PLT16DBL
];
274 case BFD_RELOC_390_PC32DBL
:
275 return &elf_howto_table
[(int) R_390_PC32DBL
];
276 case BFD_RELOC_390_PLT32DBL
:
277 return &elf_howto_table
[(int) R_390_PLT32DBL
];
278 case BFD_RELOC_390_GOTPCDBL
:
279 return &elf_howto_table
[(int) R_390_GOTPCDBL
];
281 return &elf_howto_table
[(int) R_390_64
];
282 case BFD_RELOC_64_PCREL
:
283 return &elf_howto_table
[(int) R_390_PC64
];
284 case BFD_RELOC_390_GOT64
:
285 return &elf_howto_table
[(int) R_390_GOT64
];
286 case BFD_RELOC_390_PLT64
:
287 return &elf_howto_table
[(int) R_390_PLT64
];
288 case BFD_RELOC_390_GOTENT
:
289 return &elf_howto_table
[(int) R_390_GOTENT
];
290 case BFD_RELOC_16_GOTOFF
:
291 return &elf_howto_table
[(int) R_390_GOTOFF16
];
292 case BFD_RELOC_390_GOTOFF64
:
293 return &elf_howto_table
[(int) R_390_GOTOFF64
];
294 case BFD_RELOC_390_GOTPLT12
:
295 return &elf_howto_table
[(int) R_390_GOTPLT12
];
296 case BFD_RELOC_390_GOTPLT16
:
297 return &elf_howto_table
[(int) R_390_GOTPLT16
];
298 case BFD_RELOC_390_GOTPLT32
:
299 return &elf_howto_table
[(int) R_390_GOTPLT32
];
300 case BFD_RELOC_390_GOTPLT64
:
301 return &elf_howto_table
[(int) R_390_GOTPLT64
];
302 case BFD_RELOC_390_GOTPLTENT
:
303 return &elf_howto_table
[(int) R_390_GOTPLTENT
];
304 case BFD_RELOC_390_PLTOFF16
:
305 return &elf_howto_table
[(int) R_390_PLTOFF16
];
306 case BFD_RELOC_390_PLTOFF32
:
307 return &elf_howto_table
[(int) R_390_PLTOFF32
];
308 case BFD_RELOC_390_PLTOFF64
:
309 return &elf_howto_table
[(int) R_390_PLTOFF64
];
310 case BFD_RELOC_390_TLS_LOAD
:
311 return &elf_howto_table
[(int) R_390_TLS_LOAD
];
312 case BFD_RELOC_390_TLS_GDCALL
:
313 return &elf_howto_table
[(int) R_390_TLS_GDCALL
];
314 case BFD_RELOC_390_TLS_LDCALL
:
315 return &elf_howto_table
[(int) R_390_TLS_LDCALL
];
316 case BFD_RELOC_390_TLS_GD64
:
317 return &elf_howto_table
[(int) R_390_TLS_GD64
];
318 case BFD_RELOC_390_TLS_GOTIE12
:
319 return &elf_howto_table
[(int) R_390_TLS_GOTIE12
];
320 case BFD_RELOC_390_TLS_GOTIE64
:
321 return &elf_howto_table
[(int) R_390_TLS_GOTIE64
];
322 case BFD_RELOC_390_TLS_LDM64
:
323 return &elf_howto_table
[(int) R_390_TLS_LDM64
];
324 case BFD_RELOC_390_TLS_IE64
:
325 return &elf_howto_table
[(int) R_390_TLS_IE64
];
326 case BFD_RELOC_390_TLS_IEENT
:
327 return &elf_howto_table
[(int) R_390_TLS_IEENT
];
328 case BFD_RELOC_390_TLS_LE64
:
329 return &elf_howto_table
[(int) R_390_TLS_LE64
];
330 case BFD_RELOC_390_TLS_LDO64
:
331 return &elf_howto_table
[(int) R_390_TLS_LDO64
];
332 case BFD_RELOC_390_TLS_DTPMOD
:
333 return &elf_howto_table
[(int) R_390_TLS_DTPMOD
];
334 case BFD_RELOC_390_TLS_DTPOFF
:
335 return &elf_howto_table
[(int) R_390_TLS_DTPOFF
];
336 case BFD_RELOC_390_TLS_TPOFF
:
337 return &elf_howto_table
[(int) R_390_TLS_TPOFF
];
338 case BFD_RELOC_VTABLE_INHERIT
:
339 return &elf64_s390_vtinherit_howto
;
340 case BFD_RELOC_VTABLE_ENTRY
:
341 return &elf64_s390_vtentry_howto
;
348 /* We need to use ELF64_R_TYPE so we have our own copy of this function,
349 and elf64-s390.c has its own copy. */
352 elf_s390_info_to_howto (abfd
, cache_ptr
, dst
)
353 bfd
*abfd ATTRIBUTE_UNUSED
;
355 Elf_Internal_Rela
*dst
;
357 switch (ELF64_R_TYPE(dst
->r_info
))
359 case R_390_GNU_VTINHERIT
:
360 cache_ptr
->howto
= &elf64_s390_vtinherit_howto
;
363 case R_390_GNU_VTENTRY
:
364 cache_ptr
->howto
= &elf64_s390_vtentry_howto
;
368 BFD_ASSERT (ELF64_R_TYPE(dst
->r_info
) < (unsigned int) R_390_max
);
369 cache_ptr
->howto
= &elf_howto_table
[ELF64_R_TYPE(dst
->r_info
)];
373 /* A relocation function which doesn't do anything. */
374 static bfd_reloc_status_type
375 s390_tls_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
376 output_bfd
, error_message
)
377 bfd
*abfd ATTRIBUTE_UNUSED
;
378 arelent
*reloc_entry
;
379 asymbol
*symbol ATTRIBUTE_UNUSED
;
380 PTR data ATTRIBUTE_UNUSED
;
381 asection
*input_section
;
383 char **error_message ATTRIBUTE_UNUSED
;
386 reloc_entry
->address
+= input_section
->output_offset
;
391 elf_s390_is_local_label_name (abfd
, name
)
395 if (name
[0] == '.' && (name
[1] == 'X' || name
[1] == 'L'))
398 return _bfd_elf_is_local_label_name (abfd
, name
);
401 /* Functions for the 390 ELF linker. */
403 /* The name of the dynamic interpreter. This is put in the .interp
406 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
408 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
409 copying dynamic variables from a shared lib into an app's dynbss
410 section, and instead use a dynamic relocation to point into the
412 #define ELIMINATE_COPY_RELOCS 1
414 /* The size in bytes of the first entry in the procedure linkage table. */
415 #define PLT_FIRST_ENTRY_SIZE 32
416 /* The size in bytes of an entry in the procedure linkage table. */
417 #define PLT_ENTRY_SIZE 32
419 #define GOT_ENTRY_SIZE 8
421 /* The first three entries in a procedure linkage table are reserved,
422 and the initial contents are unimportant (we zero them out).
423 Subsequent entries look like this. See the SVR4 ABI 386
424 supplement to see how this works. */
426 /* For the s390, simple addr offset can only be 0 - 4096.
427 To use the full 16777216 TB address space, several instructions
428 are needed to load an address in a register and execute
429 a branch( or just saving the address)
431 Furthermore, only r 0 and 1 are free to use!!! */
433 /* The first 3 words in the GOT are then reserved.
434 Word 0 is the address of the dynamic table.
435 Word 1 is a pointer to a structure describing the object
436 Word 2 is used to point to the loader entry address.
438 The code for PLT entries looks like this:
440 The GOT holds the address in the PLT to be executed.
441 The loader then gets:
442 24(15) = Pointer to the structure describing the object.
443 28(15) = Offset in symbol table
444 The loader must then find the module where the function is
445 and insert the address in the GOT.
447 PLT1: LARL 1,<fn>@GOTENT # 6 bytes Load address of GOT entry in r1
448 LG 1,0(1) # 6 bytes Load address from GOT in r1
449 BCR 15,1 # 2 bytes Jump to address
450 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
451 LGF 1,12(1) # 6 bytes Load offset in symbl table in r1
452 BRCL 15,-x # 6 bytes Jump to start of PLT
453 .long ? # 4 bytes offset into symbol table
455 Total = 32 bytes per PLT entry
456 Fixup at offset 2: relative address to GOT entry
457 Fixup at offset 22: relative branch to PLT0
458 Fixup at offset 28: 32 bit offset into symbol table
460 A 32 bit offset into the symbol table is enough. It allows for symbol
461 tables up to a size of 2 gigabyte. A single dynamic object (the main
462 program, any shared library) is limited to 4GB in size and I want to see
463 the program that manages to have a symbol table of more than 2 GB with a
464 total size of at max 4 GB. */
466 #define PLT_ENTRY_WORD0 (bfd_vma) 0xc0100000
467 #define PLT_ENTRY_WORD1 (bfd_vma) 0x0000e310
468 #define PLT_ENTRY_WORD2 (bfd_vma) 0x10000004
469 #define PLT_ENTRY_WORD3 (bfd_vma) 0x07f10d10
470 #define PLT_ENTRY_WORD4 (bfd_vma) 0xe310100c
471 #define PLT_ENTRY_WORD5 (bfd_vma) 0x0014c0f4
472 #define PLT_ENTRY_WORD6 (bfd_vma) 0x00000000
473 #define PLT_ENTRY_WORD7 (bfd_vma) 0x00000000
475 /* The first PLT entry pushes the offset into the symbol table
476 from R1 onto the stack at 8(15) and the loader object info
477 at 12(15), loads the loader address in R1 and jumps to it. */
479 /* The first entry in the PLT:
482 STG 1,56(15) # r1 contains the offset into the symbol table
483 LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table
484 MVC 48(8,15),8(1) # move loader ino (object struct address) to stack
485 LG 1,16(1) # get entry address of loader
486 BCR 15,1 # jump to loader
488 Fixup at offset 8: relative address to start of GOT. */
490 #define PLT_FIRST_ENTRY_WORD0 (bfd_vma) 0xe310f038
491 #define PLT_FIRST_ENTRY_WORD1 (bfd_vma) 0x0024c010
492 #define PLT_FIRST_ENTRY_WORD2 (bfd_vma) 0x00000000
493 #define PLT_FIRST_ENTRY_WORD3 (bfd_vma) 0xd207f030
494 #define PLT_FIRST_ENTRY_WORD4 (bfd_vma) 0x1008e310
495 #define PLT_FIRST_ENTRY_WORD5 (bfd_vma) 0x10100004
496 #define PLT_FIRST_ENTRY_WORD6 (bfd_vma) 0x07f10700
497 #define PLT_FIRST_ENTRY_WORD7 (bfd_vma) 0x07000700
499 /* The s390 linker needs to keep track of the number of relocs that it
500 decides to copy as dynamic relocs in check_relocs for each symbol.
501 This is so that it can later discard them if they are found to be
502 unnecessary. We store the information in a field extending the
503 regular ELF linker hash table. */
505 struct elf_s390_dyn_relocs
507 struct elf_s390_dyn_relocs
*next
;
509 /* The input section of the reloc. */
512 /* Total number of relocs copied for the input section. */
515 /* Number of pc-relative relocs copied for the input section. */
516 bfd_size_type pc_count
;
519 /* s390 ELF linker hash entry. */
521 struct elf_s390_link_hash_entry
523 struct elf_link_hash_entry elf
;
525 /* Track dynamic relocs copied for this symbol. */
526 struct elf_s390_dyn_relocs
*dyn_relocs
;
528 /* Number of GOTPLT references for a function. */
529 bfd_signed_vma gotplt_refcount
;
531 #define GOT_UNKNOWN 0
535 #define GOT_TLS_IE_NLT 3
536 unsigned char tls_type
;
539 #define elf_s390_hash_entry(ent) \
540 ((struct elf_s390_link_hash_entry *)(ent))
542 struct elf_s390_obj_tdata
544 struct elf_obj_tdata root
;
546 /* tls_type for each local got entry. */
547 char *local_got_tls_type
;
550 #define elf_s390_tdata(abfd) \
551 ((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
553 #define elf_s390_local_got_tls_type(abfd) \
554 (elf_s390_tdata (abfd)->local_got_tls_type)
557 elf_s390_mkobject (abfd
)
560 bfd_size_type amt
= sizeof (struct elf_s390_obj_tdata
);
561 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
562 if (abfd
->tdata
.any
== NULL
)
568 elf_s390_object_p (abfd
)
571 /* Allocate our special target data. */
572 struct elf_s390_obj_tdata
*new_tdata
;
573 bfd_size_type amt
= sizeof (struct elf_s390_obj_tdata
);
574 new_tdata
= bfd_zalloc (abfd
, amt
);
575 if (new_tdata
== NULL
)
577 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
578 abfd
->tdata
.any
= new_tdata
;
579 /* Set the right machine number for an s390 elf32 file. */
580 return bfd_default_set_arch_mach (abfd
, bfd_arch_s390
, bfd_mach_s390_64
);
583 /* s390 ELF linker hash table. */
585 struct elf_s390_link_hash_table
587 struct elf_link_hash_table elf
;
589 /* Short-cuts to get to dynamic linker sections. */
599 bfd_signed_vma refcount
;
603 /* Small local sym to section mapping cache. */
604 struct sym_sec_cache sym_sec
;
607 /* Get the s390 ELF linker hash table from a link_info structure. */
609 #define elf_s390_hash_table(p) \
610 ((struct elf_s390_link_hash_table *) ((p)->hash))
612 /* Create an entry in an s390 ELF linker hash table. */
614 static struct bfd_hash_entry
*
615 link_hash_newfunc (entry
, table
, string
)
616 struct bfd_hash_entry
*entry
;
617 struct bfd_hash_table
*table
;
620 /* Allocate the structure if it has not already been allocated by a
624 entry
= bfd_hash_allocate (table
,
625 sizeof (struct elf_s390_link_hash_entry
));
630 /* Call the allocation method of the superclass. */
631 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
634 struct elf_s390_link_hash_entry
*eh
;
636 eh
= (struct elf_s390_link_hash_entry
*) entry
;
637 eh
->dyn_relocs
= NULL
;
638 eh
->gotplt_refcount
= 0;
639 eh
->tls_type
= GOT_UNKNOWN
;
645 /* Create an s390 ELF linker hash table. */
647 static struct bfd_link_hash_table
*
648 elf_s390_link_hash_table_create (abfd
)
651 struct elf_s390_link_hash_table
*ret
;
652 bfd_size_type amt
= sizeof (struct elf_s390_link_hash_table
);
654 ret
= (struct elf_s390_link_hash_table
*) bfd_malloc (amt
);
658 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
671 ret
->tls_ldm_got
.refcount
= 0;
672 ret
->sym_sec
.abfd
= NULL
;
674 return &ret
->elf
.root
;
677 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
678 shortcuts to them in our hash table. */
681 create_got_section (dynobj
, info
)
683 struct bfd_link_info
*info
;
685 struct elf_s390_link_hash_table
*htab
;
687 if (! _bfd_elf_create_got_section (dynobj
, info
))
690 htab
= elf_s390_hash_table (info
);
691 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
692 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
693 if (!htab
->sgot
|| !htab
->sgotplt
)
696 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
697 if (htab
->srelgot
== NULL
698 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
699 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
700 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
702 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
707 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
708 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
712 elf_s390_create_dynamic_sections (dynobj
, info
)
714 struct bfd_link_info
*info
;
716 struct elf_s390_link_hash_table
*htab
;
718 htab
= elf_s390_hash_table (info
);
719 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
722 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
725 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
726 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
727 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
729 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
731 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
732 || (!info
->shared
&& !htab
->srelbss
))
738 /* Copy the extra info we tack onto an elf_link_hash_entry. */
741 elf_s390_copy_indirect_symbol (bed
, dir
, ind
)
742 struct elf_backend_data
*bed
;
743 struct elf_link_hash_entry
*dir
, *ind
;
745 struct elf_s390_link_hash_entry
*edir
, *eind
;
747 edir
= (struct elf_s390_link_hash_entry
*) dir
;
748 eind
= (struct elf_s390_link_hash_entry
*) ind
;
750 if (eind
->dyn_relocs
!= NULL
)
752 if (edir
->dyn_relocs
!= NULL
)
754 struct elf_s390_dyn_relocs
**pp
;
755 struct elf_s390_dyn_relocs
*p
;
757 if (ind
->root
.type
== bfd_link_hash_indirect
)
760 /* Add reloc counts against the weak sym to the strong sym
761 list. Merge any entries against the same section. */
762 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
764 struct elf_s390_dyn_relocs
*q
;
766 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
767 if (q
->sec
== p
->sec
)
769 q
->pc_count
+= p
->pc_count
;
770 q
->count
+= p
->count
;
777 *pp
= edir
->dyn_relocs
;
780 edir
->dyn_relocs
= eind
->dyn_relocs
;
781 eind
->dyn_relocs
= NULL
;
784 if (ind
->root
.type
== bfd_link_hash_indirect
785 && dir
->got
.refcount
<= 0)
787 edir
->tls_type
= eind
->tls_type
;
788 eind
->tls_type
= GOT_UNKNOWN
;
791 if (ELIMINATE_COPY_RELOCS
792 && ind
->root
.type
!= bfd_link_hash_indirect
793 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
794 /* If called to transfer flags for a weakdef during processing
795 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
796 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
797 dir
->elf_link_hash_flags
|=
798 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
799 | ELF_LINK_HASH_REF_REGULAR
800 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
802 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
806 elf_s390_tls_transition (info
, r_type
, is_local
)
807 struct bfd_link_info
*info
;
819 return R_390_TLS_LE64
;
820 return R_390_TLS_IE64
;
821 case R_390_TLS_GOTIE64
:
823 return R_390_TLS_LE64
;
824 return R_390_TLS_GOTIE64
;
825 case R_390_TLS_LDM64
:
826 return R_390_TLS_LE64
;
832 /* Look through the relocs for a section during the first phase, and
833 allocate space in the global offset table or procedure linkage
837 elf_s390_check_relocs (abfd
, info
, sec
, relocs
)
839 struct bfd_link_info
*info
;
841 const Elf_Internal_Rela
*relocs
;
843 struct elf_s390_link_hash_table
*htab
;
844 Elf_Internal_Shdr
*symtab_hdr
;
845 struct elf_link_hash_entry
**sym_hashes
;
846 const Elf_Internal_Rela
*rel
;
847 const Elf_Internal_Rela
*rel_end
;
849 bfd_signed_vma
*local_got_refcounts
;
850 int tls_type
, old_tls_type
;
852 if (info
->relocateable
)
855 htab
= elf_s390_hash_table (info
);
856 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
857 sym_hashes
= elf_sym_hashes (abfd
);
858 local_got_refcounts
= elf_local_got_refcounts (abfd
);
862 rel_end
= relocs
+ sec
->reloc_count
;
863 for (rel
= relocs
; rel
< rel_end
; rel
++)
866 unsigned long r_symndx
;
867 struct elf_link_hash_entry
*h
;
869 r_symndx
= ELF64_R_SYM (rel
->r_info
);
871 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
873 (*_bfd_error_handler
) (_("%s: bad symbol index: %d"),
874 bfd_archive_filename (abfd
),
879 if (r_symndx
< symtab_hdr
->sh_info
)
882 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
884 /* Create got section and local_got_refcounts array if they
886 r_type
= elf_s390_tls_transition (info
,
887 ELF64_R_TYPE (rel
->r_info
),
900 case R_390_GOTPLTENT
:
902 case R_390_TLS_GOTIE12
:
903 case R_390_TLS_GOTIE64
:
904 case R_390_TLS_IEENT
:
906 case R_390_TLS_LDM64
:
908 && local_got_refcounts
== NULL
)
912 size
= symtab_hdr
->sh_info
;
913 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
914 local_got_refcounts
= ((bfd_signed_vma
*)
915 bfd_zalloc (abfd
, size
));
916 if (local_got_refcounts
== NULL
)
918 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
919 elf_s390_local_got_tls_type (abfd
)
920 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
928 if (htab
->sgot
== NULL
)
930 if (htab
->elf
.dynobj
== NULL
)
931 htab
->elf
.dynobj
= abfd
;
932 if (!create_got_section (htab
->elf
.dynobj
, info
))
944 /* Got is created, nothing to be done. */
954 /* This symbol requires a procedure linkage table entry. We
955 actually build the entry in adjust_dynamic_symbol,
956 because this might be a case of linking PIC code which is
957 never referenced by a dynamic object, in which case we
958 don't need to generate a procedure linkage table entry
961 /* If this is a local symbol, we resolve it directly without
962 creating a procedure linkage table entry. */
965 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
966 h
->plt
.refcount
+= 1;
974 case R_390_GOTPLTENT
:
975 /* This symbol requires either a procedure linkage table entry
976 or an entry in the local got. We actually build the entry
977 in adjust_dynamic_symbol because whether this is really a
978 global reference can change and with it the fact if we have
979 to create a plt entry or a local got entry. To be able to
980 make a once global symbol a local one we have to keep track
981 of the number of gotplt references that exist for this
985 ((struct elf_s390_link_hash_entry
*) h
)->gotplt_refcount
++;
986 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
987 h
->plt
.refcount
+= 1;
990 local_got_refcounts
[r_symndx
] += 1;
993 case R_390_TLS_LDM64
:
994 htab
->tls_ldm_got
.refcount
+= 1;
998 case R_390_TLS_GOTIE12
:
999 case R_390_TLS_GOTIE64
:
1000 case R_390_TLS_IEENT
:
1002 info
->flags
|= DF_STATIC_TLS
;
1010 case R_390_TLS_GD64
:
1011 /* This symbol requires a global offset table entry. */
1019 tls_type
= GOT_NORMAL
;
1021 case R_390_TLS_GD64
:
1022 tls_type
= GOT_TLS_GD
;
1024 case R_390_TLS_IE64
:
1025 case R_390_TLS_GOTIE64
:
1026 tls_type
= GOT_TLS_IE
;
1028 case R_390_TLS_GOTIE12
:
1029 case R_390_TLS_IEENT
:
1030 tls_type
= GOT_TLS_IE_NLT
;
1036 h
->got
.refcount
+= 1;
1037 old_tls_type
= elf_s390_hash_entry(h
)->tls_type
;
1041 local_got_refcounts
[r_symndx
] += 1;
1042 old_tls_type
= elf_s390_local_got_tls_type (abfd
) [r_symndx
];
1044 /* If a TLS symbol is accessed using IE at least once,
1045 there is no point to use dynamic model for it. */
1046 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
)
1048 if (old_tls_type
== GOT_NORMAL
|| tls_type
== GOT_NORMAL
)
1050 (*_bfd_error_handler
)
1051 (_("%s: `%s' accessed both as normal and thread local symbol"),
1052 bfd_archive_filename (abfd
), h
->root
.root
.string
);
1055 if (old_tls_type
> tls_type
)
1056 tls_type
= old_tls_type
;
1059 if (old_tls_type
!= tls_type
)
1062 elf_s390_hash_entry (h
)->tls_type
= tls_type
;
1064 elf_s390_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1067 if (r_type
!= R_390_TLS_IE64
)
1071 case R_390_TLS_LE64
:
1074 info
->flags
|= DF_STATIC_TLS
;
1086 if (h
!= NULL
&& !info
->shared
)
1088 /* If this reloc is in a read-only section, we might
1089 need a copy reloc. We can't check reliably at this
1090 stage whether the section is read-only, as input
1091 sections have not yet been mapped to output sections.
1092 Tentatively set the flag for now, and correct in
1093 adjust_dynamic_symbol. */
1094 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1096 /* We may need a .plt entry if the function this reloc
1097 refers to is in a shared lib. */
1098 h
->plt
.refcount
+= 1;
1101 /* If we are creating a shared library, and this is a reloc
1102 against a global symbol, or a non PC relative reloc
1103 against a local symbol, then we need to copy the reloc
1104 into the shared library. However, if we are linking with
1105 -Bsymbolic, we do not need to copy a reloc against a
1106 global symbol which is defined in an object we are
1107 including in the link (i.e., DEF_REGULAR is set). At
1108 this point we have not seen all the input files, so it is
1109 possible that DEF_REGULAR is not set now but will be set
1110 later (it is never cleared). In case of a weak definition,
1111 DEF_REGULAR may be cleared later by a strong definition in
1112 a shared library. We account for that possibility below by
1113 storing information in the relocs_copied field of the hash
1114 table entry. A similar situation occurs when creating
1115 shared libraries and symbol visibility changes render the
1118 If on the other hand, we are creating an executable, we
1119 may need to keep relocations for symbols satisfied by a
1120 dynamic library if we manage to avoid copy relocs for the
1123 && (sec
->flags
& SEC_ALLOC
) != 0
1124 && ((ELF64_R_TYPE (rel
->r_info
) != R_390_PC16
1125 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC16DBL
1126 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC32
1127 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC32DBL
1128 && ELF64_R_TYPE (rel
->r_info
) != R_390_PC64
)
1130 && (! info
->symbolic
1131 || h
->root
.type
== bfd_link_hash_defweak
1132 || (h
->elf_link_hash_flags
1133 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1134 || (ELIMINATE_COPY_RELOCS
1136 && (sec
->flags
& SEC_ALLOC
) != 0
1138 && (h
->root
.type
== bfd_link_hash_defweak
1139 || (h
->elf_link_hash_flags
1140 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1142 struct elf_s390_dyn_relocs
*p
;
1143 struct elf_s390_dyn_relocs
**head
;
1145 /* We must copy these reloc types into the output file.
1146 Create a reloc section in dynobj and make room for
1153 name
= (bfd_elf_string_from_elf_section
1155 elf_elfheader (abfd
)->e_shstrndx
,
1156 elf_section_data (sec
)->rel_hdr
.sh_name
));
1160 if (strncmp (name
, ".rela", 5) != 0
1161 || strcmp (bfd_get_section_name (abfd
, sec
),
1164 (*_bfd_error_handler
)
1165 (_("%s: bad relocation section name `%s\'"),
1166 bfd_archive_filename (abfd
), name
);
1169 if (htab
->elf
.dynobj
== NULL
)
1170 htab
->elf
.dynobj
= abfd
;
1172 dynobj
= htab
->elf
.dynobj
;
1173 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1178 sreloc
= bfd_make_section (dynobj
, name
);
1179 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1180 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1181 if ((sec
->flags
& SEC_ALLOC
) != 0)
1182 flags
|= SEC_ALLOC
| SEC_LOAD
;
1184 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
1185 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
1188 elf_section_data (sec
)->sreloc
= sreloc
;
1191 /* If this is a global symbol, we count the number of
1192 relocations we need for this symbol. */
1195 head
= &((struct elf_s390_link_hash_entry
*) h
)->dyn_relocs
;
1199 /* Track dynamic relocs needed for local syms too.
1200 We really need local syms available to do this
1204 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1209 head
= ((struct elf_s390_dyn_relocs
**)
1210 &elf_section_data (s
)->local_dynrel
);
1214 if (p
== NULL
|| p
->sec
!= sec
)
1216 bfd_size_type amt
= sizeof *p
;
1217 p
= ((struct elf_s390_dyn_relocs
*)
1218 bfd_alloc (htab
->elf
.dynobj
, amt
));
1229 if (ELF64_R_TYPE (rel
->r_info
) == R_390_PC16
1230 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC16DBL
1231 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC32
1232 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC32DBL
1233 || ELF64_R_TYPE (rel
->r_info
) == R_390_PC64
)
1238 /* This relocation describes the C++ object vtable hierarchy.
1239 Reconstruct it for later use during GC. */
1240 case R_390_GNU_VTINHERIT
:
1241 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1245 /* This relocation describes which C++ vtable entries are actually
1246 used. Record for later use during GC. */
1247 case R_390_GNU_VTENTRY
:
1248 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1260 /* Return the section that should be marked against GC for a given
1264 elf_s390_gc_mark_hook (sec
, info
, rel
, h
, sym
)
1266 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1267 Elf_Internal_Rela
*rel
;
1268 struct elf_link_hash_entry
*h
;
1269 Elf_Internal_Sym
*sym
;
1273 switch (ELF64_R_TYPE (rel
->r_info
))
1275 case R_390_GNU_VTINHERIT
:
1276 case R_390_GNU_VTENTRY
:
1280 switch (h
->root
.type
)
1282 case bfd_link_hash_defined
:
1283 case bfd_link_hash_defweak
:
1284 return h
->root
.u
.def
.section
;
1286 case bfd_link_hash_common
:
1287 return h
->root
.u
.c
.p
->section
;
1295 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1300 /* Update the got entry reference counts for the section being removed. */
1303 elf_s390_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1305 struct bfd_link_info
*info
;
1307 const Elf_Internal_Rela
*relocs
;
1309 Elf_Internal_Shdr
*symtab_hdr
;
1310 struct elf_link_hash_entry
**sym_hashes
;
1311 bfd_signed_vma
*local_got_refcounts
;
1312 const Elf_Internal_Rela
*rel
, *relend
;
1314 elf_section_data (sec
)->local_dynrel
= NULL
;
1316 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1317 sym_hashes
= elf_sym_hashes (abfd
);
1318 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1320 relend
= relocs
+ sec
->reloc_count
;
1321 for (rel
= relocs
; rel
< relend
; rel
++)
1323 unsigned long r_symndx
;
1324 unsigned int r_type
;
1325 struct elf_link_hash_entry
*h
= NULL
;
1327 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1328 if (r_symndx
>= symtab_hdr
->sh_info
)
1330 struct elf_s390_link_hash_entry
*eh
;
1331 struct elf_s390_dyn_relocs
**pp
;
1332 struct elf_s390_dyn_relocs
*p
;
1334 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1335 eh
= (struct elf_s390_link_hash_entry
*) h
;
1337 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1340 /* Everything must go for SEC. */
1346 r_type
= ELF64_R_TYPE (rel
->r_info
);
1347 r_type
= elf_s390_tls_transition (info
, r_type
, h
!= NULL
);
1350 case R_390_TLS_LDM64
:
1351 if (elf_s390_hash_table (info
)->tls_ldm_got
.refcount
> 0)
1352 elf_s390_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1355 case R_390_TLS_GD64
:
1356 case R_390_TLS_IE64
:
1357 case R_390_TLS_GOTIE12
:
1358 case R_390_TLS_GOTIE64
:
1359 case R_390_TLS_IEENT
:
1364 case R_390_GOTOFF16
:
1365 case R_390_GOTOFF32
:
1366 case R_390_GOTOFF64
:
1368 case R_390_GOTPCDBL
:
1372 if (h
->got
.refcount
> 0)
1373 h
->got
.refcount
-= 1;
1375 else if (local_got_refcounts
!= NULL
)
1377 if (local_got_refcounts
[r_symndx
] > 0)
1378 local_got_refcounts
[r_symndx
] -= 1;
1396 case R_390_PLT16DBL
:
1398 case R_390_PLT32DBL
:
1400 case R_390_PLTOFF16
:
1401 case R_390_PLTOFF32
:
1402 case R_390_PLTOFF64
:
1405 if (h
->plt
.refcount
> 0)
1406 h
->plt
.refcount
-= 1;
1410 case R_390_GOTPLT12
:
1411 case R_390_GOTPLT16
:
1412 case R_390_GOTPLT32
:
1413 case R_390_GOTPLT64
:
1414 case R_390_GOTPLTENT
:
1417 if (h
->plt
.refcount
> 0)
1419 ((struct elf_s390_link_hash_entry
*) h
)->gotplt_refcount
--;
1420 h
->plt
.refcount
-= 1;
1423 else if (local_got_refcounts
!= NULL
)
1425 if (local_got_refcounts
[r_symndx
] > 0)
1426 local_got_refcounts
[r_symndx
] -= 1;
1438 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1439 entry but we found we will not create any. Called when we find we will
1440 not have any PLT for this symbol, by for example
1441 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
1442 or elf_s390_size_dynamic_sections if no dynamic sections will be
1443 created (we're only linking static objects). */
1446 elf_s390_adjust_gotplt (h
)
1447 struct elf_s390_link_hash_entry
*h
;
1449 if (h
->elf
.root
.type
== bfd_link_hash_warning
)
1450 h
= (struct elf_s390_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
1452 if (h
->gotplt_refcount
<= 0)
1455 /* We simply add the number of gotplt references to the number
1456 * of got references for this symbol. */
1457 h
->elf
.got
.refcount
+= h
->gotplt_refcount
;
1458 h
->gotplt_refcount
= -1;
1461 /* Adjust a symbol defined by a dynamic object and referenced by a
1462 regular object. The current definition is in some section of the
1463 dynamic object, but we're not including those sections. We have to
1464 change the definition to something the rest of the link can
1468 elf_s390_adjust_dynamic_symbol (info
, h
)
1469 struct bfd_link_info
*info
;
1470 struct elf_link_hash_entry
*h
;
1472 struct elf_s390_link_hash_table
*htab
;
1474 unsigned int power_of_two
;
1476 /* If this is a function, put it in the procedure linkage table. We
1477 will fill in the contents of the procedure linkage table later
1478 (although we could actually do it here). */
1479 if (h
->type
== STT_FUNC
1480 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1482 if (h
->plt
.refcount
<= 0
1484 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1485 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
1486 && h
->root
.type
!= bfd_link_hash_undefweak
1487 && h
->root
.type
!= bfd_link_hash_undefined
))
1489 /* This case can occur if we saw a PLT32 reloc in an input
1490 file, but the symbol was never referred to by a dynamic
1491 object, or if all references were garbage collected. In
1492 such a case, we don't actually need to build a procedure
1493 linkage table, and we can just do a PC32 reloc instead. */
1494 h
->plt
.offset
= (bfd_vma
) -1;
1495 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1496 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1502 /* It's possible that we incorrectly decided a .plt reloc was
1503 needed for an R_390_PC32 reloc to a non-function sym in
1504 check_relocs. We can't decide accurately between function and
1505 non-function syms in check-relocs; Objects loaded later in
1506 the link may change h->type. So fix it now. */
1507 h
->plt
.offset
= (bfd_vma
) -1;
1509 /* If this is a weak symbol, and there is a real definition, the
1510 processor independent code will have arranged for us to see the
1511 real definition first, and we can just use the same value. */
1512 if (h
->weakdef
!= NULL
)
1514 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1515 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1516 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1517 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1518 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1519 h
->elf_link_hash_flags
1520 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
1521 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
1525 /* This is a reference to a symbol defined by a dynamic object which
1526 is not a function. */
1528 /* If we are creating a shared library, we must presume that the
1529 only references to the symbol are via the global offset table.
1530 For such cases we need not do anything here; the relocations will
1531 be handled correctly by relocate_section. */
1535 /* If there are no references to this symbol that do not use the
1536 GOT, we don't need to generate a copy reloc. */
1537 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1540 /* If -z nocopyreloc was given, we won't generate them either. */
1541 if (info
->nocopyreloc
)
1543 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1547 if (ELIMINATE_COPY_RELOCS
)
1549 struct elf_s390_link_hash_entry
* eh
;
1550 struct elf_s390_dyn_relocs
*p
;
1552 eh
= (struct elf_s390_link_hash_entry
*) h
;
1553 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1555 s
= p
->sec
->output_section
;
1556 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1560 /* If we didn't find any dynamic relocs in read-only sections, then
1561 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1564 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1569 /* We must allocate the symbol in our .dynbss section, which will
1570 become part of the .bss section of the executable. There will be
1571 an entry for this symbol in the .dynsym section. The dynamic
1572 object will contain position independent code, so all references
1573 from the dynamic object to this symbol will go through the global
1574 offset table. The dynamic linker will use the .dynsym entry to
1575 determine the address it must put in the global offset table, so
1576 both the dynamic object and the regular object will refer to the
1577 same memory location for the variable. */
1579 htab
= elf_s390_hash_table (info
);
1581 /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1582 copy the initial value out of the dynamic object and into the
1583 runtime process image. */
1584 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1586 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
1587 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1590 /* We need to figure out the alignment required for this symbol. I
1591 have no idea how ELF linkers handle this. */
1592 power_of_two
= bfd_log2 (h
->size
);
1593 if (power_of_two
> 3)
1596 /* Apply the required alignment. */
1598 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
1599 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1601 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1605 /* Define the symbol as being at this point in the section. */
1606 h
->root
.u
.def
.section
= s
;
1607 h
->root
.u
.def
.value
= s
->_raw_size
;
1609 /* Increment the section size to make room for the symbol. */
1610 s
->_raw_size
+= h
->size
;
1615 /* This is the condition under which elf_s390_finish_dynamic_symbol
1616 will be called from elflink.h. If elflink.h doesn't call our
1617 finish_dynamic_symbol routine, we'll need to do something about
1618 initializing any .plt and .got entries in elf_s390_relocate_section. */
1619 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
1622 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1623 && ((H)->dynindx != -1 \
1624 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1626 /* Allocate space in .plt, .got and associated reloc sections for
1630 allocate_dynrelocs (h
, inf
)
1631 struct elf_link_hash_entry
*h
;
1634 struct bfd_link_info
*info
;
1635 struct elf_s390_link_hash_table
*htab
;
1636 struct elf_s390_link_hash_entry
*eh
;
1637 struct elf_s390_dyn_relocs
*p
;
1639 if (h
->root
.type
== bfd_link_hash_indirect
)
1642 if (h
->root
.type
== bfd_link_hash_warning
)
1643 /* When warning symbols are created, they **replace** the "real"
1644 entry in the hash table, thus we never get to see the real
1645 symbol in a hash traversal. So look at it now. */
1646 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1648 info
= (struct bfd_link_info
*) inf
;
1649 htab
= elf_s390_hash_table (info
);
1651 if (htab
->elf
.dynamic_sections_created
1652 && h
->plt
.refcount
> 0
1653 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1654 || h
->root
.type
!= bfd_link_hash_undefweak
))
1656 /* Make sure this symbol is output as a dynamic symbol.
1657 Undefined weak syms won't yet be marked as dynamic. */
1658 if (h
->dynindx
== -1
1659 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1661 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1666 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1668 asection
*s
= htab
->splt
;
1670 /* If this is the first .plt entry, make room for the special
1672 if (s
->_raw_size
== 0)
1673 s
->_raw_size
+= PLT_FIRST_ENTRY_SIZE
;
1675 h
->plt
.offset
= s
->_raw_size
;
1677 /* If this symbol is not defined in a regular file, and we are
1678 not generating a shared library, then set the symbol to this
1679 location in the .plt. This is required to make function
1680 pointers compare as equal between the normal executable and
1681 the shared library. */
1683 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1685 h
->root
.u
.def
.section
= s
;
1686 h
->root
.u
.def
.value
= h
->plt
.offset
;
1689 /* Make room for this entry. */
1690 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1692 /* We also need to make an entry in the .got.plt section, which
1693 will be placed in the .got section by the linker script. */
1694 htab
->sgotplt
->_raw_size
+= GOT_ENTRY_SIZE
;
1696 /* We also need to make an entry in the .rela.plt section. */
1697 htab
->srelplt
->_raw_size
+= sizeof (Elf64_External_Rela
);
1701 h
->plt
.offset
= (bfd_vma
) -1;
1702 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1703 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1708 h
->plt
.offset
= (bfd_vma
) -1;
1709 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1710 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry
*) h
);
1713 /* If R_390_TLS_{IE64,GOTIE64,GOTIE12,IEENT} symbol is now local to
1714 the binary, we can optimize a bit. IE64 and GOTIE64 get converted
1715 to R_390_TLS_LE64 requiring no TLS entry. For GOTIE12 and IEENT
1716 we can save the dynamic TLS relocation. */
1717 if (h
->got
.refcount
> 0
1720 && elf_s390_hash_entry(h
)->tls_type
>= GOT_TLS_IE
)
1722 if (elf_s390_hash_entry(h
)->tls_type
== GOT_TLS_IE_NLT
)
1723 /* For the GOTIE access without a literal pool entry the offset has
1724 to be stored somewhere. The immediate value in the instruction
1725 is not bit enough so the value is stored in the got. */
1727 h
->got
.offset
= htab
->sgot
->_raw_size
;
1728 htab
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1731 h
->got
.offset
= (bfd_vma
) -1;
1733 else if (h
->got
.refcount
> 0)
1737 int tls_type
= elf_s390_hash_entry(h
)->tls_type
;
1739 /* Make sure this symbol is output as a dynamic symbol.
1740 Undefined weak syms won't yet be marked as dynamic. */
1741 if (h
->dynindx
== -1
1742 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1744 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1749 h
->got
.offset
= s
->_raw_size
;
1750 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1751 /* R_390_TLS_GD64 needs 2 consecutive GOT slots. */
1752 if (tls_type
== GOT_TLS_GD
)
1753 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1754 dyn
= htab
->elf
.dynamic_sections_created
;
1755 /* R_390_TLS_IE64 needs one dynamic relocation,
1756 R_390_TLS_GD64 needs one if local symbol and two if global. */
1757 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
1758 || tls_type
>= GOT_TLS_IE
)
1759 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1760 else if (tls_type
== GOT_TLS_GD
)
1761 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf64_External_Rela
);
1762 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1763 || h
->root
.type
!= bfd_link_hash_undefweak
)
1765 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1766 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1769 h
->got
.offset
= (bfd_vma
) -1;
1771 eh
= (struct elf_s390_link_hash_entry
*) h
;
1772 if (eh
->dyn_relocs
== NULL
)
1775 /* In the shared -Bsymbolic case, discard space allocated for
1776 dynamic pc-relative relocs against symbols which turn out to be
1777 defined in regular objects. For the normal shared case, discard
1778 space for pc-relative relocs that have become local due to symbol
1779 visibility changes. */
1783 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1784 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
1787 struct elf_s390_dyn_relocs
**pp
;
1789 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1791 p
->count
-= p
->pc_count
;
1800 /* Also discard relocs on undefined weak syms with non-default
1802 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1803 && h
->root
.type
== bfd_link_hash_undefweak
)
1804 eh
->dyn_relocs
= NULL
;
1806 else if (ELIMINATE_COPY_RELOCS
)
1808 /* For the non-shared case, discard space for relocs against
1809 symbols which turn out to need copy relocs or are not
1812 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1813 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1814 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1815 || (htab
->elf
.dynamic_sections_created
1816 && (h
->root
.type
== bfd_link_hash_undefweak
1817 || h
->root
.type
== bfd_link_hash_undefined
))))
1819 /* Make sure this symbol is output as a dynamic symbol.
1820 Undefined weak syms won't yet be marked as dynamic. */
1821 if (h
->dynindx
== -1
1822 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1824 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1828 /* If that succeeded, we know we'll be keeping all the
1830 if (h
->dynindx
!= -1)
1834 eh
->dyn_relocs
= NULL
;
1839 /* Finally, allocate space. */
1840 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1842 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1843 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1849 /* Find any dynamic relocs that apply to read-only sections. */
1852 readonly_dynrelocs (h
, inf
)
1853 struct elf_link_hash_entry
*h
;
1856 struct elf_s390_link_hash_entry
*eh
;
1857 struct elf_s390_dyn_relocs
*p
;
1859 if (h
->root
.type
== bfd_link_hash_warning
)
1860 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1862 eh
= (struct elf_s390_link_hash_entry
*) h
;
1863 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1865 asection
*s
= p
->sec
->output_section
;
1867 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1869 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1871 info
->flags
|= DF_TEXTREL
;
1873 /* Not an error, just cut short the traversal. */
1880 /* Set the sizes of the dynamic sections. */
1883 elf_s390_size_dynamic_sections (output_bfd
, info
)
1884 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1885 struct bfd_link_info
*info
;
1887 struct elf_s390_link_hash_table
*htab
;
1893 htab
= elf_s390_hash_table (info
);
1894 dynobj
= htab
->elf
.dynobj
;
1898 if (htab
->elf
.dynamic_sections_created
)
1900 /* Set the contents of the .interp section to the interpreter. */
1903 s
= bfd_get_section_by_name (dynobj
, ".interp");
1906 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1907 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1911 /* Set up .got offsets for local syms, and space for local dynamic
1913 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1915 bfd_signed_vma
*local_got
;
1916 bfd_signed_vma
*end_local_got
;
1917 char *local_tls_type
;
1918 bfd_size_type locsymcount
;
1919 Elf_Internal_Shdr
*symtab_hdr
;
1922 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1925 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1927 struct elf_s390_dyn_relocs
*p
;
1929 for (p
= *((struct elf_s390_dyn_relocs
**)
1930 &elf_section_data (s
)->local_dynrel
);
1934 if (!bfd_is_abs_section (p
->sec
)
1935 && bfd_is_abs_section (p
->sec
->output_section
))
1937 /* Input section has been discarded, either because
1938 it is a copy of a linkonce section or due to
1939 linker script /DISCARD/, so we'll be discarding
1942 else if (p
->count
!= 0)
1944 srela
= elf_section_data (p
->sec
)->sreloc
;
1945 srela
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1946 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1947 info
->flags
|= DF_TEXTREL
;
1952 local_got
= elf_local_got_refcounts (ibfd
);
1956 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1957 locsymcount
= symtab_hdr
->sh_info
;
1958 end_local_got
= local_got
+ locsymcount
;
1959 local_tls_type
= elf_s390_local_got_tls_type (ibfd
);
1961 srela
= htab
->srelgot
;
1962 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
1966 *local_got
= s
->_raw_size
;
1967 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1968 if (*local_tls_type
== GOT_TLS_GD
)
1969 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1971 srela
->_raw_size
+= sizeof (Elf64_External_Rela
);
1974 *local_got
= (bfd_vma
) -1;
1978 if (htab
->tls_ldm_got
.refcount
> 0)
1980 /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM64
1982 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
1983 htab
->sgot
->_raw_size
+= 2 * GOT_ENTRY_SIZE
;
1984 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1987 htab
->tls_ldm_got
.offset
= -1;
1989 /* Allocate global sym .plt and .got entries, and space for global
1990 sym dynamic relocs. */
1991 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1993 /* We now have determined the sizes of the various dynamic sections.
1994 Allocate memory for them. */
1996 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1998 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2003 || s
== htab
->sgotplt
)
2005 /* Strip this section if we don't need it; see the
2008 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
2010 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
2013 /* We use the reloc_count field as a counter if we need
2014 to copy relocs into the output file. */
2019 /* It's not one of our sections, so don't allocate space. */
2023 if (s
->_raw_size
== 0)
2025 /* If we don't need this section, strip it from the
2026 output file. This is to handle .rela.bss and
2027 .rela.plt. We must create it in
2028 create_dynamic_sections, because it must be created
2029 before the linker maps input sections to output
2030 sections. The linker does that before
2031 adjust_dynamic_symbol is called, and it is that
2032 function which decides whether anything needs to go
2033 into these sections. */
2035 _bfd_strip_section_from_output (info
, s
);
2039 /* Allocate memory for the section contents. We use bfd_zalloc
2040 here in case unused entries are not reclaimed before the
2041 section's contents are written out. This should not happen,
2042 but this way if it does, we get a R_390_NONE reloc instead
2044 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2045 if (s
->contents
== NULL
)
2049 if (htab
->elf
.dynamic_sections_created
)
2051 /* Add some entries to the .dynamic section. We fill in the
2052 values later, in elf_s390_finish_dynamic_sections, but we
2053 must add the entries now so that we get the correct size for
2054 the .dynamic section. The DT_DEBUG entry is filled in by the
2055 dynamic linker and used by the debugger. */
2056 #define add_dynamic_entry(TAG, VAL) \
2057 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2061 if (!add_dynamic_entry (DT_DEBUG
, 0))
2065 if (htab
->splt
->_raw_size
!= 0)
2067 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2068 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2069 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2070 || !add_dynamic_entry (DT_JMPREL
, 0))
2076 if (!add_dynamic_entry (DT_RELA
, 0)
2077 || !add_dynamic_entry (DT_RELASZ
, 0)
2078 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2081 /* If any dynamic relocs apply to a read-only section,
2082 then we need a DT_TEXTREL entry. */
2083 if ((info
->flags
& DF_TEXTREL
) == 0)
2084 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2087 if ((info
->flags
& DF_TEXTREL
) != 0)
2089 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2094 #undef add_dynamic_entry
2099 /* Return the base VMA address which should be subtracted from real addresses
2100 when resolving @dtpoff relocation.
2101 This is PT_TLS segment p_vaddr. */
2105 struct bfd_link_info
*info
;
2107 /* If tls_segment is NULL, we should have signalled an error already. */
2108 if (elf_hash_table (info
)->tls_segment
== NULL
)
2110 return elf_hash_table (info
)->tls_segment
->start
;
2113 /* Return the relocation value for @tpoff relocation
2114 if STT_TLS virtual address is ADDRESS. */
2117 tpoff (info
, address
)
2118 struct bfd_link_info
*info
;
2121 struct elf_link_tls_segment
*tls_segment
2122 = elf_hash_table (info
)->tls_segment
;
2124 /* If tls_segment is NULL, we should have signalled an error already. */
2125 if (tls_segment
== NULL
)
2127 return (align_power (tls_segment
->size
, tls_segment
->align
)
2128 + tls_segment
->start
- address
);
2131 /* Complain if TLS instruction relocation is against an invalid
2135 invalid_tls_insn (input_bfd
, input_section
, rel
)
2137 asection
*input_section
;
2138 Elf_Internal_Rela
*rel
;
2140 reloc_howto_type
*howto
;
2142 howto
= elf_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
2143 (*_bfd_error_handler
)
2144 (_("%s(%s+0x%lx): invalid instruction for TLS relocation %s"),
2145 bfd_archive_filename (input_bfd
),
2146 bfd_get_section_name (input_bfd
, input_section
),
2147 (long) rel
->r_offset
,
2151 /* Relocate a 390 ELF section. */
2154 elf_s390_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2155 contents
, relocs
, local_syms
, local_sections
)
2157 struct bfd_link_info
*info
;
2159 asection
*input_section
;
2161 Elf_Internal_Rela
*relocs
;
2162 Elf_Internal_Sym
*local_syms
;
2163 asection
**local_sections
;
2165 struct elf_s390_link_hash_table
*htab
;
2166 Elf_Internal_Shdr
*symtab_hdr
;
2167 struct elf_link_hash_entry
**sym_hashes
;
2168 bfd_vma
*local_got_offsets
;
2169 Elf_Internal_Rela
*rel
;
2170 Elf_Internal_Rela
*relend
;
2172 if (info
->relocateable
)
2175 htab
= elf_s390_hash_table (info
);
2176 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2177 sym_hashes
= elf_sym_hashes (input_bfd
);
2178 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2181 relend
= relocs
+ input_section
->reloc_count
;
2182 for (; rel
< relend
; rel
++)
2184 unsigned int r_type
;
2185 reloc_howto_type
*howto
;
2186 unsigned long r_symndx
;
2187 struct elf_link_hash_entry
*h
;
2188 Elf_Internal_Sym
*sym
;
2192 bfd_boolean unresolved_reloc
;
2193 bfd_reloc_status_type r
;
2196 r_type
= ELF64_R_TYPE (rel
->r_info
);
2197 if (r_type
== (int) R_390_GNU_VTINHERIT
2198 || r_type
== (int) R_390_GNU_VTENTRY
)
2200 if (r_type
>= (int) R_390_max
)
2202 bfd_set_error (bfd_error_bad_value
);
2206 howto
= elf_howto_table
+ r_type
;
2207 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2209 /* This is a final link. */
2213 unresolved_reloc
= FALSE
;
2214 if (r_symndx
< symtab_hdr
->sh_info
)
2216 sym
= local_syms
+ r_symndx
;
2217 sec
= local_sections
[r_symndx
];
2218 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
2222 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2223 while (h
->root
.type
== bfd_link_hash_indirect
2224 || h
->root
.type
== bfd_link_hash_warning
)
2225 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2227 if (h
->root
.type
== bfd_link_hash_defined
2228 || h
->root
.type
== bfd_link_hash_defweak
)
2230 sec
= h
->root
.u
.def
.section
;
2231 if (sec
->output_section
== NULL
)
2233 /* Set a flag that will be cleared later if we find a
2234 relocation value for this symbol. output_section
2235 is typically NULL for symbols satisfied by a shared
2237 unresolved_reloc
= TRUE
;
2241 relocation
= (h
->root
.u
.def
.value
2242 + sec
->output_section
->vma
2243 + sec
->output_offset
);
2245 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2247 else if (info
->shared
2248 && !info
->no_undefined
2249 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2253 if (! ((*info
->callbacks
->undefined_symbol
)
2254 (info
, h
->root
.root
.string
, input_bfd
,
2255 input_section
, rel
->r_offset
,
2256 (!info
->shared
|| info
->no_undefined
2257 || ELF_ST_VISIBILITY (h
->other
)))))
2265 case R_390_GOTPLT12
:
2266 case R_390_GOTPLT16
:
2267 case R_390_GOTPLT32
:
2268 case R_390_GOTPLT64
:
2269 case R_390_GOTPLTENT
:
2270 /* There are three cases for a GOTPLT relocation. 1) The
2271 relocation is against the jump slot entry of a plt that
2272 will get emitted to the output file. 2) The relocation
2273 is against the jump slot of a plt entry that has been
2274 removed. elf_s390_adjust_gotplt has created a GOT entry
2275 as replacement. 3) The relocation is against a local symbol.
2276 Cases 2) and 3) are the same as the GOT relocation code
2277 so we just have to test for case 1 and fall through for
2279 if (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
2284 Current offset - size first entry / entry size. */
2285 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) /
2288 /* Offset in GOT is PLT index plus GOT headers(3) times 4,
2290 relocation
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2291 unresolved_reloc
= FALSE
;
2293 if (r_type
== R_390_GOTPLTENT
)
2294 relocation
+= htab
->sgot
->output_section
->vma
;
2304 /* Relocation is to the entry for this symbol in the global
2306 if (htab
->sgot
== NULL
)
2313 off
= h
->got
.offset
;
2314 dyn
= htab
->elf
.dynamic_sections_created
;
2315 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2319 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
2320 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2321 || (ELF_ST_VISIBILITY (h
->other
)
2322 && h
->root
.type
== bfd_link_hash_undefweak
))
2324 /* This is actually a static link, or it is a
2325 -Bsymbolic link and the symbol is defined
2326 locally, or the symbol was forced to be local
2327 because of a version file. We must initialize
2328 this entry in the global offset table. Since the
2329 offset must always be a multiple of 2, we use the
2330 least significant bit to record whether we have
2331 initialized it already.
2333 When doing a dynamic link, we create a .rel.got
2334 relocation entry to initialize the value. This
2335 is done in the finish_dynamic_symbol routine. */
2340 bfd_put_64 (output_bfd
, relocation
,
2341 htab
->sgot
->contents
+ off
);
2346 unresolved_reloc
= FALSE
;
2350 if (local_got_offsets
== NULL
)
2353 off
= local_got_offsets
[r_symndx
];
2355 /* The offset must always be a multiple of 8. We use
2356 the least significant bit to record whether we have
2357 already generated the necessary reloc. */
2362 bfd_put_64 (output_bfd
, relocation
,
2363 htab
->sgot
->contents
+ off
);
2368 Elf_Internal_Rela outrel
;
2375 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2376 + htab
->sgot
->output_offset
2378 outrel
.r_info
= ELF64_R_INFO (0, R_390_RELATIVE
);
2379 outrel
.r_addend
= relocation
;
2381 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2382 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2385 local_got_offsets
[r_symndx
] |= 1;
2389 if (off
>= (bfd_vma
) -2)
2392 relocation
= htab
->sgot
->output_offset
+ off
;
2394 /* For @GOTENT the relocation is against the offset between
2395 the instruction and the symbols entry in the GOT and not
2396 between the start of the GOT and the symbols entry. We
2397 add the vma of the GOT to get the correct value. */
2398 if ( r_type
== R_390_GOTENT
2399 || r_type
== R_390_GOTPLTENT
)
2400 relocation
+= htab
->sgot
->output_section
->vma
;
2404 case R_390_GOTOFF16
:
2405 case R_390_GOTOFF32
:
2406 case R_390_GOTOFF64
:
2407 /* Relocation is relative to the start of the global offset
2410 /* Note that sgot->output_offset is not involved in this
2411 calculation. We always want the start of .got. If we
2412 defined _GLOBAL_OFFSET_TABLE in a different way, as is
2413 permitted by the ABI, we might have to change this
2415 relocation
-= htab
->sgot
->output_section
->vma
;
2419 case R_390_GOTPCDBL
:
2420 /* Use global offset table as symbol value. */
2421 relocation
= htab
->sgot
->output_section
->vma
;
2422 unresolved_reloc
= FALSE
;
2425 case R_390_PLT16DBL
:
2427 case R_390_PLT32DBL
:
2429 /* Relocation is to the entry for this symbol in the
2430 procedure linkage table. */
2432 /* Resolve a PLT32 reloc against a local symbol directly,
2433 without using the procedure linkage table. */
2437 if (h
->plt
.offset
== (bfd_vma
) -1
2438 || htab
->splt
== NULL
)
2440 /* We didn't make a PLT entry for this symbol. This
2441 happens when statically linking PIC code, or when
2442 using -Bsymbolic. */
2446 relocation
= (htab
->splt
->output_section
->vma
2447 + htab
->splt
->output_offset
2449 unresolved_reloc
= FALSE
;
2452 case R_390_PLTOFF16
:
2453 case R_390_PLTOFF32
:
2454 case R_390_PLTOFF64
:
2455 /* Relocation is to the entry for this symbol in the
2456 procedure linkage table relative to the start of the GOT. */
2458 /* For local symbols or if we didn't make a PLT entry for
2459 this symbol resolve the symbol directly. */
2461 || h
->plt
.offset
== (bfd_vma
) -1
2462 || htab
->splt
== NULL
)
2464 relocation
-= htab
->sgot
->output_section
->vma
;
2468 relocation
= (htab
->splt
->output_section
->vma
2469 + htab
->splt
->output_offset
2471 - htab
->sgot
->output_section
->vma
);
2472 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)
2493 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2494 || h
->root
.type
!= bfd_link_hash_undefweak
)
2495 && ((r_type
!= R_390_PC16
2496 && r_type
!= R_390_PC16DBL
2497 && r_type
!= R_390_PC32
2498 && r_type
!= R_390_PC32DBL
2499 && r_type
!= R_390_PC64
)
2502 && (! info
->symbolic
2503 || (h
->elf_link_hash_flags
2504 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2505 || (ELIMINATE_COPY_RELOCS
2509 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2510 && (((h
->elf_link_hash_flags
2511 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2512 && (h
->elf_link_hash_flags
2513 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2514 || h
->root
.type
== bfd_link_hash_undefweak
2515 || h
->root
.type
== bfd_link_hash_undefined
)))
2517 Elf_Internal_Rela outrel
;
2518 bfd_boolean skip
, relocate
;
2522 /* When generating a shared object, these relocations
2523 are copied into the output file to be resolved at run
2529 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2531 if (outrel
.r_offset
== (bfd_vma
) -1)
2533 else if (outrel
.r_offset
== (bfd_vma
) -2)
2534 skip
= TRUE
, relocate
= TRUE
;
2536 outrel
.r_offset
+= (input_section
->output_section
->vma
2537 + input_section
->output_offset
);
2540 memset (&outrel
, 0, sizeof outrel
);
2543 && (r_type
== R_390_PC16
2544 || r_type
== R_390_PC16DBL
2545 || r_type
== R_390_PC32
2546 || r_type
== R_390_PC32DBL
2547 || r_type
== R_390_PC64
2550 || (h
->elf_link_hash_flags
2551 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2553 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
2554 outrel
.r_addend
= rel
->r_addend
;
2558 /* This symbol is local, or marked to become local. */
2560 outrel
.r_info
= ELF64_R_INFO (0, R_390_RELATIVE
);
2561 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2564 sreloc
= elf_section_data (input_section
)->sreloc
;
2568 loc
= sreloc
->contents
;
2569 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2570 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2572 /* If this reloc is against an external symbol, we do
2573 not want to fiddle with the addend. Otherwise, we
2574 need to include the symbol value so that it becomes
2575 an addend for the dynamic reloc. */
2582 /* Relocations for tls literal pool entries. */
2583 case R_390_TLS_IE64
:
2586 Elf_Internal_Rela outrel
;
2590 outrel
.r_offset
= rel
->r_offset
2591 + input_section
->output_section
->vma
2592 + input_section
->output_offset
;
2593 outrel
.r_info
= ELF64_R_INFO (0, R_390_RELATIVE
);
2594 sreloc
= elf_section_data (input_section
)->sreloc
;
2597 loc
= sreloc
->contents
;
2598 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2599 bfd_elf64_swap_reloc_out (output_bfd
, &outrel
, loc
);
2603 case R_390_TLS_GD64
:
2604 case R_390_TLS_GOTIE64
:
2605 r_type
= elf_s390_tls_transition (info
, r_type
, h
== NULL
);
2606 tls_type
= GOT_UNKNOWN
;
2607 if (h
== NULL
&& local_got_offsets
)
2608 tls_type
= elf_s390_local_got_tls_type (input_bfd
) [r_symndx
];
2611 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2612 if (!info
->shared
&& h
->dynindx
== -1 && tls_type
>= GOT_TLS_IE
)
2613 r_type
= R_390_TLS_LE64
;
2615 if (r_type
== R_390_TLS_GD64
&& tls_type
>= GOT_TLS_IE
)
2616 r_type
= R_390_TLS_IE64
;
2618 if (r_type
== R_390_TLS_LE64
)
2620 /* This relocation gets optimized away by the local exec
2621 access optimization. */
2622 BFD_ASSERT (! unresolved_reloc
);
2623 bfd_put_64 (output_bfd
, -tpoff (info
, relocation
),
2624 contents
+ rel
->r_offset
);
2628 if (htab
->sgot
== NULL
)
2632 off
= h
->got
.offset
;
2635 if (local_got_offsets
== NULL
)
2638 off
= local_got_offsets
[r_symndx
];
2647 Elf_Internal_Rela outrel
;
2651 if (htab
->srelgot
== NULL
)
2654 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2655 + htab
->sgot
->output_offset
+ off
);
2657 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2658 if (r_type
== R_390_TLS_GD64
)
2659 dr_type
= R_390_TLS_DTPMOD
;
2661 dr_type
= R_390_TLS_TPOFF
;
2662 if (dr_type
== R_390_TLS_TPOFF
&& indx
== 0)
2663 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2665 outrel
.r_addend
= 0;
2666 outrel
.r_info
= ELF64_R_INFO (indx
, dr_type
);
2667 loc
= htab
->srelgot
->contents
;
2668 loc
+= htab
->srelgot
->reloc_count
++
2669 * sizeof (Elf64_External_Rela
);
2670 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2672 if (r_type
== R_390_TLS_GD64
)
2676 BFD_ASSERT (! unresolved_reloc
);
2677 bfd_put_64 (output_bfd
,
2678 relocation
- dtpoff_base (info
),
2679 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2683 outrel
.r_info
= ELF64_R_INFO (indx
, R_390_TLS_DTPOFF
);
2684 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
2685 outrel
.r_addend
= 0;
2686 htab
->srelgot
->reloc_count
++;
2687 loc
+= sizeof (Elf64_External_Rela
);
2688 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2695 local_got_offsets
[r_symndx
] |= 1;
2698 if (off
>= (bfd_vma
) -2)
2700 if (r_type
== ELF64_R_TYPE (rel
->r_info
))
2702 relocation
= htab
->sgot
->output_offset
+ off
;
2703 if (r_type
== R_390_TLS_IE64
|| r_type
== R_390_TLS_IEENT
)
2704 relocation
+= htab
->sgot
->output_section
->vma
;
2705 unresolved_reloc
= FALSE
;
2709 bfd_put_64 (output_bfd
, htab
->sgot
->output_offset
+ off
,
2710 contents
+ rel
->r_offset
);
2715 case R_390_TLS_GOTIE12
:
2716 case R_390_TLS_IEENT
:
2719 if (local_got_offsets
== NULL
)
2721 off
= local_got_offsets
[r_symndx
];
2723 goto emit_tls_relocs
;
2727 off
= h
->got
.offset
;
2728 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2729 if (info
->shared
|| h
->dynindx
!= -1 || tls_type
< GOT_TLS_IE
)
2730 goto emit_tls_relocs
;
2733 if (htab
->sgot
== NULL
)
2736 BFD_ASSERT (! unresolved_reloc
);
2737 bfd_put_64 (output_bfd
, -tpoff (info
, relocation
),
2738 htab
->sgot
->contents
+ off
);
2739 relocation
= htab
->sgot
->output_offset
+ off
;
2740 if (r_type
== R_390_TLS_IEENT
)
2741 relocation
+= htab
->sgot
->output_section
->vma
;
2742 unresolved_reloc
= FALSE
;
2745 case R_390_TLS_LDM64
:
2747 /* The literal pool entry this relocation refers to gets ignored
2748 by the optimized code of the local exec model. Do nothing
2749 and the value will turn out zero. */
2752 if (htab
->sgot
== NULL
)
2755 off
= htab
->tls_ldm_got
.offset
;
2760 Elf_Internal_Rela outrel
;
2763 if (htab
->srelgot
== NULL
)
2766 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2767 + htab
->sgot
->output_offset
+ off
);
2769 bfd_put_64 (output_bfd
, 0,
2770 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2771 outrel
.r_info
= ELF64_R_INFO (0, R_390_TLS_DTPMOD
);
2772 outrel
.r_addend
= 0;
2773 loc
= htab
->srelgot
->contents
;
2774 loc
+= htab
->srelgot
->reloc_count
++
2775 * sizeof (Elf64_External_Rela
);
2776 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2777 htab
->tls_ldm_got
.offset
|= 1;
2779 relocation
= htab
->sgot
->output_offset
+ off
;
2780 unresolved_reloc
= FALSE
;
2783 case R_390_TLS_LE64
:
2786 /* Linking a shared library with non-fpic code requires
2787 a R_390_TLS_TPOFF relocation. */
2788 Elf_Internal_Rela outrel
;
2793 outrel
.r_offset
= rel
->r_offset
2794 + input_section
->output_section
->vma
2795 + input_section
->output_offset
;
2796 if (h
!= NULL
&& h
->dynindx
!= -1)
2800 outrel
.r_info
= ELF64_R_INFO (indx
, R_390_TLS_TPOFF
);
2802 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2804 outrel
.r_addend
= 0;
2805 sreloc
= elf_section_data (input_section
)->sreloc
;
2808 loc
= sreloc
->contents
;
2809 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2810 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2814 BFD_ASSERT (! unresolved_reloc
);
2815 bfd_put_64 (output_bfd
, -tpoff (info
, relocation
),
2816 contents
+ rel
->r_offset
);
2820 case R_390_TLS_LDO64
:
2821 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
2822 relocation
-= dtpoff_base (info
);
2824 /* When converting LDO to LE, we must negate. */
2825 relocation
= -tpoff (info
, relocation
);
2828 /* Relocations for tls instructions. */
2829 case R_390_TLS_LOAD
:
2830 case R_390_TLS_GDCALL
:
2831 case R_390_TLS_LDCALL
:
2832 tls_type
= GOT_UNKNOWN
;
2833 if (h
== NULL
&& local_got_offsets
)
2834 tls_type
= elf_s390_local_got_tls_type (input_bfd
) [r_symndx
];
2836 tls_type
= elf_s390_hash_entry(h
)->tls_type
;
2838 if (tls_type
== GOT_TLS_GD
)
2841 if (r_type
== R_390_TLS_LOAD
)
2843 if (!info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
2845 /* IE->LE transition. Four valid cases:
2846 lg %rx,(0,%ry) -> sllg %rx,%ry,0
2847 lg %rx,(%ry,0) -> sllg %rx,%ry,0
2848 lg %rx,(%ry,%r12) -> sllg %rx,%ry,0
2849 lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 */
2850 unsigned int insn0
, insn1
, ry
;
2852 insn0
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2853 insn1
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 4);
2854 if (insn1
!= 0x0004)
2855 invalid_tls_insn (input_bfd
, input_section
, rel
);
2857 if ((insn0
& 0xff00f000) == 0xe3000000)
2858 /* lg %rx,0(%ry,0) -> sllg %rx,%ry,0 */
2859 ry
= (insn0
& 0x000f0000);
2860 else if ((insn0
& 0xff0f0000) == 0xe3000000)
2861 /* lg %rx,0(0,%ry) -> sllg %rx,%ry,0 */
2862 ry
= (insn0
& 0x0000f000) << 4;
2863 else if ((insn0
& 0xff00f000) == 0xe300c000)
2864 /* lg %rx,0(%ry,%r12) -> sllg %rx,%ry,0 */
2865 ry
= (insn0
& 0x000f0000);
2866 else if ((insn0
& 0xff0f0000) == 0xe30c0000)
2867 /* lg %rx,0(%r12,%ry) -> sllg %rx,%ry,0 */
2868 ry
= (insn0
& 0x0000f000) << 4;
2870 invalid_tls_insn (input_bfd
, input_section
, rel
);
2871 insn0
= 0xeb000000 | (insn0
& 0x00f00000) | ry
;
2873 bfd_put_32 (output_bfd
, insn0
, contents
+ rel
->r_offset
);
2874 bfd_put_16 (output_bfd
, insn1
, contents
+ rel
->r_offset
+ 4);
2877 else if (r_type
== R_390_TLS_GDCALL
)
2879 unsigned int insn0
, insn1
;
2881 insn0
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2882 insn1
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 4);
2883 if ((insn0
& 0xffff0000) != 0xc0e50000)
2884 invalid_tls_insn (input_bfd
, input_section
, rel
);
2885 if (!info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
2887 /* GD->LE transition.
2888 brasl %r14,__tls_get_addr@plt -> brcl 0,. */
2894 /* GD->IE transition.
2895 brasl %r14,__tls_get_addr@plt -> lg %r2,0(%r2,%r12) */
2899 bfd_put_32 (output_bfd
, insn0
, contents
+ rel
->r_offset
);
2900 bfd_put_16 (output_bfd
, insn1
, contents
+ rel
->r_offset
+ 4);
2902 else if (r_type
== R_390_TLS_LDCALL
)
2906 unsigned int insn0
, insn1
;
2908 insn0
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2909 insn1
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 4);
2910 if ((insn0
& 0xffff0000) != 0xc0e50000)
2911 invalid_tls_insn (input_bfd
, input_section
, rel
);
2912 /* LD->LE transition.
2913 brasl %r14,__tls_get_addr@plt -> brcl 0,. */
2916 bfd_put_32 (output_bfd
, insn0
, contents
+ rel
->r_offset
);
2917 bfd_put_16 (output_bfd
, insn1
, contents
+ rel
->r_offset
+ 4);
2926 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2927 because such sections are not SEC_ALLOC and thus ld.so will
2928 not process them. */
2929 if (unresolved_reloc
2930 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
2931 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2932 (*_bfd_error_handler
)
2933 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
2934 bfd_archive_filename (input_bfd
),
2935 bfd_get_section_name (input_bfd
, input_section
),
2936 (long) rel
->r_offset
,
2937 h
->root
.root
.string
);
2939 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2940 contents
, rel
->r_offset
,
2941 relocation
, rel
->r_addend
);
2943 if (r
!= bfd_reloc_ok
)
2948 name
= h
->root
.root
.string
;
2951 name
= bfd_elf_string_from_elf_section (input_bfd
,
2952 symtab_hdr
->sh_link
,
2957 name
= bfd_section_name (input_bfd
, sec
);
2960 if (r
== bfd_reloc_overflow
)
2963 if (! ((*info
->callbacks
->reloc_overflow
)
2964 (info
, name
, howto
->name
, (bfd_vma
) 0,
2965 input_bfd
, input_section
, rel
->r_offset
)))
2970 (*_bfd_error_handler
)
2971 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
2972 bfd_archive_filename (input_bfd
),
2973 bfd_get_section_name (input_bfd
, input_section
),
2974 (long) rel
->r_offset
, name
, (int) r
);
2983 /* Finish up dynamic symbol handling. We set the contents of various
2984 dynamic sections here. */
2987 elf_s390_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2989 struct bfd_link_info
*info
;
2990 struct elf_link_hash_entry
*h
;
2991 Elf_Internal_Sym
*sym
;
2993 struct elf_s390_link_hash_table
*htab
;
2995 htab
= elf_s390_hash_table (info
);
2997 if (h
->plt
.offset
!= (bfd_vma
) -1)
3001 Elf_Internal_Rela rela
;
3004 /* This symbol has an entry in the procedure linkage table. Set
3007 if (h
->dynindx
== -1
3008 || htab
->splt
== NULL
3009 || htab
->sgotplt
== NULL
3010 || htab
->srelplt
== NULL
)
3014 Current offset - size first entry / entry size. */
3015 plt_index
= (h
->plt
.offset
- PLT_FIRST_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3017 /* Offset in GOT is PLT index plus GOT headers(3) times 8,
3019 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3021 /* Fill in the blueprint of a PLT. */
3022 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD0
,
3023 htab
->splt
->contents
+ h
->plt
.offset
);
3024 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD1
,
3025 htab
->splt
->contents
+ h
->plt
.offset
+ 4);
3026 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD2
,
3027 htab
->splt
->contents
+ h
->plt
.offset
+ 8);
3028 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD3
,
3029 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
3030 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD4
,
3031 htab
->splt
->contents
+ h
->plt
.offset
+ 16);
3032 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD5
,
3033 htab
->splt
->contents
+ h
->plt
.offset
+ 20);
3034 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD6
,
3035 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3036 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_ENTRY_WORD7
,
3037 htab
->splt
->contents
+ h
->plt
.offset
+ 28);
3038 /* Fixup the relative address to the GOT entry */
3039 bfd_put_32 (output_bfd
,
3040 (htab
->sgotplt
->output_section
->vma
+
3041 htab
->sgotplt
->output_offset
+ got_offset
3042 - (htab
->splt
->output_section
->vma
+ h
->plt
.offset
))/2,
3043 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
3044 /* Fixup the relative branch to PLT 0 */
3045 bfd_put_32 (output_bfd
, - (PLT_FIRST_ENTRY_SIZE
+
3046 (PLT_ENTRY_SIZE
* plt_index
) + 22)/2,
3047 htab
->splt
->contents
+ h
->plt
.offset
+ 24);
3048 /* Fixup offset into symbol table */
3049 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf64_External_Rela
),
3050 htab
->splt
->contents
+ h
->plt
.offset
+ 28);
3052 /* Fill in the entry in the global offset table.
3053 Points to instruction after GOT offset. */
3054 bfd_put_64 (output_bfd
,
3055 (htab
->splt
->output_section
->vma
3056 + htab
->splt
->output_offset
3059 htab
->sgotplt
->contents
+ got_offset
);
3061 /* Fill in the entry in the .rela.plt section. */
3062 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
3063 + htab
->sgotplt
->output_offset
3065 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_390_JMP_SLOT
);
3067 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
3068 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3070 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3072 /* Mark the symbol as undefined, rather than as defined in
3073 the .plt section. Leave the value alone. This is a clue
3074 for the dynamic linker, to make function pointer
3075 comparisons work between an application and shared
3077 sym
->st_shndx
= SHN_UNDEF
;
3081 if (h
->got
.offset
!= (bfd_vma
) -1
3082 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_GD
3083 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_IE
3084 && elf_s390_hash_entry(h
)->tls_type
!= GOT_TLS_IE_NLT
)
3086 Elf_Internal_Rela rela
;
3089 /* This symbol has an entry in the global offset table. Set it
3091 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3094 rela
.r_offset
= (htab
->sgot
->output_section
->vma
3095 + htab
->sgot
->output_offset
3096 + (h
->got
.offset
&~ (bfd_vma
) 1));
3098 /* If this is a static link, or it is a -Bsymbolic link and the
3099 symbol is defined locally or was forced to be local because
3100 of a version file, we just want to emit a RELATIVE reloc.
3101 The entry in the global offset table will already have been
3102 initialized in the relocate_section function. */
3106 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
3107 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3109 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3110 rela
.r_info
= ELF64_R_INFO (0, R_390_RELATIVE
);
3111 rela
.r_addend
= (h
->root
.u
.def
.value
3112 + h
->root
.u
.def
.section
->output_section
->vma
3113 + h
->root
.u
.def
.section
->output_offset
);
3117 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3118 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgot
->contents
+ h
->got
.offset
);
3119 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_390_GLOB_DAT
);
3123 loc
= htab
->srelgot
->contents
;
3124 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3125 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3128 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3130 Elf_Internal_Rela rela
;
3133 /* This symbols needs a copy reloc. Set it up. */
3135 if (h
->dynindx
== -1
3136 || (h
->root
.type
!= bfd_link_hash_defined
3137 && h
->root
.type
!= bfd_link_hash_defweak
)
3138 || htab
->srelbss
== NULL
)
3141 rela
.r_offset
= (h
->root
.u
.def
.value
3142 + h
->root
.u
.def
.section
->output_section
->vma
3143 + h
->root
.u
.def
.section
->output_offset
);
3144 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_390_COPY
);
3146 loc
= htab
->srelbss
->contents
;
3147 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3148 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3151 /* Mark some specially defined symbols as absolute. */
3152 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3153 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3154 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3155 sym
->st_shndx
= SHN_ABS
;
3160 /* Used to decide how to sort relocs in an optimal manner for the
3161 dynamic linker, before writing them out. */
3163 static enum elf_reloc_type_class
3164 elf_s390_reloc_type_class (rela
)
3165 const Elf_Internal_Rela
*rela
;
3167 switch ((int) ELF64_R_TYPE (rela
->r_info
))
3169 case R_390_RELATIVE
:
3170 return reloc_class_relative
;
3171 case R_390_JMP_SLOT
:
3172 return reloc_class_plt
;
3174 return reloc_class_copy
;
3176 return reloc_class_normal
;
3180 /* Finish up the dynamic sections. */
3183 elf_s390_finish_dynamic_sections (output_bfd
, info
)
3185 struct bfd_link_info
*info
;
3187 struct elf_s390_link_hash_table
*htab
;
3191 htab
= elf_s390_hash_table (info
);
3192 dynobj
= htab
->elf
.dynobj
;
3193 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3195 if (htab
->elf
.dynamic_sections_created
)
3197 Elf64_External_Dyn
*dyncon
, *dynconend
;
3199 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3202 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3203 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3204 for (; dyncon
< dynconend
; dyncon
++)
3206 Elf_Internal_Dyn dyn
;
3209 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3217 dyn
.d_un
.d_ptr
= htab
->sgot
->output_section
->vma
;
3221 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
3225 s
= htab
->srelplt
->output_section
;
3226 if (s
->_cooked_size
!= 0)
3227 dyn
.d_un
.d_val
= s
->_cooked_size
;
3229 dyn
.d_un
.d_val
= s
->_raw_size
;
3233 /* The procedure linkage table relocs (DT_JMPREL) should
3234 not be included in the overall relocs (DT_RELA).
3235 Therefore, we override the DT_RELASZ entry here to
3236 make it not include the JMPREL relocs. Since the
3237 linker script arranges for .rela.plt to follow all
3238 other relocation sections, we don't have to worry
3239 about changing the DT_RELA entry. */
3240 s
= htab
->srelplt
->output_section
;
3241 if (s
->_cooked_size
!= 0)
3242 dyn
.d_un
.d_val
-= s
->_cooked_size
;
3244 dyn
.d_un
.d_val
-= s
->_raw_size
;
3248 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3251 /* Fill in the special first entry in the procedure linkage table. */
3252 if (htab
->splt
&& htab
->splt
->_raw_size
> 0)
3254 /* fill in blueprint for plt 0 entry */
3255 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD0
,
3256 htab
->splt
->contents
);
3257 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD1
,
3258 htab
->splt
->contents
+4 );
3259 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD3
,
3260 htab
->splt
->contents
+12 );
3261 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD4
,
3262 htab
->splt
->contents
+16 );
3263 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD5
,
3264 htab
->splt
->contents
+20 );
3265 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD6
,
3266 htab
->splt
->contents
+ 24);
3267 bfd_put_32 (output_bfd
, (bfd_vma
) PLT_FIRST_ENTRY_WORD7
,
3268 htab
->splt
->contents
+ 28 );
3269 /* Fixup relative address to start of GOT */
3270 bfd_put_32 (output_bfd
,
3271 (htab
->sgotplt
->output_section
->vma
+
3272 htab
->sgotplt
->output_offset
3273 - htab
->splt
->output_section
->vma
- 6)/2,
3274 htab
->splt
->contents
+ 8);
3276 elf_section_data (htab
->splt
->output_section
)
3277 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
3282 /* Fill in the first three entries in the global offset table. */
3283 if (htab
->sgotplt
->_raw_size
> 0)
3285 bfd_put_64 (output_bfd
,
3286 (sdyn
== NULL
? (bfd_vma
) 0
3287 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
3288 htab
->sgotplt
->contents
);
3289 /* One entry for shared object struct ptr. */
3290 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 8);
3291 /* One entry for _dl_runtime_resolve. */
3292 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ 12);
3295 elf_section_data (htab
->sgot
->output_section
)
3296 ->this_hdr
.sh_entsize
= 8;
3301 /* Why was the hash table entry size definition changed from
3302 ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
3303 this is the only reason for the s390_elf64_size_info structure. */
3305 const struct elf_size_info s390_elf64_size_info
=
3307 sizeof (Elf64_External_Ehdr
),
3308 sizeof (Elf64_External_Phdr
),
3309 sizeof (Elf64_External_Shdr
),
3310 sizeof (Elf64_External_Rel
),
3311 sizeof (Elf64_External_Rela
),
3312 sizeof (Elf64_External_Sym
),
3313 sizeof (Elf64_External_Dyn
),
3314 sizeof (Elf_External_Note
),
3315 8, /* hash-table entry size. */
3316 1, /* internal relocations per external relocations. */
3317 64, /* arch_size. */
3318 3, /* log_file_align. */
3319 ELFCLASS64
, EV_CURRENT
,
3320 bfd_elf64_write_out_phdrs
,
3321 bfd_elf64_write_shdrs_and_ehdr
,
3322 bfd_elf64_write_relocs
,
3323 bfd_elf64_swap_symbol_in
,
3324 bfd_elf64_swap_symbol_out
,
3325 bfd_elf64_slurp_reloc_table
,
3326 bfd_elf64_slurp_symbol_table
,
3327 bfd_elf64_swap_dyn_in
,
3328 bfd_elf64_swap_dyn_out
,
3329 bfd_elf64_swap_reloc_in
,
3330 bfd_elf64_swap_reloc_out
,
3331 bfd_elf64_swap_reloca_in
,
3332 bfd_elf64_swap_reloca_out
3335 #define TARGET_BIG_SYM bfd_elf64_s390_vec
3336 #define TARGET_BIG_NAME "elf64-s390"
3337 #define ELF_ARCH bfd_arch_s390
3338 #define ELF_MACHINE_CODE EM_S390
3339 #define ELF_MACHINE_ALT1 EM_S390_OLD
3340 #define ELF_MAXPAGESIZE 0x1000
3342 #define elf_backend_size_info s390_elf64_size_info
3344 #define elf_backend_can_gc_sections 1
3345 #define elf_backend_can_refcount 1
3346 #define elf_backend_want_got_plt 1
3347 #define elf_backend_plt_readonly 1
3348 #define elf_backend_want_plt_sym 0
3349 #define elf_backend_got_header_size 24
3350 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
3351 #define elf_backend_rela_normal 1
3353 #define elf_info_to_howto elf_s390_info_to_howto
3355 #define bfd_elf64_bfd_is_local_label_name elf_s390_is_local_label_name
3356 #define bfd_elf64_bfd_link_hash_table_create elf_s390_link_hash_table_create
3357 #define bfd_elf64_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
3359 #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
3360 #define elf_backend_check_relocs elf_s390_check_relocs
3361 #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
3362 #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
3363 #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
3364 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
3365 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
3366 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
3367 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3368 #define elf_backend_relocate_section elf_s390_relocate_section
3369 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
3370 #define elf_backend_reloc_type_class elf_s390_reloc_type_class
3372 #define bfd_elf64_mkobject elf_s390_mkobject
3373 #define elf_backend_object_p elf_s390_object_p
3375 #include "elf64-target.h"