登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
代码拉取完成,页面将自动刷新
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
34
Star
29
Fork
15
openKylin(孵化期)
/
qa
代码
Issues
207
Pull Requests
0
Wiki
统计
流水线
服务
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
openKylin 3.0 LLVM 22 wasm32-wasip1 运行时库路径不匹配,导致 wasm 链接失败
已确认
#IKQB2V
缺陷
秦凡东
创建于
2026-10-26 02:03
# Bug 报告:LLVM 22 wasm32-wasip1 运行时库路径不匹配,导致 wasm 链接失败 | 项目 | 内容 | |---|---| | 提交对象 | openKylin / `llvm-toolchain-22` | | 相关组件 | `clang-22`、`libclang-rt-22-dev-wasm32`、`libc++-22-dev-wasm32`、`libc++abi-22-dev-wasm32` | | 系统版本 | openKylin 3.0 (huanghe),x86_64 | | 严重程度 | 高(阻塞 Firefox ESR 153 以及所有 `wasm32-wasip1` 项目构建) | | 报告类型 | 打包错误 / 工具链兼容性问题 | --- ## 摘要 openKylin 3.0 的 `clang-22 1:22.1.2-ok4` 使用 `--target=wasm32-wasip1` 时,会在以下路径查找 wasm 运行时库: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 但 `libclang-rt-22-dev-wasm32 1:22.1.2-ok4` 只安装了旧布局: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a ``` 因此所有 `wasm32-wasip1` 的 C/C++ 链接都会失败。Debian 的 `clang-22 22.1.8` 在同样只安装旧布局的情况下可以正常链接(driver 会回退到旧布局),说明 openKylin 的 22.1.2 driver 缺少该回退逻辑,或者包内缺少新布局路径。 另外还发现一个独立问题:openKylin 的 wasm 版 `libc++.a` 是带异常构建,而 `libc++abi.a` 是 no-exceptions 构建,导致使用 `std::string`、`new/delete` 的 C++ wasm 程序出现 `__cxa_allocate_exception` / `__cxa_throw` 未定义符号。 --- ## 一、环境与版本 ```text openKylin 3.0 (huanghe) Linux X99-TF 7.0.0-3-generic #0ok1-KYLINOS SMP PREEMPT_DYNAMIC x86_64 clang-22 1:22.1.2-ok4 llvm-22 1:22.1.2-ok4 libclang-rt-22-dev-wasm32 1:22.1.2-ok4 libc++-22-dev-wasm32 1:22.1.2-ok4 libc++abi-22-dev-wasm32 1:22.1.2-ok4 wasi-libc 0.0~git20250726.3f7eb4c-ok1 clang 1:22.1.1-72-ok1 (meta) libclang-rt-dev-wasm32 1:22.1.1-72-ok1 (meta) libc++-dev-wasm32 1:22.1.1-72-ok1 (meta) ``` --- ## 二、问题现象 ### 2.1 主问题:`wasm32-wasip1` 链接找不到 builtins 最小 C 程序: ```c /* hello.c */ int main(void) { return 0; } ``` 编译并链接: ```bash clang --target=wasm32-wasip1 hello.c -o hello.wasm ``` 实际结果: ```text wasm-ld-22: error: cannot open /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` 同样的代码使用旧 target 可以成功: ```text $ clang --target=wasm32-wasi hello.c -o hello.wasm $ echo $? 0 ``` 使用 `-v` 可以看到 driver 的实际查找路径: ```text $ clang --target=wasm32-wasip1 -v hello.c -o hello.wasm ... "/bin/wasm-ld-22" -m wasm32 \ -L/usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1 \ -L/usr/lib/wasm32-wasip1 \ /usr/lib/wasm32-wasip1/crt1-command.o \ /tmp/hello-xxxx.o -lc \ /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a \ -o hello.wasm ``` 而 `libclang-rt-22-dev-wasm32` 实际只安装了旧路径: ```text $ dpkg -L libclang-rt-22-dev-wasm32 | grep builtins /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a ``` 路径对照: | 项目 | 路径 | |---|---| | clang 22.1.2 查找 | `/usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a` | | 包实际安装 | `/usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a` | #### 实际影响:Firefox ESR 153 构建失败 构建 Debian 的 `firefox-esr 153.5.1esr-1` 时,configure 阶段直接失败: ```text checking the wasm C compiler can find wasi headers... yes checking the wasm C compiler version... 22.1.2 checking the wasm C compiler works... yes checking the wasm C compiler can find wasi headers... yes ... checking the wasm C linker can find wasi libraries... DEBUG: Executing: `/usr/bin/clang --target=wasm32-wasip1 /tmp/conftestrak4u7np.c` DEBUG: The command returned non-zero exit status 1. DEBUG: Its error output was: DEBUG: | wasm-ld-22: error: cannot open /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a: No such file or directory DEBUG: | clang: error: linker command failed with exit code 1 (use -v to see invocation) ERROR: Cannot find wasi libraries or problem with the wasm linker. Please fix the problem. Or build with --without-wasm-sandboxed-libraries. ``` ### 2.2 关联问题:wasm 版 libc++ 与 libc++abi 异常配置不一致 即使按第 7 节临时补上 builtins 路径,C++ wasm 链接仍会失败: ```cpp // cxx.cc #include <string> int main() { std::string s = "x"; return (int)s.size(); } ``` 编译并链接: ```bash clang++ --target=wasm32-wasip1 -std=c++17 cxx.cc -o cxx.wasm ``` 实际结果: ```text wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_throw wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_throw clang++: error: linker command failed with exit code 1 ``` 这个问题与主问题独立。把 `--target` 换成旧的 `wasm32-wasi`(会有 deprecation warning),同样可以复现: ```text $ clang++ --target=wasm32-wasi -std=c++17 cxx.cc -o cxx.wasm clang++: warning: argument '--target=wasm32-wasi' is deprecated, use --target=wasm32-wasip1 instead wasm-ld-22: error: /usr/lib/wasm32-wasi/libc++.a(string.cpp.o): undefined symbol: __cxa_allocate_exception ... ``` --- ## 三、复现方法 ### 3.1 复现主问题 ```bash cat > hello.c <<'EOF' int main(void) { return 0; } EOF clang --target=wasm32-wasip1 hello.c -o hello.wasm ``` 实际结果: ```text wasm-ld-22: error: cannot open /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a: No such file or directory clang: error: linker command failed with exit code 1 ``` 期望结果:生成 `hello.wasm`,退出码 0。 ### 3.2 复现关联问题 先按第 7 节补上 builtins 路径(或直接使用旧 target `wasm32-wasi`),然后: ```bash cat > cxx.cc <<'EOF' #include <string> int main() { std::string s = "x"; return (int)s.size(); } EOF clang++ --target=wasm32-wasip1 -std=c++17 cxx.cc -o cxx.wasm ``` 实际结果: ```text wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_throw wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_throw clang++: error: linker command failed with exit code 1 ``` 期望结果:生成 `cxx.wasm`,退出码 0。 --- ## 四、分析 ### 4.1 主问题分析 LLVM 22.1 将 wasm 的 target 从 `wasm32-wasi` 改名为 `wasm32-wasip1`。clang 22.1.2 在计算 compiler-rt 路径时,按新 target triple 到以下目录查找: ```text <resource-dir>/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 但 `libclang-rt-22-dev-wasm32 22.1.2-ok4` 仍按旧布局安装: ```text <resource-dir>/lib/wasi/libclang_rt.builtins-wasm32.a ``` 因此新的 `wasm32-wasip1` target 找不到 builtins;旧 target `wasm32-wasi` 由于仍映射到旧目录,可以正常工作。 #### 与 Debian 22.1.8 的对比 下载 Debian sid 的 `llvm-toolchain-22 1:22.1.8-3` 后验证: - Debian 的 `libclang-rt-22-dev-wasm32 1:22.1.8-3` **同样只安装** `lib/wasi/libclang_rt.builtins-wasm32.a`; - 但 Debian 的 `clang-22 22.1.8` 可以成功链接: ```text "/bin/wasm-ld-22" -m wasm32 -L/usr/lib/wasm32-wasip1 ... -lc \ /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a \ -o db.wasm exit=0 ``` 原因:Debian 的 22.1.8 驱动在找不到新布局时,会回退到旧布局(`ToolChain::getCompilerRT` 会检查旧路径下带 `-wasm32` 后缀的 builtins)。openKylin 的 22.1.2 没有这个回退行为。 #### 结论 - 直接原因:`libclang-rt-22-dev-wasm32` 缺少新布局路径,而 clang 22.1.2 又不会回退到旧布局。 - 长期原因:openKylin 的 clang 22.1.2 缺少上游后续版本加入的旧布局兼容逻辑。 - 修复可以从“补包内路径”或“升级/backport driver”任一方向做,最好两者都做。 ### 4.2 关联问题分析 检查 wasm 版 C++ 运行库: ```text $ ar t /usr/lib/llvm-22/lib/wasm32-wasi/libc++abi.a | grep cxa_ cxa_noexception.cpp.o ``` `libc++abi.a` 是 no-exceptions 构建,不包含 `cxa_exception.cpp.o`,因此没有 `__cxa_allocate_exception`、`__cxa_throw` 等符号。 但 `libc++.a` 是带异常构建的: ```text $ llvm-nm -A /usr/lib/llvm-22/lib/wasm32-wasi/libc++.a | grep -c ' U __cxa_allocate_exception' 15 $ llvm-nm -A /usr/lib/llvm-22/lib/wasm32-wasi/libc++.a | grep -c ' U __cxa_throw' 15 ``` `std::string` 会拉入 `string.cpp.o`,其中引用了 `__cxa_throw`;`new/delete` 会拉入 `stdlib_new_delete.cpp.o`,同样引用 `__cxa_allocate_exception`,于是链接失败。 对比 Debian 22.1.8: ```text Debian 22.1.8 的 libc++.a:0 处 U __cxa_allocate_exception Debian 22.1.8 的 libc++.a:0 处 U __cxa_throw ``` Debian 的 wasm libc++ 与 libc++abi 都按 no-exceptions 构建,两者一致;openKylin 的 libc++ 开启了异常,而 libc++abi 关闭了异常,配置不一致。 #### 结论 `libc++-22-dev-wasm32` 与 `libc++abi-22-dev-wasm32` 的异常配置必须保持一致。按 wasi-sdk/Debian 的做法,应统一为 no-exceptions(或者两边都启用异常并补齐 runtime)。 --- ## 五、影响范围 1. **Firefox ESR 153 构建失败**:`firefox-esr 153.5.1esr-1` 的 configure 在 wasm 链接检查阶段直接退出。 2. **所有 `--target=wasm32-wasip1` 项目**:C/C++ 程序都无法链接。 3. **C++ wasm 库**:Firefox 的 wasm sandbox 库包含 `graphite`、`hunspell`、`woff2`、`soundtouch` 等 C++ 库,即使绕过 builtins 问题,仍会因 `__cxa_*` 缺失而失败。 4. **使用 `libc++-dev-wasm32` 的交叉编译场景**:只要用到 `std::string`、`new/delete` 或异常相关代码,就会链接失败。 --- ## 六、修复建议 ### 6.1 主问题:builtins 路径 #### 短期(打包修复,建议尽快做) 在 `libclang-rt-22-dev-wasm32` 中同时提供新布局路径,指向现有旧文件即可: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a -> ../wasi/libclang_rt.builtins-wasm32.a ``` 打包时增加一个相对符号链接: ```bash ln -s ../wasi/libclang_rt.builtins-wasm32.a \ /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 同时保留旧路径: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a ``` 以继续兼容 `--target=wasm32-wasi`。 #### 长期(driver 修复) 升级 `clang-22`/`llvm-22` 到 22.1.8 或更新版本(该版本包含旧布局回退逻辑),或者 backport 上游 `ToolChain::getCompilerRT` 中“新布局找不到时回退到旧布局”的补丁。这样即使包内只有旧路径,`wasm32-wasip1` 也能正常工作。 #### 回归测试 在包构建或 CI 中增加: ```bash clang --target=wasm32-wasip1 hello.c -o hello.wasm clang --target=wasm32-wasi hello.c -o hello_old.wasm ``` ### 6.2 关联问题:libc++ 异常配置 建议统一 wasm 版 libc++ 与 libc++abi 的异常配置: - **方案 A(推荐,与 Debian/wasi-sdk 一致)**:两者都按 no-exceptions 构建。即 `libc++` 使用 `-fno-exceptions` / `LIBCXX_ENABLE_EXCEPTIONS=OFF`,确保 `libc++.a` 不再引用 `__cxa_allocate_exception`、`__cxa_throw`。 - **方案 B**:两者都启用异常,`libc++abi` 需要包含 `cxa_exception.cpp.o` 并提供完整的 `__cxa_*` 运行时。 回归测试: ```bash clang++ --target=wasm32-wasip1 -std=c++17 cxx.cc -o cxx.wasm ``` 应能成功链接使用 `std::string` 的最小程序。 ### 6.3 建议的 issue 拆分 - **Bug 1**:`libclang-rt-22-dev-wasm32` 的 `wasm32-wasip1` builtins 路径缺失(主问题)。 - **Bug 2**:`libc++-22-dev-wasm32` 与 `libc++abi-22-dev-wasm32` 异常配置不一致(关联问题)。 如果只提交一个 issue,可将本报告第 2.2 节作为“附加发现”一并附上。 --- ## 七、临时规避方法 ### 7.1 规避主问题 手动补符号链接(需要 root): ```bash mkdir -p /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1 ln -sf ../wasi/libclang_rt.builtins-wasm32.a \ /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 验证: ```bash clang --target=wasm32-wasip1 hello.c -o hello.wasm # 退出码 0,生成 WebAssembly 文件 ``` Firefox 构建中也可通过 mozconfig 绕过 wasm 检查: ```text ac_add_options --without-wasm-sandboxed-libraries ``` ### 7.2 规避关联问题 目前没有干净的包内规避方法。可选: - 不使用 C++ 编写 wasm 库; - 使用一个完整、自洽的 wasi-sdk,通过 `--with-wasi-sysroot=/path/to/wasi-sdk` 指定; - 等待 `libc++-22-dev-wasm32` 修复。 --- ## 八、附件与补充信息 建议随 issue 附上: 1. 第 2.1、2.2 节的完整命令输出。 2. `dpkg -L libclang-rt-22-dev-wasm32` 输出。 3. `ar t /usr/lib/llvm-22/lib/wasm32-wasi/libc++abi.a | grep cxa_` 输出。 4. `llvm-nm` 统计结果(openKylin 15 处 vs Debian 0 处)。 5. Firefox `build-browser/config.log` 中 `wasm C linker` 相关片段。 6. 如有条件,附上 Debian 22.1.8 的回退行为对比(证明 driver 修复的可行性)。 --- ## 附:本报告中的关键路径与版本汇总 ```text clang 查找路径(新布局): /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a 包实际安装路径(旧布局): /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a wasm libc++: /usr/lib/llvm-22/lib/wasm32-wasi/libc++.a /usr/lib/wasm32-wasip1/libc++.a -> ../llvm-22/lib/wasm32-wasi/libc++.a wasm libc++abi: /usr/lib/llvm-22/lib/wasm32-wasi/libc++abi.a /usr/lib/wasm32-wasip1/libc++abi.a -> ../llvm-22/lib/wasm32-wasi/libc++abi.a ``` 相关包版本: ```text clang-22 1:22.1.2-ok4 llvm-22 1:22.1.2-ok4 libclang-rt-22-dev-wasm32 1:22.1.2-ok4 libc++-22-dev-wasm32 1:22.1.2-ok4 libc++abi-22-dev-wasm32 1:22.1.2-ok4 wasi-libc 0.0~git20250726.3f7eb4c-ok1 ``` --- **备注**:报告中的“Debian 22.1.8 可回退”是实测结果:提取 Debian 的 `clang-22 1:22.1.8-3` 与 `libclang-rt-22-dev-wasm32 1:22.1.8-3` 后,`--target=wasm32-wasip1` 能成功链接到 `lib/wasi/libclang_rt.builtins-wasm32.a`;openKylin 的 22.1.2 则不会回退。建议 openKylin 维护者对照上游 `ToolChain::getCompilerRT` 的相关改动进行升级或 backport。
# Bug 报告:LLVM 22 wasm32-wasip1 运行时库路径不匹配,导致 wasm 链接失败 | 项目 | 内容 | |---|---| | 提交对象 | openKylin / `llvm-toolchain-22` | | 相关组件 | `clang-22`、`libclang-rt-22-dev-wasm32`、`libc++-22-dev-wasm32`、`libc++abi-22-dev-wasm32` | | 系统版本 | openKylin 3.0 (huanghe),x86_64 | | 严重程度 | 高(阻塞 Firefox ESR 153 以及所有 `wasm32-wasip1` 项目构建) | | 报告类型 | 打包错误 / 工具链兼容性问题 | --- ## 摘要 openKylin 3.0 的 `clang-22 1:22.1.2-ok4` 使用 `--target=wasm32-wasip1` 时,会在以下路径查找 wasm 运行时库: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 但 `libclang-rt-22-dev-wasm32 1:22.1.2-ok4` 只安装了旧布局: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a ``` 因此所有 `wasm32-wasip1` 的 C/C++ 链接都会失败。Debian 的 `clang-22 22.1.8` 在同样只安装旧布局的情况下可以正常链接(driver 会回退到旧布局),说明 openKylin 的 22.1.2 driver 缺少该回退逻辑,或者包内缺少新布局路径。 另外还发现一个独立问题:openKylin 的 wasm 版 `libc++.a` 是带异常构建,而 `libc++abi.a` 是 no-exceptions 构建,导致使用 `std::string`、`new/delete` 的 C++ wasm 程序出现 `__cxa_allocate_exception` / `__cxa_throw` 未定义符号。 --- ## 一、环境与版本 ```text openKylin 3.0 (huanghe) Linux X99-TF 7.0.0-3-generic #0ok1-KYLINOS SMP PREEMPT_DYNAMIC x86_64 clang-22 1:22.1.2-ok4 llvm-22 1:22.1.2-ok4 libclang-rt-22-dev-wasm32 1:22.1.2-ok4 libc++-22-dev-wasm32 1:22.1.2-ok4 libc++abi-22-dev-wasm32 1:22.1.2-ok4 wasi-libc 0.0~git20250726.3f7eb4c-ok1 clang 1:22.1.1-72-ok1 (meta) libclang-rt-dev-wasm32 1:22.1.1-72-ok1 (meta) libc++-dev-wasm32 1:22.1.1-72-ok1 (meta) ``` --- ## 二、问题现象 ### 2.1 主问题:`wasm32-wasip1` 链接找不到 builtins 最小 C 程序: ```c /* hello.c */ int main(void) { return 0; } ``` 编译并链接: ```bash clang --target=wasm32-wasip1 hello.c -o hello.wasm ``` 实际结果: ```text wasm-ld-22: error: cannot open /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` 同样的代码使用旧 target 可以成功: ```text $ clang --target=wasm32-wasi hello.c -o hello.wasm $ echo $? 0 ``` 使用 `-v` 可以看到 driver 的实际查找路径: ```text $ clang --target=wasm32-wasip1 -v hello.c -o hello.wasm ... "/bin/wasm-ld-22" -m wasm32 \ -L/usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1 \ -L/usr/lib/wasm32-wasip1 \ /usr/lib/wasm32-wasip1/crt1-command.o \ /tmp/hello-xxxx.o -lc \ /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a \ -o hello.wasm ``` 而 `libclang-rt-22-dev-wasm32` 实际只安装了旧路径: ```text $ dpkg -L libclang-rt-22-dev-wasm32 | grep builtins /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a ``` 路径对照: | 项目 | 路径 | |---|---| | clang 22.1.2 查找 | `/usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a` | | 包实际安装 | `/usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a` | #### 实际影响:Firefox ESR 153 构建失败 构建 Debian 的 `firefox-esr 153.5.1esr-1` 时,configure 阶段直接失败: ```text checking the wasm C compiler can find wasi headers... yes checking the wasm C compiler version... 22.1.2 checking the wasm C compiler works... yes checking the wasm C compiler can find wasi headers... yes ... checking the wasm C linker can find wasi libraries... DEBUG: Executing: `/usr/bin/clang --target=wasm32-wasip1 /tmp/conftestrak4u7np.c` DEBUG: The command returned non-zero exit status 1. DEBUG: Its error output was: DEBUG: | wasm-ld-22: error: cannot open /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a: No such file or directory DEBUG: | clang: error: linker command failed with exit code 1 (use -v to see invocation) ERROR: Cannot find wasi libraries or problem with the wasm linker. Please fix the problem. Or build with --without-wasm-sandboxed-libraries. ``` ### 2.2 关联问题:wasm 版 libc++ 与 libc++abi 异常配置不一致 即使按第 7 节临时补上 builtins 路径,C++ wasm 链接仍会失败: ```cpp // cxx.cc #include <string> int main() { std::string s = "x"; return (int)s.size(); } ``` 编译并链接: ```bash clang++ --target=wasm32-wasip1 -std=c++17 cxx.cc -o cxx.wasm ``` 实际结果: ```text wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_throw wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_throw clang++: error: linker command failed with exit code 1 ``` 这个问题与主问题独立。把 `--target` 换成旧的 `wasm32-wasi`(会有 deprecation warning),同样可以复现: ```text $ clang++ --target=wasm32-wasi -std=c++17 cxx.cc -o cxx.wasm clang++: warning: argument '--target=wasm32-wasi' is deprecated, use --target=wasm32-wasip1 instead wasm-ld-22: error: /usr/lib/wasm32-wasi/libc++.a(string.cpp.o): undefined symbol: __cxa_allocate_exception ... ``` --- ## 三、复现方法 ### 3.1 复现主问题 ```bash cat > hello.c <<'EOF' int main(void) { return 0; } EOF clang --target=wasm32-wasip1 hello.c -o hello.wasm ``` 实际结果: ```text wasm-ld-22: error: cannot open /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a: No such file or directory clang: error: linker command failed with exit code 1 ``` 期望结果:生成 `hello.wasm`,退出码 0。 ### 3.2 复现关联问题 先按第 7 节补上 builtins 路径(或直接使用旧 target `wasm32-wasi`),然后: ```bash cat > cxx.cc <<'EOF' #include <string> int main() { std::string s = "x"; return (int)s.size(); } EOF clang++ --target=wasm32-wasip1 -std=c++17 cxx.cc -o cxx.wasm ``` 实际结果: ```text wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++abi.a(stdlib_new_delete.cpp.o): undefined symbol: __cxa_throw wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_allocate_exception wasm-ld-22: error: /usr/lib/wasm32-wasip1/libc++.a(string.cpp.o): undefined symbol: __cxa_throw clang++: error: linker command failed with exit code 1 ``` 期望结果:生成 `cxx.wasm`,退出码 0。 --- ## 四、分析 ### 4.1 主问题分析 LLVM 22.1 将 wasm 的 target 从 `wasm32-wasi` 改名为 `wasm32-wasip1`。clang 22.1.2 在计算 compiler-rt 路径时,按新 target triple 到以下目录查找: ```text <resource-dir>/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 但 `libclang-rt-22-dev-wasm32 22.1.2-ok4` 仍按旧布局安装: ```text <resource-dir>/lib/wasi/libclang_rt.builtins-wasm32.a ``` 因此新的 `wasm32-wasip1` target 找不到 builtins;旧 target `wasm32-wasi` 由于仍映射到旧目录,可以正常工作。 #### 与 Debian 22.1.8 的对比 下载 Debian sid 的 `llvm-toolchain-22 1:22.1.8-3` 后验证: - Debian 的 `libclang-rt-22-dev-wasm32 1:22.1.8-3` **同样只安装** `lib/wasi/libclang_rt.builtins-wasm32.a`; - 但 Debian 的 `clang-22 22.1.8` 可以成功链接: ```text "/bin/wasm-ld-22" -m wasm32 -L/usr/lib/wasm32-wasip1 ... -lc \ /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a \ -o db.wasm exit=0 ``` 原因:Debian 的 22.1.8 驱动在找不到新布局时,会回退到旧布局(`ToolChain::getCompilerRT` 会检查旧路径下带 `-wasm32` 后缀的 builtins)。openKylin 的 22.1.2 没有这个回退行为。 #### 结论 - 直接原因:`libclang-rt-22-dev-wasm32` 缺少新布局路径,而 clang 22.1.2 又不会回退到旧布局。 - 长期原因:openKylin 的 clang 22.1.2 缺少上游后续版本加入的旧布局兼容逻辑。 - 修复可以从“补包内路径”或“升级/backport driver”任一方向做,最好两者都做。 ### 4.2 关联问题分析 检查 wasm 版 C++ 运行库: ```text $ ar t /usr/lib/llvm-22/lib/wasm32-wasi/libc++abi.a | grep cxa_ cxa_noexception.cpp.o ``` `libc++abi.a` 是 no-exceptions 构建,不包含 `cxa_exception.cpp.o`,因此没有 `__cxa_allocate_exception`、`__cxa_throw` 等符号。 但 `libc++.a` 是带异常构建的: ```text $ llvm-nm -A /usr/lib/llvm-22/lib/wasm32-wasi/libc++.a | grep -c ' U __cxa_allocate_exception' 15 $ llvm-nm -A /usr/lib/llvm-22/lib/wasm32-wasi/libc++.a | grep -c ' U __cxa_throw' 15 ``` `std::string` 会拉入 `string.cpp.o`,其中引用了 `__cxa_throw`;`new/delete` 会拉入 `stdlib_new_delete.cpp.o`,同样引用 `__cxa_allocate_exception`,于是链接失败。 对比 Debian 22.1.8: ```text Debian 22.1.8 的 libc++.a:0 处 U __cxa_allocate_exception Debian 22.1.8 的 libc++.a:0 处 U __cxa_throw ``` Debian 的 wasm libc++ 与 libc++abi 都按 no-exceptions 构建,两者一致;openKylin 的 libc++ 开启了异常,而 libc++abi 关闭了异常,配置不一致。 #### 结论 `libc++-22-dev-wasm32` 与 `libc++abi-22-dev-wasm32` 的异常配置必须保持一致。按 wasi-sdk/Debian 的做法,应统一为 no-exceptions(或者两边都启用异常并补齐 runtime)。 --- ## 五、影响范围 1. **Firefox ESR 153 构建失败**:`firefox-esr 153.5.1esr-1` 的 configure 在 wasm 链接检查阶段直接退出。 2. **所有 `--target=wasm32-wasip1` 项目**:C/C++ 程序都无法链接。 3. **C++ wasm 库**:Firefox 的 wasm sandbox 库包含 `graphite`、`hunspell`、`woff2`、`soundtouch` 等 C++ 库,即使绕过 builtins 问题,仍会因 `__cxa_*` 缺失而失败。 4. **使用 `libc++-dev-wasm32` 的交叉编译场景**:只要用到 `std::string`、`new/delete` 或异常相关代码,就会链接失败。 --- ## 六、修复建议 ### 6.1 主问题:builtins 路径 #### 短期(打包修复,建议尽快做) 在 `libclang-rt-22-dev-wasm32` 中同时提供新布局路径,指向现有旧文件即可: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a -> ../wasi/libclang_rt.builtins-wasm32.a ``` 打包时增加一个相对符号链接: ```bash ln -s ../wasi/libclang_rt.builtins-wasm32.a \ /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 同时保留旧路径: ```text /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a ``` 以继续兼容 `--target=wasm32-wasi`。 #### 长期(driver 修复) 升级 `clang-22`/`llvm-22` 到 22.1.8 或更新版本(该版本包含旧布局回退逻辑),或者 backport 上游 `ToolChain::getCompilerRT` 中“新布局找不到时回退到旧布局”的补丁。这样即使包内只有旧路径,`wasm32-wasip1` 也能正常工作。 #### 回归测试 在包构建或 CI 中增加: ```bash clang --target=wasm32-wasip1 hello.c -o hello.wasm clang --target=wasm32-wasi hello.c -o hello_old.wasm ``` ### 6.2 关联问题:libc++ 异常配置 建议统一 wasm 版 libc++ 与 libc++abi 的异常配置: - **方案 A(推荐,与 Debian/wasi-sdk 一致)**:两者都按 no-exceptions 构建。即 `libc++` 使用 `-fno-exceptions` / `LIBCXX_ENABLE_EXCEPTIONS=OFF`,确保 `libc++.a` 不再引用 `__cxa_allocate_exception`、`__cxa_throw`。 - **方案 B**:两者都启用异常,`libc++abi` 需要包含 `cxa_exception.cpp.o` 并提供完整的 `__cxa_*` 运行时。 回归测试: ```bash clang++ --target=wasm32-wasip1 -std=c++17 cxx.cc -o cxx.wasm ``` 应能成功链接使用 `std::string` 的最小程序。 ### 6.3 建议的 issue 拆分 - **Bug 1**:`libclang-rt-22-dev-wasm32` 的 `wasm32-wasip1` builtins 路径缺失(主问题)。 - **Bug 2**:`libc++-22-dev-wasm32` 与 `libc++abi-22-dev-wasm32` 异常配置不一致(关联问题)。 如果只提交一个 issue,可将本报告第 2.2 节作为“附加发现”一并附上。 --- ## 七、临时规避方法 ### 7.1 规避主问题 手动补符号链接(需要 root): ```bash mkdir -p /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1 ln -sf ../wasi/libclang_rt.builtins-wasm32.a \ /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a ``` 验证: ```bash clang --target=wasm32-wasip1 hello.c -o hello.wasm # 退出码 0,生成 WebAssembly 文件 ``` Firefox 构建中也可通过 mozconfig 绕过 wasm 检查: ```text ac_add_options --without-wasm-sandboxed-libraries ``` ### 7.2 规避关联问题 目前没有干净的包内规避方法。可选: - 不使用 C++ 编写 wasm 库; - 使用一个完整、自洽的 wasi-sdk,通过 `--with-wasi-sysroot=/path/to/wasi-sdk` 指定; - 等待 `libc++-22-dev-wasm32` 修复。 --- ## 八、附件与补充信息 建议随 issue 附上: 1. 第 2.1、2.2 节的完整命令输出。 2. `dpkg -L libclang-rt-22-dev-wasm32` 输出。 3. `ar t /usr/lib/llvm-22/lib/wasm32-wasi/libc++abi.a | grep cxa_` 输出。 4. `llvm-nm` 统计结果(openKylin 15 处 vs Debian 0 处)。 5. Firefox `build-browser/config.log` 中 `wasm C linker` 相关片段。 6. 如有条件,附上 Debian 22.1.8 的回退行为对比(证明 driver 修复的可行性)。 --- ## 附:本报告中的关键路径与版本汇总 ```text clang 查找路径(新布局): /usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a 包实际安装路径(旧布局): /usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a wasm libc++: /usr/lib/llvm-22/lib/wasm32-wasi/libc++.a /usr/lib/wasm32-wasip1/libc++.a -> ../llvm-22/lib/wasm32-wasi/libc++.a wasm libc++abi: /usr/lib/llvm-22/lib/wasm32-wasi/libc++abi.a /usr/lib/wasm32-wasip1/libc++abi.a -> ../llvm-22/lib/wasm32-wasi/libc++abi.a ``` 相关包版本: ```text clang-22 1:22.1.2-ok4 llvm-22 1:22.1.2-ok4 libclang-rt-22-dev-wasm32 1:22.1.2-ok4 libc++-22-dev-wasm32 1:22.1.2-ok4 libc++abi-22-dev-wasm32 1:22.1.2-ok4 wasi-libc 0.0~git20250726.3f7eb4c-ok1 ``` --- **备注**:报告中的“Debian 22.1.8 可回退”是实测结果:提取 Debian 的 `clang-22 1:22.1.8-3` 与 `libclang-rt-22-dev-wasm32 1:22.1.8-3` 后,`--target=wasm32-wasip1` 能成功链接到 `lib/wasi/libclang_rt.builtins-wasm32.a`;openKylin 的 22.1.2 则不会回退。建议 openKylin 维护者对照上游 `ToolChain::getCompilerRT` 的相关改动进行升级或 backport。
评论 (
0
)
登录
后才可以发表评论
状态
已确认
待确认
已确认
待评审
修复中
已修复
已验收
已发布
CND
确认评审关闭
已关闭
负责人
未设置
luoyaoming
luoyaoming
负责人
协作者
+负责人
+协作者
郝思伟
hjmdl
负责人
协作者
+负责人
+协作者
李伟南
luckyliwn
负责人
协作者
+负责人
+协作者
标签
bug
未设置
项目
未立项任务
未立项任务
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(3)
1
https://gitee.com/openkylin/qa.git
git@gitee.com:openkylin/qa.git
openkylin
qa
qa
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册