/src/binutils-gdb/bfd/elf32-m68k.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Motorola 68k series support for 32-bit ELF |
2 | | Copyright (C) 1993-2025 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of BFD, the Binary File Descriptor library. |
5 | | |
6 | | This program is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3 of the License, or |
9 | | (at your option) any later version. |
10 | | |
11 | | This program is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with this program; if not, write to the Free Software |
18 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | | MA 02110-1301, USA. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include "bfd.h" |
23 | | #include "bfdlink.h" |
24 | | #include "libbfd.h" |
25 | | #include "elf-bfd.h" |
26 | | #include "elf/m68k.h" |
27 | | #include "opcode/m68k.h" |
28 | | #include "cpu-m68k.h" |
29 | | #include "elf32-m68k.h" |
30 | | |
31 | | static bool |
32 | | elf_m68k_discard_copies (struct elf_link_hash_entry *, void *); |
33 | | |
34 | | static reloc_howto_type howto_table[] = |
35 | | { |
36 | | HOWTO(R_68K_NONE, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", false, 0, 0x00000000,false), |
37 | | HOWTO(R_68K_32, 0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", false, 0, 0xffffffff,false), |
38 | | HOWTO(R_68K_16, 0, 2,16, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", false, 0, 0x0000ffff,false), |
39 | | HOWTO(R_68K_8, 0, 1, 8, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", false, 0, 0x000000ff,false), |
40 | | HOWTO(R_68K_PC32, 0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", false, 0, 0xffffffff,true), |
41 | | HOWTO(R_68K_PC16, 0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", false, 0, 0x0000ffff,true), |
42 | | HOWTO(R_68K_PC8, 0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", false, 0, 0x000000ff,true), |
43 | | HOWTO(R_68K_GOT32, 0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", false, 0, 0xffffffff,true), |
44 | | HOWTO(R_68K_GOT16, 0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", false, 0, 0x0000ffff,true), |
45 | | HOWTO(R_68K_GOT8, 0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", false, 0, 0x000000ff,true), |
46 | | HOWTO(R_68K_GOT32O, 0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", false, 0, 0xffffffff,false), |
47 | | HOWTO(R_68K_GOT16O, 0, 2,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", false, 0, 0x0000ffff,false), |
48 | | HOWTO(R_68K_GOT8O, 0, 1, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", false, 0, 0x000000ff,false), |
49 | | HOWTO(R_68K_PLT32, 0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", false, 0, 0xffffffff,true), |
50 | | HOWTO(R_68K_PLT16, 0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", false, 0, 0x0000ffff,true), |
51 | | HOWTO(R_68K_PLT8, 0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", false, 0, 0x000000ff,true), |
52 | | HOWTO(R_68K_PLT32O, 0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", false, 0, 0xffffffff,false), |
53 | | HOWTO(R_68K_PLT16O, 0, 2,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", false, 0, 0x0000ffff,false), |
54 | | HOWTO(R_68K_PLT8O, 0, 1, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", false, 0, 0x000000ff,false), |
55 | | HOWTO(R_68K_COPY, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", false, 0, 0xffffffff,false), |
56 | | HOWTO(R_68K_GLOB_DAT, 0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", false, 0, 0xffffffff,false), |
57 | | HOWTO(R_68K_JMP_SLOT, 0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", false, 0, 0xffffffff,false), |
58 | | HOWTO(R_68K_RELATIVE, 0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", false, 0, 0xffffffff,false), |
59 | | /* GNU extension to record C++ vtable hierarchy. */ |
60 | | HOWTO (R_68K_GNU_VTINHERIT, /* type */ |
61 | | 0, /* rightshift */ |
62 | | 4, /* size */ |
63 | | 0, /* bitsize */ |
64 | | false, /* pc_relative */ |
65 | | 0, /* bitpos */ |
66 | | complain_overflow_dont, /* complain_on_overflow */ |
67 | | NULL, /* special_function */ |
68 | | "R_68K_GNU_VTINHERIT", /* name */ |
69 | | false, /* partial_inplace */ |
70 | | 0, /* src_mask */ |
71 | | 0, /* dst_mask */ |
72 | | false), |
73 | | /* GNU extension to record C++ vtable member usage. */ |
74 | | HOWTO (R_68K_GNU_VTENTRY, /* type */ |
75 | | 0, /* rightshift */ |
76 | | 4, /* size */ |
77 | | 0, /* bitsize */ |
78 | | false, /* pc_relative */ |
79 | | 0, /* bitpos */ |
80 | | complain_overflow_dont, /* complain_on_overflow */ |
81 | | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ |
82 | | "R_68K_GNU_VTENTRY", /* name */ |
83 | | false, /* partial_inplace */ |
84 | | 0, /* src_mask */ |
85 | | 0, /* dst_mask */ |
86 | | false), |
87 | | |
88 | | /* TLS general dynamic variable reference. */ |
89 | | HOWTO (R_68K_TLS_GD32, /* type */ |
90 | | 0, /* rightshift */ |
91 | | 4, /* size */ |
92 | | 32, /* bitsize */ |
93 | | false, /* pc_relative */ |
94 | | 0, /* bitpos */ |
95 | | complain_overflow_bitfield, /* complain_on_overflow */ |
96 | | bfd_elf_generic_reloc, /* special_function */ |
97 | | "R_68K_TLS_GD32", /* name */ |
98 | | false, /* partial_inplace */ |
99 | | 0, /* src_mask */ |
100 | | 0xffffffff, /* dst_mask */ |
101 | | false), /* pcrel_offset */ |
102 | | |
103 | | HOWTO (R_68K_TLS_GD16, /* type */ |
104 | | 0, /* rightshift */ |
105 | | 2, /* size */ |
106 | | 16, /* bitsize */ |
107 | | false, /* pc_relative */ |
108 | | 0, /* bitpos */ |
109 | | complain_overflow_signed, /* complain_on_overflow */ |
110 | | bfd_elf_generic_reloc, /* special_function */ |
111 | | "R_68K_TLS_GD16", /* name */ |
112 | | false, /* partial_inplace */ |
113 | | 0, /* src_mask */ |
114 | | 0x0000ffff, /* dst_mask */ |
115 | | false), /* pcrel_offset */ |
116 | | |
117 | | HOWTO (R_68K_TLS_GD8, /* type */ |
118 | | 0, /* rightshift */ |
119 | | 1, /* size */ |
120 | | 8, /* bitsize */ |
121 | | false, /* pc_relative */ |
122 | | 0, /* bitpos */ |
123 | | complain_overflow_signed, /* complain_on_overflow */ |
124 | | bfd_elf_generic_reloc, /* special_function */ |
125 | | "R_68K_TLS_GD8", /* name */ |
126 | | false, /* partial_inplace */ |
127 | | 0, /* src_mask */ |
128 | | 0x000000ff, /* dst_mask */ |
129 | | false), /* pcrel_offset */ |
130 | | |
131 | | /* TLS local dynamic variable reference. */ |
132 | | HOWTO (R_68K_TLS_LDM32, /* type */ |
133 | | 0, /* rightshift */ |
134 | | 4, /* size */ |
135 | | 32, /* bitsize */ |
136 | | false, /* pc_relative */ |
137 | | 0, /* bitpos */ |
138 | | complain_overflow_bitfield, /* complain_on_overflow */ |
139 | | bfd_elf_generic_reloc, /* special_function */ |
140 | | "R_68K_TLS_LDM32", /* name */ |
141 | | false, /* partial_inplace */ |
142 | | 0, /* src_mask */ |
143 | | 0xffffffff, /* dst_mask */ |
144 | | false), /* pcrel_offset */ |
145 | | |
146 | | HOWTO (R_68K_TLS_LDM16, /* type */ |
147 | | 0, /* rightshift */ |
148 | | 2, /* size */ |
149 | | 16, /* bitsize */ |
150 | | false, /* pc_relative */ |
151 | | 0, /* bitpos */ |
152 | | complain_overflow_signed, /* complain_on_overflow */ |
153 | | bfd_elf_generic_reloc, /* special_function */ |
154 | | "R_68K_TLS_LDM16", /* name */ |
155 | | false, /* partial_inplace */ |
156 | | 0, /* src_mask */ |
157 | | 0x0000ffff, /* dst_mask */ |
158 | | false), /* pcrel_offset */ |
159 | | |
160 | | HOWTO (R_68K_TLS_LDM8, /* type */ |
161 | | 0, /* rightshift */ |
162 | | 1, /* size */ |
163 | | 8, /* bitsize */ |
164 | | false, /* pc_relative */ |
165 | | 0, /* bitpos */ |
166 | | complain_overflow_signed, /* complain_on_overflow */ |
167 | | bfd_elf_generic_reloc, /* special_function */ |
168 | | "R_68K_TLS_LDM8", /* name */ |
169 | | false, /* partial_inplace */ |
170 | | 0, /* src_mask */ |
171 | | 0x000000ff, /* dst_mask */ |
172 | | false), /* pcrel_offset */ |
173 | | |
174 | | HOWTO (R_68K_TLS_LDO32, /* type */ |
175 | | 0, /* rightshift */ |
176 | | 4, /* size */ |
177 | | 32, /* bitsize */ |
178 | | false, /* pc_relative */ |
179 | | 0, /* bitpos */ |
180 | | complain_overflow_bitfield, /* complain_on_overflow */ |
181 | | bfd_elf_generic_reloc, /* special_function */ |
182 | | "R_68K_TLS_LDO32", /* name */ |
183 | | false, /* partial_inplace */ |
184 | | 0, /* src_mask */ |
185 | | 0xffffffff, /* dst_mask */ |
186 | | false), /* pcrel_offset */ |
187 | | |
188 | | HOWTO (R_68K_TLS_LDO16, /* type */ |
189 | | 0, /* rightshift */ |
190 | | 2, /* size */ |
191 | | 16, /* bitsize */ |
192 | | false, /* pc_relative */ |
193 | | 0, /* bitpos */ |
194 | | complain_overflow_signed, /* complain_on_overflow */ |
195 | | bfd_elf_generic_reloc, /* special_function */ |
196 | | "R_68K_TLS_LDO16", /* name */ |
197 | | false, /* partial_inplace */ |
198 | | 0, /* src_mask */ |
199 | | 0x0000ffff, /* dst_mask */ |
200 | | false), /* pcrel_offset */ |
201 | | |
202 | | HOWTO (R_68K_TLS_LDO8, /* type */ |
203 | | 0, /* rightshift */ |
204 | | 1, /* size */ |
205 | | 8, /* bitsize */ |
206 | | false, /* pc_relative */ |
207 | | 0, /* bitpos */ |
208 | | complain_overflow_signed, /* complain_on_overflow */ |
209 | | bfd_elf_generic_reloc, /* special_function */ |
210 | | "R_68K_TLS_LDO8", /* name */ |
211 | | false, /* partial_inplace */ |
212 | | 0, /* src_mask */ |
213 | | 0x000000ff, /* dst_mask */ |
214 | | false), /* pcrel_offset */ |
215 | | |
216 | | /* TLS initial execution variable reference. */ |
217 | | HOWTO (R_68K_TLS_IE32, /* type */ |
218 | | 0, /* rightshift */ |
219 | | 4, /* size */ |
220 | | 32, /* bitsize */ |
221 | | false, /* pc_relative */ |
222 | | 0, /* bitpos */ |
223 | | complain_overflow_bitfield, /* complain_on_overflow */ |
224 | | bfd_elf_generic_reloc, /* special_function */ |
225 | | "R_68K_TLS_IE32", /* name */ |
226 | | false, /* partial_inplace */ |
227 | | 0, /* src_mask */ |
228 | | 0xffffffff, /* dst_mask */ |
229 | | false), /* pcrel_offset */ |
230 | | |
231 | | HOWTO (R_68K_TLS_IE16, /* type */ |
232 | | 0, /* rightshift */ |
233 | | 2, /* size */ |
234 | | 16, /* bitsize */ |
235 | | false, /* pc_relative */ |
236 | | 0, /* bitpos */ |
237 | | complain_overflow_signed, /* complain_on_overflow */ |
238 | | bfd_elf_generic_reloc, /* special_function */ |
239 | | "R_68K_TLS_IE16", /* name */ |
240 | | false, /* partial_inplace */ |
241 | | 0, /* src_mask */ |
242 | | 0x0000ffff, /* dst_mask */ |
243 | | false), /* pcrel_offset */ |
244 | | |
245 | | HOWTO (R_68K_TLS_IE8, /* type */ |
246 | | 0, /* rightshift */ |
247 | | 1, /* size */ |
248 | | 8, /* bitsize */ |
249 | | false, /* pc_relative */ |
250 | | 0, /* bitpos */ |
251 | | complain_overflow_signed, /* complain_on_overflow */ |
252 | | bfd_elf_generic_reloc, /* special_function */ |
253 | | "R_68K_TLS_IE8", /* name */ |
254 | | false, /* partial_inplace */ |
255 | | 0, /* src_mask */ |
256 | | 0x000000ff, /* dst_mask */ |
257 | | false), /* pcrel_offset */ |
258 | | |
259 | | /* TLS local execution variable reference. */ |
260 | | HOWTO (R_68K_TLS_LE32, /* type */ |
261 | | 0, /* rightshift */ |
262 | | 4, /* size */ |
263 | | 32, /* bitsize */ |
264 | | false, /* pc_relative */ |
265 | | 0, /* bitpos */ |
266 | | complain_overflow_bitfield, /* complain_on_overflow */ |
267 | | bfd_elf_generic_reloc, /* special_function */ |
268 | | "R_68K_TLS_LE32", /* name */ |
269 | | false, /* partial_inplace */ |
270 | | 0, /* src_mask */ |
271 | | 0xffffffff, /* dst_mask */ |
272 | | false), /* pcrel_offset */ |
273 | | |
274 | | HOWTO (R_68K_TLS_LE16, /* type */ |
275 | | 0, /* rightshift */ |
276 | | 2, /* size */ |
277 | | 16, /* bitsize */ |
278 | | false, /* pc_relative */ |
279 | | 0, /* bitpos */ |
280 | | complain_overflow_signed, /* complain_on_overflow */ |
281 | | bfd_elf_generic_reloc, /* special_function */ |
282 | | "R_68K_TLS_LE16", /* name */ |
283 | | false, /* partial_inplace */ |
284 | | 0, /* src_mask */ |
285 | | 0x0000ffff, /* dst_mask */ |
286 | | false), /* pcrel_offset */ |
287 | | |
288 | | HOWTO (R_68K_TLS_LE8, /* type */ |
289 | | 0, /* rightshift */ |
290 | | 1, /* size */ |
291 | | 8, /* bitsize */ |
292 | | false, /* pc_relative */ |
293 | | 0, /* bitpos */ |
294 | | complain_overflow_signed, /* complain_on_overflow */ |
295 | | bfd_elf_generic_reloc, /* special_function */ |
296 | | "R_68K_TLS_LE8", /* name */ |
297 | | false, /* partial_inplace */ |
298 | | 0, /* src_mask */ |
299 | | 0x000000ff, /* dst_mask */ |
300 | | false), /* pcrel_offset */ |
301 | | |
302 | | /* TLS GD/LD dynamic relocations. */ |
303 | | HOWTO (R_68K_TLS_DTPMOD32, /* type */ |
304 | | 0, /* rightshift */ |
305 | | 4, /* size */ |
306 | | 32, /* bitsize */ |
307 | | false, /* pc_relative */ |
308 | | 0, /* bitpos */ |
309 | | complain_overflow_dont, /* complain_on_overflow */ |
310 | | bfd_elf_generic_reloc, /* special_function */ |
311 | | "R_68K_TLS_DTPMOD32", /* name */ |
312 | | false, /* partial_inplace */ |
313 | | 0, /* src_mask */ |
314 | | 0xffffffff, /* dst_mask */ |
315 | | false), /* pcrel_offset */ |
316 | | |
317 | | HOWTO (R_68K_TLS_DTPREL32, /* type */ |
318 | | 0, /* rightshift */ |
319 | | 4, /* size */ |
320 | | 32, /* bitsize */ |
321 | | false, /* pc_relative */ |
322 | | 0, /* bitpos */ |
323 | | complain_overflow_dont, /* complain_on_overflow */ |
324 | | bfd_elf_generic_reloc, /* special_function */ |
325 | | "R_68K_TLS_DTPREL32", /* name */ |
326 | | false, /* partial_inplace */ |
327 | | 0, /* src_mask */ |
328 | | 0xffffffff, /* dst_mask */ |
329 | | false), /* pcrel_offset */ |
330 | | |
331 | | HOWTO (R_68K_TLS_TPREL32, /* type */ |
332 | | 0, /* rightshift */ |
333 | | 4, /* size */ |
334 | | 32, /* bitsize */ |
335 | | false, /* pc_relative */ |
336 | | 0, /* bitpos */ |
337 | | complain_overflow_dont, /* complain_on_overflow */ |
338 | | bfd_elf_generic_reloc, /* special_function */ |
339 | | "R_68K_TLS_TPREL32", /* name */ |
340 | | false, /* partial_inplace */ |
341 | | 0, /* src_mask */ |
342 | | 0xffffffff, /* dst_mask */ |
343 | | false), /* pcrel_offset */ |
344 | | }; |
345 | | |
346 | | static bool |
347 | | rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) |
348 | 0 | { |
349 | 0 | unsigned int indx = ELF32_R_TYPE (dst->r_info); |
350 | |
|
351 | 0 | if (indx >= (unsigned int) R_68K_max) |
352 | 0 | { |
353 | | /* xgettext:c-format */ |
354 | 0 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
355 | 0 | abfd, indx); |
356 | 0 | bfd_set_error (bfd_error_bad_value); |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | cache_ptr->howto = &howto_table[indx]; |
360 | 0 | return true; |
361 | 0 | } |
362 | | |
363 | | #define elf_info_to_howto rtype_to_howto |
364 | | |
365 | | static const struct |
366 | | { |
367 | | bfd_reloc_code_real_type bfd_val; |
368 | | int elf_val; |
369 | | } |
370 | | reloc_map[] = |
371 | | { |
372 | | { BFD_RELOC_NONE, R_68K_NONE }, |
373 | | { BFD_RELOC_32, R_68K_32 }, |
374 | | { BFD_RELOC_16, R_68K_16 }, |
375 | | { BFD_RELOC_8, R_68K_8 }, |
376 | | { BFD_RELOC_32_PCREL, R_68K_PC32 }, |
377 | | { BFD_RELOC_16_PCREL, R_68K_PC16 }, |
378 | | { BFD_RELOC_8_PCREL, R_68K_PC8 }, |
379 | | { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 }, |
380 | | { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 }, |
381 | | { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 }, |
382 | | { BFD_RELOC_32_GOTOFF, R_68K_GOT32O }, |
383 | | { BFD_RELOC_16_GOTOFF, R_68K_GOT16O }, |
384 | | { BFD_RELOC_8_GOTOFF, R_68K_GOT8O }, |
385 | | { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 }, |
386 | | { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 }, |
387 | | { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 }, |
388 | | { BFD_RELOC_32_PLTOFF, R_68K_PLT32O }, |
389 | | { BFD_RELOC_16_PLTOFF, R_68K_PLT16O }, |
390 | | { BFD_RELOC_8_PLTOFF, R_68K_PLT8O }, |
391 | | { BFD_RELOC_NONE, R_68K_COPY }, |
392 | | { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT }, |
393 | | { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT }, |
394 | | { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE }, |
395 | | { BFD_RELOC_CTOR, R_68K_32 }, |
396 | | { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT }, |
397 | | { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY }, |
398 | | { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 }, |
399 | | { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 }, |
400 | | { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 }, |
401 | | { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 }, |
402 | | { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 }, |
403 | | { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 }, |
404 | | { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 }, |
405 | | { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 }, |
406 | | { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 }, |
407 | | { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 }, |
408 | | { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 }, |
409 | | { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 }, |
410 | | { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 }, |
411 | | { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 }, |
412 | | { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 }, |
413 | | }; |
414 | | |
415 | | static reloc_howto_type * |
416 | | reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
417 | | bfd_reloc_code_real_type code) |
418 | 0 | { |
419 | 0 | unsigned int i; |
420 | 0 | for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++) |
421 | 0 | { |
422 | 0 | if (reloc_map[i].bfd_val == code) |
423 | 0 | return &howto_table[reloc_map[i].elf_val]; |
424 | 0 | } |
425 | 0 | return 0; |
426 | 0 | } |
427 | | |
428 | | static reloc_howto_type * |
429 | | reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) |
430 | 0 | { |
431 | 0 | unsigned int i; |
432 | |
|
433 | 0 | for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++) |
434 | 0 | if (howto_table[i].name != NULL |
435 | 0 | && strcasecmp (howto_table[i].name, r_name) == 0) |
436 | 0 | return &howto_table[i]; |
437 | | |
438 | 0 | return NULL; |
439 | 0 | } |
440 | | |
441 | | #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup |
442 | | #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup |
443 | | #define ELF_ARCH bfd_arch_m68k |
444 | | #define ELF_TARGET_ID M68K_ELF_DATA |
445 | | |
446 | | /* Functions for the m68k ELF linker. */ |
447 | | |
448 | | /* The name of the dynamic interpreter. This is put in the .interp |
449 | | section. */ |
450 | | |
451 | 0 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" |
452 | | |
453 | | /* Describes one of the various PLT styles. */ |
454 | | |
455 | | struct elf_m68k_plt_info |
456 | | { |
457 | | /* The size of each PLT entry. */ |
458 | | bfd_vma size; |
459 | | |
460 | | /* The template for the first PLT entry. */ |
461 | | const bfd_byte *plt0_entry; |
462 | | |
463 | | /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations. |
464 | | The comments by each member indicate the value that the relocation |
465 | | is against. */ |
466 | | struct { |
467 | | unsigned int got4; /* .got + 4 */ |
468 | | unsigned int got8; /* .got + 8 */ |
469 | | } plt0_relocs; |
470 | | |
471 | | /* The template for a symbol's PLT entry. */ |
472 | | const bfd_byte *symbol_entry; |
473 | | |
474 | | /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations. |
475 | | The comments by each member indicate the value that the relocation |
476 | | is against. */ |
477 | | struct { |
478 | | unsigned int got; /* the symbol's .got.plt entry */ |
479 | | unsigned int plt; /* .plt */ |
480 | | } symbol_relocs; |
481 | | |
482 | | /* The offset of the resolver stub from the start of SYMBOL_ENTRY. |
483 | | The stub starts with "move.l #relocoffset,%d0". */ |
484 | | bfd_vma symbol_resolve_entry; |
485 | | }; |
486 | | |
487 | | /* The size in bytes of an entry in the procedure linkage table. */ |
488 | | |
489 | | #define PLT_ENTRY_SIZE 20 |
490 | | |
491 | | /* The first entry in a procedure linkage table looks like this. See |
492 | | the SVR4 ABI m68k supplement to see how this works. */ |
493 | | |
494 | | static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] = |
495 | | { |
496 | | 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ |
497 | | 0, 0, 0, 2, /* + (.got + 4) - . */ |
498 | | 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */ |
499 | | 0, 0, 0, 2, /* + (.got + 8) - . */ |
500 | | 0, 0, 0, 0 /* pad out to 20 bytes. */ |
501 | | }; |
502 | | |
503 | | /* Subsequent entries in a procedure linkage table look like this. */ |
504 | | |
505 | | static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] = |
506 | | { |
507 | | 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */ |
508 | | 0, 0, 0, 2, /* + (.got.plt entry) - . */ |
509 | | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
510 | | 0, 0, 0, 0, /* + reloc index */ |
511 | | 0x60, 0xff, /* bra.l .plt */ |
512 | | 0, 0, 0, 0 /* + .plt - . */ |
513 | | }; |
514 | | |
515 | | static const struct elf_m68k_plt_info elf_m68k_plt_info = |
516 | | { |
517 | | PLT_ENTRY_SIZE, |
518 | | elf_m68k_plt0_entry, { 4, 12 }, |
519 | | elf_m68k_plt_entry, { 4, 16 }, 8 |
520 | | }; |
521 | | |
522 | | #define ISAB_PLT_ENTRY_SIZE 24 |
523 | | |
524 | | static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] = |
525 | | { |
526 | | 0x20, 0x3c, /* move.l #offset,%d0 */ |
527 | | 0, 0, 0, 0, /* + (.got + 4) - . */ |
528 | | 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */ |
529 | | 0x20, 0x3c, /* move.l #offset,%d0 */ |
530 | | 0, 0, 0, 0, /* + (.got + 8) - . */ |
531 | | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
532 | | 0x4e, 0xd0, /* jmp (%a0) */ |
533 | | 0x4e, 0x71 /* nop */ |
534 | | }; |
535 | | |
536 | | /* Subsequent entries in a procedure linkage table look like this. */ |
537 | | |
538 | | static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] = |
539 | | { |
540 | | 0x20, 0x3c, /* move.l #offset,%d0 */ |
541 | | 0, 0, 0, 0, /* + (.got.plt entry) - . */ |
542 | | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
543 | | 0x4e, 0xd0, /* jmp (%a0) */ |
544 | | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
545 | | 0, 0, 0, 0, /* + reloc index */ |
546 | | 0x60, 0xff, /* bra.l .plt */ |
547 | | 0, 0, 0, 0 /* + .plt - . */ |
548 | | }; |
549 | | |
550 | | static const struct elf_m68k_plt_info elf_isab_plt_info = |
551 | | { |
552 | | ISAB_PLT_ENTRY_SIZE, |
553 | | elf_isab_plt0_entry, { 2, 12 }, |
554 | | elf_isab_plt_entry, { 2, 20 }, 12 |
555 | | }; |
556 | | |
557 | | #define ISAC_PLT_ENTRY_SIZE 24 |
558 | | |
559 | | static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] = |
560 | | { |
561 | | 0x20, 0x3c, /* move.l #offset,%d0 */ |
562 | | 0, 0, 0, 0, /* replaced with .got + 4 - . */ |
563 | | 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */ |
564 | | 0x20, 0x3c, /* move.l #offset,%d0 */ |
565 | | 0, 0, 0, 0, /* replaced with .got + 8 - . */ |
566 | | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
567 | | 0x4e, 0xd0, /* jmp (%a0) */ |
568 | | 0x4e, 0x71 /* nop */ |
569 | | }; |
570 | | |
571 | | /* Subsequent entries in a procedure linkage table look like this. */ |
572 | | |
573 | | static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] = |
574 | | { |
575 | | 0x20, 0x3c, /* move.l #offset,%d0 */ |
576 | | 0, 0, 0, 0, /* replaced with (.got entry) - . */ |
577 | | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
578 | | 0x4e, 0xd0, /* jmp (%a0) */ |
579 | | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
580 | | 0, 0, 0, 0, /* replaced with offset into relocation table */ |
581 | | 0x61, 0xff, /* bsr.l .plt */ |
582 | | 0, 0, 0, 0 /* replaced with .plt - . */ |
583 | | }; |
584 | | |
585 | | static const struct elf_m68k_plt_info elf_isac_plt_info = |
586 | | { |
587 | | ISAC_PLT_ENTRY_SIZE, |
588 | | elf_isac_plt0_entry, { 2, 12}, |
589 | | elf_isac_plt_entry, { 2, 20 }, 12 |
590 | | }; |
591 | | |
592 | | #define CPU32_PLT_ENTRY_SIZE 24 |
593 | | /* Procedure linkage table entries for the cpu32 */ |
594 | | static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] = |
595 | | { |
596 | | 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ |
597 | | 0, 0, 0, 2, /* + (.got + 4) - . */ |
598 | | 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ |
599 | | 0, 0, 0, 2, /* + (.got + 8) - . */ |
600 | | 0x4e, 0xd1, /* jmp %a1@ */ |
601 | | 0, 0, 0, 0, /* pad out to 24 bytes. */ |
602 | | 0, 0 |
603 | | }; |
604 | | |
605 | | static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] = |
606 | | { |
607 | | 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ |
608 | | 0, 0, 0, 2, /* + (.got.plt entry) - . */ |
609 | | 0x4e, 0xd1, /* jmp %a1@ */ |
610 | | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
611 | | 0, 0, 0, 0, /* + reloc index */ |
612 | | 0x60, 0xff, /* bra.l .plt */ |
613 | | 0, 0, 0, 0, /* + .plt - . */ |
614 | | 0, 0 |
615 | | }; |
616 | | |
617 | | static const struct elf_m68k_plt_info elf_cpu32_plt_info = |
618 | | { |
619 | | CPU32_PLT_ENTRY_SIZE, |
620 | | elf_cpu32_plt0_entry, { 4, 12 }, |
621 | | elf_cpu32_plt_entry, { 4, 18 }, 10 |
622 | | }; |
623 | | |
624 | | /* The m68k linker needs to keep track of the number of relocs that it |
625 | | decides to copy in check_relocs for each symbol. This is so that it |
626 | | can discard PC relative relocs if it doesn't need them when linking |
627 | | with -Bsymbolic. We store the information in a field extending the |
628 | | regular ELF linker hash table. */ |
629 | | |
630 | | /* This structure keeps track of the number of PC relative relocs we have |
631 | | copied for a given symbol. */ |
632 | | |
633 | | struct elf_m68k_pcrel_relocs_copied |
634 | | { |
635 | | /* Next section. */ |
636 | | struct elf_m68k_pcrel_relocs_copied *next; |
637 | | /* A section in dynobj. */ |
638 | | asection *section; |
639 | | /* Number of relocs copied in this section. */ |
640 | | bfd_size_type count; |
641 | | }; |
642 | | |
643 | | /* Forward declaration. */ |
644 | | struct elf_m68k_got_entry; |
645 | | |
646 | | /* m68k ELF linker hash entry. */ |
647 | | |
648 | | struct elf_m68k_link_hash_entry |
649 | | { |
650 | | struct elf_link_hash_entry root; |
651 | | |
652 | | /* Number of PC relative relocs copied for this symbol. */ |
653 | | struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied; |
654 | | |
655 | | /* Key to got_entries. */ |
656 | | unsigned long got_entry_key; |
657 | | |
658 | | /* List of GOT entries for this symbol. This list is build during |
659 | | offset finalization and is used within elf_m68k_finish_dynamic_symbol |
660 | | to traverse all GOT entries for a particular symbol. |
661 | | |
662 | | ??? We could've used root.got.glist field instead, but having |
663 | | a separate field is cleaner. */ |
664 | | struct elf_m68k_got_entry *glist; |
665 | | }; |
666 | | |
667 | 0 | #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent)) |
668 | | |
669 | | /* Key part of GOT entry in hashtable. */ |
670 | | struct elf_m68k_got_entry_key |
671 | | { |
672 | | /* BFD in which this symbol was defined. NULL for global symbols. */ |
673 | | const bfd *bfd; |
674 | | |
675 | | /* Symbol index. Either local symbol index or h->got_entry_key. */ |
676 | | unsigned long symndx; |
677 | | |
678 | | /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32}, |
679 | | R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}. |
680 | | |
681 | | From perspective of hashtable key, only elf_m68k_got_reloc_type (type) |
682 | | matters. That is, we distinguish between, say, R_68K_GOT16O |
683 | | and R_68K_GOT32O when allocating offsets, but they are considered to be |
684 | | the same when searching got->entries. */ |
685 | | enum elf_m68k_reloc_type type; |
686 | | }; |
687 | | |
688 | | /* Size of the GOT offset suitable for relocation. */ |
689 | | enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST }; |
690 | | |
691 | | /* Entry of the GOT. */ |
692 | | struct elf_m68k_got_entry |
693 | | { |
694 | | /* GOT entries are put into a got->entries hashtable. This is the key. */ |
695 | | struct elf_m68k_got_entry_key key_; |
696 | | |
697 | | /* GOT entry data. We need s1 before offset finalization and s2 after. */ |
698 | | union |
699 | | { |
700 | | struct |
701 | | { |
702 | | /* Number of times this entry is referenced. */ |
703 | | bfd_vma refcount; |
704 | | } s1; |
705 | | |
706 | | struct |
707 | | { |
708 | | /* Offset from the start of .got section. To calculate offset relative |
709 | | to GOT pointer one should subtract got->offset from this value. */ |
710 | | bfd_vma offset; |
711 | | |
712 | | /* Pointer to the next GOT entry for this global symbol. |
713 | | Symbols have at most one entry in one GOT, but might |
714 | | have entries in more than one GOT. |
715 | | Root of this list is h->glist. |
716 | | NULL for local symbols. */ |
717 | | struct elf_m68k_got_entry *next; |
718 | | } s2; |
719 | | } u; |
720 | | }; |
721 | | |
722 | | /* Return representative type for relocation R_TYPE. |
723 | | This is used to avoid enumerating many relocations in comparisons, |
724 | | switches etc. */ |
725 | | |
726 | | static enum elf_m68k_reloc_type |
727 | | elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type) |
728 | 0 | { |
729 | 0 | switch (r_type) |
730 | 0 | { |
731 | | /* In most cases R_68K_GOTx relocations require the very same |
732 | | handling as R_68K_GOT32O relocation. In cases when we need |
733 | | to distinguish between the two, we use explicitly compare against |
734 | | r_type. */ |
735 | 0 | case R_68K_GOT32: |
736 | 0 | case R_68K_GOT16: |
737 | 0 | case R_68K_GOT8: |
738 | 0 | case R_68K_GOT32O: |
739 | 0 | case R_68K_GOT16O: |
740 | 0 | case R_68K_GOT8O: |
741 | 0 | return R_68K_GOT32O; |
742 | | |
743 | 0 | case R_68K_TLS_GD32: |
744 | 0 | case R_68K_TLS_GD16: |
745 | 0 | case R_68K_TLS_GD8: |
746 | 0 | return R_68K_TLS_GD32; |
747 | | |
748 | 0 | case R_68K_TLS_LDM32: |
749 | 0 | case R_68K_TLS_LDM16: |
750 | 0 | case R_68K_TLS_LDM8: |
751 | 0 | return R_68K_TLS_LDM32; |
752 | | |
753 | 0 | case R_68K_TLS_IE32: |
754 | 0 | case R_68K_TLS_IE16: |
755 | 0 | case R_68K_TLS_IE8: |
756 | 0 | return R_68K_TLS_IE32; |
757 | | |
758 | 0 | default: |
759 | 0 | BFD_ASSERT (false); |
760 | 0 | return 0; |
761 | 0 | } |
762 | 0 | } |
763 | | |
764 | | /* Return size of the GOT entry offset for relocation R_TYPE. */ |
765 | | |
766 | | static enum elf_m68k_got_offset_size |
767 | | elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type) |
768 | 0 | { |
769 | 0 | switch (r_type) |
770 | 0 | { |
771 | 0 | case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8: |
772 | 0 | case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32: |
773 | 0 | case R_68K_TLS_IE32: |
774 | 0 | return R_32; |
775 | | |
776 | 0 | case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16: |
777 | 0 | case R_68K_TLS_IE16: |
778 | 0 | return R_16; |
779 | | |
780 | 0 | case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8: |
781 | 0 | case R_68K_TLS_IE8: |
782 | 0 | return R_8; |
783 | | |
784 | 0 | default: |
785 | 0 | BFD_ASSERT (false); |
786 | 0 | return 0; |
787 | 0 | } |
788 | 0 | } |
789 | | |
790 | | /* Return number of GOT entries we need to allocate in GOT for |
791 | | relocation R_TYPE. */ |
792 | | |
793 | | static bfd_vma |
794 | | elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type) |
795 | 0 | { |
796 | 0 | switch (elf_m68k_reloc_got_type (r_type)) |
797 | 0 | { |
798 | 0 | case R_68K_GOT32O: |
799 | 0 | case R_68K_TLS_IE32: |
800 | 0 | return 1; |
801 | | |
802 | 0 | case R_68K_TLS_GD32: |
803 | 0 | case R_68K_TLS_LDM32: |
804 | 0 | return 2; |
805 | | |
806 | 0 | default: |
807 | 0 | BFD_ASSERT (false); |
808 | 0 | return 0; |
809 | 0 | } |
810 | 0 | } |
811 | | |
812 | | /* Return TRUE if relocation R_TYPE is a TLS one. */ |
813 | | |
814 | | static bool |
815 | | elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type) |
816 | 0 | { |
817 | 0 | switch (r_type) |
818 | 0 | { |
819 | 0 | case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8: |
820 | 0 | case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8: |
821 | 0 | case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8: |
822 | 0 | case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8: |
823 | 0 | case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8: |
824 | 0 | case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32: |
825 | 0 | return true; |
826 | | |
827 | 0 | default: |
828 | 0 | return false; |
829 | 0 | } |
830 | 0 | } |
831 | | |
832 | | /* Data structure representing a single GOT. */ |
833 | | struct elf_m68k_got |
834 | | { |
835 | | /* Hashtable of 'struct elf_m68k_got_entry's. |
836 | | Starting size of this table is the maximum number of |
837 | | R_68K_GOT8O entries. */ |
838 | | htab_t entries; |
839 | | |
840 | | /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require |
841 | | several GOT slots. |
842 | | |
843 | | n_slots[R_8] is the count of R_8 slots in this GOT. |
844 | | n_slots[R_16] is the cumulative count of R_8 and R_16 slots |
845 | | in this GOT. |
846 | | n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots |
847 | | in this GOT. This is the total number of slots. */ |
848 | | bfd_vma n_slots[R_LAST]; |
849 | | |
850 | | /* Number of local (entry->key_.h == NULL) slots in this GOT. |
851 | | This is only used to properly calculate size of .rela.got section; |
852 | | see elf_m68k_partition_multi_got. */ |
853 | | bfd_vma local_n_slots; |
854 | | |
855 | | /* Offset of this GOT relative to beginning of .got section. */ |
856 | | bfd_vma offset; |
857 | | }; |
858 | | |
859 | | /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */ |
860 | | struct elf_m68k_bfd2got_entry |
861 | | { |
862 | | /* BFD. */ |
863 | | const bfd *bfd; |
864 | | |
865 | | /* Assigned GOT. Before partitioning multi-GOT each BFD has its own |
866 | | GOT structure. After partitioning several BFD's might [and often do] |
867 | | share a single GOT. */ |
868 | | struct elf_m68k_got *got; |
869 | | }; |
870 | | |
871 | | /* The main data structure holding all the pieces. */ |
872 | | struct elf_m68k_multi_got |
873 | | { |
874 | | /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry |
875 | | here, then it doesn't need a GOT (this includes the case of a BFD |
876 | | having an empty GOT). |
877 | | |
878 | | ??? This hashtable can be replaced by an array indexed by bfd->id. */ |
879 | | htab_t bfd2got; |
880 | | |
881 | | /* Next symndx to assign a global symbol. |
882 | | h->got_entry_key is initialized from this counter. */ |
883 | | unsigned long global_symndx; |
884 | | }; |
885 | | |
886 | | /* m68k ELF linker hash table. */ |
887 | | |
888 | | struct elf_m68k_link_hash_table |
889 | | { |
890 | | struct elf_link_hash_table root; |
891 | | |
892 | | /* The PLT format used by this link, or NULL if the format has not |
893 | | yet been chosen. */ |
894 | | const struct elf_m68k_plt_info *plt_info; |
895 | | |
896 | | /* True, if GP is loaded within each function which uses it. |
897 | | Set to TRUE when GOT negative offsets or multi-GOT is enabled. */ |
898 | | bool local_gp_p; |
899 | | |
900 | | /* Switch controlling use of negative offsets to double the size of GOTs. */ |
901 | | bool use_neg_got_offsets_p; |
902 | | |
903 | | /* Switch controlling generation of multiple GOTs. */ |
904 | | bool allow_multigot_p; |
905 | | |
906 | | /* Multi-GOT data structure. */ |
907 | | struct elf_m68k_multi_got multi_got_; |
908 | | }; |
909 | | |
910 | | /* Get the m68k ELF linker hash table from a link_info structure. */ |
911 | | |
912 | | #define elf_m68k_hash_table(p) \ |
913 | 0 | ((is_elf_hash_table ((p)->hash) \ |
914 | 0 | && elf_hash_table_id (elf_hash_table (p)) == M68K_ELF_DATA) \ |
915 | 0 | ? (struct elf_m68k_link_hash_table *) (p)->hash : NULL) |
916 | | |
917 | | /* Shortcut to multi-GOT data. */ |
918 | 0 | #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_) |
919 | | |
920 | | /* Create an entry in an m68k ELF linker hash table. */ |
921 | | |
922 | | static struct bfd_hash_entry * |
923 | | elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry, |
924 | | struct bfd_hash_table *table, |
925 | | const char *string) |
926 | 0 | { |
927 | 0 | struct bfd_hash_entry *ret = entry; |
928 | | |
929 | | /* Allocate the structure if it has not already been allocated by a |
930 | | subclass. */ |
931 | 0 | if (ret == NULL) |
932 | 0 | ret = bfd_hash_allocate (table, |
933 | 0 | sizeof (struct elf_m68k_link_hash_entry)); |
934 | 0 | if (ret == NULL) |
935 | 0 | return ret; |
936 | | |
937 | | /* Call the allocation method of the superclass. */ |
938 | 0 | ret = _bfd_elf_link_hash_newfunc (ret, table, string); |
939 | 0 | if (ret != NULL) |
940 | 0 | { |
941 | 0 | elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL; |
942 | 0 | elf_m68k_hash_entry (ret)->got_entry_key = 0; |
943 | 0 | elf_m68k_hash_entry (ret)->glist = NULL; |
944 | 0 | } |
945 | |
|
946 | 0 | return ret; |
947 | 0 | } |
948 | | |
949 | | /* Destroy an m68k ELF linker hash table. */ |
950 | | |
951 | | static void |
952 | | elf_m68k_link_hash_table_free (bfd *obfd) |
953 | 0 | { |
954 | 0 | struct elf_m68k_link_hash_table *htab; |
955 | |
|
956 | 0 | htab = (struct elf_m68k_link_hash_table *) obfd->link.hash; |
957 | |
|
958 | 0 | if (htab->multi_got_.bfd2got != NULL) |
959 | 0 | { |
960 | 0 | htab_delete (htab->multi_got_.bfd2got); |
961 | 0 | htab->multi_got_.bfd2got = NULL; |
962 | 0 | } |
963 | 0 | _bfd_elf_link_hash_table_free (obfd); |
964 | 0 | } |
965 | | |
966 | | /* Create an m68k ELF linker hash table. */ |
967 | | |
968 | | static struct bfd_link_hash_table * |
969 | | elf_m68k_link_hash_table_create (bfd *abfd) |
970 | 0 | { |
971 | 0 | struct elf_m68k_link_hash_table *ret; |
972 | 0 | size_t amt = sizeof (struct elf_m68k_link_hash_table); |
973 | |
|
974 | 0 | ret = (struct elf_m68k_link_hash_table *) bfd_zmalloc (amt); |
975 | 0 | if (ret == (struct elf_m68k_link_hash_table *) NULL) |
976 | 0 | return NULL; |
977 | | |
978 | 0 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, |
979 | 0 | elf_m68k_link_hash_newfunc, |
980 | 0 | sizeof (struct elf_m68k_link_hash_entry))) |
981 | 0 | { |
982 | 0 | free (ret); |
983 | 0 | return NULL; |
984 | 0 | } |
985 | 0 | ret->root.root.hash_table_free = elf_m68k_link_hash_table_free; |
986 | |
|
987 | 0 | ret->multi_got_.global_symndx = 1; |
988 | |
|
989 | 0 | return &ret->root.root; |
990 | 0 | } |
991 | | |
992 | | /* Set the right machine number. */ |
993 | | |
994 | | static bool |
995 | | elf32_m68k_object_p (bfd *abfd) |
996 | 19.6k | { |
997 | 19.6k | unsigned int mach = 0; |
998 | 19.6k | unsigned features = 0; |
999 | 19.6k | flagword eflags = elf_elfheader (abfd)->e_flags; |
1000 | | |
1001 | 19.6k | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
1002 | 1.67k | features |= m68000; |
1003 | 17.9k | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
1004 | 1.69k | features |= cpu32; |
1005 | 16.2k | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
1006 | 1.67k | features |= fido_a; |
1007 | 14.5k | else |
1008 | 14.5k | { |
1009 | 14.5k | switch (eflags & EF_M68K_CF_ISA_MASK) |
1010 | 14.5k | { |
1011 | 746 | case EF_M68K_CF_ISA_A_NODIV: |
1012 | 746 | features |= mcfisa_a; |
1013 | 746 | break; |
1014 | 946 | case EF_M68K_CF_ISA_A: |
1015 | 946 | features |= mcfisa_a|mcfhwdiv; |
1016 | 946 | break; |
1017 | 1.88k | case EF_M68K_CF_ISA_A_PLUS: |
1018 | 1.88k | features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp; |
1019 | 1.88k | break; |
1020 | 1.42k | case EF_M68K_CF_ISA_B_NOUSP: |
1021 | 1.42k | features |= mcfisa_a|mcfisa_b|mcfhwdiv; |
1022 | 1.42k | break; |
1023 | 1.39k | case EF_M68K_CF_ISA_B: |
1024 | 1.39k | features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp; |
1025 | 1.39k | break; |
1026 | 1.19k | case EF_M68K_CF_ISA_C: |
1027 | 1.19k | features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp; |
1028 | 1.19k | break; |
1029 | 475 | case EF_M68K_CF_ISA_C_NODIV: |
1030 | 475 | features |= mcfisa_a|mcfisa_c|mcfusp; |
1031 | 475 | break; |
1032 | 14.5k | } |
1033 | 14.5k | switch (eflags & EF_M68K_CF_MAC_MASK) |
1034 | 14.5k | { |
1035 | 4.02k | case EF_M68K_CF_MAC: |
1036 | 4.02k | features |= mcfmac; |
1037 | 4.02k | break; |
1038 | 4.70k | case EF_M68K_CF_EMAC: |
1039 | 4.70k | features |= mcfemac; |
1040 | 4.70k | break; |
1041 | 14.5k | } |
1042 | 14.5k | if (eflags & EF_M68K_CF_FLOAT) |
1043 | 6.41k | features |= cfloat; |
1044 | 14.5k | } |
1045 | | |
1046 | 19.6k | mach = bfd_m68k_features_to_mach (features); |
1047 | 19.6k | bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach); |
1048 | | |
1049 | 19.6k | return true; |
1050 | 19.6k | } |
1051 | | |
1052 | | /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag |
1053 | | field based on the machine number. */ |
1054 | | |
1055 | | static bool |
1056 | | elf_m68k_final_write_processing (bfd *abfd) |
1057 | 0 | { |
1058 | 0 | int mach = bfd_get_mach (abfd); |
1059 | 0 | unsigned long e_flags = elf_elfheader (abfd)->e_flags; |
1060 | |
|
1061 | 0 | if (!e_flags) |
1062 | 0 | { |
1063 | 0 | unsigned int arch_mask; |
1064 | |
|
1065 | 0 | arch_mask = bfd_m68k_mach_to_features (mach); |
1066 | |
|
1067 | 0 | if (arch_mask & m68000) |
1068 | 0 | e_flags = EF_M68K_M68000; |
1069 | 0 | else if (arch_mask & cpu32) |
1070 | 0 | e_flags = EF_M68K_CPU32; |
1071 | 0 | else if (arch_mask & fido_a) |
1072 | 0 | e_flags = EF_M68K_FIDO; |
1073 | 0 | else |
1074 | 0 | { |
1075 | 0 | switch (arch_mask |
1076 | 0 | & (mcfisa_a | mcfisa_aa | mcfisa_b | mcfisa_c | mcfhwdiv | mcfusp)) |
1077 | 0 | { |
1078 | 0 | case mcfisa_a: |
1079 | 0 | e_flags |= EF_M68K_CF_ISA_A_NODIV; |
1080 | 0 | break; |
1081 | 0 | case mcfisa_a | mcfhwdiv: |
1082 | 0 | e_flags |= EF_M68K_CF_ISA_A; |
1083 | 0 | break; |
1084 | 0 | case mcfisa_a | mcfisa_aa | mcfhwdiv | mcfusp: |
1085 | 0 | e_flags |= EF_M68K_CF_ISA_A_PLUS; |
1086 | 0 | break; |
1087 | 0 | case mcfisa_a | mcfisa_b | mcfhwdiv: |
1088 | 0 | e_flags |= EF_M68K_CF_ISA_B_NOUSP; |
1089 | 0 | break; |
1090 | 0 | case mcfisa_a | mcfisa_b | mcfhwdiv | mcfusp: |
1091 | 0 | e_flags |= EF_M68K_CF_ISA_B; |
1092 | 0 | break; |
1093 | 0 | case mcfisa_a | mcfisa_c | mcfhwdiv | mcfusp: |
1094 | 0 | e_flags |= EF_M68K_CF_ISA_C; |
1095 | 0 | break; |
1096 | 0 | case mcfisa_a | mcfisa_c | mcfusp: |
1097 | 0 | e_flags |= EF_M68K_CF_ISA_C_NODIV; |
1098 | 0 | break; |
1099 | 0 | } |
1100 | 0 | if (arch_mask & mcfmac) |
1101 | 0 | e_flags |= EF_M68K_CF_MAC; |
1102 | 0 | else if (arch_mask & mcfemac) |
1103 | 0 | e_flags |= EF_M68K_CF_EMAC; |
1104 | 0 | if (arch_mask & cfloat) |
1105 | 0 | e_flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E; |
1106 | 0 | } |
1107 | 0 | elf_elfheader (abfd)->e_flags = e_flags; |
1108 | 0 | } |
1109 | 0 | return _bfd_elf_final_write_processing (abfd); |
1110 | 0 | } |
1111 | | |
1112 | | /* Keep m68k-specific flags in the ELF header. */ |
1113 | | |
1114 | | static bool |
1115 | | elf32_m68k_set_private_flags (bfd *abfd, flagword flags) |
1116 | 0 | { |
1117 | 0 | elf_elfheader (abfd)->e_flags = flags; |
1118 | 0 | elf_flags_init (abfd) = true; |
1119 | 0 | return true; |
1120 | 0 | } |
1121 | | |
1122 | | /* Merge object attributes from IBFD into OBFD. Warn if |
1123 | | there are conflicting attributes. */ |
1124 | | static bool |
1125 | | m68k_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info) |
1126 | 0 | { |
1127 | 0 | bfd *obfd = info->output_bfd; |
1128 | 0 | obj_attribute *in_attr, *in_attrs; |
1129 | 0 | obj_attribute *out_attr, *out_attrs; |
1130 | 0 | bool ret = true; |
1131 | |
|
1132 | 0 | in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU]; |
1133 | 0 | out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU]; |
1134 | |
|
1135 | 0 | in_attr = &in_attrs[Tag_GNU_M68K_ABI_FP]; |
1136 | 0 | out_attr = &out_attrs[Tag_GNU_M68K_ABI_FP]; |
1137 | |
|
1138 | 0 | if (in_attr->i != out_attr->i) |
1139 | 0 | { |
1140 | 0 | int in_fp = in_attr->i & 3; |
1141 | 0 | int out_fp = out_attr->i & 3; |
1142 | 0 | static bfd *last_fp; |
1143 | |
|
1144 | 0 | if (in_fp == 0) |
1145 | 0 | ; |
1146 | 0 | else if (out_fp == 0) |
1147 | 0 | { |
1148 | 0 | out_attr->type = ATTR_TYPE_FLAG_INT_VAL; |
1149 | 0 | out_attr->i ^= in_fp; |
1150 | 0 | last_fp = ibfd; |
1151 | 0 | } |
1152 | 0 | else if (out_fp == 1 && in_fp == 2) |
1153 | 0 | { |
1154 | 0 | _bfd_error_handler |
1155 | | /* xgettext:c-format */ |
1156 | 0 | (_("%pB uses hard float, %pB uses soft float"), |
1157 | 0 | last_fp, ibfd); |
1158 | 0 | ret = false; |
1159 | 0 | } |
1160 | 0 | else if (out_fp == 2 && in_fp == 1) |
1161 | 0 | { |
1162 | 0 | _bfd_error_handler |
1163 | | /* xgettext:c-format */ |
1164 | 0 | (_("%pB uses hard float, %pB uses soft float"), |
1165 | 0 | ibfd, last_fp); |
1166 | 0 | ret = false; |
1167 | 0 | } |
1168 | 0 | } |
1169 | |
|
1170 | 0 | if (!ret) |
1171 | 0 | { |
1172 | 0 | out_attr->type = ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_ERROR; |
1173 | 0 | bfd_set_error (bfd_error_bad_value); |
1174 | 0 | return false; |
1175 | 0 | } |
1176 | | |
1177 | | /* Merge Tag_compatibility attributes and any common GNU ones. */ |
1178 | 0 | return _bfd_elf_merge_object_attributes (ibfd, info); |
1179 | 0 | } |
1180 | | |
1181 | | /* Merge backend specific data from an object file to the output |
1182 | | object file when linking. */ |
1183 | | static bool |
1184 | | elf32_m68k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
1185 | 0 | { |
1186 | 0 | bfd *obfd = info->output_bfd; |
1187 | 0 | flagword out_flags; |
1188 | 0 | flagword in_flags; |
1189 | 0 | flagword out_isa; |
1190 | 0 | flagword in_isa; |
1191 | 0 | const bfd_arch_info_type *arch_info; |
1192 | |
|
1193 | 0 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
1194 | 0 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
1195 | | /* PR 24523: For non-ELF files do not try to merge any private |
1196 | | data, but also do not prevent the link from succeeding. */ |
1197 | 0 | return true; |
1198 | | |
1199 | | /* Get the merged machine. This checks for incompatibility between |
1200 | | Coldfire & non-Coldfire flags, incompability between different |
1201 | | Coldfire ISAs, and incompability between different MAC types. */ |
1202 | 0 | arch_info = bfd_arch_get_compatible (ibfd, obfd, false); |
1203 | 0 | if (!arch_info) |
1204 | 0 | return false; |
1205 | | |
1206 | 0 | bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach); |
1207 | |
|
1208 | 0 | if (!m68k_elf_merge_obj_attributes (ibfd, info)) |
1209 | 0 | return false; |
1210 | | |
1211 | 0 | in_flags = elf_elfheader (ibfd)->e_flags; |
1212 | 0 | if (!elf_flags_init (obfd)) |
1213 | 0 | { |
1214 | 0 | elf_flags_init (obfd) = true; |
1215 | 0 | out_flags = in_flags; |
1216 | 0 | } |
1217 | 0 | else |
1218 | 0 | { |
1219 | 0 | out_flags = elf_elfheader (obfd)->e_flags; |
1220 | 0 | unsigned int variant_mask; |
1221 | |
|
1222 | 0 | if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
1223 | 0 | variant_mask = 0; |
1224 | 0 | else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
1225 | 0 | variant_mask = 0; |
1226 | 0 | else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
1227 | 0 | variant_mask = 0; |
1228 | 0 | else |
1229 | 0 | variant_mask = EF_M68K_CF_ISA_MASK; |
1230 | |
|
1231 | 0 | in_isa = (in_flags & variant_mask); |
1232 | 0 | out_isa = (out_flags & variant_mask); |
1233 | 0 | if (in_isa > out_isa) |
1234 | 0 | out_flags ^= in_isa ^ out_isa; |
1235 | 0 | if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32 |
1236 | 0 | && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
1237 | 0 | || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO |
1238 | 0 | && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)) |
1239 | 0 | out_flags = EF_M68K_FIDO; |
1240 | 0 | else |
1241 | 0 | out_flags |= in_flags ^ in_isa; |
1242 | 0 | } |
1243 | 0 | elf_elfheader (obfd)->e_flags = out_flags; |
1244 | |
|
1245 | 0 | return true; |
1246 | 0 | } |
1247 | | |
1248 | | /* Display the flags field. */ |
1249 | | |
1250 | | static bool |
1251 | | elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr) |
1252 | 85 | { |
1253 | 85 | FILE *file = (FILE *) ptr; |
1254 | 85 | flagword eflags = elf_elfheader (abfd)->e_flags; |
1255 | | |
1256 | 85 | BFD_ASSERT (abfd != NULL && ptr != NULL); |
1257 | | |
1258 | | /* Print normal ELF private data. */ |
1259 | 85 | _bfd_elf_print_private_bfd_data (abfd, ptr); |
1260 | | |
1261 | | /* Ignore init flag - it may not be set, despite the flags field containing valid data. */ |
1262 | | |
1263 | | /* xgettext:c-format */ |
1264 | 85 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
1265 | | |
1266 | 85 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
1267 | 2 | fprintf (file, " [m68000]"); |
1268 | 83 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
1269 | 2 | fprintf (file, " [cpu32]"); |
1270 | 81 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
1271 | 2 | fprintf (file, " [fido]"); |
1272 | 79 | else |
1273 | 79 | { |
1274 | 79 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E) |
1275 | 10 | fprintf (file, " [cfv4e]"); |
1276 | | |
1277 | 79 | if (eflags & EF_M68K_CF_ISA_MASK) |
1278 | 35 | { |
1279 | 35 | char const *isa = _("unknown"); |
1280 | 35 | char const *mac = _("unknown"); |
1281 | 35 | char const *additional = ""; |
1282 | | |
1283 | 35 | switch (eflags & EF_M68K_CF_ISA_MASK) |
1284 | 35 | { |
1285 | 1 | case EF_M68K_CF_ISA_A_NODIV: |
1286 | 1 | isa = "A"; |
1287 | 1 | additional = " [nodiv]"; |
1288 | 1 | break; |
1289 | 4 | case EF_M68K_CF_ISA_A: |
1290 | 4 | isa = "A"; |
1291 | 4 | break; |
1292 | 2 | case EF_M68K_CF_ISA_A_PLUS: |
1293 | 2 | isa = "A+"; |
1294 | 2 | break; |
1295 | 4 | case EF_M68K_CF_ISA_B_NOUSP: |
1296 | 4 | isa = "B"; |
1297 | 4 | additional = " [nousp]"; |
1298 | 4 | break; |
1299 | 1 | case EF_M68K_CF_ISA_B: |
1300 | 1 | isa = "B"; |
1301 | 1 | break; |
1302 | 0 | case EF_M68K_CF_ISA_C: |
1303 | 0 | isa = "C"; |
1304 | 0 | break; |
1305 | 1 | case EF_M68K_CF_ISA_C_NODIV: |
1306 | 1 | isa = "C"; |
1307 | 1 | additional = " [nodiv]"; |
1308 | 1 | break; |
1309 | 35 | } |
1310 | 35 | fprintf (file, " [isa %s]%s", isa, additional); |
1311 | | |
1312 | 35 | if (eflags & EF_M68K_CF_FLOAT) |
1313 | 27 | fprintf (file, " [float]"); |
1314 | | |
1315 | 35 | switch (eflags & EF_M68K_CF_MAC_MASK) |
1316 | 35 | { |
1317 | 5 | case 0: |
1318 | 5 | mac = NULL; |
1319 | 5 | break; |
1320 | 3 | case EF_M68K_CF_MAC: |
1321 | 3 | mac = "mac"; |
1322 | 3 | break; |
1323 | 16 | case EF_M68K_CF_EMAC: |
1324 | 16 | mac = "emac"; |
1325 | 16 | break; |
1326 | 11 | case EF_M68K_CF_EMAC_B: |
1327 | 11 | mac = "emac_b"; |
1328 | 11 | break; |
1329 | 35 | } |
1330 | 35 | if (mac) |
1331 | 30 | fprintf (file, " [%s]", mac); |
1332 | 35 | } |
1333 | 79 | } |
1334 | | |
1335 | 85 | fputc ('\n', file); |
1336 | | |
1337 | 85 | return true; |
1338 | 85 | } |
1339 | | |
1340 | | /* Multi-GOT support implementation design: |
1341 | | |
1342 | | Multi-GOT starts in check_relocs hook. There we scan all |
1343 | | relocations of a BFD and build a local GOT (struct elf_m68k_got) |
1344 | | for it. If a single BFD appears to require too many GOT slots with |
1345 | | R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification |
1346 | | to user. |
1347 | | After check_relocs has been invoked for each input BFD, we have |
1348 | | constructed a GOT for each input BFD. |
1349 | | |
1350 | | To minimize total number of GOTs required for a particular output BFD |
1351 | | (as some environments support only 1 GOT per output object) we try |
1352 | | to merge some of the GOTs to share an offset space. Ideally [and in most |
1353 | | cases] we end up with a single GOT. In cases when there are too many |
1354 | | restricted relocations (e.g., R_68K_GOT16O relocations) we end up with |
1355 | | several GOTs, assuming the environment can handle them. |
1356 | | |
1357 | | Partitioning is done in elf_m68k_partition_multi_got. We start with |
1358 | | an empty GOT and traverse bfd2got hashtable putting got_entries from |
1359 | | local GOTs to the new 'big' one. We do that by constructing an |
1360 | | intermediate GOT holding all the entries the local GOT has and the big |
1361 | | GOT lacks. Then we check if there is room in the big GOT to accomodate |
1362 | | all the entries from diff. On success we add those entries to the big |
1363 | | GOT; on failure we start the new 'big' GOT and retry the adding of |
1364 | | entries from the local GOT. Note that this retry will always succeed as |
1365 | | each local GOT doesn't overflow the limits. After partitioning we |
1366 | | end up with each bfd assigned one of the big GOTs. GOT entries in the |
1367 | | big GOTs are initialized with GOT offsets. Note that big GOTs are |
1368 | | positioned consequently in program space and represent a single huge GOT |
1369 | | to the outside world. |
1370 | | |
1371 | | After that we get to elf_m68k_relocate_section. There we |
1372 | | adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol |
1373 | | relocations to refer to appropriate [assigned to current input_bfd] |
1374 | | big GOT. |
1375 | | |
1376 | | Notes: |
1377 | | |
1378 | | GOT entry type: We have several types of GOT entries. |
1379 | | * R_8 type is used in entries for symbols that have at least one |
1380 | | R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40 |
1381 | | such entries in one GOT. |
1382 | | * R_16 type is used in entries for symbols that have at least one |
1383 | | R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations. |
1384 | | We can have at most 0x4000 such entries in one GOT. |
1385 | | * R_32 type is used in all other cases. We can have as many |
1386 | | such entries in one GOT as we'd like. |
1387 | | When counting relocations we have to include the count of the smaller |
1388 | | ranged relocations in the counts of the larger ranged ones in order |
1389 | | to correctly detect overflow. |
1390 | | |
1391 | | Sorting the GOT: In each GOT starting offsets are assigned to |
1392 | | R_8 entries, which are followed by R_16 entries, and |
1393 | | R_32 entries go at the end. See finalize_got_offsets for details. |
1394 | | |
1395 | | Negative GOT offsets: To double usable offset range of GOTs we use |
1396 | | negative offsets. As we assign entries with GOT offsets relative to |
1397 | | start of .got section, the offset values are positive. They become |
1398 | | negative only in relocate_section where got->offset value is |
1399 | | subtracted from them. |
1400 | | |
1401 | | 3 special GOT entries: There are 3 special GOT entries used internally |
1402 | | by loader. These entries happen to be placed to .got.plt section, |
1403 | | so we don't do anything about them in multi-GOT support. |
1404 | | |
1405 | | Memory management: All data except for hashtables |
1406 | | multi_got->bfd2got and got->entries are allocated on |
1407 | | elf_hash_table (info)->dynobj bfd (for this reason we pass 'info' |
1408 | | to most functions), so we don't need to care to free them. At the |
1409 | | moment of allocation hashtables are being linked into main data |
1410 | | structure (multi_got), all pieces of which are reachable from |
1411 | | elf_m68k_multi_got (info). We deallocate them in |
1412 | | elf_m68k_link_hash_table_free. */ |
1413 | | |
1414 | | /* Initialize GOT. */ |
1415 | | |
1416 | | static void |
1417 | | elf_m68k_init_got (struct elf_m68k_got *got) |
1418 | 0 | { |
1419 | 0 | got->entries = NULL; |
1420 | 0 | got->n_slots[R_8] = 0; |
1421 | 0 | got->n_slots[R_16] = 0; |
1422 | 0 | got->n_slots[R_32] = 0; |
1423 | 0 | got->local_n_slots = 0; |
1424 | 0 | got->offset = (bfd_vma) -1; |
1425 | 0 | } |
1426 | | |
1427 | | /* Destruct GOT. */ |
1428 | | |
1429 | | static void |
1430 | | elf_m68k_clear_got (struct elf_m68k_got *got) |
1431 | 0 | { |
1432 | 0 | if (got->entries != NULL) |
1433 | 0 | { |
1434 | 0 | htab_delete (got->entries); |
1435 | 0 | got->entries = NULL; |
1436 | 0 | } |
1437 | 0 | } |
1438 | | |
1439 | | /* Create and empty GOT structure. INFO is the context where memory |
1440 | | should be allocated. */ |
1441 | | |
1442 | | static struct elf_m68k_got * |
1443 | | elf_m68k_create_empty_got (struct bfd_link_info *info) |
1444 | 0 | { |
1445 | 0 | struct elf_m68k_got *got; |
1446 | |
|
1447 | 0 | got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got)); |
1448 | 0 | if (got == NULL) |
1449 | 0 | return NULL; |
1450 | | |
1451 | 0 | elf_m68k_init_got (got); |
1452 | |
|
1453 | 0 | return got; |
1454 | 0 | } |
1455 | | |
1456 | | /* Initialize KEY. */ |
1457 | | |
1458 | | static void |
1459 | | elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key, |
1460 | | struct elf_link_hash_entry *h, |
1461 | | const bfd *abfd, unsigned long symndx, |
1462 | | enum elf_m68k_reloc_type reloc_type) |
1463 | 0 | { |
1464 | 0 | if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32) |
1465 | | /* All TLS_LDM relocations share a single GOT entry. */ |
1466 | 0 | { |
1467 | 0 | key->bfd = NULL; |
1468 | 0 | key->symndx = 0; |
1469 | 0 | } |
1470 | 0 | else if (h != NULL) |
1471 | | /* Global symbols are identified with their got_entry_key. */ |
1472 | 0 | { |
1473 | 0 | key->bfd = NULL; |
1474 | 0 | key->symndx = elf_m68k_hash_entry (h)->got_entry_key; |
1475 | 0 | BFD_ASSERT (key->symndx != 0); |
1476 | 0 | } |
1477 | 0 | else |
1478 | | /* Local symbols are identified by BFD they appear in and symndx. */ |
1479 | 0 | { |
1480 | 0 | key->bfd = abfd; |
1481 | 0 | key->symndx = symndx; |
1482 | 0 | } |
1483 | |
|
1484 | 0 | key->type = reloc_type; |
1485 | 0 | } |
1486 | | |
1487 | | /* Calculate hash of got_entry. |
1488 | | ??? Is it good? */ |
1489 | | |
1490 | | static hashval_t |
1491 | | elf_m68k_got_entry_hash (const void *_entry) |
1492 | 0 | { |
1493 | 0 | const struct elf_m68k_got_entry_key *key; |
1494 | |
|
1495 | 0 | key = &((const struct elf_m68k_got_entry *) _entry)->key_; |
1496 | |
|
1497 | 0 | return (key->symndx |
1498 | 0 | + (key->bfd != NULL ? (int) key->bfd->id : -1) |
1499 | 0 | + elf_m68k_reloc_got_type (key->type)); |
1500 | 0 | } |
1501 | | |
1502 | | /* Check if two got entries are equal. */ |
1503 | | |
1504 | | static int |
1505 | | elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2) |
1506 | 0 | { |
1507 | 0 | const struct elf_m68k_got_entry_key *key1; |
1508 | 0 | const struct elf_m68k_got_entry_key *key2; |
1509 | |
|
1510 | 0 | key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_; |
1511 | 0 | key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_; |
1512 | |
|
1513 | 0 | return (key1->bfd == key2->bfd |
1514 | 0 | && key1->symndx == key2->symndx |
1515 | 0 | && (elf_m68k_reloc_got_type (key1->type) |
1516 | 0 | == elf_m68k_reloc_got_type (key2->type))); |
1517 | 0 | } |
1518 | | |
1519 | | /* When using negative offsets, we allocate one extra R_8, one extra R_16 |
1520 | | and one extra R_32 slots to simplify handling of 2-slot entries during |
1521 | | offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */ |
1522 | | |
1523 | | /* Maximal number of R_8 slots in a single GOT. */ |
1524 | | #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \ |
1525 | 0 | (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \ |
1526 | 0 | ? (0x40 - 1) \ |
1527 | 0 | : 0x20) |
1528 | | |
1529 | | /* Maximal number of R_8 and R_16 slots in a single GOT. */ |
1530 | | #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \ |
1531 | 0 | (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \ |
1532 | 0 | ? (0x4000 - 2) \ |
1533 | 0 | : 0x2000) |
1534 | | |
1535 | | /* SEARCH - simply search the hashtable, don't insert new entries or fail when |
1536 | | the entry cannot be found. |
1537 | | FIND_OR_CREATE - search for an existing entry, but create new if there's |
1538 | | no such. |
1539 | | MUST_FIND - search for an existing entry and assert that it exist. |
1540 | | MUST_CREATE - assert that there's no such entry and create new one. */ |
1541 | | enum elf_m68k_get_entry_howto |
1542 | | { |
1543 | | SEARCH, |
1544 | | FIND_OR_CREATE, |
1545 | | MUST_FIND, |
1546 | | MUST_CREATE |
1547 | | }; |
1548 | | |
1549 | | /* Get or create (depending on HOWTO) entry with KEY in GOT. |
1550 | | INFO is context in which memory should be allocated (can be NULL if |
1551 | | HOWTO is SEARCH or MUST_FIND). */ |
1552 | | |
1553 | | static struct elf_m68k_got_entry * |
1554 | | elf_m68k_get_got_entry (struct elf_m68k_got *got, |
1555 | | const struct elf_m68k_got_entry_key *key, |
1556 | | enum elf_m68k_get_entry_howto howto, |
1557 | | struct bfd_link_info *info) |
1558 | 0 | { |
1559 | 0 | struct elf_m68k_got_entry entry_; |
1560 | 0 | struct elf_m68k_got_entry *entry; |
1561 | 0 | void **ptr; |
1562 | |
|
1563 | 0 | BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND)); |
1564 | |
|
1565 | 0 | if (got->entries == NULL) |
1566 | | /* This is the first entry in ABFD. Initialize hashtable. */ |
1567 | 0 | { |
1568 | 0 | if (howto == SEARCH) |
1569 | 0 | return NULL; |
1570 | | |
1571 | 0 | got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT |
1572 | 0 | (info), |
1573 | 0 | elf_m68k_got_entry_hash, |
1574 | 0 | elf_m68k_got_entry_eq, NULL); |
1575 | 0 | if (got->entries == NULL) |
1576 | 0 | { |
1577 | 0 | bfd_set_error (bfd_error_no_memory); |
1578 | 0 | return NULL; |
1579 | 0 | } |
1580 | 0 | } |
1581 | | |
1582 | 0 | entry_.key_ = *key; |
1583 | 0 | ptr = htab_find_slot (got->entries, &entry_, |
1584 | 0 | (howto == SEARCH || howto == MUST_FIND ? NO_INSERT |
1585 | 0 | : INSERT)); |
1586 | 0 | if (ptr == NULL) |
1587 | 0 | { |
1588 | 0 | if (howto == SEARCH) |
1589 | | /* Entry not found. */ |
1590 | 0 | return NULL; |
1591 | | |
1592 | 0 | if (howto == MUST_FIND) |
1593 | 0 | abort (); |
1594 | | |
1595 | | /* We're out of memory. */ |
1596 | 0 | bfd_set_error (bfd_error_no_memory); |
1597 | 0 | return NULL; |
1598 | 0 | } |
1599 | | |
1600 | 0 | if (*ptr == NULL) |
1601 | | /* We didn't find the entry and we're asked to create a new one. */ |
1602 | 0 | { |
1603 | 0 | if (howto == MUST_FIND) |
1604 | 0 | abort (); |
1605 | | |
1606 | 0 | BFD_ASSERT (howto != SEARCH); |
1607 | |
|
1608 | 0 | entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)); |
1609 | 0 | if (entry == NULL) |
1610 | 0 | return NULL; |
1611 | | |
1612 | | /* Initialize new entry. */ |
1613 | 0 | entry->key_ = *key; |
1614 | |
|
1615 | 0 | entry->u.s1.refcount = 0; |
1616 | | |
1617 | | /* Mark the entry as not initialized. */ |
1618 | 0 | entry->key_.type = R_68K_max; |
1619 | |
|
1620 | 0 | *ptr = entry; |
1621 | 0 | } |
1622 | 0 | else |
1623 | | /* We found the entry. */ |
1624 | 0 | { |
1625 | 0 | BFD_ASSERT (howto != MUST_CREATE); |
1626 | |
|
1627 | 0 | entry = *ptr; |
1628 | 0 | } |
1629 | | |
1630 | 0 | return entry; |
1631 | 0 | } |
1632 | | |
1633 | | /* Update GOT counters when merging entry of WAS type with entry of NEW type. |
1634 | | Return the value to which ENTRY's type should be set. */ |
1635 | | |
1636 | | static enum elf_m68k_reloc_type |
1637 | | elf_m68k_update_got_entry_type (struct elf_m68k_got *got, |
1638 | | enum elf_m68k_reloc_type was, |
1639 | | enum elf_m68k_reloc_type new_reloc) |
1640 | 0 | { |
1641 | 0 | enum elf_m68k_got_offset_size was_size; |
1642 | 0 | enum elf_m68k_got_offset_size new_size; |
1643 | 0 | bfd_vma n_slots; |
1644 | |
|
1645 | 0 | if (was == R_68K_max) |
1646 | | /* The type of the entry is not initialized yet. */ |
1647 | 0 | { |
1648 | | /* Update all got->n_slots counters, including n_slots[R_32]. */ |
1649 | 0 | was_size = R_LAST; |
1650 | |
|
1651 | 0 | was = new_reloc; |
1652 | 0 | } |
1653 | 0 | else |
1654 | 0 | { |
1655 | | /* !!! We, probably, should emit an error rather then fail on assert |
1656 | | in such a case. */ |
1657 | 0 | BFD_ASSERT (elf_m68k_reloc_got_type (was) |
1658 | 0 | == elf_m68k_reloc_got_type (new_reloc)); |
1659 | |
|
1660 | 0 | was_size = elf_m68k_reloc_got_offset_size (was); |
1661 | 0 | } |
1662 | |
|
1663 | 0 | new_size = elf_m68k_reloc_got_offset_size (new_reloc); |
1664 | 0 | n_slots = elf_m68k_reloc_got_n_slots (new_reloc); |
1665 | |
|
1666 | 0 | while (was_size > new_size) |
1667 | 0 | { |
1668 | 0 | --was_size; |
1669 | 0 | got->n_slots[was_size] += n_slots; |
1670 | 0 | } |
1671 | |
|
1672 | 0 | if (new_reloc > was) |
1673 | | /* Relocations are ordered from bigger got offset size to lesser, |
1674 | | so choose the relocation type with lesser offset size. */ |
1675 | 0 | was = new_reloc; |
1676 | |
|
1677 | 0 | return was; |
1678 | 0 | } |
1679 | | |
1680 | | /* Add new or update existing entry to GOT. |
1681 | | H, ABFD, TYPE and SYMNDX is data for the entry. |
1682 | | INFO is a context where memory should be allocated. */ |
1683 | | |
1684 | | static struct elf_m68k_got_entry * |
1685 | | elf_m68k_add_entry_to_got (struct elf_m68k_got *got, |
1686 | | struct elf_link_hash_entry *h, |
1687 | | const bfd *abfd, |
1688 | | enum elf_m68k_reloc_type reloc_type, |
1689 | | unsigned long symndx, |
1690 | | struct bfd_link_info *info) |
1691 | 0 | { |
1692 | 0 | struct elf_m68k_got_entry_key key_; |
1693 | 0 | struct elf_m68k_got_entry *entry; |
1694 | |
|
1695 | 0 | if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0) |
1696 | 0 | elf_m68k_hash_entry (h)->got_entry_key |
1697 | 0 | = elf_m68k_multi_got (info)->global_symndx++; |
1698 | |
|
1699 | 0 | elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type); |
1700 | |
|
1701 | 0 | entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info); |
1702 | 0 | if (entry == NULL) |
1703 | 0 | return NULL; |
1704 | | |
1705 | | /* Determine entry's type and update got->n_slots counters. */ |
1706 | 0 | entry->key_.type = elf_m68k_update_got_entry_type (got, |
1707 | 0 | entry->key_.type, |
1708 | 0 | reloc_type); |
1709 | | |
1710 | | /* Update refcount. */ |
1711 | 0 | ++entry->u.s1.refcount; |
1712 | |
|
1713 | 0 | if (entry->u.s1.refcount == 1) |
1714 | | /* We see this entry for the first time. */ |
1715 | 0 | { |
1716 | 0 | if (entry->key_.bfd != NULL) |
1717 | 0 | got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type); |
1718 | 0 | } |
1719 | |
|
1720 | 0 | BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots); |
1721 | |
|
1722 | 0 | if ((got->n_slots[R_8] |
1723 | 0 | > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) |
1724 | 0 | || (got->n_slots[R_16] |
1725 | 0 | > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))) |
1726 | | /* This BFD has too many relocation. */ |
1727 | 0 | { |
1728 | 0 | if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) |
1729 | | /* xgettext:c-format */ |
1730 | 0 | _bfd_error_handler (_("%pB: GOT overflow: " |
1731 | 0 | "number of relocations with 8-bit " |
1732 | 0 | "offset > %d"), |
1733 | 0 | abfd, |
1734 | 0 | ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)); |
1735 | 0 | else |
1736 | | /* xgettext:c-format */ |
1737 | 0 | _bfd_error_handler (_("%pB: GOT overflow: " |
1738 | 0 | "number of relocations with 8- or 16-bit " |
1739 | 0 | "offset > %d"), |
1740 | 0 | abfd, |
1741 | 0 | ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)); |
1742 | |
|
1743 | 0 | return NULL; |
1744 | 0 | } |
1745 | | |
1746 | 0 | return entry; |
1747 | 0 | } |
1748 | | |
1749 | | /* Compute the hash value of the bfd in a bfd2got hash entry. */ |
1750 | | |
1751 | | static hashval_t |
1752 | | elf_m68k_bfd2got_entry_hash (const void *entry) |
1753 | 0 | { |
1754 | 0 | const struct elf_m68k_bfd2got_entry *e; |
1755 | |
|
1756 | 0 | e = (const struct elf_m68k_bfd2got_entry *) entry; |
1757 | |
|
1758 | 0 | return e->bfd->id; |
1759 | 0 | } |
1760 | | |
1761 | | /* Check whether two hash entries have the same bfd. */ |
1762 | | |
1763 | | static int |
1764 | | elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2) |
1765 | 0 | { |
1766 | 0 | const struct elf_m68k_bfd2got_entry *e1; |
1767 | 0 | const struct elf_m68k_bfd2got_entry *e2; |
1768 | |
|
1769 | 0 | e1 = (const struct elf_m68k_bfd2got_entry *) entry1; |
1770 | 0 | e2 = (const struct elf_m68k_bfd2got_entry *) entry2; |
1771 | |
|
1772 | 0 | return e1->bfd == e2->bfd; |
1773 | 0 | } |
1774 | | |
1775 | | /* Destruct a bfd2got entry. */ |
1776 | | |
1777 | | static void |
1778 | | elf_m68k_bfd2got_entry_del (void *_entry) |
1779 | 0 | { |
1780 | 0 | struct elf_m68k_bfd2got_entry *entry; |
1781 | |
|
1782 | 0 | entry = (struct elf_m68k_bfd2got_entry *) _entry; |
1783 | |
|
1784 | 0 | BFD_ASSERT (entry->got != NULL); |
1785 | 0 | elf_m68k_clear_got (entry->got); |
1786 | 0 | } |
1787 | | |
1788 | | /* Find existing or create new (depending on HOWTO) bfd2got entry in |
1789 | | MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where |
1790 | | memory should be allocated. */ |
1791 | | |
1792 | | static struct elf_m68k_bfd2got_entry * |
1793 | | elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got, |
1794 | | const bfd *abfd, |
1795 | | enum elf_m68k_get_entry_howto howto, |
1796 | | struct bfd_link_info *info) |
1797 | 0 | { |
1798 | 0 | struct elf_m68k_bfd2got_entry entry_; |
1799 | 0 | void **ptr; |
1800 | 0 | struct elf_m68k_bfd2got_entry *entry; |
1801 | |
|
1802 | 0 | BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND)); |
1803 | |
|
1804 | 0 | if (multi_got->bfd2got == NULL) |
1805 | | /* This is the first GOT. Initialize bfd2got. */ |
1806 | 0 | { |
1807 | 0 | if (howto == SEARCH) |
1808 | 0 | return NULL; |
1809 | | |
1810 | 0 | multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash, |
1811 | 0 | elf_m68k_bfd2got_entry_eq, |
1812 | 0 | elf_m68k_bfd2got_entry_del); |
1813 | 0 | if (multi_got->bfd2got == NULL) |
1814 | 0 | { |
1815 | 0 | bfd_set_error (bfd_error_no_memory); |
1816 | 0 | return NULL; |
1817 | 0 | } |
1818 | 0 | } |
1819 | | |
1820 | 0 | entry_.bfd = abfd; |
1821 | 0 | ptr = htab_find_slot (multi_got->bfd2got, &entry_, |
1822 | 0 | (howto == SEARCH || howto == MUST_FIND ? NO_INSERT |
1823 | 0 | : INSERT)); |
1824 | 0 | if (ptr == NULL) |
1825 | 0 | { |
1826 | 0 | if (howto == SEARCH) |
1827 | | /* Entry not found. */ |
1828 | 0 | return NULL; |
1829 | | |
1830 | 0 | if (howto == MUST_FIND) |
1831 | 0 | abort (); |
1832 | | |
1833 | | /* We're out of memory. */ |
1834 | 0 | bfd_set_error (bfd_error_no_memory); |
1835 | 0 | return NULL; |
1836 | 0 | } |
1837 | | |
1838 | 0 | if (*ptr == NULL) |
1839 | | /* Entry was not found. Create new one. */ |
1840 | 0 | { |
1841 | 0 | if (howto == MUST_FIND) |
1842 | 0 | abort (); |
1843 | | |
1844 | 0 | BFD_ASSERT (howto != SEARCH); |
1845 | |
|
1846 | 0 | entry = ((struct elf_m68k_bfd2got_entry *) |
1847 | 0 | bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry))); |
1848 | 0 | if (entry == NULL) |
1849 | 0 | return NULL; |
1850 | | |
1851 | 0 | entry->bfd = abfd; |
1852 | |
|
1853 | 0 | entry->got = elf_m68k_create_empty_got (info); |
1854 | 0 | if (entry->got == NULL) |
1855 | 0 | return NULL; |
1856 | | |
1857 | 0 | *ptr = entry; |
1858 | 0 | } |
1859 | 0 | else |
1860 | 0 | { |
1861 | 0 | BFD_ASSERT (howto != MUST_CREATE); |
1862 | | |
1863 | | /* Return existing entry. */ |
1864 | 0 | entry = *ptr; |
1865 | 0 | } |
1866 | | |
1867 | 0 | return entry; |
1868 | 0 | } |
1869 | | |
1870 | | struct elf_m68k_can_merge_gots_arg |
1871 | | { |
1872 | | /* A current_got that we constructing a DIFF against. */ |
1873 | | struct elf_m68k_got *big; |
1874 | | |
1875 | | /* GOT holding entries not present or that should be changed in |
1876 | | BIG. */ |
1877 | | struct elf_m68k_got *diff; |
1878 | | |
1879 | | /* Context where to allocate memory. */ |
1880 | | struct bfd_link_info *info; |
1881 | | |
1882 | | /* Error flag. */ |
1883 | | bool error_p; |
1884 | | }; |
1885 | | |
1886 | | /* Process a single entry from the small GOT to see if it should be added |
1887 | | or updated in the big GOT. */ |
1888 | | |
1889 | | static int |
1890 | | elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg) |
1891 | 0 | { |
1892 | 0 | const struct elf_m68k_got_entry *entry1; |
1893 | 0 | struct elf_m68k_can_merge_gots_arg *arg; |
1894 | 0 | const struct elf_m68k_got_entry *entry2; |
1895 | 0 | enum elf_m68k_reloc_type type; |
1896 | |
|
1897 | 0 | entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr; |
1898 | 0 | arg = (struct elf_m68k_can_merge_gots_arg *) _arg; |
1899 | |
|
1900 | 0 | entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL); |
1901 | |
|
1902 | 0 | if (entry2 != NULL) |
1903 | | /* We found an existing entry. Check if we should update it. */ |
1904 | 0 | { |
1905 | 0 | type = elf_m68k_update_got_entry_type (arg->diff, |
1906 | 0 | entry2->key_.type, |
1907 | 0 | entry1->key_.type); |
1908 | |
|
1909 | 0 | if (type == entry2->key_.type) |
1910 | | /* ENTRY1 doesn't update data in ENTRY2. Skip it. |
1911 | | To skip creation of difference entry we use the type, |
1912 | | which we won't see in GOT entries for sure. */ |
1913 | 0 | type = R_68K_max; |
1914 | 0 | } |
1915 | 0 | else |
1916 | | /* We didn't find the entry. Add entry1 to DIFF. */ |
1917 | 0 | { |
1918 | 0 | BFD_ASSERT (entry1->key_.type != R_68K_max); |
1919 | |
|
1920 | 0 | type = elf_m68k_update_got_entry_type (arg->diff, |
1921 | 0 | R_68K_max, entry1->key_.type); |
1922 | |
|
1923 | 0 | if (entry1->key_.bfd != NULL) |
1924 | 0 | arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type); |
1925 | 0 | } |
1926 | |
|
1927 | 0 | if (type != R_68K_max) |
1928 | | /* Create an entry in DIFF. */ |
1929 | 0 | { |
1930 | 0 | struct elf_m68k_got_entry *entry; |
1931 | |
|
1932 | 0 | entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE, |
1933 | 0 | arg->info); |
1934 | 0 | if (entry == NULL) |
1935 | 0 | { |
1936 | 0 | arg->error_p = true; |
1937 | 0 | return 0; |
1938 | 0 | } |
1939 | | |
1940 | 0 | entry->key_.type = type; |
1941 | 0 | } |
1942 | | |
1943 | 0 | return 1; |
1944 | 0 | } |
1945 | | |
1946 | | /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it. |
1947 | | Construct DIFF GOT holding the entries which should be added or updated |
1948 | | in BIG GOT to accumulate information from SMALL. |
1949 | | INFO is the context where memory should be allocated. */ |
1950 | | |
1951 | | static bool |
1952 | | elf_m68k_can_merge_gots (struct elf_m68k_got *big, |
1953 | | const struct elf_m68k_got *small, |
1954 | | struct bfd_link_info *info, |
1955 | | struct elf_m68k_got *diff) |
1956 | 0 | { |
1957 | 0 | struct elf_m68k_can_merge_gots_arg arg_; |
1958 | |
|
1959 | 0 | BFD_ASSERT (small->offset == (bfd_vma) -1); |
1960 | |
|
1961 | 0 | arg_.big = big; |
1962 | 0 | arg_.diff = diff; |
1963 | 0 | arg_.info = info; |
1964 | 0 | arg_.error_p = false; |
1965 | 0 | htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_); |
1966 | 0 | if (arg_.error_p) |
1967 | 0 | { |
1968 | 0 | diff->offset = 0; |
1969 | 0 | return false; |
1970 | 0 | } |
1971 | | |
1972 | | /* Check for overflow. */ |
1973 | 0 | if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8] |
1974 | 0 | > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) |
1975 | 0 | || (big->n_slots[R_16] + arg_.diff->n_slots[R_16] |
1976 | 0 | > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))) |
1977 | 0 | return false; |
1978 | | |
1979 | 0 | return true; |
1980 | 0 | } |
1981 | | |
1982 | | struct elf_m68k_merge_gots_arg |
1983 | | { |
1984 | | /* The BIG got. */ |
1985 | | struct elf_m68k_got *big; |
1986 | | |
1987 | | /* Context where memory should be allocated. */ |
1988 | | struct bfd_link_info *info; |
1989 | | |
1990 | | /* Error flag. */ |
1991 | | bool error_p; |
1992 | | }; |
1993 | | |
1994 | | /* Process a single entry from DIFF got. Add or update corresponding |
1995 | | entry in the BIG got. */ |
1996 | | |
1997 | | static int |
1998 | | elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg) |
1999 | 0 | { |
2000 | 0 | const struct elf_m68k_got_entry *from; |
2001 | 0 | struct elf_m68k_merge_gots_arg *arg; |
2002 | 0 | struct elf_m68k_got_entry *to; |
2003 | |
|
2004 | 0 | from = (const struct elf_m68k_got_entry *) *entry_ptr; |
2005 | 0 | arg = (struct elf_m68k_merge_gots_arg *) _arg; |
2006 | |
|
2007 | 0 | to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE, |
2008 | 0 | arg->info); |
2009 | 0 | if (to == NULL) |
2010 | 0 | { |
2011 | 0 | arg->error_p = true; |
2012 | 0 | return 0; |
2013 | 0 | } |
2014 | | |
2015 | 0 | BFD_ASSERT (to->u.s1.refcount == 0); |
2016 | | /* All we need to merge is TYPE. */ |
2017 | 0 | to->key_.type = from->key_.type; |
2018 | |
|
2019 | 0 | return 1; |
2020 | 0 | } |
2021 | | |
2022 | | /* Merge data from DIFF to BIG. INFO is context where memory should be |
2023 | | allocated. */ |
2024 | | |
2025 | | static bool |
2026 | | elf_m68k_merge_gots (struct elf_m68k_got *big, |
2027 | | struct elf_m68k_got *diff, |
2028 | | struct bfd_link_info *info) |
2029 | 0 | { |
2030 | 0 | if (diff->entries != NULL) |
2031 | | /* DIFF is not empty. Merge it into BIG GOT. */ |
2032 | 0 | { |
2033 | 0 | struct elf_m68k_merge_gots_arg arg_; |
2034 | | |
2035 | | /* Merge entries. */ |
2036 | 0 | arg_.big = big; |
2037 | 0 | arg_.info = info; |
2038 | 0 | arg_.error_p = false; |
2039 | 0 | htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_); |
2040 | 0 | if (arg_.error_p) |
2041 | 0 | return false; |
2042 | | |
2043 | | /* Merge counters. */ |
2044 | 0 | big->n_slots[R_8] += diff->n_slots[R_8]; |
2045 | 0 | big->n_slots[R_16] += diff->n_slots[R_16]; |
2046 | 0 | big->n_slots[R_32] += diff->n_slots[R_32]; |
2047 | 0 | big->local_n_slots += diff->local_n_slots; |
2048 | 0 | } |
2049 | 0 | else |
2050 | | /* DIFF is empty. */ |
2051 | 0 | { |
2052 | 0 | BFD_ASSERT (diff->n_slots[R_8] == 0); |
2053 | 0 | BFD_ASSERT (diff->n_slots[R_16] == 0); |
2054 | 0 | BFD_ASSERT (diff->n_slots[R_32] == 0); |
2055 | 0 | BFD_ASSERT (diff->local_n_slots == 0); |
2056 | 0 | } |
2057 | | |
2058 | 0 | BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p |
2059 | 0 | || ((big->n_slots[R_8] |
2060 | 0 | <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) |
2061 | 0 | && (big->n_slots[R_16] |
2062 | 0 | <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))); |
2063 | |
|
2064 | 0 | return true; |
2065 | 0 | } |
2066 | | |
2067 | | struct elf_m68k_finalize_got_offsets_arg |
2068 | | { |
2069 | | /* Ranges of the offsets for GOT entries. |
2070 | | R_x entries receive offsets between offset1[R_x] and offset2[R_x]. |
2071 | | R_x is R_8, R_16 and R_32. */ |
2072 | | bfd_vma *offset1; |
2073 | | bfd_vma *offset2; |
2074 | | |
2075 | | /* Mapping from global symndx to global symbols. |
2076 | | This is used to build lists of got entries for global symbols. */ |
2077 | | struct elf_m68k_link_hash_entry **symndx2h; |
2078 | | |
2079 | | bfd_vma n_ldm_entries; |
2080 | | }; |
2081 | | |
2082 | | /* Assign ENTRY an offset. Build list of GOT entries for global symbols |
2083 | | along the way. */ |
2084 | | |
2085 | | static int |
2086 | | elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg) |
2087 | 0 | { |
2088 | 0 | struct elf_m68k_got_entry *entry; |
2089 | 0 | struct elf_m68k_finalize_got_offsets_arg *arg; |
2090 | |
|
2091 | 0 | enum elf_m68k_got_offset_size got_offset_size; |
2092 | 0 | bfd_vma entry_size; |
2093 | |
|
2094 | 0 | entry = (struct elf_m68k_got_entry *) *entry_ptr; |
2095 | 0 | arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg; |
2096 | | |
2097 | | /* This should be a fresh entry created in elf_m68k_can_merge_gots. */ |
2098 | 0 | BFD_ASSERT (entry->u.s1.refcount == 0); |
2099 | | |
2100 | | /* Get GOT offset size for the entry . */ |
2101 | 0 | got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type); |
2102 | | |
2103 | | /* Calculate entry size in bytes. */ |
2104 | 0 | entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type); |
2105 | | |
2106 | | /* Check if we should switch to negative range of the offsets. */ |
2107 | 0 | if (arg->offset1[got_offset_size] + entry_size |
2108 | 0 | > arg->offset2[got_offset_size]) |
2109 | 0 | { |
2110 | | /* Verify that this is the only switch to negative range for |
2111 | | got_offset_size. If this assertion fails, then we've miscalculated |
2112 | | range for got_offset_size entries in |
2113 | | elf_m68k_finalize_got_offsets. */ |
2114 | 0 | BFD_ASSERT (arg->offset2[got_offset_size] |
2115 | 0 | != arg->offset2[-(int) got_offset_size - 1]); |
2116 | | |
2117 | | /* Switch. */ |
2118 | 0 | arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1]; |
2119 | 0 | arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1]; |
2120 | | |
2121 | | /* Verify that now we have enough room for the entry. */ |
2122 | 0 | BFD_ASSERT (arg->offset1[got_offset_size] + entry_size |
2123 | 0 | <= arg->offset2[got_offset_size]); |
2124 | 0 | } |
2125 | | |
2126 | | /* Assign offset to entry. */ |
2127 | 0 | entry->u.s2.offset = arg->offset1[got_offset_size]; |
2128 | 0 | arg->offset1[got_offset_size] += entry_size; |
2129 | |
|
2130 | 0 | if (entry->key_.bfd == NULL) |
2131 | | /* Hook up this entry into the list of got_entries of H. */ |
2132 | 0 | { |
2133 | 0 | struct elf_m68k_link_hash_entry *h; |
2134 | |
|
2135 | 0 | h = arg->symndx2h[entry->key_.symndx]; |
2136 | 0 | if (h != NULL) |
2137 | 0 | { |
2138 | 0 | entry->u.s2.next = h->glist; |
2139 | 0 | h->glist = entry; |
2140 | 0 | } |
2141 | 0 | else |
2142 | | /* This should be the entry for TLS_LDM relocation then. */ |
2143 | 0 | { |
2144 | 0 | BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type) |
2145 | 0 | == R_68K_TLS_LDM32) |
2146 | 0 | && entry->key_.symndx == 0); |
2147 | |
|
2148 | 0 | ++arg->n_ldm_entries; |
2149 | 0 | } |
2150 | 0 | } |
2151 | 0 | else |
2152 | | /* This entry is for local symbol. */ |
2153 | 0 | entry->u.s2.next = NULL; |
2154 | |
|
2155 | 0 | return 1; |
2156 | 0 | } |
2157 | | |
2158 | | /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we |
2159 | | should use negative offsets. |
2160 | | Build list of GOT entries for global symbols along the way. |
2161 | | SYMNDX2H is mapping from global symbol indices to actual |
2162 | | global symbols. |
2163 | | Return offset at which next GOT should start. */ |
2164 | | |
2165 | | static void |
2166 | | elf_m68k_finalize_got_offsets (struct elf_m68k_got *got, |
2167 | | bool use_neg_got_offsets_p, |
2168 | | struct elf_m68k_link_hash_entry **symndx2h, |
2169 | | bfd_vma *final_offset, bfd_vma *n_ldm_entries) |
2170 | 0 | { |
2171 | 0 | struct elf_m68k_finalize_got_offsets_arg arg_; |
2172 | 0 | bfd_vma offset1_[2 * R_LAST]; |
2173 | 0 | bfd_vma offset2_[2 * R_LAST]; |
2174 | 0 | int i; |
2175 | 0 | bfd_vma start_offset; |
2176 | |
|
2177 | 0 | BFD_ASSERT (got->offset != (bfd_vma) -1); |
2178 | | |
2179 | | /* We set entry offsets relative to the .got section (and not the |
2180 | | start of a particular GOT), so that we can use them in |
2181 | | finish_dynamic_symbol without needing to know the GOT which they come |
2182 | | from. */ |
2183 | | |
2184 | | /* Put offset1 in the middle of offset1_, same for offset2. */ |
2185 | 0 | arg_.offset1 = offset1_ + R_LAST; |
2186 | 0 | arg_.offset2 = offset2_ + R_LAST; |
2187 | |
|
2188 | 0 | start_offset = got->offset; |
2189 | |
|
2190 | 0 | if (use_neg_got_offsets_p) |
2191 | | /* Setup both negative and positive ranges for R_8, R_16 and R_32. */ |
2192 | 0 | i = -(int) R_32 - 1; |
2193 | 0 | else |
2194 | | /* Setup positives ranges for R_8, R_16 and R_32. */ |
2195 | 0 | i = (int) R_8; |
2196 | |
|
2197 | 0 | for (; i <= (int) R_32; ++i) |
2198 | 0 | { |
2199 | 0 | int j; |
2200 | 0 | size_t n; |
2201 | | |
2202 | | /* Set beginning of the range of offsets I. */ |
2203 | 0 | arg_.offset1[i] = start_offset; |
2204 | | |
2205 | | /* Calculate number of slots that require I offsets. */ |
2206 | 0 | j = (i >= 0) ? i : -i - 1; |
2207 | 0 | n = (j >= 1) ? got->n_slots[j - 1] : 0; |
2208 | 0 | n = got->n_slots[j] - n; |
2209 | |
|
2210 | 0 | if (use_neg_got_offsets_p && n != 0) |
2211 | 0 | { |
2212 | 0 | if (i < 0) |
2213 | | /* We first fill the positive side of the range, so we might |
2214 | | end up with one empty slot at that side when we can't fit |
2215 | | whole 2-slot entry. Account for that at negative side of |
2216 | | the interval with one additional entry. */ |
2217 | 0 | n = n / 2 + 1; |
2218 | 0 | else |
2219 | | /* When the number of slots is odd, make positive side of the |
2220 | | range one entry bigger. */ |
2221 | 0 | n = (n + 1) / 2; |
2222 | 0 | } |
2223 | | |
2224 | | /* N is the number of slots that require I offsets. |
2225 | | Calculate length of the range for I offsets. */ |
2226 | 0 | n = 4 * n; |
2227 | | |
2228 | | /* Set end of the range. */ |
2229 | 0 | arg_.offset2[i] = start_offset + n; |
2230 | |
|
2231 | 0 | start_offset = arg_.offset2[i]; |
2232 | 0 | } |
2233 | |
|
2234 | 0 | if (!use_neg_got_offsets_p) |
2235 | | /* Make sure that if we try to switch to negative offsets in |
2236 | | elf_m68k_finalize_got_offsets_1, the assert therein will catch |
2237 | | the bug. */ |
2238 | 0 | for (i = R_8; i <= R_32; ++i) |
2239 | 0 | arg_.offset2[-i - 1] = arg_.offset2[i]; |
2240 | | |
2241 | | /* Setup got->offset. offset1[R_8] is either in the middle or at the |
2242 | | beginning of GOT depending on use_neg_got_offsets_p. */ |
2243 | 0 | got->offset = arg_.offset1[R_8]; |
2244 | |
|
2245 | 0 | arg_.symndx2h = symndx2h; |
2246 | 0 | arg_.n_ldm_entries = 0; |
2247 | | |
2248 | | /* Assign offsets. */ |
2249 | 0 | htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_); |
2250 | | |
2251 | | /* Check offset ranges we have actually assigned. */ |
2252 | 0 | for (i = (int) R_8; i <= (int) R_32; ++i) |
2253 | 0 | BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4); |
2254 | |
|
2255 | 0 | *final_offset = start_offset; |
2256 | 0 | *n_ldm_entries = arg_.n_ldm_entries; |
2257 | 0 | } |
2258 | | |
2259 | | struct elf_m68k_partition_multi_got_arg |
2260 | | { |
2261 | | /* The GOT we are adding entries to. Aka big got. */ |
2262 | | struct elf_m68k_got *current_got; |
2263 | | |
2264 | | /* Offset to assign the next CURRENT_GOT. */ |
2265 | | bfd_vma offset; |
2266 | | |
2267 | | /* Context where memory should be allocated. */ |
2268 | | struct bfd_link_info *info; |
2269 | | |
2270 | | /* Total number of slots in the .got section. |
2271 | | This is used to calculate size of the .got and .rela.got sections. */ |
2272 | | bfd_vma n_slots; |
2273 | | |
2274 | | /* Difference in numbers of allocated slots in the .got section |
2275 | | and necessary relocations in the .rela.got section. |
2276 | | This is used to calculate size of the .rela.got section. */ |
2277 | | bfd_vma slots_relas_diff; |
2278 | | |
2279 | | /* Error flag. */ |
2280 | | bool error_p; |
2281 | | |
2282 | | /* Mapping from global symndx to global symbols. |
2283 | | This is used to build lists of got entries for global symbols. */ |
2284 | | struct elf_m68k_link_hash_entry **symndx2h; |
2285 | | }; |
2286 | | |
2287 | | static void |
2288 | | elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg) |
2289 | 0 | { |
2290 | 0 | bfd_vma n_ldm_entries; |
2291 | |
|
2292 | 0 | elf_m68k_finalize_got_offsets (arg->current_got, |
2293 | 0 | (elf_m68k_hash_table (arg->info) |
2294 | 0 | ->use_neg_got_offsets_p), |
2295 | 0 | arg->symndx2h, |
2296 | 0 | &arg->offset, &n_ldm_entries); |
2297 | |
|
2298 | 0 | arg->n_slots += arg->current_got->n_slots[R_32]; |
2299 | |
|
2300 | 0 | if (!bfd_link_pic (arg->info)) |
2301 | | /* If we are generating a shared object, we need to |
2302 | | output a R_68K_RELATIVE reloc so that the dynamic |
2303 | | linker can adjust this GOT entry. Overwise we |
2304 | | don't need space in .rela.got for local symbols. */ |
2305 | 0 | arg->slots_relas_diff += arg->current_got->local_n_slots; |
2306 | | |
2307 | | /* @LDM relocations require a 2-slot GOT entry, but only |
2308 | | one relocation. Account for that. */ |
2309 | 0 | arg->slots_relas_diff += n_ldm_entries; |
2310 | |
|
2311 | 0 | BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots); |
2312 | 0 | } |
2313 | | |
2314 | | |
2315 | | /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT |
2316 | | or start a new CURRENT_GOT. */ |
2317 | | |
2318 | | static int |
2319 | | elf_m68k_partition_multi_got_1 (void **_entry, void *_arg) |
2320 | 0 | { |
2321 | 0 | struct elf_m68k_bfd2got_entry *entry; |
2322 | 0 | struct elf_m68k_partition_multi_got_arg *arg; |
2323 | 0 | struct elf_m68k_got *got; |
2324 | 0 | struct elf_m68k_got diff_; |
2325 | 0 | struct elf_m68k_got *diff; |
2326 | |
|
2327 | 0 | entry = (struct elf_m68k_bfd2got_entry *) *_entry; |
2328 | 0 | arg = (struct elf_m68k_partition_multi_got_arg *) _arg; |
2329 | |
|
2330 | 0 | got = entry->got; |
2331 | 0 | BFD_ASSERT (got != NULL); |
2332 | 0 | BFD_ASSERT (got->offset == (bfd_vma) -1); |
2333 | |
|
2334 | 0 | diff = NULL; |
2335 | |
|
2336 | 0 | if (arg->current_got != NULL) |
2337 | | /* Construct diff. */ |
2338 | 0 | { |
2339 | 0 | diff = &diff_; |
2340 | 0 | elf_m68k_init_got (diff); |
2341 | |
|
2342 | 0 | if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff)) |
2343 | 0 | { |
2344 | 0 | if (diff->offset == 0) |
2345 | | /* Offset set to 0 in the diff_ indicates an error. */ |
2346 | 0 | { |
2347 | 0 | arg->error_p = true; |
2348 | 0 | goto final_return; |
2349 | 0 | } |
2350 | | |
2351 | 0 | if (elf_m68k_hash_table (arg->info)->allow_multigot_p) |
2352 | 0 | { |
2353 | 0 | elf_m68k_clear_got (diff); |
2354 | | /* Schedule to finish up current_got and start new one. */ |
2355 | 0 | diff = NULL; |
2356 | 0 | } |
2357 | | /* else |
2358 | | Merge GOTs no matter what. If big GOT overflows, |
2359 | | we'll fail in relocate_section due to truncated relocations. |
2360 | | |
2361 | | ??? May be fail earlier? E.g., in can_merge_gots. */ |
2362 | 0 | } |
2363 | 0 | } |
2364 | 0 | else |
2365 | | /* Diff of got against empty current_got is got itself. */ |
2366 | 0 | { |
2367 | | /* Create empty current_got to put subsequent GOTs to. */ |
2368 | 0 | arg->current_got = elf_m68k_create_empty_got (arg->info); |
2369 | 0 | if (arg->current_got == NULL) |
2370 | 0 | { |
2371 | 0 | arg->error_p = true; |
2372 | 0 | goto final_return; |
2373 | 0 | } |
2374 | | |
2375 | 0 | arg->current_got->offset = arg->offset; |
2376 | |
|
2377 | 0 | diff = got; |
2378 | 0 | } |
2379 | | |
2380 | 0 | if (diff != NULL) |
2381 | 0 | { |
2382 | 0 | if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info)) |
2383 | 0 | { |
2384 | 0 | arg->error_p = true; |
2385 | 0 | goto final_return; |
2386 | 0 | } |
2387 | | |
2388 | | /* Now we can free GOT. */ |
2389 | 0 | elf_m68k_clear_got (got); |
2390 | |
|
2391 | 0 | entry->got = arg->current_got; |
2392 | 0 | } |
2393 | 0 | else |
2394 | 0 | { |
2395 | | /* Finish up current_got. */ |
2396 | 0 | elf_m68k_partition_multi_got_2 (arg); |
2397 | | |
2398 | | /* Schedule to start a new current_got. */ |
2399 | 0 | arg->current_got = NULL; |
2400 | | |
2401 | | /* Retry. */ |
2402 | 0 | if (!elf_m68k_partition_multi_got_1 (_entry, _arg)) |
2403 | 0 | { |
2404 | 0 | BFD_ASSERT (arg->error_p); |
2405 | 0 | goto final_return; |
2406 | 0 | } |
2407 | 0 | } |
2408 | | |
2409 | 0 | final_return: |
2410 | 0 | if (diff != NULL) |
2411 | 0 | elf_m68k_clear_got (diff); |
2412 | |
|
2413 | 0 | return !arg->error_p; |
2414 | 0 | } |
2415 | | |
2416 | | /* Helper function to build symndx2h mapping. */ |
2417 | | |
2418 | | static bool |
2419 | | elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h, |
2420 | | void *_arg) |
2421 | 0 | { |
2422 | 0 | struct elf_m68k_link_hash_entry *h; |
2423 | |
|
2424 | 0 | h = elf_m68k_hash_entry (_h); |
2425 | |
|
2426 | 0 | if (h->got_entry_key != 0) |
2427 | | /* H has at least one entry in the GOT. */ |
2428 | 0 | { |
2429 | 0 | struct elf_m68k_partition_multi_got_arg *arg; |
2430 | |
|
2431 | 0 | arg = (struct elf_m68k_partition_multi_got_arg *) _arg; |
2432 | |
|
2433 | 0 | BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL); |
2434 | 0 | arg->symndx2h[h->got_entry_key] = h; |
2435 | 0 | } |
2436 | |
|
2437 | 0 | return true; |
2438 | 0 | } |
2439 | | |
2440 | | /* Merge GOTs of some BFDs, assign offsets to GOT entries and build |
2441 | | lists of GOT entries for global symbols. |
2442 | | Calculate sizes of .got and .rela.got sections. */ |
2443 | | |
2444 | | static bool |
2445 | | elf_m68k_partition_multi_got (struct bfd_link_info *info) |
2446 | 0 | { |
2447 | 0 | struct elf_m68k_multi_got *multi_got; |
2448 | 0 | struct elf_m68k_partition_multi_got_arg arg_; |
2449 | |
|
2450 | 0 | multi_got = elf_m68k_multi_got (info); |
2451 | |
|
2452 | 0 | arg_.current_got = NULL; |
2453 | 0 | arg_.offset = 0; |
2454 | 0 | arg_.info = info; |
2455 | 0 | arg_.n_slots = 0; |
2456 | 0 | arg_.slots_relas_diff = 0; |
2457 | 0 | arg_.error_p = false; |
2458 | |
|
2459 | 0 | if (multi_got->bfd2got != NULL) |
2460 | 0 | { |
2461 | | /* Initialize symndx2h mapping. */ |
2462 | 0 | { |
2463 | 0 | arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx |
2464 | 0 | * sizeof (*arg_.symndx2h)); |
2465 | 0 | if (arg_.symndx2h == NULL) |
2466 | 0 | return false; |
2467 | | |
2468 | 0 | elf_link_hash_traverse (elf_hash_table (info), |
2469 | 0 | elf_m68k_init_symndx2h_1, &arg_); |
2470 | 0 | } |
2471 | | |
2472 | | /* Partition. */ |
2473 | 0 | htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1, |
2474 | 0 | &arg_); |
2475 | 0 | if (arg_.error_p) |
2476 | 0 | { |
2477 | 0 | free (arg_.symndx2h); |
2478 | 0 | arg_.symndx2h = NULL; |
2479 | |
|
2480 | 0 | return false; |
2481 | 0 | } |
2482 | | |
2483 | | /* Finish up last current_got. */ |
2484 | 0 | elf_m68k_partition_multi_got_2 (&arg_); |
2485 | |
|
2486 | 0 | free (arg_.symndx2h); |
2487 | 0 | } |
2488 | | |
2489 | 0 | if (elf_hash_table (info)->dynobj != NULL) |
2490 | | /* Set sizes of .got and .rela.got sections. */ |
2491 | 0 | { |
2492 | 0 | asection *s; |
2493 | |
|
2494 | 0 | s = elf_hash_table (info)->sgot; |
2495 | 0 | if (s != NULL) |
2496 | 0 | s->size = arg_.offset; |
2497 | 0 | else |
2498 | 0 | BFD_ASSERT (arg_.offset == 0); |
2499 | |
|
2500 | 0 | BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots); |
2501 | 0 | arg_.n_slots -= arg_.slots_relas_diff; |
2502 | |
|
2503 | 0 | s = elf_hash_table (info)->srelgot; |
2504 | 0 | if (s != NULL) |
2505 | 0 | s->size = arg_.n_slots * sizeof (Elf32_External_Rela); |
2506 | 0 | else |
2507 | 0 | BFD_ASSERT (arg_.n_slots == 0); |
2508 | 0 | } |
2509 | 0 | else |
2510 | 0 | BFD_ASSERT (multi_got->bfd2got == NULL); |
2511 | |
|
2512 | 0 | return true; |
2513 | 0 | } |
2514 | | |
2515 | | /* Copy any information related to dynamic linking from a pre-existing |
2516 | | symbol to a newly created symbol. Also called to copy flags and |
2517 | | other back-end info to a weakdef, in which case the symbol is not |
2518 | | newly created and plt/got refcounts and dynamic indices should not |
2519 | | be copied. */ |
2520 | | |
2521 | | static void |
2522 | | elf_m68k_copy_indirect_symbol (struct bfd_link_info *info, |
2523 | | struct elf_link_hash_entry *_dir, |
2524 | | struct elf_link_hash_entry *_ind) |
2525 | 0 | { |
2526 | 0 | struct elf_m68k_link_hash_entry *dir; |
2527 | 0 | struct elf_m68k_link_hash_entry *ind; |
2528 | |
|
2529 | 0 | _bfd_elf_link_hash_copy_indirect (info, _dir, _ind); |
2530 | |
|
2531 | 0 | if (_ind->root.type != bfd_link_hash_indirect) |
2532 | 0 | return; |
2533 | | |
2534 | 0 | dir = elf_m68k_hash_entry (_dir); |
2535 | 0 | ind = elf_m68k_hash_entry (_ind); |
2536 | | |
2537 | | /* Any absolute non-dynamic relocations against an indirect or weak |
2538 | | definition will be against the target symbol. */ |
2539 | 0 | _dir->non_got_ref |= _ind->non_got_ref; |
2540 | | |
2541 | | /* We might have a direct symbol already having entries in the GOTs. |
2542 | | Update its key only in case indirect symbol has GOT entries and |
2543 | | assert that both indirect and direct symbols don't have GOT entries |
2544 | | at the same time. */ |
2545 | 0 | if (ind->got_entry_key != 0) |
2546 | 0 | { |
2547 | 0 | BFD_ASSERT (dir->got_entry_key == 0); |
2548 | | /* Assert that GOTs aren't partioned yet. */ |
2549 | 0 | BFD_ASSERT (ind->glist == NULL); |
2550 | |
|
2551 | 0 | dir->got_entry_key = ind->got_entry_key; |
2552 | 0 | ind->got_entry_key = 0; |
2553 | 0 | } |
2554 | 0 | } |
2555 | | |
2556 | | /* Look through the relocs for a section during the first phase, and |
2557 | | allocate space in the global offset table or procedure linkage |
2558 | | table. */ |
2559 | | |
2560 | | static bool |
2561 | | elf_m68k_check_relocs (bfd *abfd, |
2562 | | struct bfd_link_info *info, |
2563 | | asection *sec, |
2564 | | const Elf_Internal_Rela *relocs) |
2565 | 0 | { |
2566 | 0 | bfd *dynobj; |
2567 | 0 | Elf_Internal_Shdr *symtab_hdr; |
2568 | 0 | struct elf_link_hash_entry **sym_hashes; |
2569 | 0 | const Elf_Internal_Rela *rel; |
2570 | 0 | const Elf_Internal_Rela *rel_end; |
2571 | 0 | asection *sreloc; |
2572 | 0 | struct elf_m68k_got *got; |
2573 | |
|
2574 | 0 | if (bfd_link_relocatable (info)) |
2575 | 0 | return true; |
2576 | | |
2577 | 0 | dynobj = elf_hash_table (info)->dynobj; |
2578 | 0 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
2579 | 0 | sym_hashes = elf_sym_hashes (abfd); |
2580 | |
|
2581 | 0 | sreloc = NULL; |
2582 | |
|
2583 | 0 | got = NULL; |
2584 | |
|
2585 | 0 | rel_end = relocs + sec->reloc_count; |
2586 | 0 | for (rel = relocs; rel < rel_end; rel++) |
2587 | 0 | { |
2588 | 0 | unsigned long r_symndx; |
2589 | 0 | struct elf_link_hash_entry *h; |
2590 | |
|
2591 | 0 | r_symndx = ELF32_R_SYM (rel->r_info); |
2592 | |
|
2593 | 0 | if (r_symndx < symtab_hdr->sh_info) |
2594 | 0 | h = NULL; |
2595 | 0 | else |
2596 | 0 | { |
2597 | 0 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
2598 | 0 | while (h->root.type == bfd_link_hash_indirect |
2599 | 0 | || h->root.type == bfd_link_hash_warning) |
2600 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
2601 | 0 | } |
2602 | |
|
2603 | 0 | switch (ELF32_R_TYPE (rel->r_info)) |
2604 | 0 | { |
2605 | 0 | case R_68K_GOT8: |
2606 | 0 | case R_68K_GOT16: |
2607 | 0 | case R_68K_GOT32: |
2608 | 0 | if (h != NULL |
2609 | 0 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
2610 | 0 | break; |
2611 | | /* Fall through. */ |
2612 | | |
2613 | | /* Relative GOT relocations. */ |
2614 | 0 | case R_68K_GOT8O: |
2615 | 0 | case R_68K_GOT16O: |
2616 | 0 | case R_68K_GOT32O: |
2617 | | /* Fall through. */ |
2618 | | |
2619 | | /* TLS relocations. */ |
2620 | 0 | case R_68K_TLS_GD8: |
2621 | 0 | case R_68K_TLS_GD16: |
2622 | 0 | case R_68K_TLS_GD32: |
2623 | 0 | case R_68K_TLS_LDM8: |
2624 | 0 | case R_68K_TLS_LDM16: |
2625 | 0 | case R_68K_TLS_LDM32: |
2626 | 0 | case R_68K_TLS_IE8: |
2627 | 0 | case R_68K_TLS_IE16: |
2628 | 0 | case R_68K_TLS_IE32: |
2629 | |
|
2630 | 0 | case R_68K_TLS_TPREL32: |
2631 | 0 | case R_68K_TLS_DTPREL32: |
2632 | |
|
2633 | 0 | if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32 |
2634 | 0 | && bfd_link_pic (info)) |
2635 | | /* Do the special chorus for libraries with static TLS. */ |
2636 | 0 | info->flags |= DF_STATIC_TLS; |
2637 | | |
2638 | | /* This symbol requires a global offset table entry. */ |
2639 | |
|
2640 | 0 | if (dynobj == NULL) |
2641 | 0 | { |
2642 | | /* Create the .got section. */ |
2643 | 0 | elf_hash_table (info)->dynobj = dynobj = abfd; |
2644 | 0 | if (!_bfd_elf_create_got_section (dynobj, info)) |
2645 | 0 | return false; |
2646 | 0 | } |
2647 | | |
2648 | 0 | if (got == NULL) |
2649 | 0 | { |
2650 | 0 | struct elf_m68k_bfd2got_entry *bfd2got_entry; |
2651 | |
|
2652 | 0 | bfd2got_entry |
2653 | 0 | = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), |
2654 | 0 | abfd, FIND_OR_CREATE, info); |
2655 | 0 | if (bfd2got_entry == NULL) |
2656 | 0 | return false; |
2657 | | |
2658 | 0 | got = bfd2got_entry->got; |
2659 | 0 | BFD_ASSERT (got != NULL); |
2660 | 0 | } |
2661 | | |
2662 | 0 | { |
2663 | 0 | struct elf_m68k_got_entry *got_entry; |
2664 | | |
2665 | | /* Add entry to got. */ |
2666 | 0 | got_entry = elf_m68k_add_entry_to_got (got, h, abfd, |
2667 | 0 | ELF32_R_TYPE (rel->r_info), |
2668 | 0 | r_symndx, info); |
2669 | 0 | if (got_entry == NULL) |
2670 | 0 | return false; |
2671 | | |
2672 | 0 | if (got_entry->u.s1.refcount == 1) |
2673 | 0 | { |
2674 | | /* Make sure this symbol is output as a dynamic symbol. */ |
2675 | 0 | if (h != NULL |
2676 | 0 | && h->dynindx == -1 |
2677 | 0 | && !h->forced_local) |
2678 | 0 | { |
2679 | 0 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
2680 | 0 | return false; |
2681 | 0 | } |
2682 | 0 | } |
2683 | 0 | } |
2684 | | |
2685 | 0 | break; |
2686 | | |
2687 | 0 | case R_68K_PLT8: |
2688 | 0 | case R_68K_PLT16: |
2689 | 0 | case R_68K_PLT32: |
2690 | | /* This symbol requires a procedure linkage table entry. We |
2691 | | actually build the entry in adjust_dynamic_symbol, |
2692 | | because this might be a case of linking PIC code which is |
2693 | | never referenced by a dynamic object, in which case we |
2694 | | don't need to generate a procedure linkage table entry |
2695 | | after all. */ |
2696 | | |
2697 | | /* If this is a local symbol, we resolve it directly without |
2698 | | creating a procedure linkage table entry. */ |
2699 | 0 | if (h == NULL) |
2700 | 0 | continue; |
2701 | | |
2702 | 0 | h->needs_plt = 1; |
2703 | 0 | h->plt.refcount++; |
2704 | 0 | break; |
2705 | | |
2706 | 0 | case R_68K_PLT8O: |
2707 | 0 | case R_68K_PLT16O: |
2708 | 0 | case R_68K_PLT32O: |
2709 | | /* This symbol requires a procedure linkage table entry. */ |
2710 | |
|
2711 | 0 | if (h == NULL) |
2712 | 0 | { |
2713 | | /* It does not make sense to have this relocation for a |
2714 | | local symbol. FIXME: does it? How to handle it if |
2715 | | it does make sense? */ |
2716 | 0 | bfd_set_error (bfd_error_bad_value); |
2717 | 0 | return false; |
2718 | 0 | } |
2719 | | |
2720 | | /* Make sure this symbol is output as a dynamic symbol. */ |
2721 | 0 | if (h->dynindx == -1 |
2722 | 0 | && !h->forced_local) |
2723 | 0 | { |
2724 | 0 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
2725 | 0 | return false; |
2726 | 0 | } |
2727 | | |
2728 | 0 | h->needs_plt = 1; |
2729 | 0 | h->plt.refcount++; |
2730 | 0 | break; |
2731 | | |
2732 | 0 | case R_68K_PC8: |
2733 | 0 | case R_68K_PC16: |
2734 | 0 | case R_68K_PC32: |
2735 | | /* If we are creating a shared library and this is not a local |
2736 | | symbol, we need to copy the reloc into the shared library. |
2737 | | However when linking with -Bsymbolic and this is a global |
2738 | | symbol which is defined in an object we are including in the |
2739 | | link (i.e., DEF_REGULAR is set), then we can resolve the |
2740 | | reloc directly. At this point we have not seen all the input |
2741 | | files, so it is possible that DEF_REGULAR is not set now but |
2742 | | will be set later (it is never cleared). We account for that |
2743 | | possibility below by storing information in the |
2744 | | pcrel_relocs_copied field of the hash table entry. */ |
2745 | 0 | if (!(bfd_link_pic (info) |
2746 | 0 | && (sec->flags & SEC_ALLOC) != 0 |
2747 | 0 | && h != NULL |
2748 | 0 | && (!SYMBOLIC_BIND (info, h) |
2749 | 0 | || h->root.type == bfd_link_hash_defweak |
2750 | 0 | || !h->def_regular))) |
2751 | 0 | { |
2752 | 0 | if (h != NULL) |
2753 | 0 | { |
2754 | | /* Make sure a plt entry is created for this symbol if |
2755 | | it turns out to be a function defined by a dynamic |
2756 | | object. */ |
2757 | 0 | h->plt.refcount++; |
2758 | 0 | } |
2759 | 0 | break; |
2760 | 0 | } |
2761 | | /* Fall through. */ |
2762 | 0 | case R_68K_8: |
2763 | 0 | case R_68K_16: |
2764 | 0 | case R_68K_32: |
2765 | | /* We don't need to handle relocs into sections not going into |
2766 | | the "real" output. */ |
2767 | 0 | if ((sec->flags & SEC_ALLOC) == 0) |
2768 | 0 | break; |
2769 | | |
2770 | 0 | if (h != NULL) |
2771 | 0 | { |
2772 | | /* Make sure a plt entry is created for this symbol if it |
2773 | | turns out to be a function defined by a dynamic object. */ |
2774 | 0 | h->plt.refcount++; |
2775 | |
|
2776 | 0 | if (bfd_link_executable (info)) |
2777 | | /* This symbol needs a non-GOT reference. */ |
2778 | 0 | h->non_got_ref = 1; |
2779 | 0 | } |
2780 | | |
2781 | | /* If we are creating a shared library, we need to copy the |
2782 | | reloc into the shared library. */ |
2783 | 0 | if (bfd_link_pic (info) |
2784 | 0 | && (h == NULL |
2785 | 0 | || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))) |
2786 | 0 | { |
2787 | | /* When creating a shared object, we must copy these |
2788 | | reloc types into the output file. We create a reloc |
2789 | | section in dynobj and make room for this reloc. */ |
2790 | 0 | if (sreloc == NULL) |
2791 | 0 | { |
2792 | 0 | sreloc = _bfd_elf_make_dynamic_reloc_section |
2793 | 0 | (sec, dynobj, 2, abfd, /*rela?*/ true); |
2794 | |
|
2795 | 0 | if (sreloc == NULL) |
2796 | 0 | return false; |
2797 | 0 | } |
2798 | | |
2799 | 0 | if (sec->flags & SEC_READONLY |
2800 | | /* Don't set DF_TEXTREL yet for PC relative |
2801 | | relocations, they might be discarded later. */ |
2802 | 0 | && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8 |
2803 | 0 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 |
2804 | 0 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)) |
2805 | 0 | info->flags |= DF_TEXTREL; |
2806 | |
|
2807 | 0 | sreloc->size += sizeof (Elf32_External_Rela); |
2808 | | |
2809 | | /* We count the number of PC relative relocations we have |
2810 | | entered for this symbol, so that we can discard them |
2811 | | again if, in the -Bsymbolic case, the symbol is later |
2812 | | defined by a regular object, or, in the normal shared |
2813 | | case, the symbol is forced to be local. Note that this |
2814 | | function is only called if we are using an m68kelf linker |
2815 | | hash table, which means that h is really a pointer to an |
2816 | | elf_m68k_link_hash_entry. */ |
2817 | 0 | if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8 |
2818 | 0 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 |
2819 | 0 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC32) |
2820 | 0 | { |
2821 | 0 | struct elf_m68k_pcrel_relocs_copied *p; |
2822 | 0 | struct elf_m68k_pcrel_relocs_copied **head; |
2823 | |
|
2824 | 0 | if (h != NULL) |
2825 | 0 | { |
2826 | 0 | struct elf_m68k_link_hash_entry *eh |
2827 | 0 | = elf_m68k_hash_entry (h); |
2828 | 0 | head = &eh->pcrel_relocs_copied; |
2829 | 0 | } |
2830 | 0 | else |
2831 | 0 | { |
2832 | 0 | asection *s; |
2833 | 0 | void *vpp; |
2834 | 0 | Elf_Internal_Sym *isym; |
2835 | |
|
2836 | 0 | isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->root.sym_cache, |
2837 | 0 | abfd, r_symndx); |
2838 | 0 | if (isym == NULL) |
2839 | 0 | return false; |
2840 | | |
2841 | 0 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
2842 | 0 | if (s == NULL) |
2843 | 0 | s = sec; |
2844 | |
|
2845 | 0 | vpp = &elf_section_data (s)->local_dynrel; |
2846 | 0 | head = (struct elf_m68k_pcrel_relocs_copied **) vpp; |
2847 | 0 | } |
2848 | | |
2849 | 0 | for (p = *head; p != NULL; p = p->next) |
2850 | 0 | if (p->section == sreloc) |
2851 | 0 | break; |
2852 | |
|
2853 | 0 | if (p == NULL) |
2854 | 0 | { |
2855 | 0 | p = ((struct elf_m68k_pcrel_relocs_copied *) |
2856 | 0 | bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); |
2857 | 0 | if (p == NULL) |
2858 | 0 | return false; |
2859 | 0 | p->next = *head; |
2860 | 0 | *head = p; |
2861 | 0 | p->section = sreloc; |
2862 | 0 | p->count = 0; |
2863 | 0 | } |
2864 | | |
2865 | 0 | ++p->count; |
2866 | 0 | } |
2867 | 0 | } |
2868 | | |
2869 | 0 | break; |
2870 | | |
2871 | | /* This relocation describes the C++ object vtable hierarchy. |
2872 | | Reconstruct it for later use during GC. */ |
2873 | 0 | case R_68K_GNU_VTINHERIT: |
2874 | 0 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
2875 | 0 | return false; |
2876 | 0 | break; |
2877 | | |
2878 | | /* This relocation describes which C++ vtable entries are actually |
2879 | | used. Record for later use during GC. */ |
2880 | 0 | case R_68K_GNU_VTENTRY: |
2881 | 0 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
2882 | 0 | return false; |
2883 | 0 | break; |
2884 | | |
2885 | 0 | default: |
2886 | 0 | break; |
2887 | 0 | } |
2888 | 0 | } |
2889 | | |
2890 | 0 | return true; |
2891 | 0 | } |
2892 | | |
2893 | | /* Return the section that should be marked against GC for a given |
2894 | | relocation. */ |
2895 | | |
2896 | | static asection * |
2897 | | elf_m68k_gc_mark_hook (asection *sec, |
2898 | | struct bfd_link_info *info, |
2899 | | Elf_Internal_Rela *rel, |
2900 | | struct elf_link_hash_entry *h, |
2901 | | Elf_Internal_Sym *sym) |
2902 | 0 | { |
2903 | 0 | if (h != NULL) |
2904 | 0 | switch (ELF32_R_TYPE (rel->r_info)) |
2905 | 0 | { |
2906 | 0 | case R_68K_GNU_VTINHERIT: |
2907 | 0 | case R_68K_GNU_VTENTRY: |
2908 | 0 | return NULL; |
2909 | 0 | } |
2910 | | |
2911 | 0 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); |
2912 | 0 | } |
2913 | | |
2914 | | /* Return the type of PLT associated with OUTPUT_BFD. */ |
2915 | | |
2916 | | static const struct elf_m68k_plt_info * |
2917 | | elf_m68k_get_plt_info (bfd *output_bfd) |
2918 | 0 | { |
2919 | 0 | unsigned int features; |
2920 | |
|
2921 | 0 | features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd)); |
2922 | 0 | if (features & cpu32) |
2923 | 0 | return &elf_cpu32_plt_info; |
2924 | 0 | if (features & mcfisa_b) |
2925 | 0 | return &elf_isab_plt_info; |
2926 | 0 | if (features & mcfisa_c) |
2927 | 0 | return &elf_isac_plt_info; |
2928 | 0 | return &elf_m68k_plt_info; |
2929 | 0 | } |
2930 | | |
2931 | | /* This function is called after all the input files have been read, |
2932 | | and the input sections have been assigned to output sections. |
2933 | | It's a convenient place to determine the PLT style. */ |
2934 | | |
2935 | | static bool |
2936 | | elf_m68k_early_size_sections (bfd *output_bfd, struct bfd_link_info *info) |
2937 | 0 | { |
2938 | | /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got |
2939 | | sections. */ |
2940 | 0 | if (!elf_m68k_partition_multi_got (info)) |
2941 | 0 | return false; |
2942 | | |
2943 | 0 | elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd); |
2944 | 0 | return true; |
2945 | 0 | } |
2946 | | |
2947 | | /* Adjust a symbol defined by a dynamic object and referenced by a |
2948 | | regular object. The current definition is in some section of the |
2949 | | dynamic object, but we're not including those sections. We have to |
2950 | | change the definition to something the rest of the link can |
2951 | | understand. */ |
2952 | | |
2953 | | static bool |
2954 | | elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info, |
2955 | | struct elf_link_hash_entry *h) |
2956 | 0 | { |
2957 | 0 | struct elf_m68k_link_hash_table *htab; |
2958 | 0 | bfd *dynobj; |
2959 | 0 | asection *s; |
2960 | |
|
2961 | 0 | htab = elf_m68k_hash_table (info); |
2962 | 0 | dynobj = htab->root.dynobj; |
2963 | | |
2964 | | /* Make sure we know what is going on here. */ |
2965 | 0 | BFD_ASSERT (dynobj != NULL |
2966 | 0 | && (h->needs_plt |
2967 | 0 | || h->is_weakalias |
2968 | 0 | || (h->def_dynamic |
2969 | 0 | && h->ref_regular |
2970 | 0 | && !h->def_regular))); |
2971 | | |
2972 | | /* If this is a function, put it in the procedure linkage table. We |
2973 | | will fill in the contents of the procedure linkage table later, |
2974 | | when we know the address of the .got section. */ |
2975 | 0 | if (h->type == STT_FUNC |
2976 | 0 | || h->needs_plt) |
2977 | 0 | { |
2978 | 0 | if ((h->plt.refcount <= 0 |
2979 | 0 | || SYMBOL_CALLS_LOCAL (info, h) |
2980 | 0 | || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
2981 | 0 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
2982 | 0 | && h->root.type == bfd_link_hash_undefweak)) |
2983 | | /* We must always create the plt entry if it was referenced |
2984 | | by a PLTxxO relocation. In this case we already recorded |
2985 | | it as a dynamic symbol. */ |
2986 | 0 | && h->dynindx == -1) |
2987 | 0 | { |
2988 | | /* This case can occur if we saw a PLTxx reloc in an input |
2989 | | file, but the symbol was never referred to by a dynamic |
2990 | | object, or if all references were garbage collected. In |
2991 | | such a case, we don't actually need to build a procedure |
2992 | | linkage table, and we can just do a PCxx reloc instead. */ |
2993 | 0 | h->plt.offset = (bfd_vma) -1; |
2994 | 0 | h->needs_plt = 0; |
2995 | 0 | return true; |
2996 | 0 | } |
2997 | | |
2998 | | /* Make sure this symbol is output as a dynamic symbol. */ |
2999 | 0 | if (h->dynindx == -1 |
3000 | 0 | && !h->forced_local) |
3001 | 0 | { |
3002 | 0 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
3003 | 0 | return false; |
3004 | 0 | } |
3005 | | |
3006 | 0 | s = htab->root.splt; |
3007 | 0 | BFD_ASSERT (s != NULL); |
3008 | | |
3009 | | /* If this is the first .plt entry, make room for the special |
3010 | | first entry. */ |
3011 | 0 | if (s->size == 0) |
3012 | 0 | s->size = htab->plt_info->size; |
3013 | | |
3014 | | /* If this symbol is not defined in a regular file, and we are |
3015 | | not generating a shared library, then set the symbol to this |
3016 | | location in the .plt. This is required to make function |
3017 | | pointers compare as equal between the normal executable and |
3018 | | the shared library. */ |
3019 | 0 | if (!bfd_link_pic (info) |
3020 | 0 | && !h->def_regular) |
3021 | 0 | { |
3022 | 0 | h->root.u.def.section = s; |
3023 | 0 | h->root.u.def.value = s->size; |
3024 | 0 | } |
3025 | |
|
3026 | 0 | h->plt.offset = s->size; |
3027 | | |
3028 | | /* Make room for this entry. */ |
3029 | 0 | s->size += htab->plt_info->size; |
3030 | | |
3031 | | /* We also need to make an entry in the .got.plt section, which |
3032 | | will be placed in the .got section by the linker script. */ |
3033 | 0 | s = htab->root.sgotplt; |
3034 | 0 | BFD_ASSERT (s != NULL); |
3035 | 0 | s->size += 4; |
3036 | | |
3037 | | /* We also need to make an entry in the .rela.plt section. */ |
3038 | 0 | s = htab->root.srelplt; |
3039 | 0 | BFD_ASSERT (s != NULL); |
3040 | 0 | s->size += sizeof (Elf32_External_Rela); |
3041 | |
|
3042 | 0 | return true; |
3043 | 0 | } |
3044 | | |
3045 | | /* Reinitialize the plt offset now that it is not used as a reference |
3046 | | count any more. */ |
3047 | 0 | h->plt.offset = (bfd_vma) -1; |
3048 | | |
3049 | | /* If this is a weak symbol, and there is a real definition, the |
3050 | | processor independent code will have arranged for us to see the |
3051 | | real definition first, and we can just use the same value. */ |
3052 | 0 | if (h->is_weakalias) |
3053 | 0 | { |
3054 | 0 | struct elf_link_hash_entry *def = weakdef (h); |
3055 | 0 | BFD_ASSERT (def->root.type == bfd_link_hash_defined); |
3056 | 0 | h->root.u.def.section = def->root.u.def.section; |
3057 | 0 | h->root.u.def.value = def->root.u.def.value; |
3058 | 0 | return true; |
3059 | 0 | } |
3060 | | |
3061 | | /* This is a reference to a symbol defined by a dynamic object which |
3062 | | is not a function. */ |
3063 | | |
3064 | | /* If we are creating a shared library, we must presume that the |
3065 | | only references to the symbol are via the global offset table. |
3066 | | For such cases we need not do anything here; the relocations will |
3067 | | be handled correctly by relocate_section. */ |
3068 | 0 | if (bfd_link_pic (info)) |
3069 | 0 | return true; |
3070 | | |
3071 | | /* If there are no references to this symbol that do not use the |
3072 | | GOT, we don't need to generate a copy reloc. */ |
3073 | 0 | if (!h->non_got_ref) |
3074 | 0 | return true; |
3075 | | |
3076 | | /* We must allocate the symbol in our .dynbss section, which will |
3077 | | become part of the .bss section of the executable. There will be |
3078 | | an entry for this symbol in the .dynsym section. The dynamic |
3079 | | object will contain position independent code, so all references |
3080 | | from the dynamic object to this symbol will go through the global |
3081 | | offset table. The dynamic linker will use the .dynsym entry to |
3082 | | determine the address it must put in the global offset table, so |
3083 | | both the dynamic object and the regular object will refer to the |
3084 | | same memory location for the variable. */ |
3085 | | |
3086 | 0 | s = bfd_get_linker_section (dynobj, ".dynbss"); |
3087 | 0 | BFD_ASSERT (s != NULL); |
3088 | | |
3089 | | /* We must generate a R_68K_COPY reloc to tell the dynamic linker to |
3090 | | copy the initial value out of the dynamic object and into the |
3091 | | runtime process image. We need to remember the offset into the |
3092 | | .rela.bss section we are going to use. */ |
3093 | 0 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
3094 | 0 | { |
3095 | 0 | asection *srel; |
3096 | |
|
3097 | 0 | srel = bfd_get_linker_section (dynobj, ".rela.bss"); |
3098 | 0 | BFD_ASSERT (srel != NULL); |
3099 | 0 | srel->size += sizeof (Elf32_External_Rela); |
3100 | 0 | h->needs_copy = 1; |
3101 | 0 | } |
3102 | |
|
3103 | 0 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
3104 | 0 | } |
3105 | | |
3106 | | /* Set the sizes of the dynamic sections. */ |
3107 | | |
3108 | | static bool |
3109 | | elf_m68k_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
3110 | | struct bfd_link_info *info) |
3111 | 0 | { |
3112 | 0 | bfd *dynobj; |
3113 | 0 | asection *s; |
3114 | 0 | bool relocs; |
3115 | |
|
3116 | 0 | dynobj = elf_hash_table (info)->dynobj; |
3117 | 0 | if (dynobj == NULL) |
3118 | 0 | return true; |
3119 | | |
3120 | 0 | if (elf_hash_table (info)->dynamic_sections_created) |
3121 | 0 | { |
3122 | | /* Set the contents of the .interp section to the interpreter. */ |
3123 | 0 | if (bfd_link_executable (info) && !info->nointerp) |
3124 | 0 | { |
3125 | 0 | s = bfd_get_linker_section (dynobj, ".interp"); |
3126 | 0 | BFD_ASSERT (s != NULL); |
3127 | 0 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
3128 | 0 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
3129 | 0 | s->alloced = 1; |
3130 | 0 | } |
3131 | 0 | } |
3132 | 0 | else |
3133 | 0 | { |
3134 | | /* We may have created entries in the .rela.got section. |
3135 | | However, if we are not creating the dynamic sections, we will |
3136 | | not actually use these entries. Reset the size of .rela.got, |
3137 | | which will cause it to get stripped from the output file |
3138 | | below. */ |
3139 | 0 | s = elf_hash_table (info)->srelgot; |
3140 | 0 | if (s != NULL) |
3141 | 0 | s->size = 0; |
3142 | 0 | } |
3143 | | |
3144 | | /* If this is a -Bsymbolic shared link, then we need to discard all |
3145 | | PC relative relocs against symbols defined in a regular object. |
3146 | | For the normal shared case we discard the PC relative relocs |
3147 | | against symbols that have become local due to visibility changes. |
3148 | | We allocated space for them in the check_relocs routine, but we |
3149 | | will not fill them in in the relocate_section routine. */ |
3150 | 0 | if (bfd_link_pic (info)) |
3151 | 0 | elf_link_hash_traverse (elf_hash_table (info), |
3152 | 0 | elf_m68k_discard_copies, |
3153 | 0 | info); |
3154 | | |
3155 | | /* The check_relocs and adjust_dynamic_symbol entry points have |
3156 | | determined the sizes of the various dynamic sections. Allocate |
3157 | | memory for them. */ |
3158 | 0 | relocs = false; |
3159 | 0 | for (s = dynobj->sections; s != NULL; s = s->next) |
3160 | 0 | { |
3161 | 0 | const char *name; |
3162 | |
|
3163 | 0 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
3164 | 0 | continue; |
3165 | | |
3166 | | /* It's OK to base decisions on the section name, because none |
3167 | | of the dynobj section names depend upon the input files. */ |
3168 | 0 | name = bfd_section_name (s); |
3169 | |
|
3170 | 0 | if (strcmp (name, ".plt") == 0) |
3171 | 0 | { |
3172 | | /* Remember whether there is a PLT. */ |
3173 | 0 | ; |
3174 | 0 | } |
3175 | 0 | else if (startswith (name, ".rela")) |
3176 | 0 | { |
3177 | 0 | if (s->size != 0) |
3178 | 0 | { |
3179 | 0 | relocs = true; |
3180 | | |
3181 | | /* We use the reloc_count field as a counter if we need |
3182 | | to copy relocs into the output file. */ |
3183 | 0 | s->reloc_count = 0; |
3184 | 0 | } |
3185 | 0 | } |
3186 | 0 | else if (! startswith (name, ".got") |
3187 | 0 | && strcmp (name, ".dynbss") != 0) |
3188 | 0 | { |
3189 | | /* It's not one of our sections, so don't allocate space. */ |
3190 | 0 | continue; |
3191 | 0 | } |
3192 | | |
3193 | 0 | if (s->size == 0) |
3194 | 0 | { |
3195 | | /* If we don't need this section, strip it from the |
3196 | | output file. This is mostly to handle .rela.bss and |
3197 | | .rela.plt. We must create both sections in |
3198 | | create_dynamic_sections, because they must be created |
3199 | | before the linker maps input sections to output |
3200 | | sections. The linker does that before |
3201 | | adjust_dynamic_symbol is called, and it is that |
3202 | | function which decides whether anything needs to go |
3203 | | into these sections. */ |
3204 | 0 | s->flags |= SEC_EXCLUDE; |
3205 | 0 | continue; |
3206 | 0 | } |
3207 | | |
3208 | 0 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
3209 | 0 | continue; |
3210 | | |
3211 | | /* Allocate memory for the section contents. */ |
3212 | | /* FIXME: This should be a call to bfd_alloc not bfd_zalloc. |
3213 | | Unused entries should be reclaimed before the section's contents |
3214 | | are written out, but at the moment this does not happen. Thus in |
3215 | | order to prevent writing out garbage, we initialise the section's |
3216 | | contents to zero. */ |
3217 | 0 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
3218 | 0 | if (s->contents == NULL) |
3219 | 0 | return false; |
3220 | 0 | s->alloced = 1; |
3221 | 0 | } |
3222 | | |
3223 | 0 | return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs); |
3224 | 0 | } |
3225 | | |
3226 | | /* This function is called via elf_link_hash_traverse if we are |
3227 | | creating a shared object. In the -Bsymbolic case it discards the |
3228 | | space allocated to copy PC relative relocs against symbols which |
3229 | | are defined in regular objects. For the normal shared case, it |
3230 | | discards space for pc-relative relocs that have become local due to |
3231 | | symbol visibility changes. We allocated space for them in the |
3232 | | check_relocs routine, but we won't fill them in in the |
3233 | | relocate_section routine. |
3234 | | |
3235 | | We also check whether any of the remaining relocations apply |
3236 | | against a readonly section, and set the DF_TEXTREL flag in this |
3237 | | case. */ |
3238 | | |
3239 | | static bool |
3240 | | elf_m68k_discard_copies (struct elf_link_hash_entry *h, |
3241 | | void * inf) |
3242 | 0 | { |
3243 | 0 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
3244 | 0 | struct elf_m68k_pcrel_relocs_copied *s; |
3245 | |
|
3246 | 0 | if (!SYMBOL_CALLS_LOCAL (info, h)) |
3247 | 0 | { |
3248 | 0 | if ((info->flags & DF_TEXTREL) == 0) |
3249 | 0 | { |
3250 | | /* Look for relocations against read-only sections. */ |
3251 | 0 | for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; |
3252 | 0 | s != NULL; |
3253 | 0 | s = s->next) |
3254 | 0 | if ((s->section->flags & SEC_READONLY) != 0) |
3255 | 0 | { |
3256 | 0 | info->flags |= DF_TEXTREL; |
3257 | 0 | break; |
3258 | 0 | } |
3259 | 0 | } |
3260 | | |
3261 | | /* Make sure undefined weak symbols are output as a dynamic symbol |
3262 | | in PIEs. */ |
3263 | 0 | if (h->non_got_ref |
3264 | 0 | && h->root.type == bfd_link_hash_undefweak |
3265 | 0 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
3266 | 0 | && h->dynindx == -1 |
3267 | 0 | && !h->forced_local) |
3268 | 0 | { |
3269 | 0 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
3270 | 0 | return false; |
3271 | 0 | } |
3272 | | |
3273 | 0 | return true; |
3274 | 0 | } |
3275 | | |
3276 | 0 | for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; |
3277 | 0 | s != NULL; |
3278 | 0 | s = s->next) |
3279 | 0 | s->section->size -= s->count * sizeof (Elf32_External_Rela); |
3280 | |
|
3281 | 0 | return true; |
3282 | 0 | } |
3283 | | |
3284 | | |
3285 | | /* Install relocation RELA. */ |
3286 | | |
3287 | | static void |
3288 | | elf_m68k_install_rela (bfd *output_bfd, |
3289 | | asection *srela, |
3290 | | Elf_Internal_Rela *rela) |
3291 | 0 | { |
3292 | 0 | bfd_byte *loc; |
3293 | |
|
3294 | 0 | loc = srela->contents; |
3295 | 0 | loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); |
3296 | 0 | bfd_elf32_swap_reloca_out (output_bfd, rela, loc); |
3297 | 0 | } |
3298 | | |
3299 | | /* Find the base offsets for thread-local storage in this object, |
3300 | | for GD/LD and IE/LE respectively. */ |
3301 | | |
3302 | 0 | #define DTP_OFFSET 0x8000 |
3303 | 0 | #define TP_OFFSET 0x7000 |
3304 | | |
3305 | | static bfd_vma |
3306 | | dtpoff_base (struct bfd_link_info *info) |
3307 | 0 | { |
3308 | | /* If tls_sec is NULL, we should have signalled an error already. */ |
3309 | 0 | if (elf_hash_table (info)->tls_sec == NULL) |
3310 | 0 | return 0; |
3311 | 0 | return elf_hash_table (info)->tls_sec->vma + DTP_OFFSET; |
3312 | 0 | } |
3313 | | |
3314 | | static bfd_vma |
3315 | | tpoff_base (struct bfd_link_info *info) |
3316 | 0 | { |
3317 | | /* If tls_sec is NULL, we should have signalled an error already. */ |
3318 | 0 | if (elf_hash_table (info)->tls_sec == NULL) |
3319 | 0 | return 0; |
3320 | 0 | return elf_hash_table (info)->tls_sec->vma + TP_OFFSET; |
3321 | 0 | } |
3322 | | |
3323 | | /* Output necessary relocation to handle a symbol during static link. |
3324 | | This function is called from elf_m68k_relocate_section. */ |
3325 | | |
3326 | | static void |
3327 | | elf_m68k_init_got_entry_static (struct bfd_link_info *info, |
3328 | | bfd *output_bfd, |
3329 | | enum elf_m68k_reloc_type r_type, |
3330 | | asection *sgot, |
3331 | | bfd_vma got_entry_offset, |
3332 | | bfd_vma relocation) |
3333 | 0 | { |
3334 | 0 | switch (elf_m68k_reloc_got_type (r_type)) |
3335 | 0 | { |
3336 | 0 | case R_68K_GOT32O: |
3337 | 0 | bfd_put_32 (output_bfd, relocation, sgot->contents + got_entry_offset); |
3338 | 0 | break; |
3339 | | |
3340 | 0 | case R_68K_TLS_GD32: |
3341 | | /* We know the offset within the module, |
3342 | | put it into the second GOT slot. */ |
3343 | 0 | bfd_put_32 (output_bfd, relocation - dtpoff_base (info), |
3344 | 0 | sgot->contents + got_entry_offset + 4); |
3345 | | /* FALLTHRU */ |
3346 | |
|
3347 | 0 | case R_68K_TLS_LDM32: |
3348 | | /* Mark it as belonging to module 1, the executable. */ |
3349 | 0 | bfd_put_32 (output_bfd, 1, sgot->contents + got_entry_offset); |
3350 | 0 | break; |
3351 | | |
3352 | 0 | case R_68K_TLS_IE32: |
3353 | 0 | bfd_put_32 (output_bfd, relocation - tpoff_base (info), |
3354 | 0 | sgot->contents + got_entry_offset); |
3355 | 0 | break; |
3356 | | |
3357 | 0 | default: |
3358 | 0 | BFD_ASSERT (false); |
3359 | 0 | } |
3360 | 0 | } |
3361 | | |
3362 | | /* Output necessary relocation to handle a local symbol |
3363 | | during dynamic link. |
3364 | | This function is called either from elf_m68k_relocate_section |
3365 | | or from elf_m68k_finish_dynamic_symbol. */ |
3366 | | |
3367 | | static void |
3368 | | elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info, |
3369 | | bfd *output_bfd, |
3370 | | enum elf_m68k_reloc_type r_type, |
3371 | | asection *sgot, |
3372 | | bfd_vma got_entry_offset, |
3373 | | bfd_vma relocation, |
3374 | | asection *srela) |
3375 | 0 | { |
3376 | 0 | Elf_Internal_Rela outrel; |
3377 | |
|
3378 | 0 | switch (elf_m68k_reloc_got_type (r_type)) |
3379 | 0 | { |
3380 | 0 | case R_68K_GOT32O: |
3381 | | /* Emit RELATIVE relocation to initialize GOT slot |
3382 | | at run-time. */ |
3383 | 0 | outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); |
3384 | 0 | outrel.r_addend = relocation; |
3385 | 0 | break; |
3386 | | |
3387 | 0 | case R_68K_TLS_GD32: |
3388 | | /* We know the offset within the module, |
3389 | | put it into the second GOT slot. */ |
3390 | 0 | bfd_put_32 (output_bfd, relocation - dtpoff_base (info), |
3391 | 0 | sgot->contents + got_entry_offset + 4); |
3392 | | /* FALLTHRU */ |
3393 | |
|
3394 | 0 | case R_68K_TLS_LDM32: |
3395 | | /* We don't know the module number, |
3396 | | create a relocation for it. */ |
3397 | 0 | outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32); |
3398 | 0 | outrel.r_addend = 0; |
3399 | 0 | break; |
3400 | | |
3401 | 0 | case R_68K_TLS_IE32: |
3402 | | /* Emit TPREL relocation to initialize GOT slot |
3403 | | at run-time. */ |
3404 | 0 | outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32); |
3405 | 0 | outrel.r_addend = relocation - elf_hash_table (info)->tls_sec->vma; |
3406 | 0 | break; |
3407 | | |
3408 | 0 | default: |
3409 | 0 | BFD_ASSERT (false); |
3410 | 0 | } |
3411 | | |
3412 | | /* Offset of the GOT entry. */ |
3413 | 0 | outrel.r_offset = (sgot->output_section->vma |
3414 | 0 | + sgot->output_offset |
3415 | 0 | + got_entry_offset); |
3416 | | |
3417 | | /* Install one of the above relocations. */ |
3418 | 0 | elf_m68k_install_rela (output_bfd, srela, &outrel); |
3419 | |
|
3420 | 0 | bfd_put_32 (output_bfd, outrel.r_addend, sgot->contents + got_entry_offset); |
3421 | 0 | } |
3422 | | |
3423 | | /* Relocate an M68K ELF section. */ |
3424 | | |
3425 | | static int |
3426 | | elf_m68k_relocate_section (bfd *output_bfd, |
3427 | | struct bfd_link_info *info, |
3428 | | bfd *input_bfd, |
3429 | | asection *input_section, |
3430 | | bfd_byte *contents, |
3431 | | Elf_Internal_Rela *relocs, |
3432 | | Elf_Internal_Sym *local_syms, |
3433 | | asection **local_sections) |
3434 | 0 | { |
3435 | 0 | Elf_Internal_Shdr *symtab_hdr; |
3436 | 0 | struct elf_link_hash_entry **sym_hashes; |
3437 | 0 | asection *sgot; |
3438 | 0 | asection *splt; |
3439 | 0 | asection *sreloc; |
3440 | 0 | asection *srela; |
3441 | 0 | struct elf_m68k_got *got; |
3442 | 0 | Elf_Internal_Rela *rel; |
3443 | 0 | Elf_Internal_Rela *relend; |
3444 | |
|
3445 | 0 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
3446 | 0 | sym_hashes = elf_sym_hashes (input_bfd); |
3447 | |
|
3448 | 0 | sgot = NULL; |
3449 | 0 | splt = NULL; |
3450 | 0 | sreloc = NULL; |
3451 | 0 | srela = NULL; |
3452 | |
|
3453 | 0 | got = NULL; |
3454 | |
|
3455 | 0 | rel = relocs; |
3456 | 0 | relend = relocs + input_section->reloc_count; |
3457 | 0 | for (; rel < relend; rel++) |
3458 | 0 | { |
3459 | 0 | int r_type; |
3460 | 0 | reloc_howto_type *howto; |
3461 | 0 | unsigned long r_symndx; |
3462 | 0 | struct elf_link_hash_entry *h; |
3463 | 0 | Elf_Internal_Sym *sym; |
3464 | 0 | asection *sec; |
3465 | 0 | bfd_vma relocation; |
3466 | 0 | bool unresolved_reloc; |
3467 | 0 | bfd_reloc_status_type r; |
3468 | 0 | bool resolved_to_zero; |
3469 | |
|
3470 | 0 | r_type = ELF32_R_TYPE (rel->r_info); |
3471 | 0 | if (r_type < 0 || r_type >= (int) R_68K_max) |
3472 | 0 | { |
3473 | 0 | bfd_set_error (bfd_error_bad_value); |
3474 | 0 | return false; |
3475 | 0 | } |
3476 | 0 | howto = howto_table + r_type; |
3477 | |
|
3478 | 0 | r_symndx = ELF32_R_SYM (rel->r_info); |
3479 | |
|
3480 | 0 | h = NULL; |
3481 | 0 | sym = NULL; |
3482 | 0 | sec = NULL; |
3483 | 0 | unresolved_reloc = false; |
3484 | |
|
3485 | 0 | if (r_symndx < symtab_hdr->sh_info) |
3486 | 0 | { |
3487 | 0 | sym = local_syms + r_symndx; |
3488 | 0 | sec = local_sections[r_symndx]; |
3489 | 0 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
3490 | 0 | } |
3491 | 0 | else |
3492 | 0 | { |
3493 | 0 | bool warned, ignored; |
3494 | |
|
3495 | 0 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
3496 | 0 | r_symndx, symtab_hdr, sym_hashes, |
3497 | 0 | h, sec, relocation, |
3498 | 0 | unresolved_reloc, warned, ignored); |
3499 | 0 | } |
3500 | | |
3501 | 0 | if (sec != NULL && discarded_section (sec)) |
3502 | 0 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
3503 | 0 | rel, 1, relend, howto, 0, contents); |
3504 | |
|
3505 | 0 | if (bfd_link_relocatable (info)) |
3506 | 0 | continue; |
3507 | | |
3508 | 0 | resolved_to_zero = (h != NULL |
3509 | 0 | && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); |
3510 | |
|
3511 | 0 | switch (r_type) |
3512 | 0 | { |
3513 | 0 | case R_68K_GOT8: |
3514 | 0 | case R_68K_GOT16: |
3515 | 0 | case R_68K_GOT32: |
3516 | | /* Relocation is to the address of the entry for this symbol |
3517 | | in the global offset table. */ |
3518 | 0 | if (h != NULL |
3519 | 0 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
3520 | 0 | { |
3521 | 0 | if (elf_m68k_hash_table (info)->local_gp_p) |
3522 | 0 | { |
3523 | 0 | bfd_vma sgot_output_offset; |
3524 | 0 | bfd_vma got_offset; |
3525 | |
|
3526 | 0 | sgot = elf_hash_table (info)->sgot; |
3527 | |
|
3528 | 0 | if (sgot != NULL) |
3529 | 0 | sgot_output_offset = sgot->output_offset; |
3530 | 0 | else |
3531 | | /* In this case we have a reference to |
3532 | | _GLOBAL_OFFSET_TABLE_, but the GOT itself is |
3533 | | empty. |
3534 | | ??? Issue a warning? */ |
3535 | 0 | sgot_output_offset = 0; |
3536 | |
|
3537 | 0 | if (got == NULL) |
3538 | 0 | { |
3539 | 0 | struct elf_m68k_bfd2got_entry *bfd2got_entry; |
3540 | |
|
3541 | 0 | bfd2got_entry |
3542 | 0 | = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), |
3543 | 0 | input_bfd, SEARCH, NULL); |
3544 | |
|
3545 | 0 | if (bfd2got_entry != NULL) |
3546 | 0 | { |
3547 | 0 | got = bfd2got_entry->got; |
3548 | 0 | BFD_ASSERT (got != NULL); |
3549 | |
|
3550 | 0 | got_offset = got->offset; |
3551 | 0 | } |
3552 | 0 | else |
3553 | | /* In this case we have a reference to |
3554 | | _GLOBAL_OFFSET_TABLE_, but no other references |
3555 | | accessing any GOT entries. |
3556 | | ??? Issue a warning? */ |
3557 | 0 | got_offset = 0; |
3558 | 0 | } |
3559 | 0 | else |
3560 | 0 | got_offset = got->offset; |
3561 | | |
3562 | | /* Adjust GOT pointer to point to the GOT |
3563 | | assigned to input_bfd. */ |
3564 | 0 | rel->r_addend += sgot_output_offset + got_offset; |
3565 | 0 | } |
3566 | 0 | else |
3567 | 0 | BFD_ASSERT (got == NULL || got->offset == 0); |
3568 | |
|
3569 | 0 | break; |
3570 | 0 | } |
3571 | | /* Fall through. */ |
3572 | 0 | case R_68K_GOT8O: |
3573 | 0 | case R_68K_GOT16O: |
3574 | 0 | case R_68K_GOT32O: |
3575 | |
|
3576 | 0 | case R_68K_TLS_LDM32: |
3577 | 0 | case R_68K_TLS_LDM16: |
3578 | 0 | case R_68K_TLS_LDM8: |
3579 | |
|
3580 | 0 | case R_68K_TLS_GD8: |
3581 | 0 | case R_68K_TLS_GD16: |
3582 | 0 | case R_68K_TLS_GD32: |
3583 | |
|
3584 | 0 | case R_68K_TLS_IE8: |
3585 | 0 | case R_68K_TLS_IE16: |
3586 | 0 | case R_68K_TLS_IE32: |
3587 | | |
3588 | | /* Relocation is the offset of the entry for this symbol in |
3589 | | the global offset table. */ |
3590 | |
|
3591 | 0 | { |
3592 | 0 | struct elf_m68k_got_entry_key key_; |
3593 | 0 | bfd_vma *off_ptr; |
3594 | 0 | bfd_vma off; |
3595 | |
|
3596 | 0 | sgot = elf_hash_table (info)->sgot; |
3597 | 0 | BFD_ASSERT (sgot != NULL); |
3598 | |
|
3599 | 0 | if (got == NULL) |
3600 | 0 | got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), |
3601 | 0 | input_bfd, MUST_FIND, |
3602 | 0 | NULL)->got; |
3603 | | |
3604 | | /* Get GOT offset for this symbol. */ |
3605 | 0 | elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx, |
3606 | 0 | r_type); |
3607 | 0 | off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND, |
3608 | 0 | NULL)->u.s2.offset; |
3609 | 0 | off = *off_ptr; |
3610 | | |
3611 | | /* The offset must always be a multiple of 4. We use |
3612 | | the least significant bit to record whether we have |
3613 | | already generated the necessary reloc. */ |
3614 | 0 | if ((off & 1) != 0) |
3615 | 0 | off &= ~1; |
3616 | 0 | else |
3617 | 0 | { |
3618 | 0 | if (h != NULL |
3619 | | /* @TLSLDM relocations are bounded to the module, in |
3620 | | which the symbol is defined -- not to the symbol |
3621 | | itself. */ |
3622 | 0 | && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32) |
3623 | 0 | { |
3624 | 0 | bool dyn; |
3625 | |
|
3626 | 0 | dyn = elf_hash_table (info)->dynamic_sections_created; |
3627 | 0 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, |
3628 | 0 | bfd_link_pic (info), |
3629 | 0 | h) |
3630 | 0 | || (bfd_link_pic (info) |
3631 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
3632 | 0 | || ((ELF_ST_VISIBILITY (h->other) |
3633 | 0 | || resolved_to_zero) |
3634 | 0 | && h->root.type == bfd_link_hash_undefweak)) |
3635 | 0 | { |
3636 | | /* This is actually a static link, or it is a |
3637 | | -Bsymbolic link and the symbol is defined |
3638 | | locally, or the symbol was forced to be local |
3639 | | because of a version file. We must initialize |
3640 | | this entry in the global offset table. Since |
3641 | | the offset must always be a multiple of 4, we |
3642 | | use the least significant bit to record whether |
3643 | | we have initialized it already. |
3644 | | |
3645 | | When doing a dynamic link, we create a .rela.got |
3646 | | relocation entry to initialize the value. This |
3647 | | is done in the finish_dynamic_symbol routine. */ |
3648 | |
|
3649 | 0 | elf_m68k_init_got_entry_static (info, |
3650 | 0 | output_bfd, |
3651 | 0 | r_type, |
3652 | 0 | sgot, |
3653 | 0 | off, |
3654 | 0 | relocation); |
3655 | |
|
3656 | 0 | *off_ptr |= 1; |
3657 | 0 | } |
3658 | 0 | else |
3659 | 0 | unresolved_reloc = false; |
3660 | 0 | } |
3661 | 0 | else if (bfd_link_pic (info)) /* && h == NULL */ |
3662 | | /* Process local symbol during dynamic link. */ |
3663 | 0 | { |
3664 | 0 | srela = elf_hash_table (info)->srelgot; |
3665 | 0 | BFD_ASSERT (srela != NULL); |
3666 | |
|
3667 | 0 | elf_m68k_init_got_entry_local_shared (info, |
3668 | 0 | output_bfd, |
3669 | 0 | r_type, |
3670 | 0 | sgot, |
3671 | 0 | off, |
3672 | 0 | relocation, |
3673 | 0 | srela); |
3674 | |
|
3675 | 0 | *off_ptr |= 1; |
3676 | 0 | } |
3677 | 0 | else /* h == NULL && !bfd_link_pic (info) */ |
3678 | 0 | { |
3679 | 0 | elf_m68k_init_got_entry_static (info, |
3680 | 0 | output_bfd, |
3681 | 0 | r_type, |
3682 | 0 | sgot, |
3683 | 0 | off, |
3684 | 0 | relocation); |
3685 | |
|
3686 | 0 | *off_ptr |= 1; |
3687 | 0 | } |
3688 | 0 | } |
3689 | | |
3690 | | /* We don't use elf_m68k_reloc_got_type in the condition below |
3691 | | because this is the only place where difference between |
3692 | | R_68K_GOTx and R_68K_GOTxO relocations matters. */ |
3693 | 0 | if (r_type == R_68K_GOT32O |
3694 | 0 | || r_type == R_68K_GOT16O |
3695 | 0 | || r_type == R_68K_GOT8O |
3696 | 0 | || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32 |
3697 | 0 | || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32 |
3698 | 0 | || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32) |
3699 | 0 | { |
3700 | | /* GOT pointer is adjusted to point to the start/middle |
3701 | | of local GOT. Adjust the offset accordingly. */ |
3702 | 0 | BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p |
3703 | 0 | || off >= got->offset); |
3704 | |
|
3705 | 0 | if (elf_m68k_hash_table (info)->local_gp_p) |
3706 | 0 | relocation = off - got->offset; |
3707 | 0 | else |
3708 | 0 | { |
3709 | 0 | BFD_ASSERT (got->offset == 0); |
3710 | 0 | relocation = sgot->output_offset + off; |
3711 | 0 | } |
3712 | | |
3713 | | /* This relocation does not use the addend. */ |
3714 | 0 | rel->r_addend = 0; |
3715 | 0 | } |
3716 | 0 | else |
3717 | 0 | relocation = (sgot->output_section->vma + sgot->output_offset |
3718 | 0 | + off); |
3719 | 0 | } |
3720 | 0 | break; |
3721 | | |
3722 | 0 | case R_68K_TLS_LDO32: |
3723 | 0 | case R_68K_TLS_LDO16: |
3724 | 0 | case R_68K_TLS_LDO8: |
3725 | 0 | relocation -= dtpoff_base (info); |
3726 | 0 | break; |
3727 | | |
3728 | 0 | case R_68K_TLS_LE32: |
3729 | 0 | case R_68K_TLS_LE16: |
3730 | 0 | case R_68K_TLS_LE8: |
3731 | 0 | if (bfd_link_dll (info)) |
3732 | 0 | { |
3733 | 0 | _bfd_error_handler |
3734 | | /* xgettext:c-format */ |
3735 | 0 | (_("%pB(%pA+%#" PRIx64 "): " |
3736 | 0 | "%s relocation not permitted in shared object"), |
3737 | 0 | input_bfd, input_section, (uint64_t) rel->r_offset, |
3738 | 0 | howto->name); |
3739 | |
|
3740 | 0 | return false; |
3741 | 0 | } |
3742 | 0 | else |
3743 | 0 | relocation -= tpoff_base (info); |
3744 | | |
3745 | 0 | break; |
3746 | | |
3747 | 0 | case R_68K_PLT8: |
3748 | 0 | case R_68K_PLT16: |
3749 | 0 | case R_68K_PLT32: |
3750 | | /* Relocation is to the entry for this symbol in the |
3751 | | procedure linkage table. */ |
3752 | | |
3753 | | /* Resolve a PLTxx reloc against a local symbol directly, |
3754 | | without using the procedure linkage table. */ |
3755 | 0 | if (h == NULL) |
3756 | 0 | break; |
3757 | | |
3758 | 0 | if (h->plt.offset == (bfd_vma) -1 |
3759 | 0 | || !elf_hash_table (info)->dynamic_sections_created) |
3760 | 0 | { |
3761 | | /* We didn't make a PLT entry for this symbol. This |
3762 | | happens when statically linking PIC code, or when |
3763 | | using -Bsymbolic. */ |
3764 | 0 | break; |
3765 | 0 | } |
3766 | | |
3767 | 0 | splt = elf_hash_table (info)->splt; |
3768 | 0 | BFD_ASSERT (splt != NULL); |
3769 | |
|
3770 | 0 | relocation = (splt->output_section->vma |
3771 | 0 | + splt->output_offset |
3772 | 0 | + h->plt.offset); |
3773 | 0 | unresolved_reloc = false; |
3774 | 0 | break; |
3775 | | |
3776 | 0 | case R_68K_PLT8O: |
3777 | 0 | case R_68K_PLT16O: |
3778 | 0 | case R_68K_PLT32O: |
3779 | | /* Relocation is the offset of the entry for this symbol in |
3780 | | the procedure linkage table. */ |
3781 | 0 | BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1); |
3782 | |
|
3783 | 0 | splt = elf_hash_table (info)->splt; |
3784 | 0 | BFD_ASSERT (splt != NULL); |
3785 | |
|
3786 | 0 | relocation = h->plt.offset; |
3787 | 0 | unresolved_reloc = false; |
3788 | | |
3789 | | /* This relocation does not use the addend. */ |
3790 | 0 | rel->r_addend = 0; |
3791 | |
|
3792 | 0 | break; |
3793 | | |
3794 | 0 | case R_68K_8: |
3795 | 0 | case R_68K_16: |
3796 | 0 | case R_68K_32: |
3797 | 0 | case R_68K_PC8: |
3798 | 0 | case R_68K_PC16: |
3799 | 0 | case R_68K_PC32: |
3800 | 0 | if (bfd_link_pic (info) |
3801 | 0 | && r_symndx != STN_UNDEF |
3802 | 0 | && (input_section->flags & SEC_ALLOC) != 0 |
3803 | 0 | && (h == NULL |
3804 | 0 | || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
3805 | 0 | && !resolved_to_zero) |
3806 | 0 | || h->root.type != bfd_link_hash_undefweak) |
3807 | 0 | && ((r_type != R_68K_PC8 |
3808 | 0 | && r_type != R_68K_PC16 |
3809 | 0 | && r_type != R_68K_PC32) |
3810 | 0 | || !SYMBOL_CALLS_LOCAL (info, h))) |
3811 | 0 | { |
3812 | 0 | Elf_Internal_Rela outrel; |
3813 | 0 | bfd_byte *loc; |
3814 | 0 | bool skip, relocate; |
3815 | | |
3816 | | /* When generating a shared object, these relocations |
3817 | | are copied into the output file to be resolved at run |
3818 | | time. */ |
3819 | |
|
3820 | 0 | skip = false; |
3821 | 0 | relocate = false; |
3822 | |
|
3823 | 0 | outrel.r_offset = |
3824 | 0 | _bfd_elf_section_offset (output_bfd, info, input_section, |
3825 | 0 | rel->r_offset); |
3826 | 0 | if (outrel.r_offset == (bfd_vma) -1) |
3827 | 0 | skip = true; |
3828 | 0 | else if (outrel.r_offset == (bfd_vma) -2) |
3829 | 0 | skip = true, relocate = true; |
3830 | 0 | outrel.r_offset += (input_section->output_section->vma |
3831 | 0 | + input_section->output_offset); |
3832 | |
|
3833 | 0 | if (skip) |
3834 | 0 | memset (&outrel, 0, sizeof outrel); |
3835 | 0 | else if (h != NULL |
3836 | 0 | && h->dynindx != -1 |
3837 | 0 | && (r_type == R_68K_PC8 |
3838 | 0 | || r_type == R_68K_PC16 |
3839 | 0 | || r_type == R_68K_PC32 |
3840 | 0 | || !bfd_link_pic (info) |
3841 | 0 | || !SYMBOLIC_BIND (info, h) |
3842 | 0 | || !h->def_regular)) |
3843 | 0 | { |
3844 | 0 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
3845 | 0 | outrel.r_addend = rel->r_addend; |
3846 | 0 | } |
3847 | 0 | else |
3848 | 0 | { |
3849 | | /* This symbol is local, or marked to become local. */ |
3850 | 0 | outrel.r_addend = relocation + rel->r_addend; |
3851 | |
|
3852 | 0 | if (r_type == R_68K_32) |
3853 | 0 | { |
3854 | 0 | relocate = true; |
3855 | 0 | outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); |
3856 | 0 | } |
3857 | 0 | else |
3858 | 0 | { |
3859 | 0 | long indx; |
3860 | |
|
3861 | 0 | if (bfd_is_abs_section (sec)) |
3862 | 0 | indx = 0; |
3863 | 0 | else if (sec == NULL || sec->owner == NULL) |
3864 | 0 | { |
3865 | 0 | bfd_set_error (bfd_error_bad_value); |
3866 | 0 | return false; |
3867 | 0 | } |
3868 | 0 | else |
3869 | 0 | { |
3870 | 0 | asection *osec; |
3871 | | |
3872 | | /* We are turning this relocation into one |
3873 | | against a section symbol. It would be |
3874 | | proper to subtract the symbol's value, |
3875 | | osec->vma, from the emitted reloc addend, |
3876 | | but ld.so expects buggy relocs. */ |
3877 | 0 | osec = sec->output_section; |
3878 | 0 | indx = elf_section_data (osec)->dynindx; |
3879 | 0 | if (indx == 0) |
3880 | 0 | { |
3881 | 0 | struct elf_link_hash_table *htab; |
3882 | 0 | htab = elf_hash_table (info); |
3883 | 0 | osec = htab->text_index_section; |
3884 | 0 | indx = elf_section_data (osec)->dynindx; |
3885 | 0 | } |
3886 | 0 | BFD_ASSERT (indx != 0); |
3887 | 0 | } |
3888 | | |
3889 | 0 | outrel.r_info = ELF32_R_INFO (indx, r_type); |
3890 | 0 | } |
3891 | 0 | } |
3892 | | |
3893 | 0 | sreloc = elf_section_data (input_section)->sreloc; |
3894 | 0 | if (sreloc == NULL) |
3895 | 0 | abort (); |
3896 | | |
3897 | 0 | loc = sreloc->contents; |
3898 | 0 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); |
3899 | 0 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
3900 | | |
3901 | | /* This reloc will be computed at runtime, so there's no |
3902 | | need to do anything now, except for R_68K_32 |
3903 | | relocations that have been turned into |
3904 | | R_68K_RELATIVE. */ |
3905 | 0 | if (!relocate) |
3906 | 0 | continue; |
3907 | 0 | } |
3908 | | |
3909 | 0 | break; |
3910 | | |
3911 | 0 | case R_68K_GNU_VTINHERIT: |
3912 | 0 | case R_68K_GNU_VTENTRY: |
3913 | | /* These are no-ops in the end. */ |
3914 | 0 | continue; |
3915 | | |
3916 | 0 | default: |
3917 | 0 | break; |
3918 | 0 | } |
3919 | | |
3920 | | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
3921 | | because such sections are not SEC_ALLOC and thus ld.so will |
3922 | | not process them. */ |
3923 | 0 | if (unresolved_reloc |
3924 | 0 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
3925 | 0 | && h->def_dynamic) |
3926 | 0 | && _bfd_elf_section_offset (output_bfd, info, input_section, |
3927 | 0 | rel->r_offset) != (bfd_vma) -1) |
3928 | 0 | { |
3929 | 0 | _bfd_error_handler |
3930 | | /* xgettext:c-format */ |
3931 | 0 | (_("%pB(%pA+%#" PRIx64 "): " |
3932 | 0 | "unresolvable %s relocation against symbol `%s'"), |
3933 | 0 | input_bfd, |
3934 | 0 | input_section, |
3935 | 0 | (uint64_t) rel->r_offset, |
3936 | 0 | howto->name, |
3937 | 0 | h->root.root.string); |
3938 | 0 | return false; |
3939 | 0 | } |
3940 | | |
3941 | 0 | if (r_symndx != STN_UNDEF |
3942 | 0 | && r_type != R_68K_NONE |
3943 | 0 | && (h == NULL |
3944 | 0 | || h->root.type == bfd_link_hash_defined |
3945 | 0 | || h->root.type == bfd_link_hash_defweak)) |
3946 | 0 | { |
3947 | 0 | char sym_type; |
3948 | |
|
3949 | 0 | sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type; |
3950 | |
|
3951 | 0 | if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS)) |
3952 | 0 | { |
3953 | 0 | const char *name; |
3954 | |
|
3955 | 0 | if (h != NULL) |
3956 | 0 | name = h->root.root.string; |
3957 | 0 | else |
3958 | 0 | { |
3959 | 0 | name = (bfd_elf_string_from_elf_section |
3960 | 0 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); |
3961 | 0 | if (name == NULL || *name == '\0') |
3962 | 0 | name = bfd_section_name (sec); |
3963 | 0 | } |
3964 | |
|
3965 | 0 | _bfd_error_handler |
3966 | 0 | ((sym_type == STT_TLS |
3967 | | /* xgettext:c-format */ |
3968 | 0 | ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s") |
3969 | | /* xgettext:c-format */ |
3970 | 0 | : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")), |
3971 | 0 | input_bfd, |
3972 | 0 | input_section, |
3973 | 0 | (uint64_t) rel->r_offset, |
3974 | 0 | howto->name, |
3975 | 0 | name); |
3976 | 0 | } |
3977 | 0 | } |
3978 | |
|
3979 | 0 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
3980 | 0 | contents, rel->r_offset, |
3981 | 0 | relocation, rel->r_addend); |
3982 | |
|
3983 | 0 | if (r != bfd_reloc_ok) |
3984 | 0 | { |
3985 | 0 | const char *name; |
3986 | |
|
3987 | 0 | if (h != NULL) |
3988 | 0 | name = h->root.root.string; |
3989 | 0 | else |
3990 | 0 | { |
3991 | 0 | name = bfd_elf_string_from_elf_section (input_bfd, |
3992 | 0 | symtab_hdr->sh_link, |
3993 | 0 | sym->st_name); |
3994 | 0 | if (name == NULL) |
3995 | 0 | return false; |
3996 | 0 | if (*name == '\0') |
3997 | 0 | name = bfd_section_name (sec); |
3998 | 0 | } |
3999 | | |
4000 | 0 | if (r == bfd_reloc_overflow) |
4001 | 0 | (*info->callbacks->reloc_overflow) |
4002 | 0 | (info, (h ? &h->root : NULL), name, howto->name, |
4003 | 0 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); |
4004 | 0 | else |
4005 | 0 | { |
4006 | 0 | _bfd_error_handler |
4007 | | /* xgettext:c-format */ |
4008 | 0 | (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"), |
4009 | 0 | input_bfd, input_section, |
4010 | 0 | (uint64_t) rel->r_offset, name, (int) r); |
4011 | 0 | return false; |
4012 | 0 | } |
4013 | 0 | } |
4014 | 0 | } |
4015 | | |
4016 | 0 | return true; |
4017 | 0 | } |
4018 | | |
4019 | | /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET |
4020 | | into section SEC. */ |
4021 | | |
4022 | | static void |
4023 | | elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value) |
4024 | 0 | { |
4025 | | /* Make VALUE PC-relative. */ |
4026 | 0 | value -= sec->output_section->vma + offset; |
4027 | | |
4028 | | /* Apply any in-place addend. */ |
4029 | 0 | value += bfd_get_32 (sec->owner, sec->contents + offset); |
4030 | |
|
4031 | 0 | bfd_put_32 (sec->owner, value, sec->contents + offset); |
4032 | 0 | } |
4033 | | |
4034 | | /* Finish up dynamic symbol handling. We set the contents of various |
4035 | | dynamic sections here. */ |
4036 | | |
4037 | | static bool |
4038 | | elf_m68k_finish_dynamic_symbol (bfd *output_bfd, |
4039 | | struct bfd_link_info *info, |
4040 | | struct elf_link_hash_entry *h, |
4041 | | Elf_Internal_Sym *sym) |
4042 | 0 | { |
4043 | 0 | bfd *dynobj; |
4044 | |
|
4045 | 0 | dynobj = elf_hash_table (info)->dynobj; |
4046 | |
|
4047 | 0 | if (h->plt.offset != (bfd_vma) -1) |
4048 | 0 | { |
4049 | 0 | const struct elf_m68k_plt_info *plt_info; |
4050 | 0 | asection *splt; |
4051 | 0 | asection *sgot; |
4052 | 0 | asection *srela; |
4053 | 0 | bfd_vma plt_index; |
4054 | 0 | bfd_vma got_offset; |
4055 | 0 | Elf_Internal_Rela rela; |
4056 | 0 | bfd_byte *loc; |
4057 | | |
4058 | | /* This symbol has an entry in the procedure linkage table. Set |
4059 | | it up. */ |
4060 | |
|
4061 | 0 | BFD_ASSERT (h->dynindx != -1); |
4062 | |
|
4063 | 0 | plt_info = elf_m68k_hash_table (info)->plt_info; |
4064 | 0 | splt = elf_hash_table (info)->splt; |
4065 | 0 | sgot = elf_hash_table (info)->sgotplt; |
4066 | 0 | srela = elf_hash_table (info)->srelplt; |
4067 | 0 | BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); |
4068 | | |
4069 | | /* Get the index in the procedure linkage table which |
4070 | | corresponds to this symbol. This is the index of this symbol |
4071 | | in all the symbols for which we are making plt entries. The |
4072 | | first entry in the procedure linkage table is reserved. */ |
4073 | 0 | plt_index = (h->plt.offset / plt_info->size) - 1; |
4074 | | |
4075 | | /* Get the offset into the .got table of the entry that |
4076 | | corresponds to this function. Each .got entry is 4 bytes. |
4077 | | The first three are reserved. */ |
4078 | 0 | got_offset = (plt_index + 3) * 4; |
4079 | |
|
4080 | 0 | memcpy (splt->contents + h->plt.offset, |
4081 | 0 | plt_info->symbol_entry, |
4082 | 0 | plt_info->size); |
4083 | |
|
4084 | 0 | elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got, |
4085 | 0 | (sgot->output_section->vma |
4086 | 0 | + sgot->output_offset |
4087 | 0 | + got_offset)); |
4088 | |
|
4089 | 0 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), |
4090 | 0 | splt->contents |
4091 | 0 | + h->plt.offset |
4092 | 0 | + plt_info->symbol_resolve_entry + 2); |
4093 | |
|
4094 | 0 | elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt, |
4095 | 0 | splt->output_section->vma); |
4096 | | |
4097 | | /* Fill in the entry in the global offset table. */ |
4098 | 0 | bfd_put_32 (output_bfd, |
4099 | 0 | (splt->output_section->vma |
4100 | 0 | + splt->output_offset |
4101 | 0 | + h->plt.offset |
4102 | 0 | + plt_info->symbol_resolve_entry), |
4103 | 0 | sgot->contents + got_offset); |
4104 | | |
4105 | | /* Fill in the entry in the .rela.plt section. */ |
4106 | 0 | rela.r_offset = (sgot->output_section->vma |
4107 | 0 | + sgot->output_offset |
4108 | 0 | + got_offset); |
4109 | 0 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT); |
4110 | 0 | rela.r_addend = 0; |
4111 | 0 | loc = srela->contents + plt_index * sizeof (Elf32_External_Rela); |
4112 | 0 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
4113 | |
|
4114 | 0 | if (!h->def_regular) |
4115 | 0 | { |
4116 | | /* Mark the symbol as undefined, rather than as defined in |
4117 | | the .plt section. Leave the value alone. */ |
4118 | 0 | sym->st_shndx = SHN_UNDEF; |
4119 | 0 | } |
4120 | 0 | } |
4121 | |
|
4122 | 0 | if (elf_m68k_hash_entry (h)->glist != NULL) |
4123 | 0 | { |
4124 | 0 | asection *sgot; |
4125 | 0 | asection *srela; |
4126 | 0 | struct elf_m68k_got_entry *got_entry; |
4127 | | |
4128 | | /* This symbol has an entry in the global offset table. Set it |
4129 | | up. */ |
4130 | |
|
4131 | 0 | sgot = elf_hash_table (info)->sgot; |
4132 | 0 | srela = elf_hash_table (info)->srelgot; |
4133 | 0 | BFD_ASSERT (sgot != NULL && srela != NULL); |
4134 | |
|
4135 | 0 | got_entry = elf_m68k_hash_entry (h)->glist; |
4136 | |
|
4137 | 0 | while (got_entry != NULL) |
4138 | 0 | { |
4139 | 0 | enum elf_m68k_reloc_type r_type; |
4140 | 0 | bfd_vma got_entry_offset; |
4141 | |
|
4142 | 0 | r_type = got_entry->key_.type; |
4143 | 0 | got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1; |
4144 | | |
4145 | | /* If this is a -Bsymbolic link, and the symbol is defined |
4146 | | locally, we just want to emit a RELATIVE reloc. Likewise if |
4147 | | the symbol was forced to be local because of a version file. |
4148 | | The entry in the global offset table already have been |
4149 | | initialized in the relocate_section function. */ |
4150 | 0 | if (bfd_link_pic (info) |
4151 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
4152 | 0 | { |
4153 | 0 | bfd_vma relocation; |
4154 | |
|
4155 | 0 | relocation = bfd_get_signed_32 (output_bfd, |
4156 | 0 | (sgot->contents |
4157 | 0 | + got_entry_offset)); |
4158 | | |
4159 | | /* Undo TP bias. */ |
4160 | 0 | switch (elf_m68k_reloc_got_type (r_type)) |
4161 | 0 | { |
4162 | 0 | case R_68K_GOT32O: |
4163 | 0 | case R_68K_TLS_LDM32: |
4164 | 0 | break; |
4165 | | |
4166 | 0 | case R_68K_TLS_GD32: |
4167 | | /* The value for this relocation is actually put in |
4168 | | the second GOT slot. */ |
4169 | 0 | relocation = bfd_get_signed_32 (output_bfd, |
4170 | 0 | (sgot->contents |
4171 | 0 | + got_entry_offset + 4)); |
4172 | 0 | relocation += dtpoff_base (info); |
4173 | 0 | break; |
4174 | | |
4175 | 0 | case R_68K_TLS_IE32: |
4176 | 0 | relocation += tpoff_base (info); |
4177 | 0 | break; |
4178 | | |
4179 | 0 | default: |
4180 | 0 | BFD_ASSERT (false); |
4181 | 0 | } |
4182 | | |
4183 | 0 | elf_m68k_init_got_entry_local_shared (info, |
4184 | 0 | output_bfd, |
4185 | 0 | r_type, |
4186 | 0 | sgot, |
4187 | 0 | got_entry_offset, |
4188 | 0 | relocation, |
4189 | 0 | srela); |
4190 | 0 | } |
4191 | 0 | else |
4192 | 0 | { |
4193 | 0 | Elf_Internal_Rela rela; |
4194 | | |
4195 | | /* Put zeros to GOT slots that will be initialized |
4196 | | at run-time. */ |
4197 | 0 | { |
4198 | 0 | bfd_vma n_slots; |
4199 | |
|
4200 | 0 | n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type); |
4201 | 0 | while (n_slots--) |
4202 | 0 | bfd_put_32 (output_bfd, (bfd_vma) 0, |
4203 | 0 | (sgot->contents + got_entry_offset |
4204 | 0 | + 4 * n_slots)); |
4205 | 0 | } |
4206 | |
|
4207 | 0 | rela.r_addend = 0; |
4208 | 0 | rela.r_offset = (sgot->output_section->vma |
4209 | 0 | + sgot->output_offset |
4210 | 0 | + got_entry_offset); |
4211 | |
|
4212 | 0 | switch (elf_m68k_reloc_got_type (r_type)) |
4213 | 0 | { |
4214 | 0 | case R_68K_GOT32O: |
4215 | 0 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT); |
4216 | 0 | elf_m68k_install_rela (output_bfd, srela, &rela); |
4217 | 0 | break; |
4218 | | |
4219 | 0 | case R_68K_TLS_GD32: |
4220 | 0 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32); |
4221 | 0 | elf_m68k_install_rela (output_bfd, srela, &rela); |
4222 | |
|
4223 | 0 | rela.r_offset += 4; |
4224 | 0 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32); |
4225 | 0 | elf_m68k_install_rela (output_bfd, srela, &rela); |
4226 | 0 | break; |
4227 | | |
4228 | 0 | case R_68K_TLS_IE32: |
4229 | 0 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32); |
4230 | 0 | elf_m68k_install_rela (output_bfd, srela, &rela); |
4231 | 0 | break; |
4232 | | |
4233 | 0 | default: |
4234 | 0 | BFD_ASSERT (false); |
4235 | 0 | break; |
4236 | 0 | } |
4237 | 0 | } |
4238 | | |
4239 | 0 | got_entry = got_entry->u.s2.next; |
4240 | 0 | } |
4241 | 0 | } |
4242 | | |
4243 | 0 | if (h->needs_copy) |
4244 | 0 | { |
4245 | 0 | asection *s; |
4246 | 0 | Elf_Internal_Rela rela; |
4247 | 0 | bfd_byte *loc; |
4248 | | |
4249 | | /* This symbol needs a copy reloc. Set it up. */ |
4250 | |
|
4251 | 0 | BFD_ASSERT (h->dynindx != -1 |
4252 | 0 | && (h->root.type == bfd_link_hash_defined |
4253 | 0 | || h->root.type == bfd_link_hash_defweak)); |
4254 | |
|
4255 | 0 | s = bfd_get_linker_section (dynobj, ".rela.bss"); |
4256 | 0 | BFD_ASSERT (s != NULL); |
4257 | |
|
4258 | 0 | rela.r_offset = (h->root.u.def.value |
4259 | 0 | + h->root.u.def.section->output_section->vma |
4260 | 0 | + h->root.u.def.section->output_offset); |
4261 | 0 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY); |
4262 | 0 | rela.r_addend = 0; |
4263 | 0 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); |
4264 | 0 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
4265 | 0 | } |
4266 | |
|
4267 | 0 | return true; |
4268 | 0 | } |
4269 | | |
4270 | | /* Finish up the dynamic sections. */ |
4271 | | |
4272 | | static bool |
4273 | | elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) |
4274 | 0 | { |
4275 | 0 | bfd *dynobj; |
4276 | 0 | asection *sgot; |
4277 | 0 | asection *sdyn; |
4278 | |
|
4279 | 0 | dynobj = elf_hash_table (info)->dynobj; |
4280 | |
|
4281 | 0 | sgot = elf_hash_table (info)->sgotplt; |
4282 | 0 | BFD_ASSERT (sgot != NULL); |
4283 | 0 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
4284 | |
|
4285 | 0 | if (elf_hash_table (info)->dynamic_sections_created) |
4286 | 0 | { |
4287 | 0 | asection *splt; |
4288 | 0 | Elf32_External_Dyn *dyncon, *dynconend; |
4289 | |
|
4290 | 0 | splt = elf_hash_table (info)->splt; |
4291 | 0 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
4292 | |
|
4293 | 0 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
4294 | 0 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
4295 | 0 | for (; dyncon < dynconend; dyncon++) |
4296 | 0 | { |
4297 | 0 | Elf_Internal_Dyn dyn; |
4298 | 0 | asection *s; |
4299 | |
|
4300 | 0 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
4301 | |
|
4302 | 0 | switch (dyn.d_tag) |
4303 | 0 | { |
4304 | 0 | default: |
4305 | 0 | break; |
4306 | | |
4307 | 0 | case DT_PLTGOT: |
4308 | 0 | s = elf_hash_table (info)->sgotplt; |
4309 | 0 | goto get_vma; |
4310 | 0 | case DT_JMPREL: |
4311 | 0 | s = elf_hash_table (info)->srelplt; |
4312 | 0 | get_vma: |
4313 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
4314 | 0 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
4315 | 0 | break; |
4316 | | |
4317 | 0 | case DT_PLTRELSZ: |
4318 | 0 | s = elf_hash_table (info)->srelplt; |
4319 | 0 | dyn.d_un.d_val = s->size; |
4320 | 0 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
4321 | 0 | break; |
4322 | 0 | } |
4323 | 0 | } |
4324 | | |
4325 | | /* Fill in the first entry in the procedure linkage table. */ |
4326 | 0 | if (splt->size > 0) |
4327 | 0 | { |
4328 | 0 | const struct elf_m68k_plt_info *plt_info; |
4329 | |
|
4330 | 0 | plt_info = elf_m68k_hash_table (info)->plt_info; |
4331 | 0 | memcpy (splt->contents, plt_info->plt0_entry, plt_info->size); |
4332 | |
|
4333 | 0 | elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4, |
4334 | 0 | (sgot->output_section->vma |
4335 | 0 | + sgot->output_offset |
4336 | 0 | + 4)); |
4337 | |
|
4338 | 0 | elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8, |
4339 | 0 | (sgot->output_section->vma |
4340 | 0 | + sgot->output_offset |
4341 | 0 | + 8)); |
4342 | |
|
4343 | 0 | elf_section_data (splt->output_section)->this_hdr.sh_entsize |
4344 | 0 | = plt_info->size; |
4345 | 0 | } |
4346 | 0 | } |
4347 | | |
4348 | | /* Fill in the first three entries in the global offset table. */ |
4349 | 0 | if (sgot->size > 0) |
4350 | 0 | { |
4351 | 0 | if (sdyn == NULL) |
4352 | 0 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); |
4353 | 0 | else |
4354 | 0 | bfd_put_32 (output_bfd, |
4355 | 0 | sdyn->output_section->vma + sdyn->output_offset, |
4356 | 0 | sgot->contents); |
4357 | 0 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); |
4358 | 0 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); |
4359 | 0 | } |
4360 | |
|
4361 | 0 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
4362 | |
|
4363 | 0 | return true; |
4364 | 0 | } |
4365 | | |
4366 | | /* Given a .data section and a .emreloc in-memory section, store |
4367 | | relocation information into the .emreloc section which can be |
4368 | | used at runtime to relocate the section. This is called by the |
4369 | | linker when the --embedded-relocs switch is used. This is called |
4370 | | after the add_symbols entry point has been called for all the |
4371 | | objects, and before the final_link entry point is called. */ |
4372 | | |
4373 | | bool |
4374 | | bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info, |
4375 | | asection *datasec, asection *relsec, |
4376 | | char **errmsg) |
4377 | 0 | { |
4378 | 0 | Elf_Internal_Shdr *symtab_hdr; |
4379 | 0 | Elf_Internal_Sym *isymbuf = NULL; |
4380 | 0 | Elf_Internal_Rela *internal_relocs = NULL; |
4381 | 0 | Elf_Internal_Rela *irel, *irelend; |
4382 | 0 | bfd_byte *p; |
4383 | 0 | bfd_size_type amt; |
4384 | |
|
4385 | 0 | BFD_ASSERT (! bfd_link_relocatable (info)); |
4386 | |
|
4387 | 0 | *errmsg = NULL; |
4388 | |
|
4389 | 0 | if (datasec->reloc_count == 0) |
4390 | 0 | return true; |
4391 | | |
4392 | 0 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4393 | | |
4394 | | /* Get a copy of the native relocations. */ |
4395 | 0 | internal_relocs = (_bfd_elf_link_read_relocs |
4396 | 0 | (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL, |
4397 | 0 | info->keep_memory)); |
4398 | 0 | if (internal_relocs == NULL) |
4399 | 0 | goto error_return; |
4400 | | |
4401 | 0 | amt = (bfd_size_type) datasec->reloc_count * 12; |
4402 | 0 | relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt); |
4403 | 0 | if (relsec->contents == NULL) |
4404 | 0 | goto error_return; |
4405 | 0 | relsec->alloced = 1; |
4406 | |
|
4407 | 0 | p = relsec->contents; |
4408 | |
|
4409 | 0 | irelend = internal_relocs + datasec->reloc_count; |
4410 | 0 | for (irel = internal_relocs; irel < irelend; irel++, p += 12) |
4411 | 0 | { |
4412 | 0 | asection *targetsec; |
4413 | | |
4414 | | /* We are going to write a four byte longword into the runtime |
4415 | | reloc section. The longword will be the address in the data |
4416 | | section which must be relocated. It is followed by the name |
4417 | | of the target section NUL-padded or truncated to 8 |
4418 | | characters. */ |
4419 | | |
4420 | | /* We can only relocate absolute longword relocs at run time. */ |
4421 | 0 | if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32) |
4422 | 0 | { |
4423 | 0 | *errmsg = _("unsupported relocation type"); |
4424 | 0 | bfd_set_error (bfd_error_bad_value); |
4425 | 0 | goto error_return; |
4426 | 0 | } |
4427 | | |
4428 | | /* Get the target section referred to by the reloc. */ |
4429 | 0 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
4430 | 0 | { |
4431 | | /* A local symbol. */ |
4432 | 0 | Elf_Internal_Sym *isym; |
4433 | | |
4434 | | /* Read this BFD's local symbols if we haven't done so already. */ |
4435 | 0 | if (isymbuf == NULL) |
4436 | 0 | { |
4437 | 0 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
4438 | 0 | if (isymbuf == NULL) |
4439 | 0 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, |
4440 | 0 | symtab_hdr->sh_info, 0, |
4441 | 0 | NULL, NULL, NULL); |
4442 | 0 | if (isymbuf == NULL) |
4443 | 0 | goto error_return; |
4444 | 0 | } |
4445 | | |
4446 | 0 | isym = isymbuf + ELF32_R_SYM (irel->r_info); |
4447 | 0 | targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
4448 | 0 | } |
4449 | 0 | else |
4450 | 0 | { |
4451 | 0 | unsigned long indx; |
4452 | 0 | struct elf_link_hash_entry *h; |
4453 | | |
4454 | | /* An external symbol. */ |
4455 | 0 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
4456 | 0 | h = elf_sym_hashes (abfd)[indx]; |
4457 | 0 | BFD_ASSERT (h != NULL); |
4458 | 0 | if (h->root.type == bfd_link_hash_defined |
4459 | 0 | || h->root.type == bfd_link_hash_defweak) |
4460 | 0 | targetsec = h->root.u.def.section; |
4461 | 0 | else |
4462 | 0 | targetsec = NULL; |
4463 | 0 | } |
4464 | | |
4465 | 0 | bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p); |
4466 | 0 | memset (p + 4, 0, 8); |
4467 | 0 | if (targetsec != NULL) |
4468 | 0 | strncpy ((char *) p + 4, targetsec->output_section->name, 8); |
4469 | 0 | } |
4470 | | |
4471 | 0 | if (symtab_hdr->contents != (unsigned char *) isymbuf) |
4472 | 0 | free (isymbuf); |
4473 | 0 | if (elf_section_data (datasec)->relocs != internal_relocs) |
4474 | 0 | free (internal_relocs); |
4475 | 0 | return true; |
4476 | | |
4477 | 0 | error_return: |
4478 | 0 | if (symtab_hdr->contents != (unsigned char *) isymbuf) |
4479 | 0 | free (isymbuf); |
4480 | 0 | if (elf_section_data (datasec)->relocs != internal_relocs) |
4481 | 0 | free (internal_relocs); |
4482 | 0 | return false; |
4483 | 0 | } |
4484 | | |
4485 | | /* Set target options. */ |
4486 | | |
4487 | | void |
4488 | | bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling) |
4489 | 0 | { |
4490 | 0 | struct elf_m68k_link_hash_table *htab; |
4491 | 0 | bool use_neg_got_offsets_p; |
4492 | 0 | bool allow_multigot_p; |
4493 | 0 | bool local_gp_p; |
4494 | |
|
4495 | 0 | switch (got_handling) |
4496 | 0 | { |
4497 | 0 | case 0: |
4498 | | /* --got=single. */ |
4499 | 0 | local_gp_p = false; |
4500 | 0 | use_neg_got_offsets_p = false; |
4501 | 0 | allow_multigot_p = false; |
4502 | 0 | break; |
4503 | | |
4504 | 0 | case 1: |
4505 | | /* --got=negative. */ |
4506 | 0 | local_gp_p = true; |
4507 | 0 | use_neg_got_offsets_p = true; |
4508 | 0 | allow_multigot_p = false; |
4509 | 0 | break; |
4510 | | |
4511 | 0 | case 2: |
4512 | | /* --got=multigot. */ |
4513 | 0 | local_gp_p = true; |
4514 | 0 | use_neg_got_offsets_p = true; |
4515 | 0 | allow_multigot_p = true; |
4516 | 0 | break; |
4517 | | |
4518 | 0 | default: |
4519 | 0 | BFD_ASSERT (false); |
4520 | 0 | return; |
4521 | 0 | } |
4522 | | |
4523 | 0 | htab = elf_m68k_hash_table (info); |
4524 | 0 | if (htab != NULL) |
4525 | 0 | { |
4526 | 0 | htab->local_gp_p = local_gp_p; |
4527 | 0 | htab->use_neg_got_offsets_p = use_neg_got_offsets_p; |
4528 | 0 | htab->allow_multigot_p = allow_multigot_p; |
4529 | 0 | } |
4530 | 0 | } |
4531 | | |
4532 | | static enum elf_reloc_type_class |
4533 | | elf32_m68k_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
4534 | | const asection *rel_sec ATTRIBUTE_UNUSED, |
4535 | | const Elf_Internal_Rela *rela) |
4536 | 0 | { |
4537 | 0 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
4538 | 0 | { |
4539 | 0 | case R_68K_RELATIVE: |
4540 | 0 | return reloc_class_relative; |
4541 | 0 | case R_68K_JMP_SLOT: |
4542 | 0 | return reloc_class_plt; |
4543 | 0 | case R_68K_COPY: |
4544 | 0 | return reloc_class_copy; |
4545 | 0 | default: |
4546 | 0 | return reloc_class_normal; |
4547 | 0 | } |
4548 | 0 | } |
4549 | | |
4550 | | /* Return address for Ith PLT stub in section PLT, for relocation REL |
4551 | | or (bfd_vma) -1 if it should not be included. */ |
4552 | | |
4553 | | static bfd_vma |
4554 | | elf_m68k_plt_sym_val (bfd_vma i, const asection *plt, |
4555 | | const arelent *rel ATTRIBUTE_UNUSED) |
4556 | 0 | { |
4557 | 0 | return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size; |
4558 | 0 | } |
4559 | | |
4560 | | /* Support for core dump NOTE sections. */ |
4561 | | |
4562 | | static bool |
4563 | | elf_m68k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
4564 | 27 | { |
4565 | 27 | int offset; |
4566 | 27 | size_t size; |
4567 | | |
4568 | 27 | switch (note->descsz) |
4569 | 27 | { |
4570 | 20 | default: |
4571 | 20 | return false; |
4572 | | |
4573 | 7 | case 154: /* Linux/m68k */ |
4574 | | /* pr_cursig */ |
4575 | 7 | elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); |
4576 | | |
4577 | | /* pr_pid */ |
4578 | 7 | elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22); |
4579 | | |
4580 | | /* pr_reg */ |
4581 | 7 | offset = 70; |
4582 | 7 | size = 80; |
4583 | | |
4584 | 7 | break; |
4585 | 27 | } |
4586 | | |
4587 | | /* Make a ".reg/999" section. */ |
4588 | 7 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", |
4589 | 7 | size, note->descpos + offset); |
4590 | 27 | } |
4591 | | |
4592 | | static bool |
4593 | | elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
4594 | 10 | { |
4595 | 10 | switch (note->descsz) |
4596 | 10 | { |
4597 | 10 | default: |
4598 | 10 | return false; |
4599 | | |
4600 | 0 | case 124: /* Linux/m68k elf_prpsinfo. */ |
4601 | 0 | elf_tdata (abfd)->core->pid |
4602 | 0 | = bfd_get_32 (abfd, note->descdata + 12); |
4603 | 0 | elf_tdata (abfd)->core->program |
4604 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); |
4605 | 0 | elf_tdata (abfd)->core->command |
4606 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); |
4607 | 10 | } |
4608 | | |
4609 | | /* Note that for some reason, a spurious space is tacked |
4610 | | onto the end of the args in some (at least one anyway) |
4611 | | implementations, so strip it off if it exists. */ |
4612 | 0 | { |
4613 | 0 | char *command = elf_tdata (abfd)->core->command; |
4614 | 0 | int n = strlen (command); |
4615 | |
|
4616 | 0 | if (n > 0 && command[n - 1] == ' ') |
4617 | 0 | command[n - 1] = '\0'; |
4618 | 0 | } |
4619 | |
|
4620 | 0 | return true; |
4621 | 10 | } |
4622 | | |
4623 | | #define TARGET_BIG_SYM m68k_elf32_vec |
4624 | | #define TARGET_BIG_NAME "elf32-m68k" |
4625 | | #define ELF_MACHINE_CODE EM_68K |
4626 | | #define ELF_MAXPAGESIZE 0x2000 |
4627 | | #define elf_backend_create_dynamic_sections \ |
4628 | | _bfd_elf_create_dynamic_sections |
4629 | | #define bfd_elf32_bfd_link_hash_table_create \ |
4630 | | elf_m68k_link_hash_table_create |
4631 | | #define bfd_elf32_bfd_final_link bfd_elf_final_link |
4632 | | |
4633 | | #define elf_backend_check_relocs elf_m68k_check_relocs |
4634 | | #define elf_backend_early_size_sections \ |
4635 | | elf_m68k_early_size_sections |
4636 | | #define elf_backend_adjust_dynamic_symbol \ |
4637 | | elf_m68k_adjust_dynamic_symbol |
4638 | | #define elf_backend_late_size_sections elf_m68k_late_size_sections |
4639 | | #define elf_backend_final_write_processing elf_m68k_final_write_processing |
4640 | | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
4641 | | #define elf_backend_relocate_section elf_m68k_relocate_section |
4642 | | #define elf_backend_finish_dynamic_symbol \ |
4643 | | elf_m68k_finish_dynamic_symbol |
4644 | | #define elf_backend_finish_dynamic_sections \ |
4645 | | elf_m68k_finish_dynamic_sections |
4646 | | #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook |
4647 | | #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol |
4648 | | #define bfd_elf32_bfd_merge_private_bfd_data \ |
4649 | | elf32_m68k_merge_private_bfd_data |
4650 | | #define bfd_elf32_bfd_set_private_flags \ |
4651 | | elf32_m68k_set_private_flags |
4652 | | #define bfd_elf32_bfd_print_private_bfd_data \ |
4653 | | elf32_m68k_print_private_bfd_data |
4654 | | #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class |
4655 | | #define elf_backend_plt_sym_val elf_m68k_plt_sym_val |
4656 | | #define elf_backend_object_p elf32_m68k_object_p |
4657 | | #define elf_backend_grok_prstatus elf_m68k_grok_prstatus |
4658 | | #define elf_backend_grok_psinfo elf_m68k_grok_psinfo |
4659 | | |
4660 | | #define elf_backend_can_gc_sections 1 |
4661 | | #define elf_backend_can_refcount 1 |
4662 | | #define elf_backend_want_got_plt 1 |
4663 | | #define elf_backend_plt_readonly 1 |
4664 | | #define elf_backend_want_plt_sym 0 |
4665 | | #define elf_backend_got_header_size 12 |
4666 | | #define elf_backend_rela_normal 1 |
4667 | | #define elf_backend_dtrel_excludes_plt 1 |
4668 | | |
4669 | | #define elf_backend_linux_prpsinfo32_ugid16 true |
4670 | | |
4671 | | #include "elf32-target.h" |