Skip to content

Commit 93c2bac

Browse files
committed
CFI: Switch sense of type erasure flag
Previously, we had `NO_SELF_TYPE_ERASURE`, a negative configuration. Now we have `ERASE_SELF_TYPE`, a positive configuration.
1 parent 36b6f9b commit 93c2bac

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

compiler/rustc_codegen_llvm/src/declare.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
147147
for options in [
148148
TypeIdOptions::GENERALIZE_POINTERS,
149149
TypeIdOptions::NORMALIZE_INTEGERS,
150-
TypeIdOptions::NO_SELF_TYPE_ERASURE,
150+
TypeIdOptions::ERASE_SELF_TYPE,
151151
]
152152
.into_iter()
153153
.powerset()
@@ -173,7 +173,9 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
173173

174174
if self.tcx.sess.is_sanitizer_kcfi_enabled() {
175175
// LLVM KCFI does not support multiple !kcfi_type attachments
176-
let mut options = TypeIdOptions::empty();
176+
// Default to erasing the self type. If we need the concrete type, there will be a
177+
// hint in the instance.
178+
let mut options = TypeIdOptions::ERASE_SELF_TYPE;
177179
if self.tcx.sess.is_sanitizer_cfi_generalize_pointers_enabled() {
178180
options.insert(TypeIdOptions::GENERALIZE_POINTERS);
179181
}

compiler/rustc_symbol_mangling/src/typeid.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ bitflags! {
2424
/// `-fsanitize-cfi-icall-experimental-normalize-integers` option for cross-language LLVM
2525
/// CFI and KCFI support.
2626
const NORMALIZE_INTEGERS = 4;
27-
/// Do not perform self type erasure for attaching a secondary type id to methods with their
28-
/// concrete self so they can be used as function pointers.
29-
const NO_SELF_TYPE_ERASURE = 8;
27+
/// Generalize the instance by erasing the concrete `Self` type where possible.
28+
/// Only has an effect on `{kcfi_,}typeid_for_instance`.
29+
const ERASE_SELF_TYPE = 8;
3030
}
3131
}
3232

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ pub fn typeid_for_instance<'tcx>(
11721172
instance.args = tcx.mk_args_trait(invoke_ty, trait_ref.args.into_iter().skip(1));
11731173
}
11741174

1175-
if !options.contains(EncodeTyOptions::NO_SELF_TYPE_ERASURE) {
1175+
if options.contains(EncodeTyOptions::ERASE_SELF_TYPE) {
11761176
if let Some(impl_id) = tcx.impl_of_method(instance.def_id())
11771177
&& let Some(trait_ref) = tcx.impl_trait_ref(impl_id)
11781178
{

tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-method-secondary-typeid.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ impl Trait1 for Type1 {
1818
}
1919

2020

21-
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEEE"}
22-
// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type1EE"}
21+
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type1EE"}
22+
// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEEE"}

0 commit comments

Comments
 (0)