X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Flibbfd.c;h=a225397c3e780fd18b39c940d19f78edd3fad542;hb=6bba1048d63e0476b94b9934527defd81c590a13;hp=b2f83c4503062b17763b54cf320283a3d3cc77e0;hpb=c0c28ab8b2757069a1abf73fcb4714f077e76995;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/libbfd.c b/bfd/libbfd.c index b2f83c4503..a225397c3e 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -1,6 +1,6 @@ /* Assorted BFD support routines, only used internally. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004 + 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. Written by Cygnus Support. @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -18,10 +18,11 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ -#include "bfd.h" #include "sysdep.h" +#include "bfd.h" #include "libbfd.h" #ifndef HAVE_GETPAGESIZE @@ -30,6 +31,9 @@ /* SECTION + Implementation details + +SUBSECTION Internal functions DESCRIPTION @@ -100,6 +104,23 @@ bfd_void (bfd *ignore ATTRIBUTE_UNUSED) { } +long +_bfd_norelocs_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, + asection *sec ATTRIBUTE_UNUSED) +{ + return sizeof (arelent *); +} + +long +_bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED, + asection *sec ATTRIBUTE_UNUSED, + arelent **relptr, + asymbol **symbols ATTRIBUTE_UNUSED) +{ + *relptr = NULL; + return 0; +} + bfd_boolean _bfd_nocore_core_file_matches_executable_p (bfd *ignore_core_bfd ATTRIBUTE_UNUSED, @@ -156,6 +177,36 @@ bfd_malloc (bfd_size_type size) return ptr; } +/* Allocate memory using malloc, nmemb * size with overflow checking. */ + +void * +bfd_malloc2 (bfd_size_type nmemb, bfd_size_type size) +{ + void *ptr; + + if ((nmemb | size) >= HALF_BFD_SIZE_TYPE + && size != 0 + && nmemb > ~(bfd_size_type) 0 / size) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + size *= nmemb; + + if (size != (size_t) size) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + ptr = malloc ((size_t) size); + if (ptr == NULL && (size_t) size != 0) + bfd_set_error (bfd_error_no_memory); + + return ptr; +} + /* Reallocate memory using realloc. */ void * @@ -180,6 +231,68 @@ bfd_realloc (void *ptr, bfd_size_type size) return ret; } +/* Reallocate memory using realloc, nmemb * size with overflow checking. */ + +void * +bfd_realloc2 (void *ptr, bfd_size_type nmemb, bfd_size_type size) +{ + void *ret; + + if ((nmemb | size) >= HALF_BFD_SIZE_TYPE + && size != 0 + && nmemb > ~(bfd_size_type) 0 / size) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + size *= nmemb; + + if (size != (size_t) size) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + if (ptr == NULL) + ret = malloc ((size_t) size); + else + ret = realloc (ptr, (size_t) size); + + if (ret == NULL && (size_t) size != 0) + bfd_set_error (bfd_error_no_memory); + + return ret; +} + +/* Reallocate memory using realloc. + If this fails the pointer is freed before returning. */ + +void * +bfd_realloc_or_free (void *ptr, bfd_size_type size) +{ + size_t amount = (size_t) size; + void *ret; + + if (size != amount) + ret = NULL; + else if (ptr == NULL) + ret = malloc (amount); + else + ret = realloc (ptr, amount); + + if (ret == NULL) + { + if (amount > 0) + bfd_set_error (bfd_error_no_memory); + + if (ptr != NULL) + free (ptr); + } + + return ret; +} + /* Allocate memory using malloc and clear it. */ void * @@ -205,6 +318,44 @@ bfd_zmalloc (bfd_size_type size) return ptr; } + +/* Allocate memory using malloc (nmemb * size) with overflow checking + and clear it. */ + +void * +bfd_zmalloc2 (bfd_size_type nmemb, bfd_size_type size) +{ + void *ptr; + + if ((nmemb | size) >= HALF_BFD_SIZE_TYPE + && size != 0 + && nmemb > ~(bfd_size_type) 0 / size) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + size *= nmemb; + + if (size != (size_t) size) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + ptr = malloc ((size_t) size); + + if ((size_t) size != 0) + { + if (ptr == NULL) + bfd_set_error (bfd_error_no_memory); + else + memset (ptr, 0, (size_t) size); + } + + return ptr; +} + /* INTERNAL_FUNCTION bfd_write_bigendian_4byte_int @@ -697,7 +848,8 @@ _bfd_generic_get_section_contents (bfd *abfd, return TRUE; sz = section->rawsize ? section->rawsize : section->size; - if (offset + count > sz) + if (offset + count < count + || offset + count > sz) { bfd_set_error (bfd_error_invalid_operation); return FALSE; @@ -865,12 +1017,12 @@ warn_deprecated (const char *what, bfd_vma read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED, - char *buf, + bfd_byte *buf, unsigned int *bytes_read_ptr) { bfd_vma result; unsigned int num_read; - int shift; + unsigned int shift; unsigned char byte; result = 0; @@ -878,7 +1030,7 @@ read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED, num_read = 0; do { - byte = bfd_get_8 (abfd, (bfd_byte *) buf); + byte = bfd_get_8 (abfd, buf); buf++; num_read++; result |= (((bfd_vma) byte & 0x7f) << shift); @@ -893,12 +1045,12 @@ read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED, bfd_signed_vma read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED, - char *buf, - unsigned int * bytes_read_ptr) + bfd_byte *buf, + unsigned int *bytes_read_ptr) { bfd_vma result; - int shift; - int num_read; + unsigned int shift; + unsigned int num_read; unsigned char byte; result = 0; @@ -906,15 +1058,35 @@ read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED, num_read = 0; do { - byte = bfd_get_8 (abfd, (bfd_byte *) buf); + byte = bfd_get_8 (abfd, buf); buf ++; num_read ++; result |= (((bfd_vma) byte & 0x7f) << shift); shift += 7; } while (byte & 0x80); - if ((shift < 8 * sizeof (result)) && (byte & 0x40)) + if (shift < 8 * sizeof (result) && (byte & 0x40)) result |= (((bfd_vma) -1) << shift); *bytes_read_ptr = num_read; return result; } + +bfd_boolean +_bfd_generic_find_line (bfd *abfd ATTRIBUTE_UNUSED, + asymbol **symbols ATTRIBUTE_UNUSED, + asymbol *symbol ATTRIBUTE_UNUSED, + const char **filename_ptr ATTRIBUTE_UNUSED, + unsigned int *linenumber_ptr ATTRIBUTE_UNUSED) +{ + return FALSE; +} + +bfd_boolean +_bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED, + asection *isec ATTRIBUTE_UNUSED, + bfd *obfd ATTRIBUTE_UNUSED, + asection *osec ATTRIBUTE_UNUSED, + struct bfd_link_info *link_info ATTRIBUTE_UNUSED) +{ + return TRUE; +}