Skip to content

Commit 31a6dbe

Browse files
authored
[LLD][COFF] Add Support for ARM64EC pseudo relocations (#113832)
1 parent 97fb21a commit 31a6dbe

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

lld/COFF/Chunks.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ void SectionChunk::getBaserels(std::vector<Baserel> *res) {
570570
// another DLL) This returns the size the relocation is supposed to update,
571571
// in bits, or 0 if the relocation cannot be handled as a runtime pseudo
572572
// relocation.
573-
static int getRuntimePseudoRelocSize(uint16_t type,
574-
llvm::COFF::MachineTypes machine) {
573+
static int getRuntimePseudoRelocSize(uint16_t type, Triple::ArchType arch) {
575574
// Relocations that either contain an absolute address, or a plain
576575
// relative offset, since the runtime pseudo reloc implementation
577576
// adds 8/16/32/64 bit values to a memory address.
@@ -597,8 +596,8 @@ static int getRuntimePseudoRelocSize(uint16_t type,
597596
// the image, or temporarily changed at runtime with VirtualProtect.
598597
// Since this only operates on direct address values, it doesn't work for
599598
// ARM/ARM64 relocations, other than the plain ADDR32/ADDR64 relocations.
600-
switch (machine) {
601-
case AMD64:
599+
switch (arch) {
600+
case Triple::x86_64:
602601
switch (type) {
603602
case IMAGE_REL_AMD64_ADDR64:
604603
return 64;
@@ -613,22 +612,22 @@ static int getRuntimePseudoRelocSize(uint16_t type,
613612
default:
614613
return 0;
615614
}
616-
case I386:
615+
case Triple::x86:
617616
switch (type) {
618617
case IMAGE_REL_I386_DIR32:
619618
case IMAGE_REL_I386_REL32:
620619
return 32;
621620
default:
622621
return 0;
623622
}
624-
case ARMNT:
623+
case Triple::thumb:
625624
switch (type) {
626625
case IMAGE_REL_ARM_ADDR32:
627626
return 32;
628627
default:
629628
return 0;
630629
}
631-
case ARM64:
630+
case Triple::aarch64:
632631
switch (type) {
633632
case IMAGE_REL_ARM64_ADDR64:
634633
return 64;
@@ -661,8 +660,7 @@ void SectionChunk::getRuntimePseudoRelocs(
661660
// alive. Thus such dangling references in DWARF sections are expected.
662661
if (!target->getChunk())
663662
continue;
664-
int sizeInBits =
665-
getRuntimePseudoRelocSize(rel.Type, file->ctx.config.machine);
663+
int sizeInBits = getRuntimePseudoRelocSize(rel.Type, getArch());
666664
if (sizeInBits == 0) {
667665
error("unable to automatically import from " + target->getName() +
668666
" with relocation type " +
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# REQUIRES: aarch64, x86
2+
RUN: split-file %s %t.dir && cd %t.dir
3+
4+
RUN: llvm-lib -machine:arm64ec -out:libtest.a -def:test.def
5+
RUN: llvm-mc -triple=arm64ec-windows-gnu arm64ec.s -filetype=obj -o arm64ec.obj
6+
RUN: llvm-mc -triple=arm64ec-windows-gnu x86_64.s -filetype=obj -o x86_64.obj
7+
8+
RUN: lld-link -machine:arm64ec -out:out.dll -dll -noentry x86_64.obj arm64ec.obj libtest.a -lldmingw
9+
10+
RUN: llvm-readobj --coff-imports out.dll | FileCheck -check-prefix=IMPORTS %s
11+
RUN: llvm-objdump -s out.dll | FileCheck --check-prefix=CONTENTS %s
12+
13+
IMPORTS: Import {
14+
IMPORTS-NEXT: Name: test.dll
15+
IMPORTS-NEXT: ImportLookupTableRVA: 0x40E0
16+
IMPORTS-NEXT: ImportAddressTableRVA: 0x3000
17+
IMPORTS-NEXT: Symbol: variable (0)
18+
IMPORTS-NEXT: }
19+
20+
Runtime pseudo relocation list header at 0x401c, consisting of 0x0, 0x0, 0x1.
21+
The first runtime pseudo relocation is from an x86_64 object file, with import
22+
from 0x3000, applied at 0x7000 with a size of 32 bits. The second pseudo
23+
relocation is from an ARM64EC object file, with import from 0x3000, applied
24+
at 0x7008 with a size of 32 bits.
25+
26+
CONTENTS: Contents of section .rdata:
27+
CONTENTS: 180004010 00200000 10200000 00200000 00000000
28+
CONTENTS: 180004020 00000000 01000000 00300000 00700000
29+
CONTENTS: 180004030 40000000 00300000 08700000 40000000
30+
31+
CONTENTS: Contents of section .test:
32+
CONTENTS-NEXT: 180007000 00300080 01000000 00300080 01000000
33+
CONTENTS-NEXT: 180007010 1c400080 01000000 40400080 01000000
34+
35+
#--- arm64ec.s
36+
.text
37+
.global "#_pei386_runtime_relocator"
38+
"#_pei386_runtime_relocator":
39+
ret
40+
41+
.weak_anti_dep _pei386_runtime_relocator
42+
.set _pei386_runtime_relocator,"#_pei386_runtime_relocator"
43+
44+
.section .test,"dr"
45+
.quad variable
46+
.quad __RUNTIME_PSEUDO_RELOC_LIST__
47+
.quad __RUNTIME_PSEUDO_RELOC_LIST_END__
48+
49+
#--- x86_64.s
50+
.section .test,"dr"
51+
.quad variable
52+
53+
#--- test.def
54+
LIBRARY test.dll
55+
EXPORTS
56+
variable DATA

0 commit comments

Comments
 (0)