Problem with stripping symbols in linux kernel on riscv64

Nelson Chu nelson@rivosinc.com
Fri Oct 10 02:20:04 GMT 2025


I guess, if enable relaxations, the code may be shrinked, the symbols may
be changed after linking, so we need relocations if we want to get the
values of the symbols.  It seems weird that the kernel code never used the
alias symbols, but still have relocations for them.  You probably can check
where and who tries to get the value of these alias symbols?  Which
relocation types? R_RISCV_PCREL_HI20/LO12 or R_RISCV_32/64?  If fromer then
still has code try to access the aliases, if later then probably you enable
the debug mode.

Nelson

On Fri, Oct 10, 2025 at 1:23 AM Alexey Gladkov <legion@kernel.org> wrote:

> Greetings!
>
> I faced a problem when compiling the linux kernel [1]. The kernel uses
> symbols with special names to generate modaliases [2]. These symbols are
> aliases for real data structures used by the kernel. These aliases
> themselves are never used in the kernel code. These symbols are only
> needed for post-generation.
>
> After generating modalias these symbols are removed. It works, but for
> some reason, in some cases, this does not work. The problem only occurs
> with CONFIG_RELOCATABLE=y on riscv64.
>
> I compared the builds on x86_64 and riscv64. At first glance, everything
> looks the same and the symbols end up in the same sections.
>
>
> $ objdump -x vmlinux.unstripped.x86_64 | grep ffffffff81ef4dc0
> ffffffff81ef4dc0 l O .rodata 0000000000000258 kbd_ids
> ffffffff81ef4dc0 l O .rodata 0000000000000258
> __mod_device_table__kmod_keyboard__input__kbd_ids
>
> $ objcopy \
>     --strip-symbol=__mod_device_table__kmod_keyboard__input__kbd_ids \
>     vmlinux.unstripped.x86_64 vmlinux.unstripped.x86_64.strip
>
> $ objdump -x vmlinux.unstripped.x86_64.strip | grep ffffffff81ef4dc0
> ffffffff81ef4dc0 l O .rodata 0000000000000258 kbd_ids
>
>
> However, for riscv64 with CONFIG_RELOCATABLE=y, an error occurs:
>
> $ objdump -x vmlinux.unstripped.riscv |grep ffffffff80c637e0
> ffffffff80c637e0 l O .rodata 0000000000000258
> __mod_device_table__kmod_keyboard__input__kbd_ids
> ffffffff80c637e0 l O .rodata 0000000000000258 kbd_ids
>
> $ riscv64-unknown-linux-gnu-objcopy \
>     --strip-symbol=__mod_device_table__kmod_keyboard__input__kbd_ids \
>     vmlinux.unstripped.riscv vmlinux.unstripped.riscv.strip
> riscv64-unknown-linux-gnu-objcopy: not stripping symbol
> `__mod_device_table__kmod_keyboard__input__kbd_ids' because it is named in
> a relocation
>
>
> I'm not sure where the problem is. I would be very grateful for any help
> in finding it.
>
>
> [1]
> https://lore.kernel.org/all/20251007011637.2512413-1-cmirabil@redhat.com/
> [2]
> https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/module.h#n260
> [3]
> https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=binutils/objcopy.c;h=3c1bcf622ff2c813276109c626bfb7711c5ccc77;hb=HEAD#l1647
>
> --
> Rgrds, legion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20251010/7a962358/attachment.htm>


More information about the Binutils mailing list