Skip to content

Commit 8a36989

Browse files
committed
[LLD][COFF] Emit base relocation for native CHPE metadata pointer on ARM64X
1 parent 1fa0302 commit 8a36989

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lld/COFF/Writer.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,38 @@ void Writer::createDynamicRelocs() {
25942594
LOAD_CONFIG_TABLE * sizeof(data_directory) +
25952595
offsetof(data_directory, Size),
25962596
0);
2597+
2598+
// Insert a 64-bit relocation for CHPEMetadataPointer. Its value will be set
2599+
// later in prepareLoadConfig to match the value in the EC load config.
2600+
// However, a base relocation must be allocated in advance, so we handle it
2601+
// here.
2602+
if (ctx.symtab.loadConfigSym && ctx.hybridSymtab->loadConfigSym &&
2603+
ctx.symtab.loadConfigSize >=
2604+
offsetof(coff_load_configuration64, CHPEMetadataPointer) +
2605+
sizeof(coff_load_configuration64::CHPEMetadataPointer)) {
2606+
DefinedRegular *sym = ctx.symtab.loadConfigSym;
2607+
SectionChunk *chunk = sym->getChunk();
2608+
ArrayRef<coff_relocation> curRelocs = chunk->getRelocs();
2609+
MutableArrayRef<coff_relocation> newRelocs(
2610+
bAlloc().Allocate<coff_relocation>(curRelocs.size() + 1),
2611+
curRelocs.size() + 1);
2612+
size_t chpeOffset = sym->getValue() + offsetof(coff_load_configuration64,
2613+
CHPEMetadataPointer);
2614+
size_t i;
2615+
for (i = 0;
2616+
i < curRelocs.size() && curRelocs[i].VirtualAddress < chpeOffset; ++i)
2617+
newRelocs[i] = curRelocs[i];
2618+
newRelocs[i].VirtualAddress = chpeOffset;
2619+
// The specific symbol used here is irrelevant as long as it's valid, since
2620+
// it will be overridden by prepareLoadConfig. Use the load config symbol
2621+
// itself.
2622+
newRelocs[i].SymbolTableIndex =
2623+
chunk->file->getCOFFObj()->getSymbolIndex(sym->getCOFFSymbol());
2624+
newRelocs[i].Type = IMAGE_REL_ARM64_ADDR64;
2625+
for (; i < curRelocs.size(); ++i)
2626+
newRelocs[i + 1] = curRelocs[i];
2627+
chunk->setRelocs(newRelocs);
2628+
}
25972629
}
25982630

25992631
PartialSection *Writer::createPartialSection(StringRef name,

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)