mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-19 09:14:14 +08:00
Don't use "long" in readelf for file offsets
The aim here is to improve readelf handling of large 64-bit object files on LLP64 hosts (Windows) where long is only 32 bits. The patch changes more than just file offsets. Addresses and sizes are also changed to avoid "long". Most places get to use uint64_t even where size_t may be more appropriate, because that allows some overflow checks to be implemented easily (*alloc changes). * dwarf.c (cmalloc, xcmalloc, xcrealloc, xcalloc2): Make nmemb parameter uint64_t. * dwarf.h: Update prototypes. (struct dwarf_section): Make num_relocs uint64_t. * elfcomm.c (setup_archive): Update error format. * elfcomm.h (struct archive_info): Make sym_size, longnames_size, nested_member_origin, next_arhdr_offset uint64_t. * readelf.c (struct filedata): Make archive_file_offset, archive_file_size, string_table_length, dynamic_addr, dynamic_nent, dynamic_strings_length, num_dynamic_syms, dynamic_syminfo_offset uint64_t. (many functions): Replace uses of "unsigned long" with "uint64_t" or "size_t".
This commit is contained in:
@ -11082,7 +11082,7 @@ display_debug_not_supported (struct dwarf_section *section,
|
||||
Note: does *not* initialise the allocated memory to zero. */
|
||||
|
||||
void *
|
||||
cmalloc (size_t nmemb, size_t size)
|
||||
cmalloc (uint64_t nmemb, size_t size)
|
||||
{
|
||||
/* Check for overflow. */
|
||||
if (nmemb >= ~(size_t) 0 / size)
|
||||
@ -11096,13 +11096,13 @@ cmalloc (size_t nmemb, size_t size)
|
||||
Note: does *not* initialise the allocated memory to zero. */
|
||||
|
||||
void *
|
||||
xcmalloc (size_t nmemb, size_t size)
|
||||
xcmalloc (uint64_t nmemb, size_t size)
|
||||
{
|
||||
/* Check for overflow. */
|
||||
if (nmemb >= ~(size_t) 0 / size)
|
||||
{
|
||||
fprintf (stderr,
|
||||
_("Attempt to allocate an array with an excessive number of elements: %#zx\n"),
|
||||
_("Attempt to allocate an array with an excessive number of elements: %#" PRIx64 "\n"),
|
||||
nmemb);
|
||||
xexit (1);
|
||||
}
|
||||
@ -11115,12 +11115,12 @@ xcmalloc (size_t nmemb, size_t size)
|
||||
Note: does *not* initialise any new memory to zero. */
|
||||
|
||||
void *
|
||||
xcrealloc (void *ptr, size_t nmemb, size_t size)
|
||||
xcrealloc (void *ptr, uint64_t nmemb, size_t size)
|
||||
{
|
||||
/* Check for overflow. */
|
||||
if (nmemb >= ~(size_t) 0 / size)
|
||||
{
|
||||
error (_("Attempt to re-allocate an array with an excessive number of elements: %#zx\n"),
|
||||
error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64 "\n"),
|
||||
nmemb);
|
||||
xexit (1);
|
||||
}
|
||||
@ -11131,12 +11131,12 @@ xcrealloc (void *ptr, size_t nmemb, size_t size)
|
||||
/* Like xcalloc, but verifies that the first parameter is not too large. */
|
||||
|
||||
void *
|
||||
xcalloc2 (size_t nmemb, size_t size)
|
||||
xcalloc2 (uint64_t nmemb, size_t size)
|
||||
{
|
||||
/* Check for overflow. */
|
||||
if (nmemb >= ~(size_t) 0 / size)
|
||||
{
|
||||
error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#zx\n"),
|
||||
error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64 "\n"),
|
||||
nmemb);
|
||||
xexit (1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user