2009-07-02 Tristan Gingold <gingold@adacore.com>
[binutils.git] / bfd / elf32-m68k.c
blob2957db0740bb1a36fa42131da585b752af346bdf
1 /* Motorola 68k series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "bfdlink.h"
25 #include "libbfd.h"
26 #include "elf-bfd.h"
27 #include "elf/m68k.h"
28 #include "opcode/m68k.h"
30 static reloc_howto_type *reloc_type_lookup
31 PARAMS ((bfd *, bfd_reloc_code_real_type));
32 static void rtype_to_howto
33 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
34 static struct bfd_hash_entry *elf_m68k_link_hash_newfunc
35 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
36 static struct bfd_link_hash_table *elf_m68k_link_hash_table_create
37 PARAMS ((bfd *));
38 static bfd_boolean elf_m68k_check_relocs
39 PARAMS ((bfd *, struct bfd_link_info *, asection *,
40 const Elf_Internal_Rela *));
41 static bfd_boolean elf_m68k_adjust_dynamic_symbol
42 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
43 static bfd_boolean elf_m68k_size_dynamic_sections
44 PARAMS ((bfd *, struct bfd_link_info *));
45 static bfd_boolean elf_m68k_discard_copies
46 PARAMS ((struct elf_link_hash_entry *, PTR));
47 static bfd_boolean elf_m68k_relocate_section
48 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
49 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
50 static bfd_boolean elf_m68k_finish_dynamic_symbol
51 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
52 Elf_Internal_Sym *));
53 static bfd_boolean elf_m68k_finish_dynamic_sections
54 PARAMS ((bfd *, struct bfd_link_info *));
56 static bfd_boolean elf32_m68k_set_private_flags
57 PARAMS ((bfd *, flagword));
58 static bfd_boolean elf32_m68k_merge_private_bfd_data
59 PARAMS ((bfd *, bfd *));
60 static bfd_boolean elf32_m68k_print_private_bfd_data
61 PARAMS ((bfd *, PTR));
62 static enum elf_reloc_type_class elf32_m68k_reloc_type_class
63 PARAMS ((const Elf_Internal_Rela *));
65 static reloc_howto_type howto_table[] = {
66 HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE),
67 HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE),
68 HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE),
69 HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE),
70 HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE),
71 HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE),
72 HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE),
73 HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE),
74 HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE),
75 HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE),
76 HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE),
77 HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE),
78 HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE),
79 HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE),
80 HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE),
81 HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE),
82 HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE),
83 HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE),
84 HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE),
85 HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE),
86 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),
87 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),
88 HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE),
89 /* GNU extension to record C++ vtable hierarchy. */
90 HOWTO (R_68K_GNU_VTINHERIT, /* type */
91 0, /* rightshift */
92 2, /* size (0 = byte, 1 = short, 2 = long) */
93 0, /* bitsize */
94 FALSE, /* pc_relative */
95 0, /* bitpos */
96 complain_overflow_dont, /* complain_on_overflow */
97 NULL, /* special_function */
98 "R_68K_GNU_VTINHERIT", /* name */
99 FALSE, /* partial_inplace */
100 0, /* src_mask */
101 0, /* dst_mask */
102 FALSE),
103 /* GNU extension to record C++ vtable member usage. */
104 HOWTO (R_68K_GNU_VTENTRY, /* type */
105 0, /* rightshift */
106 2, /* size (0 = byte, 1 = short, 2 = long) */
107 0, /* bitsize */
108 FALSE, /* pc_relative */
109 0, /* bitpos */
110 complain_overflow_dont, /* complain_on_overflow */
111 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
112 "R_68K_GNU_VTENTRY", /* name */
113 FALSE, /* partial_inplace */
114 0, /* src_mask */
115 0, /* dst_mask */
116 FALSE),
118 /* TLS general dynamic variable reference. */
119 HOWTO (R_68K_TLS_GD32, /* type */
120 0, /* rightshift */
121 2, /* size (0 = byte, 1 = short, 2 = long) */
122 32, /* bitsize */
123 FALSE, /* pc_relative */
124 0, /* bitpos */
125 complain_overflow_bitfield, /* complain_on_overflow */
126 bfd_elf_generic_reloc, /* special_function */
127 "R_68K_TLS_GD32", /* name */
128 FALSE, /* partial_inplace */
129 0, /* src_mask */
130 0xffffffff, /* dst_mask */
131 FALSE), /* pcrel_offset */
133 HOWTO (R_68K_TLS_GD16, /* type */
134 0, /* rightshift */
135 1, /* size (0 = byte, 1 = short, 2 = long) */
136 16, /* bitsize */
137 FALSE, /* pc_relative */
138 0, /* bitpos */
139 complain_overflow_signed, /* complain_on_overflow */
140 bfd_elf_generic_reloc, /* special_function */
141 "R_68K_TLS_GD16", /* name */
142 FALSE, /* partial_inplace */
143 0, /* src_mask */
144 0x0000ffff, /* dst_mask */
145 FALSE), /* pcrel_offset */
147 HOWTO (R_68K_TLS_GD8, /* type */
148 0, /* rightshift */
149 0, /* size (0 = byte, 1 = short, 2 = long) */
150 8, /* bitsize */
151 FALSE, /* pc_relative */
152 0, /* bitpos */
153 complain_overflow_signed, /* complain_on_overflow */
154 bfd_elf_generic_reloc, /* special_function */
155 "R_68K_TLS_GD8", /* name */
156 FALSE, /* partial_inplace */
157 0, /* src_mask */
158 0x000000ff, /* dst_mask */
159 FALSE), /* pcrel_offset */
161 /* TLS local dynamic variable reference. */
162 HOWTO (R_68K_TLS_LDM32, /* type */
163 0, /* rightshift */
164 2, /* size (0 = byte, 1 = short, 2 = long) */
165 32, /* bitsize */
166 FALSE, /* pc_relative */
167 0, /* bitpos */
168 complain_overflow_bitfield, /* complain_on_overflow */
169 bfd_elf_generic_reloc, /* special_function */
170 "R_68K_TLS_LDM32", /* name */
171 FALSE, /* partial_inplace */
172 0, /* src_mask */
173 0xffffffff, /* dst_mask */
174 FALSE), /* pcrel_offset */
176 HOWTO (R_68K_TLS_LDM16, /* type */
177 0, /* rightshift */
178 1, /* size (0 = byte, 1 = short, 2 = long) */
179 16, /* bitsize */
180 FALSE, /* pc_relative */
181 0, /* bitpos */
182 complain_overflow_signed, /* complain_on_overflow */
183 bfd_elf_generic_reloc, /* special_function */
184 "R_68K_TLS_LDM16", /* name */
185 FALSE, /* partial_inplace */
186 0, /* src_mask */
187 0x0000ffff, /* dst_mask */
188 FALSE), /* pcrel_offset */
190 HOWTO (R_68K_TLS_LDM8, /* type */
191 0, /* rightshift */
192 0, /* size (0 = byte, 1 = short, 2 = long) */
193 8, /* bitsize */
194 FALSE, /* pc_relative */
195 0, /* bitpos */
196 complain_overflow_signed, /* complain_on_overflow */
197 bfd_elf_generic_reloc, /* special_function */
198 "R_68K_TLS_LDM8", /* name */
199 FALSE, /* partial_inplace */
200 0, /* src_mask */
201 0x000000ff, /* dst_mask */
202 FALSE), /* pcrel_offset */
204 HOWTO (R_68K_TLS_LDO32, /* type */
205 0, /* rightshift */
206 2, /* size (0 = byte, 1 = short, 2 = long) */
207 32, /* bitsize */
208 FALSE, /* pc_relative */
209 0, /* bitpos */
210 complain_overflow_bitfield, /* complain_on_overflow */
211 bfd_elf_generic_reloc, /* special_function */
212 "R_68K_TLS_LDO32", /* name */
213 FALSE, /* partial_inplace */
214 0, /* src_mask */
215 0xffffffff, /* dst_mask */
216 FALSE), /* pcrel_offset */
218 HOWTO (R_68K_TLS_LDO16, /* type */
219 0, /* rightshift */
220 1, /* size (0 = byte, 1 = short, 2 = long) */
221 16, /* bitsize */
222 FALSE, /* pc_relative */
223 0, /* bitpos */
224 complain_overflow_signed, /* complain_on_overflow */
225 bfd_elf_generic_reloc, /* special_function */
226 "R_68K_TLS_LDO16", /* name */
227 FALSE, /* partial_inplace */
228 0, /* src_mask */
229 0x0000ffff, /* dst_mask */
230 FALSE), /* pcrel_offset */
232 HOWTO (R_68K_TLS_LDO8, /* type */
233 0, /* rightshift */
234 0, /* size (0 = byte, 1 = short, 2 = long) */
235 8, /* bitsize */
236 FALSE, /* pc_relative */
237 0, /* bitpos */
238 complain_overflow_signed, /* complain_on_overflow */
239 bfd_elf_generic_reloc, /* special_function */
240 "R_68K_TLS_LDO8", /* name */
241 FALSE, /* partial_inplace */
242 0, /* src_mask */
243 0x000000ff, /* dst_mask */
244 FALSE), /* pcrel_offset */
246 /* TLS initial execution variable reference. */
247 HOWTO (R_68K_TLS_IE32, /* type */
248 0, /* rightshift */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
250 32, /* bitsize */
251 FALSE, /* pc_relative */
252 0, /* bitpos */
253 complain_overflow_bitfield, /* complain_on_overflow */
254 bfd_elf_generic_reloc, /* special_function */
255 "R_68K_TLS_IE32", /* name */
256 FALSE, /* partial_inplace */
257 0, /* src_mask */
258 0xffffffff, /* dst_mask */
259 FALSE), /* pcrel_offset */
261 HOWTO (R_68K_TLS_IE16, /* type */
262 0, /* rightshift */
263 1, /* size (0 = byte, 1 = short, 2 = long) */
264 16, /* bitsize */
265 FALSE, /* pc_relative */
266 0, /* bitpos */
267 complain_overflow_signed, /* complain_on_overflow */
268 bfd_elf_generic_reloc, /* special_function */
269 "R_68K_TLS_IE16", /* name */
270 FALSE, /* partial_inplace */
271 0, /* src_mask */
272 0x0000ffff, /* dst_mask */
273 FALSE), /* pcrel_offset */
275 HOWTO (R_68K_TLS_IE8, /* type */
276 0, /* rightshift */
277 0, /* size (0 = byte, 1 = short, 2 = long) */
278 8, /* bitsize */
279 FALSE, /* pc_relative */
280 0, /* bitpos */
281 complain_overflow_signed, /* complain_on_overflow */
282 bfd_elf_generic_reloc, /* special_function */
283 "R_68K_TLS_IE8", /* name */
284 FALSE, /* partial_inplace */
285 0, /* src_mask */
286 0x000000ff, /* dst_mask */
287 FALSE), /* pcrel_offset */
289 /* TLS local execution variable reference. */
290 HOWTO (R_68K_TLS_LE32, /* type */
291 0, /* rightshift */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
293 32, /* bitsize */
294 FALSE, /* pc_relative */
295 0, /* bitpos */
296 complain_overflow_bitfield, /* complain_on_overflow */
297 bfd_elf_generic_reloc, /* special_function */
298 "R_68K_TLS_LE32", /* name */
299 FALSE, /* partial_inplace */
300 0, /* src_mask */
301 0xffffffff, /* dst_mask */
302 FALSE), /* pcrel_offset */
304 HOWTO (R_68K_TLS_LE16, /* type */
305 0, /* rightshift */
306 1, /* size (0 = byte, 1 = short, 2 = long) */
307 16, /* bitsize */
308 FALSE, /* pc_relative */
309 0, /* bitpos */
310 complain_overflow_signed, /* complain_on_overflow */
311 bfd_elf_generic_reloc, /* special_function */
312 "R_68K_TLS_LE16", /* name */
313 FALSE, /* partial_inplace */
314 0, /* src_mask */
315 0x0000ffff, /* dst_mask */
316 FALSE), /* pcrel_offset */
318 HOWTO (R_68K_TLS_LE8, /* type */
319 0, /* rightshift */
320 0, /* size (0 = byte, 1 = short, 2 = long) */
321 8, /* bitsize */
322 FALSE, /* pc_relative */
323 0, /* bitpos */
324 complain_overflow_signed, /* complain_on_overflow */
325 bfd_elf_generic_reloc, /* special_function */
326 "R_68K_TLS_LE8", /* name */
327 FALSE, /* partial_inplace */
328 0, /* src_mask */
329 0x000000ff, /* dst_mask */
330 FALSE), /* pcrel_offset */
332 /* TLS GD/LD dynamic relocations. */
333 HOWTO (R_68K_TLS_DTPMOD32, /* type */
334 0, /* rightshift */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
336 32, /* bitsize */
337 FALSE, /* pc_relative */
338 0, /* bitpos */
339 complain_overflow_dont, /* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_68K_TLS_DTPMOD32", /* name */
342 FALSE, /* partial_inplace */
343 0, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE), /* pcrel_offset */
347 HOWTO (R_68K_TLS_DTPREL32, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 32, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_dont, /* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 "R_68K_TLS_DTPREL32", /* name */
356 FALSE, /* partial_inplace */
357 0, /* src_mask */
358 0xffffffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
361 HOWTO (R_68K_TLS_TPREL32, /* type */
362 0, /* rightshift */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
364 32, /* bitsize */
365 FALSE, /* pc_relative */
366 0, /* bitpos */
367 complain_overflow_dont, /* complain_on_overflow */
368 bfd_elf_generic_reloc, /* special_function */
369 "R_68K_TLS_TPREL32", /* name */
370 FALSE, /* partial_inplace */
371 0, /* src_mask */
372 0xffffffff, /* dst_mask */
373 FALSE), /* pcrel_offset */
376 static void
377 rtype_to_howto (abfd, cache_ptr, dst)
378 bfd *abfd ATTRIBUTE_UNUSED;
379 arelent *cache_ptr;
380 Elf_Internal_Rela *dst;
382 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K_max);
383 cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
386 #define elf_info_to_howto rtype_to_howto
388 static const struct
390 bfd_reloc_code_real_type bfd_val;
391 int elf_val;
393 reloc_map[] =
395 { BFD_RELOC_NONE, R_68K_NONE },
396 { BFD_RELOC_32, R_68K_32 },
397 { BFD_RELOC_16, R_68K_16 },
398 { BFD_RELOC_8, R_68K_8 },
399 { BFD_RELOC_32_PCREL, R_68K_PC32 },
400 { BFD_RELOC_16_PCREL, R_68K_PC16 },
401 { BFD_RELOC_8_PCREL, R_68K_PC8 },
402 { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
403 { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
404 { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
405 { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
406 { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
407 { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
408 { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
409 { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
410 { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
411 { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
412 { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
413 { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
414 { BFD_RELOC_NONE, R_68K_COPY },
415 { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
416 { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
417 { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
418 { BFD_RELOC_CTOR, R_68K_32 },
419 { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
420 { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
421 { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 },
422 { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 },
423 { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 },
424 { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 },
425 { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 },
426 { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 },
427 { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 },
428 { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 },
429 { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 },
430 { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 },
431 { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 },
432 { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 },
433 { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 },
434 { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 },
435 { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 },
438 static reloc_howto_type *
439 reloc_type_lookup (abfd, code)
440 bfd *abfd ATTRIBUTE_UNUSED;
441 bfd_reloc_code_real_type code;
443 unsigned int i;
444 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
446 if (reloc_map[i].bfd_val == code)
447 return &howto_table[reloc_map[i].elf_val];
449 return 0;
452 static reloc_howto_type *
453 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
455 unsigned int i;
457 for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
458 if (howto_table[i].name != NULL
459 && strcasecmp (howto_table[i].name, r_name) == 0)
460 return &howto_table[i];
462 return NULL;
465 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
466 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
467 #define ELF_ARCH bfd_arch_m68k
469 /* Functions for the m68k ELF linker. */
471 /* The name of the dynamic interpreter. This is put in the .interp
472 section. */
474 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
476 /* Describes one of the various PLT styles. */
478 struct elf_m68k_plt_info
480 /* The size of each PLT entry. */
481 bfd_vma size;
483 /* The template for the first PLT entry. */
484 const bfd_byte *plt0_entry;
486 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
487 The comments by each member indicate the value that the relocation
488 is against. */
489 struct {
490 unsigned int got4; /* .got + 4 */
491 unsigned int got8; /* .got + 8 */
492 } plt0_relocs;
494 /* The template for a symbol's PLT entry. */
495 const bfd_byte *symbol_entry;
497 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
498 The comments by each member indicate the value that the relocation
499 is against. */
500 struct {
501 unsigned int got; /* the symbol's .got.plt entry */
502 unsigned int plt; /* .plt */
503 } symbol_relocs;
505 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
506 The stub starts with "move.l #relocoffset,%d0". */
507 bfd_vma symbol_resolve_entry;
510 /* The size in bytes of an entry in the procedure linkage table. */
512 #define PLT_ENTRY_SIZE 20
514 /* The first entry in a procedure linkage table looks like this. See
515 the SVR4 ABI m68k supplement to see how this works. */
517 static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
519 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
520 0, 0, 0, 2, /* + (.got + 4) - . */
521 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
522 0, 0, 0, 2, /* + (.got + 8) - . */
523 0, 0, 0, 0 /* pad out to 20 bytes. */
526 /* Subsequent entries in a procedure linkage table look like this. */
528 static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
530 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
531 0, 0, 0, 2, /* + (.got.plt entry) - . */
532 0x2f, 0x3c, /* move.l #offset,-(%sp) */
533 0, 0, 0, 0, /* + reloc index */
534 0x60, 0xff, /* bra.l .plt */
535 0, 0, 0, 0 /* + .plt - . */
538 static const struct elf_m68k_plt_info elf_m68k_plt_info = {
539 PLT_ENTRY_SIZE,
540 elf_m68k_plt0_entry, { 4, 12 },
541 elf_m68k_plt_entry, { 4, 16 }, 8
544 #define ISAB_PLT_ENTRY_SIZE 24
546 static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
548 0x20, 0x3c, /* move.l #offset,%d0 */
549 0, 0, 0, 0, /* + (.got + 4) - . */
550 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
551 0x20, 0x3c, /* move.l #offset,%d0 */
552 0, 0, 0, 0, /* + (.got + 8) - . */
553 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
554 0x4e, 0xd0, /* jmp (%a0) */
555 0x4e, 0x71 /* nop */
558 /* Subsequent entries in a procedure linkage table look like this. */
560 static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
562 0x20, 0x3c, /* move.l #offset,%d0 */
563 0, 0, 0, 0, /* + (.got.plt entry) - . */
564 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
565 0x4e, 0xd0, /* jmp (%a0) */
566 0x2f, 0x3c, /* move.l #offset,-(%sp) */
567 0, 0, 0, 0, /* + reloc index */
568 0x60, 0xff, /* bra.l .plt */
569 0, 0, 0, 0 /* + .plt - . */
572 static const struct elf_m68k_plt_info elf_isab_plt_info = {
573 ISAB_PLT_ENTRY_SIZE,
574 elf_isab_plt0_entry, { 2, 12 },
575 elf_isab_plt_entry, { 2, 20 }, 12
578 #define ISAC_PLT_ENTRY_SIZE 24
580 static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
582 0x20, 0x3c, /* move.l #offset,%d0 */
583 0, 0, 0, 0, /* replaced with .got + 4 - . */
584 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
585 0x20, 0x3c, /* move.l #offset,%d0 */
586 0, 0, 0, 0, /* replaced with .got + 8 - . */
587 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
588 0x4e, 0xd0, /* jmp (%a0) */
589 0x4e, 0x71 /* nop */
592 /* Subsequent entries in a procedure linkage table look like this. */
594 static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
596 0x20, 0x3c, /* move.l #offset,%d0 */
597 0, 0, 0, 0, /* replaced with (.got entry) - . */
598 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
599 0x4e, 0xd0, /* jmp (%a0) */
600 0x2f, 0x3c, /* move.l #offset,-(%sp) */
601 0, 0, 0, 0, /* replaced with offset into relocation table */
602 0x61, 0xff, /* bsr.l .plt */
603 0, 0, 0, 0 /* replaced with .plt - . */
606 static const struct elf_m68k_plt_info elf_isac_plt_info = {
607 ISAC_PLT_ENTRY_SIZE,
608 elf_isac_plt0_entry, { 2, 12},
609 elf_isac_plt_entry, { 2, 20 }, 12
612 #define CPU32_PLT_ENTRY_SIZE 24
613 /* Procedure linkage table entries for the cpu32 */
614 static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
616 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
617 0, 0, 0, 2, /* + (.got + 4) - . */
618 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
619 0, 0, 0, 2, /* + (.got + 8) - . */
620 0x4e, 0xd1, /* jmp %a1@ */
621 0, 0, 0, 0, /* pad out to 24 bytes. */
622 0, 0
625 static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
627 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
628 0, 0, 0, 2, /* + (.got.plt entry) - . */
629 0x4e, 0xd1, /* jmp %a1@ */
630 0x2f, 0x3c, /* move.l #offset,-(%sp) */
631 0, 0, 0, 0, /* + reloc index */
632 0x60, 0xff, /* bra.l .plt */
633 0, 0, 0, 0, /* + .plt - . */
634 0, 0
637 static const struct elf_m68k_plt_info elf_cpu32_plt_info = {
638 CPU32_PLT_ENTRY_SIZE,
639 elf_cpu32_plt0_entry, { 4, 12 },
640 elf_cpu32_plt_entry, { 4, 18 }, 10
643 /* The m68k linker needs to keep track of the number of relocs that it
644 decides to copy in check_relocs for each symbol. This is so that it
645 can discard PC relative relocs if it doesn't need them when linking
646 with -Bsymbolic. We store the information in a field extending the
647 regular ELF linker hash table. */
649 /* This structure keeps track of the number of PC relative relocs we have
650 copied for a given symbol. */
652 struct elf_m68k_pcrel_relocs_copied
654 /* Next section. */
655 struct elf_m68k_pcrel_relocs_copied *next;
656 /* A section in dynobj. */
657 asection *section;
658 /* Number of relocs copied in this section. */
659 bfd_size_type count;
662 /* Forward declaration. */
663 struct elf_m68k_got_entry;
665 /* m68k ELF linker hash entry. */
667 struct elf_m68k_link_hash_entry
669 struct elf_link_hash_entry root;
671 /* Number of PC relative relocs copied for this symbol. */
672 struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
674 /* Key to got_entries. */
675 unsigned long got_entry_key;
677 /* List of GOT entries for this symbol. This list is build during
678 offset finalization and is used within elf_m68k_finish_dynamic_symbol
679 to traverse all GOT entries for a particular symbol.
681 ??? We could've used root.got.glist field instead, but having
682 a separate field is cleaner. */
683 struct elf_m68k_got_entry *glist;
686 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
688 /* Key part of GOT entry in hashtable. */
689 struct elf_m68k_got_entry_key
691 /* BFD in which this symbol was defined. NULL for global symbols. */
692 const bfd *bfd;
694 /* Symbol index. Either local symbol index or h->got_entry_key. */
695 unsigned long symndx;
697 /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
698 R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
700 From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
701 matters. That is, we distinguish between, say, R_68K_GOT16O
702 and R_68K_GOT32O when allocating offsets, but they are considered to be
703 the same when searching got->entries. */
704 enum elf_m68k_reloc_type type;
707 /* Size of the GOT offset suitable for relocation. */
708 enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST };
710 /* Entry of the GOT. */
711 struct elf_m68k_got_entry
713 /* GOT entries are put into a got->entries hashtable. This is the key. */
714 struct elf_m68k_got_entry_key key_;
716 /* GOT entry data. We need s1 before offset finalization and s2 after. */
717 union
719 struct
721 /* Number of times this entry is referenced. It is used to
722 filter out unnecessary GOT slots in elf_m68k_gc_sweep_hook. */
723 bfd_vma refcount;
724 } s1;
726 struct
728 /* Offset from the start of .got section. To calculate offset relative
729 to GOT pointer one should substract got->offset from this value. */
730 bfd_vma offset;
732 /* Pointer to the next GOT entry for this global symbol.
733 Symbols have at most one entry in one GOT, but might
734 have entries in more than one GOT.
735 Root of this list is h->glist.
736 NULL for local symbols. */
737 struct elf_m68k_got_entry *next;
738 } s2;
739 } u;
742 /* Return representative type for relocation R_TYPE.
743 This is used to avoid enumerating many relocations in comparisons,
744 switches etc. */
746 static enum elf_m68k_reloc_type
747 elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type)
749 switch (r_type)
751 /* In most cases R_68K_GOTx relocations require the very same
752 handling as R_68K_GOT32O relocation. In cases when we need
753 to distinguish between the two, we use explicitly compare against
754 r_type. */
755 case R_68K_GOT32:
756 case R_68K_GOT16:
757 case R_68K_GOT8:
758 case R_68K_GOT32O:
759 case R_68K_GOT16O:
760 case R_68K_GOT8O:
761 return R_68K_GOT32O;
763 case R_68K_TLS_GD32:
764 case R_68K_TLS_GD16:
765 case R_68K_TLS_GD8:
766 return R_68K_TLS_GD32;
768 case R_68K_TLS_LDM32:
769 case R_68K_TLS_LDM16:
770 case R_68K_TLS_LDM8:
771 return R_68K_TLS_LDM32;
773 case R_68K_TLS_IE32:
774 case R_68K_TLS_IE16:
775 case R_68K_TLS_IE8:
776 return R_68K_TLS_IE32;
778 default:
779 BFD_ASSERT (FALSE);
780 return 0;
784 /* Return size of the GOT entry offset for relocation R_TYPE. */
786 static enum elf_m68k_got_offset_size
787 elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type)
789 switch (r_type)
791 case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8:
792 case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32:
793 case R_68K_TLS_IE32:
794 return R_32;
796 case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16:
797 case R_68K_TLS_IE16:
798 return R_16;
800 case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8:
801 case R_68K_TLS_IE8:
802 return R_8;
804 default:
805 BFD_ASSERT (FALSE);
806 return 0;
810 /* Return number of GOT entries we need to allocate in GOT for
811 relocation R_TYPE. */
813 static bfd_vma
814 elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type)
816 switch (elf_m68k_reloc_got_type (r_type))
818 case R_68K_GOT32O:
819 case R_68K_TLS_IE32:
820 return 1;
822 case R_68K_TLS_GD32:
823 case R_68K_TLS_LDM32:
824 return 2;
826 default:
827 BFD_ASSERT (FALSE);
828 return 0;
832 /* Return TRUE if relocation R_TYPE is a TLS one. */
834 static bfd_boolean
835 elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type)
837 switch (r_type)
839 case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8:
840 case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8:
841 case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8:
842 case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8:
843 case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8:
844 case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32:
845 return TRUE;
847 default:
848 return FALSE;
852 /* Data structure representing a single GOT. */
853 struct elf_m68k_got
855 /* Hashtable of 'struct elf_m68k_got_entry's.
856 Starting size of this table is the maximum number of
857 R_68K_GOT8O entries. */
858 htab_t entries;
860 /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
861 several GOT slots.
863 n_slots[R_8] is the count of R_8 slots in this GOT.
864 n_slots[R_16] is the cumulative count of R_8 and R_16 slots
865 in this GOT.
866 n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
867 in this GOT. This is the total number of slots. */
868 bfd_vma n_slots[R_LAST];
870 /* Number of local (entry->key_.h == NULL) slots in this GOT.
871 This is only used to properly calculate size of .rela.got section;
872 see elf_m68k_partition_multi_got. */
873 bfd_vma local_n_slots;
875 /* Offset of this GOT relative to beginning of .got section. */
876 bfd_vma offset;
879 /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
880 struct elf_m68k_bfd2got_entry
882 /* BFD. */
883 const bfd *bfd;
885 /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
886 GOT structure. After partitioning several BFD's might [and often do]
887 share a single GOT. */
888 struct elf_m68k_got *got;
891 /* The main data structure holding all the pieces. */
892 struct elf_m68k_multi_got
894 /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
895 here, then it doesn't need a GOT (this includes the case of a BFD
896 having an empty GOT).
898 ??? This hashtable can be replaced by an array indexed by bfd->id. */
899 htab_t bfd2got;
901 /* Next symndx to assign a global symbol.
902 h->got_entry_key is initialized from this counter. */
903 unsigned long global_symndx;
906 /* m68k ELF linker hash table. */
908 struct elf_m68k_link_hash_table
910 struct elf_link_hash_table root;
912 /* Small local sym cache. */
913 struct sym_cache sym_cache;
915 /* The PLT format used by this link, or NULL if the format has not
916 yet been chosen. */
917 const struct elf_m68k_plt_info *plt_info;
919 /* True, if GP is loaded within each function which uses it.
920 Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
921 bfd_boolean local_gp_p;
923 /* Switch controlling use of negative offsets to double the size of GOTs. */
924 bfd_boolean use_neg_got_offsets_p;
926 /* Switch controlling generation of multiple GOTs. */
927 bfd_boolean allow_multigot_p;
929 /* Multi-GOT data structure. */
930 struct elf_m68k_multi_got multi_got_;
933 /* Get the m68k ELF linker hash table from a link_info structure. */
935 #define elf_m68k_hash_table(p) \
936 ((struct elf_m68k_link_hash_table *) (p)->hash)
938 /* Shortcut to multi-GOT data. */
939 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
941 /* Create an entry in an m68k ELF linker hash table. */
943 static struct bfd_hash_entry *
944 elf_m68k_link_hash_newfunc (entry, table, string)
945 struct bfd_hash_entry *entry;
946 struct bfd_hash_table *table;
947 const char *string;
949 struct bfd_hash_entry *ret = entry;
951 /* Allocate the structure if it has not already been allocated by a
952 subclass. */
953 if (ret == NULL)
954 ret = bfd_hash_allocate (table,
955 sizeof (struct elf_m68k_link_hash_entry));
956 if (ret == NULL)
957 return ret;
959 /* Call the allocation method of the superclass. */
960 ret = _bfd_elf_link_hash_newfunc (ret, table, string);
961 if (ret != NULL)
963 elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
964 elf_m68k_hash_entry (ret)->got_entry_key = 0;
965 elf_m68k_hash_entry (ret)->glist = NULL;
968 return ret;
971 /* Create an m68k ELF linker hash table. */
973 static struct bfd_link_hash_table *
974 elf_m68k_link_hash_table_create (abfd)
975 bfd *abfd;
977 struct elf_m68k_link_hash_table *ret;
978 bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table);
980 ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt);
981 if (ret == (struct elf_m68k_link_hash_table *) NULL)
982 return NULL;
984 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
985 elf_m68k_link_hash_newfunc,
986 sizeof (struct elf_m68k_link_hash_entry)))
988 free (ret);
989 return NULL;
992 ret->sym_cache.abfd = NULL;
993 ret->plt_info = NULL;
994 ret->local_gp_p = FALSE;
995 ret->use_neg_got_offsets_p = FALSE;
996 ret->allow_multigot_p = FALSE;
997 ret->multi_got_.bfd2got = NULL;
998 ret->multi_got_.global_symndx = 1;
1000 return &ret->root.root;
1003 /* Destruct local data. */
1005 static void
1006 elf_m68k_link_hash_table_free (struct bfd_link_hash_table *_htab)
1008 struct elf_m68k_link_hash_table *htab;
1010 htab = (struct elf_m68k_link_hash_table *) _htab;
1012 if (htab->multi_got_.bfd2got != NULL)
1014 htab_delete (htab->multi_got_.bfd2got);
1015 htab->multi_got_.bfd2got = NULL;
1019 /* Set the right machine number. */
1021 static bfd_boolean
1022 elf32_m68k_object_p (bfd *abfd)
1024 unsigned int mach = 0;
1025 unsigned features = 0;
1026 flagword eflags = elf_elfheader (abfd)->e_flags;
1028 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1029 features |= m68000;
1030 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1031 features |= cpu32;
1032 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1033 features |= fido_a;
1034 else
1036 switch (eflags & EF_M68K_CF_ISA_MASK)
1038 case EF_M68K_CF_ISA_A_NODIV:
1039 features |= mcfisa_a;
1040 break;
1041 case EF_M68K_CF_ISA_A:
1042 features |= mcfisa_a|mcfhwdiv;
1043 break;
1044 case EF_M68K_CF_ISA_A_PLUS:
1045 features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
1046 break;
1047 case EF_M68K_CF_ISA_B_NOUSP:
1048 features |= mcfisa_a|mcfisa_b|mcfhwdiv;
1049 break;
1050 case EF_M68K_CF_ISA_B:
1051 features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
1052 break;
1053 case EF_M68K_CF_ISA_C:
1054 features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
1055 break;
1056 case EF_M68K_CF_ISA_C_NODIV:
1057 features |= mcfisa_a|mcfisa_c|mcfusp;
1058 break;
1060 switch (eflags & EF_M68K_CF_MAC_MASK)
1062 case EF_M68K_CF_MAC:
1063 features |= mcfmac;
1064 break;
1065 case EF_M68K_CF_EMAC:
1066 features |= mcfemac;
1067 break;
1069 if (eflags & EF_M68K_CF_FLOAT)
1070 features |= cfloat;
1073 mach = bfd_m68k_features_to_mach (features);
1074 bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
1076 return TRUE;
1079 /* Keep m68k-specific flags in the ELF header. */
1080 static bfd_boolean
1081 elf32_m68k_set_private_flags (abfd, flags)
1082 bfd *abfd;
1083 flagword flags;
1085 elf_elfheader (abfd)->e_flags = flags;
1086 elf_flags_init (abfd) = TRUE;
1087 return TRUE;
1090 /* Merge backend specific data from an object file to the output
1091 object file when linking. */
1092 static bfd_boolean
1093 elf32_m68k_merge_private_bfd_data (ibfd, obfd)
1094 bfd *ibfd;
1095 bfd *obfd;
1097 flagword out_flags;
1098 flagword in_flags;
1099 flagword out_isa;
1100 flagword in_isa;
1101 const bfd_arch_info_type *arch_info;
1103 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1104 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1105 return FALSE;
1107 /* Get the merged machine. This checks for incompatibility between
1108 Coldfire & non-Coldfire flags, incompability between different
1109 Coldfire ISAs, and incompability between different MAC types. */
1110 arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE);
1111 if (!arch_info)
1112 return FALSE;
1114 bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
1116 in_flags = elf_elfheader (ibfd)->e_flags;
1117 if (!elf_flags_init (obfd))
1119 elf_flags_init (obfd) = TRUE;
1120 out_flags = in_flags;
1122 else
1124 out_flags = elf_elfheader (obfd)->e_flags;
1125 unsigned int variant_mask;
1127 if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1128 variant_mask = 0;
1129 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1130 variant_mask = 0;
1131 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1132 variant_mask = 0;
1133 else
1134 variant_mask = EF_M68K_CF_ISA_MASK;
1136 in_isa = (in_flags & variant_mask);
1137 out_isa = (out_flags & variant_mask);
1138 if (in_isa > out_isa)
1139 out_flags ^= in_isa ^ out_isa;
1140 if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
1141 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1142 || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
1143 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
1144 out_flags = EF_M68K_FIDO;
1145 else
1146 out_flags |= in_flags ^ in_isa;
1148 elf_elfheader (obfd)->e_flags = out_flags;
1150 return TRUE;
1153 /* Display the flags field. */
1155 static bfd_boolean
1156 elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr)
1158 FILE *file = (FILE *) ptr;
1159 flagword eflags = elf_elfheader (abfd)->e_flags;
1161 BFD_ASSERT (abfd != NULL && ptr != NULL);
1163 /* Print normal ELF private data. */
1164 _bfd_elf_print_private_bfd_data (abfd, ptr);
1166 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1168 /* xgettext:c-format */
1169 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
1171 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1172 fprintf (file, " [m68000]");
1173 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1174 fprintf (file, " [cpu32]");
1175 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1176 fprintf (file, " [fido]");
1177 else
1179 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
1180 fprintf (file, " [cfv4e]");
1182 if (eflags & EF_M68K_CF_ISA_MASK)
1184 char const *isa = _("unknown");
1185 char const *mac = _("unknown");
1186 char const *additional = "";
1188 switch (eflags & EF_M68K_CF_ISA_MASK)
1190 case EF_M68K_CF_ISA_A_NODIV:
1191 isa = "A";
1192 additional = " [nodiv]";
1193 break;
1194 case EF_M68K_CF_ISA_A:
1195 isa = "A";
1196 break;
1197 case EF_M68K_CF_ISA_A_PLUS:
1198 isa = "A+";
1199 break;
1200 case EF_M68K_CF_ISA_B_NOUSP:
1201 isa = "B";
1202 additional = " [nousp]";
1203 break;
1204 case EF_M68K_CF_ISA_B:
1205 isa = "B";
1206 break;
1207 case EF_M68K_CF_ISA_C:
1208 isa = "C";
1209 break;
1210 case EF_M68K_CF_ISA_C_NODIV:
1211 isa = "C";
1212 additional = " [nodiv]";
1213 break;
1215 fprintf (file, " [isa %s]%s", isa, additional);
1217 if (eflags & EF_M68K_CF_FLOAT)
1218 fprintf (file, " [float]");
1220 switch (eflags & EF_M68K_CF_MAC_MASK)
1222 case 0:
1223 mac = NULL;
1224 break;
1225 case EF_M68K_CF_MAC:
1226 mac = "mac";
1227 break;
1228 case EF_M68K_CF_EMAC:
1229 mac = "emac";
1230 break;
1232 if (mac)
1233 fprintf (file, " [%s]", mac);
1237 fputc ('\n', file);
1239 return TRUE;
1242 /* Multi-GOT support implementation design:
1244 Multi-GOT starts in check_relocs hook. There we scan all
1245 relocations of a BFD and build a local GOT (struct elf_m68k_got)
1246 for it. If a single BFD appears to require too many GOT slots with
1247 R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1248 to user.
1249 After check_relocs has been invoked for each input BFD, we have
1250 constructed a GOT for each input BFD.
1252 To minimize total number of GOTs required for a particular output BFD
1253 (as some environments support only 1 GOT per output object) we try
1254 to merge some of the GOTs to share an offset space. Ideally [and in most
1255 cases] we end up with a single GOT. In cases when there are too many
1256 restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1257 several GOTs, assuming the environment can handle them.
1259 Partitioning is done in elf_m68k_partition_multi_got. We start with
1260 an empty GOT and traverse bfd2got hashtable putting got_entries from
1261 local GOTs to the new 'big' one. We do that by constructing an
1262 intermediate GOT holding all the entries the local GOT has and the big
1263 GOT lacks. Then we check if there is room in the big GOT to accomodate
1264 all the entries from diff. On success we add those entries to the big
1265 GOT; on failure we start the new 'big' GOT and retry the adding of
1266 entries from the local GOT. Note that this retry will always succeed as
1267 each local GOT doesn't overflow the limits. After partitioning we
1268 end up with each bfd assigned one of the big GOTs. GOT entries in the
1269 big GOTs are initialized with GOT offsets. Note that big GOTs are
1270 positioned consequently in program space and represent a single huge GOT
1271 to the outside world.
1273 After that we get to elf_m68k_relocate_section. There we
1274 adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1275 relocations to refer to appropriate [assigned to current input_bfd]
1276 big GOT.
1278 Notes:
1280 GOT entry type: We have several types of GOT entries.
1281 * R_8 type is used in entries for symbols that have at least one
1282 R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
1283 such entries in one GOT.
1284 * R_16 type is used in entries for symbols that have at least one
1285 R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1286 We can have at most 0x4000 such entries in one GOT.
1287 * R_32 type is used in all other cases. We can have as many
1288 such entries in one GOT as we'd like.
1289 When counting relocations we have to include the count of the smaller
1290 ranged relocations in the counts of the larger ranged ones in order
1291 to correctly detect overflow.
1293 Sorting the GOT: In each GOT starting offsets are assigned to
1294 R_8 entries, which are followed by R_16 entries, and
1295 R_32 entries go at the end. See finalize_got_offsets for details.
1297 Negative GOT offsets: To double usable offset range of GOTs we use
1298 negative offsets. As we assign entries with GOT offsets relative to
1299 start of .got section, the offset values are positive. They become
1300 negative only in relocate_section where got->offset value is
1301 subtracted from them.
1303 3 special GOT entries: There are 3 special GOT entries used internally
1304 by loader. These entries happen to be placed to .got.plt section,
1305 so we don't do anything about them in multi-GOT support.
1307 Memory management: All data except for hashtables
1308 multi_got->bfd2got and got->entries are allocated on
1309 elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1310 to most functions), so we don't need to care to free them. At the
1311 moment of allocation hashtables are being linked into main data
1312 structure (multi_got), all pieces of which are reachable from
1313 elf_m68k_multi_got (info). We deallocate them in
1314 elf_m68k_link_hash_table_free. */
1316 /* Initialize GOT. */
1318 static void
1319 elf_m68k_init_got (struct elf_m68k_got *got)
1321 got->entries = NULL;
1322 got->n_slots[R_8] = 0;
1323 got->n_slots[R_16] = 0;
1324 got->n_slots[R_32] = 0;
1325 got->local_n_slots = 0;
1326 got->offset = (bfd_vma) -1;
1329 /* Destruct GOT. */
1331 static void
1332 elf_m68k_clear_got (struct elf_m68k_got *got)
1334 if (got->entries != NULL)
1336 htab_delete (got->entries);
1337 got->entries = NULL;
1341 /* Create and empty GOT structure. INFO is the context where memory
1342 should be allocated. */
1344 static struct elf_m68k_got *
1345 elf_m68k_create_empty_got (struct bfd_link_info *info)
1347 struct elf_m68k_got *got;
1349 got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got));
1350 if (got == NULL)
1351 return NULL;
1353 elf_m68k_init_got (got);
1355 return got;
1358 /* Initialize KEY. */
1360 static void
1361 elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key,
1362 struct elf_link_hash_entry *h,
1363 const bfd *abfd, unsigned long symndx,
1364 enum elf_m68k_reloc_type reloc_type)
1366 if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32)
1367 /* All TLS_LDM relocations share a single GOT entry. */
1369 key->bfd = NULL;
1370 key->symndx = 0;
1372 else if (h != NULL)
1373 /* Global symbols are identified with their got_entry_key. */
1375 key->bfd = NULL;
1376 key->symndx = elf_m68k_hash_entry (h)->got_entry_key;
1377 BFD_ASSERT (key->symndx != 0);
1379 else
1380 /* Local symbols are identified by BFD they appear in and symndx. */
1382 key->bfd = abfd;
1383 key->symndx = symndx;
1386 key->type = reloc_type;
1389 /* Calculate hash of got_entry.
1390 ??? Is it good? */
1392 static hashval_t
1393 elf_m68k_got_entry_hash (const void *_entry)
1395 const struct elf_m68k_got_entry_key *key;
1397 key = &((const struct elf_m68k_got_entry *) _entry)->key_;
1399 return (key->symndx
1400 + (key->bfd != NULL ? (int) key->bfd->id : -1)
1401 + elf_m68k_reloc_got_type (key->type));
1404 /* Check if two got entries are equal. */
1406 static int
1407 elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2)
1409 const struct elf_m68k_got_entry_key *key1;
1410 const struct elf_m68k_got_entry_key *key2;
1412 key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_;
1413 key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_;
1415 return (key1->bfd == key2->bfd
1416 && key1->symndx == key2->symndx
1417 && (elf_m68k_reloc_got_type (key1->type)
1418 == elf_m68k_reloc_got_type (key2->type)));
1421 /* When using negative offsets, we allocate one extra R_8, one extra R_16
1422 and one extra R_32 slots to simplify handling of 2-slot entries during
1423 offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
1425 /* Maximal number of R_8 slots in a single GOT. */
1426 #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
1427 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1428 ? (0x40 - 1) \
1429 : 0x20)
1431 /* Maximal number of R_8 and R_16 slots in a single GOT. */
1432 #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
1433 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1434 ? (0x4000 - 2) \
1435 : 0x2000)
1437 /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1438 the entry cannot be found.
1439 FIND_OR_CREATE - search for an existing entry, but create new if there's
1440 no such.
1441 MUST_FIND - search for an existing entry and assert that it exist.
1442 MUST_CREATE - assert that there's no such entry and create new one. */
1443 enum elf_m68k_get_entry_howto
1445 SEARCH,
1446 FIND_OR_CREATE,
1447 MUST_FIND,
1448 MUST_CREATE
1451 /* Get or create (depending on HOWTO) entry with KEY in GOT.
1452 INFO is context in which memory should be allocated (can be NULL if
1453 HOWTO is SEARCH or MUST_FIND). */
1455 static struct elf_m68k_got_entry *
1456 elf_m68k_get_got_entry (struct elf_m68k_got *got,
1457 const struct elf_m68k_got_entry_key *key,
1458 enum elf_m68k_get_entry_howto howto,
1459 struct bfd_link_info *info)
1461 struct elf_m68k_got_entry entry_;
1462 struct elf_m68k_got_entry *entry;
1463 void **ptr;
1465 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1467 if (got->entries == NULL)
1468 /* This is the first entry in ABFD. Initialize hashtable. */
1470 if (howto == SEARCH)
1471 return NULL;
1473 got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1474 (info),
1475 elf_m68k_got_entry_hash,
1476 elf_m68k_got_entry_eq, NULL);
1477 if (got->entries == NULL)
1479 bfd_set_error (bfd_error_no_memory);
1480 return NULL;
1484 entry_.key_ = *key;
1485 ptr = htab_find_slot (got->entries, &entry_, (howto != SEARCH
1486 ? INSERT : NO_INSERT));
1487 if (ptr == NULL)
1489 if (howto == SEARCH)
1490 /* Entry not found. */
1491 return NULL;
1493 /* We're out of memory. */
1494 bfd_set_error (bfd_error_no_memory);
1495 return NULL;
1498 if (*ptr == NULL)
1499 /* We didn't find the entry and we're asked to create a new one. */
1501 BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1503 entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry));
1504 if (entry == NULL)
1505 return NULL;
1507 /* Initialize new entry. */
1508 entry->key_ = *key;
1510 entry->u.s1.refcount = 0;
1512 /* Mark the entry as not initialized. */
1513 entry->key_.type = R_68K_max;
1515 *ptr = entry;
1517 else
1518 /* We found the entry. */
1520 BFD_ASSERT (howto != MUST_CREATE);
1522 entry = *ptr;
1525 return entry;
1528 /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1529 Return the value to which ENTRY's type should be set. */
1531 static enum elf_m68k_reloc_type
1532 elf_m68k_update_got_entry_type (struct elf_m68k_got *got,
1533 enum elf_m68k_reloc_type was,
1534 enum elf_m68k_reloc_type new)
1536 enum elf_m68k_got_offset_size was_size;
1537 enum elf_m68k_got_offset_size new_size;
1538 bfd_vma n_slots;
1540 if (was == R_68K_max)
1541 /* The type of the entry is not initialized yet. */
1543 /* Update all got->n_slots counters, including n_slots[R_32]. */
1544 was_size = R_LAST;
1546 was = new;
1548 else
1550 /* !!! We, probably, should emit an error rather then fail on assert
1551 in such a case. */
1552 BFD_ASSERT (elf_m68k_reloc_got_type (was)
1553 == elf_m68k_reloc_got_type (new));
1555 was_size = elf_m68k_reloc_got_offset_size (was);
1558 new_size = elf_m68k_reloc_got_offset_size (new);
1559 n_slots = elf_m68k_reloc_got_n_slots (new);
1561 while (was_size > new_size)
1563 --was_size;
1564 got->n_slots[was_size] += n_slots;
1567 if (new > was)
1568 /* Relocations are ordered from bigger got offset size to lesser,
1569 so choose the relocation type with lesser offset size. */
1570 was = new;
1572 return was;
1575 /* Update GOT counters when removing an entry of type TYPE. */
1577 static void
1578 elf_m68k_remove_got_entry_type (struct elf_m68k_got *got,
1579 enum elf_m68k_reloc_type type)
1581 enum elf_m68k_got_offset_size os;
1582 bfd_vma n_slots;
1584 n_slots = elf_m68k_reloc_got_n_slots (type);
1586 /* Decrese counter of slots with offset size corresponding to TYPE
1587 and all greater offset sizes. */
1588 for (os = elf_m68k_reloc_got_offset_size (type); os <= R_32; ++os)
1590 BFD_ASSERT (got->n_slots[os] >= n_slots);
1592 got->n_slots[os] -= n_slots;
1596 /* Add new or update existing entry to GOT.
1597 H, ABFD, TYPE and SYMNDX is data for the entry.
1598 INFO is a context where memory should be allocated. */
1600 static struct elf_m68k_got_entry *
1601 elf_m68k_add_entry_to_got (struct elf_m68k_got *got,
1602 struct elf_link_hash_entry *h,
1603 const bfd *abfd,
1604 enum elf_m68k_reloc_type reloc_type,
1605 unsigned long symndx,
1606 struct bfd_link_info *info)
1608 struct elf_m68k_got_entry_key key_;
1609 struct elf_m68k_got_entry *entry;
1611 if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0)
1612 elf_m68k_hash_entry (h)->got_entry_key
1613 = elf_m68k_multi_got (info)->global_symndx++;
1615 elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type);
1617 entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info);
1618 if (entry == NULL)
1619 return NULL;
1621 /* Determine entry's type and update got->n_slots counters. */
1622 entry->key_.type = elf_m68k_update_got_entry_type (got,
1623 entry->key_.type,
1624 reloc_type);
1626 /* Update refcount. */
1627 ++entry->u.s1.refcount;
1629 if (entry->u.s1.refcount == 1)
1630 /* We see this entry for the first time. */
1632 if (entry->key_.bfd != NULL)
1633 got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type);
1636 BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
1638 if ((got->n_slots[R_8]
1639 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1640 || (got->n_slots[R_16]
1641 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1642 /* This BFD has too many relocation. */
1644 if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1645 (*_bfd_error_handler) (_("%B: GOT overflow: "
1646 "Number of relocations with 8-bit "
1647 "offset > %d"),
1648 abfd,
1649 ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info));
1650 else
1651 (*_bfd_error_handler) (_("%B: GOT overflow: "
1652 "Number of relocations with 8- or 16-bit "
1653 "offset > %d"),
1654 abfd,
1655 ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info));
1657 return NULL;
1660 return entry;
1663 /* Compute the hash value of the bfd in a bfd2got hash entry. */
1665 static hashval_t
1666 elf_m68k_bfd2got_entry_hash (const void *entry)
1668 const struct elf_m68k_bfd2got_entry *e;
1670 e = (const struct elf_m68k_bfd2got_entry *) entry;
1672 return e->bfd->id;
1675 /* Check whether two hash entries have the same bfd. */
1677 static int
1678 elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2)
1680 const struct elf_m68k_bfd2got_entry *e1;
1681 const struct elf_m68k_bfd2got_entry *e2;
1683 e1 = (const struct elf_m68k_bfd2got_entry *) entry1;
1684 e2 = (const struct elf_m68k_bfd2got_entry *) entry2;
1686 return e1->bfd == e2->bfd;
1689 /* Destruct a bfd2got entry. */
1691 static void
1692 elf_m68k_bfd2got_entry_del (void *_entry)
1694 struct elf_m68k_bfd2got_entry *entry;
1696 entry = (struct elf_m68k_bfd2got_entry *) _entry;
1698 BFD_ASSERT (entry->got != NULL);
1699 elf_m68k_clear_got (entry->got);
1702 /* Find existing or create new (depending on HOWTO) bfd2got entry in
1703 MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1704 memory should be allocated. */
1706 static struct elf_m68k_bfd2got_entry *
1707 elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got,
1708 const bfd *abfd,
1709 enum elf_m68k_get_entry_howto howto,
1710 struct bfd_link_info *info)
1712 struct elf_m68k_bfd2got_entry entry_;
1713 void **ptr;
1714 struct elf_m68k_bfd2got_entry *entry;
1716 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1718 if (multi_got->bfd2got == NULL)
1719 /* This is the first GOT. Initialize bfd2got. */
1721 if (howto == SEARCH)
1722 return NULL;
1724 multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash,
1725 elf_m68k_bfd2got_entry_eq,
1726 elf_m68k_bfd2got_entry_del);
1727 if (multi_got->bfd2got == NULL)
1729 bfd_set_error (bfd_error_no_memory);
1730 return NULL;
1734 entry_.bfd = abfd;
1735 ptr = htab_find_slot (multi_got->bfd2got, &entry_, (howto != SEARCH
1736 ? INSERT : NO_INSERT));
1737 if (ptr == NULL)
1739 if (howto == SEARCH)
1740 /* Entry not found. */
1741 return NULL;
1743 /* We're out of memory. */
1744 bfd_set_error (bfd_error_no_memory);
1745 return NULL;
1748 if (*ptr == NULL)
1749 /* Entry was not found. Create new one. */
1751 BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1753 entry = ((struct elf_m68k_bfd2got_entry *)
1754 bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)));
1755 if (entry == NULL)
1756 return NULL;
1758 entry->bfd = abfd;
1760 entry->got = elf_m68k_create_empty_got (info);
1761 if (entry->got == NULL)
1762 return NULL;
1764 *ptr = entry;
1766 else
1768 BFD_ASSERT (howto != MUST_CREATE);
1770 /* Return existing entry. */
1771 entry = *ptr;
1774 return entry;
1777 struct elf_m68k_can_merge_gots_arg
1779 /* A current_got that we constructing a DIFF against. */
1780 struct elf_m68k_got *big;
1782 /* GOT holding entries not present or that should be changed in
1783 BIG. */
1784 struct elf_m68k_got *diff;
1786 /* Context where to allocate memory. */
1787 struct bfd_link_info *info;
1789 /* Error flag. */
1790 bfd_boolean error_p;
1793 /* Process a single entry from the small GOT to see if it should be added
1794 or updated in the big GOT. */
1796 static int
1797 elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg)
1799 const struct elf_m68k_got_entry *entry1;
1800 struct elf_m68k_can_merge_gots_arg *arg;
1801 const struct elf_m68k_got_entry *entry2;
1802 enum elf_m68k_reloc_type type;
1804 entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr;
1805 arg = (struct elf_m68k_can_merge_gots_arg *) _arg;
1807 entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL);
1809 if (entry2 != NULL)
1810 /* We found an existing entry. Check if we should update it. */
1812 type = elf_m68k_update_got_entry_type (arg->diff,
1813 entry2->key_.type,
1814 entry1->key_.type);
1816 if (type == entry2->key_.type)
1817 /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1818 To skip creation of difference entry we use the type,
1819 which we won't see in GOT entries for sure. */
1820 type = R_68K_max;
1822 else
1823 /* We didn't find the entry. Add entry1 to DIFF. */
1825 BFD_ASSERT (entry1->key_.type != R_68K_max);
1827 type = elf_m68k_update_got_entry_type (arg->diff,
1828 R_68K_max, entry1->key_.type);
1830 if (entry1->key_.bfd != NULL)
1831 arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type);
1834 if (type != R_68K_max)
1835 /* Create an entry in DIFF. */
1837 struct elf_m68k_got_entry *entry;
1839 entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE,
1840 arg->info);
1841 if (entry == NULL)
1843 arg->error_p = TRUE;
1844 return 0;
1847 entry->key_.type = type;
1850 return 1;
1853 /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1854 Construct DIFF GOT holding the entries which should be added or updated
1855 in BIG GOT to accumulate information from SMALL.
1856 INFO is the context where memory should be allocated. */
1858 static bfd_boolean
1859 elf_m68k_can_merge_gots (struct elf_m68k_got *big,
1860 const struct elf_m68k_got *small,
1861 struct bfd_link_info *info,
1862 struct elf_m68k_got *diff)
1864 struct elf_m68k_can_merge_gots_arg arg_;
1866 BFD_ASSERT (small->offset == (bfd_vma) -1);
1868 arg_.big = big;
1869 arg_.diff = diff;
1870 arg_.info = info;
1871 arg_.error_p = FALSE;
1872 htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_);
1873 if (arg_.error_p)
1875 diff->offset = 0;
1876 return FALSE;
1879 /* Check for overflow. */
1880 if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8]
1881 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1882 || (big->n_slots[R_16] + arg_.diff->n_slots[R_16]
1883 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1884 return FALSE;
1886 return TRUE;
1889 struct elf_m68k_merge_gots_arg
1891 /* The BIG got. */
1892 struct elf_m68k_got *big;
1894 /* Context where memory should be allocated. */
1895 struct bfd_link_info *info;
1897 /* Error flag. */
1898 bfd_boolean error_p;
1901 /* Process a single entry from DIFF got. Add or update corresponding
1902 entry in the BIG got. */
1904 static int
1905 elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg)
1907 const struct elf_m68k_got_entry *from;
1908 struct elf_m68k_merge_gots_arg *arg;
1909 struct elf_m68k_got_entry *to;
1911 from = (const struct elf_m68k_got_entry *) *entry_ptr;
1912 arg = (struct elf_m68k_merge_gots_arg *) _arg;
1914 to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE,
1915 arg->info);
1916 if (to == NULL)
1918 arg->error_p = TRUE;
1919 return 0;
1922 BFD_ASSERT (to->u.s1.refcount == 0);
1923 /* All we need to merge is TYPE. */
1924 to->key_.type = from->key_.type;
1926 return 1;
1929 /* Merge data from DIFF to BIG. INFO is context where memory should be
1930 allocated. */
1932 static bfd_boolean
1933 elf_m68k_merge_gots (struct elf_m68k_got *big,
1934 struct elf_m68k_got *diff,
1935 struct bfd_link_info *info)
1937 if (diff->entries != NULL)
1938 /* DIFF is not empty. Merge it into BIG GOT. */
1940 struct elf_m68k_merge_gots_arg arg_;
1942 /* Merge entries. */
1943 arg_.big = big;
1944 arg_.info = info;
1945 arg_.error_p = FALSE;
1946 htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_);
1947 if (arg_.error_p)
1948 return FALSE;
1950 /* Merge counters. */
1951 big->n_slots[R_8] += diff->n_slots[R_8];
1952 big->n_slots[R_16] += diff->n_slots[R_16];
1953 big->n_slots[R_32] += diff->n_slots[R_32];
1954 big->local_n_slots += diff->local_n_slots;
1956 else
1957 /* DIFF is empty. */
1959 BFD_ASSERT (diff->n_slots[R_8] == 0);
1960 BFD_ASSERT (diff->n_slots[R_16] == 0);
1961 BFD_ASSERT (diff->n_slots[R_32] == 0);
1962 BFD_ASSERT (diff->local_n_slots == 0);
1965 BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p
1966 || ((big->n_slots[R_8]
1967 <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1968 && (big->n_slots[R_16]
1969 <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))));
1971 return TRUE;
1974 struct elf_m68k_finalize_got_offsets_arg
1976 /* Ranges of the offsets for GOT entries.
1977 R_x entries receive offsets between offset1[R_x] and offset2[R_x].
1978 R_x is R_8, R_16 and R_32. */
1979 bfd_vma *offset1;
1980 bfd_vma *offset2;
1982 /* Mapping from global symndx to global symbols.
1983 This is used to build lists of got entries for global symbols. */
1984 struct elf_m68k_link_hash_entry **symndx2h;
1986 bfd_vma n_ldm_entries;
1989 /* Assign ENTRY an offset. Build list of GOT entries for global symbols
1990 along the way. */
1992 static int
1993 elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg)
1995 struct elf_m68k_got_entry *entry;
1996 struct elf_m68k_finalize_got_offsets_arg *arg;
1998 enum elf_m68k_got_offset_size got_offset_size;
1999 bfd_vma entry_size;
2001 entry = (struct elf_m68k_got_entry *) *entry_ptr;
2002 arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg;
2004 /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
2005 BFD_ASSERT (entry->u.s1.refcount == 0);
2007 /* Get GOT offset size for the entry . */
2008 got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type);
2010 /* Calculate entry size in bytes. */
2011 entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type);
2013 /* Check if we should switch to negative range of the offsets. */
2014 if (arg->offset1[got_offset_size] + entry_size
2015 > arg->offset2[got_offset_size])
2017 /* Verify that this is the only switch to negative range for
2018 got_offset_size. If this assertion fails, then we've miscalculated
2019 range for got_offset_size entries in
2020 elf_m68k_finalize_got_offsets. */
2021 BFD_ASSERT (arg->offset2[got_offset_size]
2022 != arg->offset2[-(int) got_offset_size - 1]);
2024 /* Switch. */
2025 arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1];
2026 arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1];
2028 /* Verify that now we have enough room for the entry. */
2029 BFD_ASSERT (arg->offset1[got_offset_size] + entry_size
2030 <= arg->offset2[got_offset_size]);
2033 /* Assign offset to entry. */
2034 entry->u.s2.offset = arg->offset1[got_offset_size];
2035 arg->offset1[got_offset_size] += entry_size;
2037 if (entry->key_.bfd == NULL)
2038 /* Hook up this entry into the list of got_entries of H. */
2040 struct elf_m68k_link_hash_entry *h;
2042 h = arg->symndx2h[entry->key_.symndx];
2043 if (h != NULL)
2045 entry->u.s2.next = h->glist;
2046 h->glist = entry;
2048 else
2049 /* This should be the entry for TLS_LDM relocation then. */
2051 BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type)
2052 == R_68K_TLS_LDM32)
2053 && entry->key_.symndx == 0);
2055 ++arg->n_ldm_entries;
2058 else
2059 /* This entry is for local symbol. */
2060 entry->u.s2.next = NULL;
2062 return 1;
2065 /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
2066 should use negative offsets.
2067 Build list of GOT entries for global symbols along the way.
2068 SYMNDX2H is mapping from global symbol indices to actual
2069 global symbols.
2070 Return offset at which next GOT should start. */
2072 static void
2073 elf_m68k_finalize_got_offsets (struct elf_m68k_got *got,
2074 bfd_boolean use_neg_got_offsets_p,
2075 struct elf_m68k_link_hash_entry **symndx2h,
2076 bfd_vma *final_offset, bfd_vma *n_ldm_entries)
2078 struct elf_m68k_finalize_got_offsets_arg arg_;
2079 bfd_vma offset1_[2 * R_LAST];
2080 bfd_vma offset2_[2 * R_LAST];
2081 int i;
2082 bfd_vma start_offset;
2084 BFD_ASSERT (got->offset != (bfd_vma) -1);
2086 /* We set entry offsets relative to the .got section (and not the
2087 start of a particular GOT), so that we can use them in
2088 finish_dynamic_symbol without needing to know the GOT which they come
2089 from. */
2091 /* Put offset1 in the middle of offset1_, same for offset2. */
2092 arg_.offset1 = offset1_ + R_LAST;
2093 arg_.offset2 = offset2_ + R_LAST;
2095 start_offset = got->offset;
2097 if (use_neg_got_offsets_p)
2098 /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
2099 i = -(int) R_32 - 1;
2100 else
2101 /* Setup positives ranges for R_8, R_16 and R_32. */
2102 i = (int) R_8;
2104 for (; i <= (int) R_32; ++i)
2106 int j;
2107 size_t n;
2109 /* Set beginning of the range of offsets I. */
2110 arg_.offset1[i] = start_offset;
2112 /* Calculate number of slots that require I offsets. */
2113 j = (i >= 0) ? i : -i - 1;
2114 n = (j >= 1) ? got->n_slots[j - 1] : 0;
2115 n = got->n_slots[j] - n;
2117 if (use_neg_got_offsets_p && n != 0)
2119 if (i < 0)
2120 /* We first fill the positive side of the range, so we might
2121 end up with one empty slot at that side when we can't fit
2122 whole 2-slot entry. Account for that at negative side of
2123 the interval with one additional entry. */
2124 n = n / 2 + 1;
2125 else
2126 /* When the number of slots is odd, make positive side of the
2127 range one entry bigger. */
2128 n = (n + 1) / 2;
2131 /* N is the number of slots that require I offsets.
2132 Calculate length of the range for I offsets. */
2133 n = 4 * n;
2135 /* Set end of the range. */
2136 arg_.offset2[i] = start_offset + n;
2138 start_offset = arg_.offset2[i];
2141 if (!use_neg_got_offsets_p)
2142 /* Make sure that if we try to switch to negative offsets in
2143 elf_m68k_finalize_got_offsets_1, the assert therein will catch
2144 the bug. */
2145 for (i = R_8; i <= R_32; ++i)
2146 arg_.offset2[-i - 1] = arg_.offset2[i];
2148 /* Setup got->offset. offset1[R_8] is either in the middle or at the
2149 beginning of GOT depending on use_neg_got_offsets_p. */
2150 got->offset = arg_.offset1[R_8];
2152 arg_.symndx2h = symndx2h;
2153 arg_.n_ldm_entries = 0;
2155 /* Assign offsets. */
2156 htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_);
2158 /* Check offset ranges we have actually assigned. */
2159 for (i = (int) R_8; i <= (int) R_32; ++i)
2160 BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4);
2162 *final_offset = start_offset;
2163 *n_ldm_entries = arg_.n_ldm_entries;
2166 struct elf_m68k_partition_multi_got_arg
2168 /* The GOT we are adding entries to. Aka big got. */
2169 struct elf_m68k_got *current_got;
2171 /* Offset to assign the next CURRENT_GOT. */
2172 bfd_vma offset;
2174 /* Context where memory should be allocated. */
2175 struct bfd_link_info *info;
2177 /* Total number of slots in the .got section.
2178 This is used to calculate size of the .got and .rela.got sections. */
2179 bfd_vma n_slots;
2181 /* Difference in numbers of allocated slots in the .got section
2182 and necessary relocations in the .rela.got section.
2183 This is used to calculate size of the .rela.got section. */
2184 bfd_vma slots_relas_diff;
2186 /* Error flag. */
2187 bfd_boolean error_p;
2189 /* Mapping from global symndx to global symbols.
2190 This is used to build lists of got entries for global symbols. */
2191 struct elf_m68k_link_hash_entry **symndx2h;
2194 static void
2195 elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg)
2197 bfd_vma n_ldm_entries;
2199 elf_m68k_finalize_got_offsets (arg->current_got,
2200 (elf_m68k_hash_table (arg->info)
2201 ->use_neg_got_offsets_p),
2202 arg->symndx2h,
2203 &arg->offset, &n_ldm_entries);
2205 arg->n_slots += arg->current_got->n_slots[R_32];
2207 if (!arg->info->shared)
2208 /* If we are generating a shared object, we need to
2209 output a R_68K_RELATIVE reloc so that the dynamic
2210 linker can adjust this GOT entry. Overwise we
2211 don't need space in .rela.got for local symbols. */
2212 arg->slots_relas_diff += arg->current_got->local_n_slots;
2214 /* @LDM relocations require a 2-slot GOT entry, but only
2215 one relocation. Account for that. */
2216 arg->slots_relas_diff += n_ldm_entries;
2218 BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots);
2222 /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2223 or start a new CURRENT_GOT. */
2225 static int
2226 elf_m68k_partition_multi_got_1 (void **_entry, void *_arg)
2228 struct elf_m68k_bfd2got_entry *entry;
2229 struct elf_m68k_partition_multi_got_arg *arg;
2230 struct elf_m68k_got *got;
2231 struct elf_m68k_got diff_;
2232 struct elf_m68k_got *diff;
2234 entry = (struct elf_m68k_bfd2got_entry *) *_entry;
2235 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2237 got = entry->got;
2238 BFD_ASSERT (got != NULL);
2239 BFD_ASSERT (got->offset == (bfd_vma) -1);
2241 diff = NULL;
2243 if (arg->current_got != NULL)
2244 /* Construct diff. */
2246 diff = &diff_;
2247 elf_m68k_init_got (diff);
2249 if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff))
2251 if (diff->offset == 0)
2252 /* Offset set to 0 in the diff_ indicates an error. */
2254 arg->error_p = TRUE;
2255 goto final_return;
2258 if (elf_m68k_hash_table (arg->info)->allow_multigot_p)
2260 elf_m68k_clear_got (diff);
2261 /* Schedule to finish up current_got and start new one. */
2262 diff = NULL;
2264 /* else
2265 Merge GOTs no matter what. If big GOT overflows,
2266 we'll fail in relocate_section due to truncated relocations.
2268 ??? May be fail earlier? E.g., in can_merge_gots. */
2271 else
2272 /* Diff of got against empty current_got is got itself. */
2274 /* Create empty current_got to put subsequent GOTs to. */
2275 arg->current_got = elf_m68k_create_empty_got (arg->info);
2276 if (arg->current_got == NULL)
2278 arg->error_p = TRUE;
2279 goto final_return;
2282 arg->current_got->offset = arg->offset;
2284 diff = got;
2287 if (diff != NULL)
2289 if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info))
2291 arg->error_p = TRUE;
2292 goto final_return;
2295 /* Now we can free GOT. */
2296 elf_m68k_clear_got (got);
2298 entry->got = arg->current_got;
2300 else
2302 /* Finish up current_got. */
2303 elf_m68k_partition_multi_got_2 (arg);
2305 /* Schedule to start a new current_got. */
2306 arg->current_got = NULL;
2308 /* Retry. */
2309 if (!elf_m68k_partition_multi_got_1 (_entry, _arg))
2311 BFD_ASSERT (arg->error_p);
2312 goto final_return;
2316 final_return:
2317 if (diff != NULL)
2318 elf_m68k_clear_got (diff);
2320 return arg->error_p == FALSE ? 1 : 0;
2323 /* Helper function to build symndx2h mapping. */
2325 static bfd_boolean
2326 elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h,
2327 void *_arg)
2329 struct elf_m68k_link_hash_entry *h;
2331 h = elf_m68k_hash_entry (_h);
2333 if (h->got_entry_key != 0)
2334 /* H has at least one entry in the GOT. */
2336 struct elf_m68k_partition_multi_got_arg *arg;
2338 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2340 BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL);
2341 arg->symndx2h[h->got_entry_key] = h;
2344 return TRUE;
2347 /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2348 lists of GOT entries for global symbols.
2349 Calculate sizes of .got and .rela.got sections. */
2351 static bfd_boolean
2352 elf_m68k_partition_multi_got (struct bfd_link_info *info)
2354 struct elf_m68k_multi_got *multi_got;
2355 struct elf_m68k_partition_multi_got_arg arg_;
2357 multi_got = elf_m68k_multi_got (info);
2359 arg_.current_got = NULL;
2360 arg_.offset = 0;
2361 arg_.info = info;
2362 arg_.n_slots = 0;
2363 arg_.slots_relas_diff = 0;
2364 arg_.error_p = FALSE;
2366 if (multi_got->bfd2got != NULL)
2368 /* Initialize symndx2h mapping. */
2370 arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx
2371 * sizeof (*arg_.symndx2h));
2372 if (arg_.symndx2h == NULL)
2373 return FALSE;
2375 elf_link_hash_traverse (elf_hash_table (info),
2376 elf_m68k_init_symndx2h_1, &arg_);
2379 /* Partition. */
2380 htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1,
2381 &arg_);
2382 if (arg_.error_p)
2384 free (arg_.symndx2h);
2385 arg_.symndx2h = NULL;
2387 return FALSE;
2390 /* Finish up last current_got. */
2391 elf_m68k_partition_multi_got_2 (&arg_);
2393 free (arg_.symndx2h);
2396 if (elf_hash_table (info)->dynobj != NULL)
2397 /* Set sizes of .got and .rela.got sections. */
2399 asection *s;
2401 s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".got");
2402 if (s != NULL)
2403 s->size = arg_.offset;
2404 else
2405 BFD_ASSERT (arg_.offset == 0);
2407 BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots);
2408 arg_.n_slots -= arg_.slots_relas_diff;
2410 s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".rela.got");
2411 if (s != NULL)
2412 s->size = arg_.n_slots * sizeof (Elf32_External_Rela);
2413 else
2414 BFD_ASSERT (arg_.n_slots == 0);
2416 else
2417 BFD_ASSERT (multi_got->bfd2got == NULL);
2419 return TRUE;
2422 /* Specialized version of elf_m68k_get_got_entry that returns pointer
2423 to hashtable slot, thus allowing removal of entry via
2424 elf_m68k_remove_got_entry. */
2426 static struct elf_m68k_got_entry **
2427 elf_m68k_find_got_entry_ptr (struct elf_m68k_got *got,
2428 struct elf_m68k_got_entry_key *key)
2430 void **ptr;
2431 struct elf_m68k_got_entry entry_;
2432 struct elf_m68k_got_entry **entry_ptr;
2434 entry_.key_ = *key;
2435 ptr = htab_find_slot (got->entries, &entry_, NO_INSERT);
2436 BFD_ASSERT (ptr != NULL);
2438 entry_ptr = (struct elf_m68k_got_entry **) ptr;
2440 return entry_ptr;
2443 /* Remove entry pointed to by ENTRY_PTR from GOT. */
2445 static void
2446 elf_m68k_remove_got_entry (struct elf_m68k_got *got,
2447 struct elf_m68k_got_entry **entry_ptr)
2449 struct elf_m68k_got_entry *entry;
2451 entry = *entry_ptr;
2453 /* Check that offsets have not been finalized yet. */
2454 BFD_ASSERT (got->offset == (bfd_vma) -1);
2455 /* Check that this entry is indeed unused. */
2456 BFD_ASSERT (entry->u.s1.refcount == 0);
2458 elf_m68k_remove_got_entry_type (got, entry->key_.type);
2460 if (entry->key_.bfd != NULL)
2461 got->local_n_slots -= elf_m68k_reloc_got_n_slots (entry->key_.type);
2463 BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
2465 htab_clear_slot (got->entries, (void **) entry_ptr);
2468 /* Copy any information related to dynamic linking from a pre-existing
2469 symbol to a newly created symbol. Also called to copy flags and
2470 other back-end info to a weakdef, in which case the symbol is not
2471 newly created and plt/got refcounts and dynamic indices should not
2472 be copied. */
2474 static void
2475 elf_m68k_copy_indirect_symbol (struct bfd_link_info *info,
2476 struct elf_link_hash_entry *_dir,
2477 struct elf_link_hash_entry *_ind)
2479 struct elf_m68k_link_hash_entry *dir;
2480 struct elf_m68k_link_hash_entry *ind;
2482 _bfd_elf_link_hash_copy_indirect (info, _dir, _ind);
2484 if (_ind->root.type != bfd_link_hash_indirect)
2485 return;
2487 dir = elf_m68k_hash_entry (_dir);
2488 ind = elf_m68k_hash_entry (_ind);
2490 /* We might have a direct symbol already having entries in the GOTs.
2491 Update its key only in case indirect symbol has GOT entries and
2492 assert that both indirect and direct symbols don't have GOT entries
2493 at the same time. */
2494 if (ind->got_entry_key != 0)
2496 BFD_ASSERT (dir->got_entry_key == 0);
2497 /* Assert that GOTs aren't partioned yet. */
2498 BFD_ASSERT (ind->glist == NULL);
2500 dir->got_entry_key = ind->got_entry_key;
2501 ind->got_entry_key = 0;
2505 /* Look through the relocs for a section during the first phase, and
2506 allocate space in the global offset table or procedure linkage
2507 table. */
2509 static bfd_boolean
2510 elf_m68k_check_relocs (abfd, info, sec, relocs)
2511 bfd *abfd;
2512 struct bfd_link_info *info;
2513 asection *sec;
2514 const Elf_Internal_Rela *relocs;
2516 bfd *dynobj;
2517 Elf_Internal_Shdr *symtab_hdr;
2518 struct elf_link_hash_entry **sym_hashes;
2519 const Elf_Internal_Rela *rel;
2520 const Elf_Internal_Rela *rel_end;
2521 asection *sgot;
2522 asection *srelgot;
2523 asection *sreloc;
2524 struct elf_m68k_got *got;
2526 if (info->relocatable)
2527 return TRUE;
2529 dynobj = elf_hash_table (info)->dynobj;
2530 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2531 sym_hashes = elf_sym_hashes (abfd);
2533 sgot = NULL;
2534 srelgot = NULL;
2535 sreloc = NULL;
2537 got = NULL;
2539 rel_end = relocs + sec->reloc_count;
2540 for (rel = relocs; rel < rel_end; rel++)
2542 unsigned long r_symndx;
2543 struct elf_link_hash_entry *h;
2545 r_symndx = ELF32_R_SYM (rel->r_info);
2547 if (r_symndx < symtab_hdr->sh_info)
2548 h = NULL;
2549 else
2551 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2552 while (h->root.type == bfd_link_hash_indirect
2553 || h->root.type == bfd_link_hash_warning)
2554 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2557 switch (ELF32_R_TYPE (rel->r_info))
2559 case R_68K_GOT8:
2560 case R_68K_GOT16:
2561 case R_68K_GOT32:
2562 if (h != NULL
2563 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2564 break;
2565 /* Fall through. */
2567 /* Relative GOT relocations. */
2568 case R_68K_GOT8O:
2569 case R_68K_GOT16O:
2570 case R_68K_GOT32O:
2571 /* Fall through. */
2573 /* TLS relocations. */
2574 case R_68K_TLS_GD8:
2575 case R_68K_TLS_GD16:
2576 case R_68K_TLS_GD32:
2577 case R_68K_TLS_LDM8:
2578 case R_68K_TLS_LDM16:
2579 case R_68K_TLS_LDM32:
2580 case R_68K_TLS_IE8:
2581 case R_68K_TLS_IE16:
2582 case R_68K_TLS_IE32:
2584 /* This symbol requires a global offset table entry. */
2586 if (dynobj == NULL)
2588 /* Create the .got section. */
2589 elf_hash_table (info)->dynobj = dynobj = abfd;
2590 if (!_bfd_elf_create_got_section (dynobj, info))
2591 return FALSE;
2594 if (sgot == NULL)
2596 sgot = bfd_get_section_by_name (dynobj, ".got");
2597 BFD_ASSERT (sgot != NULL);
2600 if (srelgot == NULL
2601 && (h != NULL || info->shared))
2603 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2604 if (srelgot == NULL)
2606 srelgot = bfd_make_section_with_flags (dynobj,
2607 ".rela.got",
2608 (SEC_ALLOC
2609 | SEC_LOAD
2610 | SEC_HAS_CONTENTS
2611 | SEC_IN_MEMORY
2612 | SEC_LINKER_CREATED
2613 | SEC_READONLY));
2614 if (srelgot == NULL
2615 || !bfd_set_section_alignment (dynobj, srelgot, 2))
2616 return FALSE;
2620 if (got == NULL)
2622 struct elf_m68k_bfd2got_entry *bfd2got_entry;
2624 bfd2got_entry
2625 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2626 abfd, FIND_OR_CREATE, info);
2627 if (bfd2got_entry == NULL)
2628 return FALSE;
2630 got = bfd2got_entry->got;
2631 BFD_ASSERT (got != NULL);
2635 struct elf_m68k_got_entry *got_entry;
2637 /* Add entry to got. */
2638 got_entry = elf_m68k_add_entry_to_got (got, h, abfd,
2639 ELF32_R_TYPE (rel->r_info),
2640 r_symndx, info);
2641 if (got_entry == NULL)
2642 return FALSE;
2644 if (got_entry->u.s1.refcount == 1)
2646 /* Make sure this symbol is output as a dynamic symbol. */
2647 if (h != NULL
2648 && h->dynindx == -1
2649 && !h->forced_local)
2651 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2652 return FALSE;
2657 break;
2659 case R_68K_PLT8:
2660 case R_68K_PLT16:
2661 case R_68K_PLT32:
2662 /* This symbol requires a procedure linkage table entry. We
2663 actually build the entry in adjust_dynamic_symbol,
2664 because this might be a case of linking PIC code which is
2665 never referenced by a dynamic object, in which case we
2666 don't need to generate a procedure linkage table entry
2667 after all. */
2669 /* If this is a local symbol, we resolve it directly without
2670 creating a procedure linkage table entry. */
2671 if (h == NULL)
2672 continue;
2674 h->needs_plt = 1;
2675 h->plt.refcount++;
2676 break;
2678 case R_68K_PLT8O:
2679 case R_68K_PLT16O:
2680 case R_68K_PLT32O:
2681 /* This symbol requires a procedure linkage table entry. */
2683 if (h == NULL)
2685 /* It does not make sense to have this relocation for a
2686 local symbol. FIXME: does it? How to handle it if
2687 it does make sense? */
2688 bfd_set_error (bfd_error_bad_value);
2689 return FALSE;
2692 /* Make sure this symbol is output as a dynamic symbol. */
2693 if (h->dynindx == -1
2694 && !h->forced_local)
2696 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2697 return FALSE;
2700 h->needs_plt = 1;
2701 h->plt.refcount++;
2702 break;
2704 case R_68K_PC8:
2705 case R_68K_PC16:
2706 case R_68K_PC32:
2707 /* If we are creating a shared library and this is not a local
2708 symbol, we need to copy the reloc into the shared library.
2709 However when linking with -Bsymbolic and this is a global
2710 symbol which is defined in an object we are including in the
2711 link (i.e., DEF_REGULAR is set), then we can resolve the
2712 reloc directly. At this point we have not seen all the input
2713 files, so it is possible that DEF_REGULAR is not set now but
2714 will be set later (it is never cleared). We account for that
2715 possibility below by storing information in the
2716 pcrel_relocs_copied field of the hash table entry. */
2717 if (!(info->shared
2718 && (sec->flags & SEC_ALLOC) != 0
2719 && h != NULL
2720 && (!info->symbolic
2721 || h->root.type == bfd_link_hash_defweak
2722 || !h->def_regular)))
2724 if (h != NULL)
2726 /* Make sure a plt entry is created for this symbol if
2727 it turns out to be a function defined by a dynamic
2728 object. */
2729 h->plt.refcount++;
2731 break;
2733 /* Fall through. */
2734 case R_68K_8:
2735 case R_68K_16:
2736 case R_68K_32:
2737 if (h != NULL)
2739 /* Make sure a plt entry is created for this symbol if it
2740 turns out to be a function defined by a dynamic object. */
2741 h->plt.refcount++;
2744 /* If we are creating a shared library, we need to copy the
2745 reloc into the shared library. */
2746 if (info->shared
2747 && (sec->flags & SEC_ALLOC) != 0)
2749 /* When creating a shared object, we must copy these
2750 reloc types into the output file. We create a reloc
2751 section in dynobj and make room for this reloc. */
2752 if (sreloc == NULL)
2754 sreloc = _bfd_elf_make_dynamic_reloc_section
2755 (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2757 if (sreloc == NULL)
2758 return FALSE;
2761 if (sec->flags & SEC_READONLY
2762 /* Don't set DF_TEXTREL yet for PC relative
2763 relocations, they might be discarded later. */
2764 && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2765 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2766 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
2767 info->flags |= DF_TEXTREL;
2769 sreloc->size += sizeof (Elf32_External_Rela);
2771 /* We count the number of PC relative relocations we have
2772 entered for this symbol, so that we can discard them
2773 again if, in the -Bsymbolic case, the symbol is later
2774 defined by a regular object, or, in the normal shared
2775 case, the symbol is forced to be local. Note that this
2776 function is only called if we are using an m68kelf linker
2777 hash table, which means that h is really a pointer to an
2778 elf_m68k_link_hash_entry. */
2779 if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2780 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2781 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
2783 struct elf_m68k_pcrel_relocs_copied *p;
2784 struct elf_m68k_pcrel_relocs_copied **head;
2786 if (h != NULL)
2788 struct elf_m68k_link_hash_entry *eh
2789 = elf_m68k_hash_entry (h);
2790 head = &eh->pcrel_relocs_copied;
2792 else
2794 asection *s;
2795 void *vpp;
2796 Elf_Internal_Sym *isym;
2798 isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->sym_cache,
2799 abfd, r_symndx);
2800 if (isym == NULL)
2801 return FALSE;
2803 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2804 if (s == NULL)
2805 s = sec;
2807 vpp = &elf_section_data (s)->local_dynrel;
2808 head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
2811 for (p = *head; p != NULL; p = p->next)
2812 if (p->section == sreloc)
2813 break;
2815 if (p == NULL)
2817 p = ((struct elf_m68k_pcrel_relocs_copied *)
2818 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
2819 if (p == NULL)
2820 return FALSE;
2821 p->next = *head;
2822 *head = p;
2823 p->section = sreloc;
2824 p->count = 0;
2827 ++p->count;
2831 break;
2833 /* This relocation describes the C++ object vtable hierarchy.
2834 Reconstruct it for later use during GC. */
2835 case R_68K_GNU_VTINHERIT:
2836 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2837 return FALSE;
2838 break;
2840 /* This relocation describes which C++ vtable entries are actually
2841 used. Record for later use during GC. */
2842 case R_68K_GNU_VTENTRY:
2843 BFD_ASSERT (h != NULL);
2844 if (h != NULL
2845 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2846 return FALSE;
2847 break;
2849 default:
2850 break;
2854 return TRUE;
2857 /* Return the section that should be marked against GC for a given
2858 relocation. */
2860 static asection *
2861 elf_m68k_gc_mark_hook (asection *sec,
2862 struct bfd_link_info *info,
2863 Elf_Internal_Rela *rel,
2864 struct elf_link_hash_entry *h,
2865 Elf_Internal_Sym *sym)
2867 if (h != NULL)
2868 switch (ELF32_R_TYPE (rel->r_info))
2870 case R_68K_GNU_VTINHERIT:
2871 case R_68K_GNU_VTENTRY:
2872 return NULL;
2875 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2878 /* Update the got entry reference counts for the section being removed. */
2880 static bfd_boolean
2881 elf_m68k_gc_sweep_hook (bfd *abfd,
2882 struct bfd_link_info *info,
2883 asection *sec,
2884 const Elf_Internal_Rela *relocs)
2886 Elf_Internal_Shdr *symtab_hdr;
2887 struct elf_link_hash_entry **sym_hashes;
2888 const Elf_Internal_Rela *rel, *relend;
2889 bfd *dynobj;
2890 asection *sgot;
2891 asection *srelgot;
2892 struct elf_m68k_got *got;
2894 if (info->relocatable)
2895 return TRUE;
2897 dynobj = elf_hash_table (info)->dynobj;
2898 if (dynobj == NULL)
2899 return TRUE;
2901 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2902 sym_hashes = elf_sym_hashes (abfd);
2904 sgot = bfd_get_section_by_name (dynobj, ".got");
2905 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2906 got = NULL;
2908 relend = relocs + sec->reloc_count;
2909 for (rel = relocs; rel < relend; rel++)
2911 unsigned long r_symndx;
2912 struct elf_link_hash_entry *h = NULL;
2914 r_symndx = ELF32_R_SYM (rel->r_info);
2915 if (r_symndx >= symtab_hdr->sh_info)
2917 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2918 while (h->root.type == bfd_link_hash_indirect
2919 || h->root.type == bfd_link_hash_warning)
2920 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2923 switch (ELF32_R_TYPE (rel->r_info))
2925 case R_68K_GOT8:
2926 case R_68K_GOT16:
2927 case R_68K_GOT32:
2928 if (h != NULL
2929 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2930 break;
2932 /* FALLTHRU */
2933 case R_68K_GOT8O:
2934 case R_68K_GOT16O:
2935 case R_68K_GOT32O:
2936 /* Fall through. */
2938 /* TLS relocations. */
2939 case R_68K_TLS_GD8:
2940 case R_68K_TLS_GD16:
2941 case R_68K_TLS_GD32:
2942 case R_68K_TLS_LDM8:
2943 case R_68K_TLS_LDM16:
2944 case R_68K_TLS_LDM32:
2945 case R_68K_TLS_IE8:
2946 case R_68K_TLS_IE16:
2947 case R_68K_TLS_IE32:
2949 if (got == NULL)
2951 got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2952 abfd, MUST_FIND, NULL)->got;
2953 BFD_ASSERT (got != NULL);
2957 struct elf_m68k_got_entry_key key_;
2958 struct elf_m68k_got_entry **got_entry_ptr;
2959 struct elf_m68k_got_entry *got_entry;
2961 elf_m68k_init_got_entry_key (&key_, h, abfd, r_symndx,
2962 ELF32_R_TYPE (rel->r_info));
2963 got_entry_ptr = elf_m68k_find_got_entry_ptr (got, &key_);
2965 got_entry = *got_entry_ptr;
2967 if (got_entry->u.s1.refcount > 0)
2969 --got_entry->u.s1.refcount;
2971 if (got_entry->u.s1.refcount == 0)
2972 /* We don't need the .got entry any more. */
2973 elf_m68k_remove_got_entry (got, got_entry_ptr);
2976 break;
2978 case R_68K_PLT8:
2979 case R_68K_PLT16:
2980 case R_68K_PLT32:
2981 case R_68K_PLT8O:
2982 case R_68K_PLT16O:
2983 case R_68K_PLT32O:
2984 case R_68K_PC8:
2985 case R_68K_PC16:
2986 case R_68K_PC32:
2987 case R_68K_8:
2988 case R_68K_16:
2989 case R_68K_32:
2990 if (h != NULL)
2992 if (h->plt.refcount > 0)
2993 --h->plt.refcount;
2995 break;
2997 default:
2998 break;
3002 return TRUE;
3005 /* Return the type of PLT associated with OUTPUT_BFD. */
3007 static const struct elf_m68k_plt_info *
3008 elf_m68k_get_plt_info (bfd *output_bfd)
3010 unsigned int features;
3012 features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
3013 if (features & cpu32)
3014 return &elf_cpu32_plt_info;
3015 if (features & mcfisa_b)
3016 return &elf_isab_plt_info;
3017 if (features & mcfisa_c)
3018 return &elf_isac_plt_info;
3019 return &elf_m68k_plt_info;
3022 /* This function is called after all the input files have been read,
3023 and the input sections have been assigned to output sections.
3024 It's a convenient place to determine the PLT style. */
3026 static bfd_boolean
3027 elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3029 /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
3030 sections. */
3031 if (!elf_m68k_partition_multi_got (info))
3032 return FALSE;
3034 elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
3035 return TRUE;
3038 /* Adjust a symbol defined by a dynamic object and referenced by a
3039 regular object. The current definition is in some section of the
3040 dynamic object, but we're not including those sections. We have to
3041 change the definition to something the rest of the link can
3042 understand. */
3044 static bfd_boolean
3045 elf_m68k_adjust_dynamic_symbol (info, h)
3046 struct bfd_link_info *info;
3047 struct elf_link_hash_entry *h;
3049 struct elf_m68k_link_hash_table *htab;
3050 bfd *dynobj;
3051 asection *s;
3053 htab = elf_m68k_hash_table (info);
3054 dynobj = elf_hash_table (info)->dynobj;
3056 /* Make sure we know what is going on here. */
3057 BFD_ASSERT (dynobj != NULL
3058 && (h->needs_plt
3059 || h->u.weakdef != NULL
3060 || (h->def_dynamic
3061 && h->ref_regular
3062 && !h->def_regular)));
3064 /* If this is a function, put it in the procedure linkage table. We
3065 will fill in the contents of the procedure linkage table later,
3066 when we know the address of the .got section. */
3067 if (h->type == STT_FUNC
3068 || h->needs_plt)
3070 if ((h->plt.refcount <= 0
3071 || SYMBOL_CALLS_LOCAL (info, h)
3072 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3073 && h->root.type == bfd_link_hash_undefweak))
3074 /* We must always create the plt entry if it was referenced
3075 by a PLTxxO relocation. In this case we already recorded
3076 it as a dynamic symbol. */
3077 && h->dynindx == -1)
3079 /* This case can occur if we saw a PLTxx reloc in an input
3080 file, but the symbol was never referred to by a dynamic
3081 object, or if all references were garbage collected. In
3082 such a case, we don't actually need to build a procedure
3083 linkage table, and we can just do a PCxx reloc instead. */
3084 h->plt.offset = (bfd_vma) -1;
3085 h->needs_plt = 0;
3086 return TRUE;
3089 /* Make sure this symbol is output as a dynamic symbol. */
3090 if (h->dynindx == -1
3091 && !h->forced_local)
3093 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3094 return FALSE;
3097 s = bfd_get_section_by_name (dynobj, ".plt");
3098 BFD_ASSERT (s != NULL);
3100 /* If this is the first .plt entry, make room for the special
3101 first entry. */
3102 if (s->size == 0)
3103 s->size = htab->plt_info->size;
3105 /* If this symbol is not defined in a regular file, and we are
3106 not generating a shared library, then set the symbol to this
3107 location in the .plt. This is required to make function
3108 pointers compare as equal between the normal executable and
3109 the shared library. */
3110 if (!info->shared
3111 && !h->def_regular)
3113 h->root.u.def.section = s;
3114 h->root.u.def.value = s->size;
3117 h->plt.offset = s->size;
3119 /* Make room for this entry. */
3120 s->size += htab->plt_info->size;
3122 /* We also need to make an entry in the .got.plt section, which
3123 will be placed in the .got section by the linker script. */
3124 s = bfd_get_section_by_name (dynobj, ".got.plt");
3125 BFD_ASSERT (s != NULL);
3126 s->size += 4;
3128 /* We also need to make an entry in the .rela.plt section. */
3129 s = bfd_get_section_by_name (dynobj, ".rela.plt");
3130 BFD_ASSERT (s != NULL);
3131 s->size += sizeof (Elf32_External_Rela);
3133 return TRUE;
3136 /* Reinitialize the plt offset now that it is not used as a reference
3137 count any more. */
3138 h->plt.offset = (bfd_vma) -1;
3140 /* If this is a weak symbol, and there is a real definition, the
3141 processor independent code will have arranged for us to see the
3142 real definition first, and we can just use the same value. */
3143 if (h->u.weakdef != NULL)
3145 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3146 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3147 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3148 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3149 return TRUE;
3152 /* This is a reference to a symbol defined by a dynamic object which
3153 is not a function. */
3155 /* If we are creating a shared library, we must presume that the
3156 only references to the symbol are via the global offset table.
3157 For such cases we need not do anything here; the relocations will
3158 be handled correctly by relocate_section. */
3159 if (info->shared)
3160 return TRUE;
3162 if (h->size == 0)
3164 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
3165 h->root.root.string);
3166 return TRUE;
3169 /* We must allocate the symbol in our .dynbss section, which will
3170 become part of the .bss section of the executable. There will be
3171 an entry for this symbol in the .dynsym section. The dynamic
3172 object will contain position independent code, so all references
3173 from the dynamic object to this symbol will go through the global
3174 offset table. The dynamic linker will use the .dynsym entry to
3175 determine the address it must put in the global offset table, so
3176 both the dynamic object and the regular object will refer to the
3177 same memory location for the variable. */
3179 s = bfd_get_section_by_name (dynobj, ".dynbss");
3180 BFD_ASSERT (s != NULL);
3182 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3183 copy the initial value out of the dynamic object and into the
3184 runtime process image. We need to remember the offset into the
3185 .rela.bss section we are going to use. */
3186 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3188 asection *srel;
3190 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
3191 BFD_ASSERT (srel != NULL);
3192 srel->size += sizeof (Elf32_External_Rela);
3193 h->needs_copy = 1;
3196 return _bfd_elf_adjust_dynamic_copy (h, s);
3199 /* Set the sizes of the dynamic sections. */
3201 static bfd_boolean
3202 elf_m68k_size_dynamic_sections (output_bfd, info)
3203 bfd *output_bfd ATTRIBUTE_UNUSED;
3204 struct bfd_link_info *info;
3206 bfd *dynobj;
3207 asection *s;
3208 bfd_boolean plt;
3209 bfd_boolean relocs;
3211 dynobj = elf_hash_table (info)->dynobj;
3212 BFD_ASSERT (dynobj != NULL);
3214 if (elf_hash_table (info)->dynamic_sections_created)
3216 /* Set the contents of the .interp section to the interpreter. */
3217 if (info->executable)
3219 s = bfd_get_section_by_name (dynobj, ".interp");
3220 BFD_ASSERT (s != NULL);
3221 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3222 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3225 else
3227 /* We may have created entries in the .rela.got section.
3228 However, if we are not creating the dynamic sections, we will
3229 not actually use these entries. Reset the size of .rela.got,
3230 which will cause it to get stripped from the output file
3231 below. */
3232 s = bfd_get_section_by_name (dynobj, ".rela.got");
3233 if (s != NULL)
3234 s->size = 0;
3237 /* If this is a -Bsymbolic shared link, then we need to discard all
3238 PC relative relocs against symbols defined in a regular object.
3239 For the normal shared case we discard the PC relative relocs
3240 against symbols that have become local due to visibility changes.
3241 We allocated space for them in the check_relocs routine, but we
3242 will not fill them in in the relocate_section routine. */
3243 if (info->shared)
3244 elf_link_hash_traverse (elf_hash_table (info),
3245 elf_m68k_discard_copies,
3246 (PTR) info);
3248 /* The check_relocs and adjust_dynamic_symbol entry points have
3249 determined the sizes of the various dynamic sections. Allocate
3250 memory for them. */
3251 plt = FALSE;
3252 relocs = FALSE;
3253 for (s = dynobj->sections; s != NULL; s = s->next)
3255 const char *name;
3257 if ((s->flags & SEC_LINKER_CREATED) == 0)
3258 continue;
3260 /* It's OK to base decisions on the section name, because none
3261 of the dynobj section names depend upon the input files. */
3262 name = bfd_get_section_name (dynobj, s);
3264 if (strcmp (name, ".plt") == 0)
3266 /* Remember whether there is a PLT. */
3267 plt = s->size != 0;
3269 else if (CONST_STRNEQ (name, ".rela"))
3271 if (s->size != 0)
3273 relocs = TRUE;
3275 /* We use the reloc_count field as a counter if we need
3276 to copy relocs into the output file. */
3277 s->reloc_count = 0;
3280 else if (! CONST_STRNEQ (name, ".got")
3281 && strcmp (name, ".dynbss") != 0)
3283 /* It's not one of our sections, so don't allocate space. */
3284 continue;
3287 if (s->size == 0)
3289 /* If we don't need this section, strip it from the
3290 output file. This is mostly to handle .rela.bss and
3291 .rela.plt. We must create both sections in
3292 create_dynamic_sections, because they must be created
3293 before the linker maps input sections to output
3294 sections. The linker does that before
3295 adjust_dynamic_symbol is called, and it is that
3296 function which decides whether anything needs to go
3297 into these sections. */
3298 s->flags |= SEC_EXCLUDE;
3299 continue;
3302 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3303 continue;
3305 /* Allocate memory for the section contents. */
3306 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3307 Unused entries should be reclaimed before the section's contents
3308 are written out, but at the moment this does not happen. Thus in
3309 order to prevent writing out garbage, we initialise the section's
3310 contents to zero. */
3311 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3312 if (s->contents == NULL)
3313 return FALSE;
3316 if (elf_hash_table (info)->dynamic_sections_created)
3318 /* Add some entries to the .dynamic section. We fill in the
3319 values later, in elf_m68k_finish_dynamic_sections, but we
3320 must add the entries now so that we get the correct size for
3321 the .dynamic section. The DT_DEBUG entry is filled in by the
3322 dynamic linker and used by the debugger. */
3323 #define add_dynamic_entry(TAG, VAL) \
3324 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3326 if (!info->shared)
3328 if (!add_dynamic_entry (DT_DEBUG, 0))
3329 return FALSE;
3332 if (plt)
3334 if (!add_dynamic_entry (DT_PLTGOT, 0)
3335 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3336 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3337 || !add_dynamic_entry (DT_JMPREL, 0))
3338 return FALSE;
3341 if (relocs)
3343 if (!add_dynamic_entry (DT_RELA, 0)
3344 || !add_dynamic_entry (DT_RELASZ, 0)
3345 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3346 return FALSE;
3349 if ((info->flags & DF_TEXTREL) != 0)
3351 if (!add_dynamic_entry (DT_TEXTREL, 0))
3352 return FALSE;
3355 #undef add_dynamic_entry
3357 return TRUE;
3360 /* This function is called via elf_link_hash_traverse if we are
3361 creating a shared object. In the -Bsymbolic case it discards the
3362 space allocated to copy PC relative relocs against symbols which
3363 are defined in regular objects. For the normal shared case, it
3364 discards space for pc-relative relocs that have become local due to
3365 symbol visibility changes. We allocated space for them in the
3366 check_relocs routine, but we won't fill them in in the
3367 relocate_section routine.
3369 We also check whether any of the remaining relocations apply
3370 against a readonly section, and set the DF_TEXTREL flag in this
3371 case. */
3373 static bfd_boolean
3374 elf_m68k_discard_copies (h, inf)
3375 struct elf_link_hash_entry *h;
3376 PTR inf;
3378 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3379 struct elf_m68k_pcrel_relocs_copied *s;
3381 if (h->root.type == bfd_link_hash_warning)
3382 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3384 if (!SYMBOL_CALLS_LOCAL (info, h))
3386 if ((info->flags & DF_TEXTREL) == 0)
3388 /* Look for relocations against read-only sections. */
3389 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3390 s != NULL;
3391 s = s->next)
3392 if ((s->section->flags & SEC_READONLY) != 0)
3394 info->flags |= DF_TEXTREL;
3395 break;
3399 return TRUE;
3402 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3403 s != NULL;
3404 s = s->next)
3405 s->section->size -= s->count * sizeof (Elf32_External_Rela);
3407 return TRUE;
3411 /* Install relocation RELA. */
3413 static void
3414 elf_m68k_install_rela (bfd *output_bfd,
3415 asection *srela,
3416 Elf_Internal_Rela *rela)
3418 bfd_byte *loc;
3420 loc = srela->contents;
3421 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
3422 bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
3425 /* Return the base VMA address which should be subtracted from real addresses
3426 when resolving @dtpoff relocation.
3427 This is PT_TLS segment p_vaddr. */
3429 static bfd_vma
3430 dtpoff_base (struct bfd_link_info *info)
3432 /* If tls_sec is NULL, we should have signalled an error already. */
3433 if (elf_hash_table (info)->tls_sec == NULL)
3434 return 0;
3435 return elf_hash_table (info)->tls_sec->vma;
3438 /* Return the relocation value for @tpoff relocation
3439 if STT_TLS virtual address is ADDRESS. */
3441 static bfd_vma
3442 tpoff (struct bfd_link_info *info, bfd_vma address)
3444 struct elf_link_hash_table *htab = elf_hash_table (info);
3445 bfd_vma base;
3447 /* If tls_sec is NULL, we should have signalled an error already. */
3448 if (htab->tls_sec == NULL)
3449 return 0;
3450 base = align_power ((bfd_vma) 8, htab->tls_sec->alignment_power);
3451 return address - htab->tls_sec->vma + base;
3454 /* Relocate an M68K ELF section. */
3456 static bfd_boolean
3457 elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section,
3458 contents, relocs, local_syms, local_sections)
3459 bfd *output_bfd;
3460 struct bfd_link_info *info;
3461 bfd *input_bfd;
3462 asection *input_section;
3463 bfd_byte *contents;
3464 Elf_Internal_Rela *relocs;
3465 Elf_Internal_Sym *local_syms;
3466 asection **local_sections;
3468 bfd *dynobj;
3469 Elf_Internal_Shdr *symtab_hdr;
3470 struct elf_link_hash_entry **sym_hashes;
3471 asection *sgot;
3472 asection *splt;
3473 asection *sreloc;
3474 struct elf_m68k_got *got;
3475 Elf_Internal_Rela *rel;
3476 Elf_Internal_Rela *relend;
3478 dynobj = elf_hash_table (info)->dynobj;
3479 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3480 sym_hashes = elf_sym_hashes (input_bfd);
3482 sgot = NULL;
3483 splt = NULL;
3484 sreloc = NULL;
3486 got = NULL;
3488 rel = relocs;
3489 relend = relocs + input_section->reloc_count;
3490 for (; rel < relend; rel++)
3492 int r_type;
3493 reloc_howto_type *howto;
3494 unsigned long r_symndx;
3495 struct elf_link_hash_entry *h;
3496 Elf_Internal_Sym *sym;
3497 asection *sec;
3498 bfd_vma relocation;
3499 bfd_boolean unresolved_reloc;
3500 bfd_reloc_status_type r;
3502 r_type = ELF32_R_TYPE (rel->r_info);
3503 if (r_type < 0 || r_type >= (int) R_68K_max)
3505 bfd_set_error (bfd_error_bad_value);
3506 return FALSE;
3508 howto = howto_table + r_type;
3510 r_symndx = ELF32_R_SYM (rel->r_info);
3512 h = NULL;
3513 sym = NULL;
3514 sec = NULL;
3515 unresolved_reloc = FALSE;
3517 if (r_symndx < symtab_hdr->sh_info)
3519 sym = local_syms + r_symndx;
3520 sec = local_sections[r_symndx];
3521 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3523 else
3525 bfd_boolean warned;
3527 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3528 r_symndx, symtab_hdr, sym_hashes,
3529 h, sec, relocation,
3530 unresolved_reloc, warned);
3533 if (sec != NULL && elf_discarded_section (sec))
3535 /* For relocs against symbols from removed linkonce sections,
3536 or sections discarded by a linker script, we just want the
3537 section contents zeroed. Avoid any special processing. */
3538 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
3539 rel->r_info = 0;
3540 rel->r_addend = 0;
3541 continue;
3544 if (info->relocatable)
3545 continue;
3547 switch (r_type)
3549 case R_68K_GOT8:
3550 case R_68K_GOT16:
3551 case R_68K_GOT32:
3552 /* Relocation is to the address of the entry for this symbol
3553 in the global offset table. */
3554 if (h != NULL
3555 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3557 if (elf_m68k_hash_table (info)->local_gp_p)
3559 bfd_vma sgot_output_offset;
3560 bfd_vma got_offset;
3562 if (sgot == NULL)
3564 sgot = bfd_get_section_by_name (dynobj, ".got");
3566 if (sgot != NULL)
3567 sgot_output_offset = sgot->output_offset;
3568 else
3569 /* In this case we have a reference to
3570 _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3571 empty.
3572 ??? Issue a warning? */
3573 sgot_output_offset = 0;
3575 else
3576 sgot_output_offset = sgot->output_offset;
3578 if (got == NULL)
3580 struct elf_m68k_bfd2got_entry *bfd2got_entry;
3582 bfd2got_entry
3583 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3584 input_bfd, SEARCH, NULL);
3586 if (bfd2got_entry != NULL)
3588 got = bfd2got_entry->got;
3589 BFD_ASSERT (got != NULL);
3591 got_offset = got->offset;
3593 else
3594 /* In this case we have a reference to
3595 _GLOBAL_OFFSET_TABLE_, but no other references
3596 accessing any GOT entries.
3597 ??? Issue a warning? */
3598 got_offset = 0;
3600 else
3601 got_offset = got->offset;
3603 /* Adjust GOT pointer to point to the GOT
3604 assigned to input_bfd. */
3605 rel->r_addend += sgot_output_offset + got_offset;
3607 else
3608 BFD_ASSERT (got == NULL || got->offset == 0);
3610 break;
3612 /* Fall through. */
3613 case R_68K_GOT8O:
3614 case R_68K_GOT16O:
3615 case R_68K_GOT32O:
3617 case R_68K_TLS_LDM32:
3618 case R_68K_TLS_LDM16:
3619 case R_68K_TLS_LDM8:
3621 case R_68K_TLS_GD8:
3622 case R_68K_TLS_GD16:
3623 case R_68K_TLS_GD32:
3625 case R_68K_TLS_IE8:
3626 case R_68K_TLS_IE16:
3627 case R_68K_TLS_IE32:
3629 /* Relocation is the offset of the entry for this symbol in
3630 the global offset table. */
3633 struct elf_m68k_got_entry_key key_;
3634 bfd_vma *off_ptr;
3635 bfd_vma off;
3637 if (sgot == NULL)
3639 sgot = bfd_get_section_by_name (dynobj, ".got");
3640 BFD_ASSERT (sgot != NULL);
3643 if (got == NULL)
3645 got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3646 input_bfd, MUST_FIND,
3647 NULL)->got;
3648 BFD_ASSERT (got != NULL);
3651 /* Get GOT offset for this symbol. */
3652 elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx,
3653 r_type);
3654 off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND,
3655 NULL)->u.s2.offset;
3656 off = *off_ptr;
3658 /* The offset must always be a multiple of 4. We use
3659 the least significant bit to record whether we have
3660 already generated the necessary reloc. */
3661 if ((off & 1) != 0)
3662 off &= ~1;
3663 else
3665 if (h != NULL
3666 /* @TLSLDM relocations are bounded to the module, in
3667 which the symbol is defined -- not to the symbol
3668 itself. */
3669 && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32)
3671 bfd_boolean dyn;
3673 dyn = elf_hash_table (info)->dynamic_sections_created;
3674 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3675 || (info->shared
3676 && SYMBOL_REFERENCES_LOCAL (info, h))
3677 || (ELF_ST_VISIBILITY (h->other)
3678 && h->root.type == bfd_link_hash_undefweak))
3680 /* This is actually a static link, or it is a
3681 -Bsymbolic link and the symbol is defined
3682 locally, or the symbol was forced to be local
3683 because of a version file.. We must initialize
3684 this entry in the global offset table. Since
3685 the offset must always be a multiple of 4, we
3686 use the least significant bit to record whether
3687 we have initialized it already.
3689 When doing a dynamic link, we create a .rela.got
3690 relocation entry to initialize the value. This
3691 is done in the finish_dynamic_symbol routine. */
3693 if (elf_m68k_reloc_got_type (r_type) == R_68K_GOT32O)
3694 bfd_put_32 (output_bfd, relocation,
3695 sgot->contents + off);
3696 else if (elf_m68k_reloc_got_type (r_type)
3697 == R_68K_TLS_GD32)
3698 /* Mark it as belonging to module 1,
3699 the executable. */
3701 bfd_put_32 (output_bfd, 1,
3702 sgot->contents + off);
3703 bfd_put_32 (output_bfd, (relocation
3704 - dtpoff_base (info)),
3705 sgot->contents + off + 4);
3707 else if (elf_m68k_reloc_got_type (r_type)
3708 == R_68K_TLS_IE32)
3709 bfd_put_32 (output_bfd, tpoff (info, relocation),
3710 sgot->contents + off);
3711 else
3712 BFD_ASSERT (FALSE);
3714 *off_ptr |= 1;
3716 else
3717 unresolved_reloc = FALSE;
3719 else if (info->shared) /* && h == NULL */
3721 asection *srela;
3722 Elf_Internal_Rela outrel;
3724 srela = bfd_get_section_by_name (dynobj, ".rela.got");
3725 BFD_ASSERT (srela != NULL);
3727 if (elf_m68k_reloc_got_type (r_type) == R_68K_GOT32O)
3729 /* Emit RELATIVE relocation to initialize GOT slot
3730 at run-time. */
3731 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3732 outrel.r_addend = relocation;
3733 outrel.r_offset = (sgot->output_section->vma
3734 + sgot->output_offset
3735 + off);
3737 elf_m68k_install_rela (output_bfd, srela, &outrel);
3739 else if (elf_m68k_reloc_got_type (r_type)
3740 == R_68K_TLS_LDM32)
3742 /* If we don't know the module number, create
3743 a relocation for it. */
3744 outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
3745 outrel.r_addend = 0;
3746 outrel.r_offset = (sgot->output_section->vma
3747 + sgot->output_offset
3748 + off);
3750 elf_m68k_install_rela (output_bfd, srela, &outrel);
3752 else if (elf_m68k_reloc_got_type (r_type)
3753 == R_68K_TLS_GD32)
3755 /* If we don't know the module number, create
3756 a relocation for it. */
3757 outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
3758 outrel.r_addend = 0;
3759 outrel.r_offset = (sgot->output_section->vma
3760 + sgot->output_offset
3761 + off);
3763 elf_m68k_install_rela (output_bfd, srela, &outrel);
3765 bfd_put_32 (output_bfd, (relocation
3766 - dtpoff_base (info)),
3767 sgot->contents + off + 4);
3769 else if (elf_m68k_reloc_got_type (r_type)
3770 == R_68K_TLS_IE32)
3772 outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32);
3773 outrel.r_addend = relocation - dtpoff_base (info);
3774 outrel.r_offset = (sgot->output_section->vma
3775 + sgot->output_offset
3776 + off);
3778 elf_m68k_install_rela (output_bfd, srela, &outrel);
3780 else
3781 BFD_ASSERT (FALSE);
3783 bfd_put_32 (output_bfd, outrel.r_addend,
3784 sgot->contents + off);
3786 *off_ptr |= 1;
3788 else /* h == NULL && !info->shared */
3790 if (elf_m68k_reloc_got_type (r_type) == R_68K_GOT32O)
3791 bfd_put_32 (output_bfd, relocation,
3792 sgot->contents + off);
3793 else if (elf_m68k_reloc_got_type (r_type)
3794 == R_68K_TLS_LDM32)
3795 /* If this is a static link, put the number of the
3796 only module in the GOT slot. */
3797 bfd_put_32 (output_bfd, 1, sgot->contents + off);
3798 else if (elf_m68k_reloc_got_type (r_type)
3799 == R_68K_TLS_GD32)
3801 /* If we are not emitting relocations for a
3802 general dynamic reference, then we must be in a
3803 static link or an executable link with the
3804 symbol binding locally. Mark it as belonging
3805 to module 1, the executable. */
3806 bfd_put_32 (output_bfd, 1, sgot->contents + off);
3807 bfd_put_32 (output_bfd, (relocation
3808 - dtpoff_base (info)),
3809 sgot->contents + off + 4);
3811 else if (elf_m68k_reloc_got_type (r_type)
3812 == R_68K_TLS_IE32)
3813 bfd_put_32 (output_bfd, tpoff (info, relocation),
3814 sgot->contents + off);
3815 else
3816 BFD_ASSERT (FALSE);
3818 *off_ptr |= 1;
3822 /* We don't use elf_m68k_reloc_got_type in the condition below
3823 because this is the only place where difference between
3824 R_68K_GOTx and R_68K_GOTxO relocations matters. */
3825 if (r_type == R_68K_GOT32O
3826 || r_type == R_68K_GOT16O
3827 || r_type == R_68K_GOT8O
3828 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32
3829 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32
3830 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32)
3832 /* GOT pointer is adjusted to point to the start/middle
3833 of local GOT. Adjust the offset accordingly. */
3834 BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p
3835 || off >= got->offset);
3837 if (elf_m68k_hash_table (info)->local_gp_p)
3838 relocation = off - got->offset;
3839 else
3841 BFD_ASSERT (got->offset == 0);
3842 relocation = sgot->output_offset + off;
3845 /* This relocation does not use the addend. */
3846 BFD_ASSERT (rel->r_addend == 0);
3847 rel->r_addend = 0;
3849 else
3850 relocation = (sgot->output_section->vma + sgot->output_offset
3851 + off);
3853 break;
3855 case R_68K_TLS_LDO32:
3856 case R_68K_TLS_LDO16:
3857 case R_68K_TLS_LDO8:
3858 relocation -= dtpoff_base (info);
3859 break;
3861 case R_68K_TLS_LE32:
3862 case R_68K_TLS_LE16:
3863 case R_68K_TLS_LE8:
3864 if (info->shared)
3866 (*_bfd_error_handler)
3867 (_("%B(%A+0x%lx): R_68K_TLS_LE32 relocation not permitted "
3868 "in shared object"),
3869 input_bfd, input_section, (long) rel->r_offset, howto->name);
3871 return FALSE;
3873 else
3874 relocation = tpoff (info, relocation);
3876 break;
3878 case R_68K_PLT8:
3879 case R_68K_PLT16:
3880 case R_68K_PLT32:
3881 /* Relocation is to the entry for this symbol in the
3882 procedure linkage table. */
3884 /* Resolve a PLTxx reloc against a local symbol directly,
3885 without using the procedure linkage table. */
3886 if (h == NULL)
3887 break;
3889 if (h->plt.offset == (bfd_vma) -1
3890 || !elf_hash_table (info)->dynamic_sections_created)
3892 /* We didn't make a PLT entry for this symbol. This
3893 happens when statically linking PIC code, or when
3894 using -Bsymbolic. */
3895 break;
3898 if (splt == NULL)
3900 splt = bfd_get_section_by_name (dynobj, ".plt");
3901 BFD_ASSERT (splt != NULL);
3904 relocation = (splt->output_section->vma
3905 + splt->output_offset
3906 + h->plt.offset);
3907 unresolved_reloc = FALSE;
3908 break;
3910 case R_68K_PLT8O:
3911 case R_68K_PLT16O:
3912 case R_68K_PLT32O:
3913 /* Relocation is the offset of the entry for this symbol in
3914 the procedure linkage table. */
3915 BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
3917 if (splt == NULL)
3919 splt = bfd_get_section_by_name (dynobj, ".plt");
3920 BFD_ASSERT (splt != NULL);
3923 relocation = h->plt.offset;
3924 unresolved_reloc = FALSE;
3926 /* This relocation does not use the addend. */
3927 rel->r_addend = 0;
3929 break;
3931 case R_68K_8:
3932 case R_68K_16:
3933 case R_68K_32:
3934 case R_68K_PC8:
3935 case R_68K_PC16:
3936 case R_68K_PC32:
3937 if (info->shared
3938 && r_symndx != 0
3939 && (input_section->flags & SEC_ALLOC) != 0
3940 && (h == NULL
3941 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3942 || h->root.type != bfd_link_hash_undefweak)
3943 && ((r_type != R_68K_PC8
3944 && r_type != R_68K_PC16
3945 && r_type != R_68K_PC32)
3946 || !SYMBOL_CALLS_LOCAL (info, h)))
3948 Elf_Internal_Rela outrel;
3949 bfd_byte *loc;
3950 bfd_boolean skip, relocate;
3952 /* When generating a shared object, these relocations
3953 are copied into the output file to be resolved at run
3954 time. */
3956 skip = FALSE;
3957 relocate = FALSE;
3959 outrel.r_offset =
3960 _bfd_elf_section_offset (output_bfd, info, input_section,
3961 rel->r_offset);
3962 if (outrel.r_offset == (bfd_vma) -1)
3963 skip = TRUE;
3964 else if (outrel.r_offset == (bfd_vma) -2)
3965 skip = TRUE, relocate = TRUE;
3966 outrel.r_offset += (input_section->output_section->vma
3967 + input_section->output_offset);
3969 if (skip)
3970 memset (&outrel, 0, sizeof outrel);
3971 else if (h != NULL
3972 && h->dynindx != -1
3973 && (r_type == R_68K_PC8
3974 || r_type == R_68K_PC16
3975 || r_type == R_68K_PC32
3976 || !info->shared
3977 || !info->symbolic
3978 || !h->def_regular))
3980 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3981 outrel.r_addend = rel->r_addend;
3983 else
3985 /* This symbol is local, or marked to become local. */
3986 outrel.r_addend = relocation + rel->r_addend;
3988 if (r_type == R_68K_32)
3990 relocate = TRUE;
3991 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3993 else
3995 long indx;
3997 if (bfd_is_abs_section (sec))
3998 indx = 0;
3999 else if (sec == NULL || sec->owner == NULL)
4001 bfd_set_error (bfd_error_bad_value);
4002 return FALSE;
4004 else
4006 asection *osec;
4008 /* We are turning this relocation into one
4009 against a section symbol. It would be
4010 proper to subtract the symbol's value,
4011 osec->vma, from the emitted reloc addend,
4012 but ld.so expects buggy relocs. */
4013 osec = sec->output_section;
4014 indx = elf_section_data (osec)->dynindx;
4015 if (indx == 0)
4017 struct elf_link_hash_table *htab;
4018 htab = elf_hash_table (info);
4019 osec = htab->text_index_section;
4020 indx = elf_section_data (osec)->dynindx;
4022 BFD_ASSERT (indx != 0);
4025 outrel.r_info = ELF32_R_INFO (indx, r_type);
4029 sreloc = elf_section_data (input_section)->sreloc;
4030 if (sreloc == NULL)
4031 abort ();
4033 loc = sreloc->contents;
4034 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4035 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4037 /* This reloc will be computed at runtime, so there's no
4038 need to do anything now, except for R_68K_32
4039 relocations that have been turned into
4040 R_68K_RELATIVE. */
4041 if (!relocate)
4042 continue;
4045 break;
4047 case R_68K_GNU_VTINHERIT:
4048 case R_68K_GNU_VTENTRY:
4049 /* These are no-ops in the end. */
4050 continue;
4052 default:
4053 break;
4056 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4057 because such sections are not SEC_ALLOC and thus ld.so will
4058 not process them. */
4059 if (unresolved_reloc
4060 && !((input_section->flags & SEC_DEBUGGING) != 0
4061 && h->def_dynamic))
4063 (*_bfd_error_handler)
4064 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4065 input_bfd,
4066 input_section,
4067 (long) rel->r_offset,
4068 howto->name,
4069 h->root.root.string);
4070 return FALSE;
4073 if (r_symndx != 0
4074 && r_type != R_68K_NONE
4075 && (h == NULL
4076 || h->root.type == bfd_link_hash_defined
4077 || h->root.type == bfd_link_hash_defweak))
4079 char sym_type;
4081 sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type;
4083 if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS))
4085 const char *name;
4087 if (h != NULL)
4088 name = h->root.root.string;
4089 else
4091 name = (bfd_elf_string_from_elf_section
4092 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4093 if (name == NULL || *name == '\0')
4094 name = bfd_section_name (input_bfd, sec);
4097 (*_bfd_error_handler)
4098 ((sym_type == STT_TLS
4099 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4100 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4101 input_bfd,
4102 input_section,
4103 (long) rel->r_offset,
4104 howto->name,
4105 name);
4109 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4110 contents, rel->r_offset,
4111 relocation, rel->r_addend);
4113 if (r != bfd_reloc_ok)
4115 const char *name;
4117 if (h != NULL)
4118 name = h->root.root.string;
4119 else
4121 name = bfd_elf_string_from_elf_section (input_bfd,
4122 symtab_hdr->sh_link,
4123 sym->st_name);
4124 if (name == NULL)
4125 return FALSE;
4126 if (*name == '\0')
4127 name = bfd_section_name (input_bfd, sec);
4130 if (r == bfd_reloc_overflow)
4132 if (!(info->callbacks->reloc_overflow
4133 (info, (h ? &h->root : NULL), name, howto->name,
4134 (bfd_vma) 0, input_bfd, input_section,
4135 rel->r_offset)))
4136 return FALSE;
4138 else
4140 (*_bfd_error_handler)
4141 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4142 input_bfd, input_section,
4143 (long) rel->r_offset, name, (int) r);
4144 return FALSE;
4149 return TRUE;
4152 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4153 into section SEC. */
4155 static void
4156 elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
4158 /* Make VALUE PC-relative. */
4159 value -= sec->output_section->vma + offset;
4161 /* Apply any in-place addend. */
4162 value += bfd_get_32 (sec->owner, sec->contents + offset);
4164 bfd_put_32 (sec->owner, value, sec->contents + offset);
4167 /* Finish up dynamic symbol handling. We set the contents of various
4168 dynamic sections here. */
4170 static bfd_boolean
4171 elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym)
4172 bfd *output_bfd;
4173 struct bfd_link_info *info;
4174 struct elf_link_hash_entry *h;
4175 Elf_Internal_Sym *sym;
4177 bfd *dynobj;
4179 dynobj = elf_hash_table (info)->dynobj;
4181 if (h->plt.offset != (bfd_vma) -1)
4183 const struct elf_m68k_plt_info *plt_info;
4184 asection *splt;
4185 asection *sgot;
4186 asection *srela;
4187 bfd_vma plt_index;
4188 bfd_vma got_offset;
4189 Elf_Internal_Rela rela;
4190 bfd_byte *loc;
4192 /* This symbol has an entry in the procedure linkage table. Set
4193 it up. */
4195 BFD_ASSERT (h->dynindx != -1);
4197 plt_info = elf_m68k_hash_table (info)->plt_info;
4198 splt = bfd_get_section_by_name (dynobj, ".plt");
4199 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4200 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
4201 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
4203 /* Get the index in the procedure linkage table which
4204 corresponds to this symbol. This is the index of this symbol
4205 in all the symbols for which we are making plt entries. The
4206 first entry in the procedure linkage table is reserved. */
4207 plt_index = (h->plt.offset / plt_info->size) - 1;
4209 /* Get the offset into the .got table of the entry that
4210 corresponds to this function. Each .got entry is 4 bytes.
4211 The first three are reserved. */
4212 got_offset = (plt_index + 3) * 4;
4214 memcpy (splt->contents + h->plt.offset,
4215 plt_info->symbol_entry,
4216 plt_info->size);
4218 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
4219 (sgot->output_section->vma
4220 + sgot->output_offset
4221 + got_offset));
4223 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4224 splt->contents
4225 + h->plt.offset
4226 + plt_info->symbol_resolve_entry + 2);
4228 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
4229 splt->output_section->vma);
4231 /* Fill in the entry in the global offset table. */
4232 bfd_put_32 (output_bfd,
4233 (splt->output_section->vma
4234 + splt->output_offset
4235 + h->plt.offset
4236 + plt_info->symbol_resolve_entry),
4237 sgot->contents + got_offset);
4239 /* Fill in the entry in the .rela.plt section. */
4240 rela.r_offset = (sgot->output_section->vma
4241 + sgot->output_offset
4242 + got_offset);
4243 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
4244 rela.r_addend = 0;
4245 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
4246 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4248 if (!h->def_regular)
4250 /* Mark the symbol as undefined, rather than as defined in
4251 the .plt section. Leave the value alone. */
4252 sym->st_shndx = SHN_UNDEF;
4256 if (elf_m68k_hash_entry (h)->glist != NULL)
4258 asection *sgot;
4259 asection *srela;
4260 struct elf_m68k_got_entry *got_entry;
4262 /* This symbol has an entry in the global offset table. Set it
4263 up. */
4265 sgot = bfd_get_section_by_name (dynobj, ".got");
4266 srela = bfd_get_section_by_name (dynobj, ".rela.got");
4267 BFD_ASSERT (sgot != NULL && srela != NULL);
4269 got_entry = elf_m68k_hash_entry (h)->glist;
4271 while (got_entry != NULL)
4273 Elf_Internal_Rela rela;
4274 bfd_vma got_entry_offset;
4276 got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1;
4278 rela.r_offset = (sgot->output_section->vma
4279 + sgot->output_offset
4280 + got_entry_offset);
4282 /* If this is a -Bsymbolic link, and the symbol is defined
4283 locally, we just want to emit a RELATIVE reloc. Likewise if
4284 the symbol was forced to be local because of a version file.
4285 The entry in the global offset table already have been
4286 initialized in the relocate_section function. */
4287 if (info->shared
4288 && SYMBOL_REFERENCES_LOCAL (info, h))
4290 rela.r_addend = bfd_get_signed_32 (output_bfd,
4291 (sgot->contents
4292 + got_entry_offset));
4294 switch (elf_m68k_reloc_got_type (got_entry->key_.type))
4296 case R_68K_GOT32O:
4297 rela.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
4298 break;
4300 case R_68K_TLS_GD32:
4301 rela.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
4302 break;
4304 case R_68K_TLS_IE32:
4305 rela.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32);
4306 break;
4308 default:
4309 BFD_ASSERT (FALSE);
4310 break;
4313 elf_m68k_install_rela (output_bfd, srela, &rela);
4315 else
4317 /* Put zeros to GOT slots that will be initialized
4318 at run-time. */
4320 bfd_vma n_slots;
4322 n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type);
4323 while (n_slots--)
4324 bfd_put_32 (output_bfd, (bfd_vma) 0,
4325 (sgot->contents + got_entry_offset
4326 + 4 * n_slots));
4329 rela.r_addend = 0;
4331 switch (elf_m68k_reloc_got_type (got_entry->key_.type))
4333 case R_68K_GOT32O:
4334 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
4335 elf_m68k_install_rela (output_bfd, srela, &rela);
4336 break;
4338 case R_68K_TLS_GD32:
4339 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32);
4340 elf_m68k_install_rela (output_bfd, srela, &rela);
4342 rela.r_offset += 4;
4343 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32);
4344 elf_m68k_install_rela (output_bfd, srela, &rela);
4345 break;
4347 case R_68K_TLS_IE32:
4348 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32);
4349 elf_m68k_install_rela (output_bfd, srela, &rela);
4350 break;
4352 default:
4353 BFD_ASSERT (FALSE);
4354 break;
4358 got_entry = got_entry->u.s2.next;
4362 if (h->needs_copy)
4364 asection *s;
4365 Elf_Internal_Rela rela;
4366 bfd_byte *loc;
4368 /* This symbol needs a copy reloc. Set it up. */
4370 BFD_ASSERT (h->dynindx != -1
4371 && (h->root.type == bfd_link_hash_defined
4372 || h->root.type == bfd_link_hash_defweak));
4374 s = bfd_get_section_by_name (h->root.u.def.section->owner,
4375 ".rela.bss");
4376 BFD_ASSERT (s != NULL);
4378 rela.r_offset = (h->root.u.def.value
4379 + h->root.u.def.section->output_section->vma
4380 + h->root.u.def.section->output_offset);
4381 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
4382 rela.r_addend = 0;
4383 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
4384 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4387 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4388 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4389 || h == elf_hash_table (info)->hgot)
4390 sym->st_shndx = SHN_ABS;
4392 return TRUE;
4395 /* Finish up the dynamic sections. */
4397 static bfd_boolean
4398 elf_m68k_finish_dynamic_sections (output_bfd, info)
4399 bfd *output_bfd;
4400 struct bfd_link_info *info;
4402 bfd *dynobj;
4403 asection *sgot;
4404 asection *sdyn;
4406 dynobj = elf_hash_table (info)->dynobj;
4408 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4409 BFD_ASSERT (sgot != NULL);
4410 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4412 if (elf_hash_table (info)->dynamic_sections_created)
4414 asection *splt;
4415 Elf32_External_Dyn *dyncon, *dynconend;
4417 splt = bfd_get_section_by_name (dynobj, ".plt");
4418 BFD_ASSERT (splt != NULL && sdyn != NULL);
4420 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4421 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4422 for (; dyncon < dynconend; dyncon++)
4424 Elf_Internal_Dyn dyn;
4425 const char *name;
4426 asection *s;
4428 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4430 switch (dyn.d_tag)
4432 default:
4433 break;
4435 case DT_PLTGOT:
4436 name = ".got";
4437 goto get_vma;
4438 case DT_JMPREL:
4439 name = ".rela.plt";
4440 get_vma:
4441 s = bfd_get_section_by_name (output_bfd, name);
4442 BFD_ASSERT (s != NULL);
4443 dyn.d_un.d_ptr = s->vma;
4444 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4445 break;
4447 case DT_PLTRELSZ:
4448 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4449 BFD_ASSERT (s != NULL);
4450 dyn.d_un.d_val = s->size;
4451 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4452 break;
4454 case DT_RELASZ:
4455 /* The procedure linkage table relocs (DT_JMPREL) should
4456 not be included in the overall relocs (DT_RELA).
4457 Therefore, we override the DT_RELASZ entry here to
4458 make it not include the JMPREL relocs. Since the
4459 linker script arranges for .rela.plt to follow all
4460 other relocation sections, we don't have to worry
4461 about changing the DT_RELA entry. */
4462 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4463 if (s != NULL)
4464 dyn.d_un.d_val -= s->size;
4465 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4466 break;
4470 /* Fill in the first entry in the procedure linkage table. */
4471 if (splt->size > 0)
4473 const struct elf_m68k_plt_info *plt_info;
4475 plt_info = elf_m68k_hash_table (info)->plt_info;
4476 memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
4478 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
4479 (sgot->output_section->vma
4480 + sgot->output_offset
4481 + 4));
4483 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
4484 (sgot->output_section->vma
4485 + sgot->output_offset
4486 + 8));
4488 elf_section_data (splt->output_section)->this_hdr.sh_entsize
4489 = plt_info->size;
4493 /* Fill in the first three entries in the global offset table. */
4494 if (sgot->size > 0)
4496 if (sdyn == NULL)
4497 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4498 else
4499 bfd_put_32 (output_bfd,
4500 sdyn->output_section->vma + sdyn->output_offset,
4501 sgot->contents);
4502 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4503 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4506 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4508 return TRUE;
4511 /* Given a .data section and a .emreloc in-memory section, store
4512 relocation information into the .emreloc section which can be
4513 used at runtime to relocate the section. This is called by the
4514 linker when the --embedded-relocs switch is used. This is called
4515 after the add_symbols entry point has been called for all the
4516 objects, and before the final_link entry point is called. */
4518 bfd_boolean
4519 bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
4520 bfd *abfd;
4521 struct bfd_link_info *info;
4522 asection *datasec;
4523 asection *relsec;
4524 char **errmsg;
4526 Elf_Internal_Shdr *symtab_hdr;
4527 Elf_Internal_Sym *isymbuf = NULL;
4528 Elf_Internal_Rela *internal_relocs = NULL;
4529 Elf_Internal_Rela *irel, *irelend;
4530 bfd_byte *p;
4531 bfd_size_type amt;
4533 BFD_ASSERT (! info->relocatable);
4535 *errmsg = NULL;
4537 if (datasec->reloc_count == 0)
4538 return TRUE;
4540 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4542 /* Get a copy of the native relocations. */
4543 internal_relocs = (_bfd_elf_link_read_relocs
4544 (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
4545 info->keep_memory));
4546 if (internal_relocs == NULL)
4547 goto error_return;
4549 amt = (bfd_size_type) datasec->reloc_count * 12;
4550 relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
4551 if (relsec->contents == NULL)
4552 goto error_return;
4554 p = relsec->contents;
4556 irelend = internal_relocs + datasec->reloc_count;
4557 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
4559 asection *targetsec;
4561 /* We are going to write a four byte longword into the runtime
4562 reloc section. The longword will be the address in the data
4563 section which must be relocated. It is followed by the name
4564 of the target section NUL-padded or truncated to 8
4565 characters. */
4567 /* We can only relocate absolute longword relocs at run time. */
4568 if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
4570 *errmsg = _("unsupported reloc type");
4571 bfd_set_error (bfd_error_bad_value);
4572 goto error_return;
4575 /* Get the target section referred to by the reloc. */
4576 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4578 /* A local symbol. */
4579 Elf_Internal_Sym *isym;
4581 /* Read this BFD's local symbols if we haven't done so already. */
4582 if (isymbuf == NULL)
4584 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4585 if (isymbuf == NULL)
4586 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4587 symtab_hdr->sh_info, 0,
4588 NULL, NULL, NULL);
4589 if (isymbuf == NULL)
4590 goto error_return;
4593 isym = isymbuf + ELF32_R_SYM (irel->r_info);
4594 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4596 else
4598 unsigned long indx;
4599 struct elf_link_hash_entry *h;
4601 /* An external symbol. */
4602 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4603 h = elf_sym_hashes (abfd)[indx];
4604 BFD_ASSERT (h != NULL);
4605 if (h->root.type == bfd_link_hash_defined
4606 || h->root.type == bfd_link_hash_defweak)
4607 targetsec = h->root.u.def.section;
4608 else
4609 targetsec = NULL;
4612 bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
4613 memset (p + 4, 0, 8);
4614 if (targetsec != NULL)
4615 strncpy ((char *) p + 4, targetsec->output_section->name, 8);
4618 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4619 free (isymbuf);
4620 if (internal_relocs != NULL
4621 && elf_section_data (datasec)->relocs != internal_relocs)
4622 free (internal_relocs);
4623 return TRUE;
4625 error_return:
4626 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4627 free (isymbuf);
4628 if (internal_relocs != NULL
4629 && elf_section_data (datasec)->relocs != internal_relocs)
4630 free (internal_relocs);
4631 return FALSE;
4634 /* Set target options. */
4636 void
4637 bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
4639 struct elf_m68k_link_hash_table *htab;
4641 htab = elf_m68k_hash_table (info);
4643 switch (got_handling)
4645 case 0:
4646 /* --got=single. */
4647 htab->local_gp_p = FALSE;
4648 htab->use_neg_got_offsets_p = FALSE;
4649 htab->allow_multigot_p = FALSE;
4650 break;
4652 case 1:
4653 /* --got=negative. */
4654 htab->local_gp_p = TRUE;
4655 htab->use_neg_got_offsets_p = TRUE;
4656 htab->allow_multigot_p = FALSE;
4657 break;
4659 case 2:
4660 /* --got=multigot. */
4661 htab->local_gp_p = TRUE;
4662 htab->use_neg_got_offsets_p = TRUE;
4663 htab->allow_multigot_p = TRUE;
4664 break;
4666 default:
4667 BFD_ASSERT (FALSE);
4671 static enum elf_reloc_type_class
4672 elf32_m68k_reloc_type_class (rela)
4673 const Elf_Internal_Rela *rela;
4675 switch ((int) ELF32_R_TYPE (rela->r_info))
4677 case R_68K_RELATIVE:
4678 return reloc_class_relative;
4679 case R_68K_JMP_SLOT:
4680 return reloc_class_plt;
4681 case R_68K_COPY:
4682 return reloc_class_copy;
4683 default:
4684 return reloc_class_normal;
4688 /* Return address for Ith PLT stub in section PLT, for relocation REL
4689 or (bfd_vma) -1 if it should not be included. */
4691 static bfd_vma
4692 elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
4693 const arelent *rel ATTRIBUTE_UNUSED)
4695 return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
4698 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
4699 #define TARGET_BIG_NAME "elf32-m68k"
4700 #define ELF_MACHINE_CODE EM_68K
4701 #define ELF_MAXPAGESIZE 0x2000
4702 #define elf_backend_create_dynamic_sections \
4703 _bfd_elf_create_dynamic_sections
4704 #define bfd_elf32_bfd_link_hash_table_create \
4705 elf_m68k_link_hash_table_create
4706 /* ??? Should it be this macro or bfd_elfNN_bfd_link_hash_table_create? */
4707 #define bfd_elf32_bfd_link_hash_table_free \
4708 elf_m68k_link_hash_table_free
4709 #define bfd_elf32_bfd_final_link bfd_elf_final_link
4711 #define elf_backend_check_relocs elf_m68k_check_relocs
4712 #define elf_backend_always_size_sections \
4713 elf_m68k_always_size_sections
4714 #define elf_backend_adjust_dynamic_symbol \
4715 elf_m68k_adjust_dynamic_symbol
4716 #define elf_backend_size_dynamic_sections \
4717 elf_m68k_size_dynamic_sections
4718 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4719 #define elf_backend_relocate_section elf_m68k_relocate_section
4720 #define elf_backend_finish_dynamic_symbol \
4721 elf_m68k_finish_dynamic_symbol
4722 #define elf_backend_finish_dynamic_sections \
4723 elf_m68k_finish_dynamic_sections
4724 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4725 #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook
4726 #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4727 #define bfd_elf32_bfd_merge_private_bfd_data \
4728 elf32_m68k_merge_private_bfd_data
4729 #define bfd_elf32_bfd_set_private_flags \
4730 elf32_m68k_set_private_flags
4731 #define bfd_elf32_bfd_print_private_bfd_data \
4732 elf32_m68k_print_private_bfd_data
4733 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4734 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4735 #define elf_backend_object_p elf32_m68k_object_p
4737 #define elf_backend_can_gc_sections 1
4738 #define elf_backend_can_refcount 1
4739 #define elf_backend_want_got_plt 1
4740 #define elf_backend_plt_readonly 1
4741 #define elf_backend_want_plt_sym 0
4742 #define elf_backend_got_header_size 12
4743 #define elf_backend_rela_normal 1
4745 #include "elf32-target.h"