https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/151403

>From 279bb81cafcf1d5fcbb3f605293a52c0cbe25f9b Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jo...@devlieghere.com>
Date: Wed, 30 Jul 2025 14:57:20 -0700
Subject: [PATCH 1/2] [lldb] Support Darwin cross compilation for remote Linux
 test suite runs

Fix cross-compilation of test inferiors on Darwin, targeting remote
Linux. This requires specifying the target triple and using LLD for
linking.

Fixes #150806
---
 .../packages/Python/lldbsuite/test/builders/builder.py |  5 ++++-
 lldb/packages/Python/lldbsuite/test/configuration.py   |  4 ++++
 lldb/packages/Python/lldbsuite/test/dotest.py          |  5 +++++
 lldb/packages/Python/lldbsuite/test/dotest_args.py     |  8 ++++++++
 .../packages/Python/lldbsuite/test/make/Makefile.rules | 10 ++++++++++
 5 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py 
b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index ada6f9ff4a54f..96c7b3987d8a1 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -26,7 +26,7 @@ def getCompiler(self):
 
     def getTriple(self, arch):
         """Returns the triple for the given architecture or None."""
-        return None
+        return configuration.triple
 
     def getExtraMakeArgs(self):
         """
@@ -37,6 +37,9 @@ def getExtraMakeArgs(self):
 
     def getArchCFlags(self, architecture):
         """Returns the ARCH_CFLAGS for the make system."""
+        triple = self.getTriple(architecture)
+        if triple:
+            return ["ARCH_CFLAGS=-target {}".format(triple)]
         return []
 
     def getMake(self, test_subdir, test_name):
diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py 
b/lldb/packages/Python/lldbsuite/test/configuration.py
index b2d91fd211477..5e3810992d172 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -45,6 +45,9 @@
 sdkroot = None
 make_path = None
 
+# Allow specifying a triple for cross compilation.
+triple = None
+
 # The overriden dwarf verison.
 # Don't use this to test the current compiler's
 # DWARF version, as this won't be set if the
@@ -141,6 +144,7 @@
 # Typical values include Debug, Release, RelWithDebInfo and MinSizeRel
 cmake_build_type = None
 
+
 def shouldSkipBecauseOfCategories(test_categories):
     if use_categories:
         if (
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py 
b/lldb/packages/Python/lldbsuite/test/dotest.py
index 24236e779e51d..31b48dc50bfaa 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -321,8 +321,13 @@ def parseOptionsAndInitTestdirs():
             logging.error("No SDK found with the name %s; aborting...", 
args.apple_sdk)
             sys.exit(-1)
 
+    if args.triple:
+        configuration.triple = args.triple
+
     if args.arch:
         configuration.arch = args.arch
+    elif args.triple:
+        configuration.arch = args.triple.split("-")[0]
     else:
         configuration.arch = platform_machine
 
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py 
b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index e9c21388bc213..fce9e41cb5385 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -58,6 +58,14 @@ def create_parser():
             """Specify the path to sysroot. This overrides apple_sdk 
sysroot."""
         ),
     )
+    group.add_argument(
+        "--triple",
+        metavar="triple",
+        dest="triple",
+        help=textwrap.dedent(
+            """Specify the target triple. Used for cross compilation."""
+        ),
+    )
     if sys.platform == "darwin":
         group.add_argument(
             "--apple-sdk",
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index 8521ca508a479..a3d04326845bb 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -148,6 +148,16 @@ else
     endif
 endif
 
+#----------------------------------------------------------------------
+# Use LLD when cross compiling on Darwin.
+#----------------------------------------------------------------------
+ifeq "$(HOST_OS)" "Darwin"
+       ifneq (,$(filter $(OS), FreeBSD Linux NetBSD Windows_NT))
+               LDFLAGS += -fuse-ld=lld
+       endif
+endif
+
+
 #----------------------------------------------------------------------
 # ARCHFLAG is the flag used to tell the compiler which architecture
 # to compile for. The default is the flag that clang accepts.

>From a58abf3ad986adf3d9c6d8451eb004434d9aea77 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jo...@devlieghere.com>
Date: Thu, 31 Jul 2025 10:32:56 -0700
Subject: [PATCH 2/2] Add Android to the list

---
 lldb/packages/Python/lldbsuite/test/make/Makefile.rules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index a3d04326845bb..e72ffd1f030ec 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -152,7 +152,7 @@ endif
 # Use LLD when cross compiling on Darwin.
 #----------------------------------------------------------------------
 ifeq "$(HOST_OS)" "Darwin"
-       ifneq (,$(filter $(OS), FreeBSD Linux NetBSD Windows_NT))
+       ifneq (,$(filter $(OS), Android FreeBSD Linux NetBSD Windows_NT))
                LDFLAGS += -fuse-ld=lld
        endif
 endif

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to