This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch]: Fix base-file and relocation for w64
- From: Kai Tietz <Kai dot Tietz at onevision dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: binutils at sourceware dot org, Nick Clifton <nickc at redhat dot com>, NightStrike at gmail dot com
- Date: Thu, 2 Oct 2008 09:43:32 +0200
- Subject: Re: [patch]: Fix base-file and relocation for w64
Hi Andreas,
Andreas Schwab <schwab@suse.de> wrote on 01.10.2008 17:20:20:
> Kai Tietz <Kai.Tietz@onevision.com> writes:
>
> > @@ -1584,18 +1584,18 @@ dump_def_info (FILE *f)
> > static int
> > sfunc (const void *a, const void *b)
> > {
> > - return *(const long *) a - *(const long *) b;
> > + return (int) (*(const bfd_vma *) a - *(const bfd_vma *) b);
>
> This will overflow.
I can't see this problem here. But I agree that for addresses with deltas
higher then 2^31 an overflow could happen here. But even the old
expression for 32-bit has this disadvantages, too. If the addresses have a
delta of 2^31 the sorting order seems to be wrong. E.g. For a=0x80000000
and b=0, this function will say, that a is less than b, which in terms of
memory orginization isn't true.
But I agree that a rewrite of this method as:
@@ -1584,18 +1584,18 @@ dump_def_info (FILE *f)
static int
sfunc (const void *a, const void *b)
{
- return *(const long *) a - *(const long *) b;
+ return ((*(const bfd_vma *) a == *(const bfd_vma *) b) ? 0 :
+ ((*(const bfd_vma *) a > *(const bfd_vma *) b) ? 1 : -1));
more correct and will sort things proper, too.
Cheers,
Kai
| (\_/) This is Bunny. Copy and paste Bunny
| (='.'=) into your signature to help him gain
| (")_(") world domination.