[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <i2vb4l3ykg7memhl34jkcbyet4myhjwnforwiebwyzyicfmxkm@5jseorvzzy4i>
Date: Tue, 16 Sep 2025 16:18:49 -0700
From: Josh Poimboeuf <jpoimboe@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org,
Petr Mladek <pmladek@...e.com>, Miroslav Benes <mbenes@...e.cz>,
Joe Lawrence <joe.lawrence@...hat.com>, live-patching@...r.kernel.org, Song Liu <song@...nel.org>,
laokz <laokz@...mail.com>, Jiri Kosina <jikos@...nel.org>,
Marcos Paulo de Souza <mpdesouza@...e.com>, Weinan Liu <wnliu@...gle.com>,
Fazla Mehrab <a.mehrab@...edance.com>, Chen Zhongjin <chenzhongjin@...wei.com>,
Puranjay Mohan <puranjay@...nel.org>, Dylan Hatch <dylanbhatch@...gle.com>,
Masahiro Yamada <masahiroy@...nel.org>
Subject: Re: [PATCH v3 42/64] kbuild,x86: Fix special section module
permissions
On Mon, Jun 30, 2025 at 09:31:44AM +0200, Peter Zijlstra wrote:
> On Fri, Jun 27, 2025 at 10:34:15AM -0700, Josh Poimboeuf wrote:
> > On Fri, Jun 27, 2025 at 12:53:28PM +0200, Peter Zijlstra wrote:
> > > 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.
> >
> > Yeah, I really hate this too. I really tried to find something better,
> > including mucking with the linker script, but this was unfortunately the
> > only thing that worked.
> >
> > Though, looking at it again, I realize we can localize the pain to Clang
> > (and the makefile) by leaving the code untouched and instead strip
> > SHF_WRITE before the link and re-add it afterwards. Then we can tie
> > this horrible hack to specific Clang versions when it gets fixed.
>
> Oh yeah, that might be nicer indeed!
I ended up giving up on this approach. It was just too painful trying
to get the toolchain to cooperate. It does kind of make sense that
SHF_WRITE and SHF_MERGE are incompatible.
What I really needed was a way to set entsize from assembly, but that
doesn't seem possible without SHF_MERGE.
For now I'm just going with marking the beginning of each special
section entry with an objtool annotation. Then objtool can deduce the
sizes from the distance between the annotations.
--
Josh
Powered by blists - more mailing lists