Skip to content

Added support for retagging subfields of places. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: bsan
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,18 @@ dependencies = [
name = "bsan-rt"
version = "0.1.0"
dependencies = [
"bsan-shared",
"cbindgen",
"hashbrown 0.15.2",
"libc",
"rustc-hash 2.1.1",
"smallvec",
]

[[package]]
name = "bsan-shared"
version = "0.1.0"

[[package]]
name = "bstr"
version = "1.10.0"
Expand Down Expand Up @@ -3546,6 +3551,7 @@ dependencies = [
"ar_archive_writer",
"arrayvec",
"bitflags 2.6.0",
"bsan-shared",
"cc",
"either",
"itertools",
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
"src/tools/rustfmt",
"src/tools/miri",
"src/tools/miri/cargo-miri",
"src/tools/bsan/bsan-shared/",
"src/tools/bsan/bsan-driver/",
"src/tools/bsan/bsan-driver/cargo-bsan",
"src/tools/bsan/bsan-rt/",
Expand All @@ -49,7 +50,7 @@ members = [
"src/tools/opt-dist",
"src/tools/coverage-dump",
"src/tools/rustc-perf-wrapper",
"src/tools/wasm-component-ld",
"src/tools/wasm-component-ld", "src/tools/bsan/bsan-shared",
]

exclude = [
Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use std::{iter, ptr};
use libc::{c_char, c_uint};
use rustc_abi as abi;
use rustc_abi::{Align, Size, WrappingRange};
use rustc_codegen_ssa::MemFlags;
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind};
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::{MemFlags, RetagInfo};
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::mir::{PlaceKind, RetagKind};
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers,
TyAndLayout,
Expand Down Expand Up @@ -1164,16 +1163,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
self.call_lifetime_intrinsic("llvm.lifetime.end.p0i8", ptr, size);
}

fn retag(
&mut self,
place: PlaceValue<&'ll Value>,
place_kind: PlaceKind,
retag_kind: RetagKind,
) {
fn retag(&mut self, place: PlaceValue<Self::Value>, info: RetagInfo) {
self.call_intrinsic("llvm.bsan.retag", &[
place.llval,
self.cx.const_i8(place_kind as i8),
self.cx.const_i8(retag_kind as i8),
self.const_usize(info.size as u64),
self.const_u8(info.perm_kind.into()),
self.const_u8(info.protector_kind as u8),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ impl<'ll> CodegenCx<'ll, '_> {

ifn!("llvm.ptrmask", fn(ptr, t_isize) -> ptr);

ifn!("llvm.bsan.retag", fn(ptr, t_i8, t_i8) -> void);
ifn!("llvm.bsan.retag", fn(ptr, t_isize, t_i8, t_i8) -> void);

None
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
ar_archive_writer = "0.4.2"
arrayvec = { version = "0.7", default-features = false }
bitflags = "2.4.1"
bsan-shared = { path = "../../src/tools/bsan/bsan-shared" }
cc = "1.1.23"
either = "1.5.0"
itertools = "0.12"
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub mod size_of_val;
pub mod target_features;
pub mod traits;

pub use bsan_shared::RetagInfo;

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

pub struct ModuleCodegen<M> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod intrinsic;
mod locals;
pub mod operand;
pub mod place;
mod retag;
mod rvalue;
mod statement;

Expand Down
Loading
Loading