about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
AgeCommit message (Collapse)AuthorLines
2022-12-10Rollup merge of #105109 - rcvalle:rust-kcfi, r=bjorn3Matthias Krüger-13/+86
Add LLVM KCFI support to the Rust compiler This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.) Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653). LLVM KCFI can be enabled with -Zsanitizer=kcfi. Thank you again, `@bjorn3,` `@eddyb,` `@nagisa,` and `@ojeda,` for all the help!
2022-12-10Rollup merge of #104019 - compiler-errors:print-generator-sizes, r=wesleywiserMatthias Krüger-75/+8
Compute generator sizes with `-Zprint_type_sizes` Fixes #103887 r? `@pnkfelix`
2022-12-08Add LLVM KCFI support to the Rust compilerRamon de C Valle-13/+86
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.) Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653). LLVM KCFI can be enabled with -Zsanitizer=kcfi. Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2022-12-07Move closure/generator type info methods to TyCtxtMichael Goulet-75/+8
2022-12-05Move linkage type check to HIR analysis and fix semantics issues.Peter Collingbourne-21/+4
This ensures that the error is printed even for unused variables, as well as unifying the handling between the LLVM and GCC backends. This also fixes unusual behavior around exported Rust-defined variables with linkage attributes. With the previous behavior, it appears to be impossible to define such a variable such that it can actually be imported and used by another crate. This is because on the importing side, the variable is required to be a pointer, but on the exporting side, the type checker rejects static variables of pointer type because they do not implement `Sync`. Even if it were possible to import such a type, it appears that code generation on the importing side would add an unexpected additional level of pointer indirection, which would break type safety. This highlighted that the semantics of linkage on Rust-defined variables is different to linkage on foreign items. As such, we now model the difference with two different codegen attributes: linkage for Rust-defined variables, and import_linkage for foreign items. This change gives semantics to the test src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs which was previously expected to fail to compile. Therefore, convert it into a test that is expected to successfully compile. The update to the GCC backend is speculative and untested.
2022-12-03Auto merge of #105218 - matthiaskrgr:rollup-8d3k08n, r=matthiaskrgrbors-7/+6
Rollup of 9 pull requests Successful merges: - #104199 (Keep track of the start of the argument block of a closure) - #105050 (Remove useless borrows and derefs) - #105153 (Create a hacky fail-fast mode that stops tests at the first failure) - #105164 (Restore `use` suggestion for `dyn` method call requiring `Sized`) - #105193 (Disable coverage instrumentation for naked functions) - #105200 (Remove useless filter in unused extern crate check.) - #105201 (Do not call fn_sig on non-functions.) - #105208 (Add AmbiguityError for inconsistent resolution for an import) - #105214 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-03Rollup merge of #105193 - tmiasko:naked-nocoverage, r=wesleywiserMatthias Krüger-7/+6
Disable coverage instrumentation for naked functions Fixes #105170.
2022-12-03Auto merge of #97485 - bjorn3:new_archive_writer, r=wesleywiserbors-74/+82
Rewrite LLVM's archive writer in Rust This allows it to be used by other codegen backends. Fixes https://github.com/bjorn3/rustc_codegen_cranelift/issues/1155
2022-12-03Mark naked functions as never inline in codegen_fn_attrsTomasz Miąsko-7/+6
Use code generation attributes to ensure that naked functions are never inline, replacing separate checks in MIR inliner and LLVM code generation.
2022-12-02Rollup merge of #105026 - oToToT:aarch64-v8a, r=davidtwcoMatthias Krüger-0/+5
v8a as default aarch64 target After https://github.com/llvm/llvm-project/commit/8689f5e landed, LLVM takes the intersection of v8a and v8r as default. This commit brings back v8a support by explicitly specifying v8a in the feature list. This should solve #97724. p.s. a bit more context can also be found in https://github.com/llvm/llvm-project/issues/57904#issuecomment-1329555590.
2022-11-30Auto merge of #104679 - dvdhrm:rw/dso, r=petrochenkovbors-6/+10
codegen-llvm: never combine DSOLocal and DllImport Prevent DllImport from being attached to DSOLocal definitions in the LLVM IR. The combination makes no sense, since definitions local to the compilation unit will never be imported from external objects. Additionally, LLVM will refuse the IR if it encounters the combination (introduced in [1]): ``` if (GV.hasDLLImportStorageClass()) Assert(!GV.isDSOLocal(), "GlobalValue with DLLImport Storage is dso_local!", &GV); ``` Right now, codegen-llvm will only apply DllImport to constants and rely on call-stubs for functions. Hence, we simply extend the codegen of constants to skip DllImport for any local definitions. This was discovered when switching the EFI targets to the static relocation model [2]. With this fixed, we can start another attempt at this. [1] https://smlnj-gitlab.cs.uchicago.edu/manticore/llvm/commit/509132b368efed10bbdad825403f45e9cf1d6e38 [2] https://github.com/rust-lang/rust/issues/101656
2022-11-29Rollup merge of #104627 - calebzulawski:print-target-features, r=compiler-errorsMatthias Krüger-16/+19
Print all features with --print target-features This fixes `rustc --print target-features` with respect to aliases and tied features. Before this change, the print command assumed that each LLVM feature corresponds exactly to one rustc feature. In the case of aliases and tied features, this assumption failed and some features (such as aarch64's "pacg") were missing. With this change, every target feature is listed.
2022-11-29codegen-llvm: never combine DSOLocal and DllImportDavid Rheinsberg-6/+10
Prevent DllImport from being attached to DSOLocal definitions in the LLVM IR. The combination makes no sense, since definitions local to the compilation unit will never be imported from external objects. Additionally, LLVM will refuse the IR if it encounters the combination (introduced in [1]): if (GV.hasDLLImportStorageClass()) Assert(!GV.isDSOLocal(), "GlobalValue with DLLImport Storage is dso_local!", &GV); Right now, codegen-llvm will only apply DllImport to constants and rely on call-stubs for functions. Hence, we simply extend the codegen of constants to skip DllImport for any local definitions. This was discovered when switching the EFI targets to the static relocation model [2]. With this fixed, we can start another attempt at this. [1] https://smlnj-gitlab.cs.uchicago.edu/manticore/llvm/commit/509132b368efed10bbdad825403f45e9cf1d6e38 [2] https://github.com/rust-lang/rust/issues/101656
2022-11-29v8a as default aarch64 targetTommy Chiang (oToToT)-0/+5
After https://github.com/llvm/llvm-project/commit/8689f5e landed, LLVM takes the intersection of v8a and v8r as default. This commit brings back v8a support by explicitly specifying v8a in the feature list. This should solve #97724.
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-7/+7
2022-11-26Use LLVM for getting symbols from COFF bigobj filesbjorn3-1/+9
2022-11-26Rewrite LLVM's archive writer in Rustbjorn3-74/+74
This allows it to be used by other codegen backends
2022-11-26Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errorsGuillaume Gomez-1/+1
Use the power of adding helper function to simplify code w/ `Mutability` r? `@compiler-errors`
2022-11-24Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiserbors-1/+1
Use `as_deref` in compiler (but only where it makes sense) This simplifies some code :3 (there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-23Add `Mutability::{is_mut,is_not}`Maybe Waffle-1/+1
2022-11-21Unreserve braced enum variants in value namespaceVadim Petrochenkov-2/+2
2022-11-21Rollup merge of #104511 - dpaoliello:privateglobalworkaround, r=michaelwoeristerMatthias Krüger-1/+14
Mark functions created for `raw-dylib` on x86 with DllImport storage class Fix for #104453 ## Issue Details On x86 Windows, LLVM uses 'L' as the prefix for any private global symbols (`PrivateGlobalPrefix`), so when the `raw-dylib` feature creates an undecorated function symbol that begins with an 'L' LLVM misinterprets that as a private global symbol that it created and so fails the compilation at a later stage since such a symbol must have a definition. ## Fix Details Mark the function we are creating for `raw-dylib` with `DllImport` storage class (this was already being done for MSVC at a later point for `callee::get_fn` but not for GNU (due to "backwards compatibility")): this will cause LLVM to prefix the name with `__imp_` and so it won't mistake it for a private global symbol.
2022-11-21Auto merge of #102717 - beetrees:repr128-c-style-debuginfo, r=nagisabors-12/+9
Pass 128-bit C-style enum enumerator values to LLVM Pass the full 128 bits of C-style enum enumerators through to LLVM. This means that debuginfo for C-style repr128 enums is now emitted correctly for DWARF platforms (as compared to not being correctly emitted on any platform). Tracking issue: #56071
2022-11-19Print all features with --print target-features, including aliases and tied ↵Caleb Zulawski-16/+19
features
2022-11-19Rollup merge of #104001 - Ayush1325:custom-entry, r=bjorn3Dylan DPC-19/+53
Improve generating Custom entry function This commit is aimed at making compiler-generated entry functions (Basically just C `main` right now) more generic so other targets can do similar things for custom entry. This was initially implemented as part of https://github.com/rust-lang/rust/pull/100316. Currently, this moves the entry function name and Call convention to the target spec. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-18Workaround for private global symbol issueDaniel Paoliello-1/+14
2022-11-17Auto merge of #103138 - nnethercote:merge-BBs, r=bjorn3bors-5/+5
Merge basic blocks where possible when generating LLVM IR. r? `@ghost`
2022-11-16Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle-1/+1
2022-11-16Rollup merge of #103750 - calebzulawski:master, r=workingjubileeMatthias Krüger-0/+3
Fix some misleading target feature aliases This is the first half of a fix for #100752. It looks like these aliases were added in #78361 and slipped under the radar, as these features are not AVX512. These features _do_ add AVX512 instructions when used _in combination_ with AVX512F, but without AVX512F, these features still provide 128-bit and 256-bit vector instructions. A user might be mislead into thinking these features imply AVX512F (which is true of the actual AVX512 features). This PR allows using the names as defined by LLVM, which matches Intel documentation. A future PR should change the `std::arch` intrinsics to use these names, and finally remove these aliases from rustc. r? ```@workingjubilee``` cc ```@Amanieu```
2022-11-16Use `&mut Bx` more.Nicholas Nethercote-5/+5
For the next commit, `FunctionCx::codegen_*_terminator` need to take a `&mut Bx` instead of consuming a `Bx`. This triggers a cascade of similar changes across multiple functions. The resulting code is more concise and replaces many `&mut bx` expressions with `bx`.
2022-11-15Auto merge of #102570 - cjgillot:deagg-debuginfo, r=oli-obkbors-1/+12
Perform simple scalar replacement of aggregates (SROA) MIR opt This is a re-open of https://github.com/rust-lang/rust/pull/85796 I copied the debuginfo implementation (first commit) from `@eddyb's` own SROA PR. This pass replaces plain field accesses by simple locals when possible. To be eligible, the replaced locals: - must not be enums or unions; - must not be used whole; - must not have their address taken. The storage and deinit statements are duplicated on each created local. cc `@tmiasko` who reviewed the former version of this PR.
2022-11-15Introduce composite debuginfo.Camille GILLOT-1/+12
2022-11-15Auto merge of #104054 - RalfJung:byte-provenance, r=oli-obkbors-7/+5
interpret: support for per-byte provenance Also factors the provenance map into its own module. The third commit does the same for the init mask. I can move it in a separate PR if you prefer. Fixes https://github.com/rust-lang/miri/issues/2181 r? `@oli-obk`
2022-11-13Rollup merge of #104105 - davidtwco:split-dwarf-lto, r=michaelwoeristerManish Goregaokar-3/+13
llvm: dwo only emitted when object code emitted Fixes #103932. `CompiledModule` should not think a DWARF object was emitted when a bitcode-only compilation has happened, this can confuse archive file creation (which expects to create an archive containing non-existent dwo files). r? ``````@michaelwoerister``````
2022-11-13Rollup merge of #104357 - RalfJung:is-sized, r=cjgillotMatthias Krüger-2/+2
add is_sized method on Abi and Layout, and use it This avoids the double negation of `!is_unsized()` that we have quite a lot.
2022-11-13add is_sized method on Abi and Layout, and use itRalf Jung-2/+2
2022-11-12Update compiler/rustc_codegen_llvm/src/llvm_util.rsCaleb Zulawski-1/+1
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2022-11-12Allow actual AVX512-related feature names in the case of some misleading aliasesCaleb Zulawski-0/+3
2022-11-12Rollup merge of #104110 - krasimirgg:msan-16, r=nagisaGuillaume Gomez-3/+12
prevent uninitialized access in black_box for zero-sized-types Don't read the pointer location in black_box for zero sized types, just emit a memory clobber instead. Addresses https://github.com/rust-lang/rust/issues/103304 when rust is build against LLVM at HEAD. Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/.28with.20llvm.20at.20HEAD.29.3A.20msan.20error.20in.20core.3A.3Ahint.3A.3Ablack_box
2022-11-11Improve generating Custom entry functionAyush Singh-19/+53
This commit is aimed at making compiler generated entry functions (Basically just C `main` right now) more generic so other targets can do similar things for custom entry. This was initially implemented as part of https://github.com/rust-lang/rust/pull/100316. Currently, this moves the entry function name and Call convention to the target spec. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-09Update compiler/rustc_codegen_llvm/src/back/archive.rsSLASHLogin-1/+1
Co-authored-by: David Wood <agile.lion3441@fuligin.ink>
2022-11-09Use `LayoutError`'s implementation of `IntoDiagnostic`SLASHLogin-11/+3
2022-11-09Simplify existing Diagnostic implementationsSLASHLogin-41/+49
2022-11-09Port diagnostics created by `Handler`SLASHLogin-8/+17
2022-11-09Flatten diagnostic structsSLASHLogin-48/+43
2022-11-09Port `MissingFeatures` and `TargetFeatureDisableOrEnable`SLASHLogin-14/+39
2022-11-09Port `UnknownArchiveKind`SLASHLogin-4/+11
2022-11-09Port `DlltoolFailImportLibrary` and implement `IntoDiagnosticArg` for ↵SLASHLogin-6/+17
`Cow<'a, str>`
2022-11-09Port ErrorCallingDllToolSLASHLogin-2/+10
2022-11-09Import ErrorWritingDEFFileSLASHLogin-2/+8