coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] stdbuf: support compilers other than __GNUC__


From: Pádraig Brady
Subject: [PATCH] stdbuf: support compilers other than __GNUC__
Date: Wed, 21 May 2014 18:30:48 +0100

__SUNPRO_C >= 0x590 /*12.0*/ supports __attribute((constructor))
required by stdbuf, so use a more direct check for this.

Note ensure that --libexecdir is set to the appropriate
install location for libstdbuf.so so that stdbuf works
when installed on the system like it does when running
tests in the build directory.

* configure.ac (stdbuf_supported): Use a test prog to determine support.
* src/libstdbuf.c (stdbuf): Define appropriately for non GCC compilers,
and provide early feedback (compilation warning) if trying to compile
libstdbuf without the necessary support.
* src/stdbuf.c (set_LD_PRELOAD): Add a note on having stdbuf
look for libstdbuf.so in the default lib search path.
* cfg.mk (sc_prohibit-gl-attributes): Adjust so we can exclude
libstdbuf.so from prohibiting '__attribute', since we want
this form to avoid silently eliding this required attribute on non GCC.

Reported and tested by Rich Burridge.
---
 cfg.mk          |   11 +++++++----
 configure.ac    |   28 ++++++++++++++++++++--------
 src/libstdbuf.c |    3 ++-
 src/stdbuf.c    |   12 +++++++++++-
 4 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index f84b1a4..66aa55d 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -229,10 +229,10 @@ sc_prohibit-j-printf-format:
 # directly use attributes already defined by gnulib.
 # TODO: move the check for _GL... attributes to gnulib.
 sc_prohibit-gl-attributes:
-       @cd $(srcdir) && GIT_PAGER= git grep -En                        \
-           "__attribute |__(unused|pure|const)__" src gl/lib/*.[ch]    \
-         && { echo '$(ME): Use _GL... attribute macros' 1>&2; exit 1; }  \
-         || :
+       @prohibit='__attribute |__(unused|pure|const)__'        \
+       in_vc_files='\.[ch]$$'                                  \
+       halt='Use _GL... attribute macros'                      \
+         $(_sc_search_regexp)
 
 # Look for lines longer than 80 characters, except omit:
 # - program-generated long lines in diff headers,
@@ -647,6 +647,9 @@ 
exclude_file_name_regexp--sc_prohibit_operator_at_end_of_line = \
 exclude_file_name_regexp--sc_error_message_uppercase = ^src/factor\.c$$
 exclude_file_name_regexp--sc_prohibit_atoi_atof = ^src/make-prime-list\.c$$
 
+# Exception here as we don't want __attribute elided on non GCC
+exclude_file_name_regexp--sc_prohibit-gl-attributes = ^src/libstdbuf\.c$$
+
 # Augment AM_CFLAGS to include our per-directory options:
 AM_CFLAGS += $($(@D)_CFLAGS)
 
diff --git a/configure.ac b/configure.ac
index 34f2955..a7a8bfc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -430,14 +430,26 @@ if test $gl_cv_list_mounted_fs = yes && test 
$gl_cv_fs_space = yes; then
   gl_ADD_PROG([optional_bin_progs], [df])
 fi
 
-# Limit stdbuf to ELF systems with GCC
-AC_MSG_CHECKING([whether this is an ELF system])
-AC_EGREP_CPP([yes], [#if __ELF__
-yes
-#endif], [elf_sys=yes], [elf_sys=no])
-AC_MSG_RESULT([$elf_sys])
-if test "$elf_sys" = "yes" && \
-   test "$GCC" = "yes"; then
+AC_MSG_CHECKING([whether this is system supports stdbuf])
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM([[
+    static int stdbuf = 0;
+
+    /* Restrict to ELF systems with compilers
+       that support the constructor attribute.  */
+    void __attribute__ ((constructor))
+    stdbuf_init (void)
+    {
+      #if __ELF__
+        stdbuf = 1;
+      #endif
+    }]],[[
+    return !(stdbuf == 1);]])
+  ],
+  [stdbuf_supported=yes],
+  [stdbuf_supported=no])
+AC_MSG_RESULT([$stdbuf_supported])
+if test "$stdbuf_supported" = "yes"; then
   gl_ADD_PROG([optional_bin_progs], [stdbuf])
 fi
 
diff --git a/src/libstdbuf.c b/src/libstdbuf.c
index 88321e9..1281b9d 100644
--- a/src/libstdbuf.c
+++ b/src/libstdbuf.c
@@ -127,7 +127,8 @@ apply_mode (FILE *stream, const char *mode)
     }
 }
 
-__attribute__ ((constructor)) static void
+/* Use __attribute to avoid elision of __attribute__ on SUNPRO_C etc.  */
+static void __attribute ((constructor))
 stdbuf (void)
 {
   char *e_mode = getenv ("_STDBUF_E");
diff --git a/src/stdbuf.c b/src/stdbuf.c
index 270881b..c648fc5 100644
--- a/src/stdbuf.c
+++ b/src/stdbuf.c
@@ -195,7 +195,17 @@ set_LD_PRELOAD (void)
      However we want the lookup done for the exec'd command not stdbuf.
 
      Since we don't link against libstdbuf.so add it to PKGLIBEXECDIR
-     rather than to LIBDIR.  */
+     rather than to LIBDIR.
+
+     Note we could add "" as the penultimate item in the following list
+     to enable searching for libstdbuf.so in the default system lib paths.
+     However that would not indicate an error if libstdbuf.so was not found.
+     Also while this could support auto selecting the right arch in a multilib
+     environment, what we really want is to auto select based on the arch of 
the
+     command being run, rather than that of stdbuf itself.  This is currently
+     not supported due to the unusual need for controlling the stdio buffering
+     of programs that are a different architecture to the default on the
+     system (and that of stdbuf itself).  */
   char const *const search_path[] = {
     program_path,
     PKGLIBEXECDIR,
-- 
1.7.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]