Skip to content

Commit 5ab285e

Browse files
authored
[LLD][COFF] Fix ARM64X CHPE exception data size relocation when no x86 .pdata is present (#144085)
Fixes an issue where we incorrectly skip setting the relocation value if `hybridPdata.first` is null.
1 parent f62a8ab commit 5ab285e

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

lld/COFF/Writer.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,22 +2495,16 @@ void Writer::setECSymbols() {
24952495
offsetof(data_directory, Size),
24962496
ctx.symtab.edataEnd->getRVA() - ctx.symtab.edataStart->getRVA() +
24972497
ctx.symtab.edataEnd->getSize());
2498-
if (hybridPdata.first) {
2498+
if (hybridPdata.first)
24992499
ctx.dynamicRelocs->set(
25002500
dataDirOffset64 + EXCEPTION_TABLE * sizeof(data_directory) +
25012501
offsetof(data_directory, Size),
25022502
hybridPdata.last->getRVA() - hybridPdata.first->getRVA() +
25032503
hybridPdata.last->getSize());
2504-
if (chpeSym) {
2505-
size_t size = 0;
2506-
if (pdata.first)
2507-
size = pdata.last->getRVA() + pdata.last->getSize() -
2508-
pdata.first->getRVA();
2509-
ctx.dynamicRelocs->set(chpeSym->getRVA() +
2510-
offsetof(chpe_metadata, ExtraRFETableSize),
2511-
size);
2512-
}
2513-
}
2504+
if (chpeSym && pdata.first)
2505+
ctx.dynamicRelocs->set(
2506+
chpeSym->getRVA() + offsetof(chpe_metadata, ExtraRFETableSize),
2507+
pdata.last->getRVA() + pdata.last->getSize() - pdata.first->getRVA());
25142508
}
25152509
}
25162510

lld/test/COFF/pdata-arm64ec.test

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,63 @@ DIR3-NEXT: ExtraRFETableSize: 0x10
8080
DIR3: ]
8181
DIR3: }
8282

83+
arm64x with no x86 .pdata:
84+
8385
RUN: llvm-objdump -s --section=.pdata test4.dll | FileCheck -check-prefix=DATA4 %s
8486
DATA4: 180006000 00100000 11000001 00200000 11000001 ......... ......
8587
DATA4: 180006010 00300000 0e300000
8688

89+
RUN: lld-link -out:testx2.dll -machine:arm64x arm64-func-sym.obj arm64ec-func-sym.obj \
90+
RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -dll -noentry
91+
92+
RUN: llvm-readobj --headers --coff-load-config testx2.dll | FileCheck -check-prefix=DIR4 %s
93+
DIR4: ImageOptionalHeader {
94+
DIR4: DataDirectory {
95+
DIR4: ExceptionTableRVA: 0x5000
96+
DIR4-NEXT: ExceptionTableSize: 0x10
97+
DIR4: }
98+
DIR4: }
99+
DIR4: CHPEMetadata [
100+
DIR4: ExtraRFETable: 0x0
101+
DIR4-NEXT: ExtraRFETableSize: 0x0
102+
DIR4: ]
103+
DIR4: HybridObject {
104+
DIR4: ImageOptionalHeader {
105+
DIR4: ExceptionTableRVA: 0x0
106+
DIR4-NEXT: ExceptionTableSize: 0x0
107+
DIR4: }
108+
DIR4: CHPEMetadata [
109+
DIR4: ExtraRFETable: 0x5000
110+
DIR4-NEXT: ExtraRFETableSize: 0x10
111+
DIR4: ]
112+
DIR4: }
113+
114+
arm64x with no ARM .pdata:
115+
116+
RUN: lld-link -out:testx3.dll -machine:arm64x x86_64-func-sym.obj loadconfig-arm64.obj loadconfig-arm64ec.obj -dll -noentry
117+
118+
RUN: llvm-readobj --headers --coff-load-config testx3.dll | FileCheck -check-prefix=DIR5 %s
119+
DIR5: ImageOptionalHeader {
120+
DIR5: DataDirectory {
121+
DIR5: ExceptionTableRVA: 0x0
122+
DIR5-NEXT: ExceptionTableSize: 0x0
123+
DIR5: }
124+
DIR5: }
125+
DIR5: CHPEMetadata [
126+
DIR5: ExtraRFETable: 0x4000
127+
DIR5-NEXT: ExtraRFETableSize: 0xC
128+
DIR5: ]
129+
DIR5: HybridObject {
130+
DIR5: ImageOptionalHeader {
131+
DIR5: ExceptionTableRVA: 0x4000
132+
DIR5-NEXT: ExceptionTableSize: 0xC
133+
DIR5: }
134+
DIR5: CHPEMetadata [
135+
DIR5: ExtraRFETable: 0x0
136+
DIR5-NEXT: ExtraRFETableSize: 0x0
137+
DIR5: ]
138+
DIR5: }
139+
87140
Order of inputs doesn't matter, the data is sorted by type and RVA:
88141

89142
RUN: lld-link -out:test5.dll -machine:arm64ec x86_64-func-sym.obj arm64ec-func-sym.obj \

0 commit comments

Comments
 (0)