summaryrefslogtreecommitdiff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Auto merge of #94229 - erikdesjardins:rem2, r=nikicbors2022-03-021-26/+0
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove LLVM attribute removal This was necessary before, because `declare_raw_fn` would always apply the default optimization attributes to every declared function. Then `attributes::from_fn_attrs` would have to remove the default attributes in the case of, e.g. `#[optimize(speed)]` in a `-Os` build. (see [`src/test/codegen/optimize-attr-1.rs`](https://github.com/rust-lang/rust/blob/03a8cc7df1d65554a4d40825b0490c93ac0f0236/src/test/codegen/optimize-attr-1.rs#L33)) However, every relevant callsite of `declare_raw_fn` (i.e. where we actually generate code for the function, and not e.g. a call to an intrinsic, where optimization attributes don't [?] matter) calls `from_fn_attrs`, so we can remove the attribute setting from `declare_raw_fn`, and rely on `from_fn_attrs` to apply the correct attributes all at once. r? `@ghost` (blocked on #94221) `@rustbot` label S-blocked
| * Remove LLVM attribute removalErik Desjardins2022-02-281-26/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This was necessary before, because `declare_raw_fn` would always apply the default optimization attributes to every declared function, and then `attributes::from_fn_attrs` would have to remove the default attributes in the case of, e.g. `#[optimize(speed)]` in a `-Os` build. However, every relevant callsite of `declare_raw_fn` (i.e. where we actually generate code for the function, and not e.g. a call to an intrinsic, where optimization attributes don't [?] matter) calls `from_fn_attrs`, so we can simply remove the attribute setting from `declare_raw_fn`, and rely on `from_fn_attrs` to apply the correct attributes all at once.
* | Revert "Auto merge of #92419 - erikdesjardins:coldland, r=nagisa"Erik Desjardins2022-02-271-8/+0
|/ | | | | This reverts commit 4f49627c6fe2a32d1fed6310466bb0e1c535c0c0, reversing changes made to 028c6f1454787c068ff5117e9000a1de4fd98374.
* AttrBuilder doesn't take a context in old LLVMErik Desjardins2022-02-261-4/+7
|
* use attrbuilder to remove attrs in old LLVMErik Desjardins2022-02-261-4/+7
|
* Add LLVM attributes in batches instead of individuallyErik Desjardins2022-02-261-105/+60
| | | | This should improve performance.
* Rollup merge of #91675 - ivanloz:memtagsan, r=nagisaMatthias Krüger2022-02-181-0/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add MemTagSanitizer Support Add support for the LLVM [MemTagSanitizer](https://llvm.org/docs/MemTagSanitizer.html). On hardware which supports it (see caveats below), the MemTagSanitizer can catch bugs similar to AddressSanitizer and HardwareAddressSanitizer, but with lower overhead. On a tag mismatch, a SIGSEGV is signaled with code SEGV_MTESERR / SEGV_MTEAERR. # Usage `-Zsanitizer=memtag -C target-feature="+mte"` # Comments/Caveats * MemTagSanitizer is only supported on AArch64 targets with hardware support * Requires `-C target-feature="+mte"` * LLVM MemTagSanitizer currently only performs stack tagging. # TODO * Tests * Example
| * MemTagSanitizer SupportIvan Lozano2022-02-161-0/+2
| | | | | | | | Adds support for the LLVM MemTagSanitizer.
* | llvm: migrate to new parameter-bearing uwtable attrAugie Fackler2022-02-141-0/+11
|/ | | | | | | | | | | | In https://reviews.llvm.org/D114543 the uwtable attribute gained a flag so that we can ask for sync uwtables instead of async, as the former are much cheaper. The default is async, so that's what I've done here, but I left a TODO that we might be able to do better. While in here I went ahead and dropped support for removing uwtable attributes in rustc: we never did it, so I didn't write the extra C++ bridge code to make it work. Maybe I should have done the same thing with the `sync|async` parameter but we'll see.
* Apply noundef attribute to &T, &mut T, Box<T>, boolErik Desjardins2022-02-051-0/+2
| | | | | | | | | This doesn't handle `char` because it's a bit awkward to distinguish it from u32 at this point in codegen. Note that for some types (like `&Struct` and `&mut Struct`), we already apply `dereferenceable`, which implies `noundef`, so the IR does not change.
* Windows: Disable LLVM crash dialog boxes.Eric Huss2022-01-271-0/+4
|
* Use error-on-mismatch policy for PAuth module flags.Jacob Bramley2022-01-241-3/+6
| | | | | | | | | This agrees with Clang, and avoids an error when using LTO with mixed C/Rust. LLVM considers different behaviour flags to be a mismatch, even when the flag value itself is the same. This also makes the flag setting explicit for all uses of LLVMRustAddModuleFlag.
* Rollup merge of #92559 - durin42:llvm-14-attributemask, r=nikicMatthias Krüger2022-01-061-5/+3
|\ | | | | | | | | | | | | | | | | RustWrapper: adapt to new AttributeMask API Upstream LLVM change 9290ccc3c1a1 migrated attribute removal to use AttributeMask instead of AttrBuilder, so we need to follow suit here. r? ``@nagisa`` cc ``@nikic``
| * RustWrapper: simplify removing attributesAugie Fackler2022-01-051-7/+3
| | | | | | | | Avoids some extra conversions. Spotted by nikic during review.
| * RustWrapper: adapt to new AttributeMask APIAugie Fackler2022-01-041-2/+4
| | | | | | | | | | Upstream LLVM change 9290ccc3c1a1 migrated attribute removal to use AttributeMask instead of AttrBuilder, so we need to follow suit here.
* | RustWrapper: adapt for an LLVM API changeKrasimir Georgiev2022-01-031-4/+4
|/ | | | | | | | | No functional changes intended. The LLVM commit https://github.com/llvm/llvm-project/commit/ec501f15a8b8ace2b283732740d6d65d40d82e09 removed the signed version of `createExpression`. This adapts the Rust LLVM wrappers accordingly.
* keep noinline for system llvm < 14Erik Desjardins2021-12-301-0/+8
|
* LLVM codgen support for unwinding inline assemblycynecx2021-12-031-0/+8
|
* Adjust llvm wrapper for unwinding support for inlineasmcynecx2021-12-031-2/+3
|
* Rollup merge of #90833 - tmiasko:optimization-remarks, r=nikicMatthias Krüger2021-11-281-0/+93
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Emit LLVM optimization remarks when enabled with `-Cremark` The default diagnostic handler considers all remarks to be disabled by default unless configured otherwise through LLVM internal flags: `-pass-remarks`, `-pass-remarks-missed`, and `-pass-remarks-analysis`. This behaviour makes `-Cremark` ineffective on its own. Fix this by configuring a custom diagnostic handler that enables optimization remarks based on the value of `-Cremark` option. With `-Cremark=all` enabling all remarks. Fixes #90924. r? `@nikic`
| * Recognize machine optimization remarksTomasz Miąsko2021-11-161-0/+3
| |
| * Emit LLVM optimization remarks when enabled with `-Cremark`Tomasz Miąsko2021-11-161-0/+90
| | | | | | | | | | | | | | | | | | | | | | The default diagnostic handler considers all remarks to be disabled by default unless configured otherwise through LLVM internal flags: `-pass-remarks`, `-pass-remarks-missed`, and `-pass-remarks-analysis`. This behaviour makes `-Cremark` ineffective on its own. Fix this by configuring a custom diagnostic handler that enables optimization remarks based on the value of `-Cremark` option. With `-Cremark=all` enabling all remarks.
* | add rustc option for using LLVM stack smash protectionBenjamin A. Bjørnseth2021-11-221-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | LLVM has built-in heuristics for adding stack canaries to functions. These heuristics can be selected with LLVM function attributes. This patch adds a rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use of these attributes. This gives rustc the same stack smash protection support as clang offers through options `-fno-stack-protector`, `-fstack-protector`, `-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the current list of rustc exploit mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html), originally discussed in #15179. Stack smash protection adds runtime overhead and is therefore still off by default, but now users have the option to trade performance for security as they see fit. An example use case is adding Rust code in an existing C/C++ code base compiled with stack smash protection. Without the ability to add stack smash protection to the Rust code, the code base artifacts could be exploitable in ways not possible if the code base remained pure C/C++. Stack smash protection support is present in LLVM for almost all the current tier 1/tier 2 targets: see test/assembly/stack-protector/stack-protector-target-support.rs. The one exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a warning message printed if stack smash protection is used with this target (see test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3 targets has not been checked. Since the heuristics are applied at the LLVM level, the heuristics are expected to add stack smash protection to a fraction of functions comparable to C/C++. Some experiments demonstrating how Rust code is affected by the different heuristics can be found in test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is potential for better heuristics using Rust-specific safety information. For example it might be reasonable to skip stack smash protection in functions which transitively only use safe Rust code, or which uses only a subset of functions the user declares safe (such as anything under `std.*`). Such alternative heuristics could be added at a later point. LLVM also offers a "safestack" sanitizer as an alternative way to guard against stack smashing (see #26612). This could possibly also be included as a stack-protection heuristic. An alternative is to add it as a sanitizer (#39699). This is what clang does: safestack is exposed with option `-fsanitize=safe-stack`. The options are only supported by the LLVM backend, but as with other codegen options it is visible in the main codegen option help menu. The heuristic names "basic", "strong", and "all" are hopefully sufficiently generic to be usable in other backends as well. Reviewed-by: Nikita Popov <nikic@php.net> Extra commits during review: - [address-review] make the stack-protector option unstable - [address-review] reduce detail level of stack-protector option help text - [address-review] correct grammar in comment - [address-review] use compiler flag to avoid merging functions in test - [address-review] specify min LLVM version in fortanix stack-protector test Only for Fortanix test, since this target specifically requests the `--x86-experimental-lvi-inline-asm-hardening` flag. - [address-review] specify required LLVM components in stack-protector tests - move stack protector option enum closer to other similar option enums - rustc_interface/tests: sort debug option list in tracking hash test - add an explicit `none` stack-protector option Revert "set LLVM requirements for all stack protector support test revisions" This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
* | Make `LLVMRustGetOrInsertGlobal` always return a `GlobalVariable`Josh Stone2021-11-191-1/+11
|/ | | | | | | | | | | | | `Module::getOrInsertGlobal` returns a `Constant*`, which is a super class of `GlobalVariable`, but if the given type doesn't match an existing declaration, it returns a bitcast of that global instead. This causes UB when we pass that to `LLVMGetVisibility` which unconditionally casts the opaque argument to a `GlobalValue*`. Instead, we can do our own get-or-insert without worrying whether existing types match exactly. It's not relevant when we're just trying to get/set the linkage and visibility, and if types are needed we can bitcast or error nicely from `rustc_codegen_llvm` instead.
* Update the minimum external LLVM to 12Josh Stone2021-10-221-24/+0
|
* Update the minimum external LLVM to 11Josh Stone2021-10-221-14/+0
|
* Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoeristerJubilee2021-10-071-4/+7
|\ | | | | | | | | | | | | | | Implement `#[link_ordinal(n)]` Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name. As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL. Part of #58713.
| * Implement #[link_ordinal] attribute in the context of #[link(kind = ↵Richard Cobbe2021-09-201-4/+7
| | | | | | | | "raw-dylib")].
* | RustWrapper: adapt for LLVM API change of fatal_error_handler_tKrasimir Georgiev2021-10-051-0/+4
|/ | | | | | | | | No functional changes intended. The LLVM commit https://github.com/llvm/llvm-project/commit/e463b69736da8b0a950ecd937cf990401bdfcdeb changed an argument of fatal_error_handler_t from std::string to char*. This adapts RustWrapper accordingly.
* RustWrapper: remove some uses of AttrBuilderAugie Fackler2021-09-081-19/+6
| | | | | Turns out we can also use Attribute::get*() methods here, and avoid the AttrBuilder and an extra helper method here.
* RustWrapper: just use the *AtIndex funcs directlyAugie Fackler2021-09-071-36/+3
| | | | | Otherwise we're kind of reimplementing the inverse of the well-named methods, and that's not a direction we want to go.
* RustWrapper: avoid deleted unclear attribute methodsAugie Fackler2021-09-071-18/+70
| | | | | | | | | | | | These were deleted in https://reviews.llvm.org/D108614, and in C++ I definitely see the argument for their removal. I didn't try and propagate the changes up into higher layers of rustc in this change because my initial goal was to get rustc working against LLVM HEAD promptly, but I'm happy to follow up with some refactoring to make the API on the Rust side match the LLVM API more directly (though the way the enum works in Rust makes the API less scary IMO). r? @nagisa cc @nikic
* RustWrapper: adapt to LLVM change 0f45c16f2caaAugie Fackler2021-08-261-14/+9
| | | | | | | The above-mentioned commit (part of the LLVM 14 development cycle) removes a method that rustc uses somewhat extensively. We mostly switch to lower-level methods that exist in all versions of LLVM we use, so no new ifdef logic is required in most cases.
* Handle SrcMgr diagnosticsNikita Popov2021-08-161-3/+17
| | | | | | This is how InlineAsm diagnostics with source information are reported now. Previously a separate InlineAsm diagnostic handler was used.
* Prepare call/invoke for opaque pointersJosh Stone2021-08-051-7/+7
| | | | | | Rather than relying on `getPointerElementType()` from LLVM function pointers, we now pass the function type explicitly when building `call` or `invoke` instructions.
* Replace LLVMConstInBoundsGEP with LLVMConstInBoundsGEP2*Tomasz Miąsko2021-08-041-0/+10
| | | | | | A custom reimplementation of LLVMConstInBoundsGEP2 is used, since the LLVM contains a declaration of LLVMConstInBoundsGEP2 but not the implementation.
* Pass type when creating atomic loadNikita Popov2021-07-091-4/+3
| | | | | Instead of determining it from the pointer type, explicitly pass the type to load.
* Add first cut of functionality for #58713: support for #[link(kind = ↵Richard Cobbe2021-06-041-0/+52
| | | | | | | | "raw-dylib")]. This does not yet support #[link_name] attributes on functions, the #[link_ordinal] attribute, #[link(kind = "raw-dylib")] on extern blocks in bin crates, or stdcall functions on 32-bit x86.
* rustc: Store metadata-in-rlibs in object filesAlex Crichton2021-06-041-35/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit updates how rustc compiler metadata is stored in rlibs. Previously metadata was stored as a raw file that has the same format as `--emit metadata`. After this commit, however, the metadata is encoded into a small object file which has one section which is the contents of the metadata. The motivation for this commit is to fix a common case where #83730 arises. The problem is that when rustc crates a `dylib` crate type it needs to include entire rlib files into the dylib, so it passes `--whole-archive` (or the equivalent) to the linker. The problem with this, though, is that the linker will attempt to read all files in the archive. If the metadata file were left as-is (today) then the linker would generate an error saying it can't read the file. The previous solution was to alter the rlib just before linking, creating a new archive in a temporary directory which has the metadata file removed. This problem from before this commit is now removed if the metadata file is stored in an object file that the linker can read. The only caveat we have to take care of is to ensure that the linker never actually includes the contents of the object file into the final output. We apply similar tricks as the `.llvmbc` bytecode sections to do this. This involved changing the metadata loading code a bit, namely updating some of the LLVM C APIs used to use non-deprecated ones and fiddling with the lifetimes a bit to get everything to work out. Otherwise though this isn't intended to be a functional change really, only that metadata is stored differently in archives now. This should end up fixing #83730 because by default dylibs will no longer have their rlib dependencies "altered" meaning that split-debuginfo will continue to have valid paths pointing at the original rlibs. (note that we still "alter" rlibs if LTO is enabled to remove Rust object files and we also "alter" for the #[link(cfg)] feature, but that's rarely used). Closes #83730
* RustWrapper: work around unification of diagnostic handlersAugie Fackler2021-04-221-1/+11
| | | | | | | | | This lets me build against llvm/main as of March 23rd, 2021. I'm not entirely sure this is _correct_, but it appears to be functionally identical to what was done in LLVM: existing callsites of setInlineAsmDiagnosticHandler were moved to SetDiagnosticHandler() on the context object, which we already set up in both places that we called setInlineAsmDiagnosticHandler().
* Don't set `fast`(-math) for certain simd opsSimonas Kazlauskas2021-04-171-2/+4
| | | | | | | | | | | | `fast-math` implies things like functions not being able to accept as an argument or return as a result, say, `inf` which made these functions confusingly named or behaving incorrectly, depending on how you interpret it. Since the time when these intrinsics have been implemented the intrinsics user's (stdsimd) approach has changed significantly and so now it is required that these intrinsics operate normally rather than in "whatever" way. Fixes #84268
* Manually set dso_local when its valid to do soSimonas Kazlauskas2021-04-031-0/+4
| | | | | | | | | | | | | | | | This should have no real effect in most cases, as e.g. `hidden` visibility already implies `dso_local` (or at least LLVM IR does not preserve the `dso_local` setting if the item is already `hidden`), but it should fix `-Crelocation-model=static` and improve codegen in executables. Note that this PR does not exhaustively port the logic in [clang]. Only the obviously correct portion and what is necessary to fix a regression from LLVM 12 that relates to `-Crelocation_model=static`. Fixes #83335 [clang]: https://github.com/llvm/llvm-project/blob/3001d080c813da20b329303bf8f45451480e5905/clang/lib/CodeGen/CodeGenModule.cpp#L945-L1039
* Auto merge of #83387 - cuviper:min-llvm-10, r=nagisabors2021-03-251-38/+0
|\ | | | | | | | | | | Update the minimum external LLVM to 10 r? `@nikic`
| * Update the minimum external LLVM to 10Josh Stone2021-03-221-38/+0
| |
* | cleanup: add some comments per review feedbackAugie Fackler2021-03-221-0/+3
| |
* | fix: I meant LLVM version 13, not 12Augie Fackler2021-03-191-1/+1
| |
* | llvm-wrapper: add alignment argument to CreateAtomicCmpXchgAugie Fackler2021-03-161-0/+6
|/ | | | | | As far as I can tell what we've been getting is llvm::MaybeAlign(), so just use that for now. This is required sometime after 24539f1ef2471d07bd87f833cb0288fc0f251f4b.
* Mark pure asm as willreturnNikita Popov2021-03-011-0/+2
|
* Support LLVM 12 in rustcNikita Popov2021-02-281-4/+49
|
* HWASan supportTri Vo2021-02-071-0/+2
|