PE/COFF: raise normal PE section limit safely
Increases the maximum number of sections in PE/COFF objects from 32767 to 65279 by using unsigned 16-bit integers for section numbers.
Oleg Tolmatcev proposes raising the section limit in PE/COFF objects from 32,767 to 65,279. This change is necessary because binutils currently uses signed 16-bit integers for symbol section numbers, whereas modern compilers like MSVC and Clang support a larger unsigned range. The patch modifies BFD to handle section numbers as unsigned values while preserving special constants, and includes a new gas test case to verify the functionality.
In Details
The PE/COFF executable format has a limit on the number of sections, imposed by the 16-bit field used for section numbers in symbol table entries. Historically, binutils treated this as signed, limiting valid section numbers to 32767. This patch corrects this by interpreting and encoding these numbers as unsigned, aligning with the format's capability to support up to 65535 sections (minus reserved values), thus enabling the creation of objects with more sections.
- PE/COFF
- Portable Executable / Common Object File Format. The standard file format for executables, object code, and DLLs used in Windows operating systems.
- section number
- In the PE/COFF format, a symbol table entry refers to a section by its number (index).
- BFD
- Binary File Descriptor library. A low-level library used by GNU binutils to handle various object file formats.
- gas
- The GNU Assembler, part of the GNU binutils.
- objdump
- A utility in GNU binutils that displays information from object files.