[lld] [LLD][COFF] Implement support for hybrid IAT on ARM64X (PR #124189)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 04:55:54 PST 2025


================
@@ -717,52 +717,155 @@ class ExportOrdinalChunk : public NonSectionChunk {
 void IdataContents::create(COFFLinkerContext &ctx) {
   std::vector<std::vector<DefinedImportData *>> v = binImports(ctx, imports);
 
+  // Merge compatible EC and native import files in hybrid images.
+  if (ctx.hybridSymtab) {
+    for (std::vector<DefinedImportData *> &syms : v) {
+      // At this point, symbols are sorted by base name, ensuring that
+      // compatible import files, if present, are adjacent.
+      std::vector<DefinedImportData *> hybridSyms;
+      ImportFile *prev = nullptr;
+      for (DefinedImportData *sym : syms) {
+        ImportFile *file = sym->file;
+        if (!prev || file->isEC() == prev->isEC() ||
+            !file->isSameImport(prev)) {
+          hybridSyms.push_back(sym);
+          prev = file;
+          continue;
+        }
+
+        // The native variant exposes a subset of EC symbols and chunks. Use the
+        // EC variant to represent both.
+        if (file->isEC()) {
+          hybridSyms.pop_back();
----------------
mstorsjo wrote:

> I don't think binImports guarantees this; the order may vary. That's why I check isEC on the new symbol and swap it with the one stored in hybridSyms if the native symbol appears first.

Ok, now I see - if we're in the dedup codepath, we don't end up pushing the second symbol at all, if it was native.

Perhaps we can make it even clearer with more comments? Like this:
```
if (file->isEC()) {
  // Native symbol was pushed to hybridSyms before, replace it with the EC one
  pop_back()
  push_back()
} else {
  // EC symbol was pushed to hybridSyms before, keep it as is and don't push this one
}
```

> Yes, I can change the code to avoid using an early continue if you prefer.

I'm not entirely sure if it is needed, if we have more comments for understanding the code flow.

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


More information about the llvm-commits mailing list