Skip to content

Commit 311c327

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 65c6b30 commit 311c327

File tree

35 files changed

+189
-30
lines changed

35 files changed

+189
-30
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
@@ -289,6 +289,10 @@ dependencies = [
289289
"generic-array",
290290
]
291291

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ members = [
88
"src/rustc-std-workspace/rustc-std-workspace-alloc",
99
"src/rustc-std-workspace/rustc-std-workspace-std",
1010
"src/rustdoc-json-types",
11+
"src/tools/bsan",
12+
"src/tools/build_helper",
1113
"src/tools/cargotest",
1214
"src/tools/clippy",
1315
"src/tools/clippy/clippy_dev",

compiler/rustc_borrowck/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,12 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
664664
state,
665665
);
666666
}
667+
StatementKind::Retag { .. } => {
668+
if !self.infcx.tcx.sess.emit_retags() {
669+
bug!("Statement not allowed in this MIR phase")
670+
}
671+
}
667672
StatementKind::Nop
668-
| StatementKind::Retag { .. }
669673
| StatementKind::Deinit(..)
670674
| StatementKind::SetDiscriminant { .. } => {
671675
bug!("Statement not allowed in this MIR phase")
@@ -1779,11 +1783,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
17791783
mpi,
17801784
);
17811785
} // Only query longest prefix with a MovePath, not further
1782-
// ancestors; dataflow recurs on children when parents
1783-
// move (to support partial (re)inits).
1784-
//
1785-
// (I.e., querying parents breaks scenario 7; but may want
1786-
// to do such a query based on partial-init feature-gate.)
1786+
// ancestors; dataflow recurs on children when parents
1787+
// move (to support partial (re)inits).
1788+
//
1789+
// (I.e., querying parents breaks scenario 7; but may want
1790+
// to do such a query based on partial-init feature-gate.)
17871791
}
17881792

17891793
/// 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
@@ -1245,10 +1245,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12451245
"Unexpected NonDivergingIntrinsic::CopyNonOverlapping, should only appear after lowering_intrinsics",
12461246
),
12471247
},
1248+
StatementKind::Retag { .. } => {
1249+
if !self.infcx.tcx.sess.emit_retags() {
1250+
bug!("Statement not allowed in this MIR phase")
1251+
}
1252+
},
12481253
StatementKind::FakeRead(..)
12491254
| StatementKind::StorageLive(..)
12501255
| StatementKind::StorageDead(..)
1251-
| StatementKind::Retag { .. }
12521256
| StatementKind::Coverage(..)
12531257
| StatementKind::ConstEvalCounter
12541258
| 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)