[PATCH v4 0/4] PE delay import fixes

Jeremy Drake sourceware-bugzilla@jdrake.com
Wed Jun 11 17:27:23 GMT 2025


v4 rebased against master and moved a change from patch 2 into patch 1 so
that tests pass after every patch in the series.

Jeremy Drake (3):
  ld,dlltool: move read-only delayimp data into .rdata
  dlltool: respect use-nul-prefixed-import-tables option for delaylib
  bfd: populate delay import directory in PE header.

LIU Hao (1):
  bfd,ld,dlltool: Emit delay-load import data into its own section

 bfd/coffgen.c         | 15 +++++++
 bfd/pe-aarch64.c      |  2 +
 bfd/pe-arm.c          |  2 +
 bfd/pe-i386.c         |  2 +
 bfd/pe-x86_64.c       |  2 +
 bfd/peXXigen.c        | 51 +++++++++++++++++++++-
 bfd/pei-aarch64.c     |  2 +
 bfd/pei-arm.c         |  2 +
 bfd/pei-i386.c        |  2 +
 bfd/pei-loongarch64.c |  2 +
 bfd/pei-riscv64.c     |  2 +
 bfd/pei-x86_64.c      |  2 +
 bfd/syms.c            |  1 +
 binutils/dlltool.c    | 98 ++++++++++++++++++++++++++++++++++++-------
 ld/scripttempl/pe.sc  | 29 ++++++++++++-
 ld/scripttempl/pep.sc | 31 +++++++++++++-
 16 files changed, 226 insertions(+), 19 deletions(-)

Range-diff against v3:
1:  f77f8a9b86c ! 1:  8dc4f01572f bfd,ld,dlltool: Emit delay-load import data into its own section
    @@ Commit message

      ## bfd/coffgen.c ##
     @@
    - #include "coff/internal.h"
      #include "libcoff.h"
    + #include "elf-bfd.h"
      #include "hashtab.h"
     +#include "safe-ctype.h"

    @@ ld/scripttempl/pe.sc: if test "${RELOCATING}"; then
          KEEP (SORT(*)(.idata$6))
          KEEP (SORT(*)(.idata$7))'
     +  R_DIDAT234='
    ++    __DELAY_IMPORT_DIRECTORY_start__ = .;
     +    KEEP (SORT(*)(.didat$2))
     +    KEEP (SORT(*)(.didat$3))
    ++    __DELAY_IMPORT_DIRECTORY_end__ = .;
     +    /* These zeroes mark the end of the import list.  */
    -+    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
    ++    . += (__DELAY_IMPORT_DIRECTORY_end__ - __DELAY_IMPORT_DIRECTORY_start__) ? 8*4 : 0;
     +    KEEP (SORT(*)(.didat$4))'
     +  R_DIDAT5='KEEP (SORT(*)(.didat$5))'
     +  R_DIDAT67='
    @@ ld/scripttempl/pe.sc: SECTIONS
     +    /* This cannot currently be handled with grouped sections.
     +	See pe.em:sort_sections.  */
     +    ${R_DIDAT234}
    -+    ${RELOCATING+__DELAY_IAT_start__ = .;}
     +    ${R_DIDAT5}
    -+    ${RELOCATING+__DELAY_IAT_end__ = .;}
     +    ${R_DIDAT67}
     +  }
     +
    @@ ld/scripttempl/pep.sc: if test "${RELOCATING}"; then
          KEEP (SORT(*)(.idata$6))
          KEEP (SORT(*)(.idata$7))'
     +  R_DIDAT234='
    ++    __DELAY_IMPORT_DIRECTORY_start__ = .;
     +    KEEP (SORT(*)(.didat$2))
     +    KEEP (SORT(*)(.didat$3))
    ++    __DELAY_IMPORT_DIRECTORY_end__ = .;
     +    /* These zeroes mark the end of the import list.  */
    -+    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
    ++    . += (__DELAY_IMPORT_DIRECTORY_end__ - __DELAY_IMPORT_DIRECTORY_start__) ? 8*4 : 0;
     +    . = ALIGN(8);
     +    KEEP (SORT(*)(.didat$4))'
     +  R_DIDAT5='SORT(*)(.didat$5)'
    @@ ld/scripttempl/pep.sc: SECTIONS
     +    /* This cannot currently be handled with grouped sections.
     +	See pep.em:sort_sections.  */
     +    ${R_DIDAT234}
    -+    ${RELOCATING+__DELAY_IAT_start__ = .;}
     +    ${R_DIDAT5}
    -+    ${RELOCATING+__DELAY_IAT_end__ = .;}
     +    ${R_DIDAT67}
     +  }
     +
