[llvm-bugs] [Bug 40012] New: Tail merging causes mismatched CFA offset for stack adjustments

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 13 12:46:21 PST 2018


            Bug ID: 40012
           Summary: Tail merging causes mismatched CFA offset for stack
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: martin at martin.st
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

Created attachment 21220
  --> https://bugs.llvm.org/attachment.cgi?id=21220&action=edit
LLVM IR for reproducing the issue

In cases where the X86CallFrameOptimization has run on a function, the stack
pointer is adjusted within functions when doing a function call. This leads to
output that looks like this:

        pushl   $72
        .cfi_adjust_cfa_offset 4
        calll   __Znwj
        addl    $4, %esp
        .cfi_adjust_cfa_offset -4

If multiple blocks within a function share the same tail, tail merging can end
up merging the stack pointer restoration from multiple blocks. This leads to
the CFA offset from interpreting the dwarf CFI being incorrect:

        movl    %eax, %ebx
        .cfi_escape 0x2e, 0x04
        pushl   $__ZGVZNSt3__16locale7classicEvE1c
        .cfi_adjust_cfa_offset 4
        calll   ___cxa_guard_abort
        jmp     LBB622_158
        pushl   %edi
        .cfi_adjust_cfa_offset 4
        calll   __ZdlPv
        addl    $4, %esp
        .cfi_adjust_cfa_offset -4
        jmp     LBB622_158

When scanning the DWARF CFI linearly, the CFA offset ends up at +4 after this
section, even though the stack pointer actually always is back where it

If the "addl $4, %esp; .cfi_adjust_cfa_offset -4" is moved back into both
branches, the CFA offset from scanning DWARF CFI ends up correct.

The attached (zipped) LLVM IR, when compiled with "llc locale.ll", shows off
the issue.

This results in broken DWARF unwinding on x86 platforms, in particular on
platforms where X86CallFrameOptimization actually does transformations (which
seems to mostly be on x86_32 platforms with a 4 byte aligned stack). It seems
that the issue can be avoided by either -enable-tail-merge=0 or

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/20181213/fc9ce4f9/attachment.html>

More information about the llvm-bugs mailing list