[lld] [LLD][COFF] Add support for -includeoptional on ARM64X (PR #126300)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 7 12:03:25 PST 2025


https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/126300

Include symbols from both symbol tables.

>From 4f068610c94aa914a61bb7ebf6907ba3d324d3df Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Fri, 7 Feb 2025 20:55:28 +0100
Subject: [PATCH] [LLD][COFF] Add support for -includeoptional on ARM64X

Include symbols from both symbol tables.
---
 lld/COFF/Driver.cpp                    | 14 +++++++-------
 lld/test/COFF/arm64x-includeoptional.s | 17 +++++++++++++++++
 2 files changed, 24 insertions(+), 7 deletions(-)
 create mode 100644 lld/test/COFF/arm64x-includeoptional.s

diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 281510b7ac6ea6d..7ffd3f2219757c0 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -2557,14 +2557,14 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
         // it.
         if (symtab.findUnderscore("_load_config_used"))
           symtab.addGCRoot(symtab.mangle("_load_config_used"));
-      });
 
-      if (args.hasArg(OPT_include_optional)) {
-        // Handle /includeoptional
-        for (auto *arg : args.filtered(OPT_include_optional))
-          if (isa_and_nonnull<LazyArchive>(ctx.symtab.find(arg->getValue())))
-            ctx.symtab.addGCRoot(arg->getValue());
-      }
+        if (args.hasArg(OPT_include_optional)) {
+          // Handle /includeoptional
+          for (auto *arg : args.filtered(OPT_include_optional))
+            if (isa_and_nonnull<LazyArchive>(symtab.find(arg->getValue())))
+              symtab.addGCRoot(arg->getValue());
+        }
+      });
     } while (run());
   }
 
diff --git a/lld/test/COFF/arm64x-includeoptional.s b/lld/test/COFF/arm64x-includeoptional.s
new file mode 100644
index 000000000000000..40e885bd1c45367
--- /dev/null
+++ b/lld/test/COFF/arm64x-includeoptional.s
@@ -0,0 +1,17 @@
+// REQUIRE: aarch64
+
+// RUN: llvm-mc -filetype=obj -triple=aarch64-windows %s -o %t.arm64.obj
+// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.arm64ec.obj
+// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o %t-loadconfig-arm64ec.obj
+// RUN: llvm-mc -filetype=obj -triple=aarch64-windows %S/Inputs/loadconfig-arm64.s -o %t-loadconfig-arm64.obj
+
+// RUN: llvm-lib -machine:arm64x -out:%t-test.lib %t.arm64.obj %t.arm64ec.obj %t-loadconfig-arm64ec.obj %t-loadconfig-arm64.obj
+// RUN: lld-link -machine:arm64x -dll -noentry -out:%t.dll %t-test.lib -includeoptional:sym
+
+// RUN: llvm-readobj --hex-dump=.test %t.dll | FileCheck %s
+// CHECK: 0x180004000 01000000 01000000
+
+        .globl sym
+        .section .test,"dr"
+sym:
+        .word 1



More information about the llvm-commits mailing list