This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [Patch]: Fix bfd_get_arch_size for non-ELF targets
- From: Tristan Gingold <gingold at adacore dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: "binutils at sourceware dot org Development" <binutils at sourceware dot org>
- Date: Thu, 3 Apr 2014 14:48:35 +0200
- Subject: Re: [Patch]: Fix bfd_get_arch_size for non-ELF targets
- Authentication-results: sourceware.org; auth=none
- References: <DD667986-BF49-448D-B70E-B9548BC540B0 at adacore dot com> <20140403123458 dot GD18201 at bubble dot grove dot modra dot org>
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;
}
/*