Repository navigation
binding/fortran: initialize sentinel common blocks in libmpifort - #8027
Open
hzhou-muse wants to merge 2 commits into
Open
hzhou-muse wants to merge 2 commits into
hzhou-muse wants to merge 2 commits into
Conversation
Generate mpifnoext.h next to mpif.h in mpif_h/, so that the f77 binding can include it. The mpi module adds mpif_h to its include path. Previously it was generated in use_mpi/ and only used by the mpi module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a BLOCK DATA in setbotf.f that initializes the common blocks holding the Fortran sentinels (MPI_IN_PLACE, MPI_BOTTOM, etc.), so libmpifort defines them as initialized data. GNU ld then resolves the common blocks of shared libraries that include mpif.h or use the mpi module to libmpifort's definitions instead of giving them private copies. Previously, such a library loaded with RTLD_DEEPBIND used its own copy, and MPICH did not recognize the sentinels it passed. Fixes pmodels#8020 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
test:mpich/ch3/tcp ✔️ 1 unrelated failure fixed in #8030 |
Collaborator
|
@eschnett Can you review? |
eschnett
reviewed
Oct 18, 2026
| ! | ||
| subroutine mpirinitf( ) | ||
| include 'mpif.h' | ||
| ! make sure the block data is linked, e.g. from a static library |
Collaborator
There was a problem hiding this comment.
I don't think that's how external is working. I don't think it's doing anything for linking. (Maybe it does, but only for some compilers?) Anyway, the block data definition is in the same file so it is linked anyway.
eschnett
approved these changes
Oct 18, 2026
eschnett
left a comment
Collaborator
There was a problem hiding this comment.
This looks good. I left a comment because I think one comment in the code is wrong, but not in a consequential way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description
The Fortran sentinels (
MPI_IN_PLACE,MPI_BOTTOM,MPI_STATUS_IGNORE, etc.) are recognized by the addresses of theMPIPRIV*/MPIFCMB*common blocks. These blocks were uninitialized, so they were in.bssinlibmpifort.so, and a shared library that includesmpif.h(or uses thempimodule) got its own private copy. When such a library is loaded withRTLD_DEEPBIND, it uses its own copy, and MPICH treatsMPI_IN_PLACEas a buffer (#8020).This PR adds a
BLOCK DATAinsetbotf.fthat initializes the blocks, solibmpifortdefines them in.data. GNU ld (bfd) then resolves the consumer's common blocks tolibmpifort(Uinstead of a privateB). TheBLOCK DATAincludesmpifnoext.h, so the block layout always matchesmpif.h.mpifnoext.hinmpif_h/instead ofuse_mpi/, so the f77 binding can include it.Tested with the reproducer from #8020 (stand-alone Fortran build against 5.1.0a1):
RTLD_DEEPBINDRTLD_DEEPBINDFixes #8020
Author Checklist
🤖 Generated with Claude Code