[RFA] fix bfd multi-arch compilation failure

Alan Modra amodra@bigpond.net.au
Wed Mar 18 11:05:00 GMT 2009


On Wed, Mar 18, 2009 at 12:26:53AM +0100, Pierre Muller wrote:
> I found two problems in bfd directory,
> related to uses of alloca without
> including <alloca.h>

I think it's slightly crazy that we have multiple places trying to
handle alloca declarations, some quite different from the others.
Some time ago I added include/alloca-conf.h and used it, but
apparently the original alloca-conf.h failed to work in some cases.
Unfortunately, instead of fixing alloca-conf.h, the version in
gas/as.h was copied into bfd/elf64-hppa.c and bfd/som.c, then further
tweaked.  This patch gets us back to just one file with alloca magic.

Note that we aren't supposed to use alloca in BFD because on systems
which do not have alloca the version in libiberty calls xmalloc, which
might cause the program to crash when it runs out of memory.  BFD
ought to return an error status instead.  However, I don't care enough
to force this on other people, or fix their code.

include/
	* alloca-conf.h: Revise based on autoconf-2.61, autoconf-2.13
	documentation.
bfd/
	* elf32-m68hc1x.c: Include alloca-conf.h.
	* xsym.c: Likewise.
	* elf64-hppa.c: Likewise.  Remove existing #if's handling alloca.
	* som.c: Likewise.
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
binutils/
	* sysdep.h: Include alloca-conf.h instead of config.h and remove
	existing #if's handling alloca.
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
gas/
	* as.h: Include alloca-conf.h instead of config.h and remove
	existing #if's handling alloca.
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
opcodes/
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
	* openrisc-opc.c: Regenerate.
ld/
	* ld.h: Remove alloca handling.

Index: include/alloca-conf.h
===================================================================
RCS file: /cvs/src/src/include/alloca-conf.h,v
retrieving revision 1.1
diff -c -p -r1.1 alloca-conf.h
*** include/alloca-conf.h	28 Sep 2000 08:00:54 -0000	1.1
--- include/alloca-conf.h	18 Mar 2009 07:49:36 -0000
***************
*** 1,24 ****
  #include "config.h"
  
! #if defined(__GNUC__) && !defined(C_ALLOCA)
! # ifndef alloca
! #  define alloca __builtin_alloca
! # endif
! #else /* ! defined (__GNUC__) */
! #  ifdef _AIX
!  #pragma alloca
  #  else
! #  if defined(HAVE_ALLOCA_H) && !defined(C_ALLOCA)
! #   include <alloca.h>
! #  else /* ! defined (HAVE_ALLOCA_H) */
! #   ifdef __STDC__
! extern PTR alloca (size_t);
! #   else /* ! defined (__STDC__) */
! extern PTR alloca ();
! #   endif /* ! defined (__STDC__) */
! #  endif /* ! defined (HAVE_ALLOCA_H) */
! #  ifdef _WIN32
! #   include <malloc.h>
  #  endif
! # endif /* ! defined (_AIX) */
! #endif /* ! defined (__GNUC__) */
--- 1,44 ----
  #include "config.h"
  
! /* This is a merge of code recommended in the autoconf-2.61 documentation
!    with that recommended in the autoconf-2.13 documentation, with added
!    tweaks to heed C_ALLOCA.  */
! 
! #if defined HAVE_ALLOCA_H && !defined C_ALLOCA
! # include <alloca.h>
! #else
! # if defined __GNUC__ && !defined C_ALLOCA
! #  if !defined alloca
! #   define alloca __builtin_alloca
! #  endif
! # else
! #  if defined _AIX
! /* Indented so that pre-ansi C compilers will ignore it, rather than
!    choke on it.  Some versions of AIX require this to be the first
!    thing in the file except for comments and preprocessor directives.  */
!     #pragma alloca
  #  else
! #   if defined _MSC_VER && !defined C_ALLOCA
! #    include <malloc.h>
! #    define alloca _alloca
! #   else
! #    if !defined alloca
! #     if defined __STDC__ || defined __hpux
! #      if defined HAVE_STDDEF_H
! #       include <stddef.h>
! #       if defined  __cplusplus
! extern "C" void *alloca (size_t);
! #       else
! extern void *alloca (size_t);
! #       endif
! #      else
! extern void *alloca ();
! #      endif
! #     else
! extern char *alloca ();
! #     endif
! #    endif
! #   endif
  #  endif
