Commit | Line | Data |
---|---|---|
a85d7ed0 | 1 | /* IBM S/390-specific support for 32-bit ELF |
e92d460e | 2 | Copyright 2000, 2001, 2002 Free Software Foundation, Inc. |
a85d7ed0 NC |
3 | Contributed by Carl B. Pedersen and Martin Schwidefsky. |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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 | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
24 | #include "bfdlink.h" | |
25 | #include "libbfd.h" | |
26 | #include "elf-bfd.h" | |
27 | ||
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 *)); | |
b34976b6 | 32 | static bfd_boolean elf_s390_is_local_label_name |
0451c93c MS |
33 | PARAMS ((bfd *, const char *)); |
34 | static struct bfd_hash_entry *link_hash_newfunc | |
a85d7ed0 NC |
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 | |
37 | PARAMS ((bfd *)); | |
b34976b6 | 38 | static bfd_boolean create_got_section |
0451c93c | 39 | PARAMS((bfd *, struct bfd_link_info *)); |
b34976b6 | 40 | static bfd_boolean elf_s390_create_dynamic_sections |
0451c93c MS |
41 | PARAMS((bfd *, struct bfd_link_info *)); |
42 | static void elf_s390_copy_indirect_symbol | |
b48fa14c AM |
43 | PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *, |
44 | struct elf_link_hash_entry *)); | |
b34976b6 | 45 | static bfd_boolean elf_s390_check_relocs |
a85d7ed0 NC |
46 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
47 | const Elf_Internal_Rela *)); | |
5a65713f | 48 | static asection *elf_s390_gc_mark_hook |
1e2f5b6e | 49 | PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
0451c93c | 50 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); |
b34976b6 | 51 | static bfd_boolean elf_s390_gc_sweep_hook |
5a65713f AJ |
52 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
53 | const Elf_Internal_Rela *)); | |
5236c819 MS |
54 | struct elf_s390_link_hash_entry; |
55 | static void elf_s390_adjust_gotplt | |
56 | PARAMS ((struct elf_s390_link_hash_entry *)); | |
b34976b6 | 57 | static bfd_boolean elf_s390_adjust_dynamic_symbol |
a85d7ed0 | 58 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); |
b34976b6 | 59 | static bfd_boolean allocate_dynrelocs |
0451c93c | 60 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
b34976b6 | 61 | static bfd_boolean readonly_dynrelocs |
0451c93c | 62 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
b34976b6 | 63 | static bfd_boolean elf_s390_size_dynamic_sections |
a85d7ed0 | 64 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 | 65 | static bfd_boolean elf_s390_relocate_section |
a85d7ed0 NC |
66 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
67 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
b34976b6 | 68 | static bfd_boolean elf_s390_finish_dynamic_symbol |
a85d7ed0 NC |
69 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, |
70 | Elf_Internal_Sym *)); | |
0451c93c MS |
71 | static enum elf_reloc_type_class elf_s390_reloc_type_class |
72 | PARAMS ((const Elf_Internal_Rela *)); | |
b34976b6 | 73 | static bfd_boolean elf_s390_finish_dynamic_sections |
a85d7ed0 | 74 | PARAMS ((bfd *, struct bfd_link_info *)); |
69fc87f1 MS |
75 | static bfd_boolean elf_s390_mkobject |
76 | PARAMS ((bfd *)); | |
b34976b6 AM |
77 | static bfd_boolean elf_s390_object_p |
78 | PARAMS ((bfd *)); | |
79 | static bfd_boolean elf_s390_grok_prstatus | |
80 | PARAMS ((bfd *, Elf_Internal_Note *)); | |
69fc87f1 MS |
81 | static int elf_s390_tls_transition |
82 | PARAMS ((struct bfd_link_info *, int, int)); | |
83 | static bfd_reloc_status_type s390_tls_reloc | |
84 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
85 | static bfd_vma dtpoff_base | |
86 | PARAMS ((struct bfd_link_info *)); | |
87 | static bfd_vma tpoff | |
88 | PARAMS ((struct bfd_link_info *, bfd_vma)); | |
89 | static void invalid_tls_insn | |
90 | PARAMS ((bfd *, asection *, Elf_Internal_Rela *)); | |
a85d7ed0 | 91 | |
a85d7ed0 NC |
92 | #include "elf/s390.h" |
93 | ||
94 | /* The relocation "howto" table. */ | |
95 | ||
96 | static reloc_howto_type elf_howto_table[] = | |
97 | { | |
98 | HOWTO (R_390_NONE, /* type */ | |
99 | 0, /* rightshift */ | |
100 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
101 | 0, /* bitsize */ | |
b34976b6 | 102 | FALSE, /* pc_relative */ |
a85d7ed0 NC |
103 | 0, /* bitpos */ |
104 | complain_overflow_dont, /* complain_on_overflow */ | |
105 | bfd_elf_generic_reloc, /* special_function */ | |
106 | "R_390_NONE", /* name */ | |
b34976b6 | 107 | FALSE, /* partial_inplace */ |
a85d7ed0 NC |
108 | 0, /* src_mask */ |
109 | 0, /* dst_mask */ | |
b34976b6 AM |
110 | FALSE), /* pcrel_offset */ |
111 | ||
5236c819 MS |
112 | HOWTO(R_390_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, |
113 | bfd_elf_generic_reloc, "R_390_8", FALSE, 0,0x000000ff, FALSE), | |
114 | HOWTO(R_390_12, 0, 1, 12, FALSE, 0, complain_overflow_dont, | |
115 | bfd_elf_generic_reloc, "R_390_12", FALSE, 0,0x00000fff, FALSE), | |
116 | HOWTO(R_390_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, | |
117 | bfd_elf_generic_reloc, "R_390_16", FALSE, 0,0x0000ffff, FALSE), | |
118 | HOWTO(R_390_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
119 | bfd_elf_generic_reloc, "R_390_32", FALSE, 0,0xffffffff, FALSE), | |
120 | HOWTO(R_390_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
121 | bfd_elf_generic_reloc, "R_390_PC32", FALSE, 0,0xffffffff, TRUE), | |
122 | HOWTO(R_390_GOT12, 0, 1, 12, FALSE, 0, complain_overflow_dont, | |
123 | bfd_elf_generic_reloc, "R_390_GOT12", FALSE, 0,0x00000fff, FALSE), | |
124 | HOWTO(R_390_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
125 | bfd_elf_generic_reloc, "R_390_GOT32", FALSE, 0,0xffffffff, FALSE), | |
126 | HOWTO(R_390_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
127 | bfd_elf_generic_reloc, "R_390_PLT32", FALSE, 0,0xffffffff, TRUE), | |
128 | HOWTO(R_390_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
129 | bfd_elf_generic_reloc, "R_390_COPY", FALSE, 0,0xffffffff, FALSE), | |
130 | HOWTO(R_390_GLOB_DAT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
131 | bfd_elf_generic_reloc, "R_390_GLOB_DAT", FALSE, 0,0xffffffff, FALSE), | |
132 | HOWTO(R_390_JMP_SLOT, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
133 | bfd_elf_generic_reloc, "R_390_JMP_SLOT", FALSE, 0,0xffffffff, FALSE), | |
134 | HOWTO(R_390_RELATIVE, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
135 | bfd_elf_generic_reloc, "R_390_RELATIVE", FALSE, 0,0xffffffff, FALSE), | |
136 | HOWTO(R_390_GOTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
137 | bfd_elf_generic_reloc, "R_390_GOTOFF32", FALSE, 0,0xffffffff, FALSE), | |
138 | HOWTO(R_390_GOTPC, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
139 | bfd_elf_generic_reloc, "R_390_GOTPC", FALSE, 0,0xffffffff, TRUE), | |
140 | HOWTO(R_390_GOT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, | |
141 | bfd_elf_generic_reloc, "R_390_GOT16", FALSE, 0,0x0000ffff, FALSE), | |
142 | HOWTO(R_390_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield, | |
143 | bfd_elf_generic_reloc, "R_390_PC16", FALSE, 0,0x0000ffff, TRUE), | |
144 | HOWTO(R_390_PC16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield, | |
145 | bfd_elf_generic_reloc, "R_390_PC16DBL", FALSE, 0,0x0000ffff, TRUE), | |
146 | HOWTO(R_390_PLT16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield, | |
147 | bfd_elf_generic_reloc, "R_390_PLT16DBL", FALSE, 0,0x0000ffff, TRUE), | |
148 | HOWTO(R_390_PC32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
149 | bfd_elf_generic_reloc, "R_390_PC32DBL", FALSE, 0,0xffffffff, TRUE), | |
150 | HOWTO(R_390_PLT32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
151 | bfd_elf_generic_reloc, "R_390_PLT32DBL", FALSE, 0,0xffffffff, TRUE), | |
152 | HOWTO(R_390_GOTPCDBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
153 | bfd_elf_generic_reloc, "R_390_GOTPCDBL", FALSE, 0,0xffffffff, TRUE), | |
154 | EMPTY_HOWTO (R_390_64), /* Empty entry for R_390_64. */ | |
155 | EMPTY_HOWTO (R_390_PC64), /* Empty entry for R_390_PC64. */ | |
156 | EMPTY_HOWTO (R_390_GOT64), /* Empty entry for R_390_GOT64. */ | |
157 | EMPTY_HOWTO (R_390_PLT64), /* Empty entry for R_390_PLT64. */ | |
158 | HOWTO(R_390_GOTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
159 | bfd_elf_generic_reloc, "R_390_GOTENT", FALSE, 0,0xffffffff, TRUE), | |
160 | HOWTO(R_390_GOTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, | |
161 | bfd_elf_generic_reloc, "R_390_GOTOFF16", FALSE, 0,0x0000ffff, FALSE), | |
162 | EMPTY_HOWTO (R_390_GOTOFF64), /* Empty entry for R_390_GOTOFF64. */ | |
163 | HOWTO(R_390_GOTPLT12, 0, 1, 12, FALSE, 0, complain_overflow_dont, | |
164 | bfd_elf_generic_reloc, "R_390_GOTPLT12", FALSE, 0,0x00000fff, FALSE), | |
165 | HOWTO(R_390_GOTPLT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, | |
166 | bfd_elf_generic_reloc, "R_390_GOTPLT16", FALSE, 0,0x0000ffff, FALSE), | |
167 | HOWTO(R_390_GOTPLT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
168 | bfd_elf_generic_reloc, "R_390_GOTPLT32", FALSE, 0,0xffffffff, FALSE), | |
169 | EMPTY_HOWTO (R_390_GOTPLT64), /* Empty entry for R_390_GOTPLT64. */ | |
170 | HOWTO(R_390_GOTPLTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
171 | bfd_elf_generic_reloc, "R_390_GOTPLTENT",FALSE, 0,0xffffffff, TRUE), | |
172 | HOWTO(R_390_PLTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, | |
173 | bfd_elf_generic_reloc, "R_390_PLTOFF16", FALSE, 0,0x0000ffff, FALSE), | |
174 | HOWTO(R_390_PLTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
175 | bfd_elf_generic_reloc, "R_390_PLTOFF32", FALSE, 0,0xffffffff, FALSE), | |
176 | EMPTY_HOWTO (R_390_PLTOFF64), /* Empty entry for R_390_PLTOFF64. */ | |
69fc87f1 MS |
177 | HOWTO(R_390_TLS_LOAD, 0, 0, 0, FALSE, 0, complain_overflow_dont, |
178 | s390_tls_reloc, "R_390_TLS_LOAD", FALSE, 0, 0, FALSE), | |
179 | HOWTO(R_390_TLS_GDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont, | |
180 | s390_tls_reloc, "R_390_TLS_GDCALL", FALSE, 0, 0, FALSE), | |
181 | HOWTO(R_390_TLS_LDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont, | |
182 | s390_tls_reloc, "R_390_TLS_LDCALL", FALSE, 0, 0, FALSE), | |
183 | HOWTO(R_390_TLS_GD32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
184 | bfd_elf_generic_reloc, "R_390_TLS_GD32", FALSE, 0, 0xffffffff, FALSE), | |
185 | EMPTY_HOWTO (R_390_TLS_GD64), /* Empty entry for R_390_TLS_GD64. */ | |
186 | HOWTO(R_390_TLS_GOTIE12, 0, 1, 12, FALSE, 0, complain_overflow_dont, | |
187 | bfd_elf_generic_reloc, "R_390_TLS_GOTIE12", FALSE, 0, 0x00000fff, FALSE), | |
188 | HOWTO(R_390_TLS_GOTIE32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
189 | bfd_elf_generic_reloc, "R_390_TLS_GOTIE32", FALSE, 0, 0xffffffff, FALSE), | |
190 | EMPTY_HOWTO (R_390_TLS_GOTIE64), /* Empty entry for R_390_TLS_GOTIE64. */ | |
191 | HOWTO(R_390_TLS_LDM32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
192 | bfd_elf_generic_reloc, "R_390_TLS_LDM32", FALSE, 0, 0xffffffff, FALSE), | |
193 | EMPTY_HOWTO (R_390_TLS_LDM64), /* Empty entry for R_390_TLS_LDM64. */ | |
194 | HOWTO(R_390_TLS_IE32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
195 | bfd_elf_generic_reloc, "R_390_TLS_IE32", FALSE, 0, 0xffffffff, FALSE), | |
196 | EMPTY_HOWTO (R_390_TLS_IE64), /* Empty entry for R_390_TLS_IE64. */ | |
197 | HOWTO(R_390_TLS_IEENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield, | |
198 | bfd_elf_generic_reloc, "R_390_TLS_IEENT", FALSE, 0, 0xffffffff, TRUE), | |
199 | HOWTO(R_390_TLS_LE32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
200 | bfd_elf_generic_reloc, "R_390_TLS_LE32", FALSE, 0, 0xffffffff, FALSE), | |
201 | EMPTY_HOWTO (R_390_TLS_LE64), /* Empty entry for R_390_TLS_LE64. */ | |
202 | HOWTO(R_390_TLS_LDO32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
203 | bfd_elf_generic_reloc, "R_390_TLS_LDO32", FALSE, 0, 0xffffffff, FALSE), | |
204 | EMPTY_HOWTO (R_390_TLS_LDO64), /* Empty entry for R_390_TLS_LDO64. */ | |
205 | HOWTO(R_390_TLS_DTPMOD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
206 | bfd_elf_generic_reloc, "R_390_TLS_DTPMOD", FALSE, 0, 0xffffffff, FALSE), | |
207 | HOWTO(R_390_TLS_DTPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
208 | bfd_elf_generic_reloc, "R_390_TLS_DTPOFF", FALSE, 0, 0xffffffff, FALSE), | |
209 | HOWTO(R_390_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
210 | bfd_elf_generic_reloc, "R_390_TLS_TPOFF", FALSE, 0, 0xffffffff, FALSE), | |
a85d7ed0 NC |
211 | }; |
212 | ||
213 | /* GNU extension to record C++ vtable hierarchy. */ | |
214 | static reloc_howto_type elf32_s390_vtinherit_howto = | |
b34976b6 | 215 | HOWTO (R_390_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", FALSE,0, 0, FALSE); |
a85d7ed0 | 216 | static reloc_howto_type elf32_s390_vtentry_howto = |
b34976b6 | 217 | HOWTO (R_390_GNU_VTENTRY, 0,2,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", FALSE,0,0, FALSE); |
a85d7ed0 NC |
218 | |
219 | static reloc_howto_type * | |
220 | elf_s390_reloc_type_lookup (abfd, code) | |
221 | bfd *abfd ATTRIBUTE_UNUSED; | |
222 | bfd_reloc_code_real_type code; | |
223 | { | |
ec338859 | 224 | switch (code) |
0451c93c MS |
225 | { |
226 | case BFD_RELOC_NONE: | |
227 | return &elf_howto_table[(int) R_390_NONE]; | |
228 | case BFD_RELOC_8: | |
229 | return &elf_howto_table[(int) R_390_8]; | |
230 | case BFD_RELOC_390_12: | |
231 | return &elf_howto_table[(int) R_390_12]; | |
232 | case BFD_RELOC_16: | |
233 | return &elf_howto_table[(int) R_390_16]; | |
234 | case BFD_RELOC_32: | |
235 | return &elf_howto_table[(int) R_390_32]; | |
236 | case BFD_RELOC_CTOR: | |
237 | return &elf_howto_table[(int) R_390_32]; | |
238 | case BFD_RELOC_32_PCREL: | |
239 | return &elf_howto_table[(int) R_390_PC32]; | |
240 | case BFD_RELOC_390_GOT12: | |
241 | return &elf_howto_table[(int) R_390_GOT12]; | |
242 | case BFD_RELOC_32_GOT_PCREL: | |
243 | return &elf_howto_table[(int) R_390_GOT32]; | |
244 | case BFD_RELOC_390_PLT32: | |
245 | return &elf_howto_table[(int) R_390_PLT32]; | |
246 | case BFD_RELOC_390_COPY: | |
247 | return &elf_howto_table[(int) R_390_COPY]; | |
248 | case BFD_RELOC_390_GLOB_DAT: | |
249 | return &elf_howto_table[(int) R_390_GLOB_DAT]; | |
250 | case BFD_RELOC_390_JMP_SLOT: | |
251 | return &elf_howto_table[(int) R_390_JMP_SLOT]; | |
252 | case BFD_RELOC_390_RELATIVE: | |
253 | return &elf_howto_table[(int) R_390_RELATIVE]; | |
254 | case BFD_RELOC_32_GOTOFF: | |
5236c819 | 255 | return &elf_howto_table[(int) R_390_GOTOFF32]; |
0451c93c MS |
256 | case BFD_RELOC_390_GOTPC: |
257 | return &elf_howto_table[(int) R_390_GOTPC]; | |
258 | case BFD_RELOC_390_GOT16: | |
259 | return &elf_howto_table[(int) R_390_GOT16]; | |
260 | case BFD_RELOC_16_PCREL: | |
261 | return &elf_howto_table[(int) R_390_PC16]; | |
262 | case BFD_RELOC_390_PC16DBL: | |
263 | return &elf_howto_table[(int) R_390_PC16DBL]; | |
264 | case BFD_RELOC_390_PLT16DBL: | |
265 | return &elf_howto_table[(int) R_390_PLT16DBL]; | |
befc3abb MS |
266 | case BFD_RELOC_390_PC32DBL: |
267 | return &elf_howto_table[(int) R_390_PC32DBL]; | |
268 | case BFD_RELOC_390_PLT32DBL: | |
269 | return &elf_howto_table[(int) R_390_PLT32DBL]; | |
270 | case BFD_RELOC_390_GOTPCDBL: | |
271 | return &elf_howto_table[(int) R_390_GOTPCDBL]; | |
272 | case BFD_RELOC_390_GOTENT: | |
273 | return &elf_howto_table[(int) R_390_GOTENT]; | |
5236c819 MS |
274 | case BFD_RELOC_16_GOTOFF: |
275 | return &elf_howto_table[(int) R_390_GOTOFF16]; | |
276 | case BFD_RELOC_390_GOTPLT12: | |
277 | return &elf_howto_table[(int) R_390_GOTPLT12]; | |
278 | case BFD_RELOC_390_GOTPLT16: | |
279 | return &elf_howto_table[(int) R_390_GOTPLT16]; | |
280 | case BFD_RELOC_390_GOTPLT32: | |
281 | return &elf_howto_table[(int) R_390_GOTPLT32]; | |
282 | case BFD_RELOC_390_GOTPLTENT: | |
283 | return &elf_howto_table[(int) R_390_GOTPLTENT]; | |
284 | case BFD_RELOC_390_PLTOFF16: | |
285 | return &elf_howto_table[(int) R_390_PLTOFF16]; | |
286 | case BFD_RELOC_390_PLTOFF32: | |
287 | return &elf_howto_table[(int) R_390_PLTOFF32]; | |
69fc87f1 MS |
288 | case BFD_RELOC_390_TLS_LOAD: |
289 | return &elf_howto_table[(int) R_390_TLS_LOAD]; | |
290 | case BFD_RELOC_390_TLS_GDCALL: | |
291 | return &elf_howto_table[(int) R_390_TLS_GDCALL]; | |
292 | case BFD_RELOC_390_TLS_LDCALL: | |
293 | return &elf_howto_table[(int) R_390_TLS_LDCALL]; | |
294 | case BFD_RELOC_390_TLS_GD32: | |
295 | return &elf_howto_table[(int) R_390_TLS_GD32]; | |
296 | case BFD_RELOC_390_TLS_GOTIE12: | |
297 | return &elf_howto_table[(int) R_390_TLS_GOTIE12]; | |
298 | case BFD_RELOC_390_TLS_GOTIE32: | |
299 | return &elf_howto_table[(int) R_390_TLS_GOTIE32]; | |
300 | case BFD_RELOC_390_TLS_LDM32: | |
301 | return &elf_howto_table[(int) R_390_TLS_LDM32]; | |
302 | case BFD_RELOC_390_TLS_IE32: | |
303 | return &elf_howto_table[(int) R_390_TLS_IE32]; | |
304 | case BFD_RELOC_390_TLS_IEENT: | |
305 | return &elf_howto_table[(int) R_390_TLS_IEENT]; | |
306 | case BFD_RELOC_390_TLS_LE32: | |
307 | return &elf_howto_table[(int) R_390_TLS_LE32]; | |
308 | case BFD_RELOC_390_TLS_LDO32: | |
309 | return &elf_howto_table[(int) R_390_TLS_LDO32]; | |
310 | case BFD_RELOC_390_TLS_DTPMOD: | |
311 | return &elf_howto_table[(int) R_390_TLS_DTPMOD]; | |
312 | case BFD_RELOC_390_TLS_DTPOFF: | |
313 | return &elf_howto_table[(int) R_390_TLS_DTPOFF]; | |
314 | case BFD_RELOC_390_TLS_TPOFF: | |
315 | return &elf_howto_table[(int) R_390_TLS_TPOFF]; | |
0451c93c MS |
316 | case BFD_RELOC_VTABLE_INHERIT: |
317 | return &elf32_s390_vtinherit_howto; | |
318 | case BFD_RELOC_VTABLE_ENTRY: | |
319 | return &elf32_s390_vtentry_howto; | |
320 | default: | |
321 | break; | |
322 | } | |
a85d7ed0 NC |
323 | return 0; |
324 | } | |
325 | ||
326 | /* We need to use ELF32_R_TYPE so we have our own copy of this function, | |
327 | and elf32-s390.c has its own copy. */ | |
328 | ||
329 | static void | |
330 | elf_s390_info_to_howto (abfd, cache_ptr, dst) | |
331 | bfd *abfd ATTRIBUTE_UNUSED; | |
332 | arelent *cache_ptr; | |
333 | Elf_Internal_Rela *dst; | |
334 | { | |
335 | switch (ELF32_R_TYPE(dst->r_info)) | |
336 | { | |
337 | case R_390_GNU_VTINHERIT: | |
338 | cache_ptr->howto = &elf32_s390_vtinherit_howto; | |
339 | break; | |
340 | ||
341 | case R_390_GNU_VTENTRY: | |
342 | cache_ptr->howto = &elf32_s390_vtentry_howto; | |
343 | break; | |
344 | ||
345 | default: | |
346 | BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_390_max); | |
347 | cache_ptr->howto = &elf_howto_table[ELF32_R_TYPE(dst->r_info)]; | |
dc810e39 | 348 | } |
a85d7ed0 NC |
349 | } |
350 | ||
69fc87f1 MS |
351 | /* A relocation function which doesn't do anything. */ |
352 | static bfd_reloc_status_type | |
353 | s390_tls_reloc (abfd, reloc_entry, symbol, data, input_section, | |
354 | output_bfd, error_message) | |
355 | bfd *abfd ATTRIBUTE_UNUSED; | |
356 | arelent *reloc_entry; | |
357 | asymbol *symbol ATTRIBUTE_UNUSED; | |
358 | PTR data ATTRIBUTE_UNUSED; | |
359 | asection *input_section; | |
360 | bfd *output_bfd; | |
361 | char **error_message ATTRIBUTE_UNUSED; | |
362 | { | |
363 | if (output_bfd) | |
364 | reloc_entry->address += input_section->output_offset; | |
365 | return bfd_reloc_ok; | |
366 | } | |
367 | ||
b34976b6 | 368 | static bfd_boolean |
a85d7ed0 NC |
369 | elf_s390_is_local_label_name (abfd, name) |
370 | bfd *abfd; | |
371 | const char *name; | |
372 | { | |
373 | if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L')) | |
b34976b6 | 374 | return TRUE; |
a85d7ed0 NC |
375 | |
376 | return _bfd_elf_is_local_label_name (abfd, name); | |
377 | } | |
378 | ||
379 | /* Functions for the 390 ELF linker. */ | |
380 | ||
381 | /* The name of the dynamic interpreter. This is put in the .interp | |
382 | section. */ | |
383 | ||
384 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
385 | ||
a85d7ed0 NC |
386 | /* The size in bytes of the first entry in the procedure linkage table. */ |
387 | #define PLT_FIRST_ENTRY_SIZE 32 | |
388 | /* The size in bytes of an entry in the procedure linkage table. */ | |
dc810e39 | 389 | #define PLT_ENTRY_SIZE 32 |
a85d7ed0 NC |
390 | |
391 | #define GOT_ENTRY_SIZE 4 | |
392 | ||
393 | /* The first three entries in a procedure linkage table are reserved, | |
394 | and the initial contents are unimportant (we zero them out). | |
395 | Subsequent entries look like this. See the SVR4 ABI 386 | |
396 | supplement to see how this works. */ | |
397 | ||
398 | /* For the s390, simple addr offset can only be 0 - 4096. | |
399 | To use the full 2 GB address space, several instructions | |
400 | are needed to load an address in a register and execute | |
401 | a branch( or just saving the address) | |
402 | ||
dc810e39 | 403 | Furthermore, only r 0 and 1 are free to use!!! */ |
a85d7ed0 NC |
404 | |
405 | /* The first 3 words in the GOT are then reserved. | |
406 | Word 0 is the address of the dynamic table. | |
407 | Word 1 is a pointer to a structure describing the object | |
408 | Word 2 is used to point to the loader entry address. | |
409 | ||
410 | The code for position independand PLT entries looks like this: | |
411 | ||
412 | r12 holds addr of the current GOT at entry to the PLT | |
413 | ||
414 | The GOT holds the address in the PLT to be executed. | |
415 | The loader then gets: | |
416 | 24(15) = Pointer to the structure describing the object. | |
dc810e39 | 417 | 28(15) = Offset in symbol table |
a85d7ed0 NC |
418 | |
419 | The loader must then find the module where the function is | |
420 | and insert the address in the GOT. | |
421 | ||
422 | Note: 390 can only address +- 64 K relative. | |
423 | We check if offset > 65536, then make a relative branch -64xxx | |
424 | back to a previous defined branch | |
425 | ||
426 | PLT1: BASR 1,0 # 2 bytes | |
427 | L 1,22(1) # 4 bytes Load offset in GOT in r 1 | |
428 | L 1,(1,12) # 4 bytes Load address from GOT in r1 | |
429 | BCR 15,1 # 2 bytes Jump to address | |
430 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | |
431 | L 1,14(1) # 4 bytes Load offset in symol table in r1 | |
432 | BRC 15,-x # 4 bytes Jump to start of PLT | |
433 | .word 0 # 2 bytes filler | |
434 | .long ? # 4 bytes offset in GOT | |
435 | .long ? # 4 bytes offset into symbol table | |
436 | ||
437 | This was the general case. There are two additional, optimizes PLT | |
438 | definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768. | |
439 | First the one for GOT offsets < 4096: | |
440 | ||
441 | PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1 | |
442 | BCR 15,1 # 2 bytes Jump to address | |
443 | .word 0,0,0 # 6 bytes filler | |
444 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | |
445 | L 1,14(1) # 4 bytes Load offset in symbol table in r1 | |
446 | BRC 15,-x # 4 bytes Jump to start of PLT | |
447 | .word 0,0,0 # 6 bytes filler | |
448 | .long ? # 4 bytes offset into symbol table | |
449 | ||
450 | Second the one for GOT offsets < 32768: | |
451 | ||
452 | PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1 | |
453 | L 1,(1,12) # 4 bytes Load address from GOT to r1 | |
454 | BCR 15,1 # 2 bytes Jump to address | |
455 | .word 0 # 2 bytes filler | |
456 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | |
457 | L 1,14(1) # 4 bytes Load offset in symbol table in r1 | |
458 | BRC 15,-x # 4 bytes Jump to start of PLT | |
459 | .word 0,0,0 # 6 bytes filler | |
460 | .long ? # 4 bytes offset into symbol table | |
461 | ||
462 | Total = 32 bytes per PLT entry | |
463 | ||
464 | The code for static build PLT entries looks like this: | |
465 | ||
466 | PLT1: BASR 1,0 # 2 bytes | |
467 | L 1,22(1) # 4 bytes Load address of GOT entry | |
468 | L 1,0(0,1) # 4 bytes Load address from GOT in r1 | |
469 | BCR 15,1 # 2 bytes Jump to address | |
470 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | |
471 | L 1,14(1) # 4 bytes Load offset in symbol table in r1 | |
472 | BRC 15,-x # 4 bytes Jump to start of PLT | |
473 | .word 0 # 2 bytes filler | |
474 | .long ? # 4 bytes address of GOT entry | |
475 | .long ? # 4 bytes offset into symbol table */ | |
476 | ||
477 | #define PLT_PIC_ENTRY_WORD0 0x0d105810 | |
478 | #define PLT_PIC_ENTRY_WORD1 0x10165811 | |
479 | #define PLT_PIC_ENTRY_WORD2 0xc00007f1 | |
480 | #define PLT_PIC_ENTRY_WORD3 0x0d105810 | |
481 | #define PLT_PIC_ENTRY_WORD4 0x100ea7f4 | |
482 | ||
483 | #define PLT_PIC12_ENTRY_WORD0 0x5810c000 | |
484 | #define PLT_PIC12_ENTRY_WORD1 0x07f10000 | |
485 | #define PLT_PIC12_ENTRY_WORD2 0x00000000 | |
486 | #define PLT_PIC12_ENTRY_WORD3 0x0d105810 | |
487 | #define PLT_PIC12_ENTRY_WORD4 0x100ea7f4 | |
488 | ||
489 | #define PLT_PIC16_ENTRY_WORD0 0xa7180000 | |
490 | #define PLT_PIC16_ENTRY_WORD1 0x5811c000 | |
491 | #define PLT_PIC16_ENTRY_WORD2 0x07f10000 | |
492 | #define PLT_PIC16_ENTRY_WORD3 0x0d105810 | |
493 | #define PLT_PIC16_ENTRY_WORD4 0x100ea7f4 | |
494 | ||
495 | #define PLT_ENTRY_WORD0 0x0d105810 | |
496 | #define PLT_ENTRY_WORD1 0x10165810 | |
497 | #define PLT_ENTRY_WORD2 0x100007f1 | |
498 | #define PLT_ENTRY_WORD3 0x0d105810 | |
499 | #define PLT_ENTRY_WORD4 0x100ea7f4 | |
500 | ||
501 | /* The first PLT entry pushes the offset into the symbol table | |
502 | from R1 onto the stack at 8(15) and the loader object info | |
503 | at 12(15), loads the loader address in R1 and jumps to it. */ | |
504 | ||
505 | /* The first entry in the PLT for PIC code: | |
506 | ||
507 | PLT0: | |
508 | ST 1,28(15) # R1 has offset into symbol table | |
509 | L 1,4(12) # Get loader ino(object struct address) | |
dc810e39 | 510 | ST 1,24(15) # Store address |
a85d7ed0 NC |
511 | L 1,8(12) # Entry address of loader in R1 |
512 | BR 1 # Jump to loader | |
513 | ||
514 | The first entry in the PLT for static code: | |
515 | ||
516 | PLT0: | |
517 | ST 1,28(15) # R1 has offset into symbol table | |
518 | BASR 1,0 | |
519 | L 1,18(0,1) # Get address of GOT | |
520 | MVC 24(4,15),4(1) # Move loader ino to stack | |
521 | L 1,8(1) # Get address of loader | |
522 | BR 1 # Jump to loader | |
523 | .word 0 # filler | |
524 | .long got # address of GOT */ | |
525 | ||
526 | #define PLT_PIC_FIRST_ENTRY_WORD0 0x5010f01c | |
527 | #define PLT_PIC_FIRST_ENTRY_WORD1 0x5810c004 | |
528 | #define PLT_PIC_FIRST_ENTRY_WORD2 0x5010f018 | |
529 | #define PLT_PIC_FIRST_ENTRY_WORD3 0x5810c008 | |
530 | #define PLT_PIC_FIRST_ENTRY_WORD4 0x07f10000 | |
531 | ||
532 | #define PLT_FIRST_ENTRY_WORD0 0x5010f01c | |
533 | #define PLT_FIRST_ENTRY_WORD1 0x0d105810 | |
534 | #define PLT_FIRST_ENTRY_WORD2 0x1012D203 | |
535 | #define PLT_FIRST_ENTRY_WORD3 0xf0181004 | |
536 | #define PLT_FIRST_ENTRY_WORD4 0x58101008 | |
537 | #define PLT_FIRST_ENTRY_WORD5 0x07f10000 | |
538 | ||
539 | /* The s390 linker needs to keep track of the number of relocs that it | |
0451c93c MS |
540 | decides to copy as dynamic relocs in check_relocs for each symbol. |
541 | This is so that it can later discard them if they are found to be | |
542 | unnecessary. We store the information in a field extending the | |
543 | regular ELF linker hash table. */ | |
a85d7ed0 | 544 | |
0451c93c | 545 | struct elf_s390_dyn_relocs |
a85d7ed0 | 546 | { |
0451c93c MS |
547 | struct elf_s390_dyn_relocs *next; |
548 | ||
549 | /* The input section of the reloc. */ | |
550 | asection *sec; | |
551 | ||
552 | /* Total number of relocs copied for the input section. */ | |
a85d7ed0 | 553 | bfd_size_type count; |
0451c93c MS |
554 | |
555 | /* Number of pc-relative relocs copied for the input section. */ | |
556 | bfd_size_type pc_count; | |
a85d7ed0 NC |
557 | }; |
558 | ||
559 | /* s390 ELF linker hash entry. */ | |
560 | ||
561 | struct elf_s390_link_hash_entry | |
562 | { | |
0451c93c | 563 | struct elf_link_hash_entry elf; |
a85d7ed0 | 564 | |
0451c93c MS |
565 | /* Track dynamic relocs copied for this symbol. */ |
566 | struct elf_s390_dyn_relocs *dyn_relocs; | |
5236c819 MS |
567 | |
568 | /* Number of GOTPLT references for a function. */ | |
569 | bfd_signed_vma gotplt_refcount; | |
69fc87f1 MS |
570 | |
571 | #define GOT_UNKNOWN 0 | |
572 | #define GOT_NORMAL 1 | |
573 | #define GOT_TLS_GD 2 | |
574 | #define GOT_TLS_IE 3 | |
575 | #define GOT_TLS_IE_NLT 4 | |
576 | unsigned char tls_type; | |
a85d7ed0 NC |
577 | }; |
578 | ||
69fc87f1 MS |
579 | #define elf_s390_hash_entry(ent) \ |
580 | ((struct elf_s390_link_hash_entry *)(ent)) | |
581 | ||
582 | struct elf_s390_obj_tdata | |
583 | { | |
584 | struct elf_obj_tdata root; | |
585 | ||
586 | /* tls_type for each local got entry. */ | |
587 | char *local_got_tls_type; | |
588 | }; | |
589 | ||
590 | #define elf_s390_tdata(abfd) \ | |
591 | ((struct elf_s390_obj_tdata *) (abfd)->tdata.any) | |
592 | ||
593 | #define elf_s390_local_got_tls_type(abfd) \ | |
594 | (elf_s390_tdata (abfd)->local_got_tls_type) | |
595 | ||
596 | static bfd_boolean | |
597 | elf_s390_mkobject (abfd) | |
598 | bfd *abfd; | |
599 | { | |
600 | bfd_size_type amt = sizeof (struct elf_s390_obj_tdata); | |
601 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
602 | if (abfd->tdata.any == NULL) | |
603 | return FALSE; | |
604 | return TRUE; | |
605 | } | |
606 | ||
607 | static bfd_boolean | |
608 | elf_s390_object_p (abfd) | |
609 | bfd *abfd; | |
610 | { | |
611 | /* Allocate our special target data. */ | |
612 | struct elf_s390_obj_tdata *new_tdata; | |
613 | bfd_size_type amt = sizeof (struct elf_s390_obj_tdata); | |
614 | new_tdata = bfd_zalloc (abfd, amt); | |
615 | if (new_tdata == NULL) | |
616 | return FALSE; | |
617 | new_tdata->root = *abfd->tdata.elf_obj_data; | |
618 | abfd->tdata.any = new_tdata; | |
619 | /* Set the right machine number for an s390 elf32 file. */ | |
620 | return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_31); | |
621 | } | |
622 | ||
a85d7ed0 NC |
623 | /* s390 ELF linker hash table. */ |
624 | ||
625 | struct elf_s390_link_hash_table | |
626 | { | |
0451c93c | 627 | struct elf_link_hash_table elf; |
a85d7ed0 | 628 | |
0451c93c MS |
629 | /* Short-cuts to get to dynamic linker sections. */ |
630 | asection *sgot; | |
631 | asection *sgotplt; | |
632 | asection *srelgot; | |
633 | asection *splt; | |
634 | asection *srelplt; | |
635 | asection *sdynbss; | |
636 | asection *srelbss; | |
ec338859 | 637 | |
69fc87f1 MS |
638 | union { |
639 | bfd_signed_vma refcount; | |
640 | bfd_vma offset; | |
641 | } tls_ldm_got; | |
642 | ||
ec338859 AM |
643 | /* Small local sym to section mapping cache. */ |
644 | struct sym_sec_cache sym_sec; | |
0451c93c | 645 | }; |
a85d7ed0 NC |
646 | |
647 | /* Get the s390 ELF linker hash table from a link_info structure. */ | |
648 | ||
649 | #define elf_s390_hash_table(p) \ | |
650 | ((struct elf_s390_link_hash_table *) ((p)->hash)) | |
651 | ||
652 | /* Create an entry in an s390 ELF linker hash table. */ | |
653 | ||
654 | static struct bfd_hash_entry * | |
0451c93c | 655 | link_hash_newfunc (entry, table, string) |
a85d7ed0 NC |
656 | struct bfd_hash_entry *entry; |
657 | struct bfd_hash_table *table; | |
658 | const char *string; | |
659 | { | |
a85d7ed0 NC |
660 | /* Allocate the structure if it has not already been allocated by a |
661 | subclass. */ | |
0451c93c MS |
662 | if (entry == NULL) |
663 | { | |
664 | entry = bfd_hash_allocate (table, | |
665 | sizeof (struct elf_s390_link_hash_entry)); | |
666 | if (entry == NULL) | |
667 | return entry; | |
668 | } | |
ec338859 | 669 | |
a85d7ed0 | 670 | /* Call the allocation method of the superclass. */ |
0451c93c MS |
671 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
672 | if (entry != NULL) | |
a85d7ed0 | 673 | { |
0451c93c | 674 | struct elf_s390_link_hash_entry *eh; |
ec338859 | 675 | |
0451c93c MS |
676 | eh = (struct elf_s390_link_hash_entry *) entry; |
677 | eh->dyn_relocs = NULL; | |
5236c819 | 678 | eh->gotplt_refcount = 0; |
69fc87f1 | 679 | eh->tls_type = GOT_UNKNOWN; |
a85d7ed0 NC |
680 | } |
681 | ||
0451c93c | 682 | return entry; |
a85d7ed0 NC |
683 | } |
684 | ||
685 | /* Create an s390 ELF linker hash table. */ | |
686 | ||
687 | static struct bfd_link_hash_table * | |
688 | elf_s390_link_hash_table_create (abfd) | |
689 | bfd *abfd; | |
690 | { | |
691 | struct elf_s390_link_hash_table *ret; | |
dc810e39 | 692 | bfd_size_type amt = sizeof (struct elf_s390_link_hash_table); |
a85d7ed0 | 693 | |
e2d34d7d | 694 | ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt); |
0451c93c | 695 | if (ret == NULL) |
a85d7ed0 NC |
696 | return NULL; |
697 | ||
0451c93c | 698 | if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc)) |
a85d7ed0 | 699 | { |
e2d34d7d | 700 | free (ret); |
a85d7ed0 NC |
701 | return NULL; |
702 | } | |
703 | ||
0451c93c MS |
704 | ret->sgot = NULL; |
705 | ret->sgotplt = NULL; | |
706 | ret->srelgot = NULL; | |
707 | ret->splt = NULL; | |
708 | ret->srelplt = NULL; | |
709 | ret->sdynbss = NULL; | |
710 | ret->srelbss = NULL; | |
69fc87f1 | 711 | ret->tls_ldm_got.refcount = 0; |
ec338859 | 712 | ret->sym_sec.abfd = NULL; |
0451c93c MS |
713 | |
714 | return &ret->elf.root; | |
715 | } | |
716 | ||
717 | /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up | |
718 | shortcuts to them in our hash table. */ | |
719 | ||
b34976b6 | 720 | static bfd_boolean |
0451c93c MS |
721 | create_got_section (dynobj, info) |
722 | bfd *dynobj; | |
723 | struct bfd_link_info *info; | |
724 | { | |
725 | struct elf_s390_link_hash_table *htab; | |
726 | ||
727 | if (! _bfd_elf_create_got_section (dynobj, info)) | |
b34976b6 | 728 | return FALSE; |
0451c93c MS |
729 | |
730 | htab = elf_s390_hash_table (info); | |
731 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); | |
732 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
733 | if (!htab->sgot || !htab->sgotplt) | |
734 | abort (); | |
735 | ||
736 | htab->srelgot = bfd_make_section (dynobj, ".rela.got"); | |
737 | if (htab->srelgot == NULL | |
738 | || ! bfd_set_section_flags (dynobj, htab->srelgot, | |
739 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
740 | | SEC_IN_MEMORY | SEC_LINKER_CREATED | |
741 | | SEC_READONLY)) | |
742 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) | |
b34976b6 AM |
743 | return FALSE; |
744 | return TRUE; | |
0451c93c MS |
745 | } |
746 | ||
747 | /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and | |
748 | .rela.bss sections in DYNOBJ, and set up shortcuts to them in our | |
749 | hash table. */ | |
750 | ||
b34976b6 | 751 | static bfd_boolean |
0451c93c MS |
752 | elf_s390_create_dynamic_sections (dynobj, info) |
753 | bfd *dynobj; | |
754 | struct bfd_link_info *info; | |
755 | { | |
756 | struct elf_s390_link_hash_table *htab; | |
757 | ||
758 | htab = elf_s390_hash_table (info); | |
759 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
b34976b6 | 760 | return FALSE; |
0451c93c MS |
761 | |
762 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
b34976b6 | 763 | return FALSE; |
0451c93c MS |
764 | |
765 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
766 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
767 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
768 | if (!info->shared) | |
769 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
770 | ||
771 | if (!htab->splt || !htab->srelplt || !htab->sdynbss | |
772 | || (!info->shared && !htab->srelbss)) | |
773 | abort (); | |
774 | ||
b34976b6 | 775 | return TRUE; |
a85d7ed0 NC |
776 | } |
777 | ||
0451c93c MS |
778 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
779 | ||
780 | static void | |
b48fa14c AM |
781 | elf_s390_copy_indirect_symbol (bed, dir, ind) |
782 | struct elf_backend_data *bed; | |
0451c93c MS |
783 | struct elf_link_hash_entry *dir, *ind; |
784 | { | |
785 | struct elf_s390_link_hash_entry *edir, *eind; | |
786 | ||
787 | edir = (struct elf_s390_link_hash_entry *) dir; | |
788 | eind = (struct elf_s390_link_hash_entry *) ind; | |
789 | ||
790 | if (eind->dyn_relocs != NULL) | |
791 | { | |
792 | if (edir->dyn_relocs != NULL) | |
793 | { | |
794 | struct elf_s390_dyn_relocs **pp; | |
795 | struct elf_s390_dyn_relocs *p; | |
796 | ||
797 | if (ind->root.type == bfd_link_hash_indirect) | |
798 | abort (); | |
799 | ||
800 | /* Add reloc counts against the weak sym to the strong sym | |
801 | list. Merge any entries against the same section. */ | |
802 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
803 | { | |
804 | struct elf_s390_dyn_relocs *q; | |
805 | ||
806 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
807 | if (q->sec == p->sec) | |
808 | { | |
809 | q->pc_count += p->pc_count; | |
810 | q->count += p->count; | |
811 | *pp = p->next; | |
812 | break; | |
813 | } | |
814 | if (q == NULL) | |
815 | pp = &p->next; | |
816 | } | |
817 | *pp = edir->dyn_relocs; | |
818 | } | |
819 | ||
820 | edir->dyn_relocs = eind->dyn_relocs; | |
821 | eind->dyn_relocs = NULL; | |
822 | } | |
823 | ||
69fc87f1 MS |
824 | if (ind->root.type == bfd_link_hash_indirect |
825 | && dir->got.refcount <= 0) | |
826 | { | |
827 | edir->tls_type = eind->tls_type; | |
828 | eind->tls_type = GOT_UNKNOWN; | |
829 | } | |
830 | ||
b48fa14c | 831 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); |
0451c93c | 832 | } |
a85d7ed0 | 833 | |
69fc87f1 MS |
834 | static int |
835 | elf_s390_tls_transition (info, r_type, is_local) | |
836 | struct bfd_link_info *info; | |
837 | int r_type; | |
838 | int is_local; | |
839 | { | |
840 | if (info->shared) | |
841 | return r_type; | |
842 | ||
843 | switch (r_type) | |
844 | { | |
845 | case R_390_TLS_GD32: | |
846 | case R_390_TLS_IE32: | |
847 | if (is_local) | |
848 | return R_390_TLS_LE32; | |
849 | return R_390_TLS_IE32; | |
850 | case R_390_TLS_GOTIE32: | |
851 | if (is_local) | |
852 | return R_390_TLS_LE32; | |
853 | return R_390_TLS_GOTIE32; | |
854 | case R_390_TLS_LDM32: | |
855 | return R_390_TLS_LE32; | |
856 | } | |
857 | ||
858 | return r_type; | |
859 | } | |
860 | ||
a85d7ed0 NC |
861 | /* Look through the relocs for a section during the first phase, and |
862 | allocate space in the global offset table or procedure linkage | |
863 | table. */ | |
864 | ||
b34976b6 | 865 | static bfd_boolean |
a85d7ed0 NC |
866 | elf_s390_check_relocs (abfd, info, sec, relocs) |
867 | bfd *abfd; | |
868 | struct bfd_link_info *info; | |
869 | asection *sec; | |
870 | const Elf_Internal_Rela *relocs; | |
871 | { | |
0451c93c | 872 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
873 | Elf_Internal_Shdr *symtab_hdr; |
874 | struct elf_link_hash_entry **sym_hashes; | |
a85d7ed0 NC |
875 | const Elf_Internal_Rela *rel; |
876 | const Elf_Internal_Rela *rel_end; | |
a85d7ed0 | 877 | asection *sreloc; |
5236c819 | 878 | bfd_signed_vma *local_got_refcounts; |
69fc87f1 | 879 | int tls_type, old_tls_type; |
a85d7ed0 NC |
880 | |
881 | if (info->relocateable) | |
b34976b6 | 882 | return TRUE; |
a85d7ed0 | 883 | |
0451c93c | 884 | htab = elf_s390_hash_table (info); |
a85d7ed0 NC |
885 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
886 | sym_hashes = elf_sym_hashes (abfd); | |
5236c819 | 887 | local_got_refcounts = elf_local_got_refcounts (abfd); |
a85d7ed0 | 888 | |
a85d7ed0 NC |
889 | sreloc = NULL; |
890 | ||
891 | rel_end = relocs + sec->reloc_count; | |
892 | for (rel = relocs; rel < rel_end; rel++) | |
893 | { | |
69fc87f1 | 894 | unsigned int r_type; |
a85d7ed0 NC |
895 | unsigned long r_symndx; |
896 | struct elf_link_hash_entry *h; | |
897 | ||
898 | r_symndx = ELF32_R_SYM (rel->r_info); | |
899 | ||
0451c93c MS |
900 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
901 | { | |
902 | (*_bfd_error_handler) (_("%s: bad symbol index: %d"), | |
903 | bfd_archive_filename (abfd), | |
904 | r_symndx); | |
b34976b6 | 905 | return FALSE; |
0451c93c MS |
906 | } |
907 | ||
a85d7ed0 NC |
908 | if (r_symndx < symtab_hdr->sh_info) |
909 | h = NULL; | |
910 | else | |
dc810e39 | 911 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
a85d7ed0 | 912 | |
5236c819 MS |
913 | /* Create got section and local_got_refcounts array if they |
914 | are needed. */ | |
69fc87f1 MS |
915 | r_type = elf_s390_tls_transition (info, |
916 | ELF32_R_TYPE (rel->r_info), | |
917 | h == NULL); | |
918 | switch (r_type) | |
a85d7ed0 NC |
919 | { |
920 | case R_390_GOT12: | |
5236c819 | 921 | case R_390_GOT16: |
a85d7ed0 | 922 | case R_390_GOT32: |
befc3abb | 923 | case R_390_GOTENT: |
5236c819 MS |
924 | case R_390_GOTPLT12: |
925 | case R_390_GOTPLT16: | |
926 | case R_390_GOTPLT32: | |
927 | case R_390_GOTPLTENT: | |
69fc87f1 MS |
928 | case R_390_TLS_GD32: |
929 | case R_390_TLS_GOTIE12: | |
930 | case R_390_TLS_GOTIE32: | |
931 | case R_390_TLS_IEENT: | |
932 | case R_390_TLS_IE32: | |
933 | case R_390_TLS_LDM32: | |
5236c819 MS |
934 | if (h == NULL |
935 | && local_got_refcounts == NULL) | |
a85d7ed0 | 936 | { |
5236c819 MS |
937 | bfd_size_type size; |
938 | ||
939 | size = symtab_hdr->sh_info; | |
69fc87f1 | 940 | size *= (sizeof (bfd_signed_vma) + sizeof(char)); |
5236c819 MS |
941 | local_got_refcounts = ((bfd_signed_vma *) |
942 | bfd_zalloc (abfd, size)); | |
a85d7ed0 | 943 | if (local_got_refcounts == NULL) |
5236c819 MS |
944 | return FALSE; |
945 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
69fc87f1 MS |
946 | elf_s390_local_got_tls_type (abfd) |
947 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
a85d7ed0 | 948 | } |
5236c819 MS |
949 | /* Fall through. */ |
950 | case R_390_GOTOFF16: | |
951 | case R_390_GOTOFF32: | |
0451c93c | 952 | case R_390_GOTPC: |
befc3abb | 953 | case R_390_GOTPCDBL: |
0451c93c MS |
954 | if (htab->sgot == NULL) |
955 | { | |
956 | if (htab->elf.dynobj == NULL) | |
957 | htab->elf.dynobj = abfd; | |
958 | if (!create_got_section (htab->elf.dynobj, info)) | |
b34976b6 | 959 | return FALSE; |
0451c93c | 960 | } |
5236c819 MS |
961 | } |
962 | ||
69fc87f1 | 963 | switch (r_type) |
5236c819 | 964 | { |
5236c819 MS |
965 | case R_390_GOTOFF16: |
966 | case R_390_GOTOFF32: | |
967 | case R_390_GOTPC: | |
968 | case R_390_GOTPCDBL: | |
969 | /* Got is created, nothing to be done. */ | |
a85d7ed0 NC |
970 | break; |
971 | ||
972 | case R_390_PLT16DBL: | |
befc3abb | 973 | case R_390_PLT32DBL: |
a85d7ed0 | 974 | case R_390_PLT32: |
5236c819 MS |
975 | case R_390_PLTOFF16: |
976 | case R_390_PLTOFF32: | |
a85d7ed0 NC |
977 | /* This symbol requires a procedure linkage table entry. We |
978 | actually build the entry in adjust_dynamic_symbol, | |
979 | because this might be a case of linking PIC code which is | |
980 | never referenced by a dynamic object, in which case we | |
981 | don't need to generate a procedure linkage table entry | |
982 | after all. */ | |
983 | ||
984 | /* If this is a local symbol, we resolve it directly without | |
985 | creating a procedure linkage table entry. */ | |
5236c819 MS |
986 | if (h != NULL) |
987 | { | |
988 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
989 | h->plt.refcount += 1; | |
990 | } | |
991 | break; | |
a85d7ed0 | 992 | |
5236c819 MS |
993 | case R_390_GOTPLT12: |
994 | case R_390_GOTPLT16: | |
995 | case R_390_GOTPLT32: | |
996 | case R_390_GOTPLTENT: | |
997 | /* This symbol requires either a procedure linkage table entry | |
998 | or an entry in the local got. We actually build the entry | |
999 | in adjust_dynamic_symbol because whether this is really a | |
1000 | global reference can change and with it the fact if we have | |
1001 | to create a plt entry or a local got entry. To be able to | |
1002 | make a once global symbol a local one we have to keep track | |
1003 | of the number of gotplt references that exist for this | |
1004 | symbol. */ | |
1005 | if (h != NULL) | |
1006 | { | |
1007 | ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount++; | |
1008 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
1009 | h->plt.refcount += 1; | |
1010 | } | |
1011 | else | |
1012 | local_got_refcounts[r_symndx] += 1; | |
a85d7ed0 NC |
1013 | break; |
1014 | ||
69fc87f1 MS |
1015 | case R_390_TLS_LDM32: |
1016 | htab->tls_ldm_got.refcount += 1; | |
1017 | break; | |
1018 | ||
1019 | case R_390_TLS_IE32: | |
1020 | case R_390_TLS_GOTIE12: | |
1021 | case R_390_TLS_GOTIE32: | |
1022 | case R_390_TLS_IEENT: | |
1023 | if (info->shared) | |
1024 | info->flags |= DF_STATIC_TLS; | |
1025 | /* Fall through */ | |
1026 | ||
1027 | case R_390_GOT12: | |
1028 | case R_390_GOT16: | |
1029 | case R_390_GOT32: | |
1030 | case R_390_GOTENT: | |
1031 | case R_390_TLS_GD32: | |
1032 | /* This symbol requires a global offset table entry. */ | |
1033 | switch (r_type) | |
1034 | { | |
1035 | default: | |
1036 | case R_390_GOT12: | |
1037 | case R_390_GOT16: | |
1038 | case R_390_GOT32: | |
1039 | case R_390_GOTENT: | |
1040 | tls_type = GOT_NORMAL; | |
1041 | break; | |
1042 | case R_390_TLS_GD32: | |
1043 | tls_type = GOT_TLS_GD; | |
1044 | break; | |
1045 | case R_390_TLS_IE32: | |
1046 | case R_390_TLS_GOTIE32: | |
1047 | tls_type = GOT_TLS_IE; | |
1048 | break; | |
1049 | case R_390_TLS_GOTIE12: | |
1050 | case R_390_TLS_IEENT: | |
1051 | tls_type = GOT_TLS_IE_NLT; | |
1052 | break; | |
1053 | } | |
1054 | ||
1055 | if (h != NULL) | |
1056 | { | |
1057 | h->got.refcount += 1; | |
1058 | old_tls_type = elf_s390_hash_entry(h)->tls_type; | |
1059 | } | |
1060 | else | |
1061 | { | |
1062 | local_got_refcounts[r_symndx] += 1; | |
1063 | old_tls_type = elf_s390_local_got_tls_type (abfd) [r_symndx]; | |
1064 | } | |
1065 | /* If a TLS symbol is accessed using IE at least once, | |
1066 | there is no point to use dynamic model for it. */ | |
1067 | if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN) | |
1068 | { | |
1069 | if (old_tls_type == GOT_NORMAL || tls_type == GOT_NORMAL) | |
1070 | { | |
1071 | (*_bfd_error_handler) | |
1072 | (_("%s: `%s' accessed both as normal and thread local symbol"), | |
1073 | bfd_archive_filename (abfd), h->root.root.string); | |
1074 | return FALSE; | |
1075 | } | |
1076 | if (old_tls_type > tls_type) | |
1077 | tls_type = old_tls_type; | |
1078 | } | |
1079 | ||
1080 | if (old_tls_type != tls_type) | |
1081 | { | |
1082 | if (h != NULL) | |
1083 | elf_s390_hash_entry (h)->tls_type = tls_type; | |
1084 | else | |
1085 | elf_s390_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
1086 | } | |
1087 | ||
1088 | if (r_type != R_390_TLS_IE32) | |
1089 | break; | |
1090 | /* Fall through */ | |
1091 | ||
1092 | case R_390_TLS_LE32: | |
1093 | if (!info->shared) | |
1094 | break; | |
1095 | info->flags |= DF_STATIC_TLS; | |
1096 | /* Fall through */ | |
1097 | ||
a85d7ed0 NC |
1098 | case R_390_8: |
1099 | case R_390_16: | |
1100 | case R_390_32: | |
1101 | case R_390_PC16: | |
1102 | case R_390_PC16DBL: | |
befc3abb | 1103 | case R_390_PC32DBL: |
a85d7ed0 | 1104 | case R_390_PC32: |
0451c93c MS |
1105 | if (h != NULL && !info->shared) |
1106 | { | |
1107 | /* If this reloc is in a read-only section, we might | |
1108 | need a copy reloc. We can't check reliably at this | |
1109 | stage whether the section is read-only, as input | |
1110 | sections have not yet been mapped to output sections. | |
1111 | Tentatively set the flag for now, and correct in | |
1112 | adjust_dynamic_symbol. */ | |
1113 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
ec338859 | 1114 | |
0451c93c MS |
1115 | /* We may need a .plt entry if the function this reloc |
1116 | refers to is in a shared lib. */ | |
1117 | h->plt.refcount += 1; | |
1118 | } | |
a85d7ed0 NC |
1119 | |
1120 | /* If we are creating a shared library, and this is a reloc | |
0451c93c MS |
1121 | against a global symbol, or a non PC relative reloc |
1122 | against a local symbol, then we need to copy the reloc | |
1123 | into the shared library. However, if we are linking with | |
1124 | -Bsymbolic, we do not need to copy a reloc against a | |
1125 | global symbol which is defined in an object we are | |
1126 | including in the link (i.e., DEF_REGULAR is set). At | |
1127 | this point we have not seen all the input files, so it is | |
1128 | possible that DEF_REGULAR is not set now but will be set | |
1129 | later (it is never cleared). In case of a weak definition, | |
1130 | DEF_REGULAR may be cleared later by a strong definition in | |
1131 | a shared library. We account for that possibility below by | |
1132 | storing information in the relocs_copied field of the hash | |
1133 | table entry. A similar situation occurs when creating | |
1134 | shared libraries and symbol visibility changes render the | |
1135 | symbol local. | |
1136 | ||
1137 | If on the other hand, we are creating an executable, we | |
1138 | may need to keep relocations for symbols satisfied by a | |
1139 | dynamic library if we manage to avoid copy relocs for the | |
1140 | symbol. */ | |
1141 | if ((info->shared | |
1142 | && (sec->flags & SEC_ALLOC) != 0 | |
ec338859 | 1143 | && ((ELF32_R_TYPE (rel->r_info) != R_390_PC16 |
0451c93c | 1144 | && ELF32_R_TYPE (rel->r_info) != R_390_PC16DBL |
befc3abb | 1145 | && ELF32_R_TYPE (rel->r_info) != R_390_PC32DBL |
0451c93c MS |
1146 | && ELF32_R_TYPE (rel->r_info) != R_390_PC32) |
1147 | || (h != NULL | |
1148 | && (! info->symbolic | |
1149 | || h->root.type == bfd_link_hash_defweak | |
1150 | || (h->elf_link_hash_flags | |
1151 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
1152 | || (!info->shared | |
1153 | && (sec->flags & SEC_ALLOC) != 0 | |
1154 | && h != NULL | |
1155 | && (h->root.type == bfd_link_hash_defweak | |
1156 | || (h->elf_link_hash_flags | |
1157 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
a85d7ed0 | 1158 | { |
ec338859 AM |
1159 | struct elf_s390_dyn_relocs *p; |
1160 | struct elf_s390_dyn_relocs **head; | |
1161 | ||
0451c93c MS |
1162 | /* We must copy these reloc types into the output file. |
1163 | Create a reloc section in dynobj and make room for | |
1164 | this reloc. */ | |
a85d7ed0 NC |
1165 | if (sreloc == NULL) |
1166 | { | |
1167 | const char *name; | |
0451c93c | 1168 | bfd *dynobj; |
ec338859 | 1169 | |
a85d7ed0 NC |
1170 | name = (bfd_elf_string_from_elf_section |
1171 | (abfd, | |
1172 | elf_elfheader (abfd)->e_shstrndx, | |
1173 | elf_section_data (sec)->rel_hdr.sh_name)); | |
1174 | if (name == NULL) | |
b34976b6 | 1175 | return FALSE; |
a85d7ed0 | 1176 | |
0451c93c MS |
1177 | if (strncmp (name, ".rela", 5) != 0 |
1178 | || strcmp (bfd_get_section_name (abfd, sec), | |
1179 | name + 5) != 0) | |
1180 | { | |
1181 | (*_bfd_error_handler) | |
1182 | (_("%s: bad relocation section name `%s\'"), | |
1183 | bfd_archive_filename (abfd), name); | |
1184 | } | |
1185 | ||
1186 | if (htab->elf.dynobj == NULL) | |
1187 | htab->elf.dynobj = abfd; | |
a85d7ed0 | 1188 | |
0451c93c | 1189 | dynobj = htab->elf.dynobj; |
a85d7ed0 NC |
1190 | sreloc = bfd_get_section_by_name (dynobj, name); |
1191 | if (sreloc == NULL) | |
1192 | { | |
1193 | flagword flags; | |
1194 | ||
1195 | sreloc = bfd_make_section (dynobj, name); | |
1196 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
1197 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
1198 | if ((sec->flags & SEC_ALLOC) != 0) | |
1199 | flags |= SEC_ALLOC | SEC_LOAD; | |
1200 | if (sreloc == NULL | |
1201 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
1202 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) | |
b34976b6 | 1203 | return FALSE; |
a85d7ed0 | 1204 | } |
0451c93c | 1205 | elf_section_data (sec)->sreloc = sreloc; |
a85d7ed0 NC |
1206 | } |
1207 | ||
0451c93c MS |
1208 | /* If this is a global symbol, we count the number of |
1209 | relocations we need for this symbol. */ | |
1210 | if (h != NULL) | |
a85d7ed0 | 1211 | { |
ec338859 | 1212 | head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs; |
0451c93c MS |
1213 | } |
1214 | else | |
1215 | { | |
ec338859 AM |
1216 | /* Track dynamic relocs needed for local syms too. |
1217 | We really need local syms available to do this | |
1218 | easily. Oh well. */ | |
1219 | ||
1220 | asection *s; | |
1221 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
1222 | sec, r_symndx); | |
1223 | if (s == NULL) | |
b34976b6 | 1224 | return FALSE; |
ec338859 AM |
1225 | |
1226 | head = ((struct elf_s390_dyn_relocs **) | |
1227 | &elf_section_data (s)->local_dynrel); | |
1228 | } | |
1229 | ||
1230 | p = *head; | |
1231 | if (p == NULL || p->sec != sec) | |
1232 | { | |
1233 | bfd_size_type amt = sizeof *p; | |
1234 | p = ((struct elf_s390_dyn_relocs *) | |
1235 | bfd_alloc (htab->elf.dynobj, amt)); | |
1236 | if (p == NULL) | |
b34976b6 | 1237 | return FALSE; |
ec338859 AM |
1238 | p->next = *head; |
1239 | *head = p; | |
1240 | p->sec = sec; | |
1241 | p->count = 0; | |
1242 | p->pc_count = 0; | |
a85d7ed0 | 1243 | } |
ec338859 AM |
1244 | |
1245 | p->count += 1; | |
1246 | if (ELF32_R_TYPE (rel->r_info) == R_390_PC16 | |
1247 | || ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL | |
befc3abb | 1248 | || ELF32_R_TYPE (rel->r_info) == R_390_PC32DBL |
ec338859 AM |
1249 | || ELF32_R_TYPE (rel->r_info) == R_390_PC32) |
1250 | p->pc_count += 1; | |
a85d7ed0 | 1251 | } |
a85d7ed0 | 1252 | break; |
ec338859 | 1253 | |
a85d7ed0 NC |
1254 | /* This relocation describes the C++ object vtable hierarchy. |
1255 | Reconstruct it for later use during GC. */ | |
1256 | case R_390_GNU_VTINHERIT: | |
1257 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
b34976b6 | 1258 | return FALSE; |
a85d7ed0 | 1259 | break; |
ec338859 | 1260 | |
a85d7ed0 NC |
1261 | /* This relocation describes which C++ vtable entries are actually |
1262 | used. Record for later use during GC. */ | |
1263 | case R_390_GNU_VTENTRY: | |
db727808 | 1264 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 1265 | return FALSE; |
a85d7ed0 | 1266 | break; |
ec338859 | 1267 | |
a85d7ed0 NC |
1268 | default: |
1269 | break; | |
1270 | } | |
1271 | } | |
1272 | ||
b34976b6 | 1273 | return TRUE; |
a85d7ed0 NC |
1274 | } |
1275 | ||
1276 | /* Return the section that should be marked against GC for a given | |
1277 | relocation. */ | |
1278 | ||
1279 | static asection * | |
1e2f5b6e AM |
1280 | elf_s390_gc_mark_hook (sec, info, rel, h, sym) |
1281 | asection *sec; | |
a85d7ed0 NC |
1282 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
1283 | Elf_Internal_Rela *rel; | |
1284 | struct elf_link_hash_entry *h; | |
1285 | Elf_Internal_Sym *sym; | |
1286 | { | |
1287 | if (h != NULL) | |
1288 | { | |
1289 | switch (ELF32_R_TYPE (rel->r_info)) | |
1290 | { | |
1291 | case R_390_GNU_VTINHERIT: | |
1292 | case R_390_GNU_VTENTRY: | |
1293 | break; | |
1294 | ||
1295 | default: | |
1296 | switch (h->root.type) | |
1297 | { | |
1298 | case bfd_link_hash_defined: | |
1299 | case bfd_link_hash_defweak: | |
1300 | return h->root.u.def.section; | |
1301 | ||
1302 | case bfd_link_hash_common: | |
1303 | return h->root.u.c.p->section; | |
1304 | ||
1305 | default: | |
1306 | break; | |
1307 | } | |
1308 | } | |
1309 | } | |
1310 | else | |
1e2f5b6e | 1311 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
a85d7ed0 NC |
1312 | |
1313 | return NULL; | |
1314 | } | |
1315 | ||
1316 | /* Update the got entry reference counts for the section being removed. */ | |
1317 | ||
b34976b6 | 1318 | static bfd_boolean |
a85d7ed0 | 1319 | elf_s390_gc_sweep_hook (abfd, info, sec, relocs) |
0451c93c MS |
1320 | bfd *abfd; |
1321 | struct bfd_link_info *info; | |
1322 | asection *sec; | |
1323 | const Elf_Internal_Rela *relocs; | |
a85d7ed0 NC |
1324 | { |
1325 | Elf_Internal_Shdr *symtab_hdr; | |
1326 | struct elf_link_hash_entry **sym_hashes; | |
1327 | bfd_signed_vma *local_got_refcounts; | |
1328 | const Elf_Internal_Rela *rel, *relend; | |
1329 | unsigned long r_symndx; | |
69fc87f1 | 1330 | int r_type; |
a85d7ed0 | 1331 | struct elf_link_hash_entry *h; |
a85d7ed0 | 1332 | |
ec338859 | 1333 | elf_section_data (sec)->local_dynrel = NULL; |
a85d7ed0 | 1334 | |
0451c93c MS |
1335 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
1336 | sym_hashes = elf_sym_hashes (abfd); | |
1337 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
a85d7ed0 NC |
1338 | |
1339 | relend = relocs + sec->reloc_count; | |
1340 | for (rel = relocs; rel < relend; rel++) | |
5236c819 MS |
1341 | { |
1342 | r_symndx = ELF32_R_SYM (rel->r_info); | |
0451c93c | 1343 | |
5236c819 MS |
1344 | if (r_symndx < symtab_hdr->sh_info) |
1345 | h = NULL; | |
1346 | else | |
1347 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1348 | ||
69fc87f1 MS |
1349 | r_type = elf_s390_tls_transition (info, |
1350 | ELF32_R_TYPE (rel->r_info), | |
1351 | r_symndx >= symtab_hdr->sh_info); | |
1352 | switch (r_type) | |
5236c819 | 1353 | { |
69fc87f1 MS |
1354 | case R_390_TLS_LDM32: |
1355 | if (elf_s390_hash_table (info)->tls_ldm_got.refcount > 0) | |
1356 | elf_s390_hash_table (info)->tls_ldm_got.refcount -= 1; | |
1357 | break; | |
1358 | ||
1359 | case R_390_TLS_GD32: | |
1360 | case R_390_TLS_IE32: | |
1361 | case R_390_TLS_GOTIE12: | |
1362 | case R_390_TLS_GOTIE32: | |
1363 | case R_390_TLS_IEENT: | |
5236c819 MS |
1364 | case R_390_GOT12: |
1365 | case R_390_GOT16: | |
1366 | case R_390_GOT32: | |
1367 | case R_390_GOTOFF16: | |
1368 | case R_390_GOTOFF32: | |
1369 | case R_390_GOTPC: | |
1370 | case R_390_GOTPCDBL: | |
1371 | case R_390_GOTENT: | |
1372 | if (h != NULL) | |
1373 | { | |
1374 | if (h->got.refcount > 0) | |
1375 | h->got.refcount -= 1; | |
1376 | } | |
1377 | else if (local_got_refcounts != NULL) | |
1378 | { | |
1379 | if (local_got_refcounts[r_symndx] > 0) | |
1380 | local_got_refcounts[r_symndx] -= 1; | |
1381 | } | |
69fc87f1 MS |
1382 | if (r_type != R_390_TLS_IE32) |
1383 | break; | |
1384 | /* Fall through */ | |
5236c819 | 1385 | |
69fc87f1 MS |
1386 | case R_390_TLS_LE32: |
1387 | if (!info->shared) | |
1388 | break; | |
1389 | /* Fall through */ | |
a85d7ed0 | 1390 | |
5236c819 MS |
1391 | case R_390_8: |
1392 | case R_390_12: | |
1393 | case R_390_16: | |
1394 | case R_390_32: | |
1395 | case R_390_PC16: | |
1396 | case R_390_PC16DBL: | |
1397 | case R_390_PC32DBL: | |
1398 | case R_390_PC32: | |
1399 | if (h != NULL) | |
1400 | { | |
1401 | struct elf_s390_link_hash_entry *eh; | |
1402 | struct elf_s390_dyn_relocs **pp; | |
1403 | struct elf_s390_dyn_relocs *p; | |
1404 | ||
1405 | if (!info->shared && h->plt.refcount > 0) | |
1406 | h->plt.refcount -= 1; | |
1407 | ||
1408 | eh = (struct elf_s390_link_hash_entry *) h; | |
1409 | ||
1410 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
1411 | if (p->sec == sec) | |
1412 | { | |
1413 | if (ELF32_R_TYPE (rel->r_info) == R_390_PC16 | |
1414 | || ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL | |
1415 | || ELF32_R_TYPE (rel->r_info) == R_390_PC32DBL | |
1416 | || ELF32_R_TYPE (rel->r_info) == R_390_PC32) | |
1417 | p->pc_count -= 1; | |
1418 | p->count -= 1; | |
1419 | if (p->count == 0) | |
1420 | *pp = p->next; | |
1421 | break; | |
1422 | } | |
1423 | } | |
1424 | break; | |
1425 | ||
69fc87f1 MS |
1426 | case R_390_PLT16DBL: |
1427 | case R_390_PLT32DBL: | |
1428 | case R_390_PLT32: | |
1429 | case R_390_PLTOFF16: | |
1430 | case R_390_PLTOFF32: | |
1431 | if (h != NULL) | |
1432 | { | |
1433 | if (h->plt.refcount > 0) | |
1434 | h->plt.refcount -= 1; | |
1435 | } | |
1436 | break; | |
1437 | ||
1438 | case R_390_GOTPLT12: | |
1439 | case R_390_GOTPLT16: | |
1440 | case R_390_GOTPLT32: | |
1441 | case R_390_GOTPLTENT: | |
1442 | if (h != NULL) | |
1443 | { | |
1444 | if (h->plt.refcount > 0) | |
1445 | { | |
1446 | ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount--; | |
1447 | h->plt.refcount -= 1; | |
1448 | } | |
1449 | } | |
1450 | else if (local_got_refcounts != NULL) | |
1451 | { | |
1452 | if (local_got_refcounts[r_symndx] > 0) | |
1453 | local_got_refcounts[r_symndx] -= 1; | |
1454 | } | |
1455 | break; | |
1456 | ||
5236c819 MS |
1457 | default: |
1458 | break; | |
1459 | } | |
1460 | } | |
a85d7ed0 | 1461 | |
b34976b6 | 1462 | return TRUE; |
a85d7ed0 NC |
1463 | } |
1464 | ||
5236c819 MS |
1465 | /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT |
1466 | entry but we found we will not create any. Called when we find we will | |
1467 | not have any PLT for this symbol, by for example | |
1468 | elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link, | |
1469 | or elf_s390_size_dynamic_sections if no dynamic sections will be | |
1470 | created (we're only linking static objects). */ | |
1471 | ||
1472 | static void | |
1473 | elf_s390_adjust_gotplt (h) | |
1474 | struct elf_s390_link_hash_entry *h; | |
1475 | { | |
1476 | if (h->elf.root.type == bfd_link_hash_warning) | |
1477 | h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link; | |
1478 | ||
1479 | if (h->gotplt_refcount <= 0) | |
1480 | return; | |
1481 | ||
1482 | /* We simply add the number of gotplt references to the number | |
1483 | * of got references for this symbol. */ | |
1484 | h->elf.got.refcount += h->gotplt_refcount; | |
1485 | h->gotplt_refcount = -1; | |
1486 | } | |
1487 | ||
a85d7ed0 NC |
1488 | /* Adjust a symbol defined by a dynamic object and referenced by a |
1489 | regular object. The current definition is in some section of the | |
1490 | dynamic object, but we're not including those sections. We have to | |
1491 | change the definition to something the rest of the link can | |
1492 | understand. */ | |
1493 | ||
b34976b6 | 1494 | static bfd_boolean |
a85d7ed0 NC |
1495 | elf_s390_adjust_dynamic_symbol (info, h) |
1496 | struct bfd_link_info *info; | |
1497 | struct elf_link_hash_entry *h; | |
1498 | { | |
0451c93c MS |
1499 | struct elf_s390_link_hash_table *htab; |
1500 | struct elf_s390_link_hash_entry * eh; | |
1501 | struct elf_s390_dyn_relocs *p; | |
a85d7ed0 NC |
1502 | asection *s; |
1503 | unsigned int power_of_two; | |
1504 | ||
a85d7ed0 NC |
1505 | /* If this is a function, put it in the procedure linkage table. We |
1506 | will fill in the contents of the procedure linkage table later | |
cedb70c5 | 1507 | (although we could actually do it here). */ |
a85d7ed0 NC |
1508 | if (h->type == STT_FUNC |
1509 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
1510 | { | |
0451c93c MS |
1511 | if (h->plt.refcount <= 0 |
1512 | || (! info->shared | |
1513 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 | |
f9cd9119 MS |
1514 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0 |
1515 | && h->root.type != bfd_link_hash_undefweak | |
1516 | && h->root.type != bfd_link_hash_undefined)) | |
a85d7ed0 NC |
1517 | { |
1518 | /* This case can occur if we saw a PLT32 reloc in an input | |
1519 | file, but the symbol was never referred to by a dynamic | |
1520 | object, or if all references were garbage collected. In | |
1521 | such a case, we don't actually need to build a procedure | |
1522 | linkage table, and we can just do a PC32 reloc instead. */ | |
1523 | h->plt.offset = (bfd_vma) -1; | |
1524 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
5236c819 | 1525 | elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h); |
a85d7ed0 NC |
1526 | } |
1527 | ||
b34976b6 | 1528 | return TRUE; |
a85d7ed0 | 1529 | } |
bbd7ec4a | 1530 | else |
0451c93c MS |
1531 | /* It's possible that we incorrectly decided a .plt reloc was |
1532 | needed for an R_390_PC32 reloc to a non-function sym in | |
1533 | check_relocs. We can't decide accurately between function and | |
1534 | non-function syms in check-relocs; Objects loaded later in | |
1535 | the link may change h->type. So fix it now. */ | |
bbd7ec4a | 1536 | h->plt.offset = (bfd_vma) -1; |
a85d7ed0 NC |
1537 | |
1538 | /* If this is a weak symbol, and there is a real definition, the | |
1539 | processor independent code will have arranged for us to see the | |
1540 | real definition first, and we can just use the same value. */ | |
1541 | if (h->weakdef != NULL) | |
1542 | { | |
1543 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
1544 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
1545 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
1546 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
b34976b6 | 1547 | return TRUE; |
a85d7ed0 NC |
1548 | } |
1549 | ||
1550 | /* This is a reference to a symbol defined by a dynamic object which | |
1551 | is not a function. */ | |
1552 | ||
1553 | /* If we are creating a shared library, we must presume that the | |
1554 | only references to the symbol are via the global offset table. | |
1555 | For such cases we need not do anything here; the relocations will | |
1556 | be handled correctly by relocate_section. */ | |
1557 | if (info->shared) | |
b34976b6 | 1558 | return TRUE; |
a85d7ed0 NC |
1559 | |
1560 | /* If there are no references to this symbol that do not use the | |
1561 | GOT, we don't need to generate a copy reloc. */ | |
1562 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
b34976b6 | 1563 | return TRUE; |
a85d7ed0 | 1564 | |
0451c93c MS |
1565 | /* If -z nocopyreloc was given, we won't generate them either. */ |
1566 | if (info->nocopyreloc) | |
1567 | { | |
1568 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
b34976b6 | 1569 | return TRUE; |
0451c93c MS |
1570 | } |
1571 | ||
1572 | eh = (struct elf_s390_link_hash_entry *) h; | |
1573 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
1574 | { | |
1575 | s = p->sec->output_section; | |
1576 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
1577 | break; | |
1578 | } | |
1579 | ||
1580 | /* If we didn't find any dynamic relocs in read-only sections, then | |
ec338859 | 1581 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
0451c93c MS |
1582 | if (p == NULL) |
1583 | { | |
1584 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
b34976b6 | 1585 | return TRUE; |
0451c93c MS |
1586 | } |
1587 | ||
a85d7ed0 NC |
1588 | /* We must allocate the symbol in our .dynbss section, which will |
1589 | become part of the .bss section of the executable. There will be | |
1590 | an entry for this symbol in the .dynsym section. The dynamic | |
1591 | object will contain position independent code, so all references | |
1592 | from the dynamic object to this symbol will go through the global | |
1593 | offset table. The dynamic linker will use the .dynsym entry to | |
1594 | determine the address it must put in the global offset table, so | |
1595 | both the dynamic object and the regular object will refer to the | |
1596 | same memory location for the variable. */ | |
1597 | ||
0451c93c | 1598 | htab = elf_s390_hash_table (info); |
a85d7ed0 | 1599 | |
0451c93c MS |
1600 | /* We must generate a R_390_COPY reloc to tell the dynamic linker to |
1601 | copy the initial value out of the dynamic object and into the | |
1602 | runtime process image. */ | |
a85d7ed0 NC |
1603 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
1604 | { | |
0451c93c | 1605 | htab->srelbss->_raw_size += sizeof (Elf32_External_Rela); |
a85d7ed0 NC |
1606 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
1607 | } | |
1608 | ||
1609 | /* We need to figure out the alignment required for this symbol. I | |
1610 | have no idea how ELF linkers handle this. */ | |
1611 | power_of_two = bfd_log2 (h->size); | |
1612 | if (power_of_two > 3) | |
1613 | power_of_two = 3; | |
1614 | ||
1615 | /* Apply the required alignment. */ | |
0451c93c MS |
1616 | s = htab->sdynbss; |
1617 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); | |
1618 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
a85d7ed0 | 1619 | { |
0451c93c | 1620 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 1621 | return FALSE; |
a85d7ed0 NC |
1622 | } |
1623 | ||
1624 | /* Define the symbol as being at this point in the section. */ | |
1625 | h->root.u.def.section = s; | |
1626 | h->root.u.def.value = s->_raw_size; | |
1627 | ||
1628 | /* Increment the section size to make room for the symbol. */ | |
1629 | s->_raw_size += h->size; | |
1630 | ||
b34976b6 | 1631 | return TRUE; |
a85d7ed0 NC |
1632 | } |
1633 | ||
0451c93c MS |
1634 | /* This is the condition under which elf_s390_finish_dynamic_symbol |
1635 | will be called from elflink.h. If elflink.h doesn't call our | |
1636 | finish_dynamic_symbol routine, we'll need to do something about | |
1637 | initializing any .plt and .got entries in elf_s390_relocate_section. */ | |
1638 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ | |
1639 | ((DYN) \ | |
1640 | && ((INFO)->shared \ | |
1641 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ | |
1642 | && ((H)->dynindx != -1 \ | |
1643 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
1644 | ||
1645 | /* Allocate space in .plt, .got and associated reloc sections for | |
1646 | dynamic relocs. */ | |
1647 | ||
b34976b6 | 1648 | static bfd_boolean |
0451c93c MS |
1649 | allocate_dynrelocs (h, inf) |
1650 | struct elf_link_hash_entry *h; | |
1651 | PTR inf; | |
1652 | { | |
1653 | struct bfd_link_info *info; | |
1654 | struct elf_s390_link_hash_table *htab; | |
1655 | struct elf_s390_link_hash_entry *eh; | |
1656 | struct elf_s390_dyn_relocs *p; | |
1657 | ||
e92d460e | 1658 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 1659 | return TRUE; |
0451c93c | 1660 | |
e92d460e | 1661 | if (h->root.type == bfd_link_hash_warning) |
5236c819 MS |
1662 | /* When warning symbols are created, they **replace** the "real" |
1663 | entry in the hash table, thus we never get to see the real | |
1664 | symbol in a hash traversal. So look at it now. */ | |
e92d460e AM |
1665 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
1666 | ||
0451c93c MS |
1667 | info = (struct bfd_link_info *) inf; |
1668 | htab = elf_s390_hash_table (info); | |
1669 | ||
1670 | if (htab->elf.dynamic_sections_created | |
1671 | && h->plt.refcount > 0) | |
1672 | { | |
1673 | /* Make sure this symbol is output as a dynamic symbol. | |
1674 | Undefined weak syms won't yet be marked as dynamic. */ | |
1675 | if (h->dynindx == -1 | |
1676 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
1677 | { | |
1678 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
b34976b6 | 1679 | return FALSE; |
0451c93c MS |
1680 | } |
1681 | ||
1682 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) | |
1683 | { | |
1684 | asection *s = htab->splt; | |
1685 | ||
1686 | /* If this is the first .plt entry, make room for the special | |
1687 | first entry. */ | |
1688 | if (s->_raw_size == 0) | |
1689 | s->_raw_size += PLT_FIRST_ENTRY_SIZE; | |
1690 | ||
1691 | h->plt.offset = s->_raw_size; | |
1692 | ||
1693 | /* If this symbol is not defined in a regular file, and we are | |
1694 | not generating a shared library, then set the symbol to this | |
1695 | location in the .plt. This is required to make function | |
1696 | pointers compare as equal between the normal executable and | |
1697 | the shared library. */ | |
1698 | if (! info->shared | |
1699 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
1700 | { | |
1701 | h->root.u.def.section = s; | |
1702 | h->root.u.def.value = h->plt.offset; | |
1703 | } | |
ec338859 | 1704 | |
0451c93c MS |
1705 | /* Make room for this entry. */ |
1706 | s->_raw_size += PLT_ENTRY_SIZE; | |
ec338859 | 1707 | |
0451c93c MS |
1708 | /* We also need to make an entry in the .got.plt section, which |
1709 | will be placed in the .got section by the linker script. */ | |
1710 | htab->sgotplt->_raw_size += GOT_ENTRY_SIZE; | |
1711 | ||
1712 | /* We also need to make an entry in the .rela.plt section. */ | |
1713 | htab->srelplt->_raw_size += sizeof (Elf32_External_Rela); | |
1714 | } | |
1715 | else | |
1716 | { | |
1717 | h->plt.offset = (bfd_vma) -1; | |
1718 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
5236c819 | 1719 | elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h); |
0451c93c | 1720 | } |
ec338859 | 1721 | } |
0451c93c MS |
1722 | else |
1723 | { | |
1724 | h->plt.offset = (bfd_vma) -1; | |
1725 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
5236c819 | 1726 | elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h); |
ec338859 AM |
1727 | } |
1728 | ||
69fc87f1 MS |
1729 | /* If R_390_TLS_{IE32,GOTIE32,GOTIE12,IEENT} symbol is now local to |
1730 | the binary, we can optimize a bit. IE32 and GOTIE32 get converted | |
1731 | to R_390_TLS_LE32 requiring no TLS entry. For GOTIE12 and IEENT | |
1732 | we can save the dynamic TLS relocation. */ | |
1733 | if (h->got.refcount > 0 | |
1734 | && !info->shared | |
1735 | && h->dynindx == -1 | |
1736 | && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE) | |
0451c93c | 1737 | { |
69fc87f1 MS |
1738 | if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT) |
1739 | /* For the GOTIE access without a literal pool entry the offset has | |
1740 | to be stored somewhere. The immediate value in the instruction | |
1741 | is not bit enough so the value is stored in the got. */ | |
1742 | { | |
1743 | h->got.offset = htab->sgot->_raw_size; | |
1744 | htab->sgot->_raw_size += GOT_ENTRY_SIZE; | |
1745 | } | |
1746 | else | |
1747 | h->got.offset = (bfd_vma) -1; | |
1748 | } | |
1749 | else if (h->got.refcount > 0) | |
1750 | { | |
0451c93c | 1751 | asection *s; |
b34976b6 | 1752 | bfd_boolean dyn; |
69fc87f1 | 1753 | int tls_type = elf_s390_hash_entry(h)->tls_type; |
0451c93c MS |
1754 | |
1755 | /* Make sure this symbol is output as a dynamic symbol. | |
1756 | Undefined weak syms won't yet be marked as dynamic. */ | |
1757 | if (h->dynindx == -1 | |
1758 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
1759 | { | |
1760 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
b34976b6 | 1761 | return FALSE; |
0451c93c MS |
1762 | } |
1763 | ||
1764 | s = htab->sgot; | |
1765 | h->got.offset = s->_raw_size; | |
1766 | s->_raw_size += GOT_ENTRY_SIZE; | |
69fc87f1 MS |
1767 | /* R_390_TLS_GD32 needs 2 consecutive GOT slots. */ |
1768 | if (tls_type == GOT_TLS_GD) | |
1769 | s->_raw_size += GOT_ENTRY_SIZE; | |
0451c93c | 1770 | dyn = htab->elf.dynamic_sections_created; |
69fc87f1 MS |
1771 | /* R_390_TLS_IE32 needs one dynamic relocation, |
1772 | R_390_TLS_GD32 needs one if local symbol and two if global. */ | |
1773 | if ((tls_type == GOT_TLS_GD && h->dynindx == -1) | |
1774 | || tls_type >= GOT_TLS_IE) | |
1775 | htab->srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
1776 | else if (tls_type == GOT_TLS_GD) | |
1777 | htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela); | |
1778 | else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) | |
0451c93c MS |
1779 | htab->srelgot->_raw_size += sizeof (Elf32_External_Rela); |
1780 | } | |
1781 | else | |
1782 | h->got.offset = (bfd_vma) -1; | |
1783 | ||
1784 | eh = (struct elf_s390_link_hash_entry *) h; | |
1785 | if (eh->dyn_relocs == NULL) | |
b34976b6 | 1786 | return TRUE; |
0451c93c MS |
1787 | |
1788 | /* In the shared -Bsymbolic case, discard space allocated for | |
1789 | dynamic pc-relative relocs against symbols which turn out to be | |
1790 | defined in regular objects. For the normal shared case, discard | |
1791 | space for pc-relative relocs that have become local due to symbol | |
1792 | visibility changes. */ | |
1793 | ||
1794 | if (info->shared) | |
1795 | { | |
1796 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 | |
1797 | && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 | |
1798 | || info->symbolic)) | |
1799 | { | |
1800 | struct elf_s390_dyn_relocs **pp; | |
1801 | ||
1802 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
1803 | { | |
1804 | p->count -= p->pc_count; | |
1805 | p->pc_count = 0; | |
1806 | if (p->count == 0) | |
1807 | *pp = p->next; | |
1808 | else | |
1809 | pp = &p->next; | |
1810 | } | |
1811 | } | |
1812 | } | |
1813 | else | |
1814 | { | |
1815 | /* For the non-shared case, discard space for relocs against | |
1816 | symbols which turn out to need copy relocs or are not | |
1817 | dynamic. */ | |
1818 | ||
1819 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
1820 | && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
1821 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
1822 | || (htab->elf.dynamic_sections_created | |
1823 | && (h->root.type == bfd_link_hash_undefweak | |
1824 | || h->root.type == bfd_link_hash_undefined)))) | |
1825 | { | |
1826 | /* Make sure this symbol is output as a dynamic symbol. | |
1827 | Undefined weak syms won't yet be marked as dynamic. */ | |
1828 | if (h->dynindx == -1 | |
1829 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
1830 | { | |
1831 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
b34976b6 | 1832 | return FALSE; |
0451c93c MS |
1833 | } |
1834 | ||
1835 | /* If that succeeded, we know we'll be keeping all the | |
1836 | relocs. */ | |
1837 | if (h->dynindx != -1) | |
1838 | goto keep; | |
1839 | } | |
1840 | ||
1841 | eh->dyn_relocs = NULL; | |
1842 | ||
ec338859 | 1843 | keep: ; |
0451c93c MS |
1844 | } |
1845 | ||
1846 | /* Finally, allocate space. */ | |
1847 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
1848 | { | |
1849 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
1850 | sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela); | |
1851 | } | |
1852 | ||
b34976b6 | 1853 | return TRUE; |
0451c93c MS |
1854 | } |
1855 | ||
1856 | /* Find any dynamic relocs that apply to read-only sections. */ | |
1857 | ||
b34976b6 | 1858 | static bfd_boolean |
0451c93c MS |
1859 | readonly_dynrelocs (h, inf) |
1860 | struct elf_link_hash_entry *h; | |
1861 | PTR inf; | |
1862 | { | |
1863 | struct elf_s390_link_hash_entry *eh; | |
1864 | struct elf_s390_dyn_relocs *p; | |
1865 | ||
e92d460e AM |
1866 | if (h->root.type == bfd_link_hash_warning) |
1867 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
1868 | ||
0451c93c MS |
1869 | eh = (struct elf_s390_link_hash_entry *) h; |
1870 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
1871 | { | |
1872 | asection *s = p->sec->output_section; | |
1873 | ||
1874 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
1875 | { | |
1876 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
1877 | ||
1878 | info->flags |= DF_TEXTREL; | |
1879 | ||
1880 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 1881 | return FALSE; |
0451c93c MS |
1882 | } |
1883 | } | |
b34976b6 | 1884 | return TRUE; |
0451c93c MS |
1885 | } |
1886 | ||
a85d7ed0 NC |
1887 | /* Set the sizes of the dynamic sections. */ |
1888 | ||
b34976b6 | 1889 | static bfd_boolean |
a85d7ed0 | 1890 | elf_s390_size_dynamic_sections (output_bfd, info) |
29c2fb7c | 1891 | bfd *output_bfd ATTRIBUTE_UNUSED; |
a85d7ed0 NC |
1892 | struct bfd_link_info *info; |
1893 | { | |
0451c93c | 1894 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
1895 | bfd *dynobj; |
1896 | asection *s; | |
b34976b6 | 1897 | bfd_boolean relocs; |
0451c93c | 1898 | bfd *ibfd; |
a85d7ed0 | 1899 | |
0451c93c MS |
1900 | htab = elf_s390_hash_table (info); |
1901 | dynobj = htab->elf.dynobj; | |
1902 | if (dynobj == NULL) | |
1903 | abort (); | |
a85d7ed0 | 1904 | |
0451c93c | 1905 | if (htab->elf.dynamic_sections_created) |
a85d7ed0 NC |
1906 | { |
1907 | /* Set the contents of the .interp section to the interpreter. */ | |
1908 | if (! info->shared) | |
1909 | { | |
1910 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
0451c93c MS |
1911 | if (s == NULL) |
1912 | abort (); | |
a85d7ed0 NC |
1913 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; |
1914 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
1915 | } | |
1916 | } | |
a85d7ed0 | 1917 | |
0451c93c MS |
1918 | /* Set up .got offsets for local syms, and space for local dynamic |
1919 | relocs. */ | |
1920 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
a85d7ed0 | 1921 | { |
0451c93c MS |
1922 | bfd_signed_vma *local_got; |
1923 | bfd_signed_vma *end_local_got; | |
69fc87f1 | 1924 | char *local_tls_type; |
0451c93c MS |
1925 | bfd_size_type locsymcount; |
1926 | Elf_Internal_Shdr *symtab_hdr; | |
1927 | asection *srela; | |
a85d7ed0 | 1928 | |
0451c93c | 1929 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
a85d7ed0 NC |
1930 | continue; |
1931 | ||
0451c93c | 1932 | for (s = ibfd->sections; s != NULL; s = s->next) |
a85d7ed0 | 1933 | { |
ec338859 | 1934 | struct elf_s390_dyn_relocs *p; |
0451c93c | 1935 | |
ec338859 AM |
1936 | for (p = *((struct elf_s390_dyn_relocs **) |
1937 | &elf_section_data (s)->local_dynrel); | |
1938 | p != NULL; | |
1939 | p = p->next) | |
a85d7ed0 | 1940 | { |
ec338859 AM |
1941 | if (!bfd_is_abs_section (p->sec) |
1942 | && bfd_is_abs_section (p->sec->output_section)) | |
1943 | { | |
1944 | /* Input section has been discarded, either because | |
1945 | it is a copy of a linkonce section or due to | |
1946 | linker script /DISCARD/, so we'll be discarding | |
1947 | the relocs too. */ | |
1948 | } | |
248866a8 | 1949 | else if (p->count != 0) |
ec338859 AM |
1950 | { |
1951 | srela = elf_section_data (p->sec)->sreloc; | |
1952 | srela->_raw_size += p->count * sizeof (Elf32_External_Rela); | |
248866a8 AM |
1953 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
1954 | info->flags |= DF_TEXTREL; | |
ec338859 | 1955 | } |
a85d7ed0 NC |
1956 | } |
1957 | } | |
0451c93c MS |
1958 | |
1959 | local_got = elf_local_got_refcounts (ibfd); | |
1960 | if (!local_got) | |
1961 | continue; | |
1962 | ||
1963 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
1964 | locsymcount = symtab_hdr->sh_info; | |
1965 | end_local_got = local_got + locsymcount; | |
69fc87f1 | 1966 | local_tls_type = elf_s390_local_got_tls_type (ibfd); |
0451c93c MS |
1967 | s = htab->sgot; |
1968 | srela = htab->srelgot; | |
69fc87f1 | 1969 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) |
a85d7ed0 | 1970 | { |
0451c93c | 1971 | if (*local_got > 0) |
a85d7ed0 | 1972 | { |
0451c93c MS |
1973 | *local_got = s->_raw_size; |
1974 | s->_raw_size += GOT_ENTRY_SIZE; | |
69fc87f1 MS |
1975 | if (*local_tls_type == GOT_TLS_GD) |
1976 | s->_raw_size += GOT_ENTRY_SIZE; | |
0451c93c MS |
1977 | if (info->shared) |
1978 | srela->_raw_size += sizeof (Elf32_External_Rela); | |
a85d7ed0 NC |
1979 | } |
1980 | else | |
0451c93c MS |
1981 | *local_got = (bfd_vma) -1; |
1982 | } | |
1983 | } | |
1984 | ||
69fc87f1 MS |
1985 | if (htab->tls_ldm_got.refcount > 0) |
1986 | { | |
1987 | /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM32 | |
1988 | relocs. */ | |
1989 | htab->tls_ldm_got.offset = htab->sgot->_raw_size; | |
1990 | htab->sgot->_raw_size += 2 * GOT_ENTRY_SIZE; | |
1991 | htab->srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
1992 | } | |
1993 | else | |
1994 | htab->tls_ldm_got.offset = -1; | |
1995 | ||
0451c93c MS |
1996 | /* Allocate global sym .plt and .got entries, and space for global |
1997 | sym dynamic relocs. */ | |
1998 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); | |
1999 | ||
2000 | /* We now have determined the sizes of the various dynamic sections. | |
2001 | Allocate memory for them. */ | |
b34976b6 | 2002 | relocs = FALSE; |
0451c93c MS |
2003 | for (s = dynobj->sections; s != NULL; s = s->next) |
2004 | { | |
2005 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
2006 | continue; | |
2007 | ||
2008 | if (s == htab->splt | |
2009 | || s == htab->sgot | |
2010 | || s == htab->sgotplt) | |
2011 | { | |
2012 | /* Strip this section if we don't need it; see the | |
2013 | comment below. */ | |
a85d7ed0 | 2014 | } |
0451c93c MS |
2015 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
2016 | { | |
2017 | if (s->_raw_size != 0 && s != htab->srelplt) | |
b34976b6 | 2018 | relocs = TRUE; |
ec338859 | 2019 | |
0451c93c MS |
2020 | /* We use the reloc_count field as a counter if we need |
2021 | to copy relocs into the output file. */ | |
2022 | s->reloc_count = 0; | |
2023 | } | |
2024 | else | |
a85d7ed0 NC |
2025 | { |
2026 | /* It's not one of our sections, so don't allocate space. */ | |
2027 | continue; | |
2028 | } | |
2029 | ||
0451c93c | 2030 | if (s->_raw_size == 0) |
a85d7ed0 | 2031 | { |
0451c93c MS |
2032 | /* If we don't need this section, strip it from the |
2033 | output file. This is to handle .rela.bss and | |
2034 | .rela.plt. We must create it in | |
2035 | create_dynamic_sections, because it must be created | |
2036 | before the linker maps input sections to output | |
2037 | sections. The linker does that before | |
2038 | adjust_dynamic_symbol is called, and it is that | |
2039 | function which decides whether anything needs to go | |
2040 | into these sections. */ | |
2041 | ||
a85d7ed0 NC |
2042 | _bfd_strip_section_from_output (info, s); |
2043 | continue; | |
2044 | } | |
2045 | ||
0451c93c MS |
2046 | /* Allocate memory for the section contents. We use bfd_zalloc |
2047 | here in case unused entries are not reclaimed before the | |
2048 | section's contents are written out. This should not happen, | |
2049 | but this way if it does, we get a R_390_NONE reloc instead | |
2050 | of garbage. */ | |
2051 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); | |
2052 | if (s->contents == NULL) | |
b34976b6 | 2053 | return FALSE; |
a85d7ed0 | 2054 | } |
ec338859 | 2055 | |
0451c93c | 2056 | if (htab->elf.dynamic_sections_created) |
a85d7ed0 NC |
2057 | { |
2058 | /* Add some entries to the .dynamic section. We fill in the | |
2059 | values later, in elf_s390_finish_dynamic_sections, but we | |
2060 | must add the entries now so that we get the correct size for | |
2061 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
2062 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
2063 | #define add_dynamic_entry(TAG, VAL) \ |
2064 | bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
ec338859 | 2065 | |
a85d7ed0 NC |
2066 | if (! info->shared) |
2067 | { | |
dc810e39 | 2068 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 2069 | return FALSE; |
a85d7ed0 | 2070 | } |
ec338859 | 2071 | |
0451c93c | 2072 | if (htab->splt->_raw_size != 0) |
a85d7ed0 | 2073 | { |
dc810e39 AM |
2074 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
2075 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
2076 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
2077 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 2078 | return FALSE; |
a85d7ed0 | 2079 | } |
ec338859 | 2080 | |
a85d7ed0 NC |
2081 | if (relocs) |
2082 | { | |
dc810e39 AM |
2083 | if (!add_dynamic_entry (DT_RELA, 0) |
2084 | || !add_dynamic_entry (DT_RELASZ, 0) | |
2085 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
b34976b6 | 2086 | return FALSE; |
a85d7ed0 | 2087 | |
0451c93c MS |
2088 | /* If any dynamic relocs apply to a read-only section, |
2089 | then we need a DT_TEXTREL entry. */ | |
248866a8 AM |
2090 | if ((info->flags & DF_TEXTREL) == 0) |
2091 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, | |
2092 | (PTR) info); | |
ec338859 | 2093 | |
0451c93c MS |
2094 | if ((info->flags & DF_TEXTREL) != 0) |
2095 | { | |
2096 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
b34976b6 | 2097 | return FALSE; |
0451c93c | 2098 | } |
a85d7ed0 NC |
2099 | } |
2100 | } | |
dc810e39 | 2101 | #undef add_dynamic_entry |
ec338859 | 2102 | |
b34976b6 | 2103 | return TRUE; |
a85d7ed0 NC |
2104 | } |
2105 | ||
69fc87f1 MS |
2106 | /* Return the base VMA address which should be subtracted from real addresses |
2107 | when resolving @dtpoff relocation. | |
2108 | This is PT_TLS segment p_vaddr. */ | |
2109 | ||
2110 | static bfd_vma | |
2111 | dtpoff_base (info) | |
2112 | struct bfd_link_info *info; | |
2113 | { | |
2114 | /* If tls_segment is NULL, we should have signalled an error already. */ | |
2115 | if (elf_hash_table (info)->tls_segment == NULL) | |
2116 | return 0; | |
2117 | return elf_hash_table (info)->tls_segment->start; | |
2118 | } | |
2119 | ||
2120 | /* Return the relocation value for @tpoff relocation | |
2121 | if STT_TLS virtual address is ADDRESS. */ | |
2122 | ||
2123 | static bfd_vma | |
2124 | tpoff (info, address) | |
2125 | struct bfd_link_info *info; | |
2126 | bfd_vma address; | |
2127 | { | |
2128 | struct elf_link_tls_segment *tls_segment | |
2129 | = elf_hash_table (info)->tls_segment; | |
2130 | ||
2131 | /* If tls_segment is NULL, we should have signalled an error already. */ | |
2132 | if (tls_segment == NULL) | |
2133 | return 0; | |
2134 | return (align_power (tls_segment->size, tls_segment->align) | |
2135 | + tls_segment->start - address); | |
2136 | } | |
2137 | ||
2138 | /* Complain if TLS instruction relocation is against an invalid | |
2139 | instruction. */ | |
2140 | ||
2141 | static void | |
2142 | invalid_tls_insn (input_bfd, input_section, rel) | |
2143 | bfd *input_bfd; | |
2144 | asection *input_section; | |
2145 | Elf_Internal_Rela *rel; | |
2146 | { | |
2147 | reloc_howto_type *howto; | |
2148 | ||
2149 | howto = elf_howto_table + ELF32_R_TYPE (rel->r_info); | |
2150 | (*_bfd_error_handler) | |
2151 | (_("%s(%s+0x%lx): invalid instruction for TLS relocation %s"), | |
2152 | bfd_archive_filename (input_bfd), | |
2153 | bfd_get_section_name (input_bfd, input_section), | |
2154 | (long) rel->r_offset, | |
2155 | howto->name); | |
2156 | } | |
2157 | ||
a85d7ed0 NC |
2158 | /* Relocate a 390 ELF section. */ |
2159 | ||
b34976b6 | 2160 | static bfd_boolean |
a85d7ed0 NC |
2161 | elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, |
2162 | contents, relocs, local_syms, local_sections) | |
2163 | bfd *output_bfd; | |
2164 | struct bfd_link_info *info; | |
2165 | bfd *input_bfd; | |
2166 | asection *input_section; | |
2167 | bfd_byte *contents; | |
2168 | Elf_Internal_Rela *relocs; | |
2169 | Elf_Internal_Sym *local_syms; | |
2170 | asection **local_sections; | |
2171 | { | |
0451c93c | 2172 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
2173 | Elf_Internal_Shdr *symtab_hdr; |
2174 | struct elf_link_hash_entry **sym_hashes; | |
2175 | bfd_vma *local_got_offsets; | |
a85d7ed0 NC |
2176 | Elf_Internal_Rela *rel; |
2177 | Elf_Internal_Rela *relend; | |
2178 | ||
b491616a | 2179 | if (info->relocateable) |
b34976b6 | 2180 | return TRUE; |
b491616a | 2181 | |
0451c93c | 2182 | htab = elf_s390_hash_table (info); |
a85d7ed0 NC |
2183 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
2184 | sym_hashes = elf_sym_hashes (input_bfd); | |
2185 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
2186 | ||
a85d7ed0 NC |
2187 | rel = relocs; |
2188 | relend = relocs + input_section->reloc_count; | |
2189 | for (; rel < relend; rel++) | |
2190 | { | |
5236c819 | 2191 | unsigned int r_type; |
a85d7ed0 NC |
2192 | reloc_howto_type *howto; |
2193 | unsigned long r_symndx; | |
2194 | struct elf_link_hash_entry *h; | |
2195 | Elf_Internal_Sym *sym; | |
2196 | asection *sec; | |
0451c93c | 2197 | bfd_vma off; |
a85d7ed0 | 2198 | bfd_vma relocation; |
b34976b6 | 2199 | bfd_boolean unresolved_reloc; |
a85d7ed0 | 2200 | bfd_reloc_status_type r; |
69fc87f1 | 2201 | int tls_type; |
ec338859 | 2202 | |
a85d7ed0 NC |
2203 | r_type = ELF32_R_TYPE (rel->r_info); |
2204 | if (r_type == (int) R_390_GNU_VTINHERIT | |
2205 | || r_type == (int) R_390_GNU_VTENTRY) | |
2206 | continue; | |
5236c819 | 2207 | if (r_type >= (int) R_390_max) |
a85d7ed0 NC |
2208 | { |
2209 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 2210 | return FALSE; |
a85d7ed0 | 2211 | } |
ec338859 | 2212 | |
b491616a | 2213 | howto = elf_howto_table + r_type; |
a85d7ed0 | 2214 | r_symndx = ELF32_R_SYM (rel->r_info); |
5236c819 MS |
2215 | |
2216 | /* This is a final link. */ | |
a85d7ed0 NC |
2217 | h = NULL; |
2218 | sym = NULL; | |
2219 | sec = NULL; | |
b34976b6 | 2220 | unresolved_reloc = FALSE; |
a85d7ed0 NC |
2221 | if (r_symndx < symtab_hdr->sh_info) |
2222 | { | |
2223 | sym = local_syms + r_symndx; | |
2224 | sec = local_sections[r_symndx]; | |
f8df10f4 | 2225 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
a85d7ed0 NC |
2226 | } |
2227 | else | |
2228 | { | |
2229 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2230 | while (h->root.type == bfd_link_hash_indirect | |
2231 | || h->root.type == bfd_link_hash_warning) | |
2232 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
ec338859 | 2233 | |
a85d7ed0 NC |
2234 | if (h->root.type == bfd_link_hash_defined |
2235 | || h->root.type == bfd_link_hash_defweak) | |
2236 | { | |
2237 | sec = h->root.u.def.section; | |
27018c3f | 2238 | if (sec->output_section == NULL) |
a85d7ed0 | 2239 | { |
0451c93c MS |
2240 | /* Set a flag that will be cleared later if we find a |
2241 | relocation value for this symbol. output_section | |
2242 | is typically NULL for symbols satisfied by a shared | |
2243 | library. */ | |
b34976b6 | 2244 | unresolved_reloc = TRUE; |
a85d7ed0 NC |
2245 | relocation = 0; |
2246 | } | |
2247 | else | |
2248 | relocation = (h->root.u.def.value | |
2249 | + sec->output_section->vma | |
2250 | + sec->output_offset); | |
2251 | } | |
2252 | else if (h->root.type == bfd_link_hash_undefweak) | |
2253 | relocation = 0; | |
671bae9c NC |
2254 | else if (info->shared |
2255 | && (!info->symbolic || info->allow_shlib_undefined) | |
a85d7ed0 NC |
2256 | && !info->no_undefined |
2257 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
2258 | relocation = 0; | |
2259 | else | |
2260 | { | |
2261 | if (! ((*info->callbacks->undefined_symbol) | |
2262 | (info, h->root.root.string, input_bfd, | |
2263 | input_section, rel->r_offset, | |
0451c93c MS |
2264 | (!info->shared || info->no_undefined |
2265 | || ELF_ST_VISIBILITY (h->other))))) | |
b34976b6 | 2266 | return FALSE; |
a85d7ed0 NC |
2267 | relocation = 0; |
2268 | } | |
2269 | } | |
ec338859 | 2270 | |
a85d7ed0 NC |
2271 | switch (r_type) |
2272 | { | |
5236c819 MS |
2273 | case R_390_GOTPLT12: |
2274 | case R_390_GOTPLT16: | |
2275 | case R_390_GOTPLT32: | |
2276 | case R_390_GOTPLTENT: | |
2277 | /* There are three cases for a GOTPLT relocation. 1) The | |
2278 | relocation is against the jump slot entry of a plt that | |
2279 | will get emitted to the output file. 2) The relocation | |
2280 | is against the jump slot of a plt entry that has been | |
2281 | removed. elf_s390_adjust_gotplt has created a GOT entry | |
2282 | as replacement. 3) The relocation is against a local symbol. | |
2283 | Cases 2) and 3) are the same as the GOT relocation code | |
2284 | so we just have to test for case 1 and fall through for | |
2285 | the other two. */ | |
2286 | if (h != NULL && h->plt.offset != (bfd_vma) -1) | |
2287 | { | |
2288 | bfd_vma plt_index; | |
2289 | ||
2290 | /* Calc. index no. | |
2291 | Current offset - size first entry / entry size. */ | |
2292 | plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / | |
2293 | PLT_ENTRY_SIZE; | |
2294 | ||
2295 | /* Offset in GOT is PLT index plus GOT headers(3) times 4, | |
2296 | addr & GOT addr. */ | |
2297 | relocation = (plt_index + 3) * GOT_ENTRY_SIZE; | |
2298 | unresolved_reloc = FALSE; | |
2299 | ||
2300 | if (r_type == R_390_GOTPLTENT) | |
2301 | relocation += htab->sgot->output_section->vma; | |
2302 | break; | |
2303 | } | |
2304 | /* Fall through. */ | |
2305 | ||
a85d7ed0 NC |
2306 | case R_390_GOT12: |
2307 | case R_390_GOT16: | |
2308 | case R_390_GOT32: | |
befc3abb | 2309 | case R_390_GOTENT: |
a85d7ed0 NC |
2310 | /* Relocation is to the entry for this symbol in the global |
2311 | offset table. */ | |
0451c93c MS |
2312 | if (htab->sgot == NULL) |
2313 | abort (); | |
ec338859 | 2314 | |
a85d7ed0 NC |
2315 | if (h != NULL) |
2316 | { | |
b34976b6 | 2317 | bfd_boolean dyn; |
ec338859 | 2318 | |
a85d7ed0 | 2319 | off = h->got.offset; |
0451c93c MS |
2320 | dyn = htab->elf.dynamic_sections_created; |
2321 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) | |
a85d7ed0 | 2322 | || (info->shared |
0451c93c MS |
2323 | && (info->symbolic |
2324 | || h->dynindx == -1 | |
2325 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) | |
a85d7ed0 NC |
2326 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) |
2327 | { | |
2328 | /* This is actually a static link, or it is a | |
2329 | -Bsymbolic link and the symbol is defined | |
2330 | locally, or the symbol was forced to be local | |
2331 | because of a version file. We must initialize | |
2332 | this entry in the global offset table. Since the | |
2333 | offset must always be a multiple of 2, we use the | |
2334 | least significant bit to record whether we have | |
2335 | initialized it already. | |
2336 | ||
2337 | When doing a dynamic link, we create a .rel.got | |
2338 | relocation entry to initialize the value. This | |
2339 | is done in the finish_dynamic_symbol routine. */ | |
2340 | if ((off & 1) != 0) | |
2341 | off &= ~1; | |
2342 | else | |
2343 | { | |
2344 | bfd_put_32 (output_bfd, relocation, | |
0451c93c | 2345 | htab->sgot->contents + off); |
a85d7ed0 NC |
2346 | h->got.offset |= 1; |
2347 | } | |
2348 | } | |
0451c93c | 2349 | else |
b34976b6 | 2350 | unresolved_reloc = FALSE; |
a85d7ed0 NC |
2351 | } |
2352 | else | |
2353 | { | |
0451c93c MS |
2354 | if (local_got_offsets == NULL) |
2355 | abort (); | |
a85d7ed0 NC |
2356 | |
2357 | off = local_got_offsets[r_symndx]; | |
2358 | ||
2359 | /* The offset must always be a multiple of 4. We use | |
2360 | the least significant bit to record whether we have | |
2361 | already generated the necessary reloc. */ | |
2362 | if ((off & 1) != 0) | |
2363 | off &= ~1; | |
2364 | else | |
2365 | { | |
0451c93c MS |
2366 | bfd_put_32 (output_bfd, relocation, |
2367 | htab->sgot->contents + off); | |
a85d7ed0 NC |
2368 | |
2369 | if (info->shared) | |
2370 | { | |
2371 | asection *srelgot; | |
2372 | Elf_Internal_Rela outrel; | |
947216bf | 2373 | bfd_byte *loc; |
a85d7ed0 | 2374 | |
0451c93c MS |
2375 | srelgot = htab->srelgot; |
2376 | if (srelgot == NULL) | |
2377 | abort (); | |
a85d7ed0 | 2378 | |
0451c93c MS |
2379 | outrel.r_offset = (htab->sgot->output_section->vma |
2380 | + htab->sgot->output_offset | |
a85d7ed0 NC |
2381 | + off); |
2382 | outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE); | |
2383 | outrel.r_addend = relocation; | |
947216bf AM |
2384 | loc = srelgot->contents; |
2385 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela); | |
0451c93c | 2386 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
a85d7ed0 NC |
2387 | } |
2388 | ||
2389 | local_got_offsets[r_symndx] |= 1; | |
2390 | } | |
a85d7ed0 NC |
2391 | } |
2392 | ||
0451c93c MS |
2393 | if (off >= (bfd_vma) -2) |
2394 | abort (); | |
a85d7ed0 | 2395 | |
0451c93c | 2396 | relocation = htab->sgot->output_offset + off; |
befc3abb MS |
2397 | |
2398 | /* | |
2399 | * For @GOTENT the relocation is against the offset between | |
2400 | * the instruction and the symbols entry in the GOT and not | |
2401 | * between the start of the GOT and the symbols entry. We | |
2402 | * add the vma of the GOT to get the correct value. | |
2403 | */ | |
5236c819 MS |
2404 | if ( r_type == R_390_GOTENT |
2405 | || r_type == R_390_GOTPLTENT) | |
befc3abb MS |
2406 | relocation += htab->sgot->output_section->vma; |
2407 | ||
a85d7ed0 | 2408 | break; |
dc810e39 | 2409 | |
5236c819 MS |
2410 | case R_390_GOTOFF16: |
2411 | case R_390_GOTOFF32: | |
a85d7ed0 NC |
2412 | /* Relocation is relative to the start of the global offset |
2413 | table. */ | |
2414 | ||
a85d7ed0 NC |
2415 | /* Note that sgot->output_offset is not involved in this |
2416 | calculation. We always want the start of .got. If we | |
2417 | defined _GLOBAL_OFFSET_TABLE in a different way, as is | |
2418 | permitted by the ABI, we might have to change this | |
2419 | calculation. */ | |
0451c93c | 2420 | relocation -= htab->sgot->output_section->vma; |
a85d7ed0 NC |
2421 | break; |
2422 | ||
2423 | case R_390_GOTPC: | |
befc3abb | 2424 | case R_390_GOTPCDBL: |
a85d7ed0 | 2425 | /* Use global offset table as symbol value. */ |
0451c93c | 2426 | relocation = htab->sgot->output_section->vma; |
b34976b6 | 2427 | unresolved_reloc = FALSE; |
a85d7ed0 NC |
2428 | break; |
2429 | ||
2430 | case R_390_PLT16DBL: | |
befc3abb | 2431 | case R_390_PLT32DBL: |
a85d7ed0 NC |
2432 | case R_390_PLT32: |
2433 | /* Relocation is to the entry for this symbol in the | |
2434 | procedure linkage table. */ | |
2435 | ||
2436 | /* Resolve a PLT32 reloc against a local symbol directly, | |
2437 | without using the procedure linkage table. */ | |
2438 | if (h == NULL) | |
2439 | break; | |
2440 | ||
0451c93c MS |
2441 | if (h->plt.offset == (bfd_vma) -1 |
2442 | || htab->splt == NULL) | |
a85d7ed0 NC |
2443 | { |
2444 | /* We didn't make a PLT entry for this symbol. This | |
2445 | happens when statically linking PIC code, or when | |
2446 | using -Bsymbolic. */ | |
2447 | break; | |
2448 | } | |
2449 | ||
0451c93c MS |
2450 | relocation = (htab->splt->output_section->vma |
2451 | + htab->splt->output_offset | |
a85d7ed0 | 2452 | + h->plt.offset); |
b34976b6 | 2453 | unresolved_reloc = FALSE; |
a85d7ed0 NC |
2454 | break; |
2455 | ||
5236c819 MS |
2456 | case R_390_PLTOFF16: |
2457 | case R_390_PLTOFF32: | |
2458 | /* Relocation is to the entry for this symbol in the | |
2459 | procedure linkage table relative to the start of the GOT. */ | |
2460 | ||
2461 | /* For local symbols or if we didn't make a PLT entry for | |
2462 | this symbol resolve the symbol directly. */ | |
2463 | if ( h == NULL | |
2464 | || h->plt.offset == (bfd_vma) -1 | |
2465 | || htab->splt == NULL) | |
2466 | { | |
2467 | relocation -= htab->sgot->output_section->vma; | |
2468 | break; | |
2469 | } | |
2470 | ||
2471 | relocation = (htab->splt->output_section->vma | |
2472 | + htab->splt->output_offset | |
2473 | + h->plt.offset | |
2474 | - htab->sgot->output_section->vma); | |
2475 | unresolved_reloc = FALSE; | |
2476 | break; | |
2477 | ||
a85d7ed0 NC |
2478 | case R_390_8: |
2479 | case R_390_16: | |
2480 | case R_390_32: | |
2481 | case R_390_PC16: | |
2482 | case R_390_PC16DBL: | |
befc3abb | 2483 | case R_390_PC32DBL: |
a85d7ed0 | 2484 | case R_390_PC32: |
ec338859 AM |
2485 | /* r_symndx will be zero only for relocs against symbols |
2486 | from removed linkonce sections, or sections discarded by | |
2487 | a linker script. */ | |
2488 | if (r_symndx == 0 | |
2489 | || (input_section->flags & SEC_ALLOC) == 0) | |
2490 | break; | |
2491 | ||
0451c93c | 2492 | if ((info->shared |
0451c93c MS |
2493 | && ((r_type != R_390_PC16 |
2494 | && r_type != R_390_PC16DBL | |
befc3abb | 2495 | && r_type != R_390_PC32DBL |
0451c93c MS |
2496 | && r_type != R_390_PC32) |
2497 | || (h != NULL | |
2498 | && h->dynindx != -1 | |
2499 | && (! info->symbolic | |
2500 | || (h->elf_link_hash_flags | |
2501 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
2502 | || (!info->shared | |
0451c93c MS |
2503 | && h != NULL |
2504 | && h->dynindx != -1 | |
2505 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
2506 | && (((h->elf_link_hash_flags | |
2507 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
2508 | && (h->elf_link_hash_flags | |
2509 | & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
2510 | || h->root.type == bfd_link_hash_undefweak | |
2511 | || h->root.type == bfd_link_hash_undefined))) | |
a85d7ed0 NC |
2512 | { |
2513 | Elf_Internal_Rela outrel; | |
b34976b6 | 2514 | bfd_boolean skip, relocate; |
0451c93c | 2515 | asection *sreloc; |
947216bf | 2516 | bfd_byte *loc; |
ec338859 | 2517 | |
0451c93c MS |
2518 | /* When generating a shared object, these relocations |
2519 | are copied into the output file to be resolved at run | |
2520 | time. */ | |
ec338859 | 2521 | |
b34976b6 AM |
2522 | skip = FALSE; |
2523 | relocate = FALSE; | |
ec338859 | 2524 | |
c629eae0 JJ |
2525 | outrel.r_offset = |
2526 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
2527 | rel->r_offset); | |
2528 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 2529 | skip = TRUE; |
0bb2d96a | 2530 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 2531 | skip = TRUE, relocate = TRUE; |
a85d7ed0 NC |
2532 | outrel.r_offset += (input_section->output_section->vma |
2533 | + input_section->output_offset); | |
ec338859 | 2534 | |
a85d7ed0 | 2535 | if (skip) |
0bb2d96a | 2536 | memset (&outrel, 0, sizeof outrel); |
0451c93c MS |
2537 | else if (h != NULL |
2538 | && h->dynindx != -1 | |
2539 | && (r_type == R_390_PC16 | |
2540 | || r_type == R_390_PC16DBL | |
befc3abb | 2541 | || r_type == R_390_PC32DBL |
0451c93c MS |
2542 | || r_type == R_390_PC32 |
2543 | || !info->shared | |
2544 | || !info->symbolic | |
2545 | || (h->elf_link_hash_flags | |
2546 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
a85d7ed0 | 2547 | { |
a85d7ed0 | 2548 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
27018c3f | 2549 | outrel.r_addend = rel->r_addend; |
a85d7ed0 NC |
2550 | } |
2551 | else | |
2552 | { | |
0451c93c | 2553 | /* This symbol is local, or marked to become local. */ |
b34976b6 | 2554 | relocate = TRUE; |
0451c93c MS |
2555 | outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE); |
2556 | outrel.r_addend = relocation + rel->r_addend; | |
a85d7ed0 | 2557 | } |
ec338859 | 2558 | |
0451c93c MS |
2559 | sreloc = elf_section_data (input_section)->sreloc; |
2560 | if (sreloc == NULL) | |
2561 | abort (); | |
ec338859 | 2562 | |
947216bf AM |
2563 | loc = sreloc->contents; |
2564 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
0451c93c | 2565 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
ec338859 | 2566 | |
a85d7ed0 NC |
2567 | /* If this reloc is against an external symbol, we do |
2568 | not want to fiddle with the addend. Otherwise, we | |
2569 | need to include the symbol value so that it becomes | |
2570 | an addend for the dynamic reloc. */ | |
2571 | if (! relocate) | |
2572 | continue; | |
2573 | } | |
0451c93c | 2574 | break; |
ec338859 | 2575 | |
69fc87f1 MS |
2576 | /* Relocations for tls literal pool entries. */ |
2577 | case R_390_TLS_IE32: | |
2578 | if (info->shared) | |
2579 | { | |
2580 | Elf_Internal_Rela outrel; | |
2581 | asection *sreloc; | |
2582 | bfd_byte *loc; | |
2583 | ||
2584 | outrel.r_offset = rel->r_offset | |
2585 | + input_section->output_section->vma | |
2586 | + input_section->output_offset; | |
2587 | outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE); | |
2588 | sreloc = elf_section_data (input_section)->sreloc; | |
2589 | if (sreloc == NULL) | |
2590 | abort (); | |
2591 | loc = sreloc->contents; | |
2592 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
2593 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
2594 | } | |
2595 | /* Fall through */ | |
2596 | ||
2597 | case R_390_TLS_GD32: | |
2598 | case R_390_TLS_GOTIE32: | |
2599 | r_type = elf_s390_tls_transition (info, r_type, h == NULL); | |
2600 | tls_type = GOT_UNKNOWN; | |
2601 | if (h == NULL && local_got_offsets) | |
2602 | tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx]; | |
2603 | else if (h != NULL) | |
2604 | { | |
2605 | tls_type = elf_s390_hash_entry(h)->tls_type; | |
2606 | if (!info->shared && h->dynindx == -1 && tls_type >= GOT_TLS_IE) | |
2607 | r_type = R_390_TLS_LE32; | |
2608 | } | |
2609 | if (r_type == R_390_TLS_GD32 && tls_type >= GOT_TLS_IE) | |
2610 | r_type = R_390_TLS_IE32; | |
2611 | ||
2612 | if (r_type == R_390_TLS_LE32) | |
2613 | { | |
2614 | /* This relocation gets optimized away by the local exec | |
2615 | access optimization. */ | |
2616 | BFD_ASSERT (! unresolved_reloc); | |
2617 | bfd_put_32 (output_bfd, -tpoff (info, relocation), | |
2618 | contents + rel->r_offset); | |
2619 | continue; | |
2620 | } | |
2621 | ||
2622 | if (htab->sgot == NULL) | |
2623 | abort (); | |
2624 | ||
2625 | if (h != NULL) | |
2626 | off = h->got.offset; | |
2627 | else | |
2628 | { | |
2629 | if (local_got_offsets == NULL) | |
2630 | abort (); | |
2631 | ||
2632 | off = local_got_offsets[r_symndx]; | |
2633 | } | |
2634 | ||
2635 | emit_tls_relocs: | |
2636 | ||
2637 | if ((off & 1) != 0) | |
2638 | off &= ~1; | |
2639 | else | |
2640 | { | |
2641 | Elf_Internal_Rela outrel; | |
2642 | bfd_byte *loc; | |
2643 | int dr_type, indx; | |
2644 | ||
2645 | if (htab->srelgot == NULL) | |
2646 | abort (); | |
2647 | ||
2648 | outrel.r_offset = (htab->sgot->output_section->vma | |
2649 | + htab->sgot->output_offset + off); | |
2650 | ||
2651 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
2652 | if (r_type == R_390_TLS_GD32) | |
2653 | dr_type = R_390_TLS_DTPMOD; | |
2654 | else | |
2655 | dr_type = R_390_TLS_TPOFF; | |
2656 | if (dr_type == R_390_TLS_TPOFF && indx == 0) | |
2657 | outrel.r_addend = relocation - dtpoff_base (info); | |
2658 | else | |
2659 | outrel.r_addend = 0; | |
2660 | outrel.r_info = ELF32_R_INFO (indx, dr_type); | |
2661 | loc = htab->srelgot->contents; | |
2662 | loc += htab->srelgot->reloc_count++ | |
2663 | * sizeof (Elf32_External_Rela); | |
2664 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
2665 | ||
2666 | if (r_type == R_390_TLS_GD32) | |
2667 | { | |
2668 | if (indx == 0) | |
2669 | { | |
2670 | BFD_ASSERT (! unresolved_reloc); | |
2671 | bfd_put_32 (output_bfd, | |
2672 | relocation - dtpoff_base (info), | |
2673 | htab->sgot->contents + off + GOT_ENTRY_SIZE); | |
2674 | } | |
2675 | else | |
2676 | { | |
2677 | outrel.r_info = ELF32_R_INFO (indx, R_390_TLS_DTPOFF); | |
2678 | outrel.r_offset += GOT_ENTRY_SIZE; | |
2679 | outrel.r_addend = 0; | |
2680 | htab->srelgot->reloc_count++; | |
2681 | loc += sizeof (Elf32_External_Rela); | |
2682 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
2683 | } | |
2684 | } | |
2685 | ||
2686 | if (h != NULL) | |
2687 | h->got.offset |= 1; | |
2688 | else | |
2689 | local_got_offsets[r_symndx] |= 1; | |
2690 | } | |
2691 | ||
2692 | if (off >= (bfd_vma) -2) | |
2693 | abort (); | |
2694 | if (r_type == ELF32_R_TYPE (rel->r_info)) | |
2695 | { | |
2696 | relocation = htab->sgot->output_offset + off; | |
2697 | if (r_type == R_390_TLS_IE32 || r_type == R_390_TLS_IEENT) | |
2698 | relocation += htab->sgot->output_section->vma; | |
2699 | unresolved_reloc = FALSE; | |
2700 | } | |
2701 | else | |
2702 | { | |
2703 | bfd_put_32 (output_bfd, htab->sgot->output_offset + off, | |
2704 | contents + rel->r_offset); | |
2705 | continue; | |
2706 | } | |
2707 | break; | |
2708 | ||
2709 | case R_390_TLS_GOTIE12: | |
2710 | case R_390_TLS_IEENT: | |
2711 | if (h == NULL) | |
2712 | { | |
2713 | if (local_got_offsets == NULL) | |
2714 | abort(); | |
2715 | off = local_got_offsets[r_symndx]; | |
2716 | if (info->shared) | |
2717 | goto emit_tls_relocs; | |
2718 | } | |
2719 | else | |
2720 | { | |
2721 | off = h->got.offset; | |
2722 | tls_type = elf_s390_hash_entry(h)->tls_type; | |
2723 | if (info->shared || h->dynindx != -1 || tls_type < GOT_TLS_IE) | |
2724 | goto emit_tls_relocs; | |
2725 | } | |
2726 | ||
2727 | if (htab->sgot == NULL) | |
2728 | abort (); | |
2729 | ||
2730 | BFD_ASSERT (! unresolved_reloc); | |
2731 | bfd_put_32 (output_bfd, -tpoff (info, relocation), | |
2732 | htab->sgot->contents + off); | |
2733 | relocation = htab->sgot->output_offset + off; | |
2734 | if (r_type == R_390_TLS_IEENT) | |
2735 | relocation += htab->sgot->output_section->vma; | |
2736 | unresolved_reloc = FALSE; | |
2737 | break; | |
2738 | ||
2739 | case R_390_TLS_LDM32: | |
2740 | if (! info->shared) | |
2741 | /* The literal pool entry this relocation refers to gets ignored | |
2742 | by the optimized code of the local exec model. Do nothing | |
2743 | and the value will turn out zero. */ | |
2744 | continue; | |
2745 | ||
2746 | if (htab->sgot == NULL) | |
2747 | abort (); | |
2748 | ||
2749 | off = htab->tls_ldm_got.offset; | |
2750 | if (off & 1) | |
2751 | off &= ~1; | |
2752 | else | |
2753 | { | |
2754 | Elf_Internal_Rela outrel; | |
2755 | bfd_byte *loc; | |
2756 | ||
2757 | if (htab->srelgot == NULL) | |
2758 | abort (); | |
2759 | ||
2760 | outrel.r_offset = (htab->sgot->output_section->vma | |
2761 | + htab->sgot->output_offset + off); | |
2762 | ||
2763 | bfd_put_32 (output_bfd, 0, | |
2764 | htab->sgot->contents + off + GOT_ENTRY_SIZE); | |
2765 | outrel.r_info = ELF32_R_INFO (0, R_390_TLS_DTPMOD); | |
2766 | outrel.r_addend = 0; | |
2767 | loc = htab->srelgot->contents; | |
2768 | loc += htab->srelgot->reloc_count++ | |
2769 | * sizeof (Elf32_External_Rela); | |
2770 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
2771 | htab->tls_ldm_got.offset |= 1; | |
2772 | } | |
2773 | relocation = htab->sgot->output_offset + off; | |
2774 | unresolved_reloc = FALSE; | |
2775 | break; | |
2776 | ||
2777 | case R_390_TLS_LE32: | |
2778 | if (info->shared) | |
2779 | { | |
2780 | /* Linking a shared library with non-fpic code requires | |
2781 | a R_390_TLS_TPOFF relocation. */ | |
2782 | Elf_Internal_Rela outrel; | |
2783 | asection *sreloc; | |
2784 | bfd_byte *loc; | |
2785 | int indx; | |
2786 | ||
2787 | outrel.r_offset = rel->r_offset | |
2788 | + input_section->output_section->vma | |
2789 | + input_section->output_offset; | |
2790 | if (h != NULL && h->dynindx != -1) | |
2791 | indx = h->dynindx; | |
2792 | else | |
2793 | indx = 0; | |
2794 | outrel.r_info = ELF32_R_INFO (indx, R_390_TLS_TPOFF); | |
2795 | if (indx == 0) | |
2796 | outrel.r_addend = relocation - dtpoff_base (info); | |
2797 | else | |
2798 | outrel.r_addend = 0; | |
2799 | sreloc = elf_section_data (input_section)->sreloc; | |
2800 | if (sreloc == NULL) | |
2801 | abort (); | |
2802 | loc = sreloc->contents; | |
2803 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
2804 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
2805 | } | |
2806 | else | |
2807 | { | |
2808 | BFD_ASSERT (! unresolved_reloc); | |
2809 | bfd_put_32 (output_bfd, -tpoff (info, relocation), | |
2810 | contents + rel->r_offset); | |
2811 | } | |
2812 | continue; | |
2813 | ||
2814 | case R_390_TLS_LDO32: | |
2815 | if (info->shared || (input_section->flags & SEC_CODE) == 0) | |
2816 | relocation -= dtpoff_base (info); | |
2817 | else | |
2818 | /* When converting LDO to LE, we must negate. */ | |
2819 | relocation = -tpoff (info, relocation); | |
2820 | break; | |
2821 | ||
2822 | /* Relocations for tls instructions. */ | |
2823 | case R_390_TLS_LOAD: | |
2824 | case R_390_TLS_GDCALL: | |
2825 | case R_390_TLS_LDCALL: | |
2826 | tls_type = GOT_UNKNOWN; | |
2827 | if (h == NULL && local_got_offsets) | |
2828 | tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx]; | |
2829 | else if (h != NULL) | |
2830 | tls_type = elf_s390_hash_entry(h)->tls_type; | |
2831 | ||
2832 | if (tls_type == GOT_TLS_GD) | |
2833 | continue; | |
2834 | ||
2835 | if (r_type == R_390_TLS_LOAD) | |
2836 | { | |
2837 | if (!info->shared && (h == NULL || h->dynindx == -1)) | |
2838 | { | |
2839 | /* IE->LE transition. Four valid cases: | |
2840 | l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0 | |
2841 | l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0 | |
2842 | l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0 | |
2843 | l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */ | |
2844 | unsigned int insn, ry; | |
2845 | ||
2846 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
2847 | ry = 0; | |
2848 | if ((insn & 0xff00f000) == 0x58000000) | |
2849 | /* l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0 */ | |
2850 | ry = (insn & 0x000f0000); | |
2851 | else if ((insn & 0xff0f0000) == 0x58000000) | |
2852 | /* l %rx,0(0,%ry) -> lr %rx,%ry + bcr 0,0 */ | |
2853 | ry = (insn & 0x0000f000) << 4; | |
2854 | else if ((insn & 0xff00f000) == 0x5800c000) | |
2855 | /* l %rx,0(%ry,%r12) -> lr %rx,%ry + bcr 0,0 */ | |
2856 | ry = (insn & 0x000f0000); | |
2857 | else if ((insn & 0xff0f0000) == 0x580c0000) | |
2858 | /* l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */ | |
2859 | ry = (insn & 0x0000f000) << 4; | |
2860 | else | |
2861 | invalid_tls_insn (input_bfd, input_section, rel); | |
2862 | insn = 0x18000700 | (insn & 0x00f00000) | ry; | |
2863 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
2864 | } | |
2865 | } | |
2866 | else if (r_type == R_390_TLS_GDCALL) | |
2867 | { | |
2868 | unsigned int insn; | |
2869 | ||
2870 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
2871 | if ((insn & 0xff000fff) != 0x4d000000) | |
2872 | invalid_tls_insn (input_bfd, input_section, rel); | |
2873 | if (!info->shared && (h == NULL || h->dynindx == -1)) | |
2874 | /* GD->LE transition. | |
2875 | bas %r14,0(%rx,%r13) -> bc 0,0 */ | |
2876 | insn = 0x47000000; | |
2877 | else | |
2878 | /* GD->IE transition. | |
2879 | bas %r14,0(%rx,%r13) -> l %r2,0(%r2,%r12) */ | |
2880 | insn = 0x5822c000; | |
2881 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
2882 | } | |
2883 | else if (r_type == R_390_TLS_LDCALL) | |
2884 | { | |
2885 | if (!info->shared) | |
2886 | { | |
2887 | unsigned int insn; | |
2888 | ||
2889 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
2890 | if ((insn & 0xff000fff) != 0x4d000000) | |
2891 | invalid_tls_insn (input_bfd, input_section, rel); | |
2892 | /* LD->LE transition. | |
2893 | bas %r14,0(%rx,%r13) -> bc 0,0 */ | |
2894 | insn = 0x47000000; | |
2895 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
2896 | } | |
2897 | } | |
2898 | continue; | |
2899 | ||
0451c93c MS |
2900 | default: |
2901 | break; | |
2902 | } | |
ec338859 | 2903 | |
239e1f3a AM |
2904 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
2905 | because such sections are not SEC_ALLOC and thus ld.so will | |
2906 | not process them. */ | |
0451c93c | 2907 | if (unresolved_reloc |
239e1f3a | 2908 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
0451c93c MS |
2909 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
2910 | (*_bfd_error_handler) | |
2911 | (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"), | |
2912 | bfd_archive_filename (input_bfd), | |
2913 | bfd_get_section_name (input_bfd, input_section), | |
2914 | (long) rel->r_offset, | |
2915 | h->root.root.string); | |
ec338859 | 2916 | |
a85d7ed0 | 2917 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
0451c93c MS |
2918 | contents, rel->r_offset, |
2919 | relocation, rel->r_addend); | |
ec338859 | 2920 | |
a85d7ed0 NC |
2921 | if (r != bfd_reloc_ok) |
2922 | { | |
0451c93c | 2923 | const char *name; |
ec338859 | 2924 | |
0451c93c MS |
2925 | if (h != NULL) |
2926 | name = h->root.root.string; | |
2927 | else | |
a85d7ed0 | 2928 | { |
0451c93c MS |
2929 | name = bfd_elf_string_from_elf_section (input_bfd, |
2930 | symtab_hdr->sh_link, | |
2931 | sym->st_name); | |
2932 | if (name == NULL) | |
b34976b6 | 2933 | return FALSE; |
0451c93c MS |
2934 | if (*name == '\0') |
2935 | name = bfd_section_name (input_bfd, sec); | |
2936 | } | |
ec338859 | 2937 | |
0451c93c MS |
2938 | if (r == bfd_reloc_overflow) |
2939 | { | |
ec338859 | 2940 | |
0451c93c MS |
2941 | if (! ((*info->callbacks->reloc_overflow) |
2942 | (info, name, howto->name, (bfd_vma) 0, | |
2943 | input_bfd, input_section, rel->r_offset))) | |
b34976b6 | 2944 | return FALSE; |
0451c93c MS |
2945 | } |
2946 | else | |
2947 | { | |
2948 | (*_bfd_error_handler) | |
2949 | (_("%s(%s+0x%lx): reloc against `%s': error %d"), | |
2950 | bfd_archive_filename (input_bfd), | |
2951 | bfd_get_section_name (input_bfd, input_section), | |
2952 | (long) rel->r_offset, name, (int) r); | |
b34976b6 | 2953 | return FALSE; |
a85d7ed0 NC |
2954 | } |
2955 | } | |
2956 | } | |
ec338859 | 2957 | |
b34976b6 | 2958 | return TRUE; |
a85d7ed0 NC |
2959 | } |
2960 | ||
2961 | /* Finish up dynamic symbol handling. We set the contents of various | |
2962 | dynamic sections here. */ | |
2963 | ||
b34976b6 | 2964 | static bfd_boolean |
a85d7ed0 NC |
2965 | elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym) |
2966 | bfd *output_bfd; | |
2967 | struct bfd_link_info *info; | |
2968 | struct elf_link_hash_entry *h; | |
2969 | Elf_Internal_Sym *sym; | |
2970 | { | |
0451c93c | 2971 | struct elf_s390_link_hash_table *htab; |
ec338859 | 2972 | |
0451c93c | 2973 | htab = elf_s390_hash_table (info); |
ec338859 | 2974 | |
a85d7ed0 NC |
2975 | if (h->plt.offset != (bfd_vma) -1) |
2976 | { | |
0451c93c MS |
2977 | bfd_vma plt_index; |
2978 | bfd_vma got_offset; | |
a85d7ed0 | 2979 | Elf_Internal_Rela rela; |
947216bf | 2980 | bfd_byte *loc; |
a85d7ed0 | 2981 | bfd_vma relative_offset; |
ec338859 | 2982 | |
a85d7ed0 NC |
2983 | /* This symbol has an entry in the procedure linkage table. Set |
2984 | it up. */ | |
ec338859 | 2985 | |
0451c93c MS |
2986 | if (h->dynindx == -1 |
2987 | || htab->splt == NULL | |
2988 | || htab->sgotplt == NULL | |
2989 | || htab->srelplt == NULL) | |
2990 | abort (); | |
a85d7ed0 | 2991 | |
dc810e39 | 2992 | /* Calc. index no. |
a85d7ed0 NC |
2993 | Current offset - size first entry / entry size. */ |
2994 | plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE; | |
2995 | ||
2996 | /* Offset in GOT is PLT index plus GOT headers(3) times 4, | |
2997 | addr & GOT addr. */ | |
2998 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; | |
2999 | ||
3000 | /* S390 uses halfwords for relative branch calc! */ | |
dc810e39 AM |
3001 | relative_offset = - ((PLT_FIRST_ENTRY_SIZE + |
3002 | (PLT_ENTRY_SIZE * plt_index) + 18) / 2); | |
a85d7ed0 NC |
3003 | /* If offset is > 32768, branch to a previous branch |
3004 | 390 can only handle +-64 K jumps. */ | |
dc810e39 AM |
3005 | if ( -32768 > (int) relative_offset ) |
3006 | relative_offset = | |
3007 | -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2); | |
a85d7ed0 NC |
3008 | |
3009 | /* Fill in the entry in the procedure linkage table. */ | |
3010 | if (!info->shared) | |
0451c93c MS |
3011 | { |
3012 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0, | |
3013 | htab->splt->contents + h->plt.offset); | |
3014 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1, | |
3015 | htab->splt->contents + h->plt.offset + 4); | |
3016 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2, | |
3017 | htab->splt->contents + h->plt.offset + 8); | |
3018 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3, | |
3019 | htab->splt->contents + h->plt.offset + 12); | |
3020 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4, | |
3021 | htab->splt->contents + h->plt.offset + 16); | |
3022 | bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3023 | htab->splt->contents + h->plt.offset + 20); | |
3024 | bfd_put_32 (output_bfd, | |
3025 | (htab->sgotplt->output_section->vma | |
3026 | + htab->sgotplt->output_offset | |
3027 | + got_offset), | |
3028 | htab->splt->contents + h->plt.offset + 24); | |
3029 | } | |
a85d7ed0 | 3030 | else if (got_offset < 4096) |
0451c93c MS |
3031 | { |
3032 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD0 + got_offset, | |
3033 | htab->splt->contents + h->plt.offset); | |
3034 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD1, | |
3035 | htab->splt->contents + h->plt.offset + 4); | |
3036 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD2, | |
3037 | htab->splt->contents + h->plt.offset + 8); | |
3038 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD3, | |
3039 | htab->splt->contents + h->plt.offset + 12); | |
3040 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD4, | |
3041 | htab->splt->contents + h->plt.offset + 16); | |
3042 | bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3043 | htab->splt->contents + h->plt.offset + 20); | |
3044 | bfd_put_32 (output_bfd, (bfd_vma) 0, | |
3045 | htab->splt->contents + h->plt.offset + 24); | |
3046 | } | |
a85d7ed0 | 3047 | else if (got_offset < 32768) |
0451c93c MS |
3048 | { |
3049 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD0 + got_offset, | |
3050 | htab->splt->contents + h->plt.offset); | |
3051 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD1, | |
3052 | htab->splt->contents + h->plt.offset + 4); | |
3053 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD2, | |
3054 | htab->splt->contents + h->plt.offset + 8); | |
3055 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD3, | |
3056 | htab->splt->contents + h->plt.offset + 12); | |
3057 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD4, | |
3058 | htab->splt->contents + h->plt.offset + 16); | |
3059 | bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3060 | htab->splt->contents + h->plt.offset + 20); | |
3061 | bfd_put_32 (output_bfd, (bfd_vma) 0, | |
3062 | htab->splt->contents + h->plt.offset + 24); | |
3063 | } | |
a85d7ed0 | 3064 | else |
0451c93c MS |
3065 | { |
3066 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD0, | |
3067 | htab->splt->contents + h->plt.offset); | |
3068 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD1, | |
3069 | htab->splt->contents + h->plt.offset + 4); | |
3070 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD2, | |
3071 | htab->splt->contents + h->plt.offset + 8); | |
3072 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD3, | |
3073 | htab->splt->contents + h->plt.offset + 12); | |
3074 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD4, | |
3075 | htab->splt->contents + h->plt.offset + 16); | |
3076 | bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3077 | htab->splt->contents + h->plt.offset + 20); | |
3078 | bfd_put_32 (output_bfd, got_offset, | |
3079 | htab->splt->contents + h->plt.offset + 24); | |
3080 | } | |
a85d7ed0 NC |
3081 | /* Insert offset into reloc. table here. */ |
3082 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), | |
0451c93c | 3083 | htab->splt->contents + h->plt.offset + 28); |
a85d7ed0 NC |
3084 | |
3085 | /* Fill in the entry in the global offset table. | |
3086 | Points to instruction after GOT offset. */ | |
3087 | bfd_put_32 (output_bfd, | |
0451c93c MS |
3088 | (htab->splt->output_section->vma |
3089 | + htab->splt->output_offset | |
a85d7ed0 NC |
3090 | + h->plt.offset |
3091 | + 12), | |
0451c93c | 3092 | htab->sgotplt->contents + got_offset); |
a85d7ed0 | 3093 | |
0451c93c MS |
3094 | /* Fill in the entry in the .rela.plt section. */ |
3095 | rela.r_offset = (htab->sgotplt->output_section->vma | |
3096 | + htab->sgotplt->output_offset | |
3097 | + got_offset); | |
3098 | rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT); | |
3099 | rela.r_addend = 0; | |
947216bf | 3100 | loc = htab->srelplt->contents + plt_index * sizeof (Elf32_External_Rela); |
0451c93c | 3101 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
ec338859 | 3102 | |
a85d7ed0 NC |
3103 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
3104 | { | |
3105 | /* Mark the symbol as undefined, rather than as defined in | |
0451c93c MS |
3106 | the .plt section. Leave the value alone. This is a clue |
3107 | for the dynamic linker, to make function pointer | |
3108 | comparisons work between an application and shared | |
ec338859 | 3109 | library. */ |
a85d7ed0 NC |
3110 | sym->st_shndx = SHN_UNDEF; |
3111 | } | |
3112 | } | |
ec338859 | 3113 | |
69fc87f1 MS |
3114 | if (h->got.offset != (bfd_vma) -1 |
3115 | && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD | |
3116 | && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE | |
3117 | && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT) | |
a85d7ed0 | 3118 | { |
a85d7ed0 | 3119 | Elf_Internal_Rela rela; |
947216bf | 3120 | bfd_byte *loc; |
a85d7ed0 NC |
3121 | |
3122 | /* This symbol has an entry in the global offset table. Set it | |
3123 | up. */ | |
3124 | ||
0451c93c MS |
3125 | if (htab->sgot == NULL || htab->srelgot == NULL) |
3126 | abort (); | |
a85d7ed0 | 3127 | |
0451c93c MS |
3128 | rela.r_offset = (htab->sgot->output_section->vma |
3129 | + htab->sgot->output_offset | |
dc810e39 | 3130 | + (h->got.offset &~ (bfd_vma) 1)); |
a85d7ed0 NC |
3131 | |
3132 | /* If this is a static link, or it is a -Bsymbolic link and the | |
3133 | symbol is defined locally or was forced to be local because | |
3134 | of a version file, we just want to emit a RELATIVE reloc. | |
3135 | The entry in the global offset table will already have been | |
3136 | initialized in the relocate_section function. */ | |
0451c93c MS |
3137 | if (info->shared |
3138 | && (info->symbolic | |
3139 | || h->dynindx == -1 | |
3140 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) | |
3141 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) | |
3142 | { | |
3143 | BFD_ASSERT((h->got.offset & 1) != 0); | |
3144 | rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE); | |
3145 | rela.r_addend = (h->root.u.def.value | |
a85d7ed0 NC |
3146 | + h->root.u.def.section->output_section->vma |
3147 | + h->root.u.def.section->output_offset); | |
3148 | } | |
3149 | else | |
3150 | { | |
3151 | BFD_ASSERT((h->got.offset & 1) == 0); | |
0451c93c | 3152 | bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.offset); |
a85d7ed0 NC |
3153 | rela.r_info = ELF32_R_INFO (h->dynindx, R_390_GLOB_DAT); |
3154 | rela.r_addend = 0; | |
3155 | } | |
3156 | ||
947216bf AM |
3157 | loc = htab->srelgot->contents; |
3158 | loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela); | |
0451c93c | 3159 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
a85d7ed0 NC |
3160 | } |
3161 | ||
3162 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
3163 | { | |
a85d7ed0 | 3164 | Elf_Internal_Rela rela; |
947216bf | 3165 | bfd_byte *loc; |
a85d7ed0 NC |
3166 | |
3167 | /* This symbols needs a copy reloc. Set it up. */ | |
3168 | ||
0451c93c MS |
3169 | if (h->dynindx == -1 |
3170 | || (h->root.type != bfd_link_hash_defined | |
3171 | && h->root.type != bfd_link_hash_defweak) | |
3172 | || htab->srelbss == NULL) | |
3173 | abort (); | |
a85d7ed0 NC |
3174 | |
3175 | rela.r_offset = (h->root.u.def.value | |
3176 | + h->root.u.def.section->output_section->vma | |
3177 | + h->root.u.def.section->output_offset); | |
3178 | rela.r_info = ELF32_R_INFO (h->dynindx, R_390_COPY); | |
3179 | rela.r_addend = 0; | |
947216bf AM |
3180 | loc = htab->srelbss->contents; |
3181 | loc += htab->srelbss->reloc_count++ * sizeof (Elf32_External_Rela); | |
0451c93c | 3182 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
a85d7ed0 NC |
3183 | } |
3184 | ||
3185 | /* Mark some specially defined symbols as absolute. */ | |
3186 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
3187 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 | |
3188 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) | |
3189 | sym->st_shndx = SHN_ABS; | |
3190 | ||
b34976b6 | 3191 | return TRUE; |
a85d7ed0 NC |
3192 | } |
3193 | ||
0451c93c MS |
3194 | /* Used to decide how to sort relocs in an optimal manner for the |
3195 | dynamic linker, before writing them out. */ | |
3196 | ||
3197 | static enum elf_reloc_type_class | |
3198 | elf_s390_reloc_type_class (rela) | |
3199 | const Elf_Internal_Rela *rela; | |
3200 | { | |
3201 | switch ((int) ELF32_R_TYPE (rela->r_info)) | |
3202 | { | |
3203 | case R_390_RELATIVE: | |
3204 | return reloc_class_relative; | |
3205 | case R_390_JMP_SLOT: | |
3206 | return reloc_class_plt; | |
3207 | case R_390_COPY: | |
3208 | return reloc_class_copy; | |
3209 | default: | |
3210 | return reloc_class_normal; | |
3211 | } | |
3212 | } | |
3213 | ||
a85d7ed0 NC |
3214 | /* Finish up the dynamic sections. */ |
3215 | ||
b34976b6 | 3216 | static bfd_boolean |
a85d7ed0 NC |
3217 | elf_s390_finish_dynamic_sections (output_bfd, info) |
3218 | bfd *output_bfd; | |
3219 | struct bfd_link_info *info; | |
3220 | { | |
0451c93c | 3221 | struct elf_s390_link_hash_table *htab; |
a85d7ed0 NC |
3222 | bfd *dynobj; |
3223 | asection *sdyn; | |
a85d7ed0 | 3224 | |
0451c93c MS |
3225 | htab = elf_s390_hash_table (info); |
3226 | dynobj = htab->elf.dynobj; | |
a85d7ed0 NC |
3227 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
3228 | ||
0451c93c | 3229 | if (htab->elf.dynamic_sections_created) |
a85d7ed0 | 3230 | { |
a85d7ed0 NC |
3231 | Elf32_External_Dyn *dyncon, *dynconend; |
3232 | ||
0451c93c MS |
3233 | if (sdyn == NULL || htab->sgot == NULL) |
3234 | abort (); | |
a85d7ed0 NC |
3235 | |
3236 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
3237 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
3238 | for (; dyncon < dynconend; dyncon++) | |
3239 | { | |
3240 | Elf_Internal_Dyn dyn; | |
a85d7ed0 | 3241 | asection *s; |
ec338859 | 3242 | |
a85d7ed0 | 3243 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
ec338859 | 3244 | |
a85d7ed0 NC |
3245 | switch (dyn.d_tag) |
3246 | { | |
3247 | default: | |
0451c93c | 3248 | continue; |
ec338859 | 3249 | |
a85d7ed0 | 3250 | case DT_PLTGOT: |
0451c93c MS |
3251 | dyn.d_un.d_ptr = htab->sgot->output_section->vma; |
3252 | break; | |
ec338859 | 3253 | |
a85d7ed0 | 3254 | case DT_JMPREL: |
0451c93c | 3255 | dyn.d_un.d_ptr = htab->srelplt->output_section->vma; |
a85d7ed0 NC |
3256 | break; |
3257 | ||
3258 | case DT_PLTRELSZ: | |
0451c93c | 3259 | s = htab->srelplt->output_section; |
a85d7ed0 NC |
3260 | if (s->_cooked_size != 0) |
3261 | dyn.d_un.d_val = s->_cooked_size; | |
3262 | else | |
3263 | dyn.d_un.d_val = s->_raw_size; | |
a85d7ed0 NC |
3264 | break; |
3265 | } | |
0451c93c MS |
3266 | |
3267 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
a85d7ed0 NC |
3268 | } |
3269 | ||
3270 | /* Fill in the special first entry in the procedure linkage table. */ | |
0451c93c | 3271 | if (htab->splt && htab->splt->_raw_size > 0) |
a85d7ed0 | 3272 | { |
0451c93c | 3273 | memset (htab->splt->contents, 0, PLT_FIRST_ENTRY_SIZE); |
a85d7ed0 | 3274 | if (info->shared) |
0451c93c | 3275 | { |
dc810e39 | 3276 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD0, |
0451c93c | 3277 | htab->splt->contents ); |
dc810e39 | 3278 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD1, |
0451c93c | 3279 | htab->splt->contents +4 ); |
dc810e39 | 3280 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD2, |
0451c93c | 3281 | htab->splt->contents +8 ); |
dc810e39 | 3282 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD3, |
0451c93c | 3283 | htab->splt->contents +12 ); |
dc810e39 | 3284 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD4, |
0451c93c | 3285 | htab->splt->contents +16 ); |
a85d7ed0 NC |
3286 | } |
3287 | else | |
3288 | { | |
0451c93c MS |
3289 | bfd_put_32 (output_bfd, (bfd_vma)PLT_FIRST_ENTRY_WORD0, |
3290 | htab->splt->contents ); | |
dc810e39 | 3291 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1, |
0451c93c | 3292 | htab->splt->contents +4 ); |
dc810e39 | 3293 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD2, |
0451c93c | 3294 | htab->splt->contents +8 ); |
dc810e39 | 3295 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3, |
0451c93c | 3296 | htab->splt->contents +12 ); |
dc810e39 | 3297 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4, |
0451c93c | 3298 | htab->splt->contents +16 ); |
dc810e39 | 3299 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5, |
0451c93c | 3300 | htab->splt->contents +20 ); |
a85d7ed0 | 3301 | bfd_put_32 (output_bfd, |
0451c93c MS |
3302 | htab->sgotplt->output_section->vma |
3303 | + htab->sgotplt->output_offset, | |
3304 | htab->splt->contents + 24); | |
a85d7ed0 | 3305 | } |
0451c93c MS |
3306 | elf_section_data (htab->splt->output_section) |
3307 | ->this_hdr.sh_entsize = 4; | |
a85d7ed0 NC |
3308 | } |
3309 | ||
3310 | } | |
3311 | ||
0451c93c | 3312 | if (htab->sgotplt) |
a85d7ed0 | 3313 | { |
0451c93c MS |
3314 | /* Fill in the first three entries in the global offset table. */ |
3315 | if (htab->sgotplt->_raw_size > 0) | |
3316 | { | |
3317 | bfd_put_32 (output_bfd, | |
3318 | (sdyn == NULL ? (bfd_vma) 0 | |
3319 | : sdyn->output_section->vma + sdyn->output_offset), | |
3320 | htab->sgotplt->contents); | |
3321 | /* One entry for shared object struct ptr. */ | |
3322 | bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 4); | |
3323 | /* One entry for _dl_runtime_resolve. */ | |
3324 | bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8); | |
3325 | } | |
a85d7ed0 | 3326 | |
0451c93c MS |
3327 | elf_section_data (htab->sgotplt->output_section) |
3328 | ->this_hdr.sh_entsize = 4; | |
3329 | } | |
b34976b6 | 3330 | return TRUE; |
a85d7ed0 NC |
3331 | } |
3332 | ||
b34976b6 | 3333 | static bfd_boolean |
979f4a38 NC |
3334 | elf_s390_grok_prstatus (abfd, note) |
3335 | bfd * abfd; | |
3336 | Elf_Internal_Note * note; | |
3337 | { | |
3338 | int offset; | |
3339 | unsigned int raw_size; | |
3340 | ||
3341 | switch (note->descsz) | |
3342 | { | |
3343 | default: | |
b34976b6 | 3344 | return FALSE; |
979f4a38 NC |
3345 | |
3346 | case 224: /* S/390 Linux. */ | |
3347 | /* pr_cursig */ | |
3348 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
3349 | ||
3350 | /* pr_pid */ | |
3351 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
3352 | ||
3353 | /* pr_reg */ | |
3354 | offset = 72; | |
3355 | raw_size = 144; | |
3356 | break; | |
3357 | } | |
3358 | ||
3359 | /* Make a ".reg/999" section. */ | |
3360 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
3361 | raw_size, note->descpos + offset); | |
3362 | } | |
3363 | ||
a85d7ed0 NC |
3364 | #define TARGET_BIG_SYM bfd_elf32_s390_vec |
3365 | #define TARGET_BIG_NAME "elf32-s390" | |
3366 | #define ELF_ARCH bfd_arch_s390 | |
3367 | #define ELF_MACHINE_CODE EM_S390 | |
3368 | #define ELF_MACHINE_ALT1 EM_S390_OLD | |
3369 | #define ELF_MAXPAGESIZE 0x1000 | |
3370 | ||
3371 | #define elf_backend_can_gc_sections 1 | |
51b64d56 | 3372 | #define elf_backend_can_refcount 1 |
a85d7ed0 NC |
3373 | #define elf_backend_want_got_plt 1 |
3374 | #define elf_backend_plt_readonly 1 | |
3375 | #define elf_backend_want_plt_sym 0 | |
3376 | #define elf_backend_got_header_size 12 | |
3377 | #define elf_backend_plt_header_size PLT_ENTRY_SIZE | |
b491616a | 3378 | #define elf_backend_rela_normal 1 |
a85d7ed0 NC |
3379 | |
3380 | #define elf_info_to_howto elf_s390_info_to_howto | |
3381 | ||
a85d7ed0 NC |
3382 | #define bfd_elf32_bfd_is_local_label_name elf_s390_is_local_label_name |
3383 | #define bfd_elf32_bfd_link_hash_table_create elf_s390_link_hash_table_create | |
3384 | #define bfd_elf32_bfd_reloc_type_lookup elf_s390_reloc_type_lookup | |
3385 | ||
3386 | #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol | |
3387 | #define elf_backend_check_relocs elf_s390_check_relocs | |
0451c93c MS |
3388 | #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol |
3389 | #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections | |
a85d7ed0 NC |
3390 | #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections |
3391 | #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol | |
3392 | #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook | |
3393 | #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook | |
0451c93c | 3394 | #define elf_backend_reloc_type_class elf_s390_reloc_type_class |
a85d7ed0 NC |
3395 | #define elf_backend_relocate_section elf_s390_relocate_section |
3396 | #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections | |
29c2fb7c | 3397 | #define elf_backend_reloc_type_class elf_s390_reloc_type_class |
979f4a38 | 3398 | #define elf_backend_grok_prstatus elf_s390_grok_prstatus |
a85d7ed0 | 3399 | |
69fc87f1 | 3400 | #define bfd_elf32_mkobject elf_s390_mkobject |
a85d7ed0 NC |
3401 | #define elf_backend_object_p elf_s390_object_p |
3402 | ||
3403 | #include "elf32-target.h" |