https://sourceware.org/bugzilla/show_bug.cgi?id=18087
Bug ID: 18087 Summary: objcopy --compress-debug-sections can produce broken debug sections in PE binaries Product: binutils Version: 2.26 (HEAD) Status: NEW Severity: normal Priority: P2 Component: binutils Assignee: unassigned at sourceware dot org Reporter: jon.turney at dronecode dot org.uk Created attachment 8177 --> https://sourceware.org/bugzilla/attachment.cgi?id=8177&action=edit Update section virtual size when it's compressed or decompressed PE binary support for objcopy --compress-debug-sections added in bug #14067 (commit a29a8af8) seems to have a problem when compression makes sections larger. Examining the unstripped XWin.exe for which the problem was reported [1] (using my own PE dumper as objdump -h transparently decompresses the compressed sections for you.) Section Name Virtual Size VMA RawSize File Offset Characteristics .text 0017df74 00001000 0017e000 00000600 60500060 .data 00004184 0017f000 00004200 0017e600 c0700040 .rdata 000321e0 00184000 00032200 00182800 40700040 .buildid 00000035 001b7000 00000200 001b4a00 40300040 /4 .eh_frame 00049240 001b8000 00049400 001b4c00 40300040 .bss 0000eae0 00202000 00000000 00000000 c0700080 .edata 0002a0a5 00211000 0002a200 001fe000 40300040 .idata 00004c70 0023c000 00004e00 00228200 c0300040 .rsrc 00007800 00241000 00007400 0022d000 c0300040 .reloc 0000d1bc 00249000 0000d200 00234800 42300040 /14 .debug_aranges 00002fb0 00257000 00003000 00241a00 42400040 /29 .debug_info 007c423e 0025a000 007c4400 00244a00 42100040 /41 .debug_abbrev 00056487 00a1f000 00056600 00a08e00 42100040 /55 .debug_line 0009576a 00a76000 00095800 00a5f400 42100040 /67 .debug_frame 00000038 00b0c000 00000200 00af4c00 42300040 /80 .debug_str 00026a8b 00b0d000 00026c00 00af4e00 42100040 /91 .debug_loc 001799f0 00b34000 00179a00 00b1ba00 42100040 /102 .debug_ranges 00038b88 00cae000 00038c00 00c95400 42100040 Compare with this after it's compressed using objcopy -compressed-debug-sections Section Name Virtual Size VMA RawSize File Offset Characteristics .text 0017df74 00001000 0017e000 00000600 60500060 .data 00004184 0017f000 00004200 0017e600 c0700040 .rdata 000321e0 00184000 00032200 00182800 40700040 .buildid 00000035 001b7000 00000200 001b4a00 40300040 /4 .eh_frame 00049240 001b8000 00049400 001b4c00 40300040 .bss 0000eae0 00202000 00000000 00000000 c0700080 .edata 0002a0a5 00211000 0002a200 001fe000 40300040 .idata 00004c70 0023c000 00004e00 00228200 c0300040 .rsrc 00007800 00241000 00007400 0022d000 c0300040 .reloc 0000d1bc 00249000 0000d200 00234400 42300040 /14 .zdebug_aranges 00002fb0 00257000 00001200 00241600 42400040 /30 .zdebug_info 007c423e 0025a000 00356200 00242800 42100040 /43 .zdebug_abbrev 00056487 00a1f000 0000d600 00598a00 42100040 /58 .zdebug_line 0009576a 00a76000 00040600 005a6000 42100040 /71 .zdebug_frame 00000038 00b0c000 00000200 005e6600 42300040 /85 .zdebug_str 00026a8b 00b0d000 00005c00 005e6800 42100040 /97 .zdebug_loc 001799f0 00b34000 0007de00 005ec400 42100040 /109 .zdebug_ranges 00038b88 00cae000 00013000 0066a200 42100040 It can be seen that the virtual size of the compressed sections is not updated, although the raw size has decreased. Normally this is not a problem, as nothing is accessing the section contents after the raw size. However, if the compressor has made the data bigger, it is truncated to the virtual size and decompression fails. Unfortunately, small .debug_frame sections seem to be quite normal on x86. Attached is a patch which updates the virtual size, which seems to fix this issue. Section Name Virtual Size VMA RawSize File Offset Characteristics .text 0017df74 00001000 0017e000 00000600 60500060 .data 00004184 0017f000 00004200 0017e600 c0700040 .rdata 000321e0 00184000 00032200 00182800 40700040 .buildid 00000035 001b7000 00000200 001b4a00 40300040 /4 .eh_frame 00049240 001b8000 00049400 001b4c00 40300040 .bss 0000eae0 00202000 00000000 00000000 c0700080 .edata 0002a0a5 00211000 0002a200 001fe000 40300040 .idata 00004c70 0023c000 00004e00 00228200 c0300040 .rsrc 00007800 00241000 00007400 0022d000 c0300040 .reloc 0000d1bc 00249000 0000d200 00234400 42300040 /14 .zdebug_aranges 0000103e 00257000 00001200 00241600 42400040 /30 .zdebug_info 003561b2 0025a000 00356200 00242800 42100040 /43 .zdebug_abbrev 0000d5aa 00a1f000 0000d600 00598a00 42100040 /58 .zdebug_line 0004049b 00a76000 00040600 005a6000 42100040 /71 .zdebug_frame 00000045 00b0c000 00000200 005e6600 42300040 /85 .zdebug_str 00005b42 00b0d000 00005c00 005e6800 42100040 /97 .zdebug_loc 0007dc89 00b34000 0007de00 005ec400 42100040 /109 .zdebug_ranges 00012e79 00cae000 00013000 0066a200 42100040 Possibly related to bug #15350 [1] https://cygwin.com/ml/cygwin/2015-03/msg00080.html -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils