PATCH libiberty configure mysteries

Gabriel Dos Reis gdr@integrable-solutions.net
Fri Apr 15 21:58:00 GMT 2005


Ian Lance Taylor <ian@airs.com> writes:

| Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
| 
| > The following is from libibtery.h
| > 
| >    /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
| >       undefined, we haven't run the autoconf check so provide the
| >       declaration without arguments.  If it is 0, we checked and failed
| >       to find the declaration so provide a fully prototyped one.  If it
| >       is 1, we found it so don't provide any declaration at all.  */
| > 
| > However, that appears to be incorrect because what configure output in
| > config.h is not HAVE_DECL_XXX, but HAVE_XXX. Therefore, it appears
| > that libiberty would be misdetecting declarations -- it thinks
| > something is  missing, whereas in fact it is not.
| 
| HAVE_XXX means that the function exists on the system.  HAVE_DECL_XXX
| means that the function is declared in a header file.  The libiberty
| configure script itself doesn't bother to test for any declarations.
| The tests for HAVE_DECL_XXX in libiberty.h are for the benefit of
| other programs which use libiberty.
| 
| > The way I ran into this problem is when trying to compile libiberty
| > with a C++ compiler, which is quite intolerant about declaration
| > mismatches:
| > 
| > /home/gdr/tmp/ipr.gcc-4.1/libiberty/../include/libiberty.h:78: error:
| > declaration of 'char* basename(const char*)' throws different exceptions
| > /usr/include/string.h:345: error: than previous declaration 'char*
| > basename(const char*) throw ()'
| > 
| > Of course, configure #defines HAVE_BASENAME to 1, but libiberty is
| > testing for HAVE_DECL_BASENAME.
| 
| This approach was designed to work with C compilers, which are more
| forgiving.  As Daniel said, you will need to add an AC_CHECK_DECLS to
| the libiberty configure.ac for basename, and probably for some other
| functions as well.  Then you will have to return autoconf and
| autoheader.  Make sure the configure script outputs "whether basename
| is declared".  Make sure that HAVE_DECL_BASENAME appears in
| libiberty/config.in (which is generated by autoheader).  Make sure
| that every file in libiberty which includes libiberty.h includes
| config.h first.

Ian --

  Here is a patch that implements your suggestion.  It correctly
detects and propagates configure findings.  There about a hal-dozen
files in libberty that included libiberty.h without config.h.  Fixed.

OK to apply?

-- Gaby
2005-04-13  Gabriel Dos Reis  <gdr@integrable-solutions.net>

	* asprintf.c: Include config.h.
	* basename.c: Likewise.
	* fdmatch.c: Likewise.
	* hex.c: Likewise.
	* lbasename.c: Likewise.
	* spaces.c: Likewise.
	* xatexit.c:Likewise.
	* configure.ac:  Do check declarations for basename, ffs, asprintf 
	and vasprintf for real.
	* configure: Regenerate.

Index: argv.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/argv.c,v
retrieving revision 1.15
diff -p -r1.15 argv.c
*** argv.c	13 Apr 2005 13:49:19 -0000	1.15
--- argv.c	15 Apr 2005 21:30:33 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 22,27 ****
--- 22,30 ----
  /*  Create and destroy argument vectors.  An argument vector is simply an
      array of string pointers, terminated by a NULL pointer. */
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "ansidecl.h"
  #include "libiberty.h"
  
Index: asprintf.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/asprintf.c,v
retrieving revision 1.8
diff -p -r1.8 asprintf.c
*** asprintf.c	26 Mar 2005 19:24:31 -0000	1.8
--- asprintf.c	15 Apr 2005 21:30:33 -0000
*************** License along with libiberty; see the fi
*** 19,24 ****
--- 19,27 ----
  not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "ansidecl.h"
  #include "libiberty.h"
  
Index: basename.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/basename.c,v
retrieving revision 1.7
diff -p -r1.7 basename.c
*** basename.c	26 Mar 2005 19:24:31 -0000	1.7
--- basename.c	15 Apr 2005 21:30:33 -0000
*************** Behavior is undefined if the pathname en
*** 12,17 ****
--- 12,20 ----
  
  */
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "ansidecl.h"
  #include "libiberty.h"
  #include "safe-ctype.h"
Index: configure
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/configure,v
retrieving revision 1.93
diff -p -r1.93 configure
*** configure	12 Apr 2005 14:23:47 -0000	1.93
--- configure	15 Apr 2005 21:30:35 -0000
*************** _ACEOF
*** 6915,6920 ****
--- 6915,7202 ----
  fi
  done
  
