Skip to content

Commit ea631ed

Browse files
committed
rustc_target: add is_like_cheri and use it to translate inline asm of black_box
1 parent 5113ec4 commit ea631ed

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

.cirrus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ x_check_task:
5858
- export CCACHE_REMOTE_STORAGE="http://${CIRRUS_HTTP_CACHE_HOST}/${CIRRUS_OS}/"
5959
- export CCACHE_REMOTE_ONLY=1
6060
- env
61-
pull_master_script: git fetch origin master
61+
pull_master_script: git fetch origin master:master
6262
tidy_script: CC="clang" CXX="clang++" ./x test tidy
6363
check_script: CC="clang" CXX="clang++" ./x check
6464
ui_test_script: CC="clang" CXX="clang++" ./x test ui
@@ -118,7 +118,7 @@ run_cheri_tests_task:
118118
verify_xmake_script: /root/.local/bin/xmake -v
119119
install_rust_script: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y && . "$CARGO_HOME/env"
120120
verify_rust_script: . "$CARGO_HOME/env" && cargo --version
121-
build_sail_sim_script: git clone --recurse-submodules https://github.com/CHERIoT-Platform/cheriot-sail && cd cheriot-sail && opam init --reinit --bypass-check --disable-sandboxing --disable-shell-hook && eval $(opam env) && opam install sail --confirm-level=unsafe-yes && make csim && cp c_emulator/cheriot_sim /usr/local/bin
121+
build_sail_sim_script: git clone --recurse-submodules --depth=1 https://github.com/CHERIoT-Platform/cheriot-sail && cd cheriot-sail && opam init --reinit --bypass-check --disable-sandboxing --disable-shell-hook && eval $(opam env) && opam install sail --confirm-level=unsafe-yes && make csim && cp c_emulator/cheriot_sim /usr/local/bin
122122
gen_bootstrap_script: ./cheri/gen_bootstrap.sh --build-clang
123123
setup_env_script:
124124
- export CCACHE_REMOTE_STORAGE="http://${CIRRUS_HTTP_CACHE_HOST}/${CIRRUS_OS}/"

cheri/tests/black_box.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![no_std]
2+
3+
extern crate cheriot;
4+
5+
#[no_mangle]
6+
extern "C" fn test_black_box() -> i32 {
7+
core::hint::black_box(0)
8+
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_middle::{bug, span_bug};
1818
use rustc_span::{Span, Symbol, sym};
1919
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
2020
use rustc_target::callconv::PassMode;
21+
use rustc_target::spec::HasTargetSpec;
2122
use tracing::debug;
2223

2324
use crate::abi::FnAbiLlvmExt;
@@ -515,6 +516,12 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
515516
// the memory.
516517
let (constraint, inputs): (&str, &[_]) = if result.layout.is_zst() {
517518
("~{memory}", &[])
519+
} else if self.target_spec().is_like_cheri {
520+
// When the result of the inline assembly is used in later computations, it is
521+
// usually stored in a pointer. Thus, in CHERI-like target platforms, the
522+
// register holding the result must be able to fit a capability rather than
523+
// being a simple "r" register - thus the "C" requirement.
524+
("C,~{memory}", &result_val_span)
518525
} else {
519526
("r,~{memory}", &result_val_span)
520527
};

compiler/rustc_target/src/spec/json.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl Target {
151151
forward!(is_like_wasm);
152152
forward!(is_like_android);
153153
forward!(is_like_vexos);
154+
forward!(is_like_cheri);
154155
forward!(binary_format);
155156
forward!(default_dwarf_version);
156157
forward!(allows_weak_linkage);
@@ -344,6 +345,7 @@ impl ToJson for Target {
344345
target_option_val!(is_like_wasm);
345346
target_option_val!(is_like_android);
346347
target_option_val!(is_like_vexos);
348+
target_option_val!(is_like_cheri);
347349
target_option_val!(binary_format);
348350
target_option_val!(default_dwarf_version);
349351
target_option_val!(allows_weak_linkage);
@@ -564,6 +566,7 @@ struct TargetSpecJson {
564566
is_like_wasm: Option<bool>,
565567
is_like_android: Option<bool>,
566568
is_like_vexos: Option<bool>,
569+
is_like_cheri: Option<bool>,
567570
binary_format: Option<BinaryFormat>,
568571
default_dwarf_version: Option<u32>,
569572
allows_weak_linkage: Option<bool>,

compiler/rustc_target/src/spec/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,8 @@ pub struct TargetOptions {
21192119
pub is_like_android: bool,
21202120
/// Whether a target toolchain is like VEXos, the operating system used by the VEX Robotics V5 Brain.
21212121
pub is_like_vexos: bool,
2122+
/// Whether a target toolchain is like CHERI.
2123+
pub is_like_cheri: bool,
21222124
/// Target's binary file format. Defaults to BinaryFormat::Elf
21232125
pub binary_format: BinaryFormat,
21242126
/// Default supported version of DWARF on this platform.
@@ -2500,6 +2502,7 @@ impl Default for TargetOptions {
25002502
is_like_wasm: false,
25012503
is_like_android: false,
25022504
is_like_vexos: false,
2505+
is_like_cheri: false,
25032506
binary_format: BinaryFormat::Elf,
25042507
default_dwarf_version: 4,
25052508
allows_weak_linkage: true,
@@ -2669,6 +2672,11 @@ impl Target {
26692672
self.arch == "wasm32" || self.arch == "wasm64",
26702673
"`is_like_wasm` must be set if and only if `arch` is `wasm32` or `wasm64`"
26712674
);
2675+
check_eq!(
2676+
self.families.contains(&Cow::Borrowed("cheri")),
2677+
self.is_like_cheri,
2678+
"`is_like_cheri` must be set if `cheri` is one of the families the target belongs to"
2679+
);
26722680
if self.is_like_msvc {
26732681
check!(self.is_like_windows, "if `is_like_msvc` is set, `is_like_windows` must be set");
26742682
}

compiler/rustc_target/src/spec/targets/riscv32cheriot_unknown_cheriotrtos.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(crate) fn target() -> Target {
3333
eh_frame_header: false,
3434
families: cvs!["cheri", "cheriot"],
3535
os: "cheriotrtos".into(),
36+
is_like_cheri: true,
3637
executables: false,
3738
default_address_space: rustc_abi::AddressSpace(200),
3839
..Default::default()

0 commit comments

Comments
 (0)