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