-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LLD][COFF] Keep hasData true in NullChunk constructor #124368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
This should fix CI failure in #124189. |
@llvm/pr-subscribers-platform-windows @llvm/pr-subscribers-lld Author: Jacek Caban (cjacek) Changes
Full diff: https://github.com/llvm/llvm-project/pull/124368.diff 2 Files Affected:
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
|
@llvm/pr-subscribers-lld-coff Author: Jacek Caban (cjacek) Changes
Full diff: https://github.com/llvm/llvm-project/pull/124368.diff 2 Files Affected:
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
|
Can you elaborate on how this is problematic? Usually we do this for e.g. the |
In To create behavior similar to |
Ok, I see. Yeah we don’t need to do this like bss; this should be fine if you just amend the commit message to explain that we do need to allocate actual space for it as we do memset it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if the commit message is clarified
NullChunk
instances do write data, even if it's always zero. SettinghasData
to falsecauses
Writer::assignAddresses
to ignore them when calculatingrawSize
. This typicallyisn't an issue, as null chunks are usually positioned within a section, and later
chunks adjust the size accordingly.
However, on ARM64EC, the auxiliary IAT is placed at the end of the
.rdata
section andterminates with a null chunk. As a result,
rawSize
is never updated to account for it,and space for the null chunk is not allocated. Consequently, when
NullChunk::writeTo
is called, it receives an invalid pointer - either pointing to the next section or
beyond the allocated buffer.