diff options
| author | ruki <[email protected]> | 2023-09-21 22:40:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-09-21 22:40:21 +0800 |
| commit | 8afc0e7ed5d14918fa4fafd450b23263f62ea147 (patch) | |
| tree | 42ae5604bb4582d83028ba811a90ff623e9856a5 | |
| parent | 3d9cf6af8a3fae36dbb5e8fe055a54000ddcadfb (diff) | |
enable asan for package
| -rw-r--r-- | xmake/core/package/package.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/package/tools/autoconf.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 12 | ||||
| -rw-r--r-- | xmake/modules/package/tools/meson.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 7 |
5 files changed, 32 insertions, 3 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 10d32a0ca..4df947d66 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2112,11 +2112,11 @@ function _instance:_generate_lto_configs(sourcekind) end -- generate sanitizer configs -function _instance:_generate_sanitizer_configs(sourcekind, checkmode) +function _instance:_generate_sanitizer_configs(checkmode, sourcekind) -- add cflags local configs = {} - if self:has_tool(sourcekind, "cl", "clang", "clangxx", "gcc", "gxx") then + if sourcekind and self:has_tool(sourcekind, "cl", "clang", "clangxx", "gcc", "gxx") then local cflag = sourcekind == "cxx" and "cxxflags" or "cflags" configs[cflag] = "-fsanitize=" .. checkmode end @@ -2165,7 +2165,7 @@ function _instance:_generate_build_configs(configs, opt) end end if self:config("asan") then - local configs_asan = self:_generate_sanitizer_configs(opt.sourcekind or "cxx", "address") + local configs_asan = self:_generate_sanitizer_configs("address", opt.sourcekind or "cxx") if configs_asan then for k, v in pairs(configs_asan) do configs[k] = table.wrap(configs[k] or {}) diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index faa842d54..8aa03452e 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -282,6 +282,11 @@ function buildenvs(package, opt) table.join2(cxxflags, package:_generate_lto_configs("cxx").cxxflags) table.join2(ldflags, package:_generate_lto_configs().ldflags) end + if package:config("asan") then + table.join2(cflags, package:_generate_sanitizer_configs("address", "cc").cflags) + table.join2(cxxflags, package:_generate_sanitizer_configs("address", "cxx").cxxflags) + table.join2(ldflags, package:_generate_sanitizer_configs("address").ldflags) + end envs.CFLAGS = table.concat(cflags, ' ') envs.CXXFLAGS = table.concat(cxxflags, ' ') envs.CPPFLAGS = table.concat(cppflags, ' ') diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 4c3f58def..77511735b 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -163,6 +163,9 @@ function _get_cflags(package, opt) if package:config("lto") then table.join2(result, package:_generate_lto_configs("cc").cflags) end + if package:config("asan") then + table.join2(result, package:_generate_sanitizer_configs("address", "cc").cflags) + end table.join2(result, _get_cflags_from_packagedeps(package, opt)) if #result > 0 then return os.args(result) @@ -191,6 +194,9 @@ function _get_cxxflags(package, opt) if package:config("lto") then table.join2(result, package:_generate_lto_configs("cxx").cxxflags) end + if package:config("asan") then + table.join2(result, package:_generate_sanitizer_configs("address", "cxx").cxxflags) + end table.join2(result, _get_cflags_from_packagedeps(package, opt)) if #result > 0 then return os.args(result) @@ -230,6 +236,9 @@ function _get_ldflags(package, opt) if package:config("lto") then table.join2(result, package:_generate_lto_configs().ldflags) end + if package:config("asan") then + table.join2(result, package:_generate_sanitizer_configs("address").ldflags) + end table.join2(result, _get_ldflags_from_packagedeps(package, opt)) if opt.ldflags then table.join2(result, opt.ldflags) @@ -253,6 +262,9 @@ function _get_shflags(package, opt) if package:config("lto") then table.join2(result, package:_generate_lto_configs().shflags) end + if package:config("asan") then + table.join2(result, package:_generate_sanitizer_configs("address").shflags) + end table.join2(result, _get_ldflags_from_packagedeps(package, opt)) if opt.shflags then table.join2(result, opt.shflags) diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index 1a73328cb..29e4cad35 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -291,6 +291,11 @@ function _get_configs(package, configs, opt) table.insert(configs, "-Db_lto=true") end + -- add asan + if package:config("asan") then + table.insert(configs, "-Db_sanitize=address") + end + -- add vs_runtime flags local vs_runtime = package:config("vs_runtime") if package:is_plat("windows") and vs_runtime then diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 528ad4985..3f679ef7d 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -250,6 +250,13 @@ function _get_configs(package, configs, opt) policies = "build.optimization.lto" end end + if package:config("asan") and (not policies or not policies:find("build.sanitizer.address", 1, true)) then + if policies then + policies = policies .. ",build.sanitizer.address" + else + policies = "build.sanitizer.address" + end + end if not package:use_external_includes() and (not policies or not policies:find("package.include_external_headers", 1, true)) then if policies then policies = policies .. ",package.include_external_headers:n" |
