[llvm-bugs] [Bug 41822] New: vfork broken with -fno-builtin

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 9 11:42:51 PDT 2019


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

            Bug ID: 41822
           Summary: vfork broken with -fno-builtin
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eugeni.stepanov at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

-fno-builtin removes returns_twice attribute from vfork.
Unlike most other attributes, this one is required for correctness.
Missing returns_twice allows the optimizer to use tail calls in the caller of
vfork.
Child process can not use a tail call, because that is effectively a return
from the caller of vfork, and it corrupts the stack of the parent process.


$ cat 1.cc
#include <unistd.h>
__attribute__((optnone, noinline)) static void child() {
  volatile bool z = false;
  if (!z) _exit(0);
}

void zzztest() {
  if (!vfork()) {
    child();
  }
}

$ bin/clang++  -target armv7-linux 1.cc -O2 -c  -fno-builtin  && objdump -drl
1.o
_Z7zzztestv():
   0:   e92d4800        push    {fp, lr}
   4:   e1a0b00d        mov     fp, sp
   8:   ebfffffe        bl      0 <vfork>
                        8: R_ARM_CALL   vfork
   c:   e3500000        cmp     r0, #0
  10:   18bd8800        popne   {fp, pc}
  14:   e8bd4800        pop     {fp, lr}
  18:   eaffffff        b       1c <_ZL5childv>

-- 
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/20190509/5b865ab7/attachment-0001.html>


More information about the llvm-bugs mailing list