Leaking MPI symbols from `libgmsh.so`
Description
As discussed with @geuzaine, libgmsh.so
is leaking MPI-related symbols like MPI_Init
(objdump -T libgmsh.so | c++filt | grep MPI_
).
Step 1
The first analysis was as follows:
- GMSH's SDK is indeed compiled with
-fvisibility=hidden
to ensure that only symbols explicitly declared public with__attribute__ ((visibility("default")))
are exposed. - However, GMSH's SDK contains a statically linked version of
libpetsc.a
compiled without MPI support. - Without MPI support, PETSc uses a fake MPI library that leaks its MPI-related symbols.
In a first attempt, @geuzaine made 165ded1e, that instructs PETSc to use fvisibility=hidden
by default.
Step 2
However, there were still some MPI symbols leaking from libgmsh.so
, coming from MUMPS (compiled by PETSc). It seemed that PETSc's CFLAGS
were not passed to MUMPS.
In fact, according to https://gitlab.com/petsc/petsc/-/blob/ca8c967e29bc995fdad3f17e46f56229b985d1fa/config/BuildSystem/config/packages/MUMPS.py#L108, the CFLAGS
from PETSc are filtered by a function updatePackageCFlags
, that effectively removes fvisibility=hidden
. Therefore, there is no easy workaround.
A possible workaround is to modify this MUMPS.py
file to enforce the -fvisibility=hidden
flag to be passed to MUMPS
.
It can be implemented in the Debian Stretch dockerfile as:
RUN cd ${PETSC_DIR} \
&& sed -i 's/+ self.updatePackageCFlags/+ " -fvisibility=hidden " + self.updatePackageCFlags/' /petsc-3.14.4/config/BuildSystem/config/packages/MUMPS.py \
&& sed -i 's/+self.updatePackageFFlags/+ " -fvisibility=hidden " + self.updatePackageFFlags/' /petsc-3.14.4/config/BuildSystem/config/packages/MUMPS.py \
&& ./configure CC=$CC CXX=$CXX FC=$FC CFLAGS="$CFLAGS -fvisibility=hidden" \
CXXFLAGS="$CXXFLAGS -fvisibility=hidden" FFLAGS=$FFLAGS --with-clanguage=cxx --with-debugging=0 --with-mpi=0 --with-mpiuni-fortran-binding=0 --download-mumps=yes --with-mumps-serial --with-shared-libraries=0 --with-x=0 --with-ssl=0 --with-scalar-type=real --with-blaslapack-lib="/usr/local/lib/libopenblas.a /usr/local/lib64/libgfortran.a /usr/local/lib64/libquadmath.a -lpthread" \
&& make -j8
Solution
As discussed with @geuzaine , I'll make a merge request with the fix soon. In the solution, I'd like to:
-
use awk
to ensure the substitution has occurred. This will ensure that if an update of PETSc is such that the patch cannot be applied, it will "raise". -
add a check like if objdump -T libgmsh.so | c++filt | grep "MPI_Init" ;then echo "MPI_Init was found. This should not happen."; exit -1;fi