elf.c:3701: off += (m->sections[0]->vma - off) % bed->maxpagesize

Andrew Cagney cagney@gnu.org
Wed Jan 21 16:51:00 GMT 2004

> Probably easiest to just cast OFF to ufile_ptr.

I'm testing a function that looks something like:

/* Ian Lance Taylor writes:

    We shouldn't be using % with a negative signed number.  That's just
    not good.  We have to make sure either that the number is not
    negative, or that the number has an unsigned type.  When the types
    are all the same size they wind up as unsigned.  When file_ptr is a
    larger signed type, the arithmetic winds up as signed long long,
    which is wrong.

    What we're trying to say here is something like ``increase OFF by
    the least amount that will cause it to be equal to the VMA modulo
    the page size.''  */
/* In other words, something like:

    vma_offset = m->sections[0]->vma % bed->maxpagesize;
    off_offset = off % bed->maxpagesize;
    if (vma_offset < off_offset)
      adjustment = vma_offset + bed->maxpagesize - off_offset;
      adjustment = vma_offset - off_offset;

    this can be colapsed into the expression below.  */
static ufile_ptr
offset_vma_page_adjustment (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize)
   return ((vma - off) % maxpagesize);

> I doubt there is much of this sort of arithmetic--though of course it
> appears again 15 lines lower in the function.

as I've so far stumbled across ~6 occurances of that math (yes, couldn't 
miss the one 15 lines below :-).  Look ok?

Sill doesn't work but:

00000040 D data_end
00000020 D data_start
00000020 A sizeof_data
00000020 A sizeof_text
00000010 T text_end
00000000 T text_start

note the value of sizeof_text.


More information about the Binutils mailing list