about summary refs log tree commit diff
path: root/tests/codegen/sanitizer/cfi
AgeCommit message (Collapse)AuthorLines
2025-07-22Rename `tests/codegen` into `tests/codegen-llvm`Guillaume Gomez-1384/+0
2025-06-22Fix tests to drop now-skipped codegenMark Rousskov-5/+9
2025-03-17Rollup merge of #138349 - 1c3t3a:external-weak-cfi, r=rcvalleMatthias Krüger-0/+24
Emit function declarations for functions with `#[linkage="extern_weak"]` Currently, when declaring an extern weak function in Rust, we use the following syntax: ```rust unsafe extern "C" { #[linkage = "extern_weak"] static FOO: Option<unsafe extern "C" fn() -> ()>; } ``` This allows runtime-checking the extern weak symbol through the Option. When emitting LLVM-IR, the Rust compiler currently emits this static as an i8, and a pointer that is initialized with the value of the global i8 and represents the nullabilty e.g. ``` `@FOO` = extern_weak global i8 `@_rust_extern_with_linkage_FOO` = internal global ptr `@FOO` ``` This approach does not work well with CFI, where we need to attach CFI metadata to a concrete function declaration, which was pointed out in https://github.com/rust-lang/rust/issues/115199. This change switches to emitting a proper function declaration instead of a global i8. This allows CFI to work for extern_weak functions. Example: ``` `@_rust_extern_with_linkage_FOO` = internal global ptr `@FOO` ... declare !type !61 !type !62 !type !63 !type !64 extern_weak void `@FOO(double)` unnamed_addr #6 ``` We keep initializing the Rust internal symbol with the function declaration, which preserves the correct behavior for runtime checking the Option. r? `@rcvalle` cc `@jakos-sec` try-job: test-various
2025-03-17Emit function declarations for functions with #[linkage="extern_weak"]Bastian Kersting-0/+24
Currently, when declaring an extern weak function in Rust, we use the following syntax: ```rust unsafe extern "C" { #[linkage = "extern_weak"] static FOO: Option<unsafe extern "C" fn() -> ()>; } ``` This allows runtime-checking the extern weak symbol through the Option. When emitting LLVM-IR, the Rust compiler currently emits this static as an i8, and a pointer that is initialized with the value of the global i8 and represents the nullabilty e.g. ``` @FOO = extern_weak global i8 @_rust_extern_with_linkage_FOO = internal global ptr @FOO ``` This approach does not work well with CFI, where we need to attach CFI metadata to a concrete function declaration, which was pointed out in https://github.com/rust-lang/rust/issues/115199. This change switches to emitting a proper function declaration instead of a global i8. This allows CFI to work for extern_weak functions. We keep initializing the Rust internal symbol with the function declaration, which preserves the correct behavior for runtime checking the Option. Co-authored-by: Jakob Koschel <jakobkoschel@google.com>
2025-03-11Implement `#[define_opaque]` attribute for functions.Oli Scherer-73/+61
2024-11-11CFI: Append debug location to CFI blocksBastian Kersting-0/+19
2024-10-23Set `signext` or `zeroext` for integer arguments on LoongArch64Asuna-2/+2
2024-08-21Add missing module flags for CFI and KCFI sanitizersSami Tolvanen-0/+10
Set the cfi-normalize-integers and kcfi-offset module flags when Control-Flow Integrity sanitizers are used, so functions generated by the LLVM backend use the same CFI/KCFI options as rustc. cfi-normalize-integers tells LLVM to also use integer normalization for generated functions when -Zsanitizer-cfi-normalize-integers is used. kcfi-offset specifies the number of prefix nops between the KCFI type hash and the function entry when -Z patchable-function-entry is used. Note that LLVM assumes all indirectly callable functions use the same number of prefix NOPs with -Zsanitizer=kcfi.
2024-06-12Require any function with a tait in its signature to actually constrain a ↵Oli Scherer-63/+73
hidden type
2024-06-07Fix codegen testOli Scherer-3/+3
2024-05-31Run rustfmt on `tests/codegen/`.Nicholas Nethercote-248/+256
Except for `simd-intrinsic/`, which has a lot of files containing multiple types like `u8x64` which really are better when hand-formatted. There is a surprising amount of two-space indenting in this directory. Non-trivial changes: - `rustfmt::skip` needed in `debug-column.rs` to preserve meaning of the test. - `rustfmt::skip` used in a few places where hand-formatting read more nicely: `enum/enum-match.rs` - Line number adjustments needed for the expected output of `debug-column.rs` and `coroutine-debug.rs`.
2024-05-28Bless codegen testOli Scherer-21/+23
2024-04-24Fix tests and blessGary Guo-1/+1
2024-04-06Rollup merge of #123525 - maurer:no-id-dyn2, r=compiler-errorsMatthias Krüger-21/+21
CFI: Don't rewrite ty::Dynamic directly Now that we're using a type folder, the arguments in predicates are processed automatically - we don't need to descend manually. We also want to keep projection clauses around, and this does so. r? `@compiler-errors`
2024-04-05CFI: Don't rewrite ty::Dynamic directlyMatthew Maurer-21/+21
Now that we're using a type folder, the arguments in predicates are processed automatically - we don't need to descend manually. We also want to keep projection clauses around, and this does so.
2024-04-04CFI: Restore typeid_for_instance default behaviorRamon de C Valle-2/+2
Restore typeid_for_instance default behavior of performing self type erasure, since it's the most common case and what it does most of the time. Using concrete self (or not performing self type erasure) is for assigning a secondary type id, and secondary type ids are only assigned when they're unique and to methods, and also are only tested for when methods are used as function pointers.
2024-04-02CFI: Switch sense of type erasure flagMatthew Maurer-2/+2
Previously, we had `NO_SELF_TYPE_ERASURE`, a negative configuration. Now we have `ERASE_SELF_TYPE`, a positive configuration.
2024-03-29Auto merge of #123071 - rcvalle:rust-cfi-fix-method-fn-ptr-cast, ↵bors-0/+22
r=compiler-errors CFI: Fix methods as function pointer cast Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers. This was split off from #116404. cc `@compiler-errors` `@workingjubilee`
2024-03-27CFI: Fix methods as function pointer castRamon de C Valle-0/+22
Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers.
2024-03-27CFI: Fix drop and drop_in_placeRamon de C Valle-0/+27
Fix drop and drop_in_place by transforming self of drop and drop_in_place methods into Drop trait objects.
2024-03-22CFI: Support self_cell-like recursionMatthew Maurer-0/+16
Current `transform_ty` attempts to avoid cycles when normalizing `#[repr(transparent)]` types to their interior, but runs afoul of this pattern used in `self_cell`: ``` struct X<T> { x: u8, p: PhantomData<T>, } #[repr(transparent)] struct Y(X<Y>); ``` When attempting to normalize Y, it will still cycle indefinitely. By using a types-visited list, this will instead get expanded exactly one layer deep to X<Y>, and then stop, not attempting to normalize `Y` any further.
2024-03-21CFI: Skip non-passed argumentsMatthew Maurer-32/+32
Rust will occasionally rely on fn((), X) -> Y being compatible with fn(X) -> Y, since () is a non-passed argument. Relax CFI by choosing not to encode non-passed arguments.
2024-03-14CFI: Break tests into smaller filesRamon de C Valle-0/+1254
Break type metadata identifiers tests into smaller set of tests/files, and move CFI (and KCFI) codegen tests to a cfi (and kcfi) subdirectory.