@@ -56,7 +56,9 @@ class ArgsBuilder {
56
56
57
57
private:
58
58
virtual void addSanitizers (const llvm::Triple &triple);
59
- virtual void addASanLinkFlags (const llvm::Triple &triple);
59
+ virtual void addSanitizerLinkFlags (const llvm::Triple &triple,
60
+ const llvm::StringRef sanitizerName,
61
+ const llvm::StringRef fallbackFlag);
60
62
virtual void addFuzzLinkFlags (const llvm::Triple &triple);
61
63
virtual void addCppStdlibLinkFlags (const llvm::Triple &triple);
62
64
virtual void addProfileRuntimeLinkFlags (const llvm::Triple &triple);
@@ -279,27 +281,29 @@ getFullCompilerRTLibPathCandidates(llvm::StringRef baseName,
279
281
return r;
280
282
}
281
283
282
- void ArgsBuilder::addASanLinkFlags (const llvm::Triple &triple) {
283
- // Examples: "libclang_rt.asan-x86_64.a" or "libclang_rt.asan-arm.a" and
284
- // "libclang_rt.asan-x86_64.so"
284
+ void ArgsBuilder::addSanitizerLinkFlags (const llvm::Triple &triple,
285
+ const llvm::StringRef sanitizerName,
286
+ const llvm::StringRef fallbackFlag) {
287
+ // Examples: "libclang_rt.tsan-x86_64.a" or "libclang_rt.tsan-arm.a" and
288
+ // "libclang_rt.tsan-x86_64.so"
285
289
286
290
// TODO: let user choose to link with shared lib.
287
291
// In case of shared ASan, I think we also need to statically link with
288
292
// libclang_rt.asan-preinit-<arch>.a on Linux. On Darwin, the only option is
289
293
// to use the shared library.
290
- bool linkSharedASan = triple.isOSDarwin ();
294
+ bool linkSharedLibrary = triple.isOSDarwin ();
291
295
const auto searchPaths =
292
- getFullCompilerRTLibPathCandidates (" asan " , triple, linkSharedASan );
296
+ getFullCompilerRTLibPathCandidates (sanitizerName , triple, linkSharedLibrary );
293
297
294
298
for (const auto &filepath : searchPaths) {
295
- IF_LOG Logger::println (" Searching ASan lib: %s" , filepath.c_str ());
299
+ IF_LOG Logger::println (" Searching sanitizer lib: %s" , filepath.c_str ());
296
300
297
301
if (llvm::sys::fs::exists (filepath) &&
298
302
!llvm::sys::fs::is_directory (filepath)) {
299
303
IF_LOG Logger::println (" Found, linking with %s" , filepath.c_str ());
300
304
args.push_back (filepath);
301
305
302
- if (linkSharedASan ) {
306
+ if (linkSharedLibrary ) {
303
307
// Add @executable_path to rpath to support having the shared lib copied
304
308
// with the executable.
305
309
args.push_back (" -rpath" );
@@ -315,11 +319,9 @@ void ArgsBuilder::addASanLinkFlags(const llvm::Triple &triple) {
315
319
}
316
320
}
317
321
318
- // When we reach here, we did not find the ASan library.
319
- // Fallback, requires Clang. The asan library contains a versioned symbol
320
- // name and a linker error will happen when the LDC-LLVM and Clang-LLVM
321
- // versions don't match.
322
- args.push_back (" -fsanitize=address" );
322
+ // When we reach here, we did not find the sanitizer library.
323
+ // Fallback, requires Clang.
324
+ args.push_back (fallbackFlag);
323
325
}
324
326
325
327
// Adds all required link flags for -fsanitize=fuzzer when libFuzzer library is
@@ -446,7 +448,7 @@ void ArgsBuilder::addProfileRuntimeLinkFlags(const llvm::Triple &triple) {
446
448
447
449
void ArgsBuilder::addSanitizers (const llvm::Triple &triple) {
448
450
if (opts::isSanitizerEnabled (opts::AddressSanitizer)) {
449
- addASanLinkFlags (triple);
451
+ addSanitizerLinkFlags (triple, " asan " , " -fsanitize=address " );
450
452
}
451
453
452
454
if (opts::isSanitizerEnabled (opts::FuzzSanitizer)) {
@@ -459,10 +461,8 @@ void ArgsBuilder::addSanitizers(const llvm::Triple &triple) {
459
461
args.push_back (" -fsanitize=memory" );
460
462
}
461
463
462
- // TODO: instead of this, we should link with our own sanitizer libraries
463
- // because LDC's LLVM version could be different from the system clang.
464
464
if (opts::isSanitizerEnabled (opts::ThreadSanitizer)) {
465
- args. push_back ( " -fsanitize=thread" );
465
+ addSanitizerLinkFlags (triple, " tsan " , " -fsanitize=thread" );
466
466
}
467
467
}
468
468
0 commit comments