[llvm-bugs] [Bug 40635] New: Need a function attribute for stack alignment

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 6 15:01:37 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40635

            Bug ID: 40635
           Summary: Need a function attribute for stack alignment
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: peter at pcc.me.uk
                CC: llvm-bugs at lists.llvm.org

The value of the -mstack-alignment argument is not preserved in a function
attribute, which means that it gets dropped during LTO. Reproducer:

$ cat align.c 
void g(void *);

void f() {
  char x;
  g(&x);
}
$ ~/l/ra/bin/clang align.c -mstack-alignment=32  -shared -fuse-ld=lld -O  &&
~/l2/ra/bin/llvm-objdump -d a.out | grep -A5 ' f:'
00000000000010c0 f:
    10c0:       48 83 ec 18     subq    $24, %rsp
    10c4:       48 8d 7c 24 17  leaq    23(%rsp), %rdi
    10c9:       e8 52 00 00 00  callq   82 <g at plt>
    10ce:       48 83 c4 18     addq    $24, %rsp
    10d2:       c3      retq
$ ~/l/ra/bin/clang align.c -mstack-alignment=32  -shared -fuse-ld=lld -O -flto
&& ~/l2/ra/bin/llvm-objdump -d a.out | grep -A5 ' f:'
00000000000010c0 f:
    10c0:       50      pushq   %rax
    10c1:       48 8d 7c 24 07  leaq    7(%rsp), %rdi
    10c6:       e8 55 00 00 00  callq   85 <g at plt>
    10cb:       58      popq    %rax
    10cc:       c3      retq

This is the variable in Clang that stores the value of -mstack-alignment:

http://llvm-cs.pcc.me.uk/tools/clang/include/clang/Basic/CodeGenOptions.def#247

It's only used to set a "stackrealign" function attribute (which doesn't store
the alignment value) and a code generation option StackAlignmentOverride that
isn't preserved through LTO. The right fix would probably be to remove
StackAlignmentOverride and replace it with a function attribute.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190206/ef880f9b/attachment.html>


More information about the llvm-bugs mailing list