-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Bring back stack trace printing on ARM Darwin #7840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@LemonBoy why thumbs down if you don't mind me asking? Are you against this change, or angry at the fact that LLVM doesn't play well with Apple's ARM target? 😁 |
|
(I wrote this comment a while ago but forgot to press the green button) The workaround is really ugly. We now have the scaffolding for emulated TLS in place, I think force-enabling it on M1 targets is a good workaround until the new LLD mach-o backend is promoted. |
I agree, so if you have a better idea, please fire away!
Oh, what scaffolding do you mean? Did I miss something? |
OpenBSD (and Android) does not support the usual hardware-backed TLS model and LLVM emits calls to a library call |
Oh cool, I was actually not aware of this. Thanks @LemonBoy. Lemme have a stab at this and report back. |
|
@LemonBoy Hmm, I can't seem to get it to work for some reason. Here's my diff of changes to get the emulated TLS to work: diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp
index 51af5e06d..8a0501f2c 100644
--- a/src/zig_llvm.cpp
+++ b/src/zig_llvm.cpp
@@ -104,7 +104,7 @@ static const bool assertions_on = true;
static const bool assertions_on = false;
#endif
-LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
+LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *TripleName,
const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
LLVMCodeModel CodeModel, bool function_sections, ZigLLVMABIType float_abi, const char *abi_name)
{
@@ -169,7 +169,12 @@ LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Tri
opt.MCOptions.ABIName = abi_name;
}
- TargetMachine *TM = reinterpret_cast<Target*>(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM,
+ Triple triple(TripleName);
+ if ((ZigLLVM_OSType)triple.getOS() == ZigLLVM_MacOSX) {
+ opt.ExplicitEmulatedTLS = true;
+ opt.EmulatedTLS = true;
+ }
+ TargetMachine *TM = reinterpret_cast<Target*>(T)->createTargetMachine(TripleName, CPU, Features, opt, RM, CM,
OL, JIT);
return reinterpret_cast<LLVMTargetMachineRef>(TM);
}And here's the linker error I'm seeing: Any ideas? |
|
Well well well, LLVM seems to support emitting the emulated tls sequence for aarch64 targets. The alternative workaround is to rename |
This temporary patch fixes a segfault caused by miscompilation by the LLD when generating stubs for initialization of thread local storage. We effectively bypass TLS in the default panic handler so that no segfault is generated and the stack trace is correctly reported back to the user. Note that, this is linked directly to a bigger issue with LLD ziglang#7527 and when resolved, we only need to remove the `comptime` code path introduced with this patch to use the default panic handler that relies on TLS. Co-authored-by: Andrew Kelley <[email protected]>
4cb2f4b to
457449a
Compare
|
@LemonBoy pushed a commit that should be cleaner to remove when LLD fixes the miscompilation with TLS. |
|
Also, since I know this is right up your alley @LemonBoy, here's what is actually going on: Thread-local storage, LLVM, and Apple Silicon: What can go wrong?. |
This commit brings back stack trace printing on ARM Darwin OSes by
avoiding the use of
threadlocalfor keeping track of panic stages perthread. Essentially, LLVM/LLD fails to properly emit thread-local variables
which causes a segfault on attempting access. Since the default panic
handler relies on a threadlocal to keep track of panic stages per
thread using a thread-local variable, we ensure at compilation time
that ARM Darwin platforms explicitly opt-out from this in favour of
storing the panic stages per thread in a hash-map behind a mutex.
This is a temporary solution until the underlying issue is fixed
but much welcome one since this brings back stack traces printouts
on ARM macOS without the necessity to resort to the system linker and
still get broken stack traces due to addressing differences between the
system linker and LLD. For a more complete overview of the problem with
threadlocalin LLVM, see #7527.EDIT:
This temporary patch fixes a segfault caused by miscompilation
by the LLD when generating stubs for initialization of thread local
storage. We effectively bypass TLS in the default panic handler
so that no segfault is generated and the stack trace is correctly
reported back to the user.
Note that, this is linked directly to a bigger issue with LLD
#7527 and when resolved, we only need to remove the
comptimecode path introduced with this patch to use the defaultpanic handler that relies on TLS.