Subject: bug#20733: coreutils build problem

From: Pádraig Brady <[email-masked]>
Date: Fri, 05 Jun 2015 22:34:41 +0100

On 05/06/15 20:27, Eric Blake wrote:
> On 06/05/2015 11:53 AM, Pádraig Brady wrote:
>> On 05/06/15 17:02, Michael Felt wrote:
>>>> Attribute "constructor" is not supported
>>
>> Does the attached patch help?
>>
> 
>> +++ b/configure.ac
>> @@ -455,7 +455,11 @@ if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
>>  fi
>>  
>>  AC_MSG_CHECKING([whether this is system supports stdbuf])
>> -AC_COMPILE_IFELSE(
>> +ac_save_CFLAGS="$CFLAGS"
>> +# Build with -Werror to detect warnings about
>> +# about ignored "constructor" arguments.
>> +CFLAGS="$CFLAGS -Werror"
> 
> -Werror works for gcc and some other compilers like clang, but is not
> universal to all compilers.  Are you sure that it is the right flag to
> be adding for the duration of this test?

Yes good point.

Also it's best only worry about warnings when cross compiling,
as otherwise we're using a direct runtime check.
Updated patch is attached.

thanks,
Pádraig.
From c17609817aaebcc5a5659aaba4c915f54a958431 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Fri, 5 Jun 2015 18:49:48 +0100
Subject: [PATCH] build: improve checks for stdbuf support

* configure.ac: Actually run the test program to
verify the constructor attribute is supported,
or when cross compiling fail on warnings so that
warnings about ignored attributes are significant.
Fixes a build failure on AIX.
---
 configure.ac | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index c159983..4831dca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -455,7 +455,7 @@ if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
 fi
 
 AC_MSG_CHECKING([whether this is system supports stdbuf])
-AC_COMPILE_IFELSE(
+AC_RUN_IFELSE(
   [AC_LANG_PROGRAM([[
     static int stdbuf = 0;
 
@@ -471,7 +471,27 @@ AC_COMPILE_IFELSE(
     return !(stdbuf == 1);]])
   ],
   [stdbuf_supported=yes],
-  [stdbuf_supported=no])
+  [stdbuf_supported=no],
+  [ac_save_CFLAGS="$CFLAGS"
+   # Detect warnings about ignored "constructor" attributes
+   gl_WARN_ADD([-Werror], [STDBUF_WFLAGS])
+   gl_WARN_ADD([-errwarn], [STDBUF_WFLAGS])
+   CFLAGS="$CFLAGS $STDBUF_WFLAGS"
+
+   AC_COMPILE_IFELSE(
+    [AC_LANG_SOURCE([[
+      void __attribute__ ((constructor))
+      stdbuf_cross_test (void)
+      #if __ELF__
+      {}
+      #endif
+      ]])
+    ],
+    [stdbuf_supported=yes],
+    [stdbuf_supported=no])
+
+   CFLAGS="$ac_save_CFLAGS"
+  ])
 AC_MSG_RESULT([$stdbuf_supported])
 if test "$stdbuf_supported" = "yes" && test -z "$EXEEXT"; then
   gl_ADD_PROG([optional_bin_progs], [stdbuf])
-- 
2.4.1