7

I am trying to setup Asan Address Sanitizer for Visual Studio 2022. I am following this guide from MS: https://learn.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-170#ide-msbuild


I was able to (mostly, I think) follow the instructions.

But I get this warning when running my code with Asan.

==14676==WARNING: Failed to use and restart external symbolizer!
    #0 0x7ff67ec8109f in main C:\Users\Vader\source\repos\AsanTest\AsanTest\main.cpp:5
    #1 0x7ff67ec81f68 in invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    #2 0x7ff67ec81ebd in __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    #3 0x7ff67ec81d7d in __scrt_common_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330
    #4 0x7ff67ec81fdd in mainCRTStartup D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16
    #5 0x7ffe54d07613 in BaseThreadInitThunk+0x13 (C:\Windows\System32\KERNEL32.DLL+0x180017613)
    #6 0x7ffe563226b0 in RtlUserThreadStart+0x20 (C:\Windows\SYSTEM32\ntdll.dll+0x1800526b0)

The instructions say to do 4 things:

0. Enable Address Sanitizerenter image description here

1. Turn off edit and continue"Enable Edit and Continue Hot Reload" is turned off

2. Turn off /RTC1 (runtime checks) ✅ Turned off RTC1 by right clicking on the field and deleting the value. RTC1 is turned off

3. Turn off /INCREMENTAL (incremental linking)Incremental linking is turned off


When I do the "Use AddressSanitizer from a developer command prompt" I do not get this warning.


The test code

#include <stdio.h>
int x[100];
int main() {
    printf("Hello!\n");
    x[100] = 5; // Boom!
    return 0;
}
Vader
  • 6,335
  • 8
  • 31
  • 43
  • I can't answer your question, but this does work for me. One thing I do that might be relevant is to link with the static version of the runtime library. Something to try, anyway. – Paul Sanders Jul 27 '23 at 17:42
  • I tried changing the runtime library to the other one but the problem persists. https://i.imgur.com/DemufIq.png @PaulSanders – Vader Jul 27 '23 at 18:49
  • That screenshot says DLL. I use 'Multi Threaded Debug' (no DLL). – Paul Sanders Jul 27 '23 at 19:30
  • @PaulSanders Okay. I tried them all, nothing works. Weird thing is I do get output that says there was a buffer overflow https://hastebin.com/share/zomudonaru.yaml – Vader Jul 27 '23 at 20:16
  • Also, why it is looking for a symbolizer on the non-existent D drive? – Vader Jul 27 '23 at 20:35
  • I think that's the drive that the Microsoft dev was using when he built the CRT. Probably not relevant, therefore. – Paul Sanders Jul 27 '23 at 21:25
  • Can you provide the output screenshot generated by "cl XXX " command line? And the running screenshot? – Minxin Yu - MSFT Jul 28 '23 at 07:20
  • @MinxinYu-MSFT https://hastebin.com/share/ewofezeyor.java https://hastebin.com/share/foxonowuhi.yaml – Vader Jul 29 '23 at 13:09

1 Answers1

2

The problem has been asked before.

https://developercommunity.visualstudio.com/t/Fail-to-use-and-restart-external-symbol/10222443?q=+Failed+to+use+and+restart+external+symbolizer

You can vote on issues and leave comments to bring developers attention.

The problem is related to the Visual Studio debugging environment. The same program running in visual studio will output a warning Failed to use and restart external symbolizer,but not on cmd.

There is

PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\HostX86\x86;%PATH%

ASAN_SYMBOLIZER_PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\HostX86\x86

in Project's properties-> Debugging->Environment. Remove the variable and the warning disappears.

Minxin Yu - MSFT
  • 2,234
  • 1
  • 3
  • 14
  • I don't have that variable under `Environment` https://i.imgur.com/fyiaG2y.png – Vader Aug 03 '23 at 13:10
  • I am using VS2022 17.6.5. The variables will be added automatically after setting `Yes (/fsanitize=address) ` [picture](https://i.stack.imgur.com/axbfk.png). Variables are not bolded. – Minxin Yu - MSFT Aug 04 '23 at 08:25
  • 1
    Keep only PATH, get rid of ASAN_SYMBOLIZER_PATH – Vader Aug 04 '23 at 22:02