[PATCH] D16599: ELF: Define another entry point.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 16:27:16 PST 2016


silvas added inline comments.

================
Comment at: ELF/DriverUtils.cpp:150
@@ +149,3 @@
+    dup2(Fd[1], 2);
+    link(Args);
+    exit(0);
----------------
It is not safe to call `link` after a `fork`, since e.g. the malloc lock can be held after forking in a multi-threaded situation.

http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html
```
A process shall be created with a single thread. If a multi-threaded process calls fork(), the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. ***Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called.*** [THR] [Option Start]  Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls.
```

You can find a list of async-signal safe functions here: http://man7.org/linux/man-pages/man7/signal.7.html

In other words, you pretty much have to `exec` in order to be robust when used from a multi-threaded program (and sometimes there are threads internal to the runtime library so any program can be multi-threaded). Your LLVM_ON_UNIX==false seems portable so I think you can just delete the LLVM_ON_UNIX==true version.

================
Comment at: ELF/DriverUtils.cpp:201
@@ +200,3 @@
+    if (!ExeOrErr)
+      error("lld is not found");
+  }
----------------
The documentation states that this function is guaranteed to return. So it can't call `error`.


http://reviews.llvm.org/D16599





More information about the llvm-commits mailing list