Skip to content

Commit 3edf9f1

Browse files
committed
Improve handling of libs in wrapper compilers
Improve the logic of handling library (-l) references in the wrapper compilers. Previously, a duplicate in one of the LIB strings would leave the left-most reference, which can lead to missing symbols if a more right library also depends on the duplicated library. Instead, keep only the right-most reference. Add a helper macro for list appending to avoid duplicating the same 3 lines of shell code multiple times in opal_functions.m4 Signed-off-by: Brian Barrett <bbarrett@amazon.com>
1 parent badc318 commit 3edf9f1

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

config/opal_config_libevent.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ AC_DEFUN([OPAL_CONFIG_LIBEVENT], [
101101
opal_libevent_WRAPPER_LDFLAGS="$pkg_config_core_ldflags"
102102
OPAL_FLAGS_APPEND_UNIQ([opal_libevent_WRAPPER_LDFLAGS], [$pkg_config_pthreads_ldflags])
103103
opal_libevent_WRAPPER_LIBS="$pkg_config_pthreads_libs"
104-
OPAL_FLAGS_APPEND_UNIQ([opal_libevent_WRAPPER_LIBS], [$pkg_config_core_libs])],
104+
OPAL_FLAGS_APPEND_MOVE([opal_libevent_WRAPPER_LIBS], [$pkg_config_core_libs])],
105105
[# guess that what we have from compiling OMPI is good enough
106106
opal_libevent_WRAPPER_LDFLAGS="$opal_libevent_LDFLAGS"
107107
opal_libevent_WRAPPER_LIBS="$opal_libevent_LIBS"])

config/opal_functions.m4

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dnl Copyright (c) 2009-2020 Cisco Systems, Inc. All rights reserved.
1616
dnl Copyright (c) 2014 Intel, Inc. All rights reserved.
1717
dnl Copyright (c) 2015-2017 Research Organization for Information Science
1818
dnl and Technology (RIST). All rights reserved.
19+
dnl Copyright (c) 2021 Amazon.com, Inc. or its affiliates. All Rights
20+
dnl reserved.
1921
dnl
2022
dnl $COPYRIGHT$
2123
dnl
@@ -317,6 +319,18 @@ dnl #######################################################################
317319
dnl #######################################################################
318320
dnl #######################################################################
319321

322+
# OPAL_APPEND(variable, new_argument)
323+
# ----------------------------------------
324+
# Append new_argument to variable, assuming a space separated list.
325+
#
326+
AC_DEFUN([OPAL_APPEND], [
327+
AS_IF([test -z "$$1"], [$1="$2"], [$1="$$1 $2"])
328+
])
329+
330+
dnl #######################################################################
331+
dnl #######################################################################
332+
dnl #######################################################################
333+
320334
# OPAL_APPEND_UNIQ(variable, new_argument)
321335
# ----------------------------------------
322336
# Append new_argument to variable if not already in variable. This assumes a
@@ -333,11 +347,7 @@ for arg in $2; do
333347
fi
334348
done
335349
if test "$opal_found" = "0" ; then
336-
if test -z "$$1"; then
337-
$1="$arg"
338-
else
339-
$1="$$1 $arg"
340-
fi
350+
OPAL_APPEND([$1], [$arg])
341351
fi
342352
done
343353
unset opal_found
@@ -463,7 +473,50 @@ AC_DEFUN([OPAL_FLAGS_APPEND_UNIQ], [
463473
AS_IF([test "x$val" = "x$arg"], [opal_append=0])
464474
done])
465475
AS_IF([test "$opal_append" = "1"],
466-
[AS_IF([test -z "$$1"], [$1=$arg], [$1="$$1 $arg"])])
476+
[OPAL_APPEND([$1], [$arg])])
477+
done
478+
479+
OPAL_VAR_SCOPE_POP
480+
])
481+
482+
dnl #######################################################################
483+
dnl #######################################################################
484+
dnl #######################################################################
485+
486+
# OPAL_FLAGS_APPEND_MOVE(variable, new_argument)
487+
# ----------------------------------------------
488+
# add new_arguments to the end of variable.
489+
#
490+
# If an argument in new_arguments does not begin with -I, -L, or -l OR
491+
# the argument begins with -I, -L, or -l and it is not already in
492+
# variable, it is appended to variable.
493+
#
494+
# If an argument in new_argument begins with a -l and is already in
495+
# variable, the existing occurances of the argument are removed from
496+
# variable and the argument is appended to variable. This behavior
497+
# is most useful in LIBS, where ordering matters and being rightmost
498+
# is usually the right behavior.
499+
#
500+
# This macro assumes a space separated list.
501+
AC_DEFUN([OPAL_FLAGS_APPEND_MOVE], [
502+
OPAL_VAR_SCOPE_PUSH([opal_tmp_variable opal_tmp opal_append])
503+
504+
for arg in $2; do
505+
AS_CASE([$arg],
506+
[-I*|-L*],
507+
[opal_append=1
508+
for val in ${$1} ; do
509+
AS_IF([test "x$val" = "x$arg"], [opal_append=0])
510+
done
511+
AS_IF([test $opal_append -eq 1], [OPAL_APPEND([$1], [$arg])])],
512+
[-l*],
513+
[opal_tmp_variable=
514+
for val in ${$1}; do
515+
AS_IF([test "x$val" != "x$arg"],
516+
[OPAL_APPEND([opal_tmp_variable], [$val])])
517+
done
518+
OPAL_APPEND([opal_tmp_variable], [$arg])])
519+
$1="$opal_tmp_variable"
467520
done
468521

469522
OPAL_VAR_SCOPE_POP

config/opal_mca.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ AC_MSG_ERROR([*** $2 component $3 was supposed to be direct-called, but
850850
[AS_VAR_COPY([tmp_flags], [$2_$3_WRAPPER_EXTRA_LIBS])],
851851
[AS_VAR_COPY([tmp_all_flags], [$2_$3_LIBS])
852852
OPAL_MCA_STRIP_LAFILES([tmp_flags], [$tmp_all_flags])])
853-
OPAL_FLAGS_APPEND_UNIQ([mca_wrapper_extra_libs], [$tmp_flags])])
853+
OPAL_FLAGS_APPEND_MOVE([mca_wrapper_extra_libs], [$tmp_flags])])
854854
855855
# WRAPPER_EXTRA_CPPFLAGS are only needed for STOP_AT_FIRST
856856
# components, as all other components are not allowed to leak

