C99 ld configury

Alan Modra amodra@gmail.com
Mon Apr 5 05:55:51 GMT 2021


	* configure.ac: Move initfini-array arg handling earlier.  Don't
	check for string.h, strings.h, stdlib.h, or locale.h.  Do check
	for inttypes.h, stdint.h, sys/types.h.  Don't check for
	setlocale, free, getev or strstr.
	(AC_ISC_POSIX): Don't invoke.
	* sysdep.h: Include string.h and stdlib.h unconditionally.  Test
	HAVE_SYS_TYPE_H and HAVE_SYS_STAT_H.  Remove strstr, free and
	getenv fallback declarations.
	* ld.h: Don't test HAVE_LOCALE_H.
	* ldmain.c: Don't test HAVE_SETLOCALE.
	* config.in: Regenerate.
	* configure: Regenerate.

diff --git a/ld/configure.ac b/ld/configure.ac
index 19a5df12c95..5429f22ac23 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -23,7 +23,6 @@ AC_CONFIG_SRCDIR(ldmain.c)
 
 AC_CANONICAL_TARGET
 AC_CANONICAL_BUILD
-AC_ISC_POSIX
 
 AM_INIT_AUTOMAKE
 AM_MAINTAINER_MODE
@@ -231,6 +230,18 @@ case "${enable_default_hash_style}" in
   *) ac_default_emit_gnu_hash=0 ;;
 esac
 
+AC_ARG_ENABLE(initfini-array,
+[  --disable-initfini-array do not use .init_array/.fini_array sections],
+[case "${enableval}" in
+ yes|no) ;;
+ *) AC_MSG_ERROR([invalid --enable-initfini-array argument]) ;;
+ esac], [enable_initfini_array=yes])
+AC_SUBST(enable_initfini_array)
+if test $enable_initfini_array = yes; then
+  AC_DEFINE(HAVE_INITFINI_ARRAY, 1,
+    [Define .init_array/.fini_array sections are available and working.])
+fi
+
 GCC_ENABLE([libctf], [yes], [], [Handle .ctf type-info sections])
 if test "${enable_libctf}" = yes; then
     AC_DEFINE(ENABLE_LIBCTF, 1, [Handle .ctf type-info sections])
@@ -280,30 +291,25 @@ ACX_PROG_CMP_IGNORE_INITIAL
 AC_SUBST(HDEFINES)
 AC_SUBST(NATIVE_LIB_DIRS)
 
-AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h elf-hints.h limits.h locale.h sys/param.h)
-AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h sys/stat.h)
-ACX_HEADER_STRING
-AC_CHECK_FUNCS(glob mkstemp realpath sbrk setlocale waitpid)
-AC_CHECK_FUNCS(open lseek close)
-AC_HEADER_DIRENT
+# We use headers from include/ that check various HAVE_*_H macros, thus
+# should ensure they are set by configure.  This is true even when C99
+# guarantees they are available.
+# sha1.h and md4.h test HAVE_LIMITS_H, HAVE_SYS_TYPES_H and HAVE_STDINT_H
+# plugin-api.h tests HAVE_STDINT_H and HAVE_INTTYPES_H
+# Besides those, we need to check anything used in ld/ not in C99.
+AC_CHECK_HEADERS(fcntl.h elf-hints.h limits.h inttypes.h stdint.h \
+		 sys/file.h sys/mman.h sys/param.h sys/stat.h sys/time.h \
+		 sys/types.h unistd.h)
+AC_CHECK_FUNCS(close glob lseek mkstemp open realpath sbrk waitpid)
+
+BFD_BINARY_FOPEN
+
+AC_CHECK_DECLS([asprintf, environ, sbrk])
 
-dnl AC_CHECK_HEADERS(sys/mman.h)
 AC_FUNC_MMAP
 
 AC_SEARCH_LIBS([dlopen], [dl])
 