! # endif
! #endif
Index: bfd/elf32-m68hc1x.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m68hc1x.c,v
retrieving revision 1.33
diff -u -p -r1.33 elf32-m68hc1x.c
--- bfd/elf32-m68hc1x.c	12 Mar 2008 08:36:59 -0000	1.33
+++ bfd/elf32-m68hc1x.c	18 Mar 2009 06:06:49 -0000
@@ -20,6 +20,7 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+#include "alloca-conf.h"
 #include "sysdep.h"
 #include "bfd.h"
 #include "bfdlink.h"
Index: bfd/elf64-hppa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-hppa.c,v
retrieving revision 1.90
diff -u -p -r1.90 elf64-hppa.c
--- bfd/elf64-hppa.c	1 Mar 2009 17:08:54 -0000	1.90
+++ bfd/elf64-hppa.c	18 Mar 2009 06:06:59 -0000
@@ -19,6 +19,7 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+#include "alloca-conf.h"
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
@@ -27,31 +28,6 @@
 #include "libhppa.h"
 #include "elf64-hppa.h"
 
-/* This is the code recommended in the autoconf documentation, almost
-   verbatim.  */
-#ifndef __GNUC__
-# if HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  ifdef _AIX
-/* Indented so that pre-ansi C compilers will ignore it, rather than
-   choke on it.  Some versions of AIX require this to be the first
-   thing in the file.  */
- #pragma alloca
-#  else
-#   ifndef alloca /* predefined by HP cc +Olibcalls */
-#    if !defined (__STDC__) && !defined (__hpux)
-extern char *alloca ();
-#    else
-extern void *alloca ();
-#    endif /* __STDC__, __hpux */
-#   endif /* alloca */
-#  endif /* _AIX */
-# endif /* HAVE_ALLOCA_H */
-#else
-extern void *alloca (size_t);
-#endif /* __GNUC__ */
-
 
 #define ARCH_SIZE	       64
 
Index: bfd/som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.72
diff -u -p -r1.72 som.c
--- bfd/som.c	7 Mar 2009 23:38:13 -0000	1.72
+++ bfd/som.c	18 Mar 2009 06:07:20 -0000
@@ -23,6 +23,7 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    02110-1301, USA.  */
 
+#include "alloca-conf.h"
 #include "sysdep.h"
 #include "bfd.h"
 
@@ -37,32 +38,6 @@
 #include <machine/reg.h>
 #include <sys/file.h>
 
-/* This is the code recommended in the autoconf documentation, almost
-   verbatim.  */
-
-#ifndef __GNUC__
-# if HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  ifdef _AIX
-/* Indented so that pre-ansi C compilers will ignore it, rather than
-   choke on it.  Some versions of AIX require this to be the first
-   thing in the file.  */
- #pragma alloca
-#  else
-#   ifndef alloca /* predefined by HP cc +Olibcalls */
-#    if !defined (__STDC__) && !defined (__hpux)
-extern char *alloca ();
-#    else
-extern void *alloca ();
-#    endif /* __STDC__, __hpux */
-#   endif /* alloca */
-#  endif /* _AIX */
-# endif /* HAVE_ALLOCA_H */
-#else
-extern void *alloca (size_t);
-#endif /* __GNUC__ */
-
 static bfd_reloc_status_type hppa_som_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 static bfd_boolean som_mkobject (bfd *);
Index: bfd/xsym.c
===================================================================
RCS file: /cvs/src/src/bfd/xsym.c,v
retrieving revision 1.23
diff -u -p -r1.23 xsym.c
--- bfd/xsym.c	30 Jul 2008 04:34:56 -0000	1.23
+++ bfd/xsym.c	18 Mar 2009 06:07:20 -0000
@@ -19,6 +19,7 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+#include "alloca-conf.h"
 #include "sysdep.h"
 #include "xsym.h"
 #include "bfd.h"
Index: binutils/sysdep.h
===================================================================
RCS file: /cvs/src/src/binutils/sysdep.h,v
retrieving revision 1.6
diff -u -p -r1.6 sysdep.h
--- binutils/sysdep.h	3 Feb 2009 15:48:50 -0000	1.6
+++ binutils/sysdep.h	18 Mar 2009 06:07:27 -0000
@@ -22,7 +22,7 @@
 #ifndef _BIN_SYSDEP_H
 #define _BIN_SYSDEP_H
 
-#include "config.h"
+#include "alloca-conf.h"
 #include "ansidecl.h"
 #include <stdio.h>
 #include <sys/types.h>
