1 /* Motorola 68k series support for 32-bit ELF
2 Copyright 1993 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 static reloc_howto_type *reloc_type_lookup
27 PARAMS ((bfd *, bfd_reloc_code_real_type));
28 static void rtype_to_howto
29 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
30 static void rtype_to_howto_rel
31 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
32 static boolean elf_m68k_create_dynamic_sections
33 PARAMS ((bfd *, struct bfd_link_info *));
34 static boolean elf_m68k_create_got_section
35 PARAMS ((bfd *, struct bfd_link_info *));
36 static boolean elf_m68k_check_relocs
37 PARAMS ((bfd *, struct bfd_link_info *, asection *,
38 const Elf_Internal_Rela *));
39 static boolean elf_m68k_adjust_dynamic_symbol
40 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
41 static boolean elf_m68k_adjust_dynindx
42 PARAMS ((struct elf_link_hash_entry *, PTR));
43 static boolean elf_m68k_size_dynamic_sections
44 PARAMS ((bfd *, struct bfd_link_info *));
45 static boolean elf_m68k_relocate_section
46 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
47 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
48 static boolean elf_m68k_finish_dynamic_symbol
49 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
51 static boolean elf_m68k_finish_dynamic_sections
52 PARAMS ((bfd *, struct bfd_link_info *));
54 /* elf32 m68k code, generated by elf.el */
82 static reloc_howto_type howto_table[] = {
83 HOWTO(R_68K_NONE, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", false, 0x00000000, 0x00000000,false),
84 HOWTO(R_68K_32, 0, 2,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", false, 0xffffffff, 0xffffffff,false),
85 HOWTO(R_68K_16, 0, 1,16, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", false, 0x0000ffff, 0x0000ffff,false),
86 HOWTO(R_68K_8, 0, 0, 8, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", false, 0x000000ff, 0x000000ff,false),
87 HOWTO(R_68K_PC32, 0, 2,32, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC32", false, 0xffffffff, 0xffffffff,true),
88 HOWTO(R_68K_PC16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", false, 0x0000ffff, 0x0000ffff,true),
89 HOWTO(R_68K_PC8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", false, 0x000000ff, 0x000000ff,true),
90 HOWTO(R_68K_GOT32, 0, 2,32, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT32", false, 0xffffffff, 0xffffffff,true),
91 HOWTO(R_68K_GOT16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", false, 0x0000ffff, 0x0000ffff,true),
92 HOWTO(R_68K_GOT8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", false, 0x000000ff, 0x000000ff,true),
93 HOWTO(R_68K_GOT32O, 0, 2,32, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT32O", false, 0xffffffff, 0xffffffff,false),
94 HOWTO(R_68K_GOT16O, 0, 1,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", false, 0x0000ffff, 0x0000ffff,false),
95 HOWTO(R_68K_GOT8O, 0, 0, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", false, 0x000000ff, 0x000000ff,false),
96 HOWTO(R_68K_PLT32, 0, 2,32, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT32", false, 0xffffffff, 0xffffffff,true),
97 HOWTO(R_68K_PLT16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", false, 0x0000ffff, 0x0000ffff,true),
98 HOWTO(R_68K_PLT8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", false, 0x000000ff, 0x000000ff,true),
99 HOWTO(R_68K_PLT32O, 0, 2,32, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT32O", false, 0xffffffff, 0xffffffff,false),
100 HOWTO(R_68K_PLT16O, 0, 1,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", false, 0x0000ffff, 0x0000ffff,false),
101 HOWTO(R_68K_PLT8O, 0, 0, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", false, 0x000000ff, 0x000000ff,false),
102 HOWTO(R_68K_COPY, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", false, 0xffffffff, 0xffffffff,false),
103 HOWTO(R_68K_GLOB_DAT, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", false, 0xffffffff, 0xffffffff,false),
104 HOWTO(R_68K_JMP_SLOT, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", false, 0xffffffff, 0xffffffff,false),
105 HOWTO(R_68K_RELATIVE, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", false, 0xffffffff, 0xffffffff,false),
109 rtype_to_howto (abfd, cache_ptr, dst)
112 Elf_Internal_Rela *dst;
114 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K__max);
115 cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
119 rtype_to_howto_rel (abfd, cache_ptr, dst)
122 Elf_Internal_Rel *dst;
124 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K__max);
125 cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
128 #define elf_info_to_howto rtype_to_howto
129 #define elf_info_to_howto_rel rtype_to_howto_rel
131 static const struct { unsigned char bfd_val, elf_val; } reloc_map[] = {
132 { BFD_RELOC_NONE, R_68K_NONE },
133 { BFD_RELOC_32, R_68K_32 },
134 { BFD_RELOC_16, R_68K_16 },
135 { BFD_RELOC_8, R_68K_8 },
136 { BFD_RELOC_32_PCREL, R_68K_PC32 },
137 { BFD_RELOC_16_PCREL, R_68K_PC16 },
138 { BFD_RELOC_8_PCREL, R_68K_PC8 },
139 { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
140 { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
141 { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
142 { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
143 { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
144 { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
145 { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
146 { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
147 { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
148 { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
149 { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
150 { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
151 { BFD_RELOC_NONE, R_68K_COPY },
152 { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
153 { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
154 { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
155 { BFD_RELOC_CTOR, R_68K_32 },
158 static reloc_howto_type *
159 reloc_type_lookup (abfd, code)
161 bfd_reloc_code_real_type code;
164 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
166 if (reloc_map[i].bfd_val == code)
167 return &howto_table[(int) reloc_map[i].elf_val];
172 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
173 #define ELF_ARCH bfd_arch_m68k
174 /* end code generated by elf.el */
179 /* Functions for the m68k ELF linker. */
181 /* The name of the dynamic interpreter. This is put in the .interp
184 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
186 /* The size in bytes of an entry in the procedure linkage table. */
188 #define PLT_ENTRY_SIZE 20
190 /* The first entry in a procedure linkage table looks like this. See
191 the SVR4 ABI m68k supplement to see how this works. */
193 static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
195 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
196 0, 0, 0, 0, /* replaced with address of .got + 4. */
197 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
198 0, 0, 0, 0, /* replaced with address of .got + 8. */
199 0, 0, 0, 0 /* pad out to 20 bytes. */
202 /* Subsequent entries in a procedure linkage table look like this. */
204 static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
206 0x4e, 0xfb, 0x01, 0x71, /* jmp ([addr]) */
207 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
208 0x2f, 0x3c, /* move.l #offset,-(%sp) */
209 0, 0, 0, 0, /* replaced with offset into relocation table. */
210 0x60, 0xff, /* bra.l .plt */
211 0, 0, 0, 0 /* replaced with offset to start of .plt. */
214 /* Create dynamic sections when linking against a dynamic object. */
217 elf_m68k_create_dynamic_sections (abfd, info)
219 struct bfd_link_info *info;
222 register asection *s;
224 /* We need to create .plt, .rela.plt, .got, .got.plt, .dynbss, and
225 .rela.bss sections. */
227 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
229 s = bfd_make_section (abfd, ".plt");
231 || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY | SEC_CODE)
232 || !bfd_set_section_alignment (abfd, s, 2))
235 s = bfd_make_section (abfd, ".rela.plt");
237 || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
238 || !bfd_set_section_alignment (abfd, s, 2))
241 if (!elf_m68k_create_got_section (abfd, info))
244 /* The .dynbss section is a place to put symbols which are defined
245 by dynamic objects, are referenced by regular objects, and are
246 not functions. We must allocate space for them in the process
247 image and use a R_68K_COPY reloc to tell the dynamic linker to
248 initialize them at run time. The linker script puts the .dynbss
249 section into the .bss section of the final image. */
250 s = bfd_make_section (abfd, ".dynbss");
252 || !bfd_set_section_flags (abfd, s, SEC_ALLOC))
255 /* The .rela.bss section holds copy relocs. This section is not
256 normally needed. We need to create it here, though, so that the
257 linker will map it to an output section. We can't just create it
258 only if we need it, because we will not know whether we need it
259 until we have seen all the input files, and the first time the
260 main linker code calls BFD after examining all the input files
261 (size_dynamic_sections) the input sections have already been
262 mapped to the output sections. If the section turns out not to
263 be needed, we can discard it later. We will never need this
264 section when generating a shared object, since they do not use
268 s = bfd_make_section (abfd, ".rela.bss");
270 || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
271 || !bfd_set_section_alignment (abfd, s, 2))
278 /* Create the .got section to hold the global offset table, and the
279 .got.plt section to hold procedure linkage table GOT entries. The
280 linker script will put .got.plt into the output .got section. */
283 elf_m68k_create_got_section (abfd, info)
285 struct bfd_link_info *info;
288 register asection *s;
289 struct elf_link_hash_entry *h;
291 /* This function may be called more than once. */
292 if (bfd_get_section_by_name (abfd, ".got") != NULL)
295 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
297 s = bfd_make_section (abfd, ".got");
299 || !bfd_set_section_flags (abfd, s, flags)
300 || !bfd_set_section_alignment (abfd, s, 2))
303 s = bfd_make_section (abfd, ".got.plt");
305 || !bfd_set_section_flags (abfd, s, flags)
306 || !bfd_set_section_alignment (abfd, s, 2))
309 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
310 .got.plt section, which will be placed at the start of the output
311 .got section. We don't do this in the linker script because we
312 don't want to define the symbol if we are not creating a global
315 if (!(_bfd_generic_link_add_one_symbol
316 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, (bfd_vma) 0,
317 (const char *) NULL, false, get_elf_backend_data (abfd)->collect,
318 (struct bfd_link_hash_entry **) &h)))
320 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
321 h->type = STT_OBJECT;
324 && !bfd_elf32_link_record_dynamic_symbol (info, h))
327 /* The first three global offset table entries are reserved. */
328 s->_raw_size += 3 * 4;
333 /* Look through the relocs for a section during the first phase, and
334 allocate space in the global offset table or procedure linkage
338 elf_m68k_check_relocs (abfd, info, sec, relocs)
340 struct bfd_link_info *info;
342 const Elf_Internal_Rela *relocs;
345 Elf_Internal_Shdr *symtab_hdr;
346 struct elf_link_hash_entry **sym_hashes;
347 bfd_vma *local_got_offsets;
348 const Elf_Internal_Rela *rel;
349 const Elf_Internal_Rela *rel_end;
354 if (info->relocateable)
357 dynobj = elf_hash_table (info)->dynobj;
358 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
359 sym_hashes = elf_sym_hashes (abfd);
360 local_got_offsets = elf_local_got_offsets (abfd);
366 rel_end = relocs + sec->reloc_count;
367 for (rel = relocs; rel < rel_end; rel++)
370 struct elf_link_hash_entry *h;
372 r_symndx = ELF32_R_SYM (rel->r_info);
374 if (r_symndx < symtab_hdr->sh_info)
377 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
379 switch (ELF32_R_TYPE (rel->r_info))
387 /* This symbol requires a global offset table entry. */
390 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
395 /* Create the .got section. */
396 elf_hash_table (info)->dynobj = dynobj = abfd;
397 if (!elf_m68k_create_got_section (dynobj, info))
403 sgot = bfd_get_section_by_name (dynobj, ".got");
404 BFD_ASSERT (sgot != NULL);
408 && (h != NULL || info->shared))
410 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
413 srelgot = bfd_make_section (dynobj, ".rela.got");
415 || !bfd_set_section_flags (dynobj, srelgot,
421 || !bfd_set_section_alignment (dynobj, srelgot, 2))
428 if (h->got_offset != (bfd_vma) -1)
430 /* We have already allocated space in the .got. */
433 h->got_offset = sgot->_raw_size;
435 /* Make sure this symbol is output as a dynamic symbol. */
436 if (h->dynindx == -1)
438 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
442 srelgot->_raw_size += sizeof (Elf32_External_Rela);
446 /* This is a global offset table entry for a local
448 if (local_got_offsets == NULL)
453 size = symtab_hdr->sh_info * sizeof (bfd_vma);
454 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
455 if (local_got_offsets == NULL)
457 bfd_set_error (bfd_error_no_memory);
460 elf_local_got_offsets (abfd) = local_got_offsets;
461 for (i = 0; i < symtab_hdr->sh_info; i++)
462 local_got_offsets[i] = (bfd_vma) -1;
464 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
466 /* We have already allocated space in the .got. */
469 local_got_offsets[r_symndx] = sgot->_raw_size;
473 /* If we are generating a shared object, we need to
474 output a R_68K_RELATIVE reloc so that the dynamic
475 linker can adjust this GOT entry. */
476 srelgot->_raw_size += sizeof (Elf32_External_Rela);
480 sgot->_raw_size += 4;
489 /* This symbol requires a procedure linkage table entry. We
490 actually build the entry in adjust_dynamic_symbol,
491 because this might be a case of linking PIC code without
492 linking in any dynamic objects, in which case we don't
493 need to generate a procedure linkage table after all. */
495 /* If this is a local symbol, we resolve it directly without
496 creating a procedure linkage table entry. */
500 /* Make sure this symbol is output as a dynamic symbol. */
501 if (h->dynindx == -1)
503 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
507 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
517 && (sec->flags & SEC_ALLOC) != 0)
519 /* When creating a shared object, we must copy these
520 reloc types into the output file. We create a reloc
521 section in dynobj and make room for this reloc. */
526 name = (elf_string_from_elf_section
528 elf_elfheader (abfd)->e_shstrndx,
529 elf_section_data (sec)->rel_hdr.sh_name));
533 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
534 && strcmp (bfd_get_section_name (abfd, sec),
537 sreloc = bfd_get_section_by_name (dynobj, name);
540 sreloc = bfd_make_section (dynobj, name);
542 || !bfd_set_section_flags (dynobj, sreloc,
548 || !bfd_set_section_alignment (dynobj, sreloc, 2))
553 sreloc->_raw_size += sizeof (Elf32_External_Rela);
566 /* Adjust a symbol defined by a dynamic object and referenced by a
567 regular object. The current definition is in some section of the
568 dynamic object, but we're not including those sections. We have to
569 change the definition to something the rest of the link can
573 elf_m68k_adjust_dynamic_symbol (info, h)
574 struct bfd_link_info *info;
575 struct elf_link_hash_entry *h;
579 unsigned int power_of_two;
581 dynobj = elf_hash_table (info)->dynobj;
583 /* Make sure we know what is going on here. */
584 BFD_ASSERT (dynobj != NULL);
585 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
586 || ((h->elf_link_hash_flags
587 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
588 && (h->elf_link_hash_flags
589 & ELF_LINK_HASH_REF_REGULAR) != 0
590 && (h->elf_link_hash_flags
591 & ELF_LINK_HASH_DEF_REGULAR) == 0
592 && (h->root.type == bfd_link_hash_defined
593 || h->root.type == bfd_link_hash_defweak)
594 && (h->root.u.def.section->owner == NULL
595 || ((elf_elfheader (h->root.u.def.section->owner)->e_type
597 && (bfd_get_flavour (h->root.u.def.section->owner)
598 == bfd_target_elf_flavour)
599 && h->root.u.def.section->output_section == NULL))));
601 /* If this is a function, put it in the procedure linkage table. We
602 will fill in the contents of the procedure linkage table later,
603 when we know the address of the .got section. */
604 if (h->type == STT_FUNC
605 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
607 if (!elf_hash_table (info)->dynamic_sections_created)
609 /* This case can occur if we saw a PLT32 reloc in an input
610 file, but none of the input files were dynamic objects.
611 In such a case, we don't actually need to build a
612 procedure linkage table, and we can just do a PC32 reloc
614 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
618 s = bfd_get_section_by_name (dynobj, ".plt");
619 BFD_ASSERT (s != NULL);
621 /* If this is the first .plt entry, make room for the special
623 if (s->_raw_size == 0)
624 s->_raw_size += PLT_ENTRY_SIZE;
626 /* If this symbol is not defined in a regular file, and we are
627 not generating a shared library, then set the symbol to this
628 location in the .plt. This is required to make function
629 pointers compare as equal between the normal executable and
630 the shared library. */
632 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
634 h->root.u.def.section = s;
635 h->root.u.def.value = s->_raw_size;
638 h->plt_offset = s->_raw_size;
640 /* Make room for this entry. */
641 s->_raw_size += PLT_ENTRY_SIZE;
643 /* We also need to make an entry in the .got.plt section, which
644 will be placed in the .got section by the linker script. */
646 s = bfd_get_section_by_name (dynobj, ".got.plt");
647 BFD_ASSERT (s != NULL);
650 /* We also need to make an entry in the .rela.plt section. */
652 s = bfd_get_section_by_name (dynobj, ".rela.plt");
653 BFD_ASSERT (s != NULL);
654 s->_raw_size += sizeof (Elf32_External_Rela);
659 /* If this is a weak symbol, and there is a real definition, the
660 processor independent code will have arranged for us to see the
661 real definition first, and we can just use the same value. */
662 if (h->weakdef != NULL)
664 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
665 || h->weakdef->root.type == bfd_link_hash_defweak);
666 h->root.u.def.section = h->weakdef->root.u.def.section;
667 h->root.u.def.value = h->weakdef->root.u.def.value;
671 /* This is a reference to a symbol defined by a dynamic object which
672 is not a function. */
674 /* If we are creating a shared library, we must presume that the
675 only references to the symbol are via the global offset table.
676 For such cases we need not do anything here; the relocations will
677 be handled correctly by relocate_section. */
681 /* We must allocate the symbol in our .dynbss section, which will
682 become part of the .bss section of the executable. There will be
683 an entry for this symbol in the .dynsym section. The dynamic
684 object will contain position independent code, so all references
685 from the dynamic object to this symbol will go through the global
686 offset table. The dynamic linker will use the .dynsym entry to
687 determine the address it must put in the global offset table, so
688 both the dynamic object and the regular object will refer to the
689 same memory location for the variable. */
691 s = bfd_get_section_by_name (dynobj, ".dynbss");
692 BFD_ASSERT (s != NULL);
694 /* If the symbol is currently defined in the .bss section of the
695 dynamic object, then it is OK to simply initialize it to zero.
696 If the symbol is in some other section, we must generate a
697 R_68K_COPY reloc to tell the dynamic linker to copy the initial
698 value out of the dynamic object and into the runtime process
699 image. We need to remember the offset into the .rela.bss section
700 we are going to use. */
701 if ((h->root.u.def.section->flags & SEC_LOAD) != 0)
705 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
706 BFD_ASSERT (srel != NULL);
707 srel->_raw_size += sizeof (Elf32_External_Rela);
708 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
711 /* We need to figure out the alignment required for this symbol. I
712 have no idea how ELF linkers handle this. */
713 power_of_two = bfd_log2 (h->size);
714 if (power_of_two > 3)
717 /* Apply the required alignment. */
718 s->_raw_size = BFD_ALIGN (s->_raw_size,
719 (bfd_size_type) (1 << power_of_two));
720 if (power_of_two > bfd_get_section_alignment (dynobj, s))
722 if (!bfd_set_section_alignment (dynobj, s, power_of_two))
726 /* Define the symbol as being at this point in the section. */
727 h->root.u.def.section = s;
728 h->root.u.def.value = s->_raw_size;
730 /* Increment the section size to make room for the symbol. */
731 s->_raw_size += h->size;
736 /* Set the sizes of the dynamic sections. */
739 elf_m68k_size_dynamic_sections (output_bfd, info)
741 struct bfd_link_info *info;
749 dynobj = elf_hash_table (info)->dynobj;
750 BFD_ASSERT (dynobj != NULL);
752 if (elf_hash_table (info)->dynamic_sections_created)
754 /* Set the contents of the .interp section to the interpreter. */
757 s = bfd_get_section_by_name (dynobj, ".interp");
758 BFD_ASSERT (s != NULL);
759 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
760 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
765 /* We may have created entries in the .rela.got section.
766 However, if we are not creating the dynamic sections, we will
767 not actually use these entries. Reset the size of .rela.got,
768 which will cause it to get stripped from the output file
770 s = bfd_get_section_by_name (dynobj, ".rela.got");
775 /* The check_relocs and adjust_dynamic_symbol entry points have
776 determined the sizes of the various dynamic sections. Allocate
781 for (s = dynobj->sections; s != NULL; s = s->next)
786 if ((s->flags & SEC_IN_MEMORY) == 0)
789 /* It's OK to base decisions on the section name, because none
790 of the dynobj section names depend upon the input files. */
791 name = bfd_get_section_name (dynobj, s);
795 if (strcmp (name, ".plt") == 0)
797 if (s->_raw_size == 0)
799 /* Strip this section if we don't need it; see the
805 /* Remember whether there is a PLT. */
809 else if (strncmp (name, ".rela", 5) == 0)
811 if (s->_raw_size == 0)
813 /* If we don't need this section, strip it from the
814 output file. This is mostly to handle .rela.bss and
815 .rela.plt. We must create both sections in
816 create_dynamic_sections, because they must be created
817 before the linker maps input sections to output
818 sections. The linker does that before
819 adjust_dynamic_symbol is called, and it is that
820 function which decides whether anything needs to go
821 into these sections. */
828 /* Remember whether there are any reloc sections other
830 if (strcmp (name, ".rela.plt") != 0)
834 /* If this relocation section applies to a read only
835 section, then we probably need a DT_TEXTREL
836 entry. .rela.plt is actually associated with
837 .got.plt, which is never readonly. */
838 target = bfd_get_section_by_name (output_bfd, name + 5);
840 && (target->flags & SEC_READONLY) != 0)
844 /* We use the reloc_count field as a counter if we need
845 to copy relocs into the output file. */
849 else if (strncmp (name, ".got", 4) != 0)
851 /* It's not one of our sections, so don't allocate space. */
859 for (spp = &s->output_section->owner->sections;
860 *spp != s->output_section;
863 *spp = s->output_section->next;
864 --s->output_section->owner->section_count;
869 /* Allocate memory for the section contents. */
870 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
871 if (s->contents == NULL && s->_raw_size != 0)
873 bfd_set_error (bfd_error_no_memory);
878 if (elf_hash_table (info)->dynamic_sections_created)
880 /* Add some entries to the .dynamic section. We fill in the
881 values later, in elf_m68k_finish_dynamic_sections, but we
882 must add the entries now so that we get the correct size for
883 the .dynamic section. The DT_DEBUG entry is filled in by the
884 dynamic linker and used by the debugger. */
887 if (!bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
893 if (!bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
894 || !bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
895 || !bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
896 || !bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
902 if (!bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
903 || !bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
904 || !bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
905 sizeof (Elf32_External_Rela)))
911 if (!bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
916 /* If we are generating a shared library, we generate a section
917 symbol for each output section. These are local symbols, which
918 means that they must come first in the dynamic symbol table.
919 That means we must increment the dynamic symbol index of every
920 other dynamic symbol. */
925 c = bfd_count_sections (output_bfd);
926 elf_link_hash_traverse (elf_hash_table (info),
927 elf_m68k_adjust_dynindx,
929 elf_hash_table (info)->dynsymcount += c;
931 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
933 elf_section_data (s)->dynindx = i;
934 /* These symbols will have no names, so we don't need to
935 fiddle with dynstr_index. */
942 /* Increment the index of a dynamic symbol by a given amount. Called
943 via elf_link_hash_traverse. */
946 elf_m68k_adjust_dynindx (h, cparg)
947 struct elf_link_hash_entry *h;
950 int *cp = (int *) cparg;
952 if (h->dynindx != -1)
957 /* Relocate an M68K ELF section. */
960 elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section,
961 contents, relocs, local_syms, local_sections)
963 struct bfd_link_info *info;
965 asection *input_section;
967 Elf_Internal_Rela *relocs;
968 Elf_Internal_Sym *local_syms;
969 asection **local_sections;
972 Elf_Internal_Shdr *symtab_hdr;
973 struct elf_link_hash_entry **sym_hashes;
974 bfd_vma *local_got_offsets;
979 Elf_Internal_Rela *rel;
980 Elf_Internal_Rela *relend;
982 dynobj = elf_hash_table (info)->dynobj;
983 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
984 sym_hashes = elf_sym_hashes (input_bfd);
985 local_got_offsets = elf_local_got_offsets (input_bfd);
993 relend = relocs + input_section->reloc_count;
994 for (; rel < relend; rel++)
997 reloc_howto_type *howto;
999 struct elf_link_hash_entry *h;
1000 Elf_Internal_Sym *sym;
1003 bfd_reloc_status_type r;
1005 r_type = ELF32_R_TYPE (rel->r_info);
1006 if (r_type < 0 || r_type >= (int) R_68K__max)
1008 bfd_set_error (bfd_error_bad_value);
1011 howto = howto_table + r_type;
1013 r_symndx = ELF32_R_SYM (rel->r_info);
1015 if (info->relocateable)
1017 /* This is a relocateable link. We don't have to change
1018 anything, unless the reloc is against a section symbol,
1019 in which case we have to adjust according to where the
1020 section symbol winds up in the output section. */
1021 if (r_symndx < symtab_hdr->sh_info)
1023 sym = local_syms + r_symndx;
1024 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1026 sec = local_sections[r_symndx];
1027 rel->r_addend += sec->output_offset + sym->st_value;
1034 /* This is a final link. */
1038 if (r_symndx < symtab_hdr->sh_info)
1040 sym = local_syms + r_symndx;
1041 sec = local_sections[r_symndx];
1042 relocation = (sec->output_section->vma
1043 + sec->output_offset
1048 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1049 if (h->root.type == bfd_link_hash_defined
1050 || h->root.type == bfd_link_hash_defweak)
1052 sec = h->root.u.def.section;
1053 if (((r_type == R_68K_PLT8
1054 || r_type == R_68K_PLT16
1055 || r_type == R_68K_PLT32
1056 || r_type == R_68K_PLT8O
1057 || r_type == R_68K_PLT16O
1058 || r_type == R_68K_PLT32O)
1059 && h->plt_offset != (bfd_vma) -1)
1060 || ((r_type == R_68K_GOT8O
1061 || r_type == R_68K_GOT16O
1062 || r_type == R_68K_GOT32O
1063 || ((r_type == R_68K_GOT8
1064 || r_type == R_68K_GOT16
1065 || r_type == R_68K_GOT32)
1066 && strcmp (h->root.root.string,
1067 "_GLOBAL_OFFSET_TABLE_") != 0))
1068 && elf_hash_table (info)->dynamic_sections_created)
1070 && (input_section->flags & SEC_ALLOC) != 0
1071 && (r_type == R_68K_8
1072 || r_type == R_68K_16
1073 || r_type == R_68K_32
1074 || r_type == R_68K_PC8
1075 || r_type == R_68K_PC16
1076 || r_type == R_68K_PC32)))
1078 /* In these cases, we don't need the relocation
1079 value. We check specially because in some
1080 obscure cases sec->output_section will be NULL. */
1084 relocation = (h->root.u.def.value
1085 + sec->output_section->vma
1086 + sec->output_offset);
1088 else if (h->root.type == bfd_link_hash_undefweak)
1090 else if (info->shared)
1094 if (!(info->callbacks->undefined_symbol
1095 (info, h->root.root.string, input_bfd,
1096 input_section, rel->r_offset)))
1107 /* Relocation is to the entry for this symbol in the global
1110 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1116 /* Relocation is the offset of the entry for this symbol in
1117 the global offset table. */
1121 sgot = bfd_get_section_by_name (dynobj, ".got");
1122 BFD_ASSERT (sgot != NULL);
1125 if (sgotplt == NULL)
1127 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1128 BFD_ASSERT (sgotplt != NULL);
1135 off = h->got_offset;
1136 BFD_ASSERT (off != (bfd_vma) -1);
1138 if (!elf_hash_table (info)->dynamic_sections_created)
1140 /* This is actually a static link. We must
1141 initialize this entry in the global offset table.
1142 Since the offset must always be a multiple of 4,
1143 we use the least significant bit to record
1144 whether we have initialized it already.
1146 When doing a dynamic link, we create a .rela.got
1147 relocation entry to initialize the value. This
1148 is done in the finish_dynamic_symbol routine. */
1153 bfd_put_32 (output_bfd, relocation,
1154 sgot->contents + off);
1159 relocation = sgot->output_offset + off;
1160 if (r_type == R_68K_GOT8O
1161 || r_type == R_68K_GOT16O
1162 || r_type == R_68K_GOT32O)
1163 relocation -= sgotplt->output_offset;
1169 BFD_ASSERT (local_got_offsets != NULL
1170 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1172 off = local_got_offsets[r_symndx];
1174 /* The offset must always be a multiple of 4. We use
1175 the least significant bit to record whether we have
1176 already generated the necessary reloc. */
1181 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1186 Elf_Internal_Rela outrel;
1188 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1189 BFD_ASSERT (srelgot != NULL);
1191 outrel.r_offset = (sgot->output_section->vma
1192 + sgot->output_offset
1194 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
1195 outrel.r_addend = 0;
1196 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1197 (((Elf32_External_Rela *)
1199 + srelgot->reloc_count));
1200 ++srelgot->reloc_count;
1203 local_got_offsets[r_symndx] |= 1;
1206 relocation = sgot->output_offset + off;
1207 if (r_type == R_68K_GOT8O
1208 || r_type == R_68K_GOT16O
1209 || r_type == R_68K_GOT32O)
1210 relocation -= sgotplt->output_offset;
1218 /* Relocation is to the entry for this symbol in the
1219 procedure linkage table. */
1221 /* Resolve a PLT32 reloc against a local symbol directly,
1222 without using the procedure linkage table. */
1226 if (h->plt_offset == (bfd_vma) -1)
1228 /* We didn't make a PLT entry for this symbol. This
1229 happens when statically linking PIC code. */
1235 splt = bfd_get_section_by_name (dynobj, ".plt");
1236 BFD_ASSERT (splt != NULL);
1239 relocation = (splt->output_section->vma
1240 + splt->output_offset
1247 /* Relocation is the offset of the entry for this symbol in
1248 the procedure linkage table. */
1249 BFD_ASSERT (h != NULL);
1251 if (h->plt_offset == (bfd_vma) -1)
1253 /* We didn't make a PLT entry for this symbol. This
1254 happens when statically linking PIC code. */
1260 splt = bfd_get_section_by_name (dynobj, ".plt");
1261 BFD_ASSERT (splt != NULL);
1264 relocation = h->plt_offset;
1274 && (input_section->flags & SEC_ALLOC) != 0)
1276 Elf_Internal_Rela outrel;
1278 /* When generating a shared object, these relocations
1279 are copied into the output file to be resolved at run
1286 name = (elf_string_from_elf_section
1288 elf_elfheader (input_bfd)->e_shstrndx,
1289 elf_section_data (input_section)->rel_hdr.sh_name));
1293 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1294 && strcmp (bfd_get_section_name (input_bfd,
1298 sreloc = bfd_get_section_by_name (dynobj, name);
1299 BFD_ASSERT (sreloc != NULL);
1302 outrel.r_offset = (rel->r_offset
1303 + input_section->output_section->vma
1304 + input_section->output_offset);
1307 BFD_ASSERT (h->dynindx != -1);
1308 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1309 outrel.r_addend = rel->r_addend;
1313 if (r_type == R_68K_32)
1315 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
1316 outrel.r_addend = relocation + rel->r_addend;
1322 sym = local_syms + r_symndx;
1324 BFD_ASSERT (ELF_ST_TYPE (sym->st_info) == STT_SECTION);
1326 sec = local_sections[r_symndx];
1327 if (sec != NULL && bfd_is_abs_section (sec))
1329 else if (sec == NULL || sec->owner == NULL)
1331 bfd_set_error (bfd_error_bad_value);
1338 osec = sec->output_section;
1339 indx = elf_section_data (osec)->dynindx;
1344 outrel.r_info = ELF32_R_INFO (indx, r_type);
1345 outrel.r_addend = relocation + rel->r_addend;
1349 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1350 (((Elf32_External_Rela *)
1352 + sreloc->reloc_count));
1353 ++sreloc->reloc_count;
1355 /* This reloc will be computed at runtime, so there's no
1356 need to do anything now. */
1366 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1367 contents, rel->r_offset,
1368 relocation, rel->r_addend);
1370 if (r != bfd_reloc_ok)
1375 case bfd_reloc_outofrange:
1377 case bfd_reloc_overflow:
1382 name = h->root.root.string;
1385 name = elf_string_from_elf_section (input_bfd,
1386 symtab_hdr->sh_link,
1391 name = bfd_section_name (input_bfd, sec);
1393 if (!(info->callbacks->reloc_overflow
1394 (info, name, howto->name, (bfd_vma) 0,
1395 input_bfd, input_section, rel->r_offset)))
1406 /* Finish up dynamic symbol handling. We set the contents of various
1407 dynamic sections here. */
1410 elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym)
1412 struct bfd_link_info *info;
1413 struct elf_link_hash_entry *h;
1414 Elf_Internal_Sym *sym;
1418 dynobj = elf_hash_table (info)->dynobj;
1420 if (h->plt_offset != (bfd_vma) -1)
1427 Elf_Internal_Rela rela;
1429 /* This symbol has an entry in the procedure linkage table. Set
1432 BFD_ASSERT (h->dynindx != -1);
1434 splt = bfd_get_section_by_name (dynobj, ".plt");
1435 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1436 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1437 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1439 /* Get the index in the procedure linkage table which
1440 corresponds to this symbol. This is the index of this symbol
1441 in all the symbols for which we are making plt entries. The
1442 first entry in the procedure linkage table is reserved. */
1443 plt_index = h->plt_offset / PLT_ENTRY_SIZE - 1;
1445 /* Get the offset into the .got table of the entry that
1446 corresponds to this function. Each .got entry is 4 bytes.
1447 The first three are reserved. */
1448 got_offset = (plt_index + 3) * 4;
1450 /* Fill in the entry in the procedure linkage table. */
1451 memcpy (splt->contents + h->plt_offset, elf_m68k_plt_entry,
1453 /* The offset is relative to the first extension word. */
1454 bfd_put_32 (output_bfd,
1455 (sgot->output_section->vma
1456 + sgot->output_offset
1458 - (splt->output_section->vma
1459 + h->plt_offset + 2)),
1460 splt->contents + h->plt_offset + 4);
1462 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
1463 splt->contents + h->plt_offset + 10);
1464 bfd_put_32 (output_bfd, - (h->plt_offset + 16),
1465 splt->contents + h->plt_offset + 16);
1467 /* Fill in the entry in the global offset table. */
1468 bfd_put_32 (output_bfd,
1469 (splt->output_section->vma
1470 + splt->output_offset
1473 sgot->contents + got_offset);
1475 /* Fill in the entry in the .rela.plt section. */
1476 rela.r_offset = (sgot->output_section->vma
1477 + sgot->output_offset
1479 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
1481 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1482 ((Elf32_External_Rela *) srela->contents
1485 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1487 /* Mark the symbol as undefined, rather than as defined in
1488 the .plt section. Leave the value alone. */
1489 sym->st_shndx = SHN_UNDEF;
1493 if (h->got_offset != (bfd_vma) -1)
1497 Elf_Internal_Rela rela;
1499 /* This symbol has an entry in the global offset table. Set it
1502 BFD_ASSERT (h->dynindx != -1);
1504 sgot = bfd_get_section_by_name (dynobj, ".got");
1505 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1506 BFD_ASSERT (sgot != NULL && srela != NULL);
1508 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got_offset);
1510 rela.r_offset = (sgot->output_section->vma
1511 + sgot->output_offset
1513 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
1515 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1516 ((Elf32_External_Rela *) srela->contents
1517 + srela->reloc_count));
1518 ++srela->reloc_count;
1521 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1524 Elf_Internal_Rela rela;
1526 /* This symbol needs a copy reloc. Set it up. */
1528 BFD_ASSERT (h->dynindx != -1
1529 && (h->root.type == bfd_link_hash_defined
1530 || h->root.type == bfd_link_hash_defweak));
1532 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1534 BFD_ASSERT (s != NULL);
1536 rela.r_offset = (h->root.u.def.value
1537 + h->root.u.def.section->output_section->vma
1538 + h->root.u.def.section->output_offset);
1539 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
1541 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1542 ((Elf32_External_Rela *) s->contents
1547 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1548 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1549 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1550 sym->st_shndx = SHN_ABS;
1555 /* Finish up the dynamic sections. */
1558 elf_m68k_finish_dynamic_sections (output_bfd, info)
1560 struct bfd_link_info *info;
1566 dynobj = elf_hash_table (info)->dynobj;
1568 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1569 BFD_ASSERT (sgot != NULL);
1570 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1572 if (elf_hash_table (info)->dynamic_sections_created)
1575 Elf32_External_Dyn *dyncon, *dynconend;
1577 splt = bfd_get_section_by_name (dynobj, ".plt");
1578 BFD_ASSERT (splt != NULL && sdyn != NULL);
1580 dyncon = (Elf32_External_Dyn *) sdyn->contents;
1581 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1582 for (; dyncon < dynconend; dyncon++)
1584 Elf_Internal_Dyn dyn;
1588 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1601 s = bfd_get_section_by_name (output_bfd, name);
1602 BFD_ASSERT (s != NULL);
1603 dyn.d_un.d_ptr = s->vma;
1604 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1608 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1609 BFD_ASSERT (s != NULL);
1610 if (s->_cooked_size != 0)
1611 dyn.d_un.d_val = s->_cooked_size;
1613 dyn.d_un.d_val = s->_raw_size;
1614 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1618 /* My reading of the SVR4 ABI indicates that the
1619 procedure linkage table relocs (DT_JMPREL) should be
1620 included in the overall relocs (DT_RELA). This is
1621 what Solaris does. However, UnixWare can not handle
1622 that case. Therefore, we override the DT_RELASZ entry
1623 here to make it not include the JMPREL relocs. Since
1624 the linker script arranges for .rela.plt to follow all
1625 other relocation sections, we don't have to worry
1626 about changing the DT_RELA entry. */
1627 /* FIXME: This comment is from elf32-i386.c, what about
1628 the SVR4/m68k implementations? */
1629 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1632 if (s->_cooked_size != 0)
1633 dyn.d_un.d_val -= s->_cooked_size;
1635 dyn.d_un.d_val -= s->_raw_size;
1637 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1642 /* Fill in the first entry in the procedure linkage table. */
1643 if (splt->_raw_size > 0)
1645 memcpy (splt->contents, elf_m68k_plt0_entry, PLT_ENTRY_SIZE);
1646 bfd_put_32 (output_bfd,
1647 (sgot->output_section->vma
1648 + sgot->output_offset + 4
1649 - (splt->output_section->vma + 2)),
1650 splt->contents + 4);
1651 bfd_put_32 (output_bfd,
1652 (sgot->output_section->vma
1653 + sgot->output_offset + 8
1654 - (splt->output_section->vma + 10)),
1655 splt->contents + 12);
1658 elf_section_data (splt->output_section)->this_hdr.sh_entsize
1662 /* Fill in the first three entries in the global offset table. */
1663 if (sgot->_raw_size > 0)
1666 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
1668 bfd_put_32 (output_bfd,
1669 sdyn->output_section->vma + sdyn->output_offset,
1671 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
1672 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
1675 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
1680 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
1681 #define TARGET_BIG_NAME "elf32-m68k"
1682 #define ELF_MACHINE_CODE EM_68K
1683 #define ELF_MAXPAGESIZE 0x2000
1684 #define elf_backend_create_dynamic_sections \
1685 elf_m68k_create_dynamic_sections
1686 #define elf_backend_check_relocs elf_m68k_check_relocs
1687 #define elf_backend_adjust_dynamic_symbol \
1688 elf_m68k_adjust_dynamic_symbol
1689 #define elf_backend_size_dynamic_sections \
1690 elf_m68k_size_dynamic_sections
1691 #define elf_backend_relocate_section elf_m68k_relocate_section
1692 #define elf_backend_finish_dynamic_symbol \
1693 elf_m68k_finish_dynamic_symbol
1694 #define elf_backend_finish_dynamic_sections \
1695 elf_m68k_finish_dynamic_sections
1697 #include "elf32-target.h"