<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div>+asan/tsan/msan folks </div><div><br></div>That's not as simple as this, I afraid. <div>In *san there are two different kinds of interceptors. </div>
<div>1. foo from libc/libstc++ is completely replaced with foo from asan. Example: malloc, operator new</div><div>2. foo from libc/libstc++ is wrapped, such that when a user calls foo it calls the asan copy, but then the asan function calls the original foo. Example: pthread_create, __cxa_throw</div>
<div><br></div><div>This change allows to use -static-libstdc++ with asan w/o link failures, but asan is still broken for -static-libstdc++ in a subtle way (since the __cxa_throw is not intercepted, asan will have rare false positives in presence of exceptions). </div>
<div>Tsan also intercepts __cxa_guard in the similar way, so it will have false positives on function scope statics. </div><div><br></div><div>Do we really care that much about linking asan with static libstdc++?</div><div>
<br></div><div>--kcc </div><div><br><br><div class="gmail_quote">On Wed, Dec 5, 2012 at 2:54 AM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@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: chandlerc<br>
Date: Tue Dec  4 16:54:37 2012<br>
New Revision: 169328<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=169328&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=169328&view=rev</a><br>
Log:<br>
Add -whole-archive around the ASan runtime archive in the link command.<br>
<br>
This ensures that even though it comes first, we pick up its .o files.<br>
Note that if we can use this (or something similar / equivalent) on<br>
other platforms, we could potentially remove<br>
ReplaceOperatorsNewAndDelete from the ASan runtimes.<br>
<br>
We should probably do something similar for TSan and MSan as well.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Driver/Tools.cpp<br>
    cfe/trunk/test/Driver/asan-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=169328&r1=169327&r2=169328&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=169328&r1=169327&r2=169328&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Dec  4 16:54:37 2012<br>
@@ -1524,8 +1524,14 @@<br>
       // The ASan runtime needs to come before -lstdc++ (or -lc++, libstdc++.a,<br>
       // etc.) so that the linker picks ASan's versions of the global 'operator<br>
       // new' and 'operator delete' symbols. We take the extreme (but simple)<br>
-      // strategy of inserting it at the front of the link command.<br>
-      CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan));<br>
+      // strategy of inserting it at the front of the link command. It also<br>
+      // needs to be forced to end up in the executable, so wrap it in<br>
+      // whole-archive.<br>
+      SmallVector<const char*, 3> PrefixArgs;<br>
+      PrefixArgs.push_back("-whole-archive");<br>
+      PrefixArgs.push_back(Args.MakeArgString(LibAsan));<br>
+      PrefixArgs.push_back("-no-whole-archive");<br>
+      CmdArgs.insert(CmdArgs.begin(), PrefixArgs.begin(), PrefixArgs.end());<br>
       CmdArgs.push_back("-lpthread");<br>
       CmdArgs.push_back("-ldl");<br>
       CmdArgs.push_back("-export-dynamic");<br>
<br>
Modified: cfe/trunk/test/Driver/asan-ld.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/asan-ld.c?rev=169328&r1=169327&r2=169328&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/asan-ld.c?rev=169328&r1=169327&r2=169328&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/Driver/asan-ld.c (original)<br>
+++ cfe/trunk/test/Driver/asan-ld.c Tue Dec  4 16:54:37 2012<br>
@@ -19,7 +19,7 @@<br>
 //<br>
 // CHECK-LINUX-CXX: "{{.*}}ld{{(.exe)?}}"<br>
 // CHECK-LINUX-CXX-NOT: "-lc"<br>
-// CHECK-LINUX-CXX: libclang_rt.asan-i386.a"<br>
+// CHECK-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"<br>
 // CHECK-LINUX-CXX: "-lpthread"<br>
 // CHECK-LINUX-CXX: "-ldl"<br>
 // CHECK-LINUX-CXX: "-export-dynamic"<br>
@@ -32,7 +32,7 @@<br>
 //<br>
 // CHECK-LINUX-CXX-STATIC: "{{.*}}ld{{(.exe)?}}"<br>
 // CHECK-LINUX-CXX-STATIC-NOT: stdc++<br>
-// CHECK-LINUX-CXX-STATIC: libclang_rt.asan-i386.a"<br>
+// CHECK-LINUX-CXX-STATIC: "-whole-archive" "{{.*}}libclang_rt.asan-i386.a" "-no-whole-archive"<br>
 // CHECK-LINUX-CXX-STATIC: stdc++<br>
<br>
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">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></div>