[lld] [lld][COFF] Support .pdata section on ARM64EC targets. (PR #72521)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 17:49:01 PST 2023


================
@@ -1665,10 +1689,15 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
     dir[RESOURCE_TABLE].RelativeVirtualAddress = rsrcSec->getRVA();
     dir[RESOURCE_TABLE].Size = rsrcSec->getVirtualSize();
   }
-  if (firstPdata) {
-    dir[EXCEPTION_TABLE].RelativeVirtualAddress = firstPdata->getRVA();
-    dir[EXCEPTION_TABLE].Size =
-        lastPdata->getRVA() + lastPdata->getSize() - firstPdata->getRVA();
+  Chunk *firstPdataChunk =
+      ctx.config.machine == ARM64EC ? firstHybridPdata : firstPdata;
+  if (firstPdataChunk) {
+    Chunk *lastPdataChunk =
+        ctx.config.machine == ARM64EC ? lastHybridPdata : lastPdata;
----------------
cjacek wrote:

It's a bit more tricky due to ARM64X requirements. ARM64X also may contain X64 .pdata, but needs to use ARM64 variant both here and in CHPE metadata (setECSymbols). On ARM64X data entry is overwritten in runtime with X64 .pdata using [runtime relocations](https://ffri.github.io/ProjectChameleon/new_reloc_chpev2/) (not part of this PR, it requires a number of dependencies first; I have it partially prototyped in my private tree, but it's not yet complete enough to be useful).

If I swapped roles on ARM64X then setECSymbols would have the same problem, but the other way around. Swapping it only for pure ARM64EC would make those two targets disagree, leading to even more complications.

Thinking some more about it, I think we may make it slightly nicer here by storing the first and last chunk in a struct. I will create a separated PR with a NFC commit that we could take before this PR. I will also update this PR addressing other comments and improving comments here (not using the new struct yet to avoid force-pushing until we decided if we want that; I think it makes things slightly nicer, but I'd appreciate an opinion if I'm not overthinking it).

Thanks for review!

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


More information about the llvm-commits mailing list