[PATCH v2 0/2] riscv: Add remaining module relocations and tests

From: Charlie Jenkins
Date: Fri Oct 06 2023 - 20:41:28 EST


A handful of module relocations were missing, this patch includes the
remaining ones. I also wrote some test cases to ensure that module
loading works properly. Some relocations cannot be supported in the
kernel, these include the ones that rely on thread local storage and
dynamic linking.

ULEB128 handling is a bit special because SET and SUB relocations must
happen together, and SET must happen before SUB. The module linking
ignores a SET unless it is followed by a SUB. In order to find the
corresponding SET, module linking starts at the relocation above the SUB
and iterates up until it hits the SET. If a SET is not found, module
linking fails.

This can be tested by enabling KUNIT, RUNTIME_KERNEL_TESTING_MENU, and
RISCV_MODULE_LINKING_KUNIT.

Signed-off-by: Charlie Jenkins <charlie@xxxxxxxxxxxx>
---
Changes in v2:
- Added ULEB128 relocations
- Link to v1: https://lore.kernel.org/r/20230913-module_relocations-v1-0-bb3d8467e793@xxxxxxxxxxxx

---
Charlie Jenkins (2):
riscv: Add remaining module relocations
riscv: Add tests for riscv module loading

arch/riscv/Kconfig.debug | 1 +
arch/riscv/include/uapi/asm/elf.h | 6 +-
arch/riscv/kernel/Makefile | 1 +
arch/riscv/kernel/module.c | 247 ++++++++++++++++++---
arch/riscv/kernel/tests/Kconfig.debug | 32 +++
arch/riscv/kernel/tests/Makefile | 1 +
arch/riscv/kernel/tests/module_test/Makefile | 15 ++
.../tests/module_test/test_module_linking_main.c | 73 ++++++
arch/riscv/kernel/tests/module_test/test_set16.S | 23 ++
arch/riscv/kernel/tests/module_test/test_set32.S | 20 ++
arch/riscv/kernel/tests/module_test/test_set6.S | 23 ++
arch/riscv/kernel/tests/module_test/test_set8.S | 23 ++
arch/riscv/kernel/tests/module_test/test_sub16.S | 22 ++
arch/riscv/kernel/tests/module_test/test_sub32.S | 22 ++
arch/riscv/kernel/tests/module_test/test_sub6.S | 22 ++
arch/riscv/kernel/tests/module_test/test_sub64.S | 27 +++
arch/riscv/kernel/tests/module_test/test_sub8.S | 22 ++
arch/riscv/kernel/tests/module_test/test_uleb128.S | 20 ++
18 files changed, 574 insertions(+), 26 deletions(-)
---
base-commit: 82714078aee4ccbd6ee7579d5a21f8a72155d0fb
change-id: 20230908-module_relocations-f63ced651bd7
--
- Charlie