[PATCH v2 1/1] Fix IAT (Import Address Table) alignment on AArch64

Evgeny Karpov evgeny.karpov@arm.com
Wed Apr 15 08:05:21 GMT 2026


The IAT should be aligned to 8 bytes in aarch64-w64-mingw32, otherwise, it might
result in relocation issues.

When a function is imported from DLL, it generates the following code:

adrp    x19, __imp_fn
ldr     x19, [x19, #:lo12:__imp_fn]

8 byte alignment is required for ldr relocation. Addresses are placed in IAT.
The size of the chunk on AArch64 is 8 bytes.
If IAT is not aligned to 8 bytes, the relocation issue appears.
This patch fixes this issue by aligning IAT to 8 bytes on AArch64.

binutils/ChangeLog:

	* dlltool.c (make_head): Add 8 byte alignment on AArch64.
---
 binutils/dlltool.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 94805fcd334..44823e120af 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -2735,6 +2735,12 @@ make_head (void)
   if (!no_idata5)
     {
       fprintf (f, "\t.section\t.idata$5\n");
+
+      /* Align IAT (Import Address Table) to 8 bytes on AArch64.
+	 https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-address-table.  */
+      if (machine == MAARCH64)
+	fprintf (f, "\t.p2align 3\n");
+
       if (use_nul_prefixed_import_tables)
 	{
 	  if (create_for_pep)


More information about the Binutils mailing list