[cfe-dev] Is force_align_arg_pointer function attribute supported at x86?

Anatol Pomozov via cfe-dev cfe-dev at lists.llvm.org
Wed Jun 21 14:21:45 PDT 2017


Hi

On Wed, Jun 21, 2017 at 1:42 PM, Tim Northover <t.p.northover at gmail.com> wrote:
> Hi Anatol,
>
> On 21 June 2017 at 13:30, Anatol Pomozov via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> There is a function
>> attribute __attribute__((force_align_arg_pointer)) that works great
>> with gcc 7.x.
>
> I think the issue is that this attribute only applies to 32-bit x86
> (i.e. compiling with -m32). All x86_64 ABIs require sufficient stack
> alignment for SSE instructions so Clang doesn't support it there.
>
> Essential stack realignment probably needs to be done in assembly if
> you're writing an OS or equivalent low-level code.

Thanks for the explanation.

In my example above start_64() is the entry point for 64 mode. 32-bit
code makes a long jump and does not follow x86_64 stack alignment
policy. Having __attribute__((force_align_arg_pointer)) in this 64bit
code is a valid use-case IMO. But as you suggested the other way to do
stack alignment is to make it explicitly in 32-bit code..

Could you please help me with the 32bit assembly that emulates
__attribute__((force_align_arg_pointer)) in the callee?

I tried to do this in my 32-bit code
    __asm__ volatile("and %0, %%esp"::"irm"(-16));
    __asm__ volatile("jmp %0, %1" ::"i"(CODE_SELECTOR), "p"(start_64));
that compiled into

"and $0xfffffff0,%esp"
jmp $SELECTOR,start_64

but it does not provide the correct stack alignment.



More information about the cfe-dev mailing list