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