This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch]: Fix bfd_get_arch_size for non-ELF targets


On 03 Apr 2014, at 14:34, Alan Modra <amodra@gmail.com> wrote:

> On Thu, Apr 03, 2014 at 12:09:04PM +0200, Tristan Gingold wrote:
>> --- a/bfd/bfd.c
>> +++ b/bfd/bfd.c
>> @@ -1087,7 +1087,7 @@ bfd_get_arch_size (bfd *abfd)
>>   if (abfd->xvec->flavour == bfd_target_elf_flavour)
>>     return get_elf_backend_data (abfd)->s->arch_size;
>> 
>> -  return -1;
>> +  return bfd_arch_bits_per_address (abfd);
> 
> This might be better:
>  return bfd_arch_bits_per_address (abfd) > 32 ? 64 : 32;
> 
> On more than one target, bfd_arch_bits_per_address will return 16,
> and more than one target returns 24.  So your patch would mean you
> need to change the test in objdump.c, and you'd break
> nm.c:set_print_width.

You're right.  I have also adjusted the spec of that function.

Is that ok ?

Tristan.

bfd/
	* bfd.c (bfd_get_arch_size): Default is taken from arch.


diff --git a/bfd/bfd.c b/bfd/bfd.c
index 6b00592..41de1bb 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1073,9 +1073,11 @@ SYNOPSIS
  	int bfd_get_arch_size (bfd *abfd);
 
 DESCRIPTION
-	Returns the architecture address size, in bits, as determined
-	by the object file's format.  For ELF, this information is
-	included in the header.
+	Returns the normalized architecture address size, in bits, as
+	determined by the object file's format.  By normalized, we mean
+	either 32 or 64.  For ELF, this information is included in the
+	header.  Use bfd_arch_bits_per_address for number of bits in
+	the architecture address.
 
 RETURNS
 	Returns the arch size in bits if known, <<-1>> otherwise.
@@ -1087,7 +1089,7 @@ bfd_get_arch_size (bfd *abfd)
   if (abfd->xvec->flavour == bfd_target_elf_flavour)
     return get_elf_backend_data (abfd)->s->arch_size;
 
-  return -1;
+  return bfd_arch_bits_per_address (abfd) > 32 ? 64 : 32;
 }
 
 /*


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]