config/opal_setup_wrappers.m4

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ AC_DEFUN([OPAL_WRAPPER_FLAGS_ADD], [
4343
[$1], [CXXFLAGS], [OPAL_FLAGS_APPEND_UNIQ([wrapper_extra_cxxflags], [$2])],
4444
[$1], [FCFLAGS], [OPAL_FLAGS_APPEND_UNIQ([wrapper_extra_fcflags], [$2])],
4545
[$1], [LDFLAGS], [OPAL_FLAGS_APPEND_UNIQ([wrapper_extra_ldflags], [$2])],
46-
[$1], [LIBS], [OPAL_FLAGS_APPEND_UNIQ([wrapper_extra_libs], [$2])],
46+
[$1], [LIBS], [OPAL_FLAGS_APPEND_MOVE([wrapper_extra_libs], [$2])],
4747
[m4_fatal([Unknown wrapper flag type $1])])
4848
])
4949

@@ -386,9 +386,9 @@ AC_DEFUN([OPAL_SETUP_WRAPPER_FINAL],[
386386
# asked for, as they know better than us.
387387
AC_MSG_CHECKING([for OPAL LIBS])
388388
OPAL_WRAPPER_EXTRA_LIBS="$opal_mca_wrapper_extra_libs"
389-
OPAL_FLAGS_APPEND_UNIQ([OPAL_WRAPPER_EXTRA_LIBS], [$wrapper_extra_libs])
390-
OPAL_WRAPPER_EXTRA_LIBS="$OPAL_WRAPPER_EXTRA_LIBS $with_wrapper_libs"
391-
OPAL_FLAGS_APPEND_UNIQ([OMPI_WRAPPER_EXTRA_LIBS], [$LIBS])
389+
OPAL_FLAGS_APPEND_MOVE([OPAL_WRAPPER_EXTRA_LIBS], [$wrapper_extra_libs])
390+
OPAL_FLAGS_APPEND_MOVE([OPAL_WRAPPER_EXTRA_LIBS], [$with_wrapper_libs])
391+
OPAL_FLAGS_APPEND_MOVE([OMPI_WRAPPER_EXTRA_LIBS], [$LIBS])
392392
AC_SUBST([OPAL_WRAPPER_EXTRA_LIBS])
393393
AC_MSG_RESULT([$OPAL_WRAPPER_EXTRA_LIBS])
394394
])
@@ -451,9 +451,9 @@ AC_DEFUN([OPAL_SETUP_WRAPPER_FINAL],[
451451

452452
AC_MSG_CHECKING([for OMPI LIBS])
453453
OMPI_WRAPPER_EXTRA_LIBS="$ompi_mca_wrapper_extra_libs"
454-
OPAL_FLAGS_APPEND_UNIQ([OMPI_WRAPPER_EXTRA_LIBS], [$wrapper_extra_libs])
455-
OMPI_WRAPPER_EXTRA_LIBS="$OMPI_WRAPPER_EXTRA_LIBS $with_wrapper_libs"
456-
OPAL_FLAGS_APPEND_UNIQ([OMPI_WRAPPER_EXTRA_LIBS], [$LIBS])
454+
OPAL_FLAGS_APPEND_MOVE([OMPI_WRAPPER_EXTRA_LIBS], [$wrapper_extra_libs])
455+
OPAL_FLAGS_APPEND_MOVE([OMPI_WRAPPER_EXTRA_LIBS], [$with_wrapper_libs])
456+
OPAL_FLAGS_APPEND_MOVE([OMPI_WRAPPER_EXTRA_LIBS], [$LIBS])
457457
AC_SUBST([OMPI_WRAPPER_EXTRA_LIBS])
458458
AC_MSG_RESULT([$OMPI_WRAPPER_EXTRA_LIBS])
459459

0 commit comments

Comments
 (0)