Problem with stripping symbols in linux kernel on riscv64
Alexey Gladkov
legion@kernel.org
Thu Oct 9 17:21:22 GMT 2025
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
More information about the Binutils
mailing list