@@ -324,6 +324,22 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
324
324
}
325
325
}
326
326
327
+ void DarwinClang::AddLinkSanitizerLibArgs (const ArgList &Args,
328
+ ArgStringList &CmdArgs,
329
+ StringRef Sanitizer) const {
330
+ if (!Args.hasArg (options::OPT_dynamiclib) &&
331
+ !Args.hasArg (options::OPT_bundle)) {
332
+ // Sanitizer runtime libraries requires C++.
333
+ AddCXXStdlibLibArgs (Args, CmdArgs);
334
+ }
335
+ assert (isTargetMacOS () || isTargetIOSSimulator ());
336
+ StringRef OS = isTargetMacOS () ? " osx" : " iossim" ;
337
+ AddLinkRuntimeLib (Args, CmdArgs, (Twine (" libclang_rt." ) + Sanitizer + " _" +
338
+ OS + " _dynamic.dylib" ).str (),
339
+ /* AlwaysLink*/ true , /* IsEmbedded*/ false ,
340
+ /* AddRPath*/ true );
341
+ }
342
+
327
343
void DarwinClang::AddLinkRuntimeLibArgs (const ArgList &Args,
328
344
ArgStringList &CmdArgs) const {
329
345
// Darwin only supports the compiler-rt based runtime libraries.
@@ -368,47 +384,26 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
368
384
369
385
const SanitizerArgs &Sanitize = getSanitizerArgs ();
370
386
371
- // Add Ubsan runtime library, if required.
372
- if (Sanitize.needsUbsanRt ()) {
373
- // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
374
- if (isTargetIOSBased ()) {
387
+ if (Sanitize.needsAsanRt ()) {
388
+ if (!isTargetMacOS () && !isTargetIOSSimulator ()) {
389
+ // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
375
390
getDriver ().Diag (diag::err_drv_clang_unsupported_per_platform)
376
- << " -fsanitize=undefined " ;
391
+ << " -fsanitize=address " ;
377
392
} else {
378
- assert (isTargetMacOS () && " unexpected non OS X target" );
379
- AddLinkRuntimeLib (Args, CmdArgs, " libclang_rt.ubsan_osx.a" , true );
380
-
381
- // The Ubsan runtime library requires C++.
382
- AddCXXStdlibLibArgs (Args, CmdArgs);
393
+ AddLinkSanitizerLibArgs (Args, CmdArgs, " asan" );
383
394
}
384
395
}
385
396
386
- // Add ASAN runtime library, if required. Dynamic libraries and bundles
387
- // should not be linked with the runtime library.
388
- if (Sanitize.needsAsanRt ()) {
389
- // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
390
- if (isTargetIPhoneOS ()) {
397
+ if (Sanitize.needsUbsanRt ()) {
398
+ if (!isTargetMacOS () && !isTargetIOSSimulator ()) {
399
+ // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds.
391
400
getDriver ().Diag (diag::err_drv_clang_unsupported_per_platform)
392
- << " -fsanitize=address " ;
401
+ << " -fsanitize=undefined " ;
393
402
} else {
394
- if (!Args.hasArg (options::OPT_dynamiclib) &&
395
- !Args.hasArg (options::OPT_bundle)) {
396
- // The ASAN runtime library requires C++.
397
- AddCXXStdlibLibArgs (Args, CmdArgs);
398
- }
399
- if (isTargetMacOS ()) {
400
- AddLinkRuntimeLib (Args, CmdArgs,
401
- " libclang_rt.asan_osx_dynamic.dylib" ,
402
- /* AlwaysLink*/ true , /* IsEmbedded*/ false ,
403
- /* AddRPath*/ true );
404
- } else {
405
- if (isTargetIOSSimulator ()) {
406
- AddLinkRuntimeLib (Args, CmdArgs,
407
- " libclang_rt.asan_iossim_dynamic.dylib" ,
408
- /* AlwaysLink*/ true , /* IsEmbedded*/ false ,
409
- /* AddRPath*/ true );
410
- }
411
- }
403
+ AddLinkSanitizerLibArgs (Args, CmdArgs, " ubsan" );
404
+ // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export
405
+ // all RTTI-related symbols that UBSan uses.
406
+ CmdArgs.push_back (" -lc++abi" );
412
407
}
413
408
}
414
409
0 commit comments