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 中的 downstream patches,接著檢查 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 天 6 小時
30 天內合併 PR
46

環境準備

我們還沒有檢查這個專案的環境設定檔。先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

OpenMathLib/OpenBLAS 的其他 Issue

查看 OpenMathLib/OpenBLAS 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。