bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/20193] Invalid executable after adding debuglink to an exe


From: jon.turney at dronecode dot org.uk
Subject: [Bug binutils/20193] Invalid executable after adding debuglink to an executable produced after merging PE resource sections
Date: Mon, 21 Nov 2016 17:50:39 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=20193

--- Comment #11 from Jon Turney <jon.turney at dronecode dot org.uk> ---
(In reply to Nick Clifton from comment #7)

Lookng at this again, this is quite odd behaviour from the loader.  Using my
own PE dumper, which shows the VirtSize, on the testcase above:

1.exe (valid)

Name                      VirtSize   VMA        RawSize    Offset     Flags
   .text                  00000758   00001000   00000800   00000600   60500060
   .data                  00000068   00002000   00000200   00000e00   c0600040
  .rdata                  00000370   00003000   00000400   00001000   40500040
.buildid                  00000035   00004000   00000200   00001400   40300040
  .pdata                  000000d8   00005000   00000200   00001600   40300040
  .xdata                  0000007c   00006000   00000200   00001800   40300040
    .bss                  000001c0   00007000   00000000   00000000   c0600080
  .idata                  00000268   00008000   00000400   00001a00   c0300040
   .rsrc                  000010e0   00009000   00000c00   00001e00   c0300040
      /4 .debug_aranges   00000230   0000b000   00000400   00003000   42100040
     /19 .debug_info      000066a2   0000c000   00006800   00003400   42100040
     /31 .debug_abbrev    00000afc   00013000   00000c00   00009c00   42100040
     /45 .debug_line      00000e37   00014000   00001000   0000a800   42100040
     /57 .debug_frame     000002a0   00015000   00000400   0000b800   42400040
     /70 .debug_str       00000102   00016000   00000200   0000bc00   42100040
     /81 .debug_loc       00000745   00017000   00000800   0000be00   42100040
     /92 .debug_ranges    00000030   00018000   00000200   0000c600   42100040

2.exe (valid)

Name                      VirtSize   VMA        RawSize    Offset     Flags
   .text                  00000758   00001000   00000800   00000400   60500060
   .data                  00000068   00002000   00000200   00000c00   c0600040
  .rdata                  00000370   00003000   00000400   00000e00   40500040
.buildid                  00000035   00004000   00000200   00001200   40300040
  .pdata                  000000d8   00005000   00000200   00001400   40300040
  .xdata                  0000007c   00006000   00000200   00001600   40300040
    .bss                  000001c0   00007000   00000000   00000000   c0600080
  .idata                  00000268   00008000   00000400   00001800   c0300040
   .rsrc                  000010e0   00009000   00000c00   00001c00   c0300040

3.exe (invalid)

Name                      VirtSize   VMA        RawSize    Offset     Flags
   .text                  00000758   00001000   00000800   00000400   60500060
   .data                  00000068   00002000   00000200   00000c00   c0600040
  .rdata                  00000370   00003000   00000400   00000e00   40500040
.buildid                  00000035   00004000   00000200   00001200   40300040
  .pdata                  000000d8   00005000   00000200   00001400   40300040
  .xdata                  0000007c   00006000   00000200   00001600   40300040
    .bss                  000001c0   00007000   00000000   00000000   c0600080
  .idata                  00000268   00008000   00000400   00001800   c0300040
   .rsrc                  000010e0   00009000   00000c00   00001c00   c0300040
      /4 .gnu_debuglink   0000000c   0000a000   00000200   00002800   42300040

The problem seems to manifest when the .rsrc section has a VirtSize greater
than it's RawSize (which I believe should just mean that the loaded section is
null padded) and the following section is the .gnu_debuglink, but not when
there's no following section, or it's a .debug section.

Playing around with the size of the .rsrc section, the problem first occurs
when the VirtSize crosses the page alignement boundary (i.e. VirtSize = 0x1000)

> Created attachment 9316 [details]
> Proposed patch

Anyhow, we can avoid this problem by giving the  .rsrc section the right
VirtSize, so this proposed patch seem the correct fix.
(although I'm not quite sure if the virt_size should be set in
pinfo->output_bfd rather than pinfo->abfd?)

Unfortunately, as mentioned previously, this makes 1.exe invalid, but I think I
can now see why that is:

1.exe (with patch, invalid)

Name                      VirtSize   VMA        RawSize    Offset     Flags
   .text                  00000758   00001000   00000800   00000600   60500060
   .data                  00000068   00002000   00000200   00000e00   c0600040
  .rdata                  00000370   00003000   00000400   00001000   40500040
.buildid                  00000035   00004000   00000200   00001400   40300040
  .pdata                  000000d8   00005000   00000200   00001600   40300040
  .xdata                  0000007c   00006000   00000200   00001800   40300040
    .bss                  000001a0   00007000   00000000   00000000   c0600080
  .idata                  00000268   00008000   00000400   00001a00   c0300040
   .rsrc                  00000bf8   00009000   00000c00   00001e00   c0300040
      /4 .debug_aranges   00000230   0000b000   00000400   00003000   42100040
     /19 .debug_info      000066a2   0000c000   00006800   00003400   42100040
     /31 .debug_abbrev    00000afc   00013000   00000c00   00009c00   42100040
     /45 .debug_line      00000e37   00014000   00001000   0000a800   42100040
     /57 .debug_frame     000002a0   00015000   00000400   0000b800   42400040
     /70 .debug_str       00000102   00016000   00000200   0000bc00   42100040
     /81 .debug_loc       00000745   00017000   00000800   0000be00   42100040
     /92 .debug_ranges    00000030   00018000   00000200   0000c600   42100040

This .exe is invalid because the section VMAs aren't contiguous. 
.debug_aranges should have a VMA of 0000a000.

This occurs because rsrc_process_section(), which now updates the .rsrc section
VirtSize, is happening after compute_section_file_positions(), so the VMAs
aren't computed correctly if the .rsrc section shrinks under a page boundary.

So, another fix is needed here.  I'm trying to puzzle out where to move
rsrc_process_section() to, but if you have any pointers, that would be most
helpful.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]