This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH/PING all PE target maintainers] Disallow long COFF section names in PE executable image files.



Hello team,


     As reported by Piotr a couple of days ago(*), bfd currently generates PE
executables that fail to conform to the PE specification docs.  To recap:

- COFF (on which PE is based) only allows 8-byte section names.

- PE adds an extension where long section names can be encoded in the string
table that is appended to the COFF symbols, by setting the section name to an
ASCII string of the form "/nnnnn" where nnnn is the decimal offset of the long
name in the string table.

- According to the spec, " Executable images do not use a string table and do
not support section names longer than 8 characters. Long names in object files
are truncated if they are emitted to an executable file. "

- But BFD does this for fully-linked executables as well.

     This is wrong, but it's hard to show it.  The standard MS "dumpbin" tool
accepts the format without complaint and shows the expanded long name, as does
objdump.  It does, however, cause the (free as in beer but not speech)
PEview(+) utility to display gibberish, but there's no way to export the dump
from that utility as text.  If anyone wants to see, I took a screenshot.(^)

    This patch shows the simplest way to deal with the problem: WDDTT, for all
the PE executable image file formats.  But I had second thoughts.

- This may not be standard, but it does in fact work; the executables
generated by binutils are fully functional, the string table (that shouldn't
be there) is just treated as harmless bunch-of-bytes appended to the image,
and it's only a few tools that even notice the problem.  It also makes for
nicer output when you have to dump something, so could be considered desirable
as a GNU extension.

- OTOH I don't know for absolute certain whether some conceivable harm might
result from adhering to the standard and truncating the long section names in
the fully-linked executable image files.  We do occasionally link against
executable images - DLLs in particular - and I could imagine things
conceivably becoming confused from the presence of multiple identically-named
input sections, but then again it only happens to the .debug_* sections, so we
might get away with it.

    So, I thought up a slightly more sophisticated approach, but before I put
the work in to implement it I thought I'd see if there's any kind of consensus
among the PE maintainers:  Would we like this behaviour to be controlled by a
command-line flag, rather than just forcefully disabled?

    If we do, I will prepare a patch that replaces all the "#ifdef
COFF_LONG_SECTION_NAMES" tests with run-time tests of
bfd_coff_long_filenames(), add a COFF-backend method allowing us to set the
flag at runtime, and change the semantic of COFF_LONG_SECTION_NAMES:

- currently, if COFF_LONG_SECTION_NAMES is defined, all the code to handle
long section names is compiled in, and the backend flag tested by
bfd_coff_long_filenames() is set true.  In coffcode.h where the declaration is
visible, the long section name handling code runs unconditionally (as it can
see the definition of COFF_LONG_SECTION_NAMES, it can assume that
bfd_coff_long_filenames() will return true because the flag has always been a
compile-time constant up to now), and in other files it is conditioned at
runtime on the result of calling bfd_coff_long_section_names().

- I would change this semantic so that:
    i.  As currently, the code to handle long section names is compiled in if
COFF_LONG_SECTION_NAMES is defined, and not if it isn't.
   ii.  But, all the code to handle long section names in coffcode.h (and
anywhere else that is only compile-time rather than run-time conditioned) will
now test the runtime value of bfd_coff_long_filenames().
iii.  If COFF_LONG_SECTION_NAMES is merely defined, or defined to any non-zero
value, the backend flag tested by bfd_coff_long_filenames() is initialised to
true.  If it is explicitly defined to zero, the backend flag is initialised to
false.
   iv.  I would add a coff backend method bfd_coff_set_long_filenames() which
would set the value of the flag at runtime, allowing a client of the BFD
library such as LD to enable or disable the generation of long section names.
    v.  We could then #define COFF_LONG_SECTION_NAMES to zero for all the
executable image formats to default long section names off, rather than (as in
this tentative patch) disabling the capability altogether.

    Anyway, that's a bit more work than doing it the crude way, so I'd like to
canvass some idea of the interest before getting too far into it.  The third
option, of course, is that we could just do nothing, admit we violate the
spec, and say "that's too bad" when a tool that does enforce the spec
generates mildly bogus output; it isn't really even a show stopper that anyone
can't work around, it's more just surprising and unexpected than anything
else, but my preference would be to at least provide an option of addressing it.

Opinions, please?

bfd/ChangeLog

	* efi-app-ia32.c (COFF_LONG_SECTION_NAMES):  Don't define.
	* efi-app-ia64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-app-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-bsdrv-ia32.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-bsdrv-ia64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-bsdrv-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-rtdrv-ia32.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-rtdrv-ia64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* efi-rtdrv-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-arm.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-i386.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-mcore.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-mips.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-ppc.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-sh.c (COFF_LONG_SECTION_NAMES):  Likewise.
	* pei-x86_64.c (COFF_LONG_SECTION_NAMES):  Likewise.

      cheers,
        DaveK
