-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lldb] Support Darwin cross compilation for remote Linux test suite runs #151403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Support Darwin cross compilation for remote Linux test suite runs #151403
Conversation
|
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesFix cross-compilation of test inferiors on Darwin, targeting remote Linux. This requires specifying the target triple and using LLD for linking. Fixes #150806 Full diff: https://github.com/llvm/llvm-project/pull/151403.diff 5 Files Affected:
diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index ada6f9ff4a54f..59b4abdcf7a58 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,11 @@ def getExtraMakeArgs(self):
def getArchCFlags(self, architecture):
"""Returns the ARCH_CFLAGS for the make system."""
+ triple = self.getTriple(architecture)
+ print("getArchCFlags ")
+ print(triple)
+ 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..4a26bc2da8a47 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -355,6 +355,16 @@ ifeq "$(OS)" "Windows_NT"
endif
endif
+#----------------------------------------------------------------------
+# Darwin cross compilation
+#----------------------------------------------------------------------
+ifeq "$(HOST_OS)" "Darwin"
+ ifneq "$(HOST_OS)" "$(OS)"
+ LDFLAGS += -fuse-ld=lld
+ endif
+endif
+
+
#----------------------------------------------------------------------
# C++ standard library options
#----------------------------------------------------------------------
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging leftovers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only works if you have lld built or installed on your machine. I wonder if there's something we can do to warn you about this before all the tests fail to link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could try to cross compile a simple binary upfront and complain when it fails, but I'd say it's reasonable to just say that you need lld if you want to cross compile. I believe the same thing is true on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the failure mode is that you try to run tests (on a mac, targeting a non-mac), we will try to link the test binaries with lld, which will fail immediately. Someone who doesn't know would (I think) say "Oh, I guess I need lld to build binaries for this remote target" when every test fails the same way.
Is this going to work if I run the lldb testsuite on a macOS system but running the tests on iOS or other Darwin type OS. Looking through existing OS comparisons in Makefile.rules, it seems like it can be Darwin/Android/Windows_NT/FreeBSD/NetBSD (plus I'm sure Linux). So probably it calls an iOS device Darwin too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point, I was trying to be generic but we shouldn't use lld when targeting a remote Darwin device.
a242ac3 to
436d886
Compare
jasonmolenda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the failure mode is that you try to run tests (on a mac, targeting a non-mac), we will try to link the test binaries with lld, which will fail immediately. Someone who doesn't know would (I think) say "Oh, I guess I need lld to build binaries for this remote target" when every test fails the same way.
Is this going to work if I run the lldb testsuite on a macOS system but running the tests on iOS or other Darwin type OS. Looking through existing OS comparisons in Makefile.rules, it seems like it can be Darwin/Android/Windows_NT/FreeBSD/NetBSD (plus I'm sure Linux). So probably it calls an iOS device Darwin too.
436d886 to
d2ddc86
Compare
Fix cross-compilation of test inferiors on Darwin, targeting remote Linux. This requires specifying the target triple and using LLD for linking. Fixes llvm#150806
d2ddc86 to
279bb81
Compare
| """Returns the ARCH_CFLAGS for the make system.""" | ||
| triple = self.getTriple(architecture) | ||
| if triple: | ||
| return ["ARCH_CFLAGS=-target {}".format(triple)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if ARCH_CFLAGS is overridden in the Makefile?
| ARCH_CFLAGS := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Make, command-line variables have higher precedence than variables set in the Makefile itself, so this does not overwrite the value when it's passed by the builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, thanks.
| # Use LLD when cross compiling on Darwin. | ||
| #---------------------------------------------------------------------- | ||
| ifeq "$(HOST_OS)" "Darwin" | ||
| ifneq (,$(filter $(OS), FreeBSD Linux NetBSD Windows_NT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(OS) is checked against "Android" in other places, I'd add that too.
Fix cross-compilation of test inferiors on Darwin, targeting remote Linux. This requires specifying the target triple and using LLD for linking.
Fixes #150806