Skip to content

Handle scudo rename and changes for rebranch #68063

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

Merged
merged 3 commits into from
Aug 24, 2023
Merged
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
2 changes: 1 addition & 1 deletion include/swift/Basic/Sanitizers.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ SANITIZER(0, Address, address, asan)
SANITIZER(1, Thread, thread, tsan)
SANITIZER(2, Undefined, undefined, ubsan)
SANITIZER(3, Fuzzer, fuzzer, fuzzer)
SANITIZER(4, Scudo, scudo, scudo)
SANITIZER(4, Scudo, scudo, scudo_standalone)

#undef SANITIZER
45 changes: 18 additions & 27 deletions lib/Option/SanitizerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,27 @@ OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
+ toStringRef(SanitizerKind::Thread)).toStringRef(b2));
}

// Scudo can only be run with ubsan.
if (sanitizerSet & SanitizerKind::Scudo) {
OptionSet<SanitizerKind> allowedSet;
allowedSet |= SanitizerKind::Scudo;
allowedSet |= SanitizerKind::Undefined;

auto forbiddenOptions = sanitizerSet - allowedSet;

if (forbiddenOptions) {
SanitizerKind forbidden;

if (forbiddenOptions & SanitizerKind::Address) {
forbidden = SanitizerKind::Address;
} else if (forbiddenOptions & SanitizerKind::Thread) {
forbidden = SanitizerKind::Thread;
} else {
assert(forbiddenOptions & SanitizerKind::Fuzzer);
forbidden = SanitizerKind::Fuzzer;
// Scudo must be run standalone
if (sanitizerSet.contains(SanitizerKind::Scudo) &&
!sanitizerSet.containsOnly(SanitizerKind::Scudo)) {
auto diagnoseSanitizerKind = [&Diags, A, &sanitizerSet](SanitizerKind kind) {
// Don't diagnose Scudo, but diagnose anything else
if (kind != SanitizerKind::Scudo && sanitizerSet.contains(kind)) {
SmallString<128> b1;
SmallString<128> b2;
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
(A->getOption().getPrefixedName()
+ toStringRef(SanitizerKind::Scudo)).toStringRef(b1),
(A->getOption().getPrefixedName()
+ toStringRef(kind)).toStringRef(b2));
}
};

SmallString<128> b1;
SmallString<128> b2;
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
(A->getOption().getPrefixedName()
+ toStringRef(SanitizerKind::Scudo)).toStringRef(b1),
(A->getOption().getPrefixedName()
+ toStringRef(forbidden)).toStringRef(b2));
}
}
#define SANITIZER(enm, kind, name, file) \
diagnoseSanitizerKind(SanitizerKind::kind);
#include "swift/Basic/Sanitizers.def"

}
return sanitizerSet;
}

Expand Down
5 changes: 2 additions & 3 deletions test/Driver/sanitize_scudo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// RUN: not %swiftc_driver -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ -driver-print-jobs -sanitize=scudo,address -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=SCUDO_ASAN %s
// RUN: not %swiftc_driver -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ -driver-print-jobs -sanitize=scudo,thread -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=SCUDO_TSAN %s
// RUN: %swiftc_driver -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ -driver-print-jobs -sanitize=scudo,undefined -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=SCUDO_UBSAN_LINUX %s
// RUN: not %swiftc_driver -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ -driver-print-jobs -sanitize=scudo,undefined -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=SCUDO_UBSAN %s


/*
Expand All @@ -34,7 +34,6 @@

// SCUDO_ASAN: argument '-sanitize=scudo' is not allowed with '-sanitize=address'
// SCUDO_TSAN: argument '-sanitize=scudo' is not allowed with '-sanitize=thread'
// SCUDO_UBSAN_LINUX: -fsanitize=undefined,scudo
// SCUDO_UBSAN: argument '-sanitize=scudo' is not allowed with '-sanitize=undefined'
// SCUDO_LIBRARY_LINUX: bin{{/|\\\\}}clang
// SCUDO_LIBRARY_LINUX-NOT: -fsanitize=scudo

2 changes: 1 addition & 1 deletion test/Sanitizers/scudo.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swiftc_driver %s -g -sanitize=scudo -o %t_scudo-binary
// RUN: not %target-run %t_scudo-binary 2>&1 | %FileCheck %s
// RUN: not --crash %target-run %t_scudo-binary 2>&1 | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: OS=linux-gnu
// REQUIRES: scudo_runtime
Expand Down