binutils Newspaper
JULY 29, 2026
pe/coff Proposed Sentiment 8 / 10

PE/COFF: raise normal PE section limit safely

Safely increases the maximum number of sections allowed in PE/COFF files processed by binutils.

This patch increases the limit for the number of sections in PE/COFF files handled by binutils from 32,767 to 65,279. It achieves this by correctly treating symbol section numbers as unsigned 16-bit values, aligning with modern compiler practices, while preserving special reserved section number constants. Additionally, it introduces a new gas test to verify the handling of objects with a high section count and improves input validation for reserved section numbers.

In the Thread 2 participants
  1. Oleg Tolmatcev proposer

    Submits a patch to safely increase the PE/COFF section limit by handling unsigned 16-bit section numbers and preserving reserved constants, along with new tests.

    “PE/COFF stores symbol section numbers in a 16-bit field. Binutils used signed 16-bit handling there, which limited normal PE objects to 32767 sections even though MSVC and Clang already accept a larger unsigned range. Raise the normal PE section limit to 65279, while keeping the PE/COFF special section-number values for undefined, absolute and debug symbols working correctly. Do this by decodi…”
  2. Jan Beulich reviewer

    Suggests formatting improvements for long lines in the code and a potential consolidation of related manifest constants.

    “Okay, albeit preferably with ... ... this line split for each part to remain within 80 columns (no matter that other such long lines exist). Perhaps they all should be consolidated into the checking of a single (new) manifest constant, such that mistakes like the one being fixed here are easier to avoid. But that's for later.”

Technical Tradeoffs

  • Improves compatibility with modern toolchains and allows for larger PE/COFF files.
  • Introduces more complex handling of section number encoding/decoding.
  • Adds new test cases to ensure the increased limit is handled correctly.

In Details

This patch modifies binutils to support a larger number of sections (up to 65,279) in PE/COFF files, overcoming a previous limit of 32,767 imposed by signed 16-bit interpretation of symbol section numbers. The change ensures compatibility with modern toolchains like MSVC and Clang, which support the full unsigned range. It involves correctly decoding and encoding section numbers as unsigned values while preserving special reserved values. The patch also adds input validation for reserved section numbers and includes new test cases to cover scenarios with a high section count.

For Context
PE/COFF
An object file format used by Windows, combining aspects of the COFF format with PE (Portable Executable) headers.
section number
An identifier for a section within an object file. In PE/COFF symbol tables, this number refers to the section to which a symbol belongs.
symbol table
A data structure within an object file that stores information about symbols (e.g., function and variable names, their addresses, and types).
MSVC
Microsoft Visual C++, a suite of programming tools for the Microsoft Windows platform, including a compiler and debugger.
Clang
A compiler front-end for the C, C++, Objective-C, and Objective-C++ languages, part of the LLVM project.
gas
The GNU Assembler, the default assembler used by the GNU Compiler Collection (GCC).
objdump
A utility that displays information from object files, including disassembly and symbol tables.
Filed Under: pe/coffwindowslinkersymbolsbugfix