Add use_asan option for MSVC to enable AddressSanitizer

Exposes AddressSanitizer support in MSVC compiler. Can be installed via individual
components in the Visual Studio 2019 Installer.

Disabled by default. Compile the engine with `scons use_asan=yes`.

(cherry picked from commit 53901d870b)
This commit is contained in:
Andrii Doroshenko (Xrayez) 2021-03-12 18:44:06 +02:00 committed by Rémi Verschelde
parent b73a97b110
commit 7c7f4602e7
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -71,6 +71,7 @@ def get_opts():
BoolVariable("use_llvm", "Use the LLVM compiler", False),
BoolVariable("use_thinlto", "Use ThinLTO", False),
BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True),
BoolVariable("use_asan", "Use address sanitizer (ASAN)", False),
]
@ -283,6 +284,12 @@ def configure_msvc(env, manual_msvc_config):
env.Prepend(CPPPATH=[p for p in os.getenv("INCLUDE").split(";")])
env.Append(LIBPATH=[p for p in os.getenv("LIB").split(";")])
# Sanitizers
if env["use_asan"]:
env.extra_suffix += ".s"
env.Append(LINKFLAGS=["/INFERASANLIBS"])
env.Append(CCFLAGS=["/fsanitize=address"])
# Incremental linking fix
env["BUILDERS"]["ProgramOriginal"] = env["BUILDERS"]["Program"]
env["BUILDERS"]["Program"] = methods.precious_program