2:  4d70d6041f6 ! 2:  8ec2e6482ff ld,dlltool: move read-only delayimp data into .rdata
    @@ binutils/dlltool.c: make_delay_head (void)
        assemble_file (TMP_HEAD_S, TMP_HEAD_O);

      ## ld/scripttempl/pe.sc ##
    -@@ ld/scripttempl/pe.sc: if test "${RELOCATING}"; then
    -     KEEP (SORT(*)(.idata$6))
    -     KEEP (SORT(*)(.idata$7))'
    -   R_DIDAT234='
    -+    __DELAY_IMPORT_DIRECTORY_start__ = .;
    -     KEEP (SORT(*)(.didat$2))
    -     KEEP (SORT(*)(.didat$3))
    -+    __DELAY_IMPORT_DIRECTORY_end__ = .;
    -     /* These zeroes mark the end of the import list.  */
    --    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
    -+    . += (__DELAY_IMPORT_DIRECTORY_end__ - __DELAY_IMPORT_DIRECTORY_start__) ? 8*4 : 0;
    -     KEEP (SORT(*)(.didat$4))'
    -   R_DIDAT5='KEEP (SORT(*)(.didat$5))'
    -   R_DIDAT67='
     @@ ld/scripttempl/pe.sc: SECTIONS
          ${RELOCATING+__rt_psrelocs_start = .;}
          ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
    @@ ld/scripttempl/pe.sc: SECTIONS
          /* This cannot currently be handled with grouped sections.
      	See pe.em:sort_sections.  */
     -    ${R_DIDAT234}
    --    ${RELOCATING+__DELAY_IAT_start__ = .;}
          ${R_DIDAT5}
    --    ${RELOCATING+__DELAY_IAT_end__ = .;}
     -    ${R_DIDAT67}
        }

        /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be

      ## ld/scripttempl/pep.sc ##
    -@@ ld/scripttempl/pep.sc: if test "${RELOCATING}"; then
    -     KEEP (SORT(*)(.idata$6))
    -     KEEP (SORT(*)(.idata$7))'
    -   R_DIDAT234='
    -+    __DELAY_IMPORT_DIRECTORY_start__ = .;
    -     KEEP (SORT(*)(.didat$2))
    -     KEEP (SORT(*)(.didat$3))
    -+    __DELAY_IMPORT_DIRECTORY_end__ = .;
    -     /* These zeroes mark the end of the import list.  */
    --    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
    -+    . += (__DELAY_IMPORT_DIRECTORY_end__ - __DELAY_IMPORT_DIRECTORY_start__) ? 8*4 : 0;
    -     . = ALIGN(8);
    -     KEEP (SORT(*)(.didat$4))'
    -   R_DIDAT5='SORT(*)(.didat$5)'
     @@ ld/scripttempl/pep.sc: SECTIONS
          ${RELOCATING+__rt_psrelocs_start = .;}
          ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
    @@ ld/scripttempl/pep.sc: SECTIONS
          /* This cannot currently be handled with grouped sections.
      	See pep.em:sort_sections.  */
     -    ${R_DIDAT234}
    --    ${RELOCATING+__DELAY_IAT_start__ = .;}
          ${R_DIDAT5}
    --    ${RELOCATING+__DELAY_IAT_end__ = .;}
     -    ${R_DIDAT67}
        }

3:  39640f8a87d = 3:  4b2d0bccbff dlltool: respect use-nul-prefixed-import-tables option for delaylib
4:  474189b5847 = 4:  159f150682d bfd: populate delay import directory in PE header.
-- 
2.49.0.windows.1



More information about the Binutils mailing list