Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1558024
| From | Josh Poimboeuf <jpoimboe@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: x86-64: Maintain 16-byte stack alignment |
| Date | 2017-01-13 06:10 +0100 |
| Message-ID | <sZ2hH-5a1-3@gated-at.bofh.it> (permalink) |
| References | (5 earlier) <sYZa9-2Zi-3@gated-at.bofh.it> <sZ0zg-46z-9@gated-at.bofh.it> <sZ0IV-49E-9@gated-at.bofh.it> <sZ1F0-4HH-23@gated-at.bofh.it> <sZ2hH-5a1-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, Jan 12, 2017 at 08:37:18PM -0800, Linus Torvalds wrote:
> On Jan 12, 2017 8:28 PM, "Josh Poimboeuf" <jpoimboe@redhat.com> wrote:
>
>
> The stack frame was always 16-byte aligned regardless of whether the
> buf array size was even or odd.
>
>
> Including with -fomit-frame-pointer?
>
> With frame pointers, stack frames really are naturally 16 bytes, and then
> keeping the frame 16-byte aligned is just a matter of making any extra
> frame allocations or push/pop sequences that you do also be a multiple of
> 16 bytes.
>
> But *without* frame pointers, the"native" frame size is just 8 bytes, and a
> function that doesn't need any other local storage and then calls another
> function (think various trivial wrapper functions that just add an argument
> and then munge the return value) would thus naturally cause the frame to
> become misaligned.
>
> So then the compiler actually needs to start adding useless instructions
> just to keep the stack 16-byte aligned.
Disabling frame pointers didn't seem to help, but I finally got it to
misalign with a different test case. I think it had been aligning the
array, so instead I made it push a register.
void otherfunc(void);
static inline void bar(int f)
{
register void *__sp asm(_ASM_SP);
asm volatile("call otherfunc" : "+r" (__sp) : "b"(f));
}
void foo(void)
{
bar(5);
}
00000000000020f0 <foo>:
20f0: 55 push %rbp
20f1: 48 89 e5 mov %rsp,%rbp
20f4: 53 push %rbx
20f5: bb 05 00 00 00 mov $0x5,%ebx
20fa: e8 00 00 00 00 callq 20ff <foo+0xf>
20fb: R_X86_64_PC32 otherfunc-0x4
20ff: 5b pop %rbx
2100: 5d pop %rbp
2101: c3 retq
2102: 0f 1f 40 00 nopl 0x0(%rax)
2106: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
210d: 00 00 00
--
Josh
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-10 15:40 +0100
Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-10 18:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-10 18:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-11 04:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-11 04:40 +0100
Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-11 05:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-11 05:40 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-11 07:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-12 07:30 +0100
Re: x86-64: Maintain 16-byte stack alignment Ingo Molnar <mingo@kernel.org> - 2017-01-12 08:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 15:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-12 21:00 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-12 21:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 21:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 22:00 +0100
Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-12 22:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:40 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-13 02:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 04:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-13 04:30 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 05:30 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 06:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:40 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 14:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-01-11 09:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-11 09:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-11 19:30 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-12 08:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Ingo Molnar <mingo@kernel.org> - 2017-01-12 08:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 15:50 +0100
Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-12 09:00 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-12 09:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Ingo Molnar <mingo@kernel.org> - 2017-01-12 09:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 16:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-12 16:10 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 16:20 +0100
Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 16:20 +0100
csiph-web