binutils Newspaper
NOVEMBER 30, 2026
ld — Proposed

ld: Read output in chunks when computing PE build-id

Linker patch improves build-id computation performance for PE files by reading output in chunks.

This patch optimizes the performance of the GNU linker’s (ld) build-id computation for PE files. Previously, pecoff_checksum_contents read the output file byte-by-byte, which was inefficient for large files (e.g., 15% of link time for a 235 MB executable). The change introduces reading the file in 64 KB chunks using a heap buffer, with a fallback to a 64-byte stack buffer if heap allocation fails, significantly reducing the overhead.

In the Thread 1 participant
  1. Oleg Tolmatcev proposer

    Optimizes PE build-id computation by reading the output file in chunks instead of byte-by-byte.

    “pecoff_checksum_contents read the output file back one byte at a time, seeking before every byte and passing each byte to the hash function separately. For a 235 MB executable this took about 15% of the link time. Read the file using a 64 KB heap buffer. If its allocation fails, fall back to a 64-byte buffer on the stack.”

In Details

This patch addresses a performance bottleneck in the GNU linker's (ld) calculation of the PE file build-id. The function pecoff_checksum_contents was inefficiently reading the entire output file byte-by-byte, causing significant overhead. The proposed solution reads the file in larger chunks (64KB heap buffer, with a 64-byte stack fallback) to speed up this process, especially for large executables.

For Context
ld
The GNU linker, responsible for combining object files and libraries into executables or other binary formats.
PE file
Portable Executable, the file format used for executables, DLLs, and object files in Windows.
build-id
A unique identifier for a build of an executable or library, used for debugging and identifying specific versions of binaries.
checksum
A value computed from a block of data for the purpose of detecting errors. In this context, it's used as part of the build-id calculation.
Filed Under: linkerbinutilsperformancepebuild-id