Re: [PATCH] x86/boot/compressed: Fix compressed kernel linking with lld

From: Arvind Sankar
Date: Sat Feb 22 2020 - 18:57:42 EST


On Sat, Feb 22, 2020 at 03:33:20PM -0800, Nick Desaulniers wrote:
>
> Ah, yikes. For reference, please see my commit:
>
> commit b059f801a937 ("x86/purgatory: Use CFLAGS_REMOVE rather than
> reset KBUILD_CFLAGS")
>
> I'm of the conviction that reassigning KBUILD_CFLAGS via `:=`, as
> opposed to strictly filtering flags out of it or appending to it, is
> an antipattern. We very very carefully construct KBUILD_CFLAGS in top
> level and arch/ Makefiles, and it's very easy to miss a flag or to
> when you "reset" KBUILD_CFLAGS.
>
> *Boom* Case in point.
>
> I meant to audit the rest of the places we do this in the kernel, but
> haven't had the time to revisit arch/x86/boot/compressed/Makefile.
>
> For now, I suggest:
> 1. revert `Commit TBD ("x86/boot/compressed: Remove unnecessary
> sections from bzImage")` as it runs afoul differences in `*` for
> `DISCARD` sections between linkers, as the intent was to remove
> .eh_frame, of which it's less work to not generate them in the first
> place via compiler flag, rather than generate then discard via linker.
> 2. simply add `KBUILD_CFLAGS += -fno-asynchronous-unwind-tables` to
> arch/x86/boot/compressed/Makefile with Fangrui's Sugguested-by tag.
> 3. Remind me to revisit my proposed cleanup of
> arch/x86/boot/compressed/Makefile (which eventually will undo #2). ;)
> 4. tglx to remind me that my compiler is broken and that I should fix it. :P

Ok. For reference, note that arch/x86/boot/Makefile also redefines
KBUILD_CFLAGS and missed this option, which is why commit 163159aad74d
("x86/boot: Discard .eh_frame sections") was necessary.

There's also arch/x86/realmode/rm/Makefile as well.

There's also a bunch of places where the CFLAGS_REMOVE have fallen
behind the times -- they remove only -pg rather than CC_FLAGS_FTRACE.
Probably harmless currently since the other flags should be ineffective
without the -pg but might want to clean this up as well.