@@ -431,6 +431,9 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
431
431
NeedPIE |= CfiCrossDso;
432
432
}
433
433
434
+ Stats = Args.hasFlag (options::OPT_fsanitize_stats,
435
+ options::OPT_fno_sanitize_stats, false );
436
+
434
437
// Parse -f(no-)?sanitize-coverage flags if coverage is supported by the
435
438
// enabled sanitizers.
436
439
if (AllAddedKinds & SupportsCoverage) {
@@ -548,6 +551,20 @@ static std::string toString(const clang::SanitizerSet &Sanitizers) {
548
551
return Res;
549
552
}
550
553
554
+ static void addIncludeLinkerOption (const ToolChain &TC,
555
+ const llvm::opt::ArgList &Args,
556
+ llvm::opt::ArgStringList &CmdArgs,
557
+ StringRef SymbolName) {
558
+ SmallString<64 > LinkerOptionFlag;
559
+ LinkerOptionFlag = " --linker-option=/include:" ;
560
+ if (TC.getTriple ().getArch () == llvm::Triple::x86) {
561
+ // Win32 mangles C function names with a '_' prefix.
562
+ LinkerOptionFlag += ' _' ;
563
+ }
564
+ LinkerOptionFlag += SymbolName;
565
+ CmdArgs.push_back (Args.MakeArgString (LinkerOptionFlag));
566
+ }
567
+
551
568
void SanitizerArgs::addArgs (const ToolChain &TC, const llvm::opt::ArgList &Args,
552
569
llvm::opt::ArgStringList &CmdArgs,
553
570
types::ID InputType) const {
@@ -584,6 +601,9 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
584
601
if (CfiCrossDso)
585
602
CmdArgs.push_back (Args.MakeArgString (" -fsanitize-cfi-cross-dso" ));
586
603
604
+ if (Stats)
605
+ CmdArgs.push_back (Args.MakeArgString (" -fsanitize-stats" ));
606
+
587
607
if (AsanFieldPadding)
588
608
CmdArgs.push_back (Args.MakeArgString (" -fsanitize-address-field-padding=" +
589
609
llvm::utostr (AsanFieldPadding)));
@@ -619,6 +639,18 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
619
639
CmdArgs.push_back (Args.MakeArgString (
620
640
" --dependent-lib=" + TC.getCompilerRT (Args, " ubsan_standalone_cxx" )));
621
641
}
642
+ if (TC.getTriple ().isOSWindows () && needsStatsRt ()) {
643
+ CmdArgs.push_back (Args.MakeArgString (" --dependent-lib=" +
644
+ TC.getCompilerRT (Args, " stats_client" )));
645
+
646
+ // The main executable must export the stats runtime.
647
+ // FIXME: Only exporting from the main executable (e.g. based on whether the
648
+ // translation unit defines main()) would save a little space, but having
649
+ // multiple copies of the runtime shouldn't hurt.
650
+ CmdArgs.push_back (Args.MakeArgString (" --dependent-lib=" +
651
+ TC.getCompilerRT (Args, " stats" )));
652
+ addIncludeLinkerOption (TC, Args, CmdArgs, " __sanitizer_stats_register" );
653
+ }
622
654
}
623
655
624
656
SanitizerMask parseArgValues (const Driver &D, const llvm::opt::Arg *A,
0 commit comments