Skip to content

Commit

Permalink
RISC-V: Fix linker crash in section symbol check.
Browse files Browse the repository at this point in the history
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.

	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.
  • Loading branch information
Jim Wilson committed Mar 21, 2019
1 parent 4e53911 commit a9f5a55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions bfd/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2019-03-21 Jim Wilson <jimw@sifive.com>

PR 24365
* elfnn-riscv.c (riscv_elf_relocate_section): For STT_SECTION check,
verify sym non-NULL before using. Add identical check using h.

2019-03-21 Sudakshina Das <sudi.das@arm.com>

* elf-bfd.h (struct elf_backend_data): Add argument to
Expand Down
4 changes: 3 additions & 1 deletion bfd/elfnn-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a9f5a55

Please sign in to comment.