[PATCH v6 06/11] riscv: vdso: Enable the vdsocheck tool
From: Thomas Weißschuh
Date: Mon Nov 23 2026 - 08:51:48 EST
The vdsocheck tool validates the object files and final .so library.
It can detect if the compiler created relocations which are incompatible
with the vDSO which need to be worked around.
Wire it up for the architecture.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
---
arch/riscv/Kconfig | 1 +
arch/riscv/kernel/vdso/Makefile | 4 ++--
lib/vdso/check/vdsocheck.rs | 26 ++++++++++++++++++++++++++
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index e7891a2a89da..2a0f5fbcd7e3 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -226,6 +226,7 @@ config RISCV
select THREAD_INFO_IN_TASK
select TRACE_IRQFLAGS_SUPPORT
select UACCESS_MEMCPY if !MMU
+ select VDSO_CHECK if MMU
select VDSO_DATASTORE if MMU
select VDSO_GETRANDOM if MMU && 64BIT
select USER_STACKTRACE_SUPPORT
diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile
index c023046a3fd7..b15039d0309e 100644
--- a/arch/riscv/kernel/vdso/Makefile
+++ b/arch/riscv/kernel/vdso/Makefile
@@ -75,7 +75,7 @@ endif
$(obj)/$(vdso_o): $(obj)/$(vdso_so)
# link rule for the .so file, .lds has to be first
-$(obj)/$(vdso_so_dbg): $(obj)/$(vdso_lds) $(obj-vdso) FORCE
+$(obj)/$(vdso_so_dbg): $(obj)/$(vdso_lds) $(obj-vdso) $(vdsocheck) FORCE
$(call if_changed,vdsold_and_check)
LDFLAGS_$(vdso_so_dbg) = -shared -soname=linux-vdso.so.1 \
--build-id=sha1 --eh-frame-hdr
@@ -97,7 +97,7 @@ include/generated/$(vdso_offsets): $(obj)/$(vdso_so_dbg) FORCE
# The DSO images are built using a special linker script
# Make sure only to export the intended __vdso_xxx symbol offsets.
quiet_cmd_vdsold_and_check = VDSOLD $@
- cmd_vdsold_and_check = $(LD) $(CFI_FULL) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
+ cmd_vdsold_and_check = $(LD) $(CFI_FULL) $(ld_flags) -T $(filter-out FORCE $(vdsocheck),$^) -o $@.tmp && \
$(OBJCOPY) $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
rm $@.tmp && \
$(cmd_vdso_check)
diff --git a/lib/vdso/check/vdsocheck.rs b/lib/vdso/check/vdsocheck.rs
index da58ff220eab..37455d326110 100644
--- a/lib/vdso/check/vdsocheck.rs
+++ b/lib/vdso/check/vdsocheck.rs
@@ -96,6 +96,32 @@ fn allowed_relocations_for_machine(machine: u16) -> Option<AllowedRelocations<'s
..Default::default()
}
.into(),
+ bindings::EM_RISCV => AllowedRelocations {
+ in_object_file: &[
+ 16, /* R_RISCV_BRANCH */
+ 17, /* R_RISCV_JAL */
+ 18, /* R_RISCV_CALL */
+ 19, /* R_RISCV_CALL_PLT */
+ 23, /* R_RISCV_PCREL_HI20 */
+ 24, /* R_RISCV_PCREL_LO12_I */
+ 25, /* R_RISCV_PCREL_LO12_S */
+ 33, /* R_RISCV_ADD8 */
+ 34, /* R_RISCV_ADD16 */
+ 35, /* R_RISCV_ADD32 */
+ 36, /* R_RISCV_ADD64 */
+ 37, /* R_RISCV_SUB8 */
+ 38, /* R_RISCV_SUB16 */
+ 39, /* R_RISCV_SUB32 */
+ 40, /* R_RISCV_SUB64 */
+ 43, /* R_RISCV_ALIGN */
+ 44, /* R_RISCV_RVC_BRANCH */
+ 45, /* R_RISCV_RVC_JUMP */
+ 51, /* R_RISCV_RELAX */
+ 57, /* R_RISCV_32_PCREL */
+ ],
+ ..Default::default()
+ }
+ .into(),
_ => None,
}
}
--
2.56.1