X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf32-m68k.c;h=2718564ea264f6f09e132bafe6a1bb06eb90ec2c;hb=38f14ab8fcfa4eab8bab417a5a165b7403ef9b0e;hp=1cb03aedd32cca6f7523cdaf2dbc3356ed3a7527;hpb=b70e7a2fdf5fac8cacce8335a2fd9a561480eafc;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index 1cb03aedd3..2718564ea2 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -1,7 +1,5 @@ /* Motorola 68k series support for 32-bit ELF - Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 - Free Software Foundation, Inc. + Copyright (C) 1993-2018 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -28,65 +26,34 @@ #include "elf/m68k.h" #include "opcode/m68k.h" -static reloc_howto_type *reloc_type_lookup - PARAMS ((bfd *, bfd_reloc_code_real_type)); -static void rtype_to_howto - PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); -static struct bfd_hash_entry *elf_m68k_link_hash_newfunc - PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); -static struct bfd_link_hash_table *elf_m68k_link_hash_table_create - PARAMS ((bfd *)); -static bfd_boolean elf_m68k_check_relocs - PARAMS ((bfd *, struct bfd_link_info *, asection *, - const Elf_Internal_Rela *)); -static bfd_boolean elf_m68k_adjust_dynamic_symbol - PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); -static bfd_boolean elf_m68k_size_dynamic_sections - PARAMS ((bfd *, struct bfd_link_info *)); -static bfd_boolean elf_m68k_discard_copies - PARAMS ((struct elf_link_hash_entry *, PTR)); -static bfd_boolean elf_m68k_relocate_section - PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, - Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); -static bfd_boolean elf_m68k_finish_dynamic_symbol - PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, - Elf_Internal_Sym *)); -static bfd_boolean elf_m68k_finish_dynamic_sections - PARAMS ((bfd *, struct bfd_link_info *)); - -static bfd_boolean elf32_m68k_set_private_flags - PARAMS ((bfd *, flagword)); -static bfd_boolean elf32_m68k_merge_private_bfd_data - PARAMS ((bfd *, bfd *)); -static bfd_boolean elf32_m68k_print_private_bfd_data - PARAMS ((bfd *, PTR)); -static enum elf_reloc_type_class elf32_m68k_reloc_type_class - PARAMS ((const Elf_Internal_Rela *)); - -static reloc_howto_type howto_table[] = { - HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE), - HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE), - HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE), - HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE), - HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE), - HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE), - HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE), - HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE), - HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE), - HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE), - HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE), - HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE), - HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE), - HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE), - HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE), - HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE), - HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE), - HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE), - HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE), - HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE), - 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), - 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), - HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE), +static bfd_boolean +elf_m68k_discard_copies (struct elf_link_hash_entry *, void *); + +static reloc_howto_type howto_table[] = +{ + HOWTO(R_68K_NONE, 0, 3, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE), + HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE), + HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE), + HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE), + HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE), + HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE), + HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE), + HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE), + HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE), + HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE), + HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE), + HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE), + HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE), + HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE), + HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE), + HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE), + HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE), + HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE), + HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE), + HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE), + 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), + 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), + HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE), /* GNU extension to record C++ vtable hierarchy. */ HOWTO (R_68K_GNU_VTINHERIT, /* type */ 0, /* rightshift */ @@ -381,8 +348,9 @@ rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) if (indx >= (unsigned int) R_68K_max) { - (*_bfd_error_handler) (_("%B: invalid relocation type %d"), - abfd, (int) indx); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, indx); indx = R_68K_NONE; } cache_ptr->howto = &howto_table[indx]; @@ -441,9 +409,8 @@ static const struct }; static reloc_howto_type * -reloc_type_lookup (abfd, code) - bfd *abfd ATTRIBUTE_UNUSED; - bfd_reloc_code_real_type code; +reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, + bfd_reloc_code_real_type code) { unsigned int i; for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++) @@ -541,7 +508,8 @@ static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] = 0, 0, 0, 0 /* + .plt - . */ }; -static const struct elf_m68k_plt_info elf_m68k_plt_info = { +static const struct elf_m68k_plt_info elf_m68k_plt_info = +{ PLT_ENTRY_SIZE, elf_m68k_plt0_entry, { 4, 12 }, elf_m68k_plt_entry, { 4, 16 }, 8 @@ -551,13 +519,13 @@ static const struct elf_m68k_plt_info elf_m68k_plt_info = { static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] = { - 0x20, 0x3c, /* move.l #offset,%d0 */ - 0, 0, 0, 0, /* + (.got + 4) - . */ + 0x20, 0x3c, /* move.l #offset,%d0 */ + 0, 0, 0, 0, /* + (.got + 4) - . */ 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */ - 0x20, 0x3c, /* move.l #offset,%d0 */ - 0, 0, 0, 0, /* + (.got + 8) - . */ + 0x20, 0x3c, /* move.l #offset,%d0 */ + 0, 0, 0, 0, /* + (.got + 8) - . */ 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ - 0x4e, 0xd0, /* jmp (%a0) */ + 0x4e, 0xd0, /* jmp (%a0) */ 0x4e, 0x71 /* nop */ }; @@ -565,17 +533,18 @@ static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] = static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] = { - 0x20, 0x3c, /* move.l #offset,%d0 */ - 0, 0, 0, 0, /* + (.got.plt entry) - . */ + 0x20, 0x3c, /* move.l #offset,%d0 */ + 0, 0, 0, 0, /* + (.got.plt entry) - . */ 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ - 0x4e, 0xd0, /* jmp (%a0) */ - 0x2f, 0x3c, /* move.l #offset,-(%sp) */ - 0, 0, 0, 0, /* + reloc index */ - 0x60, 0xff, /* bra.l .plt */ - 0, 0, 0, 0 /* + .plt - . */ + 0x4e, 0xd0, /* jmp (%a0) */ + 0x2f, 0x3c, /* move.l #offset,-(%sp) */ + 0, 0, 0, 0, /* + reloc index */ + 0x60, 0xff, /* bra.l .plt */ + 0, 0, 0, 0 /* + .plt - . */ }; -static const struct elf_m68k_plt_info elf_isab_plt_info = { +static const struct elf_m68k_plt_info elf_isab_plt_info = +{ ISAB_PLT_ENTRY_SIZE, elf_isab_plt0_entry, { 2, 12 }, elf_isab_plt_entry, { 2, 20 }, 12 @@ -606,10 +575,11 @@ static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] = 0x2f, 0x3c, /* move.l #offset,-(%sp) */ 0, 0, 0, 0, /* replaced with offset into relocation table */ 0x61, 0xff, /* bsr.l .plt */ - 0, 0, 0, 0 /* replaced with .plt - . */ + 0, 0, 0, 0 /* replaced with .plt - . */ }; -static const struct elf_m68k_plt_info elf_isac_plt_info = { +static const struct elf_m68k_plt_info elf_isac_plt_info = +{ ISAC_PLT_ENTRY_SIZE, elf_isac_plt0_entry, { 2, 12}, elf_isac_plt_entry, { 2, 20 }, 12 @@ -620,27 +590,28 @@ static const struct elf_m68k_plt_info elf_isac_plt_info = { static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] = { 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ - 0, 0, 0, 2, /* + (.got + 4) - . */ + 0, 0, 0, 2, /* + (.got + 4) - . */ 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ - 0, 0, 0, 2, /* + (.got + 8) - . */ - 0x4e, 0xd1, /* jmp %a1@ */ - 0, 0, 0, 0, /* pad out to 24 bytes. */ + 0, 0, 0, 2, /* + (.got + 8) - . */ + 0x4e, 0xd1, /* jmp %a1@ */ + 0, 0, 0, 0, /* pad out to 24 bytes. */ 0, 0 }; static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] = { 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ - 0, 0, 0, 2, /* + (.got.plt entry) - . */ - 0x4e, 0xd1, /* jmp %a1@ */ - 0x2f, 0x3c, /* move.l #offset,-(%sp) */ - 0, 0, 0, 0, /* + reloc index */ - 0x60, 0xff, /* bra.l .plt */ - 0, 0, 0, 0, /* + .plt - . */ + 0, 0, 0, 2, /* + (.got.plt entry) - . */ + 0x4e, 0xd1, /* jmp %a1@ */ + 0x2f, 0x3c, /* move.l #offset,-(%sp) */ + 0, 0, 0, 0, /* + reloc index */ + 0x60, 0xff, /* bra.l .plt */ + 0, 0, 0, 0, /* + .plt - . */ 0, 0 }; -static const struct elf_m68k_plt_info elf_cpu32_plt_info = { +static const struct elf_m68k_plt_info elf_cpu32_plt_info = +{ CPU32_PLT_ENTRY_SIZE, elf_cpu32_plt0_entry, { 4, 12 }, elf_cpu32_plt_entry, { 4, 18 }, 10 @@ -724,15 +695,14 @@ struct elf_m68k_got_entry { struct { - /* Number of times this entry is referenced. It is used to - filter out unnecessary GOT slots in elf_m68k_gc_sweep_hook. */ + /* Number of times this entry is referenced. */ bfd_vma refcount; } s1; struct { /* Offset from the start of .got section. To calculate offset relative - to GOT pointer one should substract got->offset from this value. */ + to GOT pointer one should subtract got->offset from this value. */ bfd_vma offset; /* Pointer to the next GOT entry for this global symbol. @@ -974,6 +944,23 @@ elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry, return ret; } +/* Destroy an m68k ELF linker hash table. */ + +static void +elf_m68k_link_hash_table_free (bfd *obfd) +{ + struct elf_m68k_link_hash_table *htab; + + htab = (struct elf_m68k_link_hash_table *) obfd->link.hash; + + if (htab->multi_got_.bfd2got != NULL) + { + htab_delete (htab->multi_got_.bfd2got); + htab->multi_got_.bfd2got = NULL; + } + _bfd_elf_link_hash_table_free (obfd); +} + /* Create an m68k ELF linker hash table. */ static struct bfd_link_hash_table * @@ -982,7 +969,7 @@ elf_m68k_link_hash_table_create (bfd *abfd) struct elf_m68k_link_hash_table *ret; bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table); - ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt); + ret = (struct elf_m68k_link_hash_table *) bfd_zmalloc (amt); if (ret == (struct elf_m68k_link_hash_table *) NULL) return NULL; @@ -994,34 +981,13 @@ elf_m68k_link_hash_table_create (bfd *abfd) free (ret); return NULL; } + ret->root.root.hash_table_free = elf_m68k_link_hash_table_free; - ret->sym_cache.abfd = NULL; - ret->plt_info = NULL; - ret->local_gp_p = FALSE; - ret->use_neg_got_offsets_p = FALSE; - ret->allow_multigot_p = FALSE; - ret->multi_got_.bfd2got = NULL; ret->multi_got_.global_symndx = 1; return &ret->root.root; } -/* Destruct local data. */ - -static void -elf_m68k_link_hash_table_free (struct bfd_link_hash_table *_htab) -{ - struct elf_m68k_link_hash_table *htab; - - htab = (struct elf_m68k_link_hash_table *) _htab; - - if (htab->multi_got_.bfd2got != NULL) - { - htab_delete (htab->multi_got_.bfd2got); - htab->multi_got_.bfd2got = NULL; - } -} - /* Set the right machine number. */ static bfd_boolean @@ -1145,9 +1111,7 @@ elf_m68k_final_write_processing (bfd *abfd, /* Keep m68k-specific flags in the ELF header. */ static bfd_boolean -elf32_m68k_set_private_flags (abfd, flags) - bfd *abfd; - flagword flags; +elf32_m68k_set_private_flags (bfd *abfd, flagword flags) { elf_elfheader (abfd)->e_flags = flags; elf_flags_init (abfd) = TRUE; @@ -1157,10 +1121,9 @@ elf32_m68k_set_private_flags (abfd, flags) /* Merge backend specific data from an object file to the output object file when linking. */ static bfd_boolean -elf32_m68k_merge_private_bfd_data (ibfd, obfd) - bfd *ibfd; - bfd *obfd; +elf32_m68k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) { + bfd *obfd = info->output_bfd; flagword out_flags; flagword in_flags; flagword out_isa; @@ -1642,27 +1605,6 @@ elf_m68k_update_got_entry_type (struct elf_m68k_got *got, return was; } -/* Update GOT counters when removing an entry of type TYPE. */ - -static void -elf_m68k_remove_got_entry_type (struct elf_m68k_got *got, - enum elf_m68k_reloc_type type) -{ - enum elf_m68k_got_offset_size os; - bfd_vma n_slots; - - n_slots = elf_m68k_reloc_got_n_slots (type); - - /* Decrese counter of slots with offset size corresponding to TYPE - and all greater offset sizes. */ - for (os = elf_m68k_reloc_got_offset_size (type); os <= R_32; ++os) - { - BFD_ASSERT (got->n_slots[os] >= n_slots); - - got->n_slots[os] -= n_slots; - } -} - /* Add new or update existing entry to GOT. H, ABFD, TYPE and SYMNDX is data for the entry. INFO is a context where memory should be allocated. */ @@ -1712,17 +1654,19 @@ elf_m68k_add_entry_to_got (struct elf_m68k_got *got, /* This BFD has too many relocation. */ { if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)) - (*_bfd_error_handler) (_("%B: GOT overflow: " - "Number of relocations with 8-bit " - "offset > %d"), - abfd, - ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: GOT overflow: " + "number of relocations with 8-bit " + "offset > %d"), + abfd, + ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info)); else - (*_bfd_error_handler) (_("%B: GOT overflow: " - "Number of relocations with 8- or 16-bit " - "offset > %d"), - abfd, - ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: GOT overflow: " + "number of relocations with 8- or 16-bit " + "offset > %d"), + abfd, + ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)); return NULL; } @@ -2274,7 +2218,7 @@ elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg) arg->n_slots += arg->current_got->n_slots[R_32]; - if (!arg->info->shared) + if (!bfd_link_pic (arg->info)) /* If we are generating a shared object, we need to output a R_68K_RELATIVE reloc so that the dynamic linker can adjust this GOT entry. Overwise we @@ -2387,7 +2331,7 @@ elf_m68k_partition_multi_got_1 (void **_entry, void *_arg) if (diff != NULL) elf_m68k_clear_got (diff); - return arg->error_p == FALSE ? 1 : 0; + return !arg->error_p; } /* Helper function to build symndx2h mapping. */ @@ -2468,7 +2412,7 @@ elf_m68k_partition_multi_got (struct bfd_link_info *info) { asection *s; - s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".got"); + s = elf_hash_table (info)->sgot; if (s != NULL) s->size = arg_.offset; else @@ -2477,7 +2421,7 @@ elf_m68k_partition_multi_got (struct bfd_link_info *info) BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots); arg_.n_slots -= arg_.slots_relas_diff; - s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".rela.got"); + s = elf_hash_table (info)->srelgot; if (s != NULL) s->size = arg_.n_slots * sizeof (Elf32_External_Rela); else @@ -2489,52 +2433,6 @@ elf_m68k_partition_multi_got (struct bfd_link_info *info) return TRUE; } -/* Specialized version of elf_m68k_get_got_entry that returns pointer - to hashtable slot, thus allowing removal of entry via - elf_m68k_remove_got_entry. */ - -static struct elf_m68k_got_entry ** -elf_m68k_find_got_entry_ptr (struct elf_m68k_got *got, - struct elf_m68k_got_entry_key *key) -{ - void **ptr; - struct elf_m68k_got_entry entry_; - struct elf_m68k_got_entry **entry_ptr; - - entry_.key_ = *key; - ptr = htab_find_slot (got->entries, &entry_, NO_INSERT); - BFD_ASSERT (ptr != NULL); - - entry_ptr = (struct elf_m68k_got_entry **) ptr; - - return entry_ptr; -} - -/* Remove entry pointed to by ENTRY_PTR from GOT. */ - -static void -elf_m68k_remove_got_entry (struct elf_m68k_got *got, - struct elf_m68k_got_entry **entry_ptr) -{ - struct elf_m68k_got_entry *entry; - - entry = *entry_ptr; - - /* Check that offsets have not been finalized yet. */ - BFD_ASSERT (got->offset == (bfd_vma) -1); - /* Check that this entry is indeed unused. */ - BFD_ASSERT (entry->u.s1.refcount == 0); - - elf_m68k_remove_got_entry_type (got, entry->key_.type); - - if (entry->key_.bfd != NULL) - got->local_n_slots -= elf_m68k_reloc_got_n_slots (entry->key_.type); - - BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots); - - htab_clear_slot (got->entries, (void **) entry_ptr); -} - /* Copy any information related to dynamic linking from a pre-existing symbol to a newly created symbol. Also called to copy flags and other back-end info to a weakdef, in which case the symbol is not @@ -2581,31 +2479,26 @@ elf_m68k_copy_indirect_symbol (struct bfd_link_info *info, table. */ static bfd_boolean -elf_m68k_check_relocs (abfd, info, sec, relocs) - bfd *abfd; - struct bfd_link_info *info; - asection *sec; - const Elf_Internal_Rela *relocs; +elf_m68k_check_relocs (bfd *abfd, + struct bfd_link_info *info, + asection *sec, + const Elf_Internal_Rela *relocs) { bfd *dynobj; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel_end; - asection *sgot; - asection *srelgot; asection *sreloc; struct elf_m68k_got *got; - if (info->relocatable) + if (bfd_link_relocatable (info)) return TRUE; dynobj = elf_hash_table (info)->dynobj; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - sgot = NULL; - srelgot = NULL; sreloc = NULL; got = NULL; @@ -2659,7 +2552,7 @@ elf_m68k_check_relocs (abfd, info, sec, relocs) case R_68K_TLS_DTPREL32: if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32 - && info->shared) + && bfd_link_pic (info)) /* Do the special chorus for libraries with static TLS. */ info->flags |= DF_STATIC_TLS; @@ -2673,32 +2566,6 @@ elf_m68k_check_relocs (abfd, info, sec, relocs) return FALSE; } - if (sgot == NULL) - { - sgot = bfd_get_section_by_name (dynobj, ".got"); - BFD_ASSERT (sgot != NULL); - } - - if (srelgot == NULL - && (h != NULL || info->shared)) - { - srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); - if (srelgot == NULL) - { - srelgot = bfd_make_section_with_flags (dynobj, - ".rela.got", - (SEC_ALLOC - | SEC_LOAD - | SEC_HAS_CONTENTS - | SEC_IN_MEMORY - | SEC_LINKER_CREATED - | SEC_READONLY)); - if (srelgot == NULL - || !bfd_set_section_alignment (dynobj, srelgot, 2)) - return FALSE; - } - } - if (got == NULL) { struct elf_m68k_bfd2got_entry *bfd2got_entry; @@ -2743,10 +2610,10 @@ elf_m68k_check_relocs (abfd, info, sec, relocs) case R_68K_PLT32: /* This symbol requires a procedure linkage table entry. We actually build the entry in adjust_dynamic_symbol, - because this might be a case of linking PIC code which is - never referenced by a dynamic object, in which case we - don't need to generate a procedure linkage table entry - after all. */ + because this might be a case of linking PIC code which is + never referenced by a dynamic object, in which case we + don't need to generate a procedure linkage table entry + after all. */ /* If this is a local symbol, we resolve it directly without creating a procedure linkage table entry. */ @@ -2796,10 +2663,10 @@ elf_m68k_check_relocs (abfd, info, sec, relocs) will be set later (it is never cleared). We account for that possibility below by storing information in the pcrel_relocs_copied field of the hash table entry. */ - if (!(info->shared + if (!(bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0 && h != NULL - && (!info->symbolic + && (!SYMBOLIC_BIND (info, h) || h->root.type == bfd_link_hash_defweak || !h->def_regular))) { @@ -2827,14 +2694,16 @@ elf_m68k_check_relocs (abfd, info, sec, relocs) turns out to be a function defined by a dynamic object. */ h->plt.refcount++; - if (info->executable) + if (bfd_link_executable (info)) /* This symbol needs a non-GOT reference. */ h->non_got_ref = 1; } /* If we are creating a shared library, we need to copy the reloc into the shared library. */ - if (info->shared) + if (bfd_link_pic (info) + && (h == NULL + || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))) { /* When creating a shared object, we must copy these reloc types into the output file. We create a reloc @@ -2964,131 +2833,6 @@ elf_m68k_gc_mark_hook (asection *sec, return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); } - -/* Update the got entry reference counts for the section being removed. */ - -static bfd_boolean -elf_m68k_gc_sweep_hook (bfd *abfd, - struct bfd_link_info *info, - asection *sec, - const Elf_Internal_Rela *relocs) -{ - Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes; - const Elf_Internal_Rela *rel, *relend; - bfd *dynobj; - struct elf_m68k_got *got; - - if (info->relocatable) - return TRUE; - - dynobj = elf_hash_table (info)->dynobj; - if (dynobj == NULL) - return TRUE; - - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; - sym_hashes = elf_sym_hashes (abfd); - got = NULL; - - relend = relocs + sec->reloc_count; - for (rel = relocs; rel < relend; rel++) - { - unsigned long r_symndx; - struct elf_link_hash_entry *h = NULL; - - r_symndx = ELF32_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_info) - { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; - while (h->root.type == bfd_link_hash_indirect - || h->root.type == bfd_link_hash_warning) - h = (struct elf_link_hash_entry *) h->root.u.i.link; - } - - switch (ELF32_R_TYPE (rel->r_info)) - { - case R_68K_GOT8: - case R_68K_GOT16: - case R_68K_GOT32: - if (h != NULL - && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) - break; - - /* FALLTHRU */ - case R_68K_GOT8O: - case R_68K_GOT16O: - case R_68K_GOT32O: - /* Fall through. */ - - /* TLS relocations. */ - case R_68K_TLS_GD8: - case R_68K_TLS_GD16: - case R_68K_TLS_GD32: - case R_68K_TLS_LDM8: - case R_68K_TLS_LDM16: - case R_68K_TLS_LDM32: - case R_68K_TLS_IE8: - case R_68K_TLS_IE16: - case R_68K_TLS_IE32: - - case R_68K_TLS_TPREL32: - case R_68K_TLS_DTPREL32: - - if (got == NULL) - { - got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), - abfd, MUST_FIND, NULL)->got; - BFD_ASSERT (got != NULL); - } - - { - struct elf_m68k_got_entry_key key_; - struct elf_m68k_got_entry **got_entry_ptr; - struct elf_m68k_got_entry *got_entry; - - elf_m68k_init_got_entry_key (&key_, h, abfd, r_symndx, - ELF32_R_TYPE (rel->r_info)); - got_entry_ptr = elf_m68k_find_got_entry_ptr (got, &key_); - - got_entry = *got_entry_ptr; - - if (got_entry->u.s1.refcount > 0) - { - --got_entry->u.s1.refcount; - - if (got_entry->u.s1.refcount == 0) - /* We don't need the .got entry any more. */ - elf_m68k_remove_got_entry (got, got_entry_ptr); - } - } - break; - - case R_68K_PLT8: - case R_68K_PLT16: - case R_68K_PLT32: - case R_68K_PLT8O: - case R_68K_PLT16O: - case R_68K_PLT32O: - case R_68K_PC8: - case R_68K_PC16: - case R_68K_PC32: - case R_68K_8: - case R_68K_16: - case R_68K_32: - if (h != NULL) - { - if (h->plt.refcount > 0) - --h->plt.refcount; - } - break; - - default: - break; - } - } - - return TRUE; -} /* Return the type of PLT associated with OUTPUT_BFD. */ @@ -3130,21 +2874,20 @@ elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info) understand. */ static bfd_boolean -elf_m68k_adjust_dynamic_symbol (info, h) - struct bfd_link_info *info; - struct elf_link_hash_entry *h; +elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info, + struct elf_link_hash_entry *h) { struct elf_m68k_link_hash_table *htab; bfd *dynobj; asection *s; htab = elf_m68k_hash_table (info); - dynobj = elf_hash_table (info)->dynobj; + dynobj = htab->root.dynobj; /* Make sure we know what is going on here. */ BFD_ASSERT (dynobj != NULL && (h->needs_plt - || h->u.weakdef != NULL + || h->is_weakalias || (h->def_dynamic && h->ref_regular && !h->def_regular))); @@ -3156,8 +2899,9 @@ elf_m68k_adjust_dynamic_symbol (info, h) || h->needs_plt) { if ((h->plt.refcount <= 0 - || SYMBOL_CALLS_LOCAL (info, h) - || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT + || SYMBOL_CALLS_LOCAL (info, h) + || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT + || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) && h->root.type == bfd_link_hash_undefweak)) /* We must always create the plt entry if it was referenced by a PLTxxO relocation. In this case we already recorded @@ -3182,7 +2926,7 @@ elf_m68k_adjust_dynamic_symbol (info, h) return FALSE; } - s = bfd_get_section_by_name (dynobj, ".plt"); + s = htab->root.splt; BFD_ASSERT (s != NULL); /* If this is the first .plt entry, make room for the special @@ -3195,7 +2939,7 @@ elf_m68k_adjust_dynamic_symbol (info, h) location in the .plt. This is required to make function pointers compare as equal between the normal executable and the shared library. */ - if (!info->shared + if (!bfd_link_pic (info) && !h->def_regular) { h->root.u.def.section = s; @@ -3209,12 +2953,12 @@ elf_m68k_adjust_dynamic_symbol (info, h) /* We also need to make an entry in the .got.plt section, which will be placed in the .got section by the linker script. */ - s = bfd_get_section_by_name (dynobj, ".got.plt"); + s = htab->root.sgotplt; BFD_ASSERT (s != NULL); s->size += 4; /* We also need to make an entry in the .rela.plt section. */ - s = bfd_get_section_by_name (dynobj, ".rela.plt"); + s = htab->root.srelplt; BFD_ASSERT (s != NULL); s->size += sizeof (Elf32_External_Rela); @@ -3228,12 +2972,12 @@ elf_m68k_adjust_dynamic_symbol (info, h) /* If this is a weak symbol, and there is a real definition, the processor independent code will have arranged for us to see the real definition first, and we can just use the same value. */ - if (h->u.weakdef != NULL) + if (h->is_weakalias) { - BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined - || h->u.weakdef->root.type == bfd_link_hash_defweak); - h->root.u.def.section = h->u.weakdef->root.u.def.section; - h->root.u.def.value = h->u.weakdef->root.u.def.value; + struct elf_link_hash_entry *def = weakdef (h); + BFD_ASSERT (def->root.type == bfd_link_hash_defined); + h->root.u.def.section = def->root.u.def.section; + h->root.u.def.value = def->root.u.def.value; return TRUE; } @@ -3244,7 +2988,7 @@ elf_m68k_adjust_dynamic_symbol (info, h) only references to the symbol are via the global offset table. For such cases we need not do anything here; the relocations will be handled correctly by relocate_section. */ - if (info->shared) + if (bfd_link_pic (info)) return TRUE; /* If there are no references to this symbol that do not use the @@ -3262,7 +3006,7 @@ elf_m68k_adjust_dynamic_symbol (info, h) both the dynamic object and the regular object will refer to the same memory location for the variable. */ - s = bfd_get_section_by_name (dynobj, ".dynbss"); + s = bfd_get_linker_section (dynobj, ".dynbss"); BFD_ASSERT (s != NULL); /* We must generate a R_68K_COPY reloc to tell the dynamic linker to @@ -3273,21 +3017,20 @@ elf_m68k_adjust_dynamic_symbol (info, h) { asection *srel; - srel = bfd_get_section_by_name (dynobj, ".rela.bss"); + srel = bfd_get_linker_section (dynobj, ".rela.bss"); BFD_ASSERT (srel != NULL); srel->size += sizeof (Elf32_External_Rela); h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Set the sizes of the dynamic sections. */ static bfd_boolean -elf_m68k_size_dynamic_sections (output_bfd, info) - bfd *output_bfd ATTRIBUTE_UNUSED; - struct bfd_link_info *info; +elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, + struct bfd_link_info *info) { bfd *dynobj; asection *s; @@ -3300,9 +3043,9 @@ elf_m68k_size_dynamic_sections (output_bfd, info) if (elf_hash_table (info)->dynamic_sections_created) { /* Set the contents of the .interp section to the interpreter. */ - if (info->executable) + if (bfd_link_executable (info) && !info->nointerp) { - s = bfd_get_section_by_name (dynobj, ".interp"); + s = bfd_get_linker_section (dynobj, ".interp"); BFD_ASSERT (s != NULL); s->size = sizeof ELF_DYNAMIC_INTERPRETER; s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; @@ -3315,7 +3058,7 @@ elf_m68k_size_dynamic_sections (output_bfd, info) not actually use these entries. Reset the size of .rela.got, which will cause it to get stripped from the output file below. */ - s = bfd_get_section_by_name (dynobj, ".rela.got"); + s = elf_hash_table (info)->srelgot; if (s != NULL) s->size = 0; } @@ -3326,10 +3069,10 @@ elf_m68k_size_dynamic_sections (output_bfd, info) against symbols that have become local due to visibility changes. We allocated space for them in the check_relocs routine, but we will not fill them in in the relocate_section routine. */ - if (info->shared) + if (bfd_link_pic (info)) elf_link_hash_traverse (elf_hash_table (info), elf_m68k_discard_copies, - (PTR) info); + info); /* The check_relocs and adjust_dynamic_symbol entry points have determined the sizes of the various dynamic sections. Allocate @@ -3409,7 +3152,7 @@ elf_m68k_size_dynamic_sections (output_bfd, info) #define add_dynamic_entry(TAG, VAL) \ _bfd_elf_add_dynamic_entry (info, TAG, VAL) - if (!info->shared) + if (bfd_link_executable (info)) { if (!add_dynamic_entry (DT_DEBUG, 0)) return FALSE; @@ -3457,9 +3200,8 @@ elf_m68k_size_dynamic_sections (output_bfd, info) case. */ static bfd_boolean -elf_m68k_discard_copies (h, inf) - struct elf_link_hash_entry *h; - PTR inf; +elf_m68k_discard_copies (struct elf_link_hash_entry *h, + void * inf) { struct bfd_link_info *info = (struct bfd_link_info *) inf; struct elf_m68k_pcrel_relocs_copied *s; @@ -3644,18 +3386,15 @@ elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info, /* Relocate an M68K ELF section. */ static bfd_boolean -elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, - contents, relocs, local_syms, local_sections) - bfd *output_bfd; - struct bfd_link_info *info; - bfd *input_bfd; - asection *input_section; - bfd_byte *contents; - Elf_Internal_Rela *relocs; - Elf_Internal_Sym *local_syms; - asection **local_sections; +elf_m68k_relocate_section (bfd *output_bfd, + struct bfd_link_info *info, + bfd *input_bfd, + asection *input_section, + bfd_byte *contents, + Elf_Internal_Rela *relocs, + Elf_Internal_Sym *local_syms, + asection **local_sections) { - bfd *dynobj; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; asection *sgot; @@ -3666,7 +3405,6 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; - dynobj = elf_hash_table (info)->dynobj; symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); @@ -3690,6 +3428,7 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, bfd_vma relocation; bfd_boolean unresolved_reloc; bfd_reloc_status_type r; + bfd_boolean resolved_to_zero; r_type = ELF32_R_TYPE (rel->r_info); if (r_type < 0 || r_type >= (int) R_68K_max) @@ -3714,21 +3453,24 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, } else { - bfd_boolean warned; + bfd_boolean warned, ignored; RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, r_symndx, symtab_hdr, sym_hashes, h, sec, relocation, - unresolved_reloc, warned); + unresolved_reloc, warned, ignored); } if (sec != NULL && discarded_section (sec)) RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, rel, 1, relend, howto, 0, contents); - if (info->relocatable) + if (bfd_link_relocatable (info)) continue; + resolved_to_zero = (h != NULL + && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); + switch (r_type) { case R_68K_GOT8: @@ -3744,21 +3486,16 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, bfd_vma sgot_output_offset; bfd_vma got_offset; - if (sgot == NULL) - { - sgot = bfd_get_section_by_name (dynobj, ".got"); + sgot = elf_hash_table (info)->sgot; - if (sgot != NULL) - sgot_output_offset = sgot->output_offset; - else - /* In this case we have a reference to - _GLOBAL_OFFSET_TABLE_, but the GOT itself is - empty. - ??? Issue a warning? */ - sgot_output_offset = 0; - } - else + if (sgot != NULL) sgot_output_offset = sgot->output_offset; + else + /* In this case we have a reference to + _GLOBAL_OFFSET_TABLE_, but the GOT itself is + empty. + ??? Issue a warning? */ + sgot_output_offset = 0; if (got == NULL) { @@ -3819,11 +3556,8 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, bfd_vma *off_ptr; bfd_vma off; - if (sgot == NULL) - { - sgot = bfd_get_section_by_name (dynobj, ".got"); - BFD_ASSERT (sgot != NULL); - } + sgot = elf_hash_table (info)->sgot; + BFD_ASSERT (sgot != NULL); if (got == NULL) { @@ -3856,10 +3590,13 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, bfd_boolean dyn; dyn = elf_hash_table (info)->dynamic_sections_created; - if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) - || (info->shared + if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, + bfd_link_pic (info), + h) + || (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) - || (ELF_ST_VISIBILITY (h->other) + || ((ELF_ST_VISIBILITY (h->other) + || resolved_to_zero) && h->root.type == bfd_link_hash_undefweak)) { /* This is actually a static link, or it is a @@ -3887,14 +3624,11 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, else unresolved_reloc = FALSE; } - else if (info->shared) /* && h == NULL */ + else if (bfd_link_pic (info)) /* && h == NULL */ /* Process local symbol during dynamic link. */ { - if (srela == NULL) - { - srela = bfd_get_section_by_name (dynobj, ".rela.got"); - BFD_ASSERT (srela != NULL); - } + srela = elf_hash_table (info)->srelgot; + BFD_ASSERT (srela != NULL); elf_m68k_init_got_entry_local_shared (info, output_bfd, @@ -3906,7 +3640,7 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, *off_ptr |= 1; } - else /* h == NULL && !info->shared */ + else /* h == NULL && !bfd_link_pic (info) */ { elf_m68k_init_got_entry_static (info, output_bfd, @@ -3960,12 +3694,14 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8: - if (info->shared && !info->pie) + if (bfd_link_dll (info)) { - (*_bfd_error_handler) - (_("%B(%A+0x%lx): R_68K_TLS_LE32 relocation not permitted " - "in shared object"), - input_bfd, input_section, (long) rel->r_offset, howto->name); + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB(%pA+%#" PRIx64 "): " + "%s relocation not permitted in shared object"), + input_bfd, input_section, (uint64_t) rel->r_offset, + howto->name); return FALSE; } @@ -3994,11 +3730,8 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, break; } - if (splt == NULL) - { - splt = bfd_get_section_by_name (dynobj, ".plt"); - BFD_ASSERT (splt != NULL); - } + splt = elf_hash_table (info)->splt; + BFD_ASSERT (splt != NULL); relocation = (splt->output_section->vma + splt->output_offset @@ -4013,11 +3746,8 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, the procedure linkage table. */ BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1); - if (splt == NULL) - { - splt = bfd_get_section_by_name (dynobj, ".plt"); - BFD_ASSERT (splt != NULL); - } + splt = elf_hash_table (info)->splt; + BFD_ASSERT (splt != NULL); relocation = h->plt.offset; unresolved_reloc = FALSE; @@ -4033,11 +3763,12 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, case R_68K_PC8: case R_68K_PC16: case R_68K_PC32: - if (info->shared + if (bfd_link_pic (info) && r_symndx != STN_UNDEF && (input_section->flags & SEC_ALLOC) != 0 && (h == NULL - || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + && !resolved_to_zero) || h->root.type != bfd_link_hash_undefweak) && ((r_type != R_68K_PC8 && r_type != R_68K_PC16 @@ -4072,8 +3803,8 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, && (r_type == R_68K_PC8 || r_type == R_68K_PC16 || r_type == R_68K_PC32 - || !info->shared - || !info->symbolic + || !bfd_link_pic (info) + || !SYMBOLIC_BIND (info, h) || !h->def_regular)) { outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); @@ -4134,9 +3865,9 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); /* This reloc will be computed at runtime, so there's no - need to do anything now, except for R_68K_32 - relocations that have been turned into - R_68K_RELATIVE. */ + need to do anything now, except for R_68K_32 + relocations that have been turned into + R_68K_RELATIVE. */ if (!relocate) continue; } @@ -4161,11 +3892,13 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, && _bfd_elf_section_offset (output_bfd, info, input_section, rel->r_offset) != (bfd_vma) -1) { - (*_bfd_error_handler) - (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB(%pA+%#" PRIx64 "): " + "unresolvable %s relocation against symbol `%s'"), input_bfd, input_section, - (long) rel->r_offset, + (uint64_t) rel->r_offset, howto->name, h->root.root.string); return FALSE; @@ -4195,13 +3928,15 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, name = bfd_section_name (input_bfd, sec); } - (*_bfd_error_handler) + _bfd_error_handler ((sym_type == STT_TLS - ? _("%B(%A+0x%lx): %s used with TLS symbol %s") - : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), + /* xgettext:c-format */ + ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s") + /* xgettext:c-format */ + : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")), input_bfd, input_section, - (long) rel->r_offset, + (uint64_t) rel->r_offset, howto->name, name); } @@ -4229,19 +3964,16 @@ elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, } if (r == bfd_reloc_overflow) - { - if (!(info->callbacks->reloc_overflow - (info, (h ? &h->root : NULL), name, howto->name, - (bfd_vma) 0, input_bfd, input_section, - rel->r_offset))) - return FALSE; - } + (*info->callbacks->reloc_overflow) + (info, (h ? &h->root : NULL), name, howto->name, + (bfd_vma) 0, input_bfd, input_section, rel->r_offset); else { - (*_bfd_error_handler) - (_("%B(%A+0x%lx): reloc against `%s': error %d"), + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"), input_bfd, input_section, - (long) rel->r_offset, name, (int) r); + (uint64_t) rel->r_offset, name, (int) r); return FALSE; } } @@ -4269,11 +4001,10 @@ elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value) dynamic sections here. */ static bfd_boolean -elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) - bfd *output_bfd; - struct bfd_link_info *info; - struct elf_link_hash_entry *h; - Elf_Internal_Sym *sym; +elf_m68k_finish_dynamic_symbol (bfd *output_bfd, + struct bfd_link_info *info, + struct elf_link_hash_entry *h, + Elf_Internal_Sym *sym) { bfd *dynobj; @@ -4296,9 +4027,9 @@ elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) BFD_ASSERT (h->dynindx != -1); plt_info = elf_m68k_hash_table (info)->plt_info; - splt = bfd_get_section_by_name (dynobj, ".plt"); - sgot = bfd_get_section_by_name (dynobj, ".got.plt"); - srela = bfd_get_section_by_name (dynobj, ".rela.plt"); + splt = elf_hash_table (info)->splt; + sgot = elf_hash_table (info)->sgotplt; + srela = elf_hash_table (info)->srelplt; BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); /* Get the index in the procedure linkage table which @@ -4363,8 +4094,8 @@ elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) /* This symbol has an entry in the global offset table. Set it up. */ - sgot = bfd_get_section_by_name (dynobj, ".got"); - srela = bfd_get_section_by_name (dynobj, ".rela.got"); + sgot = elf_hash_table (info)->sgot; + srela = elf_hash_table (info)->srelgot; BFD_ASSERT (sgot != NULL && srela != NULL); got_entry = elf_m68k_hash_entry (h)->glist; @@ -4382,7 +4113,7 @@ elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) the symbol was forced to be local because of a version file. The entry in the global offset table already have been initialized in the relocate_section function. */ - if (info->shared + if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) { bfd_vma relocation; @@ -4487,8 +4218,7 @@ elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak)); - s = bfd_get_section_by_name (h->root.u.def.section->owner, - ".rela.bss"); + s = bfd_get_linker_section (dynobj, ".rela.bss"); BFD_ASSERT (s != NULL); rela.r_offset = (h->root.u.def.value @@ -4506,9 +4236,7 @@ elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) /* Finish up the dynamic sections. */ static bfd_boolean -elf_m68k_finish_dynamic_sections (output_bfd, info) - bfd *output_bfd; - struct bfd_link_info *info; +elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) { bfd *dynobj; asection *sgot; @@ -4516,16 +4244,16 @@ elf_m68k_finish_dynamic_sections (output_bfd, info) dynobj = elf_hash_table (info)->dynobj; - sgot = bfd_get_section_by_name (dynobj, ".got.plt"); + sgot = elf_hash_table (info)->sgotplt; BFD_ASSERT (sgot != NULL); - sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); + sdyn = bfd_get_linker_section (dynobj, ".dynamic"); if (elf_hash_table (info)->dynamic_sections_created) { asection *splt; Elf32_External_Dyn *dyncon, *dynconend; - splt = bfd_get_section_by_name (dynobj, ".plt"); + splt = elf_hash_table (info)->splt; BFD_ASSERT (splt != NULL && sdyn != NULL); dyncon = (Elf32_External_Dyn *) sdyn->contents; @@ -4533,7 +4261,6 @@ elf_m68k_finish_dynamic_sections (output_bfd, info) for (; dyncon < dynconend; dyncon++) { Elf_Internal_Dyn dyn; - const char *name; asection *s; bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); @@ -4544,37 +4271,20 @@ elf_m68k_finish_dynamic_sections (output_bfd, info) break; case DT_PLTGOT: - name = ".got"; + s = elf_hash_table (info)->sgotplt; goto get_vma; case DT_JMPREL: - name = ".rela.plt"; + s = elf_hash_table (info)->srelplt; get_vma: - s = bfd_get_section_by_name (output_bfd, name); - BFD_ASSERT (s != NULL); - dyn.d_un.d_ptr = s->vma; + dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; case DT_PLTRELSZ: - s = bfd_get_section_by_name (output_bfd, ".rela.plt"); - BFD_ASSERT (s != NULL); + s = elf_hash_table (info)->srelplt; dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* The procedure linkage table relocs (DT_JMPREL) should - not be included in the overall relocs (DT_RELA). - Therefore, we override the DT_RELASZ entry here to - make it not include the JMPREL relocs. Since the - linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = bfd_get_section_by_name (output_bfd, ".rela.plt"); - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -4627,12 +4337,9 @@ elf_m68k_finish_dynamic_sections (output_bfd, info) objects, and before the final_link entry point is called. */ bfd_boolean -bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) - bfd *abfd; - struct bfd_link_info *info; - asection *datasec; - asection *relsec; - char **errmsg; +bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info, + asection *datasec, asection *relsec, + char **errmsg) { Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Sym *isymbuf = NULL; @@ -4641,7 +4348,7 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) bfd_byte *p; bfd_size_type amt; - BFD_ASSERT (! info->relocatable); + BFD_ASSERT (! bfd_link_relocatable (info)); *errmsg = NULL; @@ -4652,7 +4359,7 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) /* Get a copy of the native relocations. */ internal_relocs = (_bfd_elf_link_read_relocs - (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL, + (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL, info->keep_memory)); if (internal_relocs == NULL) goto error_return; @@ -4678,7 +4385,7 @@ bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) /* We can only relocate absolute longword relocs at run time. */ if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32) { - *errmsg = _("unsupported reloc type"); + *errmsg = _("unsupported relocation type"); bfd_set_error (bfd_error_bad_value); goto error_return; } @@ -4790,8 +4497,9 @@ bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling) } static enum elf_reloc_type_class -elf32_m68k_reloc_type_class (rela) - const Elf_Internal_Rela *rela; +elf32_m68k_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, + const asection *rel_sec ATTRIBUTE_UNUSED, + const Elf_Internal_Rela *rela) { switch ((int) ELF32_R_TYPE (rela->r_info)) { @@ -4831,10 +4539,10 @@ elf_m68k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) case 154: /* Linux/m68k */ /* pr_cursig */ - elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); + elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); /* pr_pid */ - elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 22); + elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22); /* pr_reg */ offset = 70; @@ -4857,11 +4565,11 @@ elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) return FALSE; case 124: /* Linux/m68k elf_prpsinfo. */ - elf_tdata (abfd)->core_pid + elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 12); - elf_tdata (abfd)->core_program + elf_tdata (abfd)->core->program = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); - elf_tdata (abfd)->core_command + elf_tdata (abfd)->core->command = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); } @@ -4869,7 +4577,7 @@ elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) onto the end of the args in some (at least one anyway) implementations, so strip it off if it exists. */ { - char *command = elf_tdata (abfd)->core_command; + char *command = elf_tdata (abfd)->core->command; int n = strlen (command); if (n > 0 && command[n - 1] == ' ') @@ -4879,7 +4587,27 @@ elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) return TRUE; } -#define TARGET_BIG_SYM bfd_elf32_m68k_vec +/* Hook called by the linker routine which adds symbols from an object + file. */ + +static bfd_boolean +elf_m68k_add_symbol_hook (bfd *abfd, + struct bfd_link_info *info, + Elf_Internal_Sym *sym, + const char **namep ATTRIBUTE_UNUSED, + flagword *flagsp ATTRIBUTE_UNUSED, + asection **secp ATTRIBUTE_UNUSED, + bfd_vma *valp ATTRIBUTE_UNUSED) +{ + if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC + && (abfd->flags & DYNAMIC) == 0 + && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour) + elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc; + + return TRUE; +} + +#define TARGET_BIG_SYM m68k_elf32_vec #define TARGET_BIG_NAME "elf32-m68k" #define ELF_MACHINE_CODE EM_68K #define ELF_MAXPAGESIZE 0x2000 @@ -4887,9 +4615,6 @@ elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) _bfd_elf_create_dynamic_sections #define bfd_elf32_bfd_link_hash_table_create \ elf_m68k_link_hash_table_create -/* ??? Should it be this macro or bfd_elfNN_bfd_link_hash_table_create? */ -#define bfd_elf32_bfd_link_hash_table_free \ - elf_m68k_link_hash_table_free #define bfd_elf32_bfd_final_link bfd_elf_final_link #define elf_backend_check_relocs elf_m68k_check_relocs @@ -4907,19 +4632,19 @@ elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) #define elf_backend_finish_dynamic_sections \ elf_m68k_finish_dynamic_sections #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook -#define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol #define bfd_elf32_bfd_merge_private_bfd_data \ - elf32_m68k_merge_private_bfd_data + elf32_m68k_merge_private_bfd_data #define bfd_elf32_bfd_set_private_flags \ - elf32_m68k_set_private_flags + elf32_m68k_set_private_flags #define bfd_elf32_bfd_print_private_bfd_data \ - elf32_m68k_print_private_bfd_data + elf32_m68k_print_private_bfd_data #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class #define elf_backend_plt_sym_val elf_m68k_plt_sym_val #define elf_backend_object_p elf32_m68k_object_p #define elf_backend_grok_prstatus elf_m68k_grok_prstatus #define elf_backend_grok_psinfo elf_m68k_grok_psinfo +#define elf_backend_add_symbol_hook elf_m68k_add_symbol_hook #define elf_backend_can_gc_sections 1 #define elf_backend_can_refcount 1 @@ -4928,5 +4653,8 @@ elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 + +#define elf_backend_linux_prpsinfo32_ugid16 TRUE #include "elf32-target.h"