-AC_ARG_ENABLE(initfini-array,
-[  --disable-initfini-array do not use .init_array/.fini_array sections],
-[case "${enableval}" in
- yes|no) ;;
- *) AC_MSG_ERROR([invalid --enable-initfini-array argument]) ;;
- esac], [enable_initfini_array=yes])
-AC_SUBST(enable_initfini_array)
-if test $enable_initfini_array = yes; then
-  AC_DEFINE(HAVE_INITFINI_ARRAY, 1,
-    [Define .init_array/.fini_array sections are available and working.])
-fi
-
 AC_MSG_CHECKING(for a known getopt prototype in unistd.h)
 AC_CACHE_VAL(ld_cv_decl_getopt_unistd_h,
 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>], [extern int getopt (int, char *const*, const char *);])],
@@ -314,10 +320,6 @@ if test $ld_cv_decl_getopt_unistd_h = yes; then
 	    [Is the prototype for getopt in <unistd.h> in the expected format?])
 fi
 
-BFD_BINARY_FOPEN
-
-AC_CHECK_DECLS([asprintf, environ, free, getenv, sbrk, strstr])
-
 # Link in zlib if we can.  This allows us to read and write
 # compressed CTF sections.
 AM_ZLIB
diff --git a/ld/ld.h b/ld/ld.h
index 1f52be9add6..35fafebfaed 100644
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -21,8 +21,6 @@
 #ifndef LD_H
 #define LD_H
 
-#ifdef HAVE_LOCALE_H
-#endif
 #ifndef SEEK_CUR
 #define SEEK_CUR 1
 #endif
@@ -30,18 +28,16 @@
 #define SEEK_END 2
 #endif
 
-#ifdef HAVE_LOCALE_H
-# ifndef ENABLE_NLS
-   /* The Solaris version of locale.h always includes libintl.h.  If we have
-      been configured with --disable-nls then ENABLE_NLS will not be defined
-      and the dummy definitions of bindtextdomain (et al) below will conflict
-      with the defintions in libintl.h.  So we define these values to prevent
-      the bogus inclusion of libintl.h.  */
-#  define _LIBINTL_H
-#  define _LIBGETTEXT_H
-# endif
-# include <locale.h>
+#ifndef ENABLE_NLS
+  /* The Solaris version of locale.h always includes libintl.h.  If we have
+     been configured with --disable-nls then ENABLE_NLS will not be defined
+     and the dummy definitions of bindtextdomain (et al) below will conflict
+     with the defintions in libintl.h.  So we define these values to prevent
+     the bogus inclusion of libintl.h.  */
+# define _LIBINTL_H
+# define _LIBGETTEXT_H
 #endif
+#include <locale.h>
 
 #ifdef ENABLE_NLS
 # include <libintl.h>
diff --git a/ld/ldmain.c b/ld/ldmain.c
index b99d518ea31..be33b6943c6 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -246,12 +246,10 @@ main (int argc, char **argv)
   char *emulation;
   long start_time = get_run_time ();
 
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
+#ifdef HAVE_LC_MESSAGES
   setlocale (LC_MESSAGES, "");
 #endif
-#if defined (HAVE_SETLOCALE)
   setlocale (LC_CTYPE, "");
-#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
diff --git a/ld/sysdep.h b/ld/sysdep.h
index 27bce0adf38..a80ac133ade 100644
--- a/ld/sysdep.h
+++ b/ld/sysdep.h
@@ -28,30 +28,15 @@
 #include "config.h"
 
 #include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <stdarg.h>
-
-#ifdef STRING_WITH_STRINGS
-#include <string.h>
-#include <strings.h>
-#else
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#else
-extern char *strchr ();
-extern char *strrchr ();
-#endif
 #endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
 #endif
-
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-
+#include <string.h>
+#include <stdarg.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -107,18 +92,6 @@ extern char *strrchr ();
 #define SEEK_END 2
 #endif
 
-#if !HAVE_DECL_STRSTR
-extern char *strstr ();
-#endif
-
-#if !HAVE_DECL_FREE
-extern void free ();
-#endif
-
-#if !HAVE_DECL_GETENV
-extern char *getenv ();
-#endif
-
 #if !HAVE_DECL_ENVIRON
 extern char **environ;
 #endif

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list