Skip to content

Commit c392708

Browse files
authored
[lldb] Support Darwin cross compilation for remote Linux test suite runs (#151403)
Fix cross-compilation of test inferiors on Darwin, targeting remote Linux. This requires specifying the target triple and using LLD for linking. Fixes #150806
1 parent 4cec493 commit c392708

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

lldb/packages/Python/lldbsuite/test/builders/builder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def getCompiler(self):
2626

2727
def getTriple(self, arch):
2828
"""Returns the triple for the given architecture or None."""
29-
return None
29+
return configuration.triple
3030

3131
def getExtraMakeArgs(self):
3232
"""
@@ -37,6 +37,9 @@ def getExtraMakeArgs(self):
3737

3838
def getArchCFlags(self, architecture):
3939
"""Returns the ARCH_CFLAGS for the make system."""
40+
triple = self.getTriple(architecture)
41+
if triple:
42+
return ["ARCH_CFLAGS=-target {}".format(triple)]
4043
return []
4144

4245
def getMake(self, test_subdir, test_name):

lldb/packages/Python/lldbsuite/test/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
sdkroot = None
4646
make_path = None
4747

48+
# Allow specifying a triple for cross compilation.
49+
triple = None
50+
4851
# The overriden dwarf verison.
4952
# Don't use this to test the current compiler's
5053
# DWARF version, as this won't be set if the
@@ -141,6 +144,7 @@
141144
# Typical values include Debug, Release, RelWithDebInfo and MinSizeRel
142145
cmake_build_type = None
143146

147+
144148
def shouldSkipBecauseOfCategories(test_categories):
145149
if use_categories:
146150
if (

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,13 @@ def parseOptionsAndInitTestdirs():
321321
logging.error("No SDK found with the name %s; aborting...", args.apple_sdk)
322322
sys.exit(-1)
323323

324+
if args.triple:
325+
configuration.triple = args.triple
326+
324327
if args.arch:
325328
configuration.arch = args.arch
329+
elif args.triple:
330+
configuration.arch = args.triple.split("-")[0]
326331
else:
327332
configuration.arch = platform_machine
328333

lldb/packages/Python/lldbsuite/test/dotest_args.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ def create_parser():
5858
"""Specify the path to sysroot. This overrides apple_sdk sysroot."""
5959
),
6060
)
61+
group.add_argument(
62+
"--triple",
63+
metavar="triple",
64+
dest="triple",
65+
help=textwrap.dedent(
66+
"""Specify the target triple. Used for cross compilation."""
67+
),
68+
)
6169
if sys.platform == "darwin":
6270
group.add_argument(
6371
"--apple-sdk",

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ else
148148
endif
149149
endif
150150

151+
#----------------------------------------------------------------------
152+
# Use LLD when cross compiling on Darwin.
153+
#----------------------------------------------------------------------
154+
ifeq "$(HOST_OS)" "Darwin"
155+
ifneq (,$(filter $(OS), Android FreeBSD Linux NetBSD Windows_NT))
156+
LDFLAGS += -fuse-ld=lld
157+
endif
158+
endif
159+
160+
151161
#----------------------------------------------------------------------
152162
# ARCHFLAG is the flag used to tell the compiler which architecture
153163
# to compile for. The default is the flag that clang accepts.

0 commit comments

Comments
 (0)