Skip to content

Commit a09a00c

Browse files
committed
---
yaml --- r: 322487 b: refs/heads/tensorflow-next c: 2389006 h: refs/heads/master i: 322485: d3c0dd8 322483: 5de36fc 322479: 28d9aaf
1 parent 2e4300a commit a09a00c

File tree

6 files changed

+34
-44
lines changed

6 files changed

+34
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,4 @@ refs/heads/master-rebranch: 86e95c23aa0d37f24ec138b7853146c1cead2e40
14611461
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14621462
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14631463
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec
1464-
refs/heads/tensorflow-next: b3956bae7b4663ca5d2b78e682f75458954df543
1464+
refs/heads/tensorflow-next: 23890066e6e52767aa682942d3c65fa9abb39b22

branches/tensorflow-next/include/swift/Option/SanitizerOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ llvm::SanitizerCoverageOptions parseSanitizerCoverageArgValue(
4242
const llvm::Triple &Triple,
4343
DiagnosticEngine &Diag,
4444
OptionSet<SanitizerKind> sanitizers);
45+
46+
/// Returns the active sanitizers as a comma-separated list.
47+
std::string getSanitizerList(const OptionSet<SanitizerKind> &Set);
4548
}
4649
#endif // SWIFT_OPTIONS_SANITIZER_OPTIONS_H

branches/tensorflow-next/lib/Driver/UnixToolChains.cpp

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Driver/Driver.h"
2323
#include "swift/Driver/Job.h"
2424
#include "swift/Option/Options.h"
25+
#include "swift/Option/SanitizerOptions.h"
2526
#include "clang/Basic/Version.h"
2627
#include "clang/Driver/Util.h"
2728
#include "llvm/ADT/StringSwitch.h"
@@ -37,27 +38,6 @@ using namespace swift;
3738
using namespace swift::driver;
3839
using namespace llvm::opt;
3940

