From: Alan Modra Date: Sat, 18 Apr 2026 08:07:13 +0000 (+0930) Subject: Don't create got in bfin_relocate_section X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d88b58231ebf1d1a963bf194bf0666174b3a6547;p=thirdparty%2Fbinutils-gdb.git Don't create got in bfin_relocate_section Commit 7a84e3daf81a created .got in relocate_section which according to https://sourceware.org/pipermail/binutils/2008-February/055281.html was to "fix a crash when linking incompatible object files (normal vs. FD-PIC)". I can see how that happens by inspecting the two check_relocs functions, and note that Bernd's change to merge_private_bfd_data will cause a linker error on trying to link incompatible ABI objects before relocate_section is reached. However a user can silence the error with --no-warn-mismatch. It is far too late to be creating sections in relocate_sections. They won't be output. * elf32-bfin.c (bfin_relocate_section): Do not create .got here to avoid a segfault. Instead report an unresolvable relocation error if .got has not already been created. --- diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c index 0b87cd92b17..940fdc8c7a9 100644 --- a/bfd/elf32-bfin.c +++ b/bfd/elf32-bfin.c @@ -1369,7 +1369,6 @@ bfin_relocate_section (bfd * output_bfd, Elf_Internal_Sym * local_syms, asection ** local_sections) { - bfd *dynobj; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; bfd_vma *local_got_offsets; @@ -1377,7 +1376,6 @@ bfin_relocate_section (bfd * output_bfd, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; - dynobj = elf_hash_table (info)->dynobj; symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); @@ -1462,24 +1460,19 @@ bfin_relocate_section (bfd * output_bfd, if (h != NULL && strcmp (h->root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0) goto do_default; - /* Fall through. */ + /* Relocation is the offset of the entry for this symbol in the global offset table. */ + sgot = elf_hash_table (info)->sgot; + if (sgot == NULL) + { + r = bfd_reloc_undefined; + goto report_error; + } { bfd_vma off; - if (dynobj == NULL) - { - /* Create the .got section. */ - elf_hash_table (info)->dynobj = dynobj = output_bfd; - if (!_bfd_elf_create_got_section (dynobj, info)) - return false; - } - - sgot = elf_hash_table (info)->sgot; - BFD_ASSERT (sgot != NULL); - if (h != NULL) { bool dyn; @@ -1565,14 +1558,13 @@ bfin_relocate_section (bfd * output_bfd, /* bfin : preg = [preg + 17bitdiv4offset] relocation is div by 4. */ relocation /= 4; } - goto do_default; + /* Fall through. */ default: do_default: r = bfin_final_link_relocate (rel, howto, input_bfd, input_section, contents, address, relocation, rel->r_addend); - break; } @@ -1583,16 +1575,9 @@ bfin_relocate_section (bfd * output_bfd, && !((input_section->flags & SEC_DEBUGGING) != 0 && h->def_dynamic) && _bfd_elf_section_offset (output_bfd, info, input_section, rel->r_offset) != (bfd_vma) -1) - { - _bfd_error_handler - /* xgettext:c-format */ - (_("%pB(%pA+%#" PRIx64 "): " - "unresolvable relocation against symbol `%s'"), - input_bfd, input_section, (uint64_t) rel->r_offset, - h->root.root.string); - return false; - } + r = bfd_reloc_undefined; + report_error: if (r != bfd_reloc_ok) { const char *name; @@ -1614,6 +1599,15 @@ bfin_relocate_section (bfd * output_bfd, (*info->callbacks->reloc_overflow) (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0, input_bfd, input_section, rel->r_offset); + else if (r == bfd_reloc_undefined) + { + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB(%pA+%#" PRIx64 "): " + "unresolvable relocation against symbol `%s'"), + input_bfd, input_section, (uint64_t) rel->r_offset, name); + return false; + } else { _bfd_error_handler