Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F173444108
D59901.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D59901.diff
View Options
diff --git a/lib/libkldelf/Makefile b/lib/libkldelf/Makefile
--- a/lib/libkldelf/Makefile
+++ b/lib/libkldelf/Makefile
@@ -11,6 +11,7 @@
ef_arm.c \
ef_amd64.c \
ef_i386.c \
+ ef_loongarch.c \
ef_powerpc.c \
ef_riscv.c
WARNS?= 2
diff --git a/lib/libkldelf/ef_loongarch.c b/lib/libkldelf/ef_loongarch.c
new file mode 100644
--- /dev/null
+++ b/lib/libkldelf/ef_loongarch.c
@@ -0,0 +1,60 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Xiaoqiang Zhao <zhaoxiaoqiang007@gmail.com>
+ *
+ */
+
+#include <sys/endian.h>
+
+#include <err.h>
+#include <errno.h>
+#include <gelf.h>
+
+#include "kldelf.h"
+
+/*
+ * Apply relocations to the values obtained from the file. `relbase' is the
+ * target relocation address of the section, and `dataoff/len' is the region
+ * that is to be relocated, and has been copied to *dest
+ */
+static int
+ef_loongarch_reloc(struct elf_file *ef, const void *reldata, Elf_Type reltype,
+ GElf_Addr relbase, GElf_Addr dataoff, size_t len, void *dest)
+{
+ char *where;
+ GElf_Addr addr, addend;
+ GElf_Size rtype, symidx;
+ const GElf_Rela *rela;
+
+ switch (reltype) {
+ case ELF_T_RELA:
+ rela = (const GElf_Rela *)reldata;
+ where = (char *)dest + (relbase + rela->r_offset - dataoff);
+ addend = rela->r_addend;
+ rtype = GELF_R_TYPE(rela->r_info);
+ symidx = GELF_R_SYM(rela->r_info);
+ break;
+ default:
+ return (EINVAL);
+ }
+
+ if (where < (char *)dest || where >= (char *)dest + len)
+ return (0);
+
+ switch (rtype) {
+ case R_LARCH_64: /* S + A */
+ addr = EF_SYMADDR(ef, symidx) + addend;
+ le64enc(where, addr);
+ break;
+ case R_LARCH_RELATIVE: /* B + A */
+ addr = relbase + addend;
+ le64enc(where, addr);
+ break;
+ default:
+ warnx("unhandled relocation type %d", (int)rtype);
+ }
+ return (0);
+}
+
+ELF_RELOC(ELFCLASS64, ELFDATA2LSB, EM_LOONGARCH, ef_loongarch_reloc);
diff --git a/usr.sbin/kldxref/Makefile b/usr.sbin/kldxref/Makefile
--- a/usr.sbin/kldxref/Makefile
+++ b/usr.sbin/kldxref/Makefile
@@ -21,6 +21,7 @@
ef_arm.c \
ef_amd64.c \
ef_i386.c \
+ ef_loongarch.c \
ef_powerpc.c \
ef_riscv.c
SRCS+= ${KLDELF_SRCS}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Sep 26, 11:39 PM (3 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39601510
Default Alt Text
D59901.diff (2 KB)
Attached To
Mode
D59901: kldxref: add LoongArch support
Attached
Detach File
Event Timeline
Log In to Comment