PE FILNMLEN and E_FILNMLEN

Alan Modra amodra@gmail.com
Sun Aug 24 22:58:07 GMT 2025


This defines COFF_WITH_PE before including coff/external.h or
coff/internal.h, if compiling for PE COFF.  That allows these files to
define the correct FILNMLEN and E_FILNMLEN for PE, without overriding
them later.  (The patch doesn't change x_fname.)

include/
	* coff/external.h (E_FILNMLEN): Define value for PE if
	COFF_WITH_PE.
	* coff/internal.h (FILNMLEN): Define value for PE if
	COFF_WITH_PE.
	* coff/pe.h (FILNMLEN, E_FILNMLEN): Don't define.
bfd/
	* pe-x86_64.c (COFF_WITH_PE): Define earlier.
	* peXXigen.c (COFF_WITH_PE): Define earlier.  Include
	coff/internal.h later.
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.
gdb/
	* amd64-windows-tdep.c (COFF_WITH_PE): Define.
ld/
	* emultempl/pe.em (COFF_WITH_PE): Define.
	* pdb.c (COFF_WITH_PE): Define.

diff --git a/bfd/pe-x86_64.c b/bfd/pe-x86_64.c
index 9151aac5792..695cc0f0b2e 100644
--- a/bfd/pe-x86_64.c
+++ b/bfd/pe-x86_64.c
@@ -24,6 +24,7 @@
 #include "bfd.h"
 #include "libbfd.h"
 #include "libiberty.h"
+#define COFF_WITH_PE
 #include "coff/x86_64.h"
 #include "coff/internal.h"
 #include "coff/pe.h"
@@ -33,7 +34,6 @@
 #define TARGET_NAME		"pe-x86-64"
 #define TARGET_SYM_BIG		x86_64_pe_big_vec
 #define TARGET_NAME_BIG		"pe-bigobj-x86-64"
-#define COFF_WITH_PE
 #define COFF_WITH_pex64
 #define COFF_WITH_PE_BIGOBJ
 #define PCRELOFFSET		true
diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 1a195d97c5c..42f2bfb41a2 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -68,12 +68,13 @@
 #include "sysdep.h"
 #include "bfd.h"
 #include "libbfd.h"
-#include "coff/internal.h"
 #include "bfdver.h"
 #include "libiberty.h"
 #include <wchar.h>
 #include <wctype.h>
 
+#define COFF_WITH_PE
+
 /* NOTE: it's strange to be including an architecture specific header
    in what's supposed to be general (to PE/PEI) code.  However, that's
    where the definitions are, and they don't vary per architecture
@@ -94,6 +95,7 @@
 # include "coff/i386.h"
 #endif
 
+#include "coff/internal.h"
 #include "coff/pe.h"
 #include "libcoff.h"
 #include "libpei.h"
diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 99c651f7f9b..afe1228d97f 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -252,6 +252,8 @@
 #include <time.h>
 #include <assert.h>
 
+#define COFF_WITH_PE
+
 #ifdef DLLTOOL_ARM
 #include "coff/arm.h"
 #include "coff/internal.h"
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 51d87d6d359..497bf441187 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -27,6 +27,7 @@
 #include "filenames.h"
 #include "fnmatch.h"
 #include "elf-bfd.h"
+#define COFF_WITH_PE
 #include "coff/internal.h"
 #include "libcoff.h"
 #include "safe-ctype.h"
diff --git a/binutils/od-pe.c b/binutils/od-pe.c
index c3341fb15ca..c3d504a39ee 100644
--- a/binutils/od-pe.c
+++ b/binutils/od-pe.c
@@ -27,6 +27,7 @@
 #include "objdump.h"
 #include "bucomm.h"
 #include "bfdlink.h"
+#define COFF_WITH_PE
 #include "coff/internal.h"
 #define L_LNNO_SIZE 4 /* FIXME: which value should we use ?  */
 #include "coff/external.h"
diff --git a/gas/config/obj-coff.h b/gas/config/obj-coff.h
index 51dfd56e447..50b5a06b66e 100644
--- a/gas/config/obj-coff.h
+++ b/gas/config/obj-coff.h
@@ -71,10 +71,6 @@
 
 #ifdef TC_SH
 
-#ifdef TE_PE
-#define COFF_WITH_PE
-#endif
-
 #include "coff/sh.h"
 
 #ifdef TE_PE
diff --git a/gas/config/te-pe.h b/gas/config/te-pe.h
index d77dc05e3b1..ed5c959c490 100644
--- a/gas/config/te-pe.h
+++ b/gas/config/te-pe.h
@@ -18,6 +18,7 @@
    02110-1301, USA.  */
 
 #define TE_PE
+#define COFF_WITH_PE
 #define LEX_AT (LEX_BEGIN_NAME | LEX_NAME) /* Can have @'s inside labels.  */
 
 /* The PE format supports long section names.  */
diff --git a/gas/config/te-pep.h b/gas/config/te-pep.h
index ed5c0ac7f54..658207506eb 100644
--- a/gas/config/te-pep.h
+++ b/gas/config/te-pep.h
@@ -18,6 +18,7 @@
    02110-1301, USA.  */
 
 #define TE_PEP
+#define COFF_WITH_PE
 #define COFF_WITH_pex64
 
 #define TE_PE
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index c7977d29c3f..fbec7a78002 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -27,6 +27,7 @@
 #include "frame.h"
 #include "objfiles.h"
 #include "frame-unwind.h"
+#define COFF_WITH_PE
 #include "coff/internal.h"
 #include "coff/i386.h"
 #include "coff/pe.h"
diff --git a/include/coff/external.h b/include/coff/external.h
index 1b3c06db2eb..97d2f968dbc 100644
--- a/include/coff/external.h
+++ b/include/coff/external.h
@@ -180,7 +180,11 @@ SYMENT;
 
 #ifndef DO_NOT_DEFINE_AUXENT
 
+#ifdef COFF_WITH_PE
+#define E_FILNMLEN	18	/* # characters in a file name		*/
+#else
 #define E_FILNMLEN	14	/* # characters in a file name		*/
+#endif
 #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
 #define AUXESZ	18
 
diff --git a/include/coff/internal.h b/include/coff/internal.h
index 9da5e4b9025..ee15d47a6a3 100644
--- a/include/coff/internal.h
+++ b/include/coff/internal.h
@@ -539,7 +539,11 @@ struct internal_syment
 #define SYM_V_EXPORTED		0x4000
 #define SYM_V_MASK		0xF000
 
+#ifdef COFF_WITH_PE
+#define FILNMLEN	18	/* # characters in a file name		*/
+#else
 #define FILNMLEN	14	/* # characters in a file name		*/
+#endif
 #define DIMNUM		4	/* # array dimensions in auxiliary entry */
 
 union internal_auxent
diff --git a/include/coff/pe.h b/include/coff/pe.h
index 59ac6366bf8..6bb8bc9c793 100644
--- a/include/coff/pe.h
+++ b/include/coff/pe.h
@@ -179,11 +179,6 @@
 #define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER	13
 #define IMAGE_SUBSYSTEM_XBOX			14
 
-/* NT allows long filenames, we want to accommodate this.
-   This may break some of the bfd functions.  */
-#undef  FILNMLEN
-#define FILNMLEN	18	/* # characters in a file name.  */
-
 struct external_PEI_IMAGE_hdr
 {
   char nt_signature[4];		/* Required NT signature, 0x4550.  */
@@ -325,9 +320,6 @@ typedef struct
 #define PEPAOUTSZ	240
 #endif
 
-#undef  E_FILNMLEN
-#define E_FILNMLEN	18	/* # characters in a file name.  */
-
 /* Import Tyoes fot ILF format object files..  */
 #define IMPORT_CODE	0
 #define IMPORT_DATA	1
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index b522687c1d5..eeabcebb494 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -65,6 +65,7 @@ fragment <<EOF
 #include "ldmisc.h"
 #include "ldctor.h"
 #include "ldbuildid.h"
+#define COFF_WITH_PE
 #include "coff/internal.h"
 EOF
 
diff --git a/ld/pdb.c b/ld/pdb.c
index d0d51c7a79a..e4bed3ab9b1 100644
--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -25,6 +25,7 @@
 #include "ldmisc.h"
 #include "libbfd.h"
 #include "libiberty.h"
+#define COFF_WITH_PE
 #include "coff/i386.h"
 #include "coff/external.h"
 #include "coff/internal.h"

-- 
Alan Modra


More information about the Binutils mailing list