<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr">On Tue, Dec 4, 2012 at 2:52 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank" class="cremed">thakis@chromium.org</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">-whole-archive is linux-only. darwin has -force_load libfoo.a.<br></blockquote>
<div><br></div><div style>This is already in the linux-only part of the driver.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
On Tue, Dec 4, 2012 at 2:43 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" class="cremed">chandlerc@google.com</a>> wrote:<br>
> On it. We need to wrap the runtime in -whole-archive as well.<br>
><br>
> I'm a touch worried about this being a Linux-only fix, but that'll have to<br>
> wait for someone on a non-linux platform where it matters to chime in...<br>
><br>
><br>
> On Tue, Dec 4, 2012 at 2:21 PM, Alexey Samsonov <<a href="mailto:samsonov@google.com" class="cremed">samsonov@google.com</a>> wrote:<br>
>><br>
>> Hi Matt,<br>
>><br>
>> This breaks building programs with ASan:<br>
>> $ cat zzz.cc<br>
>> int main(int argc, char *argv[]) {<br>
>>   return 0;<br>
>> }<br>
>> $ clang++ -fsanitize=address zzz.cc<br>
>> /tmp/zzz-YkVYcB.o: In function `main':<br>
>> zzz.cc:(.text+0xfb): undefined reference to `__asan_report_store4'<br>
>> zzz.cc:(.text+0x157): undefined reference to `__asan_report_store4'<br>
>> zzz.cc:(.text+0x18b): undefined reference to `__asan_report_store8'<br>
>> /tmp/zzz-YkVYcB.o: In function `asan.module_ctor':<br>
>> zzz.cc:(.text+0x1f5): undefined reference to `__asan_init'<br>
>> clang-3: error: linker command failed with exit code 1 (use -v to see<br>
>> invocation)<br>
>><br>
>><br>
>> On Tue, Dec 4, 2012 at 1:18 PM, Matt Beaumont-Gay <<a href="mailto:matthewbg@google.com" class="cremed">matthewbg@google.com</a>><br>
>> wrote:<br>
>>><br>
>>> Author: matthewbg<br>
>>> Date: Tue Dec  4 15:18:26 2012<br>
>>> New Revision: 169310<br>
>>><br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=169310&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=169310&view=rev</a><br>
>>> Log:<br>
>>> Currently, with -fsanitize=address, the driver appends libclang_rt.asan.a<br>
>>> to<br>
>>> the link command. This all works fine when the driver is also responsible<br>
>>> for<br>
>>> adding -lstdc++ to the link command. But, if -lstdc++ (or libstdc++.a,<br>
>>> etc) is<br>
>>> passed explicitly to the driver, the ASan runtime will appear in the link<br>
>>> command after the standard library, leading to multiple-definition errors<br>
>>> for<br>
>>> the global 'operator new' and 'operator delete'. Fix this in a painfully<br>
>>> simple way, by inserting libclang_rt.asan.a at the start of the link<br>
>>> command<br>
>>> instead of the end.<br>
>>><br>
>>> If we need to do something more clever, we can walk the link command<br>
>>> looking<br>
>>> for something that resembles libstdc++ and insert libclang_rt.asan.a as<br>
>>> late<br>
>>> as possible, but the simple solution works for now.<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:<br>
>>> <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=169310&r1=169309&r2=169310&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=169310&r1=169309&r2=169310&view=diff</a><br>

>>><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
>>> +++ cfe/trunk/lib/Driver/Tools.cpp Tue Dec  4 15:18:26 2012<br>
>>> @@ -1512,7 +1512,7 @@<br>
>>>      llvm::sys::path::append(LibAsan, "lib", "linux",<br>
>>>          (Twine("libclang_rt.asan-") +<br>
>>>              TC.getArchName() + "-android.so"));<br>
>>> -    CmdArgs.push_back(Args.MakeArgString(LibAsan));<br>
>>> +    CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan));<br>
>>>    } else {<br>
>>>      if (!Args.hasArg(options::OPT_shared)) {<br>
>>>        // LibAsan is "libclang_rt.asan-<ArchName>.a" in the Linux library<br>
>>> @@ -1521,7 +1521,11 @@<br>
>>>        llvm::sys::path::append(LibAsan, "lib", "linux",<br>
>>>                                (Twine("libclang_rt.asan-") +<br>
>>>                                 TC.getArchName() + ".a"));<br>
>>> -      CmdArgs.push_back(Args.MakeArgString(LibAsan));<br>
>>> +      // The ASan runtime needs to come before -lstdc++ (or -lc++,<br>
>>> libstdc++.a,<br>
>>> +      // etc.) so that the linker picks ASan's versions of the global<br>
>>> 'operator<br>
>>> +      // new' and 'operator delete' symbols. We take the extreme (but<br>
>>> simple)<br>
>>> +      // strategy of inserting it at the front of the link command.<br>
>>> +      CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan));<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:<br>
>>> <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/asan-ld.c?rev=169310&r1=169309&r2=169310&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/asan-ld.c?rev=169310&r1=169309&r2=169310&view=diff</a><br>

>>><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/test/Driver/asan-ld.c (original)<br>
>>> +++ cfe/trunk/test/Driver/asan-ld.c Tue Dec  4 15:18:26 2012<br>
>>> @@ -24,7 +24,17 @@<br>
>>>  // CHECK-LINUX-CXX: "-ldl"<br>
>>>  // CHECK-LINUX-CXX: "-export-dynamic"<br>
>>>  // CHECK-LINUX-CXX: stdc++<br>
>>> +<br>
>>> +// RUN: %clang -no-canonical-prefixes %s -### -o /dev/null<br>
>>> -fsanitize=address \<br>
>>> +// RUN:     -target i386-unknown-linux<br>
>>> --sysroot=%S/Inputs/basic_linux_tree \<br>
>>> +// RUN:     -lstdc++ -static 2>&1 \<br>
>>> +// RUN:   | FileCheck --check-prefix=CHECK-LINUX-CXX-STATIC %s<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: stdc++<br>
>>> +<br>
>>>  // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \<br>
>>>  // RUN:     -target arm-linux-androideabi -fsanitize=address \<br>
>>>  // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \<br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> cfe-commits mailing list<br>
>>> <a href="mailto:cfe-commits@cs.uiuc.edu" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
>> Alexey Samsonov, MSK<br>
>><br>
>><br>
>> _______________________________________________<br>
>> cfe-commits mailing list<br>
>> <a href="mailto:cfe-commits@cs.uiuc.edu" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
><br>
</div></div></blockquote></div><br></div></div></div>