1 /* Motorola 68k series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
29 #include "opcode/m68k.h"
31 static reloc_howto_type
*reloc_type_lookup
32 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
33 static void rtype_to_howto
34 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
35 static struct bfd_hash_entry
*elf_m68k_link_hash_newfunc
36 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
37 static struct bfd_link_hash_table
*elf_m68k_link_hash_table_create
39 static bfd_boolean elf_m68k_check_relocs
40 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
41 const Elf_Internal_Rela
*));
42 static bfd_boolean elf_m68k_adjust_dynamic_symbol
43 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
44 static bfd_boolean elf_m68k_size_dynamic_sections
45 PARAMS ((bfd
*, struct bfd_link_info
*));
46 static bfd_boolean elf_m68k_discard_copies
47 PARAMS ((struct elf_link_hash_entry
*, PTR
));
48 static bfd_boolean elf_m68k_relocate_section
49 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
50 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
51 static bfd_boolean elf_m68k_finish_dynamic_symbol
52 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
54 static bfd_boolean elf_m68k_finish_dynamic_sections
55 PARAMS ((bfd
*, struct bfd_link_info
*));
57 static bfd_boolean elf32_m68k_set_private_flags
58 PARAMS ((bfd
*, flagword
));
59 static bfd_boolean elf32_m68k_merge_private_bfd_data
60 PARAMS ((bfd
*, bfd
*));
61 static bfd_boolean elf32_m68k_print_private_bfd_data
62 PARAMS ((bfd
*, PTR
));
63 static enum elf_reloc_type_class elf32_m68k_reloc_type_class
64 PARAMS ((const Elf_Internal_Rela
*));
66 static reloc_howto_type howto_table
[] = {
67 HOWTO(R_68K_NONE
, 0, 0, 0, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_NONE", FALSE
, 0, 0x00000000,FALSE
),
68 HOWTO(R_68K_32
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_32", FALSE
, 0, 0xffffffff,FALSE
),
69 HOWTO(R_68K_16
, 0, 1,16, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_16", FALSE
, 0, 0x0000ffff,FALSE
),
70 HOWTO(R_68K_8
, 0, 0, 8, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_8", FALSE
, 0, 0x000000ff,FALSE
),
71 HOWTO(R_68K_PC32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PC32", FALSE
, 0, 0xffffffff,TRUE
),
72 HOWTO(R_68K_PC16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC16", FALSE
, 0, 0x0000ffff,TRUE
),
73 HOWTO(R_68K_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC8", FALSE
, 0, 0x000000ff,TRUE
),
74 HOWTO(R_68K_GOT32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32", FALSE
, 0, 0xffffffff,TRUE
),
75 HOWTO(R_68K_GOT16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16", FALSE
, 0, 0x0000ffff,TRUE
),
76 HOWTO(R_68K_GOT8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8", FALSE
, 0, 0x000000ff,TRUE
),
77 HOWTO(R_68K_GOT32O
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32O", FALSE
, 0, 0xffffffff,FALSE
),
78 HOWTO(R_68K_GOT16O
, 0, 1,16, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16O", FALSE
, 0, 0x0000ffff,FALSE
),
79 HOWTO(R_68K_GOT8O
, 0, 0, 8, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8O", FALSE
, 0, 0x000000ff,FALSE
),
80 HOWTO(R_68K_PLT32
, 0, 2,32, TRUE
, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32", FALSE
, 0, 0xffffffff,TRUE
),
81 HOWTO(R_68K_PLT16
, 0, 1,16, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16", FALSE
, 0, 0x0000ffff,TRUE
),
82 HOWTO(R_68K_PLT8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8", FALSE
, 0, 0x000000ff,TRUE
),
83 HOWTO(R_68K_PLT32O
, 0, 2,32, FALSE
,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32O", FALSE
, 0, 0xffffffff,FALSE
),
84 HOWTO(R_68K_PLT16O
, 0, 1,16, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16O", FALSE
, 0, 0x0000ffff,FALSE
),
85 HOWTO(R_68K_PLT8O
, 0, 0, 8, FALSE
,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8O", FALSE
, 0, 0x000000ff,FALSE
),
86 HOWTO(R_68K_COPY
, 0, 0, 0, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_COPY", FALSE
, 0, 0xffffffff,FALSE
),
87 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
),
88 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
),
89 HOWTO(R_68K_RELATIVE
, 0, 2,32, FALSE
,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_RELATIVE", FALSE
, 0, 0xffffffff,FALSE
),
90 /* GNU extension to record C++ vtable hierarchy. */
91 HOWTO (R_68K_GNU_VTINHERIT
, /* type */
93 2, /* size (0 = byte, 1 = short, 2 = long) */
95 FALSE
, /* pc_relative */
97 complain_overflow_dont
, /* complain_on_overflow */
98 NULL
, /* special_function */
99 "R_68K_GNU_VTINHERIT", /* name */
100 FALSE
, /* partial_inplace */
104 /* GNU extension to record C++ vtable member usage. */
105 HOWTO (R_68K_GNU_VTENTRY
, /* type */
107 2, /* size (0 = byte, 1 = short, 2 = long) */
109 FALSE
, /* pc_relative */
111 complain_overflow_dont
, /* complain_on_overflow */
112 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
113 "R_68K_GNU_VTENTRY", /* name */
114 FALSE
, /* partial_inplace */
119 /* TLS general dynamic variable reference. */
120 HOWTO (R_68K_TLS_GD32
, /* type */
122 2, /* size (0 = byte, 1 = short, 2 = long) */
124 FALSE
, /* pc_relative */
126 complain_overflow_bitfield
, /* complain_on_overflow */
127 bfd_elf_generic_reloc
, /* special_function */
128 "R_68K_TLS_GD32", /* name */
129 FALSE
, /* partial_inplace */
131 0xffffffff, /* dst_mask */
132 FALSE
), /* pcrel_offset */
134 HOWTO (R_68K_TLS_GD16
, /* type */
136 1, /* size (0 = byte, 1 = short, 2 = long) */
138 FALSE
, /* pc_relative */
140 complain_overflow_signed
, /* complain_on_overflow */
141 bfd_elf_generic_reloc
, /* special_function */
142 "R_68K_TLS_GD16", /* name */
143 FALSE
, /* partial_inplace */
145 0x0000ffff, /* dst_mask */
146 FALSE
), /* pcrel_offset */
148 HOWTO (R_68K_TLS_GD8
, /* type */
150 0, /* size (0 = byte, 1 = short, 2 = long) */
152 FALSE
, /* pc_relative */
154 complain_overflow_signed
, /* complain_on_overflow */
155 bfd_elf_generic_reloc
, /* special_function */
156 "R_68K_TLS_GD8", /* name */
157 FALSE
, /* partial_inplace */
159 0x000000ff, /* dst_mask */
160 FALSE
), /* pcrel_offset */
162 /* TLS local dynamic variable reference. */
163 HOWTO (R_68K_TLS_LDM32
, /* type */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
167 FALSE
, /* pc_relative */
169 complain_overflow_bitfield
, /* complain_on_overflow */
170 bfd_elf_generic_reloc
, /* special_function */
171 "R_68K_TLS_LDM32", /* name */
172 FALSE
, /* partial_inplace */
174 0xffffffff, /* dst_mask */
175 FALSE
), /* pcrel_offset */
177 HOWTO (R_68K_TLS_LDM16
, /* type */
179 1, /* size (0 = byte, 1 = short, 2 = long) */
181 FALSE
, /* pc_relative */
183 complain_overflow_signed
, /* complain_on_overflow */
184 bfd_elf_generic_reloc
, /* special_function */
185 "R_68K_TLS_LDM16", /* name */
186 FALSE
, /* partial_inplace */
188 0x0000ffff, /* dst_mask */
189 FALSE
), /* pcrel_offset */
191 HOWTO (R_68K_TLS_LDM8
, /* type */
193 0, /* size (0 = byte, 1 = short, 2 = long) */
195 FALSE
, /* pc_relative */
197 complain_overflow_signed
, /* complain_on_overflow */
198 bfd_elf_generic_reloc
, /* special_function */
199 "R_68K_TLS_LDM8", /* name */
200 FALSE
, /* partial_inplace */
202 0x000000ff, /* dst_mask */
203 FALSE
), /* pcrel_offset */
205 HOWTO (R_68K_TLS_LDO32
, /* type */
207 2, /* size (0 = byte, 1 = short, 2 = long) */
209 FALSE
, /* pc_relative */
211 complain_overflow_bitfield
, /* complain_on_overflow */
212 bfd_elf_generic_reloc
, /* special_function */
213 "R_68K_TLS_LDO32", /* name */
214 FALSE
, /* partial_inplace */
216 0xffffffff, /* dst_mask */
217 FALSE
), /* pcrel_offset */
219 HOWTO (R_68K_TLS_LDO16
, /* type */
221 1, /* size (0 = byte, 1 = short, 2 = long) */
223 FALSE
, /* pc_relative */
225 complain_overflow_signed
, /* complain_on_overflow */
226 bfd_elf_generic_reloc
, /* special_function */
227 "R_68K_TLS_LDO16", /* name */
228 FALSE
, /* partial_inplace */
230 0x0000ffff, /* dst_mask */
231 FALSE
), /* pcrel_offset */
233 HOWTO (R_68K_TLS_LDO8
, /* type */
235 0, /* size (0 = byte, 1 = short, 2 = long) */
237 FALSE
, /* pc_relative */
239 complain_overflow_signed
, /* complain_on_overflow */
240 bfd_elf_generic_reloc
, /* special_function */
241 "R_68K_TLS_LDO8", /* name */
242 FALSE
, /* partial_inplace */
244 0x000000ff, /* dst_mask */
245 FALSE
), /* pcrel_offset */
247 /* TLS initial execution variable reference. */
248 HOWTO (R_68K_TLS_IE32
, /* type */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
252 FALSE
, /* pc_relative */
254 complain_overflow_bitfield
, /* complain_on_overflow */
255 bfd_elf_generic_reloc
, /* special_function */
256 "R_68K_TLS_IE32", /* name */
257 FALSE
, /* partial_inplace */
259 0xffffffff, /* dst_mask */
260 FALSE
), /* pcrel_offset */
262 HOWTO (R_68K_TLS_IE16
, /* type */
264 1, /* size (0 = byte, 1 = short, 2 = long) */
266 FALSE
, /* pc_relative */
268 complain_overflow_signed
, /* complain_on_overflow */
269 bfd_elf_generic_reloc
, /* special_function */
270 "R_68K_TLS_IE16", /* name */
271 FALSE
, /* partial_inplace */
273 0x0000ffff, /* dst_mask */
274 FALSE
), /* pcrel_offset */
276 HOWTO (R_68K_TLS_IE8
, /* type */
278 0, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE
, /* pc_relative */
282 complain_overflow_signed
, /* complain_on_overflow */
283 bfd_elf_generic_reloc
, /* special_function */
284 "R_68K_TLS_IE8", /* name */
285 FALSE
, /* partial_inplace */
287 0x000000ff, /* dst_mask */
288 FALSE
), /* pcrel_offset */
290 /* TLS local execution variable reference. */
291 HOWTO (R_68K_TLS_LE32
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE
, /* pc_relative */
297 complain_overflow_bitfield
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_68K_TLS_LE32", /* name */
300 FALSE
, /* partial_inplace */
302 0xffffffff, /* dst_mask */
303 FALSE
), /* pcrel_offset */
305 HOWTO (R_68K_TLS_LE16
, /* type */
307 1, /* size (0 = byte, 1 = short, 2 = long) */
309 FALSE
, /* pc_relative */
311 complain_overflow_signed
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_68K_TLS_LE16", /* name */
314 FALSE
, /* partial_inplace */
316 0x0000ffff, /* dst_mask */
317 FALSE
), /* pcrel_offset */
319 HOWTO (R_68K_TLS_LE8
, /* type */
321 0, /* size (0 = byte, 1 = short, 2 = long) */
323 FALSE
, /* pc_relative */
325 complain_overflow_signed
, /* complain_on_overflow */
326 bfd_elf_generic_reloc
, /* special_function */
327 "R_68K_TLS_LE8", /* name */
328 FALSE
, /* partial_inplace */
330 0x000000ff, /* dst_mask */
331 FALSE
), /* pcrel_offset */
333 /* TLS GD/LD dynamic relocations. */
334 HOWTO (R_68K_TLS_DTPMOD32
, /* type */
336 2, /* size (0 = byte, 1 = short, 2 = long) */
338 FALSE
, /* pc_relative */
340 complain_overflow_dont
, /* complain_on_overflow */
341 bfd_elf_generic_reloc
, /* special_function */
342 "R_68K_TLS_DTPMOD32", /* name */
343 FALSE
, /* partial_inplace */
345 0xffffffff, /* dst_mask */
346 FALSE
), /* pcrel_offset */
348 HOWTO (R_68K_TLS_DTPREL32
, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 FALSE
, /* pc_relative */
354 complain_overflow_dont
, /* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_68K_TLS_DTPREL32", /* name */
357 FALSE
, /* partial_inplace */
359 0xffffffff, /* dst_mask */
360 FALSE
), /* pcrel_offset */
362 HOWTO (R_68K_TLS_TPREL32
, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 FALSE
, /* pc_relative */
368 complain_overflow_dont
, /* complain_on_overflow */
369 bfd_elf_generic_reloc
, /* special_function */
370 "R_68K_TLS_TPREL32", /* name */
371 FALSE
, /* partial_inplace */
373 0xffffffff, /* dst_mask */
374 FALSE
), /* pcrel_offset */
378 rtype_to_howto (bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
380 unsigned int indx
= ELF32_R_TYPE (dst
->r_info
);
382 if (indx
>= (unsigned int) R_68K_max
)
384 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
388 cache_ptr
->howto
= &howto_table
[indx
];
391 #define elf_info_to_howto rtype_to_howto
395 bfd_reloc_code_real_type bfd_val
;
400 { BFD_RELOC_NONE
, R_68K_NONE
},
401 { BFD_RELOC_32
, R_68K_32
},
402 { BFD_RELOC_16
, R_68K_16
},
403 { BFD_RELOC_8
, R_68K_8
},
404 { BFD_RELOC_32_PCREL
, R_68K_PC32
},
405 { BFD_RELOC_16_PCREL
, R_68K_PC16
},
406 { BFD_RELOC_8_PCREL
, R_68K_PC8
},
407 { BFD_RELOC_32_GOT_PCREL
, R_68K_GOT32
},
408 { BFD_RELOC_16_GOT_PCREL
, R_68K_GOT16
},
409 { BFD_RELOC_8_GOT_PCREL
, R_68K_GOT8
},
410 { BFD_RELOC_32_GOTOFF
, R_68K_GOT32O
},
411 { BFD_RELOC_16_GOTOFF
, R_68K_GOT16O
},
412 { BFD_RELOC_8_GOTOFF
, R_68K_GOT8O
},
413 { BFD_RELOC_32_PLT_PCREL
, R_68K_PLT32
},
414 { BFD_RELOC_16_PLT_PCREL
, R_68K_PLT16
},
415 { BFD_RELOC_8_PLT_PCREL
, R_68K_PLT8
},
416 { BFD_RELOC_32_PLTOFF
, R_68K_PLT32O
},
417 { BFD_RELOC_16_PLTOFF
, R_68K_PLT16O
},
418 { BFD_RELOC_8_PLTOFF
, R_68K_PLT8O
},
419 { BFD_RELOC_NONE
, R_68K_COPY
},
420 { BFD_RELOC_68K_GLOB_DAT
, R_68K_GLOB_DAT
},
421 { BFD_RELOC_68K_JMP_SLOT
, R_68K_JMP_SLOT
},
422 { BFD_RELOC_68K_RELATIVE
, R_68K_RELATIVE
},
423 { BFD_RELOC_CTOR
, R_68K_32
},
424 { BFD_RELOC_VTABLE_INHERIT
, R_68K_GNU_VTINHERIT
},
425 { BFD_RELOC_VTABLE_ENTRY
, R_68K_GNU_VTENTRY
},
426 { BFD_RELOC_68K_TLS_GD32
, R_68K_TLS_GD32
},
427 { BFD_RELOC_68K_TLS_GD16
, R_68K_TLS_GD16
},
428 { BFD_RELOC_68K_TLS_GD8
, R_68K_TLS_GD8
},
429 { BFD_RELOC_68K_TLS_LDM32
, R_68K_TLS_LDM32
},
430 { BFD_RELOC_68K_TLS_LDM16
, R_68K_TLS_LDM16
},
431 { BFD_RELOC_68K_TLS_LDM8
, R_68K_TLS_LDM8
},
432 { BFD_RELOC_68K_TLS_LDO32
, R_68K_TLS_LDO32
},
433 { BFD_RELOC_68K_TLS_LDO16
, R_68K_TLS_LDO16
},
434 { BFD_RELOC_68K_TLS_LDO8
, R_68K_TLS_LDO8
},
435 { BFD_RELOC_68K_TLS_IE32
, R_68K_TLS_IE32
},
436 { BFD_RELOC_68K_TLS_IE16
, R_68K_TLS_IE16
},
437 { BFD_RELOC_68K_TLS_IE8
, R_68K_TLS_IE8
},
438 { BFD_RELOC_68K_TLS_LE32
, R_68K_TLS_LE32
},
439 { BFD_RELOC_68K_TLS_LE16
, R_68K_TLS_LE16
},
440 { BFD_RELOC_68K_TLS_LE8
, R_68K_TLS_LE8
},
443 static reloc_howto_type
*
444 reloc_type_lookup (abfd
, code
)
445 bfd
*abfd ATTRIBUTE_UNUSED
;
446 bfd_reloc_code_real_type code
;
449 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
451 if (reloc_map
[i
].bfd_val
== code
)
452 return &howto_table
[reloc_map
[i
].elf_val
];
457 static reloc_howto_type
*
458 reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
462 for (i
= 0; i
< sizeof (howto_table
) / sizeof (howto_table
[0]); i
++)
463 if (howto_table
[i
].name
!= NULL
464 && strcasecmp (howto_table
[i
].name
, r_name
) == 0)
465 return &howto_table
[i
];
470 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
471 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
472 #define ELF_ARCH bfd_arch_m68k
473 #define ELF_TARGET_ID M68K_ELF_DATA
475 /* Functions for the m68k ELF linker. */
477 /* The name of the dynamic interpreter. This is put in the .interp
480 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
482 /* Describes one of the various PLT styles. */
484 struct elf_m68k_plt_info
486 /* The size of each PLT entry. */
489 /* The template for the first PLT entry. */
490 const bfd_byte
*plt0_entry
;
492 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
493 The comments by each member indicate the value that the relocation
496 unsigned int got4
; /* .got + 4 */
497 unsigned int got8
; /* .got + 8 */
500 /* The template for a symbol's PLT entry. */
501 const bfd_byte
*symbol_entry
;
503 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
504 The comments by each member indicate the value that the relocation
507 unsigned int got
; /* the symbol's .got.plt entry */
508 unsigned int plt
; /* .plt */
511 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
512 The stub starts with "move.l #relocoffset,%d0". */
513 bfd_vma symbol_resolve_entry
;
516 /* The size in bytes of an entry in the procedure linkage table. */
518 #define PLT_ENTRY_SIZE 20
520 /* The first entry in a procedure linkage table looks like this. See
521 the SVR4 ABI m68k supplement to see how this works. */
523 static const bfd_byte elf_m68k_plt0_entry
[PLT_ENTRY_SIZE
] =
525 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
526 0, 0, 0, 2, /* + (.got + 4) - . */
527 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
528 0, 0, 0, 2, /* + (.got + 8) - . */
529 0, 0, 0, 0 /* pad out to 20 bytes. */
532 /* Subsequent entries in a procedure linkage table look like this. */
534 static const bfd_byte elf_m68k_plt_entry
[PLT_ENTRY_SIZE
] =
536 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
537 0, 0, 0, 2, /* + (.got.plt entry) - . */
538 0x2f, 0x3c, /* move.l #offset,-(%sp) */
539 0, 0, 0, 0, /* + reloc index */
540 0x60, 0xff, /* bra.l .plt */
541 0, 0, 0, 0 /* + .plt - . */
544 static const struct elf_m68k_plt_info elf_m68k_plt_info
= {
546 elf_m68k_plt0_entry
, { 4, 12 },
547 elf_m68k_plt_entry
, { 4, 16 }, 8
550 #define ISAB_PLT_ENTRY_SIZE 24
552 static const bfd_byte elf_isab_plt0_entry
[ISAB_PLT_ENTRY_SIZE
] =
554 0x20, 0x3c, /* move.l #offset,%d0 */
555 0, 0, 0, 0, /* + (.got + 4) - . */
556 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
557 0x20, 0x3c, /* move.l #offset,%d0 */
558 0, 0, 0, 0, /* + (.got + 8) - . */
559 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
560 0x4e, 0xd0, /* jmp (%a0) */
564 /* Subsequent entries in a procedure linkage table look like this. */
566 static const bfd_byte elf_isab_plt_entry
[ISAB_PLT_ENTRY_SIZE
] =
568 0x20, 0x3c, /* move.l #offset,%d0 */
569 0, 0, 0, 0, /* + (.got.plt entry) - . */
570 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
571 0x4e, 0xd0, /* jmp (%a0) */
572 0x2f, 0x3c, /* move.l #offset,-(%sp) */
573 0, 0, 0, 0, /* + reloc index */
574 0x60, 0xff, /* bra.l .plt */
575 0, 0, 0, 0 /* + .plt - . */
578 static const struct elf_m68k_plt_info elf_isab_plt_info
= {
580 elf_isab_plt0_entry
, { 2, 12 },
581 elf_isab_plt_entry
, { 2, 20 }, 12
584 #define ISAC_PLT_ENTRY_SIZE 24
586 static const bfd_byte elf_isac_plt0_entry
[ISAC_PLT_ENTRY_SIZE
] =
588 0x20, 0x3c, /* move.l #offset,%d0 */
589 0, 0, 0, 0, /* replaced with .got + 4 - . */
590 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
591 0x20, 0x3c, /* move.l #offset,%d0 */
592 0, 0, 0, 0, /* replaced with .got + 8 - . */
593 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
594 0x4e, 0xd0, /* jmp (%a0) */
598 /* Subsequent entries in a procedure linkage table look like this. */
600 static const bfd_byte elf_isac_plt_entry
[ISAC_PLT_ENTRY_SIZE
] =
602 0x20, 0x3c, /* move.l #offset,%d0 */
603 0, 0, 0, 0, /* replaced with (.got entry) - . */
604 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
605 0x4e, 0xd0, /* jmp (%a0) */
606 0x2f, 0x3c, /* move.l #offset,-(%sp) */
607 0, 0, 0, 0, /* replaced with offset into relocation table */
608 0x61, 0xff, /* bsr.l .plt */
609 0, 0, 0, 0 /* replaced with .plt - . */
612 static const struct elf_m68k_plt_info elf_isac_plt_info
= {
614 elf_isac_plt0_entry
, { 2, 12},
615 elf_isac_plt_entry
, { 2, 20 }, 12
618 #define CPU32_PLT_ENTRY_SIZE 24
619 /* Procedure linkage table entries for the cpu32 */
620 static const bfd_byte elf_cpu32_plt0_entry
[CPU32_PLT_ENTRY_SIZE
] =
622 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
623 0, 0, 0, 2, /* + (.got + 4) - . */
624 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
625 0, 0, 0, 2, /* + (.got + 8) - . */
626 0x4e, 0xd1, /* jmp %a1@ */
627 0, 0, 0, 0, /* pad out to 24 bytes. */
631 static const bfd_byte elf_cpu32_plt_entry
[CPU32_PLT_ENTRY_SIZE
] =
633 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
634 0, 0, 0, 2, /* + (.got.plt entry) - . */
635 0x4e, 0xd1, /* jmp %a1@ */
636 0x2f, 0x3c, /* move.l #offset,-(%sp) */
637 0, 0, 0, 0, /* + reloc index */
638 0x60, 0xff, /* bra.l .plt */
639 0, 0, 0, 0, /* + .plt - . */
643 static const struct elf_m68k_plt_info elf_cpu32_plt_info
= {
644 CPU32_PLT_ENTRY_SIZE
,
645 elf_cpu32_plt0_entry
, { 4, 12 },
646 elf_cpu32_plt_entry
, { 4, 18 }, 10
649 /* The m68k linker needs to keep track of the number of relocs that it
650 decides to copy in check_relocs for each symbol. This is so that it
651 can discard PC relative relocs if it doesn't need them when linking
652 with -Bsymbolic. We store the information in a field extending the
653 regular ELF linker hash table. */
655 /* This structure keeps track of the number of PC relative relocs we have
656 copied for a given symbol. */
658 struct elf_m68k_pcrel_relocs_copied
661 struct elf_m68k_pcrel_relocs_copied
*next
;
662 /* A section in dynobj. */
664 /* Number of relocs copied in this section. */
668 /* Forward declaration. */
669 struct elf_m68k_got_entry
;
671 /* m68k ELF linker hash entry. */
673 struct elf_m68k_link_hash_entry
675 struct elf_link_hash_entry root
;
677 /* Number of PC relative relocs copied for this symbol. */
678 struct elf_m68k_pcrel_relocs_copied
*pcrel_relocs_copied
;
680 /* Key to got_entries. */
681 unsigned long got_entry_key
;
683 /* List of GOT entries for this symbol. This list is build during
684 offset finalization and is used within elf_m68k_finish_dynamic_symbol
685 to traverse all GOT entries for a particular symbol.
687 ??? We could've used root.got.glist field instead, but having
688 a separate field is cleaner. */
689 struct elf_m68k_got_entry
*glist
;
692 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
694 /* Key part of GOT entry in hashtable. */
695 struct elf_m68k_got_entry_key
697 /* BFD in which this symbol was defined. NULL for global symbols. */
700 /* Symbol index. Either local symbol index or h->got_entry_key. */
701 unsigned long symndx
;
703 /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
704 R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
706 From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
707 matters. That is, we distinguish between, say, R_68K_GOT16O
708 and R_68K_GOT32O when allocating offsets, but they are considered to be
709 the same when searching got->entries. */
710 enum elf_m68k_reloc_type type
;
713 /* Size of the GOT offset suitable for relocation. */
714 enum elf_m68k_got_offset_size
{ R_8
, R_16
, R_32
, R_LAST
};
716 /* Entry of the GOT. */
717 struct elf_m68k_got_entry
719 /* GOT entries are put into a got->entries hashtable. This is the key. */
720 struct elf_m68k_got_entry_key key_
;
722 /* GOT entry data. We need s1 before offset finalization and s2 after. */
727 /* Number of times this entry is referenced. It is used to
728 filter out unnecessary GOT slots in elf_m68k_gc_sweep_hook. */
734 /* Offset from the start of .got section. To calculate offset relative
735 to GOT pointer one should substract got->offset from this value. */
738 /* Pointer to the next GOT entry for this global symbol.
739 Symbols have at most one entry in one GOT, but might
740 have entries in more than one GOT.
741 Root of this list is h->glist.
742 NULL for local symbols. */
743 struct elf_m68k_got_entry
*next
;
748 /* Return representative type for relocation R_TYPE.
749 This is used to avoid enumerating many relocations in comparisons,
752 static enum elf_m68k_reloc_type
753 elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type
)
757 /* In most cases R_68K_GOTx relocations require the very same
758 handling as R_68K_GOT32O relocation. In cases when we need
759 to distinguish between the two, we use explicitly compare against
772 return R_68K_TLS_GD32
;
774 case R_68K_TLS_LDM32
:
775 case R_68K_TLS_LDM16
:
777 return R_68K_TLS_LDM32
;
782 return R_68K_TLS_IE32
;
790 /* Return size of the GOT entry offset for relocation R_TYPE. */
792 static enum elf_m68k_got_offset_size
793 elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type
)
797 case R_68K_GOT32
: case R_68K_GOT16
: case R_68K_GOT8
:
798 case R_68K_GOT32O
: case R_68K_TLS_GD32
: case R_68K_TLS_LDM32
:
802 case R_68K_GOT16O
: case R_68K_TLS_GD16
: case R_68K_TLS_LDM16
:
806 case R_68K_GOT8O
: case R_68K_TLS_GD8
: case R_68K_TLS_LDM8
:
816 /* Return number of GOT entries we need to allocate in GOT for
817 relocation R_TYPE. */
820 elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type
)
822 switch (elf_m68k_reloc_got_type (r_type
))
829 case R_68K_TLS_LDM32
:
838 /* Return TRUE if relocation R_TYPE is a TLS one. */
841 elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type
)
845 case R_68K_TLS_GD32
: case R_68K_TLS_GD16
: case R_68K_TLS_GD8
:
846 case R_68K_TLS_LDM32
: case R_68K_TLS_LDM16
: case R_68K_TLS_LDM8
:
847 case R_68K_TLS_LDO32
: case R_68K_TLS_LDO16
: case R_68K_TLS_LDO8
:
848 case R_68K_TLS_IE32
: case R_68K_TLS_IE16
: case R_68K_TLS_IE8
:
849 case R_68K_TLS_LE32
: case R_68K_TLS_LE16
: case R_68K_TLS_LE8
:
850 case R_68K_TLS_DTPMOD32
: case R_68K_TLS_DTPREL32
: case R_68K_TLS_TPREL32
:
858 /* Data structure representing a single GOT. */
861 /* Hashtable of 'struct elf_m68k_got_entry's.
862 Starting size of this table is the maximum number of
863 R_68K_GOT8O entries. */
866 /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
869 n_slots[R_8] is the count of R_8 slots in this GOT.
870 n_slots[R_16] is the cumulative count of R_8 and R_16 slots
872 n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
873 in this GOT. This is the total number of slots. */
874 bfd_vma n_slots
[R_LAST
];
876 /* Number of local (entry->key_.h == NULL) slots in this GOT.
877 This is only used to properly calculate size of .rela.got section;
878 see elf_m68k_partition_multi_got. */
879 bfd_vma local_n_slots
;
881 /* Offset of this GOT relative to beginning of .got section. */
885 /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
886 struct elf_m68k_bfd2got_entry
891 /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
892 GOT structure. After partitioning several BFD's might [and often do]
893 share a single GOT. */
894 struct elf_m68k_got
*got
;
897 /* The main data structure holding all the pieces. */
898 struct elf_m68k_multi_got
900 /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
901 here, then it doesn't need a GOT (this includes the case of a BFD
902 having an empty GOT).
904 ??? This hashtable can be replaced by an array indexed by bfd->id. */
907 /* Next symndx to assign a global symbol.
908 h->got_entry_key is initialized from this counter. */
909 unsigned long global_symndx
;
912 /* m68k ELF linker hash table. */
914 struct elf_m68k_link_hash_table
916 struct elf_link_hash_table root
;
918 /* Small local sym cache. */
919 struct sym_cache sym_cache
;
921 /* The PLT format used by this link, or NULL if the format has not
923 const struct elf_m68k_plt_info
*plt_info
;
925 /* True, if GP is loaded within each function which uses it.
926 Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
927 bfd_boolean local_gp_p
;
929 /* Switch controlling use of negative offsets to double the size of GOTs. */
930 bfd_boolean use_neg_got_offsets_p
;
932 /* Switch controlling generation of multiple GOTs. */
933 bfd_boolean allow_multigot_p
;
935 /* Multi-GOT data structure. */
936 struct elf_m68k_multi_got multi_got_
;
939 /* Get the m68k ELF linker hash table from a link_info structure. */
941 #define elf_m68k_hash_table(p) \
942 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
943 == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL)
945 /* Shortcut to multi-GOT data. */
946 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
948 /* Create an entry in an m68k ELF linker hash table. */
950 static struct bfd_hash_entry
*
951 elf_m68k_link_hash_newfunc (struct bfd_hash_entry
*entry
,
952 struct bfd_hash_table
*table
,
955 struct bfd_hash_entry
*ret
= entry
;
957 /* Allocate the structure if it has not already been allocated by a
960 ret
= bfd_hash_allocate (table
,
961 sizeof (struct elf_m68k_link_hash_entry
));
965 /* Call the allocation method of the superclass. */
966 ret
= _bfd_elf_link_hash_newfunc (ret
, table
, string
);
969 elf_m68k_hash_entry (ret
)->pcrel_relocs_copied
= NULL
;
970 elf_m68k_hash_entry (ret
)->got_entry_key
= 0;
971 elf_m68k_hash_entry (ret
)->glist
= NULL
;
977 /* Create an m68k ELF linker hash table. */
979 static struct bfd_link_hash_table
*
980 elf_m68k_link_hash_table_create (bfd
*abfd
)
982 struct elf_m68k_link_hash_table
*ret
;
983 bfd_size_type amt
= sizeof (struct elf_m68k_link_hash_table
);
985 ret
= (struct elf_m68k_link_hash_table
*) bfd_malloc (amt
);
986 if (ret
== (struct elf_m68k_link_hash_table
*) NULL
)
989 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
990 elf_m68k_link_hash_newfunc
,
991 sizeof (struct elf_m68k_link_hash_entry
),
998 ret
->sym_cache
.abfd
= NULL
;
999 ret
->plt_info
= NULL
;
1000 ret
->local_gp_p
= FALSE
;
1001 ret
->use_neg_got_offsets_p
= FALSE
;
1002 ret
->allow_multigot_p
= FALSE
;
1003 ret
->multi_got_
.bfd2got
= NULL
;
1004 ret
->multi_got_
.global_symndx
= 1;
1006 return &ret
->root
.root
;
1009 /* Destruct local data. */
1012 elf_m68k_link_hash_table_free (struct bfd_link_hash_table
*_htab
)
1014 struct elf_m68k_link_hash_table
*htab
;
1016 htab
= (struct elf_m68k_link_hash_table
*) _htab
;
1018 if (htab
->multi_got_
.bfd2got
!= NULL
)
1020 htab_delete (htab
->multi_got_
.bfd2got
);
1021 htab
->multi_got_
.bfd2got
= NULL
;
1025 /* Set the right machine number. */
1028 elf32_m68k_object_p (bfd
*abfd
)
1030 unsigned int mach
= 0;
1031 unsigned features
= 0;
1032 flagword eflags
= elf_elfheader (abfd
)->e_flags
;
1034 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1036 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1038 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1042 switch (eflags
& EF_M68K_CF_ISA_MASK
)
1044 case EF_M68K_CF_ISA_A_NODIV
:
1045 features
|= mcfisa_a
;
1047 case EF_M68K_CF_ISA_A
:
1048 features
|= mcfisa_a
|mcfhwdiv
;
1050 case EF_M68K_CF_ISA_A_PLUS
:
1051 features
|= mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
;
1053 case EF_M68K_CF_ISA_B_NOUSP
:
1054 features
|= mcfisa_a
|mcfisa_b
|mcfhwdiv
;
1056 case EF_M68K_CF_ISA_B
:
1057 features
|= mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfusp
;
1059 case EF_M68K_CF_ISA_C
:
1060 features
|= mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfusp
;
1062 case EF_M68K_CF_ISA_C_NODIV
:
1063 features
|= mcfisa_a
|mcfisa_c
|mcfusp
;
1066 switch (eflags
& EF_M68K_CF_MAC_MASK
)
1068 case EF_M68K_CF_MAC
:
1071 case EF_M68K_CF_EMAC
:
1072 features
|= mcfemac
;
1075 if (eflags
& EF_M68K_CF_FLOAT
)
1079 mach
= bfd_m68k_features_to_mach (features
);
1080 bfd_default_set_arch_mach (abfd
, bfd_arch_m68k
, mach
);
1085 /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
1086 field based on the machine number. */
1089 elf_m68k_final_write_processing (bfd
*abfd
,
1090 bfd_boolean linker ATTRIBUTE_UNUSED
)
1092 int mach
= bfd_get_mach (abfd
);
1093 unsigned long e_flags
= elf_elfheader (abfd
)->e_flags
;
1097 unsigned int arch_mask
;
1099 arch_mask
= bfd_m68k_mach_to_features (mach
);
1101 if (arch_mask
& m68000
)
1102 e_flags
= EF_M68K_M68000
;
1103 else if (arch_mask
& cpu32
)
1104 e_flags
= EF_M68K_CPU32
;
1105 else if (arch_mask
& fido_a
)
1106 e_flags
= EF_M68K_FIDO
;
1110 & (mcfisa_a
| mcfisa_aa
| mcfisa_b
| mcfisa_c
| mcfhwdiv
| mcfusp
))
1113 e_flags
|= EF_M68K_CF_ISA_A_NODIV
;
1115 case mcfisa_a
| mcfhwdiv
:
1116 e_flags
|= EF_M68K_CF_ISA_A
;
1118 case mcfisa_a
| mcfisa_aa
| mcfhwdiv
| mcfusp
:
1119 e_flags
|= EF_M68K_CF_ISA_A_PLUS
;
1121 case mcfisa_a
| mcfisa_b
| mcfhwdiv
:
1122 e_flags
|= EF_M68K_CF_ISA_B_NOUSP
;
1124 case mcfisa_a
| mcfisa_b
| mcfhwdiv
| mcfusp
:
1125 e_flags
|= EF_M68K_CF_ISA_B
;
1127 case mcfisa_a
| mcfisa_c
| mcfhwdiv
| mcfusp
:
1128 e_flags
|= EF_M68K_CF_ISA_C
;
1130 case mcfisa_a
| mcfisa_c
| mcfusp
:
1131 e_flags
|= EF_M68K_CF_ISA_C_NODIV
;
1134 if (arch_mask
& mcfmac
)
1135 e_flags
|= EF_M68K_CF_MAC
;
1136 else if (arch_mask
& mcfemac
)
1137 e_flags
|= EF_M68K_CF_EMAC
;
1138 if (arch_mask
& cfloat
)
1139 e_flags
|= EF_M68K_CF_FLOAT
| EF_M68K_CFV4E
;
1141 elf_elfheader (abfd
)->e_flags
= e_flags
;
1145 /* Keep m68k-specific flags in the ELF header. */
1148 elf32_m68k_set_private_flags (abfd
, flags
)
1152 elf_elfheader (abfd
)->e_flags
= flags
;
1153 elf_flags_init (abfd
) = TRUE
;
1157 /* Merge backend specific data from an object file to the output
1158 object file when linking. */
1160 elf32_m68k_merge_private_bfd_data (ibfd
, obfd
)
1168 const bfd_arch_info_type
*arch_info
;
1170 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1171 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1174 /* Get the merged machine. This checks for incompatibility between
1175 Coldfire & non-Coldfire flags, incompability between different
1176 Coldfire ISAs, and incompability between different MAC types. */
1177 arch_info
= bfd_arch_get_compatible (ibfd
, obfd
, FALSE
);
1181 bfd_set_arch_mach (obfd
, bfd_arch_m68k
, arch_info
->mach
);
1183 in_flags
= elf_elfheader (ibfd
)->e_flags
;
1184 if (!elf_flags_init (obfd
))
1186 elf_flags_init (obfd
) = TRUE
;
1187 out_flags
= in_flags
;
1191 out_flags
= elf_elfheader (obfd
)->e_flags
;
1192 unsigned int variant_mask
;
1194 if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1196 else if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1198 else if ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1201 variant_mask
= EF_M68K_CF_ISA_MASK
;
1203 in_isa
= (in_flags
& variant_mask
);
1204 out_isa
= (out_flags
& variant_mask
);
1205 if (in_isa
> out_isa
)
1206 out_flags
^= in_isa
^ out_isa
;
1207 if (((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
1208 && (out_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1209 || ((in_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
1210 && (out_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
))
1211 out_flags
= EF_M68K_FIDO
;
1213 out_flags
|= in_flags
^ in_isa
;
1215 elf_elfheader (obfd
)->e_flags
= out_flags
;
1220 /* Display the flags field. */
1223 elf32_m68k_print_private_bfd_data (bfd
*abfd
, void * ptr
)
1225 FILE *file
= (FILE *) ptr
;
1226 flagword eflags
= elf_elfheader (abfd
)->e_flags
;
1228 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
1230 /* Print normal ELF private data. */
1231 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
1233 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1235 /* xgettext:c-format */
1236 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
1238 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
1239 fprintf (file
, " [m68000]");
1240 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
1241 fprintf (file
, " [cpu32]");
1242 else if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
1243 fprintf (file
, " [fido]");
1246 if ((eflags
& EF_M68K_ARCH_MASK
) == EF_M68K_CFV4E
)
1247 fprintf (file
, " [cfv4e]");
1249 if (eflags
& EF_M68K_CF_ISA_MASK
)
1251 char const *isa
= _("unknown");
1252 char const *mac
= _("unknown");
1253 char const *additional
= "";
1255 switch (eflags
& EF_M68K_CF_ISA_MASK
)
1257 case EF_M68K_CF_ISA_A_NODIV
:
1259 additional
= " [nodiv]";
1261 case EF_M68K_CF_ISA_A
:
1264 case EF_M68K_CF_ISA_A_PLUS
:
1267 case EF_M68K_CF_ISA_B_NOUSP
:
1269 additional
= " [nousp]";
1271 case EF_M68K_CF_ISA_B
:
1274 case EF_M68K_CF_ISA_C
:
1277 case EF_M68K_CF_ISA_C_NODIV
:
1279 additional
= " [nodiv]";
1282 fprintf (file
, " [isa %s]%s", isa
, additional
);
1284 if (eflags
& EF_M68K_CF_FLOAT
)
1285 fprintf (file
, " [float]");
1287 switch (eflags
& EF_M68K_CF_MAC_MASK
)
1292 case EF_M68K_CF_MAC
:
1295 case EF_M68K_CF_EMAC
:
1298 case EF_M68K_CF_EMAC_B
:
1303 fprintf (file
, " [%s]", mac
);
1312 /* Multi-GOT support implementation design:
1314 Multi-GOT starts in check_relocs hook. There we scan all
1315 relocations of a BFD and build a local GOT (struct elf_m68k_got)
1316 for it. If a single BFD appears to require too many GOT slots with
1317 R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1319 After check_relocs has been invoked for each input BFD, we have
1320 constructed a GOT for each input BFD.
1322 To minimize total number of GOTs required for a particular output BFD
1323 (as some environments support only 1 GOT per output object) we try
1324 to merge some of the GOTs to share an offset space. Ideally [and in most
1325 cases] we end up with a single GOT. In cases when there are too many
1326 restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1327 several GOTs, assuming the environment can handle them.
1329 Partitioning is done in elf_m68k_partition_multi_got. We start with
1330 an empty GOT and traverse bfd2got hashtable putting got_entries from
1331 local GOTs to the new 'big' one. We do that by constructing an
1332 intermediate GOT holding all the entries the local GOT has and the big
1333 GOT lacks. Then we check if there is room in the big GOT to accomodate
1334 all the entries from diff. On success we add those entries to the big
1335 GOT; on failure we start the new 'big' GOT and retry the adding of
1336 entries from the local GOT. Note that this retry will always succeed as
1337 each local GOT doesn't overflow the limits. After partitioning we
1338 end up with each bfd assigned one of the big GOTs. GOT entries in the
1339 big GOTs are initialized with GOT offsets. Note that big GOTs are
1340 positioned consequently in program space and represent a single huge GOT
1341 to the outside world.
1343 After that we get to elf_m68k_relocate_section. There we
1344 adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1345 relocations to refer to appropriate [assigned to current input_bfd]
1350 GOT entry type: We have several types of GOT entries.
1351 * R_8 type is used in entries for symbols that have at least one
1352 R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
1353 such entries in one GOT.
1354 * R_16 type is used in entries for symbols that have at least one
1355 R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1356 We can have at most 0x4000 such entries in one GOT.
1357 * R_32 type is used in all other cases. We can have as many
1358 such entries in one GOT as we'd like.
1359 When counting relocations we have to include the count of the smaller
1360 ranged relocations in the counts of the larger ranged ones in order
1361 to correctly detect overflow.
1363 Sorting the GOT: In each GOT starting offsets are assigned to
1364 R_8 entries, which are followed by R_16 entries, and
1365 R_32 entries go at the end. See finalize_got_offsets for details.
1367 Negative GOT offsets: To double usable offset range of GOTs we use
1368 negative offsets. As we assign entries with GOT offsets relative to
1369 start of .got section, the offset values are positive. They become
1370 negative only in relocate_section where got->offset value is
1371 subtracted from them.
1373 3 special GOT entries: There are 3 special GOT entries used internally
1374 by loader. These entries happen to be placed to .got.plt section,
1375 so we don't do anything about them in multi-GOT support.
1377 Memory management: All data except for hashtables
1378 multi_got->bfd2got and got->entries are allocated on
1379 elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1380 to most functions), so we don't need to care to free them. At the
1381 moment of allocation hashtables are being linked into main data
1382 structure (multi_got), all pieces of which are reachable from
1383 elf_m68k_multi_got (info). We deallocate them in
1384 elf_m68k_link_hash_table_free. */
1386 /* Initialize GOT. */
1389 elf_m68k_init_got (struct elf_m68k_got
*got
)
1391 got
->entries
= NULL
;
1392 got
->n_slots
[R_8
] = 0;
1393 got
->n_slots
[R_16
] = 0;
1394 got
->n_slots
[R_32
] = 0;
1395 got
->local_n_slots
= 0;
1396 got
->offset
= (bfd_vma
) -1;
1402 elf_m68k_clear_got (struct elf_m68k_got
*got
)
1404 if (got
->entries
!= NULL
)
1406 htab_delete (got
->entries
);
1407 got
->entries
= NULL
;
1411 /* Create and empty GOT structure. INFO is the context where memory
1412 should be allocated. */
1414 static struct elf_m68k_got
*
1415 elf_m68k_create_empty_got (struct bfd_link_info
*info
)
1417 struct elf_m68k_got
*got
;
1419 got
= bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*got
));
1423 elf_m68k_init_got (got
);
1428 /* Initialize KEY. */
1431 elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key
*key
,
1432 struct elf_link_hash_entry
*h
,
1433 const bfd
*abfd
, unsigned long symndx
,
1434 enum elf_m68k_reloc_type reloc_type
)
1436 if (elf_m68k_reloc_got_type (reloc_type
) == R_68K_TLS_LDM32
)
1437 /* All TLS_LDM relocations share a single GOT entry. */
1443 /* Global symbols are identified with their got_entry_key. */
1446 key
->symndx
= elf_m68k_hash_entry (h
)->got_entry_key
;
1447 BFD_ASSERT (key
->symndx
!= 0);
1450 /* Local symbols are identified by BFD they appear in and symndx. */
1453 key
->symndx
= symndx
;
1456 key
->type
= reloc_type
;
1459 /* Calculate hash of got_entry.
1463 elf_m68k_got_entry_hash (const void *_entry
)
1465 const struct elf_m68k_got_entry_key
*key
;
1467 key
= &((const struct elf_m68k_got_entry
*) _entry
)->key_
;
1470 + (key
->bfd
!= NULL
? (int) key
->bfd
->id
: -1)
1471 + elf_m68k_reloc_got_type (key
->type
));
1474 /* Check if two got entries are equal. */
1477 elf_m68k_got_entry_eq (const void *_entry1
, const void *_entry2
)
1479 const struct elf_m68k_got_entry_key
*key1
;
1480 const struct elf_m68k_got_entry_key
*key2
;
1482 key1
= &((const struct elf_m68k_got_entry
*) _entry1
)->key_
;
1483 key2
= &((const struct elf_m68k_got_entry
*) _entry2
)->key_
;
1485 return (key1
->bfd
== key2
->bfd
1486 && key1
->symndx
== key2
->symndx
1487 && (elf_m68k_reloc_got_type (key1
->type
)
1488 == elf_m68k_reloc_got_type (key2
->type
)));
1491 /* When using negative offsets, we allocate one extra R_8, one extra R_16
1492 and one extra R_32 slots to simplify handling of 2-slot entries during
1493 offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
1495 /* Maximal number of R_8 slots in a single GOT. */
1496 #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
1497 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1501 /* Maximal number of R_8 and R_16 slots in a single GOT. */
1502 #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
1503 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1507 /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1508 the entry cannot be found.
1509 FIND_OR_CREATE - search for an existing entry, but create new if there's
1511 MUST_FIND - search for an existing entry and assert that it exist.
1512 MUST_CREATE - assert that there's no such entry and create new one. */
1513 enum elf_m68k_get_entry_howto
1521 /* Get or create (depending on HOWTO) entry with KEY in GOT.
1522 INFO is context in which memory should be allocated (can be NULL if
1523 HOWTO is SEARCH or MUST_FIND). */
1525 static struct elf_m68k_got_entry
*
1526 elf_m68k_get_got_entry (struct elf_m68k_got
*got
,
1527 const struct elf_m68k_got_entry_key
*key
,
1528 enum elf_m68k_get_entry_howto howto
,
1529 struct bfd_link_info
*info
)
1531 struct elf_m68k_got_entry entry_
;
1532 struct elf_m68k_got_entry
*entry
;
1535 BFD_ASSERT ((info
== NULL
) == (howto
== SEARCH
|| howto
== MUST_FIND
));
1537 if (got
->entries
== NULL
)
1538 /* This is the first entry in ABFD. Initialize hashtable. */
1540 if (howto
== SEARCH
)
1543 got
->entries
= htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1545 elf_m68k_got_entry_hash
,
1546 elf_m68k_got_entry_eq
, NULL
);
1547 if (got
->entries
== NULL
)
1549 bfd_set_error (bfd_error_no_memory
);
1555 ptr
= htab_find_slot (got
->entries
, &entry_
, (howto
!= SEARCH
1556 ? INSERT
: NO_INSERT
));
1559 if (howto
== SEARCH
)
1560 /* Entry not found. */
1563 /* We're out of memory. */
1564 bfd_set_error (bfd_error_no_memory
);
1569 /* We didn't find the entry and we're asked to create a new one. */
1571 BFD_ASSERT (howto
!= MUST_FIND
&& howto
!= SEARCH
);
1573 entry
= bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*entry
));
1577 /* Initialize new entry. */
1580 entry
->u
.s1
.refcount
= 0;
1582 /* Mark the entry as not initialized. */
1583 entry
->key_
.type
= R_68K_max
;
1588 /* We found the entry. */
1590 BFD_ASSERT (howto
!= MUST_CREATE
);
1598 /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1599 Return the value to which ENTRY's type should be set. */
1601 static enum elf_m68k_reloc_type
1602 elf_m68k_update_got_entry_type (struct elf_m68k_got
*got
,
1603 enum elf_m68k_reloc_type was
,
1604 enum elf_m68k_reloc_type new_reloc
)
1606 enum elf_m68k_got_offset_size was_size
;
1607 enum elf_m68k_got_offset_size new_size
;
1610 if (was
== R_68K_max
)
1611 /* The type of the entry is not initialized yet. */
1613 /* Update all got->n_slots counters, including n_slots[R_32]. */
1620 /* !!! We, probably, should emit an error rather then fail on assert
1622 BFD_ASSERT (elf_m68k_reloc_got_type (was
)
1623 == elf_m68k_reloc_got_type (new_reloc
));
1625 was_size
= elf_m68k_reloc_got_offset_size (was
);
1628 new_size
= elf_m68k_reloc_got_offset_size (new_reloc
);
1629 n_slots
= elf_m68k_reloc_got_n_slots (new_reloc
);
1631 while (was_size
> new_size
)
1634 got
->n_slots
[was_size
] += n_slots
;
1637 if (new_reloc
> was
)
1638 /* Relocations are ordered from bigger got offset size to lesser,
1639 so choose the relocation type with lesser offset size. */
1645 /* Update GOT counters when removing an entry of type TYPE. */
1648 elf_m68k_remove_got_entry_type (struct elf_m68k_got
*got
,
1649 enum elf_m68k_reloc_type type
)
1651 enum elf_m68k_got_offset_size os
;
1654 n_slots
= elf_m68k_reloc_got_n_slots (type
);
1656 /* Decrese counter of slots with offset size corresponding to TYPE
1657 and all greater offset sizes. */
1658 for (os
= elf_m68k_reloc_got_offset_size (type
); os
<= R_32
; ++os
)
1660 BFD_ASSERT (got
->n_slots
[os
] >= n_slots
);
1662 got
->n_slots
[os
] -= n_slots
;
1666 /* Add new or update existing entry to GOT.
1667 H, ABFD, TYPE and SYMNDX is data for the entry.
1668 INFO is a context where memory should be allocated. */
1670 static struct elf_m68k_got_entry
*
1671 elf_m68k_add_entry_to_got (struct elf_m68k_got
*got
,
1672 struct elf_link_hash_entry
*h
,
1674 enum elf_m68k_reloc_type reloc_type
,
1675 unsigned long symndx
,
1676 struct bfd_link_info
*info
)
1678 struct elf_m68k_got_entry_key key_
;
1679 struct elf_m68k_got_entry
*entry
;
1681 if (h
!= NULL
&& elf_m68k_hash_entry (h
)->got_entry_key
== 0)
1682 elf_m68k_hash_entry (h
)->got_entry_key
1683 = elf_m68k_multi_got (info
)->global_symndx
++;
1685 elf_m68k_init_got_entry_key (&key_
, h
, abfd
, symndx
, reloc_type
);
1687 entry
= elf_m68k_get_got_entry (got
, &key_
, FIND_OR_CREATE
, info
);
1691 /* Determine entry's type and update got->n_slots counters. */
1692 entry
->key_
.type
= elf_m68k_update_got_entry_type (got
,
1696 /* Update refcount. */
1697 ++entry
->u
.s1
.refcount
;
1699 if (entry
->u
.s1
.refcount
== 1)
1700 /* We see this entry for the first time. */
1702 if (entry
->key_
.bfd
!= NULL
)
1703 got
->local_n_slots
+= elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
1706 BFD_ASSERT (got
->n_slots
[R_32
] >= got
->local_n_slots
);
1708 if ((got
->n_slots
[R_8
]
1709 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1710 || (got
->n_slots
[R_16
]
1711 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
)))
1712 /* This BFD has too many relocation. */
1714 if (got
->n_slots
[R_8
] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1715 (*_bfd_error_handler
) (_("%B: GOT overflow: "
1716 "Number of relocations with 8-bit "
1719 ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
));
1721 (*_bfd_error_handler
) (_("%B: GOT overflow: "
1722 "Number of relocations with 8- or 16-bit "
1725 ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
));
1733 /* Compute the hash value of the bfd in a bfd2got hash entry. */
1736 elf_m68k_bfd2got_entry_hash (const void *entry
)
1738 const struct elf_m68k_bfd2got_entry
*e
;
1740 e
= (const struct elf_m68k_bfd2got_entry
*) entry
;
1745 /* Check whether two hash entries have the same bfd. */
1748 elf_m68k_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
1750 const struct elf_m68k_bfd2got_entry
*e1
;
1751 const struct elf_m68k_bfd2got_entry
*e2
;
1753 e1
= (const struct elf_m68k_bfd2got_entry
*) entry1
;
1754 e2
= (const struct elf_m68k_bfd2got_entry
*) entry2
;
1756 return e1
->bfd
== e2
->bfd
;
1759 /* Destruct a bfd2got entry. */
1762 elf_m68k_bfd2got_entry_del (void *_entry
)
1764 struct elf_m68k_bfd2got_entry
*entry
;
1766 entry
= (struct elf_m68k_bfd2got_entry
*) _entry
;
1768 BFD_ASSERT (entry
->got
!= NULL
);
1769 elf_m68k_clear_got (entry
->got
);
1772 /* Find existing or create new (depending on HOWTO) bfd2got entry in
1773 MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1774 memory should be allocated. */
1776 static struct elf_m68k_bfd2got_entry
*
1777 elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got
*multi_got
,
1779 enum elf_m68k_get_entry_howto howto
,
1780 struct bfd_link_info
*info
)
1782 struct elf_m68k_bfd2got_entry entry_
;
1784 struct elf_m68k_bfd2got_entry
*entry
;
1786 BFD_ASSERT ((info
== NULL
) == (howto
== SEARCH
|| howto
== MUST_FIND
));
1788 if (multi_got
->bfd2got
== NULL
)
1789 /* This is the first GOT. Initialize bfd2got. */
1791 if (howto
== SEARCH
)
1794 multi_got
->bfd2got
= htab_try_create (1, elf_m68k_bfd2got_entry_hash
,
1795 elf_m68k_bfd2got_entry_eq
,
1796 elf_m68k_bfd2got_entry_del
);
1797 if (multi_got
->bfd2got
== NULL
)
1799 bfd_set_error (bfd_error_no_memory
);
1805 ptr
= htab_find_slot (multi_got
->bfd2got
, &entry_
, (howto
!= SEARCH
1806 ? INSERT
: NO_INSERT
));
1809 if (howto
== SEARCH
)
1810 /* Entry not found. */
1813 /* We're out of memory. */
1814 bfd_set_error (bfd_error_no_memory
);
1819 /* Entry was not found. Create new one. */
1821 BFD_ASSERT (howto
!= MUST_FIND
&& howto
!= SEARCH
);
1823 entry
= ((struct elf_m68k_bfd2got_entry
*)
1824 bfd_alloc (elf_hash_table (info
)->dynobj
, sizeof (*entry
)));
1830 entry
->got
= elf_m68k_create_empty_got (info
);
1831 if (entry
->got
== NULL
)
1838 BFD_ASSERT (howto
!= MUST_CREATE
);
1840 /* Return existing entry. */
1847 struct elf_m68k_can_merge_gots_arg
1849 /* A current_got that we constructing a DIFF against. */
1850 struct elf_m68k_got
*big
;
1852 /* GOT holding entries not present or that should be changed in
1854 struct elf_m68k_got
*diff
;
1856 /* Context where to allocate memory. */
1857 struct bfd_link_info
*info
;
1860 bfd_boolean error_p
;
1863 /* Process a single entry from the small GOT to see if it should be added
1864 or updated in the big GOT. */
1867 elf_m68k_can_merge_gots_1 (void **_entry_ptr
, void *_arg
)
1869 const struct elf_m68k_got_entry
*entry1
;
1870 struct elf_m68k_can_merge_gots_arg
*arg
;
1871 const struct elf_m68k_got_entry
*entry2
;
1872 enum elf_m68k_reloc_type type
;
1874 entry1
= (const struct elf_m68k_got_entry
*) *_entry_ptr
;
1875 arg
= (struct elf_m68k_can_merge_gots_arg
*) _arg
;
1877 entry2
= elf_m68k_get_got_entry (arg
->big
, &entry1
->key_
, SEARCH
, NULL
);
1880 /* We found an existing entry. Check if we should update it. */
1882 type
= elf_m68k_update_got_entry_type (arg
->diff
,
1886 if (type
== entry2
->key_
.type
)
1887 /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1888 To skip creation of difference entry we use the type,
1889 which we won't see in GOT entries for sure. */
1893 /* We didn't find the entry. Add entry1 to DIFF. */
1895 BFD_ASSERT (entry1
->key_
.type
!= R_68K_max
);
1897 type
= elf_m68k_update_got_entry_type (arg
->diff
,
1898 R_68K_max
, entry1
->key_
.type
);
1900 if (entry1
->key_
.bfd
!= NULL
)
1901 arg
->diff
->local_n_slots
+= elf_m68k_reloc_got_n_slots (type
);
1904 if (type
!= R_68K_max
)
1905 /* Create an entry in DIFF. */
1907 struct elf_m68k_got_entry
*entry
;
1909 entry
= elf_m68k_get_got_entry (arg
->diff
, &entry1
->key_
, MUST_CREATE
,
1913 arg
->error_p
= TRUE
;
1917 entry
->key_
.type
= type
;
1923 /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1924 Construct DIFF GOT holding the entries which should be added or updated
1925 in BIG GOT to accumulate information from SMALL.
1926 INFO is the context where memory should be allocated. */
1929 elf_m68k_can_merge_gots (struct elf_m68k_got
*big
,
1930 const struct elf_m68k_got
*small
,
1931 struct bfd_link_info
*info
,
1932 struct elf_m68k_got
*diff
)
1934 struct elf_m68k_can_merge_gots_arg arg_
;
1936 BFD_ASSERT (small
->offset
== (bfd_vma
) -1);
1941 arg_
.error_p
= FALSE
;
1942 htab_traverse_noresize (small
->entries
, elf_m68k_can_merge_gots_1
, &arg_
);
1949 /* Check for overflow. */
1950 if ((big
->n_slots
[R_8
] + arg_
.diff
->n_slots
[R_8
]
1951 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
1952 || (big
->n_slots
[R_16
] + arg_
.diff
->n_slots
[R_16
]
1953 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
)))
1959 struct elf_m68k_merge_gots_arg
1962 struct elf_m68k_got
*big
;
1964 /* Context where memory should be allocated. */
1965 struct bfd_link_info
*info
;
1968 bfd_boolean error_p
;
1971 /* Process a single entry from DIFF got. Add or update corresponding
1972 entry in the BIG got. */
1975 elf_m68k_merge_gots_1 (void **entry_ptr
, void *_arg
)
1977 const struct elf_m68k_got_entry
*from
;
1978 struct elf_m68k_merge_gots_arg
*arg
;
1979 struct elf_m68k_got_entry
*to
;
1981 from
= (const struct elf_m68k_got_entry
*) *entry_ptr
;
1982 arg
= (struct elf_m68k_merge_gots_arg
*) _arg
;
1984 to
= elf_m68k_get_got_entry (arg
->big
, &from
->key_
, FIND_OR_CREATE
,
1988 arg
->error_p
= TRUE
;
1992 BFD_ASSERT (to
->u
.s1
.refcount
== 0);
1993 /* All we need to merge is TYPE. */
1994 to
->key_
.type
= from
->key_
.type
;
1999 /* Merge data from DIFF to BIG. INFO is context where memory should be
2003 elf_m68k_merge_gots (struct elf_m68k_got
*big
,
2004 struct elf_m68k_got
*diff
,
2005 struct bfd_link_info
*info
)
2007 if (diff
->entries
!= NULL
)
2008 /* DIFF is not empty. Merge it into BIG GOT. */
2010 struct elf_m68k_merge_gots_arg arg_
;
2012 /* Merge entries. */
2015 arg_
.error_p
= FALSE
;
2016 htab_traverse_noresize (diff
->entries
, elf_m68k_merge_gots_1
, &arg_
);
2020 /* Merge counters. */
2021 big
->n_slots
[R_8
] += diff
->n_slots
[R_8
];
2022 big
->n_slots
[R_16
] += diff
->n_slots
[R_16
];
2023 big
->n_slots
[R_32
] += diff
->n_slots
[R_32
];
2024 big
->local_n_slots
+= diff
->local_n_slots
;
2027 /* DIFF is empty. */
2029 BFD_ASSERT (diff
->n_slots
[R_8
] == 0);
2030 BFD_ASSERT (diff
->n_slots
[R_16
] == 0);
2031 BFD_ASSERT (diff
->n_slots
[R_32
] == 0);
2032 BFD_ASSERT (diff
->local_n_slots
== 0);
2035 BFD_ASSERT (!elf_m68k_hash_table (info
)->allow_multigot_p
2036 || ((big
->n_slots
[R_8
]
2037 <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info
))
2038 && (big
->n_slots
[R_16
]
2039 <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info
))));
2044 struct elf_m68k_finalize_got_offsets_arg
2046 /* Ranges of the offsets for GOT entries.
2047 R_x entries receive offsets between offset1[R_x] and offset2[R_x].
2048 R_x is R_8, R_16 and R_32. */
2052 /* Mapping from global symndx to global symbols.
2053 This is used to build lists of got entries for global symbols. */
2054 struct elf_m68k_link_hash_entry
**symndx2h
;
2056 bfd_vma n_ldm_entries
;
2059 /* Assign ENTRY an offset. Build list of GOT entries for global symbols
2063 elf_m68k_finalize_got_offsets_1 (void **entry_ptr
, void *_arg
)
2065 struct elf_m68k_got_entry
*entry
;
2066 struct elf_m68k_finalize_got_offsets_arg
*arg
;
2068 enum elf_m68k_got_offset_size got_offset_size
;
2071 entry
= (struct elf_m68k_got_entry
*) *entry_ptr
;
2072 arg
= (struct elf_m68k_finalize_got_offsets_arg
*) _arg
;
2074 /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
2075 BFD_ASSERT (entry
->u
.s1
.refcount
== 0);
2077 /* Get GOT offset size for the entry . */
2078 got_offset_size
= elf_m68k_reloc_got_offset_size (entry
->key_
.type
);
2080 /* Calculate entry size in bytes. */
2081 entry_size
= 4 * elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
2083 /* Check if we should switch to negative range of the offsets. */
2084 if (arg
->offset1
[got_offset_size
] + entry_size
2085 > arg
->offset2
[got_offset_size
])
2087 /* Verify that this is the only switch to negative range for
2088 got_offset_size. If this assertion fails, then we've miscalculated
2089 range for got_offset_size entries in
2090 elf_m68k_finalize_got_offsets. */
2091 BFD_ASSERT (arg
->offset2
[got_offset_size
]
2092 != arg
->offset2
[-(int) got_offset_size
- 1]);
2095 arg
->offset1
[got_offset_size
] = arg
->offset1
[-(int) got_offset_size
- 1];
2096 arg
->offset2
[got_offset_size
] = arg
->offset2
[-(int) got_offset_size
- 1];
2098 /* Verify that now we have enough room for the entry. */
2099 BFD_ASSERT (arg
->offset1
[got_offset_size
] + entry_size
2100 <= arg
->offset2
[got_offset_size
]);
2103 /* Assign offset to entry. */
2104 entry
->u
.s2
.offset
= arg
->offset1
[got_offset_size
];
2105 arg
->offset1
[got_offset_size
] += entry_size
;
2107 if (entry
->key_
.bfd
== NULL
)
2108 /* Hook up this entry into the list of got_entries of H. */
2110 struct elf_m68k_link_hash_entry
*h
;
2112 h
= arg
->symndx2h
[entry
->key_
.symndx
];
2115 entry
->u
.s2
.next
= h
->glist
;
2119 /* This should be the entry for TLS_LDM relocation then. */
2121 BFD_ASSERT ((elf_m68k_reloc_got_type (entry
->key_
.type
)
2123 && entry
->key_
.symndx
== 0);
2125 ++arg
->n_ldm_entries
;
2129 /* This entry is for local symbol. */
2130 entry
->u
.s2
.next
= NULL
;
2135 /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
2136 should use negative offsets.
2137 Build list of GOT entries for global symbols along the way.
2138 SYMNDX2H is mapping from global symbol indices to actual
2140 Return offset at which next GOT should start. */
2143 elf_m68k_finalize_got_offsets (struct elf_m68k_got
*got
,
2144 bfd_boolean use_neg_got_offsets_p
,
2145 struct elf_m68k_link_hash_entry
**symndx2h
,
2146 bfd_vma
*final_offset
, bfd_vma
*n_ldm_entries
)
2148 struct elf_m68k_finalize_got_offsets_arg arg_
;
2149 bfd_vma offset1_
[2 * R_LAST
];
2150 bfd_vma offset2_
[2 * R_LAST
];
2152 bfd_vma start_offset
;
2154 BFD_ASSERT (got
->offset
!= (bfd_vma
) -1);
2156 /* We set entry offsets relative to the .got section (and not the
2157 start of a particular GOT), so that we can use them in
2158 finish_dynamic_symbol without needing to know the GOT which they come
2161 /* Put offset1 in the middle of offset1_, same for offset2. */
2162 arg_
.offset1
= offset1_
+ R_LAST
;
2163 arg_
.offset2
= offset2_
+ R_LAST
;
2165 start_offset
= got
->offset
;
2167 if (use_neg_got_offsets_p
)
2168 /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
2169 i
= -(int) R_32
- 1;
2171 /* Setup positives ranges for R_8, R_16 and R_32. */
2174 for (; i
<= (int) R_32
; ++i
)
2179 /* Set beginning of the range of offsets I. */
2180 arg_
.offset1
[i
] = start_offset
;
2182 /* Calculate number of slots that require I offsets. */
2183 j
= (i
>= 0) ? i
: -i
- 1;
2184 n
= (j
>= 1) ? got
->n_slots
[j
- 1] : 0;
2185 n
= got
->n_slots
[j
] - n
;
2187 if (use_neg_got_offsets_p
&& n
!= 0)
2190 /* We first fill the positive side of the range, so we might
2191 end up with one empty slot at that side when we can't fit
2192 whole 2-slot entry. Account for that at negative side of
2193 the interval with one additional entry. */
2196 /* When the number of slots is odd, make positive side of the
2197 range one entry bigger. */
2201 /* N is the number of slots that require I offsets.
2202 Calculate length of the range for I offsets. */
2205 /* Set end of the range. */
2206 arg_
.offset2
[i
] = start_offset
+ n
;
2208 start_offset
= arg_
.offset2
[i
];
2211 if (!use_neg_got_offsets_p
)
2212 /* Make sure that if we try to switch to negative offsets in
2213 elf_m68k_finalize_got_offsets_1, the assert therein will catch
2215 for (i
= R_8
; i
<= R_32
; ++i
)
2216 arg_
.offset2
[-i
- 1] = arg_
.offset2
[i
];
2218 /* Setup got->offset. offset1[R_8] is either in the middle or at the
2219 beginning of GOT depending on use_neg_got_offsets_p. */
2220 got
->offset
= arg_
.offset1
[R_8
];
2222 arg_
.symndx2h
= symndx2h
;
2223 arg_
.n_ldm_entries
= 0;
2225 /* Assign offsets. */
2226 htab_traverse (got
->entries
, elf_m68k_finalize_got_offsets_1
, &arg_
);
2228 /* Check offset ranges we have actually assigned. */
2229 for (i
= (int) R_8
; i
<= (int) R_32
; ++i
)
2230 BFD_ASSERT (arg_
.offset2
[i
] - arg_
.offset1
[i
] <= 4);
2232 *final_offset
= start_offset
;
2233 *n_ldm_entries
= arg_
.n_ldm_entries
;
2236 struct elf_m68k_partition_multi_got_arg
2238 /* The GOT we are adding entries to. Aka big got. */
2239 struct elf_m68k_got
*current_got
;
2241 /* Offset to assign the next CURRENT_GOT. */
2244 /* Context where memory should be allocated. */
2245 struct bfd_link_info
*info
;
2247 /* Total number of slots in the .got section.
2248 This is used to calculate size of the .got and .rela.got sections. */
2251 /* Difference in numbers of allocated slots in the .got section
2252 and necessary relocations in the .rela.got section.
2253 This is used to calculate size of the .rela.got section. */
2254 bfd_vma slots_relas_diff
;
2257 bfd_boolean error_p
;
2259 /* Mapping from global symndx to global symbols.
2260 This is used to build lists of got entries for global symbols. */
2261 struct elf_m68k_link_hash_entry
**symndx2h
;
2265 elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg
*arg
)
2267 bfd_vma n_ldm_entries
;
2269 elf_m68k_finalize_got_offsets (arg
->current_got
,
2270 (elf_m68k_hash_table (arg
->info
)
2271 ->use_neg_got_offsets_p
),
2273 &arg
->offset
, &n_ldm_entries
);
2275 arg
->n_slots
+= arg
->current_got
->n_slots
[R_32
];
2277 if (!arg
->info
->shared
)
2278 /* If we are generating a shared object, we need to
2279 output a R_68K_RELATIVE reloc so that the dynamic
2280 linker can adjust this GOT entry. Overwise we
2281 don't need space in .rela.got for local symbols. */
2282 arg
->slots_relas_diff
+= arg
->current_got
->local_n_slots
;
2284 /* @LDM relocations require a 2-slot GOT entry, but only
2285 one relocation. Account for that. */
2286 arg
->slots_relas_diff
+= n_ldm_entries
;
2288 BFD_ASSERT (arg
->slots_relas_diff
<= arg
->n_slots
);
2292 /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2293 or start a new CURRENT_GOT. */
2296 elf_m68k_partition_multi_got_1 (void **_entry
, void *_arg
)
2298 struct elf_m68k_bfd2got_entry
*entry
;
2299 struct elf_m68k_partition_multi_got_arg
*arg
;
2300 struct elf_m68k_got
*got
;
2301 struct elf_m68k_got diff_
;
2302 struct elf_m68k_got
*diff
;
2304 entry
= (struct elf_m68k_bfd2got_entry
*) *_entry
;
2305 arg
= (struct elf_m68k_partition_multi_got_arg
*) _arg
;
2308 BFD_ASSERT (got
!= NULL
);
2309 BFD_ASSERT (got
->offset
== (bfd_vma
) -1);
2313 if (arg
->current_got
!= NULL
)
2314 /* Construct diff. */
2317 elf_m68k_init_got (diff
);
2319 if (!elf_m68k_can_merge_gots (arg
->current_got
, got
, arg
->info
, diff
))
2321 if (diff
->offset
== 0)
2322 /* Offset set to 0 in the diff_ indicates an error. */
2324 arg
->error_p
= TRUE
;
2328 if (elf_m68k_hash_table (arg
->info
)->allow_multigot_p
)
2330 elf_m68k_clear_got (diff
);
2331 /* Schedule to finish up current_got and start new one. */
2335 Merge GOTs no matter what. If big GOT overflows,
2336 we'll fail in relocate_section due to truncated relocations.
2338 ??? May be fail earlier? E.g., in can_merge_gots. */
2342 /* Diff of got against empty current_got is got itself. */
2344 /* Create empty current_got to put subsequent GOTs to. */
2345 arg
->current_got
= elf_m68k_create_empty_got (arg
->info
);
2346 if (arg
->current_got
== NULL
)
2348 arg
->error_p
= TRUE
;
2352 arg
->current_got
->offset
= arg
->offset
;
2359 if (!elf_m68k_merge_gots (arg
->current_got
, diff
, arg
->info
))
2361 arg
->error_p
= TRUE
;
2365 /* Now we can free GOT. */
2366 elf_m68k_clear_got (got
);
2368 entry
->got
= arg
->current_got
;
2372 /* Finish up current_got. */
2373 elf_m68k_partition_multi_got_2 (arg
);
2375 /* Schedule to start a new current_got. */
2376 arg
->current_got
= NULL
;
2379 if (!elf_m68k_partition_multi_got_1 (_entry
, _arg
))
2381 BFD_ASSERT (arg
->error_p
);
2388 elf_m68k_clear_got (diff
);
2390 return arg
->error_p
== FALSE
? 1 : 0;
2393 /* Helper function to build symndx2h mapping. */
2396 elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry
*_h
,
2399 struct elf_m68k_link_hash_entry
*h
;
2401 h
= elf_m68k_hash_entry (_h
);
2403 if (h
->got_entry_key
!= 0)
2404 /* H has at least one entry in the GOT. */
2406 struct elf_m68k_partition_multi_got_arg
*arg
;
2408 arg
= (struct elf_m68k_partition_multi_got_arg
*) _arg
;
2410 BFD_ASSERT (arg
->symndx2h
[h
->got_entry_key
] == NULL
);
2411 arg
->symndx2h
[h
->got_entry_key
] = h
;
2417 /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2418 lists of GOT entries for global symbols.
2419 Calculate sizes of .got and .rela.got sections. */
2422 elf_m68k_partition_multi_got (struct bfd_link_info
*info
)
2424 struct elf_m68k_multi_got
*multi_got
;
2425 struct elf_m68k_partition_multi_got_arg arg_
;
2427 multi_got
= elf_m68k_multi_got (info
);
2429 arg_
.current_got
= NULL
;
2433 arg_
.slots_relas_diff
= 0;
2434 arg_
.error_p
= FALSE
;
2436 if (multi_got
->bfd2got
!= NULL
)
2438 /* Initialize symndx2h mapping. */
2440 arg_
.symndx2h
= bfd_zmalloc (multi_got
->global_symndx
2441 * sizeof (*arg_
.symndx2h
));
2442 if (arg_
.symndx2h
== NULL
)
2445 elf_link_hash_traverse (elf_hash_table (info
),
2446 elf_m68k_init_symndx2h_1
, &arg_
);
2450 htab_traverse (multi_got
->bfd2got
, elf_m68k_partition_multi_got_1
,
2454 free (arg_
.symndx2h
);
2455 arg_
.symndx2h
= NULL
;
2460 /* Finish up last current_got. */
2461 elf_m68k_partition_multi_got_2 (&arg_
);
2463 free (arg_
.symndx2h
);
2466 if (elf_hash_table (info
)->dynobj
!= NULL
)
2467 /* Set sizes of .got and .rela.got sections. */
2471 s
= bfd_get_section_by_name (elf_hash_table (info
)->dynobj
, ".got");
2473 s
->size
= arg_
.offset
;
2475 BFD_ASSERT (arg_
.offset
== 0);
2477 BFD_ASSERT (arg_
.slots_relas_diff
<= arg_
.n_slots
);
2478 arg_
.n_slots
-= arg_
.slots_relas_diff
;
2480 s
= bfd_get_section_by_name (elf_hash_table (info
)->dynobj
, ".rela.got");
2482 s
->size
= arg_
.n_slots
* sizeof (Elf32_External_Rela
);
2484 BFD_ASSERT (arg_
.n_slots
== 0);
2487 BFD_ASSERT (multi_got
->bfd2got
== NULL
);
2492 /* Specialized version of elf_m68k_get_got_entry that returns pointer
2493 to hashtable slot, thus allowing removal of entry via
2494 elf_m68k_remove_got_entry. */
2496 static struct elf_m68k_got_entry
**
2497 elf_m68k_find_got_entry_ptr (struct elf_m68k_got
*got
,
2498 struct elf_m68k_got_entry_key
*key
)
2501 struct elf_m68k_got_entry entry_
;
2502 struct elf_m68k_got_entry
**entry_ptr
;
2505 ptr
= htab_find_slot (got
->entries
, &entry_
, NO_INSERT
);
2506 BFD_ASSERT (ptr
!= NULL
);
2508 entry_ptr
= (struct elf_m68k_got_entry
**) ptr
;
2513 /* Remove entry pointed to by ENTRY_PTR from GOT. */
2516 elf_m68k_remove_got_entry (struct elf_m68k_got
*got
,
2517 struct elf_m68k_got_entry
**entry_ptr
)
2519 struct elf_m68k_got_entry
*entry
;
2523 /* Check that offsets have not been finalized yet. */
2524 BFD_ASSERT (got
->offset
== (bfd_vma
) -1);
2525 /* Check that this entry is indeed unused. */
2526 BFD_ASSERT (entry
->u
.s1
.refcount
== 0);
2528 elf_m68k_remove_got_entry_type (got
, entry
->key_
.type
);
2530 if (entry
->key_
.bfd
!= NULL
)
2531 got
->local_n_slots
-= elf_m68k_reloc_got_n_slots (entry
->key_
.type
);
2533 BFD_ASSERT (got
->n_slots
[R_32
] >= got
->local_n_slots
);
2535 htab_clear_slot (got
->entries
, (void **) entry_ptr
);
2538 /* Copy any information related to dynamic linking from a pre-existing
2539 symbol to a newly created symbol. Also called to copy flags and
2540 other back-end info to a weakdef, in which case the symbol is not
2541 newly created and plt/got refcounts and dynamic indices should not
2545 elf_m68k_copy_indirect_symbol (struct bfd_link_info
*info
,
2546 struct elf_link_hash_entry
*_dir
,
2547 struct elf_link_hash_entry
*_ind
)
2549 struct elf_m68k_link_hash_entry
*dir
;
2550 struct elf_m68k_link_hash_entry
*ind
;
2552 _bfd_elf_link_hash_copy_indirect (info
, _dir
, _ind
);
2554 if (_ind
->root
.type
!= bfd_link_hash_indirect
)
2557 dir
= elf_m68k_hash_entry (_dir
);
2558 ind
= elf_m68k_hash_entry (_ind
);
2560 /* Any absolute non-dynamic relocations against an indirect or weak
2561 definition will be against the target symbol. */
2562 _dir
->non_got_ref
|= _ind
->non_got_ref
;
2564 /* We might have a direct symbol already having entries in the GOTs.
2565 Update its key only in case indirect symbol has GOT entries and
2566 assert that both indirect and direct symbols don't have GOT entries
2567 at the same time. */
2568 if (ind
->got_entry_key
!= 0)
2570 BFD_ASSERT (dir
->got_entry_key
== 0);
2571 /* Assert that GOTs aren't partioned yet. */
2572 BFD_ASSERT (ind
->glist
== NULL
);
2574 dir
->got_entry_key
= ind
->got_entry_key
;
2575 ind
->got_entry_key
= 0;
2579 /* Look through the relocs for a section during the first phase, and
2580 allocate space in the global offset table or procedure linkage
2584 elf_m68k_check_relocs (abfd
, info
, sec
, relocs
)
2586 struct bfd_link_info
*info
;
2588 const Elf_Internal_Rela
*relocs
;
2591 Elf_Internal_Shdr
*symtab_hdr
;
2592 struct elf_link_hash_entry
**sym_hashes
;
2593 const Elf_Internal_Rela
*rel
;
2594 const Elf_Internal_Rela
*rel_end
;
2598 struct elf_m68k_got
*got
;
2600 if (info
->relocatable
)
2603 dynobj
= elf_hash_table (info
)->dynobj
;
2604 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2605 sym_hashes
= elf_sym_hashes (abfd
);
2613 rel_end
= relocs
+ sec
->reloc_count
;
2614 for (rel
= relocs
; rel
< rel_end
; rel
++)
2616 unsigned long r_symndx
;
2617 struct elf_link_hash_entry
*h
;
2619 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2621 if (r_symndx
< symtab_hdr
->sh_info
)
2625 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2626 while (h
->root
.type
== bfd_link_hash_indirect
2627 || h
->root
.type
== bfd_link_hash_warning
)
2628 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2631 switch (ELF32_R_TYPE (rel
->r_info
))
2637 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2641 /* Relative GOT relocations. */
2647 /* TLS relocations. */
2649 case R_68K_TLS_GD16
:
2650 case R_68K_TLS_GD32
:
2651 case R_68K_TLS_LDM8
:
2652 case R_68K_TLS_LDM16
:
2653 case R_68K_TLS_LDM32
:
2655 case R_68K_TLS_IE16
:
2656 case R_68K_TLS_IE32
:
2658 case R_68K_TLS_TPREL32
:
2659 case R_68K_TLS_DTPREL32
:
2661 if (ELF32_R_TYPE (rel
->r_info
) == R_68K_TLS_TPREL32
2663 /* Do the special chorus for libraries with static TLS. */
2664 info
->flags
|= DF_STATIC_TLS
;
2666 /* This symbol requires a global offset table entry. */
2670 /* Create the .got section. */
2671 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2672 if (!_bfd_elf_create_got_section (dynobj
, info
))
2678 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2679 BFD_ASSERT (sgot
!= NULL
);
2683 && (h
!= NULL
|| info
->shared
))
2685 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2686 if (srelgot
== NULL
)
2688 srelgot
= bfd_make_section_with_flags (dynobj
,
2694 | SEC_LINKER_CREATED
2697 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
2704 struct elf_m68k_bfd2got_entry
*bfd2got_entry
;
2707 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
2708 abfd
, FIND_OR_CREATE
, info
);
2709 if (bfd2got_entry
== NULL
)
2712 got
= bfd2got_entry
->got
;
2713 BFD_ASSERT (got
!= NULL
);
2717 struct elf_m68k_got_entry
*got_entry
;
2719 /* Add entry to got. */
2720 got_entry
= elf_m68k_add_entry_to_got (got
, h
, abfd
,
2721 ELF32_R_TYPE (rel
->r_info
),
2723 if (got_entry
== NULL
)
2726 if (got_entry
->u
.s1
.refcount
== 1)
2728 /* Make sure this symbol is output as a dynamic symbol. */
2731 && !h
->forced_local
)
2733 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2744 /* This symbol requires a procedure linkage table entry. We
2745 actually build the entry in adjust_dynamic_symbol,
2746 because this might be a case of linking PIC code which is
2747 never referenced by a dynamic object, in which case we
2748 don't need to generate a procedure linkage table entry
2751 /* If this is a local symbol, we resolve it directly without
2752 creating a procedure linkage table entry. */
2763 /* This symbol requires a procedure linkage table entry. */
2767 /* It does not make sense to have this relocation for a
2768 local symbol. FIXME: does it? How to handle it if
2769 it does make sense? */
2770 bfd_set_error (bfd_error_bad_value
);
2774 /* Make sure this symbol is output as a dynamic symbol. */
2775 if (h
->dynindx
== -1
2776 && !h
->forced_local
)
2778 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2789 /* If we are creating a shared library and this is not a local
2790 symbol, we need to copy the reloc into the shared library.
2791 However when linking with -Bsymbolic and this is a global
2792 symbol which is defined in an object we are including in the
2793 link (i.e., DEF_REGULAR is set), then we can resolve the
2794 reloc directly. At this point we have not seen all the input
2795 files, so it is possible that DEF_REGULAR is not set now but
2796 will be set later (it is never cleared). We account for that
2797 possibility below by storing information in the
2798 pcrel_relocs_copied field of the hash table entry. */
2800 && (sec
->flags
& SEC_ALLOC
) != 0
2803 || h
->root
.type
== bfd_link_hash_defweak
2804 || !h
->def_regular
)))
2808 /* Make sure a plt entry is created for this symbol if
2809 it turns out to be a function defined by a dynamic
2819 /* We don't need to handle relocs into sections not going into
2820 the "real" output. */
2821 if ((sec
->flags
& SEC_ALLOC
) == 0)
2826 /* Make sure a plt entry is created for this symbol if it
2827 turns out to be a function defined by a dynamic object. */
2831 /* This symbol needs a non-GOT reference. */
2835 /* If we are creating a shared library, we need to copy the
2836 reloc into the shared library. */
2839 /* When creating a shared object, we must copy these
2840 reloc types into the output file. We create a reloc
2841 section in dynobj and make room for this reloc. */
2844 sreloc
= _bfd_elf_make_dynamic_reloc_section
2845 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
2851 if (sec
->flags
& SEC_READONLY
2852 /* Don't set DF_TEXTREL yet for PC relative
2853 relocations, they might be discarded later. */
2854 && !(ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
2855 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
2856 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
))
2857 info
->flags
|= DF_TEXTREL
;
2859 sreloc
->size
+= sizeof (Elf32_External_Rela
);
2861 /* We count the number of PC relative relocations we have
2862 entered for this symbol, so that we can discard them
2863 again if, in the -Bsymbolic case, the symbol is later
2864 defined by a regular object, or, in the normal shared
2865 case, the symbol is forced to be local. Note that this
2866 function is only called if we are using an m68kelf linker
2867 hash table, which means that h is really a pointer to an
2868 elf_m68k_link_hash_entry. */
2869 if (ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
2870 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
2871 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
)
2873 struct elf_m68k_pcrel_relocs_copied
*p
;
2874 struct elf_m68k_pcrel_relocs_copied
**head
;
2878 struct elf_m68k_link_hash_entry
*eh
2879 = elf_m68k_hash_entry (h
);
2880 head
= &eh
->pcrel_relocs_copied
;
2886 Elf_Internal_Sym
*isym
;
2888 isym
= bfd_sym_from_r_symndx (&elf_m68k_hash_table (info
)->sym_cache
,
2893 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2897 vpp
= &elf_section_data (s
)->local_dynrel
;
2898 head
= (struct elf_m68k_pcrel_relocs_copied
**) vpp
;
2901 for (p
= *head
; p
!= NULL
; p
= p
->next
)
2902 if (p
->section
== sreloc
)
2907 p
= ((struct elf_m68k_pcrel_relocs_copied
*)
2908 bfd_alloc (dynobj
, (bfd_size_type
) sizeof *p
));
2913 p
->section
= sreloc
;
2923 /* This relocation describes the C++ object vtable hierarchy.
2924 Reconstruct it for later use during GC. */
2925 case R_68K_GNU_VTINHERIT
:
2926 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2930 /* This relocation describes which C++ vtable entries are actually
2931 used. Record for later use during GC. */
2932 case R_68K_GNU_VTENTRY
:
2933 BFD_ASSERT (h
!= NULL
);
2935 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2947 /* Return the section that should be marked against GC for a given
2951 elf_m68k_gc_mark_hook (asection
*sec
,
2952 struct bfd_link_info
*info
,
2953 Elf_Internal_Rela
*rel
,
2954 struct elf_link_hash_entry
*h
,
2955 Elf_Internal_Sym
*sym
)
2958 switch (ELF32_R_TYPE (rel
->r_info
))
2960 case R_68K_GNU_VTINHERIT
:
2961 case R_68K_GNU_VTENTRY
:
2965 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2968 /* Update the got entry reference counts for the section being removed. */
2971 elf_m68k_gc_sweep_hook (bfd
*abfd
,
2972 struct bfd_link_info
*info
,
2974 const Elf_Internal_Rela
*relocs
)
2976 Elf_Internal_Shdr
*symtab_hdr
;
2977 struct elf_link_hash_entry
**sym_hashes
;
2978 const Elf_Internal_Rela
*rel
, *relend
;
2980 struct elf_m68k_got
*got
;
2982 if (info
->relocatable
)
2985 dynobj
= elf_hash_table (info
)->dynobj
;
2989 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2990 sym_hashes
= elf_sym_hashes (abfd
);
2993 relend
= relocs
+ sec
->reloc_count
;
2994 for (rel
= relocs
; rel
< relend
; rel
++)
2996 unsigned long r_symndx
;
2997 struct elf_link_hash_entry
*h
= NULL
;
2999 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3000 if (r_symndx
>= symtab_hdr
->sh_info
)
3002 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3003 while (h
->root
.type
== bfd_link_hash_indirect
3004 || h
->root
.type
== bfd_link_hash_warning
)
3005 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3008 switch (ELF32_R_TYPE (rel
->r_info
))
3014 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3023 /* TLS relocations. */
3025 case R_68K_TLS_GD16
:
3026 case R_68K_TLS_GD32
:
3027 case R_68K_TLS_LDM8
:
3028 case R_68K_TLS_LDM16
:
3029 case R_68K_TLS_LDM32
:
3031 case R_68K_TLS_IE16
:
3032 case R_68K_TLS_IE32
:
3034 case R_68K_TLS_TPREL32
:
3035 case R_68K_TLS_DTPREL32
:
3039 got
= elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
3040 abfd
, MUST_FIND
, NULL
)->got
;
3041 BFD_ASSERT (got
!= NULL
);
3045 struct elf_m68k_got_entry_key key_
;
3046 struct elf_m68k_got_entry
**got_entry_ptr
;
3047 struct elf_m68k_got_entry
*got_entry
;
3049 elf_m68k_init_got_entry_key (&key_
, h
, abfd
, r_symndx
,
3050 ELF32_R_TYPE (rel
->r_info
));
3051 got_entry_ptr
= elf_m68k_find_got_entry_ptr (got
, &key_
);
3053 got_entry
= *got_entry_ptr
;
3055 if (got_entry
->u
.s1
.refcount
> 0)
3057 --got_entry
->u
.s1
.refcount
;
3059 if (got_entry
->u
.s1
.refcount
== 0)
3060 /* We don't need the .got entry any more. */
3061 elf_m68k_remove_got_entry (got
, got_entry_ptr
);
3080 if (h
->plt
.refcount
> 0)
3093 /* Return the type of PLT associated with OUTPUT_BFD. */
3095 static const struct elf_m68k_plt_info
*
3096 elf_m68k_get_plt_info (bfd
*output_bfd
)
3098 unsigned int features
;
3100 features
= bfd_m68k_mach_to_features (bfd_get_mach (output_bfd
));
3101 if (features
& cpu32
)
3102 return &elf_cpu32_plt_info
;
3103 if (features
& mcfisa_b
)
3104 return &elf_isab_plt_info
;
3105 if (features
& mcfisa_c
)
3106 return &elf_isac_plt_info
;
3107 return &elf_m68k_plt_info
;
3110 /* This function is called after all the input files have been read,
3111 and the input sections have been assigned to output sections.
3112 It's a convenient place to determine the PLT style. */
3115 elf_m68k_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3117 /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
3119 if (!elf_m68k_partition_multi_got (info
))
3122 elf_m68k_hash_table (info
)->plt_info
= elf_m68k_get_plt_info (output_bfd
);
3126 /* Adjust a symbol defined by a dynamic object and referenced by a
3127 regular object. The current definition is in some section of the
3128 dynamic object, but we're not including those sections. We have to
3129 change the definition to something the rest of the link can
3133 elf_m68k_adjust_dynamic_symbol (info
, h
)
3134 struct bfd_link_info
*info
;
3135 struct elf_link_hash_entry
*h
;
3137 struct elf_m68k_link_hash_table
*htab
;
3141 htab
= elf_m68k_hash_table (info
);
3142 dynobj
= elf_hash_table (info
)->dynobj
;
3144 /* Make sure we know what is going on here. */
3145 BFD_ASSERT (dynobj
!= NULL
3147 || h
->u
.weakdef
!= NULL
3150 && !h
->def_regular
)));
3152 /* If this is a function, put it in the procedure linkage table. We
3153 will fill in the contents of the procedure linkage table later,
3154 when we know the address of the .got section. */
3155 if (h
->type
== STT_FUNC
3158 if ((h
->plt
.refcount
<= 0
3159 || SYMBOL_CALLS_LOCAL (info
, h
)
3160 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3161 && h
->root
.type
== bfd_link_hash_undefweak
))
3162 /* We must always create the plt entry if it was referenced
3163 by a PLTxxO relocation. In this case we already recorded
3164 it as a dynamic symbol. */
3165 && h
->dynindx
== -1)
3167 /* This case can occur if we saw a PLTxx reloc in an input
3168 file, but the symbol was never referred to by a dynamic
3169 object, or if all references were garbage collected. In
3170 such a case, we don't actually need to build a procedure
3171 linkage table, and we can just do a PCxx reloc instead. */
3172 h
->plt
.offset
= (bfd_vma
) -1;
3177 /* Make sure this symbol is output as a dynamic symbol. */
3178 if (h
->dynindx
== -1
3179 && !h
->forced_local
)
3181 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3185 s
= bfd_get_section_by_name (dynobj
, ".plt");
3186 BFD_ASSERT (s
!= NULL
);
3188 /* If this is the first .plt entry, make room for the special
3191 s
->size
= htab
->plt_info
->size
;
3193 /* If this symbol is not defined in a regular file, and we are
3194 not generating a shared library, then set the symbol to this
3195 location in the .plt. This is required to make function
3196 pointers compare as equal between the normal executable and
3197 the shared library. */
3201 h
->root
.u
.def
.section
= s
;
3202 h
->root
.u
.def
.value
= s
->size
;
3205 h
->plt
.offset
= s
->size
;
3207 /* Make room for this entry. */
3208 s
->size
+= htab
->plt_info
->size
;
3210 /* We also need to make an entry in the .got.plt section, which
3211 will be placed in the .got section by the linker script. */
3212 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
3213 BFD_ASSERT (s
!= NULL
);
3216 /* We also need to make an entry in the .rela.plt section. */
3217 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3218 BFD_ASSERT (s
!= NULL
);
3219 s
->size
+= sizeof (Elf32_External_Rela
);
3224 /* Reinitialize the plt offset now that it is not used as a reference
3226 h
->plt
.offset
= (bfd_vma
) -1;
3228 /* If this is a weak symbol, and there is a real definition, the
3229 processor independent code will have arranged for us to see the
3230 real definition first, and we can just use the same value. */
3231 if (h
->u
.weakdef
!= NULL
)
3233 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3234 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3235 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3236 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3240 /* This is a reference to a symbol defined by a dynamic object which
3241 is not a function. */
3243 /* If we are creating a shared library, we must presume that the
3244 only references to the symbol are via the global offset table.
3245 For such cases we need not do anything here; the relocations will
3246 be handled correctly by relocate_section. */
3250 /* If there are no references to this symbol that do not use the
3251 GOT, we don't need to generate a copy reloc. */
3252 if (!h
->non_got_ref
)
3257 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
3258 h
->root
.root
.string
);
3262 /* We must allocate the symbol in our .dynbss section, which will
3263 become part of the .bss section of the executable. There will be
3264 an entry for this symbol in the .dynsym section. The dynamic
3265 object will contain position independent code, so all references
3266 from the dynamic object to this symbol will go through the global
3267 offset table. The dynamic linker will use the .dynsym entry to
3268 determine the address it must put in the global offset table, so
3269 both the dynamic object and the regular object will refer to the
3270 same memory location for the variable. */
3272 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3273 BFD_ASSERT (s
!= NULL
);
3275 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3276 copy the initial value out of the dynamic object and into the
3277 runtime process image. We need to remember the offset into the
3278 .rela.bss section we are going to use. */
3279 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3283 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3284 BFD_ASSERT (srel
!= NULL
);
3285 srel
->size
+= sizeof (Elf32_External_Rela
);
3289 return _bfd_elf_adjust_dynamic_copy (h
, s
);
3292 /* Set the sizes of the dynamic sections. */
3295 elf_m68k_size_dynamic_sections (output_bfd
, info
)
3296 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3297 struct bfd_link_info
*info
;
3304 dynobj
= elf_hash_table (info
)->dynobj
;
3305 BFD_ASSERT (dynobj
!= NULL
);
3307 if (elf_hash_table (info
)->dynamic_sections_created
)
3309 /* Set the contents of the .interp section to the interpreter. */
3310 if (info
->executable
)
3312 s
= bfd_get_section_by_name (dynobj
, ".interp");
3313 BFD_ASSERT (s
!= NULL
);
3314 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3315 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3320 /* We may have created entries in the .rela.got section.
3321 However, if we are not creating the dynamic sections, we will
3322 not actually use these entries. Reset the size of .rela.got,
3323 which will cause it to get stripped from the output file
3325 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
3330 /* If this is a -Bsymbolic shared link, then we need to discard all
3331 PC relative relocs against symbols defined in a regular object.
3332 For the normal shared case we discard the PC relative relocs
3333 against symbols that have become local due to visibility changes.
3334 We allocated space for them in the check_relocs routine, but we
3335 will not fill them in in the relocate_section routine. */
3337 elf_link_hash_traverse (elf_hash_table (info
),
3338 elf_m68k_discard_copies
,
3341 /* The check_relocs and adjust_dynamic_symbol entry points have
3342 determined the sizes of the various dynamic sections. Allocate
3346 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3350 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3353 /* It's OK to base decisions on the section name, because none
3354 of the dynobj section names depend upon the input files. */
3355 name
= bfd_get_section_name (dynobj
, s
);
3357 if (strcmp (name
, ".plt") == 0)
3359 /* Remember whether there is a PLT. */
3362 else if (CONST_STRNEQ (name
, ".rela"))
3368 /* We use the reloc_count field as a counter if we need
3369 to copy relocs into the output file. */
3373 else if (! CONST_STRNEQ (name
, ".got")
3374 && strcmp (name
, ".dynbss") != 0)
3376 /* It's not one of our sections, so don't allocate space. */
3382 /* If we don't need this section, strip it from the
3383 output file. This is mostly to handle .rela.bss and
3384 .rela.plt. We must create both sections in
3385 create_dynamic_sections, because they must be created
3386 before the linker maps input sections to output
3387 sections. The linker does that before
3388 adjust_dynamic_symbol is called, and it is that
3389 function which decides whether anything needs to go
3390 into these sections. */
3391 s
->flags
|= SEC_EXCLUDE
;
3395 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3398 /* Allocate memory for the section contents. */
3399 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3400 Unused entries should be reclaimed before the section's contents
3401 are written out, but at the moment this does not happen. Thus in
3402 order to prevent writing out garbage, we initialise the section's
3403 contents to zero. */
3404 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3405 if (s
->contents
== NULL
)
3409 if (elf_hash_table (info
)->dynamic_sections_created
)
3411 /* Add some entries to the .dynamic section. We fill in the
3412 values later, in elf_m68k_finish_dynamic_sections, but we
3413 must add the entries now so that we get the correct size for
3414 the .dynamic section. The DT_DEBUG entry is filled in by the
3415 dynamic linker and used by the debugger. */
3416 #define add_dynamic_entry(TAG, VAL) \
3417 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3421 if (!add_dynamic_entry (DT_DEBUG
, 0))
3427 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3428 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3429 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3430 || !add_dynamic_entry (DT_JMPREL
, 0))
3436 if (!add_dynamic_entry (DT_RELA
, 0)
3437 || !add_dynamic_entry (DT_RELASZ
, 0)
3438 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3442 if ((info
->flags
& DF_TEXTREL
) != 0)
3444 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3448 #undef add_dynamic_entry
3453 /* This function is called via elf_link_hash_traverse if we are
3454 creating a shared object. In the -Bsymbolic case it discards the
3455 space allocated to copy PC relative relocs against symbols which
3456 are defined in regular objects. For the normal shared case, it
3457 discards space for pc-relative relocs that have become local due to
3458 symbol visibility changes. We allocated space for them in the
3459 check_relocs routine, but we won't fill them in in the
3460 relocate_section routine.
3462 We also check whether any of the remaining relocations apply
3463 against a readonly section, and set the DF_TEXTREL flag in this
3467 elf_m68k_discard_copies (h
, inf
)
3468 struct elf_link_hash_entry
*h
;
3471 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3472 struct elf_m68k_pcrel_relocs_copied
*s
;
3474 if (!SYMBOL_CALLS_LOCAL (info
, h
))
3476 if ((info
->flags
& DF_TEXTREL
) == 0)
3478 /* Look for relocations against read-only sections. */
3479 for (s
= elf_m68k_hash_entry (h
)->pcrel_relocs_copied
;
3482 if ((s
->section
->flags
& SEC_READONLY
) != 0)
3484 info
->flags
|= DF_TEXTREL
;
3492 for (s
= elf_m68k_hash_entry (h
)->pcrel_relocs_copied
;
3495 s
->section
->size
-= s
->count
* sizeof (Elf32_External_Rela
);
3501 /* Install relocation RELA. */
3504 elf_m68k_install_rela (bfd
*output_bfd
,
3506 Elf_Internal_Rela
*rela
)
3510 loc
= srela
->contents
;
3511 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3512 bfd_elf32_swap_reloca_out (output_bfd
, rela
, loc
);
3515 /* Find the base offsets for thread-local storage in this object,
3516 for GD/LD and IE/LE respectively. */
3518 #define DTP_OFFSET 0x8000
3519 #define TP_OFFSET 0x7000
3522 dtpoff_base (struct bfd_link_info
*info
)
3524 /* If tls_sec is NULL, we should have signalled an error already. */
3525 if (elf_hash_table (info
)->tls_sec
== NULL
)
3527 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
3531 tpoff_base (struct bfd_link_info
*info
)
3533 /* If tls_sec is NULL, we should have signalled an error already. */
3534 if (elf_hash_table (info
)->tls_sec
== NULL
)
3536 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
3539 /* Output necessary relocation to handle a symbol during static link.
3540 This function is called from elf_m68k_relocate_section. */
3543 elf_m68k_init_got_entry_static (struct bfd_link_info
*info
,
3545 enum elf_m68k_reloc_type r_type
,
3547 bfd_vma got_entry_offset
,
3550 switch (elf_m68k_reloc_got_type (r_type
))
3553 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ got_entry_offset
);
3556 case R_68K_TLS_GD32
:
3557 /* We know the offset within the module,
3558 put it into the second GOT slot. */
3559 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3560 sgot
->contents
+ got_entry_offset
+ 4);
3563 case R_68K_TLS_LDM32
:
3564 /* Mark it as belonging to module 1, the executable. */
3565 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ got_entry_offset
);
3568 case R_68K_TLS_IE32
:
3569 bfd_put_32 (output_bfd
, relocation
- tpoff_base (info
),
3570 sgot
->contents
+ got_entry_offset
);
3578 /* Output necessary relocation to handle a local symbol
3579 during dynamic link.
3580 This function is called either from elf_m68k_relocate_section
3581 or from elf_m68k_finish_dynamic_symbol. */
3584 elf_m68k_init_got_entry_local_shared (struct bfd_link_info
*info
,
3586 enum elf_m68k_reloc_type r_type
,
3588 bfd_vma got_entry_offset
,
3592 Elf_Internal_Rela outrel
;
3594 switch (elf_m68k_reloc_got_type (r_type
))
3597 /* Emit RELATIVE relocation to initialize GOT slot
3599 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
3600 outrel
.r_addend
= relocation
;
3603 case R_68K_TLS_GD32
:
3604 /* We know the offset within the module,
3605 put it into the second GOT slot. */
3606 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
3607 sgot
->contents
+ got_entry_offset
+ 4);
3610 case R_68K_TLS_LDM32
:
3611 /* We don't know the module number,
3612 create a relocation for it. */
3613 outrel
.r_info
= ELF32_R_INFO (0, R_68K_TLS_DTPMOD32
);
3614 outrel
.r_addend
= 0;
3617 case R_68K_TLS_IE32
:
3618 /* Emit TPREL relocation to initialize GOT slot
3620 outrel
.r_info
= ELF32_R_INFO (0, R_68K_TLS_TPREL32
);
3621 outrel
.r_addend
= relocation
- elf_hash_table (info
)->tls_sec
->vma
;
3628 /* Offset of the GOT entry. */
3629 outrel
.r_offset
= (sgot
->output_section
->vma
3630 + sgot
->output_offset
3631 + got_entry_offset
);
3633 /* Install one of the above relocations. */
3634 elf_m68k_install_rela (output_bfd
, srela
, &outrel
);
3636 bfd_put_32 (output_bfd
, outrel
.r_addend
, sgot
->contents
+ got_entry_offset
);
3639 /* Relocate an M68K ELF section. */
3642 elf_m68k_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3643 contents
, relocs
, local_syms
, local_sections
)
3645 struct bfd_link_info
*info
;
3647 asection
*input_section
;
3649 Elf_Internal_Rela
*relocs
;
3650 Elf_Internal_Sym
*local_syms
;
3651 asection
**local_sections
;
3654 Elf_Internal_Shdr
*symtab_hdr
;
3655 struct elf_link_hash_entry
**sym_hashes
;
3660 struct elf_m68k_got
*got
;
3661 Elf_Internal_Rela
*rel
;
3662 Elf_Internal_Rela
*relend
;
3664 dynobj
= elf_hash_table (info
)->dynobj
;
3665 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3666 sym_hashes
= elf_sym_hashes (input_bfd
);
3676 relend
= relocs
+ input_section
->reloc_count
;
3677 for (; rel
< relend
; rel
++)
3680 reloc_howto_type
*howto
;
3681 unsigned long r_symndx
;
3682 struct elf_link_hash_entry
*h
;
3683 Elf_Internal_Sym
*sym
;
3686 bfd_boolean unresolved_reloc
;
3687 bfd_reloc_status_type r
;
3689 r_type
= ELF32_R_TYPE (rel
->r_info
);
3690 if (r_type
< 0 || r_type
>= (int) R_68K_max
)
3692 bfd_set_error (bfd_error_bad_value
);
3695 howto
= howto_table
+ r_type
;
3697 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3702 unresolved_reloc
= FALSE
;
3704 if (r_symndx
< symtab_hdr
->sh_info
)
3706 sym
= local_syms
+ r_symndx
;
3707 sec
= local_sections
[r_symndx
];
3708 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
3714 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3715 r_symndx
, symtab_hdr
, sym_hashes
,
3717 unresolved_reloc
, warned
);
3720 if (sec
!= NULL
&& elf_discarded_section (sec
))
3721 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3722 rel
, relend
, howto
, contents
);
3724 if (info
->relocatable
)
3732 /* Relocation is to the address of the entry for this symbol
3733 in the global offset table. */
3735 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3737 if (elf_m68k_hash_table (info
)->local_gp_p
)
3739 bfd_vma sgot_output_offset
;
3744 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3747 sgot_output_offset
= sgot
->output_offset
;
3749 /* In this case we have a reference to
3750 _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3752 ??? Issue a warning? */
3753 sgot_output_offset
= 0;
3756 sgot_output_offset
= sgot
->output_offset
;
3760 struct elf_m68k_bfd2got_entry
*bfd2got_entry
;
3763 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
3764 input_bfd
, SEARCH
, NULL
);
3766 if (bfd2got_entry
!= NULL
)
3768 got
= bfd2got_entry
->got
;
3769 BFD_ASSERT (got
!= NULL
);
3771 got_offset
= got
->offset
;
3774 /* In this case we have a reference to
3775 _GLOBAL_OFFSET_TABLE_, but no other references
3776 accessing any GOT entries.
3777 ??? Issue a warning? */
3781 got_offset
= got
->offset
;
3783 /* Adjust GOT pointer to point to the GOT
3784 assigned to input_bfd. */
3785 rel
->r_addend
+= sgot_output_offset
+ got_offset
;
3788 BFD_ASSERT (got
== NULL
|| got
->offset
== 0);
3797 case R_68K_TLS_LDM32
:
3798 case R_68K_TLS_LDM16
:
3799 case R_68K_TLS_LDM8
:
3802 case R_68K_TLS_GD16
:
3803 case R_68K_TLS_GD32
:
3806 case R_68K_TLS_IE16
:
3807 case R_68K_TLS_IE32
:
3809 /* Relocation is the offset of the entry for this symbol in
3810 the global offset table. */
3813 struct elf_m68k_got_entry_key key_
;
3819 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3820 BFD_ASSERT (sgot
!= NULL
);
3825 got
= elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info
),
3826 input_bfd
, MUST_FIND
,
3828 BFD_ASSERT (got
!= NULL
);
3831 /* Get GOT offset for this symbol. */
3832 elf_m68k_init_got_entry_key (&key_
, h
, input_bfd
, r_symndx
,
3834 off_ptr
= &elf_m68k_get_got_entry (got
, &key_
, MUST_FIND
,
3838 /* The offset must always be a multiple of 4. We use
3839 the least significant bit to record whether we have
3840 already generated the necessary reloc. */
3846 /* @TLSLDM relocations are bounded to the module, in
3847 which the symbol is defined -- not to the symbol
3849 && elf_m68k_reloc_got_type (r_type
) != R_68K_TLS_LDM32
)
3853 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3854 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3856 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3857 || (ELF_ST_VISIBILITY (h
->other
)
3858 && h
->root
.type
== bfd_link_hash_undefweak
))
3860 /* This is actually a static link, or it is a
3861 -Bsymbolic link and the symbol is defined
3862 locally, or the symbol was forced to be local
3863 because of a version file. We must initialize
3864 this entry in the global offset table. Since
3865 the offset must always be a multiple of 4, we
3866 use the least significant bit to record whether
3867 we have initialized it already.
3869 When doing a dynamic link, we create a .rela.got
3870 relocation entry to initialize the value. This
3871 is done in the finish_dynamic_symbol routine. */
3873 elf_m68k_init_got_entry_static (info
,
3883 unresolved_reloc
= FALSE
;
3885 else if (info
->shared
) /* && h == NULL */
3886 /* Process local symbol during dynamic link. */
3890 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
3891 BFD_ASSERT (srela
!= NULL
);
3894 elf_m68k_init_got_entry_local_shared (info
,
3904 else /* h == NULL && !info->shared */
3906 elf_m68k_init_got_entry_static (info
,
3917 /* We don't use elf_m68k_reloc_got_type in the condition below
3918 because this is the only place where difference between
3919 R_68K_GOTx and R_68K_GOTxO relocations matters. */
3920 if (r_type
== R_68K_GOT32O
3921 || r_type
== R_68K_GOT16O
3922 || r_type
== R_68K_GOT8O
3923 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_GD32
3924 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_LDM32
3925 || elf_m68k_reloc_got_type (r_type
) == R_68K_TLS_IE32
)
3927 /* GOT pointer is adjusted to point to the start/middle
3928 of local GOT. Adjust the offset accordingly. */
3929 BFD_ASSERT (elf_m68k_hash_table (info
)->use_neg_got_offsets_p
3930 || off
>= got
->offset
);
3932 if (elf_m68k_hash_table (info
)->local_gp_p
)
3933 relocation
= off
- got
->offset
;
3936 BFD_ASSERT (got
->offset
== 0);
3937 relocation
= sgot
->output_offset
+ off
;
3940 /* This relocation does not use the addend. */
3944 relocation
= (sgot
->output_section
->vma
+ sgot
->output_offset
3949 case R_68K_TLS_LDO32
:
3950 case R_68K_TLS_LDO16
:
3951 case R_68K_TLS_LDO8
:
3952 relocation
-= dtpoff_base (info
);
3955 case R_68K_TLS_LE32
:
3956 case R_68K_TLS_LE16
:
3960 (*_bfd_error_handler
)
3961 (_("%B(%A+0x%lx): R_68K_TLS_LE32 relocation not permitted "
3962 "in shared object"),
3963 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
);
3968 relocation
-= tpoff_base (info
);
3975 /* Relocation is to the entry for this symbol in the
3976 procedure linkage table. */
3978 /* Resolve a PLTxx reloc against a local symbol directly,
3979 without using the procedure linkage table. */
3983 if (h
->plt
.offset
== (bfd_vma
) -1
3984 || !elf_hash_table (info
)->dynamic_sections_created
)
3986 /* We didn't make a PLT entry for this symbol. This
3987 happens when statically linking PIC code, or when
3988 using -Bsymbolic. */
3994 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3995 BFD_ASSERT (splt
!= NULL
);
3998 relocation
= (splt
->output_section
->vma
3999 + splt
->output_offset
4001 unresolved_reloc
= FALSE
;
4007 /* Relocation is the offset of the entry for this symbol in
4008 the procedure linkage table. */
4009 BFD_ASSERT (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1);
4013 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4014 BFD_ASSERT (splt
!= NULL
);
4017 relocation
= h
->plt
.offset
;
4018 unresolved_reloc
= FALSE
;
4020 /* This relocation does not use the addend. */
4032 && r_symndx
!= STN_UNDEF
4033 && (input_section
->flags
& SEC_ALLOC
) != 0
4035 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4036 || h
->root
.type
!= bfd_link_hash_undefweak
)
4037 && ((r_type
!= R_68K_PC8
4038 && r_type
!= R_68K_PC16
4039 && r_type
!= R_68K_PC32
)
4040 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4042 Elf_Internal_Rela outrel
;
4044 bfd_boolean skip
, relocate
;
4046 /* When generating a shared object, these relocations
4047 are copied into the output file to be resolved at run
4054 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4056 if (outrel
.r_offset
== (bfd_vma
) -1)
4058 else if (outrel
.r_offset
== (bfd_vma
) -2)
4059 skip
= TRUE
, relocate
= TRUE
;
4060 outrel
.r_offset
+= (input_section
->output_section
->vma
4061 + input_section
->output_offset
);
4064 memset (&outrel
, 0, sizeof outrel
);
4067 && (r_type
== R_68K_PC8
4068 || r_type
== R_68K_PC16
4069 || r_type
== R_68K_PC32
4072 || !h
->def_regular
))
4074 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4075 outrel
.r_addend
= rel
->r_addend
;
4079 /* This symbol is local, or marked to become local. */
4080 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4082 if (r_type
== R_68K_32
)
4085 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
4091 if (bfd_is_abs_section (sec
))
4093 else if (sec
== NULL
|| sec
->owner
== NULL
)
4095 bfd_set_error (bfd_error_bad_value
);
4102 /* We are turning this relocation into one
4103 against a section symbol. It would be
4104 proper to subtract the symbol's value,
4105 osec->vma, from the emitted reloc addend,
4106 but ld.so expects buggy relocs. */
4107 osec
= sec
->output_section
;
4108 indx
= elf_section_data (osec
)->dynindx
;
4111 struct elf_link_hash_table
*htab
;
4112 htab
= elf_hash_table (info
);
4113 osec
= htab
->text_index_section
;
4114 indx
= elf_section_data (osec
)->dynindx
;
4116 BFD_ASSERT (indx
!= 0);
4119 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
4123 sreloc
= elf_section_data (input_section
)->sreloc
;
4127 loc
= sreloc
->contents
;
4128 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4129 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4131 /* This reloc will be computed at runtime, so there's no
4132 need to do anything now, except for R_68K_32
4133 relocations that have been turned into
4141 case R_68K_GNU_VTINHERIT
:
4142 case R_68K_GNU_VTENTRY
:
4143 /* These are no-ops in the end. */
4150 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4151 because such sections are not SEC_ALLOC and thus ld.so will
4152 not process them. */
4153 if (unresolved_reloc
4154 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4156 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4157 rel
->r_offset
) != (bfd_vma
) -1)
4159 (*_bfd_error_handler
)
4160 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4163 (long) rel
->r_offset
,
4165 h
->root
.root
.string
);
4169 if (r_symndx
!= STN_UNDEF
4170 && r_type
!= R_68K_NONE
4172 || h
->root
.type
== bfd_link_hash_defined
4173 || h
->root
.type
== bfd_link_hash_defweak
))
4177 sym_type
= (sym
!= NULL
) ? ELF32_ST_TYPE (sym
->st_info
) : h
->type
;
4179 if (elf_m68k_reloc_tls_p (r_type
) != (sym_type
== STT_TLS
))
4184 name
= h
->root
.root
.string
;
4187 name
= (bfd_elf_string_from_elf_section
4188 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4189 if (name
== NULL
|| *name
== '\0')
4190 name
= bfd_section_name (input_bfd
, sec
);
4193 (*_bfd_error_handler
)
4194 ((sym_type
== STT_TLS
4195 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4196 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4199 (long) rel
->r_offset
,
4205 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4206 contents
, rel
->r_offset
,
4207 relocation
, rel
->r_addend
);
4209 if (r
!= bfd_reloc_ok
)
4214 name
= h
->root
.root
.string
;
4217 name
= bfd_elf_string_from_elf_section (input_bfd
,
4218 symtab_hdr
->sh_link
,
4223 name
= bfd_section_name (input_bfd
, sec
);
4226 if (r
== bfd_reloc_overflow
)
4228 if (!(info
->callbacks
->reloc_overflow
4229 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4230 (bfd_vma
) 0, input_bfd
, input_section
,
4236 (*_bfd_error_handler
)
4237 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4238 input_bfd
, input_section
,
4239 (long) rel
->r_offset
, name
, (int) r
);
4248 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4249 into section SEC. */
4252 elf_m68k_install_pc32 (asection
*sec
, bfd_vma offset
, bfd_vma value
)
4254 /* Make VALUE PC-relative. */
4255 value
-= sec
->output_section
->vma
+ offset
;
4257 /* Apply any in-place addend. */
4258 value
+= bfd_get_32 (sec
->owner
, sec
->contents
+ offset
);
4260 bfd_put_32 (sec
->owner
, value
, sec
->contents
+ offset
);
4263 /* Finish up dynamic symbol handling. We set the contents of various
4264 dynamic sections here. */
4267 elf_m68k_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4269 struct bfd_link_info
*info
;
4270 struct elf_link_hash_entry
*h
;
4271 Elf_Internal_Sym
*sym
;
4275 dynobj
= elf_hash_table (info
)->dynobj
;
4277 if (h
->plt
.offset
!= (bfd_vma
) -1)
4279 const struct elf_m68k_plt_info
*plt_info
;
4285 Elf_Internal_Rela rela
;
4288 /* This symbol has an entry in the procedure linkage table. Set
4291 BFD_ASSERT (h
->dynindx
!= -1);
4293 plt_info
= elf_m68k_hash_table (info
)->plt_info
;
4294 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4295 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
4296 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4297 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
4299 /* Get the index in the procedure linkage table which
4300 corresponds to this symbol. This is the index of this symbol
4301 in all the symbols for which we are making plt entries. The
4302 first entry in the procedure linkage table is reserved. */
4303 plt_index
= (h
->plt
.offset
/ plt_info
->size
) - 1;
4305 /* Get the offset into the .got table of the entry that
4306 corresponds to this function. Each .got entry is 4 bytes.
4307 The first three are reserved. */
4308 got_offset
= (plt_index
+ 3) * 4;
4310 memcpy (splt
->contents
+ h
->plt
.offset
,
4311 plt_info
->symbol_entry
,
4314 elf_m68k_install_pc32 (splt
, h
->plt
.offset
+ plt_info
->symbol_relocs
.got
,
4315 (sgot
->output_section
->vma
4316 + sgot
->output_offset
4319 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
4322 + plt_info
->symbol_resolve_entry
+ 2);
4324 elf_m68k_install_pc32 (splt
, h
->plt
.offset
+ plt_info
->symbol_relocs
.plt
,
4325 splt
->output_section
->vma
);
4327 /* Fill in the entry in the global offset table. */
4328 bfd_put_32 (output_bfd
,
4329 (splt
->output_section
->vma
4330 + splt
->output_offset
4332 + plt_info
->symbol_resolve_entry
),
4333 sgot
->contents
+ got_offset
);
4335 /* Fill in the entry in the .rela.plt section. */
4336 rela
.r_offset
= (sgot
->output_section
->vma
4337 + sgot
->output_offset
4339 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_JMP_SLOT
);
4341 loc
= srela
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
4342 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4344 if (!h
->def_regular
)
4346 /* Mark the symbol as undefined, rather than as defined in
4347 the .plt section. Leave the value alone. */
4348 sym
->st_shndx
= SHN_UNDEF
;
4352 if (elf_m68k_hash_entry (h
)->glist
!= NULL
)
4356 struct elf_m68k_got_entry
*got_entry
;
4358 /* This symbol has an entry in the global offset table. Set it
4361 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4362 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
4363 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
4365 got_entry
= elf_m68k_hash_entry (h
)->glist
;
4367 while (got_entry
!= NULL
)
4369 enum elf_m68k_reloc_type r_type
;
4370 bfd_vma got_entry_offset
;
4372 r_type
= got_entry
->key_
.type
;
4373 got_entry_offset
= got_entry
->u
.s2
.offset
&~ (bfd_vma
) 1;
4375 /* If this is a -Bsymbolic link, and the symbol is defined
4376 locally, we just want to emit a RELATIVE reloc. Likewise if
4377 the symbol was forced to be local because of a version file.
4378 The entry in the global offset table already have been
4379 initialized in the relocate_section function. */
4381 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4385 relocation
= bfd_get_signed_32 (output_bfd
,
4387 + got_entry_offset
));
4390 switch (elf_m68k_reloc_got_type (r_type
))
4393 case R_68K_TLS_LDM32
:
4396 case R_68K_TLS_GD32
:
4397 /* The value for this relocation is actually put in
4398 the second GOT slot. */
4399 relocation
= bfd_get_signed_32 (output_bfd
,
4401 + got_entry_offset
+ 4));
4402 relocation
+= dtpoff_base (info
);
4405 case R_68K_TLS_IE32
:
4406 relocation
+= tpoff_base (info
);
4413 elf_m68k_init_got_entry_local_shared (info
,
4423 Elf_Internal_Rela rela
;
4425 /* Put zeros to GOT slots that will be initialized
4430 n_slots
= elf_m68k_reloc_got_n_slots (got_entry
->key_
.type
);
4432 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4433 (sgot
->contents
+ got_entry_offset
4438 rela
.r_offset
= (sgot
->output_section
->vma
4439 + sgot
->output_offset
4440 + got_entry_offset
);
4442 switch (elf_m68k_reloc_got_type (r_type
))
4445 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_GLOB_DAT
);
4446 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4449 case R_68K_TLS_GD32
:
4450 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_DTPMOD32
);
4451 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4454 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_DTPREL32
);
4455 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4458 case R_68K_TLS_IE32
:
4459 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_TLS_TPREL32
);
4460 elf_m68k_install_rela (output_bfd
, srela
, &rela
);
4469 got_entry
= got_entry
->u
.s2
.next
;
4476 Elf_Internal_Rela rela
;
4479 /* This symbol needs a copy reloc. Set it up. */
4481 BFD_ASSERT (h
->dynindx
!= -1
4482 && (h
->root
.type
== bfd_link_hash_defined
4483 || h
->root
.type
== bfd_link_hash_defweak
));
4485 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
4487 BFD_ASSERT (s
!= NULL
);
4489 rela
.r_offset
= (h
->root
.u
.def
.value
4490 + h
->root
.u
.def
.section
->output_section
->vma
4491 + h
->root
.u
.def
.section
->output_offset
);
4492 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_COPY
);
4494 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4495 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4498 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4499 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4500 || h
== elf_hash_table (info
)->hgot
)
4501 sym
->st_shndx
= SHN_ABS
;
4506 /* Finish up the dynamic sections. */
4509 elf_m68k_finish_dynamic_sections (output_bfd
, info
)
4511 struct bfd_link_info
*info
;
4517 dynobj
= elf_hash_table (info
)->dynobj
;
4519 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
4520 BFD_ASSERT (sgot
!= NULL
);
4521 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4523 if (elf_hash_table (info
)->dynamic_sections_created
)
4526 Elf32_External_Dyn
*dyncon
, *dynconend
;
4528 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4529 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
4531 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4532 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4533 for (; dyncon
< dynconend
; dyncon
++)
4535 Elf_Internal_Dyn dyn
;
4539 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4552 s
= bfd_get_section_by_name (output_bfd
, name
);
4553 BFD_ASSERT (s
!= NULL
);
4554 dyn
.d_un
.d_ptr
= s
->vma
;
4555 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4559 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4560 BFD_ASSERT (s
!= NULL
);
4561 dyn
.d_un
.d_val
= s
->size
;
4562 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4566 /* The procedure linkage table relocs (DT_JMPREL) should
4567 not be included in the overall relocs (DT_RELA).
4568 Therefore, we override the DT_RELASZ entry here to
4569 make it not include the JMPREL relocs. Since the
4570 linker script arranges for .rela.plt to follow all
4571 other relocation sections, we don't have to worry
4572 about changing the DT_RELA entry. */
4573 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4575 dyn
.d_un
.d_val
-= s
->size
;
4576 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4581 /* Fill in the first entry in the procedure linkage table. */
4584 const struct elf_m68k_plt_info
*plt_info
;
4586 plt_info
= elf_m68k_hash_table (info
)->plt_info
;
4587 memcpy (splt
->contents
, plt_info
->plt0_entry
, plt_info
->size
);
4589 elf_m68k_install_pc32 (splt
, plt_info
->plt0_relocs
.got4
,
4590 (sgot
->output_section
->vma
4591 + sgot
->output_offset
4594 elf_m68k_install_pc32 (splt
, plt_info
->plt0_relocs
.got8
,
4595 (sgot
->output_section
->vma
4596 + sgot
->output_offset
4599 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
4604 /* Fill in the first three entries in the global offset table. */
4608 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4610 bfd_put_32 (output_bfd
,
4611 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4613 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4614 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4617 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4622 /* Given a .data section and a .emreloc in-memory section, store
4623 relocation information into the .emreloc section which can be
4624 used at runtime to relocate the section. This is called by the
4625 linker when the --embedded-relocs switch is used. This is called
4626 after the add_symbols entry point has been called for all the
4627 objects, and before the final_link entry point is called. */
4630 bfd_m68k_elf32_create_embedded_relocs (abfd
, info
, datasec
, relsec
, errmsg
)
4632 struct bfd_link_info
*info
;
4637 Elf_Internal_Shdr
*symtab_hdr
;
4638 Elf_Internal_Sym
*isymbuf
= NULL
;
4639 Elf_Internal_Rela
*internal_relocs
= NULL
;
4640 Elf_Internal_Rela
*irel
, *irelend
;
4644 BFD_ASSERT (! info
->relocatable
);
4648 if (datasec
->reloc_count
== 0)
4651 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4653 /* Get a copy of the native relocations. */
4654 internal_relocs
= (_bfd_elf_link_read_relocs
4655 (abfd
, datasec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
4656 info
->keep_memory
));
4657 if (internal_relocs
== NULL
)
4660 amt
= (bfd_size_type
) datasec
->reloc_count
* 12;
4661 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, amt
);
4662 if (relsec
->contents
== NULL
)
4665 p
= relsec
->contents
;
4667 irelend
= internal_relocs
+ datasec
->reloc_count
;
4668 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
4670 asection
*targetsec
;
4672 /* We are going to write a four byte longword into the runtime
4673 reloc section. The longword will be the address in the data
4674 section which must be relocated. It is followed by the name
4675 of the target section NUL-padded or truncated to 8
4678 /* We can only relocate absolute longword relocs at run time. */
4679 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_68K_32
)
4681 *errmsg
= _("unsupported reloc type");
4682 bfd_set_error (bfd_error_bad_value
);
4686 /* Get the target section referred to by the reloc. */
4687 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
4689 /* A local symbol. */
4690 Elf_Internal_Sym
*isym
;
4692 /* Read this BFD's local symbols if we haven't done so already. */
4693 if (isymbuf
== NULL
)
4695 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4696 if (isymbuf
== NULL
)
4697 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
4698 symtab_hdr
->sh_info
, 0,
4700 if (isymbuf
== NULL
)
4704 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
4705 targetsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4710 struct elf_link_hash_entry
*h
;
4712 /* An external symbol. */
4713 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
4714 h
= elf_sym_hashes (abfd
)[indx
];
4715 BFD_ASSERT (h
!= NULL
);
4716 if (h
->root
.type
== bfd_link_hash_defined
4717 || h
->root
.type
== bfd_link_hash_defweak
)
4718 targetsec
= h
->root
.u
.def
.section
;
4723 bfd_put_32 (abfd
, irel
->r_offset
+ datasec
->output_offset
, p
);
4724 memset (p
+ 4, 0, 8);
4725 if (targetsec
!= NULL
)
4726 strncpy ((char *) p
+ 4, targetsec
->output_section
->name
, 8);
4729 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
4731 if (internal_relocs
!= NULL
4732 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
4733 free (internal_relocs
);
4737 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
4739 if (internal_relocs
!= NULL
4740 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
4741 free (internal_relocs
);
4745 /* Set target options. */
4748 bfd_elf_m68k_set_target_options (struct bfd_link_info
*info
, int got_handling
)
4750 struct elf_m68k_link_hash_table
*htab
;
4751 bfd_boolean use_neg_got_offsets_p
;
4752 bfd_boolean allow_multigot_p
;
4753 bfd_boolean local_gp_p
;
4755 switch (got_handling
)
4760 use_neg_got_offsets_p
= FALSE
;
4761 allow_multigot_p
= FALSE
;
4765 /* --got=negative. */
4767 use_neg_got_offsets_p
= TRUE
;
4768 allow_multigot_p
= FALSE
;
4772 /* --got=multigot. */
4774 use_neg_got_offsets_p
= TRUE
;
4775 allow_multigot_p
= TRUE
;
4783 htab
= elf_m68k_hash_table (info
);
4786 htab
->local_gp_p
= local_gp_p
;
4787 htab
->use_neg_got_offsets_p
= use_neg_got_offsets_p
;
4788 htab
->allow_multigot_p
= allow_multigot_p
;
4792 static enum elf_reloc_type_class
4793 elf32_m68k_reloc_type_class (rela
)
4794 const Elf_Internal_Rela
*rela
;
4796 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4798 case R_68K_RELATIVE
:
4799 return reloc_class_relative
;
4800 case R_68K_JMP_SLOT
:
4801 return reloc_class_plt
;
4803 return reloc_class_copy
;
4805 return reloc_class_normal
;
4809 /* Return address for Ith PLT stub in section PLT, for relocation REL
4810 or (bfd_vma) -1 if it should not be included. */
4813 elf_m68k_plt_sym_val (bfd_vma i
, const asection
*plt
,
4814 const arelent
*rel ATTRIBUTE_UNUSED
)
4816 return plt
->vma
+ (i
+ 1) * elf_m68k_get_plt_info (plt
->owner
)->size
;
4819 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
4820 #define TARGET_BIG_NAME "elf32-m68k"
4821 #define ELF_MACHINE_CODE EM_68K
4822 #define ELF_MAXPAGESIZE 0x2000
4823 #define elf_backend_create_dynamic_sections \
4824 _bfd_elf_create_dynamic_sections
4825 #define bfd_elf32_bfd_link_hash_table_create \
4826 elf_m68k_link_hash_table_create
4827 /* ??? Should it be this macro or bfd_elfNN_bfd_link_hash_table_create? */
4828 #define bfd_elf32_bfd_link_hash_table_free \
4829 elf_m68k_link_hash_table_free
4830 #define bfd_elf32_bfd_final_link bfd_elf_final_link
4832 #define elf_backend_check_relocs elf_m68k_check_relocs
4833 #define elf_backend_always_size_sections \
4834 elf_m68k_always_size_sections
4835 #define elf_backend_adjust_dynamic_symbol \
4836 elf_m68k_adjust_dynamic_symbol
4837 #define elf_backend_size_dynamic_sections \
4838 elf_m68k_size_dynamic_sections
4839 #define elf_backend_final_write_processing elf_m68k_final_write_processing
4840 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4841 #define elf_backend_relocate_section elf_m68k_relocate_section
4842 #define elf_backend_finish_dynamic_symbol \
4843 elf_m68k_finish_dynamic_symbol
4844 #define elf_backend_finish_dynamic_sections \
4845 elf_m68k_finish_dynamic_sections
4846 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4847 #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook
4848 #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4849 #define bfd_elf32_bfd_merge_private_bfd_data \
4850 elf32_m68k_merge_private_bfd_data
4851 #define bfd_elf32_bfd_set_private_flags \
4852 elf32_m68k_set_private_flags
4853 #define bfd_elf32_bfd_print_private_bfd_data \
4854 elf32_m68k_print_private_bfd_data
4855 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4856 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4857 #define elf_backend_object_p elf32_m68k_object_p
4859 #define elf_backend_can_gc_sections 1
4860 #define elf_backend_can_refcount 1
4861 #define elf_backend_want_got_plt 1
4862 #define elf_backend_plt_readonly 1
4863 #define elf_backend_want_plt_sym 0
4864 #define elf_backend_got_header_size 12
4865 #define elf_backend_rela_normal 1
4867 #include "elf32-target.h"