[PATCH v4 1/2] bfd: fill in PE load config directory entry.

Jeremy Drake sourceware-bugzilla@jdrake.com
Tue Apr 1 20:17:53 GMT 2025


On Tue, 1 Apr 2025, Jeremy Drake wrote:

> On Tue, 1 Apr 2025, Jan Beulich wrote:
>
> I can either: add a remark "If anyone cares about such versions, the size
> would need to be overridden for them."  Or, if you can point out the
> proper incantation to identify i386 here I can do that.  I confirmed on
> Windows 11 that for i386 modules it will accept either 0x40 or the 32-bit
> value at the VirtualAddress as the Size, while for x86_64 modules it will
> only accept the 32-bit value at the VirtualAddress.

This is what I came up with.  I'll wait to send a new patch series to hear
if that's right, to hopefully avoid yet another 24-hour roundtrip.

diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 0dec04fcc3e..0b43ed2ee15 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -4601,21 +4601,22 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
              result = false;
            }

-         /* The size is stored as the first 4 bytes at _load_config_used.
-            The Microsoft PE format documentation says for compatibility with
-            Windows XP and earlier, the size must be 64 for x86 images.  If
-            anyone cares about those versions, the size should be overridden
-            for i386.  */
+         /* The size is stored as the first 4 bytes at _load_config_used.  */
          if (bfd_get_section_contents (abfd,
                h1->root.u.def.section->output_section, data,
                h1->root.u.def.section->output_offset + h1->root.u.def.value,
                4))
            {
+             uint32_t size = bfd_get_32 (abfd, data);
+             /* The Microsoft PE format documentation says for compatibility
+                with Windows XP and earlier, the size must be 64 for x86
+                images.  */
              pe_data (abfd)->pe_opthdr.DataDirectory[PE_LOAD_CONFIG_TABLE].Size =
-               bfd_get_32 (abfd, data);
+               (bfd_get_arch (abfd) == bfd_arch_i386 &&
+                (bfd_get_mach (abfd) & ~bfd_mach_i386_intel_syntax) ==
+                 bfd_mach_i386_i386) ? 64 : size;

-             if (pe_data (abfd)->pe_opthdr.DataDirectory[PE_LOAD_CONFIG_TABLE].Size >
-                 h1->root.u.def.section->size - h1->root.u.def.value)
+             if (size > h1->root.u.def.section->size - h1->root.u.def.value)
                {
                  _bfd_error_handler
                    (_("%pB: unable to fill in DataDictionary[%d]: size too large for the containing section"),


More information about the Binutils mailing list