Skip to content

Commit a679202

Browse files
authored
Merge pull request #5 from xdoardo/llvm-preserve-cheri-tags
Adapt Rust's LLVM wrapper to CHERIoT-Platform's LLVM
2 parents 46e1621 + b4835c3 commit a679202

File tree

14 files changed

+111
-29
lines changed

14 files changed

+111
-29
lines changed

.cirrus.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ pr_check_commits_task:
3232
x_check_task:
3333
skip: $CIRRUS_PR == ""
3434
name: (PR) Run ./x check
35-
depends_on: (PR) Check commits structure
35+
# TODO(xdoardo): Figure out when it makes sense to have this dependency, or
36+
# how that dependency should actually work. Having this dependency would
37+
# pretty much mean making every PR that merges changes on `beta` to `master`
38+
# to have failing CI, which would be the reason why we want to make PRs and
39+
# not direct pushes in the first place.
40+
# depends_on: (PR) Check commits structure
3641
timeout_in: 240m
3742
gce_instance: &arm_vm
3843
image_project: ubuntu-os-cloud
@@ -54,6 +59,8 @@ x_check_task:
5459
- export CCACHE_REMOTE_STORAGE="http://${CIRRUS_HTTP_CACHE_HOST}/${CIRRUS_OS}/"
5560
- export CCACHE_REMOTE_ONLY=1
5661
- env
57-
test_script: CC="clang" CXX="clang++" ./x check
62+
pull_master_script: git fetch origin master
63+
tidy_script: CC="clang" CXX="clang++" ./x test tidy
64+
check_script: CC="clang" CXX="clang++" ./x check
5865

5966
# -- End PR tasks

cheri/gen_bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ change-id = 140732
1717
ccache = true
1818
1919
[rust]
20-
#channel = "nightly"
20+
channel = "beta"
2121
#codegen-backends = ["llvm"]
2222
#debug = true
2323
#debuginfo-level = 2

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
1212
use rustc_apfloat::{Float, Round, Status, ieee};
1313
use rustc_codegen_ssa::MemFlags;
1414
use rustc_codegen_ssa::common::{
15-
AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
15+
AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind, PreserveCheriTags,
1616
};
1717
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1818
use rustc_codegen_ssa::mir::place::PlaceRef;
@@ -1369,6 +1369,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13691369
_src_align: Align,
13701370
size: RValue<'gcc>,
13711371
flags: MemFlags,
1372+
_preserve_cheri_tags: PreserveCheriTags,
13721373
) {
13731374
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memcpy not supported");
13741375
let size = self.intcast(size, self.type_size_t(), false);
@@ -1391,6 +1392,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13911392
_src_align: Align,
13921393
size: RValue<'gcc>,
13931394
flags: MemFlags,
1395+
_preserve_cheri_flags: PreserveCheriTags,
13941396
) {
13951397
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memmove not supported");
13961398
let size = self.intcast(size, self.type_size_t(), false);

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_abi::ExternAbi;
1212
use rustc_abi::{BackendRepr, HasDataLayout};
1313
use rustc_codegen_ssa::MemFlags;
1414
use rustc_codegen_ssa::base::wants_msvc_seh;
15-
use rustc_codegen_ssa::common::IntPredicate;
15+
use rustc_codegen_ssa::common::{IntPredicate, PreserveCheriTags};
1616
use rustc_codegen_ssa::errors::InvalidMonomorphization;
1717
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1818
use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
@@ -771,6 +771,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
771771
scratch_align,
772772
bx.const_usize(self.layout.size.bytes()),
773773
MemFlags::empty(),
774+
PreserveCheriTags::Unknown,
774775
);
775776

