Package: mpich
Version: 5.0.1-9
Severity: important
Tags: patch
User: [email protected]
Usertags: origin-ubuntu stonking

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
--- a/debian/patches/mpl-isolate-ldflags.patch	1970-01-01 01:00:00.000000000 +0100
+++ b/debian/patches/mpl-isolate-ldflags.patch	2026-10-10 17:00:00.000000000 +0200
@@ -0,0 +1,63 @@
+Description: Do not leak build LDFLAGS into WRAPPER_LIBS via MPL localdefs
+ MPL localdefs.in templates unconditionally appended @LDFLAGS@ into WRAPPER_LIBS,
+ causing distro build flags (e.g. -flto, --package-metadata) to leak into
+ mpich.pc and downstream builds.
+Author: Viktor Pashaiev <[email protected]>
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/mpich/+bug/2170321
+Last-Update: 2026-10-10
+
+--- a/src/mpl/localdefs.in	2026-10-10 18:22:43.003377612 +0200
++++ b/src/mpl/localdefs.in	2026-10-10 18:22:43.005377657 +0200
+@@ -6,7 +6,7 @@
+ GPU_SUPPORT="@GPU_SUPPORT@"
+ CPPFLAGS="@CPPFLAGS@"
+ MPL_CFLAGS="@MPL_CFLAGS@"
+-WRAPPER_LIBS="$WRAPPER_LIBS @LDFLAGS@ @LIBS@"
++WRAPPER_LIBS="$WRAPPER_LIBS @LIBS@"
+ RPATHS="$RPATHS @RPATHS@"
+ COMPILER_TLS="@COMPILER_TLS@"
+ MPL_SUMMARY_MESSAGE="@SUMMARY_MESSAGE@"
+--- a/src/pm/hydra/modules/mpl/localdefs.in	2026-10-10 18:22:43.011377791 +0200
++++ b/src/pm/hydra/modules/mpl/localdefs.in	2026-10-10 18:22:43.013377836 +0200
+@@ -6,7 +6,7 @@
+ GPU_SUPPORT="@GPU_SUPPORT@"
+ CPPFLAGS="@CPPFLAGS@"
+ MPL_CFLAGS="@MPL_CFLAGS@"
+-WRAPPER_LIBS="$WRAPPER_LIBS @LDFLAGS@ @LIBS@"
++WRAPPER_LIBS="$WRAPPER_LIBS @LIBS@"
+ RPATHS="$RPATHS @RPATHS@"
+ COMPILER_TLS="@COMPILER_TLS@"
+ MPL_SUMMARY_MESSAGE="@SUMMARY_MESSAGE@"
+--- a/src/mpi/romio/mpl/localdefs.in	2026-10-10 18:22:43.020377993 +0200
++++ b/src/mpi/romio/mpl/localdefs.in	2026-10-10 18:22:43.022378038 +0200
+@@ -6,7 +6,7 @@
+ GPU_SUPPORT="@GPU_SUPPORT@"
+ CPPFLAGS="@CPPFLAGS@"
+ MPL_CFLAGS="@MPL_CFLAGS@"
+-WRAPPER_LIBS="$WRAPPER_LIBS @LDFLAGS@ @LIBS@"
++WRAPPER_LIBS="$WRAPPER_LIBS @LIBS@"
+ RPATHS="$RPATHS @RPATHS@"
+ COMPILER_TLS="@COMPILER_TLS@"
+ MPL_SUMMARY_MESSAGE="@SUMMARY_MESSAGE@"
+--- a/src/pmi/mpl/localdefs.in	2026-10-10 18:22:43.029378195 +0200
++++ b/src/pmi/mpl/localdefs.in	2026-10-10 18:22:43.030378217 +0200
+@@ -6,7 +6,7 @@
+ GPU_SUPPORT="@GPU_SUPPORT@"
+ CPPFLAGS="@CPPFLAGS@"
+ MPL_CFLAGS="@MPL_CFLAGS@"
+-WRAPPER_LIBS="$WRAPPER_LIBS @LDFLAGS@ @LIBS@"
++WRAPPER_LIBS="$WRAPPER_LIBS @LIBS@"
+ RPATHS="$RPATHS @RPATHS@"
+ COMPILER_TLS="@COMPILER_TLS@"
+ MPL_SUMMARY_MESSAGE="@SUMMARY_MESSAGE@"
+--- a/src/pm/hydra/modules/pmi/mpl/localdefs.in	2026-10-10 18:22:43.037378375 +0200
++++ b/src/pm/hydra/modules/pmi/mpl/localdefs.in	2026-10-10 18:22:43.039378419 +0200
+@@ -6,7 +6,7 @@
+ GPU_SUPPORT="@GPU_SUPPORT@"
+ CPPFLAGS="@CPPFLAGS@"
+ MPL_CFLAGS="@MPL_CFLAGS@"
+-WRAPPER_LIBS="$WRAPPER_LIBS @LDFLAGS@ @LIBS@"
++WRAPPER_LIBS="$WRAPPER_LIBS @LIBS@"
+ RPATHS="$RPATHS @RPATHS@"
+ COMPILER_TLS="@COMPILER_TLS@"
+ MPL_SUMMARY_MESSAGE="@SUMMARY_MESSAGE@"
--- a/debian/patches/series	2026-08-30 13:41:08.000000000 +0200
+++ b/debian/patches/series	2026-10-10 17:00:00.000000000 +0200
@@ -1,2 +1,3 @@
 0002-autogen.sh-Avoid-debian-buggy-which-output.patch
 disable-checking-ext-modules.patch
+mpl-isolate-ldflags.patch
--- a/debian/rules	2026-08-30 13:41:08.000000000 +0200
+++ b/debian/rules	2026-10-10 17:00:00.000000000 +0200
@@ -14,6 +14,7 @@
 export MPICHLIB_CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
 export MPICHLIB_FFLAGS:=$(shell dpkg-buildflags --get FFLAGS) $(GF_FLAGS)
 export MPICHLIB_FCFLAGS:=$(shell dpkg-buildflags --get FFLAGS) -cpp $(GF_FLAGS)
+export MPICHLIB_LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)
 export FFLAGS:=$(shell dpkg-buildflags --get FFLAGS | sed -e 's/-g //') $(GF_FLAGS)
 export F77=f77
 export TZ=UTC+0
@@ -109,7 +110,7 @@
 	dh_autoreconf ./autogen.sh
 
 override_dh_auto_configure: $(AUTOGENERATED)
-	dh_auto_configure -- $(extra_flags) CPPFLAGS="" CFLAGS="" CXXFLAGS="" FFLAGS="$(FFLAGS)" FCFLAGS="$(FFLAGS)" BASH_SHELL=/bin/bash
+	dh_auto_configure -- $(extra_flags) CPPFLAGS="" CFLAGS="" CXXFLAGS="" LDFLAGS="" FFLAGS="$(GF_FLAGS)" FCFLAGS="$(GF_FLAGS)" BASH_SHELL=/bin/bash
 	dh_auto_configure --sourcedirectory src/pm/hydra -- --with-hwloc-prefix=/usr $(DEVICE) FFLAGS="$(FFLAGS)"
 	sed -r -i 's/ +-ffile-prefix-map=[^ ]+//g' src/env/mpifort.bash src/include/mpichinfo.h src/packaging/pkgconfig/mpich.pc src/pm/hydra/hydra_config.h

Reply via email to