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

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 15:44:27 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

Author: Jacek Caban (cjacek)

<details>
<summary>Changes</summary>

`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.

---
Full diff: https://github.com/llvm/llvm-project/pull/124368.diff


2 Files Affected:

- (modified) lld/COFF/DLL.cpp (-1) 
- (modified) lld/test/COFF/arm64ec-import.test (+13) 


``````````diff
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

``````````

</details>


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


More information about the llvm-commits mailing list