Skip to content

Commit

Permalink
Fix some broken relocation handling
Browse files Browse the repository at this point in the history
In a few cases, the symbol lookup is missing before attempting to
perform the relocation. While the relocation types affected are
currently unused, this results in an uninitialized variable warning,
that is escalated to an error when building with clang.

Reviewed by:	markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D21773
  • Loading branch information
mhorne committed Sep 26, 2019
1 parent 73d1090 commit 4b17c31
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sys/riscv/riscv/elf_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
break;

case R_RISCV_PCREL_HI20:
error = lookup(lf, symidx, 1, &addr);
if (error != 0)
return (-1);

val = addr - (Elf_Addr)where;
insn32p = (uint32_t *)where;
before32 = *insn32p;
Expand All @@ -385,6 +389,10 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
break;

case R_RISCV_PCREL_LO12_I:
error = lookup(lf, symidx, 1, &addr);
if (error != 0)
return (-1);

val = addr - (Elf_Addr)where;
insn32p = (uint32_t *)where;
before32 = *insn32p;
Expand All @@ -396,6 +404,10 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
break;

case R_RISCV_PCREL_LO12_S:
error = lookup(lf, symidx, 1, &addr);
if (error != 0)
return (-1);

val = addr - (Elf_Addr)where;
insn32p = (uint32_t *)where;
before32 = *insn32p;
Expand All @@ -412,6 +424,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
if (error != 0)
return (-1);

val = addr;
insn32p = (uint32_t *)where;
before32 = *insn32p;
imm20 = calc_hi20_imm(val);
Expand Down

0 comments on commit 4b17c31

Please sign in to comment.