r204129 - Add support for sanitizers arguments on FreeBSD
Viktor Kutuzov
vkutuzov at accesssoftek.com
Tue Mar 18 02:36:51 PDT 2014
Author: vkutuzov
Date: Tue Mar 18 04:36:50 2014
New Revision: 204129
URL: http://llvm.org/viewvc/llvm-project?rev=204129&view=rev
Log:
Add support for sanitizers arguments on FreeBSD
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/sanitizer-ld.c
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=204129&r1=204128&r2=204129&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Mar 18 04:36:50 2014
@@ -1775,7 +1775,11 @@ static StringRef getArchNameForCompilerR
static SmallString<128> getCompilerRTLibDir(const ToolChain &TC) {
// The runtimes are located in the OS-specific resource directory.
SmallString<128> Res(TC.getDriver().ResourceDir);
- llvm::sys::path::append(Res, "lib", TC.getOS());
+ const llvm::Triple &Triple = TC.getTriple();
+ // TC.getOS() yield "freebsd10.0" whereas "freebsd" is expected.
+ StringRef OSLibName = (Triple.getOS() == llvm::Triple::FreeBSD) ?
+ "freebsd" : TC.getOS();
+ llvm::sys::path::append(Res, "lib", OSLibName);
return Res;
}
@@ -1836,8 +1840,10 @@ static void addSanitizerRTLinkFlags(
CmdArgs.push_back("-lpthread");
CmdArgs.push_back("-lrt");
- CmdArgs.push_back("-ldl");
CmdArgs.push_back("-lm");
+ // There's no libdl on FreeBSD.
+ if (TC.getTriple().getOS() != llvm::Triple::FreeBSD)
+ CmdArgs.push_back("-ldl");
// If possible, use a dynamic symbols file to export the symbols from the
// runtime library. If we can't do so, use -export-dynamic instead to export
@@ -6236,6 +6242,8 @@ void freebsd::Link::ConstructJob(Compila
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
}
+ addSanitizerRuntimes(getToolChain(), Args, CmdArgs);
+
addProfileRT(ToolChain, Args, CmdArgs);
const char *Exec =
Modified: cfe/trunk/test/Driver/sanitizer-ld.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=204129&r1=204128&r2=204129&view=diff
==============================================================================
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)
+++ cfe/trunk/test/Driver/sanitizer-ld.c Tue Mar 18 04:36:50 2014
@@ -15,6 +15,29 @@
// CHECK-ASAN-LINUX-NOT: "-export-dynamic"
// CHECK-ASAN-LINUX: "--dynamic-list={{.*}}libclang_rt.asan-i386.a.syms"
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-freebsd -fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_freebsd_tree \
+// RUN: | FileCheck --check-prefix=CHECK-ASAN-FREEBSD %s
+//
+// CHECK-ASAN-FREEBSD: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-FREEBSD-NOT: "-lc"
+// CHECK-ASAN-FREEBSD: freebsd/libclang_rt.asan-i386.a"
+// CHECK-ASAN-FREEBSD: "-lpthread"
+// CHECK-ASAN-FREEBSD: "-lrt"
+// CHECK-ASAN-FREEBSD: "-export-dynamic"
+// CHECK-ASAN-FREEBSD-NOT: "--dynamic-list"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-freebsd -fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_freebsd_tree \
+// RUN: | FileCheck --check-prefix=CHECK-ASAN-FREEBSD-LDL %s
+//
+// CHECK-ASAN-FREEBSD-LDL: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-FREEBSD-LDL-NOT: "-ldl"
+
// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
// RUN: -target i386-unknown-linux -fsanitize=address \
// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
More information about the cfe-commits
mailing list