rust/compiler/rustc_codegen_llvm/src
Wesley Wiser 296489c892 Fix Access Violation when using lld & ThinLTO on windows-msvc
Users report an AV at runtime of the compiled binary when using lld and
ThinLTO on windows-msvc. The AV occurs when accessing a static value
which is defined in one crate but used in another. Based on the
disassembly of the cross-crate use, it appears that the use is not
correctly linked with the definition and is instead assigned a garbage
pointer value.

If we look at the symbol tables for each crates' obj file, we can see
what is happening:

*lib.obj*:

```
COFF SYMBOL TABLE
...
00E 00000000 SECT2  notype       External     | _ZN10reproducer7memrchr2FN17h612b61ca0e168901E
...
```

*bin.obj*:

```
COFF SYMBOL TABLE
...
010 00000000 UNDEF  notype       External     | __imp__ZN10reproducer7memrchr2FN17h612b61ca0e168901E
...
```

The use of the symbol has the "import" style symbol name but the
declaration doesn't generate any symbol with the same name. As a result,
linking the files generates a warning from lld:

> rust-lld: warning: bin.obj: locally defined symbol imported: reproducer::memrchr::FN::h612b61ca0e168901 (defined in lib.obj) [LNK4217]

and the symbol reference remains undefined at runtime leading to the AV.

To fix this, we just need to detect that we are performing ThinLTO (and
thus, static linking) and omit the `dllimport` attribute on the extern
item in LLVM IR.
2022-11-03 11:17:42 -04:00
..
back Support raw-dylib functions being used inside inlined functions 2022-10-24 16:17:38 -07:00
coverageinfo more dupe word typos 2022-10-14 12:57:56 +08:00
debuginfo Change name of "dataful" variant to "untagged" 2022-09-07 20:12:45 +00:00
llvm Use the existing set_visibility function. 2022-09-28 14:43:58 -07:00
abi.rs Merge apply_attrs_callsite into call and invoke 2022-10-01 17:01:31 +00:00
allocator.rs Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
asm.rs Add links to relevant pages to find constraint information 2022-10-13 22:05:49 +02:00
attributes.rs Add inline-llvm option for disabling/enabling LLVM inlining 2022-09-09 08:00:47 -07:00
base.rs Remove several unused methods from MiscMethods 2022-10-01 16:45:07 +00:00
builder.rs Don't use usub.with.overflow intrinsic 2022-10-20 12:47:17 +02:00
callee.rs Get rid of native_library projection queries 2022-10-19 16:21:21 +02:00
common.rs Introduce a fallible variant of LLVMConstIntGetZExtValue 2022-09-09 15:54:14 +02:00
consts.rs Fix Access Violation when using lld & ThinLTO on windows-msvc 2022-11-03 11:17:42 -04:00
context.rs Remove several unused methods from MiscMethods 2022-10-01 16:45:07 +00:00
declare.rs Change declare_cfn to use the C visibility for all C ABI functions. 2022-09-28 14:50:58 -07:00
intrinsic.rs Merge apply_attrs_callsite into call and invoke 2022-10-01 17:01:31 +00:00
lib.rs Rewrite implementation of #[alloc_error_handler] 2022-10-31 16:32:57 +00:00
llvm_util.rs Remove support for LLVM's legacy pass manager 2022-09-18 13:25:49 -07:00
mono_item.rs Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
type_.rs Add fine-grained LLVM CFI support to the Rust compiler 2022-07-23 10:51:34 -07:00
type_of.rs Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
va_arg.rs Introduce Bx::switch_to_block 2022-02-24 12:18:21 +01:00
value.rs