aboutsummaryrefslogtreecommitdiff
path: root/sys/riscv/riscv/elf_machdep.c
diff options
context:
space:
mode:
authorMitchell Horne <mhorne@FreeBSD.org>2019-09-26 00:58:47 +0000
committerMitchell Horne <mhorne@FreeBSD.org>2019-09-26 00:58:47 +0000
commitc81e8f9891a3bda0cd2734ba02cf53931d97a64a (patch)
tree555500a6fba34fca5c746068c2c5919690f2c8b3 /sys/riscv/riscv/elf_machdep.c
parent8b868507496853e46a765e0add00a81233bc0f55 (diff)
downloadsrc-c81e8f9891a3bda0cd2734ba02cf53931d97a64a.tar.gz
src-c81e8f9891a3bda0cd2734ba02cf53931d97a64a.zip
Fix some broken relocation handling
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
Notes
Notes: svn path=/head/; revision=352730
Diffstat (limited to 'sys/riscv/riscv/elf_machdep.c')
-rw-r--r--sys/riscv/riscv/elf_machdep.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/riscv/riscv/elf_machdep.c b/sys/riscv/riscv/elf_machdep.c
index 7164f5b8a0b9..09d8aba84023 100644
--- a/sys/riscv/riscv/elf_machdep.c
+++ b/sys/riscv/riscv/elf_machdep.c
@@ -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;
@@ -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;
@@ -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;
@@ -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);