[PATCH] add supporting of the sanitizer arguments into Clang on FreeBSD platform.
Viktor Kutuzov
vkutuzov at accesssoftek.com
Mon Mar 17 03:51:59 PDT 2014
Updated.
Alexey, please let me know if you would prefer explicit "freebsd" instead of calling Triple::getOSTypeName(). Thanks.
Hi kcc, samsonov,
http://llvm-reviews.chandlerc.com/D2644
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2644?vs=7644&id=7873#toc
Files:
lib/Driver/Tools.cpp
test/Driver/sanitizer-ld.c
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1775,7 +1775,10 @@
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();
+ StringRef OSLibName = Triple.getOS() == llvm::Triple::FreeBSD ?
+ Triple.getOSTypeName(Triple.getOS()) : TC.getOS();
+ llvm::sys::path::append(Res, "lib", OSLibName);
return Res;
}
@@ -1836,9 +1839,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.
@@ -6236,6 +6242,8 @@
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
}
+ addSanitizerRuntimes(getToolChain(), Args, CmdArgs);
+
addProfileRT(ToolChain, Args, CmdArgs);
const char *Exec =
Index: test/Driver/sanitizer-ld.c
===================================================================
--- test/Driver/sanitizer-ld.c
+++ test/Driver/sanitizer-ld.c
@@ -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 \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2644.9.patch
Type: text/x-patch
Size: 2853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140317/87cb44b4/attachment.bin>
More information about the cfe-commits
mailing list