已合并
[feat] support environment variable LD_PRELOAD #34371
liujunzhu创建于 4月25日
[feat] support environment variable LD_PRELOAD #34371
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 liujunzhu 的贡献)ascend-robot
4月25日 评论:
4月25日 评论:
ascend-robot
4月25日 评论:
4月25日 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/pytorch | ✅ chujinjin, hbhu_bin (2/2) | ✅ chujinjin (1/1) |
| test | ✅ chujinjin, hbhu_bin (2/2) | ✅ chujinjin (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
liujunzhu, thanks for your pull request. All authors of the commits have signed the CLA. 👍


4月25日 添加了label:ascend-cla/yes
ascend-robot
4月25日 评论:
4月25日 评论:
当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.10.0 | ||
| v2.11.0 | ||
| v2.7.1 | ||
| v2.9.0 | ||
| v2.8.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


liujunzhu
4月25日 评论:
4月25日 评论:
compile


4月25日 添加了label:ci-pipeline-running
4月25日 删除了label:ci-pipeline-running
4月25日 添加了label:ci-pipeline-passed
ascend-robot
4月25日 评论:
4月25日 评论:
流水线 PR-pipeline_pytorch#17236 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_DIST_X86_Part_01 | 🛑 | >>> | |
| UT_DIST_X86_Part_02 | 🛑 | >>> | |
| UT_DIST_X86_Part_03 | 🛑 | >>> | |
| UT_DIST_X86_Part_04 | 🛑 | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


4月27日 修改标题为 “[feat] support environment variable LD_PRELOAD”,原标题为“support environment variable LD_PRELOAD”
4月27日 修改标题为 “[feat] support environment variable LD_PRELOAD”,原标题为“support environment variable LD_PRELOAD”
4月27日 修改了pull request 的描述
liujunzhu
4月27日 评论:
4月27日 评论:
add_component


4月27日 添加了label:MindSpore-Component
4月27日 添加了label:approvedlgtm
ascend-robot
4月27日 评论:
4月27日 评论:
4月27日 合入了pull request
5月6日 关联了issue:[Feature]: support environment variable LD_PRELOAD
【合入来源】
【修改方案】
用户自实现
aclrtMallocAlign32等 ACL 符号并打包成.so,通过LD_PRELOAD注入 torch_npu 进程,期望拦截对 ACL 函数的调用,但实际未被调用。根因:torch_npu 中部分 ACL 函数(如
aclrtMallocAlign32、aclrtFreePhysical)通过FunctionLoader::Get()使用dlsym(handle, name)查找符号,该方式限定在 handle 对应的库中查找,不搜索 LD_PRELOAD 预加载的库,导致覆盖失效。而直接链接调用的 ACL 符号(如aclrtFree)走 PLT 全局符号解析,天然支持 LD_PRELOAD。修改方案:
FunctionLoader::Get()方法,当LD_PRELOAD环境变量非空时,优先通过dlsym(RTLD_DEFAULT, name)在全局符号表中查找函数,使 LD_PRELOAD 注入的同名符号可被命中;未命中时回落原有dlopen + dlsym(handle)路径。LD_PRELOAD非空作为门控条件,未设置时完全走旧路径,行为与修改前一致。torch_npu/csrc/core/npu/register/FunctionLoader.cpp,不新增头文件、不改变调用方。【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
测试场景:通过
LD_PRELOAD注入自定义aclrtMallocAlign32实现,验证 FunctionLoader 路径的符号可被覆盖。测试方法:子进程隔离测试,每个用例在独立子进程中设置不同
LD_PRELOAD环境变量。aclrtMallocAlign32被 hook 拦截新增测试文件:
test/npu/test_ld_preload_acl_hook.py。【CheckList】