Re: [PATCH] x86/tools/relocs: Add _etext and __end_of_kernel_reserve to S_REL

From: Arvind Sankar
Date: Mon Jan 13 2020 - 23:10:27 EST


On Mon, Jan 13, 2020 at 05:38:55PM +0100, Borislav Petkov wrote:
> On Mon, Jan 13, 2020 at 11:13:10AM -0500, Arvind Sankar wrote:
> > I will note that the purpose of S_REL in relocs.c was originally to
> > handle exactly this case of symbols defined outside output sections:
>
> And we should try not to do hacks, if it can be fixed properly, as
> binutils expects symbols to be usually relative to a section.
>

I've poked around a bit more, and all the hacks in relocs.c in S_REL,
other than init_per_cpu__.*, are only there to work around old and/or
buggy binutils versions from the 2.21-2.22 days.

The current code is *not* broken for binutils-2.23+, where none of these
symbols are marked as absolute. IOW, the current code is perfectly fine
and generates relative symbols for any binutils not of 2.21-2.22
vintage.

So we have the following choices:
* bump minimum supported binutils version to 2.23, and remove all the
hacks for earlier versions.
* add a couple of hacks to relocs.c to account for new symbols, as in v2
* complicate regular code, as in v3, which Kees says might break new
code [1] and Tom says is bad for future kernel hackers [2]

[1] 202001131750.C1B8468@keescook/">https://lore.kernel.org/lkml/202001131750.C1B8468@keescook/
[2] https://lore.kernel.org/lkml/3e46154d-6e5e-1c16-90fe-f2c5daa44b60@xxxxxxx/