Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Discussion: Fortran/C interface fixes surfaced by wasm ABI enforcement

未关闭
#6,005 21 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
活跃
技术栈
c, fortran, wasm
领域
api, build-system

调研方向

首先检查 emscripten-forge OpenBLAS recipe 中的下游补丁,然后检查 Fortran 接口声明、lapack-netlib/SRC,以及讨论中提到的由 LAPACKE 调用的子集。比较 wasm 和 native 构建中针对 strlen 以及 SUBROUTINE 返回类型的拟议更改;完成的标准是确定一致认可的 upstream 方向、可正常工作的 wasm ABI 检查,并且相关测试通过。

由索引模型根据 Issue 内容生成。

描述

Hi,

We maintain the emscripten build of OpenBLAS at emscripten-forge and are considering upstreaming a few patches, notably on matching the c/fortran interface with its calling conventions more precisely. Before opening PRs I'd like to initiate discussion here.

The main issue is that Wasm32 checks function signatures at call sites more strictly than native. Mismatched arity/types are hard errors at link or load time rather than being silently absorbed. This surfaces a Fortran/C interface mismatch: My understanding of it is that Fortran's ABI appends a hidden size_t string-length arg for each CHARACTER arg at the end of each function argument list. Native compilation and use tolerates C callers omitting those trailing args, causing the Fortran callee to read whatever garbage is in that register/stack slot. This may or may not produce issues, depending on whether that empty argument is actually used. Wasm, on the other hand, rejects the signature mismatch outright.

Patches we have downstream to overcome this are:

  1. Conditionally add, for builds that need it (such as wasm), the trailing size_t (dummy hidden strlen) arguments to the C-side declarations of BLAS/LAPACK interface functions that take Fortran CHARACTER args matching the "strlen at end" convention (LAPACK_FORTRAN_STRLEN_END). It seems likely difficult to activate this by default because downstream C consumers may all have to get rewritten then. But if it's activated it may be able to catch some bugs, e.g. if the string length argument is actually used by the fortran routine. It could get activated on CI, for example.

  2. Change return type of the SUBROUTINE-wrapping C prototypes from int to void, since flang expects SUBROUTINE to have no return value. A quick grep across the OpenBLAS tree (including the ~2000 f2c-derived files in lapack-netlib/SRC) showed zero internal callers that read the return value of a Fortran SUBROUTINE. It seems f2c did this for historic reasons but unsure. There is a potential risk for external callers reading that return int although it's garbage, but it seems thos callers shouldn't use return values anyway if it's just garbage returned.

  3. Same for a subset of LAPACK functions called from LAPACKE.

  4. Remove the #ifndef EMSCRIPTEN guard around #define LAPACK_FORTRAN_STRLEN_END, so it's defined for every target. The comment above already asserts this is the universally available convention.

More opinions on this would be great. We also have a few additional patches (mostly around testing and build workarounds), but the ones above seem most fundamental and are a good place to start. The diff for these may be large, but the changes themselves would be rather mechanical. One way to start would be to open a draft PR so that we can test.

Thoughts @martin-frbg ? Also tagging @ianthomas23 and @jjerphan who worked on this.

主要语言
C
星标
7.6k
派生
1.7k
平均合并
1 天 9 小时
30 天内合并 PR
44

环境准备

我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenMathLib/OpenBLAS 的其他 Issue

查看 OpenMathLib/OpenBLAS 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。