public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Fix linker crash in section symbol check.
@ 2019-03-21 22:17 Jim Wilson
  0 siblings, 0 replies; only message in thread
From: Jim Wilson @ 2019-03-21 22:17 UTC (permalink / raw)
  To: binutils; +Cc: Jim Wilson

sym is only set for local symbols.  h is only set for global symbols.  Gas
won't let me create a global section symbol, but bfd appears to have some
support for that, and I can't rule out that other assemblers might do this.
So we need to support both, and verify sym and h are non-NULL before using.

Tested with cross build for 32/64-bit elf/linux.  There were no regressions.

Committed.

Jim

	bfd/
	PR 24365
	* elfnn-riscv.c (riscv_elf_relocate_section): For STT_SECTION check,
	verify sym non-NULL before using.  Add identical check using h.
---
 bfd/elfnn-riscv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 0a0ceb7930..bb114e59c7 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2059,7 +2059,9 @@ riscv_elf_relocate_section (bfd *output_bfd,
 	     all relocs to update these addends.  This is also ambiguous, as
 	     we do allow offsets to be added to the target address, which are
 	     not to be used to find the auipc address.  */
-	  if ((ELF_ST_TYPE (sym->st_info) == STT_SECTION) && rel->r_addend)
+	  if (((sym != NULL && (ELF_ST_TYPE (sym->st_info) == STT_SECTION))
+	       || (h != NULL && h->type == STT_SECTION))
+	      && rel->r_addend)
 	    {
 	      r = bfd_reloc_dangerous;
 	      break;
-- 
2.17.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-03-21 22:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-21 22:17 [PATCH] RISC-V: Fix linker crash in section symbol check Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).