Bug 5146 - bfd build fails in alloca-conf.h when built without gcc
Summary: bfd build fails in alloca-conf.h when built without gcc
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-09 08:09 UTC by Michael Haubenwallner
Modified: 2007-12-29 01:48 UTC (History)
1 user (show)

See Also:
Host: hppa2.0w-hp-hpux11.11
Target: hppa2.0w-hp-hpux11.11
Build: hppa2.0w-hp-hpux11.11
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Haubenwallner 2007-10-09 08:09:03 UTC
When building binutils-2.18 with native cc on hppa-hpux11.11,
include/alloca-conf.h fails to correctly include <alloca.h>, or to define 'PTR'
when included in bfd/som.c:

libtool: compile:  cc -Wp,-H256000 -DHAVE_CONFIG_H -I.
-I/source/binutils-2.18/bfd -I. -DHOST_HPPAHPUX -D_LARGEFILE64_SOURCE
-DHPUX_CORE -I. -I/source/binutils-2.18/bfd
-I/source/binutils-2.18/bfd/../include -O3 -c /source/binutils-2.18/bfd/som.c -o
som.o
cc: "/source/binutils-2.18/bfd/../include/alloca-conf.h", line 15: error 1000:
Unexpected symbol: "alloca".
cc: panic 2017: Cannot recover from earlier errors, terminating.
gmake[4]: *** [som.lo] Error 1
gmake[4]: Leaving directory `/build/binutils-2.18/bfd'
gmake[3]: *** [all-recursive] Error 1
gmake[3]: Leaving directory `/build/binutils-2.18/bfd'
gmake[2]: *** [all] Error 2 
gmake[2]: Leaving directory `/build/binutils-2.18/bfd'
gmake[1]: *** [all-bfd] Error 2
gmake[1]: Leaving directory `/build/binutils-2.18'
gmake: *** [all] Error 2

This line 15 is
  extern PTR alloca (size_t);

The problem causing cc to fail is that 'PTR' is not typedef'd or defined before
- don't know where this should be done.

Instead, <alloca.h> could be used here, but bfd/configure.in does not check for
"alloca.h":

--- binutils-2.18/bfd/configure.in.orig 2007-10-09 09:35:46.626269000 +0200
+++ binutils-2.18/bfd/configure.in  2007-10-09 09:36:41.264676000 +0200
@@ -159,7 +159,7 @@

 BFD_CC_FOR_BUILD

-AC_CHECK_HEADERS(stddef.h string.h strings.h stdlib.h time.h unistd.h)
+AC_CHECK_HEADERS(alloca.h stddef.h string.h strings.h stdlib.h time.h unistd.h)
 AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h)
 GCC_HEADER_STDINT(bfd_stdint.h)
 AC_HEADER_TIME
Comment 1 Nick Clifton 2007-10-12 16:47:25 UTC
Subject: Re:  New: bfd build fails in alloca-conf.h when
 built without gcc

Hi Michael,

> When building binutils-2.18 with native cc on hppa-hpux11.11,
> include/alloca-conf.h fails to correctly include <alloca.h>, or to define 'PTR'
> when included in bfd/som.c.

Hmm, the problem here, it seems to me, is the alloca-conf.h header using PTR 
when it is not defined.  (It is defined in include/ansidecl.h, but 
alloca-conf.h does not include that header).

Fixing the bfd configure script so that the system alloca.h is used instead 
does not seem to me to be sufficient - the problem can still arise in other 
build directories.  So please could you try out the patch below (which fixes 
the header itself) and let me know if it works for you ?

Cheers
   Nick

Index: include/alloca-conf.h
===================================================================
RCS file: /cvs/src/src/include/alloca-conf.h,v
retrieving revision 1.1
diff -c -3 -p -r1.1 alloca-conf.h
*** include/alloca-conf.h	28 Sep 2000 08:00:54 -0000	1.1
--- include/alloca-conf.h	12 Oct 2007 16:42:35 -0000
***************
*** 12,20 ****
   #   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
