[PATCH 2/4] libtool.m4: adjust kludge for ignoring syntax errors

Nick Alcock nick.alcock@oracle.com
Fri Dec 16 13:25:39 GMT 2022
LT_PATH_NM considers an nm to support -p/-B if it returns
output that names the path being checked -- but since that is itself nm
(usually with a path attached), this can trigger false positives with
errors like

/usr/bin/nm: unknown option "B" ignored"

The test currently avoids this case for the single instance of HP-UX
by deleting all but the last line of the output.  Keep on doing that
(so we don't do more work than we need to), but also explicitly
eliminate references to "unknown" and "invalid", with any leading
capitalization.  This handles Darwin, which says

error: nm: invalid argument '-B'

Alas, we cannot check the exit code, because some nm's return nonzero
exit codes if no symbols are found!

Things were also erroneously failing if nm had actual symbols in it,
because we were getting output that did not mention nm by name (its
usual output).  Identify things that look like valid nm output and
let it through.

	PR libctf/29547
	* libtool.m4 (LT_PATH_NM): Explicitly filter out 'unknown'
	and 'invalid' errors when looking for valid output.  Let
	through actual valid nm output too.
---
 libtool.m4 | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libtool.m4 b/libtool.m4
index ad63ebbb385..4e5b1884b87 100644
--- a/libtool.m4
+++ b/libtool.m4
@@ -3231,15 +3231,18 @@ AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
      tmp_nm_to_nm="`$ECHO "$tmp_nm" | sed 's, -.*$,,'`"
      if test -f "$tmp_nm_to_nm" || test -f "$tmp_nm_to_nm$ac_exeext" ; then
        # Check to see if the nm accepts a BSD-compat flag.
-       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
+       # We discard lines that mention 'unknown', 'invalid', or 'usage', hopefully
+       # placating systems like Darwin and HP-UX, which mention the name of nm
+       # in error output.
        #   nm: unknown option "B" ignored
-       case `"$tmp_nm" -B "$tmp_nm_to_nm" 2>&1 | grep -v '^ *$' | sed '1q'` in
-       *$tmp_nm*) lt_cv_path_NM="$tmp_nm -B"
+       case `"$tmp_nm" -B "$tmp_nm_to_nm" 2>&1 | $GREP -v '^ *$' | $GREP -v 'nknown ' | $GREP -v 'nvalid ' | $GREP -v 'sage: ' | sed '1q'` in
+       *$tmp_nm*|*\ \ \ [[A-Za-z]]\ *|*[[0-9a-f]][[0-9a-f]][[0-9a-f]]\ [[A-Za-z]]\ *)
+	 lt_cv_path_NM="$tmp_nm -B"
 	 break
 	 ;;
        *)
-	 case `"$tmp_nm" -p "$tmp_nm_to_nm" 2>&1 | grep -v '^ *$' | sed '1q'` in
-	 *$tmp_nm*)
+	 case `"$tmp_nm" -p "$tmp_nm_to_nm" 2>&1 | $GREP -v '^ *$' | $GREP -v 'nknown ' | $GREP -v 'nvalid ' | $GREP -v 'sage: ' | sed '1q'` in
+	 *$tmp_nm*|*\ \ \ [[A-Za-z]]\ *|*[[0-9a-f]][[0-9a-f]][[0-9a-f]]\ [[A-Za-z]]\ *)
 	   lt_cv_path_NM="$tmp_nm -p"
 	   break
 	   ;;
-- 
2.39.0.267.g7648178303



More information about the Binutils mailing list