-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[LLD][COFF] Add support for alternate entry point in CHPE metadata on ARM64X #123346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2352,6 +2352,20 @@ void Writer::setECSymbols() { | |
delayIatCopySym, "__hybrid_auxiliary_delayload_iat_copy", | ||
delayIdata.getAuxIatCopy().empty() ? nullptr | ||
: delayIdata.getAuxIatCopy().front()); | ||
|
||
if (ctx.hybridSymtab) { | ||
// For the hybrid image, set the alternate entry point to the EC entry | ||
// point. In the hybrid view, it is swapped to the native entry point | ||
// using ARM64X relocations. | ||
if (auto altEntrySym = cast_or_null<Defined>(ctx.hybridSymtab->entry)) { | ||
// If the entry is an EC export thunk, use its target instead. | ||
if (auto thunkChunk = | ||
dyn_cast<ECExportThunkChunk>(altEntrySym->getChunk())) | ||
altEntrySym = thunkChunk->target; | ||
symtab->findUnderscore("__arm64x_native_entrypoint") | ||
->replaceKeepingName(altEntrySym, sizeof(SymbolUnion)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dereferencing the output of e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, we similarly dereference other symbols with Merged, thanks! |
||
} | ||
} | ||
} | ||
|
||
// Write section contents to a mmap'ed file. | ||
|
@@ -2586,12 +2600,23 @@ void Writer::createDynamicRelocs() { | |
coffHeaderOffset + offsetof(coff_file_header, Machine), | ||
AMD64); | ||
|
||
if (ctx.symtab.entry != ctx.hybridSymtab->entry) | ||
if (ctx.symtab.entry != ctx.hybridSymtab->entry) { | ||
ctx.dynamicRelocs->add(IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE, sizeof(uint32_t), | ||
peHeaderOffset + | ||
offsetof(pe32plus_header, AddressOfEntryPoint), | ||
cast_or_null<Defined>(ctx.hybridSymtab->entry)); | ||
|
||
// Swap the alternate entry point in the CHPE metadata. | ||
Symbol *s = ctx.hybridSymtab->findUnderscore("__chpe_metadata"); | ||
if (auto chpeSym = cast_or_null<DefinedRegular>(s)) | ||
ctx.dynamicRelocs->add( | ||
IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE, sizeof(uint32_t), | ||
Arm64XRelocVal(chpeSym, offsetof(chpe_metadata, AlternateEntryPoint)), | ||
cast_or_null<Defined>(ctx.symtab.entry)); | ||
else | ||
Warn(ctx) << "'__chpe_metadata' is missing for ARM64X target"; | ||
} | ||
|
||
// Set the hybrid load config to the EC load config. | ||
ctx.dynamicRelocs->add(IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE, sizeof(uint32_t), | ||
dataDirOffset64 + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assume that we had a nonzero number of relocations here, so that
pageHeader
was initialized?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, every ARM64X image will have at least one relocation for the machine field in the PE header. If other types of dynamic relocations are used in the future, this whole chunk code will have to be skipped anyway.