lsalamon / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 1 forks source link

AddressSanitizer should support -MTd/-MDd runtimes #328

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
$ cat foo.cpp
#include <stdlib.h>
int f() {
 calloc(1, 1);
 return 1;
}

$ clang-cl -fsanitize=address -c foo.cpp -MTd

$ clang-cl -fsanitize=address foo.obj -LD
libcmtd.lib(dbgheap.obj) : error LNK2005: __calloc_dbg already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __expand already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __expand_dbg already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __free_dbg already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __malloc_dbg already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __msize already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __realloc_dbg already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in 
clang_rt.asan_dll_thunk-i386.lib(asan_dll_thunk.obj)
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; 
use /NODEFAULTLIB:library
foo.dll : fatal error LNK1169: one or more multiply defined symbols found
clang-cl.exe: error: linker command failed with exit code 1169 (use -v to see 
invocation)

$ clang-cl -fsanitize=address foo.obj
libcmtd.lib(dbgheap.obj) : error LNK2005: __calloc_dbg already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __expand already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __expand_dbg already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __free_dbg already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __malloc_dbg already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __msize already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __realloc_dbg already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
libcmtd.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in 
clang_rt.asan-i386.lib(asan_malloc_win.obj)
   Creating library foo.lib and object foo.exp
LINK : fatal error LNK1561: entry point must be defined
clang-cl.exe: error: linker command failed with exit code 1561 (use -v to see 
invocation)

Original issue reported on code.google.com by ehsan.ak...@gmail.com on 26 Jul 2014 at 5:44

GoogleCodeExporter commented 9 years ago

Original comment by konstant...@gmail.com on 28 Jul 2014 at 6:57

GoogleCodeExporter commented 9 years ago
Note that I'm also getting similar errors when using -MT and building one of 
the Firefox test executables, but so far I have not been able to create a small 
test case that reproduces it...

clang_rt.asan_cxx-i386.lib(asan_new_delete.obj) : error LNK2005: "void __cdecl 
operator delete(void *)" (??3@YAXPAX@Z) already defined in 
libcmt.lib(delete.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: __calloc_impl 
already defined in libcmt.lib(calloc_impl.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: __expand already 
defined in libcmt.lib(expand.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: __msize already 
defined in libcmt.lib(msize.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: __recalloc already 
defined in libcmt.lib(recalloc.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: _calloc already 
defined in libcmt.lib(calloc.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: _free already 
defined in libcmt.lib(free.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: _malloc already 
defined in libcmt.lib(malloc.obj)
clang_rt.asan-i386.lib(asan_malloc_win.obj) : error LNK2005: _realloc already 
defined in libcmt.lib(realloc.obj)

Original comment by ehsan.ak...@gmail.com on 28 Jul 2014 at 1:11

GoogleCodeExporter commented 9 years ago
Only -MT is currently supported.
-MD is very likely to be implemented before -MTd/-MDd.

Can you provide a justification why -MTd/-MDd are important to support?

Original comment by timurrrr@google.com on 28 Jul 2014 at 1:15

GoogleCodeExporter commented 9 years ago
Self-note: -MD support is tracked here 
http://llvm.org/bugs/show_bug.cgi?id=20214

Original comment by timurrrr@google.com on 28 Jul 2014 at 1:15

GoogleCodeExporter commented 9 years ago
-MTd and -MDd would be useful for us since on other platforms we use ASAN with 
our "debug" builds which have other debugging runtime facilities such as 
assertions and bounds checking enabled.  That being said, supporting -MD is 
*much* more useful to us since we don't really support building Firefox with 
-MT at all, and I've had to do some major hackery to our build system which 
disables a whole bunch of modules that we would ideally like to test with ASAN.

Original comment by ehsan.ak...@gmail.com on 28 Jul 2014 at 1:29

GoogleCodeExporter commented 9 years ago
My understanding is that the linker is sensitive to the order of libraries on 
the command line.  IIRC, the correct order is the asan rtl followed by the CRT. 
 Can you play with the link line directly to make the link succeed?

It may be affected by '/defaultlib:libcmt.lib' flags in object files as well.  
Maybe '/nodefaultlib:libcmt.lib clang_rt.asan-i386.lib libcmt.lib' could fix it.

Hopefully we can fix the order dependency at some point.

Original comment by rnk@google.com on 28 Jul 2014 at 4:52

GoogleCodeExporter commented 9 years ago
I did play with the linking order and also with /nodefaultlib and neither 
helped. :(

Original comment by ehsan.ak...@gmail.com on 28 Jul 2014 at 5:09

GoogleCodeExporter commented 9 years ago
If -MD was supported, could you emulate -MDd assertions etc. using preprocessor 
macro?
IIRC, all those debug CRTs are structured very differently from the release 
counterparts and it is much harder to intercept them correctly.

Original comment by timurrrr@google.com on 4 Aug 2014 at 1:04

GoogleCodeExporter commented 9 years ago
Yes I think that would be possible.  We would of course lose the assertion 
within the CRT itself, but I don't think that we have used them very heavily 
anyways.

Original comment by ehsan.ak...@gmail.com on 4 Aug 2014 at 1:45

GoogleCodeExporter commented 9 years ago
We'll dodge CRT allocator assertions anyways as we'll use ASan-provided 
allocator :)
OK, got ya -- I'll prioritize -MD above -MTd/-MDd then.

Original comment by timurrrr@google.com on 4 Aug 2014 at 1:52

GoogleCodeExporter commented 9 years ago
Yep, thanks, I appreciate it.  :-)

Original comment by ehsan.ak...@gmail.com on 4 Aug 2014 at 1:56

GoogleCodeExporter commented 9 years ago

Original comment by ramosian.glider@gmail.com on 30 Jul 2015 at 9:05

GoogleCodeExporter commented 9 years ago
Adding Project:AddressSanitizer as part of GitHub migration.

Original comment by ramosian.glider@gmail.com on 30 Jul 2015 at 9:06