[lld] [LLD][COFF] Add support for ARM64EC auxiliary IAT (PR #108304)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 04:15:13 PDT 2024


================
@@ -1071,19 +1071,39 @@ void ImportFile::parse() {
   this->hdr = hdr;
   externalName = extName;
 
-  impSym = ctx.symtab.addImportData(impName, this);
+  bool isCode = hdr->getType() == llvm::COFF::IMPORT_CODE;
+
+  if (ctx.config.machine != ARM64EC) {
+    impSym = ctx.symtab.addImportData(impName, this, location);
+  } else {
+    // In addition to the regular IAT, ARM64EC also contains an auxiliary IAT,
+    // which holds addresses that are guaranteed to be callable directly from
+    // ARM64 code. Function symbol naming is swapped: __imp_ symbols refer to
+    // the auxiliary IAT, while __imp_aux_ symbols refer to the regular IAT. For
+    // data imports, the naming is reversed.
----------------
mstorsjo wrote:

Wow, this bit is highly surprising!

As there is such a stark difference, I guess it's also quite important that the distinction between what's data and what's code is made in quite exactly the same way as MS link, not only roughly the same way. But I guess as the short import library does contain a declaration of the type, it's not something we need to guess somehow.

As many mingw-w64 import libraries mark functions as "DATA", for cases where we don't want to call them (but still retain them in the import libraries, in the `__imp_func` form), does this have any practical implication? Not much I guess, as we generally don't expect those functions to be called. (And I think recent cleanups there have moved away from marking functions as DATA.) I guess the implication is that if you'd call a DATA-marked function via the `__imp_func` symbol, you'll get the x64 thunks, while if you'd call it via `__imp_func` for a function that isn't marked DATA, you'd get the native arm64ec version?

How does this work with x86_64 code in an arm64ec module? When x86_64 code calls a dllimport function, it'd load the address from `__imp_func`, won't that be the auxillary IAT, which contains a native arm64ec version?

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


More information about the llvm-commits mailing list