Skip to content

Commit 23de452

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 e3666f8 commit 23de452

File tree

33 files changed

+180
-28
lines changed

33 files changed

+180
-28
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
@@ -50,4 +50,4 @@
5050
[submodule "src/gcc"]
5151
path = src/gcc
5252
url = https://github.com/rust-lang/gcc.git
53-
shallow = true
53+
shallow = true

Cargo.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ dependencies = [
334334
"generic-array",
335335
]
336336

337+
[[package]]
338+
name = "bsan"
339+
version = "0.1.0"
340+
337341
[[package]]
338342
name = "bstr"
339343
version = "1.12.0"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"src/rustdoc-json-types",
1212
"src/tools/build-manifest",
1313
"src/tools/bump-stage0",
14+
"src/tools/bsan",
1415
"src/tools/cargotest",
1516
"src/tools/clippy",
1617
"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
@@ -772,8 +772,12 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a,
772772
state,
773773
);
774774
}
775+
StatementKind::Retag { .. } => {
776+
if !self.infcx.tcx.sess.emit_retags() {
777+
bug!("Statement not allowed in this MIR phase")
778+
}
779+
}
775780
StatementKind::Nop
776-
| StatementKind::Retag { .. }
777781
| StatementKind::Deinit(..)
778782
| StatementKind::SetDiscriminant { .. } => {
779783
bug!("Statement not allowed in this MIR phase")
@@ -1973,11 +1977,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19731977
mpi,
19741978
);
19751979
} // Only query longest prefix with a MovePath, not further
1976-
// ancestors; dataflow recurs on children when parents
1977-
// move (to support partial (re)inits).
1978-
//
1979-
// (I.e., querying parents breaks scenario 7; but may want
1980-
// to do such a query based on partial-init feature-gate.)
1980+
// ancestors; dataflow recurs on children when parents
1981+
// move (to support partial (re)inits).
1982+
//
1983+
// (I.e., querying parents breaks scenario 7; but may want
1984+
// to do such a query based on partial-init feature-gate.)
19811985
}
19821986

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

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ pub(crate) fn sanitize_attrs<'ll>(
131131
if enabled.contains(SanitizerSet::SAFESTACK) {
132132
attrs.push(llvm::AttributeKind::SanitizeSafeStack.create_attr(cx.llcx));
133133
}
134+
if enabled.contains(SanitizerSet::BORROW) {
135+
attrs.push(llvm::AttributeKind::SanitizeBorrow.create_attr(cx.llcx));
136+
}
134137
attrs
135138
}
136139

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ pub(crate) unsafe fn llvm_optimize(
644644
sanitize_kernel_address_recover: config
645645
.sanitizer_recover
646646
.contains(SanitizerSet::KERNELADDRESS),
647+
sanitize_borrow: config.sanitizer.contains(SanitizerSet::BORROW),
647648
})
648649
} else {
649650
None

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ pub(crate) enum AttributeKind {
238238
FnRetThunkExtern = 41,
239239
Writable = 42,
240240
DeadOnUnwind = 43,
241+
SanitizeBorrow = 44,
241242
}
242243

243244
/// LLVMIntPredicate
@@ -529,6 +530,7 @@ pub(crate) struct SanitizerOptions {
529530
pub sanitize_hwaddress_recover: bool,
530531
pub sanitize_kernel_address: bool,
531532
pub sanitize_kernel_address_recover: bool,
533+
pub sanitize_borrow: bool,
532534
}
533535

534536
/// LLVMRustRelocModel

compiler/rustc_codegen_llvm/src/retag.rs

Whitespace-only changes.

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,9 @@ fn add_sanitizer_libraries(
12251225
if sanitizer.contains(SanitizerSet::ADDRESS) {
12261226
link_sanitizer_runtime(sess, flavor, linker, "asan");
12271227
}
1228+
if sanitizer.contains(SanitizerSet::BORROW) {
1229+
link_sanitizer_runtime(sess, flavor, linker, "bsan");
1230+
}
12281231
if sanitizer.contains(SanitizerSet::DATAFLOW) {
12291232
link_sanitizer_runtime(sess, flavor, linker, "dfsan");
12301233
}

0 commit comments

Comments
 (0)