Ulrich Weigand
2013-Apr-14 18:00 UTC
[LLVMdev] [RFC/PATCH][4/4] Support System Z as host architecture
Hello, this last patch is strictly-speaking not related to System Z as target platform, but to running LLVM on (Linux on) System Z as a *host* architecture. Most of the LLVM and Clang code base builds and works fine on System Z, however, there is one problem relating to use of signal handlers to react to crashes (SIGSEGV, SIGILL etc.). The llvm::sys::AddSignalHandler (and related) function in lib/Support/Unix/Signals.inc currently registers a signal handler routine via "sigaction". When this handler is called due to a SIGSEGV, SIGILL or similar signal, it will show a stack backtrace, deactivate the handler, and then simply return to the operating system. The intent is that the OS will now retry execution at the same location as before, which ought to again trigger the same error condition and cause the same signal to be delivered again. Since the hander is now deactivated, the OS will take its default action (usually, terminate the program and possibly create a core dump). However, this method doesn't work reliably on System Z: With certain signals (namely SIGILL, SIGFPE, and SIGTRAP), the program counter stored by the kernel on the signal stack frame (which is the location where execution will resume) is not the instruction that triggered the fault, but then instruction *after it*. When the LLVM signal handler simply returns to the kernel, execution will then resume at *that* address, which will not trigger the problem again, but simply go on and execute potentially unrelated code leading to random errors afterwards. To fix this, the patch simply goes and re-raises the signal in question directly from the handler instead of returning from it. This is done only on System Z and only for those signals that have this particular problem. [ This fixes e.g. the otherwise failing Driver/output-file-cleanup.c Clang test case. ] [ I guess this patch is really independent of the System Z backend; it ought to go in in any case to fix cross-compilers hosted on System Z ... ] [See also LLVMdev for the full set of SystemZ patches and discussion.] Bye, Ulrich (See attached file: diff-llvm-systemzsig) -------------- next part -------------- A non-text attachment was scrubbed... Name: diff-llvm-systemzsig Type: application/octet-stream Size: 917 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130414/df5486bb/attachment.obj>
Reasonably Related Threads
- [klibc:master] alpha: Fix definitions of _NSIG and struct sigaction
- [PATCH] Fix arm signals
- [LLVMdev] Is LLVM expressive enough to represent asynchronous exceptions?
- [LLVMdev] Is LLVM expressive enough to represent asynchronous exceptions?
- [PATCH/RFC] Add initial avr32 port