40-
static void addLinkSanitizerLibArgsForLinux(const ArgList &Args,
41-
ArgStringList &Arguments,
42-
StringRef Sanitizer,
43-
const ToolChain &TC) {
44-
TC.addLinkRuntimeLib(Args, Arguments, TC.sanitizerRuntimeLibName(Sanitizer));
45-
46-
// Code taken from
47-
// https://github.com/apple/swift-clang/blob/ab3cbe7/lib/Driver/Tools.cpp#L3264-L3276
48-
// There's no libpthread or librt on RTEMS.
49-
if (TC.getTriple().getOS() != llvm::Triple::RTEMS) {
50-
Arguments.push_back("-lpthread");
51-
Arguments.push_back("-lrt");
52-
}
53-
Arguments.push_back("-lm");
54-
55-
// There's no libdl on FreeBSD or RTEMS.
56-
if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
57-
TC.getTriple().getOS() != llvm::Triple::RTEMS)
58-
Arguments.push_back("-ldl");
59-
}
60-
6141
std::string
6242
toolchains::GenericUnix::sanitizerRuntimeLibName(StringRef Sanitizer,
6343
bool shared) const {
@@ -293,23 +273,11 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
293273
Arguments.push_back(
294274
context.Args.MakeArgString("--target=" + getTriple().str()));
295275

296-
if (getTriple().getOS() == llvm::Triple::Linux) {
297-
// Make sure we only add SanitizerLibs for executables
298-
if (job.getKind() == LinkKind::Executable) {
299-
if (context.OI.SelectedSanitizers & SanitizerKind::Address)
300-
addLinkSanitizerLibArgsForLinux(context.Args, Arguments, "asan", *this);
301-
302-
if (context.OI.SelectedSanitizers & SanitizerKind::Thread)
303-
addLinkSanitizerLibArgsForLinux(context.Args, Arguments, "tsan", *this);
304-
305-
if (context.OI.SelectedSanitizers & SanitizerKind::Undefined)
306-
addLinkSanitizerLibArgsForLinux(context.Args, Arguments, "ubsan", *this);
307-
308-
if (context.OI.SelectedSanitizers & SanitizerKind::Fuzzer)
309-
addLinkRuntimeLib(context.Args, Arguments,
310-
sanitizerRuntimeLibName("fuzzer"));
311-
312-
}
276+
// Delegate to Clang for sanitizers. It will figure out the correct linker
277+
// options.
278+
if (job.getKind() == LinkKind::Executable && context.OI.SelectedSanitizers) {
279+
Arguments.push_back(context.Args.MakeArgString(
280+
"-fsanitize=" + getSanitizerList(context.OI.SelectedSanitizers)));
313281
}
314282

315283
if (context.Args.hasArg(options::OPT_profile_generate)) {

branches/tensorflow-next/lib/Option/SanitizerOptions.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,13 @@ OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
188188

189189
return sanitizerSet;
190190
}
191+
192+
std::string swift::getSanitizerList(const OptionSet<SanitizerKind> &Set) {
193+
std::string list;
194+
if (Set & SanitizerKind::Address) list += "address,";
195+
if (Set & SanitizerKind::Thread) list += "thread,";
196+
if (Set & SanitizerKind::Fuzzer) list += "fuzzer,";
197+
if (Set & SanitizerKind::Undefined) list += "undefined,";
198+
if (!list.empty()) list.pop_back(); // Remove last comma
199+
return list;
200+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// UNSUPPORTED: windows
22
// UNSUPPORTED: CPU=powerpc64le
3-
// RUN: %swiftc_driver -driver-print-jobs -sanitize=fuzzer,address -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ %s | %FileCheck -check-prefix=LIBFUZZER %s
3+
// RUN: %swiftc_driver -driver-print-jobs -sanitize=fuzzer,address -target x86_64-apple-macosx10.9 -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ %s | %FileCheck -check-prefix=LIBFUZZER_OSX %s
4+
// RUN: %swiftc_driver -driver-print-jobs -sanitize=fuzzer,address -target x86_64-unknown-linux-gnu -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ %s | %FileCheck -check-prefix=LIBFUZZER_LINUX %s
5+
6+
// LIBFUZZER_OSX: libclang_rt.fuzzer
7+
// LIBFUZZER_LINUX: -fsanitize=address,fuzzer
48

5-
// LIBFUZZER: libclang_rt.fuzzer
69
@_cdecl("LLVMFuzzerTestOneInput") public func fuzzOneInput(Data: UnsafePointer<CChar>, Size: CLong) -> CInt {
710
return 0;
811
}

branches/tensorflow-next/test/Driver/sanitizers.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
// RUN: %swiftc_driver -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ -driver-print-jobs -sanitize=undefined -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=UBSAN_LINUX %s
4040
// RUN: %swiftc_driver -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ -driver-print-jobs -sanitize=undefined -target x86_64-unknown-windows-msvc %s 2>&1 | %FileCheck -check-prefix=UBSAN_WINDOWS %s
4141

42+
/*
43+
* Multiple Sanitizers At Once
44+
*/
45+
// RUN: %swiftc_driver -resource-dir %S/Inputs/fake-resource-dir/lib/swift/ -driver-print-jobs -sanitize=address,undefined,fuzzer -target x86_64-unknown-linux-gnu %s 2>&1 | %FileCheck -check-prefix=MULTIPLE_SAN_LINUX %s
4246

4347
/*
4448
* Bad Argument Tests
@@ -65,7 +69,7 @@
6569
// ASAN_tvOS: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}darwin{{/|\\\\}}libclang_rt.asan_tvos_dynamic.dylib
6670
// ASAN_watchOS_SIM: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}darwin{{/|\\\\}}libclang_rt.asan_watchossim_dynamic.dylib
6771
// ASAN_watchOS: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}darwin{{/|\\\\}}libclang_rt.asan_watchos_dynamic.dylib
68-
// ASAN_LINUX: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.asan-x86_64.a
72+
// ASAN_LINUX: -fsanitize=address
6973
// ASAN_WINDOWS: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}windows{{/|\\\\}}clang_rt.asan-x86_64.lib
7074

7175
// ASAN: -rpath @executable_path
@@ -82,7 +86,7 @@
8286
// TSAN_watchOS_SIM: unsupported option '-sanitize=thread' for target 'i386-apple-watchos2.0'
8387
// TSAN_watchOS: unsupported option '-sanitize=thread' for target 'armv7k-apple-watchos2.0'
8488
// FUZZER_NONEXISTENT: unsupported option '-sanitize=fuzzer' for target 'x86_64-apple-macosx10.9'
85-
// TSAN_LINUX: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.tsan-x86_64.a
89+
// TSAN_LINUX: -fsanitize=thread
8690
// TSAN_WINDOWS: unsupported option '-sanitize=thread' for target 'x86_64-unknown-windows-msvc'
8791

8892
// TSAN: -rpath @executable_path
@@ -97,10 +101,12 @@
97101
// UBSAN_tvOS: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}darwin{{/|\\\\}}libclang_rt.ubsan_tvos_dynamic.dylib
98102
// UBSAN_watchOS_SIM: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}darwin{{/|\\\\}}libclang_rt.ubsan_watchossim_dynamic.dylib
99103
// UBSAN_watchOS: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}darwin{{/|\\\\}}libclang_rt.ubsan_watchos_dynamic.dylib
100-
// UBSAN_LINUX: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.ubsan-x86_64.a
104+
// UBSAN_LINUX: -fsanitize=undefined
101105
// UBSAN_WINDOWS: lib{{/|\\\\}}swift{{/|\\\\}}clang{{/|\\\\}}lib{{/|\\\\}}windows{{/|\\\\}}clang_rt.ubsan-x86_64.lib
102106

103107
// UBSAN: -rpath @executable_path
104108

109+
// MULTIPLE_SAN_LINUX: -fsanitize=address,fuzzer,undefined
110+
105111
// BADARG: unsupported argument 'unknown' to option '-sanitize='
106112
// INCOMPATIBLESANITIZERS: argument '-sanitize=address' is not allowed with '-sanitize=thread'

0 commit comments

Comments
 (0)