alvinhochun created this revision.
alvinhochun added reviewers: labath, JDevlieghere, DavidSpickett, mstorsjo.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This passes the host triple to the lldbsuite test builder used in API
tests and the build helper used in Shell tests, so that Clang can use
the correct host triple when LLVM was configured with a default target
triple different from the host triple.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134751

Files:
  lldb/packages/Python/lldbsuite/test/builders/builder.py
  lldb/packages/Python/lldbsuite/test/configuration.py
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/packages/Python/lldbsuite/test/dotest_args.py
  lldb/test/API/lit.cfg.py
  lldb/test/Shell/BuildScript/script-args.test
  lldb/test/Shell/BuildScript/toolchain-clang.test
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py

Index: lldb/test/Shell/helper/toolchain.py
===================================================================
--- lldb/test/Shell/helper/toolchain.py
+++ 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:
Index: lldb/test/Shell/helper/build.py
===================================================================
--- lldb/test/Shell/helper/build.py
+++ 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))
Index: lldb/test/Shell/BuildScript/toolchain-clang.test
===================================================================
--- lldb/test/Shell/BuildScript/toolchain-clang.test
+++ 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
Index: lldb/test/Shell/BuildScript/script-args.test
===================================================================
--- lldb/test/Shell/BuildScript/script-args.test
+++ 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
Index: lldb/test/API/lit.cfg.py
===================================================================
--- lldb/test/API/lit.cfg.py
+++ 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]
 
Index: lldb/packages/Python/lldbsuite/test/dotest_args.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ 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.'''))
Index: lldb/packages/Python/lldbsuite/test/dotest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ 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':
Index: lldb/packages/Python/lldbsuite/test/configuration.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/configuration.py
+++ 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
 
Index: lldb/packages/Python/lldbsuite/test/builders/builder.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ 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.
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... Alvin Wong via Phabricator via lldb-commits

Reply via email to