Add address sanitizer flags

This commit is contained in:
Chad Engler 2022-08-07 12:09:19 -07:00
parent ce5b4af6c3
commit 55352cac7a
No known key found for this signature in database
GPG Key ID: 447DF683B71FB0BE
8 changed files with 111 additions and 6 deletions

View File

@ -156,7 +156,7 @@
<CLRSupport>Pure</CLRSupport>
]]
end
function suite.clrSupport_onClrNetCore()
clr "NetCore"
prepare()
@ -353,3 +353,69 @@
</PropertyGroup>
]]
end
--
-- If the AddressSanitizer flag is set, add the EnableASAN element.
--
function suite.onAddressSanitizer()
p.action.set("vs2022")
flags "AddressSanitizer"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
<EnableASAN>true</EnableASAN>
</PropertyGroup>
]]
end
function suite.onAddressSanitizer_BeforeVS2022()
p.action.set("vs2019")
flags "AddressSanitizer"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
]]
end
--
-- If the Fuzzer flag is set, add the EnableFuzzer element.
--
function suite.onFuzzer()
p.action.set("vs2022")
flags "Fuzzer"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
<EnableFuzzer>true</EnableFuzzer>
</PropertyGroup>
]]
end
function suite.onFuzzer_BeforeVS2022()
p.action.set("vs2019")
flags "Fuzzer"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
]]
end

View File

@ -195,6 +195,7 @@
m.clrSupport,
m.characterSet,
m.platformToolset,
m.sanitizers,
m.toolsVersion,
m.wholeProgramOptimization,
m.nmakeOutDirs,
@ -2507,6 +2508,17 @@
end
end
function m.sanitizers(cfg)
if _ACTION >= "vs2022" then
if cfg.flags.AddressSanitizer then
m.element("EnableASAN", nil, "true")
end
if cfg.flags.Fuzzer then
m.element("EnableFuzzer", nil, "true")
end
end
end
function m.precompiledHeaderFile(fileName, cfg)
m.element("PrecompiledHeaderFile", nil, "%s", fileName)
end

View File

@ -489,6 +489,7 @@
scope = "config",
kind = "list:string",
allowed = {
"AddressSanitizer",
"Component", -- DEPRECATED
"DebugEnvsDontMerge",
"DebugEnvsInherit",
@ -500,6 +501,7 @@
"FatalLinkWarnings",
"FloatFast", -- DEPRECATED
"FloatStrict", -- DEPRECATED
"Fuzzer", -- Visual Studio 2022+ only
"LinkTimeOptimization",
"Managed", -- DEPRECATED
"Maps",

View File

@ -203,6 +203,7 @@
Off = "-fno-exceptions"
},
flags = {
AddressSanitizer = "-fsanitize=address",
NoBufferSecurityCheck = "-fno-stack-protector",
},
cppdialect = {

View File

@ -154,6 +154,10 @@
--
msc.cxxflags = {
flags = {
AddressSanitizer = "/fsanitize=address",
Fuzzer = "/fsanitize=fuzzer",
},
exceptionhandling = {
Default = "/EHsc",
On = "/EHsc",

View File

@ -356,18 +356,24 @@
-- Check the translation of CXXFLAGS.
--
function suite.cflags_onNoExceptions()
function suite.cxxflags_onNoExceptions()
exceptionhandling "Off"
prepare()
test.contains({ "-fno-exceptions" }, gcc.getcxxflags(cfg))
end
function suite.cflags_onNoBufferSecurityCheck()
function suite.cxxflags_onNoBufferSecurityCheck()
flags { "NoBufferSecurityCheck" }
prepare()
test.contains({ "-fno-stack-protector" }, gcc.getcxxflags(cfg))
end
function suite.cxxflags_onAddressSanitizer()
flags { "AddressSanitizer" }
prepare()
test.contains({ "-fsanitize=address" }, gcc.getcxxflags(cfg))
end
--
-- Check the basic translation of LDFLAGS for a Posix system.
--

View File

@ -441,6 +441,18 @@
test.contains("/GR-", msc.getcxxflags(cfg))
end
function suite.cxxflags_onAddressSanitizer()
flags { "AddressSanitizer" }
prepare()
test.contains("/fsanitize=address", msc.getcxxflags(cfg))
end
function suite.cxxflags_onFuzzer()
flags { "Fuzzer" }
prepare()
test.contains("/fsanitize=fuzzer", msc.getcxxflags(cfg))
end
--
-- Check handling of additional linker options.
@ -573,9 +585,9 @@
end
--
-- Check handling of Run-Time Library flags.
--
--
-- Check handling of Run-Time Library flags.
--
function suite.cflags_onStaticRuntime()
staticruntime "On"

View File

@ -10,6 +10,8 @@ flags { "flag_list" }
| Flag | Description | Notes |
|-----------------------|---------------------------------------------------------------------|----------------|
| AddressSanitizer | Enables compiler support for AddressSanitizer. | Visual Studio support starts with 2022. |
| Fuzzer | Enables support for LibFuzzer, a coverage-guided fuzzing library. | Visual Studio 2022+ only. |
| ExcludeFromBuild | Exclude a source code file from the build, for the current configuration. |
| FatalCompileWarnings | Treat compiler warnings as errors. |
| FatalLinkWarnings | Treat linker warnings as errors. |