1 /* Motorola 68k series support for 32-bit ELF
2 Copyright (C) 1993-2020 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"
29 #include "elf32-m68k.h"
32 elf_m68k_discard_copies (struct elf_link_hash_entry
*, void *);
34 static reloc_howto_type howto_table
[] =
36 HOWTO(R_68K_NONE
, 0, 3, 0, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_NONE", FALSE
, 0, 0x00000000,FALSE
),
37 HOWTO(R_68K_32
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_32", FALSE
, 0, 0xffffffff,FALSE
),
38 HOWTO(R_68K_16
, 0, 1,16, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_16", FALSE
, 0, 0x0000ffff,FALSE
),
39 HOWTO(R_68K_8
, 0, 0, 8, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_8", FALSE
, 0, 0x000000ff,FALSE
),
40 HOWTO(R_68K_PC32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PC32", FALSE
, 0, 0xffffffff,TRUE
),
41 HOWTO(R_68K_PC16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC16", FALSE
, 0, 0x0000ffff,TRUE
),
42 HOWTO(R_68K_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC8", FALSE
, 0, 0x000000ff,TRUE
),
43 HOWTO(R_68K_GOT32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32", FALSE
, 0, 0xffffffff,TRUE
),
44 HOWTO(R_68K_GOT16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16", FALSE
, 0, 0x0000ffff,TRUE
),
45 HOWTO(R_68K_GOT8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8", FALSE
, 0, 0x000000ff,TRUE
),
46 HOWTO(R_68K_GOT32O
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32O", FALSE
, 0, 0xffffffff,FALSE
),
47 HOWTO(R_68K_GOT16O
, 0, 1,16, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16O", FALSE
, 0, 0x0000ffff,FALSE
),
48 HOWTO(R_68K_GOT8O
, 0, 0, 8, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8O", FALSE
, 0, 0x000000ff,FALSE
),
49 HOWTO(R_68K_PLT32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32", FALSE
, 0, 0xffffffff,TRUE
),
50 HOWTO(R_68K_PLT16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16", FALSE
, 0, 0x0000ffff,TRUE
),
51 HOWTO(R_68K_PLT8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8", FALSE
, 0, 0x000000ff,TRUE
),
52 HOWTO(R_68K_PLT32O
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32O", FALSE
, 0, 0xffffffff,FALSE
),
53 HOWTO(R_68K_PLT16O
, 0, 1,16, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16O", FALSE
, 0, 0x0000ffff,FALSE
),
54 HOWTO(R_68K_PLT8O
, 0, 0, 8, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8O", FALSE
, 0, 0x000000ff,FALSE
),
55 HOWTO(R_68K_COPY
, 0, 0, 0, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_COPY", FALSE
, 0, 0xffffffff,FALSE
),
56 HOWTO(R_68K_GLOB_DAT
, 0, 2,32, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_GLOB_DAT", FALSE
, 0, 0xffffffff,FALSE
),
57 HOWTO(R_68K_JMP_SLOT
, 0, 2,32, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_JMP_SLOT", FALSE
, 0, 0xffffffff,FALSE
),
58 HOWTO(R_68K_RELATIVE
, 0, 2,32, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_RELATIVE", FALSE
, 0, 0xffffffff,FALSE
),
59 /* GNU extension to record C++ vtable hierarchy. */
60 HOWTO (R_68K_GNU_VTINHERIT
, /* type */
62 2, /* size (0 = byte, 1 = short, 2 = long) */
64 FALSE
, /* pc_relative */
66 complain_overflow_dont
, /* complain_on_overflow */
67 NULL
, /* special_function */
68 "R_68K_GNU_VTINHERIT", /* name */
69 FALSE
, /* partial_inplace */
73 /* GNU extension to record C++ vtable member usage. */
74 HOWTO (R_68K_GNU_VTENTRY
, /* type */
76 2, /* size (0 = byte, 1 = short, 2 = long) */
78 FALSE
, /* pc_relative */
80 complain_overflow_dont
, /* complain_on_overflow */
81 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
82 "R_68K_GNU_VTENTRY", /* name */
83 FALSE
, /* partial_inplace */
88 /* TLS general dynamic variable reference. */
89 HOWTO (R_68K_TLS_GD32
, /* type */
91 2, /* size (0 = byte, 1 = short, 2 = long) */
93 FALSE
, /* pc_relative */
95 complain_overflow_bitfield
, /* complain_on_overflow */
96 bfd_elf_generic_reloc
, /* special_function */
97 "R_68K_TLS_GD32", /* name */
98 FALSE
, /* partial_inplace */
100 0xffffffff, /* dst_mask */
101 FALSE
), /* pcrel_offset */
103 HOWTO (R_68K_TLS_GD16
, /* type */
105 1, /* size (0 = byte, 1 = short, 2 = long) */
107 FALSE
, /* pc_relative */
109 complain_overflow_signed
, /* complain_on_overflow */
110 bfd_elf_generic_reloc
, /* special_function */
111 "R_68K_TLS_GD16", /* name */
112 FALSE
, /* partial_inplace */
114 0x0000ffff, /* dst_mask */
115 FALSE
), /* pcrel_offset */
117 HOWTO (R_68K_TLS_GD8
, /* type */
119 0, /* size (0 = byte, 1 = short, 2 = long) */
121 FALSE
, /* pc_relative */
123 complain_overflow_signed
, /* complain_on_overflow */
124 bfd_elf_generic_reloc
, /* special_function */
125 "R_68K_TLS_GD8", /* name */
126 FALSE
, /* partial_inplace */
128 0x000000ff, /* dst_mask */
129 FALSE
), /* pcrel_offset */
131 /* TLS local dynamic variable reference. */
132 HOWTO (R_68K_TLS_LDM32
, /* type */
134 2, /* size (0 = byte, 1 = short, 2 = long) */
136 FALSE
, /* pc_relative */
138 complain_overflow_bitfield
, /* complain_on_overflow */
139 bfd_elf_generic_reloc
, /* special_function */
140 "R_68K_TLS_LDM32", /* name */
141 FALSE
, /* partial_inplace */
143 0xffffffff, /* dst_mask */
144 FALSE
), /* pcrel_offset */
146 HOWTO (R_68K_TLS_LDM16
, /* type */
148 1, /* size (0 = byte, 1 = short, 2 = long) */
150 FALSE
, /* pc_relative */
152 complain_overflow_signed
, /* complain_on_overflow */
153 bfd_elf_generic_reloc
, /* special_function */
154 "R_68K_TLS_LDM16", /* name */
155 FALSE
, /* partial_inplace */
157 0x0000ffff, /* dst_mask */
158 FALSE
), /* pcrel_offset */
160 HOWTO (R_68K_TLS_LDM8
, /* type */
162 0, /* size (0 = byte, 1 = short, 2 = long) */
164 FALSE
, /* pc_relative */
166 complain_overflow_signed
, /* complain_on_overflow */
167 bfd_elf_generic_reloc
, /* special_function */
168 "R_68K_TLS_LDM8", /* name */
169 FALSE
, /* partial_inplace */
171 0x000000ff, /* dst_mask */
172 FALSE
), /* pcrel_offset */
174 HOWTO (R_68K_TLS_LDO32
, /* type */
176 2, /* size (0 = byte, 1 = short, 2 = long) */
178 FALSE
, /* pc_relative */
180 complain_overflow_bitfield
, /* complain_on_overflow */
181 bfd_elf_generic_reloc
, /* special_function */
182 "R_68K_TLS_LDO32", /* name */
183 FALSE
, /* partial_inplace */
185 0xffffffff, /* dst_mask */
186 FALSE
), /* pcrel_offset */
188 HOWTO (R_68K_TLS_LDO16
, /* type */
190 1, /* size (0 = byte, 1 = short, 2 = long) */
192 FALSE
, /* pc_relative */
194 complain_overflow_signed
, /* complain_on_overflow */
195 bfd_elf_generic_reloc
, /* special_function */
196 "R_68K_TLS_LDO16", /* name */
197 FALSE
, /* partial_inplace */
199 0x0000ffff, /* dst_mask */
200 FALSE
), /* pcrel_offset */
202 HOWTO (R_68K_TLS_LDO8
, /* type */
204 0, /* size (0 = byte, 1 = short, 2 = long) */
206 FALSE
, /* pc_relative */
208 complain_overflow_signed
, /* complain_on_overflow */
209 bfd_elf_generic_reloc
, /* special_function */
210 "R_68K_TLS_LDO8", /* name */
211 FALSE
, /* partial_inplace */
213 0x000000ff, /* dst_mask */
214 FALSE
), /* pcrel_offset */
216 /* TLS initial execution variable reference. */
217 HOWTO (R_68K_TLS_IE32
, /* type */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
221 FALSE
, /* pc_relative */
223 complain_overflow_bitfield
, /* complain_on_overflow */
224 bfd_elf_generic_reloc
, /* special_function */
225 "R_68K_TLS_IE32", /* name */
226 FALSE
, /* partial_inplace */
228 0xffffffff, /* dst_mask */
229 FALSE
), /* pcrel_offset */
231 HOWTO (R_68K_TLS_IE16
, /* type */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
235 FALSE
, /* pc_relative */
237 complain_overflow_signed
, /* complain_on_overflow */
238 bfd_elf_generic_reloc
, /* special_function */
239 "R_68K_TLS_IE16", /* name */
240 FALSE
, /* partial_inplace */
242 0x0000ffff, /* dst_mask */
243 FALSE
), /* pcrel_offset */
245 HOWTO (R_68K_TLS_IE8
, /* type */
247 0, /* size (0 = byte, 1 = short, 2 = long) */
249 FALSE
, /* pc_relative */
251 complain_overflow_signed
, /* complain_on_overflow */
252 bfd_elf_generic_reloc
, /* special_function */
253 "R_68K_TLS_IE8", /* name */
254 FALSE
, /* partial_inplace */
256 0x000000ff, /* dst_mask */
257 FALSE
), /* pcrel_offset */
259 /* TLS local execution variable reference. */
260 HOWTO (R_68K_TLS_LE32
, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE
, /* pc_relative */
266 complain_overflow_bitfield
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_68K_TLS_LE32", /* name */
269 FALSE
, /* partial_inplace */
271 0xffffffff, /* dst_mask */
272 FALSE
), /* pcrel_offset */
274 HOWTO (R_68K_TLS_LE16
, /* type */
276 1, /* size (0 = byte, 1 = short, 2 = long) */
278 FALSE
, /* pc_relative */
280 complain_overflow_signed
, /* complain_on_overflow */
281 bfd_elf_generic_reloc
, /* special_function */
282 "R_68K_TLS_LE16", /* name */
283 FALSE
, /* partial_inplace */
285 0x0000ffff, /* dst_mask */
286 FALSE
), /* pcrel_offset */
288 HOWTO (R_68K_TLS_LE8
, /* type */
290 0, /* size (0 = byte, 1 = short, 2 = long) */
292 FALSE
, /* pc_relative */
294 complain_overflow_signed
, /* complain_on_overflow */
295 bfd_elf_generic_reloc
, /* special_function */
296 "R_68K_TLS_LE8", /* name */
297 FALSE
, /* partial_inplace */
299 0x000000ff, /* dst_mask */
300 FALSE
), /* pcrel_offset */
302 /* TLS GD/LD dynamic relocations. */
303 HOWTO (R_68K_TLS_DTPMOD32
, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 FALSE
, /* pc_relative */
309 complain_overflow_dont
, /* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_68K_TLS_DTPMOD32", /* name */
312 FALSE
, /* partial_inplace */
314 0xffffffff, /* dst_mask */
315 FALSE
), /* pcrel_offset */
317 HOWTO (R_68K_TLS_DTPREL32
, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 FALSE
, /* pc_relative */
323 complain_overflow_dont
, /* complain_on_overflow */
324 bfd_elf_generic_reloc
, /* special_function */
325 "R_68K_TLS_DTPREL32", /* name */
326 FALSE
, /* partial_inplace */
328 0xffffffff, /* dst_mask */
329 FALSE
), /* pcrel_offset */
331 HOWTO (R_68K_TLS_TPREL32
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE
, /* pc_relative */
337 complain_overflow_dont
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_68K_TLS_TPREL32", /* name */
340 FALSE
, /* partial_inplace */
342 0xffffffff, /* dst_mask */
343 FALSE
), /* pcrel_offset */
347 rtype_to_howto (bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
349 unsigned int indx
= ELF32_R_TYPE (dst
->r_info
);
351 if (indx
>= (unsigned int) R_68K_max
)
353 /* xgettext:c-format */
354 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
356 bfd_set_error (bfd_error_bad_value
);
359 cache_ptr
->howto
= &howto_table
[indx
];
363 #define elf_info_to_howto rtype_to_howto
367 bfd_reloc_code_real_type bfd_val
;
372 { BFD_RELOC_NONE
, R_68K_NONE
},
373 { BFD_RELOC_32
, R_68K_32
},
374 { BFD_RELOC_16
, R_68K_16
},
375 { BFD_RELOC_8
, R_68K_8
},
376 { BFD_RELOC_32_PCREL
, R_68K_PC32
},
377 { BFD_RELOC_16_PCREL
, R_68K_PC16
},
378 { BFD_RELOC_8_PCREL
, R_68K_PC8
},
379 { BFD_RELOC_32_GOT_PCREL
, R_68K_GOT32
},
380 { BFD_RELOC_16_GOT_PCREL
, R_68K_GOT16
},
381 { BFD_RELOC_8_GOT_PCREL
, R_68K_GOT8
},
382 { BFD_RELOC_32_GOTOFF
, R_68K_GOT32O
},
383 { BFD_RELOC_16_GOTOFF
, R_68K_GOT16O
},
384 { BFD_RELOC_8_GOTOFF
, R_68K_GOT8O
},
385 { BFD_RELOC_32_PLT_PCREL
, R_68K_PLT32
},
386 { BFD_RELOC_16_PLT_PCREL
, R_68K_PLT16
},
387 { BFD_RELOC_8_PLT_PCREL
, R_68K_PLT8
},
388 { BFD_RELOC_32_PLTOFF
, R_68K_PLT32O
},
389 { BFD_RELOC_16_PLTOFF
, R_68K_PLT16O
},
390 { BFD_RELOC_8_PLTOFF
, R_68K_PLT8O
},
391 { BFD_RELOC_NONE
, R_68K_COPY
},
392 { BFD_RELOC_68K_GLOB_DAT
, R_68K_GLOB_DAT
},
393 { BFD_RELOC_68K_JMP_SLOT
, R_68K_JMP_SLOT
},
394 { BFD_RELOC_68K_RELATIVE
, R_68K_RELATIVE
},
395 { BFD_RELOC_CTOR
, R_68K_32
},
396 { BFD_RELOC_VTABLE_INHERIT
, R_68K_GNU_VTINHERIT
},
397 { BFD_RELOC_VTABLE_ENTRY
, R_68K_GNU_VTENTRY
},
398 { BFD_RELOC_68K_TLS_GD32
, R_68K_TLS_GD32
},
399 { BFD_RELOC_68K_TLS_GD16
, R_68K_TLS_GD16
},
400 { BFD_RELOC_68K_TLS_GD8
, R_68K_TLS_GD8
},
401 { BFD_RELOC_68K_TLS_LDM32
, R_68K_TLS_LDM32
},
402 { BFD_RELOC_68K_TLS_LDM16
, R_68K_TLS_LDM16
},
403 { BFD_RELOC_68K_TLS_LDM8
, R_68K_TLS_LDM8
},
404 { BFD_RELOC_68K_TLS_LDO32
, R_68K_TLS_LDO32
},
405 { BFD_RELOC_68K_TLS_LDO16
, R_68K_TLS_LDO16
},
406 { BFD_RELOC_68K_TLS_LDO8
, R_68K_TLS_LDO8
},
407 { BFD_RELOC_68K_TLS_IE32
, R_68K_TLS_IE32
},
408 { BFD_RELOC_68K_TLS_IE16
, R_68K_TLS_IE16
},
409 { BFD_RELOC_68K_TLS_IE8
, R_68K_TLS_IE8
},
410 { BFD_RELOC_68K_TLS_LE32
, R_68K_TLS_LE32
},
411 { BFD_RELOC_68K_TLS_LE16
, R_68K_TLS_LE16
},
412 { BFD_RELOC_68K_TLS_LE8
, R_68K_TLS_LE8
},
415 static reloc_howto_type
*
416 reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
417 bfd_reloc_code_real_type code
)
420 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
422 if (reloc_map
[i
].bfd_val
== code
)
423 return &howto_table
[reloc_map
[i
].elf_val
];
428 static reloc_howto_type
*
429 reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
433 for (i
= 0; i
< sizeof (howto_table
) / sizeof (howto_table
[0]); i
++)
434 if (howto_table
[i
].name
!= NULL
435 && strcasecmp (howto_table
[i
].name
, r_name
) == 0)
436 return &howto_table
[i
];
441 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
442 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
443 #define ELF_ARCH bfd_arch_m68k
444 #define ELF_TARGET_ID M68K_ELF_DATA
446 /* Functions for the m68k ELF linker. */
448 /* The name of the dynamic interpreter. This is put in the .interp
451 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
453 /* Describes one of the various PLT styles. */
455 struct elf_m68k_plt_info
457 /* The size of each PLT entry. */
460 /* The template for the first PLT entry. */
461 const bfd_byte
*plt0_entry
;
463 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
464 The comments by each member indicate the value that the relocation
467 unsigned int got4
; /* .got + 4 */
468 unsigned int got8
; /* .got + 8 */
471 /* The template for a symbol's PLT entry. */
472 const bfd_byte
*symbol_entry
;
474 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
475 The comments by each member indicate the value that the relocation
478 unsigned int got
; /* the symbol's .got.plt entry */
479 unsigned int plt
; /* .plt */
482 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
483 The stub starts with "move.l #relocoffset,%d0". */
484 bfd_vma symbol_resolve_entry
;
487 /* The size in bytes of an entry in the procedure linkage table. */
489 #define PLT_ENTRY_SIZE 20
491 /* The first entry in a procedure linkage table looks like this. See
492 the SVR4 ABI m68k supplement to see how this works. */
494 static const bfd_byte elf_m68k_plt0_entry
[PLT_ENTRY_SIZE
] =
496 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
497 0, 0, 0, 2, /* + (.got + 4) - . */
498 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
499 0, 0, 0, 2, /* + (.got + 8) - . */
500 0, 0, 0, 0 /* pad out to 20 bytes. */
503 /* Subsequent entries in a procedure linkage table look like this. */
505 static const bfd_byte elf_m68k_plt_entry
[PLT_ENTRY_SIZE
] =
507 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
508 0, 0, 0, 2, /* + (.got.plt entry) - . */
509 0x2f, 0x3c, /* move.l #offset,-(%sp) */
510 0, 0, 0, 0, /* + reloc index */
511 0x60, 0xff, /* bra.l .plt */
512 0, 0, 0, 0 /* + .plt - . */
515 static const struct elf_m68k_plt_info elf_m68k_plt_info
=
518 elf_m68k_plt0_entry
, { 4, 12 },
519 elf_m68k_plt_entry
, { 4, 16 }, 8
522 #define ISAB_PLT_ENTRY_SIZE 24
524 static const bfd_byte elf_isab_plt0_entry
[ISAB_PLT_ENTRY_SIZE
] =
526 0x20, 0x3c, /* move.l #offset,%d0 */
527 0, 0, 0, 0, /* + (.got + 4) - . */
528 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
529 0x20, 0x3c, /* move.l #offset,%d0 */
530 0, 0, 0, 0, /* + (.got + 8) - . */
531 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
532 0x4e, 0xd0, /* jmp (%a0) */
536 /* Subsequent entries in a procedure linkage table look like this. */
538 static const bfd_byte elf_isab_plt_entry
[ISAB_PLT_ENTRY_SIZE
] =
540 0x20, 0x3c, /* move.l #offset,%d0 */
541 0, 0, 0, 0, /* + (.got.plt entry) - . */
542 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
543 0x4e, 0xd0, /* jmp (%a0) */
544 0x2f, 0x3c, /* move.l #offset,-(%sp) */
545 0, 0, 0, 0, /* + reloc index */
546 0x60, 0xff, /* bra.l .plt */
547 0, 0, 0, 0 /* + .plt - . */
550 static const struct elf_m68k_plt_info elf_isab_plt_info
=
553 elf_isab_plt0_entry
, { 2, 12 },
554 elf_isab_plt_entry
, { 2, 20 }, 12
557 #define ISAC_PLT_ENTRY_SIZE 24
559 static const bfd_byte elf_isac_plt0_entry
[ISAC_PLT_ENTRY_SIZE
] =
561 0x20, 0x3c, /* move.l #offset,%d0 */
562 0, 0, 0, 0, /* replaced with .got + 4 - . */
563 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
564 0x20, 0x3c, /* move.l #offset,%d0 */
565 0, 0, 0, 0, /* replaced with .got + 8 - . */
566 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
567 0x4e, 0xd0, /* jmp (%a0) */
571 /* Subsequent entries in a procedure linkage table look like this. */
573 static const bfd_byte elf_isac_plt_entry
[ISAC_PLT_ENTRY_SIZE
] =
575 0x20, 0x3c, /* move.l #offset,%d0 */
576 0, 0, 0, 0, /* replaced with (.got entry) - . */
577 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
578 0x4e, 0xd0, /* jmp (%a0) */
579 0x2f, 0x3c, /* move.l #offset,-(%sp) */
580 0, 0, 0, 0, /* replaced with offset into relocation table */
581 0x61, 0xff, /* bsr.l .plt */
582 0, 0, 0, 0 /* replaced with .plt - . */
585 static const struct elf_m68k_plt_info elf_isac_plt_info
=
588 elf_isac_plt0_entry
, { 2, 12},
589 elf_isac_plt_entry
, { 2, 20 }, 12
592 #define CPU32_PLT_ENTRY_SIZE 24
593 /* Procedure linkage table entries for the cpu32 */
594 static const bfd_byte elf_cpu32_plt0_entry
[CPU32_PLT_ENTRY_SIZE
] =
596 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
597 0, 0, 0, 2, /* + (.got + 4) - . */
598 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
599 0, 0, 0, 2, /* + (.got + 8) - . */
600 0x4e, 0xd1, /* jmp %a1@ */
601 0, 0, 0, 0, /* pad out to 24 bytes. */
605 static const bfd_byte elf_cpu32_plt_entry
[CPU32_PLT_ENTRY_SIZE
] =
607 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
608 0, 0, 0, 2, /* + (.got.plt entry) - . */
609 0x4e, 0xd1, /* jmp %a1@ */
610 0x2f, 0x3c, /* move.l #offset,-(%sp) */
611 0, 0, 0, 0, /* + reloc index */
612 0x60, 0xff, /* bra.l .plt */
613 0, 0, 0, 0, /* + .plt - . */
617 static const struct elf_m68k_plt_info elf_cpu32_plt_info
=
619 CPU32_PLT_ENTRY_SIZE
,
620 elf_cpu32_plt0_entry
, { 4, 12 },
621 elf_cpu32_plt_entry
, { 4, 18 }, 10
624 /* The m68k linker needs to keep track of the number of relocs that it
625 decides to copy in check_relocs for each symbol. This is so that it
626 can discard PC relative relocs if it doesn't need them when linking
627 with -Bsymbolic. We store the information in a field extending the
628 regular ELF linker hash table. */
630 /* This structure keeps track of the number of PC relative relocs we have
631 copied for a given symbol. */
633 struct elf_m68k_pcrel_relocs_copied
636 struct elf_m68k_pcrel_relocs_copied
*next
;
637 /* A section in dynobj. */
639 /* Number of relocs copied in this section. */
643 /* Forward declaration. */
644 struct elf_m68k_got_entry
;
646 /* m68k ELF linker hash entry. */
648 struct elf_m68k_link_hash_entry
650 struct elf_link_hash_entry root
;
652 /* Number of PC relative relocs copied for this symbol. */
653 struct elf_m68k_pcrel_relocs_copied
*pcrel_relocs_copied
;
655 /* Key to got_entries. */
656 unsigned long got_entry_key
;
658 /* List of GOT entries for this symbol. This list is build during
659 offset finalization and is used within elf_m68k_finish_dynamic_symbol
660 to traverse all GOT entries for a particular symbol.
662 ??? We could've used root.got.glist field instead, but having
663 a separate field is cleaner. */
664 struct elf_m68k_got_entry
*glist
;
667 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
669 /* Key part of GOT entry in hashtable. */
670 struct elf_m68k_got_entry_key
672 /* BFD in which this symbol was defined. NULL for global symbols. */
675 /* Symbol index. Either local symbol index or h->got_entry_key. */
676 unsigned long symndx
;
678 /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
679 R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
681 From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
682 matters. That is, we distinguish between, say, R_68K_GOT16O
683 and R_68K_GOT32O when allocating offsets, but they are considered to be
684 the same when searching got->entries. */
685 enum elf_m68k_reloc_type type
;
688 /* Size of the GOT offset suitable for relocation. */
689 enum elf_m68k_got_offset_size
{ R_8
, R_16
, R_32
, R_LAST
};
691 /* Entry of the GOT. */
692 struct elf_m68k_got_entry
694 /* GOT entries are put into a got->entries hashtable. This is the key. */
695 struct elf_m68k_got_entry_key key_
;
697 /* GOT entry data. We need s1 before offset finalization and s2 after. */
702 /* Number of times this entry is referenced. */
708 /* Offset from the start of .got section. To calculate offset relative
709 to GOT pointer one should subtract got->offset from this value. */
712 /* Pointer to the next GOT entry for this global symbol.
713 Symbols have at most one entry in one GOT, but might
714 have entries in more than one GOT.
715 Root of this list is h->glist.
716 NULL for local symbols. */
717 struct elf_m68k_got_entry
*next
;
722 /* Return representative type for relocation R_TYPE.
723 This is used to avoid enumerating many relocations in comparisons,
726 static enum elf_m68k_reloc_type
727 elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type
)
731 /* In most cases R_68K_GOTx relocations require the very same
732 handling as R_68K_GOT32O relocation. In cases when we need
733 to distinguish between the two, we use explicitly compare against
746 return R_68K_TLS_GD32
;
748 case R_68K_TLS_LDM32
:
749 case R_68K_TLS_LDM16
:
751 return R_68K_TLS_LDM32
;
756 return R_68K_TLS_IE32
;
764 /* Return size of the GOT entry offset for relocation R_TYPE. */
766 static enum elf_m68k_got_offset_size
767 elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type
)
771 case R_68K_GOT32
: case R_68K_GOT16
: case R_68K_GOT8
:
772 case R_68K_GOT32O
: case R_68K_TLS_GD32
: case R_68K_TLS_LDM32
:
776 case R_68K_GOT16O
: case R_68K_TLS_GD16
: case R_68K_TLS_LDM16
:
780 case R_68K_GOT8O
: case R_68K_TLS_GD8
: case R_68K_TLS_LDM8
:
790 /* Return number of GOT entries we need to allocate in GOT for
791 relocation R_TYPE. */
794 elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type
)
796 switch (elf_m68k_reloc_got_type (r_type
))
803 case R_68K_TLS_LDM32
:
812 /* Return TRUE if relocation R_TYPE is a TLS one. */
815 elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type
)
819 case R_68K_TLS_GD32
: case R_68K_TLS_GD16
: case R_68K_TLS_GD8
:
820 case R_68K_TLS_LDM32
: case R_68K_TLS_LDM16
: case R_68K_TLS_LDM8
:
821 case R_68K_TLS_LDO32
: case R_68K_TLS_LDO16
: case R_68K_TLS_LDO8
:
822 case R_68K_TLS_IE32
: case R_68K_TLS_IE16
: case R_68K_TLS_IE8
:
823 case R_68K_TLS_LE32
: case R_68K_TLS_LE16
: case R_68K_TLS_LE8
:
824 case R_68K_TLS_DTPMOD32
: case R_68K_TLS_DTPREL32
: case R_68K_TLS_TPREL32
:
832 /* Data structure representing a single GOT. */
835 /* Hashtable of 'struct elf_m68k_got_entry's.
836 Starting size of this table is the maximum number of
837 R_68K_GOT8O entries. */
840 /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
843 n_slots[R_8] is the count of R_8 slots in this GOT.
844 n_slots[R_16] is the cumulative count of R_8 and R_16 slots
846 n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
847 in this GOT. This is the total number of slots. */
848 bfd_vma n_slots
[R_LAST
];
850 /* Number of local (entry->key_.h == NULL) slots in this GOT.
851 This is only used to properly calculate size of .rela.got section;
852 see elf_m68k_partition_multi_got. */
853 bfd_vma local_n_slots
;
855 /* Offset of this GOT relative to beginning of .got section. */
859 /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
860 struct elf_m68k_bfd2got_entry
865 /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
866 GOT structure. After partitioning several BFD's might [and often do]
867 share a single GOT. */
868 struct elf_m68k_got
*got
;
871 /* The main data structure holding all the pieces. */
872 struct elf_m68k_multi_got
874 /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
875 here, then it doesn't need a GOT (this includes the case of a BFD
876 having an empty GOT).
878 ??? This hashtable can be replaced by an array indexed by bfd->id. */
881 /* Next symndx to assign a global symbol.
882 h->got_entry_key is initialized from this counter. */
883 unsigned long global_symndx
;
886 /* m68k ELF linker hash table. */
888 struct elf_m68k_link_hash_table
890 struct elf_link_hash_table root
;
892 /* Small local sym cache. */
893 struct sym_cache sym_cache
;
895 /* The PLT format used by this link, or NULL if the format has not
897 const struct elf_m68k_plt_info
*plt_info
;
899 /* True, if GP is loaded within each function which uses it.
900 Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
901 bfd_boolean local_gp_p
;
903 /* Switch controlling use of negative offsets to double the size of GOTs. */
904 bfd_boolean use_neg_got_offsets_p
;
906 /* Switch controlling generation of multiple GOTs. */
907 bfd_boolean allow_multigot_p
;
909 /* Multi-GOT data structure. */
910 struct elf_m68k_multi_got multi_got_
;
913 /* Get the m68k ELF linker hash table from a link_info structure. */
915 #define elf_m68k_hash_table(p) \
916 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
917 == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL)
919 /* Shortcut to multi-GOT data. */
920 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
922 /* Create an entry in an m68k ELF linker hash table. */
924 static struct bfd_hash_entry
*
925 elf_m68k_link_hash_newfunc (struct bfd_hash_entry
*entry
,
926 struct bfd_hash_table
*table
,
929 struct bfd_hash_entry
*ret
= entry
;
931 /* Allocate the structure if it has not already been allocated by a
934 ret
= bfd_hash_allocate (table
,
935 sizeof (struct elf_m68k_link_hash_entry
));
939 /* Call the allocation method of the superclass. */
940 ret
= _bfd_elf_link_hash_newfunc (ret
, table
, string
);
943 elf_m68k_hash_entry (ret
)->pcrel_relocs_copied
= NULL
;
944 elf_m68k_hash_entry (ret
)->got_entry_key
= 0;
945 elf_m68k_hash_entry (ret
)->glist
= NULL
;
951 /* Destroy an m68k ELF linker hash table. */
954 elf_m68k_link_hash_table_free (bfd
*obfd
)
956 struct elf_m68k_link_hash_table
*htab
;
958 htab
= (struct elf_m68k_link_hash_table
*) obfd
->link
.hash
;
960 if (htab
->multi_got_
.bfd2got
!= NULL
)
962 htab_delete (htab
->multi_got_
.bfd2got
);
963 htab
->multi_got_
.bfd2got
= NULL
;
965 _bfd_elf_link_hash_table_free (obfd
);
968 /* Create an m68k ELF linker hash table. */
970 static struct bfd_link_hash_table
*
971 elf_m68k_link_hash_table_create (bfd
*abfd
)
973 struct elf_m68k_link_hash_table
*ret
;
974 size_t amt
= sizeof (struct elf_m68k_link_hash_table
);
976 ret
= (struct elf_m68k_link_hash_table
*) bfd_zmalloc (amt
);
977 if (ret
== (struct elf_m68k_link_hash_table
*) NULL
)
980 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
981 elf_m68k_link_hash_newfunc
,
982 sizeof (struct elf_m68k_link_hash_entry
),
988 ret
->root
.root
.hash_table_free
= elf_m68k_link_hash_table_free
;
990 ret
->multi_got_
.global_symndx
= 1;
992 return &ret
->root
.root
;
995 /* Set the right machine number. */
998 elf32_m68k_object_p (bfd
*abfd
)
1000 unsigned int mach
= 0;
1001 unsigned features
= 0;
1002 flagword eflags
= elf_elfheader (abfd
)->e_flags
;
1004 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1006 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1008 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1012 switch (eflags
& EF_M68K_CF_ISA_MASK
)
1014 case EF_M68K_CF_ISA_A_NODIV
:
1015 features
|= mcfisa_a
;
1017 case EF_M68K_CF_ISA_A
:
1018 features
|= mcfisa_a
|mcfhwdiv
;
1020 case EF_M68K_CF_ISA_A_PLUS
:
1021 features
|= mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
;
1023 case EF_M68K_CF_ISA_B_NOUSP
:
1024 features
|= mcfisa_a
|mcfisa_b
|mcfhwdiv
;
1026 case EF_M68K_CF_ISA_B
:
1027 features
|= mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfusp
;
1029 case EF_M68K_CF_ISA_C
:
1030 features
|= mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfusp
;
1032 case EF_M68K_CF_ISA_C_NODIV
:
1033 features
|= mcfisa_a
|mcfisa_c
|mcfusp
;
1036 switch (eflags
& EF_M68K_CF_MAC_MASK
)
1038 case EF_M68K_CF_MAC
:
1041 case EF_M68K_CF_EMAC
:
1042 features
|= mcfemac
;
1045 if (eflags
& EF_M68K_CF_FLOAT
)
1049 mach
= bfd_m68k_features_to_mach (features
);
1050 bfd_default_set_arch_mach (abfd
, bfd_arch_m68k
, mach
);
1055 /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
1056 field based on the machine number. */
1059 elf_m68k_final_write_processing (bfd
*abfd
)
1061 int mach
= bfd_get_mach (abfd
);
1062 unsigned long e_flags
= elf_elfheader (abfd
)->e_flags
;
1066 unsigned int arch_mask
;
1068 arch_mask
= bfd_m68k_mach_to_features (mach
);
1070 if (arch_mask
& m68000
)
1071 e_flags
= EF_M68K_M68000
;
1072 else if (arch_mask
& cpu32
)
1073 e_flags
= EF_M68K_CPU32
;
1074 else if (arch_mask
& fido_a
)
1075 e_flags
= EF_M68K_FIDO
;
1079 & (mcfisa_a
| mcfisa_aa
| mcfisa_b
| mcfisa_c
| mcfhwdiv
| mcfusp
))
1082 e_flags
|= EF_M68K_CF_ISA_A_NODIV
;
1084 case mcfisa_a
| mcfhwdiv
:
1085 e_flags
|= EF_M68K_CF_ISA_A
;
1087 case mcfisa_a
| mcfisa_aa
| mcfhwdiv
| mcfusp
:
1088 e_flags
|= EF_M68K_CF_ISA_A_PLUS
;
1090 case mcfisa_a
| mcfisa_b
| mcfhwdiv
:
1091 e_flags
|= EF_M68K_CF_ISA_B_NOUSP
;
1093 case mcfisa_a
| mcfisa_b
| mcfhwdiv
| mcfusp
:
1094 e_flags
|= EF_M68K_CF_ISA_B
;
1096 case mcfisa_a
| mcfisa_c
| mcfhwdiv
| mcfusp
:
1097 e_flags
|= EF_M68K_CF_ISA_C
;
1099 case mcfisa_a
| mcfisa_c
| mcfusp
:
1100 e_flags
|= EF_M68K_CF_ISA_C_NODIV
;
1103 if (arch_mask
& mcfmac
)
1104 e_flags
|= EF_M68K_CF_MAC
;
1105 else if (arch_mask
& mcfemac
)
1106 e_flags
|= EF_M68K_CF_EMAC
;
1107 if (arch_mask
& cfloat
)
1108 e_flags
|= EF_M68K_CF_FLOAT
| EF_M68K_CFV4E
;
1110 elf_elfheader (abfd
)->e_flags
= e_flags
;
1112 return _bfd_elf_final_write_processing (abfd
);
1115 /* Keep m68k-specific flags in the ELF header. */
1118 elf32_m68k_set_private_flags (bfd
*abfd
, flagword flags
)
1120 elf_elfheader (abfd
)->e_flags
= flags
;
1121 elf_flags_init (abfd
) = TRUE
;
1125 /* Merge object attributes from IBFD into OBFD. Warn if
1126 there are conflicting attributes. */
1128 m68k_elf_merge_obj_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
1130 bfd
*obfd
= info
->output_bfd
;
1131 obj_attribute
*in_attr
, *in_attrs
;
1132 obj_attribute
*out_attr
, *out_attrs
;
1133 bfd_boolean ret
= TRUE
;
1135 in_attrs
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
1136 out_attrs
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
1138 in_attr
= &in_attrs
[Tag_GNU_M68K_ABI_FP
];
1139 out_attr
= &out_attrs
[Tag_GNU_M68K_ABI_FP
];
1141 if (in_attr
->i
!= out_attr
->i
)
1143 int in_fp
= in_attr
->i
& 3;
1144 int out_fp
= out_attr
->i
& 3;
1145 static bfd
*last_fp
;
1149 else if (out_fp
== 0)
1151 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
;
1152 out_attr
->i
^= in_fp
;
1155 else if (out_fp
== 1 && in_fp
== 2)
1158 /* xgettext:c-format */
1159 (_("%pB uses hard float, %pB uses soft float"),
1163 else if (out_fp
== 2 && in_fp
== 1)
1166 /* xgettext:c-format */
1167 (_("%pB uses hard float, %pB uses soft float"),
1175 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_ERROR
;
1176 bfd_set_error (bfd_error_bad_value
);
1180 /* Merge Tag_compatibility attributes and any common GNU ones. */
1181 return _bfd_elf_merge_object_attributes (ibfd
, info
);
1184 /* Merge backend specific data from an object file to the output
1185 object file when linking. */
1187 elf32_m68k_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
1189 bfd
*obfd
= info
->output_bfd
;
1194 const bfd_arch_info_type
*arch_info
;
1196 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1197 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1198 /* PR 24523: For non-ELF files do not try to merge any private
1199 data, but also do not prevent the link from succeeding. */
1202 /* Get the merged machine. This checks for incompatibility between
1203 Coldfire & non-Coldfire flags, incompability between different
1204 Coldfire ISAs, and incompability between different MAC types. */
1205 arch_info
= bfd_arch_get_compatible (ibfd
, obfd
, FALSE
);
1209 bfd_set_arch_mach (obfd
, bfd_arch_m68k
, arch_info
->mach
);
1211 if (!m68k_elf_merge_obj_attributes (ibfd
, info
))
1214 in_flags
= elf_elfheader (ibfd
)->e_flags
;
1215 if (!elf_flags_init (obfd
))
1217 elf_flags_init (obfd
) = TRUE
;
1218 out_flags
= in_flags
;
1222 out_flags
= elf_elfheader (obfd
)->e_flags
;
1223 unsigned int variant_mask
;
1225 if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1227 else if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1229 else if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1232 variant_mask
= EF_M68K_CF_ISA_MASK
;
1234 in_isa
= (in_flags
& variant_mask
);
1235 out_isa
= (out_flags
& variant_mask
);
1236 if (in_isa
> out_isa
)
1237 out_flags
^= in_isa
^ out_isa
;
1238 if (((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
1239 && (out_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1240 || ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
1241 && (out_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
))
1242 out_flags
= EF_M68K_FIDO
;
1244 out_flags
|= in_flags
^ in_isa
;
1246 elf_elfheader (obfd
)->e_flags
= out_flags
;
1251 /* Display the flags field. */
1254 elf32_m68k_print_private_bfd_data (bfd
*abfd
, void * ptr
)
1256 FILE *file
= (FILE *) ptr
;
1257 flagword eflags
= elf_elfheader (abfd
)->e_flags
;
1259 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
1261 /* Print normal ELF private data. */
1262 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
1264 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1266 /* xgettext:c-format */
1267 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
1269 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1270 fprintf (file
, " [m68000]");
1271 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1272 fprintf (file
, " [cpu32]");
1273 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1274 fprintf (file
, " [fido]");
1277 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CFV4E
)
1278 fprintf (file
, " [cfv4e]");
1280 if (eflags
& EF_M68K_CF_ISA_MASK
)
1282 char const *isa
= _("unknown");
1283 char const *mac
= _("unknown");
1284 char const *additional
= "";
1286 switch (eflags
& EF_M68K_CF_ISA_MASK
)
1288 case EF_M68K_CF_ISA_A_NODIV
:
1290 additional
= " [nodiv]";
1292 case EF_M68K_CF_ISA_A
:
1295 case EF_M68K_CF_ISA_A_PLUS
:
1298 case EF_M68K_CF_ISA_B_NOUSP
:
1300 additional
= " [nousp]";
1302 case EF_M68K_CF_ISA_B
:
1305 case EF_M68K_CF_ISA_C
:
1308 case EF_M68K_CF_ISA_C_NODIV
:
1310 additional
= " [nodiv]";
1313 fprintf (file
, " [isa %s]%s", isa
, additional
);
1315 if (eflags
& EF_M68K_CF_FLOAT
)
1316 fprintf (file
, " [float]");
1318 switch (eflags
& EF_M68K_CF_MAC_MASK
)
1323 case EF_M68K_CF_MAC
:
1326 case EF_M68K_CF_EMAC
:
1329 case EF_M68K_CF_EMAC_B
:
1334 fprintf (file
, " [%s]", mac
);
1343 /* Multi-GOT support implementation design:
1345 Multi-GOT starts in check_relocs hook. There we scan all
1346 relocations of a BFD and build a local GOT (struct elf_m68k_got)
1347 for it. If a single BFD appears to require too many GOT slots with
1348 R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1350 After check_relocs has been invoked for each input BFD, we have
1351 constructed a GOT for each input BFD.
1353 To minimize total number of GOTs required for a particular output BFD
1354 (as some environments support only 1 GOT per output object) we try
1355 to merge some of the GOTs to share an offset space. Ideally [and in most
1356 cases] we end up with a single GOT. In cases when there are too many
1357 restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1358 several GOTs, assuming the environment can handle them.
1360 Partitioning is done in elf_m68k_partition_multi_got. We start with
1361 an empty GOT and traverse bfd2got hashtable putting got_entries from
1362 local GOTs to the new 'big' one. We do that by constructing an
1363 intermediate GOT holding all the entries the local GOT has and the big
1364 GOT lacks. Then we check if there is room in the big GOT to accomodate
1365 all the entries from diff. On success we add those entries to the big
1366 GOT; on failure we start the new 'big' GOT and retry the adding of
1367 entries from the local GOT. Note that this retry will always succeed as
1368 each local GOT doesn't overflow the limits. After partitioning we
1369 end up with each bfd assigned one of the big GOTs. GOT entries in the
1370 big GOTs are initialized with GOT offsets. Note that big GOTs are
1371 positioned consequently in program space and represent a single huge GOT
1372 to the outside world.
1374 After that we get to elf_m68k_relocate_section. There we
1375 adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1376 relocations to refer to appropriate [assigned to current input_bfd]
1381 GOT entry type: We have several types of GOT entries.
1382 * R_8 type is used in entries for symbols that have at least one
1383 R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
1384 such entries in one GOT.
1385 * R_16 type is used in entries for symbols that have at least one
1386 R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1387 We can have at most 0x4000 such entries in one GOT.
1388 * R_32 type is used in all other cases. We can have as many
1389 such entries in one GOT as we'd like.
1390 When counting relocations we have to include the count of the smaller
1391 ranged relocations in the counts of the larger ranged ones in order
1392 to correctly detect overflow.
1394 Sorting the GOT: In each GOT starting offsets are assigned to
1395 R_8 entries, which are followed by R_16 entries, and
1396 R_32 entries go at the end. See finalize_got_offsets for details.
1398 Negative GOT offsets: To double usable offset range of GOTs we use
1399 negative offsets. As we assign entries with GOT offsets relative to
1400 start of .got section, the offset values are positive. They become
1401 negative only in relocate_section where got->offset value is
1402 subtracted from them.
1404 3 special GOT entries: There are 3 special GOT entries used internally
1405 by loader. These entries happen to be placed to .got.plt section,
1406 so we don't do anything about them in multi-GOT support.
1408 Memory management: All data except for hashtables
1409 multi_got->bfd2got and got->entries are allocated on
1410 elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1411 to most functions), so we don't need to care to free them. At the
1412 moment of allocation hashtables are being linked into main data
1413 structure (multi_got), all pieces of which are reachable from
1414 elf_m68k_multi_got (info). We deallocate them in
1415 elf_m68k_link_hash_table_free. */
1417 /* Initialize GOT. */
1420 elf_m68k_init_got (struct elf_m68k_got
*got
)
1422 got
->entries
= NULL
;
1423 got
->n_slots
[R_8
] = 0;
1424 got
->n_slots
[R_16
] = 0;
1425 got
->n_slots
[R_32
] = 0;
1426 got
->local_n_slots
= 0;
1427 got
->offset
= (bfd_vma
) -1;
1433 elf_m68k_clear_got (struct elf_m68k_got
*got
)
1435 if (got
->entries
!= NULL
)
1437 htab_delete (got
->entries
);
1438 got
->entries
= NULL
;
1442 /* Create and empty GOT structure. INFO is the context where memory
1443 should be allocated. */
1445 static struct elf_m68k_got
*
1446 elf_m68k_create_empty_got (struct bfd_link_info
*info
)
1448 struct elf_m68k_got
*got
;
1450 got
= bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*got
));
1454 elf_m68k_init_got (got
);
1459 /* Initialize KEY. */
1462 elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key
*key
,
1463 struct elf_link_hash_entry
*h
,
1464 const bfd
*abfd
, unsigned long symndx
,
1465 enum elf_m68k_reloc_type reloc_type
)
1467 if (elf_m68k_reloc_got_type (reloc_type
) == R_68K_TLS_LDM32
)
1468 /* All TLS_LDM relocations share a single GOT entry. */
1474 /* Global symbols are identified with their got_entry_key. */
1477 key
->symndx
= elf_m68k_hash_entry (h
)->got_entry_key
;
1478 BFD_ASSERT (key
->symndx
!= 0);
1481 /* Local symbols are identified by BFD they appear in and symndx. */
1484 key
->symndx
= symndx
;
1487 key
->type
= reloc_type
;
1490 /* Calculate hash of got_entry.
1494 elf_m68k_got_entry_hash (const void *_entry
)
1496 const struct elf_m68k_got_entry_key
*key
;
1498 key
= &((const struct elf_m68k_got_entry
*) _entry
)->key_
;
1501 + (key
->bfd
!= NULL
? (int) key
->bfd
->id
: -1)
1502 + elf_m68k_reloc_got_type (key
->type
));
1505 /* Check if two got entries are equal. */
1508 elf_m68k_got_entry_eq (const void *_entry1
, const void *_entry2
)
1510 const struct elf_m68k_got_entry_key
*key1
;
1511 const struct elf_m68k_got_entry_key
*key2
;
1513 key1
= &((const struct elf_m68k_got_entry
*) _entry1
)->key_
;
1514 key2
= &((const struct elf_m68k_got_entry
*) _entry2
)->key_
;
1516 return (key1
->bfd
== key2
->bfd
1517 && key1
->symndx
== key2
->symndx
1518 && (elf_m68k_reloc_got_type (key1
->type
)
1519 == elf_m68k_reloc_got_type (key2
->type
)));
1522 /* When using negative offsets, we allocate one extra R_8, one extra R_16
1523 and one extra R_32 slots to simplify handling of 2-slot entries during
1524 offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
1526 /* Maximal number of R_8 slots in a single GOT. */
1527 #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
1528 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1532 /* Maximal number of R_8 and R_16 slots in a single GOT. */
1533 #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
1534 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1538 /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1539 the entry cannot be found.
1540 FIND_OR_CREATE - search for an existing entry, but create new if there's
1542 MUST_FIND - search for an existing entry and assert that it exist.
1543 MUST_CREATE - assert that there's no such entry and create new one. */
1544 enum elf_m68k_get_entry_howto
1552 /* Get or create (depending on HOWTO) entry with KEY in GOT.
1553 INFO is context in which memory should be allocated (can be NULL if
1554 HOWTO is SEARCH or MUST_FIND). */
1556 static struct elf_m68k_got_entry
*
1557 elf_m68k_get_got_entry (struct elf_m68k_got
*got
,
1558 const struct elf_m68k_got_entry_key
*key
,
1559 enum elf_m68k_get_entry_howto howto
,
1560 struct bfd_link_info
*info
)
1562 struct elf_m68k_got_entry entry_
;
1563 struct elf_m68k_got_entry
*entry
;
1566 BFD_ASSERT ((info
== NULL
) == (howto
== SEARCH
|| howto
== MUST_FIND
));
1568 if (got
->entries
== NULL
)
1569 /* This is the first entry in ABFD. Initialize hashtable. */
1571 if (howto
== SEARCH
)
1574 got
->entries
= htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1576 elf_m68k_got_entry_hash
,
1577 elf_m68k_got_entry_eq
, NULL
);
1578 if (got
->entries
== NULL
)
1580 bfd_set_error (bfd_error_no_memory
);
1586 ptr
= htab_find_slot (got
->entries
, &entry_
,
1587 (howto
== SEARCH
|| howto
== MUST_FIND
? NO_INSERT
1591 if (howto
== SEARCH
)
1592 /* Entry not found. */
1595 if (howto
== MUST_FIND
)
1598 /* We're out of memory. */
1599 bfd_set_error (bfd_error_no_memory
);
1604 /* We didn't find the entry and we're asked to create a new one. */
1606 if (howto
== MUST_FIND
)
1609 BFD_ASSERT (howto
!= SEARCH
);
1611 entry
= bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*entry
));
1615 /* Initialize new entry. */
1618 entry
->u
.s1
.refcount
= 0;
1620 /* Mark the entry as not initialized. */
1621 entry
->key_
.type
= R_68K_max
;
1626 /* We found the entry. */
1628 BFD_ASSERT (howto
!= MUST_CREATE
);
1636 /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1637 Return the value to which ENTRY's type should be set. */
1639 static enum elf_m68k_reloc_type
1640 elf_m68k_update_got_entry_type (struct elf_m68k_got
*got
,
1641 enum elf_m68k_reloc_type was
,
1642 enum elf_m68k_reloc_type new_reloc
)
1644 enum elf_m68k_got_offset_size was_size
;
1645 enum elf_m68k_got_offset_size new_size
;
1648 if (was
== R_68K_max
)
1649 /* The type of the entry is not initialized yet. */
1651 /* Update all got->n_slots counters, including n_slots[R_32]. */
1658 /* !!! We, probably, should emit an error rather then fail on assert
1660 BFD_ASSERT (elf_m68k_reloc_got_type (was
)
1661 == elf_m68k_reloc_got_type (new_reloc
));
1663 was_size
= elf_m68k_reloc_got_offset_size (was
);
1666 new_size
= elf_m68k_reloc_got_offset_size (new_reloc
);
1667 n_slots
= elf_m68k_reloc_got_n_slots (new_reloc
);
1669 while (was_size
> new_size
)
1672 got
->n_slots
[was_size
] += n_slots
;
1675 if (new_reloc
> was
)
1676 /* Relocations are ordered from bigger got offset size to lesser,
1677 so choose the relocation type with lesser offset size. */
1683 /* Add new or update existing entry to GOT.
1684 H, ABFD, TYPE and SYMNDX is data for the entry.
1685 INFO is a context where memory should be allocated. */
1687 static struct elf_m68k_got_entry
*
1688 elf_m68k_add_entry_to_got (struct elf_m68k_got
*got
,
1689 struct elf_link_hash_entry
*h
,
1691 enum elf_m68k_reloc_type reloc_type
,
1692 unsigned long symndx
,
1693 struct bfd_link_info
*info
)
1695 struct elf_m68k_got_entry_key key_
;
1696 struct elf_m68k_got_entry
*entry
;
1698 if (h
!= NULL
&& elf_m68k_hash_entry (h
)->got_entry_key
== 0)
1699 elf_m68k_hash_entry (h
)->got_entry_key
1700 = elf_m68k_multi_got (info
)->global_symndx
++;
1702 elf_m68k_init_got_entry_key (&key_
, h
, abfd
, symndx
, reloc_type
);
1704 entry
= elf_m68k_get_got_entry (got
, &key_
, FIND_OR_CREATE
, info
);
1708 /* Determine entry's type and update got->n_slots counters. */
1709 entry
->key_
.type
= elf_m68k_update_got_entry_type (got
,
1713 /* Update refcount. */
1714 ++entry
->u
.s1
.refcount
;
1716 if (entry
->u
.s1
.refcount
== 1)
1717 /* We see this entry for the first time. */
1719 if (entry
->key_
.bfd
!= NULL
)
1720 got
->local_n_slots
+= elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
1723 BFD_ASSERT (got
->n_slots
[R_32
] >= got
->local_n_slots
);
1725 if ((got
->n_slots
[R_8
]
1726 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1727 || (got
->n_slots
[R_16
]
1728 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
)))
1729 /* This BFD has too many relocation. */
1731 if (got
->n_slots
[R_8
] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1732 /* xgettext:c-format */
1733 _bfd_error_handler (_("%pB: GOT overflow: "
1734 "number of relocations with 8-bit "
1737 ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
));
1739 /* xgettext:c-format */
1740 _bfd_error_handler (_("%pB: GOT overflow: "
1741 "number of relocations with 8- or 16-bit "
1744 ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
));
1752 /* Compute the hash value of the bfd in a bfd2got hash entry. */
1755 elf_m68k_bfd2got_entry_hash (const void *entry
)
1757 const struct elf_m68k_bfd2got_entry
*e
;
1759 e
= (const struct elf_m68k_bfd2got_entry
*) entry
;
1764 /* Check whether two hash entries have the same bfd. */
1767 elf_m68k_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
1769 const struct elf_m68k_bfd2got_entry
*e1
;
1770 const struct elf_m68k_bfd2got_entry
*e2
;
1772 e1
= (const struct elf_m68k_bfd2got_entry
*) entry1
;
1773 e2
= (const struct elf_m68k_bfd2got_entry
*) entry2
;
1775 return e1
->bfd
== e2
->bfd
;
1778 /* Destruct a bfd2got entry. */
1781 elf_m68k_bfd2got_entry_del (void *_entry
)
1783 struct elf_m68k_bfd2got_entry
*entry
;
1785 entry
= (struct elf_m68k_bfd2got_entry
*) _entry
;
1787 BFD_ASSERT (entry
->got
!= NULL
);
1788 elf_m68k_clear_got (entry
->got
);
1791 /* Find existing or create new (depending on HOWTO) bfd2got entry in
1792 MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1793 memory should be allocated. */
1795 static struct elf_m68k_bfd2got_entry
*
1796 elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got
*multi_got
,
1798 enum elf_m68k_get_entry_howto howto
,
1799 struct bfd_link_info
*info
)
1801 struct elf_m68k_bfd2got_entry entry_
;
1803 struct elf_m68k_bfd2got_entry
*entry
;
1805 BFD_ASSERT ((info
== NULL
) == (howto
== SEARCH
|| howto
== MUST_FIND
));
1807 if (multi_got
->bfd2got
== NULL
)
1808 /* This is the first GOT. Initialize bfd2got. */
1810 if (howto
== SEARCH
)
1813 multi_got
->bfd2got
= htab_try_create (1, elf_m68k_bfd2got_entry_hash
,
1814 elf_m68k_bfd2got_entry_eq
,
1815 elf_m68k_bfd2got_entry_del
);
1816 if (multi_got
->bfd2got
== NULL
)
1818 bfd_set_error (bfd_error_no_memory
);
1824 ptr
= htab_find_slot (multi_got
->bfd2got
, &entry_
,
1825 (howto
== SEARCH
|| howto
== MUST_FIND
? NO_INSERT
1829 if (howto
== SEARCH
)
1830 /* Entry not found. */
1833 if (howto
== MUST_FIND
)
1836 /* We're out of memory. */
1837 bfd_set_error (bfd_error_no_memory
);
1842 /* Entry was not found. Create new one. */
1844 if (howto
== MUST_FIND
)
1847 BFD_ASSERT (howto
!= SEARCH
);
1849 entry
= ((struct elf_m68k_bfd2got_entry
*)
1850 bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*entry
)));
1856 entry
->got
= elf_m68k_create_empty_got (info
);
1857 if (entry
->got
== NULL
)
1864 BFD_ASSERT (howto
!= MUST_CREATE
);
1866 /* Return existing entry. */
1873 struct elf_m68k_can_merge_gots_arg
1875 /* A current_got that we constructing a DIFF against. */
1876 struct elf_m68k_got
*big
;
1878 /* GOT holding entries not present or that should be changed in
1880 struct elf_m68k_got
*diff
;
1882 /* Context where to allocate memory. */
1883 struct bfd_link_info
*info
;
1886 bfd_boolean error_p
;
1889 /* Process a single entry from the small GOT to see if it should be added
1890 or updated in the big GOT. */
1893 elf_m68k_can_merge_gots_1 (void **_entry_ptr
, void *_arg
)
1895 const struct elf_m68k_got_entry
*entry1
;
1896 struct elf_m68k_can_merge_gots_arg
*arg
;
1897 const struct elf_m68k_got_entry
*entry2
;
1898 enum elf_m68k_reloc_type type
;
1900 entry1
= (const struct elf_m68k_got_entry
*) *_entry_ptr
;
1901 arg
= (struct elf_m68k_can_merge_gots_arg
*) _arg
;
1903 entry2
= elf_m68k_get_got_entry (arg
->big
, &entry1
->key_
, SEARCH
, NULL
);
1906 /* We found an existing entry. Check if we should update it. */
1908 type
= elf_m68k_update_got_entry_type (arg
->diff
,
1912 if (type
== entry2
->key_
.type
)
1913 /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1914 To skip creation of difference entry we use the type,
1915 which we won't see in GOT entries for sure. */
1919 /* We didn't find the entry. Add entry1 to DIFF. */
1921 BFD_ASSERT (entry1
->key_
.type
!= R_68K_max
);
1923 type
= elf_m68k_update_got_entry_type (arg
->diff
,
1924 R_68K_max
, entry1
->key_
.type
);
1926 if (entry1
->key_
.bfd
!= NULL
)
1927 arg
->diff
->local_n_slots
+= elf_m68k_reloc_got_n_slots (type
);
1930 if (type
!= R_68K_max
)
1931 /* Create an entry in DIFF. */
1933 struct elf_m68k_got_entry
*entry
;
1935 entry
= elf_m68k_get_got_entry (arg
->diff
, &entry1
->key_
, MUST_CREATE
,
1939 arg
->error_p
= TRUE
;
1943 entry
->key_
.type
= type
;
1949 /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1950 Construct DIFF GOT holding the entries which should be added or updated
1951 in BIG GOT to accumulate information from SMALL.
1952 INFO is the context where memory should be allocated. */
1955 elf_m68k_can_merge_gots (struct elf_m68k_got
*big
,
1956 const struct elf_m68k_got
*small
,
1957 struct bfd_link_info
*info
,
1958 struct elf_m68k_got
*diff
)
1960 struct elf_m68k_can_merge_gots_arg arg_
;
1962 BFD_ASSERT (small
->offset
== (bfd_vma
) -1);
1967 arg_
.error_p
= FALSE
;
1968 htab_traverse_noresize (small
->entries
, elf_m68k_can_merge_gots_1
, &arg_
);
1975 /* Check for overflow. */
1976 if ((big
->n_slots
[R_8
] + arg_
.diff
->n_slots
[R_8
]
1977 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1978 || (big
->n_slots
[R_16
] + arg_
.diff
->n_slots
[R_16
]
1979 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
)))
1985 struct elf_m68k_merge_gots_arg
1988 struct elf_m68k_got
*big
;
1990 /* Context where memory should be allocated. */
1991 struct bfd_link_info
*info
;
1994 bfd_boolean error_p
;
1997 /* Process a single entry from DIFF got. Add or update corresponding
1998 entry in the BIG got. */
2001 elf_m68k_merge_gots_1 (void **entry_ptr
, void *_arg
)
2003 const struct elf_m68k_got_entry
*from
;
2004 struct elf_m68k_merge_gots_arg
*arg
;
2005 struct elf_m68k_got_entry
*to
;
2007 from
= (const struct elf_m68k_got_entry
*) *entry_ptr
;
2008 arg
= (struct elf_m68k_merge_gots_arg
*) _arg
;
2010 to
= elf_m68k_get_got_entry (arg
->big
, &from
->key_
, FIND_OR_CREATE
,
2014 arg
->error_p
= TRUE
;
2018 BFD_ASSERT (to
->u
.s1
.refcount
== 0);
2019 /* All we need to merge is TYPE. */
2020 to
->key_
.type
= from
->key_
.type
;
2025 /* Merge data from DIFF to BIG. INFO is context where memory should be
2029 elf_m68k_merge_gots (struct elf_m68k_got
*big
,
2030 struct elf_m68k_got
*diff
,
2031 struct bfd_link_info
*info
)
2033 if (diff
->entries
!= NULL
)
2034 /* DIFF is not empty. Merge it into BIG GOT. */
2036 struct elf_m68k_merge_gots_arg arg_
;
2038 /* Merge entries. */
2041 arg_
.error_p
= FALSE
;
2042 htab_traverse_noresize (diff
->entries
, elf_m68k_merge_gots_1
, &arg_
);
2046 /* Merge counters. */
2047 big
->n_slots
[R_8
] += diff
->n_slots
[R_8
];
2048 big
->n_slots
[R_16
] += diff
->n_slots
[R_16
];
2049 big
->n_slots
[R_32
] += diff
->n_slots
[R_32
];
2050 big
->local_n_slots
+= diff
->local_n_slots
;
2053 /* DIFF is empty. */
2055 BFD_ASSERT (diff
->n_slots
[R_8
] == 0);
2056 BFD_ASSERT (diff
->n_slots
[R_16
] == 0);
2057 BFD_ASSERT (diff
->n_slots
[R_32
] == 0);
2058 BFD_ASSERT (diff
->local_n_slots
== 0);
2061 BFD_ASSERT (!elf_m68k_hash_table (info
)->allow_multigot_p
2062 || ((big
->n_slots
[R_8
]
2063 <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
2064 && (big
->n_slots
[R_16
]
2065 <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
))));
2070 struct elf_m68k_finalize_got_offsets_arg
2072 /* Ranges of the offsets for GOT entries.
2073 R_x entries receive offsets between offset1[R_x] and offset2[R_x].
2074 R_x is R_8, R_16 and R_32. */
2078 /* Mapping from global symndx to global symbols.
2079 This is used to build lists of got entries for global symbols. */
2080 struct elf_m68k_link_hash_entry
**symndx2h
;
2082 bfd_vma n_ldm_entries
;
2085 /* Assign ENTRY an offset. Build list of GOT entries for global symbols
2089 elf_m68k_finalize_got_offsets_1 (void **entry_ptr
, void *_arg
)
2091 struct elf_m68k_got_entry
*entry
;
2092 struct elf_m68k_finalize_got_offsets_arg
*arg
;
2094 enum elf_m68k_got_offset_size got_offset_size
;
2097 entry
= (struct elf_m68k_got_entry
*) *entry_ptr
;
2098 arg
= (struct elf_m68k_finalize_got_offsets_arg
*) _arg
;
2100 /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
2101 BFD_ASSERT (entry
->u
.s1
.refcount
== 0);
2103 /* Get GOT offset size for the entry . */
2104 got_offset_size
= elf_m68k_reloc_got_offset_size (entry
->key_
.type
);
2106 /* Calculate entry size in bytes. */
2107 entry_size
= 4 * elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
2109 /* Check if we should switch to negative range of the offsets. */
2110 if (arg
->offset1
[got_offset_size
] + entry_size
2111 > arg
->offset2
[got_offset_size
])
2113 /* Verify that this is the only switch to negative range for
2114 got_offset_size. If this assertion fails, then we've miscalculated
2115 range for got_offset_size entries in
2116 elf_m68k_finalize_got_offsets. */
2117 BFD_ASSERT (arg
->offset2
[got_offset_size
]
2118 != arg
->offset2
[-(int) got_offset_size
- 1]);
2121 arg
->offset1
[got_offset_size
] = arg
->offset1
[-(int) got_offset_size
- 1];
2122 arg
->offset2
[got_offset_size
] = arg
->offset2
[-(int) got_offset_size
- 1];
2124 /* Verify that now we have enough room for the entry. */
2125 BFD_ASSERT (arg
->offset1
[got_offset_size
] + entry_size
2126 <= arg
->offset2
[got_offset_size
]);
2129 /* Assign offset to entry. */
2130 entry
->u
.s2
.offset
= arg
->offset1
[got_offset_size
];
2131 arg
->offset1
[got_offset_size
] += entry_size
;
2133 if (entry
->key_
.bfd
== NULL
)
2134 /* Hook up this entry into the list of got_entries of H. */
2136 struct elf_m68k_link_hash_entry
*h
;
2138 h
= arg
->symndx2h
[entry
->key_
.symndx
];
2141 entry
->u
.s2
.next
= h
->glist
;
2145 /* This should be the entry for TLS_LDM relocation then. */
2147 BFD_ASSERT ((elf_m68k_reloc_got_type (entry
->key_
.type
)
2149 && entry
->key_
.symndx
== 0);
2151 ++arg
->n_ldm_entries
;
2155 /* This entry is for local symbol. */
2156 entry
->u
.s2
.next
= NULL
;
2161 /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
2162 should use negative offsets.
2163 Build list of GOT entries for global symbols along the way.
2164 SYMNDX2H is mapping from global symbol indices to actual
2166 Return offset at which next GOT should start. */
2169 elf_m68k_finalize_got_offsets (struct elf_m68k_got
*got
,
2170 bfd_boolean use_neg_got_offsets_p
,
2171 struct elf_m68k_link_hash_entry
**symndx2h
,
2172 bfd_vma
*final_offset
, bfd_vma
*n_ldm_entries
)
2174 struct elf_m68k_finalize_got_offsets_arg arg_
;
2175 bfd_vma offset1_
[2 * R_LAST
];
2176 bfd_vma offset2_
[2 * R_LAST
];
2178 bfd_vma start_offset
;
2180 BFD_ASSERT (got
->offset
!= (bfd_vma
) -1);
2182 /* We set entry offsets relative to the .got section (and not the
2183 start of a particular GOT), so that we can use them in
2184 finish_dynamic_symbol without needing to know the GOT which they come
2187 /* Put offset1 in the middle of offset1_, same for offset2. */
2188 arg_
.offset1
= offset1_
+ R_LAST
;
2189 arg_
.offset2
= offset2_
+ R_LAST
;
2191 start_offset
= got
->offset
;
2193 if (use_neg_got_offsets_p
)
2194 /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
2195 i
= -(int) R_32
- 1;
2197 /* Setup positives ranges for R_8, R_16 and R_32. */
2200 for (; i
<= (int) R_32
; ++i
)
2205 /* Set beginning of the range of offsets I. */
2206 arg_
.offset1
[i
] = start_offset
;
2208 /* Calculate number of slots that require I offsets. */
2209 j
= (i
>= 0) ? i
: -i
- 1;
2210 n
= (j
>= 1) ? got
->n_slots
[j
- 1] : 0;
2211 n
= got
->n_slots
[j
] - n
;
2213 if (use_neg_got_offsets_p
&& n
!= 0)
2216 /* We first fill the positive side of the range, so we might
2217 end up with one empty slot at that side when we can't fit
2218 whole 2-slot entry. Account for that at negative side of
2219 the interval with one additional entry. */
2222 /* When the number of slots is odd, make positive side of the
2223 range one entry bigger. */
2227 /* N is the number of slots that require I offsets.
2228 Calculate length of the range for I offsets. */
2231 /* Set end of the range. */
2232 arg_
.offset2
[i
] = start_offset
+ n
;
2234 start_offset
= arg_
.offset2
[i
];
2237 if (!use_neg_got_offsets_p
)
2238 /* Make sure that if we try to switch to negative offsets in
2239 elf_m68k_finalize_got_offsets_1, the assert therein will catch
2241 for (i
= R_8
; i
<= R_32
; ++i
)
2242 arg_
.offset2
[-i
- 1] = arg_
.offset2
[i
];
2244 /* Setup got->offset. offset1[R_8] is either in the middle or at the
2245 beginning of GOT depending on use_neg_got_offsets_p. */
2246 got
->offset
= arg_
.offset1
[R_8
];
2248 arg_
.symndx2h
= symndx2h
;
2249 arg_
.n_ldm_entries
= 0;
2251 /* Assign offsets. */
2252 htab_traverse (got
->entries
, elf_m68k_finalize_got_offsets_1
, &arg_
);
2254 /* Check offset ranges we have actually assigned. */
2255 for (i
= (int) R_8
; i
<= (int) R_32
; ++i
)
2256 BFD_ASSERT (arg_
.offset2
[i
] - arg_
.offset1
[i
] <= 4);
2258 *final_offset
= start_offset
;
2259 *n_ldm_entries
= arg_
.n_ldm_entries
;
2262 struct elf_m68k_partition_multi_got_arg
2264 /* The GOT we are adding entries to. Aka big got. */
2265 struct elf_m68k_got
*current_got
;
2267 /* Offset to assign the next CURRENT_GOT. */
2270 /* Context where memory should be allocated. */
2271 struct bfd_link_info
*info
;
2273 /* Total number of slots in the .got section.
2274 This is used to calculate size of the .got and .rela.got sections. */
2277 /* Difference in numbers of allocated slots in the .got section
2278 and necessary relocations in the .rela.got section.
2279 This is used to calculate size of the .rela.got section. */
2280 bfd_vma slots_relas_diff
;
2283 bfd_boolean error_p
;
2285 /* Mapping from global symndx to global symbols.
2286 This is used to build lists of got entries for global symbols. */
2287 struct elf_m68k_link_hash_entry
**symndx2h
;
2291 elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg
*arg
)
2293 bfd_vma n_ldm_entries
;
2295 elf_m68k_finalize_got_offsets (arg
->current_got
,
2296 (elf_m68k_hash_table (arg
->info
)
2297 ->use_neg_got_offsets_p
),
2299 &arg
->offset
, &n_ldm_entries
);
2301 arg
->n_slots
+= arg
->current_got
->n_slots
[R_32
];
2303 if (!bfd_link_pic (arg
->info
))
2304 /* If we are generating a shared object, we need to
2305 output a R_68K_RELATIVE reloc so that the dynamic
2306 linker can adjust this GOT entry. Overwise we
2307 don't need space in .rela.got for local symbols. */
2308 arg
->slots_relas_diff
+= arg
->current_got
->local_n_slots
;
2310 /* @LDM relocations require a 2-slot GOT entry, but only
2311 one relocation. Account for that. */
2312 arg
->slots_relas_diff
+= n_ldm_entries
;
2314 BFD_ASSERT (arg
->slots_relas_diff
<= arg
->n_slots
);
2318 /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2319 or start a new CURRENT_GOT. */
2322 elf_m68k_partition_multi_got_1 (void **_entry
, void *_arg
)
2324 struct elf_m68k_bfd2got_entry
*entry
;
2325 struct elf_m68k_partition_multi_got_arg
*arg
;
2326 struct elf_m68k_got
*got
;
2327 struct elf_m68k_got diff_
;
2328 struct elf_m68k_got
*diff
;
2330 entry
= (struct elf_m68k_bfd2got_entry
*) *_entry
;
2331 arg
= (struct elf_m68k_partition_multi_got_arg
*) _arg
;
2334 BFD_ASSERT (got
!= NULL
);
2335 BFD_ASSERT (got
->offset
== (bfd_vma
) -1);
2339 if (arg
->current_got
!= NULL
)
2340 /* Construct diff. */
2343 elf_m68k_init_got (diff
);
2345 if (!elf_m68k_can_merge_gots (arg
->current_got
, got
, arg
->info
, diff
))
2347 if (diff
->offset
== 0)
2348 /* Offset set to 0 in the diff_ indicates an error. */
2350 arg
->error_p
= TRUE
;
2354 if (elf_m68k_hash_table (arg
->info
)->allow_multigot_p
)
2356 elf_m68k_clear_got (diff
);
2357 /* Schedule to finish up current_got and start new one. */
2361 Merge GOTs no matter what. If big GOT overflows,
2362 we'll fail in relocate_section due to truncated relocations.
2364 ??? May be fail earlier? E.g., in can_merge_gots. */
2368 /* Diff of got against empty current_got is got itself. */
2370 /* Create empty current_got to put subsequent GOTs to. */
2371 arg
->current_got
= elf_m68k_create_empty_got (arg
->info
);
2372 if (arg
->current_got
== NULL
)
2374 arg
->error_p
= TRUE
;
2378 arg
->current_got
->offset
= arg
->offset
;
2385 if (!elf_m68k_merge_gots (arg
->current_got
, diff
, arg
->info
))
2387 arg
->error_p
= TRUE
;
2391 /* Now we can free GOT. */
2392 elf_m68k_clear_got (got
);
2394 entry
->got
= arg
->current_got
;
2398 /* Finish up current_got. */
2399 elf_m68k_partition_multi_got_2 (arg
);
2401 /* Schedule to start a new current_got. */
2402 arg
->current_got
= NULL
;
2405 if (!elf_m68k_partition_multi_got_1 (_entry
, _arg
))
2407 BFD_ASSERT (arg
->error_p
);
2414 elf_m68k_clear_got (diff
);
2416 return !arg
->error_p
;
2419 /* Helper function to build symndx2h mapping. */
2422 elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry
*_h
,
2425 struct elf_m68k_link_hash_entry
*h
;
2427 h
= elf_m68k_hash_entry (_h
);
2429 if (h
->got_entry_key
!= 0)
2430 /* H has at least one entry in the GOT. */
2432 struct elf_m68k_partition_multi_got_arg
*arg
;
2434 arg
= (struct elf_m68k_partition_multi_got_arg
*) _arg
;
2436 BFD_ASSERT (arg
->symndx2h
[h
->got_entry_key
] == NULL
);
2437 arg
->symndx2h
[h
->got_entry_key
] = h
;
2443 /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2444 lists of GOT entries for global symbols.
2445 Calculate sizes of .got and .rela.got sections. */
2448 elf_m68k_partition_multi_got (struct bfd_link_info
*info
)
2450 struct elf_m68k_multi_got
*multi_got
;
2451 struct elf_m68k_partition_multi_got_arg arg_
;
2453 multi_got
= elf_m68k_multi_got (info
);
2455 arg_
.current_got
= NULL
;
2459 arg_
.slots_relas_diff
= 0;
2460 arg_
.error_p
= FALSE
;
2462 if (multi_got
->bfd2got
!= NULL
)
2464 /* Initialize symndx2h mapping. */
2466 arg_
.symndx2h
= bfd_zmalloc (multi_got
->global_symndx
2467 * sizeof (*arg_
.symndx2h
));
2468 if (arg_
.symndx2h
== NULL
)
2471 elf_link_hash_traverse (elf_hash_table (info
),
2472 elf_m68k_init_symndx2h_1
, &arg_
);
2476 htab_traverse (multi_got
->bfd2got
, elf_m68k_partition_multi_got_1
,
2480 free (arg_
.symndx2h
);
2481 arg_
.symndx2h
= NULL
;
2486 /* Finish up last current_got. */
2487 elf_m68k_partition_multi_got_2 (&arg_
);
2489 free (arg_
.symndx2h
);
2492 if (elf_hash_table (info
)->dynobj
!= NULL
)
2493 /* Set sizes of .got and .rela.got sections. */
2497 s
= elf_hash_table (info
)->sgot
;
2499 s
->size
= arg_
.offset
;
2501 BFD_ASSERT (arg_
.offset
== 0);
2503 BFD_ASSERT (arg_
.slots_relas_diff
<= arg_
.n_slots
);
2504 arg_
.n_slots
-= arg_
.slots_relas_diff
;
2506 s
= elf_hash_table (info
)->srelgot
;
2508 s
->size
= arg_
.n_slots
* sizeof (Elf32_External_Rela
);
2510 BFD_ASSERT (arg_
.n_slots
== 0);
2513 BFD_ASSERT (multi_got
->bfd2got
== NULL
);
2518 /* Copy any information related to dynamic linking from a pre-existing
2519 symbol to a newly created symbol. Also called to copy flags and
2520 other back-end info to a weakdef, in which case the symbol is not
2521 newly created and plt/got refcounts and dynamic indices should not
2525 elf_m68k_copy_indirect_symbol (struct bfd_link_info
*info
,
2526 struct elf_link_hash_entry
*_dir
,
2527 struct elf_link_hash_entry
*_ind
)
2529 struct elf_m68k_link_hash_entry
*dir
;
2530 struct elf_m68k_link_hash_entry
*ind
;
2532 _bfd_elf_link_hash_copy_indirect (info
, _dir
, _ind
);
2534 if (_ind
->root
.type
!= bfd_link_hash_indirect
)
2537 dir
= elf_m68k_hash_entry (_dir
);
2538 ind
= elf_m68k_hash_entry (_ind
);
2540 /* Any absolute non-dynamic relocations against an indirect or weak
2541 definition will be against the target symbol. */
2542 _dir
->non_got_ref
|= _ind
->non_got_ref
;
2544 /* We might have a direct symbol already having entries in the GOTs.
2545 Update its key only in case indirect symbol has GOT entries and
2546 assert that both indirect and direct symbols don't have GOT entries
2547 at the same time. */
2548 if (ind
->got_entry_key
!= 0)
2550 BFD_ASSERT (dir
->got_entry_key
== 0);
2551 /* Assert that GOTs aren't partioned yet. */
2552 BFD_ASSERT (ind
->glist
== NULL
);
2554 dir
->got_entry_key
= ind
->got_entry_key
;
2555 ind
->got_entry_key
= 0;
2559 /* Look through the relocs for a section during the first phase, and
2560 allocate space in the global offset table or procedure linkage
2564 elf_m68k_check_relocs (bfd
*abfd
,
2565 struct bfd_link_info
*info
,
2567 const Elf_Internal_Rela
*relocs
)
2570 Elf_Internal_Shdr
*symtab_hdr
;
2571 struct elf_link_hash_entry
**sym_hashes
;
2572 const Elf_Internal_Rela
*rel
;
2573 const Elf_Internal_Rela
*rel_end
;
2575 struct elf_m68k_got
*got
;
2577 if (bfd_link_relocatable (info
))
2580 dynobj
= elf_hash_table (info
)->dynobj
;
2581 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2582 sym_hashes
= elf_sym_hashes (abfd
);
2588 rel_end
= relocs
+ sec
->reloc_count
;
2589 for (rel
= relocs
; rel
< rel_end
; rel
++)
2591 unsigned long r_symndx
;
2592 struct elf_link_hash_entry
*h
;
2594 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2596 if (r_symndx
< symtab_hdr
->sh_info
)
2600 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2601 while (h
->root
.type
== bfd_link_hash_indirect
2602 || h
->root
.type
== bfd_link_hash_warning
)
2603 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2606 switch (ELF32_R_TYPE (rel
->r_info
))
2612 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2616 /* Relative GOT relocations. */
2622 /* TLS relocations. */
2624 case R_68K_TLS_GD16
:
2625 case R_68K_TLS_GD32
:
2626 case R_68K_TLS_LDM8
:
2627 case R_68K_TLS_LDM16
:
2628 case R_68K_TLS_LDM32
:
2630 case R_68K_TLS_IE16
:
2631 case R_68K_TLS_IE32
:
2633 case R_68K_TLS_TPREL32
:
2634 case R_68K_TLS_DTPREL32
:
2636 if (ELF32_R_TYPE (rel
->r_info
) == R_68K_TLS_TPREL32
2637 && bfd_link_pic (info
))
2638 /* Do the special chorus for libraries with static TLS. */
2639 info
->flags
|= DF_STATIC_TLS
;
2641 /* This symbol requires a global offset table entry. */
2645 /* Create the .got section. */
2646 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2647 if (!_bfd_elf_create_got_section (dynobj
, info
))
2653 struct elf_m68k_bfd2got_entry
*bfd2got_entry
;
2656 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
2657 abfd
, FIND_OR_CREATE
, info
);
2658 if (bfd2got_entry
== NULL
)
2661 got
= bfd2got_entry
->got
;
2662 BFD_ASSERT (got
!= NULL
);
2666 struct elf_m68k_got_entry
*got_entry
;
2668 /* Add entry to got. */
2669 got_entry
= elf_m68k_add_entry_to_got (got
, h
, abfd
,
2670 ELF32_R_TYPE (rel
->r_info
),
2672 if (got_entry
== NULL
)
2675 if (got_entry
->u
.s1
.refcount
== 1)
2677 /* Make sure this symbol is output as a dynamic symbol. */
2680 && !h
->forced_local
)
2682 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2693 /* This symbol requires a procedure linkage table entry. We
2694 actually build the entry in adjust_dynamic_symbol,
2695 because this might be a case of linking PIC code which is
2696 never referenced by a dynamic object, in which case we
2697 don't need to generate a procedure linkage table entry
2700 /* If this is a local symbol, we resolve it directly without
2701 creating a procedure linkage table entry. */
2712 /* This symbol requires a procedure linkage table entry. */
2716 /* It does not make sense to have this relocation for a
2717 local symbol. FIXME: does it? How to handle it if
2718 it does make sense? */
2719 bfd_set_error (bfd_error_bad_value
);
2723 /* Make sure this symbol is output as a dynamic symbol. */
2724 if (h
->dynindx
== -1
2725 && !h
->forced_local
)
2727 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2738 /* If we are creating a shared library and this is not a local
2739 symbol, we need to copy the reloc into the shared library.
2740 However when linking with -Bsymbolic and this is a global
2741 symbol which is defined in an object we are including in the
2742 link (i.e., DEF_REGULAR is set), then we can resolve the
2743 reloc directly. At this point we have not seen all the input
2744 files, so it is possible that DEF_REGULAR is not set now but
2745 will be set later (it is never cleared). We account for that
2746 possibility below by storing information in the
2747 pcrel_relocs_copied field of the hash table entry. */
2748 if (!(bfd_link_pic (info
)
2749 && (sec
->flags
& SEC_ALLOC
) != 0
2751 && (!SYMBOLIC_BIND (info
, h
)
2752 || h
->root
.type
== bfd_link_hash_defweak
2753 || !h
->def_regular
)))
2757 /* Make sure a plt entry is created for this symbol if
2758 it turns out to be a function defined by a dynamic
2768 /* We don't need to handle relocs into sections not going into
2769 the "real" output. */
2770 if ((sec
->flags
& SEC_ALLOC
) == 0)
2775 /* Make sure a plt entry is created for this symbol if it
2776 turns out to be a function defined by a dynamic object. */
2779 if (bfd_link_executable (info
))
2780 /* This symbol needs a non-GOT reference. */
2784 /* If we are creating a shared library, we need to copy the
2785 reloc into the shared library. */
2786 if (bfd_link_pic (info
)
2788 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
)))
2790 /* When creating a shared object, we must copy these
2791 reloc types into the output file. We create a reloc
2792 section in dynobj and make room for this reloc. */
2795 sreloc
= _bfd_elf_make_dynamic_reloc_section
2796 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
2802 if (sec
->flags
& SEC_READONLY
2803 /* Don't set DF_TEXTREL yet for PC relative
2804 relocations, they might be discarded later. */
2805 && !(ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
2806 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
2807 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
))
2808 info
->flags
|= DF_TEXTREL
;
2810 sreloc
->size
+= sizeof (Elf32_External_Rela
);
2812 /* We count the number of PC relative relocations we have
2813 entered for this symbol, so that we can discard them
2814 again if, in the -Bsymbolic case, the symbol is later
2815 defined by a regular object, or, in the normal shared
2816 case, the symbol is forced to be local. Note that this
2817 function is only called if we are using an m68kelf linker
2818 hash table, which means that h is really a pointer to an
2819 elf_m68k_link_hash_entry. */
2820 if (ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
2821 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
2822 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
)
2824 struct elf_m68k_pcrel_relocs_copied
*p
;
2825 struct elf_m68k_pcrel_relocs_copied
**head
;
2829 struct elf_m68k_link_hash_entry
*eh
2830 = elf_m68k_hash_entry (h
);
2831 head
= &eh
->pcrel_relocs_copied
;
2837 Elf_Internal_Sym
*isym
;
2839 isym
= bfd_sym_from_r_symndx (&elf_m68k_hash_table (info
)->sym_cache
,
2844 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2848 vpp
= &elf_section_data (s
)->local_dynrel
;
2849 head
= (struct elf_m68k_pcrel_relocs_copied
**) vpp
;
2852 for (p
= *head
; p
!= NULL
; p
= p
->next
)
2853 if (p
->section
== sreloc
)
2858 p
= ((struct elf_m68k_pcrel_relocs_copied
*)
2859 bfd_alloc (dynobj
, (bfd_size_type
) sizeof *p
));
2864 p
->section
= sreloc
;
2874 /* This relocation describes the C++ object vtable hierarchy.
2875 Reconstruct it for later use during GC. */
2876 case R_68K_GNU_VTINHERIT
:
2877 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2881 /* This relocation describes which C++ vtable entries are actually
2882 used. Record for later use during GC. */
2883 case R_68K_GNU_VTENTRY
:
2884 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2896 /* Return the section that should be marked against GC for a given
2900 elf_m68k_gc_mark_hook (asection
*sec
,
2901 struct bfd_link_info
*info
,
2902 Elf_Internal_Rela
*rel
,
2903 struct elf_link_hash_entry
*h
,
2904 Elf_Internal_Sym
*sym
)
2907 switch (ELF32_R_TYPE (rel
->r_info
))
2909 case R_68K_GNU_VTINHERIT
:
2910 case R_68K_GNU_VTENTRY
:
2914 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2917 /* Return the type of PLT associated with OUTPUT_BFD. */
2919 static const struct elf_m68k_plt_info
*
2920 elf_m68k_get_plt_info (bfd
*output_bfd
)
2922 unsigned int features
;
2924 features
= bfd_m68k_mach_to_features (bfd_get_mach (output_bfd
));
2925 if (features
& cpu32
)
2926 return &elf_cpu32_plt_info
;
2927 if (features
& mcfisa_b
)
2928 return &elf_isab_plt_info
;
2929 if (features
& mcfisa_c
)
2930 return &elf_isac_plt_info
;
2931 return &elf_m68k_plt_info
;
2934 /* This function is called after all the input files have been read,
2935 and the input sections have been assigned to output sections.
2936 It's a convenient place to determine the PLT style. */
2939 elf_m68k_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2941 /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
2943 if (!elf_m68k_partition_multi_got (info
))
2946 elf_m68k_hash_table (info
)->plt_info
= elf_m68k_get_plt_info (output_bfd
);
2950 /* Adjust a symbol defined by a dynamic object and referenced by a
2951 regular object. The current definition is in some section of the
2952 dynamic object, but we're not including those sections. We have to
2953 change the definition to something the rest of the link can
2957 elf_m68k_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2958 struct elf_link_hash_entry
*h
)
2960 struct elf_m68k_link_hash_table
*htab
;
2964 htab
= elf_m68k_hash_table (info
);
2965 dynobj
= htab
->root
.dynobj
;
2967 /* Make sure we know what is going on here. */
2968 BFD_ASSERT (dynobj
!= NULL
2973 && !h
->def_regular
)));
2975 /* If this is a function, put it in the procedure linkage table. We
2976 will fill in the contents of the procedure linkage table later,
2977 when we know the address of the .got section. */
2978 if (h
->type
== STT_FUNC
2981 if ((h
->plt
.refcount
<= 0
2982 || SYMBOL_CALLS_LOCAL (info
, h
)
2983 || ((ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2984 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
2985 && h
->root
.type
== bfd_link_hash_undefweak
))
2986 /* We must always create the plt entry if it was referenced
2987 by a PLTxxO relocation. In this case we already recorded
2988 it as a dynamic symbol. */
2989 && h
->dynindx
== -1)
2991 /* This case can occur if we saw a PLTxx reloc in an input
2992 file, but the symbol was never referred to by a dynamic
2993 object, or if all references were garbage collected. In
2994 such a case, we don't actually need to build a procedure
2995 linkage table, and we can just do a PCxx reloc instead. */
2996 h
->plt
.offset
= (bfd_vma
) -1;
3001 /* Make sure this symbol is output as a dynamic symbol. */
3002 if (h
->dynindx
== -1
3003 && !h
->forced_local
)
3005 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3009 s
= htab
->root
.splt
;
3010 BFD_ASSERT (s
!= NULL
);
3012 /* If this is the first .plt entry, make room for the special
3015 s
->size
= htab
->plt_info
->size
;
3017 /* If this symbol is not defined in a regular file, and we are
3018 not generating a shared library, then set the symbol to this
3019 location in the .plt. This is required to make function
3020 pointers compare as equal between the normal executable and
3021 the shared library. */
3022 if (!bfd_link_pic (info
)
3025 h
->root
.u
.def
.section
= s
;
3026 h
->root
.u
.def
.value
= s
->size
;
3029 h
->plt
.offset
= s
->size
;
3031 /* Make room for this entry. */
3032 s
->size
+= htab
->plt_info
->size
;
3034 /* We also need to make an entry in the .got.plt section, which
3035 will be placed in the .got section by the linker script. */
3036 s
= htab
->root
.sgotplt
;
3037 BFD_ASSERT (s
!= NULL
);
3040 /* We also need to make an entry in the .rela.plt section. */
3041 s
= htab
->root
.srelplt
;
3042 BFD_ASSERT (s
!= NULL
);
3043 s
->size
+= sizeof (Elf32_External_Rela
);
3048 /* Reinitialize the plt offset now that it is not used as a reference
3050 h
->plt
.offset
= (bfd_vma
) -1;
3052 /* If this is a weak symbol, and there is a real definition, the
3053 processor independent code will have arranged for us to see the
3054 real definition first, and we can just use the same value. */
3055 if (h
->is_weakalias
)
3057 struct elf_link_hash_entry
*def
= weakdef (h
);
3058 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
3059 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
3060 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
3064 /* This is a reference to a symbol defined by a dynamic object which
3065 is not a function. */
3067 /* If we are creating a shared library, we must presume that the
3068 only references to the symbol are via the global offset table.
3069 For such cases we need not do anything here; the relocations will
3070 be handled correctly by relocate_section. */
3071 if (bfd_link_pic (info
))
3074 /* If there are no references to this symbol that do not use the
3075 GOT, we don't need to generate a copy reloc. */
3076 if (!h
->non_got_ref
)
3079 /* We must allocate the symbol in our .dynbss section, which will
3080 become part of the .bss section of the executable. There will be
3081 an entry for this symbol in the .dynsym section. The dynamic
3082 object will contain position independent code, so all references
3083 from the dynamic object to this symbol will go through the global
3084 offset table. The dynamic linker will use the .dynsym entry to
3085 determine the address it must put in the global offset table, so
3086 both the dynamic object and the regular object will refer to the
3087 same memory location for the variable. */
3089 s
= bfd_get_linker_section (dynobj
, ".dynbss");
3090 BFD_ASSERT (s
!= NULL
);
3092 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3093 copy the initial value out of the dynamic object and into the
3094 runtime process image. We need to remember the offset into the
3095 .rela.bss section we are going to use. */
3096 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3100 srel
= bfd_get_linker_section (dynobj
, ".rela.bss");
3101 BFD_ASSERT (srel
!= NULL
);
3102 srel
->size
+= sizeof (Elf32_External_Rela
);
3106 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3109 /* Set the sizes of the dynamic sections. */
3112 elf_m68k_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3113 struct bfd_link_info
*info
)
3119 dynobj
= elf_hash_table (info
)->dynobj
;
3120 BFD_ASSERT (dynobj
!= NULL
);
3122 if (elf_hash_table (info
)->dynamic_sections_created
)
3124 /* Set the contents of the .interp section to the interpreter. */
3125 if (bfd_link_executable (info
) && !info
->nointerp
)
3127 s
= bfd_get_linker_section (dynobj
, ".interp");
3128 BFD_ASSERT (s
!= NULL
);
3129 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3130 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3135 /* We may have created entries in the .rela.got section.
3136 However, if we are not creating the dynamic sections, we will
3137 not actually use these entries. Reset the size of .rela.got,
3138 which will cause it to get stripped from the output file
3140 s
= elf_hash_table (info
)->srelgot
;
3145 /* If this is a -Bsymbolic shared link, then we need to discard all
3146 PC relative relocs against symbols defined in a regular object.
3147 For the normal shared case we discard the PC relative relocs
3148 against symbols that have become local due to visibility changes.
3149 We allocated space for them in the check_relocs routine, but we
3150 will not fill them in in the relocate_section routine. */
3151 if (bfd_link_pic (info
))
3152 elf_link_hash_traverse (elf_hash_table (info
),
3153 elf_m68k_discard_copies
,
3156 /* The check_relocs and adjust_dynamic_symbol entry points have
3157 determined the sizes of the various dynamic sections. Allocate
3160 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3164 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3167 /* It's OK to base decisions on the section name, because none
3168 of the dynobj section names depend upon the input files. */
3169 name
= bfd_section_name (s
);
3171 if (strcmp (name
, ".plt") == 0)
3173 /* Remember whether there is a PLT. */
3176 else if (CONST_STRNEQ (name
, ".rela"))
3182 /* We use the reloc_count field as a counter if we need
3183 to copy relocs into the output file. */
3187 else if (! CONST_STRNEQ (name
, ".got")
3188 && strcmp (name
, ".dynbss") != 0)
3190 /* It's not one of our sections, so don't allocate space. */
3196 /* If we don't need this section, strip it from the
3197 output file. This is mostly to handle .rela.bss and
3198 .rela.plt. We must create both sections in
3199 create_dynamic_sections, because they must be created
3200 before the linker maps input sections to output
3201 sections. The linker does that before
3202 adjust_dynamic_symbol is called, and it is that
3203 function which decides whether anything needs to go
3204 into these sections. */
3205 s
->flags
|= SEC_EXCLUDE
;
3209 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3212 /* Allocate memory for the section contents. */
3213 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3214 Unused entries should be reclaimed before the section's contents
3215 are written out, but at the moment this does not happen. Thus in
3216 order to prevent writing out garbage, we initialise the section's
3217 contents to zero. */
3218 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3219 if (s
->contents
== NULL
)
3223 return _bfd_elf_add_dynamic_tags (output_bfd
, info
, relocs
);
3226 /* This function is called via elf_link_hash_traverse if we are
3227 creating a shared object. In the -Bsymbolic case it discards the
3228 space allocated to copy PC relative relocs against symbols which
3229 are defined in regular objects. For the normal shared case, it
3230 discards space for pc-relative relocs that have become local due to
3231 symbol visibility changes. We allocated space for them in the
3232 check_relocs routine, but we won't fill them in in the
3233 relocate_section routine.
3235 We also check whether any of the remaining relocations apply
3236 against a readonly section, and set the DF_TEXTREL flag in this
3240 elf_m68k_discard_copies (struct elf_link_hash_entry
*h
,
3243 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3244 struct elf_m68k_pcrel_relocs_copied
*s
;
3246 if (!SYMBOL_CALLS_LOCAL (info
, h
))
3248 if ((info
->flags
& DF_TEXTREL
) == 0)
3250 /* Look for relocations against read-only sections. */
3251 for (s
= elf_m68k_hash_entry (h
)->pcrel_relocs_copied
;
3254 if ((s
->section
->flags
& SEC_READONLY
) != 0)
3256 info
->flags
|= DF_TEXTREL
;
3261 /* Make sure undefined weak symbols are output as a dynamic symbol
3264 && h
->root
.type
== bfd_link_hash_undefweak
3265 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3267 && !h
->forced_local
)
3269 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3276 for (s
= elf_m68k_hash_entry (h
)->pcrel_relocs_copied
;
3279 s
->section
->size
-= s
->count
* sizeof (Elf32_External_Rela
);
3285 /* Install relocation RELA. */
3288 elf_m68k_install_rela (bfd
*output_bfd
,
3290 Elf_Internal_Rela
*rela
)
3294 loc
= srela
->contents
;
3295 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3296 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
3299 /* Find the base offsets for thread-local storage in this object,
3300 for GD/LD and IE/LE respectively. */
3302 #define DTP_OFFSET 0x8000
3303 #define TP_OFFSET 0x7000
3306 dtpoff_base (struct bfd_link_info
*info
)
3308 /* If tls_sec is NULL, we should have signalled an error already. */
3309 if (elf_hash_table (info
)->tls_sec
== NULL
)
3311 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
3315 tpoff_base (struct bfd_link_info
*info
)
3317 /* If tls_sec is NULL, we should have signalled an error already. */
3318 if (elf_hash_table (info
)->tls_sec
== NULL
)
3320 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
3323 /* Output necessary relocation to handle a symbol during static link.
3324 This function is called from elf_m68k_relocate_section. */
3327 elf_m68k_init_got_entry_static (struct bfd_link_info
*info
,
3329 enum elf_m68k_reloc_type r_type
,
3331 bfd_vma got_entry_offset
,
3334 switch (elf_m68k_reloc_got_type (r_type
))
3337 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ got_entry_offset
);
3340 case R_68K_TLS_GD32
:
3341 /* We know the offset within the module,
3342 put it into the second GOT slot. */
3343 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3344 sgot
->contents
+ got_entry_offset
+ 4);
3347 case R_68K_TLS_LDM32
:
3348 /* Mark it as belonging to module 1, the executable. */
3349 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ got_entry_offset
);
3352 case R_68K_TLS_IE32
:
3353 bfd_put_32 (output_bfd
, relocation
- tpoff_base (info
),
3354 sgot
->contents
+ got_entry_offset
);
3362 /* Output necessary relocation to handle a local symbol
3363 during dynamic link.
3364 This function is called either from elf_m68k_relocate_section
3365 or from elf_m68k_finish_dynamic_symbol. */
3368 elf_m68k_init_got_entry_local_shared (struct bfd_link_info
*info
,
3370 enum elf_m68k_reloc_type r_type
,
3372 bfd_vma got_entry_offset
,
3376 Elf_Internal_Rela outrel
;
3378 switch (elf_m68k_reloc_got_type (r_type
))
3381 /* Emit RELATIVE relocation to initialize GOT slot
3383 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
3384 outrel
.r_addend
= relocation
;
3387 case R_68K_TLS_GD32
:
3388 /* We know the offset within the module,
3389 put it into the second GOT slot. */
3390 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3391 sgot
->contents
+ got_entry_offset
+ 4);
3394 case R_68K_TLS_LDM32
:
3395 /* We don't know the module number,
3396 create a relocation for it. */
3397 outrel
.r_info
= ELF32_R_INFO (0, R_68K_TLS_DTPMOD32
);
3398 outrel
.r_addend
= 0;
3401 case R_68K_TLS_IE32
:
3402 /* Emit TPREL relocation to initialize GOT slot
3404 outrel
.r_info
= ELF32_R_INFO (0, R_68K_TLS_TPREL32
);
3405 outrel
.r_addend
= relocation
- elf_hash_table (info
)->tls_sec
->vma
;
3412 /* Offset of the GOT entry. */
3413 outrel
.r_offset
= (sgot
->output_section
->vma
3414 + sgot
->output_offset
3415 + got_entry_offset
);
3417 /* Install one of the above relocations. */
3418 elf_m68k_install_rela (output_bfd
, srela
, &outrel
);
3420 bfd_put_32 (output_bfd
, outrel
.r_addend
, sgot
->contents
+ got_entry_offset
);
3423 /* Relocate an M68K ELF section. */
3426 elf_m68k_relocate_section (bfd
*output_bfd
,
3427 struct bfd_link_info
*info
,
3429 asection
*input_section
,
3431 Elf_Internal_Rela
*relocs
,
3432 Elf_Internal_Sym
*local_syms
,
3433 asection
**local_sections
)
3435 Elf_Internal_Shdr
*symtab_hdr
;
3436 struct elf_link_hash_entry
**sym_hashes
;
3441 struct elf_m68k_got
*got
;
3442 Elf_Internal_Rela
*rel
;
3443 Elf_Internal_Rela
*relend
;
3445 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3446 sym_hashes
= elf_sym_hashes (input_bfd
);
3456 relend
= relocs
+ input_section
->reloc_count
;
3457 for (; rel
< relend
; rel
++)
3460 reloc_howto_type
*howto
;
3461 unsigned long r_symndx
;
3462 struct elf_link_hash_entry
*h
;
3463 Elf_Internal_Sym
*sym
;
3466 bfd_boolean unresolved_reloc
;
3467 bfd_reloc_status_type r
;
3468 bfd_boolean resolved_to_zero
;
3470 r_type
= ELF32_R_TYPE (rel
->r_info
);
3471 if (r_type
< 0 || r_type
>= (int) R_68K_max
)
3473 bfd_set_error (bfd_error_bad_value
);
3476 howto
= howto_table
+ r_type
;
3478 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3483 unresolved_reloc
= FALSE
;
3485 if (r_symndx
< symtab_hdr
->sh_info
)
3487 sym
= local_syms
+ r_symndx
;
3488 sec
= local_sections
[r_symndx
];
3489 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
3493 bfd_boolean warned
, ignored
;
3495 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3496 r_symndx
, symtab_hdr
, sym_hashes
,
3498 unresolved_reloc
, warned
, ignored
);
3501 if (sec
!= NULL
&& discarded_section (sec
))
3502 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3503 rel
, 1, relend
, howto
, 0, contents
);
3505 if (bfd_link_relocatable (info
))
3508 resolved_to_zero
= (h
!= NULL
3509 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
3516 /* Relocation is to the address of the entry for this symbol
3517 in the global offset table. */
3519 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3521 if (elf_m68k_hash_table (info
)->local_gp_p
)
3523 bfd_vma sgot_output_offset
;
3526 sgot
= elf_hash_table (info
)->sgot
;
3529 sgot_output_offset
= sgot
->output_offset
;
3531 /* In this case we have a reference to
3532 _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3534 ??? Issue a warning? */
3535 sgot_output_offset
= 0;
3539 struct elf_m68k_bfd2got_entry
*bfd2got_entry
;
3542 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
3543 input_bfd
, SEARCH
, NULL
);
3545 if (bfd2got_entry
!= NULL
)
3547 got
= bfd2got_entry
->got
;
3548 BFD_ASSERT (got
!= NULL
);
3550 got_offset
= got
->offset
;
3553 /* In this case we have a reference to
3554 _GLOBAL_OFFSET_TABLE_, but no other references
3555 accessing any GOT entries.
3556 ??? Issue a warning? */
3560 got_offset
= got
->offset
;
3562 /* Adjust GOT pointer to point to the GOT
3563 assigned to input_bfd. */
3564 rel
->r_addend
+= sgot_output_offset
+ got_offset
;
3567 BFD_ASSERT (got
== NULL
|| got
->offset
== 0);
3576 case R_68K_TLS_LDM32
:
3577 case R_68K_TLS_LDM16
:
3578 case R_68K_TLS_LDM8
:
3581 case R_68K_TLS_GD16
:
3582 case R_68K_TLS_GD32
:
3585 case R_68K_TLS_IE16
:
3586 case R_68K_TLS_IE32
:
3588 /* Relocation is the offset of the entry for this symbol in
3589 the global offset table. */
3592 struct elf_m68k_got_entry_key key_
;
3596 sgot
= elf_hash_table (info
)->sgot
;
3597 BFD_ASSERT (sgot
!= NULL
);
3600 got
= elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
3601 input_bfd
, MUST_FIND
,
3604 /* Get GOT offset for this symbol. */
3605 elf_m68k_init_got_entry_key (&key_
, h
, input_bfd
, r_symndx
,
3607 off_ptr
= &elf_m68k_get_got_entry (got
, &key_
, MUST_FIND
,
3611 /* The offset must always be a multiple of 4. We use
3612 the least significant bit to record whether we have
3613 already generated the necessary reloc. */
3619 /* @TLSLDM relocations are bounded to the module, in
3620 which the symbol is defined -- not to the symbol
3622 && elf_m68k_reloc_got_type (r_type
) != R_68K_TLS_LDM32
)
3626 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3627 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
3628 bfd_link_pic (info
),
3630 || (bfd_link_pic (info
)
3631 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3632 || ((ELF_ST_VISIBILITY (h
->other
)
3633 || resolved_to_zero
)
3634 && h
->root
.type
== bfd_link_hash_undefweak
))
3636 /* This is actually a static link, or it is a
3637 -Bsymbolic link and the symbol is defined
3638 locally, or the symbol was forced to be local
3639 because of a version file. We must initialize
3640 this entry in the global offset table. Since
3641 the offset must always be a multiple of 4, we
3642 use the least significant bit to record whether
3643 we have initialized it already.
3645 When doing a dynamic link, we create a .rela.got
3646 relocation entry to initialize the value. This
3647 is done in the finish_dynamic_symbol routine. */
3649 elf_m68k_init_got_entry_static (info
,
3659 unresolved_reloc
= FALSE
;
3661 else if (bfd_link_pic (info
)) /* && h == NULL */
3662 /* Process local symbol during dynamic link. */
3664 srela
= elf_hash_table (info
)->srelgot
;
3665 BFD_ASSERT (srela
!= NULL
);
3667 elf_m68k_init_got_entry_local_shared (info
,
3677 else /* h == NULL && !bfd_link_pic (info) */
3679 elf_m68k_init_got_entry_static (info
,
3690 /* We don't use elf_m68k_reloc_got_type in the condition below
3691 because this is the only place where difference between
3692 R_68K_GOTx and R_68K_GOTxO relocations matters. */
3693 if (r_type
== R_68K_GOT32O
3694 || r_type
== R_68K_GOT16O
3695 || r_type
== R_68K_GOT8O
3696 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_GD32
3697 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_LDM32
3698 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_IE32
)
3700 /* GOT pointer is adjusted to point to the start/middle
3701 of local GOT. Adjust the offset accordingly. */
3702 BFD_ASSERT (elf_m68k_hash_table (info
)->use_neg_got_offsets_p
3703 || off
>= got
->offset
);
3705 if (elf_m68k_hash_table (info
)->local_gp_p
)
3706 relocation
= off
- got
->offset
;
3709 BFD_ASSERT (got
->offset
== 0);
3710 relocation
= sgot
->output_offset
+ off
;
3713 /* This relocation does not use the addend. */
3717 relocation
= (sgot
->output_section
->vma
+ sgot
->output_offset
3722 case R_68K_TLS_LDO32
:
3723 case R_68K_TLS_LDO16
:
3724 case R_68K_TLS_LDO8
:
3725 relocation
-= dtpoff_base (info
);
3728 case R_68K_TLS_LE32
:
3729 case R_68K_TLS_LE16
:
3731 if (bfd_link_dll (info
))
3734 /* xgettext:c-format */
3735 (_("%pB(%pA+%#" PRIx64
"): "
3736 "%s relocation not permitted in shared object"),
3737 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
3743 relocation
-= tpoff_base (info
);
3750 /* Relocation is to the entry for this symbol in the
3751 procedure linkage table. */
3753 /* Resolve a PLTxx reloc against a local symbol directly,
3754 without using the procedure linkage table. */
3758 if (h
->plt
.offset
== (bfd_vma
) -1
3759 || !elf_hash_table (info
)->dynamic_sections_created
)
3761 /* We didn't make a PLT entry for this symbol. This
3762 happens when statically linking PIC code, or when
3763 using -Bsymbolic. */
3767 splt
= elf_hash_table (info
)->splt
;
3768 BFD_ASSERT (splt
!= NULL
);
3770 relocation
= (splt
->output_section
->vma
3771 + splt
->output_offset
3773 unresolved_reloc
= FALSE
;
3779 /* Relocation is the offset of the entry for this symbol in
3780 the procedure linkage table. */
3781 BFD_ASSERT (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1);
3783 splt
= elf_hash_table (info
)->splt
;
3784 BFD_ASSERT (splt
!= NULL
);
3786 relocation
= h
->plt
.offset
;
3787 unresolved_reloc
= FALSE
;
3789 /* This relocation does not use the addend. */
3800 if (bfd_link_pic (info
)
3801 && r_symndx
!= STN_UNDEF
3802 && (input_section
->flags
& SEC_ALLOC
) != 0
3804 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3805 && !resolved_to_zero
)
3806 || h
->root
.type
!= bfd_link_hash_undefweak
)
3807 && ((r_type
!= R_68K_PC8
3808 && r_type
!= R_68K_PC16
3809 && r_type
!= R_68K_PC32
)
3810 || !SYMBOL_CALLS_LOCAL (info
, h
)))
3812 Elf_Internal_Rela outrel
;
3814 bfd_boolean skip
, relocate
;
3816 /* When generating a shared object, these relocations
3817 are copied into the output file to be resolved at run
3824 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3826 if (outrel
.r_offset
== (bfd_vma
) -1)
3828 else if (outrel
.r_offset
== (bfd_vma
) -2)
3829 skip
= TRUE
, relocate
= TRUE
;
3830 outrel
.r_offset
+= (input_section
->output_section
->vma
3831 + input_section
->output_offset
);
3834 memset (&outrel
, 0, sizeof outrel
);
3837 && (r_type
== R_68K_PC8
3838 || r_type
== R_68K_PC16
3839 || r_type
== R_68K_PC32
3840 || !bfd_link_pic (info
)
3841 || !SYMBOLIC_BIND (info
, h
)
3842 || !h
->def_regular
))
3844 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3845 outrel
.r_addend
= rel
->r_addend
;
3849 /* This symbol is local, or marked to become local. */
3850 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3852 if (r_type
== R_68K_32
)
3855 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
3861 if (bfd_is_abs_section (sec
))
3863 else if (sec
== NULL
|| sec
->owner
== NULL
)
3865 bfd_set_error (bfd_error_bad_value
);
3872 /* We are turning this relocation into one
3873 against a section symbol. It would be
3874 proper to subtract the symbol's value,
3875 osec->vma, from the emitted reloc addend,
3876 but ld.so expects buggy relocs. */
3877 osec
= sec
->output_section
;
3878 indx
= elf_section_data (osec
)->dynindx
;
3881 struct elf_link_hash_table
*htab
;
3882 htab
= elf_hash_table (info
);
3883 osec
= htab
->text_index_section
;
3884 indx
= elf_section_data (osec
)->dynindx
;
3886 BFD_ASSERT (indx
!= 0);
3889 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3893 sreloc
= elf_section_data (input_section
)->sreloc
;
3897 loc
= sreloc
->contents
;
3898 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3899 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3901 /* This reloc will be computed at runtime, so there's no
3902 need to do anything now, except for R_68K_32
3903 relocations that have been turned into
3911 case R_68K_GNU_VTINHERIT
:
3912 case R_68K_GNU_VTENTRY
:
3913 /* These are no-ops in the end. */
3920 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3921 because such sections are not SEC_ALLOC and thus ld.so will
3922 not process them. */
3923 if (unresolved_reloc
3924 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3926 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3927 rel
->r_offset
) != (bfd_vma
) -1)
3930 /* xgettext:c-format */
3931 (_("%pB(%pA+%#" PRIx64
"): "
3932 "unresolvable %s relocation against symbol `%s'"),
3935 (uint64_t) rel
->r_offset
,
3937 h
->root
.root
.string
);
3941 if (r_symndx
!= STN_UNDEF
3942 && r_type
!= R_68K_NONE
3944 || h
->root
.type
== bfd_link_hash_defined
3945 || h
->root
.type
== bfd_link_hash_defweak
))
3949 sym_type
= (sym
!= NULL
) ? ELF32_ST_TYPE (sym
->st_info
) : h
->type
;
3951 if (elf_m68k_reloc_tls_p (r_type
) != (sym_type
== STT_TLS
))
3956 name
= h
->root
.root
.string
;
3959 name
= (bfd_elf_string_from_elf_section
3960 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
3961 if (name
== NULL
|| *name
== '\0')
3962 name
= bfd_section_name (sec
);
3966 ((sym_type
== STT_TLS
3967 /* xgettext:c-format */
3968 ? _("%pB(%pA+%#" PRIx64
"): %s used with TLS symbol %s")
3969 /* xgettext:c-format */
3970 : _("%pB(%pA+%#" PRIx64
"): %s used with non-TLS symbol %s")),
3973 (uint64_t) rel
->r_offset
,
3979 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3980 contents
, rel
->r_offset
,
3981 relocation
, rel
->r_addend
);
3983 if (r
!= bfd_reloc_ok
)
3988 name
= h
->root
.root
.string
;
3991 name
= bfd_elf_string_from_elf_section (input_bfd
,
3992 symtab_hdr
->sh_link
,
3997 name
= bfd_section_name (sec
);
4000 if (r
== bfd_reloc_overflow
)
4001 (*info
->callbacks
->reloc_overflow
)
4002 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4003 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4007 /* xgettext:c-format */
4008 (_("%pB(%pA+%#" PRIx64
"): reloc against `%s': error %d"),
4009 input_bfd
, input_section
,
4010 (uint64_t) rel
->r_offset
, name
, (int) r
);
4019 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4020 into section SEC. */
4023 elf_m68k_install_pc32 (asection
*sec
, bfd_vma offset
, bfd_vma value
)
4025 /* Make VALUE PC-relative. */
4026 value
-= sec
->output_section
->vma
+ offset
;
4028 /* Apply any in-place addend. */
4029 value
+= bfd_get_32 (sec
->owner
, sec
->contents
+ offset
);
4031 bfd_put_32 (sec
->owner
, value
, sec
->contents
+ offset
);
4034 /* Finish up dynamic symbol handling. We set the contents of various
4035 dynamic sections here. */
4038 elf_m68k_finish_dynamic_symbol (bfd
*output_bfd
,
4039 struct bfd_link_info
*info
,
4040 struct elf_link_hash_entry
*h
,
4041 Elf_Internal_Sym
*sym
)
4045 dynobj
= elf_hash_table (info
)->dynobj
;
4047 if (h
->plt
.offset
!= (bfd_vma
) -1)
4049 const struct elf_m68k_plt_info
*plt_info
;
4055 Elf_Internal_Rela rela
;
4058 /* This symbol has an entry in the procedure linkage table. Set
4061 BFD_ASSERT (h
->dynindx
!= -1);
4063 plt_info
= elf_m68k_hash_table (info
)->plt_info
;
4064 splt
= elf_hash_table (info
)->splt
;
4065 sgot
= elf_hash_table (info
)->sgotplt
;
4066 srela
= elf_hash_table (info
)->srelplt
;
4067 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
4069 /* Get the index in the procedure linkage table which
4070 corresponds to this symbol. This is the index of this symbol
4071 in all the symbols for which we are making plt entries. The
4072 first entry in the procedure linkage table is reserved. */
4073 plt_index
= (h
->plt
.offset
/ plt_info
->size
) - 1;
4075 /* Get the offset into the .got table of the entry that
4076 corresponds to this function. Each .got entry is 4 bytes.
4077 The first three are reserved. */
4078 got_offset
= (plt_index
+ 3) * 4;
4080 memcpy (splt
->contents
+ h
->plt
.offset
,
4081 plt_info
->symbol_entry
,
4084 elf_m68k_install_pc32 (splt
, h
->plt
.offset
+ plt_info
->symbol_relocs
.got
,
4085 (sgot
->output_section
->vma
4086 + sgot
->output_offset
4089 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
4092 + plt_info
->symbol_resolve_entry
+ 2);
4094 elf_m68k_install_pc32 (splt
, h
->plt
.offset
+ plt_info
->symbol_relocs
.plt
,
4095 splt
->output_section
->vma
);
4097 /* Fill in the entry in the global offset table. */
4098 bfd_put_32 (output_bfd
,
4099 (splt
->output_section
->vma
4100 + splt
->output_offset
4102 + plt_info
->symbol_resolve_entry
),
4103 sgot
->contents
+ got_offset
);
4105 /* Fill in the entry in the .rela.plt section. */
4106 rela
.r_offset
= (sgot
->output_section
->vma
4107 + sgot
->output_offset
4109 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_JMP_SLOT
);
4111 loc
= srela
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
4112 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4114 if (!h
->def_regular
)
4116 /* Mark the symbol as undefined, rather than as defined in
4117 the .plt section. Leave the value alone. */
4118 sym
->st_shndx
= SHN_UNDEF
;
4122 if (elf_m68k_hash_entry (h
)->glist
!= NULL
)
4126 struct elf_m68k_got_entry
*got_entry
;
4128 /* This symbol has an entry in the global offset table. Set it
4131 sgot
= elf_hash_table (info
)->sgot
;
4132 srela
= elf_hash_table (info
)->srelgot
;
4133 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
4135 got_entry
= elf_m68k_hash_entry (h
)->glist
;
4137 while (got_entry
!= NULL
)
4139 enum elf_m68k_reloc_type r_type
;
4140 bfd_vma got_entry_offset
;
4142 r_type
= got_entry
->key_
.type
;
4143 got_entry_offset
= got_entry
->u
.s2
.offset
&~ (bfd_vma
) 1;
4145 /* If this is a -Bsymbolic link, and the symbol is defined
4146 locally, we just want to emit a RELATIVE reloc. Likewise if
4147 the symbol was forced to be local because of a version file.
4148 The entry in the global offset table already have been
4149 initialized in the relocate_section function. */
4150 if (bfd_link_pic (info
)
4151 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4155 relocation
= bfd_get_signed_32 (output_bfd
,
4157 + got_entry_offset
));
4160 switch (elf_m68k_reloc_got_type (r_type
))
4163 case R_68K_TLS_LDM32
:
4166 case R_68K_TLS_GD32
:
4167 /* The value for this relocation is actually put in
4168 the second GOT slot. */
4169 relocation
= bfd_get_signed_32 (output_bfd
,
4171 + got_entry_offset
+ 4));
4172 relocation
+= dtpoff_base (info
);
4175 case R_68K_TLS_IE32
:
4176 relocation
+= tpoff_base (info
);
4183 elf_m68k_init_got_entry_local_shared (info
,
4193 Elf_Internal_Rela rela
;
4195 /* Put zeros to GOT slots that will be initialized
4200 n_slots
= elf_m68k_reloc_got_n_slots (got_entry
->key_
.type
);
4202 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4203 (sgot
->contents
+ got_entry_offset
4208 rela
.r_offset
= (sgot
->output_section
->vma
4209 + sgot
->output_offset
4210 + got_entry_offset
);
4212 switch (elf_m68k_reloc_got_type (r_type
))
4215 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_GLOB_DAT
);
4216 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4219 case R_68K_TLS_GD32
:
4220 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_DTPMOD32
);
4221 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4224 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_DTPREL32
);
4225 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4228 case R_68K_TLS_IE32
:
4229 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_TPREL32
);
4230 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4239 got_entry
= got_entry
->u
.s2
.next
;
4246 Elf_Internal_Rela rela
;
4249 /* This symbol needs a copy reloc. Set it up. */
4251 BFD_ASSERT (h
->dynindx
!= -1
4252 && (h
->root
.type
== bfd_link_hash_defined
4253 || h
->root
.type
== bfd_link_hash_defweak
));
4255 s
= bfd_get_linker_section (dynobj
, ".rela.bss");
4256 BFD_ASSERT (s
!= NULL
);
4258 rela
.r_offset
= (h
->root
.u
.def
.value
4259 + h
->root
.u
.def
.section
->output_section
->vma
4260 + h
->root
.u
.def
.section
->output_offset
);
4261 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_COPY
);
4263 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4264 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4270 /* Finish up the dynamic sections. */
4273 elf_m68k_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
4279 dynobj
= elf_hash_table (info
)->dynobj
;
4281 sgot
= elf_hash_table (info
)->sgotplt
;
4282 BFD_ASSERT (sgot
!= NULL
);
4283 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4285 if (elf_hash_table (info
)->dynamic_sections_created
)
4288 Elf32_External_Dyn
*dyncon
, *dynconend
;
4290 splt
= elf_hash_table (info
)->splt
;
4291 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
4293 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4294 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4295 for (; dyncon
< dynconend
; dyncon
++)
4297 Elf_Internal_Dyn dyn
;
4300 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4308 s
= elf_hash_table (info
)->sgotplt
;
4311 s
= elf_hash_table (info
)->srelplt
;
4313 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4314 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4318 s
= elf_hash_table (info
)->srelplt
;
4319 dyn
.d_un
.d_val
= s
->size
;
4320 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4325 /* Fill in the first entry in the procedure linkage table. */
4328 const struct elf_m68k_plt_info
*plt_info
;
4330 plt_info
= elf_m68k_hash_table (info
)->plt_info
;
4331 memcpy (splt
->contents
, plt_info
->plt0_entry
, plt_info
->size
);
4333 elf_m68k_install_pc32 (splt
, plt_info
->plt0_relocs
.got4
,
4334 (sgot
->output_section
->vma
4335 + sgot
->output_offset
4338 elf_m68k_install_pc32 (splt
, plt_info
->plt0_relocs
.got8
,
4339 (sgot
->output_section
->vma
4340 + sgot
->output_offset
4343 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
4348 /* Fill in the first three entries in the global offset table. */
4352 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4354 bfd_put_32 (output_bfd
,
4355 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4357 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4358 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4361 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4366 /* Given a .data section and a .emreloc in-memory section, store
4367 relocation information into the .emreloc section which can be
4368 used at runtime to relocate the section. This is called by the
4369 linker when the --embedded-relocs switch is used. This is called
4370 after the add_symbols entry point has been called for all the
4371 objects, and before the final_link entry point is called. */
4374 bfd_m68k_elf32_create_embedded_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4375 asection
*datasec
, asection
*relsec
,
4378 Elf_Internal_Shdr
*symtab_hdr
;
4379 Elf_Internal_Sym
*isymbuf
= NULL
;
4380 Elf_Internal_Rela
*internal_relocs
= NULL
;
4381 Elf_Internal_Rela
*irel
, *irelend
;
4385 BFD_ASSERT (! bfd_link_relocatable (info
));
4389 if (datasec
->reloc_count
== 0)
4392 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4394 /* Get a copy of the native relocations. */
4395 internal_relocs
= (_bfd_elf_link_read_relocs
4396 (abfd
, datasec
, NULL
, (Elf_Internal_Rela
*) NULL
,
4397 info
->keep_memory
));
4398 if (internal_relocs
== NULL
)
4401 amt
= (bfd_size_type
) datasec
->reloc_count
* 12;
4402 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, amt
);
4403 if (relsec
->contents
== NULL
)
4406 p
= relsec
->contents
;
4408 irelend
= internal_relocs
+ datasec
->reloc_count
;
4409 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
4411 asection
*targetsec
;
4413 /* We are going to write a four byte longword into the runtime
4414 reloc section. The longword will be the address in the data
4415 section which must be relocated. It is followed by the name
4416 of the target section NUL-padded or truncated to 8
4419 /* We can only relocate absolute longword relocs at run time. */
4420 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_68K_32
)
4422 *errmsg
= _("unsupported relocation type");
4423 bfd_set_error (bfd_error_bad_value
);
4427 /* Get the target section referred to by the reloc. */
4428 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
4430 /* A local symbol. */
4431 Elf_Internal_Sym
*isym
;
4433 /* Read this BFD's local symbols if we haven't done so already. */
4434 if (isymbuf
== NULL
)
4436 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4437 if (isymbuf
== NULL
)
4438 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
4439 symtab_hdr
->sh_info
, 0,
4441 if (isymbuf
== NULL
)
4445 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
4446 targetsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4451 struct elf_link_hash_entry
*h
;
4453 /* An external symbol. */
4454 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
4455 h
= elf_sym_hashes (abfd
)[indx
];
4456 BFD_ASSERT (h
!= NULL
);
4457 if (h
->root
.type
== bfd_link_hash_defined
4458 || h
->root
.type
== bfd_link_hash_defweak
)
4459 targetsec
= h
->root
.u
.def
.section
;
4464 bfd_put_32 (abfd
, irel
->r_offset
+ datasec
->output_offset
, p
);
4465 memset (p
+ 4, 0, 8);
4466 if (targetsec
!= NULL
)
4467 strncpy ((char *) p
+ 4, targetsec
->output_section
->name
, 8);
4470 if (symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
4472 if (elf_section_data (datasec
)->relocs
!= internal_relocs
)
4473 free (internal_relocs
);
4477 if (symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
4479 if (elf_section_data (datasec
)->relocs
!= internal_relocs
)
4480 free (internal_relocs
);
4484 /* Set target options. */
4487 bfd_elf_m68k_set_target_options (struct bfd_link_info
*info
, int got_handling
)
4489 struct elf_m68k_link_hash_table
*htab
;
4490 bfd_boolean use_neg_got_offsets_p
;
4491 bfd_boolean allow_multigot_p
;
4492 bfd_boolean local_gp_p
;
4494 switch (got_handling
)
4499 use_neg_got_offsets_p
= FALSE
;
4500 allow_multigot_p
= FALSE
;
4504 /* --got=negative. */
4506 use_neg_got_offsets_p
= TRUE
;
4507 allow_multigot_p
= FALSE
;
4511 /* --got=multigot. */
4513 use_neg_got_offsets_p
= TRUE
;
4514 allow_multigot_p
= TRUE
;
4522 htab
= elf_m68k_hash_table (info
);
4525 htab
->local_gp_p
= local_gp_p
;
4526 htab
->use_neg_got_offsets_p
= use_neg_got_offsets_p
;
4527 htab
->allow_multigot_p
= allow_multigot_p
;
4531 static enum elf_reloc_type_class
4532 elf32_m68k_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4533 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4534 const Elf_Internal_Rela
*rela
)
4536 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4538 case R_68K_RELATIVE
:
4539 return reloc_class_relative
;
4540 case R_68K_JMP_SLOT
:
4541 return reloc_class_plt
;
4543 return reloc_class_copy
;
4545 return reloc_class_normal
;
4549 /* Return address for Ith PLT stub in section PLT, for relocation REL
4550 or (bfd_vma) -1 if it should not be included. */
4553 elf_m68k_plt_sym_val (bfd_vma i
, const asection
*plt
,
4554 const arelent
*rel ATTRIBUTE_UNUSED
)
4556 return plt
->vma
+ (i
+ 1) * elf_m68k_get_plt_info (plt
->owner
)->size
;
4559 /* Support for core dump NOTE sections. */
4562 elf_m68k_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
4567 switch (note
->descsz
)
4572 case 154: /* Linux/m68k */
4574 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
4577 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 22);
4586 /* Make a ".reg/999" section. */
4587 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
4588 size
, note
->descpos
+ offset
);
4592 elf_m68k_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
4594 switch (note
->descsz
)
4599 case 124: /* Linux/m68k elf_prpsinfo. */
4600 elf_tdata (abfd
)->core
->pid
4601 = bfd_get_32 (abfd
, note
->descdata
+ 12);
4602 elf_tdata (abfd
)->core
->program
4603 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
4604 elf_tdata (abfd
)->core
->command
4605 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
4608 /* Note that for some reason, a spurious space is tacked
4609 onto the end of the args in some (at least one anyway)
4610 implementations, so strip it off if it exists. */
4612 char *command
= elf_tdata (abfd
)->core
->command
;
4613 int n
= strlen (command
);
4615 if (n
> 0 && command
[n
- 1] == ' ')
4616 command
[n
- 1] = '\0';
4622 #define TARGET_BIG_SYM m68k_elf32_vec
4623 #define TARGET_BIG_NAME "elf32-m68k"
4624 #define ELF_MACHINE_CODE EM_68K
4625 #define ELF_MAXPAGESIZE 0x2000
4626 #define elf_backend_create_dynamic_sections \
4627 _bfd_elf_create_dynamic_sections
4628 #define bfd_elf32_bfd_link_hash_table_create \
4629 elf_m68k_link_hash_table_create
4630 #define bfd_elf32_bfd_final_link bfd_elf_final_link
4632 #define elf_backend_check_relocs elf_m68k_check_relocs
4633 #define elf_backend_always_size_sections \
4634 elf_m68k_always_size_sections
4635 #define elf_backend_adjust_dynamic_symbol \
4636 elf_m68k_adjust_dynamic_symbol
4637 #define elf_backend_size_dynamic_sections \
4638 elf_m68k_size_dynamic_sections
4639 #define elf_backend_final_write_processing elf_m68k_final_write_processing
4640 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4641 #define elf_backend_relocate_section elf_m68k_relocate_section
4642 #define elf_backend_finish_dynamic_symbol \
4643 elf_m68k_finish_dynamic_symbol
4644 #define elf_backend_finish_dynamic_sections \
4645 elf_m68k_finish_dynamic_sections
4646 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4647 #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4648 #define bfd_elf32_bfd_merge_private_bfd_data \
4649 elf32_m68k_merge_private_bfd_data
4650 #define bfd_elf32_bfd_set_private_flags \
4651 elf32_m68k_set_private_flags
4652 #define bfd_elf32_bfd_print_private_bfd_data \
4653 elf32_m68k_print_private_bfd_data
4654 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4655 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4656 #define elf_backend_object_p elf32_m68k_object_p
4657 #define elf_backend_grok_prstatus elf_m68k_grok_prstatus
4658 #define elf_backend_grok_psinfo elf_m68k_grok_psinfo
4660 #define elf_backend_can_gc_sections 1
4661 #define elf_backend_can_refcount 1
4662 #define elf_backend_want_got_plt 1
4663 #define elf_backend_plt_readonly 1
4664 #define elf_backend_want_plt_sym 0
4665 #define elf_backend_got_header_size 12
4666 #define elf_backend_rela_normal 1
4667 #define elf_backend_dtrel_excludes_plt 1
4669 #define elf_backend_linux_prpsinfo32_ugid16 TRUE
4671 #include "elf32-target.h"