about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/attributes.rs
AgeCommit message (Collapse)AuthorLines
2024-08-27rustc_codegen_llvm: Filter out unavailable LLVM featuresKajetan Puchalski-3/+4
Convert to_llvm_features to return Option<LLVMFeature> so that it can return None if the requested feature is not available for the current LLVM version. Add match rules to filter out aarch64 features not available in LLVM 17.
2024-08-27rustc_target: Remove fpmr target featureKajetan Puchalski-0/+6
FEAT_FPMR has been removed from upstream LLVM as of LLVM 19. Remove the feature from the target features list and temporarily hack the LLVM codegen to always enable it until the minimum LLVM version is bumped to 19.
2024-08-16Add `warn(unreachable_pub)` to `rustc_codegen_llvm`.Nicholas Nethercote-10/+10
2024-08-07Rollup merge of #128679 - RalfJung:codegen-fn-attrs, r=nikicMatthias Krüger-1/+2
codegen: better centralize function declaration attribute computation For some reason, the codegen backend has two functions that compute which attributes a function declaration gets: `apply_attrs_llfn` and `attributes::from_fn_attrs`. They are called in different places, on entirely different layers of abstraction. To me the code seems cleaner if we centralize this entirely in `apply_attrs_llfn`, so that's what this PR does.
2024-08-07codegen: better centralize function attribute computationRalf Jung-1/+2
2024-08-07Hide implicit target features from diagnostics when possibleCaleb Zulawski-1/+1
2024-07-30Rollup merge of #128141 - nikic:aarch64-bti, r=DianQK,cuviperMatthias Krüger-3/+28
Set branch protection function attributes Since LLVM 19, it is necessary to set not only module flags, but also function attributes for branch protection on aarch64. See https://github.com/llvm/llvm-project/commit/e15d67cfc2e5775cc79281aa860f3ad3be628f39 for the relevant LLVM change. Fixes https://github.com/rust-lang/rust/issues/127829.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-24Set branch protection function attributesNikita Popov-3/+28
Since LLVM 19, it is necessary to set not only module flags, but also function attributes for branch protection on aarch64. See https://github.com/llvm/llvm-project/commit/e15d67cfc2e5775cc79281aa860f3ad3be628f39 for the relevant LLVM change.
2024-07-17rustc_codegen_llvm: properly passing backchain attribute to LLVM ...liushuyu-0/+14
... this is a special attribute that was made to be a target-feature in LLVM 18+, but in all previous versions, this "feature" is a naked attribute. We will have to handle this situation differently than all other target-features.
2024-07-11Remove extern "wasm" ABINikita Popov-13/+1
Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked in #83788). As discussed in https://github.com/rust-lang/rust/pull/127513#issuecomment-2220410679 and following, this ABI is a failed experiment that did not end up being used for anything. Keeping support for this ABI in LLVM 19 would require us to switch wasm targets to the `experimental-mv` ABI, which we do not want to do. It should be noted that `Abi::Wasm` was internally used for two things: The `-Z wasm-c-abi=legacy` ABI that is still used by default on some wasm targets, and the `extern "wasm"` ABI. Despite both being `Abi::Wasm` internally, they were not the same. An explicit `extern "wasm"` additionally enabled the `+multivalue` feature. I've opted to remove `Abi::Wasm` in this patch entirely, instead of keeping it as an ABI with only internal usage. Both `-Z wasm-c-abi` variants are now treated as part of the normal C ABI, just with different different treatment in adjust_for_foreign_abi.
2024-06-25Support `#[patchable_function_entries]`Matthew Maurer-3/+6
See [RFC](https://github.com/maurer/rust-rfcs/blob/patchable-function-entry/text/0000-patchable-function-entry.md) (yet to be numbered) TODO before submission: * Needs an RFC * Improve error reporting for malformed attributes
2024-06-25Support for -Z patchable-function-entryMatthew Maurer-0/+26
`-Z patchable-function-entry` works like `-fpatchable-function-entry` on clang/gcc. The arguments are total nop count and function offset. See MCP rust-lang/compiler-team#704
2024-06-23compiler(nfc): -Cforce-frame-pointers is a FramePointerJubilee Young-2/+3
2024-04-01Use the `Align` type when parsing alignment attributesbeetrees-1/+1
2024-02-11is_closure_likeMichael Goulet-1/+1
2024-01-30Remove `ffi_returns_twice` featureclubby789-3/+0
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.