diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py --- a/lldb/packages/Python/lldbsuite/test/builders/builder.py +++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py @@ -34,7 +34,10 @@ def getArchCFlags(self, architecture): """Returns the ARCH_CFLAGS for the make system.""" - return [] + if configuration.host_triple: + return ["ARCH_CFLAGS=--target=" + configuration.host_triple] + else: + return [] def getMake(self, test_subdir, test_name): """Returns the invocation for GNU make. diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py --- a/lldb/packages/Python/lldbsuite/test/configuration.py +++ b/lldb/packages/Python/lldbsuite/test/configuration.py @@ -44,6 +44,7 @@ # The 'arch' and 'compiler' can be specified via command line. arch = None compiler = None +host_triple = None dsymutil = None sdkroot = None diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py --- a/lldb/packages/Python/lldbsuite/test/dotest.py +++ b/lldb/packages/Python/lldbsuite/test/dotest.py @@ -267,6 +267,8 @@ configuration.compiler = candidate break + configuration.host_triple = args.host_triple + if args.dsymutil: configuration.dsymutil = args.dsymutil elif platform_system == 'Darwin': diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py --- a/lldb/packages/Python/lldbsuite/test/dotest_args.py +++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py @@ -40,6 +40,8 @@ help=textwrap.dedent('''Specify the architecture(s) to test. This option can be specified more than once''')) group.add_argument('-C', '--compiler', metavar='compiler', dest='compiler', help=textwrap.dedent( '''Specify the compiler(s) used to build the inferior executables. The compiler path can be an executable basename or a full path to a compiler executable. This option can be specified multiple times.''')) + group.add_argument('--host-triple', metavar='host_triple', dest='host_triple', help=textwrap.dedent( + '''Specify the host target triple used to build the inferior executables.''')) if sys.platform == 'darwin': group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="", help=textwrap.dedent( '''Specify the name of the Apple SDK (macosx, macosx.internal, iphoneos, iphoneos.internal, or path to SDK) and use the appropriate tools from that SDK's toolchain.''')) diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py --- a/lldb/test/API/lit.cfg.py +++ b/lldb/test/API/lit.cfg.py @@ -203,6 +203,9 @@ if is_configured('test_compiler'): dotest_cmd += ['--compiler', config.test_compiler] +if config.host_triple != config.target_triple: + dotest_cmd += ['--host-triple', config.host_triple] + if is_configured('dsymutil'): dotest_cmd += ['--dsymutil', config.dsymutil] diff --git a/lldb/test/Shell/BuildScript/script-args.test b/lldb/test/Shell/BuildScript/script-args.test --- a/lldb/test/Shell/BuildScript/script-args.test +++ b/lldb/test/Shell/BuildScript/script-args.test @@ -7,6 +7,7 @@ CHECK: Script Arguments: CHECK-NEXT: Arch: 32 CHECK: Compiler: any +CHECK: Host Triple: CHECK: Outdir: {{.*}}script-args.test.tmp CHECK: Output: {{.*}}script-args.test.tmp{{.}}foo.out CHECK: Nodefaultlib: False @@ -20,6 +21,7 @@ MULTI-INPUT: Script Arguments: MULTI-INPUT-NEXT: Arch: 32 MULTI-INPUT-NEXT: Compiler: any +MULTI-INPUT-NEXT: Host Triple: MULTI-INPUT-NEXT: Outdir: {{.*}}script-args.test.tmp MULTI-INPUT-NEXT: Output: MULTI-INPUT-NEXT: Nodefaultlib: False diff --git a/lldb/test/Shell/BuildScript/toolchain-clang.test b/lldb/test/Shell/BuildScript/toolchain-clang.test --- a/lldb/test/Shell/BuildScript/toolchain-clang.test +++ b/lldb/test/Shell/BuildScript/toolchain-clang.test @@ -1,14 +1,19 @@ -RUN: %build -n --verbose --arch=32 --compiler=clang --mode=compile-and-link -o %t/foo.exe foobar.c \ +RUN: %build -n --verbose --arch=32 --compiler=clang --host-triple= --mode=compile-and-link -o %t/foo.exe foobar.c \ RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-32 %s -RUN: %build -n --verbose --arch=64 --compiler=clang --mode=compile-and-link -o %t/foo.exe foobar.c \ +RUN: %build -n --verbose --arch=64 --compiler=clang --host-triple= --mode=compile-and-link -o %t/foo.exe foobar.c \ RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-64 %s +RUN: %build -n --verbose --arch=64 --compiler=clang --host-triple=x86_64-linux-gnu --mode=compile-and-link -o %t/foo.exe foobar.c \ +RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-TARGET %s + CHECK: Cleaning {{.*}}toolchain-clang.test.tmp{{.}}foo.exe-foobar.o CHECK: Cleaning {{.*}}toolchain-clang.test.tmp{{.}}foo.exe CHECK: compiling foobar.c -> foo.exe-foobar.o CHECK-32: {{.*}}clang++{{(\.EXE)?}} -m32 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c CHECK-64: {{.*}}clang++{{(\.EXE)?}} -m64 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c +CHECK-TARGET: {{.*}}clang++{{(\.EXE)?}} --target=x86_64-linux-gnu -m64 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c CHECK: linking foo.exe-foobar.o -> foo.exe CHECK-32: {{.*}}clang++{{(\.EXE)?}} -m32 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o CHECK-64: {{.*}}clang++{{(\.EXE)?}} -m64 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o +CHECK-TARGET: {{.*}}clang++{{(\.EXE)?}} --target=x86_64-linux-gnu -m64 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o diff --git a/lldb/test/Shell/helper/build.py b/lldb/test/Shell/helper/build.py --- a/lldb/test/Shell/helper/build.py +++ b/lldb/test/Shell/helper/build.py @@ -35,6 +35,12 @@ required=True, help='Path to a compiler executable, or one of the values [any, msvc, clang-cl, gcc, clang]') +parser.add_argument('--host-triple', + metavar='host_triple', + dest='host_triple', + required=False, + help='The host target triple to use instead of the default') + parser.add_argument('--libs-dir', metavar='directory', dest='libs_dir', @@ -224,6 +230,7 @@ self.opt = args.opt self.outdir = args.outdir self.compiler = args.compiler + self.host_triple = args.host_triple self.clean = args.clean self.output = args.output self.mode = args.mode @@ -632,6 +639,8 @@ args = [] args.append(self.compiler) + if self.host_triple: + args.append('--target=' + self.host_triple) args.append('-m' + self.arch) args.append('-g') @@ -657,6 +666,8 @@ def _get_link_command(self): args = [] args.append(self.compiler) + if self.host_triple: + args.append('--target=' + self.host_triple) args.append('-m' + self.arch) if self.nodefaultlib: args.append('-nostdlib') @@ -780,6 +791,7 @@ print('Script Arguments:') print(' Arch: ' + args.arch) print(' Compiler: ' + args.compiler) + print(' Host Triple: ' + (args.host_triple or "")) print(' Outdir: ' + args.outdir) print(' Output: ' + args.output) print(' Nodefaultlib: ' + str(args.nodefaultlib)) diff --git a/lldb/test/Shell/helper/toolchain.py b/lldb/test/Shell/helper/toolchain.py --- a/lldb/test/Shell/helper/toolchain.py +++ b/lldb/test/Shell/helper/toolchain.py @@ -36,6 +36,8 @@ build_script_args = [build_script, '--compiler=any', # Default to best compiler '--arch=' + str(config.lldb_bitness)] + if config.host_triple != config.target_triple: + build_script_args += ['--host-triple', config.host_triple] if config.lldb_lit_tools_dir: build_script_args.append('--tools-dir={0}'.format(config.lldb_lit_tools_dir)) if config.lldb_tools_dir: