[compiler-rt] r212815 - [ASan/Win] Don't apply dllexport to __asan_init in the DLL thunk

Timur Iskhodzhanov timurrrr at google.com
Mon Jul 14 10:13:49 PDT 2014


2014-07-11 22:41 GMT+04:00 Reid Kleckner <rnk at google.com>:
> Do we require link.exe to be on PATH?  Can you just call it directly?

Ah, ok.
Probably not the most elegant solution ever, but not sure if a more
elegant solution exists.

> 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.

I just defined an %asan_dll_thunk substitution instead.

Test case added in r212959!

> On Fri, Jul 11, 2014 at 8:29 AM, Timur Iskhodzhanov <timurrrr at google.com>
> wrote:
>>
>> Reid, Hans,
>>
>> I have a hard time writing a simple LIT test that would fail before the
>> fix.
>>
>> Here's a small standalone repro:
>> ---- f.cc ----
>> #if CONFIG==1
>> extern "C" __declspec(dllexport) int f1() {
>>   int x = 0;
>>   return 1;
>> }
>> #else
>> extern "C" __declspec(dllexport) int f2() {
>>   int x = 0;
>>   return 2;
>> }
>> #endif
>> --------------
>>
>> I can repro the failure @r212814 invoking link.exe directly (similar
>> to what Chromium does):
>> $ clang-cl -fsanitize=address -DCONFIG=1 f.cc -c -Fo1.obj && clang-cl
>> -fsanitize=address -DCONFIG=2 f.cc -c -Fo2.obj
>> $ link /DLL 1.obj
>> %LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib
>> && \
>>    link /DLL 2.obj 1.lib
>> %LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib
>> ...
>> clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.cc.obj) : error
>> LNK2005: ___asan_init_v4 already defined in 1.lib(1.dll)
>>
>> OK, cool, now I want to get the same error without invoking link.exe
>> directly and without knowing the path to the RTL:
>> [using the 1.lib generated by the previous link.exe command]
>> $ clang-cl -fsanitize=address -LD -DCONFIG=2 f.cc 1.lib -Fe2.dll && echo
>> OOPS
>>    Creating library 2.lib and object 2.exp
>> OOPS
>>
>> ?!?!
>>
>> Adding -### reveals that clang-cl calls link.exe with the following
>> args at the end of the command line:
>> ... "...\clang_rt.asan_dll_thunk-i386.lib" "blablabla.obj" "1.lib"
>> and link.exe seems to be sensitive to the order in which the RTL and
>> 1.lib appear on the command line!   8)
>> $ link /nologo /DLL 2.obj
>> %LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib
>> 1.lib && echo OOPS
>> OOPS
>> $ link /nologo /DLL 2.obj 1.lib
>> %LLVM_BUILD%\lib\clang\3.5.0\lib\windows\clang_rt.asan_dll_thunk-i386.lib
>> clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.cc.obj) : error
>> LNK2005: ___asan_init_v4 already defined in 1.lib(1.dll)
>>
>> I was unable to pass the lib and the RTL in the order required to
>> repro the bug using clang-cl, as clang-cl overrides the order of stuff
>> I pass via "-link".
>> Any ideas?
>> Or maybe it's Chromium/GYP that's doing something wrong?
>>
>> --
>> Tim
>>
>> 2014-07-11 17:46 GMT+04:00 Timur Iskhodzhanov <timurrrr at google.com>:
>> > Author: timurrrr
>> > Date: Fri Jul 11 08:46:05 2014
>> > New Revision: 212815
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=212815&view=rev
>> > Log:
>> > [ASan/Win] Don't apply dllexport to __asan_init in the DLL thunk
>> >
>> > This fixes '___asan_init_v4 already defined' errors when linking some of
>> > Chromium DLLs.
>> > Looks like one of the DLL is using a .lib produced while linking another
>> > DLL and it exploded after r212699.
>> > I'm trying to come up with a small testcase...
>> >
>> > Modified:
>> >     compiler-rt/trunk/lib/asan/CMakeLists.txt
>> >     compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
>> >
>> > Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=212815&r1=212814&r2=212815&view=diff
>> >
>> > ==============================================================================
>> > --- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
>> > +++ compiler-rt/trunk/lib/asan/CMakeLists.txt Fri Jul 11 08:46:05 2014
>> > @@ -179,7 +179,7 @@ else()
>> >        add_compiler_rt_runtime(clang_rt.asan_dll_thunk-${arch} ${arch}
>> > STATIC
>> >          SOURCES asan_dll_thunk.cc
>> >                  $<TARGET_OBJECTS:RTInterception.${arch}>
>> > -        CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
>> > +        CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK -DSANITIZER_DLL_THUNK
>> >          DEFS ${ASAN_COMMON_DEFINITIONS})
>> >        add_dependencies(asan clang_rt.asan_dll_thunk-${arch})
>> >      endif()
>> >
>> > Modified:
>> > compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=212815&r1=212814&r2=212815&view=diff
>> >
>> > ==============================================================================
>> > --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
>> > (original)
>> > +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Fri
>> > Jul 11 08:46:05 2014
>> > @@ -17,7 +17,11 @@
>> >
>> >  // Only use SANITIZER_*ATTRIBUTE* before the function return type!
>> >  #if SANITIZER_WINDOWS
>> > -# define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllexport)
>> > +# if defined(SANITIZER_DLL_THUNK)
>> > +#  define SANITIZER_INTERFACE_ATTRIBUTE
>> > +# else
>> > +#  define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllexport)
>> > +# endif
>> >  // FIXME find out what we need on Windows, if anything.
>> >  # define SANITIZER_WEAK_ATTRIBUTE
>> >  #elif defined(SANITIZER_GO)
>> >
>> >
>> > _______________________________________________
>> > llvm-commits mailing list
>> > llvm-commits at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>



More information about the llvm-commits mailing list