Re: [PATCH v3 42/64] kbuild,x86: Fix special section module permissions

From: Peter Zijlstra
Date: Fri Jun 27 2025 - 06:53:52 EST


On Thu, Jun 26, 2025 at 04:55:29PM -0700, Josh Poimboeuf wrote:
> An upcoming patch will add the SHF_MERGE flag to x86 __jump_table and
> __bug_table so their entry sizes can be defined in inline asm.
>
> However, those sections have SHF_WRITE, which the Clang linker (lld)
> explicitly forbids combining with SHF_MERGE.
>
> Those sections are modified at runtime and must remain writable. While
> SHF_WRITE is ignored by vmlinux, it's still needed for modules.
>
> To work around the linker interference, remove SHF_WRITE during
> compilation and restore it after linking the module.

This is vile... but I'm not sure I have a better solution.

Eventually we should get the toolchains fixed, but we can't very well
mandate clang-21+ to build x86 just yet.