--
(*) - http://gcc.gnu.org/ml/gcc/2009-02/msg00026.html
(+) - http://www.magma.ca/~wjr
(^) - http://img13.imageshack.us/img13/8521/peviewgarbledxu9.png


? diffs.log
? libiberty/autom4te.cache
Index: bfd/efi-app-ia32.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-app-ia32.c,v
retrieving revision 1.10
diff -p -u -r1.10 efi-app-ia32.c
--- bfd/efi-app-ia32.c	3 Jul 2007 14:26:40 -0000	1.10
+++ bfd/efi-app-ia32.c	3 Feb 2009 13:43:07 -0000
@@ -28,7 +28,8 @@
 #define COFF_WITH_PE
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM	IMAGE_SUBSYSTEM_EFI_APPLICATION
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-app-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-app-ia64.c,v
retrieving revision 1.8
diff -p -u -r1.8 efi-app-ia64.c
--- bfd/efi-app-ia64.c	3 Jul 2007 14:26:40 -0000	1.8
+++ bfd/efi-app-ia64.c	3 Feb 2009 13:43:07 -0000
@@ -29,7 +29,8 @@
 #define COFF_WITH_pep
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM		IMAGE_SUBSYSTEM_EFI_APPLICATION
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-app-x86_64.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-app-x86_64.c,v
retrieving revision 1.3
diff -p -u -r1.3 efi-app-x86_64.c
--- bfd/efi-app-x86_64.c	3 Jul 2007 14:26:40 -0000	1.3
+++ bfd/efi-app-x86_64.c	3 Feb 2009 13:43:07 -0000
@@ -28,7 +28,8 @@
 #define COFF_WITH_pep
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM	IMAGE_SUBSYSTEM_EFI_APPLICATION
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-bsdrv-ia32.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-bsdrv-ia32.c,v
retrieving revision 1.1
diff -p -u -r1.1 efi-bsdrv-ia32.c
--- bfd/efi-bsdrv-ia32.c	14 Feb 2008 15:20:26 -0000	1.1
+++ bfd/efi-bsdrv-ia32.c	3 Feb 2009 13:43:07 -0000
@@ -29,7 +29,8 @@
 #define COFF_WITH_PE
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM	IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-bsdrv-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-bsdrv-ia64.c,v
retrieving revision 1.1
diff -p -u -r1.1 efi-bsdrv-ia64.c
--- bfd/efi-bsdrv-ia64.c	14 Feb 2008 15:20:26 -0000	1.1
+++ bfd/efi-bsdrv-ia64.c	3 Feb 2009 13:43:07 -0000
@@ -30,7 +30,8 @@
 #define COFF_WITH_pep
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM		IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-bsdrv-x86_64.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-bsdrv-x86_64.c,v
retrieving revision 1.1
diff -p -u -r1.1 efi-bsdrv-x86_64.c
--- bfd/efi-bsdrv-x86_64.c	14 Feb 2008 15:20:26 -0000	1.1
+++ bfd/efi-bsdrv-x86_64.c	3 Feb 2009 13:43:07 -0000
@@ -30,7 +30,8 @@
 #define COFF_WITH_pep
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM	IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-rtdrv-ia32.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-rtdrv-ia32.c,v
retrieving revision 1.1
diff -p -u -r1.1 efi-rtdrv-ia32.c
--- bfd/efi-rtdrv-ia32.c	14 Feb 2008 15:20:26 -0000	1.1
+++ bfd/efi-rtdrv-ia32.c	3 Feb 2009 13:43:07 -0000
@@ -29,7 +29,8 @@
 #define COFF_WITH_PE
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM	IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-rtdrv-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-rtdrv-ia64.c,v
retrieving revision 1.1
diff -p -u -r1.1 efi-rtdrv-ia64.c
--- bfd/efi-rtdrv-ia64.c	14 Feb 2008 15:20:26 -0000	1.1
+++ bfd/efi-rtdrv-ia64.c	3 Feb 2009 13:43:07 -0000
@@ -30,7 +30,8 @@
 #define COFF_WITH_pep
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM		IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/efi-rtdrv-x86_64.c
===================================================================
RCS file: /cvs/src/src/bfd/efi-rtdrv-x86_64.c,v
retrieving revision 1.1
diff -p -u -r1.1 efi-rtdrv-x86_64.c
--- bfd/efi-rtdrv-x86_64.c	14 Feb 2008 15:20:26 -0000	1.1
+++ bfd/efi-rtdrv-x86_64.c	3 Feb 2009 13:43:07 -0000
@@ -30,7 +30,8 @@
 #define COFF_WITH_pep
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define PEI_TARGET_SUBSYSTEM	IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
 #define PEI_FORCE_MINIMUM_ALIGNMENT
 
