Discussion: Fortran/C interface fixes surfaced by wasm ABI enforcement
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- À clarifier
- Activité
- Active
- Stack technique
- c, fortran, wasm
- Domaine
- api, build-system
Piste de recherche
Commencez par examiner les patches aval dans la recette emscripten-forge OpenBLAS, puis inspectez les déclarations d’interface Fortran, lapack-netlib/SRC et le sous-ensemble appelé par LAPACKE mentionné dans la discussion. Comparez les changements proposés pour strlen et les types de retour de SUBROUTINE entre les builds wasm et natifs ; le travail sera considéré comme terminé lorsqu’une orientation upstream aura été convenue, que les vérifications de l’ABI wasm fonctionneront et que les tests pertinents passeront.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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:
-
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.
-
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.
-
Same for a subset of LAPACK functions called from LAPACKE.
-
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.
- Langage dominant
- C
- Étoiles
- 7.6k
- Forks
- 1.7k
- Merge moyen
- 1 j 9 h
- PR mergées (30 j)
- 44
Préparer son environnement
Nous n'avons pas encore vérifié les fichiers d'installation de ce projet. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de OpenMathLib/OpenBLAS
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
OpenMathLib/OpenBLAS#6062 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Missing cgroup awarenessOuverte
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
OpenMathLib/OpenBLAS#6059 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
OpenMathLib/OpenBLAS#6029 · 21 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
OpenMathLib/OpenBLAS#6028 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
OpenMathLib/OpenBLAS#5930 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de OpenMathLib/OpenBLAS
Issues similaires
-
bug needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
netdata/netdata#24062 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
riscv-software-src/riscv-isa-sim#2448 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 75/100
NabuCasa/silabs-firmware-builder#231 · 1 commentaire ·