Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#6,005 21 comentarios 2 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Activo
Stack tecnológico
c, fortran, wasm
Área
api, build-system

Línea de trabajo

Empieza revisando los parches posteriores en la receta de emscripten-forge OpenBLAS y, después, inspecciona las declaraciones de interfaz de Fortran, lapack-netlib/SRC y el subconjunto invocado por LAPACKE mencionado en la discusión. Compara los cambios propuestos en strlen y en los tipos de retorno de SUBROUTINE entre las compilaciones wasm y nativas; el trabajo estará terminado cuando exista una dirección acordada para upstream, funcionen las comprobaciones de la ABI de wasm y pasen las pruebas pertinentes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C
Estrellas
7.6k
Forks
1.7k
Merge medio
1 d 9 h
PR fusionados (30 d)
44

Preparar el entorno

Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenMathLib/OpenBLAS

Todos los issues de OpenMathLib/OpenBLAS

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.