Bug#1049903: petsc: misbuild with gcc-13

Steve Langasek steve.langasek at canonical.com
Wed Aug 16 17:49:24 BST 2023


Package: petsc
Version: 3.18.6+dfsg1-1
Severity: serious
Tags: patch
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu mantic ubuntu-patch

Dear maintainers,

A no-change rebuild of petsc in Ubuntu for a libamd transition resulted in a
libpetsc64_complex that was missing linkage against libstdc++ and was
therefore unusable (identified via failing autopkgtests).

The root cause is:

 - petsc can use either a C compiler (mpicc, wrapping gcc) or a C++ compiler
   (mpicxx, wrapping g++) to build these libraries.  It defaults to C.
 - libpetsc64_complex, unlike the other variants, includes C++ code
 - petsc's build system includes code to detect what additional arguments,
   if any, need to be passed to the C compiler to link in the standard C++
   runtime library (-lstdc++)
 - the test case petsc uses to detect whether additional libraries are
   required SOMEHOW, only with gcc-13, gets all of its C++ dependencies
   emitted as weak symbols by the compiler with no requirement to link
   against libstdc++
 - as a result, petsc incorrectly links libpetsc64_complex without libstdc++,
   giving an unusable library with unresolvable symbols.

Now, there were binNMUs of petsc in Debian 8 days ago, and I checked and the
libpetsc64-complex from that build on amd64 did use gcc-13 as the compiler
and did NOT miss the linkage to libstdc++.  I do not have an explanation for
this; it's possible it's related to the fact that Ubuntu is ahead of Debian
on glibc versions.  Nevertheless, since there are no other toolchain
differences between Debian and Ubuntu other than this (and certainly no
delta related to MPI), I expect this is a foot-gun that will at some point
affect Debian as well.

And because Debian does not trigger autopkgtests for binNMUs and does not
gate testing promotion of binNMUs on successful autopkgtest results, this
would not be caught automatically in Debian the way it was in Ubuntu;
therefore I am filing this bug at serious severity.

The attached patch does two things:

  * debian/patches/gcc-13.patch: fix misdetection of required C++
    library with gcc-13.
  * debian/rules: pass -Wl,-z,defs to the linker to guard against future
    misbuilds.

The patch to the upstream build system is inelegant and simply hard-codes
libstdc++.  I couldn't find a cleaner way to pass this information to the
build system as a configure option, and modifying the test case to fail
without libstdc++ was also non-trivial.  I'm sure upstream will eventually
want a different fix.

And btw, the build log does show tests that have regressed because the
library is broken, but these failing tests did not block the package
build...

I've uploaded this delta to Ubuntu to unbreak petsc there.

Thanks for considering the patch.
-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                   https://www.debian.org/
slangasek at ubuntu.com                                     vorlon at debian.org
-------------- next part --------------
diff -Nru petsc-3.18.6+dfsg1/debian/control petsc-3.18.6+dfsg1/debian/control
--- petsc-3.18.6+dfsg1/debian/control	2023-07-30 13:56:16.000000000 -0700
+++ petsc-3.18.6+dfsg1/debian/control	2023-08-16 08:42:11.000000000 -0700
@@ -1,8 +1,7 @@
 Source: petsc
 Section: devel
 Priority: optional
-Maintainer: Ubuntu Developers <ubuntu-devel-discuss at lists.ubuntu.com>
-XSBC-Original-Maintainer: Debian Science Maintainers <debian-science-maintainers at lists.alioth.debian.org>
+Maintainer: Debian Science Maintainers <debian-science-maintainers at lists.alioth.debian.org>
 Uploaders: "Adam C. Powell, IV" <hazelsct at debian.org>, Drew Parsons <dparsons at debian.org>
 Standards-Version: 4.6.2
 Build-Depends: debhelper-compat (= 13), python3, gfortran,
diff -Nru petsc-3.18.6+dfsg1/debian/patches/gcc-13.patch petsc-3.18.6+dfsg1/debian/patches/gcc-13.patch
--- petsc-3.18.6+dfsg1/debian/patches/gcc-13.patch	1969-12-31 16:00:00.000000000 -0800
+++ petsc-3.18.6+dfsg1/debian/patches/gcc-13.patch	2023-08-15 23:12:13.000000000 -0700
@@ -0,0 +1,27 @@
+Description: fix misdetection of required C++ library with gcc-13
+ petsc tries to autodetect what libraries need to be passed to the C
+ compiler in order to correctly link C++ code.  Unfortunately, the test
+ case somehow manages to build just fine without an explicit -lstdc++
+ argument under gcc-13, causing missing linkage.  Hard code the library
+ option instead.
+Author: Steve Langasek <steve.langasek at ubuntu.com>
+Forwarded: no
+Last-Update: 2023-08-15
+
+Index: petsc-3.18.6+dfsg1/config/BuildSystem/config/compilers.py
+===================================================================
+--- petsc-3.18.6+dfsg1.orig/config/BuildSystem/config/compilers.py
++++ petsc-3.18.6+dfsg1/config/BuildSystem/config/compilers.py
+@@ -446,6 +446,12 @@
+     '''Determines the libraries needed to link with C++ from C and Fortran'''
+     skipcxxlibraries = 1
+     self.setCompilers.saveLog()
++    oldLibs = self.setCompilers.LIBS
++    self.setCompilers.LIBS = '-lstdc++ '+self.setCompilers.LIBS
++    self.logWrite(self.setCompilers.restoreLog())
++    self.logPrint('C++ requires -lstdc++ to link with C compiler', 3, 'compilers')
++    return
++
+     body   = '''#include <iostream>\n#include <vector>\nvoid asub(void)\n{std::vector<int> v;\ntry  { throw 20;  }  catch (int e)  { std::cout << "An exception occurred";  }}'''
+     try:
+       if self.checkCrossLink(body,"int main(int argc,char **args)\n{return 0;}\n",language1='C++',language2='C'):
diff -Nru petsc-3.18.6+dfsg1/debian/patches/series petsc-3.18.6+dfsg1/debian/patches/series
--- petsc-3.18.6+dfsg1/debian/patches/series	2023-06-11 12:55:10.000000000 -0700
+++ petsc-3.18.6+dfsg1/debian/patches/series	2023-08-15 23:05:48.000000000 -0700
@@ -12,3 +12,4 @@
 configure_python3.patch
 petscmatmod_split.patch
 ptscotch_without_bison_MR5787.diff
+gcc-13.patch
diff -Nru petsc-3.18.6+dfsg1/debian/rules petsc-3.18.6+dfsg1/debian/rules
--- petsc-3.18.6+dfsg1/debian/rules	2023-06-11 12:55:10.000000000 -0700
+++ petsc-3.18.6+dfsg1/debian/rules	2023-08-15 23:14:45.000000000 -0700
@@ -158,7 +158,9 @@
 	  --with-fftw=1 --with-fftw-include=[] --with-fftw-lib="-lfftw3 -lfftw3_mpi" \
 	  --with-yaml=1 \
 	  $(VALGRIND_CONFIG) \
-	  $(PETSC_HDF5_FLAGS) --CXX_LINKER_FLAGS="-Wl,--no-as-needed"
+	  $(PETSC_HDF5_FLAGS) \
+          --CXX_LINKER_FLAGS="-Wl,--no-as-needed -Wl,-z,defs" \
+          --CC_LINKER_FLAGS="-Wl,-z,defs"
 
 
 # hypre is only supported with real numbers, not complex


More information about the debian-science-maintainers mailing list