From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thiemo Seufer To: binutils@sources.redhat.com Subject: Re: [PATCH] Include alloca.h for bfd Date: Thu, 23 Aug 2001 08:48:00 -0000 Message-id: <20010823174716.E3542@rembrandt.csv.ica.uni-stuttgart.de> References: <20010821210909.E30301@rembrandt.csv.ica.uni-stuttgart.de> <20010821234604.J30301@rembrandt.csv.ica.uni-stuttgart.de> X-SW-Source: 2001-08/msg00534.html Nick Clifton wrote: > Hi Thiemo, Hi Ian, > > > In the past I did not permit alloca to be used in BFD, because on > > systems which do not have alloca the version in libiberty would call > > xmalloc, which might cause the program to crash when it ran out of > > memory. I believe that BFD should never crash because it runs out of > > memory; instead, it should return the appropriate error to the caller. > > (That's why I wrote the objalloc interface when obstacks were changed > > to no longer support a failure to allocate memory.) However, I do not > > know what the current thinking is on alloca in BFD. > > I agree with your policy. I was unaware of the problems involved with > using alloca, which is why I did not enforce the rule as you used to > do. Now that I am aware of it I will try to enforce it in the future > and also remove the current uses of alloca. > > Thiemo - rather than including alloca.h how about changing the code in > linker.c to use objalloc_alloc() instead ? It's a simple string, so I used bfd_malloc. Thiemo 2001-08-23 Thiemo Seufer /bfd/ChangeLog * linker.c (_bfd_generic_link_add_archive_symbols): Replace alloca() by bfd_malloc(). diff -BurpNX /bigdisk/src/binutils-exclude src-orig/bfd/linker.c src/bfd/linker.c --- src-orig/bfd/linker.c Sat Aug 18 21:47:22 2001 +++ src/bfd/linker.c Thu Aug 23 17:14:45 2001 @@ -1007,9 +1007,10 @@ _bfd_generic_link_add_archive_symbols (a let's look for its import thunk */ if (info->pei386_auto_import) { - char *buf = alloca (strlen (h->root.string) + 10); + char *buf = (char *) bfd_malloc (strlen (h->root.string) + 10); sprintf (buf, "__imp_%s", h->root.string); arh = archive_hash_lookup (&arsym_hash, buf, false, false); + free(buf); } if (arh == (struct archive_hash_entry *) NULL) {