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: bfd/elf.c: more wrap/overlap/overflow weirdness


On Fri, Aug 20, 2010 at 03:45:45PM -0400, DJ Delorie wrote:
> 
> If .data wraps around 0xffffffff, the next section appended to it
> triggers the "p_end < p_start" test, but the LMA does *not* change,
> making the warning message useless.  There's also no warning for the
> wrapped section.

I think things have gone haywire before you get to this code.  If I
build your testcase with an x86 linker, with 64-bit vmas, I see

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0xffff8000 0xffff8000 0x07e34 0x07e34 R E 0x1000
  LOAD           0x009001 0x00001001 0xfffffe34 0x008e6 0x048e7 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata 
   01     .data .bss 

No errors..

          lma      end lma    vma  end vma
.text    ffff8000  ffffb558
.rodata  ffffb558  fffffe34
.data    fffffe34 10000071a   1001 18e7
.bss    10000071b 10000471b   18e8 58e8

Now, if I build with an x86 linker without 64-bit vmas, we get three
segments.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x00001000 0xfffffe33 0x00094 0x048e8 RW  0x1000
  LOAD           0x001000 0xffff8000 0xffff8000 0x07e34 0x07e34 R E 0x1000
  LOAD           0x009001 0x00001001 0xfffffe34 0x008e6 0x008e6 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .bss 
   01     .text .rodata 
   02     .data 

The fact we get three segments isn't that surprising  .bss lma (of
71b) is way different from other section lmas.  The trouble is that
.bss is being packed into a segment containing the ELF header and
sections headers.  Notice the weird p_paddr which overlaps the last
header p_paddr.

> This patch checks for the two cases separately - a warning if a
> section's load data wraps, and an extra test to see if the LMA
> actually changes.

I could argue the bss lma has changed, from 0x10000071b to 0x71b.  ;-)

> Does it even make sense to warn about section wrapping?

I don't know.  I do know that you'd want to make sure the warning
didn't trigger on a section right at the end of memory.

-- 
Alan Modra
Australia Development Lab, IBM


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