diff options
| author | star9029 <[email protected]> | 2025-12-22 16:54:25 +0800 |
|---|---|---|
| committer | star9029 <[email protected]> | 2025-12-22 16:54:25 +0800 |
| commit | 05ad043eaf740be73dd0b95b6d5ab97a4d82ac59 (patch) | |
| tree | 0c5b1c6e8f0b564ce14acc919d05462b6c5cd39e | |
| parent | a9e51834621aedeb6e8aa5aec0880af28ac4200d (diff) | |
add get_llvm_asan_flags
| -rw-r--r-- | xmake/core/package/package.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/utils/toolchain.lua | 16 | ||||
| -rw-r--r-- | xmake/rules/c++/config/sanitizer.lua | 2 |
3 files changed, 13 insertions, 7 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index bdd09ed5a..6c2742c80 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2471,7 +2471,7 @@ function _instance:_generate_sanitizer_configs(checkmode, sourcekind) if self:is_plat("windows") and checkmode == "address" and not self:has_tool("cxx", "cl") then local toolchain_utils = sandbox_module.import("private.utils.toolchain", {anonymous = true}) - table.join2(ldflags, toolchain_utils.add_llvm_asan_flags(self)) + table.join2(ldflags, toolchain_utils.get_llvm_asan_flags(self)) end if #ldflags ~= 0 then diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index 864d2d76e..25ada449c 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -467,9 +467,15 @@ function add_llvm_runenvs(toolchain) for _, dir in ipairs({dirs.libdir or false, dirs.cxxlibdir or false, dirs.rtlibdir or false}) do if dir then if toolchain:is_plat("windows") or is_host("windows") then - -- clang asan path must be first - local envs = toolchain:get("runenvs")["PATH"] - table.insert(envs, 1 , dir) + -- The dynamic libraries (DLLs) for Clang ASan and MSVC ASan share the same filename, making them incompatible. + -- Currently, runenvs maybe have Visual Studio environment variables. + -- If the Clang path is not prioritized (placed first), the system incorrectly loads the MSVC ASan DLL, resulting in a runtime failure. + local runenvs = toolchain:get("runenvs") + if runenvs and runenvs["PATH"]then + table.insert(runenvs["PATH"], 1 , dir) + else + toolchain:add("runenvs", "PATH", dir) + end elseif toolchain:is_plat("linux", "bsd") then toolchain:add("runenvs", "LD_LIBRARY_PATH", dir) elseif toolchain:is_plat("macosx") then @@ -484,8 +490,8 @@ function add_llvm_runenvs(toolchain) end end --- add address sanitizer flags for llvm -function add_llvm_asan_flags(target) +-- get address sanitizer flags for llvm +function get_llvm_asan_flags(target) assert(target:has_runtime("MD", "MT"), "clang asan only support MD/MT runtime on windows") local ldflags = {} diff --git a/xmake/rules/c++/config/sanitizer.lua b/xmake/rules/c++/config/sanitizer.lua index 646197c0c..3293a6808 100644 --- a/xmake/rules/c++/config/sanitizer.lua +++ b/xmake/rules/c++/config/sanitizer.lua @@ -47,7 +47,7 @@ function _add_build_sanitizer(target, sourcekind, checkmode) end if target:is_plat("windows") and checkmode == "address" and not target:has_tool("cxx", "cl") then - local ldflags = toolchain_utils.add_llvm_asan_flags(target) + local ldflags = toolchain_utils.get_llvm_asan_flags(target) if #ldflags ~= 0 then target:add("ldflags", ldflags, {force = true}) target:add("shflags", ldflags, {force = true}) |
