summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/attributes.rs
AgeCommit message (Collapse)AuthorLines
2024-01-09Rollup merge of #117744 - quininer:add-z-sync-uw, r=bjorn3Matthias Krüger-3/+4
Add -Zuse-sync-unwind Currently Rust uses async unwind by default, but async unwind will bring non-negligible size overhead. it would be nice to allow users to choose this. In addition, async unwind currently prevents LLVM from generate compact unwind for MachO, if one wishes to generate compact unwind for MachO, then also needs this flag.
2023-12-31Add -Zuse-sync-unwindquininer-3/+4
This flag specifies whether LLVM generates async unwind or sync unwind.
2023-12-30is_coroutine -> is_coroutine_or_closureMichael Goulet-1/+1
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-2/+2
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-11-30Add `-Zfunction-return={keep,thunk-extern}` optionMiguel Ojeda-1/+11
This is intended to be used for Linux kernel RETHUNK builds. With this commit (optionally backported to Rust 1.73.0), plus a patched Linux kernel to pass the flag, I get a RETHUNK build with Rust enabled that is `objtool`-warning-free and is able to boot in QEMU and load a sample Rust kernel module. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-11-30rustc_codegen_llvm: remove outdated count in commentMiguel Ojeda-1/+1
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-2/+2
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-08-18Auto merge of #113814 - ChoKyuWon:master, r=davidtwcobors-1/+4
Replace the \01__gnu_mcount_nc to LLVM intrinsic for ARM Current `-Zinstrument-mcount` for ARM32 use the `\01__gnu_mcount_nc` directly for its instrumentation function. However, the LLVM does not use this mcount function directly, but it wraps it to intrinsic, `llvm.arm.gnu.eabi.mcount` and the transform pass also only handle the intrinsic. As a result, current `-Zinstrument-mcount` not work on ARM32. Refer: https://github.com/namhyung/uftrace/issues/1764 This commit replaces the mcount name from native function to the LLVM intrinsic so that the transform pass can handle it.
2023-08-18Replace the \01__gnu_mcount_nc to LLVM intrinsic for ARMChoKyuWon-1/+4
Current `-Zinstrument-mcount` for ARM32 use the `\01__gnu_mcount_nc` directly for its instrumentation function. However, the LLVM does not use this mcount function directly, but it wraps it to intrinsic, `llvm.arm.gnu.eabi.mcount` and the transform pass also only handle the intrinsic. As a result, current `-Zinstrument-mcount` not work on ARM32. Refer: https://github.com/namhyung/uftrace/issues/1764 This commit replaces the mcount name from native function to the LLVM intrinsic so that the transform pass can handle it. Signed-off-by: ChoKyuWon <kyuwoncho18@gmail.com>
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-1/+1
2023-07-27Update the minimum external LLVM to 15Josh Stone-34/+28
2023-07-18Add the `no-builtins` attribute to functions when `no_builtins` is applied ↵DianQK-0/+4
at the crate level. When `no_builtins` is applied at the crate level, we should add the `no-builtins` attribute to each function to ensure it takes effect in LTO.
2023-06-29Avoid an unnecessary use of `SmallStr`.Nicholas Nethercote-3/+2
I don't know why `SmallStr` was used here; some ad hoc profiling showed this code is not that hot, the string is usually empty, and when it's not empty it's usually very short. However, the use of a `SmallStr<1024>` does result in 1024 byte `memcpy` call on each execution, which shows up when I do `memcpy` profiling. So using a normal string makes the code both simpler and very slightly faster.
2023-05-26Add SafeStack support to rustcWesley Wiser-0/+3
Adds support for LLVM [SafeStack] which provides backward edge control flow protection by separating the stack into two parts: data which is only accessed in provable safe ways is allocated on the normal stack (the "safe stack") and all other data is placed in a separate allocation (the "unsafe stack"). SafeStack support is enabled by passing `-Zsanitizer=safestack`. [SafeStack]: https://clang.llvm.org/docs/SafeStack.html
2023-02-14Add `kernel-address` sanitizer support for freestanding targetsWesley Norris-1/+1
2023-02-09Emit basic XRay instrumentation attributesOleksii Lozovskyi-0/+28
Add the attributes to functions according to the settings. "xray-always" overrides "xray-never", and they both override "xray-ignore-loops" and "xray-instruction-threshold", but we'll let lints deal with warnings about silly attribute combinations.
2023-02-09Allow multiple instrumentation attributesOleksii Lozovskyi-5/+5
Four because that's the new reasonable maximum for XRay instrumentation attributes in the following commit.
2023-01-26change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add ↵Kyle Matsuda-1/+1
EarlyBinder to fn_sig in metadata
2023-01-26replace usages of fn_sig query with bound_fn_sigKyle Matsuda-1/+1
2022-12-25Rollup merge of #105955 - ↵Matthias Krüger-3/+3
Nilstrieb:no-trivial-opt-wrappers-we-have-field-accesses-for-that, r=cjgillot Remove wrapper functions for some unstable options They are trivial and just forward to the option. Like most other options, we can just access it directly.
2022-12-20Add `-Zno-jump-tables`Miguel Ojeda-0/+9
This flag mimics GCC/Clang's `-fno-jump-tables` [1][2], which makes the codegen backend avoid generating jump tables when lowering switches. In the case of LLVM, the `"no-jump-tables"="true"` function attribute is added to every function. The kernel currently needs it for x86 when enabling IBT [3], as well as for Alpha (plus VDSO objects in MIPS/LoongArch). [1] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fno-jump-tables [2] https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fjump-tables [3] https://github.com/torvalds/linux/blob/v6.1/arch/x86/Makefile#L75-L83 Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-12-20Remove wrapper functions for some unstable optionsNilstrieb-3/+3
They are trivial and just forward to the option. Like most other options, we can just access it directly.
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-11-09Simplify existing Diagnostic implementationsSLASHLogin-2/+5
2022-11-09Port `MissingFeatures` and `TargetFeatureDisableOrEnable`SLASHLogin-8/+6
2022-11-09Port SanitizerMemtagRequiresMteSLASHLogin-1/+2
2022-11-04LLVM 16: Switch to using MemoryEffectsTim Neumann-3/+3
2022-09-09Add inline-llvm option for disabling/enabling LLVM inliningYan Chen-0/+4
2022-09-06get_attr should check that no duplicates are allowedyukang-1/+2
2022-07-26codegen: use new {re,de,}allocator annotations in llvmAugie Fackler-2/+49
This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. While we're here, we also emit allocator attributes on __rust_alloc_zeroed. This should allow LLVM to perform more optimizations for zeroed blocks, and probably fixes #90032. [This comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157) mentions "weird UB-like behaviour with bitvec iterators in rustc_data_structures" so we may need to back this change out if things go wrong. The new test cases require LLVM 15, so we copy them into LLVM 14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-20Add ShadowCallStack SupportIvan Lozano-0/+3
Adds support for the LLVM ShadowCallStack sanitizer.
2022-07-18Rollup merge of #98998 - ↵Dylan DPC-0/+6
workingjubilee:naked-means-no-clothes-enforcement-technology, r=Amanieu Remove branch target prologues from `#[naked] fn` This patch hacks around rust-lang/rust#98768 for now via injecting appropriate attributes into the LLVMIR we emit for naked functions. I intend to pursue this upstream so that these attributes can be removed in general, but it's slow going wading through C++ for me.
2022-07-13Rename `debugging_opts` to `unstable_opts`Joshua Nelson-4/+4
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`). Rename it to be more clear.
2022-07-06Also stop emitting BTI prologues for naked functionsJubilee Young-0/+2
Same idea but for AArch64.
2022-07-06Stop emitting CET prologues for naked functionsJubilee Young-0/+4
We can apply nocf_check as a hack for now.
2022-05-10only_local: always check for misuselcnr-3/+2
2022-04-03Replace every `String` in Target(Options) with `Cow<'static, str>`Loïc BRANSTETT-1/+1
2022-03-04Always include global target features in function attributesTomasz Miąsko-7/+6
This ensures that information about target features configured with `-C target-feature=...` or detected with `-C target-cpu=native` is retained for subsequent consumers of LLVM bitcode. This is crucial for linker plugin LTO, since this information is not conveyed to the plugin otherwise.
2022-03-04Use SmallStr when building target-features LLVM attributeTomasz Miąsko-1/+2
2022-03-03Pass LLVM string attributes as string slicesTomasz Miąsko-29/+23
2022-03-02Auto merge of #94229 - erikdesjardins:rem2, r=nikicbors-39/+9
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
2022-03-01Querify `global_backend_features`Simonas Kazlauskas-11/+10
At the very least this serves to deduplicate the diagnostics that are output about unknown target features provided via CLI.
2022-03-01Direct users towards using Rust feature names in CLISimonas Kazlauskas-4/+1
If they are trying to use features rustc doesn't yet know about, request a feature request. Additionally, also warn against using feature names without leading `+` or `-` signs.
2022-02-28Remove LLVM attribute removalErik Desjardins-39/+9
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.
2022-02-26just put smallvec lengths in the signatureErik Desjardins-6/+6
2022-02-26Add LLVM attributes in batches instead of individuallyErik Desjardins-139/+145
This should improve performance.
2022-02-18Rollup merge of #91675 - ivanloz:memtagsan, r=nagisaMatthias Krüger-0/+13
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
2022-02-16MemTagSanitizer SupportIvan Lozano-0/+13
Adds support for the LLVM MemTagSanitizer.
2022-02-14llvm: migrate to new parameter-bearing uwtable attrAugie Fackler-3/+6
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.
2022-02-10Split PAuth target featureAdam Gemmell-5/+26