@@ -123,23 +123,6 @@ extern int vsnprintf(char *, size_t, con
 #define SEEK_END 2
 #endif
 
-#if defined(__GNUC__) && !defined(C_ALLOCA)
-# undef alloca
-# define alloca __builtin_alloca
-#else
-# if defined(HAVE_ALLOCA_H) && !defined(C_ALLOCA)
-#  include <alloca.h>
-# else
-#  ifndef alloca /* predefined by HP cc +Olibcalls */
-#   if !defined (__STDC__) && !defined (__hpux)
-char *alloca ();
-#   else
-void *alloca ();
-#   endif /* __STDC__, __hpux */
-#  endif /* alloca */
-# endif /* HAVE_ALLOCA_H */
-#endif
-
 #ifdef HAVE_LOCALE_H
 # ifndef ENABLE_NLS
    /* The Solaris version of locale.h always includes libintl.h.  If we have
Index: gas/as.h
===================================================================
RCS file: /cvs/src/src/gas/as.h,v
retrieving revision 1.61
diff -u -p -r1.61 as.h
--- gas/as.h	12 Aug 2008 23:39:30 -0000	1.61
+++ gas/as.h	18 Mar 2009 06:07:32 -0000
@@ -36,36 +36,7 @@
   	COMMON as "".
    If TEST is #defined, then we are testing a module: #define COMMON as "".  */
 
-#include "config.h"
-
-/* This is the code recommended in the autoconf documentation, almost
-   verbatim.  If it doesn't work for you, let me know, and notify
-   djm@gnu.ai.mit.edu as well.  */
-/* Added void* version for STDC case.  This is to be compatible with
-   the declaration in bison.simple, used for m68k operand parsing.
-   --KR 1995.08.08 */
-/* Force void* decl for hpux.  This is what Bison uses.  --KR 1995.08.16 */
-
-#ifndef __GNUC__
-# if HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  ifdef _AIX
-/* Indented so that pre-ansi C compilers will ignore it, rather than
-   choke on it.  Some versions of AIX require this to be the first
-   thing in the file.  */
- #pragma alloca
-#  else
-#   ifndef alloca /* predefined by HP cc +Olibcalls */
-#    if !defined (__STDC__) && !defined (__hpux)
-extern char *alloca ();
-#    else
-extern void *alloca ();
-#    endif /* __STDC__, __hpux */
-#   endif /* alloca */
-#  endif /* _AIX */
-# endif /* HAVE_ALLOCA_H */
-#endif /* __GNUC__ */
+#include "alloca-conf.h"
 
 /* Prefer varargs for non-ANSI compiler, since some will barf if the
    ellipsis definition is used with a no-arguments declaration.  */
Index: opcodes/openrisc-opc.c
===================================================================
RCS file: /cvs/src/src/opcodes/openrisc-opc.c,v
retrieving revision 1.12
diff -u -p -r1.12 openrisc-opc.c
--- opcodes/openrisc-opc.c	5 Jul 2007 09:49:02 -0000	1.12
+++ opcodes/openrisc-opc.c	18 Mar 2009 06:08:06 -0000
@@ -671,7 +671,10 @@ openrisc_cgen_init_opcode_table (CGEN_CP
   const CGEN_OPCODE *oc = & openrisc_cgen_macro_insn_opcode_table[0];
   CGEN_INSN *insns = xmalloc (num_macros * sizeof (CGEN_INSN));
 
-  memset (insns, 0, num_macros * sizeof (CGEN_INSN));
+  /* This test has been added to avoid a warning generated
+     if memset is called with a third argument of value zero.  */
+  if (num_macros >= 1)
+    memset (insns, 0, num_macros * sizeof (CGEN_INSN));
   for (i = 0; i < num_macros; ++i)
     {
       insns[i].base = &ib[i];
Index: ld/ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.42
diff -u -p -r1.42 ld.h
--- ld/ld.h	26 Jan 2009 15:23:39 -0000	1.42
+++ ld/ld.h	18 Mar 2009 08:13:20 -0000
@@ -32,24 +32,6 @@
 #define SEEK_END 2
 #endif
 
-#if defined(__GNUC__) && !defined(C_ALLOCA)
-# undef alloca
-# define alloca __builtin_alloca
-#else
-# if defined(HAVE_ALLOCA_H) && !defined(C_ALLOCA)
-#  include <alloca.h>
-# else
-#  ifndef alloca /* predefined by HP cc +Olibcalls */
-#   if !defined (__STDC__) && !defined (__hpux)
-char *alloca ();
-#   else
-void *alloca ();
-#   endif /* __STDC__, __hpux */
-#  endif /* alloca */
-# endif /* HAVE_ALLOCA_H */
-#endif
-
-
 #ifdef HAVE_LOCALE_H
 # ifndef ENABLE_NLS
    /* The Solaris version of locale.h always includes libintl.h.  If we have

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list