From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 656C13858423; Tue, 20 Jun 2023 02:58:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 656C13858423 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Don't segfault in mips reloc special_functions X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: a89e364b45a93acd20f48abd787ef5cb7c07f683 X-Git-Newrev: 75e73c6cadcc064c2a0fd03396666574cd5335ca Message-Id: <20230620025850.656C13858423@sourceware.org> Date: Tue, 20 Jun 2023 02:58:50 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jun 2023 02:58:50 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D75e73c6cadcc= 064c2a0fd03396666574cd5335ca commit 75e73c6cadcc064c2a0fd03396666574cd5335ca Author: Alan Modra Date: Tue Jun 20 09:46:03 2023 +0930 Don't segfault in mips reloc special_functions =20 A symbol defined in a section from a shared library will have a NULL section->output_section during linking. =20 * elf32-mips.c (gprel32_with_gp): Don't segfault on NULL symbol->section->output_section. * elf64-mips.c (mips_elf64_gprel32_reloc): Likewise. * elfn32-mips.c (mips_elf_gprel16_reloc): Likewise. (mips_elf_literal_reloc, mips_elf_gprel32_reloc): Likewise. (gprel32_with_gp, mips16_gprel_reloc): Likewise. * elfxx-mips.c (_bfd_mips_elf_gprel16_with_gp): Likewise. (_bfd_mips_elf_generic_reloc): Likewise. Diff: --- bfd/elf32-mips.c | 7 +++++-- bfd/elf64-mips.c | 7 +++++-- bfd/elfn32-mips.c | 19 +++++++++++++------ bfd/elfxx-mips.c | 10 +++++++--- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index 34ffa67edec..03be42e845c 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -1858,8 +1858,11 @@ gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent= *reloc_entry, else relocation =3D symbol->value; =20 - relocation +=3D symbol->section->output_section->vma; - relocation +=3D symbol->section->output_offset; + if (symbol->section->output_section !=3D NULL) + { + relocation +=3D symbol->section->output_section->vma; + relocation +=3D symbol->section->output_offset; + } =20 if (!_bfd_mips_reloc_offset_in_range (abfd, input_section, reloc_entry, check_inplace)) diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c index 0530be1253f..9af4e4047e3 100644 --- a/bfd/elf64-mips.c +++ b/bfd/elf64-mips.c @@ -3577,8 +3577,11 @@ mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_= entry, asymbol *symbol, else relocation =3D symbol->value; =20 - relocation +=3D symbol->section->output_section->vma; - relocation +=3D symbol->section->output_offset; + if (symbol->section->output_section !=3D NULL) + { + relocation +=3D symbol->section->output_section->vma; + relocation +=3D symbol->section->output_offset; + } =20 if (!_bfd_mips_reloc_offset_in_range (abfd, input_section, reloc_entry, check_inplace)) diff --git a/bfd/elfn32-mips.c b/bfd/elfn32-mips.c index 3ae11e2f992..ab3b58994ba 100644 --- a/bfd/elfn32-mips.c +++ b/bfd/elfn32-mips.c @@ -3300,7 +3300,8 @@ mips_elf_gprel16_reloc (bfd *abfd ATTRIBUTE_UNUSED, a= relent *reloc_entry, else { relocatable =3D false; - output_bfd =3D symbol->section->output_section->owner; + if (symbol->section->output_section !=3D NULL) + output_bfd =3D symbol->section->output_section->owner; } =20 ret =3D mips_elf_final_gp (output_bfd, symbol, relocatable, error_messag= e, @@ -3340,7 +3341,8 @@ mips_elf_literal_reloc (bfd *abfd, arelent *reloc_ent= ry, asymbol *symbol, else { relocatable =3D false; - output_bfd =3D symbol->section->output_section->owner; + if (symbol->section->output_section !=3D NULL) + output_bfd =3D symbol->section->output_section->owner; } =20 ret =3D mips_elf_final_gp (output_bfd, symbol, relocatable, error_messag= e, @@ -3383,7 +3385,8 @@ mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_ent= ry, asymbol *symbol, else { relocatable =3D false; - output_bfd =3D symbol->section->output_section->owner; + if (symbol->section->output_section !=3D NULL) + output_bfd =3D symbol->section->output_section->owner; =20 ret =3D mips_elf_final_gp (output_bfd, symbol, relocatable, error_message, &gp); @@ -3408,8 +3411,11 @@ gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent= *reloc_entry, else relocation =3D symbol->value; =20 - relocation +=3D symbol->section->output_section->vma; - relocation +=3D symbol->section->output_offset; + if (symbol->section->output_section !=3D NULL) + { + relocation +=3D symbol->section->output_section->vma; + relocation +=3D symbol->section->output_offset; + } =20 if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, input_section, reloc_entry->address)) @@ -3484,7 +3490,8 @@ mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, = asymbol *symbol, else { relocatable =3D false; - output_bfd =3D symbol->section->output_section->owner; + if (symbol->section->output_section !=3D NULL) + output_bfd =3D symbol->section->output_section->owner; } =20 ret =3D mips_elf_final_gp (output_bfd, symbol, relocatable, error_messag= e, diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 4dfd8d04610..71f2dc9d779 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -2481,8 +2481,11 @@ _bfd_mips_elf_gprel16_with_gp (bfd *abfd, asymbol *s= ymbol, else relocation =3D symbol->value; =20 - relocation +=3D symbol->section->output_section->vma; - relocation +=3D symbol->section->output_offset; + if (symbol->section->output_section !=3D NULL) + { + relocation +=3D symbol->section->output_section->vma; + relocation +=3D symbol->section->output_offset; + } =20 /* Set val to the offset into the section or symbol. */ val =3D reloc_entry->addend; @@ -2673,7 +2676,8 @@ _bfd_mips_elf_generic_reloc (bfd *abfd ATTRIBUTE_UNUS= ED, arelent *reloc_entry, =20 /* Build up the field adjustment in VAL. */ val =3D 0; - if (!relocatable || (symbol->flags & BSF_SECTION_SYM) !=3D 0) + if ((!relocatable || (symbol->flags & BSF_SECTION_SYM) !=3D 0) + && symbol->section->output_section !=3D NULL) { /* Either we're calculating the final field value or we have a relocation against a section symbol. Add in the section's