[lld] [LLD][COFF] Keep hasData true in NullChunk constructor (PR #124368)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 15:43:56 PST 2025


https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/124368

`NullChunk` instances do write data, even if it's always zero. Setting `hasData` to false causes `Writer::assignAddresses` to ignore them when calculating `rawSize`. This usually isn't an issue, as null chunks are typically in the middle of a section and later chunks adjust the size. However, on ARM64EC, the auxiliary IAT is placed at the end of the `.rdata` section and ends with a null chunk, making this problematic.

>From 12f780d5dc86e2bffc3db82fbaafef9f803e9ea8 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Sat, 25 Jan 2025 00:36:59 +0100
Subject: [PATCH] [LLD][COFF] Keep hasData true in NullChunk constructor

NullChunk instances do write data, even if it's always zero. Setting hasData to false
causes Writer::assignAddresses to ignore them when calculating rawSize. This usually
isn't an issue, as null chunks are typically in the middle of a section and later
chunks adjust the size. However, on ARM64EC, the auxiliary IAT is placed at the end
of the .rdata section and ends with a null chunk, making this problematic.
---
 lld/COFF/DLL.cpp                  |  1 -
 lld/test/COFF/arm64ec-import.test | 13 +++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp
index 6a3f8eb21e8475..ae3a8047b7008f 100644
--- a/lld/COFF/DLL.cpp
+++ b/lld/COFF/DLL.cpp
@@ -132,7 +132,6 @@ class ImportDirectoryChunk : public NonSectionChunk {
 class NullChunk : public NonSectionChunk {
 public:
   explicit NullChunk(size_t n, uint32_t align) : size(n) {
-    hasData = false;
     setAlignment(align);
   }
   explicit NullChunk(COFFLinkerContext &ctx)
diff --git a/lld/test/COFF/arm64ec-import.test b/lld/test/COFF/arm64ec-import.test
index 033c27884be02c..bb2b772081d590 100644
--- a/lld/test/COFF/arm64ec-import.test
+++ b/lld/test/COFF/arm64ec-import.test
@@ -160,6 +160,19 @@ BASERELOC-NEXT:     Type: DIR64
 BASERELOC-NEXT:     Address: 0x5020
 BASERELOC-NEXT:   }
 
+
+Build with -filealign:8 to enable precise size checking.
+
+RUN: lld-link -machine:arm64ec -dll -noentry -out:out-size.dll loadconfig-arm64ec.obj icall.obj hybmp.obj \
+RUN:          test.obj test-arm64ec.lib test2-arm64ec.lib -filealign:8
+
+RUN: llvm-readobj --headers out-size.dll | FileCheck --check-prefix=RDATA-HEADER %s
+
+RDATA-HEADER:      Name: .rdata (2E 72 64 61 74 61 00 00)
+RDATA-HEADER-NEXT: VirtualSize: 0x2030
+RDATA-HEADER-NEXT: VirtualAddress: 0x3000
+RDATA-HEADER-NEXT: RawDataSize: 8240
+
 #--- test.s
     .section .test, "r"
     .globl arm64ec_data_sym



More information about the llvm-commits mailing list