+   echo "$as_me:$LINENO: checking whether basename is declared" >&5
+ echo $ECHO_N "checking whether basename is declared... $ECHO_C" >&6
+ if test "${ac_cv_have_decl_basename+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   cat >conftest.$ac_ext <<_ACEOF
+ /* confdefs.h.  */
+ _ACEOF
+ cat confdefs.h >>conftest.$ac_ext
+ cat >>conftest.$ac_ext <<_ACEOF
+ /* end confdefs.h.  */
+ $ac_includes_default
+ int
+ main ()
+ {
+ #ifndef basename
+   char *p = (char *) basename;
+ #endif
+ 
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+   (eval $ac_compile) 2>conftest.er1
+   ac_status=$?
+   grep -v '^ *+' conftest.er1 >conftest.err
+   rm -f conftest.er1
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+ 	 { ac_try='test -z "$ac_c_werror_flag"
+ 			 || test ! -s conftest.err'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; } &&
+ 	 { ac_try='test -s conftest.$ac_objext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   ac_cv_have_decl_basename=yes
+ else
+   echo "$as_me: failed program was:" >&5
+ sed 's/^/| /' conftest.$ac_ext >&5
+ 
+ ac_cv_have_decl_basename=no
+ fi
+ rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi
+ echo "$as_me:$LINENO: result: $ac_cv_have_decl_basename" >&5
+ echo "${ECHO_T}$ac_cv_have_decl_basename" >&6
+ if test $ac_cv_have_decl_basename = yes; then
+ 
+ cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_BASENAME 1
+ _ACEOF
+ 
+ 
+ else
+   cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_BASENAME 0
+ _ACEOF
+ 
+ 
+ fi
+ echo "$as_me:$LINENO: checking whether ffs is declared" >&5
+ echo $ECHO_N "checking whether ffs is declared... $ECHO_C" >&6
+ if test "${ac_cv_have_decl_ffs+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   cat >conftest.$ac_ext <<_ACEOF
+ /* confdefs.h.  */
+ _ACEOF
+ cat confdefs.h >>conftest.$ac_ext
+ cat >>conftest.$ac_ext <<_ACEOF
+ /* end confdefs.h.  */
+ $ac_includes_default
+ int
+ main ()
+ {
+ #ifndef ffs
+   char *p = (char *) ffs;
+ #endif
+ 
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+   (eval $ac_compile) 2>conftest.er1
+   ac_status=$?
+   grep -v '^ *+' conftest.er1 >conftest.err
+   rm -f conftest.er1
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+ 	 { ac_try='test -z "$ac_c_werror_flag"
+ 			 || test ! -s conftest.err'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; } &&
+ 	 { ac_try='test -s conftest.$ac_objext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   ac_cv_have_decl_ffs=yes
+ else
+   echo "$as_me: failed program was:" >&5
+ sed 's/^/| /' conftest.$ac_ext >&5
+ 
+ ac_cv_have_decl_ffs=no
+ fi
+ rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi
+ echo "$as_me:$LINENO: result: $ac_cv_have_decl_ffs" >&5
+ echo "${ECHO_T}$ac_cv_have_decl_ffs" >&6
+ if test $ac_cv_have_decl_ffs = yes; then
+ 
+ cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_FFS 1
+ _ACEOF
+ 
+ 
+ else
+   cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_FFS 0
+ _ACEOF
+ 
+ 
+ fi
+ echo "$as_me:$LINENO: checking whether asprintf is declared" >&5
+ echo $ECHO_N "checking whether asprintf is declared... $ECHO_C" >&6
+ if test "${ac_cv_have_decl_asprintf+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   cat >conftest.$ac_ext <<_ACEOF
+ /* confdefs.h.  */
+ _ACEOF
+ cat confdefs.h >>conftest.$ac_ext
+ cat >>conftest.$ac_ext <<_ACEOF
+ /* end confdefs.h.  */
+ $ac_includes_default
+ int
+ main ()
+ {
+ #ifndef asprintf
+   char *p = (char *) asprintf;
+ #endif
+ 
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+   (eval $ac_compile) 2>conftest.er1
+   ac_status=$?
+   grep -v '^ *+' conftest.er1 >conftest.err
+   rm -f conftest.er1
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+ 	 { ac_try='test -z "$ac_c_werror_flag"
+ 			 || test ! -s conftest.err'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; } &&
+ 	 { ac_try='test -s conftest.$ac_objext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   ac_cv_have_decl_asprintf=yes
+ else
+   echo "$as_me: failed program was:" >&5
+ sed 's/^/| /' conftest.$ac_ext >&5
+ 
+ ac_cv_have_decl_asprintf=no
+ fi
+ rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi
+ echo "$as_me:$LINENO: result: $ac_cv_have_decl_asprintf" >&5
+ echo "${ECHO_T}$ac_cv_have_decl_asprintf" >&6
+ if test $ac_cv_have_decl_asprintf = yes; then
+ 
+ cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_ASPRINTF 1
+ _ACEOF
+ 
+ 
+ else
+   cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_ASPRINTF 0
+ _ACEOF
+ 
+ 
+ fi
+ echo "$as_me:$LINENO: checking whether vasprintf is declared" >&5
+ echo $ECHO_N "checking whether vasprintf is declared... $ECHO_C" >&6
+ if test "${ac_cv_have_decl_vasprintf+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   cat >conftest.$ac_ext <<_ACEOF
+ /* confdefs.h.  */
+ _ACEOF
+ cat confdefs.h >>conftest.$ac_ext
+ cat >>conftest.$ac_ext <<_ACEOF
+ /* end confdefs.h.  */
+ $ac_includes_default
+ int
+ main ()
+ {
+ #ifndef vasprintf
+   char *p = (char *) vasprintf;
+ #endif
+ 
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+   (eval $ac_compile) 2>conftest.er1
+   ac_status=$?
+   grep -v '^ *+' conftest.er1 >conftest.err
+   rm -f conftest.er1
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+ 	 { ac_try='test -z "$ac_c_werror_flag"
+ 			 || test ! -s conftest.err'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; } &&
+ 	 { ac_try='test -s conftest.$ac_objext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   ac_cv_have_decl_vasprintf=yes
+ else
+   echo "$as_me: failed program was:" >&5
+ sed 's/^/| /' conftest.$ac_ext >&5
+ 
+ ac_cv_have_decl_vasprintf=no
+ fi
+ rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi
+ echo "$as_me:$LINENO: result: $ac_cv_have_decl_vasprintf" >&5
+ echo "${ECHO_T}$ac_cv_have_decl_vasprintf" >&6
+ if test $ac_cv_have_decl_vasprintf = yes; then
+ 
+ cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_VASPRINTF 1
+ _ACEOF
+ 
+ 
+ else
+   cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_VASPRINTF 0
+ _ACEOF
+ 
+ 
+ fi
+ 
+ 
    echo "$as_me:$LINENO: checking whether canonicalize_file_name must be declared" >&5
  echo $ECHO_N "checking whether canonicalize_file_name must be declared... $ECHO_C" >&6
  if test "${libiberty_cv_decl_needed_canonicalize_file_name+set}" = set; then
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/configure.ac,v
retrieving revision 1.21
diff -p -r1.21 configure.ac
*** configure.ac	12 Apr 2005 14:23:48 -0000	1.21
--- configure.ac	15 Apr 2005 21:30:36 -0000
*************** if test -z "${setobjs}"; then
*** 518,523 ****
--- 518,524 ----
      [AC_MSG_RESULT([no])])
  
    AC_CHECK_FUNCS($checkfuncs)
+   AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf])
    libiberty_NEED_DECLARATION(canonicalize_file_name)
  fi
  
Index: fdmatch.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/fdmatch.c,v
retrieving revision 1.4
diff -p -r1.4 fdmatch.c
*** fdmatch.c	27 Mar 2005 15:31:12 -0000	1.4
--- fdmatch.c	15 Apr 2005 21:30:36 -0000
*************** BUGS
*** 41,46 ****
--- 41,49 ----
  
  */
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "ansidecl.h"
  #include "libiberty.h"
  #include <sys/types.h>
Index: hex.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/hex.c,v
retrieving revision 1.9
diff -p -r1.9 hex.c
*** hex.c	27 Mar 2005 15:31:13 -0000	1.9
--- hex.c	15 Apr 2005 21:30:36 -0000
*************** not, write to the Free Software Foundati
*** 18,23 ****
--- 18,26 ----
  Boston, MA 02111-1307, USA.  */
  
  #include <stdio.h>  /* for EOF */
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "libiberty.h"
  #include "safe-ctype.h" /* for HOST_CHARSET_ASCII */
  
Index: lbasename.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/lbasename.c,v
retrieving revision 1.6
diff -p -r1.6 lbasename.c
*** lbasename.c	27 Mar 2005 15:31:13 -0000	1.6
--- lbasename.c	15 Apr 2005 21:30:36 -0000
*************** and a path ending in @code{/} returns th
*** 37,42 ****
--- 37,45 ----
  
  */
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "ansidecl.h"
  #include "libiberty.h"
  #include "safe-ctype.h"
Index: spaces.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/spaces.c,v
retrieving revision 1.4
diff -p -r1.4 spaces.c
*** spaces.c	28 Mar 2005 04:22:33 -0000	1.4
--- spaces.c	15 Apr 2005 21:30:36 -0000
*************** valid until at least the next call.
*** 29,34 ****
--- 29,37 ----
  
  */
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "ansidecl.h"
  #include "libiberty.h"
  
Index: xatexit.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/xatexit.c,v
retrieving revision 1.8
diff -p -r1.8 xatexit.c
*** xatexit.c	28 Mar 2005 01:28:01 -0000	1.8
--- xatexit.c	15 Apr 2005 21:30:36 -0000
*************** failure.  If you use @code{xatexit} to r
*** 22,27 ****
--- 22,30 ----
  /* Adapted from newlib/libc/stdlib/{,at}exit.[ch].
     If you use xatexit, you must call xexit instead of exit.  */
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
  #include "ansidecl.h"
  #include "libiberty.h"
  



More information about the Gcc-patches mailing list