[lld] [LLD][COFF] Add support for alternate entry point in CHPE metadata on ARM64X (PR #123346)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 01:06:43 PST 2025


================
@@ -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));
----------------
mstorsjo wrote:

Dereferencing the output of e.g. `findUnderscore()` directly feels a bit scary, but I guess this is a symbol that we always define ourselves in the linker, unconditionally when linking EC code, so I guess it's fine.

https://github.com/llvm/llvm-project/pull/123346


More information about the llvm-commits mailing list