Re: Remaining randconfig objtool warnings, linux-next-20200428

From: Josh Poimboeuf
Date: Tue Apr 28 2020 - 19:08:25 EST


On Tue, Apr 28, 2020 at 05:48:38PM -0500, Josh Poimboeuf wrote:
> On Wed, Apr 29, 2020 at 12:33:27AM +0200, Peter Zijlstra wrote:
> > On Tue, Apr 28, 2020 at 05:03:53PM -0500, Josh Poimboeuf wrote:
> > > On Tue, Apr 28, 2020 at 11:55:54PM +0200, Peter Zijlstra wrote:
> >
> > > > binutils.git/gas/configure/tc-i386.c:i386_generate_nops
> > > >
> > > > When there's too many NOPs (as here) it generates a JMP across the NOPS.
> > > > It makes some sort of sense, at some point executing NOPs is going to be
> > > > more expensive than a branch.. But shees..
> > >
> > > Urgh. Even if I tell it specifically to pad with NOPs, it still does
> > > this "trick". I have no idea how to deal with this in objtool.
> >
> > This is horrible... but it _might_ just work.
>
> HAHA, nice.
>
> This seems to work:

More sophisticated version:

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 3063aa9090f9..f9082673f84c 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -597,8 +597,22 @@ SYM_CODE_START_LOCAL(common_spurious)
SYM_CODE_END(common_spurious)
_ASM_NOKPROBE(common_spurious)

+/*
+ * For .p2align NOP padding with shift >= 7, if the gap is big enough, the GNU
+ * assembler decides to insert a JMP in the padding, which makes objtool sad.
+ * Force it to NOPs only, by splitting it into smaller alignments if necessary.
+ */
+.macro P2ALIGN shift
+ tmp=6
+ .rept \shift-6
+ .p2align tmp
+ tmp=tmp+1
+ .endr
+ .p2align \shift
+.endm
+
/* common_interrupt is a hotpath. Align it */
- .p2align CONFIG_X86_L1_CACHE_SHIFT
+P2ALIGN shift=CONFIG_X86_L1_CACHE_SHIFT
SYM_CODE_START_LOCAL(common_interrupt)
addq $-0x80, (%rsp) /* Adjust vector to [-256, -1] range */
call interrupt_entry