已关闭
[Bug-Report|缺陷反馈]: --mssanitizer 编译的算子未插桩,mssanitizer 四种检测工具实际失效 #5276
weihao18创建于  9月14日关闭于  9月15日
weihao18成员
9月14日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

使用 build.sh --mssanitizer 编译单算子,编译“成功”,但产出的 kernel .o 不含任何 sanitizer 插桩符号(0 个 __sanitizer_report_*,对照 --ops-compile-options -sanitizer 有 500 个),运行 mssanitizer 工具时:

  • racecheck / initcheck / synccheck:被静默忽略(运行时库打 WARN "not supported on the kernel that without `--cce-enable-sanitizer' compiler option, thus it's temporarily ignored")
  • memcheck:以降级模式工作(仅 GM 搬运指令的非法读写/非对齐检查,无调用栈、无泄漏检测),导致用户误以为编译链路正常

此外纯 --mssanitizer(不带 --ops-compile-options -g)时连 debug 符号都没有(.o 的 .debug_* 段为 0)。

Environment Information / 环境信息 (Mandatory / 必填)

  • 复现仓库:ops-transformer(master,commit 253df0330 附近及之前)
  • CANN 9.0.0(aarch64),SoC ascend910b,纯编译即可复现(无需 NPU)

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

bash build.sh --opkernel --soc=ascend910b --ops=moe_gating_top_k --mssanitizer

# 验证:0 个插桩符号,0 个 debug 段
nm build/binary/ascend910b/bin/moe_gating_top_k/*.o | grep -c __sanitizer_report   # -> 0
readelf -S build/binary/ascend910b/bin/moe_gating_top_k/*.o | grep -c '\.debug_'    # -> 0

# 对照(正常路径):500 个插桩符号 + 15 个 debug 段
bash build.sh --opkernel --soc=ascend910b --ops=moe_gating_top_k --ops-compile-options -sanitizer

根因(两层,任缺其一修复无效)

  1. prepare 阶段选项丢失:构建为两段式,adapt py(build/impl/dynamic/<op>.py)在 prepare 阶段按当时的 custom_compile_options.ini 固化编译选项。cmake/config.cmake 调 prepare.sh 时传了 --enable_oom 却未传 ENABLE_MSSANITIZER(prepare.sh 也不解析该参数),导致 --mssanitizer 的选项在 adapt py 生成前就已丢失;主阶段写回的 ini 不会被重新消费,直接 cat ini 看到的内容具有迷惑性。
  2. 选项拼写与 CANN 匹配不符:cmake/func.cmake 注入 --cce-enable-sanitizer(双横线,bisheng 层拼写),而 CANN 侧 is_enable_sanitizer 按 list 元素精确匹配 -sanitizer(单横线,算子工程层拼写),判定失败后不追加 -mllvm 配套、不链接 libsanitizer_stub_dav-c220-*.a——即使选项透传到 bisheng 也会链接失败(undefined symbol: __sanitizer_report_store)。

附带问题(同 PR 一并修复)

  • opdesc_parser._set_all_options_to_opdescs 对多行 ALL 配置直接赋值,后行覆盖前行:用户传 --ops-compile-options 会把 func.cmake 注入的行(含 -sanitizer、-DNOT_DYNAMIC_COMPILE 等)整行冲掉
  • --ops-compile-options=<value> / --op_debug_config=<value> 的 = 传值形式落入 *) 分支,静默打印 usage 退出(exit 1,无报错提示)
  • check_param 互斥检查只查变量组合:--oom --ops-compile-options -sanitizer 等组合可绕过 --mssanitizer 的互斥拦截
  • help 文案与实现不符:--oom 虚标 '-g --cce-enable-oom'(实际不带 -g),未标注互斥关系

Describe the expected behavior / 预期结果 (Mandatory / 必填)

--mssanitizer 与 --ops-compile-options -sanitizer 等价:.o 含数百个 __sanitizer_report_* weak 符号 + debug 段(自动带 -g),mssanitizer 四种工具(memcheck/racecheck/initcheck/synccheck)均正常检测。

如上

Special notes for this issue/备注 (Optional / 选填)

likedislike
Wweihao18成员
9月14日 添加了label:bug-report
Wweihao18成员
9月14日 将 weihao18 设为负责人
Wweihao18成员
9月14日 将 weihao18 设为负责人
游震成员
9月14日 评论:

/assign @weihao18

likedislike
CANN-robotCANN-robot成员
9月15日 关闭了 issue
CANN-robotCANN-robot成员
9月15日 添加了label:resolved