From c83004d526c9f5e203926a979d405f7b720b9ede Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 28 May 2019 11:49:30 +0930 Subject: [PATCH] m68k linker segmentation faults This doesn't fix the underlying bug, but an abort is better than a segfault. PR 24596 * elf32-m68k.c (elf_m68k_get_got_entry): Don't create a new entry when MUST_FIND. Abort when MUST_FIND not found. (elf_m68k_get_bfd2got_entry): Likewise. (elf_m68k_relocate_section): Remove now useless assert. --- bfd/ChangeLog | 8 ++++++++ bfd/elf32-m68k.c | 35 +++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 72da0df..fd0dfcb 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,6 +1,14 @@ 2019-05-28 Alan Modra PR 24596 + * elf32-m68k.c (elf_m68k_get_got_entry): Don't create a new + entry when MUST_FIND. Abort when MUST_FIND not found. + (elf_m68k_get_bfd2got_entry): Likewise. + (elf_m68k_relocate_section): Remove now useless assert. + +2019-05-28 Alan Modra + + PR 24596 * elf64-hppa.c (elf64_hppa_finalize_dynreloc): Get the output bfd from bfd_link_info, not an output section owner. (elf64_hppa_finish_dynamic_symbol, elf64_hppa_finalize_opd): Likewise. diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index e8d9ed5..4efac79 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -1519,14 +1519,18 @@ elf_m68k_get_got_entry (struct elf_m68k_got *got, } entry_.key_ = *key; - ptr = htab_find_slot (got->entries, &entry_, (howto != SEARCH - ? INSERT : NO_INSERT)); + ptr = htab_find_slot (got->entries, &entry_, + (howto == SEARCH || howto == MUST_FIND ? NO_INSERT + : INSERT)); if (ptr == NULL) { if (howto == SEARCH) /* Entry not found. */ return NULL; + if (howto == MUST_FIND) + abort (); + /* We're out of memory. */ bfd_set_error (bfd_error_no_memory); return NULL; @@ -1535,7 +1539,10 @@ elf_m68k_get_got_entry (struct elf_m68k_got *got, if (*ptr == NULL) /* We didn't find the entry and we're asked to create a new one. */ { - BFD_ASSERT (howto != MUST_FIND && howto != SEARCH); + if (howto == MUST_FIND) + abort (); + + BFD_ASSERT (howto != SEARCH); entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)); if (entry == NULL) @@ -1750,14 +1757,18 @@ elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got, } entry_.bfd = abfd; - ptr = htab_find_slot (multi_got->bfd2got, &entry_, (howto != SEARCH - ? INSERT : NO_INSERT)); + ptr = htab_find_slot (multi_got->bfd2got, &entry_, + (howto == SEARCH || howto == MUST_FIND ? NO_INSERT + : INSERT)); if (ptr == NULL) { if (howto == SEARCH) /* Entry not found. */ return NULL; + if (howto == MUST_FIND) + abort (); + /* We're out of memory. */ bfd_set_error (bfd_error_no_memory); return NULL; @@ -1766,7 +1777,10 @@ elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got, if (*ptr == NULL) /* Entry was not found. Create new one. */ { - BFD_ASSERT (howto != MUST_FIND && howto != SEARCH); + if (howto == MUST_FIND) + abort (); + + BFD_ASSERT (howto != SEARCH); entry = ((struct elf_m68k_bfd2got_entry *) bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry))); @@ -3562,12 +3576,9 @@ elf_m68k_relocate_section (bfd *output_bfd, BFD_ASSERT (sgot != NULL); if (got == NULL) - { - got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), - input_bfd, MUST_FIND, - NULL)->got; - BFD_ASSERT (got != NULL); - } + got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info), + input_bfd, MUST_FIND, + NULL)->got; /* Get GOT offset for this symbol. */ elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx, -- 2.7.4