This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: bfd/elf.c: more wrap/overlap/overflow weirdness
> + /* A wrapping section potentially clashes with header. */
> + if (((s->lma + s->size) & addr_mask) < (s->lma & addr_mask))
> + wrap_to = (s->lma + s->size) & addr_mask;
If a section is non-empty and ends *at* the end of the target memory,
wrap_to is zero...
> + || (sections[0]->lma & addr_mask & -maxpagesize) < wrap_to)
...and is that test wrong?
This is what I've got so far, but I suspect this code needs an
addrmask just like yours...
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.515
diff -p -U3 -r1.515 elf.c
--- elf.c 18 Aug 2010 12:24:05 -0000 1.515
+++ elf.c 27 Aug 2010 02:19:20 -0000
@@ -4467,14 +4467,24 @@ assign_file_positions_for_load_sections
bfd_vma p_start = p->p_paddr;
bfd_vma p_end = p_start + p->p_memsz;
bfd_vma s_start = sec->lma;
+ bfd_vma s_end = sec->lma + sec->size;
bfd_vma adjust = s_start - p_end;
+ if (sec->size > 0
+ && (s_end - 1) < s_start)
+ {
+ (*_bfd_error_handler)
+ (_("%B: warning: section %A lma wraps from %#lx to %#lx"), abfd, sec,
+ (unsigned long) s_start, (unsigned long) s_end);
+ }
+
if (s_start < p_end
|| p_end < p_start)
{
- (*_bfd_error_handler)
- (_("%B: section %A lma %#lx adjusted to %#lx"), abfd, sec,
- (unsigned long) s_start, (unsigned long) p_end);
+ if (sec->lma != p_end)
+ (*_bfd_error_handler)
+ (_("%B: section %A lma %#lx adjusted to %#lx"), abfd, sec,
+ (unsigned long) s_start, (unsigned long) p_end);
adjust = 0;
sec->lma = p_end;
}