I don't know anything about the go compiler, but it seems to me this patch shouldn't be done like this.<div><br></div><div>If I understand correctly, when you pass -fsanitize=undefined (or whatever) to the linker job, all it does is add the library. If this is correct, then it makes no sense to have -nodefaultlibs remove it: it's not a default lib and it was explicitly added by passing -fsanitize to the link job.<span></span></div><div><br></div><div>From what's in the bug report, isn't it possible to change go's behaviour by passing it -fsanitize=blah in CFLAGS but now passing it in LDFLAGS, since it will add it by itself?</div><div><br></div><div>Regards,</div><div><br></div><div>  Filipe<br><br>On Friday, October 17, 2014, Eric Fiselier <<a href="mailto:eric@efcs.ca">eric@efcs.ca</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi All,<div><br></div><div>The libc++ LIT test driver uses -nodefaultlibs so that it can properly link against libc++ and the ABI library.</div><div>Since this patch we can no longer use sanitizers when running our test suite since it's quite difficult to mimic the driver's behavior and manually link in the sanitizer runtimes.</div><div><br></div><div>I agree with the rational behind your change. </div><div>However, since it's difficult to manually link the sanitizer runtimes, it would be nice to have a way to force the front end to do it even when -nodefaultlibs is present.</div><div>I think we should consider adding '-static-lib*san' flags similar to the ones provided by GCC.<br></div><div><br></div><div>I'm not very knowledgeable about the clang linker driver so any input is welcome. </div><div><br></div><div>/Eric</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 26, 2014 at 3:22 PM, Alexey Samsonov <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','vonosmas@gmail.com');" target="_blank">vonosmas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: samsonov<br>
Date: Fri Sep 26 16:22:08 2014<br>
New Revision: 218541<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=218541&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=218541&view=rev</a><br>
Log:<br>
Don't link in sanitizer runtimes if -nostdlib/-nodefaultlibs is provided.<br>
<br>
It makes no sense to link in sanitizer runtimes in this case: the user<br>
probably doesn't want to see any system/toolchain libs in his link if he<br>
provides these flags, and the link will most likely fail anyway - as sanitizer<br>
runtimes depend on libpthread, libdl, libc etc.<br>
<br>
Also, see discussion in <a href="https://code.google.com/p/address-sanitizer/issues/detail?id=344" target="_blank">https://code.google.com/p/address-sanitizer/issues/detail?id=344</a><br>
<br>
Modified:<br>
    cfe/trunk/lib/Driver/Tools.cpp<br>
    cfe/trunk/test/Driver/sanitizer-ld.c<br>
<br>
Modified: cfe/trunk/lib/Driver/Tools.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=218541&r1=218540&r2=218541&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=218541&r1=218540&r2=218541&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Sep 26 16:22:08 2014<br>
@@ -2243,6 +2243,10 @@ collectSanitizerRuntimes(const ToolChain<br>
 // C runtime, etc). Returns true if sanitizer system deps need to be linked in.<br>
 static bool addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,<br>
                                  ArgStringList &CmdArgs) {<br>
+  // Don't link in any sanitizer runtimes if we have no system libraries.<br>
+  if (Args.hasArg(options::OPT_nostdlib) ||<br>
+      Args.hasArg(options::OPT_nodefaultlibs))<br>
+    return false;<br>
   SmallVector<StringRef, 4> SharedRuntimes, StaticRuntimes,<br>
       HelperStaticRuntimes;<br>
   collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,<br>
<br>
Modified: cfe/trunk/test/Driver/sanitizer-ld.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=218541&r1=218540&r2=218541&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=218541&r1=218540&r2=218541&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Driver/sanitizer-ld.c (original)<br>
+++ cfe/trunk/test/Driver/sanitizer-ld.c Fri Sep 26 16:22:08 2014<br>
@@ -301,3 +301,10 @@<br>
 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan<br>
 // CHECK-LSAN-ASAN-LINUX: libclang_rt.asan-x86_64<br>
 // CHECK-LSAN-ASAN-LINUX-NOT: libclang_rt.lsan<br>
+<br>
+// RUN: %clang -nostdlib -fsanitize=address %s -### -o %t.o 2>&1 \<br>
+// RUN:     -target x86_64-unknown-linux \<br>
+// RUN:     --sysroot=%S/Inputs/basic_linux_tree \<br>
+// RUN:   | FileCheck --check-prefix=CHECK-NOSTDLIB %s<br>
+// CHECK-NOSTDLIB: "{{.*}}ld{{(.exe)?}}"<br>
+// CHECK-NOSTDLIB-NOT: libclang_rt.asan<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','cfe-commits@cs.uiuc.edu');" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</blockquote></div>