[cfe-commits] r168428 - in /cfe/trunk: lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h test/Driver/darwin-sanitizer-ld.c
David Blaikie
dblaikie at gmail.com
Fri Nov 23 10:24:28 PST 2012
On Wed, Nov 21, 2012 at 6:17 AM, Alexey Samsonov <samsonov at google.com> wrote:
> Author: samsonov
> Date: Wed Nov 21 08:17:42 2012
> New Revision: 168428
>
> URL: http://llvm.org/viewvc/llvm-project?rev=168428&view=rev
> Log:
> [Sanitizer] force linking with static sanitizer runtimes on Darwin even if they are not found in resource directory. Add test checking sanitizer linker flags on Darwin.
>
> Added:
> cfe/trunk/test/Driver/darwin-sanitizer-ld.c
> Modified:
> cfe/trunk/lib/Driver/ToolChains.cpp
> cfe/trunk/lib/Driver/ToolChains.h
>
> Modified: cfe/trunk/lib/Driver/ToolChains.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=168428&r1=168427&r2=168428&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChains.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Nov 21 08:17:42 2012
> @@ -261,16 +261,18 @@
>
> void DarwinClang::AddLinkRuntimeLib(const ArgList &Args,
> ArgStringList &CmdArgs,
> - const char *DarwinStaticLib) const {
> + const char *DarwinStaticLib,
> + bool AlwaysLink) const {
> llvm::sys::Path P(getDriver().ResourceDir);
> P.appendComponent("lib");
> P.appendComponent("darwin");
> P.appendComponent(DarwinStaticLib);
>
> // For now, allow missing resource libraries to support developers who may
> - // not have compiler-rt checked out or integrated into their build.
> + // not have compiler-rt checked out or integrated into their build (unless
> + // we explicitly force linking with this library).
> bool Exists;
> - if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
> + if (AlwaysLink || (!llvm::sys::fs::exists(P.str(), Exists) && Exists))
> CmdArgs.push_back(Args.MakeArgString(P.str()));
> }
>
> @@ -326,7 +328,7 @@
> getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
> << "-fsanitize=undefined";
> } else {
> - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a");
> + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a", true);
>
> // The Ubsan runtime library requires C++.
> AddCXXStdlibLibArgs(Args, CmdArgs);
> @@ -343,7 +345,7 @@
> getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
> << "-fsanitize=address";
> } else {
> - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.asan_osx.a");
> + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.asan_osx.a", true);
>
> // The ASAN runtime library requires C++ and CoreFoundation.
> AddCXXStdlibLibArgs(Args, CmdArgs);
>
> Modified: cfe/trunk/lib/Driver/ToolChains.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=168428&r1=168427&r2=168428&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChains.h (original)
> +++ cfe/trunk/lib/Driver/ToolChains.h Wed Nov 21 08:17:42 2012
> @@ -370,9 +370,10 @@
>
> virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
> ArgStringList &CmdArgs) const;
> - void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
> - const char *DarwinStaticLib) const;
> -
> + void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
> + const char *DarwinStaticLib,
> + bool AlwaysLink = false) const;
> +
> virtual void AddCXXStdlibLibArgs(const ArgList &Args,
> ArgStringList &CmdArgs) const;
>
>
> Added: cfe/trunk/test/Driver/darwin-sanitizer-ld.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-sanitizer-ld.c?rev=168428&view=auto
> ==============================================================================
> --- cfe/trunk/test/Driver/darwin-sanitizer-ld.c (added)
> +++ cfe/trunk/test/Driver/darwin-sanitizer-ld.c Wed Nov 21 08:17:42 2012
> @@ -0,0 +1,40 @@
> +// Test sanitizer link flags on Darwin.
> +
> +// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
> +// RUN: -fsanitize=address %s -o %t.o 2>&1 \
> +// RUN: | FileCheck --check-prefix=CHECK-ASAN %s
> +
> +// CHECK-ASAN: "{{.*}}ld"
> +// CHECK-ASAN: libclang_rt.asan_osx.a"
> +// CHECK-ASAN: "-lstdc++"
This check fails on Snow Leopard, by the looks of it
http://lab.llvm.org:8011/builders/clang-x86_64-darwin10-gdb/builds/37/steps/check-all/logs/darwin-sanitizer-ld.c
Full output:
macmini4:build buildslave$
/Users/buildslave/build/Debug+Asserts/bin/clang
-no-canonical-prefixes -### -target x86_64-darwin
-fsanitize=address
/Users/buildslave/llvm/tools/clang/test/Driver/darwin-sanitizer-ld.c
-o /Users/buildslave/build/tools/clang/test/Driver/Output/darwin-sanitizer-ld.c.tmp.o
2>&1 | ./Debug+Asserts/bin/FileCheck --check-prefix=CHECK-ASAN
/Users/buildslave/llvm/tools/clang/test/Driver/darwin-sanitizer-ld.c
/Users/buildslave/llvm/tools/clang/test/Driver/darwin-sanitizer-ld.c:9:16:
error: expected string not found in input
// CHECK-ASAN: "-lstdc++"
^
<stdin>:5:319: note: scanning from here
"/usr/bin/ld" "-demangle" "-dynamic" "-arch" "x86_64"
"-macosx_version_min" "10.4.0" "-o"
"/Users/buildslave/build/tools/clang/test/Driver/Output/darwin-sanitizer-ld.c.tmp.o"
"-lcrt1.o" "/tmp/darwin-sanitizer-ld-1EuvSw.o"
"/Users/buildslave/build/Debug+Asserts/bin/../lib/clang/3.3/lib/darwin/libclang_rt.asan_osx.a"
"/usr/lib/libstdc++.6.dylib" "-framework" "CoreFoundation" "-lSystem"
"-lgcc_s.10.4"
^
<stdin>:5:329: note: possible intended match here
"/usr/bin/ld" "-demangle" "-dynamic" "-arch" "x86_64"
"-macosx_version_min" "10.4.0" "-o"
"/Users/buildslave/build/tools/clang/test/Driver/Output/darwin-sanitizer-ld.c.tmp.o"
"-lcrt1.o" "/tmp/darwin-sanitizer-ld-1EuvSw.o"
"/Users/buildslave/build/Debug+Asserts/bin/../lib/clang/3.3/lib/darwin/libclang_rt.asan_osx.a"
"/usr/lib/libstdc++.6.dylib" "-framework" "CoreFoundation" "-lSystem"
"-lgcc_s.10.4"
^
macmini4:build buildslave$
/Users/buildslave/build/Debug+Asserts/bin/clang
-no-canonical-prefixes -### -target x86_64-darwin
-fsanitize=address
/Users/buildslave/llvm/tools/clang/test/Driver/darwin-sanitizer-ld.c
-o /Users/buildslave/build/tools/clang/test/Driver/Output/darwin-sanitizer-ld.c.tmp.o
2>&1
clang version 3.3 (trunk 168521)
Target: x86_64--darwin
Thread model: posix
"/Users/buildslave/build/Debug+Asserts/bin/clang" "-cc1" "-triple"
"x86_64--macosx10.4.0" "-emit-obj" "-mrelax-all" "-disable-free"
"-main-file-name" "darwin-sanitizer-ld.c" "-mrelocation-model" "pic"
"-pic-level" "2" "-mdisable-fp-elim" "-masm-verbose" "-munwind-tables"
"-target-cpu" "core2" "-target-linker-version" "127.2.1"
"-resource-dir"
"/Users/buildslave/build/Debug+Asserts/bin/../lib/clang/3.3"
"-fmodule-cache-path" "/var/tmp/clang-module-cache"
"-fdebug-compilation-dir" "/Users/buildslave/build" "-ferror-limit"
"19" "-fmessage-length" "238" "-fsanitize=address" "-mstackrealign"
"-fblocks" "-fblocks-runtime-optional" "-fobjc-runtime=macosx-10.4.0"
"-fobjc-dispatch-method=non-legacy"
"-fobjc-default-synthesize-properties"
"-fencode-extended-block-signature" "-fdiagnostics-show-option"
"-fcolor-diagnostics" "-o" "/tmp/darwin-sanitizer-ld-WCSNj1.o" "-x"
"c" "/Users/buildslave/llvm/tools/clang/test/Driver/darwin-sanitizer-ld.c"
"/usr/bin/ld" "-demangle" "-dynamic" "-arch" "x86_64"
"-macosx_version_min" "10.4.0" "-o"
"/Users/buildslave/build/tools/clang/test/Driver/Output/darwin-sanitizer-ld.c.tmp.o"
"-lcrt1.o" "/tmp/darwin-sanitizer-ld-WCSNj1.o"
"/Users/buildslave/build/Debug+Asserts/bin/../lib/clang/3.3/lib/darwin/libclang_rt.asan_osx.a"
"/usr/lib/libstdc++.6.dylib" "-framework" "CoreFoundation" "-lSystem"
"-lgcc_s.10.4"
macmini4:build buildslave$
Is there something we could do to tidy this up? (either generalize the
CHECKs or, if ASan doesn't support Snow Leopard, XFAIL the test there
(I'm not sure how to detect that state in the REQUIRES lines, perhaps
we'd need to plumb through another property)).
Any other ideas? (I'm hoping to get this cleaned up so we can get the
bot back to green - it's already hiding/noisy-ing up some debug info
regressions also being reported by the bot)
> +// CHECK-ASAN: "-framework" "CoreFoundation"
> +
> +// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
> +// RUN: -fPIC -shared -fsanitize=address %s -o %t.so 2>&1 \
> +// RUN: | FileCheck --check-prefix=CHECK-DYN-ASAN %s
> +
> +// CHECK-DYN-ASAN: "{{.*}}ld"
> +// CHECK-DYN-ASAN: "-dylib"
> +// CHECK-DYN-ASAN-NOT: libclang_rt.asan_osx.a
> +// CHECK-DYN-ASAN: "-undefined"
> +// CHECK-DYN-ASAN: "dynamic_lookup"
> +// CHECK-DYN-ASAN-NOT: libclang_rt.asan_osx.a
> +
> +// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
> +// RUN: -fsanitize=undefined %s -o %t.o 2>&1 \
> +// RUN: | FileCheck --check-prefix=CHECK-UBSAN %s
> +
> +// CHECK-UBSAN: "{{.*}}ld"
> +// CHECK-UBSAN: libclang_rt.ubsan_osx.a"
> +// CHECK-UBSAN: "-lstdc++"
> +
> +// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
> +// RUN: -fPIC -shared -fsanitize=undefined %s -o %t.so 2>&1 \
> +// RUN: | FileCheck --check-prefix=CHECK-DYN-UBSAN %s
> +
> +// CHECK-DYN-UBSAN: "{{.*}}ld"
> +// CHECK-DYN-UBSAN: "-dylib"
> +// CHECK-DYN-UBSAN-NOT: libclang_rt.ubsan_osx.a
> +// CHECK-DYN-UBSAN: "-undefined"
> +// CHECK-DYN-UBSAN: "dynamic_lookup"
> +// CHECK-DYN-UBSAN-NOT: libclang_rt.ubsan_osx.a
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list