From 1d6469fcb103acef30206ed3ad48c64bea5c84b3 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 1 Dec 2011 23:40:18 +0000 Subject: [PATCH] Driver/Darwin: Add ASAN runtime library link support. llvm-svn: 145651 --- clang/lib/Driver/ToolChains.cpp | 16 ++++++++++++++++ clang/runtime/compiler-rt/Makefile | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 5ebe2828547d..245b3e83084d 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -467,6 +467,22 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, } } + // Add ASAN runtime library, if required. + if (Args.hasFlag(options::OPT_faddress_sanitizer, + options::OPT_fno_address_sanitizer, false)) { + if (isTargetIPhoneOS()) { + getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) + << "-faddress-sanitizer"; + } else { + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.asan_osx.a"); + + // The ASAN runtime library requires C++ and CoreFoundation. + AddCXXStdlibLibArgs(Args, CmdArgs); + CmdArgs.push_back("-framework"); + CmdArgs.push_back("CoreFoundation"); + } + } + // Otherwise link libSystem, then the dynamic runtime library, and finally any // target specific static runtime library. CmdArgs.push_back("-lSystem"); diff --git a/clang/runtime/compiler-rt/Makefile b/clang/runtime/compiler-rt/Makefile index bba8fb304810..a8cd2e981d64 100644 --- a/clang/runtime/compiler-rt/Makefile +++ b/clang/runtime/compiler-rt/Makefile @@ -78,7 +78,7 @@ ifeq ($(OS),Darwin) RuntimeDirs += darwin RuntimeLibrary.darwin.Configs := \ eprintf 10.4 osx ios cc_kext \ - profile_osx profile_ios + asan_osx profile_osx profile_ios # On Darwin, fake Clang into using the iOS assembler (since compiler-rt wants to # build ARM bits).