Skip to content

Commit 3a5fa6d

Browse files
committed
[LLD][COFF] Emit base relocation for native CHPE metadata pointer on ARM64X
1 parent 9d5299e commit 3a5fa6d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lld/COFF/Chunks.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,22 @@ void SectionChunk::getBaserels(std::vector<Baserel> *res) {
564564
continue;
565565
res->emplace_back(rva + rel.VirtualAddress, ty);
566566
}
567+
568+
// Insert a 64-bit relocation for CHPEMetadataPointer in the native load
569+
// config of a hybrid ARM64X image. Its value will be set in prepareLoadConfig
570+
// to match the value in the EC load config, which is expected to be
571+
// a relocatable pointer to the __chpe_metadata symbol.
572+
COFFLinkerContext &ctx = file->symtab.ctx;
573+
if (ctx.hybridSymtab && ctx.symtab.loadConfigSym &&
574+
ctx.symtab.loadConfigSym->getChunk() == this &&
575+
ctx.hybridSymtab->loadConfigSym &&
576+
ctx.symtab.loadConfigSize >=
577+
offsetof(coff_load_configuration64, CHPEMetadataPointer) +
578+
sizeof(coff_load_configuration64::CHPEMetadataPointer))
579+
res->emplace_back(
580+
ctx.symtab.loadConfigSym->getRVA() +
581+
offsetof(coff_load_configuration64, CHPEMetadataPointer),
582+
IMAGE_REL_BASED_DIR64);
567583
}
568584

569585
// MinGW specific.

lld/test/COFF/arm64x-loadconfig.s

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@
118118
// BASERELOC: BaseReloc [
119119
// BASERELOC-NEXT: Entry {
120120
// BASERELOC-NEXT: Type: DIR64
121+
// BASERELOC-NEXT: Address: 0x10C8
122+
// BASERELOC-NEXT: }
123+
// BASERELOC-NEXT: Entry {
124+
// BASERELOC-NEXT: Type: DIR64
121125
// BASERELOC-NEXT: Address: 0x1208
122126
// BASERELOC-NEXT: }
123127
// BASERELOC-NEXT: Entry {
124-
// BASERELOC: Type: DIR64
128+
// BASERELOC-NEXT: Type: DIR64
125129
// BASERELOC-NEXT: Address: 0x2074
126130
// BASERELOC-NEXT: }
127131

0 commit comments

Comments
 (0)