776777
bx.lifetime_end(scratch, scratch_size);

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_abi::{
77
X86Call,
88
};
99
use rustc_codegen_ssa::MemFlags;
10+
use rustc_codegen_ssa::common::PreserveCheriTags;
1011
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1112
use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
1213
use rustc_codegen_ssa::traits::*;
@@ -238,6 +239,8 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
238239
scratch_align,
239240
bx.const_usize(copy_bytes),
240241
MemFlags::empty(),
242+
// Handling of CHERI capabilities could probably be more efficient.
243+
PreserveCheriTags::Unknown,
241244
);
242245
bx.lifetime_end(llscratch, scratch_size);
243246
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::attributes;
3535
use crate::common::Funclet;
3636
use crate::context::{CodegenCx, FullCx, GenericCx, SCx};
3737
use crate::llvm::{
38-
self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, GEPNoWrapFlags, Metadata, True,
38+
self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, GEPNoWrapFlags, Metadata, True, PreserveCheriTags
3939
};
4040
use crate::type_::Type;
4141
use crate::type_of::LayoutLlvmExt;
@@ -1106,9 +1106,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11061106
src_align: Align,
11071107
size: &'ll Value,
11081108
flags: MemFlags,
1109+
preserve_tags: rustc_codegen_ssa::common::PreserveCheriTags,
11091110
) {
11101111
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memcpy not supported");
11111112
let size = self.intcast(size, self.type_isize(), false);
1113+
let preserve_tags = PreserveCheriTags::from_generic(preserve_tags);
11121114
let is_volatile = flags.contains(MemFlags::VOLATILE);
11131115
unsafe {
11141116
llvm::LLVMRustBuildMemCpy(
@@ -1118,6 +1120,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11181120
src,
11191121
src_align.bytes() as c_uint,
11201122
size,
1123+
preserve_tags,
11211124
is_volatile,
11221125
);
11231126
}
@@ -1131,9 +1134,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11311134
src_align: Align,
11321135
size: &'ll Value,
11331136
flags: MemFlags,
1137+
preserve_tags: rustc_codegen_ssa::common::PreserveCheriTags,
11341138
) {
11351139
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memmove not supported");
11361140
let size = self.intcast(size, self.type_isize(), false);
1141+
let preserve_tags = PreserveCheriTags::from_generic(preserve_tags);
11371142
let is_volatile = flags.contains(MemFlags::VOLATILE);
11381143
unsafe {
11391144
llvm::LLVMRustBuildMemMove(
@@ -1143,6 +1148,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11431148
src,
11441149
src_align.bytes() as c_uint,
11451150
size,
1151+
preserve_tags,
11461152
is_volatile,
11471153
);
11481154
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,25 @@ pub(crate) enum Opcode {
741741
CatchSwitch = 65,
742742
}
743743

744+
/// LLVMPreserveCheriTags
745+
#[derive(Copy, Clone)]
746+
#[repr(C)]
747+
pub(crate) enum PreserveCheriTags {
748+
Unknown,
749+
Required,
750+
Unnecessary,
751+
}
752+
753+
impl PreserveCheriTags {
754+
pub(crate) fn from_generic(value: rustc_codegen_ssa::common::PreserveCheriTags) -> Self {
755+
match value {
756+
rustc_codegen_ssa::common::PreserveCheriTags::Unknown => PreserveCheriTags::Unknown,
757+
rustc_codegen_ssa::common::PreserveCheriTags::Required => PreserveCheriTags::Required,
758+
rustc_codegen_ssa::common::PreserveCheriTags::Unnecessary => PreserveCheriTags::Unnecessary,
759+
}
760+
}
761+
}
762+
744763
unsafe extern "C" {
745764
type Opaque;
746765
}
@@ -1933,6 +1952,7 @@ unsafe extern "C" {
19331952
Src: &'a Value,
19341953
SrcAlign: c_uint,
19351954
Size: &'a Value,
1955+
PreserveTags: PreserveCheriTags,
19361956
IsVolatile: bool,
19371957
) -> &'a Value;
19381958
pub(crate) fn LLVMRustBuildMemMove<'a>(
@@ -1942,6 +1962,7 @@ unsafe extern "C" {
19421962
Src: &'a Value,
19431963
SrcAlign: c_uint,
19441964
Size: &'a Value,
1965+
PreserveTags: PreserveCheriTags,
19451966
IsVolatile: bool,
19461967
) -> &'a Value;
19471968
pub(crate) fn LLVMRustBuildMemSet<'a>(

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_abi::{Align, BackendRepr, Endian, HasDataLayout, Primitive, Size, TyAndLayout};
22
use rustc_codegen_ssa::MemFlags;
3-
use rustc_codegen_ssa::common::IntPredicate;
3+
use rustc_codegen_ssa::common::{IntPredicate, PreserveCheriTags};
44
use rustc_codegen_ssa::mir::operand::OperandRef;
55
use rustc_codegen_ssa::traits::{
66
BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods, LayoutTypeCodegenMethods,
@@ -735,6 +735,7 @@ fn copy_to_temporary_if_more_aligned<'ll, 'tcx>(
735735
src_align,
736736
bx.const_u32(layout.layout.size().bytes() as u32),
737737
MemFlags::empty(),
738+
PreserveCheriTags::Unknown,
738739
);
739740
tmp
740741
} else {

compiler/rustc_codegen_ssa/src/common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ pub enum AtomicRmwBinOp {
5959
AtomicUMin,
6060
}
6161

62+
#[derive(Copy, Clone, Debug)]
63+
pub enum PreserveCheriTags {
64+
Unknown,
65+
Required,
66+
Unnecessary,
67+
}
68+
6269
#[derive(Copy, Clone, Debug)]
6370
pub enum SynchronizationScope {
6471
SingleThread,

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::operand::OperandValue::{Immediate, Pair, Ref, ZeroSized};
2121
use super::place::{PlaceRef, PlaceValue};
2222
use super::{CachedLlbb, FunctionCx, LocalRef};
2323
use crate::base::{self, is_call_from_compiler_builtins_to_upstream_monomorphization};
24-
use crate::common::{self, IntPredicate};
24+
use crate::common::{self, IntPredicate, PreserveCheriTags};
2525
use crate::errors::CompilerBuiltinsCannotCall;
2626
use crate::traits::*;
2727
use crate::{MemFlags, meth};
@@ -1601,6 +1601,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16011601
align,
16021602
bx.const_usize(copy_bytes),
16031603
MemFlags::empty(),
1604+
PreserveCheriTags::Unknown,
16041605
);
16051606
// ...and then load it with the ABI type.
16061607
llval = load_cast(bx, cast, llscratch, scratch_align);

0 commit comments

Comments
 (0)