This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [Patch]: fix bfd/targets.c build failure on AIX
On Wed, Nov 18, 2009 at 12:58:23AM +1030, Alan Modra wrote:
> On Tue, Nov 17, 2009 at 02:00:48PM +0100, Tristan Gingold wrote:
> > So, do we accept alloca in targets.c ?
>
> I think we could easily use a fixed size buffer, since the code in
> bfd_get_target_info is using alloca for (part of) target_vec->name.
> The largest target_vec->name is currently 24 chars. A buffer twice
> that size should be ample.
>
> > Maybe we should also clearly document in alloca-conf.h that this
> > file must be the first include.
>
> We do have a comment that says in part: "Some versions of AIX require
> this to be the first thing in the file except for comments and
> preprocessor directives."
>
> s/in the file/seen by the compiler/ would be clearer.
Applying.
include/
* alloca-conf.h: Clarify comment.
bfd/
* targets.c: Don't include alloca-conf.h.
(bfd_get_target_info): Don't use alloca.
Index: include/alloca-conf.h
===================================================================
RCS file: /cvs/src/src/include/alloca-conf.h,v
retrieving revision 1.2
diff -u -p -r1.2 alloca-conf.h
--- include/alloca-conf.h 18 Mar 2009 11:27:16 -0000 1.2
+++ include/alloca-conf.h 17 Nov 2009 23:08:45 -0000
@@ -15,7 +15,8 @@
# 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. */
+ thing seen by the compiler except for comments and preprocessor
+ directives. */
#pragma alloca
# else
# if defined _MSC_VER && !defined C_ALLOCA
Index: bfd/targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.181
diff -u -p -r1.181 targets.c
--- bfd/targets.c 17 Nov 2009 10:54:20 -0000 1.181
+++ bfd/targets.c 17 Nov 2009 23:07:47 -0000
@@ -25,7 +25,6 @@
#include "bfd.h"
#include "libbfd.h"
#include "fnmatch.h"
-#include "alloca-conf.h"
/*
It's okay to see some:
@@ -1523,7 +1522,8 @@ bfd_get_target_info (const char *target_
for triplets like "pe-arm-wince-little". */
if (!_bfd_find_arch_match (tname, arches, def_target_arch))
{
- char *new_tname = (char *) alloca (strlen (hyp) + 1);
+ char new_tname[50];
+
strcpy (new_tname, hyp);
while ((hyp = strrchr (new_tname, '-')) != NULL)
{
--
Alan Modra
Australia Development Lab, IBM