stand/reloc_elf: Handle relative relocations for arm{,64} and riscv

Extend the powerpc relative relocation handling from r240782 to a
handful of other architectures.  This is needed to properly read
dependency information from kernel modules.

Reviewed by:	jhb
Approved by:	scottl (implicit)
MFC after:	1 week
Sponsored by:	Ampere Computing, Inc.
Differential Revision:	https://reviews.freebsd.org/D26365
This commit is contained in:
D Scott Phillips 2020-09-21 22:24:46 +00:00
parent de03184698
commit 987eabdc2a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=365982

View File

@ -175,7 +175,8 @@ __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr, const void *reldata,
}
return (0);
#elif defined(__powerpc__)
#elif defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) || \
defined(__riscv)
Elf_Size w;
const Elf_Rela *rela;
@ -185,7 +186,15 @@ __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr, const void *reldata,
if (relbase + rela->r_offset >= dataaddr &&
relbase + rela->r_offset < dataaddr + len) {
switch (ELF_R_TYPE(rela->r_info)) {
#if defined(__aarch64__)
case R_AARCH64_RELATIVE:
#elif defined(__arm__)
case R_ARM_RELATIVE:
#elif defined(__powerpc__)
case R_PPC_RELATIVE:
#elif defined(__riscv)
case R_RISCV_RELATIVE:
#endif
w = relbase + rela->r_addend;
bcopy(&w, (u_char *)data + (relbase +
rela->r_offset - dataaddr), sizeof(w));