[PATCH] riscv: fix KUnit test_kprobes crash when building with Clang

Nam Cao namcao at linutronix.de
Wed Nov 26 10:08:01 PST 2025


Nam Cao <namcao at linutronix.de> writes:
> 许佳凯 <xujiakai2025 at iscas.ac.cn> writes:
>> Clang misaligns the test_kprobes_addresses and test_kprobes_functions
>> arrays, or does not export local labels by default. Both can cause
>> kmalloc_array() allocation errors and KUnit failures.
>>
>> This patch fixes the issue by:
>> - Adding .section .rodata to explicitly place arrays in the read-only data segment.
>> - Adding .align 3 to align arrays to 8 bytes.
>> - Adding .globl to probe labels to ensure symbols are visible.
>
> We do not have to make it exactly the same as building with GCC, right?
> Only moving the arrays to .rodata seems sufficient to fix the issue, but
> I cannot explain why yet.
>
> What I observed is that with CONFIG_RELOCATABLE=y, the kernel's
> .rela.dyn section, which holds the relocation entries for the two
> arrays, have incorrect addresses (they are all incorrectly offset by 6
> bytes for my build). The kernel uses these relocation information to
> fill the arrays during boot, and fill them at wrong addresses.
>
> I smell a linker problem, but more investigation needed...

I sent my findings to LLVM folks:
https://github.com/llvm/llvm-project/issues/168308#issuecomment-3582596694

I suspect linker problem. But let's see what LLVM people think.

Nam



More information about the linux-riscv mailing list