about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/context.rs
AgeCommit message (Collapse)AuthorLines
2023-11-11Add -Z llvm_module_flagPaul Menage-0/+18
Allow adding values to the `!llvm.module.flags` metadata for a generated module. The syntax is `-Z llvm_module_flag=<name>:<type>:<value>:<behavior>` Currently only u32 values are supported but the type is required to be specified for forward compatibility. The `behavior` element must match one of the named LLVM metadata behaviors.viors. This flag is expected to be perma-unstable.
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-1/+1
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-09-24Add OwnedTargetMachine to manage llvm:TargetMachine. Uses pointersFlorian Schmiderer-2/+2
instead of &'static mut and provides safe interface to create/dispose it.
2023-08-28Don't ICE on layout computation failureKatherine Philip-1/+2
2023-08-09rustc: Move `crate_types` from `Session` to `GlobalCtxt`Vadim Petrochenkov-1/+1
Removes a piece of mutable state. Follow up to #114578.
2023-08-07Update powerpc data layoutsNikita Popov-0/+11
Function pointer alignment is specified since https://reviews.llvm.org/D147016.
2023-08-06Add a new `compare_bytes` intrinsic instead of calling `memcmp` directlyScott McMurray-1/+2
2023-08-05Fix ICE failed to get layout for ReferencesErroryukang-1/+1
2023-07-29cg_llvm: remove pointee types and pointercast/bitcast-of-ptrErik Desjardins-34/+20
2023-07-21Support `.comment` section like GCC/Clang (`!llvm.ident`)Miguel Ojeda-0/+18
Both GCC and Clang write by default a `.comment` section with compiler information: ```txt $ gcc -c -xc /dev/null && readelf -p '.comment' null.o String dump of section '.comment': [ 1] GCC: (GNU) 11.2.0 $ clang -c -xc /dev/null && readelf -p '.comment' null.o String dump of section '.comment': [ 1] clang version 14.0.1 (https://github.com/llvm/llvm-project.git c62053979489ccb002efe411c3af059addcb5d7d) ``` They also implement the `-Qn` flag to avoid doing so: ```txt $ gcc -Qn -c -xc /dev/null && readelf -p '.comment' null.o readelf: Warning: Section '.comment' was not dumped because it does not exist! $ clang -Qn -c -xc /dev/null && readelf -p '.comment' null.o readelf: Warning: Section '.comment' was not dumped because it does not exist! ``` So far, `rustc` only does it for WebAssembly targets and only when debug info is enabled: ```txt $ echo 'fn main(){}' | rustc --target=wasm32-unknown-unknown --emit=llvm-ir -Cdebuginfo=2 - && grep llvm.ident rust_out.ll !llvm.ident = !{!27} ``` In the RFC part of this PR it was decided to always add the information, which gets us closer to other popular compilers. An opt-out flag like GCC and Clang may be added later on if deemed necessary. Implementation-wise, this covers both `ModuleLlvm::new()` and `ModuleLlvm::new_metadata()` cases by moving the addition to `context::create_module` and adds a few test cases. ThinLTO also sees the `llvm.ident` named metadata duplicated (in temporary outputs), so this deduplicates it like it is done for `wasm.custom_sections`. The tests also check this duplication does not take place. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-07-05Revert "use new c literals instead of cstr! macro"León Orell Valerian Liehr-24/+20
This reverts commit a17561ffc90c900cb7d0e96b00c6381244764ef7.
2023-06-07add comment regarding `__gxx_wasm_personality_v0`Jan-Mirko Otter-0/+4
2023-06-07wasm exception handlingJan-Mirko Otter-7/+12
2023-06-07add wasm eh intrinsicsJan-Mirko Otter-0/+4
2023-06-02Rollup merge of #111647 - klensy:cstr, r=oli-obkMatthias Krüger-20/+24
use c literals in compiler and library Use c literals #108801 in compiler and library currently blocked on: * <strike>rustfmt: don't know how to format c literals</strike> nope, nightly one works. * <strike>bootstrap</strike> r? `@ghost` `@rustbot` blocked
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-13/+4
2023-05-31use new c literals instead of cstr! macroklensy-20/+24
2023-05-03Add cross-language LLVM CFI support to the Rust compilerRamon de C Valle-4/+15
This commit adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395). It provides 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). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653. Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).
2023-03-07Auto merge of #95317 - Jules-Bertholet:round_ties_to_even, ↵bors-0/+4
r=pnkfelix,m-ou-se,scottmcm Add `round_ties_even` to `f32` and `f64` Tracking issue: #96710 Redux of #82273. See also #55107 Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this. Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`). Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight. Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
2023-02-24Use `List::empty()` instead of `mk_substs(&[])`.Nicholas Nethercote-1/+1
2023-02-24Rename many interner functions.Nicholas Nethercote-8/+3
(This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup
2023-02-18add a summary, in addition to the linkTshepang Mbambo-2/+5
2023-02-18link to llvm changes that prompted the special casesTshepang Mbambo-0/+2
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-6/+2
2023-02-10Update the minimum external LLVM to 14Josh Stone-11/+0
2023-01-31Rollup merge of #107412 - tshepang:needless-check, r=wesleywiserGuillaume Gomez-5/+2
avoid needless checks
2023-01-28make more pleasant to readTshepang Mbambo-1/+1
2023-01-28avoid needless checksTshepang Mbambo-5/+2
2022-12-20Use `Error` behavior for LLVM versions prior to 15Arvind Mukund-4/+10
CI fails when building with LLVM-13. This raises unknown behavior constant `8` from IRVerifier.
2022-12-19Correct ModFlagBehavior for Aarch64 on LLVM-15Arvind Mukund-4/+4
When building with Fat LTO and BTI enabled on aarch64, the BTI is set to `Module::Min` for alloc shim but is set to `Module::Error` for the crate. This was fine when we were using LLVM-14 but LLVM-15 changes it's behaviour to support for compiling with different `mbranch-protection` flags. Refer: https://github.com/rust-lang/llvm-project/commit/b0343a38a5910e980bb031e4014655d77cd0c162
2022-12-17Auto merge of #105421 - jacobbramley:jb/branch-prot-check, r=nagisabors-4/+6
Check AArch64 branch-protection earlier in the pipeline. As suggested in #93516. r? `@nagisa`
2022-12-13bug! if branch-protection makes it to non-AArch64 codegen.Jacob Bramley-3/+7
2022-12-11Add `round_ties_even` to `f32` and `f64`Jules Bertholet-0/+4
2022-12-08Add LLVM KCFI support to the Rust compilerRamon de C Valle-0/+5
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-06Check AArch64 branch-protection earlier in the pipeline.Jacob Bramley-5/+3
As suggested in #93516.
2022-11-19Rollup merge of #104001 - Ayush1325:custom-entry, r=bjorn3Dylan DPC-2/+8
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-11Improve generating Custom entry functionAyush Singh-2/+8
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-09Use `LayoutError`'s implementation of `IntoDiagnostic`SLASHLogin-3/+3
2022-11-09Port layout size overflowSLASHLogin-2/+3
2022-11-09Port branch protection on aarch64SLASHLogin-1/+2
2022-11-06LLVM 16: Update RISCV data layoutTim Neumann-0/+4
2022-10-01Remove several unused methods from MiscMethodsbjorn3-20/+1
2022-09-29Adjust the s390x data layout for LLVM 16Josh Stone-0/+5
LLVM [D131158] changed the SystemZ data layout to always set 64-bit vector alignment, which used to be conditional on the "vector" feature. [D131158]: https://reviews.llvm.org/D131158
2022-08-21Do not use void pointer for `ptr_mask` intrinsicMaybe Waffle-2/+1
I couldn't find where exactly it's documented, but apperantly pointers to void type are invalid in llvm - void is only allowed as a return type of functions.
2022-08-21Add pointer masking convenience functionsMaybe Waffle-0/+4
This commit adds the following functions all of which have a signature `pointer, usize -> pointer`: - `<*mut T>::mask` - `<*const T>::mask` - `intrinsics::ptr_mask` These functions are equivalent to `.map_addr(|a| a & mask)` but they utilize `llvm.ptrmask` llvm intrinsic. *masks your pointers*
2022-08-14Update the minimum external LLVM to 13Josh Stone-11/+0
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-06-28Avoid unnecessary string interning for const_strbjorn3-2/+1
2022-06-18rustc_target: Remove some redundant target propertiesVadim Petrochenkov-1/+1
2022-06-14Add llvm.type.checked.load intrinsicflip1995-3/+5
Add the intrinsic declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) This is used in the VFE optimization when lowering loading functions from vtables to LLVM IR. The `metadata` is used to map the function to all vtables this function could belong to. This ensures that functions from vtables that might be used somewhere won't get removed.