refactor(asan): TPC_ASAN 环境变量改 args 直传
--asan 不再写 TPC_ASAN 环境变量,改为 Config 解析后直接经 asan_mode=args.asan 传给 Phase2Translator(主进程 .ll→.obj 插桩与 链接 -fsanitize=address 均读 self.asan_mode),消除环境变量在 worker 子进程/外部调用链下的不可靠性。
This commit is contained in:
1 parent
e83c06041a
commit
0db1ccd1bb
2 files changed
+9
-8
No files matched your search
@@ -445,7 +445,7 @@ class Phase2Translator:
|
||||
_include_sha1_cache: dict[str, str] = {}
|
||||
_include_exist_cache: dict[str, bool] = {}
|
||||
|
||||
def __init__(self, src_root: str, temp_dir: str, output_dir: str, compile_cmd: str = 'llc', compile_flags: list[str] | None = None, linker_cmd: str | None = None, linker_flags: list[str] | None = None, linker_output: str | None = None, include_dirs: list[str] | None = None, entry_files: list[str] | None = None, target_triple: str | None = None, target_datalayout: str | None = None, force_recompile_includes: bool = False, build_pyi_cache: bool = True) -> None:
|
||||
def __init__(self, src_root: str, temp_dir: str, output_dir: str, compile_cmd: str = 'llc', compile_flags: list[str] | None = None, linker_cmd: str | None = None, linker_flags: list[str] | None = None, linker_output: str | None = None, include_dirs: list[str] | None = None, entry_files: list[str] | None = None, target_triple: str | None = None, target_datalayout: str | None = None, force_recompile_includes: bool = False, build_pyi_cache: bool = True, asan_mode: bool = False) -> None:
|
||||
self.src_root = os.path.abspath(src_root)
|
||||
self.temp_dir = os.path.abspath(temp_dir)
|
||||
self.output_dir = os.path.abspath(output_dir)
|
||||
@@ -462,11 +462,12 @@ class Phase2Translator:
|
||||
self.linker_cmd = linker_cmd
|
||||
self.linker_flags = linker_flags or []
|
||||
self.linker_output = linker_output
|
||||
# ASan 模式:TPC_ASAN=1 时对全部 .ll 做 opt -passes=asan 插桩并链接 libasan。
|
||||
# ASan 模式:由 Config 的 --asan 参数直传(不再用 TPC_ASAN 环境变量,
|
||||
# 环境变量在 worker 子进程/外部调用链下不可靠)。
|
||||
# 检测 stdlib 堆/栈/全局越界与垃圾指针(MemBuddy pool 内部由 canary 覆盖)。
|
||||
# 注意:mingw64 的 clang 不提供 ASan runtime(libclang_rt.asan 缺失),
|
||||
# 必须使用 clang64 环境(自带 asan_dynamic runtime),PATH 前置 clang64/bin。
|
||||
self.asan_mode = os.environ.get('TPC_ASAN') == '1'
|
||||
self.asan_mode = asan_mode
|
||||
if self.asan_mode:
|
||||
_clang64_bin = r'D:\msys64\clang64\bin'
|
||||
if os.path.isdir(_clang64_bin):
|
||||
@@ -1573,7 +1574,7 @@ class Phase2Translator:
|
||||
cwd: str | None = None) -> subprocess.CompletedProcess:
|
||||
"""编译单个 .ll 为 obj。
|
||||
|
||||
ASan 模式(TPC_ASAN=1)下先对 IR 执行 opt 插桩:
|
||||
ASan 模式(--asan)下先对 IR 执行 opt 插桩:
|
||||
检测 stdlib 堆/栈/全局越界写与垃圾指针解引用(MemBuddy pool 内部
|
||||
由块尾 canary 覆盖,两者互补)。opt 失败返回其结果(returncode!=0)。
|
||||
|
||||
|
||||
Reference in new issue
Block a user