Index: bfd/pei-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-arm.c,v
retrieving revision 1.13
diff -p -u -r1.13 pei-arm.c
--- bfd/pei-arm.c	3 Jul 2007 14:26:42 -0000	1.13
+++ bfd/pei-arm.c	3 Feb 2009 13:43:07 -0000
@@ -31,7 +31,8 @@
 #define COFF_IMAGE_WITH_PE
 #define COFF_WITH_PE
 #define PCRELOFFSET        TRUE
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 
 #define COFF_SECTION_ALIGNMENT_ENTRIES \
 { COFF_SECTION_NAME_EXACT_MATCH (".bss"), \
Index: bfd/pei-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-i386.c,v
retrieving revision 1.13
diff -p -u -r1.13 pei-i386.c
--- bfd/pei-i386.c	9 Nov 2007 08:35:29 -0000	1.13
+++ bfd/pei-i386.c	3 Feb 2009 13:43:07 -0000
@@ -28,7 +28,8 @@
 #define COFF_WITH_PE
 #define PCRELOFFSET 		TRUE
 #define TARGET_UNDERSCORE 	'_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define COFF_SUPPORT_GNU_LINKONCE
 #define COFF_LONG_FILENAMES
 
Index: bfd/pei-mcore.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-mcore.c,v
retrieving revision 1.8
diff -p -u -r1.8 pei-mcore.c
--- bfd/pei-mcore.c	18 Jul 2008 11:30:22 -0000	1.8
+++ bfd/pei-mcore.c	3 Feb 2009 13:43:07 -0000
@@ -31,7 +31,8 @@
 #define COFF_IMAGE_WITH_PE
 #define COFF_WITH_PE
 #define PCRELOFFSET        TRUE
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 
 #define MCORE_PE
 
Index: bfd/pei-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-mips.c,v
retrieving revision 1.8
diff -p -u -r1.8 pei-mips.c
--- bfd/pei-mips.c	3 Jul 2007 14:26:42 -0000	1.8
+++ bfd/pei-mips.c	3 Feb 2009 13:43:07 -0000
@@ -25,7 +25,8 @@
 #define TARGET_NAME "pei-mips"
 #define COFF_IMAGE_WITH_PE
 #define PCRELOFFSET TRUE
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 
 #include "pe-mips.c"
 
Index: bfd/pei-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-ppc.c,v
retrieving revision 1.9
diff -p -u -r1.9 pei-ppc.c
--- bfd/pei-ppc.c	18 Jul 2008 11:30:22 -0000	1.9
+++ bfd/pei-ppc.c	3 Feb 2009 13:43:07 -0000
@@ -35,7 +35,8 @@
 #define COFF_IMAGE_WITH_PE
 #define COFF_WITH_PE
 
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 
 /* FIXME: Verify PCRELOFFSET is always false */
 
Index: bfd/pei-sh.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-sh.c,v
retrieving revision 1.8
diff -p -u -r1.8 pei-sh.c
--- bfd/pei-sh.c	3 Jul 2007 14:26:42 -0000	1.8
+++ bfd/pei-sh.c	3 Feb 2009 13:43:07 -0000
@@ -28,7 +28,8 @@
 #define COFF_WITH_PE
 #define PCRELOFFSET TRUE
 #define TARGET_UNDERSCORE '_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 
 #include "coff-sh.c"
 
Index: bfd/pei-x86_64.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-x86_64.c,v
retrieving revision 1.3
diff -p -u -r1.3 pei-x86_64.c
--- bfd/pei-x86_64.c	3 Jul 2007 14:26:42 -0000	1.3
+++ bfd/pei-x86_64.c	3 Feb 2009 13:43:07 -0000
@@ -30,7 +30,8 @@
 #define COFF_WITH_pex64
 #define PCRELOFFSET 		TRUE
 #define TARGET_UNDERSCORE 	'_'
-#define COFF_LONG_SECTION_NAMES
+/* Long section names are not allowed in executable images, only object files.  */
+#undef COFF_LONG_SECTION_NAMES
 #define COFF_SUPPORT_GNU_LINKONCE
 #define COFF_LONG_FILENAMES
 




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]