binutils Newspaper
OCTOBER 6, 2026
bfd/pe — Proposed

bfd/PE: fix debug section compression for pei-*

Fixes incorrect handling of compressed debug sections in PE image files (pei-*).

Tobias Deiminger corrects a bug where compressing debug sections for PE image files (pei-*) did not work correctly in a full round trip. The issue arose from BFD incorrectly using the uncompressed size (VirtualSize) instead of the compressed size for decompression verification. The fix ensures the compressed size is used, and virt_size is updated only after successful decompression.

In the Thread 1 participant
  1. Tobias Deiminger proposer

    Corrects the handling of compressed debug sections in PE image files (pei-*), ensuring successful decompression by using the compressed size for verification.

    “bfd supports compressing debug sections for PE/Coff since a29a8af823af ("ChangeLog bfd"). It works for pe, but never worked for pei in a full round trip. For example: $ x86_64-w64-mingw32-gcc -g -o testprog testprog.c $ objcopy --compress-debug-sections testprog.exe testprog_z.exe $ gdb --batch -ex "break fn" -ex "info line fn" testprog_z.exe warning: Can't read data for section '.zdebug_inf…”

In Details

This patch resolves a longstanding issue in BFD's PE backend where debug sections compressed with --compress-debug-sections could not be correctly decompressed and read for pei-* targets. The core problem was in peicode.h:coff_swap_scnhdr_in, which used VirtualSize (uncompressed size) instead of the actual compressed size for verification. The fix ensures that the correct compressed size is stored and used for decompression, and that virt_size is updated to the decompressed size only after successful decompression, enabling tools like GDB to read the debug information.

For Context
PE image files (pei-*)
A specific variant of the PE (Portable Executable) file format, often used for Windows executables and DLLs, with specific characteristics that differ from standard PE files.
debug sections
Sections within an executable file that contain debugging information, such as symbol tables, line number information, and DWARF data, used by debuggers.
round trip
The process of applying an operation (e.g., compression) and then its inverse (e.g., decompression), verifying that the data returns to its original state.
VirtualSize
A field in the PE section header that typically represents the size of the section in memory after decompression or loading, as opposed to its size on disk.
SizeOfRawData
A field in the PE section header that represents the size of the section in the file on disk, usually aligned to a specific boundary.
Filed Under: binutilsbfdpedebugcompression