PR 33302, Symbols truncated on i386pep target

Jan Beulich jbeulich@suse.com
Fri Aug 22 11:59:18 GMT 2025


On 22.08.2025 13:33, Alan Modra wrote:
> This tidies a few things in the COFF/PE code I noticed while
> correcting this bug, which was caused by commit 012d44268695
> effectively making peXXigen.c _bfd_XXi_swap_aux_out always use the
> COFF E_FILNMLEN of 14.  The problem was that the auxent x_fname field
> was defined in include/coff/external.h using a length of 14.  Later,
> E_FILNMLEN is redefined to 18 in coff/pe.h.  This no doubt falsely
> tripped memory checking tools.  (AUXESZ is 18, so no actual buffer
> overrun.)
> 
> There are multiple ways to fix this problem.  One is to define x_fname
> as an 18 char field, and use E_FILNMLEN when accessing.  I chose to
> set E_FILNMLEN to the correct value in include/coff/external.h rather
> than overriding it later so that the field is the correct size.  I did
> the same for FILNMLEN.  This requires COFF_WITH_PE to be defined
> before including coff/external.h or coff/internal.h, if compiling for
> PE COFF.  Much of the patch is about doing just that.  I'll note the
> the gdb patch isn't strictly needed (no change in compiler output
> except assert line numbers) but is there for consistency.
> 
> Some of the coff-<arch>.c files have PE specific code, unconditionally
> compiled.  They now get an error if they are compiled stand-alone
> rather than being included from pe-<arch>.c or pei-<arch>.c.
> 
> include/
> 	* coff/external.h (E_FILNMLEN): Define value for PE if
> 	COFF_WITH_PE.
> 	(E_FILNMLEN, E_DIMNUM): Move before auxent.
> 	* coff/internal.h (FILNMLEN): Define value for PE if
> 	COFF_WITH_PE.
> 	(FILNMLEN, DIMNUM): Move before auxent.
> 	* coff/pe.h (FILNMLEN, E_FILNMLEN): Don't define.
> bfd/
> 	* coff-aarch64.c (COFF_WITH_peAArch64): Don't define here.
> 	(COFF_WITH_PE): Error if not defined.
> 	* coff-ia64.c (COFF_WITH_PE): Error if not defined.
> 	* coff-loongarch64.c (COFF_WITH_peLoongArch64): Don't define here.
> 	(COFF_WITH_PE): Error if not defined.
> 	* coff-mcore.c (COFF_WITH_PE): Error if not defined.
> 	* coff-riscv64.c (COFF_WITH_PE): Error if not defined.
> 	* pe-x86_64.c (COFF_WITH_PE): Define earlier.
> 	* peXXigen.c (COFF_WITH_PE): Define earlier.  Include
> 	coff/internal.h later.
> 	* pei-aarch64.c: Remove duplicate includes.
> 	* pei-loongarch64.c: Likewise.
> 	* pei-riscv64.c: Likewise.
> 	* pei-x86_64.c: Likewise.
> binutils/
> 	* dlltool.c (COFF_WITH_PE): Define.
> 	* objcopy.c (COFF_WITH_PE): Define.
> 	* od-pe.c (COFF_WITH_PE): Define.
> gas/
> 	* config/obj-coff.h (COFF_WITH_PE): Don't define.
> 	* config/te-pe.h (COFF_WITH_PE): Define.
> 	* config/te-pep.h (COFF_WITH_PE): Define.
> 	* testsuite/gas/pe/long_file_symbol.d,
> 	* testsuite/gas/pe/long_file_symbol.s: New test.
> 	* testsuite/gas/pe/pe.exp: Run it.
> gdb/
> 	* amd64-windows-tdep.c (COFF_WITH_PE): Define.
> ld/
> 	* emultempl/pe.em (COFF_WITH_PE): Define.
> 	* pdb.c (COFF_WITH_PE): Define.

That's quite a bit larger a change than I was anticipating; thanks for putting
this together so quickly.

Jan


More information about the Binutils mailing list