[lld] [LLD][COFF] Emit base relocation for native CHPE metadata pointer on ARM64X (PR #121500)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 5 07:07:45 PST 2025


================
@@ -2594,6 +2594,38 @@ void Writer::createDynamicRelocs() {
                              LOAD_CONFIG_TABLE * sizeof(data_directory) +
                              offsetof(data_directory, Size),
                          0);
+
+  // Insert a 64-bit relocation for CHPEMetadataPointer. Its value will be set
+  // later in prepareLoadConfig to match the value in the EC load config.
+  // However, a base relocation must be allocated in advance, so we handle it
+  // here.
+  if (ctx.symtab.loadConfigSym && ctx.hybridSymtab->loadConfigSym &&
+      ctx.symtab.loadConfigSize >=
+          offsetof(coff_load_configuration64, CHPEMetadataPointer) +
+              sizeof(coff_load_configuration64::CHPEMetadataPointer)) {
+    DefinedRegular *sym = ctx.symtab.loadConfigSym;
+    SectionChunk *chunk = sym->getChunk();
+    ArrayRef<coff_relocation> curRelocs = chunk->getRelocs();
+    MutableArrayRef<coff_relocation> newRelocs(
+        bAlloc().Allocate<coff_relocation>(curRelocs.size() + 1),
+        curRelocs.size() + 1);
+    size_t chpeOffset = sym->getValue() + offsetof(coff_load_configuration64,
+                                                   CHPEMetadataPointer);
+    size_t i;
+    for (i = 0;
+         i < curRelocs.size() && curRelocs[i].VirtualAddress < chpeOffset; ++i)
+      newRelocs[i] = curRelocs[i];
+    newRelocs[i].VirtualAddress = chpeOffset;
+    // The specific symbol used here is irrelevant as long as it's valid, since
+    // it will be overridden by prepareLoadConfig. Use the load config symbol
----------------
cjacek wrote:

This wasn't about dynamic relocations; it updates the pointer within the load configuration itself, which was the part affected by this relocation. That said, this aspect no longer exists in the updated version.

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


More information about the llvm-commits mailing list