1 /* Motorola 68k series support for 32-bit ELF
2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
27 #include "opcode/m68k.h"
30 elf_m68k_discard_copies (struct elf_link_hash_entry
*, void *);
32 static reloc_howto_type howto_table
[] =
34 HOWTO(R_68K_NONE
, 0, 3, 0, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_NONE", FALSE
, 0, 0x00000000,FALSE
),
35 HOWTO(R_68K_32
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_32", FALSE
, 0, 0xffffffff,FALSE
),
36 HOWTO(R_68K_16
, 0, 1,16, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_16", FALSE
, 0, 0x0000ffff,FALSE
),
37 HOWTO(R_68K_8
, 0, 0, 8, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_8", FALSE
, 0, 0x000000ff,FALSE
),
38 HOWTO(R_68K_PC32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PC32", FALSE
, 0, 0xffffffff,TRUE
),
39 HOWTO(R_68K_PC16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC16", FALSE
, 0, 0x0000ffff,TRUE
),
40 HOWTO(R_68K_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC8", FALSE
, 0, 0x000000ff,TRUE
),
41 HOWTO(R_68K_GOT32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32", FALSE
, 0, 0xffffffff,TRUE
),
42 HOWTO(R_68K_GOT16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16", FALSE
, 0, 0x0000ffff,TRUE
),
43 HOWTO(R_68K_GOT8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8", FALSE
, 0, 0x000000ff,TRUE
),
44 HOWTO(R_68K_GOT32O
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32O", FALSE
, 0, 0xffffffff,FALSE
),
45 HOWTO(R_68K_GOT16O
, 0, 1,16, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16O", FALSE
, 0, 0x0000ffff,FALSE
),
46 HOWTO(R_68K_GOT8O
, 0, 0, 8, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8O", FALSE
, 0, 0x000000ff,FALSE
),
47 HOWTO(R_68K_PLT32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32", FALSE
, 0, 0xffffffff,TRUE
),
48 HOWTO(R_68K_PLT16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16", FALSE
, 0, 0x0000ffff,TRUE
),
49 HOWTO(R_68K_PLT8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8", FALSE
, 0, 0x000000ff,TRUE
),
50 HOWTO(R_68K_PLT32O
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32O", FALSE
, 0, 0xffffffff,FALSE
),
51 HOWTO(R_68K_PLT16O
, 0, 1,16, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16O", FALSE
, 0, 0x0000ffff,FALSE
),
52 HOWTO(R_68K_PLT8O
, 0, 0, 8, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8O", FALSE
, 0, 0x000000ff,FALSE
),
53 HOWTO(R_68K_COPY
, 0, 0, 0, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_COPY", FALSE
, 0, 0xffffffff,FALSE
),
54 HOWTO(R_68K_GLOB_DAT
, 0, 2,32, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_GLOB_DAT", FALSE
, 0, 0xffffffff,FALSE
),
55 HOWTO(R_68K_JMP_SLOT
, 0, 2,32, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_JMP_SLOT", FALSE
, 0, 0xffffffff,FALSE
),
56 HOWTO(R_68K_RELATIVE
, 0, 2,32, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_RELATIVE", FALSE
, 0, 0xffffffff,FALSE
),
57 /* GNU extension to record C++ vtable hierarchy. */
58 HOWTO (R_68K_GNU_VTINHERIT
, /* type */
60 2, /* size (0 = byte, 1 = short, 2 = long) */
62 FALSE
, /* pc_relative */
64 complain_overflow_dont
, /* complain_on_overflow */
65 NULL
, /* special_function */
66 "R_68K_GNU_VTINHERIT", /* name */
67 FALSE
, /* partial_inplace */
71 /* GNU extension to record C++ vtable member usage. */
72 HOWTO (R_68K_GNU_VTENTRY
, /* type */
74 2, /* size (0 = byte, 1 = short, 2 = long) */
76 FALSE
, /* pc_relative */
78 complain_overflow_dont
, /* complain_on_overflow */
79 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
80 "R_68K_GNU_VTENTRY", /* name */
81 FALSE
, /* partial_inplace */
86 /* TLS general dynamic variable reference. */
87 HOWTO (R_68K_TLS_GD32
, /* type */
89 2, /* size (0 = byte, 1 = short, 2 = long) */
91 FALSE
, /* pc_relative */
93 complain_overflow_bitfield
, /* complain_on_overflow */
94 bfd_elf_generic_reloc
, /* special_function */
95 "R_68K_TLS_GD32", /* name */
96 FALSE
, /* partial_inplace */
98 0xffffffff, /* dst_mask */
99 FALSE
), /* pcrel_offset */
101 HOWTO (R_68K_TLS_GD16
, /* type */
103 1, /* size (0 = byte, 1 = short, 2 = long) */
105 FALSE
, /* pc_relative */
107 complain_overflow_signed
, /* complain_on_overflow */
108 bfd_elf_generic_reloc
, /* special_function */
109 "R_68K_TLS_GD16", /* name */
110 FALSE
, /* partial_inplace */
112 0x0000ffff, /* dst_mask */
113 FALSE
), /* pcrel_offset */
115 HOWTO (R_68K_TLS_GD8
, /* type */
117 0, /* size (0 = byte, 1 = short, 2 = long) */
119 FALSE
, /* pc_relative */
121 complain_overflow_signed
, /* complain_on_overflow */
122 bfd_elf_generic_reloc
, /* special_function */
123 "R_68K_TLS_GD8", /* name */
124 FALSE
, /* partial_inplace */
126 0x000000ff, /* dst_mask */
127 FALSE
), /* pcrel_offset */
129 /* TLS local dynamic variable reference. */
130 HOWTO (R_68K_TLS_LDM32
, /* type */
132 2, /* size (0 = byte, 1 = short, 2 = long) */
134 FALSE
, /* pc_relative */
136 complain_overflow_bitfield
, /* complain_on_overflow */
137 bfd_elf_generic_reloc
, /* special_function */
138 "R_68K_TLS_LDM32", /* name */
139 FALSE
, /* partial_inplace */
141 0xffffffff, /* dst_mask */
142 FALSE
), /* pcrel_offset */
144 HOWTO (R_68K_TLS_LDM16
, /* type */
146 1, /* size (0 = byte, 1 = short, 2 = long) */
148 FALSE
, /* pc_relative */
150 complain_overflow_signed
, /* complain_on_overflow */
151 bfd_elf_generic_reloc
, /* special_function */
152 "R_68K_TLS_LDM16", /* name */
153 FALSE
, /* partial_inplace */
155 0x0000ffff, /* dst_mask */
156 FALSE
), /* pcrel_offset */
158 HOWTO (R_68K_TLS_LDM8
, /* type */
160 0, /* size (0 = byte, 1 = short, 2 = long) */
162 FALSE
, /* pc_relative */
164 complain_overflow_signed
, /* complain_on_overflow */
165 bfd_elf_generic_reloc
, /* special_function */
166 "R_68K_TLS_LDM8", /* name */
167 FALSE
, /* partial_inplace */
169 0x000000ff, /* dst_mask */
170 FALSE
), /* pcrel_offset */
172 HOWTO (R_68K_TLS_LDO32
, /* type */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
176 FALSE
, /* pc_relative */
178 complain_overflow_bitfield
, /* complain_on_overflow */
179 bfd_elf_generic_reloc
, /* special_function */
180 "R_68K_TLS_LDO32", /* name */
181 FALSE
, /* partial_inplace */
183 0xffffffff, /* dst_mask */
184 FALSE
), /* pcrel_offset */
186 HOWTO (R_68K_TLS_LDO16
, /* type */
188 1, /* size (0 = byte, 1 = short, 2 = long) */
190 FALSE
, /* pc_relative */
192 complain_overflow_signed
, /* complain_on_overflow */
193 bfd_elf_generic_reloc
, /* special_function */
194 "R_68K_TLS_LDO16", /* name */
195 FALSE
, /* partial_inplace */
197 0x0000ffff, /* dst_mask */
198 FALSE
), /* pcrel_offset */
200 HOWTO (R_68K_TLS_LDO8
, /* type */
202 0, /* size (0 = byte, 1 = short, 2 = long) */
204 FALSE
, /* pc_relative */
206 complain_overflow_signed
, /* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_68K_TLS_LDO8", /* name */
209 FALSE
, /* partial_inplace */
211 0x000000ff, /* dst_mask */
212 FALSE
), /* pcrel_offset */
214 /* TLS initial execution variable reference. */
215 HOWTO (R_68K_TLS_IE32
, /* type */
217 2, /* size (0 = byte, 1 = short, 2 = long) */
219 FALSE
, /* pc_relative */
221 complain_overflow_bitfield
, /* complain_on_overflow */
222 bfd_elf_generic_reloc
, /* special_function */
223 "R_68K_TLS_IE32", /* name */
224 FALSE
, /* partial_inplace */
226 0xffffffff, /* dst_mask */
227 FALSE
), /* pcrel_offset */
229 HOWTO (R_68K_TLS_IE16
, /* type */
231 1, /* size (0 = byte, 1 = short, 2 = long) */
233 FALSE
, /* pc_relative */
235 complain_overflow_signed
, /* complain_on_overflow */
236 bfd_elf_generic_reloc
, /* special_function */
237 "R_68K_TLS_IE16", /* name */
238 FALSE
, /* partial_inplace */
240 0x0000ffff, /* dst_mask */
241 FALSE
), /* pcrel_offset */
243 HOWTO (R_68K_TLS_IE8
, /* type */
245 0, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE
, /* pc_relative */
249 complain_overflow_signed
, /* complain_on_overflow */
250 bfd_elf_generic_reloc
, /* special_function */
251 "R_68K_TLS_IE8", /* name */
252 FALSE
, /* partial_inplace */
254 0x000000ff, /* dst_mask */
255 FALSE
), /* pcrel_offset */
257 /* TLS local execution variable reference. */
258 HOWTO (R_68K_TLS_LE32
, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 FALSE
, /* pc_relative */
264 complain_overflow_bitfield
, /* complain_on_overflow */
265 bfd_elf_generic_reloc
, /* special_function */
266 "R_68K_TLS_LE32", /* name */
267 FALSE
, /* partial_inplace */
269 0xffffffff, /* dst_mask */
270 FALSE
), /* pcrel_offset */
272 HOWTO (R_68K_TLS_LE16
, /* type */
274 1, /* size (0 = byte, 1 = short, 2 = long) */
276 FALSE
, /* pc_relative */
278 complain_overflow_signed
, /* complain_on_overflow */
279 bfd_elf_generic_reloc
, /* special_function */
280 "R_68K_TLS_LE16", /* name */
281 FALSE
, /* partial_inplace */
283 0x0000ffff, /* dst_mask */
284 FALSE
), /* pcrel_offset */
286 HOWTO (R_68K_TLS_LE8
, /* type */
288 0, /* size (0 = byte, 1 = short, 2 = long) */
290 FALSE
, /* pc_relative */
292 complain_overflow_signed
, /* complain_on_overflow */
293 bfd_elf_generic_reloc
, /* special_function */
294 "R_68K_TLS_LE8", /* name */
295 FALSE
, /* partial_inplace */
297 0x000000ff, /* dst_mask */
298 FALSE
), /* pcrel_offset */
300 /* TLS GD/LD dynamic relocations. */
301 HOWTO (R_68K_TLS_DTPMOD32
, /* type */
303 2, /* size (0 = byte, 1 = short, 2 = long) */
305 FALSE
, /* pc_relative */
307 complain_overflow_dont
, /* complain_on_overflow */
308 bfd_elf_generic_reloc
, /* special_function */
309 "R_68K_TLS_DTPMOD32", /* name */
310 FALSE
, /* partial_inplace */
312 0xffffffff, /* dst_mask */
313 FALSE
), /* pcrel_offset */
315 HOWTO (R_68K_TLS_DTPREL32
, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 FALSE
, /* pc_relative */
321 complain_overflow_dont
, /* complain_on_overflow */
322 bfd_elf_generic_reloc
, /* special_function */
323 "R_68K_TLS_DTPREL32", /* name */
324 FALSE
, /* partial_inplace */
326 0xffffffff, /* dst_mask */
327 FALSE
), /* pcrel_offset */
329 HOWTO (R_68K_TLS_TPREL32
, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 FALSE
, /* pc_relative */
335 complain_overflow_dont
, /* complain_on_overflow */
336 bfd_elf_generic_reloc
, /* special_function */
337 "R_68K_TLS_TPREL32", /* name */
338 FALSE
, /* partial_inplace */
340 0xffffffff, /* dst_mask */
341 FALSE
), /* pcrel_offset */
345 rtype_to_howto (bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
347 unsigned int indx
= ELF32_R_TYPE (dst
->r_info
);
349 if (indx
>= (unsigned int) R_68K_max
)
351 /* xgettext:c-format */
352 _bfd_error_handler (_("%B: invalid relocation type %d"),
356 cache_ptr
->howto
= &howto_table
[indx
];
359 #define elf_info_to_howto rtype_to_howto
363 bfd_reloc_code_real_type bfd_val
;
368 { BFD_RELOC_NONE
, R_68K_NONE
},
369 { BFD_RELOC_32
, R_68K_32
},
370 { BFD_RELOC_16
, R_68K_16
},
371 { BFD_RELOC_8
, R_68K_8
},
372 { BFD_RELOC_32_PCREL
, R_68K_PC32
},
373 { BFD_RELOC_16_PCREL
, R_68K_PC16
},
374 { BFD_RELOC_8_PCREL
, R_68K_PC8
},
375 { BFD_RELOC_32_GOT_PCREL
, R_68K_GOT32
},
376 { BFD_RELOC_16_GOT_PCREL
, R_68K_GOT16
},
377 { BFD_RELOC_8_GOT_PCREL
, R_68K_GOT8
},
378 { BFD_RELOC_32_GOTOFF
, R_68K_GOT32O
},
379 { BFD_RELOC_16_GOTOFF
, R_68K_GOT16O
},
380 { BFD_RELOC_8_GOTOFF
, R_68K_GOT8O
},
381 { BFD_RELOC_32_PLT_PCREL
, R_68K_PLT32
},
382 { BFD_RELOC_16_PLT_PCREL
, R_68K_PLT16
},
383 { BFD_RELOC_8_PLT_PCREL
, R_68K_PLT8
},
384 { BFD_RELOC_32_PLTOFF
, R_68K_PLT32O
},
385 { BFD_RELOC_16_PLTOFF
, R_68K_PLT16O
},
386 { BFD_RELOC_8_PLTOFF
, R_68K_PLT8O
},
387 { BFD_RELOC_NONE
, R_68K_COPY
},
388 { BFD_RELOC_68K_GLOB_DAT
, R_68K_GLOB_DAT
},
389 { BFD_RELOC_68K_JMP_SLOT
, R_68K_JMP_SLOT
},
390 { BFD_RELOC_68K_RELATIVE
, R_68K_RELATIVE
},
391 { BFD_RELOC_CTOR
, R_68K_32
},
392 { BFD_RELOC_VTABLE_INHERIT
, R_68K_GNU_VTINHERIT
},
393 { BFD_RELOC_VTABLE_ENTRY
, R_68K_GNU_VTENTRY
},
394 { BFD_RELOC_68K_TLS_GD32
, R_68K_TLS_GD32
},
395 { BFD_RELOC_68K_TLS_GD16
, R_68K_TLS_GD16
},
396 { BFD_RELOC_68K_TLS_GD8
, R_68K_TLS_GD8
},
397 { BFD_RELOC_68K_TLS_LDM32
, R_68K_TLS_LDM32
},
398 { BFD_RELOC_68K_TLS_LDM16
, R_68K_TLS_LDM16
},
399 { BFD_RELOC_68K_TLS_LDM8
, R_68K_TLS_LDM8
},
400 { BFD_RELOC_68K_TLS_LDO32
, R_68K_TLS_LDO32
},
401 { BFD_RELOC_68K_TLS_LDO16
, R_68K_TLS_LDO16
},
402 { BFD_RELOC_68K_TLS_LDO8
, R_68K_TLS_LDO8
},
403 { BFD_RELOC_68K_TLS_IE32
, R_68K_TLS_IE32
},
404 { BFD_RELOC_68K_TLS_IE16
, R_68K_TLS_IE16
},
405 { BFD_RELOC_68K_TLS_IE8
, R_68K_TLS_IE8
},
406 { BFD_RELOC_68K_TLS_LE32
, R_68K_TLS_LE32
},
407 { BFD_RELOC_68K_TLS_LE16
, R_68K_TLS_LE16
},
408 { BFD_RELOC_68K_TLS_LE8
, R_68K_TLS_LE8
},
411 static reloc_howto_type
*
412 reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
413 bfd_reloc_code_real_type code
)
416 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
418 if (reloc_map
[i
].bfd_val
== code
)
419 return &howto_table
[reloc_map
[i
].elf_val
];
424 static reloc_howto_type
*
425 reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
429 for (i
= 0; i
< sizeof (howto_table
) / sizeof (howto_table
[0]); i
++)
430 if (howto_table
[i
].name
!= NULL
431 && strcasecmp (howto_table
[i
].name
, r_name
) == 0)
432 return &howto_table
[i
];
437 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
438 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
439 #define ELF_ARCH bfd_arch_m68k
440 #define ELF_TARGET_ID M68K_ELF_DATA
442 /* Functions for the m68k ELF linker. */
444 /* The name of the dynamic interpreter. This is put in the .interp
447 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
449 /* Describes one of the various PLT styles. */
451 struct elf_m68k_plt_info
453 /* The size of each PLT entry. */
456 /* The template for the first PLT entry. */
457 const bfd_byte
*plt0_entry
;
459 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
460 The comments by each member indicate the value that the relocation
463 unsigned int got4
; /* .got + 4 */
464 unsigned int got8
; /* .got + 8 */
467 /* The template for a symbol's PLT entry. */
468 const bfd_byte
*symbol_entry
;
470 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
471 The comments by each member indicate the value that the relocation
474 unsigned int got
; /* the symbol's .got.plt entry */
475 unsigned int plt
; /* .plt */
478 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
479 The stub starts with "move.l #relocoffset,%d0". */
480 bfd_vma symbol_resolve_entry
;
483 /* The size in bytes of an entry in the procedure linkage table. */
485 #define PLT_ENTRY_SIZE 20
487 /* The first entry in a procedure linkage table looks like this. See
488 the SVR4 ABI m68k supplement to see how this works. */
490 static const bfd_byte elf_m68k_plt0_entry
[PLT_ENTRY_SIZE
] =
492 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
493 0, 0, 0, 2, /* + (.got + 4) - . */
494 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
495 0, 0, 0, 2, /* + (.got + 8) - . */
496 0, 0, 0, 0 /* pad out to 20 bytes. */
499 /* Subsequent entries in a procedure linkage table look like this. */
501 static const bfd_byte elf_m68k_plt_entry
[PLT_ENTRY_SIZE
] =
503 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
504 0, 0, 0, 2, /* + (.got.plt entry) - . */
505 0x2f, 0x3c, /* move.l #offset,-(%sp) */
506 0, 0, 0, 0, /* + reloc index */
507 0x60, 0xff, /* bra.l .plt */
508 0, 0, 0, 0 /* + .plt - . */
511 static const struct elf_m68k_plt_info elf_m68k_plt_info
=
514 elf_m68k_plt0_entry
, { 4, 12 },
515 elf_m68k_plt_entry
, { 4, 16 }, 8
518 #define ISAB_PLT_ENTRY_SIZE 24
520 static const bfd_byte elf_isab_plt0_entry
[ISAB_PLT_ENTRY_SIZE
] =
522 0x20, 0x3c, /* move.l #offset,%d0 */
523 0, 0, 0, 0, /* + (.got + 4) - . */
524 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
525 0x20, 0x3c, /* move.l #offset,%d0 */
526 0, 0, 0, 0, /* + (.got + 8) - . */
527 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
528 0x4e, 0xd0, /* jmp (%a0) */
532 /* Subsequent entries in a procedure linkage table look like this. */
534 static const bfd_byte elf_isab_plt_entry
[ISAB_PLT_ENTRY_SIZE
] =
536 0x20, 0x3c, /* move.l #offset,%d0 */
537 0, 0, 0, 0, /* + (.got.plt entry) - . */
538 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
539 0x4e, 0xd0, /* jmp (%a0) */
540 0x2f, 0x3c, /* move.l #offset,-(%sp) */
541 0, 0, 0, 0, /* + reloc index */
542 0x60, 0xff, /* bra.l .plt */
543 0, 0, 0, 0 /* + .plt - . */
546 static const struct elf_m68k_plt_info elf_isab_plt_info
=
549 elf_isab_plt0_entry
, { 2, 12 },
550 elf_isab_plt_entry
, { 2, 20 }, 12
553 #define ISAC_PLT_ENTRY_SIZE 24
555 static const bfd_byte elf_isac_plt0_entry
[ISAC_PLT_ENTRY_SIZE
] =
557 0x20, 0x3c, /* move.l #offset,%d0 */
558 0, 0, 0, 0, /* replaced with .got + 4 - . */
559 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
560 0x20, 0x3c, /* move.l #offset,%d0 */
561 0, 0, 0, 0, /* replaced with .got + 8 - . */
562 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
563 0x4e, 0xd0, /* jmp (%a0) */
567 /* Subsequent entries in a procedure linkage table look like this. */
569 static const bfd_byte elf_isac_plt_entry
[ISAC_PLT_ENTRY_SIZE
] =
571 0x20, 0x3c, /* move.l #offset,%d0 */
572 0, 0, 0, 0, /* replaced with (.got entry) - . */
573 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
574 0x4e, 0xd0, /* jmp (%a0) */
575 0x2f, 0x3c, /* move.l #offset,-(%sp) */
576 0, 0, 0, 0, /* replaced with offset into relocation table */
577 0x61, 0xff, /* bsr.l .plt */
578 0, 0, 0, 0 /* replaced with .plt - . */
581 static const struct elf_m68k_plt_info elf_isac_plt_info
=
584 elf_isac_plt0_entry
, { 2, 12},
585 elf_isac_plt_entry
, { 2, 20 }, 12
588 #define CPU32_PLT_ENTRY_SIZE 24
589 /* Procedure linkage table entries for the cpu32 */
590 static const bfd_byte elf_cpu32_plt0_entry
[CPU32_PLT_ENTRY_SIZE
] =
592 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
593 0, 0, 0, 2, /* + (.got + 4) - . */
594 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
595 0, 0, 0, 2, /* + (.got + 8) - . */
596 0x4e, 0xd1, /* jmp %a1@ */
597 0, 0, 0, 0, /* pad out to 24 bytes. */
601 static const bfd_byte elf_cpu32_plt_entry
[CPU32_PLT_ENTRY_SIZE
] =
603 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
604 0, 0, 0, 2, /* + (.got.plt entry) - . */
605 0x4e, 0xd1, /* jmp %a1@ */
606 0x2f, 0x3c, /* move.l #offset,-(%sp) */
607 0, 0, 0, 0, /* + reloc index */
608 0x60, 0xff, /* bra.l .plt */
609 0, 0, 0, 0, /* + .plt - . */
613 static const struct elf_m68k_plt_info elf_cpu32_plt_info
=
615 CPU32_PLT_ENTRY_SIZE
,
616 elf_cpu32_plt0_entry
, { 4, 12 },
617 elf_cpu32_plt_entry
, { 4, 18 }, 10
620 /* The m68k linker needs to keep track of the number of relocs that it
621 decides to copy in check_relocs for each symbol. This is so that it
622 can discard PC relative relocs if it doesn't need them when linking
623 with -Bsymbolic. We store the information in a field extending the
624 regular ELF linker hash table. */
626 /* This structure keeps track of the number of PC relative relocs we have
627 copied for a given symbol. */
629 struct elf_m68k_pcrel_relocs_copied
632 struct elf_m68k_pcrel_relocs_copied
*next
;
633 /* A section in dynobj. */
635 /* Number of relocs copied in this section. */
639 /* Forward declaration. */
640 struct elf_m68k_got_entry
;
642 /* m68k ELF linker hash entry. */
644 struct elf_m68k_link_hash_entry
646 struct elf_link_hash_entry root
;
648 /* Number of PC relative relocs copied for this symbol. */
649 struct elf_m68k_pcrel_relocs_copied
*pcrel_relocs_copied
;
651 /* Key to got_entries. */
652 unsigned long got_entry_key
;
654 /* List of GOT entries for this symbol. This list is build during
655 offset finalization and is used within elf_m68k_finish_dynamic_symbol
656 to traverse all GOT entries for a particular symbol.
658 ??? We could've used root.got.glist field instead, but having
659 a separate field is cleaner. */
660 struct elf_m68k_got_entry
*glist
;
663 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
665 /* Key part of GOT entry in hashtable. */
666 struct elf_m68k_got_entry_key
668 /* BFD in which this symbol was defined. NULL for global symbols. */
671 /* Symbol index. Either local symbol index or h->got_entry_key. */
672 unsigned long symndx
;
674 /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
675 R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
677 From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
678 matters. That is, we distinguish between, say, R_68K_GOT16O
679 and R_68K_GOT32O when allocating offsets, but they are considered to be
680 the same when searching got->entries. */
681 enum elf_m68k_reloc_type type
;
684 /* Size of the GOT offset suitable for relocation. */
685 enum elf_m68k_got_offset_size
{ R_8
, R_16
, R_32
, R_LAST
};
687 /* Entry of the GOT. */
688 struct elf_m68k_got_entry
690 /* GOT entries are put into a got->entries hashtable. This is the key. */
691 struct elf_m68k_got_entry_key key_
;
693 /* GOT entry data. We need s1 before offset finalization and s2 after. */
698 /* Number of times this entry is referenced. It is used to
699 filter out unnecessary GOT slots in elf_m68k_gc_sweep_hook. */
705 /* Offset from the start of .got section. To calculate offset relative
706 to GOT pointer one should substract got->offset from this value. */
709 /* Pointer to the next GOT entry for this global symbol.
710 Symbols have at most one entry in one GOT, but might
711 have entries in more than one GOT.
712 Root of this list is h->glist.
713 NULL for local symbols. */
714 struct elf_m68k_got_entry
*next
;
719 /* Return representative type for relocation R_TYPE.
720 This is used to avoid enumerating many relocations in comparisons,
723 static enum elf_m68k_reloc_type
724 elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type
)
728 /* In most cases R_68K_GOTx relocations require the very same
729 handling as R_68K_GOT32O relocation. In cases when we need
730 to distinguish between the two, we use explicitly compare against
743 return R_68K_TLS_GD32
;
745 case R_68K_TLS_LDM32
:
746 case R_68K_TLS_LDM16
:
748 return R_68K_TLS_LDM32
;
753 return R_68K_TLS_IE32
;
761 /* Return size of the GOT entry offset for relocation R_TYPE. */
763 static enum elf_m68k_got_offset_size
764 elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type
)
768 case R_68K_GOT32
: case R_68K_GOT16
: case R_68K_GOT8
:
769 case R_68K_GOT32O
: case R_68K_TLS_GD32
: case R_68K_TLS_LDM32
:
773 case R_68K_GOT16O
: case R_68K_TLS_GD16
: case R_68K_TLS_LDM16
:
777 case R_68K_GOT8O
: case R_68K_TLS_GD8
: case R_68K_TLS_LDM8
:
787 /* Return number of GOT entries we need to allocate in GOT for
788 relocation R_TYPE. */
791 elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type
)
793 switch (elf_m68k_reloc_got_type (r_type
))
800 case R_68K_TLS_LDM32
:
809 /* Return TRUE if relocation R_TYPE is a TLS one. */
812 elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type
)
816 case R_68K_TLS_GD32
: case R_68K_TLS_GD16
: case R_68K_TLS_GD8
:
817 case R_68K_TLS_LDM32
: case R_68K_TLS_LDM16
: case R_68K_TLS_LDM8
:
818 case R_68K_TLS_LDO32
: case R_68K_TLS_LDO16
: case R_68K_TLS_LDO8
:
819 case R_68K_TLS_IE32
: case R_68K_TLS_IE16
: case R_68K_TLS_IE8
:
820 case R_68K_TLS_LE32
: case R_68K_TLS_LE16
: case R_68K_TLS_LE8
:
821 case R_68K_TLS_DTPMOD32
: case R_68K_TLS_DTPREL32
: case R_68K_TLS_TPREL32
:
829 /* Data structure representing a single GOT. */
832 /* Hashtable of 'struct elf_m68k_got_entry's.
833 Starting size of this table is the maximum number of
834 R_68K_GOT8O entries. */
837 /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
840 n_slots[R_8] is the count of R_8 slots in this GOT.
841 n_slots[R_16] is the cumulative count of R_8 and R_16 slots
843 n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
844 in this GOT. This is the total number of slots. */
845 bfd_vma n_slots
[R_LAST
];
847 /* Number of local (entry->key_.h == NULL) slots in this GOT.
848 This is only used to properly calculate size of .rela.got section;
849 see elf_m68k_partition_multi_got. */
850 bfd_vma local_n_slots
;
852 /* Offset of this GOT relative to beginning of .got section. */
856 /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
857 struct elf_m68k_bfd2got_entry
862 /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
863 GOT structure. After partitioning several BFD's might [and often do]
864 share a single GOT. */
865 struct elf_m68k_got
*got
;
868 /* The main data structure holding all the pieces. */
869 struct elf_m68k_multi_got
871 /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
872 here, then it doesn't need a GOT (this includes the case of a BFD
873 having an empty GOT).
875 ??? This hashtable can be replaced by an array indexed by bfd->id. */
878 /* Next symndx to assign a global symbol.
879 h->got_entry_key is initialized from this counter. */
880 unsigned long global_symndx
;
883 /* m68k ELF linker hash table. */
885 struct elf_m68k_link_hash_table
887 struct elf_link_hash_table root
;
889 /* Small local sym cache. */
890 struct sym_cache sym_cache
;
892 /* The PLT format used by this link, or NULL if the format has not
894 const struct elf_m68k_plt_info
*plt_info
;
896 /* True, if GP is loaded within each function which uses it.
897 Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
898 bfd_boolean local_gp_p
;
900 /* Switch controlling use of negative offsets to double the size of GOTs. */
901 bfd_boolean use_neg_got_offsets_p
;
903 /* Switch controlling generation of multiple GOTs. */
904 bfd_boolean allow_multigot_p
;
906 /* Multi-GOT data structure. */
907 struct elf_m68k_multi_got multi_got_
;
910 /* Get the m68k ELF linker hash table from a link_info structure. */
912 #define elf_m68k_hash_table(p) \
913 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
914 == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL)
916 /* Shortcut to multi-GOT data. */
917 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
919 /* Create an entry in an m68k ELF linker hash table. */
921 static struct bfd_hash_entry
*
922 elf_m68k_link_hash_newfunc (struct bfd_hash_entry
*entry
,
923 struct bfd_hash_table
*table
,
926 struct bfd_hash_entry
*ret
= entry
;
928 /* Allocate the structure if it has not already been allocated by a
931 ret
= bfd_hash_allocate (table
,
932 sizeof (struct elf_m68k_link_hash_entry
));
936 /* Call the allocation method of the superclass. */
937 ret
= _bfd_elf_link_hash_newfunc (ret
, table
, string
);
940 elf_m68k_hash_entry (ret
)->pcrel_relocs_copied
= NULL
;
941 elf_m68k_hash_entry (ret
)->got_entry_key
= 0;
942 elf_m68k_hash_entry (ret
)->glist
= NULL
;
948 /* Destroy an m68k ELF linker hash table. */
951 elf_m68k_link_hash_table_free (bfd
*obfd
)
953 struct elf_m68k_link_hash_table
*htab
;
955 htab
= (struct elf_m68k_link_hash_table
*) obfd
->link
.hash
;
957 if (htab
->multi_got_
.bfd2got
!= NULL
)
959 htab_delete (htab
->multi_got_
.bfd2got
);
960 htab
->multi_got_
.bfd2got
= NULL
;
962 _bfd_elf_link_hash_table_free (obfd
);
965 /* Create an m68k ELF linker hash table. */
967 static struct bfd_link_hash_table
*
968 elf_m68k_link_hash_table_create (bfd
*abfd
)
970 struct elf_m68k_link_hash_table
*ret
;
971 bfd_size_type amt
= sizeof (struct elf_m68k_link_hash_table
);
973 ret
= (struct elf_m68k_link_hash_table
*) bfd_zmalloc (amt
);
974 if (ret
== (struct elf_m68k_link_hash_table
*) NULL
)
977 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
978 elf_m68k_link_hash_newfunc
,
979 sizeof (struct elf_m68k_link_hash_entry
),
985 ret
->root
.root
.hash_table_free
= elf_m68k_link_hash_table_free
;
987 ret
->multi_got_
.global_symndx
= 1;
989 return &ret
->root
.root
;
992 /* Set the right machine number. */
995 elf32_m68k_object_p (bfd
*abfd
)
997 unsigned int mach
= 0;
998 unsigned features
= 0;
999 flagword eflags
= elf_elfheader (abfd
)->e_flags
;
1001 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1003 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1005 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1009 switch (eflags
& EF_M68K_CF_ISA_MASK
)
1011 case EF_M68K_CF_ISA_A_NODIV
:
1012 features
|= mcfisa_a
;
1014 case EF_M68K_CF_ISA_A
:
1015 features
|= mcfisa_a
|mcfhwdiv
;
1017 case EF_M68K_CF_ISA_A_PLUS
:
1018 features
|= mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
;
1020 case EF_M68K_CF_ISA_B_NOUSP
:
1021 features
|= mcfisa_a
|mcfisa_b
|mcfhwdiv
;
1023 case EF_M68K_CF_ISA_B
:
1024 features
|= mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfusp
;
1026 case EF_M68K_CF_ISA_C
:
1027 features
|= mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfusp
;
1029 case EF_M68K_CF_ISA_C_NODIV
:
1030 features
|= mcfisa_a
|mcfisa_c
|mcfusp
;
1033 switch (eflags
& EF_M68K_CF_MAC_MASK
)
1035 case EF_M68K_CF_MAC
:
1038 case EF_M68K_CF_EMAC
:
1039 features
|= mcfemac
;
1042 if (eflags
& EF_M68K_CF_FLOAT
)
1046 mach
= bfd_m68k_features_to_mach (features
);
1047 bfd_default_set_arch_mach (abfd
, bfd_arch_m68k
, mach
);
1052 /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
1053 field based on the machine number. */
1056 elf_m68k_final_write_processing (bfd
*abfd
,
1057 bfd_boolean linker ATTRIBUTE_UNUSED
)
1059 int mach
= bfd_get_mach (abfd
);
1060 unsigned long e_flags
= elf_elfheader (abfd
)->e_flags
;
1064 unsigned int arch_mask
;
1066 arch_mask
= bfd_m68k_mach_to_features (mach
);
1068 if (arch_mask
& m68000
)
1069 e_flags
= EF_M68K_M68000
;
1070 else if (arch_mask
& cpu32
)
1071 e_flags
= EF_M68K_CPU32
;
1072 else if (arch_mask
& fido_a
)
1073 e_flags
= EF_M68K_FIDO
;
1077 & (mcfisa_a
| mcfisa_aa
| mcfisa_b
| mcfisa_c
| mcfhwdiv
| mcfusp
))
1080 e_flags
|= EF_M68K_CF_ISA_A_NODIV
;
1082 case mcfisa_a
| mcfhwdiv
:
1083 e_flags
|= EF_M68K_CF_ISA_A
;
1085 case mcfisa_a
| mcfisa_aa
| mcfhwdiv
| mcfusp
:
1086 e_flags
|= EF_M68K_CF_ISA_A_PLUS
;
1088 case mcfisa_a
| mcfisa_b
| mcfhwdiv
:
1089 e_flags
|= EF_M68K_CF_ISA_B_NOUSP
;
1091 case mcfisa_a
| mcfisa_b
| mcfhwdiv
| mcfusp
:
1092 e_flags
|= EF_M68K_CF_ISA_B
;
1094 case mcfisa_a
| mcfisa_c
| mcfhwdiv
| mcfusp
:
1095 e_flags
|= EF_M68K_CF_ISA_C
;
1097 case mcfisa_a
| mcfisa_c
| mcfusp
:
1098 e_flags
|= EF_M68K_CF_ISA_C_NODIV
;
1101 if (arch_mask
& mcfmac
)
1102 e_flags
|= EF_M68K_CF_MAC
;
1103 else if (arch_mask
& mcfemac
)
1104 e_flags
|= EF_M68K_CF_EMAC
;
1105 if (arch_mask
& cfloat
)
1106 e_flags
|= EF_M68K_CF_FLOAT
| EF_M68K_CFV4E
;
1108 elf_elfheader (abfd
)->e_flags
= e_flags
;
1112 /* Keep m68k-specific flags in the ELF header. */
1115 elf32_m68k_set_private_flags (bfd
*abfd
, flagword flags
)
1117 elf_elfheader (abfd
)->e_flags
= flags
;
1118 elf_flags_init (abfd
) = TRUE
;
1122 /* Merge backend specific data from an object file to the output
1123 object file when linking. */
1125 elf32_m68k_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
1127 bfd
*obfd
= info
->output_bfd
;
1132 const bfd_arch_info_type
*arch_info
;
1134 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1135 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1138 /* Get the merged machine. This checks for incompatibility between
1139 Coldfire & non-Coldfire flags, incompability between different
1140 Coldfire ISAs, and incompability between different MAC types. */
1141 arch_info
= bfd_arch_get_compatible (ibfd
, obfd
, FALSE
);
1145 bfd_set_arch_mach (obfd
, bfd_arch_m68k
, arch_info
->mach
);
1147 in_flags
= elf_elfheader (ibfd
)->e_flags
;
1148 if (!elf_flags_init (obfd
))
1150 elf_flags_init (obfd
) = TRUE
;
1151 out_flags
= in_flags
;
1155 out_flags
= elf_elfheader (obfd
)->e_flags
;
1156 unsigned int variant_mask
;
1158 if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1160 else if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1162 else if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1165 variant_mask
= EF_M68K_CF_ISA_MASK
;
1167 in_isa
= (in_flags
& variant_mask
);
1168 out_isa
= (out_flags
& variant_mask
);
1169 if (in_isa
> out_isa
)
1170 out_flags
^= in_isa
^ out_isa
;
1171 if (((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
1172 && (out_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1173 || ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
1174 && (out_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
))
1175 out_flags
= EF_M68K_FIDO
;
1177 out_flags
|= in_flags
^ in_isa
;
1179 elf_elfheader (obfd
)->e_flags
= out_flags
;
1184 /* Display the flags field. */
1187 elf32_m68k_print_private_bfd_data (bfd
*abfd
, void * ptr
)
1189 FILE *file
= (FILE *) ptr
;
1190 flagword eflags
= elf_elfheader (abfd
)->e_flags
;
1192 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
1194 /* Print normal ELF private data. */
1195 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
1197 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1199 /* xgettext:c-format */
1200 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
1202 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1203 fprintf (file
, " [m68000]");
1204 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1205 fprintf (file
, " [cpu32]");
1206 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1207 fprintf (file
, " [fido]");
1210 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CFV4E
)
1211 fprintf (file
, " [cfv4e]");
1213 if (eflags
& EF_M68K_CF_ISA_MASK
)
1215 char const *isa
= _("unknown");
1216 char const *mac
= _("unknown");
1217 char const *additional
= "";
1219 switch (eflags
& EF_M68K_CF_ISA_MASK
)
1221 case EF_M68K_CF_ISA_A_NODIV
:
1223 additional
= " [nodiv]";
1225 case EF_M68K_CF_ISA_A
:
1228 case EF_M68K_CF_ISA_A_PLUS
:
1231 case EF_M68K_CF_ISA_B_NOUSP
:
1233 additional
= " [nousp]";
1235 case EF_M68K_CF_ISA_B
:
1238 case EF_M68K_CF_ISA_C
:
1241 case EF_M68K_CF_ISA_C_NODIV
:
1243 additional
= " [nodiv]";
1246 fprintf (file
, " [isa %s]%s", isa
, additional
);
1248 if (eflags
& EF_M68K_CF_FLOAT
)
1249 fprintf (file
, " [float]");
1251 switch (eflags
& EF_M68K_CF_MAC_MASK
)
1256 case EF_M68K_CF_MAC
:
1259 case EF_M68K_CF_EMAC
:
1262 case EF_M68K_CF_EMAC_B
:
1267 fprintf (file
, " [%s]", mac
);
1276 /* Multi-GOT support implementation design:
1278 Multi-GOT starts in check_relocs hook. There we scan all
1279 relocations of a BFD and build a local GOT (struct elf_m68k_got)
1280 for it. If a single BFD appears to require too many GOT slots with
1281 R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1283 After check_relocs has been invoked for each input BFD, we have
1284 constructed a GOT for each input BFD.
1286 To minimize total number of GOTs required for a particular output BFD
1287 (as some environments support only 1 GOT per output object) we try
1288 to merge some of the GOTs to share an offset space. Ideally [and in most
1289 cases] we end up with a single GOT. In cases when there are too many
1290 restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1291 several GOTs, assuming the environment can handle them.
1293 Partitioning is done in elf_m68k_partition_multi_got. We start with
1294 an empty GOT and traverse bfd2got hashtable putting got_entries from
1295 local GOTs to the new 'big' one. We do that by constructing an
1296 intermediate GOT holding all the entries the local GOT has and the big
1297 GOT lacks. Then we check if there is room in the big GOT to accomodate
1298 all the entries from diff. On success we add those entries to the big
1299 GOT; on failure we start the new 'big' GOT and retry the adding of
1300 entries from the local GOT. Note that this retry will always succeed as
1301 each local GOT doesn't overflow the limits. After partitioning we
1302 end up with each bfd assigned one of the big GOTs. GOT entries in the
1303 big GOTs are initialized with GOT offsets. Note that big GOTs are
1304 positioned consequently in program space and represent a single huge GOT
1305 to the outside world.
1307 After that we get to elf_m68k_relocate_section. There we
1308 adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1309 relocations to refer to appropriate [assigned to current input_bfd]
1314 GOT entry type: We have several types of GOT entries.
1315 * R_8 type is used in entries for symbols that have at least one
1316 R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
1317 such entries in one GOT.
1318 * R_16 type is used in entries for symbols that have at least one
1319 R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1320 We can have at most 0x4000 such entries in one GOT.
1321 * R_32 type is used in all other cases. We can have as many
1322 such entries in one GOT as we'd like.
1323 When counting relocations we have to include the count of the smaller
1324 ranged relocations in the counts of the larger ranged ones in order
1325 to correctly detect overflow.
1327 Sorting the GOT: In each GOT starting offsets are assigned to
1328 R_8 entries, which are followed by R_16 entries, and
1329 R_32 entries go at the end. See finalize_got_offsets for details.
1331 Negative GOT offsets: To double usable offset range of GOTs we use
1332 negative offsets. As we assign entries with GOT offsets relative to
1333 start of .got section, the offset values are positive. They become
1334 negative only in relocate_section where got->offset value is
1335 subtracted from them.
1337 3 special GOT entries: There are 3 special GOT entries used internally
1338 by loader. These entries happen to be placed to .got.plt section,
1339 so we don't do anything about them in multi-GOT support.
1341 Memory management: All data except for hashtables
1342 multi_got->bfd2got and got->entries are allocated on
1343 elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1344 to most functions), so we don't need to care to free them. At the
1345 moment of allocation hashtables are being linked into main data
1346 structure (multi_got), all pieces of which are reachable from
1347 elf_m68k_multi_got (info). We deallocate them in
1348 elf_m68k_link_hash_table_free. */
1350 /* Initialize GOT. */
1353 elf_m68k_init_got (struct elf_m68k_got
*got
)
1355 got
->entries
= NULL
;
1356 got
->n_slots
[R_8
] = 0;
1357 got
->n_slots
[R_16
] = 0;
1358 got
->n_slots
[R_32
] = 0;
1359 got
->local_n_slots
= 0;
1360 got
->offset
= (bfd_vma
) -1;
1366 elf_m68k_clear_got (struct elf_m68k_got
*got
)
1368 if (got
->entries
!= NULL
)
1370 htab_delete (got
->entries
);
1371 got
->entries
= NULL
;
1375 /* Create and empty GOT structure. INFO is the context where memory
1376 should be allocated. */
1378 static struct elf_m68k_got
*
1379 elf_m68k_create_empty_got (struct bfd_link_info
*info
)
1381 struct elf_m68k_got
*got
;
1383 got
= bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*got
));
1387 elf_m68k_init_got (got
);
1392 /* Initialize KEY. */
1395 elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key
*key
,
1396 struct elf_link_hash_entry
*h
,
1397 const bfd
*abfd
, unsigned long symndx
,
1398 enum elf_m68k_reloc_type reloc_type
)
1400 if (elf_m68k_reloc_got_type (reloc_type
) == R_68K_TLS_LDM32
)
1401 /* All TLS_LDM relocations share a single GOT entry. */
1407 /* Global symbols are identified with their got_entry_key. */
1410 key
->symndx
= elf_m68k_hash_entry (h
)->got_entry_key
;
1411 BFD_ASSERT (key
->symndx
!= 0);
1414 /* Local symbols are identified by BFD they appear in and symndx. */
1417 key
->symndx
= symndx
;
1420 key
->type
= reloc_type
;
1423 /* Calculate hash of got_entry.
1427 elf_m68k_got_entry_hash (const void *_entry
)
1429 const struct elf_m68k_got_entry_key
*key
;
1431 key
= &((const struct elf_m68k_got_entry
*) _entry
)->key_
;
1434 + (key
->bfd
!= NULL
? (int) key
->bfd
->id
: -1)
1435 + elf_m68k_reloc_got_type (key
->type
));
1438 /* Check if two got entries are equal. */
1441 elf_m68k_got_entry_eq (const void *_entry1
, const void *_entry2
)
1443 const struct elf_m68k_got_entry_key
*key1
;
1444 const struct elf_m68k_got_entry_key
*key2
;
1446 key1
= &((const struct elf_m68k_got_entry
*) _entry1
)->key_
;
1447 key2
= &((const struct elf_m68k_got_entry
*) _entry2
)->key_
;
1449 return (key1
->bfd
== key2
->bfd
1450 && key1
->symndx
== key2
->symndx
1451 && (elf_m68k_reloc_got_type (key1
->type
)
1452 == elf_m68k_reloc_got_type (key2
->type
)));
1455 /* When using negative offsets, we allocate one extra R_8, one extra R_16
1456 and one extra R_32 slots to simplify handling of 2-slot entries during
1457 offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
1459 /* Maximal number of R_8 slots in a single GOT. */
1460 #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
1461 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1465 /* Maximal number of R_8 and R_16 slots in a single GOT. */
1466 #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
1467 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1471 /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1472 the entry cannot be found.
1473 FIND_OR_CREATE - search for an existing entry, but create new if there's
1475 MUST_FIND - search for an existing entry and assert that it exist.
1476 MUST_CREATE - assert that there's no such entry and create new one. */
1477 enum elf_m68k_get_entry_howto
1485 /* Get or create (depending on HOWTO) entry with KEY in GOT.
1486 INFO is context in which memory should be allocated (can be NULL if
1487 HOWTO is SEARCH or MUST_FIND). */
1489 static struct elf_m68k_got_entry
*
1490 elf_m68k_get_got_entry (struct elf_m68k_got
*got
,
1491 const struct elf_m68k_got_entry_key
*key
,
1492 enum elf_m68k_get_entry_howto howto
,
1493 struct bfd_link_info
*info
)
1495 struct elf_m68k_got_entry entry_
;
1496 struct elf_m68k_got_entry
*entry
;
1499 BFD_ASSERT ((info
== NULL
) == (howto
== SEARCH
|| howto
== MUST_FIND
));
1501 if (got
->entries
== NULL
)
1502 /* This is the first entry in ABFD. Initialize hashtable. */
1504 if (howto
== SEARCH
)
1507 got
->entries
= htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1509 elf_m68k_got_entry_hash
,
1510 elf_m68k_got_entry_eq
, NULL
);
1511 if (got
->entries
== NULL
)
1513 bfd_set_error (bfd_error_no_memory
);
1519 ptr
= htab_find_slot (got
->entries
, &entry_
, (howto
!= SEARCH
1520 ? INSERT
: NO_INSERT
));
1523 if (howto
== SEARCH
)
1524 /* Entry not found. */
1527 /* We're out of memory. */
1528 bfd_set_error (bfd_error_no_memory
);
1533 /* We didn't find the entry and we're asked to create a new one. */
1535 BFD_ASSERT (howto
!= MUST_FIND
&& howto
!= SEARCH
);
1537 entry
= bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*entry
));
1541 /* Initialize new entry. */
1544 entry
->u
.s1
.refcount
= 0;
1546 /* Mark the entry as not initialized. */
1547 entry
->key_
.type
= R_68K_max
;
1552 /* We found the entry. */
1554 BFD_ASSERT (howto
!= MUST_CREATE
);
1562 /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1563 Return the value to which ENTRY's type should be set. */
1565 static enum elf_m68k_reloc_type
1566 elf_m68k_update_got_entry_type (struct elf_m68k_got
*got
,
1567 enum elf_m68k_reloc_type was
,
1568 enum elf_m68k_reloc_type new_reloc
)
1570 enum elf_m68k_got_offset_size was_size
;
1571 enum elf_m68k_got_offset_size new_size
;
1574 if (was
== R_68K_max
)
1575 /* The type of the entry is not initialized yet. */
1577 /* Update all got->n_slots counters, including n_slots[R_32]. */
1584 /* !!! We, probably, should emit an error rather then fail on assert
1586 BFD_ASSERT (elf_m68k_reloc_got_type (was
)
1587 == elf_m68k_reloc_got_type (new_reloc
));
1589 was_size
= elf_m68k_reloc_got_offset_size (was
);
1592 new_size
= elf_m68k_reloc_got_offset_size (new_reloc
);
1593 n_slots
= elf_m68k_reloc_got_n_slots (new_reloc
);
1595 while (was_size
> new_size
)
1598 got
->n_slots
[was_size
] += n_slots
;
1601 if (new_reloc
> was
)
1602 /* Relocations are ordered from bigger got offset size to lesser,
1603 so choose the relocation type with lesser offset size. */
1609 /* Update GOT counters when removing an entry of type TYPE. */
1612 elf_m68k_remove_got_entry_type (struct elf_m68k_got
*got
,
1613 enum elf_m68k_reloc_type type
)
1615 enum elf_m68k_got_offset_size os
;
1618 n_slots
= elf_m68k_reloc_got_n_slots (type
);
1620 /* Decrese counter of slots with offset size corresponding to TYPE
1621 and all greater offset sizes. */
1622 for (os
= elf_m68k_reloc_got_offset_size (type
); os
<= R_32
; ++os
)
1624 BFD_ASSERT (got
->n_slots
[os
] >= n_slots
);
1626 got
->n_slots
[os
] -= n_slots
;
1630 /* Add new or update existing entry to GOT.
1631 H, ABFD, TYPE and SYMNDX is data for the entry.
1632 INFO is a context where memory should be allocated. */
1634 static struct elf_m68k_got_entry
*
1635 elf_m68k_add_entry_to_got (struct elf_m68k_got
*got
,
1636 struct elf_link_hash_entry
*h
,
1638 enum elf_m68k_reloc_type reloc_type
,
1639 unsigned long symndx
,
1640 struct bfd_link_info
*info
)
1642 struct elf_m68k_got_entry_key key_
;
1643 struct elf_m68k_got_entry
*entry
;
1645 if (h
!= NULL
&& elf_m68k_hash_entry (h
)->got_entry_key
== 0)
1646 elf_m68k_hash_entry (h
)->got_entry_key
1647 = elf_m68k_multi_got (info
)->global_symndx
++;
1649 elf_m68k_init_got_entry_key (&key_
, h
, abfd
, symndx
, reloc_type
);
1651 entry
= elf_m68k_get_got_entry (got
, &key_
, FIND_OR_CREATE
, info
);
1655 /* Determine entry's type and update got->n_slots counters. */
1656 entry
->key_
.type
= elf_m68k_update_got_entry_type (got
,
1660 /* Update refcount. */
1661 ++entry
->u
.s1
.refcount
;
1663 if (entry
->u
.s1
.refcount
== 1)
1664 /* We see this entry for the first time. */
1666 if (entry
->key_
.bfd
!= NULL
)
1667 got
->local_n_slots
+= elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
1670 BFD_ASSERT (got
->n_slots
[R_32
] >= got
->local_n_slots
);
1672 if ((got
->n_slots
[R_8
]
1673 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1674 || (got
->n_slots
[R_16
]
1675 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
)))
1676 /* This BFD has too many relocation. */
1678 if (got
->n_slots
[R_8
] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1679 /* xgettext:c-format */
1680 _bfd_error_handler (_("%B: GOT overflow: "
1681 "Number of relocations with 8-bit "
1684 ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
));
1686 /* xgettext:c-format */
1687 _bfd_error_handler (_("%B: GOT overflow: "
1688 "Number of relocations with 8- or 16-bit "
1691 ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
));
1699 /* Compute the hash value of the bfd in a bfd2got hash entry. */
1702 elf_m68k_bfd2got_entry_hash (const void *entry
)
1704 const struct elf_m68k_bfd2got_entry
*e
;
1706 e
= (const struct elf_m68k_bfd2got_entry
*) entry
;
1711 /* Check whether two hash entries have the same bfd. */
1714 elf_m68k_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
1716 const struct elf_m68k_bfd2got_entry
*e1
;
1717 const struct elf_m68k_bfd2got_entry
*e2
;
1719 e1
= (const struct elf_m68k_bfd2got_entry
*) entry1
;
1720 e2
= (const struct elf_m68k_bfd2got_entry
*) entry2
;
1722 return e1
->bfd
== e2
->bfd
;
1725 /* Destruct a bfd2got entry. */
1728 elf_m68k_bfd2got_entry_del (void *_entry
)
1730 struct elf_m68k_bfd2got_entry
*entry
;
1732 entry
= (struct elf_m68k_bfd2got_entry
*) _entry
;
1734 BFD_ASSERT (entry
->got
!= NULL
);
1735 elf_m68k_clear_got (entry
->got
);
1738 /* Find existing or create new (depending on HOWTO) bfd2got entry in
1739 MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1740 memory should be allocated. */
1742 static struct elf_m68k_bfd2got_entry
*
1743 elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got
*multi_got
,
1745 enum elf_m68k_get_entry_howto howto
,
1746 struct bfd_link_info
*info
)
1748 struct elf_m68k_bfd2got_entry entry_
;
1750 struct elf_m68k_bfd2got_entry
*entry
;
1752 BFD_ASSERT ((info
== NULL
) == (howto
== SEARCH
|| howto
== MUST_FIND
));
1754 if (multi_got
->bfd2got
== NULL
)
1755 /* This is the first GOT. Initialize bfd2got. */
1757 if (howto
== SEARCH
)
1760 multi_got
->bfd2got
= htab_try_create (1, elf_m68k_bfd2got_entry_hash
,
1761 elf_m68k_bfd2got_entry_eq
,
1762 elf_m68k_bfd2got_entry_del
);
1763 if (multi_got
->bfd2got
== NULL
)
1765 bfd_set_error (bfd_error_no_memory
);
1771 ptr
= htab_find_slot (multi_got
->bfd2got
, &entry_
, (howto
!= SEARCH
1772 ? INSERT
: NO_INSERT
));
1775 if (howto
== SEARCH
)
1776 /* Entry not found. */
1779 /* We're out of memory. */
1780 bfd_set_error (bfd_error_no_memory
);
1785 /* Entry was not found. Create new one. */
1787 BFD_ASSERT (howto
!= MUST_FIND
&& howto
!= SEARCH
);
1789 entry
= ((struct elf_m68k_bfd2got_entry
*)
1790 bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*entry
)));
1796 entry
->got
= elf_m68k_create_empty_got (info
);
1797 if (entry
->got
== NULL
)
1804 BFD_ASSERT (howto
!= MUST_CREATE
);
1806 /* Return existing entry. */
1813 struct elf_m68k_can_merge_gots_arg
1815 /* A current_got that we constructing a DIFF against. */
1816 struct elf_m68k_got
*big
;
1818 /* GOT holding entries not present or that should be changed in
1820 struct elf_m68k_got
*diff
;
1822 /* Context where to allocate memory. */
1823 struct bfd_link_info
*info
;
1826 bfd_boolean error_p
;
1829 /* Process a single entry from the small GOT to see if it should be added
1830 or updated in the big GOT. */
1833 elf_m68k_can_merge_gots_1 (void **_entry_ptr
, void *_arg
)
1835 const struct elf_m68k_got_entry
*entry1
;
1836 struct elf_m68k_can_merge_gots_arg
*arg
;
1837 const struct elf_m68k_got_entry
*entry2
;
1838 enum elf_m68k_reloc_type type
;
1840 entry1
= (const struct elf_m68k_got_entry
*) *_entry_ptr
;
1841 arg
= (struct elf_m68k_can_merge_gots_arg
*) _arg
;
1843 entry2
= elf_m68k_get_got_entry (arg
->big
, &entry1
->key_
, SEARCH
, NULL
);
1846 /* We found an existing entry. Check if we should update it. */
1848 type
= elf_m68k_update_got_entry_type (arg
->diff
,
1852 if (type
== entry2
->key_
.type
)
1853 /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1854 To skip creation of difference entry we use the type,
1855 which we won't see in GOT entries for sure. */
1859 /* We didn't find the entry. Add entry1 to DIFF. */
1861 BFD_ASSERT (entry1
->key_
.type
!= R_68K_max
);
1863 type
= elf_m68k_update_got_entry_type (arg
->diff
,
1864 R_68K_max
, entry1
->key_
.type
);
1866 if (entry1
->key_
.bfd
!= NULL
)
1867 arg
->diff
->local_n_slots
+= elf_m68k_reloc_got_n_slots (type
);
1870 if (type
!= R_68K_max
)
1871 /* Create an entry in DIFF. */
1873 struct elf_m68k_got_entry
*entry
;
1875 entry
= elf_m68k_get_got_entry (arg
->diff
, &entry1
->key_
, MUST_CREATE
,
1879 arg
->error_p
= TRUE
;
1883 entry
->key_
.type
= type
;
1889 /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1890 Construct DIFF GOT holding the entries which should be added or updated
1891 in BIG GOT to accumulate information from SMALL.
1892 INFO is the context where memory should be allocated. */
1895 elf_m68k_can_merge_gots (struct elf_m68k_got
*big
,
1896 const struct elf_m68k_got
*small
,
1897 struct bfd_link_info
*info
,
1898 struct elf_m68k_got
*diff
)
1900 struct elf_m68k_can_merge_gots_arg arg_
;
1902 BFD_ASSERT (small
->offset
== (bfd_vma
) -1);
1907 arg_
.error_p
= FALSE
;
1908 htab_traverse_noresize (small
->entries
, elf_m68k_can_merge_gots_1
, &arg_
);
1915 /* Check for overflow. */
1916 if ((big
->n_slots
[R_8
] + arg_
.diff
->n_slots
[R_8
]
1917 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1918 || (big
->n_slots
[R_16
] + arg_
.diff
->n_slots
[R_16
]
1919 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
)))
1925 struct elf_m68k_merge_gots_arg
1928 struct elf_m68k_got
*big
;
1930 /* Context where memory should be allocated. */
1931 struct bfd_link_info
*info
;
1934 bfd_boolean error_p
;
1937 /* Process a single entry from DIFF got. Add or update corresponding
1938 entry in the BIG got. */
1941 elf_m68k_merge_gots_1 (void **entry_ptr
, void *_arg
)
1943 const struct elf_m68k_got_entry
*from
;
1944 struct elf_m68k_merge_gots_arg
*arg
;
1945 struct elf_m68k_got_entry
*to
;
1947 from
= (const struct elf_m68k_got_entry
*) *entry_ptr
;
1948 arg
= (struct elf_m68k_merge_gots_arg
*) _arg
;
1950 to
= elf_m68k_get_got_entry (arg
->big
, &from
->key_
, FIND_OR_CREATE
,
1954 arg
->error_p
= TRUE
;
1958 BFD_ASSERT (to
->u
.s1
.refcount
== 0);
1959 /* All we need to merge is TYPE. */
1960 to
->key_
.type
= from
->key_
.type
;
1965 /* Merge data from DIFF to BIG. INFO is context where memory should be
1969 elf_m68k_merge_gots (struct elf_m68k_got
*big
,
1970 struct elf_m68k_got
*diff
,
1971 struct bfd_link_info
*info
)
1973 if (diff
->entries
!= NULL
)
1974 /* DIFF is not empty. Merge it into BIG GOT. */
1976 struct elf_m68k_merge_gots_arg arg_
;
1978 /* Merge entries. */
1981 arg_
.error_p
= FALSE
;
1982 htab_traverse_noresize (diff
->entries
, elf_m68k_merge_gots_1
, &arg_
);
1986 /* Merge counters. */
1987 big
->n_slots
[R_8
] += diff
->n_slots
[R_8
];
1988 big
->n_slots
[R_16
] += diff
->n_slots
[R_16
];
1989 big
->n_slots
[R_32
] += diff
->n_slots
[R_32
];
1990 big
->local_n_slots
+= diff
->local_n_slots
;
1993 /* DIFF is empty. */
1995 BFD_ASSERT (diff
->n_slots
[R_8
] == 0);
1996 BFD_ASSERT (diff
->n_slots
[R_16
] == 0);
1997 BFD_ASSERT (diff
->n_slots
[R_32
] == 0);
1998 BFD_ASSERT (diff
->local_n_slots
== 0);
2001 BFD_ASSERT (!elf_m68k_hash_table (info
)->allow_multigot_p
2002 || ((big
->n_slots
[R_8
]
2003 <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
2004 && (big
->n_slots
[R_16
]
2005 <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
))));
2010 struct elf_m68k_finalize_got_offsets_arg
2012 /* Ranges of the offsets for GOT entries.
2013 R_x entries receive offsets between offset1[R_x] and offset2[R_x].
2014 R_x is R_8, R_16 and R_32. */
2018 /* Mapping from global symndx to global symbols.
2019 This is used to build lists of got entries for global symbols. */
2020 struct elf_m68k_link_hash_entry
**symndx2h
;
2022 bfd_vma n_ldm_entries
;
2025 /* Assign ENTRY an offset. Build list of GOT entries for global symbols
2029 elf_m68k_finalize_got_offsets_1 (void **entry_ptr
, void *_arg
)
2031 struct elf_m68k_got_entry
*entry
;
2032 struct elf_m68k_finalize_got_offsets_arg
*arg
;
2034 enum elf_m68k_got_offset_size got_offset_size
;
2037 entry
= (struct elf_m68k_got_entry
*) *entry_ptr
;
2038 arg
= (struct elf_m68k_finalize_got_offsets_arg
*) _arg
;
2040 /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
2041 BFD_ASSERT (entry
->u
.s1
.refcount
== 0);
2043 /* Get GOT offset size for the entry . */
2044 got_offset_size
= elf_m68k_reloc_got_offset_size (entry
->key_
.type
);
2046 /* Calculate entry size in bytes. */
2047 entry_size
= 4 * elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
2049 /* Check if we should switch to negative range of the offsets. */
2050 if (arg
->offset1
[got_offset_size
] + entry_size
2051 > arg
->offset2
[got_offset_size
])
2053 /* Verify that this is the only switch to negative range for
2054 got_offset_size. If this assertion fails, then we've miscalculated
2055 range for got_offset_size entries in
2056 elf_m68k_finalize_got_offsets. */
2057 BFD_ASSERT (arg
->offset2
[got_offset_size
]
2058 != arg
->offset2
[-(int) got_offset_size
- 1]);
2061 arg
->offset1
[got_offset_size
] = arg
->offset1
[-(int) got_offset_size
- 1];
2062 arg
->offset2
[got_offset_size
] = arg
->offset2
[-(int) got_offset_size
- 1];
2064 /* Verify that now we have enough room for the entry. */
2065 BFD_ASSERT (arg
->offset1
[got_offset_size
] + entry_size
2066 <= arg
->offset2
[got_offset_size
]);
2069 /* Assign offset to entry. */
2070 entry
->u
.s2
.offset
= arg
->offset1
[got_offset_size
];
2071 arg
->offset1
[got_offset_size
] += entry_size
;
2073 if (entry
->key_
.bfd
== NULL
)
2074 /* Hook up this entry into the list of got_entries of H. */
2076 struct elf_m68k_link_hash_entry
*h
;
2078 h
= arg
->symndx2h
[entry
->key_
.symndx
];
2081 entry
->u
.s2
.next
= h
->glist
;
2085 /* This should be the entry for TLS_LDM relocation then. */
2087 BFD_ASSERT ((elf_m68k_reloc_got_type (entry
->key_
.type
)
2089 && entry
->key_
.symndx
== 0);
2091 ++arg
->n_ldm_entries
;
2095 /* This entry is for local symbol. */
2096 entry
->u
.s2
.next
= NULL
;
2101 /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
2102 should use negative offsets.
2103 Build list of GOT entries for global symbols along the way.
2104 SYMNDX2H is mapping from global symbol indices to actual
2106 Return offset at which next GOT should start. */
2109 elf_m68k_finalize_got_offsets (struct elf_m68k_got
*got
,
2110 bfd_boolean use_neg_got_offsets_p
,
2111 struct elf_m68k_link_hash_entry
**symndx2h
,
2112 bfd_vma
*final_offset
, bfd_vma
*n_ldm_entries
)
2114 struct elf_m68k_finalize_got_offsets_arg arg_
;
2115 bfd_vma offset1_
[2 * R_LAST
];
2116 bfd_vma offset2_
[2 * R_LAST
];
2118 bfd_vma start_offset
;
2120 BFD_ASSERT (got
->offset
!= (bfd_vma
) -1);
2122 /* We set entry offsets relative to the .got section (and not the
2123 start of a particular GOT), so that we can use them in
2124 finish_dynamic_symbol without needing to know the GOT which they come
2127 /* Put offset1 in the middle of offset1_, same for offset2. */
2128 arg_
.offset1
= offset1_
+ R_LAST
;
2129 arg_
.offset2
= offset2_
+ R_LAST
;
2131 start_offset
= got
->offset
;
2133 if (use_neg_got_offsets_p
)
2134 /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
2135 i
= -(int) R_32
- 1;
2137 /* Setup positives ranges for R_8, R_16 and R_32. */
2140 for (; i
<= (int) R_32
; ++i
)
2145 /* Set beginning of the range of offsets I. */
2146 arg_
.offset1
[i
] = start_offset
;
2148 /* Calculate number of slots that require I offsets. */
2149 j
= (i
>= 0) ? i
: -i
- 1;
2150 n
= (j
>= 1) ? got
->n_slots
[j
- 1] : 0;
2151 n
= got
->n_slots
[j
] - n
;
2153 if (use_neg_got_offsets_p
&& n
!= 0)
2156 /* We first fill the positive side of the range, so we might
2157 end up with one empty slot at that side when we can't fit
2158 whole 2-slot entry. Account for that at negative side of
2159 the interval with one additional entry. */
2162 /* When the number of slots is odd, make positive side of the
2163 range one entry bigger. */
2167 /* N is the number of slots that require I offsets.
2168 Calculate length of the range for I offsets. */
2171 /* Set end of the range. */
2172 arg_
.offset2
[i
] = start_offset
+ n
;
2174 start_offset
= arg_
.offset2
[i
];
2177 if (!use_neg_got_offsets_p
)
2178 /* Make sure that if we try to switch to negative offsets in
2179 elf_m68k_finalize_got_offsets_1, the assert therein will catch
2181 for (i
= R_8
; i
<= R_32
; ++i
)
2182 arg_
.offset2
[-i
- 1] = arg_
.offset2
[i
];
2184 /* Setup got->offset. offset1[R_8] is either in the middle or at the
2185 beginning of GOT depending on use_neg_got_offsets_p. */
2186 got
->offset
= arg_
.offset1
[R_8
];
2188 arg_
.symndx2h
= symndx2h
;
2189 arg_
.n_ldm_entries
= 0;
2191 /* Assign offsets. */
2192 htab_traverse (got
->entries
, elf_m68k_finalize_got_offsets_1
, &arg_
);
2194 /* Check offset ranges we have actually assigned. */
2195 for (i
= (int) R_8
; i
<= (int) R_32
; ++i
)
2196 BFD_ASSERT (arg_
.offset2
[i
] - arg_
.offset1
[i
] <= 4);
2198 *final_offset
= start_offset
;
2199 *n_ldm_entries
= arg_
.n_ldm_entries
;
2202 struct elf_m68k_partition_multi_got_arg
2204 /* The GOT we are adding entries to. Aka big got. */
2205 struct elf_m68k_got
*current_got
;
2207 /* Offset to assign the next CURRENT_GOT. */
2210 /* Context where memory should be allocated. */
2211 struct bfd_link_info
*info
;
2213 /* Total number of slots in the .got section.
2214 This is used to calculate size of the .got and .rela.got sections. */
2217 /* Difference in numbers of allocated slots in the .got section
2218 and necessary relocations in the .rela.got section.
2219 This is used to calculate size of the .rela.got section. */
2220 bfd_vma slots_relas_diff
;
2223 bfd_boolean error_p
;
2225 /* Mapping from global symndx to global symbols.
2226 This is used to build lists of got entries for global symbols. */
2227 struct elf_m68k_link_hash_entry
**symndx2h
;
2231 elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg
*arg
)
2233 bfd_vma n_ldm_entries
;
2235 elf_m68k_finalize_got_offsets (arg
->current_got
,
2236 (elf_m68k_hash_table (arg
->info
)
2237 ->use_neg_got_offsets_p
),
2239 &arg
->offset
, &n_ldm_entries
);
2241 arg
->n_slots
+= arg
->current_got
->n_slots
[R_32
];
2243 if (!bfd_link_pic (arg
->info
))
2244 /* If we are generating a shared object, we need to
2245 output a R_68K_RELATIVE reloc so that the dynamic
2246 linker can adjust this GOT entry. Overwise we
2247 don't need space in .rela.got for local symbols. */
2248 arg
->slots_relas_diff
+= arg
->current_got
->local_n_slots
;
2250 /* @LDM relocations require a 2-slot GOT entry, but only
2251 one relocation. Account for that. */
2252 arg
->slots_relas_diff
+= n_ldm_entries
;
2254 BFD_ASSERT (arg
->slots_relas_diff
<= arg
->n_slots
);
2258 /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2259 or start a new CURRENT_GOT. */
2262 elf_m68k_partition_multi_got_1 (void **_entry
, void *_arg
)
2264 struct elf_m68k_bfd2got_entry
*entry
;
2265 struct elf_m68k_partition_multi_got_arg
*arg
;
2266 struct elf_m68k_got
*got
;
2267 struct elf_m68k_got diff_
;
2268 struct elf_m68k_got
*diff
;
2270 entry
= (struct elf_m68k_bfd2got_entry
*) *_entry
;
2271 arg
= (struct elf_m68k_partition_multi_got_arg
*) _arg
;
2274 BFD_ASSERT (got
!= NULL
);
2275 BFD_ASSERT (got
->offset
== (bfd_vma
) -1);
2279 if (arg
->current_got
!= NULL
)
2280 /* Construct diff. */
2283 elf_m68k_init_got (diff
);
2285 if (!elf_m68k_can_merge_gots (arg
->current_got
, got
, arg
->info
, diff
))
2287 if (diff
->offset
== 0)
2288 /* Offset set to 0 in the diff_ indicates an error. */
2290 arg
->error_p
= TRUE
;
2294 if (elf_m68k_hash_table (arg
->info
)->allow_multigot_p
)
2296 elf_m68k_clear_got (diff
);
2297 /* Schedule to finish up current_got and start new one. */
2301 Merge GOTs no matter what. If big GOT overflows,
2302 we'll fail in relocate_section due to truncated relocations.
2304 ??? May be fail earlier? E.g., in can_merge_gots. */
2308 /* Diff of got against empty current_got is got itself. */
2310 /* Create empty current_got to put subsequent GOTs to. */
2311 arg
->current_got
= elf_m68k_create_empty_got (arg
->info
);
2312 if (arg
->current_got
== NULL
)
2314 arg
->error_p
= TRUE
;
2318 arg
->current_got
->offset
= arg
->offset
;
2325 if (!elf_m68k_merge_gots (arg
->current_got
, diff
, arg
->info
))
2327 arg
->error_p
= TRUE
;
2331 /* Now we can free GOT. */
2332 elf_m68k_clear_got (got
);
2334 entry
->got
= arg
->current_got
;
2338 /* Finish up current_got. */
2339 elf_m68k_partition_multi_got_2 (arg
);
2341 /* Schedule to start a new current_got. */
2342 arg
->current_got
= NULL
;
2345 if (!elf_m68k_partition_multi_got_1 (_entry
, _arg
))
2347 BFD_ASSERT (arg
->error_p
);
2354 elf_m68k_clear_got (diff
);
2356 return arg
->error_p
== FALSE
? 1 : 0;
2359 /* Helper function to build symndx2h mapping. */
2362 elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry
*_h
,
2365 struct elf_m68k_link_hash_entry
*h
;
2367 h
= elf_m68k_hash_entry (_h
);
2369 if (h
->got_entry_key
!= 0)
2370 /* H has at least one entry in the GOT. */
2372 struct elf_m68k_partition_multi_got_arg
*arg
;
2374 arg
= (struct elf_m68k_partition_multi_got_arg
*) _arg
;
2376 BFD_ASSERT (arg
->symndx2h
[h
->got_entry_key
] == NULL
);
2377 arg
->symndx2h
[h
->got_entry_key
] = h
;
2383 /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2384 lists of GOT entries for global symbols.
2385 Calculate sizes of .got and .rela.got sections. */
2388 elf_m68k_partition_multi_got (struct bfd_link_info
*info
)
2390 struct elf_m68k_multi_got
*multi_got
;
2391 struct elf_m68k_partition_multi_got_arg arg_
;
2393 multi_got
= elf_m68k_multi_got (info
);
2395 arg_
.current_got
= NULL
;
2399 arg_
.slots_relas_diff
= 0;
2400 arg_
.error_p
= FALSE
;
2402 if (multi_got
->bfd2got
!= NULL
)
2404 /* Initialize symndx2h mapping. */
2406 arg_
.symndx2h
= bfd_zmalloc (multi_got
->global_symndx
2407 * sizeof (*arg_
.symndx2h
));
2408 if (arg_
.symndx2h
== NULL
)
2411 elf_link_hash_traverse (elf_hash_table (info
),
2412 elf_m68k_init_symndx2h_1
, &arg_
);
2416 htab_traverse (multi_got
->bfd2got
, elf_m68k_partition_multi_got_1
,
2420 free (arg_
.symndx2h
);
2421 arg_
.symndx2h
= NULL
;
2426 /* Finish up last current_got. */
2427 elf_m68k_partition_multi_got_2 (&arg_
);
2429 free (arg_
.symndx2h
);
2432 if (elf_hash_table (info
)->dynobj
!= NULL
)
2433 /* Set sizes of .got and .rela.got sections. */
2437 s
= elf_hash_table (info
)->sgot
;
2439 s
->size
= arg_
.offset
;
2441 BFD_ASSERT (arg_
.offset
== 0);
2443 BFD_ASSERT (arg_
.slots_relas_diff
<= arg_
.n_slots
);
2444 arg_
.n_slots
-= arg_
.slots_relas_diff
;
2446 s
= elf_hash_table (info
)->srelgot
;
2448 s
->size
= arg_
.n_slots
* sizeof (Elf32_External_Rela
);
2450 BFD_ASSERT (arg_
.n_slots
== 0);
2453 BFD_ASSERT (multi_got
->bfd2got
== NULL
);
2458 /* Specialized version of elf_m68k_get_got_entry that returns pointer
2459 to hashtable slot, thus allowing removal of entry via
2460 elf_m68k_remove_got_entry. */
2462 static struct elf_m68k_got_entry
**
2463 elf_m68k_find_got_entry_ptr (struct elf_m68k_got
*got
,
2464 struct elf_m68k_got_entry_key
*key
)
2467 struct elf_m68k_got_entry entry_
;
2468 struct elf_m68k_got_entry
**entry_ptr
;
2471 ptr
= htab_find_slot (got
->entries
, &entry_
, NO_INSERT
);
2472 BFD_ASSERT (ptr
!= NULL
);
2474 entry_ptr
= (struct elf_m68k_got_entry
**) ptr
;
2479 /* Remove entry pointed to by ENTRY_PTR from GOT. */
2482 elf_m68k_remove_got_entry (struct elf_m68k_got
*got
,
2483 struct elf_m68k_got_entry
**entry_ptr
)
2485 struct elf_m68k_got_entry
*entry
;
2489 /* Check that offsets have not been finalized yet. */
2490 BFD_ASSERT (got
->offset
== (bfd_vma
) -1);
2491 /* Check that this entry is indeed unused. */
2492 BFD_ASSERT (entry
->u
.s1
.refcount
== 0);
2494 elf_m68k_remove_got_entry_type (got
, entry
->key_
.type
);
2496 if (entry
->key_
.bfd
!= NULL
)
2497 got
->local_n_slots
-= elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
2499 BFD_ASSERT (got
->n_slots
[R_32
] >= got
->local_n_slots
);
2501 htab_clear_slot (got
->entries
, (void **) entry_ptr
);
2504 /* Copy any information related to dynamic linking from a pre-existing
2505 symbol to a newly created symbol. Also called to copy flags and
2506 other back-end info to a weakdef, in which case the symbol is not
2507 newly created and plt/got refcounts and dynamic indices should not
2511 elf_m68k_copy_indirect_symbol (struct bfd_link_info
*info
,
2512 struct elf_link_hash_entry
*_dir
,
2513 struct elf_link_hash_entry
*_ind
)
2515 struct elf_m68k_link_hash_entry
*dir
;
2516 struct elf_m68k_link_hash_entry
*ind
;
2518 _bfd_elf_link_hash_copy_indirect (info
, _dir
, _ind
);
2520 if (_ind
->root
.type
!= bfd_link_hash_indirect
)
2523 dir
= elf_m68k_hash_entry (_dir
);
2524 ind
= elf_m68k_hash_entry (_ind
);
2526 /* Any absolute non-dynamic relocations against an indirect or weak
2527 definition will be against the target symbol. */
2528 _dir
->non_got_ref
|= _ind
->non_got_ref
;
2530 /* We might have a direct symbol already having entries in the GOTs.
2531 Update its key only in case indirect symbol has GOT entries and
2532 assert that both indirect and direct symbols don't have GOT entries
2533 at the same time. */
2534 if (ind
->got_entry_key
!= 0)
2536 BFD_ASSERT (dir
->got_entry_key
== 0);
2537 /* Assert that GOTs aren't partioned yet. */
2538 BFD_ASSERT (ind
->glist
== NULL
);
2540 dir
->got_entry_key
= ind
->got_entry_key
;
2541 ind
->got_entry_key
= 0;
2545 /* Look through the relocs for a section during the first phase, and
2546 allocate space in the global offset table or procedure linkage
2550 elf_m68k_check_relocs (bfd
*abfd
,
2551 struct bfd_link_info
*info
,
2553 const Elf_Internal_Rela
*relocs
)
2556 Elf_Internal_Shdr
*symtab_hdr
;
2557 struct elf_link_hash_entry
**sym_hashes
;
2558 const Elf_Internal_Rela
*rel
;
2559 const Elf_Internal_Rela
*rel_end
;
2561 struct elf_m68k_got
*got
;
2563 if (bfd_link_relocatable (info
))
2566 dynobj
= elf_hash_table (info
)->dynobj
;
2567 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2568 sym_hashes
= elf_sym_hashes (abfd
);
2574 rel_end
= relocs
+ sec
->reloc_count
;
2575 for (rel
= relocs
; rel
< rel_end
; rel
++)
2577 unsigned long r_symndx
;
2578 struct elf_link_hash_entry
*h
;
2580 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2582 if (r_symndx
< symtab_hdr
->sh_info
)
2586 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2587 while (h
->root
.type
== bfd_link_hash_indirect
2588 || h
->root
.type
== bfd_link_hash_warning
)
2589 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2591 /* PR15323, ref flags aren't set for references in the same
2593 h
->root
.non_ir_ref
= 1;
2596 switch (ELF32_R_TYPE (rel
->r_info
))
2602 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2606 /* Relative GOT relocations. */
2612 /* TLS relocations. */
2614 case R_68K_TLS_GD16
:
2615 case R_68K_TLS_GD32
:
2616 case R_68K_TLS_LDM8
:
2617 case R_68K_TLS_LDM16
:
2618 case R_68K_TLS_LDM32
:
2620 case R_68K_TLS_IE16
:
2621 case R_68K_TLS_IE32
:
2623 case R_68K_TLS_TPREL32
:
2624 case R_68K_TLS_DTPREL32
:
2626 if (ELF32_R_TYPE (rel
->r_info
) == R_68K_TLS_TPREL32
2627 && bfd_link_pic (info
))
2628 /* Do the special chorus for libraries with static TLS. */
2629 info
->flags
|= DF_STATIC_TLS
;
2631 /* This symbol requires a global offset table entry. */
2635 /* Create the .got section. */
2636 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2637 if (!_bfd_elf_create_got_section (dynobj
, info
))
2643 struct elf_m68k_bfd2got_entry
*bfd2got_entry
;
2646 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
2647 abfd
, FIND_OR_CREATE
, info
);
2648 if (bfd2got_entry
== NULL
)
2651 got
= bfd2got_entry
->got
;
2652 BFD_ASSERT (got
!= NULL
);
2656 struct elf_m68k_got_entry
*got_entry
;
2658 /* Add entry to got. */
2659 got_entry
= elf_m68k_add_entry_to_got (got
, h
, abfd
,
2660 ELF32_R_TYPE (rel
->r_info
),
2662 if (got_entry
== NULL
)
2665 if (got_entry
->u
.s1
.refcount
== 1)
2667 /* Make sure this symbol is output as a dynamic symbol. */
2670 && !h
->forced_local
)
2672 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2683 /* This symbol requires a procedure linkage table entry. We
2684 actually build the entry in adjust_dynamic_symbol,
2685 because this might be a case of linking PIC code which is
2686 never referenced by a dynamic object, in which case we
2687 don't need to generate a procedure linkage table entry
2690 /* If this is a local symbol, we resolve it directly without
2691 creating a procedure linkage table entry. */
2702 /* This symbol requires a procedure linkage table entry. */
2706 /* It does not make sense to have this relocation for a
2707 local symbol. FIXME: does it? How to handle it if
2708 it does make sense? */
2709 bfd_set_error (bfd_error_bad_value
);
2713 /* Make sure this symbol is output as a dynamic symbol. */
2714 if (h
->dynindx
== -1
2715 && !h
->forced_local
)
2717 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2728 /* If we are creating a shared library and this is not a local
2729 symbol, we need to copy the reloc into the shared library.
2730 However when linking with -Bsymbolic and this is a global
2731 symbol which is defined in an object we are including in the
2732 link (i.e., DEF_REGULAR is set), then we can resolve the
2733 reloc directly. At this point we have not seen all the input
2734 files, so it is possible that DEF_REGULAR is not set now but
2735 will be set later (it is never cleared). We account for that
2736 possibility below by storing information in the
2737 pcrel_relocs_copied field of the hash table entry. */
2738 if (!(bfd_link_pic (info
)
2739 && (sec
->flags
& SEC_ALLOC
) != 0
2741 && (!SYMBOLIC_BIND (info
, h
)
2742 || h
->root
.type
== bfd_link_hash_defweak
2743 || !h
->def_regular
)))
2747 /* Make sure a plt entry is created for this symbol if
2748 it turns out to be a function defined by a dynamic
2758 /* We don't need to handle relocs into sections not going into
2759 the "real" output. */
2760 if ((sec
->flags
& SEC_ALLOC
) == 0)
2765 /* Make sure a plt entry is created for this symbol if it
2766 turns out to be a function defined by a dynamic object. */
2769 if (bfd_link_executable (info
))
2770 /* This symbol needs a non-GOT reference. */
2774 /* If we are creating a shared library, we need to copy the
2775 reloc into the shared library. */
2776 if (bfd_link_pic (info
))
2778 /* When creating a shared object, we must copy these
2779 reloc types into the output file. We create a reloc
2780 section in dynobj and make room for this reloc. */
2783 sreloc
= _bfd_elf_make_dynamic_reloc_section
2784 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
2790 if (sec
->flags
& SEC_READONLY
2791 /* Don't set DF_TEXTREL yet for PC relative
2792 relocations, they might be discarded later. */
2793 && !(ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
2794 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
2795 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
))
2796 info
->flags
|= DF_TEXTREL
;
2798 sreloc
->size
+= sizeof (Elf32_External_Rela
);
2800 /* We count the number of PC relative relocations we have
2801 entered for this symbol, so that we can discard them
2802 again if, in the -Bsymbolic case, the symbol is later
2803 defined by a regular object, or, in the normal shared
2804 case, the symbol is forced to be local. Note that this
2805 function is only called if we are using an m68kelf linker
2806 hash table, which means that h is really a pointer to an
2807 elf_m68k_link_hash_entry. */
2808 if (ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
2809 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
2810 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
)
2812 struct elf_m68k_pcrel_relocs_copied
*p
;
2813 struct elf_m68k_pcrel_relocs_copied
**head
;
2817 struct elf_m68k_link_hash_entry
*eh
2818 = elf_m68k_hash_entry (h
);
2819 head
= &eh
->pcrel_relocs_copied
;
2825 Elf_Internal_Sym
*isym
;
2827 isym
= bfd_sym_from_r_symndx (&elf_m68k_hash_table (info
)->sym_cache
,
2832 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2836 vpp
= &elf_section_data (s
)->local_dynrel
;
2837 head
= (struct elf_m68k_pcrel_relocs_copied
**) vpp
;
2840 for (p
= *head
; p
!= NULL
; p
= p
->next
)
2841 if (p
->section
== sreloc
)
2846 p
= ((struct elf_m68k_pcrel_relocs_copied
*)
2847 bfd_alloc (dynobj
, (bfd_size_type
) sizeof *p
));
2852 p
->section
= sreloc
;
2862 /* This relocation describes the C++ object vtable hierarchy.
2863 Reconstruct it for later use during GC. */
2864 case R_68K_GNU_VTINHERIT
:
2865 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2869 /* This relocation describes which C++ vtable entries are actually
2870 used. Record for later use during GC. */
2871 case R_68K_GNU_VTENTRY
:
2872 BFD_ASSERT (h
!= NULL
);
2874 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2886 /* Return the section that should be marked against GC for a given
2890 elf_m68k_gc_mark_hook (asection
*sec
,
2891 struct bfd_link_info
*info
,
2892 Elf_Internal_Rela
*rel
,
2893 struct elf_link_hash_entry
*h
,
2894 Elf_Internal_Sym
*sym
)
2897 switch (ELF32_R_TYPE (rel
->r_info
))
2899 case R_68K_GNU_VTINHERIT
:
2900 case R_68K_GNU_VTENTRY
:
2904 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2907 /* Update the got entry reference counts for the section being removed. */
2910 elf_m68k_gc_sweep_hook (bfd
*abfd
,
2911 struct bfd_link_info
*info
,
2913 const Elf_Internal_Rela
*relocs
)
2915 Elf_Internal_Shdr
*symtab_hdr
;
2916 struct elf_link_hash_entry
**sym_hashes
;
2917 const Elf_Internal_Rela
*rel
, *relend
;
2919 struct elf_m68k_got
*got
;
2921 if (bfd_link_relocatable (info
))
2924 dynobj
= elf_hash_table (info
)->dynobj
;
2928 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2929 sym_hashes
= elf_sym_hashes (abfd
);
2932 relend
= relocs
+ sec
->reloc_count
;
2933 for (rel
= relocs
; rel
< relend
; rel
++)
2935 unsigned long r_symndx
;
2936 struct elf_link_hash_entry
*h
= NULL
;
2938 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2939 if (r_symndx
>= symtab_hdr
->sh_info
)
2941 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2942 while (h
->root
.type
== bfd_link_hash_indirect
2943 || h
->root
.type
== bfd_link_hash_warning
)
2944 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2947 switch (ELF32_R_TYPE (rel
->r_info
))
2953 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2962 /* TLS relocations. */
2964 case R_68K_TLS_GD16
:
2965 case R_68K_TLS_GD32
:
2966 case R_68K_TLS_LDM8
:
2967 case R_68K_TLS_LDM16
:
2968 case R_68K_TLS_LDM32
:
2970 case R_68K_TLS_IE16
:
2971 case R_68K_TLS_IE32
:
2973 case R_68K_TLS_TPREL32
:
2974 case R_68K_TLS_DTPREL32
:
2978 got
= elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
2979 abfd
, MUST_FIND
, NULL
)->got
;
2980 BFD_ASSERT (got
!= NULL
);
2984 struct elf_m68k_got_entry_key key_
;
2985 struct elf_m68k_got_entry
**got_entry_ptr
;
2986 struct elf_m68k_got_entry
*got_entry
;
2988 elf_m68k_init_got_entry_key (&key_
, h
, abfd
, r_symndx
,
2989 ELF32_R_TYPE (rel
->r_info
));
2990 got_entry_ptr
= elf_m68k_find_got_entry_ptr (got
, &key_
);
2992 got_entry
= *got_entry_ptr
;
2994 if (got_entry
->u
.s1
.refcount
> 0)
2996 --got_entry
->u
.s1
.refcount
;
2998 if (got_entry
->u
.s1
.refcount
== 0)
2999 /* We don't need the .got entry any more. */
3000 elf_m68k_remove_got_entry (got
, got_entry_ptr
);
3019 if (h
->plt
.refcount
> 0)
3032 /* Return the type of PLT associated with OUTPUT_BFD. */
3034 static const struct elf_m68k_plt_info
*
3035 elf_m68k_get_plt_info (bfd
*output_bfd
)
3037 unsigned int features
;
3039 features
= bfd_m68k_mach_to_features (bfd_get_mach (output_bfd
));
3040 if (features
& cpu32
)
3041 return &elf_cpu32_plt_info
;
3042 if (features
& mcfisa_b
)
3043 return &elf_isab_plt_info
;
3044 if (features
& mcfisa_c
)
3045 return &elf_isac_plt_info
;
3046 return &elf_m68k_plt_info
;
3049 /* This function is called after all the input files have been read,
3050 and the input sections have been assigned to output sections.
3051 It's a convenient place to determine the PLT style. */
3054 elf_m68k_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3056 /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
3058 if (!elf_m68k_partition_multi_got (info
))
3061 elf_m68k_hash_table (info
)->plt_info
= elf_m68k_get_plt_info (output_bfd
);
3065 /* Adjust a symbol defined by a dynamic object and referenced by a
3066 regular object. The current definition is in some section of the
3067 dynamic object, but we're not including those sections. We have to
3068 change the definition to something the rest of the link can
3072 elf_m68k_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3073 struct elf_link_hash_entry
*h
)
3075 struct elf_m68k_link_hash_table
*htab
;
3079 htab
= elf_m68k_hash_table (info
);
3080 dynobj
= htab
->root
.dynobj
;
3082 /* Make sure we know what is going on here. */
3083 BFD_ASSERT (dynobj
!= NULL
3085 || h
->u
.weakdef
!= NULL
3088 && !h
->def_regular
)));
3090 /* If this is a function, put it in the procedure linkage table. We
3091 will fill in the contents of the procedure linkage table later,
3092 when we know the address of the .got section. */
3093 if (h
->type
== STT_FUNC
3096 if ((h
->plt
.refcount
<= 0
3097 || SYMBOL_CALLS_LOCAL (info
, h
)
3098 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3099 && h
->root
.type
== bfd_link_hash_undefweak
))
3100 /* We must always create the plt entry if it was referenced
3101 by a PLTxxO relocation. In this case we already recorded
3102 it as a dynamic symbol. */
3103 && h
->dynindx
== -1)
3105 /* This case can occur if we saw a PLTxx reloc in an input
3106 file, but the symbol was never referred to by a dynamic
3107 object, or if all references were garbage collected. In
3108 such a case, we don't actually need to build a procedure
3109 linkage table, and we can just do a PCxx reloc instead. */
3110 h
->plt
.offset
= (bfd_vma
) -1;
3115 /* Make sure this symbol is output as a dynamic symbol. */
3116 if (h
->dynindx
== -1
3117 && !h
->forced_local
)
3119 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3123 s
= htab
->root
.splt
;
3124 BFD_ASSERT (s
!= NULL
);
3126 /* If this is the first .plt entry, make room for the special
3129 s
->size
= htab
->plt_info
->size
;
3131 /* If this symbol is not defined in a regular file, and we are
3132 not generating a shared library, then set the symbol to this
3133 location in the .plt. This is required to make function
3134 pointers compare as equal between the normal executable and
3135 the shared library. */
3136 if (!bfd_link_pic (info
)
3139 h
->root
.u
.def
.section
= s
;
3140 h
->root
.u
.def
.value
= s
->size
;
3143 h
->plt
.offset
= s
->size
;
3145 /* Make room for this entry. */
3146 s
->size
+= htab
->plt_info
->size
;
3148 /* We also need to make an entry in the .got.plt section, which
3149 will be placed in the .got section by the linker script. */
3150 s
= htab
->root
.sgotplt
;
3151 BFD_ASSERT (s
!= NULL
);
3154 /* We also need to make an entry in the .rela.plt section. */
3155 s
= htab
->root
.srelplt
;
3156 BFD_ASSERT (s
!= NULL
);
3157 s
->size
+= sizeof (Elf32_External_Rela
);
3162 /* Reinitialize the plt offset now that it is not used as a reference
3164 h
->plt
.offset
= (bfd_vma
) -1;
3166 /* If this is a weak symbol, and there is a real definition, the
3167 processor independent code will have arranged for us to see the
3168 real definition first, and we can just use the same value. */
3169 if (h
->u
.weakdef
!= NULL
)
3171 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3172 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3173 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3174 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3178 /* This is a reference to a symbol defined by a dynamic object which
3179 is not a function. */
3181 /* If we are creating a shared library, we must presume that the
3182 only references to the symbol are via the global offset table.
3183 For such cases we need not do anything here; the relocations will
3184 be handled correctly by relocate_section. */
3185 if (bfd_link_pic (info
))
3188 /* If there are no references to this symbol that do not use the
3189 GOT, we don't need to generate a copy reloc. */
3190 if (!h
->non_got_ref
)
3193 /* We must allocate the symbol in our .dynbss section, which will
3194 become part of the .bss section of the executable. There will be
3195 an entry for this symbol in the .dynsym section. The dynamic
3196 object will contain position independent code, so all references
3197 from the dynamic object to this symbol will go through the global
3198 offset table. The dynamic linker will use the .dynsym entry to
3199 determine the address it must put in the global offset table, so
3200 both the dynamic object and the regular object will refer to the
3201 same memory location for the variable. */
3203 s
= bfd_get_linker_section (dynobj
, ".dynbss");
3204 BFD_ASSERT (s
!= NULL
);
3206 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3207 copy the initial value out of the dynamic object and into the
3208 runtime process image. We need to remember the offset into the
3209 .rela.bss section we are going to use. */
3210 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3214 srel
= bfd_get_linker_section (dynobj
, ".rela.bss");
3215 BFD_ASSERT (srel
!= NULL
);
3216 srel
->size
+= sizeof (Elf32_External_Rela
);
3220 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3223 /* Set the sizes of the dynamic sections. */
3226 elf_m68k_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3227 struct bfd_link_info
*info
)
3234 dynobj
= elf_hash_table (info
)->dynobj
;
3235 BFD_ASSERT (dynobj
!= NULL
);
3237 if (elf_hash_table (info
)->dynamic_sections_created
)
3239 /* Set the contents of the .interp section to the interpreter. */
3240 if (bfd_link_executable (info
) && !info
->nointerp
)
3242 s
= bfd_get_linker_section (dynobj
, ".interp");
3243 BFD_ASSERT (s
!= NULL
);
3244 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3245 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3250 /* We may have created entries in the .rela.got section.
3251 However, if we are not creating the dynamic sections, we will
3252 not actually use these entries. Reset the size of .rela.got,
3253 which will cause it to get stripped from the output file
3255 s
= elf_hash_table (info
)->srelgot
;
3260 /* If this is a -Bsymbolic shared link, then we need to discard all
3261 PC relative relocs against symbols defined in a regular object.
3262 For the normal shared case we discard the PC relative relocs
3263 against symbols that have become local due to visibility changes.
3264 We allocated space for them in the check_relocs routine, but we
3265 will not fill them in in the relocate_section routine. */
3266 if (bfd_link_pic (info
))
3267 elf_link_hash_traverse (elf_hash_table (info
),
3268 elf_m68k_discard_copies
,
3271 /* The check_relocs and adjust_dynamic_symbol entry points have
3272 determined the sizes of the various dynamic sections. Allocate
3276 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3280 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3283 /* It's OK to base decisions on the section name, because none
3284 of the dynobj section names depend upon the input files. */
3285 name
= bfd_get_section_name (dynobj
, s
);
3287 if (strcmp (name
, ".plt") == 0)
3289 /* Remember whether there is a PLT. */
3292 else if (CONST_STRNEQ (name
, ".rela"))
3298 /* We use the reloc_count field as a counter if we need
3299 to copy relocs into the output file. */
3303 else if (! CONST_STRNEQ (name
, ".got")
3304 && strcmp (name
, ".dynbss") != 0)
3306 /* It's not one of our sections, so don't allocate space. */
3312 /* If we don't need this section, strip it from the
3313 output file. This is mostly to handle .rela.bss and
3314 .rela.plt. We must create both sections in
3315 create_dynamic_sections, because they must be created
3316 before the linker maps input sections to output
3317 sections. The linker does that before
3318 adjust_dynamic_symbol is called, and it is that
3319 function which decides whether anything needs to go
3320 into these sections. */
3321 s
->flags
|= SEC_EXCLUDE
;
3325 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3328 /* Allocate memory for the section contents. */
3329 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3330 Unused entries should be reclaimed before the section's contents
3331 are written out, but at the moment this does not happen. Thus in
3332 order to prevent writing out garbage, we initialise the section's
3333 contents to zero. */
3334 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3335 if (s
->contents
== NULL
)
3339 if (elf_hash_table (info
)->dynamic_sections_created
)
3341 /* Add some entries to the .dynamic section. We fill in the
3342 values later, in elf_m68k_finish_dynamic_sections, but we
3343 must add the entries now so that we get the correct size for
3344 the .dynamic section. The DT_DEBUG entry is filled in by the
3345 dynamic linker and used by the debugger. */
3346 #define add_dynamic_entry(TAG, VAL) \
3347 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3349 if (bfd_link_executable (info
))
3351 if (!add_dynamic_entry (DT_DEBUG
, 0))
3357 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3358 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3359 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3360 || !add_dynamic_entry (DT_JMPREL
, 0))
3366 if (!add_dynamic_entry (DT_RELA
, 0)
3367 || !add_dynamic_entry (DT_RELASZ
, 0)
3368 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3372 if ((info
->flags
& DF_TEXTREL
) != 0)
3374 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3378 #undef add_dynamic_entry
3383 /* This function is called via elf_link_hash_traverse if we are
3384 creating a shared object. In the -Bsymbolic case it discards the
3385 space allocated to copy PC relative relocs against symbols which
3386 are defined in regular objects. For the normal shared case, it
3387 discards space for pc-relative relocs that have become local due to
3388 symbol visibility changes. We allocated space for them in the
3389 check_relocs routine, but we won't fill them in in the
3390 relocate_section routine.
3392 We also check whether any of the remaining relocations apply
3393 against a readonly section, and set the DF_TEXTREL flag in this
3397 elf_m68k_discard_copies (struct elf_link_hash_entry
*h
,
3400 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3401 struct elf_m68k_pcrel_relocs_copied
*s
;
3403 if (!SYMBOL_CALLS_LOCAL (info
, h
))
3405 if ((info
->flags
& DF_TEXTREL
) == 0)
3407 /* Look for relocations against read-only sections. */
3408 for (s
= elf_m68k_hash_entry (h
)->pcrel_relocs_copied
;
3411 if ((s
->section
->flags
& SEC_READONLY
) != 0)
3413 info
->flags
|= DF_TEXTREL
;
3418 /* Make sure undefined weak symbols are output as a dynamic symbol
3421 && h
->root
.type
== bfd_link_hash_undefweak
3422 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3424 && !h
->forced_local
)
3426 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3433 for (s
= elf_m68k_hash_entry (h
)->pcrel_relocs_copied
;
3436 s
->section
->size
-= s
->count
* sizeof (Elf32_External_Rela
);
3442 /* Install relocation RELA. */
3445 elf_m68k_install_rela (bfd
*output_bfd
,
3447 Elf_Internal_Rela
*rela
)
3451 loc
= srela
->contents
;
3452 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3453 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
3456 /* Find the base offsets for thread-local storage in this object,
3457 for GD/LD and IE/LE respectively. */
3459 #define DTP_OFFSET 0x8000
3460 #define TP_OFFSET 0x7000
3463 dtpoff_base (struct bfd_link_info
*info
)
3465 /* If tls_sec is NULL, we should have signalled an error already. */
3466 if (elf_hash_table (info
)->tls_sec
== NULL
)
3468 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
3472 tpoff_base (struct bfd_link_info
*info
)
3474 /* If tls_sec is NULL, we should have signalled an error already. */
3475 if (elf_hash_table (info
)->tls_sec
== NULL
)
3477 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
3480 /* Output necessary relocation to handle a symbol during static link.
3481 This function is called from elf_m68k_relocate_section. */
3484 elf_m68k_init_got_entry_static (struct bfd_link_info
*info
,
3486 enum elf_m68k_reloc_type r_type
,
3488 bfd_vma got_entry_offset
,
3491 switch (elf_m68k_reloc_got_type (r_type
))
3494 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ got_entry_offset
);
3497 case R_68K_TLS_GD32
:
3498 /* We know the offset within the module,
3499 put it into the second GOT slot. */
3500 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3501 sgot
->contents
+ got_entry_offset
+ 4);
3504 case R_68K_TLS_LDM32
:
3505 /* Mark it as belonging to module 1, the executable. */
3506 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ got_entry_offset
);
3509 case R_68K_TLS_IE32
:
3510 bfd_put_32 (output_bfd
, relocation
- tpoff_base (info
),
3511 sgot
->contents
+ got_entry_offset
);
3519 /* Output necessary relocation to handle a local symbol
3520 during dynamic link.
3521 This function is called either from elf_m68k_relocate_section
3522 or from elf_m68k_finish_dynamic_symbol. */
3525 elf_m68k_init_got_entry_local_shared (struct bfd_link_info
*info
,
3527 enum elf_m68k_reloc_type r_type
,
3529 bfd_vma got_entry_offset
,
3533 Elf_Internal_Rela outrel
;
3535 switch (elf_m68k_reloc_got_type (r_type
))
3538 /* Emit RELATIVE relocation to initialize GOT slot
3540 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
3541 outrel
.r_addend
= relocation
;
3544 case R_68K_TLS_GD32
:
3545 /* We know the offset within the module,
3546 put it into the second GOT slot. */
3547 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3548 sgot
->contents
+ got_entry_offset
+ 4);
3551 case R_68K_TLS_LDM32
:
3552 /* We don't know the module number,
3553 create a relocation for it. */
3554 outrel
.r_info
= ELF32_R_INFO (0, R_68K_TLS_DTPMOD32
);
3555 outrel
.r_addend
= 0;
3558 case R_68K_TLS_IE32
:
3559 /* Emit TPREL relocation to initialize GOT slot
3561 outrel
.r_info
= ELF32_R_INFO (0, R_68K_TLS_TPREL32
);
3562 outrel
.r_addend
= relocation
- elf_hash_table (info
)->tls_sec
->vma
;
3569 /* Offset of the GOT entry. */
3570 outrel
.r_offset
= (sgot
->output_section
->vma
3571 + sgot
->output_offset
3572 + got_entry_offset
);
3574 /* Install one of the above relocations. */
3575 elf_m68k_install_rela (output_bfd
, srela
, &outrel
);
3577 bfd_put_32 (output_bfd
, outrel
.r_addend
, sgot
->contents
+ got_entry_offset
);
3580 /* Relocate an M68K ELF section. */
3583 elf_m68k_relocate_section (bfd
*output_bfd
,
3584 struct bfd_link_info
*info
,
3586 asection
*input_section
,
3588 Elf_Internal_Rela
*relocs
,
3589 Elf_Internal_Sym
*local_syms
,
3590 asection
**local_sections
)
3592 Elf_Internal_Shdr
*symtab_hdr
;
3593 struct elf_link_hash_entry
**sym_hashes
;
3598 struct elf_m68k_got
*got
;
3599 Elf_Internal_Rela
*rel
;
3600 Elf_Internal_Rela
*relend
;
3602 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3603 sym_hashes
= elf_sym_hashes (input_bfd
);
3613 relend
= relocs
+ input_section
->reloc_count
;
3614 for (; rel
< relend
; rel
++)
3617 reloc_howto_type
*howto
;
3618 unsigned long r_symndx
;
3619 struct elf_link_hash_entry
*h
;
3620 Elf_Internal_Sym
*sym
;
3623 bfd_boolean unresolved_reloc
;
3624 bfd_reloc_status_type r
;
3626 r_type
= ELF32_R_TYPE (rel
->r_info
);
3627 if (r_type
< 0 || r_type
>= (int) R_68K_max
)
3629 bfd_set_error (bfd_error_bad_value
);
3632 howto
= howto_table
+ r_type
;
3634 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3639 unresolved_reloc
= FALSE
;
3641 if (r_symndx
< symtab_hdr
->sh_info
)
3643 sym
= local_syms
+ r_symndx
;
3644 sec
= local_sections
[r_symndx
];
3645 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
3649 bfd_boolean warned
, ignored
;
3651 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3652 r_symndx
, symtab_hdr
, sym_hashes
,
3654 unresolved_reloc
, warned
, ignored
);
3657 if (sec
!= NULL
&& discarded_section (sec
))
3658 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3659 rel
, 1, relend
, howto
, 0, contents
);
3661 if (bfd_link_relocatable (info
))
3669 /* Relocation is to the address of the entry for this symbol
3670 in the global offset table. */
3672 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3674 if (elf_m68k_hash_table (info
)->local_gp_p
)
3676 bfd_vma sgot_output_offset
;
3679 sgot
= elf_hash_table (info
)->sgot
;
3682 sgot_output_offset
= sgot
->output_offset
;
3684 /* In this case we have a reference to
3685 _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3687 ??? Issue a warning? */
3688 sgot_output_offset
= 0;
3692 struct elf_m68k_bfd2got_entry
*bfd2got_entry
;
3695 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
3696 input_bfd
, SEARCH
, NULL
);
3698 if (bfd2got_entry
!= NULL
)
3700 got
= bfd2got_entry
->got
;
3701 BFD_ASSERT (got
!= NULL
);
3703 got_offset
= got
->offset
;
3706 /* In this case we have a reference to
3707 _GLOBAL_OFFSET_TABLE_, but no other references
3708 accessing any GOT entries.
3709 ??? Issue a warning? */
3713 got_offset
= got
->offset
;
3715 /* Adjust GOT pointer to point to the GOT
3716 assigned to input_bfd. */
3717 rel
->r_addend
+= sgot_output_offset
+ got_offset
;
3720 BFD_ASSERT (got
== NULL
|| got
->offset
== 0);
3729 case R_68K_TLS_LDM32
:
3730 case R_68K_TLS_LDM16
:
3731 case R_68K_TLS_LDM8
:
3734 case R_68K_TLS_GD16
:
3735 case R_68K_TLS_GD32
:
3738 case R_68K_TLS_IE16
:
3739 case R_68K_TLS_IE32
:
3741 /* Relocation is the offset of the entry for this symbol in
3742 the global offset table. */
3745 struct elf_m68k_got_entry_key key_
;
3749 sgot
= elf_hash_table (info
)->sgot
;
3750 BFD_ASSERT (sgot
!= NULL
);
3754 got
= elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
3755 input_bfd
, MUST_FIND
,
3757 BFD_ASSERT (got
!= NULL
);
3760 /* Get GOT offset for this symbol. */
3761 elf_m68k_init_got_entry_key (&key_
, h
, input_bfd
, r_symndx
,
3763 off_ptr
= &elf_m68k_get_got_entry (got
, &key_
, MUST_FIND
,
3767 /* The offset must always be a multiple of 4. We use
3768 the least significant bit to record whether we have
3769 already generated the necessary reloc. */
3775 /* @TLSLDM relocations are bounded to the module, in
3776 which the symbol is defined -- not to the symbol
3778 && elf_m68k_reloc_got_type (r_type
) != R_68K_TLS_LDM32
)
3782 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3783 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
3784 bfd_link_pic (info
),
3786 || (bfd_link_pic (info
)
3787 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3788 || (ELF_ST_VISIBILITY (h
->other
)
3789 && h
->root
.type
== bfd_link_hash_undefweak
))
3791 /* This is actually a static link, or it is a
3792 -Bsymbolic link and the symbol is defined
3793 locally, or the symbol was forced to be local
3794 because of a version file. We must initialize
3795 this entry in the global offset table. Since
3796 the offset must always be a multiple of 4, we
3797 use the least significant bit to record whether
3798 we have initialized it already.
3800 When doing a dynamic link, we create a .rela.got
3801 relocation entry to initialize the value. This
3802 is done in the finish_dynamic_symbol routine. */
3804 elf_m68k_init_got_entry_static (info
,
3814 unresolved_reloc
= FALSE
;
3816 else if (bfd_link_pic (info
)) /* && h == NULL */
3817 /* Process local symbol during dynamic link. */
3819 srela
= elf_hash_table (info
)->srelgot
;
3820 BFD_ASSERT (srela
!= NULL
);
3822 elf_m68k_init_got_entry_local_shared (info
,
3832 else /* h == NULL && !bfd_link_pic (info) */
3834 elf_m68k_init_got_entry_static (info
,
3845 /* We don't use elf_m68k_reloc_got_type in the condition below
3846 because this is the only place where difference between
3847 R_68K_GOTx and R_68K_GOTxO relocations matters. */
3848 if (r_type
== R_68K_GOT32O
3849 || r_type
== R_68K_GOT16O
3850 || r_type
== R_68K_GOT8O
3851 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_GD32
3852 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_LDM32
3853 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_IE32
)
3855 /* GOT pointer is adjusted to point to the start/middle
3856 of local GOT. Adjust the offset accordingly. */
3857 BFD_ASSERT (elf_m68k_hash_table (info
)->use_neg_got_offsets_p
3858 || off
>= got
->offset
);
3860 if (elf_m68k_hash_table (info
)->local_gp_p
)
3861 relocation
= off
- got
->offset
;
3864 BFD_ASSERT (got
->offset
== 0);
3865 relocation
= sgot
->output_offset
+ off
;
3868 /* This relocation does not use the addend. */
3872 relocation
= (sgot
->output_section
->vma
+ sgot
->output_offset
3877 case R_68K_TLS_LDO32
:
3878 case R_68K_TLS_LDO16
:
3879 case R_68K_TLS_LDO8
:
3880 relocation
-= dtpoff_base (info
);
3883 case R_68K_TLS_LE32
:
3884 case R_68K_TLS_LE16
:
3886 if (bfd_link_dll (info
))
3889 /* xgettext:c-format */
3890 (_("%B(%A+0x%lx): R_68K_TLS_LE32 relocation not permitted "
3891 "in shared object"),
3892 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
);
3897 relocation
-= tpoff_base (info
);
3904 /* Relocation is to the entry for this symbol in the
3905 procedure linkage table. */
3907 /* Resolve a PLTxx reloc against a local symbol directly,
3908 without using the procedure linkage table. */
3912 if (h
->plt
.offset
== (bfd_vma
) -1
3913 || !elf_hash_table (info
)->dynamic_sections_created
)
3915 /* We didn't make a PLT entry for this symbol. This
3916 happens when statically linking PIC code, or when
3917 using -Bsymbolic. */
3921 splt
= elf_hash_table (info
)->splt
;
3922 BFD_ASSERT (splt
!= NULL
);
3924 relocation
= (splt
->output_section
->vma
3925 + splt
->output_offset
3927 unresolved_reloc
= FALSE
;
3933 /* Relocation is the offset of the entry for this symbol in
3934 the procedure linkage table. */
3935 BFD_ASSERT (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1);
3937 splt
= elf_hash_table (info
)->splt
;
3938 BFD_ASSERT (splt
!= NULL
);
3940 relocation
= h
->plt
.offset
;
3941 unresolved_reloc
= FALSE
;
3943 /* This relocation does not use the addend. */
3954 if (bfd_link_pic (info
)
3955 && r_symndx
!= STN_UNDEF
3956 && (input_section
->flags
& SEC_ALLOC
) != 0
3958 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3959 || h
->root
.type
!= bfd_link_hash_undefweak
)
3960 && ((r_type
!= R_68K_PC8
3961 && r_type
!= R_68K_PC16
3962 && r_type
!= R_68K_PC32
)
3963 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3965 Elf_Internal_Rela outrel
;
3967 bfd_boolean skip
, relocate
;
3969 /* When generating a shared object, these relocations
3970 are copied into the output file to be resolved at run
3977 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3979 if (outrel
.r_offset
== (bfd_vma
) -1)
3981 else if (outrel
.r_offset
== (bfd_vma
) -2)
3982 skip
= TRUE
, relocate
= TRUE
;
3983 outrel
.r_offset
+= (input_section
->output_section
->vma
3984 + input_section
->output_offset
);
3987 memset (&outrel
, 0, sizeof outrel
);
3990 && (r_type
== R_68K_PC8
3991 || r_type
== R_68K_PC16
3992 || r_type
== R_68K_PC32
3993 || !bfd_link_pic (info
)
3994 || !SYMBOLIC_BIND (info
, h
)
3995 || !h
->def_regular
))
3997 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3998 outrel
.r_addend
= rel
->r_addend
;
4002 /* This symbol is local, or marked to become local. */
4003 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4005 if (r_type
== R_68K_32
)
4008 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
4014 if (bfd_is_abs_section (sec
))
4016 else if (sec
== NULL
|| sec
->owner
== NULL
)
4018 bfd_set_error (bfd_error_bad_value
);
4025 /* We are turning this relocation into one
4026 against a section symbol. It would be
4027 proper to subtract the symbol's value,
4028 osec->vma, from the emitted reloc addend,
4029 but ld.so expects buggy relocs. */
4030 osec
= sec
->output_section
;
4031 indx
= elf_section_data (osec
)->dynindx
;
4034 struct elf_link_hash_table
*htab
;
4035 htab
= elf_hash_table (info
);
4036 osec
= htab
->text_index_section
;
4037 indx
= elf_section_data (osec
)->dynindx
;
4039 BFD_ASSERT (indx
!= 0);
4042 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
4046 sreloc
= elf_section_data (input_section
)->sreloc
;
4050 loc
= sreloc
->contents
;
4051 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4052 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4054 /* This reloc will be computed at runtime, so there's no
4055 need to do anything now, except for R_68K_32
4056 relocations that have been turned into
4064 case R_68K_GNU_VTINHERIT
:
4065 case R_68K_GNU_VTENTRY
:
4066 /* These are no-ops in the end. */
4073 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4074 because such sections are not SEC_ALLOC and thus ld.so will
4075 not process them. */
4076 if (unresolved_reloc
4077 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4079 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4080 rel
->r_offset
) != (bfd_vma
) -1)
4083 /* xgettext:c-format */
4084 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4087 (long) rel
->r_offset
,
4089 h
->root
.root
.string
);
4093 if (r_symndx
!= STN_UNDEF
4094 && r_type
!= R_68K_NONE
4096 || h
->root
.type
== bfd_link_hash_defined
4097 || h
->root
.type
== bfd_link_hash_defweak
))
4101 sym_type
= (sym
!= NULL
) ? ELF32_ST_TYPE (sym
->st_info
) : h
->type
;
4103 if (elf_m68k_reloc_tls_p (r_type
) != (sym_type
== STT_TLS
))
4108 name
= h
->root
.root
.string
;
4111 name
= (bfd_elf_string_from_elf_section
4112 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4113 if (name
== NULL
|| *name
== '\0')
4114 name
= bfd_section_name (input_bfd
, sec
);
4118 ((sym_type
== STT_TLS
4119 /* xgettext:c-format */
4120 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4121 /* xgettext:c-format */
4122 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4125 (long) rel
->r_offset
,
4131 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4132 contents
, rel
->r_offset
,
4133 relocation
, rel
->r_addend
);
4135 if (r
!= bfd_reloc_ok
)
4140 name
= h
->root
.root
.string
;
4143 name
= bfd_elf_string_from_elf_section (input_bfd
,
4144 symtab_hdr
->sh_link
,
4149 name
= bfd_section_name (input_bfd
, sec
);
4152 if (r
== bfd_reloc_overflow
)
4153 (*info
->callbacks
->reloc_overflow
)
4154 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4155 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4159 /* xgettext:c-format */
4160 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4161 input_bfd
, input_section
,
4162 (long) rel
->r_offset
, name
, (int) r
);
4171 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4172 into section SEC. */
4175 elf_m68k_install_pc32 (asection
*sec
, bfd_vma offset
, bfd_vma value
)
4177 /* Make VALUE PC-relative. */
4178 value
-= sec
->output_section
->vma
+ offset
;
4180 /* Apply any in-place addend. */
4181 value
+= bfd_get_32 (sec
->owner
, sec
->contents
+ offset
);
4183 bfd_put_32 (sec
->owner
, value
, sec
->contents
+ offset
);
4186 /* Finish up dynamic symbol handling. We set the contents of various
4187 dynamic sections here. */
4190 elf_m68k_finish_dynamic_symbol (bfd
*output_bfd
,
4191 struct bfd_link_info
*info
,
4192 struct elf_link_hash_entry
*h
,
4193 Elf_Internal_Sym
*sym
)
4197 dynobj
= elf_hash_table (info
)->dynobj
;
4199 if (h
->plt
.offset
!= (bfd_vma
) -1)
4201 const struct elf_m68k_plt_info
*plt_info
;
4207 Elf_Internal_Rela rela
;
4210 /* This symbol has an entry in the procedure linkage table. Set
4213 BFD_ASSERT (h
->dynindx
!= -1);
4215 plt_info
= elf_m68k_hash_table (info
)->plt_info
;
4216 splt
= elf_hash_table (info
)->splt
;
4217 sgot
= elf_hash_table (info
)->sgotplt
;
4218 srela
= elf_hash_table (info
)->srelplt
;
4219 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
4221 /* Get the index in the procedure linkage table which
4222 corresponds to this symbol. This is the index of this symbol
4223 in all the symbols for which we are making plt entries. The
4224 first entry in the procedure linkage table is reserved. */
4225 plt_index
= (h
->plt
.offset
/ plt_info
->size
) - 1;
4227 /* Get the offset into the .got table of the entry that
4228 corresponds to this function. Each .got entry is 4 bytes.
4229 The first three are reserved. */
4230 got_offset
= (plt_index
+ 3) * 4;
4232 memcpy (splt
->contents
+ h
->plt
.offset
,
4233 plt_info
->symbol_entry
,
4236 elf_m68k_install_pc32 (splt
, h
->plt
.offset
+ plt_info
->symbol_relocs
.got
,
4237 (sgot
->output_section
->vma
4238 + sgot
->output_offset
4241 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
4244 + plt_info
->symbol_resolve_entry
+ 2);
4246 elf_m68k_install_pc32 (splt
, h
->plt
.offset
+ plt_info
->symbol_relocs
.plt
,
4247 splt
->output_section
->vma
);
4249 /* Fill in the entry in the global offset table. */
4250 bfd_put_32 (output_bfd
,
4251 (splt
->output_section
->vma
4252 + splt
->output_offset
4254 + plt_info
->symbol_resolve_entry
),
4255 sgot
->contents
+ got_offset
);
4257 /* Fill in the entry in the .rela.plt section. */
4258 rela
.r_offset
= (sgot
->output_section
->vma
4259 + sgot
->output_offset
4261 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_JMP_SLOT
);
4263 loc
= srela
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
4264 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4266 if (!h
->def_regular
)
4268 /* Mark the symbol as undefined, rather than as defined in
4269 the .plt section. Leave the value alone. */
4270 sym
->st_shndx
= SHN_UNDEF
;
4274 if (elf_m68k_hash_entry (h
)->glist
!= NULL
)
4278 struct elf_m68k_got_entry
*got_entry
;
4280 /* This symbol has an entry in the global offset table. Set it
4283 sgot
= elf_hash_table (info
)->sgot
;
4284 srela
= elf_hash_table (info
)->srelgot
;
4285 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
4287 got_entry
= elf_m68k_hash_entry (h
)->glist
;
4289 while (got_entry
!= NULL
)
4291 enum elf_m68k_reloc_type r_type
;
4292 bfd_vma got_entry_offset
;
4294 r_type
= got_entry
->key_
.type
;
4295 got_entry_offset
= got_entry
->u
.s2
.offset
&~ (bfd_vma
) 1;
4297 /* If this is a -Bsymbolic link, and the symbol is defined
4298 locally, we just want to emit a RELATIVE reloc. Likewise if
4299 the symbol was forced to be local because of a version file.
4300 The entry in the global offset table already have been
4301 initialized in the relocate_section function. */
4302 if (bfd_link_pic (info
)
4303 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4307 relocation
= bfd_get_signed_32 (output_bfd
,
4309 + got_entry_offset
));
4312 switch (elf_m68k_reloc_got_type (r_type
))
4315 case R_68K_TLS_LDM32
:
4318 case R_68K_TLS_GD32
:
4319 /* The value for this relocation is actually put in
4320 the second GOT slot. */
4321 relocation
= bfd_get_signed_32 (output_bfd
,
4323 + got_entry_offset
+ 4));
4324 relocation
+= dtpoff_base (info
);
4327 case R_68K_TLS_IE32
:
4328 relocation
+= tpoff_base (info
);
4335 elf_m68k_init_got_entry_local_shared (info
,
4345 Elf_Internal_Rela rela
;
4347 /* Put zeros to GOT slots that will be initialized
4352 n_slots
= elf_m68k_reloc_got_n_slots (got_entry
->key_
.type
);
4354 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4355 (sgot
->contents
+ got_entry_offset
4360 rela
.r_offset
= (sgot
->output_section
->vma
4361 + sgot
->output_offset
4362 + got_entry_offset
);
4364 switch (elf_m68k_reloc_got_type (r_type
))
4367 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_GLOB_DAT
);
4368 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4371 case R_68K_TLS_GD32
:
4372 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_DTPMOD32
);
4373 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4376 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_DTPREL32
);
4377 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4380 case R_68K_TLS_IE32
:
4381 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_TPREL32
);
4382 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4391 got_entry
= got_entry
->u
.s2
.next
;
4398 Elf_Internal_Rela rela
;
4401 /* This symbol needs a copy reloc. Set it up. */
4403 BFD_ASSERT (h
->dynindx
!= -1
4404 && (h
->root
.type
== bfd_link_hash_defined
4405 || h
->root
.type
== bfd_link_hash_defweak
));
4407 s
= bfd_get_linker_section (dynobj
, ".rela.bss");
4408 BFD_ASSERT (s
!= NULL
);
4410 rela
.r_offset
= (h
->root
.u
.def
.value
4411 + h
->root
.u
.def
.section
->output_section
->vma
4412 + h
->root
.u
.def
.section
->output_offset
);
4413 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_COPY
);
4415 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4416 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4422 /* Finish up the dynamic sections. */
4425 elf_m68k_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
4431 dynobj
= elf_hash_table (info
)->dynobj
;
4433 sgot
= elf_hash_table (info
)->sgotplt
;
4434 BFD_ASSERT (sgot
!= NULL
);
4435 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4437 if (elf_hash_table (info
)->dynamic_sections_created
)
4440 Elf32_External_Dyn
*dyncon
, *dynconend
;
4442 splt
= elf_hash_table (info
)->splt
;
4443 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
4445 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4446 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4447 for (; dyncon
< dynconend
; dyncon
++)
4449 Elf_Internal_Dyn dyn
;
4452 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4460 s
= elf_hash_table (info
)->sgotplt
;
4463 s
= elf_hash_table (info
)->srelplt
;
4465 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4466 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4470 s
= elf_hash_table (info
)->srelplt
;
4471 dyn
.d_un
.d_val
= s
->size
;
4472 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4477 /* Fill in the first entry in the procedure linkage table. */
4480 const struct elf_m68k_plt_info
*plt_info
;
4482 plt_info
= elf_m68k_hash_table (info
)->plt_info
;
4483 memcpy (splt
->contents
, plt_info
->plt0_entry
, plt_info
->size
);
4485 elf_m68k_install_pc32 (splt
, plt_info
->plt0_relocs
.got4
,
4486 (sgot
->output_section
->vma
4487 + sgot
->output_offset
4490 elf_m68k_install_pc32 (splt
, plt_info
->plt0_relocs
.got8
,
4491 (sgot
->output_section
->vma
4492 + sgot
->output_offset
4495 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
4500 /* Fill in the first three entries in the global offset table. */
4504 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4506 bfd_put_32 (output_bfd
,
4507 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4509 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4510 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4513 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4518 /* Given a .data section and a .emreloc in-memory section, store
4519 relocation information into the .emreloc section which can be
4520 used at runtime to relocate the section. This is called by the
4521 linker when the --embedded-relocs switch is used. This is called
4522 after the add_symbols entry point has been called for all the
4523 objects, and before the final_link entry point is called. */
4526 bfd_m68k_elf32_create_embedded_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4527 asection
*datasec
, asection
*relsec
,
4530 Elf_Internal_Shdr
*symtab_hdr
;
4531 Elf_Internal_Sym
*isymbuf
= NULL
;
4532 Elf_Internal_Rela
*internal_relocs
= NULL
;
4533 Elf_Internal_Rela
*irel
, *irelend
;
4537 BFD_ASSERT (! bfd_link_relocatable (info
));
4541 if (datasec
->reloc_count
== 0)
4544 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4546 /* Get a copy of the native relocations. */
4547 internal_relocs
= (_bfd_elf_link_read_relocs
4548 (abfd
, datasec
, NULL
, (Elf_Internal_Rela
*) NULL
,
4549 info
->keep_memory
));
4550 if (internal_relocs
== NULL
)
4553 amt
= (bfd_size_type
) datasec
->reloc_count
* 12;
4554 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, amt
);
4555 if (relsec
->contents
== NULL
)
4558 p
= relsec
->contents
;
4560 irelend
= internal_relocs
+ datasec
->reloc_count
;
4561 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
4563 asection
*targetsec
;
4565 /* We are going to write a four byte longword into the runtime
4566 reloc section. The longword will be the address in the data
4567 section which must be relocated. It is followed by the name
4568 of the target section NUL-padded or truncated to 8
4571 /* We can only relocate absolute longword relocs at run time. */
4572 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_68K_32
)
4574 *errmsg
= _("unsupported reloc type");
4575 bfd_set_error (bfd_error_bad_value
);
4579 /* Get the target section referred to by the reloc. */
4580 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
4582 /* A local symbol. */
4583 Elf_Internal_Sym
*isym
;
4585 /* Read this BFD's local symbols if we haven't done so already. */
4586 if (isymbuf
== NULL
)
4588 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4589 if (isymbuf
== NULL
)
4590 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
4591 symtab_hdr
->sh_info
, 0,
4593 if (isymbuf
== NULL
)
4597 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
4598 targetsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4603 struct elf_link_hash_entry
*h
;
4605 /* An external symbol. */
4606 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
4607 h
= elf_sym_hashes (abfd
)[indx
];
4608 BFD_ASSERT (h
!= NULL
);
4609 if (h
->root
.type
== bfd_link_hash_defined
4610 || h
->root
.type
== bfd_link_hash_defweak
)
4611 targetsec
= h
->root
.u
.def
.section
;
4616 bfd_put_32 (abfd
, irel
->r_offset
+ datasec
->output_offset
, p
);
4617 memset (p
+ 4, 0, 8);
4618 if (targetsec
!= NULL
)
4619 strncpy ((char *) p
+ 4, targetsec
->output_section
->name
, 8);
4622 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
4624 if (internal_relocs
!= NULL
4625 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
4626 free (internal_relocs
);
4630 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
4632 if (internal_relocs
!= NULL
4633 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
4634 free (internal_relocs
);
4638 /* Set target options. */
4641 bfd_elf_m68k_set_target_options (struct bfd_link_info
*info
, int got_handling
)
4643 struct elf_m68k_link_hash_table
*htab
;
4644 bfd_boolean use_neg_got_offsets_p
;
4645 bfd_boolean allow_multigot_p
;
4646 bfd_boolean local_gp_p
;
4648 switch (got_handling
)
4653 use_neg_got_offsets_p
= FALSE
;
4654 allow_multigot_p
= FALSE
;
4658 /* --got=negative. */
4660 use_neg_got_offsets_p
= TRUE
;
4661 allow_multigot_p
= FALSE
;
4665 /* --got=multigot. */
4667 use_neg_got_offsets_p
= TRUE
;
4668 allow_multigot_p
= TRUE
;
4676 htab
= elf_m68k_hash_table (info
);
4679 htab
->local_gp_p
= local_gp_p
;
4680 htab
->use_neg_got_offsets_p
= use_neg_got_offsets_p
;
4681 htab
->allow_multigot_p
= allow_multigot_p
;
4685 static enum elf_reloc_type_class
4686 elf32_m68k_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4687 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4688 const Elf_Internal_Rela
*rela
)
4690 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4692 case R_68K_RELATIVE
:
4693 return reloc_class_relative
;
4694 case R_68K_JMP_SLOT
:
4695 return reloc_class_plt
;
4697 return reloc_class_copy
;
4699 return reloc_class_normal
;
4703 /* Return address for Ith PLT stub in section PLT, for relocation REL
4704 or (bfd_vma) -1 if it should not be included. */
4707 elf_m68k_plt_sym_val (bfd_vma i
, const asection
*plt
,
4708 const arelent
*rel ATTRIBUTE_UNUSED
)
4710 return plt
->vma
+ (i
+ 1) * elf_m68k_get_plt_info (plt
->owner
)->size
;
4713 /* Support for core dump NOTE sections. */
4716 elf_m68k_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
4721 switch (note
->descsz
)
4726 case 154: /* Linux/m68k */
4728 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
4731 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 22);
4740 /* Make a ".reg/999" section. */
4741 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
4742 size
, note
->descpos
+ offset
);
4746 elf_m68k_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
4748 switch (note
->descsz
)
4753 case 124: /* Linux/m68k elf_prpsinfo. */
4754 elf_tdata (abfd
)->core
->pid
4755 = bfd_get_32 (abfd
, note
->descdata
+ 12);
4756 elf_tdata (abfd
)->core
->program
4757 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
4758 elf_tdata (abfd
)->core
->command
4759 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
4762 /* Note that for some reason, a spurious space is tacked
4763 onto the end of the args in some (at least one anyway)
4764 implementations, so strip it off if it exists. */
4766 char *command
= elf_tdata (abfd
)->core
->command
;
4767 int n
= strlen (command
);
4769 if (n
> 0 && command
[n
- 1] == ' ')
4770 command
[n
- 1] = '\0';
4776 /* Hook called by the linker routine which adds symbols from an object
4780 elf_m68k_add_symbol_hook (bfd
*abfd
,
4781 struct bfd_link_info
*info
,
4782 Elf_Internal_Sym
*sym
,
4783 const char **namep ATTRIBUTE_UNUSED
,
4784 flagword
*flagsp ATTRIBUTE_UNUSED
,
4785 asection
**secp ATTRIBUTE_UNUSED
,
4786 bfd_vma
*valp ATTRIBUTE_UNUSED
)
4788 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4789 && (abfd
->flags
& DYNAMIC
) == 0
4790 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
4791 elf_tdata (info
->output_bfd
)->has_gnu_symbols
|= elf_gnu_symbol_ifunc
;
4796 #define TARGET_BIG_SYM m68k_elf32_vec
4797 #define TARGET_BIG_NAME "elf32-m68k"
4798 #define ELF_MACHINE_CODE EM_68K
4799 #define ELF_MAXPAGESIZE 0x2000
4800 #define elf_backend_create_dynamic_sections \
4801 _bfd_elf_create_dynamic_sections
4802 #define bfd_elf32_bfd_link_hash_table_create \
4803 elf_m68k_link_hash_table_create
4804 #define bfd_elf32_bfd_final_link bfd_elf_final_link
4806 #define elf_backend_check_relocs elf_m68k_check_relocs
4807 #define elf_backend_always_size_sections \
4808 elf_m68k_always_size_sections
4809 #define elf_backend_adjust_dynamic_symbol \
4810 elf_m68k_adjust_dynamic_symbol
4811 #define elf_backend_size_dynamic_sections \
4812 elf_m68k_size_dynamic_sections
4813 #define elf_backend_final_write_processing elf_m68k_final_write_processing
4814 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4815 #define elf_backend_relocate_section elf_m68k_relocate_section
4816 #define elf_backend_finish_dynamic_symbol \
4817 elf_m68k_finish_dynamic_symbol
4818 #define elf_backend_finish_dynamic_sections \
4819 elf_m68k_finish_dynamic_sections
4820 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4821 #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook
4822 #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4823 #define bfd_elf32_bfd_merge_private_bfd_data \
4824 elf32_m68k_merge_private_bfd_data
4825 #define bfd_elf32_bfd_set_private_flags \
4826 elf32_m68k_set_private_flags
4827 #define bfd_elf32_bfd_print_private_bfd_data \
4828 elf32_m68k_print_private_bfd_data
4829 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4830 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4831 #define elf_backend_object_p elf32_m68k_object_p
4832 #define elf_backend_grok_prstatus elf_m68k_grok_prstatus
4833 #define elf_backend_grok_psinfo elf_m68k_grok_psinfo
4834 #define elf_backend_add_symbol_hook elf_m68k_add_symbol_hook
4836 #define elf_backend_can_gc_sections 1
4837 #define elf_backend_can_refcount 1
4838 #define elf_backend_want_got_plt 1
4839 #define elf_backend_plt_readonly 1
4840 #define elf_backend_want_plt_sym 0
4841 #define elf_backend_got_header_size 12
4842 #define elf_backend_rela_normal 1
4843 #define elf_backend_dtrel_excludes_plt 1
4845 #include "elf32-target.h"