--- 12,20 ----
   #   include <alloca.h>
   #  else /* ! defined (HAVE_ALLOCA_H) */
   #   ifdef __STDC__
! extern void * alloca (size_t);
   #   else /* ! defined (__STDC__) */
! extern char * alloca ();
   #   endif /* ! defined (__STDC__) */
   #  endif /* ! defined (HAVE_ALLOCA_H) */
   #  ifdef _WIN32
Comment 2 Michael Haubenwallner 2007-10-15 09:51:38 UTC
Hi Nick,

(In reply to comment #1)

> Fixing the bfd configure script so that the system alloca.h is used instead 
> does not seem to me to be sufficient - the problem can still arise in other 
> build directories.

Did not have this problem in other directories - actually, "alloca-conf.h" is
used in bfd only.

But agreed, this is not sufficient for platforms really lacking alloca.h

> So please could you try out the patch below (which fixes 
> the header itself) and let me know if it works for you ?

With this patch only (without checking for <alloca.h> in bfd/configure), the
next unknown symbol is 'size_t':

libtool: compile:  cc -Wp,-H256000 -DHAVE_CONFIG_H -I.
-I/source/binutils-2.18/bfd -I. -DHOST_HPPAHPUX -D_LARGEFILE64_SOURCE
-DHPUX_CORE -I. -I/source/binutils-2.18/bfd
-I/source/binutils-2.18/bfd/../include -g -c /source/binutils-2.18/bfd/som.c -o
som.o
cc: "/source/binutils-2.18/bfd/../include/alloca-conf.h", line 15: error 1506:
Parameters allowed in function definition only.

So in case <alloca.h> is missing, alloca-conf.h should include both ansidecl.h
for PTR (as there is a complex #ifdef for __STDC__) as well as sys/types.h (if
available) for size_t ?

Eh, in gas/ChangeLog-9295 there is this log entry: "Replace alloca-conf.h
inclusion with code recommended in autoconf documentation."

Maybe this should be done for bfd too ?

Thanks!
/haubi/
Comment 3 Nick Clifton 2007-10-16 14:16:27 UTC
Subject: Re:  bfd build fails in alloca-conf.h when built
 without gcc

Hi Haubi,

> With this patch only (without checking for <alloca.h> in bfd/configure), the
> next unknown symbol is 'size_t':

Doh.

> Eh, in gas/ChangeLog-9295 there is this log entry: "Replace alloca-conf.h
> inclusion with code recommended in autoconf documentation."
> 
> Maybe this should be done for bfd too ?

Yup.

Please try this revised patch which changes the som.c file directly.  If it 
works for you then I will check it in along with a similar change to 
elf64-hppa.c and an update of the dependencies in bfd/Makefile.am.  (I think 
that it is best not to include this code in the bfd.h header since I do not 
want to encourage the use of alloca.  It is a poor programming tool and one 
that can lead to very mysterious and hard to track down bugs).

Cheers
   Nick


Index: bfd/som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.68
diff -c -3 -p -r1.68 som.c
*** bfd/som.c	26 Sep 2007 08:12:59 -0000	1.68
--- bfd/som.c	16 Oct 2007 14:05:42 -0000
***************
*** 23,29 ****
     Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
     02110-1301, USA.  */
  
- #include "alloca-conf.h"
  #include "sysdep.h"
  #include "bfd.h"
  
--- 23,28 ----
***************
*** 38,43 ****
--- 37,71 ----
  #include <machine/reg.h>
  #include <sys/file.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__ */
+ 
  static bfd_reloc_status_type hppa_som_reloc
    (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  static bfd_boolean som_mkobject (bfd *);
Comment 4 Michael Haubenwallner 2007-10-16 14:44:27 UTC
Well, compiling bfd/som.c succeeded, so the patch for bfd/som.c seems ok.
But linking the first executable in binutils/ now gives:
/bin/sh ./libtool --tag=CC --mode=link cc -Wp,-H256000  -g   -o size  size.o
bucomm.o version.o filemode.o ../bfd/libbfd.la ../libiberty/libiberty.a  -lm
libtool: link: cc -Wp,-H256000 -g -o size size.o bucomm.o version.o filemode.o 
../bfd/.libs/libbfd.a ../libiberty/libiberty.a -lm
/usr/ccs/bin/ld: Unsatisfied symbols:
   alloca (first referenced in ../bfd/.libs/libbfd.a(som.o)) (code)

Currently bfd/configure does _not_ check for <alloca.h> - IMO this still is
required, as that patch tests HAVE_ALLOCA_H too.
Comment 5 Nick Clifton 2007-10-16 14:55:42 UTC
Subject: Re:  bfd build fails in alloca-conf.h when built
 without gcc

Hi Haubi,

> Currently bfd/configure does _not_ check for <alloca.h> - IMO this still is
> required, as that patch tests HAVE_ALLOCA_H too.

Well bum.  OK, I'll check your patch in as well as mine, and that should take 
care of it, right ?

Cheers
   Nick


Comment 6 Michael Haubenwallner 2007-10-16 15:05:38 UTC
Hi Nick,

> Well bum.  OK, I'll check your patch in as well as mine, and that should take 
> care of it, right ?

Yep - both bfd/som.c and bfd/elf64-hppa.c get "config.h" through "sysdep.h" -
should work.
And you drop "include/alloca-conf.h" ?
OTOH, why not simply put your patch into alloca-conf.h ?

Anyway, thank you!

/haubi/
Comment 7 Nick Clifton 2007-10-16 15:18:25 UTC
Patches checked in with this ChangeLog entry.

bfd/ChangeLog
2007-10-16  Nick Clifton  <nickc@redhat.com>

	PR 5146
	* configure.in (AC_CHECK_HEADERS): Add alloca.h
	* configure: Regenerate.
	* config.in: Regenerate.
	* som.c: Replace alloca-conf.h inclusion with code recommended in
	autoconf documentation.
	* elf64-hppa.c: Likewise.
Comment 8 John David Anglin 2007-12-28 19:55:55 UTC
Native build with gcc 4.2.2 on hppa64-hp-hpux11.11 fails:

/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../src/bf
d -I. -DHOST_HPPAHPUX -D_LARGEFILE64_SOURCE -DHPUX_CORE  -DHPUX_LARGE_AR_IDS -I.
 -I../../src/bfd -I../../src/bfd/../include     -W -Wall -Wstrict-prototypes -Wm
issing-prototypes -Werror -g -O2 -c -o elf64-hppa.lo ../../src/bfd/elf64-hppa.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../src/bfd -I. -DHOST_HPPAHPUX -
D_LARGEFILE64_SOURCE -DHPUX_CORE -DHPUX_LARGE_AR_IDS -I. -I../../src/bfd -I../..
/src/bfd/../include -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g
 -O2 -c ../../src/bfd/elf64-hppa.c  -DPIC -o .libs/elf64-hppa.o
cc1: warnings being treated as errors
../../src/bfd/elf64-hppa.c: In function 'allocate_global_data_opd':
../../src/bfd/elf64-hppa.c:1189: warning: implicit declaration of function 'allo
ca'
../../src/bfd/elf64-hppa.c:1189: warning: incompatible implicit declaration of b
uilt-in function 'alloca'
../../src/bfd/elf64-hppa.c: In function 'elf64_hppa_finalize_opd':
../../src/bfd/elf64-hppa.c:2189: warning: incompatible implicit declaration of b
uilt-in function 'alloca'
make[4]: *** [elf64-hppa.lo] Error 1
Comment 9 John David Anglin 2007-12-29 01:48:14 UTC
This is now fixed for builds with gcc by the following change:
http://sources.redhat.com/ml/binutils/2007-12/msg00160.html