http://llvm.org/bugs/show_bug.cgi?id=22311

            Bug ID: 22311
           Summary: Clang does not implement the noclone attribute
           Product: clang
           Version: 3.5
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Driver
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

noclone is a companion attribute to the noinline attribute that GCC implements.
It prevents constant propagation from happening.  If one is doing magic low
level hackery then it is a necessity.  A specific use case I have for this is
creating a safe wrapper for vfork (which most compilers understandably mess up
on).

The wrapper:

__attribute__((noinline))
__attribute__((noclone))
__attribute__((no_sanitize_address))
static pid_t safe_vfork(int (*f)(void *), void * arg)
{
        __atomic_signal_fence(__ATOMIC_SEQ_CST);

        pid_t child = vfork();
        if (0 == child)
                _Exit(f(arg));

        return child;
}

Some workarounds:

Use assembly: This is annoying but would work.
Put safe_vfork in a separate module: This doesn't work with link-time
optimization but is the typical workaround.
Use volatile on the function arguments as follows: Strangely, this doesn't
actually work.  I can further work around this with more indirection but I am
hesitant to do so because the semantics of volatile are very unclear and
compiler specific.

__attribute__((noinline))
__attribute__((noclone))
__attribute__((no_sanitize_address))
static pid_t safe_vfork(int (*volatile f)(void *), void * volatile arg)
{
        __atomic_signal_fence(__ATOMIC_SEQ_CST);

        pid_t child = vfork();
        if (0 == child)
                _Exit(f(arg));

        return child;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to