<div dir="ltr">Do we require link.exe to be on PATH?  Can you just call it directly?<div><br></div><div>You can arrange for LIB to contain the path to the asan rt, and then you should be able to mention it on the link line without much trouble.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 11, 2014 at 8:29 AM, Timur Iskhodzhanov <span dir="ltr"><<a href="mailto:timurrrr@google.com" target="_blank">timurrrr@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Reid, Hans,<br>
<br>
I have a hard time writing a simple LIT test that would fail before the fix.<br>
<br>
Here's a small standalone repro:<br>
---- f.cc ----<br>
#if CONFIG==1<br>
extern "C" __declspec(dllexport) int f1() {<br>
  int x = 0;<br>
  return 1;<br>
}<br>
#else<br>
extern "C" __declspec(dllexport) int f2() {<br>
  int x = 0;<br>
  return 2;<br>
}<br>
#endif<br>
--------------<br>
<br>
I can repro the failure @r212814 invoking link.exe directly (similar<br>
to what Chromium does):<br>
$ clang-cl -fsanitize=address -DCONFIG=1 f.cc -c -Fo1.obj && clang-cl<br>
-fsanitize=address -DCONFIG=2 f.cc -c -Fo2.obj<br>
$ link /DLL 1.obj<br>
%LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib<br>
&& \<br>
   link /DLL 2.obj 1.lib<br>
%LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib<br>
...<br>
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.cc.obj) : error<br>
LNK2005: ___asan_init_v4 already defined in 1.lib(1.dll)<br>
<br>
OK, cool, now I want to get the same error without invoking link.exe<br>
directly and without knowing the path to the RTL:<br>
[using the 1.lib generated by the previous link.exe command]<br>
$ clang-cl -fsanitize=address -LD -DCONFIG=2 f.cc 1.lib -Fe2.dll && echo OOPS<br>
   Creating library 2.lib and object 2.exp<br>
OOPS<br>
<br>
?!?!<br>
<br>
Adding -### reveals that clang-cl calls link.exe with the following<br>
args at the end of the command line:<br>
... "...\clang_rt.asan_dll_thunk-i386.lib" "blablabla.obj" "1.lib"<br>
and link.exe seems to be sensitive to the order in which the RTL and<br>
1.lib appear on the command line!   8)<br>
$ link /nologo /DLL 2.obj<br>
%LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib<br>
1.lib && echo OOPS<br>
OOPS<br>
$ link /nologo /DLL 2.obj 1.lib<br>
%LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib<br>
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.cc.obj) : error<br>
LNK2005: ___asan_init_v4 already defined in 1.lib(1.dll)<br>
<br>
I was unable to pass the lib and the RTL in the order required to<br>
repro the bug using clang-cl, as clang-cl overrides the order of stuff<br>
I pass via "-link".<br>
Any ideas?<br>
Or maybe it's Chromium/GYP that's doing something wrong?<br>
<br>
--<br>
Tim<br>
<br>
2014-07-11 17:46 GMT+04:00 Timur Iskhodzhanov <<a href="mailto:timurrrr@google.com">timurrrr@google.com</a>>:<br>
<div class="HOEnZb"><div class="h5">> Author: timurrrr<br>
> Date: Fri Jul 11 08:46:05 2014<br>
> New Revision: 212815<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=212815&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=212815&view=rev</a><br>
> Log:<br>
> [ASan/Win] Don't apply dllexport to __asan_init in the DLL thunk<br>
><br>
> This fixes '___asan_init_v4 already defined' errors when linking some of Chromium DLLs.<br>
> Looks like one of the DLL is using a .lib produced while linking another DLL and it exploded after r212699.<br>
> I'm trying to come up with a small testcase...<br>
><br>
> Modified:<br>
>     compiler-rt/trunk/lib/asan/CMakeLists.txt<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h<br>
><br>
> Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=212815&r1=212814&r2=212815&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=212815&r1=212814&r2=212815&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)<br>
> +++ compiler-rt/trunk/lib/asan/CMakeLists.txt Fri Jul 11 08:46:05 2014<br>
> @@ -179,7 +179,7 @@ else()<br>
>        add_compiler_rt_runtime(clang_rt.asan_dll_thunk-${arch} ${arch} STATIC<br>
>          SOURCES asan_dll_thunk.cc<br>
>                  $<TARGET_OBJECTS:RTInterception.${arch}><br>
> -        CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK<br>
> +        CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK -DSANITIZER_DLL_THUNK<br>
>          DEFS ${ASAN_COMMON_DEFINITIONS})<br>
>        add_dependencies(asan clang_rt.asan_dll_thunk-${arch})<br>
>      endif()<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=212815&r1=212814&r2=212815&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=212815&r1=212814&r2=212815&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Fri Jul 11 08:46:05 2014<br>
> @@ -17,7 +17,11 @@<br>
><br>
>  // Only use SANITIZER_*ATTRIBUTE* before the function return type!<br>
>  #if SANITIZER_WINDOWS<br>
> -# define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllexport)<br>
> +# if defined(SANITIZER_DLL_THUNK)<br>
> +#  define SANITIZER_INTERFACE_ATTRIBUTE<br>
> +# else<br>
> +#  define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllexport)<br>
> +# endif<br>
>  // FIXME find out what we need on Windows, if anything.<br>
>  # define SANITIZER_WEAK_ATTRIBUTE<br>
>  #elif defined(SANITIZER_GO)<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>