33dnl Copyright (c) 2015-2017 Research Organization for Information Science
44dnl and Technology (RIST). All rights reserved.
55dnl Copyright (c) 2017 Intel, Inc. All rights reserved.
6+ dnl Copyright (c) 2017 Cisco Systems, Inc. All rights reserved.
67dnl $COPYRIGHT $
78dnl
89dnl Additional copyrights may follow
@@ -19,7 +20,7 @@ dnl libnl-3.so.200 and friends, so if libnl3-devel packages are not
1920dnl installed, but libnl-devel are, Open MPI should not try to use libnl.
2021dnl
2122dnl GROSS: libnl wants us to either use pkg-config (which we
22- dnl can ' t assume is always present) or we need to look in a
23+ dnl cannot assume is always present) or we need to look in a
2324dnl particular directory for the right libnl3 include files. For
2425dnl now, just hard code the special path into this logic.
2526dnl
@@ -68,46 +69,128 @@ AC_DEFUN([OPAL_LIBNL_SANITY_INIT], [
6869 esac
6970])
7071
71- dnl OPAL_LIBNL_SANITY_CHECK(lib, function, LIBS)
72+ dnl OPAL_LIBNL_SANITY_FAIL_MSG(lib)
73+ dnl
74+ dnl Helper to pring a big warning message when we detect a libnl conflict.
75+ dnl
76+ dnl --------------------------------------------------------------------
77+ AC_DEFUN([OPAL_LIBNL_SANITY_FAIL_MSG], [
78+ AC_MSG_WARN([This is a configuration that is * known* to cause run-time crashes.])
79+ AC_MSG_WARN([This is an error in lib$1 (not Open MPI).])
80+ AC_MSG_WARN([Open MPI will therefore skip using lib$1 .])
81+ ])
82+
83+ dnl OPAL_LIBNL_SANITY_CHECK(lib, function, LIBS, libnl_check_ok)
84+ dnl
85+ dnl This macro is invoked from OPAL_CHECK_PACKAGE to make sure that
86+ dnl new libraries that are added to LIBS do not pull in conflicting
87+ dnl versions of libnl. E.g., if we already have a library in LIBS
88+ dnl that pulls in libnl v3, if OPAL_CHECK_PACKAGE is later called that
89+ dnl pulls in a library that pulls in libnl v1, this macro will detect
90+ dnl the conflict and will abort configure.
91+ dnl
92+ dnl We abort rather than silently ignore this library simply because
93+ dnl we are now multiple levels deep in the M4 " call stack" , and this
94+ dnl layer does not know the intent of the user. Hence, all we can do
95+ dnl is abort with a hopefully helpful error message (that we aborted
96+ dnl because Open MPI would have been built in a configuration that is
97+ dnl known to crash).
98+ dnl
7299dnl --------------------------------------------------------------------
73100AC_DEFUN([OPAL_LIBNL_SANITY_CHECK], [
101+ OPAL_VAR_SCOPE_PUSH([opal_libnl_sane])
102+ opal_libnl_sane= 1
74103 case $host in
75104 * linux* )
76- OPAL_VAR_SCOPE_PUSH([ldd_output libnl_version])
77- AC_LANG_PUSH(C)
78- cat > conftest_c.$ac_ext << EOF
105+ OPAL_LIBNL_SANITY_CHECK_LINUX($1 , $2 , $3 , opal_libnl_sane)
106+ ;;
107+ esac
108+
109+ $4 = $opal_libnl_sane
110+ OPAL_VAR_SCOPE_POP([opal_libnl_sane])
111+ ])
112+
113+ dnl
114+ dnl Simple helper for OPAL_LIBNL_SANITY_CHECK
115+ dnl $1 : library name
116+ dnl $2 : function
117+ dnl $3 : LIBS
118+ dnl $4 : output variable (1=ok, 0=not ok)
119+ dnl
120+ AC_DEFUN([OPAL_LIBNL_SANITY_CHECK_LINUX], [
121+ OPAL_VAR_SCOPE_PUSH([this_requires_v1 libnl_sane this_requires_v3 ldd_output result_msg])
122+
123+ AC_LANG_PUSH(C)
124+
125+ AC_MSG_CHECKING([if lib$1 requires libnl v1 or v3])
126+ cat > conftest_c.$ac_ext << EOF
79127extern void $2 (void);
80128int main(int argc, char * argv[[]]) {
81129 $2 ();
82130 return 0;
83131}
84132EOF
85- OPAL_LOG_COMMAND([$CC -o conftest $CFLAGS $CPPFLAGS conftest_c.$ac_ext $LDFLAGS -l$1 $LIBS $3 ],
86- [ldd_output= ` ldd conftest`
87- libnl_version= 0
88- AS_IF([echo $ldd_output | grep -q libnl.so],
89- [AS_IF([test $opal_libnl_version -eq 3],
90- [AC_MSG_WARN([lib nl version conflict: $opal_libnlv3_libs requires libnl-3 whereas $1 requires libnl])],
91- [opal_libnlv1_libs= " $opal_libnlv1_libs $1 "
92- OPAL_UNIQ([opal_libnlv1_libs])
93- opal_libnl_version= 1])
94- libnl_version= 1])
95- AS_IF([echo $ldd_output | grep -q libnl-3.so],
96- [AS_IF([test $libnl_version -eq 1],
97- [AC_MSG_WARN([lib $1 requires both libnl v1 and libnl v3 -- yoinks! ])
98- AC_MSG_WARN([This is a configuration that is known to cause run-time crashes])
99- AC_MSG_ERROR([Cannot continue])])
100- AS_IF([test $opal_libnl_version -eq 1],
101- [AC_MSG_WARN([lib nl version conflict: $opal_libnlv1_libs requires libnl whereas $1 requires libnl-3])],
102- [opal_libnlv3_libs= " $opal_libnlv3_libs $1 "
103- OPAL_UNIQ([opal_libnlv3_libs])
104- opal_libnl_version= 3])])
105- rm -f conftest conftest_c.$ac_ext ],
106- [AC_MSG_WARN([Could not link a simple program with lib $1 ])])
107- AC_LANG_POP(C)
108- OPAL_VAR_SCOPE_POP([ldd_output libnl_version])
109- ;;
110- esac
133+
134+ this_requires_v1= 0
135+ this_requires_v3= 0
136+ result_msg=
137+ OPAL_LOG_COMMAND([$CC -o conftest $CFLAGS $CPPFLAGS conftest_c.$ac_ext $LDFLAGS -l$1 $LIBS $3 ],
138+ [ldd_output= ` ldd conftest`
139+ AS_IF([echo $ldd_output | grep -q libnl-3.so],
140+ [this_requires_v3= 1
141+ result_msg= " v3" ])
142+ AS_IF([echo $ldd_output | grep -q libnl.so],
143+ [this_requires_v1= 1
144+ result_msg= " v1 $result_msg " ])
145+ AC_MSG_RESULT([$result_msg ])
146+ ],
147+ [AC_MSG_WARN([Could not link a simple program with lib $1 ])
148+ ])
149+
150+ # Assume that our configuration is sane; this may get reset below
151+ libnl_sane= 1
152+
153+ # Note: in all the checks below, only add this library to the list
154+ # of libraries (for v1 or v3 as relevant) if we do not fail.
155+ # I.e., assume that a higher level will refuse to use this library
156+ # if we return failure.
157+
158+ # Does this library require both v1 and v3? If so, fail.
159+ AS_IF([test $this_requires_v1 -eq 1 && test $this_requires_v3 -eq 1],
160+ [AC_MSG_WARN([Unfortunately, lib$1 links to both libnl and libnl-3.])
161+ OPAL_LIBNL_SANITY_FAIL_MSG($1 )
162+ libnl_sane= 0])
163+
164+ # Does this library require v1, but some prior library required
165+ # v3? If so, fail.
166+ AS_IF([test $libnl_sane -eq 1 && test $this_requires_v1 -eq 1],
167+ [AS_IF([test $opal_libnl_version -eq 3],
168+ [AC_MSG_WARN([libnl version conflict: $opal_libnlv3_libs requires libnl-3 whereas $1 requires libnl])
169+ OPAL_LIBNL_SANITY_FAIL_MSG($1 )
170+ libnl_sane= 0],
171+ [opal_libnlv1_libs= " $opal_libnlv1_libs $1 "
172+ OPAL_UNIQ([opal_libnlv1_libs])
173+ opal_libnl_version= 1])
174+ ])
175+
176+ # Does this library require v3, but some prior library required
177+ # v1? If so, fail.
178+ AS_IF([test $libnl_sane -eq 1 && test $this_requires_v3 -eq 1],
179+ [AS_IF([test $opal_libnl_version -eq 1],
180+ [AC_MSG_WARN([libnl version conflict: $opal_libnlv1_libs requires libnl whereas lib$1 requires libnl-3])
181+ OPAL_LIBNL_SANITY_FAIL_MSG($1 )
182+ libnl_sane= 0],
183+ [opal_libnlv3_libs= " $opal_libnlv3_libs $1 "
184+ OPAL_UNIQ([opal_libnlv3_libs])
185+ opal_libnl_version= 3])
186+ ])
187+
188+ AC_LANG_POP(C)
189+ rm -f conftest conftest_c.$ac_ext
190+
191+ $4 = $libnl_sane
192+
193+ OPAL_VAR_SCOPE_POP([ldd_output libnl_sane this_requires_v1 this_requires_v3 result_msg])
111194])
112195
113196dnl
@@ -219,7 +302,11 @@ AC_DEFUN([OPAL_CHECK_LIBNL_V3],[
219302 AS_IF([test $opal_libnlv3_happy -eq 1],
220303 [$2 _LIBS= " -lnl-3 -lnl-route-3"
221304 OPAL_HAVE_LIBNL3= 1],
222- [$2 _LIBS= " " ])
305+ [# OPAL_CHECK_PACKAGE(...,nl_recvmsgs_report,...) might have set the variables below
306+ # so reset them if libnl v3 cannot be used
307+ $2 _CPPFLAGS= " "
308+ $2 _LDFLAGS= " "
309+ $2 _LIBS= " " ])
223310
224311 OPAL_VAR_SCOPE_POP
225312])
0 commit comments