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;
3738using namespace swift ::driver;
3839using 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-
6141std::string
6242toolchains::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)) {
0 commit comments