Skip to content

Commit 4c2cfc6

Browse files
committed
Added initial configuration for BSAN.
Specified bsan branch of LLVM submodule. Added Borrow sanitizer options to frontend. Added additional configuration flags for BSAN. Updated llvm submodule and ensured that retags are allowed in subsequent MIR passes. Updated LLVM project.
1 parent 5077297 commit 4c2cfc6

File tree

36 files changed

+193
-33
lines changed

36 files changed

+193
-33
lines changed

.github/workflows/sync.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: sync
2+
on: workflow_dispatch
3+
permissions:
4+
contents: read
5+
pages: write
6+
id-token: write
7+
defaults:
8+
run:
9+
shell: bash
10+
concurrency:
11+
group: "sync"
12+
cancel-in-progress: true
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Identity
18+
run: |
19+
git config --global user.name "github-actions[bot]"
20+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
- name: Rebase
25+
run: src/ci/scripts/sync.sh
26+
- name: Build
27+
run: ./x.py build --stage 1 library

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
[submodule "src/gcc"]
5555
path = src/gcc
5656
url = https://github.com/rust-lang/gcc.git
57-
shallow = true
57+
shallow = true

Cargo.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ dependencies = [
290290
"generic-array",
291291
]
292292

293+
[[package]]
294+
name = "bsan"
295+
version = "0.1.0"
296+
293297
[[package]]
294298
name = "bstr"
295299
version = "1.10.0"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"src/rustc-std-workspace/rustc-std-workspace-alloc",
88
"src/rustc-std-workspace/rustc-std-workspace-std",
99
"src/rustdoc-json-types",
10+
"src/tools/bsan",
1011
"src/tools/build_helper",
1112
"src/tools/cargotest",
1213
"src/tools/clippy",

compiler/rustc_borrowck/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ use rustc_middle::mir::*;
3636
use rustc_middle::query::Providers;
3737
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode};
3838
use rustc_middle::{bug, span_bug};
39-
use rustc_mir_dataflow::Analysis;
4039
use rustc_mir_dataflow::impls::{
4140
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
4241
};
4342
use rustc_mir_dataflow::move_paths::{
4443
InitIndex, InitLocation, LookupResult, MoveData, MoveOutIndex, MovePathIndex,
4544
};
45+
use rustc_mir_dataflow::Analysis;
4646
use rustc_session::lint::builtin::UNUSED_MUT;
4747
use rustc_span::{Span, Symbol};
4848
use smallvec::SmallVec;
@@ -656,8 +656,12 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
656656
state,
657657
);
658658
}
659+
StatementKind::Retag { .. } => {
660+
if !self.infcx.tcx.sess.emit_retags() {
661+
bug!("Statement not allowed in this MIR phase")
662+
}
663+
}
659664
StatementKind::Nop
660-
| StatementKind::Retag { .. }
661665
| StatementKind::Deinit(..)
662666
| StatementKind::SetDiscriminant { .. } => {
663667
bug!("Statement not allowed in this MIR phase")
@@ -1771,11 +1775,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
17711775
mpi,
17721776
);
17731777
} // Only query longest prefix with a MovePath, not further
1774-
// ancestors; dataflow recurs on children when parents
1775-
// move (to support partial (re)inits).
1776-
//
1777-
// (I.e., querying parents breaks scenario 7; but may want
1778-
// to do such a query based on partial-init feature-gate.)
1778+
// ancestors; dataflow recurs on children when parents
1779+
// move (to support partial (re)inits).
1780+
//
1781+
// (I.e., querying parents breaks scenario 7; but may want
1782+
// to do such a query based on partial-init feature-gate.)
17791783
}
17801784

17811785
/// Subslices correspond to multiple move paths, so we iterate through the

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,10 +1258,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12581258
"Unexpected NonDivergingIntrinsic::CopyNonOverlapping, should only appear after lowering_intrinsics",
12591259
),
12601260
},
1261+
StatementKind::Retag { .. } => {
1262+
if !self.infcx.tcx.sess.emit_retags() {
1263+
bug!("Statement not allowed in this MIR phase")
1264+
}
1265+
},
12611266
StatementKind::FakeRead(..)
12621267
| StatementKind::StorageLive(..)
12631268
| StatementKind::StorageDead(..)
1264-
| StatementKind::Retag { .. }
12651269
| StatementKind::Coverage(..)
12661270
| StatementKind::ConstEvalCounter
12671271
| StatementKind::PlaceMention(..)

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ pub(crate) fn sanitize_attrs<'ll>(
114114
if enabled.contains(SanitizerSet::SAFESTACK) {
115115
attrs.push(llvm::AttributeKind::SanitizeSafeStack.create_attr(cx.llcx));
116116
}
117+
if enabled.contains(SanitizerSet::BORROW) {
118+
attrs.push(llvm::AttributeKind::SanitizeBorrow.create_attr(cx.llcx));
119+
}
117120
attrs
118121
}
119122

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ pub(crate) unsafe fn llvm_optimize(
553553
sanitize_kernel_address_recover: config
554554
.sanitizer_recover
555555
.contains(SanitizerSet::KERNELADDRESS),
556+
sanitize_borrow: config.sanitizer.contains(SanitizerSet::BORROW),
556557
})
557558
} else {
558559
None

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pub enum AttributeKind {
252252
FnRetThunkExtern = 41,
253253
Writable = 42,
254254
DeadOnUnwind = 43,
255+
SanitizeBorrow = 44,
255256
}
256257

257258
/// LLVMIntPredicate
@@ -541,6 +542,7 @@ pub struct SanitizerOptions {
541542
pub sanitize_hwaddress_recover: bool,
542543
pub sanitize_kernel_address: bool,
543544
pub sanitize_kernel_address_recover: bool,
545+
pub sanitize_borrow: bool,
544546
}
545547

546548
/// LLVMRelocMode

compiler/rustc_codegen_llvm/src/retag.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)