[PATCH] add supporting of the sanitizer arguments into Clang on FreeBSD platform.
Viktor Kutuzov
vkutuzov at accesssoftek.com
Fri Mar 7 09:53:22 PST 2014
Fixed as suggested and supplied with tests.
Hi kcc, samsonov,
http://llvm-reviews.chandlerc.com/D2644
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2644?vs=7639&id=7644#toc
Files:
test/Driver/sanitizer-ld.c
lib/Driver/Tools.cpp
Index: test/Driver/sanitizer-ld.c
===================================================================
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -15,6 +15,21 @@
// 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-NOT: "-ldl"
+// CHECK-ASAN-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: %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 \
@@ -31,6 +46,22 @@
// CHECK-ASAN-LINUX-CXX-NOT: "--dynamic-list"
// CHECK-ASAN-LINUX-CXX: stdc++
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-freebsd -fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_freebsd_tree \
+// RUN: | FileCheck --check-prefix=CHECK-ASAN-FREEBSD-CXX %s
+//
+// CHECK-ASAN-FREEBSD-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-FREEBSD-CXX-NOT: "-lc"
+// CHECK-ASAN-FREEBSD-CXX: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
+// CHECK-ASAN-FREEBSD-CXX: stdc++
+// CHECK-ASAN-FREEBSD-CXX: "-lpthread"
+// CHECK-ASAN-FREEBSD-CXX: "-lrt"
+// CHECK-ASAN-FREEBSD-CXX-NOT: "-ldl"
+// CHECK-ASAN-FREEBSD-CXX: "-export-dynamic"
+// CHECK-ASAN-FREEBSD-CXX-NOT: "--dynamic-list"
+
// RUN: %clang -no-canonical-prefixes %s -### -o /dev/null -fsanitize=address \
// RUN: -target i386-unknown-linux --sysroot=%S/Inputs/basic_linux_tree \
// RUN: -lstdc++ -static 2>&1 \
@@ -41,6 +72,16 @@
// CHECK-ASAN-LINUX-CXX-STATIC: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
// CHECK-ASAN-LINUX-CXX-STATIC: stdc++
+// RUN: %clang -no-canonical-prefixes %s -### -o /dev/null -fsanitize=address \
+// RUN: -target i386-unknown-freebsd --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -lstdc++ -static 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-ASAN-FREEBSD-CXX-STATIC %s
+//
+// CHECK-ASAN-FREEBSD-CXX-STATIC: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-FREEBSD-CXX-STATIC-NOT: stdc++
+// CHECK-ASAN-FREEBSD-CXX-STATIC: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"
+// CHECK-ASAN-FREEBSD-CXX-STATIC: stdc++
+
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
// RUN: -target arm-linux-gnueabi -fsanitize=address \
// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1772,7 +1772,11 @@
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();
+ llvm::sys::path::append(Res, "lib",
+ Triple.getOS() == llvm::Triple::FreeBSD ?
+ Triple.getOSTypeName(Triple.getOS()) :
+ TC.getOS());
return Res;
}
@@ -1833,9 +1837,12 @@
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
// all symbols from the binary.
@@ -6230,6 +6237,8 @@
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
}
+ addSanitizerRuntimes(getToolChain(), Args, CmdArgs);
+
addProfileRT(ToolChain, Args, CmdArgs);
const char *Exec =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2644.8.patch
Type: text/x-patch
Size: 4460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140307/2d20cea4/attachment.bin>
More information about the cfe-commits
mailing list