Skip to content

Commit 6f94066

Browse files
committed
[LLD][COFF] Redirect __imp_ Symbols to __imp_aux_ on ARM64EC for x64 Sections
On ARM64EC, __imp_ symbols reference the auxiliary IAT, while __imp_aux_ symbols reference the regular IAT. However, x86_64 code expects both to reference the regular IAT. This change adjusts the symbols accordingly, matching the behavior observed in the MSVC linker.
1 parent 02e4186 commit 6f94066

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lld/COFF/Chunks.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ void SectionChunk::applyRelocation(uint8_t *off,
422422
const coff_relocation &rel) const {
423423
auto *sym = dyn_cast_or_null<Defined>(file->getSymbol(rel.SymbolTableIndex));
424424

425+
// On ARM64EC, the __imp_ symbol references the auxiliary IAT, while the
426+
// __imp_aux_ symbol references the regular IAT. However, x86_64 code expects
427+
// both to reference the regular IAT, so adjust the symbol if necessary.
428+
if (sym && getMachine() == AMD64 && isArm64EC(file->ctx.config.machine)) {
429+
if (auto impSym = dyn_cast<DefinedImportData>(sym)) {
430+
if (impSym->file->impchkThunk && sym == impSym->file->impECSym)
431+
sym = impSym->file->impSym;
432+
}
433+
}
434+
425435
// Get the output section of the symbol for this relocation. The output
426436
// section is needed to compute SECREL and SECTION relocations used in debug
427437
// info.

lld/test/COFF/arm64ec-import.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ RUN: split-file %s %t.dir && cd %t.dir
44
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows test.s -o test.obj
55
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows icall.s -o icall.obj
66
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows hybmp.s -o hybmp.obj
7+
RUN: llvm-mc -filetype=obj -triple=x86_64-windows test.s -o test-x86_64.obj
78
RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj
89
RUN: llvm-lib -machine:arm64ec -def:test.def -out:test-arm64ec.lib
910
RUN: llvm-lib -machine:arm64ec -def:test2.def -out:test2-arm64ec.lib
@@ -17,8 +18,13 @@ Link using x86_64 import library:
1718
RUN: lld-link -machine:arm64ec -dll -noentry -out:out2.dll loadconfig-arm64ec.obj icall.obj hybmp.obj \
1819
RUN: test.obj test-x86_64.lib test2-arm64ec.lib
1920

21+
Link using x86_64 object file:
22+
RUN: lld-link -machine:arm64ec -dll -noentry -out:out3.dll loadconfig-arm64ec.obj icall.obj hybmp.obj \
23+
RUN: test-x86_64.obj test-arm64ec.lib test2-arm64ec.lib
24+
2025
RUN: llvm-readobj --coff-imports out.dll | FileCheck --check-prefix=IMPORTS %s
2126
RUN: llvm-readobj --coff-imports out2.dll | FileCheck --check-prefix=IMPORTS %s
27+
RUN: llvm-readobj --coff-imports out3.dll | FileCheck -check-prefix=IMPORTS %s
2228
IMPORTS: Import {
2329
IMPORTS-NEXT: Name: test.dll
2430
IMPORTS-NEXT: ImportLookupTableRVA:
@@ -36,6 +42,7 @@ IMPORTS-NEXT: }
3642

3743
RUN: llvm-objdump -d out.dll | FileCheck --check-prefix=DISASM %s
3844
RUN: llvm-objdump -d out2.dll | FileCheck --check-prefix=DISASM %s
45+
RUN: llvm-objdump -d out3.dll | FileCheck -check-prefix=DISASM %s
3946

4047
DISASM: 180001000: 52800000 mov w0, #0x0 // =0
4148
DISASM-NEXT: 180001004: d65f03c0 ret
@@ -74,20 +81,33 @@ TESTSEC-NEXT: 0x180007010 08300000 00500000 10300000 20300000
7481
TESTSEC-NEXT: 0x180007020 14100000 28100000 00200000 08100000
7582
TESTSEC-NEXT: 0x180007030 3c100000
7683

84+
RUN: llvm-readobj --hex-dump=.test out3.dll | FileCheck -check-prefix=TESTSEC-X64 %s
85+
TESTSEC-X64: 0x180007000 08300000 00300000 10300000 20300000
86+
TESTSEC-X64-NEXT: 0x180007010 08300000 00500000 10300000 20300000
87+
TESTSEC-X64-NEXT: 0x180007020 14100000 28100000 00200000 08100000
88+
7789
RUN: llvm-readobj --headers out.dll | FileCheck -check-prefix=HEADERS %s
90+
RUN: llvm-readobj --headers out2.dll | FileCheck -check-prefix=HEADERS %s
91+
RUN: llvm-readobj --headers out3.dll | FileCheck -check-prefix=HEADERS %s
7892
HEADERS: LoadConfigTableRVA: 0x4010
7993
HEADERS: IATRVA: 0x3000
8094
HEADERS: IATSize: 0x1000
8195

8296
RUN: llvm-readobj --coff-load-config out.dll | FileCheck -check-prefix=LOADCONFIG %s
97+
RUN: llvm-readobj --coff-load-config out2.dll | FileCheck -check-prefix=LOADCONFIG %s
98+
RUN: llvm-readobj --coff-load-config out3.dll | FileCheck -check-prefix=LOADCONFIG %s
8399
LOADCONFIG: AuxiliaryIAT: 0x5000
84100

85101
RUN: llvm-readobj --hex-dump=.rdata out.dll | FileCheck -check-prefix=RDATA %s
102+
RUN: llvm-readobj --hex-dump=.rdata out2.dll | FileCheck -check-prefix=RDATA %s
103+
RUN: llvm-readobj --hex-dump=.rdata out3.dll | FileCheck -check-prefix=RDATA %s
86104
RDATA: 0x180005000 00000000 00000000 14100080 01000000
87105
RDATA-NEXT: 0x180005010 28100080 01000000 00000000 00000000
88106
RDATA-NEXT: 0x180005020 48100080 01000000 00000000 00000000
89107

90108
RUN: llvm-readobj --coff-basereloc out.dll | FileCheck -check-prefix=BASERELOC %s
109+
RUN: llvm-readobj --coff-basereloc out2.dll | FileCheck -check-prefix=BASERELOC %s
110+
RUN: llvm-readobj --coff-basereloc out3.dll | FileCheck -check-prefix=BASERELOC %s
91111
BASERELOC: BaseReloc [
92112
BASERELOC-NOT: Address: 0x5000
93113
BASERELOC: Address: 0x5008

0 commit comments

Comments
 (0)