Skip to content

Commit b51fc88

Browse files
Merge patch series "riscv: Add remaining module relocations and tests"
Charlie Jenkins <[email protected]> says: 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. This patch also overhauls the implementation of ADD/SUB/SET/ULEB128 relocations to handle overflow. "Overflow" is different for ULEB128 since it is a variable-length encoding that the compiler can be expected to generate enough space for. Instead of overflowing, ULEB128 will expand into the next 8-bit segment of the location. A psABI proposal [1] was merged that mandates that SET_ULEB128 and SUB_ULEB128 are paired, however the discussion following the merging of the pull request revealed that while the pull request was valid, it would be better for linkers to properly handle this overflow. This patch proactively implements this methodology for future compatibility. This can be tested by enabling KUNIT, RUNTIME_KERNEL_TESTING_MENU, and RISCV_MODULE_LINKING_KUNIT. [1] riscv-non-isa/riscv-elf-psabi-doc#403 * b4-shazam-merge: riscv: Add tests for riscv module loading riscv: Add remaining module relocations riscv: Avoid unaligned access when relocating modules Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents 946bb33 + af71bc1 commit b51fc88

File tree

18 files changed

+869
-105
lines changed

18 files changed

+869
-105
lines changed

arch/riscv/Kconfig.debug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "arch/riscv/kernel/tests/Kconfig.debug"

arch/riscv/include/uapi/asm/elf.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef union __riscv_fp_state elf_fpregset_t;
4949
#define R_RISCV_TLS_DTPREL64 9
5050
#define R_RISCV_TLS_TPREL32 10
5151
#define R_RISCV_TLS_TPREL64 11
52+
#define R_RISCV_IRELATIVE 58
5253

5354
/* Relocation types not used by the dynamic linker */
5455
#define R_RISCV_BRANCH 16
@@ -81,7 +82,6 @@ typedef union __riscv_fp_state elf_fpregset_t;
8182
#define R_RISCV_ALIGN 43
8283
#define R_RISCV_RVC_BRANCH 44
8384
#define R_RISCV_RVC_JUMP 45
84-
#define R_RISCV_LUI 46
8585
#define R_RISCV_GPREL_I 47
8686
#define R_RISCV_GPREL_S 48
8787
#define R_RISCV_TPREL_I 49
@@ -93,6 +93,9 @@ typedef union __riscv_fp_state elf_fpregset_t;
9393
#define R_RISCV_SET16 55
9494
#define R_RISCV_SET32 56
9595
#define R_RISCV_32_PCREL 57
96+
#define R_RISCV_PLT32 59
97+
#define R_RISCV_SET_ULEB128 60
98+
#define R_RISCV_SUB_ULEB128 61
9699

97100

98101
#endif /* _UAPI_ASM_RISCV_ELF_H */

arch/riscv/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ obj-y += stacktrace.o
5757
obj-y += cacheinfo.o
5858
obj-y += patch.o
5959
obj-y += probes/
60+
obj-y += tests/
6061
obj-$(CONFIG_MMU) += vdso.o vdso/
6162

6263
obj-$(CONFIG_RISCV_MISALIGNED) += traps_misaligned.o

0 commit comments

Comments
 (0)