-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
"died due to signal 11" in atomic::static_init libcore test on Android #49775
Comments
Assume the error is first discovered in #49675 (based on 74abffe). The final PRs involved in that rollup are:
It was reported that the error still appears locally, so one of the above would be the cause. From #49669 (comment), we knew the cause should be already contained by d919eb671b5c6d3c68221831a8d1186f492ea4d4 (i.e. 48fa6f9 on master). 74abffe...48fa6f9 includes the following PRs:
PRs in both lists are:
|
Yes I've been able to reproduce this locally and it seems to be unrelated to changes that we're landing and otherwise just related to how libcore or libstd itself is optimized. I've attempted to debug this to get an actual cause but to no avail so far. |
I'm pretty certain though that this isn't spurious in the sense that |
Ok I think I've found the cause of this. I've got no idea how this ever worked before! (as is par for the course on these kinds of bugs) So a program like this: use std::sync::atomic::*;
use std::sync::atomic::Ordering::SeqCst;
static FOO: AtomicIsize = AtomicIsize::new(0);
fn main() {
FOO.load(SeqCst);
} generates roughly this IR: @FOO = internal unnamed_addr global <{ [4 x i8] }> zeroinitializer, align 4
define void @main() {
%a = load atomic i32, i32* bitcast (<{ [4 x i8] }>* @FOO to i32*) seq_cst, align 4
ret void
} Now the crucial thing here is that we don't actually modify @FOO = internal unnamed_addr constant <{ [4 x i8] }> zeroinitializer, align 4 Which sounds reasonable! As a result, our constant was promoted from BSS to read-only data. We can see this:
Here the Now the tricky part comes later during the actual codegen. Here if you disassemble the function we get:
So it turns out we're not using atomic instructions at all, but rather we're using the
Turns out So it looks like tl;dr; LLVM will aggressively flag unmodified internal globals as Given that we don't actually have many instances of atomics without modifying them I'm just gonna fix the test and call it a day... |
As to how this ever worked I'm sort of msytified. I'm just gonna assume that all rodata doesn't actually end up being read-only for various reasons in the loader and we got lucky before where our constants here just happened to wind up in a read/write section of memory |
I've posted a workaround at #49811 |
This sounds like something that still needs to be fixed! |
Since we have no control over Android's libgcc, is it possible that the implementation on an actual Android device might be updated in the future to use real atomic instructions, thus triggering the bug on that device as well as in the emulator? |
See rust-lang#49775 for some more information but it looks like this is working around an LLVM bug for the time being. Closes rust-lang#49775
@cuviper indeed! I've opened https://bugs.llvm.org/show_bug.cgi?id=37061 |
@BatmanAoD hm I'm not sure I quite follow? It looks like our vanilla If the code is recompiled with support for atomic instructions then I don't think any fault will happen as LLVM's assumption that the static is never modified will actually be true (as it's generating the atomic instructions). Does that answer your question? |
@alexcrichton Yes; I misunderstood or misread and somehow got the impression that libgcc was responsible for making the determination of whether to invoke the |
The same test has failed on Travis in multiple PRs, including at least:
I can reproduce on some branches (but not
master
) by runningRUST_TEST_THREADS=1 src/ci/docker/run.sh arm-android
. The end of the output looks like:Which means the test process dies with “SIGSEGV Invalid memory reference” while executing this test:
I haven’t figured out how to use gdb inside the Android emulator inside Docker to debug this further.
CC @alexcrichton, @rust-lang/release
The text was updated successfully, but these errors were encountered: