<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Need a function attribute for stack alignment"
   href="https://bugs.llvm.org/show_bug.cgi?id=40635">40635</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Need a function attribute for stack alignment
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>peter@pcc.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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@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@plt>
    10cb:       58      popq    %rax
    10cc:       c3      retq

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

<a href="http://llvm-cs.pcc.me.uk/tools/clang/include/clang/Basic/CodeGenOptions.def#247">http://llvm-cs.pcc.me.uk/tools/clang/include/clang/Basic/CodeGenOptions.def#247</a>

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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>