Skip to content

Commit 9ea205f

Browse files
committed
Fix broken static linking of apps.
Use pkg-config for both internal and external builds of libevent, hwloc, and libpmix and store them in OPAL_WRAPPER_EXTRA_LIBS. Signed-off-by: Austen Lauria <awlauria@us.ibm.com>
1 parent 3fedbf7 commit 9ea205f

12 files changed

+169
-7
lines changed

config/opal_check_pc.m4

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2021 IBM Corporation. All rights reserved.
4+
dnl
5+
dnl $COPYRIGHT$
6+
dnl
7+
dnl Additional copyrights may follow
8+
dnl
9+
dnl $HEADER$
10+
dnl
11+
12+
13+
dnl OPAL_CHECK_PKG_CONFIG
14+
dnl Check for availability of pkg-config and store the result.
15+
dnl If it is not available, store any passed in libs from the
16+
dnl --with-extra-libs configure option, or the known defaults.
17+
dnl
18+
dnl If it is available, allow configury to check for .pc files
19+
dnl and append to OPAL_WRAPPER_EXTRA_LIBS.
20+
AC_DEFUN([OPAL_CHECK_PKG_CONFIG], [
21+
AS_IF([test -z "$OPAL_HAS_PKG_CONFIG"],
22+
[
23+
AC_MSG_CHECKING([If pkg-config is available])
24+
which pkg-config > /dev/null 2>&1
25+
AS_IF([test "$?" -eq "0"],
26+
[
27+
AC_MSG_RESULT([yes])
28+
OPAL_HAS_PKG_CONFIG="yes"
29+
],
30+
[
31+
AC_MSG_RESULT([no])
32+
OPAL_HAS_PKG_CONFIG="no"
33+
OPAL_FLAGS_APPEND_UNIQ([OPAL_WRAPPER_EXTRA_LIBS], [$OPAL_EXTRA_LIBS])
34+
]
35+
)
36+
]
37+
)
38+
])
39+
40+
dnl OPAL_GET_LFLAGS_FROM_PC
41+
dnl Get the -l flags using pkg-config on the passed in .pc file, and
42+
dnl append them to OPAL_WRAPPER_EXTRA_LIBS.
43+
dnl
44+
dnl Requires 1 or more arguments.
45+
dnl
46+
dnl Arg 1 (Required): the name of the .pc file to look for (hwloc/pmix/libevent_core).pc
47+
dnl
48+
dnl Arg 2..n (Optional): The search path for the .pc file above and any dependencies.
49+
dnl These search will be appended and set in the env variable
50+
dnl PKG_CONFIG_PATH to tell pkg-config where to locate the .pc
51+
dnl file from argument 1, and its dependencies.
52+
dnl
53+
AC_DEFUN([OPAL_GET_LFLAGS_FROM_PC], [
54+
55+
AC_REQUIRE([OPAL_CHECK_PKG_CONFIG])
56+
AS_IF([test "$OPAL_HAS_PKG_CONFIG" = "yes"],
57+
[
58+
AC_MSG_NOTICE([Looking for pc file for $1])
59+
OPAL_VAR_SCOPE_PUSH([opal_pkg_config_name opal_pkg_config_env_to_set opal_pkg_config_args opal_pkg_config_cmd opal_pkg_config_result])
60+
opal_pkg_config_name=$1
61+
opal_pkg_config_env_to_set=""
62+
opal_pkg_config_cmd=""
63+
64+
AS_LITERAL_WORD_IF([$1], [], [m4_fatal([Non-literal argument $1])], [])
65+
$1_OMPI_PC_DIR=""
66+
67+
# Tell pkg-config where to find the .pc file from argument 1
68+
# as well as any/all dependencies.
69+
# The following block will append the path
70+
# to those .pc files into the pkg-config command.
71+
# num_paths > 1 implies there is at least one dependent .pc file
72+
# to append.
73+
AS_IF([test $# -gt 1],
74+
[
75+
$1_OMPI_PC_DIR=$2
76+
77+
# Shift the arguments by one to get to the actual paths.
78+
opal_pkg_config_args=m4_shift($@)
79+
80+
# Iterate over the comma seperated arguments, and replace the ','
81+
for i in $(echo $opal_pkg_config_args | sed "s/,/ /g"); do
82+
opal_pkg_config_env_to_set="$i:${opal_pkg_config_env_to_set}"
83+
done
84+
opal_pkg_config_cmd="env PKG_CONFIG_PATH=$opal_pkg_config_env_to_set pkg-config --libs $opal_pkg_config_name"
85+
],
86+
[opal_pkg_config_cmd="pkg-config --libs $opal_pkg_config_name"]
87+
)
88+
89+
OPAL_LOG_MSG([pkg-config cmd for $opal_pkg_config_name: $opal_pkg_config_cmd])
90+
91+
opal_pkg_config_result=$($opal_pkg_config_cmd)
92+
AS_IF([test -z "$opal_pkg_config_result"],
93+
[
94+
AC_MSG_WARN([Could not find viable $opal_pkg_config_name.pc])
95+
],
96+
[
97+
AC_MSG_NOTICE([pkg-config result $opal_pkg_config_result])
98+
OPAL_FLAGS_APPEND_UNIQ([OPAL_WRAPPER_EXTRA_LIBS], [$opal_pkg_config_result])
99+
]
100+
)
101+
OPAL_VAR_SCOPE_POP
102+
],
103+
[]
104+
)
105+
])

config/opal_config_hwloc.m4

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ AC_DEFUN([OPAL_CONFIG_HWLOC], [
7070
AS_IF([test "$external_hwloc_happy" = "0" -a "$internal_hwloc_happy" = "0"],
7171
[AC_MSG_ERROR([Could not find viable hwloc build.])])
7272
73+
AS_IF([test "$opal_hwloc_mode" = "external"],
74+
[AS_IF([test -n "$with_hwloc"],
75+
[OPAL_GET_LFLAGS_FROM_PC(hwloc, $with_hwloc/lib/pkgconfig)],
76+
[OPAL_GET_LFLAGS_FROM_PC(hwloc)]
77+
)],
78+
[OPAL_GET_LFLAGS_FROM_PC(hwloc, $OMPI_TOP_SRCDIR/3rd-party/hwloc_directory)]
79+
)
80+
7381
# this will work even if there is no hwloc package included,
7482
# because hwloc_tarball and hwloc_directory will evaluate to an
7583
# empty string. These are relative to the 3rd-party/ directory.

config/opal_config_libevent.m4

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,31 @@ AC_DEFUN([OPAL_CONFIG_LIBEVENT], [
7070
AS_IF([test "$external_libevent_happy" = "0" -a "$internal_libevent_happy" = "0"],
7171
[AC_MSG_ERROR([Could not find viable libevent build.])])
7272
73+
AS_IF([test "$opal_libevent_mode" = "external"],
74+
# The libevent.pc file only returns -levent, however we want
75+
# only -libevent_core and -libevent_pthreads, so ompi needs to
76+
# do this twice, once for each.
77+
[AS_IF([test -n "$with_libevent"],
78+
[
79+
OPAL_GET_LFLAGS_FROM_PC(libevent_core, $with_libevent/lib/pkgconfig)
80+
OPAL_GET_LFLAGS_FROM_PC(libevent_pthreads, $with_libevent/lib/pkgconfig)
81+
],
82+
[
83+
OPAL_GET_LFLAGS_FROM_PC(libevent_core)
84+
OPAL_GET_LFLAGS_FROM_PC(libevent_pthreads)
85+
]
86+
)],
87+
[
88+
OPAL_GET_LFLAGS_FROM_PC(libevent_core, $OMPI_TOP_SRCDIR/3rd-party/libevent_directory)
89+
OPAL_GET_LFLAGS_FROM_PC(libevent_pthreads, $OMPI_TOP_SRCDIR/3rd-party/libevent_directory)
90+
]
91+
)
92+
93+
# Strip -levent as we don't want it. We only want -levent_core/-levent_pthreads.
94+
# See https://github.com/open-mpi/ompi/pull/8792
95+
OPAL_WRAPPER_EXTRA_LIBS=$(echo $OPAL_WRAPPER_EXTRA_LIBS | sed "s/\\-levent\b//g");
96+
AC_MSG_NOTICE([OPAL_WRAPPER_EXTRA_LIBS stripped -levent: $OPAL_WRAPPER_EXTRA_LIBS])
97+
7398
# this will work even if there is no libevent package included,
7499
# because libevent_tarball and libevent_directory will evaluate to
75100
# an empty string. These are relative to the 3rd-party/

config/opal_config_pmix.m4

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ AC_DEFUN([OPAL_CONFIG_PMIX], [
129129
AS_IF([test "$external_pmix_happy" = "0" -a "$internal_pmix_happy" = "0"],
130130
[AC_MSG_ERROR([Could not find viable pmix build.])])
131131
132+
AS_IF([test "$external_pmix_happy" = "1"],
133+
[AS_IF([test -n "$with_pmix"],
134+
[OPAL_GET_LFLAGS_FROM_PC(pmix, $with_pmix/lib/pkgconfig, $libevent_core_OMPI_PC_DIR, $hwloc_OMPI_PC_DIR)],
135+
[OPAL_GET_LFLAGS_FROM_PC(pmix, "", $libevent_core_OMPI_PC_DIR, $hwloc_OMPI_PC_DIR)]
136+
)],
137+
[OPAL_GET_LFLAGS_FROM_PC(pmix, $OMPI_TOP_SRCDIR/3rd-party/openpmix/maint, $libevent_core_OMPI_PC_DIR, $hwloc_OMPI_PC_DIR)]
138+
)
139+
132140
AC_DEFINE_UNQUOTED([OPAL_USING_INTERNAL_PMIX],
133141
[$OPAL_USING_INTERNAL_PMIX],
134142
[Whether or not we are using the internal PMIx])

config/opal_configure_options.m4

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,22 @@ else
213213
fi
214214
AM_CONDITIONAL(WANT_INSTALL_HEADERS, test "$WANT_INSTALL_HEADERS" = 1)
215215

216+
#
217+
# If there's no pkg-config available, allow users to pass in -l/-L flags manually.
218+
#
219+
AC_MSG_CHECKING([if want extra libs for static builds])
220+
AC_ARG_WITH([extra-libs],[AS_HELP_STRING([--with-extra-libs],
221+
[A comma seperated list of extra libraries to link in for static builds (example: -lbar,-lbat) (default: None.). This should be used if pkg-config is not available.])])
222+
OPAL_EXTRA_LIBS=""
223+
if test -n "x$with_extra_libs"; then
224+
# Iterate over the list, removing the commas.
225+
for i in $(echo $with_extra_libs | sed "s/,/ /g"); do
226+
OPAL_FLAGS_APPEND_UNIQ([OPAL_EXTRA_LIBS], [$i])
227+
done
228+
AC_MSG_RESULT($OPAL_EXTRA_LIBS)
229+
else
230+
AC_MSG_RESULT(default)
231+
fi
216232

217233
#
218234
# Do we want the pretty-print stack trace feature?

config/opal_setup_wrappers.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ AC_DEFUN([OPAL_SETUP_WRAPPER_FINAL],[
380380
# and this cleans the duplication up a bunch. Always add everything the user
381381
# asked for, as they know better than us.
382382
AC_MSG_CHECKING([for OPAL LIBS])
383-
OPAL_WRAPPER_EXTRA_LIBS="$opal_mca_wrapper_extra_libs"
383+
OPAL_WRAPPER_EXTRA_LIBS="$opal_mca_wrapper_extra_libs $OPAL_WRAPPER_EXTRA_LIBS"
384384
OPAL_FLAGS_APPEND_UNIQ([OPAL_WRAPPER_EXTRA_LIBS], [$wrapper_extra_libs])
385385
OPAL_WRAPPER_EXTRA_LIBS="$OPAL_WRAPPER_EXTRA_LIBS $with_wrapper_libs"
386386
AC_SUBST([OPAL_WRAPPER_EXTRA_LIBS])

ompi/tools/wrappers/mpic++-wrapper-data.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ linker_flags=@OMPI_WRAPPER_EXTRA_LDFLAGS@
2121
# pulled in implicitly) because we intend MPI applications to only use
2222
# the MPI API.
2323
libs=@OMPI_WRAPPER_CXX_LIB@ -l@OMPI_LIBMPI_NAME@
24-
libs_static=@OMPI_WRAPPER_CXX_LIB@ -l@OMPI_LIBMPI_NAME@ -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@
24+
libs_static=@OMPI_WRAPPER_CXX_LIB@ -l@OMPI_LIBMPI_NAME@ -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@ @OPAL_WRAPPER_EXTRA_LIBS@
2525
dyn_lib_file=lib@OMPI_LIBMPI_NAME@.@OPAL_DYN_LIB_SUFFIX@
2626
static_lib_file=lib@OMPI_LIBMPI_NAME@.a
2727
required_file=@OMPI_WRAPPER_CXX_REQUIRED_FILE@

ompi/tools/wrappers/mpicc-wrapper-data.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ linker_flags=@OMPI_WRAPPER_EXTRA_LDFLAGS@
2121
# pulled in implicitly) because we intend MPI applications to only use
2222
# the MPI API.
2323
libs=-l@OMPI_LIBMPI_NAME@
24-
libs_static=-l@OMPI_LIBMPI_NAME@ -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@
24+
libs_static=-l@OMPI_LIBMPI_NAME@ -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@ @OPAL_WRAPPER_EXTRA_LIBS@
2525
dyn_lib_file=lib@OMPI_LIBMPI_NAME@.@OPAL_DYN_LIB_SUFFIX@
2626
static_lib_file=lib@OMPI_LIBMPI_NAME@.a
2727
required_file=

ompi/tools/wrappers/mpifort-wrapper-data.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ linker_flags=@OMPI_WRAPPER_EXTRA_FC_LDFLAGS@
2020
# pulled in implicitly) because we intend MPI applications to only use
2121
# the MPI API.
2222
libs=@OMPI_FORTRAN_USEMPIF08_LIB@ @OMPI_FORTRAN_USEMPI_LIB@ @OMPI_FORTRAN_MPIFH_LINK@ -l@OMPI_LIBMPI_NAME@
23-
libs_static=@OMPI_FORTRAN_USEMPIF08_LIB@ @OMPI_FORTRAN_USEMPI_LIB@ @OMPI_FORTRAN_MPIFH_LINK@ -l@OMPI_LIBMPI_NAME@ -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@
23+
libs_static=@OMPI_FORTRAN_USEMPIF08_LIB@ @OMPI_FORTRAN_USEMPI_LIB@ @OMPI_FORTRAN_MPIFH_LINK@ -l@OMPI_LIBMPI_NAME@ -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@ @OPAL_WRAPPER_EXTRA_LIBS@
2424
dyn_lib_file=lib@OMPI_LIBMPI_NAME@.@OPAL_DYN_LIB_SUFFIX@
2525
static_lib_file=lib@OMPI_LIBMPI_NAME@.a
2626
required_file=@OMPI_WRAPPER_FORTRAN_REQUIRED_FILE@

ompi/tools/wrappers/ompi-c.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ pkgincludedir=@opalincludedir@
1616
# static linking, so only list these in Libs.private.
1717
#
1818
Libs: -L${libdir} @OMPI_PKG_CONFIG_LDFLAGS@ -l@OMPI_LIBMPI_NAME@
19-
Libs.private: -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@
19+
Libs.private: -l@OPAL_LIB_NAME@ @OMPI_WRAPPER_EXTRA_LIBS@ @OPAL_WRAPPER_EXTRA_LIBS@
2020
#
2121
Cflags: -I${includedir} @OMPI_WRAPPER_EXTRA_CPPFLAGS@ @OMPI_WRAPPER_EXTRA_CFLAGS@

0 commit comments

Comments
 (0)