Re: [RFC PATCH 3/4] x86/asm: Make alternative macro interfaces more clear and consistent
From: Josh Poimboeuf
Date: Tue Sep 19 2017 - 12:02:18 EST
On Fri, Sep 15, 2017 at 11:01:19AM -0700, Linus Torvalds wrote:
> And most code movement really seemed to be around inline asms, I
> wonder if the gcc logic simply is something like "if the stack pointer
> is visible as a register, don't move any inline asm across a frame
> setup".
After some testing, that seems to be exactly right. Making the stack
pointer a global register variable seems to cause *all* inline asm to be
treated like it has a call instruction.
And setting the stack pointer as a constraint becomes a no-op.
So basically if we just put
register void *__asm_call_sp asm(_ASM_SP);
in a globally visible header file (e.g., arch/x86/include/asm/asm.h), it
will *always* make sure the frame pointer is set up before inserting
*any* inline asm.
The upside is that we don't have to manually annotate inline asm anymore
with those awful "+r" (__sp) constraints.
The downside is that this creates a very slight performance issue for
leaf functions which use inline assembly without call instructions,
because they're getting frame pointer setup when they don't need it.
But based on the text size difference, the performance impact should be
negligible. And it's only an issue for frame pointer-based kernels,
which may soon no longer be the default anyway.
And for non-frame-pointer-based kernels, it actually saves quite a bit
of text.
In GCC, here are the vmlinux .text size differences with the following
configs:
- defconfig
- defconfig without frame pointers
- Fedora distro config
- Fedora distro config without frame pointers
defconfig defconfig-nofp distro distro-nofp
before 9796300 9466764 9076191 8789745
after 9796941 9462859 9076381 8785325
If there are no objections, I'll go forward with the patch.
--
Josh