git: 9f810201f020 - stable/13 - kldxref: handle R_RISCV_64 relocation

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 28 Oct 2022 14:10:55 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=9f810201f0207872a2223091d70376fd74ab0d40

commit 9f810201f0207872a2223091d70376fd74ab0d40
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-10-20 14:56:01 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-10-28 14:10:37 +0000

    kldxref: handle R_RISCV_64 relocation
    
    These are emitted in at least two kmods, and kldxref prints a warning.
    While here, remove the unneeded local variable 'val'.
    
    Reviewed by:    jrtc27, imp, emaste
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D37038
    
    (cherry picked from commit fc4c39c54fc240af424ae249b75057d2977ef8f2)
---
 usr.sbin/kldxref/ef_riscv.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/kldxref/ef_riscv.c b/usr.sbin/kldxref/ef_riscv.c
index e0caae3bd286..b94b37b3a92f 100644
--- a/usr.sbin/kldxref/ef_riscv.c
+++ b/usr.sbin/kldxref/ef_riscv.c
@@ -45,10 +45,10 @@ int
 ef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off relbase,
     Elf_Off dataoff, size_t len, void *dest)
 {
-	Elf_Addr *where, val;
+	Elf_Addr *where;
 	const Elf_Rela *rela;
 	Elf_Addr addend, addr;
-	Elf_Size rtype;
+	Elf_Size rtype, symidx;
 
 	switch (reltype) {
 	case EF_RELOC_RELA:
@@ -57,6 +57,7 @@ ef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off relbase,
 		    dataoff);
 		addend = rela->r_addend;
 		rtype = ELF_R_TYPE(rela->r_info);
+		symidx = ELF_R_SYM(rela->r_info);
 		break;
 	default:
 		return (EINVAL);
@@ -66,10 +67,13 @@ ef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off relbase,
 		return (0);
 
 	switch (rtype) {
+	case R_RISCV_64:	/* S + A */
+		addr = EF_SYMADDR(ef, symidx) + addend;
+		*where = addr;
+		break;
 	case R_RISCV_RELATIVE:	/* B + A */
 		addr = addend + relbase;
-		val = addr;
-		*where = val;
+		*where = addr;
 		break;
 	default:
 		warnx("unhandled relocation type %d", (int)rtype);