Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASan requires /MTd linking on Windows #43

Closed
ramosian-glider opened this issue Aug 31, 2015 · 5 comments
Closed

ASan requires /MTd linking on Windows #43

ramosian-glider opened this issue Aug 31, 2015 · 5 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 43

As of LLVM@r150812 / asan-tests@r1200,

$ cl /MT /Zi /Fehello.exe <path_to_asan_rtl>/asan_*.cc <path_to_tests>/hello_pass.c
&& hello.exe
...
==4832== ERROR: AddressSanitizer attempting free on address which was not malloc()-ed:
0x019f2368
  #0 0x408635  free <path_to_asan_rtl>\asan_malloc_win.cc:38
  #1 0x40e062  __endstdio f:\dd\vctools\crt_bld\self_x86\crt\src\_file.c:198
  #2 0x40e417  doexit f:\dd\vctools\crt_bld\self_x86\crt\src\crt0dat.c:606
  #3 0x40e479  exit f:\dd\vctools\crt_bld\self_x86\crt\src\crt0dat.c:412
  #4 0x40e7e7  __tmainCRTStartup f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c:272
NOTE: this happens even without intrumentation.

A similar command line with /MTd works fine.

Reported by timurrrr on 2012-02-21 09:18:40

@ramosian-glider
Copy link
Member Author

crt\src\_file.c:
190 void __cdecl __endstdio(void)
191 {
192         /* flush all streams */
193         _flushall();
194
195         /* if in callable exit, close all streams */
196         if (_exitflag)
197                 _fcloseall();
198         _free_crt(__piob);
199 }

__piob is initialized in the same file:
133         if ( (__piob = (void **)_calloc_crt( _nstream, sizeof(void *) )) ==
134              NULL ) {

Turns out _free_crt is an alias to free
whilst _calloc_crt is NOT an alias of calloc...

crt\src\dbgint.h:
 83 #define _expand_crt                     _expand
 84 #define _free_crt                       free
 85 #define _msize_crt                      _msize
 86 #define _dupenv_s_crt(ps1, size, s2)    _dupenv_s(ps1, size, s2)
 87 #define _wdupenv_s_crt(ps1, size, s2)   _wdupenv_s(ps1, size, s2)
 88 #if defined (_SYSCRT) || defined (MRTDLL) || defined (_M_CEE_PURE)
 89 #define _malloc_crt                     malloc
 90 #define _calloc_crt                     calloc
 91 #define _realloc_crt                    realloc
 92 #define _recalloc_crt                   _recalloc
 93 #else  /* defined (_SYSCRT) || defined (MRTDLL) || defined (_M_CEE_PURE) */
 94 _Check_return_ _Ret_opt_bytecap_(_Size) _CRTIMP void * __cdecl _malloc_crt(...);
 95 _Check_return_ _Ret_opt_bytecap_x_(_Count*_Size) _CRTIMP void * __cdecl _calloc_crt(...);
 96 _Check_return_ _Ret_opt_bytecap_(_NewSize) _CRTIMP void * __cdecl _realloc_crt(...);
 97 _Check_return_ _Ret_opt_bytecap_x_(_Count*_Size) _CRTIMP void * __cdecl _recalloc_crt(...);
 98 #endif  /* defined (_SYSCRT) || defined (MRTDLL) || defined (_M_CEE_PURE) */

Reported by timurrrr on 2012-02-21 09:23:51

@ramosian-glider
Copy link
Member Author

See also http://code.google.com/p/drmemory/issues/detail?id=606

Reported by timurrrr on 2012-02-21 09:24:07

@ramosian-glider
Copy link
Member Author

... _calloc_crt in turn calls HeapAlloc.

Defining _SYSCRT doesn't help (probably the CRT is pre-built as LIBCMT.lib)

Possible solutions:
1) Use /MTd until we have good reasons not to
2) Intercept _*alloc_crt too (not clear how -> "already defined")
   Intercepting _calloc_impl gives an infinite loop due to ASanWrite/fwrite 

   FTR,
     _calloc_crt is in crt\src\crtheap.c
     _calloc_impl is in crt\src\calloc_impl.c
3) Intercept HeapAlloc -> TODO anyways
4) ...

For now I'm going to use /MTd as it's
a) simple + no need to write code
b) allows me to avoid suppressing wrong-free-arg reports
  =>
c) allows me to add more tests

Reported by timurrrr on 2012-02-21 09:43:49

@ramosian-glider
Copy link
Member Author

Turns out we don't need /MTd as it's a synonym to "static linking" on Linux,
so we've switched to /MD since r1206.

Reported by timurrrr on 2012-02-21 16:36:07

  • Status changed: WontFix

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:12:58

  • Labels added: ProjectAddressSanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant