Hi,

Jeremy reported this ages and ages ago, and I promptly forgot about it (sorry). David reported it again yesterday.

Darwin's linker can be quite verbose, if it sees an -L path that does not exist it prints a warning on stderr. Jeremy needs to configure with -L paths that don't exist at configure time (because they will exist later), and would like to be able to debug the result, so detecting -force_load properly would be helpful.

Davids problem was about failing to detect -single_module, same issue.

I only have Mac OS X 10.6 systems, and I am much too lazy to check what older linkers did when they saw flags they didn't recognize, so this patch greps stderr for "flag" and assumes the linker didn't recognize it if is there. I think all Darwin ld's exit with an error for flags they don't recognize, so even that is probably not necessary, but I am not 100% sure of that.

Jeremy, I set RC_TRACE_ARCHIVES, RC_TRACE_DYLIBS, RC_TRACE_DYLIB_SEARCHING to check that none of those env vars caused ld to print its arguments on stderr, and they didn't. Are there any env vars set when building the OS that would cause that to happen? If so I will change this patch to just assume that ld exits with an error code for unrecognized arguments.

Patch Ok?

Peter


>From 4f0eb4701ae67e7e52dcc4cb8eb7eb65f11645d3 Mon Sep 17 00:00:00 2001
From: Peter O'Gorman <pe...@pogma.com>
Date: Wed, 19 Jan 2011 10:09:46 -0600
Subject: [PATCH] Don't let verbose linker messages influence test results.

* libltdl/m4/libtool.m4 (_LT_REQUIRED_DARWIN_CHECKS): Ignore
stderr during tests for -flag unless it contains "flag".
* tests/darwin.at: Add test.
Reported by Jeremy Huddleston and also by David Fang.
---
 ChangeLog             |    8 ++++++++
 libltdl/m4/libtool.m4 |   14 ++++++++++++--
 tests/darwin.at       |   26 +++++++++++++++++++++++++-
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1ad3741..640f4a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-01-19  Peter O'Gorman  <pe...@pogma.com>
+
+	Don't let verbose linker messages influence test results.
+	* libltdl/m4/libtool.m4 (_LT_REQUIRED_DARWIN_CHECKS): Ignore
+	stderr during tests for -flag unless it contains "flag".
+	* tests/darwin.at: Add test.
+	Reported by Jeremy Huddleston and also by David Fang.
+
 2011-01-09  John David Anglin  <dave.ang...@nrc-cnrc.gc.ca>  (tiny change)
 
 	Fix relink mode to use absolute path if hardcode_minus_L.
diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4
index fd79dcf..706a2df 100644
--- a/libltdl/m4/libtool.m4
+++ b/libltdl/m4/libtool.m4
@@ -986,7 +986,13 @@ m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
 	$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
 	  -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
         _lt_result=$?
-	if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
+	# If there is a non-empty error log, and "single_module"
+	# appears in it, assume the flag caused a linker warning
+        if test -s conftest.err && $GREP single_module conftest.err; then
+	  cat conftest.err >&AS_MESSAGE_LOG_FD
+	# Otherwise, if the output was created with a 0 exit code from
+	# the compiler, it worked.
+	elif test -f libconftest.dylib && test $_lt_result = 0; then
 	  lt_cv_apple_cc_single_mod=yes
 	else
 	  cat conftest.err >&AS_MESSAGE_LOG_FD
@@ -994,6 +1000,7 @@ m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
 	rm -rf libconftest.dylib*
 	rm -f conftest.*
       fi])
+
     AC_CACHE_CHECK([for -exported_symbols_list linker flag],
       [lt_cv_ld_exported_symbols_list],
       [lt_cv_ld_exported_symbols_list=no
@@ -1005,6 +1012,7 @@ m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
 	[lt_cv_ld_exported_symbols_list=no])
 	LDFLAGS="$save_LDFLAGS"
     ])
+
     AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load],
       [lt_cv_ld_force_load=no
       cat > conftest.c << _LT_EOF
@@ -1022,7 +1030,9 @@ _LT_EOF
       echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD
       $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err
       _lt_result=$?
-      if test -f conftest && test ! -s conftest.err && test $_lt_result = 0 && $GREP forced_load conftest 2>&1 >/dev/null; then
+      if test -s conftest.err && $GREP force_load conftest.err; then
+	cat conftest.err >&AS_MESSAGE_LOG_FD
+      elif test -f conftest && test $_lt_result = 0 && $GREP forced_load conftest 2>&1 >/dev/null; then
 	lt_cv_ld_force_load=yes
       else
 	cat conftest.err >&AS_MESSAGE_LOG_FD
diff --git a/tests/darwin.at b/tests/darwin.at
index bb71207..4e5034e 100644
--- a/tests/darwin.at
+++ b/tests/darwin.at
@@ -1,6 +1,6 @@
 # darwin.at - tests specific to Mac OS X
 #
-#   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+#   Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
 #   Written by Peter O'Gorman, 2008
 #
 #   This file is part of GNU Libtool.
@@ -204,3 +204,27 @@ AT_CHECK([echo quit | $LIBTOOL --mode=execute gdb main],
 AT_CHECK([grep 'Could not find object file' stderr],[1],[ignore],[ignore])
 
 AT_CLEANUP
+
+AT_SETUP([darwin ld warnings changing configure results])
+
+AT_DATA([configure.ac],
+[[AC_INIT([ld-stderr], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
+AC_CONFIG_MACRO_DIR([m4])
+AM_INIT_AUTOMAKE([foreign])
+AC_PROG_CC
+LT_INIT
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+]])
+
+AT_DATA([Makefile.am],[
+ACLOCAL_AMFLAGS = -I m4
+])
+LT_AT_LIBTOOLIZE([--copy --force])
+LT_AT_AUTORECONF([--force --install])
+LT_AT_CONFIGURE
+AT_CHECK([./libtool --config],[ignore],[stdout],[ignore])
+mv stdout expout
+LT_AT_CONFIGURE([LDFLAGS=-L/there/is/no/dir/here])
+AT_CHECK([./libtool --config],[ignore],[expout],[ignore])
+AT_CLEANUP
-- 
1.7.2.3

Reply via email to