rust/src/rustllvm
bors ec016f80cf Auto merge of #45170 - rust-lang:aphs-no-unsynchronised-llvm-err-global, r=alexcrichton
Band-aid fix to stop race conditions in llvm errors

This is a big hammer, but should be effective at completely removing a
few issues, including inconsistent error messages and segfaults when
LLVM workers race to report results

`LLVM_THREAD_LOCAL` has been present in LLVM since 8 months before 3.7
(the earliest supported LLVM version that Rust can use)

Maybe fixes #43402 (third time lucky?)

r? @alexcrichton

------

You can see that in 5f578dfad0/src/librustc_trans/back/write.rs (L75-L100) there's a small window where the static global error message (made thread local in this PR) could be altered by another thread.

Note that we can't use `thread_local` because gcc 4.7 (permitted according to the readme) does not support it.

Maybe ideally all the functions should be modified to not use a global, but this PR makes things deterministic at least. My only hesitation is whether errors are checked in different threads to where they occur, but I figure that's probably unlikely (and is less bad than racing code).

As an aside, segfault evidence before this patch when I was doing some debugging:
```
$ while grep 'No such file or directory' log2; do RUST_LOG=debug ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc -o "" y.rs >log2 2>&1; done
error: could not write output to : No such file or directory
error: could not write output to : No such file or directory
error: could not write output to : No such file or directory
error: could not write output to : No such file or directory
error: could not write output to : No such file or directory
error: could not write output to : No such file or directory
error: could not write output to : No such file or directory
Segmentation fault (core dumped)
error: could not write output to : No such file or directory
error: could not write output to : No such file or directory
```
2017-10-10 14:26:13 +00:00
..
.editorconfig Add .editorconfig to src/rustllvm 2017-06-30 23:13:40 +03:00
ArchiveWrapper.cpp Fix archive member names on 5.0 2017-07-21 19:09:11 +02:00
llvm-rebuild-trigger Fix LLVM assertion when a weak symbol is defined in global_asm. 2017-07-18 16:52:00 +03:00
PassWrapper.cpp rustc: Implement ThinLTO 2017-10-07 08:17:52 -07:00
README audit LLVM C++ types in ArchiveWrapper and PassWrapper 2016-08-03 15:08:47 +03:00
rustllvm.h rustllvm: define LLVM_VERSION_LT 2017-07-21 14:31:17 +02:00
RustWrapper.cpp Band-aid fix to stop race conditions in llvm errors 2017-10-10 13:14:51 +01:00

This directory currently contains some LLVM support code. This will generally
be sent upstream to LLVM in time; for now it lives here.

NOTE: the LLVM C++ ABI is subject to between-version breakage and must *never*
be exposed to Rust. To allow for easy auditing of that, all Rust-exposed types
must be typedef-ed as "LLVMXyz", or "LLVMRustXyz" if they were defined here.

Functions that return a failure status and leave the error in
the LLVM last error should return an LLVMRustResult rather than an
int or anything to avoid confusion.

When translating enums, add a single `Other` variant as the first
one to allow for new variants to be added. It should abort when used
as an input.

All other types must not be typedef-ed as such.