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