Dear Maintainer,
In mpich debian/rules, MPICHLIB_CPPFLAGS, MPICHLIB_CFLAGS, MPICHLIB_CXXFLAGS, MPICHLIB_FFLAGS, and MPICHLIB_FCFLAGS are exported for building internal MPICH libraries, while CPPFLAGS, CFLAGS, and CXXFLAGS are cleared when invoking configure to avoid leaking build flags into generated compiler wrappers.
However, build flags still leak into compiler wrappers and pkg-config via two paths:
1. LDFLAGS and Fortran flags in debian/rules:
- MPICHLIB_LDFLAGS is not exported.
- LDFLAGS is not cleared in dh_auto_configure, causing WRAPPER_LDFLAGS=$LDFLAGS to leak build flags into wrapper scripts.
- FFLAGS="$(FFLAGS)" FCFLAGS="$(FFLAGS)" passes full optimization and LTO flags into WRAPPER_FFLAGS/WRAPPER_FCFLAGS, leaking into mpifort.mpich.
2. MPL localdefs.in templates:
- src/mpl/localdefs.in (and related submodules) unconditionally appends @LDFLAGS@ to WRAPPER_LIBS ("$WRAPPER_LIBS @LDFLAGS@ @LIBS@"), leaking distro LDFLAGS directly into /usr/lib/*/pkgconfig/mpich.pc (Libs:).
In distributions enabling default LTO and linker metadata flags (such as Ubuntu 26.10), these flags leak into consumers. In particular, CMake FindMPI picks up "-flto=auto -ffat-lto-objects" and passes it to downstream builds as a compiler option, causing FTBFS in reverse dependencies (such as madness, LP: #2170321).
The attached patch resolves both issues:
- Exports MPICHLIB_LDFLAGS and passes LDFLAGS="" FFLAGS="$(GF_FLAGS)" FCFLAGS="$(GF_FLAGS)" to dh_auto_configure in debian/rules.
- Removes @LDFLAGS@ from WRAPPER_LIBS in MPL localdefs.in templates (mpl-isolate-ldflags.patch).
Best regards,
Viktor Pashaiev