Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3278,6 +3278,7 @@ SmallVectorImpl &HelperStaticRuntimes, SmallVectorImpl &RequiredSymbols) { const SanitizerArgs &SanArgs = TC.getSanitizerArgs(); + bool NeedSanCommon = false; // Collect shared runtimes. if (SanArgs.needsAsanRt() && SanArgs.needsSharedAsanRt()) { SharedRuntimes.push_back("asan"); @@ -3296,44 +3297,60 @@ HelperStaticRuntimes.push_back("asan-preinit"); } else { StaticRuntimes.push_back("asan"); + NeedSanCommon = true; if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("asan_cxx"); } } - if (SanArgs.needsDfsanRt()) + if (SanArgs.needsDfsanRt()) { StaticRuntimes.push_back("dfsan"); - if (SanArgs.needsLsanRt()) + NeedSanCommon = true; + } + if (SanArgs.needsLsanRt()) { StaticRuntimes.push_back("lsan"); + NeedSanCommon = true; + } if (SanArgs.needsMsanRt()) { StaticRuntimes.push_back("msan"); + NeedSanCommon = true; if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("msan_cxx"); } if (SanArgs.needsTsanRt()) { StaticRuntimes.push_back("tsan"); + NeedSanCommon = true; if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("tsan_cxx"); } if (SanArgs.needsUbsanRt()) { StaticRuntimes.push_back("ubsan_standalone"); + NeedSanCommon = true; if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("ubsan_standalone_cxx"); } if (SanArgs.needsSafeStackRt()) StaticRuntimes.push_back("safestack"); - if (SanArgs.needsCfiRt()) + if (SanArgs.needsCfiRt()) { StaticRuntimes.push_back("cfi"); + NeedSanCommon = true; + } if (SanArgs.needsCfiDiagRt()) { StaticRuntimes.push_back("cfi_diag"); + NeedSanCommon = true; if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("ubsan_standalone_cxx"); } if (SanArgs.needsStatsRt()) { NonWholeStaticRuntimes.push_back("stats"); + NeedSanCommon = true; RequiredSymbols.push_back("__sanitizer_stats_register"); } - if (SanArgs.needsEsanRt()) + if (SanArgs.needsEsanRt()) { StaticRuntimes.push_back("esan"); + NeedSanCommon = true; + } + if (NeedSanCommon) + StaticRuntimes.push_back("san_common"); } // Should be called before we add system libraries (C++ ABI, libstdc++/libc++, @@ -3380,6 +3397,7 @@ options::OPT_fnoxray_instrument, false)) { CmdArgs.push_back("-whole-archive"); CmdArgs.push_back(TC.getCompilerRTArgString(Args, "xray", false)); + CmdArgs.push_back(TC.getCompilerRTArgString(Args, "san_common", false)); CmdArgs.push_back("-no-whole-archive"); return true; } @@ -10904,7 +10922,7 @@ } else if (DLL) { CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dll_thunk")); } else { - for (const auto &Lib : {"asan", "asan_cxx"}) + for (const auto &Lib : {"asan", "asan_cxx", "san_common"}) CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib)); } }